Isometric line figures that answer the pointer. For React and for anything with a DOM.
Site: the reel's figures dissolve into one another, a ring shows each one answering, and the captions are gone
Lucas Marquese31690ef8d6a
diff --git a/apps/site/app/globals.css b/apps/site/app/globals.cssindex f37132d..4a1a6ee 100644--- a/apps/site/app/globals.css+++ b/apps/site/app/globals.css@@ -279,12 +279,21 @@ 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, six ticks under it, and the caption of the one on show. Every figure is- 5:4 and the captions share one cell, so a change of figure never moves the page. */+/* The reel: the figure on the page itself and six ticks 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 { width: 100%; max-width: 440px; aspect-ratio: 5 / 4; --hairline-plate: var(--color-canvas); }-.reel-stage > div { animation: reel-in 320ms var(--ease-out) both; }+.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; }.reel-ticks { display: flex; margin-top: 10px; }.reel-tick { display: grid; place-items: center; width: 30px; height: 26px; border-radius: 6px; }.reel-tick::before, .reel-fill { grid-area: 1 / 1; width: 20px; height: 1.5px; border-radius: 1px; }@@ -294,15 +303,11 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }/* 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 */+/* 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-caps { display: grid; width: 100%; max-width: 46ch; margin-top: 4px; font-size: 13.5px; line-height: 1.55; }-.reel-cap { grid-area: 1 / 1; color: var(--color-muted); text-wrap: balance; visibility: hidden; }-.reel-cap[data-on] { visibility: visible; animation: reel-cap 300ms var(--ease-out) both; }-.reel-cap b { font-weight: 500; color: var(--color-ink); }-@keyframes reel-in { from { opacity: 0; filter: blur(4px); } to { opacity: 1; filter: none; } }+.reel:not([data-playing])[data-dir="back"] .reel-tick[aria-current] .reel-fill { transform-origin: right; }@keyframes reel-tick { to { transform: none; } }-@keyframes reel-cap { from { opacity: 0; filter: blur(3px); transform: translateY(3px); } to { opacity: 1; filter: none; transform: none; } }/* 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@@ -374,7 +379,10 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }.props[data-tokens] td:nth-child(3) { flex-basis: 100%; margin-top: 6px; }}@media (prefers-reduced-motion: reduce) {- .hero-rise > *, .reel-stage > div, .reel-cap[data-on] { animation-name: fade; }+ .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; }diff --git a/apps/site/components/reel.tsx b/apps/site/components/reel.tsxindex 80d8ad2..fab7428 100644--- a/apps/site/components/reel.tsx+++ b/apps/site/components/reel.tsx@@ -1,29 +1,60 @@"use client";-import { useEffect, useState, type CSSProperties } from "react";+import { useEffect, useRef, useState, type CSSProperties } from "react";import { Exploded, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";import { FIGURES } from "@/lib/figures";const COMPONENTS = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable };+/**+ * 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]],+};++/** 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 six figures, one at a time, standing on the page with no controls. Each- * plays for six seconds while its tick fills, then the next comes in. 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.+ * 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`. Nothing moves the page when the- * figure changes: every figure is 5:4, and the six captions share one cell,- * as tall as the longest of them, with only the current one shown.+ * 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 Figure = COMPONENTS[FIGURES[at].id];+ 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);@@ -32,30 +63,103 @@ export function Reel({ style }: { style?: CSSProperties }) {return () => document.removeEventListener("visibilitychange", visibility);}, []);- const pick = (i: number) => {+ 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-playing={playing ? "" : undefined} data-paused={held || hidden ? "" : undefined}>- <div className="reel-stage" data-figure={FIGURES[at].id} onPointerEnter={() => setHeld(true)} onPointerLeave={() => setHeld(false)}>- <Figure key={at} />+ <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 className="reel-fill" onAnimationEnd={i === at ? () => setAt((at + 1) % FIGURES.length) : undefined} />+ <span ref={(el) => { fills.current[i] = el; }} className="reel-fill" onAnimationEnd={i === at ? () => go((at + 1) % FIGURES.length, true) : undefined} /></button>))}</div>- <div className="reel-caps">- {FIGURES.map((f, i) => (- <p key={f.id} className="reel-cap" data-on={i === at ? "" : undefined}>- <b>{f.name}.</b> {f.summary}- </p>- ))}- </div></div>);}diff --git a/apps/site/test/site.spec.ts b/apps/site/test/site.spec.tsindex e59df8a..d94839e 100644--- a/apps/site/test/site.spec.ts+++ b/apps/site/test/site.spec.ts@@ -112,14 +112,15 @@ test("the reel plays the six figures in turn, holds under the pointer, and stopsawait expect(ticks).toHaveCount(6);await expect(figure).toHaveAttribute("data-figure", "riffle");await expect(ticks.first()).toHaveAttribute("aria-current", "true");- await expect(reel.locator(".reel-cap[data-on]")).toContainText("Riffle.");+ // 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 onconst 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(reel.locator(".reel-cap[data-on]")).toContainText("Terrain.");+ await expect(ticks.nth(1)).toHaveAttribute("aria-current", "true");await figure.hover();await expect(reel).toHaveAttribute("data-paused", "");