Isometric line figures that answer the pointer. For React and for anything with a DOM.
Docs: the sections, the quick start's three files, the two signatures and the intensity table's units come from lib, beside llms.txt
Lucas Marquesb4f251f41ca9
diff --git a/apps/site/lib/docs.ts b/apps/site/lib/docs.tsnew file mode 100644index 0000000..6823e7b--- /dev/null+++ b/apps/site/lib/docs.ts@@ -0,0 +1,20 @@+/**+ * The docs' sections, in page order. The sidebar and the page both map over+ * this list, so an anchor cannot exist on one side only.+ */++export type Group = "Getting started" | "API" | "Reference";++export type Section = { id: string; group: Group; title: string };++export const SECTIONS: Section[] = [+ { id: "install", group: "Getting started", title: "Install" },+ { id: "quick-start", group: "Getting started", title: "Quick start" },+ { id: "options", group: "Getting started", title: "Options" },+ { id: "react", group: "API", title: "React" },+ { id: "vanilla", group: "API", title: "Vanilla" },+ { id: "cdn", group: "API", title: "CDN" },+ { id: "figures", group: "Reference", title: "Figures" },+ { id: "theme", group: "Reference", title: "Theme" },+ { id: "accessibility", group: "Reference", title: "Accessibility" },+];diff --git a/apps/site/lib/figures.ts b/apps/site/lib/figures.tsindex 0b984de..422eb00 100644--- a/apps/site/lib/figures.ts+++ b/apps/site/lib/figures.ts@@ -74,6 +74,11 @@ export const INTENSITY: Record<FigureId, readonly [number, number, number]> = {turntable: [200, 650, 1500],};+/** A number with its unit, as the docs' table and /llms.txt write it: "40 ms", "0.2× normal speed". */+export function measure(value: number, unit: string): string {+ return `${value}${unit.startsWith("×") ? "" : " "}${unit}`;+}+export type Row = { name: string; type: string; default: string; description: string };/** The options every figure takes: the whole API, in the quickstart's table. */diff --git a/apps/site/lib/llms.ts b/apps/site/lib/llms.tsindex 09f3fcd..908cb02 100644--- a/apps/site/lib/llms.ts+++ b/apps/site/lib/llms.ts@@ -1,4 +1,4 @@-import { FIGURES, INTENSITY, LINKS, OPTIONS, THEME, type Row } from "./figures";+import { FIGURES, INTENSITY, LINKS, OPTIONS, THEME, measure, 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. */@@ -8,9 +8,8 @@ const fence = (lang: string, code: string) => "```" + lang + "\n" + code.trimEnd/** "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`;+ const [lo, mid, hi] = INTENSITY[id].map((n) => measure(n, parameter.unit));+ return `${parameter.name} ${lo} at 0, ${mid} at 0.5, ${hi} at 1`;}export function llms(base: string): string {diff --git a/apps/site/lib/snippets.ts b/apps/site/lib/snippets.tsindex 2c65330..cc5a3ab 100644--- a/apps/site/lib/snippets.ts+++ b/apps/site/lib/snippets.ts@@ -1,4 +1,4 @@-import { THEME } from "./figures";+import { OPTIONS, THEME } from "./figures";/*** Every piece of code the page shows, as plain text. The page highlights it;@@ -66,6 +66,26 @@ ${THEME.map((t) => ` ${t.property}: ${t.light};`).join("\n")}}`;+/** The quick start's tabs: the same figure three ways, each under the file it goes in. */+export const QUICKSTART: { label: string; lang: string; file: string; code: string }[] = [+ { label: "React", lang: "tsx", file: "app/page.tsx", code: REACT },+ { label: "Vanilla", lang: "ts", file: "main.ts", code: VANILLA },+ { label: "CDN", lang: "html", file: "index.html", code: CDN },+];++/** The component's props, read from the options table so the two cannot drift. */+export const REACT_SIGNATURE = `<Terrain+${OPTIONS.map((o) => ` ${o.name}?: ${o.type}`).join("\n")}+ {...divProps}+/>+`;++export const VANILLA_SIGNATURE = `terrain(element: HTMLElement, options?: HairlineOptions): {+ update(options: HairlineOptions): void+ destroy(): void+}+`;+/** The quickstart's second step. */export const PASTE: { label: string; lang: string; code: string }[] = [{ label: "React", lang: "tsx", code: REACT },diff --git a/apps/site/test/docs.test.ts b/apps/site/test/docs.test.tsindex f783f7c..2a53e61 100644--- a/apps/site/test/docs.test.ts+++ b/apps/site/test/docs.test.ts@@ -5,11 +5,12 @@ import * as components from "@lucasmarkes/hairline/react";import * as figures from "@lucasmarkes/hairline";import type { HairlineOptions } from "@lucasmarkes/hairline";import { TABLE } from "../../../packages/hairline/src/intensity";-import { FIGURES, INTENSITY, OPTIONS } from "@/lib/figures";+import { SECTIONS } from "@/lib/docs";+import { FIGURES, INTENSITY, OPTIONS, measure } from "@/lib/figures";import { llms, scale } from "@/lib/llms";import { tiny } from "@/lib/size";import { highlight } from "@/lib/highlight";-import { CDN, CSS, PASTE, REACT, VANILLA, install, snippet } from "@/lib/snippets";+import { CDN, CSS, QUICKSTART, REACT, REACT_SIGNATURE, VANILLA, VANILLA_SIGNATURE, install, snippet } from "@/lib/snippets";/** The docs describe the package, and these check that nothing was written by hand around it. */@@ -71,19 +72,42 @@ describe("the install commands", () => {});});-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/);+describe("the quick start", () => {+ it("pastes React, Vanilla and CDN, each under a file name, and none of them sets an option the package dropped", () => {+ expect(QUICKSTART.map((q) => [q.label, q.file])).toEqual([["React", "app/page.tsx"], ["Vanilla", "main.ts"], ["CDN", "index.html"]]);+ expect(QUICKSTART.map((q) => q.code)).toEqual([REACT, VANILLA, CDN]);+ for (const q of QUICKSTART) expect(q.code).not.toMatch(/stagger|radius|afterglow|coast|bands|labels|ranges|className/);});+});++describe("the theme's CSS", () => {+ it("sets all six theme properties", () => {+ for (const key of ["plate", "hi", "edge", "mid", "lo", "stroke"]) expect(CSS).toContain(`--hairline-${key}:`);+ });+});- 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 signatures", () => {+ it("list the component's four options with their types, read from the options table", () => {+ expect(REACT_SIGNATURE).toBe(`<Terrain+ intensity?: number+ theme?: "auto" | "light" | "dark"+ label?: string+ onRead?: (text: string) => void+ {...divProps}+/>+`);+ });++ it("give the function's handle its two methods", () => {+ expect(VANILLA_SIGNATURE).toBe(`terrain(element: HTMLElement, options?: HairlineOptions): {+ update(options: HairlineOptions): void+ destroy(): void+}+`);});});-describe("the Tiny card", () => {+describe("the Install note's size", () => {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`);@@ -91,6 +115,38 @@ describe("the Tiny card", () => {});});+describe("the docs' sections", () => {+ it("are nine, in three groups in order, with unique ids that work as fragments", () => {+ expect(SECTIONS.map((s) => s.id)).toEqual(["install", "quick-start", "options", "react", "vanilla", "cdn", "figures", "theme", "accessibility"]);+ expect(new Set(SECTIONS.map((s) => s.id)).size).toBe(9);+ for (const s of SECTIONS) expect(s.id).toMatch(/^[a-z-]+$/);+ expect(SECTIONS.map((s) => s.group)).toEqual([+ "Getting started", "Getting started", "Getting started",+ "API", "API", "API",+ "Reference", "Reference", "Reference",+ ]);+ });++ it("share their headings with /llms.txt", () => {+ const text = llms("https://example.test");+ for (const title of ["Install", "Options", "Figures", "Theme", "Accessibility"]) {+ expect(SECTIONS.map((s) => s.title)).toContain(title);+ expect(text).toContain(`\n## ${title}\n`);+ }+ });+});++describe("the intensity table", () => {+ it("writes each number with its unit, as /llms.txt does", () => {+ expect(measure(40, "ms")).toBe("40 ms");+ expect(measure(0.2, "× normal speed")).toBe("0.2× normal speed");+ for (const doc of FIGURES) {+ const [lo, mid, hi] = INTENSITY[doc.id].map((n) => measure(n, doc.parameter.unit));+ expect(scale(doc.id, doc.parameter)).toBe(`${doc.parameter.name} ${lo} at 0, ${mid} at 0.5, ${hi} at 1`);+ }+ });+});+describe("/llms.txt", () => {const text = llms("https://example.test");@@ -119,7 +175,7 @@ describe("/llms.txt", () => {});/** Every snippet the docs highlight, with its language. */-const SAMPLES: [code: string, lang: string][] = [[REACT, "tsx"], [VANILLA, "ts"], [CDN, "html"], [CSS, "css"]];+const SAMPLES: [code: string, lang: string][] = [[REACT, "tsx"], [VANILLA, "ts"], [CDN, "html"], [CSS, "css"], [REACT_SIGNATURE, "tsx"], [VANILLA_SIGNATURE, "ts"]];describe("highlighting", () => {it("colours tokens with the --code- variables only, and leaves the block one tab stop", async () => {