import fs from 'fs';
import { chromium } from 'playwright-core';
const D = process.cwd();
const b64 = f => fs.readFileSync(D + '/' + f).toString('base64');
const font = f => fs.readFileSync(D + '/node_modules/@fontsource/' + f).toString('base64');
function raggedBar(x0, y0, x1, y1, w) {
const dx = x1 - x0, dy = y1 - y0, L = Math.hypot(dx, dy), ux = dx / L, uy = dy / L, nx = -uy, ny = ux;
const pts = [], n = 9;
for (let s = 0; s <= 1; s++) {
const side = s ? -1 : 1, seq = [];
for (let k = 0; k <= n; k++) {
const t = k / n * L, knot = (k > 0 && k < n && k % 2 === 1) ? 26 : 0;
seq.push([x0 + ux * t + nx * side * (w / 2 + knot), y0 + uy * t + ny * side * (w / 2 + knot)]);
if (knot) seq.push([x0 + ux * (t + 18) + nx * side * w / 2, y0 + uy * (t + 18) + ny * side * w / 2]);
}
pts.push(...(s ? seq.reverse() : seq));
}
return 'M' + pts.map(p => p.map(v => v.toFixed(1)).join(',')).join('L') + 'Z';
}
const cross = raggedBar(-60, -60, 1140, 1140, 110) + raggedBar(1140, -60, -60, 1140, 110);
// anchor + laurel, centred at (cx, cy)
function emblem(cx, cy) {
const g = '#F2C64B';
let leaves = '';
for (const side of [-1, 1]) {
// branch: arc from bottom centre outwards and up
const pts = [];
for (let i = 0; i <= 10; i++) {
const t = i / 10, a = Math.PI * (0.62 + 0.62 * t);
pts.push([cx + side * -Math.cos(a) * 92 * -1, cy + 18 - Math.sin(a) * 82]);
}
leaves += `