feat: new page formats A3, A5, letter, legal

This commit is contained in:
Steffen Becker committed 2026-07-08 19:21:18 +00:00
1 parent d11fc065f8
commit bbd84cbeed
15 files changed
+177 -62

No files matched your search

+10 -6
View File
@@ -18,7 +18,8 @@
import HeaderFooterLayer from './HeaderFooterLayer.svelte';
import { saveDocument, loadDocument } from '../storage/autosave';
import { applyMarginVars, cmToPx, DEFAULT_MARGINS, type PageMargins } from '../storage/pageMargins';
import { applyOrientationVars, type Orientation } from '../storage/pageOrientation';
import { type Orientation } from '../storage/pageOrientation';
import { applyPageSizeVars, type PageFormat } from '../storage/pageFormat';
import { DEFAULT_HF_DISTANCES, type HfDoc, type HfZone, type HfDistances } from '../storage/headerFooter';
import { FORCE_PAGE_RECALC, type TableBreakBand } from '../editor/extensions/pageBreaks';
import { recordTransaction, resetHistoryLog } from '../utils/historyLog.svelte';
@@ -31,11 +32,12 @@
let {
editor = $bindable(), tick = $bindable(0), currentPage = $bindable(1), numPages = $bindable(1),
zoom = 100, showFormattingMarks = false, pageMargins = DEFAULT_MARGINS, orientation = 'portrait',
pageFormat = 'A4',
headerDoc = $bindable(null), footerDoc = $bindable(null), hfDistances = DEFAULT_HF_DISTANCES,
hfEditor = $bindable(null), hfActive = $bindable(null), hfTick = $bindable(0),
}: {
editor: Editor | null; tick: number; currentPage: number; numPages: number; zoom: number;
showFormattingMarks?: boolean; pageMargins?: PageMargins; orientation?: Orientation;
showFormattingMarks?: boolean; pageMargins?: PageMargins; orientation?: Orientation; pageFormat?: PageFormat;
headerDoc?: HfDoc; footerDoc?: HfDoc; hfDistances?: HfDistances;
hfEditor?: Editor | null; hfActive?: HfZone | null; hfTick?: number;
} = $props();
@@ -46,7 +48,7 @@
applyMarginVars(pageMargins);
});
$effect(() => {
applyOrientationVars(orientation);
applyPageSizeVars(pageFormat, orientation);
});
// Nudge the pageBreaks plugin to recompute with the new content area. The dispatch
@@ -54,9 +56,10 @@
// Svelte effect flush (re-entering it would trip effect_update_depth_exceeded).
let marginRecalcRaf = 0;
$effect(() => {
// track each margin + orientation so the effect re-runs on any change
// track each margin + orientation + format so the effect re-runs on any change
void (pageMargins.top + pageMargins.bottom + pageMargins.left + pageMargins.right);
void orientation;
void pageFormat;
const ed = editor;
if (!ed) return;
cancelAnimationFrame(marginRecalcRaf);
@@ -97,8 +100,8 @@
scaledHeight = Math.round(h * z);
}
// Page cycle (page height + 20px gap) in document px. Orientation-dependent, so
// read live from --user-page-height (set by applyOrientationVars). Must match
// Page cycle (page height + 20px gap) in document px. Format/orientation-dependent,
// so read live from --user-page-height (set by applyPageSizeVars). Must match
// pageBreaks.ts. Fallback = A4 portrait (1123 + 20).
function getCycle(): number {
const ph = parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--user-page-height'));
@@ -679,6 +682,7 @@
{currentPage}
{pageMargins}
{orientation}
{pageFormat}
{hfDistances}
/>
</div>
+7 -4
View File
@@ -2,8 +2,9 @@
import { Editor, generateHTML, type Content } from '@tiptap/core';
import { hfExtensions } from '../editor/extensions/headerFooter';
import { hfIsEmpty, DEFAULT_HF_DISTANCES, type HfDoc, type HfZone, type HfDistances } from '../storage/headerFooter';
import { cmToPx, type PageMargins } from '../storage/pageMargins';
import { PAGE_W_PORTRAIT, PAGE_H_PORTRAIT, type Orientation } from '../storage/pageOrientation';
import { cmToPx, PX_PER_CM, type PageMargins } from '../storage/pageMargins';
import { type Orientation } from '../storage/pageOrientation';
import { pageDimsCm, type PageFormat } from '../storage/pageFormat';
import { t } from '../i18n/i18n.svelte';
let {
@@ -13,6 +14,7 @@
currentPage,
pageMargins,
orientation,
pageFormat = 'A4',
hfDistances = DEFAULT_HF_DISTANCES,
hfEditor = $bindable(),
hfActive = $bindable(),
@@ -24,6 +26,7 @@
currentPage: number;
pageMargins: PageMargins;
orientation: Orientation;
pageFormat?: PageFormat;
hfDistances?: HfDistances;
hfEditor: Editor | null;
hfActive: HfZone | null;
@@ -36,8 +39,8 @@
// All geometry is in unscaled document px — the layer lives inside the scaled
// .paper, so the zoom transform applies to it identically to the page background.
let pageWidthPx = $derived(orientation === 'landscape' ? PAGE_H_PORTRAIT : PAGE_W_PORTRAIT);
let pageHeightPx = $derived(orientation === 'landscape' ? PAGE_W_PORTRAIT : PAGE_H_PORTRAIT);
let pageWidthPx = $derived(pageDimsCm(pageFormat, orientation).w * PX_PER_CM);
let pageHeightPx = $derived(pageDimsCm(pageFormat, orientation).h * PX_PER_CM);
let cycle = $derived(pageHeightPx + PAGE_GAP);
let mTop = $derived(cmToPx(pageMargins.top));
let mBottom = $derived(cmToPx(pageMargins.bottom));
+28 -6
View File
@@ -14,14 +14,17 @@
} from '../utils/fontDetect';
import { DEFAULT_MARGINS, cmToPx, type PageMargins } from '../storage/pageMargins';
import type { Orientation } from '../storage/pageOrientation';
import { pageDimsCm, PAGE_FORMAT_CM, type PageFormat } from '../storage/pageFormat';
import { DEFAULT_HF_DISTANCES, clampHfDistance, type HfDistances } from '../storage/headerFooter';
import { listContext } from '../editor/extensions/indent';
import { findColumns, DEFAULT_COLUMN_GAP_CM } from '../editor/extensions/columns';
import { t } from '../i18n/i18n.svelte';
import { withShortcut } from '../i18n/shortcut';
let { editor, tick, showFormattingMarks = $bindable(), pageMargins = $bindable(DEFAULT_MARGINS), pageOrientation = $bindable<Orientation>('portrait'), hfDistances = $bindable(DEFAULT_HF_DISTANCES), hfActive = null, onEditZone, onDebugDump }:
{ editor: Editor | null; tick: number; showFormattingMarks: boolean; pageMargins?: PageMargins; pageOrientation?: Orientation; hfDistances?: HfDistances; hfActive?: 'header' | 'footer' | null; onEditZone?: (zone: 'header' | 'footer') => void; onDebugDump?: () => void } = $props();
let { editor, tick, showFormattingMarks = $bindable(), pageMargins = $bindable(DEFAULT_MARGINS), pageOrientation = $bindable<Orientation>('portrait'), pageFormat = $bindable<PageFormat>('A4'), hfDistances = $bindable(DEFAULT_HF_DISTANCES), hfActive = null, onEditZone, onDebugDump }:
{ editor: Editor | null; tick: number; showFormattingMarks: boolean; pageMargins?: PageMargins; pageOrientation?: Orientation; pageFormat?: PageFormat; hfDistances?: HfDistances; hfActive?: 'header' | 'footer' | null; onEditZone?: (zone: 'header' | 'footer') => void; onDebugDump?: () => void } = $props();
const PAGE_FORMATS = Object.keys(PAGE_FORMAT_CM) as PageFormat[];
// Must match the first font in --font-serif in global.css. Bundled as a
// webfont so it is always available and matches the exported .odt's font.
@@ -774,11 +777,11 @@
let imageInput = $state<HTMLInputElement | null>(null);
// The page text box in px, so an inserted image never starts wider/taller than
// one page (mirrors export's content-width math; A4 dims swap with orientation).
// one page (mirrors export's content-width math; dims follow format + orientation).
function contentBoxPx(): { maxW: number; maxH: number } {
const land = pageOrientation === 'landscape';
const wCm = (land ? 29.7 : 21) - pageMargins.left - pageMargins.right;
const hCm = (land ? 21 : 29.7) - pageMargins.top - pageMargins.bottom;
const { w, h } = pageDimsCm(pageFormat, pageOrientation);
const wCm = w - pageMargins.left - pageMargins.right;
const hCm = h - pageMargins.top - pageMargins.bottom;
return { maxW: Math.round(cmToPx(wCm)), maxH: Math.round(cmToPx(hCm)) };
}
@@ -1155,6 +1158,12 @@
</button>
{#if layoutOpen}
<div class="layout-dropdown">
<div class="lh-section-label">{t().toolbarExpanded.pageFormat}</div>
<select class="format-select" bind:value={pageFormat} title={t().toolbarExpanded.pageFormat}>
{#each PAGE_FORMATS as fmt}
<option value={fmt}>{t().toolbarExpanded.pageFormats[fmt]}</option>
{/each}
</select>
<div class="lh-section-label">{t().toolbarExpanded.orientation}</div>
<div class="orientation-row">
<button
@@ -1879,6 +1888,19 @@
padding: 4px 6px 2px;
}
.format-select {
margin: 4px 6px 2px;
width: calc(100% - 12px);
padding: 6px 8px;
border: 1px solid var(--color-border);
border-radius: var(--radius);
background: transparent;
color: var(--color-text);
font-family: var(--font-sans);
font-size: 0.78rem;
cursor: pointer;
}
.orientation-btn {
display: flex;
flex-direction: column;