Isometric line figures that answer the pointer. For React and for anything with a DOM.
Site: the copy, the snippets and llms.txt speak one intensity option
Lucas Marquesbf0625558326
diff --git a/apps/site/lib/figures.ts b/apps/site/lib/figures.tsindex 9d4fa88..d9ddee4 100644--- a/apps/site/lib/figures.ts+++ b/apps/site/lib/figures.ts@@ -1,115 +1,105 @@-import { ranges, type Range } from "@lucasmarkes/hairline";-/**- * The page's copy about each figure. Everything numeric comes from the- * package's own `ranges`, so a slider, a props table and /llms.txt cannot- * disagree with what the figure does.+ * The page's copy about each figure, and the options every figure takes.+ *+ * INTENSITY copies the table in packages/hairline/src/intensity.ts, which the+ * package keeps internal. test/docs.test.ts holds the two equal, so /llms.txt+ * cannot describe a map the figures do not use.*/-export type FigureId = keyof typeof ranges;+export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable";export type FigureDoc = {id: FigureId;/** The React component, and the figure's name on the page. */name: string;- /** The figure's one numeric option. */- option: string;- range: Range;summary: string;- optionDoc: string;+ /** What a higher intensity does to this figure, as one sentence. */+ stronger: string;+ /** The number intensity sets inside the figure, for /llms.txt. */+ parameter: { name: string; unit: string };};-const COPY: Record<FigureId, { name: string; summary: string; optionDoc: string }> = {- riffle: {+export const FIGURES: FigureDoc[] = [+ {+ id: "riffle",name: "Riffle",summary: "A tray of eight cards. The card under the pointer stands up and its neighbours lean after it. The arrow keys walk the cards.",- optionDoc: "The delay between one card and the next as they lean.",+ stronger: "The ripple spreads further from the pulled card.",+ parameter: { name: "stagger", unit: "ms" },},- terrain: {+ {+ id: "terrain",name: "Terrain",summary: "Eighty-one pillars on a plinth. They rise around the pointer and settle back into a dune with two rises.",- optionDoc: "How far the rise reaches around the pointer.",+ stronger: "A wider area rises.",+ parameter: { name: "radius", unit: "cells" },},- exploded: {+ {+ id: "exploded",name: "Exploded",summary: "An app window taken apart into four layers. Moving across opens the gap; moving down picks a layer.",- optionDoc: "The space between two layers when fully open, in viewBox units (the drawing is 400 × 320).",+ stronger: "The layers open further.",+ parameter: { name: "gap", unit: "viewBox units" },},- phosphor: {+ {+ id: "phosphor",name: "Phosphor",summary: "A seven by seven dot matrix playing a loop. Where the pointer paints, the dots fade like phosphor.",- optionDoc: "How long a painted dot takes to fade.",+ stronger: "The trail lingers longer.",+ parameter: { name: "afterglow", unit: "ms" },},- slow: {+ {+ id: "slow",name: "Slow",summary: "Crates riding a belt through a gate. Hovering slows the clock without stopping it.",- optionDoc: "The clock's speed while the pointer is over the figure, as a multiple of normal.",+ stronger: "Time slows down more.",+ parameter: { name: "rate", unit: "× normal speed" },},- turntable: {+ {+ id: "turntable",name: "Turntable",summary: "Blocks on a turntable. A flick across it spins it, and it settles on the nearest quarter turn.",- optionDoc: "How long a flick keeps the table turning.",+ stronger: "The spin coasts longer.",+ parameter: { name: "coast", unit: "ms" },},-};--export const FIGURES: FigureDoc[] = (Object.keys(ranges) as FigureId[]).map((id) => {- const [option, range] = Object.entries(ranges[id])[0] as [string, Range];- return { id, option, range, ...COPY[id] };-});--/** Names for Riffle's eight cards on this page. */-export const CARDS = ["Radial menu", "Drum", "Dock", "Condense", "Settle", "Upload", "Badge", "Spark"] as const;--/** "0 to 90 ms", "0.05× to 0.6×", "12 to 40 units" */-export function span(range: Range): string {- if (range.unit === "×") return `${range.min}× to ${range.max}×`;- return `${range.min} to ${range.max} ${range.unit === "u" ? "units" : range.unit}`;-}+];-/** A value as the page shows it next to a slider: "40 ms", "0.2×" */-export function shown(value: number, range: Range): string {- return range.unit === "×" ? `${value}×` : `${value} ${range.unit}`;-}+/** Each figure's number at intensity 0, 0.5 and 1: a copy of the package's table. */+export const INTENSITY: Record<FigureId, readonly [number, number, number]> = {+ riffle: [0, 40, 90],+ terrain: [1.5, 3, 5],+ exploded: [12, 28, 40],+ phosphor: [150, 520, 1500],+ slow: [0.6, 0.2, 0.05],+ turntable: [200, 650, 1500],+};export type Row = { name: string; type: string; default: string; description: string };-/** A figure's own options, the numeric one first. */-export function rows(doc: FigureDoc): Row[] {- const out: Row[] = [- { name: doc.option, type: "number", default: String(doc.range.default), description: `${doc.optionDoc} ${span(doc.range)}.` },- ];- if (doc.id === "riffle") {- out.push(- { name: "bands", type: "boolean", default: "false", description: "Shows the bands the pointer is tested against." },- { name: "labels", type: "readonly string[]", default: "[]", description: "Names for the eight cards, card 01 first. A named card is read out as \"03 · Dock\", an unnamed one as \"03\"." },- );- }- return out;-}--/** The options every figure takes. */-export const SHARED: Row[] = [+/** The options every figure takes: the whole API, in the quickstart's table. */+export const OPTIONS: Row[] = [+ { name: "intensity", type: "number", default: "0.5", description: "How strongly the figure answers the pointer, from 0 (subtle) to 1 (strong). Outside 0…1 is clamped; anything that is not a number is 0.5." },{ name: "theme", type: "\"auto\" | \"light\" | \"dark\"", default: "\"auto\"", description: "\"auto\" follows the page: an ancestor with class dark or data-theme=\"dark\", then the page's color-scheme." },- { name: "label", type: "string", default: "a description in English", description: "The accessible name. In React, aria-label does the same." },+ { name: "label", type: "string", default: "a description", description: "The accessible name. In React, aria-label does the same." },{ name: "onRead", type: "(text: string) => void", default: "", description: "The figure's caption, each time it changes. Called once at mount with the rest caption." },];/** The public theme: six custom properties, set on the figure or on anything above it. */-export const THEME: { property: string; role: string }[] = [- { property: "--hairline-plate", role: "The fill of every plate. It hides what is drawn behind, so it must be the colour the figure sits on." },- { property: "--hairline-hi", role: "The stroke of what is lit: the card pulled, the layer picked, a dot that is on." },- { property: "--hairline-edge", role: "Silhouettes, and dots at half strength." },- { property: "--hairline-mid", role: "Every other stroke." },- { property: "--hairline-lo", role: "What recedes: guides, and dots that are off." },- { property: "--hairline-stroke", role: "The stroke width, in CSS pixels at any size. Default 0.9." },+export const THEME: { property: string; light: string; role: string }[] = [+ { property: "--hairline-plate", light: "#ffffff", role: "The fill of every plate. It hides what is drawn behind, so it must be the colour the figure sits on." },+ { property: "--hairline-hi", light: "#232327", role: "The stroke of what is lit: the card pulled, the layer picked, a dot that is on." },+ { property: "--hairline-edge", light: "#a4a4ac", role: "Silhouettes, and dots at half strength." },+ { property: "--hairline-mid", light: "#c3c3c9", role: "Every other stroke." },+ { property: "--hairline-lo", light: "#e0e0e4", role: "What recedes: guides, and dots that are off." },+ { property: "--hairline-stroke", light: "0.9", role: "The stroke width, in CSS pixels at any size." },];-export const NOTES: { title: string; body: string }[] = [- { title: "Accessibility", body: "A figure is an image with a description you can replace with label. Riffle is the exception: it is a focusable group, the arrow keys walk its cards, and a live region reads the card out." },- { title: "Reduced motion", body: "With prefers-reduced-motion, the figures that play on their own (Phosphor and Slow) hold still, and every figure still answers the pointer." },- { title: "Performance", body: "Every figure on a page shares one requestAnimationFrame loop. A figure off screen, or at rest, does no work, and the loop stops when nothing is moving." },- { title: "Server rendering", body: "On the server a figure is an empty box with a 5:4 aspect ratio, so nothing shifts when it draws. The drawing itself happens in the browser." },- { title: "Size", body: "No dependencies. A bundle that imports one figure carries one figure." },+/** The four cards under the figures. Tiny's body is the measured size; see lib/size.ts. */+export const CARDS: { title: string; body: string }[] = [+ { title: "Tiny", body: "gzipped, all six figures. A bundle that imports one carries one." },+ { title: "No dependencies", body: "SVG and one shared animation frame. React is optional." },+ { title: "Accessible", body: "Keyboard on Riffle, a description for screen readers, and stillness under reduced motion." },+ { title: "Themeable", body: "Six CSS variables, on the figure or anything above it. Light and dark built in." },];export const LINKS = {diff --git a/apps/site/lib/highlight.ts b/apps/site/lib/highlight.tsindex 857e4a1..64c457f 100644--- a/apps/site/lib/highlight.ts+++ b/apps/site/lib/highlight.ts@@ -1,22 +1,14 @@import { codeToHtml } from "shiki";-/**- * Highlighting happens here, at build, so no highlighter reaches the browser.- *- * A snippet that follows a slider is written with LIVE where the value goes.- * After highlighting, LIVE becomes a marked span holding the default; the- * client only ever changes that span's text.- */-export const LIVE = "424242";+/** Highlighting happens here, at build, so no highlighter reaches the browser. */const escape = (s: string) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");-export async function highlight(code: string, lang: string, initial?: string | number): Promise<string> {- const html = await codeToHtml(code.trimEnd(), { lang, theme: "min-light" });- return initial === undefined ? html : html.replaceAll(LIVE, `<span data-live>${escape(String(initial))}</span>`);+export async function highlight(code: string, lang: string): Promise<string> {+ return codeToHtml(code.trimEnd(), { lang, theme: "min-light" });}-/** A shell command, unhighlighted, in the same wrapper the highlighter writes. */+/** Plain text in the same wrapper the highlighter writes. */export function plain(code: string): string {return `<pre class="shiki"><code>${escape(code.trimEnd())}</code></pre>`;}diff --git a/apps/site/lib/llms.ts b/apps/site/lib/llms.tsindex fd74262..09f3fcd 100644--- a/apps/site/lib/llms.ts+++ b/apps/site/lib/llms.ts@@ -1,16 +1,23 @@-import { FIGURES, LINKS, NOTES, SHARED, THEME, rows, type Row } from "./figures";-import { FRAMEWORKS, PACKAGE, install, react, vanilla } from "./snippets";+import { FIGURES, INTENSITY, LINKS, OPTIONS, THEME, type Row } from "./figures";+import { CDN, PACKAGE, REACT, VANILLA, install } from "./snippets";/** The page as plain text, for a model to read: the same data, the same copy. */const table = (list: Row[]) => list.map((r) => `- \`${r.name}\` (${r.type}${r.default ? `, default ${r.default}` : ""}): ${r.description}`).join("\n");const fence = (lang: string, code: string) => "```" + lang + "\n" + code.trimEnd() + "\n```";+/** "stagger 0 ms at 0, 40 ms at 0.5, 90 ms at 1" */+export function scale(id: keyof typeof INTENSITY, parameter: { name: string; unit: string }): string {+ const unit = parameter.unit.startsWith("×") ? parameter.unit : ` ${parameter.unit}`;+ const [lo, mid, hi] = INTENSITY[id];+ return `${parameter.name} ${lo}${unit} at 0, ${mid}${unit} at 0.5, ${hi}${unit} at 1`;+}+export function llms(base: string): string {const out: string[] = ["# hairline","",- `> ${PACKAGE}: six isometric line figures that answer the pointer. SVG, no dependencies, ESM only. A function per figure, and a React component per figure.`,+ `> ${PACKAGE}: six isometric line figures that answer the pointer. SVG, no dependencies, ESM only. A function per figure, and a React component per figure. Every figure takes the same four options.`,"","## Install","",@@ -18,31 +25,39 @@ export function llms(base: string): string {"","## Use","",- `Vanilla: \`import { ${FIGURES.map((f) => f.id).join(", ")} } from "${PACKAGE}"\`. Each function takes an element and options, draws into the element, and returns \`{ update(options), destroy() }\`.`,+ `React: \`import { ${FIGURES.map((f) => f.name).join(", ")} } from "${PACKAGE}/react"\`. Each component renders a \`<div>\`, takes the options below and any \`<div>\` attribute, and forwards its ref. The entry is a client module: render it from a Server Component without writing "use client".`,+ "",+ fence("tsx", REACT),+ "",+ `Vanilla: \`import { ${FIGURES.map((f) => f.id).join(", ")} } from "${PACKAGE}"\`. Each function takes an element and the options, draws into the element, and returns \`{ update(options), destroy() }\`. In \`update\`, a key set to \`undefined\` goes back to its default and a key left out stays as it is.`,"",- `React: \`import { ${FIGURES.map((f) => f.name).join(", ")} } from "${PACKAGE}/react"\`. Each component renders a \`<div>\`, takes the figure's options and any \`<div>\` attribute, and forwards its ref. The entry is a client module: render it from a Server Component without writing "use client".`,+ fence("ts", VANILLA),"",- "A figure fills its element's width at a 5:4 aspect ratio. Give the element a width.",+ "Without a bundler:","",- "## Options every figure takes",+ fence("html", CDN),"",- table(SHARED),+ "A figure fills its element's width at a 5:4 aspect ratio.",+ "",+ "## Options",+ "",+ table(OPTIONS),"","## Figures",+ "",+ "What a higher `intensity` does to each figure, and the number it sets inside the figure (two straight lines through these three points):",];for (const doc of FIGURES) {- out.push("", `### ${doc.name}`, "", doc.summary, "", table(rows(doc)), "", fence("tsx", react(doc, doc.range.default)), "", fence("ts", vanilla(doc, doc.range.default)));+ out.push("", `### ${doc.name}`, "", doc.summary, "", `Higher intensity: ${doc.stronger} (${scale(doc.id, doc.parameter)}.)`);}out.push(- "", "## Ranges", "",- `\`import { ranges } from "${PACKAGE}"\` gives every numeric option's \`min\`, \`max\`, \`step\`, \`default\` and \`unit\`. A value outside its range is clamped; a value that is not a number becomes the default.`,"", "## Theme", "","Six CSS custom properties, set on the figure or on any ancestor. Without them a figure is light, or dark when an ancestor has class `dark` or `data-theme=\"dark\"`, or when the page's `color-scheme` is dark.",- "", THEME.map((t) => `- \`${t.property}\`: ${t.role}`).join("\n"),- "", "## Frameworks",+ "", THEME.map((t) => `- \`${t.property}\` (light: ${t.light}): ${t.role}`).join("\n"),+ "", "## Accessibility", "",+ "A figure is an image with a description you can replace with `label`. Riffle is a focusable group: the arrow keys walk its cards and a live region reads out the card's number. Under prefers-reduced-motion, Phosphor and Slow hold still, and every figure still answers the pointer.",+ "", "## Links", "",+ `- Site: ${base}`, `- Source: ${LINKS.github}`, `- npm: ${LINKS.npm}`, `- The essay the figures come from: ${LINKS.essay}`, `- shadcn registry item: ${base}/r/hairline.json`, "",);- for (const f of FRAMEWORKS) out.push("", `### ${f.label}`, "", fence(f.lang, f.code));- out.push("", "## Notes", "", NOTES.map((n) => `- ${n.title}: ${n.body}`).join("\n"));- out.push("", "## Links", "", `- Site: ${base}`, `- Source: ${LINKS.github}`, `- npm: ${LINKS.npm}`, `- The essay the figures come from: ${LINKS.essay}`, `- shadcn registry item: ${base}/r/hairline.json`, "");return out.join("\n");}diff --git a/apps/site/lib/size.ts b/apps/site/lib/size.tsnew file mode 100644index 0000000..a084366--- /dev/null+++ b/apps/site/lib/size.ts@@ -0,0 +1,13 @@+import { readFileSync } from "node:fs";+import { join } from "node:path";+import { gzipSync } from "node:zlib";++/**+ * The vanilla entry's gzip size with all six figures, as the Tiny card says+ * it: "16.3 kB". Measured at build from the package's own dist, which turbo+ * builds before the site. Next runs the build from apps/site.+ */+export function tiny(): string {+ const file = readFileSync(join(process.cwd(), "../../packages/hairline/dist/index.js"));+ return `${(gzipSync(file).length / 1000).toFixed(1)} kB`;+}diff --git a/apps/site/lib/snippets.ts b/apps/site/lib/snippets.tsindex 836961b..2c65330 100644--- a/apps/site/lib/snippets.ts+++ b/apps/site/lib/snippets.ts@@ -1,4 +1,4 @@-import type { FigureDoc } from "./figures";+import { THEME } from "./figures";/*** Every piece of code the page shows, as plain text. The page highlights it;@@ -7,110 +7,69 @@ import type { FigureDoc } from "./figures";export const PACKAGE = "@lucasmarkes/hairline";+/** npm first: it is the command a stranger already knows. */export function install(base: string): { label: string; code: string }[] {return [+ { label: "npm", code: `npm i ${PACKAGE}` },{ label: "pnpm", code: `pnpm add ${PACKAGE}` },- { label: "npm", code: `npm install ${PACKAGE}` },{ label: "yarn", code: `yarn add ${PACKAGE}` },{ label: "bun", code: `bun add ${PACKAGE}` },{ label: "shadcn", code: `npx shadcn@latest add ${base}/r/hairline.json` },];}-export function react(doc: FigureDoc, value: string | number): string {- return `import { ${doc.name} } from "${PACKAGE}/react";+export type Theme = "auto" | "light" | "dark";-export function Figure() {- return <${doc.name} ${doc.option}={${value}} className="w-80" />;-}-`;-}--export function vanilla(doc: FigureDoc, value: string | number): string {- return `import { ${doc.id} } from "${PACKAGE}";--const figure = ${doc.id}(document.getElementById("figure")!, { ${doc.option}: ${value} });--// later-figure.update({ ${doc.option}: ${doc.range.max} });-figure.destroy();-`;+/**+ * The inspector's snippet: the component with only the props that differ+ * from the default. The intensity is read to two decimals, the slider's+ * precision, so 0.5 and a float a hair away from it both leave it out.+ */+export function snippet(name: string, state: { intensity: number; theme: Theme }): string {+ const intensity = Math.round(state.intensity * 100) / 100;+ const props = [+ intensity !== 0.5 ? ` intensity={${intensity}}` : "",+ state.theme !== "auto" ? ` theme="${state.theme}"` : "",+ ].join("");+ return `import { ${name} } from "${PACKAGE}/react";\n\n<${name}${props} />\n`;}-export const FRAMEWORKS: { label: string; lang: string; code: string }[] = [- {- label: "Next.js",- lang: "tsx",- code: `// app/page.tsx — a Server Component. The React entry is a client module,-// so there is no "use client" to write.-import { Terrain } from "${PACKAGE}/react";+export const REACT = `import { Terrain } from "${PACKAGE}/react";export default function Page() {- return <Terrain radius={4} className="w-96" />;+ return <Terrain />;}-`,- },- {- label: "Vue",- lang: "vue",- code: `<script setup lang="ts">-import { onBeforeUnmount, onMounted, ref } from "vue";-import { terrain, type Figure, type TerrainOptions } from "${PACKAGE}";--const el = ref<HTMLElement>();-let figure: Figure<TerrainOptions> | undefined;--onMounted(() => { figure = terrain(el.value!, { radius: 4 }); });-onBeforeUnmount(() => figure?.destroy());-</script>--<template>- <div ref="el" />-</template>-`,- },- {- label: "Svelte",- lang: "svelte",- code: `<script lang="ts">- import { terrain, type TerrainOptions } from "${PACKAGE}";+`;- // A figure has the shape of a Svelte action: { update, destroy }.- const figure = (el: HTMLElement, options: TerrainOptions) => terrain(el, options);- let radius = 4;-</script>+export const VANILLA = `import { terrain } from "${PACKAGE}";-<div use:figure={{ radius }} />-`,- },- {- label: "Astro",- lang: "astro",- code: `<div id="figure"></div>+const figure = terrain(document.getElementById("figure")!);-<script>- import { terrain } from "${PACKAGE}";+figure.update({ intensity: 0.8 });+figure.destroy();+`;- terrain(document.getElementById("figure")!, { radius: 4 });-</script>-`,- },- {- label: "CDN",- lang: "html",- code: `<div id="figure" style="width: 400px"></div>+export const CDN = `<div id="figure" style="width: 400px"></div><script type="module">import { terrain } from "https://esm.sh/${PACKAGE}";- terrain(document.getElementById("figure"), { radius: 4 });+ terrain(document.getElementById("figure"));</script>-`,- },-];+`;-/** What the theme editor prints. */-export function themeCss(colors: Record<string, string>, stroke: number): string {- const lines = Object.entries(colors).map(([k, v]) => ` --hairline-${k}: ${v};`);- return `.figures {\n${lines.join("\n")}\n --hairline-stroke: ${stroke};\n}\n`;+export const CSS = `/* On a figure or anything above it. Without them a figure is light,+ or dark when the page says so. --hairline-plate must be the colour+ the figure sits on: it hides what is drawn behind each plate. */+.figures {+${THEME.map((t) => ` ${t.property}: ${t.light};`).join("\n")}}+`;++/** The quickstart's second step. */+export const PASTE: { label: string; lang: string; code: string }[] = [+ { label: "React", lang: "tsx", code: REACT },+ { label: "Vanilla", lang: "ts", code: VANILLA },+ { label: "CDN", lang: "html", code: CDN },+ { label: "CSS", lang: "css", code: CSS },+];diff --git a/apps/site/test/docs.test.ts b/apps/site/test/docs.test.tsindex c24efa9..015a5dd 100644--- a/apps/site/test/docs.test.ts+++ b/apps/site/test/docs.test.ts@@ -1,82 +1,118 @@+import { gzipSync } from "node:zlib";+import { readFileSync } from "node:fs";import { describe, expect, it } from "vitest";-import { ranges } from "@lucasmarkes/hairline";import * as components from "@lucasmarkes/hairline/react";import * as figures from "@lucasmarkes/hairline";-import { FIGURES, SHARED, rows, span } from "@/lib/figures";-import { llms } from "@/lib/llms";-import { FRAMEWORKS, install, react, vanilla } from "@/lib/snippets";+import type { HairlineOptions } from "@lucasmarkes/hairline";+import { TABLE } from "../../../packages/hairline/src/intensity";+import { FIGURES, INTENSITY, OPTIONS } from "@/lib/figures";+import { llms, scale } from "@/lib/llms";+import { tiny } from "@/lib/size";+import { PASTE, install, snippet } from "@/lib/snippets";-/** The docs are generated from the package, and these check that nothing was written by hand around it. */+/** The docs describe the package, and these check that nothing was written by hand around it. */-describe("the props tables", () => {- it("have one figure per entry of ranges, in the same order", () => {- expect(FIGURES.map((f) => f.id)).toEqual(Object.keys(ranges));- });+/* a key added to or taken from HairlineOptions fails the typecheck here, before the table can drift */+const KEYS = { intensity: true, theme: true, label: true, onRead: true } satisfies Record<keyof HairlineOptions, true>;- it.each(FIGURES)("$name's first row is its numeric option, with the package's default and bounds", (doc) => {- const range = (ranges[doc.id] as Record<string, { min: number; max: number; default: number }>)[doc.option];- const [row] = rows(doc);- expect(range).toBeDefined();- expect(row.name).toBe(doc.option);- expect(row.type).toBe("number");- expect(row.default).toBe(String(range.default));- expect(row.description).toContain(String(range.min));- expect(row.description).toContain(String(range.max));+describe("the figures", () => {+ it("are the package's six, each with a function and a component", () => {+ expect(FIGURES.map((f) => f.id).sort()).toEqual(Object.keys(figures).sort());+ for (const doc of FIGURES) expect(components).toHaveProperty(doc.name);});- it("list Riffle's two other options and nobody else's", () => {- expect(rows(FIGURES[0]).map((r) => r.name)).toEqual(["stagger", "bands", "labels"]);- for (const doc of FIGURES.slice(1)) expect(rows(doc)).toHaveLength(1);+ it("copy the package's intensity table exactly", () => {+ expect(INTENSITY).toEqual(TABLE);});+});- it("list the shared options", () => {- expect(SHARED.map((r) => r.name)).toEqual(["theme", "label", "onRead"]);+describe("the options table", () => {+ it("has the four keys of HairlineOptions, in that order", () => {+ expect(OPTIONS.map((r) => r.name)).toEqual(Object.keys(KEYS));});- it("write a range the way a person would", () => {- expect(span(ranges.riffle.stagger)).toBe("0 to 90 ms");- expect(span(ranges.slow.rate)).toBe("0.05× to 0.6×");- expect(span(ranges.exploded.gap)).toBe("12 to 40 units");+ it("gives intensity's default as 0.5", () => {+ expect(OPTIONS[0]).toMatchObject({ name: "intensity", type: "number", default: "0.5" });});});-describe("the snippets", () => {- it.each(FIGURES)("name an export that exists: $name", (doc) => {- expect(components).toHaveProperty(doc.name);- expect(figures).toHaveProperty(doc.id);- expect(react(doc, 7)).toContain(`<${doc.name} ${doc.option}={7}`);- expect(vanilla(doc, 7)).toContain(`${doc.id}(document.getElementById("figure")!, { ${doc.option}: 7 })`);+describe("the inspector's snippet", () => {+ it("is the bare component at the defaults", () => {+ expect(snippet("Terrain", { intensity: 0.5, theme: "auto" })).toContain("<Terrain />");+ });++ it("leaves out an intensity that reads as 0.5 at the slider's precision", () => {+ expect(snippet("Terrain", { intensity: 0.1 + 0.4, theme: "auto" })).toContain("<Terrain />");+ expect(snippet("Terrain", { intensity: 0.5000001, theme: "auto" })).toContain("<Terrain />");+ });++ it("shows an intensity of 0, which is not the default", () => {+ expect(snippet("Riffle", { intensity: 0, theme: "auto" })).toContain("<Riffle intensity={0} />");+ });++ it("shows what differs, intensity first, at two decimals", () => {+ expect(snippet("Slow", { intensity: 0.1 + 0.2, theme: "dark" })).toContain('<Slow intensity={0.3} theme="dark" />');+ expect(snippet("Slow", { intensity: 0.55, theme: "light" })).toContain('<Slow intensity={0.55} theme="light" />');+ expect(snippet("Slow", { intensity: 1, theme: "auto" })).toContain("<Slow intensity={1} />");});- it("install from the address the site is built for", () => {+ it("imports what it renders", () => {+ expect(snippet("Exploded", { intensity: 0.5, theme: "auto" })).toMatch(/^import \{ Exploded \} from "@lucasmarkes\/hairline\/react";/);+ });+});++describe("the install commands", () => {+ it("put npm first and install from the address the site is built for", () => {const commands = install("https://example.test");- expect(commands.map((c) => c.label)).toEqual(["pnpm", "npm", "yarn", "bun", "shadcn"]);+ expect(commands.map((c) => c.label)).toEqual(["npm", "pnpm", "yarn", "bun", "shadcn"]);+ expect(commands[0].code).toBe("npm i @lucasmarkes/hairline");expect(commands[4].code).toBe("npx shadcn@latest add https://example.test/r/hairline.json");});+});- it("cover the five frameworks", () => {- expect(FRAMEWORKS.map((f) => f.label)).toEqual(["Next.js", "Vue", "Svelte", "Astro", "CDN"]);+describe("the quickstart", () => {+ it("pastes React, Vanilla, CDN and CSS, and none of them sets an option the package dropped", () => {+ expect(PASTE.map((p) => p.label)).toEqual(["React", "Vanilla", "CDN", "CSS"]);+ for (const p of PASTE) expect(p.code).not.toMatch(/stagger|radius|afterglow|coast|bands|labels|ranges|className/);+ });++ it("sets all six theme properties in the CSS tab", () => {+ const css = PASTE[3].code;+ for (const key of ["plate", "hi", "edge", "mid", "lo", "stroke"]) expect(css).toContain(`--hairline-${key}:`);+ });+});++describe("the Tiny card", () => {+ it("is the gzip size of the vanilla entry, to a tenth of a kB", () => {+ const bytes = gzipSync(readFileSync(new URL("../../../packages/hairline/dist/index.js", import.meta.url))).length;+ expect(tiny()).toBe(`${(bytes / 1000).toFixed(1)} kB`);+ expect(tiny()).toMatch(/^\d+\.\d kB$/);});});describe("/llms.txt", () => {const text = llms("https://example.test");- it.each(FIGURES)("documents $name with its range and both snippets", (doc) => {+ it.each(FIGURES)("names $name with its row of the intensity table", (doc) => {expect(text).toContain(`### ${doc.name}`);- expect(text).toContain(span(doc.range));- expect(text).toContain(react(doc, doc.range.default).trimEnd());- expect(text).toContain(vanilla(doc, doc.range.default).trimEnd());+ expect(text).toContain(doc.stronger);+ expect(text).toContain(scale(doc.id, doc.parameter));+ for (const n of INTENSITY[doc.id]) expect(scale(doc.id, doc.parameter)).toContain(String(n));});- it("names every theme property and the registry item", () => {+ it("documents the four options, every theme property and the registry item", () => {+ for (const row of OPTIONS) expect(text).toContain(`- \`${row.name}\``);for (const key of ["plate", "hi", "edge", "mid", "lo", "stroke"]) expect(text).toContain(`--hairline-${key}`);expect(text).toContain("https://example.test/r/hairline.json");});+ it("mentions no option the package dropped", () => {+ expect(text).not.toMatch(/stagger=|radius=|\bbands\b|\blabels\b|\branges\b/);+ });+it("has no hole in it", () => {// outside the code blocks, where `undefined` is a word TypeScript uses- const prose = text.replace(/```[\s\S]*?```/g, "");+ const prose = text.replace(/```[\s\S]*?```/g, "").replace(/`undefined`/g, "");expect(prose).not.toMatch(/undefined|NaN|\[object/);});});