/** * DOCX Module - Document IO * * IO operations: package/unpackage to bytes, base64, Flat OPC, * plus the public Patch and Template APIs that combine read/patch/write. */ import { type PatchOperation } from "./patcher.js"; import type { TemplateOptions } from "./template/template-engine.js"; import type { DocxDocument } from "./types.js"; export type { PatchContent, PatchOperation } from "./patcher.js"; /** Package a DocxDocument model to DOCX bytes. */ export declare function toBuffer(doc: DocxDocument, compressionLevel?: number): Promise; /** Package a DocxDocument model to base64 string. */ export declare function toBase64(doc: DocxDocument, compressionLevel?: number): Promise; /** Options for patchDocument. */ export interface PatchOptions { /** Compression level (0-9). Default: 6. */ readonly compressionLevel?: number; } /** A compiled template that can be reused for multiple patch operations. */ export interface CompiledTemplate { /** The parsed document model (internal use only). */ readonly _doc: DocxDocument; } /** * Compile a DOCX template for reuse with multiple data sets. * * Parsing the ZIP and XML is expensive. If you need to patch the same template * multiple times with different data, compile it once and reuse. * * @param buffer - The source DOCX template file as a Uint8Array. * @returns A compiled template handle. */ export declare function compileTemplate(buffer: Uint8Array): Promise; /** * Apply patches to a pre-compiled template. * * Much faster than `patchDocument` when applying to the same template repeatedly, * since ZIP/XML parsing is skipped. * * @param template - A compiled template from `compileTemplate`. * @param patches - Array of patch operations to apply. * @param options - Optional compression settings. * @returns New DOCX file as a Uint8Array. */ export declare function patchTemplate(template: CompiledTemplate, patches: readonly PatchOperation[], options?: PatchOptions): Promise; /** * Read an existing DOCX file, replace placeholders with content, and produce a new DOCX. * * Placeholders are strings like `{{name}}` embedded in the document text. * They may span across multiple runs — the patcher handles cross-run matching. * * Supported patch content types: * - `text` — simple text replacement (preserves formatting of the first run) * - `paragraph` — replaces the entire paragraph containing the placeholder * - `table` — replaces the entire paragraph with a table * - `image` — replaces the placeholder with an inline image * * @param buffer - The source DOCX file as a Uint8Array. * @param patches - Array of patch operations to apply. * @param options - Optional compression settings. * @returns New DOCX file as a Uint8Array. */ export declare function patchDocument(buffer: Uint8Array, patches: readonly PatchOperation[], options?: PatchOptions): Promise; /** * Read a DOCX buffer, fill template placeholders with data, and produce a new DOCX. * * This is a convenience wrapper combining readDocx + fillTemplate + packageDocx. * * @param buffer - The source DOCX template file as a Uint8Array. * @param data - Data object to fill into the template placeholders. * @param options - Template and compression options. * @returns New DOCX file as a Uint8Array. */ export declare function fillTemplateFromBuffer(buffer: Uint8Array, data: Record, options?: TemplateOptions & { readonly compressionLevel?: number; }): Promise; /** * Package a DocxDocument model into Flat OPC XML format. * * This packages the document to a ZIP, then re-reads the entries to wrap * them as Flat OPC XML. While this involves a ZIP round-trip, it ensures * the Flat OPC output is byte-identical to what `packageDocx` would produce * (same XML serialization, same relationships, same content types). * * @param doc - The document model. * @param compressionLevel - Optional compression level (0 = no compression, faster for Flat OPC). * @returns The Flat OPC XML string. */ export declare function toFlatOpcFromDoc(doc: DocxDocument, compressionLevel?: number): Promise;