/**
* Renders the Freezmo app icons (PWA + iOS) from the master artwork with
* headless Chromium.
* Run: node scripts/make-icons.mjs (requires a Playwright Chromium cache)
*
* Master: assets/app-icon-source.jpeg — a 1024x1024 navy rounded square.
* 1. The master is masked at full resolution first (a rounded rect 4px
* inside the artwork's own corner radius), so the JPEG's anti-aliased
* white edge never survives and small sizes downscale with clean alpha.
* 2. "any" icons use that masked master as-is.
* Apple touch icons are full-bleed, because iOS paints transparency
* black; the artwork is zoomed 20% so its corners fall outside the
* square (the master's corners are ~85px, so nothing else is cropped).
* The maskable icon keeps the artwork inside the 80% safe circle on a
* matching navy field.
* Also writes app/favicon.ico, the Next.js file convention for the browser
* tab (the larger sizes are declared in app/layout.tsx metadata).
*/
import { chromium } from "playwright-core";
import { mkdirSync, existsSync, readFileSync, writeFileSync } from "node:fs";
const CHROME = process.env.CHROME ?? "/home/martin/.cache/ms-playwright/chromium-1243/chrome-linux64/chrome";
const ROOT = new URL("../", import.meta.url).pathname;
const OUT = `${ROOT}public/icons/`;
const SOURCE = `${ROOT}assets/app-icon-source.jpeg`;
mkdirSync(OUT, { recursive: true });
/** Sampled from the master artwork: background colour, size, corner radius. */
const NAVY = "#101528";
const SIZE = 1024;
const CORNER = 253;
const ERODE = 4; // keeps the clip inside the artwork's anti-aliased edge
const sourceUri = `data:image/jpeg;base64,${readFileSync(SOURCE).toString("base64")}`;
const browser = await chromium.launch({ executablePath: CHROME, args: ["--no-sandbox"] });
/* Stage 1: mask the master at full resolution. */
const masterHtml = `