// THE STAGE (operator, 5 Nov: "look at all layouts and make the bg colors match"): every post layout's page is the // palette's bg, edge to edge -- the card a box on it, never a full-frame fill -- so nothing changes the background // between items. Rendered in chromium, each layout's frame edges sampled. (The jump the operator saw was the // ENCODE's colour range, color-range.test.mjs; this holds the pages to the same colour so that fix is the whole fix.) import assert from "node:assert/strict"; import { spawnSync } from "node:child_process"; import { test } from "node:test"; import { panelEntry, postCardHtml, postItemPlan, postLayout } from "./post-item.mjs"; import { verticalPostBox } from "./vertical.mjs"; const have = (cmd, args) => { try { return spawnSync(cmd, args, { stdio: "ignore" }).status === 0; } catch { return false; } }; const BG = "#12100c"; const palette = { bg: BG, fg: "#efe6d2", accent: "#e08a2c" }; const render = { fps: 30, palette }; const at = "2026-11-04T01:06:00.000Z"; const post = (id, text, o = {}) => ({ type: "post", id: `p-${id}`, post: `acct-x/${id}`, platform: "x", author: "MR. OBVIOUS", handle: "ObviousRises", date: at, text, likes: 11, replies: 5, ...o }); const pic = (w, h, src = "posts-media/a/1.jpg") => ({ src, kind: "image", width: w, height: h }); const parent = (id, text, o = {}) => ({ id, handle: "LikeAStoneKiwi", author: "LikeAStone", date: at, text, ...o }); const deck = { width: 1610, height: 906 }; /** Each layout as the render draws its page: `[name, entry, box, opts]`. */ function layouts() { const out = []; const add = (name, entry, box = deck, o = {}) => { const plan = postItemPlan(entry, render, o.ctx ?? {}); out.push([name, entry, box, { follow: !!plan.follow, thread: plan.follow?.thread ?? null, ...o.html }]); }; add("lone text card", post("1", "I should shower")); add("lone text card, long read", post("2", "A long read. ".repeat(60))); add("card + image beside (side)", post("3", "Look at this.", { media: [pic(1200, 800)] })); add("card + tall image (side)", post("4", "Tall.", { media: [pic(600, 1200)] })); add("wide image (panelEntry)", panelEntry(post("5", "A wide one.", { media: [pic(1400, 200)] }), render)); add("thread column", post("6", "I don't dox him by choice.", { parents: [parent("9", "Careful, I saw your brother warming up.")] })); add("thread column with a slot", post("7", "Reply with a picture.", { parents: [parent("9", "Careful.", { media: [pic(800, 600)] })] })); add("quote tile", post("8", "Quoting this.", { quoted: { id: "10", handle: "someone", author: "Someone", date: at, text: "The quoted words." } })); add("picture-only post", post("11", "", { media: [pic(800, 600)] })); add("stack, media phase", post("12", "Two pictures.", { media: [pic(800, 600), pic(800, 600, "posts-media/a/2.jpg")] }), deck, { html: { phase: "media" } }); const vb = verticalPostBox(render).box; add("vertical card", post("13", "I should shower"), { width: vb.width, height: vb.height }); add("vertical with a picture", post("14", "Look.", { media: [pic(1200, 800)] }), { width: vb.width, height: vb.height }); return out; } const hex = ([r, g, b]) => `#${[r, g, b].map((v) => v.toString(16).padStart(2, "0")).join("")}`; test("every post layout's page is the palette's bg at every edge of the frame (chromium)", { skip: !have(process.env.CHROME ?? "/usr/bin/chromium", ["--version"]) }, async () => { const mod = await import("@playwright/test"); const chromium = mod.chromium ?? mod.default?.chromium; const browser = await chromium.launch(process.env.CHROME ? { executablePath: process.env.CHROME } : {}); const ff = have("ffmpeg", ["-version"]); try { const rows = []; for (const [name, entry, box, o] of layouts()) { const layout = postLayout(entry, box); const page = await browser.newPage({ viewport: { width: box.width, height: box.height } }); await page.setContent(postCardHtml(entry, { width: box.width, height: box.height, palette, ...o }), { waitUntil: "load" }); // The page's own background (what the encode sees behind the card) and the frame's edge pixels. const css = await page.evaluate(() => [getComputedStyle(document.documentElement).backgroundColor, getComputedStyle(document.body).backgroundColor]); const shot = await page.screenshot({ type: "png" }); await page.close(); let edges = null; if (ff) { // The screenshot's pixels, decoded by ffmpeg (rgb24, row-major). const raw = spawnSync("ffmpeg", ["-v", "error", "-i", "pipe:0", "-f", "rawvideo", "-pix_fmt", "rgb24", "pipe:1"], { input: shot, maxBuffer: 1 << 26 }).stdout; const W = box.width, H = box.height; const px = (x, y) => { const i = (y * W + x) * 3; return [raw[i], raw[i + 1], raw[i + 2]]; }; edges = [[1, 1], [W - 2, 1], [1, H - 2], [W - 2, H - 2], [Math.round(W / 2), 1], [1, Math.round(H / 2)]].map(([x, y]) => hex(px(x, y))); } rows.push({ name, mode: layout.mode, css, edges }); if (process.env.STAGE_TABLE) console.log(`${name}\t${layout.mode}\t${css[1]}\t${edges?.join(" ")}`); } for (const r of rows) { assert.deepEqual(r.css, ["rgb(18, 16, 12)", "rgb(18, 16, 12)"], `${r.name} (${r.mode}): the page is palette.bg`); if (r.edges) for (const e of r.edges) assert.equal(e, BG, `${r.name} (${r.mode}): a frame edge is ${e}, not the stage ${BG} -- ${JSON.stringify(r.edges)}`); } // Two consecutive layouts (the mid-21 cut: an item with its picture beside, then a lone card) share the stage. const side = rows.find((r) => r.name === "card + image beside (side)"); const lone = rows.find((r) => r.name === "lone text card"); assert.deepEqual(side.css, lone.css); if (side.edges) assert.deepEqual(side.edges, lone.edges); } finally { await browser.close(); } });