Isometric line figures that answer the pointer. For React and for anything with a DOM.
Tests: the packed tarball installed in a Next.js app and a Vite app, built and opened in Chrome
Lucas Marquescf7b433978a6
diff --git a/.github/workflows/consumers.yml b/.github/workflows/consumers.ymlnew file mode 100644index 0000000..2edb2d1--- /dev/null+++ b/.github/workflows/consumers.yml@@ -0,0 +1,42 @@+name: Consumers++# Layer 6: the packed tarball installed in a Next.js app and a Vite app, built+# and opened in a browser. Slow and network-bound, so it runs only when what+# ships (or what checks it) changes. The release gate runs it too.+on:+ pull_request:+ paths:+ - 'packages/**'+ - 'fixtures/**'+ - 'scripts/consumers.mjs'+ - '.github/workflows/consumers.yml'++concurrency:+ group: consumers-${{ github.ref }}+ cancel-in-progress: true++permissions:+ contents: read++jobs:+ consumers:+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v7++ - name: Enable Corepack+ run: corepack enable++ - uses: actions/setup-node@v7+ with:+ node-version: 22+ cache: pnpm++ - name: Install+ run: pnpm install --frozen-lockfile++ - name: Build+ run: pnpm build++ - name: Install, build and open the fixtures+ run: node scripts/consumers.mjsdiff --git a/fixtures/next-app/.gitignore b/fixtures/next-app/.gitignorenew file mode 100644index 0000000..33eca0a--- /dev/null+++ b/fixtures/next-app/.gitignore@@ -0,0 +1,6 @@+node_modules/+.next/+next-env.d.ts+package-lock.json+# written by scripts/consumers.mjs from the registry item+components/diff --git a/fixtures/next-app/app/layout.tsx b/fixtures/next-app/app/layout.tsxnew file mode 100644index 0000000..1ba913c--- /dev/null+++ b/fixtures/next-app/app/layout.tsx@@ -0,0 +1,11 @@+import type { ReactNode } from "react";++export const metadata = { title: "hairline fixture", icons: { icon: "data:," } };++export default function RootLayout({ children }: { children: ReactNode }) {+ return (+ <html lang="en">+ <body>{children}</body>+ </html>+ );+}diff --git a/fixtures/next-app/app/page.tsx b/fixtures/next-app/app/page.tsxnew file mode 100644index 0000000..9b1dddf--- /dev/null+++ b/fixtures/next-app/app/page.tsx@@ -0,0 +1,17 @@+import { Riffle, Slow } from "@lucasmarkes/hairline/react";+import { Vanilla } from "./vanilla";++/**+ * A Server Component: no "use client" here. The components come from the+ * React entry, which marks itself as a client module; the third figure comes+ * from the vanilla entry, so the page loads both entries at once.+ */+export default function Page() {+ return (+ <main style={{ display: "grid", gap: 24, width: 400, margin: "40px auto" }}>+ <Riffle id="riffle" labels={["Radial menu", "Drum"]} />+ <Slow id="slow" rate={0.4} theme="dark" />+ <Vanilla />+ </main>+ );+}diff --git a/fixtures/next-app/app/registry/page.tsx b/fixtures/next-app/app/registry/page.tsxnew file mode 100644index 0000000..85c7a41--- /dev/null+++ b/fixtures/next-app/app/registry/page.tsx@@ -0,0 +1,18 @@+import type { CSSProperties } from "react";+import { Terrain } from "@/components/ui/hairline";++/** shadcn's tokens, as a dark theme would define them. */+const tokens = { "--background": "#101014", "--foreground": "#fafafa", "--muted-foreground": "#a1a1aa", "--border": "#27272a" } as CSSProperties;++/**+ * The shadcn registry item, as `shadcn add` would leave it:+ * scripts/consumers.mjs writes components/ui/hairline.tsx from the built item+ * before it builds this app.+ */+export default function Page() {+ return (+ <main style={{ width: 400, margin: "40px auto", background: "var(--background)", ...tokens }}>+ <Terrain id="themed" />+ </main>+ );+}diff --git a/fixtures/next-app/app/vanilla.tsx b/fixtures/next-app/app/vanilla.tsxnew file mode 100644index 0000000..52984a5--- /dev/null+++ b/fixtures/next-app/app/vanilla.tsx@@ -0,0 +1,13 @@+"use client";++import { useEffect, useRef } from "react";+import { phosphor } from "@lucasmarkes/hairline";++export function Vanilla() {+ const ref = useRef<HTMLDivElement>(null);+ useEffect(() => {+ const figure = phosphor(ref.current!, { afterglow: 900 });+ return () => figure.destroy();+ }, []);+ return <div id="phosphor" ref={ref} />;+}diff --git a/fixtures/next-app/next.config.mjs b/fixtures/next-app/next.config.mjsnew file mode 100644index 0000000..8e6bf4d--- /dev/null+++ b/fixtures/next-app/next.config.mjs@@ -0,0 +1,2 @@+/** A consumer's project, as plain as one gets: no transpilePackages, no aliases. */+export default {};diff --git a/fixtures/next-app/package.json b/fixtures/next-app/package.jsonnew file mode 100644index 0000000..047ec2e--- /dev/null+++ b/fixtures/next-app/package.json@@ -0,0 +1,19 @@+{+ "name": "hairline-fixture-next",+ "private": true,+ "scripts": {+ "build": "next build",+ "start": "next start"+ },+ "dependencies": {+ "next": "16.3.8",+ "react": "19.3.0",+ "react-dom": "19.3.0"+ },+ "devDependencies": {+ "@types/node": "^22",+ "@types/react": "^19",+ "@types/react-dom": "^19",+ "typescript": "5.9.3"+ }+}diff --git a/fixtures/next-app/tsconfig.json b/fixtures/next-app/tsconfig.jsonnew file mode 100644index 0000000..db60d66--- /dev/null+++ b/fixtures/next-app/tsconfig.json@@ -0,0 +1,21 @@+{+ "compilerOptions": {+ "target": "ES2020",+ "lib": ["dom", "dom.iterable", "esnext"],+ "strict": true,+ "noEmit": true,+ "esModuleInterop": true,+ "module": "esnext",+ "moduleResolution": "bundler",+ "resolveJsonModule": true,+ "isolatedModules": true,+ "jsx": "react-jsx",+ "incremental": true,+ "skipLibCheck": true,+ "allowJs": true,+ "plugins": [{ "name": "next" }],+ "paths": { "@/*": ["./*"] }+ },+ "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", ".next/dev/types/**/*.ts"],+ "exclude": ["node_modules"]+}diff --git a/fixtures/vite-vanilla/.gitignore b/fixtures/vite-vanilla/.gitignorenew file mode 100644index 0000000..320c107--- /dev/null+++ b/fixtures/vite-vanilla/.gitignore@@ -0,0 +1,3 @@+node_modules/+dist/+package-lock.jsondiff --git a/fixtures/vite-vanilla/index.html b/fixtures/vite-vanilla/index.htmlnew file mode 100644index 0000000..3d05232--- /dev/null+++ b/fixtures/vite-vanilla/index.html@@ -0,0 +1,24 @@+<!doctype html>+<html lang="en">+<head>+<meta charset="utf-8">+<meta name="viewport" content="width=device-width, initial-scale=1">+<title>hairline fixture</title>+<link rel="icon" href="data:,">+<style>+ main { display: grid; grid-template-columns: repeat(3, 300px); gap: 24px; margin: 40px; }+</style>+</head>+<body>+ <main>+ <div id="riffle"></div>+ <div id="terrain"></div>+ <div id="exploded"></div>+ <div id="phosphor"></div>+ <div id="slow"></div>+ <div id="turntable"></div>+ </main>+ <output id="read"></output>+ <script type="module" src="/src/main.ts"></script>+</body>+</html>diff --git a/fixtures/vite-vanilla/package.json b/fixtures/vite-vanilla/package.jsonnew file mode 100644index 0000000..c84c33f--- /dev/null+++ b/fixtures/vite-vanilla/package.json@@ -0,0 +1,13 @@+{+ "name": "hairline-fixture-vite",+ "private": true,+ "type": "module",+ "scripts": {+ "build": "tsc --noEmit && vite build",+ "preview": "vite preview"+ },+ "devDependencies": {+ "typescript": "5.9.3",+ "vite": "8.3.2"+ }+}diff --git a/fixtures/vite-vanilla/src/main.ts b/fixtures/vite-vanilla/src/main.tsnew file mode 100644index 0000000..729f150--- /dev/null+++ b/fixtures/vite-vanilla/src/main.ts@@ -0,0 +1,18 @@+import { exploded, phosphor, ranges, riffle, slow, terrain, turntable, type Figure, type RiffleOptions } from "@lucasmarkes/hairline";++/** No framework: six elements, six calls. */+const el = (id: string) => document.getElementById(id)!;+const read = el("read");++const cards: Figure<RiffleOptions> = riffle(el("riffle"), {+ stagger: ranges.riffle.stagger.max,+ labels: ["Radial menu", "Drum"],+ onRead: (text) => { read.textContent = text; },+});+terrain(el("terrain"), { radius: 4 });+exploded(el("exploded"));+phosphor(el("phosphor"), { theme: "dark" });+slow(el("slow"));+turntable(el("turntable"));++cards.update({ bands: true });diff --git a/fixtures/vite-vanilla/tsconfig.json b/fixtures/vite-vanilla/tsconfig.jsonnew file mode 100644index 0000000..873f5cc--- /dev/null+++ b/fixtures/vite-vanilla/tsconfig.json@@ -0,0 +1,12 @@+{+ "compilerOptions": {+ "target": "ES2020",+ "lib": ["ES2020", "DOM", "DOM.Iterable"],+ "module": "ESNext",+ "moduleResolution": "bundler",+ "strict": true,+ "noEmit": true,+ "skipLibCheck": false+ },+ "include": ["src"]+}diff --git a/scripts/consumers.mjs b/scripts/consumers.mjsnew file mode 100644index 0000000..3bcde1e--- /dev/null+++ b/scripts/consumers.mjs@@ -0,0 +1,134 @@+#!/usr/bin/env node+/**+ * Layer 6: the package as a stranger gets it. Packs it, installs the tarball+ * with npm into a copy of each fixture (outside the workspace, so nothing+ * resolves through a symlink), builds the fixture with its own toolchain,+ * serves the build and opens it in Chrome.+ *+ * node scripts/consumers.mjs both fixtures+ * node scripts/consumers.mjs next one of them (next | vite)+ *+ * Needs the network (npm installs next, react and vite) and a built package.+ */+import { execFileSync, spawn } from "node:child_process";+import { cpSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";+import { createRequire } from "node:module";+import { tmpdir } from "node:os";+import { join, resolve } from "node:path";++const ROOT = resolve(import.meta.dirname, "..");+const PKG = join(ROOT, "packages/hairline");+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"] },+};+const only = process.argv[2];+if (only && !FIXTURES[only]) { console.error(`Unknown fixture "${only}". Use: ${Object.keys(FIXTURES).join(" | ")}`); process.exit(2); }++let failures = 0;+const fail = (msg) => { failures++; console.error(` ✗ ${msg}`); };+const pass = (msg) => console.log(` ✓ ${msg}`);+const check = (ok, good, bad) => (ok ? pass(good) : fail(bad));+const run = (cmd, args, cwd) => execFileSync(cmd, args, { cwd, encoding: "utf8", stdio: "pipe" });+function step(label, cmd, args, cwd) {+ try { run(cmd, args, cwd); pass(label); return true; }+ catch (err) { fail(`${label}\n${String((err.stdout ?? "") + (err.stderr ?? "") || err.message).trim().split("\n").slice(-30).join("\n")}`); return false; }+}+async function up(url, tries = 100) {+ for (let i = 0; i < tries; i++) {+ try { if ((await fetch(url)).ok) return true; } catch {}+ await new Promise((r) => setTimeout(r, 200));+ }+ return false;+}++/**+ * Counts the animation frames requested between one frame and the next. A+ * page with any number of figures keeps one loop, so it asks for one frame per+ * frame; a second copy of the engine would ask for two.+ */+const COUNT_FRAMES = `(() => {+ const raf = window.requestAnimationFrame.bind(window);+ let asked = 0;+ window.__asked = [];+ window.requestAnimationFrame = (fn) => { asked++; return raf(fn); };+ const tally = () => { window.__asked.push(asked); asked = 0; raf(tally); };+ raf(tally);+})();`;++const staging = mkdtempSync(join(tmpdir(), "hairline-consumers-"));+console.log("\n▸ tarball");+step("pnpm pack", "pnpm", ["pack", "--pack-destination", staging], PKG);+const tgz = readdirSync(staging).filter((f) => f.endsWith(".tgz")).map((f) => join(staging, f))[0];+if (!tgz) { console.error("\nNo tarball to install.\n"); process.exit(1); }++const browser = await chromium.launch({ channel: "chrome" });+for (const [name, fx] of Object.entries(FIXTURES)) {+ if (only && only !== name) continue;+ console.log(`\n▸ ${fx.dir}`);+ const dir = join(staging, name);+ cpSync(join(ROOT, fx.dir), dir, { recursive: true, filter: (src) => !/\/(node_modules|\.next|dist)$/.test(src) });+ if (name === "next") {+ // what `shadcn add` does with the registry item: write its file into the app+ run("node", ["registry/build.mjs"], ROOT);+ const item = JSON.parse(readFileSync(join(ROOT, "apps/site/public/r/hairline.json"), "utf8"));+ for (const file of item.files) {+ mkdirSync(join(dir, file.path, ".."), { recursive: true });+ writeFileSync(join(dir, file.path), file.content);+ }+ pass("the registry item's file is in place");+ }+ if (!step("npm install (the tarball, as a dependency)", "npm", ["install", "--no-audit", "--no-fund", tgz], dir)) continue;+ if (!step("build (the fixture's own typecheck and bundler)", "npm", ["run", "build"], dir)) continue;++ const [cmd, args] = fx.serve(fx.port);+ const server = spawn(cmd, args, { cwd: dir, stdio: "ignore" });+ try {+ const url = `http://localhost:${fx.port}/`;+ if (!(await up(url))) { fail(`nothing answered at ${url}`); continue; }++ if (name === "next") {+ const html = await (await fetch(url)).text();+ check(/<div id="riffle"[^>]*><\/div>/.test(html), "the server renders an empty <div> for a figure", "the server-rendered page has no empty <div id=\"riffle\">");+ check(!html.includes("<svg"), "no figure is drawn on the server", "the server-rendered page already has an <svg>");+ }++ const context = await browser.newContext({ viewport: { width: 1200, height: 900 } });+ await context.addInitScript(COUNT_FRAMES);+ const page = await context.newPage();+ const noise = [];+ page.on("console", (m) => { if (m.type() === "error" || m.type() === "warning") noise.push(`${m.type()}: ${m.text()}`); });+ page.on("pageerror", (e) => noise.push(`pageerror: ${e}`));+ await page.goto(url, { waitUntil: "networkidle" });++ for (const id of fx.figures) {+ const drawn = await page.locator(`#${id} svg > *`).first().waitFor({ timeout: 5000 }).then(() => true, () => false);+ const box = drawn ? await page.locator(`#${id} svg`).boundingBox() : null;+ check(drawn && box.width > 100 && Math.abs(box.width / box.height - 1.25) < 0.01, `${id} is drawn, 5:4`, `${id} is not drawn (box ${JSON.stringify(box)})`);+ }+ check((await page.locator("style[data-hairline-style]").count()) === 0 && (await page.evaluate(() => document.adoptedStyleSheets.length)) === 1,+ "one adopted stylesheet for every figure", "the figures did not share one adopted stylesheet");++ await page.waitForTimeout(500);+ const asked = await page.evaluate(() => { const from = window.__asked.length; return new Promise((r) => setTimeout(() => r(window.__asked.slice(from)), 500)); });+ check(asked.length > 10 && asked.every((n) => n === 1), `one loop for ${fx.figures.length} figures (${asked.length} frames, one request each)`, `expected one frame request per frame, saw ${[...new Set(asked)].join(", ")} over ${asked.length} frames`);++ if (name === "next") {+ await page.goto(`${url}registry`, { waitUntil: "networkidle" });+ const fill = await page.locator("#themed svg path").first().evaluate((el) => getComputedStyle(el).fill).catch(() => "");+ check(fill === "rgb(16, 16, 20)", "the registry item draws with the app's tokens", `the registry item's figure is filled ${fill || "(not drawn)"}, not --background`);+ }+ if (name === "vite") check((await page.locator("#read").textContent()) !== "", "onRead reached the page", "onRead never wrote to the page");+ check(noise.length === 0, "console is clean", `console:\n${noise.join("\n")}`);+ await context.close();+ } finally {+ server.kill();+ }+}+await browser.close();+rmSync(staging, { recursive: true, force: true });++if (failures) { console.error(`\n${failures} consumer check${failures > 1 ? "s" : ""} failed.\n`); process.exit(1); }+console.log("\nBoth consumers install, build and draw.\n");