import { C as CommentThread, P as PageSetup, a as PageDimensionsTwips } from './watermark-DNRzAyyP.cjs'; interface ParsedOOXML { /** TipTap JSON document (ready for editor.setJSON()). */ json: any; /** Raw document.xml string (for selective save round-trip). */ documentXml: string; /** Styles.xml parsed as a Map. */ styles: Map; /** Document metadata from core.xml. */ metadata: DocxMetadata; /** Any parsing warnings. */ warnings: string[]; /** Comment threads from word/comments.xml, keyed to the `comment` mark ids * in `json`. Seed a `CommentsStorageAdapter` with these after import. */ commentThreads: CommentThread[]; /** Header/footer content as plain HTML paragraphs (default type only, v1). */ headerHTML?: string; footerHTML?: string; } /** * Raw `` attribute values in twips, before conversion to the editor's * px-based paragraph attrs. Kept in twips at this layer — on both a style * and a paragraph — so `resolveStyleIndent()` can hand back a style's whole * declared indentation unconverted, exactly mirroring how `ownNumId`/ * `resolveStyleNumId()` handle numbering below. */ interface IndTwips { left?: number; right?: number; firstLine?: number; hanging?: number; } interface StyleDef { styleId: string; name: string; type: 'paragraph' | 'character' | 'table' | 'numbering'; basedOn?: string; headingLevel?: number; alignment?: string; /** `w:default="1"` — Word's fallback style for runs/paragraphs of this type. */ isDefault?: boolean; /** * `w:numId` declared on this style's ``. Word lets a * paragraph style (e.g. "List Number") carry the numbering, so a clause * paragraph states only `` with no direct * `numPr` — common in legal documents. Resolved via `resolveStyleNumId()`. */ ownNumId?: string; /** * The run formatting declared directly on this style (``), * BEFORE `basedOn` inheritance is resolved. Word applies formatting through * named styles at least as often as through direct run properties, so a * faithful import has to read this — not just the run's own `` — and * fold it into the effective formatting. See `resolveStyleRunProps()`. */ ownRunProps?: RunProps; /** * `w:ind` declared directly on this style's `` — the indentation * equivalent of `ownNumId`. A legal-document paragraph style ("Clause", * "Sub-Clause") very often carries its indentation this way rather than * repeating `` on every paragraph, so resolving only a paragraph's * own direct `` would leave most of a template's indentation * unresolved. See `resolveStyleIndent()`. */ ownIndent?: IndTwips; } /** * A resolved set of character-formatting properties, in the editor's own * units (css color/px/font-stack), independent of where in the OOXML style * cascade they came from. Toggle properties (bold/italic/…) are tri-state: * `true` = on, `false` = explicitly turned off (a lower-priority "on" must * not win), `undefined` = not specified at this level (inherit). */ interface RunProps { bold?: boolean; italic?: boolean; underline?: boolean; strike?: boolean; vertAlign?: 'superscript' | 'subscript'; color?: string; fontSizePx?: string; fontFamily?: string; highlight?: string; } interface DocxMetadata { title?: string; creator?: string; created?: string; modified?: string; subject?: string; description?: string; } /** * Parse a .docx ArrayBuffer into TipTap JSON with high fidelity. * * Unlike mammoth (which converts to HTML), this parser reads the raw * OOXML XML and converts directly to TipTap's ProseMirror JSON format, * preserving all formatting attributes. * * @param buffer - .docx file as ArrayBuffer * @returns Parsed document with JSON, raw XML, styles, and metadata */ declare function parseDocxOOXML(buffer: ArrayBuffer): Promise; /** * Read just the page size/orientation/margins from a .docx's `` — * independent of (and cheaper than) full body-content parsing, so the * editor's on-screen page geometry can be restored to match what a loaded * file actually used regardless of whether `parseDocxOOXML()` or the * mammoth fallback ends up handling the body content. * * Returns `null` if the file has no readable ``/`` — * callers should leave the current page setup untouched in that case * rather than resetting it to a default. */ declare function readPageSetupFromDocx(buffer: ArrayBuffer): Promise; interface NumberingInfo { numId: string; format: 'bullet' | 'decimal' | 'lowerLetter' | 'upperLetter'; } /** * OOXML Serializer — convert TipTap JSON back to OOXML XML. * * This replaces the `docx` library (which rebuilds the entire document * from scratch) with a serializer that generates proper , , * elements. When used with selective save, only changed paragraphs * are patched into the original XML — preserving unchanged content * byte-for-byte for Word Compare compatibility. */ /** * Real image embedding requires more than XML text: the binary bytes need * to land in `word/media/*`, a relationship needs to be registered in * `word/_rels/document.xml.rels` mapping an `rId` to that media file, and * `[Content_Types].xml` needs a `Default` entry for the file extension. * `ImageCollector` gathers that side-table while `blockToXml`/`imageToXml` * walk the document, so the caller can apply it to the zip in one pass * after serialization. */ interface CollectedImage { relId: string; fileName: string; contentType: string; bytes: Uint8Array; } /** An external hyperlink target that needs an `TargetMode="External"` * relationship written alongside the images. */ interface CollectedLink { relId: string; href: string; } declare class ImageCollector { readonly images: CollectedImage[]; /** External hyperlink targets, sharing this collector's `rId` counter so * image and link relationship ids can never collide. */ readonly links: CollectedLink[]; private nextRelIdNum; private nextMediaNum; private linkRelIdByHref; constructor(startRelIdNum?: number, startMediaNum?: number); /** Register an image `src` (data URI) for embedding. Returns the `r:embed` * relationship id to reference from the drawing XML, or null if `src` * isn't something we can embed (e.g. a remote URL we can't fetch here). */ add(src: string): string | null; /** * Register an external hyperlink target. Returns the `r:id` for the * `` element. * * `` addresses its target by relationship id, so a link is only * a link if a matching entry exists in `word/_rels/document.xml.rels`. * Without this the serializer emitted a hardcoded `r:id="rIdLink"` that * resolved to nothing — Word treats an unresolvable relationship as a * damaged part and offers to repair the file. Identical hrefs share one * relationship, the way Word itself writes them. */ addLink(href: string): string; } interface SerializeOptions { /** If provided, only serialize blocks whose indices are in this set. * Others will be left unchanged in the original XML. */ changedBlockIndices?: Set; /** Collects images encountered during serialization (bytes + assigned * relationship id) so the caller can embed them into the .docx zip. * If omitted, images are serialized as `[Image: ...]` placeholder text. */ imageCollector?: ImageCollector; /** * Numbering definitions read from the *original* document's * `word/numbering.xml` (via `parseNumberingXml`). When present, bullet and * ordered lists resolve their `w:numId` to a definition that actually * exists in that document instead of hardcoding numId "1"/"2" — which * only happens to be correct by convention and can point a list at the * wrong (or a nonexistent) numbering definition otherwise. */ numberingMap?: Map; /** Reference default header/footer parts in sectPr (rel ids fixed to * match docx-package.ts's buildFreshDocxPackage). */ hasHeader?: boolean; hasFooter?: boolean; /** * Page size/margins in OOXML twips, from `resolvePageDimensionsTwips()` * (`../page-setup`). Defaults to US Letter (12240x15840 twips) with 1in * margins — matching Word's own built-in default — when omitted. */ pageDimensions?: PageDimensionsTwips; } interface SerializeResult { /** Full XML string (for full document replacement). */ bodyXml: string; /** Array of { index, xml } for individual changed paragraphs (for selective patching). */ changedParagraphs: Array<{ index: number; xml: string; }>; } /** * Convert TipTap JSON to OOXML XML. * * @param json - TipTap document JSON * @param options - Serialization options * @returns XML string + per-paragraph XML for selective patching */ declare function serializeTipTapToOOXML(json: any, options?: SerializeOptions): SerializeResult; /** * Patch only the changed elements in the original document.xml. * * This finds all and elements in the original XML, * replaces the ones at the given indices with the new XML, and * preserves everything else byte-for-byte. * * @param originalXml - The original word/document.xml string * @param changedParagraphs - Array of { index, xml } from serializeTipTapToOOXML * @returns Patched document.xml string */ declare function patchDocumentXml(originalXml: string, changedParagraphs: Array<{ index: number; xml: string; }>): string; /** * Patch specific files in a .docx ZIP archive without rebuilding everything. * * @param docxBuffer - Original .docx as ArrayBuffer * @param patches - Map of { filePath: newContent } (string or ArrayBuffer) * @returns New .docx ArrayBuffer with patched files */ declare function rezipDocx(docxBuffer: ArrayBuffer, patches: Map): Promise; /** * Save TipTap JSON to a .docx ArrayBuffer with selective XML patching. * * If originalBuffer is provided, only changed paragraphs are patched into * the original XML — preserving unchanged content byte-for-byte. * If originalBuffer is not provided, a full document is generated. * * @param json - TipTap document JSON * @param originalBuffer - Original .docx ArrayBuffer (for selective patching) * @param changedBlockIndices - Set of block indices that changed (for selective patching) * @param pageDimensions - Page size/margins in twips, from `resolvePageDimensionsTwips()` * (`../page-setup`). Applied to the "full save" branch below (replacing * `document.xml`'s ``) and to the no-`originalBuffer` fresh-build * branch. Defaults to US Letter when omitted. * @returns .docx ArrayBuffer */ declare function saveDocxSelective(json: any, originalBuffer?: ArrayBuffer, changedBlockIndices?: Set, pageDimensions?: PageDimensionsTwips): Promise; /** * Docxtemplater plugin — template variable substitution for .docx files. * * Supports the docxtemplater syntax: * - {variable} — simple variable substitution * - {#loop}...{/loop} — repeat content for each item in an array * - {#cond}...{/cond} — conditional inclusion (truthy = show) * - {-w:image} — image substitution (with base64 data) * * All formatting (fonts, styles, colors, tables) is preserved because * docxtemplater operates on the raw OOXML XML, not on rendered HTML. * * Usage: * import { processTemplate } from '@shashimadushan/docx-editor-editor/headless'; * * const result = processTemplate(docxBuffer, { * name: 'John Doe', * date: '2026-01-15', * items: [{ name: 'Item 1' }, { name: 'Item 2' }], * }); * // result.buffer = processed .docx ArrayBuffer * * Can be used server-side (no DOM required). */ interface ProcessTemplateOptions { /** How to handle undefined variables: 'keep' (leave tag as-is), 'empty' (remove), 'error' (throw). Default: 'keep'. */ nullGetter?: 'keep' | 'empty' | 'error'; /** Convert \n in values to (Word line breaks). Default: true. */ linebreaks?: boolean; /** Custom delimiters (default: { and }). */ delimiters?: { start?: string; end?: string; }; } interface ProcessTemplateResult { /** The processed document buffer. */ buffer: ArrayBuffer; /** Variables that were found and replaced. */ replacedVariables: string[]; /** Variables that were not replaced (no value provided). */ unreplacedVariables: string[]; /** Any warnings during processing. */ warnings: string[]; } interface TemplateError { message: string; variable?: string; type: 'parse' | 'render' | 'undefined' | 'unknown'; originalError?: Error; } interface TemplateValidation { valid: boolean; errors: TemplateError[]; tags: string[]; } /** * Process a DOCX template with variable substitution. * * @param buffer - The DOCX file as ArrayBuffer * @param variables - Map of variable names to values (strings, arrays, or nested objects) * @param options - Processing options * @returns Processed DOCX as ArrayBuffer */ declare function processTemplate(buffer: ArrayBuffer, variables: Record, options?: ProcessTemplateOptions): Promise; /** * Process template and return as Blob (for download). */ declare function processTemplateAsBlob(buffer: ArrayBuffer, variables: Record, options?: ProcessTemplateOptions): Promise; /** * Process template and trigger browser download. */ declare function processTemplateAndDownload(buffer: ArrayBuffer, variables: Record, filename?: string, options?: ProcessTemplateOptions): Promise; /** * Get all template tags in a document without processing. */ declare function getTemplateTags(buffer: ArrayBuffer): Promise; /** * Validate that a document is a valid docxtemplater template. */ declare function validateTemplate(buffer: ArrayBuffer): Promise; /** * Check which required variables are missing. */ declare function getMissingVariables(tags: string[], variables: Record): string[]; /** * Preview the document text with variables replaced (no formatting). */ declare function previewTemplate(buffer: ArrayBuffer, variables: Record): Promise; export { type DocxMetadata as D, type ParsedOOXML as P, type SerializeOptions as S, type TemplateError as T, type ProcessTemplateOptions as a, type ProcessTemplateResult as b, type SerializeResult as c, type StyleDef as d, patchDocumentXml as e, previewTemplate as f, getTemplateTags as g, processTemplate as h, rezipDocx as i, serializeTipTapToOOXML as j, type TemplateValidation as k, getMissingVariables as l, processTemplateAndDownload as m, processTemplateAsBlob as n, parseDocxOOXML as p, readPageSetupFromDocx as r, saveDocxSelective as s, validateTemplate as v };