Branchwell

Inkspring / app · inkspring.ai / build / generate-brand-assets.mjs

1// Regenerate shipped logo images from the editable SVG, retaining each asset's layout.
2// Run from the desktop repo: node build/generate-brand-assets.mjs
3// Render on Expand, then copy the small shipped assets into their source locations.
4import fs from 'node:fs/promises';
5import path from 'node:path';
6import { fileURLToPath } from 'node:url';
7import { chromium } from 'playwright';
8import { execFileSync } from 'node:child_process';
9
10const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
11const output = '/Volumes/Expand/Codex Media/inkspring/brand-assets';
12await fs.access('/Volumes/Expand');
13await fs.mkdir(output, { recursive: true });
14const master = await fs.readFile(path.join(root, 'public/inkspring-mark.svg'), 'utf8');
15const paths = [...master.matchAll(/<path[^>]*d="([^"]+)"/g)].map(match => `<path d="${match[1]}"/>`).join('');
16const circle = master.match(/<circle[^>]*cx="([^"]+)"[^>]*cy="([^"]+)"[^>]*r="([^"]+)"/);
17if (paths.length === 0 || !circle) throw new Error('The master must contain the ink drops and a circle.');
18const [centerX, centerY, radius] = circle.slice(1, 4).map(Number);
19
20function mark([x, y, width, height], color) {
21 const sx = width / 1808;
22 const sy = height / 1789;
23 // Keep the dot circular even in the older, slightly taller bitmap layouts.
24 return `<g fill="${color}"><g transform="translate(${x} ${y}) scale(${sx} ${sy}) translate(-1102 -1124)"><g transform="translate(0 4000) scale(1 -1)">${paths}</g></g><circle cx="${x + (centerX - 1102) * sx}" cy="${y + (4000 - centerY - 1124) * sy}" r="${radius * Math.sqrt(sx * sy)}"/></g>`;
25}
26
27const paper = '#F5F2EC';
28const accent = '#C4613C';
29const variants = [
30 ['website/public/social-card.png', 1024, 1024, [154, 158, 716, 708], accent, paper, 0],
31 ['website/public/inkspring-logo.png', 992, 1072, [176, 200, 644, 688], '#000000', 'transparent', 0],
32 ['website/public/inkspring-logo-white.png', 992, 1072, [176, 200, 644, 688], '#FFFFFF', 'transparent', 0],
33 ['website/public/inkspring-logo-cyan.png', 992, 1072, [176, 200, 644, 688], '#22D3EE', 'transparent', 0],
34 ['website/public/inkspring-logo-flat.png', 992, 1072, [176, 200, 644, 688], '#22D3EE', '#030712', 0],
35 ['website/public/inkspring-logo-styled.png', 400, 400, [110, 112, 182, 180], '#FFFFFF', 'gradient', 48],
36 ['website/public/inkspring-logo-black-on-gradient.png', 400, 400, [110, 112, 182, 180], '#111116', 'gradient', 48],
37 ['website/public/inkspring-icon-black-gradient.png', 512, 512, [40, 56, 435, 432], '#111116', 'gradient', 80],
38 ['website/public/apple-touch-icon.png', 180, 180, [14.0625, 19.6875, 152.9297, 151.875], '#111116', 'gradient', 28.125],
39];
40for (const size of [16, 32, 128, 256, 512]) {
41 for (const retina of [false, true]) {
42 const pixels = size * (retina ? 2 : 1);
43 variants.push([`build/icon.iconset/icon_${size}x${size}${retina ? '@2x' : ''}.png`, pixels, pixels,
44 [154, 158, 716, 708].map(value => value * pixels / 1024), accent, paper, 0]);
45 }
46}
47
48const browser = await chromium.launch({ channel: 'chrome', headless: true });
49try {
50 for (const [file, width, height, box, color, background, rounding] of variants) {
51 const page = await browser.newPage({ viewport: { width, height }, deviceScaleFactor: 1 });
52 const fill = background === 'gradient' ? 'url(#background)' : background === 'transparent' ? 'none' : background;
53 const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}"><defs><linearGradient id="background" x1="0" y1="0" x2="1" y2="1"><stop stop-color="#22D3EE"/><stop offset="1" stop-color="#A855F7"/></linearGradient></defs><rect width="${width}" height="${height}" rx="${rounding}" fill="${fill}"/>${mark(box, color)}</svg>`;
54 await page.setContent(`<style>html,body{margin:0;background:transparent}svg{display:block}</style>${svg}`);
55 const target = path.join(output, file);
56 await fs.mkdir(path.dirname(target), { recursive: true });
57 await page.screenshot({ path: target, omitBackground: true, scale: 'css' });
58 // These small shipped assets belong in git; only large transient output stays on Expand.
59 await fs.copyFile(target, path.join(root, file));
60 await page.close();
61 }
62} finally {
63 await browser.close();
64}
65execFileSync('/usr/bin/iconutil', ['-c', 'icns', path.join(output, 'build/icon.iconset'), '-o', path.join(output, 'build/icon.icns')]);
66await fs.copyFile(path.join(output, 'build/icon.icns'), path.join(root, 'build/icon.icns'));
67console.log(`Rendered ${variants.length} logo/icon images and the macOS icon from the circular-dot SVG.`);