/* build-app-icons.mjs — derive every icon the app ships from one source image. * * The source is assets/logoym.png (a PNG despite its old .jpeg name; it has a real alpha channel, * with the emblem's corners transparent). Everything else here is generated, so the app icon, the * iOS home-screen icon, the in-app brand mark and the Capacitor source icon can never drift apart * from each other or from the file the owner actually dropped in assets/. * * Run it after replacing the source: * * cd frontend && node scripts/build-app-icons.mjs * * `sharp` comes with @capacitor/assets (a devDependency here), which is the only reason it is * available without adding a dependency of our own — see CONTRIBUTING.md on that. * * THE ONE DESIGN DECISION: the emblem is dark green (its most common colour is #031808, its light * accents are greens too), and its corners are transparent. So a transparent icon would disappear * on a dark home screen, and a white one would put a white card behind an already-square logo. The * canvases below are filled with the emblem's OWN darkest green and the logo is centred at 88% of * the square: the corners it does not cover blend into it, the maskable safe circle stays clean, * and the icon reads as one piece at 180 px. Change ICON_BG to re-skin all of them at once. */ import sharp from 'sharp' import { readFileSync } from 'node:fs' import { fileURLToPath } from 'node:url' // sharp takes paths, not file: URLs — hence fileURLToPath here and in icon() below. const SRC = fileURLToPath(new URL('../../assets/logoym.png', import.meta.url)) const PUB = new URL('../public/', import.meta.url) const RES = new URL('../resources/', import.meta.url) /** The emblem's own dominant colour (sampled from the source), used to fill the icon squares. */ const ICON_BG = '#031808' /** Fraction of the canvas the emblem occupies. The maskable safe circle is 80% of the square, and * the emblem's own corners are transparent, so slightly past it costs nothing and gains size. */ const ICON_FIT = 0.88 /** Longest side of the in-app mark. Displayed at 52 px (tab bar) and ~88 px (login), so 256 covers * a 3× screen twice over; anything larger is bytes nobody looks at. */ const MARK_PX = 256 /* Every PNG here is written as a 256-colour palette. Measured against the full RGBA version the * mean per-channel error is 1.5/255 — invisible — for a file about 2.5× smaller: the emblem is * greens on greens, which is exactly what a palette is good at. The transparency survives as the * palette's own alpha entries (checked: the corners really are alpha 0.) */ const PNG = { palette: true, colours: 256, compressionLevel: 9, effort: 10 } const logo = sharp(SRC).ensureAlpha().trim() /** One opaque square with the emblem centred in it. */ async function icon(size, out) { const inner = Math.round(size * ICON_FIT) const placed = await logo.clone().resize(inner, inner, { fit: 'inside' }).png().toBuffer() await sharp({ create: { width: size, height: size, channels: 4, background: ICON_BG } }) .composite([{ input: placed, gravity: 'centre' }]) .png(PNG) .toFile(fileURLToPath(out)) console.log(` ${out.pathname.split('/').slice(-2).join('/')} ${size}x${size} bg ${ICON_BG}`) } console.log('generating app icons from assets/logoym.png') // The two the web app ships: icon-512 is declared "any maskable" in manifest.json (hence the // opaque background and the centred emblem), icon-180 is the iOS home screen and the favicon. await icon(512, new URL('icon-512.png', PUB)) await icon(180, new URL('icon-180.png', PUB)) // The in-app brand mark: transparent, so it sits on the page's own background. Used by the tab // bar's Start button, the login screen and the boot placeholder. await logo.clone().resize(MARK_PX, MARK_PX, { fit: 'inside' }).png(PNG) .toFile(fileURLToPath(new URL('logo.png', PUB))) const mark = readFileSync(fileURLToPath(new URL('logo.png', PUB))) console.log(` public/logo.png transparent ${(mark.length / 1024).toFixed(1)} KB`) // The Capacitor source icon for the native shells (docs/MOBILE.md: `npx @capacitor/assets // generate` reads resources/). Kept opaque and 1024 wide, which is what that tool wants. await icon(1024, new URL('icon.png', RES))