feat(pdf): large text switch in the trip PDF preview (#2817)

A third switch next to the page break and transport notes switches scales the
day content's type by 1.35 and darkens its greys, for readers who print the
plan. Off by default and remembered per browser like the other two; the day
content's sizes and greys now come from three CSS variables on <body>.
This commit is contained in:
Maurice
2026-11-13 09:17:00 +01:00
parent 12ae32b69e
commit 12406bbbf4
37 changed files with 204 additions and 43 deletions
+24 -5
View File
@@ -18,6 +18,13 @@ export const PAGE_BREAK_KEY = 'trek_pdf_page_break_per_day';
*/
export const TRANSPORT_NOTES_KEY = 'trek_pdf_transport_notes';
/**
* Larger type and darker greys for a reader who prints the plan and finds the
* small grey text hard to read (#2817). Off by default, so the document keeps
* its compact look unless someone asks for more.
*/
export const LARGE_TEXT_KEY = 'trek_pdf_large_text';
/* The overlay is imperative DOM, so the switch from Settings/ToggleSwitch is
rebuilt here rather than rendered — as static markup it would carry no
behaviour. Same geometry and the same tokens, so it reads as the same control. */
@@ -44,6 +51,7 @@ export interface PdfPreviewOptions {
showTransportNotes: boolean;
/** The transport-notes switch only shows when there is a note to hide. */
hasTransportNotes: boolean;
largeText: boolean;
}
/**
@@ -75,6 +83,7 @@ export function openPdfPreview({
breaksPerDay,
showTransportNotes,
hasTransportNotes,
largeText,
}: PdfPreviewOptions): void {
// Open in modal with srcdoc iframe (no URL loading = no X-Frame-Options issue)
const overlay = document.createElement('div');
@@ -95,9 +104,10 @@ export function openPdfPreview({
'display:flex;align-items:center;justify-content:space-between;gap:8px;flex-wrap:wrap;padding:10px 16px;border-bottom:1px solid var(--border-primary);flex-shrink:0;';
header.innerHTML = `
<span style="font-size:13px;font-weight:600;color:var(--text-primary);min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">${escapeHtml(title)}</span>
<div style="display:flex;align-items:center;gap:8px">
<div style="display:flex;align-items:center;justify-content:flex-end;flex-wrap:wrap;gap:8px">
${hasTransportNotes ? previewSwitch('pdf-transport-notes-toggle', tr('pdf.transportNotes'), showTransportNotes) : ''}
${previewSwitch('pdf-daybreak-toggle', tr('pdf.pageBreakPerDay'), breaksPerDay)}
${previewSwitch('pdf-large-text-toggle', tr('pdf.largeText'), largeText)}
${save.html}
<button type="button" id="pdf-close-btn" style="background:none;border:none;cursor:pointer;color:var(--text-faint);display:flex;padding:4px;border-radius:6px">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
@@ -133,7 +143,7 @@ export function openPdfPreview({
iframe.contentWindow?.print();
};
// Both choices differ by one class on <body>, so switching is instant in the
// Each choice differs by one class on <body>, so switching is instant in the
// preview and there is no need to re-fetch photos or rebuild the document.
wirePreviewSwitch(header, 'pdf-daybreak-toggle', (on) => {
rememberPdfSwitch(PAGE_BREAK_KEY, on);
@@ -143,14 +153,23 @@ export function openPdfPreview({
rememberPdfSwitch(TRANSPORT_NOTES_KEY, on);
iframe.contentDocument?.body.classList.toggle('pdf-no-transport-notes', !on);
});
wirePreviewSwitch(header, 'pdf-large-text-toggle', (on) => {
rememberPdfSwitch(LARGE_TEXT_KEY, on);
iframe.contentDocument?.body.classList.toggle('pdf-large-text', on);
});
}
/** A labelled switch for the preview header, as markup; wirePreviewSwitch gives it behaviour. */
/**
* A labelled switch for the preview header, as markup; wirePreviewSwitch gives it behaviour.
* Label and switch are one unit, so a narrow header wraps between switches, never inside one.
*/
function previewSwitch(id: string, label: string, on: boolean): string {
return `<label for="${id}" style="font-size:12px;color:var(--text-muted);cursor:pointer;user-select:none">${escapeHtml(label)}</label>
return `<span style="display:inline-flex;align-items:center;gap:8px;white-space:nowrap">
<label for="${id}" style="font-size:12px;color:var(--text-muted);cursor:pointer;user-select:none">${escapeHtml(label)}</label>
<button id="${id}" type="button" role="switch" aria-checked="${on}" aria-label="${escapeHtml(label)}" style="${TOGGLE_TRACK} background:${trackColour(on)}">
<span style="${TOGGLE_KNOB} inset-inline-start:${knobOffset(on)}"></span>
</button>`;
</button>
</span>`;
}
function wirePreviewSwitch(header: HTMLElement, id: string, onChange: (on: boolean) => void): void {