'use strict'; // Rasterise an icon SVG to PNG at a given size, using the `ui` package's cached // Playwright chromium (no extra install). Usage: // node render-png.mjs [size=1024] import { readFileSync, writeFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import { dirname, join } from 'node:path'; const DIR = dirname(fileURLToPath(import.meta.url)); const pw = await import(join(DIR, '..', '..', '..', 'ui', 'node_modules', '@playwright', 'test', 'index.js')); const { chromium } = pw.default ?? pw; const [, , svgPath, pngPath, size] = process.argv; const S = Number(size) || 1024; const svg = readFileSync(svgPath, 'utf8'); const b = await chromium.launch(); const pg = await b.newPage({ viewport: { width: S, height: S }, deviceScaleFactor: 1 }); await pg.setContent(`${svg}`, { waitUntil: 'networkidle' }); writeFileSync(pngPath, await pg.locator('svg').screenshot({ omitBackground: true })); await b.close(); console.log('wrote', pngPath, S + 'px');