#!/usr/bin/env node
// Generate the app icon set from one SVG mark, rendered through headless Chrome.
//
// node store/icons/make.js
//
// Writes into assets/images/:
// icon.png 1024×1024 opaque (iOS + fallback)
// android-icon-background.png 1024×1024 opaque (adaptive background: ember glow)
// android-icon-foreground.png 1024×1024 alpha (adaptive foreground, mark in the 66dp safe zone)
// android-icon-monochrome.png 1024×1024 alpha (themed icon, white mark)
// splash-icon.png 512×512 alpha (splash, mark only)
//
// The mark is the hold ring from the session screen: an open ring whose colour
// sweeps from a dim ember tail to a hot amber head (the hold timer mid-squeeze),
// around a glowing core: "squeeze". Colours from src/lib/theme.ts. After running,
// regenerate the committed Android res with `npx expo prebuild -p android --no-install`
// and restore the release signingConfigs block in android/app/build.gradle from git.
const fs = require("fs");
const path = require("path");
const { execFileSync } = require("child_process");
const CHROME = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome";
const OUT = path.join(__dirname, "..", "..", "assets", "images");
const TMP = path.join(__dirname, ".tmp");
const C = { bg: "#160B0B", glow: "#3B1612", edge: "#0D0606" };
// ring colour along the sweep: tail → head
const SWEEP = [[0, "#9E2418"], [0.5, "#DE3A2B"], [0.82, "#F6612F"], [1, "#FFA94D"]];
const RING = { start: 38, sweep: 292 }; // degrees clockwise from 12 o'clock; the gap sits over the top
const hex = (h) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16));
function mix(t) {
for (let i = 0; i < SWEEP.length - 1; i++) {
const [p0, c0] = SWEEP[i];
const [p1, c1] = SWEEP[i + 1];
if (t <= p1) {
const k = p1 === p0 ? 0 : (t - p0) / (p1 - p0);
const [a, b] = [hex(c0), hex(c1)];
return "#" + a.map((x, j) => Math.round(x + (b[j] - x) * k).toString(16).padStart(2, "0")).join("");
}
}
return SWEEP[SWEEP.length - 1][1];
}
const pt = (c, r, deg) => {
const a = ((deg - 90) * Math.PI) / 180;
return [c + r * Math.cos(a), c + r * Math.sin(a)];
};
const f = (n) => n.toFixed(2);
function background(size) {
return `
`;
}
// size: canvas px; scale: fraction of the canvas the ring spans.
function mark(size, scale, { mono = false, glow = true } = {}) {
const c = size / 2;
const R = (size * scale) / 2; // outer radius
const sw = R * 0.3;
const rr = R - sw / 2;
const core = R * 0.3;
const { start, sweep } = RING;
if (mono) {
const [x0, y0] = pt(c, rr, start);
const [x1, y1] = pt(c, rr, start + sweep);
return ``;
}
// SVG has no sweep gradient: draw the arc as short segments, each in its own colour.
const n = 180;
let ring = "";
for (let i = 0; i < n; i++) {
const [x0, y0] = pt(c, rr, start + (sweep * i) / n);
const [x1, y1] = pt(c, rr, start + (sweep * (i + 1)) / n + 0.6); // slight overlap hides seams
ring += ``;
}
const [tx, ty] = pt(c, rr, start);
const [hx, hy] = pt(c, rr, start + sweep);
ring += ``;
return `
${glow ? `${ring}
` : ""}
${ring}
`;
}
const svg = (size, body) =>
``;
function render(svgText, size, out, transparent) {
fs.mkdirSync(TMP, { recursive: true });
const file = path.join(TMP, path.basename(out, ".png") + ".html");
fs.writeFileSync(
file,
`
${svgText}`,
);
const args = [
"--headless=new", "--disable-gpu", "--hide-scrollbars", "--force-device-scale-factor=1",
`--window-size=${size},${size}`, `--screenshot=${out}`,
];
if (transparent) args.push("--default-background-color=00000000");
args.push("file://" + file);
execFileSync(CHROME, args, { stdio: "ignore" });
}
function main() {
// iOS: opaque, ring spans 64% of the canvas (Apple masks the corners itself).
render(svg(1024, background(1024) + mark(1024, 0.64)), 1024, path.join(OUT, "icon.png"), false);
// Android adaptive: ember-glow background + ring inside the 66dp safe circle.
render(svg(1024, background(1024)), 1024, path.join(OUT, "android-icon-background.png"), false);
render(svg(1024, mark(1024, 0.5)), 1024, path.join(OUT, "android-icon-foreground.png"), true);
// Android monochrome: white silhouette, a little smaller than the colour mark (themed icons read lighter).
render(svg(1024, mark(1024, 0.42, { mono: true })), 1024, path.join(OUT, "android-icon-monochrome.png"), true);
// Splash: mark only, on transparent; app.json sets the background colour.
render(svg(512, mark(512, 0.86, { glow: false })), 512, path.join(OUT, "splash-icon.png"), true);
fs.rmSync(TMP, { recursive: true, force: true });
console.log("wrote icon.png, android-icon-background.png, android-icon-foreground.png, android-icon-monochrome.png, splash-icon.png");
}
main();