Isometric line figures that answer the pointer. For React and for anything with a DOM.
Figures: the shelves are reordered by what each figure draws, the drawer closes cleanly, and the Data mark sits level with its name
Lucas Marques6c6e7b5995f9
diff --git a/apps/site/app/globals.css b/apps/site/app/globals.cssindex 02eaa12..c4dbf45 100644--- a/apps/site/app/globals.css+++ b/apps/site/app/globals.css@@ -21,6 +21,8 @@--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);+ /* the iOS sheet's curve: off the mark at once, then a short glide home */+ --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);/* a critically damped spring (no bounce, settles in 300ms), sampled: it leaves rest gently and eases home on a long tail, with no step in between */--spring-icon: linear(0, 0.057, 0.18, 0.32, 0.454, 0.572, 0.67, 0.749, 0.811, 0.859, 0.896, 0.923, 0.944, 0.959, 0.97, 0.979, 0.985, 0.989, 0.992, 0.994, 0.996, 0.997, 0.998, 0.999, 1);/* Code in greys, each at least 4.5:1 on the code frame's #fafafa. shiki writes these names. */@@ -479,11 +481,20 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }/* The drawer: a card fixed at the right under the top bar, a sheet from below on a phone. Its contents stay while itslides away and go once it is out of sight. */-.drawer { position: fixed; z-index: 20; inset: auto 0 0 0; max-height: 86vh; overflow-y: auto; overscroll-behavior: contain; padding: 18px var(--gutter) calc(24px + env(safe-area-inset-bottom, 0px)); background: #fff; border-radius: 18px 18px 0 0; box-shadow: var(--lift-lg), 0 0 0 1px var(--color-line); transform: translateY(102%); visibility: hidden; transition: transform 320ms var(--ease-out), visibility 0s 320ms; font-size: 14px; line-height: 1.6; }-/* hidden once it is out, or its shadow would show at the window's edge */-.drawer[data-open] { transform: none; visibility: visible; transition-delay: 0s; }-@media (min-width: 900px) { .drawer { inset: calc(var(--topbar) + 14px) 14px 14px auto; width: 360px; max-height: none; border-radius: 16px; padding: 18px 18px 22px; transform: translateX(calc(100% + 16px)); } }+.drawer { position: fixed; z-index: 20; inset: auto 0 0 0; max-height: 86vh; overflow-y: auto; overscroll-behavior: contain; padding: 18px var(--gutter) calc(24px + env(safe-area-inset-bottom, 0px)); background: #fff; border-radius: 18px 18px 0 0; box-shadow: var(--lift-lg), 0 0 0 1px var(--color-line); transform: translateY(102%); visibility: hidden; transition: transform 200ms var(--ease-drawer), visibility 0s 200ms; font-size: 14px; line-height: 1.6; }+/* hidden once it is out, or its shadow would show at the window's edge. It arrives in 320ms and leaves in 200ms: a+ close answers the hand at once, moving from its first frame, and is gone before the eye has followed it */+.drawer[data-open] { transform: none; visibility: visible; transition-duration: 320ms, 0s; transition-timing-function: var(--ease-out); transition-delay: 0s; }+@media (min-width: 900px) { .drawer { inset: calc(var(--topbar) + 14px) 14px 14px auto; width: 360px; max-height: none; border-radius: 16px; padding: 18px 18px 22px; } }@media (min-width: 1280px) { .drawer { right: max(14px, calc((100% - 1080px) / 2 - 376px + var(--gutter))); } }+/* On a desk the card does not slide out: its resting place moves with the window, and past ~1810px a slide of its own+ width would stop it inside the window and cut it off there. It steps back 24px and fades where it is, the same on any+ monitor, so the curve's tail passes while it is already clear, and it ends with the tile's ring (180ms). It opens+ the same way back. The reduced-motion block below still wins: the same fade without the 24px. */+@media (min-width: 900px) {+ .drawer { transform: translateX(24px); opacity: 0; transition: transform 180ms var(--ease-out), opacity 150ms ease, visibility 0s 180ms; }+ .drawer[data-open] { transform: none; opacity: 1; transition: transform 300ms var(--ease-out), opacity 200ms ease, visibility 0s; }+}.detail { display: grid; gap: 16px; }.detail-h { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }.detail-name { font-size: 16px; font-weight: 500; line-height: 1.3; letter-spacing: -0.01em; }@@ -514,5 +525,7 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }@media (prefers-reduced-motion: reduce) {.figs-body[data-enter] > section { animation: none; }.fig-tile, .shelf-list[data-live] .shelf-plate { transition: none; }- .drawer { transition-duration: 0s; }+ /* the drawer stays where it rests and only fades in and out */+ .drawer { transform: none; opacity: 0; transition: opacity 150ms ease, visibility 0s 150ms; }+ .drawer[data-open] { opacity: 1; transition: opacity 150ms ease, visibility 0s; }}diff --git a/apps/site/components/catalogue.tsx b/apps/site/components/catalogue.tsxindex 4c48fdf..7853a9e 100644--- a/apps/site/components/catalogue.tsx+++ b/apps/site/components/catalogue.tsx@@ -34,9 +34,9 @@ const ICONS: Record<Filter, ReactNode> = {),data: svg(<>- <rect x="2" y="8" width="3" height="6" rx="1" fill="currentColor" fillOpacity=".2" />- <rect x="6.5" y="4" width="3" height="10" rx="1" fill="currentColor" fillOpacity=".2" />- <rect x="11" y="6" width="3" height="8" rx="1" fill="currentColor" fillOpacity=".2" />+ <rect x="2" y="7" width="3" height="6" rx="1" fill="currentColor" fillOpacity=".2" />+ <rect x="6.5" y="3" width="3" height="10" rx="1" fill="currentColor" fillOpacity=".2" />+ <rect x="11" y="5" width="3" height="8" rx="1" fill="currentColor" fillOpacity=".2" /></>,),machines: svg(@@ -125,6 +125,7 @@ export function Catalogue({ code, header, end }: { code: Record<FigureId, Tab[]>const head = useRef<HTMLDivElement>(null);const close = useRef<HTMLButtonElement>(null);const opener = useRef<HTMLElement | null>(null);+ const keyed = useRef(false);// the hash is read after mount, so the server's All and the first render agreeuseEffect(() => {@@ -188,8 +189,9 @@ export function Catalogue({ code, header, end }: { code: Record<FigureId, Tab[]>}};- const pick = (f: Entry, from: HTMLElement | null) => {+ const pick = (f: Entry, from: HTMLElement | null, keyboard: boolean) => {opener.current = from;+ keyed.current = keyboard;if (entry?.id !== f.id) {setIntensity(0.5);setReads("");@@ -198,17 +200,21 @@ export function Catalogue({ code, header, end }: { code: Record<FigureId, Tab[]>setOpen(true);};- const shut = useCallback(() => {+ // focus returns to the tile's button, and its ring shows only when the keyboard closed the drawer: a script's focus+ // would otherwise draw it after a click on the ×; Escape counts as the keyboard only once it has been steering+ const shut = useCallback((keyboard: boolean) => {setOpen(false);const back = opener.current;- if (back?.isConnected) back.focus({ preventScroll: true });+ if (back?.isConnected) back.focus({ preventScroll: true, focusVisible: keyboard } as FocusOptions);}, []);useEffect(() => {if (!open) return;- close.current?.focus({ preventScroll: true });+ // the × takes focus, with its ring only when the keyboard opened the drawer, as `shut` does on the way back+ close.current?.focus({ preventScroll: true, focusVisible: keyed.current } as FocusOptions);const onKey = (event: KeyboardEvent) => {- if (event.key === "Escape") shut();+ if (event.key === "Tab") keyed.current = true;+ if (event.key === "Escape") shut(keyed.current);};document.addEventListener("keydown", onKey);return () => document.removeEventListener("keydown", onKey);@@ -272,7 +278,7 @@ export function Catalogue({ code, header, end }: { code: Record<FigureId, Tab[]>);}-function ShelfSection({ shelf, picked, onPick }: { shelf: Shelf; picked?: string; onPick: (f: Entry, from: HTMLElement | null) => void }) {+function ShelfSection({ shelf, picked, onPick }: { shelf: Shelf; picked?: string; onPick: (f: Entry, from: HTMLElement | null, keyboard: boolean) => void }) {const drawn = shelf.figures.filter((f) => f.drawn).length;return (<section id={`shelf-${shelf.id}`} className="doc-section" style={tint(shelf.color)} aria-labelledby={`shelf-${shelf.id}-h`}>@@ -296,16 +302,16 @@ function ShelfSection({ shelf, picked, onPick }: { shelf: Shelf; picked?: string* One figure on its shelf. The whole tile takes a click, but the button is its name: the figure in the stage answers* the pointer and the keyboard itself, and Riffle's cards cannot sit inside a button.*/-function Tile({ entry, picked, onPick }: { entry: Entry; picked: boolean; onPick: (f: Entry, from: HTMLElement | null) => void }) {+function Tile({ entry, picked, onPick }: { entry: Entry; picked: boolean; onPick: (f: Entry, from: HTMLElement | null, keyboard: boolean) => void }) {const button = useRef<HTMLButtonElement>(null);const Figure = entry.drawn ? COMPONENTS[entry.id] : null;return (- <div className="fig-tile" data-planned={entry.drawn ? undefined : ""} data-picked={picked ? "" : undefined} onClick={() => onPick(entry, button.current)}>+ <div className="fig-tile" data-planned={entry.drawn ? undefined : ""} data-picked={picked ? "" : undefined} onClick={(event) => onPick(entry, button.current, event.detail === 0)}><div className="fig-stage">{Figure ? <Figure /> : <Ghost />}</div><div className="fig-foot"><button ref={button} type="button" className="fig-name" aria-label={entry.drawn ? undefined : `${entry.name}, planned`} aria-expanded={picked} aria-controls="figure-drawer" onClick={(event) => {event.stopPropagation();- onPick(entry, button.current);+ onPick(entry, button.current, event.detail === 0);}}>{entry.name}</button>@@ -318,7 +324,7 @@ function Detail({entry, code, intensity, setIntensity, reads, setReads, closeRef, onClose,}: {entry: Entry; code?: Tab[]; intensity: number; setIntensity: (n: number) => void; reads: string; setReads: (s: string) => void;- closeRef: React.RefObject<HTMLButtonElement | null>; onClose: () => void;+ closeRef: React.RefObject<HTMLButtonElement | null>; onClose: (keyboard: boolean) => void;}) {const shelf = SHELF_OF.get(entry.id)!;const Figure = entry.drawn ? COMPONENTS[entry.id] : null;@@ -332,7 +338,7 @@ function Detail({{entry.drawn ? null : <span className="detail-tag">planned</span>}</p></div>- <button ref={closeRef} type="button" className="detail-close" aria-label="Close" onClick={onClose}>+ <button ref={closeRef} type="button" className="detail-close" aria-label="Close" onClick={(event) => onClose(event.detail === 0)}><svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" aria-hidden="true"><path d="m4 4 8 8M12 4l-8 8" /></svg>diff --git a/apps/site/lib/catalogue.ts b/apps/site/lib/catalogue.tsindex 6b7028e..d7eecc1 100644--- a/apps/site/lib/catalogue.ts+++ b/apps/site/lib/catalogue.ts@@ -26,15 +26,13 @@ export const SHELVES: Shelf[] = [{id: "interfaces", title: "Interfaces", color: "#3b82f6", figures: [drawn("exploded"),- drawn("riffle"),- drawn("keyboard"),],},{id: "data", title: "Data", color: "#8b5cf6", figures: [drawn("terrain"),drawn("phosphor"),- planned("funnel", "Funnel", "Three basins stepping down, water in each. The pointer picks a basin; its gate opens and the water drops to the next, staggered on down.", "The drop runs further down the flight."),+ drawn("riffle"),],},{@@ -46,37 +44,37 @@ export const SHELVES: Shelf[] = [},{id: "devices", title: "Devices", color: "#10b981", figures: [+ drawn("keyboard"),planned("phone", "Phone", "A phone in layers: glass, board, battery, shell. Moving across opens the gap; moving down picks a layer.", "The layers open further."),- planned("clock", "Clock", "A desk clock with its crown in view. The pointer turns the crown; the hands run and catch on the five-minute detents.", "The hands coast longer."),- planned("cassette", "Cassette", "A tape with both reels in view, always turning. Hovering slows it enough to read the tape go by.", "Time slows down more."),+ planned("laptop", "Laptop", "A thin laptop, open on its hinge. The pointer's height sets the lid; it follows on a spring.", "The lid opens wider."),],},{id: "coding", title: "Coding", color: "#0ea5e9", figures: [- planned("tape", "Tape", "A terminal as punched tape running through a reader. Hovering slows it; the hole under the pointer is lit.", "Time slows down more."),+ planned("terminal", "Terminal", "A terminal window with its history in rows. The pointer's height scrolls back; the line under it lifts and its neighbours follow.", "The lift spreads further."),planned("cabinet", "Cabinet", "A rack of twelve blades, a few half out. The pointer's height pulls the nearest ones out, the farther the less.", "More blades come out."),- planned("cards", "Cards", "A stack of punched cards in a hopper. The card under the pointer slides forward and its neighbours part.", "The part spreads further."),+ planned("branches", "Branches", "A commit graph with a branch forking off main and merging back. The commit under the pointer rises, and its history rises after it.", "More of the history rises."),],},{id: "security", title: "Security", color: "#ef4444", figures: [planned("vault", "Vault", "A vault door with a dial and three bolts. The pointer turns the dial; detents catch every ten, and on the combination the bolts draw back.", "The dial coasts longer."),planned("lockers", "Lockers", "A bank of twelve lockers, one ajar at rest. The locker under the pointer opens; the one at rest closes.", "The door opens wider."),- planned("shutter", "Shutter", "A shopfront with a roller shutter. The pointer's height rolls the shutter up or down, slat after slat.", "The slats lag further behind each other."),+ planned("padlock", "Padlock", "A padlock with its shackle in. As the pointer comes near the shackle lifts out and swings open.", "The shackle swings further."),],},{id: "connectivity", title: "Connectivity", color: "#ec4899", figures: [planned("patch", "Patch", "A patch panel of twenty-four ports with cables. The cable under the pointer lifts and its neighbours lean away.", "The lean spreads further."),planned("dish", "Dish", "A parabolic dish on a two-axis gimbal. The pointer aims the dish; it follows on a spring.", "The dish swings further."),- planned("train", "Train", "Five wagons coupled on a line. The pointer uncouples the one under it; the ones behind drift apart, staggered.", "The wagons drift further."),+ planned("router", "Router", "A router with its antennas up. Each antenna leans toward the pointer, the nearest most.", "The lean spreads further."),],},];export const ENTRIES: Entry[] = SHELVES.flatMap((s) => s.figures);-/** "Seven shelves, twenty-one figures" */+/** "Seven shelves, nineteen figures" */export function tally(): string {return `${cap(spell(SHELVES.length))} shelves, ${spell(ENTRIES.length)} figures`;}diff --git a/apps/site/test/catalogue.test.ts b/apps/site/test/catalogue.test.tsindex 5677795..f0cd328 100644--- a/apps/site/test/catalogue.test.ts+++ b/apps/site/test/catalogue.test.ts@@ -16,12 +16,12 @@ describe("the catalogue", () => {it("names each figure once, on seven shelves of three", () => {expect(new Set(ENTRIES.map((e) => e.id)).size).toBe(ENTRIES.length);expect(new Set(ENTRIES.map((e) => e.name)).size).toBe(ENTRIES.length);- expect(SHELVES.map((s) => s.figures.length)).toEqual([3, 3, 3, 3, 3, 3, 3]);+ expect(SHELVES.map((s) => s.figures.length)).toEqual([1, 3, 3, 3, 3, 3, 3]);});it("counts in words, read from the shelves", () => {expect([spell(7), spell(19), spell(20), spell(21), spell(40), spell(99)]).toEqual(["seven", "nineteen", "twenty", "twenty-one", "forty", "ninety-nine"]);- expect(tally()).toBe("Seven shelves, twenty-one figures");+ expect(tally()).toBe("Seven shelves, nineteen figures");});it("pastes each figure three ways, and the docs' Terrain is the same as before", () => {diff --git a/apps/site/test/figures.spec.ts b/apps/site/test/figures.spec.tsindex 821b62d..6f097d6 100644--- a/apps/site/test/figures.spec.ts+++ b/apps/site/test/figures.spec.ts@@ -16,28 +16,28 @@ function watch(page: Page): string[] {const tiles = (page: Page) => page.locator(".fig-tile");const shelf = (page: Page, name: string) => page.locator(".shelves .shelf", { hasText: name });-test("/figures prerenders seven empty boxes among twenty-one tiles, then draws them with a clean console", async ({ page, request }) => {+test("/figures prerenders seven empty boxes among nineteen tiles, then draws them with a clean console", async ({ page, request }) => {const html = await (await request.get("/figures")).text();expect(html.match(/<div style="aspect-ratio:5 \/ 4"><\/div>/g)).toHaveLength(7);- expect(html.match(/class="fig-tile"/g)).toHaveLength(21);- expect(html.match(/class="fig-tile" data-planned=""/g)).toHaveLength(14);+ expect(html.match(/class="fig-tile"/g)).toHaveLength(19);+ expect(html.match(/class="fig-tile" data-planned=""/g)).toHaveLength(12);const noise = watch(page);await page.goto("/figures");- await expect(tiles(page)).toHaveCount(21);+ await expect(tiles(page)).toHaveCount(19);await expect(page.locator(".fig-tile [data-hairline] > svg")).toHaveCount(7);- await expect(page.locator(".fig-tile .fig-ghost")).toHaveCount(14);+ await expect(page.locator(".fig-tile .fig-ghost")).toHaveCount(12);await expect(page.locator("h1")).toHaveText("Every figure, by what it draws.");await expect(page.locator(".doc-section h2")).toHaveText(SHELVES);await expect(page.locator(".fig-name").first()).toHaveAccessibleName("Exploded");- await expect(page.locator(".fig-tile[data-planned] .fig-name").first()).toHaveAccessibleName("Funnel, planned");+ await expect(page.locator(".fig-tile[data-planned] .fig-name").first()).toHaveAccessibleName("Elevator, planned");expect(noise).toEqual([]);});test("the shelves filter: All is pressed at first, a shelf shows only itself and names itself in the address", async ({ page }) => {await page.goto("/figures");await expect(shelf(page, "All")).toHaveAttribute("aria-pressed", "true");- await expect(page.locator(".shelves .shelf-n")).toHaveText(["21", "3", "3", "3", "3", "3", "3", "3"]);+ await expect(page.locator(".shelves .shelf-n")).toHaveText(["19", "1", "3", "3", "3", "3", "3", "3"]);await shelf(page, "Machines").click();await expect(shelf(page, "Machines")).toHaveAttribute("aria-pressed", "true");@@ -54,7 +54,7 @@ test("the shelves filter: All is pressed at first, a shelf shows only itself and})).toBeLessThan(1);await shelf(page, "All").click();- await expect(tiles(page)).toHaveCount(21);+ await expect(tiles(page)).toHaveCount(19);expect(new URL(page.url()).hash).toBe("");});@@ -133,6 +133,68 @@ test("a planned figure's drawer has its outline and a link to ask for it, and noawait expect(drawer).not.toHaveAttribute("data-open");});+test("closing the drawer returns focus to the tile's button, with its ring for the keyboard alone", async ({ page }) => {+ await page.goto("/figures");+ const drawer = page.locator("#figure-drawer");+ const name = page.locator(".fig-name", { hasText: "Keyboard" });+ const stage = page.locator(".fig-tile", { has: name }).locator(".fig-stage");+ const ringed = () => name.evaluate((el) => el.matches(":focus-visible"));+ const outline = () => name.evaluate((el) => getComputedStyle(el).outlineStyle === "none" || parseFloat(getComputedStyle(el).outlineWidth) === 0 ? "none" : "drawn");++ // the mouse opened it: neither the × nor Escape brings the ring back with focus+ for (const shut of [() => drawer.locator(".detail-close").click(), () => page.keyboard.press("Escape")]) {+ await stage.click();+ await expect(drawer).toHaveAttribute("data-open");+ await shut();+ await expect(drawer).not.toHaveAttribute("data-open");+ await expect(name).toBeFocused();+ expect(await ringed()).toBe(false);+ expect(await outline()).toBe("none");+ }++ // the keyboard opened it, or took over inside it with Tab: Escape returns focus with its ring+ for (const open of [async () => { await name.focus(); await page.keyboard.press("Enter"); }, async () => { await stage.click(); await page.keyboard.press("Tab"); }]) {+ await open();+ await expect(drawer).toHaveAttribute("data-open");+ await page.keyboard.press("Escape");+ await expect(drawer).not.toHaveAttribute("data-open");+ await expect(name).toBeFocused();+ expect(await ringed()).toBe(true);+ expect(await outline()).toBe("drawn");+ }+});++test("opening the drawer focuses its ×, with its ring for the keyboard alone", async ({ page }) => {+ await page.goto("/figures");+ const drawer = page.locator("#figure-drawer");+ const close = drawer.locator(".detail-close");+ const name = page.locator(".fig-name", { hasText: "Keyboard" });+ const stage = page.locator(".fig-tile", { has: name }).locator(".fig-stage");+ const ringed = () => close.evaluate((el) => el.matches(":focus-visible"));++ for (const open of [() => stage.click(), () => name.click()]) {+ await open();+ await expect(drawer).toHaveAttribute("data-open");+ await expect(close).toBeFocused();+ expect(await ringed()).toBe(false);+ await close.click();+ await expect(drawer).not.toHaveAttribute("data-open");+ }++ // opened by the keyboard, shut by Escape or by the × pressed with Enter, focus goes back to the name with its ring+ for (const [key, shut] of [["Enter", "Escape"], [" ", "Enter"]]) {+ await name.focus();+ await page.keyboard.press(key);+ await expect(drawer).toHaveAttribute("data-open");+ await expect(close).toBeFocused();+ expect(await ringed()).toBe(true);+ await page.keyboard.press(shut);+ await expect(drawer).not.toHaveAttribute("data-open");+ await expect(name).toBeFocused();+ expect(await name.evaluate((el) => el.matches(":focus-visible"))).toBe(true);+ }+});+test("on a phone the shelves are a strip under the top bar, and nothing scrolls sideways", async ({ page }) => {for (const width of [414, 390, 360, 320]) {await page.setViewportSize({ width, height: 800 });diff --git a/apps/site/test/site.spec.ts b/apps/site/test/site.spec.tsindex 6e9c46d..a6d3eda 100644--- a/apps/site/test/site.spec.ts+++ b/apps/site/test/site.spec.ts@@ -287,7 +287,7 @@ const BASE = "http://localhost:3000";test("a pasted link shows the page it leads to: each page's card has its own title, text and address", async ({ request }) => {const CARDS = [["/", "hairline", /^Seven isometric line figures/],- ["/figures", "Figures", /^Seven shelves, twenty-one figures, grouped by what they draw/],+ ["/figures", "Figures", /^Seven shelves, nineteen figures, grouped by what they draw/],["/docs", "Docs", /^Seven isometric line figures/],["/skill", "Make your own figure", /^hairline-create is a skill/],["/inspo", "How Hairline was made", /^A long brief/],