SPB Git

Repository Public

make-icons.mts 2.9 KB 64 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Sheet8 * File             : scripts/make-icons.mts9 * Module           : scripts10 * Repository       : https://git.spboucher.ai/sheet11 * Project Website  : https://sheet.spboucher.ai12 * Created          : 2026-11-1713 * Last Modified    : 2026-11-1714 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243// Renders the PNG app icons from public/icons/icon.svg with headless Chromium. Run after changing the mark:44//   node_modules/.bin/tsx scripts/make-icons.mts45import { readFileSync, writeFileSync } from "node:fs";46import { chromium } from "playwright-core";4748const svg = readFileSync("public/icons/icon.svg", "utf8");49const browser = await chromium.launch();50const shot = async (file: string, size: number, pad: number, square: boolean) => {51  const page = await browser.newPage({ viewport: { width: size, height: size } });52  // Maskable and Apple icons are full-bleed squares (the platform applies its own mask).53  const inner = square ? svg.replace('rx="8"', 'rx="0"') : svg;54  await page.setContent(`<body style="margin:0;background:${square ? "#0e1726" : "transparent"};display:grid;place-items:center;height:100vh"><div style="width:${size - pad * 2}px;height:${size - pad * 2}px">${inner}</div></body>`);55  writeFileSync(`public/icons/${file}`, await page.screenshot({ omitBackground: !square }));56  await page.close();57};58await shot("icon-192.png", 192, 0, false);59await shot("icon-512.png", 512, 0, false);60await shot("icon-maskable-512.png", 512, 56, true);61await shot("apple-touch-icon.png", 180, 0, true);62await browser.close();63console.log("icons written");64
Files main
Menu

Theme