@eigenpal/docx-js-editor 0.0.12 → 0.0.14

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.
Files changed (115) hide show
  1. package/README.md +0 -3
  2. package/dist/DocumentAgent-Ci6_T-XM.d.ts +412 -0
  3. package/dist/DocumentAgent-DEGFgYEN.d.cts +412 -0
  4. package/dist/FindReplaceDialog-46BE7Q2G.cjs +1 -0
  5. package/dist/FindReplaceDialog-UMXCBBST.js +1 -0
  6. package/dist/FootnotePropertiesDialog-OBQXOBJE.cjs +1 -0
  7. package/dist/FootnotePropertiesDialog-TYQGPWPX.js +1 -0
  8. package/dist/HyperlinkDialog-22NH7ZLP.cjs +1 -0
  9. package/dist/HyperlinkDialog-UOERZIBM.js +1 -0
  10. package/dist/ImagePositionDialog-52FDANUK.js +1 -0
  11. package/dist/ImagePositionDialog-ZK5WFBRC.cjs +1 -0
  12. package/dist/ImagePropertiesDialog-LU44RDIY.cjs +1 -0
  13. package/dist/ImagePropertiesDialog-YPSLPSF6.js +1 -0
  14. package/dist/TablePropertiesDialog-KMOYHPGF.cjs +1 -0
  15. package/dist/TablePropertiesDialog-OUUJAA7D.js +1 -0
  16. package/dist/{types-BALm1KBi.d.cts → agentApi-CbVUCZRu.d.cts} +1 -308
  17. package/dist/{types-BALm1KBi.d.ts → agentApi-CbVUCZRu.d.ts} +1 -308
  18. package/dist/chunk-2ASOEN3V.js +1 -0
  19. package/dist/chunk-3VOXZKGT.js +2 -0
  20. package/dist/{chunk-P332HWDE.js → chunk-5MWH4N7I.js} +5 -5
  21. package/dist/chunk-5WBRHVOE.js +258 -0
  22. package/dist/chunk-6YFGCUHU.js +4 -0
  23. package/dist/chunk-7H2HP242.js +58 -0
  24. package/dist/chunk-CTYOM6BE.js +2 -0
  25. package/dist/chunk-EMKABJPH.js +1 -0
  26. package/dist/chunk-ESI4BSBF.js +1 -0
  27. package/dist/{chunk-A7VY2V4X.cjs → chunk-FYAWM7MP.cjs} +1 -1
  28. package/dist/{chunk-GIZ5CTBD.cjs → chunk-IHZIA6JP.cjs} +5 -5
  29. package/dist/chunk-ITWEFKGQ.cjs +1 -0
  30. package/dist/chunk-JGPRSZPI.cjs +2 -0
  31. package/dist/chunk-JS7TPZTF.cjs +10 -0
  32. package/dist/chunk-KESNGXGO.js +1 -0
  33. package/dist/chunk-L34XFLQZ.cjs +1 -0
  34. package/dist/chunk-L7UKJGRK.js +10 -0
  35. package/dist/chunk-MLSHZVL7.js +111 -0
  36. package/dist/chunk-NT2REEAA.cjs +1 -0
  37. package/dist/chunk-O7QVCJN6.cjs +4 -0
  38. package/dist/chunk-OEOUMSWH.cjs +111 -0
  39. package/dist/chunk-OW5H5DNE.cjs +1 -0
  40. package/dist/chunk-OWMXCVKB.js +1 -0
  41. package/dist/chunk-PJVI53AH.js +2 -0
  42. package/dist/{chunk-XVFMG77A.cjs → chunk-PXC7ARQB.cjs} +1 -1
  43. package/dist/chunk-QVVLXLRZ.cjs +258 -0
  44. package/dist/{chunk-QHWHCIUW.js → chunk-R5SKERM2.js} +1 -1
  45. package/dist/chunk-SF53KLDZ.cjs +1 -0
  46. package/dist/chunk-TOI5W3HK.js +8 -0
  47. package/dist/chunk-UAME5JHZ.cjs +58 -0
  48. package/dist/chunk-UAVOWAIF.cjs +8 -0
  49. package/dist/chunk-VOWKSURW.cjs +1 -0
  50. package/dist/chunk-VTAS7VZ6.cjs +2 -0
  51. package/dist/{chunk-MMJD2DLL.js → chunk-WFWLPKQA.js} +1 -1
  52. package/dist/chunk-XS2AQFMF.cjs +2 -0
  53. package/dist/chunk-ZDYHAYN6.js +1 -0
  54. package/dist/clipboard-BOocwmAM.d.ts +539 -0
  55. package/dist/clipboard-Cx7cb3kX.d.cts +539 -0
  56. package/dist/{colorResolver-BNj-uZ58.d.ts → colorResolver-CIDiSPWd.d.cts} +3 -411
  57. package/dist/{colorResolver-DiMquGWR.d.cts → colorResolver-KXbUgzWC.d.ts} +3 -411
  58. package/dist/core-plugins.cjs +1 -1
  59. package/dist/core-plugins.d.cts +11 -7
  60. package/dist/core-plugins.d.ts +11 -7
  61. package/dist/core-plugins.js +1 -1
  62. package/dist/core.cjs +1 -0
  63. package/dist/core.d.cts +23 -0
  64. package/dist/core.d.ts +23 -0
  65. package/dist/core.js +1 -0
  66. package/dist/executor-ITYZTNSH.cjs +1 -0
  67. package/dist/executor-TC7CLATE.js +1 -0
  68. package/dist/headless.cjs +2 -2
  69. package/dist/headless.d.cts +8 -175
  70. package/dist/headless.d.ts +8 -175
  71. package/dist/headless.js +1 -1
  72. package/dist/index.cjs +9 -378
  73. package/dist/index.d.cts +17 -4161
  74. package/dist/index.d.ts +17 -4161
  75. package/dist/index.js +9 -378
  76. package/dist/insertOperations-CzB5b-Of.d.ts +176 -0
  77. package/dist/insertOperations-DKVmCV32.d.cts +176 -0
  78. package/dist/mcp-cli.js +21 -21
  79. package/dist/mcp.cjs +10 -10
  80. package/dist/mcp.d.cts +2 -1
  81. package/dist/mcp.d.ts +2 -1
  82. package/dist/mcp.js +9 -9
  83. package/dist/processTemplate-525HZL4S.cjs +1 -0
  84. package/dist/processTemplate-RJN6452W.js +1 -0
  85. package/dist/react-BZxD04XV.d.ts +1350 -0
  86. package/dist/react-D8eAYckC.d.cts +1350 -0
  87. package/dist/react.cjs +1 -0
  88. package/dist/react.css +1 -0
  89. package/dist/react.d.cts +9 -0
  90. package/dist/react.d.ts +9 -0
  91. package/dist/react.js +1 -0
  92. package/dist/{registry-CzqAPdui.d.ts → registry-D4tvj9f3.d.ts} +1 -1
  93. package/dist/{registry-BUTMLqSj.d.cts → registry-ngv6Bumt.d.cts} +1 -1
  94. package/dist/{selectionRects-LO3FJT47.js → selectionRects-42JURU6D.js} +1 -1
  95. package/dist/{selectionRects-I5JVL73G.cjs → selectionRects-XGMQBMC5.cjs} +1 -1
  96. package/dist/styles.css +1 -1
  97. package/dist/types-D96elyJF.d.cts +310 -0
  98. package/dist/types-xMzSPT4i.d.ts +310 -0
  99. package/dist/ui.cjs +1 -0
  100. package/dist/ui.d.cts +2051 -0
  101. package/dist/ui.d.ts +2051 -0
  102. package/dist/ui.js +1 -0
  103. package/dist/variableDetector-CPxKo9jP.d.cts +173 -0
  104. package/dist/variableDetector-DeM1N-_L.d.ts +173 -0
  105. package/package.json +85 -11
  106. package/dist/chunk-3IYNTJO5.js +0 -1
  107. package/dist/chunk-56AGRHVO.cjs +0 -58
  108. package/dist/chunk-E23CAQXT.js +0 -9
  109. package/dist/chunk-HIBC7HTU.cjs +0 -9
  110. package/dist/chunk-ICEPOA7G.js +0 -58
  111. package/dist/chunk-IZGUXSCC.js +0 -10
  112. package/dist/chunk-RTESADL3.cjs +0 -1
  113. package/dist/chunk-XF3IPO7C.cjs +0 -10
  114. package/dist/executor-44OB3DFD.js +0 -1
  115. package/dist/executor-U3BZPPGN.cjs +0 -1
package/README.md CHANGED
@@ -77,9 +77,6 @@ function Editor({ file }: { file: ArrayBuffer }) {
77
77
  | `showRuler` | `boolean` | `false` | Show horizontal & vertical rulers |
78
78
  | `rulerUnit` | `'inch' \| 'cm'` | `'inch'` | Unit for ruler display |
79
79
  | `showZoomControl` | `boolean` | `true` | Show zoom controls in toolbar |
80
- | `showVariablePanel` | `boolean` | `true` | Show template variable panel |
81
- | `variablePanelPosition` | `'left' \| 'right'` | `'right'` | Variable panel position |
82
- | `variableDescriptions` | `Record<string, string>` | — | Descriptions for template variables |
83
80
  | `showPrintButton` | `boolean` | `true` | Show print button in toolbar |
84
81
  | `showPageNumbers` | `boolean` | `true` | Show page number indicator |
85
82
  | `enablePageNavigation` | `boolean` | `true` | Enable interactive page navigation |
@@ -0,0 +1,412 @@
1
+ import { h as Document, X as TextFormatting, a5 as StyleInfo, c as AgentContext, v as Position, R as Range, u as ParagraphFormatting, b as AgentCommand } from './agentApi-CbVUCZRu.js';
2
+
3
+ /**
4
+ * Flexible input types for DOCX documents.
5
+ *
6
+ * Accepts any common binary format so consumers don't need to manually
7
+ * convert before passing data to the editor or parser.
8
+ */
9
+ /**
10
+ * Any binary representation of a DOCX file that the editor can consume.
11
+ *
12
+ * - `ArrayBuffer` — from `FileReader.readAsArrayBuffer()` or `fetch().arrayBuffer()`
13
+ * - `Uint8Array` — from Node.js `fs.readFile()` or streaming APIs
14
+ * - `Blob` — from drag-and-drop or `<input type="file">`
15
+ * - `File` — subclass of Blob, from `<input type="file">`
16
+ */
17
+ type DocxInput = ArrayBuffer | Uint8Array | Blob | File;
18
+ /**
19
+ * Normalize any {@link DocxInput} into an `ArrayBuffer` for internal use.
20
+ */
21
+ declare function toArrayBuffer(input: DocxInput): Promise<ArrayBuffer>;
22
+
23
+ /**
24
+ * DocumentAgent - High-level fluent API for programmatic document manipulation
25
+ *
26
+ * Provides a convenient interface for:
27
+ * - Reading document content and metadata
28
+ * - Editing text with formatting
29
+ * - Inserting tables, images, and hyperlinks
30
+ * - Managing template variables
31
+ * - Exporting to DOCX buffer
32
+ *
33
+ * All operations are immutable - they return a new DocumentAgent instance
34
+ * or don't modify the underlying document.
35
+ */
36
+
37
+ /**
38
+ * Options for inserting text
39
+ */
40
+ interface InsertTextOptions {
41
+ /** Text formatting */
42
+ formatting?: TextFormatting;
43
+ }
44
+ /**
45
+ * Options for inserting table
46
+ */
47
+ interface InsertTableOptions {
48
+ /** Table data (2D array of strings) */
49
+ data?: string[][];
50
+ /** Whether first row is a header */
51
+ hasHeader?: boolean;
52
+ }
53
+ /**
54
+ * Options for inserting image
55
+ */
56
+ interface InsertImageOptions {
57
+ /** Image width in pixels */
58
+ width?: number;
59
+ /** Image height in pixels */
60
+ height?: number;
61
+ /** Alt text for accessibility */
62
+ alt?: string;
63
+ }
64
+ /**
65
+ * Options for inserting hyperlink
66
+ */
67
+ interface InsertHyperlinkOptions {
68
+ /** Display text (overrides selected text) */
69
+ displayText?: string;
70
+ /** Tooltip on hover */
71
+ tooltip?: string;
72
+ }
73
+ /**
74
+ * Formatted text segment
75
+ */
76
+ interface FormattedTextSegment {
77
+ /** Text content */
78
+ text: string;
79
+ /** Applied formatting */
80
+ formatting?: TextFormatting;
81
+ /** Is part of a hyperlink */
82
+ isHyperlink?: boolean;
83
+ /** Hyperlink URL if applicable */
84
+ hyperlinkUrl?: string;
85
+ }
86
+ /**
87
+ * DocumentAgent provides a fluent API for document manipulation
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * const agent = new DocumentAgent(buffer);
92
+ *
93
+ * // Read operations
94
+ * const text = agent.getText();
95
+ * const wordCount = agent.getWordCount();
96
+ * const variables = agent.getVariables();
97
+ *
98
+ * // Write operations (returns new agent)
99
+ * const newAgent = agent
100
+ * .insertText({ paragraphIndex: 0, offset: 0 }, 'Hello ', { formatting: { bold: true } })
101
+ * .applyStyle({ paragraphIndex: 0, offset: 0 }, { paragraphIndex: 0, offset: 5 }, 'Heading1');
102
+ *
103
+ * // Export
104
+ * const newBuffer = await newAgent.toBuffer();
105
+ * ```
106
+ */
107
+ declare class DocumentAgent {
108
+ private _document;
109
+ private _pendingVariables;
110
+ /**
111
+ * Create a new DocumentAgent
112
+ *
113
+ * @param source - Document object or ArrayBuffer to parse
114
+ */
115
+ constructor(source: Document | ArrayBuffer);
116
+ /**
117
+ * Create a DocumentAgent from a DOCX buffer (async)
118
+ *
119
+ * @param buffer - DOCX file as ArrayBuffer, Uint8Array, Blob, or File
120
+ * @returns Promise resolving to DocumentAgent
121
+ */
122
+ static fromBuffer(buffer: DocxInput): Promise<DocumentAgent>;
123
+ /**
124
+ * Create a DocumentAgent from a Document object
125
+ *
126
+ * @param document - Parsed Document
127
+ * @returns DocumentAgent
128
+ */
129
+ static fromDocument(document: Document): DocumentAgent;
130
+ /**
131
+ * Get the underlying document
132
+ */
133
+ getDocument(): Document;
134
+ /**
135
+ * Get plain text content of the document
136
+ *
137
+ * @returns All document text concatenated
138
+ */
139
+ getText(): string;
140
+ /**
141
+ * Get formatted text segments
142
+ *
143
+ * @returns Array of text segments with formatting info
144
+ */
145
+ getFormattedText(): FormattedTextSegment[];
146
+ /**
147
+ * Get detected template variables
148
+ *
149
+ * @returns Array of variable names (without braces)
150
+ */
151
+ getVariables(): string[];
152
+ /**
153
+ * Get available styles from the document
154
+ *
155
+ * @returns Array of style info
156
+ */
157
+ getStyles(): StyleInfo[];
158
+ /**
159
+ * Get approximate page count
160
+ *
161
+ * Note: This is an estimate based on content length.
162
+ * Actual page count requires full layout computation.
163
+ *
164
+ * @returns Estimated page count
165
+ */
166
+ getPageCount(): number;
167
+ /**
168
+ * Get word count
169
+ *
170
+ * @returns Number of words in the document
171
+ */
172
+ getWordCount(): number;
173
+ /**
174
+ * Get character count
175
+ *
176
+ * @param includeSpaces - Whether to include whitespace
177
+ * @returns Number of characters
178
+ */
179
+ getCharacterCount(includeSpaces?: boolean): number;
180
+ /**
181
+ * Get paragraph count
182
+ *
183
+ * @returns Number of paragraphs
184
+ */
185
+ getParagraphCount(): number;
186
+ /**
187
+ * Get table count
188
+ *
189
+ * @returns Number of tables
190
+ */
191
+ getTableCount(): number;
192
+ /**
193
+ * Get document context for AI agents
194
+ *
195
+ * @param outlineMaxChars - Max characters per paragraph in outline
196
+ * @returns Agent context
197
+ */
198
+ getAgentContext(outlineMaxChars?: number): AgentContext;
199
+ /**
200
+ * Insert text at a position
201
+ *
202
+ * @param position - Where to insert
203
+ * @param text - Text to insert
204
+ * @param options - Insert options
205
+ * @returns New DocumentAgent with text inserted
206
+ */
207
+ insertText(position: Position, text: string, options?: InsertTextOptions): DocumentAgent;
208
+ /**
209
+ * Replace text in a range
210
+ *
211
+ * @param range - Range to replace
212
+ * @param text - Replacement text
213
+ * @param options - Replace options
214
+ * @returns New DocumentAgent with text replaced
215
+ */
216
+ replaceRange(range: Range, text: string, options?: InsertTextOptions): DocumentAgent;
217
+ /**
218
+ * Delete text in a range
219
+ *
220
+ * @param range - Range to delete
221
+ * @returns New DocumentAgent with text deleted
222
+ */
223
+ deleteRange(range: Range): DocumentAgent;
224
+ /**
225
+ * Apply text formatting to a range
226
+ *
227
+ * @param range - Range to format
228
+ * @param formatting - Formatting to apply
229
+ * @returns New DocumentAgent with formatting applied
230
+ */
231
+ applyFormatting(range: Range, formatting: Partial<TextFormatting>): DocumentAgent;
232
+ /**
233
+ * Apply a named style to a paragraph
234
+ *
235
+ * @param paragraphIndex - Index of the paragraph
236
+ * @param styleId - Style ID to apply
237
+ * @returns New DocumentAgent with style applied
238
+ */
239
+ applyStyle(paragraphIndex: number, styleId: string): DocumentAgent;
240
+ /**
241
+ * Apply paragraph formatting
242
+ *
243
+ * @param paragraphIndex - Index of the paragraph
244
+ * @param formatting - Formatting to apply
245
+ * @returns New DocumentAgent with formatting applied
246
+ */
247
+ applyParagraphFormatting(paragraphIndex: number, formatting: Partial<ParagraphFormatting>): DocumentAgent;
248
+ /**
249
+ * Insert a table at a position
250
+ *
251
+ * @param position - Where to insert the table
252
+ * @param rows - Number of rows
253
+ * @param cols - Number of columns
254
+ * @param options - Table options
255
+ * @returns New DocumentAgent with table inserted
256
+ */
257
+ insertTable(position: Position, rows: number, cols: number, options?: InsertTableOptions): DocumentAgent;
258
+ /**
259
+ * Insert an image at a position
260
+ *
261
+ * @param position - Where to insert the image
262
+ * @param src - Image source (base64 data URL or URL)
263
+ * @param options - Image options
264
+ * @returns New DocumentAgent with image inserted
265
+ */
266
+ insertImage(position: Position, src: string, options?: InsertImageOptions): DocumentAgent;
267
+ /**
268
+ * Insert a hyperlink
269
+ *
270
+ * @param range - Range to make into a hyperlink
271
+ * @param url - URL of the hyperlink
272
+ * @param options - Hyperlink options
273
+ * @returns New DocumentAgent with hyperlink inserted
274
+ */
275
+ insertHyperlink(range: Range, url: string, options?: InsertHyperlinkOptions): DocumentAgent;
276
+ /**
277
+ * Remove a hyperlink but keep the text
278
+ *
279
+ * @param range - Range containing the hyperlink
280
+ * @returns New DocumentAgent with hyperlink removed
281
+ */
282
+ removeHyperlink(range: Range): DocumentAgent;
283
+ /**
284
+ * Insert a paragraph break
285
+ *
286
+ * @param position - Where to break the paragraph
287
+ * @returns New DocumentAgent with paragraph broken
288
+ */
289
+ insertParagraphBreak(position: Position): DocumentAgent;
290
+ /**
291
+ * Merge consecutive paragraphs
292
+ *
293
+ * @param startParagraphIndex - First paragraph index
294
+ * @param count - Number of paragraphs to merge with the first
295
+ * @returns New DocumentAgent with paragraphs merged
296
+ */
297
+ mergeParagraphs(startParagraphIndex: number, count: number): DocumentAgent;
298
+ /**
299
+ * Set a template variable value
300
+ *
301
+ * Note: Variables are not applied until `applyVariables()` is called
302
+ *
303
+ * @param name - Variable name (without braces)
304
+ * @param value - Variable value
305
+ * @returns This DocumentAgent (for chaining)
306
+ */
307
+ setVariable(name: string, value: string): DocumentAgent;
308
+ /**
309
+ * Set multiple template variables
310
+ *
311
+ * @param variables - Map of variable names to values
312
+ * @returns This DocumentAgent (for chaining)
313
+ */
314
+ setVariables(variables: Record<string, string>): DocumentAgent;
315
+ /**
316
+ * Get pending variable values
317
+ *
318
+ * @returns Map of pending variable values
319
+ */
320
+ getPendingVariables(): Record<string, string>;
321
+ /**
322
+ * Clear pending variables
323
+ *
324
+ * @returns This DocumentAgent (for chaining)
325
+ */
326
+ clearPendingVariables(): DocumentAgent;
327
+ /**
328
+ * Apply all pending template variables
329
+ *
330
+ * Uses docxtemplater to substitute variables while preserving formatting.
331
+ *
332
+ * @param variables - Optional additional variables (merged with pending)
333
+ * @returns New DocumentAgent with variables applied
334
+ */
335
+ applyVariables(variables?: Record<string, string>): Promise<DocumentAgent>;
336
+ /**
337
+ * Export document to DOCX ArrayBuffer
338
+ *
339
+ * @returns Promise resolving to DOCX file as ArrayBuffer
340
+ */
341
+ toBuffer(): Promise<ArrayBuffer>;
342
+ /**
343
+ * Export document to Blob
344
+ *
345
+ * @param mimeType - MIME type for the blob
346
+ * @returns Promise resolving to DOCX file as Blob
347
+ */
348
+ toBlob(mimeType?: string): Promise<Blob>;
349
+ /**
350
+ * Execute multiple commands in sequence
351
+ *
352
+ * @param commands - Commands to execute
353
+ * @returns New DocumentAgent with all commands applied
354
+ */
355
+ executeCommands(commands: AgentCommand[]): DocumentAgent;
356
+ /**
357
+ * Execute a single command and return new agent
358
+ */
359
+ private _executeCommand;
360
+ /**
361
+ * Get plain text from document body
362
+ */
363
+ private _getBodyText;
364
+ /**
365
+ * Get plain text from a paragraph
366
+ */
367
+ private _getParagraphText;
368
+ /**
369
+ * Get plain text from a run
370
+ */
371
+ private _getRunText;
372
+ /**
373
+ * Get plain text from a hyperlink
374
+ */
375
+ private _getHyperlinkText;
376
+ /**
377
+ * Get plain text from a table
378
+ */
379
+ private _getTableText;
380
+ /**
381
+ * Extract formatted text segments from a paragraph
382
+ */
383
+ private _extractParagraphSegments;
384
+ /**
385
+ * Parse heading level from style ID
386
+ */
387
+ private _parseHeadingLevel;
388
+ /**
389
+ * Check if document has images
390
+ */
391
+ private _hasImages;
392
+ /**
393
+ * Check if document has hyperlinks
394
+ */
395
+ private _hasHyperlinks;
396
+ }
397
+ /**
398
+ * Create a DocumentAgent from a DOCX buffer
399
+ *
400
+ * @param buffer - DOCX file as ArrayBuffer
401
+ * @returns Promise resolving to DocumentAgent
402
+ */
403
+ declare function createAgent(buffer: ArrayBuffer): Promise<DocumentAgent>;
404
+ /**
405
+ * Create a DocumentAgent from a parsed Document
406
+ *
407
+ * @param document - Parsed Document
408
+ * @returns DocumentAgent
409
+ */
410
+ declare function createAgentFromDocument(document: Document): DocumentAgent;
411
+
412
+ export { DocumentAgent as D, type FormattedTextSegment as F, type InsertHyperlinkOptions as I, type DocxInput as a, type InsertImageOptions as b, type InsertTableOptions as c, type InsertTextOptions as d, createAgent as e, createAgentFromDocument as f, toArrayBuffer as t };