// Capture the L2–L4 layout prototype through the repository's zero-dependency // Chrome DevTools driver. Read-only import: web/test/browser.mjs is not modified. // // node web/design/layout/capture.mjs // // Writes PNGs into web/design/layout/captures/ (gitignored by the root // `captures/` rule). No server is started; the prototype is a local file. import { mkdir } from "node:fs/promises"; import { dirname, join } from "node:path"; import { fileURLToPath, pathToFileURL } from "node:url"; import { launchChrome } from "../../test/browser.mjs"; const here = dirname(fileURLToPath(import.meta.url)); const outDir = join(here, "captures"); const prototype = pathToFileURL(join(here, "prototype.html")); const shots = [ { hash: "wide", width: 1440, height: 900, name: "wide-pipelines-1440x900.png" }, { hash: "runs", width: 420, height: 900, name: "narrow-runs-420x900.png" }, { hash: "detail", width: 420, height: 900, name: "narrow-run-detail-420x900.png" }, ]; await mkdir(outDir, { recursive: true }); const browser = await launchChrome({ width: 1440, height: 900 }); try { for (const shot of shots) { const page = await browser.openPage(`${prototype.href}#${shot.hash}`, { width: shot.width, height: shot.height, }); await page.waitForSelector(`#${shot.hash}`); await page.evaluate("document.fonts.ready.then(() => true)"); await new Promise((resolve) => setTimeout(resolve, 150)); const box = await page.evaluate(`(() => { const node = document.querySelector("#${shot.hash} .app-shell"); const rect = node.getBoundingClientRect(); return { width: Math.round(rect.width), height: Math.round(rect.height) }; })()`); const path = join(outDir, shot.name); await page.screenshot(path); console.log(`${shot.name}: viewport ${shot.width}x${shot.height}, shell ${box.width}x${box.height}`); await page.close(); } } finally { await browser.close(); }