Isometric line figures that answer the pointer. For React and for anything with a DOM.
Security: a vault door whose dial coasts and catches, a bank of lockers that swing open one at a time, and a padlock whose shackle springs up as the pointer nears
Lucas Marques79de46d12101
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5e9055c..4b4828b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -29,6 +29,15 @@ Every release of `@lucasmarkes/hairline`. The format follows- `branches` and `Branches`: a commit graph on a board. The commit under thepointer rises, and its history rises after it, the farther back the less. Astronger `intensity` raises more of the history.+- `vault` and `Vault`: a vault door. Circling the pointer turns its dial,+ which coasts and catches every ten; on forty its three bolts draw back. A+ stronger `intensity` lets the dial coast longer.+- `lockers` and `Lockers`: a bank of twelve lockers, one ajar at rest. The+ locker under the pointer opens, and the one open before it swings shut. A+ stronger `intensity` opens the door wider.+- `padlock` and `Padlock`: a padlock. As the pointer nears, the shackle+ springs up out of the body and swings open about its long leg. A stronger+ `intensity` swings the shackle further.## 0.1.0 - 2026-10-01diff --git a/README.md b/README.mdindex 5d6a00a..9bddc74 100644--- a/README.md+++ b/README.md@@ -1,6 +1,6 @@# hairline-Thirteen isometric line figures that answer the pointer. For React and for anything with a DOM.+Sixteen isometric line figures that answer the pointer. For React and for anything with a DOM.[](https://www.npmjs.com/package/@lucasmarkes/hairline)[](https://github.com/lucasmarkes/hairline/actions/workflows/ci.yml)@@ -68,6 +68,9 @@ A figure draws into the element you give it, at the element's width and a 5:4 as| `terminal` | `Terminal` | A terminal window with its history in rows. The pointer's height scrolls back; the line under it lifts and its neighbours follow. | The lift spreads further. || `cabinet` | `Cabinet` | A rack of twelve blades, a few half out. The pointer's height pulls the nearest ones out, the farther the less. | More blades come out. || `branches` | `Branches` | A commit graph with a branch forking off main and merging back. The commit under the pointer rises, and its history rises after it. | More of the history rises. |+| `vault` | `Vault` | A vault door with a dial and three bolts. The pointer turns the dial; detents catch every ten, and on the combination the bolts draw back. | The dial coasts longer. |+| `lockers` | `Lockers` | A bank of twelve lockers, one ajar at rest. The locker under the pointer opens; the one at rest closes. | The door opens wider. |+| `padlock` | `Padlock` | A padlock with its shackle in. As the pointer comes near the shackle lifts out and swings open. | The shackle swings further. |## Options@@ -111,7 +114,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 thirteen 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 sixteen above, as one HTML file.```shnpx skills add lucasmarkes/hairlinediff --git a/apps/site/app/docs/sections.tsx b/apps/site/app/docs/sections.tsxindex a79123b..dcbd060 100644--- a/apps/site/app/docs/sections.tsx+++ b/apps/site/app/docs/sections.tsx@@ -1,5 +1,5 @@import type { ReactNode } from "react";-import { Branches, Cabinet, Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terminal, Terrain, Turntable } from "@lucasmarkes/hairline/react";+import { Branches, Cabinet, Elevator, Exploded, Keyboard, Laptop, Lockers, Padlock, Phone, Phosphor, Riffle, Slow, Terminal, Terrain, Turntable, Vault } from "@lucasmarkes/hairline/react";import { Anchor } from "@/components/anchor";import { CodeBlock } from "@/components/code-block";import { Install } from "@/components/install";@@ -8,7 +8,7 @@ import { SECTIONS } from "@/lib/docs";import { COUNT, FIGURES, INTENSITY, OPTIONS, THEME, measure } from "@/lib/figures";import { PACKAGE } from "@/lib/snippets";-const SMALL = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard, elevator: Elevator, phone: Phone, laptop: Laptop, terminal: Terminal, cabinet: Cabinet, branches: Branches };+const SMALL = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard, elevator: Elevator, phone: Phone, laptop: Laptop, terminal: Terminal, cabinet: Cabinet, branches: Branches, vault: Vault, lockers: Lockers, padlock: Padlock };/** A section takes its title from SECTIONS, the list the rail reads, so the two always agree. Its link copies from beside its title. */function Section({ id, children }: { id: string; children: ReactNode }) {diff --git a/apps/site/components/catalogue.tsx b/apps/site/components/catalogue.tsxindex d877c5b..b2f47b5 100644--- a/apps/site/components/catalogue.tsx+++ b/apps/site/components/catalogue.tsx@@ -1,12 +1,12 @@"use client";import { useCallback, useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ReactNode } from "react";-import { Branches, Cabinet, Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terminal, Terrain, Turntable } from "@lucasmarkes/hairline/react";+import { Branches, Cabinet, Elevator, Exploded, Keyboard, Laptop, Lockers, Padlock, Phone, Phosphor, Riffle, Slow, Terminal, Terrain, Turntable, Vault } from "@lucasmarkes/hairline/react";import { ENTRIES, SHELVES, type Entry, type Shelf, type ShelfId } from "@/lib/catalogue";import { LINKS, type FigureId } from "@/lib/figures";import { Tabs, type Tab } from "./tabs";-const COMPONENTS: Record<FigureId, typeof Riffle> = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard, elevator: Elevator, phone: Phone, laptop: Laptop, terminal: Terminal, cabinet: Cabinet, branches: Branches };+const COMPONENTS: Record<FigureId, typeof Riffle> = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard, elevator: Elevator, phone: Phone, laptop: Laptop, terminal: Terminal, cabinet: Cabinet, branches: Branches, vault: Vault, lockers: Lockers, padlock: Padlock };type Filter = "all" | ShelfId;diff --git a/apps/site/components/reel.tsx b/apps/site/components/reel.tsxindex e543e19..a2ffb33 100644--- a/apps/site/components/reel.tsx+++ b/apps/site/components/reel.tsx@@ -1,10 +1,10 @@"use client";import { useEffect, useRef, useState, type CSSProperties } from "react";-import { Branches, Cabinet, Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terminal, Terrain, Turntable } from "@lucasmarkes/hairline/react";+import { Branches, Cabinet, Elevator, Exploded, Keyboard, Laptop, Lockers, Padlock, Phone, Phosphor, Riffle, Slow, Terminal, Terrain, Turntable, Vault } from "@lucasmarkes/hairline/react";import { FIGURES } from "@/lib/figures";-const COMPONENTS = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard, elevator: Elevator, phone: Phone, laptop: Laptop, terminal: Terminal, cabinet: Cabinet, branches: Branches };+const COMPONENTS = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard, elevator: Elevator, phone: Phone, laptop: Laptop, terminal: Terminal, cabinet: Cabinet, branches: Branches, vault: Vault, lockers: Lockers, padlock: Padlock };/*** One pass of a pointer over each figure, in its viewBox (400 × 320): [x, y, ms]. Each path does the@@ -24,6 +24,9 @@ const DEMO: Record<keyof typeof COMPONENTS, [number, number, number][]> = {terminal: [[200, 250, 0], [200, 90, 1500], [200, 170, 3300]],cabinet: [[200, 250, 0], [200, 120, 1600], [200, 200, 3300]],branches: [[170, 192, 0], [124, 112, 1800], [332, 216, 3400]],+ vault: [[214, 187, 0], [207, 216, 1100], [207, 216, 2300], [214, 187, 3400]],+ lockers: [[200, 160, 0], [250, 230, 1800], [120, 110, 3200]],+ padlock: [[40, 280, 0], [200, 170, 1500], [330, 100, 3000]],};/** Long enough for the slowest dissolve (the reel's own, 520ms) to finish before its leaver goes. */diff --git a/apps/site/lib/catalogue.ts b/apps/site/lib/catalogue.tsindex 0ae55fd..2a791ca 100644--- a/apps/site/lib/catalogue.ts+++ b/apps/site/lib/catalogue.ts@@ -58,9 +58,9 @@ export const SHELVES: Shelf[] = [},{id: "security", title: "Security", color: "#ef4444", figures: [- planned("vault", "Vault", "A vault door with a dial and three bolts. The pointer turns the dial; detents catch every ten, and on the combination the bolts draw back.", "The dial coasts longer."),- planned("lockers", "Lockers", "A bank of twelve lockers, one ajar at rest. The locker under the pointer opens; the one at rest closes.", "The door opens wider."),- planned("padlock", "Padlock", "A padlock with its shackle in. As the pointer comes near the shackle lifts out and swings open.", "The shackle swings further."),+ drawn("vault"),+ drawn("lockers"),+ drawn("padlock"),],},{diff --git a/apps/site/lib/figures.ts b/apps/site/lib/figures.tsindex ed25feb..e25d737 100644--- a/apps/site/lib/figures.ts+++ b/apps/site/lib/figures.ts@@ -8,7 +8,7 @@import { spell } from "./words";-export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches";+export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches" | "vault" | "lockers" | "padlock";export type FigureDoc = {id: FigureId;@@ -113,9 +113,30 @@ export const FIGURES: FigureDoc[] = [stronger: "More of the history rises.",parameter: { name: "reach", unit: "commits" },},+ {+ id: "vault",+ name: "Vault",+ summary: "A vault door with a dial and three bolts. The pointer turns the dial; detents catch every ten, and on the combination the bolts draw back.",+ stronger: "The dial coasts longer.",+ parameter: { name: "coast", unit: "ms" },+ },+ {+ id: "lockers",+ name: "Lockers",+ summary: "A bank of twelve lockers, one ajar at rest. The locker under the pointer opens; the one at rest closes.",+ stronger: "The door opens wider.",+ parameter: { name: "opening", unit: "degrees" },+ },+ {+ id: "padlock",+ name: "Padlock",+ summary: "A padlock with its shackle in. As the pointer comes near the shackle lifts out and swings open.",+ stronger: "The shackle swings further.",+ parameter: { name: "swing", unit: "degrees" },+ },];-/** How many figures the package has, as the prose writes it: "thirteen". */+/** How many figures the package has, as the prose writes it: "sixteen". */export const COUNT = spell(FIGURES.length);/** Each figure's number at intensity 0, 0.5 and 1: a copy of the package's table. */@@ -133,6 +154,9 @@ export const INTENSITY: Record<FigureId, readonly [number, number, number]> = {terminal: [1, 2, 3.5],cabinet: [1.5, 3, 5],branches: [1, 3, 6],+ vault: [250, 600, 1500],+ lockers: [55, 90, 120],+ padlock: [45, 90, 100],};/** A number with its unit, as the docs' table and /llms.txt write it: "40 ms", "0.2× normal speed". */diff --git a/apps/site/test/figures.spec.ts b/apps/site/test/figures.spec.tsindex cbab504..034798b 100644--- a/apps/site/test/figures.spec.ts+++ b/apps/site/test/figures.spec.ts@@ -16,21 +16,21 @@ function watch(page: Page): string[] {const tiles = (page: Page) => page.locator(".fig-tile");const shelf = (page: Page, name: string) => page.locator(".shelves .shelf", { hasText: name });-test("/figures prerenders thirteen empty boxes among nineteen tiles, then draws them with a clean console", async ({ page, request }) => {+test("/figures prerenders sixteen empty boxes among nineteen tiles, then draws them with a clean console", async ({ page, request }) => {const html = await (await request.get("/figures")).text();- expect(html.match(/<div style="aspect-ratio:5 \/ 4"><\/div>/g)).toHaveLength(13);+ expect(html.match(/<div style="aspect-ratio:5 \/ 4"><\/div>/g)).toHaveLength(16);expect(html.match(/class="fig-tile"/g)).toHaveLength(19);- expect(html.match(/class="fig-tile" data-planned=""/g)).toHaveLength(6);+ expect(html.match(/class="fig-tile" data-planned=""/g)).toHaveLength(3);const noise = watch(page);await page.goto("/figures");await expect(tiles(page)).toHaveCount(19);- await expect(page.locator(".fig-tile [data-hairline] > svg")).toHaveCount(13);- await expect(page.locator(".fig-tile .fig-ghost")).toHaveCount(6);+ await expect(page.locator(".fig-tile [data-hairline] > svg")).toHaveCount(16);+ await expect(page.locator(".fig-tile .fig-ghost")).toHaveCount(3);await expect(page.locator("h1")).toHaveText("Every figure, by what it draws.");await expect(page.locator(".doc-section h2")).toHaveText(SHELVES);await expect(page.locator(".fig-name").first()).toHaveAccessibleName("Exploded");- await expect(page.locator(".fig-tile[data-planned] .fig-name").first()).toHaveAccessibleName("Vault, planned");+ await expect(page.locator(".fig-tile[data-planned] .fig-name").first()).toHaveAccessibleName("Patch, planned");expect(noise).toEqual([]);});@@ -122,13 +122,13 @@ test("picking a figure opens the drawer: the figure large, the slider, what it rtest("a planned figure's drawer has its outline and a link to ask for it, and no code", async ({ page }) => {await page.goto("/figures");- await page.locator(".fig-name", { hasText: "Vault" }).click();+ await page.locator(".fig-name", { hasText: "Patch" }).click();const drawer = page.locator("#figure-drawer");await expect(drawer).toHaveAttribute("data-open", "");await expect(drawer.locator(".detail-tag")).toHaveText("planned");await expect(drawer.locator(".fig-ghost")).toHaveCount(1);await expect(drawer.locator(".code, input[type=range]")).toHaveCount(0);- await expect(drawer.getByRole("link", { name: "Request on GitHub" })).toHaveAttribute("href", "https://github.com/lucasmarkes/hairline/issues/new?title=Figure%3A%20Vault");+ await expect(drawer.getByRole("link", { name: "Request on GitHub" })).toHaveAttribute("href", "https://github.com/lucasmarkes/hairline/issues/new?title=Figure%3A%20Patch");await drawer.locator(".detail-close").click();await expect(drawer).not.toHaveAttribute("data-open");});diff --git a/apps/site/test/site.spec.ts b/apps/site/test/site.spec.tsindex d94c622..476d1ca 100644--- a/apps/site/test/site.spec.ts+++ b/apps/site/test/site.spec.ts@@ -1,6 +1,6 @@import { expect, test, type Page } from "@playwright/test";-const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches"];+const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches", "vault", "lockers", "padlock"];const MANAGERS = [["npm", "npm i @lucasmarkes/hairline"],["pnpm", "pnpm add @lucasmarkes/hairline"],@@ -288,9 +288,9 @@ const BASE = "http://localhost:3000";test("a pasted link shows the page it leads to: each page's card has its own title, text and address", async ({ request }) => {const CARDS = [- ["/", "hairline", /^Thirteen isometric line figures/],+ ["/", "hairline", /^Sixteen isometric line figures/],["/figures", "Figures", /^Seven shelves, nineteen figures, grouped by what they draw/],- ["/docs", "Docs", /^Thirteen isometric line figures/],+ ["/docs", "Docs", /^Sixteen isometric line figures/],["/skill", "Make your own figure", /^hairline-create is a skill/],["/inspo", "How Hairline was made", /^A long brief/],] as const;diff --git a/fixtures/vite-vanilla/index.html b/fixtures/vite-vanilla/index.htmlindex b69f423..1eed51d 100644--- a/fixtures/vite-vanilla/index.html+++ b/fixtures/vite-vanilla/index.html@@ -24,6 +24,9 @@<div id="terminal"></div><div id="cabinet"></div><div id="branches"></div>+ <div id="vault"></div>+ <div id="lockers"></div>+ <div id="padlock"></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.tsindex 710023c..cb6ab07 100644--- a/fixtures/vite-vanilla/src/main.ts+++ b/fixtures/vite-vanilla/src/main.ts@@ -1,6 +1,6 @@-import { branches, cabinet, elevator, exploded, keyboard, laptop, phone, phosphor, riffle, slow, terminal, terrain, turntable, type Figure } from "@lucasmarkes/hairline";+import { branches, cabinet, elevator, exploded, keyboard, laptop, lockers, padlock, phone, phosphor, riffle, slow, terminal, terrain, turntable, vault, type Figure } from "@lucasmarkes/hairline";-/** No framework: thirteen elements, thirteen calls. */+/** No framework: sixteen elements, sixteen calls. */const el = (id: string) => document.getElementById(id)!;const read = el("read");@@ -20,5 +20,8 @@ laptop(el("laptop"));terminal(el("terminal"));cabinet(el("cabinet"));branches(el("branches"));+vault(el("vault"));+lockers(el("lockers"));+padlock(el("padlock"));cards.update({ intensity: 0.8 });diff --git a/package.json b/package.jsonindex 418d6f7..7c98aab 100644--- a/package.json+++ b/package.json@@ -2,7 +2,7 @@"name": "hairline-monorepo","version": "0.0.0","private": true,- "description": "Thirteen isometric line figures that answer the pointer",+ "description": "Sixteen isometric line figures that answer the pointer","packageManager": "[email protected]","engines": {"node": ">=22"diff --git a/packages/hairline/package.json b/packages/hairline/package.jsonindex 793c26d..92273e5 100644--- a/packages/hairline/package.json+++ b/packages/hairline/package.json@@ -1,7 +1,7 @@{"name": "@lucasmarkes/hairline","version": "0.2.0",- "description": "Thirteen isometric line figures that answer the pointer. For React and for anything with a DOM.",+ "description": "Sixteen 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": "19.9 kB"+ "limit": "23.8 kB"},{"name": "vanilla, one figure","path": "dist/index.js","import": "{ terrain }",- "limit": "5.4 kB"+ "limit": "5.6 kB"},{"name": "react, every component","path": "dist/react.js",- "limit": "20.3 kB",+ "limit": "24.1 kB","ignore": ["react","react/jsx-runtime"diff --git a/packages/hairline/src/figures/lockers.ts b/packages/hairline/src/figures/lockers.tsnew file mode 100644index 0000000..15b6f2f--- /dev/null+++ b/packages/hairline/src/figures/lockers.ts@@ -0,0 +1,153 @@+import { Cam, clamp, facing, fit, hull, poly, prism, proj, rad, rings, rrect, seg, type Ring, type Vec2, type Vec3 } from "../core/iso";+import { tdone, tset, tval, tween, type Tween } from "../core/motion";+import { disposer, mk, pointer, put, register, solid, type FigureMount } from "../core/stage";++/**+ * Lockers: a bank of twelve, six across and two high, standing on a plinth.+ * Each door is a thin steel plate with louvred vents, a blank number plate and+ * a latch cup on its free edge, hung on a hinge down its left side. The pointer+ * is put on the closed door faces; the locker under it swings its door open on+ * the 700ms curve, and the one open before it swings shut on the same clock.+ * An opening shows the locker's inside: its floor and shelf running back along+ * the inner wall. At rest, one door stands ajar, bright. The slider is how far+ * a door opens, in degrees.+ *+ * The pattern: one of many. A tween per door, a hit test on the plane of the+ * closed doors, and each door drawn every frame as a plate turned on its hinge.+ */++const COLS = 6, ROWS = 2, W = 24, HR = 38, GAP = 1.2, FM = 3, ZP = 6, D = 26, T = 1.4, DEP = 23;+const BW = COLS * W + 2 * FM, BH = ROWS * HR + 2 * FM, DW = W - 2 * GAP, DH = HR - 2 * GAP;+const REST_I = 5, REST_A = 22, FAR = 120;++/** The door's local outline and marks, in (u, v): u from the hinge, v up from its foot. */+const OUTLINE = rrect(0, 0, DW, DH, 1.8, 4);+const VENTS = [0, 1, 2].map((k) => rrect(4, DH - 6.6 - k * 3.2, DW - 4, DH - 5.2 - k * 3.2, 0.7, 2));+const PLATE = rrect(DW / 2 - 4.5, DH - 19, DW / 2 + 4.5, DH - 15, 1, 3);+const CUP = rrect(DW - 5.6, DH / 2 - 7, DW - 2.8, DH / 2 + 2, 1.2, 3);+const FRAME = rrect(2.6, 2.6, DW - 2.6, DH - 2.6, 1.4, 3);++/** Twice the signed area of a screen polygon: its sign says which way round it is seen. */+const area = (pts: readonly Vec2[]) => pts.reduce((s, p, i) => { const q = pts[(i + 1) % pts.length]; return s + p[0] * q[1] - q[0] * p[1]; }, 0);++type Locker = {+ c: number; r: number; n: number; x0: number; z0: number; drawn: number; sign0: number; tw: Tween;+ plate: SVGPathElement; face: SVGPathElement; marks: SVGPathElement; cup: SVGPathElement;+};++export const mount: FigureMount = ({ stage, svg, read }, value) => {+ const bag = disposer();+ const C = Cam(45, 0.5, 1.6);+ // fitted with the corner doors swung to the slider's far end, so no pose leaves the frame+ const sw = [Math.cos(rad(FAR)) * DW, Math.sin(rad(FAR)) * DW];+ fit(C, [[-4, -4, 0], [BW + 4, D + 4, 0], [BW + 4, -4, 0], [-4, D + 4, 0], [0, 0, ZP + BH], [BW, 0, ZP + BH],+ [FM + sw[0], D + sw[1], ZP + FM], [FM + sw[0], D + sw[1], ZP + BH - FM]], 200, 166);+ const P = proj(C), front = facing(C);+ let MAX = value, act = -1;++ /** The world point (x, z) on the vertical plane y = y0 that lies under a screen point. */+ function onFace(p: Vec2, y0: number): Vec2 {+ const o = P(0, y0, 0), a = P(1, y0, 0), b = P(0, y0, 1);+ const ex = [a[0] - o[0], a[1] - o[1]], ez = [b[0] - o[0], b[1] - o[1]], det = ex[0] * ez[1] - ex[1] * ez[0];+ const qx = p[0] - o[0], qy = p[1] - o[1];+ return [(qx * ez[1] - qy * ez[0]) / det, (ex[0] * qy - ex[1] * qx) / det];+ }+ /** A world segment, cut to what shows through a locker's opening: clipped on the face plane, as a screen path. */+ function through(A: Vec3, B: Vec3, L: Locker) {+ const pa = P(...A), pb = P(...B), a = onFace(pa, D), b = onFace(pb, D), m = 0.9;+ let t0 = 0, t1 = 1;+ const lim = [[a[0] - b[0], a[0] - (L.x0 + m)], [b[0] - a[0], L.x0 + DW - m - a[0]], [a[1] - b[1], a[1] - (L.z0 + m)], [b[1] - a[1], L.z0 + DH - m - a[1]]];+ for (const [p, q] of lim) {+ if (p === 0) { if (q < 0) return ""; continue; }+ const r = q / p;+ if (p < 0) t0 = Math.max(t0, r); else t1 = Math.min(t1, r);+ }+ if (t1 - t0 < 0.01) return "";+ const at = (t: number): Vec2 => [pa[0] + (pb[0] - pa[0]) * t, pa[1] + (pb[1] - pa[1]) * t];+ return seg(at(t0), at(t1));+ }++ const g = mk("g", {}, svg);+ const [pr, pi] = rings(-4, -4, BW + 4, D + 4, 5, 1.6);+ put(solid(g), prism(P, front, pr, pi, 0, ZP));+ const [br, bi] = rings(0, 0, BW, D, 3, 1.4);+ put(solid(g), prism(P, front, br, bi, ZP, ZP + BH));++ // Column by column from the left, bottom row before top: a door swings left and+ // out, over the column before it and the row below it, so this is back to front.+ const lockers: Locker[] = [];+ for (let c = 0; c < COLS; c++) for (let r = 0; r < ROWS; r++) {+ const x0 = FM + c * W + GAP, z0 = ZP + FM + r * HR + GAP;+ const lg = mk("g", {}, g);+ mk("path", { d: poly(OUTLINE.map((q) => P(x0 + q.u, D, z0 + q.v))), class: "" }, lg);+ const L = { c, r, n: (ROWS - 1 - r) * COLS + c + 1, x0, z0, drawn: NaN, sign0: 0, tw: tween(0) } as Locker;+ const zs = L.z0 + DH - 9.5, x1 = L.x0 + DW;+ const inside = [+ through([L.x0, D, L.z0], [L.x0, D - DEP, L.z0], L),+ through([L.x0, D - 1.6, zs], [x1, D - 1.6, zs], L),+ through([L.x0, D - 1.6, zs], [L.x0, D - DEP, zs], L),+ ].join("");+ mk("path", { d: inside, class: "nf lo" }, lg);+ L.plate = mk("path", { class: "lo" }, lg);+ L.face = mk("path", { class: "sil" }, lg);+ L.marks = mk("path", { class: "nf lo" }, lg);+ L.cup = mk("path", { class: "nf" }, lg);+ lockers.push(L);+ }+ const byN = (n: number) => lockers.find((L) => L.n === n)!;++ /** Door L turned th degrees on its hinge: a point on it at (u, v), s off its middle plane toward the front. */+ function drawDoor(L: Locker, th: number) {+ if (th === L.drawn) return;+ L.drawn = th;+ const cs = Math.cos(rad(th)), sn = Math.sin(rad(th));+ const at = (s: number) => (q: { u: number; v: number }) => P(L.x0 + q.u * cs - s * sn, D + T / 2 + q.u * sn + s * cs, L.z0 + q.v);+ const fr = OUTLINE.map(at(T / 2)), bk = OUTLINE.map(at(-T / 2));+ const outward = area(fr) * L.sign0 > 0, s = outward ? T / 2 : -T / 2;+ L.plate.setAttribute("d", poly(hull(fr.concat(bk))));+ L.face.setAttribute("d", poly(outward ? fr : bk));+ const marks: Ring[] = outward ? [...VENTS, PLATE] : [...VENTS, FRAME];+ L.marks.setAttribute("d", marks.map((m) => poly(m.map(at(s)))).join(""));+ L.cup.setAttribute("d", outward ? poly(CUP.map(at(s))) : "");+ }+ for (const L of lockers) L.sign0 = Math.sign(area(OUTLINE.map((q) => P(L.x0 + q.u, D + T, L.z0 + q.v))));++ const B = register(stage, (_dt, now) => {+ let m = false;+ for (const L of lockers) { drawDoor(L, tval(L.tw, now)); if (!tdone(L.tw, now)) m = true; }+ return m;+ });+ bag.add(B.unregister);++ /** The locker under a screen point, read on the plane of the closed door faces, which never moves. */+ function hit(p: Vec2) {+ const [x, z] = onFace(p, D + T);+ if (x < 0 || x > BW || z < ZP || z > ZP + BH) return -1;+ const c = clamp(Math.floor((x - FM) / W), 0, COLS - 1), r = clamp(Math.floor((z - ZP - FM) / HR), 0, ROWS - 1);+ return (ROWS - 1 - r) * COLS + c + 1;+ }++ /** Opens locker n and shuts the one open before it; 0 puts the bank back to rest. */+ function choose(n: number, force?: boolean) {+ if (n === act && !force) return;+ act = n;+ const now = performance.now(), lit = n > 0 ? n : REST_I;+ for (const L of lockers) {+ tset(L.tw, L.n === n ? MAX : n <= 0 && L.n === REST_I ? REST_A : 0, now, 0);+ L.face.classList.toggle("hi", L.n === lit);+ L.cup.classList.toggle("hi", L.n === lit);+ }+ read.textContent = n > 0 ? "locker " + String(n).padStart(2, "0") : "rest";+ B.wake();+ }+ byN(REST_I).tw = tween(REST_A);+ choose(0, true);++ bag.add(pointer(stage, { move: (p) => choose(Math.max(0, hit(p))), leave: () => choose(0) }));+ bag.add(() => svg.replaceChildren());++ return {+ set: (v) => { MAX = v; if (act > 0) choose(act, true); },+ destroy: bag.dispose,+ };+};diff --git a/packages/hairline/src/figures/padlock.ts b/packages/hairline/src/figures/padlock.tsnew file mode 100644index 0000000..383b77e--- /dev/null+++ b/packages/hairline/src/figures/padlock.ts@@ -0,0 +1,146 @@+import { Cam, circ, clamp, fillet, fit, hull, open, poly, proj, rad, run, 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";++/**+ * Padlock: a solid body with a keyway in its face, and a U-shaped shackle, a+ * round bar drawn as one tube. As the pointer comes near the lock, the+ * shackle rises out of the body on a spring; once its short leg has cleared+ * its hole, it swings about its long leg, which never leaves the body. Going+ * away drops it back and locks it. At rest it is caught just unlatched: up,+ * a little turned, bright. The slider is how far it swings, in degrees.+ *+ * The pattern: a continuous field with one part, as Terrain's falloff: one+ * spring on how open the lock is, set by the pointer's distance to the body,+ * which never moves. Lift and turn are both read from that one number, the+ * turn only once the lift is done, so the short leg can never cut the body.+ */++const W = 56, D = 20, H = 44, B = 1.6; // body: width, depth, height, crease inset+const T = 4.2, S2 = 30, XL = 13, YC = D / 2, ARM = 13, SINK = 7, LIFT = 11; // shackle: bar radius, leg spacing, long leg's x, legs' y, straight above the body, short leg's depth when shut, lift+const O1 = 0.42, REST_TURN = 26, R0 = 56, R1 = 200, SC = 2.75, TMAX = 100;+const VX = Math.SQRT1_2 * Math.sqrt(3); // the view's x (and y) for a z of 1, at Cam(45, .5)+const ss = (t: number) => t * t * (3 - 2 * t);++/** A closed outline in the face's own (x, z), as ring samples with outward normals. */+function samples(pts: readonly Vec2[]): Ring {+ return pts.map((p, i) => {+ const a = pts[(i + pts.length - 1) % pts.length], b = pts[(i + 1) % pts.length];+ const tx = b[0] - a[0], tz = b[1] - a[1], l = Math.hypot(tx, tz) || 1;+ return { u: p[0], v: p[1], nu: tz / l, nv: -tx / l };+ });+}++/** 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, each end a flat round cut seen from above. */+function tube(Q: readonly Vec2[], rho: 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)];+ const u0 = [c[0] - a[0], c[1] - a[1]], u1 = [b[0] - c[0], b[1] - c[1]];+ const l0 = Math.hypot(u0[0], u0[1]) || 1, l1 = Math.hypot(u1[0], u1[1]) || 1;+ let tx = u0[0] / l0 + u1[0] / l1, ty = u0[1] / l0 + u1[1] / l1;+ 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 poly([...untangle(A), ...cap(Q[n - 1]), ...untangle(Bk).reverse(), ...cap(Q[0])]);+}++export const mount: FigureMount = ({ stage, svg, read }, value) => {+ const bag = disposer();+ const tm = spring(value);+ let over = false;++ // The shackle's centre line, from the short leg's end, over the bow, down the long leg into its hole.+ const line = <R>(P: (x: number, y: number, z: number) => R, lift: number, th: number): R[] => {+ const u = [Math.cos(rad(th)), -Math.sin(rad(th))], za = H + ARM + lift, r = S2 / 2;+ const at = (s: number, z: number) => P(XL + u[0] * s, YC + u[1] * s, z);+ const pts = [at(S2, Math.max(H - SINK + lift, H)), at(S2, za)];+ for (let i = 1; i < 28; i++) { const f = (Math.PI * i) / 28; pts.push(at(r + r * Math.cos(f), za + r * Math.sin(f))); }+ pts.push(at(0, za), at(0, H));+ return pts;+ };++ // The camera is fitted to the body and the shackle at its highest and furthest swing.+ const C = Cam(45, 0.5, SC);+ const id = (x: number, y: number, z: number): Vec3 => [x, y, z];+ const ext: Vec3[] = [[0, 0, 0], [W, 0, 0], [0, D, 0], [W, D, 0], [0, 0, H]];+ for (const th of [0, 40, 80, TMAX]) for (const p of line(id, LIFT, th)) ext.push([p[0], p[1], p[2] + T]);+ fit(C, ext, 200, 170);+ const P = proj(C), rho = T * SC;++ // The body: its face a rounded block, fuller at the foot, stood out along y.+ const face = fillet([[0, 0], [W, 0], [W, H], [0, H]], [14, 14, 7, 7], 12);+ const inner = samples(fillet([[B, B], [W - B, B], [W - B, H - B], [B, H - B]], [14 - B, 14 - B, 7 - B, 7 - B], 12));+ const g = mk("g", {}, svg);+ put(solid(g), {+ sil: poly(hull(face.map((p) => P(p[0], 0, p[1])).concat(face.map((p) => P(p[0], D, p[1]))))),+ crease: open(run(inner, (q) => q.nu * VX + q.nv > 0).map((q) => P(q.u, D, q.v))),+ });++ // The keyway: a round hole and the slot under it, one closed cut in the face.+ const kx = W / 2, kz = H * 0.56, kr = 4.4, kw = 1.8, kb = kz - 12, a0 = Math.asin(kw / kr), key: Vec2[] = [];+ for (let i = 0; i <= 20; i++) { const t = -Math.PI / 2 + a0 + ((2 * Math.PI - 2 * a0) * i) / 20; key.push([kx + kr * Math.cos(t), kz + kr * Math.sin(t)]); }+ for (let i = 0; i <= 6; i++) { const t = Math.PI + (Math.PI * i) / 6; key.push([kx + kw * Math.cos(t), kb + kw * Math.sin(t)]); }+ mk("path", { d: poly(key.map((p) => P(p[0], D, p[1]))), class: "nf" }, g);++ // The two holes in the top the legs stand in.+ const hole = circ(T + 1.3, 20);+ for (const x of [XL, XL + S2]) mk("path", { d: poly(hole.map((q) => P(x + q.u, YC + q.v, H))), class: "nf lo" }, g);++ const bar = mk("path", { class: "sil" }, g);++ /** Lift and turn from how open the lock is: the lift first, then, with the short leg clear, the turn. */+ const pose = (o: number, max: number): [number, number] => [LIFT * ss(clamp(o / O1, 0, 1)), max * ss(clamp((o - O1) / (1 - O1), 0, 1))];+ /** How open the rest pose is: just unlatched, turned REST_TURN degrees, whatever the slider. */+ const restO = () => O1 + (1 - O1) * (0.5 - Math.sin(Math.asin(1 - (2 * REST_TURN) / tm.t) / 3));++ const sp = spring(restO(), { eps: 0.002 });+ let dO = NaN, dT = NaN;+ function draw() {+ if (sp.x === dO && tm.x === dT) return;+ dO = sp.x; dT = tm.x;+ const [lift, th] = pose(sp.x, tm.x);+ bar.setAttribute("d", tube(line(P, lift, th), rho));+ }++ const loop = register(stage, (dt) => { const a = stepS(sp, dt), b = stepS(tm, dt); draw(); return a || b; });+ bag.add(loop.unregister);++ const c0 = P(W / 2, D / 2, H / 2);+ function retarget() {+ const [lift, th] = pose(sp.t, tm.t), shut = over && lift < SINK; // read from the targets, never the pose on screen+ read.textContent = !over ? "rest" : shut ? "locked" : th < 1 ? "open" : Math.round(th) + "°";+ bar.classList.toggle("hi", !shut);+ loop.wake();+ }+ retarget();++ bag.add(pointer(stage, {+ move: (p) => { over = true; sp.t = clamp((R1 - Math.hypot(p[0] - c0[0], p[1] - c0[1])) / (R1 - R0), 0, 1); retarget(); },+ leave: () => { over = false; sp.t = restO(); retarget(); },+ }));+ bag.add(() => svg.replaceChildren());++ return {+ set: (v) => { tm.t = v; if (!over) sp.t = restO(); retarget(); },+ destroy: bag.dispose,+ };+};diff --git a/packages/hairline/src/figures/vault.ts b/packages/hairline/src/figures/vault.tsnew file mode 100644index 0000000..ee63adb--- /dev/null+++ b/packages/hairline/src/figures/vault.ts@@ -0,0 +1,194 @@+import { Cam, circ, clamp, fit, hull, lerp, open, poly, proj, rrect, run, seg, type Projector, type Ring, type Sample, type Vec2, type Vec3 } from "../core/iso";+import { reducedMotion, tdone, tset, tval, tween, type Tween } from "../core/motion";+import { disposer, mk, place, pointer, put, register, solid, type FigureMount, type Solid } from "../core/stage";++/**+ * Vault: a round vault door standing proud of a wall block, a combination dial+ * at its centre and three bolts on its lock side, each thrown across a gap into+ * a keeper bolted to the wall. Circling the pointer round the dial pushes it;+ * it coasts, friction bleeds the spin, and a detent every ten catches it. When+ * it lands on forty the bolts draw back into the door, staggered out from the+ * one nearest the pointer, and they are thrown again once the dial leaves.+ * At rest the dial sits on thirty, the combination's long tick bright just+ * past the index. The slider is the coast: friction's time constant, in ms.+ *+ * The pattern: push the camera, as Turntable's: friction, then a spring into+ * the detent; tweens for the bolts' choice; a hit test on the door's own plane.+ */++const R = 40, DP = 14, ZC = 64, RD = 17, DT = 4, KN = 6, KH = 6, GAP = 10, KL = 11, KW = 12, KD = 10, BR = 3.6;+const HX = -R - 8, HR = 4.6, WX0 = -70, WX1 = 70, WZ1 = 130, WT = 14, COMBO = 40, REST = 30, STEP = 50, WMAX = 150;+const THETA = [72, 26, -20];+/** Toward the viewer, for Cam(45, 0.5): a face whose normal has a positive dot with it is seen. */+const V: Vec3 = [Math.SQRT1_2 * Math.sqrt(0.75), Math.SQRT1_2 * Math.sqrt(0.75), 0.5];+const dir = (deg: number): Vec3 => [Math.cos((deg * Math.PI) / 180), 0, Math.sin((deg * Math.PI) / 180)];+const wrap = (d: number) => ((((d + 50) % 100) + 100) % 100) - 50;++/**+ * A rounded solid along axis e from s0 to s1, its cross-section `ring` lying in+ * the (a, b) plane round o: the hull of its two ends, and one crease on the end+ * at s1 where it meets the side the viewer sees.+ */+function bar(P: Projector, o: Vec3, e: Vec3, a: Vec3, b: Vec3, ring: Ring, inner: Ring, s0: number, s1: number) {+ const at = (q: Sample, s: number) => P(+ o[0] + e[0] * s + a[0] * q.u + b[0] * q.v,+ o[1] + e[1] * s + a[1] * q.u + b[1] * q.v,+ o[2] + e[2] * s + a[2] * q.u + b[2] * q.v,+ );+ const seen = (q: Sample) => [0, 1, 2].reduce((t, i) => t + (a[i] * q.nu + b[i] * q.nv) * V[i], 0) > 0;+ return {+ sil: poly(hull(ring.map((q) => at(q, s0)).concat(ring.map((q) => at(q, s1))))),+ crease: open(run(inner, seen).map((q) => at(q, s1))),+ };+}++type Bolt = { th: number; e: Vec3; t: Vec3; el: Solid; tw: Tween; drawn: number };++export const mount: FigureMount = ({ stage, svg, read }, value) => {+ const bag = disposer();+ let coast = value;+ const Y: Vec3 = [0, 1, 0], X: Vec3 = [1, 0, 0], Z: Vec3 = [0, 0, 1], O: Vec3 = [0, 0, ZC];++ const C = Cam(45, 0.5, 1.5);+ fit(C, [[WX0, -WT, 0], [WX1, -WT, 0], [WX0, -WT, WZ1], [WX1, -WT, WZ1], [WX0, KD, 0], [WX1, 0, 0], [WX0, 0, WZ1], [WX1, 0, WZ1]], 200, 166);+ const P = proj(C);++ const g = mk("g", {}, svg);+ // the wall block, then the door standing proud of it, painted back to front+ put(solid(g), bar(P, [0, 0, 0], Y, X, Z, rrect(WX0, 0, WX1, WZ1, 9, 6), rrect(WX0 + 2, 2, WX1 - 2, WZ1 - 2, 7, 6), -WT, 0));+ // the hinge, a barrel on the left with two arms into the door+ put(solid(g), bar(P, [HX, DP * 0.55, 0], Z, X, Y, circ(HR, 28), circ(HR - 1, 28), ZC - 26, ZC + 26));+ for (const dz of [-15, 15]) put(solid(g), bar(P, [0, 0, ZC + dz], Y, X, Z, rrect(HX, -4, -R + 6, 4, 3, 4), rrect(HX + 1, -3, -R + 5, 3, 2, 4), 1, DP * 0.8));+ put(solid(g), bar(P, O, Y, X, Z, circ(R, 72), circ(R - 2.4, 72), 0, DP));+ // the door's stepped face, and the index, a short stroke above the dial+ mk("path", { class: "nf lo", d: poly(circ(R - 8, 64).map((q) => P(q.u, DP, ZC + q.v))) }, g);+ mk("path", { class: "nf", d: seg(P(0, DP, ZC + RD + 1.8), P(0, DP, ZC + RD + 6.5)) }, g);+ const dial = solid(g);+ put(dial, bar(P, O, Y, X, Z, circ(RD, 56), circ(RD - 1.4, 56), DP, DP + DT));+ const ticks = mk("path", { class: "nf lo" }, g), longs = mk("path", { class: "nf" }, g), combo = mk("path", { class: "nf" }, g);+ put(solid(g), bar(P, O, Y, X, Z, circ(KN, 32), circ(KN - 1, 32), DP + DT, DP + DT + KH));++ // three bolts, each with the keeper it is thrown into; the keeper is painted after its bolt and covers its end+ const bolts: Bolt[] = THETA.map((th) => {+ const e = dir(th), t = dir(th + 90);+ const el = solid(g), keep = solid(g);+ put(keep, bar(P, O, Y, e, t, rrect(R + GAP, -KW / 2, R + GAP + KL, KW / 2, 3, 4), rrect(R + GAP + 1.4, -KW / 2 + 1.4, R + GAP + KL - 1.4, KW / 2 - 1.4, 1.8, 4), 0, KD));+ for (const s of [-3.4, 3.4]) {+ const c = R + GAP + KL / 2 + s;+ place(mk("circle", { r: 0.9, class: "dot off" }, keep.g), P(e[0] * c, KD, ZC + e[2] * c));+ }+ return { th, e, t, el, tw: tween(0), drawn: NaN };+ });+ const drawBolt = (b: Bolt, k: number) => {+ const s1 = lerp(R + GAP + 4.5, R + 1.2, k);+ if (s1 === b.drawn) return;+ b.drawn = s1;+ put(b.el, bar(P, [0, DP / 2, ZC], b.e, b.t, Y, circ(BR, 24), circ(BR - 0.9, 24), R - 0.2, s1));+ };++ // the dial: a is the number under the index, w its speed in numbers a second+ const spin = { a: REST, w: 0, mode: "rest" as "rest" | "coast" | "settle", tgt: REST };+ let raw = REST, said = "", last: number | null = null, lastT = 0, lastMove = -1e9, over = false, opened = false, from = 1, lit: string | null = null, drawnA = NaN;++ function drawDial() {+ if (spin.a === drawnA) return;+ drawnA = spin.a;+ const tk: string[] = [], lg: string[] = [], z = DP + DT;+ for (let m = 0; m < 100; m += 5) {+ const th = 90 + (m - spin.a) * 3.6, e = dir(th), r0 = m % 10 ? RD - 4 : RD - 6.5, r1 = RD - 1.8;+ const d = seg(P(e[0] * r0, z, ZC + e[2] * r0), P(e[0] * r1, z, ZC + e[2] * r1));+ if (m === COMBO) combo.setAttribute("d", d);+ else (m % 10 ? tk : lg).push(d);+ }+ ticks.setAttribute("d", tk.join(""));+ longs.setAttribute("d", lg.join(""));+ }++ /** One bright place: the bolts when open, the dial while handled, the combination's tick at rest. */+ function light() {+ const want = opened ? "bolts" : over ? "dial" : "combo";+ if (want === lit) return;+ lit = want;+ bolts.forEach((b) => b.el.sil.classList.toggle("hi", want === "bolts"));+ dial.sil.classList.toggle("hi", want === "dial");+ combo.classList.toggle("hi", want === "combo");+ }++ function setOpen(on: boolean, now: number) {+ opened = on;+ bolts.forEach((b, i) => tset(b.tw, on ? 1 : 0, now, Math.abs(i - from) * STEP));+ light();+ }++ /** Coast under friction, a detent's pull every ten; once slow, a spring into the nearest. 240Hz substeps. */+ function stepSpin(dt: number, now: number) {+ if (spin.mode === "rest") return false;+ const n = Math.max(1, Math.ceil(dt * 240)), h = dt / n;+ for (let i = 0; i < n; i++) {+ if (spin.mode === "coast") {+ spin.w = spin.w * Math.exp((-h * 1000) / coast) - 40 * Math.sin((spin.a / 10) * 2 * Math.PI) * h;+ spin.a += spin.w * h;+ if (Math.abs(spin.w) < 12 && now - lastMove > 90) { spin.mode = "settle"; spin.tgt = Math.round((spin.a + spin.w * 0.15) / 10) * 10; }+ } else { spin.w += (-90 * (spin.a - spin.tgt) - 16 * spin.w) * h; spin.a += spin.w * h; }+ }+ if (spin.mode === "settle" && Math.abs(spin.a - spin.tgt) < 0.01 && Math.abs(spin.w) < 0.2) {+ spin.a = spin.tgt = ((spin.tgt % 100) + 100) % 100; spin.w = 0; spin.mode = "rest";+ }+ return spin.mode !== "rest";+ }++ const B = register(stage, (dt, now) => {+ let m = stepSpin(dt, now);+ const near = Math.abs(wrap(spin.a - COMBO));+ if (!opened && near < 0.8 && Math.abs(spin.w) < 6) setOpen(true, now);+ else if (opened && near > 2.5) setOpen(false, now);+ drawDial();+ bolts.forEach((b) => { drawBolt(b, tval(b.tw, now)); if (!tdone(b.tw, now)) m = true; });+ const n = String(((Math.round(spin.a) % 100) + 100) % 100).padStart(2, "0");+ const say = over || spin.mode !== "rest" ? `dial ${n}` + (opened ? " · open" : "") : "rest";+ if (say !== said) read.textContent = said = say;+ return m;+ });+ bag.add(B.unregister);++ // the pointer on the door's face plane, which never moves+ const p0 = P(0, DP, 0), px = P(1, DP, 0), pz = P(0, DP, 1);+ const ax = [px[0] - p0[0], px[1] - p0[1]], az = [pz[0] - p0[0], pz[1] - p0[1]], det = ax[0] * az[1] - ax[1] * az[0];+ function onFace([sx, sy]: Vec2): Vec2 {+ const qx = sx - p0[0], qy = sy - p0[1];+ return [(qx * az[1] - qy * az[0]) / det, (ax[0] * qy - ax[1] * qx) / det - ZC];+ }++ function leave() {+ over = false; last = null;+ if (reducedMotion()) { raw = spin.a = ((Math.round(spin.a / 10) * 10) % 100 + 100) % 100; spin.w = 0; spin.mode = "rest"; }+ light(); B.wake();+ }++ bag.add(pointer(stage, {+ move: (p) => {+ const [u, v] = onFace(p), r = Math.hypot(u, v);+ if (r > R + GAP + KL + 10) return leave();+ const now = performance.now(), ang = (Math.atan2(v, u) * 180) / Math.PI;+ over = true;+ from = THETA.reduce((bi, th, i) => (Math.abs(wrap((ang - th) / 3.6)) < Math.abs(wrap((ang - THETA[bi]) / 3.6)) ? i : bi), 0);+ if (last !== null) {+ // circling the dial turns it with the pointer; near its centre the push fades+ const da = (-(((ang - last + 540) % 360) - 180) / 3.6) * clamp(r / 22, 0, 1);+ if (reducedMotion()) { raw += da; spin.a = Math.round(raw / 10) * 10; spin.mode = "rest"; }+ else {+ spin.w = clamp(lerp(spin.w, da / Math.max(0.008, (now - lastT) / 1000), 0.35), -WMAX, WMAX);+ spin.mode = "coast"; raw = spin.a;+ }+ if (Math.abs(da) > 0.05) lastMove = now;+ }+ last = ang; lastT = now;+ light(); B.wake();+ },+ leave,+ }));+ light();+ bag.add(() => svg.replaceChildren());++ return { set: (v) => { coast = v; B.wake(); }, destroy: bag.dispose };+};diff --git a/packages/hairline/src/index.ts b/packages/hairline/src/index.tsindex 1423a9d..c6aaf1c 100644--- a/packages/hairline/src/index.ts+++ b/packages/hairline/src/index.ts@@ -5,6 +5,8 @@ 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 padlockEngine } from "./figures/padlock";import { mount as phoneEngine } from "./figures/phone";import { mount as phosphorEngine } from "./figures/phosphor";import { mount as riffleEngine } from "./figures/riffle";@@ -12,9 +14,10 @@ import { mount as slowEngine } from "./figures/slow";import { mount as terminalEngine } from "./figures/terminal";import { mount as terrainEngine } from "./figures/terrain";import { mount as turntableEngine } from "./figures/turntable";+import { mount as vaultEngine } from "./figures/vault";/**- * @lucasmarkes/hairline — thirteen isometric line figures that answer the pointer.+ * @lucasmarkes/hairline — sixteen 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@@ -153,3 +156,33 @@ export function branches(el: HTMLElement, options?: HairlineOptions): Figure {engine: branchesEngine,}, el, options);}++/** A vault door: circling the pointer turns its dial, which coasts and catches every ten; on forty its three bolts draw back. `intensity` lets the dial coast longer. */+export function vault(el: HTMLElement, options?: HairlineOptions): Figure {+ return create({+ id: "vault",+ label: "A vault door: circling the pointer turns its dial, which coasts and catches every ten; on forty its three bolts draw back.",+ rest: "rest",+ engine: vaultEngine,+ }, el, options);+}++/** 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 function lockers(el: HTMLElement, options?: HairlineOptions): Figure {+ return create({+ id: "lockers",+ label: "A bank of twelve lockers, one ajar at rest: the locker under the pointer opens, and the one open before it swings shut.",+ rest: "rest",+ engine: lockersEngine,+ }, 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({+ id: "padlock",+ label: "A padlock: as the pointer nears, the shackle springs up out of the body and swings open about its long leg.",+ rest: "rest",+ engine: padlockEngine,+ }, el, options);+}diff --git a/packages/hairline/src/intensity.ts b/packages/hairline/src/intensity.tsindex 99b9ea3..c4ddfba 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";+export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches" | "vault" | "lockers" | "padlock";/** 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]> = {@@ -24,6 +24,9 @@ export const TABLE: Record<FigureId, readonly [number, number, number]> = {terminal: [1, 2, 3.5], // spread, linescabinet: [1.5, 3, 5], // reach, bladesbranches: [1, 3, 6], // reach, commits+ vault: [250, 600, 1500], // coast, ms+ lockers: [55, 90, 120], // opening, degrees+ padlock: [45, 90, 100], // swing, degrees};export const DEFAULT = 0.5;diff --git a/packages/hairline/src/react.tsx b/packages/hairline/src/react.tsxindex 52679f0..5923a62 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, elevator, exploded, keyboard, laptop, phone, phosphor, riffle, slow, terminal, terrain, turntable, type Figure, type HairlineOptions } from "./index";+import { branches, cabinet, elevator, exploded, keyboard, laptop, lockers, padlock, phone, phosphor, riffle, slow, terminal, terrain, turntable, vault, type Figure, type HairlineOptions } from "./index";/**- * @lucasmarkes/hairline/react — the thirteen figures as components.+ * @lucasmarkes/hairline/react — the sixteen 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.@@ -79,3 +79,9 @@ export const Terminal = make("Terminal", terminal);export const Cabinet = make("Cabinet", cabinet);/** A commit graph on a board: the commit under the pointer rises, and its history rises after it, the farther back the less. `intensity` raises more of the history. */export const Branches = make("Branches", branches);+/** A vault door: circling the pointer turns its dial, which coasts and catches every ten; on forty its three bolts draw back. `intensity` lets the dial coast longer. */+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 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);diff --git a/packages/hairline/test/browser/entry.ts b/packages/hairline/test/browser/entry.tsindex 35180c6..ed2788a 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";+type Id = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches" | "vault" | "lockers" | "padlock";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.tsindex 7eefd48..232354d 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"] as const;+const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches", "vault", "lockers", "padlock"] 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.tsindex 0a385d2..ef60ce6 100644--- a/packages/hairline/test/mount.test.ts+++ b/packages/hairline/test/mount.test.ts@@ -1,10 +1,10 @@// @vitest-environment jsdomimport { describe, expect, it, vi } from "vitest";import { frames, host, observers, pending } from "./dom";-import { branches, cabinet, elevator, exploded, keyboard, laptop, phone, phosphor, riffle, slow, terminal, terrain, turntable } from "../src/index";+import { branches, cabinet, elevator, exploded, keyboard, laptop, lockers, padlock, phone, phosphor, riffle, 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 };+const ALL = { riffle, terrain, exploded, phosphor, slow, turntable, keyboard, elevator, phone, laptop, terminal, cabinet, branches, vault, lockers, padlock };const key = (el: Element, k: string) => el.dispatchEvent(new KeyboardEvent("keydown", { key: k, bubbles: true, cancelable: true }));describe("mount", () => {@@ -149,6 +149,9 @@ describe("intensity", () => {terminal: [[200, 120], 20],cabinet: [[200, 120], 8],branches: [[200, 160], 8],+ vault: [[260, 170], 2, [200, 230], 2, [140, 170], 2, [200, 110], 8],+ lockers: [[200, 160], 8],+ padlock: [[200, 170], 60],};const svg = (el: Element) => el.querySelector("svg")!.innerHTML.replace(/hl-fd\d+/g, "hl-fd");diff --git a/packages/hairline/test/react.test.tsx b/packages/hairline/test/react.test.tsxindex a9ccc36..60df784 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, Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terminal, Terrain, Turntable } from "../src/react";+import { Branches, Cabinet, Elevator, Exploded, Keyboard, Laptop, Lockers, Padlock, Phone, Phosphor, Riffle, 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\ddescribe("components", () => {it("renders each figure into one div", () => {- const { container } = render(<><Riffle /><Terrain /><Exploded /><Phosphor /><Slow /><Turntable /><Keyboard /><Elevator /><Phone /><Laptop /><Terminal /><Cabinet /><Branches /></>);+ const { container } = render(<><Riffle /><Terrain /><Exploded /><Phosphor /><Slow /><Turntable /><Keyboard /><Elevator /><Phone /><Laptop /><Terminal /><Cabinet /><Branches /><Vault /><Lockers /><Padlock /></>);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"]);+ expect(ids).toEqual(["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches", "vault", "lockers", "padlock"]);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].map((c) => c.displayName))- .toEqual(["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard", "Elevator", "Phone", "Laptop", "Terminal", "Cabinet", "Branches"]);+ expect([Riffle, Terrain, Exploded, Phosphor, Slow, Turntable, Keyboard, Elevator, Phone, Laptop, Terminal, Cabinet, Branches, Vault, Lockers, Padlock].map((c) => c.displayName))+ .toEqual(["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard", "Elevator", "Phone", "Laptop", "Terminal", "Cabinet", "Branches", "Vault", "Lockers", "Padlock"]);});});diff --git a/packages/hairline/test/types.test-d.tsx b/packages/hairline/test/types.test-d.tsxindex 1654132..9ccc142 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, elevator, exploded, keyboard, laptop, phone, phosphor, riffle, slow, terminal, terrain, turntable, type Figure, type HairlineOptions } from "../src/index";+import { branches, cabinet, elevator, exploded, keyboard, laptop, lockers, padlock, phone, phosphor, riffle, 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, Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terminal, Terrain, Turntable, type HairlineProps } from "../src/react";+import { Branches, Cabinet, Elevator, Exploded, Keyboard, Laptop, Lockers, Padlock, Phone, Phosphor, Riffle, 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]) {+for (const mount of [riffle, terrain, exploded, phosphor, slow, turntable, keyboard, elevator, phone, laptop, terminal, cabinet, branches, vault, lockers, padlock]) {yes<Equal<typeof mount, (el: HTMLElement, options?: HairlineOptions) => Figure>>();// @ts-expect-error the old per-figure options are gonemount(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">>();-yes<Equal<keyof typeof components, "Riffle" | "Terrain" | "Exploded" | "Phosphor" | "Slow" | "Turntable" | "Keyboard" | "Elevator" | "Phone" | "Laptop" | "Terminal" | "Cabinet" | "Branches">>();+yes<Equal<keyof typeof vanilla, "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches" | "vault" | "lockers" | "padlock">>();+yes<Equal<keyof typeof components, "Riffle" | "Terrain" | "Exploded" | "Phosphor" | "Slow" | "Turntable" | "Keyboard" | "Elevator" | "Phone" | "Laptop" | "Terminal" | "Cabinet" | "Branches" | "Vault" | "Lockers" | "Padlock">>();// @ts-expect-error ranges is gonevoid 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]) {+for (const C of [Riffle, Terrain, Exploded, Phosphor, Slow, Turntable, Keyboard, Elevator, Phone, Laptop, Terminal, Cabinet, Branches, Vault, Lockers, Padlock]) {// @ts-expect-error the old per-figure options are gone<C stagger={60} />;// @ts-expect-error the old per-figure options are gonediff --git a/registry/src/hairline.tsx b/registry/src/hairline.tsxindex 7f1b371..dd7e0a6 100644--- a/registry/src/hairline.tsx+++ b/registry/src/hairline.tsx@@ -69,3 +69,15 @@ export function Cabinet({ style, ...props }: ComponentProps<typeof Hairline.Cabiexport function Branches({ style, ...props }: ComponentProps<typeof Hairline.Branches>) {return <Hairline.Branches style={{ ...tokens, ...style }} {...props} />;}++export function Vault({ style, ...props }: ComponentProps<typeof Hairline.Vault>) {+ return <Hairline.Vault style={{ ...tokens, ...style }} {...props} />;+}++export function Lockers({ style, ...props }: ComponentProps<typeof Hairline.Lockers>) {+ return <Hairline.Lockers style={{ ...tokens, ...style }} {...props} />;+}++export function Padlock({ style, ...props }: ComponentProps<typeof Hairline.Padlock>) {+ return <Hairline.Padlock style={{ ...tokens, ...style }} {...props} />;+}diff --git a/registry/validate.mjs b/registry/validate.mjsindex c352e1d..afe8982 100644--- a/registry/validate.mjs+++ b/registry/validate.mjs@@ -29,7 +29,7 @@ const [source] = item.files ?? [];if (item.dependencies?.join() !== "@lucasmarkes/hairline") problems.push("dependencies must be exactly @lucasmarkes/hairline");if (source?.path !== "components/ui/hairline.tsx") problems.push("the file must be components/ui/hairline.tsx");if (!source?.content?.startsWith('"use client";')) problems.push('the file must start with "use client"');-for (const name of ["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard", "Elevator", "Phone", "Laptop", "Terminal", "Cabinet", "Branches"]) {+for (const name of ["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard", "Elevator", "Phone", "Laptop", "Terminal", "Cabinet", "Branches", "Vault", "Lockers", "Padlock"]) {if (!source?.content?.includes(`export function ${name}(`)) problems.push(`the file does not export ${name}`);}if (/localhost/.test(JSON.stringify(item)) && process.env.VERCEL) problems.push("the item points at localhost in a deployed build");diff --git a/scripts/consumers.mjs b/scripts/consumers.mjsindex 66f95d7..b323d7c 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"] },+ 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"] },};const only = process.argv[2];if (only && !FIXTURES[only]) { console.error(`Unknown fixture "${only}". Use: ${Object.keys(FIXTURES).join(" | ")}`); process.exit(2); }