@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.
- package/LICENSE +21 -0
- package/README.md +191 -0
- package/dist/colorResolver-C-tITrbI.d.cts +1037 -0
- package/dist/colorResolver-Yakhydrt.d.ts +1037 -0
- package/dist/core-plugins.cjs +7131 -0
- package/dist/core-plugins.cjs.map +1 -0
- package/dist/core-plugins.d.cts +27 -0
- package/dist/core-plugins.d.ts +27 -0
- package/dist/core-plugins.js +7102 -0
- package/dist/core-plugins.js.map +1 -0
- package/dist/headless.cjs +10984 -0
- package/dist/headless.cjs.map +1 -0
- package/dist/headless.d.cts +361 -0
- package/dist/headless.d.ts +361 -0
- package/dist/headless.js +10852 -0
- package/dist/headless.js.map +1 -0
- package/dist/index.cjs +45026 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.css +369 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.cts +4579 -0
- package/dist/index.d.ts +4579 -0
- package/dist/index.js +44701 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-cli.js +9657 -0
- package/dist/mcp-cli.js.map +1 -0
- package/dist/mcp.cjs +8715 -0
- package/dist/mcp.cjs.map +1 -0
- package/dist/mcp.d.cts +155 -0
- package/dist/mcp.d.ts +155 -0
- package/dist/mcp.js +8667 -0
- package/dist/mcp.js.map +1 -0
- package/dist/registry-D3zhko7n.d.ts +165 -0
- package/dist/registry-DeeU0bQB.d.cts +165 -0
- package/dist/styles.css +1 -0
- package/dist/types-BJXChtaM.d.cts +2216 -0
- package/dist/types-BJXChtaM.d.ts +2216 -0
- package/package.json +132 -0
|
@@ -0,0 +1,1037 @@
|
|
|
1
|
+
import { h as Document, T as TextFormatting, a6 as StyleInfo, k as AgentContext, g as Position, Y as Range, U as ParagraphFormatting, j as AgentCommand, a2 as SelectionContext, D as DocumentBody, a1 as SectionProperties, al as ColorValue, ab as Theme, am as ThemeColorSlot } from './types-BJXChtaM.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* DocumentAgent - High-level fluent API for programmatic document manipulation
|
|
5
|
+
*
|
|
6
|
+
* Provides a convenient interface for:
|
|
7
|
+
* - Reading document content and metadata
|
|
8
|
+
* - Editing text with formatting
|
|
9
|
+
* - Inserting tables, images, and hyperlinks
|
|
10
|
+
* - Managing template variables
|
|
11
|
+
* - Exporting to DOCX buffer
|
|
12
|
+
*
|
|
13
|
+
* All operations are immutable - they return a new DocumentAgent instance
|
|
14
|
+
* or don't modify the underlying document.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Options for inserting text
|
|
19
|
+
*/
|
|
20
|
+
interface InsertTextOptions {
|
|
21
|
+
/** Text formatting */
|
|
22
|
+
formatting?: TextFormatting;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Options for inserting table
|
|
26
|
+
*/
|
|
27
|
+
interface InsertTableOptions {
|
|
28
|
+
/** Table data (2D array of strings) */
|
|
29
|
+
data?: string[][];
|
|
30
|
+
/** Whether first row is a header */
|
|
31
|
+
hasHeader?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Options for inserting image
|
|
35
|
+
*/
|
|
36
|
+
interface InsertImageOptions {
|
|
37
|
+
/** Image width in pixels */
|
|
38
|
+
width?: number;
|
|
39
|
+
/** Image height in pixels */
|
|
40
|
+
height?: number;
|
|
41
|
+
/** Alt text for accessibility */
|
|
42
|
+
alt?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Options for inserting hyperlink
|
|
46
|
+
*/
|
|
47
|
+
interface InsertHyperlinkOptions {
|
|
48
|
+
/** Display text (overrides selected text) */
|
|
49
|
+
displayText?: string;
|
|
50
|
+
/** Tooltip on hover */
|
|
51
|
+
tooltip?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Formatted text segment
|
|
55
|
+
*/
|
|
56
|
+
interface FormattedTextSegment {
|
|
57
|
+
/** Text content */
|
|
58
|
+
text: string;
|
|
59
|
+
/** Applied formatting */
|
|
60
|
+
formatting?: TextFormatting;
|
|
61
|
+
/** Is part of a hyperlink */
|
|
62
|
+
isHyperlink?: boolean;
|
|
63
|
+
/** Hyperlink URL if applicable */
|
|
64
|
+
hyperlinkUrl?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* DocumentAgent provides a fluent API for document manipulation
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const agent = new DocumentAgent(buffer);
|
|
72
|
+
*
|
|
73
|
+
* // Read operations
|
|
74
|
+
* const text = agent.getText();
|
|
75
|
+
* const wordCount = agent.getWordCount();
|
|
76
|
+
* const variables = agent.getVariables();
|
|
77
|
+
*
|
|
78
|
+
* // Write operations (returns new agent)
|
|
79
|
+
* const newAgent = agent
|
|
80
|
+
* .insertText({ paragraphIndex: 0, offset: 0 }, 'Hello ', { formatting: { bold: true } })
|
|
81
|
+
* .applyStyle({ paragraphIndex: 0, offset: 0 }, { paragraphIndex: 0, offset: 5 }, 'Heading1');
|
|
82
|
+
*
|
|
83
|
+
* // Export
|
|
84
|
+
* const newBuffer = await newAgent.toBuffer();
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
declare class DocumentAgent {
|
|
88
|
+
private _document;
|
|
89
|
+
private _pendingVariables;
|
|
90
|
+
/**
|
|
91
|
+
* Create a new DocumentAgent
|
|
92
|
+
*
|
|
93
|
+
* @param source - Document object or ArrayBuffer to parse
|
|
94
|
+
*/
|
|
95
|
+
constructor(source: Document | ArrayBuffer);
|
|
96
|
+
/**
|
|
97
|
+
* Create a DocumentAgent from an ArrayBuffer (async)
|
|
98
|
+
*
|
|
99
|
+
* @param buffer - DOCX file as ArrayBuffer
|
|
100
|
+
* @returns Promise resolving to DocumentAgent
|
|
101
|
+
*/
|
|
102
|
+
static fromBuffer(buffer: ArrayBuffer): Promise<DocumentAgent>;
|
|
103
|
+
/**
|
|
104
|
+
* Create a DocumentAgent from a Document object
|
|
105
|
+
*
|
|
106
|
+
* @param document - Parsed Document
|
|
107
|
+
* @returns DocumentAgent
|
|
108
|
+
*/
|
|
109
|
+
static fromDocument(document: Document): DocumentAgent;
|
|
110
|
+
/**
|
|
111
|
+
* Get the underlying document
|
|
112
|
+
*/
|
|
113
|
+
getDocument(): Document;
|
|
114
|
+
/**
|
|
115
|
+
* Get plain text content of the document
|
|
116
|
+
*
|
|
117
|
+
* @returns All document text concatenated
|
|
118
|
+
*/
|
|
119
|
+
getText(): string;
|
|
120
|
+
/**
|
|
121
|
+
* Get formatted text segments
|
|
122
|
+
*
|
|
123
|
+
* @returns Array of text segments with formatting info
|
|
124
|
+
*/
|
|
125
|
+
getFormattedText(): FormattedTextSegment[];
|
|
126
|
+
/**
|
|
127
|
+
* Get detected template variables
|
|
128
|
+
*
|
|
129
|
+
* @returns Array of variable names (without braces)
|
|
130
|
+
*/
|
|
131
|
+
getVariables(): string[];
|
|
132
|
+
/**
|
|
133
|
+
* Get available styles from the document
|
|
134
|
+
*
|
|
135
|
+
* @returns Array of style info
|
|
136
|
+
*/
|
|
137
|
+
getStyles(): StyleInfo[];
|
|
138
|
+
/**
|
|
139
|
+
* Get approximate page count
|
|
140
|
+
*
|
|
141
|
+
* Note: This is an estimate based on content length.
|
|
142
|
+
* Actual page count requires full layout computation.
|
|
143
|
+
*
|
|
144
|
+
* @returns Estimated page count
|
|
145
|
+
*/
|
|
146
|
+
getPageCount(): number;
|
|
147
|
+
/**
|
|
148
|
+
* Get word count
|
|
149
|
+
*
|
|
150
|
+
* @returns Number of words in the document
|
|
151
|
+
*/
|
|
152
|
+
getWordCount(): number;
|
|
153
|
+
/**
|
|
154
|
+
* Get character count
|
|
155
|
+
*
|
|
156
|
+
* @param includeSpaces - Whether to include whitespace
|
|
157
|
+
* @returns Number of characters
|
|
158
|
+
*/
|
|
159
|
+
getCharacterCount(includeSpaces?: boolean): number;
|
|
160
|
+
/**
|
|
161
|
+
* Get paragraph count
|
|
162
|
+
*
|
|
163
|
+
* @returns Number of paragraphs
|
|
164
|
+
*/
|
|
165
|
+
getParagraphCount(): number;
|
|
166
|
+
/**
|
|
167
|
+
* Get table count
|
|
168
|
+
*
|
|
169
|
+
* @returns Number of tables
|
|
170
|
+
*/
|
|
171
|
+
getTableCount(): number;
|
|
172
|
+
/**
|
|
173
|
+
* Get document context for AI agents
|
|
174
|
+
*
|
|
175
|
+
* @param outlineMaxChars - Max characters per paragraph in outline
|
|
176
|
+
* @returns Agent context
|
|
177
|
+
*/
|
|
178
|
+
getAgentContext(outlineMaxChars?: number): AgentContext;
|
|
179
|
+
/**
|
|
180
|
+
* Insert text at a position
|
|
181
|
+
*
|
|
182
|
+
* @param position - Where to insert
|
|
183
|
+
* @param text - Text to insert
|
|
184
|
+
* @param options - Insert options
|
|
185
|
+
* @returns New DocumentAgent with text inserted
|
|
186
|
+
*/
|
|
187
|
+
insertText(position: Position, text: string, options?: InsertTextOptions): DocumentAgent;
|
|
188
|
+
/**
|
|
189
|
+
* Replace text in a range
|
|
190
|
+
*
|
|
191
|
+
* @param range - Range to replace
|
|
192
|
+
* @param text - Replacement text
|
|
193
|
+
* @param options - Replace options
|
|
194
|
+
* @returns New DocumentAgent with text replaced
|
|
195
|
+
*/
|
|
196
|
+
replaceRange(range: Range, text: string, options?: InsertTextOptions): DocumentAgent;
|
|
197
|
+
/**
|
|
198
|
+
* Delete text in a range
|
|
199
|
+
*
|
|
200
|
+
* @param range - Range to delete
|
|
201
|
+
* @returns New DocumentAgent with text deleted
|
|
202
|
+
*/
|
|
203
|
+
deleteRange(range: Range): DocumentAgent;
|
|
204
|
+
/**
|
|
205
|
+
* Apply text formatting to a range
|
|
206
|
+
*
|
|
207
|
+
* @param range - Range to format
|
|
208
|
+
* @param formatting - Formatting to apply
|
|
209
|
+
* @returns New DocumentAgent with formatting applied
|
|
210
|
+
*/
|
|
211
|
+
applyFormatting(range: Range, formatting: Partial<TextFormatting>): DocumentAgent;
|
|
212
|
+
/**
|
|
213
|
+
* Apply a named style to a paragraph
|
|
214
|
+
*
|
|
215
|
+
* @param paragraphIndex - Index of the paragraph
|
|
216
|
+
* @param styleId - Style ID to apply
|
|
217
|
+
* @returns New DocumentAgent with style applied
|
|
218
|
+
*/
|
|
219
|
+
applyStyle(paragraphIndex: number, styleId: string): DocumentAgent;
|
|
220
|
+
/**
|
|
221
|
+
* Apply paragraph formatting
|
|
222
|
+
*
|
|
223
|
+
* @param paragraphIndex - Index of the paragraph
|
|
224
|
+
* @param formatting - Formatting to apply
|
|
225
|
+
* @returns New DocumentAgent with formatting applied
|
|
226
|
+
*/
|
|
227
|
+
applyParagraphFormatting(paragraphIndex: number, formatting: Partial<ParagraphFormatting>): DocumentAgent;
|
|
228
|
+
/**
|
|
229
|
+
* Insert a table at a position
|
|
230
|
+
*
|
|
231
|
+
* @param position - Where to insert the table
|
|
232
|
+
* @param rows - Number of rows
|
|
233
|
+
* @param cols - Number of columns
|
|
234
|
+
* @param options - Table options
|
|
235
|
+
* @returns New DocumentAgent with table inserted
|
|
236
|
+
*/
|
|
237
|
+
insertTable(position: Position, rows: number, cols: number, options?: InsertTableOptions): DocumentAgent;
|
|
238
|
+
/**
|
|
239
|
+
* Insert an image at a position
|
|
240
|
+
*
|
|
241
|
+
* @param position - Where to insert the image
|
|
242
|
+
* @param src - Image source (base64 data URL or URL)
|
|
243
|
+
* @param options - Image options
|
|
244
|
+
* @returns New DocumentAgent with image inserted
|
|
245
|
+
*/
|
|
246
|
+
insertImage(position: Position, src: string, options?: InsertImageOptions): DocumentAgent;
|
|
247
|
+
/**
|
|
248
|
+
* Insert a hyperlink
|
|
249
|
+
*
|
|
250
|
+
* @param range - Range to make into a hyperlink
|
|
251
|
+
* @param url - URL of the hyperlink
|
|
252
|
+
* @param options - Hyperlink options
|
|
253
|
+
* @returns New DocumentAgent with hyperlink inserted
|
|
254
|
+
*/
|
|
255
|
+
insertHyperlink(range: Range, url: string, options?: InsertHyperlinkOptions): DocumentAgent;
|
|
256
|
+
/**
|
|
257
|
+
* Remove a hyperlink but keep the text
|
|
258
|
+
*
|
|
259
|
+
* @param range - Range containing the hyperlink
|
|
260
|
+
* @returns New DocumentAgent with hyperlink removed
|
|
261
|
+
*/
|
|
262
|
+
removeHyperlink(range: Range): DocumentAgent;
|
|
263
|
+
/**
|
|
264
|
+
* Insert a paragraph break
|
|
265
|
+
*
|
|
266
|
+
* @param position - Where to break the paragraph
|
|
267
|
+
* @returns New DocumentAgent with paragraph broken
|
|
268
|
+
*/
|
|
269
|
+
insertParagraphBreak(position: Position): DocumentAgent;
|
|
270
|
+
/**
|
|
271
|
+
* Merge consecutive paragraphs
|
|
272
|
+
*
|
|
273
|
+
* @param startParagraphIndex - First paragraph index
|
|
274
|
+
* @param count - Number of paragraphs to merge with the first
|
|
275
|
+
* @returns New DocumentAgent with paragraphs merged
|
|
276
|
+
*/
|
|
277
|
+
mergeParagraphs(startParagraphIndex: number, count: number): DocumentAgent;
|
|
278
|
+
/**
|
|
279
|
+
* Set a template variable value
|
|
280
|
+
*
|
|
281
|
+
* Note: Variables are not applied until `applyVariables()` is called
|
|
282
|
+
*
|
|
283
|
+
* @param name - Variable name (without braces)
|
|
284
|
+
* @param value - Variable value
|
|
285
|
+
* @returns This DocumentAgent (for chaining)
|
|
286
|
+
*/
|
|
287
|
+
setVariable(name: string, value: string): DocumentAgent;
|
|
288
|
+
/**
|
|
289
|
+
* Set multiple template variables
|
|
290
|
+
*
|
|
291
|
+
* @param variables - Map of variable names to values
|
|
292
|
+
* @returns This DocumentAgent (for chaining)
|
|
293
|
+
*/
|
|
294
|
+
setVariables(variables: Record<string, string>): DocumentAgent;
|
|
295
|
+
/**
|
|
296
|
+
* Get pending variable values
|
|
297
|
+
*
|
|
298
|
+
* @returns Map of pending variable values
|
|
299
|
+
*/
|
|
300
|
+
getPendingVariables(): Record<string, string>;
|
|
301
|
+
/**
|
|
302
|
+
* Clear pending variables
|
|
303
|
+
*
|
|
304
|
+
* @returns This DocumentAgent (for chaining)
|
|
305
|
+
*/
|
|
306
|
+
clearPendingVariables(): DocumentAgent;
|
|
307
|
+
/**
|
|
308
|
+
* Apply all pending template variables
|
|
309
|
+
*
|
|
310
|
+
* Uses docxtemplater to substitute variables while preserving formatting.
|
|
311
|
+
*
|
|
312
|
+
* @param variables - Optional additional variables (merged with pending)
|
|
313
|
+
* @returns New DocumentAgent with variables applied
|
|
314
|
+
*/
|
|
315
|
+
applyVariables(variables?: Record<string, string>): Promise<DocumentAgent>;
|
|
316
|
+
/**
|
|
317
|
+
* Export document to DOCX ArrayBuffer
|
|
318
|
+
*
|
|
319
|
+
* @returns Promise resolving to DOCX file as ArrayBuffer
|
|
320
|
+
*/
|
|
321
|
+
toBuffer(): Promise<ArrayBuffer>;
|
|
322
|
+
/**
|
|
323
|
+
* Export document to Blob
|
|
324
|
+
*
|
|
325
|
+
* @param mimeType - MIME type for the blob
|
|
326
|
+
* @returns Promise resolving to DOCX file as Blob
|
|
327
|
+
*/
|
|
328
|
+
toBlob(mimeType?: string): Promise<Blob>;
|
|
329
|
+
/**
|
|
330
|
+
* Execute multiple commands in sequence
|
|
331
|
+
*
|
|
332
|
+
* @param commands - Commands to execute
|
|
333
|
+
* @returns New DocumentAgent with all commands applied
|
|
334
|
+
*/
|
|
335
|
+
executeCommands(commands: AgentCommand[]): DocumentAgent;
|
|
336
|
+
/**
|
|
337
|
+
* Execute a single command and return new agent
|
|
338
|
+
*/
|
|
339
|
+
private _executeCommand;
|
|
340
|
+
/**
|
|
341
|
+
* Get plain text from document body
|
|
342
|
+
*/
|
|
343
|
+
private _getBodyText;
|
|
344
|
+
/**
|
|
345
|
+
* Get plain text from a paragraph
|
|
346
|
+
*/
|
|
347
|
+
private _getParagraphText;
|
|
348
|
+
/**
|
|
349
|
+
* Get plain text from a run
|
|
350
|
+
*/
|
|
351
|
+
private _getRunText;
|
|
352
|
+
/**
|
|
353
|
+
* Get plain text from a hyperlink
|
|
354
|
+
*/
|
|
355
|
+
private _getHyperlinkText;
|
|
356
|
+
/**
|
|
357
|
+
* Get plain text from a table
|
|
358
|
+
*/
|
|
359
|
+
private _getTableText;
|
|
360
|
+
/**
|
|
361
|
+
* Extract formatted text segments from a paragraph
|
|
362
|
+
*/
|
|
363
|
+
private _extractParagraphSegments;
|
|
364
|
+
/**
|
|
365
|
+
* Parse heading level from style ID
|
|
366
|
+
*/
|
|
367
|
+
private _parseHeadingLevel;
|
|
368
|
+
/**
|
|
369
|
+
* Check if document has images
|
|
370
|
+
*/
|
|
371
|
+
private _hasImages;
|
|
372
|
+
/**
|
|
373
|
+
* Check if document has hyperlinks
|
|
374
|
+
*/
|
|
375
|
+
private _hasHyperlinks;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Create a DocumentAgent from a DOCX buffer
|
|
379
|
+
*
|
|
380
|
+
* @param buffer - DOCX file as ArrayBuffer
|
|
381
|
+
* @returns Promise resolving to DocumentAgent
|
|
382
|
+
*/
|
|
383
|
+
declare function createAgent(buffer: ArrayBuffer): Promise<DocumentAgent>;
|
|
384
|
+
/**
|
|
385
|
+
* Create a DocumentAgent from a parsed Document
|
|
386
|
+
*
|
|
387
|
+
* @param document - Parsed Document
|
|
388
|
+
* @returns DocumentAgent
|
|
389
|
+
*/
|
|
390
|
+
declare function createAgentFromDocument(document: Document): DocumentAgent;
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Command Executor
|
|
394
|
+
*
|
|
395
|
+
* Executes agent commands on a document immutably:
|
|
396
|
+
* - Handles all command types from AgentCommand
|
|
397
|
+
* - Preserves surrounding formatting
|
|
398
|
+
* - Returns new document (immutable updates)
|
|
399
|
+
*/
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Execute an agent command on a document
|
|
403
|
+
* Returns a new document with the command applied (immutable)
|
|
404
|
+
*
|
|
405
|
+
* Dispatch order:
|
|
406
|
+
* 1. Try plugin handlers first (allows plugins to override built-in commands)
|
|
407
|
+
* 2. Fall back to built-in handlers
|
|
408
|
+
*
|
|
409
|
+
* @param doc - The document to modify
|
|
410
|
+
* @param command - The command to execute
|
|
411
|
+
* @returns New document with command applied
|
|
412
|
+
*/
|
|
413
|
+
declare function executeCommand(doc: Document, command: AgentCommand): Document;
|
|
414
|
+
/**
|
|
415
|
+
* Execute multiple commands in sequence
|
|
416
|
+
*
|
|
417
|
+
* @param doc - The document to modify
|
|
418
|
+
* @param commands - Commands to execute in order
|
|
419
|
+
* @returns New document with all commands applied
|
|
420
|
+
*/
|
|
421
|
+
declare function executeCommands(doc: Document, commands: AgentCommand[]): Document;
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Agent Context Builder
|
|
425
|
+
*
|
|
426
|
+
* Generates context objects for AI/LLM consumption from DOCX documents.
|
|
427
|
+
* The context provides a structured summary of the document that can be
|
|
428
|
+
* used by AI agents to understand the document structure and content.
|
|
429
|
+
*
|
|
430
|
+
* All outputs are JSON serializable for easy transmission to AI backends.
|
|
431
|
+
*/
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Options for building agent context
|
|
435
|
+
*/
|
|
436
|
+
interface AgentContextOptions {
|
|
437
|
+
/** Maximum characters per paragraph in outline (default: 100) */
|
|
438
|
+
outlineMaxChars?: number;
|
|
439
|
+
/** Maximum paragraphs to include in outline (default: 50) */
|
|
440
|
+
maxOutlineParagraphs?: number;
|
|
441
|
+
/** Include table content in context (default: false) */
|
|
442
|
+
includeTableContent?: boolean;
|
|
443
|
+
/** Include detailed formatting info (default: false) */
|
|
444
|
+
includeFormatting?: boolean;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Options for building selection context
|
|
448
|
+
*/
|
|
449
|
+
interface SelectionContextOptions$1 {
|
|
450
|
+
/** Characters of context before/after selection (default: 200) */
|
|
451
|
+
contextChars?: number;
|
|
452
|
+
/** Include suggested actions (default: true) */
|
|
453
|
+
includeSuggestions?: boolean;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Build agent context from a document
|
|
457
|
+
*
|
|
458
|
+
* @param doc - The parsed document
|
|
459
|
+
* @param options - Context building options
|
|
460
|
+
* @returns AgentContext object (JSON serializable)
|
|
461
|
+
*/
|
|
462
|
+
declare function getAgentContext(doc: Document, options?: AgentContextOptions): AgentContext;
|
|
463
|
+
/**
|
|
464
|
+
* Build selection context for AI operations
|
|
465
|
+
*
|
|
466
|
+
* @param doc - The parsed document
|
|
467
|
+
* @param range - The selected range
|
|
468
|
+
* @param options - Selection context options
|
|
469
|
+
* @returns SelectionContext object (JSON serializable)
|
|
470
|
+
*/
|
|
471
|
+
declare function buildSelectionContext$1(doc: Document, range: Range, options?: SelectionContextOptions$1): SelectionContext;
|
|
472
|
+
/**
|
|
473
|
+
* Get a simple document summary for quick context
|
|
474
|
+
*
|
|
475
|
+
* @param doc - The parsed document
|
|
476
|
+
* @returns Summary string
|
|
477
|
+
*/
|
|
478
|
+
declare function getDocumentSummary(doc: Document): string;
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Selection Context Builder
|
|
482
|
+
*
|
|
483
|
+
* Builds rich context objects from document selections for AI operations.
|
|
484
|
+
* Includes selected text, formatting, surrounding context, and suggested actions.
|
|
485
|
+
*/
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Options for building selection context
|
|
489
|
+
*/
|
|
490
|
+
interface SelectionContextOptions {
|
|
491
|
+
/** Characters of context before selection (default: 200) */
|
|
492
|
+
contextCharsBefore?: number;
|
|
493
|
+
/** Characters of context after selection (default: 200) */
|
|
494
|
+
contextCharsAfter?: number;
|
|
495
|
+
/** Include suggested actions (default: true) */
|
|
496
|
+
includeSuggestions?: boolean;
|
|
497
|
+
/** Include document summary (default: true) */
|
|
498
|
+
includeDocumentSummary?: boolean;
|
|
499
|
+
/** Maximum suggested actions (default: 8) */
|
|
500
|
+
maxSuggestions?: number;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Extended selection context with additional details
|
|
504
|
+
*/
|
|
505
|
+
interface ExtendedSelectionContext extends SelectionContext {
|
|
506
|
+
/** Document summary for additional context */
|
|
507
|
+
documentSummary?: string;
|
|
508
|
+
/** Selection word count */
|
|
509
|
+
wordCount?: number;
|
|
510
|
+
/** Selection character count */
|
|
511
|
+
characterCount?: number;
|
|
512
|
+
/** Is selection multi-paragraph */
|
|
513
|
+
isMultiParagraph?: boolean;
|
|
514
|
+
/** Selected paragraph indices */
|
|
515
|
+
paragraphIndices?: number[];
|
|
516
|
+
/** Language detection hint */
|
|
517
|
+
detectedLanguage?: string;
|
|
518
|
+
/** Content type hints */
|
|
519
|
+
contentType?: 'prose' | 'list' | 'heading' | 'table' | 'mixed';
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Selection formatting summary
|
|
523
|
+
*/
|
|
524
|
+
interface FormattingSummary {
|
|
525
|
+
/** Predominant formatting */
|
|
526
|
+
predominant: Partial<TextFormatting>;
|
|
527
|
+
/** Is formatting consistent across selection */
|
|
528
|
+
isConsistent: boolean;
|
|
529
|
+
/** All formatting found */
|
|
530
|
+
allFormatting: Partial<TextFormatting>[];
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Build selection context for AI operations
|
|
534
|
+
*
|
|
535
|
+
* @param doc - The parsed document
|
|
536
|
+
* @param range - The selected range
|
|
537
|
+
* @param options - Selection context options
|
|
538
|
+
* @returns SelectionContext object
|
|
539
|
+
*/
|
|
540
|
+
declare function buildSelectionContext(doc: Document, range: Range, options?: SelectionContextOptions): SelectionContext;
|
|
541
|
+
/**
|
|
542
|
+
* Build extended selection context with additional details
|
|
543
|
+
*
|
|
544
|
+
* @param doc - The parsed document
|
|
545
|
+
* @param range - The selected range
|
|
546
|
+
* @param options - Selection context options
|
|
547
|
+
* @returns ExtendedSelectionContext object
|
|
548
|
+
*/
|
|
549
|
+
declare function buildExtendedSelectionContext(doc: Document, range: Range, options?: SelectionContextOptions): ExtendedSelectionContext;
|
|
550
|
+
/**
|
|
551
|
+
* Get formatting summary for a selection
|
|
552
|
+
*
|
|
553
|
+
* @param doc - The parsed document
|
|
554
|
+
* @param range - The selected range
|
|
555
|
+
* @returns FormattingSummary object
|
|
556
|
+
*/
|
|
557
|
+
declare function getSelectionFormattingSummary(doc: Document, range: Range): FormattingSummary;
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Main Parser Orchestrator - Unified parseDocx function
|
|
561
|
+
*
|
|
562
|
+
* Coordinates all sub-parsers to produce a complete Document model.
|
|
563
|
+
* Handles loading order, dependency resolution, and font preloading.
|
|
564
|
+
*
|
|
565
|
+
* Parsing order:
|
|
566
|
+
* 1. Unzip DOCX package
|
|
567
|
+
* 2. Parse relationships
|
|
568
|
+
* 3. Parse theme (needed for style color/font resolution)
|
|
569
|
+
* 4. Parse styles (depends on theme)
|
|
570
|
+
* 5. Parse numbering
|
|
571
|
+
* 6. Parse document body (depends on styles, theme, numbering, rels)
|
|
572
|
+
* 7. Parse headers/footers (depends on styles, theme, numbering, rels)
|
|
573
|
+
* 8. Parse footnotes/endnotes (depends on styles, theme, numbering, rels)
|
|
574
|
+
* 9. Extract and load fonts
|
|
575
|
+
* 10. Build media file map
|
|
576
|
+
* 11. Assemble final Document
|
|
577
|
+
*/
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Progress callback for tracking parsing stages
|
|
581
|
+
*/
|
|
582
|
+
type ProgressCallback = (stage: string, percent: number) => void;
|
|
583
|
+
/**
|
|
584
|
+
* Parsing options
|
|
585
|
+
*/
|
|
586
|
+
interface ParseOptions {
|
|
587
|
+
/** Progress callback for tracking parsing stages */
|
|
588
|
+
onProgress?: ProgressCallback;
|
|
589
|
+
/** Whether to preload fonts (default: true) */
|
|
590
|
+
preloadFonts?: boolean;
|
|
591
|
+
/** Whether to parse headers/footers (default: true) */
|
|
592
|
+
parseHeadersFooters?: boolean;
|
|
593
|
+
/** Whether to parse footnotes/endnotes (default: true) */
|
|
594
|
+
parseNotes?: boolean;
|
|
595
|
+
/** Whether to detect template variables (default: true) */
|
|
596
|
+
detectVariables?: boolean;
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Parse a DOCX file into a complete Document model
|
|
600
|
+
*
|
|
601
|
+
* @param buffer - DOCX file as ArrayBuffer
|
|
602
|
+
* @param options - Parsing options
|
|
603
|
+
* @returns Promise resolving to Document
|
|
604
|
+
* @throws Error if parsing fails
|
|
605
|
+
*/
|
|
606
|
+
declare function parseDocx(buffer: ArrayBuffer, options?: ParseOptions): Promise<Document>;
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Document Serializer - Serialize complete document.xml
|
|
610
|
+
*
|
|
611
|
+
* Converts Document objects back to valid document.xml OOXML format.
|
|
612
|
+
* Combines all content (paragraphs, tables) with section properties
|
|
613
|
+
* and proper namespace declarations.
|
|
614
|
+
*
|
|
615
|
+
* OOXML Reference:
|
|
616
|
+
* - Document root: w:document
|
|
617
|
+
* - Document body: w:body
|
|
618
|
+
* - Section properties: w:sectPr
|
|
619
|
+
*/
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Serialize section properties (w:sectPr)
|
|
623
|
+
*/
|
|
624
|
+
declare function serializeSectionProperties(props: SectionProperties | undefined): string;
|
|
625
|
+
/**
|
|
626
|
+
* Serialize a DocumentBody to document.xml body content
|
|
627
|
+
*
|
|
628
|
+
* @param body - The document body to serialize
|
|
629
|
+
* @returns XML string for the body element (without body tags)
|
|
630
|
+
*/
|
|
631
|
+
declare function serializeDocumentBody(body: DocumentBody): string;
|
|
632
|
+
/**
|
|
633
|
+
* Serialize a complete Document to valid document.xml
|
|
634
|
+
*
|
|
635
|
+
* @param doc - The document to serialize
|
|
636
|
+
* @returns Complete XML string for document.xml
|
|
637
|
+
*/
|
|
638
|
+
declare function serializeDocument(doc: Document): string;
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Template Processing Utility
|
|
642
|
+
*
|
|
643
|
+
* Uses docxtemplater to substitute template variables in DOCX documents:
|
|
644
|
+
* - Processes {variable_name} patterns (docxtemplater default syntax)
|
|
645
|
+
* - Preserves all formatting (fonts, styles, colors, tables)
|
|
646
|
+
* - Error handling with useful messages
|
|
647
|
+
*/
|
|
648
|
+
/**
|
|
649
|
+
* Options for template processing
|
|
650
|
+
*/
|
|
651
|
+
interface ProcessTemplateOptions {
|
|
652
|
+
/** How to handle undefined variables */
|
|
653
|
+
nullGetter?: 'keep' | 'empty' | 'error';
|
|
654
|
+
/** Custom parser for variable names */
|
|
655
|
+
parser?: (tag: string) => {
|
|
656
|
+
get: (scope: Record<string, unknown>) => unknown;
|
|
657
|
+
};
|
|
658
|
+
/** Line breaks: keep raw \n or convert to w:br */
|
|
659
|
+
linebreaks?: boolean;
|
|
660
|
+
/** Delimiter settings */
|
|
661
|
+
delimiters?: {
|
|
662
|
+
start?: string;
|
|
663
|
+
end?: string;
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Result of template processing
|
|
668
|
+
*/
|
|
669
|
+
interface ProcessTemplateResult {
|
|
670
|
+
/** The processed document buffer */
|
|
671
|
+
buffer: ArrayBuffer;
|
|
672
|
+
/** Variables that were found and replaced */
|
|
673
|
+
replacedVariables: string[];
|
|
674
|
+
/** Variables that were not replaced (no value provided) */
|
|
675
|
+
unreplacedVariables: string[];
|
|
676
|
+
/** Any warnings during processing */
|
|
677
|
+
warnings: string[];
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Error details from template processing
|
|
681
|
+
*/
|
|
682
|
+
interface TemplateError {
|
|
683
|
+
/** Error message */
|
|
684
|
+
message: string;
|
|
685
|
+
/** Variable name that caused the error (if applicable) */
|
|
686
|
+
variable?: string;
|
|
687
|
+
/** Error type */
|
|
688
|
+
type: 'parse' | 'render' | 'undefined' | 'unknown';
|
|
689
|
+
/** Original error */
|
|
690
|
+
originalError?: Error;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Process a DOCX template with variable substitution
|
|
694
|
+
*
|
|
695
|
+
* @param buffer - The DOCX file as ArrayBuffer
|
|
696
|
+
* @param variables - Map of variable names to values
|
|
697
|
+
* @param options - Processing options
|
|
698
|
+
* @returns Processed DOCX as ArrayBuffer
|
|
699
|
+
*/
|
|
700
|
+
declare function processTemplate(buffer: ArrayBuffer, variables: Record<string, string>, options?: ProcessTemplateOptions): ArrayBuffer;
|
|
701
|
+
/**
|
|
702
|
+
* Process template with detailed result
|
|
703
|
+
*
|
|
704
|
+
* @param buffer - The DOCX file as ArrayBuffer
|
|
705
|
+
* @param variables - Map of variable names to values
|
|
706
|
+
* @param options - Processing options
|
|
707
|
+
* @returns Detailed processing result
|
|
708
|
+
*/
|
|
709
|
+
declare function processTemplateDetailed(buffer: ArrayBuffer, variables: Record<string, string>, options?: ProcessTemplateOptions): ProcessTemplateResult;
|
|
710
|
+
/**
|
|
711
|
+
* Process template and return as Blob
|
|
712
|
+
*
|
|
713
|
+
* @param buffer - The DOCX file as ArrayBuffer
|
|
714
|
+
* @param variables - Map of variable names to values
|
|
715
|
+
* @param options - Processing options
|
|
716
|
+
* @returns Processed DOCX as Blob
|
|
717
|
+
*/
|
|
718
|
+
declare function processTemplateAsBlob(buffer: ArrayBuffer, variables: Record<string, string>, options?: ProcessTemplateOptions): Blob;
|
|
719
|
+
/**
|
|
720
|
+
* Get all template tags in a document without processing
|
|
721
|
+
*
|
|
722
|
+
* @param buffer - The DOCX file as ArrayBuffer
|
|
723
|
+
* @returns List of tag names found
|
|
724
|
+
*/
|
|
725
|
+
declare function getTemplateTags(buffer: ArrayBuffer): string[];
|
|
726
|
+
/**
|
|
727
|
+
* Validate that a document is a valid docxtemplater template
|
|
728
|
+
*
|
|
729
|
+
* @param buffer - The DOCX file as ArrayBuffer
|
|
730
|
+
* @returns Validation result
|
|
731
|
+
*/
|
|
732
|
+
declare function validateTemplate(buffer: ArrayBuffer): {
|
|
733
|
+
valid: boolean;
|
|
734
|
+
errors: TemplateError[];
|
|
735
|
+
tags: string[];
|
|
736
|
+
};
|
|
737
|
+
/**
|
|
738
|
+
* Check if all required variables have values
|
|
739
|
+
*
|
|
740
|
+
* @param tags - List of template tags
|
|
741
|
+
* @param variables - Provided variable values
|
|
742
|
+
* @returns Missing variable names
|
|
743
|
+
*/
|
|
744
|
+
declare function getMissingVariables(tags: string[], variables: Record<string, string>): string[];
|
|
745
|
+
/**
|
|
746
|
+
* Preview what the document will look like after processing
|
|
747
|
+
* Returns the document text with variables replaced (for preview purposes)
|
|
748
|
+
*
|
|
749
|
+
* @param buffer - The DOCX file as ArrayBuffer
|
|
750
|
+
* @param variables - Map of variable names to values
|
|
751
|
+
* @returns Preview text
|
|
752
|
+
*/
|
|
753
|
+
declare function previewTemplate(buffer: ArrayBuffer, variables: Record<string, string>): string;
|
|
754
|
+
/**
|
|
755
|
+
* Process template with conditional sections
|
|
756
|
+
* Supports #if, #unless, #each loops
|
|
757
|
+
*
|
|
758
|
+
* @param buffer - The DOCX file as ArrayBuffer
|
|
759
|
+
* @param data - Full data object (can include arrays, nested objects)
|
|
760
|
+
* @param options - Processing options
|
|
761
|
+
* @returns Processed DOCX as ArrayBuffer
|
|
762
|
+
*/
|
|
763
|
+
declare function processTemplateAdvanced(buffer: ArrayBuffer, data: Record<string, unknown>, options?: ProcessTemplateOptions): ArrayBuffer;
|
|
764
|
+
/**
|
|
765
|
+
* Create a template processor with preset options
|
|
766
|
+
*/
|
|
767
|
+
declare function createTemplateProcessor(defaultOptions?: ProcessTemplateOptions): (buffer: ArrayBuffer, variables: Record<string, string>) => ArrayBuffer;
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* Create Document Utility
|
|
771
|
+
*
|
|
772
|
+
* Provides functions to create new documents programmatically.
|
|
773
|
+
*/
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* Options for creating an empty document
|
|
777
|
+
*/
|
|
778
|
+
interface CreateEmptyDocumentOptions {
|
|
779
|
+
/** Page width in twips (default: 12240 = 8.5 inches) */
|
|
780
|
+
pageWidth?: number;
|
|
781
|
+
/** Page height in twips (default: 15840 = 11 inches) */
|
|
782
|
+
pageHeight?: number;
|
|
783
|
+
/** Page orientation (default: 'portrait') */
|
|
784
|
+
orientation?: 'portrait' | 'landscape';
|
|
785
|
+
/** Top margin in twips (default: 1440 = 1 inch) */
|
|
786
|
+
marginTop?: number;
|
|
787
|
+
/** Bottom margin in twips (default: 1440 = 1 inch) */
|
|
788
|
+
marginBottom?: number;
|
|
789
|
+
/** Left margin in twips (default: 1440 = 1 inch) */
|
|
790
|
+
marginLeft?: number;
|
|
791
|
+
/** Right margin in twips (default: 1440 = 1 inch) */
|
|
792
|
+
marginRight?: number;
|
|
793
|
+
/** Initial text content (default: empty string) */
|
|
794
|
+
initialText?: string;
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Create an empty document with a single paragraph
|
|
798
|
+
*
|
|
799
|
+
* @param options - Optional configuration for the document
|
|
800
|
+
* @returns A new empty Document object
|
|
801
|
+
*
|
|
802
|
+
* @example
|
|
803
|
+
* ```ts
|
|
804
|
+
* // Create a blank document
|
|
805
|
+
* const doc = createEmptyDocument();
|
|
806
|
+
*
|
|
807
|
+
* // Create with custom margins
|
|
808
|
+
* const doc = createEmptyDocument({
|
|
809
|
+
* marginTop: 720, // 0.5 inch
|
|
810
|
+
* marginBottom: 720,
|
|
811
|
+
* });
|
|
812
|
+
*
|
|
813
|
+
* // Create with initial text
|
|
814
|
+
* const doc = createEmptyDocument({
|
|
815
|
+
* initialText: 'Hello, World!'
|
|
816
|
+
* });
|
|
817
|
+
* ```
|
|
818
|
+
*/
|
|
819
|
+
declare function createEmptyDocument(options?: CreateEmptyDocumentOptions): Document;
|
|
820
|
+
/**
|
|
821
|
+
* Create a document with a single paragraph containing the given text
|
|
822
|
+
*
|
|
823
|
+
* @param text - The text content for the document
|
|
824
|
+
* @param options - Optional configuration for the document
|
|
825
|
+
* @returns A new Document object with the specified text
|
|
826
|
+
*/
|
|
827
|
+
declare function createDocumentWithText(text: string, options?: Omit<CreateEmptyDocumentOptions, 'initialText'>): Document;
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Convert twips to pixels (at 96 DPI)
|
|
831
|
+
*
|
|
832
|
+
* 1 inch = 1440 twips = 96 pixels
|
|
833
|
+
* → 1 twip = 96/1440 pixels = 1/15 pixels
|
|
834
|
+
*
|
|
835
|
+
* @param twips - Value in twips (1/20 of a point)
|
|
836
|
+
* @returns Value in pixels
|
|
837
|
+
*/
|
|
838
|
+
declare function twipsToPixels(twips: number): number;
|
|
839
|
+
/**
|
|
840
|
+
* Convert pixels to twips
|
|
841
|
+
*
|
|
842
|
+
* @param px - Value in pixels
|
|
843
|
+
* @returns Value in twips
|
|
844
|
+
*/
|
|
845
|
+
declare function pixelsToTwips(px: number): number;
|
|
846
|
+
/**
|
|
847
|
+
* Convert EMUs to pixels (at 96 DPI)
|
|
848
|
+
*
|
|
849
|
+
* 1 inch = 914400 EMUs = 96 pixels
|
|
850
|
+
* → 1 EMU = 96/914400 pixels
|
|
851
|
+
*
|
|
852
|
+
* @param emu - Value in EMUs (English Metric Units)
|
|
853
|
+
* @returns Value in pixels
|
|
854
|
+
*/
|
|
855
|
+
declare function emuToPixels(emu: number): number;
|
|
856
|
+
/**
|
|
857
|
+
* Convert pixels to EMUs
|
|
858
|
+
*
|
|
859
|
+
* @param px - Value in pixels
|
|
860
|
+
* @returns Value in EMUs
|
|
861
|
+
*/
|
|
862
|
+
declare function pixelsToEmu(px: number): number;
|
|
863
|
+
/**
|
|
864
|
+
* Convert EMUs to twips
|
|
865
|
+
*
|
|
866
|
+
* @param emu - Value in EMUs
|
|
867
|
+
* @returns Value in twips
|
|
868
|
+
*/
|
|
869
|
+
declare function emuToTwips(emu: number): number;
|
|
870
|
+
/**
|
|
871
|
+
* Convert twips to EMUs
|
|
872
|
+
*
|
|
873
|
+
* @param twips - Value in twips
|
|
874
|
+
* @returns Value in EMUs
|
|
875
|
+
*/
|
|
876
|
+
declare function twipsToEmu(twips: number): number;
|
|
877
|
+
/**
|
|
878
|
+
* Convert points to pixels (at 96 DPI)
|
|
879
|
+
*
|
|
880
|
+
* 1 inch = 72 points = 96 pixels
|
|
881
|
+
* → 1 point = 96/72 pixels = 4/3 pixels
|
|
882
|
+
*
|
|
883
|
+
* @param points - Value in points
|
|
884
|
+
* @returns Value in pixels
|
|
885
|
+
*/
|
|
886
|
+
declare function pointsToPixels(points: number): number;
|
|
887
|
+
/**
|
|
888
|
+
* Convert half-points to pixels (at 96 DPI)
|
|
889
|
+
*
|
|
890
|
+
* 1 inch = 144 half-points = 96 pixels
|
|
891
|
+
* → 1 half-point = 96/144 pixels = 2/3 pixels
|
|
892
|
+
*
|
|
893
|
+
* Half-points are commonly used for font sizes in OOXML (w:sz).
|
|
894
|
+
*
|
|
895
|
+
* @param halfPoints - Value in half-points
|
|
896
|
+
* @returns Value in pixels
|
|
897
|
+
*/
|
|
898
|
+
declare function halfPointsToPixels(halfPoints: number): number;
|
|
899
|
+
/**
|
|
900
|
+
* Format a pixel value as CSS string
|
|
901
|
+
*
|
|
902
|
+
* @param px - Value in pixels
|
|
903
|
+
* @returns CSS string (e.g., "16px")
|
|
904
|
+
*/
|
|
905
|
+
declare function formatPx(px: number): string;
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* Color Resolver - Convert OOXML colors to CSS
|
|
909
|
+
*
|
|
910
|
+
* Handles:
|
|
911
|
+
* - Theme color references (accent1, dk1, etc.)
|
|
912
|
+
* - RGB hex values
|
|
913
|
+
* - "auto" colors (context-dependent)
|
|
914
|
+
* - Tint/shade modifications
|
|
915
|
+
*
|
|
916
|
+
* OOXML Color References:
|
|
917
|
+
* - w:color/@w:val - RGB hex or "auto"
|
|
918
|
+
* - w:color/@w:themeColor - Theme color slot
|
|
919
|
+
* - w:color/@w:themeTint - Tint modifier (0-255, hex)
|
|
920
|
+
* - w:color/@w:themeShade - Shade modifier (0-255, hex)
|
|
921
|
+
*
|
|
922
|
+
* Tint/Shade Calculations:
|
|
923
|
+
* - Tint makes color lighter (blend with white)
|
|
924
|
+
* - Shade makes color darker (blend with black)
|
|
925
|
+
* - Value is in hex (00-FF), converted to 0-1 for calculation
|
|
926
|
+
*/
|
|
927
|
+
|
|
928
|
+
/**
|
|
929
|
+
* Resolve a ColorValue to a CSS color string
|
|
930
|
+
*
|
|
931
|
+
* @param color - ColorValue object with rgb, themeColor, tint/shade, or auto
|
|
932
|
+
* @param theme - Theme for resolving theme colors
|
|
933
|
+
* @param defaultColor - Default color if auto or undefined (default: black)
|
|
934
|
+
* @returns CSS color string (e.g., "#FF0000" or "inherit")
|
|
935
|
+
*/
|
|
936
|
+
declare function resolveColor(color: ColorValue | undefined | null, theme: Theme | null | undefined, defaultColor?: string): string;
|
|
937
|
+
/**
|
|
938
|
+
* Resolve a highlight color name to CSS
|
|
939
|
+
*
|
|
940
|
+
* @param highlight - Highlight color name (e.g., "yellow", "cyan")
|
|
941
|
+
* @returns CSS color string or empty string for "none"
|
|
942
|
+
*/
|
|
943
|
+
declare function resolveHighlightColor(highlight: string | undefined): string;
|
|
944
|
+
/**
|
|
945
|
+
* Resolve a shading fill or pattern color to CSS
|
|
946
|
+
*
|
|
947
|
+
* @param color - ColorValue for fill
|
|
948
|
+
* @param theme - Theme for resolving theme colors
|
|
949
|
+
* @returns CSS color string
|
|
950
|
+
*/
|
|
951
|
+
declare function resolveShadingColor(color: ColorValue | undefined | null, theme: Theme | null | undefined): string;
|
|
952
|
+
/**
|
|
953
|
+
* Check if a color is effectively black
|
|
954
|
+
*
|
|
955
|
+
* @param color - ColorValue object
|
|
956
|
+
* @param theme - Theme for resolving theme colors
|
|
957
|
+
* @returns True if color resolves to black or very dark
|
|
958
|
+
*/
|
|
959
|
+
declare function isBlack(color: ColorValue | undefined | null, theme: Theme | null | undefined): boolean;
|
|
960
|
+
/**
|
|
961
|
+
* Check if a color is effectively white
|
|
962
|
+
*
|
|
963
|
+
* @param color - ColorValue object
|
|
964
|
+
* @param theme - Theme for resolving theme colors
|
|
965
|
+
* @returns True if color resolves to white or very light
|
|
966
|
+
*/
|
|
967
|
+
declare function isWhite(color: ColorValue | undefined | null, theme: Theme | null | undefined): boolean;
|
|
968
|
+
/**
|
|
969
|
+
* Get contrasting text color for a background
|
|
970
|
+
*
|
|
971
|
+
* @param backgroundColor - Background ColorValue
|
|
972
|
+
* @param theme - Theme for resolving theme colors
|
|
973
|
+
* @returns Black or white hex color for best contrast
|
|
974
|
+
*/
|
|
975
|
+
declare function getContrastingColor(backgroundColor: ColorValue | undefined | null, theme: Theme | null | undefined): string;
|
|
976
|
+
/**
|
|
977
|
+
* Parse a color string (various formats) to ColorValue
|
|
978
|
+
*
|
|
979
|
+
* @param colorString - Color string like "FF0000", "auto", or theme color name
|
|
980
|
+
* @returns ColorValue object
|
|
981
|
+
*/
|
|
982
|
+
declare function parseColorString(colorString: string | undefined): ColorValue | undefined;
|
|
983
|
+
/**
|
|
984
|
+
* Create a ColorValue from theme color reference
|
|
985
|
+
*
|
|
986
|
+
* @param themeColor - Theme color slot name
|
|
987
|
+
* @param tint - Optional tint modifier
|
|
988
|
+
* @param shade - Optional shade modifier
|
|
989
|
+
* @returns ColorValue object
|
|
990
|
+
*/
|
|
991
|
+
declare function createThemeColor(themeColor: ThemeColorSlot, tint?: number, shade?: number): ColorValue;
|
|
992
|
+
/**
|
|
993
|
+
* Create a ColorValue from RGB hex
|
|
994
|
+
*
|
|
995
|
+
* @param hex - 6-character hex color (no #)
|
|
996
|
+
* @returns ColorValue object
|
|
997
|
+
*/
|
|
998
|
+
declare function createRgbColor(hex: string): ColorValue;
|
|
999
|
+
/**
|
|
1000
|
+
* Darken a color by a percentage
|
|
1001
|
+
*
|
|
1002
|
+
* @param color - ColorValue to darken
|
|
1003
|
+
* @param theme - Theme for resolving
|
|
1004
|
+
* @param percent - Percentage to darken (0-100)
|
|
1005
|
+
* @returns CSS color string
|
|
1006
|
+
*/
|
|
1007
|
+
declare function darkenColor(color: ColorValue | undefined | null, theme: Theme | null | undefined, percent: number): string;
|
|
1008
|
+
/**
|
|
1009
|
+
* Lighten a color by a percentage
|
|
1010
|
+
*
|
|
1011
|
+
* @param color - ColorValue to lighten
|
|
1012
|
+
* @param theme - Theme for resolving
|
|
1013
|
+
* @param percent - Percentage to lighten (0-100)
|
|
1014
|
+
* @returns CSS color string
|
|
1015
|
+
*/
|
|
1016
|
+
declare function lightenColor(color: ColorValue | undefined | null, theme: Theme | null | undefined, percent: number): string;
|
|
1017
|
+
/**
|
|
1018
|
+
* Blend two colors together
|
|
1019
|
+
*
|
|
1020
|
+
* @param color1 - First color
|
|
1021
|
+
* @param color2 - Second color
|
|
1022
|
+
* @param ratio - Blend ratio (0 = all color1, 1 = all color2)
|
|
1023
|
+
* @param theme - Theme for resolving
|
|
1024
|
+
* @returns CSS color string
|
|
1025
|
+
*/
|
|
1026
|
+
declare function blendColors(color1: ColorValue | undefined | null, color2: ColorValue | undefined | null, ratio: number, theme: Theme | null | undefined): string;
|
|
1027
|
+
/**
|
|
1028
|
+
* Check if two colors are equal
|
|
1029
|
+
*
|
|
1030
|
+
* @param color1 - First color
|
|
1031
|
+
* @param color2 - Second color
|
|
1032
|
+
* @param theme - Theme for resolving
|
|
1033
|
+
* @returns True if colors resolve to the same value
|
|
1034
|
+
*/
|
|
1035
|
+
declare function colorsEqual(color1: ColorValue | undefined | null, color2: ColorValue | undefined | null, theme: Theme | null | undefined): boolean;
|
|
1036
|
+
|
|
1037
|
+
export { resolveColor as $, type AgentContextOptions as A, getDocumentSummary as B, type CreateEmptyDocumentOptions as C, DocumentAgent as D, type ExtendedSelectionContext as E, type FormattedTextSegment as F, getMissingVariables as G, getSelectionFormattingSummary as H, type InsertHyperlinkOptions as I, getTemplateTags as J, halfPointsToPixels as K, isBlack as L, isWhite as M, lightenColor as N, parseColorString as O, type ProcessTemplateOptions as P, parseDocx as Q, pixelsToEmu as R, type SelectionContextOptions$1 as S, type TemplateError as T, pixelsToTwips as U, pointsToPixels as V, previewTemplate as W, processTemplate as X, processTemplateAdvanced as Y, processTemplateAsBlob as Z, processTemplateDetailed as _, type FormattingSummary as a, resolveHighlightColor as a0, resolveShadingColor as a1, serializeDocumentBody as a2, serializeDocument as a3, serializeSectionProperties as a4, twipsToEmu as a5, twipsToPixels as a6, validateTemplate as a7, type InsertImageOptions as b, type InsertTableOptions as c, type InsertTextOptions as d, type ProcessTemplateResult as e, type SelectionContextOptions as f, blendColors as g, buildExtendedSelectionContext as h, buildSelectionContext as i, buildSelectionContext$1 as j, colorsEqual as k, createAgent as l, createAgentFromDocument as m, createDocumentWithText as n, createEmptyDocument as o, createRgbColor as p, createTemplateProcessor as q, createThemeColor as r, darkenColor as s, emuToPixels as t, emuToTwips as u, executeCommand as v, executeCommands as w, formatPx as x, getAgentContext as y, getContrastingColor as z };
|