Isometric line figures that answer the pointer. For React and for anything with a DOM.
Home: a window drawn in hairlines assembles itself where the reel was, and the version sits beside the name
Lucas Marques027508311b43
diff --git a/apps/site/app/globals.css b/apps/site/app/globals.cssindex a03e843..c68f962 100644--- a/apps/site/app/globals.css+++ b/apps/site/app/globals.css@@ -60,10 +60,12 @@ em { font-style: italic; }@media (hover: hover) { a.topbar-link:hover { color: var(--color-ink); } }/* a 40px target around each link, the name and the footer's links, taller than what is drawn */a.topbar-link::after { content: ""; position: absolute; inset: -5px 0; }-.topbar > a { position: relative; }+.topbar-name { position: relative; }+/* the version, a step smaller and greyer than the name it follows, on the name's baseline */+.topbar-version { font-size: 12px; line-height: 1; color: var(--color-muted); font-variant-numeric: tabular-nums; }/* the last link's 10px padding is target, not ink: pull the nav out by it so the GitHub mark ends on the column's edge, as the footer's last link does */.topbar nav { margin-right: -10px; }-.topbar > a::after { content: ""; position: absolute; inset: -9px -6px; }+.topbar-name::after { content: ""; position: absolute; inset: -9px -6px; }/* the docs' underline, kept clear until the pointer is on the link */footer a { position: relative; text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 4px; transition: text-decoration-color 150ms ease; }@media (hover: hover) { footer a:hover { text-decoration-color: currentColor; } }@@ -283,36 +285,23 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }.skill-link:focus-visible .skill-link-hex { stroke: var(--color-ink); }.skill-link:focus-visible .skill-link-edge { stroke-dashoffset: 0; }-/* The reel: the figure on the page itself and a tick per figure under it. Every figure is 5:4 and the layers of a change- stack in one box, so a change of figure never moves the page. */-.hero-reel { width: 100%; margin-top: 14px; scroll-margin-top: calc(var(--topbar) + 24px); }-.reel { display: grid; justify-items: center; }-.reel-stage { position: relative; width: 100%; max-width: 440px; aspect-ratio: 5 / 4; --hairline-plate: var(--color-canvas); --d: 520ms; }-/* a pick answers faster than the reel's own turn */-.reel:not([data-playing]) .reel-stage { --d: 260ms; }-/* A change dissolves: the new figure comes into focus over the old, which blurs away a little faster. Transitions,- not keyframes, so a pick in the middle of a change turns it around from where it is. */-.reel-layer { position: absolute; inset: 0; transition: opacity var(--d) var(--ease-out), filter var(--d) var(--ease-out); }-@starting-style { .reel-layer { opacity: 0; filter: blur(6px); } }-.reel-layer[data-leaving] { opacity: 0; filter: blur(6px); transition-duration: calc(var(--d) * 0.7); pointer-events: none; }-/* the demo pointer: a hairline ring, there only while it walks the figure */-.reel-ghost { position: absolute; top: 0; left: 0; z-index: 1; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; border: 1px solid var(--color-ink); pointer-events: none; opacity: 0; transition: opacity 200ms ease; }-.reel-ghost[data-on] { opacity: 0.4; }-/* a tick is 30px and gives way when the row would pass the figure's width, so nineteen ticks fit a phone */-.reel-ticks { display: flex; width: 100%; max-width: 440px; justify-content: center; margin-top: 10px; }-.reel-tick { display: grid; place-items: center; flex: 0 1 30px; min-width: 0; height: 26px; border-radius: 6px; }-.reel-tick::before, .reel-fill { grid-area: 1 / 1; width: min(20px, 70%); height: 1.5px; border-radius: 1px; }-.reel-tick::before { content: ""; background: rgba(0, 0, 0, 0.12); transition: background-color 150ms ease; }-@media (hover: hover) { .reel-tick:hover::before { background: rgba(0, 0, 0, 0.3); } }-.reel-fill { background: var(--color-ink); transform: scaleX(0); transform-origin: left; }-/* the clock: the fill runs while its figure plays, and its end moves the reel on; a pause only holds it */-.reel[data-playing] .reel-tick[aria-current] .reel-fill { animation: reel-tick 6000ms linear both; }-.reel[data-playing][data-paused] .reel-tick[aria-current] .reel-fill { animation-play-state: paused; }-/* once the reel has stopped, the tick of the figure on show stays drawn; a pick to the left draws it from the right,- where the line it takes over from was */-.reel:not([data-playing]) .reel-tick[aria-current] .reel-fill { transform: none; transition: transform 240ms var(--ease-out); }-.reel:not([data-playing])[data-dir="back"] .reel-tick[aria-current] .reel-fill { transform-origin: right; }-@keyframes reel-tick { to { transform: none; } }+/* The hero's drawing, drawn by components/assembly.tsx: a floor of rules and dots, a window of three plates. The box is+ sized before the drawing mounts, so nothing moves the page. Its greys lean cool, as the figures' do. */+.hero-art { width: 100%; margin-top: 14px; }+.assembly { width: 100%; max-width: 760px; aspect-ratio: 760 / 388; margin: 0 auto; }+.assembly svg { display: block; width: 100%; height: 100%; overflow: visible; }+.assembly path { fill: none; stroke-width: 1; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }+/* a stroke drawn in is a path of length 1 with a dash as long, pushed back by what is not drawn yet */+.assembly .rule { stroke: #ebebeb; stroke-dasharray: 1 1; }+.assembly .dots { stroke: #d9d9d9; stroke-width: 1.6; }+.assembly .foot { stroke: #cfcfd4; stroke-dasharray: 1 1; }+.assembly .drop { fill: #f3f3f4; stroke: none; }+.assembly .band, .assembly .face { fill: var(--color-canvas); }+.assembly .band { stroke: none; }+.assembly .edge { stroke: #3f3f46; stroke-width: 1.15; }+.assembly .part { stroke: #bdbdc2; stroke-dasharray: 1 1; }+.assembly .pip { stroke: #3f3f46; }+.assembly .lit { stroke: var(--color-ink); stroke-width: 1.15; stroke-dasharray: 1 1; }/* Rise, blur and fade end in that order. The rise and the blur end in steps: moving text is drawn on whole devicepixels, so the last pixel of travel lands as a hop, and Chrome draws no blur under 0.4px, so the last of it goes@@ -385,10 +374,6 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }}@media (prefers-reduced-motion: reduce) {.hero-rise > * { animation-name: fade; }- /* a change of figure only crossfades, and the demo pointer stays home */- .reel-layer { filter: none !important; transition: opacity 180ms ease; }- .reel-ghost { display: none; }- .reel[data-playing] .reel-tick[aria-current] .reel-fill { animation: none; }.skill-link-hex, .skill-link-edge, .skill-link:hover .skill-link-edge { transition: none; }.icopy-b, .icopy[data-copied] .icopy-a { transform: none; filter: none; }[data-live] > .doc-dot, .doc-strip [data-live] .doc-link[aria-current] > span, .doc-strip [data-live] .doc-link > span { transition: none; }diff --git a/apps/site/app/page.tsx b/apps/site/app/page.tsxindex 6516714..cfcd580 100644--- a/apps/site/app/page.tsx+++ b/apps/site/app/page.tsx@@ -1,7 +1,7 @@import type { CSSProperties } from "react";+import { Assembly } from "@/components/assembly";import { Footer, Topbar } from "@/components/chrome";import { Install } from "@/components/install";-import { Reel } from "@/components/reel";import { SkillLink } from "@/components/skill-link";import { COUNT } from "@/lib/figures";import { install } from "@/lib/snippets";@@ -14,9 +14,8 @@ const at = (i: number) => ({ "--i": i }) as CSSProperties;/*** The home, as one column: the pitch, the command with the way in, the way to the- * skill, then the figures playing by themselves. A Server Component, so the figures- * are the package's React components rendered from here, and every deploy- * runs them through server rendering and hydration. The rest lives on /docs.+ * skill, then a window drawn in hairlines, assembling itself layer by layer. The+ * figures live on /figures and /docs.*/export default function Page() {return (@@ -33,7 +32,7 @@ export default function Page() {<a className="btn btn-primary press" href="/docs">Get started</a></div><p className="hero-skill" style={at(3)}><SkillLink /></p>- <div id="try" className="hero-reel" style={at(4)}><Reel /></div>+ <div className="hero-art" style={at(4)}><Assembly /></div></section></main><Footer />diff --git a/apps/site/components/assembly.tsx b/apps/site/components/assembly.tsxnew file mode 100644index 0000000..82e175a--- /dev/null+++ b/apps/site/components/assembly.tsx@@ -0,0 +1,220 @@+"use client";++import { useEffect, useRef } from "react";++type Pt = [number, number];++/** The floor's isometric projection, at 30px a unit. Every point is projected here, so each stroke is one screen pixel whatever its direction. */+const C = Math.cos(Math.PI / 6), S = 0.5, K = 30;+const P = (x: number, y: number, z = 0): Pt => [K * C * (x - y), K * S * (x + y) - z];++const NS = "http://www.w3.org/2000/svg";+const mk = (tag: string, at: Record<string, string | number>, parent: Element) => {+ const el = document.createElementNS(NS, tag) as SVGElement;+ for (const k in at) el.setAttribute(k, String(at[k]));+ parent.appendChild(el);+ return el;+};+const f = (n: number) => n.toFixed(2);+const line = (pts: Pt[]) => "M" + pts.map((p) => f(p[0]) + "," + f(p[1])).join("L");+const clamp = (v: number) => Math.max(0, Math.min(1, v));+/** A critically damped spring from 0 to 1: it leaves rest with no jolt and settles on a long, soft tail. */+const spring = (t: number, w: number) => (t <= 0 ? 0 : 1 - (1 + w * t) * Math.exp(-w * t));+const inout = (t: number) => ((t = clamp(t)) < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2);+const out = (t: number) => 1 - Math.pow(1 - clamp(t), 3);++/** A rounded rectangle on the floor, as points: four quarter arcs, n steps each. */+function ring(x0: number, y0: number, x1: number, y1: number, r: number, n = 8): Pt[] {+ const pts: Pt[] = [];+ for (const [cx, cy, a0] of [[x1 - r, y0 + r, -90], [x1 - r, y1 - r, 0], [x0 + r, y1 - r, 90], [x0 + r, y0 + r, 180]]) {+ for (let i = 0; i <= n; i++) {+ const a = ((a0 + (90 * i) / n) * Math.PI) / 180;+ pts.push([cx + r * Math.cos(a), cy + r * Math.sin(a)]);+ }+ }+ return pts;+}++/** The rim's points split at its left and right extremes on screen: the half nearer the viewer is the side you see. */+function frontHalf(pts: Pt[]) {+ let l = 0, r = 0;+ pts.forEach((p, i) => {+ if (p[0] < pts[l][0]) l = i;+ if (p[0] > pts[r][0]) r = i;+ });+ const walk = (a: number, b: number) => {+ const o: Pt[] = [];+ for (let i = a; ; i = (i + 1) % pts.length) {+ o.push(pts[i]);+ if (i === b) break;+ }+ return o;+ };+ const h1 = walk(l, r), h2 = walk(r, l), avg = (h: Pt[]) => h.reduce((s, p) => s + p[1], 0) / h.length;+ return avg(h1) > avg(h2) ? h1 : h2.reverse();+}++/** The window, half-widths A × B with corners of R; each plate T thick, its underside at rest at Z. N is the floor's reach. */+const A = 3.4, B = 2.4, R = 0.6, T = 6, Z = [22, 64, 106], N = 7;+const RIM = ring(-A, -B, A, B, R, 10);++/**+ * The window's parts, by stage: 0 the frame, 1 the blocks, 2 the details. The frame's lines run exactly to the rim and+ * sit under its stroke, so each meets the edge without a gap or a tip; the lit line is drawn over the grey row it marks.+ */+type Part = { stage: number; pts: Pt[]; cls: string; closed: boolean };+const TB = -B + 0.78, SB = -A + 1.45;+const PARTS: Part[] = [];+const add = (stage: number, pts: Pt[], cls = "part", closed = false) => PARTS.push({ stage, pts, cls, closed });+add(0, [[-A, TB], [A, TB]]);+add(0, [[SB, TB], [SB, B]]);+[0.72, 0.5, 0.62, 0.42].forEach((w, k) => add(1, [[-A + 0.4, TB + 0.55 + k * 0.42], [-A + 0.4 + w, TB + 0.55 + k * 0.42]]));+add(1, ring(SB + 0.4, TB + 0.42, A - 0.4, TB + 1.62, 0.16, 6), "part", true);+[3.3, 2.6, 3.0, 1.9].forEach((w, k) => add(1, [[SB + 0.4, TB + 2.12 + k * 0.42], [SB + 0.4 + w, TB + 2.12 + k * 0.42]]));+for (let k = 0; k < 3; k++) {+ const x = -A + 0.38 + k * 0.3, y = -B + 0.39, r = 0.085;+ add(2, ring(x - r, y - r, x + r, y + r, r, 6), "part pip", true);+}+add(2, [[SB + 0.75, TB + 0.82], [SB + 2.6, TB + 0.82]]);+add(2, ring(SB + 0.75, TB + 1.1, SB + 1.85, TB + 1.34, 0.12, 6), "part", true);+add(2, [[SB + 0.4, TB + 2.54], [SB + 3, TB + 2.54]], "lit");++/**+ * When things happen, in ms from mount. The floor starts at D, once the hero's own fade has shown the box; the first+ * plate at RISE, then one every STEP, each peeling off the top of the one below while that one is still settling.+ * At REST everything has arrived, and the stack starts to breathe.+ */+const D = 650, RISE = D + 900, STEP = 620, REST = RISE + 2 * STEP + 1100;++function build(host: HTMLElement) {+ const svg = mk("svg", { viewBox: "-380 -215 760 388", "aria-hidden": "true" }, host);+ const defs = mk("defs", {}, svg);+ const fade = mk("radialGradient", { id: "assembly-fade", cx: 0, cy: 0, r: 1, gradientUnits: "userSpaceOnUse" }, defs);+ mk("stop", { offset: 0.45, "stop-color": "#fff" }, fade);+ mk("stop", { offset: 1, "stop-color": "#fff", "stop-opacity": 0 }, fade);+ const mask = mk("mask", { id: "assembly-mask", maskUnits: "userSpaceOnUse", x: -400, y: -240, width: 800, height: 480 }, defs);+ mk("rect", { x: -400, y: -240, width: 800, height: 480, fill: "url(#assembly-fade)" }, mask);++ // the floor: a line every unit, each drawn as two halves running out from the point nearest the middle, and a dot+ // every quarter, seen through a soft disc that widens as they draw+ const floor = mk("g", { mask: "url(#assembly-mask)" }, svg);+ let d = "";+ for (let i = -N * 4; i <= N * 4; i++) {+ for (let j = -N * 4; j <= N * 4; j++) {+ if (i % 4 === 0 || j % 4 === 0) continue;+ const [x, y] = P(i / 4, j / 4);+ d += `M${f(x)},${f(y)}h.01`;+ }+ }+ const dots = mk("path", { d, class: "dots" }, floor);+ const rules: [SVGElement, number][] = [];+ for (let i = -N; i <= N; i++) {+ for (const e of [N, -N]) {+ rules.push([mk("path", { class: "rule", d: line([P(i, 0), P(i, e)]), pathLength: 1 }, floor), Math.abs(i)]);+ rules.push([mk("path", { class: "rule", d: line([P(0, i), P(e, i)]), pathLength: 1 }, floor), Math.abs(i)]);+ }+ }+ const foot = mk("path", { class: "foot", d: line(RIM.map((p) => P(p[0], p[1]))) + "Z" }, svg);+ const drop = mk("path", { class: "drop", d: line(ring(-A + 0.15, -B + 0.15, A - 0.15, B - 0.15, R).map((p) => P(p[0], p[1]))) + "Z" }, svg);++ // each plate carries every part up to its own stage; `k` counts the ones its own stage adds, -1 for those it inherits+ const plates = Z.map((_, i) => {+ const g = mk("g", {}, svg);+ const band = mk("path", { class: "band" }, g), side = mk("path", { class: "edge" }, g), face = mk("path", { class: "face" }, g);+ const pg = mk("g", {}, g);+ let n = 0;+ const parts = PARTS.filter((w) => w.stage <= i).map((w) => ({ ...w, k: w.stage === i ? n++ : -1, el: mk("path", { class: w.cls, pathLength: 1 }, pg) }));+ return { g, band, side, face, parts, top: mk("path", { class: "edge" }, g) };+ });+ return { fade, rules, dots, foot, drop, plates };+}++type Scene = ReturnType<typeof build>;++/** The floor's entrance: the disc widens while the lines run out to meet its edge, the nearer ones first. */+function drawFloor(s: Scene, t: number) {+ const k = N * (0.1 + 0.9 * out((t - D) / 1500));+ s.fade.setAttribute("gradientTransform", `matrix(${f(K * C * k)} ${f(K * S * k)} ${f(-K * C * k)} ${f(K * S * k)} 0 0)`);+ for (const [el, d] of s.rules) {+ const p = out((t - D - d * 55) / 1000);+ el.style.strokeDashoffset = String(1 - p);+ el.style.opacity = p ? "1" : "0";+ }+ s.dots.style.opacity = String(out((t - D - 200) / 1200));+}++/** At rest the stack breathes as one body: the gaps open and close together, slowly, rising from nothing. */+const breath = (t: number) => Math.sin(((t - REST) / 1000) * 1.05) * inout((t - REST) / 2400);++/** One frame at `t`: where each plate's underside is, how thick it is, and how much of what it adds is drawn yet. */+function draw(s: Scene, t: number, still: boolean) {+ const b = still ? 0 : breath(t);+ let below = 0, lift = 0;+ s.plates.forEach((pl, i) => {+ const u = (t - RISE - i * STEP) / 1000;+ const z = below + (Z[i] - below) * spring(u, 5.2) + b * (1.4 + 1.6 * i), th = T * out(u / 0.6);+ if (!i) lift = z;+ below = z + th;+ pl.g.style.opacity = String(i ? (u >= 0 ? 1 : 0) : clamp(u / 0.25));+ const top = RIM.map((p) => P(p[0], p[1], z + th)), bot = RIM.map((p) => P(p[0], p[1], z));+ const fb = frontHalf(bot), ft = frontHalf(top), rim = line(top) + "Z";+ pl.band.setAttribute("d", line([...ft, ...fb.slice().reverse()]) + "Z");+ pl.side.setAttribute("d", line(fb) + line([ft[0], fb[0]]) + line([ft[ft.length - 1], fb[fb.length - 1]]));+ pl.side.style.opacity = th > 0.2 ? "1" : "0";+ pl.face.setAttribute("d", rim);+ pl.top.setAttribute("d", rim);+ for (const w of pl.parts) {+ const p = w.k < 0 ? 1 : out((t - RISE - i * STEP - 260 - w.k * 55) / 520);+ w.el.setAttribute("d", line(w.pts.map((q) => P(q[0], q[1], z + th))) + (w.closed ? "Z" : ""));+ w.el.style.strokeDashoffset = String(1 - p);+ w.el.style.opacity = p ? "1" : "0";+ }+ });+ s.foot.style.opacity = String(inout((t - D - 450) / 700));+ // the shadow on the floor darkens as the bottom plate lifts off it+ s.drop.style.opacity = String(0.55 * clamp(lift / Z[0]));+}++/**+ * The hero's drawing: a floor that draws itself out from the middle, then a window built as three plates that peel+ * off one another, the frame, then the blocks, then the details, each adding its stage as it rises. Once built, the+ * stack breathes. One clock drives it all; it only counts the time the drawing is on screen, so a hidden tab or a+ * scroll away picks up where it left off. Under reduced motion it is drawn at rest, at once.+ */+export function Assembly() {+ const host = useRef<HTMLDivElement>(null);++ useEffect(() => {+ const el = host.current!;+ const scene = build(el);+ if (matchMedia("(prefers-reduced-motion: reduce)").matches) {+ drawFloor(scene, REST);+ draw(scene, REST, true);+ return () => el.replaceChildren();+ }+ let t = 0, prev = 0, raf = 0;+ const tick = (now: number) => {+ // a long gap (a slow frame, a tab coming back) counts as one ordinary frame+ t += prev ? Math.min(now - prev, 50) : 0;+ prev = now;+ if (t < REST) drawFloor(scene, t);+ draw(scene, t, false);+ raf = requestAnimationFrame(tick);+ };+ drawFloor(scene, 0);+ draw(scene, 0, false);+ const io = new IntersectionObserver(([e]) => {+ cancelAnimationFrame(raf);+ prev = 0;+ if (e.isIntersecting) raf = requestAnimationFrame(tick);+ });+ io.observe(el);+ return () => {+ io.disconnect();+ cancelAnimationFrame(raf);+ el.replaceChildren();+ };+ }, []);++ return <div ref={host} className="assembly" data-assembly />;+}diff --git a/apps/site/components/chrome.tsx b/apps/site/components/chrome.tsxindex 9482d41..b023942 100644--- a/apps/site/components/chrome.tsx+++ b/apps/site/components/chrome.tsx@@ -9,17 +9,19 @@ export function GitHub() {);}-/** The bar on every page: the name home, the figures, the skill, the docs, the story, the version, GitHub. */+/** The bar on every page: the name home with the version beside it, then the figures, the skill, the docs, the story, GitHub. */export function Topbar() {return (<header className="topbar">- <a href="/" className="text-[15px] font-medium tracking-[-0.02em]">hairline</a>+ <div className="flex items-baseline gap-2">+ <a href="/" className="topbar-name text-[15px] font-medium tracking-[-0.02em]">hairline</a>+ <span className="topbar-version" data-version>v{pkg.version}</span>+ </div><nav className="flex items-center"><a className="topbar-link" href="/figures">Figures</a><a className="topbar-link" href="/skill">Skill</a><a className="topbar-link" href="/docs">Docs</a><a className="topbar-link" href="/inspo">Inspo</a>- <span className="topbar-link tabular-nums" data-version>v{pkg.version}</span><a className="topbar-link" href={LINKS.github} aria-label="GitHub"><GitHub /></a></nav></header>diff --git a/apps/site/components/reel.tsx b/apps/site/components/reel.tsxdeleted file mode 100644index 0941d73..0000000--- a/apps/site/components/reel.tsx+++ /dev/null@@ -1,178 +0,0 @@-"use client";--import { useEffect, useRef, useState, type CSSProperties } from "react";-import { Branches, Cabinet, Dish, Elevator, Exploded, Keyboard, Laptop, Lockers, Padlock, Patch, Phone, Phosphor, Riffle, Router, Slow, Terminal, Terrain, Turntable, Vault } from "@lucasmarkes/hairline/react";-import { FIGURES } from "@/lib/figures";--const COMPONENTS = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard, elevator: Elevator, phone: Phone, laptop: Laptop, terminal: Terminal, cabinet: Cabinet, branches: Branches, vault: Vault, lockers: Lockers, padlock: Padlock, patch: Patch, dish: Dish, router: Router };--/**- * One pass of a pointer over each figure, in its viewBox (400 × 320): [x, y, ms]. Each path does the- * one thing that figure answers to, so a visitor who never moves the mouse still sees it answer.- */-const DEMO: Record<keyof typeof COMPONENTS, [number, number, number][]> = {- riffle: [[110, 220, 0], [300, 115, 2200]],- terrain: [[140, 175, 0], [215, 135, 700], [275, 170, 1400], [205, 210, 2100], [150, 175, 2700]],- exploded: [[110, 195, 0], [280, 185, 1200], [245, 265, 2400]],- phosphor: [[130, 100, 0], [270, 100, 700], [140, 160, 1400], [275, 165, 2100]],- slow: [[120, 250, 0], [200, 165, 700], [206, 160, 2600]],- turntable: [[100, 170, 0], [125, 168, 400], [310, 160, 620], [320, 158, 900]],- keyboard: [[126, 116, 0], [290, 198, 2000], [172, 165, 3000]],- elevator: [[200, 250, 0], [200, 60, 1400], [200, 175, 3400]],- phone: [[110, 170, 0], [290, 170, 1200], [290, 90, 1900], [290, 250, 2900]],- laptop: [[200, 270, 0], [200, 70, 1500], [200, 180, 3300]],- terminal: [[200, 250, 0], [200, 90, 1500], [200, 170, 3300]],- cabinet: [[200, 250, 0], [200, 120, 1600], [200, 200, 3300]],- branches: [[170, 192, 0], [124, 112, 1800], [332, 216, 3400]],- vault: [[214, 187, 0], [207, 216, 1100], [207, 216, 2300], [214, 187, 3400]],- lockers: [[200, 160, 0], [250, 230, 1800], [120, 110, 3200]],- padlock: [[40, 280, 0], [200, 170, 1500], [330, 100, 3000]],- patch: [[200, 160, 0], [120, 110, 1800], [230, 180, 3200]],- dish: [[100, 100, 0], [300, 100, 1200], [300, 250, 2400], [120, 240, 3500]],- router: [[80, 200, 0], [320, 200, 2000], [200, 120, 3200]],-};--/** Long enough for the slowest dissolve (the reel's own, 520ms) to finish before its leaver goes. */-const LEAVE_MS = 640;--type Layer = { key: number; at: number; leaving: boolean };--/**- * The figures, one at a time, standing on the page with no controls. Each- * plays for six seconds while its tick fills, then the next dissolves in over- * it. A pointer on the figure pauses the reel, and so does a hidden tab;- * picking a tick shows that figure and stops the reel for good. Under reduced- * motion it never starts.- *- * The tick's fill is the clock: a CSS animation whose end moves the reel on,- * so a pause is only `animation-play-state`. A change of figure overlaps: the- * new one mounts in its own layer over the old, which blurs away and is then- * unmounted. Nothing moves the page: every figure is 5:4 and the layers stack- * in one box.- *- * While the reel plays, a hairline ring walks each figure once and hands it- * the pointer events a mouse would, so the page shows what "answer the- * pointer" means before anyone moves theirs. A real pointer takes over at once.- */-export function Reel({ style }: { style?: CSSProperties }) {- const [at, setAt] = useState(0);- const [layers, setLayers] = useState<Layer[]>([{ key: 0, at: 0, leaving: false }]);- const [dir, setDir] = useState<"fwd" | "back">("fwd");- const [playing, setPlaying] = useState(true);- const [held, setHeld] = useState(false);- const [hidden, setHidden] = useState(false);- const nextKey = useRef(1);- const fills = useRef<(HTMLSpanElement | null)[]>([]);- const front = useRef<HTMLDivElement>(null);- const ghost = useRef<HTMLSpanElement>(null);- const heldRef = useRef(false);- const stopDemo = useRef<() => void>(() => {});- const first = useRef(true);-- useEffect(() => {- if (matchMedia("(prefers-reduced-motion: reduce)").matches) setPlaying(false);- const visibility = () => setHidden(document.hidden);- document.addEventListener("visibilitychange", visibility);- return () => document.removeEventListener("visibilitychange", visibility);- }, []);-- const go = (i: number, auto: boolean) => {- if (i === at) return;- const way = i > at || (auto && i === 0) ? "fwd" : "back";- // A full tick hands its line on toward the next one; one cut short by a pick rewinds to where it began.- const out = fills.current[at];- if (out && !matchMedia("(prefers-reduced-motion: reduce)").matches) {- const m = getComputedStyle(out).transform;- const drawn = m === "none" ? 1 : new DOMMatrix(m).a;- const origin = drawn > 0.99 ? (way === "fwd" ? "right" : "left") : "left";- if (drawn > 0.01) out.animate([{ transform: `scaleX(${drawn})`, transformOrigin: origin }, { transform: "scaleX(0)", transformOrigin: origin }], { duration: 240, easing: "cubic-bezier(0.23, 1, 0.32, 1)" });- }- const key = nextKey.current++;- setLayers((ls) => [...ls.map((l) => (l.leaving ? l : { ...l, leaving: true })), { key, at: i, leaving: false }]);- // every layer that left on this change goes; one that leaves on a later change waits for its own timer- setTimeout(() => setLayers((ls) => ls.filter((l) => !l.leaving || l.key >= key)), LEAVE_MS);- setDir(way);- setAt(i);- };-- const pick = (i: number) => {- setPlaying(false);- go(i, false);- };-- // the demo pointer: once per figure, while the reel plays and nobody is pointing- useEffect(() => {- const delay = first.current ? 1400 : 920;- first.current = false;- const host = front.current?.firstElementChild as HTMLElement | null | undefined;- const ring = ghost.current;- if (!playing || heldRef.current || !host || !ring || matchMedia("(prefers-reduced-motion: reduce)").matches) return;- const path = DEMO[FIGURES[at].id];- const end = path[path.length - 1][2];- let raf = 0, inside = false, done = false;- const stop = () => {- if (done) return;- done = true;- clearTimeout(timer);- cancelAnimationFrame(raf);- if (inside) host.dispatchEvent(new PointerEvent("pointerleave", { pointerType: "mouse" }));- delete ring.dataset.on;- };- const frame = (start: number) => (now: number) => {- const t = now - start;- if (t > end) return stop();- let k = 1;- while (k < path.length - 1 && path[k][2] < t) k++;- const [x0, y0, a] = path[k - 1], [x1, y1, b] = path[k];- let u = Math.min(1, Math.max(0, (t - a) / (b - a || 1)));- u = u * u * (3 - 2 * u);- const box = host.getBoundingClientRect(), stage = ring.parentElement!.getBoundingClientRect();- const x = box.left + ((x0 + (x1 - x0) * u) / 400) * box.width;- const y = box.top + ((y0 + (y1 - y0) * u) / 320) * box.height;- ring.style.transform = `translate(${x - stage.left}px, ${y - stage.top}px)`;- ring.dataset.on = "";- inside = true;- host.dispatchEvent(new PointerEvent("pointermove", { clientX: x, clientY: y, pointerType: "mouse" }));- raf = requestAnimationFrame(frame(start));- };- const timer = setTimeout(() => (raf = requestAnimationFrame((now) => frame(now)(now))), delay);- stopDemo.current = stop;- return stop;- }, [at, playing]);-- return (- <div className="reel" style={style} data-reel data-dir={dir} data-playing={playing ? "" : undefined} data-paused={held || hidden ? "" : undefined}>- <div- className="reel-stage"- data-figure={FIGURES[at].id}- onPointerEnter={() => {- // before the pointer's own first move reaches the figure- heldRef.current = true;- stopDemo.current();- setHeld(true);- }}- onPointerLeave={() => {- heldRef.current = false;- setHeld(false);- }}- >- {layers.map((l) => {- const Figure = COMPONENTS[FIGURES[l.at].id];- return (- <div key={l.key} ref={l.leaving ? undefined : front} className="reel-layer" data-leaving={l.leaving ? "" : undefined}>- <Figure />- </div>- );- })}- <span ref={ghost} className="reel-ghost" aria-hidden="true" />- </div>- <div className="reel-ticks" role="group" aria-label="Figures">- {FIGURES.map((f, i) => (- <button key={f.id} type="button" className="reel-tick" aria-label={f.name} title={f.name} aria-current={i === at || undefined} onClick={() => pick(i)}>- <span ref={(el) => { fills.current[i] = el; }} className="reel-fill" onAnimationEnd={i === at ? () => go((at + 1) % FIGURES.length, true) : undefined} />- </button>- ))}- </div>- </div>- );-}diff --git a/apps/site/test/figures.spec.ts b/apps/site/test/figures.spec.tsindex 5918748..d65a233 100644--- a/apps/site/test/figures.spec.ts+++ b/apps/site/test/figures.spec.ts@@ -70,7 +70,7 @@ test("the shelves' marks sit on the name in the top bar, and the shelves start wawait page.goto("/figures");const at = await page.evaluate(() => {const left = (el: Element | null) => el!.getBoundingClientRect().left;- return { mark: left(document.querySelector(".shelves .shelf svg")), name: left(document.querySelector(".topbar > a")), h1: left(document.querySelector("h1")) };+ return { mark: left(document.querySelector(".shelves .shelf svg")), name: left(document.querySelector(".topbar-name")), h1: left(document.querySelector("h1")) };});expect(Math.abs(at.mark - at.name), `${width}`).toBeLessThan(0.5);expect(Math.abs(at.h1 - at.name - 260), `${width}`).toBeLessThan(0.5);@@ -194,7 +194,7 @@ test("on a phone the shelves are a strip under the top bar, and nothing scrolls// with Figures first, the name still stands clear of the links: the version goes under 400pxconst names = await page.evaluate(() => {const text = (el: Element) => { const r = document.createRange(); r.selectNodeContents(el); return r.getBoundingClientRect(); };- return text(document.querySelector(".topbar nav > a")!).left - text(document.querySelector(".topbar > a")!).right;+ return text(document.querySelector(".topbar nav > a")!).left - text(document.querySelector(".topbar-name")!).right;});expect(names, `${width}`).toBeGreaterThanOrEqual(20);diff --git a/apps/site/test/site.spec.ts b/apps/site/test/site.spec.tsindex 31a1e52..b5e665f 100644--- a/apps/site/test/site.spec.ts+++ b/apps/site/test/site.spec.ts@@ -21,28 +21,40 @@ function watch(page: Page): string[] {return noise;}-test("the home prerenders an empty box, then draws the reel's figure with a clean console", async ({ page, request }) => {+test("the home prerenders the drawing's empty box, then draws it with a clean console", async ({ page, request }) => {const html = await (await request.get("/")).text();- // the figure's box is empty on the server- expect(html.match(/<div style="aspect-ratio:5 \/ 4"><\/div>/g)).toHaveLength(1);- expect(html).not.toMatch(/aspect-ratio:5 \/ 4"[^>]*><svg/);- expect(html).not.toMatch(/Fig\. \d/);+ // the drawing's box is empty on the server, and no figure is on the home+ expect(html.match(/<div class="assembly" data-assembly="true"><\/div>/g)).toHaveLength(1);+ expect(html).not.toContain("data-hairline");const noise = watch(page);await page.goto("/");- await expect(page.locator("[data-hairline] > svg")).toHaveCount(1);+ await expect(page.locator("[data-assembly] > svg")).toHaveCount(1);await expect(page.locator("[data-install]").first()).toHaveText(/npm i @lucasmarkes\/hairline/);await expect(page.locator("[data-version]")).toHaveText(/^v\d+\.\d+\.\d+/);expect(noise).toEqual([]);});-test("the top bar holds the figures, the skill, the docs, the story, the version and GitHub, and no llms.txt button", async ({ page }) => {+test("the top bar holds the name with the version beside it, then the figures, the skill, the docs, the story and GitHub, and no llms.txt button", async ({ page }) => {await page.goto("/");- await expect(page.locator(".topbar nav > *")).toHaveCount(6);+ await expect(page.locator(".topbar nav > *")).toHaveCount(5);await expect(page.locator(".topbar nav > a").nth(0)).toHaveText("Figures");await expect(page.locator(".topbar nav > a").nth(1)).toHaveText("Skill");await expect(page.locator(".topbar nav > a").nth(2)).toHaveText("Docs");+ await expect(page.locator(".topbar nav [data-version]")).toHaveCount(0);await expect(page.locator(".topbar")).not.toContainText("llms.txt");+ // the version follows the name on its baseline, a step smaller, close enough to read as one+ const [name, version] = await Promise.all([".topbar-name", "[data-version]"].map((s) => page.locator(s).evaluate((el) => {+ const r = document.createRange();+ r.selectNodeContents(el);+ const box = r.getBoundingClientRect();+ return { left: box.left, right: box.right, bottom: box.bottom, size: parseFloat(getComputedStyle(el).fontSize) };+ })));+ const gap = version.left - name.right;+ expect(gap).toBeGreaterThan(4);+ expect(gap).toBeLessThan(12);+ expect(Math.abs(version.bottom - name.bottom)).toBeLessThan(2.5);+ expect(version.size).toBeLessThan(name.size);});test("the top bar's links sit as one row: one height, one centre line, one type, even spaces between them", async ({ page }) => {@@ -56,7 +68,7 @@ test("the top bar's links sit as one row: one height, one centre line, one type,const style = getComputedStyle(el);return { height: box.height, middle: box.top + box.height / 2, left: ink.left, right: ink.right, type: [style.fontSize, style.fontWeight, style.color, style.backgroundColor].join(" ") };}));- expect(items).toHaveLength(6);+ expect(items).toHaveLength(5);expect(new Set(items.map((i) => i.height)).size).toBe(1);for (const i of items) expect(Math.abs(i.middle - items[0].middle)).toBeLessThan(0.5);expect(new Set(items.map((i) => i.type)).size).toBe(1);@@ -89,9 +101,9 @@ test("the docs' code is in greys: every token's colour has equal red, green andexpect(tinted).toEqual([]);});-/** Waits for every transition and entrance on the page to finish: all but the reel's clock, which runs as long as the reel plays. */+/** Waits for every transition and entrance on the page to finish. */const settled = (page: Page) =>- expect.poll(() => page.evaluate(() => document.getAnimations().filter((a) => a.playState === "running" && !(a.effect as KeyframeEffect).target?.closest(".reel-ticks")).length)).toBe(0);+ expect.poll(() => page.evaluate(() => document.getAnimations().filter((a) => a.playState === "running").length)).toBe(0);test("the home's entrance settles within 1.4s, with its hero blocks 70ms apart", async ({ page }) => {await page.goto("/");@@ -105,61 +117,52 @@ test("the home's entrance settles within 1.4s, with its hero blocks 70ms apart",expect(timing.end).toBeLessThanOrEqual(1400);});-test("the reel plays the figures in turn, holds under the pointer, and stops on a picked tick", async ({ page }) => {+/** What the drawing shows now: each path's shape and how much of it is drawn, in order. */+const drawing = (page: Page) =>+ page.locator("[data-assembly] svg").evaluate((svg) => [...svg.querySelectorAll("path")].map((p) => `${p.getAttribute("d")} ${p.style.strokeDashoffset} ${p.style.opacity}`).join("\n"));++test("the drawing builds the window in three plates, each adding its stage, then breathes", async ({ page }) => {await page.goto("/");- const reel = page.locator("[data-reel]");- const figure = reel.locator(".reel-stage");- const ticks = reel.getByRole("group", { name: "Figures" }).getByRole("button");- await expect(ticks).toHaveCount(IDS.length);- await expect(figure).toHaveAttribute("data-figure", "riffle");- await expect(ticks.first()).toHaveAttribute("aria-current", "true");- // the figure stands alone: no caption under it- await expect(reel.locator("p")).toHaveCount(0);-- // the tick's fill is the clock: its end moves the reel on- const fill = reel.locator(".reel-tick[aria-current] .reel-fill");- await expect.poll(() => fill.evaluate((el) => el.getAnimations().length)).toBe(1);- await fill.evaluate((el) => el.getAnimations()[0].finish());- await expect(figure).toHaveAttribute("data-figure", "terrain");- await expect(ticks.nth(1)).toHaveAttribute("aria-current", "true");-- await figure.hover();- await expect(reel).toHaveAttribute("data-paused", "");- await expect(fill).toHaveCSS("animation-play-state", "paused");- await expect(figure).toHaveAttribute("data-figure", "terrain");- await page.mouse.move(0, 0);- await expect(reel).not.toHaveAttribute("data-paused");-- await ticks.nth(4).click();- await expect(figure).toHaveAttribute("data-figure", "slow");- await expect(reel).not.toHaveAttribute("data-playing");- // the clock is gone: no fill runs its keyframes (the picked tick only eases full)- expect(await reel.locator(".reel-fill").evaluateAll((els) => els.flatMap((el) => el.getAnimations()).filter((a) => a instanceof CSSAnimation).length)).toBe(0);- await expect(figure).toHaveAttribute("data-figure", "slow");- await expect(reel.locator("[data-hairline]")).toHaveCount(1);-});--test("under reduced motion the reel never starts", async ({ page }) => {+ const svg = page.locator("[data-assembly] svg");+ // three plates; the frame's two lines on each, the blocks' nine on the upper two, the details' six on the top one+ await expect(svg.locator(":scope > g:not([mask])")).toHaveCount(3);+ await expect(svg.locator(".part, .lit")).toHaveCount(2 * 3 + 9 * 2 + 6);+ // the last line drawn is the top plate's lit row: once it is in full, the whole window is+ const lit = svg.locator(".lit");+ await expect.poll(() => lit.evaluate((el: SVGPathElement) => Number(el.style.strokeDashoffset)), { timeout: 8000 }).toBe(0);+ // every part and every rule is drawn in full+ const undrawn = () => svg.evaluate((el) => [...el.querySelectorAll<SVGPathElement>(".part, .lit, .rule")].filter((p) => p.style.opacity !== "1" || Number(p.style.strokeDashoffset) !== 0).length);+ expect(await undrawn()).toBe(0);+ // at rest the stack keeps moving, slowly+ const before = await drawing(page);+ await page.waitForTimeout(400);+ expect(await drawing(page)).not.toBe(before);+});++test("under reduced motion the drawing is at rest at once, and holds still", async ({ page }) => {await page.emulateMedia({ reducedMotion: "reduce" });await page.goto("/");- await expect(page.locator("[data-reel]")).not.toHaveAttribute("data-playing");- await expect(page.locator(".reel-stage")).toHaveAttribute("data-figure", "riffle");+ await expect(page.locator("[data-assembly] .lit")).toHaveCSS("stroke-dashoffset", "0px");+ const before = await drawing(page);+ await page.waitForTimeout(500);+ expect(await drawing(page)).toBe(before);});-test("a change of figure never moves the page: the reel and the page hold their height through every figure", async ({ page }) => {- // every change waits out its dissolve, at three widths: the time grows with the figures- test.setTimeout(IDS.length * 3 * 1500 + 15_000);+test("the drawing never moves the page: its box is the same height before it mounts and after it is built", async ({ browser }) => {for (const width of [1440, 390, 320]) {- await page.setViewportSize({ width, height: 800 });+ const viewport = { width, height: 800 };+ const height = (page: Page) => page.evaluate(() => `${document.documentElement.scrollHeight} ${Math.round(document.querySelector(".assembly")!.getBoundingClientRect().height)}`);+ const off = await browser.newContext({ viewport, javaScriptEnabled: false });+ const bare = await off.newPage();+ await bare.goto("/");+ const prerendered = await height(bare);+ await off.close();+ const on = await browser.newContext({ viewport, reducedMotion: "reduce" });+ const page = await on.newPage();await page.goto("/");- const ticks = page.locator(".reel-tick");- const heights = new Set<string>();- for (let i = 0; i < IDS.length; i++) {- await ticks.nth(i).click();- await expect(page.locator(".reel-stage [data-hairline] > svg")).toHaveCount(1);- heights.add(await page.evaluate(() => `${document.documentElement.scrollHeight} ${Math.round(document.querySelector(".reel")!.getBoundingClientRect().height)}`));- }- expect([...heights], `${width}px`).toHaveLength(1);+ await expect(page.locator("[data-assembly] > svg")).toHaveCount(1);+ expect(await height(page), `${width}px`).toBe(prerendered);+ await on.close();}});@@ -317,7 +320,7 @@ test("robots.txt lets every crawler in and names the sitemap, which lists the fiexpect([...sitemap.matchAll(/<loc>([^<]+)<\/loc>/g)].map((m) => m[1])).toEqual([BASE, `${BASE}/figures`, `${BASE}/docs`, `${BASE}/skill`, `${BASE}/inspo`]);});-test("the page fits a phone, with the longest install command, its buttons and the reel's ticks", async ({ page }) => {+test("the page fits a phone, with the longest install command, and its buttons", async ({ page }) => {await page.setViewportSize({ width: 390, height: 800 });await page.goto("/");const width = () => page.evaluate(() => document.documentElement.scrollWidth);@@ -328,15 +331,17 @@ test("the page fits a phone, with the longest install command, its buttons and tawait expect(pill).toHaveAttribute("data-install", "shadcn");expect(await width()).toBeLessThanOrEqual(390);- const controls = page.locator(".hero-get .btn, .reel-tick");- await expect(controls).toHaveCount(1 + IDS.length);+ const controls = page.locator(".hero-get .btn");+ await expect(controls).toHaveCount(1);for (const control of await controls.all()) {const box = (await control.boundingBox())!;expect(box.x).toBeGreaterThanOrEqual(0);expect(box.x + box.width).toBeLessThanOrEqual(390);}- await page.getByRole("button", { name: "Keyboard" }).click();- expect(await width()).toBeLessThanOrEqual(390);+ // the drawing keeps to the column, its floor fading out before the edge+ const art = (await page.locator("[data-assembly]").boundingBox())!;+ expect(art.x).toBeGreaterThanOrEqual(0);+ expect(art.x + art.width).toBeLessThanOrEqual(390);});/** Every element that holds text of its own, outside code, the hero's serif word and the figures, with its family. */diff --git a/apps/site/test/skill.spec.ts b/apps/site/test/skill.spec.tsindex 964108d..3e47c61 100644--- a/apps/site/test/skill.spec.ts+++ b/apps/site/test/skill.spec.ts@@ -203,7 +203,7 @@ test("the top bar fits a 320px screen on one row, the version left out so the na// from the name's last letter to the Skill link's first: at least the 20px the links keep between each otherconst gap = await page.evaluate(() => {const text = (el: Element) => { const r = document.createRange(); r.selectNodeContents(el); return r.getBoundingClientRect(); };- return text(document.querySelector(".topbar-link")!).left - text(document.querySelector(".topbar > a")!).right;+ return text(document.querySelector(".topbar-link")!).left - text(document.querySelector(".topbar-name")!).right;});expect(gap).toBeGreaterThanOrEqual(20);expect(await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth)).toBe(0);@@ -214,7 +214,7 @@ test("the top bar fits a 320px screen on one row, the version left out so the naexpect(last.x + last.width).toBeLessThanOrEqual(bar.x + bar.width);});-test("the home's hero points to the skill in one line between the buttons and the reel, and it reaches /skill", async ({ page }) => {+test("the home's hero points to the skill in one line between the buttons and the drawing, and it reaches /skill", async ({ page }) => {for (const width of [1200, 320]) {await page.setViewportSize({ width, height: 800 });await page.goto("/");@@ -223,9 +223,9 @@ test("the home's hero points to the skill in one line between the buttons and thexpect(await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth)).toBe(0);const get = (await page.locator(".hero-get").boundingBox())!;const box = (await link.boundingBox())!;- const reel = (await page.locator("[data-reel]").boundingBox())!;+ const art = (await page.locator("[data-assembly]").boundingBox())!;expect(box.y).toBeGreaterThanOrEqual(get.y + get.height);- expect(box.y + box.height).toBeLessThanOrEqual(reel.y);+ expect(box.y + box.height).toBeLessThanOrEqual(art.y);}await page.locator(".hero-rise").getByRole("link", { name: "Or draw your own with the skill" }).click();await expect(page).toHaveURL(/\/skill$/);