Isometric line figures that answer the pointer. For React and for anything with a DOM.
Site: install first, a live inspector, and the figures without numbers
Lucas Marquesdbac63db8b80
diff --git a/apps/site/app/globals.css b/apps/site/app/globals.cssindex 6413d90..19b1b22 100644--- a/apps/site/app/globals.css+++ b/apps/site/app/globals.css@@ -1,71 +1,112 @@@import "tailwindcss";-/* The look of the tweet videos: warm paper, white tiles with a soft shadow, mono captions in the corners. */+/* After cuelume: a light canvas, white panels with a soft lift, one serif accent, mono for code. */@theme {--font-sans: var(--font-geist-sans), ui-sans-serif, system-ui, sans-serif;- --font-mono: var(--font-geist-mono), ui-monospace, monospace;- --color-ground: #efebe5;- --color-ink: #232327;- --color-muted: #77736c;- --color-line: rgba(28, 22, 14, 0.1);+ --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);+}++: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;}html { color-scheme: light; scroll-behavior: smooth; }+body { min-height: 100vh; color: var(--color-ink); background: var(--color-canvas); }+em { font-style: italic; }-body {- min-height: 100vh;- color: var(--color-ink);- background:- radial-gradient(60% 75% at 16% 8%, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0) 70%) fixed,- linear-gradient(160deg, #f7f5f2 0%, #f0ece6 55%, #e9e4dd 100%) fixed,- var(--color-ground);+.topbar {+ position: sticky; top: 0; z-index: 10;+ display: flex; align-items: center; justify-content: space-between;+ padding: 12px clamp(18px, 5vw, 28px);+ background: color-mix(in srgb, var(--color-canvas) 82%, transparent);+ backdrop-filter: blur(12px);}-.tile {- position: relative;- overflow: hidden;- border-radius: 12px;- background: #fff;- box-shadow:- 0 0 0 1px rgba(0, 0, 0, 0.05),- 0 2px 6px rgba(28, 22, 14, 0.05),- 0 20px 50px -18px rgba(28, 22, 14, 0.18);+.btn {+ display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px;+ border-radius: 9px; font-size: 14px; font-weight: 500;+ 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: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); }-.cap {- position: absolute;- font: 500 11px/1 var(--font-mono);- letter-spacing: 0.02em;- color: var(--hairline-edge, #a4a4ac);- pointer-events: none;- font-variant-numeric: tabular-nums;+.pill {+ display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 6px 0 16px;+ border-radius: 12px; background: #fff; box-shadow: inset 0 0 0 1px var(--color-stone), var(--lift);+ font: 400 14px/1 var(--font-mono); text-align: left;}+.pill-line { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; scrollbar-width: none; }+.pill-line::-webkit-scrollbar { display: none; }+.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; }-.code { overflow: hidden; border-radius: 12px; background: rgba(255, 255, 255, 0.66); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05); }+.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); }++.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, .code-copy, .chip { border-radius: 7px; padding: 5px 10px; font: 500 12px/1 var(--font-mono); color: var(--color-muted); }-.code-tab[aria-selected="true"], .chip[aria-pressed="true"] { background: rgba(28, 22, 14, 0.07); color: var(--color-ink); }-.code-copy:hover, .code-tab:hover, .chip:hover { color: var(--color-ink); }-.chip { box-shadow: 0 0 0 1px var(--color-line); }-.code-panel { margin: 0; overflow-x: auto; padding: 14px 16px; font: 400 13px/1.6 var(--font-mono); }+.code-tab { border-radius: 7px; padding: 6px 10px; font: 500 12px/1 var(--font-mono); 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); }.code-panel pre { margin: 0; background: transparent !important; }.code-panel code { font: inherit; }-:is(.code-tab, .code-copy, .chip, .code-panel, .slider, .swatch, a):focus-visible { outline: 1.5px solid var(--color-ink); outline-offset: 2px; }-.slider { flex: 1; min-width: 0; height: 18px; appearance: none; background: transparent; cursor: pointer; }-.slider::-webkit-slider-runnable-track { height: 2px; border-radius: 1px; background: rgba(28, 22, 14, 0.18); }-.slider::-webkit-slider-thumb { appearance: none; width: 14px; height: 14px; margin-top: -6px; border-radius: 50%; background: var(--color-ink); }-.slider::-moz-range-track { height: 2px; border-radius: 1px; background: rgba(28, 22, 14, 0.18); }-.slider::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--color-ink); }+.tile { overflow: hidden; border-radius: 14px; background: #fff; box-shadow: inset 0 0 0 1px var(--color-stone), var(--lift); }+.figure-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(120px, 240px); align-items: center; gap: 24px; padding: 28px 0; border-top: 1px solid var(--color-line); }+.figure-row:last-child { border-bottom: 1px solid var(--color-line); }+.card { border-radius: 14px; padding: 20px; background: #fff; box-shadow: inset 0 0 0 1px var(--color-stone); }-.swatch { width: 26px; height: 26px; padding: 0; border: 0; border-radius: 7px; background: none; cursor: pointer; }-.swatch::-webkit-color-swatch-wrapper { padding: 0; }-.swatch::-webkit-color-swatch { border: 1px solid var(--color-line); border-radius: 7px; }+.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); }.props { width: 100%; border-collapse: collapse; font-size: 13px; }-.props th { padding: 8px 12px 8px 0; text-align: left; font: 500 11px/1 var(--font-mono); letter-spacing: 0.04em; text-transform: uppercase; color: var(--color-muted); }-.props td { padding: 10px 12px 10px 0; vertical-align: top; border-top: 1px solid var(--color-line); }+.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 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); }+:is(button, a, input, .code-panel):focus-visible { outline: 1.5px solid var(--color-ink); outline-offset: 2px; }++@media (max-width: 640px) {+ .figure-row { grid-template-columns: minmax(0, 1fr) 120px; gap: 16px; }+ /* one option per block: name, type and default on a line, the description under them */+ .props thead { display: none; }+ .props tr { display: flex; flex-wrap: wrap; column-gap: 12px; padding: 14px 0; border-top: 1px solid var(--color-line); }+ .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; } }diff --git a/apps/site/app/layout.tsx b/apps/site/app/layout.tsxindex a54b989..420fabe 100644--- a/apps/site/app/layout.tsx+++ b/apps/site/app/layout.tsx@@ -2,9 +2,13 @@ import type { Metadata } from "next";import type { ReactNode } from "react";import { GeistMono } from "geist/font/mono";import { GeistSans } from "geist/font/sans";+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. */+const serif = Instrument_Serif({ weight: "400", style: ["normal", "italic"], subsets: ["latin"], variable: "--font-instrument-serif" });+const SITE = process.env.NEXT_PUBLIC_SITE_URL!;const DESCRIPTION = "Six isometric line figures that answer the pointer. SVG, no dependencies, for React and for everything else.";@@ -13,14 +17,14 @@ export const metadata: Metadata = {title: "hairline",description: DESCRIPTION,alternates: { canonical: "/" },- openGraph: { title: "hairline", description: DESCRIPTION, url: "/", siteName: "hairline", type: "website", images: [{ url: "/og.png", width: 1200, height: 630, alt: "The six hairline figures on a board." }] },+ openGraph: { title: "hairline", description: DESCRIPTION, url: "/", siteName: "hairline", type: "website", images: [{ url: "/og.png", width: 1200, height: 630, alt: "Line drawings that answer the pointer: the Terrain figure, its pillars rising." }] },twitter: { card: "summary_large_image", title: "hairline", description: DESCRIPTION, images: ["/og.png"], creator: "@lucasmarkes" },icons: { icon: "/icon.svg" },};export default function RootLayout({ children }: { children: ReactNode }) {return (- <html lang="en" className={`${GeistSans.variable} ${GeistMono.variable}`}>+ <html lang="en" className={`${GeistSans.variable} ${GeistMono.variable} ${serif.variable}`}><body className="font-sans antialiased">{children}<Analytics />diff --git a/apps/site/app/og/page.tsx b/apps/site/app/og/page.tsxindex 95bfd85..e275fb2 100644--- a/apps/site/app/og/page.tsx+++ b/apps/site/app/og/page.tsx@@ -1,21 +1,19 @@import type { Metadata } from "next";-import { Tile } from "@/components/tile";-import { FIGURES } from "@/lib/figures";+import { Terrain } from "@lucasmarkes/hairline/react";/** The Open Graph card, as a page: scripts/og.mjs photographs it at 1200 × 630 into public/og.png. */export const metadata: Metadata = { robots: { index: false } };export default function Og() {return (- <main className="flex h-[630px] w-[1200px] items-center gap-14 overflow-hidden px-16">- <div className="w-[300px] shrink-0">- <h1 className="text-[56px] font-medium leading-none tracking-[-0.04em]">hairline</h1>- <p className="mt-5 text-[22px] leading-[1.35] text-muted">Six isometric line figures that answer the pointer.</p>- <p className="mt-8 font-mono text-[15px] text-ink">npm i @lucasmarkes/hairline</p>- </div>- <div className="grid flex-1 grid-cols-3 gap-4">- {FIGURES.map((doc, i) => <Tile key={doc.id} id={doc.id} index={i + 1} name={doc.name} />)}+ <main className="flex h-[630px] w-[1200px] items-center gap-16 overflow-hidden px-20">+ <div className="w-[470px] shrink-0">+ <h1 className="text-[64px] font-medium leading-[1.02] tracking-[-0.045em]">+ Line drawings that <em className="font-serif text-[1.08em] font-normal tracking-[-0.02em]">answer</em> the pointer.+ </h1>+ <p className="mt-8 font-mono text-[18px] text-muted">npm i @lucasmarkes/hairline</p></div>+ <div className="tile flex-1 p-6"><Terrain /></div></main>);}diff --git a/apps/site/app/page.tsx b/apps/site/app/page.tsxindex bdff9e4..576fcb6 100644--- a/apps/site/app/page.tsx+++ b/apps/site/app/page.tsx@@ -1,142 +1,146 @@+import pkg from "@lucasmarkes/hairline/package.json";import { Exploded, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";-import { FigureDemo } from "@/components/figure-demo";+import { CopyButton } from "@/components/copy";+import { Inspector } from "@/components/inspector";+import { Install } from "@/components/install";import { Tabs } from "@/components/tabs";-import { ThemeEditor } from "@/components/theme-editor";-import { CARDS, FIGURES, LINKS, NOTES, SHARED, THEME, rows, type Row } from "@/lib/figures";-import { LIVE, highlight, plain } from "@/lib/highlight";-import { FRAMEWORKS, install, react, vanilla } from "@/lib/snippets";+import { CARDS, FIGURES, LINKS, 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 };-function Props({ list }: { list: Row[] }) {+function GitHub() {return (- <div className="overflow-x-auto">- <table className="props">- <thead>- <tr><th>Option</th><th>Type</th><th>Default</th><th>What it does</th></tr>- </thead>- <tbody>- {list.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>+ <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, kicker, title, children }: { id: string; kicker: string; title: string; children?: React.ReactNode }) {+function Heading({ id, title, children }: { id: string; title: React.ReactNode; children?: React.ReactNode }) {return (- <header className="mb-8 max-w-[62ch]">- <p className="font-mono text-[11px] uppercase tracking-[0.08em] text-muted">{kicker}</p>- <h2 id={id} className="mt-2 scroll-mt-10 text-[28px] font-medium tracking-[-0.03em]">- <a href={`#${id}`}>{title}</a>- </h2>+ <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 whole site. A Server Component: the six figures in the hero are the- * package's React components rendered straight from here, so every deploy- * runs them through server rendering and hydration.+ * 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.*/export default async function Page() {- const demos = await Promise.all(- FIGURES.map(async (doc) => [- { label: "React", html: await highlight(react(doc, LIVE), "tsx", doc.range.default) },- { label: "Vanilla", html: await highlight(vanilla(doc, LIVE), "ts", doc.range.default) },- ]),- );- const frameworks = await Promise.all(FRAMEWORKS.map(async (f) => ({ label: f.label, html: await highlight(f.code, f.lang) })));- const commands = install(SITE).map((i) => ({ label: i.label, html: plain(i.code) }));- const hero = [- <Riffle key="riffle" labels={CARDS} />, <Terrain key="terrain" />, <Exploded key="exploded" />,- <Phosphor key="phosphor" />, <Slow key="slow" />, <Turntable key="turntable" />,- ];+ 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 (- <main className="mx-auto grid max-w-[1040px] gap-28 px-6 pb-24 pt-20 [&>*]:min-w-0">- <section aria-labelledby="hairline">- <div className="max-w-[52ch]">- <h1 id="hairline" className="text-[44px] font-medium leading-none tracking-[-0.04em]">hairline</h1>- <p className="mt-4 text-[19px] leading-[1.45] text-muted">- Six isometric line figures that answer the pointer. SVG, no dependencies, for React and for everything else.- </p>- </div>- <div className="mt-10 grid grid-cols-2 gap-4 md:grid-cols-3" data-hero>- {FIGURES.map((doc, i) => (- <a key={doc.id} href={`#${doc.id}`} className="tile" aria-label={`${doc.name}, figure ${i + 1}`}>- {hero[i]}- <span className="cap left-4 top-3">Fig. {i + 1}</span>- <span className="cap right-4 top-3">{doc.name}</span>- </a>- ))}- </div>- <div className="mt-8 max-w-[560px]" data-install>- <Tabs tabs={commands} label="Install" />- </div>- </section>+ <>+ <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`} label="llms.txt" className="btn btn-quiet" />+ </nav>+ </header>- {FIGURES.map((doc, i) => (- <section key={doc.id} aria-labelledby={doc.id} data-section={doc.id}>- <Heading id={doc.id} kicker={`Fig. ${i + 1}`} title={doc.name}>{doc.summary}</Heading>- <FigureDemo id={doc.id} index={i + 1} name={doc.name} option={doc.option} range={doc.range} tabs={demos[i]} />- <div className="mt-8"><Props list={rows(doc)} /></div>+ <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.+ </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>+ </div></section>- ))}-- <section aria-labelledby="options">- <Heading id="options" kicker="API" title="Options every figure takes">- A figure fills the width of its element at a 5:4 aspect ratio. In React, every other prop goes to the <code className="font-mono text-[14px]"><div></code>, and the ref is forwarded.- </Heading>- <Props list={SHARED} />- </section>- <section aria-labelledby="theme">- <Heading id="theme" kicker="Theme" title="Six properties">- Set them on a figure or on anything above it. Without them a figure is light, or dark when the page says so. The plate colour hides what is drawn behind each plate, so it has to match what the figure sits on.- </Heading>- <ThemeEditor />- <ul className="mt-8 grid gap-2 text-[14px] leading-[1.5]">- {THEME.map((t) => (- <li key={t.property} className="grid gap-x-6 md:grid-cols-[190px_1fr]">- <code className="font-mono text-[13px]">{t.property}</code>- <span className="text-muted">{t.role}</span>- </li>- ))}- </ul>- </section>+ <section aria-label="Try it">+ <Inspector />+ </section>- <section aria-labelledby="frameworks">- <Heading id="frameworks" kicker="Use" title="Anywhere there is an element">- The vanilla entry is a function that takes an element and returns <code className="font-mono text-[14px]">update</code> and <code className="font-mono text-[14px]">destroy</code>, which is all a framework needs.- </Heading>- <Tabs tabs={frameworks} label="Frameworks" />- </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] 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-labelledby="notes">- <Heading id="notes" kicker="Notes" title="What it does when you are not looking" />- <dl className="grid gap-x-10 gap-y-6 md:grid-cols-2">- {NOTES.map((n) => (- <div key={n.title}>- <dt className="text-[15px] font-medium">{n.title}</dt>- <dd className="mt-1 text-[14px] leading-[1.55] text-muted">{n.body}</dd>+ <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>))}- </dl>- </section>+ </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-2 border-t border-line pt-6 font-mono text-[12px] text-muted">- <a className="text-ink" href={LINKS.github}>GitHub</a>- <a className="text-ink" href={LINKS.npm}>npm</a>- <a className="text-ink" href={LINKS.essay}>The essay</a>- <a className="text-ink" href="/llms.txt">llms.txt</a>- <span className="md:ml-auto">- After the figures on <a className="text-ink" href={LINKS.linear}>Linear</a>’s home page. MIT, Lucas Marques.- </span>- </footer>- </main>+ <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 Lucas Marques. 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.essay}>The essay</a>+ </nav>+ </footer>+ </main>+ </>);}diff --git a/apps/site/components/copy.tsx b/apps/site/components/copy.tsxnew file mode 100644index 0000000..5642d37--- /dev/null+++ b/apps/site/components/copy.tsx@@ -0,0 +1,48 @@+"use client";++import { useCallback, useEffect, useState, type RefObject } from "react";++/**+ * Copies text, and says so for a moment. Without clipboard permission, or on+ * a page served without a secure context where there is no clipboard at all,+ * it selects the text instead, so the keyboard can copy it.+ */+export function useCopy(): [copied: boolean, copy: (text: string, fallback?: Element | null) => void] {+ const [copied, setCopied] = useState(false);++ useEffect(() => {+ if (!copied) return;+ const timer = setTimeout(() => setCopied(false), 1600);+ return () => clearTimeout(timer);+ }, [copied]);++ const copy = useCallback(async (text: string, fallback?: Element | null) => {+ try {+ await navigator.clipboard.writeText(text);+ setCopied(true);+ } catch {+ if (!fallback) return;+ const range = document.createRange();+ range.selectNodeContents(fallback);+ const selection = window.getSelection();+ selection?.removeAllRanges();+ selection?.addRange(range);+ }+ }, []);++ return [copied, copy];+}++/**+ * A button that copies `text`, or selects what `select` points at when it+ * cannot. `text` can be a function, read at the click, for text the button+ * does not own.+ */+export function CopyButton({ text, select, label = "Copy", className = "copy" }: { text: string | (() => string); select?: RefObject<Element | null>; label?: string; className?: string }) {+ const [copied, copy] = useCopy();+ return (+ <button type="button" className={className} onClick={() => copy(typeof text === "function" ? text() : text, select?.current)} aria-live="polite">+ {copied ? "Copied" : label}+ </button>+ );+}diff --git a/apps/site/components/figure-demo.tsx b/apps/site/components/figure-demo.tsxdeleted file mode 100644index 3cdccdf..0000000--- a/apps/site/components/figure-demo.tsx+++ /dev/null@@ -1,26 +0,0 @@-"use client";--import { useId, useState } from "react";-import type { Range } from "@lucasmarkes/hairline";-import { shown, type FigureId } from "@/lib/figures";-import { Tabs, type Tab } from "./tabs";-import { Tile } from "./tile";--/** A figure, the slider for its option, and the code that follows the slider. */-export function FigureDemo({ id, index, name, option, range, tabs }: { id: FigureId; index: number; name: string; option: string; range: Range; tabs: Tab[] }) {- const [value, setValue] = useState(range.default);- const slider = useId();- return (- <div className="grid items-start gap-6 md:grid-cols-2 [&>*]:min-w-0">- <Tile id={id} index={index} name={name} options={{ [option]: value }} />- <div className="grid gap-4 [&>*]:min-w-0">- <div className="flex items-center gap-4 font-mono text-[13px]">- <label htmlFor={slider} className="w-20 text-ink">{option}</label>- <input id={slider} type="range" className="slider" min={range.min} max={range.max} step={range.step} value={value} onChange={(event) => setValue(Number(event.target.value))} />- <output htmlFor={slider} className="w-20 text-right text-muted">{shown(value, range)}</output>- </div>- <Tabs tabs={tabs} label={`${name} code`} live={String(value)} />- </div>- </div>- );-}diff --git a/apps/site/components/inspector.tsx b/apps/site/components/inspector.tsxnew file mode 100644index 0000000..f14127c--- /dev/null+++ b/apps/site/components/inspector.tsx@@ -0,0 +1,76 @@+"use client";++import { useId, useRef, useState } 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";++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" },+];++/**+ * One large figure and its three controls: 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 });++ 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>+ <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>+ <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>+ </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>+ </div>+ </div>+ );+}diff --git a/apps/site/components/install.tsx b/apps/site/components/install.tsxnew file mode 100644index 0000000..dd46a16--- /dev/null+++ b/apps/site/components/install.tsx@@ -0,0 +1,29 @@+"use client";++import { useRef, useState } from "react";+import { CopyButton } 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.+ */+export function Install({ commands }: { commands: { label: string; code: string }[] }) {+ const [at, setAt] = useState(0);+ const line = useRef<HTMLElement>(null);+ const { label, code } = commands[at];+ const head = code.slice(0, code.indexOf(" "));+ const next = commands[(at + 1) % commands.length].label;++ return (+ <div className="pill" data-install={label}>+ <span aria-hidden="true" className="select-none text-faint">$</span>+ <code ref={line} className="pill-line">+ <button type="button" className="pill-manager" onClick={() => setAt((at + 1) % commands.length)} aria-label={`${label}: switch to ${next}`} title={`Switch to ${next}`}>+ {head}+ </button>+ {code.slice(head.length)}+ </code>+ <CopyButton text={code} select={line} />+ </div>+ );+}diff --git a/apps/site/components/tabs.tsx b/apps/site/components/tabs.tsxindex a5de335..03f631a 100644--- a/apps/site/components/tabs.tsx+++ b/apps/site/components/tabs.tsx@@ -1,41 +1,17 @@"use client";-import { useEffect, useId, useRef, useState, type KeyboardEvent } from "react";+import { useId, useRef, useState, type KeyboardEvent } from "react";+import { CopyButton } from "./copy";export type Tab = { label: string; html: string };-/**- * Code behind tabs, with a copy button. The HTML is highlighted at build; when- * `live` is given, every span marked data-live shows it, so a snippet follows- * a slider without a highlighter in the browser.- */-export function Tabs({ tabs, label, live }: { tabs: Tab[]; label: string; live?: string }) {+/** Code behind tabs, with a copy button. The HTML is highlighted at build. */+export function Tabs({ tabs, label }: { tabs: Tab[]; label: string }) {const [at, setAt] = useState(0);- const [copied, setCopied] = useState(false);const panel = useRef<HTMLDivElement>(null);const list = useRef<HTMLDivElement>(null);const id = useId();- useEffect(() => {- if (live === undefined) return;- panel.current?.querySelectorAll("[data-live]").forEach((node) => { node.textContent = live; });- }, [live, at]);-- useEffect(() => {- if (!copied) return;- const timer = setTimeout(() => setCopied(false), 1600);- return () => clearTimeout(timer);- }, [copied]);-- const copy = async () => {- try {- await navigator.clipboard.writeText(panel.current?.textContent ?? "");- setCopied(true);- } catch {- // no clipboard permission: the text is still selectable- }- };-const onKeyDown = (event: KeyboardEvent) => {const step = event.key === "ArrowRight" ? 1 : event.key === "ArrowLeft" ? -1 : 0;if (!step) return;@@ -55,11 +31,11 @@ export function Tabs({ tabs, label, live }: { tabs: Tab[]; label: string; live?:</button>))}</div>- <button type="button" onClick={copy} className="code-copy" aria-live="polite">- {copied ? "Copied" : "Copy"}- </button>+ {/* read at the click, so it is always the tab on screen */}+ <CopyButton text={() => panel.current?.textContent ?? ""} select={panel} /></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/components/theme-editor.tsx b/apps/site/components/theme-editor.tsxdeleted file mode 100644index d2ee97c..0000000--- a/apps/site/components/theme-editor.tsx+++ /dev/null@@ -1,70 +0,0 @@-"use client";--import { useState, type CSSProperties } from "react";-import { themeCss } from "@/lib/snippets";-import { Tile } from "./tile";--type Colors = { plate: string; hi: string; edge: string; mid: string; lo: string };--/** The package's own palettes, and one that is neither. */-const PRESETS: Record<string, Colors> = {- Light: { plate: "#ffffff", hi: "#232327", edge: "#a4a4ac", mid: "#c3c3c9", lo: "#e0e0e4" },- Dark: { plate: "#08090a", hi: "#d0d6e0", edge: "#5b5d64", mid: "#3e3e44", lo: "#29292d" },- Blueprint: { plate: "#0f2f57", hi: "#eaf2ff", edge: "#8fb2e0", mid: "#5b83ba", lo: "#2b4f80" },-};-const KEYS = ["plate", "hi", "edge", "mid", "lo"] as const;--/** The six theme properties, live: change one and the figure and the CSS below both follow. */-export function ThemeEditor() {- const [colors, setColors] = useState<Colors>(PRESETS.Light);- const [stroke, setStroke] = useState(0.9);- const [copied, setCopied] = useState(false);- const css = themeCss(colors, stroke);- const style = { background: colors.plate, "--hairline-stroke": stroke, ...Object.fromEntries(KEYS.map((k) => [`--hairline-${k}`, colors[k]])) } as CSSProperties;-- const copy = async () => {- try {- await navigator.clipboard.writeText(css);- setCopied(true);- setTimeout(() => setCopied(false), 1600);- } catch {- // no clipboard permission: the text is still selectable- }- };-- return (- <div className="grid items-start gap-6 md:grid-cols-2 [&>*]:min-w-0">- <Tile id="exploded" index={3} name="Exploded" style={style} />- <div className="grid gap-4 [&>*]:min-w-0">- <div className="flex gap-2">- {Object.entries(PRESETS).map(([name, preset]) => (- <button key={name} type="button" className="chip" aria-pressed={KEYS.every((k) => colors[k] === preset[k])} onClick={() => setColors(preset)}>- {name}- </button>- ))}- </div>- <div className="grid gap-2 font-mono text-[13px]">- {KEYS.map((key) => (- <label key={key} className="flex items-center gap-3">- <input type="color" className="swatch" value={colors[key]} onChange={(event) => setColors({ ...colors, [key]: event.target.value })} />- <span className="text-ink">--hairline-{key}</span>- <span className="ml-auto text-muted">{colors[key]}</span>- </label>- ))}- <label className="flex items-center gap-3">- <span className="text-ink">--hairline-stroke</span>- <input type="range" className="slider" min={0.5} max={2} step={0.1} value={stroke} onChange={(event) => setStroke(Number(event.target.value))} />- <span className="w-8 text-right text-muted">{stroke}</span>- </label>- </div>- <div className="code">- <div className="code-bar">- <span className="code-tab" aria-selected="true">CSS</span>- <button type="button" onClick={copy} className="code-copy" aria-live="polite">{copied ? "Copied" : "Copy"}</button>- </div>- <pre className="code-panel" data-theme-css>{css}</pre>- </div>- </div>- </div>- );-}diff --git a/apps/site/components/tile.tsx b/apps/site/components/tile.tsxdeleted file mode 100644index fb1a462..0000000--- a/apps/site/components/tile.tsx+++ /dev/null@@ -1,21 +0,0 @@-"use client";--import { useState, type ComponentType, type CSSProperties } from "react";-import { Exploded, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";-import { CARDS, type FigureId } from "@/lib/figures";--const COMPONENTS = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable };--/** A live figure on a white tile, with its number, its name and its caption in the corners. */-export function Tile({ id, index, name, options, style }: { id: FigureId; index: number; name: string; options?: Record<string, unknown>; style?: CSSProperties }) {- const [read, setRead] = useState("");- const Figure = COMPONENTS[id] as unknown as ComponentType<Record<string, unknown>>;- return (- <div className="tile" style={style} data-figure={id}>- <Figure {...(id === "riffle" ? { labels: CARDS } : null)} {...options} onRead={setRead} />- <span className="cap left-4 top-3">Fig. {index}</span>- <span className="cap right-4 top-3">{name}</span>- <span className="cap bottom-3 left-4" data-read aria-hidden="true">{read}</span>- </div>- );-}diff --git a/apps/site/test/site.spec.ts b/apps/site/test/site.spec.tsindex 4b34fcf..93887f8 100644--- a/apps/site/test/site.spec.ts+++ b/apps/site/test/site.spec.ts@@ -1,6 +1,14 @@import { expect, test, type Page } from "@playwright/test";const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable"];+const MANAGERS = [+ ["npm", "npm i @lucasmarkes/hairline"],+ ["pnpm", "pnpm add @lucasmarkes/hairline"],+ ["yarn", "yarn add @lucasmarkes/hairline"],+ ["bun", "bun add @lucasmarkes/hairline"],+ // the build's base URL, which is localhost:3000 off Vercel+ ["shadcn", "npx shadcn@latest add http://localhost:3000/r/hairline.json"],+] as const;function watch(page: Page): string[] {const noise: string[] = [];@@ -13,53 +21,121 @@ function watch(page: Page): string[] {return noise;}-test("the page prerenders empty boxes and draws thirteen figures with a clean console", async ({ page, request }) => {+/** 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 }) => {const html = await (await request.get("/")).text();- expect(html).not.toContain("<svg");- expect(html).toContain("pnpm add @lucasmarkes/hairline");+ // 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);+ expect(html).not.toMatch(/aspect-ratio:5 \/ 4"[^>]*><svg/);+ expect(html).not.toMatch(/Fig\. \d/);const noise = watch(page);await page.goto("/");- // six in the hero, one per section, one in the theme editor- await expect(page.locator("[data-hairline] > svg")).toHaveCount(13);- await expect(page.locator("[data-hero] [data-hairline] > svg > *").first()).toBeVisible();- // every figure but Exploded has a caption at rest- for (const id of IDS.filter((id) => id !== "exploded")) await expect(page.locator(`[data-section="${id}"] [data-read]`)).not.toBeEmpty();+ // 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-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("a slider moves the figure's option and both snippets", async ({ page }) => {+test("the inspector's chips pick 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-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 />");+});++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 stage = inspector.locator("[data-hairline]");+ const box = (await stage.boundingBox())!;+ const hover = async () => {+ 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);+ };++ await slider.fill("0");+ await expect(inspector.locator("output")).toHaveText("0.00");+ await expect(inspector.locator("[data-snippet] .code-panel")).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 hover();+ expect(await drawing(page)).not.toBe(subtle);++ await slider.fill("0.5");+ await expect(inspector.locator("[data-snippet] .code-panel")).toContainText("<Terrain />");+});++test("the inspector's theme switch repaints the figure", async ({ page }) => {await page.goto("/");- const section = page.locator('[data-section="riffle"]');- await expect(section.locator(".code-panel")).toContainText("<Riffle stagger={40}");- await section.locator("input[type=range]").fill("75");- await expect(section.locator("output")).toHaveText("75 ms");- await expect(section.locator(".code-panel")).toContainText("<Riffle stagger={75}");- await section.getByRole("tab", { name: "Vanilla" }).click();- await expect(section.locator(".code-panel")).toContainText("{ stagger: 75 }");+ 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" />');+ 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 expect.poll(plate).toBe("rgb(255, 255, 255)");});-test("the install tabs switch and copy", async ({ page, context }) => {+test("the install pill copies every manager's command", async ({ page, context }) => {await context.grantPermissions(["clipboard-read", "clipboard-write"]);await page.goto("/");- const install = page.locator("[data-install]");- await install.getByRole("tab", { name: "npm", exact: true }).click();- await expect(install.locator(".code-panel")).toHaveText("npm install @lucasmarkes/hairline");- await install.getByRole("button", { name: "Copy" }).click();- await expect(install.getByRole("button", { name: "Copied" })).toBeVisible();- expect(await page.evaluate(() => navigator.clipboard.readText())).toBe("npm install @lucasmarkes/hairline");- await install.getByRole("tab", { name: "npm", exact: true }).press("ArrowLeft");- await expect(install.getByRole("tab", { name: "pnpm" })).toBeFocused();- await expect(install.locator(".code-panel")).toHaveText("pnpm add @lucasmarkes/hairline");+ const pill = page.locator("[data-install]").first();+ 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();+ expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(code);+ await pill.getByRole("button", { name: new RegExp(`^${label}: switch to`) }).click();+ }+ await expect(pill).toHaveAttribute("data-install", "npm");});-test("the theme editor repaints the figure and rewrites the CSS", async ({ page }) => {+test("without a clipboard, copy selects the text instead and throws nothing", async ({ page }) => {+ await page.addInitScript(() => {+ Object.defineProperty(navigator, "clipboard", { value: { writeText: () => Promise.reject(new DOMException("denied", "NotAllowedError")) } });+ });+ const 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();+ 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();+ 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 }) => {+ await context.grantPermissions(["clipboard-read", "clipboard-write"]);await page.goto("/");- const theme = page.locator("section[aria-labelledby=theme]");- await theme.getByRole("button", { name: "Dark" }).click();- await expect(theme.locator("[data-theme-css]")).toContainText("--hairline-plate: #08090a;");- const fill = await theme.locator("[data-hairline] svg path").first().evaluate((el) => getComputedStyle(el).fill);- expect(fill).toBe("rgb(8, 9, 10)");+ await page.getByRole("link", { name: "Get started" }).click();+ await expect(page).toHaveURL(/#quickstart$/);+ 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();+ 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"]);});test("llms.txt and the registry item are served", async ({ request }) => {@@ -74,8 +150,26 @@ test("llms.txt and the registry item are served", async ({ request }) => {expect(item.files[0].content).toContain('"use client"');});-test("the page fits a phone", async ({ page }) => {+test("the page fits a phone, with the longest install command and every control", async ({ page }) => {await page.setViewportSize({ width: 390, height: 800 });await page.goto("/");- expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(390);+ const width = () => page.evaluate(() => document.documentElement.scrollWidth);+ expect(await width()).toBeLessThanOrEqual(390);++ const pill = page.locator("[data-install]").first();+ for (let i = 0; i < 4; i++) await pill.getByRole("button", { name: /: switch to/ }).click();+ await expect(pill).toHaveAttribute("data-install", "shadcn");+ expect(await width()).toBeLessThanOrEqual(390);++ const inspector = page.locator("[data-inspector]");+ for (const name of ["Turntable", "Dark"]) {+ const control = inspector.getByRole("button", { 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" />');+ expect(await width()).toBeLessThanOrEqual(390);});