@eigenpal/docx-js-editor 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,361 @@
1
+ export { A as AgentContextOptions, S as ContextSelectionOptions, C as CreateEmptyDocumentOptions, D as DocumentAgent, E as ExtendedSelectionContext, F as FormattedTextSegment, a as FormattingSummary, I as InsertHyperlinkOptions, b as InsertImageOptions, c as InsertTableOptions, d as InsertTextOptions, P as ProcessTemplateOptions, e as ProcessTemplateResult, f as SelectionContextOptions, T as TemplateError, g as blendColors, h as buildExtendedSelectionContext, i as buildSelectionContext, j as buildSelectionContextFromContext, k as colorsEqual, l as createAgent, m as createAgentFromDocument, n as createDocumentWithText, o as createEmptyDocument, p as createRgbColor, q as createTemplateProcessor, r as createThemeColor, s as darkenColor, D as default, t as emuToPixels, u as emuToTwips, v as executeCommand, w as executeCommands, x as formatPx, y as getAgentContext, z as getContrastingColor, B as getDocumentSummary, G as getMissingVariables, H as getSelectionFormattingSummary, J as getTemplateTags, K as halfPointsToPixels, L as isBlack, M as isWhite, N as lightenColor, O as parseColorString, Q as parseDocx, R as pixelsToEmu, U as pixelsToTwips, V as pointsToPixels, W as previewTemplate, X as processTemplate, Y as processTemplateAdvanced, Z as processTemplateAsBlob, _ as processTemplateDetailed, $ as resolveColor, a0 as resolveHighlightColor, a1 as resolveShadingColor, a2 as serializeDocumentBody, a3 as serializeDocx, a4 as serializeSectionProperties, a5 as twipsToEmu, a6 as twipsToPixels, a7 as validateTemplate } from './colorResolver-C-tITrbI.cjs';
2
+ import { D as DocumentBody, e as Paragraph, T as TextFormatting, H as Hyperlink, R as Run, f as Table, g as Position, h as Document } from './types-BJXChtaM.cjs';
3
+ export { A as AIAction, i as AIActionRequest, j as AgentCommand, k as AgentContext, l as AgentResponse, m as ApplyStyleCommand, n as ApplyVariablesCommand, B as BlockContent, b as CommandHandler, o as CommandResult, C as CorePlugin, p as DEFAULT_AI_ACTIONS, q as DeleteTextCommand, r as DocxPackage, E as Endnote, F as Footnote, s as FormatParagraphCommand, t as FormatTextCommand, I as Image, u as InsertHyperlinkCommand, v as InsertImageCommand, w as InsertTableCommand, x as InsertTextCommand, J as JsonSchema, L as ListLevel, y as LoadedDocument, d as McpSession, z as McpToolAnnotations, G as McpToolContent, K as McpToolContext, M as McpToolDefinition, N as McpToolHandler, O as McpToolResult, Q as NumberingDefinitions, S as ParagraphContext, U as ParagraphFormatting, V as ParagraphOutline, C as Plugin, W as PluginCommand, b as PluginCommandHandler, X as PluginEvent, c as PluginEventListener, P as PluginOptions, a as PluginRegistrationResult, Y as Range, Z as Relationship, _ as ReplaceTextCommand, $ as RunContent, a0 as SectionInfo, a1 as SectionProperties, a2 as SelectionContext, a3 as SetVariableCommand, a4 as Style, a5 as StyleDefinitions, a6 as StyleInfo, a7 as SuggestedAction, a8 as TableCell, a9 as TableRow, aa as TextContent, ab as Theme, M as ToolDefinition, N as ToolHandler, O as ToolResult, ac as ZodSchemaLike, ad as comparePositions, ae as createCollapsedRange, af as createCommand, ag as createRange, ah as getActionDescription, ai as getActionLabel, aj as isPositionInRange, ak as isZodSchema } from './types-BJXChtaM.cjs';
4
+ export { P as PluginRegistry, c as createPluginRegistrar, p as pluginRegistry, r as registerPlugins } from './registry-DeeU0bQB.cjs';
5
+
6
+ /**
7
+ * Shared Text Utilities for Agent Module
8
+ *
9
+ * Common text extraction and manipulation utilities used by
10
+ * context.ts, selectionContext.ts, and other agent-related code.
11
+ *
12
+ * Consolidates duplicated helper functions into a single location.
13
+ */
14
+
15
+ /**
16
+ * Get plain text from a paragraph
17
+ */
18
+ declare function getParagraphText(paragraph: Paragraph): string;
19
+ /**
20
+ * Get plain text from a run
21
+ */
22
+ declare function getRunText(run: Run): string;
23
+ /**
24
+ * Get plain text from a hyperlink
25
+ */
26
+ declare function getHyperlinkText(hyperlink: Hyperlink): string;
27
+ /**
28
+ * Get plain text from a table
29
+ */
30
+ declare function getTableText(table: Table): string;
31
+ /**
32
+ * Get plain text from document body
33
+ */
34
+ declare function getBodyText(body: DocumentBody): string;
35
+ /**
36
+ * Count words in text
37
+ */
38
+ declare function countWords(text: string): number;
39
+ /**
40
+ * Count characters in text
41
+ */
42
+ declare function countCharacters(text: string, includeSpaces?: boolean): number;
43
+ /**
44
+ * Get word count from document body
45
+ */
46
+ declare function getBodyWordCount(body: DocumentBody): number;
47
+ /**
48
+ * Get character count from document body
49
+ */
50
+ declare function getBodyCharacterCount(body: DocumentBody): number;
51
+ /**
52
+ * Get text before a position
53
+ *
54
+ * @param paragraphs - Array of paragraphs
55
+ * @param position - Position to get text before
56
+ * @param maxChars - Maximum characters to return
57
+ * @returns Text before the position
58
+ */
59
+ declare function getTextBefore(paragraphs: Paragraph[], position: Position, maxChars: number): string;
60
+ /**
61
+ * Get text after a position
62
+ *
63
+ * @param paragraphs - Array of paragraphs
64
+ * @param position - Position to get text after
65
+ * @param maxChars - Maximum characters to return
66
+ * @returns Text after the position
67
+ */
68
+ declare function getTextAfter(paragraphs: Paragraph[], position: Position, maxChars: number): string;
69
+ /**
70
+ * Get formatting at a specific position in a paragraph
71
+ *
72
+ * @param paragraph - The paragraph to check
73
+ * @param offset - Character offset in the paragraph
74
+ * @returns Formatting at that position
75
+ */
76
+ declare function getFormattingAtPosition(paragraph: Paragraph, offset: number): Partial<TextFormatting>;
77
+ /**
78
+ * Check if position is within a hyperlink
79
+ *
80
+ * @param paragraph - The paragraph to check
81
+ * @param offset - Character offset in the paragraph
82
+ * @returns True if position is in a hyperlink
83
+ */
84
+ declare function isPositionInHyperlink(paragraph: Paragraph, offset: number): boolean;
85
+ /**
86
+ * Get hyperlink at position
87
+ *
88
+ * @param paragraph - The paragraph to check
89
+ * @param offset - Character offset in the paragraph
90
+ * @returns The hyperlink at that position, or undefined
91
+ */
92
+ declare function getHyperlinkAtPosition(paragraph: Paragraph, offset: number): Hyperlink | undefined;
93
+ /**
94
+ * Check if style ID represents a heading
95
+ *
96
+ * @param styleId - Style ID to check
97
+ * @returns True if it's a heading style
98
+ */
99
+ declare function isHeadingStyle(styleId?: string): boolean;
100
+ /**
101
+ * Parse heading level from style ID
102
+ *
103
+ * @param styleId - Style ID to parse
104
+ * @returns Heading level (1-9) or undefined
105
+ */
106
+ declare function parseHeadingLevel(styleId?: string): number | undefined;
107
+ /**
108
+ * Check if document body has images
109
+ *
110
+ * @param body - Document body to check
111
+ * @returns True if contains images
112
+ */
113
+ declare function hasImages(body: DocumentBody): boolean;
114
+ /**
115
+ * Check if document body has hyperlinks
116
+ *
117
+ * @param body - Document body to check
118
+ * @returns True if contains hyperlinks
119
+ */
120
+ declare function hasHyperlinks(body: DocumentBody): boolean;
121
+ /**
122
+ * Check if document body has tables
123
+ *
124
+ * @param body - Document body to check
125
+ * @returns True if contains tables
126
+ */
127
+ declare function hasTables(body: DocumentBody): boolean;
128
+ /**
129
+ * Get all paragraphs from document body
130
+ *
131
+ * @param body - Document body
132
+ * @returns Array of paragraphs
133
+ */
134
+ declare function getParagraphs(body: DocumentBody): Paragraph[];
135
+ /**
136
+ * Get paragraph at index from document body
137
+ *
138
+ * @param body - Document body
139
+ * @param index - Paragraph index (0-indexed)
140
+ * @returns Paragraph or undefined
141
+ */
142
+ declare function getParagraphAtIndex(body: DocumentBody, index: number): Paragraph | undefined;
143
+ /**
144
+ * Get block index for a paragraph index
145
+ *
146
+ * @param body - Document body
147
+ * @param paragraphIndex - Paragraph index
148
+ * @returns Block index or -1 if not found
149
+ */
150
+ declare function getBlockIndexForParagraph(body: DocumentBody, paragraphIndex: number): number;
151
+
152
+ /**
153
+ * DOCX Repacker - Repack modified document into valid DOCX
154
+ *
155
+ * Takes a Document with modified content and creates a new DOCX file
156
+ * by updating document.xml while preserving all other files from
157
+ * the original ZIP archive.
158
+ *
159
+ * This ensures round-trip fidelity:
160
+ * - styles.xml, theme1.xml, fontTable.xml remain untouched
161
+ * - Media files preserved
162
+ * - Relationships preserved
163
+ * - Only document.xml is updated with new content
164
+ *
165
+ * OOXML Package Structure:
166
+ * - [Content_Types].xml - Content type declarations
167
+ * - _rels/.rels - Package relationships
168
+ * - word/document.xml - Main document (modified)
169
+ * - word/styles.xml - Styles (preserved)
170
+ * - word/theme/theme1.xml - Theme (preserved)
171
+ * - word/numbering.xml - Numbering (preserved)
172
+ * - word/fontTable.xml - Font table (preserved)
173
+ * - word/settings.xml - Settings (preserved)
174
+ * - word/header*.xml - Headers (preserved)
175
+ * - word/footer*.xml - Footers (preserved)
176
+ * - word/footnotes.xml - Footnotes (preserved)
177
+ * - word/endnotes.xml - Endnotes (preserved)
178
+ * - word/media/* - Media files (preserved)
179
+ * - word/_rels/document.xml.rels - Document relationships (preserved)
180
+ * - docProps/* - Document properties (preserved)
181
+ */
182
+
183
+ /**
184
+ * Options for repacking DOCX
185
+ */
186
+ interface RepackOptions {
187
+ /** Compression level (0-9, default: 6) */
188
+ compressionLevel?: number;
189
+ /** Whether to update modification date in docProps/core.xml */
190
+ updateModifiedDate?: boolean;
191
+ /** Custom modifier name for lastModifiedBy */
192
+ modifiedBy?: string;
193
+ }
194
+ /**
195
+ * Repack a Document into a valid DOCX file
196
+ *
197
+ * @param doc - Document with modified content
198
+ * @param options - Optional repack options
199
+ * @returns Promise resolving to DOCX as ArrayBuffer
200
+ * @throws Error if document has no original buffer for round-trip
201
+ */
202
+ declare function repackDocx(doc: Document, options?: RepackOptions): Promise<ArrayBuffer>;
203
+ /**
204
+ * Create a new DOCX from a Document (without requiring original buffer)
205
+ *
206
+ * @param doc - Document to serialize
207
+ * @returns Promise resolving to DOCX as ArrayBuffer
208
+ */
209
+ declare function createDocx(doc: Document): Promise<ArrayBuffer>;
210
+
211
+ /**
212
+ * Variable Detector Utility
213
+ *
214
+ * Scans a DOCX document for template variables in the format {{variable_name}}.
215
+ * Returns a unique, sorted list of variable names found in the document.
216
+ */
217
+
218
+ /**
219
+ * Result of variable detection
220
+ */
221
+ interface VariableDetectionResult {
222
+ /** Unique variable names sorted alphabetically */
223
+ variables: string[];
224
+ /** Total count of variable occurrences */
225
+ totalOccurrences: number;
226
+ /** Variables by location */
227
+ byLocation: {
228
+ body: string[];
229
+ headers: string[];
230
+ footers: string[];
231
+ footnotes: string[];
232
+ endnotes: string[];
233
+ textBoxes: string[];
234
+ };
235
+ /** Variable occurrences with positions */
236
+ occurrences: VariableOccurrence[];
237
+ }
238
+ /**
239
+ * A single variable occurrence with location info
240
+ */
241
+ interface VariableOccurrence {
242
+ /** Variable name (without braces) */
243
+ name: string;
244
+ /** Location type */
245
+ location: 'body' | 'header' | 'footer' | 'footnote' | 'endnote' | 'textBox';
246
+ /** Paragraph index within location */
247
+ paragraphIndex?: number;
248
+ /** Section index (for headers/footers) */
249
+ sectionIndex?: number;
250
+ }
251
+ /**
252
+ * Detect all template variables in a document
253
+ *
254
+ * @param doc - The parsed document
255
+ * @returns Array of unique variable names sorted alphabetically
256
+ */
257
+ declare function detectVariables(doc: Document): string[];
258
+ /**
259
+ * Detect variables with detailed information
260
+ *
261
+ * @param doc - The parsed document
262
+ * @returns Detailed detection result
263
+ */
264
+ declare function detectVariablesDetailed(doc: Document): VariableDetectionResult;
265
+ /**
266
+ * Detect variables in document body
267
+ */
268
+ declare function detectVariablesInBody(body: DocumentBody): string[];
269
+ /**
270
+ * Detect variables in a paragraph
271
+ */
272
+ declare function detectVariablesInParagraph(paragraph: Paragraph): string[];
273
+ /**
274
+ * Extract variable names from text
275
+ *
276
+ * @param text - The text to search
277
+ * @returns Array of variable names (without braces)
278
+ */
279
+ declare function extractVariablesFromText(text: string): string[];
280
+ /**
281
+ * Check if text contains template variables
282
+ */
283
+ declare function hasTemplateVariables(text: string): boolean;
284
+ /**
285
+ * Check if a variable name is valid
286
+ */
287
+ declare function isValidVariableName(name: string): boolean;
288
+ /**
289
+ * Sanitize a variable name
290
+ */
291
+ declare function sanitizeVariableName(name: string): string;
292
+ /**
293
+ * Format a variable name with braces
294
+ */
295
+ declare function formatVariable(name: string): string;
296
+ /**
297
+ * Parse a variable string to get the name
298
+ */
299
+ declare function parseVariable(variable: string): string | null;
300
+ /**
301
+ * Replace variables in text with values
302
+ *
303
+ * @param text - The text containing variables
304
+ * @param values - Map of variable name to replacement value
305
+ * @returns Text with variables replaced
306
+ */
307
+ declare function replaceVariables(text: string, values: Record<string, string>): string;
308
+ /**
309
+ * Replace all variables in text with a placeholder
310
+ *
311
+ * @param text - The text containing variables
312
+ * @param placeholder - Placeholder to use (default: empty string)
313
+ * @returns Text with variables replaced
314
+ */
315
+ declare function removeVariables(text: string, placeholder?: string): string;
316
+ /**
317
+ * Check if document has any template variables
318
+ */
319
+ declare function documentHasVariables(doc: Document): boolean;
320
+
321
+ /**
322
+ * Headless API Entry Point
323
+ *
324
+ * Provides document manipulation functionality without React/DOM dependencies.
325
+ * Suitable for Node.js scripts, CLI tools, and server-side processing.
326
+ *
327
+ * @example
328
+ * ```ts
329
+ * import { DocumentAgent, parseDocx, pluginRegistry } from '@eigenpal/docx-editor/headless';
330
+ * import { docxtemplaterPlugin } from '@eigenpal/docx-editor/core-plugins';
331
+ *
332
+ * // Register plugins
333
+ * pluginRegistry.register(docxtemplaterPlugin);
334
+ *
335
+ * // Load and manipulate document
336
+ * const buffer = fs.readFileSync('template.docx');
337
+ * const agent = await DocumentAgent.fromBuffer(buffer);
338
+ *
339
+ * // Get document info
340
+ * console.log('Word count:', agent.getWordCount());
341
+ * console.log('Variables:', agent.getVariables());
342
+ *
343
+ * // Edit document
344
+ * const newAgent = agent
345
+ * .insertText({ paragraphIndex: 0, offset: 0 }, 'Hello ')
346
+ * .applyStyle(0, 'Heading1');
347
+ *
348
+ * // Apply template variables
349
+ * const finalAgent = await newAgent.applyVariables({
350
+ * customer_name: 'Jane Doe',
351
+ * date: '2024-02-15',
352
+ * });
353
+ *
354
+ * // Export
355
+ * const output = await finalAgent.toBuffer();
356
+ * fs.writeFileSync('output.docx', Buffer.from(output));
357
+ * ```
358
+ */
359
+ declare const VERSION = "0.1.0";
360
+
361
+ export { Document, DocumentBody, Hyperlink, Paragraph, Position, Run, Table, TextFormatting, VERSION, type VariableDetectionResult, type VariableOccurrence, countCharacters, countWords, createDocx, detectVariables, detectVariablesDetailed, detectVariablesInBody, detectVariablesInParagraph, documentHasVariables, extractVariablesFromText, formatVariable, getBlockIndexForParagraph, getBodyCharacterCount, getBodyText, getBodyWordCount, getFormattingAtPosition, getHyperlinkAtPosition, getHyperlinkText, getParagraphAtIndex, getParagraphText, getParagraphs, getRunText, getTableText, getTextAfter, getTextBefore, hasHyperlinks, hasImages, hasTables, hasTemplateVariables, isHeadingStyle, isPositionInHyperlink, isValidVariableName, parseHeadingLevel, parseVariable, removeVariables, repackDocx, replaceVariables, sanitizeVariableName };