/** * Print-preview layout for the printouts on a rendered page. * * A worksheet or handout is written to be printed and handed out, and PreTeXt * lays one out very differently on paper than on screen: paginated to the * chosen paper size, headers and footers on each sheet, solutions dropped, and * — the part that is impossible to judge from the ordinary view — every * `` grown to the height the author asked for, so the blank space a * student writes in is actually shown. An author editing a worksheet wants to * see *that*, not the web version of it. * * ## How the built page does it, and why the preview cannot * * All of it is client-side, in pretext-core.js, and the entire entry point is a * URL query parameter: `?printpreview=`. On DOMContentLoaded the * script swaps the theme stylesheet for `print-worksheet.css`, moves the named * printout to be the page's only content, flattens its knowls, and paginates * it. Upstream's print icon on a printout heading is nothing more than a link * to that URL. * * A preview has no such URL. It is rendered in memory and handed to a host — a * VS Code webview, an iframe on pretext.plus — so there is no page to reload * and no query string of ours to put the parameter in; the link is disabled in * the preview wrapper for exactly that reason (see PRINTOUT_LINK_OVERRIDE in * scripts/refresh-xsl.mjs). What this module does is supply the parameter * without the navigation: {@link injectPrintPreview} adds a small script that * makes `new URLSearchParams(window.location.search)` — the one and only place * pretext-core.js looks — report a `printpreview` parameter that is not in the * URL at all. * * Rewriting the URL itself would be the obvious alternative and does not work * here: `history.replaceState` throws in a document whose origin cannot own a * new URL (a `vscode-webview://` page, an `about:blank` document written into * in place), and on a host like pretext.plus it would corrupt the app's own * address. Patching the reader is inert by comparison — it adds a parameter to * one particular string and touches nothing else. * * ## Switching in and out * * By re-delivering the page, not by talking to a live one, exactly as the * slideshow view toggle does (see reveal.ts). pretext-core.js runs the whole * transformation once, from a DOMContentLoaded handler, and it is thoroughly * destructive — sections are removed from the DOM, knowls are flattened, * `
` become `
`s. There is no undo. Since the embedder already * holds the rendered HTML, leaving print preview means re-injecting the *off* * state into that pristine HTML and delivering it again; a fresh document * (whether from a reload or an in-place `document.write`) fires * DOMContentLoaded again and the page comes up in the other mode. No re-render. * * Injecting the off state matters as much as injecting the on state: a * `document.write` rebuild reuses the same `Window`, so a patch installed by an * earlier delivery is still in place. The script therefore keeps the wanted id * in a window property it re-reads on every call, and the off state clears it. */ /** A printout on a rendered page: a division the reader can lay out for print. */ export interface PrintoutInfo { /** * The printout element's HTML id — what `?printpreview=` names, and what * {@link injectPrintPreview} takes. */ id: string; /** Localized division type: "Worksheet", "Handout", "Project", … */ type: string; /** The printout's number as printed ("2.3"), or "" when it has none. */ number: string; /** The printout's title as plain text, or "" when it is untitled. */ title: string; /** * The three above composed into one line — "Worksheet 2.3: Counting" — for * an embedder that just wants to put the page's printouts in a menu. */ label: string; } /** * The printouts on a rendered page, in document order. * * Empty for a page with none, which is the signal an embedder wants: with no * printouts there is nothing to offer, and — because PreTeXt only emits the * paper-size and print-options controls on a page that has one — no print * preview to be had either. */ export declare function listPrintouts(html: string): PrintoutInfo[]; /** * The printout to open in print preview when a document is *itself* a printout * — the case of previewing `worksheet-3.ptx`, whose root element is the * ``. Nothing else in the file competes for the reader's attention, * so the paper layout is what they came to see. * * `rootElement` is the document's root element name **before** any fragment * wrapping: a lone worksheet is rendered inside a synthesized `
`, and * by the time the page exists that is all the HTML can say. The printout is the * page's first, since the wrapper holds nothing else. * * Undefined for a document that merely contains printouts — a chapter with * three worksheets in it should open as the chapter. */ export declare function rootPrintoutId(printouts: PrintoutInfo[], rootElement: string | undefined): string | undefined; /** * Window property holding the id the patched reader should report. Read on * every call rather than captured, so re-injecting into a document that shares * a `Window` with an earlier one (an in-place `document.write` rebuild) changes * the answer instead of piling a second patch on the first. */ export declare const PRINT_PREVIEW_GLOBAL = "__ptxPrintPreview"; /** * The inline `