storebound/tools/fixture-art.ts
CRT 82066de5ed No hand-written SVG: visx charts, lucide icons, Mermaid journey diagram
- desktop: Growth chart, Health and portfolio sparklines and the rollout bar drawn with visx (responsive width,
  crosshair tooltip with real values, arrow keys, theme tokens, no animation); icons from lucide-react behind the
  existing Icon names; empty states are lucide icons on token tiles; store marks are generic lucide icons; stars are
  lucide; the brand mark moves to ui/brand.tsx as the one allowed inline SVG
- fixtures: app icons and store art stand-ins are PNGs rendered by tools/fixture-art.ts (lucide on gradients)
- site: icons are lucide's own files in site/img/icons (tools/site-icons.ts, with the ISC licence) shown as CSS masks;
  the journey diagram is rendered from docs/diagrams/journey.mmd by tools/diagrams.ts (Mermaid CLI), with a tall
  variant for phones
- tests/no-handmade-svg.test.ts fails on new inline SVG drawing in apps/desktop/src and site/*.html
- desktop bundle: 598.7 -> 695.5 kB minified, 174.6 -> 206.0 kB gzip
2026-10-11 00:49:30 +00:00

70 lines
4.9 KiB
TypeScript

#!/usr/bin/env bun
// Renders the desktop dev fixtures' art (apps/desktop/src/dev/art/*.png): app icons and store screenshot stand-ins,
// each a lucide icon (lucide-static, ISC) on a CSS gradient, photographed by Playwright's Chromium. No drawn SVG: the
// icons are lucide's own files. Dev only (the fixtures never ship in the release bundle).
// bun tools/fixture-art.ts (Playwright's Chromium, or an installed Google Chrome; same launcher as storebound shots)
import { mkdirSync, readFileSync, renameSync } from 'node:fs';
import { join } from 'node:path';
import { launch } from '../cli/shots/browser';
const root = new URL('..', import.meta.url).pathname;
const out = join(root, 'apps/desktop/src/dev/art');
const lucide = (name: string) => readFileSync(join(root, 'node_modules/lucide-static/icons', `${name}.svg`), 'utf8').replace(/<!--.*?-->/s, '');
/** [file, lucide icon, gradient from, gradient to] */
const ICONS: [string, string, string, string][] = [
['icon-prism', 'droplets', '#7c5cff', '#ff5fa2'], ['icon-tidy', 'list-checks', '#2fd18b', '#0f9d74'],
['icon-orbit', 'orbit', '#0ea5e9', '#6366f1'], ['icon-block', 'blocks', '#22c55e', '#15803d'],
['icon-lantern', 'lamp', '#f59e0b', '#b45309'], ['icon-tycoon', 'coins', '#a855f7', '#6d28d9'],
['icon-racer', 'car-front', '#ef4444', '#991b1b'], ['icon-habit', 'egg', '#14b8a6', '#0f766e'],
['icon-focus', 'timer', '#f43f5e', '#be123c'], ['icon-sketch', 'star', '#fb923c', '#ea580c'],
['icon-night', 'moon', '#1e293b', '#4338ca'], ['icon-mood', 'grid-2x2', '#ec4899', '#8b5cf6'],
];
/** Four scenes of the demo game: [lucide icon, from, to, accent] */
const SCENES: [string, string, string, string][] = [
['droplets', '#7c5cff', '#ff5fa2', '#ffd36e'], ['zap', '#ff7a59', '#ff3d7f', '#ffe08a'],
['calendar-days', '#2fb5ff', '#5b6cff', '#b8f3ff'], ['trophy', '#ffb03b', '#ff7a1a', '#fff1b8'],
];
/** Screenshot shapes at a small preview size, in the stores' aspect ratios. */
const SHAPES: [string, number, number][] = [['phone', 240, 521], ['play', 240, 427], ['ipad', 300, 400], ['feature', 512, 250]];
const page = (w: number, h: number, body: string, css: string) =>
`<!doctype html><html><head><style>*{margin:0;box-sizing:border-box}html,body{width:${w}px;height:${h}px;overflow:hidden}${css}</style></head><body>${body}</body></html>`;
mkdirSync(out, { recursive: true });
const browser = await launch(root, {});
const tab = await browser.newPage({ deviceScaleFactor: 1 });
async function snap(file: string, w: number, h: number, html: string) {
await tab.setViewportSize({ width: w, height: h });
await tab.setContent(html);
const png = join(out, `${file}.png`);
await tab.screenshot({ path: png, clip: { x: 0, y: 0, width: w, height: h } });
// 8-bit palette PNG (ffmpeg, already needed for storebound icons): about a quarter of the bytes; kept as is without it
if (Bun.which('ffmpeg')) {
const tmp = `${png}.q.png`;
const r = Bun.spawnSync(['ffmpeg', '-v', 'error', '-y', '-i', png, '-vf', 'split[a][b];[a]palettegen=max_colors=96:stats_mode=full[p];[b][p]paletteuse=dither=bayer:bayer_scale=3', tmp]);
if (r.exitCode === 0) renameSync(tmp, png);
}
console.log(`fixture-art: ${file}.png ${w}x${h}`);
}
for (const [file, icon, a, b] of ICONS) {
await snap(file, 128, 128, page(128, 128, `<div class="t">${lucide(icon)}</div>`,
`.t{width:128px;height:128px;display:grid;place-items:center;background:linear-gradient(135deg,${a},${b});color:#fff}.t svg{width:72px;height:72px;stroke-width:1.8}`));
}
for (const [i, [icon, a, b, c]] of SCENES.entries()) {
for (const [shape, w, h] of SHAPES) {
const land = w > h;
const phone = land ? { w: h * 0.42, h: h * 0.86 } : { w: w * 0.62, h: Math.min(h * 0.72, w * 0.62 * 2.05) };
await snap(`scene${i + 1}-${shape}`, w, h, page(w, h,
`<div class="bg"><div class="glow"></div><div class="big">${lucide(icon)}</div><div class="ph"><div class="scr">${lucide(icon)}</div></div></div>`,
`.bg{position:relative;width:${w}px;height:${h}px;background:linear-gradient(135deg,${a},${b});color:#fff;overflow:hidden}
.glow{position:absolute;inset:0;background:radial-gradient(circle at 50% 30%,rgba(255,255,255,.35),transparent 70%)}
.big{position:absolute;${land ? `left:${w * 0.1}px;top:${h * 0.22}px` : `left:50%;top:${h * 0.05}px;transform:translateX(-50%)`};color:${c}}
.big svg{width:${land ? h * 0.5 : w * 0.26}px;height:${land ? h * 0.5 : w * 0.26}px;stroke-width:2.2}
.ph{position:absolute;width:${phone.w}px;height:${phone.h}px;${land ? `right:${w * 0.1}px;top:${h * 0.07}px` : `left:50%;bottom:-${phone.w * 0.12}px;transform:translateX(-50%)`};
border-radius:${phone.w * 0.14}px;background:#10142a;border:${Math.max(2, phone.w * 0.03)}px solid rgba(255,255,255,.85);padding:${phone.w * 0.06}px}
.scr{width:100%;height:100%;border-radius:${phone.w * 0.08}px;background:#1d2350;display:grid;place-items:center;color:${c}}
.scr svg{width:45%;height:45%;stroke-width:1.6}`));
}
}
await browser.close();