Skip to content

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

Skill page: each figure's plate starts on its prompt's line and reaches the column's edges, and its frame is fitted to the whole pixel

Lucas Marquesfa61654fc37e
diff --git a/apps/site/app/globals.css b/apps/site/app/globals.css
index 2591d3b..821732f 100644
--- a/apps/site/app/globals.css
+++ b/apps/site/app/globals.css
@@ -358,8 +358,12 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }
/* a follow-up is a sentence: it wraps in its pill, and the copy icon stays by its first line */
.pill[data-command="follow-up"] { height: auto; min-height: 48px; padding-block: 6px; align-items: start; }
.pill[data-command="follow-up"] .pill-line { padding-block: 8px; line-height: 20px; white-space: normal; overflow: visible; text-wrap: pretty; }
-/* 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; }
+/* 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
+ 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; }
.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); }
@@ -368,4 +372,5 @@ 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/components/example-frame.tsx b/apps/site/components/example-frame.tsx
index 9209c63..ed821e6 100644
--- a/apps/site/components/example-frame.tsx
+++ b/apps/site/components/example-frame.tsx
@@ -2,13 +2,15 @@
import { useEffect, useRef } from "react";
-/** The generated page's body has 24px of padding above and below its one column. */
+/** 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;
/**
* 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.
+ * 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.
*/
export function ExampleFrame({ src, title }: { src: string; title: string }) {
const frame = useRef<HTMLIFrameElement>(null);
@@ -21,7 +23,7 @@ export function ExampleFrame({ src, title }: { src: string; title: string }) {
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`; };
+ const size = () => { el.style.height = `${Math.ceil(main.getBoundingClientRect().height) + PAD}px`; };
size();
watch?.disconnect();
// the frame's own observer: its column is in the frame's document
diff --git a/apps/site/test/skill.spec.ts b/apps/site/test/skill.spec.ts
index 71ee797..d744be1 100644
--- a/apps/site/test/skill.spec.ts
+++ b/apps/site/test/skill.spec.ts
@@ -27,8 +27,14 @@ async function frames(page: Page): Promise<FrameLocator[]> {
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 }));
+/**
+ * Measured inside the frame, apart from how the frame is fitted: whether its page scrolls, and the band left under
+ * its column beyond the page's own 24px of padding.
+ */
+const fit = (frame: FrameLocator) => frame.locator("main").evaluate((main) => ({
+ scrolls: document.documentElement.scrollHeight > document.documentElement.clientHeight,
+ band: window.innerHeight - main.getBoundingClientRect().bottom - 24,
+}));
test("/skill opens with the install command, four prompts and four live figures, and a clean console", async ({ page }) => {
const noise = watch(page);
@@ -96,11 +102,28 @@ for (const width of [1200, 320]) {
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);
+ await expect.poll(async () => { const f = await fit(frame); return !f.scrolls && f.band < 1; }).toBe(true);
}
});
}
+test("at 1200px each plate starts on its prompt's line and meets the column's edges", async ({ page }) => {
+ await page.goto("/skill");
+ await frames(page);
+ await page.evaluate(() => window.scrollTo(0, 0));
+ for (const row of await page.locator("[data-example]").all()) {
+ const m = await row.evaluate((el) => {
+ const frame = el.querySelector("iframe")!;
+ const at = frame.getBoundingClientRect();
+ const plate = frame.contentDocument!.querySelector(".plate")!.getBoundingClientRect();
+ const figure = el.querySelector(".example-figure")!.getBoundingClientRect();
+ const pill = el.querySelector('[data-command="prompt"]')!.getBoundingClientRect();
+ return { top: at.top + plate.top - pill.top, left: at.left + plate.left - figure.left, right: at.left + plate.right - figure.right };
+ });
+ for (const d of Object.values(m)) expect(Math.abs(d)).toBeLessThan(1);
+ }
+});
+
test.describe("on a dark system", () => {
test.use({ colorScheme: "dark" });