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 += ``; for (let i = 1; i < 10; i++) { const [x, y] = pts[i], [x2, y2] = pts[i + 1]; const ang = Math.atan2(y2 - y, x2 - x) * 180 / Math.PI; leaves += ``; leaves += ``; } } const anchor = ` `; return `${leaves}${anchor}`; } const ships = ['SANTÍSIMA TRINIDAD', 'PRÍNCIPE DE ASTURIAS', 'SANTA ANA', 'RAYO', 'NEPTUNO', 'ARGONAUTA', 'SAN ILDEFONSO', 'BAHAMA', 'SAN JUAN NEPOMUCENO', 'SAN AGUSTÍN', 'MONARCA', 'MONTAÑÉS', 'SAN FRANCISCO DE ASÍS', 'SAN JUSTO', 'SAN LEANDRO']; const svg = ` ${emblem(540, 470)} ${[[124, 564], [956, 564], [124, 936], [956, 936]].map(([x, y]) => ``).join('')} PARTIDO NACIONAL HISPANISTA — 21 DE OCTUBRE DE 1805 — TRAFALGAR A los marinos de España GRAVINA · CHURRUCA · ALCALÁ GALIANO `; const html = `
${svg}
NAVÍOS DE LA REAL ARMADA
✦ ✦ ✦
${ships.map((n, i) => `${n}
`).join('')}
`; const browser = await chromium.launch({ executablePath: '/opt/pw-browsers/chromium' }); const pg = await browser.newPage({ viewport: { width: 1080, height: 1080 } }); await pg.setContent(html); await pg.evaluate(() => document.fonts.ready); await pg.waitForTimeout(200); await pg.screenshot({ path: D + '/lapida.png', clip: { x: 0, y: 0, width: 1080, height: 1080 } }); await browser.close(); console.log('ok');