@canvakit/export 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,508 @@
1
+ import { Medium, PageSpec, RenderInput, FilesystemLike, ParsedRenderResult } from '@canvakit/core';
2
+ export { Medium, PageSpec } from '@canvakit/core';
3
+
4
+ /**
5
+ * Export types — the artifact layer over a canvakit render.
6
+ *
7
+ * A canvakit render produces an HTML string (the generate half lives in
8
+ * `@canvakit/core` and stays format-agnostic). This layer turns that HTML into a
9
+ * downloadable ARTIFACT in one of four formats, behind a small pluggable seam so
10
+ * the same call runs on a dev/bureau box (local system Chrome) or in a container
11
+ * (a bundled chromium the caller injects).
12
+ */
13
+
14
+ /**
15
+ * The artifact a caller wants out of a render.
16
+ * - html / html-zip : the document, raw or as a self-contained bundle
17
+ * - png / pdf : pixels / a paginated document (needs a Chrome renderer)
18
+ * - docx : an editable Word document (pure — no browser; lawyers
19
+ * live in Word)
20
+ * - text : an LLM-readable markdown/plain-text projection of the
21
+ * canvas (an `llms.txt` for a canvas) — agent-facing, pure
22
+ * - email-html : the document with its `<style>` blocks inlined onto the
23
+ * elements they match (email clients strip `<style>`) —
24
+ * pure
25
+ */
26
+ type ExportFormat = "html" | "html-zip" | "png" | "pdf" | "docx" | "text" | "email-html";
27
+ /** Page options for the pixel/PDF formats (passed to the Chrome renderer). */
28
+ interface PageOptions {
29
+ /** Paper size for PDF (default A4). */
30
+ format?: "A4" | "Letter";
31
+ /** Landscape orientation (PDF). */
32
+ landscape?: boolean;
33
+ /** Device scale factor (PNG sharpness / PDF scale). */
34
+ scale?: number;
35
+ /** Virtual-time budget in ms — lets fonts/images settle before capture
36
+ * (default 1200). */
37
+ waitMs?: number;
38
+ /** Print background colors/images (PDF; default true here — reports are
39
+ * designed with backgrounds). */
40
+ background?: boolean;
41
+ }
42
+ /**
43
+ * The headless-Chrome seam — the only part that needs a browser. One HTML load
44
+ * can serve both `toPdf` and `toPng`. Ship a `localChromeRenderer` (discovers
45
+ * system Chrome) and accept an injected one (a bundled chromium / puppeteer /
46
+ * playwright) for environments without a system browser.
47
+ */
48
+ interface ChromeRenderer {
49
+ toPdf(html: string, page?: PageOptions): Promise<Buffer>;
50
+ toPng(html: string, page?: PageOptions): Promise<Buffer>;
51
+ }
52
+ /** A fetched asset for the html-zip bundle (bytes + mime), or null to skip. */
53
+ interface FetchedAsset {
54
+ bytes: Buffer;
55
+ mime?: string;
56
+ }
57
+ /**
58
+ * Document-assembly knobs for a `document`-medium PDF (cover + TOC + page
59
+ * numbers, via {@link renderDocumentPdf}). The TOC and page numbers are always
60
+ * produced; only the cover is opt-in.
61
+ */
62
+ interface DocumentExportOptions {
63
+ /**
64
+ * Cover page. A string is used verbatim as the cover HTML; `true` generates a
65
+ * branded cover from {@link ExportOptions.name} (and {@link DocumentExportOptions.coverSubtitle});
66
+ * `false` / omitted = no cover.
67
+ */
68
+ cover?: string | boolean;
69
+ /** Subtitle for the auto-generated cover (e.g. a guild name or date). */
70
+ coverSubtitle?: string;
71
+ /** TOC heading (default "Contents"). */
72
+ tocTitle?: string;
73
+ /** Heading levels to include in the TOC (default [1, 2]). */
74
+ tocLevels?: number[];
75
+ }
76
+ /** Options for {@link exportHtml}. */
77
+ interface ExportOptions {
78
+ /**
79
+ * Which artifact to produce. Optional when {@link ExportOptions.medium} is
80
+ * set — the medium supplies a default format (web → html-zip, document /
81
+ * presentation → pdf, image → png). An explicit `format` always wins.
82
+ */
83
+ format?: ExportFormat;
84
+ /**
85
+ * The canvas's intended output medium (see `@canvakit/core`'s `Medium`). When
86
+ * set, it supplies the default `format` and the page geometry (a `@page` rule
87
+ * injected for pdf). `exportCanvas` fills this from `frontmatter.medium`
88
+ * automatically; pass it to `exportHtml` for an already-rendered document.
89
+ */
90
+ medium?: Medium;
91
+ /**
92
+ * Page-geometry override (frontmatter `page` shape). Overrides the medium's
93
+ * default size / orientation / margin. `exportCanvas` fills it from
94
+ * `frontmatter.page`. For a `document`, its `header`/`footer` become the
95
+ * running header/footer.
96
+ */
97
+ pageSpec?: PageSpec;
98
+ /**
99
+ * Document-assembly options. When the resolved medium is `document` (or this
100
+ * object is present) and the format resolves to `pdf`, the export is built by
101
+ * {@link renderDocumentPdf} — a branded cover + a clickable TOC with real page
102
+ * numbers + running header/footer — instead of the single-pass renderer
103
+ * (Chrome can only produce those via CDP, never from CSS). Header/footer come
104
+ * from {@link ExportOptions.pageSpec}.
105
+ */
106
+ document?: DocumentExportOptions;
107
+ /** Base filename (no extension); the artifact appends the right one. Default
108
+ * "canvas". */
109
+ name?: string;
110
+ /** Page options for the `png`/`pdf` formats. */
111
+ page?: PageOptions;
112
+ /** The Chrome renderer for `png`/`pdf`. Defaults to the resolver (injection >
113
+ * CANVAKIT_RENDERER env > local system Chrome). */
114
+ renderer?: ChromeRenderer;
115
+ /** Binary path for the default local engine (else CANVAKIT_CHROME / discovery). */
116
+ chrome?: string;
117
+ /**
118
+ * For `html-zip`: fetch a referenced asset (image/stylesheet/script) so the
119
+ * bundle is self-contained. Defaults to a `fetch`-backed loader. Return null to
120
+ * leave a reference remote (the default loader does this on any error, so a
121
+ * failed image never fails the export). Inject a stub for offline/tests.
122
+ */
123
+ fetchAsset?: (url: string) => Promise<FetchedAsset | null>;
124
+ }
125
+ /** The produced artifact — bytes + how to serve/name them. */
126
+ interface ExportArtifact {
127
+ format: ExportFormat;
128
+ bytes: Buffer;
129
+ mime: string;
130
+ /** Suggested download filename, with extension. */
131
+ filename: string;
132
+ }
133
+
134
+ /**
135
+ * exportHtml / exportCanvas — the artifact dispatch over a canvakit render.
136
+ *
137
+ * exportCanvas(renderInput, opts?) render via @canvakit/core, then export
138
+ * exportHtml(htmlString, opts) export an already-rendered document
139
+ *
140
+ * Generation stays in `@canvakit/core` (format-agnostic — it emits an HTML
141
+ * string); this picks the artifact:
142
+ * - `html` / `html-zip` — the document, raw or self-contained (pure)
143
+ * - `text` — an LLM-readable markdown projection (pure)
144
+ * - `png` / `pdf` — pixels / a paginated doc via a {@link ChromeRenderer}
145
+ *
146
+ * The canvas's `medium` (web / document / presentation / image) supplies a
147
+ * default `format` and the page geometry (an injected `@page` rule). For a
148
+ * `document` with running header / footer / page numbers / a TOC, see the
149
+ * `document` renderer (`renderDocumentPdf`) — Chrome only produces those via
150
+ * CDP, never from CSS on the single-pass renderer.
151
+ */
152
+
153
+ /** No-op filesystem — a template with no `file`/`query` sources or `imports`
154
+ * never touches it, but `render` requires one. The default for {@link exportCanvas}. */
155
+ declare const noopFilesystem: FilesystemLike;
156
+ /** Turn a rendered HTML document into the requested artifact. */
157
+ declare function exportHtml(html: string, opts: ExportOptions): Promise<ExportArtifact>;
158
+ /** A canvakit render input with `filesystem` optional (defaults to no-op). */
159
+ type ExportCanvasInput = Omit<RenderInput, "filesystem"> & {
160
+ filesystem?: FilesystemLike;
161
+ };
162
+ /** An export artifact plus the render's diagnostics (warnings/statuses/meta). */
163
+ type ExportCanvasResult = ExportArtifact & Pick<ParsedRenderResult, "warnings" | "statuses" | "meta">;
164
+ /**
165
+ * Render a canvakit template via `@canvakit/core`, then export the result. The
166
+ * template's `medium` / `page` frontmatter become the export defaults (so a
167
+ * `medium: document` template exports a paginated PDF without the caller
168
+ * restating it); an explicit `opts.format` / `medium` / `pageSpec` still wins.
169
+ */
170
+ declare function exportCanvas(input: ExportCanvasInput, opts?: ExportOptions): Promise<ExportCanvasResult>;
171
+
172
+ /**
173
+ * localChromeRenderer — the {@link ChromeRenderer} seam backed by the system
174
+ * Chrome/Chromium, headless. It writes the HTML to a temp file and drives Chrome
175
+ * via the same CLI flags the `print` skill proved (`--headless=new
176
+ * --print-to-pdf` / `--screenshot`), so pagination obeys the document's print CSS
177
+ * (`break-before:page` / `break-inside:avoid`). Zero npm deps — it shells out to
178
+ * a browser already on the machine. For environments without one (a lean
179
+ * container), inject a bundled-chromium renderer instead.
180
+ */
181
+
182
+ /** Resolve a usable Chrome binary, or throw a clear, actionable error. */
183
+ declare function findChrome(): string;
184
+ /** The system-Chrome renderer. `chrome` is auto-discovered unless given. */
185
+ declare function localChromeRenderer(chrome?: string): ChromeRenderer;
186
+
187
+ /**
188
+ * cdpChromeRenderer — a {@link ChromeRenderer} backed by Chrome DevTools
189
+ * Protocol `Page.printToPDF`, the only path that produces **branded running
190
+ * header/footer + page numbers**. The CLI `--print-to-pdf` (see chrome.ts)
191
+ * can't: Chrome doesn't implement `@page` margin boxes, and the CLI exposes no
192
+ * header/footer template. CDP does, via `displayHeaderFooter` +
193
+ * `headerTemplate`/`footerTemplate` (special `pageNumber`/`totalPages`/`title`
194
+ * spans Chrome fills in).
195
+ *
196
+ * Ported from the proven deep-research `bible` pipeline (render-pdf.mjs):
197
+ * - `preferCSSPageSize: true` so the injected `@page { size; margin }` (and
198
+ * `@page :first { margin: 0 }` for the cover) drives geometry, and the
199
+ * header/footer render INSIDE the page margin — so a full-bleed cover (0
200
+ * margin) automatically gets no header/footer.
201
+ * - header/footer templates use a SYSTEM font: Chrome renders them in an
202
+ * isolated context with NO access to the document's @font-face/web fonts.
203
+ *
204
+ * Engine notes: spawns a headless Chrome per render (no shared state), talks CDP
205
+ * over the global `WebSocket` (Node 20.10+/22). Zero npm deps — shells out to a
206
+ * browser already on the machine, like chrome.ts. Opt-in: the default renderer
207
+ * stays the CLI one; select this via `CANVAKIT_RENDERER=cdp` or inject it.
208
+ *
209
+ * Remote mode (no local Chrome): set `browserWSEndpoint` (or env
210
+ * `CANVAKIT_BROWSER_WS_ENDPOINT`) to a BROWSER-level CDP-over-WS endpoint — e.g.
211
+ * a remote browser service's session proxy `ws://…/sessions/:id/ws`. The
212
+ * renderer then connects instead of spawning, opens its own isolated target, and
213
+ * sets the document directly with `Page.setDocumentContent` (a remote Chrome
214
+ * can't read the worker's `file://` disk). Same zero deps — still raw CDP over
215
+ * the global WebSocket. This is how a Chrome-less worker renders (brief seam S2);
216
+ * the env fallback lets the document engine's internal renderers (document.ts)
217
+ * route remote with no call-site change, exactly like `CANVAKIT_CHROME`.
218
+ */
219
+
220
+ /**
221
+ * Running-header / footer content. A bare string drops into one default slot
222
+ * (header → left; footer → center, the conventional document footer position);
223
+ * the object form places content in any of the three print slots independently.
224
+ */
225
+ type HeaderFooter = string | {
226
+ left?: string;
227
+ center?: string;
228
+ right?: string;
229
+ };
230
+ /** Which slot the auto page numbers ("n / total") land in. Default `right`. */
231
+ type Slot = "left" | "center" | "right";
232
+ interface CdpRendererOptions {
233
+ /** Chrome binary (else discovered — CANVAKIT_CHROME / system Chrome). */
234
+ chrome?: string;
235
+ /**
236
+ * BROWSER-level CDP-over-WS endpoint of a REMOTE Chrome (e.g.
237
+ * a remote browser service's `ws://…/sessions/:id/ws`). When set (or env
238
+ * `CANVAKIT_BROWSER_WS_ENDPOINT`), the renderer connects instead of spawning —
239
+ * the document is delivered via `Page.setDocumentContent`, not `file://`.
240
+ */
241
+ browserWSEndpoint?: string;
242
+ /** Running-header content (rendered in the top page margin). */
243
+ header?: HeaderFooter;
244
+ /** Running-footer content (rendered in the bottom page margin). */
245
+ footer?: HeaderFooter;
246
+ /** Append "current / total" page numbers to the footer. */
247
+ pageNumbers?: boolean;
248
+ /** Slot the page numbers occupy (composing with any footer content there). Default `right`. */
249
+ pageNumbersSlot?: Slot;
250
+ /** ms to wait after navigation for fonts/images to settle. Default 2500. */
251
+ waitMs?: number;
252
+ }
253
+ /** A CDP-backed renderer with branded header/footer + page numbers. Spawns a
254
+ * local Chrome by default; connects to a remote browser when an endpoint is
255
+ * resolved (option > env). */
256
+ declare function cdpChromeRenderer(opts?: CdpRendererOptions): ChromeRenderer;
257
+
258
+ /**
259
+ * resolveRenderer — the one place every surface picks the {@link ChromeRenderer}
260
+ * for the pixel/PDF formats, so the choice is configuration, never a hard-coded
261
+ * engine. Precedence:
262
+ *
263
+ * 1. an explicitly INJECTED renderer (opts.renderer) — a host that manages its
264
+ * own browser (puppeteer / playwright / a bundled chromium) wins outright.
265
+ * 2. env CANVAKIT_RENDERER — selects a built-in engine. Only "local" ships in
266
+ * this package; any other value means "the host must inject that engine",
267
+ * and we say so loudly instead of guessing.
268
+ * 3. the local system-Chrome renderer (honours CANVAKIT_CHROME for the binary)
269
+ * — the zero-dependency default that works on a dev box, a bureau, or a
270
+ * container that simply baked a `chrome-headless-shell` in and set the env.
271
+ *
272
+ * So there is no engine to "decide": a deployment configures via env (point
273
+ * CANVAKIT_CHROME at a binary) or by injecting a renderer — without touching this
274
+ * library.
275
+ */
276
+
277
+ interface ResolveRendererOptions {
278
+ /** An explicit renderer to use (a host-managed puppeteer/playwright/etc.). Wins. */
279
+ renderer?: ChromeRenderer;
280
+ /** Binary path for the built-in local engine (else CANVAKIT_CHROME / discovery). */
281
+ chrome?: string;
282
+ }
283
+ /** Pick the renderer for `png`/`pdf` exports — injection > env > local Chrome. */
284
+ declare function resolveRenderer(opts?: ResolveRendererOptions): ChromeRenderer;
285
+
286
+ /**
287
+ * renderDocumentPdf — assemble a bible-grade PDF document from canvas HTML:
288
+ * a branded cover, a clickable Table of Contents whose entries carry REAL page
289
+ * numbers, and numbered content with a running header/footer.
290
+ *
291
+ * This is the multi-pass engine the `document` medium needs and that no single
292
+ * print pass can do (Chrome has no `target-counter` for TOC page numbers).
293
+ * Ported from the proven deep-research `bible` pipeline (make-bible.sh) — the
294
+ * skill is left intact; this is the package-level, HTML-input generalisation:
295
+ *
296
+ * 1. extract h1/h2 headings from the content → TOC entries (+ inject ids)
297
+ * 2. render content via CDP (page numbers from 1, running header/footer)
298
+ * 3. locate each heading's page by text search (pdfjs) → page map
299
+ * 4. render the TOC (with the found page numbers) + the cover (unnumbered)
300
+ * 5. merge cover + TOC + content (pdf-lib)
301
+ * 6. re-stamp clickable TOC link annotations (pdf-lib) — the split render
302
+ * drops them, so we add GoTo links from each TOC row to its content page
303
+ *
304
+ * Engine deps are lazy + optional: pdfjs-dist (text/layout) + pdf-lib (merge +
305
+ * annotations). The core export (`exportHtml`/`exportCanvas`) never loads them.
306
+ */
307
+
308
+ interface DocumentTocEntry {
309
+ level: number;
310
+ label: string;
311
+ slug: string;
312
+ }
313
+ interface DocumentOptions {
314
+ /** Content HTML (a full document, head + body). Its h1/h2 headings become the TOC. */
315
+ contentHtml: string;
316
+ /**
317
+ * Optional cover HTML — the FRONT full-bleed pages (1re / 2e de couverture).
318
+ * One string → a single full-bleed first page; an array → several front pages
319
+ * (front cover, inside cover, a statement / key-facts page, …) rendered in
320
+ * order before the TOC. All are margin-0 with no running header/footer; each
321
+ * entry may itself span multiple pages.
322
+ */
323
+ coverHtml?: string | string[];
324
+ /**
325
+ * Optional BACK full-bleed pages (3e / 4e de couverture) — appended after the
326
+ * content, the last entry becoming the final page (the quatrième de
327
+ * couverture / back cover). Same string|array shape and full-bleed treatment
328
+ * as {@link coverHtml}; they sit after the content so they don't shift the TOC
329
+ * page numbers or content links.
330
+ */
331
+ backHtml?: string | string[];
332
+ /** Heading levels to list in the TOC. Default [1, 2]. */
333
+ tocLevels?: number[];
334
+ /** TOC page heading. Default "Contents". */
335
+ tocTitle?: string;
336
+ /** Heading labels to OMIT from the TOC (matched case/space/punct-insensitively), e.g. ["Executive summary", "Sources"]. */
337
+ tocExclude?: string[];
338
+ /** Running-header content (top margin). String or `{left,center,right}` slots. */
339
+ header?: HeaderFooter;
340
+ /** Running-footer content (bottom margin). String or `{left,center,right}` slots; page numbers default to the right slot. */
341
+ footer?: HeaderFooter;
342
+ /** Slot the auto page numbers occupy. Default `right`. */
343
+ pageNumbersSlot?: Slot;
344
+ /** Page geometry. Default A4 portrait, 18mm margin. */
345
+ pageSpec?: PageSpec;
346
+ /** Extra CSS for the generated TOC page (brand match — overrides the defaults). */
347
+ tocCss?: string;
348
+ /** Raw HTML injected into the TOC page `<head>` — e.g. a web-font `<link>` so the TOC can match brand type (the TOC is a normal page, NOT a Chrome header template, so web fonts work). */
349
+ tocHead?: string;
350
+ /** Chrome binary (else discovered). */
351
+ chrome?: string;
352
+ /**
353
+ * Print-time shrink-to-fit for the CONTENT pass (0.1-2, forwarded to CDP
354
+ * `Page.printToPDF`'s `scale`) — covers/TOC render at their normal size
355
+ * regardless, since the overflow this corrects is content length, not
356
+ * cover/TOC length.
357
+ */
358
+ scale?: number;
359
+ }
360
+ interface DocumentResult {
361
+ bytes: Buffer;
362
+ pages: number;
363
+ toc: DocumentTocEntry[];
364
+ /** slug → content-local page (1-based). */
365
+ pageMap: Record<string, number>;
366
+ /** Entries whose page / TOC row couldn't be resolved. */
367
+ warnings: string[];
368
+ }
369
+ /**
370
+ * Match key for locating a heading in rendered-PDF text: entity-decode (so an
371
+ * escaped `&#39;` collapses to the glyph the PDF shows, not the digits `39`),
372
+ * lowercase, drop everything but [a-z0-9]. Used to match a TOC label against the
373
+ * text pdfjs extracts from each page. Exported for regression testing.
374
+ */
375
+ declare const matchKey: (s: string) => string;
376
+ /**
377
+ * Render canvas HTML to a bible-grade PDF: branded front cover(s) + clickable
378
+ * TOC with real page numbers + numbered content with a running header/footer +
379
+ * optional back pages (3e/4e de couverture).
380
+ */
381
+ declare function renderDocumentPdf(opts: DocumentOptions): Promise<DocumentResult>;
382
+
383
+ /**
384
+ * htmlToZip — bundle a rendered HTML document + its referenced assets into a
385
+ * self-contained, portable zip (`index.html` + `assets/…`, references rewritten
386
+ * to the local copies). The point is an artifact that opens offline, with no
387
+ * dependency on a CDN that may resize, move, or expire the images.
388
+ *
389
+ * Scope (v1): crawls `src=`/`href=` attributes (img, link, script, source). It
390
+ * does NOT crawl CSS `url(...)` inside stylesheets — canvakit reports inline
391
+ * their CSS and reference images via `<img>`, which this covers. A reference that
392
+ * can't be fetched is left remote (the export never fails over one dead image).
393
+ */
394
+
395
+ /** Unique referenced asset URLs in `src=`/`href=` attributes (skips data:/anchors). */
396
+ declare function extractAssetUrls(html: string): string[];
397
+ /**
398
+ * Bundle `html` + its fetchable assets into a zip buffer. Returns
399
+ * `index.html` (with rewritten references) plus an `assets/` folder.
400
+ */
401
+ declare function htmlToZip(html: string, opts?: Pick<ExportOptions, "fetchAsset">): Promise<Buffer>;
402
+
403
+ /**
404
+ * htmlToText — project a rendered canvas (HTML) to LLM-readable markdown: an
405
+ * "llms.txt" for a canvas.
406
+ *
407
+ * canvakit's base is HTML + datasources, so the rendered document IS the source
408
+ * of truth. This strips the visual chrome (style / script / svg) and keeps the
409
+ * content structure an agent needs — headings, lists, links, tables, emphasis,
410
+ * code, quotes. The agent-facing counterpart to the human-facing pdf / png.
411
+ *
412
+ * Zero-dep + regex-based: solid for the clean, rendered HTML canvakit emits, not
413
+ * a general-purpose HTML→Markdown engine. Conservative — unknown tags are
414
+ * dropped, never guessed.
415
+ */
416
+ /** Project rendered canvas HTML to LLM-readable markdown. */
417
+ declare function htmlToText(html: string): string;
418
+
419
+ /**
420
+ * htmlToEmail — the email-safe HTML projection. designkit / tailwind-bridge
421
+ * inject `<style>` blocks, which Gmail / Outlook strip; juice inlines those
422
+ * rules onto the elements they match (and drops the now-redundant `<style>`
423
+ * tags) so the styling survives an email client.
424
+ */
425
+ declare function htmlToEmail(html: string): string;
426
+
427
+ /**
428
+ * Medium → export defaults + page CSS.
429
+ *
430
+ * A canvas's `medium` (web / document / presentation / image — see
431
+ * `@canvakit/core`) is a design constraint, not just a file format. This maps
432
+ * it to a default artifact `format` (web → html-zip, document/presentation →
433
+ * pdf, image → png) and to the page GEOMETRY, compiled to a `@page` CSS block
434
+ * the headless-Chrome renderer honours via `preferCSSPageSize`.
435
+ *
436
+ * What lives here (works on the base single-pass renderer):
437
+ * - `@page { size; margin }` geometry, and
438
+ * - `@page :first { margin: 0 }` for a full-bleed branded cover.
439
+ *
440
+ * What does NOT live here — the document "chrome": running header / footer,
441
+ * page numbers, and a TOC whose entries carry real page numbers. Headless
442
+ * Chrome produces those via the CDP `Page.printToPDF` header/footer templates
443
+ * plus a two-pass page-number extraction (render content → locate headings →
444
+ * render the TOC with the found numbers → merge → re-stamp links). That is the
445
+ * `document` renderer's job (the proven pipeline in the deep-research `bible`
446
+ * skill); `wantsDocumentChrome` flags when a spec needs it so a single-pass
447
+ * caller can route to that renderer instead of silently dropping page numbers.
448
+ */
449
+
450
+ /** The default artifact shape for a medium. */
451
+ interface MediumDefaults {
452
+ format: ExportFormat;
453
+ /** Renderer flags (landscape/scale/background) for png/pdf. */
454
+ page: PageOptions;
455
+ /** Default page geometry + chrome (overridden field-by-field by frontmatter `page`). */
456
+ pageSpec?: PageSpec;
457
+ }
458
+ /** The default export shape (format + page geometry) for a medium. */
459
+ declare function mediumDefaults(medium: Medium): MediumDefaults;
460
+ /** Field-by-field merge of a base PageSpec with an override (override wins). */
461
+ declare function mergePageSpec(base: PageSpec | undefined, override: PageSpec | undefined): PageSpec | undefined;
462
+ /**
463
+ * Resolve a {@link PageSpec.size} (+ orientation) to a CSS `@page size` value:
464
+ * named paper (`A4 landscape`), an aspect ratio (`16:9` → `1280px 720px`),
465
+ * `<W>x<H>` pixels, or a raw CSS value passed through. Orientation alone is a
466
+ * valid `@page size` too. Returns null when nothing is specified.
467
+ */
468
+ declare function resolvePageSize(size: string | undefined, orientation?: "portrait" | "landscape"): string | null;
469
+ /**
470
+ * Compile a {@link PageSpec} to a `@page` CSS block — geometry (`size`/`margin`)
471
+ * and a full-bleed cover (`@page :first`). Mirrors the bible pipeline's `@page`
472
+ * CSS; honoured by Chrome via `preferCSSPageSize`. Returns null when the spec
473
+ * implies no page rules. (Running header/footer/page numbers are NOT CSS here —
474
+ * they come from the document renderer; see {@link wantsDocumentChrome}.)
475
+ */
476
+ declare function pageCssFor(spec: PageSpec | undefined): string | null;
477
+ /**
478
+ * True when a spec asks for document chrome — a running header / footer / page
479
+ * numbers — which Chrome only produces through the CDP `printToPDF` header/
480
+ * footer templates (the `document` renderer), never from `@page` CSS on the
481
+ * base single-pass renderer. Callers use this to route to that renderer (or to
482
+ * warn) rather than emit page-number CSS Chrome's CLI silently ignores.
483
+ */
484
+ declare function wantsDocumentChrome(spec: PageSpec | undefined): boolean;
485
+ /**
486
+ * Inject a `@page` CSS block into an HTML document's `<head>`. Placed right
487
+ * after `<head>` so author styles (later in the head) still win the cascade.
488
+ * No-op when `css` is null. Prepends a `<style>` when there's no `<head>`.
489
+ */
490
+ declare function applyPageCss(html: string, css: string | null): string;
491
+
492
+ /**
493
+ * Cover-page helpers for `document`-medium PDFs. Pure (no browser) so they're
494
+ * unit-testable; the actual render happens in {@link renderDocumentPdf}.
495
+ *
496
+ * `document.cover` is the knob:
497
+ * - a string → used verbatim as the cover HTML
498
+ * - `true` → a minimal branded cover built from the export `name`
499
+ * - omitted / `false` → no cover (TOC + page numbers still apply)
500
+ */
501
+ /** "q2-board-deck" → "Q2 Board Deck" for the auto cover title. */
502
+ declare function titleize(name: string): string;
503
+ /** A minimal branded cover page for `document.cover: true`. */
504
+ declare function autoCoverHtml(name: string, subtitle?: string): string;
505
+ /** Resolve the cover HTML from the `cover` knob (string verbatim, `true` = auto). */
506
+ declare function resolveCover(cover: string | boolean | undefined, name: string, subtitle?: string): string | undefined;
507
+
508
+ export { type CdpRendererOptions, type ChromeRenderer, type DocumentExportOptions, type DocumentOptions, type DocumentResult, type DocumentTocEntry, type ExportArtifact, type ExportCanvasInput, type ExportCanvasResult, type ExportFormat, type ExportOptions, type FetchedAsset, type HeaderFooter, type MediumDefaults, type PageOptions, type ResolveRendererOptions, type Slot, applyPageCss, autoCoverHtml, cdpChromeRenderer, exportCanvas, exportHtml, extractAssetUrls, findChrome, htmlToEmail, htmlToText, htmlToZip, localChromeRenderer, matchKey, mediumDefaults, mergePageSpec, noopFilesystem, pageCssFor, renderDocumentPdf, resolveCover, resolvePageSize, resolveRenderer, titleize, wantsDocumentChrome };