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
+1 -1
View File
@@ -72,7 +72,7 @@
"components/Map/ratingBadge.ts": 2,
"components/Map/reservationsMapbox.ts": 1,
"components/Map/switcherRow.ts": 1,
"components/PDF/TripPDF.tsx": 51,
"components/PDF/TripPDF.tsx": 44,
"components/Packing/PackingListPanelBagModal.tsx": 2,
"components/Packing/PackingListPanelCategoryGroup.tsx": 5,
"components/Packing/PackingListPanelHeader.tsx": 5,
+60
View File
@@ -1426,3 +1426,63 @@ describe('downloadTripPDF — transport notes', () => {
localStorage.removeItem('trek_pdf_page_break_per_day')
})
})
// ── Large text (#2817) ──────────────────────────────────────────────────────
describe('downloadTripPDF — large text', () => {
beforeEach(() => {
localStorage.removeItem('trek_pdf_large_text')
})
const largeToggle = () => document.querySelector<HTMLButtonElement>('#pdf-large-text-toggle')
it('FE-PDF-LARGE-001: the document keeps its compact type by default and offers the switch off', async () => {
await downloadTripPDF(richArgs)
const html = getIframe()!.srcdoc
expect(html).not.toContain('pdf-large-text"')
expect(largeToggle()!.getAttribute('aria-checked')).toBe('false')
// One scale and one set of greys, at today's values unless the class is on.
expect(html).toContain('--pdf-text: 1;')
expect(html).toContain('body.pdf-large-text {')
expect(html).toContain('.place-name { font-size: calc(11.5px * var(--pdf-text));')
expect(html).toContain('.note-text { font-size: calc(9.5px * var(--pdf-text)); color: var(--pdf-ink);')
})
it('FE-PDF-LARGE-002: the clock and the booking code of a transport scale with the rest', async () => {
await downloadTripPDF(richArgs)
const html = getIframe()!.srcdoc
expect(html).toContain('<span class="note-clock">')
expect(html).toContain('<div class="note-time note-code">Code: ABC123</div>')
expect(html).not.toContain('font-size:10px;')
})
it('FE-PDF-LARGE-003: turning it on enlarges the open preview at once and is remembered', async () => {
await downloadTripPDF(richArgs)
largeToggle()!.click()
expect(largeToggle()!.getAttribute('aria-checked')).toBe('true')
expect(localStorage.getItem('trek_pdf_large_text')).toBe('1')
const body = getIframe()!.contentDocument?.body
if (body) expect(body.classList.contains('pdf-large-text')).toBe(true)
})
it('FE-PDF-LARGE-004: the remembered choice comes back next to the other switches', async () => {
localStorage.setItem('trek_pdf_large_text', '1')
localStorage.setItem('trek_pdf_page_break_per_day', '0')
await downloadTripPDF(richArgs)
expect(getIframe()!.srcdoc).toContain('<body class="pdf-flow pdf-large-text">')
expect(largeToggle()!.getAttribute('aria-checked')).toBe('true')
localStorage.removeItem('trek_pdf_page_break_per_day')
})
it('FE-PDF-LARGE-005: a blocked storage prints the compact document', async () => {
vi.spyOn(Storage.prototype, 'getItem').mockImplementation(() => { throw new Error('blocked') })
await downloadTripPDF(richArgs)
expect(getIframe()!.srcdoc).not.toContain('pdf-large-text"')
expect(largeToggle()!.getAttribute('aria-checked')).toBe('false')
})
})
+45 -27
View File
@@ -9,7 +9,7 @@ import { isDayInAccommodationRange, getDayOrder } from '../../utils/dayOrder'
import { hidesOnMiddleDay, getTransportForDay, getMergedItems, getSpanPhase, getDisplayTimeForDay } from '../../utils/dayMerge'
import { safeHexColor } from '../../utils/safeColor'
import { pdfSwitchOn } from '../../utils/pdfSwitch'
import { openPdfPreview, PAGE_BREAK_KEY, TRANSPORT_NOTES_KEY } from './pdfPreview'
import { openPdfPreview, LARGE_TEXT_KEY, PAGE_BREAK_KEY, TRANSPORT_NOTES_KEY } from './pdfPreview'
import { renderIconMarkup } from '../../utils/iconMarkup'
import { formatMoney, formatMoneySum, formatClockTime, splitReservationDateTime, type MoneyEntry } from '../../utils/formatters'
import { useSettingsStore } from '../../store/settingsStore'
@@ -192,6 +192,7 @@ export async function downloadTripPDF({ trip, days, places, assignments: allStor
const assignments = planAssignments(stored, showServiceStops)
const breaksPerDay = pdfSwitchOn(PAGE_BREAK_KEY)
const showTransportNotes = pdfSwitchOn(TRANSPORT_NOTES_KEY)
const largeText = pdfSwitchOn(LARGE_TEXT_KEY, false)
// Set while the days render: the switch only shows when there is a note to hide.
let hasTransportNotes = false
const loc = _locale || undefined
@@ -461,10 +462,10 @@ export async function downloadTripPDF({ trip, days, places, assignments: allStor
<div class="note-line" style="background: ${color};"></div>
<span class="note-icon">${icon}</span>
<div class="note-body">
<div class="note-text" style="font-weight: 600;">${titleHtml}${time ? ` <span style="color:#6b7280;font-weight:400;font-size:10px;">${time}</span>` : ''}</div>
<div class="note-text" style="font-weight: 600;">${titleHtml}${time ? ` <span class="note-clock">${time}</span>` : ''}</div>
${subtitleLines.filter(Boolean).map(s => `<div class="note-time">${escHtml(s)}</div>`).join('')}
${locationLine ? `<div class="note-time">${escHtml(locationLine)}</div>` : ''}
${r.confirmation_number ? `<div class="note-time" style="font-size:9px;">Code: ${escHtml(r.confirmation_number)}</div>` : ''}
${r.confirmation_number ? `<div class="note-time note-code">Code: ${escHtml(r.confirmation_number)}</div>` : ''}
${transportNote ? `<div class="note-time transport-note">${escHtml(transportNote)}</div>` : ''}
</div>
</div>`
@@ -619,6 +620,21 @@ export async function downloadTripPDF({ trip, days, places, assignments: allStor
@font-face { font-family: 'Poppins'; font-style: normal; font-weight: 600 700; font-display: swap; src: url('/fonts/Poppins-Bold.ttf') format('truetype'); }
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Poppins', sans-serif; background: #fff; color: #1e293b; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
/* The day content's type scale and its three greys, so the large-text switch in the
preview (#2817) is one class on <body>: bigger type, and greys dark enough to
read on an inkjet. The cover and the map keep their own sizes. */
body {
--pdf-text: 1;
--pdf-ink: #334155;
--pdf-ink-soft: #64748b;
--pdf-ink-faint: #94a3b8;
}
body.pdf-large-text {
--pdf-text: 1.35;
--pdf-ink: #1e293b;
--pdf-ink-soft: #334155;
--pdf-ink-faint: #475569;
}
svg { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
/* Footer on every printed page */
@@ -715,10 +731,10 @@ export async function downloadTripPDF({ trip, days, places, assignments: allStor
background: #0f172a; padding: 11px 28px;
display: flex; align-items: center; gap: 8px;
}
.day-tag { font-size: 8px; font-weight: 700; color: #fff; letter-spacing: 0.8px; background: rgba(255,255,255,0.12); border-radius: 4px; padding: 3px 8px; flex-shrink: 0; }
.day-title { font-size: 13px; font-weight: 600; color: #fff; flex: 1; }
.day-date { font-size: 9px; color: rgba(255,255,255,0.45); }
.day-cost { font-size: 9px; font-weight: 600; color: rgba(255,255,255,0.65); }
.day-tag { font-size: calc(8px * var(--pdf-text)); font-weight: 700; color: #fff; letter-spacing: 0.8px; background: rgba(255,255,255,0.12); border-radius: 4px; padding: 3px 8px; flex-shrink: 0; }
.day-title { font-size: calc(13px * var(--pdf-text)); font-weight: 600; color: #fff; flex: 1; }
.day-date { font-size: calc(9px * var(--pdf-text)); color: rgba(255,255,255,0.45); }
.day-cost { font-size: calc(9px * var(--pdf-text)); font-weight: 600; color: rgba(255,255,255,0.65); }
/* The gap under the header bar must sit inside the repeated <thead> cell: a block-start
padding on .day-body is only painted on the box's first fragment, so overflow pages
would render their first card flush against the bar (#1531). */
@@ -726,7 +742,7 @@ export async function downloadTripPDF({ trip, days, places, assignments: allStor
.day-body { padding: 0 28px 6px; }
/* accommodation info */
.day-accommodations-overview { font-size: 12px; }
.day-accommodations-overview { font-size: calc(12px * var(--pdf-text)); }
.day-accommodations { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; }
.day-accommodations.single { justify-content: center; }
.day-accommodation {
@@ -739,7 +755,7 @@ export async function downloadTripPDF({ trip, days, places, assignments: allStor
break-inside: avoid; page-break-inside: avoid;
}
.day-accommodation-title {
font-size: 16px; font-weight: 600; text-align: center;
font-size: calc(16px * var(--pdf-text)); font-weight: 600; text-align: center;
margin-bottom: 4px; align-self: center;
}
.accommodation-center-icon { display: flex; align-items: center; gap: 4px; }
@@ -766,22 +782,22 @@ export async function downloadTripPDF({ trip, days, places, assignments: allStor
.place-name-row { display: flex; align-items: center; gap: 5px; margin-bottom: 4px; }
.place-num {
width: 16px; height: 16px; border-radius: 50%;
background: #1e293b; color: #fff; font-size: 8px; font-weight: 700;
width: calc(16px * var(--pdf-text)); height: calc(16px * var(--pdf-text)); border-radius: 50%;
background: #1e293b; color: #fff; font-size: calc(8px * var(--pdf-text)); font-weight: 700;
display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.place-name { font-size: 11.5px; font-weight: 600; color: #1e293b; flex: 1; }
.cat-badge { font-size: 7.5px; font-weight: 600; color: #fff; border-radius: 99px; padding: 2px 7px; flex-shrink: 0; white-space: nowrap; }
.place-name { font-size: calc(11.5px * var(--pdf-text)); font-weight: 600; color: #1e293b; flex: 1; }
.cat-badge { font-size: calc(7.5px * var(--pdf-text)); font-weight: 600; color: #fff; border-radius: 99px; padding: 2px 7px; flex-shrink: 0; white-space: nowrap; }
.info-row { display: flex; align-items: flex-start; gap: 4px; margin-bottom: 2px; padding-left: 21px; }
.info-row svg { flex-shrink: 0; margin-top: 1px; }
.info-spacer { width: 13px; flex-shrink: 0; }
.info-text { font-size: 9px; color: #64748b; line-height: 1.5; }
.info-text.muted { color: #94a3b8; }
.info-text { font-size: calc(9px * var(--pdf-text)); color: var(--pdf-ink-soft); line-height: 1.5; }
.info-text.muted { color: var(--pdf-ink-faint); }
${PDF_MARKDOWN_CSS}
.chips { display: flex; flex-wrap: wrap; gap: 4px; padding-left: 21px; margin-top: 4px; }
.chip { display: inline-flex; align-items: center; gap: 3px; font-size: 8px; font-weight: 600; background: #f1f5f9; color: #374151; border-radius: 99px; padding: 2px 7px; white-space: nowrap; }
.chip { display: inline-flex; align-items: center; gap: 3px; font-size: calc(8px * var(--pdf-text)); font-weight: 600; background: #f1f5f9; color: #374151; border-radius: 99px; padding: 2px 7px; white-space: nowrap; }
.chip svg { flex-shrink: 0; }
.chip-green { background: #ecfdf5; color: #059669; }
.chip-amber { background: #fffbeb; color: #d97706; }
@@ -795,19 +811,21 @@ export async function downloadTripPDF({ trip, days, places, assignments: allStor
.note-line { width: 3px; border-radius: 99px; background: #94a3b8; align-self: stretch; flex-shrink: 0; }
.note-icon { flex-shrink: 0; }
.note-body { flex: 1; min-width: 0; }
.note-text { font-size: 9.5px; color: #334155; line-height: 1.55; }
.note-time { font-size: 8px; color: #94a3b8; margin-top: 2px; }
.note-text { font-size: calc(9.5px * var(--pdf-text)); color: var(--pdf-ink); line-height: 1.55; }
.note-time { font-size: calc(8px * var(--pdf-text)); color: var(--pdf-ink-faint); margin-top: 2px; }
.note-code { font-size: calc(9px * var(--pdf-text)); }
.note-clock { font-size: calc(10px * var(--pdf-text)); font-weight: 400; color: var(--pdf-ink-soft); }
.empty-day { font-size: 9.5px; color: #cbd5e1; font-style: italic; text-align: center; padding: 14px 0; }
.empty-day { font-size: calc(9.5px * var(--pdf-text)); color: #cbd5e1; font-style: italic; text-align: center; padding: 14px 0; }
/* ── Plugin sections ───────────────────────────── */
.plugin-sections { padding: 16px 28px 6px; }
.plugin-section { margin-bottom: 16px; page-break-inside: avoid; }
.plugin-section-title { font-size: 12px; font-weight: 600; color: #1e293b; margin-bottom: 6px; padding-bottom: 4px; border-bottom: 1px solid #e2e8f0; }
.plugin-section-text { font-size: 9.5px; color: #334155; line-height: 1.55; margin-bottom: 5px; }
.plugin-section-title { font-size: calc(12px * var(--pdf-text)); font-weight: 600; color: #1e293b; margin-bottom: 6px; padding-bottom: 4px; border-bottom: 1px solid #e2e8f0; }
.plugin-section-text { font-size: calc(9.5px * var(--pdf-text)); color: var(--pdf-ink); line-height: 1.55; margin-bottom: 5px; }
.plugin-section-table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.plugin-section-table th { font-size: 8px; font-weight: 600; color: #64748b; text-transform: uppercase; letter-spacing: 0.5px; text-align: left; padding: 4px 8px; border-bottom: 1px solid #e2e8f0; }
.plugin-section-table td { font-size: 9px; color: #334155; padding: 4px 8px; border-bottom: 1px solid #f1f5f9; }
.plugin-section-table th { font-size: calc(8px * var(--pdf-text)); font-weight: 600; color: #64748b; text-transform: uppercase; letter-spacing: 0.5px; text-align: left; padding: 4px 8px; border-bottom: 1px solid #e2e8f0; }
.plugin-section-table td { font-size: calc(9px * var(--pdf-text)); color: var(--pdf-ink); padding: 4px 8px; border-bottom: 1px solid #f1f5f9; }
/* ── Print ─────────────────────────────────────── */
@media print {
@@ -817,7 +835,7 @@ export async function downloadTripPDF({ trip, days, places, assignments: allStor
}
</style>
</head>
<body${bodyClassAttr(breaksPerDay, showTransportNotes)}>
<body${bodyClassAttr(breaksPerDay, showTransportNotes, largeText)}>
<!-- Footer on every page -->
<div class="pdf-footer">
@@ -875,10 +893,10 @@ ${pluginSectionsHtml}
markdown.dispose()
if (signal?.aborted) return
openPdfPreview({ html, title: trip?.title || tr('pdf.travelPlan'), tripId: trip?.id, tr, breaksPerDay, showTransportNotes, hasTransportNotes })
openPdfPreview({ html, title: trip?.title || tr('pdf.travelPlan'), tripId: trip?.id, tr, breaksPerDay, showTransportNotes, hasTransportNotes, largeText })
}
function bodyClassAttr(breaksPerDay: boolean, showTransportNotes: boolean): string {
const classes = [!breaksPerDay && 'pdf-flow', !showTransportNotes && 'pdf-no-transport-notes'].filter(Boolean)
function bodyClassAttr(breaksPerDay: boolean, showTransportNotes: boolean, largeText: boolean): string {
const classes = [!breaksPerDay && 'pdf-flow', !showTransportNotes && 'pdf-no-transport-notes', largeText && 'pdf-large-text'].filter(Boolean)
return classes.length ? ` class="${classes.join(' ')}"` : ''
}
+1 -1
View File
@@ -24,7 +24,7 @@ export const PDF_MARKDOWN_CSS = `
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { font-size: 1.1em; font-weight: 700; margin: 4px 0 2px; }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid #e2e8f0; padding: 2px 5px; text-align: start; }
.md code { font-family: ui-monospace, monospace; font-size: 8.5px; }
.md code { font-family: ui-monospace, monospace; font-size: calc(8.5px * var(--pdf-text, 1)); }
.md a { color: inherit; text-decoration: underline; }
.md blockquote { border-inline-start: 2px solid #e2e8f0; padding-inline-start: 6px; }
`;
+26 -2
View File
@@ -1,12 +1,12 @@
/**
* FE-PDFPREVIEW-001 to FE-PDFPREVIEW-005: the trip PDF's preview and the control
* FE-PDFPREVIEW-001 to FE-PDFPREVIEW-007: the trip PDF's preview and the control
* that saves it. An iPhone or iPad ignores print() in the Home Screen app, so
* there the preview hands the export to Safari instead of offering a button that
* does nothing.
*/
import { afterEach, describe, expect, it, vi } from 'vitest';
import { PAGE_BREAK_KEY, openPdfPreview, type PdfPreviewOptions } from './pdfPreview';
import { LARGE_TEXT_KEY, PAGE_BREAK_KEY, openPdfPreview, type PdfPreviewOptions } from './pdfPreview';
const tr = (key: string) => key;
@@ -19,6 +19,7 @@ function open(overrides: Partial<PdfPreviewOptions> = {}) {
breaksPerDay: true,
showTransportNotes: true,
hasTransportNotes: false,
largeText: false,
...overrides,
});
}
@@ -87,4 +88,27 @@ describe('openPdfPreview', () => {
expect(toggle?.getAttribute('aria-checked')).toBe('false');
expect(localStorage.getItem(PAGE_BREAK_KEY)).not.toBeNull();
});
it('FE-PDFPREVIEW-006: the large-text switch starts as given, flips, and remembers the choice', () => {
open();
const toggle = document.getElementById('pdf-large-text-toggle');
expect(toggle?.getAttribute('aria-label')).toBe('pdf.largeText');
expect(toggle?.getAttribute('aria-checked')).toBe('false');
toggle?.click();
expect(toggle?.getAttribute('aria-checked')).toBe('true');
expect(localStorage.getItem(LARGE_TEXT_KEY)).toBe('1');
toggle?.click();
expect(localStorage.getItem(LARGE_TEXT_KEY)).toBe('0');
});
it('FE-PDFPREVIEW-007: each label stays with its switch, so a narrow header wraps between them', () => {
open({ largeText: true, hasTransportNotes: true });
for (const id of ['pdf-transport-notes-toggle', 'pdf-daybreak-toggle', 'pdf-large-text-toggle']) {
const toggle = document.getElementById(id);
const unit = toggle?.parentElement;
expect(unit?.querySelector(`label[for="${id}"]`)).not.toBeNull();
expect(unit?.style.whiteSpace).toBe('nowrap');
}
expect(document.getElementById('pdf-large-text-toggle')?.getAttribute('aria-checked')).toBe('true');
});
});
+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 {
+10 -1
View File
@@ -1,4 +1,4 @@
// FE-UTIL-PDFSWITCH-001 to FE-UTIL-PDFSWITCH-002
// FE-UTIL-PDFSWITCH-001 to FE-UTIL-PDFSWITCH-003
import { afterEach, describe, expect, it, vi } from 'vitest';
import { pdfSwitchOn, rememberPdfSwitch } from './pdfSwitch';
@@ -28,6 +28,15 @@ describe('pdfSwitch', () => {
throw new Error('blocked');
});
expect(pdfSwitchOn(KEY)).toBe(true);
expect(pdfSwitchOn(KEY, false)).toBe(false);
expect(() => rememberPdfSwitch(KEY, false)).not.toThrow();
});
it('FE-UTIL-PDFSWITCH-003: a switch that defaults to off stays off until it is turned on', () => {
expect(pdfSwitchOn(KEY, false)).toBe(false);
rememberPdfSwitch(KEY, true);
expect(pdfSwitchOn(KEY, false)).toBe(true);
rememberPdfSwitch(KEY, false);
expect(pdfSwitchOn(KEY, false)).toBe(false);
});
});
+7 -6
View File
@@ -1,14 +1,15 @@
/*
* The two switches of the trip PDF preview (a new page for every day, and the notes
* of the transports), remembered in this browser.
* The switches of the trip PDF preview (a new page for every day, the notes of
* the transports, large text), remembered in this browser.
*/
/** A preview switch that is on unless it was turned off; both default to on. */
export function pdfSwitchOn(key: string): boolean {
/** A preview switch as it was last left; `defaultOn` until it is first touched, or when storage is blocked. */
export function pdfSwitchOn(key: string, defaultOn = true): boolean {
try {
return localStorage.getItem(key) !== '0';
const stored = localStorage.getItem(key);
return stored === null ? defaultOn : stored !== '0';
} catch {
return true;
return defaultOn;
}
}
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'لا يمكن لنظام iOS الطباعة من التطبيق على الشاشة الرئيسية. سيفتح Safari هذه الرحلة مع تجهيز التصدير، ويمكنك حفظ ملف PDF هناك.',
'pdf.pageBreakPerDay': 'فاصل صفحة لكل يوم',
'pdf.transportNotes': 'ملاحظات التنقل',
'pdf.largeText': 'نص كبير',
'pdf.mapTitle': 'نظرة عامة على المسار',
'pdf.distanceLabel': 'المسافة',
'pdf.mapCredit': 'حدود الدول: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'iOS Əsas ekrandakı tətbiqdən çap edə bilmir. Safari bu səfəri ixrac hazır vəziyyətdə açır, PDF-i orada saxlaya bilərsən.',
'pdf.pageBreakPerDay': 'Hər gün üçün yeni səhifə',
'pdf.transportNotes': 'Nəqliyyat qeydləri',
'pdf.largeText': 'Böyük mətn',
'pdf.mapTitle': 'Marşrutun icmalı',
'pdf.distanceLabel': 'Məsafə',
'pdf.mapCredit': 'Ölkə sərhədləri: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'O iOS não consegue imprimir pelo app na Tela de Início. O Safari abre esta viagem com a exportação pronta, e lá você pode salvar o PDF.',
'pdf.pageBreakPerDay': 'Quebra de página por dia',
'pdf.transportNotes': 'Notas de transporte',
'pdf.largeText': 'Texto grande',
'pdf.mapTitle': 'Visão geral da rota',
'pdf.distanceLabel': 'Distância',
'pdf.mapCredit': 'Contornos dos países: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
"iOS no pot imprimir des de l'app de la pantalla d'inici. Safari obre aquest viatge amb l'exportació a punt i allà pots desar el PDF.",
'pdf.pageBreakPerDay': 'Salt de pàgina per dia',
'pdf.transportNotes': 'Notes del transport',
'pdf.largeText': 'Text gran',
'pdf.mapTitle': 'Resum de la ruta',
'pdf.distanceLabel': 'Distància',
'pdf.mapCredit': 'Contorns dels països: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'iOS neumí tisknout z aplikace na ploše. Safari otevře tento výlet s připraveným exportem a tam si PDF uložíte.',
'pdf.pageBreakPerDay': 'Zalomení stránky pro každý den',
'pdf.transportNotes': 'Poznámky k dopravě',
'pdf.largeText': 'Velké písmo',
'pdf.mapTitle': 'Přehled trasy',
'pdf.distanceLabel': 'Vzdálenost',
'pdf.mapCredit': 'Obrysy zemí: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'iOS kann aus der App auf dem Home-Bildschirm nicht drucken. Safari öffnet diese Reise mit dem Export, dort kannst du das PDF speichern.',
'pdf.pageBreakPerDay': 'Seitenumbruch pro Tag',
'pdf.transportNotes': 'Notizen zu Transporten',
'pdf.largeText': 'Große Schrift',
'pdf.mapTitle': 'Routenübersicht',
'pdf.distanceLabel': 'Strecke',
'pdf.mapCredit': 'Ländergrenzen: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'iOS cannot print from the app on your Home Screen. Safari opens this trip with the export ready, and there you can save the PDF.',
'pdf.pageBreakPerDay': 'Page break per day',
'pdf.transportNotes': 'Transport notes',
'pdf.largeText': 'Large text',
'pdf.mapTitle': 'Route overview',
'pdf.distanceLabel': 'Distance',
'pdf.mapCredit': 'Country outlines: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'iOS no puede imprimir desde la app de la pantalla de inicio. Safari abre este viaje con la exportación lista y allí puedes guardar el PDF.',
'pdf.pageBreakPerDay': 'Salto de página por día',
'pdf.transportNotes': 'Notas de transporte',
'pdf.largeText': 'Texto grande',
'pdf.mapTitle': 'Resumen de la ruta',
'pdf.distanceLabel': 'Distancia',
'pdf.mapCredit': 'Contornos de países: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'iOS ei saa avakuval olevast rakendusest printida. Safari avab selle reisi valmis ekspordiga ja seal saad PDF-i salvestada.',
'pdf.pageBreakPerDay': 'Iga päev uuel lehel',
'pdf.transportNotes': 'Transpordi märkmed',
'pdf.largeText': 'Suur kiri',
'pdf.mapTitle': 'Marsruudi ülevaade',
'pdf.distanceLabel': 'Vahemaa',
'pdf.mapCredit': 'Riigipiirid: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
"iOS ne peut pas imprimer depuis l'app de l'écran d'accueil. Safari ouvre ce voyage avec l'export prêt, et vous pourrez y enregistrer le PDF.",
'pdf.pageBreakPerDay': 'Saut de page par jour',
'pdf.transportNotes': 'Notes de transport',
'pdf.largeText': 'Texte agrandi',
'pdf.mapTitle': "Aperçu de l'itinéraire",
'pdf.distanceLabel': 'Distance', // same-as-en
'pdf.mapCredit': 'Contours des pays : geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'Το iOS δεν μπορεί να εκτυπώσει από την εφαρμογή στην οθόνη Αφετηρίας. Το Safari ανοίγει αυτό το ταξίδι με έτοιμη την εξαγωγή, εκεί μπορείς να αποθηκεύσεις το PDF.',
'pdf.pageBreakPerDay': 'Αλλαγή σελίδας ανά ημέρα',
'pdf.transportNotes': 'Σημειώσεις μεταφορών',
'pdf.largeText': 'Μεγάλο κείμενο',
'pdf.mapTitle': 'Επισκόπηση διαδρομής',
'pdf.distanceLabel': 'Απόσταση',
'pdf.mapCredit': 'Περιγράμματα χωρών: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'מערכת iOS לא יכולה להדפיס מהאפליקציה שבמסך הבית. Safari יפתח את הטיול הזה עם הייצוא מוכן, ושם אפשר לשמור את ה-PDF.',
'pdf.pageBreakPerDay': 'מעבר עמוד לכל יום',
'pdf.transportNotes': 'הערות תחבורה',
'pdf.largeText': 'טקסט גדול',
'pdf.mapTitle': 'סקירת המסלול',
'pdf.distanceLabel': 'מרחק',
'pdf.mapCredit': 'גבולות מדינות: geoBoundaries ‏(CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'Az iOS nem tud nyomtatni a kezdőképernyőn lévő appból. A Safari megnyitja ezt az utat az előkészített exporttal, ott mentheted a PDF-et.',
'pdf.pageBreakPerDay': 'Oldaltörés naponta',
'pdf.transportNotes': 'Közlekedési jegyzetek',
'pdf.largeText': 'Nagy betűméret',
'pdf.mapTitle': 'Útvonal áttekintése',
'pdf.distanceLabel': 'Távolság',
'pdf.mapCredit': 'Országhatárok: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'iOS tidak bisa mencetak dari aplikasi di Layar Utama. Safari membuka perjalanan ini dengan ekspor yang siap, di sana kamu bisa menyimpan PDF.',
'pdf.pageBreakPerDay': 'Pemisah halaman per hari',
'pdf.transportNotes': 'Catatan transportasi',
'pdf.largeText': 'Teks besar',
'pdf.mapTitle': 'Ringkasan rute',
'pdf.distanceLabel': 'Jarak',
'pdf.mapCredit': 'Garis batas negara: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
"iOS non può stampare dall'app nella schermata Home. Safari apre questo viaggio con l'esportazione pronta, lì puoi salvare il PDF.",
'pdf.pageBreakPerDay': 'Interruzione di pagina per giorno',
'pdf.transportNotes': 'Note sui trasporti',
'pdf.largeText': 'Testo grande',
'pdf.mapTitle': 'Panoramica del percorso',
'pdf.distanceLabel': 'Distanza',
'pdf.mapCredit': 'Confini dei paesi: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'iOS ではホーム画面のアプリから印刷できません。Safari でこの旅行をエクスポートの準備ができた状態で開き、そこで PDF を保存できます。',
'pdf.pageBreakPerDay': '日ごとに改ページ',
'pdf.transportNotes': '交通機関のメモ',
'pdf.largeText': '大きな文字',
'pdf.mapTitle': 'ルート概要',
'pdf.distanceLabel': '距離',
'pdf.mapCredit': '国境線: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'iOS에서는 홈 화면 앱에서 인쇄할 수 없습니다. Safari에서 내보내기가 준비된 상태로 이 여행이 열리며, 거기서 PDF를 저장할 수 있습니다.',
'pdf.pageBreakPerDay': '날짜별 페이지 나누기',
'pdf.transportNotes': '교통편 메모',
'pdf.largeText': '큰 글씨',
'pdf.mapTitle': '경로 개요',
'pdf.distanceLabel': '거리',
'pdf.mapCredit': '국가 윤곽: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'iOS kan niet afdrukken vanuit de app op je beginscherm. Safari opent deze reis met de export klaar, daar kun je de PDF opslaan.',
'pdf.pageBreakPerDay': 'Pagina-einde per dag',
'pdf.transportNotes': 'Notities bij vervoer',
'pdf.largeText': 'Grote tekst',
'pdf.mapTitle': 'Routeoverzicht',
'pdf.distanceLabel': 'Afstand',
'pdf.mapCredit': 'Landcontouren: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'iOS nie może drukować z aplikacji na ekranie początkowym. Safari otworzy tę podróż z gotowym eksportem i tam zapiszesz PDF.',
'pdf.pageBreakPerDay': 'Podział strony dla każdego dnia',
'pdf.transportNotes': 'Notatki do transportu',
'pdf.largeText': 'Duży tekst',
'pdf.mapTitle': 'Przegląd trasy',
'pdf.distanceLabel': 'Dystans',
'pdf.mapCredit': 'Kontury krajów: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'iOS не может печатать из приложения на экране «Домой». Safari откроет эту поездку с готовым экспортом, там можно сохранить PDF.',
'pdf.pageBreakPerDay': 'Разрыв страницы для каждого дня',
'pdf.transportNotes': 'Заметки к транспорту',
'pdf.largeText': 'Крупный текст',
'pdf.mapTitle': 'Обзор маршрута',
'pdf.distanceLabel': 'Расстояние',
'pdf.mapCredit': 'Контуры стран: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'iOS nedokáže tlačiť z aplikácie na ploche. Safari otvorí tento výlet s pripraveným exportom a tam si PDF uložíte.',
'pdf.pageBreakPerDay': 'Zalomenie strany pre každý deň',
'pdf.transportNotes': 'Poznámky k doprave',
'pdf.largeText': 'Veľké písmo',
'pdf.mapTitle': 'Prehľad trasy',
'pdf.distanceLabel': 'Vzdialenosť',
'pdf.mapCredit': 'Obrysy krajín: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'iOS kan inte skriva ut från appen på hemskärmen. Safari öppnar resan med exporten redo, där kan du spara PDF:en.',
'pdf.pageBreakPerDay': 'Sidbrytning per dag',
'pdf.transportNotes': 'Anteckningar om transporter',
'pdf.largeText': 'Stor text',
'pdf.mapTitle': 'Ruttöversikt',
'pdf.distanceLabel': 'Sträcka',
'pdf.mapCredit': 'Landskonturer: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -10,6 +10,7 @@ const pdf: TranslationStrings = {
'pdf.safariHint': 'iOS พิมพ์จากแอปบนหน้าจอโฮมไม่ได้ Safari จะเปิดทริปนี้พร้อมการส่งออก และคุณบันทึก PDF ได้ที่นั่น',
'pdf.pageBreakPerDay': 'ขึ้นหน้าใหม่ทุกวัน',
'pdf.transportNotes': 'บันทึกการเดินทาง',
'pdf.largeText': 'ตัวอักษรขนาดใหญ่',
'pdf.mapTitle': 'ภาพรวมเส้นทาง',
'pdf.distanceLabel': 'ระยะทาง',
'pdf.mapCredit': 'ขอบเขตประเทศ: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
"iOS, ana ekrandaki uygulamadan yazdıramaz. Safari bu geziyi dışa aktarma hazır şekilde açar, PDF'i orada kaydedebilirsin.",
'pdf.pageBreakPerDay': 'Her gün için sayfa sonu',
'pdf.transportNotes': 'Ulaşım notları',
'pdf.largeText': 'Büyük yazı',
'pdf.mapTitle': 'Rota genel görünümü',
'pdf.distanceLabel': 'Mesafe',
'pdf.mapCredit': 'Ülke sınırları: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'iOS не може друкувати з застосунку на екрані «Додому». Safari відкриє цю подорож із готовим експортом, там можна зберегти PDF.',
'pdf.pageBreakPerDay': 'Розрив сторінки для кожного дня',
'pdf.transportNotes': 'Нотатки до транспорту',
'pdf.largeText': 'Великий текст',
'pdf.mapTitle': 'Огляд маршруту',
'pdf.distanceLabel': 'Відстань',
'pdf.mapCredit': 'Контури країн: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -11,6 +11,7 @@ const pdf: TranslationStrings = {
'iOS không thể in từ ứng dụng trên Màn hình chính. Safari sẽ mở chuyến đi này với bản xuất sẵn sàng, tại đó bạn có thể lưu PDF.',
'pdf.pageBreakPerDay': 'Ngắt trang cho mỗi ngày',
'pdf.transportNotes': 'Ghi chú phương tiện',
'pdf.largeText': 'Chữ lớn',
'pdf.mapTitle': 'Tổng quan lộ trình',
'pdf.distanceLabel': 'Quãng đường',
'pdf.mapCredit': 'Đường viền quốc gia: geoBoundaries (CC BY 4.0)',
+1
View File
@@ -10,6 +10,7 @@ const pdf: TranslationStrings = {
'pdf.safariHint': 'iOS 無法從主畫面上的 App 列印。Safari 會開啟此行程並準備好匯出,你可以在那裡儲存 PDF。',
'pdf.pageBreakPerDay': '每天分頁',
'pdf.transportNotes': '交通備註',
'pdf.largeText': '大字體',
'pdf.mapTitle': '路線總覽',
'pdf.distanceLabel': '距離',
'pdf.mapCredit': '國家輪廓:geoBoundaries (CC BY 4.0)',
+1
View File
@@ -10,6 +10,7 @@ const pdf: TranslationStrings = {
'pdf.safariHint': 'iOS 无法从主屏幕上的应用打印。Safari 会打开此行程并准备好导出,你可以在那里保存 PDF。',
'pdf.pageBreakPerDay': '每天分页',
'pdf.transportNotes': '交通备注',
'pdf.largeText': '大字体',
'pdf.mapTitle': '路线总览',
'pdf.distanceLabel': '距离',
'pdf.mapCredit': '国家轮廓:geoBoundaries (CC BY 4.0)',
+2
View File
@@ -52,6 +52,8 @@ Each day starts on a new page, unless you turn off **Page break per day**, with
**Transport notes** sits next to it when a flight, train, rental or other transport of the trip has notes. On by default, it prints those notes under the transport in the day plan; turn it off to leave them out. This choice is remembered in the browser too.
**Large text** is the last switch in the header. Off by default, it prints the day pages in larger type and turns their grey text darker, which reads better on paper and on an inkjet printer. The cover and the route map keep their size. This choice is remembered in the browser too.
Under the header:
- **The stay**, when an accommodation covers that day: *Check-in* on the first day, *Check-out* on the last, *Accommodation* on the nights in between, with the time, the place name, the address, the notes, and the booking code on the check-in day only