Isometric line figures that answer the pointer. For React and for anything with a DOM.
Skill page: the storm and sidings pages are the ones a follow-up made, and the follow-up sits under the first prompt as a second line
Lucas Marques98d157ce35f5
diff --git a/apps/site/app/globals.css b/apps/site/app/globals.cssindex e660afc..2591d3b 100644--- a/apps/site/app/globals.css+++ b/apps/site/app/globals.css@@ -355,6 +355,9 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }.example > * { min-width: 0; }.example-prompt { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-content: start; }.example-figure { container-type: inline-size; }+/* a follow-up is a sentence: it wraps in its pill, and the copy icon stays by its first line */+.pill[data-command="follow-up"] { height: auto; min-height: 48px; padding-block: 6px; align-items: start; }+.pill[data-command="follow-up"] .pill-line { padding-block: 8px; line-height: 20px; white-space: normal; overflow: visible; text-wrap: pretty; }/* the height the generated page takes before it is measured: its 5:4 stage, at most 640px wide, and the lines under it */.example-frame { display: block; width: 100%; height: calc(min(100cqw - 32px, 640px) * 0.8 + 190px); border: 0; }.skill-steps { display: grid; gap: 12px; max-width: 64ch; counter-reset: step; }diff --git a/apps/site/app/skill/page.tsx b/apps/site/app/skill/page.tsxindex 22c3866..54f2e55 100644--- a/apps/site/app/skill/page.tsx+++ b/apps/site/app/skill/page.tsx@@ -26,12 +26,13 @@ export default function Skill() {<section aria-labelledby="examples-title" className="doc-section"><h2 id="examples-title" className="doc-h2">What it draws</h2>- <p className="doc-p">Each figure below is the page the skill wrote for the line beside it, as it wrote it. Move the pointer over one.</p>+ <p className="doc-p">Each figure below is the page the skill wrote for the line beside it, as it wrote it. Where there is a second line, it is the change asked for next. Move the pointer over one.</p><div>{shown.map((e) => (<article key={e.file} className="example" data-example={e.name}><div className="example-prompt"><Command code={e.prompt} kind="prompt" label="Copy prompt" />+ {e.followUp && <Command code={e.followUp} kind="follow-up" label="Copy follow-up" />}<a className="doc-more" href={e.href}>Open the page</a></div><div className="example-figure">diff --git a/apps/site/components/command.tsx b/apps/site/components/command.tsxindex 9fcc5d0..4b3b568 100644--- a/apps/site/components/command.tsx+++ b/apps/site/components/command.tsx@@ -5,10 +5,11 @@ import { CopyIcon } from "./copy";/*** One line to type, in a pill with a copy icon. `kind` says which line it is,- * for the tests (`prompt` is an example's, `usage` the bare command); a shell- * command takes the `$` in front of it.+ * for the tests (`prompt` is an example's, `follow-up` the change asked for+ * after it, `usage` the bare command); a shell command takes the `$` in front+ * of it. A follow-up is a sentence, so it wraps instead of scrolling.*/-export function Command({ code, kind, label }: { code: string; kind: "install" | "prompt" | "usage"; label: string }) {+export function Command({ code, kind, label }: { code: string; kind: "install" | "prompt" | "follow-up" | "usage"; label: string }) {const line = useRef<HTMLElement>(null);return (<div className="pill" data-command={kind}>diff --git a/apps/site/lib/skill.ts b/apps/site/lib/skill.tsindex 0727daf..9d11a8e 100644--- a/apps/site/lib/skill.ts+++ b/apps/site/lib/skill.ts@@ -17,8 +17,8 @@ export type Example = { idea: string; file: string; followUp?: string };export const EXAMPLES: Example[] = [{ idea: "a sales funnel", file: "hairline-funnel.html" },{ idea: "a rate limiter", file: "hairline-clearance.html" },- { idea: "git branches", file: "hairline-sidings.html" },- { idea: "weather over a city", file: "hairline-storm.html" },+ { idea: "git branches", file: "hairline-sidings.html", followUp: "The rails almost disappear and the trains read as loose blocks. Make it read as a railway at a glance." },+ { idea: "weather over a city", file: "hairline-storm.html", followUp: "The cloud looks like a stack of cylinders. Make it read as a cloud at a glance." },];export type Shown = Example & { name: string; means: string; prompt: string; href: string };diff --git a/apps/site/public/skill/hairline-sidings.html b/apps/site/public/skill/hairline-sidings.htmlindex 82146ca..5c5a847 100644--- a/apps/site/public/skill/hairline-sidings.html+++ b/apps/site/public/skill/hairline-sidings.html@@ -725,25 +725,26 @@ var HL = (() => {* head, which takes the bright edge. At rest that is the trunk. The pointer* checks out the track it is over: those wagons rise and the others settle,* staggered outwards from the wagon under the pointer. Each siding's head- * carries its number in dots on the lid. The slider is the rise, in world units.+ * carries its number in dots on the lid. Wagons ride on wheeled underframes,+ * close-coupled; rails sit on sleepers and end at buffer stops. The slider is the rise, in world units.** The pattern: discrete items. Tweens, a stagger by distance, and a hit test* on a fixed plane, so a wagon rising under the pointer cannot flip the choice.*/const {- Cam, clamp, facing, fit, hull, open, prism, proj, ringAt, rings, unproj,+ Cam, clamp, facing, fit, hull, open, poly, seg, prism, proj, ringAt, rings, unproj,tween, tset, tval, tdone, flatDot, mk, place, pointer, put, register, disposer, solid,} = HL;-const PITCH = 17, WL = 13, WW = 9, GAUGE = 5, G = 17, LEAD = 24, BASE = 5.5, STEP = 45, PB = 5, TOP = 22;-const BX0 = -10, BX1 = 114, BY0 = -11, BY1 = 3 * G + 11;+const PITCH = 16, WL = 14, WW = 8, CH = 3.4, GAUGE = 5, G = 17, LEAD = 24, BASE = 7, STEP = 45, PB = 5, TOP = 22;+const BX0 = -10, BX1 = 117, BY0 = -11, BY1 = 3 * G + 11;// Each track: its read-out, its line (y), the track it leaves (-1 for the trunk) and where (xf),-// the first wagon (x0), how many wagons, and where the rails end.+// the first wagon (x0), how many wagons, and where the rails end at a buffer stop.const TRACKS = [{ tag: "main", y: 0, from: -1, xf: -6, x0: 34, n: 4, xe: 106 },{ tag: "br 1", y: G, from: 0, xf: 2, x0: 46, n: 3, xe: 100 },- { tag: "br 2", y: 2 * G, from: 1, xf: 24, x0: 58, n: 3, xe: 108 },- { tag: "br 3", y: 3 * G, from: 2, xf: 46, x0: 78, n: 2, xe: 110 },+ { tag: "br 2", y: 2 * G, from: 1, xf: 24, x0: 58, n: 3, xe: 111 },+ { tag: "br 3", y: 3 * G, from: 2, xf: 46, x0: 76, n: 2, xe: 112 },];/** The track's centre line at x: straight, or easing off its parent's line through the switch. */@@ -761,6 +762,19 @@ function rails(P, t) {return [-1, 1].map((s) => open(xs.map((x) => P(x, lineY(t, x) + (s * GAUGE) / 2, 0)))).join("");}+/** A wheel, upright on the wagon's near side at y, centred over x. */+const wheel = (P, x, y) => poly(Array.from({ length: 12 }, (_, k) => P(x + 1.5 * Math.cos((k * Math.PI) / 6), y, 1.6 + 1.5 * Math.sin((k * Math.PI) / 6))));++/** The sleepers under the rails: short ties across the track, every 4.5 units. */+function sleepers(P, t) {+ let d = "";+ for (let x = t.xf + 2; x < t.xe; x += 4.5) {+ const y = lineY(t, x);+ d += seg(P(x, y - GAUGE / 2 - 2, 0), P(x, y + GAUGE / 2 + 2, 0));+ }+ return d;+}+function mount({ stage, svg, read }, value) {const bag = disposer();let lift = value;@@ -781,15 +795,22 @@ function mount({ stage, svg, read }, value) {const g = mk("g", {}, svg);const [br, bi] = rings(BX0, BY0, BX1, BY1, 10, 2.2);put(solid(g), prism(P, front, br, bi, -PB, 0));- // Rails lie flat on the board, so they go down before any wagon.- for (const t of TRACKS) mk("path", { d: rails(P, t), class: "nf" }, g);+ // Sleepers, then rails on them: flat on the board, so they go down before anything that stands.+ for (const t of TRACKS) mk("path", { d: sleepers(P, t), class: "nf lo" }, g);+ for (const t of TRACKS) mk("path", { d: rails(P, t), class: "nf sil" }, g);- // Wagons back to front: by x + y of the centre, which holds while tracks sit further apart than a wagon is long.- wag.sort((a, b) => a.x0 + a.y0 - (b.x0 + b.y0));+ // Everything standing, back to front by x + y of its corner, which holds while tracks sit further apart than a wagon is long.+ const stops = TRACKS.map((t) => ({ stop: true, x0: t.xe - 3, y0: t.y - 4 }));+ const parts = wag.concat(stops).sort((a, b) => a.x0 + a.y0 - (b.x0 + b.y0));for (const t of TRACKS) t.cars = [];- for (const w of wag) {+ for (const w of parts) {+ if (w.stop) { const [r, ri] = rings(w.x0, w.y0, w.x0 + 3, w.y0 + 8, 1.2, 0.6); put(solid(g), prism(P, front, r, ri, 0, 4.5)); continue; }const t = TRACKS[w.k];- [w.ring, w.inner] = rings(w.x0, w.y0, w.x0 + WL, w.y0 + WW, 2.6, 1);+ // a low underframe the body rides on, and two wheels on the side that faces the viewer+ const [ur, ui] = rings(w.x0 + 2.5, w.y0 + 1.6, w.x0 + WL - 2.5, w.y0 + WW - 1.6, 1.2, 0.6);+ put(solid(g), prism(P, front, ur, ui, 0, CH));+ for (const wx of [w.x0 + 4.2, w.x0 + WL - 4.2]) mk("path", { d: wheel(P, wx, w.y0 + WW - 1.6), class: "" }, g);+ [w.ring, w.inner] = rings(w.x0, w.y0, w.x0 + WL, w.y0 + WW, 2.4, 1);w.el = solid(g);w.tw = tween(w.k === 0 ? up(t, w.i) : 0);w.drawn = NaN;@@ -800,7 +821,7 @@ function mount({ stage, svg, read }, value) {}function draw(w, h) {- put(w.el, prism(P, front, w.ring, w.inner, 0, h));+ put(w.el, prism(P, front, w.ring, w.inner, CH, h));const cx = w.x0 + WL / 2, cy = w.y0 + WW / 2, n = w.dots.length;w.dots.forEach((d, j) => place(d, P(cx + (j - (n - 1) / 2) * 2.8, cy, h)));}diff --git a/apps/site/public/skill/hairline-storm.html b/apps/site/public/skill/hairline-storm.htmlindex c3cb4a4..4366591 100644--- a/apps/site/public/skill/hairline-storm.html+++ b/apps/site/public/skill/hairline-storm.html@@ -732,24 +732,30 @@ var HL = (() => {* the rain.*/const {- Cam, clamp, facing, fit, prism, proj, rings, rrect, unproj, spring, stepS, seg,+ Cam, clamp, facing, fit, prism, proj, rings, rrect, unproj, spring, stepS, seg, poly,mk, pointer, put, register, disposer, solid,} = HL;const N = 5, CELL = 14, FOOT = 10, EXT = N * CELL, PB = 5, ZC = 46, RMAX = 24;const IN = (CELL - FOOT) / 2, LO = CELL * 0.8, HI = EXT - CELL * 0.8;const REST = [1.3 * CELL, 3.4 * CELL];-/** The cloud's puffs on its base, in radii: centre, radius, height; ordered back to front. */-const PUFFS = [[-0.32, -0.1, 0.42, 0.42], [0.15, -0.22, 0.34, 0.32], [0, 0.26, 0.3, 0.2], [0.5, 0.1, 0.3, 0.26]];/**- * Drops in cloud radii, with the share of the fall each one makes: one in the- * middle and five near it reach the roofs; seven at the rim give out half way.+ * The cloud is a cumulus: domes on one flat underside, the tallest at the back.+ * In cloud radii, across the screen (a) and towards the viewer (b), with each+ * dome's radius; ordered back to front.+ */+const DOMES = [[0.05, -0.12, 0.56], [-0.62, 0, 0.36], [0.62, -0.04, 0.4], [-0.24, 0.3, 0.34], [0.3, 0.32, 0.3]];+const SQ = Math.SQRT1_2, ARC = 24;+/**+ * Drops in cloud radii, across and towards as the domes are, with the share+ * of the fall each one makes: one in the middle and five near it reach the+ * roofs; seven at the rim give out half way.*/const DROPS = [[0, 0, 1]];[[0.42, 5, 0.3, 1], [0.8, 7, 0.1, 0.5]].forEach(([f, n, a, reach]) => {for (let k = 0; k < n; k++) {const t = a + (k / n) * Math.PI * 2;- DROPS.push([f * 0.9 * Math.cos(t), f * 0.55 * Math.sin(t), reach]);+ DROPS.push([f * 0.85 * Math.cos(t), f * 0.3 * Math.sin(t), reach]);}});@@ -758,7 +764,7 @@ function mount({ stage, svg, read }, value) {const C = Cam(45, 0.5, 2.15);const ext = [[-6, -6, -PB], [EXT + 6, EXT + 6, -PB], [EXT + 6, -6, -PB], [-6, EXT + 6, -PB]];for (const x of [LO, HI]) for (const y of [LO, HI]) {- ext.push([x - RMAX, y, ZC + RMAX * 0.6], [x + RMAX, y, ZC], [x, y - RMAX, ZC + RMAX * 0.6], [x, y + RMAX, ZC]);+ ext.push([x - RMAX * 0.7, y + RMAX * 0.7, ZC], [x + RMAX * 0.7, y - RMAX * 0.7, ZC], [x, y, ZC + RMAX * 0.7], [x + RMAX * 0.3, y + RMAX * 0.3, ZC]);}fit(C, ext, 200, 166);const P = proj(C), front = facing(C);@@ -784,9 +790,9 @@ function mount({ stage, svg, read }, value) {// The rain: one dashed line per drop, moved in the paint order as the cloud moves.const drops = DROPS.map(() => ({ el: mk("path", { class: "dash" }, g), at: null }));- // The cloud: a flat base and two puffs on it, above every tower, so it is painted last.+ // The cloud: above every tower, so it is painted last.const cloud = mk("g", {}, svg);- const base = solid(cloud), puffs = PUFFS.map(() => solid(cloud));+ const domes = DOMES.map(() => solid(cloud));const sx = spring(REST[0]), sy = spring(REST[1]), sr = spring(value);let lit = null, drawn = "";@@ -805,27 +811,42 @@ function mount({ stage, svg, read }, value) {return i < 0 || j < 0 ? plinth : c;}- /** A rounded footprint sampled finely enough that the cloud's long curves stay round. */+ /** A rounded footprint sampled finely enough that the plinth's long curves stay round. */function lobe(el, x0, y0, x1, y1, r, b, z0, z1) {const ring = rrect(x0, y0, x1, y1, r, 14), inner = rrect(x0 + b, y0 + b, x1 - b, y1 - b, r - b, 14);put(el, prism(P, front, ring, inner, z0, z1));}+ /**+ * A dome of radius q standing on the cloud's underside at (x, y). The camera+ * is orthographic, so its outline is a half circle over the front half of+ * its base ellipse. A dome has no crease: a ring drawn on it reads as a lip.+ */+ function dome(el, x, y, q) {+ const c = P(x, y, ZC), rho = P(x + q * SQ, y - q * SQ, ZC)[0] - c[0];+ const ks = (P(x + q * SQ, y + q * SQ, ZC)[1] - c[1]) / rho;+ const out = [];+ for (let k = 0; k <= ARC; k++) {+ const t = (Math.PI * k) / ARC;+ out.push([c[0] + rho * Math.cos(t), c[1] - rho * Math.sin(t)]);+ }+ for (let k = 1; k < ARC; k++) {+ const t = Math.PI + (Math.PI * k) / ARC;+ out.push([c[0] + rho * Math.cos(t), c[1] - rho * ks * Math.sin(t)]);+ }+ put(el, { sil: poly(out), crease: "" });+ }+function draw() {const cx = sx.x, cy = sy.x, R = sr.x, key = `${cx.toFixed(2)},${cy.toFixed(2)},${R.toFixed(2)}`;if (key === drawn) return;drawn = key;- const zb = ZC + R * 0.14;- lobe(base, cx - R, cy - R * 0.65, cx + R, cy + R * 0.65, R * 0.65, 1.2, ZC, zb);- PUFFS.forEach(([u, v, r, h], k) => {- const x = cx + u * R, y = cy + v * R, q = r * R;- lobe(puffs[k], x - q, y - q, x + q, y + q, q, 1, zb, zb + h * R);- });- DROPS.forEach(([u, v, reach], k) => {- const d = drops[k], x = cx + u * R, y = cy + v * R, z = roofAt(x, y);+ DOMES.forEach(([a, b, r], k) => dome(domes[k], cx + (a + b) * SQ * R, cy + (b - a) * SQ * R, r * R));+ DROPS.forEach(([a, b, reach], k) => {+ const d = drops[k], x = cx + (a + b) * SQ * R, y = cy + (b - a) * SQ * R, z = roofAt(x, y);d.el.setAttribute("d", seg(P(x, y, ZC), P(x, y, ZC - (ZC - z) * reach)));- const b = behind(x, y);- if (b !== d.at) { d.at = b; (b.el ? b.el.g : b.g).after(d.el); }+ const back = behind(x, y);+ if (back !== d.at) { d.at = back; (back.el ? back.el.g : back.g).after(d.el); }});}diff --git a/apps/site/test/skill.spec.ts b/apps/site/test/skill.spec.tsindex 202b251..71ee797 100644--- a/apps/site/test/skill.spec.ts+++ b/apps/site/test/skill.spec.ts@@ -160,3 +160,27 @@ test("the home's hero points to the skill in one quiet line under its two buttonawait expect(page).toHaveURL(/\/skill$/);await expect(page.getByRole("heading", { level: 1 })).toHaveText("Make your own figure");});++const FOLLOW_UPS: Record<string, string | undefined> = {+ funnel: undefined,+ clearance: undefined,+ sidings: "The rails almost disappear and the trains read as loose blocks. Make it read as a railway at a glance.",+ storm: "The cloud looks like a stack of cylinders. Make it read as a cloud at a glance.",+};++test("a follow-up sits under its prompt as a second line that wraps instead of scrolling, and copies on its own", async ({ page, context }) => {+ await context.grantPermissions(["clipboard-read", "clipboard-write"]);+ await page.setViewportSize({ width: 320, height: 800 });+ await page.goto("/skill");+ for (const [name, text] of Object.entries(FOLLOW_UPS)) {+ const row = page.locator(`[data-example="${name}"]`);+ const line = row.locator('[data-command="follow-up"]');+ if (!text) { await expect(line).toHaveCount(0); continue; }+ await expect(line).toHaveText(text);+ const prompt = (await row.locator('[data-command="prompt"]').boundingBox())!;+ expect((await line.boundingBox())!.y).toBeGreaterThanOrEqual(prompt.y + prompt.height);+ expect(await line.locator(".pill-line").evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(0);+ await line.locator(".icopy").click();+ expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(text);+ }+});diff --git a/apps/site/test/skill.test.ts b/apps/site/test/skill.test.tsindex 85c9990..ec26bb7 100644--- a/apps/site/test/skill.test.ts+++ b/apps/site/test/skill.test.ts@@ -34,6 +34,15 @@ describe("the skill's examples", () => {}});+ it("carry a follow-up only where the page shown came out of one", () => {+ expect(Object.fromEntries(EXAMPLES.map((e) => [e.idea, e.followUp]))).toEqual({+ "a sales funnel": undefined,+ "a rate limiter": undefined,+ "git branches": "The rails almost disappear and the trains read as loose blocks. Make it read as a railway at a glance.",+ "weather over a city": "The cloud looks like a stack of cylinders. Make it read as a cloud at a glance.",+ });+ });+it("read the meaning out of the page, escapes undone", () => {const page = '<script type="module" id="hl-figure">\nconst tray = { name: "other", means: "not this" };\nhairline({ name: "tiers", means: "A \\"funnel\\" as trays.", rules: [1], range: [0, 1, 2], mount });\n</script>';expect(declared(page, "x.html")).toEqual({ name: "tiers", means: 'A "funnel" as trays.' });