Isometric line figures that answer the pointer. For React and for anything with a DOM.
Coding: a terminal whose history scrolls with the pointer's height, a cabinet whose blades slide out, and a commit graph that rises after the commit under the pointer
Lucas Marques738a3584f1d2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ffcafd6..5e9055c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -20,6 +20,15 @@ Every release of `@lucasmarkes/hairline`. The format follows- `laptop` and `Laptop`: a thin laptop. The pointer's height sets how far thelid stands open, and the lid follows it on a spring. A stronger `intensity`lets the lid open wider.+- `terminal` and `Terminal`: a terminal window. The pointer's height scrolls+ back through its history, and the line under it lifts off the screen. A+ stronger `intensity` lifts more lines with it.+- `cabinet` and `Cabinet`: a rack of twelve blades. The pointer's height pulls+ the nearest ones out on their rails, the farther the less. A stronger+ `intensity` pulls out more blades.+- `branches` and `Branches`: a commit graph on a board. The commit under the+ pointer rises, and its history rises after it, the farther back the less. A+ stronger `intensity` raises more of the history.## 0.1.0 - 2026-10-01diff --git a/README.md b/README.mdindex 6c16c50..5d6a00a 100644--- a/README.md+++ b/README.md@@ -1,6 +1,6 @@# hairline-Ten isometric line figures that answer the pointer. For React and for anything with a DOM.+Thirteen 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)@@ -65,6 +65,9 @@ A figure draws into the element you give it, at the element's width and a 5:4 as| `elevator` | `Elevator` | Four floors beside an open shaft. The pointer's height picks a floor; the car travels there. | The car travels faster between floors. || `phone` | `Phone` | A phone in layers: glass, board, battery, shell. Moving across opens the gap; moving down picks a layer. | The layers open further. || `laptop` | `Laptop` | A thin laptop, open on its hinge. The pointer's height sets the lid; it follows on a spring. | The lid opens wider. |+| `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. |## Options@@ -108,7 +111,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 ten 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 thirteen 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 3a2e060..a79123b 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 { Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";+import { Branches, Cabinet, Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terminal, Terrain, Turntable } 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 };+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 };/** 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/app/globals.css b/apps/site/app/globals.cssindex c4dbf45..8153f62 100644--- a/apps/site/app/globals.css+++ b/apps/site/app/globals.css@@ -298,9 +298,10 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }/* the demo pointer: a hairline ring, there only while it walks the figure */.reel-ghost { position: absolute; top: 0; left: 0; z-index: 1; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; border: 1px solid var(--color-ink); pointer-events: none; opacity: 0; transition: opacity 200ms ease; }.reel-ghost[data-on] { opacity: 0.4; }-.reel-ticks { display: flex; margin-top: 10px; }-.reel-tick { display: grid; place-items: center; width: 30px; height: 26px; border-radius: 6px; }-.reel-tick::before, .reel-fill { grid-area: 1 / 1; width: 20px; height: 1.5px; border-radius: 1px; }+/* a tick is 30px and gives way when the row would pass the figure's width, so nineteen ticks fit a phone */+.reel-ticks { display: flex; width: 100%; max-width: 440px; justify-content: center; margin-top: 10px; }+.reel-tick { display: grid; place-items: center; flex: 0 1 30px; min-width: 0; height: 26px; border-radius: 6px; }+.reel-tick::before, .reel-fill { grid-area: 1 / 1; width: min(20px, 70%); height: 1.5px; border-radius: 1px; }.reel-tick::before { content: ""; background: rgba(0, 0, 0, 0.12); transition: background-color 150ms ease; }@media (hover: hover) { .reel-tick:hover::before { background: rgba(0, 0, 0, 0.3); } }.reel-fill { background: var(--color-ink); transform: scaleX(0); transform-origin: left; }diff --git a/apps/site/components/catalogue.tsx b/apps/site/components/catalogue.tsxindex 0aedf82..d877c5b 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 { Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";+import { Branches, Cabinet, Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terminal, Terrain, Turntable } 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 };+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 };type Filter = "all" | ShelfId;diff --git a/apps/site/components/reel.tsx b/apps/site/components/reel.tsxindex 205d883..e543e19 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 { Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";+import { Branches, Cabinet, Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terminal, Terrain, Turntable } 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 };+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 };/*** One pass of a pointer over each figure, in its viewBox (400 × 320): [x, y, ms]. Each path does the@@ -21,6 +21,9 @@ const DEMO: Record<keyof typeof COMPONENTS, [number, number, number][]> = {elevator: [[200, 250, 0], [200, 60, 1400], [200, 175, 3400]],phone: [[110, 170, 0], [290, 170, 1200], [290, 90, 1900], [290, 250, 2900]],laptop: [[200, 270, 0], [200, 70, 1500], [200, 180, 3300]],+ 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]],};/** 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 e1587d6..0ae55fd 100644--- a/apps/site/lib/catalogue.ts+++ b/apps/site/lib/catalogue.ts@@ -51,9 +51,9 @@ export const SHELVES: Shelf[] = [},{id: "coding", title: "Coding", color: "#0ea5e9", figures: [- planned("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."),- planned("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."),- planned("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."),+ drawn("terminal"),+ drawn("cabinet"),+ drawn("branches"),],},{diff --git a/apps/site/lib/figures.ts b/apps/site/lib/figures.tsindex ff6852c..ed25feb 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";+export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches";export type FigureDoc = {id: FigureId;@@ -92,9 +92,30 @@ export const FIGURES: FigureDoc[] = [stronger: "The lid opens wider.",parameter: { name: "lid", unit: "degrees" },},+ {+ id: "terminal",+ name: "Terminal",+ summary: "A terminal window with its history in rows. The pointer's height scrolls back; the line under it lifts and its neighbours follow.",+ stronger: "The lift spreads further.",+ parameter: { name: "spread", unit: "lines" },+ },+ {+ id: "cabinet",+ name: "Cabinet",+ summary: "A rack of twelve blades, a few half out. The pointer's height pulls the nearest ones out, the farther the less.",+ stronger: "More blades come out.",+ parameter: { name: "reach", unit: "blades" },+ },+ {+ id: "branches",+ name: "Branches",+ summary: "A commit graph with a branch forking off main and merging back. The commit under the pointer rises, and its history rises after it.",+ stronger: "More of the history rises.",+ parameter: { name: "reach", unit: "commits" },+ },];-/** How many figures the package has, as the prose writes it: "ten". */+/** How many figures the package has, as the prose writes it: "thirteen". */export const COUNT = spell(FIGURES.length);/** Each figure's number at intensity 0, 0.5 and 1: a copy of the package's table. */@@ -109,6 +130,9 @@ export const INTENSITY: Record<FigureId, readonly [number, number, number]> = {elevator: [40, 100, 220],phone: [16, 28, 40],laptop: [100, 125, 150],+ terminal: [1, 2, 3.5],+ cabinet: [1.5, 3, 5],+ branches: [1, 3, 6],};/** 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 e098f93..cbab504 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 ten empty boxes among nineteen tiles, then draws them with a clean console", async ({ page, request }) => {+test("/figures prerenders thirteen 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(10);+ expect(html.match(/<div style="aspect-ratio:5 \/ 4"><\/div>/g)).toHaveLength(13);expect(html.match(/class="fig-tile"/g)).toHaveLength(19);- expect(html.match(/class="fig-tile" data-planned=""/g)).toHaveLength(9);+ expect(html.match(/class="fig-tile" data-planned=""/g)).toHaveLength(6);const noise = watch(page);await page.goto("/figures");await expect(tiles(page)).toHaveCount(19);- await expect(page.locator(".fig-tile [data-hairline] > svg")).toHaveCount(10);- await expect(page.locator(".fig-tile .fig-ghost")).toHaveCount(9);+ 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("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("Terminal, planned");+ await expect(page.locator(".fig-tile[data-planned] .fig-name").first()).toHaveAccessibleName("Vault, planned");expect(noise).toEqual([]);});diff --git a/apps/site/test/site.spec.ts b/apps/site/test/site.spec.tsindex 79bb2b7..d94c622 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"];+const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches"];const MANAGERS = [["npm", "npm i @lucasmarkes/hairline"],["pnpm", "pnpm add @lucasmarkes/hairline"],@@ -147,6 +147,8 @@ test("under reduced motion the reel never starts", async ({ page }) => {});test("a change of figure never moves the page: the reel and the page hold their height through every figure", async ({ page }) => {+ // every change waits out its dissolve, at three widths: the time grows with the figures+ test.setTimeout(IDS.length * 3 * 1500 + 15_000);for (const width of [1440, 390, 320]) {await page.setViewportSize({ width, height: 800 });await page.goto("/");@@ -286,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", /^Ten isometric line figures/],+ ["/", "hairline", /^Thirteen isometric line figures/],["/figures", "Figures", /^Seven shelves, nineteen figures, grouped by what they draw/],- ["/docs", "Docs", /^Ten isometric line figures/],+ ["/docs", "Docs", /^Thirteen 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 c22dc23..b69f423 100644--- a/fixtures/vite-vanilla/index.html+++ b/fixtures/vite-vanilla/index.html@@ -21,6 +21,9 @@<div id="elevator"></div><div id="phone"></div><div id="laptop"></div>+ <div id="terminal"></div>+ <div id="cabinet"></div>+ <div id="branches"></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 88a1869..710023c 100644--- a/fixtures/vite-vanilla/src/main.ts+++ b/fixtures/vite-vanilla/src/main.ts@@ -1,6 +1,6 @@-import { elevator, exploded, keyboard, laptop, phone, phosphor, riffle, slow, terrain, turntable, type Figure } from "@lucasmarkes/hairline";+import { branches, cabinet, elevator, exploded, keyboard, laptop, phone, phosphor, riffle, slow, terminal, terrain, turntable, type Figure } from "@lucasmarkes/hairline";-/** No framework: ten elements, ten calls. */+/** No framework: thirteen elements, thirteen calls. */const el = (id: string) => document.getElementById(id)!;const read = el("read");@@ -17,5 +17,8 @@ keyboard(el("keyboard"));elevator(el("elevator"));phone(el("phone"));laptop(el("laptop"));+terminal(el("terminal"));+cabinet(el("cabinet"));+branches(el("branches"));cards.update({ intensity: 0.8 });diff --git a/package.json b/package.jsonindex 87cf182..418d6f7 100644--- a/package.json+++ b/package.json@@ -2,7 +2,7 @@"name": "hairline-monorepo","version": "0.0.0","private": true,- "description": "Ten isometric line figures that answer the pointer",+ "description": "Thirteen 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 cec3069..793c26d 100644--- a/packages/hairline/package.json+++ b/packages/hairline/package.json@@ -1,7 +1,7 @@{"name": "@lucasmarkes/hairline","version": "0.2.0",- "description": "Ten isometric line figures that answer the pointer. For React and for anything with a DOM.",+ "description": "Thirteen isometric line figures that answer the pointer. For React and for anything with a DOM.","license": "MIT","type": "module","sideEffects": false,@@ -83,7 +83,7 @@{"name": "vanilla, every figure","path": "dist/index.js",- "limit": "16.6 kB"+ "limit": "19.9 kB"},{"name": "vanilla, one figure",@@ -94,7 +94,7 @@{"name": "react, every component","path": "dist/react.js",- "limit": "16.9 kB",+ "limit": "20.3 kB","ignore": ["react","react/jsx-runtime"diff --git a/packages/hairline/src/figures/branches.ts b/packages/hairline/src/figures/branches.tsnew file mode 100644index 0000000..b7bceb4--- /dev/null+++ b/packages/hairline/src/figures/branches.ts@@ -0,0 +1,158 @@+import { Cam, circ, clamp, facing, fit, poly, prism, proj, rings, seg, unproj, type Ring, type Vec2 } from "../core/iso";+import { tdone, tset, tval, tween, type Tween } from "../core/motion";+import { disposer, mk, pointer, put, register, solid, type FigureMount, type Solid } from "../core/stage";++/**+ * Branches: a git history as an object on a board. A main line of commits+ * runs along a rail, each commit a puck seated on a round pad; a feature+ * branch forks off it near the start and merges back late. The rails are+ * closed strips that run pad to pad, so each fork and merge sits on a pad.+ * The pointer picks the commit under it: that puck rises off its pad, and+ * its first-parent ancestry rises after it, staggered back along its own+ * branch and through the fork, the farther back the less. Commits outside+ * that history stay seated. At rest, the feature's last commit is caught+ * bright, two ancestors under it. The slider is the reach, in commits.+ *+ * The pattern: discrete items, as Riffle's: tweens, a stagger by distance+ * (here, distance back through the history), and a hit test on the pucks'+ * shared rest top, which never moves.+ */++const D = 30, FY = 58, RW = 7, RT = 2.6, PR = 8, PH = 2.4, CR = 6.6, CH = 6, LIFT = 36, STEP = 45;+const BX0 = -15, BX1 = 7 * D + 15, BY0 = -16, BY1 = FY + 14, PB = 6, ZTOP = RT + PH + CH;++type Commit = {+ lane: "main" | "feature"; n: number; x: number; y: number; parent: number;+ ring: Ring; inner: Ring; el: Solid; drop: SVGPathElement; z: Tween; drawn: number;+};+type Seed = Pick<Commit, "lane" | "n" | "x" | "y" | "parent">;++/** The history. Each commit: lane, number on its lane, world x, y, and its first parent. */+function history() {+ const cs: Seed[] = [], at = (lane: Seed["lane"], n: number, x: number, y: number, parent: number) => (cs.push({ lane, n, x, y, parent }), cs.length - 1);+ const m: number[] = [];+ for (let i = 0; i < 8; i++) m.push(at("main", i + 1, i * D, 0, i ? m[i - 1] : -1));+ const f1 = at("feature", 1, 2.5 * D, FY, m[1]), f2 = at("feature", 2, 3.5 * D, FY, f1), f3 = at("feature", 3, 4.5 * D, FY, f2);+ return { cs, m, f: [f1, f2, f3] };+}++/** A cubic from a to b, leaving a along (ox, oy) and arriving at b level. */+const bez = (a: Vec2, b: Vec2, ox: number, oy: number, ix: number, n: number) => {+ const out: Vec2[] = [];+ for (let k = 0; k <= n; k++) {+ const t = k / n, u = 1 - t, w = [u * u * u, 3 * u * u * t, 3 * u * t * t, t * t * t];+ const px = [a[0], a[0] + ox, b[0] - ix, b[0]], py = [a[1], a[1] + oy, b[1], b[1]];+ out.push([w[0] * px[0] + w[1] * px[1] + w[2] * px[2] + w[3] * px[3], w[0] * py[0] + w[1] * py[1] + w[2] * py[2] + w[3] * py[3]]);+ }+ return out;+};++/** A rail: the closed strip RW wide round a centre line of world points. Its ends sit under pads. */+function strip(c: Vec2[]) {+ const L: Vec2[] = [], R: Vec2[] = [];+ c.forEach((p, i) => {+ const a = c[Math.max(0, i - 1)], b = c[Math.min(c.length - 1, i + 1)];+ const dx = b[0] - a[0], dy = b[1] - a[1], l = Math.hypot(dx, dy), nx = -dy / l, ny = dx / l;+ L.push([p[0] + nx * RW / 2, p[1] + ny * RW / 2]);+ R.push([p[0] - nx * RW / 2, p[1] - ny * RW / 2]);+ });+ return L.concat(R.reverse());+}++export const mount: FigureMount = ({ stage, svg, read }, value) => {+ const bag = disposer();+ let reach = value;+ const C = Cam(45, 0.5, 1.4);+ fit(C, [[BX0, BY0, -PB], [BX1, BY1, -PB], [BX1, BY0, -PB], [BX0, BY1, -PB], [BX0, BY0, ZTOP + LIFT], [BX1, BY0, ZTOP + LIFT]], 200, 166);+ const P = proj(C), front = facing(C);+ const { cs: seeds, m, f } = history();+ const xy = (i: number): Vec2 => [seeds[i].x, seeds[i].y];++ const g = mk("g", {}, svg);+ const [br, bi] = rings(BX0, BY0, BX1, BY1, 12, 2.2);+ put(solid(g), prism(P, front, br, bi, -PB, 0));++ // The rails, pad to pad: main straight; each branch leaves its fork on a slant and comes back into its merge.+ const fork = (a: Vec2, b: Vec2) => bez(a, b, (b[0] - a[0]) * 0.3, (b[1] - a[1]) * 0.5, (b[0] - a[0]) * 0.45, 14);+ const merge = (a: Vec2, b: Vec2) => bez(b, a, (a[0] - b[0]) * 0.3, (a[1] - b[1]) * 0.5, (a[0] - b[0]) * 0.45, 14).reverse();+ const lines: Vec2[][] = [+ [xy(m[0]), xy(m[7])],+ [...fork(xy(m[1]), xy(f[0])), ...merge(xy(f[2]), xy(m[6])).slice(1)],+ ];+ for (const c of lines) {+ const s = strip(c);+ mk("path", { d: poly(s.map((p) => P(p[0], p[1], 0))), class: "lo" }, g);+ mk("path", { d: poly(s.map((p) => P(p[0], p[1], RT))), class: "" }, g);+ }++ // Pads and pucks, by ascending x + y, so a nearer commit covers a farther one.+ const [pr, pi] = [circ(PR, 24), circ(PR - 1.4, 24)], [cr, ci] = [circ(CR, 24), circ(CR - 1.2, 24)];+ const at = (ring: Ring, x: number, y: number): Ring => ring.map((q) => ({ ...q, u: q.u + x, v: q.v + y }));+ const order = seeds.map((_, i) => i).sort((a, b) => seeds[a].x + seeds[a].y - (seeds[b].x + seeds[b].y));+ const cs: Commit[] = [];+ for (const i of order) {+ const c = seeds[i];+ put(solid(g), prism(P, front, at(pr, c.x, c.y), at(pi, c.x, c.y), RT, PH + RT));+ const drop = mk("path", { class: "dash nf" }, g);+ cs[i] = { ...c, drop, el: solid(g), ring: at(cr, c.x, c.y), inner: at(ci, c.x, c.y), z: tween(0), drawn: NaN };+ }++ /** The first-parent history of commit a, nearest first: [index, steps back]. */+ const chain = (a: number) => { const out: Array<[number, number]> = []; for (let i = a, k = 0; i >= 0; i = cs[i].parent, k++) out.push([i, k]); return out; };+ const REST = f[2], REST_REACH = 2.2, REST_DEPTH = 0.5;++ function draw(c: Commit, z: number) {+ if (z === c.drawn) return;+ c.drawn = z;+ const b = PH + RT + z;+ put(c.el, prism(P, front, c.ring, c.inner, b, b + CH));+ c.drop.setAttribute("d", seg(P(c.x, c.y, PH + RT), P(c.x, c.y, b)));+ }++ const B = register(stage, (_dt, now) => {+ let moving = false;+ for (const c of cs) { draw(c, tval(c.z, now)); if (!tdone(c.z, now)) moving = true; }+ return moving;+ });+ bag.add(B.unregister);++ let act: number | null = null, lit: number | null = null, held = new Map<number, [number, number]>();+ /** Lifts commit a and its history, reach commits back, depth a share of full lift. The stagger runs back from a; what drops runs back from the commit let go. */+ function lift(a: number, r: number, depth: number, instant?: boolean) {+ const now = performance.now(), want = new Map<number, [number, number]>();+ for (const [i, k] of chain(a)) if (k <= r) want.set(i, [LIFT * depth * clamp(1 - k / (r + 1), 0, 1), k]);+ cs.forEach((c, i) => {+ const [to, k] = want.get(i) || [0, (held.get(i) || [0, 0])[1]];+ if (instant) c.z = tween(to);+ else tset(c.z, to, now, k * STEP);+ });+ held = want;+ if (lit !== a) { if (lit !== null) cs[lit].el.sil.classList.remove("hi"); lit = a; cs[a].el.sil.classList.add("hi"); }+ B.wake();+ }+ lift(REST, REST_REACH, REST_DEPTH, true);++ function choose(a: number | null) {+ if (a === act) return;+ act = a;+ if (a === null) { lift(REST, REST_REACH, REST_DEPTH); read.textContent = "rest"; }+ else { lift(a, reach, 1); read.textContent = `${cs[a].lane} · ${cs[a].n}`; }+ }++ /** The commit under a screen point, from the pucks' rest top, which every puck shares and none leaves when the pointer picks. */+ function hit(p: Vec2): number | null {+ const q = unproj(C, p[0], p[1], ZTOP);+ if (q[0] < BX0 || q[0] > BX1 || q[1] < BY0 || q[1] > BY1) return null;+ let best: number | null = null, bd = Infinity;+ cs.forEach((c, i) => { const d = Math.hypot(c.x - q[0], c.y - q[1]); if (d < bd) { bd = d; best = i; } });+ return best;+ }++ bag.add(pointer(stage, { move: (p) => choose(hit(p)), leave: () => choose(null) }));+ bag.add(() => svg.replaceChildren());++ return {+ set: (v) => { reach = v; if (act !== null) lift(act, reach, 1); },+ destroy: bag.dispose,+ };+};diff --git a/packages/hairline/src/figures/cabinet.ts b/packages/hairline/src/figures/cabinet.tsnew file mode 100644index 0000000..f44c99b--- /dev/null+++ b/packages/hairline/src/figures/cabinet.ts@@ -0,0 +1,164 @@+import { Cam, clamp, facing, fit, hull, open, poly, prism, proj, rings, rrect, run, seg, type Projector, type Ring, type Sample, type Vec2, type Vec3 } from "../core/iso";+import { spring, stepS, type Spring } from "../core/motion";+import { disposer, mk, place, pointer, put, register, solid, type FigureMount, type Solid } from "../core/stage";++/**+ * Cabinet: a server rack of twelve 1U blades between two drilled rails, on a+ * plinth. Each blade is a chassis behind a faceplate: ears with pull handles+ * on the rails, four drive bays, a vent and a status lamp. The pointer's+ * height is read on the rack's closed front, and the blades near it slide out+ * along their rails, the farther the less, each on its own spring; the one+ * under it comes all the way and its lamp lights. At rest the last update has+ * stopped part-way: blade 7 half out and lit, a few others caught on the way.+ * The slider is the reach, in blades.+ *+ * The pattern: a continuous field, as Keyboard's, over a stack: a spring per+ * blade, a falloff by distance, a hit test on the rest pose's planes.+ */++const N = 12, U = 10.4, BH = 9.6, W = 84, EAR = 4, FT = 2, D = 44, OUT = 26;+const X0 = -10, X1 = W + 10, Z0 = 6, ZB = 11, ZT = ZB + (N - 1) * U + BH, H = ZT + 6;+/** Where the last update stopped: blade 7 half out, its neighbours and two others caught on their way. */+const REST = [0, 0, 0.2, 0, 0, 0.3, 0.58, 0.26, 0, 0, 0.13, 0];+const LIT = 6;++/** The share of full travel a blade comes out, u reaches from the pointer: all of it under the pointer, none past the reach. */+const falloff = (u: number) => (u >= 1 ? 0 : (1 - u) * (1 - u));+/** On a plate's front 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 | null, 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: inset ? open(at(run(inset, inner), y1)) : "" };+}++type Blade = {+ i: number; z: number;+ body: Ring; face: Ring; faceIn: Ring;+ chassis: Solid; plate: Solid; marks: SVGPathElement; lamp: SVGCircleElement;+ sp: Spring; drawn: number;+};++export const mount: FigureMount = ({ stage, svg, read }, value) => {+ const bag = disposer();+ const C = Cam(45, 0.5, 1.5);+ const yo = D + FT + OUT;+ fit(C, [[X0, 0, 0], [X1, 0, H], [X1, D, 0], [X0, 0, H], [-EAR, yo, ZB], [-EAR, yo, ZT], [W + EAR, yo, ZB]], 200, 166);+ const P = proj(C), front = facing(C);+ let R = value, over: number | null = null, lit: Blade | null = null;++ const g = mk("g", {}, svg);+ // the plinth, set back under the cabinet, then the cabinet itself+ const [pr, pi] = rings(X0 + 3, 3, X1 - 3, D - 3, 3, 1.2);+ put(solid(g), prism(P, front, pr, pi, 0, Z0));+ const [br, bi] = rings(X0, 0, X1, D, 3.5, 1.6);+ put(solid(g), prism(P, front, br, bi, Z0, H));+ // its front: the opening's edge round the rails, a hole in each rail for every U; and the side panel's inset+ const onFront = (r: Ring) => r.map((q): Vec2 => P(q.u, D, q.v)), onSide = (r: Ring) => r.map((q): Vec2 => P(X1, q.u, q.v));+ mk("path", { d: poly(onFront(rrect(-7.6, ZB - 2.2, W + 7.6, ZT + 2.2, 2, 4))) + poly(onSide(rrect(5, Z0 + 7, D - 5, H - 7, 3, 4))), class: "lo nf" }, g);+ for (let i = 0; i < N; i++) for (const x of [-5.8, W + 5.8]) {+ place(mk("circle", { r: 0.75, class: "dot off" }, g), P(x, D, ZB + i * U + BH / 2));+ }++ // Bottom to top: the camera looks down, so a lower blade can never cover a higher one.+ const blades: Blade[] = [];+ for (let i = 0; i < N; i++) {+ const z = ZB + i * U, gi = mk("g", {}, g);+ blades.push({+ i, z,+ body: rrect(0, z + 0.4, W, z + BH - 0.4, 1.6, 4),+ face: rrect(-EAR, z, W + EAR, z + BH, 2, 4),+ faceIn: rrect(-EAR + 0.8, z + 0.8, W + EAR - 0.8, z + BH - 0.8, 1.2, 4),+ chassis: solid(gi), plate: solid(gi),+ marks: mk("path", { class: "lo nf" }, gi),+ lamp: mk("circle", { r: 1.1, class: "dot off" }, gi),+ sp: spring(OUT * REST[i], { eps: 0.02 }), drawn: NaN,+ });+ }++ /** Blade b's faceplate marks, drawn on its front at y: two handles, four bays, a vent. */+ function marks(b: Blade, y: number) {+ const z = b.z, F = (r: Ring) => poly(r.map((q): Vec2 => P(q.u, y, q.v)));+ let d = F(rrect(-3.4, z + 2, -1.2, z + BH - 2, 1, 3)) + F(rrect(W + 1.2, z + 2, W + 3.4, z + BH - 2, 1, 3));+ for (let k = 0; k < 4; k++) d += F(rrect(4 + k * 10.6, z + 2, 13.8 + k * 10.6, z + BH - 2, 1, 3));+ for (let k = 0; k < 8; k++) d += seg(P(50 + k * 2.6, y, z + 2.5), P(50 + k * 2.6, y, z + BH - 2.5));+ return d;+ }++ function drawBlade(b: Blade) {+ const o = b.sp.x;+ if (o === b.drawn) return;+ b.drawn = o;+ const yf = D + o + FT, zm = b.z + BH / 2;+ const ch = slab(P, b.body, null, D, D + o + 0.5);+ // the slide: where the chassis's side rides out along its rail+ put(b.chassis, { sil: ch.sil, crease: seg(P(W, D, zm), P(W, D + o, zm)) });+ put(b.plate, slab(P, b.face, b.faceIn, D + o, yf));+ b.marks.setAttribute("d", marks(b, yf));+ place(b.lamp, P(W - 5, yf, zm));+ }++ function light(b: Blade) {+ if (b === lit) return;+ if (lit) { lit.plate.sil.classList.remove("hi"); lit.lamp.setAttribute("class", "dot off"); }+ lit = b;+ lit.plate.sil.classList.add("hi");+ lit.lamp.setAttribute("class", "dot");+ }++ const B = register(stage, (dt) => {+ let m = false;+ for (const b of blades) { if (stepS(b.sp, dt)) m = true; drawBlade(b); }+ return m;+ });+ bag.add(B.unregister);++ // The hit test: the pointer is put on the rack's planes with every blade home, which never move.+ const o0 = P(0, 0, 0), E = [P(1, 0, 0), P(0, 1, 0), P(0, 0, 1)].map((p) => [p[0] - o0[0], p[1] - o0[1]]);+ /** The world point under screen point p on the plane where coordinate `axis` is c. */+ function onPlane(p: Vec2, axis: number, c: number): Vec3 {+ const [a, k] = [0, 1, 2].filter((n) => n !== axis), ea = E[a], ek = E[k];+ const rx = p[0] - o0[0] - c * E[axis][0], ry = p[1] - o0[1] - c * E[axis][1], det = ea[0] * ek[1] - ea[1] * ek[0];+ const w: Vec3 = [0, 0, 0];+ w[axis] = c; w[a] = (rx * ek[1] - ry * ek[0]) / det; w[k] = (ea[0] * ry - ea[1] * rx) / det;+ return w;+ }+ /** The pointer's height, in blades from the bottom one, or null off the rack: first on each faceplate where it+ * stands at rest, top down as a higher blade covers a lower one; then on the closed front, and the side panel. */+ function hit(p: Vec2): number | null {+ for (let i = N - 1; i >= 0; i--) {+ const q = onPlane(p, 1, D + FT + OUT * REST[i]), z = (q[2] - ZB - BH / 2) / U;+ if (q[0] >= -EAR && q[0] <= W + EAR && Math.abs(z - i) <= 0.5) return z;+ }+ const f = onPlane(p, 1, D + FT), s = onPlane(p, 0, X1);+ let z: number | null = null;+ if (f[0] >= X0 - OUT - 4 && f[0] <= X1 && f[2] >= -OUT * 0.8 && f[2] <= H) z = f[2];+ else if (s[1] >= 0 && s[1] <= D && s[2] >= 0 && s[2] <= H + 4) z = s[2];+ return z === null ? null : clamp((z - ZB - BH / 2) / U, 0, N - 1);+ }++ function retarget() {+ if (over === null) {+ for (const b of blades) b.sp.t = OUT * REST[b.i];+ light(blades[LIT]); read.textContent = "rest";+ } else {+ for (const b of blades) b.sp.t = OUT * falloff(Math.max(0, Math.abs(b.i - over) - 0.5) / R);+ const a = Math.round(over);+ light(blades[a]); read.textContent = "blade " + (a + 1);+ }+ B.wake();+ }+ light(blades[LIT]);++ bag.add(pointer(stage, {+ move: (p) => { over = hit(p); retarget(); },+ leave: () => { over = null; retarget(); },+ }));+ bag.add(() => svg.replaceChildren());++ return {+ set: (v) => { R = v; if (over !== null) retarget(); },+ destroy: bag.dispose,+ };+};diff --git a/packages/hairline/src/figures/terminal.ts b/packages/hairline/src/figures/terminal.tsnew file mode 100644index 0000000..6e5e094--- /dev/null+++ b/packages/hairline/src/figures/terminal.ts@@ -0,0 +1,164 @@+import { Cam, clamp, fillet, fit, poly, prism, proj, rings, rrect, type Ring, type Sample, type Vec2 } from "../core/iso";+import { spring, stepS, type Spring } from "../core/motion";+import { disposer, mk, pointer, put, register, solid, type FigureMount, type Solid } from "../core/stage";++/**+ * Terminal: a terminal window floating upright as a thin rounded slab. A title+ * bar with its three round buttons across the top, a prompt bar across the+ * foot with a chevron and a block cursor, and between them the output: rows+ * of rounded bars, indented and of different lengths, as code and logs are.+ * The pointer's height scrolls back through twenty-four lines of history on a+ * spring; lines leaving the top pass in behind the title bar, and new ones+ * come up from behind the prompt bar, cut where they meet it. The line under the+ * pointer lifts off the slab, and its neighbours less, each on its own spring.+ * At rest the window is scrolled back half a line and one long line is caught+ * lifted, bright. The slider is how far the lift spreads, in lines.+ *+ * The slab stands in the x–z plane and faces +y, so the figure draws in its+ * own frame: u across, v up, w out of the face, P2(u, v, w) = P(u, w, v).+ * The pattern: scrub and pick. One spring for the scroll, a spring per line+ * for its lift, a falloff by distance, and a hit test on the rest planes.+ */++const N = 24, V = 7, G = 11, T = 2.1, LH = 1.8, CH = 3.9, LIFT = 5.5, HB = 3.4, SLAB = 3;+const W = 150, TB = 17, PB = 17, PAD = 11, IN = 2.5, FIRST = 37;+const VB = PB, VA = PB + V * G, H = VA + TB, E = 4;+/** The history, oldest first: an indent in cells, then each token's length in cells. */+const HIST = [+ "0 5 12", "2 7 3 9", "2 14", "4 6 10", "4 18", "2 3", "0 2", "0 2 6 8",+ "0 26", "0 20", "0 11 4", "2 9 12", "2 5 3 7", "4 16", "4 8 8", "2 4",+ "0 3 14", "0 24", "0 30", "0 17", "2 6 11", "2 13", "0 9 5", "0 4 7",+];+/** Rest: scrolled back part way into a line, with line 18 lifted and its neighbours following. */+const REST_TOP = N - V - 2.6, REST_LINE = 18, REST_R = 2;++/** The share of the full lift a line takes, d lines from the one under the pointer: all of it there, none past R. */+const falloff = (d: number, R: number) => clamp(1 - d / R, 0, 1);+const smooth = (t: number) => t * t * (3 - 2 * t);+/** A ring sample faces the camera: its normal, in the slab's u–v plane, against the view direction (x .612, z .5). */+const front = (q: Sample) => 0.612 * q.nu + 0.5 * q.nv > 0;+/** A ring cut to the window between the bars: whatever lies past a bar is pressed flat against it. */+const cut = (ring: Ring): Ring => ring.map((q) => ({ ...q, v: clamp(q.v, VB, VA) }));++type Seg = { x0: number; x1: number; el: Solid };+type Row = { j: number; segs: Seg[]; sp: Spring; drawn: string };+type Over = "prompt" | number | null;++export const mount: FigureMount = ({ stage, svg, read }, value) => {+ const bag = disposer();+ const C = Cam(45, 0.5, 1.62);+ const W3 = (u: number, v: number, w: number): [number, number, number] => [u, w, v];+ fit(C, [W3(0, 0, -SLAB), W3(W, 0, -SLAB), W3(0, H, -SLAB), W3(W, H, -SLAB), W3(W, 0, HB + 2.8), W3(0, H, HB + 1.3), W3(PAD, VA - 4, LIFT + LH)], 200, 166);+ const P = proj(C), P2 = (u: number, v: number, w: number) => P(u, w, v);+ let R = value, over: Over = null, lit: Element[] = [];++ const g = mk("g", {}, svg);+ const [sr, si] = rings(0, 0, W, H, 9, 2);+ put(solid(g), prism(P2, front, sr, si, -SLAB, 0));++ // The history, oldest (highest) first. Each token is a pill, cut to the window as it is drawn.+ const rows: Row[] = HIST.map((s, j) => {+ const [ind, ...tok] = s.split(" ").map(Number), segs: Seg[] = [];+ let at = ind;+ for (const n of tok) {+ const x0 = PAD + at * CH;+ segs.push({ x0, x1: x0 + n * CH - 1.4, el: solid(g) });+ at += n + 1;+ }+ return { j, segs, sp: spring(0, { eps: 0.01 }), drawn: "" };+ });++ // The prompt bar, its chevron (two strokes joined into one shape) and the block cursor, painted after the+ // lines as the title bar is: a line coming up out of it rises from behind it, cut flat inside it.+ const [pr, pi] = rings(IN, IN, W - IN, VB, 6, 1.4);+ put(solid(g), prism(P2, front, pr, pi, 0, HB));+ const cy = (IN + VB) / 2;+ const chev = fillet([[0, 6.2], [8.5, 0], [0, -6.2], [0, -3.1], [4.25, 0], [0, 3.1]], [0.9, 1.1, 0.9, 0.5, 0.6, 0.5]);+ const chevEl = mk("path", { d: poly(chev.map(([x, y]) => P2(PAD + x, cy + y, HB))), class: "nf" }, g);+ const [kr, ki] = rings(PAD + 13, cy - 5.2, PAD + 13 + CH * 1.5, cy + 5.2, 1.2, 0.8);+ const cursor = solid(g);+ put(cursor, prism(P2, front, kr, ki, HB, HB + 2.8));++ // The title bar and its buttons, painted after the lines: a line going up passes in behind it.+ const [tr, ti] = rings(IN, VA, W - IN, H - IN, 6, 1.4);+ put(solid(g), prism(P2, front, tr, ti, 0, HB));+ for (let i = 0; i < 3; i++) {+ const cx = PAD + i * 8.5, cv = (VA + H - IN) / 2;+ const [r, ri] = rings(cx - 2.8, cv - 2.8, cx + 2.8, cv + 2.8, 2.8, 0.8);+ put(solid(g), prism(P2, front, r, ri, HB, HB + 1.3));+ }++ /** Row j with the window scrolled to `top` lines: cut to the window, and lifted less as it nears either bar. */+ function drawRow(rw: Row, top: number) {+ const key = top + "|" + rw.sp.x;+ if (key === rw.drawn) return;+ rw.drawn = key;+ const vc = VA - (rw.j - top + 0.5) * G, v0 = Math.max(vc - T, VB), v1 = Math.min(vc + T, VA);+ const env = smooth(clamp((VA - vc - T) / E, 0, 1)) * smooth(clamp((vc - T - VB) / E, 0, 1));+ const w0 = rw.sp.x * env;+ for (const s of rw.segs) {+ if (v1 - v0 < 0.05) { put(s.el, { sil: "", crease: "" }); continue; }+ const ring = cut(rrect(s.x0, vc - T, s.x1, vc + T, T, 4)), inner = cut(rrect(s.x0 + 0.7, vc - T + 0.7, s.x1 - 0.7, vc + T - 0.7, T - 0.7, 4));+ put(s.el, prism(P2, front, ring, inner, w0, w0 + LH));+ }+ }++ function light(els: Element[]) {+ for (const el of lit) el.classList.remove("hi");+ lit = els;+ for (const el of lit) el.classList.add("hi");+ }++ const top = spring(REST_TOP, { eps: 0.002 });+ const B = register(stage, (dt) => {+ let m = stepS(top, dt);+ for (const rw of rows) { if (stepS(rw.sp, dt)) m = true; drawRow(rw, top.x); }+ return m;+ });+ bag.add(B.unregister);++ /** The slab-frame point [u, v] under a screen point, on the plane w. */+ function onFace([sx, sy]: Vec2, w: number): Vec2 {+ const o = P2(0, 0, w), a = P2(1, 0, w), b = P2(0, 1, w);+ const ax = a[0] - o[0], ay = a[1] - o[1], bx = b[0] - o[0], by = b[1] - o[1], det = ax * by - ay * bx;+ return [((sx - o[0]) * by - (sy - o[1]) * bx) / det, (ax * (sy - o[1]) - ay * (sx - o[0])) / det];+ }+ /** Where the pointer is, on the rest planes, nearest first: "prompt", a depth down the rows from 0 to 1, or null off the window. */+ function hit(p: Vec2): Over {+ const qb = onFace(p, HB), inU = (q: Vec2) => q[0] > IN && q[0] < W - IN;+ if (inU(qb) && qb[1] > IN && qb[1] < VB) return "prompt";+ if (inU(qb) && qb[1] > VA && qb[1] < H - IN) return 0;+ const q = onFace(p, 0);+ if (q[0] < 0 || q[0] > W || q[1] < 0 || q[1] > H) return null;+ return q[1] <= VB ? "prompt" : clamp((VA - G / 2 - q[1]) / ((V - 1) * G), 0, 1);+ }++ function retarget() {+ let t: number, c: number, r = R;+ if (over === null) { t = REST_TOP; c = REST_LINE; r = REST_R; read.textContent = "rest"; }+ else if (over === "prompt") { t = N - V; c = -1; read.textContent = "prompt"; }+ else {+ // The pointer runs over the row centres; the column scrolls with it, and the line nearest it is taken, kept clear of both bars.+ t = over * (N - V);+ c = clamp(Math.round(over * (N - 1)), Math.ceil(t), Math.floor(t + V - 1));+ read.textContent = "line " + (FIRST + c);+ }+ top.t = t;+ for (const rw of rows) rw.sp.t = c < 0 ? 0 : LIFT * falloff(Math.abs(rw.j - c), r);+ light(c < 0 ? [cursor.sil, chevEl] : rows[c].segs.map((s) => s.el.sil));+ B.wake();+ }+ retarget();+ for (const rw of rows) rw.sp.x = rw.sp.t;++ bag.add(pointer(stage, {+ move: (p) => { over = hit(p); retarget(); },+ leave: () => { over = null; retarget(); },+ }));+ bag.add(() => svg.replaceChildren());++ return {+ set: (v) => { R = v; if (over !== null) retarget(); },+ destroy: bag.dispose,+ };+};diff --git a/packages/hairline/src/index.ts b/packages/hairline/src/index.tsindex 4da0df8..1423a9d 100644--- a/packages/hairline/src/index.ts+++ b/packages/hairline/src/index.ts@@ -1,4 +1,6 @@import { create, type Figure, type HairlineOptions } from "./mount";+import { mount as branchesEngine } from "./figures/branches";+import { mount as cabinetEngine } from "./figures/cabinet";import { mount as elevatorEngine } from "./figures/elevator";import { mount as explodedEngine } from "./figures/exploded";import { mount as keyboardEngine } from "./figures/keyboard";@@ -7,11 +9,12 @@ import { mount as phoneEngine } from "./figures/phone";import { mount as phosphorEngine } from "./figures/phosphor";import { mount as riffleEngine } from "./figures/riffle";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";/**- * @lucasmarkes/hairline — ten isometric line figures that answer the pointer.+ * @lucasmarkes/hairline — thirteen 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@@ -120,3 +123,33 @@ export function laptop(el: HTMLElement, options?: HairlineOptions): Figure {engine: laptopEngine,}, el, options);}++/** A terminal window: the pointer's height scrolls back through its history, and the line under it lifts off the screen. `intensity` spreads the lift over more lines. */+export function terminal(el: HTMLElement, options?: HairlineOptions): Figure {+ return create({+ id: "terminal",+ label: "A terminal window: the pointer's height scrolls back through its history, and the line under it lifts off the screen.",+ rest: "rest",+ engine: terminalEngine,+ }, el, options);+}++/** A rack of twelve blades: the pointer's height pulls the nearest ones out on their rails, the farther the less. `intensity` pulls out more blades. */+export function cabinet(el: HTMLElement, options?: HairlineOptions): Figure {+ return create({+ id: "cabinet",+ label: "A rack of twelve blades: the pointer's height pulls the nearest ones out on their rails, the farther the less.",+ rest: "rest",+ engine: cabinetEngine,+ }, el, options);+}++/** 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 function branches(el: HTMLElement, options?: HairlineOptions): Figure {+ return create({+ id: "branches",+ label: "A commit graph on a board: the commit under the pointer rises, and its history rises after it, the farther back the less.",+ rest: "rest",+ engine: branchesEngine,+ }, el, options);+}diff --git a/packages/hairline/src/intensity.ts b/packages/hairline/src/intensity.tsindex 05cc88d..99b9ea3 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";+export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches";/** 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]> = {@@ -21,6 +21,9 @@ export const TABLE: Record<FigureId, readonly [number, number, number]> = {elevator: [40, 100, 220], // stiffness, spring unitsphone: [16, 28, 40], // gap, viewBox unitslaptop: [100, 125, 150], // lid, degrees+ terminal: [1, 2, 3.5], // spread, lines+ cabinet: [1.5, 3, 5], // reach, blades+ branches: [1, 3, 6], // reach, commits};export const DEFAULT = 0.5;diff --git a/packages/hairline/src/react.tsx b/packages/hairline/src/react.tsxindex fb35931..52679f0 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 { elevator, exploded, keyboard, laptop, phone, phosphor, riffle, slow, terrain, turntable, type Figure, type HairlineOptions } from "./index";+import { branches, cabinet, elevator, exploded, keyboard, laptop, phone, phosphor, riffle, slow, terminal, terrain, turntable, type Figure, type HairlineOptions } from "./index";/**- * @lucasmarkes/hairline/react — the ten figures as components.+ * @lucasmarkes/hairline/react — the thirteen 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.@@ -73,3 +73,9 @@ export const Elevator = make("Elevator", elevator);export const Phone = make("Phone", phone);/** A thin laptop: the pointer's height sets how far the lid stands open, and the lid follows it on a spring. `intensity` lets the lid open wider. */export const Laptop = make("Laptop", laptop);+/** A terminal window: the pointer's height scrolls back through its history, and the line under it lifts off the screen. `intensity` spreads the lift over more lines. */+export const Terminal = make("Terminal", terminal);+/** A rack of twelve blades: the pointer's height pulls the nearest ones out on their rails, the farther the less. `intensity` pulls out more blades. */+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);diff --git a/packages/hairline/test/browser/entry.ts b/packages/hairline/test/browser/entry.tsindex 6b64ff6..35180c6 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";+type Id = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches";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 2a635f8..7eefd48 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"] as const;+const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches"] 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 56278b2..0a385d2 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 { elevator, exploded, keyboard, laptop, phone, phosphor, riffle, slow, terrain, turntable } from "../src/index";+import { branches, cabinet, elevator, exploded, keyboard, laptop, phone, phosphor, riffle, slow, terminal, terrain, turntable } from "../src/index";import { css } from "../src/core/styles";-const ALL = { riffle, terrain, exploded, phosphor, slow, turntable, keyboard, elevator, phone, laptop };+const ALL = { riffle, terrain, exploded, phosphor, slow, turntable, keyboard, elevator, phone, laptop, terminal, cabinet, branches };const key = (el: Element, k: string) => el.dispatchEvent(new KeyboardEvent("keydown", { key: k, bubbles: true, cancelable: true }));describe("mount", () => {@@ -146,6 +146,9 @@ describe("intensity", () => {elevator: [[200, 60], 8],phone: [[100, 80], 100],laptop: [[200, 60], 60],+ terminal: [[200, 120], 20],+ cabinet: [[200, 120], 8],+ branches: [[200, 160], 8],};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 0d5d4d8..a9ccc36 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 { Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terrain, Turntable } from "../src/react";+import { Branches, Cabinet, Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terminal, Terrain, Turntable } 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 /></>);+ const { container } = render(<><Riffle /><Terrain /><Exploded /><Phosphor /><Slow /><Turntable /><Keyboard /><Elevator /><Phone /><Laptop /><Terminal /><Cabinet /><Branches /></>);const ids = [...container.children].map((el) => el.getAttribute("data-hairline"));- expect(ids).toEqual(["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop"]);+ expect(ids).toEqual(["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches"]);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].map((c) => c.displayName))- .toEqual(["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard", "Elevator", "Phone", "Laptop"]);+ 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"]);});});diff --git a/packages/hairline/test/types.test-d.tsx b/packages/hairline/test/types.test-d.tsxindex 2ac489b..1654132 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 { elevator, exploded, keyboard, laptop, phone, phosphor, riffle, slow, terrain, turntable, type Figure, type HairlineOptions } from "../src/index";+import { branches, cabinet, elevator, exploded, keyboard, laptop, phone, phosphor, riffle, slow, terminal, terrain, turntable, type Figure, type HairlineOptions } from "../src/index";import * as vanilla from "../src/index";import * as components from "../src/react";-import { Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terrain, Turntable, type HairlineProps } from "../src/react";+import { Branches, Cabinet, Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terminal, Terrain, Turntable, 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]) {+for (const mount of [riffle, terrain, exploded, phosphor, slow, turntable, keyboard, elevator, phone, laptop, terminal, cabinet, branches]) {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">>();-yes<Equal<keyof typeof components, "Riffle" | "Terrain" | "Exploded" | "Phosphor" | "Slow" | "Turntable" | "Keyboard" | "Elevator" | "Phone" | "Laptop">>();+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">>();// @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]) {+for (const C of [Riffle, Terrain, Exploded, Phosphor, Slow, Turntable, Keyboard, Elevator, Phone, Laptop, Terminal, Cabinet, Branches]) {// @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 37b6aa7..7f1b371 100644--- a/registry/src/hairline.tsx+++ b/registry/src/hairline.tsx@@ -57,3 +57,15 @@ export function Phone({ style, ...props }: ComponentProps<typeof Hairline.Phone>export function Laptop({ style, ...props }: ComponentProps<typeof Hairline.Laptop>) {return <Hairline.Laptop style={{ ...tokens, ...style }} {...props} />;}++export function Terminal({ style, ...props }: ComponentProps<typeof Hairline.Terminal>) {+ return <Hairline.Terminal style={{ ...tokens, ...style }} {...props} />;+}++export function Cabinet({ style, ...props }: ComponentProps<typeof Hairline.Cabinet>) {+ return <Hairline.Cabinet style={{ ...tokens, ...style }} {...props} />;+}++export function Branches({ style, ...props }: ComponentProps<typeof Hairline.Branches>) {+ return <Hairline.Branches style={{ ...tokens, ...style }} {...props} />;+}diff --git a/registry/validate.mjs b/registry/validate.mjsindex 9f97a24..c352e1d 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"]) {+for (const name of ["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard", "Elevator", "Phone", "Laptop", "Terminal", "Cabinet", "Branches"]) {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 140fe23..66f95d7 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"] },+ 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"] },};const only = process.argv[2];if (only && !FIXTURES[only]) { console.error(`Unknown fixture "${only}". Use: ${Object.keys(FIXTURES).join(" | ")}`); process.exit(2); }