Tudo: Primeiro commit
This commit is contained in:
commit
06a90928dc
4633 files changed
+6327263
No files matched your search
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env node
|
||||
/*
|
||||
* Gera build/robo-movel.pdf a partir de build/index.html.
|
||||
*
|
||||
* - Sobe um servidor estático local (porta efêmera) para servir o build.
|
||||
* - Usa o @media print de styles.css: cada .slide ocupa uma página 1920x1080.
|
||||
* - Injeta CSS para deixar reveals no estado final e esconder botões/progresso.
|
||||
* - page.pdf() mantém o texto selecionável (diferente de juntar PNGs).
|
||||
*
|
||||
* Uso: node scripts/build-pdf.cjs
|
||||
*/
|
||||
const http = require("http");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { chromium } = require("/home/marcel/.npm/_npx/e41f203b7505f1fb/node_modules/playwright");
|
||||
|
||||
const BUILD = path.resolve(__dirname, "..", "build");
|
||||
const OUT = path.join(BUILD, "robo-movel.pdf");
|
||||
|
||||
const MIME = {
|
||||
".html": "text/html; charset=utf-8",
|
||||
".css": "text/css; charset=utf-8",
|
||||
".js": "text/javascript; charset=utf-8",
|
||||
".png": "image/png",
|
||||
".jpg": "image/jpeg",
|
||||
".jpeg": "image/jpeg",
|
||||
".svg": "image/svg+xml",
|
||||
".woff2": "font/woff2",
|
||||
};
|
||||
|
||||
// Estado final das animações + oculta chrome de navegação/edição no PDF.
|
||||
const PRINT_STATE_CSS = `
|
||||
.reveal, .reveal-scale {
|
||||
opacity: 1 !important;
|
||||
transform: none !important;
|
||||
transition: none !important;
|
||||
animation: none !important;
|
||||
}
|
||||
.edit-toggle, .edit-hotzone, .progress, .deck-controls { display: none !important; }
|
||||
`;
|
||||
|
||||
function startServer() {
|
||||
const server = http.createServer((req, res) => {
|
||||
const urlPath = decodeURIComponent(req.url.split("?")[0]);
|
||||
let filePath = path.join(BUILD, urlPath === "/" ? "index.html" : urlPath);
|
||||
if (!filePath.startsWith(BUILD)) {
|
||||
res.writeHead(403).end();
|
||||
return;
|
||||
}
|
||||
fs.readFile(filePath, (err, data) => {
|
||||
if (err) {
|
||||
res.writeHead(404).end("not found");
|
||||
return;
|
||||
}
|
||||
res.writeHead(200, { "Content-Type": MIME[path.extname(filePath)] || "application/octet-stream" });
|
||||
res.end(data);
|
||||
});
|
||||
});
|
||||
return new Promise((resolve) => server.listen(0, "127.0.0.1", () => resolve(server)));
|
||||
}
|
||||
|
||||
(async () => {
|
||||
if (!fs.existsSync(path.join(BUILD, "index.html"))) {
|
||||
console.error("build/index.html não encontrado. Rode `make` primeiro.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const server = await startServer();
|
||||
const port = server.address().port;
|
||||
const url = `http://127.0.0.1:${port}/index.html`;
|
||||
|
||||
const browser = await chromium.launch({ headless: true });
|
||||
const page = await browser.newPage({ viewport: { width: 1920, height: 1080 } });
|
||||
page.on("pageerror", (e) => console.log("PAGE EXCEPTION:", e.message));
|
||||
|
||||
await page.goto(url, { waitUntil: "networkidle" });
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
await page.addStyleTag({ content: PRINT_STATE_CSS });
|
||||
await page.waitForTimeout(300);
|
||||
|
||||
const total = await page.evaluate(() => document.querySelectorAll(".slide").length);
|
||||
|
||||
await page.emulateMedia({ media: "print" });
|
||||
await page.pdf({
|
||||
path: OUT,
|
||||
width: "1920px",
|
||||
height: "1080px",
|
||||
margin: { top: "0", right: "0", bottom: "0", left: "0" },
|
||||
printBackground: true,
|
||||
preferCSSPageSize: false,
|
||||
});
|
||||
|
||||
await browser.close();
|
||||
server.close();
|
||||
|
||||
const size = fs.statSync(OUT).size;
|
||||
console.log(`build/robo-movel.pdf gerado (${total} slides, ${(size / 1024).toFixed(0)} KB)`);
|
||||
})();
|
||||
Reference in new issue
Block a user