Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677#!/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 `<rect x="${x}" y="${y}" width="${w}" height="${h}" fill="${HUE[hue]}"/>`;}// The disc: gold with a lead rim, and a lead pen stroke written across it.const coin = ` <circle cx="512" cy="548" r="262" fill="${LEAD}"/> <circle cx="512" cy="548" r="226" fill="${HUE.gold}"/> <circle cx="512" cy="548" r="186" fill="none" stroke="${HUE.goldInk}" stroke-width="10" opacity="0.5"/> <path d="M 372 612 C 420 470, 470 450, 480 540 C 486 600, 450 640, 430 600 C 420 560, 500 470, 560 480 C 620 490, 560 620, 600 600 C 640 580, 630 470, 660 500" fill="none" stroke="${LEAD}" stroke-width="30" stroke-linecap="round" stroke-linejoin="round"/>`;
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${S} ${S}" width="${S}" height="${S}"> <defs><clipPath id="pane"><rect x="${INSET}" y="${INSET}" width="${SIZE}" height="${SIZE}" rx="${R}"/></clipPath></defs> <rect x="${INSET}" y="${INSET}" width="${SIZE}" height="${SIZE}" rx="${R}" fill="${LEAD}"/> <g clip-path="url(#pane)">${panes.map(pane).join('')}</g>${coin}</svg>`;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, `<!doctype html><html><body style="margin:0;background:transparent"><img src="file://${svgPath}" width="${S}" height="${S}"></body></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');