Skip to content

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

Devices: a phone whose layers part as the pointer crosses it, and a laptop whose lid follows the pointer's height

Lucas Marques537bdc453948
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 712b54e..ffcafd6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,12 @@ Every release of `@lucasmarkes/hairline`. The format follows
- `elevator` and `Elevator`: four floors beside an open shaft. The pointer's
height picks a floor, and the car travels there through the ones between.
A stronger `intensity` makes the car travel faster.
+- `phone` and `Phone`: a phone in four layers. Moving across opens the gap
+ between them, and moving down picks a layer. A stronger `intensity` opens
+ the layers further.
+- `laptop` and `Laptop`: a thin laptop. The pointer's height sets how far the
+ lid stands open, and the lid follows it on a spring. A stronger `intensity`
+ lets the lid open wider.
## 0.1.0 - 2026-10-01
diff --git a/README.md b/README.md
index f76923d..6c16c50 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# hairline
-Eight isometric line figures that answer the pointer. For React and for anything with a DOM.
+Ten 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)
@@ -63,6 +63,8 @@ A figure draws into the element you give it, at the element's width and a 5:4 as
| `turntable` | `Turntable` | Blocks on a turntable. A flick spins it; it settles on the nearest quarter turn. | The spin coasts longer. |
| `keyboard` | `Keyboard` | A sixty-key board. The key under the pointer sinks, and its neighbours follow it down. | A wider patch of keys sinks. |
| `elevator` | `Elevator` | Four floors beside an open shaft. The pointer's height picks a floor; the car travels there. | The car travels faster between floors. |
+| `phone` | `Phone` | A phone in layers: glass, board, battery, shell. Moving across opens the gap; moving down picks a layer. | The layers open further. |
+| `laptop` | `Laptop` | A thin laptop, open on its hinge. The pointer's height sets the lid; it follows on a spring. | The lid opens wider. |
## Options
@@ -106,7 +108,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 eight above, as one HTML file.
+`hairline-create` is a skill for coding agents. Give it an idea and it draws a new figure to Hairline's ten rules, on the same engine as the ten above, as one HTML file.
```sh
npx skills add lucasmarkes/hairline
diff --git a/apps/site/app/docs/sections.tsx b/apps/site/app/docs/sections.tsx
index da8659d..3a2e060 100644
--- a/apps/site/app/docs/sections.tsx
+++ b/apps/site/app/docs/sections.tsx
@@ -1,5 +1,5 @@
import type { ReactNode } from "react";
-import { Elevator, Exploded, Keyboard, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";
+import { Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";
import { Anchor } from "@/components/anchor";
import { CodeBlock } from "@/components/code-block";
import { Install } from "@/components/install";
@@ -8,7 +8,7 @@ import { SECTIONS } from "@/lib/docs";
import { COUNT, FIGURES, INTENSITY, OPTIONS, THEME, measure } from "@/lib/figures";
import { PACKAGE } from "@/lib/snippets";
-const SMALL = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard, elevator: Elevator };
+const SMALL = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard, elevator: Elevator, phone: Phone, laptop: Laptop };
/** 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 bd57d6b..0aedf82 100644
--- a/apps/site/components/catalogue.tsx
+++ b/apps/site/components/catalogue.tsx
@@ -1,12 +1,12 @@
"use client";
import { useCallback, useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ReactNode } from "react";
-import { Elevator, Exploded, Keyboard, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";
+import { Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";
import { ENTRIES, SHELVES, type Entry, type Shelf, type ShelfId } from "@/lib/catalogue";
import { LINKS, type FigureId } from "@/lib/figures";
import { Tabs, type Tab } from "./tabs";
-const COMPONENTS: Record<FigureId, typeof Riffle> = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard, elevator: Elevator };
+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 };
type Filter = "all" | ShelfId;
diff --git a/apps/site/components/reel.tsx b/apps/site/components/reel.tsx
index 9d78303..205d883 100644
--- a/apps/site/components/reel.tsx
+++ b/apps/site/components/reel.tsx
@@ -1,10 +1,10 @@
"use client";
import { useEffect, useRef, useState, type CSSProperties } from "react";
-import { Elevator, Exploded, Keyboard, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";
+import { Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";
import { FIGURES } from "@/lib/figures";
-const COMPONENTS = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard, elevator: Elevator };
+const COMPONENTS = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard, elevator: Elevator, phone: Phone, laptop: Laptop };
/**
* One pass of a pointer over each figure, in its viewBox (400 × 320): [x, y, ms]. Each path does the
@@ -19,6 +19,8 @@ const DEMO: Record<keyof typeof COMPONENTS, [number, number, number][]> = {
turntable: [[100, 170, 0], [125, 168, 400], [310, 160, 620], [320, 158, 900]],
keyboard: [[126, 116, 0], [290, 198, 2000], [172, 165, 3000]],
elevator: [[200, 250, 0], [200, 60, 1400], [200, 175, 3400]],
+ phone: [[110, 170, 0], [290, 170, 1200], [290, 90, 1900], [290, 250, 2900]],
+ laptop: [[200, 270, 0], [200, 70, 1500], [200, 180, 3300]],
};
/** Long enough for the slowest dissolve (the reel's own, 520ms) to finish before its leaver goes. */
diff --git a/apps/site/lib/catalogue.ts b/apps/site/lib/catalogue.ts
index 1f7b0c0..e1587d6 100644
--- a/apps/site/lib/catalogue.ts
+++ b/apps/site/lib/catalogue.ts
@@ -45,8 +45,8 @@ export const SHELVES: Shelf[] = [
{
id: "devices", title: "Devices", color: "#10b981", figures: [
drawn("keyboard"),
- planned("phone", "Phone", "A phone in layers: glass, board, battery, shell. Moving across opens the gap; moving down picks a layer.", "The layers open further."),
- planned("laptop", "Laptop", "A thin laptop, open on its hinge. The pointer's height sets the lid; it follows on a spring.", "The lid opens wider."),
+ drawn("phone"),
+ drawn("laptop"),
],
},
{
diff --git a/apps/site/lib/figures.ts b/apps/site/lib/figures.ts
index 4dff012..ff6852c 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";
+export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop";
export type FigureDoc = {
id: FigureId;
@@ -78,9 +78,23 @@ export const FIGURES: FigureDoc[] = [
stronger: "The car travels faster between floors.",
parameter: { name: "stiffness", unit: "spring units" },
},
+ {
+ id: "phone",
+ name: "Phone",
+ summary: "A phone in layers: glass, board, battery, shell. Moving across opens the gap; moving down picks a layer.",
+ stronger: "The layers open further.",
+ parameter: { name: "gap", unit: "viewBox units" },
+ },
+ {
+ id: "laptop",
+ name: "Laptop",
+ summary: "A thin laptop, open on its hinge. The pointer's height sets the lid; it follows on a spring.",
+ stronger: "The lid opens wider.",
+ parameter: { name: "lid", unit: "degrees" },
+ },
];
-/** How many figures the package has, as the prose writes it: "eight". */
+/** How many figures the package has, as the prose writes it: "ten". */
export const COUNT = spell(FIGURES.length);
/** Each figure's number at intensity 0, 0.5 and 1: a copy of the package's table. */
@@ -93,6 +107,8 @@ export const INTENSITY: Record<FigureId, readonly [number, number, number]> = {
turntable: [200, 650, 1500],
keyboard: [1, 2, 3.5],
elevator: [40, 100, 220],
+ phone: [16, 28, 40],
+ laptop: [100, 125, 150],
};
/** A number with its unit, as the docs' table and /llms.txt write it: "40 ms", "0.2× normal speed". */
diff --git a/apps/site/test/figures.spec.ts b/apps/site/test/figures.spec.ts
index 4ae27c9..e098f93 100644
--- a/apps/site/test/figures.spec.ts
+++ b/apps/site/test/figures.spec.ts
@@ -16,21 +16,21 @@ function watch(page: Page): string[] {
const tiles = (page: Page) => page.locator(".fig-tile");
const shelf = (page: Page, name: string) => page.locator(".shelves .shelf", { hasText: name });
-test("/figures prerenders eight empty boxes among nineteen tiles, then draws them with a clean console", async ({ page, request }) => {
+test("/figures prerenders ten empty boxes among nineteen tiles, then draws them with a clean console", async ({ page, request }) => {
const html = await (await request.get("/figures")).text();
- expect(html.match(/<div style="aspect-ratio:5 \/ 4"><\/div>/g)).toHaveLength(8);
+ expect(html.match(/<div style="aspect-ratio:5 \/ 4"><\/div>/g)).toHaveLength(10);
expect(html.match(/class="fig-tile"/g)).toHaveLength(19);
- expect(html.match(/class="fig-tile" data-planned=""/g)).toHaveLength(11);
+ expect(html.match(/class="fig-tile" data-planned=""/g)).toHaveLength(9);
const noise = watch(page);
await page.goto("/figures");
await expect(tiles(page)).toHaveCount(19);
- await expect(page.locator(".fig-tile [data-hairline] > svg")).toHaveCount(8);
- await expect(page.locator(".fig-tile .fig-ghost")).toHaveCount(11);
+ await expect(page.locator(".fig-tile [data-hairline] > svg")).toHaveCount(10);
+ await expect(page.locator(".fig-tile .fig-ghost")).toHaveCount(9);
await expect(page.locator("h1")).toHaveText("Every figure, by what it draws.");
await expect(page.locator(".doc-section h2")).toHaveText(SHELVES);
await expect(page.locator(".fig-name").first()).toHaveAccessibleName("Exploded");
- await expect(page.locator(".fig-tile[data-planned] .fig-name").first()).toHaveAccessibleName("Phone, planned");
+ await expect(page.locator(".fig-tile[data-planned] .fig-name").first()).toHaveAccessibleName("Terminal, planned");
expect(noise).toEqual([]);
});
diff --git a/apps/site/test/site.spec.ts b/apps/site/test/site.spec.ts
index da51f4d..79bb2b7 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"];
+const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop"];
const MANAGERS = [
["npm", "npm i @lucasmarkes/hairline"],
["pnpm", "pnpm add @lucasmarkes/hairline"],
@@ -286,9 +286,9 @@ const BASE = "http://localhost:3000";
test("a pasted link shows the page it leads to: each page's card has its own title, text and address", async ({ request }) => {
const CARDS = [
- ["/", "hairline", /^Eight isometric line figures/],
+ ["/", "hairline", /^Ten isometric line figures/],
["/figures", "Figures", /^Seven shelves, nineteen figures, grouped by what they draw/],
- ["/docs", "Docs", /^Eight isometric line figures/],
+ ["/docs", "Docs", /^Ten 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 7e71146..c22dc23 100644
--- a/fixtures/vite-vanilla/index.html
+++ b/fixtures/vite-vanilla/index.html
@@ -19,6 +19,8 @@
<div id="turntable"></div>
<div id="keyboard"></div>
<div id="elevator"></div>
+ <div id="phone"></div>
+ <div id="laptop"></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 43c6f80..88a1869 100644
--- a/fixtures/vite-vanilla/src/main.ts
+++ b/fixtures/vite-vanilla/src/main.ts
@@ -1,6 +1,6 @@
-import { elevator, exploded, keyboard, phosphor, riffle, slow, terrain, turntable, type Figure } from "@lucasmarkes/hairline";
+import { elevator, exploded, keyboard, laptop, phone, phosphor, riffle, slow, terrain, turntable, type Figure } from "@lucasmarkes/hairline";
-/** No framework: eight elements, eight calls. */
+/** No framework: ten elements, ten calls. */
const el = (id: string) => document.getElementById(id)!;
const read = el("read");
@@ -15,5 +15,7 @@ slow(el("slow"));
turntable(el("turntable"));
keyboard(el("keyboard"));
elevator(el("elevator"));
+phone(el("phone"));
+laptop(el("laptop"));
cards.update({ intensity: 0.8 });
diff --git a/package.json b/package.json
index 5d2a7e5..87cf182 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "hairline-monorepo",
"version": "0.0.0",
"private": true,
- "description": "Eight isometric line figures that answer the pointer",
+ "description": "Ten 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 ea5fc33..cec3069 100644
--- a/packages/hairline/package.json
+++ b/packages/hairline/package.json
@@ -1,7 +1,7 @@
{
"name": "@lucasmarkes/hairline",
"version": "0.2.0",
- "description": "Eight isometric line figures that answer the pointer. For React and for anything with a DOM.",
+ "description": "Ten 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": "14 kB"
+ "limit": "16.6 kB"
},
{
"name": "vanilla, one figure",
@@ -94,7 +94,7 @@
{
"name": "react, every component",
"path": "dist/react.js",
- "limit": "14.4 kB",
+ "limit": "16.9 kB",
"ignore": [
"react",
"react/jsx-runtime"
diff --git a/packages/hairline/src/figures/laptop.ts b/packages/hairline/src/figures/laptop.ts
new file mode 100644
index 0000000..ba0d4ea
--- /dev/null
+++ b/packages/hairline/src/figures/laptop.ts
@@ -0,0 +1,129 @@
+import { Cam, clamp, facing, fit, hull, lerp, open, poly, prism, proj, rad, rings, rrect, run, seg, type Ring, type Sample, type Vec2, type Vec3 } from "../core/iso";
+import { spring, stepS } from "../core/motion";
+import { disposer, mk, place, pointer, put, register, solid, type FigureMount } from "../core/stage";
+
+/**
+ * Laptop: a thin aluminium base with a keyboard well and a wide trackpad, and
+ * a thin lid on a full-width hinge. On the lid's face a bezel holds the screen,
+ * with a menu bar, a dock and one app window. The pointer's height sets how
+ * far the lid stands open, from nearly shut to wide open, and the lid follows
+ * it on a spring. At rest it stands open a little past upright, lit. The
+ * slider is how far the lid is allowed to open, in degrees.
+ *
+ * The paint order is fixed and honest at every angle: the lid turns about an
+ * axis through the middle of its thickness, so no part of it ever dips under
+ * the base's top, and base then lid is back to front from nearly shut to
+ * wide open. The screen's marks sit in front of the lid's plate while its face
+ * looks at the viewer and behind it once the face turns away; they swap at the
+ * angle where the face is edge-on and the marks are squeezed to a line.
+ */
+
+const W = 150, D = 106, HB = 4, T = 2.4, HZ = HB + T / 2, R = 7, B = 1.1;
+const MIN = 15, REST = 100, BZ = 4.2, CHIN = 7.5, KU = 8.6, KY = 6;
+
+/** The lid at th degrees from shut: lid space (u across, v from the hinge, w through it) to world. */
+const lidAt = (th: number) => {
+ const c = Math.cos(rad(th)), s = Math.sin(rad(th));
+ return (u: number, v: number, w: number): Vec3 => [u, v * c - w * s, HZ + v * s + w * c];
+};
+
+/** The keys, as [x0, y0, x1, y1] on the base: a half-height function row, four rows, and a row with an inverted-T of arrows. */
+function keys() {
+ const out: Array<[number, number, number, number]> = [], x0 = (W - 14.5 * KU) / 2;
+ const row = (y: number, h: number, widths: number[]) => { let x = x0; for (const w of widths) { out.push([x, y, x + w * KU, y + h]); x += w * KU; } };
+ const ones = (n: number) => Array<number>(n).fill(1);
+ row(KY, KU * 0.6, Array<number>(14).fill(14.5 / 14));
+ let y = KY + KU * 0.6;
+ for (const w of [[...ones(13), 1.5], [1.5, ...ones(13)], [1.75, ...ones(11), 1.75], [2.25, ...ones(10), 2.25]]) { row(y, KU, w); y += KU; }
+ row(y, KU, [1, 1, 1, 1.25, 5, 1.25, 1]);
+ const ax = x0 + 11.5 * KU, h = KU / 2;
+ out.push([ax, y + h, ax + KU, y + KU], [ax + KU, y, ax + 2 * KU, y + h], [ax + KU, y + h, ax + 2 * KU, y + KU], [ax + 2 * KU, y + h, ax + 3 * KU, y + KU]);
+ return { out, y1: y + KU, x0 };
+}
+
+export const mount: FigureMount = ({ stage, svg, read }, value) => {
+ const bag = disposer();
+ let maxA = value, over: number | null = null;
+
+ // Fitted to the base and to the lid at shut, upright, rest and the default widest; the slider's far end is checked to stay inside.
+ const C = Cam(45, 0.5, 1.3), pts: Vec3[] = [[0, 0, 0], [W, 0, 0], [0, D, 0], [W, D, 0]];
+ for (const th of [MIN, 90, REST, 125]) for (const u of [0, W]) for (const v of [0, D]) for (const w of [-T / 2, T / 2]) pts.push(lidAt(th)(u, v, w));
+ fit(C, pts, 200, 166);
+ const P = proj(C), front = facing(C);
+
+ // The direction toward the viewer, read off the projection: the world direction P cannot see.
+ const o = P(0, 0, 0), ex = P(1, 0, 0), ey = P(0, 1, 0), ez = P(0, 0, 1);
+ const r1 = [ex[0] - o[0], ey[0] - o[0], ez[0] - o[0]], r2 = [ex[1] - o[1], ey[1] - o[1], ez[1] - o[1]];
+ let eye = [r1[1] * r2[2] - r1[2] * r2[1], r1[2] * r2[0] - r1[0] * r2[2], r1[0] * r2[1] - r1[1] * r2[0]];
+ if (eye[2] < 0) eye = eye.map((n) => -n);
+ const dot = (a: number[], b: number[]) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
+
+ const g = mk("g", {}, svg);
+
+ // The base: a thin slab, then what lies on its top. It never moves.
+ const [br, bi] = rings(0, 0, W, D, R, B);
+ put(solid(g), prism(P, front, br, bi, 0, HB));
+ const top = (q: Ring) => poly(q.map((s) => P(s.u, s.v, HB)));
+ const kb = keys();
+ mk("path", { class: "nf lo", d: kb.out.map(([a, b, c, d]) => top(rrect(a + 0.5, b + 0.5, c - 0.5, d - 0.5, 1.1, 2))).join("") }, g);
+ mk("path", { class: "nf", d: top(rrect(kb.x0 - 1.6, KY - 1.6, W - kb.x0 + 1.6, kb.y1 + 1.6, 3, 4)) }, g);
+ mk("path", { class: "nf", d: top(rrect(W / 2 - 35, D - 45, W / 2 + 35, D - 5, 3.2, 4)) }, g);
+
+ // The lid: a plate and its thickness line, and the screen's marks, which change sides of the plate with the face.
+ const lidG = mk("g", {}, g), lid = solid(lidG), scr = mk("g", {}, lidG);
+ lid.sil.classList.add("hi");
+ const [lr, li] = rings(0, 0, W, D, R, B);
+ const disp = mk("path", { class: "nf" }, scr), bar = mk("path", { class: "nf lo" }, scr), dock = mk("path", { class: "nf lo" }, scr);
+ const win = mk("path", {}, scr), strip = mk("path", { class: "nf lo" }, scr);
+ const cam = mk("circle", { r: 0.8, class: "dot off" }, scr);
+ const lights = [0, 1, 2].map(() => mk("circle", { r: 0.8, class: "dot off" }, scr));
+ const VT = D - BZ, WX0 = 30, WX1 = 104, WV0 = CHIN + 16, WV1 = VT - 12;
+ let faced: boolean | null = null, drawn = NaN;
+
+ function drawLid(th: number) {
+ if (th === drawn) return;
+ drawn = th;
+ const f = lidAt(th), c = Math.cos(rad(th)), s = Math.sin(rad(th));
+ const at = (u: number, v: number, w: number) => P(...f(u, v, w)), on = (u: number, v: number) => at(u, v, -T / 2);
+ const plane = (q: readonly Sample[], w: number) => q.map((p) => at(p.u, p.v, w));
+ const shows = dot([0, s, -c], eye) > 0, wf = shows ? -T / 2 : T / 2;
+ const wall = (q: Sample) => dot([q.nu, q.nv * c, q.nv * s], eye) > 0;
+ put(lid, { sil: poly(hull(plane(lr, -T / 2).concat(plane(lr, T / 2)))), crease: open(plane(run(li, wall), wf)) });
+ if (shows !== faced) { faced = shows; if (shows) lid.g.after(scr); else lid.g.before(scr); }
+ const face = (q: Ring) => poly(q.map((p) => on(p.u, p.v)));
+ disp.setAttribute("d", face(rrect(BZ, CHIN, W - BZ, VT, 3, 4)));
+ bar.setAttribute("d", seg(on(BZ + 1.5, VT - 4), on(W - BZ - 1.5, VT - 4)));
+ dock.setAttribute("d", face(rrect(W / 2 - 28, CHIN + 2.5, W / 2 + 28, CHIN + 8.5, 2.2, 4)));
+ win.setAttribute("d", face(rrect(WX0, WV0, WX1, WV1, 2.6, 4)));
+ strip.setAttribute("d", seg(on(WX0, WV1 - 6), on(WX1, WV1 - 6)) + seg(on(WX0 + 20, WV0), on(WX0 + 20, WV1 - 6)));
+ place(cam, on(W / 2, D - BZ / 2));
+ lights.forEach((el, k) => place(el, on(WX0 + 4 + k * 3.4, WV1 - 3)));
+ }
+
+ const sp = spring(REST, { eps: 0.05 });
+ const Bk = register(stage, (dt) => { const m = stepS(sp, dt); drawLid(sp.x); return m; });
+ bag.add(Bk.unregister);
+ drawLid(REST);
+
+ // The pointer's height, over a band from the upright lid's top to the base's front, sets the angle; the stage never moves, so nothing can flicker.
+ const yTop = P(W / 2, 0, HZ + D)[1] + 12, yBot = P(W / 2, D, 0)[1] - 12;
+ function retarget() {
+ if (over === null) { sp.t = Math.min(REST, maxA); read.textContent = "rest"; }
+ else {
+ sp.t = lerp(maxA, MIN, clamp((over - yTop) / (yBot - yTop), 0, 1));
+ read.textContent = sp.t <= MIN + 0.5 ? "shut" : sp.t >= maxA - 0.5 ? "open" : `lid ${Math.round(sp.t)}°`;
+ }
+ Bk.wake();
+ }
+
+ bag.add(pointer(stage, {
+ move: (p: Vec2) => { over = p[1]; retarget(); },
+ leave: () => { over = null; retarget(); },
+ }));
+ bag.add(() => svg.replaceChildren());
+
+ return {
+ set: (v) => { maxA = v; retarget(); },
+ destroy: bag.dispose,
+ };
+};
diff --git a/packages/hairline/src/figures/phone.ts b/packages/hairline/src/figures/phone.ts
new file mode 100644
index 0000000..2b73fc7
--- /dev/null
+++ b/packages/hairline/src/figures/phone.ts
@@ -0,0 +1,187 @@
+import {
+ Cam, circ, clamp, extremes, facing, fillet, fit, hull, lerp, poly, prism, proj, ringAt, rings, rrect, seg,
+ type Ring, type Vec2,
+} from "../core/iso";
+import { spring, stepS } from "../core/motion";
+import { disposer, mk, pointer, put, register, solid, type FigureMount } from "../core/stage";
+
+/**
+ * Phone: a phone lying face down, taken apart in four layers, from the bottom:
+ * the glass with its notch, an L-shaped board with its chips, the battery with
+ * the connector tab that runs to the board, and the back shell with its camera
+ * bump and side buttons. The pointer's x scrubs the gaps (a spring per gap);
+ * its y picks a layer, which takes the bright edge and goes to the read-out.
+ * The gaps open in turn outwards from the layer picked: the two beside it
+ * chase the target, and each further gap chases its inner neighbour. At rest
+ * the board is caught lifting off the glass, bright. The slider is the
+ * largest gap, in world units.
+ *
+ * The pattern: scrub and pick, as Exploded. Picking is tested against the
+ * target gaps, never the gaps on screen, and the stack is centred on its own
+ * middle so it opens both ways and stays in the frame.
+ */
+
+const W = 68, L = 140, R = 11, GMAX = 40;
+/** Thicknesses: glass, board, the tallest chip, battery, shell, the camera bump and a lens. */
+const TG = 2, TB = 1.6, TC = 1.8, TBAT = 7, TS = 6, TBUMP = 2.2, TL = 0.9;
+const STACK = TG + TB + TC + TBAT + TS + TBUMP + TL;
+const NAMES = ["glass", "board", "battery", "shell"];
+/** The gaps at rest, as shares of the largest: the board caught lifting off the glass. */
+const REST = [0.36, 0.3, 1.2], MIN = 0.08, PIVOT = 1;
+const BOARD: Vec2[] = [[4, L - 44], [W - 4, L - 44], [W - 4, L - 5], [36, L - 5], [36, L - 30], [4, L - 30]];
+const BAT: [number, number, number, number] = [9, 12, W - 9, L - 48];
+/** Chips on the board, [x0, y0, x1, y1, height], back to front: a modem, a socket, a regulator, the processor. */
+const CHIPS: Array<[number, number, number, number, number]> = [
+ [10, L - 41, 26, L - 34, 1.4], [45, L - 40, 54, L - 35, 1.2], [57, L - 42, 62, L - 36, 1.2], [42, L - 27, 56, L - 13, 1.8],
+];
+const RECT: Vec2[] = [[0, 0], [W, 0], [W, L], [0, L]];
+const FOOT: Vec2[][] = [RECT, BOARD, [[BAT[0], BAT[1]], [BAT[2], BAT[1]], [BAT[2], BAT[3]], [BAT[0], BAT[3]]], RECT];
+const THICK = [TG, TB, TBAT, TS];
+
+/** Each layer's base height, from the three gaps, centred so the stack opens both ways about its middle. */
+function bases(g: readonly number[]): number[] {
+ const b = [0], t = [TG, TB + TC, TBAT];
+ for (let j = 0; j < 3; j++) b.push(b[j] + t[j] + g[j]);
+ const mid = (b[3] + TS + TBUMP + TL) / 2;
+ return b.map((z) => z - mid);
+}
+
+/** Even-odd point-in-polygon, on screen. */
+function inside(pt: Vec2, pg: readonly Vec2[]) {
+ let c = false;
+ for (let i = 0, j = pg.length - 1; i < pg.length; j = i++) {
+ const [xi, yi] = pg[i], [xj, yj] = pg[j];
+ if ((yi > pt[1]) !== (yj > pt[1]) && pt[0] < ((xj - xi) * (pt[1] - yi)) / (yj - yi) + xi) c = !c;
+ }
+ return c;
+}
+
+/** A ring moved by (cx, cy) on the ground. */
+const at = (ring: Ring, cx: number, cy: number): Ring => ring.map((q) => ({ ...q, u: q.u + cx, v: q.v + cy }));
+
+export const mount: FigureMount = ({ stage, svg, read }, value) => {
+ const bag = disposer();
+ let GAP = value, share: number | null = null, act = -1, origin = PIVOT, lastP: Vec2 | null = null;
+
+ const C = Cam(45, 0.5, 1.5), H = (STACK + 3 * GMAX) / 2;
+ fit(C, [[0, 0, -H], [W + 2.2, L, -H], [W + 2.2, 0, -H], [0, L, -H], [0, 0, H], [W + 2.2, 0, H], [0, L, H]], 200, 166);
+ const P = proj(C), front = facing(C);
+ const flat = (pts: readonly Vec2[], z: number) => poly(pts.map(([x, y]) => P(x, y, z)));
+ const g = mk("g", {}, svg);
+
+ // the guides, from the shell's outermost points down to the glass: painted first, so every plate hides them
+ const outer = rrect(0, 0, W, L, R, 8);
+ const ext = extremes(P, outer).slice(0, 2), guide = mk("path", { class: "nf dash" }, g);
+
+ // glass: a rounded slab, its display edge cut by the notch, a camera and a speaker slit in the notch
+ const gg = mk("g", {}, g), glass = solid(gg), gIn = rrect(1.2, 1.2, W - 1.2, L - 1.2, R - 1.2, 8);
+ const DISP = fillet([[4, 4], [W - 4, 4], [W - 4, L - 4], [W / 2 + 12, L - 4], [W / 2 + 12, L - 10], [W / 2 - 12, L - 10], [W / 2 - 12, L - 4], [4, L - 4]], [7.5, 7.5, 7.5, 2, 3.5, 3.5, 2, 7.5]);
+ const disp = mk("path", { class: "nf" }, gg), lensF = mk("path", { class: "nf" }, gg), slit = mk("path", { class: "nf lo" }, gg);
+ const camF = at(circ(1.5, 16), W / 2 + 6, L - 7);
+
+ // board: an L-shaped plate, its edge as a second outline, and its chips
+ const bg = mk("g", {}, g), BF = fillet(BOARD, [4, 4, 4, 4, 3, 4]);
+ const bBack = mk("path", { class: "lo" }, bg), bFace = mk("path", { class: "sil" }, bg);
+ const chips = CHIPS.map(([x0, y0, x1, y1, h]) => { const [ring, inner] = rings(x0, y0, x1, y1, 1.5, 0.7); return { ring, inner, h, el: solid(bg) }; });
+
+ // battery: a rounded block, and the flex tab that leaves its near end with the connector on it
+ const tg = mk("g", {}, g), battery = solid(tg), [batR, batI] = rings(...BAT, 6, 1.6);
+ const TAB = fillet([[41, L - 48], [52, L - 48], [52, L - 31], [41, L - 31]], [0.5, 0.5, 2, 2]);
+ const tBack = mk("path", { class: "lo" }, tg), tFace = mk("path", {}, tg), conn = solid(tg);
+ const [conR, conI] = rings(42, L - 38, 51, L - 32, 1.5, 0.7);
+
+ // shell: the back, two volume buttons standing off its near side, the camera bump and its lenses
+ const sg = mk("g", {}, g), shell = solid(sg), sIn = rrect(1.8, 1.8, W - 1.8, L - 1.8, R - 1.8, 8);
+ const buttons = [[L - 68, L - 58], [L - 54, L - 44]].map(([y0, y1]) => { const [ring, inner] = rings(W - 0.5, y0, W + 2.2, y1, 1.2, 0.5); return { ring, inner, el: solid(sg) }; });
+ const bump = solid(sg), bumpR = rrect(7, L - 33, 33, L - 7, 7, 6), bumpI = rrect(8, L - 32, 32, L - 8, 6, 6);
+ const lenses = [[14.5, L - 25.5], [25.5, L - 14.5]].map(([x, y]) => {
+ const el = solid(sg);
+ return { ring: at(circ(4.6, 24), x, y), inner: at(circ(3.6, 24), x, y), eye: at(circ(1.9, 16), x, y), el, glass: mk("path", { class: "nf lo" }, el.g) };
+ });
+ const flash = mk("path", { class: "nf" }, sg), FL = at(circ(1.7, 16), 25.5, L - 25.5);
+
+ const draw: Array<(z: number) => void> = [
+ (z) => {
+ put(glass, prism(P, front, outer, gIn, z, z + TG));
+ const t = z + TG;
+ disp.setAttribute("d", flat(DISP, t));
+ lensF.setAttribute("d", poly(ringAt(P, camF, t)));
+ slit.setAttribute("d", seg(P(W / 2 - 6, L - 7, t), P(W / 2 + 1.5, L - 7, t)));
+ },
+ (z) => {
+ bBack.setAttribute("d", flat(BF, z));
+ bFace.setAttribute("d", flat(BF, z + TB));
+ for (const c of chips) put(c.el, prism(P, front, c.ring, c.inner, z + TB, z + TB + c.h));
+ },
+ (z) => {
+ put(battery, prism(P, front, batR, batI, z, z + TBAT));
+ tBack.setAttribute("d", flat(TAB, z + 0.8));
+ tFace.setAttribute("d", flat(TAB, z + 1.4));
+ put(conn, prism(P, front, conR, conI, z + 1.4, z + 2.6));
+ },
+ (z) => {
+ put(shell, prism(P, front, outer, sIn, z, z + TS));
+ for (const b of buttons) put(b.el, prism(P, front, b.ring, b.inner, z + 1.6, z + 4.4));
+ const t = z + TS, u = t + TBUMP;
+ put(bump, prism(P, front, bumpR, bumpI, t, u));
+ for (const l of lenses) { put(l.el, prism(P, front, l.ring, l.inner, u, u + TL)); l.glass.setAttribute("d", poly(ringAt(P, l.eye, u + TL))); }
+ flash.setAttribute("d", poly(ringAt(P, FL, u)));
+ },
+ ];
+ const sils = [glass.sil, bFace, battery.sil, shell.sil];
+
+ /** The gaps the pointer asks for: one share of the largest across, or the rest pose. */
+ const targets = () => [0, 1, 2].map((j) => GAP * (share === null ? REST[j] : share));
+ const gs = targets().map((t) => spring(t, { eps: 0.01 }));
+ const drawn = [NaN, NaN, NaN, NaN];
+
+ const B = register(stage, (dt) => {
+ // the gaps beside the origin chase the target; each further gap chases its inner neighbour's lag
+ const T = targets(), order = [0, 1, 2].sort((a, b) => Math.abs(a + 0.5 - origin) - Math.abs(b + 0.5 - origin));
+ let m = false;
+ for (const j of order) {
+ const d = j + 0.5 - origin, k = d > 0 ? j - 1 : j + 1;
+ gs[j].t = Math.abs(d) < 1 ? T[j] : T[j] + gs[k].x - T[k];
+ if (stepS(gs[j], dt)) m = true;
+ }
+ const b = bases(gs.map((s) => s.x));
+ let changed = false;
+ b.forEach((z, i) => { if (z !== drawn[i]) { drawn[i] = z; draw[i](z); changed = true; } });
+ if (changed) guide.setAttribute("d", ext.map((q) => seg(P(q.u, q.v, b[3]), P(q.u, q.v, b[0] + TG))).join(""));
+ return m;
+ });
+ bag.add(B.unregister);
+
+ /** The layer under a screen point, tested where the layers are going (the target gaps), topmost first; else the nearest in height. */
+ function pick(p: Vec2) {
+ const b = bases(targets());
+ for (let i = 3; i >= 0; i--) {
+ const f = FOOT[i], top = f.map(([x, y]) => P(x, y, b[i] + THICK[i]));
+ const shape = i === 1 ? top : hull(top.concat(f.map(([x, y]) => P(x, y, b[i]))));
+ if (inside(p, shape)) return i;
+ }
+ let best = 0, bd = Infinity;
+ b.forEach((z, i) => { const dy = Math.abs(P(W / 2, L / 2, z + THICK[i])[1] - p[1]); if (dy < bd) { bd = dy; best = i; } });
+ return best;
+ }
+ function setAct(a: number) {
+ if (a >= 0) origin = a;
+ act = a;
+ const lit = a >= 0 ? a : PIVOT;
+ sils.forEach((s, i) => s.classList.toggle("hi", i === lit));
+ read.textContent = a >= 0 ? NAMES[a] : "rest";
+ B.wake();
+ }
+ setAct(-1);
+
+ bag.add(pointer(stage, {
+ move: (p) => { lastP = p; share = lerp(MIN, 1, clamp((p[0] - 60) / 280, 0, 1)); setAct(pick(p)); },
+ leave: () => { lastP = null; share = null; setAct(-1); },
+ }));
+ bag.add(() => svg.replaceChildren());
+
+ return {
+ set: (v) => { GAP = v; if (lastP) setAct(pick(lastP)); B.wake(); },
+ destroy: bag.dispose,
+ };
+};
diff --git a/packages/hairline/src/index.ts b/packages/hairline/src/index.ts
index ac983c3..4da0df8 100644
--- a/packages/hairline/src/index.ts
+++ b/packages/hairline/src/index.ts
@@ -2,6 +2,8 @@ import { create, type Figure, type HairlineOptions } from "./mount";
import { mount as elevatorEngine } from "./figures/elevator";
import { mount as explodedEngine } from "./figures/exploded";
import { mount as keyboardEngine } from "./figures/keyboard";
+import { mount as laptopEngine } from "./figures/laptop";
+import { mount as phoneEngine } from "./figures/phone";
import { mount as phosphorEngine } from "./figures/phosphor";
import { mount as riffleEngine } from "./figures/riffle";
import { mount as slowEngine } from "./figures/slow";
@@ -9,7 +11,7 @@ import { mount as terrainEngine } from "./figures/terrain";
import { mount as turntableEngine } from "./figures/turntable";
/**
- * @lucasmarkes/hairline — eight isometric line figures that answer the pointer.
+ * @lucasmarkes/hairline — ten 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
@@ -98,3 +100,23 @@ export function elevator(el: HTMLElement, options?: HairlineOptions): Figure {
engine: elevatorEngine,
}, el, options);
}
+
+/** A phone in layers: glass, board, battery, shell. Moving across opens the gap; moving down picks a layer. `intensity` opens the layers further. */
+export function phone(el: HTMLElement, options?: HairlineOptions): Figure {
+ return create({
+ id: "phone",
+ label: "A phone in layers: glass, board, battery, shell. Moving across opens the gap; moving down picks a layer.",
+ rest: "rest",
+ engine: phoneEngine,
+ }, el, options);
+}
+
+/** A thin laptop: the pointer's height sets how far the lid stands open, and the lid follows it on a spring. `intensity` lets the lid open wider. */
+export function laptop(el: HTMLElement, options?: HairlineOptions): Figure {
+ return create({
+ id: "laptop",
+ label: "A thin laptop: the pointer's height sets how far the lid stands open, and the lid follows it on a spring.",
+ rest: "rest",
+ engine: laptopEngine,
+ }, el, options);
+}
diff --git a/packages/hairline/src/intensity.ts b/packages/hairline/src/intensity.ts
index 66750dd..05cc88d 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";
+export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop";
/** 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]> = {
@@ -19,6 +19,8 @@ export const TABLE: Record<FigureId, readonly [number, number, number]> = {
turntable: [200, 650, 1500], // coast, ms
keyboard: [1, 2, 3.5], // radius, keys
elevator: [40, 100, 220], // stiffness, spring units
+ phone: [16, 28, 40], // gap, viewBox units
+ laptop: [100, 125, 150], // lid, degrees
};
export const DEFAULT = 0.5;
diff --git a/packages/hairline/src/react.tsx b/packages/hairline/src/react.tsx
index 457ced9..fb35931 100644
--- a/packages/hairline/src/react.tsx
+++ b/packages/hairline/src/react.tsx
@@ -2,10 +2,10 @@ import {
forwardRef, useCallback, useEffect, useLayoutEffect, useRef,
type ComponentPropsWithoutRef, type ForwardRefExoticComponent, type RefAttributes,
} from "react";
-import { elevator, exploded, keyboard, phosphor, riffle, slow, terrain, turntable, type Figure, type HairlineOptions } from "./index";
+import { elevator, exploded, keyboard, laptop, phone, phosphor, riffle, slow, terrain, turntable, type Figure, type HairlineOptions } from "./index";
/**
- * @lucasmarkes/hairline/react — the eight figures as components.
+ * @lucasmarkes/hairline/react — the ten 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.
@@ -69,3 +69,7 @@ export const Turntable = make("Turntable", turntable);
export const Keyboard = make("Keyboard", keyboard);
/** Four floors beside an open shaft. The pointer's height picks a floor, and the car travels there through the ones between. `intensity` makes the car travel faster. */
export const Elevator = make("Elevator", elevator);
+/** A phone in layers: glass, board, battery, shell. Moving across opens the gap; moving down picks a layer. `intensity` opens the layers further. */
+export const Phone = make("Phone", phone);
+/** A thin laptop: the pointer's height sets how far the lid stands open, and the lid follows it on a spring. `intensity` lets the lid open wider. */
+export const Laptop = make("Laptop", laptop);
diff --git a/packages/hairline/test/browser/entry.ts b/packages/hairline/test/browser/entry.ts
index 42389d5..6b64ff6 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";
+type Id = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop";
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 eec31ba..2a635f8 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"] as const;
+const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop"] 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 4f2ebb9..56278b2 100644
--- a/packages/hairline/test/mount.test.ts
+++ b/packages/hairline/test/mount.test.ts
@@ -1,10 +1,10 @@
// @vitest-environment jsdom
import { describe, expect, it, vi } from "vitest";
import { frames, host, observers, pending } from "./dom";
-import { elevator, exploded, keyboard, phosphor, riffle, slow, terrain, turntable } from "../src/index";
+import { elevator, exploded, keyboard, laptop, phone, phosphor, riffle, slow, terrain, turntable } from "../src/index";
import { css } from "../src/core/styles";
-const ALL = { riffle, terrain, exploded, phosphor, slow, turntable, keyboard, elevator };
+const ALL = { riffle, terrain, exploded, phosphor, slow, turntable, keyboard, elevator, phone, laptop };
const key = (el: Element, k: string) => el.dispatchEvent(new KeyboardEvent("keydown", { key: k, bubbles: true, cancelable: true }));
describe("mount", () => {
@@ -144,6 +144,8 @@ describe("intensity", () => {
turntable: [[50, 176], 1, [120, 176], 1, [200, 176], 1, [280, 176], 1, [350, 176], 40],
keyboard: [[200, 160], 20],
elevator: [[200, 60], 8],
+ phone: [[100, 80], 100],
+ laptop: [[200, 60], 60],
};
const svg = (el: Element) => el.querySelector("svg")!.innerHTML.replace(/hl-fd\d+/g, "hl-fd");
diff --git a/packages/hairline/test/react.test.tsx b/packages/hairline/test/react.test.tsx
index 258132c..0d5d4d8 100644
--- a/packages/hairline/test/react.test.tsx
+++ b/packages/hairline/test/react.test.tsx
@@ -3,7 +3,7 @@ import { StrictMode, createRef } from "react";
import { cleanup, render } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { frames, observers, pending } from "./dom";
-import { Elevator, Exploded, Keyboard, Phosphor, Riffle, Slow, Terrain, Turntable } from "../src/react";
+import { Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terrain, Turntable } from "../src/react";
afterEach(cleanup);
@@ -17,9 +17,9 @@ const svg = (el: Element) => el.querySelector("svg")!.innerHTML.replace(/hl-fd\d
describe("components", () => {
it("renders each figure into one div", () => {
- const { container } = render(<><Riffle /><Terrain /><Exploded /><Phosphor /><Slow /><Turntable /><Keyboard /><Elevator /></>);
+ const { container } = render(<><Riffle /><Terrain /><Exploded /><Phosphor /><Slow /><Turntable /><Keyboard /><Elevator /><Phone /><Laptop /></>);
const ids = [...container.children].map((el) => el.getAttribute("data-hairline"));
- expect(ids).toEqual(["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator"]);
+ expect(ids).toEqual(["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard", "elevator", "phone", "laptop"]);
for (const el of container.children) expect(el.querySelectorAll(":scope > svg")).toHaveLength(1);
});
@@ -118,7 +118,7 @@ describe("components", () => {
});
it("names the components for the dev tools", () => {
- expect([Riffle, Terrain, Exploded, Phosphor, Slow, Turntable, Keyboard, Elevator].map((c) => c.displayName))
- .toEqual(["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard", "Elevator"]);
+ expect([Riffle, Terrain, Exploded, Phosphor, Slow, Turntable, Keyboard, Elevator, Phone, Laptop].map((c) => c.displayName))
+ .toEqual(["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard", "Elevator", "Phone", "Laptop"]);
});
});
diff --git a/packages/hairline/test/types.test-d.tsx b/packages/hairline/test/types.test-d.tsx
index 62f21f7..2ac489b 100644
--- a/packages/hairline/test/types.test-d.tsx
+++ b/packages/hairline/test/types.test-d.tsx
@@ -4,10 +4,10 @@
* an error. Vitest does not pick it up (it is not a `.test.` file).
*/
import { createRef } from "react";
-import { elevator, exploded, keyboard, phosphor, riffle, slow, terrain, turntable, type Figure, type HairlineOptions } from "../src/index";
+import { elevator, exploded, keyboard, laptop, phone, phosphor, riffle, slow, terrain, turntable, type Figure, type HairlineOptions } from "../src/index";
import * as vanilla from "../src/index";
import * as components from "../src/react";
-import { Elevator, Exploded, Keyboard, Phosphor, Riffle, Slow, Terrain, Turntable, type HairlineProps } from "../src/react";
+import { Elevator, Exploded, Keyboard, Laptop, Phone, Phosphor, Riffle, Slow, Terrain, Turntable, type HairlineProps } from "../src/react";
declare const el: HTMLElement;
type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
@@ -16,7 +16,7 @@ const yes = <T extends true>() => {};
/* every figure takes the same options */
riffle(el, { intensity: 0.8, theme: "dark", label: "Cards", onRead: (t: string) => t });
riffle(el);
-for (const mount of [riffle, terrain, exploded, phosphor, slow, turntable, keyboard, elevator]) {
+for (const mount of [riffle, terrain, exploded, phosphor, slow, turntable, keyboard, elevator, phone, laptop]) {
yes<Equal<typeof mount, (el: HTMLElement, options?: HairlineOptions) => Figure>>();
// @ts-expect-error the old per-figure options are gone
mount(el, { stagger: 60 });
@@ -46,8 +46,8 @@ f.update({ stagger: 60 });
f.update({ bands: true });
/* the entries export the functions, the components and three types, and nothing of the old API */
-yes<Equal<keyof typeof vanilla, "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator">>();
-yes<Equal<keyof typeof components, "Riffle" | "Terrain" | "Exploded" | "Phosphor" | "Slow" | "Turntable" | "Keyboard" | "Elevator">>();
+yes<Equal<keyof typeof vanilla, "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard" | "elevator" | "phone" | "laptop">>();
+yes<Equal<keyof typeof components, "Riffle" | "Terrain" | "Exploded" | "Phosphor" | "Slow" | "Turntable" | "Keyboard" | "Elevator" | "Phone" | "Laptop">>();
// @ts-expect-error ranges is gone
void vanilla.ranges;
// @ts-expect-error the per-figure option types are gone
@@ -60,7 +60,7 @@ const ref = createRef<HTMLDivElement>();
<Riffle ref={ref} intensity={0.8} theme="dark" className="w-80" id="cards" onClick={() => {}} onRead={(text) => text.length} />;
<Terrain style={{ width: 320 }} aria-label="Dunes" data-x="1" />;
<Riffle />;
-for (const C of [Riffle, Terrain, Exploded, Phosphor, Slow, Turntable, Keyboard, Elevator]) {
+for (const C of [Riffle, Terrain, Exploded, Phosphor, Slow, Turntable, Keyboard, Elevator, Phone, Laptop]) {
// @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 4dd2d20..37b6aa7 100644
--- a/registry/src/hairline.tsx
+++ b/registry/src/hairline.tsx
@@ -49,3 +49,11 @@ export function Keyboard({ style, ...props }: ComponentProps<typeof Hairline.Key
export function Elevator({ style, ...props }: ComponentProps<typeof Hairline.Elevator>) {
return <Hairline.Elevator style={{ ...tokens, ...style }} {...props} />;
}
+
+export function Phone({ style, ...props }: ComponentProps<typeof Hairline.Phone>) {
+ return <Hairline.Phone style={{ ...tokens, ...style }} {...props} />;
+}
+
+export function Laptop({ style, ...props }: ComponentProps<typeof Hairline.Laptop>) {
+ return <Hairline.Laptop style={{ ...tokens, ...style }} {...props} />;
+}
diff --git a/registry/validate.mjs b/registry/validate.mjs
index 0ade8c3..9f97a24 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"]) {
+for (const name of ["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard", "Elevator", "Phone", "Laptop"]) {
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 00106d7..140fe23 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"] },
+ 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"] },
};
const only = process.argv[2];
if (only && !FIXTURES[only]) { console.error(`Unknown fixture "${only}". Use: ${Object.keys(FIXTURES).join(" | ")}`); process.exit(2); }