// Build-time helper. Runtime serves the generated WebP files without a browser. const fs = require('node:fs'); const path = require('node:path'); const {pathToFileURL} = require('node:url'); const {chromium} = require(process.env.SPLATANYTHING_PLAYWRIGHT_MODULE || 'playwright'); async function capture() { const [catalogPath, source, output] = process.argv.slice(2); if (!catalogPath || !source || !output) throw new Error('Expected catalog.json, HTML source directory, and output directory.'); const catalog = JSON.parse(fs.readFileSync(catalogPath, 'utf8')); fs.mkdirSync(output, {recursive:true}); const browser = await chromium.launch({ ...(process.env.SPLATANYTHING_CHROMIUM ? {executablePath:process.env.SPLATANYTHING_CHROMIUM} : {}), args:['--no-sandbox','--disable-dev-shm-usage','--use-angle=swiftshader','--enable-unsafe-swiftshader'] }); try { for (const [id, record] of Object.entries(catalog.scenes)) { const target = path.join(output, record.poster); if (fs.existsSync(target)) continue; const page = await browser.newPage({viewport:{width:1440,height:900}}); try { await page.goto(pathToFileURL(path.join(source, id+'.html')).href+'?noanim=1', {waitUntil:'domcontentloaded',timeout:180000}); await page.waitForFunction(()=>typeof window.captureFrame==='function', null, {timeout:180000}); const data = await page.evaluate(async()=>{ const image = await window.captureFrame({time:0,width:1440,height:900,supersample:1}); const raw = atob(image.data); const pixels = new Uint8ClampedArray(raw.length); for (let i=0;i{console.error(error);process.exitCode=1;});