// Unreleased: render the FlagTLDR icon SVGs (docs/icon/) to PNGs with headless Chrome – no network, no extension. // node icon-render.mjs [chosen] chosen = a-szczyt | b-lisc | c-kropla (installs it when given) // Outputs: docs/icon/variants/.png (256 preview), docs/icon/comparison.png (16/32/48/128 on light + dark), // and with [chosen]: docs/icon/flagtldr.svg, extension/icons/icon{16,32,48,128}.png, // docs/store/assets/{icon-128,logo-300,promo-440x280}.png // (16/32/48 full bleed for the toolbar; 128 = 96 px artwork + 16 px transparent padding, Chrome Web Store guideline) import puppeteer from "puppeteer-core"; import { renderStoreIcons } from "./icon-assets.mjs"; import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); const DIR = path.join(ROOT, "docs", "icon"), VAR = path.join(DIR, "variants"), ICONS = path.join(ROOT, "extension", "icons"); const CHROME = process.env.CHROME || process.argv[2], CHOSEN = process.argv[3]; const variants = fs.readdirSync(VAR).filter((f) => f.endsWith(".svg")).sort().map((f) => f.replace(/\.svg$/, "")); const uri = (svg) => "data:image/svg+xml;base64," + Buffer.from(svg).toString("base64"); const svgOf = (v) => fs.readFileSync(path.join(VAR, v + ".svg"), "utf8"); const browser = await puppeteer.launch({ executablePath: CHROME, headless: true, args: ["--no-sandbox", "--force-color-profile=srgb"] }); try { const p = await browser.newPage(); async function png(file, html, w, h) { await p.setViewport({ width: w, height: h, deviceScaleFactor: 1 }); await p.setContent(`${html}`); await p.evaluate(() => Promise.all([...document.images].map((i) => i.decode()))); await p.screenshot({ path: file, omitBackground: true, clip: { x: 0, y: 0, width: w, height: h } }); console.log("[icon]", path.relative(ROOT, file)); } const img = (v, s, pad = 0) => ``; for (const v of variants) await png(path.join(VAR, v + ".png"), img(v, 256), 256, 256); const SIZES = [16, 32, 48, 128]; const names = { "a-szczyt": "A · Szczyt (góra o świcie)", "b-lisc": "B · Liść", "c-kropla": "C · Kropla" }; const panel = (v, bg, fg) => `
${SIZES.map((s) => `
${img(v, s)}${s}px
`).join("")}
`; const sheet = `
FlagTLDR – warianty ikony
16 / 32 / 48 / 128 px w rzeczywistej wielkości (bez skalowania) · jasne i ciemne tło (np. pasek narzędzi Chrome)
${variants.map((v) => `
${names[v] || v}${v === CHOSEN ? "
✓ wybrany" : ""}
${panel(v, "#ffffff", "#0f1419")}${panel(v, "#202124", "#e8eaed")}
`).join("")}
`; await p.setViewport({ width: 1000, height: 100 }); await p.setContent(`${sheet}`); await p.evaluate(() => Promise.all([...document.images].map((i) => i.decode()))); const h = await p.evaluate(() => document.body.firstElementChild.getBoundingClientRect().height); await p.setViewport({ width: 1000, height: Math.ceil(h) }); await p.screenshot({ path: path.join(DIR, "comparison.png") }); console.log("[icon] docs/icon/comparison.png"); if (CHOSEN) { fs.copyFileSync(path.join(VAR, CHOSEN + ".svg"), path.join(DIR, "flagtldr.svg")); for (const s of [16, 32, 48]) await png(path.join(ICONS, `icon${s}.png`), img(CHOSEN, s), s, s); await png(path.join(ICONS, "icon128.png"), img(CHOSEN, 128, 16), 128, 128); await renderStoreIcons(browser, path.join(ROOT, "docs", "store", "assets")); } } finally { await browser.close(); }