Add local p5.min.js

This commit is contained in:
John Gatward committed 2026-10-08 12:44:23 +01:00
1 parent c744979818
commit 68e773d77b
27 files changed
+212 -840

No files matched your search

+52 -89
View File
@@ -1,123 +1,78 @@
body {
display: flex;
flex-direction: column;
min-height: 100vh;
min-height: 100dvh;
}
.not-found {
flex: 1;
display: flex;
flex-direction: column;
display: grid;
align-items: center;
justify-content: center;
text-align: center;
padding: 7rem 2rem 5rem;
gap: 0;
position: relative;
width: 100%;
max-width: 1100px;
margin: 0 auto;
padding: 8rem 3rem 5rem;
}
.nf-code {
font-family: 'Fraunces', serif;
font-size: clamp(7rem, 22vw, 16rem);
font-weight: 600;
line-height: 1;
color: var(--surface0);
letter-spacing: -0.02em;
user-select: none;
position: relative;
opacity: 0;
animation: fadeUp 0.6s 0.1s forwards;
.nf-layout {
display: grid;
grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
align-items: center;
gap: 3rem;
}
.nf-eyebrow {
font-size: 0.7rem;
letter-spacing: 0.2em;
margin-bottom: 1.5rem;
font-family: var(--font-mono);
font-size: 0.72rem;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--mauve);
margin-bottom: 0.75rem;
display: flex;
align-items: center;
gap: 0.75rem;
opacity: 0;
animation: fadeUp 0.6s 0.3s forwards;
}
.nf-eyebrow::before,
.nf-eyebrow::after {
content: '';
display: block;
height: 1px;
width: 3rem;
background: var(--mauve);
opacity: 0.5;
}
.nf-heading {
font-family: 'Fraunces', serif;
font-size: clamp(1.6rem, 4vw, 2.8rem);
font-weight: 600;
color: var(--text);
line-height: 1.15;
margin-bottom: 1rem;
opacity: 0;
animation: fadeUp 0.6s 0.4s forwards;
}
.nf-heading em {
font-style: italic;
color: var(--mauve);
}
.nf-desc {
font-size: 0.88rem;
color: var(--subtext0);
max-width: 420px;
line-height: 1.8;
margin-bottom: 2.5rem;
opacity: 0;
animation: fadeUp 0.6s 0.5s forwards;
color: var(--link-accent);
}
.nf-terminal {
min-width: 0;
padding: 1.5rem;
background: var(--mantle);
border: 1px solid var(--surface0);
border-radius: 8px;
padding: 1rem 1.5rem;
font-family: var(--font-mono);
font-size: 0.78rem;
color: var(--subtext1);
text-align: left;
max-width: 440px;
width: 100%;
margin-bottom: 2.5rem;
opacity: 0;
animation: fadeUp 0.6s 0.6s forwards;
}
.nf-terminal-bar {
display: flex;
gap: 0.5rem;
margin-bottom: 0.75rem;
}
.nf-dot {
width: 10px;
height: 10px;
border-radius: 50%;
opacity: 0.7;
}
.nf-dot--red {
background: var(--red);
opacity: 0.7;
}
.nf-dot--yellow {
background: var(--yellow);
opacity: 0.7;
}
.nf-dot--green {
background: var(--green);
opacity: 0.7;
}
.nf-code {
margin: 1.5rem 0;
font-size: clamp(5rem, 10vw, 8rem);
font-weight: 700;
line-height: 1;
letter-spacing: -0.06em;
color: var(--mauve);
user-select: none;
}
.nf-terminal-line {
@@ -131,6 +86,8 @@ body {
}
.nf-cmd {
min-width: 0;
overflow-wrap: anywhere;
color: var(--text);
}
@@ -139,33 +96,39 @@ body {
}
.nf-comment {
color: var(--overlay1);
color: var(--subtext0);
}
#nf-response,
#nf-hint {
transition: opacity 0.3s;
}
.nf-cursor {
display: inline-block;
width: 0.55em;
height: 1em;
margin-top: 0.45em;
background: var(--mauve);
vertical-align: text-bottom;
animation: blink 1.1s step-end infinite;
}
@keyframes blink {
0%,
100% {
opacity: 1;
}
50% {
opacity: 0;
}
}
.nf-actions {
display: flex;
gap: 1.25rem;
flex-wrap: wrap;
justify-content: center;
opacity: 0;
animation: fadeUp 0.6s 0.7s forwards;
@media (max-width: 768px) {
.not-found {
padding: 6rem 1.5rem 3rem;
}
.nf-layout {
grid-template-columns: 1fr;
gap: 2.5rem;
}
.nf-terminal {
max-width: 440px;
}
}
+74 -51
View File
@@ -15,26 +15,36 @@
content="#eff1f5"
media="(prefers-color-scheme: light)"
/>
<script src="theme.js"></script>
<script src="/theme.js"></script>
<link rel="icon" href="/icons/favicon.ico" sizes="any" />
<link rel="apple-touch-icon" href="/icons/apple-touch-icon.png" />
<link
rel="preload"
href="/fonts/geist-variable.ttf"
as="font"
type="font/ttf"
crossorigin
/>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link
href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,400;0,700;1,400&family=Fraunces:ital,opsz,wght@0,9..144,300;0,9..144,600;1,9..144,300&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="404.css" />
<link rel="stylesheet" href="/style.css" />
<link rel="stylesheet" href="/404.css" />
</head>
<body>
<a class="skip-link" href="#main-content">Skip to main content</a>
<!-- ─── Nav ─────────────────────────────────────────────────── -->
<nav>
<a href="index.html" class="nav-logo">havox</a>
<a href="/" class="nav-logo">havox</a>
<div class="nav-actions">
<ul class="nav-links">
<li><a href="index.html#about">about</a></li>
<li><a href="index.html#skills">skills</a></li>
<li><a href="index.html#projects">projects</a></li>
<li><a href="index.html#contact">contact</a></li>
<li><a href="/#about">about</a></li>
<li><a href="/#skills">skills</a></li>
<li><a href="/#projects">projects</a></li>
<li><a href="/#contact">contact</a></li>
</ul>
<button
class="theme-toggle"
@@ -44,64 +54,77 @@
>
<span class="theme-icon" aria-hidden="true"></span>
</button>
<details class="nav-menu">
<summary>Menu</summary>
<ul class="mobile-nav-links">
<li><a href="/#about">about</a></li>
<li><a href="/#skills">skills</a></li>
<li><a href="/#projects">projects</a></li>
<li><a href="/#contact">contact</a></li>
</ul>
</details>
</div>
</nav>
<!-- ─── 404 ──────────────────────────────────────────────────── -->
<main class="not-found">
<div class="nf-code">404</div>
<main class="not-found" id="main-content" tabindex="-1">
<div class="nf-layout">
<div class="hero-copy">
<p class="nf-eyebrow">404 / page not found</p>
<h1 class="hero-name">Nothing to<br /><em>see here.</em></h1>
<p class="hero-subtitle">A wrong turn, not a dead end.</p>
<p class="hero-desc">
This page may have moved, or the link was never right. Head home for
the latest projects and experiments.
</p>
<div class="hero-links">
<a href="/" class="btn btn-primary">Back home</a>
<a href="/#projects" class="btn btn-ghost">View projects</a>
</div>
</div>
<p class="nf-eyebrow">page not found</p>
<h1 class="nf-heading">This page <em>doesn't exist</em></h1>
<p class="nf-desc">
Either this URL was wrong, something got moved, or you've stumbled onto
a dead link I haven't cleaned up yet. Wouldn't be the first time.
</p>
<div class="nf-terminal" aria-hidden="true">
<div class="nf-terminal-bar">
<span class="nf-dot nf-dot--red"></span>
<span class="nf-dot nf-dot--yellow"></span>
<span class="nf-dot nf-dot--green"></span>
<div class="nf-terminal" aria-hidden="true">
<div class="nf-terminal-bar">
<span class="nf-dot nf-dot--red"></span>
<span class="nf-dot nf-dot--yellow"></span>
<span class="nf-dot nf-dot--green"></span>
</div>
<div class="nf-code">404</div>
<div class="nf-terminal-line">
<span class="nf-prompt">~</span>
<span class="nf-cmd"
>curl -I <span id="typed-path">/missing-page</span></span
>
</div>
<div class="nf-terminal-line" id="nf-response">
<span class="nf-err">HTTP/1.1 404 Not Found</span>
</div>
<div class="nf-terminal-line" id="nf-hint">
<span class="nf-comment"># maybe try going home?</span>
</div>
<div class="nf-terminal-line">
<span class="nf-prompt">~</span>
<span class="nf-cursor"></span>
</div>
</div>
<div class="nf-terminal-line">
<span class="nf-prompt">~</span>
<span class="nf-cmd">curl -I <span id="typed-path"></span></span>
</div>
<div
class="nf-terminal-line"
id="nf-response"
style="opacity: 0; transition: opacity 0.3s"
>
<span class="nf-err">HTTP/1.1 404 Not Found</span>
</div>
<div
class="nf-terminal-line"
id="nf-hint"
style="opacity: 0; transition: opacity 0.3s"
>
<span class="nf-comment"># maybe try going home?</span>
</div>
<div class="nf-terminal-line">
<span class="nf-prompt">~</span>
<span class="nf-cursor"></span>
</div>
</div>
<div class="nf-actions">
<a href="/" class="btn btn-primary">← Back home</a>
</div>
</main>
<!-- ─── Footer ─────────────────────────────────────────────────── -->
<footer>
<span>umbra.mom — John Gatward</span>
<span>umbra.mom - John Gatward</span>
<span>
Source code (self‑hosted):
<a href="https://gitea.umbra.mom/jay/havox">repository</a>
<a
href="https://gitea.umbra.mom/jay/havox"
target="_blank"
rel="noopener noreferrer"
>repository</a
>
</span>
</footer>
<script src="404.js"></script>
<script src="/script.js"></script>
<script src="/404.js"></script>
</body>
</html>
+9
View File
@@ -5,6 +5,15 @@
const href = globalThis.location.href;
const path = href.length >= 45 ? href.substring(0, 45) : href;
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
pathEl.textContent = path;
return;
}
pathEl.textContent = '';
responseEl.style.opacity = '0';
hintEl.style.opacity = '0';
let i = 0;
const interval = setInterval(() => {
if (i < path.length) {
+1 -1
View File
@@ -89,7 +89,7 @@
<a href="/projects/pi_approximation.html">
<p>Approximating PI</p>
</a>
<a href="cardioid.php">
<a href="/projects/cardioid.html">
<p>Cardioids</p>
</a>
<a href="/projects/ellipse_construction.html">
View File
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
+1
View File
@@ -0,0 +1 @@
var p5=function(){"use strict";const t=Math.PI,r="2.3.3",i="p2d",n="webgl",s="webgl2",a="webgpu",o="default",h="simple",u="full",l="crosshair",c="pointer",p="move",d="text",f="wait",m=t/2,g=t,y=t/4,x=2*t,v=2*t,b=t/180,_=180/t,w="corner",C="corners",E="radius",A="right",D="left",S="center",T="top",F="bottom",k="alphabetic",M=0,I=1,B=4,L=6,O=5,P="quads",N="quad_strip",R=7,V=8,U="close",z="open",j="chord",G="pie",$="square",H="butt",q="round",W="bevel",X="miter",Y="auto",Z="source-over",K="destination-out",J="lighter",Q="darken",ee="lighten",te="difference",re="subtract",ie="exclusion",ne="multiply",se="screen",ae="copy",oe="overlay",he="hard-light",ue="soft-light",le="color-dodge",ce="color-burn",pe="threshold",de="gray",fe="opaque",me="invert",ge="posterize",ye="dilate",xe="erode",ve="blur",be="normal",_e="WORD",we="linear",Ce="fill",Ee="texture",Ae="image",De="linear_mipmap",Se="nearest",Te="repeat",Fe="clamp",ke="mirror",Me="flat",Ie="smooth",Be="#000000",Le="#FFFFFF",Oe="grid",Pe="axes",Ne="contain",Re="cover",Ve="unsigned-byte",Ue="unsigned-int",ze="float",je="half-float",Ge=Symbol("include"),$e=Symbol("exclude"),He=Symbol("join");var qe=Object.freeze({__proto__:null,ADD:J,ALT:"Alt",ARROW:o,AUTO:Y,AXES:Pe,BACKSPACE:"Backspace",BASELINE:k,BEVEL:W,BEZIER:"bezier",BLEND:Z,BLUR:ve,BOLD:"bold",BOLDITALIC:"bold italic",BOTTOM:F,BURN:ce,CENTER:S,CHAR:"CHAR",CHORD:j,CLAMP:Fe,CLOSE:U,CONTAIN:Ne,CONTROL:"Control",CORNER:w,CORNERS:C,COVER:Re,CROSS:l,CURVE:"curve",DARKEST:Q,DEG_TO_RAD:b,DELETE:"Delete",DIFFERENCE:te,DILATE:ye,DODGE:le,DOWN_ARROW:"ArrowDown",EMPTY_PATH:7,ENTER:"Enter",ERODE:xe,ESCAPE:"Escape",EXCLUDE:$e,EXCLUSION:ie,FALLBACK:"fallback",FILL:Ce,FLAT:Me,FLOAT:ze,FULL:u,GRAY:de,GRID:Oe,HALF_FLOAT:je,HALF_PI:m,HAND:c,HARD_LIGHT:he,IMAGE:Ae,IMMEDIATE:"immediate",INCLUDE:Ge,INVERT:me,ITALIC:"italic",JOIN:He,LABEL:"label",LANDSCAPE:"landscape",LEFT:D,LEFT_ARROW:"ArrowLeft",LIGHTEST:ee,LINEAR:we,LINEAR_MIPMAP:De,LINES:I,LINE_LOOP:2,LINE_STRIP:3,MIRROR:ke,MITER:X,MOVE:p,MULTIPLY:ne,NEAREST:Se,NORMAL:be,OPAQUE:fe,OPEN:z,OPTION:"Alt",OVERLAY:oe,P2D:i,P2DP3:"p2d-p3",PATH:8,PI:g,PIE:G,POINTS:M,PORTRAIT:"portrait",POSTERIZE:ge,PROJECT:$,QUADRATIC:"quadratic",QUADS:P,QUAD_STRIP:N,QUARTER_PI:y,RADIUS:E,RAD_TO_DEG:_,REMOVE:K,REPEAT:Te,REPLACE:ae,RETURN:"Enter",RIGHT:A,RIGHT_ARROW:"ArrowRight",ROUND:q,SCREEN:se,SHIFT:"Shift",SIMPLE:h,SMOOTH:Ie,SOFT_LIGHT:ue,SQUARE:H,STROKE:"stroke",SUBTRACT:re,TAB:"Tab",TAU:x,TESS:"tess",TEXT:d,TEXTURE:Ee,THRESHOLD:pe,TOP:T,TRIANGLES:4,TRIANGLE_FAN:6,TRIANGLE_STRIP:5,TWO_PI:v,UNSIGNED_BYTE:Ve,UNSIGNED_INT:Ue,UP_ARROW:"ArrowUp",VERSION:r,WAIT:f,WEBGL:n,WEBGL2:s,WEBGPU:a,WORD:_e,_CTX_MIDDLE:"middle",_DEFAULT_FILL:Le,_DEFAULT_LEADMULT:1.25,_DEFAULT_STROKE:Be,_DEFAULT_TEXT_FILL:"#000000"});function We(e,t){t.applyMatrix=function(...e){let t=e[0]instanceof Object.getPrototypeOf(Uint8Array);return Array.isArray(e[0])||t?this._renderer.applyMatrix(...e[0]):this._renderer.applyMatrix(...e),this},t.resetMatrix=function(){return this._renderer.resetMatrix(),this},t.rotate=function(e,t){return this._renderer.rotate(this._toRadians(e),t)},t.rotateX=function(e){return this._assert3d("rotateX"),this._renderer.rotateX(this._toRadians(e))},t.rotateY=function(e){return this._assert3d("rotateY"),this._renderer.rotateY(this._toRadians(e))},t.rotateZ=function(e){return this._assert3d("rotateZ"),this._renderer.rotateZ(this._toRadians(e))},t.scale=function(t,r,i){if(t instanceof e.Vector){const e=t;t=e.x,r=e.y,i=e.z}else if(Array.isArray(t)){const e=t;t=e[0],r=e[1],i=e[2]||1}return isNaN(r)?r=i=t:isNaN(i)&&(i=1),this._renderer.scale(t,r,i)},t.shearX=function(e){const t=this._toRadians(e);return this._renderer.applyMatrix(1,0,Math.tan(t),1,0,0),this},t.shearY=function(e){const t=this._toRadians(e);return this._renderer.applyMatrix(1,Math.tan(t),0,1,0,0),this},t.translate=function(e,t,r){return this._renderer.isP3D?this._renderer.translate(e,t,r):this._renderer.translate(e,t)},t.push=function(){this._renderer.push()},t.pop=function(){this._renderer.pop()}}function Xe(e,t){t.noLoop=function(){this._loop=!1},t.loop=function(){this._loop||(this._loop=!0,this._setupDone&&this._draw())},t.isLooping=function(){return this._loop},t.redraw=async function(e){if(this._inUserDraw||!this._setupDone)return;let t=parseInt(e);(isNaN(t)||t<1)&&(t=1);const r=this._isGlobal?window:this;if("function"==typeof r.draw){void 0===r.setup&&r.scale(r._pixelDensity,r._pixelDensity);for(let e=0;e<t;e++){r.resetMatrix(),(this._accessibleOutputs.grid||this._accessibleOutputs.text)&&this._updateAccsOutput(),this._renderer.isP3D&&this._renderer._update(),this.frameCount=r.frameCount+1,await this._runLifecycleHook("predraw"),this._inUserDraw=!0;try{await r.draw()}finally{this._inUserDraw=!1}await this._runLifecycleHook("postdraw")}await(this._renderer.finishDraw?.())}}}function Ye(e,t,r){const n=[o,l,c,p,d,f],s="undefined"!=typeof window&&"undefined"!=typeof document;t._frameRate=0,t._lastFrameTime=globalThis.performance.now(),t._targetFraLine truncated
-21
View File
@@ -1,21 +0,0 @@
MIT License
Copyright (c) 2020-2026 Paweł Kuna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+61
View File
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>
<script src="/frameworks/p5.min.js"></script>
<script>
var totalPoints = 100;
const circleRadius = 300;
var multi = 2;
var dAngle;
function setup(){
pixelDensity(1)
createCanvas(700, 700);
}
function draw(){
background(41);
translate(width/2, height/2);
angleMode(RADIANS);
rotate(PI);
multi += 0.001;
var t = map(mouseX, 0, width, 0, 500);
drawShit(t, multi);
}
function drawShit(t, m){
dAngle = TWO_PI / t;
stroke(255);
strokeWeight(7);
for (var i = 0; i < t; i++){
var x = circleRadius * Math.cos(dAngle*i);
var y = circleRadius * Math.sin(dAngle*i);
point(x,y);
}
strokeWeight(3);
noFill();
ellipse(0, 0, circleRadius * 2, circleRadius * 2);
strokeWeight(1);
for (var i = 0; i < t; i++){
var cNode = (i * m) % t;
var x1 = circleRadius * Math.cos(dAngle*i);
var y1 = circleRadius * Math.sin(dAngle*i);
var x2 = circleRadius * Math.cos(dAngle*cNode);
var y2 = circleRadius * Math.sin(dAngle*cNode);
stroke((cNode/100)*255, (i*m)%255, 255 - (cNode/100)*255);
line(x1, y1, x2, y2);
}
}
</script>
</html>
+1 -1
View File
@@ -8,7 +8,7 @@
maximum-scale="1.0,"
user-scalable="0"
/>
<script src="https://cdn.jsdelivr.net/npm/p5@1.4.0/lib/p5.min.js"></script>
<script src="/frameworks/p5.min.js"></script>
<script src="cPoint.js"></script>
<script src="cLine.js"></script>
<script src="sketch.js"></script>
+1 -1
View File
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/p5@1.4.0/lib/p5.min.js"></script>
<script src="/frameworks/p5.min.js"></script>
</head>
<style>
+1 -1
View File
@@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<title>Fourier Series — Epicycles (p5.js)</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://cdn.jsdelivr.net/npm/p5@1.4.0/lib/p5.min.js"></script>
<script src="/frameworks/p5.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
+1 -1
View File
@@ -10,7 +10,7 @@
margin: 0;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/p5@1.4.0/lib/p5.min.js"></script>
<script src="/frameworks/p5.min.js"></script>
<title>Game of Life</title>
<script>
+1 -1
View File
@@ -8,7 +8,7 @@
maximum-scale="1.0,"
user-scalable="0"
/>
<script src="https://cdn.jsdelivr.net/npm/p5@1.4.0/lib/p5.min.js"></script>
<script src="/frameworks/p5.min.js"></script>
<style>
body {
+1 -1
View File
@@ -13,7 +13,7 @@
margin: 0;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/p5@1.4.0/lib/p5.min.js"></script>
<script src="/frameworks/p5.min.js"></script>
<script src="sketch.js"></script>
<script src="cells.js"></script>
<title>Maze Generator</title>
+1 -1
View File
@@ -4,7 +4,7 @@
<head>
<link rel="shortcut icon" type"image/ico" href"/Media/iconImage.ico">
<meta name="viewport" width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0>
<script src="https://cdn.jsdelivr.net/npm/p5@1.4.0/lib/p5.min.js"></script>
<script src="/frameworks/p5.min.js"></script>
</head>
<script>
let angle = 0;
+1 -1
View File
@@ -1,6 +1,6 @@
<!doctype html>
<html>
<script src="https://cdn.jsdelivr.net/npm/p5@1.4.0/lib/p5.min.js"></script>
<script src="/frameworks/p5.min.js"></script>
<h1 id="PIbox"></h1>
<h2 id="percentage"></h2>
+1 -1
View File
@@ -1,6 +1,6 @@
<!doctype html>
<html>
<script src="https://cdn.jsdelivr.net/npm/p5@1.4.0/lib/p5.min.js"></script>
<script src="/frameworks/p5.min.js"></script>
<script>
var r = 10; //circle size
var k = 30;
+1 -1
View File
@@ -8,7 +8,7 @@
maximum-scale="1.0,"
user-scalable="0"
/>
<script src="https://cdn.jsdelivr.net/npm/p5@1.4.0/lib/p5.min.js"></script>
<script src="/frameworks/p5.min.js"></script>
<style>
body {
-465
View File
@@ -1,465 +0,0 @@
const assert = require('node:assert/strict');
const { readFileSync, existsSync } = require('node:fs');
const { resolve } = require('node:path');
const { test } = require('node:test');
const { runInNewContext } = require('node:vm');
const root = resolve(__dirname, '..');
const script = readFileSync(resolve(root, 'script.js'), 'utf8');
const html = readFileSync(resolve(root, 'index.html'), 'utf8');
function element(dataset = {}, textContent = '') {
const classes = new Set();
const attributes = new Map();
const listeners = new Map();
return {
dataset,
textContent,
hidden: true,
focused: false,
classList: {
add: (name) => classes.add(name),
contains: (name) => classes.has(name),
toggle: (name, force) => {
if (force) classes.add(name);
else classes.delete(name);
},
},
setAttribute: (name, value) => attributes.set(name, value),
getAttribute: (name) => attributes.get(name),
removeAttribute: (name) => attributes.delete(name),
addEventListener: (name, listener) => listeners.set(name, listener),
click: () => listeners.get('click')(),
dispatch: (name, event) => listeners.get(name)(event),
focus() {
this.focused = true;
},
scrollIntoView() {
this.scrolledIntoView = true;
},
contains: () => false,
};
}
function fixture({ missingFilter = false, reducedMotion = false } = {}) {
const chips = Array.from(
html.matchAll(
/<button\b[^>]*data-filter="([^"]+)"[^>]*>([\s\S]*?)<\/button>/g
),
(match) => element({ filter: match[1] }, match[2].trim())
);
if (missingFilter) chips.push(element({ filter: 'missing' }, 'Missing'));
const cards = Array.from(
html.matchAll(
/<article\s+class="card project-card"\s+data-tech="([^"]+)"/g
),
(match) => element({ tech: match[1] })
);
const controls = new Map(
[
'#projects-see-more',
'#project-count',
'#projects-empty',
'#project-grid',
'.project-filters',
'#projects-reset',
].map((selector) => [selector, element()])
);
const reveal = element();
const observers = [];
class IntersectionObserver {
constructor(callback, options) {
this.callback = callback;
this.options = options;
this.targets = [];
observers.push(this);
}
observe(target) {
this.targets.push(target);
}
unobserve(target) {
this.targets = this.targets.filter((item) => item !== target);
}
disconnect() {
this.targets = [];
this.disconnected = true;
}
}
const context = {
document: {
querySelectorAll: (selector) => {
if (selector === '.filter-chip') return chips;
if (selector === '#project-grid .project-card') return cards;
if (selector === '.reveal') return [reveal];
return [];
},
querySelector: (selector) => controls.get(selector) || null,
},
window: {
IntersectionObserver,
matchMedia: () => ({ matches: reducedMotion }),
},
IntersectionObserver,
};
return {
chips,
cards,
controls,
reveal,
observers,
context,
start: () => runInNewContext(script, context),
visible: () => cards.filter((card) => !card.hidden),
};
}
function animatedFixture(options) {
const f = fixture(options);
const animations = [];
const listeners = new Map();
const media = {
matches: options?.reducedMotion ?? false,
addEventListener: (name, listener) =>
listeners.set(`motion-${name}`, listener),
};
f.context.window.matchMedia = () => media;
f.context.window.addEventListener = (name, listener) =>
listeners.set(name, listener);
f.context.window.getComputedStyle = () => ({ opacity: '1' });
for (const card of f.cards) {
card.getBoundingClientRect = () => {
const index = f.visible().indexOf(card);
return { left: (index % 3) * 300, top: Math.floor(index / 3) * 200 };
};
card.animate = (frames, timing) => {
const animation = {
card,
frames,
timing,
cancelled: false,
cancel() {
this.cancelled = true;
},
addEventListener(name, listener) {
if (name === 'finish') this.finish = listener;
},
};
animations.push(animation);
return animation;
};
}
return { ...f, animations, listeners, media };
}
test('filtering moves retained cards and fades in new cards without delaying results', () => {
const f = animatedFixture();
f.start();
assert.equal(f.animations.length, 0);
const rust = f.chips.find((chip) => chip.dataset.filter === 'rust');
rust.click();
assert.equal(f.visible().length, 1);
assert.equal(
f.controls.get('#project-count').textContent,
'Showing 1 of 1 project (Rust)'
);
assert.ok(
f.animations.some(
(animation) => animation.frames[0].transform !== 'translate(0px, 0px)'
)
);
assert.ok(
f.animations.every((animation) => animation.timing.duration === 280)
);
f.chips[0].click();
assert.equal(f.visible().length, 9);
assert.ok(
f.animations.some((animation) => animation.frames[0].opacity === 0)
);
});
test('rapid filter changes cancel old animations and finish on the latest selection', () => {
const f = animatedFixture();
f.start();
f.chips.find((chip) => chip.dataset.filter === 'rust').click();
const previous = [...f.animations];
f.chips[0].click();
assert.ok(previous.every((animation) => animation.cancelled));
const current = f.animations.filter((animation) => !animation.cancelled);
previous.forEach((animation) => animation.finish());
f.listeners.get('resize')();
assert.ok(current.every((animation) => animation.cancelled));
assert.equal(f.visible().length, 9);
});
test('reduced motion is instant and enabling it cancels in-flight animations', () => {
const reduced = animatedFixture({ reducedMotion: true });
reduced.start();
reduced.chips.find((chip) => chip.dataset.filter === 'rust').click();
assert.equal(reduced.visible().length, 1);
assert.equal(reduced.animations.length, 0);
const f = animatedFixture();
f.start();
f.chips.find((chip) => chip.dataset.filter === 'rust').click();
f.media.matches = true;
f.listeners.get('motion-change')();
assert.ok(f.animations.every((animation) => animation.cancelled));
const count = f.animations.length;
f.chips[0].click();
assert.equal(f.animations.length, count);
assert.equal(f.visible().length, 9);
});
test('filtering restores focus when the focused project becomes hidden', () => {
const f = fixture();
f.start();
const focused = f.cards.find((card) => !card.dataset.tech.includes('rust'));
f.context.document.activeElement = focused;
focused.contains = (target) => target === focused;
const rust = f.chips.find((chip) => chip.dataset.filter === 'rust');
rust.click();
assert.equal(focused.hidden, true);
assert.equal(rust.focused, true);
});
test('keyboard focus immediately settles a moving project', () => {
const f = animatedFixture();
f.start();
f.chips.find((chip) => chip.dataset.filter === 'rust').click();
const animation = f.animations[0];
f.controls.get('#project-grid').dispatch('focusin', {
target: { closest: () => animation.card },
});
assert.equal(animation.cancelled, true);
});
test('projects start collapsed with an accurate count and remaining label', () => {
const f = fixture();
f.start();
assert.equal(f.visible().length, 9);
assert.equal(
f.controls.get('#project-count').textContent,
`Showing 9 of ${f.cards.length} projects`
);
assert.equal(
f.controls.get('#projects-see-more').textContent,
`Show ${f.cards.length - 9} more projects`
);
assert.equal(f.controls.get('.project-filters').hidden, false);
assert.equal(f.controls.get('#projects-empty').hidden, true);
assert.equal(f.chips[0].getAttribute('aria-pressed'), 'true');
});
test('expanding and collapsing updates the count and keeps the control in view', () => {
const f = fixture();
f.start();
const button = f.controls.get('#projects-see-more');
button.click();
assert.equal(f.visible().length, f.cards.length);
assert.equal(button.getAttribute('aria-expanded'), 'true');
assert.equal(button.textContent, 'Show fewer projects');
button.click();
assert.equal(f.visible().length, 9);
assert.equal(button.getAttribute('aria-expanded'), 'false');
assert.equal(button.scrolledIntoView, true);
});
test('every technology filter selects matching cards and resets expansion', () => {
const f = fixture();
f.start();
for (const chip of f.chips) {
f.controls.get('#projects-see-more').click();
chip.click();
const expected = f.cards.filter(
(card) =>
chip.dataset.filter === 'all' ||
card.dataset.tech.split(/\s+/).includes(chip.dataset.filter)
);
assert.deepEqual(f.visible(), expected.slice(0, 9));
assert.equal(chip.getAttribute('aria-pressed'), 'true');
assert.equal(
f.chips.filter((item) => item.getAttribute('aria-pressed') === 'true')
.length,
1
);
assert.equal(
f.controls.get('#projects-see-more').hidden,
expected.length <= 9
);
assert.equal(
f.controls.get('#projects-see-more').getAttribute('aria-expanded'),
'false'
);
assert.equal(
f.controls.get('#project-count').textContent,
`Showing ${Math.min(9, expected.length)} of ${expected.length} project${expected.length === 1 ? '' : 's'}` +
(chip.dataset.filter === 'all' ? '' : ` (${chip.textContent})`)
);
}
});
test('empty results show a reset which restores all projects and focus', () => {
const f = fixture({ missingFilter: true });
f.start();
f.chips.at(-1).click();
assert.equal(f.visible().length, 0);
assert.equal(f.controls.get('#projects-empty').hidden, false);
assert.equal(f.controls.get('#project-grid').hidden, true);
assert.equal(f.controls.get('#projects-see-more').hidden, true);
f.controls.get('#projects-reset').click();
assert.equal(f.visible().length, 9);
assert.equal(f.controls.get('#projects-empty').hidden, true);
assert.equal(f.controls.get('#project-grid').hidden, false);
assert.equal(f.chips[0].focused, true);
});
test('reveals only become pending when an observer can reveal them', () => {
const f = fixture();
f.start();
assert.equal(f.reveal.classList.contains('reveal-pending'), true);
const observer = f.observers[0];
observer.callback([{ target: f.reveal, isIntersecting: true }], observer);
assert.equal(f.reveal.classList.contains('visible'), true);
assert.equal(observer.targets.length, 0);
const reduced = fixture({ reducedMotion: true });
reduced.start();
assert.equal(reduced.reveal.classList.contains('reveal-pending'), false);
const unsupported = fixture();
delete unsupported.context.window.IntersectionObserver;
unsupported.start();
assert.equal(unsupported.reveal.classList.contains('reveal-pending'), false);
assert.equal(unsupported.controls.get('.project-filters').hidden, false);
});
test('active navigation uses a viewport-sized observer and updates on resize', () => {
const f = fixture();
const sections = ['hero', 'about', 'skills', 'projects', 'contact'].map(
(id) => ({ ...element(), id })
);
const links = sections.slice(1).map((section) => {
const link = element();
link.setAttribute('href', `#${section.id}`);
return link;
});
const query = f.context.document.querySelectorAll;
f.context.document.querySelectorAll = (selector) => {
if (selector === 'section[id]') return sections;
if (selector === '.nav-links a, .mobile-nav-links a') return links;
return query(selector);
};
const listeners = new Map();
f.context.window.innerHeight = 900;
f.context.window.addEventListener = (name, listener) =>
listeners.set(name, listener);
f.start();
const observer = f.observers[0];
assert.equal(observer.options.rootMargin, '-56px 0px -740px 0px');
observer.callback([{ target: sections[1], isIntersecting: true }]);
assert.equal(links[0].getAttribute('aria-current'), 'location');
observer.callback([
{ target: sections[1], isIntersecting: false },
{ target: sections[2], isIntersecting: true },
]);
assert.equal(links[0].getAttribute('aria-current'), undefined);
assert.equal(links[1].getAttribute('aria-current'), 'location');
f.context.window.innerHeight = 600;
listeners.get('resize')();
assert.equal(observer.disconnected, true);
assert.equal(f.observers.at(-1).options.rootMargin, '-56px 0px -440px 0px');
assert.deepEqual(f.observers.at(-1).targets, sections);
});
test('mobile navigation closes after selection and Escape restores menu focus', () => {
const f = fixture();
const menu = element();
const summary = element();
const link = element();
menu.querySelectorAll = () => [link];
menu.querySelector = () => summary;
f.controls.set('.nav-menu', menu);
f.start();
menu.open = true;
link.click();
assert.equal(menu.open, false);
menu.open = true;
menu.dispatch('keydown', { key: 'Escape' });
assert.equal(menu.open, false);
assert.equal(summary.focused, true);
});
test('all project destinations are native links with existing local files', () => {
assert.doesNotMatch(html, /data-href=|class="[^"]*card-link/);
const links = Array.from(
html.matchAll(/<a class="card-title" href="([^"]+)"/g),
(match) => match[1]
);
assert.equal(links.length, 17);
for (const href of links) {
if (!href.startsWith('https://')) {
assert.ok(existsSync(resolve(root, href)), `Missing project: ${href}`);
}
}
});
test('the hero is text-only and featured projects have local screenshots', () => {
const hero = html.match(/<section id="hero">([\s\S]*?)<\/section>/)[1];
assert.doesNotMatch(hero, /<img|<figure|flocking/i);
const previews = Array.from(
html.matchAll(/<img\s+class="project-preview"[\s\S]*?\/>/g),
(match) => match[0]
);
assert.equal(previews.length, 2);
for (const preview of previews) {
const src = preview.match(/src="([^"]+)"/)[1];
assert.ok(existsSync(resolve(root, src)));
assert.match(preview, /loading="lazy"/);
assert.match(preview, /width="1200"/);
assert.match(preview, /height="800"/);
}
});
test('LinkedIn is the first and primary contact action, with GitHub secondary', () => {
const contact = html.match(/<section id="contact">([\s\S]*?)<\/section>/)[1];
const links = Array.from(
contact.matchAll(/<a\s+href="([^"]+)"\s+class="([^"]+)"/g)
);
assert.equal(links.length, 2);
assert.equal(links[0][1], 'https://www.linkedin.com/in/jaygatward');
assert.match(links[0][2], /btn-primary/);
assert.equal(links[1][1], 'https://github.com/jayo60013');
assert.doesNotMatch(links[1][2], /btn-primary/);
assert.match(contact, /Connect on LinkedIn/);
assert.match(contact, /Explore my code/);
});
test('About has a genuine local portrait and an unboxed opening paragraph', () => {
const about = html.match(/<section id="about"[^>]*>([\s\S]*?)<\/section>/)[1];
assert.match(about, /class="about-intro"/);
assert.doesNotMatch(about, /about-grid|about-block-tag/);
const portrait = about.match(/<img\s+class="about-portrait"[\s\S]*?\/>/)[0];
assert.match(portrait, /alt="John Gatward"/);
assert.match(portrait, /width="800"[\s\S]*height="800"/);
assert.ok(existsSync(resolve(root, portrait.match(/src="([^"]+)"/)[1])));
assert.match(about, /<h3 class="about-subheading">Version history<\/h3>/);
assert.equal(
(about.match(/href="archive\/v[123]\/index.html"/g) || []).length,
3
);
});
test('featured projects put title and purpose ahead of supporting metadata', () => {
const featured = Array.from(
html.matchAll(/<article class="card featured-card">([\s\S]*?)<\/article>/g),
(match) => match[1]
);
assert.equal(featured.length, 2);
for (const card of featured) {
assert.ok(card.indexOf('project-preview') < card.indexOf('card-title'));
assert.ok(card.indexOf('card-title') < card.indexOf('card-desc'));
assert.ok(card.indexOf('card-desc') < card.indexOf('project-meta'));
assert.ok(card.indexOf('project-meta') < card.indexOf('tag-row'));
}
assert.doesNotMatch(html, /class="section-label|class="divider"/);
});
-187
View File
@@ -1,187 +0,0 @@
const assert = require('node:assert/strict');
const { readFileSync } = require('node:fs');
const { resolve } = require('node:path');
const { test } = require('node:test');
const { runInNewContext } = require('node:vm');
const root = resolve(__dirname, '..');
const script = readFileSync(resolve(root, 'theme.js'), 'utf8');
const html = readFileSync(resolve(root, 'index.html'), 'utf8');
function fixture({
dark = false,
saved = null,
storageError = null,
writeError = null,
} = {}) {
const dataset = {};
const storage = new Map(saved === null ? [] : [['havox-theme', saved]]);
const meta = [{ content: '#1e1e2e' }, { content: '#eff1f5' }];
const listeners = new Map();
const warnings = [];
const attributes = new Map();
const button = {
hidden: true,
dataset: {},
setAttribute: (name, value) => attributes.set(name, value),
getAttribute: (name) => attributes.get(name),
addEventListener: (name, listener) => listeners.set(name, listener),
};
const media = {
matches: dark,
addEventListener: (name, listener) =>
listeners.set(`system-${name}`, listener),
};
const context = {
document: {
documentElement: { dataset },
querySelectorAll: () => meta,
querySelector: () => button,
addEventListener: (name, listener) => listeners.set(name, listener),
},
window: {
matchMedia: (query) => {
assert.equal(query, '(prefers-color-scheme: dark)');
return media;
},
},
localStorage: {
getItem: (key) => {
if (storageError) throw storageError;
return storage.get(key) ?? null;
},
setItem: (key, value) => {
if (storageError) throw storageError;
if (writeError) throw writeError;
storage.set(key, value);
},
},
console: { warn: (...args) => warnings.push(args) },
};
runInNewContext(script, context);
return {
dataset,
storage,
meta,
button,
warnings,
ready: () => listeners.get('DOMContentLoaded')(),
toggle: () => listeners.get('click')(),
setSystemDark(value) {
media.matches = value;
listeners.get('system-change')();
},
};
}
test('system preference applies immediately and follows operating-system changes', () => {
for (const dark of [false, true]) {
const f = fixture({ dark });
assert.equal(f.dataset.theme, undefined);
assert.ok(
f.meta.every((meta) => meta.content === (dark ? '#1e1e2e' : '#eff1f5'))
);
assert.equal(f.button.hidden, true);
f.ready();
assert.equal(f.button.hidden, false);
assert.equal(f.button.dataset.theme, dark ? 'dark' : 'light');
assert.equal(
f.button.getAttribute('aria-label'),
`Switch to ${dark ? 'light' : 'dark'} theme`
);
f.setSystemDark(!dark);
assert.equal(f.button.dataset.theme, dark ? 'light' : 'dark');
assert.equal(
f.button.getAttribute('aria-label'),
`Switch to ${dark ? 'dark' : 'light'} theme`
);
assert.ok(
f.meta.every((meta) => meta.content === (dark ? '#eff1f5' : '#1e1e2e'))
);
}
});
test('saved themes override the system before first paint', () => {
for (const saved of ['light', 'dark']) {
const f = fixture({ dark: saved === 'light', saved });
assert.equal(f.dataset.theme, saved);
f.ready();
assert.equal(f.button.dataset.theme, saved);
f.setSystemDark(saved === 'dark');
assert.equal(f.dataset.theme, saved);
assert.ok(
f.meta.every(
(meta) => meta.content === (saved === 'dark' ? '#1e1e2e' : '#eff1f5')
)
);
}
assert.ok(html.indexOf('src="theme.js"') < html.indexOf('href="style.css"'));
const notFound = readFileSync(resolve(root, '404.html'), 'utf8');
assert.ok(
notFound.indexOf('src="theme.js"') < notFound.indexOf('href="style.css"')
);
assert.match(
notFound,
/class="theme-toggle"[\s\S]*?type="button"[\s\S]*?hidden/
);
});
test('the button toggles the effective theme and persists the explicit choice', () => {
const f = fixture({ dark: true });
f.ready();
f.toggle();
assert.equal(f.dataset.theme, 'light');
assert.equal(f.storage.get('havox-theme'), 'light');
f.toggle();
assert.equal(f.dataset.theme, 'dark');
assert.equal(f.storage.get('havox-theme'), 'dark');
f.setSystemDark(false);
assert.equal(f.dataset.theme, 'dark');
assert.equal(f.button.dataset.theme, 'dark');
assert.ok(f.meta.every((meta) => meta.content === '#1e1e2e'));
const reloaded = fixture({
dark: false,
saved: f.storage.get('havox-theme'),
});
reloaded.ready();
assert.equal(reloaded.button.dataset.theme, 'dark');
reloaded.toggle();
assert.equal(reloaded.dataset.theme, 'light');
});
test('invalid saved values do not become theme attributes', () => {
const f = fixture({ saved: 'unexpected' });
f.ready();
assert.equal(f.dataset.theme, undefined);
assert.equal(f.button.dataset.theme, 'light');
});
test('blocked storage warns but does not prevent switching themes', () => {
const storageError = new Error('Storage denied');
storageError.name = 'SecurityError';
const f = fixture({ storageError });
f.ready();
f.toggle();
assert.equal(f.dataset.theme, 'dark');
assert.ok(f.meta.every((meta) => meta.content === '#1e1e2e'));
assert.equal(f.warnings.length, 2);
});
test('unexpected storage errors are not swallowed', () => {
assert.throws(
() => fixture({ storageError: new Error('Unexpected failure') }),
/Unexpected failure/
);
});
test('full storage does not prevent toggling in either direction', () => {
const writeError = new Error('Storage full');
writeError.name = 'QuotaExceededError';
const f = fixture({ writeError });
f.ready();
f.toggle();
assert.equal(f.dataset.theme, 'dark');
f.toggle();
assert.equal(f.dataset.theme, 'light');
assert.equal(f.warnings.length, 2);
});
+1 -3
View File
@@ -6,9 +6,7 @@
<link href="https://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.2.0/p5.min.js"
integrity="sha512-b/htz6gIyFi3dwSoZ0Uv3cuv3Ony7EeKkacgrcVg8CMzu90n777qveu0PBcbZUA7TzyENGtU+qZRuFAkfqgyoQ=="
crossorigin="anonymous"></script>
<script src="/frameworks/p5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/latest.js?config=AM_CHTML"></script>
<button id="backButton" onclick="window.location.href='/#tutorials'">Back</button>
+1 -3
View File
@@ -94,9 +94,7 @@
<!--<span id="c1"></span>-->
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.2.0/p5.min.js"
integrity="sha512-b/htz6gIyFi3dwSoZ0Uv3cuv3Ony7EeKkacgrcVg8CMzu90n777qveu0PBcbZUA7TzyENGtU+qZRuFAkfqgyoQ=="
crossorigin="anonymous"></script>
<script src="/frameworks/p5.min.js"></script>
<script src="sketch.js"></script>
<script src="dot.js"></script>
+1 -5
View File
@@ -6,11 +6,7 @@
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/atom-one-dark.min.css"
/>
<link rel="stylesheet" href="style.css" />
<script
src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.2.0/p5.min.js"
integrity="sha512-b/htz6gIyFi3dwSoZ0Uv3cuv3Ony7EeKkacgrcVg8CMzu90n777qveu0PBcbZUA7TzyENGtU+qZRuFAkfqgyoQ=="
crossorigin="anonymous"
></script>
<script src="/frameworks/p5.min.js"></script>
<script src="script.js"></script>
<script>
fetch("snippets/defineCount.js")
+1 -5
View File
@@ -2,11 +2,7 @@
<html>
<link href="style.css" rel="stylesheet" type="text/css" />
<script
src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.2.0/p5.min.js"
integrity="sha512-b/htz6gIyFi3dwSoZ0Uv3cuv3Ony7EeKkacgrcVg8CMzu90n777qveu0PBcbZUA7TzyENGtU+qZRuFAkfqgyoQ=="
crossorigin="anonymous"
></script>
<script src="/frameworks/p5.min.js"></script>
<title>Travelling Sales Person</title>
<h1>Travelling Sales Person Problem</h1>