Skip to content

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

Site: the llms.txt button opens the file without a clipboard, the figure names are italic, and a long install line fades at its edge

Lucas Marquesb3586d063c3b
diff --git a/apps/site/app/globals.css b/apps/site/app/globals.css
index 19b1b22..71f0f2e 100644
--- a/apps/site/app/globals.css
+++ b/apps/site/app/globals.css
@@ -47,6 +47,7 @@ em { font-style: italic; }
}
.pill-line { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; scrollbar-width: none; }
.pill-line::-webkit-scrollbar { display: none; }
+.pill-line[data-more] { mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent); }
.pill-manager { border-radius: 5px; padding: 3px 4px; margin: -3px -4px; color: var(--color-ink); text-decoration: underline dotted var(--color-faint); text-underline-offset: 4px; cursor: pointer; }
.pill-manager:hover { background: var(--color-stone); }
diff --git a/apps/site/app/page.tsx b/apps/site/app/page.tsx
index 576fcb6..f835c6f 100644
--- a/apps/site/app/page.tsx
+++ b/apps/site/app/page.tsx
@@ -46,7 +46,7 @@ export default async function Page() {
<nav className="flex items-center gap-1">
<span className="px-2 font-mono text-[12px] text-muted" data-version>v{pkg.version}</span>
<a className="icon-link" href={LINKS.github} aria-label="GitHub"><GitHub /></a>
- <CopyButton text={`${SITE}/llms.txt`} label="llms.txt" className="btn btn-quiet" />
+ <CopyButton text={`${SITE}/llms.txt`} open="/llms.txt" label="llms.txt" className="btn btn-quiet" />
</nav>
</header>
@@ -79,7 +79,7 @@ export default async function Page() {
return (
<li key={doc.id} className="figure-row" data-row={doc.id}>
<div>
- <h3 className="font-serif text-[30px] leading-none">{doc.name}</h3>
+ <h3 className="font-serif text-[30px] italic leading-none">{doc.name}</h3>
<p className="mt-3 text-[16px] leading-[1.5]">{doc.stronger}</p>
<p className="mt-1 max-w-[52ch] text-[14px] leading-[1.55] text-muted">{doc.summary}</p>
</div>
diff --git a/apps/site/components/copy.tsx b/apps/site/components/copy.tsx
index 5642d37..1a81f5b 100644
--- a/apps/site/components/copy.tsx
+++ b/apps/site/components/copy.tsx
@@ -5,9 +5,10 @@ import { useCallback, useEffect, useState, type RefObject } from "react";
/**
* Copies text, and says so for a moment. Without clipboard permission, or on
* a page served without a secure context where there is no clipboard at all,
- * it selects the text instead, so the keyboard can copy it.
+ * it selects the text instead, so the keyboard can copy it. Resolves whether
+ * the text reached the clipboard.
*/
-export function useCopy(): [copied: boolean, copy: (text: string, fallback?: Element | null) => void] {
+export function useCopy(): [copied: boolean, copy: (text: string, fallback?: Element | null) => Promise<boolean>] {
const [copied, setCopied] = useState(false);
useEffect(() => {
@@ -20,13 +21,15 @@ export function useCopy(): [copied: boolean, copy: (text: string, fallback?: Ele
try {
await navigator.clipboard.writeText(text);
setCopied(true);
+ return true;
} catch {
- if (!fallback) return;
+ if (!fallback) return false;
const range = document.createRange();
range.selectNodeContents(fallback);
const selection = window.getSelection();
selection?.removeAllRanges();
selection?.addRange(range);
+ return false;
}
}, []);
@@ -34,14 +37,17 @@ export function useCopy(): [copied: boolean, copy: (text: string, fallback?: Ele
}
/**
- * A button that copies `text`, or selects what `select` points at when it
- * cannot. `text` can be a function, read at the click, for text the button
- * does not own.
+ * A button that copies `text`, or when it cannot, selects what `select` points
+ * at, or opens `open` for a button with no text of its own on the page. `text`
+ * can be a function, read at the click, for text the button does not own.
*/
-export function CopyButton({ text, select, label = "Copy", className = "copy" }: { text: string | (() => string); select?: RefObject<Element | null>; label?: string; className?: string }) {
+export function CopyButton({ text, select, open, label = "Copy", className = "copy" }: { text: string | (() => string); select?: RefObject<Element | null>; open?: string; label?: string; className?: string }) {
const [copied, copy] = useCopy();
+ const click = async () => {
+ if (!(await copy(typeof text === "function" ? text() : text, select?.current)) && open) window.location.assign(open);
+ };
return (
- <button type="button" className={className} onClick={() => copy(typeof text === "function" ? text() : text, select?.current)} aria-live="polite">
+ <button type="button" className={className} onClick={click} aria-live="polite">
{copied ? "Copied" : label}
</button>
);
diff --git a/apps/site/components/install.tsx b/apps/site/components/install.tsx
index dd46a16..8fdb2b1 100644
--- a/apps/site/components/install.tsx
+++ b/apps/site/components/install.tsx
@@ -1,11 +1,13 @@
"use client";
-import { useRef, useState } from "react";
+import { useEffect, useRef, useState } from "react";
import { CopyButton } from "./copy";
/**
* The install command in a pill. The command's first word is a button that
* moves to the next package manager; the copy button copies the whole line.
+ * A line wider than the pill scrolls, fades at the edge while more of it is
+ * hidden, and shows itself whole on hover.
*/
export function Install({ commands }: { commands: { label: string; code: string }[] }) {
const [at, setAt] = useState(0);
@@ -13,11 +15,26 @@ export function Install({ commands }: { commands: { label: string; code: string
const { label, code } = commands[at];
const head = code.slice(0, code.indexOf(" "));
const next = commands[(at + 1) % commands.length].label;
+ const [more, setMore] = useState(false);
+
+ useEffect(() => {
+ const el = line.current;
+ if (!el) return;
+ const measure = () => setMore(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();
+ };
+ }, [code]);
return (
<div className="pill" data-install={label}>
<span aria-hidden="true" className="select-none text-faint">$</span>
- <code ref={line} className="pill-line">
+ <code ref={line} className="pill-line" title={code} data-more={more ? "" : undefined}>
<button type="button" className="pill-manager" onClick={() => setAt((at + 1) % commands.length)} aria-label={`${label}: switch to ${next}`} title={`Switch to ${next}`}>
{head}
</button>
diff --git a/apps/site/test/site.spec.ts b/apps/site/test/site.spec.ts
index 93887f8..deebf92 100644
--- a/apps/site/test/site.spec.ts
+++ b/apps/site/test/site.spec.ts
@@ -173,3 +173,39 @@ test("the page fits a phone, with the longest install command and every control"
await expect(inspector.locator("[data-snippet] .code-panel")).toContainText('<Turntable intensity={0.85} theme="dark" />');
expect(await width()).toBeLessThanOrEqual(390);
});
+
+test("without a clipboard at all, the top bar's llms.txt button opens the file", async ({ page }) => {
+ await page.addInitScript(() => {
+ Object.defineProperty(navigator, "clipboard", { value: undefined });
+ });
+ const noise = watch(page);
+ await page.goto("/");
+ await page.locator(".topbar").getByRole("button", { name: "llms.txt" }).click();
+ await expect(page).toHaveURL(/\/llms\.txt$/);
+ // the text file has no icon, so Chrome's own request for /favicon.ico 404s there
+ expect(noise.filter((line) => line.startsWith("pageerror"))).toEqual([]);
+});
+
+test("each figure row names its figure in italic serif", async ({ page }) => {
+ await page.goto("/");
+ for (const id of IDS) await expect(page.locator(`[data-row="${id}"] h3`)).toHaveCSS("font-style", "italic");
+});
+
+test("a command wider than the pill fades at the edge until it is scrolled to its end, and shows itself whole on hover", async ({ page }) => {
+ await page.setViewportSize({ width: 1200, height: 800 });
+ await page.goto("/");
+ const pill = page.locator("[data-install]").first();
+ const line = pill.locator("code");
+ await expect(line).not.toHaveAttribute("data-more");
+ await expect(line).toHaveCSS("mask-image", "none");
+
+ for (let i = 0; i < 4; i++) await pill.getByRole("button", { name: /: switch to/ }).click();
+ const [, shadcn] = MANAGERS[4];
+ await expect(line).toHaveAttribute("title", shadcn);
+ await expect(line).toHaveAttribute("data-more", "");
+ await expect(line).toHaveCSS("mask-image", /gradient/);
+
+ await line.evaluate((el) => el.scrollTo({ left: el.scrollWidth }));
+ await expect(line).not.toHaveAttribute("data-more");
+ await expect(line).toHaveCSS("mask-image", "none");
+});