Isometric line figures that answer the pointer. For React and for anything with a DOM.
Elevator: four floors beside an open shaft, and the car travels to the one the pointer's height picks
Lucas Marques7785db98f23d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 71bb463..712b54e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -11,6 +11,9 @@ Every release of `@lucasmarkes/hairline`. The format follows- `keyboard` and `Keyboard`: a sixty-key board. The key under the pointersinks, and its neighbours follow it down, less the further away. A stronger`intensity` sinks a wider patch of keys.+- `elevator` and `Elevator`: four floors beside an open shaft. The pointer's+ height picks a floor, and the car travels there through the ones between.+ A stronger `intensity` makes the car travel faster.## 0.1.0 - 2026-10-01diff --git a/README.md b/README.mdindex bdb468b..f76923d 100644--- a/README.md+++ b/README.md@@ -1,6 +1,6 @@# hairline-Seven isometric line figures that answer the pointer. For React and for anything with a DOM.+Eight 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)@@ -62,6 +62,7 @@ A figure draws into the element you give it, at the element's width and a 5:4 as| `slow` | `Slow` | Crates riding a belt through a gate. Hovering slows the clock without stopping it. | Time slows down more. || `turntable` | `Turntable` | Blocks on a turntable. A flick spins it; it settles on the nearest quarter turn. | The spin coasts longer. || `keyboard` | `Keyboard` | A sixty-key board. The key under the pointer sinks, and its neighbours follow it down. | A wider patch of keys sinks. |+| `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. |## Options@@ -105,7 +106,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 seven 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 eight 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 02530e2..da8659d 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 { Exploded, Keyboard, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";+import { Elevator, Exploded, Keyboard, Phosphor, Riffle, Slow, 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 };+const SMALL = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard, elevator: Elevator };/** 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 7853a9e..bd57d6b 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 { Exploded, Keyboard, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";+import { Elevator, Exploded, Keyboard, Phosphor, Riffle, Slow, 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 };+const COMPONENTS: Record<FigureId, typeof Riffle> = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard, elevator: Elevator };type Filter = "all" | ShelfId;diff --git a/apps/site/components/reel.tsx b/apps/site/components/reel.tsxindex 9187410..9d78303 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 { Exploded, Keyboard, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";+import { Elevator, Exploded, Keyboard, Phosphor, Riffle, Slow, 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 };+const COMPONENTS = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard, elevator: Elevator };/*** One pass of a pointer over each figure, in its viewBox (400 × 320): [x, y, ms]. Each path does the@@ -18,6 +18,7 @@ const DEMO: Record<keyof typeof COMPONENTS, [number, number, number][]> = {slow: [[120, 250, 0], [200, 165, 700], [206, 160, 2600]],turntable: [[100, 170, 0], [125, 168, 400], [310, 160, 620], [320, 158, 900]],keyboard: [[126, 116, 0], [290, 198, 2000], [172, 165, 3000]],+ elevator: [[200, 250, 0], [200, 60, 1400], [200, 175, 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 d7eecc1..1f7b0c0 100644--- a/apps/site/lib/catalogue.ts+++ b/apps/site/lib/catalogue.ts@@ -39,7 +39,7 @@ export const SHELVES: Shelf[] = [id: "machines", title: "Machines", color: "#f59e0b", figures: [drawn("slow"),drawn("turntable"),- planned("elevator", "Elevator", "Four floors with the shaft open and the car inside. The pointer's height picks the floor; the car travels there.", "The car travels faster between floors."),+ drawn("elevator"),],},{diff --git a/apps/site/lib/figures.ts b/apps/site/lib/figures.tsindex c4a01c8..4dff012 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";+export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator";export type FigureDoc = {id: FigureId;@@ -71,9 +71,16 @@ export const FIGURES: FigureDoc[] = [stronger: "A wider patch of keys sinks.",parameter: { name: "radius", unit: "keys" },},+ {+ id: "elevator",+ name: "Elevator",+ summary: "Four floors with the shaft open and the car inside. The pointer's height picks the floor; the car travels there.",+ stronger: "The car travels faster between floors.",+ parameter: { name: "stiffness", unit: "spring units" },+ },];-/** How many figures the package has, as the prose writes it: "seven". */+/** How many figures the package has, as the prose writes it: "eight". */export const COUNT = spell(FIGURES.length);/** Each figure's number at intensity 0, 0.5 and 1: a copy of the package's table. */@@ -85,6 +92,7 @@ export const INTENSITY: Record<FigureId, readonly [number, number, number]> = {slow: [0.6, 0.2, 0.05],turntable: [200, 650, 1500],keyboard: [1, 2, 3.5],+ elevator: [40, 100, 220],};/** 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 6f097d6..4ae27c9 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 seven empty boxes among nineteen tiles, then draws them with a clean console", async ({ page, request }) => {+test("/figures prerenders eight 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(7);+ expect(html.match(/<div style="aspect-ratio:5 \/ 4"><\/div>/g)).toHaveLength(8);expect(html.match(/class="fig-tile"/g)).toHaveLength(19);- expect(html.match(/class="fig-tile" data-planned=""/g)).toHaveLength(12);+ expect(html.match(/class="fig-tile" data-planned=""/g)).toHaveLength(11);const noise = watch(page);await page.goto("/figures");await expect(tiles(page)).toHaveCount(19);- await expect(page.locator(".fig-tile [data-hairline] > svg")).toHaveCount(7);- await expect(page.locator(".fig-tile .fig-ghost")).toHaveCount(12);+ await expect(page.locator(".fig-tile [data-hairline] > svg")).toHaveCount(8);+ await expect(page.locator(".fig-tile .fig-ghost")).toHaveCount(11);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("Elevator, planned");+ await expect(page.locator(".fig-tile[data-planned] .fig-name").first()).toHaveAccessibleName("Phone, planned");expect(noise).toEqual([]);});@@ -44,7 +44,7 @@ test("the shelves filter: All is pressed at first, a shelf shows only itself andawait expect(shelf(page, "All")).toHaveAttribute("aria-pressed", "false");await expect(page.locator(".doc-section h2")).toHaveText(["Machines"]);await expect(tiles(page)).toHaveCount(3);- await expect(page.locator(".fig-tile [data-hairline] > svg")).toHaveCount(2);+ await expect(page.locator(".fig-tile [data-hairline] > svg")).toHaveCount(3);expect(new URL(page.url()).hash).toBe("#machines");// the plate sits under the pressed rowawait expect.poll(() => page.evaluate(() => {diff --git a/apps/site/test/site.spec.ts b/apps/site/test/site.spec.tsindex a6d3eda..da51f4d 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"];+const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator"];const MANAGERS = [["npm", "npm i @lucasmarkes/hairline"],["pnpm", "pnpm add @lucasmarkes/hairline"],@@ -286,9 +286,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", /^Seven isometric line figures/],+ ["/", "hairline", /^Eight isometric line figures/],["/figures", "Figures", /^Seven shelves, nineteen figures, grouped by what they draw/],- ["/docs", "Docs", /^Seven isometric line figures/],+ ["/docs", "Docs", /^Eight 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 ab9ef27..7e71146 100644--- a/fixtures/vite-vanilla/index.html+++ b/fixtures/vite-vanilla/index.html@@ -18,6 +18,7 @@<div id="slow"></div><div id="turntable"></div><div id="keyboard"></div>+ <div id="elevator"></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 d96d3bd..43c6f80 100644--- a/fixtures/vite-vanilla/src/main.ts+++ b/fixtures/vite-vanilla/src/main.ts@@ -1,6 +1,6 @@-import { exploded, keyboard, phosphor, riffle, slow, terrain, turntable, type Figure } from "@lucasmarkes/hairline";+import { elevator, exploded, keyboard, phosphor, riffle, slow, terrain, turntable, type Figure } from "@lucasmarkes/hairline";-/** No framework: seven elements, seven calls. */+/** No framework: eight elements, eight calls. */const el = (id: string) => document.getElementById(id)!;const read = el("read");@@ -14,5 +14,6 @@ phosphor(el("phosphor"), { theme: "dark" });slow(el("slow"));turntable(el("turntable"));keyboard(el("keyboard"));+elevator(el("elevator"));cards.update({ intensity: 0.8 });diff --git a/package.json b/package.jsonindex 05b9e20..5d2a7e5 100644--- a/package.json+++ b/package.json@@ -2,7 +2,7 @@"name": "hairline-monorepo","version": "0.0.0","private": true,- "description": "Seven isometric line figures that answer the pointer",+ "description": "Eight 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 fe0bd22..ea5fc33 100644--- a/packages/hairline/package.json+++ b/packages/hairline/package.json@@ -1,7 +1,7 @@{"name": "@lucasmarkes/hairline","version": "0.2.0",- "description": "Seven isometric line figures that answer the pointer. For React and for anything with a DOM.",+ "description": "Eight 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": "12.8 kB"+ "limit": "14 kB"},{"name": "vanilla, one figure",@@ -94,7 +94,7 @@{"name": "react, every component","path": "dist/react.js",- "limit": "13.2 kB",+ "limit": "14.4 kB","ignore": ["react","react/jsx-runtime"diff --git a/packages/hairline/src/figures/elevator.ts b/packages/hairline/src/figures/elevator.tsnew file mode 100644index 0000000..feed24a--- /dev/null+++ b/packages/hairline/src/figures/elevator.ts@@ -0,0 +1,142 @@+import { Cam, circ, clamp, facing, fillet, fit, hull, open, poly, prism, proj, rings, rrect, seg, type Vec2, type Vec3 } from "../core/iso";+import { spring, stepS } from "../core/motion";+import { disposer, flatDot, mk, place, pointer, put, register, solid, type FigureMount } from "../core/stage";++/**+ * Elevator: an open shaft, two walls at its back, the car inside it on two+ * guide rails, and four floors running off to the right of it, one landing+ * in front of the car's door on each. A rope runs from the car's crosshead+ * up through the head slab, over the traction sheave and down to a+ * counterweight that falls as the car rises. The pointer's height on the stage+ * picks a floor; the car travels there on a spring, through every floor in+ * between, and the floor it is bound for takes the bright stroke. At rest the+ * car is caught between the first and the second floor, bright. The slider is+ * the car's spring stiffness: stiffer travels faster.+ *+ * The pattern: scrub and pick. A spring for where the car is, a choice read+ * from the fixed floors, never from the car on screen.+ */++type Box = [number, number, number, number];++const SX = 32, SY = 34, FH = 36, CH = 25, T = 2.5, NF = 4, TOP = 3 * FH + CH + 7;+const CAR: Box = [5, 7, 28, 27], RX = 16.5, CW: Box = [-8, 11, -2, 23], CWH = 17;+const WALL = 2;+/** The plinth: under the shaft, and under the floors where they run back past the shaft's wall, no further. */+const BASE = fillet([[-16, -2], [33, -2], [33, -56], [76, -56], [76, 38], [-16, 38]], [3, 2, 4, 6, 6, 6]);+/** A floor's outline: the plate to the right of the shaft and the landing in front of the car's door, as one L. */+const FLOOR = fillet([[33, -56], [72, -56], [72, -6], [43, -6], [43, 34], [33, 34]], [4, 4, 4, 3, 3, 3]);+const CWX = (CW[0] + CW[2]) / 2, SR = (RX - CWX) / 2;+/** The sheave's centre. */+const SC: Vec3 = [CWX + SR, SY / 2, TOP + 3 + SR + 2];+const REST_Z = 1.5 * FH - 4;+const NAMES = ["ground", "floor 1", "floor 2", "floor 3"];++export const mount: FigureMount = ({ stage, svg, read }, value) => {+ const bag = disposer();+ const C = Cam(45, 0.5, 1.3);+ fit(C, [[-16, -56, -8], [76, 38, -8], [76, -56, -8], [-16, 38, -8], [SC[0], SC[1], SC[2] + SR]], 200, 166);+ const P = proj(C), front = facing(C);+ const g = mk("g", {}, svg);+ const block = (box: Box, r: number, b: number, z0: number, z1: number) => { const [o, i] = rings(...box, r, b); put(solid(g), prism(P, front, o, i, z0, z1)); };+ const line = (cls: string) => mk("path", { class: cls }, g);+ // A slab on any outline, convex or not: its silhouette is the far run of the+ // top joined to the near run of the underside; the top's near run is the crease.+ const slab = (pts: Vec2[], z0: number, z1: number) => {+ const n = pts.length, near = pts.map((p, i) => { const q = pts[(i + 1) % n]; return q[1] - p[1] - (q[0] - p[0]) > 0; });+ const runOf = (want: boolean) => {+ const s = near.findIndex((f, i) => f === want && near[(i + n - 1) % n] !== want), out: Vec2[] = [];+ for (let i = s; near[i % n] === want; i++) out.push(pts[i % n]);+ return out.concat([pts[(s + out.length) % n]]);+ };+ const at = (r: Vec2[], z: number) => r.map((p) => P(p[0], p[1], z)), back = runOf(false), fore = runOf(true);+ const sil = mk("path", { class: "sil", d: poly(at(back, z1).concat(at(fore, z0))) }, g);+ mk("path", { class: "nf lo", d: open(at(fore, z1)) }, g);+ return sil;+ };++ // The plinth, the shaft's two back walls, then back to front: the far rail,+ // the counterweight and its rope, the car, the near rail.+ slab(BASE, -8, -T);+ block([-14 - WALL, -WALL, -14, SY], 1, 0.5, -T, TOP);+ block([-14, -WALL, SX, 0], 1, 0.5, -T, TOP);+ block([RX - 1.3, 3, RX + 1.3, 5.4], 0.8, 0.5, -T, TOP);+ const [cwo, cwi] = rings(...CW, 1.6, 0.8);+ const cw = solid(g), cwBands = line("nf lo"), cwRope = line("nf");+ const [co, ci] = rings(...CAR, 2.4, 1.1);+ const car = solid(g), door = line("nf"), split = line("nf lo");+ const [ho, hi] = rings(RX - 1.7, 5.4, RX + 1.7, 28.6, 0.8, 0.5);+ const head = solid(g), rope = line("nf");+ block([RX - 1.3, 28.6, RX + 1.3, 31], 0.8, 0.5, -T, TOP);++ // The head slab, the machine behind the sheave, the ropes up to it, the sheave.+ block([-14 - WALL, -WALL, SX + 1, SY + 1], 4, 1.4, TOP, TOP + 3);+ block([CWX + 2, 4, RX - 2, SY / 2 - 3], 2, 1, TOP + 3, SC[2] + 4);+ mk("path", { class: "nf", d: seg(P(RX, SY / 2, TOP + 3), P(RX, SY / 2, SC[2])) + seg(P(CWX, SY / 2, TOP + 3), P(CWX, SY / 2, SC[2])) }, g);+ const disc = (y: number, r: number) => circ(r, 28).map((q) => P(SC[0] + q.u, y, SC[2] + q.v));+ put(solid(g), { sil: poly(hull(disc(SY / 2 - 1.8, SR).concat(disc(SY / 2 + 1.8, SR)))), crease: poly(disc(SY / 2 + 1.8, SR - 1.4)) });+ const spokes = line("nf lo");+ mk("path", { class: "nf lo", d: poly(disc(SY / 2 + 1.8, 2.6)) }, g);++ // The floors, bottom to top: each an L-shaped slab, two columns at its+ // right holding up the next, and its number in dots on the landing by the door.+ const lands: Array<{ sil: SVGPathElement; dots: SVGEllipseElement[] }> = [];+ for (let f = 0; f < NF; f++) {+ const z = f * FH, sil = slab(FLOOR, z - T, z);+ if (f < NF - 1) for (const y of [-53, -15]) block([62, y, 68, y + 6], 1.5, 0.8, z, z + FH - T);+ const dots: SVGEllipseElement[] = [];+ for (let k = 0; k <= f; k++) { const d = flatDot(g, C, 0.8, "dot off"); place(d, P(37, CAR[1] - 3 - k * 3, z)); dots.push(d); }+ lands.push({ sil, dots });+ }++ const sp = spring(REST_Z, { k: value, c: 1.8 * Math.sqrt(value) });+ let drawn = NaN, chosen: number | null = null;++ function draw(z: number) {+ const zc = 3 * FH - z + 6, mid = (CAR[1] + CAR[3]) / 2;+ put(cw, prism(P, front, cwo, cwi, zc, zc + CWH));+ cwBands.setAttribute("d", [5, 9, 13].map((v) => seg(P(CW[0] + 0.6, CW[3], zc + v), P(CW[2] - 0.6, CW[3], zc + v))).join(""));+ cwRope.setAttribute("d", seg(P(CWX, SY / 2, zc + CWH), P(CWX, SY / 2, TOP)));+ put(car, prism(P, front, co, ci, z, z + CH));+ door.setAttribute("d", poly(rrect(CAR[1] + 3.5, z + 1.2, CAR[3] - 3.5, z + CH - 4, 1.2, 4).map((q) => P(CAR[2], q.u, q.v))));+ split.setAttribute("d", seg(P(CAR[2], mid, z + 1.2), P(CAR[2], mid, z + CH - 4)));+ put(head, prism(P, front, ho, hi, z + CH, z + CH + 2.4));+ rope.setAttribute("d", seg(P(RX, SY / 2, z + CH + 2.4), P(RX, SY / 2, TOP)));+ // the sheave turns as the rope runs over it+ const a = z / SR, y = SY / 2 + 1.8, at = (t: number, r: number) => P(SC[0] + Math.cos(t) * r, y, SC[2] + Math.sin(t) * r);+ spokes.setAttribute("d", [0, 1, 2, 3, 4, 5].map((k) => seg(at(a + k * Math.PI / 3, 2.6), at(a + k * Math.PI / 3, SR - 1.4))).join(""));+ }++ const B = register(stage, (dt) => {+ const m = stepS(sp, dt);+ if (sp.x !== drawn) { drawn = sp.x; draw(sp.x); }+ return m;+ });+ bag.add(B.unregister);++ // The floor under the pointer: its height read on the fixed column of the car's door, against the floors, which never move.+ const base = P(CAR[2], SY / 2, 0)[1], perZ = base - P(CAR[2], SY / 2, 1)[1];+ const pick = (p: Vec2) => clamp(Math.floor(((base - p[1]) / perZ + 8) / FH), 0, NF - 1);++ function choose(f: number) {+ if (f === chosen) return;+ chosen = f;+ sp.t = f < 0 ? REST_Z : f * FH;+ car.sil.classList.toggle("hi", f < 0);+ lands.forEach((l, i) => {+ l.sil.classList.toggle("hi", i === f);+ l.dots.forEach((d) => d.setAttribute("class", i === f ? "dot m" : "dot off"));+ });+ read.textContent = f < 0 ? "rest" : NAMES[f];+ B.wake();+ }+ choose(-1);++ bag.add(pointer(stage, { move: (p) => choose(pick(p)), leave: () => choose(-1) }));+ bag.add(() => svg.replaceChildren());++ return {+ set: (v) => { sp.k = v; sp.c = 1.8 * Math.sqrt(v); B.wake(); },+ destroy: bag.dispose,+ };+};diff --git a/packages/hairline/src/index.ts b/packages/hairline/src/index.tsindex 4585264..ac983c3 100644--- a/packages/hairline/src/index.ts+++ b/packages/hairline/src/index.ts@@ -1,4 +1,5 @@import { create, type Figure, type HairlineOptions } from "./mount";+import { mount as elevatorEngine } from "./figures/elevator";import { mount as explodedEngine } from "./figures/exploded";import { mount as keyboardEngine } from "./figures/keyboard";import { mount as phosphorEngine } from "./figures/phosphor";@@ -8,7 +9,7 @@ import { mount as terrainEngine } from "./figures/terrain";import { mount as turntableEngine } from "./figures/turntable";/**- * @lucasmarkes/hairline — seven isometric line figures that answer the pointer.+ * @lucasmarkes/hairline — eight 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@@ -87,3 +88,13 @@ export function keyboard(el: HTMLElement, options?: HairlineOptions): Figure {engine: keyboardEngine,}, el, options);}++/** Four floors beside an open shaft. The pointer's height picks a floor, and the car travels there through the ones between. `intensity` makes the car travel faster. */+export function elevator(el: HTMLElement, options?: HairlineOptions): Figure {+ return create({+ id: "elevator",+ label: "Four floors beside an open shaft. The pointer's height picks a floor, and the car travels there through the ones between.",+ rest: "rest",+ engine: elevatorEngine,+ }, el, options);+}diff --git a/packages/hairline/src/intensity.ts b/packages/hairline/src/intensity.tsindex 20be915..66750dd 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";+export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator";/** 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]> = {@@ -18,6 +18,7 @@ export const TABLE: Record<FigureId, readonly [number, number, number]> = {slow: [0.6, 0.2, 0.05], // rate, × normal speedturntable: [200, 650, 1500], // coast, mskeyboard: [1, 2, 3.5], // radius, keys+ elevator: [40, 100, 220], // stiffness, spring units};export const DEFAULT = 0.5;diff --git a/packages/hairline/src/react.tsx b/packages/hairline/src/react.tsxindex 3f760b4..457ced9 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 { exploded, keyboard, phosphor, riffle, slow, terrain, turntable, type Figure, type HairlineOptions } from "./index";+import { elevator, exploded, keyboard, phosphor, riffle, slow, terrain, turntable, type Figure, type HairlineOptions } from "./index";/**- * @lucasmarkes/hairline/react — the seven figures as components.+ * @lucasmarkes/hairline/react — the eight 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.@@ -67,3 +67,5 @@ export const Slow = make("Slow", slow);export const Turntable = make("Turntable", turntable);/** A sixty-key board. The key under the pointer sinks, and its neighbours follow it down, less the further away. `intensity` widens how far the press reaches. */export const Keyboard = make("Keyboard", keyboard);+/** Four floors beside an open shaft. The pointer's height picks a floor, and the car travels there through the ones between. `intensity` makes the car travel faster. */+export const Elevator = make("Elevator", elevator);diff --git a/packages/hairline/test/browser/entry.ts b/packages/hairline/test/browser/entry.tsindex 94e1d88..42389d5 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";+type Id = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator";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 08b71fc..eec31ba 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"] as const;+const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator"] 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 362cedb..4f2ebb9 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 { exploded, keyboard, phosphor, riffle, slow, terrain, turntable } from "../src/index";+import { elevator, exploded, keyboard, phosphor, riffle, slow, terrain, turntable } from "../src/index";import { css } from "../src/core/styles";-const ALL = { riffle, terrain, exploded, phosphor, slow, turntable, keyboard };+const ALL = { riffle, terrain, exploded, phosphor, slow, turntable, keyboard, elevator };const key = (el: Element, k: string) => el.dispatchEvent(new KeyboardEvent("keydown", { key: k, bubbles: true, cancelable: true }));describe("mount", () => {@@ -143,6 +143,7 @@ describe("intensity", () => {slow: [[200, 160], 60],turntable: [[50, 176], 1, [120, 176], 1, [200, 176], 1, [280, 176], 1, [350, 176], 40],keyboard: [[200, 160], 20],+ elevator: [[200, 60], 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 6de6917..258132c 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 { Exploded, Keyboard, Phosphor, Riffle, Slow, Terrain, Turntable } from "../src/react";+import { Elevator, Exploded, Keyboard, Phosphor, Riffle, Slow, 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 /></>);+ const { container } = render(<><Riffle /><Terrain /><Exploded /><Phosphor /><Slow /><Turntable /><Keyboard /><Elevator /></>);const ids = [...container.children].map((el) => el.getAttribute("data-hairline"));- expect(ids).toEqual(["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard"]);+ expect(ids).toEqual(["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator"]);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].map((c) => c.displayName))- .toEqual(["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard"]);+ expect([Riffle, Terrain, Exploded, Phosphor, Slow, Turntable, Keyboard, Elevator].map((c) => c.displayName))+ .toEqual(["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard", "Elevator"]);});});diff --git a/packages/hairline/test/types.test-d.tsx b/packages/hairline/test/types.test-d.tsxindex 6a74241..62f21f7 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 { exploded, keyboard, phosphor, riffle, slow, terrain, turntable, type Figure, type HairlineOptions } from "../src/index";+import { elevator, exploded, keyboard, phosphor, riffle, slow, terrain, turntable, type Figure, type HairlineOptions } from "../src/index";import * as vanilla from "../src/index";import * as components from "../src/react";-import { Exploded, Keyboard, Phosphor, Riffle, Slow, Terrain, Turntable, type HairlineProps } from "../src/react";+import { Elevator, Exploded, Keyboard, Phosphor, Riffle, Slow, 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]) {+for (const mount of [riffle, terrain, exploded, phosphor, slow, turntable, keyboard, elevator]) {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">>();-yes<Equal<keyof typeof components, "Riffle" | "Terrain" | "Exploded" | "Phosphor" | "Slow" | "Turntable" | "Keyboard">>();+yes<Equal<keyof typeof vanilla, "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator">>();+yes<Equal<keyof typeof components, "Riffle" | "Terrain" | "Exploded" | "Phosphor" | "Slow" | "Turntable" | "Keyboard" | "Elevator">>();// @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]) {+for (const C of [Riffle, Terrain, Exploded, Phosphor, Slow, Turntable, Keyboard, Elevator]) {// @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 c7bf01c..4dd2d20 100644--- a/registry/src/hairline.tsx+++ b/registry/src/hairline.tsx@@ -45,3 +45,7 @@ export function Turntable({ style, ...props }: ComponentProps<typeof Hairline.Tuexport function Keyboard({ style, ...props }: ComponentProps<typeof Hairline.Keyboard>) {return <Hairline.Keyboard style={{ ...tokens, ...style }} {...props} />;}++export function Elevator({ style, ...props }: ComponentProps<typeof Hairline.Elevator>) {+ return <Hairline.Elevator style={{ ...tokens, ...style }} {...props} />;+}diff --git a/registry/validate.mjs b/registry/validate.mjsindex a0387ff..0ade8c3 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"]) {+for (const name of ["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard", "Elevator"]) {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 121208b..00106d7 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"] },+ 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"] },};const only = process.argv[2];if (only && !FIXTURES[only]) { console.error(`Unknown fixture "${only}". Use: ${Object.keys(FIXTURES).join(" | ")}`); process.exit(2); }