pnh-rrss/kit/referencia/votoenblanco_carrusel.mjs

166 lines
12 KiB
JavaScript

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');
const OUT = process.argv[2] || D + '/carrusel';
fs.mkdirSync(OUT, { recursive: true });
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 horse = b64('horse.png'), logo = b64('logo_full_hd.png');
const TOTAL = 6;
const css = `
@font-face{font-family:Cinzel;font-weight:700;src:url(data:font/woff2;base64,${font('cinzel/files/cinzel-latin-700-normal.woff2')})}
@font-face{font-family:Cinzel;font-weight:900;src:url(data:font/woff2;base64,${font('cinzel/files/cinzel-latin-900-normal.woff2')})}
@font-face{font-family:Garamond;font-weight:500;src:url(data:font/woff2;base64,${font('eb-garamond/files/eb-garamond-latin-500-normal.woff2')})}
@font-face{font-family:Garamond;font-weight:600;src:url(data:font/woff2;base64,${font('eb-garamond/files/eb-garamond-latin-600-normal.woff2')})}
@font-face{font-family:Garamond;font-style:italic;font-weight:500;src:url(data:font/woff2;base64,${font('eb-garamond/files/eb-garamond-latin-500-italic.woff2')})}
html,body{margin:0;background:#2a0508}
.s{position:relative;width:1080px;height:1080px;overflow:hidden;color:#FBF3E4}
.s>svg{position:absolute;inset:0}
.txt{position:absolute;left:96px;right:96px;top:215px;bottom:150px;display:flex;flex-direction:column;justify-content:center;gap:34px}
.kick{font-family:Cinzel;font-weight:700;font-size:24px;letter-spacing:6px;color:#D9A63A}
h1{margin:0;font-family:Cinzel;font-weight:900;font-size:68px;line-height:1.05;color:#F2C64B;text-wrap:balance}
p{margin:0;font-family:Garamond;font-weight:500;font-size:37px;line-height:1.32;color:#FBF3E4}
p b{font-weight:600;color:#F2C64B}
.rows{display:flex;flex-direction:column;gap:22px}
.row{display:grid;grid-template-columns:270px 1fr;gap:28px;align-items:baseline;border-top:1.5px solid rgba(217,166,58,.55);padding-top:20px}
.row .k{font-family:Cinzel;font-weight:900;font-size:34px;color:#F2C64B;letter-spacing:1px}
.row .v{font-family:Garamond;font-weight:500;font-size:33px;line-height:1.28}
.row.hl .k{color:#FBF3E4;background:#A10F2B;padding:2px 12px;justify-self:start;white-space:nowrap;font-size:30px}
.quote{font-family:Garamond;font-style:italic;font-size:44px;line-height:1.25;color:#F2C64B;border-left:4px solid #D9A63A;padding-left:28px}
`;
function frame(n) {
return `<svg width="1080" height="1080" viewBox="0 0 1080 1080" xmlns="http://www.w3.org/2000/svg">
<defs>
<radialGradient id="bg" cx="50%" cy="55%" r="75%"><stop offset="0" stop-color="#6a0a14"/><stop offset=".55" stop-color="#4B0000"/><stop offset="1" stop-color="#220306"/></radialGradient>
<linearGradient id="gold" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#FFE9A6"/><stop offset=".45" stop-color="#F2C64B"/><stop offset="1" stop-color="#C9962C"/></linearGradient>
<clipPath id="inner"><rect x="44" y="44" width="992" height="992"/></clipPath>
</defs>
<rect width="1080" height="1080" fill="url(#bg)"/>
<g clip-path="url(#inner)"><path d="${cross}" fill="#A10F2B" opacity="${n === 1 ? .22 : .13}"/></g>
<rect x="26" y="26" width="1028" height="1028" fill="none" stroke="#D9A63A" stroke-width="4"/>
<rect x="38" y="38" width="1004" height="1004" fill="none" stroke="#D9A63A" stroke-width="1.5"/>
<g font-family="Cinzel" font-weight="700" font-size="27" fill="url(#gold)" letter-spacing="3">
<text x="460" y="104" text-anchor="end">PARTIDO NACIONAL</text>
<text x="620" y="104" text-anchor="start">HISPANISTA</text>
</g>
<image href="data:image/png;base64,${horse}" x="483" y="62" width="114" height="72"/>
<line x1="90" y1="148" x2="990" y2="148" stroke="#D9A63A" stroke-width="1.5"/>
<line x1="90" y1="154" x2="990" y2="154" stroke="#D9A63A" stroke-width="1"/>
<line x1="90" y1="968" x2="990" y2="968" stroke="#D9A63A" stroke-width="1"/>
<text x="96" y="1008" font-family="Cinzel" font-weight="700" font-size="20" fill="#D9A63A" letter-spacing="4">29N · VOTO EN BLANCO</text>
<text x="984" y="1008" text-anchor="end" font-family="Cinzel" font-weight="700" font-size="20" fill="#D9A63A" letter-spacing="3">${n} / ${TOTAL}${n < TOTAL ? ' →' : ''}</text>
</svg>`;
}
// ballot box + blank envelope illustration for the cover
const urna = `<svg width="1080" height="1080" viewBox="0 0 1080 1080" xmlns="http://www.w3.org/2000/svg" style="position:absolute;inset:0">
<defs>
<linearGradient id="glass" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#fff" stop-opacity=".16"/><stop offset="1" stop-color="#fff" stop-opacity=".04"/></linearGradient>
<linearGradient id="env" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#FFFDF7"/><stop offset="1" stop-color="#EFE6D3"/></linearGradient>
<radialGradient id="halo"><stop offset="0" stop-color="#F2C64B" stop-opacity=".45"/><stop offset="1" stop-color="#F2C64B" stop-opacity="0"/></radialGradient>
<filter id="sh" x="-30%" y="-30%" width="160%" height="160%"><feDropShadow dx="0" dy="8" stdDeviation="10" flood-color="#000" flood-opacity=".5"/></filter>
</defs>
<g transform="translate(540,0) scale(0.9) translate(-540,0) translate(0,90)">
<circle cx="540" cy="640" r="300" fill="url(#halo)"/>
<g stroke="#F2C64B" stroke-width="2" opacity=".28">
${Array.from({ length: 28 }, (_, i) => { const a = i * Math.PI * 2 / 28, r0 = 210, r1 = i % 2 ? 300 : 360; return `<line x1="${540 + r0 * Math.cos(a)}" y1="${640 + r0 * Math.sin(a)}" x2="${540 + r1 * Math.cos(a)}" y2="${640 + r1 * Math.sin(a)}"/>`; }).join('')}
</g>
<!-- envelope entering slot -->
<g filter="url(#sh)" transform="rotate(-4 540 560)">
<rect x="440" y="455" width="200" height="140" rx="4" fill="url(#env)"/>
<path d="M440,459 L540,530 L640,459" fill="none" stroke="#C9B48A" stroke-width="3"/>
</g>
<!-- urn: top face -->
<path d="M330,600 L750,600 L810,650 L270,650 Z" fill="#FBF3E4" fill-opacity=".10" stroke="#F2C64B" stroke-width="4" stroke-linejoin="round"/>
<rect x="455" y="614" width="170" height="14" rx="7" fill="#220306" stroke="#F2C64B" stroke-width="3"/>
<!-- front -->
<rect x="270" y="650" width="540" height="270" fill="url(#glass)" stroke="#F2C64B" stroke-width="4"/>
<line x1="270" y1="690" x2="810" y2="690" stroke="#F2C64B" stroke-width="2" opacity=".7"/>
<!-- envelopes resting inside -->
<g opacity=".55">
<rect x="310" y="850" width="150" height="62" fill="#FBF3E4" transform="rotate(-6 385 881)"/>
<rect x="470" y="862" width="150" height="52" fill="#FBF3E4" transform="rotate(4 545 888)"/>
<rect x="620" y="846" width="150" height="66" fill="#FBF3E4" transform="rotate(-3 695 879)"/>
</g>
<path d="M300,700 L330,700 L300,900 Z" fill="#fff" opacity=".07"/>
</g>
</svg>`;
const slides = [
// 1 portada
`${frame(1)}${urna}
<div style="position:absolute;left:0;right:0;top:182px;text-align:center">
<div style="font-family:Cinzel;font-weight:700;font-size:30px;letter-spacing:10px;color:#D9A63A">ELECCIONES GENERALES · 29N</div>
<div style="font-family:Cinzel;font-weight:900;font-size:118px;line-height:1.02;color:#FBF3E4;margin-top:22px;text-shadow:0 4px 12px rgba(0,0,0,.5)">VOTO EN<br>BLANCO</div>
</div>
<div style="position:absolute;left:0;right:0;top:722px;text-align:center;font-family:Garamond;font-style:italic;font-size:42px;line-height:1.2;color:#F2C64B;text-shadow:0 2px 10px rgba(0,0,0,.6)">Ninguno nos representa.<br>Todavía.</div>`,
// 2
`${frame(2)}<div class="txt">
<div class="kick">LA POSTURA DEL PNH</div>
<h1>¿Por qué no pedimos el voto para nadie?</h1>
<p>Ningún partido de los que se presentan el 29N defiende la <b>Hispanidad</b> como proyecto. Ninguno pone en el centro la <b>unidad de nuestros pueblos</b>, la <b>fe</b> que los formó y un <b>destino común</b> para España y América.</p>
<p>No vamos a elegir el mal menor. Vamos a decirlo con claridad en las urnas.</p>
</div>`,
// 3
`${frame(3)}<div class="txt">
<div class="kick">CÓMO SE VOTA EN BLANCO</div>
<h1>Blanco no es nulo.<br>Nulo no es blanco.</h1>
<div class="rows">
<div class="row hl"><div class="k">EN BLANCO</div><div class="v"><b style="color:#F2C64B">Congreso:</b> sobre vacío, sin papeleta. <b style="color:#F2C64B">Senado:</b> papeleta sin ninguna cruz. Es un voto válido y sale en los resultados oficiales.</div></div>
<div class="row"><div class="k">NULO</div><div class="v">Papeleta tachada, rota, con dibujos o dos papeletas distintas. No cuenta como voto válido.</div></div>
<div class="row"><div class="k">ABSTENCIÓN</div><div class="v">Quedarse en casa. No cuenta para nada.</div></div>
</div>
</div>`,
// 4
`${frame(4)}<div class="txt">
<div class="kick">¿Y POR QUÉ NO QUEDARSE EN CASA?</div>
<h1>Quien se abstiene, calla. Quien vota en blanco, habla.</h1>
<p>La abstención se lee como desinterés. Se mezcla con quien olvidó votar, con quien estaba de viaje y con quien no le importa nada.</p>
<div class="quote">El voto en blanco dice otra cosa: he venido, creo en mi Patria y ninguno de vosotros la merece.</div>
</div>`,
// 5
`${frame(5)}<div class="txt">
<div class="kick">HASTA QUE PODAMOS PRESENTARNOS</div>
<h1>La próxima vez, el PNH estará en la papeleta.</h1>
<p>El Partido Nacional Hispanista está en formación. Todavía no podemos concurrir a estas elecciones, pero estamos construyendo la alternativa.</p>
<p>Hasta entonces, <b>en blanco</b>. Y después, <b>con nosotros</b>.</p>
</div>`,
// 6 cierre
`${frame(6)}
<div style="position:absolute;left:0;right:0;top:200px;text-align:center">
<div style="font-family:Cinzel;font-weight:700;font-size:30px;letter-spacing:10px;color:#D9A63A">DOMINGO 29 DE NOVIEMBRE</div>
<div style="font-family:Cinzel;font-weight:900;font-size:104px;line-height:1.02;color:#FBF3E4;margin-top:20px;text-shadow:0 4px 12px rgba(0,0,0,.5)">VOTA EN<br>BLANCO</div>
</div>
<img src="data:image/png;base64,${logo}" style="position:absolute;left:355px;top:500px;width:370px;filter:drop-shadow(0 6px 10px rgba(0,0,0,.55))">
<div style="position:absolute;left:0;right:0;top:785px;text-align:center;font-family:Garamond;font-style:italic;font-size:40px;color:#F2C64B">Unidad, Fe y Destino</div>
<div style="position:absolute;left:0;right:0;top:860px;text-align:center;font-family:Cinzel;font-weight:700;font-size:30px;letter-spacing:5px;color:#FBF3E4">¡ARRIBA LA HISPANIDAD!</div>`,
];
const browser = await chromium.launch({ executablePath: '/opt/pw-browsers/chromium' });
const pg = await browser.newPage({ viewport: { width: 1080, height: 1080 }, deviceScaleFactor: 1 });
for (let i = 0; i < slides.length; i++) {
await pg.setContent(`<!doctype html><html><head><meta charset="utf-8"><style>${css}</style></head><body><div class="s">${slides[i]}</div></body></html>`);
await pg.evaluate(() => document.fonts.ready); await pg.waitForTimeout(150);
await pg.screenshot({ path: `${OUT}/votoenblanco_${i + 1}.png`, clip: { x: 0, y: 0, width: 1080, height: 1080 } });
}
await browser.close();
console.log('ok');