import { D as DocxEditorExtension } from './editor-BpyLLFVy.cjs'; export { C as CommentAnchor, a as CommentMark, b as CommentsCore, c as CursorContext, d as DocxEditor, e as DocxEditorExportSnapshot, f as DocxEditorOptions, g as DocxEditorTheme, E as EditorMode, h as ExtensionContext, i as ExtensionRegistry, H as HeaderFooterConfig, j as HistoryCheckpointMeta, k as HistoryEntry, l as HistoryEntryMeta, m as HistorySource, n as HistoryStorageAdapter, S as SINHALA_FONT_STACK, o as SaveDocxOptions, p as SlashCommand, T as TAMIL_FONT_STACK, q as ToolbarButton, V as ViewMode, r as defaultTheme, s as formatCursorContext, t as hasComments, u as listCommentAnchors, v as saveDocxFromJSON, w as themeToCSSVars } from './editor-BpyLLFVy.cjs'; export { b as CommentMentionUser, c as CommentMessage, C as CommentThread, d as CommentsHostCommand, e as CommentsHostViewState, f as CommentsStorageAdapter, D as DEFAULT_PAGE_SETUP, g as DEFAULT_WATERMARK, h as DEFAULT_WATERMARK_PRESETS, i as PAGE_SIZE_PRESETS, a as PageDimensionsTwips, P as PageSetup, j as PageSizePreset, W as WatermarkConfig, k as createWatermarkElement, m as mmToPx, p as pageSetupFromTwips, l as pxToMm, r as resolvePageDimensions, n as resolvePageDimensionsTwips } from './watermark-DNRzAyyP.cjs'; import * as _tiptap_core from '@tiptap/core'; import { Extension, Node, Mark, Editor } from '@tiptap/core'; import * as _tiptap_extension_image from '@tiptap/extension-image'; import * as _tiptap_extension_table_header from '@tiptap/extension-table-header'; import * as _tiptap_extension_table_cell from '@tiptap/extension-table-cell'; import * as _tiptap_extension_table_row from '@tiptap/extension-table-row'; import * as _tiptap_extension_table from '@tiptap/extension-table'; export { D as DocxMetadata, P as ParsedOOXML, a as ProcessTemplateOptions, b as ProcessTemplateResult, S as SerializeOptions, c as SerializeResult, d as StyleDef, T as TemplateError, k as TemplateValidation, l as getMissingVariables, g as getTemplateTags, p as parseDocxOOXML, e as patchDocumentXml, f as previewTemplate, h as processTemplate, m as processTemplateAndDownload, n as processTemplateAsBlob, r as readPageSetupFromDocx, i as rezipDocx, s as saveDocxSelective, j as serializeTipTapToOOXML, v as validateTemplate } from './template-C57bJmsi.cjs'; import '@tiptap/pm/model'; import './diff.cjs'; /** * Pure, DOM-free helpers for describing WHAT a TipTap/ProseMirror JSON block * is (title? bullet? quote?) and for rendering its text with inline marks * (bold/italic/underline/...) made visible as lightweight markdown-like * syntax. * * Why this exists * ---------------- * The agent used to be fed the plain text before/after the cursor and a * block *index*, but nothing about the block's *type* or the *marks* on the * text around the caret — so it could not tell a heading from a bulleted * item from bold body text, and would guess (usually wrong) when the user * said things like "make this a title" or "match the formatting here". * * These are plain functions over TipTap JSON (the same shape every tool in * `packages/agent/src/tools` already reads via `ctx.doc`), not raw * ProseMirror `Node` instances — so they work identically whether called * from the live editor (`editor.getJSON()`) or from a hand-built JSON doc in * a test, and can be shared verbatim between `DocxEditor.getCursorContext()` * (this package) and the agent's inspection tools (`packages/agent`) * instead of each maintaining its own copy. */ /** Mark names `annotateNode`/`getCursorContext` know how to surface. */ declare const KNOWN_MARK_NAMES: readonly ["bold", "italic", "underline", "strike", "code", "highlight", "subscript", "superscript", "link"]; /** * Human-readable label for a block's type — what an agent should say when * asked "what is this block?" ("heading level 2", "bulleted list item", * ...) rather than a bare schema name like `"heading"`. */ declare function describeBlockType(node: any): string; /** The block's paragraph-level alignment attr, if any set. */ declare function getBlockAlignment(node: any): string | undefined; /** * Render a JSON node's text with inline marks made visible as lightweight * markdown-like syntax, plus structural prefixes for headings/lists/quotes/ * code — the same information a sighted user gets for free from the * rendered page, collapsed into a single annotated string an LLM can read. * * Examples: * heading level 2 "Summary" -> "## Summary" * paragraph with a bold word -> "This is **important**." * bulleted list of 2 items -> "- first\n- second" * blockquote -> "> quoted text" */ declare function annotateNode(node: any): string; /** * The default set of TipTap extensions used by DocxEditor. * * NOTE: We intentionally use a permissive `any[]` return type here because * TipTap's Extension/Node/Mark are structurally distinct in TypeScript, even * though they're all valid `extensions` array entries at runtime. */ declare function defaultTipTapExtensions(): any[]; /** * Common font families offered in the toolbar font picker. This drives * `@tiptap/extension-font-family` (registered below), which applies a * `font-family` inline style to the current selection via the `TextStyle` * mark — independent of `DocxEditorTheme.fontFamily` (the whole-document * default; see `theme.ts`'s `SINHALA_FONT_STACK`/`TAMIL_FONT_STACK`). Use * the theme for an all-Sinhala/all-Tamil document; use this picker to mix * scripts within one document (e.g. an English deed with a Sinhala clause). */ declare const COMMON_FONT_FAMILIES: Array<{ label: string; value: string; }>; /** Common font sizes (in pt) offered in the toolbar font size picker. */ declare const COMMON_FONT_SIZES: number[]; /** * Builtin extensions contributed by the editor itself. * Each one is a small, focused DocxEditorExtension that: * - registers the TipTap node/mark (already in defaultTipTapExtensions), AND * - contributes toolbar buttons + slash commands for that feature. * * Users can replace any of these by registering their own extension with the * same id AFTER the builtins (the registry throws on duplicates, so they * should instead create the editor with `disableBuiltins: ['bold', ...]`). */ declare const boldExtension: DocxEditorExtension; declare const italicExtension: DocxEditorExtension; declare const underlineExtension: DocxEditorExtension; declare const strikeExtension: DocxEditorExtension; declare const highlightExtension: DocxEditorExtension; declare const headingExtension: DocxEditorExtension; declare const listExtension: DocxEditorExtension; declare const alignmentExtension: DocxEditorExtension; declare const codeBlockExtension: DocxEditorExtension; declare const blockquoteExtension: DocxEditorExtension; declare const horizontalRuleExtension: DocxEditorExtension; declare const tableExtension: DocxEditorExtension; declare const imageExtension: DocxEditorExtension; declare const linkExtension: DocxEditorExtension; /** * The full list of builtin DocxEditorExtensions. * Used by default; users can disable any subset via `disableBuiltins`. */ declare const builtinExtensions: DocxEditorExtension[]; declare const builtinExtensionIds: string[]; /** * Minimal FontSize TipTap extension. * * TipTap v2 doesn't ship @tiptap/extension-font-size (it was added in v3). * We implement it ourselves as a TextStyle-based mark that stores the * font size as an attribute and applies it via inline `style="font-size: ..."`. * * This pairs with @tiptap/extension-text-style (already installed) — when * TextStyle is present, our FontSize mark piggybacks on the same . */ interface FontSizeOptions { types: string[]; } declare const FontSize: Extension; /** * PageBreak — a TipTap node that renders a real page-separation gap, * without labelling itself as an editing artifact (no "Page Break" text). * * Features: * - Renders as a clean gap between two simulated pages, sized dynamically * by `DocxEditor._layoutPagination()` (see editor.ts + editor.css). * - Insert via toolbar button, Ctrl+Enter, or "Add new page" button. * - Backspace/Delete right next to it move the cursor across the * boundary onto the adjacent page instead of deleting it — the break * (and the page it creates) is only removed by an explicit click on * the gap band (with a confirm dialog) or via `deletePageBreak()` on * an explicit node selection. * - Atom node (not editable inline, but selectable + deletable as a unit). * * On save, the .docx serializer converts this node into a paragraph with * `pageBreakBefore: true`. */ interface PageBreakOptions { HTMLAttributes: Record; } declare module '@tiptap/core' { interface Commands { pageBreak: { /** Insert a page break at the current cursor position. */ insertPageBreak: () => ReturnType; /** Delete the page break node that is currently selected. */ deletePageBreak: () => ReturnType; }; } } declare const PageBreak: Node; type ImageAlignment = 'inline' | 'left' | 'center' | 'right'; type ImageWrap = 'none' | 'left' | 'right'; declare module '@tiptap/core' { interface Commands { docxImage: { setImageAlignment: (alignment: ImageAlignment) => ReturnType; setImageSize: (width: string, height?: string) => ReturnType; setImageWrap: (wrap: ImageWrap) => ReturnType; }; } } declare const DocxImage: _tiptap_core.Node<_tiptap_extension_image.ImageOptions, any>; /** * Text layout extensions: * - TextTransform: uppercase / lowercase / capitalize / none (mark) * - LetterSpacing: CSS letter-spacing on text (mark, via TextStyle) * - LineHeight: paragraph attribute for line-height * * These cover the "font supports" the user asked for — beyond just * family + size, Word also exposes text-transform, letter spacing, * and line spacing. */ type TextTransformValue = 'none' | 'uppercase' | 'lowercase' | 'capitalize'; declare module '@tiptap/core' { interface Commands { textTransform: { setTextTransform: (transform: TextTransformValue) => ReturnType; unsetTextTransform: () => ReturnType; }; letterSpacing: { setLetterSpacing: (spacing: string) => ReturnType; unsetLetterSpacing: () => ReturnType; }; lineHeight: { setLineHeight: (lineHeight: string) => ReturnType; unsetLineHeight: () => ReturnType; }; } } declare const TextTransform: Mark; declare const LetterSpacing: Extension; declare const LineHeight: Extension; /** * LegalBlock — a paragraph-level attribute (not a new node type) that tags a * paragraph as a structural element of a Sri Lankan legal document: a * witness signature line, a notarial attestation clause, a District Court * case caption line, a signature line, or a numbered pleading paragraph. * * Deliberately implemented as an attribute on the existing `paragraph` node * (same pattern as `LineHeight` in `text-layout.ts`) rather than a brand-new * atom node type: * - It inherits paragraph's existing OOXML save/load round-trip for free — * `ooxml-serializer.ts` dispatches purely on `node.type` ('paragraph'), * so an extra `data-legal-block` attribute is simply carried along * unrecognized by anything that doesn't care about it (no crash risk), * while text formatting (bold/underline/alignment) on the paragraph * still exports normally. * - It stays fully editable text (unlike an atom node), which is what a * lawyer actually wants: they need to type over the witness/notary * placeholder lines, not treat them as an uneditable block. * - The templates in `@shashimadushan/docx-editor-legal-templates` render as plain * paragraphs today; `applyLegalBlockStyles()` below can be run over a * freshly-inserted template's paragraphs to tag the witness/attestation/ * signature lines so they get the distinct visual treatment defined in * `editor.css` (`.docx-editor [data-legal-block]`). */ type LegalBlockType = 'case-caption' | 'witness-line' | 'attestation' | 'signature-line' | 'numbered-clause'; declare module '@tiptap/core' { interface Commands { legalBlock: { /** Tag the current paragraph as a legal structural block. */ setLegalBlock: (type: LegalBlockType) => ReturnType; /** Remove the legal-block tag from the current paragraph. */ unsetLegalBlock: () => ReturnType; }; } } declare const LegalBlock: Extension; /** * Heuristically tag the witness/attestation/signature lines produced by * `@shashimadushan/docx-editor-legal-templates`' `witnessBlock()` / `caseCaption()` * builders, so they pick up the CSS treatment in `editor.css` right after a * template is inserted. Matches on the literal boilerplate text those * builders emit — safe to run on any document (paragraphs that don't match * are left untouched) and idempotent (re-running just re-applies the same * tags). * * @param doc - A TipTap JSON document (`{ type: 'doc', content: [...] }`) or * a bare array of top-level block nodes. * @returns A new document/array with `legalBlock` attrs applied — does not * mutate the input. */ declare function applyLegalBlockStyles(doc: T): T; /** * Image interactions extension — adds: * 1. Clipboard paste (Ctrl+V with image in clipboard → insert as base64) * 2. Drag-and-drop (drag image files onto editor → insert at drop position) * 3. Image resize handles (click image → 8 drag handles appear) * * This extension uses TipTap's ProseMirror plugin API to intercept * paste and drop events, and a DOM overlay for resize handles. */ declare const ImageInteractions: Extension; /** * ImageResizeHandles — a React component that shows 8 drag handles around * a selected image node, allowing the user to resize it by dragging. * * Usage: render this component inside the editor's React wrapper. * It listens to selection changes and shows handles when an image is selected. */ interface ImageResizeState { active: boolean; src: string; width: number; height: number; aspectRatio: number; left: number; top: number; } /** * Attach resize handle logic to the editor. * Call this from a React useEffect with the editor's DOM element. * * @param editorEl The .ProseMirror element * @param onResize Callback when an image is resized (receives new width/height) * @returns Cleanup function */ declare function attachImageResizeHandles(editorEl: HTMLElement, onResize: (width: string, height?: string) => void): () => void; /** Curated table style presets (Word/Google-Docs "table style gallery" * equivalent). Each preset is a CSS hook (`data-table-style=""`) — see * the `[data-table-style]` rules in `editor.css`. Cell/table attributes set * afterward (custom colors, borders) always win because inline styles beat * class/attribute-selector CSS. */ declare const TABLE_STYLE_PRESETS: Array<{ id: string; label: string; }>; /** Border presets — mirrors Word's "Borders" gallery (All / Outside / * Inside / one edge / None). Rendered via `data-border-style=""`. */ declare const TABLE_BORDER_PRESETS: Array<{ id: string; label: string; }>; declare const EnhancedTable: _tiptap_core.Node<_tiptap_extension_table.TableOptions, any>; declare const EnhancedTableRow: _tiptap_core.Node<_tiptap_extension_table_row.TableRowOptions, any>; declare const EnhancedTableCell: _tiptap_core.Node<_tiptap_extension_table_cell.TableCellOptions, any>; declare const EnhancedTableHeader: _tiptap_core.Node<_tiptap_extension_table_header.TableHeaderOptions, any>; /** * Measure the actual usable width of the page's content area (page width * minus its left/right margins), reading real computed styles so it's * correct for any theme (custom page size, custom margins, non-px units). */ declare function getAvailableContentWidth(ed: Editor): number; /** * Column width (px) that divides the page's actual content width evenly * across `cols` columns, floored at `MIN_COLUMN_WIDTH`. Exported so any code * path that builds table JSON directly (bypassing the `insertTable` command * — e.g. `@shashimadushan/docx-editor-agent`'s `insert_table` tool, which needs to insert * at an arbitrary block index rather than at the cursor) can set the same * `colwidth` up front instead of rendering at prosemirror-tables' cramped * ~25px-per-column default and looking inconsistent with tables inserted * from the toolbar. */ declare function computeEvenColumnWidth(ed: Editor, cols: number): number; /** * Insert a table sized like Word/Google Docs would: its columns are set to * divide the page's actual content width evenly, so a freshly-inserted * table fills the page edge-to-edge (matching the surrounding text margins) * instead of rendering at prosemirror-tables' default ~25px-per-column * (cramped/squished look). Replaces plain `editor.chain().insertTable(...)` * at every call site that offers "insert table" in the UI. */ declare function insertTableFitted(ed: Editor, options?: { rows?: number; cols?: number; withHeaderRow?: boolean; }): boolean; /** * table-interactions — composes the small, focused table interaction * modules into a single attach/detach call for `ReactDocxEditor`: * * - `table-attr-sync.ts` — re-applies table-level style/border/align/width * attributes onto the live DOM (needed because of a Table NodeView quirk * when `resizable: true` — see that file's header for details). * - `table-row-resize.ts` — drag a row's bottom border to resize it * (prosemirror-tables only supports column resize natively). * - `table-insert-buttons.ts` — hover "+" buttons to insert a row/column * at the boundary nearest the cursor. * - `table-move-handle.ts` — the "⠿ Move table" grip to drag a whole table * to a different position in the document. * - `table-selector-handles.ts` — row/column grip bars that select the * whole row/column on click (a `CellSelection`), Google-Docs-style. * * Column resizing itself needs no custom code — it's native * (prosemirror-tables' `columnResizing` plugin, enabled via * `resizable: true`). Cell drag-selection is also native (`tableEditing()`, * bundled inside the `Table` extension) — see the `.selectedCell` CSS rule. */ /** * Attach all table interactions to a mounted editor. * * @param editorEl The `.ProseMirror` element (same element passed to * `attachImageResizeHandles`). * @param ed The underlying TipTap `Editor` instance (`docxEditor.editor`). * @returns Cleanup function. */ declare function attachTableInteractions(editorEl: HTMLElement, ed: Editor): () => void; /** * Convert a .docx ArrayBuffer to HTML. * * Returns well-formed HTML that TipTap can ingest via `editor.commands.setContent(html)`. * Layout is preserved via inline styles and the post-processing step. */ declare function loadDocxToHTML(buffer: ArrayBuffer): Promise; /** * Load .docx and return both HTML and conversion messages. * Useful for surfacing "X features were not supported" warnings to the UI. */ declare function loadDocx(buffer: ArrayBuffer): Promise<{ html: string; messages: Array<{ type: string; message: string; }>; }>; /** * Convert a TipTap JSON node into HTML using a temporary in-memory DOM. * * This is a fallback for callers who don't have a live editor instance. * For round-trip fidelity, prefer using the live editor's `getHTML()` / * `setHTML()` methods, which use ProseMirror's serializer. */ declare function jsonToHTML(json: any): string; /** Set HTML on the given TipTap-compatible editor instance. */ declare function setEditorHTML(editor: any, html: string): void; /** Get HTML from the given TipTap-compatible editor instance. */ declare function getEditorHTML(editor: any): string; /** * Embedded font extraction and registration. * * Word documents can embed fonts as obfuscated `.odttf` files in the * `word/fonts/` directory. The first 32 bytes are XOR-scrambled with * a 16-byte key derived from the `w:fontKey` GUID (byte order reversed). * * This module: * 1. Extracts font files from a .docx ArrayBuffer using JSZip * 2. Reads `word/fontTable.xml` to find embedded font declarations * 3. Reads `word/_rels/fontTable.xml.rels` to map relIds → file paths * 4. De-obfuscates each `.odttf` file * 5. Registers each font as a CSS `@font-face` via the FontFace API * * After registration, imported documents render in their authored fonts * instead of falling back to system defaults. */ /** * De-obfuscate an embedded `.odttf` font by XOR-ing its first 32 bytes * with the reversed `w:fontKey` GUID. Returns a new buffer. */ declare function deobfuscateFont(data: ArrayBuffer, fontKey: string): ArrayBuffer; interface EmbeddedFontResult { /** Set of font family names that were successfully registered. */ families: Set; /** Total number of font faces processed. */ faceCount: number; } /** * Extract and register all embedded fonts from a .docx ArrayBuffer. * * This should be called AFTER loading the document content, so the fonts * are registered before the browser tries to render text using them. * * @param docxBuffer - The .docx file as an ArrayBuffer * @returns Set of registered font family names */ declare function loadEmbeddedFontsFromDocx(docxBuffer: ArrayBuffer): Promise; /** * Returns the set of font family names that have been registered from * embedded fonts. Useful for populating a "Document fonts" section in * the font picker. */ declare function getLoadedEmbeddedFonts(): Set; /** * Clear all registered embedded fonts (for when a new document is loaded). * Note: FontFace API doesn't support removal, so we just clear the tracking set. */ declare function clearEmbeddedFonts(): void; export { COMMON_FONT_FAMILIES, COMMON_FONT_SIZES, DocxEditorExtension, DocxImage, type EmbeddedFontResult, EnhancedTable, EnhancedTableCell, EnhancedTableHeader, EnhancedTableRow, FontSize, type ImageAlignment, ImageInteractions, type ImageResizeState, type ImageWrap, KNOWN_MARK_NAMES, LegalBlock, type LegalBlockType, LetterSpacing, LineHeight, PageBreak, TABLE_BORDER_PRESETS, TABLE_STYLE_PRESETS, TextTransform, type TextTransformValue, alignmentExtension, annotateNode, applyLegalBlockStyles, attachImageResizeHandles, attachTableInteractions, blockquoteExtension, boldExtension, builtinExtensionIds, builtinExtensions, clearEmbeddedFonts, codeBlockExtension, computeEvenColumnWidth, defaultTipTapExtensions, deobfuscateFont, describeBlockType, getAvailableContentWidth, getBlockAlignment, getEditorHTML, getLoadedEmbeddedFonts, headingExtension, highlightExtension, horizontalRuleExtension, imageExtension, insertTableFitted, italicExtension, jsonToHTML, linkExtension, listExtension, loadDocx, loadDocxToHTML, loadEmbeddedFontsFromDocx, setEditorHTML, strikeExtension, tableExtension, underlineExtension };