32 lines
1.7 KiB
JavaScript
32 lines
1.7 KiB
JavaScript
// Erzeugt die Symbole der PWA aus docs/icon/lunch.svg (Chromium über
|
||
// Playwright, nur lokal nötig): public/icon.svg, apple-touch-icon.png,
|
||
// icon-192.png, icon-512.png, icon-512-maskable.png und olares/icon.png (512 × 512, geht als lunch/icon.png nach aimighty/bilder).
|
||
// Ändert sich das Symbol, alle neu erzeugen und mit committen.
|
||
import { copyFile, readFile } from "node:fs/promises";
|
||
import { createRequire } from "node:module";
|
||
|
||
// Playwright ist keine Abhängigkeit des Projekts; global installiert reicht.
|
||
const { chromium } = createRequire(import.meta.url)("playwright");
|
||
|
||
const svg = await readFile("docs/icon/lunch.svg", "utf8");
|
||
const browser = await chromium.launch();
|
||
const page = await browser.newPage();
|
||
|
||
async function render(file, size, { maskable = false } = {}) {
|
||
// Maskierbar: Motiv auf 80 % in sicherer Zone, Rand in Terrakotta.
|
||
const inner = maskable ? Math.round(size * 0.8) : size;
|
||
await page.setViewportSize({ width: size, height: size });
|
||
await page.setContent(`<html><body style="margin:0;background:${maskable ? "#b8573a" : "transparent"};display:grid;place-items:center;width:${size}px;height:${size}px">
|
||
<div style="width:${inner}px;height:${inner}px">${svg.replace("<svg ", `<svg width="${inner}" height="${inner}" `)}</div></body></html>`);
|
||
await page.screenshot({ path: file, omitBackground: !maskable });
|
||
}
|
||
|
||
await copyFile("docs/icon/lunch.svg", "public/icon.svg");
|
||
await render("public/apple-touch-icon.png", 180, { maskable: true });
|
||
await render("public/icon-192.png", 192);
|
||
await render("public/icon-512.png", 512);
|
||
await render("public/icon-512-maskable.png", 512, { maskable: true });
|
||
await render("olares/icon.png", 512);
|
||
await browser.close();
|
||
console.log("icons written");
|