Isometric line figures that answer the pointer. For React and for anything with a DOM.
Docs and fixtures: one intensity option, and the README leads with the install
Lucas Marques7479c9e8b3ca
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 596b18a..591bde4 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -37,16 +37,20 @@ scripts the release gate and what it callsThe six engines in `packages/hairline/src/figures`, and `src/core/iso.ts`, `motion.ts` and `stage.ts`, were ported from the essay at [lucasmarkes.com/lab/hairline](https://lucasmarkes.com/lab/hairline), where they are figures 9.1 to 9.6. Their comments still say "the study" and "Fig 9.n": that is the essay.-The port is held to the essay by the parity tests. `packages/hairline/test/parity/golden` holds the SVG each figure drew on the essay's page, under a frozen clock, at four moments of a scripted pointer path; `test/browser/parity.spec.ts` replays the same script against the package, on the same frozen clock, and expects the same SVG and the same caption, character for character.+The port is held to the essay by the parity tests. `packages/hairline/test/parity/golden` holds the SVG each figure drew on the essay's page, under a frozen clock, at four moments of a scripted pointer path; `test/browser/parity.spec.ts` replays the same script against the package, on the same frozen clock, and expects the same SVG and the same caption, character for character. Two things come out of both sides first, because the package no longer has them: Riffle's hidden hit bands, and the names the essay gives Riffle's cards. Where the script changes the option, the package is set to the `intensity` in `test/parity/scripts.mjs` that maps exactly onto the essay's value.So a change to an engine that moves a line fails parity, and that is the point. If the change is meant, say so in the pull request and update the golden file for that figure by hand. The goldens are not regenerated from the package: `pnpm -C packages/hairline capture <commit> [url]` records them from the essay's site at that commit, and exists for the day the essay changes.-## Adding an option+## Tuning `intensity`-1. Add its bounds to `src/ranges.ts`. The site's sliders and tables, and the tests, read them from there.-2. Add it to the figure's options type in `src/index.ts`, with a doc comment that states the range and the default.-3. Add its name to the component's key list in `src/react.tsx`.-4. Describe it in `apps/site/lib/figures.ts`. The site's tests hold its tables and snippets to `ranges`.+Every figure takes one tuning option, `intensity`, from 0 to 1. Each figure turns it into its own number through the table in `packages/hairline/src/intensity.ts`: three values per figure, at 0, 0.5 and 1, joined by two straight lines. The value at 0.5 is the figure's default, so the default drawing never changes.++To change how strongly a figure answers:++1. Change its row in `src/intensity.ts`. `test/intensity.test.ts` checks the row still moves one way only, and that each parity intensity still lands on its golden value.+2. Change the same row in `apps/site/lib/figures.ts`, which keeps a copy for the site's copy. `apps/site/test/docs.test.ts` fails until the two agree.++There are no per-figure options, by design. A new option is a new key in `HairlineOptions` (`src/mount.ts`), for every figure at once.## Pull requestsdiff --git a/README.md b/README.mdindex 63585fe..455c1a5 100644--- a/README.md+++ b/README.md@@ -8,12 +8,12 @@ Six isometric line figures that answer the pointer. For React and for anything w-Live, with a slider for every option: **[hairline.lucasmarkes.com](https://hairline.lucasmarkes.com)**+Live, with a slider for `intensity`: **[hairline.lucasmarkes.com](https://hairline.lucasmarkes.com)**## Install```sh-pnpm add @lucasmarkes/hairline+npm i @lucasmarkes/hairline```No dependencies. ESM only. React 18 or later is an optional peer, needed only by `@lucasmarkes/hairline/react`.@@ -32,53 +32,48 @@ npx shadcn@latest add https://hairline.lucasmarkes.com/r/hairline.jsonimport { Terrain } from "@lucasmarkes/hairline/react";export function Hero() {- return <Terrain radius={4} className="w-96" />;+ return <Terrain />;}```-The entry is a client module, so a Server Component can render it with no `"use client"` of its own. A component takes its figure's options and every `<div>` attribute, and forwards its ref to the `<div>`.+The figure fills its parent's width at a 5:4 aspect ratio. The entry is a client module, so a Server Component can render it with no `"use client"` of its own. Every component takes the options below and every `<div>` attribute, and forwards its ref to the `<div>`.### Anything else```tsimport { terrain } from "@lucasmarkes/hairline";-const figure = terrain(document.getElementById("figure")!, { radius: 4 });+const figure = terrain(document.getElementById("figure")!);-figure.update({ radius: 2 });+figure.update({ intensity: 0.8 });figure.destroy();```-A figure draws into the element you give it, at the element's width and a 5:4 aspect ratio. `update` changes options on the running figure; `destroy` removes what the figure added. That is the shape of a Svelte action, so `use:terrain={{ radius }}` works as it is.+A figure draws into the element you give it, at the element's width and a 5:4 aspect ratio. `update` changes options on the running figure; `destroy` removes what the figure added. That is the shape of a Svelte action, so `use:terrain={{ intensity }}` works as it is.## The figures-| Function | Component | What it is | Option | Range | Default |-| --- | --- | --- | --- | --- | --- |-| `riffle` | `Riffle` | A tray of eight cards. The card under the pointer stands up; the arrow keys walk the cards. | `stagger` | 0 to 90 ms | 40 |-| `terrain` | `Terrain` | Eighty-one pillars on a plinth that rise around the pointer. | `radius` | 1.5 to 5 cells | 3 |-| `exploded` | `Exploded` | An app window in four layers. Moving across opens the gap; moving down picks a layer. | `gap` | 12 to 40 units | 28 |-| `phosphor` | `Phosphor` | A dot matrix that plays a loop, and fades like phosphor where the pointer paints it. | `afterglow` | 150 to 1500 ms | 520 |-| `slow` | `Slow` | Crates riding a belt through a gate. Hovering slows the clock without stopping it. | `rate` | 0.05 to 0.6 × | 0.2 |-| `turntable` | `Turntable` | Blocks on a turntable. A flick spins it; it settles on the nearest quarter turn. | `coast` | 200 to 1500 ms | 650 |--A number outside its range is clamped, and anything that is not a number falls back to the default. The bounds are exported, so a slider or a table never repeats them:--```ts-import { ranges } from "@lucasmarkes/hairline";--ranges.terrain.radius; // { min: 1.5, max: 5, step: 0.25, default: 3, unit: "cells" }-```+| Function | Component | What it is | A stronger `intensity` |+| --- | --- | --- | --- |+| `riffle` | `Riffle` | A tray of eight cards. The card under the pointer stands up; the arrow keys walk the cards. | The ripple spreads further from the pulled card. |+| `terrain` | `Terrain` | Eighty-one pillars on a plinth that rise around the pointer. | A wider area rises. |+| `exploded` | `Exploded` | An app window in four layers. Moving across opens the gap; moving down picks a layer. | The layers open further. |+| `phosphor` | `Phosphor` | A dot matrix that plays a loop, and fades like phosphor where the pointer paints it. | The trail lingers longer. |+| `slow` | `Slow` | Crates riding a belt through a gate. Hovering slows the clock without stopping it. | Time slows down more. |+| `turntable` | `Turntable` | Blocks on a turntable. A flick spins it; it settles on the nearest quarter turn. | The spin coasts longer. |-Riffle takes two more options: `bands` (boolean) shows the bands the pointer is tested against, and `labels` (up to eight strings) names the cards.+## Options-Every figure also takes:+Every figure takes the same four, all optional:| Option | Type | Default | || --- | --- | --- | --- |+| `intensity` | `number` | `0.5` | How strongly the figure answers the pointer, from 0 (subtle) to 1 (strong). A number outside 0…1 is clamped; anything that is not a number is 0.5. || `theme` | `"auto" \| "light" \| "dark"` | `"auto"` | `"auto"` follows the page: an ancestor with class `dark` or `data-theme="dark"`, then the page's `color-scheme`. || `label` | `string` | a description in English | The accessible name. In React, `aria-label` does the same. |-| `onRead` | `(text: string) => void` | | The figure's caption, each time it changes: `"03 · Dock"`, `"gap 28.0"`, `"rate 0.20×"`. |+| `onRead` | `(text: string) => void` | | The figure's caption, each time it changes: `"03"`, `"gap 28.0"`, `"rate 0.20×"`. |++In `update`, a key set to `undefined` goes back to its default, and a key left out stays as it is.## Theme@@ -109,7 +104,7 @@ The figure's styles have no specificity, so any rule of yours wins without `!imp## More-- [hairline.lucasmarkes.com](https://hairline.lucasmarkes.com): every figure live, a theme editor, and snippets for Next.js, Vue, Svelte, Astro and a CDN.+- [hairline.lucasmarkes.com](https://hairline.lucasmarkes.com): every figure live, an inspector that writes the snippet for you, and a CDN example.- [The essay](https://lucasmarkes.com/lab/hairline): how the figures are drawn, and why with lines.- [CHANGELOG.md](https://github.com/lucasmarkes/hairline/blob/main/CHANGELOG.md) and [CONTRIBUTING.md](https://github.com/lucasmarkes/hairline/blob/main/CONTRIBUTING.md).diff --git a/fixtures/next-app/app/page.tsx b/fixtures/next-app/app/page.tsxindex 9b1dddf..2816ff1 100644--- a/fixtures/next-app/app/page.tsx+++ b/fixtures/next-app/app/page.tsx@@ -9,8 +9,8 @@ import { Vanilla } from "./vanilla";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" />+ <Riffle id="riffle" intensity={0.8} />+ <Slow id="slow" intensity={0.25} theme="dark" /><Vanilla /></main>);diff --git a/fixtures/next-app/app/registry/page.tsx b/fixtures/next-app/app/registry/page.tsxindex 85c7a41..73eacd1 100644--- a/fixtures/next-app/app/registry/page.tsx+++ b/fixtures/next-app/app/registry/page.tsx@@ -1,5 +1,5 @@import type { CSSProperties } from "react";-import { Terrain } from "@/components/ui/hairline";+import { Riffle, 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;@@ -13,6 +13,7 @@ export default function Page() {return (<main style={{ width: 400, margin: "40px auto", background: "var(--background)", ...tokens }}><Terrain id="themed" />+ <Riffle intensity={0.8} /></main>);}diff --git a/fixtures/next-app/app/vanilla.tsx b/fixtures/next-app/app/vanilla.tsxindex 52984a5..d07b287 100644--- a/fixtures/next-app/app/vanilla.tsx+++ b/fixtures/next-app/app/vanilla.tsx@@ -6,7 +6,7 @@ import { phosphor } from "@lucasmarkes/hairline";export function Vanilla() {const ref = useRef<HTMLDivElement>(null);useEffect(() => {- const figure = phosphor(ref.current!, { afterglow: 900 });+ const figure = phosphor(ref.current!, { intensity: 0.8 });return () => figure.destroy();}, []);return <div id="phosphor" ref={ref} />;diff --git a/fixtures/vite-vanilla/src/main.ts b/fixtures/vite-vanilla/src/main.tsindex 729f150..ee3059d 100644--- a/fixtures/vite-vanilla/src/main.ts+++ b/fixtures/vite-vanilla/src/main.ts@@ -1,18 +1,17 @@-import { exploded, phosphor, ranges, riffle, slow, terrain, turntable, type Figure, type RiffleOptions } from "@lucasmarkes/hairline";+import { exploded, phosphor, riffle, slow, terrain, turntable, type Figure } 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"],+const cards: Figure = riffle(el("riffle"), {+ intensity: 1,onRead: (text) => { read.textContent = text; },});-terrain(el("terrain"), { radius: 4 });+terrain(el("terrain"), { intensity: 0.75 });exploded(el("exploded"));phosphor(el("phosphor"), { theme: "dark" });slow(el("slow"));turntable(el("turntable"));-cards.update({ bands: true });+cards.update({ intensity: 0.8 });