@eigenpal/docx-editor-core
(default entry point)
Fat barrel that re-exports the parser, serializer, agent, plugin registry, and the most-used types. No React/DOM imports.
**When to import from `.` vs `./headless`:** identical for Node.js use; `.` is the convenient aggregate, `./headless` is its mirror with a slightly different name suffix. Adapter authors who only need a specific slice should prefer the smaller subpaths (`./docx`, `./agent`, `./prosemirror`, `./layout-*`, `./utils`) — they tree-shake better.
Functions(108)
attemptSelectiveSave
Attempt a selective save — patch only changed paragraphs in document.xml. Also updates comments, headers/footers, and core properties so that all document parts stay in sync even when only paragraphs are patched.
Returns the saved ArrayBuffer, or null if selective save is not possible (caller should fall back to full repack).
declare function attemptSelectiveSave(doc: Document, originalBuffer: ArrayBuffer, options: SelectiveSaveOptions): Promise<ArrayBuffer | null>;blendColors
Blend two colors together
declare function blendColors(color1: ColorValue | undefined | null, color2: ColorValue | undefined | null, ratio: number, theme: Theme | null | undefined): string;buildExtendedSelectionContext
Build extended selection context with additional details
declare function buildExtendedSelectionContext(doc: Document, range: Range, options?: SelectionContextOptions): ExtendedSelectionContext;buildFootnoteContentMap
Build footnote content for all footnotes referenced in the document. Display numbers are assigned by first-appearance order (the same way Word renders them).
declare function buildFootnoteContentMap(footnotes: Footnote[], footnoteRefs: Array<{
footnoteId: number;
}>, contentWidth: number, options: ConvertFootnoteOptions): Map<number, FootnoteContent>;buildFootnoteRenderItems
Turn the page→footnote-id map into the per-page render payload that `renderPages` consumes via `footnotesByPage`. Skips non-`normal` notes (separators, continuation notices), reads the display number out of the content map, and pulls plain text via `getFootnoteText`.
Lives in core (not in either adapter) so React + Vue both call the same helper — same rule as the rest of this module.
declare function buildFootnoteRenderItems(pageFootnoteMap: Map<number, number[]>, footnoteContentMap: Map<number, FootnoteContent>, doc: Document | null): Map<number, FootnoteRenderItem[]>;buildPatchedDocumentXml
Build a patched document.xml by splicing new paragraph XML into the original at the correct offsets. Only changed paragraphs are replaced; everything else is preserved byte-for-byte.
Returns null if any step fails.
declare function buildPatchedDocumentXml(originalXml: string, serializedXml: string, changedIds: Set<string>): string | null;buildSelectionContext
Build selection context for AI operations
declare function buildSelectionContext(doc: Document, range: Range, options?: SelectionContextOptions): SelectionContext;calculateFootnoteReservedHeights
Calculate per-page footnote reserved heights. Returns MappageNumber, reservedHeight.
declare function calculateFootnoteReservedHeights(pageFootnoteMap: Map<number, number[]>, footnoteContentMap: Map<number, {
height: number;
}>): Map<number, number>;canRenderFont
Check if a font is available on the system using canvas measurement
This uses the technique of comparing text width with the target font vs a known fallback font. If they differ, the font is available.
declare function canRenderFont(fontFamily: string, fallbackFont?: string): boolean;collectFootnoteRefs
Scan FlowBlocks for runs with footnoteRefId set. Returns a list of footnoteId, pmPos in document order.
declare function collectFootnoteRefs(blocks: FlowBlock[]): Array<{
footnoteId: number;
pmPos: number;
}>;colorsEqual
Check if two colors are equal
declare function colorsEqual(color1: ColorValue | undefined | null, color2: ColorValue | undefined | null, theme: Theme | null | undefined): boolean;countPageBreaks
Count page breaks in a document
declare function countPageBreaks(doc: Document): number;createColumnBreak
Create a column break content element
declare function createColumnBreak(): BreakContent;createDocumentWithText
Create a document with a single paragraph containing the given text
declare function createDocumentWithText(text: string, options?: Omit<CreateEmptyDocumentOptions, 'initialText'>): Document;createDocx
Create a new DOCX from a Document (without requiring original buffer)
declare function createDocx(doc: Document): Promise<ArrayBuffer>;createEmptyDocument
Create an empty document with a single paragraph
declare function createEmptyDocument(options?: CreateEmptyDocumentOptions): Document;```ts
// Create a blank document
const doc = createEmptyDocument();
// Create with custom margins
const doc = createEmptyDocument({
marginTop: 720, // 0.5 inch
marginBottom: 720,
});
// Create with initial text
const doc = createEmptyDocument({
initialText: 'Hello, World!'
});
```createHorizontalRule
Create a horizontal rule paragraph Uses a paragraph with bottom border to simulate horizontal rule
declare function createHorizontalRule(): Paragraph;createLineBreak
Create a text wrapping break (line break)
declare function createLineBreak(clear?: 'none' | 'left' | 'right' | 'all'): BreakContent;createPageBreak
Create a page break content element
declare function createPageBreak(): BreakContent;createPageBreakParagraph
Create an empty paragraph with a page break before it
declare function createPageBreakParagraph(): Paragraph;createPageBreakRun
Create a run containing a page break
declare function createPageBreakRun(): Run;createRgbColor
Create a ColorValue from RGB hex
declare function createRgbColor(hex: string): ColorValue;createSelectionFromDOM
Create a ClipboardSelection from the current DOM selection.
declare function createSelectionFromDOM(): ClipboardSelection | null;createThemeColor
Create a ColorValue from theme color reference
declare function createThemeColor(themeColor: ThemeColorSlot, tint?: number, shade?: number): ColorValue;darkenColor
Darken a color by a percentage
declare function darkenColor(color: ColorValue | undefined | null, theme: Theme | null | undefined, percent: number): string;detectVariables
Detect all template variables in a document
declare function detectVariables(doc: Document): string[];detectVariablesDetailed
Detect variables with detailed information
declare function detectVariablesDetailed(doc: Document): VariableDetectionResult;detectVariablesInBody
Detect variables in document body
declare function detectVariablesInBody(body: DocumentBody): string[];detectVariablesInParagraph
Detect variables in a paragraph
declare function detectVariablesInParagraph(paragraph: Paragraph): string[];documentHasVariables
Check if document has any template variables
declare function documentHasVariables(doc: Document): boolean;emuToPixels
Convert EMUs to pixels (at 96 DPI)
1 inch = 914400 EMUs = 96 pixels Returns 0 for null/undefined/NaN inputs.
declare function emuToPixels(emu: number | undefined | null): number;emuToTwips
Convert EMUs to twips
declare function emuToTwips(emu: number): number;ensureHexPrefix
Ensure a hex color string has a '#' prefix.
declare function ensureHexPrefix(hex: string): string;executeCommand
Execute an agent command on a document Returns a new document with the command applied (immutable)
Dispatch order: 1. Try plugin handlers first (allows plugins to override built-in commands) 2. Fall back to built-in handlers
declare function executeCommand(doc: Document, command: AgentCommand): Document;executeCommands
Execute multiple commands in sequence
declare function executeCommands(doc: Document, commands: AgentCommand[]): Document;extractFormattingFromElement
Extract formatting from an HTML element's computed styles.
declare function extractFormattingFromElement(element: HTMLElement): Run['formatting'];extractVariablesFromText
Extract variable names from text
declare function extractVariablesFromText(text: string): string[];findPageBreaks
Find all page break positions in a document
declare function findPageBreaks(doc: Document): InsertPosition[];findParagraphByParaId
ProseMirror position range for the paragraph (or any textblock) whose `paraId` attribute equals `paraId`. Returns the inclusive `from` and exclusive `to` positions, plus the node, so callers can both target the paragraph (e.g. addMark over its text range) and inspect it.
`from` is the position immediately before the textblock; `to` is `from + node.nodeSize`. The text content lives at `[from + 1, to - 1]`.
Returns null if no textblock with that paraId exists.
declare function findParagraphByParaId(doc: Node, paraId: string): {
node: Node;
from: number;
to: number;
} | null;findStartPosForParaId
ProseMirror position immediately before the first textblock whose `paraId` attribute equals `paraId` (Word `w14:paraId` / OOXML paragraph id).
Match is strict string equality on `node.attrs.paraId`.
declare function findStartPosForParaId(doc: Node, paraId: string): number | null;footnoteReservedHeightsEqual
Compare two per-page footnote reservation maps. Used by the React + Vue adapters to detect when the multi-pass loop has converged.
declare function footnoteReservedHeightsEqual(a: Map<number, number>, b: Map<number, number>): boolean;formatLastSaveTime
Format last save time for display
declare function formatLastSaveTime(date: Date | null): string;formatPx
Format a pixel value as CSS string
declare function formatPx(px: number): string;formatStorageSize
Format storage size for display
declare function formatStorageSize(bytes: number): string;formatVariable
Format a variable name with braces (standard docxtemplater syntax)
declare function formatVariable(name: string): string;generateThemeTintShadeMatrix
Generate the 10×6 theme color matrix for an advanced color picker.
Columns: lt1, dk1, lt2, dk2, accent1-6 (matches Word's order) Rows: base, 80% tint, 60% tint, 40% tint, 25% shade, 50% shade
declare function generateThemeTintShadeMatrix(colorScheme?: ThemeColorScheme | null): ThemeMatrixCell[][];getAgentContext
Build agent context from a document
declare function getAgentContext(doc: Document, options?: AgentContextOptions): AgentContext;getAutoSaveStatusLabel
Get auto-save status label
declare function getAutoSaveStatusLabel(status: AutoSaveStatus): string;getAutoSaveStorageSize
Get storage size used by auto-save
declare function getAutoSaveStorageSize(storageKey?: string): number;getContrastingColor
Get contrasting text color for a background
declare function getContrastingColor(backgroundColor: ColorValue | undefined | null, theme: Theme | null | undefined): string;getDocumentSummary
Get a simple document summary for quick context
declare function getDocumentSummary(doc: Document): string;getLoadedFonts
Get list of all loaded fonts
declare function getLoadedFonts(): string[];getSelectionRuns
Get selected runs from the current DOM selection.
declare function getSelectionRuns(): Run[];getThemeTintShadeHex
Compute a single tinted or shaded hex color from a base color.
declare function getThemeTintShadeHex(baseHex: string, type: 'tint' | 'shade', fraction: number): string;halfPointsToPixels
Convert half-points to pixels (at 96 DPI)
Half-points are commonly used for font sizes in OOXML (w:sz).
declare function halfPointsToPixels(halfPoints: number): number;hasPageBreakBefore
Check if a paragraph has pageBreakBefore
declare function hasPageBreakBefore(paragraph: Paragraph): boolean;hasTemplateVariables
Check if text contains template variables
declare function hasTemplateVariables(text: string): boolean;injectStyles
Inject CSS styles into the document head. Returns a cleanup function.
declare function injectStyles(pluginId: string, css: string): () => void;insertHorizontalRule
Insert a horizontal rule at a position in the document
declare function insertHorizontalRule(doc: Document, position: InsertPosition): Document;insertPageBreak
Insert a page break at a position in the document This inserts a new paragraph with pageBreakBefore: true
declare function insertPageBreak(doc: Document, position: InsertPosition): Document;isAutoSaveSupported
Check if auto-save is supported
declare function isAutoSaveSupported(): boolean;Check if a color is effectively black
declare function isBlack(color: ColorValue | undefined | null, theme: Theme | null | undefined): boolean;isBreakContent
Check if content is any type of break
declare function isBreakContent(content: RunContent): content is BreakContent;isColumnBreak
Check if content is a column break
declare function isColumnBreak(content: RunContent): boolean;isFontLoaded
Check if a font is loaded
declare function isFontLoaded(fontFamily: string): boolean;isFontsLoading
Check if any fonts are currently loading
declare function isLoading(): boolean;isLineBreak
Check if content is a line break
declare function isLineBreak(content: RunContent): boolean;isPageBreak
Check if content is a page break
declare function isPageBreak(content: RunContent): boolean;isValidVariableName
Check if a variable name is valid
declare function isValidVariableName(name: string): boolean;Check if a color is effectively white
declare function isWhite(color: ColorValue | undefined | null, theme: Theme | null | undefined): boolean;lightenColor
Lighten a color by a percentage
declare function lightenColor(color: ColorValue | undefined | null, theme: Theme | null | undefined, percent: number): string;loadFont
Load a font from Google Fonts
declare function loadFont(fontFamily: string, options?: {
weights?: number[];
styles?: ('normal' | 'italic')[];
}): Promise<boolean>;loadFontFromBuffer
Load a font from a raw buffer (e.g., embedded in DOCX)
declare function loadFontFromBuffer(fontFamily: string, buffer: ArrayBuffer, options?: {
weight?: number | string;
style?: 'normal' | 'italic';
}): Promise<boolean>;loadFonts
Load multiple fonts from Google Fonts
declare function loadFonts(families: string[], options?: {
weights?: number[];
styles?: ('normal' | 'italic')[];
}): Promise<void>;mapFootnotesToPages
After layout, determine which footnotes appear on which pages. Checks each page's fragments to see if any footnoteRef PM positions fall within.
Returns MappageNumber, footnoteId[] in document order.
declare function mapFootnotesToPages(pages: Page[], footnoteRefs: Array<{
footnoteId: number;
pmPos: number;
}>): Map<number, number[]>;onFontsLoaded
Register a callback to be notified when fonts are loaded
declare function onFontsLoaded(callback: (fonts: string[]) => void): () => void;parseColorString
Parse a color string (various formats) to ColorValue
declare function parseColorString(colorString: string | undefined): ColorValue | undefined;parseDocx
Parse a DOCX file into a complete Document model
declare function parseDocx(input: DocxInput, options?: ParseOptions): Promise<Document>;parseVariable
Parse a variable string to get the name
declare function parseVariable(variable: string): string | null;pixelsToEmu
Convert pixels to EMUs. EMU coordinates in OOXML are integer-typed (xs:long); rounding here keeps floating-point drift (e.g. 52 px → 495299.99999999994) out of the document.
declare function pixelsToEmu(px: number): number;pixelsToTwips
Convert pixels to twips
declare function pixelsToTwips(px: number): number;pointsToPixels
Convert points to pixels (at 96 DPI)
1 inch = 72 points = 96 pixels → 1 point = 96/72 pixels = 4/3 pixels
declare function pointsToPixels(points: number): number;preloadCommonFonts
Preload a list of common document fonts
This preloads fonts commonly used in DOCX documents that have Google Fonts equivalents.
declare function preloadCommonFonts(): Promise<void>;processTemplate
Process a DOCX template with variable substitution
declare function processTemplate(buffer: ArrayBuffer, variables: Record<string, string>, options?: ProcessTemplateOptions): ArrayBuffer;processTemplateAsBlob
Process template and return as Blob
declare function processTemplateAsBlob(buffer: ArrayBuffer, variables: Record<string, string>, options?: ProcessTemplateOptions): Blob;processTemplateDetailed
Process template with detailed result
declare function processTemplateDetailed(buffer: ArrayBuffer, variables: Record<string, string>, options?: ProcessTemplateOptions): ProcessTemplateResult;registerPlugins
Register multiple plugins at once
declare function registerPlugins(plugins: CorePlugin[], options?: PluginOptions): PluginRegistrationResult[];removePageBreak
Remove a page break at a specific position
declare function removePageBreak(doc: Document, position: InsertPosition): Document;removeVariables
Replace all variables in text with a placeholder
declare function removeVariables(text: string, placeholder?: string): string;repackDocx
Repack a Document into a valid DOCX file
declare function repackDocx(doc: Document, options?: RepackOptions): Promise<ArrayBuffer>;replaceVariables
Replace variables in text with values
declare function replaceVariables(text: string, values: Record<string, string>): string;resolveColor
Resolve a ColorValue to a CSS color string
declare function resolveColor(color: ColorValue | undefined | null, theme: Theme | null | undefined, defaultColor?: string): string;resolveHighlightColor
Resolve a highlight color name to CSS
declare function resolveHighlightColor(highlight: string | undefined): string;resolveHighlightToCss
Resolve a highlight color value to a CSS-ready string. Tries OOXML named highlight first, then ensures hex prefix.
declare function resolveHighlightToCss(value: string): string;resolveShadingColor
Resolve a shading fill or pattern color to CSS
declare function resolveShadingColor(color: ColorValue | undefined | null, theme: Theme | null | undefined): string;sanitizeVariableName
Sanitize a variable name
declare function sanitizeVariableName(name: string): string;serializeDocumentBody
Serialize a DocumentBody to document.xml body content
declare function serializeDocumentBody(body: DocumentBody): string;serializeDocx
Serialize a complete Document to valid document.xml
declare function serializeDocument(doc: Document): string;serializeSectionProperties
Serialize section properties (w:sectPr)
declare function serializeSectionProperties(props: SectionProperties | undefined): string;stabilizeFootnoteLayout
Run the multi-pass footnote layout loop. Reserving footnote space on a page can move a reference to another page, which changes the reservation, which can move references again. Iterate until the page→height contract is the same one used by the latest layout, or `MAX_FOOTNOTE_LAYOUT_PASSES` passes have run.
Lives in core so the React + Vue adapters call the same loop and stay in lockstep on convergence behaviour. Writes `page.footnoteIds` onto each page in the returned layout so renderers can paint footnote areas.
declare function stabilizeFootnoteLayout(args: StabilizeFootnoteLayoutArgs): StabilizeFootnoteLayoutResult;toArrayBuffer
Normalize any [DocxInput](DocxInput) into an `ArrayBuffer` for internal use.
declare function toArrayBuffer(input: DocxInput): Promise<ArrayBuffer>;twipsToEmu
Convert twips to EMUs
declare function twipsToEmu(twips: number): number;twipsToPixels
Convert twips to pixels (at 96 DPI)
1 inch = 1440 twips = 96 pixels → 1 twip = 96/1440 pixels = 1/15 pixels
declare function twipsToPixels(twips: number): number;updateMultipleFiles
Update multiple files in a DOCX buffer
declare function updateMultipleFiles(originalBuffer: ArrayBuffer, updates: Map<string, string | ArrayBuffer>, options?: RepackOptions): Promise<ArrayBuffer>;validatePatchSafety
Validate that a selective patch can be safely applied.
Checks: - All changed paraIds exist in original XML (exactly once) - All changed paraIds exist in serialized XML (exactly once) - Paragraph count matches between original and serialized
declare function validatePatchSafety(originalXml: string, serializedXml: string, changedIds: Set<string>): PatchValidationResult;validateTemplate
Validate that a document is a valid docxtemplater template
declare function validateTemplate(buffer: ArrayBuffer): {
valid: boolean;
errors: TemplateError[];
tags: string[];
};Classes(8)
AutoSaveManager
AutoSaveManager
Framework-agnostic class for auto-saving documents to localStorage. Extracted from the React `useAutoSave` hook.
Usage with React:
```ts const snapshot = useSyncExternalStore(manager.subscribe, manager.getSnapshot); ```
declare class AutoSaveManager extends Subscribable<AutoSaveSnapshot>| Member | Type | Summary |
|---|---|---|
| (constructor) | — | Constructs a new instance of the `AutoSaveManager` class |
| acceptRecovery | — | Accept recovery and return the document. |
| clear | — | Clear auto-saved data from storage. |
| destroy | — | Save synchronously on destroy (best-effort). |
| disable | — | Disable auto-save and stop all timers. |
| dismissRecovery | — | Dismiss recovery and clear saved data. |
| enable | — | Enable auto-save and start the interval timer. |
| getRecoveryData | — | Get recovery data from storage. |
| onDocumentChanged | — | Update the current document. Triggers debounced save if enabled. |
| save | — | Manually trigger a save. |
| startInterval | — | Start the interval timer. Call after enabling or on init. |
DocumentAgent
DocumentAgent provides a fluent API for document manipulation
declare class DocumentAgent```ts
const agent = new DocumentAgent(buffer);
// Read operations
const text = agent.getText();
const wordCount = agent.getWordCount();
const variables = agent.getVariables();
// Write operations (returns new agent)
const newAgent = agent
.insertText({ paragraphIndex: 0, offset: 0 }, 'Hello ', { formatting: { bold: true } })
.applyStyle({ paragraphIndex: 0, offset: 0 }, { paragraphIndex: 0, offset: 5 }, 'Heading1');
// Export
const newBuffer = await newAgent.toBuffer();
```| Member | Type | Summary |
|---|---|---|
| (constructor) | — | Create a new DocumentAgent |
| applyFormatting | — | Apply text formatting to a range |
| applyParagraphFormatting | — | Apply paragraph formatting |
| applyStyle | — | Apply a named style to a paragraph |
| applyVariables | — | Apply all pending template variables |
| clearPendingVariables | — | Clear pending variables |
| deleteRange | — | Delete text in a range |
| executeCommands | — | Execute multiple commands in sequence |
| fromBuffer | — | Create a DocumentAgent from a DOCX buffer (async) |
| fromDocument | — | Create a DocumentAgent from a Document object |
| getAgentContext | — | Get document context for AI agents |
| getCharacterCount | — | Get character count |
| getDocument | — | Get the underlying document |
| getFormattedText | — | Get formatted text segments |
| getPageCount | — | Get approximate page count |
| getParagraphCount | — | Get paragraph count |
| getPendingVariables | — | Get pending variable values |
| getStyles | — | Get available styles from the document |
| getTableCount | — | Get table count |
| getText | — | Get plain text content of the document |
| getVariables | — | Get detected template variables |
| getWordCount | — | Get word count |
| insertHyperlink | — | Insert a hyperlink |
| insertImage | — | Insert an image at a position |
| insertParagraphBreak | — | Insert a paragraph break |
| insertTable | — | Insert a table at a position |
| insertText | — | Insert text at a position |
| mergeParagraphs | — | Merge consecutive paragraphs |
| removeHyperlink | — | Remove a hyperlink but keep the text |
| replaceRange | — | Replace text in a range |
| setVariable | — | Set a template variable value |
| setVariables | — | Set multiple template variables |
| toBlob | — | Export document to Blob |
| toBuffer | — | Export document to DOCX ArrayBuffer |
EditorCoordinator
declare class EditorCoordinator extends Subscribable<EditorCoordinatorSnapshot>| Member | Type | Summary |
|---|---|---|
| (constructor) | — | Constructs a new instance of the `EditorCoordinator` class |
| getDocument | — | Get the current document. |
| getZoom | — | Get the current zoom level. |
| setDocumentLoaded | — | Signal that document parsing completed successfully. |
| setFontsLoaded | — | Signal that font loading completed. |
| setLoadError | — | Signal that an error occurred during loading. |
| setParsingStarted | — | Signal that document parsing has started. |
| setZoom | — | Set the zoom level (1.0 = 100%). |
| updateDocument | — | Update the document (after edits). |
ErrorManager
ErrorManager
Framework-agnostic pub/sub error notification system. Replaces React's `componentDidCatch` + context pattern for error notifications.
Usage with React:
```ts const { notifications } = useSyncExternalStore(manager.subscribe, manager.getSnapshot); ```
declare class ErrorManager extends Subscribable<ErrorManagerSnapshot>| Member | Type | Summary |
|---|---|---|
| (constructor) | — | Constructs a new instance of the `ErrorManager` class |
| clearAll | — | Clear all notifications and cancel pending timers. |
| destroy | — | Destroy the manager and clean up all timers. |
| dismiss | — | Dismiss a notification by ID. |
| showError | — | Show an error notification (persistent, not auto-dismissed). |
| showInfo | — | Show an info notification (auto-dismissed after 5s). |
| showWarning | — | Show a warning notification (auto-dismissed after 5s). |
LayoutCoordinator
declare class LayoutCoordinator extends Subscribable<LayoutCoordinatorSnapshot>| Member | Type | Summary |
|---|---|---|
| (constructor) | — | Constructs a new instance of the `LayoutCoordinator` class |
| clearSelectedImage | — | Clear the image selection. |
| endColumnResize | — | End column resize. |
| endDrag | — | End drag selection. |
| getColumnResize | — | Get current column resize state. |
| getDragAnchor | — | Get the drag anchor position. |
| setFocused | — | Update focus state. |
| setImageInteracting | — | Set whether an image interaction (resize/move) is in progress. |
| setLayoutReady | — | Notify that layout has been computed. |
| setSelectedImage | — | Set the currently selected image. |
| startColumnResize | — | Start resizing a table column. |
| startDrag | — | Start a drag selection from the given PM anchor position. |
| updateSelection | — | Update selection rectangles and caret position. |
PluginLifecycleManager
declare class PluginLifecycleManager extends Subscribable<PluginLifecycleSnapshot>| Member | Type | Summary |
|---|---|---|
| (constructor) | — | Constructs a new instance of the `PluginLifecycleManager` class |
| destroy | — | Destroy all plugins and clean up. |
| getPluginState | — | Get plugin state by ID. |
| initialize | — | Initialize plugins with an editor view. Calls `plugin.initialize(editorView)` for each plugin. |
| setPluginState | — | Set plugin state by ID. |
| updateStates | — | Update all plugin states by calling `onStateChange` on each plugin. Returns true if any plugin state changed. |
PluginRegistry
Plugin Registry - manages core plugins
declare class PluginRegistry```ts
import { pluginRegistry, docxtemplaterPlugin } from '@eigenpal/docx-editor/core-plugins';
// Register plugins
pluginRegistry.register(docxtemplaterPlugin);
// Get all MCP tools for MCP server
const tools = pluginRegistry.getMcpTools();
// Get command handler for executor
const handler = pluginRegistry.getCommandHandler('insertTemplateVariable');
```| Member | Type | Summary |
|---|---|---|
| addEventListener | — | Add an event listener |
| clear | — | Clear all registered plugins |
| get | — | Get a registered plugin by ID |
| getAll | — | Get all registered plugins |
| getCommandHandler | — | Get a command handler for a command type |
| getCommandTypes | — | Get all registered command types |
| getDebugInfo | — | Get registry state for debugging |
| getMcpTool | — | Get an MCP tool by name |
| getMcpTools | — | Get all MCP tools from all registered plugins |
| getMcpToolsForPlugin | — | Get MCP tools from a specific plugin |
| has | — | Check if a plugin is registered |
| hasCommandHandler | — | Check if a command type has a handler |
| register | — | Register a plugin |
| removeEventListener | — | Remove an event listener |
| size | number | Get number of registered plugins |
| unregister | — | Unregister a plugin |
Subscribable
Subscribable Base Class
Framework-agnostic base for manager classes that need to notify UI frameworks of state changes.
Compatible with: - React: useSyncExternalStore(manager.subscribe, manager.getSnapshot) - Vue: watchEffect(() = manager.subscribe(triggerRef) )
declare abstract class Subscribable<TSnapshot>| Member | Type | Summary |
|---|---|---|
| (constructor) | — | Constructs a new instance of the `Subscribable` class |
| getSnapshot | () => TSnapshot | Get the current snapshot. Returns a stable reference unless state has changed. Bound method — safe to pass as `useSyncExternalStore(..., manager.getSnapshot)`. |
| setSnapshot | — | Update the snapshot and notify all subscribers. Subclasses should call this whenever their state changes. |
| subscribe | (listener: () => void) => (() => void) | Subscribe to state changes. Returns an unsubscribe function. Bound method — safe to pass as `useSyncExternalStore(manager.subscribe, ...)`. |
Interfaces(96)
AgentContext
Document context for AI agents
interface AgentContext| Member | Type | Summary |
|---|---|---|
| availableStyles | StyleInfo[] | Available styles |
| characterCount | number | Total character count |
| hasHyperlinks | boolean | Has hyperlinks |
| hasImages | boolean | Has images |
| hasTables | boolean | Has tables |
| language? | string | Document language |
| outline | ParagraphOutline[] | Content outline (first N chars per paragraph) |
| paragraphCount | number | Total paragraph count |
| sections | SectionInfo[] | Document sections info |
| variableCount | number | Variable count |
| variables | string[] | Detected template variables |
| wordCount | number | Total word count (approximate) |
AgentContextOptions
Options for building agent context
interface AgentContextOptions| Member | Type | Summary |
|---|---|---|
| includeFormatting? | boolean | Include detailed formatting info (default: false) |
| includeTableContent? | boolean | Include table content in context (default: false) |
| maxOutlineParagraphs? | number | Maximum paragraphs to include in outline (default: 50) |
| outlineMaxChars? | number | Maximum characters per paragraph in outline (default: 100) |
AgentResponse
Response from an agent action
interface AgentResponse| Member | Type | Summary |
|---|---|---|
| commands? | AgentCommand[] | Commands to execute |
| error? | string | Error message if failed |
| metadata? | Record<string, unknown> | Metadata about the response |
| newContent? | AgentContent[] | New formatted content |
| newText? | string | New text to insert (for rewrite/expand/etc.) |
| success | boolean | Success status |
| warnings? | string[] | Warning messages |
AIActionRequest
AI action request
interface AIActionRequest| Member | Type | Summary |
|---|---|---|
| action | AIAction | Action type |
| context | SelectionContext | Selection context |
| customPrompt? | string | Custom prompt (for 'custom' action) |
| options? | Record<string, unknown> | Additional options |
| targetLanguage? | string | Target language (for 'translate' action) |
ApplyStyleCommand
Apply a named style to a paragraph
interface ApplyStyleCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| paragraphIndex | number | Paragraph index |
| styleId | string | Style ID to apply |
| type | 'applyStyle' |
AutoSaveManagerOptions
Configuration for AutoSaveManager
interface AutoSaveManagerOptions| Member | Type | Summary |
|---|---|---|
| debounceDelay? | number | Debounce delay for saveOnChange in milliseconds (default: 2000) |
| interval? | number | Save interval in milliseconds (default: 30000 - 30 seconds) |
| maxAge? | number | Maximum age of auto-save before it's considered stale (default: 24 hours) |
| onError? | (error: Error) => void | Callback when save fails |
| onRecoveryAvailable? | (savedDocument: SavedDocumentData) => void | Callback when recovery data is found |
| onSave? | (timestamp: Date) => void | Callback when save succeeds |
| saveOnChange? | boolean | Whether to save on document change with debounce (default: true) |
| storageKey? | string | Storage key for localStorage (default: 'docx-editor-autosave') |
AutoSaveSnapshot
AutoSaveManager snapshot for UI consumption
interface AutoSaveSnapshot| Member | Type | Summary |
|---|---|---|
| hasRecoveryData | boolean | |
| isEnabled | boolean | |
| lastSaveTime | Date | null | |
| status | AutoSaveStatus |
BookmarkEnd
Bookmark end marker (w:bookmarkEnd)
interface BookmarkEnd| Member | Type | Summary |
|---|---|---|
| id | number | Bookmark ID |
| type | 'bookmarkEnd' |
BookmarkStart
Bookmark start marker (w:bookmarkStart)
interface BookmarkStart| Member | Type | Summary |
|---|---|---|
| colFirst? | number | Column index for table bookmarks |
| colLast? | number | |
| id | number | Bookmark ID |
| name | string | Bookmark name |
| type | 'bookmarkStart' |
CaretPosition_2
Caret position for rendering the blinking cursor
interface CaretPosition| Member | Type | Summary |
|---|---|---|
| height | number | |
| pageIndex | number | |
| x | number | |
| y | number |
CellCoordinates
Cell coordinates in a table
interface CellCoordinates| Member | Type | Summary |
|---|---|---|
| columnIndex | number | |
| rowIndex | number | |
| tableIndex | number |
ClipboardSelection
Selection data for clipboard operations
interface ClipboardSelection| Member | Type | Summary |
|---|---|---|
| endOffset | number | |
| endParagraphIndex | number | |
| endRunIndex | number | |
| isMultiParagraph | boolean | |
| runs | Run[] | |
| startOffset | number | |
| startParagraphIndex | number | |
| startRunIndex | number | |
| text | string |
ColumnResizeState
Column resize tracking state
interface ColumnResizeState| Member | Type | Summary |
|---|---|---|
| columnIndex | number | |
| isResizing | boolean | |
| originalWidths | {
left: number;
right: number;
} | |
| startX | number | |
| tablePmStart | number |
Comment_2
A comment from `comments.xml` — the top-level entity for review comments and replies. `id` matches the inline `CommentRangeStart` / `CommentRangeEnd` markers that anchor it inside a paragraph; `parentId` threads replies under their parent; `done` reflects Word's "Resolve" state (`w15:done`).
interface Comment| Member | Type | Summary |
|---|---|---|
| author | string | Author name |
| content | Paragraph[] | Comment content (paragraphs) |
| date? | string | Date |
| done? | boolean | Whether the comment is resolved/done |
| id | number | Comment ID (matches commentRangeStart/End) |
| initials? | string | Author initials |
| parentId? | number | Parent comment ID (for replies) |
CommentRangeEnd
Comment range end marker in paragraph content
interface CommentRangeEnd| Member | Type | Summary |
|---|---|---|
| id | number | |
| type | 'commentRangeEnd' |
CommentRangeStart
Comment range start marker in paragraph content
interface CommentRangeStart| Member | Type | Summary |
|---|---|---|
| id | number | |
| type | 'commentRangeStart' |
CorePlugin
Core plugin interface - headless, works in Node.js
Plugins can: - Register command handlers that DocumentAgent dispatches to - Declare MCP tools that the MCP server exposes to AI clients - Have optional initialization logic - Declare dependencies on other plugins
interface CorePlugin| Member | Type | Summary |
|---|---|---|
| commandHandlers? | Record<string, CommandHandler> | Command handlers this plugin provides. DocumentAgent dispatches commands to these handlers. |
| dependencies? | string[] | Dependencies on other plugins (by ID). The registry ensures dependencies are loaded first. |
| description? | string | Plugin description |
| destroy? | () => void | Promise<void> | Optional cleanup when plugin is unregistered. |
| id | string | Unique plugin identifier |
| initialize? | () => void | Promise<void> | Optional setup when plugin is registered. Called once during plugin registration. |
| mcpTools? | McpToolDefinition[] | MCP tools this plugin exposes. MCP server collects these from all plugins. |
| name | string | Human-readable plugin name |
| version? | string | Plugin version (semver) |
CreateEmptyDocumentOptions
Options for creating an empty document
interface CreateEmptyDocumentOptions| Member | Type | Summary |
|---|---|---|
| initialText? | string | Initial text content (default: empty string) |
| marginBottom? | number | Bottom margin in twips (default: 1440 = 1 inch) |
| marginLeft? | number | Left margin in twips (default: 1440 = 1 inch) |
| marginRight? | number | Right margin in twips (default: 1440 = 1 inch) |
| marginTop? | number | Top margin in twips (default: 1440 = 1 inch) |
| orientation? | 'portrait' | 'landscape' | Page orientation (default: 'portrait') |
| pageHeight? | number | Page height in twips (default: 15840 = 11 inches) |
| pageWidth? | number | Page width in twips (default: 12240 = 8.5 inches) |
DeleteTextCommand
Delete text in a range
interface DeleteTextCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| range | Range | Range to delete |
| type | 'deleteText' |
Deletion
Deletion wrapper (w:del) — runs deleted by tracked changes
interface Deletion| Member | Type | Summary |
|---|---|---|
| content | (Run | Hyperlink)[] | Deleted content |
| info | TrackedChangeInfo | Tracked change metadata |
| type | 'deletion' |
Document_2
Top-level parsed DOCX document — the result of `parseDocx(buffer)`.
Wraps the unzipped DOCX package (`document.xml`, `styles.xml`, etc.), the original buffer for round-trip saves, and any template variables / parse warnings detected during ingestion.
interface Document```ts
import { parseDocx } from '@eigenpal/docx-editor-core/headless';
const doc = await parseDocx(buffer);
console.log(doc.package.document.content.length);
```| Member | Type | Summary |
|---|---|---|
| originalBuffer? | ArrayBuffer | Original DOCX buffer. Kept for round-trip saves that preserve untouched parts. |
| package | DocxPackage | Parsed DOCX package — body, styles, numbering, theme, media, headers/footers. |
| templateVariables? | string[] | Detected docxtemplater variables (e.g. `{name}`, `{address}`). Populated when the document is recognized as a template. |
| warnings? | string[] | Non-fatal parser diagnostics — malformed parts, unsupported features, fallbacks. |
DocumentBody
Document body (`w:body`) — the editable content of the document.
Contains the ordered block content (paragraphs and tables), the section layout chain derived from inline `sectPr` markers, the final `sectPr`, and any document-level comments. This is what most edit operations mutate; headers/footers/styles live elsewhere in the package.
interface DocumentBody| Member | Type | Summary |
|---|---|---|
| comments? | Comment[] | Comments from comments.xml |
| content | BlockContent[] | All content (paragraphs, tables) |
| finalSectionProperties? | SectionProperties | Final section properties (from body's sectPr) |
| sections? | Section[] | Sections (derived from sectPr in paragraphs and final sectPr) |
DocxPackage
Complete DOCX package structure
interface DocxPackage| Member | Type | Summary |
|---|---|---|
| document | DocumentBody | Document body |
| endnotes? | Endnote[] | Endnotes |
| fontTable? | FontTable | Font table |
| footers? | Map<string, HeaderFooter> | Footers by relationship ID |
| footnotes? | Footnote[] | Footnotes |
| headers? | Map<string, HeaderFooter> | Headers by relationship ID |
| media? | Map<string, MediaFile> | Media files |
| numbering? | NumberingDefinitions | Numbering definitions |
| properties? | {
title?: string;
subject?: string;
creator?: string;
keywords?: string;
description?: string;
lastModifiedBy?: string;
revision?: number;
created?: Date;
modified?: Date;
} | Document properties |
| relationships? | RelationshipMap | Document relationships |
| styles? | StyleDefinitions | Style definitions |
| theme? | Theme | Theme |
EditorCoordinatorOptions
Configuration for EditorCoordinator
interface EditorCoordinatorOptions| Member | Type | Summary |
|---|---|---|
| initialZoom? | number | Initial zoom level (default: 1.0) |
| onChange? | (document: Document) => void | Callback when the document changes |
| onError? | (error: Error) => void | Callback when an error occurs |
EditorCoordinatorSnapshot
The full snapshot exposed to UI frameworks
interface EditorCoordinatorSnapshot| Member | Type | Summary |
|---|---|---|
| fontsLoaded | boolean | Whether fonts have been loaded |
| isReady | boolean | Whether the editor is ready for interaction |
| loadingState | EditorLoadingState | Current loading state |
| parseError | string | null | Error message if loadingState is 'error' |
| version | number | Version counter |
| zoom | number | Current zoom level (1.0 = 100%) |
EditorHandle
Framework-agnostic interface for an imperatively mounted editor instance.
Returned by `renderAsync()` implementations (React, Vue, etc.). Consumers use this to interact with the editor programmatically.
interface EditorHandle| Member | Type | Summary |
|---|---|---|
| destroy | — | Unmount the editor and clean up. |
| focus | — | Focus the editor. |
| getDocument | — | Get the current parsed document model. |
| save | — | Save the document and return the DOCX as a Blob. |
EditorPluginCore
Framework-agnostic core plugin interface.
Contains all non-UI plugin capabilities: - ProseMirror plugins (decorations, keymaps, etc.) - State management (initialize, onStateChange, destroy) - CSS injection - Panel configuration
Framework adapters (ReactEditorPlugin, VueEditorPlugin) extend this with their own Panel component type and renderOverlay function.
interface EditorPluginCore<TState = any>| Member | Type | Summary |
|---|---|---|
| destroy? | () => void | Called when the plugin is being destroyed. Use this for cleanup (subscriptions, timers, etc.) |
| id | string | Unique plugin identifier |
| initialize? | (view: EditorView | null) => TState | Initialize plugin state when the plugin is first loaded. |
| name | string | Display name for the plugin |
| onStateChange? | (view: EditorView) => TState | undefined | Called when the editor state changes. Use this to update plugin-specific state based on document changes. |
| panelConfig? | PanelConfig | Configuration for the panel (position, size, etc.) |
| proseMirrorPlugins? | Plugin[] | ProseMirror plugins to register with the editor. These are merged with the editor's internal plugins. |
| styles? | string | CSS styles to inject for this plugin. Can be a string of CSS or a URL to a stylesheet. |
Endnote
Endnote (w:endnote)
interface Endnote| Member | Type | Summary |
|---|---|---|
| content | (Paragraph | Table)[] | Content. Per ECMA-376 §17.11.4 endnotes can hold the same blocks as the body — paragraphs and tables. See note on `Footnote.content`. |
| id | number | Endnote ID |
| noteType? | 'normal' | 'separator' | 'continuationSeparator' | 'continuationNotice' | Special endnote type |
| type | 'endnote' |
ErrorManagerSnapshot
ErrorManager snapshot
interface ErrorManagerSnapshot| Member | Type | Summary |
|---|---|---|
| notifications | ErrorNotification[] |
ErrorNotification
Error notification
interface ErrorNotification| Member | Type | Summary |
|---|---|---|
| details? | string | |
| dismissed? | boolean | |
| id | string | |
| message | string | |
| severity | ErrorSeverity | |
| timestamp | number |
ExtendedSelectionContext
Extended selection context with additional details
interface ExtendedSelectionContext extends SelectionContext| Member | Type | Summary |
|---|---|---|
| characterCount? | number | Selection character count |
| contentType? | 'prose' | 'list' | 'heading' | 'table' | 'mixed' | Content type hints |
| detectedLanguage? | string | Language detection hint |
| documentSummary? | string | Document summary for additional context |
| isMultiParagraph? | boolean | Is selection multi-paragraph |
| paragraphIndices? | number[] | Selected paragraph indices |
| wordCount? | number | Selection word count |
Footnote
Footnote (w:footnote)
interface Footnote| Member | Type | Summary |
|---|---|---|
| content | (Paragraph | Table)[] | Content. Per ECMA-376 §17.11.10 footnotes can hold the same blocks as the body — paragraphs and tables. The parser previously only collected w:p children which silently dropped any w:tbl inside a footnote; widened to match HeaderFooter / TableCell shape so the body pipeline (toProseDoc → toFlowBlocks) can render them uniformly. |
| id | number | Footnote ID |
| noteType? | 'normal' | 'separator' | 'continuationSeparator' | 'continuationNotice' | Special footnote type |
| type | 'footnote' |
FormatTextCommand
Apply formatting to a range
interface FormatTextCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| formatting | Partial<TextFormatting> | Formatting to apply |
| range | Range | Range to format |
| type | 'formatText' |
HeaderReference
Header or footer reference
interface HeaderReference| Member | Type | Summary |
|---|---|---|
| rId | string | |
| type | HeaderFooterType |
Hyperlink
Hyperlink (`w:hyperlink`) — wraps runs in a clickable link. External targets resolve through the relationships part (`rId` → `href`); internal targets reference a `BookmarkStart` anchor by name.
interface Hyperlink| Member | Type | Summary |
|---|---|---|
| anchor? | string | Internal bookmark anchor |
| children | (Run | BookmarkStart | BookmarkEnd)[] | Child runs |
| docLocation? | string | Document location |
| history? | boolean | Link history tracking |
| href? | string | Resolved URL (from relationships) |
| rId? | string | Relationship ID for external link |
| target? | string | Target frame |
| tooltip? | string | Tooltip text |
| type | 'hyperlink' |
Image_2
Embedded image (`w:drawing` with an inline or anchored picture). Carries the relationship-id pointer to the binary in `word/media/`, its resolved data URL (`src`), display dimensions, optional crop / transform / wrap behaviors, and anchor positioning for floating images.
See ECMA-376 §20.4 (DrawingML wordprocessingDrawing).
interface Image| Member | Type | Summary |
|---|---|---|
| allowOverlap? | boolean | `wp:anchor allowOverlap` — when true (default), anchored objects may overlap; when false, Word repositions them to avoid collisions. We don't currently reposition; we round-trip the flag so saving preserves the author's intent. |
| alt? | string | Alt text for accessibility |
| crop? | ImageCrop | Source-image crop (fractional, OOXML `a:srcRect`). |
| decorative? | boolean | Whether this is a decorative image |
| effects? | {
brightness?: number;
contrast?: number;
saturation?: number;
} | Image effects |
| filename? | string | Original filename |
| hlinkHref? | string | Hyperlink URL for clickable image |
| id? | string | Unique ID |
| layoutInCell? | boolean | `wp:anchor layoutInCell` — when true (default), an anchored image inside a table cell is constrained to the cell. When false, the image escapes the cell into the page area. Round-tripped on save. |
| mimeType? | string | Image MIME type |
| opacity? | number | Opacity in [0, 1] (OOXML `a:alphaModFix amt`). Undefined = fully opaque. |
| originalSize? | ImageSize | Original size before any transforms |
| outline? | ShapeOutline | Image outline/border |
| padding? | ImagePadding | Padding around image |
| position? | ImagePosition | Position for floating images |
| rId | string | Relationship ID for the image data |
| size | ImageSize | Image size |
| src? | string | Resolved image data (base64 or blob URL) |
| title? | string | Title/description |
| transform? | ImageTransform | Image transformations |
| type | 'image' | |
| wrap | ImageWrap | Wrap settings |
ImageSelectionInfo
Info about the currently selected/hovered image
interface ImageSelectionInfo| Member | Type | Summary |
|---|---|---|
| heightEmu | number | |
| isInline | boolean | |
| pageIndex | number | |
| pmPos | number | |
| rect | {
x: number;
y: number;
width: number;
height: number;
} | |
| widthEmu | number |
InsertHyperlinkCommand
Insert a hyperlink at a range
interface InsertHyperlinkCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| displayText? | string | Display text (replaces range text if provided) |
| range | Range | Range to make into a hyperlink |
| tooltip? | string | Tooltip |
| type | 'insertHyperlink' | |
| url | string | URL of the hyperlink |
InsertImageCommand
Insert an image at a position
interface InsertImageCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| alt? | string | Alt text |
| height? | number | Image height in pixels |
| position | Position | Position to insert at |
| src | string | Image source (base64 or URL) |
| type | 'insertImage' | |
| width? | number | Image width in pixels |
Insertion
Insertion wrapper (w:ins) — runs inserted by tracked changes
interface Insertion| Member | Type | Summary |
|---|---|---|
| content | (Run | Hyperlink)[] | Inserted content |
| info | TrackedChangeInfo | Tracked change metadata |
| type | 'insertion' |
InsertPosition_2
Insert position in the document
interface InsertPosition| Member | Type | Summary |
|---|---|---|
| offset? | number | Character offset within the run (optional) |
| paragraphIndex | number | Paragraph index in the document body |
| runIndex? | number | Run index within the paragraph (optional) |
InsertTableCommand
Insert a table at a position
interface InsertTableCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| columns | number | Number of columns |
| data? | string[][] | Optional table data |
| hasHeader? | boolean | Optional header row |
| position | Position | Position to insert at |
| rows | number | Number of rows |
| type | 'insertTable' |
InsertTextCommand
Insert text at a position
interface InsertTextCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| formatting? | TextFormatting | Optional formatting for the inserted text |
| position | Position | Position to insert at |
| text | string | Text to insert |
| type | 'insertText' |
LayoutCoordinatorSnapshot
The full snapshot exposed to UI frameworks
interface LayoutCoordinatorSnapshot| Member | Type | Summary |
|---|---|---|
| caretPosition | CaretPosition | null | Caret position for cursor overlay |
| hasLayout | boolean | Computed page layout, null until first computation |
| isDragging | boolean | Whether a text drag is in progress |
| isFocused | boolean | Whether the editor is focused |
| isImageInteracting | boolean | Whether an image interaction is in progress |
| isResizingColumn | boolean | Whether a column resize is in progress |
| selectedImageInfo | ImageSelectionInfo | null | Currently selected/hovered image |
| selectionRects | SelectionRect[] | Selection rectangles for range selection overlay |
| version | number | Version counter — incremented on every state change |
ListLevel
One indentation level of an abstract numbering definition (`w:lvl`). Carries the number format, the marker template (`lvlText` — e.g. `"%1.%2."`), the level's paragraph properties (indent, hanging) and character properties (font, size, color for the marker itself).
`ilvl` ranges 0-8 in standard Word documents.
interface ListLevel| Member | Type | Summary |
|---|---|---|
| ilvl | number | Level index (0-8) |
| isLgl? | boolean | Is legal numbering style |
| legacy? | {
legacy?: boolean;
legacySpace?: number;
legacyIndent?: number;
} | Legacy settings |
| lvlJc? | 'left' | 'center' | 'right' | Justification |
| lvlRestart? | number | Restart numbering from higher level |
| lvlText | string | Level text (e.g., "%1." or "•") |
| numFmt | NumberFormat | Number format |
| pPr? | ParagraphFormatting | Paragraph properties for this level |
| rPr? | TextFormatting | Run properties for the number/bullet |
| start? | number | Starting number |
| suffix? | LevelSuffix | Suffix after number |
McpSession
MCP session state
Maintains state across tool calls within a session.
interface McpSession| Member | Type | Summary |
|---|---|---|
| data | Map<string, unknown> | Custom session data |
| documents | Map<string, LoadedDocument> | Loaded documents by ID |
| id | string | Session ID |
McpToolDefinition
MCP tool definition
Describes a tool that can be called by AI clients through the MCP server.
interface McpToolDefinition| Member | Type | Summary |
|---|---|---|
| annotations? | McpToolAnnotations | Optional annotations for the tool |
| description | string | Human-readable description for AI |
| handler | McpToolHandler | Handler function for the tool. Receives validated input and returns a result. |
| inputSchema | JsonSchema | ZodSchemaLike | JSON Schema for tool input validation. Can be a Zod schema or plain JSON Schema object. |
| name | string | Tool name (used in MCP protocol) |
McpToolResult
MCP tool result
interface McpToolResult| Member | Type | Summary |
|---|---|---|
| content | McpToolContent[] | Result content |
| isError? | boolean | Whether this is an error result |
MoveFrom
Move-from wrapper (w:moveFrom) — content moved away from this position
interface MoveFrom| Member | Type | Summary |
|---|---|---|
| content | (Run | Hyperlink)[] | Moved content |
| info | TrackedChangeInfo | Tracked change metadata |
| type | 'moveFrom' |
MoveTo
Move-to wrapper (w:moveTo) — content moved into this position
interface MoveTo| Member | Type | Summary |
|---|---|---|
| content | (Run | Hyperlink)[] | Moved content |
| info | TrackedChangeInfo | Tracked change metadata |
| type | 'moveTo' |
NumberingDefinitions
Top-level numbering data from `numbering.xml` — the set of abstract templates and the per-document `NumberingInstance`s that reference them. Paragraphs reference a `numId` (instance), not an `abstractNumId` directly.
interface NumberingDefinitions| Member | Type | Summary |
|---|---|---|
| abstractNums | AbstractNumbering[] | Abstract numbering definitions |
| nums | NumberingInstance[] | Numbering instances |
PanelConfig
Configuration for plugin panel rendering.
interface PanelConfig| Member | Type | Summary |
|---|---|---|
| collapsible? | boolean | Whether the panel can be collapsed |
| defaultCollapsed? | boolean | Initial collapsed state |
| defaultSize | number | Default width/height of the panel |
| maxSize? | number | Maximum size |
| minSize? | number | Minimum size |
| position | 'left' | 'right' | 'bottom' | Where to render the panel |
| resizable? | boolean | Whether the panel is resizable |
Paragraph
Paragraph (`w:p`) — the primary block-level container in a Word document.
Every paragraph carries direct formatting (`formatting`), tracked property changes (`propertyChanges`), inline content (`content`), and optional list rendering / section break metadata. `paraId` is Word's stable identifier (`w14:paraId`) and is what `EditorBridge` and the agent toolkit use to address paragraphs.
See ECMA-376 §17.3.1.
interface Paragraph| Member | Type | Summary |
|---|---|---|
| content | ParagraphContent[] | Paragraph content |
| formatting? | ParagraphFormatting | Paragraph formatting |
| listRendering? | ListRendering | Computed list rendering (if this is a list item) |
| paraId? | string | Unique paragraph ID |
| propertyChanges? | ParagraphPropertyChange[] | Paragraph-level tracked property changes (w:pPrChange) |
| renderedPageBreakBefore? | boolean | Word's cached layout says this paragraph started on a new rendered page. |
| sectionProperties? | SectionProperties | Section properties (if this paragraph ends a section) |
| textId? | string | Text ID |
| type | 'paragraph' |
ParagraphContext
Paragraph context for selection
interface ParagraphContext| Member | Type | Summary |
|---|---|---|
| fullText | string | Full paragraph text |
| index | number | Paragraph index |
| style? | string | Paragraph style |
| wordCount | number | Word count |
ParagraphFormatting
Paragraph-level formatting (`w:pPr`) — alignment, indentation, spacing (before/after, line height), pagination flags (keepNext, keepLines, pageBreakBefore, widowControl), tabs, borders, shading, numbering reference, style reference, and frame/anchored-text properties.
Most fields mirror their ECMA-376 element names (see §17.3.1). Inheritance: direct formatting beats the linked style which beats document defaults.
interface ParagraphFormatting| Member | Type | Summary |
|---|---|---|
| afterAutospacing? | boolean | Auto space after (w:spacing/w:afterAutospacing) |
| alignment? | ParagraphAlignment | Paragraph alignment (w:jc) |
| beforeAutospacing? | boolean | Auto space before (w:spacing/w:beforeAutospacing) |
| bidi? | boolean | Text direction (w:bidi) |
| borders? | {
top?: BorderSpec;
bottom?: BorderSpec;
left?: BorderSpec;
right?: BorderSpec;
between?: BorderSpec;
bar?: BorderSpec;
} | Paragraph borders (w:pBdr) |
| contextualSpacing? | boolean | Contextual spacing — suppress space between paragraphs of the same style (w:contextualSpacing) |
| frame? | {
width?: number;
height?: number;
hAnchor?: 'text' | 'margin' | 'page';
vAnchor?: 'text' | 'margin' | 'page';
x?: number;
y?: number;
xAlign?: 'left' | 'center' | 'right' | 'inside' | 'outside';
yAlign?: 'top' | 'center' | 'bottom' | 'inside' | 'outside' | 'inline';
wrap?: 'around' | 'auto' | 'none' | 'notBeside' | 'through' | 'tight';
} | Text frame properties (w:framePr) |
| hangingIndent? | boolean | Whether first line is hanging indent |
| indentFirstLine? | number | First line indent in twips - positive for indent, negative for hanging (w:ind/w:firstLine or w:hanging) |
| indentLeft? | number | Left indent in twips (w:ind/w:left) |
| indentRight? | number | Right indent in twips (w:ind/w:right) |
| keepLines? | boolean | Keep lines together (w:keepLines) |
| keepNext? | boolean | Keep with next paragraph (w:keepNext) |
| lineSpacing? | number | Line spacing value (w:spacing/w:line) |
| lineSpacingRule? | LineSpacingRule | Line spacing rule (w:spacing/w:lineRule) |
| numPr? | {
numId?: number;
ilvl?: number;
} | Numbering properties (w:numPr) |
| outlineLevel? | number | Outline level 0-9 (w:outlineLvl) |
| pageBreakBefore? | boolean | Page break before (w:pageBreakBefore) |
| runProperties? | TextFormatting | Run properties to apply to all runs (w:rPr) |
| shading? | ShadingProperties | Paragraph shading (w:shd) |
| spaceAfter? | number | Spacing after in twips (w:spacing/w:after) |
| spaceBefore? | number | Spacing before in twips (w:spacing/w:before) |
| spacingExplicit? | SpacingExplicit | Per-side flags marking which `<w:spacing>` attrs came from this paragraph's own pPr (vs inherited). Word collapses style-inherited spacing on empty paragraphs but honors the explicit values. |
| styleId? | string | Paragraph style ID (w:pStyle) |
| suppressAutoHyphens? | boolean | Suppress auto hyphens (w:suppressAutoHyphens) |
| suppressLineNumbers? | boolean | Suppress line numbers (w:suppressLineNumbers) |
| tabs? | TabStop[] | Custom tab stops (w:tabs) |
| widowControl? | boolean | Widow/orphan control (w:widowControl) |
PluginLifecycleConfig
Plugin lifecycle configuration
interface PluginLifecycleConfig| Member | Type | Summary |
|---|---|---|
| destroy? | () => void | |
| id | string | |
| initialize? | (editorView: EditorView) => unknown | |
| onStateChange? | (editorView: EditorView) => unknown | |
| styles? | string |
PluginLifecycleSnapshot
PluginLifecycleManager snapshot
interface PluginLifecycleSnapshot| Member | Type | Summary |
|---|---|---|
| states | Map<string, unknown> | Map of plugin ID to plugin state |
| version | number | Version counter (incremented on any state change) |
PluginPanelProps
Props passed to plugin panel components (framework-agnostic base).
interface PluginPanelProps<TState = unknown>| Member | Type | Summary |
|---|---|---|
| doc | Node | null | Current ProseMirror document |
| editorView | EditorView | null | Current ProseMirror editor view |
| panelWidth | number | Width of the panel in pixels |
| pluginState | TState | Plugin-specific state (managed by the plugin) |
| renderedDomContext | RenderedDomContext | null | Context for the rendered DOM (LayoutPainter output). May be null if layout hasn't completed yet. |
| scrollToPosition | (pos: number) => void | Scroll editor to a specific position |
| selectRange | (from: number, to: number) => void | Select a range in the editor |
Position_2
Position within a document
interface Position| Member | Type | Summary |
|---|---|---|
| contentIndex? | number | Optional: Content index within paragraph (run, hyperlink, etc.) |
| offset | number | Offset within the paragraph in characters |
| paragraphIndex | number | Index of the paragraph (0-indexed) |
| sectionIndex? | number | Optional: Section index |
PositionCoordinates
Coordinates returned by position lookup in the rendered DOM.
interface PositionCoordinates| Member | Type | Summary |
|---|---|---|
| height | number | |
| x | number | |
| y | number |
ProcessTemplateOptions
Options for template processing
interface ProcessTemplateOptions| Member | Type | Summary |
|---|---|---|
| delimiters? | {
start?: string;
end?: string;
} | Delimiter settings |
| linebreaks? | boolean | Line breaks: keep raw n or convert to w:br |
| nullGetter? | 'keep' | 'empty' | 'error' | How to handle undefined variables |
| parser? | (tag: string) => {
get: (scope: Record<string, unknown>) => unknown;
} | Custom parser for variable names |
ProcessTemplateResult
Result of template processing
interface ProcessTemplateResult| Member | Type | Summary |
|---|---|---|
| buffer | ArrayBuffer | The processed document buffer |
| replacedVariables | string[] | Variables that were found and replaced |
| unreplacedVariables | string[] | Variables that were not replaced (no value provided) |
| warnings | string[] | Any warnings during processing |
Range_2
Range within a document
interface Range| Member | Type | Summary |
|---|---|---|
| collapsed? | boolean | Whether the range is collapsed (cursor position) |
| end | Position | End position |
| start | Position | Start position |
Relationship
Relationship entry
interface Relationship| Member | Type | Summary |
|---|---|---|
| id | string | Relationship ID (e.g., "rId1") |
| target | string | Target path or URL |
| targetMode? | 'External' | 'Internal' | Target mode |
| type | RelationshipType | Relationship type URI |
RenderedDomContext
Context for accessing the rendered DOM in the paged editor.
Provides DOM-based position mapping that works with the LayoutPainter output (visible pages). Use this for rendering overlays, annotations, and other visual elements positioned relative to rendered content.
The rendered DOM uses data-pm-start/data-pm-end attributes on spans to map between ProseMirror positions and DOM elements.
interface RenderedDomContext| Member | Type | Summary |
|---|---|---|
| findElementsForRange | — | Find DOM elements that overlap with a ProseMirror position range. |
| getContainerOffset | — | Offset of the pages container from its parent viewport. |
| getCoordinatesForPosition | — | Get pixel coordinates for a ProseMirror position in the rendered DOM. Returns null if the position cannot be found. |
| getRectsForRange | — | Get bounding rectangles for a range of text, accounting for line wraps. Returns rects relative to the pages container. |
| pagesContainer | HTMLElement | The container element holding all rendered pages. |
| zoom | number | Current zoom level (1 = 100%). |
ReplaceTextCommand
Replace text in a range
interface ReplaceTextCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| formatting? | TextFormatting | Optional formatting for the new text |
| range | Range | Range to replace |
| text | string | Replacement text |
| type | 'replaceText' |
Run
A run (`w:r`) — a contiguous span of inline content sharing one set of character properties (bold, italic, font, color, etc.). Runs are the atomic unit of character formatting; toggling bold on a selection that spans different formatting creates new runs.
See ECMA-376 §17.3.2.
interface Run```ts
const run: Run = {
type: 'run',
formatting: { bold: true },
content: [{ type: 'text', text: 'Hello' }],
};
```| Member | Type | Summary |
|---|---|---|
| content | RunContent[] | Run content (text, tabs, breaks, etc.) |
| formatting? | TextFormatting | Text formatting properties |
| propertyChanges? | RunPropertyChange[] | Run-level tracked property changes (w:rPrChange) |
| type | 'run' |
SavedDocumentData
Saved document data structure
interface SavedDocumentData| Member | Type | Summary |
|---|---|---|
| document | Document | The document JSON |
| documentId? | string | Optional document identifier |
| savedAt | string | When the document was saved |
| version | number | Version for format compatibility |
SectionProperties
Section properties (`w:sectPr`) — page geometry, margins, columns, header/footer references, and page numbering for one section of the document. Sections are introduced by inline `sectPr` markers on the terminating paragraph (`Paragraph.sectionProperties`) and the body's final `sectPr`.
All distance units are twips (1/20 of a point) on the wire. The layout engine converts to pixels.
See ECMA-376 §17.6.
interface SectionProperties| Member | Type | Summary |
|---|---|---|
| background? | {
color?: ColorValue;
themeColor?: ThemeColorSlot;
themeTint?: string;
themeShade?: string;
} | Page background |
| bidi? | boolean | Right-to-left section |
| columnCount? | number | Number of columns |
| columns? | Column[] | Individual column definitions |
| columnSpace? | number | Space between columns in twips |
| docGrid? | {
type?: 'default' | 'lines' | 'linesAndChars' | 'snapToChars';
linePitch?: number;
charSpace?: number;
} | Document grid |
| endnotePr? | EndnoteProperties | Endnote properties for this section |
| equalWidth? | boolean | Equal width columns |
| evenAndOddHeaders? | boolean | Different odd/even page headers/footers |
| footerDistance? | number | Footer distance from bottom in twips |
| footerReferences? | FooterReference[] | Footer references |
| footnotePr? | FootnoteProperties | Footnote properties for this section |
| gutter? | number | Gutter margin in twips |
| headerDistance? | number | Header distance from top in twips |
| headerReferences? | HeaderReference[] | Header references |
| lineNumbers? | {
start?: number;
countBy?: number;
distance?: number;
restart?: LineNumberRestart;
} | Line numbering settings |
| marginBottom? | number | Bottom margin in twips |
| marginLeft? | number | Left margin in twips |
| marginRight? | number | Right margin in twips |
| marginTop? | number | Top margin in twips |
| orientation? | PageOrientation | Page orientation |
| pageBorders? | {
top?: BorderSpec;
bottom?: BorderSpec;
left?: BorderSpec;
right?: BorderSpec;
display?: 'allPages' | 'firstPage' | 'notFirstPage';
offsetFrom?: 'page' | 'text';
zOrder?: 'front' | 'back';
} | Page borders |
| pageHeight? | number | Page height in twips |
| pageWidth? | number | Page width in twips |
| paperSrcFirst? | number | First page paper source |
| paperSrcOther? | number | Other pages paper source |
| sectionStart? | SectionStart | Section start type |
| separator? | boolean | Separator line between columns |
| titlePg? | boolean | Different first page header/footer |
| verticalAlign? | VerticalAlign | Vertical alignment of text |
SelectionContext
Context about the current selection
interface SelectionContext| Member | Type | Summary |
|---|---|---|
| formatting | Partial<TextFormatting> | Current formatting of selection |
| inHyperlink? | boolean | Is selection within a hyperlink |
| inTable? | boolean | Is selection within a table |
| paragraph | ParagraphContext | Paragraph containing selection |
| paragraphFormatting | Partial<ParagraphFormatting> | Current paragraph formatting |
| range | Range | Selection range |
| selectedText | string | Selected text |
| suggestedActions? | SuggestedAction[] | Suggested actions based on selection |
| textAfter | string | Text after selection (context) |
| textBefore | string | Text before selection (context) |
SelectionContextOptions
Options for building selection context
interface SelectionContextOptions| Member | Type | Summary |
|---|---|---|
| contextCharsAfter? | number | Characters of context after selection (default: 200) |
| contextCharsBefore? | number | Characters of context before selection (default: 200) |
| includeDocumentSummary? | boolean | Include document summary (default: true) |
| includeSuggestions? | boolean | Include suggested actions (default: true) |
| maxSuggestions? | number | Maximum suggested actions (default: 8) |
SelectionRect
Selection rectangle for rendering selection overlays
interface SelectionRect| Member | Type | Summary |
|---|---|---|
| height | number | |
| pageIndex | number | |
| width | number | |
| x | number | |
| y | number |
SetVariableCommand
Set template variable value
interface SetVariableCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| name | string | Variable name |
| type | 'setVariable' | |
| value | string | Variable value |
Shape
Shape/drawing object (wps:wsp)
interface Shape| Member | Type | Summary |
|---|---|---|
| customGeometry? | string | Custom geometry points |
| fill? | ShapeFill | Fill |
| id? | string | Unique ID |
| name? | string | Name |
| outline? | ShapeOutline | Outline/stroke |
| position? | ImagePosition | Position for floating shapes |
| shapeType | ShapeType | Shape type preset |
| size | ImageSize | Size in EMUs |
| textBody? | ShapeTextBody | Text content inside the shape |
| transform? | ImageTransform | Transform |
| type | 'shape' | |
| wrap? | ImageWrap | Wrap settings |
StabilizeFootnoteLayoutArgs
interface StabilizeFootnoteLayoutArgs| Member | Type | Summary |
|---|---|---|
| blocks | FlowBlock[] | |
| footnoteContentMap | Map<number, FootnoteContent> | |
| footnoteRefs | Array<{
footnoteId: number;
pmPos: number;
}> | |
| initialLayout | Layout | First-pass layout already computed by the caller without reserved heights. |
| layoutOpts | LayoutOptions | |
| measures | Measure[] |
StabilizeFootnoteLayoutResult
interface StabilizeFootnoteLayoutResult| Member | Type | Summary |
|---|---|---|
| converged | boolean | True if the loop converged before hitting MAX_FOOTNOTE_LAYOUT_PASSES. |
| layout | Layout | |
| pageFootnoteMap | Map<number, number[]> |
Style
Style definition from `styles.xml` — a named, reusable bundle of paragraph and/or character formatting. Word's "Heading 1", "Normal", "Title", and "List Bullet" are styles; user-defined styles look the same. `basedOn` chains styles for inheritance; `link` pairs a paragraph style with a matching character style.
See ECMA-376 §17.7.4.
interface Style| Member | Type | Summary |
|---|---|---|
| basedOn? | string | Based on style ID |
| default? | boolean | Is default style |
| link? | string | Linked style (paragraph/character pair) |
| name? | string | Display name |
| next? | string | Next style after Enter (for paragraph styles) |
| personal? | boolean | Personal style (custom) |
| pPr? | ParagraphFormatting | Paragraph properties (for paragraph/table styles) |
| qFormat? | boolean | Quick format in gallery |
| rPr? | TextFormatting | Run properties |
| styleId | string | Style ID |
| tblPr? | TableFormatting | Table properties (for table styles) |
| tblStylePr? | Array<{
type: 'band1Horz' | 'band1Vert' | 'band2Horz' | 'band2Vert' | 'firstCol' | 'firstRow' | 'lastCol' | 'lastRow' | 'neCell' | 'nwCell' | 'seCell' | 'swCell';
pPr?: ParagraphFormatting;
rPr?: TextFormatting;
tblPr?: TableFormatting;
trPr?: TableRowFormatting;
tcPr?: TableCellFormatting;
}> | Conditional table style parts |
| tcPr? | TableCellFormatting | Table cell properties |
| trPr? | TableRowFormatting | Table row properties |
| type | StyleType | Style type |
| uiPriority? | number | UI sort priority |
| unhideWhenUsed? | boolean | Unhide when used |
StyleDefinitions
Style definitions from styles.xml
interface StyleDefinitions| Member | Type | Summary |
|---|---|---|
| docDefaults? | DocDefaults | Document defaults |
| latentStyles? | {
defLockedState?: boolean;
defUIPriority?: number;
defSemiHidden?: boolean;
defUnhideWhenUsed?: boolean;
defQFormat?: boolean;
count?: number;
} | Latent styles |
| styles | Style[] | Style definitions |
SuggestedAction
Suggested action for context menu
interface SuggestedAction| Member | Type | Summary |
|---|---|---|
| description? | string | Description |
| icon? | string | Icon name |
| id | string | Action ID |
| label | string | Display label |
| priority? | number | Priority (higher = more prominent) |
Table
Table (`w:tbl`) — a block-level grid of rows × cells. Tables carry their own formatting layer (borders, shading, alignment, indent, floating placement) and an explicit column-width grid in twips. Tables can nest arbitrarily through `TableCell.content`.
See ECMA-376 §17.4.
interface Table| Member | Type | Summary |
|---|---|---|
| columnWidths? | number[] | Column widths in twips |
| formatting? | TableFormatting | Table formatting |
| propertyChanges? | TablePropertyChange[] | Table-level tracked property changes (w:tblPrChange) |
| rows | TableRow[] | Table rows |
| type | 'table' |
TableCell
Table cell (`w:tc`). Holds nested block content (paragraphs and nested tables), cell-level formatting (borders, shading, vertical merge), tracked property changes, and tracked structural changes for cell insert/delete/merge operations.
interface TableCell| Member | Type | Summary |
|---|---|---|
| content | (Paragraph | Table)[] | Cell content (paragraphs, tables, etc.) |
| formatting? | TableCellFormatting | Cell formatting |
| propertyChanges? | TableCellPropertyChange[] | Cell-level tracked property changes (w:tcPrChange) |
| structuralChange? | TableStructuralChangeInfo | Tracked structural changes (cell insert/delete/merge) |
| type | 'tableCell' |
TableRow
Table row (`w:tr`) — an ordered list of `TableCell` plus row-level formatting (height, repeated header, cantSplit) and tracked changes for inserts/deletes.
interface TableRow| Member | Type | Summary |
|---|---|---|
| cells | TableCell[] | Cells in this row |
| formatting? | TableRowFormatting | Row formatting |
| propertyChanges? | TableRowPropertyChange[] | Row-level tracked property changes (w:trPrChange) |
| structuralChange? | TableStructuralChangeInfo | Tracked structural changes (row insert/delete) |
| type | 'tableRow' |
TableSelectionSnapshot
TableSelectionManager snapshot
interface TableSelectionSnapshot| Member | Type | Summary |
|---|---|---|
| selectedCell | CellCoordinates | null | Currently selected cell, or null if no selection |
TextBox
Text box (floating text container)
interface TextBox| Member | Type | Summary |
|---|---|---|
| content | Paragraph[] | Text content |
| fill? | ShapeFill | Fill |
| id? | string | Unique ID |
| margins? | {
top?: number;
bottom?: number;
left?: number;
right?: number;
} | Internal margins |
| outline? | ShapeOutline | Outline |
| position? | ImagePosition | Position |
| size | ImageSize | Size |
| type | 'textBox' | |
| wrap? | ImageWrap | Wrap settings |
TextContent
Plain text run content (`w:t`). `preserveSpace` mirrors the `xml:space="preserve"` attribute and matters for runs that begin or end with whitespace — without it, Word collapses leading/trailing spaces.
interface TextContent| Member | Type | Summary |
|---|---|---|
| preserveSpace? | boolean | Preserve whitespace (xml:space="preserve") |
| text | string | The text string |
| type | 'text' |
TextFormatting
Character-level formatting (`w:rPr`) — the full set of run properties Word supports: weight, slant, font, size, color, highlight, underline, strikethrough, vertical position, language, complex-script variants, spacing/kerning, emphasis marks, and more.
Most fields mirror their ECMA-376 element names (see §17.3.2). Missing keys inherit from the run's paragraph style → linked style → document defaults chain.
interface TextFormatting| Member | Type | Summary |
|---|---|---|
| allCaps? | boolean | All caps (w:caps) |
| bold? | boolean | Bold (w:b) |
| boldCs? | boolean | Bold complex script (w:bCs) |
| color? | ColorValue | Text color (w:color) |
| cs? | boolean | Complex script formatting (w:cs) |
| doubleStrike? | boolean | Double strikethrough (w:dstrike) |
| effect? | TextEffect | Text effect animation (w:effect) |
| emboss? | boolean | Emboss effect (w:emboss) |
| emphasisMark? | EmphasisMark | Emphasis mark (w:em) |
| fontFamily? | {
ascii?: string;
hAnsi?: string;
eastAsia?: string;
cs?: string;
asciiTheme?: 'majorAscii' | 'majorHAnsi' | 'majorEastAsia' | 'majorBidi' | 'minorAscii' | 'minorHAnsi' | 'minorEastAsia' | 'minorBidi';
hAnsiTheme?: string;
eastAsiaTheme?: string;
csTheme?: string;
} | Font family (w:rFonts) |
| fontSize? | number | Font size in half-points (w:sz) - e.g., 24 = 12pt |
| fontSizeCs? | number | Font size complex script (w:szCs) |
| highlight? | 'black' | 'blue' | 'cyan' | 'darkBlue' | 'darkCyan' | 'darkGray' | 'darkGreen' | 'darkMagenta' | 'darkRed' | 'darkYellow' | 'green' | 'lightGray' | 'magenta' | 'none' | 'red' | 'white' | 'yellow' | Highlight/background color (w:highlight) |
| imprint? | boolean | Imprint/engrave effect (w:imprint) |
| italic? | boolean | Italic (w:i) |
| italicCs? | boolean | Italic complex script (w:iCs) |
| kerning? | number | Kerning threshold in half-points (w:kern) |
| outline? | boolean | Outline effect (w:outline) |
| position? | number | Raised/lowered text position in half-points (w:position) |
| rtl? | boolean | Right-to-left text (w:rtl) |
| scale? | number | Horizontal text scale percentage (w:w) |
| shading? | ShadingProperties | Character shading (w:shd) |
| shadow? | boolean | Shadow effect (w:shadow) |
| smallCaps? | boolean | Small caps (w:smallCaps) |
| spacing? | number | Character spacing in twips (w:spacing) |
| strike? | boolean | Strikethrough (w:strike) |
| styleId? | string | Character style ID (w:rStyle) |
| underline? | {
style: UnderlineStyle;
color?: ColorValue;
} | Underline style and color (w:u) |
| vertAlign? | 'baseline' | 'superscript' | 'subscript' | Superscript/subscript (w:vertAlign) |
Theme
Theme (from theme1.xml)
interface Theme| Member | Type | Summary |
|---|---|---|
| colorScheme? | ThemeColorScheme | Color scheme |
| fontScheme? | ThemeFontScheme | Font scheme |
| formatScheme? | {
name?: string;
} | Format scheme (fills, lines, effects) - simplified |
| name? | string | Theme name |
ThemeColorScheme
Theme color scheme (a:clrScheme)
interface ThemeColorScheme| Member | Type | Summary |
|---|---|---|
| accent1? | string | Accent colors 1-6 |
| accent2? | string | |
| accent3? | string | |
| accent4? | string | |
| accent5? | string | |
| accent6? | string | |
| dk1? | string | Dark 1 color (usually black) |
| dk2? | string | Dark 2 color |
| folHlink? | string | Followed hyperlink color |
| hlink? | string | Hyperlink color |
| lt1? | string | Light 1 color (usually white) |
| lt2? | string | Light 2 color |
ThemeFont
Theme font (with script variants)
interface ThemeFont| Member | Type | Summary |
|---|---|---|
| cs? | string | Complex script font |
| ea? | string | East Asian font |
| fonts? | Record<string, string> | Script-specific fonts |
| latin? | string | Latin font |
ThemeFontScheme
Theme font scheme (a:fontScheme)
interface ThemeFontScheme| Member | Type | Summary |
|---|---|---|
| majorFont? | ThemeFont | Major font (headings) |
| minorFont? | ThemeFont | Minor font (body text) |
ThemeMatrixCell
Theme color matrix cell
interface ThemeMatrixCell| Member | Type | Summary |
|---|---|---|
| hex | string | Resolved hex color (6 chars, no #) |
| label | string | Human-readable label (e.g., "Accent 1, Lighter 60%") |
| shade? | string | Shade hex modifier if applicable (e.g., "BF") |
| themeSlot | ThemeColorSlot | Theme color slot |
| tint? | string | Tint hex modifier if applicable (e.g., "CC") |
TrackedChangeInfo
Tracked change metadata (w:ins, w:del attributes)
interface TrackedChangeInfo| Member | Type | Summary |
|---|---|---|
| author | string | Author who made the change |
| date? | string | Date of the change |
| id | number | Revision ID |
VariableDetectionResult
Result of variable detection
interface VariableDetectionResult| Member | Type | Summary |
|---|---|---|
| byLocation | {
body: string[];
headers: string[];
footers: string[];
footnotes: string[];
endnotes: string[];
textBoxes: string[];
} | Variables by location |
| occurrences | VariableOccurrence[] | Variable occurrences with positions |
| totalOccurrences | number | Total count of variable occurrences |
| variables | string[] | Unique variable names sorted alphabetically |
VariableOccurrence
A single variable occurrence with location info
interface VariableOccurrence| Member | Type | Summary |
|---|---|---|
| location | 'body' | 'header' | 'footer' | 'footnote' | 'endnote' | 'textBox' | Location type |
| name | string | Variable name (without braces) |
| paragraphIndex? | number | Paragraph index within location |
| sectionIndex? | number | Section index (for headers/footers) |
Type aliases(21)
AgentCommand
Union of all command types
type AgentCommand = InsertTextCommand | ReplaceTextCommand | DeleteTextCommand | FormatTextCommand | FormatParagraphCommand | ApplyStyleCommand | InsertTableCommand | InsertImageCommand | InsertHyperlinkCommand | RemoveHyperlinkCommand | InsertParagraphBreakCommand | MergeParagraphsCommand | SplitParagraphCommand | SetVariableCommand | ApplyVariablesCommand;AIAction
AI action types for context menu
type AIAction = 'askAI' | 'rewrite' | 'expand' | 'summarize' | 'translate' | 'explain' | 'fixGrammar' | 'makeFormal' | 'makeCasual' | 'custom';AutoSaveStatus
Auto-save status
type AutoSaveStatus = 'idle' | 'saving' | 'saved' | 'error';BlockContent
Block-level content types
type BlockContent = Paragraph | Table | BlockSdt;ConvertFootnoteOptions
Options for [convertFootnoteToContent](convertFootnoteToContent).
type ConvertFootnoteOptions = {
styles?: StyleDefinitions | null;
theme?: Theme | null;
measureBlocks: MeasureBlocksFn;
};DocxInput
Any binary representation of a DOCX file that the editor can consume.
- `ArrayBuffer` — from `FileReader.readAsArrayBuffer()` or `fetch().arrayBuffer()` - `Uint8Array` — from Node.js `fs.readFile()` or streaming APIs - `Blob` — from drag-and-drop or `<input type="file">` - `File` — subclass of Blob, from `<input type="file">`
type DocxInput = ArrayBuffer | Uint8Array | Blob | File;EditorLoadingState
Editor loading state
type EditorLoadingState = 'idle' | 'parsing' | 'loading-fonts' | 'ready' | 'error';ErrorSeverity
Error severity levels
type ErrorSeverity = 'error' | 'warning' | 'info';type Field = SimpleField | ComplexField;FlowBlock
Union of every block kind the layout engine knows about.
Three switches over `block.kind` must stay in sync with this type: - `runLayoutPipeline` in `layout-engine/index.ts` (this package) - `measureBlock` in `packages/react/src/paged-editor/PagedEditor.tsx` - `measureBlock` in `packages/vue/src/composables/useDocxEditor.ts`
All three end in `assertExhaustiveFlowBlock(block, '<site>')` so adding a new variant here without updating every site is a typecheck error.
type FlowBlock = ParagraphBlock | TableBlock | ImageBlock | TextBoxBlock | SectionBreakBlock | PageBreakBlock | ColumnBreakBlock;FootnoteContent
Pre-calculated footnote content for layout and rendering.
type FootnoteContent = {
id: number;
displayNumber: number;
blocks: FlowBlock[];
measures: Measure[];
height: number;
};Final layout output ready for rendering/painting.
type Layout = {
pageSize: {
w: number;
h: number;
};
pages: Page[];
columns?: ColumnLayout;
headers?: Record<string, HeaderFooterLayout>;
footers?: Record<string, HeaderFooterLayout>;
pageGap?: number;
};McpToolHandler
MCP tool handler function
type McpToolHandler = (input: unknown, context: McpToolContext) => Promise<McpToolResult> | McpToolResult;Measure
Union of all measurement types.
type Measure = ParagraphMeasure | ImageMeasure | TableMeasure | TextBoxMeasure | SectionBreakMeasure | PageBreakMeasure | ColumnBreakMeasure;MeasureBlocksFn
Adapter-supplied block measurement function. The caller (React / Vue / etc.) supplies its platform's measure routine — at minimum paragraph + table + image + textBox — so this core helper stays Canvas-free.
type MeasureBlocksFn = (blocks: FlowBlock[], contentWidth: number) => Measure[];A rendered page containing positioned fragments.
type Page = {
number: number;
fragments: Fragment[];
margins: PageMargins;
size: {
w: number;
h: number;
};
orientation?: 'portrait' | 'landscape';
sectionIndex?: number;
headerFooterRefs?: {
headerDefault?: string;
headerFirst?: string;
headerEven?: string;
footerDefault?: string;
footerFirst?: string;
footerEven?: string;
};
footnoteIds?: number[];
footnoteReservedHeight?: number;
columns?: ColumnLayout;
};ParagraphContent
Inline content that can appear inside a paragraph. Covers runs (text), hyperlinks, bookmarks, fields, structured document tags, comment range markers, tracked-change wrappers, and math equations. Every node in this union carries a `type` discriminator so consumers can narrow at runtime.
type ParagraphContent = Run | Hyperlink | BookmarkStart | BookmarkEnd | SimpleField | ComplexField | InlineSdt | CommentRangeStart | CommentRangeEnd | Insertion | Deletion | MoveFrom | MoveTo | MoveFromRangeStart | MoveFromRangeEnd | MoveToRangeStart | MoveToRangeEnd | MathEquation;RunContent
All possible run content types
type RunContent = TextContent | TabContent | BreakContent | SymbolContent | NoteReferenceContent | FieldCharContent | InstrTextContent | SoftHyphenContent | NoBreakHyphenContent | DrawingContent | ShapeContent;TrackedRunChange
Run-level tracked wrappers represented in WordprocessingML.
type TrackedRunChange = Insertion | Deletion | MoveFrom | MoveTo;Variables(6)
docxtemplaterPlugin
Docxtemplater plugin for template variable functionality.
Dependency validation is handled lazily by `processTemplate` at call time, so no eager `initialize()` is needed.
docxtemplaterPlugin: CorePluginFOOTNOTE_SEPARATOR_HEIGHT
Separator line height + vertical padding in pixels.
FOOTNOTE_SEPARATOR_HEIGHT = 12MAX_FOOTNOTE_LAYOUT_PASSES
Hard cap on the multi-pass footnote layout loop. Reserving footnote space can move a reference to another page, so adapters keep remapping until the page→height contract is stable. Dense layouts converge in 2–3 passes in practice; 6 is a safe ceiling.
MAX_FOOTNOTE_LAYOUT_PASSES = 6pluginRegistry
Global plugin registry instance
Use this for registering plugins and accessing their capabilities.
pluginRegistry: PluginRegistryrgbToHex
rgbToHex: typeof cssColorToHexVERSION
eigenpal/docx-editor-core (default entry point)
Fat barrel that re-exports the parser, serializer, agent, plugin registry, and the most-used types. No React/DOM imports.
**When to import from `.` vs `./headless`:** identical for Node.js use; `.` is the convenient aggregate, `./headless` is its mirror with a slightly different name suffix. Adapter authors who only need a specific slice should prefer the smaller subpaths (`./docx`, `./agent`, `./prosemirror`, `./layout-*`, `./utils`) — they tree-shake better.
VERSION = "0.0.2"```ts
import { parseDocx, serializeDocx, resolveColor } from '@eigenpal/docx-editor-core';
```