Skip to content

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

0.5.0: hub, relay, settle, format, rebuild and stack

Lucas Marques217e9abef0ed
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a777138..5c0cdf0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,31 @@ Every release of `@lucasmarkes/hairline`. The format follows
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow
[semver](https://semver.org/).
+## 0.5.0 - 2026-10-08
+
+### Added
+
+- `hub` and `Hub`: a hub and eight tiles on a grid. The tile under the pointer
+ rises and its link turns solid; its neighbours rise less. A stronger
+ `intensity` raises the tiles higher.
+- `relay` and `Relay`: a hub and four branches of tiles. The path to the leaf
+ under the pointer lights hop by hop, each tile rising in turn. A stronger
+ `intensity` makes each hop wait longer.
+- `settle` and `Settle`: twelve tiles lie crooked round a hub. As the pointer
+ nears it they slide into a tree and the links draw in. A stronger `intensity`
+ starts the tree from further away.
+- `format` and `Format`: a file of ten crooked lines. The pointer runs the
+ formatter down it, and every line above snaps square to its indent. A stronger
+ `intensity` starts the lines more crooked.
+- `rebuild` and `Rebuild`: a tree of package tiles. The one touched rises, and
+ every package that depends on it rises after it along the links. A stronger
+ `intensity` raises them higher.
+- `stack` and `Stack`: a call stack of five frames. The pointer's height picks
+ one, and the frames above lift away to open it. A stronger `intensity` lifts
+ them further.
+- Site: the Connectivity and Coding shelves hold six figures each, and each new
+ figure walks its own `tour` under `play`.
+
## 0.4.0 - 2026-10-07
### Added
diff --git a/README.md b/README.md
index 611efde..2a6aa21 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# hairline
-Twenty-seven isometric line figures that answer the pointer. For React and for anything with a DOM.
+Thirty-three isometric line figures that answer the pointer. For React and for anything with a DOM.
[![npm](https://img.shields.io/npm/v/@lucasmarkes/hairline)](https://www.npmjs.com/package/@lucasmarkes/hairline)
[![CI](https://github.com/lucasmarkes/hairline/actions/workflows/ci.yml/badge.svg)](https://github.com/lucasmarkes/hairline/actions/workflows/ci.yml)
@@ -82,6 +82,12 @@ A figure draws into the element you give it, at the element's width and a 5:4 as
| `drawer` | `Drawer` | A cabinet of three drawers. The pointer's height picks one; it slides out and shows two dividers with nothing between them. | The drawer opens further. |
| `basket` | `Basket` | A wire basket under a bail handle. It tilts toward the pointer and shows its bare floor; the handle swings after it. | The basket tilts further. |
| `plot` | `Plot` | A bar chart with seven flat tabs where the bars would stand. The pointer brushes them; each lifts a little and drops back to zero. | The tabs lift higher. |
+| `hub` | `Hub` | A hub with eight tiles around it on dashed links. The tile under the pointer rises and its link turns solid. | The tiles rise higher. |
+| `relay` | `Relay` | A hub with four branches of tiles. The path to the leaf under the pointer lights hop by hop. | Each hop waits longer. |
+| `settle` | `Settle` | Twelve tiles lie crooked round a hub. As the pointer nears it, they slide into a tree and the links draw in. | The tree forms from further away. |
+| `format` | `Format` | A file of ten crooked lines. The pointer runs the formatter down it, and every line above snaps square. | The lines start more crooked. |
+| `rebuild` | `Rebuild` | A tree of packages. The one under the pointer rises, and every package that depends on it rises after it. | The packages rise higher. |
+| `stack` | `Stack` | A call stack of five frames. The pointer's height picks one, and the frames above lift away to open it. | The frames above lift further. |
## Options
@@ -126,7 +132,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 twenty-seven above, as one HTML file. Every figure it makes declares a tour, the stops a hand would visit, and the page it writes has a play button that walks it.
+`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 thirty-three above, as one HTML file. Every figure it makes declares a tour, the stops a hand would visit, and the page it writes has a play button that walks it.
```sh
npx skills add lucasmarkes/hairline
diff --git a/apps/site/app/docs/sections.tsx b/apps/site/app/docs/sections.tsx
index e82f9f8..10b5feb 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 { Basket, Branches, Cabinet, Dish, Drawer, Elevator, Exploded, Keyboard, Laptop, Lockers, Loupe, Padlock, Patch, Phone, Phosphor, Plot, Plug, Query, Rail, Riffle, Router, Sieve, Slow, Terminal, Terrain, Turntable, Vault } from "@lucasmarkes/hairline/react";
+import { Basket, Branches, Cabinet, Dish, Drawer, Elevator, Exploded, Format, Hub, Keyboard, Laptop, Lockers, Loupe, Padlock, Patch, Phone, Phosphor, Plot, Plug, Query, Rail, Rebuild, Relay, Riffle, Router, Settle, Sieve, Slow, Stack, Terminal, Terrain, Turntable, Vault } from "@lucasmarkes/hairline/react";
import { Anchor } from "@/components/anchor";
import { CodeBlock } from "@/components/code-block";
import { Install } from "@/components/install";
@@ -8,7 +8,7 @@ import { SECTIONS } from "@/lib/docs";
import { COUNT, FIGURES, INTENSITY, OPTIONS, THEME, measure } from "@/lib/figures";
import { NO_RESULTS, PACKAGE } from "@/lib/snippets";
-const SMALL = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard, elevator: Elevator, phone: Phone, laptop: Laptop, terminal: Terminal, cabinet: Cabinet, branches: Branches, vault: Vault, lockers: Lockers, padlock: Padlock, patch: Patch, dish: Dish, router: Router, loupe: Loupe, sieve: Sieve, rail: Rail, plug: Plug, query: Query, drawer: Drawer, basket: Basket, plot: Plot };
+const SMALL = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard, elevator: Elevator, phone: Phone, laptop: Laptop, terminal: Terminal, cabinet: Cabinet, branches: Branches, vault: Vault, lockers: Lockers, padlock: Padlock, patch: Patch, dish: Dish, router: Router, loupe: Loupe, sieve: Sieve, rail: Rail, plug: Plug, query: Query, drawer: Drawer, basket: Basket, plot: Plot, hub: Hub, relay: Relay, settle: Settle, format: Format, rebuild: Rebuild, stack: Stack };
/** 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.tsx
index e9b52f0..d043329 100644
--- a/apps/site/components/catalogue.tsx
+++ b/apps/site/components/catalogue.tsx
@@ -1,7 +1,7 @@
"use client";
import { useCallback, useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ReactNode } from "react";
-import { Basket, Branches, Cabinet, Dish, Drawer, Elevator, Exploded, Keyboard, Laptop, Lockers, Loupe, Padlock, Patch, Phone, Phosphor, Plot, Plug, Query, Rail, Riffle, Router, Sieve, Slow, Terminal, Terrain, Turntable, Vault } from "@lucasmarkes/hairline/react";
+import { Basket, Branches, Cabinet, Dish, Drawer, Elevator, Exploded, Format, Hub, Keyboard, Laptop, Lockers, Loupe, Padlock, Patch, Phone, Phosphor, Plot, Plug, Query, Rail, Rebuild, Relay, Riffle, Router, Settle, Sieve, Slow, Stack, Terminal, Terrain, Turntable, Vault } from "@lucasmarkes/hairline/react";
import { ENTRIES, NOTICE, SHELVES, type Entry, type Shelf, type ShelfId } from "@/lib/catalogue";
import { LINKS, type FigureId } from "@/lib/figures";
import { Command } from "./command";
@@ -9,7 +9,7 @@ import { ExampleFrame } from "./example-frame";
import { MadeFrame } from "./made-frame";
import { Tabs, type Tab } from "./tabs";
-const COMPONENTS: Record<FigureId, typeof Riffle> = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard, elevator: Elevator, phone: Phone, laptop: Laptop, terminal: Terminal, cabinet: Cabinet, branches: Branches, vault: Vault, lockers: Lockers, padlock: Padlock, patch: Patch, dish: Dish, router: Router, loupe: Loupe, sieve: Sieve, rail: Rail, plug: Plug, query: Query, drawer: Drawer, basket: Basket, plot: Plot };
+const COMPONENTS: Record<FigureId, typeof Riffle> = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard, elevator: Elevator, phone: Phone, laptop: Laptop, terminal: Terminal, cabinet: Cabinet, branches: Branches, vault: Vault, lockers: Lockers, padlock: Padlock, patch: Patch, dish: Dish, router: Router, loupe: Loupe, sieve: Sieve, rail: Rail, plug: Plug, query: Query, drawer: Drawer, basket: Basket, plot: Plot, hub: Hub, relay: Relay, settle: Settle, format: Format, rebuild: Rebuild, stack: Stack };
type Filter = "all" | ShelfId;
diff --git a/apps/site/lib/catalogue.ts b/apps/site/lib/catalogue.ts
index 0da2c50..eddfb7e 100644
--- a/apps/site/lib/catalogue.ts
+++ b/apps/site/lib/catalogue.ts
@@ -64,6 +64,9 @@ export const SHELVES: Shelf[] = [
drawn("terminal"),
drawn("cabinet"),
drawn("branches"),
+ drawn("format"),
+ drawn("rebuild"),
+ drawn("stack"),
],
},
{
@@ -78,6 +81,9 @@ export const SHELVES: Shelf[] = [
drawn("patch"),
drawn("dish"),
drawn("router"),
+ drawn("hub"),
+ drawn("relay"),
+ drawn("settle"),
],
},
{
@@ -103,7 +109,7 @@ export const SHELVES: Shelf[] = [
export const ENTRIES: Entry[] = SHELVES.flatMap((s) => s.figures);
-/** "Eight shelves, twenty-seven figures": the package's. The marks are the skill's, and are counted apart. */
+/** "Eight shelves, thirty-three figures": the package's. The marks are the skill's, and are counted apart. */
export function tally(): string {
const own = SHELVES.filter((s) => s.id !== "marks");
return `${cap(spell(own.length))} shelves, ${spell(own.flatMap((s) => s.figures).length)} figures`;
diff --git a/apps/site/lib/figures.ts b/apps/site/lib/figures.ts
index 6c90a0b..3a6c372 100644
--- a/apps/site/lib/figures.ts
+++ b/apps/site/lib/figures.ts
@@ -8,7 +8,7 @@
import { spell } from "./words";
-export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches" | "vault" | "lockers" | "padlock" | "patch" | "dish" | "router" | "loupe" | "sieve" | "rail" | "plug" | "query" | "drawer" | "basket" | "plot";
+export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches" | "vault" | "lockers" | "padlock" | "patch" | "dish" | "router" | "loupe" | "sieve" | "rail" | "plug" | "query" | "drawer" | "basket" | "plot" | "hub" | "relay" | "settle" | "format" | "rebuild" | "stack";
export type FigureDoc = {
id: FigureId;
@@ -210,10 +210,51 @@ export const FIGURES: FigureDoc[] = [
summary: "A bar chart with seven flat tabs where the bars would stand. The pointer brushes them; each lifts a little and drops back to zero.",
stronger: "The tabs lift higher.",
parameter: { name: "lift", unit: "viewBox units" },
+ }, {
+ id: "hub",
+ name: "Hub",
+ summary: "A hub with eight tiles around it on dashed links. The tile under the pointer rises and its link turns solid.",
+ stronger: "The tiles rise higher.",
+ parameter: { name: "rise", unit: "viewBox units" },
+ },
+ {
+ id: "relay",
+ name: "Relay",
+ summary: "A hub with four branches of tiles. The path to the leaf under the pointer lights hop by hop.",
+ stronger: "Each hop waits longer.",
+ parameter: { name: "delay", unit: "ms per hop" },
+ },
+ {
+ id: "settle",
+ name: "Settle",
+ summary: "Twelve tiles lie crooked round a hub. As the pointer nears it, they slide into a tree and the links draw in.",
+ stronger: "The tree forms from further away.",
+ parameter: { name: "reach", unit: "viewBox units" },
+ },
+ {
+ id: "format",
+ name: "Format",
+ summary: "A file of ten crooked lines. The pointer runs the formatter down it, and every line above snaps square.",
+ stronger: "The lines start more crooked.",
+ parameter: { name: "disorder", unit: "degrees" },
+ },
+ {
+ id: "rebuild",
+ name: "Rebuild",
+ summary: "A tree of packages. The one under the pointer rises, and every package that depends on it rises after it.",
+ stronger: "The packages rise higher.",
+ parameter: { name: "rise", unit: "viewBox units" },
+ },
+ {
+ id: "stack",
+ name: "Stack",
+ summary: "A call stack of five frames. The pointer's height picks one, and the frames above lift away to open it.",
+ stronger: "The frames above lift further.",
+ parameter: { name: "lift", unit: "viewBox units" },
},
];
-/** How many figures the package has, as the prose writes it: "twenty-seven". */
+/** How many figures the package has, as the prose writes it: "thirty-three". */
export const COUNT = spell(FIGURES.length);
/** Each figure's number at intensity 0, 0.5 and 1: a copy of the package's table. */
@@ -245,6 +286,12 @@ export const INTENSITY: Record<FigureId, readonly [number, number, number]> = {
drawer: [12, 22, 34],
basket: [8, 16, 28],
plot: [3, 6, 12],
+ hub: [10, 16, 24],
+ relay: [40, 120, 220],
+ settle: [90, 120, 150],
+ format: [9, 12, 14],
+ rebuild: [8, 14, 20],
+ stack: [22, 34, 46],
};
/** 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/catalogue.test.ts b/apps/site/test/catalogue.test.ts
index 96264a0..a64798e 100644
--- a/apps/site/test/catalogue.test.ts
+++ b/apps/site/test/catalogue.test.ts
@@ -17,7 +17,7 @@ describe("the catalogue", () => {
it("names each figure once, on nine shelves", () => {
expect(new Set(ENTRIES.map((e) => e.id)).size).toBe(ENTRIES.length);
expect(new Set(ENTRIES.map((e) => e.name)).size).toBe(ENTRIES.length);
- expect(SHELVES.map((s) => s.figures.length)).toEqual([1, 3, 3, 3, 3, 3, 3, 8, 3]);
+ expect(SHELVES.map((s) => s.figures.length)).toEqual([1, 3, 3, 3, 6, 3, 6, 8, 3]);
});
it("keeps the marks apart: made by the skill, counted outside the package's tally", () => {
@@ -31,13 +31,13 @@ describe("the catalogue", () => {
}
// each line says what that page's slider does
expect(marks.figures.map((f) => f.stronger)).toEqual(["It answers from further away.", "The neck holds further before it lets go.", "The lid opens wider."]);
- expect(tally()).toBe("Eight shelves, twenty-seven figures");
+ expect(tally()).toBe("Eight shelves, thirty-three figures");
expect(NOTICE).toMatch(/not affiliated/);
});
it("counts in words, read from the shelves", () => {
expect([spell(7), spell(19), spell(20), spell(21), spell(40), spell(99)]).toEqual(["seven", "nineteen", "twenty", "twenty-one", "forty", "ninety-nine"]);
- expect(tally()).toBe("Eight shelves, twenty-seven figures");
+ expect(tally()).toBe("Eight shelves, thirty-three figures");
});
it("pastes each figure three ways, and the docs' Terrain is the same as before", () => {
diff --git a/apps/site/test/figures.spec.ts b/apps/site/test/figures.spec.ts
index 8759faa..3835014 100644
--- a/apps/site/test/figures.spec.ts
+++ b/apps/site/test/figures.spec.ts
@@ -16,16 +16,16 @@ 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 twenty-seven empty boxes among thirty tiles, then draws them with a clean console", async ({ page, request }) => {
+test("/figures prerenders thirty-three empty boxes among thirty-six 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(27);
- expect(html.match(/class="fig-tile"/g)).toHaveLength(30);
+ expect(html.match(/<div style="aspect-ratio:5 \/ 4"><\/div>/g)).toHaveLength(33);
+ expect(html.match(/class="fig-tile"/g)).toHaveLength(36);
expect(html).not.toContain("data-planned");
const noise = watch(page);
await page.goto("/figures");
- await expect(tiles(page)).toHaveCount(30);
- await expect(page.locator(".fig-tile [data-hairline] > svg")).toHaveCount(27);
+ await expect(tiles(page)).toHaveCount(36);
+ await expect(page.locator(".fig-tile [data-hairline] > svg")).toHaveCount(33);
await expect(page.locator(".fig-tile .fig-ghost, .fig-tile[data-planned]")).toHaveCount(0);
await expect(page.locator("h1")).toHaveText("Every figure, by what it draws.");
await expect(page.locator(".doc-section h2")).toHaveText(SHELVES);
@@ -36,7 +36,7 @@ test("/figures prerenders twenty-seven empty boxes among thirty tiles, then draw
test("the shelves filter: All is pressed at first, a shelf shows only itself and names itself in the address", async ({ page }) => {
await page.goto("/figures");
await expect(shelf(page, "All")).toHaveAttribute("aria-pressed", "true");
- await expect(page.locator(".shelves .shelf-n")).toHaveText(["30", "1", "3", "3", "3", "3", "3", "3", "8", "3"]);
+ await expect(page.locator(".shelves .shelf-n")).toHaveText(["36", "1", "3", "3", "3", "6", "3", "6", "8", "3"]);
await shelf(page, "Machines").click();
await expect(shelf(page, "Machines")).toHaveAttribute("aria-pressed", "true");
@@ -53,7 +53,7 @@ test("the shelves filter: All is pressed at first, a shelf shows only itself and
})).toBeLessThan(1);
await shelf(page, "All").click();
- await expect(tiles(page)).toHaveCount(30);
+ await expect(tiles(page)).toHaveCount(36);
expect(new URL(page.url()).hash).toBe("");
});
diff --git a/apps/site/test/site.spec.ts b/apps/site/test/site.spec.ts
index 7f7f52f..cf7b85c 100644
--- a/apps/site/test/site.spec.ts
+++ b/apps/site/test/site.spec.ts
@@ -1,6 +1,6 @@
import { expect, test, type Page } from "@playwright/test";
-const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches", "vault", "lockers", "padlock", "patch", "dish", "router", "loupe", "sieve", "rail", "plug", "query", "drawer", "basket", "plot"];
+const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches", "vault", "lockers", "padlock", "patch", "dish", "router", "loupe", "sieve", "rail", "plug", "query", "drawer", "basket", "plot", "hub", "relay", "settle", "format", "rebuild", "stack"];
const MANAGERS = [
["npm", "npm i @lucasmarkes/hairline"],
["pnpm", "pnpm add @lucasmarkes/hairline"],
@@ -332,9 +332,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", /^Twenty-seven isometric line figures/],
- ["/figures", "Figures", /^Eight shelves, twenty-seven figures, grouped by what they draw/],
- ["/docs", "Docs", /^Twenty-seven isometric line figures/],
+ ["/", "hairline", /^Thirty-three isometric line figures/],
+ ["/figures", "Figures", /^Eight shelves, thirty-three figures, grouped by what they draw/],
+ ["/docs", "Docs", /^Thirty-three 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.html
index 4500a26..7bd982b 100644
--- a/fixtures/vite-vanilla/index.html
+++ b/fixtures/vite-vanilla/index.html
@@ -38,6 +38,12 @@
<div id="drawer"></div>
<div id="basket"></div>
<div id="plot"></div>
+ <div id="hub"></div>
+ <div id="relay"></div>
+ <div id="settle"></div>
+ <div id="format"></div>
+ <div id="rebuild"></div>
+ <div id="stack"></div>
</main>
<output id="read"></output>
<script type="module" src="/src/main.ts"></script>
diff --git a/fixtures/vite-vanilla/src/main.ts b/fixtures/vite-vanilla/src/main.ts
index 6399e05..ee3d597 100644
--- a/fixtures/vite-vanilla/src/main.ts
+++ b/fixtures/vite-vanilla/src/main.ts
@@ -1,6 +1,6 @@
-import { basket, branches, cabinet, dish, drawer, elevator, exploded, keyboard, laptop, lockers, loupe, padlock, patch, phone, phosphor, plot, plug, query, rail, riffle, router, sieve, slow, terminal, terrain, turntable, vault, type Figure } from "@lucasmarkes/hairline";
+import { basket, branches, cabinet, dish, drawer, elevator, exploded, format, hub, keyboard, laptop, lockers, loupe, padlock, patch, phone, phosphor, plot, plug, query, rail, rebuild, relay, riffle, router, settle, sieve, slow, stack, terminal, terrain, turntable, vault, type Figure } from "@lucasmarkes/hairline";
-/** No framework: twenty-seven elements, twenty-seven calls. */
+/** No framework: thirty-three elements, thirty-three calls. */
const el = (id: string) => document.getElementById(id)!;
const read = el("read");
@@ -34,5 +34,11 @@ query(el("query"));
drawer(el("drawer"));
basket(el("basket"));
plot(el("plot"));
+hub(el("hub"));
+relay(el("relay"));
+settle(el("settle"));
+format(el("format"));
+rebuild(el("rebuild"));
+stack(el("stack"));
cards.update({ intensity: 0.8 });
diff --git a/package.json b/package.json
index 9402cd4..a4e109c 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "hairline-monorepo",
"version": "0.0.0",
"private": true,
- "description": "Twenty-seven isometric line figures that answer the pointer",
+ "description": "Thirty-three isometric line figures that answer the pointer",
"packageManager": "[email protected]",
"engines": {
"node": ">=22"
diff --git a/packages/hairline/package.json b/packages/hairline/package.json
index 4bacdf1..c0c3fdf 100644
--- a/packages/hairline/package.json
+++ b/packages/hairline/package.json
@@ -1,7 +1,7 @@
{
"name": "@lucasmarkes/hairline",
- "version": "0.4.0",
- "description": "Twenty-seven isometric line figures that answer the pointer. For React and for anything with a DOM.",
+ "version": "0.5.0",
+ "description": "Thirty-three 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": "35.3 kB"
+ "limit": "42.0 kB"
},
{
"name": "vanilla, one figure",
@@ -94,7 +94,7 @@
{
"name": "react, every component",
"path": "dist/react.js",
- "limit": "35.7 kB",
+ "limit": "42.3 kB",
"ignore": [
"react",
"react/jsx-runtime"
diff --git a/packages/hairline/src/figures/format.ts b/packages/hairline/src/figures/format.ts
new file mode 100644
index 0000000..be73f9d
--- /dev/null
+++ b/packages/hairline/src/figures/format.ts
@@ -0,0 +1,142 @@
+import { Cam, clamp, facing, fit, prism, proj, rad, rings, rrect, unproj, type Ring, type Vec2 } from "../core/iso";
+import { reducedMotion, spring, stepS, type Spring } from "../core/motion";
+import { disposer, mk, pointer, put, register, solid, type FigureMount, type Solid } from "../core/stage";
+
+/**
+ * Format: a file as a stack of ten thin slabs on a rounded board, one to a
+ * line, indented like code. At rest it is unformatted: every line pivoted
+ * about its own start, its indent wrong, none touching another. The pointer
+ * runs the formatter down the file: every line above the pointer swings square
+ * to its indent on a spring, staggered line by line; lines below stay as they
+ * were. The line at the formatter's front takes the bright edge (none at
+ * rest), which the kernel's stroke transition fades from line to line.
+ * Leaving un-formats the file slowly, bottom-up, with no bounce.
+ * The slider is the disorder, in degrees of the worst skew.
+ *
+ * The pattern: discrete items on springs. A stagger by distance, a hit test on
+ * the ground plane (which never moves), and a rest that is a composition.
+ */
+
+const G = 12, WD = 5.5, T = 2.4, X0 = 8, IND = 13, PB = 5, STEP = 55, STEP_OUT = 80, MAXV = 14;
+const BX0 = -9, BX1 = 118, BY0 = -8, BY1 = 9 * G + WD + 8, GUT = 1;
+// Each line: indent level, length, and how it sits crooked at rest, as fractions of the slider's far end:
+// yaw (about its own start, the indent point), dx (the indent error), dy (a small shift along the page), dz (unused: a raised line would cross its neighbour on screen).
+// Picked by search so that no two lines touch at any slider value or any mix of their springs (lines further down are never less crooked than the ones above while the formatter runs).
+const LINES: [number, number, number, number, number, number][] = [
+ [0, 56, 0.3, -8, -2, 0],
+ [1, 40, 0.75, 8, -1.9, 0],
+ [1, 58, 0.3, -8, -0.8, 0],
+ [2, 74, 1, -8, -1.9, 0],
+ [2, 48, 1, 8, 1.3, 0],
+ [1, 34, 0.3, 8, 2, 0],
+ [1, 66, 1, -8, -2, 0],
+ [2, 52, 1, -8, -0.8, 0],
+ [1, 30, 0.45, 8, 2, 0],
+ [0, 22, 1, -8, 1.6, 0],
+];
+const N = LINES.length;
+
+type Row = {
+ r: number; yaw: number; dx: number; dy: number; dz: number; px: number; py: number; drawn: number;
+ ring: Ring; inner: Ring; sp: Spring; tgt: number; due: number; el: Solid;
+ lit: boolean; wantLit: boolean; litDue: number;
+};
+
+/** A ring turned by th degrees about (cx, cy) and moved by (dx, dy): normals turn with it. */
+function turn(ring: Ring, cx: number, cy: number, th: number, dx: number, dy: number): Ring {
+ const s = Math.sin(rad(th)), c = Math.cos(rad(th));
+ return ring.map((q) => ({
+ u: cx + (q.u - cx) * c - (q.v - cy) * s + dx, v: cy + (q.u - cx) * s + (q.v - cy) * c + dy,
+ nu: q.nu * c - q.nv * s, nv: q.nu * s + q.nv * c,
+ }));
+}
+
+export const mount: FigureMount = ({ stage, svg, read }, value) => {
+ const bag = disposer();
+ let mess = value / MAXV;
+
+ // The camera is fitted to the board and to the most crooked, most raised line at the slider's far end.
+ const C = Cam(45, 0.5, 1.9);
+ fit(C, [[BX0, BY0, -PB], [BX1, BY0, -PB], [BX0, BY1, -PB], [BX1, BY1, -PB], [BX1, BY1, 9]], 200, 168);
+ const P = proj(C), front = facing(C);
+
+ const g = mk("g", {}, svg);
+ const [br, bi] = rings(BX0, BY0, BX1, BY1, 9, 2.2);
+ put(solid(g), prism(P, front, br, bi, -PB, 0));
+ // the gutter: a dashed guide on the board, before any line lies on it
+ mk("path", { d: `M${P(X0 - 4, BY0 + 5, 0).join(" ")}L${P(X0 - 4, BY1 - 5, 0).join(" ")}`, class: "dash" }, g);
+
+ const rows = LINES.map(([lv, len, yaw, dx, dy, dz], r) => {
+ const x0 = X0 + lv * IND, y0 = r * G;
+ const e = solid(g);
+ return {
+ r, yaw, dx, dy, dz, px: x0, py: y0 + WD / 2, drawn: NaN,
+ ring: rrect(x0, y0, x0 + len, y0 + WD, 2.2, 4), inner: rrect(x0 + 0.9, y0 + 0.9, x0 + len - 0.9, y0 + WD - 0.9, 1.3, 4),
+ sp: spring(1, { k: 100, c: 14, eps: 0.003 }), tgt: 1, due: -1, el: e,
+ // the bright edge: the kernel's stroke transition fades it in and out; this only says when
+ lit: false, wantLit: false, litDue: -1,
+ } as Row;
+ });
+
+ function draw(w: Row) {
+ const m = w.sp.x;
+ if (m !== w.drawn) {
+ w.drawn = m;
+ const k = m * mess, th = w.yaw * MAXV * k, z = Math.max(0, m) * w.dz * mess;
+ const ring = turn(w.ring, w.px, w.py, th, w.dx * k, w.dy * k), inner = turn(w.inner, w.px, w.py, th, w.dx * k, w.dy * k);
+ const p = prism(P, front, ring, inner, z, z + T);
+ put(w.el, p);
+ }
+ }
+
+ let fr = -1;
+ const B = register(stage, (dt, now) => {
+ let moving = false;
+ for (const w of rows) {
+ if (w.due >= 0) { if (now >= w.due) { w.sp.t = w.tgt; w.due = -1; } else moving = true; }
+ if (stepS(w.sp, dt)) moving = true;
+ if (w.litDue >= 0) {
+ if (now >= w.litDue) { w.litDue = -1; if (w.lit !== w.wantLit) { w.lit = w.wantLit; w.el.sil.classList.toggle("hi", w.lit); } } else moving = true;
+ }
+ draw(w);
+ }
+ return moving;
+ });
+ bag.add(B.unregister);
+
+ /** Lines 0..a are formatted. New ones snap in a ripple down from the old front; un-formatting is slow and goes bottom-up: the last to be fixed is the first to go. */
+ function setFront(a: number) {
+ if (a === fr) return;
+ const now = performance.now(), prev = fr, rm = reducedMotion();
+ fr = a;
+ for (const w of rows) {
+ const tgt = w.r <= a ? 0 : 1;
+ if (tgt !== w.tgt) {
+ w.tgt = tgt;
+ const slow = tgt === 1;
+ w.sp.k = slow ? 22 : 100; w.sp.c = slow ? 9.4 : 14;
+ w.due = now + (rm ? 0 : slow ? (N - 1 - w.r) * STEP_OUT : (w.r - (prev + 1)) * STEP);
+ }
+ // the bright edge belongs to the line at the front, and to nothing at rest; it arrives with that line's snap
+ const on = w.r === a ? 1 : 0;
+ w.wantLit = !!on;
+ w.litDue = now + (on && !rm ? Math.max(0, w.r - (prev + 1)) * STEP : 0);
+ }
+ read.textContent = a < 0 ? "rest" : `ln ${a + 1}`;
+ B.wake();
+ }
+
+ // The pointer is read on the ground plane, which never moves: the line is the band of rows it is over.
+ const rowAt = (p: Vec2) => {
+ const [x, y] = unproj(C, p[0], p[1], 0);
+ return x < BX0 || x > BX1 || y < BY0 || y > BY1 ? -1 : clamp(Math.floor(y / G), -1, N - 1);
+ };
+ bag.add(pointer(stage, { move: (p) => setFront(rowAt(p)), leave: () => setFront(-1) }));
+ bag.add(() => svg.replaceChildren());
+
+ rows.forEach((w) => draw(w));
+ return {
+ set: (v) => { mess = v / MAXV; rows.forEach((w) => { w.drawn = NaN; }); B.wake(); },
+ destroy: bag.dispose,
+ };
+};
diff --git a/packages/hairline/src/figures/hub.ts b/packages/hairline/src/figures/hub.ts
new file mode 100644
index 0000000..5bb46e9
--- /dev/null
+++ b/packages/hairline/src/figures/hub.ts
@@ -0,0 +1,167 @@
+import { Cam, clamp, facing, fit, hull, open, poly, prism, proj, ringAt, rings, rrect, seg, type Ring, type Vec2, type Vec3 } from "../core/iso";
+import { reducedMotion, spring, stepS, tdone, tset, tval, tween, type Spring, type Tween } from "../core/motion";
+import { disposer, mk, pointer, put, register, solid, type FigureMount, type Solid } from "../core/stage";
+
+/**
+ * Hub: a thick plate in the middle of a faint floor grid, eight thin tiles
+ * around it, a little off their cells, each joined to the hub by a dashed
+ * link. The tile nearest the pointer rises on a spring and its link turns
+ * solid, drawn out from the hub; the tiles beside it rise less, by how far
+ * round the ring they sit. The risen tile is the bright mark; at rest it is
+ * the hub's inset square. The slider is the rise, in world units.
+ *
+ * The pattern: one of many, on springs. A hit test on the tiles' resting
+ * positions, a falloff by angle, a stagger by hops round the ring.
+ */
+
+const D = 52, HS = 10, T = 4, HUB = 18, HT = 8, FALL = [1, 0.5, 0.2, 0.06, 0], STEP = 70, HIT = 40;
+// The rise arrives on a lightly underdamped spring; the return is slower and near-critical.
+const UP = { k: 70, c: 14 }, DOWN = { k: 40, c: 12.4 }, DRAW = { k: 120, c: 21, eps: 0.002 }, RETRACT = { k: 36, c: 11.6, eps: 0.002 };
+// Each tile's cell, and how far it sits off it.
+const JIT = [[2, -2], [-2, 1.5], [1.5, 2.5], [-2.5, -1], [2, 1.5], [-1.5, 2], [2.5, -1.5], [-2, -2.5]];
+const CELLS = [[-1, -1], [0, -1], [1, -1], [1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0]];
+
+type Tile = {
+ k: number; x: number; y: number; n: number; a: number; b: number;
+ sp: Spring; lk: Spring; hw: Tween; drawn: number; due: number; tgt: number; pend: boolean; on: boolean;
+ ring: Ring; inner: Ring; el: Solid; slot: SVGPathElement; line: SVGPathElement;
+};
+
+export const mount: FigureMount = ({ stage, svg, read }, value) => {
+ const bag = disposer();
+ let lift = value;
+
+ const C = Cam(45, 0.5, 1.76);
+ const E = 3 * D / 2 - 4;
+ const pts: Vec3[] = [[-E, -E, 0], [E, -E, 0], [E, E, 0], [-E, E, 0]];
+ CELLS.forEach(([i, j], k) => pts.push([i * D + JIT[k][0] - HS, j * D + JIT[k][1] - HS, 24 * 1.15 + T], [i * D + JIT[k][0] + HS, j * D + JIT[k][1] + HS, 24 * 1.15 + T]));
+ fit(C, pts, 200, 166);
+ const P = proj(C), front = facing(C);
+
+ const g = mk("g", {}, svg);
+ // the floor: a faint grid on the tile pitch
+ let d = "";
+ for (let v = -E; v <= E + 1; v += D / 2) d += seg(P(v, -E, 0), P(v, E, 0)) + seg(P(-E, v, 0), P(E, v, 0));
+ mk("path", { d, class: "nf lo" }, g);
+
+ const tiles = CELLS.map(([i, j], k) => {
+ const x = i * D + JIT[k][0], y = j * D + JIT[k][1];
+ return { k, x, y, sp: spring(0, { ...UP }), lk: spring(0, { ...DRAW, eps: 0.002 }), hw: tween(0, 220), drawn: NaN, due: 0, tgt: 0, pend: false, on: false } as Tile;
+ });
+ // ring order, by angle: the neighbours of a tile are the ones beside it on the ring
+ const ring = tiles.slice().sort((a, b) => Math.atan2(a.y, a.x) - Math.atan2(b.y, b.x));
+ ring.forEach((t, n) => { t.n = n; });
+
+ // links go down first: dashed to every tile, and a solid one over it that is drawn out from the hub
+ // each link is a floor segment from the hub's rim to the tile's footprint edge
+ tiles.forEach((t) => {
+ const m = Math.max(Math.abs(t.x), Math.abs(t.y));
+ t.a = HUB / m; t.b = 1 - HS / m;
+ // the visible rim: where the floor segment comes out from behind the hub's silhouette
+ const H = hull([[-HUB, -HUB], [HUB, -HUB], [HUB, HUB], [-HUB, HUB]].flatMap(([x, y]) => [P(x, y, 0), P(x, y, HT)]));
+ const inside = (q: Vec2) => { let s0 = 0; for (let i = 0; i < H.length; i++) { const a = H[i], b = H[(i + 1) % H.length], c = (b[0] - a[0]) * (q[1] - a[1]) - (b[1] - a[1]) * (q[0] - a[0]); if (c * s0 < 0) return false; if (c) s0 = c; } return true; };
+ let u = t.a; while (u < t.b - 0.05 && inside(P(t.x * u, t.y * u, 0))) u += 0.005;
+ t.a = Math.min(u + 0.01, t.b - 0.1);
+ // short real dashes in the plain stroke, so the link reads at 240px
+ const len = Math.hypot(t.x, t.y) * (t.b - t.a), n = Math.max(2, Math.round(len / 6));
+ let dd = "";
+ for (let i = 0; i < n; i++) {
+ const u0 = t.a + ((t.b - t.a) * (i + 0.15)) / n, u1 = t.a + ((t.b - t.a) * (i + 0.65)) / n;
+ dd += seg(P(t.x * u0, t.y * u0, 0), P(t.x * u1, t.y * u1, 0));
+ }
+ mk("path", { d: dd, class: "nf" }, g);
+ });
+ tiles.forEach((t) => { t.slot = mk("path", { class: "nf lo" }, g); t.line = mk("path", { class: "nf hi" }, g); });
+
+ // plates, back to front by x + y; the hub sits among them
+ let mark!: SVGPathElement;
+ const order: (Tile | null)[] = [...tiles, null].sort((a, b) => (a ? a.x + a.y : 0) - (b ? b.x + b.y : 0));
+ for (const t of order) {
+ if (!t) {
+ const [r, ri] = rings(-HUB, -HUB, HUB, HUB, 6, 1.4);
+ put(solid(g), prism(P, front, r, ri, 0, HT));
+ mk("path", { d: open(ringAt(P, rrect(-13, -13, 13, 13, 3.5, 4).concat(rrect(-13, -13, 13, 13, 3.5, 4).slice(0, 1)), HT)), class: "nf lo" }, g);
+ const md = open(ringAt(P, rrect(-7, -7, 7, 7, 2, 4).concat(rrect(-7, -7, 7, 7, 2, 4).slice(0, 1)), HT));
+ mark = mk("path", { d: md, class: "nf hi" }, g);
+ continue;
+ }
+ [t.ring, t.inner] = rings(t.x - HS, t.y - HS, t.x + HS, t.y + HS, 3.5, 1);
+ t.el = solid(g);
+ }
+
+ const hubW = tween(1, 240);
+ let hubOn = true;
+ function draw(t: Tile, now: number) {
+ const z = Math.max(0, t.sp.x), l = clamp(t.lk.x, 0, 1), w = tval(t.hw, now);
+ if (z !== t.drawn) {
+ t.drawn = z; put(t.el, prism(P, front, t.ring, t.inner, z, z + T));
+ t.slot.setAttribute("d", z > 0.4 ? poly(ringAt(P, t.ring, 0)) : "");
+ }
+ // the bright mark is the stroke's own colour transition, switched when its weight crosses half
+ if ((w > 0.5) !== t.on) { t.on = w > 0.5; t.el.sil.classList.toggle("hi", t.on); }
+ const e = t.a + (t.b - t.a) * l;
+ t.line.setAttribute("d", l > 0.002 ? seg(P(t.x * t.a, t.y * t.a, 0), P(t.x * e, t.y * e, 0)) : "");
+ }
+
+ const B = register(stage, (dt, now) => {
+ let moving = false;
+ for (const t of tiles) {
+ if (t.pend) { if (now >= t.due) { t.pend = false; Object.assign(t.sp, t.tgt > t.sp.t ? UP : DOWN); t.sp.t = t.tgt; } else moving = true; }
+ if (stepS(t.sp, dt)) moving = true;
+ if (stepS(t.lk, dt)) moving = true;
+ if (!tdone(t.hw, now)) moving = true;
+ draw(t, now);
+ }
+ const hw = tval(hubW, now) > 0.5;
+ if (hw !== hubOn) { hubOn = hw; mark.setAttribute("class", hw ? "nf hi" : "nf lo"); }
+ if (!tdone(hubW, now)) moving = true;
+ return moving;
+ });
+ bag.add(B.unregister);
+
+ // hit: the tile whose RESTING top is nearest the pointer on screen; the hub's own ground is rest
+ const top = tiles.map((t) => P(t.x, t.y, T)), hubAt = P(0, 0, HT);
+ let act = -1;
+ function hit([sx, sy]: Vec2) {
+ if (Math.hypot(sx - hubAt[0], sy - hubAt[1]) < 30) return -1;
+ let a = -1, best = HIT;
+ top.forEach((q, k) => { const m = Math.hypot(sx - q[0], sy - q[1]); if (m < best) { best = m; a = k; } });
+ // a little hysteresis: the tile already under the pointer is kept until another is clearly nearer
+ if (a !== act && act >= 0) {
+ const held = Math.hypot(sx - top[act][0], sy - top[act][1]);
+ if (held < HIT && best > 0.8 * held) return act;
+ }
+ return a;
+ }
+
+ /** Hops round the ring from tile `from`. */
+ const hops = (t: Tile, from: number) => Math.min((t.n - from + 8) % 8, (from - t.n + 8) % 8);
+ function setActive(a: number) {
+ if (a === act) return;
+ const now = performance.now(), from = a >= 0 ? tiles[a].n : tiles[act].n;
+ act = a;
+ tiles.forEach((t) => {
+ const hop = hops(t, from), tgt = a < 0 ? 0 : lift * FALL[hop], rising = tgt > t.tgt;
+ // up: the touched tile first, the others a beat behind by hops; down: the outer ones first, the one just left last
+ const delay = reducedMotion() ? 0 : rising ? hop * STEP : a < 0 ? (4 - hop) * 25 : hop === 0 ? 60 : 0;
+ t.tgt = tgt; t.due = now + delay; t.pend = true;
+ const on = t.k === a;
+ Object.assign(t.lk, on ? DRAW : RETRACT); t.lk.t = on ? 1 : 0;
+ t.hw.dur = on ? 220 : 260; tset(t.hw, on ? 1 : 0, now, on ? 60 : 0);
+ });
+ hubW.dur = a < 0 ? 280 : 200; tset(hubW, a < 0 ? 1 : 0, now, a < 0 ? 180 : 0);
+ read.textContent = a < 0 ? "rest" : "tile " + (a + 1);
+ B.wake();
+ }
+
+ bag.add(pointer(stage, { move: (p) => setActive(hit(p)), leave: () => setActive(-1) }));
+ bag.add(() => svg.replaceChildren());
+
+ return {
+ set: (v) => {
+ lift = v;
+ if (act >= 0) { const from = tiles[act].n; tiles.forEach((t) => { t.tgt = t.sp.t = lift * FALL[hops(t, from)]; t.pend = false; }); B.wake(); }
+ },
+ destroy: bag.dispose,
+ };
+};
diff --git a/packages/hairline/src/figures/rebuild.ts b/packages/hairline/src/figures/rebuild.ts
new file mode 100644
index 0000000..f3b1229
--- /dev/null
+++ b/packages/hairline/src/figures/rebuild.ts
@@ -0,0 +1,195 @@
+import { Cam, facing, fit, hull, lerp, poly, prism, proj, ringAt, rings, seg, unproj, type Ring, type Vec2, type Vec3 } from "../core/iso";
+import { EASE_LIFT, reducedMotion, tdone, tset, tval, tween, type Tween } from "../core/motion";
+import { disposer, mk, pointer, put, register, solid, type FigureMount, type Solid } from "../core/stage";
+
+/**
+ * Rebuild: a monorepo as a tree of package tiles on a rounded plinth, a thick
+ * root at the back, two packages under it, five more under those, joined by
+ * dashed links on the floor. The tile under the pointer rises, and every
+ * package that depends on it (its subtree) rises after it, hop by hop along
+ * the links, each a little less; a pulse of ink runs down each link just ahead
+ * of the tile it feeds. The rest stay down. Letting go is slower and softer than the
+ * rise, deepest tile first. The touched tile takes the bright edge as the
+ * last one lets it go (the stage's stroke transition is the cross-fade); at
+ * rest that is the root. The slider is the rise, in world units.
+ *
+ * The pattern: discrete items. Tweens, a stagger by hop (forward on the rise,
+ * reversed on the return), and a hit test on the target pose of each tile, so
+ * a tile rising under the pointer cannot flip it.
+ */
+const T = 3, TH = 5, HALF = 12, HUBH = 18, FALL = 0.7, REACH = 24;
+// ms: a hop of the rise, a hop of the return (deepest first), the two durations, the pulse, the mark's hand-over
+const HOP = 125, RHOP = 90, UP = 700, DOWN = 1350, PULSE = 420, LATE = 70;
+const TAIL = 0.45, GRACE = 400;
+// Depth runs down the screen (x + y), spread across it (x - y); parents sit between their children.
+type Dash = { u: number; d: string; full: string; lit: number; el: SVGPathElement };
+type Link = { n: Node; pt: Tween; on: boolean; dashes: Dash[] };
+type Node = {
+ p: number; l: number; d: number; s: number;
+ i: number; x: number; y: number; h: number; tw: Tween; drawn: number; want: boolean; at: number | undefined;
+ ring: Ring; inner: Ring; el: Solid; rec?: Ring; recEl?: SVGPathElement;
+};
+/** The tree's shape; each mount draws its own copy, so two of the figure on a page never share a tile. */
+const TREE: ReadonlyArray<Pick<Node, "p" | "l" | "d" | "s">> = [
+ { p: -1, l: 0, d: 0, s: -9 },
+ { p: 0, l: 1, d: 60, s: -54 }, { p: 0, l: 1, d: 60, s: 36 },
+ { p: 1, l: 2, d: 120, s: -72 }, { p: 1, l: 2, d: 120, s: -36 },
+ { p: 2, l: 2, d: 120, s: 0 }, { p: 2, l: 2, d: 120, s: 36 }, { p: 2, l: 2, d: 120, s: 72 },
+];
+/** Hops from a to b along the links. */
+const dist = (a: number, b: number) => {
+ const up = (i: number) => { const c: number[] = []; for (; i >= 0; i = TREE[i].p) c.push(i); return c; };
+ const ca = up(a), cb = up(b), m = ca.find((i) => cb.includes(i))!;
+ return ca.indexOf(m) + cb.indexOf(m);
+};
+const under = (a: number, b: number) => { for (let i = b; i >= 0; i = TREE[i].p) if (i === a) return true; return false; };
+
+export const mount: FigureMount = ({ stage, svg, read }, value) => {
+ const bag = disposer();
+ let rise = value, act = -1, grace: number | null = null;
+ const NODES = TREE.map((t) => ({ ...t }) as Node);
+ const half = (n: Node) => (n.l ? HALF : HUBH), thick = (n: Node) => (n.l ? T : TH);
+ NODES.forEach((n, i) => { n.i = i; n.x = n.d + n.s; n.y = n.d - n.s; n.h = half(n); n.tw = tween(0); n.drawn = NaN; n.want = !n.i; n.at = undefined; });
+
+ const C = Cam(45, 0.5, 1.5);
+ const ext: Vec3[] = [];
+ for (const n of NODES) ext.push([n.x - n.h, n.y - n.h, 0], [n.x + n.h, n.y + n.h, 0], [n.x, n.y, 20 + TH]);
+ fit(C, ext, 200, 166);
+ const P = proj(C), front = facing(C);
+
+ const g = mk("g", {}, svg);
+
+ // Links and footprints lie on the floor, so they go down before any tile.
+ const links: Link[] = [];
+ for (const n of NODES) {
+ if (n.p < 0) continue;
+ const q = NODES[n.p], dx = n.x - q.x, dy = n.y - q.y, L = Math.hypot(dx, dy);
+ // a straight run on the floor from one slab's edge to the other's, along the line between their centres
+ const cut = (h: number) => h / Math.max(Math.abs(dx), Math.abs(dy)) * L + 2.5;
+ const a = cut(q.h) / L, e = 1 - cut(n.h) / L;
+ // short real dashes along the run, in screen space
+ const A = P(q.x + dx * a, q.y + dy * a, 0), Z = P(q.x + dx * e, q.y + dy * e, 0);
+ const k = Math.max(2, Math.round(Math.hypot(Z[0] - A[0], Z[1] - A[1]) / 9));
+ const lk: Link = { n, pt: tween(0, PULSE), on: false, dashes: [] }; links.push(lk);
+ for (let j = 0; j < k; j++) lk.dashes.push({ u: (j + 0.35) / k, d: seg([lerp(A[0], Z[0], (j + 0.1) / k), lerp(A[1], Z[1], (j + 0.1) / k)], [lerp(A[0], Z[0], (j + 0.6) / k), lerp(A[1], Z[1], (j + 0.6) / k)]), full: seg([lerp(A[0], Z[0], j / k), lerp(A[1], Z[1], j / k)], [lerp(A[0], Z[0], (j + 1) / k), lerp(A[1], Z[1], (j + 1) / k)]), lit: 0 } as Dash);
+ }
+ // each dash is its own path, so the pulse can take them one by one (the stage eases the ink)
+ for (const L of links) for (const e of L.dashes) e.el = mk("path", { d: e.d, class: "nf" }, g);
+ for (const n of NODES) {
+ const [r] = rings(n.x - n.h, n.y - n.h, n.x + n.h, n.y + n.h, 3, 1);
+ n.ring = r;
+ mk("path", { d: poly(ringAt(P, r, 0)), class: "nf lo" }, g);
+ }
+ // Back to front by x + y of the centre.
+ const order = NODES.slice().sort((a, b) => a.x + a.y - (b.x + b.y));
+ for (const n of order) {
+ const [r, ri] = rings(n.x - n.h, n.y - n.h, n.x + n.h, n.y + n.h, n.l ? 3 : 4, n.l ? 1 : 1.6);
+ n.ring = r; n.inner = ri; n.el = solid(g);
+ // the root carries a recessed square in its lid
+ if (!n.l) {
+ const [rs] = rings(n.x - 8, n.y - 8, n.x + 8, n.y + 8, 2, 0.5);
+ n.rec = rs; n.recEl = mk("path", { class: "nf lo" }, n.el.g);
+ }
+ }
+ const draw = (n: Node, h: number) => {
+ put(n.el, prism(P, front, n.ring, n.inner, h, h + thick(n)));
+ if (n.rec) n.recEl!.setAttribute("d", poly(ringAt(P, n.rec, h + thick(n))));
+ };
+
+ const B = register(stage, (_dt, now) => {
+ let moving = false;
+ for (const n of NODES) {
+ const h = tval(n.tw, now);
+ if (!tdone(n.tw, now)) moving = true;
+ if (h !== n.drawn) { n.drawn = h; draw(n, h); }
+ }
+ // on open floor the last tile is held a moment before it lets go
+ if (grace !== null) { if (now >= grace) { grace = null; set(-1); } else moving = true; }
+ // the bright mark changes hands a beat after the old one lets go
+ for (const n of NODES) {
+ if (n.at === undefined) continue;
+ if (now >= n.at) { n.el.sil.classList.toggle("hi", n.want); n.at = undefined; } else moving = true;
+ }
+ for (const L of links) {
+ if (!L.on) continue;
+ const fin = tdone(L.pt, now);
+ moving = true;
+ // the head travels the run, mostly steadily, the tail of lit dashes behind it
+ const s = tval(L.pt, now);
+ let lo = 0, hi = 1;
+ for (let i = 0; i < 14; i++) { const m = (lo + hi) / 2; if (EASE_LIFT(m) < s) lo = m; else hi = m; }
+ const hd = fin ? 9 : lerp(lo, s, 0.3) * (1 + TAIL);
+ for (const e of L.dashes) {
+ // under the head a dash closes up into a solid run; behind it, it stays inked and lets go
+ const x = hd - e.u, lit = x < 0 || x >= TAIL ? 0 : x < TAIL * 0.4 ? 2 : 1;
+ if (lit !== e.lit) { e.lit = lit; e.el.classList.toggle("sil", lit > 0); e.el.setAttribute("d", lit === 2 ? e.full : e.d); }
+ }
+ if (fin) { L.on = false; L.pt.from = L.pt.to = 0; L.pt.t0 = -1e9; }
+ }
+ return moving;
+ });
+ bag.add(B.unregister);
+
+ /** The rise tile n takes when a is touched: it falls off a little with each hop down the links. */
+ const target = (a: number, n: Node) => (a >= 0 && under(a, n.i) ? rise * FALL ** dist(a, n.i) : 0);
+
+ const within = (q: Vec2, pg: Vec2[]) => {
+ const s = pg.map((a, i) => { const b = pg[(i + 1) % pg.length]; return (b[0] - a[0]) * (q[1] - a[1]) - (b[1] - a[1]) * (q[0] - a[0]); });
+ return s.every((v) => v >= 0) || s.every((v) => v <= 0);
+ };
+ /** The tile under the point on its target pose, the nearest in front first; else keep, near the tree, or -1 away from it. */
+ function hit(p: Vec2): number {
+ for (let k = order.length - 1; k >= 0; k--) {
+ const n = order[k], z = target(act, n);
+ if (within(p, hull(ringAt(P, n.ring, 0).concat(ringAt(P, n.ring, z + thick(n)))))) return n.i;
+ }
+ const [x, y] = unproj(C, p[0], p[1], 0);
+ return NODES.some((n) => Math.hypot(x - n.x, y - n.y) < n.h + REACH - HALF) ? act : -1;
+ }
+
+ const name = (a: number) => (a < 0 ? "rest" : a === 0 ? "root" : `pkg ${NODES[a].l}·${NODES.filter((n) => n.l === NODES[a].l && n.i <= a).length}`);
+ /** Moves tile n to y after delay: a rise keeps the arrival's life, a fall is slower. */
+ const go = (n: Node, y: number, now: number, delay: number) => {
+ if (n.tw.to === y) return;
+ const up = y > n.tw.to;
+ tset(n.tw, y, now, delay);
+ n.tw.dur = up ? UP : DOWN;
+ };
+ /** Touches a (-1 lets go): tiles that rise follow the hops from a; tiles that fall go deepest first from the one left. */
+ function set(a: number) {
+ if (a === act) return;
+ const now = performance.now(), o = act, now_t = NODES.map((n) => target(a, n));
+ act = a;
+ let deep = 0;
+ NODES.forEach((n, i) => { if (now_t[i] < n.tw.to && o >= 0) deep = Math.max(deep, dist(o, n.i)); });
+ NODES.forEach((n, i) => go(n, now_t[i], now, now_t[i] < n.tw.to ? (deep - dist(o, n.i)) * RHOP : a >= 0 ? dist(a, n.i) * HOP : 0));
+ for (const L of links) {
+ L.pt.from = L.pt.to = 0; L.pt.t0 = -1e9; L.on = false; for (const e of L.dashes) { e.lit = 0; e.el.classList.remove("sil"); e.el.setAttribute("d", e.d); }
+ if (a >= 0 && under(a, L.n.i) && L.n.i !== a) { L.on = true; tset(L.pt, 1, now, dist(a, L.n.p) * HOP + 20); }
+ }
+ for (const n of NODES) {
+ const on = n.i === (a < 0 ? 0 : a);
+ if (on !== n.want) { n.want = on; n.at = on ? now + LATE : now; }
+ }
+ read.textContent = name(a);
+ B.wake();
+ }
+ NODES[0].el.sil.classList.add("hi");
+ read.textContent = "rest";
+ for (const n of NODES) draw(n, 0);
+
+ bag.add(pointer(stage, {
+ move: (p) => {
+ const h = hit(p);
+ if (h < 0 && act >= 0 && !reducedMotion()) { if (grace === null) { grace = performance.now() + GRACE; B.wake(); } return; }
+ grace = null; set(h);
+ },
+ leave: () => { grace = null; set(-1); },
+ }));
+ bag.add(() => svg.replaceChildren());
+
+ return {
+ set: (v) => { rise = v; const now = performance.now(); for (const n of NODES) { if (n.tw.to !== target(act, n)) { tset(n.tw, target(act, n), now, 0); n.tw.dur = UP; } } B.wake(); },
+ destroy: bag.dispose,
+ };
+};
diff --git a/packages/hairline/src/figures/relay.ts b/packages/hairline/src/figures/relay.ts
new file mode 100644
index 0000000..bb1b593
--- /dev/null
+++ b/packages/hairline/src/figures/relay.ts
@@ -0,0 +1,159 @@
+import { Cam, facing, fit, lerp, poly, prism, proj, ringAt, rings, rrect, seg, type Ring, type Vec2, type Vec3 } from "../core/iso";
+import { tdone, tset, tval, tween, type Tween } from "../core/motion";
+import { disposer, mk, pointer, put, register, solid, type FigureMount, type Solid } from "../core/stage";
+
+/**
+ * Relay: a hub plate and four branches of thin tiles on a floor, joined by
+ * dashed links. The pointer picks the nearest leaf; the path from the hub to it
+ * lights hop by hop: each link turns solid as a line that grows along it, and
+ * each tile on the path rises a little, a short delay per hop. The leaf takes
+ * the bright edge, which cross-fades from one leaf to the next (and to the hub's
+ * rim at rest). Moving to another leaf lowers the old path leaf to hub, slower
+ * than it rose, then lights the new one. The slider is the delay per hop, in ms.
+ *
+ * The pattern: discrete items. Tweens, a stagger by hop count, and a hit test
+ * on the leaves' resting positions, so a tile that has risen cannot flip the choice.
+ */
+
+const T = 3, HT = 7, RISE = 9, TS = 9, HS = 17;
+// Each branch leaves the hub along an axis: its first tile at `a`, its second at `b`, then leaves
+// beside the second, to either side. Tiles are [along, across] on that axis; the parent is the one before it.
+const BRANCHES = [
+ { d: [-1, 0], a: 50, b: 84, side: [-1, 1] },
+ { d: [0, -1], a: 50, b: 76, side: [1] },
+ { d: [1, 0], a: 50, b: 84, side: [-1, 1] },
+ { d: [0, 1], a: 50, b: 76, side: [-1] },
+];
+const FORK = 31;
+
+type Node = {
+ c: Vec2; par: number; dep: number; tag?: string;
+ a: Vec2; b: Vec2; link: SVGPathElement; l: Tween; z: Tween; h: Tween; ld: number; zd: number; hd: boolean;
+ ring: Ring; inner: Ring; el: Solid;
+};
+
+/** The tiles of the tree: world centre, parent index (-1 is the hub), depth, and its leaf's read-out. */
+function tree(): Node[] {
+ const nodes: Node[] = [];
+ BRANCHES.forEach((br, k) => {
+ const at = (s: number, o: number): Vec2 => [br.d[0] * s - br.d[1] * o, br.d[1] * s + br.d[0] * o];
+ const i = nodes.length;
+ nodes.push({ c: at(br.a, 0), par: -1, dep: 1 } as Node);
+ nodes.push({ c: at(br.b, 0), par: i, dep: 2 } as Node);
+ br.side.forEach((s, j) => nodes.push({ c: at(br.b, s * FORK), par: i + 1, dep: 3, tag: "leaf " + (k + 1) + "·" + (j + 1) } as Node));
+ });
+ return nodes;
+}
+
+export const mount: FigureMount = ({ stage, svg, read }, value) => {
+ const bag = disposer();
+ let step = value;
+ const nodes = tree(), leaves = nodes.filter((n) => n.tag);
+
+ const C = Cam(45, 0.5, 1.9);
+ const pts: Vec3[] = [[-HS, -HS, 0], [HS, HS, 0], [-HS, HS, 0], [HS, -HS, 0]];
+ for (const n of nodes) for (const [sx, sy] of [[-1, -1], [1, -1], [-1, 1], [1, 1]]) pts.push([n.c[0] + sx * TS, n.c[1] + sy * TS, T + RISE]);
+ fit(C, pts, 200, 166);
+ const P = proj(C), front = facing(C);
+ const g = mk("g", {}, svg);
+
+ // Links, painted before the plates they join: a dashed run, and over it the solid line that grows.
+ for (const n of nodes) {
+ const from = n.par < 0 ? [0, 0] : nodes[n.par].c;
+ const dx = n.c[0] - from[0], dy = n.c[1] - from[1], len = Math.hypot(dx, dy), o0 = n.par < 0 ? HS : 0, o1 = 0;
+ n.a = P(from[0] + (dx / len) * o0, from[1] + (dy / len) * o0, 0); n.b = P(n.c[0] - (dx / len) * o1, n.c[1] - (dy / len) * o1, 0);
+ let dd = "";
+ const L = Math.hypot(n.b[0] - n.a[0], n.b[1] - n.a[1]), k = Math.max(2, Math.round(L / 9));
+ for (let j = 0; j < k; j++) dd += seg([lerp(n.a[0], n.b[0], (j + 0.1) / k), lerp(n.a[1], n.b[1], (j + 0.1) / k)], [lerp(n.a[0], n.b[0], (j + 0.6) / k), lerp(n.a[1], n.b[1], (j + 0.6) / k)]);
+ mk("path", { d: dd, class: "nf" }, g);
+ }
+ for (const n of nodes) {
+ n.link = mk("path", { class: "nf sil" }, g);
+ n.l = tween(0); n.z = tween(0); n.h = tween(0); n.ld = NaN; n.zd = NaN; n.hd = false;
+ }
+
+ // The hub: a thick plate with a recessed square set in its top.
+ const hub = solid(g);
+ const [hr, hi] = rings(-HS, -HS, HS, HS, 6, 2);
+ put(hub, prism(P, front, hr, hi, 0, HT));
+ const rim = mk("path", { d: poly(ringAt(P, rrect(-HS + 6, -HS + 6, HS - 6, HS - 6, 2.5, 4), HT)), class: "nf hi" }, g);
+ const rimW = tween(1); let rimD = true;
+ mk("path", { d: poly(ringAt(P, rrect(-HS + 9, -HS + 9, HS - 9, HS - 9, 1.2, 4), HT)), class: "nf lo" }, g);
+
+ // The tiles, back to front by x + y.
+ for (const n of nodes.slice().sort((p, q) => p.c[0] + p.c[1] - q.c[0] - q.c[1])) {
+ [n.ring, n.inner] = rings(n.c[0] - TS, n.c[1] - TS, n.c[0] + TS, n.c[1] + TS, 3.4, 1.1);
+ n.el = solid(g);
+ }
+
+ const B = register(stage, (_dt, now) => {
+ let moving = false;
+ for (const n of nodes) {
+ const l = tval(n.l, now), z = tval(n.z, now);
+ if (l !== n.ld) {
+ n.ld = l;
+ n.link.setAttribute("d", l > 0.002 ? seg(n.a, [lerp(n.a[0], n.b[0], l), lerp(n.a[1], n.b[1], l)]) : "");
+ }
+ if (z !== n.zd) {
+ n.zd = z;
+ put(n.el, prism(P, front, n.ring, n.inner, z * RISE, z * RISE + T));
+ }
+ // The bright edge is a class on the silhouette; the kernel eases the stroke between the two (260ms),
+ // so the hand-off is a cross-fade. Its weight tween only says when to flip.
+ if (n.tag) { const h = tval(n.h, now) > 0.5; if (h !== n.hd) { n.hd = h; n.el.sil.classList.toggle("hi", h); } }
+ if (!tdone(n.l, now) || !tdone(n.z, now) || !tdone(n.h, now)) moving = true;
+ }
+ const rw = tval(rimW, now) > 0.5;
+ if (rw !== rimD) { rimD = rw; rim.classList.toggle("hi", rw); }
+ if (!tdone(rimW, now)) moving = true;
+ return moving;
+ });
+ bag.add(B.unregister);
+
+ // Hit test on the leaves' rest positions, in screen space: they never move. It is sticky: the leaf
+ // in hand is kept until another is clearly nearer, so a pointer passing by does not flash it.
+ const spot = leaves.map((n) => P(n.c[0], n.c[1], T));
+ const CAP = 78, STICK = 18;
+ const dist = (i: number, [x, y]: Vec2) => Math.hypot(spot[i][0] - x, spot[i][1] - y);
+ function hit(p: Vec2) {
+ let best = -1, bd = CAP;
+ spot.forEach((_, i) => { const d = dist(i, p); if (d < bd) { bd = d; best = i; } });
+ if (act >= 0 && best !== act && dist(act, p) < CAP && dist(act, p) - bd < STICK) return act;
+ return best;
+ }
+
+ // Tweens with their own length: what rises is quick, what falls back is longer and softer.
+ const UP = 700, DOWN = 1500;
+ const go = (tw: Tween, to: number, now: number, delay: number, dur: number) => { if (tw.to === to) return; tset(tw, to, now, delay); tw.dur = dur; };
+ const lit = new Set<Node>(), parentOf = (n: Node): Node | null => (n.par < 0 ? null : nodes[n.par]);
+ let act = -1;
+ /** Lights the path to leaf a (-1: none). What leaves the path goes first, leaf to hub, slower than it rose; what joins it follows, hub to leaf. */
+ function setActive(a: number) {
+ if (a === act) return;
+ const now = performance.now(), want = new Set<Node>(), out = step * 1.5;
+ for (let n: Node | null = a < 0 ? null : leaves[a]; n; n = parentOf(n)) want.add(n);
+ const off = [...lit].filter((n) => !want.has(n)), top = off.reduce((m, n) => Math.max(m, n.dep), 0);
+ const wait = off.length ? (off.length - 1) * out * 0.65 + step * 0.5 : 0;
+ for (const n of nodes) {
+ const on = want.has(n), was = lit.has(n);
+ if (on === was) continue;
+ if (on) { go(n.l, 1, now, wait + (n.dep - 1) * step, UP); go(n.z, 1, now, wait + n.dep * step, UP); }
+ else { go(n.z, 0, now, (top - n.dep) * out, DOWN); go(n.l, 0, now, (top - n.dep) * out + out * 0.5, DOWN); }
+ if (n.tag) {
+ // the bright edge hands over: the old leaf lets go just as the new one takes hold
+ if (on) go(n.h, 1, now, wait + n.dep * step, 40);
+ else go(n.h, 0, now, a < 0 ? 0 : Math.max(0, wait + 3 * step - 60), 40);
+ }
+ }
+ lit.clear(); want.forEach((n) => lit.add(n));
+ go(rimW, a < 0 ? 1 : 0, now, a < 0 ? (off.length - 1) * out * 0.5 + 120 : 0, 40);
+ act = a;
+ read.textContent = a < 0 ? "rest" : leaves[a].tag!;
+ B.wake();
+ }
+
+ bag.add(pointer(stage, { move: (p) => setActive(hit(p)), leave: () => setActive(-1) }));
+ bag.add(() => svg.replaceChildren());
+
+ return { set: (v) => { step = v; }, destroy: bag.dispose };
+};
diff --git a/packages/hairline/src/figures/settle.ts b/packages/hairline/src/figures/settle.ts
new file mode 100644
index 0000000..8589799
--- /dev/null
+++ b/packages/hairline/src/figures/settle.ts
@@ -0,0 +1,179 @@
+import { Cam, clamp, facing, fit, lerp, poly, prism, proj, rad, ringAt, rings, rrect, seg, unproj, type Ring, type Vec2, type Vec3 } from "../core/iso";
+import { reducedMotion, spring, stepS, tdone, tset, tval, tween, type Spring, type Tween } from "../core/motion";
+import { disposer, mk, pointer, put, register, solid, type FigureMount, type Solid } from "../core/stage";
+
+/**
+ * Settle: a hub plate on a faint floor grid and twelve thin tiles lying
+ * scattered and crooked around it, no links. The nearer the pointer comes to
+ * the hub, the more the map resolves: each tile slides and turns into its
+ * place in a pinwheel tree on its own spring, the inner ones first, and a
+ * dashed link draws in from the hub once both its ends are seated. Pointer far
+ * away: they drift back to the heap. The hub takes the bright stroke. The
+ * slider is the reach, in world units: how far from the hub the map starts to
+ * resolve.
+ *
+ * The pattern: a field, read as a count. The pointer sets a distance on the
+ * ground plane (which never moves); each tile has its own threshold on it.
+ */
+
+const TH = 3.2, HALF = 9, HUB = 17, HUBT = 6.5, GRID = 22, GN = 0, GR = 86;
+// [settled x, y, parent (-1 hub), scattered x, y, angle, z]
+const T: number[][] = [
+ [50, 0, -1, 51, -19, 14, 0], [88, 0, 0, 93, 23, -22, 0], [50, 34, 0, 58, 50, 26, 0],
+ [0, 50, -1, -21, 59, -16, 0], [0, 88, 3, 20, 84, 28, 0], [-34, 50, 3, -59, 64, -20, 0],
+ [-50, 0, -1, -67, -20, -12, 0], [-88, 0, 6, -91, 26, 20, 0], [-50, -34, 6, -47, -57, -28, 0],
+ [0, -50, -1, 22, -46, 18, 0], [0, -88, 9, -15, -95, -14, 0], [34, -50, 9, 62, -60, 22, 0],
+];
+
+type Link = { i: number; from: Vec2; to: Vec2; tw: Tween; p: number; el: SVGPathElement; drawn: number };
+type Tile = {
+ i: number; t: number[]; el: Solid; th: number; sp: Spring; key: string; ord: number; k: number;
+ rise: { k: number; c: number }; fall: { k: number; c: number }; lag: number; want: number; wait: number; falling: boolean;
+};
+
+/** A rounded square of half-side h about (cx, cy), turned by a degrees: a ring whose samples carry their normals round with it. */
+function turned(cx: number, cy: number, h: number, r: number, a: number): Ring {
+ const c = Math.cos(rad(a)), s = Math.sin(rad(a));
+ return rrect(-h, -h, h, h, r, 4).map((q) => ({
+ u: cx + q.u * c - q.v * s, v: cy + q.u * s + q.v * c, nu: q.nu * c - q.nv * s, nv: q.nu * s + q.nv * c,
+ }));
+}
+
+export const mount: FigureMount = ({ stage, svg, read }, value) => {
+ const bag = disposer();
+ let reach = value, q = 0;
+
+ const C = Cam(45, 0.5, 1.9);
+ const pts: Vec3[] = [[0, 0, HUBT], [GR, 0, 0], [-GR, 0, 0], [0, GR, 0], [0, -GR, 0]];
+ for (const t of T) for (const [x, y] of [[t[0], t[1]], [t[3], t[4]]] as Vec2[]) pts.push([x - 11, y - 11, 0], [x + 11, y + 11, 0], [x + 11, y - 11, 0], [x - 11, y + 11, 0]);
+ fit(C, pts, 200, 166);
+ const P = proj(C), front = facing(C);
+
+ const g = mk("g", {}, svg);
+ // the floor: a faint grid, lying flat, under everything
+ let d = "";
+ for (let k = -GN; k <= GN; k++) {
+ const e = Math.sqrt(GR * GR - (k * GRID) ** 2);
+ d += seg(P(k * GRID, -e, 0), P(k * GRID, e, 0)) + seg(P(-e, k * GRID, 0), P(e, k * GRID, 0));
+ }
+ if (GN > 0) mk("path", { d, class: "nf lo" }, g);
+
+ // links are guides on the floor: painted before every plate they join
+ const links: Link[] = T.map((t, i) => {
+ const a: Vec2 = t[2] < 0 ? [0, 0] : [T[t[2]][0], T[t[2]][1]], b: Vec2 = [t[0], t[1]];
+ const L = Math.hypot(b[0] - a[0], b[1] - a[1]), u = [(b[0] - a[0]) / L, (b[1] - a[1]) / L];
+ const ha = t[2] < 0 ? HUB : HALF, from: Vec2 = [a[0] + u[0] * (ha + 2), a[1] + u[1] * (ha + 2)], to: Vec2 = [b[0] - u[0] * (HALF + 2), b[1] - u[1] * (HALF + 2)];
+ return { i, from, to, tw: tween(0), p: parent(i), el: mk("path", { class: "nf" }, g), drawn: NaN };
+ });
+ function parent(i: number) { return T[i][2]; }
+
+ // the hub: a thick slab with a recessed square set into its lid
+ const hub = mk("g", {}, g);
+ const [hr, hi] = rings(-HUB, -HUB, HUB, HUB, 5, 1.6);
+ const hs = solid(hub);
+ put(hs, prism(P, front, hr, hi, 0, HUBT));
+ hs.sil.classList.add("hi");
+ mk("path", { d: poly(ringAt(P, rrect(-9.5, -9.5, 9.5, 9.5, 2.5, 4), HUBT)), class: "nf lo" }, hub);
+
+ const tiles: Tile[] = T.map((t, i) => ({
+ i, t, el: solid(mk("g", {}, g)),
+ // the inner tiles seat first and a little more briskly; the outer ones follow, out of step
+ th: [0.05, 0.3, 0.4][i % 3],
+ sp: spring(0, { k: i % 3 === 0 ? 120 : 90 - (i % 3) * 8, c: i % 3 === 0 ? 14 : 12, eps: 0.002 }),
+ key: "", ord: 0, k: 0,
+ // arrival and return keep their own springs: the return is softer, near-critical, no bounce
+ rise: { k: i % 3 === 0 ? 120 : 90 - (i % 3) * 8, c: i % 3 === 0 ? 14 : 12 },
+ fall: { k: [38, 44, 50][i % 3], c: 2 * Math.sqrt([38, 44, 50][i % 3]) },
+ // outermost let go first: the leaves, then the middles, then the stems
+ lag: [0.3, 0.2, 0.12][i % 3] * 1000,
+ want: 0, wait: 0, falling: false,
+ }));
+
+ function pose(tl: Tile) {
+ const s = tl.sp.x, [sx, sy, , x0, y0, a0, z0] = tl.t;
+ const w = clamp(s, 0, 1), hop = 6.5 * w * (1 - w) * 4 / 4;
+ const x = lerp(x0, sx, s), y = lerp(y0, sy, s), a = lerp(a0, 0, s), z = Math.max(0, lerp(z0, 0, w) + hop);
+ return { x, y, a, z };
+ }
+ function drawTile(tl: Tile) {
+ const p = pose(tl), key = [p.x, p.y, p.a, p.z].map((v) => v.toFixed(2)).join();
+ tl.k = p.x + p.y + 6 * p.z;
+ if (key === tl.key) return;
+ tl.key = key;
+ put(tl.el, prism(P, front, turned(p.x, p.y, HALF, 2.6, p.a), turned(p.x, p.y, HALF - 1.1, 1.6, p.a), p.z, p.z + TH));
+ }
+
+ let order = "";
+ function paintOrder() {
+ const list = tiles.slice().sort((a, b) => a.k - b.k);
+ const hubAt = list.findIndex((t) => t.k > 0), arr = list.slice();
+ // the hub sits at x + y = 0; tiles are painted around it
+ const seq: (SVGGElement | SVGGElement)[] = hubAt < 0 ? arr.map((t) => t.el.g).concat(hub) : arr.slice(0, hubAt).map((t) => t.el.g).concat(hub, arr.slice(hubAt).map((t) => t.el.g));
+ const id = seq.map((e) => (e === hub ? "h" : tiles.findIndex((t) => t.el.g === e))).join();
+ if (id === order) return;
+ order = id;
+ for (const e of seq) g.appendChild(e);
+ }
+
+ function drawLink(l: Link, now: number) {
+ const A = l.p < 0 ? null : tiles[l.p], B2 = tiles[l.i];
+ const a = A ? A.sp.x : 1, b = B2.sp.x;
+ // it draws in only once both ends are seated, and draws back out as soon as either is asked to leave
+ const want = Math.min(a, b) > 0.96 && B2.want >= 1 && (!A || A.want >= 1) ? 1 : 0;
+ if (l.tw.to !== want) { tset(l.tw, want, now, 0); l.tw.dur = want ? 700 : 900; }
+ const u = tval(l.tw, now);
+ if (u === l.drawn) return;
+ l.drawn = u;
+ // real dashes along the link in screen space, as many as the draw-in has reached
+ const pa = P(l.from[0], l.from[1], 0), pb = P(l.to[0], l.to[1], 0), k = Math.max(2, Math.round(Math.hypot(pb[0] - pa[0], pb[1] - pa[1]) / 9));
+ let dd = "";
+ for (let j = 0; j < k; j++) {
+ const f0 = (j + 0.1) / k, f1 = Math.min((j + 0.6) / k, u);
+ if (f1 > f0) dd += seg([lerp(pa[0], pb[0], f0), lerp(pa[1], pb[1], f0)], [lerp(pa[0], pb[0], f1), lerp(pa[1], pb[1], f1)]);
+ }
+ l.el.setAttribute("d", dd);
+ }
+
+ const B = register(stage, (dt, now) => {
+ let m = false;
+ for (const tl of tiles) {
+ if (tl.wait > 0) { tl.wait -= dt * 1000; m = true; if (tl.wait <= 0) tl.sp.t = tl.want; }
+ if (stepS(tl.sp, dt)) m = true;
+ drawTile(tl);
+ }
+ for (const l of links) { drawLink(l, now); if (!tdone(l.tw, now)) m = true; }
+ paintOrder();
+ return m;
+ });
+ bag.add(B.unregister);
+
+ function retarget() {
+ let n = 0;
+ for (const tl of tiles) {
+ const s = clamp((q - tl.th) / 0.22, 0, 1);
+ if (s > tl.want) {
+ tl.falling = false; tl.wait = 0; tl.want = s; Object.assign(tl.sp, tl.rise); tl.sp.t = s;
+ } else if (s < tl.want) {
+ if (!tl.falling) { tl.falling = true; tl.wait = reducedMotion() ? 0 : tl.lag; Object.assign(tl.sp, tl.fall); }
+ tl.want = s;
+ if (tl.wait <= 0) tl.sp.t = s;
+ }
+ if (s > 0.5) n++;
+ }
+ read.textContent = q <= 0 ? "rest" : `map ${n}·${tiles.length}`;
+ B.wake();
+ }
+
+ /** How resolved the map is, 0 at the reach and beyond, 1 at the hub. */
+ const resolve = (dd: number) => { const u = clamp((reach - dd) / (reach - 18), 0, 1); return u * u * (3 - 2 * u); };
+ bag.add(pointer(stage, {
+ move: (p) => { const [x, y] = unproj(C, p[0], p[1], 0); q = resolve(Math.hypot(x, y)); retarget(); },
+ leave: () => { q = 0; retarget(); },
+ }));
+ bag.add(() => svg.replaceChildren());
+ for (const tl of tiles) drawTile(tl);
+ paintOrder();
+ read.textContent = "rest";
+
+ return { set: (v) => { reach = v; }, destroy: bag.dispose };
+};
diff --git a/packages/hairline/src/figures/stack.ts b/packages/hairline/src/figures/stack.ts
new file mode 100644
index 0000000..a6e75f9
--- /dev/null
+++ b/packages/hairline/src/figures/stack.ts
@@ -0,0 +1,125 @@
+import { Cam, facing, fit, poly, prism, proj, ringAt, rings, type Ring } from "../core/iso";
+import { spring, stepS, tdone, tset, tval, tween, type Spring, type Tween } from "../core/motion";
+import { disposer, mk, pointer, put, register, solid, type FigureMount, type Solid } from "../core/stage";
+
+/**
+ * Stack: a call stack, five frames laid one over another on a base plate, each
+ * a thin slab with a quiet inset rim on the lid. The pointer's height picks a
+ * frame: the frames above it lift away on the 700ms curve, the top one furthest
+ * and each in turn, so the chosen frame opens to the eye and takes the bright
+ * edge. At rest the stack sits closed with the top frame, the one running now,
+ * bright. The slider is the lift, in world units.
+ *
+ * The pattern: discrete items. Tweens, a stagger by distance, and a hit test
+ * on static bands of the resting stack's height, so a lifting frame cannot
+ * move the choice.
+ */
+const N = 5, T = 4, PITCH = 9, Z0 = 7, FW = 56, STEP = 55;
+const BASE = [-8, -8, 64, 64], BT = 4;
+// Each frame sits a little off the one below, so the closed stack is not a block.
+// Motion: opening is quick and gets a calm settle; closing is slower and softer,
+// the low frames first and the top one last to land; the bright mark rides the kernel's 260ms stroke fade.
+const OPEN = 700, CLOSE = 1250, CSTEP = 45, KICK = 0.42, SETTLE = 230;
+const HYS = 5;
+const OFF = [[-1.5, 1], [1.5, -1.2], [-0.5, -1.8], [2, 1.2], [0, 0]];
+
+type Frame = { j: number; ring: Ring; inner: Ring; el: Solid; rim: Ring; lid: SVGPathElement; tw: Tween; sp: Spring & { v0?: number }; kick: number; drawn: number };
+
+export const mount: FigureMount = ({ stage, svg, read }, value) => {
+ const bag = disposer();
+ let lift = value;
+ /** How far frame j stands above its place when frame a is chosen: the top frame furthest. */
+ const up = (j: number, a: number) => (j <= a ? 0 : lift * (0.4 + (0.6 * (j - a)) / (N - 1 - a)));
+
+ const C = Cam(45, 0.5, 2.2);
+ const ztop = Z0 + (N - 1) * PITCH + T;
+ fit(C, [[BASE[0], BASE[1], 0], [BASE[2], BASE[3], 0], [BASE[0], BASE[1], ztop + 46], [BASE[2], BASE[3], ztop + 46]], 200, 166);
+ const P = proj(C), front = facing(C);
+
+ const g = mk("g", {}, svg);
+ const [br, bi] = rings(BASE[0], BASE[1], BASE[2], BASE[3], 8, 1.6);
+ put(solid(g), prism(P, front, br, bi, 0, BT));
+ // a recessed square in the base, under the stack
+ const [rr] = rings(4, 4, 52, 52, 4, 1);
+ mk("path", { d: poly(ringAt(P, rr, BT)), class: "nf lo" }, g);
+
+ const fr: Frame[] = [];
+ for (let j = 0; j < N; j++) {
+ const x0 = 0 + OFF[j][0], y0 = 0 + OFF[j][1];
+ const [ring, inner] = rings(x0, y0, x0 + FW, y0 + FW, 5, 1.1);
+ const el = solid(g);
+ // the same quiet inset rim on every lid
+ const [rim] = rings(x0 + 5, y0 + 5, x0 + FW - 5, y0 + FW - 5, 2.5, 0.6);
+ fr.push({ j, ring, inner, el, rim, lid: mk("path", { class: "nf lo" }, el.g), tw: tween(0), sp: spring(0, { k: 90, c: 10, eps: 0.005 }), kick: Infinity, drawn: NaN });
+ }
+
+ function draw(f: Frame, e: number) {
+ const z = Z0 + f.j * PITCH + e;
+ put(f.el, prism(P, front, f.ring, f.inner, z, z + T));
+ f.lid.setAttribute("d", poly(ringAt(P, f.rim, z + T)));
+ }
+
+ const B = register(stage, (_dt, now) => {
+ let moving = false;
+ for (const f of fr) {
+ if (now >= f.kick) { f.kick = Infinity; f.sp.v = KICK * f.sp.v0!; }
+ const bump = f.sp.x !== 0 || f.sp.v !== 0 ? (stepS(f.sp, _dt), f.sp.x) : 0;
+ const e = tval(f.tw, now) + bump;
+ if (!tdone(f.tw, now) || f.kick !== Infinity || f.sp.x !== 0 || f.sp.v !== 0) moving = true;
+ if (e !== f.drawn) { f.drawn = e; draw(f, e); }
+ }
+ return moving;
+ });
+ bag.add(B.unregister);
+
+ // Hit bands: the resting stack's heights on screen. They never move.
+ const mid = fr.map((f) => P(FW / 2 + OFF[f.j][0], FW - 9 + OFF[f.j][1], Z0 + f.j * PITCH + T)[1]);
+ const xs = ringAt(P, br, 0).map((q) => q[0]), yb = Math.max(...ringAt(P, br, 0).map((q) => q[1]));
+ const xa = Math.min(...xs) + 4, xb = Math.max(...xs) - 4, ya = mid[N - 1] - 150;
+ /** The frame at the point's height, clamped to the stack; -1 off the column. */
+ function hit([x, y]: [number, number]) {
+ if (x < xa || x > xb || y > yb || y < ya) return -1;
+ // keep the current frame until the pointer is clearly inside another band
+ if (act >= 0) {
+ const lo = act < N - 1 ? (mid[act] + mid[act + 1]) / 2 : -1e9, hi = act > 0 ? (mid[act - 1] + mid[act]) / 2 : 1e9;
+ if (y >= lo - HYS && y <= hi + HYS) return act;
+ }
+ let a = 0;
+ while (a < N - 1 && y < (mid[a] + mid[a + 1]) / 2) a++;
+ return a;
+ }
+
+ let act = -1;
+ function apply(a: number, from: number) {
+ const now = performance.now(), s = a < 0 ? N - 1 : a;
+ fr.forEach((f) => {
+ const to = a < 0 ? 0 : up(f.j, a), cur = tval(f.tw, now);
+ if (to !== f.tw.to) {
+ const closing = to < cur;
+ tset(f.tw, to, now, closing ? (a < 0 ? f.j * CSTEP : Math.abs(f.j - from) * 30) : Math.abs(f.j - from) * STEP);
+ f.tw.dur = closing ? CLOSE : OPEN;
+ if (!closing) { f.kick = f.tw.t0 + SETTLE; f.sp.v0 = Math.max(6, to - cur) * 0.5; f.sp.v0! /= KICK; }
+ }
+ f.el.sil.classList.toggle("hi", f.j === s);
+ });
+ B.wake();
+ }
+ apply(-1, N - 1);
+ read.textContent = "rest";
+
+ function over(a: number) {
+ if (a === act) return;
+ const from = a < 0 ? act : a;
+ act = a;
+ read.textContent = a < 0 ? "rest" : "fr " + (a + 1);
+ apply(a, from);
+ }
+
+ bag.add(pointer(stage, { move: (p) => over(hit(p)), leave: () => over(-1) }));
+ bag.add(() => svg.replaceChildren());
+
+ return {
+ set: (v: number) => { lift = v; apply(act, act < 0 ? N - 1 : act); },
+ destroy: bag.dispose,
+ };
+};
diff --git a/packages/hairline/src/index.ts b/packages/hairline/src/index.ts
index 9aef472..8dee8f3 100644
--- a/packages/hairline/src/index.ts
+++ b/packages/hairline/src/index.ts
@@ -6,6 +6,8 @@ import { mount as dishEngine } from "./figures/dish";
import { mount as drawerEngine } from "./figures/drawer";
import { mount as elevatorEngine } from "./figures/elevator";
import { mount as explodedEngine } from "./figures/exploded";
+import { mount as formatEngine } from "./figures/format";
+import { mount as hubEngine } from "./figures/hub";
import { mount as keyboardEngine } from "./figures/keyboard";
import { mount as laptopEngine } from "./figures/laptop";
import { mount as lockersEngine } from "./figures/lockers";
@@ -18,17 +20,21 @@ import { mount as plotEngine } from "./figures/plot";
import { mount as plugEngine } from "./figures/plug";
import { mount as queryEngine } from "./figures/query";
import { mount as railEngine } from "./figures/rail";
+import { mount as rebuildEngine } from "./figures/rebuild";
+import { mount as relayEngine } from "./figures/relay";
import { mount as riffleEngine } from "./figures/riffle";
import { mount as routerEngine } from "./figures/router";
+import { mount as settleEngine } from "./figures/settle";
import { mount as sieveEngine } from "./figures/sieve";
import { mount as slowEngine } from "./figures/slow";
+import { mount as stackEngine } from "./figures/stack";
import { mount as terminalEngine } from "./figures/terminal";
import { mount as terrainEngine } from "./figures/terrain";
import { mount as turntableEngine } from "./figures/turntable";
import { mount as vaultEngine } from "./figures/vault";
/**
- * @lucasmarkes/hairline — twenty-seven isometric line figures that answer the pointer.
+ * @lucasmarkes/hairline — thirty-three 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
@@ -307,3 +313,69 @@ export function plot(el: HTMLElement, options?: HairlineOptions): Figure {
engine: plotEngine,
}, el, options);
}
+
+/** A hub and eight tiles on a grid: the tile under the pointer rises and its link turns solid, and its neighbours rise less. `intensity` raises the tiles higher. */
+export function hub(el: HTMLElement, options?: HairlineOptions): Figure {
+ return create({
+ id: "hub",
+ label: "A hub and eight tiles on a grid: the tile under the pointer rises and its link turns solid; its neighbours rise less.",
+ rest: "rest",
+ engine: hubEngine,
+ tour: [[205, 112], [260, 144], [329, 179], [263, 207], [201, 243], null],
+ }, el, options);
+}
+
+/** A hub and four branches of tiles: the path to the leaf under the pointer lights hop by hop, each tile rising in turn. `intensity` makes each hop wait longer. */
+export function relay(el: HTMLElement, options?: HairlineOptions): Figure {
+ return create({
+ id: "relay",
+ label: "A hub and four branches of tiles: the path to the leaf under the pointer lights hop by hop, each tile rising in turn.",
+ rest: "rest",
+ engine: relayEngine,
+ tour: [[45, 145], [140, 253], [271, 258], [355, 216], [344, 151], null],
+ }, el, options);
+}
+
+/** Twelve tiles lie crooked round a hub; as the pointer nears it they slide into a tree and the links draw in. `intensity` starts the tree from further away. */
+export function settle(el: HTMLElement, options?: HairlineOptions): Figure {
+ return create({
+ id: "settle",
+ label: "Twelve tiles lie crooked round a hub; as the pointer nears it they slide into a tree and the links draw in.",
+ rest: "rest",
+ engine: settleEngine,
+ tour: [[360, 40], [320, 120], [203, 155], null],
+ }, el, options);
+}
+
+/** A file of ten crooked lines: the pointer runs the formatter down it, and every line above snaps square to its indent. `intensity` starts the lines more crooked. */
+export function format(el: HTMLElement, options?: HairlineOptions): Figure {
+ return create({
+ id: "format",
+ label: "A file of ten crooked lines: the pointer runs the formatter down it, and every line above snaps square to its indent.",
+ rest: "rest",
+ engine: formatEngine,
+ tour: [[290, 162], [199, 168], [135, 200], null],
+ }, el, options);
+}
+
+/** A tree of package tiles: the one touched rises, and every package that depends on it rises after it along the links. `intensity` raises them higher. */
+export function rebuild(el: HTMLElement, options?: HairlineOptions): Figure {
+ return create({
+ id: "rebuild",
+ label: "A tree of package tiles: the one touched rises, and every package that depends on it rises after it along the links.",
+ rest: "rest",
+ engine: rebuildEngine,
+ tour: [[47, 236], [276, 172], [181, 106], null],
+ }, el, options);
+}
+
+/** A call stack of five frames: the pointer's height picks one, and the frames above lift away to open it. `intensity` lifts them further. */
+export function stack(el: HTMLElement, options?: HairlineOptions): Figure {
+ return create({
+ id: "stack",
+ label: "A call stack of five frames: the pointer's height picks one, and the frames above lift away to open it.",
+ rest: "rest",
+ engine: stackEngine,
+ tour: [[200, 250], [200, 216], [200, 199], null],
+ }, el, options);
+}
diff --git a/packages/hairline/src/intensity.ts b/packages/hairline/src/intensity.ts
index e126557..87b2d8e 100644
--- a/packages/hairline/src/intensity.ts
+++ b/packages/hairline/src/intensity.ts
@@ -7,7 +7,7 @@
* copy and its tests hold the two together.
*/
-export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches" | "vault" | "lockers" | "padlock" | "patch" | "dish" | "router" | "loupe" | "sieve" | "rail" | "plug" | "query" | "drawer" | "basket" | "plot";
+export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches" | "vault" | "lockers" | "padlock" | "patch" | "dish" | "router" | "loupe" | "sieve" | "rail" | "plug" | "query" | "drawer" | "basket" | "plot" | "hub" | "relay" | "settle" | "format" | "rebuild" | "stack";
/** 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]> = {
@@ -38,6 +38,12 @@ export const TABLE: Record<FigureId, readonly [number, number, number]> = {
drawer: [12, 22, 34], // pull, viewBox units
basket: [8, 16, 28], // tilt, degrees
plot: [3, 6, 12], // lift, viewBox units
+ hub: [10, 16, 24], // rise, viewBox units
+ relay: [40, 120, 220], // delay, ms per hop
+ settle: [90, 120, 150], // reach, viewBox units from the hub
+ format: [9, 12, 14], // disorder, degrees of the worst skew
+ rebuild: [8, 14, 20], // rise, viewBox units
+ stack: [22, 34, 46], // lift, viewBox units
};
export const DEFAULT = 0.5;
diff --git a/packages/hairline/src/react.tsx b/packages/hairline/src/react.tsx
index 52b148d..843d2f9 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 { basket, branches, cabinet, dish, drawer, elevator, exploded, keyboard, laptop, lockers, loupe, padlock, patch, phone, phosphor, plot, plug, query, rail, riffle, router, sieve, slow, terminal, terrain, turntable, vault, type Figure, type HairlineOptions } from "./index";
+import { basket, branches, cabinet, dish, drawer, elevator, exploded, format, hub, keyboard, laptop, lockers, loupe, padlock, patch, phone, phosphor, plot, plug, query, rail, rebuild, relay, riffle, router, settle, sieve, slow, stack, terminal, terrain, turntable, vault, type Figure, type HairlineOptions } from "./index";
/**
- * @lucasmarkes/hairline/react — the twenty-seven figures as components.
+ * @lucasmarkes/hairline/react — the thirty-three 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.
@@ -107,3 +107,15 @@ export const Drawer = make("Drawer", drawer);
export const Basket = make("Basket", basket);
/** A bar chart with no data: seven flat tabs on its base, before a plate of grid lines. The pointer brushes them, and each lifts a little, the nearest most, and drops back to zero. `intensity` lifts them higher. */
export const Plot = make("Plot", plot);
+/** A hub and eight tiles on a grid: the tile under the pointer rises and its link turns solid, and its neighbours rise less. `intensity` raises the tiles higher. */
+export const Hub = make("Hub", hub);
+/** A hub and four branches of tiles: the path to the leaf under the pointer lights hop by hop, each tile rising in turn. `intensity` makes each hop wait longer. */
+export const Relay = make("Relay", relay);
+/** Twelve tiles lie crooked round a hub; as the pointer nears it they slide into a tree and the links draw in. `intensity` starts the tree from further away. */
+export const Settle = make("Settle", settle);
+/** A file of ten crooked lines: the pointer runs the formatter down it, and every line above snaps square to its indent. `intensity` starts the lines more crooked. */
+export const Format = make("Format", format);
+/** A tree of package tiles: the one touched rises, and every package that depends on it rises after it along the links. `intensity` raises them higher. */
+export const Rebuild = make("Rebuild", rebuild);
+/** A call stack of five frames: the pointer's height picks one, and the frames above lift away to open it. `intensity` lifts them further. */
+export const Stack = make("Stack", stack);
diff --git a/packages/hairline/test/browser/entry.ts b/packages/hairline/test/browser/entry.ts
index b9eeb6f..c10a647 100644
--- a/packages/hairline/test/browser/entry.ts
+++ b/packages/hairline/test/browser/entry.ts
@@ -4,7 +4,7 @@ import * as hairline from "../../src/index";
* The harness page's script: the package, on `window`, with one figure at a
* time on #host. Tests drive it through page.evaluate.
*/
-type Id = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches" | "vault" | "lockers" | "padlock" | "patch" | "dish" | "router" | "loupe" | "sieve" | "rail" | "plug" | "query" | "drawer" | "basket" | "plot";
+type Id = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches" | "vault" | "lockers" | "padlock" | "patch" | "dish" | "router" | "loupe" | "sieve" | "rail" | "plug" | "query" | "drawer" | "basket" | "plot" | "hub" | "relay" | "settle" | "format" | "rebuild" | "stack";
type Loose = Record<string, unknown>;
type Mount = (el: HTMLElement, options?: Loose) => { update(o: Loose): void; destroy(): void };
diff --git a/packages/hairline/test/browser/figures.spec.ts b/packages/hairline/test/browser/figures.spec.ts
index 2de17a6..c2d52a6 100644
--- a/packages/hairline/test/browser/figures.spec.ts
+++ b/packages/hairline/test/browser/figures.spec.ts
@@ -2,7 +2,7 @@ import { expect, test, type Page } from "@playwright/test";
/** The figures in a real browser: input, focus, reduced motion, shadow roots, a clean console. */
-const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches", "vault", "lockers", "padlock", "patch", "dish", "router", "loupe", "sieve", "rail", "plug", "query", "drawer", "basket", "plot"] as const;
+const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches", "vault", "lockers", "padlock", "patch", "dish", "router", "loupe", "sieve", "rail", "plug", "query", "drawer", "basket", "plot", "hub", "relay", "settle", "format", "rebuild", "stack"] as const;
type Id = (typeof IDS)[number];
const mount = (page: Page, id: Id, options: Record<string, unknown> = {}) =>
diff --git a/packages/hairline/test/mount.test.ts b/packages/hairline/test/mount.test.ts
index 8a041f7..3502729 100644
--- a/packages/hairline/test/mount.test.ts
+++ b/packages/hairline/test/mount.test.ts
@@ -1,11 +1,11 @@
// @vitest-environment jsdom
import { describe, expect, it, vi } from "vitest";
import { frames, host, observers, pending } from "./dom";
-import { basket, branches, cabinet, dish, drawer, elevator, exploded, keyboard, laptop, lockers, loupe, padlock, patch, phone, phosphor, plot, plug, query, rail, riffle, router, sieve, slow, terminal, terrain, turntable, vault } from "../src/index";
+import { basket, branches, cabinet, dish, drawer, elevator, exploded, format, hub, keyboard, laptop, lockers, loupe, padlock, patch, phone, phosphor, plot, plug, query, rail, rebuild, relay, riffle, router, settle, sieve, slow, stack, terminal, terrain, turntable, vault } from "../src/index";
import { css } from "../src/core/styles";
import { create } from "../src/mount";
-const ALL = { riffle, terrain, exploded, phosphor, slow, turntable, keyboard, elevator, phone, laptop, terminal, cabinet, branches, vault, lockers, padlock, patch, dish, router, loupe, sieve, rail, plug, query, drawer, basket, plot };
+const ALL = { riffle, terrain, exploded, phosphor, slow, turntable, keyboard, elevator, phone, laptop, terminal, cabinet, branches, vault, lockers, padlock, patch, dish, router, loupe, sieve, rail, plug, query, drawer, basket, plot, hub, relay, settle, format, rebuild, stack };
const key = (el: Element, k: string) => el.dispatchEvent(new KeyboardEvent("keydown", { key: k, bubbles: true, cancelable: true }));
describe("mount", () => {
@@ -184,6 +184,12 @@ describe("intensity", () => {
drawer: [[200, 90], 60],
basket: [[90, 260], 60],
plot: [[200, 160], 6],
+ hub: [[260, 144], 12],
+ relay: [[271, 258], 12],
+ settle: [[320, 120], 30],
+ format: [[199, 168], 12],
+ rebuild: [[276, 172], 12],
+ stack: [[200, 216], 12],
};
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.tsx
index 606af73..86ffe95 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 { Basket, Branches, Cabinet, Dish, Drawer, Elevator, Exploded, Keyboard, Laptop, Lockers, Loupe, Padlock, Patch, Phone, Phosphor, Plot, Plug, Query, Rail, Riffle, Router, Sieve, Slow, Terminal, Terrain, Turntable, Vault } from "../src/react";
+import { Basket, Branches, Cabinet, Dish, Drawer, Elevator, Exploded, Format, Hub, Keyboard, Laptop, Lockers, Loupe, Padlock, Patch, Phone, Phosphor, Plot, Plug, Query, Rail, Rebuild, Relay, Riffle, Router, Settle, Sieve, Slow, Stack, Terminal, Terrain, Turntable, Vault } from "../src/react";
afterEach(cleanup);
@@ -29,9 +29,9 @@ describe("components", () => {
});
it("renders each figure into one div", () => {
- const { container } = render(<><Riffle /><Terrain /><Exploded /><Phosphor /><Slow /><Turntable /><Keyboard /><Elevator /><Phone /><Laptop /><Terminal /><Cabinet /><Branches /><Vault /><Lockers /><Padlock /><Patch /><Dish /><Router /><Loupe /><Sieve /><Rail /><Plug /><Query /><Drawer /><Basket /><Plot /></>);
+ const { container } = render(<><Riffle /><Terrain /><Exploded /><Phosphor /><Slow /><Turntable /><Keyboard /><Elevator /><Phone /><Laptop /><Terminal /><Cabinet /><Branches /><Vault /><Lockers /><Padlock /><Patch /><Dish /><Router /><Loupe /><Sieve /><Rail /><Plug /><Query /><Drawer /><Basket /><Plot /><Hub /><Relay /><Settle /><Format /><Rebuild /><Stack /></>);
const ids = [...container.children].map((el) => el.getAttribute("data-hairline"));
- expect(ids).toEqual(["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches", "vault", "lockers", "padlock", "patch", "dish", "router", "loupe", "sieve", "rail", "plug", "query", "drawer", "basket", "plot"]);
+ expect(ids).toEqual(["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches", "vault", "lockers", "padlock", "patch", "dish", "router", "loupe", "sieve", "rail", "plug", "query", "drawer", "basket", "plot", "hub", "relay", "settle", "format", "rebuild", "stack"]);
for (const el of container.children) expect(el.querySelectorAll(":scope > svg")).toHaveLength(1);
});
@@ -130,7 +130,7 @@ describe("components", () => {
});
it("names the components for the dev tools", () => {
- expect([Riffle, Terrain, Exploded, Phosphor, Slow, Turntable, Keyboard, Elevator, Phone, Laptop, Terminal, Cabinet, Branches, Vault, Lockers, Padlock, Patch, Dish, Router, Loupe, Sieve, Rail, Plug, Query, Drawer, Basket, Plot].map((c) => c.displayName))
- .toEqual(["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard", "Elevator", "Phone", "Laptop", "Terminal", "Cabinet", "Branches", "Vault", "Lockers", "Padlock", "Patch", "Dish", "Router", "Loupe", "Sieve", "Rail", "Plug", "Query", "Drawer", "Basket", "Plot"]);
+ expect([Riffle, Terrain, Exploded, Phosphor, Slow, Turntable, Keyboard, Elevator, Phone, Laptop, Terminal, Cabinet, Branches, Vault, Lockers, Padlock, Patch, Dish, Router, Loupe, Sieve, Rail, Plug, Query, Drawer, Basket, Plot, Hub, Relay, Settle, Format, Rebuild, Stack].map((c) => c.displayName))
+ .toEqual(["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard", "Elevator", "Phone", "Laptop", "Terminal", "Cabinet", "Branches", "Vault", "Lockers", "Padlock", "Patch", "Dish", "Router", "Loupe", "Sieve", "Rail", "Plug", "Query", "Drawer", "Basket", "Plot", "Hub", "Relay", "Settle", "Format", "Rebuild", "Stack"]);
});
});
diff --git a/packages/hairline/test/types.test-d.tsx b/packages/hairline/test/types.test-d.tsx
index bbf9528..23b9a03 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 { basket, branches, cabinet, dish, drawer, elevator, exploded, keyboard, laptop, lockers, loupe, padlock, patch, phone, phosphor, plot, plug, query, rail, riffle, router, sieve, slow, terminal, terrain, turntable, vault, type Figure, type HairlineOptions } from "../src/index";
+import { basket, branches, cabinet, dish, drawer, elevator, exploded, format, hub, keyboard, laptop, lockers, loupe, padlock, patch, phone, phosphor, plot, plug, query, rail, rebuild, relay, riffle, router, settle, sieve, slow, stack, terminal, terrain, turntable, vault, type Figure, type HairlineOptions } from "../src/index";
import * as vanilla from "../src/index";
import * as components from "../src/react";
-import { Basket, Branches, Cabinet, Dish, Drawer, Elevator, Exploded, Keyboard, Laptop, Lockers, Loupe, Padlock, Patch, Phone, Phosphor, Plot, Plug, Query, Rail, Riffle, Router, Sieve, Slow, Terminal, Terrain, Turntable, Vault, type HairlineProps } from "../src/react";
+import { Basket, Branches, Cabinet, Dish, Drawer, Elevator, Exploded, Format, Hub, Keyboard, Laptop, Lockers, Loupe, Padlock, Patch, Phone, Phosphor, Plot, Plug, Query, Rail, Rebuild, Relay, Riffle, Router, Settle, Sieve, Slow, Stack, Terminal, Terrain, Turntable, Vault, type HairlineProps } from "../src/react";
declare const el: HTMLElement;
type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
@@ -16,7 +16,7 @@ const yes = <T extends true>() => {};
/* every figure takes the same options */
riffle(el, { intensity: 0.8, theme: "dark", label: "Cards", onRead: (t: string) => t });
riffle(el);
-for (const mount of [riffle, terrain, exploded, phosphor, slow, turntable, keyboard, elevator, phone, laptop, terminal, cabinet, branches, vault, lockers, padlock, patch, dish, router, loupe, sieve, rail, plug, query, drawer, basket, plot]) {
+for (const mount of [riffle, terrain, exploded, phosphor, slow, turntable, keyboard, elevator, phone, laptop, terminal, cabinet, branches, vault, lockers, padlock, patch, dish, router, loupe, sieve, rail, plug, query, drawer, basket, plot, hub, relay, settle, format, rebuild, stack]) {
yes<Equal<typeof mount, (el: HTMLElement, options?: HairlineOptions) => Figure>>();
// @ts-expect-error the old per-figure options are gone
mount(el, { stagger: 60 });
@@ -48,8 +48,8 @@ f.update({ stagger: 60 });
f.update({ bands: true });
/* the entries export the functions, the components and three types, and nothing of the old API */
-yes<Equal<keyof typeof vanilla, "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches" | "vault" | "lockers" | "padlock" | "patch" | "dish" | "router" | "loupe" | "sieve" | "rail" | "plug" | "query" | "drawer" | "basket" | "plot">>();
-yes<Equal<keyof typeof components, "Riffle" | "Terrain" | "Exploded" | "Phosphor" | "Slow" | "Turntable" | "Keyboard" | "Elevator" | "Phone" | "Laptop" | "Terminal" | "Cabinet" | "Branches" | "Vault" | "Lockers" | "Padlock" | "Patch" | "Dish" | "Router" | "Loupe" | "Sieve" | "Rail" | "Plug" | "Query" | "Drawer" | "Basket" | "Plot">>();
+yes<Equal<keyof typeof vanilla, "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop" | "terminal" | "cabinet" | "branches" | "vault" | "lockers" | "padlock" | "patch" | "dish" | "router" | "loupe" | "sieve" | "rail" | "plug" | "query" | "drawer" | "basket" | "plot" | "hub" | "relay" | "settle" | "format" | "rebuild" | "stack">>();
+yes<Equal<keyof typeof components, "Riffle" | "Terrain" | "Exploded" | "Phosphor" | "Slow" | "Turntable" | "Keyboard" | "Elevator" | "Phone" | "Laptop" | "Terminal" | "Cabinet" | "Branches" | "Vault" | "Lockers" | "Padlock" | "Patch" | "Dish" | "Router" | "Loupe" | "Sieve" | "Rail" | "Plug" | "Query" | "Drawer" | "Basket" | "Plot" | "Hub" | "Relay" | "Settle" | "Format" | "Rebuild" | "Stack">>();
// @ts-expect-error ranges is gone
void vanilla.ranges;
// @ts-expect-error the per-figure option types are gone
@@ -62,7 +62,7 @@ const ref = createRef<HTMLDivElement>();
<Riffle ref={ref} intensity={0.8} theme="dark" className="w-80" id="cards" onClick={() => {}} onRead={(text) => text.length} />;
<Terrain style={{ width: 320 }} aria-label="Dunes" data-x="1" />;
<Riffle />;
-for (const C of [Riffle, Terrain, Exploded, Phosphor, Slow, Turntable, Keyboard, Elevator, Phone, Laptop, Terminal, Cabinet, Branches, Vault, Lockers, Padlock, Patch, Dish, Router, Loupe, Sieve, Rail, Plug, Query, Drawer, Basket, Plot]) {
+for (const C of [Riffle, Terrain, Exploded, Phosphor, Slow, Turntable, Keyboard, Elevator, Phone, Laptop, Terminal, Cabinet, Branches, Vault, Lockers, Padlock, Patch, Dish, Router, Loupe, Sieve, Rail, Plug, Query, Drawer, Basket, Plot, Hub, Relay, Settle, Format, Rebuild, Stack]) {
// @ts-expect-error the old per-figure options are gone
<C stagger={60} />;
// @ts-expect-error the old per-figure options are gone
diff --git a/registry/src/hairline.tsx b/registry/src/hairline.tsx
index bb4b75e..8da3a40 100644
--- a/registry/src/hairline.tsx
+++ b/registry/src/hairline.tsx
@@ -93,3 +93,27 @@ export function Dish({ style, ...props }: ComponentProps<typeof Hairline.Dish>)
export function Router({ style, ...props }: ComponentProps<typeof Hairline.Router>) {
return <Hairline.Router style={{ ...tokens, ...style }} {...props} />;
}
+
+export function Hub({ style, ...props }: ComponentProps<typeof Hairline.Hub>) {
+ return <Hairline.Hub style={{ ...tokens, ...style }} {...props} />;
+}
+
+export function Relay({ style, ...props }: ComponentProps<typeof Hairline.Relay>) {
+ return <Hairline.Relay style={{ ...tokens, ...style }} {...props} />;
+}
+
+export function Settle({ style, ...props }: ComponentProps<typeof Hairline.Settle>) {
+ return <Hairline.Settle style={{ ...tokens, ...style }} {...props} />;
+}
+
+export function Format({ style, ...props }: ComponentProps<typeof Hairline.Format>) {
+ return <Hairline.Format style={{ ...tokens, ...style }} {...props} />;
+}
+
+export function Rebuild({ style, ...props }: ComponentProps<typeof Hairline.Rebuild>) {
+ return <Hairline.Rebuild style={{ ...tokens, ...style }} {...props} />;
+}
+
+export function Stack({ style, ...props }: ComponentProps<typeof Hairline.Stack>) {
+ return <Hairline.Stack style={{ ...tokens, ...style }} {...props} />;
+}
diff --git a/registry/validate.mjs b/registry/validate.mjs
index 3548956..a1aef28 100644
--- a/registry/validate.mjs
+++ b/registry/validate.mjs
@@ -29,7 +29,7 @@ const [source] = item.files ?? [];
if (item.dependencies?.join() !== "@lucasmarkes/hairline") problems.push("dependencies must be exactly @lucasmarkes/hairline");
if (source?.path !== "components/ui/hairline.tsx") problems.push("the file must be components/ui/hairline.tsx");
if (!source?.content?.startsWith('"use client";')) problems.push('the file must start with "use client"');
-for (const name of ["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard", "Elevator", "Phone", "Laptop", "Terminal", "Cabinet", "Branches", "Vault", "Lockers", "Padlock", "Patch", "Dish", "Router"]) {
+for (const name of ["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard", "Elevator", "Phone", "Laptop", "Terminal", "Cabinet", "Branches", "Vault", "Lockers", "Padlock", "Patch", "Dish", "Router", "Hub", "Relay", "Settle", "Format", "Rebuild", "Stack"]) {
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.mjs
index 96e524b..a1d0fd7 100644
--- a/scripts/consumers.mjs
+++ b/scripts/consumers.mjs
@@ -22,7 +22,7 @@ const { chromium } = createRequire(join(PKG, "package.json"))("@playwright/test"
const FIXTURES = {
next: { dir: "fixtures/next-app", port: 4311, serve: (port) => ["npx", ["next", "start", "-p", String(port)]], figures: ["riffle", "slow", "phosphor"] },
- vite: { dir: "fixtures/vite-vanilla", port: 4312, serve: (port) => ["npx", ["vite", "preview", "--port", String(port), "--strictPort"]], figures: ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches", "vault", "lockers", "padlock", "patch", "dish", "router", "loupe", "sieve", "rail", "plug", "query", "drawer", "basket", "plot"] },
+ vite: { dir: "fixtures/vite-vanilla", port: 4312, serve: (port) => ["npx", ["vite", "preview", "--port", String(port), "--strictPort"]], figures: ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop", "terminal", "cabinet", "branches", "vault", "lockers", "padlock", "patch", "dish", "router", "loupe", "sieve", "rail", "plug", "query", "drawer", "basket", "plot", "hub", "relay", "settle", "format", "rebuild", "stack"] },
};
const only = process.argv[2];
if (only && !FIXTURES[only]) { console.error(`Unknown fixture "${only}". Use: ${Object.keys(FIXTURES).join(" | ")}`); process.exit(2); }