// Renders the app icon set from one generated SVG using headless Chrome.
// Writes .kody/icon.{svg,png}, public/icons/*. Needs playwright-core and CHROME_PATH (default /usr/bin/google-chrome).
import { chromium } from 'playwright-core'
import { mkdirSync, writeFileSync } from 'node:fs'
function art({ pad = 0, round = true }) {
// pad shrinks the artwork toward the center for the maskable icon safe zone.
const cx = 256, cy = 262, R = 150
const n = 27
let beads = ''
const a0 = (-215 * Math.PI) / 180, a1 = (50 * Math.PI) / 180
let hx = 0, hy = 0, ha = 0
for (let i = 0; i < n; i++) {
const t = i / (n - 1)
const a = a0 + (a1 - a0) * t
const x = cx + Math.cos(a) * R, y = cy + Math.sin(a) * R
const r = 12 + t * 10
const hue = 175 - t * 55
const gun = i % 3 === 2 && i > 2
beads += ``
if (gun) beads += ``
if (i === n - 1) { hx = x; hy = y; ha = a + Math.PI / 2 }
}
const ship = ``
const rock = ``
const gem = (x, y, s) => ``
const core = ``
const towers = ``
const s = 1 - pad
return ``
}
mkdirSync('public/icons', { recursive: true }); mkdirSync('.kody', { recursive: true })
const main = art({}), maskable = art({ pad: 0.2, round: false })
writeFileSync('.kody/icon.svg', main); writeFileSync('public/icons/favicon.svg', main)
const browser = await chromium.launch({ executablePath: process.env.CHROME_PATH || '/usr/bin/google-chrome' })
async function png(svg, size, out, transparent = true) {
const page = await browser.newPage({ viewport: { width: size, height: size } })
await page.setContent(`${svg}`)
await page.screenshot({ path: out, omitBackground: transparent })
await page.close()
}
await png(main, 512, '.kody/icon.png')
await png(main, 512, 'public/icons/icon-512.png')
await png(main, 192, 'public/icons/icon-192.png')
await png(main, 32, 'public/icons/favicon-32.png')
await png(maskable, 512, 'public/icons/icon-maskable-512.png', false)
// iOS draws its own rounded corners: full-bleed square on the dark background.
await png(art({ round: false, pad: 0.06 }), 180, 'public/icons/apple-touch-icon.png', false)
await browser.close()
console.log('icons ok')