/** * DOCX Module - Patcher * * Internal logic for replacing placeholders (e.g. `{{name}}`) in a DocxDocument * with text, paragraphs, tables, or images. Used by `patchDocument` and * `patchTemplate` in document-io.ts. * * Public API is exposed through document-io.ts; this file contains the * pure patch logic (no IO). * * Container coverage: the patcher walks every container that may carry * paragraphs — body, headers/footers, footnotes/endnotes, table cells * (including nested tables), structured-document tags (block & inline), * text boxes, drawing shape text bodies, and the cached paragraphs of a * Table of Contents. Anything paragraph-shaped is run through * `patchParagraph`, so a placeholder is matched the same way regardless * of which container holds it. */ import type { DocxDocument, ImageDef, Paragraph, Table } from "./types.js"; /** Type of content to patch into a placeholder. */ export type PatchContent = { readonly type: "text"; readonly text: string; } | { readonly type: "paragraph"; readonly children: readonly Paragraph[]; } | { readonly type: "table"; readonly table: Table; } | { readonly type: "image"; readonly image: ImageDef; readonly width: number; readonly height: number; }; /** A single patch operation mapping a placeholder to replacement content. */ export interface PatchOperation { /** Placeholder string to find (e.g. "{{name}}"). */ readonly placeholder: string; /** Content to replace the placeholder with. */ readonly content: PatchContent; } /** * Apply patches to a parsed document model. * * Returns a NEW {@link DocxDocument} with a fresh `body` array and a new * `images` array. However, the inner content reachable from * `headers` / `footers` / `footnotes` / `endnotes` and from non-replaced * paragraphs/tables is mutated in place: text replacements rewrite the * existing `Paragraph.children[].content[].text`, table rows/cells are * patched in place, etc. * * **Practical consequence**: do not keep using the input `doc` after calling * this function — its inner state has been modified. Always use the return * value. Concurrent use of the input `doc` from another thread/path is not * supported. * * @param doc - The document model. Internal arrays/objects will be mutated. * @param patches - Patches to apply. * @returns A new {@link DocxDocument} reference with patches applied. */ export declare function applyPatchesToDocument(doc: DocxDocument, patches: readonly PatchOperation[]): DocxDocument;