diff --git a/internal/check-poster-raster.mjs b/internal/check-poster-raster.mjs new file mode 100644 index 000000000..f588d80cb --- /dev/null +++ b/internal/check-poster-raster.mjs @@ -0,0 +1,86 @@ +// check-poster-raster — a poster with NO pre-rendered image must still download. +// +// ★ THE POINT: 378 posters ship as .webp — 41 MB in every clone, delivered to every +// reader whether or not they open one, and a publish was ALREADY rejected once at a +// 74 MB asset tree. Driver: "it would be a big win to not have to have 80mb of +// images in a public folder and let the posters get generated by the website." +// +// The fallback rasterises posters/.html in the browser. This gate proves the +// generated image is REAL, because the failure mode here is silent and total: +// +// ⚠ AN SVG LOADED THROUGH IS AN ISOLATED DOCUMENT. It cannot see the host +// page's CSS, so every var() falls back to its initial value — and `fill`'s initial +// value is BLACK. A poster that lost its stylesheet downloads as a black rectangle +// with no error, no exception and a perfectly normal file size. So this gate +// MEASURES PIXELS: mean luminance and colour variety, not "did it produce bytes". +// +// Usage: node internal/check-poster-raster.mjs [zoneId] +// PACKET_ORIGIN (default http://127.0.0.1:4898) +import { chromium } from 'playwright' + +const ORIGIN = process.env.PACKET_ORIGIN || 'http://127.0.0.1:4898' +const ZONE = process.argv[2] || 'laos' +const HTML = `${ORIGIN}/library/scripts/posters/out/posters/${ZONE}.html` + +const b = await chromium.launch() +const pg = await b.newPage({ viewport: { width: 1200, height: 900 } }) +const errs = []; pg.on('pageerror', e => errs.push(String(e).slice(0, 140))) +await pg.goto(ORIGIN + '/') + +const r = await pg.evaluate(async ({ ORIGIN, HTML }) => { + const { rasterPoster, looksRendered, inlineSvg } = + await import(`${ORIGIN}/library/packet/poster-raster.js`) + const res = await fetch(HTML) + if (!res.ok) return { error: `poster HTML ${res.status}` } + const html = await res.text() + + // The stylesheet must actually travel with the svg. + const svg = inlineSvg(html) + const carriesCss = /