Skip to content

Isometric line figures that answer the pointer. For React and for anything with a DOM.

Docs, Inspo and Skill: pages in the craft of a rail, each section hung off its group's mark on a hairline

Lucas Marques72dbcc2d9225
diff --git a/apps/site/app/docs/page.tsx b/apps/site/app/docs/page.tsx
index 4c905fa..d7e1f98 100644
--- a/apps/site/app/docs/page.tsx
+++ b/apps/site/app/docs/page.tsx
@@ -1,6 +1,8 @@
import type { Metadata } from "next";
+import type { CSSProperties } from "react";
import { Footer, Topbar } from "@/components/chrome";
-import { Sidebar } from "@/components/sidebar";
+import { Rail, type RailGroup } from "@/components/rail";
+import { SECTIONS, type Group } from "@/lib/docs";
import { LINKS } from "@/lib/figures";
import { highlight } from "@/lib/highlight";
import { tiny } from "@/lib/size";
@@ -9,8 +11,19 @@ import { Api, GettingStarted, Reference } from "./sections";
const SITE = process.env.NEXT_PUBLIC_SITE_URL!;
+/** A block's place in the header's entrance. */
+const at = (i: number) => ({ "--i": i }) as CSSProperties;
+
export const metadata: Metadata = { title: "Docs · hairline", alternates: { canonical: "/docs" } };
+/** Each group of the rail under its own mark and colour. */
+const MARK: Record<Group, Pick<RailGroup, "icon" | "color">> = {
+ "Getting started": { icon: "bolt", color: "#3b82f6" },
+ API: { icon: "braces", color: "#8b5cf6" },
+ Reference: { icon: "stack", color: "#f59e0b" },
+};
+const RAIL: RailGroup[] = (Object.keys(MARK) as Group[]).map((group) => ({ title: group, ...MARK[group], items: SECTIONS.filter((s) => s.group === group) }));
+
/**
* The docs: one page of sections. A Server Component, so every snippet is
* highlighted at build and each figure goes through server rendering and
@@ -30,23 +43,21 @@ export default async function Docs() {
return (
<>
<Topbar />
- <div className="docs">
- <Sidebar />
- <main className="docs-main">
- <header className="max-w-[64ch]">
- <h1 className="text-[36px] font-medium leading-[1.05] tracking-[-0.035em] text-balance md:text-[44px]">Six figures, one set of options.</h1>
- <p className="mt-4 text-[16px] leading-[1.55] text-muted">
- Every figure takes the same four options and draws itself in SVG, with no dependencies. Install the package, paste a figure, and turn <code className="doc-code">intensity</code> up or down.
- </p>
- </header>
- <GettingStarted commands={install(SITE)} size={tiny()} quickstart={quickstart} />
- <Api code={{ reactSignature, react, vanillaSignature, vanilla, cdn }} />
- <Reference css={css} />
- <p className="doc-note">
- Anything missing? <a className="doc-more" href={`${LINKS.github}/issues`}>Open an issue on GitHub</a>.
+ <Rail label="Docs" groups={RAIL} />
+ <main className="col">
+ <header className="hero-rise">
+ <h1 className="col-h1" style={at(0)}>Six figures, one set of options.</h1>
+ <p className="col-lede" style={at(1)}>
+ Every figure takes the same four options and draws itself in SVG, with no dependencies. Install the package, paste a figure, and turn <code className="doc-code">intensity</code> up or down.
</p>
- </main>
- </div>
+ </header>
+ <GettingStarted commands={install(SITE)} size={tiny()} quickstart={quickstart} />
+ <Api code={{ reactSignature, react, vanillaSignature, vanilla, cdn }} />
+ <Reference css={css} />
+ <p className="col-end">
+ Anything missing? <a className="doc-more" href={`${LINKS.github}/issues`}>Open an issue on GitHub</a>.
+ </p>
+ </main>
<Footer />
</>
);
diff --git a/apps/site/app/docs/sections.tsx b/apps/site/app/docs/sections.tsx
index a65e9ef..6bc96ae 100644
--- a/apps/site/app/docs/sections.tsx
+++ b/apps/site/app/docs/sections.tsx
@@ -1,5 +1,6 @@
import type { ReactNode } from "react";
import { Exploded, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";
+import { Anchor } from "@/components/anchor";
import { CodeBlock } from "@/components/code-block";
import { Install } from "@/components/install";
import { Tabs, type Tab } from "@/components/tabs";
@@ -9,12 +10,15 @@ import { PACKAGE } from "@/lib/snippets";
const SMALL = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable };
-/** A section takes its title from SECTIONS, the list the sidebar reads, so the two always agree. */
+/** A section takes its title from SECTIONS, the list the rail reads, so the two always agree. Its link copies from beside its title. */
function Section({ id, children }: { id: string; children: ReactNode }) {
const { title } = SECTIONS.find((s) => s.id === id)!;
return (
<section id={id} aria-labelledby={`${id}-title`} className="doc-section">
- <h2 id={`${id}-title`} className="doc-h2">{title}</h2>
+ <div className="doc-head">
+ <h2 id={`${id}-title`} className="doc-h2">{title}</h2>
+ <Anchor id={id} title={title} />
+ </div>
{children}
</section>
);
@@ -38,7 +42,7 @@ export function GettingStarted({ commands, size, quickstart }: { commands: { lab
</Section>
<Section id="options">
<p className="doc-p">Every figure takes the same four options, all optional.</p>
- <div className="overflow-x-auto">
+ <div className="tbl-card">
<table className="props" data-options>
<thead>
<tr><th>Option</th><th>Type</th><th>Default</th><th>What it does</th></tr>
@@ -87,22 +91,22 @@ export function Reference({ css }: { css: string }) {
<>
<Section id="figures">
<p className="doc-p">Every figure takes <C>intensity</C>, from 0 to 1. Here is what it turns up.</p>
- <ul className="grid">
+ <ul className="grid gap-[10px]">
{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-[15px] leading-[1.5]">Higher intensity: {doc.stronger}</p>
- <p className="mt-1 max-w-[52ch] text-[14px] leading-[1.55] text-muted">{doc.summary}</p>
+ <h3 className="figure-name">{doc.name}</h3>
+ <p className="figure-text"><b>Higher intensity:</b> {doc.stronger}</p>
+ <p className="figure-text">{doc.summary}</p>
</div>
- <div className="tile w-full max-w-[240px] justify-self-end"><Small /></div>
+ <div className="tile"><Small /></div>
</li>
);
})}
</ul>
- <div className="table-scroll" tabIndex={0} role="region" aria-label="What intensity sets in each figure">
+ <div className="table-scroll tbl-card" tabIndex={0} role="region" aria-label="What intensity sets in each figure">
<table className="intensity" data-intensity>
<thead>
<tr><th>Figure</th><th>Parameter</th><th>0</th><th>0.5</th><th>1</th></tr>
@@ -124,7 +128,7 @@ export function Reference({ css }: { css: string }) {
<p className="doc-p">
Six custom properties, set on the figure or on any ancestor. Without them a figure is light, or dark when an ancestor has class <C>dark</C> or <C>data-theme=&quot;dark&quot;</C>, or when the page&rsquo;s <C>color-scheme</C> is dark.
</p>
- <div className="overflow-x-auto">
+ <div className="tbl-card">
<table className="props" data-tokens>
<thead>
<tr><th>Property</th><th>Light</th><th>Role</th></tr>
diff --git a/apps/site/app/globals.css b/apps/site/app/globals.css
index 0585fee..79603f9 100644
--- a/apps/site/app/globals.css
+++ b/apps/site/app/globals.css
@@ -15,6 +15,9 @@
:root {
--topbar: 54px;
+ --gutter: clamp(18px, 5vw, 28px);
+ /* a card drawn by its shadow alone: a hairline ring, then two soft drops */
+ --card: 0 0 0 1px #0000000f, 0 1px 2px -1px #0000000f, 0 2px 4px 0 #0000000a;
--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);
@@ -119,8 +122,12 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }
.code-body[data-plain] .line::before { content: none; }
.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); }
+/* a figure on its card: its name and what it does, the figure small at the right */
+.figure-row { display: grid; grid-template-columns: minmax(0, 1fr) 150px; align-items: center; gap: 16px; padding: 12px 12px 12px 16px; border-radius: 12px; background: #fff; box-shadow: var(--card); }
+.figure-name { font-size: 13.5px; font-weight: 500; line-height: 1.4; }
+.figure-text { margin-top: 4px; font-size: 13px; line-height: 1.55; color: var(--color-muted); text-wrap: pretty; }
+.figure-text b { font-weight: 500; color: var(--color-ink); }
+.figure-row .tile { box-shadow: inset 0 0 0 1px var(--color-stone); }
.props, .intensity { width: 100%; border-collapse: collapse; font-size: 13px; }
:is(.props, .intensity) th { padding: 8px 14px 8px 0; text-align: left; font-size: 13px; font-weight: 500; color: var(--color-muted); }
:is(.props, .intensity) td { padding: 12px 14px 12px 0; vertical-align: top; border-top: 1px solid var(--color-line); line-height: 1.5; }
@@ -129,53 +136,113 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }
.props[data-tokens] td:nth-child(3) { white-space: normal; color: var(--color-ink); }
.intensity td { white-space: nowrap; }
.intensity td:nth-child(n + 3) { color: var(--color-muted); font-variant-numeric: tabular-nums; }
-.table-scroll { overflow-x: auto; border-radius: 4px; }
+.table-scroll { overflow-x: auto; }
+/* a table on a card, its first and last cells kept off the card's edge */
+.tbl-card { padding: 4px 16px; border-radius: 12px; background: #fff; box-shadow: var(--card); }
+.tbl-card :is(th, td):last-child { padding-right: 0; }
+
+/* A page in the craft of a rail: one 640px column of 14px text, and beside it from 1100px a rail of the page's
+ sections, fixed by the column's left edge. The column then steps right of the rail, inside the 1080px column the top
+ bar keeps to, so the rail lines up under the name. */
+.col { max-width: calc(640px + 2 * var(--gutter)); margin: 0 auto; padding: 56px var(--gutter) 96px; font-size: 14px; line-height: 1.6; }
+.col > * { min-width: 0; }
+.col-label { font: 400 11.5px/1 var(--font-mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-muted); }
+.col-h1 { margin-top: 10px; font-size: 16px; font-weight: 500; line-height: 1.35; letter-spacing: -0.01em; text-wrap: balance; }
+.col-h1 em { font-family: var(--font-serif); font-size: 1.12em; font-weight: 400; letter-spacing: 0; }
+.col header > .col-h1:first-child { margin-top: 0; }
+.col-lede { margin-top: 12px; max-width: 60ch; color: var(--color-muted); text-wrap: pretty; }
+.col-end { margin-top: 64px; padding-top: 20px; border-top: 1px solid var(--color-line); font-size: 13px; color: var(--color-muted); text-wrap: pretty; }
+.col-end .doc-more { font-size: inherit; }
-/* The docs: the header and nine sections in one column. Prose stops at 64ch; code and tables take the column. */
-.docs { --gutter: clamp(18px, 5vw, 28px); --doc-offset: calc(var(--topbar) + 60px); max-width: 1080px; margin: 0 auto; padding: 0 var(--gutter); }
-.docs-main { display: grid; gap: 64px; min-width: 0; padding: 48px 0 96px; }
-.docs-main > * { min-width: 0; }
-.doc-section { display: grid; gap: 16px; scroll-margin-top: var(--doc-offset); }
+/* A section opens 56px under the last, its title beside a link that shows when the pointer is on the title. */
+.doc-section { display: grid; gap: 14px; padding-top: 56px; scroll-margin-top: calc(var(--topbar) + 44px); }
.doc-section > * { min-width: 0; }
-.doc-h2 { font-size: 24px; font-weight: 500; line-height: 1.2; letter-spacing: -0.02em; text-wrap: balance; }
-.doc-p, .doc-list { max-width: 64ch; font-size: 15px; line-height: 1.6; text-wrap: pretty; }
-.doc-list { display: grid; gap: 8px; padding-left: 1.2em; list-style: disc; }
-.doc-note { max-width: 64ch; font-size: 14px; line-height: 1.55; color: var(--color-muted); text-wrap: pretty; }
+.doc-head { display: flex; align-items: center; gap: 4px; min-height: 28px; }
+.doc-h2 { font-size: 14px; font-weight: 500; line-height: 1.4; letter-spacing: -0.005em; text-wrap: balance; }
+.anchor { width: 28px; height: 28px; opacity: 0; transition: opacity 150ms ease, color 150ms ease, background-color 150ms ease; }
+.doc-head:focus-within .anchor, .anchor[data-copied] { opacity: 1; }
+@media (hover: hover) { .doc-head:hover .anchor { opacity: 1; } }
+/* no hover on a touch screen: the link stays in view, quiet */
+@media (hover: none) { .anchor { opacity: 1; color: var(--color-faint); } }
+.doc-p, .doc-list { max-width: 64ch; font-size: 14px; line-height: 1.6; text-wrap: pretty; }
+.doc-list { display: grid; gap: 6px; padding-left: 1.2em; list-style: disc; }
+.doc-list li::marker { color: var(--color-faint); }
+.doc-note { max-width: 64ch; font-size: 13px; line-height: 1.55; color: var(--color-muted); text-wrap: pretty; }
.doc-code { font-size: 0.9em; color: var(--color-ink); }
.doc-more { justify-self: start; font-size: 14px; color: var(--color-ink); text-decoration: underline; text-decoration-color: var(--color-faint); text-underline-offset: 4px; }
@media (hover: hover) { .doc-more:hover { text-decoration-color: currentColor; } }
+/* code in the column is a white card, as the tables and figures are */
+.col .code { background: #fff; box-shadow: var(--card); }
+.col .code-bar { border-bottom-color: var(--color-line); }
+.col .code-body { font-size: 12.5px; }
-/* The sidebar: the same links twice, grouped in a column from 1024px, one sideways strip under the top bar below it. */
+/* The rail and the strip: the same links twice, grouped in the rail from 1100px, one sideways strip under the top bar
+ below it. */
.doc-link { position: relative; display: flex; align-items: center; height: 32px; padding: 0 10px; border-radius: 8px; font-size: 14px; color: var(--color-muted); white-space: nowrap; transition: color 200ms ease; }
.doc-link[aria-current] { color: var(--color-ink); }
@media (hover: hover) { .doc-link:hover { color: var(--color-ink); } }
/* in the strip, where a finger picks, a 40px target inside the strip's own padding */
.doc-strip .doc-link::after { content: ""; position: absolute; inset: -4px 0; }
-/* The marked link's text steps aside for a dot that flies in from the link marked before. The old text steps back at
- once and the new one steps aside as the dot lands, so the two never meet. Nothing moves until the first mark is
- drawn: the page opens with it in place. */
+/* In the strip, the marked link's text steps aside for a dot that flies in from the link marked before. The old text
+ steps back at once and the new one steps aside as the dot lands, so the two never meet. Nothing moves until the first
+ mark is drawn: the page opens with it in place. */
.doc-link > span { display: inline-block; }
-.doc-link[aria-current] > span { transform: translateX(12px); }
-[data-live] .doc-link > span { transition: transform 250ms var(--ease-out); }
-[data-live] .doc-link[aria-current] > span { transition-duration: 300ms; transition-delay: 160ms; }
+.doc-strip .doc-link[aria-current] > span { transform: translateX(12px); }
+.doc-strip [data-live] .doc-link > span { transition: transform 250ms var(--ease-out); }
+.doc-strip [data-live] .doc-link[aria-current] > span { transition-duration: 300ms; transition-delay: 160ms; }
.doc-dot { position: absolute; top: 0; left: 0; width: 5px; height: 5px; border-radius: 50%; background: var(--color-ink); pointer-events: none; }
[data-live] > .doc-dot { transition: translate 350ms var(--ease-out); }
-.doc-sidebar { display: none; }
-.doc-group-label { margin-bottom: 4px; padding: 0 10px; font-size: 12px; font-weight: 500; color: var(--color-muted); }
-.doc-strip { position: sticky; top: var(--topbar); z-index: 9; margin: 0 calc(-1 * var(--gutter)); background: color-mix(in srgb, var(--color-canvas) 82%, transparent); backdrop-filter: blur(12px); }
-.doc-strip-scroll { position: relative; overflow-x: auto; padding: 6px var(--gutter); scrollbar-width: none; }
+
+/* the rail's two ends fade, so a list taller than the window runs out softly instead of being cut */
+.fade-mask-y { mask-image: linear-gradient(to bottom, transparent, #0000001a 0.375rem, #00000059 0.75rem, #000000a6 1.125rem, #000000d9 1.5rem, #000000f2 1.875rem, #000 2.25rem, #000 calc(100% - 2.25rem), #000000f2 calc(100% - 1.875rem), #000000d9 calc(100% - 1.5rem), #000000a6 calc(100% - 1.125rem), #00000059 calc(100% - 0.75rem), #0000001a calc(100% - 0.375rem), transparent); }
+.rail { display: none; }
+.rail-group { display: grid; gap: 6px; }
+.rail-title { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 500; line-height: 1.5; color: var(--color-ink); transition: color 240ms ease; }
+.rail-title svg { flex: none; color: var(--gc); transition: filter 240ms ease, opacity 240ms ease; }
+/* Once a section is marked, only its group is lit: the others' marks go grey and their titles fade. */
+.doc-sidebar:has([aria-current]) .rail-group:not(:has([aria-current])) .rail-title { color: #525252; }
+.doc-sidebar:has([aria-current]) .rail-group:not(:has([aria-current])) .rail-title svg { filter: grayscale(1); opacity: 0.4; }
+.rail .doc-link { height: auto; padding: 3px 0; border-radius: 0; font-size: 13px; line-height: 1.5; }
+.rail .doc-link::after { content: ""; position: absolute; inset: -2px -8px; }
+
+/* The links hang off their group's mark on a hairline: a trunk down from the mark's centre, and an arm that bends out to
+ each link. Each row draws its own stretch of trunk and its arm, from 6px over the row before's centre, so the rows
+ stack into one line. The marked row's line is drawn in the group's colour: the trunk reaches down to the row's bend,
+ then the arm draws out, then a tip lands at its end; the line to a row left behind draws back the other way. */
+.rail ul { position: relative; padding-left: 24px; }
+.rail li { position: relative; }
+.rail li::before, .rail li::after { content: ""; position: absolute; left: -17px; width: 11px; border: 0 solid #e5e5e5; border-width: 0 0 1px 1px; border-bottom-left-radius: 6px; pointer-events: none; }
+.rail li::before { top: calc(-50% - 6px); bottom: 50%; }
+.rail li:first-child::before { top: -2px; }
+.rail li::after { top: calc(50% - 6px); height: 6px; border-color: var(--gc); clip-path: inset(0 100% 0 0); }
+.rail li:has(> [aria-current])::after { clip-path: inset(0); }
+.rail ul::after { content: ""; position: absolute; top: -2px; bottom: 0; left: 7px; width: 1px; background: var(--gc); transform: scaleY(var(--reach, 0)); transform-origin: top; pointer-events: none; }
+.rail .doc-link::before { content: ""; position: absolute; top: calc(50% - 2.5px); left: -6.5px; width: 4px; height: 4px; border-radius: 50%; background: var(--gc); transform: scale(0); }
+.rail .doc-link[aria-current]::before { transform: none; }
+.rail [data-live] ul::after { transition: transform 300ms var(--ease-out); }
+.rail [data-live] li::after { transition: clip-path 140ms ease-out; }
+.rail [data-live] li:has(> [aria-current])::after { transition: clip-path 220ms var(--ease-out) 160ms; }
+.rail [data-live] .doc-link::before { transition: transform 120ms ease-out; }
+.rail [data-live] .doc-link[aria-current]::before { transition: transform 260ms cubic-bezier(0.34, 1.56, 0.64, 1) 320ms; }
+
+.doc-strip { position: sticky; top: var(--topbar); z-index: 9; background: color-mix(in srgb, var(--color-canvas) 82%, transparent); backdrop-filter: blur(12px); }
+/* the strip's first link keeps to the column's text: its 10px padding hangs out past it */
+.doc-strip-scroll { position: relative; overflow-x: auto; padding: 6px max(calc(var(--gutter) - 10px), calc((100% - 640px) / 2 - 10px)); scrollbar-width: none; }
.doc-strip-scroll::-webkit-scrollbar { display: none; }
.doc-strip-scroll ul { display: flex; gap: 8px; width: max-content; }
.doc-strip-scroll[data-start] { mask-image: linear-gradient(to right, transparent, #000 24px); }
.doc-strip-scroll[data-end] { mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent); }
.doc-strip-scroll[data-start][data-end] { mask-image: linear-gradient(to right, transparent, #000 24px, #000 calc(100% - 24px), transparent); }
-@media (min-width: 1024px) {
- .docs { --doc-offset: calc(var(--topbar) + 24px); display: grid; grid-template-columns: 220px minmax(0, 1fr); column-gap: 56px; padding-top: 64px; }
- .docs-main { padding-top: 0; }
+@media (min-width: 1100px) {
.doc-strip { display: none; }
- /* short enough to fit the window from where it starts, 64px under the top bar, with 24px to spare; a shorter
- window scrolls it */
- .doc-sidebar { display: grid; gap: 24px; align-self: start; position: sticky; top: calc(var(--topbar) + 24px); max-height: calc(100vh - var(--topbar) - 88px); overflow-y: auto; scrollbar-width: thin; }
+ .doc-section { scroll-margin-top: var(--topbar); }
+ .col { max-width: none; margin: 0; padding-right: var(--gutter); padding-left: calc(max(var(--gutter), (100% - 1080px) / 2 + var(--gutter)) + 260px); }
+ .col > * { max-width: 640px; }
+ /* fixed by the column's left edge and centred in the window under the top bar; a window too short for it scrolls it */
+ .rail { position: fixed; top: var(--topbar); bottom: 0; left: max(var(--gutter), calc((100% - 1080px) / 2 + var(--gutter))); z-index: 5; display: flex; flex-direction: column; justify-content: center; gap: 28px; width: 220px; padding: 3rem 0; }
+ /* on a short window the sections scroll inside the rail */
+ .doc-sidebar { position: relative; display: grid; gap: 28px; min-height: 0; overflow-y: auto; scrollbar-width: none; }
+ .doc-sidebar::-webkit-scrollbar { display: none; }
}
/* The hero: each block rises out of a blur, one after another. */
@@ -284,90 +351,50 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }
.s-range { flex: 1; width: auto; }
}
-/* Inspo: an essay. Everything sits on one centred axis: prose keeps to the measure, and the evidence (pictures, the
- ledger of pushback) takes the page's width around it. */
-.inspo { --gutter: clamp(18px, 5vw, 28px); --measure: 640px; display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; gap: 80px; max-width: 1080px; margin: 0 auto; padding: 56px var(--gutter) 96px; }
-.inspo-prose, .inspo-step > * { width: 100%; max-width: var(--measure); }
-.inspo-label { font: 400 12px/1 var(--font-mono); letter-spacing: 0.02em; text-transform: uppercase; color: var(--color-muted); }
-.inspo-title { margin-top: 20px; font-size: 44px; font-weight: 500; line-height: 1.02; letter-spacing: -0.045em; text-wrap: balance; }
-.inspo-title em { font-family: var(--font-serif); font-size: 1.08em; font-weight: 400; letter-spacing: -0.02em; }
-.inspo-lede { margin-top: 24px; font-size: 18px; line-height: 1.5; color: var(--color-muted); text-wrap: pretty; }
-/* the seven steps as a way in: two columns that read down, each row a 40px target */
-.inspo-toc { margin-top: 40px; }
-.inspo-toc ol { display: grid; border-bottom: 1px solid var(--color-line); }
-.inspo-toc a { display: flex; align-items: baseline; gap: 14px; padding: 11px 0; border-top: 1px solid var(--color-line); font-size: 14px; line-height: 18px; color: var(--color-muted); transition: color 150ms ease; }
-@media (hover: hover) { .inspo-toc a:hover { color: var(--color-ink); } }
-.inspo-step { display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; gap: 24px; width: 100%; }
-/* a step opens under a hairline, its number over its title */
-.inspo-h2 { display: grid; gap: 16px; padding-top: 28px; border-top: 1px solid var(--color-line); font-size: 24px; font-weight: 500; line-height: 1.15; letter-spacing: -0.025em; text-wrap: balance; scroll-margin-top: calc(var(--topbar) + 16px); }
-.inspo-n { font: 400 12px/1 var(--font-mono); letter-spacing: 0.02em; color: var(--color-muted); font-variant-numeric: tabular-nums; }
-.inspo-p { font-size: 16px; line-height: 1.65; text-wrap: pretty; }
-/* A prompt: a white card like the site's other surfaces, a row per part, its label in a column of its own when there is room. */
-.inspo-prompt { margin-block: 8px; border-radius: 16px; background: #fff; box-shadow: inset 0 0 0 1px var(--color-stone), var(--lift); }
-.inspo-prompt > .inspo-label { padding: 18px 20px; }
-.inspo-quote { font-size: 15px; line-height: 1.6; text-wrap: pretty; }
-.inspo-part { display: grid; gap: 8px; padding: 16px 20px; border-top: 1px solid var(--color-line); }
-.inspo-part > .inspo-label { line-height: 1.5; }
-/* The pushback: a ledger. What I said, and across from it what that changed. */
-.inspo-pushback { display: grid; counter-reset: turn; }
-.inspo-pushback li { position: relative; display: grid; gap: 10px; padding: 22px 0 22px 40px; border-top: 1px solid var(--color-line); counter-increment: turn; }
-.inspo-pushback li:last-child { border-bottom: 1px solid var(--color-line); }
-.inspo-pushback li::before { content: counter(turn, decimal-leading-zero); position: absolute; top: 28px; left: 0; font: 400 12px/1 var(--font-mono); letter-spacing: 0.02em; color: var(--color-muted); font-variant-numeric: tabular-nums; }
-.inspo-said { font-size: 16px; line-height: 1.55; text-wrap: pretty; }
-.inspo-changed { font-size: 14px; line-height: 1.6; color: var(--color-muted); text-wrap: pretty; }
-.inspo-changed::before { content: "Changed: "; color: var(--color-ink); font-weight: 500; }
-/* A picture on its plate. The plate's corner is the picture's plus the padding between them. */
-.inspo-figure { display: grid; justify-items: center; gap: 14px; margin-block: 16px; }
-.inspo-step > .inspo-figure, .inspo-step > .inspo-pushback, .inspo-step > .inspo-split { max-width: none; }
-.inspo-shot { --pad: clamp(6px, 1.6vw, 16px); width: 100%; padding: var(--pad); border-radius: calc(8px + var(--pad)); background: var(--color-ink); }
-.inspo-shot img { display: block; width: 100%; height: auto; border-radius: 8px; }
-.inspo-caption { width: 100%; max-width: var(--measure); font-size: 13px; line-height: 1.5; color: var(--color-muted); text-wrap: pretty; }
-.inspo-split { display: grid; justify-items: center; gap: 24px; }
-.inspo-split-text { display: grid; gap: 16px; width: 100%; max-width: var(--measure); }
-.inspo-split .inspo-figure { width: 100%; max-width: 480px; margin-block: 8px 0; }
-.inspo-rules { display: grid; }
-.inspo-rules li { display: grid; gap: 10px; padding: 20px 0; border-top: 1px solid var(--color-line); }
-.inspo-rules li:last-child { border-bottom: 1px solid var(--color-line); }
-.inspo-rules .inspo-n { line-height: 24px; text-transform: uppercase; }
-.inspo-rules li > div { display: grid; gap: 4px; }
-.inspo-rule { font-size: 16px; font-weight: 500; line-height: 1.5; }
-.inspo-rules .inspo-p { font-size: 15px; line-height: 1.6; color: var(--color-muted); }
-/* what the story leaves behind, a line each */
-.inspo-keep { display: grid; font-size: 16px; line-height: 1.55; text-wrap: pretty; }
-.inspo-keep li { padding: 16px 0; border-top: 1px solid var(--color-line); }
-.inspo-keep li:last-child { border-bottom: 1px solid var(--color-line); }
+/* Inspo, as an essay: the story in the column, each step under its number, the evidence on cards between the prose. */
+.inspo-label { font: 400 11.5px/1.5 var(--font-mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-muted); }
+.inspo .col-h1 { margin-top: 10px; }
+.inspo-step .doc-h2 { display: flex; align-items: baseline; gap: 10px; }
+.inspo-n { font: 500 11.5px/1 var(--font-mono); letter-spacing: 0.02em; color: var(--color-faint); font-variant-numeric: tabular-nums; }
+.inspo-p { text-wrap: pretty; }
+.card { border-radius: 12px; background: #fff; box-shadow: var(--card); }
+/* the brief: a card with a row per part, its label in a column of its own when there is room */
+.inspo-prompt { margin-block: 2px; padding: 6px 16px; }
+.inspo-prompt > .inspo-label { padding: 10px 0; }
+.inspo-quote { font-size: 13px; line-height: 1.55; text-wrap: pretty; }
+.inspo-part { display: grid; gap: 4px; padding: 12px 0; border-top: 1px solid var(--color-line); }
+/* a picture in the dark frame it was taken in, a light ring inside its edge */
+.inspo-figure { display: grid; gap: 8px; margin-block: 6px; }
+.inspo-shot { position: relative; overflow: hidden; border-radius: 12px; background: #0b0b0c; box-shadow: var(--card); }
+.inspo-shot::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08); pointer-events: none; }
+.inspo-shot img { display: block; width: 100%; height: auto; }
+.inspo-caption { font-size: 12.5px; line-height: 1.5; color: var(--color-muted); text-wrap: pretty; }
+/* the pushback: what I said on a card, and under it, set off by a green rule, what that changed */
+.inspo-pushback { display: grid; gap: 12px; margin-block: 2px; }
+.inspo-pushback li { padding: 14px 16px; }
+.inspo-said { font-size: 13.5px; line-height: 1.55; text-wrap: pretty; }
+.inspo-changed { margin-top: 8px; padding-left: 12px; border-left: 2px solid #10b981; font-size: 13px; line-height: 1.55; color: var(--color-muted); text-wrap: pretty; }
+.inspo-rules { display: grid; gap: 10px; }
+.inspo-rules li { display: grid; gap: 6px; padding: 14px 16px; }
+.inspo-rules .inspo-n { line-height: 21px; text-transform: uppercase; }
+.inspo-rule { font-weight: 500; }
+.inspo-rules .inspo-p { margin-top: 2px; font-size: 13px; line-height: 1.55; color: var(--color-muted); }
+/* what the story leaves behind, numbered */
+.inspo-keep { display: grid; gap: 10px; counter-reset: keep; }
+.inspo-keep li { display: grid; grid-template-columns: 28px minmax(0, 1fr); color: var(--color-muted); text-wrap: pretty; counter-increment: keep; }
+.inspo-keep li::before { content: counter(keep, decimal-leading-zero); font: 400 11.5px/22px var(--font-mono); color: var(--color-faint); font-variant-numeric: tabular-nums; }
/* a 14px link on its own gets a taller target than its text */
-.inspo .doc-more { display: inline-block; margin-block: -10px; padding-block: 10px; }
+.inspo-step .doc-more { display: inline-block; margin-block: -10px; padding-block: 10px; }
@media (min-width: 600px) {
- .inspo-toc ol { grid-auto-flow: column; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(4, auto); column-gap: 32px; }
- .inspo-part { grid-template-columns: 148px minmax(0, 1fr); align-items: baseline; gap: 20px; }
- .inspo-rules li { grid-template-columns: 84px minmax(0, 1fr); gap: 12px; }
-}
-@media (min-width: 768px) {
- .inspo { gap: 112px; padding-top: 96px; }
- .inspo-title { font-size: 64px; }
- .inspo-lede { font-size: 20px; }
- .inspo-h2 { font-size: 28px; }
- .inspo-keep { font-size: 18px; }
-}
-/* from here the ledger and the bench have the width for two columns */
-@media (min-width: 960px) {
- .inspo-pushback li { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); align-items: baseline; gap: 48px; padding-left: 56px; }
- .inspo-said { font-size: 17px; }
-}
-/* the bench beside its story: the words keep the measure's left edge and the picture runs to the page's right */
-@media (min-width: 1024px) {
- .inspo-split { grid-template-columns: calc((100% - var(--measure)) / 2) minmax(0, 1fr) 400px; align-items: center; justify-items: stretch; gap: 0; margin-top: 16px; }
- .inspo-split-text { grid-column: 2; max-width: none; padding-right: 48px; }
- .inspo-split .inspo-figure { max-width: none; margin: 0; }
+ .inspo-part { grid-template-columns: 130px minmax(0, 1fr); align-items: baseline; gap: 12px; }
+ .inspo-rules li { grid-template-columns: 76px minmax(0, 1fr); gap: 0; }
}
:is(button, a, input, .code-body, .table-scroll):focus-visible { outline: 1.5px solid var(--color-ink); outline-offset: 2px; }
@media (max-width: 640px) {
- /* a row stacks, text first, and the figure keeps its width */
- .figure-row { grid-template-columns: minmax(0, 1fr); gap: 16px; }
- .figure-row .tile { justify-self: start; }
+ /* a row stacks, text first, the figure under it */
+ .figure-row { grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 12px; }
/* 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); }
@@ -381,37 +408,38 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }
.icopy-b, .icopy[data-copied] .icopy-a { transform: none; filter: none; }
.prompt-idea { transform: none; filter: none; transition: opacity 200ms ease; }
.prompt:active, .prompt:active .prompt-key { transform: none; }
- [data-live] > .doc-dot, [data-live] .doc-link > span { transition: none; }
+ [data-live] > .doc-dot, .doc-strip [data-live] .doc-link[aria-current] > span, .doc-strip [data-live] .doc-link > span { transition: none; }
+ .rail [data-live] ul::after, .rail [data-live] li::after, .rail [data-live] li:has(> [aria-current])::after,
+ .rail [data-live] .doc-link::before, .rail [data-live] .doc-link[aria-current]::before { transition: none; }
}
-/* /skill: the pitch, then each prompt beside the page it produced, then how it works and how to use it. */
-.skill { display: grid; gap: 72px; max-width: 1080px; margin: 0 auto; padding: 64px clamp(18px, 5vw, 28px) 96px; }
-.skill > * { min-width: 0; }
-.skill-install { margin-top: 28px; max-width: 460px; }
-.example { display: grid; gap: 16px; padding: 28px 0; border-top: 1px solid var(--color-line); }
-.example:last-child { border-bottom: 1px solid var(--color-line); }
-.example > * { min-width: 0; }
-.example-prompt { position: relative; z-index: 1; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-content: start; }
-.example-figure { container-type: inline-size; }
-/* the prompt and its follow-up, one exchange: the follow-up is marked as the next turn */
-.example-turns { display: grid; gap: 8px; }
-.example-then { padding: 2px 16px 0; font-size: 12px; font-weight: 500; line-height: 1; color: var(--color-muted); }
+/* /skill, as a catalogue: how to get it and use it, the steps, then a card per idea the skill has drawn. */
+.skill .pill { box-shadow: var(--card); }
+.skill [data-command="usage"] { max-width: 460px; }
/* a prompt is read, not run: it wraps in its pill when it must, and the copy icon stays by its first line. Only the
install command, a shell line, keeps to one line and scrolls. */
.pill:is([data-command="prompt"], [data-command="follow-up"], [data-command="usage"]) { height: auto; min-height: 48px; padding-block: 6px; align-items: start; }
.pill:is([data-command="prompt"], [data-command="follow-up"], [data-command="usage"]) .pill-line { padding-block: 8px; line-height: 20px; white-space: normal; overflow: visible; text-wrap: pretty; }
-/* The generated page pads its column by 24px above and below and 16px at the sides. The frame bleeds by that much,
- so the plate meets the column: its edges on the column's, its top on the prompt's. Stacked, the frame's top padding
- runs under the prompt above it, which is drawn over the frame, so the plate sits one gap under the prompt. The height is the one the page takes before it is measured: its plate, as
- wide as the column up to 640px, a 5:4 stage, and the 148px of controls and lines under it, which wrap onto more
+.howto { display: grid; gap: 10px; counter-reset: step; }
+.howto > li { display: grid; grid-template-columns: 28px minmax(0, 1fr); color: var(--color-muted); text-wrap: pretty; counter-increment: step; }
+.howto > li::before { content: counter(step, decimal-leading-zero); font: 400 11.5px/22px var(--font-mono); color: var(--color-faint); font-variant-numeric: tabular-nums; }
+.howto b { font-weight: 500; color: var(--color-ink); }
+/* An example's card: the prompt in its header, flat, beside a link to the file; what it drew and the turn after it;
+ then the page itself, in a frame under a hairline. */
+.ex { overflow: hidden; margin-top: 4px; }
+.ex-h { display: flex; align-items: flex-start; gap: 4px; padding: 0 6px 0 2px; border-bottom: 1px solid var(--color-line); }
+.ex-h .pill { flex: 1; min-width: 0; background: none; box-shadow: none; font-size: 12.5px; }
+.ex-open { position: relative; flex: none; display: grid; place-items: center; width: 36px; height: 36px; margin-top: 6px; border-radius: 50%; color: var(--color-muted); transition: color 150ms ease, background-color 150ms ease; }
+@media (hover: hover) { .ex-open:hover { color: var(--color-ink); background: var(--color-stone); } }
+.ex-b { padding: 12px 16px 14px; }
+.ex-name { font: 500 12px/1.5 var(--font-mono); }
+.ex-means { margin-top: 2px; font-size: 13px; line-height: 1.55; color: var(--color-muted); text-wrap: pretty; }
+.ex-fu { margin-top: 10px; padding-left: 12px; border-left: 2px solid var(--color-line); }
+.ex-then { font: 400 10.5px/1.5 var(--font-mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-muted); }
+.ex-fu .pill { margin-left: -16px; background: none; box-shadow: none; font-size: 12.5px; }
+.example-figure { container-type: inline-size; border-top: 1px solid var(--color-line); }
+/* The generated page pads its column by 24px above and below and 16px at the sides, so in the card the plate sits
+ inside that much white. The height is the one the page takes before it is measured: its plate, as wide as the
+ column less its sides up to 640px, a 5:4 stage, and the 148px of controls and lines under it, which wrap onto more
lines in a column narrower than 360px. */
-.example-frame { display: block; width: calc(100% + 32px); margin: -24px -16px; height: calc(min(100cqw, 640px) * 0.8 + 148px + max(0px, 360px - 100cqw) * 0.75); border: 0; }
-.skill-steps { display: grid; gap: 12px; max-width: 64ch; counter-reset: step; }
-.skill-steps > li { display: grid; grid-template-columns: 2.2em minmax(0, 1fr); align-items: baseline; font-size: 15px; line-height: 1.55; color: var(--color-muted); counter-increment: step; }
-.skill-steps > li::before { content: counter(step, decimal-leading-zero); font: 400 12px/1 var(--font-mono); font-variant-numeric: tabular-nums; color: var(--color-faint); }
-.skill-steps strong { font-weight: 500; color: var(--color-ink); }
-
-@media (min-width: 900px) {
- .example { grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); gap: 40px; align-items: start; }
- .example-prompt { position: sticky; top: calc(var(--topbar) + 24px); }
-}
+.example-frame { display: block; width: 100%; height: calc(min(100cqw - 32px, 640px) * 0.8 + 148px + 48px + max(0px, 392px - 100cqw) * 0.75); border: 0; }
diff --git a/apps/site/app/inspo/page.tsx b/apps/site/app/inspo/page.tsx
index 0dbafcd..d9323e8 100644
--- a/apps/site/app/inspo/page.tsx
+++ b/apps/site/app/inspo/page.tsx
@@ -2,6 +2,7 @@ import type { Metadata } from "next";
import Image, { type StaticImageData } from "next/image";
import type { CSSProperties, ReactNode } from "react";
import { Footer, Topbar } from "@/components/chrome";
+import { Rail } from "@/components/rail";
import craft from "@/public/inspo/craft.webp";
import dissection from "@/public/inspo/dissection.webp";
import figures from "@/public/inspo/figures.webp";
@@ -18,17 +19,18 @@ export const metadata: Metadata = {
openGraph: { title: TITLE, description: DESCRIPTION, url: "/inspo", siteName: "hairline", type: "article", images: [{ url: "/og.png", width: 1200, height: 630, alt: "Line drawings that answer the pointer: the Terrain figure, its pillars rising." }] },
};
-/** The story's parts, in order: the header lists them and each step takes its title from here. */
+/** The story's parts, in order: the rail lists them and each step takes its title from here. */
const STEPS = ["A feeling, not a look", "The brief", "What came back", "Pushback", "The design pass", "Into a package", "What I’d keep"];
+const RAIL = [{ title: "How it was made", icon: "book" as const, color: "#f43f5e", items: STEPS.map((title, i) => ({ id: `step-${i + 1}`, title })) }];
const two = (n: number) => String(n).padStart(2, "0");
const at = (i: number) => ({ "--i": i }) as CSSProperties;
-/** One part of the story: under a hairline, a mono number over its title, then the prose. */
+/** One part of the story: a mono number before its title, then the prose. */
function Step({ n, children }: { n: number; children: ReactNode }) {
return (
- <section data-step aria-labelledby={`step-${n}`} className="inspo-step">
- <h2 id={`step-${n}`} className="inspo-h2">
+ <section id={`step-${n}`} data-step aria-labelledby={`step-${n}-title`} className="doc-section inspo-step">
+ <h2 id={`step-${n}-title`} className="doc-h2">
<span className="inspo-n">{two(n)}</span>
{STEPS[n - 1]}
</h2>
@@ -40,7 +42,7 @@ function Step({ n, children }: { n: number; children: ReactNode }) {
/** What I asked, in words close to the ones I used. A long prompt keeps its parts, each under a small label. */
function Prompt({ label, children }: { label: string; children: ReactNode }) {
return (
- <figure className="inspo-prompt">
+ <figure className="inspo-prompt card">
<figcaption className="inspo-label">{label}</figcaption>
<blockquote className="inspo-quote">{children}</blockquote>
</figure>
@@ -54,7 +56,7 @@ const Part = ({ name, children }: { name: string; children: ReactNode }) => (
</div>
);
-/** A picture on the dark plate it was taken on. */
+/** A picture in the dark frame it was taken in. */
function Shot({ src, alt, caption, priority }: { src: StaticImageData; alt: string; caption: string; priority?: boolean }) {
return (
<figure className="inspo-figure">
@@ -93,31 +95,20 @@ const PUSHBACK = [
/**
* The story behind the package, told in steps: a feeling worth explaining, a long brief, what came back, the arguing,
- * a pass of taste, then the package. Prose keeps to a reading measure; the pictures take the page's width.
+ * a pass of taste, then the package. One column at a reading measure, the rail of steps beside it.
*/
export default function Inspo() {
return (
<>
<Topbar />
- <main className="inspo">
- <header className="inspo-prose hero-rise">
+ <Rail label="Steps" groups={RAIL} />
+ <main className="col inspo">
+ <header className="hero-rise">
<p className="inspo-label" style={at(0)}>Inspo</p>
- <h1 className="inspo-title" style={at(1)}>How Hairline was <em>made</em></h1>
- <p className="inspo-lede" style={at(2)}>
+ <h1 className="col-h1 mt-[6px]" style={at(1)}>How Hairline was <em>made</em></h1>
+ <p className="col-lede" style={at(2)}>
Not with one prompt. With a long brief, a lot of questions, and every correction written down as a rule so it couldn&rsquo;t come back. Claude Opus did the building, a live Artifact was the bench, and the judgement stayed with me.
</p>
- <nav aria-label="Steps" className="inspo-toc" style={at(3)}>
- <ol>
- {STEPS.map((title, i) => (
- <li key={title}>
- <a href={`#step-${i + 1}`}>
- <span className="inspo-n">{two(i + 1)}</span>
- {title}
- </a>
- </li>
- ))}
- </ol>
- </nav>
</header>
<Step n={1}>
@@ -169,23 +160,19 @@ export default function Inspo() {
</p>
<ol className="inspo-pushback" data-pushback>
{PUSHBACK.map((p) => (
- <li key={p.said}>
+ <li key={p.said} className="card">
<p className="inspo-said">&ldquo;{p.said}&rdquo;</p>
<p className="inspo-changed" data-changed>{p.changed}</p>
</li>
))}
</ol>
- <div className="inspo-split">
- <div className="inspo-split-text">
- <p className="inspo-p">
- Asking for sliders was the turn that paid most. Once the Artifact was a bench instead of a document, I stopped reading claims and started judging by hand: drag the knob, move the pointer, say exactly what feels off.
- </p>
- <p className="inspo-p">
- Those knobs later collapsed into a single option, <code className="doc-code">intensity</code>.
- </p>
- </div>
- <Shot src={tune} alt="The Terrain figure in the first Artifact, mid-hover: a few pillars raised bright near the pointer, a note on its radial falloff underneath, and a slider set to a radius of 3 cells." caption="Terrain on the bench, its radius on a slider." />
- </div>
+ <p className="inspo-p">
+ Asking for sliders was the turn that paid most. Once the Artifact was a bench instead of a document, I stopped reading claims and started judging by hand: drag the knob, move the pointer, say exactly what feels off.
+ </p>
+ <p className="inspo-p">
+ Those knobs later collapsed into a single option, <code className="doc-code">intensity</code>.
+ </p>
+ <Shot src={tune} alt="The Terrain figure in the first Artifact, mid-hover: a few pillars raised bright near the pointer, a note on its radial falloff underneath, and a slider set to a radius of 3 cells." caption="Terrain on the bench, its radius on a slider." />
</Step>
<Step n={5}>
@@ -206,7 +193,7 @@ export default function Inspo() {
<Part name="Write it down">Make these rules 09 and 10, so the next figure can&rsquo;t break them.</Part>
</Prompt>
<ol className="inspo-rules">
- <li>
+ <li className="card">
<span className="inspo-n">Rule 09</span>
<div>
<p className="inspo-rule">Round every corner, then draw less.</p>
@@ -215,7 +202,7 @@ export default function Inspo() {
</p>
</div>
</li>
- <li>
+ <li className="card">
<span className="inspo-n">Rule 10</span>
<div>
<p className="inspo-rule">No words inside the figure.</p>
@@ -247,7 +234,7 @@ export default function Inspo() {
</ul>
</Step>
- <p className="inspo-prose doc-note">
+ <p className="col-end">
The reference image belongs to Linear and appears here as a reference only. The figures and the code in Hairline are original.
</p>
</main>
diff --git a/apps/site/app/skill/page.tsx b/apps/site/app/skill/page.tsx
index 9f27aef..4edaa66 100644
--- a/apps/site/app/skill/page.tsx
+++ b/apps/site/app/skill/page.tsx
@@ -1,8 +1,10 @@
import type { Metadata } from "next";
-import type { CSSProperties } from "react";
+import type { CSSProperties, ReactNode } from "react";
+import { Anchor } from "@/components/anchor";
import { Footer, Topbar } from "@/components/chrome";
import { Command } from "@/components/command";
import { ExampleFrame } from "@/components/example-frame";
+import { Rail } from "@/components/rail";
import { LINKS } from "@/lib/figures";
import { COMMAND, FOLDER, INSTALL, STEPS, SUMMARY, USE, examples } from "@/lib/skill";
@@ -19,68 +21,104 @@ const at = (i: number) => ({ "--i": i }) as CSSProperties;
export const metadata: Metadata = { title: "Make your own figure · hairline", description: SUMMARY, alternates: { canonical: "/skill" } };
+const RAIL = [
+ {
+ title: "hairline-create",
+ icon: "sparkle" as const,
+ color: "#8b5cf6",
+ items: [
+ { id: "install", title: "Install" },
+ { id: "use", title: "How to use it" },
+ { id: "how", title: "How it works" },
+ { id: "examples", title: "What it draws" },
+ ],
+ },
+];
+
+/** A section in the column: its title beside a button that copies its link. */
+function Section({ id, title, children }: { id: string; title: string; children: ReactNode }) {
+ return (
+ <section id={id} aria-labelledby={`${id}-title`} className="doc-section">
+ <div className="doc-head">
+ <h2 id={`${id}-title`} className="doc-h2">{title}</h2>
+ <Anchor id={id} title={title} />
+ </div>
+ {children}
+ </section>
+ );
+}
+
/**
- * The skill's page: what it draws first, then how to get it and use it. A
- * Server Component: it reads each example's name and meaning from the page
- * the skill wrote, and that page is shown as it is, in a frame.
+ * The skill's page, as a catalogue: how to get it and use it, then each idea it has drawn, on a card with the line
+ * that asked for it and the page it wrote, in a frame. A Server Component: it reads each example's name and meaning
+ * from that page.
*/
export default function Skill() {
const shown = examples();
return (
<>
<Topbar />
- <main className="skill">
+ <Rail label="Skill" groups={RAIL} />
+ <main className="col skill">
{/* the home's hero sends people here, and the header arrives as the hero does */}
<header className="hero-rise">
- <h1 className="max-w-[16ch] text-[36px] font-medium leading-[1.05] tracking-[-0.035em] text-balance md:text-[44px]" style={at(0)}>Make your own figure</h1>
- <p className="mt-4 max-w-[64ch] text-[16px] leading-[1.55] text-muted" style={at(1)}>{SUMMARY}</p>
- <div className="skill-install" style={at(2)}><Command code={INSTALL} kind="install" label="Copy install command" /></div>
+ <p className="col-label" style={at(0)}>Skill</p>
+ <h1 className="col-h1" style={at(1)}>Make your own figure</h1>
+ <p className="col-lede" style={at(2)}>{SUMMARY}</p>
</header>
- <section aria-labelledby="examples-title" className="doc-section">
- <h2 id="examples-title" className="doc-h2">What it draws</h2>
- <p className="doc-p">Each figure below is the page the skill wrote for the line next to it. Move the pointer over one.</p>
- <div>
- {shown.map((e) => (
- <article key={e.file} className="example" data-example={e.name} aria-label={e.prompt}>
- <div className="example-prompt">
- {/* one exchange: the prompt, and the change asked for next */}
- <div className="example-turns">
- <Command code={e.prompt} kind="prompt" label={`Copy prompt: ${e.idea}`} />
- {e.followUp && (
- <>
- <p className="example-then">then</p>
- <Command code={e.followUp} kind="follow-up" label={`Copy follow-up: ${e.idea}`} />
- </>
- )}
- </div>
- </div>
- <div className="example-figure">
- <ExampleFrame src={`${e.href}?theme=light`} title={e.means} />
- </div>
- </article>
- ))}
- </div>
- </section>
+ <Section id="install" title="Install">
+ <Command code={INSTALL} kind="install" label="Copy install command" />
+ <p className="doc-p">{FOLDER}</p>
+ </Section>
+
+ <Section id="use" title="How to use it">
+ <Command code={`${COMMAND} <idea>`} kind="usage" label="Copy command" />
+ <ul role="list" className="doc-list">
+ {USE.map((line) => <li key={line}>{named(line)}</li>)}
+ </ul>
+ </Section>
- <section aria-labelledby="how-title" className="doc-section">
- <h2 id="how-title" className="doc-h2">How it works</h2>
- <ol className="skill-steps" data-steps>
+ <Section id="how" title="How it works">
+ <ol className="howto" data-steps>
{STEPS.map((s) => (
- <li key={s.title}><span><strong>{s.title}.</strong> {s.text}</span></li>
+ <li key={s.title}><span><b>{s.title}.</b> {s.text}</span></li>
))}
</ol>
- <p className="doc-note">{FOLDER}</p>
- </section>
+ </Section>
+
+ <Section id="examples" title="What it draws">
+ <p className="doc-p">Four ideas, four files. Each one opens from disk with no dependencies. Move the pointer over one.</p>
+ {shown.map((e) => (
+ <article key={e.file} className="card ex" data-example={e.name} aria-label={e.prompt}>
+ <div className="ex-h">
+ <Command code={e.prompt} kind="prompt" label={`Copy prompt: ${e.idea}`} />
+ <a className="ex-open" href={e.href} target="_blank" rel="noreferrer" aria-label={`Open ${e.file} in a new tab`} title="Open the file">
+ <svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
+ <path d="M6 3.75H4.25a1.5 1.5 0 0 0-1.5 1.5v6.5a1.5 1.5 0 0 0 1.5 1.5h6.5a1.5 1.5 0 0 0 1.5-1.5V10M9 2.75h4.25V7M13 3 7.5 8.5" />
+ </svg>
+ </a>
+ </div>
+ <div className="ex-b">
+ <p className="ex-name">{e.name}</p>
+ <p className="ex-means">{e.means}</p>
+ {e.followUp && (
+ <div className="ex-fu">
+ <p className="ex-then">Then asked</p>
+ <Command code={e.followUp} kind="follow-up" label={`Copy follow-up: ${e.idea}`} />
+ </div>
+ )}
+ </div>
+ <div className="ex-f example-figure">
+ <ExampleFrame src={`${e.href}?theme=light`} title={e.means} />
+ </div>
+ </article>
+ ))}
+ </Section>
- <section aria-labelledby="use-title" className="doc-section">
- <h2 id="use-title" className="doc-h2">How to use it</h2>
- <div className="max-w-[460px]"><Command code={`${COMMAND} <idea>`} kind="usage" label="Copy command" /></div>
- {USE.map((line) => <p key={line} className="doc-p">{named(line)}</p>)}
- <p className="doc-note">
- The six figures and their options are in <a className="doc-more" href="/docs">the docs</a>. The skill&rsquo;s files are in <a className="doc-more" href={`${LINKS.github}/tree/main/skills/hairline-create`}>its folder on GitHub</a>.
- </p>
- </section>
+ <p className="col-end">
+ The six figures and their options are in <a className="doc-more" href="/docs">the docs</a>. The skill&rsquo;s files are in <a className="doc-more" href={`${LINKS.github}/tree/main/skills/hairline-create`}>its folder on GitHub</a>.
+ </p>
</main>
<Footer />
</>
diff --git a/apps/site/components/anchor.tsx b/apps/site/components/anchor.tsx
new file mode 100644
index 0000000..25decf2
--- /dev/null
+++ b/apps/site/components/anchor.tsx
@@ -0,0 +1,23 @@
+"use client";
+
+import { useCopy } from "./copy";
+
+/**
+ * A heading's link, copied: shown when the pointer is on the heading or the key is on the button. The chain gives way
+ * to a check as the copy icon's clipboard does, through scale, opacity and blur.
+ */
+export function Anchor({ id, title }: { id: string; title: string }) {
+ const [copied, copy] = useCopy();
+ return (
+ <button type="button" className="icopy anchor" data-copied={copied || undefined} aria-label={`Copy link to ${title}`} title="Copy link" onClick={() => copy(`${location.origin}${location.pathname}#${id}`)}>
+ <svg className="icopy-a" viewBox="0 0 16 16" width="13" height="13" aria-hidden="true" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
+ <path d="M6.75 9.25a2.75 2.75 0 0 0 3.9 0l2-2a2.75 2.75 0 0 0-3.9-3.9l-.6.6" />
+ <path d="M9.25 6.75a2.75 2.75 0 0 0-3.9 0l-2 2a2.75 2.75 0 0 0 3.9 3.9l.6-.6" />
+ </svg>
+ <svg className="icopy-b" viewBox="0 0 16 16" width="13" height="13" 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/rail.tsx b/apps/site/components/rail.tsx
new file mode 100644
index 0000000..ac3eb40
--- /dev/null
+++ b/apps/site/components/rail.tsx
@@ -0,0 +1,232 @@
+"use client";
+
+import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ReactNode } from "react";
+
+export type RailIcon = "bolt" | "braces" | "stack" | "book" | "sparkle";
+export type RailGroup = { title: string; icon: RailIcon; color: string; items: { id: string; title: string }[] };
+
+const svg = (children: ReactNode) => (
+ <svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
+ {children}
+ </svg>
+);
+
+/** A group's mark, drawn in the group's colour: a light fill under a line, as the page's other icons are drawn. */
+const ICONS: Record<RailIcon, ReactNode> = {
+ bolt: svg(<path d="M9 1.75 3.5 9h4L7 14.25 12.5 7h-4L9 1.75Z" fill="currentColor" fillOpacity=".2" />),
+ braces: svg(
+ <>
+ <rect x="1.75" y="2.75" width="12.5" height="10.5" rx="2.5" fill="currentColor" fillOpacity=".2" stroke="none" />
+ <path d="M6 5c-1 0-1.25.5-1.25 1.25v.5C4.75 7.5 4.5 8 3.75 8c.75 0 1 .5 1 1.25v.5C4.75 10.5 5 11 6 11M10 5c1 0 1.25.5 1.25 1.25v.5c0 .75.25 1.25 1 1.25-.75 0-1 .5-1 1.25v.5c0 .75-.25 1.25-1.25 1.25" />
+ </>,
+ ),
+ stack: svg(
+ <>
+ <path d="m8 2 6 3-6 3-6-3 6-3Z" fill="currentColor" fillOpacity=".2" />
+ <path d="m2 8 6 3 6-3M2 11l6 3 6-3" />
+ </>,
+ ),
+ book: svg(
+ <>
+ <path d="M2.5 3.25A1.5 1.5 0 0 1 4 1.75h9.5v10H4a1.5 1.5 0 0 0-1.5 1.5v-10Z" fill="currentColor" fillOpacity=".16" />
+ <path d="M2.5 13.25a1.5 1.5 0 0 0 1.5 1.5h9.5v-3" />
+ </>,
+ ),
+ sparkle: svg(
+ <>
+ <path d="M8 1.75c.4 3.1 1.9 4.6 5 5-3.1.4-4.6 1.9-5 5-.4-3.1-1.9-4.6-5-5 3.1-.4 4.6-1.9 5-5Z" fill="currentColor" fillOpacity=".2" />
+ <path d="M12.75 11.25v2.5M11.5 12.5H14" />
+ </>,
+ ),
+};
+
+/**
+ * The section in view: the first one, in page order, inside a band from under the sticky chrome (a section's
+ * scroll-margin-top, read each time, as it differs on a phone) to 30% down the viewport. Null in a gap between two
+ * sections, where the mark stays put.
+ */
+function inView(sections: HTMLElement[]): string | null {
+ const first = sections[0].id;
+ const last = sections[sections.length - 1].id;
+ const top = parseFloat(getComputedStyle(sections[0]).scrollMarginTop) || 0;
+ const bottom = window.innerHeight * 0.3;
+ if (window.innerHeight + window.scrollY >= document.documentElement.scrollHeight - 2) {
+ // the last section is too short to reach the band, so the end of the page marks it; unless the reader asked for
+ // a section the page could only bring into view, on a screen taller than what is left below it
+ const asked = sections.find((s) => `#${s.id}` === window.location.hash);
+ const at = asked?.getBoundingClientRect();
+ return asked && at && at.top >= 0 && at.top < window.innerHeight ? asked.id : last;
+ }
+ const hit = sections.find((s) => {
+ const at = s.getBoundingClientRect();
+ // a pixel of slack: the section scrolled to sits flush under the chrome, and the one before can end a fraction below
+ return at.bottom > top + 1 && at.top < bottom;
+ });
+ if (hit) return hit.id;
+ // above the first section nothing is in the band, so the first is marked, as at the top
+ return sections[0].getBoundingClientRect().top >= bottom ? first : null;
+}
+
+/**
+ * Puts the strip's dot by the marked link's text, on its centre line. The first time, the dot appears in place; after
+ * that it flies there.
+ */
+function place(list: HTMLElement | null, active: string) {
+ const dot = list?.querySelector<HTMLElement>(".doc-dot");
+ const link = list?.querySelector<HTMLElement>(`a[href="#${active}"]`);
+ if (!list || !dot || !link || !list.clientWidth) return;
+ const box = list.getBoundingClientRect();
+ const at = link.getBoundingClientRect();
+ const x = at.left - box.left + list.scrollLeft + parseFloat(getComputedStyle(link).paddingLeft);
+ const y = at.top - box.top + list.scrollTop + (at.height - dot.offsetHeight) / 2;
+ dot.style.translate = `${x}px ${y}px`;
+ live(list);
+}
+
+/**
+ * Draws the rail's line to the marked link: each group's trunk reaches down to the marked row's bend, 6px over its
+ * centre, or back up to nothing in the other groups. The row's arm and tip take it from there, in CSS.
+ */
+function reach(nav: HTMLElement | null, active: string) {
+ if (!nav?.clientWidth) return;
+ for (const list of nav.querySelectorAll<HTMLElement>("ul")) {
+ const row = list.querySelector(`a[href="#${active}"]`)?.parentElement;
+ // the trunk runs from 2px over the list to its foot
+ const f = row ? (row.offsetTop + row.offsetHeight / 2 - 4) / (list.offsetHeight + 2) : 0;
+ list.style.setProperty("--reach", String(f));
+ }
+ live(nav);
+}
+
+/** Transitions start once the first mark has been drawn, so the page opens with it in place. */
+function live(el: HTMLElement) {
+ if (!el.hasAttribute("data-live")) requestAnimationFrame(() => requestAnimationFrame(() => el.setAttribute("data-live", "")));
+}
+
+/**
+ * A page's anchors, in the craft of a rail: fixed at the column's left edge from 1100px, each group's links hung off
+ * its mark on a hairline; one sideways strip under the top bar below it. All are plain links, so they work without
+ * JavaScript. The script marks the section in view, and nothing is marked until it runs: in the rail the line to it
+ * is drawn in its group's colour and only its group stays lit; in the strip a dot flies to it.
+ * A link picked by hand marks its section at once, and the mark holds while the page glides there.
+ */
+export function Rail({ label, groups }: { label: string; groups: RailGroup[] }) {
+ const [active, setActive] = useState<string | null>(null);
+ const [edges, setEdges] = useState({ start: false, end: false });
+ const column = useRef<HTMLElement>(null);
+ const strip = useRef<HTMLDivElement>(null);
+ const held = useRef(0);
+ const items = groups.flatMap((g) => g.items);
+ const ids = items.map((s) => s.id).join(" ");
+
+ useEffect(() => {
+ const sections = ids.split(" ").map((id) => document.getElementById(id)).filter((el): el is HTMLElement => el !== null);
+ if (!sections.length) return;
+ let timer = 0;
+ const pick = () => {
+ if (performance.now() < held.current) return;
+ const id = inView(sections);
+ if (id) setActive(id);
+ };
+ const release = () => {
+ held.current = 0;
+ pick();
+ };
+ const hold = (event: MouseEvent) => {
+ const a = (event.target as Element | null)?.closest<HTMLAnchorElement>("a[href^='#']");
+ const id = a?.hash.slice(1);
+ if (!id || !sections.some((s) => s.id === id)) return;
+ setActive(id);
+ held.current = performance.now() + 1000;
+ clearTimeout(timer);
+ timer = window.setTimeout(release, 1000);
+ };
+ pick();
+ window.addEventListener("scroll", pick, { passive: true });
+ window.addEventListener("scrollend", release);
+ window.addEventListener("resize", pick);
+ document.addEventListener("click", hold);
+ // the browser has already scrolled to a deep link's section, at once; the reader's own clicks from here on glide
+ document.documentElement.dataset.smooth = "";
+ return () => {
+ clearTimeout(timer);
+ window.removeEventListener("scroll", pick);
+ window.removeEventListener("scrollend", release);
+ window.removeEventListener("resize", pick);
+ document.removeEventListener("click", hold);
+ delete document.documentElement.dataset.smooth;
+ };
+ }, [ids]);
+
+ useEffect(() => {
+ const el = strip.current;
+ if (!el) return;
+ const measure = () => setEdges({ start: el.scrollLeft > 1, end: el.scrollLeft + el.clientWidth < el.scrollWidth - 1 });
+ measure();
+ el.addEventListener("scroll", measure, { passive: true });
+ const resize = new ResizeObserver(measure);
+ resize.observe(el);
+ return () => {
+ el.removeEventListener("scroll", measure);
+ resize.disconnect();
+ };
+ }, []);
+
+ // before paint, so the mark is never drawn by a link that is no longer marked
+ useLayoutEffect(() => {
+ if (!active) return;
+ reach(column.current, active);
+ place(strip.current, active);
+ // a list that was hidden shows, or the window changes width: the line and the dot keep to their link
+ const resize = new ResizeObserver(() => {
+ reach(column.current, active);
+ place(strip.current, active);
+ });
+ for (const el of [column.current, strip.current]) if (el) resize.observe(el);
+ return () => resize.disconnect();
+ }, [active]);
+
+ // Brings the marked item into the strip by scrolling the strip alone. scrollIntoView would also scroll the
+ // page, and would cut short the smooth scroll a click on the strip has just started.
+ useEffect(() => {
+ const el = strip.current;
+ const item = el?.querySelector<HTMLElement>(`a[href="#${active}"]`);
+ if (!el || !item || !el.clientWidth) return;
+ const pad = 24;
+ const box = el.getBoundingClientRect();
+ const at = item.getBoundingClientRect();
+ if (at.left - pad < box.left) el.scrollTo({ left: el.scrollLeft + at.left - pad - box.left });
+ else if (at.right + pad > box.right) el.scrollTo({ left: el.scrollLeft + at.right + pad - box.right });
+ }, [active]);
+
+ const link = (id: string, title: string) => (
+ <li key={id}>
+ <a href={`#${id}`} className="doc-link" aria-current={id === active ? "location" : undefined}>
+ <span>{title}</span>
+ </a>
+ </li>
+ );
+ const dot = active && <span className="doc-dot" aria-hidden />;
+ const tint = (color: string) => ({ "--gc": color }) as CSSProperties;
+
+ return (
+ <>
+ <aside className="rail fade-mask-y">
+ <nav ref={column} aria-label={label} className="doc-sidebar">
+ {groups.map((group) => (
+ <div key={group.title} className="rail-group" style={tint(group.color)}>
+ <p className="rail-title">{ICONS[group.icon]}{group.title}</p>
+ <ul>{group.items.map((s) => link(s.id, s.title))}</ul>
+ </div>
+ ))}
+ </nav>
+ </aside>
+ <nav aria-label={label} className="doc-strip">
+ <div ref={strip} className="doc-strip-scroll" data-start={edges.start || undefined} data-end={edges.end || undefined}>
+ <ul>{items.map((s) => link(s.id, s.title))}</ul>
+ {dot}
+ </div>
+ </nav>
+ </>
+ );
+}
diff --git a/apps/site/components/sidebar.tsx b/apps/site/components/sidebar.tsx
deleted file mode 100644
index 2f9f24c..0000000
--- a/apps/site/components/sidebar.tsx
+++ /dev/null
@@ -1,158 +0,0 @@
-"use client";
-
-import { useEffect, useLayoutEffect, useRef, useState } from "react";
-import { SECTIONS, type Group } from "@/lib/docs";
-
-const GROUPS = [...new Set(SECTIONS.map((s) => s.group))] as Group[];
-const LAST = SECTIONS[SECTIONS.length - 1].id;
-
-/**
- * The section in view: the first one, in page order, inside a band from under the sticky chrome (a section's
- * scroll-margin-top, read each time, as it differs on a phone) to 30% down the viewport. Null in a gap between two
- * sections, where the mark stays put.
- */
-function inView(sections: HTMLElement[]): string | null {
- const top = parseFloat(getComputedStyle(sections[0]).scrollMarginTop) || 0;
- const bottom = window.innerHeight * 0.3;
- if (window.innerHeight + window.scrollY >= document.documentElement.scrollHeight - 2) {
- // the last section is too short to reach the band, so the end of the page marks it; unless the reader asked for
- // a section the page could only bring into view, on a screen taller than what is left below it
- const asked = sections.find((s) => `#${s.id}` === window.location.hash);
- const at = asked?.getBoundingClientRect();
- return asked && at && at.top >= 0 && at.top < window.innerHeight ? asked.id : LAST;
- }
- const hit = sections.find((s) => {
- const at = s.getBoundingClientRect();
- return at.bottom > top && at.top < bottom;
- });
- if (hit) return hit.id;
- // above the first section nothing is in the band, so Install is marked, as at the top
- return sections[0].getBoundingClientRect().top >= bottom ? SECTIONS[0].id : null;
-}
-
-/**
- * Puts a list's dot by the marked link's text, on its centre line. The first time, the dot appears in place; after
- * that it flies there, and in the column it swings out to the left on the way, like a thrown thing.
- */
-function place(list: HTMLElement | null, active: string, swing: boolean) {
- const dot = list?.querySelector<HTMLElement>(".doc-dot");
- const link = list?.querySelector<HTMLElement>(`a[href="#${active}"]`);
- if (!list || !dot || !link || !list.clientWidth) return;
- const box = list.getBoundingClientRect();
- const at = link.getBoundingClientRect();
- const x = at.left - box.left + list.scrollLeft + parseFloat(getComputedStyle(link).paddingLeft);
- const y = at.top - box.top + list.scrollTop + (at.height - dot.offsetHeight) / 2;
- const to = `${x}px ${y}px`;
- if (dot.style.translate === to) return;
- if (!list.hasAttribute("data-live")) {
- dot.style.translate = to;
- // transitions start once the first mark has been drawn, so the page opens with it in place
- requestAnimationFrame(() => requestAnimationFrame(() => list.setAttribute("data-live", "")));
- return;
- }
- dot.style.translate = to;
- if (swing && !matchMedia("(prefers-reduced-motion: reduce)").matches) {
- dot.animate([{ transform: "none" }, { transform: "translateX(-10px)", offset: 0.35 }, { transform: "none" }], { duration: 350, easing: "ease-in-out" });
- }
-}
-
-/**
- * The docs' anchors: grouped in a column beside the page from 1024px, one sideways strip under the top bar below it.
- * Both are plain links, so they work without JavaScript; the script marks the section in view with a dot, and
- * nothing is marked until it runs.
- */
-export function Sidebar() {
- const [active, setActive] = useState<string | null>(null);
- const [edges, setEdges] = useState({ start: false, end: false });
- const column = useRef<HTMLElement>(null);
- const strip = useRef<HTMLDivElement>(null);
-
- useEffect(() => {
- const sections = SECTIONS.map((s) => document.getElementById(s.id)).filter((el): el is HTMLElement => el !== null);
- if (!sections.length) return;
- const pick = () => {
- const id = inView(sections);
- if (id) setActive(id);
- };
- pick();
- window.addEventListener("scroll", pick, { passive: true });
- window.addEventListener("resize", pick);
- // the browser has already scrolled to a deep link's section, at once; the reader's own clicks from here on glide
- document.documentElement.dataset.smooth = "";
- return () => {
- window.removeEventListener("scroll", pick);
- window.removeEventListener("resize", pick);
- delete document.documentElement.dataset.smooth;
- };
- }, []);
-
- useEffect(() => {
- const el = strip.current;
- if (!el) return;
- const measure = () => setEdges({ start: el.scrollLeft > 1, end: el.scrollLeft + el.clientWidth < el.scrollWidth - 1 });
- measure();
- el.addEventListener("scroll", measure, { passive: true });
- const resize = new ResizeObserver(measure);
- resize.observe(el);
- return () => {
- el.removeEventListener("scroll", measure);
- resize.disconnect();
- };
- }, []);
-
- // before paint, so the dot is never drawn by a link that is no longer marked
- useLayoutEffect(() => {
- if (!active) return;
- const both = () => {
- place(column.current, active, true);
- place(strip.current, active, false);
- };
- both();
- // a list that was hidden shows, or the window changes width: the dot keeps to its link
- const resize = new ResizeObserver(both);
- for (const el of [column.current, strip.current]) if (el) resize.observe(el);
- return () => resize.disconnect();
- }, [active]);
-
- // Brings the marked item into the strip by scrolling the strip alone. scrollIntoView would also scroll the
- // page, and would cut short the smooth scroll a click on the strip has just started.
- useEffect(() => {
- const el = strip.current;
- const item = el?.querySelector<HTMLElement>(`a[href="#${active}"]`);
- if (!el || !item || !el.clientWidth) return;
- const pad = 24;
- const box = el.getBoundingClientRect();
- const at = item.getBoundingClientRect();
- if (at.left - pad < box.left) el.scrollTo({ left: el.scrollLeft + at.left - pad - box.left });
- else if (at.right + pad > box.right) el.scrollTo({ left: el.scrollLeft + at.right + pad - box.right });
- }, [active]);
-
- const link = (id: string, title: string) => (
- <li key={id}>
- <a href={`#${id}`} className="doc-link" aria-current={id === active ? "location" : undefined}>
- <span>{title}</span>
- </a>
- </li>
- );
- const dot = active && <span className="doc-dot" aria-hidden />;
-
- return (
- <>
- <nav ref={column} aria-label="Docs" className="doc-sidebar">
- {GROUPS.map((group) => (
- <div key={group} className="doc-group">
- <p className="doc-group-label">{group}</p>
- <ul>{SECTIONS.filter((s) => s.group === group).map((s) => link(s.id, s.title))}</ul>
- </div>
- ))}
- {dot}
- </nav>
- <nav aria-label="Docs" className="doc-strip">
- <div ref={strip} className="doc-strip-scroll" data-start={edges.start || undefined} data-end={edges.end || undefined}>
- <ul>{SECTIONS.map((s) => link(s.id, s.title))}</ul>
- {dot}
- </div>
- </nav>
- </>
- );
-}
diff --git a/apps/site/test/site.spec.ts b/apps/site/test/site.spec.ts
index ec83c0e..96c9afc 100644
--- a/apps/site/test/site.spec.ts
+++ b/apps/site/test/site.spec.ts
@@ -522,61 +522,57 @@ test("on a phone the sidebar is one strip under the top bar, and it follows the
expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(390);
});
-test("the sidebar marks its section with one black dot before its ink text, and no pill", async ({ page }) => {
+test("the sidebar draws the line to its section in its group's colour, and only that group stays lit", async ({ page }) => {
await page.goto("/docs");
const nav = page.locator(".doc-sidebar");
await nav.getByRole("link", { name: "Theme" }).click();
await expect(nav.getByRole("link", { name: "Theme" })).toHaveAttribute("aria-current", "location");
const read = () => nav.evaluate((nav) => {
- const ink = (el: Element) => {
- const range = document.createRange();
- range.selectNodeContents(el);
- return range.getBoundingClientRect();
- };
+ const style = (el: Element, pseudo?: string) => getComputedStyle(el, pseudo);
const on = nav.querySelector("a[aria-current]")!;
const off = nav.querySelector("a:not([aria-current])")!;
- const dots = [...nav.querySelectorAll(".doc-dot")];
- const dot = dots[0]?.getBoundingClientRect();
- const box = on.getBoundingClientRect();
+ const group = on.closest(".rail-group")!;
+ const other = nav.querySelector(".rail-group:not(:has([aria-current]))")!;
+ const scale = (ul: Element) => new DOMMatrixReadOnly(style(ul, "::after").transform).d;
return {
- dots: dots.length,
- size: dot && [Math.round(dot.width), Math.round(dot.height)],
- fill: dots[0] && getComputedStyle(dots[0]).backgroundColor,
- round: dots[0] && getComputedStyle(dots[0]).borderRadius,
- level: dot && Math.abs(dot.top + dot.height / 2 - (box.top + box.height / 2)),
- clear: dot && ink(on).left - dot.right,
- inside: dot && dot.left >= box.left,
- // the text moves aside for the dot: its distance from the link's edge, against an unmarked link's
- shift: Math.round(ink(on).left - box.left - (ink(off).left - off.getBoundingClientRect().left)),
- on: [getComputedStyle(on).color, getComputedStyle(on).backgroundColor],
- off: [getComputedStyle(off).color, getComputedStyle(off).backgroundColor],
+ // the trunk reaches into the marked group alone, and one arm is drawn: the marked row's
+ reach: [...nav.querySelectorAll("ul")].map((ul) => scale(ul) > 0),
+ arms: [...nav.querySelectorAll("li")].filter((li) => style(li, "::after").clipPath === "inset(0px)").map((li) => li.textContent),
+ tip: [style(on, "::before").transform, style(on, "::before").backgroundColor, style(off, "::before").transform],
+ on: style(on).color,
+ off: style(off).color,
+ lit: [style(group.querySelector(".rail-title")!).color, style(group.querySelector("svg")!).filter],
+ dim: [style(other.querySelector(".rail-title")!).color, style(other.querySelector("svg")!).filter],
+ dots: nav.querySelectorAll(".doc-dot").length,
};
});
- await expect.poll(async () => (await read()).shift).toBe(12);
+ // the line has finished drawing: the arm is out and the tip has landed
+ await expect.poll(async () => {
+ const r = await read();
+ return [r.arms, r.tip[0]];
+ }).toEqual([["Theme"], "none"]);
const r = await read();
- expect(r.dots).toBe(1);
- expect(r.size).toEqual([5, 5]);
- expect(r.fill).toBe("rgb(10, 10, 10)");
- expect(r.round).toBe("50%");
- expect(r.level).toBeLessThan(1);
- expect(r.clear).toBeGreaterThanOrEqual(4);
- expect(r.inside).toBe(true);
- expect(r.on).toEqual(["rgb(10, 10, 10)", "rgba(0, 0, 0, 0)"]);
- expect(r.off).toEqual(["rgb(115, 115, 115)", "rgba(0, 0, 0, 0)"]);
-});
-
-test("the dot travels from section to section instead of jumping, and under reduced motion it jumps", async ({ page }) => {
+ expect(r.reach).toEqual([false, false, true]);
+ // the tip is in Reference's amber; the unmarked rows have none
+ expect(r.tip.slice(1)).toEqual(["rgb(245, 158, 11)", "matrix(0, 0, 0, 0, 0, 0)"]);
+ expect(r.on).toBe("rgb(10, 10, 10)");
+ expect(r.off).toBe("rgb(115, 115, 115)");
+ expect(r.lit).toEqual(["rgb(10, 10, 10)", "none"]);
+ expect(r.dim).toEqual(["rgb(82, 82, 82)", "grayscale(1)"]);
+ expect(r.dots).toBe(0);
+});
+
+test("the line draws from section to section instead of jumping, and under reduced motion it jumps", async ({ page }) => {
await page.goto("/docs");
const nav = page.locator(".doc-sidebar");
await expect(nav.getByRole("link", { name: "Install" })).toHaveAttribute("aria-current", "location");
+ // Reference's trunk, as it reaches down to Theme
const flight = () => nav.evaluate((nav) => new Promise<number[]>((done) => {
- const dot = nav.querySelector(".doc-dot")!;
+ const ul = nav.querySelectorAll("ul")[2];
const ys: number[] = [];
const t0 = performance.now();
const tick = () => {
- // from the column's top: the column itself moves up as it sticks
- const r = dot.getBoundingClientRect();
- ys.push(r.top + r.height / 2 - nav.getBoundingClientRect().top);
+ ys.push(new DOMMatrixReadOnly(getComputedStyle(ul, "::after").transform).d);
if (performance.now() - t0 < 700) requestAnimationFrame(tick);
else done(ys);
};
@@ -584,22 +580,17 @@ test("the dot travels from section to section instead of jumping, and under redu
// straight to Theme: no section passes through the band on the way, so the mark moves once
document.getElementById("theme")!.scrollIntoView({ behavior: "instant" });
}));
- const centre = (name: string) => nav.getByRole("link", { name }).evaluate((a) => {
- const r = a.getBoundingClientRect();
- return r.top + r.height / 2 - a.closest("nav")!.getBoundingClientRect().top;
- });
- const from = await centre("Install");
- const to = await centre("Theme");
const ys = await flight();
- expect(ys.filter((y) => y > from + 2 && y < to - 2).length).toBeGreaterThanOrEqual(3);
- expect(Math.abs(ys[ys.length - 1] - to)).toBeLessThan(1);
+ const to = ys[ys.length - 1];
+ expect(to).toBeGreaterThan(0.3);
+ expect(ys.filter((y) => y > 0.02 && y < to - 0.02).length).toBeGreaterThanOrEqual(3);
await page.emulateMedia({ reducedMotion: "reduce" });
await page.evaluate(() => window.scrollTo({ top: 0, behavior: "instant" }));
await expect(nav.getByRole("link", { name: "Install" })).toHaveAttribute("aria-current", "location");
await page.waitForTimeout(800);
const jump = await flight();
- expect(jump.filter((y) => y > from + 2 && y < to - 2)).toEqual([]);
+ expect(jump.filter((y) => y > 0.02 && y < to - 0.02)).toEqual([]);
});
test("a deep link marks only its own section, with no other marked first", async ({ page }) => {