Skip to content

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

Skill page: each example shows the figure and its controls, without the page's name tags, rules line or open link

Lucas Marques82c0f0c4739f
diff --git a/apps/site/app/globals.css b/apps/site/app/globals.css
index b12e2e3..fd81ec3 100644
--- a/apps/site/app/globals.css
+++ b/apps/site/app/globals.css
@@ -355,7 +355,7 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }
.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-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; }
@@ -365,11 +365,11 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }
.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 stops at the
- link above it instead of covering it. 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 171px of controls and lines under it, which wrap onto more
+ 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
lines in a column narrower than 360px. */
-.example-frame { display: block; width: calc(100% + 32px); margin: -16px -16px -24px; height: calc(min(100cqw, 640px) * 0.8 + 171px + max(0px, 360px - 100cqw) * 0.75); border: 0; }
+.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); }
@@ -378,5 +378,4 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }
@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 { margin-top: -24px; }
}
diff --git a/apps/site/app/skill/page.tsx b/apps/site/app/skill/page.tsx
index 6f03f85..a7771e0 100644
--- a/apps/site/app/skill/page.tsx
+++ b/apps/site/app/skill/page.tsx
@@ -39,7 +39,7 @@ export default function Skill() {
<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, as it wrote it. Move the pointer over one.</p>
+ <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}>
@@ -54,7 +54,6 @@ export default function Skill() {
</>
)}
</div>
- <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} />
diff --git a/apps/site/components/example-frame.tsx b/apps/site/components/example-frame.tsx
index ed821e6..0eb47e9 100644
--- a/apps/site/components/example-frame.tsx
+++ b/apps/site/components/example-frame.tsx
@@ -5,12 +5,22 @@ import { useEffect, useRef } from "react";
/** The bench's `body` padding, 24px above and 24px below the page's one column: every page the skill writes has it. */
const PAD = 48;
+/** Set inside the frame: the plate's two corner tags (the figure's name and its read-out) and the rules line under it. */
+const QUIET = "hl-site-quiet";
+const HIDDEN = "#name, #read, #rules { display: none !important; }";
+
/**
* 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. The pages
* are served from the site's own origin; were they not, `contentDocument`
* would be null and the frame would keep its CSS height.
+ *
+ * Here an example shows only the figure, its controls and what it means: the
+ * name tag, the read-out and the rules line are hidden from the site's side,
+ * by one style added to the frame's document before it is measured, because
+ * the page itself stays exactly as the skill wrote it. Its error line is left
+ * alone, so a figure that throws still says so.
*/
export function ExampleFrame({ src, title }: { src: string; title: string }) {
const frame = useRef<HTMLIFrameElement>(null);
@@ -21,8 +31,15 @@ export function ExampleFrame({ src, title }: { src: string; title: string }) {
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 doc = el.contentDocument;
+ const main = doc?.querySelector("main");
+ if (!view || !doc || !main) return;
+ if (!doc.getElementById(QUIET)) {
+ const style = doc.createElement("style");
+ style.id = QUIET;
+ style.textContent = HIDDEN;
+ doc.head.append(style);
+ }
const size = () => { el.style.height = `${Math.ceil(main.getBoundingClientRect().height) + PAD}px`; };
size();
watch?.disconnect();
diff --git a/apps/site/test/skill.spec.ts b/apps/site/test/skill.spec.ts
index 2eb83e1..02619ea 100644
--- a/apps/site/test/skill.spec.ts
+++ b/apps/site/test/skill.spec.ts
@@ -71,21 +71,31 @@ test("a figure on /skill answers the pointer and goes back to rest", async ({ pa
}
});
-test("each frame is named by what its figure means, and its link opens the page the skill wrote", async ({ page, request }) => {
+test("each frame is named by what its figure means, and shows the page the skill wrote, light", 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!);
+ const frame = row.locator("iframe");
+ expect((await frame.getAttribute("title"))!.length).toBeGreaterThan(20);
+ const src = (await frame.getAttribute("src"))!;
+ expect(src).toMatch(/^\/skill\/hairline-[a-z0-9-]+\.html\?theme=light$/);
+ const res = await request.get(src.replace(/\?.*$/, ""));
expect(res.status()).toBe(200);
expect(res.headers()["content-type"]).toContain("text/html");
expect(await res.text()).toContain('id="hl-figure"');
}
});
+test("each example shows the figure, its controls and what it means, without the page's name tags or rules line", async ({ page }) => {
+ await page.goto("/skill");
+ await expect(page.getByRole("link", { name: "Open the page" })).toHaveCount(0);
+ for (const frame of await frames(page)) {
+ for (const hidden of ["#name", "#read", "#rules"]) await expect(frame.locator(hidden)).toBeHidden();
+ await expect(frame.locator("#means")).toBeVisible();
+ await expect(frame.locator("#intensity")).toBeVisible();
+ }
+});
+
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");
@@ -158,11 +168,11 @@ test.describe("on a dark system", () => {
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 }) => {
+ test("/skill still gives the install command, the prompts and the frames with 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);
+ await expect(page.locator('[data-example] iframe[src^="/skill/hairline-"]')).toHaveCount(4);
});
});