import { PdfRef } from './objects.js'; import { PdfDocument } from './writer.js'; /** * Standard structure types (ISO 32000-1 Table 333/337). Every type here is * recognised without a `/RoleMap`, so the builder never emits one. */ export type StructType = 'Document' | 'Part' | 'Sect' | 'H1' | 'H2' | 'H3' | 'H4' | 'H5' | 'H6' | 'P' | 'L' | 'LI' | 'Lbl' | 'LBody' | 'Table' | 'TR' | 'TH' | 'TD' | 'Caption' | 'Figure' | 'Link' | 'Note' | 'Span'; interface Mcref { readonly pageIndex: number; readonly mcid: number; } /** One node in the logical structure tree: a {@link StructType} plus its children, marked-content and attributes. */ export declare class StructNode { readonly id: number; type: StructType; readonly children: Array; readonly mcrefs: Array; /** * §14.7.4.3 object references (`/OBJR` kids) — e.g. a Link element pointing at * its link annotation. The annotation's own `/StructParent` entry is recorded * via {@link StructTreeBuilder.addAnnotParent}. */ readonly objrs: Array<{ readonly annotRef: PdfRef; readonly pageIndex: number; }>; parent: StructNode | null; ref: PdfRef | null; /** Alternate text (`/Alt`, §14.9.4) — required on Figure for PDF/A-1a. */ alt: string | null; /** Natural language (`/Lang`) when it differs from the document default. */ lang: string | null; /** * §14.8.5.2 Table attribute (emitted via a `/A` attribute object on the cell): * `/Scope` on a TH (Row/Column) so assistive tech binds headers to data cells. */ scope: 'Row' | 'Column' | null; /** §14.8.5.2 — `/ColSpan` when the cell spans more than one column (gridSpan). */ colSpan: number | null; /** §14.8.5.2 — `/RowSpan` when the cell spans more than one row (vertical merge). */ rowSpan: number | null; /** * @param id The node's index, used for deterministic id assignment and `/ID`. * @param type The structure type (mutable, so the renderer can retag). */ constructor(id: number, type: StructType); } /** * Builds the tagged-PDF logical structure tree (ISO 32000-1 §14.7–14.8): a * `/StructTreeRoot` over a tree of {@link StructNode}s, tied back to page * marked-content via MCRs and the `/ParentTree`. A generic emitter — the * structure-type mapping policy lives in the renderer. Object ids are assigned by * a deterministic pre-order DFS so identical input yields byte-identical output. */ export declare class StructTreeBuilder { private readonly nodes; /** The root logical element (the single `/Document` under `/StructTreeRoot`). */ readonly root: StructNode; constructor(); /** * Create a node of `type` as the last child of `parent`. * * @param parent The parent node, or `null` for a free node (only the root is * created that way). * @returns The new node. */ create(type: StructType, parent: StructNode | null): StructNode; /** * Look up a node by its id. * * @throws Error if no node has that id. */ node(id: number): StructNode; /** * Record that marked content `mcid` on page `pageIndex` is the content of node * `nodeId`. Called from the emit phase as MCIDs are assigned. */ addMcref(nodeId: number, pageIndex: number, mcid: number): void; /** * §14.7.4.4: an annotation's `/StructParent` key maps DIRECTLY to its owning * `/StructElem` in the parent tree (a scalar entry, unlike the per-page MCID * arrays). The emit phase allocates keys above the page indices. */ private readonly annotParents; /** * Register that annotation parent-tree key `key` resolves to node `nodeId`. * * @see StructTreeBuilder.annotParents */ addAnnotParent(key: number, nodeId: number): void; /** * Emit the `/StructTreeRoot`, every `/StructElem`, and the `/ParentTree`. Must * run after all pages are added (so `pageRefs` is complete) and after every * {@link StructTreeBuilder.addMcref} call. * * @param pageRefs The page object references, indexed by page number. * @returns A reference to the `/StructTreeRoot`, for the catalog. */ emit(doc: PdfDocument, pageRefs: ReadonlyArray): PdfRef; } export {};