Isometric line figures that answer the pointer. For React and for anything with a DOM.
Site: the pickers' highlight moves and clips instead of resizing, keys land at once, the hero staggers 70ms, and a pressed button's text holds still
Lucas Marques0534a1d3be9a
diff --git a/apps/site/app/globals.css b/apps/site/app/globals.cssindex be41a10..9325ca4 100644--- a/apps/site/app/globals.css+++ b/apps/site/app/globals.css@@ -57,7 +57,8 @@ a.topbar-link:hover { color: var(--color-ink); }background: #fff; box-shadow: inset 0 0 0 1px var(--color-stone), var(--lift);}.btn-primary { background: var(--color-ink); color: #fff; box-shadow: var(--lift); }-.press { transition: transform 160ms var(--ease-out); }+/* on its own layer from the start, so the press scales the text as drawn instead of redrawing it as the layer comes and goes */+.press { transition: transform 160ms var(--ease-out); will-change: transform; }.press:active { transform: scale(0.96); }.pill {@@ -160,7 +161,7 @@ a.topbar-link:hover { color: var(--color-ink); }/* Rise, blur and fade end in that order. The rise and the blur end in steps: moving text is drawn on whole devicepixels, so the last pixel of travel lands as a hop, and Chrome draws no blur under 0.4px, so the last of it goesin one frame. The hop comes under the blur, the blur goes while the block still fades in, and the fade ends it. */-.hero-rise > * { animation: fade 750ms var(--ease-out) both, unblur 560ms var(--ease-out) both, rise 380ms var(--ease-out) both; animation-delay: calc(var(--i) * 90ms + 60ms); }+.hero-rise > * { animation: fade 750ms var(--ease-out) both, unblur 560ms var(--ease-out) both, rise 380ms var(--ease-out) both; animation-delay: calc(var(--i) * 70ms + 60ms); }.enter { animation: fade 850ms var(--ease-out) both, unblur 640ms var(--ease-out) both, rise 440ms var(--ease-out) both; animation-delay: var(--d, 0ms); }.enter-hint { animation: hint 220ms var(--ease-out) both; }@keyframes unblur { from { filter: blur(6px); } to { filter: none; } }@@ -171,7 +172,9 @@ a.topbar-link:hover { color: var(--color-ink); }/* A single choice whose highlight slides to the checked option. */.slide { position: relative; display: flex; isolation: isolate; }.slide-hl { position: absolute; top: 0; left: 0; z-index: -1; pointer-events: none; }-.slide[data-ready] .slide-hl { transition: transform 240ms var(--ease-out), width 240ms var(--ease-out), height 240ms var(--ease-out); }+.slide[data-ready] .slide-hl { transition: transform 200ms var(--ease-out), clip-path 200ms var(--ease-out); }+/* a choice made with the keyboard lands at once */+.slide[data-keyed] .slide-hl { transition: none; }.slide-item { position: relative; display: inline-flex; flex: none; align-items: center; justify-content: center; white-space: nowrap; color: var(--color-muted); transition: color 150ms ease; }.slide-item:hover, .slide-item[aria-checked="true"] { color: var(--color-ink); }@@ -195,14 +198,15 @@ a.topbar-link:hover { color: var(--color-ink); }/* The inspector: the figure on the page itself, one dock under it for every control. */.s-inspector { display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; }-.s-stage { position: relative; display: grid; place-items: center; width: 100%; max-width: 760px; padding: clamp(8px, 4vw, 40px); border-radius: 28px; transition: background-color 300ms ease; }+.s-stage { position: relative; display: grid; place-items: center; width: 100%; max-width: 760px; padding: clamp(8px, 4vw, 40px); border-radius: 28px; }.s-stage > [data-hairline] { width: 100%; max-width: 560px; }.s-stage[data-dark] { background: #08090a; }.s-dock { margin-top: 8px; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; max-width: 100%; padding: 6px; border-radius: 16px; background: #fff; box-shadow: inset 0 0 0 1px var(--color-stone), var(--lift-lg); }.s-figures { min-width: 0; max-width: 100%; overflow-x: auto; scrollbar-width: none; }.s-figures::-webkit-scrollbar { display: none; }.s-figures .slide-item { height: 36px; padding: 0 12px; font-size: 14px; }-.s-figures .slide-hl { border-radius: 10px; background: var(--color-stone); }+.s-figures { --slide-radius: 10px; }+.s-figures .slide-hl { background: var(--color-stone); }.s-row { display: flex; align-items: center; gap: 12px; padding-left: 12px; border-left: 1px solid var(--color-line); }.s-range { display: flex; align-items: center; gap: 10px; width: 230px; }.s-range-label { font-size: 13px; color: var(--color-muted); }diff --git a/apps/site/components/inspector.tsx b/apps/site/components/inspector.tsxindex 9c08ce9..079cb75 100644--- a/apps/site/components/inspector.tsx+++ b/apps/site/components/inspector.tsx@@ -40,12 +40,12 @@ export function Inspector() {return (<div className="s-inspector" data-inspector>{/* off dark, the figure's plate is the page, so it stands without a box */}- <div className="s-stage enter" style={vars({ "--d": "520ms", ...(dark ? {} : { "--hairline-plate": "var(--color-canvas)" }) })} data-figure={id} data-dark={dark || undefined}>+ <div className="s-stage enter" style={vars({ "--d": "400ms", ...(dark ? {} : { "--hairline-plate": "var(--color-canvas)" }) })} data-figure={id} data-dark={dark || undefined}><Figure key={id} intensity={intensity} theme={theme} /></div>- <div className="s-dock enter" style={vars({ "--d": "640ms" })}>- <Slide label="Figure" options={FIGURE_OPTIONS} value={id} onChange={setId} className="s-figures" />+ <div className="s-dock enter" style={vars({ "--d": "460ms" })}>+ <Slide label="Figure" options={FIGURE_OPTIONS} value={id} onChange={setId} clip className="s-figures" /><div className="s-row"><div className="s-range"><label htmlFor={slider} className="s-range-label">Intensity</label>@@ -57,7 +57,7 @@ export function Inspector() {</div><p key={id} className="s-hint enter-hint">{doc.stronger}</p>- <div className="s-code enter" style={vars({ "--d": "760ms" })} data-snippet>+ <div className="s-code enter" style={vars({ "--d": "520ms" })} data-snippet><Code text={text} codeRef={code} /><CopyIcon text={text} select={code} label="Copy snippet" className="s-copy" /></div>diff --git a/apps/site/components/slide.tsx b/apps/site/components/slide.tsxindex 966f674..a15a433 100644--- a/apps/site/components/slide.tsx+++ b/apps/site/components/slide.tsx@@ -7,19 +7,27 @@ export type Option<T extends string> = { value: T; label: ReactNode; name?: stri/*** A single choice as a radio group, with a highlight that slides to the* checked option. The slide is turned on after the first paint, so the page- * does not open with it moving. Arrow keys move the choice.+ * does not open with it moving. Arrow keys move the choice, and the highlight+ * with it at once; only a pointer's choice slides.+ *+ * The highlight never animates its size. It is moved with transform; where the+ * options differ in width (`clip`), it spans the whole row and a clip-path+ * cuts it down to the checked option.*/-export function Slide<T extends string>({ options, value, onChange, label, className = "" }: { options: Option<T>[]; value: T; onChange: (value: T) => void; label: string; className?: string }) {+export function Slide<T extends string>({ options, value, onChange, label, clip = false, className = "" }: { options: Option<T>[]; value: T; onChange: (value: T) => void; label: string; clip?: boolean; className?: string }) {const group = useRef<HTMLDivElement>(null);- const [box, setBox] = useState<{ x: number; y: number; w: number; h: number } | null>(null);+ const [box, setBox] = useState<{ x: number; y: number; w: number; h: number; rowW: number; rowH: number } | null>(null);const [ready, setReady] = useState(false);+ const [keyed, setKeyed] = useState(false);useLayoutEffect(() => {const root = group.current;if (!root) return;const measure = () => {const el = root.querySelector<HTMLElement>('[aria-checked="true"]');- if (el) setBox({ x: el.offsetLeft, y: el.offsetTop, w: el.offsetWidth, h: el.offsetHeight });+ const last = root.querySelector<HTMLElement>("[role=radio]:last-of-type");+ // the row's extent is read from its options, not the group, which can scroll+ if (el && last) setBox({ x: el.offsetLeft, y: el.offsetTop, w: el.offsetWidth, h: el.offsetHeight, rowW: last.offsetLeft + last.offsetWidth, rowH: last.offsetTop + last.offsetHeight });};measure();const resize = new ResizeObserver(measure);@@ -40,6 +48,7 @@ export function Slide<T extends string>({ options, value, onChange, label, classconst step = event.key === "ArrowRight" || event.key === "ArrowDown" ? 1 : event.key === "ArrowLeft" || event.key === "ArrowUp" ? -1 : 0;if (!step) return;event.preventDefault();+ setKeyed(true);const at = options.findIndex((o) => o.value === value);const next = (at + step + options.length) % options.length;onChange(options[next].value);@@ -47,8 +56,10 @@ export function Slide<T extends string>({ options, value, onChange, label, class};return (- <div ref={group} role="radiogroup" aria-label={label} className={`slide ${className}`} data-ready={ready || undefined} onKeyDown={onKeyDown}>- {box ? <span className="slide-hl" aria-hidden="true" style={{ width: box.w, height: box.h, transform: `translate(${box.x}px, ${box.y}px)` }} /> : null}+ <div ref={group} role="radiogroup" aria-label={label} className={`slide ${className}`} data-ready={ready || undefined} data-keyed={keyed || undefined} onKeyDown={onKeyDown} onPointerDown={() => setKeyed(false)}>+ {box ? <span className="slide-hl" aria-hidden="true" style={clip+ ? { width: box.rowW, height: box.rowH, clipPath: `inset(${box.y}px ${box.rowW - box.x - box.w}px ${box.rowH - box.y - box.h}px ${box.x}px round var(--slide-radius))` }+ : { width: box.w, height: box.h, transform: `translate(${box.x}px, ${box.y}px)` }} /> : null}{options.map((o) => (<button key={o.value} type="button" role="radio" aria-checked={o.value === value} aria-label={o.name} title={o.name} tabIndex={o.value === value ? 0 : -1} className="slide-item" onClick={() => onChange(o.value)}>{o.label}diff --git a/apps/site/test/site.spec.ts b/apps/site/test/site.spec.tsindex 6c98a84..22a2c80 100644--- a/apps/site/test/site.spec.ts+++ b/apps/site/test/site.spec.ts@@ -147,6 +147,121 @@ test("the inspector's theme switch repaints the figure", async ({ page }) => {await expect.poll(plate).toBe("rgb(255, 255, 255)");});+/** Waits for every transition and entrance on the page to finish. */+const settled = (page: Page) => expect.poll(() => page.evaluate(() => document.getAnimations().filter((a) => a.playState === "running").length)).toBe(0);++/** Where a picker's highlight shows: its box, less what its clip-path cuts from each side. */+const lit = (page: Page, name: string) =>+ page.getByRole("radiogroup", { name }).evaluate((group) => {+ const hl = group.querySelector<HTMLElement>(".slide-hl")!;+ const box = hl.getBoundingClientRect();+ const inset = getComputedStyle(hl).clipPath.match(/^inset\((.*?)(?: round .*)?\)$/)?.[1].split(" ").map(parseFloat) ?? [0];+ const [t, r = t, b = t, l = r] = inset;+ return { left: box.left + l, right: box.right - r, top: box.top + t, bottom: box.bottom - b };+ });+const checked = (page: Page, name: string) =>+ page.getByRole("radiogroup", { name }).locator('[aria-checked="true"]').evaluate((el) => {+ const box = el.getBoundingClientRect();+ return { left: box.left, right: box.right, top: box.top, bottom: box.bottom };+ });+const near = (a: Record<string, number>, b: Record<string, number>) => {+ for (const k of Object.keys(b)) expect(Math.abs(a[k] - b[k]), k).toBeLessThan(0.75);+};++test("a picker's highlight lands on the checked option by moving and clipping, never by animating its size", async ({ page }) => {+ await page.goto("/");+ await settled(page);+ for (const name of ["Figure", "Theme"]) {+ const group = page.getByRole("radiogroup", { name });+ expect(await group.locator(".slide-hl").evaluate((el) => getComputedStyle(el).transitionProperty)).not.toMatch(/width|height/);+ for (const radio of await group.getByRole("radio").all()) {+ await radio.click();+ await settled(page);+ near(await lit(page, name), await checked(page, name));+ }+ }+});++test("the arrow keys move a picker's highlight at once, and a click still slides it", async ({ page }) => {+ await page.goto("/");+ await settled(page);+ const figures = page.getByRole("radiogroup", { name: "Figure" });+ const hl = figures.locator(".slide-hl");+ await figures.getByRole("radio", { name: "Terrain" }).press("ArrowRight");+ expect(await hl.evaluate((el) => el.getAnimations().length)).toBe(0);+ near(await lit(page, "Figure"), await checked(page, "Figure"));+ await figures.getByRole("radio", { name: "Riffle" }).click();+ expect(await hl.evaluate((el) => el.getAnimations().length)).toBeGreaterThan(0);+});++test("the theme switch repaints the plate in the same frame as the figure", async ({ page }) => {+ await page.goto("/");+ await settled(page);+ const inspector = page.locator("[data-inspector]");+ await inspector.getByRole("radio", { name: "Dark" }).click();+ // the stage's own entrance has finished; what is left would be a transition+ expect(await inspector.locator(".s-stage").evaluate((el) => el.getAnimations().filter((a) => a instanceof CSSTransition).length)).toBe(0);+});++test("the home's entrance settles within 1.4s, with its hero blocks 70ms apart", async ({ page }) => {+ await page.goto("/");+ const timing = await page.evaluate(() => {+ const of = (el: Element) => el.getAnimations().map((a) => a.effect!.getComputedTiming());+ const hero = [...document.querySelectorAll(".hero-rise > *")].map((el) => Math.min(...of(el).map((t) => Number(t.delay))));+ const end = Math.max(...[...document.querySelectorAll(".hero-rise > *, .enter")].flatMap((el) => of(el).map((t) => Number(t.endTime))));+ return { gaps: hero.slice(1).map((d, n) => d - hero[n]), end };+ });+ expect(timing.gaps).toEqual([70, 70, 70]);+ expect(timing.end).toBeLessThanOrEqual(1400);+});++test("a hero button's text holds still through a press: no jump when its layer comes and goes", async ({ page }) => {+ await page.goto("/");+ await settled(page);+ // the press is what is watched; following the link would end the recording+ await page.evaluate(() => document.addEventListener("click", (e) => e.preventDefault(), true));+ for (const name of ["Get started", "GitHub"]) {+ const button = page.locator(".hero-actions").getByRole("link", { name });+ const box = (await button.boundingBox())!;+ await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);+ await page.waitForTimeout(100);+ // what the compositor draws, frame by frame, which a screenshot would redraw from scratch+ const cdp = await page.context().newCDPSession(page);+ const frames: { at: number; data: string }[] = [];+ cdp.on("Page.screencastFrame", (f) => {+ frames.push({ at: Date.now(), data: f.data });+ cdp.send("Page.screencastFrameAck", { sessionId: f.sessionId }).catch(() => {});+ });+ await cdp.send("Page.startScreencast", { format: "png" });+ await page.mouse.down();+ await page.waitForTimeout(400);+ await page.mouse.up();+ const up = Date.now();+ await page.waitForTimeout(600);+ await cdp.send("Page.stopScreencast");+ await cdp.detach();+ const viewport = page.viewportSize()!.width;+ // the release eases out, so its last frame moves the text least; a jump there is the text being redrawn+ const release = frames.filter((f) => f.at > up).map((f) => f.data);+ expect(release.length).toBeGreaterThan(2);+ const worst = await page.evaluate(async ({ frames, box, viewport }) => {+ const text = async (data: string) => {+ const bitmap = await createImageBitmap(await (await fetch(`data:image/png;base64,${data}`)).blob());+ const s = bitmap.width / viewport;+ const [x, y, w, h] = [box.x + 12, box.y + 8, box.width - 24, box.height - 16].map((v) => Math.round(v * s));+ const canvas = new OffscreenCanvas(w, h);+ canvas.getContext("2d")!.drawImage(bitmap, x, y, w, h, 0, 0, w, h);+ return canvas.getContext("2d")!.getImageData(0, 0, w, h).data;+ };+ const [before, after] = await Promise.all(frames.map(text));+ let worst = 0;+ for (let k = 0; k < before.length; k += 4) worst = Math.max(worst, Math.abs(before[k] - after[k]));+ return worst;+ }, { frames: release.slice(-2), box, viewport });+ expect(worst, name).toBeLessThan(64);+ }+});+test("the install pill copies every manager's command", async ({ page, context }) => {await context.grantPermissions(["clipboard-read", "clipboard-write"]);await page.goto("/");