import type { PdfSpecNode } from './pdfSpec.cjs'; import type { TextState } from './textStyle.cjs'; /** * Why content was left out or approximated: * - `tool`: a content type with no PDF exporter (custom tools without one); * - `exporterError`: a PDF exporter threw; * - `element`: an element inside text the subset does not draw (images, * tables, form fields); * - `textNode`: a Lexical node type the subset does not know; * - `style`: CSS properties or list styles the subset does not draw; * - `entity`: a character reference in text the subset does not decode, printed * as written (HTML prints an unknown name that way too); * - `background`: background images sized in units the PDF spec cannot * take (em, vw), drawn at their own size, or repeated in another way * (space, round); * - `direction`: right-to-left text; * - `condition`: display conditions and merge-tag rules, written around the * HTML for the embedder's template engine; * - `version`: the design was saved at an older schema version than the one * designToPdfSpec reads (migrate it first, for example by loading and saving it * in the editor); * - `invalid`: a part of the design without the shape designs have (a list * that is not one, an entry that is not an object, a content without a * type). */ export type UnsupportedCode = 'version' | 'invalid' | 'tool' | 'exporterError' | 'element' | 'textNode' | 'style' | 'entity' | 'background' | 'direction' | 'condition'; export type Report = (code: UnsupportedCode, detail: string) => void; /** * Where a tool's content is drawn, as the exported document lays it out. * Widths are CSS pixels of the editor canvas (the PDF converts to points). */ export interface PdfToolContext { /** Width of the content box, inside the content's padding. */ widthPx: number; /** Text inherited from the body: font, 15px, color, `line-height: normal`. */ text: TextState; /** How links look without their own style. */ link: { color?: string; underline: boolean; }; /** The content's element id (`u_content__`), used for unit keys. */ htmlId: string; /** In a single-column row (units go on contents and table rows). */ singleColumn: boolean; /** In the header or footer band: not paginated, no units or breaks. */ inBand: boolean; /** Where the tools' own images live (social icons). */ cdnBaseUrl: string; /** The design values the exporters read besides the tool's own. */ design: { body: Record; row: { values: Record; cells: number[]; }; column: { values: Record; index: number; }; }; /** Records content that was left out or approximated. */ report: Report; } /** * A tool's PDF exporter: the PDF spec nodes drawn inside its content box, from the * tool's values. The builder's tool folders each have one (`pdf.ts`, next to * `exporters.ts`); custom tools may provide one. */ export type PdfItemExporter> = (values: Values, context: PdfToolContext) => PdfSpecNode[]; export interface PdfItemExporters { pdf: PdfItemExporter; }