import fs from 'fs'; import { geoMercator, geoPath } from 'd3-geo'; import { feature } from 'topojson-client'; import { chromium } from 'playwright-core'; const D = process.cwd(); const topo = JSON.parse(fs.readFileSync(D + '/node_modules/world-atlas/countries-50m.json')); const countries = feature(topo, topo.objects.countries).features; const b64 = f => fs.readFileSync(D + '/' + f).toString('base64'); const font = f => fs.readFileSync(D + '/node_modules/@fontsource/' + f).toString('base64'); const HISP = new Set([724, 620, 484, 320, 340, 222, 558, 188, 591, 192, 214, 630, 170, 862, 218, 604, 68, 152, 32, 858, 600, 76, 226].map(String).map(s => s.padStart(3, '0'))); const PHI = '608'; // main map: Americas const W = 1080; const proj = geoMercator().fitExtent([[80, 470], [640, 975]], { type: 'MultiPoint', coordinates: [[-117, 32.5], [-60, 23], [-74, -55.5], [-34.8, -10]] }); const path = geoPath(proj); const iproj = geoMercator().fitExtent([[760, 455], [990, 645]], { type: 'MultiPoint', coordinates: [[-9.5, 36], [4.3, 43.8]] }); const ipath = geoPath(iproj); const IBE = new Set(['724', '620']); let canar = ''; const cproj = geoMercator().scale(iproj.scale()).center([-15.6, 28.3]).translate([742, 668]); let hisp = '', iber = ''; for (const c of countries) { if (c.id === PHI) continue; if (IBE.has(c.id)) { if (c.id === '724') { const polys = c.geometry.coordinates; const main = polys.filter(p => p[0].every(([x]) => x > -12)); const can = polys.filter(p => p[0].some(([x]) => x <= -12) && p[0].every(([, y]) => y > 26.5)); iber += ipath({ type: 'MultiPolygon', coordinates: main }); canar = geoPath(cproj)({ type: 'MultiPolygon', coordinates: can }); } else iber += ipath(c); continue; } if (!HISP.has(c.id)) continue; const d = path(c); if (!d) continue; const [[x0, y0], [x1, y1]] = path.bounds(c); if (x1 < 0 || x0 > W || y1 < 0 || y0 > W) continue; hisp += d; } hisp += iber + canar; const phi = countries.find(c => c.id === PHI); const pproj = geoMercator().fitExtent([[905, 700], [1000, 880]], phi); const phiPath = geoPath(pproj)(phi); const P = iproj([-6.9, 37.2]), G = cproj([-17.2, 28.1]), S = proj([-74.5, 24.1]); const route = `M${P[0]},${P[1]} Q${(P[0] + G[0]) / 2 + 10},${(P[1] + G[1]) / 2 + 5} ${G[0]},${G[1]} Q${(G[0] + S[0]) / 2},${Math.min(G[1], S[1]) - 70} ${S[0]},${S[1]}`; const mid = [(G[0] + S[0]) / 2 + 10, (G[1] + S[1]) / 2 - 50]; // sun centre in mid-Atlantic const sun = [645, 650]; let rays = ''; for (let i = 0; i < 36; i++) { const a = i * Math.PI * 2 / 36, r0 = 70, r1 = i % 2 ? 190 : 270; rays += ``; } // ragged Cross of Burgundy (background, faint) 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); const caravel = ` `; const html = ` ${rays} 1492 ${caravel} N.ª S.ª del Pilar PARTIDO NACIONAL HISPANISTA — 12 DE OCTUBRE — HISPANIDAD Unidad, Fe y Destino ¡ARRIBA LA HISPANIDAD! · 2026 `; fs.writeFileSync(D + '/poster.html', html); const browser = await chromium.launch({ executablePath: '/opt/pw-browsers/chromium' + (fs.existsSync('/opt/pw-browsers/chromium') && fs.statSync('/opt/pw-browsers/chromium').isDirectory() ? '/chrome' : '') }); const pg = await browser.newPage({ viewport: { width: 1080, height: 1080 }, deviceScaleFactor: 2 }); await pg.setContent(html); await pg.evaluate(() => document.fonts.ready); await pg.waitForTimeout(300); await pg.screenshot({ path: D + '/out.png', clip: { x: 0, y: 0, width: 1080, height: 1080 } }); await browser.close(); console.log('ok', P, G, S, sun);