import { D as DocxInput } from './index-B5A-J9GC.js'; export { a as DocumentAgent, b as DocxEditor, c as DocxEditorHandle, d as DocxEditorProps, e as DocxEditorRef, E as EditorMode, L as LocaleProvider, f as LocaleProviderProps, R as RenderAsyncOptions, V as VERSION, r as renderAsync, u as useTranslation } from './index-B5A-J9GC.js'; export { E as EditorPlugin, R as RenderedDomContext } from './types-BnIs4sE7.js'; export { P as PluginHost } from './PluginHost-zILZO7zX.js'; import { D as Document } from './document-CxOagoLQ.js'; import { P as Position, R as Range } from './agentApi-B2Y7kexW.js'; import { T as TextFormatting, P as ParagraphFormatting } from './content-REFGFfEH.js'; export { B as BorderSpec, L as LineSpacingRule, N as NumberFormat, a as ParagraphAlignment, b as TableBorders, c as TableCellFormatting } from './content-REFGFfEH.js'; export { L as LocaleStrings, P as PartialLocaleStrings, T as TranslationKey, a as Translations } from './types-BF48VxkC.js'; import 'react'; import 'prosemirror-view'; import 'prosemirror-state'; import './types-CW6HFAX6.js'; import 'react/jsx-runtime'; import 'prosemirror-model'; import '@eigenpal/docx-editor-i18n/en.json'; /** * Selection Tracker Plugin * * Tracks selection changes and emits events for toolbar state updates. * Provides the current selection context including: * - Text formatting at cursor/selection * - Paragraph formatting * - Selection range information */ /** * Selection context for toolbar state */ interface SelectionContext { /** Whether there's a non-collapsed selection */ hasSelection: boolean; /** Whether selection spans multiple paragraphs */ isMultiParagraph: boolean; /** Current text formatting at cursor/selection */ textFormatting: TextFormatting; /** Current paragraph formatting */ paragraphFormatting: ParagraphFormatting; /** Start paragraph index */ startParagraphIndex: number; /** End paragraph index */ endParagraphIndex: number; /** Whether cursor is in a list */ inList: boolean; /** List type if in list */ listType?: 'bullet' | 'numbered'; /** List level (0-8) */ listLevel?: number; /** Active comment IDs at cursor position */ activeCommentIds: number[]; /** Whether cursor is inside a tracked insertion */ inInsertion: boolean; /** Whether cursor is inside a tracked deletion */ inDeletion: boolean; } /** * Main Parser Orchestrator - Unified parseDocx function * * Coordinates all sub-parsers to produce a complete Document model. * Handles loading order, dependency resolution, and font preloading. * * Parsing order: * 1. Unzip DOCX package * 2. Parse relationships * 3. Parse theme (needed for style color/font resolution) * 4. Parse styles (depends on theme) * 5. Parse numbering * 6. Parse document body (depends on styles, theme, numbering, rels) * 7. Parse headers/footers (depends on styles, theme, numbering, rels) * 8. Parse footnotes/endnotes (depends on styles, theme, numbering, rels) * 9. Extract and load fonts * 10. Build media file map * 11. Assemble final Document */ /** * Progress callback for tracking parsing stages */ type ProgressCallback = (stage: string, percent: number) => void; /** * Parsing options */ interface ParseOptions { /** Progress callback for tracking parsing stages */ onProgress?: ProgressCallback; /** Whether to preload fonts (default: true) */ preloadFonts?: boolean; /** Whether to parse headers/footers (default: true) */ parseHeadersFooters?: boolean; /** Whether to parse footnotes/endnotes (default: true) */ parseNotes?: boolean; /** Whether to detect template variables (default: true) */ detectVariables?: boolean; } /** * Parse a DOCX file into a complete Document model * * @param input - DOCX file as ArrayBuffer, Uint8Array, Blob, or File * @param options - Parsing options * @returns Promise resolving to Document * @throws Error if parsing fails */ declare function parseDocx(input: DocxInput, options?: ParseOptions): Promise; /** * Core Plugin System Types * * Defines the interfaces for headless plugins that work in Node.js * without React/DOM dependencies. These plugins extend DocumentAgent * with additional commands and expose MCP tools for AI integration. */ /** * 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 { /** Unique plugin identifier */ id: string; /** Human-readable plugin name */ name: string; /** Plugin version (semver) */ version?: string; /** Plugin description */ description?: string; /** * Command handlers this plugin provides. * DocumentAgent dispatches commands to these handlers. * * @example * ```ts * commandHandlers: { * 'insertTemplateVariable': (doc, cmd) => { * // Transform document * return modifiedDoc; * }, * } * ``` */ commandHandlers?: Record; /** * MCP tools this plugin exposes. * MCP server collects these from all plugins. */ mcpTools?: McpToolDefinition[]; /** * Optional setup when plugin is registered. * Called once during plugin registration. */ initialize?: () => void | Promise; /** * Optional cleanup when plugin is unregistered. */ destroy?: () => void | Promise; /** * Dependencies on other plugins (by ID). * The registry ensures dependencies are loaded first. */ dependencies?: string[]; } /** * Command handler function type * * Receives a document and a command, returns a modified document. * Must be pure/immutable - always return a new document. */ type CommandHandler = (doc: Document, command: PluginCommand) => Document; /** * Extended command type for plugins * * Plugins can define custom command types beyond the built-in AgentCommand types. */ interface PluginCommand { /** Command type identifier */ type: string; /** Unique command ID (for undo tracking) */ id?: string; /** Position for positional commands */ position?: Position; /** Range for range-based commands */ range?: Range; /** Additional command-specific data */ [key: string]: unknown; } /** * MCP tool definition * * Describes a tool that can be called by AI clients through the MCP server. */ interface McpToolDefinition { /** Tool name (used in MCP protocol) */ name: string; /** Human-readable description for AI */ description: string; /** * JSON Schema for tool input validation. * Can be a Zod schema or plain JSON Schema object. */ inputSchema: JsonSchema | ZodSchemaLike; /** * Handler function for the tool. * Receives validated input and returns a result. */ handler: McpToolHandler; /** * Optional annotations for the tool */ annotations?: McpToolAnnotations; } /** * MCP tool handler function */ type McpToolHandler = (input: unknown, context: McpToolContext) => Promise | McpToolResult; /** * Context passed to MCP tool handlers */ interface McpToolContext { /** Current document (if loaded) */ document?: Document; /** Document buffer (if loaded) */ documentBuffer?: ArrayBuffer; /** Session state */ session: McpSession; /** Logger for debugging */ log: (message: string, data?: unknown) => void; } /** * MCP session state * * Maintains state across tool calls within a session. */ interface McpSession { /** Session ID */ id: string; /** Loaded documents by ID */ documents: Map; /** Custom session data */ data: Map; } /** * A loaded document in the session */ interface LoadedDocument { /** Document ID */ id: string; /** Parsed document */ document: Document; /** Original buffer (for repacking) */ buffer?: ArrayBuffer; /** Source filename or path */ source?: string; /** Last modified timestamp */ lastModified: number; } /** * MCP tool result */ interface McpToolResult { /** Result content */ content: McpToolContent[]; /** Whether this is an error result */ isError?: boolean; } /** * MCP tool content types */ type McpToolContent = { type: 'text'; text: string; } | { type: 'image'; data: string; mimeType: string; } | { type: 'resource'; uri: string; mimeType?: string; text?: string; }; /** * MCP tool annotations */ interface McpToolAnnotations { /** Tool category for organization */ category?: string; /** Whether this tool modifies the document */ readOnly?: boolean; /** Estimated cost/complexity */ complexity?: 'low' | 'medium' | 'high'; /** Example usage */ examples?: McpToolExample[]; } /** * MCP tool example */ interface McpToolExample { /** Example description */ description: string; /** Example input */ input: unknown; /** Expected output description */ output?: string; } /** * JSON Schema definition (subset) */ interface JsonSchema { type?: string | string[]; properties?: Record; items?: JsonSchema; required?: string[]; description?: string; enum?: unknown[]; default?: unknown; minimum?: number; maximum?: number; minLength?: number; maxLength?: number; pattern?: string; format?: string; additionalProperties?: boolean | JsonSchema; anyOf?: JsonSchema[]; oneOf?: JsonSchema[]; allOf?: JsonSchema[]; $ref?: string; } /** * Zod-like schema interface for compatibility */ interface ZodSchemaLike { _def?: unknown; parse?: (data: unknown) => unknown; safeParse?: (data: unknown) => { success: boolean; data?: unknown; error?: unknown; }; } /** * Plugin lifecycle events */ type PluginEvent = { type: 'registered'; plugin: CorePlugin; } | { type: 'unregistered'; pluginId: string; } | { type: 'error'; pluginId: string; error: Error; }; /** * Plugin event listener */ type PluginEventListener = (event: PluginEvent) => void; /** * Plugin configuration options */ interface PluginOptions { /** Enable debug logging */ debug?: boolean; /** Custom configuration */ config?: Record; } /** * Result of plugin registration */ interface PluginRegistrationResult { /** Whether registration succeeded */ success: boolean; /** Registered plugin (if successful) */ plugin?: CorePlugin; /** Error message (if failed) */ error?: string; /** Warning messages */ warnings?: string[]; } /** * Plugin Registry * * Central registry for core plugins. Manages plugin lifecycle, * collects command handlers from all plugins, and aggregates * MCP tool definitions for the MCP server. */ /** * Plugin Registry - manages core plugins * * @example * ```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'); * ``` */ declare class PluginRegistry { private plugins; private commandHandlers; private eventListeners; private initialized; /** * Register a plugin * * @param plugin - The plugin to register * @param options - Optional configuration * @returns Registration result */ register(plugin: CorePlugin, options?: PluginOptions): PluginRegistrationResult; /** * Unregister a plugin * * @param pluginId - ID of the plugin to unregister * @returns Whether unregistration succeeded */ unregister(pluginId: string): boolean; /** * Get a registered plugin by ID * * @param id - Plugin ID * @returns The plugin or undefined */ get(id: string): CorePlugin | undefined; /** * Get all registered plugins * * @returns Array of all plugins */ getAll(): CorePlugin[]; /** * Check if a plugin is registered * * @param id - Plugin ID * @returns Whether the plugin is registered */ has(id: string): boolean; /** * Get number of registered plugins */ get size(): number; /** * Get a command handler for a command type * * @param commandType - The command type * @returns The handler or undefined */ getCommandHandler(commandType: string): CommandHandler | undefined; /** * Get all registered command types * * @returns Array of command type strings */ getCommandTypes(): string[]; /** * Check if a command type has a handler * * @param commandType - The command type * @returns Whether a handler exists */ hasCommandHandler(commandType: string): boolean; /** * Get all MCP tools from all registered plugins * * @returns Array of MCP tool definitions */ getMcpTools(): McpToolDefinition[]; /** * Get MCP tools from a specific plugin * * @param pluginId - Plugin ID * @returns Array of MCP tool definitions */ getMcpToolsForPlugin(pluginId: string): McpToolDefinition[]; /** * Get an MCP tool by name * * @param toolName - Tool name * @returns The tool definition or undefined */ getMcpTool(toolName: string): McpToolDefinition | undefined; /** * Add an event listener * * @param listener - Event listener function */ addEventListener(listener: PluginEventListener): void; /** * Remove an event listener * * @param listener - Event listener function */ removeEventListener(listener: PluginEventListener): void; /** * Emit an event to all listeners */ private emit; /** * Clear all registered plugins * * Useful for testing or resetting state. */ clear(): void; /** * Get registry state for debugging */ getDebugInfo(): { plugins: string[]; commandTypes: string[]; mcpTools: string[]; initialized: string[]; }; } /** * Global plugin registry instance * * Use this for registering plugins and accessing their capabilities. */ declare const pluginRegistry: PluginRegistry; export { Document, Position, Range, type SelectionContext, TextFormatting, parseDocx, pluginRegistry };