Isometric line figures that answer the pointer. For React and for anything with a DOM.
Home: the hero rises in a stagger and the figure stands on the page with one dock under it; the rest moves to /docs
Lucas Marquesc463aa7da4fb
diff --git a/apps/site/app/docs/page.tsx b/apps/site/app/docs/page.tsxnew file mode 100644index 0000000..8e0979b--- /dev/null+++ b/apps/site/app/docs/page.tsx@@ -0,0 +1,103 @@+import type { Metadata } from "next";+import type { ReactNode } from "react";+import { Exploded, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";+import { Footer, Topbar } from "@/components/chrome";+import { Install } from "@/components/install";+import { Tabs } from "@/components/tabs";+import { CARDS, FIGURES, OPTIONS } from "@/lib/figures";+import { highlight } from "@/lib/highlight";+import { tiny } from "@/lib/size";+import { PASTE, install } from "@/lib/snippets";++const SITE = process.env.NEXT_PUBLIC_SITE_URL!;+const SMALL = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable };++export const metadata: Metadata = { title: "Docs · hairline", alternates: { canonical: "/docs" } };++function Heading({ id, title, children }: { id: string; title: ReactNode; children?: ReactNode }) {+ return (+ <header className="mb-10 max-w-[56ch]">+ <h2 id={id} className="scroll-mt-20 text-[30px] font-medium leading-[1.1] tracking-[-0.03em] md:text-[36px]">{title}</h2>+ {children ? <p className="mt-3 text-[16px] leading-[1.55] text-muted">{children}</p> : null}+ </header>+ );+}++/**+ * The docs: install and paste, the options, and every figure small. A Server+ * Component, so each figure on it goes through server rendering and+ * hydration on every deploy, as on the home.+ */+export default async function Docs() {+ const commands = install(SITE);+ const paste = await Promise.all(PASTE.map(async (p) => ({ label: p.label, html: await highlight(p.code, p.lang) })));+ const size = tiny();++ return (+ <>+ <Topbar />+ <main className="mx-auto grid max-w-[1080px] gap-32 px-[clamp(18px,5vw,28px)] pb-24 pt-16 md:pt-24 [&>*]:min-w-0">+ <section aria-labelledby="quickstart">+ <h1 id="quickstart" className="mb-10 scroll-mt-20 text-[36px] font-medium leading-[1.05] tracking-[-0.035em] md:text-[44px]">Get started</h1>+ <ol className="grid gap-12">+ <li className="step">+ <h2 className="step-title"><span className="step-n">1</span>Install</h2>+ <div className="max-w-[460px]"><Install commands={commands} /></div>+ </li>+ <li className="step">+ <h2 className="step-title"><span className="step-n">2</span>Paste</h2>+ <p className="mb-4 max-w-[60ch] text-[14px] leading-[1.55] text-muted">+ A figure fills its parent’s width at a 5:4 aspect ratio. The React entry is a client module, so a Server Component can render it as it is.+ </p>+ <Tabs tabs={paste} label="Paste" />+ </li>+ </ol>+ <div className="mt-14 overflow-x-auto">+ <table className="props" data-options>+ <thead>+ <tr><th>Option</th><th>Type</th><th>Default</th><th>What it does</th></tr>+ </thead>+ <tbody>+ {OPTIONS.map((row) => (+ <tr key={row.name}><td>{row.name}</td><td>{row.type}</td><td>{row.default}</td><td>{row.description}</td></tr>+ ))}+ </tbody>+ </table>+ </div>+ </section>++ <section aria-labelledby="figures">+ <Heading id="figures" title="One prop, six figures">+ Every figure takes <code className="font-mono text-[14px] text-ink">intensity</code>, from 0 to 1. Here is what it turns up.+ </Heading>+ <ul className="grid">+ {FIGURES.map((doc) => {+ const Small = SMALL[doc.id];+ return (+ <li key={doc.id} className="figure-row" data-row={doc.id}>+ <div>+ <h3 className="text-[20px] font-medium leading-none tracking-[-0.02em]">{doc.name}</h3>+ <p className="mt-3 text-[16px] leading-[1.5]">{doc.stronger}</p>+ <p className="mt-1 max-w-[52ch] text-[14px] leading-[1.55] text-muted">{doc.summary}</p>+ </div>+ <div className="tile w-full max-w-[240px] justify-self-end"><Small /></div>+ </li>+ );+ })}+ </ul>+ </section>++ <section aria-label="Why" className="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">+ {CARDS.map((card) => (+ <div key={card.title} className="card" data-card={card.title}>+ <h3 className="text-[15px] font-medium">{card.title}</h3>+ {card.title === "Tiny" ? <p className="mt-3 text-[30px] font-medium leading-none tracking-[-0.03em] tabular-nums" data-size>{size}</p> : null}+ <p className="mt-2 text-[14px] leading-[1.5] text-muted">{card.body}</p>+ </div>+ ))}+ </section>+ </main>+ <Footer />+ </>+ );+}diff --git a/apps/site/app/globals.css b/apps/site/app/globals.cssindex 71f0f2e..5222dde 100644--- a/apps/site/app/globals.css+++ b/apps/site/app/globals.css@@ -1,21 +1,23 @@@import "tailwindcss";-/* After cuelume: a light canvas, white panels with a soft lift, one serif accent, mono for code. */+/* Black and white: a white canvas, chroma-free greys, one serif word in the hero, mono only for code. */@theme {--font-sans: var(--font-geist-sans), ui-sans-serif, system-ui, sans-serif;--font-mono: var(--font-geist-mono), ui-monospace, "SF Mono", Menlo, monospace;--font-serif: var(--font-instrument-serif), Georgia, serif;- --color-canvas: #fbfaf9;- --color-stone: #f2f0ed;- --color-ink: #121212;- --color-muted: #7e7e7d;- --color-faint: #a9a7a3;- --color-line: rgba(18, 18, 18, 0.07);+ --color-canvas: #fff;+ --color-stone: #f4f4f4;+ --color-ink: #0a0a0a;+ --color-muted: #737373;+ --color-faint: #a3a3a3;+ --color-line: rgba(0, 0, 0, 0.07);}:root {- --lift: 0 1px 2px #12121208, 0 10px 28px -16px #12121224;- --lift-lg: 0 1px 2px #12121208, 0 2px 6px #12121208, 0 32px 64px -34px #12121238;+ --lift: 0 1px 2px #00000008, 0 10px 28px -16px #00000024;+ --lift-lg: 0 1px 2px #00000008, 0 2px 6px #00000008, 0 32px 64px -34px #00000038;+ --ease-out: cubic-bezier(0.23, 1, 0.32, 1);+ --ease-icon: cubic-bezier(0.2, 0, 0, 1);}html { color-scheme: light; scroll-behavior: smooth; }@@ -36,7 +38,9 @@ em { font-style: italic; }background: #fff; box-shadow: inset 0 0 0 1px var(--color-stone), var(--lift);}.btn-primary { background: var(--color-ink); color: #fff; box-shadow: var(--lift); }-.btn-quiet { height: 30px; padding: 0 10px; font: 500 12px/1 var(--font-mono); color: var(--color-muted); }+.btn-quiet { height: 30px; padding: 0 10px; font-size: 13px; line-height: 1; color: var(--color-muted); }+.press { transition: transform 160ms var(--ease-out); }+.press:active { transform: scale(0.96); }.btn-quiet:hover, .icon-link:hover { color: var(--color-ink); }.icon-link { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; color: var(--color-muted); }@@ -51,34 +55,15 @@ em { font-style: italic; }.pill-manager { border-radius: 5px; padding: 3px 4px; margin: -3px -4px; color: var(--color-ink); text-decoration: underline dotted var(--color-faint); text-underline-offset: 4px; cursor: pointer; }.pill-manager:hover { background: var(--color-stone); }-.copy { flex: none; border-radius: 7px; padding: 7px 10px; font: 500 12px/1 var(--font-mono); color: var(--color-muted); }-.copy:hover { color: var(--color-ink); background: var(--color-stone); }--.panel { overflow: hidden; border-radius: 16px; background: var(--color-stone); box-shadow: inset 0 0 0 1px var(--color-stone), var(--lift-lg); }-.stage { position: relative; display: grid; place-items: center; padding: clamp(12px, 4vw, 40px); background: #fff; }-.stage > [data-hairline] { width: 100%; max-width: 520px; }-.stage[data-dark] { background: #08090a; }-.cap { position: absolute; left: 18px; bottom: 14px; font: 500 11px/1 var(--font-mono); letter-spacing: 0.02em; color: var(--hairline-edge, #a4a4ac); font-variant-numeric: tabular-nums; pointer-events: none; }-.stage[data-dark] .cap { color: #5b5d64; }--.label { display: block; margin-bottom: 10px; font: 500 11px/1 var(--font-mono); letter-spacing: 0.04em; text-transform: uppercase; color: var(--color-muted); }-.chip { border-radius: 8px; padding: 7px 11px; font-size: 13px; color: var(--color-muted); box-shadow: inset 0 0 0 1px var(--color-stone); }-.chip:hover { color: var(--color-ink); }-.chip[aria-pressed="true"] { background: var(--color-ink); color: #fff; box-shadow: none; }-.segmented { display: inline-flex; padding: 2px; border-radius: 9px; background: var(--color-stone); }-.segmented button { border-radius: 7px; padding: 6px 12px; font-size: 13px; color: var(--color-muted); }-.segmented button[aria-pressed="true"] { background: #fff; color: var(--color-ink); box-shadow: var(--lift); }-.slider { width: 100%; height: 18px; appearance: none; background: transparent; cursor: pointer; }-.slider::-webkit-slider-runnable-track { height: 2px; border-radius: 1px; background: rgba(18, 18, 18, 0.16); }-.slider::-webkit-slider-thumb { appearance: none; width: 16px; height: 16px; margin-top: -7px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 1px rgba(18, 18, 18, 0.2), var(--lift); }-.slider::-moz-range-track { height: 2px; border-radius: 1px; background: rgba(18, 18, 18, 0.16); }-.slider::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 0 0 1px rgba(18, 18, 18, 0.2); }+.slider::-webkit-slider-runnable-track { height: 2px; border-radius: 1px; background: rgba(0, 0, 0, 0.16); }+.slider::-webkit-slider-thumb { appearance: none; width: 16px; height: 16px; margin-top: -7px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2), var(--lift); }+.slider::-moz-range-track { height: 2px; border-radius: 1px; background: rgba(0, 0, 0, 0.16); }+.slider::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2); }.code { overflow: hidden; border-radius: 12px; background: #fff; box-shadow: inset 0 0 0 1px var(--color-stone); }-.panel .code { border-radius: 0; box-shadow: none; }-.code-bar { display: flex; align-items: center; justify-content: space-between; padding: 6px 6px 6px 8px; border-bottom: 1px solid var(--color-line); }-.code-tab { border-radius: 7px; padding: 6px 10px; font: 500 12px/1 var(--font-mono); color: var(--color-muted); }+.code-bar { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 4px 8px; border-bottom: 1px solid var(--color-line); }+.code-tab { border-radius: 7px; padding: 6px 10px; font-size: 13px; font-weight: 500; line-height: 1; color: var(--color-muted); }.code-tab[aria-selected="true"] { background: var(--color-stone); color: var(--color-ink); }.code-tab:hover { color: var(--color-ink); }.code-panel { margin: 0; overflow-x: auto; padding: 16px 18px; font: 400 13px/1.65 var(--font-mono); }@@ -92,14 +77,81 @@ em { font-style: italic; }.step { min-width: 0; }.step-title { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; font-size: 17px; font-weight: 500; }-.step-n { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--color-ink); color: #fff; font: 500 12px/1 var(--font-mono); }+.step-n { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--color-ink); color: #fff; font-size: 12px; font-weight: 500; line-height: 1; font-variant-numeric: tabular-nums; }.props { width: 100%; border-collapse: collapse; font-size: 13px; }-.props th { padding: 8px 14px 8px 0; text-align: left; font: 500 11px/1 var(--font-mono); letter-spacing: 0.04em; text-transform: uppercase; color: var(--color-muted); }+.props th { padding: 8px 14px 8px 0; text-align: left; font-size: 13px; font-weight: 500; color: var(--color-muted); }.props td { padding: 12px 14px 12px 0; vertical-align: top; border-top: 1px solid var(--color-line); line-height: 1.5; }.props td:nth-child(-n + 3) { font-family: var(--font-mono); white-space: nowrap; }.props td:nth-child(2), .props td:nth-child(3) { color: var(--color-muted); }+/* The hero: each block rises out of a blur, one after another. */+.hero-title { max-width: 16ch; font-size: 44px; font-weight: 500; line-height: 1.02; letter-spacing: -0.045em; text-wrap: balance; }+.hero-title em { font-family: var(--font-serif); font-size: 1.08em; font-weight: 400; letter-spacing: -0.02em; }+.hero-sub { margin-top: 20px; max-width: 44ch; font-size: 18px; line-height: 1.5; color: var(--color-muted); text-wrap: pretty; }+.hero-install { margin-top: 36px; width: 100%; max-width: 460px; }+.hero-actions { margin-top: 20px; display: flex; gap: 8px; }+@media (min-width: 768px) { .hero-title { font-size: 64px; } }++.hero-rise > * { animation: rise 750ms var(--ease-out) both; animation-delay: calc(var(--i) * 90ms + 60ms); }+.enter { animation: rise 850ms var(--ease-out) both; animation-delay: var(--d, 0ms); }+.enter-hint { animation: hint 220ms var(--ease-out) both; }+@keyframes rise { from { opacity: 0; transform: translateY(12px); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }+@keyframes hint { from { opacity: 0; transform: translateY(2px); filter: blur(2px); } to { opacity: 1; transform: none; filter: none; } }+@keyframes fade { from { opacity: 0; } to { opacity: 1; } }++/* A single choice whose highlight slides to the checked option. */+.slide { position: relative; display: flex; isolation: isolate; }+.slide-hl { position: absolute; top: 0; left: 0; z-index: -1; pointer-events: none; }+.slide[data-ready] .slide-hl { transition: transform 240ms var(--ease-out), width 240ms var(--ease-out), height 240ms var(--ease-out); }+.slide-item { position: relative; display: inline-flex; flex: none; align-items: center; justify-content: center; white-space: nowrap; color: var(--color-muted); transition: color 150ms ease; }+.slide-item:hover, .slide-item[aria-checked="true"] { color: var(--color-ink); }++/* Copy as an icon: the clipboard blurs and shrinks away as the check grows in. */+.icopy { position: relative; flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; color: var(--color-muted); transition: color 150ms ease, background-color 150ms ease, transform 160ms var(--ease-out); }+.icopy::after { content: ""; position: absolute; inset: -2px; }+.icopy:hover { color: var(--color-ink); background: var(--color-stone); }+.icopy:active { transform: scale(0.96); }+.icopy[data-copied] { color: var(--color-ink); }+.icopy svg { grid-area: 1 / 1; transition: opacity 200ms var(--ease-icon), transform 200ms var(--ease-icon), filter 200ms var(--ease-icon); }+.icopy-b, .icopy[data-copied] .icopy-a { opacity: 0; transform: scale(0.25); filter: blur(4px); }+.icopy[data-copied] .icopy-b { opacity: 1; transform: none; filter: none; }++/* The inspector's snippet, in greys: only the tag name carries weight. */+.p-code { flex: 1; min-width: 0; margin: 0; overflow-x: auto; font: 400 13px/1.65 var(--font-mono); color: var(--color-ink); white-space: pre; }+.t-kw { color: var(--color-muted); }+.t-tag { font-weight: 500; }+.t-attr { color: #525252; }++/* The inspector: the figure on the page itself, one dock under it for every control. */+.s-inspector { display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; }+.s-stage { position: relative; display: grid; place-items: center; width: 100%; max-width: 760px; padding: clamp(8px, 4vw, 40px); border-radius: 28px; transition: background-color 300ms ease; }+.s-stage > [data-hairline] { width: 100%; max-width: 560px; }+.s-stage[data-dark] { background: #08090a; }+.s-dock { margin-top: 8px; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; max-width: 100%; padding: 6px; border-radius: 16px; background: #fff; box-shadow: inset 0 0 0 1px var(--color-stone), var(--lift-lg); }+.s-figures { min-width: 0; max-width: 100%; overflow-x: auto; scrollbar-width: none; }+.s-figures::-webkit-scrollbar { display: none; }+.s-figures .slide-item { height: 36px; padding: 0 12px; font-size: 14px; }+.s-figures .slide-hl { border-radius: 10px; background: var(--color-stone); }+.s-row { display: flex; align-items: center; gap: 12px; padding-left: 12px; border-left: 1px solid var(--color-line); }+.s-range { display: flex; align-items: center; gap: 10px; width: 230px; }+.s-range-label { font-size: 13px; color: var(--color-muted); }+.s-range .slider { flex: 1; min-width: 0; }+.s-value { width: 4ch; font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; text-align: right; }+.s-themes { padding: 2px; border-radius: 10px; background: var(--color-stone); }+.s-themes .slide-item { width: 36px; height: 36px; }+.s-themes .slide-hl { border-radius: 8px; background: #fff; box-shadow: var(--lift); }+.s-hint { margin-top: 14px; min-height: 1.5em; font-size: 13px; line-height: 1.5; color: var(--color-muted); text-align: center; text-wrap: balance; }+.s-code { margin-top: 28px; display: flex; align-items: flex-start; gap: 8px; width: 100%; max-width: 560px; padding: 6px 6px 6px 0; border-radius: 14px; background: #fff; box-shadow: inset 0 0 0 1px var(--color-stone), var(--lift); }+.s-code .p-code { padding: 10px 0 10px 18px; }++@media (max-width: 760px) {+ .s-dock { width: 100%; }+ .s-figures { flex: 1 1 100%; }+ .s-row { width: 100%; justify-content: space-between; padding: 6px 0 0 10px; border-left: 0; border-top: 1px solid var(--color-line); }+ .s-range { flex: 1; width: auto; }+}+:is(button, a, input, .code-panel):focus-visible { outline: 1.5px solid var(--color-ink); outline-offset: 2px; }@media (max-width: 640px) {@@ -110,4 +162,9 @@ em { font-style: italic; }.props td { padding: 0; border: 0; }.props td:nth-child(4) { flex-basis: 100%; margin-top: 6px; }}-@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }+@media (prefers-reduced-motion: reduce) {+ html { scroll-behavior: auto; }+ .hero-rise > *, .enter, .enter-hint { animation-name: fade; }+ .slide[data-ready] .slide-hl { transition: none; }+ .icopy-b, .icopy[data-copied] .icopy-a { transform: none; filter: none; }+}diff --git a/apps/site/app/layout.tsx b/apps/site/app/layout.tsxindex 420fabe..5729373 100644--- a/apps/site/app/layout.tsx+++ b/apps/site/app/layout.tsx@@ -6,7 +6,7 @@ import { Instrument_Serif } from "next/font/google";import { Analytics } from "@vercel/analytics/next";import "./globals.css";-/** The headline's one serif word, and the figure names. */+/** The headline's one serif word. */const serif = Instrument_Serif({ weight: "400", style: ["normal", "italic"], subsets: ["latin"], variable: "--font-instrument-serif" });const SITE = process.env.NEXT_PUBLIC_SITE_URL!;diff --git a/apps/site/app/page.tsx b/apps/site/app/page.tsxindex 74b696d..b96e4f2 100644--- a/apps/site/app/page.tsx+++ b/apps/site/app/page.tsx@@ -1,146 +1,43 @@-import pkg from "@lucasmarkes/hairline/package.json";-import { Exploded, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";-import { CopyButton } from "@/components/copy";+import type { CSSProperties } from "react";+import { Footer, GitHub, Topbar } from "@/components/chrome";import { Inspector } from "@/components/inspector";import { Install } from "@/components/install";-import { Tabs } from "@/components/tabs";-import { CARDS, FIGURES, LINKS, OPTIONS } from "@/lib/figures";-import { highlight } from "@/lib/highlight";-import { tiny } from "@/lib/size";-import { PASTE, install } from "@/lib/snippets";+import { LINKS } from "@/lib/figures";+import { install } from "@/lib/snippets";const SITE = process.env.NEXT_PUBLIC_SITE_URL!;-const SMALL = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable };-function GitHub() {- return (- <svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" fill="currentColor">- <path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z" />- </svg>- );-}--function Heading({ id, title, children }: { id: string; title: React.ReactNode; children?: React.ReactNode }) {- return (- <header className="mb-10 max-w-[56ch]">- <h2 id={id} className="scroll-mt-20 text-[30px] font-medium leading-[1.1] tracking-[-0.03em] md:text-[36px]">{title}</h2>- {children ? <p className="mt-3 text-[16px] leading-[1.55] text-muted">{children}</p> : null}- </header>- );-}+/** Where a block falls in the hero's stagger. */+const at = (i: number) => ({ "--i": i }) as CSSProperties;/**- * The whole site. A Server Component: every figure on it is the package's- * React component rendered from here, so every deploy runs them through- * server rendering and hydration.+ * The home: the pitch, then one figure to play with. A Server Component, so+ * the figure is the package's React component rendered from here, and every+ * deploy runs it through server rendering and hydration. The rest lives on+ * /docs.*/-export default async function Page() {- const commands = install(SITE);- const paste = await Promise.all(PASTE.map(async (p) => ({ label: p.label, html: await highlight(p.code, p.lang) })));- const size = tiny();-+export default function Page() {return (<>- <header className="topbar">- <a href="#top" className="text-[15px] font-medium tracking-[-0.02em]">hairline</a>- <nav className="flex items-center gap-1">- <span className="px-2 font-mono text-[12px] text-muted" data-version>v{pkg.version}</span>- <a className="icon-link" href={LINKS.github} aria-label="GitHub"><GitHub /></a>- <CopyButton text={`${SITE}/llms.txt`} open="/llms.txt" label="llms.txt" className="btn btn-quiet" />- </nav>- </header>-- <main id="top" className="mx-auto grid max-w-[1080px] gap-32 px-[clamp(18px,5vw,28px)] pb-24 pt-16 md:pt-24 [&>*]:min-w-0">- <section aria-labelledby="hairline" className="grid grid-cols-[minmax(0,1fr)] justify-items-center text-center">- <h1 id="hairline" className="max-w-[16ch] text-[44px] font-medium leading-[1.02] tracking-[-0.045em] md:text-[64px]">- Line drawings that <em className="font-serif text-[1.08em] font-normal tracking-[-0.02em]">answer</em> the pointer.+ <Topbar />+ <main className="mx-auto grid max-w-[1080px] gap-10 px-[clamp(18px,5vw,28px)] pb-24 pt-16 md:gap-12 md:pt-24 [&>*]:min-w-0">+ <section aria-labelledby="hairline" className="hero-rise grid grid-cols-[minmax(0,1fr)] justify-items-center text-center">+ <h1 id="hairline" className="hero-title" style={at(0)}>+ Line drawings that <em>answer</em> the pointer.</h1>- <p className="mt-5 max-w-[44ch] text-[18px] leading-[1.5] text-muted">- Six isometric figures for the web. SVG, no dependencies, React or plain DOM.- </p>- <div className="mt-9 w-full max-w-[460px]"><Install commands={commands} /></div>- <div className="mt-5 flex gap-2">- <a className="btn btn-primary" href="#quickstart">Get started</a>- <a className="btn" href={LINKS.github}><GitHub /> GitHub</a>+ <p className="hero-sub" style={at(1)}>Six isometric figures for the web. SVG, no dependencies, React or plain DOM.</p>+ <div className="hero-install" style={at(2)}><Install commands={install(SITE)} /></div>+ <div className="hero-actions" style={at(3)}>+ <a className="btn btn-primary press" href="/docs">Get started</a>+ <a className="btn press" href={LINKS.github}><GitHub /> GitHub</a></div></section><section aria-label="Try it"><Inspector /></section>-- <section aria-labelledby="figures">- <Heading id="figures" title="One prop, six figures">- Every figure takes <code className="font-mono text-[14px] text-ink">intensity</code>, from 0 to 1. Here is what it turns up.- </Heading>- <ul className="grid">- {FIGURES.map((doc) => {- const Small = SMALL[doc.id];- return (- <li key={doc.id} className="figure-row" data-row={doc.id}>- <div>- <h3 className="font-serif text-[30px] italic leading-none">{doc.name}</h3>- <p className="mt-3 text-[16px] leading-[1.5]">{doc.stronger}</p>- <p className="mt-1 max-w-[52ch] text-[14px] leading-[1.55] text-muted">{doc.summary}</p>- </div>- <div className="tile w-full max-w-[240px] justify-self-end"><Small /></div>- </li>- );- })}- </ul>- </section>-- <section aria-label="Why" className="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">- {CARDS.map((card) => (- <div key={card.title} className="card" data-card={card.title}>- <h3 className="text-[15px] font-medium">{card.title}</h3>- {card.title === "Tiny" ? <p className="mt-3 font-serif text-[34px] leading-none" data-size>{size}</p> : null}- <p className="mt-2 text-[14px] leading-[1.5] text-muted">{card.body}</p>- </div>- ))}- </section>-- <section aria-labelledby="quickstart">- <Heading id="quickstart" title={<>Two <em className="font-serif font-normal">steps</em></>} />- <ol className="grid gap-12">- <li className="step">- <h3 className="step-title"><span className="step-n">1</span>Install</h3>- <div className="max-w-[460px]"><Install commands={commands} /></div>- </li>- <li className="step">- <h3 className="step-title"><span className="step-n">2</span>Paste</h3>- <p className="mb-4 max-w-[60ch] text-[14px] leading-[1.55] text-muted">- A figure fills its parent’s width at a 5:4 aspect ratio. The React entry is a client module, so a Server Component can render it as it is.- </p>- <Tabs tabs={paste} label="Paste" />- </li>- </ol>- <div className="mt-14 overflow-x-auto">- <table className="props" data-options>- <thead>- <tr><th>Option</th><th>Type</th><th>Default</th><th>What it does</th></tr>- </thead>- <tbody>- {OPTIONS.map((row) => (- <tr key={row.name}><td>{row.name}</td><td>{row.type}</td><td>{row.default}</td><td>{row.description}</td></tr>- ))}- </tbody>- </table>- </div>- </section>-- <footer className="flex flex-wrap items-baseline gap-x-6 gap-y-3 border-t border-line pt-8 text-[13px] text-muted">- <p>- MIT licensed. Built by <a className="text-ink" href={LINKS.author}>Lucas Marques</a>. After <a className="text-ink" href={LINKS.linear}>Linear</a>’s figures.- </p>- <nav className="flex gap-5 md:ml-auto">- <a className="text-ink" href={LINKS.npm}>npm</a>- <a className="text-ink" href={LINKS.github}>GitHub</a>- <a className="text-ink" href="/llms.txt">llms.txt</a>- <a className="text-ink" href={LINKS.x}>X</a>- </nav>- </footer></main>+ <Footer /></>);}diff --git a/apps/site/components/chrome.tsx b/apps/site/components/chrome.tsxnew file mode 100644index 0000000..d62f399--- /dev/null+++ b/apps/site/components/chrome.tsx@@ -0,0 +1,44 @@+import pkg from "@lucasmarkes/hairline/package.json";+import { LINKS } from "@/lib/figures";+import { CopyButton } from "./copy";++const SITE = process.env.NEXT_PUBLIC_SITE_URL!;++export function GitHub() {+ return (+ <svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" fill="currentColor">+ <path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z" />+ </svg>+ );+}++/** The bar on every page: the name home, the docs, the version, GitHub, llms.txt. */+export function Topbar() {+ return (+ <header className="topbar">+ <a href="/" className="text-[15px] font-medium tracking-[-0.02em]">hairline</a>+ <nav className="flex items-center gap-1">+ <a className="btn-quiet inline-flex items-center" href="/docs">Docs</a>+ <span className="px-2 text-[13px] text-muted tabular-nums" data-version>v{pkg.version}</span>+ <a className="icon-link" href={LINKS.github} aria-label="GitHub"><GitHub /></a>+ <CopyButton text={`${SITE}/llms.txt`} open="/llms.txt" label="llms.txt" className="btn btn-quiet" />+ </nav>+ </header>+ );+}++export function Footer() {+ return (+ <footer className="mx-auto flex max-w-[1080px] flex-wrap items-baseline gap-x-6 gap-y-3 border-t border-line px-[clamp(18px,5vw,28px)] py-8 text-[13px] text-muted">+ <p>+ MIT licensed. Built by <a className="text-ink" href={LINKS.author}>Lucas Marques</a>.+ </p>+ <nav className="flex gap-5 md:ml-auto">+ <a className="text-ink" href={LINKS.x}>X</a>+ <a className="text-ink" href={LINKS.github}>GitHub</a>+ <a className="text-ink" href={LINKS.npm}>npm</a>+ <a className="text-ink" href="/llms.txt">llms.txt</a>+ </nav>+ </footer>+ );+}diff --git a/apps/site/components/code.tsx b/apps/site/components/code.tsxnew file mode 100644index 0000000..c8008b9--- /dev/null+++ b/apps/site/components/code.tsx@@ -0,0 +1,22 @@+import type { ReactNode, RefObject } from "react";++const TOKEN = /(\bimport\b|\bfrom\b)|("[^"]*")|(<\/?)([A-Z]\w*)|(\w+)(?==)|(?<==)(\{[^}]*\})/g;++/** The inspector's snippet, coloured by hand: it only ever holds one import and one tag. */+export function Code({ text, codeRef, className = "" }: { text: string; codeRef?: RefObject<HTMLPreElement | null>; className?: string }) {+ const parts: ReactNode[] = [];+ const body = text.trimEnd();+ let last = 0;+ for (const m of body.matchAll(TOKEN)) {+ if (m.index > last) parts.push(body.slice(last, m.index));+ const k = parts.length;+ if (m[1]) parts.push(<span key={k} className="t-kw">{m[1]}</span>);+ else if (m[2]) parts.push(<span key={k} className="t-str">{m[2]}</span>);+ else if (m[4]) parts.push(<span key={k}>{m[3]}<span className="t-tag">{m[4]}</span></span>);+ else if (m[5]) parts.push(<span key={k} className="t-attr">{m[5]}</span>);+ else if (m[6]) parts.push(<span key={k} className="t-val">{m[6]}</span>);+ last = m.index + m[0].length;+ }+ parts.push(body.slice(last));+ return <pre ref={codeRef} className={`p-code ${className}`}>{parts}</pre>;+}diff --git a/apps/site/components/copy.tsx b/apps/site/components/copy.tsxindex 1a81f5b..1758906 100644--- a/apps/site/components/copy.tsx+++ b/apps/site/components/copy.tsx@@ -41,7 +41,7 @@ export function useCopy(): [copied: boolean, copy: (text: string, fallback?: Ele* at, or opens `open` for a button with no text of its own on the page. `text`* can be a function, read at the click, for text the button does not own.*/-export function CopyButton({ text, select, open, label = "Copy", className = "copy" }: { text: string | (() => string); select?: RefObject<Element | null>; open?: string; label?: string; className?: string }) {+export function CopyButton({ text, select, open, label = "Copy", className = "btn btn-quiet" }: { text: string | (() => string); select?: RefObject<Element | null>; open?: string; label?: string; className?: string }) {const [copied, copy] = useCopy();const click = async () => {if (!(await copy(typeof text === "function" ? text() : text, select?.current)) && open) window.location.assign(open);@@ -52,3 +52,24 @@ export function CopyButton({ text, select, open, label = "Copy", className = "co</button>);}++/**+ * Copy as an icon: the clipboard gives way to a check through scale, opacity+ * and blur, and back. Both icons stay in the DOM so the swap is a transition+ * either way, and interrupts cleanly on a second click.+ */+export function CopyIcon({ text, select, label = "Copy", className = "" }: { text: string | (() => string); select?: RefObject<Element | null>; label?: string; className?: string }) {+ const [copied, copy] = useCopy();+ return (+ <button type="button" className={`icopy ${className}`} data-copied={copied || undefined} aria-label={label} title={label} onClick={() => copy(typeof text === "function" ? text() : text, select?.current)}>+ <svg className="icopy-a" viewBox="0 0 16 16" width="15" height="15" aria-hidden="true" fill="none" stroke="currentColor" strokeWidth="1.3" strokeLinejoin="round">+ <rect x="5.25" y="5.25" width="8.5" height="8.5" rx="2" />+ <path d="M10.75 5.25V4.25a2 2 0 0 0-2-2h-4.5a2 2 0 0 0-2 2v4.5a2 2 0 0 0 2 2h1" />+ </svg>+ <svg className="icopy-b" viewBox="0 0 16 16" width="15" height="15" aria-hidden="true" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">+ <path d="M3.5 8.5l3 3 6-7" />+ </svg>+ <span className="sr-only" aria-live="polite">{copied ? "Copied" : ""}</span>+ </button>+ );+}diff --git a/apps/site/components/inspector.tsx b/apps/site/components/inspector.tsxindex f14127c..9c08ce9 100644--- a/apps/site/components/inspector.tsx+++ b/apps/site/components/inspector.tsx@@ -1,75 +1,65 @@"use client";-import { useId, useRef, useState } from "react";+import { useId, useRef, useState, type CSSProperties } from "react";import { Exploded, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";import { FIGURES, type FigureId } from "@/lib/figures";import { snippet, type Theme } from "@/lib/snippets";-import { CopyButton } from "./copy";+import { Code } from "./code";+import { CopyIcon } from "./copy";+import { Slide, type Option } from "./slide";const COMPONENTS = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable };-const THEMES: { value: Theme; label: string }[] = [- { value: "auto", label: "Auto" },- { value: "light", label: "Light" },- { value: "dark", label: "Dark" },+const FIGURE_OPTIONS: Option<FigureId>[] = FIGURES.map((f) => ({ value: f.id, label: f.name }));++const ICON = { width: 14, height: 14, viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: 1.3, "aria-hidden": true } as const;+const THEMES: Option<Theme>[] = [+ { value: "auto", name: "Auto", label: <svg {...ICON}><circle cx="8" cy="8" r="5.5" /><path d="M8 2.5v11a5.5 5.5 0 0 0 0-11z" fill="currentColor" stroke="none" /></svg> },+ { value: "light", name: "Light", label: <svg {...ICON} strokeLinecap="round"><circle cx="8" cy="8" r="2.75" /><path d="M8 1.75v1.5M8 12.75v1.5M1.75 8h1.5M12.75 8h1.5M3.6 3.6l1.05 1.05M11.35 11.35l1.05 1.05M3.6 12.4l1.05-1.05M11.35 4.65l1.05-1.05" /></svg> },+ { value: "dark", name: "Dark", label: <svg {...ICON}><path d="M13.25 9.6A5.5 5.5 0 0 1 6.4 2.75a5.5 5.5 0 1 0 6.85 6.85z" strokeLinejoin="round" /></svg> },];+/** A CSS custom property in a style object. */+const vars = (v: Record<string, string>) => v as CSSProperties;+/**- * One large figure and its three controls: which figure, how intense, which+ * One large figure standing on the page itself, with no card around it, and+ * one dock under it for every control: which figure, how intense, which* theme. The snippet under them is the code for what is on screen.*/export function Inspector() {const [id, setId] = useState<FigureId>("terrain");const [intensity, setIntensity] = useState(0.5);const [theme, setTheme] = useState<Theme>("auto");- const [read, setRead] = useState("");const slider = useId();const code = useRef<HTMLPreElement>(null);const doc = FIGURES.find((f) => f.id === id)!;const Figure = COMPONENTS[id];const text = snippet(doc.name, { intensity, theme });+ const dark = theme === "dark";return (- <div className="panel grid gap-px md:grid-cols-[3fr_2fr] [&>*]:min-w-0" data-inspector>- <div className="stage" data-figure={id} data-dark={theme === "dark" || undefined}>- <Figure key={id} intensity={intensity} theme={theme} onRead={setRead} />- <span className="cap" data-read aria-hidden="true">{read}</span>+ <div className="s-inspector" data-inspector>+ {/* off dark, the figure's plate is the page, so it stands without a box */}+ <div className="s-stage enter" style={vars({ "--d": "520ms", ...(dark ? {} : { "--hairline-plate": "var(--color-canvas)" }) })} data-figure={id} data-dark={dark || undefined}>+ <Figure key={id} intensity={intensity} theme={theme} /></div>- <div className="grid content-start gap-7 bg-white p-6">- <fieldset>- <legend className="label">Figure</legend>- <div className="flex flex-wrap gap-1.5">- {FIGURES.map((f) => (- <button key={f.id} type="button" className="chip" aria-pressed={f.id === id} onClick={() => { setId(f.id); setRead(""); }}>- {f.name}- </button>- ))}- </div>- </fieldset>- <div>- <div className="flex items-baseline justify-between">- <label htmlFor={slider} className="label">intensity</label>- <output htmlFor={slider} className="font-mono text-[12px] tabular-nums text-muted">{intensity.toFixed(2)}</output>++ <div className="s-dock enter" style={vars({ "--d": "640ms" })}>+ <Slide label="Figure" options={FIGURE_OPTIONS} value={id} onChange={setId} className="s-figures" />+ <div className="s-row">+ <div className="s-range">+ <label htmlFor={slider} className="s-range-label">Intensity</label>+ <input id={slider} type="range" className="slider" min={0} max={1} step={0.05} value={intensity} onChange={(event) => setIntensity(Number(event.target.value))} />+ <output htmlFor={slider} className="s-value">{intensity.toFixed(2)}</output></div>- <input id={slider} type="range" className="slider" min={0} max={1} step={0.05} value={intensity} onChange={(event) => setIntensity(Number(event.target.value))} />- <p className="mt-2 text-[13px] leading-[1.5] text-muted">{doc.stronger}</p>+ <Slide label="Theme" options={THEMES} value={theme} onChange={setTheme} className="s-themes" /></div>- <fieldset>- <legend className="label">theme</legend>- <div className="segmented">- {THEMES.map((t) => (- <button key={t.value} type="button" aria-pressed={t.value === theme} onClick={() => setTheme(t.value)}>- {t.label}- </button>- ))}- </div>- </fieldset></div>- <div className="code md:col-span-2" data-snippet>- <div className="code-bar">- <span className="code-tab" aria-selected="true">React</span>- <CopyButton text={text} select={code} />- </div>- <pre ref={code} className="code-panel">{text}</pre>+ <p key={id} className="s-hint enter-hint">{doc.stronger}</p>++ <div className="s-code enter" style={vars({ "--d": "760ms" })} data-snippet>+ <Code text={text} codeRef={code} />+ <CopyIcon text={text} select={code} label="Copy snippet" className="s-copy" /></div></div>);diff --git a/apps/site/components/install.tsx b/apps/site/components/install.tsxindex 8fdb2b1..952dc58 100644--- a/apps/site/components/install.tsx+++ b/apps/site/components/install.tsx@@ -1,11 +1,11 @@"use client";import { useEffect, useRef, useState } from "react";-import { CopyButton } from "./copy";+import { CopyIcon } from "./copy";/*** The install command in a pill. The command's first word is a button that- * moves to the next package manager; the copy button copies the whole line.+ * moves to the next package manager; the copy icon copies the whole line.* A line wider than the pill scrolls, fades at the edge while more of it is* hidden, and shows itself whole on hover.*/@@ -35,12 +35,12 @@ export function Install({ commands }: { commands: { label: string; code: string<div className="pill" data-install={label}><span aria-hidden="true" className="select-none text-faint">$</span><code ref={line} className="pill-line" title={code} data-more={more ? "" : undefined}>- <button type="button" className="pill-manager" onClick={() => setAt((at + 1) % commands.length)} aria-label={`${label}: switch to ${next}`} title={`Switch to ${next}`}>+ <button type="button" className="pill-manager" onClick={() => setAt((at + 1) % commands.length)} aria-label={`${head} (${label}): switch to ${next}`} title={`Switch to ${next}`}>{head}</button>{code.slice(head.length)}</code>- <CopyButton text={code} select={line} />+ <CopyIcon text={code} select={line} label="Copy install command" /></div>);}diff --git a/apps/site/components/slide.tsx b/apps/site/components/slide.tsxnew file mode 100644index 0000000..966f674--- /dev/null+++ b/apps/site/components/slide.tsx@@ -0,0 +1,59 @@+"use client";++import { useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent, type ReactNode } from "react";++export type Option<T extends string> = { value: T; label: ReactNode; name?: string };++/**+ * A single choice as a radio group, with a highlight that slides to the+ * checked option. The slide is turned on after the first paint, so the page+ * does not open with it moving. Arrow keys move the choice.+ */+export function Slide<T extends string>({ options, value, onChange, label, className = "" }: { options: Option<T>[]; value: T; onChange: (value: T) => void; label: string; className?: string }) {+ const group = useRef<HTMLDivElement>(null);+ const [box, setBox] = useState<{ x: number; y: number; w: number; h: number } | null>(null);+ const [ready, setReady] = useState(false);++ useLayoutEffect(() => {+ const root = group.current;+ if (!root) return;+ const measure = () => {+ const el = root.querySelector<HTMLElement>('[aria-checked="true"]');+ if (el) setBox({ x: el.offsetLeft, y: el.offsetTop, w: el.offsetWidth, h: el.offsetHeight });+ };+ measure();+ const resize = new ResizeObserver(measure);+ resize.observe(root);+ return () => resize.disconnect();+ }, [value]);++ useEffect(() => {+ let inner = 0;+ const outer = requestAnimationFrame(() => (inner = requestAnimationFrame(() => setReady(true))));+ return () => {+ cancelAnimationFrame(outer);+ cancelAnimationFrame(inner);+ };+ }, []);++ const onKeyDown = (event: KeyboardEvent) => {+ const step = event.key === "ArrowRight" || event.key === "ArrowDown" ? 1 : event.key === "ArrowLeft" || event.key === "ArrowUp" ? -1 : 0;+ if (!step) return;+ event.preventDefault();+ const at = options.findIndex((o) => o.value === value);+ const next = (at + step + options.length) % options.length;+ onChange(options[next].value);+ group.current?.querySelectorAll<HTMLButtonElement>("[role=radio]")[next]?.focus();+ };++ return (+ <div ref={group} role="radiogroup" aria-label={label} className={`slide ${className}`} data-ready={ready || undefined} onKeyDown={onKeyDown}>+ {box ? <span className="slide-hl" aria-hidden="true" style={{ width: box.w, height: box.h, transform: `translate(${box.x}px, ${box.y}px)` }} /> : null}+ {options.map((o) => (+ <button key={o.value} type="button" role="radio" aria-checked={o.value === value} aria-label={o.name} title={o.name} tabIndex={o.value === value ? 0 : -1} className="slide-item" onClick={() => onChange(o.value)}>+ {o.label}+ </button>+ ))}+ </div>+ );+}diff --git a/apps/site/components/tabs.tsx b/apps/site/components/tabs.tsxindex 03f631a..3c9f2e3 100644--- a/apps/site/components/tabs.tsx+++ b/apps/site/components/tabs.tsx@@ -1,11 +1,11 @@"use client";import { useId, useRef, useState, type KeyboardEvent } from "react";-import { CopyButton } from "./copy";+import { CopyIcon } from "./copy";export type Tab = { label: string; html: string };-/** Code behind tabs, with a copy button. The HTML is highlighted at build. */+/** Code behind tabs, with a copy icon. The HTML is highlighted at build. */export function Tabs({ tabs, label }: { tabs: Tab[]; label: string }) {const [at, setAt] = useState(0);const panel = useRef<HTMLDivElement>(null);@@ -32,7 +32,7 @@ export function Tabs({ tabs, label }: { tabs: Tab[]; label: string }) {))}</div>{/* read at the click, so it is always the tab on screen */}- <CopyButton text={() => panel.current?.textContent ?? ""} select={panel} />+ <CopyIcon text={() => panel.current?.textContent ?? ""} select={panel} label="Copy code" /></div><div ref={panel} role="tabpanel" id={`${id}-panel`} aria-labelledby={`${id}-tab-${at}`} tabIndex={0} className="code-panel" dangerouslySetInnerHTML={{ __html: tabs[at].html }} /></div>diff --git a/apps/site/test/site.spec.ts b/apps/site/test/site.spec.tsindex 23b683a..c52b237 100644--- a/apps/site/test/site.spec.ts+++ b/apps/site/test/site.spec.ts@@ -24,43 +24,61 @@ function watch(page: Page): string[] {/** The figure's drawing, without the ids that differ between mounts. */const drawing = (page: Page) => page.locator("[data-inspector] [data-hairline] > svg").evaluate((svg) => svg.innerHTML.replace(/hl-fd\d+/g, ""));-test("the page prerenders empty boxes, then draws seven figures with a clean console", async ({ page, request }) => {+test("the home prerenders an empty box, then draws the inspector's figure with a clean console", async ({ page, request }) => {const html = await (await request.get("/")).text();- // every figure's box is empty on the server (the GitHub icon is the only svg)- expect(html.match(/<div style="aspect-ratio:5 \/ 4"><\/div>/g)).toHaveLength(7);+ // the figure's box is empty on the server+ expect(html.match(/<div style="aspect-ratio:5 \/ 4"><\/div>/g)).toHaveLength(1);expect(html).not.toMatch(/aspect-ratio:5 \/ 4"[^>]*><svg/);expect(html).not.toMatch(/Fig\. \d/);const noise = watch(page);await page.goto("/");- // the inspector's, and one per row- await expect(page.locator("[data-hairline] > svg")).toHaveCount(7);- for (const id of IDS) await expect(page.locator(`[data-row="${id}"] [data-hairline] > svg > *`).first()).toBeAttached();+ await expect(page.locator("[data-hairline] > svg")).toHaveCount(1);await expect(page.locator("[data-install]").first()).toHaveText(/npm i @lucasmarkes\/hairline/);- await expect(page.locator("[data-size]")).toHaveText(/^\d+\.\d kB$/);await expect(page.locator("[data-version]")).toHaveText(/^v\d+\.\d+\.\d+/);expect(noise).toEqual([]);});-test("the inspector's chips pick the figure, and the snippet follows", async ({ page }) => {+test("the docs prerender six empty boxes, then draw one figure per row with a clean console", async ({ page, request }) => {+ const html = await (await request.get("/docs")).text();+ expect(html.match(/<div style="aspect-ratio:5 \/ 4"><\/div>/g)).toHaveLength(6);+ expect(html).not.toMatch(/aspect-ratio:5 \/ 4"[^>]*><svg/);++ const noise = watch(page);+ await page.goto("/docs");+ await expect(page.locator("[data-hairline] > svg")).toHaveCount(6);+ for (const id of IDS) await expect(page.locator(`[data-row="${id}"] [data-hairline] > svg > *`).first()).toBeAttached();+ await expect(page.locator("[data-size]")).toHaveText(/^\d+\.\d kB$/);+ expect(noise).toEqual([]);+});++test("the inspector's figure picker picks the figure, and the snippet follows", async ({ page }) => {await page.goto("/");const inspector = page.locator("[data-inspector]");- await expect(inspector.locator("[data-snippet] .code-panel")).toContainText("<Terrain />");- await inspector.getByRole("button", { name: "Riffle" }).click();+ await expect(inspector.locator("[data-snippet] pre")).toContainText("<Terrain />");+ const figures = inspector.getByRole("radiogroup", { name: "Figure" });+ await figures.getByRole("radio", { name: "Riffle" }).click();+ await expect(figures.getByRole("radio", { name: "Riffle" })).toHaveAttribute("aria-checked", "true");await expect(inspector.locator("[data-figure]")).toHaveAttribute("data-figure", "riffle");await expect(inspector.locator("[data-hairline]")).toHaveCount(1);- await expect(inspector.locator("[data-read]")).toHaveText("rest");- await expect(inspector.locator("[data-snippet] .code-panel")).toContainText('import { Riffle } from "@lucasmarkes/hairline/react";');- await expect(inspector.locator("[data-snippet] .code-panel")).toContainText("<Riffle />");+ // the arrow keys walk the choice+ await figures.getByRole("radio", { name: "Riffle" }).press("ArrowRight");+ await expect(inspector.locator("[data-figure]")).toHaveAttribute("data-figure", "terrain");+ await expect(figures.getByRole("radio", { name: "Terrain" })).toBeFocused();+ await figures.getByRole("radio", { name: "Terrain" }).press("ArrowLeft");+ await expect(inspector.locator("[data-snippet] pre")).toContainText('import { Riffle } from "@lucasmarkes/hairline/react";');+ await expect(inspector.locator("[data-snippet] pre")).toContainText("<Riffle />");});test("the inspector's slider reaches the figure, and the snippet shows it", async ({ page }) => {await page.goto("/");const inspector = page.locator("[data-inspector]");- const slider = inspector.getByRole("slider", { name: "intensity" });+ const slider = inspector.getByRole("slider", { name: "Intensity" });const stage = inspector.locator("[data-hairline]");- const box = (await stage.boundingBox())!;+ // measured at each hover: the slider sits under the figure, and filling it can scroll the pageconst hover = async () => {+ await stage.scrollIntoViewIfNeeded();+ const box = (await stage.boundingBox())!;await page.mouse.move(box.x + 4, box.y + 4);await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2, { steps: 4 });await page.waitForTimeout(1200);@@ -68,27 +86,27 @@ test("the inspector's slider reaches the figure, and the snippet shows it", asynawait slider.fill("0");await expect(inspector.locator("output")).toHaveText("0.00");- await expect(inspector.locator("[data-snippet] .code-panel")).toContainText("<Terrain intensity={0} />");+ await expect(inspector.locator("[data-snippet] pre")).toContainText("<Terrain intensity={0} />");await hover();const subtle = await drawing(page);await slider.fill("1");- await expect(inspector.locator("[data-snippet] .code-panel")).toContainText("<Terrain intensity={1} />");+ await expect(inspector.locator("[data-snippet] pre")).toContainText("<Terrain intensity={1} />");await hover();expect(await drawing(page)).not.toBe(subtle);await slider.fill("0.5");- await expect(inspector.locator("[data-snippet] .code-panel")).toContainText("<Terrain />");+ await expect(inspector.locator("[data-snippet] pre")).toContainText("<Terrain />");});test("the inspector's theme switch repaints the figure", async ({ page }) => {await page.goto("/");const inspector = page.locator("[data-inspector]");- await inspector.getByRole("button", { name: "Dark" }).click();- await expect(inspector.locator("[data-snippet] .code-panel")).toContainText('<Terrain theme="dark" />');+ await inspector.getByRole("radio", { name: "Dark" }).click();+ await expect(inspector.locator("[data-snippet] pre")).toContainText('<Terrain theme="dark" />');const plate = () => inspector.locator("[data-hairline] svg path").first().evaluate((el) => getComputedStyle(el).fill);await expect.poll(plate).toBe("rgb(8, 9, 10)");- await inspector.getByRole("button", { name: "Auto" }).click();+ await inspector.getByRole("radio", { name: "Auto" }).click();await expect.poll(plate).toBe("rgb(255, 255, 255)");});@@ -99,10 +117,12 @@ test("the install pill copies every manager's command", async ({ page, context }for (const [label, code] of MANAGERS) {await expect(pill).toHaveAttribute("data-install", label);await expect(pill.locator("code")).toHaveText(code);- await pill.getByRole("button", { name: "Copy" }).click();- await expect(pill.getByRole("button", { name: "Copied" })).toBeVisible();+ const copy = pill.getByRole("button", { name: "Copy install command" });+ await copy.click();+ await expect(copy).toHaveAttribute("data-copied", "true");+ await expect(pill.getByText("Copied")).toBeAttached();expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(code);- await pill.getByRole("button", { name: new RegExp(`^${label}: switch to`) }).click();+ await pill.getByRole("button", { name: new RegExp(`\\(${label}\\): switch to`) }).click();}await expect(pill).toHaveAttribute("data-install", "npm");});@@ -114,26 +134,27 @@ test("without a clipboard, copy selects the text instead and throws nothing", asconst noise = watch(page);await page.goto("/");const pill = page.locator("[data-install]").first();- await pill.getByRole("button", { name: "Copy" }).click();- await expect(pill.getByRole("button", { name: "Copy" })).toBeVisible();+ const copy = pill.getByRole("button", { name: "Copy install command" });+ await copy.click();+ await expect(copy).not.toHaveAttribute("data-copied");expect(await page.evaluate(() => window.getSelection()?.toString())).toBe("npm i @lucasmarkes/hairline");const snippet = page.locator("[data-snippet]");- await snippet.getByRole("button", { name: "Copy" }).click();+ await snippet.getByRole("button", { name: "Copy snippet" }).click();expect(await page.evaluate(() => window.getSelection()?.toString())).toContain("<Terrain />");expect(noise).toEqual([]);});-test("the quickstart pastes four ways and lists the four options", async ({ page, context }) => {+test("Get started leads to the docs, whose quickstart pastes four ways and lists the four options", async ({ page, context }) => {await context.grantPermissions(["clipboard-read", "clipboard-write"]);await page.goto("/");await page.getByRole("link", { name: "Get started" }).click();- await expect(page).toHaveURL(/#quickstart$/);+ await expect(page).toHaveURL(/\/docs$/);const quick = page.locator("section[aria-labelledby=quickstart]");await expect(quick.getByRole("tab")).toHaveText(["React", "Vanilla", "CDN", "CSS"]);await quick.getByRole("tab", { name: "CSS" }).click();await expect(quick.locator(".code-panel")).toContainText("--hairline-plate: #ffffff;");- await quick.locator(".code").getByRole("button", { name: "Copy" }).click();+ await quick.locator(".code").getByRole("button", { name: "Copy code" }).click();expect(await page.evaluate(() => navigator.clipboard.readText())).toContain("--hairline-stroke: 0.9;");await expect(quick.locator("[data-options] tbody tr td:first-child")).toHaveText(["intensity", "theme", "label", "onRead"]);});@@ -163,14 +184,14 @@ test("the page fits a phone, with the longest install command and every control"const inspector = page.locator("[data-inspector]");for (const name of ["Turntable", "Dark"]) {- const control = inspector.getByRole("button", { name });+ const control = inspector.getByRole("radio", { name });await control.click();const box = (await control.boundingBox())!;expect(box.x).toBeGreaterThanOrEqual(0);expect(box.x + box.width).toBeLessThanOrEqual(390);}- await inspector.getByRole("slider", { name: "intensity" }).fill("0.85");- await expect(inspector.locator("[data-snippet] .code-panel")).toContainText('<Turntable intensity={0.85} theme="dark" />');+ await inspector.getByRole("slider", { name: "Intensity" }).fill("0.85");+ await expect(inspector.locator("[data-snippet] pre")).toContainText('<Turntable intensity={0.85} theme="dark" />');expect(await width()).toBeLessThanOrEqual(390);});@@ -186,9 +207,19 @@ test("without a clipboard at all, the top bar's llms.txt button opens the file",expect(noise.filter((line) => line.startsWith("pageerror"))).toEqual([]);});-test("each figure row names its figure in italic serif", async ({ page }) => {+test("one family outside the hero: the serif is the headline's one word, mono is code", async ({ page }) => {await page.goto("/");- for (const id of IDS) await expect(page.locator(`[data-row="${id}"] h3`)).toHaveCSS("font-style", "italic");+ await expect(page.locator("h1 em")).toHaveCSS("font-family", /Instrument Serif/);+ const families = await page.evaluate(() =>+ [...document.querySelectorAll("body *")]+ // the install pill is code, prompt and all+ .filter((el) => !el.closest("h1 em, code, pre, .pill, [data-hairline]") && [...el.childNodes].some((n) => n.nodeType === 3 && n.textContent!.trim()))+ .map((el) => `${el.tagName} ${getComputedStyle(el).fontFamily}`),+ );+ expect(families.length).toBeGreaterThan(5);+ expect(families.filter((f) => !/geist/i.test(f) || /mono/i.test(f))).toEqual([]);+ await page.goto("/docs");+ for (const id of IDS) await expect(page.locator(`[data-row="${id}"] h3`)).toHaveCSS("font-style", "normal");});test("a command wider than the pill fades at the edge until it is scrolled to its end, and shows itself whole on hover", async ({ page }) => {@@ -210,10 +241,10 @@ test("a command wider than the pill fades at the edge until it is scrolled to itawait expect(line).toHaveCSS("mask-image", "none");});-test("the footer links the author's site and X, and no longer the essay", async ({ page }) => {+test("the footer links the author's site, then X, GitHub, npm and llms.txt", async ({ page }) => {await page.goto("/");const footer = page.locator("footer");await expect(footer.getByRole("link", { name: "Lucas Marques" })).toHaveAttribute("href", "https://lucasmarkes.com");await expect(footer.getByRole("link", { name: "X", exact: true })).toHaveAttribute("href", "https://x.com/lucasmarkes__");- await expect(footer.getByRole("link")).toHaveText(["Lucas Marques", "Linear", "npm", "GitHub", "llms.txt", "X"]);+ await expect(footer.getByRole("link")).toHaveText(["Lucas Marques", "X", "GitHub", "npm", "llms.txt"]);});