/** * DOCX Incremental Edit API * * Supports efficient "open → modify → save" workflows by editing a DOCX * file at the ZIP entry level. * * Use cases: * - Replace just the document.xml in an existing template * - Update headers/footers without touching styles or images * - Patch specific parts (e.g. core properties metadata) * * **Limitations and caveats — read before using `replacePart`/`deletePart`:** * * This API is a thin wrapper around ZIP entry mutation. It deliberately * does not understand DOCX semantics: * * - `[Content_Types].xml` is **not** updated when you add a new part with * a previously-unseen content type. If your replacement part introduces * a new MIME type, callers must also patch `[Content_Types].xml` (or * round-trip through `readDocx` + `packageDocx` instead). * - Relationship files (`*.rels`) are **not** rebuilt. Adding or deleting * a part with relationships will leave the corresponding `_rels/*.rels` * stale. * - `replaceBody`, `replaceHeader`, `replaceFooter` only rewrite their * target XML part; they do **not** modify the corresponding `.rels` file * or copy in new media binaries. As a result they reject content that * would introduce new relationship IDs (images, hyperlinks, charts, * altChunks, opaque drawings carrying rIds) — use `patchDocument` / * `packageDocx` for those cases. Existing references that survive * unchanged are fine because their `.rels` entries already exist. * * For DOCX-aware edits (changes that may add/remove relationships or * content types) use `patchDocument` or `compileTemplate`, or round-trip * through `readDocx` + `packageDocx`. * * Note: This API operates on raw ZIP entries; it does not parse the DOCX * model. For higher-level edits use `patchDocument` or `compileTemplate`. */ import type { BodyContent, Paragraph, Table } from "./types.js"; /** A single incremental edit operation. */ export type IncrementalEdit = { /** * Replace a specific part by raw bytes. * * Caveat: does not update `[Content_Types].xml` or any `.rels` file. * Adding a part with a new content type or new relationships will * produce a malformed package. See the file header for details. */ readonly type: "replacePart"; readonly path: string; readonly data: Uint8Array; } | { /** Replace a part with a string (UTF-8 encoded). Same caveats as `replacePart`. */ readonly type: "replacePartText"; readonly path: string; readonly text: string; } | { /** * Delete a specific part. * * Caveat: does not update `[Content_Types].xml` or any `.rels` file. * Deleting a part that other parts reference (via rels or other XML) * will leave dangling references — round-trip through readDocx + * packageDocx if you need a consistent package. */ readonly type: "deletePart"; readonly path: string; } | { /** Replace the body content of `word/document.xml`. */ readonly type: "replaceBody"; readonly body: readonly BodyContent[]; } | { /** Replace a header part identified by path (e.g. `word/header1.xml`). */ readonly type: "replaceHeader"; readonly path: string; readonly children: readonly (Paragraph | Table)[]; } | { /** Replace a footer part identified by path (e.g. `word/footer1.xml`). */ readonly type: "replaceFooter"; readonly path: string; readonly children: readonly (Paragraph | Table)[]; }; /** Options for incremental editing. */ export interface IncrementalEditOptions { /** Compression level for replaced entries (0-9). Default: 6. */ readonly compressionLevel?: number; } /** * Apply incremental edits to an existing DOCX file. * * Reads all parts from the original ZIP, applies the edits, and writes a * new ZIP. Unchanged parts are passed through (decompressed and recompressed, * but their content is not parsed). * * @param buffer - The original DOCX file as a Uint8Array. * @param edits - Array of incremental edits to apply. * @param options - Optional settings. * @returns A new DOCX file as a Uint8Array. * * @example * ```ts * const original = await fs.readFile("template.docx"); * const edited = await editDocxIncremental(original, [ * { type: "replaceBody", body: [...newParagraphs] } * ]); * ``` */ export declare function editDocxIncremental(buffer: Uint8Array, edits: readonly IncrementalEdit[], options?: IncrementalEditOptions): Promise; /** * List all part paths in a DOCX file without parsing the model. * * @param buffer - The DOCX file as a Uint8Array. * @returns Array of part paths. */ export declare function listDocxParts(buffer: Uint8Array): Promise; /** * Read a single part's raw bytes from a DOCX file. * * @param buffer - The DOCX file as a Uint8Array. * @param path - The part path (e.g. `"word/document.xml"`). * @returns The part's raw bytes, or undefined if the part doesn't exist. */ export declare function readDocxPart(buffer: Uint8Array, path: string): Promise;