Isometric line figures that answer the pointer. For React and for anything with a DOM.
Skill: the kernel, src/core as one script with a single global, generated and held current by a test
Lucas Marquesef9b578fc6be
diff --git a/package.json b/package.jsonindex b240517..a1fca50 100644--- a/package.json+++ b/package.json@@ -14,10 +14,12 @@"test": "turbo run test","test:browser": "turbo run test:browser","clean": "turbo run clean",- "release": "node scripts/release.mjs"+ "release": "node scripts/release.mjs",+ "kernel": "node scripts/kernel.mjs"},"devDependencies": {"ajv": "8.20.0",+ "esbuild": "0.28.2","turbo": "^2.10.5","typescript": "5.9.3"},diff --git a/packages/hairline/test/skill/kernel.test.ts b/packages/hairline/test/skill/kernel.test.tsnew file mode 100644index 0000000..64b06e9--- /dev/null+++ b/packages/hairline/test/skill/kernel.test.ts@@ -0,0 +1,38 @@+import { spawnSync } from "node:child_process";+import { createHash } from "node:crypto";+import { readFileSync } from "node:fs";+import { fileURLToPath } from "node:url";+import { expect, it } from "vitest";++/** The skill's kernel: generated from src/core, committed, and held current here. */+const ROOT = fileURLToPath(new URL("../../../../", import.meta.url));+const text = () => readFileSync(ROOT + "skills/hairline-create/kernel.js", "utf8");++it("the committed kernel is what src/core gives now", () => {+ const run = spawnSync("node", ["scripts/kernel.mjs", "--check"], { cwd: ROOT, encoding: "utf8" });+ expect(run.stderr).toBe("");+ expect(run.status).toBe(0);+});++it("its first line carries the hash of everything after it", () => {+ const src = text(), cut = src.indexOf("\n");+ const hash = /^\/\* hairline kernel sha256:([0-9a-f]{64}) \*\/$/.exec(src.slice(0, cut))?.[1];+ expect(hash).toBe(createHash("sha256").update(src.slice(cut + 1)).digest("hex"));+ expect(src.endsWith("/* /hairline kernel */\n")).toBe(true);+});++it("defines one global, HL, holding what its index lists and nothing else", () => {+ const src = text();+ const HL = new Function(`${src}\nreturn HL;`)() as Record<string, unknown>;+ const indexed = [...src.slice(0, src.indexOf("var HL")).matchAll(/^ \* {3}(\w+)/gm)].map((m) => m[1]);+ expect(indexed.slice().sort()).toEqual(Object.keys(HL).sort());+ expect(Object.keys(HL)).toHaveLength(44);+ expect(typeof HL.register).toBe("function");+ expect(typeof HL.EASE_LIFT).toBe("function");+});++it("can sit inside a script element, and is left readable", () => {+ const src = text();+ expect(src).not.toMatch(/<\/script/i);+ expect(src.split("\n").length).toBeGreaterThan(300);+});diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 46de6c2..32b04eb 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -11,6 +11,9 @@ importers:ajv:specifier: 8.20.0version: 8.20.0+ esbuild:+ specifier: 0.28.2+ version: 0.28.2turbo:specifier: ^2.10.5version: 2.11.6diff --git a/scripts/kernel.mjs b/scripts/kernel.mjsnew file mode 100644index 0000000..9f73e0a--- /dev/null+++ b/scripts/kernel.mjs@@ -0,0 +1,129 @@+/**+ * The skill's kernel: packages/hairline/src/core as one plain script that+ * defines a single global, HL. `node scripts/kernel.mjs` writes+ * skills/hairline-create/kernel.js; with `--check` it writes nothing and exits+ * 1 when the committed file is not what the source gives now.+ *+ * The output is not minified: an agent reads the index at its top, and a+ * person can read the rest. Its first line carries the hash of everything+ * after it, which is how the skill's validator knows a kernel was not edited.+ */+import { build } from "esbuild";+import { createHash } from "node:crypto";+import { readFileSync, writeFileSync } from "node:fs";+import { join } from "node:path";+import { fileURLToPath } from "node:url";++const ROOT = fileURLToPath(new URL("..", import.meta.url));+const OUT = join(ROOT, "skills/hairline-create/kernel.js");+const FILES = ["iso", "motion", "stage", "styles"];++/* One name per line, three spaces in: test/skill/kernel.test.ts holds this list to HL's keys. */+const INDEX = `/*+ * 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.+ *+ * 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+ * 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+ * 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+ * 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, as its own subpath+ * 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+ * tset(tw, to, now, delay) retargets from where it is, after delay ms: the stagger+ * 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 paths into solid()'s elements+ * 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+ */`;++/** The kernel's text, from the source as it is now. */+export async function kernel() {+ const result = await build({+ stdin: {+ contents: FILES.map((f) => `export * from "./${f}";`).join("\n"),+ resolveDir: join(ROOT, "packages/hairline/src/core"),+ sourcefile: "kernel.ts",+ loader: "ts",+ },+ // esbuild names each source file in a comment, relative to this: the same on every machine+ absWorkingDir: ROOT,+ bundle: true,+ format: "iife",+ globalName: "HL",+ target: "es2020",+ charset: "utf8",+ legalComments: "none",+ write: false,+ });+ const body = `${INDEX}\n${result.outputFiles[0].text.trimEnd()}\n/* /hairline kernel */\n`;+ return `/* hairline kernel sha256:${createHash("sha256").update(body).digest("hex")} */\n${body}`;+}++if (process.argv[1] === fileURLToPath(import.meta.url)) {+ const text = await kernel();+ if (process.argv.includes("--check")) {+ let have = "";+ try { have = readFileSync(OUT, "utf8"); } catch { /* not generated yet: stale */ }+ if (have !== text) {+ console.error("skills/hairline-create/kernel.js is stale: run `pnpm kernel` and commit the result.");+ process.exit(1);+ }+ console.log("kernel is current");+ } else {+ writeFileSync(OUT, text);+ console.log(`wrote skills/hairline-create/kernel.js: ${text.split("\n").length} lines, ${Buffer.byteLength(text)} bytes`);+ }+}diff --git a/skills/hairline-create/kernel.js b/skills/hairline-create/kernel.jsnew file mode 100644index 0000000..b50abeb--- /dev/null+++ b/skills/hairline-create/kernel.js@@ -0,0 +1,560 @@+/* hairline kernel sha256:8009504ebe24d93229ddab8b890d826807aa5d147c43237a11828cc5600417ea */+/*+ * 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.+ *+ * 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+ * 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+ * 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+ * 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, as its own subpath+ * 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+ * tset(tw, to, now, delay) retargets from where it is, after delay ms: the stagger+ * 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 paths into solid()'s elements+ * 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 */diff --git a/turbo.json b/turbo.jsonindex 3858ef2..05bf1bb 100644--- a/turbo.json+++ b/turbo.json@@ -11,7 +11,8 @@"dependsOn": ["^build"]},"test": {- "dependsOn": ["^build"]+ "dependsOn": ["^build"],+ "inputs": ["$TURBO_DEFAULT$", "$TURBO_ROOT$/skills/**", "$TURBO_ROOT$/scripts/kernel.mjs"]},"test:browser": {"dependsOn": ["build"],