Isometric line figures that answer the pointer. For React and for anything with a DOM.
Skill page: each prompt beside the figure it produced, live, then how the skill works and how to use it
Lucas Marques64efe24bb046
diff --git a/apps/site/app/globals.css b/apps/site/app/globals.cssindex 7e96389..e660afc 100644--- a/apps/site/app/globals.css+++ b/apps/site/app/globals.css@@ -345,3 +345,24 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }.icopy-b, .icopy[data-copied] .icopy-a { transform: none; filter: none; }[data-live] > .doc-dot, [data-live] .doc-link > span { 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 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-content: start; }+.example-figure { container-type: inline-size; }+/* the height the generated page takes before it is measured: its 5:4 stage, at most 640px wide, and the lines under it */+.example-frame { display: block; width: 100%; height: calc(min(100cqw - 32px, 640px) * 0.8 + 190px); 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); 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.95 var(--font-mono); 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); }+}diff --git a/apps/site/app/skill/page.tsx b/apps/site/app/skill/page.tsxnew file mode 100644index 0000000..22c3866--- /dev/null+++ b/apps/site/app/skill/page.tsx@@ -0,0 +1,67 @@+import type { Metadata } from "next";+import { Footer, Topbar } from "@/components/chrome";+import { Command } from "@/components/command";+import { ExampleFrame } from "@/components/example-frame";+import { LINKS } from "@/lib/figures";+import { COMMAND, FOLDER, INSTALL, STEPS, SUMMARY, USE, examples } from "@/lib/skill";++export const metadata: Metadata = { title: "Make your own figure · hairline", description: SUMMARY, alternates: { canonical: "/skill" } };++/**+ * 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.+ */+export default function Skill() {+ const shown = examples();+ return (+ <>+ <Topbar />+ <main className="skill">+ <header>+ <h1 className="max-w-[16ch] text-[36px] font-medium leading-[1.05] tracking-[-0.035em] md:text-[44px]">Make your own figure</h1>+ <p className="mt-4 max-w-[64ch] text-[16px] leading-[1.55] text-muted">{SUMMARY}</p>+ <div className="skill-install"><Command code={INSTALL} kind="install" label="Copy install command" /></div>+ </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 beside it, as it wrote it. Move the pointer over one.</p>+ <div>+ {shown.map((e) => (+ <article key={e.file} className="example" data-example={e.name}>+ <div className="example-prompt">+ <Command code={e.prompt} kind="prompt" label="Copy prompt" />+ <a className="doc-more" href={e.href}>Open the page</a>+ </div>+ <div className="example-figure">+ <ExampleFrame src={`${e.href}?theme=light`} title={e.means} />+ </div>+ </article>+ ))}+ </div>+ </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>+ {STEPS.map((s) => (+ <li key={s.title}><span><strong>{s.title}.</strong> {s.text}</span></li>+ ))}+ </ol>+ <p className="doc-note">{FOLDER}</p>+ </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">{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’s files are in <a className="doc-more" href={`${LINKS.github}/tree/main/skills/hairline-create`}>its folder on GitHub</a>.+ </p>+ </section>+ </main>+ <Footer />+ </>+ );+}diff --git a/apps/site/components/command.tsx b/apps/site/components/command.tsxnew file mode 100644index 0000000..9fcc5d0--- /dev/null+++ b/apps/site/components/command.tsx@@ -0,0 +1,20 @@+"use client";++import { useRef } from "react";+import { CopyIcon } from "./copy";++/**+ * One line to type, in a pill with a copy icon. `kind` says which line it is,+ * for the tests (`prompt` is an example's, `usage` the bare command); a shell+ * command takes the `$` in front of it.+ */+export function Command({ code, kind, label }: { code: string; kind: "install" | "prompt" | "usage"; label: string }) {+ const line = useRef<HTMLElement>(null);+ return (+ <div className="pill" data-command={kind}>+ {kind === "install" && <span aria-hidden="true" className="select-none text-faint">$</span>}+ <code ref={line} className="pill-line" title={code}>{code}</code>+ <CopyIcon text={code} select={line} label={label} />+ </div>+ );+}diff --git a/apps/site/components/example-frame.tsx b/apps/site/components/example-frame.tsxnew file mode 100644index 0000000..9209c63--- /dev/null+++ b/apps/site/components/example-frame.tsx@@ -0,0 +1,40 @@+"use client";++import { useEffect, useRef } from "react";++/** The generated page's body has 24px of padding above and below its one column. */+const PAD = 48;++/**+ * A page the skill wrote, in a frame as tall as that page: the frame never+ * scrolls inside. Its height is reserved in CSS before it loads, then fitted+ * to the page's column and kept fitted as the column's text wraps.+ */+export function ExampleFrame({ src, title }: { src: string; title: string }) {+ const frame = useRef<HTMLIFrameElement>(null);++ useEffect(() => {+ const el = frame.current;+ if (!el) return;+ let watch: ResizeObserver | undefined;+ const fit = () => {+ const view = el.contentWindow as (Window & typeof globalThis) | null;+ const main = el.contentDocument?.querySelector("main");+ if (!view || !main) return;+ const size = () => { el.style.height = `${main.offsetHeight + PAD}px`; };+ size();+ watch?.disconnect();+ // the frame's own observer: its column is in the frame's document+ watch = new view.ResizeObserver(size);+ watch.observe(main);+ };+ fit();+ el.addEventListener("load", fit);+ return () => {+ el.removeEventListener("load", fit);+ watch?.disconnect();+ };+ }, []);++ return <iframe ref={frame} className="example-frame" src={src} title={title} loading="lazy" />;+}diff --git a/apps/site/lib/skill.ts b/apps/site/lib/skill.tsindex ace3f8e..0727daf 100644--- a/apps/site/lib/skill.ts+++ b/apps/site/lib/skill.ts@@ -10,7 +10,8 @@ import { join } from "node:path";export const INSTALL = "npx skills add lucasmarkes/hairline";export const COMMAND = "/hairline-create";-export type Example = { idea: string; file: string };+/** `followUp` is a change asked for after the first prompt, when the page shown is the one that came out of it. */+export type Example = { idea: string; file: string; followUp?: string };/** What was typed after the command, and the page the skill wrote for it. The pages are never edited. */export const EXAMPLES: Example[] = [diff --git a/apps/site/test/skill.spec.ts b/apps/site/test/skill.spec.tsnew file mode 100644index 0000000..b6002dc--- /dev/null+++ b/apps/site/test/skill.spec.ts@@ -0,0 +1,124 @@+import { expect, test, type FrameLocator, type Page } from "@playwright/test";++const INSTALL = "npx skills add lucasmarkes/hairline";+const IDEAS = ["a sales funnel", "a rate limiter", "git branches", "weather over a city"];++function watch(page: Page): string[] {+ const noise: string[] = [];+ page.on("console", (m) => {+ // Vercel Analytics' script exists only on Vercel+ if (m.location().url.includes("/_vercel/")) return;+ if (m.type() === "error" || m.type() === "warning") noise.push(`${m.type()}: ${m.text()}`);+ });+ page.on("pageerror", (e) => noise.push(`pageerror: ${e}`));+ return noise;+}++/** The frames are lazy: each is brought on screen, then waited for until its figure is drawn. */+async function frames(page: Page): Promise<FrameLocator[]> {+ const out: FrameLocator[] = [];+ for (let i = 0; i < IDEAS.length; i++) {+ const row = page.locator("[data-example]").nth(i);+ await row.scrollIntoViewIfNeeded();+ const frame = row.frameLocator("iframe");+ await expect(frame.locator("#stage svg")).toHaveCount(1);+ out.push(frame);+ }+ return out;+}++/** How tall the frame is, and how tall the page inside it needs to be. */+const fit = (frame: FrameLocator) => frame.locator("main").evaluate((main) => ({ frame: window.innerHeight, page: (main as HTMLElement).offsetHeight + 48 }));++test("/skill opens with the install command, four prompts and four live figures, and a clean console", async ({ page }) => {+ const noise = watch(page);+ await page.goto("/skill");+ await expect(page).toHaveTitle("Make your own figure · hairline");+ await expect(page.getByRole("heading", { level: 1 })).toHaveText("Make your own figure");+ await expect(page.locator('[data-command="install"]')).toHaveText(new RegExp(INSTALL));+ await expect(page.locator('[data-command="prompt"]')).toHaveText(IDEAS.map((idea) => new RegExp(`/hairline-create ${idea}$`)));+ await expect(page.locator("[data-steps] > li")).toHaveCount(5);+ await frames(page);+ expect(noise).toEqual([]);+});++test("a figure on /skill answers the pointer and goes back to rest", async ({ page }) => {+ await page.goto("/skill");+ for (const frame of await frames(page)) {+ const read = frame.locator("#read");+ await expect(read).toHaveText("rest");+ // the frames were each brought on screen in turn; this one has to be on screen again for the pointer to reach it+ await frame.locator("#stage").scrollIntoViewIfNeeded();+ const box = (await frame.locator("#stage").boundingBox())!;+ // somewhere on the stage the figure picks something; walk a grid until it does+ let answered = false;+ for (const fy of [0.5, 0.35, 0.65]) {+ for (const fx of [0.5, 0.35, 0.65]) {+ await page.mouse.move(box.x + box.width * fx, box.y + box.height * fy, { steps: 4 });+ if ((await read.textContent()) !== "rest") { answered = true; break; }+ }+ if (answered) break;+ }+ expect(answered).toBe(true);+ await page.mouse.move(2, 2);+ await expect(read).toHaveText("rest");+ }+});++test("each frame is named by what its figure means, and its link opens the page the skill wrote", async ({ page, request }) => {+ await page.goto("/skill");+ await expect(page.locator("[data-example]")).toHaveCount(4);+ for (const row of await page.locator("[data-example]").all()) {+ const title = await row.locator("iframe").getAttribute("title");+ expect(title!.length).toBeGreaterThan(20);+ const href = await row.getByRole("link", { name: "Open the page" }).getAttribute("href");+ expect(href).toMatch(/^\/skill\/hairline-[a-z0-9-]+\.html$/);+ const res = await request.get(href!);+ expect(res.status()).toBe(200);+ expect(res.headers()["content-type"]).toContain("text/html");+ expect(await res.text()).toContain('id="hl-figure"');+ }+});++test("the install command and a prompt copy as they are written", async ({ page, context }) => {+ await context.grantPermissions(["clipboard-read", "clipboard-write"]);+ await page.goto("/skill");+ await page.locator('[data-command="install"] .icopy').click();+ expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(INSTALL);+ await page.locator('[data-command="prompt"] .icopy').nth(2).click();+ expect(await page.evaluate(() => navigator.clipboard.readText())).toBe("/hairline-create git branches");+});++for (const width of [1200, 320]) {+ test(`at ${width}px /skill does not scroll sideways, and no frame scrolls inside`, async ({ page }) => {+ await page.setViewportSize({ width, height: 800 });+ await page.goto("/skill");+ const list = await frames(page);+ expect(await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth)).toBe(0);+ for (const frame of list) {+ await expect.poll(async () => { const f = await fit(frame); return f.frame - f.page; }).toBe(0);+ }+ });+}++test.describe("on a dark system", () => {+ test.use({ colorScheme: "dark" });++ test("every frame is still light, as the site is", async ({ page }) => {+ await page.goto("/skill");+ for (const frame of await frames(page)) {+ expect(await frame.locator("body").evaluate((body) => getComputedStyle(body).backgroundColor)).toBe("rgb(255, 255, 255)");+ }+ });+});++test.describe("without JavaScript", () => {+ test.use({ javaScriptEnabled: false });++ test("/skill still gives the install command, the prompts and the links to the pages", async ({ page }) => {+ await page.goto("/skill");+ await expect(page.locator('[data-command="install"]')).toHaveText(new RegExp(INSTALL));+ await expect(page.locator('[data-command="prompt"]')).toHaveCount(4);+ await expect(page.getByRole("link", { name: "Open the page" })).toHaveCount(4);+ });+});