Skip to content

Isometric line figures that answer the pointer. For React and for anything with a DOM.

Figures: eight empty states, from a loupe over a blank sheet to a chart with nothing to plot

Lucas Marques2f4fd11958e1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 287f638..48f8dcd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,35 @@ Every release of `@lucasmarkes/hairline`. The format follows
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow
[semver](https://semver.org/).
+## 0.3.0 - 2026-10-05
+
+### Added
+
+- `loupe` and `Loupe`: a stand loupe over a blank ruled sheet. The pointer
+ drags it across, and the rules pass enlarged under the glass with nothing
+ between them. A stronger `intensity` magnifies more.
+- `sieve` and `Sieve`: three test sieves stacked over a pan. The pointer's
+ height picks one, it rises clear of the stack, and every mesh is bare. A
+ stronger `intensity` opens the gap further.
+- `rail` and `Rail`: a garment rail with seven bare hangers. The pointer
+ brushes them, and each rocks away from it, the nearest most. A stronger
+ `intensity` reaches more hangers.
+- `plug` and `Plug`: a wall socket and a plug lying on the floor at the end of
+ its cord. The pointer draws the plug up toward the socket; it stops short and
+ falls back. A stronger `intensity` brings it closer.
+- `query` and `Query`: a question mark built as a bent bar over a loose ball.
+ The hook turns toward the pointer and the ball rolls after it. A stronger
+ `intensity` turns it further.
+- `drawer` and `Drawer`: a cabinet of three drawers. The pointer's height
+ picks one, and it slides out to show two dividers with nothing between them.
+ A stronger `intensity` opens it further.
+- `basket` and `Basket`: a wire basket under a bail handle. It tilts toward
+ the pointer and shows its bare floor. A stronger `intensity` tilts it
+ further.
+- `plot` and `Plot`: a bar chart with seven flat tabs where the bars would
+ stand. The pointer brushes them, and each lifts a little and drops back to
+ zero. A stronger `intensity` lifts them higher.
+
## 0.2.0 - 2026-10-03
### Added
diff --git a/README.md b/README.md
index f371b26..cfe6459 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# hairline
-Nineteen isometric line figures that answer the pointer. For React and for anything with a DOM.
+Twenty-seven isometric line figures that answer the pointer. For React and for anything with a DOM.
[![npm](https://img.shields.io/npm/v/@lucasmarkes/hairline)](https://www.npmjs.com/package/@lucasmarkes/hairline)
[![CI](https://github.com/lucasmarkes/hairline/actions/workflows/ci.yml/badge.svg)](https://github.com/lucasmarkes/hairline/actions/workflows/ci.yml)
@@ -74,6 +74,14 @@ A figure draws into the element you give it, at the element's width and a 5:4 as
| `patch` | `Patch` | A patch panel of twenty-four ports with cables. The cable under the pointer lifts and its neighbours lean away. | The lean spreads further. |
| `dish` | `Dish` | A parabolic dish on a two-axis gimbal. The pointer aims the dish; it follows on a spring. | The dish swings further. |
| `router` | `Router` | A router with its antennas up. Each antenna leans toward the pointer, the nearest most. | The lean spreads further. |
+| `loupe` | `Loupe` | A stand loupe on a blank ruled sheet. The pointer drags it across; the rules pass enlarged under the glass, with nothing between them. | The glass magnifies more. |
+| `sieve` | `Sieve` | Three test sieves stacked over a pan. The pointer's height picks one; it rises clear of the stack, and every mesh is bare. | The gap opens further. |
+| `rail` | `Rail` | A garment rail with seven bare hangers. The pointer brushes them; each rocks away, the nearest most, and settles. | The brush reaches more hangers. |
+| `plug` | `Plug` | A wall socket, and a plug lying on the floor at the end of its cord. The pointer draws the plug up toward the socket; it stops short, and falls back. | The plug comes closer to the socket. |
+| `query` | `Query` | A question mark built as a bent bar over a loose ball. The hook turns toward the pointer, and the ball rolls after it. | The hook turns further. |
+| `drawer` | `Drawer` | A cabinet of three drawers. The pointer's height picks one; it slides out and shows two dividers with nothing between them. | The drawer opens further. |
+| `basket` | `Basket` | A wire basket under a bail handle. It tilts toward the pointer and shows its bare floor; the handle swings after it. | The basket tilts further. |
+| `plot` | `Plot` | A bar chart with seven flat tabs where the bars would stand. The pointer brushes them; each lifts a little and drops back to zero. | The tabs lift higher. |
## Options
@@ -117,7 +125,7 @@ The figure's styles have no specificity, so any rule of yours wins without `!imp
## Make your own
-`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 nineteen above, as one HTML file.
+`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 twenty-seven above, as one HTML file.
```sh
npx skills add lucasmarkes/hairline
diff --git a/fixtures/vite-vanilla/index.html b/fixtures/vite-vanilla/index.html
index 59afff4..4500a26 100644
--- a/fixtures/vite-vanilla/index.html
+++ b/fixtures/vite-vanilla/index.html
@@ -30,6 +30,14 @@
<div id="patch"></div>
<div id="dish"></div>
<div id="router"></div>
+ <div id="loupe"></div>
+ <div id="sieve"></div>
+ <div id="rail"></div>
+ <div id="plug"></div>
+ <div id="query"></div>
+ <div id="drawer"></div>
+ <div id="basket"></div>
+ <div id="plot"></div>
</main>
<output id="read"></output>
<script type="module" src="/src/main.ts"></script>
diff --git a/fixtures/vite-vanilla/src/main.ts b/fixtures/vite-vanilla/src/main.ts
index fedad49..6399e05 100644
--- a/fixtures/vite-vanilla/src/main.ts
+++ b/fixtures/vite-vanilla/src/main.ts
@@ -1,6 +1,6 @@
-import { branches, cabinet, dish, elevator, exploded, keyboard, laptop, lockers, padlock, patch, phone, phosphor, riffle, router, slow, terminal, terrain, turntable, vault, type Figure } from "@lucasmarkes/hairline";
+import { basket, branches, cabinet, dish, drawer, elevator, exploded, keyboard, laptop, lockers, loupe, padlock, patch, phone, phosphor, plot, plug, query, rail, riffle, router, sieve, slow, terminal, terrain, turntable, vault, type Figure } from "@lucasmarkes/hairline";
-/** No framework: nineteen elements, nineteen calls. */
+/** No framework: twenty-seven elements, twenty-seven calls. */
const el = (id: string) => document.getElementById(id)!;
const read = el("read");
@@ -26,5 +26,13 @@ padlock(el("padlock"));
patch(el("patch"));
dish(el("dish"));
router(el("router"));
+loupe(el("loupe"));
+sieve(el("sieve"));
+rail(el("rail"));
+plug(el("plug"));
+query(el("query"));
+drawer(el("drawer"));
+basket(el("basket"));
+plot(el("plot"));
cards.update({ intensity: 0.8 });
diff --git a/package.json b/package.json
index 3389c1a..9402cd4 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "hairline-monorepo",
"version": "0.0.0",
"private": true,
- "description": "Nineteen isometric line figures that answer the pointer",
+ "description": "Twenty-seven isometric line figures that answer the pointer",
"packageManager": "[email protected]",
"engines": {
"node": ">=22"
diff --git a/packages/hairline/package.json b/packages/hairline/package.json
index 1ea6924..aa0f90e 100644
--- a/packages/hairline/package.json
+++ b/packages/hairline/package.json
@@ -1,7 +1,7 @@
{
"name": "@lucasmarkes/hairline",
- "version": "0.2.0",
- "description": "Nineteen isometric line figures that answer the pointer. For React and for anything with a DOM.",
+ "version": "0.3.0",
+ "description": "Twenty-seven isometric line figures that answer the pointer. For React and for anything with a DOM.",
"license": "MIT",
"type": "module",
"sideEffects": false,
@@ -83,18 +83,18 @@
{
"name": "vanilla, every figure",
"path": "dist/index.js",
- "limit": "27.6 kB"
+ "limit": "34.4 kB"
},
{
"name": "vanilla, one figure",
"path": "dist/index.js",
"import": "{ terrain }",
- "limit": "5.6 kB"
+ "limit": "5.7 kB"
},
{
"name": "react, every component",
"path": "dist/react.js",
- "limit": "28.1 kB",
+ "limit": "34.9 kB",
"ignore": [
"react",
"react/jsx-runtime"
diff --git a/packages/hairline/src/figures/basket.ts b/packages/hairline/src/figures/basket.ts
new file mode 100644
index 0000000..feb2f4e
--- /dev/null
+++ b/packages/hairline/src/figures/basket.ts
@@ -0,0 +1,166 @@
+import { Cam, clamp, fit, hull, open, poly, proj, rad, rrect, run, seg, unproj, type Ring, type Sample, type Vec2, type Vec3 } from "../core/iso";
+import { spring, stepS } from "../core/motion";
+import { disposer, mk, pointer, put, register, solid, type FigureMount } from "../core/stage";
+import { TABLE } from "../intensity";
+
+/**
+ * Basket: a wire shopping basket. A rim and a floor, both solid, dim wires
+ * standing between them, and a bail handle with a grip. The pointer tilts the
+ * basket toward it on a spring, so the bare floor shows, and the handle
+ * swings after it, late. At rest the basket stands level, the handle dropped
+ * to one side, the rim bright; tilted, the bright goes to the floor. The
+ * slider is the furthest tilt, in degrees.
+ *
+ * The pattern: a lean. Two springs hold the tilt as a vector on the ground,
+ * set from the pointer on a fixed plane through the basket's middle, never
+ * from the basket on screen. Everything turns about the floor's centre.
+ * Tipped away from the camera it goes half as far, so the floor still shows.
+ * The handle swings on a softer spring, as Rail's hangers, whose target is
+ * read from the tilt as drawn: it comes late.
+ */
+
+const A = 40, B = 25, RR = 8, RT = 1.5, H = 30, F = 0.8; // rim: half length, half width, corner radius, wire radius, height; the floor's size as a share of the rim's
+const FT = 3, FB = 1.4, N = 44, BANDS = [0.45]; // floor: thickness, crease inset; wires round the wall; horizontal wires, as shares of the height
+const HH = 30, HR = 8, HT = 1.3, GRIP = 9, GT = 2.6; // handle: height over its pivots, corner radius, bar radius, grip half length, grip radius
+const REST_H = -46, LIFT = 0.6, REACH = 70, S = 3; // the handle's lean at rest, in degrees, and how far a degree of tilt lifts it; the pointer's distance for the full tilt; scale
+type Rot = (x: number, y: number, z: number) => Vec3;
+
+/** The tilt toward a ground direction by m degrees. Tipping away from the camera goes half as far, so the mouth stays open to it. */
+function aim(dx: number, dy: number, m: number): Vec2 {
+ const a = Math.min(0, (dx + dy) * Math.SQRT1_2) / 2; // half the part of the direction that points away from the camera, which is at 45°
+ return [m * (dx - a * Math.SQRT1_2), m * (dy - a * Math.SQRT1_2)];
+}
+
+/** The tilt as a rotation about the floor's centre: the mouth turns toward (tx, ty) by their length, in degrees. */
+function tilter(tx: number, ty: number): Rot {
+ const m = Math.hypot(tx, ty), kx = m ? -ty / m : 0, ky = m ? tx / m : 0, c = Math.cos(rad(m)), s = Math.sin(rad(m));
+ return (x, y, z) => { const d = (kx * x + ky * y) * (1 - c); return [x * c + ky * z * s + kx * d, y * c - kx * z * s + ky * d, z * c + (kx * y - ky * x) * s]; };
+}
+
+/** n samples evenly spaced by length round a closed ring. */
+function stations(ring: Ring, n: number): Ring {
+ const L = [0];
+ for (let i = 1; i <= ring.length; i++) { const p = ring[i - 1], q = ring[i % ring.length]; L.push(L[i - 1] + Math.hypot(q.u - p.u, q.v - p.v)); }
+ return Array.from({ length: n }, (_, k) => {
+ const s = (k / n) * L[ring.length];
+ let i = 0;
+ while (L[i + 1] < s) i++;
+ const p = ring[i], q = ring[(i + 1) % ring.length], f = (s - L[i]) / (L[i + 1] - L[i] || 1);
+ return { u: p.u + (q.u - p.u) * f, v: p.v + (q.v - p.v) * f, nu: p.nu, nv: p.nv };
+ });
+}
+
+/** A round bar's outline on screen: its centre line offset by its radius. Closed, it is a ring with a hole; open, its ends are round. */
+function tube(Q: readonly Vec2[], rho: number, closed = false): string {
+ const n = Q.length, L: Vec2[] = [], R: Vec2[] = [], T: Vec2[] = [];
+ for (let i = 0; i < n; i++) {
+ const a = Q[closed ? (i + n - 1) % n : Math.max(i - 1, 0)], b = Q[closed ? (i + 1) % n : Math.min(i + 1, n - 1)];
+ const l = Math.hypot(b[0] - a[0], b[1] - a[1]) || 1, tx = (b[0] - a[0]) / l, ty = (b[1] - a[1]) / l;
+ T.push([tx, ty]); L.push([Q[i][0] - ty * rho, Q[i][1] + tx * rho]); R.push([Q[i][0] + ty * rho, Q[i][1] - tx * rho]);
+ }
+ if (closed) return poly(L) + poly(R.reverse());
+ /** Half a round about c, from the left side to the right, bulging along d. */
+ const cap = (c: Vec2, t: Vec2, d: number) => Array.from({ length: 7 }, (_, k): Vec2 => {
+ const th = (Math.PI * (k + 1)) / 8, co = Math.cos(th) * d, si = Math.sin(th) * d;
+ return [c[0] + rho * (-t[1] * co + t[0] * si), c[1] + rho * (t[0] * co + t[1] * si)];
+ });
+ return poly([...L, ...cap(Q[n - 1], T[n - 1], 1), ...R.reverse(), ...cap(Q[0], T[0], -1)]);
+}
+
+/** The handle's centre line in its own plane: u across the basket, w up from the pivots. */
+const ARM: Vec2[] = /* @__PURE__ */ (() => [[-B, 0], ...Array.from({ length: 9 }, (_, k): Vec2 => { const t = Math.PI - (Math.PI / 2) * (k / 8); return [-B + HR + HR * Math.cos(t), HH - HR + HR * Math.sin(t)]; }),
+ ...Array.from({ length: 9 }, (_, k): Vec2 => { const t = (Math.PI / 2) * (1 - k / 8); return [B - HR + HR * Math.cos(t), HH - HR + HR * Math.sin(t)]; }), [B, 0]])();
+const GRIPS: Vec2[] = [[-GRIP, HH], [GRIP, HH]];
+
+/** A point of the handle's plane, swung phi degrees toward +x about the pivots, in the basket's own frame. */
+const swing = (phi: number) => { const c = Math.cos(rad(phi)), s = Math.sin(rad(phi)); return (p: Vec2): Vec3 => [p[1] * s, p[0], H + p[1] * c]; };
+
+export const mount: FigureMount = ({ stage, svg, read }, value) => {
+ const bag = disposer();
+ const C = Cam(45, 0.5, S);
+ const MAXT = TABLE.basket[2]; // the slider's far end: under the camera's 30°, so it still sees into the mouth
+ const HMAX = REST_H + LIFT * MAXT; // the handle's most upright: where the furthest tilt lifts it
+ const rim = rrect(-A, -B, A, B, RR, 14), wires = stations(rim, N);
+ const floor = rim.map((q): Sample => ({ ...q, u: q.u * F, v: q.v * F }));
+ const lid = rrect(-A * F + FB, -B * F + FB, A * F - FB, B * F - FB, RR * F - FB, 14);
+
+ // The frame holds every pose: the furthest tilt every way, with the handle at both ends of its swing.
+ const ext: Vec3[] = [];
+ for (let k = -1; k < 8; k++) {
+ const R = tilter(...aim(Math.cos((k * Math.PI) / 4), Math.sin((k * Math.PI) / 4), k < 0 ? 0 : MAXT));
+ for (const q of rim) ext.push(R(q.u, q.v, H + RT), R(q.u * F, q.v * F, 0));
+ for (const phi of [REST_H, HMAX]) for (const p of ARM) ext.push(R(...swing(phi)(p)));
+ }
+ fit(C, ext, 200, 166);
+ const P0 = proj(C), sw = Math.sqrt(1 - C.k * C.k), cam: Vec3 = [Math.sin(C.az) * sw, Math.cos(C.az) * sw, C.k];
+ const g = mk("g", {}, svg);
+
+ // Back to front: the far wall's wires, the floor, the near wall's wires, the rim, the handle and its grip.
+ const far = mk("path", { class: "nf lo" }, g);
+ const base = solid(g);
+ const near = mk("path", { class: "nf lo" }, g);
+ const ring = mk("path", { class: "sil" }, g);
+ const bar = mk("path", { class: "sil" }, g);
+ const grip = mk("path", { class: "sil" }, g);
+
+ const tx = spring(0), ty = spring(0), hp = spring(REST_H, { k: 60, c: 6, eps: 0.02 });
+ let dX = NaN, dY = NaN, dH = NaN, R = tilter(0, 0);
+ const at = (p: Vec3) => P0(...R(...p));
+ /** Whether a wall with this outward normal faces the camera, once tilted. */
+ const facing = (q: Sample) => { const n = R(q.nu, q.nv, 0); return n[0] * cam[0] + n[1] * cam[1] + n[2] * cam[2] >= 0; };
+
+ function draw() {
+ const moved = tx.x !== dX || ty.x !== dY;
+ if (moved) {
+ dX = tx.x; dY = ty.x; R = tilter(dX, dY);
+ put(base, {
+ sil: poly(hull(floor.map((q) => at([q.u, q.v, 0])).concat(floor.map((q) => at([q.u, q.v, FT]))))),
+ crease: open(run(lid, facing).map((q) => at([q.u, q.v, FT]))),
+ });
+ // the wires: up the wall from the floor's edge to the rim, and round it at each band's height
+ const d = ["", ""];
+ for (const q of wires) d[+facing(q)] += seg(at([q.u * F - q.nu, q.v * F - q.nv, FT]), at([q.u, q.v, H])); // a foot just inside the floor's edge, off its outline
+ for (const b of BANDS) {
+ const z = FT + (H - FT) * b, k = F + (1 - F) * b;
+ rim.forEach((q, i) => { const r = rim[(i + 1) % rim.length]; d[+facing(q)] += seg(at([q.u * k, q.v * k, z]), at([r.u * k, r.v * k, z])); });
+ }
+ far.setAttribute("d", d[0]); near.setAttribute("d", d[1]);
+ ring.setAttribute("d", tube(rim.map((q) => at([q.u, q.v, H])), RT * S, true));
+ }
+ if (moved || hp.x !== dH) {
+ dH = hp.x;
+ const s = swing(dH);
+ bar.setAttribute("d", tube(ARM.map((p) => at(s(p))), HT * S));
+ grip.setAttribute("d", tube(GRIPS.map((p) => at(s(p))), GT * S));
+ }
+ }
+
+ const loop = register(stage, (dt) => {
+ const a = stepS(tx, dt), b = stepS(ty, dt);
+ hp.t = Math.min(REST_H + LIFT * Math.hypot(tx.x, ty.x), HMAX); // any tilt lifts it off the rim; it chases the tilt as drawn, so it comes late
+ const c = stepS(hp, dt);
+ draw();
+ return a || b || c;
+ });
+ bag.add(loop.unregister);
+
+ let tmax = value, over = false, gx = 0, gy = 0;
+ function retarget() {
+ const r = Math.hypot(gx, gy), m = over && r ? clamp(tmax, 0, MAXT) * clamp(r / REACH, 0, 1) : 0;
+ [tx.t, ty.t] = m ? aim(gx / r, gy / r, m) : [0, 0];
+ read.textContent = over ? `tilt ${Math.round(Math.hypot(tx.t, ty.t))}° · 0` : "rest";
+ ring.classList.toggle("hi", !over);
+ base.sil.classList.toggle("hi", over);
+ loop.wake();
+ }
+ retarget();
+
+ bag.add(pointer(stage, {
+ // the pointer on a plane through the basket's middle, which never moves
+ move: (p) => { over = true; [gx, gy] = unproj(C, p[0], p[1], H / 2); retarget(); },
+ leave: () => { over = false; retarget(); },
+ }));
+ bag.add(() => svg.replaceChildren());
+
+ return { set: (v) => { tmax = v; retarget(); }, destroy: bag.dispose };
+};
diff --git a/packages/hairline/src/figures/drawer.ts b/packages/hairline/src/figures/drawer.ts
new file mode 100644
index 0000000..0275b95
--- /dev/null
+++ b/packages/hairline/src/figures/drawer.ts
@@ -0,0 +1,133 @@
+import { Cam, facing, fit, hull, open, poly, prism, proj, rings, rrect, run, type Projector, type Ring, type Sample, type Vec2, type Vec3 } from "../core/iso";
+import { tdone, tset, tval, tween } from "../core/motion";
+import { disposer, mk, pointer, put, register, solid, type FigureMount, type Solid } from "../core/stage";
+import { TABLE } from "../intensity";
+
+/**
+ * Drawer: a filing cabinet of three deep drawers on a plinth, each front with
+ * a bar pull. The pointer's height picks a drawer; it slides out on its
+ * runners and shows its inside, two dim dividers running back and nothing
+ * between them. The others close. At rest the middle drawer stands a quarter
+ * out, its front bright. The slider is how far a drawer comes out.
+ *
+ * The pattern: one of many, as Sieve's. A tween per drawer on how far it is
+ * out. The pick puts the pointer on each front's plane where it stands at
+ * rest, which moves only with the slider, never with the drawer on screen.
+ * Only a drawer whose tween moved is drawn again.
+ */
+
+const N = 3, W = 54, D = 60, Z0 = 5, M = 3, PITCH = 26, G = 1.6, FT = 2.4; // drawers, carcass width and depth, plinth, margin round the fronts, a drawer's pitch, the gap between fronts, a front's thickness
+const T = 1.3, IN = 3.2, LOW = 2.2, HIGH = 3.6, DIV = 2.6, S = 2.1; // a wall's thickness, the box's inset from its front's sides, below its front's foot and its top, how far the dividers sit under the walls, scale
+const ZB = Z0 + M, H = ZB + N * PITCH + M, REST = 0.7; // the lowest front's foot, the carcass's top, the rest pull as a share of the slider's
+
+/** On a front's face, the samples whose edge meets its top or its right side: they lie inside the silhouette. */
+const inner = (q: Sample) => 0.375 * q.nu + 0.307 * q.nv > 0;
+
+/** A plate standing in the x-z plane, from y0 back to y1 front: its silhouette, and the crease of its front face. */
+function slab(P: Projector, ring: Ring, inset: Ring, y0: number, y1: number) {
+ const at = (r: Ring, y: number) => r.map((q): Vec2 => P(q.u, y, q.v));
+ return { sil: poly(hull(at(ring, y0).concat(at(ring, y1)))), crease: open(at(run(inset, inner), y1)) };
+}
+
+type Drawer = { z0: number; z1: number; parts: SVGPathElement[]; front: Solid; pull: Solid; drawn: number };
+
+export const mount: FigureMount = ({ stage, svg, read }, value) => {
+ const bag = disposer();
+ const MAX = TABLE.drawer[2];
+ const C = Cam(45, 0.5, S);
+ // The carcass, and the top and bottom drawers out as far as the slider goes, each mirrored through the
+ // carcass's middle: the cabinet stands in the middle of the frame, and the farthest pull still fits.
+ const out = D + MAX + FT, ext: Vec3[] = [[0, 0, 0], [W, 0, 0], [0, 0, H], [W, 0, H], [W, D, 0], [0, out, ZB], [0, out, H - M], [W, out, ZB]];
+ fit(C, ext.concat(ext.map(([x, y, z]): Vec3 => [W - x, D - y, H - z])), 200, 166);
+ const P = proj(C), front = facing(C);
+ const g = mk("g", {}, svg);
+
+ // The plinth, set back under the carcass, then the carcass.
+ const [pr, pi] = rings(3, 3, W - 3, D - 3, 2.4, 1);
+ put(solid(g), prism(P, front, pr, pi, 0, Z0));
+ const [cr, ci] = rings(0, 0, W, D, 3, 1.4);
+ put(solid(g), prism(P, front, cr, ci, Z0, H));
+
+ const x0 = M + IN, x1 = W - M - IN, xs = [x0 + (x1 - x0) / 3, x0 + (2 * (x1 - x0)) / 3];
+ const onFace = (r: Ring, y: number) => poly(r.map((q): Vec2 => P(q.u, y, q.v)));
+ // Each drawer's opening on the carcass's face: hidden by its front, seen above its box when it is out.
+ mk("path", { class: "nf lo", d: Array.from({ length: N }, (_, k) => {
+ const z = ZB + k * PITCH + G / 2;
+ return onFace(rrect(x0 - 0.8, z + LOW - 0.8, x1 + 0.8, z + PITCH - G - HIGH + 1.4, 0.8, 2), D);
+ }).join("") }, g);
+
+ // Bottom to top: the camera looks down, so a lower drawer never covers a higher one.
+ // In a drawer, back to front: its floor, left wall, dividers, right wall, the box's outline, its front, its pull.
+ const drawers: Drawer[] = Array.from({ length: N }, (_, k) => {
+ const z0 = ZB + k * PITCH + G / 2, z1 = z0 + PITCH - G, dg = mk("g", {}, g);
+ const parts = [0, 1, 2, 3].map(() => mk("path", { class: "lo" }, dg));
+ parts.push(mk("path", { class: "nf sil" }, dg));
+ return { z0, z1, parts, front: solid(dg), pull: solid(dg), drawn: NaN };
+ });
+ const face = (d: Drawer) => rrect(M, d.z0, W - M, d.z1, 1.6, 4), faceIn = (d: Drawer) => rrect(M + 1, d.z0 + 1, W - M - 1, d.z1 - 1, 1, 4);
+
+ /** A box from y0 to y1 with a rounded footprint, standing from z0 to z1: its silhouette. */
+ const box = (a: number, b: number, y0: number, y1: number, z0: number, z1: number, r: number) =>
+ y1 - y0 < 0.05 ? "" : prism(P, front, rrect(a, y0, b, y1, r, 3), null, z0, z1).sil;
+
+ function draw(d: Drawer, o: number) {
+ if (o === d.drawn) return;
+ d.drawn = o;
+ const zb = d.z0 + LOW, zt = d.z1 - HIGH, yb = D + o, yf = yb + FT;
+ const [floor, left, divs, right, outline] = d.parts;
+ floor.setAttribute("d", box(x0, x1, D, yb, zb, zb + T, 0.6));
+ left.setAttribute("d", box(x0, x0 + T, D, yb, zb + T, zt, 0.5));
+ divs.setAttribute("d", xs.map((x) => box(x - 0.5, x + 0.5, D, yb, zb + T, zt - DIV, 0.4)).join(""));
+ right.setAttribute("d", box(x1 - T, x1, D, yb, zb + T, zt, 0.5));
+ outline.setAttribute("d", box(x0, x1, D, yb, zb, zt, 0.8));
+ put(d.front, slab(P, face(d), faceIn(d), yb, yf));
+ const zp = (d.z0 + d.z1) / 2, xm = W / 2;
+ const [br, bi] = rings(xm - 9, yf, xm + 9, yf + 2.6, 1.3, 0.6);
+ put(d.pull, prism(P, front, br, bi, zp - 1.3, zp + 1.3));
+ }
+
+ const tw = drawers.map(() => tween(0));
+ const B = register(stage, (_dt, now) => {
+ let m = false;
+ drawers.forEach((d, k) => { draw(d, tval(tw[k], now)); if (!tdone(tw[k], now)) m = true; });
+ return m;
+ });
+ bag.add(B.unregister);
+
+ let pull = value, picked = -2;
+ /** Opens drawer f, counted from the bottom, and closes the rest; -1 puts the cabinet back to rest. */
+ function choose(f: number, now: number) {
+ if (f === picked) return;
+ picked = f;
+ const a = f < 0 ? 1 : f;
+ tw.forEach((t, k) => tset(t, k === a ? (f < 0 ? pull * REST : pull) : 0, now, 0));
+ drawers.forEach((d, k) => d.front.sil.classList.toggle("hi", k === a));
+ read.textContent = f < 0 ? "rest" : `drawer ${N - f} · 0`;
+ B.wake();
+ }
+ tw[1] = tween(pull * REST);
+ choose(-1, -1e9);
+ drawers.forEach((d, k) => draw(d, tval(tw[k], 0)));
+
+ /** The world x and z under screen point p on the upright plane y = yf: the projection, inverted. */
+ const c = Math.cos(C.az), s = Math.sin(C.az), zf = Math.sqrt(1 - C.k * C.k);
+ const onFront = (p: Vec2, yf: number): Vec2 => { const x = (p[0] - C.ox) / (C.S * c) + (yf * s) / c; return [x, ((x * s + yf * c) * C.k - (p[1] - C.oy) / C.S) / zf]; };
+ /** The drawer under p: first on each front where it stands at rest, top down as a higher drawer covers a lower one;
+ * off every front, the nearest middle in z on the closed front. */
+ function pick(p: Vec2) {
+ for (let k = N - 1; k >= 0; k--) {
+ const [x, z] = onFront(p, D + FT + (k === 1 ? pull * REST : 0)), d = drawers[k];
+ if (x >= M && x <= W - M && z >= d.z0 && z <= d.z1) return k;
+ }
+ const z = onFront(p, D + FT)[1];
+ return drawers.reduce((best, d, k) => (Math.abs(z - (d.z0 + d.z1) / 2) < Math.abs(z - (drawers[best].z0 + drawers[best].z1) / 2) ? k : best), 0);
+ }
+
+ bag.add(pointer(stage, { move: (p) => choose(pick(p), performance.now()), leave: () => choose(-1, performance.now()) }));
+ bag.add(() => svg.replaceChildren());
+
+ return {
+ set: (v) => { pull = v; const f = picked; picked = -2; choose(f, performance.now()); },
+ destroy: bag.dispose,
+ };
+};
diff --git a/packages/hairline/src/figures/loupe.ts b/packages/hairline/src/figures/loupe.ts
new file mode 100644
index 0000000..bd6c133
--- /dev/null
+++ b/packages/hairline/src/figures/loupe.ts
@@ -0,0 +1,108 @@
+import { Cam, circ, clamp, facing, fit, hull, open, poly, prism, proj, rings, rrect, seg, unproj, type Vec2, type Vec3 } from "../core/iso";
+import { spring, stepS } from "../core/motion";
+import { disposer, mk, pointer, put, register, solid, type FigureMount } from "../core/stage";
+
+/**
+ * Loupe: a stand loupe on three legs over a ruled sheet with nothing written
+ * on it. The pointer drags the loupe across the sheet on a spring. Under the
+ * glass the rules are drawn again, larger, and there is nothing between them.
+ * At rest the glass straddles the margin where the rules start, so their ends
+ * land inside it well away from where the runs outside it would put them;
+ * its thin rim is the bright mark. The slider is the magnification.
+ *
+ * The pattern: follow a position. Two springs hold the point of the sheet the
+ * eye sees through the glass's centre, set from the pointer on the sheet's
+ * plane, which never moves; the loupe stands where its glass covers that
+ * point. The glass shows the sheet there enlarged, cut to the lens by
+ * arithmetic, not by a clip. Past the sheet's near edges the feet stand on
+ * the table, so the glass reaches every rule.
+ */
+
+const SW = 124, SD = 92, ST = 2.4; // the sheet: width, depth, thickness
+const ROWS = 7, Y0 = 13, DY = 11, ML = 26, MR = 12; // its rules: how many, the first one's y, their pitch, the left margin they start at, the right one
+const R = 27, LZ = 20, RIM = 1.2, GLASS = R - 1.4; // the loupe: ring radius, height of its underside, ring depth, glass radius
+const LEGS = [45, 165, 285], FOOT = 35, PAD = 1.8, REST: Vec2 = [ML + 9, 46], S = 2.1;
+
+export const mount: FigureMount = ({ stage, svg, read }, value) => {
+ const bag = disposer();
+ const C = Cam(45, 0.5, S), top = LZ + RIM;
+ const feet = LEGS.map((a): Vec2 => [Math.cos((a * Math.PI) / 180), Math.sin((a * Math.PI) / 180)]);
+ /** From the point the eye sees to the loupe's centre: the glass stands this far in front of it. */
+ const [bx, by] = unproj(C, ...proj(C)(0, 0, 0), top);
+ // The frame holds the rest pose; the reach still fits inside it (see the far and near corners).
+ const ext: Vec3[] = [[0, 0, -ST], [SW, 0, -ST], [0, SD, -ST], [SW, SD, -ST]];
+ for (const q of circ(R, 16)) ext.push([REST[0] + bx + q.u, REST[1] + by + q.v, top]);
+ fit(C, ext, 200, 166);
+ const P = proj(C), front = facing(C);
+ const g = mk("g", {}, svg);
+
+ // The sheet, then its rules lying on it.
+ const [so, si] = rings(0, 0, SW, SD, 6, 1.4);
+ put(solid(g), prism(P, front, so, si, -ST, 0));
+ const rowY = (i: number) => Y0 + i * DY;
+ /** The lines on the sheet: the margin, then the rules that start at it. */
+ const lines: Array<[Vec2, Vec2]> = [[[ML, Y0 - 7], [ML, rowY(ROWS - 1) + 7]], ...Array.from({ length: ROWS }, (_, i): [Vec2, Vec2] => [[ML, rowY(i)], [SW - MR, rowY(i)]])];
+ mk("path", { class: "nf lo", d: lines.map(([p, q]) => seg(P(p[0], p[1], 0), P(q[0], q[1], 0))).join("") }, g);
+
+ // The loupe: three legs, a thin ring round the glass, a glint on it, the sheet seen through it.
+ const legs = mk("path", { class: "nf" }, g);
+ const rim = solid(g);
+ const glint = mk("path", { class: "nf lo" }, g);
+ const seen = mk("path", { class: "nf sil" }, g);
+ const shine = circ(GLASS * 0.72, 64).slice(26, 36);
+ const ring = circ(R, 64), lens = circ(GLASS, 64), edge = rrect(0, 0, SW, SD, 6, 12), pad = circ(PAD, 12);
+ /** A foot on the sheet stands on its top; one past its edge, on the table under it. */
+ const floor = (x: number, y: number) => (x >= 0 && x <= SW && y >= 0 && y <= SD ? 0 : -ST);
+
+ const sx = spring(REST[0]), sy = spring(REST[1]), mag = spring(value);
+ let cx = NaN, cy = NaN, dm = NaN;
+ function draw() {
+ if (sx.x === cx && sy.x === cy && mag.x === dm) return;
+ const moved = sx.x !== cx || sy.x !== cy;
+ cx = sx.x; cy = sy.x; dm = mag.x;
+ const dx = cx + bx, dy = cy + by;
+ if (moved) {
+ const at = (q: { u: number; v: number }, z: number) => P(dx + q.u, dy + q.v, z);
+ legs.setAttribute("d", feet.map(([c, s]) => {
+ const fx = dx + c * FOOT, fy = dy + s * FOOT;
+ const z = floor(fx, fy);
+ return seg(P(fx, fy, z), P(dx + c * (R - 1), dy + s * (R - 1), LZ)) + poly(pad.map((q) => P(fx + q.u, fy + q.v, z)));
+ }).join(""));
+ put(rim, { sil: poly(hull(ring.map((q) => at(q, LZ)).concat(ring.map((q) => at(q, top))))), crease: poly(lens.map((q) => at(q, top))) });
+ glint.setAttribute("d", open(shine.map((q) => at(q, top))));
+ }
+ // A line on the sheet, enlarged about the point the eye sees through the
+ // glass's centre, and kept where it falls inside the glass.
+ const r = GLASS - 1;
+ const cut = (p: Vec2, q: Vec2) => {
+ const a0 = (p[0] - cx) * dm, a1 = (p[1] - cy) * dm, e0 = (q[0] - p[0]) * dm, e1 = (q[1] - p[1]) * dm;
+ const A = e0 * e0 + e1 * e1, B = a0 * e0 + a1 * e1, D = B * B - A * (a0 * a0 + a1 * a1 - r * r);
+ if (D <= 0) return "";
+ const t0 = Math.max(0, (-B - Math.sqrt(D)) / A), t1 = Math.min(1, (-B + Math.sqrt(D)) / A);
+ return t1 > t0 ? seg(P(dx + a0 + e0 * t0, dy + a1 + e1 * t0, top), P(dx + a0 + e0 * t1, dy + a1 + e1 * t1, top)) : "";
+ };
+ let d = edge.map((q, i) => cut([q.u, q.v], [edge[(i + 1) % edge.length].u, edge[(i + 1) % edge.length].v])).join("");
+ for (const [p, q] of lines) d += cut(p, q);
+ seen.setAttribute("d", d);
+ }
+
+ const loop = register(stage, (dt) => { const a = stepS(sx, dt), b = stepS(sy, dt), c = stepS(mag, dt); draw(); return a || b || c; });
+ bag.add(loop.unregister);
+ rim.sil.classList.add("hi");
+ read.textContent = "rest";
+ draw();
+
+ bag.add(pointer(stage, {
+ move: (p) => {
+ // the pointer on the sheet's plane, which never moves: the glass comes to cover the point under it
+ const [x, y] = unproj(C, p[0], p[1], 0);
+ sx.t = clamp(x, ML, SW - MR); sy.t = clamp(y, Y0, rowY(ROWS - 1));
+ read.textContent = `row ${Math.round((sy.t - Y0) / DY) + 1} · 0`;
+ loop.wake();
+ },
+ leave: () => { sx.t = REST[0]; sy.t = REST[1]; read.textContent = "rest"; loop.wake(); },
+ }));
+ bag.add(() => svg.replaceChildren());
+
+ return { set: (v) => { mag.t = v; loop.wake(); }, destroy: bag.dispose };
+};
diff --git a/packages/hairline/src/figures/plot.ts b/packages/hairline/src/figures/plot.ts
new file mode 100644
index 0000000..8cd293e
--- /dev/null
+++ b/packages/hairline/src/figures/plot.ts
@@ -0,0 +1,99 @@
+import { Cam, clamp, facing, fillet, fit, hull, open, poly, prism, proj, rings, seg } from "../core/iso";
+import { spring, stepS } from "../core/motion";
+import { disposer, mk, pointer, put, register, solid, type FigureMount } from "../core/stage";
+import { TABLE } from "../intensity";
+
+/**
+ * Plot: a bar chart standing up as an object, with no data in it. A base, a
+ * back plate with dim grid lines, and seven flat tabs lying on the base where
+ * the bars would stand. The pointer brushes the tabs: each lifts a little,
+ * the nearest most, and drops back to zero while the pointer is still there.
+ * At rest the tabs lie flat and one stands a hair proud, bright. The slider
+ * is how far the nearest tab lifts.
+ *
+ * The pattern: a field, as Rail's. One spring per tab on its height, always
+ * pulled back to zero; the brush is a kick of velocity, sized so the spring
+ * peaks at the lift, falling off with the distance, in tabs, from the one
+ * picked. The pick is the tab whose rest centre is nearest the pointer's
+ * screen x, and the tabs are kicked only when the pick changes, so a pointer
+ * held still leaves the chart flat.
+ */
+
+const N = 7, X0 = 13, DX = 10, TW = 5, TY0 = 6, TY1 = 11, TH = 1; // tabs: how many, the first one's centre, their pitch, width, far and near edge, thickness
+const L = 2 * X0 + (N - 1) * DX, D = 16, BZ = 3.6, PY = 2, PT = 2, HP = 34, GRID = 4, AX = 7, TICK = 4; // base: length, depth, thickness; plate: back face, thickness, height; grid lines, the axis's x, a tick's length
+const PROUD = 2.2, MARK = 4, S = 3.2;
+/**
+ * The tabs' spring is softer than the default, k 40 · c 11, so a kicked bar
+ * stays up long enough to be read against the grid: it peaks at 165ms and
+ * settles in 1s at the lowest lift to 1.4s at the highest, where the
+ * default's flinch peaks at 100ms. KICK is the velocity that makes this
+ * spring, stepped at 240 Hz, peak one unit above where it was kicked.
+ */
+const SPRING = { k: 40, c: 11, eps: 0.02 }, KICK = 16.4;
+/** The share of the lift a tab d tabs from the one picked takes: all of it there, a little for every tab. */
+const falloff = (d: number) => 1 / (1 + 0.5 * d * d);
+/** The plate's face in its own (x, z), from its bottom right corner round. `fillet` gives ARC + 1 points a corner, so EDGE is the run from the first corner's end to the third's: its right side and top. */
+const ARC = 5, FACE = /* @__PURE__ */ fillet([[L - 2, 0], [L - 2, HP], [2, HP], [2, 0]], [0.6, 4, 4, 0.6], ARC), EDGE = [ARC, 3 * (ARC + 1)] as const;
+
+export const mount: FigureMount = ({ stage, svg, read }, value) => {
+ const bag = disposer();
+ const TOP = TABLE.plot[2];
+ const C = Cam(45, 0.5, S);
+ fit(C, [[0, 0, -BZ], [L, 0, -BZ], [0, D, -BZ], [L, D, -BZ], [0, PY, HP], [L, PY, HP]], 200, 166);
+ const P = proj(C), front = facing(C);
+ const g = mk("g", {}, svg);
+
+ // Back to front: the base, the plate and the grid on its face, then the tabs from the far end.
+ const [bo, bi] = rings(0, 0, L, D, 6, 1.6);
+ put(solid(g), prism(P, front, bo, bi, -BZ, 0));
+ const face = (y: number) => FACE.map(([x, z]) => P(x, y, z));
+ // A thin plate: its silhouette, and its near face's right side and top for the thickness.
+ put(solid(g), { sil: poly(hull(face(PY).concat(face(PY + PT)))), crease: open(face(PY + PT).slice(...EDGE)) });
+ // On its face, a chart with nothing plotted: dim grid lines, and the axis they start from, with a tick at each.
+ const at = (x: number, z: number) => P(x, PY + PT, z), zs = Array.from({ length: GRID }, (_, k) => (HP * (k + 1)) / (GRID + 1));
+ mk("path", { class: "nf lo", d: zs.map((z) => seg(at(AX, z), at(L - 7, z))).join("") }, g);
+ mk("path", { class: "nf", d: seg(at(AX, 0), at(AX, HP - 4)) + zs.map((z) => seg(at(AX - TICK, z), at(AX, z))).join("") }, g);
+ const tabs = Array.from({ length: N }, (_, i) => { const x = X0 + i * DX; return { ring: rings(x - TW / 2, TY0, x + TW / 2, TY1, 1.2, 0.4), el: solid(g) }; });
+
+ const sp = tabs.map((_, i) => spring(i === MARK ? PROUD : 0, SPRING));
+ const drawn = tabs.map(() => NaN);
+ function draw() {
+ tabs.forEach((t, i) => {
+ const h = clamp(sp[i].x, 0, TOP);
+ if (h === drawn[i]) return;
+ drawn[i] = h;
+ put(t.el, prism(P, front, t.ring[0], t.ring[1], 0, TH + h));
+ });
+ }
+
+ const loop = register(stage, (dt) => { let m = false; for (const s of sp) m = stepS(s, dt) || m; draw(); return m; });
+ bag.add(loop.unregister);
+
+ // Each tab's rest centre on screen: what the pointer's x is read against.
+ const cx = tabs.map((_, i) => P(X0 + i * DX, (TY0 + TY1) / 2, 0)[0]);
+ let lift = value, picked = -2;
+ /** Kicks every tab up toward its share of the lift, from tab a; one already that high is left alone. */
+ function kick(a: number) {
+ sp.forEach((s, i) => { const need = lift * falloff(Math.abs(i - a)) - s.x; if (need > 0) s.v = Math.max(s.v, KICK * need); });
+ loop.wake();
+ }
+ function choose(a: number) {
+ if (a === picked) return;
+ picked = a;
+ sp.forEach((s, i) => { s.t = a < 0 && i === MARK ? PROUD : 0; });
+ if (a >= 0) kick(a);
+ tabs.forEach((t, i) => t.el.sil.classList.toggle("hi", i === (a < 0 ? MARK : a)));
+ read.textContent = a < 0 ? "rest" : `bar ${a + 1} · 0`;
+ loop.wake();
+ }
+ choose(-1);
+ draw();
+
+ bag.add(pointer(stage, {
+ move: (p) => choose(cx.reduce((best, x, i) => (Math.abs(p[0] - x) < Math.abs(p[0] - cx[best]) ? i : best), 0)),
+ leave: () => choose(-1),
+ }));
+ bag.add(() => svg.replaceChildren());
+
+ return { set: (v) => { lift = v; if (picked >= 0) kick(picked); }, destroy: bag.dispose };
+};
diff --git a/packages/hairline/src/figures/plug.ts b/packages/hairline/src/figures/plug.ts
new file mode 100644
index 0000000..cc66c3a
--- /dev/null
+++ b/packages/hairline/src/figures/plug.ts
@@ -0,0 +1,160 @@
+import { Cam, circ, clamp, fit, hull, lerp, open, poly, proj, rad, rrect, run, unproj, type Ring, type Vec2, type Vec3 } from "../core/iso";
+import { spring, stepS } from "../core/motion";
+import { disposer, mk, pointer, put, register, solid, type FigureMount } from "../core/stage";
+
+/**
+ * Plug: a wall plate with a socket, and a plug lying on the floor at the end
+ * of a cord that curves away out of the frame. The pointer draws the plug up
+ * toward the socket on a spring, and the cord pays out behind it. It never
+ * seats: it stops short, and falls back when the pointer leaves. At rest it
+ * lies on the floor, its two pins bright, the socket's holes bare. The slider
+ * is how much of the way to the socket the plug can come.
+ *
+ * The pattern: follow a position. One spring on how far along its way the
+ * plug is, set from where the pointer falls on the screen line from the
+ * plug's rest to the socket, which never moves. Where the plug is and how far
+ * it has turned to face the wall are both read from that one number.
+ */
+
+const PT = 3, PH = 21, ZC = 30, PR = 7, B = 1.4; // the plate: thickness, half its side, the socket's height, corner radius, crease inset
+const HOLE = 2.6, HS = 8, RECESS = 13; // the socket: hole radius, the holes' offset from its centre, the recess round them
+const BW = 11, BH = 6.5, BR = 4.5, BL = 18; // the plug's body: half width, half height, corner radius, length
+const PIN = 2, PL = 11, SL = 7, S0 = 4.6, S1 = 3, CR = 1.8; // pin radius, pin length, the sleeve's length and two radii, the cord's radius
+const REST: Vec2 = [48, 8], YAW = 100, TURN = 0.7, S = 2.8; // the pins' face on the floor, its heading, the share of the way the turn takes, scale
+const EDGE = 398; // where the cord leaves the picture: the viewBox's right edge, less a stroke
+const ss = (t: number) => t * t * (3 - 2 * t);
+
+/** Cuts the loops an inner offset makes where the cord bends tighter than its radius on screen. */
+function untangle(L: Vec2[]): Vec2[] {
+ for (let i = 0; i < L.length - 3; i++) for (let j = L.length - 2; j > i + 1; j--) {
+ const p = L[i], q = L[i + 1], r = L[j], s = L[j + 1];
+ const e0 = q[0] - p[0], e1 = q[1] - p[1], f0 = s[0] - r[0], f1 = s[1] - r[1], g0 = r[0] - p[0], g1 = r[1] - p[1], d = e0 * f1 - e1 * f0;
+ if (!d) continue;
+ const t = (g0 * f1 - g1 * f0) / d, u = (g0 * e1 - g1 * e0) / d;
+ if (t > 0 && t < 1 && u > 0 && u < 1) { L.splice(i + 1, j - i, [p[0] + t * e0, p[1] + t * e1]); break; }
+ }
+ return L;
+}
+
+/** A screen line up to where it first crosses x = X, ending on it. */
+function upTo(L: Vec2[], X: number): Vec2[] {
+ const i = L.findIndex((p) => p[0] > X);
+ if (i < 1) return i < 0 ? L : [];
+ const p = L[i - 1], q = L[i], f = (X - p[0]) / (q[0] - p[0]);
+ return [...L.slice(0, i), [X, p[1] + (q[1] - p[1]) * f]];
+}
+
+/** The cord's outline: its screen centre line offset by its radius, the plug's end a round cut, the far end cut off at x = X with no line across it, as the frame would. */
+function tube(Q: readonly Vec2[], rho: number, X: number): string {
+ const n = Q.length, A: Vec2[] = [], Bk: Vec2[] = [];
+ for (let i = 0; i < n; i++) {
+ const a = Q[Math.max(i - 1, 0)], c = Q[i], b = Q[Math.min(i + 1, n - 1)];
+ let tx = b[0] - a[0], ty = b[1] - a[1];
+ const l = Math.hypot(tx, ty) || 1; tx /= l; ty /= l;
+ A.push([c[0] - ty * rho, c[1] + tx * rho]); Bk.push([c[0] + ty * rho, c[1] - tx * rho]);
+ }
+ const cap = (c: Vec2) => { const o: Vec2[] = []; for (let k = 7; k >= 1; k--) { const t = (Math.PI * k) / 8; o.push([c[0] + rho * Math.cos(t), c[1] + rho * 0.5 * Math.sin(t)]); } return o; };
+ return open([...upTo(untangle(Bk), X).reverse(), ...cap(Q[0]), ...upTo(untangle(A), X)]);
+}
+
+/** Where the plug is s of the way to the socket: the centre of its pins' face, its heading (w) and its width (u). Up is up. */
+function pose(s: number): { c: Vec3; w: Vec3; u: Vec3 } {
+ const th = rad(lerp(YAW, 180, ss(clamp(s / TURN, 0, 1))));
+ return {
+ c: [lerp(REST[0], PL, s), lerp(REST[1], 0, s), lerp(BH, ZC, Math.sin((s * Math.PI) / 2))],
+ w: [Math.cos(th), Math.sin(th), 0],
+ u: [-Math.sin(th), Math.cos(th), 0],
+ };
+}
+
+export const mount: FigureMount = ({ stage, svg, read }, value) => {
+ const bag = disposer();
+ const C = Cam(45, 0.5, S), zf = Math.sqrt(1 - C.k * C.k);
+ /** Toward the camera: a face whose normal has a positive dot with this is seen. */
+ const V: Vec3 = [Math.sin(C.az) * zf, Math.cos(C.az) * zf, C.k];
+ const dot = (a: Vec3, b: Vec3) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
+ /** A point in the plug's own frame: a across, b up, d along its heading from the pins' face. */
+ const at = (o: ReturnType<typeof pose>, a: number, b: number, d: number): Vec3 =>
+ [o.c[0] + a * o.u[0] + d * o.w[0], o.c[1] + a * o.u[1] + d * o.w[1], o.c[2] + b];
+
+ // The camera is fitted to the plate and the plug at both ends of its way.
+ const ext: Vec3[] = [];
+ for (const x of [0, -PT]) for (const y of [-PH, PH]) for (const z of [ZC - PH, ZC + PH]) ext.push([x, y, z]);
+ for (const s of [0, 1]) { const o = pose(s); for (const a of [-BW, BW]) for (const b of [-BH, BH]) for (const d of [PL, -BL - SL]) ext.push(at(o, a, b, d)); }
+ fit(C, ext, 200, 166);
+ const P = proj(C), Pv = (p: Vec3) => P(p[0], p[1], p[2]);
+
+ // The plate: a thin slab on the wall, its face toward +x, the recess and two holes cut into it.
+ const g = mk("g", {}, svg);
+ const face = rrect(-PH, ZC - PH, PH, ZC + PH, PR, 6), lip = rrect(-PH + B, ZC - PH + B, PH - B, ZC + PH - B, PR - B, 6);
+ put(solid(g), {
+ sil: poly(hull(face.map((q) => P(0, q.u, q.v)).concat(face.map((q) => P(-PT, q.u, q.v))))),
+ crease: open(run(lip, (q) => q.nu * V[1] + q.nv * V[2] > 0).map((q) => P(0, q.u, q.v))),
+ });
+ mk("path", { class: "nf lo", d: poly(circ(RECESS, 48).map((q) => P(0, q.u, ZC + q.v))) }, g);
+ mk("path", { class: "nf", d: [-HS, HS].map((y) => poly(circ(HOLE, 16).map((q) => P(0, y + q.u, ZC + q.v)))).join("") }, g);
+
+ // The plug, back to front as it lies; the order turns over with it.
+ const pg = mk("g", {}, svg);
+ const cord = mk("path", { class: "sil" }, pg), sleeve = mk("path", { class: "sil" }, pg), body = solid(pg), pins = mk("path", { class: "sil hi" }, pg);
+ const s0 = circ(S0, 16), s1 = circ(S1, 16);
+ /** An end rounded over rr: the cross-section f(inset) in four steps, from the face at d inward along dir. */
+ const rounded = (f: (k: number) => Ring, rr: number, d: number, dir: number) =>
+ [0, 30, 60, 90].map((a): [Ring, number] => [f(rr * (1 - Math.sin(rad(a)))), d + dir * rr * (1 - Math.cos(rad(a)))]);
+ const box = (k: number) => rrect(-BW + k, -BH + k, BW - k, BH - k, BR - k), rod = (k: number) => circ(PIN - k, 12);
+ const inner = box(2), shell = [...rounded(box, 2, 0, -1), ...rounded(box, 2, -BL, 1)], prong = [[rod(0), 0] as [Ring, number], ...rounded(rod, PIN * 0.8, PL, -1)];
+ /** The silhouette of a solid swept through cross-sections, each a ring at a distance along the heading, a0 across. */
+ const sweep = (o: ReturnType<typeof pose>, parts: Array<[Ring, number]>, a0 = 0) =>
+ poly(hull(parts.flatMap(([r, d]) => r.map((q) => Pv(at(o, a0 + q.u, q.v, d))))));
+
+ // The cord's floor end, past the frame's right edge, and the floor point it bends round; neither moves.
+ // The cord is drawn only up to just inside that edge, so it runs out of the picture without leaving the viewBox.
+ const end: Vec3 = [...unproj(C, 440, 150, CR), CR], bend: Vec3 = [REST[0] + 18, REST[1] - 52, CR];
+ let front = true, drawn = NaN;
+ const sp = spring(0, { eps: 0.002 });
+
+ function draw() {
+ if (sp.x === drawn) return;
+ drawn = sp.x;
+ const o = pose(sp.x), pinsFace = dot(o.w, V) > 0, vu = dot(o.u, V);
+ if (pinsFace !== front) { front = pinsFace; pg.append(...(front ? [cord, sleeve, body.g, pins] : [pins, body.g, cord, sleeve])); }
+ const dEnd = front ? 0 : -BL;
+ put(body, {
+ sil: sweep(o, shell),
+ crease: open(run(inner, (q) => q.nu * vu + q.nv * V[2] > 0).map((q) => Pv(at(o, q.u, q.v, dEnd)))),
+ });
+ pins.setAttribute("d", [-HS, HS].map((a) => sweep(o, prong, a)).join(""));
+ sleeve.setAttribute("d", sweep(o, [[s0, -BL], [s1, -BL - SL]]));
+ // The cord: a cubic from inside the sleeve's end, leaving along the plug's heading, round the bend to the floor end.
+ const t0 = at(o, 0, 0, -BL - SL + 2), t1 = at(o, 0, 0, -BL - SL - 26), Q: Vec2[] = [];
+ for (let i = 0; i <= 40; i++) {
+ const t = i / 40, a = (1 - t) ** 3, b = 3 * (1 - t) ** 2 * t, c = 3 * (1 - t) * t * t, d = t ** 3;
+ Q.push(P(a * t0[0] + b * t1[0] + c * bend[0] + d * end[0], a * t0[1] + b * t1[1] + c * bend[1] + d * end[1], a * t0[2] + b * t1[2] + c * bend[2] + d * end[2]));
+ }
+ cord.setAttribute("d", tube(Q, CR * S, EDGE));
+ }
+
+ const loop = register(stage, (dt) => { const m = stepS(sp, dt); draw(); return m; });
+ bag.add(loop.unregister);
+
+ // The line the pointer is read along: from the pins' face at rest to the socket, on screen. Neither moves.
+ const A = Pv(pose(0).c), Bs = P(0, 0, ZC), ab: Vec2 = [Bs[0] - A[0], Bs[1] - A[1]], ab2 = ab[0] * ab[0] + ab[1] * ab[1];
+ let pull = value, along = -1;
+ function retarget() {
+ sp.t = along < 0 ? 0 : Math.min(along, pull);
+ // the gap from the pins' tips to the socket, read from the target, never the pose on screen
+ const o = pose(sp.t), tip = at(o, 0, 0, PL);
+ read.textContent = along < 0 ? "rest" : `gap ${Math.round(Math.hypot(tip[0], tip[1], tip[2] - ZC))} · 0 V`;
+ loop.wake();
+ }
+ retarget();
+ draw();
+
+ bag.add(pointer(stage, {
+ move: (p) => { along = clamp(((p[0] - A[0]) * ab[0] + (p[1] - A[1]) * ab[1]) / ab2, 0, 1); retarget(); },
+ leave: () => { along = -1; retarget(); },
+ }));
+ bag.add(() => svg.replaceChildren());
+
+ return { set: (v) => { pull = v; retarget(); }, destroy: bag.dispose };
+};
diff --git a/packages/hairline/src/figures/query.ts b/packages/hairline/src/figures/query.ts
new file mode 100644
index 0000000..33b053a
--- /dev/null
+++ b/packages/hairline/src/figures/query.ts
@@ -0,0 +1,163 @@
+import { Cam, circ, clamp, facing, fit, open, poly, prism, proj, rad, type Vec2, type Vec3 } from "../core/iso";
+import { spring, stepS } from "../core/motion";
+import { disposer, mk, pointer, put, register, solid, type FigureMount } from "../core/stage";
+import { TABLE } from "../intensity";
+
+/**
+ * Query: a question mark built as a solid on a small round plinth. The hook
+ * is one bent bar, swept along a centre line of an arc, a neck and a stem, as
+ * Padlock's shackle is; the dot is a ball lying loose on the plinth under it.
+ * The pointer turns the hook about its stem toward it, and the ball rolls
+ * round after it, later and softer, and comes back to lie under the stem. At
+ * rest the hook stands well off square and the ball lies on its axis,
+ * under the stem's foot, bright: the dot of the mark. The slider is how far
+ * the hook turns, in degrees.
+ *
+ * The pattern: follow a position. One spring on the hook's turn, set by the
+ * pointer's screen x against the stem's, which never moves. The ball follows
+ * that turn on a softer spring, because a loose ball lags what it rolls after;
+ * it is pushed off the axis only by how far it lags, a few units at most, so
+ * it always reads as the dot and settles back under the stem.
+ */
+
+const PR = 27, PH = 6, B = 1.6; // the plinth: radius, height, crease inset
+const T = 4.3, R = 16, ZC = 66, A0 = 200, A1 = -35; // the bar: radius, the hook's radius, its centre's height, where the arc starts and ends
+const ZK = 38, ZS = 29, BR = 6, SWAY = 0.2, TRAVEL = 4; // the neck's foot, the stem's end, the ball's radius, how far off the axis a degree of lag pushes it, and the most it goes
+const FACE = -45, REST = 36, REACH = 150, S = 2.6; // the plane that faces the camera, the rest turn, the pointer's reach in viewBox units, scale
+const LIGHT: Vec2 = [-Math.SQRT1_2, -Math.SQRT1_2], GLEAM = 0.4; // where the light comes from on screen (the ball's glint too), and how far the bar's crease leans to it, in radii
+
+/** The centre line in the hook's own plane (s across, z up): over the arc, down the neck, down the stem. */
+const LINE: Vec2[] = /* @__PURE__ */ (() => {
+ const pts: Vec2[] = [];
+ for (let i = 0; i <= 30; i++) { const a = rad(A0 + ((A1 - A0) * i) / 30); pts.push([R * Math.cos(a), ZC + R * Math.sin(a)]); }
+ const e = pts[pts.length - 1], a = rad(A1), t: Vec2 = [Math.sin(a), -Math.cos(a)];
+ const c1: Vec2 = [e[0] + t[0] * 10, e[1] + t[1] * 10], c2: Vec2 = [0, ZK + 10]; // long handles: the neck bends no tighter than 2.5 bar radii
+ for (let i = 1; i <= 20; i++) {
+ const u = i / 20, w = 1 - u;
+ pts.push([w * w * w * e[0] + 3 * w * w * u * c1[0] + 3 * w * u * u * c2[0], w * w * w * e[1] + 3 * w * w * u * c1[1] + 3 * w * u * u * c2[1] + u * u * u * ZK]);
+ }
+ pts.push([0, ZS]);
+ return pts;
+})();
+
+/** The run of LINE the bar's crease follows: the arc, short of its tip and of the neck. */
+const ARC = [2, 28];
+
+/** Point i of a screen centre line, moved d toward the light across the bar: the line a round section catches its light on. */
+function lean(Q: readonly Vec2[], i: number, d: number): Vec2 {
+ const a = Q[Math.max(i - 1, 0)], b = Q[Math.min(i + 1, Q.length - 1)], l = Math.hypot(b[0] - a[0], b[1] - a[1]) || 1;
+ const nx = -(b[1] - a[1]) / l, ny = (b[0] - a[0]) / l, k = d * (nx * LIGHT[0] + ny * LIGHT[1]);
+ return [Q[i][0] + nx * k, Q[i][1] + ny * k];
+}
+
+/** Where two screen segments cross, or null. */
+function cross(p: Vec2, q: Vec2, r: Vec2, s: Vec2): Vec2 | null {
+ const e0 = q[0] - p[0], e1 = q[1] - p[1], f0 = s[0] - r[0], f1 = s[1] - r[1], g0 = r[0] - p[0], g1 = r[1] - p[1];
+ const d = e0 * f1 - e1 * f0;
+ if (!d) return null;
+ const t = (g0 * f1 - g1 * f0) / d, u = (g0 * e1 - g1 * e0) / d;
+ return t > 0 && t < 1 && u > 0 && u < 1 ? [p[0] + t * e0, p[1] + t * e1] : null;
+}
+/** Cuts the loops an inner offset makes where the bar bends tighter than its radius on screen. */
+function untangle(L: Vec2[]): Vec2[] {
+ for (let i = 0; i < L.length - 3; i++) for (let j = L.length - 2; j > i + 1; j--) {
+ const x = cross(L[i], L[i + 1], L[j], L[j + 1]);
+ if (x) { L.splice(i + 1, j - i, x); break; }
+ }
+ return L;
+}
+
+/** The bar's outline: its screen centre line offset by its radius. The curl's tip is a dome, round from anywhere; the stem's foot is cut flat, seen from above. */
+function tube(Q: readonly Vec2[], rho: number): string {
+ const n = Q.length, A: Vec2[] = [], Bk: Vec2[] = [], tan: Vec2[] = [];
+ for (let i = 0; i < n; i++) {
+ const a = Q[Math.max(i - 1, 0)], c = Q[i], b = Q[Math.min(i + 1, n - 1)];
+ const l0 = Math.hypot(c[0] - a[0], c[1] - a[1]) || 1, l1 = Math.hypot(b[0] - c[0], b[1] - c[1]) || 1;
+ let tx = (c[0] - a[0]) / l0 + (b[0] - c[0]) / l1, ty = (c[1] - a[1]) / l0 + (b[1] - c[1]) / l1;
+ const l = Math.hypot(tx, ty) || 1; tx /= l; ty /= l;
+ tan.push([tx, ty]);
+ A.push([c[0] - ty * rho, c[1] + tx * rho]); Bk.push([c[0] + ty * rho, c[1] - tx * rho]);
+ }
+ /** The dome: half a round from the near side to the far, through the point the tip faces. */
+ const dome = (c: Vec2, t: Vec2) => Array.from({ length: 9 }, (_, k): Vec2 => {
+ const a = (Math.PI * (k + 1)) / 10, cs = -Math.cos(a), sn = -Math.sin(a);
+ return [c[0] + rho * (-t[1] * cs + t[0] * sn), c[1] + rho * (t[0] * cs + t[1] * sn)];
+ });
+ /** The flat cut: the near half of a level round, as Padlock's ends are. The stem stands plumb, so it runs left to right. */
+ const cut = (c: Vec2) => Array.from({ length: 7 }, (_, k): Vec2 => { const a = (Math.PI * (7 - k)) / 8; return [c[0] + rho * Math.cos(a), c[1] + rho * 0.5 * Math.sin(a)]; });
+ return poly([...untangle(A), ...cut(Q[n - 1]), ...untangle(Bk).reverse(), ...dome(Q[0], tan[0])]);
+}
+
+export const mount: FigureMount = ({ stage, svg, read }, value) => {
+ const bag = disposer();
+ const TMAX = TABLE.query[2];
+ let max = value, over = false;
+
+ /** The hook's plane, turned th degrees from facing the camera: a point (s, z) of it in the world. */
+ const at = (th: number) => { const a = rad(FACE - th), c = Math.cos(a), n = Math.sin(a); return (s: number, z: number): Vec3 => [s * c, s * n, z]; };
+ /** The ball's centre: on the axis under the stem, pushed across the hook's plane by how far it lags the turn. */
+ const ball = (lag: number, th: number): Vec3 => at(th)(clamp(lag * SWAY, -TRAVEL, TRAVEL), PH + BR);
+
+ // The camera is fitted to the plinth and the hook at both ends of its widest turn.
+ const C = Cam(45, 0.5, S);
+ const ext: Vec3[] = [[-PR, 0, 0], [PR, 0, 0], [0, -PR, 0], [0, PR, 0]];
+ for (const th of [-TMAX, -TMAX / 2, 0, TMAX / 2, TMAX]) for (const p of LINE) { const q = at(th)(p[0], p[1]); ext.push([q[0], q[1], q[2] + T], [q[0], q[1], q[2] - T]); }
+ fit(C, ext, 200, 166);
+ C.ox += 200 - proj(C)(0, 0, 0)[0]; // the stem stands on the frame's middle, however unevenly the turns reach
+ const P = proj(C), front = facing(C), rho = T * S;
+ const g = mk("g", {}, svg);
+
+ // Back to front: the plinth, the ball lying on it, the hook over it.
+ put(solid(g), prism(P, front, circ(PR, 72), circ(PR - B, 72), 0, PH));
+ const dot = solid(g);
+ const disc = circ(BR * S, 40), shine = circ(BR * S * 0.62, 40).slice(23, 31);
+ const bar = mk("path", { class: "sil" }, g);
+ const gleam = mk("path", { class: "nf lo" }, g);
+
+ /** The rest turn: off square, the other way from where it opens, and always inside the slider's reach. */
+ const rest = () => -Math.min(REST, 0.9 * max);
+ const sp = spring(rest()), roll = spring(rest(), { k: 36, c: 7 });
+ let dH = NaN, dB = NaN;
+ function draw() {
+ if (sp.x !== dH) {
+ dH = sp.x;
+ const w = at(sp.x);
+ const Q = LINE.map((p) => P(...w(p[0], p[1])));
+ bar.setAttribute("d", tube(Q, rho));
+ gleam.setAttribute("d", open(Q.slice(ARC[0], ARC[1]).map((c, i) => lean(Q, ARC[0] + i, GLEAM * rho))));
+ }
+ const lag = sp.x - roll.x;
+ if (lag !== dB) {
+ dB = lag;
+ const c = P(...ball(lag, roll.x));
+ put(dot, { sil: poly(disc.map((q) => [c[0] + q.u, c[1] + q.v])), crease: open(shine.map((q): Vec2 => [c[0] + q.u, c[1] + q.v])) });
+ }
+ }
+
+ const loop = register(stage, (dt) => {
+ roll.t = sp.x; // the ball rolls after where the hook is, not where it is going
+ const a = stepS(sp, dt), b = stepS(roll, dt);
+ draw();
+ return a || b;
+ });
+ bag.add(loop.unregister);
+
+ const cx = P(0, 0, 0)[0];
+ let px = cx;
+ function retarget() {
+ sp.t = over ? max * clamp((px - cx) / REACH, -1, 1) : rest(); // read from the target, never the turn on screen
+ read.textContent = over ? `turn ${Math.abs(Math.round(sp.t))}° · 0` : "rest";
+ dot.sil.classList.toggle("hi", !over);
+ bar.classList.toggle("hi", over);
+ loop.wake();
+ }
+ retarget();
+
+ bag.add(pointer(stage, {
+ move: (p) => { over = true; px = p[0]; retarget(); },
+ leave: () => { over = false; retarget(); },
+ }));
+ bag.add(() => svg.replaceChildren());
+
+ return { set: (v) => { max = v; retarget(); }, destroy: bag.dispose };
+};
diff --git a/packages/hairline/src/figures/rail.ts b/packages/hairline/src/figures/rail.ts
new file mode 100644
index 0000000..963bcfb
--- /dev/null
+++ b/packages/hairline/src/figures/rail.ts
@@ -0,0 +1,89 @@
+import { Cam, clamp, facing, fillet, fit, hull, open, poly, prism, proj, rad, rings, type Vec2, type Vec3 } from "../core/iso";
+import { spring, stepS } from "../core/motion";
+import { disposer, mk, pointer, put, register, solid, type FigureMount } from "../core/stage";
+
+/**
+ * Rail: a garment rail on two uprights, with seven bare hangers. The pointer
+ * brushes the hangers: each rocks on its hook away from it, the nearest most,
+ * and settles. At rest they hang at uneven angles and one is bright. The
+ * slider is how many hangers the brush reaches.
+ *
+ * The pattern: a field, as Terrain's. One spring per hanger on its rock, the
+ * target falling off with its distance, in hangers, from the one picked. The
+ * pick is the hanger whose rest centre is nearest the pointer's screen x. The
+ * springs are softer than the default because a hanger is a pendulum.
+ */
+
+const L = 132, TOP = 92, POST = 4.4, FOOT = 34, BAR = 2; // rail length, its height, upright side, foot depth, rail radius
+const N = 7, X0 = 21, DX = 15, TH = 1.8, ROCK = 22; // hangers, the first one's x, their pitch, thickness, furthest rock in degrees
+const REST = [4, -7, 2, 13, -3, 6, -9], MARK = 3, S = 1.9;
+/** A hanger in its own plane: s along its shoulders, d down from the rail's centre. */
+const BODY = /* @__PURE__ */ fillet([[0, 9], [25, 21], [25, 25], [-25, 25], [-25, 21]], [4, 2, 2, 2, 2], 5);
+const HOLE = /* @__PURE__ */ fillet([[0, 14], [15, 21.5], [-15, 21.5]], [2, 1.2, 1.2], 4);
+/** Its hook: the stem, then up the rail's near side and over; the tip that drops behind the rail is hidden, so not drawn. */
+const HOOK: Vec2[] = /* @__PURE__ */ (() => [[0, 9], [0, 5], ...Array.from({ length: 10 }, (_, k): Vec2 => { const t = rad(120 - k * 20); return [Math.sin(t) * 3.4, -Math.cos(t) * 3.4]; })])();
+
+export const mount: FigureMount = ({ stage, svg, read }, value) => {
+ const bag = disposer();
+ const C = Cam(45, 0.5, S);
+ const ext: Vec3[] = [[0, -FOOT / 2, 0], [L, -FOOT / 2, 0], [0, FOOT / 2, 0], [L, FOOT / 2, 0], [0, 0, TOP + 6], [L, 0, TOP + 6], [0, -30, TOP - 30], [L, 30, TOP - 30]];
+ fit(C, ext, 200, 166);
+ const P = proj(C), front = facing(C);
+ const g = mk("g", {}, svg);
+ const block = (x0: number, y0: number, x1: number, y1: number, r: number, z0: number, z1: number) => { const [o, i] = rings(x0, y0, x1, y1, r, 0.7); put(solid(g), prism(P, front, o, i, z0, z1)); };
+
+ // Back to front: the far foot and upright, the hangers from the far end, the rail, their hooks, the near foot and upright.
+ // The hangers go under the rail: all of one the rail crosses on screen is its far shoulder, which is behind it.
+ block(-POST / 2 - 1, -FOOT / 2, POST / 2 + 1, FOOT / 2, 2.2, 0, 3);
+ block(-POST / 2, -POST / 2, POST / 2, POST / 2, 1.4, 3, TOP + 4);
+ const bodies = Array.from({ length: N }, () => solid(g));
+ block(0, -BAR, L, BAR, BAR, TOP - BAR, TOP + BAR);
+ const hooks = bodies.map(() => mk("path", { class: "nf" }, g));
+ block(L - POST / 2 - 1, -FOOT / 2, L + POST / 2 + 1, FOOT / 2, 2.2, 0, 3);
+ block(L - POST / 2, -POST / 2, L + POST / 2, POST / 2, 1.4, 3, TOP + 4);
+
+ const sp = REST.map((a) => spring(a, { k: 60, c: 6, eps: 0.02 }));
+ const drawn = REST.map(() => NaN);
+ function draw() {
+ sp.forEach((s, i) => {
+ if (s.x === drawn[i]) return;
+ drawn[i] = s.x;
+ const c = Math.cos(rad(s.x)), n = Math.sin(rad(s.x)), x = X0 + i * DX;
+ // a point of the hanger's plane, rocked about the rail
+ const at = (p: Vec2, dx: number) => P(x + dx, p[0] * c + p[1] * n, TOP - (p[1] * c - p[0] * n));
+ put(bodies[i], { sil: poly(hull(BODY.map((p) => at(p, 0)).concat(BODY.map((p) => at(p, TH))))), crease: poly(HOLE.map((p) => at(p, TH))) });
+ hooks[i].setAttribute("d", open(HOOK.map((p) => at(p, TH / 2))));
+ });
+ }
+
+ const loop = register(stage, (dt) => { let m = false; for (const s of sp) m = stepS(s, dt) || m; draw(); return m; });
+ bag.add(loop.unregister);
+
+ // Each hanger's rest centre on screen: what the pointer's x is read against.
+ const cx = REST.map((_, i) => P(X0 + i * DX, 0, TOP - 17)[0]);
+ let reach = value, picked = -2, side = 1;
+ function choose(a: number) {
+ picked = a;
+ sp.forEach((s, i) => {
+ const f = a < 0 ? 0 : clamp(1 - Math.abs(i - a) / (reach + 0.5), 0, 1);
+ s.t = REST[i] - ROCK * f * f * (i === a ? side : Math.sign(i - a)); // a lower rock swings the bottom right: away from a pointer on the left
+ });
+ bodies.forEach((b, i) => b.sil.classList.toggle("hi", i === (a < 0 ? MARK : a)));
+ read.textContent = a < 0 ? "rest" : `hanger ${a + 1} · 0`;
+ loop.wake();
+ }
+ choose(-1);
+ draw();
+
+ bag.add(pointer(stage, {
+ move: (p) => {
+ const a = cx.reduce((best, x, i) => (Math.abs(p[0] - x) < Math.abs(p[0] - cx[best]) ? i : best), 0);
+ side = p[0] < cx[a] ? 1 : -1;
+ choose(a);
+ },
+ leave: () => choose(-1),
+ }));
+ bag.add(() => svg.replaceChildren());
+
+ return { set: (v) => { reach = v; choose(picked < 0 ? -1 : picked); }, destroy: bag.dispose };
+};
diff --git a/packages/hairline/src/figures/sieve.ts b/packages/hairline/src/figures/sieve.ts
new file mode 100644
index 0000000..6673b45
--- /dev/null
+++ b/packages/hairline/src/figures/sieve.ts
@@ -0,0 +1,111 @@
+import { Cam, circ, fit, hull, open, poly, proj, unproj, type Vec2, type Vec3 } from "../core/iso";
+import { tdone, tset, tval, tween } from "../core/motion";
+import { disposer, mk, pointer, put, register, solid, type FigureMount } from "../core/stage";
+import { TABLE } from "../intensity";
+
+/**
+ * Sieve: three test sieves stacked over a pan, standing a little apart. The
+ * pointer's height picks a sieve; it rises clear of the one below, the ones
+ * above it ride up with it, and each mesh is bare. At rest the stack is parted
+ * under the middle sieve, whose rim is bright. The slider is the gap.
+ *
+ * The pattern: one of many. A tween for the gap under each sieve, staggered
+ * outwards from the one picked. The pick is read from the sieves' rest
+ * heights, which move only with the slider, never from the stack on screen.
+ */
+
+const N = 3, R = 36, H = 11, PAN = 8, WALL = 2.6, SEAT = 2, FLOOR = 1.6; // sieves, radius, a sieve's height, the pan's, wall, closed gap, the mesh above a sieve's foot
+const CHORDS = [-22, -11, 0, 11, 22], STEP = 40, S = 2.35, REST = 0.8, RIDE = 0.6; // mesh chords, stagger ms, scale, the rest gap and the gap above a pick, as shares of the gap
+
+/** The gap under sieve i when sieve f is picked (-1 for rest: the stack parted under the middle one). */
+const under = (f: number, i: number, gap: number) => {
+ const a = f < 0 ? 1 : f;
+ return i === a ? (f < 0 ? gap * REST : gap) : f >= 0 && i === a + 1 ? gap * RIDE : SEAT;
+};
+
+export const mount: FigureMount = ({ stage, svg, read }, value) => {
+ const bag = disposer();
+ const [, MID, MAX] = TABLE.sieve;
+ const C = Cam(45, 0.5, S);
+ // The tallest pose (a lower sieve picked at the widest gap) and the rest stack at the default gap. The box
+ // runs as far below the rest stack's middle as the tallest top is above it: rest sits in the middle, and the tallest still fits.
+ const tall = PAN + N * H + SEAT + MAX * (1 + RIDE), rest = PAN + N * H + 2 * SEAT + MID * REST;
+ const ext: Vec3[] = [];
+ for (const [x, y] of [[-R, 0], [R, 0], [0, -R], [0, R]]) ext.push([x, y, rest - tall], [x, y, tall]);
+ fit(C, ext, 200, 166);
+ const P = proj(C), y0 = P(0, 0, 0)[1];
+ const rise = (z: number) => P(0, 0, z)[1] - y0;
+ const outer = circ(R, 72), inner = circ(R - WALL, 72);
+ const g = mk("g", {}, svg);
+
+ // The pan, then the sieves bottom to top: each a drum, its mouth, and its mesh seen through the mouth.
+ const drum = (z0: number, z1: number): Vec2[] => hull(outer.map((q) => P(q.u, q.v, z0)).concat(outer.map((q) => P(q.u, q.v, z1))));
+ put(solid(g), { sil: poly(drum(0, PAN)), crease: poly(inner.map((q) => P(q.u, q.v, PAN))) });
+ const parts = Array.from({ length: N }, () => ({ s: solid(g), mesh: mk("path", { class: "nf lo" }, g) }));
+
+ /** The runs of a line on the floor at zf that show through the mouth at zm. */
+ const through = (pts: readonly Vec2[], zf: number, zm: number): Vec2[][] => {
+ const runs: Vec2[][] = [[]];
+ for (const [u, v] of pts) {
+ const s = P(u, v, zf), m = unproj(C, s[0], s[1], zm);
+ if (Math.hypot(u, v) < R - WALL && Math.hypot(m[0], m[1]) < R - WALL) runs[runs.length - 1].push(s);
+ else if (runs[runs.length - 1].length) runs.push([]);
+ }
+ return runs.filter((r) => r.length > 1);
+ };
+ // The mesh: chords both ways, and the floor's edge, begun at the front so its far run is one piece.
+ const chord = (a: Vec2, b: Vec2): Vec2[] => Array.from({ length: 29 }, (_, k) => [a[0] + ((b[0] - a[0]) * k) / 28, a[1] + ((b[1] - a[1]) * k) / 28]);
+ const lines = CHORDS.flatMap((c) => [chord([c, -R], [c, R]), chord([-R, c], [R, c])]);
+ lines.push(Array.from({ length: 73 }, (_, k) => { const t = Math.PI / 4 + (k / 72) * Math.PI * 2, r = R - WALL - 0.05; return [r * Math.cos(t), r * Math.sin(t)]; }));
+
+ // A sieve standing on the ground, drawn once. What shows through the mouth depends only on the mouth's
+ // height over the mesh, so a sieve at any height is this, moved up the screen.
+ const body = drum(0, H), mouth = inner.map((q) => P(q.u, q.v, H)), mesh = lines.flatMap((l) => through(l, FLOOR, H));
+ const up = (pts: readonly Vec2[], dy: number) => pts.map((p): Vec2 => [p[0], p[1] + dy]);
+
+ const gaps = Array.from({ length: N }, () => tween(SEAT));
+ const drawn = gaps.map(() => NaN);
+ let picked = -2, gap = value;
+ function draw(now: number) {
+ let z = PAN;
+ gaps.forEach((t, i) => {
+ z += tval(t, now);
+ if (z !== drawn[i]) {
+ drawn[i] = z;
+ const dy = rise(z);
+ put(parts[i].s, { sil: poly(up(body, dy)), crease: poly(up(mouth, dy)) });
+ parts[i].mesh.setAttribute("d", mesh.map((r) => open(up(r, dy))).join(""));
+ }
+ z += H;
+ });
+ }
+
+ const loop = register(stage, (_dt, now) => { draw(now); return gaps.some((t) => !tdone(t, now)); });
+ bag.add(loop.unregister);
+
+ /** Sets every gap for a pick, f being the sieve picked, or -1 for rest. */
+ function choose(f: number, now: number) {
+ if (f === picked) return;
+ picked = f;
+ const a = f < 0 ? 1 : f;
+ gaps.forEach((t, i) => tset(t, under(f, i, gap), now, Math.abs(i - a) * STEP));
+ parts.forEach((p, i) => p.s.sil.classList.toggle("hi", i === a));
+ read.textContent = f < 0 ? "rest" : `sieve ${N - f} · 0`;
+ loop.wake();
+ }
+ choose(-1, -1e9);
+ draw(0);
+
+ /** The rest stack's middles on screen, bottom to top: what the pointer's height is read against. */
+ const bands = () => { let z = PAN; return gaps.map((_, i) => { z += under(-1, i, gap); const y = P(0, 0, z + H / 2)[1]; z += H; return y; }); };
+ let mids = bands();
+ const pick = (p: Vec2) => mids.reduce((best, y, i) => (Math.abs(p[1] - y) < Math.abs(p[1] - mids[best]) ? i : best), 0);
+
+ bag.add(pointer(stage, { move: (p) => choose(pick(p), performance.now()), leave: () => choose(-1, performance.now()) }));
+ bag.add(() => svg.replaceChildren());
+
+ return {
+ set: (v) => { gap = v; mids = bands(); const f = picked; picked = -2; choose(f, performance.now()); },
+ destroy: bag.dispose,
+ };
+};
diff --git a/packages/hairline/src/index.ts b/packages/hairline/src/index.ts
index 2533bad..9aef472 100644
--- a/packages/hairline/src/index.ts
+++ b/packages/hairline/src/index.ts
@@ -1,18 +1,26 @@
import { create, type Figure, type HairlineOptions } from "./mount";
+import { mount as basketEngine } from "./figures/basket";
import { mount as branchesEngine } from "./figures/branches";
import { mount as cabinetEngine } from "./figures/cabinet";
import { mount as dishEngine } from "./figures/dish";
+import { mount as drawerEngine } from "./figures/drawer";
import { mount as elevatorEngine } from "./figures/elevator";
import { mount as explodedEngine } from "./figures/exploded";
import { mount as keyboardEngine } from "./figures/keyboard";
import { mount as laptopEngine } from "./figures/laptop";
import { mount as lockersEngine } from "./figures/lockers";
+import { mount as loupeEngine } from "./figures/loupe";
import { mount as padlockEngine } from "./figures/padlock";
import { mount as patchEngine } from "./figures/patch";
import { mount as phoneEngine } from "./figures/phone";
import { mount as phosphorEngine } from "./figures/phosphor";
+import { mount as plotEngine } from "./figures/plot";
+import { mount as plugEngine } from "./figures/plug";
+import { mount as queryEngine } from "./figures/query";
+import { mount as railEngine } from "./figures/rail";
import { mount as riffleEngine } from "./figures/riffle";
import { mount as routerEngine } from "./figures/router";
+import { mount as sieveEngine } from "./figures/sieve";
import { mount as slowEngine } from "./figures/slow";
import { mount as terminalEngine } from "./figures/terminal";
import { mount as terrainEngine } from "./figures/terrain";
@@ -20,7 +28,7 @@ import { mount as turntableEngine } from "./figures/turntable";
import { mount as vaultEngine } from "./figures/vault";
/**
- * @lucasmarkes/hairline — nineteen isometric line figures that answer the pointer.
+ * @lucasmarkes/hairline — twenty-seven isometric line figures that answer the pointer.
*
* One function per figure. Each takes an element and the same options, draws
* into the element, and returns `{ update, destroy }`. Each function names
@@ -180,6 +188,16 @@ export function lockers(el: HTMLElement, options?: HairlineOptions): Figure {
}, el, options);
}
+/** A stand loupe over a blank ruled sheet: the pointer drags it across, and the rules pass enlarged under the glass with nothing between them. `intensity` magnifies more. */
+export function loupe(el: HTMLElement, options?: HairlineOptions): Figure {
+ return create({
+ id: "loupe",
+ label: "A stand loupe over a blank ruled sheet: the pointer drags it across, and the rules pass enlarged under the glass with nothing between them.",
+ rest: "rest",
+ engine: loupeEngine,
+ }, el, options);
+}
+
/** A padlock: as the pointer nears, the shackle springs up out of the body and swings open about its long leg. `intensity` swings the shackle further. */
export function padlock(el: HTMLElement, options?: HairlineOptions): Figure {
return create({
@@ -219,3 +237,73 @@ export function router(el: HTMLElement, options?: HairlineOptions): Figure {
engine: routerEngine,
}, el, options);
}
+
+/** Three test sieves stacked over a pan: the pointer's height picks one, it rises clear of the stack, and every mesh is bare. `intensity` opens the gap further. */
+export function sieve(el: HTMLElement, options?: HairlineOptions): Figure {
+ return create({
+ id: "sieve",
+ label: "Three test sieves stacked over a pan: the pointer's height picks one, it rises clear of the stack, and every mesh is bare.",
+ rest: "rest",
+ engine: sieveEngine,
+ }, el, options);
+}
+
+/** A garment rail with seven bare hangers: the pointer brushes them, and each rocks away from it, the nearest most, and settles. `intensity` reaches more hangers. */
+export function rail(el: HTMLElement, options?: HairlineOptions): Figure {
+ return create({
+ id: "rail",
+ label: "A garment rail with seven bare hangers: the pointer brushes them, and each rocks away from it, the nearest most, and settles.",
+ rest: "rest",
+ engine: railEngine,
+ }, el, options);
+}
+
+/** A wall socket and a plug lying on the floor at the end of its cord: the pointer draws the plug up toward the socket, and it stops short. `intensity` brings it nearer. */
+export function plug(el: HTMLElement, options?: HairlineOptions): Figure {
+ return create({
+ id: "plug",
+ label: "A wall socket and a plug lying on the floor at the end of its cord: the pointer draws the plug up toward the socket, and it stops short of it.",
+ rest: "rest",
+ engine: plugEngine,
+ }, el, options);
+}
+
+/** A question mark built as a solid on a plinth, its dot a loose ball: the hook turns about its stem toward the pointer, and the ball rolls after it. `intensity` turns the hook further. */
+export function query(el: HTMLElement, options?: HairlineOptions): Figure {
+ return create({
+ id: "query",
+ label: "A question mark built as a solid on a plinth, its dot a loose ball: the hook turns about its stem toward the pointer, and the ball rolls after it.",
+ rest: "rest",
+ engine: queryEngine,
+ }, el, options);
+}
+
+/** A filing cabinet of three drawers: the pointer's height picks one, it slides out, and inside are two dividers and nothing between them. `intensity` pulls the drawer further out. */
+export function drawer(el: HTMLElement, options?: HairlineOptions): Figure {
+ return create({
+ id: "drawer",
+ label: "A filing cabinet of three drawers: the pointer's height picks one, it slides out, and inside are two dividers and nothing between them.",
+ rest: "rest",
+ engine: drawerEngine,
+ }, el, options);
+}
+
+/** An empty wire shopping basket under a bail handle: the pointer tilts it toward itself on a spring, so the bare floor shows, and the handle swings after it, late. `intensity` tilts it further. */
+export function basket(el: HTMLElement, options?: HairlineOptions): Figure {
+ return create({
+ id: "basket",
+ label: "An empty wire shopping basket under a bail handle: the pointer tilts it toward itself on a spring, so the bare floor shows, and the handle swings after it, late.",
+ rest: "rest",
+ engine: basketEngine,
+ }, el, options);
+}
+
+/** A bar chart with no data: seven flat tabs on its base, before a plate of grid lines. The pointer brushes them, and each lifts a little, the nearest most, and drops back to zero. `intensity` lifts them higher. */
+export function plot(el: HTMLElement, options?: HairlineOptions): Figure {
+ return create({
+ id: "plot",
+ label: "A bar chart with no data: seven flat tabs on its base, before a plate of grid lines. The pointer brushes them, and each lifts a little, the nearest most, and drops back to zero.",
+ rest: "rest",
+ engine: plotEngine,
+ }, el, options);
+}
diff --git a/packages/hairline/src/intensity.ts b/packages/hairline/src/intensity.ts
index 673bbaf..e126557 100644
--- a/packages/hairline/src/intensity.ts
+++ b/packages/hairline/src/intensity.ts
@@ -7,7 +7,7 @@
* copy and its tests hold the two together.
*/
-export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches" | "vault" | "lockers" | "padlock" | "patch" | "dish" | "router";
+export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches" | "vault" | "lockers" | "padlock" | "patch" | "dish" | "router" | "loupe" | "sieve" | "rail" | "plug" | "query" | "drawer" | "basket" | "plot";
/** Each figure's number at intensity 0, 0.5 and 1. Slow's falls: a slower clock is a stronger answer. */
export const TABLE: Record<FigureId, readonly [number, number, number]> = {
@@ -30,6 +30,14 @@ export const TABLE: Record<FigureId, readonly [number, number, number]> = {
patch: [1, 2.5, 5], // radius, ports
dish: [30, 50, 70], // reach, degrees
router: [0.5, 1.5, 3], // spread, antennas
+ loupe: [1.3, 1.8, 2.6], // magnification, ×
+ sieve: [6, 14, 24], // gap, viewBox units
+ rail: [1, 2, 3.5], // radius, hangers
+ plug: [0.35, 0.6, 0.9], // pull, fraction of the way to the socket
+ query: [20, 40, 55], // turn, degrees; past 55 the hook folds over itself and stops reading as one
+ drawer: [12, 22, 34], // pull, viewBox units
+ basket: [8, 16, 28], // tilt, degrees
+ plot: [3, 6, 12], // lift, viewBox units
};
export const DEFAULT = 0.5;
diff --git a/packages/hairline/src/react.tsx b/packages/hairline/src/react.tsx
index 5fac56a..c749624 100644
--- a/packages/hairline/src/react.tsx
+++ b/packages/hairline/src/react.tsx
@@ -2,10 +2,10 @@ import {
forwardRef, useCallback, useEffect, useLayoutEffect, useRef,
type ComponentPropsWithoutRef, type ForwardRefExoticComponent, type RefAttributes,
} from "react";
-import { branches, cabinet, dish, elevator, exploded, keyboard, laptop, lockers, padlock, patch, phone, phosphor, riffle, router, slow, terminal, terrain, turntable, vault, type Figure, type HairlineOptions } from "./index";
+import { basket, branches, cabinet, dish, drawer, elevator, exploded, keyboard, laptop, lockers, loupe, padlock, patch, phone, phosphor, plot, plug, query, rail, riffle, router, sieve, slow, terminal, terrain, turntable, vault, type Figure, type HairlineOptions } from "./index";
/**
- * @lucasmarkes/hairline/react — the nineteen figures as components.
+ * @lucasmarkes/hairline/react — the twenty-seven figures as components.
*
* A component renders one empty `<div>` and mounts the figure on it in a
* layout effect, so on the server the box is there and the drawing is not.
@@ -83,6 +83,8 @@ export const Branches = make("Branches", branches);
export const Vault = make("Vault", vault);
/** A bank of twelve lockers, one ajar at rest: the locker under the pointer opens, and the one open before it swings shut. `intensity` opens the door wider. */
export const Lockers = make("Lockers", lockers);
+/** A stand loupe over a blank ruled sheet: the pointer drags it across, and the rules pass enlarged under the glass with nothing between them. `intensity` magnifies more. */
+export const Loupe = make("Loupe", loupe);
/** A padlock: as the pointer nears, the shackle springs up out of the body and swings open about its long leg. `intensity` swings the shackle further. */
export const Padlock = make("Padlock", padlock);
/** A patch panel of twenty-four ports: the cable under the pointer lifts, and its neighbours lean away, less the further away. `intensity` spreads the lean over more ports. */
@@ -91,3 +93,17 @@ export const Patch = make("Patch", patch);
export const Dish = make("Dish", dish);
/** A wifi router whose antennas lean toward the pointer, the nearest the most and the others less the further away. `intensity` spreads the lean over more antennas. */
export const Router = make("Router", router);
+/** Three test sieves stacked over a pan: the pointer's height picks one, it rises clear of the stack, and every mesh is bare. `intensity` opens the gap further. */
+export const Sieve = make("Sieve", sieve);
+/** A garment rail with seven bare hangers: the pointer brushes them, and each rocks away from it, the nearest most, and settles. `intensity` reaches more hangers. */
+export const Rail = make("Rail", rail);
+/** A wall socket and a plug lying on the floor at the end of its cord: the pointer draws the plug up toward the socket, and it stops short. `intensity` brings it nearer. */
+export const Plug = make("Plug", plug);
+/** A question mark built as a solid on a plinth, its dot a loose ball: the hook turns about its stem toward the pointer, and the ball rolls after it. `intensity` turns the hook further. */
+export const Query = make("Query", query);
+/** A filing cabinet of three drawers: the pointer's height picks one, it slides out, and inside are two dividers and nothing between them. `intensity` pulls the drawer further out. */
+export const Drawer = make("Drawer", drawer);
+/** An empty wire shopping basket under a bail handle: the pointer tilts it toward itself on a spring, so the bare floor shows, and the handle swings after it, late. `intensity` tilts it further. */
+export const Basket = make("Basket", basket);
+/** A bar chart with no data: seven flat tabs on its base, before a plate of grid lines. The pointer brushes them, and each lifts a little, the nearest most, and drops back to zero. `intensity` lifts them higher. */
+export const Plot = make("Plot", plot);
diff --git a/packages/hairline/test/browser/entry.ts b/packages/hairline/test/browser/entry.ts
index 4c3c196..b9eeb6f 100644
--- a/packages/hairline/test/browser/entry.ts
+++ b/packages/hairline/test/browser/entry.ts
@@ -4,7 +4,7 @@ import * as hairline from "../../src/index";
* The harness page's script: the package, on `window`, with one figure at a
* time on #host. Tests drive it through page.evaluate.
*/
-type Id = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches" | "vault" | "lockers" | "padlock" | "patch" | "dish" | "router";
+type Id = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches" | "vault" | "lockers" | "padlock" | "patch" | "dish" | "router" | "loupe" | "sieve" | "rail" | "plug" | "query" | "drawer" | "basket" | "plot";
type Loose = Record<string, unknown>;
type Mount = (el: HTMLElement, options?: Loose) => { update(o: Loose): void; destroy(): void };
diff --git a/packages/hairline/test/browser/figures.spec.ts b/packages/hairline/test/browser/figures.spec.ts
index c779f42..2de17a6 100644
--- a/packages/hairline/test/browser/figures.spec.ts
+++ b/packages/hairline/test/browser/figures.spec.ts
@@ -2,7 +2,7 @@ import { expect, test, type Page } from "@playwright/test";
/** The figures in a real browser: input, focus, reduced motion, shadow roots, a clean console. */
-const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches", "vault", "lockers", "padlock", "patch", "dish", "router"] as const;
+const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches", "vault", "lockers", "padlock", "patch", "dish", "router", "loupe", "sieve", "rail", "plug", "query", "drawer", "basket", "plot"] as const;
type Id = (typeof IDS)[number];
const mount = (page: Page, id: Id, options: Record<string, unknown> = {}) =>
diff --git a/packages/hairline/test/mount.test.ts b/packages/hairline/test/mount.test.ts
index ffcb8c4..0df936d 100644
--- a/packages/hairline/test/mount.test.ts
+++ b/packages/hairline/test/mount.test.ts
@@ -1,10 +1,10 @@
// @vitest-environment jsdom
import { describe, expect, it, vi } from "vitest";
import { frames, host, observers, pending } from "./dom";
-import { branches, cabinet, dish, elevator, exploded, keyboard, laptop, lockers, padlock, patch, phone, phosphor, riffle, router, slow, terminal, terrain, turntable, vault } from "../src/index";
+import { basket, branches, cabinet, dish, drawer, elevator, exploded, keyboard, laptop, lockers, loupe, padlock, patch, phone, phosphor, plot, plug, query, rail, riffle, router, sieve, slow, terminal, terrain, turntable, vault } from "../src/index";
import { css } from "../src/core/styles";
-const ALL = { riffle, terrain, exploded, phosphor, slow, turntable, keyboard, elevator, phone, laptop, terminal, cabinet, branches, vault, lockers, padlock, patch, dish, router };
+const ALL = { riffle, terrain, exploded, phosphor, slow, turntable, keyboard, elevator, phone, laptop, terminal, cabinet, branches, vault, lockers, padlock, patch, dish, router, loupe, sieve, rail, plug, query, drawer, basket, plot };
const key = (el: Element, k: string) => el.dispatchEvent(new KeyboardEvent("keydown", { key: k, bubbles: true, cancelable: true }));
describe("mount", () => {
@@ -92,6 +92,26 @@ describe("mount", () => {
const sheets = document.adoptedStyleSheets?.length ?? 0;
expect(sheets + document.querySelectorAll("style[data-hairline-style]").length).toBe(1);
});
+
+ // Review Focus 2 and 3: the new figures at both ends of the slider, with the pointer at the stage's corners, then gone
+ it.each(["loupe", "sieve", "rail", "plug", "query", "drawer", "basket", "plot"] as const)("%s stays whole at the corners and returns to rest", async (id) => {
+ for (const intensity of [0, 1]) {
+ const el = host(), reads: string[] = [];
+ const f = ALL[id](el, { intensity, onRead: (t) => reads.push(t) });
+ for (const [x, y] of [[0, 0], [400, 0], [0, 320], [400, 320], [200, 160]]) {
+ el.dispatchEvent(new MouseEvent("pointermove", { clientX: x, clientY: y, bubbles: true }));
+ frames(4);
+ }
+ expect(reads[reads.length - 1]).not.toBe("rest");
+ /* a mouse leaving acts on the next task; jsdom's MouseEvent has no pointerType of its own */
+ el.dispatchEvent(Object.assign(new MouseEvent("pointerleave"), { pointerType: "mouse" }));
+ await new Promise((r) => setTimeout(r, 0));
+ frames(240);
+ expect(reads[reads.length - 1]).toBe("rest");
+ expect(el.querySelector("svg")!.innerHTML).not.toMatch(/NaN|Infinity|undefined/);
+ f.destroy();
+ }
+ });
});
describe("options", () => {
@@ -151,10 +171,18 @@ describe("intensity", () => {
branches: [[200, 160], 8],
vault: [[260, 170], 2, [200, 230], 2, [140, 170], 2, [200, 110], 8],
lockers: [[200, 160], 8],
+ loupe: [[200, 170], 60],
padlock: [[200, 170], 60],
patch: [[200, 160], 8],
dish: [[300, 100], 12],
router: [[300, 120], 12],
+ sieve: [[200, 90], 80],
+ rail: [[200, 150], 12],
+ plug: [[140, 125], 60],
+ query: [[330, 120], 60],
+ drawer: [[200, 90], 60],
+ basket: [[90, 260], 60],
+ plot: [[200, 160], 6],
};
const svg = (el: Element) => el.querySelector("svg")!.innerHTML.replace(/hl-fd\d+/g, "hl-fd");
@@ -292,3 +320,337 @@ describe("teardown", () => {
expect(onRead).not.toHaveBeenCalled();
});
});
+
+describe("sieve", () => {
+ /* the sieves' silhouettes, bottom to top: the pan's is first */
+ const sils = (el: Element) => [...el.querySelectorAll("svg .sil")].slice(1) as SVGPathElement[];
+ /** The middle of a silhouette's box: for a drum, the point over its axis halfway up. */
+ const centre = (p: SVGPathElement): [number, number] => {
+ const n = p.getAttribute("d")!.match(/-?\d+(\.\d+)?/g)!.map(Number), xs = n.filter((_, i) => i % 2 === 0), ys = n.filter((_, i) => i % 2 === 1);
+ return [(Math.min(...xs) + Math.max(...xs)) / 2, (Math.min(...ys) + Math.max(...ys)) / 2];
+ };
+
+ it.each([0, 0.5, 1])("picks the sieve drawn under the pointer at rest, at intensity %s", (intensity) => {
+ const el = host(), onRead = vi.fn();
+ sieve(el, { intensity, onRead });
+ frames(2);
+ const at = sils(el).map(centre);
+ expect(at).toHaveLength(3);
+ for (const [i, [x, y]] of at.entries()) {
+ el.dispatchEvent(new MouseEvent("pointermove", { clientX: x, clientY: y, bubbles: true }));
+ expect(onRead).toHaveBeenLastCalledWith(`sieve ${3 - i} · 0`);
+ frames(60);
+ }
+ });
+
+ it("leaves a sieve alone while only the ones above it move", () => {
+ const el = host(), onRead = vi.fn();
+ sieve(el, { onRead });
+ frames(2);
+ const bottom = sils(el)[0], d = bottom.getAttribute("d"), set = vi.spyOn(bottom, "setAttribute");
+ el.dispatchEvent(new MouseEvent("pointermove", { clientX: 200, clientY: 90, bubbles: true }));
+ expect(onRead).toHaveBeenLastCalledWith("sieve 1 · 0");
+ frames(60);
+ expect(set).not.toHaveBeenCalled();
+ expect(bottom.getAttribute("d")).toBe(d);
+ });
+});
+
+describe("loupe", () => {
+ it("reads every row from the far rule to the near one", () => {
+ const el = host(), onRead = vi.fn();
+ loupe(el, { onRead });
+ for (let y = 0; y <= 320; y += 4) el.dispatchEvent(new MouseEvent("pointermove", { clientX: 200, clientY: y, bubbles: true }));
+ const rows = new Set(onRead.mock.calls.map((c) => c[0]));
+ expect([...rows].filter((t) => t !== "rest")).toEqual(["row 1 · 0", "row 2 · 0", "row 3 · 0", "row 4 · 0", "row 5 · 0", "row 6 · 0", "row 7 · 0"]);
+ });
+
+ it("redraws only what the glass shows when only the magnification changes", () => {
+ const el = host();
+ const f = loupe(el);
+ frames(2);
+ const paths = [...el.querySelectorAll("svg path")], seen = paths[paths.length - 1];
+ const sets = paths.map((p) => vi.spyOn(p, "setAttribute"));
+ f.update({ intensity: 1 });
+ frames(60);
+ for (const [i, set] of sets.entries()) {
+ if (paths[i] === seen) expect(set).toHaveBeenCalled();
+ else expect(set).not.toHaveBeenCalled();
+ }
+ });
+});
+
+describe("rail", () => {
+ /* the hangers' silhouettes, from the far end: after the far foot's and upright's, before the rail's */
+ const hangers = (el: Element) => [...el.querySelectorAll("svg .sil")].slice(2, 9) as SVGPathElement[];
+ const centre = (p: SVGPathElement): [number, number] => {
+ const n = p.getAttribute("d")!.match(/-?\d+(\.\d+)?/g)!.map(Number), xs = n.filter((_, i) => i % 2 === 0), ys = n.filter((_, i) => i % 2 === 1);
+ return [(Math.min(...xs) + Math.max(...xs)) / 2, (Math.min(...ys) + Math.max(...ys)) / 2];
+ };
+
+ it("reads each hanger as holding nothing, and gives the bright back to the rest one on leave", async () => {
+ const el = host(), onRead = vi.fn();
+ rail(el, { onRead });
+ frames(2);
+ const at = hangers(el).map(centre), lit = () => hangers(el).map((h) => h.classList.contains("hi"));
+ expect(at).toHaveLength(7);
+ expect(lit()).toEqual([false, false, false, true, false, false, false]);
+ for (const [i, p] of at.entries()) {
+ el.dispatchEvent(new MouseEvent("pointermove", { clientX: p[0], clientY: p[1], bubbles: true }));
+ expect(onRead).toHaveBeenLastCalledWith(`hanger ${i + 1} · 0`);
+ expect(lit().indexOf(true)).toBe(i);
+ frames(10);
+ }
+ el.dispatchEvent(Object.assign(new MouseEvent("pointerleave"), { pointerType: "mouse" }));
+ await new Promise((r) => setTimeout(r, 0));
+ frames(240);
+ expect(onRead).toHaveBeenLastCalledWith("rest");
+ expect(lit()).toEqual([false, false, false, true, false, false, false]);
+ });
+});
+
+describe("plot", () => {
+ /* the tabs' silhouettes, far to near: the base's and the plate's come first */
+ const tabs = (el: Element) => [...el.querySelectorAll("svg .sil")].slice(2) as SVGPathElement[];
+ const nums = (p: SVGPathElement) => p.getAttribute("d")!.match(/-?\d+(\.\d+)?/g)!.map(Number);
+ const top = (p: SVGPathElement) => Math.min(...nums(p).filter((_, i) => i % 2 === 1));
+ const centre = (p: SVGPathElement): [number, number] => {
+ const n = nums(p), xs = n.filter((_, i) => i % 2 === 0), ys = n.filter((_, i) => i % 2 === 1);
+ return [(Math.min(...xs) + Math.max(...xs)) / 2, (Math.min(...ys) + Math.max(...ys)) / 2];
+ };
+ const move = (el: Element, [x, y]: [number, number]) => el.dispatchEvent(new MouseEvent("pointermove", { clientX: x, clientY: y, bubbles: true }));
+
+ it("reads each tab as a bar holding zero, and gives the bright back to the proud one on leave", async () => {
+ const el = host(), onRead = vi.fn();
+ plot(el, { onRead });
+ frames(2);
+ const at = tabs(el).map(centre);
+ expect(at).toHaveLength(7);
+ expect(tabs(el).map((t) => t.classList.contains("hi"))).toEqual([false, false, false, false, true, false, false]);
+ for (const [i, p] of at.entries()) {
+ move(el, p);
+ expect(onRead).toHaveBeenLastCalledWith(`bar ${i + 1} · 0`);
+ expect(tabs(el).filter((t) => t.classList.contains("hi"))).toEqual([tabs(el)[i]]);
+ frames(10);
+ }
+ el.dispatchEvent(Object.assign(new MouseEvent("pointerleave"), { pointerType: "mouse" }));
+ await new Promise((r) => setTimeout(r, 0));
+ frames(240);
+ expect(onRead).toHaveBeenLastCalledWith("rest");
+ expect(tabs(el).map((t) => t.classList.contains("hi"))).toEqual([false, false, false, false, true, false, false]);
+ });
+
+ it("lifts the tab it brushes by the slider's 3 · 6 · 12, then drops it back to zero under a still pointer", () => {
+ const peaks: number[] = [];
+ for (const intensity of [0, 0.5, 1]) {
+ const el = host();
+ plot(el, { intensity });
+ frames(2);
+ const tab = tabs(el)[1], flat = tab.getAttribute("d"), y0 = top(tab);
+ move(el, centre(tab));
+ let peak = 0;
+ for (let k = 0; k < 60; k++) { frames(1); peak = Math.max(peak, y0 - top(tab)); }
+ frames(120);
+ expect(tab.getAttribute("d")).toBe(flat);
+ peaks.push(peak);
+ }
+ expect(peaks[0]).toBeGreaterThan(0);
+ expect(peaks[1] / peaks[0]).toBeCloseTo(2, 1);
+ expect(peaks[2] / peaks[0]).toBeCloseTo(4, 1);
+ });
+});
+
+describe("drawer", () => {
+ /* the drawers' fronts, bottom to top: the filled silhouettes after the plinth's and the carcass's, each followed by its pull's */
+ const fronts = (el: Element) => ([...el.querySelectorAll("svg .sil:not(.nf)")] as SVGPathElement[]).slice(2).filter((_, i) => i % 2 === 0);
+ const centre = (p: SVGPathElement): [number, number] => {
+ const n = p.getAttribute("d")!.match(/-?\d+(\.\d+)?/g)!.map(Number), xs = n.filter((_, i) => i % 2 === 0), ys = n.filter((_, i) => i % 2 === 1);
+ return [(Math.min(...xs) + Math.max(...xs)) / 2, (Math.min(...ys) + Math.max(...ys)) / 2];
+ };
+ const move = (el: Element, [x, y]: [number, number]) => el.dispatchEvent(new MouseEvent("pointermove", { clientX: x, clientY: y, bubbles: true }));
+
+ it.each([0, 0.5, 1])("picks the drawer drawn under the pointer at rest, at intensity %s, and finds it empty", (intensity) => {
+ const el = host(), onRead = vi.fn();
+ drawer(el, { intensity, onRead });
+ frames(2);
+ const at = fronts(el).map(centre);
+ expect(at).toHaveLength(3);
+ for (const [k, p] of at.entries()) {
+ move(el, p);
+ expect(onRead).toHaveBeenLastCalledWith(`drawer ${3 - k} · 0`);
+ frames(60);
+ expect(fronts(el).map((f, i) => f.classList.contains("hi") && i)).toEqual([0, 1, 2].map((i) => i === k && i));
+ }
+ });
+
+ /* A closed front on screen: its left edge is upright and its top falls half a unit for each unit across (the 2:1 view). */
+ it.each([0, 1, 2])("picks drawer %s from the bottom near its front's right end, in its lower third", (k) => {
+ const el = host(), onRead = vi.fn();
+ drawer(el, { onRead });
+ frames(2);
+ const n = fronts(el)[k].getAttribute("d")!.match(/-?\d+(\.\d+)?/g)!.map(Number), xs = n.filter((_, i) => i % 2 === 0), ys = n.filter((_, i) => i % 2 === 1);
+ const x0 = Math.min(...xs), w = Math.max(...xs) - x0, top = Math.min(...ys), h = Math.max(...ys) - top - w / 2;
+ move(el, [x0 + 0.85 * w, top + 0.85 * w / 2 + 0.75 * h]);
+ expect(onRead).toHaveBeenLastCalledWith(`drawer ${3 - k} · 0`);
+ });
+
+ it("draws again only the drawers that move, and takes the slider at rest", () => {
+ const el = host(), onRead = vi.fn();
+ const f = drawer(el, { onRead });
+ frames(2);
+ const [bottom, middle, top] = fronts(el), sets = [bottom, middle, top].map((p) => vi.spyOn(p, "setAttribute"));
+ move(el, centre(top));
+ frames(60);
+ expect(sets[0]).not.toHaveBeenCalled();
+ expect(sets[1]).toHaveBeenCalled();
+ expect(sets[2]).toHaveBeenCalled();
+ el.dispatchEvent(Object.assign(new MouseEvent("pointerleave"), { pointerType: "mouse" }));
+ return new Promise<void>((done) => setTimeout(() => {
+ frames(60);
+ const rest = middle.getAttribute("d");
+ f.update({ intensity: 1 });
+ frames(60);
+ expect(middle.getAttribute("d")).not.toBe(rest);
+ expect(onRead).toHaveBeenLastCalledWith("rest");
+ expect(el.querySelector("svg")!.innerHTML).not.toMatch(/NaN|Infinity|undefined/);
+ done();
+ }, 0));
+ });
+});
+
+describe("query", () => {
+ const move = (el: Element, x: number) => el.dispatchEvent(new MouseEvent("pointermove", { clientX: x, clientY: 160, bubbles: true }));
+
+ it.each([[0, 20], [0.5, 40], [1, 55]])("turns the hook as far as intensity %s allows, either way, and reads the turn to a zero", async (intensity, most) => {
+ const el = host(), onRead = vi.fn();
+ query(el, { intensity, onRead });
+ frames(2);
+ const rest = el.querySelector("svg")!.innerHTML;
+ move(el, 400);
+ expect(onRead).toHaveBeenLastCalledWith(`turn ${most}° · 0`);
+ move(el, 200);
+ expect(onRead).toHaveBeenLastCalledWith("turn 0° · 0");
+ move(el, 0);
+ expect(onRead).toHaveBeenLastCalledWith(`turn ${most}° · 0`);
+ frames(30);
+ expect(el.querySelector("svg")!.innerHTML).not.toBe(rest);
+ el.dispatchEvent(Object.assign(new MouseEvent("pointerleave"), { pointerType: "mouse" }));
+ await new Promise((r) => setTimeout(r, 0));
+ frames(300);
+ expect(onRead).toHaveBeenLastCalledWith("rest");
+ expect(el.querySelector("svg")!.innerHTML).toBe(rest);
+ });
+
+ it("rolls the ball after the hook has settled, and leaves the hook alone meanwhile", () => {
+ const el = host();
+ query(el, { intensity: 1 });
+ frames(2);
+ const paths = [...el.querySelectorAll("svg path")], ball = paths[2], bar = paths[paths.length - 1];
+ move(el, 400);
+ frames(80);
+ const b = vi.spyOn(ball, "setAttribute"), h = vi.spyOn(bar, "setAttribute");
+ frames(20);
+ expect(h).not.toHaveBeenCalled();
+ expect(b).toHaveBeenCalled();
+ });
+});
+
+describe("plug", () => {
+ /** The socket on screen: the middle of the path that holds its two holes. */
+ const socket = (el: Element): [number, number] => {
+ const n = el.querySelector('svg path[class="nf"]')!.getAttribute("d")!.match(/-?\d+(\.\d+)?/g)!.map(Number), xs = n.filter((_, i) => i % 2 === 0), ys = n.filter((_, i) => i % 2 === 1);
+ return [(Math.min(...xs) + Math.max(...xs)) / 2, (Math.min(...ys) + Math.max(...ys)) / 2];
+ };
+ const move = (el: Element, [x, y]: [number, number]) => el.dispatchEvent(new MouseEvent("pointermove", { clientX: x, clientY: y, bubbles: true }));
+ const leave = (el: Element) => el.dispatchEvent(Object.assign(new MouseEvent("pointerleave"), { pointerType: "mouse" }));
+
+ it("stops short of the socket at every pull, nearer the further the slider", () => {
+ const gaps = [0, 0.5, 1].map((intensity) => {
+ const el = host(), onRead = vi.fn();
+ plug(el, { intensity, onRead });
+ move(el, socket(el));
+ const m = /^gap (\d+) · 0 V$/.exec(onRead.mock.calls[onRead.mock.calls.length - 1][0]);
+ expect(m).not.toBeNull();
+ return Number(m![1]);
+ });
+ expect(gaps[0]).toBeGreaterThan(gaps[1]);
+ expect(gaps[1]).toBeGreaterThan(gaps[2]);
+ expect(gaps[2]).toBeGreaterThan(0);
+ });
+
+ it("closes the gap as the pointer goes from the plug to the socket, and no further than the pull", () => {
+ const el = host(), onRead = vi.fn();
+ plug(el, { onRead });
+ const [sx, sy] = socket(el), gaps: number[] = [];
+ for (let k = 0; k <= 10; k++) { move(el, [sx + (10 - k) * 9, sy + (10 - k) * 11]); gaps.push(Number(/\d+/.exec(onRead.mock.calls[onRead.mock.calls.length - 1][0])![0])); }
+ for (let k = 1; k < gaps.length; k++) expect(gaps[k]).toBeLessThanOrEqual(gaps[k - 1]);
+ expect(gaps[0]).toBeGreaterThan(gaps[10]);
+ expect(gaps.slice(-3)).toEqual([gaps[10], gaps[10], gaps[10]]);
+ });
+
+ it("takes the slider at rest and engaged, leaves the plate alone, and lies back down on leaving", async () => {
+ const el = host(), onRead = vi.fn();
+ const f = plug(el, { onRead });
+ frames(2);
+ const rest = el.querySelector("svg")!.innerHTML, plate = el.querySelector("svg .sil")!, set = vi.spyOn(plate, "setAttribute");
+ f.update({ intensity: 1 });
+ frames(60);
+ expect(el.querySelector("svg")!.innerHTML).toBe(rest);
+ expect(onRead).toHaveBeenLastCalledWith("rest");
+ move(el, socket(el));
+ const near = onRead.mock.calls[onRead.mock.calls.length - 1][0];
+ f.update({ intensity: 0 });
+ expect(onRead.mock.calls[onRead.mock.calls.length - 1][0]).not.toBe(near);
+ for (const p of [[0, 0], [400, 0], [0, 320], [400, 320]] as const) { move(el, [...p]); frames(4); }
+ leave(el);
+ await new Promise((r) => setTimeout(r, 0));
+ frames(240);
+ expect(onRead).toHaveBeenLastCalledWith("rest");
+ expect(el.querySelector("svg")!.innerHTML).toBe(rest);
+ expect(set).not.toHaveBeenCalled();
+ expect(rest).not.toMatch(/NaN|Infinity|undefined/);
+ });
+});
+
+describe("basket", () => {
+ const move = (el: Element, x: number, y: number) => el.dispatchEvent(new MouseEvent("pointermove", { clientX: x, clientY: y, bubbles: true }));
+ const last = (fn: ReturnType<typeof vi.fn>) => fn.mock.calls[fn.mock.calls.length - 1][0];
+
+ it.each([[0, 8], [0.5, 16], [1, 28]])("tilts toward the pointer by the slider's %s, %s° at most, and lies level again on leaving", async (intensity, most) => {
+ const el = host(), onRead = vi.fn();
+ basket(el, { intensity, onRead });
+ frames(2);
+ const rest = el.querySelector("svg")!.innerHTML;
+ move(el, 200, 320);
+ expect(onRead).toHaveBeenLastCalledWith(`tilt ${most}° · 0`);
+ frames(30);
+ expect(el.querySelector("svg")!.innerHTML).not.toBe(rest);
+ /* tipped away from the camera it goes half as far, so the mouth stays open to it */
+ move(el, 200, 0);
+ expect(Number(/\d+/.exec(last(onRead))![0])).toBeLessThan(most);
+ move(el, 200, 166);
+ expect(last(onRead)).toMatch(/^tilt \d+° · 0$/);
+ el.dispatchEvent(Object.assign(new MouseEvent("pointerleave"), { pointerType: "mouse" }));
+ await new Promise((r) => setTimeout(r, 0));
+ frames(240);
+ expect(onRead).toHaveBeenLastCalledWith("rest");
+ expect(el.querySelector("svg")!.innerHTML).toBe(rest);
+ });
+
+ it("takes the slider at rest without redrawing, and engaged at once", () => {
+ const el = host(), onRead = vi.fn();
+ const f = basket(el, { onRead });
+ frames(2);
+ const sets = [...el.querySelectorAll("svg path")].map((p) => vi.spyOn(p, "setAttribute"));
+ f.update({ intensity: 1 });
+ frames(60);
+ for (const set of sets) expect(set).not.toHaveBeenCalled();
+ move(el, 200, 320);
+ expect(onRead).toHaveBeenLastCalledWith("tilt 28° · 0");
+ f.update({ intensity: 0 });
+ expect(onRead).toHaveBeenLastCalledWith("tilt 8° · 0");
+ frames(120);
+ expect(el.querySelector("svg")!.innerHTML).not.toMatch(/NaN|Infinity|undefined/);
+ });
+});
+
diff --git a/packages/hairline/test/react.test.tsx b/packages/hairline/test/react.test.tsx
index 98dd850..13fc382 100644
--- a/packages/hairline/test/react.test.tsx
+++ b/packages/hairline/test/react.test.tsx
@@ -3,7 +3,7 @@ import { StrictMode, createRef } from "react";
import { cleanup, render } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { frames, observers, pending } from "./dom";
-import { Branches, Cabinet, Dish, Elevator, Exploded, Keyboard, Laptop, Lockers, Padlock, Patch, Phone, Phosphor, Riffle, Router, Slow, Terminal, Terrain, Turntable, Vault } from "../src/react";
+import { Basket, Branches, Cabinet, Dish, Drawer, Elevator, Exploded, Keyboard, Laptop, Lockers, Loupe, Padlock, Patch, Phone, Phosphor, Plot, Plug, Query, Rail, Riffle, Router, Sieve, Slow, Terminal, Terrain, Turntable, Vault } from "../src/react";
afterEach(cleanup);
@@ -17,9 +17,9 @@ const svg = (el: Element) => el.querySelector("svg")!.innerHTML.replace(/hl-fd\d
describe("components", () => {
it("renders each figure into one div", () => {
- const { container } = render(<><Riffle /><Terrain /><Exploded /><Phosphor /><Slow /><Turntable /><Keyboard /><Elevator /><Phone /><Laptop /><Terminal /><Cabinet /><Branches /><Vault /><Lockers /><Padlock /><Patch /><Dish /><Router /></>);
+ const { container } = render(<><Riffle /><Terrain /><Exploded /><Phosphor /><Slow /><Turntable /><Keyboard /><Elevator /><Phone /><Laptop /><Terminal /><Cabinet /><Branches /><Vault /><Lockers /><Padlock /><Patch /><Dish /><Router /><Loupe /><Sieve /><Rail /><Plug /><Query /><Drawer /><Basket /><Plot /></>);
const ids = [...container.children].map((el) => el.getAttribute("data-hairline"));
- expect(ids).toEqual(["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches", "vault", "lockers", "padlock", "patch", "dish", "router"]);
+ expect(ids).toEqual(["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches", "vault", "lockers", "padlock", "patch", "dish", "router", "loupe", "sieve", "rail", "plug", "query", "drawer", "basket", "plot"]);
for (const el of container.children) expect(el.querySelectorAll(":scope > svg")).toHaveLength(1);
});
@@ -118,7 +118,7 @@ describe("components", () => {
});
it("names the components for the dev tools", () => {
- expect([Riffle, Terrain, Exploded, Phosphor, Slow, Turntable, Keyboard, Elevator, Phone, Laptop, Terminal, Cabinet, Branches, Vault, Lockers, Padlock, Patch, Dish, Router].map((c) => c.displayName))
- .toEqual(["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard", "Elevator", "Phone", "Laptop", "Terminal", "Cabinet", "Branches", "Vault", "Lockers", "Padlock", "Patch", "Dish", "Router"]);
+ expect([Riffle, Terrain, Exploded, Phosphor, Slow, Turntable, Keyboard, Elevator, Phone, Laptop, Terminal, Cabinet, Branches, Vault, Lockers, Padlock, Patch, Dish, Router, Loupe, Sieve, Rail, Plug, Query, Drawer, Basket, Plot].map((c) => c.displayName))
+ .toEqual(["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard", "Elevator", "Phone", "Laptop", "Terminal", "Cabinet", "Branches", "Vault", "Lockers", "Padlock", "Patch", "Dish", "Router", "Loupe", "Sieve", "Rail", "Plug", "Query", "Drawer", "Basket", "Plot"]);
});
});
diff --git a/packages/hairline/test/types.test-d.tsx b/packages/hairline/test/types.test-d.tsx
index 12fd9f6..00f2377 100644
--- a/packages/hairline/test/types.test-d.tsx
+++ b/packages/hairline/test/types.test-d.tsx
@@ -4,10 +4,10 @@
* an error. Vitest does not pick it up (it is not a `.test.` file).
*/
import { createRef } from "react";
-import { branches, cabinet, dish, elevator, exploded, keyboard, laptop, lockers, padlock, patch, phone, phosphor, riffle, router, slow, terminal, terrain, turntable, vault, type Figure, type HairlineOptions } from "../src/index";
+import { basket, branches, cabinet, dish, drawer, elevator, exploded, keyboard, laptop, lockers, loupe, padlock, patch, phone, phosphor, plot, plug, query, rail, riffle, router, sieve, slow, terminal, terrain, turntable, vault, type Figure, type HairlineOptions } from "../src/index";
import * as vanilla from "../src/index";
import * as components from "../src/react";
-import { Branches, Cabinet, Dish, Elevator, Exploded, Keyboard, Laptop, Lockers, Padlock, Patch, Phone, Phosphor, Riffle, Router, Slow, Terminal, Terrain, Turntable, Vault, type HairlineProps } from "../src/react";
+import { Basket, Branches, Cabinet, Dish, Drawer, Elevator, Exploded, Keyboard, Laptop, Lockers, Loupe, Padlock, Patch, Phone, Phosphor, Plot, Plug, Query, Rail, Riffle, Router, Sieve, Slow, Terminal, Terrain, Turntable, Vault, type HairlineProps } from "../src/react";
declare const el: HTMLElement;
type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
@@ -16,7 +16,7 @@ const yes = <T extends true>() => {};
/* every figure takes the same options */
riffle(el, { intensity: 0.8, theme: "dark", label: "Cards", onRead: (t: string) => t });
riffle(el);
-for (const mount of [riffle, terrain, exploded, phosphor, slow, turntable, keyboard, elevator, phone, laptop, terminal, cabinet, branches, vault, lockers, padlock, patch, dish, router]) {
+for (const mount of [riffle, terrain, exploded, phosphor, slow, turntable, keyboard, elevator, phone, laptop, terminal, cabinet, branches, vault, lockers, padlock, patch, dish, router, loupe, sieve, rail, plug, query, drawer, basket, plot]) {
yes<Equal<typeof mount, (el: HTMLElement, options?: HairlineOptions) => Figure>>();
// @ts-expect-error the old per-figure options are gone
mount(el, { stagger: 60 });
@@ -46,8 +46,8 @@ f.update({ stagger: 60 });
f.update({ bands: true });
/* the entries export the functions, the components and three types, and nothing of the old API */
-yes<Equal<keyof typeof vanilla, "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches" | "vault" | "lockers" | "padlock" | "patch" | "dish" | "router">>();
-yes<Equal<keyof typeof components, "Riffle" | "Terrain" | "Exploded" | "Phosphor" | "Slow" | "Turntable" | "Keyboard" | "Elevator" | "Phone" | "Laptop" | "Terminal" | "Cabinet" | "Branches" | "Vault" | "Lockers" | "Padlock" | "Patch" | "Dish" | "Router">>();
+yes<Equal<keyof typeof vanilla, "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches" | "vault" | "lockers" | "padlock" | "patch" | "dish" | "router" | "loupe" | "sieve" | "rail" | "plug" | "query" | "drawer" | "basket" | "plot">>();
+yes<Equal<keyof typeof components, "Riffle" | "Terrain" | "Exploded" | "Phosphor" | "Slow" | "Turntable" | "Keyboard" | "Elevator" | "Phone" | "Laptop" | "Terminal" | "Cabinet" | "Branches" | "Vault" | "Lockers" | "Padlock" | "Patch" | "Dish" | "Router" | "Loupe" | "Sieve" | "Rail" | "Plug" | "Query" | "Drawer" | "Basket" | "Plot">>();
// @ts-expect-error ranges is gone
void vanilla.ranges;
// @ts-expect-error the per-figure option types are gone
@@ -60,7 +60,7 @@ const ref = createRef<HTMLDivElement>();
<Riffle ref={ref} intensity={0.8} theme="dark" className="w-80" id="cards" onClick={() => {}} onRead={(text) => text.length} />;
<Terrain style={{ width: 320 }} aria-label="Dunes" data-x="1" />;
<Riffle />;
-for (const C of [Riffle, Terrain, Exploded, Phosphor, Slow, Turntable, Keyboard, Elevator, Phone, Laptop, Terminal, Cabinet, Branches, Vault, Lockers, Padlock, Patch, Dish, Router]) {
+for (const C of [Riffle, Terrain, Exploded, Phosphor, Slow, Turntable, Keyboard, Elevator, Phone, Laptop, Terminal, Cabinet, Branches, Vault, Lockers, Padlock, Patch, Dish, Router, Loupe, Sieve, Rail, Plug, Query, Drawer, Basket, Plot]) {
// @ts-expect-error the old per-figure options are gone
<C stagger={60} />;
// @ts-expect-error the old per-figure options are gone
diff --git a/scripts/consumers.mjs b/scripts/consumers.mjs
index db55beb..96e524b 100644
--- a/scripts/consumers.mjs
+++ b/scripts/consumers.mjs
@@ -22,7 +22,7 @@ const { chromium } = createRequire(join(PKG, "package.json"))("@playwright/test"
const FIXTURES = {
next: { dir: "fixtures/next-app", port: 4311, serve: (port) => ["npx", ["next", "start", "-p", String(port)]], figures: ["riffle", "slow", "phosphor"] },
- vite: { dir: "fixtures/vite-vanilla", port: 4312, serve: (port) => ["npx", ["vite", "preview", "--port", String(port), "--strictPort"]], figures: ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches", "vault", "lockers", "padlock", "patch", "dish", "router"] },
+ vite: { dir: "fixtures/vite-vanilla", port: 4312, serve: (port) => ["npx", ["vite", "preview", "--port", String(port), "--strictPort"]], figures: ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches", "vault", "lockers", "padlock", "patch", "dish", "router", "loupe", "sieve", "rail", "plug", "query", "drawer", "basket", "plot"] },
};
const only = process.argv[2];
if (only && !FIXTURES[only]) { console.error(`Unknown fixture "${only}". Use: ${Object.keys(FIXTURES).join(" | ")}`); process.exit(2); }