feat(print): styled PDF export and printouts with branded header, real tables and podium marks (1.72.0)

This commit is contained in:
larssand committed 2026-11-06 22:52:02 +01:00
1 parent c4375daa93
commit 7c25f23ad0
8 files changed
+504 -372

No files matched your search

+59 -15
View File
@@ -7415,7 +7415,37 @@ function clearGeneratedFinals(eventId) {
});
}
// Same colours as the PDF themes (server/pdf_render.js).
const PRINT_THEMES = {
classic: { band: "#14213d", bandText: "#ffffff", bandMuted: "#c9d0dc", kicker: "#8fb4ff", accent: "#2f6fde", headFill: "#14213d", headText: "#ffffff", zebra: "#f2f5fa" },
motorsport: { band: "#111111", bandText: "#ffffff", bandMuted: "#c9c9c9", kicker: "#ff6b74", accent: "#d61f2c", headFill: "#1c1c1c", headText: "#ffffff", zebra: "#f5f2f2" },
minimal: { band: "#ffffff", bandText: "#1d2330", bandMuted: "#6b7486", kicker: "#3c4454", accent: "#3c4454", headFill: "#e9ecf1", headText: "#1d2330", zebra: "#f7f8fa" },
};
// Podium marks for result tables (first column Pos/Plac) and right-aligned number columns.
function decoratePrintTables(doc) {
const numeric = /^[-+()0-9.:,\s%/]+$/;
doc.querySelectorAll("table").forEach((table) => {
const headers = [...table.querySelectorAll("thead th")];
const rows = [...table.querySelectorAll("tbody tr")].filter((row) => !row.querySelector("td[colspan]"));
headers.forEach((th, index) => {
const values = rows.map((row) => row.children[index]?.textContent.trim() || "").filter((value) => value && value !== "-");
if (!values.length || !values.every((value) => numeric.test(value))) return;
const cls = index === 0 ? "pos" : "num";
th.classList.add(cls);
rows.forEach((row) => row.children[index]?.classList.add(cls));
});
if (/^(pos|plac|placering|place|#)\.?$/i.test(headers[0]?.textContent.trim() || "")) {
rows.forEach((row) => {
const pos = row.children[0]?.textContent.trim();
if (["1", "2", "3"].includes(pos)) row.classList.add(`podium-${pos}`);
});
}
});
}
function openPrintWindow(title, bodyHtml) {
const theme = PRINT_THEMES[state.settings.pdfTheme] || PRINT_THEMES.classic;
// noopener/noreferrer force window.open() to return null even when the window opens
// successfully (WHATWG spec, all modern browsers), which made the blocked-popup check
// below always fire and this always exit before writing any content. The opened window
@@ -7433,23 +7463,36 @@ function openPrintWindow(title, bodyHtml) {
<meta charset="utf-8" />
<title>${escapeHtml(title)}</title>
<style>
@page { size: A4 portrait; margin: 14mm; }
body { font-family: Arial, sans-serif; padding: 0; color: #10131a; }
h1, h2, h3 { margin: 0 0 12px; }
h1 { font-size: 28px; }
h2 { font-size: 18px; border-bottom: 2px solid #10131a; padding-bottom: 4px; }
p { margin: 0 0 12px; color: #44506b; }
.print-header { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; padding-bottom: 16px; border-bottom: 4px solid #10131a; }
.print-kicker { text-transform: uppercase; letter-spacing: 0.08em; color: #5b677f; font-size: 12px; }
.print-meta { text-align: right; font-size: 13px; }
@page { size: A4 portrait; margin: 12mm 12mm 16mm; @bottom-left { content: "${escapeHtml(String(title).replace(/["\\]/g, ""))}"; font: 9px Arial, sans-serif; color: #6b7486; } @bottom-right { content: counter(page) " / " counter(pages); font: bold 9px Arial, sans-serif; color: ${theme.accent}; } }
* { -webkit-print-color-adjust: exact; print-color-adjust: exact; box-sizing: border-box; }
body { font-family: "Helvetica Neue", Arial, sans-serif; margin: 0; padding: 0; color: #1d2330; font-size: 12px; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h1 { font-size: 26px; }
h2 { font-size: 16px; margin-top: 4px; padding-left: 10px; border-left: 4px solid ${theme.accent}; }
h3 { font-size: 13px; color: #1d2330; }
p { margin: 0 0 8px; color: #6b7486; }
.print-header { display: flex; justify-content: space-between; gap: 24px; align-items: center; margin: 0 0 20px; padding: 18px 20px; border-radius: 6px; background: ${theme.band}; color: ${theme.bandText}; border-bottom: 4px solid ${theme.accent}; }
.print-header h1 { color: ${theme.bandText}; margin: 2px 0 4px; }
.print-header p { color: ${theme.bandMuted}; margin: 0; }
.print-header .print-kicker { color: ${theme.kicker}; }
.print-kicker { text-transform: uppercase; letter-spacing: 0.1em; font-size: 11px; font-weight: 700; color: ${theme.accent}; }
.print-meta { text-align: right; font-size: 12px; }
.print-brand-block { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.print-brand-block strong { font-size: 15px; }
.print-brand-block p { margin: 0; }
.print-logo { max-width: 92px; max-height: 52px; object-fit: contain; }
.print-block { margin-top: 24px; break-inside: avoid; }
table { width: 100%; border-collapse: collapse; margin-top: 12px; }
th, td { border: 1px solid #b9c2d4; padding: 8px; text-align: left; }
th { background: #eef2f8; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
tbody tr:nth-child(even) { background: #f8faff; }
.print-logo { max-width: 92px; max-height: 52px; object-fit: contain; background: #fff; border-radius: 4px; padding: 3px; }
.print-block { margin-top: 22px; break-inside: avoid; }
table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 11.5px; }
thead { display: table-header-group; }
tr { break-inside: avoid; }
th, td { padding: 6px 8px; text-align: left; border: 0; border-bottom: 1px solid #e1e5ec; }
th { background: ${theme.headFill}; color: ${theme.headText}; font-size: 10.5px; font-weight: 700; letter-spacing: 0.03em; }
th:first-child { border-top-left-radius: 4px; } th:last-child { border-top-right-radius: 4px; }
tbody tr:nth-child(even) td { background: ${theme.zebra}; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.pos, th.pos { text-align: center; width: 1%; white-space: nowrap; }
tr.podium-1 td:first-child { box-shadow: inset 4px 0 #d4af37; } tr.podium-2 td:first-child { box-shadow: inset 4px 0 #a9b0bb; } tr.podium-3 td:first-child { box-shadow: inset 4px 0 #c27c3e; }
tr.podium-1 td, tr.podium-2 td, tr.podium-3 td { font-weight: 700; }
</style>
</head>
<body>
@@ -7458,6 +7501,7 @@ function openPrintWindow(title, bodyHtml) {
</html>
`);
printWindow.document.close();
decoratePrintTables(printWindow.document);
printWindow.focus();
setTimeout(() => {
printWindow.print();