Isometric line figures that answer the pointer. For React and for anything with a DOM.
Site: a figures page shelves every figure by what it draws, and each one opens large with its code
Lucas Marquesf523c9e3c93d
diff --git a/apps/site/app/docs/sections.tsx b/apps/site/app/docs/sections.tsxindex 6bc96ae..3663320 100644--- a/apps/site/app/docs/sections.tsx+++ b/apps/site/app/docs/sections.tsx@@ -122,7 +122,7 @@ export function Reference({ css }: { css: string }) {</tbody></table></div>- <a className="doc-more" href="/#try">Try them on the home page →</a>+ <a className="doc-more" href="/figures">Try each one on the figures page →</a></Section><Section id="theme"><p className="doc-p">diff --git a/apps/site/app/figures/page.tsx b/apps/site/app/figures/page.tsxnew file mode 100644index 0000000..14eb6bb--- /dev/null+++ b/apps/site/app/figures/page.tsx@@ -0,0 +1,49 @@+import type { Metadata } from "next";+import type { CSSProperties } from "react";+import { Catalogue } from "@/components/catalogue";+import { Footer, Topbar } from "@/components/chrome";+import { tally } from "@/lib/catalogue";+import { FIGURES, LINKS, type FigureId } from "@/lib/figures";+import { highlight } from "@/lib/highlight";+import { share } from "@/lib/share";+import { paste } from "@/lib/snippets";++/** A block's place in the header's entrance. */+const at = (i: number) => ({ "--i": i }) as CSSProperties;++const LEDE = `${tally()}, grouped by what they draw. Each answers the pointer and takes the same four options. Pick one to see it large and copy its code.`;++export const metadata: Metadata = share("/figures", "Figures", LEDE);++/**+ * /figures: every figure on its shelf. A Server Component, so each drawn figure's code is highlighted at build, three+ * ways, and the catalogue shows it in the drawer.+ */+export default async function Figures() {+ const code = Object.fromEntries(+ await Promise.all(+ FIGURES.map(async (f) => [f.id, await Promise.all(paste(f.name, f.id).map(async (q) => ({ label: q.label, file: q.file, html: await highlight(q.code, q.lang) })))] as const),+ ),+ ) as Record<FigureId, { label: string; file: string; html: string }[]>;++ return (+ <>+ <Topbar />+ <Catalogue+ code={code}+ header={+ <header className="hero-rise">+ <h1 className="col-h1" style={at(0)}>Every figure, by what it <em>draws</em>.</h1>+ <p className="col-lede" style={at(1)}>{LEDE}</p>+ </header>+ }+ end={+ <p className="col-end">+ Missing a figure, a variation, or a whole shelf? <a className="doc-more" href={`${LINKS.github}/issues`}>Ask for it on GitHub</a>. The ones most asked for are drawn first.+ </p>+ }+ />+ <Footer />+ </>+ );+}diff --git a/apps/site/app/globals.css b/apps/site/app/globals.cssindex 4a1a6ee..396cd9b 100644--- a/apps/site/app/globals.css+++ b/apps/site/app/globals.css@@ -66,8 +66,10 @@ a.topbar-link::after { content: ""; position: absolute; inset: -5px 0; }footer a { position: relative; text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 4px; transition: text-decoration-color 150ms ease; }@media (hover: hover) { footer a:hover { text-decoration-color: currentColor; } }footer a::after { content: ""; position: absolute; inset: -12px -8px; }-/* under 360px the name and the first link would run together: the version, the item least needed there, goes */-@media (max-width: 359px) { .topbar [data-version] { display: none; } }+/* under 400px the name and the first link would run together: the version, the item least needed there, goes; under+ 360px the links also draw closer, each 7px clear of its neighbours */+@media (max-width: 399px) { .topbar [data-version] { display: none; } }+@media (max-width: 359px) { .topbar-link { padding: 0 7px; } .topbar nav { margin-right: -7px; } }.btn {display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px;@@ -420,3 +422,97 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }column less its sides up to 640px, a 5:4 stage, and the 148px of controls and lines under it, which wrap onto morelines in a column narrower than 360px. */.example-frame { display: block; width: 100%; height: calc(min(100cqw - 32px, 640px) * 0.8 + 148px + 48px + max(0px, 392px - 100cqw) * 0.75); border: 0; }++/* /figures. The shelves are a filter: from 1100px a list by the column's left edge, sticky inside the page's grid so it+ stops where the column ends and never runs over the footer; below that the docs' strip under the top bar. The list's+ marks sit on the line the name in the top bar starts on, as the docs rail's do: the rows' inner padding hangs out+ past that line, and only the plate is drawn there. The shelves' grids take the 760px beside it, starting 260px in,+ where the docs' column starts. */+.figs { max-width: 1080px; margin: 0 auto; padding: 56px var(--gutter) 96px; font-size: 14px; line-height: 1.6; }+.figs > * { min-width: 0; }+.figs-main { max-width: 760px; margin: 0 auto; }+.figs header > .col-h1:first-child { margin-top: 0; }+.shelves { display: none; }+.shelf-list { position: relative; display: grid; gap: 2px; margin: 0 -10px; isolation: isolate; }+.shelf { position: relative; display: flex; align-items: center; gap: 10px; width: 100%; height: 34px; padding: 0 10px; border-radius: 9px; font-size: 13px; text-align: left; color: var(--color-muted); transition: color 200ms ease; -webkit-tap-highlight-color: transparent; }+.shelf svg, .figs-pill svg { flex: none; color: var(--gc); filter: grayscale(1); opacity: 0.45; transition: filter 240ms ease, opacity 240ms ease; }+.shelf-n { margin-left: auto; font: 400 11.5px/1 var(--font-mono); color: var(--color-faint); font-variant-numeric: tabular-nums; transition: color 200ms ease; }+.shelf[aria-pressed="true"] { color: var(--color-ink); }+.shelf[aria-pressed="true"] .shelf-n { color: var(--color-muted); }+:is(.shelf, .figs-pill)[aria-pressed="true"] svg { filter: none; opacity: 1; }+@media (hover: hover) { .shelf:hover { color: var(--color-ink); } .shelf:hover svg { filter: none; opacity: 1; } }+.shelf-plate { position: absolute; top: 0; left: 0; right: 0; z-index: -1; height: 34px; border-radius: 9px; background: var(--color-stone); opacity: 0; pointer-events: none; }+.shelf-list[data-on] .shelf-plate { opacity: 1; }+.shelf-list[data-live] .shelf-plate { transition: transform 320ms var(--ease-out), opacity 200ms ease; }+.figs-strip { padding-inline: max(calc(var(--gutter) - 10px), calc((100% - 760px) / 2 - 10px)); }+.figs-strip ul { gap: 4px; }+.figs-pill { gap: 7px; -webkit-tap-highlight-color: transparent; }+.shelf, .figs-pill, .fig-name { cursor: pointer; }+.figs-pill[aria-pressed="true"] { color: var(--color-ink); background: var(--color-stone); }+/* a change of shelf comes in as the header does, shorter: a rise out of a blur */+.figs-body[data-enter] > section { animation: fade 420ms var(--ease-out) both, unblur 320ms var(--ease-out) both, rise 260ms var(--ease-out) both; }+.figs-body[data-enter] > section:nth-child(2) { animation-delay: 40ms; }+.figs-body[data-enter] > section:nth-child(n + 3) { animation-delay: 80ms; }+.figs-head { align-items: baseline; gap: 10px; }+.figs-count { font: 400 12px/1 var(--font-mono); color: var(--color-faint); font-variant-numeric: tabular-nums; }+@media (min-width: 1100px) {+ .figs { display: grid; grid-template-columns: 200px minmax(0, 760px); column-gap: 60px; align-items: start; }+ .figs-main { margin: 0; }+ .shelves { display: block; position: sticky; top: calc(var(--topbar) + 56px); }+}++/* a tile: the figure live on its stage, its name under it */+.fig-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }+.fig-tile { position: relative; overflow: hidden; border-radius: 14px; background: #fff; box-shadow: inset 0 0 0 1px var(--color-stone), var(--lift); cursor: pointer; transition: box-shadow 180ms ease; }+@media (hover: hover) { .fig-tile:hover { box-shadow: inset 0 0 0 1px #ebebeb, 0 1px 2px #00000008, 0 12px 28px -18px #0000002b; } }+.fig-tile[data-picked] { box-shadow: inset 0 0 0 1.5px var(--color-ink), var(--lift); }+.fig-stage { position: relative; width: 100%; aspect-ratio: 5 / 4; --hairline-plate: #fff; }+.fig-stage > div { width: 100%; }+.fig-foot { display: flex; padding: 10px 14px 12px; border-top: 1px solid var(--color-line); }+.fig-name { position: relative; font-size: 13.5px; font-weight: 500; line-height: 1.4; text-align: left; }+.fig-name::after { content: ""; position: absolute; inset: -10px -14px -12px; }+.fig-tile[data-planned] .fig-name { color: var(--color-muted); }+.fig-ghost { display: block; width: 100%; height: 100%; }+.fig-ghost path { fill: none; stroke: #c9c9c9; stroke-width: 0.9; stroke-linejoin: round; }+.fig-ghost .fig-ghost-dash { stroke-dasharray: 3 4; }+.fig-ghost .fig-ghost-plate { fill: #fff; }++/* The drawer: a card fixed at the right under the top bar, a sheet from below on a phone. Its contents stay while it+ slides away and go once it is out of sight. */+.drawer { position: fixed; z-index: 20; inset: auto 0 0 0; max-height: 86vh; overflow-y: auto; overscroll-behavior: contain; padding: 18px var(--gutter) calc(24px + env(safe-area-inset-bottom, 0px)); background: #fff; border-radius: 18px 18px 0 0; box-shadow: var(--lift-lg), 0 0 0 1px var(--color-line); transform: translateY(102%); visibility: hidden; transition: transform 320ms var(--ease-out), visibility 0s 320ms; font-size: 14px; line-height: 1.6; }+/* hidden once it is out, or its shadow would show at the window's edge */+.drawer[data-open] { transform: none; visibility: visible; transition-delay: 0s; }+@media (min-width: 900px) { .drawer { inset: calc(var(--topbar) + 14px) 14px 14px auto; width: 360px; max-height: none; border-radius: 16px; padding: 18px 18px 22px; transform: translateX(calc(100% + 16px)); } }+@media (min-width: 1280px) { .drawer { right: max(14px, calc((100% - 1080px) / 2 - 376px + var(--gutter))); } }+.detail { display: grid; gap: 16px; }+.detail-h { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }+.detail-name { font-size: 16px; font-weight: 500; line-height: 1.3; letter-spacing: -0.01em; }+.detail-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 4px; font-size: 12.5px; color: var(--color-muted); }+.detail-shelf { display: inline-flex; align-items: center; gap: 6px; }+.detail-shelf svg { color: var(--gc); }+.detail-tag { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 6px; box-shadow: inset 0 0 0 1px #e5e5e5; font: 400 11px/1 var(--font-mono); letter-spacing: 0.04em; text-transform: uppercase; color: var(--color-faint); }+.detail-close { position: relative; flex: none; display: grid; place-items: center; width: 30px; height: 30px; margin: -4px -6px 0 0; border-radius: 50%; color: var(--color-muted); transition: color 150ms ease, background-color 150ms ease; }+.detail-close::after { content: ""; position: absolute; inset: -5px; }+@media (hover: hover) { .detail-close:hover { color: var(--color-ink); background: var(--color-stone); } }+.detail-stage { border-radius: 12px; box-shadow: inset 0 0 0 1px var(--color-stone); }+.detail-sum { font-size: 13.5px; line-height: 1.55; color: var(--color-muted); text-wrap: pretty; }+.detail-sum b, .detail-ask b { font-weight: 500; color: var(--color-ink); }+.detail-reads { font-size: 12.5px; color: var(--color-muted); }+.detail-reads b { font: 400 11.5px/1 var(--font-mono); letter-spacing: 0.02em; color: var(--color-ink); }+.detail-ask { display: grid; gap: 6px; padding: 14px 16px; border-radius: 12px; background: var(--color-stone); font-size: 13px; color: var(--color-muted); text-wrap: pretty; }+.detail-ask .doc-more { font-size: 13px; }+.drawer .code { background: #fff; box-shadow: var(--card); }+.drawer .code-bar { border-bottom-color: var(--color-line); }+.drawer .code-body { font-size: 12.5px; }+.slider { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; font: 400 12px/1 var(--font-mono); color: var(--color-muted); }+.slider input { width: 100%; height: 20px; background: none; -webkit-appearance: none; appearance: none; cursor: pointer; }+.slider input::-webkit-slider-runnable-track { height: 1.5px; border-radius: 1px; background: #e5e5e5; }+.slider input::-webkit-slider-thumb { width: 14px; height: 14px; margin-top: -6.25px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 1px var(--color-ink); -webkit-appearance: none; }+.slider input::-moz-range-track { height: 1.5px; background: #e5e5e5; }+.slider input::-moz-range-thumb { width: 12px; height: 12px; border: 1px solid var(--color-ink); border-radius: 50%; background: #fff; }+.slider input:focus-visible { outline: 2px solid var(--color-ink); outline-offset: 2px; border-radius: 4px; }+@media (prefers-reduced-motion: reduce) {+ .figs-body[data-enter] > section { animation: none; }+ .fig-tile, .shelf-list[data-live] .shelf-plate { transition: none; }+ .drawer { transition-duration: 0s; }+}diff --git a/apps/site/components/catalogue.tsx b/apps/site/components/catalogue.tsxnew file mode 100644index 0000000..d62bdc7--- /dev/null+++ b/apps/site/components/catalogue.tsx@@ -0,0 +1,365 @@+"use client";++import { useCallback, useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ReactNode } from "react";+import { Exploded, 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 };++type Filter = "all" | ShelfId;++const svg = (children: ReactNode) => (+ <svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">+ {children}+ </svg>+);++/** Each shelf's mark, drawn as the docs rail's are: a light fill under a line. */+const ICONS: Record<Filter, ReactNode> = {+ all: svg(+ <>+ <rect x="2" y="2" width="5" height="5" rx="1.5" fill="currentColor" fillOpacity=".2" />+ <rect x="9" y="2" width="5" height="5" rx="1.5" fill="currentColor" fillOpacity=".2" />+ <rect x="2" y="9" width="5" height="5" rx="1.5" fill="currentColor" fillOpacity=".2" />+ <rect x="9" y="9" width="5" height="5" rx="1.5" fill="currentColor" fillOpacity=".2" />+ </>,+ ),+ interfaces: svg(+ <>+ <rect x="1.75" y="2.75" width="12.5" height="10.5" rx="2.5" fill="currentColor" fillOpacity=".2" stroke="none" />+ <path d="M1.75 6h12.5" />+ </>,+ ),+ data: svg(+ <>+ <rect x="2" y="8" width="3" height="6" rx="1" fill="currentColor" fillOpacity=".2" />+ <rect x="6.5" y="4" width="3" height="10" rx="1" fill="currentColor" fillOpacity=".2" />+ <rect x="11" y="6" width="3" height="8" rx="1" fill="currentColor" fillOpacity=".2" />+ </>,+ ),+ machines: svg(+ <>+ <circle cx="8" cy="8" r="4.25" fill="currentColor" fillOpacity=".2" />+ <circle cx="8" cy="8" r="1.25" />+ <path d="M8 1.75v2M8 12.25v2M1.75 8h2M12.25 8h2" />+ </>,+ ),+ devices: svg(+ <>+ <rect x="4.75" y="1.75" width="6.5" height="12.5" rx="1.75" fill="currentColor" fillOpacity=".2" />+ <path d="M7 12h2" />+ </>,+ ),+ coding: svg(+ <>+ <rect x="1.75" y="2.75" width="12.5" height="10.5" rx="2.5" fill="currentColor" fillOpacity=".2" stroke="none" />+ <path d="M6 5c-1 0-1.25.5-1.25 1.25v.5C4.75 7.5 4.5 8 3.75 8c.75 0 1 .5 1 1.25v.5C4.75 10.5 5 11 6 11M10 5c1 0 1.25.5 1.25 1.25v.5c0 .75.25 1.25 1 1.25-.75 0-1 .5-1 1.25v.5c0 .75-.25 1.25-1.25 1.25" />+ </>,+ ),+ security: svg(+ <>+ <path d="M8 1.75 13 3.75v4.5c0 3-2.5 5-5 6-2.5-1-5-3-5-6v-4.5L8 1.75Z" fill="currentColor" fillOpacity=".2" />+ <path d="M6 8l1.5 1.5L10 6.5" />+ </>,+ ),+ connectivity: svg(+ <>+ <circle cx="4" cy="11.5" r="2.25" fill="currentColor" fillOpacity=".2" />+ <circle cx="12" cy="4.5" r="2.25" fill="currentColor" fillOpacity=".2" />+ <path d="m5.6 10 4.8-4.1" />+ </>,+ ),+};++/** The rows of the filter: All, then each shelf, each in its colour with how many figures it holds. */+const ROWS: { id: Filter; title: string; color: string; n: number }[] = [+ { id: "all", title: "All", color: "#0a0a0a", n: ENTRIES.length },+ ...SHELVES.map((s) => ({ id: s.id, title: s.title, color: s.color, n: s.figures.length })),+];++const SHELF_OF = new Map(SHELVES.flatMap((s) => s.figures.map((f) => [f.id, s] as const)));++const tint = (color: string) => ({ "--gc": color }) as CSSProperties;++/** The filter a hash names, a bare #shelf, or All. */+const fromHash = (hash: string): Filter => {+ const id = hash.slice(1);+ return SHELVES.some((s) => s.id === id) ? (id as ShelfId) : "all";+};++/** What stands in a planned figure's place: its plinth in outline, a figure not drawn yet. */+function Ghost() {+ return (+ <svg className="fig-ghost" viewBox="0 0 400 320" aria-hidden="true">+ <path className="fig-ghost-dash" d="M200 92 342 163 200 234 58 163Z" />+ <path className="fig-ghost-plate" d="M200 128 258 157 200 186 142 157Z" />+ <path d="M142 157v22l58 29v-22M258 157v22l-58 29" />+ <path className="fig-ghost-dash" d="M200 92v-22M342 163h22M58 163H36" />+ </svg>+ );+}++/**+ * The figures on their shelves. The shelves are a filter: All, the default, shows every shelf, and a shelf shows only+ * itself. The choice is kept in the address as a bare #shelf, which names no element, so a link opens on it without+ * the browser scrolling. From 1100px the filter is a list by the column's left edge, its marks on the line the name in+ * the top bar starts on, and a plate slides to the pressed row; below that it is a strip under the top bar.+ *+ * A tile shows its figure live. Picking one opens a drawer with the figure large, an intensity slider, what the figure+ * reads, and its code three ways, highlighted on the server. A planned figure has its outline instead, and a link to+ * ask for it. The header and the closing note come from the server, around the shelves.+ */+export function Catalogue({ code, header, end }: { code: Record<FigureId, Tab[]>; header: ReactNode; end: ReactNode }) {+ const [filter, setFilterState] = useState<Filter>("all");+ const [entered, setEntered] = useState(false);+ const [open, setOpen] = useState(false);+ const [entry, setEntry] = useState<Entry | null>(null);+ const [intensity, setIntensity] = useState(0.5);+ const [reads, setReads] = useState("");+ const [edges, setEdges] = useState({ start: false, end: false });+ const list = useRef<HTMLDivElement>(null);+ const plate = useRef<HTMLSpanElement>(null);+ const strip = useRef<HTMLDivElement>(null);+ const head = useRef<HTMLDivElement>(null);+ const close = useRef<HTMLButtonElement>(null);+ const opener = useRef<HTMLElement | null>(null);++ // the hash is read after mount, so the server's All and the first render agree+ useEffect(() => {+ const read = () => setFilterState(fromHash(window.location.hash));+ read();+ window.addEventListener("hashchange", read);+ return () => window.removeEventListener("hashchange", read);+ }, []);++ // the plate moves before paint, so it is never drawn under a row no longer pressed; the first time it lands in place+ useLayoutEffect(() => {+ const el = list.current;+ const place = () => {+ const row = el?.querySelector<HTMLElement>(`[data-filter="${filter}"]`);+ if (!el || !row || !plate.current) return;+ plate.current.style.transform = `translateY(${row.offsetTop}px)`;+ el.setAttribute("data-on", "");+ };+ place();+ if (el && !el.hasAttribute("data-live")) requestAnimationFrame(() => requestAnimationFrame(() => el.setAttribute("data-live", "")));+ window.addEventListener("resize", place);+ return () => window.removeEventListener("resize", place);+ }, [filter]);++ // brings the pressed pill into the strip by scrolling the strip alone+ useEffect(() => {+ const el = strip.current;+ const pill = el?.querySelector<HTMLElement>(`[data-filter="${filter}"]`);+ if (!el || !pill || !el.clientWidth) return;+ const pad = 24;+ const box = el.getBoundingClientRect();+ const at = pill.getBoundingClientRect();+ if (at.left - pad < box.left) el.scrollTo({ left: el.scrollLeft + at.left - pad - box.left });+ else if (at.right + pad > box.right) el.scrollTo({ left: el.scrollLeft + at.right + pad - box.right });+ }, [filter]);++ useEffect(() => {+ const el = strip.current;+ if (!el) return;+ const measure = () => setEdges({ start: el.scrollLeft > 1, end: el.scrollLeft + el.clientWidth < el.scrollWidth - 1 });+ measure();+ el.addEventListener("scroll", measure, { passive: true });+ const resize = new ResizeObserver(measure);+ resize.observe(el);+ return () => {+ el.removeEventListener("scroll", measure);+ resize.disconnect();+ };+ }, []);++ const setFilter = (id: Filter) => {+ if (id === filter) return;+ setFilterState(id);+ setEntered(true);+ try {+ history.replaceState(null, "", id === "all" ? location.pathname + location.search : `#${id}`);+ } catch {}+ // a pick made far down the page brings the shelves' top into view+ if (head.current && head.current.getBoundingClientRect().bottom < 0) {+ window.scrollTo({ top: 0, behavior: matchMedia("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth" });+ }+ };++ const pick = (f: Entry, from: HTMLElement | null) => {+ opener.current = from;+ if (entry?.id !== f.id) {+ setIntensity(0.5);+ setReads("");+ }+ setEntry(f);+ setOpen(true);+ };++ const shut = useCallback(() => {+ setOpen(false);+ const back = opener.current;+ if (back?.isConnected) back.focus({ preventScroll: true });+ }, []);++ useEffect(() => {+ if (!open) return;+ close.current?.focus({ preventScroll: true });+ const onKey = (event: KeyboardEvent) => {+ if (event.key === "Escape") shut();+ };+ document.addEventListener("keydown", onKey);+ return () => document.removeEventListener("keydown", onKey);+ }, [open, entry, shut]);++ const shown = filter === "all" ? SHELVES : SHELVES.filter((s) => s.id === filter);++ return (+ <>+ <nav aria-label="Shelves" className="doc-strip">+ <div ref={strip} className="doc-strip-scroll figs-strip" data-start={edges.start || undefined} data-end={edges.end || undefined}>+ <ul>+ {ROWS.map((r) => (+ <li key={r.id}>+ <button type="button" className="doc-link figs-pill" data-filter={r.id} aria-pressed={filter === r.id} style={tint(r.color)} onClick={() => setFilter(r.id)}>+ {ICONS[r.id]}+ {r.title}+ </button>+ </li>+ ))}+ </ul>+ </div>+ </nav>+ <main className="figs">+ <aside className="shelves">+ <div ref={list} role="group" aria-label="Shelves" className="shelf-list">+ <span ref={plate} className="shelf-plate" aria-hidden="true" />+ {ROWS.map((r) => (+ <button key={r.id} type="button" className="shelf" data-filter={r.id} aria-pressed={filter === r.id} style={tint(r.color)} onClick={() => setFilter(r.id)}>+ {ICONS[r.id]}+ <span>{r.title}</span>+ <span className="shelf-n">{r.n}</span>+ </button>+ ))}+ </div>+ </aside>+ <div className="figs-main">+ <div ref={head}>{header}</div>+ <div key={filter} className="figs-body" data-enter={entered ? "" : undefined}>+ {shown.map((s) => (+ <ShelfSection key={s.id} shelf={s} picked={open ? entry?.id : undefined} onPick={pick} />+ ))}+ </div>+ {/* wrapped, as the header is: an element from the server among this list's siblings warns for a key in dev */}+ <div>{end}</div>+ </div>+ </main>+ <aside+ id="figure-drawer"+ className="drawer"+ aria-labelledby={entry ? "figure-drawer-name" : undefined}+ inert={!open}+ data-open={open ? "" : undefined}+ onTransitionEnd={(event) => {+ if (event.target === event.currentTarget && event.propertyName === "visibility" && !open) setEntry(null);+ }}+ >+ {entry ? <Detail key={entry.id} entry={entry} code={entry.drawn ? code[entry.id] : undefined} intensity={intensity} setIntensity={setIntensity} reads={reads} setReads={setReads} closeRef={close} onClose={shut} /> : null}+ </aside>+ </>+ );+}++function ShelfSection({ shelf, picked, onPick }: { shelf: Shelf; picked?: string; onPick: (f: Entry, from: HTMLElement | null) => void }) {+ const drawn = shelf.figures.filter((f) => f.drawn).length;+ return (+ <section id={`shelf-${shelf.id}`} className="doc-section" style={tint(shelf.color)} aria-labelledby={`shelf-${shelf.id}-h`}>+ <div className="doc-head figs-head">+ <h2 id={`shelf-${shelf.id}-h`} className="doc-h2">{shelf.title}</h2>+ <span className="figs-count">+ {drawn} of {shelf.figures.length}+ <span className="sr-only"> drawn</span>+ </span>+ </div>+ <div className="fig-grid">+ {shelf.figures.map((f) => (+ <Tile key={f.id} entry={f} picked={picked === f.id} onPick={onPick} />+ ))}+ </div>+ </section>+ );+}++/**+ * One figure on its shelf. The whole tile takes a click, but the button is its name: the figure in the stage answers+ * the pointer and the keyboard itself, and Riffle's cards cannot sit inside a button.+ */+function Tile({ entry, picked, onPick }: { entry: Entry; picked: boolean; onPick: (f: Entry, from: HTMLElement | null) => void }) {+ const button = useRef<HTMLButtonElement>(null);+ const Figure = entry.drawn ? COMPONENTS[entry.id] : null;+ return (+ <div className="fig-tile" data-planned={entry.drawn ? undefined : ""} data-picked={picked ? "" : undefined} onClick={() => onPick(entry, button.current)}>+ <div className="fig-stage">{Figure ? <Figure /> : <Ghost />}</div>+ <div className="fig-foot">+ <button ref={button} type="button" className="fig-name" aria-label={entry.drawn ? undefined : `${entry.name}, planned`} aria-expanded={picked} aria-controls="figure-drawer" onClick={(event) => {+ event.stopPropagation();+ onPick(entry, button.current);+ }}>+ {entry.name}+ </button>+ </div>+ </div>+ );+}++function Detail({+ entry, code, intensity, setIntensity, reads, setReads, closeRef, onClose,+}: {+ entry: Entry; code?: Tab[]; intensity: number; setIntensity: (n: number) => void; reads: string; setReads: (s: string) => void;+ closeRef: React.RefObject<HTMLButtonElement | null>; onClose: () => void;+}) {+ const shelf = SHELF_OF.get(entry.id)!;+ const Figure = entry.drawn ? COMPONENTS[entry.id] : null;+ return (+ <div className="detail">+ <div className="detail-h">+ <div>+ <h2 id="figure-drawer-name" className="detail-name">{entry.name}</h2>+ <p className="detail-meta">+ <span className="detail-shelf" style={tint(shelf.color)}>{ICONS[shelf.id]}{shelf.title}</span>+ {entry.drawn ? null : <span className="detail-tag">planned</span>}+ </p>+ </div>+ <button ref={closeRef} type="button" className="detail-close" aria-label="Close" onClick={onClose}>+ <svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" aria-hidden="true">+ <path d="m4 4 8 8M12 4l-8 8" />+ </svg>+ </button>+ </div>+ <div className="fig-stage detail-stage">{Figure ? <Figure intensity={intensity} onRead={setReads} /> : <Ghost />}</div>+ <p className="detail-sum">+ {entry.summary} <b>Higher intensity:</b> {entry.stronger}+ </p>+ {Figure ? (+ <>+ <label className="slider">+ <span>intensity</span>+ <input type="range" min="0" max="1" step="0.01" value={intensity} onChange={(event) => setIntensity(Number(event.target.value))} />+ <span className="tabular-nums" aria-hidden="true">{intensity.toFixed(2)}</span>+ </label>+ <p className="detail-reads">+ reads <b aria-live="polite">{reads}</b>+ </p>+ {code ? <Tabs tabs={code} label={`${entry.name} code`} /> : null}+ </>+ ) : (+ <div className="detail-ask">+ <p><b>Not drawn yet.</b> This one is on the list. Ask for it, or for a variation, and it moves up.</p>+ <a className="doc-more" href={`${LINKS.github}/issues/new?title=${encodeURIComponent(`Figure: ${entry.name}`)}`}>Request on GitHub</a>+ </div>+ )}+ </div>+ );+}diff --git a/apps/site/components/chrome.tsx b/apps/site/components/chrome.tsxindex d827f04..9482d41 100644--- a/apps/site/components/chrome.tsx+++ b/apps/site/components/chrome.tsx@@ -9,12 +9,13 @@ export function GitHub() {);}-/** The bar on every page: the name home, the skill, the docs, the story, the version, GitHub. */+/** The bar on every page: the name home, the figures, the skill, the docs, the story, the version, GitHub. */export function Topbar() {return (<header className="topbar"><a href="/" className="text-[15px] font-medium tracking-[-0.02em]">hairline</a><nav className="flex items-center">+ <a className="topbar-link" href="/figures">Figures</a><a className="topbar-link" href="/skill">Skill</a><a className="topbar-link" href="/docs">Docs</a><a className="topbar-link" href="/inspo">Inspo</a>diff --git a/apps/site/lib/catalogue.ts b/apps/site/lib/catalogue.tsnew file mode 100644index 0000000..aff1785--- /dev/null+++ b/apps/site/lib/catalogue.ts@@ -0,0 +1,90 @@+import { FIGURES, type FigureId } from "./figures";++/**+ * /figures: every figure on its shelf, by what it draws. A drawn figure takes+ * its copy from FIGURES, the list the docs and /llms.txt read, so the three+ * never disagree. A planned one carries its own: it is a promise of a figure,+ * with no component behind it yet.+ */++export type ShelfId = "interfaces" | "data" | "machines" | "devices" | "coding" | "security" | "connectivity";++export type Entry = { id: string; name: string; summary: string; stronger: string } & ({ drawn: true; id: FigureId } | { drawn: false });++export type Shelf = { id: ShelfId; title: string; color: string; figures: Entry[] };++const drawn = (id: FigureId): Entry => {+ const { name, summary, stronger } = FIGURES.find((f) => f.id === id)!;+ return { id, name, summary, stronger, drawn: true };+};+const planned = (id: string, name: string, summary: string, stronger: string): Entry => ({ id, name, summary, stronger, drawn: false });++export const SHELVES: Shelf[] = [+ {+ id: "interfaces", title: "Interfaces", color: "#3b82f6", figures: [+ drawn("exploded"),+ drawn("riffle"),+ planned("keyboard", "Keyboard", "Sixty keys in a block. The key under the pointer sinks and its neighbours follow it down, less the further away.", "A wider patch of keys sinks."),+ ],+ },+ {+ id: "data", title: "Data", color: "#8b5cf6", figures: [+ drawn("terrain"),+ drawn("phosphor"),+ planned("funnel", "Funnel", "Three basins stepping down, water in each. The pointer picks a basin; its gate opens and the water drops to the next, staggered on down.", "The drop runs further down the flight."),+ ],+ },+ {+ id: "machines", title: "Machines", color: "#f59e0b", figures: [+ drawn("slow"),+ drawn("turntable"),+ planned("elevator", "Elevator", "Four floors with the shaft open and the car inside. The pointer's height picks the floor; the car travels there.", "The car travels faster between floors."),+ ],+ },+ {+ id: "devices", title: "Devices", color: "#10b981", figures: [+ 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("clock", "Clock", "A desk clock with its crown in view. The pointer turns the crown; the hands run and catch on the five-minute detents.", "The hands coast longer."),+ planned("cassette", "Cassette", "A tape with both reels in view, always turning. Hovering slows it enough to read the tape go by.", "Time slows down more."),+ ],+ },+ {+ id: "coding", title: "Coding", color: "#0ea5e9", figures: [+ planned("tape", "Tape", "A terminal as punched tape running through a reader. Hovering slows it; the hole under the pointer is lit.", "Time slows down more."),+ planned("cabinet", "Cabinet", "A rack of twelve blades, a few half out. The pointer's height pulls the nearest ones out, the farther the less.", "More blades come out."),+ planned("cards", "Cards", "A stack of punched cards in a hopper. The card under the pointer slides forward and its neighbours part.", "The part spreads further."),+ ],+ },+ {+ id: "security", title: "Security", color: "#ef4444", figures: [+ planned("vault", "Vault", "A vault door with a dial and three bolts. The pointer turns the dial; detents catch every ten, and on the combination the bolts draw back.", "The dial coasts longer."),+ planned("lockers", "Lockers", "A bank of twelve lockers, one ajar at rest. The locker under the pointer opens; the one at rest closes.", "The door opens wider."),+ planned("shutter", "Shutter", "A shopfront with a roller shutter. The pointer's height rolls the shutter up or down, slat after slat.", "The slats lag further behind each other."),+ ],+ },+ {+ id: "connectivity", title: "Connectivity", color: "#ec4899", figures: [+ planned("patch", "Patch", "A patch panel of twenty-four ports with cables. The cable under the pointer lifts and its neighbours lean away.", "The lean spreads further."),+ planned("dish", "Dish", "A parabolic dish on a two-axis gimbal. The pointer aims the dish; it follows on a spring.", "The dish swings further."),+ planned("train", "Train", "Five wagons coupled on a line. The pointer uncouples the one under it; the ones behind drift apart, staggered.", "The wagons drift further."),+ ],+ },+];++export const ENTRIES: Entry[] = SHELVES.flatMap((s) => s.figures);++const ONES = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"];+const TENS = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"];++/** A count as the page's prose writes it, "twenty-one", so the lede is read from the shelves and cannot fall behind them. Up to 99. */+export function spell(n: number): string {+ if (n < 20) return ONES[n];+ return TENS[Math.floor(n / 10)] + (n % 10 ? `-${ONES[n % 10]}` : "");+}++const cap = (s: string) => s[0].toUpperCase() + s.slice(1);++/** "Seven shelves, twenty-one figures" */+export function tally(): string {+ return `${cap(spell(SHELVES.length))} shelves, ${spell(ENTRIES.length)} figures`;+}diff --git a/apps/site/lib/share.ts b/apps/site/lib/share.tsindex 966a2a2..c730878 100644--- a/apps/site/lib/share.ts+++ b/apps/site/lib/share.ts@@ -5,7 +5,7 @@ import { LINKS } from "./figures";export const DESCRIPTION = "Six isometric line figures that answer the pointer. SVG, no dependencies, for React and for everything else.";/** The pages a reader can land on, in the top bar's order: the sitemap lists these. /og is left out, a picture to photograph. */-export const PAGES = ["/", "/docs", "/skill", "/inspo"] as const;+export const PAGES = ["/", "/figures", "/docs", "/skill", "/inspo"] as const;const NAME = "hairline";diff --git a/apps/site/lib/snippets.ts b/apps/site/lib/snippets.tsindex 6a054b0..6bb4996 100644--- a/apps/site/lib/snippets.ts+++ b/apps/site/lib/snippets.ts@@ -18,30 +18,37 @@ export function install(base: string): { label: string; code: string }[] {];}-export const REACT = `import { Terrain } from "${PACKAGE}/react";+/** A figure pasted in React, by its component's name: the docs show Terrain, /figures each figure in turn. */+export const reactFor = (name: string) => `import { ${name} } from "${PACKAGE}/react";export default function Page() {- return <Terrain />;+ return <${name} />;}`;-export const VANILLA = `import { terrain } from "${PACKAGE}";+/** The same in plain DOM, by the figure's function. */+export const vanillaFor = (id: string) => `import { ${id} } from "${PACKAGE}";-const figure = terrain(document.getElementById("figure")!);+const figure = ${id}(document.getElementById("figure")!);figure.update({ intensity: 0.8 });figure.destroy();`;-export const CDN = `<div id="figure" style="width: 400px"></div>+/** The same without a bundler. */+export const cdnFor = (id: string) => `<div id="figure" style="width: 400px"></div><script type="module">- import { terrain } from "https://esm.sh/${PACKAGE}";+ import { ${id} } from "https://esm.sh/${PACKAGE}";- terrain(document.getElementById("figure"));+ ${id}(document.getElementById("figure"));</script>`;+export const REACT = reactFor("Terrain");+export const VANILLA = vanillaFor("terrain");+export const CDN = cdnFor("terrain");+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 colourthe figure sits on: it hides what is drawn behind each plate. */@@ -51,11 +58,16 @@ ${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 },-];+export const QUICKSTART = paste("Terrain", "terrain");++/** One figure three ways, each under the file it goes in, as the quick start's tabs show it. */+export function paste(name: string, id: string): { label: string; lang: string; file: string; code: string }[] {+ return [+ { label: "React", lang: "tsx", file: "app/page.tsx", code: reactFor(name) },+ { label: "Vanilla", lang: "ts", file: "main.ts", code: vanillaFor(id) },+ { label: "CDN", lang: "html", file: "index.html", code: cdnFor(id) },+ ];+}/** The component's props, read from the options table so the two cannot drift. */export const REACT_SIGNATURE = `<Terraindiff --git a/apps/site/test/catalogue.test.ts b/apps/site/test/catalogue.test.tsnew file mode 100644index 0000000..5677795--- /dev/null+++ b/apps/site/test/catalogue.test.ts@@ -0,0 +1,37 @@+import { describe, expect, it } from "vitest";+import { ENTRIES, SHELVES, spell, tally } from "@/lib/catalogue";+import { FIGURES } from "@/lib/figures";+import { REACT, VANILLA, CDN, paste } from "@/lib/snippets";++describe("the catalogue", () => {+ it("shelves every drawn figure once, with the copy the docs use", () => {+ const drawn = ENTRIES.filter((e) => e.drawn);+ expect(drawn.map((e) => e.id).sort()).toEqual(FIGURES.map((f) => f.id).sort());+ for (const e of drawn) {+ const doc = FIGURES.find((f) => f.id === e.id)!;+ expect([e.name, e.summary, e.stronger]).toEqual([doc.name, doc.summary, doc.stronger]);+ }+ });++ it("names each figure once, on seven shelves of three", () => {+ expect(new Set(ENTRIES.map((e) => e.id)).size).toBe(ENTRIES.length);+ expect(new Set(ENTRIES.map((e) => e.name)).size).toBe(ENTRIES.length);+ expect(SHELVES.map((s) => s.figures.length)).toEqual([3, 3, 3, 3, 3, 3, 3]);+ });++ it("counts in words, read from the shelves", () => {+ expect([spell(7), spell(19), spell(20), spell(21), spell(40), spell(99)]).toEqual(["seven", "nineteen", "twenty", "twenty-one", "forty", "ninety-nine"]);+ expect(tally()).toBe("Seven shelves, twenty-one figures");+ });++ it("pastes each figure three ways, and the docs' Terrain is the same as before", () => {+ expect(paste("Terrain", "terrain").map((q) => q.code)).toEqual([REACT, VANILLA, CDN]);+ for (const f of FIGURES) {+ const [react, vanilla, cdn] = paste(f.name, f.id).map((q) => q.code);+ expect(react).toContain(`import { ${f.name} } from "@lucasmarkes/hairline/react"`);+ expect(react).toContain(`<${f.name} />`);+ expect(vanilla).toContain(`${f.id}(document.getElementById("figure")!)`);+ expect(cdn).toContain(`import { ${f.id} } from "https://esm.sh/@lucasmarkes/hairline"`);+ }+ });+});diff --git a/apps/site/test/figures.spec.ts b/apps/site/test/figures.spec.tsnew file mode 100644index 0000000..99bbc91--- /dev/null+++ b/apps/site/test/figures.spec.ts@@ -0,0 +1,161 @@+import { expect, test, type Page } from "@playwright/test";++const SHELVES = ["Interfaces", "Data", "Machines", "Devices", "Coding", "Security", "Connectivity"];++function watch(page: Page): string[] {+ const noise: string[] = [];+ page.on("console", (m) => {+ // Vercel Analytics' script exists only on Vercel+ if (m.location().url.includes("/_vercel/")) return;+ if (m.type() === "error" || m.type() === "warning") noise.push(`${m.type()}: ${m.text()}`);+ });+ page.on("pageerror", (e) => noise.push(`pageerror: ${e}`));+ return noise;+}++const tiles = (page: Page) => page.locator(".fig-tile");+const shelf = (page: Page, name: string) => page.locator(".shelves .shelf", { hasText: name });++test("/figures prerenders six empty boxes among twenty-one 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(6);+ expect(html.match(/class="fig-tile"/g)).toHaveLength(21);+ expect(html.match(/class="fig-tile" data-planned=""/g)).toHaveLength(15);++ const noise = watch(page);+ await page.goto("/figures");+ await expect(tiles(page)).toHaveCount(21);+ await expect(page.locator(".fig-tile [data-hairline] > svg")).toHaveCount(6);+ await expect(page.locator(".fig-tile .fig-ghost")).toHaveCount(15);+ 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("Keyboard, planned");+ expect(noise).toEqual([]);+});++test("the shelves filter: All is pressed at first, a shelf shows only itself and names itself in the address", async ({ page }) => {+ await page.goto("/figures");+ await expect(shelf(page, "All")).toHaveAttribute("aria-pressed", "true");+ await expect(page.locator(".shelves .shelf-n")).toHaveText(["21", "3", "3", "3", "3", "3", "3", "3"]);++ await shelf(page, "Machines").click();+ await expect(shelf(page, "Machines")).toHaveAttribute("aria-pressed", "true");+ await expect(shelf(page, "All")).toHaveAttribute("aria-pressed", "false");+ await expect(page.locator(".doc-section h2")).toHaveText(["Machines"]);+ await expect(tiles(page)).toHaveCount(3);+ await expect(page.locator(".fig-tile [data-hairline] > svg")).toHaveCount(2);+ expect(new URL(page.url()).hash).toBe("#machines");+ // the plate sits under the pressed row+ await expect.poll(() => page.evaluate(() => {+ const plate = document.querySelector(".shelf-plate")!.getBoundingClientRect();+ const row = document.querySelector('.shelf[aria-pressed="true"]')!.getBoundingClientRect();+ return Math.abs(plate.top - row.top);+ })).toBeLessThan(1);++ await shelf(page, "All").click();+ await expect(tiles(page)).toHaveCount(21);+ expect(new URL(page.url()).hash).toBe("");+});++test("a link to a shelf opens on it, without scrolling", async ({ page }) => {+ await page.goto("/figures#security");+ await expect(page.locator(".doc-section h2")).toHaveText(["Security"]);+ await expect(shelf(page, "Security")).toHaveAttribute("aria-pressed", "true");+ expect(await page.evaluate(() => window.scrollY)).toBe(0);+});++test("the shelves' marks sit on the name in the top bar, and the shelves start where the docs' column does", async ({ page }) => {+ for (const width of [1100, 1280, 1600]) {+ await page.setViewportSize({ width, height: 900 });+ await page.goto("/figures");+ const at = await page.evaluate(() => {+ const left = (el: Element | null) => el!.getBoundingClientRect().left;+ return { mark: left(document.querySelector(".shelves .shelf svg")), name: left(document.querySelector(".topbar > a")), h1: left(document.querySelector("h1")) };+ });+ expect(Math.abs(at.mark - at.name), `${width}`).toBeLessThan(0.5);+ expect(Math.abs(at.h1 - at.name - 260), `${width}`).toBeLessThan(0.5);+ }+ await page.goto("/docs");+ const docs = await page.evaluate(() => document.querySelector("h1")!.getBoundingClientRect().left);+ await page.goto("/figures");+ expect(await page.evaluate(() => document.querySelector("h1")!.getBoundingClientRect().left)).toBeCloseTo(docs, 0);+});++test("picking a figure opens the drawer: the figure large, the slider, what it reads, its code; Escape closes it", async ({ page, context }) => {+ await context.grantPermissions(["clipboard-read", "clipboard-write"]);+ const noise = watch(page);+ await page.goto("/figures");+ const drawer = page.locator("#figure-drawer");+ await expect(drawer).not.toHaveAttribute("data-open");++ const name = page.locator(".fig-name", { hasText: "Terrain" });+ await page.locator(".fig-tile", { has: name }).locator(".fig-stage").click();+ await expect(drawer).toHaveAttribute("data-open", "");+ await expect(name).toHaveAttribute("aria-expanded", "true");+ await expect(drawer.locator("h2")).toHaveText("Terrain");+ await expect(drawer.locator(".detail-shelf")).toHaveText("Data");+ await expect(drawer.locator(".detail-close")).toBeFocused();+ await expect(drawer.locator("[data-hairline] > svg")).toHaveCount(1);+ await expect(drawer.locator(".detail-sum")).toContainText("Higher intensity: A wider area rises.");+ await expect(drawer.locator(".detail-reads b")).not.toBeEmpty();++ const slider = drawer.locator('input[type="range"]');+ await slider.fill("0.9");+ await expect(drawer.locator(".slider")).toContainText("0.90");++ await expect(drawer.locator("[role=tab]")).toHaveText(["React", "Vanilla", "CDN"]);+ await expect(drawer.locator(".code-body")).toContainText('import { Terrain } from "@lucasmarkes/hairline/react"');+ await drawer.locator("[role=tab]", { hasText: "Vanilla" }).click();+ await expect(drawer.locator(".code-body")).toContainText("terrain(document.getElementById");+ await drawer.locator(".icopy").click();+ expect(await page.evaluate(() => navigator.clipboard.readText())).toContain('import { terrain } from "@lucasmarkes/hairline"');++ await page.keyboard.press("Escape");+ await expect(drawer).not.toHaveAttribute("data-open");+ await expect(name).toBeFocused();+ await expect(name).toHaveAttribute("aria-expanded", "false");+ // the contents go once it is out of sight+ await expect(drawer.locator(".detail")).toHaveCount(0);+ expect(noise).toEqual([]);+});++test("a planned figure's drawer has its outline and a link to ask for it, and no code", async ({ page }) => {+ await page.goto("/figures");+ await page.locator(".fig-name", { hasText: "Vault" }).click();+ const drawer = page.locator("#figure-drawer");+ await expect(drawer).toHaveAttribute("data-open", "");+ await expect(drawer.locator(".detail-tag")).toHaveText("planned");+ await expect(drawer.locator(".fig-ghost")).toHaveCount(1);+ await expect(drawer.locator(".code, input[type=range]")).toHaveCount(0);+ await expect(drawer.getByRole("link", { name: "Request on GitHub" })).toHaveAttribute("href", "https://github.com/lucasmarkes/hairline/issues/new?title=Figure%3A%20Vault");+ await drawer.locator(".detail-close").click();+ await expect(drawer).not.toHaveAttribute("data-open");+});++test("on a phone the shelves are a strip under the top bar, and nothing scrolls sideways", async ({ page }) => {+ for (const width of [414, 390, 360, 320]) {+ await page.setViewportSize({ width, height: 800 });+ await page.goto("/figures");+ await expect(page.locator(".shelves")).toBeHidden();+ await expect(page.locator(".figs-pill")).toHaveCount(8);+ expect(await page.evaluate(() => document.documentElement.scrollWidth), `${width}`).toBeLessThanOrEqual(width);+ // the top bar's links stay inside it+ const right = await page.evaluate(() => document.querySelector(".topbar nav")!.getBoundingClientRect().right);+ expect(right).toBeLessThanOrEqual(width);+ // with Figures first, the name still stands clear of the links: the version goes under 400px+ const names = await page.evaluate(() => {+ const text = (el: Element) => { const r = document.createRange(); r.selectNodeContents(el); return r.getBoundingClientRect(); };+ return text(document.querySelector(".topbar nav > a")!).left - text(document.querySelector(".topbar > a")!).right;+ });+ expect(names, `${width}`).toBeGreaterThanOrEqual(20);++ await page.locator(".figs-pill", { hasText: "Connectivity" }).click();+ await expect(page.locator(".doc-section h2")).toHaveText(["Connectivity"]);+ expect(new URL(page.url()).hash).toBe("#connectivity");+ await page.locator(".fig-name", { hasText: "Dish" }).click();+ const box = await page.locator("#figure-drawer").boundingBox();+ expect(box!.x).toBe(0);+ expect(box!.width).toBe(width);+ }+});diff --git a/apps/site/test/site.spec.ts b/apps/site/test/site.spec.tsindex d94839e..352e21b 100644--- a/apps/site/test/site.spec.ts+++ b/apps/site/test/site.spec.ts@@ -36,11 +36,12 @@ test("the home prerenders an empty box, then draws the reel's figure with a cleaexpect(noise).toEqual([]);});-test("the top bar holds the skill, the docs, the story, the version and GitHub, and no llms.txt button", async ({ page }) => {+test("the top bar holds the figures, the skill, the docs, the story, the version and GitHub, and no llms.txt button", async ({ page }) => {await page.goto("/");- await expect(page.locator(".topbar nav > *")).toHaveCount(5);- await expect(page.locator(".topbar nav > a").nth(0)).toHaveText("Skill");- await expect(page.locator(".topbar nav > a").nth(1)).toHaveText("Docs");+ await expect(page.locator(".topbar nav > *")).toHaveCount(6);+ await expect(page.locator(".topbar nav > a").nth(0)).toHaveText("Figures");+ await expect(page.locator(".topbar nav > a").nth(1)).toHaveText("Skill");+ await expect(page.locator(".topbar nav > a").nth(2)).toHaveText("Docs");await expect(page.locator(".topbar")).not.toContainText("llms.txt");});@@ -55,7 +56,7 @@ test("the top bar's links sit as one row: one height, one centre line, one type,const style = getComputedStyle(el);return { height: box.height, middle: box.top + box.height / 2, left: ink.left, right: ink.right, type: [style.fontSize, style.fontWeight, style.color, style.backgroundColor].join(" ") };}));- expect(items).toHaveLength(5);+ expect(items).toHaveLength(6);expect(new Set(items.map((i) => i.height)).size).toBe(1);for (const i of items) expect(Math.abs(i.middle - items[0].middle)).toBeLessThan(0.5);expect(new Set(items.map((i) => i.type)).size).toBe(1);@@ -286,6 +287,7 @@ 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", /^Six isometric line figures/],+ ["/figures", "Figures", /^Seven shelves, twenty-one figures, grouped by what they draw/],["/docs", "Docs", /^Six isometric line figures/],["/skill", "Make your own figure", /^hairline-create is a skill/],["/inspo", "How Hairline was made", /^A long brief/],@@ -304,13 +306,13 @@ test("a pasted link shows the page it leads to: each page's card has its own tit}});-test("robots.txt lets every crawler in and names the sitemap, which lists the four pages", async ({ request }) => {+test("robots.txt lets every crawler in and names the sitemap, which lists the five pages", async ({ request }) => {const robots = await (await request.get("/robots.txt")).text();expect(robots).toMatch(/^User-Agent: \*\nAllow: \/\n/);expect(robots).toContain(`Sitemap: ${BASE}/sitemap.xml`);const sitemap = await (await request.get("/sitemap.xml")).text();- expect([...sitemap.matchAll(/<loc>([^<]+)<\/loc>/g)].map((m) => m[1])).toEqual([BASE, `${BASE}/docs`, `${BASE}/skill`, `${BASE}/inspo`]);+ expect([...sitemap.matchAll(/<loc>([^<]+)<\/loc>/g)].map((m) => m[1])).toEqual([BASE, `${BASE}/figures`, `${BASE}/docs`, `${BASE}/skill`, `${BASE}/inspo`]);});test("the page fits a phone, with the longest install command, its buttons and the reel's ticks", async ({ page }) => {@@ -435,11 +437,11 @@ test("the docs fit a phone down to 320px: rows stack text first, and wide code a}});-test("the figures' link goes to the home's figure", async ({ page }) => {+test("the figures' link goes to the figures page", async ({ page }) => {await page.goto("/docs");- await page.getByRole("link", { name: "Try them on the home page →" }).click();- await expect(page).toHaveURL(/\/#try$/);- await expect(page.locator("#try [data-reel]")).toBeInViewport();+ await page.getByRole("link", { name: "Try each one on the figures page →" }).click();+ await expect(page).toHaveURL(/\/figures$/);+ await expect(page.getByRole("heading", { level: 1 })).toContainText("Every figure");});test("the sidebar's links land on their section under the top bar and mark it, and scrolling moves the mark", async ({ page }) => {