#!/usr/bin/env node // Draws the app icon — a leadlight window, cobalt-led, with a gold disc // carrying a lead pen stroke — as an SVG, rasterises it with macOS's own // tools (qlmanage, sips), and writes app/icons/icon.png (the app icon) and // app/icons/icon.svg (the page's favicon). import { execFileSync } from 'node:child_process'; import { copyFileSync, existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const iconsDir = path.join(root, 'icons'); mkdirSync(iconsDir, { recursive: true }); // Empyrean, from supram/css/tokens.css. const HUE = { ruby: '#fb5664', amber: '#f5991c', gold: '#f4cf24', emerald: '#22d08f', cobalt: '#6e9bfb', teal: '#21c4ed', cobaltInk: '#1b3f9c', goldInk: '#75620a' }; const LEAD = '#121212'; const S = 1024, INSET = 100, SIZE = 824, R = 185; const CAME = 18, N = 4; const M = (SIZE - (N + 1) * CAME) / N; // Mostly cobalt: the room this app lives in is blue. const panes = [ [0, 0, 2, 1, 'cobalt'], [2, 0, 1, 1, 'teal'], [3, 0, 1, 2, 'cobalt'], [0, 1, 1, 2, 'cobaltInk'], [1, 1, 2, 1, 'cobalt'], [1, 2, 1, 1, 'emerald'], [2, 2, 2, 1, 'cobalt'], [0, 3, 1, 1, 'cobalt'], [1, 3, 2, 1, 'cobaltInk'], [3, 3, 1, 1, 'teal'], ]; function pane ([c, r, cs, rs, hue]) { const x = INSET + CAME + c * (M + CAME); const y = INSET + CAME + r * (M + CAME); const w = cs * M + (cs - 1) * CAME; const h = rs * M + (rs - 1) * CAME; return ``; } // The disc: gold with a lead rim, and a lead pen stroke written across it. const coin = ` `; const svg = ` ${panes.map(pane).join('')}${coin} `; const svgPath = path.join(iconsDir, 'icon.svg'); writeFileSync(svgPath, svg); const tmp = mkdtempSync(path.join(tmpdir(), 'notable-icon-')); const png1024 = path.join(tmp, 'icon1024.png'); function viaQuickLook () { execFileSync('qlmanage', ['-t', '-s', String(S), '-o', tmp, svgPath], { stdio: 'ignore' }); const out = path.join(tmp, 'icon.svg.png'); if (!existsSync(out)) throw new Error('qlmanage produced nothing'); const info = execFileSync('sips', ['-g', 'hasAlpha', '-g', 'pixelWidth', out]).toString(); if (!/hasAlpha: yes/.test(info)) throw new Error('no alpha channel'); copyFileSync(out, png1024); } function viaChrome () { const chrome = ['/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', '/Applications/Chromium.app/Contents/MacOS/Chromium'].find(existsSync); if (!chrome) throw new Error('no Chrome to fall back to'); const html = path.join(tmp, 'icon.html'); writeFileSync(html, ``); execFileSync(chrome, ['--headless=new', '--disable-gpu', '--hide-scrollbars', '--default-background-color=00000000', `--window-size=${S},${S}`, `--screenshot=${png1024}`, `file://${html}`], { stdio: 'ignore' }); } try { viaQuickLook(); console.log('rasterised with qlmanage'); } catch (err) { console.log(`qlmanage: ${err.message}; using Chrome`); viaChrome(); } copyFileSync(png1024, path.join(iconsDir, 'icon.png')); rmSync(tmp, { recursive: true, force: true }); console.log('wrote app/icons/icon.svg and app/icons/icon.png');