Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
27 lines
1.3 KiB
JavaScript
27 lines
1.3 KiB
JavaScript
// Renders the PWA icons with node-canvas (borrowed from ../../calorie-counter/node_modules).
|
|
import { createRequire } from 'node:module'
|
|
import { writeFileSync } from 'node:fs'
|
|
const require = createRequire(import.meta.url)
|
|
const { createCanvas } = require('/home/core/projects/calorie-counter/node_modules/canvas')
|
|
|
|
function draw(size, { pad = 0, radius = 0 }) {
|
|
const c = createCanvas(size, size), g = c.getContext('2d')
|
|
g.fillStyle = '#111418'
|
|
if (radius) { g.beginPath(); g.roundRect(0, 0, size, size, radius); g.fill() } else g.fillRect(0, 0, size, size)
|
|
const inner = size - pad * 2
|
|
g.fillStyle = '#e3a33b'
|
|
g.font = `bold ${inner * 0.62}px "DejaVu Serif", serif`
|
|
g.textAlign = 'center'; g.textBaseline = 'middle'
|
|
g.fillText('H', size / 2, size / 2 + inner * 0.03)
|
|
// prompt caret
|
|
g.fillStyle = '#58a6ff'
|
|
g.font = `bold ${inner * 0.22}px "DejaVu Sans Mono", monospace`
|
|
g.fillText('>_', size / 2 + inner * 0.27, size / 2 + inner * 0.27)
|
|
return c.toBuffer('image/png')
|
|
}
|
|
writeFileSync('public/icons/icon-192.png', draw(192, {}))
|
|
writeFileSync('public/icons/icon-512.png', draw(512, {}))
|
|
writeFileSync('public/icons/icon-512-maskable.png', draw(512, { pad: 80 }))
|
|
writeFileSync('public/icons/apple-touch-icon.png', draw(180, {}))
|
|
console.log('icons written')
|