Isometric line figures that answer the pointer. For React and for anything with a DOM.
Skill page: four figures the skill drew, kept as it wrote them, and a test that fails if one is touched
Lucas Marques8f19566b9d23
diff --git a/apps/site/lib/skill.ts b/apps/site/lib/skill.tsnew file mode 100644index 0000000..ace3f8e--- /dev/null+++ b/apps/site/lib/skill.ts@@ -0,0 +1,64 @@+import { readFileSync } from "node:fs";+import { join } from "node:path";++/**+ * The skill, as the site tells it: the two commands, the examples, and the+ * page's copy as plain text, so /skill and /llms.txt say the same thing.+ * Server only: it reads the generated pages from public/skill.+ */++export const INSTALL = "npx skills add lucasmarkes/hairline";+export const COMMAND = "/hairline-create";++export type Example = { idea: string; file: string };++/** What was typed after the command, and the page the skill wrote for it. The pages are never edited. */+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" },+];++export type Shown = Example & { name: string; means: string; prompt: string; href: string };++const FIGURE = /<script type="module" id="hl-figure">([\s\S]*?)<\/script>/;+const NAME = /\bname:\s*["'`]([a-z][a-z0-9-]*)["'`]/;+const MEANS = /\bmeans:\s*(["'`])((?:\\.|(?!\1)[^\\])*)\1/;++/** The name and the meaning a generated page declares for its figure. */+export function declared(html: string, file: string): { name: string; means: string } {+ const figure = FIGURE.exec(html)?.[1] ?? "";+ // the declaration is the page's last call; a `name:` earlier in the figure's own code is not it+ const call = figure.slice(Math.max(0, figure.lastIndexOf("hairline({")));+ const name = NAME.exec(call)?.[1];+ const means = MEANS.exec(call)?.[2];+ if (!name || !means) throw new Error(`skill: ${file} is not a page made by the skill's build.mjs.`);+ return { name, means: means.replace(/\\(.)/g, "$1") };+}++/** The examples with what their pages declare. `next build` and vitest both run from apps/site. */+export function examples(): Shown[] {+ return EXAMPLES.map((e) => {+ const html = readFileSync(join(process.cwd(), "public", "skill", e.file), "utf8");+ return { ...e, ...declared(html, e.file), prompt: `${COMMAND} ${e.idea}`, href: `/skill/${e.file}` };+ });+}++export const SUMMARY = "hairline-create is a skill for coding agents. Give it an idea and it draws a new figure to Hairline's ten rules, on the same engine as the six, as one HTML file.";++export const STEPS: { title: string; text: string }[] = [+ { title: "Concepts", text: "It offers two or three concepts, one line each: the object, what the pointer does, what the read-out says. You pick one." },+ { title: "Build", text: "It writes only the figure. The engine and the page around it are pasted in as they are." },+ { title: "Check", text: "A script checks the file against the rules, then the agent looks at it in a browser." },+ { title: "Hand over", text: "You get the page, the metaphor it used, the rules it leans on, and anything it could not check." },+ { title: "Adjust", text: "Ask for changes while you use it. It edits the figure and checks again." },+];++export const FOLDER = "What you install is one folder of small text files. There is no npm install, and Node is only needed to run the checks.";++export const USE: string[] = [+ "Type the command with an idea. If you already have the metaphor, say it, and the concepts step is skipped.",+ "Out comes hairline-<name>.html: one file with no dependencies that opens from disk, holding the figure, an intensity slider and a theme switch.",+ "It runs on any agent that reads skills: Claude Code, Cursor, Codex and others.",+];diff --git a/apps/site/public/skill/hairline-clearance.html b/apps/site/public/skill/hairline-clearance.htmlnew file mode 100644index 0000000..e10c9e6--- /dev/null+++ b/apps/site/public/skill/hairline-clearance.html@@ -0,0 +1,834 @@+<!doctype html>+<html lang="en">+<head>+<meta charset="utf-8">+<meta name="viewport" content="width=device-width, initial-scale=1">+<title>Hairline figure</title>+<link rel="icon" href="data:,">+<style>+ :root { color-scheme: light; --ground: #ffffff; --ink: #232327; --muted: #6f6f78; --line: #e0e0e4; }+ @media (prefers-color-scheme: dark) {+ :root:not([data-theme="light"]) { color-scheme: dark; --ground: #08090a; --ink: #d0d6e0; --muted: #8a8c95; --line: #29292d; }+ }+ :root[data-theme="dark"] { color-scheme: dark; --ground: #08090a; --ink: #d0d6e0; --muted: #8a8c95; --line: #29292d; }+ :root[data-theme="light"] { color-scheme: light; }+ * { box-sizing: border-box; }+ body {+ margin: 0; min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;+ background: var(--ground); color: var(--ink);+ font: 13px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased;+ }+ main { width: 100%; max-width: 640px; }+ .plate { position: relative; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }+ .tag, .label, output, button { font: 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 0.02em; }+ .tag { position: absolute; top: 12px; z-index: 1; color: var(--muted); pointer-events: none; }+ #name { left: 14px; }+ #read { right: 14px; color: var(--ink); font-variant-numeric: tabular-nums; }+ .controls { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 14px; }+ .label { color: var(--muted); }+ input[type="range"] {+ flex: 1 1 96px; min-width: 0; height: 32px; margin: 0; background: transparent; cursor: pointer;+ -webkit-appearance: none; appearance: none;+ }+ input[type="range"]::-webkit-slider-runnable-track { height: 1px; background: var(--muted); }+ input[type="range"]::-webkit-slider-thumb {+ -webkit-appearance: none; width: 13px; height: 13px; margin-top: -6px; border-radius: 50%;+ border: 1px solid var(--ink); background: var(--ground);+ }+ input[type="range"]::-moz-range-track { height: 1px; background: var(--muted); }+ input[type="range"]::-moz-range-thumb { width: 11px; height: 11px; border-radius: 50%; border: 1px solid var(--ink); background: var(--ground); }+ input[type="range"]:focus-visible, button:focus-visible { outline: 1.5px solid var(--ink); outline-offset: 2px; }+ output { min-width: 4ch; text-align: right; font-variant-numeric: tabular-nums; }+ button {+ height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;+ background: transparent; color: var(--ink); cursor: pointer;+ }+ #means { margin: 14px 0 0; text-wrap: pretty; }+ #rules { margin: 6px 0 0; line-height: 1.6; }+ #error { margin: 12px 0 0; padding-left: 10px; border-left: 1px solid var(--ink); }+</style>+</head>+<body>+<main>+ <div class="plate">+ <span class="tag" id="name"></span>+ <span class="tag" id="read"></span>+ <div id="stage"></div>+ </div>+ <div class="controls">+ <label class="label" for="intensity">intensity</label>+ <input id="intensity" type="range" min="0" max="1" step="0.01" value="0.5">+ <output id="value" for="intensity"></output>+ <span class="label">theme</span>+ <button id="theme" type="button" aria-label="Switch between the light and the dark theme"></button>+ </div>+ <p id="means"></p>+ <p id="rules" class="label"></p>+ <p id="error" role="alert" hidden></p>+</main>+<script id="hl-kernel">+/* hairline kernel sha256:8e2abcbdf63c7755195ee942c39e9c8ea6a539d1147e986dd1c153559121f075 */+/*+ * HL: everything a figure may call. Read this index; the code under it is the+ * package's src/core, unchanged, and a figure should not need to read it.+ *+ * Every figure is drawn in a 400 × 320 viewBox. World space is x/y on the+ * ground and z up. Plates are filled with the ground colour and painted back+ * to front, so a nearer one covers a farther one: append in that order. At+ * the default camera, Cam(45, 0.5, S), +x runs down to the right and +y down+ * to the left, so the corner with the largest x and y is nearest the viewer:+ * append by ascending x + y, from the far corner (smallest x and y) to it.+ *+ * Camera+ * Cam(azDeg, k, S) a camera: azimuth in degrees, k = sin(elevation) (0.5 is the 2:1 view), S = scale+ * fit(C, points, cx, cy) centres the box of [x, y, z] points on (cx, cy); call it once, before proj+ * it only centres, it never scales: choose S by trying values, with the most extreme pose in points.+ * The six figures use S 1.42 to 2.12; the boxes they fit come out 230 to 310 wide and 180 to 245 tall+ * proj(C) returns P(x, y, z), which gives [sx, sy]+ * unproj(C, sx, sy, z) the world [x, y] under a screen point, on the plane at height z+ * facing(C) returns front(sample): whether a ring sample faces the camera+ * Rounded solids+ * rrect(u0, v0, u1, v1, r, n) a rounded rectangle, as a ring of samples {u, v, nu, nv}+ * circ(R, n) a circle, as a ring+ * rings(x0, y0, x1, y1, r, b) [ring, inner]: a rounded footprint and its crease ring, inset by b+ * r, the corner radius, is cut to half the shorter side. b, the crease's inset in world units+ * (0.6 to 2.2 in the figures), must stay under half the shorter side or the crease turns inside out+ * prism(P, front, ring, inner, z0, z1) {sil, crease}: a solid standing from z0 to z1, as two path strings+ * ringAt(P, ring, z) the ring's points, projected at height z+ * run(ring, keep) the one cyclic run of samples that pass keep+ * hull(points) the convex hull of screen points+ * extremes(P, ring) [left, right, nearest] samples: where dashed drops fall from+ * fillet(points, radii, n) rounds every vertex of a closed polygon; returns the new points+ * radii is an array, one radius per vertex, each cut to half its shorter edge; a single number gives NaN.+ * n is the steps round each corner, default 4: each vertex becomes n + 1 points+ * ghost(P, front, ring, z0, depth) a reflection's path {d, y0, y1}; reflect() draws it for you+ * Paths and numbers+ * poly(points) a closed path string+ * open(points) an open polyline string+ * seg(a, b) one segment between two screen points [sx, sy], as its own subpath; project world points with P first+ * clamp(v, a, b)+ * lerp(a, b, t)+ * rad(deg)+ * r2(n) two decimals+ * The continuous clock: one spring per moving number+ * spring(x, opts) at rest on x; write .t to retarget; opts {k, c, m, eps}, default k 100, c 18, m 1+ * stepS(sp, dt) advances by dt seconds; returns whether it is still moving+ * The discrete clock: a 700ms tween on (.32, .72, 0, 1)+ * tween(v, dur) at rest on v; dur defaults to 700 (ms)+ * tset(tw, to, now, delay) retargets from where it is, after delay ms: the stagger+ * the same target again does nothing, so calling it on every pointer move is safe+ * tval(tw, now) its value at now+ * tdone(tw, now) whether it has landed+ * bezier(x1, y1, x2, y2) a CSS cubic-bezier, as a function of progress+ * EASE_LIFT the lift curve itself+ * reducedMotion() true when the reader asked for less motion; springs and tweens already land at once+ * setReducedMotion(on) the loop's business, not a figure's+ * Drawing+ * mk(tag, attrs, parent) one svg element: the only way a figure makes a node+ * solid(parent) {g, sil, cr}: a group holding a silhouette path and a crease path+ * put(solid, paths) writes prism()'s {sil, crease} into solid()'s {sil, cr}: sil into sil, crease into cr+ * flatDot(parent, C, r, cls) a dot lying on the ground plane; cls is "dot", "dot m" or "dot off"+ * place(el, point) moves a dot or a circle to [sx, sy]+ * reflect(svg, parent, P, front, ring, z0, depth) a fading mirror under a solid+ * fade(svg, y0, y1, a0) a vertical fade, as a mask; returns the value for a mask attribute+ * Life+ * register(stage, tick) joins the one frame loop; tick(dt in seconds, now in ms) returns true to ask for another frame; gives {wake, unregister}+ * pointer(stage, handlers) {move(point), down(point), leave()}, points in viewBox units; returns its disposer+ * disposer() {add, on, dispose}: collects tear-down, so destroy is bag.dispose+ * The bench's business, not a figure's+ * css(lightDark)+ * inject(root)+ *+ * Classes, on path, polygon, ellipse and line. They are the whole palette; a+ * figure sets no colour, width or fill of its own.+ * (none) filled with the ground colour, medium stroke+ * sil the silhouette's stroke hi the bright stroke: the only highlight+ * lo the dim stroke nf no fill fo fill only, no stroke+ * dash a dashed guide+ * dot a bright dot dot m a medium dot dot off a dim dot+ */+var HL = (() => {+ var __defProp = Object.defineProperty;+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;+ var __getOwnPropNames = Object.getOwnPropertyNames;+ var __hasOwnProp = Object.prototype.hasOwnProperty;+ var __export = (target, all) => {+ for (var name in all)+ __defProp(target, name, { get: all[name], enumerable: true });+ };+ var __copyProps = (to, from, except, desc) => {+ if (from && typeof from === "object" || typeof from === "function") {+ for (let key of __getOwnPropNames(from))+ if (!__hasOwnProp.call(to, key) && key !== except)+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });+ }+ return to;+ };+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);++ // packages/hairline/src/core/kernel.ts+ var kernel_exports = {};+ __export(kernel_exports, {+ Cam: () => Cam,+ EASE_LIFT: () => EASE_LIFT,+ bezier: () => bezier,+ circ: () => circ,+ clamp: () => clamp,+ css: () => css,+ disposer: () => disposer,+ extremes: () => extremes,+ facing: () => facing,+ fade: () => fade,+ fillet: () => fillet,+ fit: () => fit,+ flatDot: () => flatDot,+ ghost: () => ghost,+ hull: () => hull,+ inject: () => inject,+ lerp: () => lerp,+ mk: () => mk,+ open: () => open,+ place: () => place,+ pointer: () => pointer,+ poly: () => poly,+ prism: () => prism,+ proj: () => proj,+ put: () => put,+ r2: () => r2,+ rad: () => rad,+ reducedMotion: () => reducedMotion,+ reflect: () => reflect,+ register: () => register,+ ringAt: () => ringAt,+ rings: () => rings,+ rrect: () => rrect,+ run: () => run,+ seg: () => seg,+ setReducedMotion: () => setReducedMotion,+ solid: () => solid,+ spring: () => spring,+ stepS: () => stepS,+ tdone: () => tdone,+ tset: () => tset,+ tval: () => tval,+ tween: () => tween,+ unproj: () => unproj+ });++ // packages/hairline/src/core/iso.ts+ var clamp = (v, a, b) => Math.max(a, Math.min(b, v));+ var lerp = (a, b, t) => a + (b - a) * t;+ var rad = (d) => d * Math.PI / 180;+ var r2 = (n) => Math.round(n * 100) / 100;+ var poly = (pts) => "M" + pts.map((p) => r2(p[0]) + " " + r2(p[1])).join("L") + "Z";+ var seg = (a, b) => `M${r2(a[0])} ${r2(a[1])}L${r2(b[0])} ${r2(b[1])}`;+ var open = (pts) => pts.length < 2 ? "" : "M" + pts.map((p) => r2(p[0]) + " " + r2(p[1])).join("L");+ var Cam = (azDeg, k, S) => ({ az: rad(azDeg), k, S, ox: 0, oy: 0 });+ function proj(C) {+ const c = Math.cos(C.az), s = Math.sin(C.az), zf = Math.sqrt(1 - C.k * C.k);+ return (x, y, z) => {+ const X = x * c - y * s, Y = x * s + y * c;+ return [C.ox + C.S * X, C.oy + C.S * (Y * C.k - z * zf)];+ };+ }+ function unproj(C, sx, sy, z) {+ const c = Math.cos(C.az), s = Math.sin(C.az), zf = Math.sqrt(1 - C.k * C.k);+ const X = (sx - C.ox) / C.S, Y = ((sy - C.oy) / C.S + z * zf) / C.k;+ return [X * c + Y * s, -X * s + Y * c];+ }+ function fit(C, pts, cx, cy) {+ C.ox = 0;+ C.oy = 0;+ const P = proj(C);+ let a = 1e9, b = -1e9, c = 1e9, d = -1e9;+ for (const p of pts) {+ const q = P(p[0], p[1], p[2]);+ a = Math.min(a, q[0]);+ b = Math.max(b, q[0]);+ c = Math.min(c, q[1]);+ d = Math.max(d, q[1]);+ }+ C.ox = cx - (a + b) / 2;+ C.oy = cy - (c + d) / 2;+ }+ function rrect(u0, v0, u1, v1, r, n = 4) {+ r = Math.max(0, Math.min(r, (u1 - u0) / 2, (v1 - v0) / 2));+ const out = [];+ for (const [cu, cv, a0] of [[u1 - r, v1 - r, 0], [u0 + r, v1 - r, 90], [u0 + r, v0 + r, 180], [u1 - r, v0 + r, 270]])+ for (let k = 0; k <= n; k++) {+ const a = rad(a0 + 90 * k / n), ca = Math.cos(a), sa = Math.sin(a);+ out.push({ u: cu + r * ca, v: cv + r * sa, nu: ca, nv: sa });+ }+ return out;+ }+ function circ(R, n = 96) {+ const out = [];+ for (let k = 0; k < n; k++) {+ const a = k / n * Math.PI * 2, ca = Math.cos(a), sa = Math.sin(a);+ out.push({ u: R * ca, v: R * sa, nu: ca, nv: sa });+ }+ return out;+ }+ function hull(input) {+ const pts = input.slice().sort((a, b) => a[0] - b[0] || a[1] - b[1]);+ const x = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);+ const lo = [], up = [];+ for (const p of pts) {+ while (lo.length > 1 && x(lo[lo.length - 2], lo[lo.length - 1], p) <= 0) lo.pop();+ lo.push(p);+ }+ for (let i = pts.length - 1; i >= 0; i--) {+ const p = pts[i];+ while (up.length > 1 && x(up[up.length - 2], up[up.length - 1], p) <= 0) up.pop();+ up.push(p);+ }+ lo.pop();+ up.pop();+ return lo.concat(up);+ }+ var ringAt = (P, ring, z) => ring.map((q) => P(q.u, q.v, z));+ var facing = (C) => {+ const s = Math.sin(C.az), c = Math.cos(C.az);+ return (q) => q.nu * s + q.nv * c >= -1e-6;+ };+ function run(ring, keep) {+ const n = ring.length;+ let s = -1;+ for (let i = 0; i < n; i++) if (keep(ring[i]) && !keep(ring[(i + n - 1) % n])) {+ s = i;+ break;+ }+ if (s < 0) return keep(ring[0]) ? ring.slice() : [];+ const out = [];+ for (let k = 0; k < n && keep(ring[(s + k) % n]); k++) out.push(ring[(s + k) % n]);+ return out;+ }+ function prism(P, front, ring, inner, z0, z1) {+ return {+ sil: poly(hull(ringAt(P, ring, z1).concat(ringAt(P, ring, z0)))),+ crease: inner ? open(ringAt(P, run(inner, front), z1)) : ""+ };+ }+ var rings = (x0, y0, x1, y1, r, b) => [+ rrect(x0, y0, x1, y1, r),+ rrect(x0 + b, y0 + b, x1 - b, y1 - b, Math.max(0.3, r - b))+ ];+ function extremes(P, ring) {+ const pr = ring.map((q) => P(q.u, q.v, 0));+ let a = 0, b = 0, c = 0;+ pr.forEach((p, k) => {+ if (p[0] < pr[a][0]) a = k;+ if (p[0] > pr[b][0]) b = k;+ if (p[1] > pr[c][1]) c = k;+ });+ return [ring[a], ring[b], ring[c]];+ }+ function fillet(pts, rs, n = 4) {+ const m = pts.length, out = [];+ for (let i = 0; i < m; i++) {+ const a = pts[(i + m - 1) % m], p = pts[i], b = pts[(i + 1) % m];+ const la = Math.hypot(a[0] - p[0], a[1] - p[1]), lb = Math.hypot(b[0] - p[0], b[1] - p[1]);+ const t = Math.min(rs[i], la / 2, lb / 2);+ const p1 = [p[0] + (a[0] - p[0]) / la * t, p[1] + (a[1] - p[1]) / la * t];+ const p2 = [p[0] + (b[0] - p[0]) / lb * t, p[1] + (b[1] - p[1]) / lb * t];+ for (let k = 0; k <= n; k++) {+ const s = k / n, w = 1 - s;+ out.push([w * w * p1[0] + 2 * w * s * p[0] + s * s * p2[0], w * w * p1[1] + 2 * w * s * p[1] + s * s * p2[1]]);+ }+ }+ return out;+ }+ function ghost(P, front, ring, z0, depth) {+ const f = run(ring, front), lowP = ringAt(P, f, z0 - depth);+ return {+ d: open(lowP) + [f[0], f[f.length - 1]].map((q) => seg(P(q.u, q.v, z0), P(q.u, q.v, z0 - depth))).join(""),+ y0: Math.min(...ringAt(P, f, z0).map((p) => p[1])),+ y1: Math.max(...lowP.map((p) => p[1])) + 2+ };+ }++ // packages/hairline/src/core/motion.ts+ var reduced = false;+ var setReducedMotion = (on) => {+ reduced = on;+ };+ var reducedMotion = () => reduced;+ function spring(x, o = {}) {+ return { x, v: 0, t: x, k: o.k ?? 100, c: o.c ?? 18, m: o.m ?? 1, eps: o.eps ?? 0.01 };+ }+ function stepS(sp, dt) {+ if (reduced) {+ sp.x = sp.t;+ sp.v = 0;+ return false;+ }+ const n = Math.max(1, Math.ceil(dt * 240)), h = dt / n;+ for (let i = 0; i < n; i++) {+ const a = (-sp.k * (sp.x - sp.t) - sp.c * sp.v) / sp.m;+ sp.v += a * h;+ sp.x += sp.v * h;+ }+ if (Math.abs(sp.x - sp.t) < sp.eps && Math.abs(sp.v) < sp.eps * 10) {+ sp.x = sp.t;+ sp.v = 0;+ return false;+ }+ return true;+ }+ function bezier(x1, y1, x2, y2) {+ const cx = 3 * x1, bx = 3 * (x2 - x1) - cx, ax = 1 - cx - bx;+ const cy = 3 * y1, by = 3 * (y2 - y1) - cy, ay = 1 - cy - by;+ const X = (u) => ((ax * u + bx) * u + cx) * u;+ const Y = (u) => ((ay * u + by) * u + cy) * u;+ const dX = (u) => (3 * ax * u + 2 * bx) * u + cx;+ return (t) => {+ if (t <= 0) return 0;+ if (t >= 1) return 1;+ let u = t;+ for (let i = 0; i < 8; i++) {+ const e = X(u) - t;+ if (Math.abs(e) < 1e-5) break;+ const d = dX(u);+ if (Math.abs(d) < 1e-6) break;+ u -= e / d;+ }+ if (!(u >= 0 && u <= 1) || Math.abs(X(u) - t) > 1e-4) {+ let lo = 0, hi = 1;+ u = t;+ for (let i = 0; i < 24; i++) {+ if (X(u) < t) lo = u;+ else hi = u;+ u = (lo + hi) / 2;+ }+ }+ return Y(u);+ };+ }+ var EASE_LIFT = bezier(0.32, 0.72, 0, 1);+ var tween = (v, dur = 700) => ({ from: v, to: v, t0: -1e9, dur });+ var tval = (tw, now) => {+ const p = clamp((now - tw.t0) / tw.dur, 0, 1);+ return tw.from + (tw.to - tw.from) * (reduced ? 1 : EASE_LIFT(p));+ };+ var tset = (tw, to, now, delay) => {+ if (tw.to === to) return;+ tw.from = tval(tw, now);+ tw.to = to;+ tw.t0 = now + delay;+ };+ var tdone = (tw, now) => reduced || now >= tw.t0 + tw.dur;++ // packages/hairline/src/core/stage.ts+ var NS = "http://www.w3.org/2000/svg";+ function mk(tag, attrs, parent) {+ const e = document.createElementNS(NS, tag);+ if (attrs) for (const k in attrs) e.setAttribute(k, String(attrs[k]));+ if (parent) parent.appendChild(e);+ return e;+ }+ function solid(parent) {+ const g = mk("g", {}, parent);+ return { g, sil: mk("path", { class: "sil" }, g), cr: mk("path", { class: "nf lo" }, g) };+ }+ var put = (el, s) => {+ el.sil.setAttribute("d", s.sil);+ el.cr.setAttribute("d", s.crease);+ };+ var flatDot = (parent, C, r, cls) => mk("ellipse", { rx: r2(r * C.S), ry: r2(r * C.S * C.k), class: cls }, parent);+ var place = (el, q) => {+ el.setAttribute("cx", String(r2(q[0])));+ el.setAttribute("cy", String(r2(q[1])));+ };+ var fid = 0;+ function fade(svg, y0, y1, a0 = 0.7) {+ const id = "hl-fd" + ++fid, defs = mk("defs", {}, svg);+ const lg = mk("linearGradient", { id: id + "g", gradientUnits: "userSpaceOnUse", x1: 0, y1: r2(y0), x2: 0, y2: r2(y1) }, defs);+ mk("stop", { offset: 0, "stop-color": "#fff", "stop-opacity": a0 }, lg);+ mk("stop", { offset: 1, "stop-color": "#fff", "stop-opacity": 0 }, lg);+ const m = mk("mask", { id, maskUnits: "userSpaceOnUse", x: 0, y: 0, width: 400, height: 320 }, defs);+ mk("rect", { x: 0, y: 0, width: 400, height: 320, fill: `url(#${id}g)` }, m);+ return `url(#${id})`;+ }+ function reflect(svg, parent, P, front, ring, z0, depth) {+ const r = ghost(P, front, ring, z0, depth);+ const gh = mk("g", { class: "ghost", mask: fade(svg, r.y0, r.y1) }, parent);+ mk("path", { d: r.d }, gh);+ }+ var boards = [];+ var byStage = /* @__PURE__ */ new Map();+ var raf = 0;+ var last = 0;+ var io = null;+ var rm = null;+ function frame(now) {+ const dt = Math.min(0.05, Math.max(0, (now - last) / 1e3));+ last = now;+ let any = false;+ for (const b of boards.slice()) if (b.vis && b.awake) {+ b.awake = !!b.tick(dt, now);+ any = any || b.awake;+ }+ raf = any ? requestAnimationFrame(frame) : 0;+ }+ function wake(b) {+ b.awake = true;+ if (!raf) {+ last = performance.now();+ raf = requestAnimationFrame(frame);+ }+ }+ var onMotion = () => {+ setReducedMotion(!!rm?.matches);+ boards.forEach(wake);+ };+ function start() {+ if (io) return;+ io = new IntersectionObserver((es) => {+ for (const e of es) {+ const b = byStage.get(e.target);+ if (!b) continue;+ b.vis = e.isIntersecting;+ if (b.vis) wake(b);+ }+ }, { rootMargin: "80px" });+ rm = matchMedia("(prefers-reduced-motion: reduce)");+ setReducedMotion(rm.matches);+ rm.addEventListener("change", onMotion);+ }+ function stop() {+ if (raf) cancelAnimationFrame(raf);+ raf = 0;+ io?.disconnect();+ io = null;+ rm?.removeEventListener("change", onMotion);+ rm = null;+ }+ function register(stage, tick) {+ start();+ const b = { stage, tick, vis: false, awake: true };+ boards.push(b);+ byStage.set(stage, b);+ io.observe(stage);+ tick(0, performance.now());+ let gone = false;+ return {+ wake: () => {+ if (!gone) wake(b);+ },+ unregister: () => {+ if (gone) return;+ gone = true;+ boards = boards.filter((x) => x !== b);+ if (byStage.get(stage) === b) {+ byStage.delete(stage);+ io?.unobserve(stage);+ }+ if (!boards.length) stop();+ }+ };+ }+ function pointer(stage, on) {+ let tm = 0;+ const pt = (e) => {+ const r = stage.getBoundingClientRect();+ return [(e.clientX - r.left) / r.width * 400, (e.clientY - r.top) / r.height * 320];+ };+ const move = (e) => {+ clearTimeout(tm);+ on.move(pt(e), e);+ };+ const down = (e) => {+ clearTimeout(tm);+ if (e.pointerType !== "mouse") stage.releasePointerCapture?.(e.pointerId);+ if (on.down) on.down(pt(e), e);+ else on.move(pt(e), e);+ };+ const leave = (e) => {+ clearTimeout(tm);+ tm = window.setTimeout(() => on.leave(e), e.pointerType === "mouse" ? 0 : 1400);+ };+ stage.addEventListener("pointermove", move);+ stage.addEventListener("pointerdown", down);+ stage.addEventListener("pointerleave", leave);+ return () => {+ clearTimeout(tm);+ stage.removeEventListener("pointermove", move);+ stage.removeEventListener("pointerdown", down);+ stage.removeEventListener("pointerleave", leave);+ };+ }+ function disposer() {+ let fns = [];+ return {+ add: (fn) => {+ fns.push(fn);+ },+ on: (target, type, fn, opts) => {+ const h = fn;+ target.addEventListener(type, h, opts);+ fns.push(() => target.removeEventListener(type, h, opts));+ },+ dispose: () => {+ const run2 = fns;+ fns = [];+ for (let i = run2.length - 1; i >= 0; i--) run2[i]();+ }+ };+ }++ // packages/hairline/src/core/styles.ts+ var LIGHT = { plate: "#ffffff", hi: "#232327", edge: "#a4a4ac", mid: "#c3c3c9", lo: "#e0e0e4" };+ var DARK = { plate: "#08090a", hi: "#d0d6e0", edge: "#5b5d64", mid: "#3e3e44", lo: "#29292d" };+ var KEYS = ["plate", "hi", "edge", "mid", "lo"];+ var vars = (p) => KEYS.map((k) => `--hl-${k}:var(--hairline-${k},${p[k]});`).join("");+ var EASE = "cubic-bezier(0.5,0,0.1,1)";+ var SVG = ":where([data-hairline]>svg)";+ function css(lightDark) {+ const both = Object.fromEntries(KEYS.map((k) => [k, `light-dark(${LIGHT[k]},${DARK[k]})`]));+ return [+ // the box, and the palette: light unless something below says otherwise+ `:where([data-hairline]){display:block;position:relative;aspect-ratio:5/4;touch-action:pan-y;user-select:none;-webkit-user-select:none;--hl-sw:var(--hairline-stroke,0.9);${vars(LIGHT)}}`,+ // the page's color-scheme+ lightDark ? `:where([data-hairline]){${vars(both)}}` : "",+ // an ancestor that says dark+ `:where(.dark,[data-theme="dark"]) :where([data-hairline]){${vars(DARK)}}`,+ // the figure's own theme option+ `:where([data-hairline][data-hairline-theme="light"]){${vars(LIGHT)}}`,+ `:where([data-hairline][data-hairline-theme="dark"]){${vars(DARK)}}`,+ `:where([data-hairline]:focus-visible){outline:1.5px solid var(--hl-hi);outline-offset:2px}`,+ `${SVG}{position:absolute;inset:0;width:100%;height:100%;display:block}`,+ // Riffle's live region: read, not seen+ `:where([data-hairline]>[data-hairline-live]){position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap}`,+ // the drawing: plates are filled with the plate colour and painted back to front+ `${SVG} :where(path,polygon,ellipse,line){fill:var(--hl-plate);stroke:var(--hl-mid);stroke-width:var(--hl-sw);vector-effect:non-scaling-stroke;stroke-linejoin:round;stroke-linecap:round;transition:stroke 260ms ${EASE}}`,+ `${SVG} :where(.nf){fill:none}`,+ `${SVG} :where(.fo){stroke:none}`,+ `${SVG} :where(.sil){stroke:var(--hl-edge)}`,+ `${SVG} :where(.hi){stroke:var(--hl-hi)}`,+ `${SVG} :where(.lo){stroke:var(--hl-lo)}`,+ `${SVG} :where(.dash){stroke-dasharray:1 3}`,+ `${SVG} :where(.dot){stroke:none;fill:var(--hl-hi);transition:fill 260ms ${EASE}}`,+ `${SVG} :where(.dot.m){fill:var(--hl-edge)}`,+ `${SVG} :where(.dot.off){fill:var(--hl-lo)}`,+ `${SVG} :where(.ghost path){fill:none;stroke:var(--hl-mid)}`+ ].join("");+ }+ var done = /* @__PURE__ */ new WeakSet();+ function inject(root) {+ if (done.has(root)) return;+ done.add(root);+ const doc = root.nodeType === 9 ? root : root.ownerDocument;+ const win = doc.defaultView;+ const text = css(!!win?.CSS?.supports?.("color", "light-dark(#000,#fff)"));+ if (win && "adoptedStyleSheets" in root) {+ try {+ const sheet = new win.CSSStyleSheet();+ sheet.replaceSync(text);+ root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet];+ return;+ } catch {+ }+ }+ const style = doc.createElement("style");+ style.setAttribute("data-hairline-style", "");+ style.textContent = text;+ (root.nodeType === 9 ? doc.head ?? doc.documentElement : root).appendChild(style);+ }+ return __toCommonJS(kernel_exports);+})();+/* /hairline kernel */+</script>+<script id="hl-bench">+/*+ * The bench: the page a figure is shown on. It makes the host and the svg the+ * way the package's mount does, hands them to the figure, and owns everything+ * around it: the read-out, the slider, the theme, the line under the stage.+ */+(() => {+ const RULES = ["hit", "order", "reach", "accent", "rest", "honesty", "cost", "clock", "radius", "quiet"];+ const $ = (id) => document.getElementById(id);+ const root = document.documentElement, params = new URLSearchParams(location.search);++ /* the theme: the system's until the switch is pressed, then the switch's */+ const dark = () => (root.dataset.theme ? root.dataset.theme === "dark" : matchMedia("(prefers-color-scheme: dark)").matches);+ const label = () => { $("theme").textContent = dark() ? "dark" : "light"; };+ $("theme").addEventListener("click", () => { root.dataset.theme = dark() ? "light" : "dark"; label(); });+ /* ?theme=light or ?theme=dark wins over the system's, as pressing the switch does */+ if (["light", "dark"].includes(params.get("theme"))) root.dataset.theme = params.get("theme");+ label();++ /* ?intensity=0 sets the slider before the figure mounts, for a look at either end */+ const i = (params.get("intensity") || "").trim();+ if (i && Number.isFinite(Number(i))) $("intensity").value = String(Math.min(1, Math.max(0, Number(i))));++ /* ?w=240 narrows the page, for a look at the size of a thumbnail */+ const w = Number(params.get("w"));+ if (w > 0) document.querySelector("main").style.maxWidth = w + "px";++ /* a figure that fails says so under the stage, instead of leaving an empty plate */+ addEventListener("error", (e) => {+ $("error").hidden = false;+ $("error").textContent = String((e.error && e.error.message) || e.message);+ });++ let mounted = false;+ window.hairline = (figure) => {+ if (mounted) throw new Error("hairline: one figure per page.");+ mounted = true;+ const stage = $("stage"), slider = $("intensity");++ /* intensity to the figure's own number: two straight lines that meet at 0.5, as in the package */+ const [lo, mid, hi] = figure.range;+ const at = (i) => Math.round((i <= 0.5 ? lo + (i / 0.5) * (mid - lo) : mid + ((i - 0.5) / 0.5) * (hi - mid)) * 1000) / 1000;++ HL.inject(document);+ stage.setAttribute("data-hairline", figure.name);+ stage.setAttribute("role", "img");+ stage.setAttribute("aria-label", figure.means);+ const svg = HL.mk("svg", { viewBox: "0 0 400 320", "aria-hidden": "true" }, stage);++ let text = null;+ const read = {+ get textContent() { return text; },+ set textContent(value) { text = value == null ? "" : String(value); $("read").textContent = text; },+ };++ document.title = "Hairline · " + figure.name;+ $("name").textContent = figure.name;+ $("means").textContent = figure.means;+ $("rules").textContent = figure.rules.map((n) => String(n).padStart(2, "0") + " " + RULES[n - 1]).join(" · ");+ const show = () => { $("value").textContent = String(at(Number(slider.value))); };+ show();++ const handle = figure.mount({ stage, svg, read }, at(Number(slider.value)));+ if (text === null) read.textContent = "rest";+ slider.addEventListener("input", () => { show(); handle.set(at(Number(slider.value))); });+ window.hairline.figure = handle;++ /* ?at=200,160 holds the pointer at a viewBox point, for a picture of the answer without a mouse */+ const p = (params.get("at") || "").split(",").map(Number);+ if (p.length === 2 && p.every(Number.isFinite)) {+ const r = stage.getBoundingClientRect();+ stage.dispatchEvent(new PointerEvent("pointermove", {+ pointerType: "mouse", pointerId: 1, bubbles: true,+ clientX: r.left + (p[0] / 400) * r.width, clientY: r.top + (p[1] / 320) * r.height,+ }));+ }+ };+})();+</script>+<script type="module" id="hl-figure">+/**+ * Clearance: a rate limiter as twelve columns of requests, one per second,+ * standing in a row on a plinth under a clearance bar hung at the limit. The+ * pointer is a burst: the columns near it grow, falling off with distance,+ * each on its own spring, and none passes the bar. At rest the traffic has one+ * peak already cut flat at the bar, and the bar carries the bright stroke; the+ * column under the pointer takes it from the bar. The slider is the burst's+ * radius, in seconds.+ *+ * The pattern: a continuous field along one row. The hit test is the+ * pointer's screen x against the columns' resting centres, which never move.+ */+const {+ Cam, clamp, facing, fit, prism, proj, rings, spring, stepS,+ mk, pointer, put, register, disposer, solid,+} = HL;++const N = 12, GAP = 14, RAD = 5, CAP = 40, BURST = 64, PB = 5;+const X1 = (N - 1) * GAP, PX0 = -22, PX1 = X1 + 22, PY0 = -10, PY1 = 10;++/** The share of the burst at u radii from the pointer: 1 → .31 at 42% → .09 at the edge and beyond. */+const falloff = (u) =>+ u <= 0 ? 1 : u <= 0.417 ? 1 - (u / 0.417) * 0.6875 : u <= 1 ? 0.3125 - ((u - 0.417) / 0.583) * 0.2185 : 0.094;++/** The traffic at rest: one peak over the limit, one hill under it. */+const demand = (i) => 9 + 44 * Math.exp(-((i - 2.6) ** 2) / 2.2) + 22 * Math.exp(-((i - 8.4) ** 2) / 1.8);++function mount({ stage, svg, read }, value) {+ const bag = disposer();+ const C = Cam(45, 0.5, 1.85);+ const box = [];+ for (const x of [PX0, PX1]) for (const y of [PY0, PY1]) for (const z of [-PB, CAP + 4]) box.push([x, y, z]);+ fit(C, box, 200, 166);+ const P = proj(C), front = facing(C);+ let R = value, over = null;++ const g = mk("g", {}, svg);+ const slab = (x0, y0, x1, y1, r, b, z0, z1) => {+ const [ring, inner] = rings(x0, y0, x1, y1, r, b), el = solid(g);+ put(el, prism(P, front, ring, inner, z0, z1));+ return el;+ };+ // Back to front: the plinth, the far post, the columns by ascending x, the+ // near post. The bar spans the row above every column, so it is painted last.+ slab(PX0, PY0, PX1, PY1, 8, 2.2, -PB, 0);+ slab(-16, -5, -12, -1, 2, 0.7, 0, CAP);+ const cols = [];+ for (let i = 0; i < N; i++) {+ const x = i * GAP, [ring, inner] = rings(x - RAD, -RAD, x + RAD, RAD, RAD, 1.2);+ const h0 = Math.min(CAP, demand(i));+ cols.push({ i, h0, ring, inner, sp: spring(h0, { eps: 0.04 }), el: solid(g), drawn: NaN });+ }+ slab(X1 + 12, -5, X1 + 16, -1, 2, 0.7, 0, CAP);+ const bar = slab(-17, -5, X1 + 17, -1, 2, 0.7, CAP, CAP + 3.5);++ // The columns' resting centres on screen: x is linear in i, and none of it moves.+ const sx0 = P(0, 0, 0)[0], step = P(GAP, 0, 0)[0] - sx0;+ function pick(p) {+ const a = (p[0] - sx0) / step;+ if (a < -0.6 || a > N - 0.4) return null;+ const x = clamp(a, 0, N - 1) * GAP;+ if (p[1] < P(x, 0, CAP + 12)[1] || p[1] > P(x, PY1, -PB)[1] + 6) return null;+ return a;+ }++ function drawCol(c) {+ const h = Math.max(0.6, c.sp.x);+ if (h === c.drawn) return;+ c.drawn = h;+ put(c.el, prism(P, front, c.ring, c.inner, 0, h));+ }++ const B = register(stage, (dt) => {+ let m = false;+ for (const c of cols) { if (stepS(c.sp, dt)) m = true; drawCol(c); }+ return m;+ });+ bag.add(B.unregister);++ function retarget() {+ const k = over === null ? -1 : clamp(Math.round(over), 0, N - 1);+ for (const c of cols) {+ c.sp.t = over === null ? c.h0 : Math.min(CAP, demand(c.i) + BURST * falloff(Math.abs(c.i - over) / R));+ c.el.sil.classList.toggle("hi", c.i === k);+ }+ bar.sil.classList.toggle("hi", k < 0);+ if (k < 0) read.textContent = "rest";+ else read.textContent = `s${String(k + 1).padStart(2, "0")}` + (cols[k].sp.t >= CAP ? " held" : "");+ B.wake();+ }+ retarget();++ bag.add(pointer(stage, {+ move: (p) => { over = pick(p); retarget(); },+ leave: () => { over = null; retarget(); },+ }));+ bag.add(() => svg.replaceChildren());++ return {+ set: (v) => { R = v; if (over !== null) retarget(); },+ destroy: bag.dispose,+ };+}++hairline({+ name: "clearance",+ means: "Each second is a column of requests: a burst lifts the ones near the pointer, and none of them gets past the bar.",+ rules: [1, 3, 5, 9],+ range: [1.5, 3, 5],+ mount,+});+</script>+</body>+</html>diff --git a/apps/site/public/skill/hairline-funnel.html b/apps/site/public/skill/hairline-funnel.htmlnew file mode 100644index 0000000..dc6fbe3--- /dev/null+++ b/apps/site/public/skill/hairline-funnel.html@@ -0,0 +1,849 @@+<!doctype html>+<html lang="en">+<head>+<meta charset="utf-8">+<meta name="viewport" content="width=device-width, initial-scale=1">+<title>Hairline figure</title>+<link rel="icon" href="data:,">+<style>+ :root { color-scheme: light; --ground: #ffffff; --ink: #232327; --muted: #6f6f78; --line: #e0e0e4; }+ @media (prefers-color-scheme: dark) {+ :root:not([data-theme="light"]) { color-scheme: dark; --ground: #08090a; --ink: #d0d6e0; --muted: #8a8c95; --line: #29292d; }+ }+ :root[data-theme="dark"] { color-scheme: dark; --ground: #08090a; --ink: #d0d6e0; --muted: #8a8c95; --line: #29292d; }+ :root[data-theme="light"] { color-scheme: light; }+ * { box-sizing: border-box; }+ body {+ margin: 0; min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;+ background: var(--ground); color: var(--ink);+ font: 13px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased;+ }+ main { width: 100%; max-width: 640px; }+ .plate { position: relative; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }+ .tag, .label, output, button { font: 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 0.02em; }+ .tag { position: absolute; top: 12px; z-index: 1; color: var(--muted); pointer-events: none; }+ #name { left: 14px; }+ #read { right: 14px; color: var(--ink); font-variant-numeric: tabular-nums; }+ .controls { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 14px; }+ .label { color: var(--muted); }+ input[type="range"] {+ flex: 1 1 96px; min-width: 0; height: 32px; margin: 0; background: transparent; cursor: pointer;+ -webkit-appearance: none; appearance: none;+ }+ input[type="range"]::-webkit-slider-runnable-track { height: 1px; background: var(--muted); }+ input[type="range"]::-webkit-slider-thumb {+ -webkit-appearance: none; width: 13px; height: 13px; margin-top: -6px; border-radius: 50%;+ border: 1px solid var(--ink); background: var(--ground);+ }+ input[type="range"]::-moz-range-track { height: 1px; background: var(--muted); }+ input[type="range"]::-moz-range-thumb { width: 11px; height: 11px; border-radius: 50%; border: 1px solid var(--ink); background: var(--ground); }+ input[type="range"]:focus-visible, button:focus-visible { outline: 1.5px solid var(--ink); outline-offset: 2px; }+ output { min-width: 4ch; text-align: right; font-variant-numeric: tabular-nums; }+ button {+ height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;+ background: transparent; color: var(--ink); cursor: pointer;+ }+ #means { margin: 14px 0 0; text-wrap: pretty; }+ #rules { margin: 6px 0 0; line-height: 1.6; }+ #error { margin: 12px 0 0; padding-left: 10px; border-left: 1px solid var(--ink); }+</style>+</head>+<body>+<main>+ <div class="plate">+ <span class="tag" id="name"></span>+ <span class="tag" id="read"></span>+ <div id="stage"></div>+ </div>+ <div class="controls">+ <label class="label" for="intensity">intensity</label>+ <input id="intensity" type="range" min="0" max="1" step="0.01" value="0.5">+ <output id="value" for="intensity"></output>+ <span class="label">theme</span>+ <button id="theme" type="button" aria-label="Switch between the light and the dark theme"></button>+ </div>+ <p id="means"></p>+ <p id="rules" class="label"></p>+ <p id="error" role="alert" hidden></p>+</main>+<script id="hl-kernel">+/* hairline kernel sha256:8e2abcbdf63c7755195ee942c39e9c8ea6a539d1147e986dd1c153559121f075 */+/*+ * HL: everything a figure may call. Read this index; the code under it is the+ * package's src/core, unchanged, and a figure should not need to read it.+ *+ * Every figure is drawn in a 400 × 320 viewBox. World space is x/y on the+ * ground and z up. Plates are filled with the ground colour and painted back+ * to front, so a nearer one covers a farther one: append in that order. At+ * the default camera, Cam(45, 0.5, S), +x runs down to the right and +y down+ * to the left, so the corner with the largest x and y is nearest the viewer:+ * append by ascending x + y, from the far corner (smallest x and y) to it.+ *+ * Camera+ * Cam(azDeg, k, S) a camera: azimuth in degrees, k = sin(elevation) (0.5 is the 2:1 view), S = scale+ * fit(C, points, cx, cy) centres the box of [x, y, z] points on (cx, cy); call it once, before proj+ * it only centres, it never scales: choose S by trying values, with the most extreme pose in points.+ * The six figures use S 1.42 to 2.12; the boxes they fit come out 230 to 310 wide and 180 to 245 tall+ * proj(C) returns P(x, y, z), which gives [sx, sy]+ * unproj(C, sx, sy, z) the world [x, y] under a screen point, on the plane at height z+ * facing(C) returns front(sample): whether a ring sample faces the camera+ * Rounded solids+ * rrect(u0, v0, u1, v1, r, n) a rounded rectangle, as a ring of samples {u, v, nu, nv}+ * circ(R, n) a circle, as a ring+ * rings(x0, y0, x1, y1, r, b) [ring, inner]: a rounded footprint and its crease ring, inset by b+ * r, the corner radius, is cut to half the shorter side. b, the crease's inset in world units+ * (0.6 to 2.2 in the figures), must stay under half the shorter side or the crease turns inside out+ * prism(P, front, ring, inner, z0, z1) {sil, crease}: a solid standing from z0 to z1, as two path strings+ * ringAt(P, ring, z) the ring's points, projected at height z+ * run(ring, keep) the one cyclic run of samples that pass keep+ * hull(points) the convex hull of screen points+ * extremes(P, ring) [left, right, nearest] samples: where dashed drops fall from+ * fillet(points, radii, n) rounds every vertex of a closed polygon; returns the new points+ * radii is an array, one radius per vertex, each cut to half its shorter edge; a single number gives NaN.+ * n is the steps round each corner, default 4: each vertex becomes n + 1 points+ * ghost(P, front, ring, z0, depth) a reflection's path {d, y0, y1}; reflect() draws it for you+ * Paths and numbers+ * poly(points) a closed path string+ * open(points) an open polyline string+ * seg(a, b) one segment between two screen points [sx, sy], as its own subpath; project world points with P first+ * clamp(v, a, b)+ * lerp(a, b, t)+ * rad(deg)+ * r2(n) two decimals+ * The continuous clock: one spring per moving number+ * spring(x, opts) at rest on x; write .t to retarget; opts {k, c, m, eps}, default k 100, c 18, m 1+ * stepS(sp, dt) advances by dt seconds; returns whether it is still moving+ * The discrete clock: a 700ms tween on (.32, .72, 0, 1)+ * tween(v, dur) at rest on v; dur defaults to 700 (ms)+ * tset(tw, to, now, delay) retargets from where it is, after delay ms: the stagger+ * the same target again does nothing, so calling it on every pointer move is safe+ * tval(tw, now) its value at now+ * tdone(tw, now) whether it has landed+ * bezier(x1, y1, x2, y2) a CSS cubic-bezier, as a function of progress+ * EASE_LIFT the lift curve itself+ * reducedMotion() true when the reader asked for less motion; springs and tweens already land at once+ * setReducedMotion(on) the loop's business, not a figure's+ * Drawing+ * mk(tag, attrs, parent) one svg element: the only way a figure makes a node+ * solid(parent) {g, sil, cr}: a group holding a silhouette path and a crease path+ * put(solid, paths) writes prism()'s {sil, crease} into solid()'s {sil, cr}: sil into sil, crease into cr+ * flatDot(parent, C, r, cls) a dot lying on the ground plane; cls is "dot", "dot m" or "dot off"+ * place(el, point) moves a dot or a circle to [sx, sy]+ * reflect(svg, parent, P, front, ring, z0, depth) a fading mirror under a solid+ * fade(svg, y0, y1, a0) a vertical fade, as a mask; returns the value for a mask attribute+ * Life+ * register(stage, tick) joins the one frame loop; tick(dt in seconds, now in ms) returns true to ask for another frame; gives {wake, unregister}+ * pointer(stage, handlers) {move(point), down(point), leave()}, points in viewBox units; returns its disposer+ * disposer() {add, on, dispose}: collects tear-down, so destroy is bag.dispose+ * The bench's business, not a figure's+ * css(lightDark)+ * inject(root)+ *+ * Classes, on path, polygon, ellipse and line. They are the whole palette; a+ * figure sets no colour, width or fill of its own.+ * (none) filled with the ground colour, medium stroke+ * sil the silhouette's stroke hi the bright stroke: the only highlight+ * lo the dim stroke nf no fill fo fill only, no stroke+ * dash a dashed guide+ * dot a bright dot dot m a medium dot dot off a dim dot+ */+var HL = (() => {+ var __defProp = Object.defineProperty;+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;+ var __getOwnPropNames = Object.getOwnPropertyNames;+ var __hasOwnProp = Object.prototype.hasOwnProperty;+ var __export = (target, all) => {+ for (var name in all)+ __defProp(target, name, { get: all[name], enumerable: true });+ };+ var __copyProps = (to, from, except, desc) => {+ if (from && typeof from === "object" || typeof from === "function") {+ for (let key of __getOwnPropNames(from))+ if (!__hasOwnProp.call(to, key) && key !== except)+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });+ }+ return to;+ };+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);++ // packages/hairline/src/core/kernel.ts+ var kernel_exports = {};+ __export(kernel_exports, {+ Cam: () => Cam,+ EASE_LIFT: () => EASE_LIFT,+ bezier: () => bezier,+ circ: () => circ,+ clamp: () => clamp,+ css: () => css,+ disposer: () => disposer,+ extremes: () => extremes,+ facing: () => facing,+ fade: () => fade,+ fillet: () => fillet,+ fit: () => fit,+ flatDot: () => flatDot,+ ghost: () => ghost,+ hull: () => hull,+ inject: () => inject,+ lerp: () => lerp,+ mk: () => mk,+ open: () => open,+ place: () => place,+ pointer: () => pointer,+ poly: () => poly,+ prism: () => prism,+ proj: () => proj,+ put: () => put,+ r2: () => r2,+ rad: () => rad,+ reducedMotion: () => reducedMotion,+ reflect: () => reflect,+ register: () => register,+ ringAt: () => ringAt,+ rings: () => rings,+ rrect: () => rrect,+ run: () => run,+ seg: () => seg,+ setReducedMotion: () => setReducedMotion,+ solid: () => solid,+ spring: () => spring,+ stepS: () => stepS,+ tdone: () => tdone,+ tset: () => tset,+ tval: () => tval,+ tween: () => tween,+ unproj: () => unproj+ });++ // packages/hairline/src/core/iso.ts+ var clamp = (v, a, b) => Math.max(a, Math.min(b, v));+ var lerp = (a, b, t) => a + (b - a) * t;+ var rad = (d) => d * Math.PI / 180;+ var r2 = (n) => Math.round(n * 100) / 100;+ var poly = (pts) => "M" + pts.map((p) => r2(p[0]) + " " + r2(p[1])).join("L") + "Z";+ var seg = (a, b) => `M${r2(a[0])} ${r2(a[1])}L${r2(b[0])} ${r2(b[1])}`;+ var open = (pts) => pts.length < 2 ? "" : "M" + pts.map((p) => r2(p[0]) + " " + r2(p[1])).join("L");+ var Cam = (azDeg, k, S) => ({ az: rad(azDeg), k, S, ox: 0, oy: 0 });+ function proj(C) {+ const c = Math.cos(C.az), s = Math.sin(C.az), zf = Math.sqrt(1 - C.k * C.k);+ return (x, y, z) => {+ const X = x * c - y * s, Y = x * s + y * c;+ return [C.ox + C.S * X, C.oy + C.S * (Y * C.k - z * zf)];+ };+ }+ function unproj(C, sx, sy, z) {+ const c = Math.cos(C.az), s = Math.sin(C.az), zf = Math.sqrt(1 - C.k * C.k);+ const X = (sx - C.ox) / C.S, Y = ((sy - C.oy) / C.S + z * zf) / C.k;+ return [X * c + Y * s, -X * s + Y * c];+ }+ function fit(C, pts, cx, cy) {+ C.ox = 0;+ C.oy = 0;+ const P = proj(C);+ let a = 1e9, b = -1e9, c = 1e9, d = -1e9;+ for (const p of pts) {+ const q = P(p[0], p[1], p[2]);+ a = Math.min(a, q[0]);+ b = Math.max(b, q[0]);+ c = Math.min(c, q[1]);+ d = Math.max(d, q[1]);+ }+ C.ox = cx - (a + b) / 2;+ C.oy = cy - (c + d) / 2;+ }+ function rrect(u0, v0, u1, v1, r, n = 4) {+ r = Math.max(0, Math.min(r, (u1 - u0) / 2, (v1 - v0) / 2));+ const out = [];+ for (const [cu, cv, a0] of [[u1 - r, v1 - r, 0], [u0 + r, v1 - r, 90], [u0 + r, v0 + r, 180], [u1 - r, v0 + r, 270]])+ for (let k = 0; k <= n; k++) {+ const a = rad(a0 + 90 * k / n), ca = Math.cos(a), sa = Math.sin(a);+ out.push({ u: cu + r * ca, v: cv + r * sa, nu: ca, nv: sa });+ }+ return out;+ }+ function circ(R, n = 96) {+ const out = [];+ for (let k = 0; k < n; k++) {+ const a = k / n * Math.PI * 2, ca = Math.cos(a), sa = Math.sin(a);+ out.push({ u: R * ca, v: R * sa, nu: ca, nv: sa });+ }+ return out;+ }+ function hull(input) {+ const pts = input.slice().sort((a, b) => a[0] - b[0] || a[1] - b[1]);+ const x = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);+ const lo = [], up = [];+ for (const p of pts) {+ while (lo.length > 1 && x(lo[lo.length - 2], lo[lo.length - 1], p) <= 0) lo.pop();+ lo.push(p);+ }+ for (let i = pts.length - 1; i >= 0; i--) {+ const p = pts[i];+ while (up.length > 1 && x(up[up.length - 2], up[up.length - 1], p) <= 0) up.pop();+ up.push(p);+ }+ lo.pop();+ up.pop();+ return lo.concat(up);+ }+ var ringAt = (P, ring, z) => ring.map((q) => P(q.u, q.v, z));+ var facing = (C) => {+ const s = Math.sin(C.az), c = Math.cos(C.az);+ return (q) => q.nu * s + q.nv * c >= -1e-6;+ };+ function run(ring, keep) {+ const n = ring.length;+ let s = -1;+ for (let i = 0; i < n; i++) if (keep(ring[i]) && !keep(ring[(i + n - 1) % n])) {+ s = i;+ break;+ }+ if (s < 0) return keep(ring[0]) ? ring.slice() : [];+ const out = [];+ for (let k = 0; k < n && keep(ring[(s + k) % n]); k++) out.push(ring[(s + k) % n]);+ return out;+ }+ function prism(P, front, ring, inner, z0, z1) {+ return {+ sil: poly(hull(ringAt(P, ring, z1).concat(ringAt(P, ring, z0)))),+ crease: inner ? open(ringAt(P, run(inner, front), z1)) : ""+ };+ }+ var rings = (x0, y0, x1, y1, r, b) => [+ rrect(x0, y0, x1, y1, r),+ rrect(x0 + b, y0 + b, x1 - b, y1 - b, Math.max(0.3, r - b))+ ];+ function extremes(P, ring) {+ const pr = ring.map((q) => P(q.u, q.v, 0));+ let a = 0, b = 0, c = 0;+ pr.forEach((p, k) => {+ if (p[0] < pr[a][0]) a = k;+ if (p[0] > pr[b][0]) b = k;+ if (p[1] > pr[c][1]) c = k;+ });+ return [ring[a], ring[b], ring[c]];+ }+ function fillet(pts, rs, n = 4) {+ const m = pts.length, out = [];+ for (let i = 0; i < m; i++) {+ const a = pts[(i + m - 1) % m], p = pts[i], b = pts[(i + 1) % m];+ const la = Math.hypot(a[0] - p[0], a[1] - p[1]), lb = Math.hypot(b[0] - p[0], b[1] - p[1]);+ const t = Math.min(rs[i], la / 2, lb / 2);+ const p1 = [p[0] + (a[0] - p[0]) / la * t, p[1] + (a[1] - p[1]) / la * t];+ const p2 = [p[0] + (b[0] - p[0]) / lb * t, p[1] + (b[1] - p[1]) / lb * t];+ for (let k = 0; k <= n; k++) {+ const s = k / n, w = 1 - s;+ out.push([w * w * p1[0] + 2 * w * s * p[0] + s * s * p2[0], w * w * p1[1] + 2 * w * s * p[1] + s * s * p2[1]]);+ }+ }+ return out;+ }+ function ghost(P, front, ring, z0, depth) {+ const f = run(ring, front), lowP = ringAt(P, f, z0 - depth);+ return {+ d: open(lowP) + [f[0], f[f.length - 1]].map((q) => seg(P(q.u, q.v, z0), P(q.u, q.v, z0 - depth))).join(""),+ y0: Math.min(...ringAt(P, f, z0).map((p) => p[1])),+ y1: Math.max(...lowP.map((p) => p[1])) + 2+ };+ }++ // packages/hairline/src/core/motion.ts+ var reduced = false;+ var setReducedMotion = (on) => {+ reduced = on;+ };+ var reducedMotion = () => reduced;+ function spring(x, o = {}) {+ return { x, v: 0, t: x, k: o.k ?? 100, c: o.c ?? 18, m: o.m ?? 1, eps: o.eps ?? 0.01 };+ }+ function stepS(sp, dt) {+ if (reduced) {+ sp.x = sp.t;+ sp.v = 0;+ return false;+ }+ const n = Math.max(1, Math.ceil(dt * 240)), h = dt / n;+ for (let i = 0; i < n; i++) {+ const a = (-sp.k * (sp.x - sp.t) - sp.c * sp.v) / sp.m;+ sp.v += a * h;+ sp.x += sp.v * h;+ }+ if (Math.abs(sp.x - sp.t) < sp.eps && Math.abs(sp.v) < sp.eps * 10) {+ sp.x = sp.t;+ sp.v = 0;+ return false;+ }+ return true;+ }+ function bezier(x1, y1, x2, y2) {+ const cx = 3 * x1, bx = 3 * (x2 - x1) - cx, ax = 1 - cx - bx;+ const cy = 3 * y1, by = 3 * (y2 - y1) - cy, ay = 1 - cy - by;+ const X = (u) => ((ax * u + bx) * u + cx) * u;+ const Y = (u) => ((ay * u + by) * u + cy) * u;+ const dX = (u) => (3 * ax * u + 2 * bx) * u + cx;+ return (t) => {+ if (t <= 0) return 0;+ if (t >= 1) return 1;+ let u = t;+ for (let i = 0; i < 8; i++) {+ const e = X(u) - t;+ if (Math.abs(e) < 1e-5) break;+ const d = dX(u);+ if (Math.abs(d) < 1e-6) break;+ u -= e / d;+ }+ if (!(u >= 0 && u <= 1) || Math.abs(X(u) - t) > 1e-4) {+ let lo = 0, hi = 1;+ u = t;+ for (let i = 0; i < 24; i++) {+ if (X(u) < t) lo = u;+ else hi = u;+ u = (lo + hi) / 2;+ }+ }+ return Y(u);+ };+ }+ var EASE_LIFT = bezier(0.32, 0.72, 0, 1);+ var tween = (v, dur = 700) => ({ from: v, to: v, t0: -1e9, dur });+ var tval = (tw, now) => {+ const p = clamp((now - tw.t0) / tw.dur, 0, 1);+ return tw.from + (tw.to - tw.from) * (reduced ? 1 : EASE_LIFT(p));+ };+ var tset = (tw, to, now, delay) => {+ if (tw.to === to) return;+ tw.from = tval(tw, now);+ tw.to = to;+ tw.t0 = now + delay;+ };+ var tdone = (tw, now) => reduced || now >= tw.t0 + tw.dur;++ // packages/hairline/src/core/stage.ts+ var NS = "http://www.w3.org/2000/svg";+ function mk(tag, attrs, parent) {+ const e = document.createElementNS(NS, tag);+ if (attrs) for (const k in attrs) e.setAttribute(k, String(attrs[k]));+ if (parent) parent.appendChild(e);+ return e;+ }+ function solid(parent) {+ const g = mk("g", {}, parent);+ return { g, sil: mk("path", { class: "sil" }, g), cr: mk("path", { class: "nf lo" }, g) };+ }+ var put = (el, s) => {+ el.sil.setAttribute("d", s.sil);+ el.cr.setAttribute("d", s.crease);+ };+ var flatDot = (parent, C, r, cls) => mk("ellipse", { rx: r2(r * C.S), ry: r2(r * C.S * C.k), class: cls }, parent);+ var place = (el, q) => {+ el.setAttribute("cx", String(r2(q[0])));+ el.setAttribute("cy", String(r2(q[1])));+ };+ var fid = 0;+ function fade(svg, y0, y1, a0 = 0.7) {+ const id = "hl-fd" + ++fid, defs = mk("defs", {}, svg);+ const lg = mk("linearGradient", { id: id + "g", gradientUnits: "userSpaceOnUse", x1: 0, y1: r2(y0), x2: 0, y2: r2(y1) }, defs);+ mk("stop", { offset: 0, "stop-color": "#fff", "stop-opacity": a0 }, lg);+ mk("stop", { offset: 1, "stop-color": "#fff", "stop-opacity": 0 }, lg);+ const m = mk("mask", { id, maskUnits: "userSpaceOnUse", x: 0, y: 0, width: 400, height: 320 }, defs);+ mk("rect", { x: 0, y: 0, width: 400, height: 320, fill: `url(#${id}g)` }, m);+ return `url(#${id})`;+ }+ function reflect(svg, parent, P, front, ring, z0, depth) {+ const r = ghost(P, front, ring, z0, depth);+ const gh = mk("g", { class: "ghost", mask: fade(svg, r.y0, r.y1) }, parent);+ mk("path", { d: r.d }, gh);+ }+ var boards = [];+ var byStage = /* @__PURE__ */ new Map();+ var raf = 0;+ var last = 0;+ var io = null;+ var rm = null;+ function frame(now) {+ const dt = Math.min(0.05, Math.max(0, (now - last) / 1e3));+ last = now;+ let any = false;+ for (const b of boards.slice()) if (b.vis && b.awake) {+ b.awake = !!b.tick(dt, now);+ any = any || b.awake;+ }+ raf = any ? requestAnimationFrame(frame) : 0;+ }+ function wake(b) {+ b.awake = true;+ if (!raf) {+ last = performance.now();+ raf = requestAnimationFrame(frame);+ }+ }+ var onMotion = () => {+ setReducedMotion(!!rm?.matches);+ boards.forEach(wake);+ };+ function start() {+ if (io) return;+ io = new IntersectionObserver((es) => {+ for (const e of es) {+ const b = byStage.get(e.target);+ if (!b) continue;+ b.vis = e.isIntersecting;+ if (b.vis) wake(b);+ }+ }, { rootMargin: "80px" });+ rm = matchMedia("(prefers-reduced-motion: reduce)");+ setReducedMotion(rm.matches);+ rm.addEventListener("change", onMotion);+ }+ function stop() {+ if (raf) cancelAnimationFrame(raf);+ raf = 0;+ io?.disconnect();+ io = null;+ rm?.removeEventListener("change", onMotion);+ rm = null;+ }+ function register(stage, tick) {+ start();+ const b = { stage, tick, vis: false, awake: true };+ boards.push(b);+ byStage.set(stage, b);+ io.observe(stage);+ tick(0, performance.now());+ let gone = false;+ return {+ wake: () => {+ if (!gone) wake(b);+ },+ unregister: () => {+ if (gone) return;+ gone = true;+ boards = boards.filter((x) => x !== b);+ if (byStage.get(stage) === b) {+ byStage.delete(stage);+ io?.unobserve(stage);+ }+ if (!boards.length) stop();+ }+ };+ }+ function pointer(stage, on) {+ let tm = 0;+ const pt = (e) => {+ const r = stage.getBoundingClientRect();+ return [(e.clientX - r.left) / r.width * 400, (e.clientY - r.top) / r.height * 320];+ };+ const move = (e) => {+ clearTimeout(tm);+ on.move(pt(e), e);+ };+ const down = (e) => {+ clearTimeout(tm);+ if (e.pointerType !== "mouse") stage.releasePointerCapture?.(e.pointerId);+ if (on.down) on.down(pt(e), e);+ else on.move(pt(e), e);+ };+ const leave = (e) => {+ clearTimeout(tm);+ tm = window.setTimeout(() => on.leave(e), e.pointerType === "mouse" ? 0 : 1400);+ };+ stage.addEventListener("pointermove", move);+ stage.addEventListener("pointerdown", down);+ stage.addEventListener("pointerleave", leave);+ return () => {+ clearTimeout(tm);+ stage.removeEventListener("pointermove", move);+ stage.removeEventListener("pointerdown", down);+ stage.removeEventListener("pointerleave", leave);+ };+ }+ function disposer() {+ let fns = [];+ return {+ add: (fn) => {+ fns.push(fn);+ },+ on: (target, type, fn, opts) => {+ const h = fn;+ target.addEventListener(type, h, opts);+ fns.push(() => target.removeEventListener(type, h, opts));+ },+ dispose: () => {+ const run2 = fns;+ fns = [];+ for (let i = run2.length - 1; i >= 0; i--) run2[i]();+ }+ };+ }++ // packages/hairline/src/core/styles.ts+ var LIGHT = { plate: "#ffffff", hi: "#232327", edge: "#a4a4ac", mid: "#c3c3c9", lo: "#e0e0e4" };+ var DARK = { plate: "#08090a", hi: "#d0d6e0", edge: "#5b5d64", mid: "#3e3e44", lo: "#29292d" };+ var KEYS = ["plate", "hi", "edge", "mid", "lo"];+ var vars = (p) => KEYS.map((k) => `--hl-${k}:var(--hairline-${k},${p[k]});`).join("");+ var EASE = "cubic-bezier(0.5,0,0.1,1)";+ var SVG = ":where([data-hairline]>svg)";+ function css(lightDark) {+ const both = Object.fromEntries(KEYS.map((k) => [k, `light-dark(${LIGHT[k]},${DARK[k]})`]));+ return [+ // the box, and the palette: light unless something below says otherwise+ `:where([data-hairline]){display:block;position:relative;aspect-ratio:5/4;touch-action:pan-y;user-select:none;-webkit-user-select:none;--hl-sw:var(--hairline-stroke,0.9);${vars(LIGHT)}}`,+ // the page's color-scheme+ lightDark ? `:where([data-hairline]){${vars(both)}}` : "",+ // an ancestor that says dark+ `:where(.dark,[data-theme="dark"]) :where([data-hairline]){${vars(DARK)}}`,+ // the figure's own theme option+ `:where([data-hairline][data-hairline-theme="light"]){${vars(LIGHT)}}`,+ `:where([data-hairline][data-hairline-theme="dark"]){${vars(DARK)}}`,+ `:where([data-hairline]:focus-visible){outline:1.5px solid var(--hl-hi);outline-offset:2px}`,+ `${SVG}{position:absolute;inset:0;width:100%;height:100%;display:block}`,+ // Riffle's live region: read, not seen+ `:where([data-hairline]>[data-hairline-live]){position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap}`,+ // the drawing: plates are filled with the plate colour and painted back to front+ `${SVG} :where(path,polygon,ellipse,line){fill:var(--hl-plate);stroke:var(--hl-mid);stroke-width:var(--hl-sw);vector-effect:non-scaling-stroke;stroke-linejoin:round;stroke-linecap:round;transition:stroke 260ms ${EASE}}`,+ `${SVG} :where(.nf){fill:none}`,+ `${SVG} :where(.fo){stroke:none}`,+ `${SVG} :where(.sil){stroke:var(--hl-edge)}`,+ `${SVG} :where(.hi){stroke:var(--hl-hi)}`,+ `${SVG} :where(.lo){stroke:var(--hl-lo)}`,+ `${SVG} :where(.dash){stroke-dasharray:1 3}`,+ `${SVG} :where(.dot){stroke:none;fill:var(--hl-hi);transition:fill 260ms ${EASE}}`,+ `${SVG} :where(.dot.m){fill:var(--hl-edge)}`,+ `${SVG} :where(.dot.off){fill:var(--hl-lo)}`,+ `${SVG} :where(.ghost path){fill:none;stroke:var(--hl-mid)}`+ ].join("");+ }+ var done = /* @__PURE__ */ new WeakSet();+ function inject(root) {+ if (done.has(root)) return;+ done.add(root);+ const doc = root.nodeType === 9 ? root : root.ownerDocument;+ const win = doc.defaultView;+ const text = css(!!win?.CSS?.supports?.("color", "light-dark(#000,#fff)"));+ if (win && "adoptedStyleSheets" in root) {+ try {+ const sheet = new win.CSSStyleSheet();+ sheet.replaceSync(text);+ root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet];+ return;+ } catch {+ }+ }+ const style = doc.createElement("style");+ style.setAttribute("data-hairline-style", "");+ style.textContent = text;+ (root.nodeType === 9 ? doc.head ?? doc.documentElement : root).appendChild(style);+ }+ return __toCommonJS(kernel_exports);+})();+/* /hairline kernel */+</script>+<script id="hl-bench">+/*+ * The bench: the page a figure is shown on. It makes the host and the svg the+ * way the package's mount does, hands them to the figure, and owns everything+ * around it: the read-out, the slider, the theme, the line under the stage.+ */+(() => {+ const RULES = ["hit", "order", "reach", "accent", "rest", "honesty", "cost", "clock", "radius", "quiet"];+ const $ = (id) => document.getElementById(id);+ const root = document.documentElement, params = new URLSearchParams(location.search);++ /* the theme: the system's until the switch is pressed, then the switch's */+ const dark = () => (root.dataset.theme ? root.dataset.theme === "dark" : matchMedia("(prefers-color-scheme: dark)").matches);+ const label = () => { $("theme").textContent = dark() ? "dark" : "light"; };+ $("theme").addEventListener("click", () => { root.dataset.theme = dark() ? "light" : "dark"; label(); });+ /* ?theme=light or ?theme=dark wins over the system's, as pressing the switch does */+ if (["light", "dark"].includes(params.get("theme"))) root.dataset.theme = params.get("theme");+ label();++ /* ?intensity=0 sets the slider before the figure mounts, for a look at either end */+ const i = (params.get("intensity") || "").trim();+ if (i && Number.isFinite(Number(i))) $("intensity").value = String(Math.min(1, Math.max(0, Number(i))));++ /* ?w=240 narrows the page, for a look at the size of a thumbnail */+ const w = Number(params.get("w"));+ if (w > 0) document.querySelector("main").style.maxWidth = w + "px";++ /* a figure that fails says so under the stage, instead of leaving an empty plate */+ addEventListener("error", (e) => {+ $("error").hidden = false;+ $("error").textContent = String((e.error && e.error.message) || e.message);+ });++ let mounted = false;+ window.hairline = (figure) => {+ if (mounted) throw new Error("hairline: one figure per page.");+ mounted = true;+ const stage = $("stage"), slider = $("intensity");++ /* intensity to the figure's own number: two straight lines that meet at 0.5, as in the package */+ const [lo, mid, hi] = figure.range;+ const at = (i) => Math.round((i <= 0.5 ? lo + (i / 0.5) * (mid - lo) : mid + ((i - 0.5) / 0.5) * (hi - mid)) * 1000) / 1000;++ HL.inject(document);+ stage.setAttribute("data-hairline", figure.name);+ stage.setAttribute("role", "img");+ stage.setAttribute("aria-label", figure.means);+ const svg = HL.mk("svg", { viewBox: "0 0 400 320", "aria-hidden": "true" }, stage);++ let text = null;+ const read = {+ get textContent() { return text; },+ set textContent(value) { text = value == null ? "" : String(value); $("read").textContent = text; },+ };++ document.title = "Hairline · " + figure.name;+ $("name").textContent = figure.name;+ $("means").textContent = figure.means;+ $("rules").textContent = figure.rules.map((n) => String(n).padStart(2, "0") + " " + RULES[n - 1]).join(" · ");+ const show = () => { $("value").textContent = String(at(Number(slider.value))); };+ show();++ const handle = figure.mount({ stage, svg, read }, at(Number(slider.value)));+ if (text === null) read.textContent = "rest";+ slider.addEventListener("input", () => { show(); handle.set(at(Number(slider.value))); });+ window.hairline.figure = handle;++ /* ?at=200,160 holds the pointer at a viewBox point, for a picture of the answer without a mouse */+ const p = (params.get("at") || "").split(",").map(Number);+ if (p.length === 2 && p.every(Number.isFinite)) {+ const r = stage.getBoundingClientRect();+ stage.dispatchEvent(new PointerEvent("pointermove", {+ pointerType: "mouse", pointerId: 1, bubbles: true,+ clientX: r.left + (p[0] / 400) * r.width, clientY: r.top + (p[1] / 320) * r.height,+ }));+ }+ };+})();+</script>+<script type="module" id="hl-figure">+/**+ * Funnel: four trays stepping down towards the viewer, each narrower than the+ * one behind it, holding sixteen, eight, four and one bead. The tray under the+ * pointer lifts out of the cascade and takes the bright edge with its beads;+ * its neighbours rise less, staggered outwards from it. At rest the one bead in+ * the last tray, the deal, is the bright mark. The slider is the stagger, in ms.+ *+ * The pattern: discrete items (Riffle's answer). Tweens, a stagger by+ * distance, and a hit test on static screen bands taken from the rest pose.+ */+const {+ Cam, clamp, extremes, facing, fit, prism, proj, rings, seg, unproj, tdone, tset, tval, tween, disposer, flatDot, mk, place,+ pointer, register, solid, put,+} = HL;++const STAGES = ["lead", "call", "demo", "deal"];+const WIDE = [136, 100, 64, 30], BEADS = [[8, 2], [4, 2], [2, 2], [1, 1]];+const D = 28, PITCH = 40, DROP = 14, T = 7, R = 8, B = 2.2, BR = 2.6, M = 15;+const LIFT = 14, FALL = [1, 0.36, 0.13, 0.05];+/** World point: a across the flow, b along it. The flow runs down the screen to the right (+x), the width across it (+y). */+const at = (a, b, z) => [b, a, z];++/** Tray i at rest: where it sits along the flow and how high, its two rings, and where its beads lie on its top. */+function tray(i) {+ const w = WIDE[i] / 2, b0 = i * PITCH, z0 = (STAGES.length - 1 - i) * DROP;+ const [outer, inner] = rings(b0 - D / 2, -w, b0 + D / 2, w, R, B);+ const [cols, rows] = BEADS[i], beads = [];+ for (let r = 0; r < rows; r++) {+ for (let c = 0; c < cols; c++) {+ const a = cols === 1 ? 0 : -w + M + (c * (2 * w - 2 * M)) / (cols - 1);+ beads.push([a, b0 + (rows === 1 ? 0 : (r - 0.5) * 12)]);+ }+ }+ return { w, b0, z0, outer, inner, beads };+}++function mount({ stage, svg, read }, value) {+ const bag = disposer();+ let stag = value;+ const N = STAGES.length, trays = [];+ for (let i = 0; i < N; i++) trays.push(tray(i));++ // Fitted with the back tray at its full lift, so no pose leaves the frame.+ const C = Cam(45, 0.5, 1.9);+ const ext = [];+ trays.forEach((t, i) => {+ for (const a of [-t.w, t.w]) for (const b of [t.b0 - D / 2, t.b0 + D / 2]) ext.push(at(a, b, t.z0), at(a, b, t.z0 + T + (i === 0 ? LIFT : 0)));+ });+ fit(C, ext, 200, 166);+ const P = proj(C), front = facing(C);++ // back to front: the widest tray, farthest and highest, first+ const g = mk("g", {}, svg);+ for (const t of trays) {+ t.drop = mk("path", { class: "dash" }, g);+ t.el = solid(g);+ t.dots = t.beads.map(() => flatDot(t.el.g, C, BR, "dot m"));+ t.lift = tween(0);+ t.last = NaN;+ }+ const deal = trays[N - 1].dots[0];+ deal.setAttribute("class", "dot");++ /** Draws tray t at lift z, and skips it when nothing changed. */+ function draw(t, z) {+ if (z === t.last) return;+ t.last = z;+ put(t.el, prism(P, front, t.outer, t.inner, t.z0 + z, t.z0 + T + z));+ // stilts: dashed drops from the tray's left and right edges to the ground, painted behind it+ t.drop.setAttribute("d", t.z0 + z < 0.5 ? "" : extremes(P, t.outer).slice(0, 2).map((q) => seg(P(q.u, q.v, t.z0 + z), P(q.u, q.v, 0))).join(""));+ t.dots.forEach((el, k) => place(el, P(...at(t.beads[k][0], t.beads[k][1], t.z0 + T + z))));+ }+ trays.forEach((t) => draw(t, 0));+ read.textContent = "rest";++ // hit bands: each tray's REST top plane. The pointer goes to the tray whose plane puts it nearest the tray's middle+ // along the flow, if it is within the tray's width. The planes never move, so a lifting tray cannot flip the choice.+ function hit([x, y]) {+ let best = -1, bd = PITCH;+ trays.forEach((t, i) => {+ const [b, a] = unproj(C, x, y, t.z0 + T), d = Math.abs(b - t.b0);+ if (d < bd && Math.abs(a) <= t.w + 6) { bd = d; best = i; }+ });+ return best;+ }++ const L = register(stage, (_dt, now) => {+ let moving = false;+ for (const t of trays) { draw(t, tval(t.lift, now)); if (!tdone(t.lift, now)) moving = true; }+ return moving;+ });+ bag.add(L.unregister);++ let act = -1;+ /** Lifts tray a out of the cascade (-1 lets them all settle). The stagger spreads out from the tray picked, or the one let go. */+ function setActive(a) {+ if (a === act) return;+ const now = performance.now(), from = a >= 0 ? a : act;+ act = a;+ trays.forEach((t, i) => {+ const d = Math.abs(i - from);+ tset(t.lift, a < 0 ? 0 : LIFT * FALL[clamp(Math.abs(i - a), 0, FALL.length - 1)], now, d * stag);+ t.el.sil.classList.toggle("hi", i === a);+ t.dots.forEach((el) => el.setAttribute("class", i === a ? "dot" : "dot m"));+ });+ if (a < 0) deal.setAttribute("class", "dot");+ read.textContent = a < 0 ? "rest" : STAGES[a];+ L.wake();+ }++ bag.add(pointer(stage, { move: (p) => setActive(hit(p)), leave: () => setActive(-1) }));+ bag.add(() => svg.replaceChildren());++ return {+ set: (v) => { stag = v; },+ destroy: bag.dispose,+ };+}++hairline({+ name: "funnel",+ means: "Four trays step down, each narrower with fewer beads: the stage under the pointer lifts, its neighbours rising less in turn.",+ rules: [1, 2, 5, 10],+ range: [0, 45, 90],+ mount,+});+</script>+</body>+</html>diff --git a/apps/site/public/skill/hairline-sidings.html b/apps/site/public/skill/hairline-sidings.htmlnew file mode 100644index 0000000..82146ca--- /dev/null+++ b/apps/site/public/skill/hairline-sidings.html@@ -0,0 +1,878 @@+<!doctype html>+<html lang="en">+<head>+<meta charset="utf-8">+<meta name="viewport" content="width=device-width, initial-scale=1">+<title>Hairline figure</title>+<link rel="icon" href="data:,">+<style>+ :root { color-scheme: light; --ground: #ffffff; --ink: #232327; --muted: #6f6f78; --line: #e0e0e4; }+ @media (prefers-color-scheme: dark) {+ :root:not([data-theme="light"]) { color-scheme: dark; --ground: #08090a; --ink: #d0d6e0; --muted: #8a8c95; --line: #29292d; }+ }+ :root[data-theme="dark"] { color-scheme: dark; --ground: #08090a; --ink: #d0d6e0; --muted: #8a8c95; --line: #29292d; }+ :root[data-theme="light"] { color-scheme: light; }+ * { box-sizing: border-box; }+ body {+ margin: 0; min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;+ background: var(--ground); color: var(--ink);+ font: 13px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased;+ }+ main { width: 100%; max-width: 640px; }+ .plate { position: relative; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }+ .tag, .label, output, button { font: 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 0.02em; }+ .tag { position: absolute; top: 12px; z-index: 1; color: var(--muted); pointer-events: none; }+ #name { left: 14px; }+ #read { right: 14px; color: var(--ink); font-variant-numeric: tabular-nums; }+ .controls { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 14px; }+ .label { color: var(--muted); }+ input[type="range"] {+ flex: 1 1 96px; min-width: 0; height: 32px; margin: 0; background: transparent; cursor: pointer;+ -webkit-appearance: none; appearance: none;+ }+ input[type="range"]::-webkit-slider-runnable-track { height: 1px; background: var(--muted); }+ input[type="range"]::-webkit-slider-thumb {+ -webkit-appearance: none; width: 13px; height: 13px; margin-top: -6px; border-radius: 50%;+ border: 1px solid var(--ink); background: var(--ground);+ }+ input[type="range"]::-moz-range-track { height: 1px; background: var(--muted); }+ input[type="range"]::-moz-range-thumb { width: 11px; height: 11px; border-radius: 50%; border: 1px solid var(--ink); background: var(--ground); }+ input[type="range"]:focus-visible, button:focus-visible { outline: 1.5px solid var(--ink); outline-offset: 2px; }+ output { min-width: 4ch; text-align: right; font-variant-numeric: tabular-nums; }+ button {+ height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;+ background: transparent; color: var(--ink); cursor: pointer;+ }+ #means { margin: 14px 0 0; text-wrap: pretty; }+ #rules { margin: 6px 0 0; line-height: 1.6; }+ #error { margin: 12px 0 0; padding-left: 10px; border-left: 1px solid var(--ink); }+</style>+</head>+<body>+<main>+ <div class="plate">+ <span class="tag" id="name"></span>+ <span class="tag" id="read"></span>+ <div id="stage"></div>+ </div>+ <div class="controls">+ <label class="label" for="intensity">intensity</label>+ <input id="intensity" type="range" min="0" max="1" step="0.01" value="0.5">+ <output id="value" for="intensity"></output>+ <span class="label">theme</span>+ <button id="theme" type="button" aria-label="Switch between the light and the dark theme"></button>+ </div>+ <p id="means"></p>+ <p id="rules" class="label"></p>+ <p id="error" role="alert" hidden></p>+</main>+<script id="hl-kernel">+/* hairline kernel sha256:8e2abcbdf63c7755195ee942c39e9c8ea6a539d1147e986dd1c153559121f075 */+/*+ * HL: everything a figure may call. Read this index; the code under it is the+ * package's src/core, unchanged, and a figure should not need to read it.+ *+ * Every figure is drawn in a 400 × 320 viewBox. World space is x/y on the+ * ground and z up. Plates are filled with the ground colour and painted back+ * to front, so a nearer one covers a farther one: append in that order. At+ * the default camera, Cam(45, 0.5, S), +x runs down to the right and +y down+ * to the left, so the corner with the largest x and y is nearest the viewer:+ * append by ascending x + y, from the far corner (smallest x and y) to it.+ *+ * Camera+ * Cam(azDeg, k, S) a camera: azimuth in degrees, k = sin(elevation) (0.5 is the 2:1 view), S = scale+ * fit(C, points, cx, cy) centres the box of [x, y, z] points on (cx, cy); call it once, before proj+ * it only centres, it never scales: choose S by trying values, with the most extreme pose in points.+ * The six figures use S 1.42 to 2.12; the boxes they fit come out 230 to 310 wide and 180 to 245 tall+ * proj(C) returns P(x, y, z), which gives [sx, sy]+ * unproj(C, sx, sy, z) the world [x, y] under a screen point, on the plane at height z+ * facing(C) returns front(sample): whether a ring sample faces the camera+ * Rounded solids+ * rrect(u0, v0, u1, v1, r, n) a rounded rectangle, as a ring of samples {u, v, nu, nv}+ * circ(R, n) a circle, as a ring+ * rings(x0, y0, x1, y1, r, b) [ring, inner]: a rounded footprint and its crease ring, inset by b+ * r, the corner radius, is cut to half the shorter side. b, the crease's inset in world units+ * (0.6 to 2.2 in the figures), must stay under half the shorter side or the crease turns inside out+ * prism(P, front, ring, inner, z0, z1) {sil, crease}: a solid standing from z0 to z1, as two path strings+ * ringAt(P, ring, z) the ring's points, projected at height z+ * run(ring, keep) the one cyclic run of samples that pass keep+ * hull(points) the convex hull of screen points+ * extremes(P, ring) [left, right, nearest] samples: where dashed drops fall from+ * fillet(points, radii, n) rounds every vertex of a closed polygon; returns the new points+ * radii is an array, one radius per vertex, each cut to half its shorter edge; a single number gives NaN.+ * n is the steps round each corner, default 4: each vertex becomes n + 1 points+ * ghost(P, front, ring, z0, depth) a reflection's path {d, y0, y1}; reflect() draws it for you+ * Paths and numbers+ * poly(points) a closed path string+ * open(points) an open polyline string+ * seg(a, b) one segment between two screen points [sx, sy], as its own subpath; project world points with P first+ * clamp(v, a, b)+ * lerp(a, b, t)+ * rad(deg)+ * r2(n) two decimals+ * The continuous clock: one spring per moving number+ * spring(x, opts) at rest on x; write .t to retarget; opts {k, c, m, eps}, default k 100, c 18, m 1+ * stepS(sp, dt) advances by dt seconds; returns whether it is still moving+ * The discrete clock: a 700ms tween on (.32, .72, 0, 1)+ * tween(v, dur) at rest on v; dur defaults to 700 (ms)+ * tset(tw, to, now, delay) retargets from where it is, after delay ms: the stagger+ * the same target again does nothing, so calling it on every pointer move is safe+ * tval(tw, now) its value at now+ * tdone(tw, now) whether it has landed+ * bezier(x1, y1, x2, y2) a CSS cubic-bezier, as a function of progress+ * EASE_LIFT the lift curve itself+ * reducedMotion() true when the reader asked for less motion; springs and tweens already land at once+ * setReducedMotion(on) the loop's business, not a figure's+ * Drawing+ * mk(tag, attrs, parent) one svg element: the only way a figure makes a node+ * solid(parent) {g, sil, cr}: a group holding a silhouette path and a crease path+ * put(solid, paths) writes prism()'s {sil, crease} into solid()'s {sil, cr}: sil into sil, crease into cr+ * flatDot(parent, C, r, cls) a dot lying on the ground plane; cls is "dot", "dot m" or "dot off"+ * place(el, point) moves a dot or a circle to [sx, sy]+ * reflect(svg, parent, P, front, ring, z0, depth) a fading mirror under a solid+ * fade(svg, y0, y1, a0) a vertical fade, as a mask; returns the value for a mask attribute+ * Life+ * register(stage, tick) joins the one frame loop; tick(dt in seconds, now in ms) returns true to ask for another frame; gives {wake, unregister}+ * pointer(stage, handlers) {move(point), down(point), leave()}, points in viewBox units; returns its disposer+ * disposer() {add, on, dispose}: collects tear-down, so destroy is bag.dispose+ * The bench's business, not a figure's+ * css(lightDark)+ * inject(root)+ *+ * Classes, on path, polygon, ellipse and line. They are the whole palette; a+ * figure sets no colour, width or fill of its own.+ * (none) filled with the ground colour, medium stroke+ * sil the silhouette's stroke hi the bright stroke: the only highlight+ * lo the dim stroke nf no fill fo fill only, no stroke+ * dash a dashed guide+ * dot a bright dot dot m a medium dot dot off a dim dot+ */+var HL = (() => {+ var __defProp = Object.defineProperty;+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;+ var __getOwnPropNames = Object.getOwnPropertyNames;+ var __hasOwnProp = Object.prototype.hasOwnProperty;+ var __export = (target, all) => {+ for (var name in all)+ __defProp(target, name, { get: all[name], enumerable: true });+ };+ var __copyProps = (to, from, except, desc) => {+ if (from && typeof from === "object" || typeof from === "function") {+ for (let key of __getOwnPropNames(from))+ if (!__hasOwnProp.call(to, key) && key !== except)+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });+ }+ return to;+ };+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);++ // packages/hairline/src/core/kernel.ts+ var kernel_exports = {};+ __export(kernel_exports, {+ Cam: () => Cam,+ EASE_LIFT: () => EASE_LIFT,+ bezier: () => bezier,+ circ: () => circ,+ clamp: () => clamp,+ css: () => css,+ disposer: () => disposer,+ extremes: () => extremes,+ facing: () => facing,+ fade: () => fade,+ fillet: () => fillet,+ fit: () => fit,+ flatDot: () => flatDot,+ ghost: () => ghost,+ hull: () => hull,+ inject: () => inject,+ lerp: () => lerp,+ mk: () => mk,+ open: () => open,+ place: () => place,+ pointer: () => pointer,+ poly: () => poly,+ prism: () => prism,+ proj: () => proj,+ put: () => put,+ r2: () => r2,+ rad: () => rad,+ reducedMotion: () => reducedMotion,+ reflect: () => reflect,+ register: () => register,+ ringAt: () => ringAt,+ rings: () => rings,+ rrect: () => rrect,+ run: () => run,+ seg: () => seg,+ setReducedMotion: () => setReducedMotion,+ solid: () => solid,+ spring: () => spring,+ stepS: () => stepS,+ tdone: () => tdone,+ tset: () => tset,+ tval: () => tval,+ tween: () => tween,+ unproj: () => unproj+ });++ // packages/hairline/src/core/iso.ts+ var clamp = (v, a, b) => Math.max(a, Math.min(b, v));+ var lerp = (a, b, t) => a + (b - a) * t;+ var rad = (d) => d * Math.PI / 180;+ var r2 = (n) => Math.round(n * 100) / 100;+ var poly = (pts) => "M" + pts.map((p) => r2(p[0]) + " " + r2(p[1])).join("L") + "Z";+ var seg = (a, b) => `M${r2(a[0])} ${r2(a[1])}L${r2(b[0])} ${r2(b[1])}`;+ var open = (pts) => pts.length < 2 ? "" : "M" + pts.map((p) => r2(p[0]) + " " + r2(p[1])).join("L");+ var Cam = (azDeg, k, S) => ({ az: rad(azDeg), k, S, ox: 0, oy: 0 });+ function proj(C) {+ const c = Math.cos(C.az), s = Math.sin(C.az), zf = Math.sqrt(1 - C.k * C.k);+ return (x, y, z) => {+ const X = x * c - y * s, Y = x * s + y * c;+ return [C.ox + C.S * X, C.oy + C.S * (Y * C.k - z * zf)];+ };+ }+ function unproj(C, sx, sy, z) {+ const c = Math.cos(C.az), s = Math.sin(C.az), zf = Math.sqrt(1 - C.k * C.k);+ const X = (sx - C.ox) / C.S, Y = ((sy - C.oy) / C.S + z * zf) / C.k;+ return [X * c + Y * s, -X * s + Y * c];+ }+ function fit(C, pts, cx, cy) {+ C.ox = 0;+ C.oy = 0;+ const P = proj(C);+ let a = 1e9, b = -1e9, c = 1e9, d = -1e9;+ for (const p of pts) {+ const q = P(p[0], p[1], p[2]);+ a = Math.min(a, q[0]);+ b = Math.max(b, q[0]);+ c = Math.min(c, q[1]);+ d = Math.max(d, q[1]);+ }+ C.ox = cx - (a + b) / 2;+ C.oy = cy - (c + d) / 2;+ }+ function rrect(u0, v0, u1, v1, r, n = 4) {+ r = Math.max(0, Math.min(r, (u1 - u0) / 2, (v1 - v0) / 2));+ const out = [];+ for (const [cu, cv, a0] of [[u1 - r, v1 - r, 0], [u0 + r, v1 - r, 90], [u0 + r, v0 + r, 180], [u1 - r, v0 + r, 270]])+ for (let k = 0; k <= n; k++) {+ const a = rad(a0 + 90 * k / n), ca = Math.cos(a), sa = Math.sin(a);+ out.push({ u: cu + r * ca, v: cv + r * sa, nu: ca, nv: sa });+ }+ return out;+ }+ function circ(R, n = 96) {+ const out = [];+ for (let k = 0; k < n; k++) {+ const a = k / n * Math.PI * 2, ca = Math.cos(a), sa = Math.sin(a);+ out.push({ u: R * ca, v: R * sa, nu: ca, nv: sa });+ }+ return out;+ }+ function hull(input) {+ const pts = input.slice().sort((a, b) => a[0] - b[0] || a[1] - b[1]);+ const x = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);+ const lo = [], up = [];+ for (const p of pts) {+ while (lo.length > 1 && x(lo[lo.length - 2], lo[lo.length - 1], p) <= 0) lo.pop();+ lo.push(p);+ }+ for (let i = pts.length - 1; i >= 0; i--) {+ const p = pts[i];+ while (up.length > 1 && x(up[up.length - 2], up[up.length - 1], p) <= 0) up.pop();+ up.push(p);+ }+ lo.pop();+ up.pop();+ return lo.concat(up);+ }+ var ringAt = (P, ring, z) => ring.map((q) => P(q.u, q.v, z));+ var facing = (C) => {+ const s = Math.sin(C.az), c = Math.cos(C.az);+ return (q) => q.nu * s + q.nv * c >= -1e-6;+ };+ function run(ring, keep) {+ const n = ring.length;+ let s = -1;+ for (let i = 0; i < n; i++) if (keep(ring[i]) && !keep(ring[(i + n - 1) % n])) {+ s = i;+ break;+ }+ if (s < 0) return keep(ring[0]) ? ring.slice() : [];+ const out = [];+ for (let k = 0; k < n && keep(ring[(s + k) % n]); k++) out.push(ring[(s + k) % n]);+ return out;+ }+ function prism(P, front, ring, inner, z0, z1) {+ return {+ sil: poly(hull(ringAt(P, ring, z1).concat(ringAt(P, ring, z0)))),+ crease: inner ? open(ringAt(P, run(inner, front), z1)) : ""+ };+ }+ var rings = (x0, y0, x1, y1, r, b) => [+ rrect(x0, y0, x1, y1, r),+ rrect(x0 + b, y0 + b, x1 - b, y1 - b, Math.max(0.3, r - b))+ ];+ function extremes(P, ring) {+ const pr = ring.map((q) => P(q.u, q.v, 0));+ let a = 0, b = 0, c = 0;+ pr.forEach((p, k) => {+ if (p[0] < pr[a][0]) a = k;+ if (p[0] > pr[b][0]) b = k;+ if (p[1] > pr[c][1]) c = k;+ });+ return [ring[a], ring[b], ring[c]];+ }+ function fillet(pts, rs, n = 4) {+ const m = pts.length, out = [];+ for (let i = 0; i < m; i++) {+ const a = pts[(i + m - 1) % m], p = pts[i], b = pts[(i + 1) % m];+ const la = Math.hypot(a[0] - p[0], a[1] - p[1]), lb = Math.hypot(b[0] - p[0], b[1] - p[1]);+ const t = Math.min(rs[i], la / 2, lb / 2);+ const p1 = [p[0] + (a[0] - p[0]) / la * t, p[1] + (a[1] - p[1]) / la * t];+ const p2 = [p[0] + (b[0] - p[0]) / lb * t, p[1] + (b[1] - p[1]) / lb * t];+ for (let k = 0; k <= n; k++) {+ const s = k / n, w = 1 - s;+ out.push([w * w * p1[0] + 2 * w * s * p[0] + s * s * p2[0], w * w * p1[1] + 2 * w * s * p[1] + s * s * p2[1]]);+ }+ }+ return out;+ }+ function ghost(P, front, ring, z0, depth) {+ const f = run(ring, front), lowP = ringAt(P, f, z0 - depth);+ return {+ d: open(lowP) + [f[0], f[f.length - 1]].map((q) => seg(P(q.u, q.v, z0), P(q.u, q.v, z0 - depth))).join(""),+ y0: Math.min(...ringAt(P, f, z0).map((p) => p[1])),+ y1: Math.max(...lowP.map((p) => p[1])) + 2+ };+ }++ // packages/hairline/src/core/motion.ts+ var reduced = false;+ var setReducedMotion = (on) => {+ reduced = on;+ };+ var reducedMotion = () => reduced;+ function spring(x, o = {}) {+ return { x, v: 0, t: x, k: o.k ?? 100, c: o.c ?? 18, m: o.m ?? 1, eps: o.eps ?? 0.01 };+ }+ function stepS(sp, dt) {+ if (reduced) {+ sp.x = sp.t;+ sp.v = 0;+ return false;+ }+ const n = Math.max(1, Math.ceil(dt * 240)), h = dt / n;+ for (let i = 0; i < n; i++) {+ const a = (-sp.k * (sp.x - sp.t) - sp.c * sp.v) / sp.m;+ sp.v += a * h;+ sp.x += sp.v * h;+ }+ if (Math.abs(sp.x - sp.t) < sp.eps && Math.abs(sp.v) < sp.eps * 10) {+ sp.x = sp.t;+ sp.v = 0;+ return false;+ }+ return true;+ }+ function bezier(x1, y1, x2, y2) {+ const cx = 3 * x1, bx = 3 * (x2 - x1) - cx, ax = 1 - cx - bx;+ const cy = 3 * y1, by = 3 * (y2 - y1) - cy, ay = 1 - cy - by;+ const X = (u) => ((ax * u + bx) * u + cx) * u;+ const Y = (u) => ((ay * u + by) * u + cy) * u;+ const dX = (u) => (3 * ax * u + 2 * bx) * u + cx;+ return (t) => {+ if (t <= 0) return 0;+ if (t >= 1) return 1;+ let u = t;+ for (let i = 0; i < 8; i++) {+ const e = X(u) - t;+ if (Math.abs(e) < 1e-5) break;+ const d = dX(u);+ if (Math.abs(d) < 1e-6) break;+ u -= e / d;+ }+ if (!(u >= 0 && u <= 1) || Math.abs(X(u) - t) > 1e-4) {+ let lo = 0, hi = 1;+ u = t;+ for (let i = 0; i < 24; i++) {+ if (X(u) < t) lo = u;+ else hi = u;+ u = (lo + hi) / 2;+ }+ }+ return Y(u);+ };+ }+ var EASE_LIFT = bezier(0.32, 0.72, 0, 1);+ var tween = (v, dur = 700) => ({ from: v, to: v, t0: -1e9, dur });+ var tval = (tw, now) => {+ const p = clamp((now - tw.t0) / tw.dur, 0, 1);+ return tw.from + (tw.to - tw.from) * (reduced ? 1 : EASE_LIFT(p));+ };+ var tset = (tw, to, now, delay) => {+ if (tw.to === to) return;+ tw.from = tval(tw, now);+ tw.to = to;+ tw.t0 = now + delay;+ };+ var tdone = (tw, now) => reduced || now >= tw.t0 + tw.dur;++ // packages/hairline/src/core/stage.ts+ var NS = "http://www.w3.org/2000/svg";+ function mk(tag, attrs, parent) {+ const e = document.createElementNS(NS, tag);+ if (attrs) for (const k in attrs) e.setAttribute(k, String(attrs[k]));+ if (parent) parent.appendChild(e);+ return e;+ }+ function solid(parent) {+ const g = mk("g", {}, parent);+ return { g, sil: mk("path", { class: "sil" }, g), cr: mk("path", { class: "nf lo" }, g) };+ }+ var put = (el, s) => {+ el.sil.setAttribute("d", s.sil);+ el.cr.setAttribute("d", s.crease);+ };+ var flatDot = (parent, C, r, cls) => mk("ellipse", { rx: r2(r * C.S), ry: r2(r * C.S * C.k), class: cls }, parent);+ var place = (el, q) => {+ el.setAttribute("cx", String(r2(q[0])));+ el.setAttribute("cy", String(r2(q[1])));+ };+ var fid = 0;+ function fade(svg, y0, y1, a0 = 0.7) {+ const id = "hl-fd" + ++fid, defs = mk("defs", {}, svg);+ const lg = mk("linearGradient", { id: id + "g", gradientUnits: "userSpaceOnUse", x1: 0, y1: r2(y0), x2: 0, y2: r2(y1) }, defs);+ mk("stop", { offset: 0, "stop-color": "#fff", "stop-opacity": a0 }, lg);+ mk("stop", { offset: 1, "stop-color": "#fff", "stop-opacity": 0 }, lg);+ const m = mk("mask", { id, maskUnits: "userSpaceOnUse", x: 0, y: 0, width: 400, height: 320 }, defs);+ mk("rect", { x: 0, y: 0, width: 400, height: 320, fill: `url(#${id}g)` }, m);+ return `url(#${id})`;+ }+ function reflect(svg, parent, P, front, ring, z0, depth) {+ const r = ghost(P, front, ring, z0, depth);+ const gh = mk("g", { class: "ghost", mask: fade(svg, r.y0, r.y1) }, parent);+ mk("path", { d: r.d }, gh);+ }+ var boards = [];+ var byStage = /* @__PURE__ */ new Map();+ var raf = 0;+ var last = 0;+ var io = null;+ var rm = null;+ function frame(now) {+ const dt = Math.min(0.05, Math.max(0, (now - last) / 1e3));+ last = now;+ let any = false;+ for (const b of boards.slice()) if (b.vis && b.awake) {+ b.awake = !!b.tick(dt, now);+ any = any || b.awake;+ }+ raf = any ? requestAnimationFrame(frame) : 0;+ }+ function wake(b) {+ b.awake = true;+ if (!raf) {+ last = performance.now();+ raf = requestAnimationFrame(frame);+ }+ }+ var onMotion = () => {+ setReducedMotion(!!rm?.matches);+ boards.forEach(wake);+ };+ function start() {+ if (io) return;+ io = new IntersectionObserver((es) => {+ for (const e of es) {+ const b = byStage.get(e.target);+ if (!b) continue;+ b.vis = e.isIntersecting;+ if (b.vis) wake(b);+ }+ }, { rootMargin: "80px" });+ rm = matchMedia("(prefers-reduced-motion: reduce)");+ setReducedMotion(rm.matches);+ rm.addEventListener("change", onMotion);+ }+ function stop() {+ if (raf) cancelAnimationFrame(raf);+ raf = 0;+ io?.disconnect();+ io = null;+ rm?.removeEventListener("change", onMotion);+ rm = null;+ }+ function register(stage, tick) {+ start();+ const b = { stage, tick, vis: false, awake: true };+ boards.push(b);+ byStage.set(stage, b);+ io.observe(stage);+ tick(0, performance.now());+ let gone = false;+ return {+ wake: () => {+ if (!gone) wake(b);+ },+ unregister: () => {+ if (gone) return;+ gone = true;+ boards = boards.filter((x) => x !== b);+ if (byStage.get(stage) === b) {+ byStage.delete(stage);+ io?.unobserve(stage);+ }+ if (!boards.length) stop();+ }+ };+ }+ function pointer(stage, on) {+ let tm = 0;+ const pt = (e) => {+ const r = stage.getBoundingClientRect();+ return [(e.clientX - r.left) / r.width * 400, (e.clientY - r.top) / r.height * 320];+ };+ const move = (e) => {+ clearTimeout(tm);+ on.move(pt(e), e);+ };+ const down = (e) => {+ clearTimeout(tm);+ if (e.pointerType !== "mouse") stage.releasePointerCapture?.(e.pointerId);+ if (on.down) on.down(pt(e), e);+ else on.move(pt(e), e);+ };+ const leave = (e) => {+ clearTimeout(tm);+ tm = window.setTimeout(() => on.leave(e), e.pointerType === "mouse" ? 0 : 1400);+ };+ stage.addEventListener("pointermove", move);+ stage.addEventListener("pointerdown", down);+ stage.addEventListener("pointerleave", leave);+ return () => {+ clearTimeout(tm);+ stage.removeEventListener("pointermove", move);+ stage.removeEventListener("pointerdown", down);+ stage.removeEventListener("pointerleave", leave);+ };+ }+ function disposer() {+ let fns = [];+ return {+ add: (fn) => {+ fns.push(fn);+ },+ on: (target, type, fn, opts) => {+ const h = fn;+ target.addEventListener(type, h, opts);+ fns.push(() => target.removeEventListener(type, h, opts));+ },+ dispose: () => {+ const run2 = fns;+ fns = [];+ for (let i = run2.length - 1; i >= 0; i--) run2[i]();+ }+ };+ }++ // packages/hairline/src/core/styles.ts+ var LIGHT = { plate: "#ffffff", hi: "#232327", edge: "#a4a4ac", mid: "#c3c3c9", lo: "#e0e0e4" };+ var DARK = { plate: "#08090a", hi: "#d0d6e0", edge: "#5b5d64", mid: "#3e3e44", lo: "#29292d" };+ var KEYS = ["plate", "hi", "edge", "mid", "lo"];+ var vars = (p) => KEYS.map((k) => `--hl-${k}:var(--hairline-${k},${p[k]});`).join("");+ var EASE = "cubic-bezier(0.5,0,0.1,1)";+ var SVG = ":where([data-hairline]>svg)";+ function css(lightDark) {+ const both = Object.fromEntries(KEYS.map((k) => [k, `light-dark(${LIGHT[k]},${DARK[k]})`]));+ return [+ // the box, and the palette: light unless something below says otherwise+ `:where([data-hairline]){display:block;position:relative;aspect-ratio:5/4;touch-action:pan-y;user-select:none;-webkit-user-select:none;--hl-sw:var(--hairline-stroke,0.9);${vars(LIGHT)}}`,+ // the page's color-scheme+ lightDark ? `:where([data-hairline]){${vars(both)}}` : "",+ // an ancestor that says dark+ `:where(.dark,[data-theme="dark"]) :where([data-hairline]){${vars(DARK)}}`,+ // the figure's own theme option+ `:where([data-hairline][data-hairline-theme="light"]){${vars(LIGHT)}}`,+ `:where([data-hairline][data-hairline-theme="dark"]){${vars(DARK)}}`,+ `:where([data-hairline]:focus-visible){outline:1.5px solid var(--hl-hi);outline-offset:2px}`,+ `${SVG}{position:absolute;inset:0;width:100%;height:100%;display:block}`,+ // Riffle's live region: read, not seen+ `:where([data-hairline]>[data-hairline-live]){position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap}`,+ // the drawing: plates are filled with the plate colour and painted back to front+ `${SVG} :where(path,polygon,ellipse,line){fill:var(--hl-plate);stroke:var(--hl-mid);stroke-width:var(--hl-sw);vector-effect:non-scaling-stroke;stroke-linejoin:round;stroke-linecap:round;transition:stroke 260ms ${EASE}}`,+ `${SVG} :where(.nf){fill:none}`,+ `${SVG} :where(.fo){stroke:none}`,+ `${SVG} :where(.sil){stroke:var(--hl-edge)}`,+ `${SVG} :where(.hi){stroke:var(--hl-hi)}`,+ `${SVG} :where(.lo){stroke:var(--hl-lo)}`,+ `${SVG} :where(.dash){stroke-dasharray:1 3}`,+ `${SVG} :where(.dot){stroke:none;fill:var(--hl-hi);transition:fill 260ms ${EASE}}`,+ `${SVG} :where(.dot.m){fill:var(--hl-edge)}`,+ `${SVG} :where(.dot.off){fill:var(--hl-lo)}`,+ `${SVG} :where(.ghost path){fill:none;stroke:var(--hl-mid)}`+ ].join("");+ }+ var done = /* @__PURE__ */ new WeakSet();+ function inject(root) {+ if (done.has(root)) return;+ done.add(root);+ const doc = root.nodeType === 9 ? root : root.ownerDocument;+ const win = doc.defaultView;+ const text = css(!!win?.CSS?.supports?.("color", "light-dark(#000,#fff)"));+ if (win && "adoptedStyleSheets" in root) {+ try {+ const sheet = new win.CSSStyleSheet();+ sheet.replaceSync(text);+ root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet];+ return;+ } catch {+ }+ }+ const style = doc.createElement("style");+ style.setAttribute("data-hairline-style", "");+ style.textContent = text;+ (root.nodeType === 9 ? doc.head ?? doc.documentElement : root).appendChild(style);+ }+ return __toCommonJS(kernel_exports);+})();+/* /hairline kernel */+</script>+<script id="hl-bench">+/*+ * The bench: the page a figure is shown on. It makes the host and the svg the+ * way the package's mount does, hands them to the figure, and owns everything+ * around it: the read-out, the slider, the theme, the line under the stage.+ */+(() => {+ const RULES = ["hit", "order", "reach", "accent", "rest", "honesty", "cost", "clock", "radius", "quiet"];+ const $ = (id) => document.getElementById(id);+ const root = document.documentElement, params = new URLSearchParams(location.search);++ /* the theme: the system's until the switch is pressed, then the switch's */+ const dark = () => (root.dataset.theme ? root.dataset.theme === "dark" : matchMedia("(prefers-color-scheme: dark)").matches);+ const label = () => { $("theme").textContent = dark() ? "dark" : "light"; };+ $("theme").addEventListener("click", () => { root.dataset.theme = dark() ? "light" : "dark"; label(); });+ /* ?theme=light or ?theme=dark wins over the system's, as pressing the switch does */+ if (["light", "dark"].includes(params.get("theme"))) root.dataset.theme = params.get("theme");+ label();++ /* ?intensity=0 sets the slider before the figure mounts, for a look at either end */+ const i = (params.get("intensity") || "").trim();+ if (i && Number.isFinite(Number(i))) $("intensity").value = String(Math.min(1, Math.max(0, Number(i))));++ /* ?w=240 narrows the page, for a look at the size of a thumbnail */+ const w = Number(params.get("w"));+ if (w > 0) document.querySelector("main").style.maxWidth = w + "px";++ /* a figure that fails says so under the stage, instead of leaving an empty plate */+ addEventListener("error", (e) => {+ $("error").hidden = false;+ $("error").textContent = String((e.error && e.error.message) || e.message);+ });++ let mounted = false;+ window.hairline = (figure) => {+ if (mounted) throw new Error("hairline: one figure per page.");+ mounted = true;+ const stage = $("stage"), slider = $("intensity");++ /* intensity to the figure's own number: two straight lines that meet at 0.5, as in the package */+ const [lo, mid, hi] = figure.range;+ const at = (i) => Math.round((i <= 0.5 ? lo + (i / 0.5) * (mid - lo) : mid + ((i - 0.5) / 0.5) * (hi - mid)) * 1000) / 1000;++ HL.inject(document);+ stage.setAttribute("data-hairline", figure.name);+ stage.setAttribute("role", "img");+ stage.setAttribute("aria-label", figure.means);+ const svg = HL.mk("svg", { viewBox: "0 0 400 320", "aria-hidden": "true" }, stage);++ let text = null;+ const read = {+ get textContent() { return text; },+ set textContent(value) { text = value == null ? "" : String(value); $("read").textContent = text; },+ };++ document.title = "Hairline · " + figure.name;+ $("name").textContent = figure.name;+ $("means").textContent = figure.means;+ $("rules").textContent = figure.rules.map((n) => String(n).padStart(2, "0") + " " + RULES[n - 1]).join(" · ");+ const show = () => { $("value").textContent = String(at(Number(slider.value))); };+ show();++ const handle = figure.mount({ stage, svg, read }, at(Number(slider.value)));+ if (text === null) read.textContent = "rest";+ slider.addEventListener("input", () => { show(); handle.set(at(Number(slider.value))); });+ window.hairline.figure = handle;++ /* ?at=200,160 holds the pointer at a viewBox point, for a picture of the answer without a mouse */+ const p = (params.get("at") || "").split(",").map(Number);+ if (p.length === 2 && p.every(Number.isFinite)) {+ const r = stage.getBoundingClientRect();+ stage.dispatchEvent(new PointerEvent("pointermove", {+ pointerType: "mouse", pointerId: 1, bubbles: true,+ clientX: r.left + (p[0] / 400) * r.width, clientY: r.top + (p[1] / 320) * r.height,+ }));+ }+ };+})();+</script>+<script type="module" id="hl-figure">+/**+ * Sidings: a model-railway board, a trunk line at the back and three sidings+ * laddered off it toward the front, a short train of wagons on each. The+ * track that is checked out stands its wagons up, rising toward its tip, the+ * 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.+ *+ * 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,+ 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;+// 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.+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 },+];++/** The track's centre line at x: straight, or easing off its parent's line through the switch. */+function lineY(t, x) {+ if (t.from < 0) return t.y;+ const yp = TRACKS[t.from].y, u = clamp((x - t.xf) / LEAD, 0, 1);+ return yp + (t.y - yp) * u * u * (3 - 2 * u);+}++/** Two rails, as open paths on the ground, from the switch to the end of the track. */+function rails(P, t) {+ const xs = [];+ for (let x = t.xf; x < t.xf + LEAD; x += 3) xs.push(x);+ xs.push(t.xf + LEAD, t.xe);+ return [-1, 1].map((s) => open(xs.map((x) => P(x, lineY(t, x) + (s * GAUGE) / 2, 0)))).join("");+}++function mount({ stage, svg, read }, value) {+ const bag = disposer();+ let lift = value;+ /** How far wagon i of a checked-out track stands up: rising toward the head. */+ const up = (t, i) => lift * (0.45 + (0.55 * (i + 1)) / t.n);++ // The camera is fitted to the board and to every wagon at the slider's far end.+ const wag = [];+ TRACKS.forEach((t, k) => {+ for (let i = 0; i < t.n; i++) wag.push({ k, i, x0: t.x0 + i * PITCH, y0: t.y - WW / 2 });+ });+ const C = Cam(45, 0.5, 2.1);+ const pts = [[BX0, BY0, -PB], [BX1, BY0, -PB], [BX0, BY1, -PB], [BX1, BY1, -PB]];+ for (const w of wag) pts.push([w.x0, w.y0, BASE + TOP], [w.x0 + WL, w.y0, BASE + TOP]);+ fit(C, pts, 200, 166);+ const P = proj(C), front = facing(C);++ 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);++ // 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));+ for (const t of TRACKS) t.cars = [];+ for (const w of wag) {+ const t = TRACKS[w.k];+ [w.ring, w.inner] = rings(w.x0, w.y0, w.x0 + WL, w.y0 + WW, 2.6, 1);+ w.el = solid(g);+ w.tw = tween(w.k === 0 ? up(t, w.i) : 0);+ w.drawn = NaN;+ // a siding's number, as dots on its head's lid+ w.dots = [];+ if (w.i === t.n - 1) for (let j = 0; j < w.k; j++) w.dots.push(flatDot(w.el.g, C, 0.6, "dot m"));+ t.cars[w.i] = w;+ }++ function draw(w, h) {+ put(w.el, prism(P, front, w.ring, w.inner, 0, 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)));+ }++ const B = register(stage, (_dt, now) => {+ let moving = false;+ for (const w of wag) {+ const h = BASE + tval(w.tw, now);+ if (!tdone(w.tw, now)) moving = true;+ if (h !== w.drawn) { w.drawn = h; draw(w, h); }+ }+ return moving;+ });+ bag.add(B.unregister);++ /** Whether a screen point is inside a convex polygon. */+ const within = (q, pg) => {+ const s = pg.map((a, i) => { const b = pg[(i + 1) % pg.length]; return (b[0] - a[0]) * (q[1] - a[1]) - (b[1] - a[1]) * (q[0] - a[0]); });+ return s.every((v) => v >= 0) || s.every((v) => v <= 0);+ };+ /** The track under the point; else the one whose straight run holds it on a fixed plane at wagon height; -1 outside. */+ function hit([sx, sy]) {+ const [x, y] = unproj(C, sx, sy, BASE), t = TRACKS[act];+ // the checked-out track keeps the pointer anywhere on its wagons' TARGET pose, never the pose on screen+ if (t.cars.some((w, i) => within([sx, sy], hull(ringAt(P, w.ring, 0).concat(ringAt(P, w.ring, BASE + up(t, i))))))) return { k: act, x };+ for (let k = 0; k < TRACKS.length; k++) {+ const t = TRACKS[k], x0 = t.from < 0 ? t.xf : t.xf + LEAD;+ if (Math.abs(y - t.y) < G / 2 && x >= x0 && x <= t.xe + 4) return { k, x };+ }+ return { k: -1, x };+ }++ let act = 0, ox = 0;+ /** Checks out track a; every track's wagons move in turn outwards from x, step ms apart. */+ function apply(a, x, step) {+ const now = performance.now();+ TRACKS.forEach((t, k) => {+ const ai = clamp(Math.round((x - t.x0 - WL / 2) / PITCH), 0, t.n - 1);+ t.cars.forEach((w, i) => tset(w.tw, k === a ? up(t, i) : 0, now, Math.abs(i - ai) * step));+ const head = t.cars[t.n - 1];+ head.el.sil.classList.toggle("hi", k === a);+ head.dots.forEach((d) => d.classList.toggle("m", k !== a));+ });+ B.wake();+ }+ apply(0, 0, 0);+ read.textContent = "rest";++ function over({ k, x }) {+ read.textContent = k < 0 ? "rest" : TRACKS[k].tag;+ const a = k < 0 ? 0 : k;+ if (a === act) return;+ act = a; ox = x;+ apply(a, x, STEP);+ }++ bag.add(pointer(stage, { move: (p) => over(hit(p)), leave: () => over({ k: -1, x: ox }) }));+ bag.add(() => svg.replaceChildren());++ return {+ set: (v) => { lift = v; apply(act, ox, 0); },+ destroy: bag.dispose,+ };+}++hairline({+ name: "sidings",+ means: "A trunk line and three sidings: the track under the pointer is checked out, its wagons rising in turn to a bright head.",+ rules: [1, 2, 5, 10],+ range: [10, 16, 22],+ mount,+});+</script>+</body>+</html>diff --git a/apps/site/public/skill/hairline-storm.html b/apps/site/public/skill/hairline-storm.htmlnew file mode 100644index 0000000..c3cb4a4--- /dev/null+++ b/apps/site/public/skill/hairline-storm.html@@ -0,0 +1,885 @@+<!doctype html>+<html lang="en">+<head>+<meta charset="utf-8">+<meta name="viewport" content="width=device-width, initial-scale=1">+<title>Hairline figure</title>+<link rel="icon" href="data:,">+<style>+ :root { color-scheme: light; --ground: #ffffff; --ink: #232327; --muted: #6f6f78; --line: #e0e0e4; }+ @media (prefers-color-scheme: dark) {+ :root:not([data-theme="light"]) { color-scheme: dark; --ground: #08090a; --ink: #d0d6e0; --muted: #8a8c95; --line: #29292d; }+ }+ :root[data-theme="dark"] { color-scheme: dark; --ground: #08090a; --ink: #d0d6e0; --muted: #8a8c95; --line: #29292d; }+ :root[data-theme="light"] { color-scheme: light; }+ * { box-sizing: border-box; }+ body {+ margin: 0; min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;+ background: var(--ground); color: var(--ink);+ font: 13px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased;+ }+ main { width: 100%; max-width: 640px; }+ .plate { position: relative; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }+ .tag, .label, output, button { font: 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 0.02em; }+ .tag { position: absolute; top: 12px; z-index: 1; color: var(--muted); pointer-events: none; }+ #name { left: 14px; }+ #read { right: 14px; color: var(--ink); font-variant-numeric: tabular-nums; }+ .controls { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 14px; }+ .label { color: var(--muted); }+ input[type="range"] {+ flex: 1 1 96px; min-width: 0; height: 32px; margin: 0; background: transparent; cursor: pointer;+ -webkit-appearance: none; appearance: none;+ }+ input[type="range"]::-webkit-slider-runnable-track { height: 1px; background: var(--muted); }+ input[type="range"]::-webkit-slider-thumb {+ -webkit-appearance: none; width: 13px; height: 13px; margin-top: -6px; border-radius: 50%;+ border: 1px solid var(--ink); background: var(--ground);+ }+ input[type="range"]::-moz-range-track { height: 1px; background: var(--muted); }+ input[type="range"]::-moz-range-thumb { width: 11px; height: 11px; border-radius: 50%; border: 1px solid var(--ink); background: var(--ground); }+ input[type="range"]:focus-visible, button:focus-visible { outline: 1.5px solid var(--ink); outline-offset: 2px; }+ output { min-width: 4ch; text-align: right; font-variant-numeric: tabular-nums; }+ button {+ height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;+ background: transparent; color: var(--ink); cursor: pointer;+ }+ #means { margin: 14px 0 0; text-wrap: pretty; }+ #rules { margin: 6px 0 0; line-height: 1.6; }+ #error { margin: 12px 0 0; padding-left: 10px; border-left: 1px solid var(--ink); }+</style>+</head>+<body>+<main>+ <div class="plate">+ <span class="tag" id="name"></span>+ <span class="tag" id="read"></span>+ <div id="stage"></div>+ </div>+ <div class="controls">+ <label class="label" for="intensity">intensity</label>+ <input id="intensity" type="range" min="0" max="1" step="0.01" value="0.5">+ <output id="value" for="intensity"></output>+ <span class="label">theme</span>+ <button id="theme" type="button" aria-label="Switch between the light and the dark theme"></button>+ </div>+ <p id="means"></p>+ <p id="rules" class="label"></p>+ <p id="error" role="alert" hidden></p>+</main>+<script id="hl-kernel">+/* hairline kernel sha256:8e2abcbdf63c7755195ee942c39e9c8ea6a539d1147e986dd1c153559121f075 */+/*+ * HL: everything a figure may call. Read this index; the code under it is the+ * package's src/core, unchanged, and a figure should not need to read it.+ *+ * Every figure is drawn in a 400 × 320 viewBox. World space is x/y on the+ * ground and z up. Plates are filled with the ground colour and painted back+ * to front, so a nearer one covers a farther one: append in that order. At+ * the default camera, Cam(45, 0.5, S), +x runs down to the right and +y down+ * to the left, so the corner with the largest x and y is nearest the viewer:+ * append by ascending x + y, from the far corner (smallest x and y) to it.+ *+ * Camera+ * Cam(azDeg, k, S) a camera: azimuth in degrees, k = sin(elevation) (0.5 is the 2:1 view), S = scale+ * fit(C, points, cx, cy) centres the box of [x, y, z] points on (cx, cy); call it once, before proj+ * it only centres, it never scales: choose S by trying values, with the most extreme pose in points.+ * The six figures use S 1.42 to 2.12; the boxes they fit come out 230 to 310 wide and 180 to 245 tall+ * proj(C) returns P(x, y, z), which gives [sx, sy]+ * unproj(C, sx, sy, z) the world [x, y] under a screen point, on the plane at height z+ * facing(C) returns front(sample): whether a ring sample faces the camera+ * Rounded solids+ * rrect(u0, v0, u1, v1, r, n) a rounded rectangle, as a ring of samples {u, v, nu, nv}+ * circ(R, n) a circle, as a ring+ * rings(x0, y0, x1, y1, r, b) [ring, inner]: a rounded footprint and its crease ring, inset by b+ * r, the corner radius, is cut to half the shorter side. b, the crease's inset in world units+ * (0.6 to 2.2 in the figures), must stay under half the shorter side or the crease turns inside out+ * prism(P, front, ring, inner, z0, z1) {sil, crease}: a solid standing from z0 to z1, as two path strings+ * ringAt(P, ring, z) the ring's points, projected at height z+ * run(ring, keep) the one cyclic run of samples that pass keep+ * hull(points) the convex hull of screen points+ * extremes(P, ring) [left, right, nearest] samples: where dashed drops fall from+ * fillet(points, radii, n) rounds every vertex of a closed polygon; returns the new points+ * radii is an array, one radius per vertex, each cut to half its shorter edge; a single number gives NaN.+ * n is the steps round each corner, default 4: each vertex becomes n + 1 points+ * ghost(P, front, ring, z0, depth) a reflection's path {d, y0, y1}; reflect() draws it for you+ * Paths and numbers+ * poly(points) a closed path string+ * open(points) an open polyline string+ * seg(a, b) one segment between two screen points [sx, sy], as its own subpath; project world points with P first+ * clamp(v, a, b)+ * lerp(a, b, t)+ * rad(deg)+ * r2(n) two decimals+ * The continuous clock: one spring per moving number+ * spring(x, opts) at rest on x; write .t to retarget; opts {k, c, m, eps}, default k 100, c 18, m 1+ * stepS(sp, dt) advances by dt seconds; returns whether it is still moving+ * The discrete clock: a 700ms tween on (.32, .72, 0, 1)+ * tween(v, dur) at rest on v; dur defaults to 700 (ms)+ * tset(tw, to, now, delay) retargets from where it is, after delay ms: the stagger+ * the same target again does nothing, so calling it on every pointer move is safe+ * tval(tw, now) its value at now+ * tdone(tw, now) whether it has landed+ * bezier(x1, y1, x2, y2) a CSS cubic-bezier, as a function of progress+ * EASE_LIFT the lift curve itself+ * reducedMotion() true when the reader asked for less motion; springs and tweens already land at once+ * setReducedMotion(on) the loop's business, not a figure's+ * Drawing+ * mk(tag, attrs, parent) one svg element: the only way a figure makes a node+ * solid(parent) {g, sil, cr}: a group holding a silhouette path and a crease path+ * put(solid, paths) writes prism()'s {sil, crease} into solid()'s {sil, cr}: sil into sil, crease into cr+ * flatDot(parent, C, r, cls) a dot lying on the ground plane; cls is "dot", "dot m" or "dot off"+ * place(el, point) moves a dot or a circle to [sx, sy]+ * reflect(svg, parent, P, front, ring, z0, depth) a fading mirror under a solid+ * fade(svg, y0, y1, a0) a vertical fade, as a mask; returns the value for a mask attribute+ * Life+ * register(stage, tick) joins the one frame loop; tick(dt in seconds, now in ms) returns true to ask for another frame; gives {wake, unregister}+ * pointer(stage, handlers) {move(point), down(point), leave()}, points in viewBox units; returns its disposer+ * disposer() {add, on, dispose}: collects tear-down, so destroy is bag.dispose+ * The bench's business, not a figure's+ * css(lightDark)+ * inject(root)+ *+ * Classes, on path, polygon, ellipse and line. They are the whole palette; a+ * figure sets no colour, width or fill of its own.+ * (none) filled with the ground colour, medium stroke+ * sil the silhouette's stroke hi the bright stroke: the only highlight+ * lo the dim stroke nf no fill fo fill only, no stroke+ * dash a dashed guide+ * dot a bright dot dot m a medium dot dot off a dim dot+ */+var HL = (() => {+ var __defProp = Object.defineProperty;+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;+ var __getOwnPropNames = Object.getOwnPropertyNames;+ var __hasOwnProp = Object.prototype.hasOwnProperty;+ var __export = (target, all) => {+ for (var name in all)+ __defProp(target, name, { get: all[name], enumerable: true });+ };+ var __copyProps = (to, from, except, desc) => {+ if (from && typeof from === "object" || typeof from === "function") {+ for (let key of __getOwnPropNames(from))+ if (!__hasOwnProp.call(to, key) && key !== except)+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });+ }+ return to;+ };+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);++ // packages/hairline/src/core/kernel.ts+ var kernel_exports = {};+ __export(kernel_exports, {+ Cam: () => Cam,+ EASE_LIFT: () => EASE_LIFT,+ bezier: () => bezier,+ circ: () => circ,+ clamp: () => clamp,+ css: () => css,+ disposer: () => disposer,+ extremes: () => extremes,+ facing: () => facing,+ fade: () => fade,+ fillet: () => fillet,+ fit: () => fit,+ flatDot: () => flatDot,+ ghost: () => ghost,+ hull: () => hull,+ inject: () => inject,+ lerp: () => lerp,+ mk: () => mk,+ open: () => open,+ place: () => place,+ pointer: () => pointer,+ poly: () => poly,+ prism: () => prism,+ proj: () => proj,+ put: () => put,+ r2: () => r2,+ rad: () => rad,+ reducedMotion: () => reducedMotion,+ reflect: () => reflect,+ register: () => register,+ ringAt: () => ringAt,+ rings: () => rings,+ rrect: () => rrect,+ run: () => run,+ seg: () => seg,+ setReducedMotion: () => setReducedMotion,+ solid: () => solid,+ spring: () => spring,+ stepS: () => stepS,+ tdone: () => tdone,+ tset: () => tset,+ tval: () => tval,+ tween: () => tween,+ unproj: () => unproj+ });++ // packages/hairline/src/core/iso.ts+ var clamp = (v, a, b) => Math.max(a, Math.min(b, v));+ var lerp = (a, b, t) => a + (b - a) * t;+ var rad = (d) => d * Math.PI / 180;+ var r2 = (n) => Math.round(n * 100) / 100;+ var poly = (pts) => "M" + pts.map((p) => r2(p[0]) + " " + r2(p[1])).join("L") + "Z";+ var seg = (a, b) => `M${r2(a[0])} ${r2(a[1])}L${r2(b[0])} ${r2(b[1])}`;+ var open = (pts) => pts.length < 2 ? "" : "M" + pts.map((p) => r2(p[0]) + " " + r2(p[1])).join("L");+ var Cam = (azDeg, k, S) => ({ az: rad(azDeg), k, S, ox: 0, oy: 0 });+ function proj(C) {+ const c = Math.cos(C.az), s = Math.sin(C.az), zf = Math.sqrt(1 - C.k * C.k);+ return (x, y, z) => {+ const X = x * c - y * s, Y = x * s + y * c;+ return [C.ox + C.S * X, C.oy + C.S * (Y * C.k - z * zf)];+ };+ }+ function unproj(C, sx, sy, z) {+ const c = Math.cos(C.az), s = Math.sin(C.az), zf = Math.sqrt(1 - C.k * C.k);+ const X = (sx - C.ox) / C.S, Y = ((sy - C.oy) / C.S + z * zf) / C.k;+ return [X * c + Y * s, -X * s + Y * c];+ }+ function fit(C, pts, cx, cy) {+ C.ox = 0;+ C.oy = 0;+ const P = proj(C);+ let a = 1e9, b = -1e9, c = 1e9, d = -1e9;+ for (const p of pts) {+ const q = P(p[0], p[1], p[2]);+ a = Math.min(a, q[0]);+ b = Math.max(b, q[0]);+ c = Math.min(c, q[1]);+ d = Math.max(d, q[1]);+ }+ C.ox = cx - (a + b) / 2;+ C.oy = cy - (c + d) / 2;+ }+ function rrect(u0, v0, u1, v1, r, n = 4) {+ r = Math.max(0, Math.min(r, (u1 - u0) / 2, (v1 - v0) / 2));+ const out = [];+ for (const [cu, cv, a0] of [[u1 - r, v1 - r, 0], [u0 + r, v1 - r, 90], [u0 + r, v0 + r, 180], [u1 - r, v0 + r, 270]])+ for (let k = 0; k <= n; k++) {+ const a = rad(a0 + 90 * k / n), ca = Math.cos(a), sa = Math.sin(a);+ out.push({ u: cu + r * ca, v: cv + r * sa, nu: ca, nv: sa });+ }+ return out;+ }+ function circ(R, n = 96) {+ const out = [];+ for (let k = 0; k < n; k++) {+ const a = k / n * Math.PI * 2, ca = Math.cos(a), sa = Math.sin(a);+ out.push({ u: R * ca, v: R * sa, nu: ca, nv: sa });+ }+ return out;+ }+ function hull(input) {+ const pts = input.slice().sort((a, b) => a[0] - b[0] || a[1] - b[1]);+ const x = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);+ const lo = [], up = [];+ for (const p of pts) {+ while (lo.length > 1 && x(lo[lo.length - 2], lo[lo.length - 1], p) <= 0) lo.pop();+ lo.push(p);+ }+ for (let i = pts.length - 1; i >= 0; i--) {+ const p = pts[i];+ while (up.length > 1 && x(up[up.length - 2], up[up.length - 1], p) <= 0) up.pop();+ up.push(p);+ }+ lo.pop();+ up.pop();+ return lo.concat(up);+ }+ var ringAt = (P, ring, z) => ring.map((q) => P(q.u, q.v, z));+ var facing = (C) => {+ const s = Math.sin(C.az), c = Math.cos(C.az);+ return (q) => q.nu * s + q.nv * c >= -1e-6;+ };+ function run(ring, keep) {+ const n = ring.length;+ let s = -1;+ for (let i = 0; i < n; i++) if (keep(ring[i]) && !keep(ring[(i + n - 1) % n])) {+ s = i;+ break;+ }+ if (s < 0) return keep(ring[0]) ? ring.slice() : [];+ const out = [];+ for (let k = 0; k < n && keep(ring[(s + k) % n]); k++) out.push(ring[(s + k) % n]);+ return out;+ }+ function prism(P, front, ring, inner, z0, z1) {+ return {+ sil: poly(hull(ringAt(P, ring, z1).concat(ringAt(P, ring, z0)))),+ crease: inner ? open(ringAt(P, run(inner, front), z1)) : ""+ };+ }+ var rings = (x0, y0, x1, y1, r, b) => [+ rrect(x0, y0, x1, y1, r),+ rrect(x0 + b, y0 + b, x1 - b, y1 - b, Math.max(0.3, r - b))+ ];+ function extremes(P, ring) {+ const pr = ring.map((q) => P(q.u, q.v, 0));+ let a = 0, b = 0, c = 0;+ pr.forEach((p, k) => {+ if (p[0] < pr[a][0]) a = k;+ if (p[0] > pr[b][0]) b = k;+ if (p[1] > pr[c][1]) c = k;+ });+ return [ring[a], ring[b], ring[c]];+ }+ function fillet(pts, rs, n = 4) {+ const m = pts.length, out = [];+ for (let i = 0; i < m; i++) {+ const a = pts[(i + m - 1) % m], p = pts[i], b = pts[(i + 1) % m];+ const la = Math.hypot(a[0] - p[0], a[1] - p[1]), lb = Math.hypot(b[0] - p[0], b[1] - p[1]);+ const t = Math.min(rs[i], la / 2, lb / 2);+ const p1 = [p[0] + (a[0] - p[0]) / la * t, p[1] + (a[1] - p[1]) / la * t];+ const p2 = [p[0] + (b[0] - p[0]) / lb * t, p[1] + (b[1] - p[1]) / lb * t];+ for (let k = 0; k <= n; k++) {+ const s = k / n, w = 1 - s;+ out.push([w * w * p1[0] + 2 * w * s * p[0] + s * s * p2[0], w * w * p1[1] + 2 * w * s * p[1] + s * s * p2[1]]);+ }+ }+ return out;+ }+ function ghost(P, front, ring, z0, depth) {+ const f = run(ring, front), lowP = ringAt(P, f, z0 - depth);+ return {+ d: open(lowP) + [f[0], f[f.length - 1]].map((q) => seg(P(q.u, q.v, z0), P(q.u, q.v, z0 - depth))).join(""),+ y0: Math.min(...ringAt(P, f, z0).map((p) => p[1])),+ y1: Math.max(...lowP.map((p) => p[1])) + 2+ };+ }++ // packages/hairline/src/core/motion.ts+ var reduced = false;+ var setReducedMotion = (on) => {+ reduced = on;+ };+ var reducedMotion = () => reduced;+ function spring(x, o = {}) {+ return { x, v: 0, t: x, k: o.k ?? 100, c: o.c ?? 18, m: o.m ?? 1, eps: o.eps ?? 0.01 };+ }+ function stepS(sp, dt) {+ if (reduced) {+ sp.x = sp.t;+ sp.v = 0;+ return false;+ }+ const n = Math.max(1, Math.ceil(dt * 240)), h = dt / n;+ for (let i = 0; i < n; i++) {+ const a = (-sp.k * (sp.x - sp.t) - sp.c * sp.v) / sp.m;+ sp.v += a * h;+ sp.x += sp.v * h;+ }+ if (Math.abs(sp.x - sp.t) < sp.eps && Math.abs(sp.v) < sp.eps * 10) {+ sp.x = sp.t;+ sp.v = 0;+ return false;+ }+ return true;+ }+ function bezier(x1, y1, x2, y2) {+ const cx = 3 * x1, bx = 3 * (x2 - x1) - cx, ax = 1 - cx - bx;+ const cy = 3 * y1, by = 3 * (y2 - y1) - cy, ay = 1 - cy - by;+ const X = (u) => ((ax * u + bx) * u + cx) * u;+ const Y = (u) => ((ay * u + by) * u + cy) * u;+ const dX = (u) => (3 * ax * u + 2 * bx) * u + cx;+ return (t) => {+ if (t <= 0) return 0;+ if (t >= 1) return 1;+ let u = t;+ for (let i = 0; i < 8; i++) {+ const e = X(u) - t;+ if (Math.abs(e) < 1e-5) break;+ const d = dX(u);+ if (Math.abs(d) < 1e-6) break;+ u -= e / d;+ }+ if (!(u >= 0 && u <= 1) || Math.abs(X(u) - t) > 1e-4) {+ let lo = 0, hi = 1;+ u = t;+ for (let i = 0; i < 24; i++) {+ if (X(u) < t) lo = u;+ else hi = u;+ u = (lo + hi) / 2;+ }+ }+ return Y(u);+ };+ }+ var EASE_LIFT = bezier(0.32, 0.72, 0, 1);+ var tween = (v, dur = 700) => ({ from: v, to: v, t0: -1e9, dur });+ var tval = (tw, now) => {+ const p = clamp((now - tw.t0) / tw.dur, 0, 1);+ return tw.from + (tw.to - tw.from) * (reduced ? 1 : EASE_LIFT(p));+ };+ var tset = (tw, to, now, delay) => {+ if (tw.to === to) return;+ tw.from = tval(tw, now);+ tw.to = to;+ tw.t0 = now + delay;+ };+ var tdone = (tw, now) => reduced || now >= tw.t0 + tw.dur;++ // packages/hairline/src/core/stage.ts+ var NS = "http://www.w3.org/2000/svg";+ function mk(tag, attrs, parent) {+ const e = document.createElementNS(NS, tag);+ if (attrs) for (const k in attrs) e.setAttribute(k, String(attrs[k]));+ if (parent) parent.appendChild(e);+ return e;+ }+ function solid(parent) {+ const g = mk("g", {}, parent);+ return { g, sil: mk("path", { class: "sil" }, g), cr: mk("path", { class: "nf lo" }, g) };+ }+ var put = (el, s) => {+ el.sil.setAttribute("d", s.sil);+ el.cr.setAttribute("d", s.crease);+ };+ var flatDot = (parent, C, r, cls) => mk("ellipse", { rx: r2(r * C.S), ry: r2(r * C.S * C.k), class: cls }, parent);+ var place = (el, q) => {+ el.setAttribute("cx", String(r2(q[0])));+ el.setAttribute("cy", String(r2(q[1])));+ };+ var fid = 0;+ function fade(svg, y0, y1, a0 = 0.7) {+ const id = "hl-fd" + ++fid, defs = mk("defs", {}, svg);+ const lg = mk("linearGradient", { id: id + "g", gradientUnits: "userSpaceOnUse", x1: 0, y1: r2(y0), x2: 0, y2: r2(y1) }, defs);+ mk("stop", { offset: 0, "stop-color": "#fff", "stop-opacity": a0 }, lg);+ mk("stop", { offset: 1, "stop-color": "#fff", "stop-opacity": 0 }, lg);+ const m = mk("mask", { id, maskUnits: "userSpaceOnUse", x: 0, y: 0, width: 400, height: 320 }, defs);+ mk("rect", { x: 0, y: 0, width: 400, height: 320, fill: `url(#${id}g)` }, m);+ return `url(#${id})`;+ }+ function reflect(svg, parent, P, front, ring, z0, depth) {+ const r = ghost(P, front, ring, z0, depth);+ const gh = mk("g", { class: "ghost", mask: fade(svg, r.y0, r.y1) }, parent);+ mk("path", { d: r.d }, gh);+ }+ var boards = [];+ var byStage = /* @__PURE__ */ new Map();+ var raf = 0;+ var last = 0;+ var io = null;+ var rm = null;+ function frame(now) {+ const dt = Math.min(0.05, Math.max(0, (now - last) / 1e3));+ last = now;+ let any = false;+ for (const b of boards.slice()) if (b.vis && b.awake) {+ b.awake = !!b.tick(dt, now);+ any = any || b.awake;+ }+ raf = any ? requestAnimationFrame(frame) : 0;+ }+ function wake(b) {+ b.awake = true;+ if (!raf) {+ last = performance.now();+ raf = requestAnimationFrame(frame);+ }+ }+ var onMotion = () => {+ setReducedMotion(!!rm?.matches);+ boards.forEach(wake);+ };+ function start() {+ if (io) return;+ io = new IntersectionObserver((es) => {+ for (const e of es) {+ const b = byStage.get(e.target);+ if (!b) continue;+ b.vis = e.isIntersecting;+ if (b.vis) wake(b);+ }+ }, { rootMargin: "80px" });+ rm = matchMedia("(prefers-reduced-motion: reduce)");+ setReducedMotion(rm.matches);+ rm.addEventListener("change", onMotion);+ }+ function stop() {+ if (raf) cancelAnimationFrame(raf);+ raf = 0;+ io?.disconnect();+ io = null;+ rm?.removeEventListener("change", onMotion);+ rm = null;+ }+ function register(stage, tick) {+ start();+ const b = { stage, tick, vis: false, awake: true };+ boards.push(b);+ byStage.set(stage, b);+ io.observe(stage);+ tick(0, performance.now());+ let gone = false;+ return {+ wake: () => {+ if (!gone) wake(b);+ },+ unregister: () => {+ if (gone) return;+ gone = true;+ boards = boards.filter((x) => x !== b);+ if (byStage.get(stage) === b) {+ byStage.delete(stage);+ io?.unobserve(stage);+ }+ if (!boards.length) stop();+ }+ };+ }+ function pointer(stage, on) {+ let tm = 0;+ const pt = (e) => {+ const r = stage.getBoundingClientRect();+ return [(e.clientX - r.left) / r.width * 400, (e.clientY - r.top) / r.height * 320];+ };+ const move = (e) => {+ clearTimeout(tm);+ on.move(pt(e), e);+ };+ const down = (e) => {+ clearTimeout(tm);+ if (e.pointerType !== "mouse") stage.releasePointerCapture?.(e.pointerId);+ if (on.down) on.down(pt(e), e);+ else on.move(pt(e), e);+ };+ const leave = (e) => {+ clearTimeout(tm);+ tm = window.setTimeout(() => on.leave(e), e.pointerType === "mouse" ? 0 : 1400);+ };+ stage.addEventListener("pointermove", move);+ stage.addEventListener("pointerdown", down);+ stage.addEventListener("pointerleave", leave);+ return () => {+ clearTimeout(tm);+ stage.removeEventListener("pointermove", move);+ stage.removeEventListener("pointerdown", down);+ stage.removeEventListener("pointerleave", leave);+ };+ }+ function disposer() {+ let fns = [];+ return {+ add: (fn) => {+ fns.push(fn);+ },+ on: (target, type, fn, opts) => {+ const h = fn;+ target.addEventListener(type, h, opts);+ fns.push(() => target.removeEventListener(type, h, opts));+ },+ dispose: () => {+ const run2 = fns;+ fns = [];+ for (let i = run2.length - 1; i >= 0; i--) run2[i]();+ }+ };+ }++ // packages/hairline/src/core/styles.ts+ var LIGHT = { plate: "#ffffff", hi: "#232327", edge: "#a4a4ac", mid: "#c3c3c9", lo: "#e0e0e4" };+ var DARK = { plate: "#08090a", hi: "#d0d6e0", edge: "#5b5d64", mid: "#3e3e44", lo: "#29292d" };+ var KEYS = ["plate", "hi", "edge", "mid", "lo"];+ var vars = (p) => KEYS.map((k) => `--hl-${k}:var(--hairline-${k},${p[k]});`).join("");+ var EASE = "cubic-bezier(0.5,0,0.1,1)";+ var SVG = ":where([data-hairline]>svg)";+ function css(lightDark) {+ const both = Object.fromEntries(KEYS.map((k) => [k, `light-dark(${LIGHT[k]},${DARK[k]})`]));+ return [+ // the box, and the palette: light unless something below says otherwise+ `:where([data-hairline]){display:block;position:relative;aspect-ratio:5/4;touch-action:pan-y;user-select:none;-webkit-user-select:none;--hl-sw:var(--hairline-stroke,0.9);${vars(LIGHT)}}`,+ // the page's color-scheme+ lightDark ? `:where([data-hairline]){${vars(both)}}` : "",+ // an ancestor that says dark+ `:where(.dark,[data-theme="dark"]) :where([data-hairline]){${vars(DARK)}}`,+ // the figure's own theme option+ `:where([data-hairline][data-hairline-theme="light"]){${vars(LIGHT)}}`,+ `:where([data-hairline][data-hairline-theme="dark"]){${vars(DARK)}}`,+ `:where([data-hairline]:focus-visible){outline:1.5px solid var(--hl-hi);outline-offset:2px}`,+ `${SVG}{position:absolute;inset:0;width:100%;height:100%;display:block}`,+ // Riffle's live region: read, not seen+ `:where([data-hairline]>[data-hairline-live]){position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap}`,+ // the drawing: plates are filled with the plate colour and painted back to front+ `${SVG} :where(path,polygon,ellipse,line){fill:var(--hl-plate);stroke:var(--hl-mid);stroke-width:var(--hl-sw);vector-effect:non-scaling-stroke;stroke-linejoin:round;stroke-linecap:round;transition:stroke 260ms ${EASE}}`,+ `${SVG} :where(.nf){fill:none}`,+ `${SVG} :where(.fo){stroke:none}`,+ `${SVG} :where(.sil){stroke:var(--hl-edge)}`,+ `${SVG} :where(.hi){stroke:var(--hl-hi)}`,+ `${SVG} :where(.lo){stroke:var(--hl-lo)}`,+ `${SVG} :where(.dash){stroke-dasharray:1 3}`,+ `${SVG} :where(.dot){stroke:none;fill:var(--hl-hi);transition:fill 260ms ${EASE}}`,+ `${SVG} :where(.dot.m){fill:var(--hl-edge)}`,+ `${SVG} :where(.dot.off){fill:var(--hl-lo)}`,+ `${SVG} :where(.ghost path){fill:none;stroke:var(--hl-mid)}`+ ].join("");+ }+ var done = /* @__PURE__ */ new WeakSet();+ function inject(root) {+ if (done.has(root)) return;+ done.add(root);+ const doc = root.nodeType === 9 ? root : root.ownerDocument;+ const win = doc.defaultView;+ const text = css(!!win?.CSS?.supports?.("color", "light-dark(#000,#fff)"));+ if (win && "adoptedStyleSheets" in root) {+ try {+ const sheet = new win.CSSStyleSheet();+ sheet.replaceSync(text);+ root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet];+ return;+ } catch {+ }+ }+ const style = doc.createElement("style");+ style.setAttribute("data-hairline-style", "");+ style.textContent = text;+ (root.nodeType === 9 ? doc.head ?? doc.documentElement : root).appendChild(style);+ }+ return __toCommonJS(kernel_exports);+})();+/* /hairline kernel */+</script>+<script id="hl-bench">+/*+ * The bench: the page a figure is shown on. It makes the host and the svg the+ * way the package's mount does, hands them to the figure, and owns everything+ * around it: the read-out, the slider, the theme, the line under the stage.+ */+(() => {+ const RULES = ["hit", "order", "reach", "accent", "rest", "honesty", "cost", "clock", "radius", "quiet"];+ const $ = (id) => document.getElementById(id);+ const root = document.documentElement, params = new URLSearchParams(location.search);++ /* the theme: the system's until the switch is pressed, then the switch's */+ const dark = () => (root.dataset.theme ? root.dataset.theme === "dark" : matchMedia("(prefers-color-scheme: dark)").matches);+ const label = () => { $("theme").textContent = dark() ? "dark" : "light"; };+ $("theme").addEventListener("click", () => { root.dataset.theme = dark() ? "light" : "dark"; label(); });+ /* ?theme=light or ?theme=dark wins over the system's, as pressing the switch does */+ if (["light", "dark"].includes(params.get("theme"))) root.dataset.theme = params.get("theme");+ label();++ /* ?intensity=0 sets the slider before the figure mounts, for a look at either end */+ const i = (params.get("intensity") || "").trim();+ if (i && Number.isFinite(Number(i))) $("intensity").value = String(Math.min(1, Math.max(0, Number(i))));++ /* ?w=240 narrows the page, for a look at the size of a thumbnail */+ const w = Number(params.get("w"));+ if (w > 0) document.querySelector("main").style.maxWidth = w + "px";++ /* a figure that fails says so under the stage, instead of leaving an empty plate */+ addEventListener("error", (e) => {+ $("error").hidden = false;+ $("error").textContent = String((e.error && e.error.message) || e.message);+ });++ let mounted = false;+ window.hairline = (figure) => {+ if (mounted) throw new Error("hairline: one figure per page.");+ mounted = true;+ const stage = $("stage"), slider = $("intensity");++ /* intensity to the figure's own number: two straight lines that meet at 0.5, as in the package */+ const [lo, mid, hi] = figure.range;+ const at = (i) => Math.round((i <= 0.5 ? lo + (i / 0.5) * (mid - lo) : mid + ((i - 0.5) / 0.5) * (hi - mid)) * 1000) / 1000;++ HL.inject(document);+ stage.setAttribute("data-hairline", figure.name);+ stage.setAttribute("role", "img");+ stage.setAttribute("aria-label", figure.means);+ const svg = HL.mk("svg", { viewBox: "0 0 400 320", "aria-hidden": "true" }, stage);++ let text = null;+ const read = {+ get textContent() { return text; },+ set textContent(value) { text = value == null ? "" : String(value); $("read").textContent = text; },+ };++ document.title = "Hairline · " + figure.name;+ $("name").textContent = figure.name;+ $("means").textContent = figure.means;+ $("rules").textContent = figure.rules.map((n) => String(n).padStart(2, "0") + " " + RULES[n - 1]).join(" · ");+ const show = () => { $("value").textContent = String(at(Number(slider.value))); };+ show();++ const handle = figure.mount({ stage, svg, read }, at(Number(slider.value)));+ if (text === null) read.textContent = "rest";+ slider.addEventListener("input", () => { show(); handle.set(at(Number(slider.value))); });+ window.hairline.figure = handle;++ /* ?at=200,160 holds the pointer at a viewBox point, for a picture of the answer without a mouse */+ const p = (params.get("at") || "").split(",").map(Number);+ if (p.length === 2 && p.every(Number.isFinite)) {+ const r = stage.getBoundingClientRect();+ stage.dispatchEvent(new PointerEvent("pointermove", {+ pointerType: "mouse", pointerId: 1, bubbles: true,+ clientX: r.left + (p[0] / 400) * r.width, clientY: r.top + (p[1] / 320) * r.height,+ }));+ }+ };+})();+</script>+<script type="module" id="hl-figure">+/**+ * Storm: a district of 25 rounded towers on a plinth, with one cloud hanging+ * over it and rain falling from it onto the roofs. The pointer steers the+ * cloud: it is read on the plane of the cloud's base, which never moves, and+ * the cloud follows it on two springs, clamped over the district. Each drop is+ * a dashed line from the cloud down to the roof or street under it, put in the+ * paint order just after the tower behind it, so nearer towers still cover it.+ * The drops under the cloud's middle reach the roofs; those at its rim give+ * out half way down, so the rain narrows to the block under the storm. The+ * tower under the storm takes the bright stroke; at rest the cloud is parked+ * off to one side of downtown. The slider is the cloud's radius: the reach of+ * the rain.+ */+const {+ Cam, clamp, facing, fit, prism, proj, rings, rrect, unproj, spring, stepS, seg,+ 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.+ */+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]);+ }+});++function mount({ stage, svg, read }, value) {+ const bag = disposer();+ 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]);+ }+ fit(C, ext, 200, 166);+ const P = proj(C), front = facing(C);++ const g = mk("g", {}, svg), cols = [], byCell = new Map();+ const plinth = solid(g);+ lobe(plinth, -6, -6, EXT + 6, EXT + 6, 9, 2.2, -PB, 0);+ // Diagonal by diagonal from the back corner: appending is painting back to front.+ for (let s = 0; s <= 2 * (N - 1); s++) for (let i = 0; i < N; i++) {+ const j = s - i;+ if (j < 0 || j >= N) continue;+ const u = i / (N - 1), v = j / (N - 1);+ const h = 5 + 32 * Math.exp(-((u - 0.12) ** 2 + (v - 0.18) ** 2) / 0.13) + 15 * Math.exp(-((u - 0.95) ** 2 + (v - 0.15) ** 2) / 0.05)+ + 3 * ((i * 7 + j * 3) % 3);+ const x0 = i * CELL + IN, y0 = j * CELL + IN;+ const [ring, inner] = rings(x0, y0, x0 + FOOT, y0 + FOOT, 2.2, 0.9);+ const el = solid(g);+ put(el, prism(P, front, ring, inner, 0, h));+ const c = { i, j, h, el };+ cols.push(c);+ byCell.set(i + "," + j, c);+ }++ // 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.+ const cloud = mk("g", {}, svg);+ const base = solid(cloud), puffs = PUFFS.map(() => solid(cloud));++ const sx = spring(REST[0]), sy = spring(REST[1]), sr = spring(value);+ let lit = null, drawn = "";++ /** The roof height at a ground point, or 0 in a street. */+ function roofAt(x, y) {+ const i = Math.floor(x / CELL), j = Math.floor(y / CELL), c = byCell.get(i + "," + j);+ if (!c) return 0;+ const u = x - i * CELL, v = y - j * CELL;+ return u >= IN && u <= CELL - IN && v >= IN && v <= CELL - IN ? c.h : 0;+ }+ /** The tower a drop at (x, y) is painted just after: the one behind it, or the plinth. */+ function behind(x, y) {+ const i = Math.floor((x - IN) / CELL), j = Math.floor((y - IN) / CELL);+ const c = byCell.get(clamp(i, 0, N - 1) + "," + clamp(j, 0, N - 1));+ return i < 0 || j < 0 ? plinth : c;+ }++ /** A rounded footprint sampled finely enough that the cloud'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));+ }++ 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);+ 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); }+ });+ }++ /** The bright tower is the one under the cloud's target, never under where it is drawn. */+ function light() {+ const i = clamp(Math.floor(sx.t / CELL), 0, N - 1), j = clamp(Math.floor(sy.t / CELL), 0, N - 1);+ const c = byCell.get(i + "," + j);+ if (c !== lit) {+ if (lit) lit.el.sil.classList.remove("hi");+ lit = c;+ lit.el.sil.classList.add("hi");+ }+ return [i, j];+ }++ const B = register(stage, (dt) => {+ const m = [stepS(sx, dt), stepS(sy, dt), stepS(sr, dt)].some(Boolean);+ draw();+ return m;+ });+ bag.add(B.unregister);+ aim(null);++ function aim(p) {+ if (p) {+ const w = unproj(C, p[0], p[1], ZC);+ sx.t = clamp(w[0], LO, HI);+ sy.t = clamp(w[1], LO, HI);+ const [i, j] = light();+ read.textContent = `block ${i}·${j}`;+ } else {+ [sx.t, sy.t] = REST;+ light();+ read.textContent = "rest";+ }+ B.wake();+ }++ bag.add(pointer(stage, { move: (p) => aim(p), leave: () => aim(null) }));+ bag.add(() => svg.replaceChildren());++ return {+ set: (v) => { sr.t = v; B.wake(); },+ destroy: bag.dispose,+ };+}++hairline({+ name: "storm",+ means: "A cloud you steer over a district rains on the roofs under it; only the rain from its middle reaches them.",+ rules: [1, 3, 5, 6],+ range: [14, 19, 24],+ mount,+});+</script>+</body>+</html>diff --git a/apps/site/test/skill.test.ts b/apps/site/test/skill.test.tsnew file mode 100644index 0000000..85c9990--- /dev/null+++ b/apps/site/test/skill.test.ts@@ -0,0 +1,53 @@+import { spawnSync } from "node:child_process";+import { readdirSync, readFileSync } from "node:fs";+import { fileURLToPath } from "node:url";+import { describe, expect, it } from "vitest";+import { COMMAND, EXAMPLES, INSTALL, declared, examples } from "@/lib/skill";++/** The showcase is the skill's own output: these fail if an example was edited, renamed, dropped, or left behind by the kernel. */++const PUBLIC = fileURLToPath(new URL("../public/skill/", import.meta.url));+const VALIDATE = fileURLToPath(new URL("../../../skills/hairline-create/validate.mjs", import.meta.url));++describe("the skill's examples", () => {+ it("are the four ideas, in page order", () => {+ expect(EXAMPLES.map((e) => e.idea)).toEqual(["a sales funnel", "a rate limiter", "git branches", "weather over a city"]);+ });++ it("are exactly the files in public/skill", () => {+ expect(EXAMPLES.map((e) => e.file).sort()).toEqual(readdirSync(PUBLIC).sort());+ });++ it.each(EXAMPLES)("$file passes the skill's validator untouched", ({ file }) => {+ const run = spawnSync(process.execPath, [VALIDATE, PUBLIC + file], { encoding: "utf8" });+ expect(run.stderr).toBe("");+ expect(run.status).toBe(0);+ });++ it("each carry the name their file is called by, a meaning, the prompt and the link", () => {+ for (const e of examples()) {+ expect(e.file).toBe(`hairline-${e.name}.html`);+ expect(e.means.length).toBeGreaterThan(0);+ expect(e.means.length).toBeLessThanOrEqual(140);+ expect(e.prompt).toBe(`${COMMAND} ${e.idea}`);+ expect(e.href).toBe(`/skill/${e.file}`);+ }+ });++ 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.' });+ });++ it("refuse a page with no figure in it, naming the file", () => {+ expect(() => declared("<html></html>", "hairline-gone.html")).toThrow(/hairline-gone\.html/);+ });+});++describe("the skill's commands", () => {+ it("are the ones the skill is installed and called by", () => {+ expect(INSTALL).toBe("npx skills add lucasmarkes/hairline");+ expect(COMMAND).toBe("/hairline-create");+ expect(readFileSync(fileURLToPath(new URL("../../../skills/hairline-create/SKILL.md", import.meta.url)), "utf8")).toContain("name: hairline-create");+ });+});