@eigenpal/docx-editor-agents 0.1.1 → 0.3.0

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 (45) hide show
  1. package/README.md +69 -16
  2. package/dist/ai-sdk/react.d.mts +67 -0
  3. package/dist/ai-sdk/react.d.ts +67 -0
  4. package/dist/ai-sdk/react.js +1 -0
  5. package/dist/ai-sdk/react.mjs +1 -0
  6. package/dist/ai-sdk/server.d.mts +42 -0
  7. package/dist/ai-sdk/server.d.ts +42 -0
  8. package/dist/ai-sdk/server.js +1 -0
  9. package/dist/ai-sdk/server.mjs +1 -0
  10. package/dist/bridge.d.mts +1 -11
  11. package/dist/bridge.d.ts +1 -11
  12. package/dist/bridge.js +1 -1
  13. package/dist/bridge.mjs +1 -1
  14. package/dist/{chunk-W2QSJSB7.mjs → chunk-25L7AEDN.mjs} +11 -11
  15. package/dist/chunk-3HEONW4M.js +5 -0
  16. package/dist/chunk-AMRM73UC.mjs +5 -0
  17. package/dist/chunk-HTCA4A6G.mjs +1 -0
  18. package/dist/chunk-O7DEBIDX.js +2 -0
  19. package/dist/chunk-T5P2DWHN.js +8 -0
  20. package/dist/chunk-TICYYVCD.mjs +8 -0
  21. package/dist/chunk-U7PAJJYD.js +1 -0
  22. package/dist/{chunk-G5XAABHF.js → chunk-VF25WARH.js} +11 -11
  23. package/dist/chunk-WGUYD2A2.mjs +2 -0
  24. package/dist/headless-B7TGKW6I.js +1 -0
  25. package/dist/{headless-I5CZ42MD.mjs → headless-PZWHORT6.mjs} +1 -1
  26. package/dist/index.d.mts +118 -1997
  27. package/dist/index.d.ts +118 -1997
  28. package/dist/index.js +1 -5
  29. package/dist/index.mjs +1 -5
  30. package/dist/mcp.d.mts +180 -0
  31. package/dist/mcp.d.ts +180 -0
  32. package/dist/mcp.js +4 -0
  33. package/dist/mcp.mjs +4 -0
  34. package/dist/react.d.mts +78 -0
  35. package/dist/react.d.ts +78 -0
  36. package/dist/react.js +1 -0
  37. package/dist/react.mjs +1 -0
  38. package/dist/server-B7dGWiLh.d.mts +2395 -0
  39. package/dist/server-B7dGWiLh.d.ts +2395 -0
  40. package/dist/server.d.mts +1 -0
  41. package/dist/server.d.ts +1 -0
  42. package/dist/server.js +1 -0
  43. package/dist/server.mjs +1 -0
  44. package/package.json +52 -1
  45. package/dist/headless-DGAHMYIU.js +0 -1
package/dist/index.d.ts CHANGED
@@ -1,2026 +1,147 @@
1
- /**
2
- * Color & Styling Primitives
3
- *
4
- * Basic types used throughout OOXML for colors, borders, and shading.
5
- */
6
- /**
7
- * Theme color slots from theme1.xml
8
- */
9
- type ThemeColorSlot = 'dk1' | 'lt1' | 'dk2' | 'lt2' | 'accent1' | 'accent2' | 'accent3' | 'accent4' | 'accent5' | 'accent6' | 'hlink' | 'folHlink' | 'background1' | 'text1' | 'background2' | 'text2';
10
- /**
11
- * Color value - can be direct RGB, theme reference, or auto
12
- */
13
- interface ColorValue {
14
- /** RGB hex value without # (e.g., "FF0000") */
15
- rgb?: string;
16
- /** Theme color slot reference */
17
- themeColor?: ThemeColorSlot;
18
- /** Tint modifier (0-255 as hex string, e.g., "80") - makes color lighter */
19
- themeTint?: string;
20
- /** Shade modifier (0-255 as hex string) - makes color darker */
21
- themeShade?: string;
22
- /** Auto color - context-dependent (usually black for text) */
23
- auto?: boolean;
24
- }
25
- /**
26
- * Border specification for any border (paragraph, table, page)
27
- */
28
- interface BorderSpec {
29
- /** Border style */
30
- style: 'none' | 'single' | 'double' | 'dotted' | 'dashed' | 'thick' | 'triple' | 'thinThickSmallGap' | 'thickThinSmallGap' | 'thinThickMediumGap' | 'thickThinMediumGap' | 'thinThickLargeGap' | 'thickThinLargeGap' | 'wave' | 'doubleWave' | 'dashSmallGap' | 'dashDotStroked' | 'threeDEmboss' | 'threeDEngrave' | 'outset' | 'inset' | 'nil';
31
- /** Color of the border */
32
- color?: ColorValue;
33
- /** Width in eighths of a point (1/8 pt) */
34
- size?: number;
35
- /** Spacing from text in points */
36
- space?: number;
37
- /** Shadow effect */
38
- shadow?: boolean;
39
- /** Frame effect */
40
- frame?: boolean;
41
- }
42
- /**
43
- * Shading/background properties
44
- */
45
- interface ShadingProperties {
46
- /** Pattern fill color */
47
- color?: ColorValue;
48
- /** Background fill color */
49
- fill?: ColorValue;
50
- /** Shading pattern type */
51
- pattern?: 'clear' | 'solid' | 'horzStripe' | 'vertStripe' | 'reverseDiagStripe' | 'diagStripe' | 'horzCross' | 'diagCross' | 'thinHorzStripe' | 'thinVertStripe' | 'thinReverseDiagStripe' | 'thinDiagStripe' | 'thinHorzCross' | 'thinDiagCross' | 'pct5' | 'pct10' | 'pct12' | 'pct15' | 'pct20' | 'pct25' | 'pct30' | 'pct35' | 'pct37' | 'pct40' | 'pct45' | 'pct50' | 'pct55' | 'pct60' | 'pct62' | 'pct65' | 'pct70' | 'pct75' | 'pct80' | 'pct85' | 'pct87' | 'pct90' | 'pct95' | 'nil';
52
- }
1
+ import { G as GetContentOptions, C as ContentBlock, e as CommentFilter, R as ReviewComment, f as ChangeFilter, h as ReviewChange, F as FoundMatch, S as SelectionInfo, i as AddCommentByParaIdOptions, j as ReplyOptions, P as ProposeChangeOptions, k as ApplyFormattingOptions, l as SetParagraphStyleOptions, m as PageContent, n as ContentChangeEvent, o as SelectionChangeEvent } from './server-B7dGWiLh.js';
2
+ export { A as AgentToolDefinition, a as AgentToolResult, B as BatchError, p as BatchResult, q as BatchReviewOptions, D as DocxReviewer, r as agentTools, s as createReviewerBridge, t as executeToolCall, g as getToolSchemas } from './server-B7dGWiLh.js';
53
3
 
54
4
  /**
55
- * Text, Paragraph, and Table Formatting Types
56
- *
57
- * Properties that control how text, paragraphs, and table structures
58
- * are formatted in OOXML (w:rPr, w:pPr, w:tblPr, etc.).
59
- */
60
-
61
- /**
62
- * Underline style options
63
- */
64
- type UnderlineStyle = 'none' | 'single' | 'words' | 'double' | 'thick' | 'dotted' | 'dottedHeavy' | 'dash' | 'dashedHeavy' | 'dashLong' | 'dashLongHeavy' | 'dotDash' | 'dashDotHeavy' | 'dotDotDash' | 'dashDotDotHeavy' | 'wave' | 'wavyHeavy' | 'wavyDouble';
65
- /**
66
- * Text effect animations
67
- */
68
- type TextEffect = 'none' | 'blinkBackground' | 'lights' | 'antsBlack' | 'antsRed' | 'shimmer' | 'sparkle';
69
- /**
70
- * Emphasis mark type
71
- */
72
- type EmphasisMark = 'none' | 'dot' | 'comma' | 'circle' | 'underDot';
73
- /**
74
- * Complete text formatting properties (w:rPr)
75
- */
76
- interface TextFormatting {
77
- /** Bold (w:b) */
78
- bold?: boolean;
79
- /** Bold complex script (w:bCs) */
80
- boldCs?: boolean;
81
- /** Italic (w:i) */
82
- italic?: boolean;
83
- /** Italic complex script (w:iCs) */
84
- italicCs?: boolean;
85
- /** Underline style and color (w:u) */
86
- underline?: {
87
- style: UnderlineStyle;
88
- color?: ColorValue;
89
- };
90
- /** Strikethrough (w:strike) */
91
- strike?: boolean;
92
- /** Double strikethrough (w:dstrike) */
93
- doubleStrike?: boolean;
94
- /** Superscript/subscript (w:vertAlign) */
95
- vertAlign?: 'baseline' | 'superscript' | 'subscript';
96
- /** Small caps (w:smallCaps) */
97
- smallCaps?: boolean;
98
- /** All caps (w:caps) */
99
- allCaps?: boolean;
100
- /** Hidden text (w:vanish) */
101
- hidden?: boolean;
102
- /** Text color (w:color) */
103
- color?: ColorValue;
104
- /** Highlight/background color (w:highlight) */
105
- highlight?: 'black' | 'blue' | 'cyan' | 'darkBlue' | 'darkCyan' | 'darkGray' | 'darkGreen' | 'darkMagenta' | 'darkRed' | 'darkYellow' | 'green' | 'lightGray' | 'magenta' | 'none' | 'red' | 'white' | 'yellow';
106
- /** Character shading (w:shd) */
107
- shading?: ShadingProperties;
108
- /** Font size in half-points (w:sz) - e.g., 24 = 12pt */
109
- fontSize?: number;
110
- /** Font size complex script (w:szCs) */
111
- fontSizeCs?: number;
112
- /** Font family (w:rFonts) */
113
- fontFamily?: {
114
- ascii?: string;
115
- hAnsi?: string;
116
- eastAsia?: string;
117
- cs?: string;
118
- /** Theme font reference */
119
- asciiTheme?: 'majorAscii' | 'majorHAnsi' | 'majorEastAsia' | 'majorBidi' | 'minorAscii' | 'minorHAnsi' | 'minorEastAsia' | 'minorBidi';
120
- hAnsiTheme?: string;
121
- eastAsiaTheme?: string;
122
- csTheme?: string;
123
- };
124
- /** Character spacing in twips (w:spacing) */
125
- spacing?: number;
126
- /** Raised/lowered text position in half-points (w:position) */
127
- position?: number;
128
- /** Horizontal text scale percentage (w:w) */
129
- scale?: number;
130
- /** Kerning threshold in half-points (w:kern) */
131
- kerning?: number;
132
- /** Text effect animation (w:effect) */
133
- effect?: TextEffect;
134
- /** Emphasis mark (w:em) */
135
- emphasisMark?: EmphasisMark;
136
- /** Emboss effect (w:emboss) */
137
- emboss?: boolean;
138
- /** Imprint/engrave effect (w:imprint) */
139
- imprint?: boolean;
140
- /** Outline effect (w:outline) */
141
- outline?: boolean;
142
- /** Shadow effect (w:shadow) */
143
- shadow?: boolean;
144
- /** Right-to-left text (w:rtl) */
145
- rtl?: boolean;
146
- /** Complex script formatting (w:cs) */
147
- cs?: boolean;
148
- /** Character style ID (w:rStyle) */
149
- styleId?: string;
150
- }
151
- /**
152
- * Tab stop alignment
153
- */
154
- type TabStopAlignment = 'left' | 'center' | 'right' | 'decimal' | 'bar' | 'clear' | 'num';
155
- /**
156
- * Tab leader character
157
- */
158
- type TabLeader = 'none' | 'dot' | 'hyphen' | 'underscore' | 'heavy' | 'middleDot';
159
- /**
160
- * Tab stop definition
161
- */
162
- interface TabStop {
163
- /** Position in twips from left margin */
164
- position: number;
165
- /** Alignment at tab stop */
166
- alignment: TabStopAlignment;
167
- /** Leader character */
168
- leader?: TabLeader;
169
- }
170
- /**
171
- * Line spacing rule
172
- */
173
- type LineSpacingRule = 'auto' | 'exact' | 'atLeast';
174
- /**
175
- * Paragraph alignment/justification
176
- */
177
- type ParagraphAlignment = 'left' | 'center' | 'right' | 'both' | 'distribute' | 'mediumKashida' | 'highKashida' | 'lowKashida' | 'thaiDistribute';
178
- /**
179
- * Complete paragraph formatting properties (w:pPr)
180
- */
181
- interface ParagraphFormatting {
182
- /** Paragraph alignment (w:jc) */
183
- alignment?: ParagraphAlignment;
184
- /** Text direction (w:bidi) */
185
- bidi?: boolean;
186
- /** Spacing before in twips (w:spacing/@w:before) */
187
- spaceBefore?: number;
188
- /** Spacing after in twips (w:spacing/@w:after) */
189
- spaceAfter?: number;
190
- /** Line spacing value (w:spacing/@w:line) */
191
- lineSpacing?: number;
192
- /** Line spacing rule (w:spacing/@w:lineRule) */
193
- lineSpacingRule?: LineSpacingRule;
194
- /** Auto space before (w:spacing/@w:beforeAutospacing) */
195
- beforeAutospacing?: boolean;
196
- /** Auto space after (w:spacing/@w:afterAutospacing) */
197
- afterAutospacing?: boolean;
198
- /** Left indent in twips (w:ind/@w:left) */
199
- indentLeft?: number;
200
- /** Right indent in twips (w:ind/@w:right) */
201
- indentRight?: number;
202
- /** First line indent in twips - positive for indent, negative for hanging (w:ind/@w:firstLine or @w:hanging) */
203
- indentFirstLine?: number;
204
- /** Whether first line is hanging indent */
205
- hangingIndent?: boolean;
206
- /** Paragraph borders (w:pBdr) */
207
- borders?: {
208
- top?: BorderSpec;
209
- bottom?: BorderSpec;
210
- left?: BorderSpec;
211
- right?: BorderSpec;
212
- between?: BorderSpec;
213
- bar?: BorderSpec;
214
- };
215
- /** Paragraph shading (w:shd) */
216
- shading?: ShadingProperties;
217
- /** Custom tab stops (w:tabs) */
218
- tabs?: TabStop[];
219
- /** Keep with next paragraph (w:keepNext) */
220
- keepNext?: boolean;
221
- /** Keep lines together (w:keepLines) */
222
- keepLines?: boolean;
223
- /** Widow/orphan control (w:widowControl) */
224
- widowControl?: boolean;
225
- /** Page break before (w:pageBreakBefore) */
226
- pageBreakBefore?: boolean;
227
- /** Contextual spacing — suppress space between paragraphs of the same style (w:contextualSpacing) */
228
- contextualSpacing?: boolean;
229
- /** Numbering properties (w:numPr) */
230
- numPr?: {
231
- /** Numbering definition ID (w:numId) */
232
- numId?: number;
233
- /** List level (0-8) (w:ilvl) */
234
- ilvl?: number;
235
- };
236
- /** Outline level 0-9 (w:outlineLvl) */
237
- outlineLevel?: number;
238
- /** Paragraph style ID (w:pStyle) */
239
- styleId?: string;
240
- /** Text frame properties (w:framePr) */
241
- frame?: {
242
- width?: number;
243
- height?: number;
244
- hAnchor?: 'text' | 'margin' | 'page';
245
- vAnchor?: 'text' | 'margin' | 'page';
246
- x?: number;
247
- y?: number;
248
- xAlign?: 'left' | 'center' | 'right' | 'inside' | 'outside';
249
- yAlign?: 'top' | 'center' | 'bottom' | 'inside' | 'outside' | 'inline';
250
- wrap?: 'around' | 'auto' | 'none' | 'notBeside' | 'through' | 'tight';
251
- };
252
- /** Suppress line numbers (w:suppressLineNumbers) */
253
- suppressLineNumbers?: boolean;
254
- /** Suppress auto hyphens (w:suppressAutoHyphens) */
255
- suppressAutoHyphens?: boolean;
256
- /** Run properties to apply to all runs (w:rPr) */
257
- runProperties?: TextFormatting;
258
- }
259
- /**
260
- * Table width type
261
- */
262
- type TableWidthType = 'auto' | 'dxa' | 'nil' | 'pct';
263
- /**
264
- * Table measurement (width or height)
265
- */
266
- interface TableMeasurement {
267
- /** Value in twips (for dxa) or fifths of a percent (for pct) */
268
- value: number;
269
- /** Measurement type */
270
- type: TableWidthType;
271
- }
272
- /**
273
- * Table borders
274
- */
275
- interface TableBorders {
276
- top?: BorderSpec;
277
- bottom?: BorderSpec;
278
- left?: BorderSpec;
279
- right?: BorderSpec;
280
- insideH?: BorderSpec;
281
- insideV?: BorderSpec;
282
- }
283
- /**
284
- * Cell margins
285
- */
286
- interface CellMargins {
287
- top?: TableMeasurement;
288
- bottom?: TableMeasurement;
289
- left?: TableMeasurement;
290
- right?: TableMeasurement;
291
- }
292
- /**
293
- * Table look flags (for table styles)
294
- */
295
- interface TableLook {
296
- firstColumn?: boolean;
297
- firstRow?: boolean;
298
- lastColumn?: boolean;
299
- lastRow?: boolean;
300
- noHBand?: boolean;
301
- noVBand?: boolean;
302
- }
303
- /**
304
- * Floating table properties
305
- */
306
- interface FloatingTableProperties {
307
- /** Horizontal anchor */
308
- horzAnchor?: 'margin' | 'page' | 'text';
309
- /** Vertical anchor */
310
- vertAnchor?: 'margin' | 'page' | 'text';
311
- /** Horizontal position */
312
- tblpX?: number;
313
- tblpXSpec?: 'left' | 'center' | 'right' | 'inside' | 'outside';
314
- /** Vertical position */
315
- tblpY?: number;
316
- tblpYSpec?: 'top' | 'center' | 'bottom' | 'inside' | 'outside' | 'inline';
317
- /** Distance from surrounding text */
318
- topFromText?: number;
319
- bottomFromText?: number;
320
- leftFromText?: number;
321
- rightFromText?: number;
322
- }
323
- /**
324
- * Table formatting properties (w:tblPr)
325
- */
326
- interface TableFormatting {
327
- /** Table width */
328
- width?: TableMeasurement;
329
- /** Table justification */
330
- justification?: 'left' | 'center' | 'right';
331
- /** Cell spacing */
332
- cellSpacing?: TableMeasurement;
333
- /** Table indent from left margin */
334
- indent?: TableMeasurement;
335
- /** Table borders */
336
- borders?: TableBorders;
337
- /** Default cell margins */
338
- cellMargins?: CellMargins;
339
- /** Table layout */
340
- layout?: 'fixed' | 'autofit';
341
- /** Table style ID */
342
- styleId?: string;
343
- /** Table look (conditional formatting flags) */
344
- look?: TableLook;
345
- /** Shading/background */
346
- shading?: ShadingProperties;
347
- /** Overlap for floating tables */
348
- overlap?: 'never' | 'overlap';
349
- /** Floating table properties */
350
- floating?: FloatingTableProperties;
351
- /** Right to left table */
352
- bidi?: boolean;
353
- }
354
- /**
355
- * Table row formatting properties (w:trPr)
5
+ * Error classes for @eigenpal/docx-editor-agents
356
6
  */
357
- interface TableRowFormatting {
358
- /** Row height */
359
- height?: TableMeasurement;
360
- /** Height rule */
361
- heightRule?: 'auto' | 'atLeast' | 'exact';
362
- /** Header row (repeats on each page) */
363
- header?: boolean;
364
- /** Allow row to break across pages */
365
- cantSplit?: boolean;
366
- /** Row justification */
367
- justification?: 'left' | 'center' | 'right';
368
- /** Hidden row */
369
- hidden?: boolean;
370
- /** Conditional format style */
371
- conditionalFormat?: ConditionalFormatStyle;
7
+ declare class TextNotFoundError extends Error {
8
+ constructor(search: string, paragraphIndex?: number);
372
9
  }
373
- /**
374
- * Conditional format style
375
- */
376
- interface ConditionalFormatStyle {
377
- /** First row */
378
- firstRow?: boolean;
379
- /** Last row */
380
- lastRow?: boolean;
381
- /** First column */
382
- firstColumn?: boolean;
383
- /** Last column */
384
- lastColumn?: boolean;
385
- /** Odd horizontal band */
386
- oddHBand?: boolean;
387
- /** Even horizontal band */
388
- evenHBand?: boolean;
389
- /** Odd vertical band */
390
- oddVBand?: boolean;
391
- /** Even vertical band */
392
- evenVBand?: boolean;
393
- /** Northwest corner */
394
- nwCell?: boolean;
395
- /** Northeast corner */
396
- neCell?: boolean;
397
- /** Southwest corner */
398
- swCell?: boolean;
399
- /** Southeast corner */
400
- seCell?: boolean;
10
+ declare class ChangeNotFoundError extends Error {
11
+ constructor(id: number);
401
12
  }
402
- /**
403
- * Table cell formatting properties (w:tcPr)
404
- */
405
- interface TableCellFormatting {
406
- /** Cell width */
407
- width?: TableMeasurement;
408
- /** Cell borders */
409
- borders?: TableBorders;
410
- /** Cell margins (override table default) */
411
- margins?: CellMargins;
412
- /** Cell shading/background */
413
- shading?: ShadingProperties;
414
- /** Vertical alignment */
415
- verticalAlign?: 'top' | 'center' | 'bottom';
416
- /** Text direction */
417
- textDirection?: 'lr' | 'lrV' | 'rl' | 'rlV' | 'tb' | 'tbV' | 'tbRl' | 'tbRlV' | 'btLr';
418
- /** Grid span (horizontal merge) */
419
- gridSpan?: number;
420
- /** Vertical merge */
421
- vMerge?: 'restart' | 'continue';
422
- /** Fit text to cell width */
423
- fitText?: boolean;
424
- /** Wrap text */
425
- noWrap?: boolean;
426
- /** Hide cell marker */
427
- hideMark?: boolean;
428
- /** Conditional format style */
429
- conditionalFormat?: ConditionalFormatStyle;
13
+ declare class CommentNotFoundError extends Error {
14
+ constructor(id: number);
430
15
  }
431
16
 
432
17
  /**
433
- * Lists & Numbering Types
18
+ * Formal Word JS API parity contract.
434
19
  *
435
- * Types for bullet lists, numbered lists, and numbering definitions.
436
- */
437
-
438
- /**
439
- * Number format type
440
- */
441
- type NumberFormat = 'decimal' | 'upperRoman' | 'lowerRoman' | 'upperLetter' | 'lowerLetter' | 'ordinal' | 'cardinalText' | 'ordinalText' | 'hex' | 'chicago' | 'ideographDigital' | 'japaneseCounting' | 'aiueo' | 'iroha' | 'decimalFullWidth' | 'decimalHalfWidth' | 'japaneseLegal' | 'japaneseDigitalTenThousand' | 'decimalEnclosedCircle' | 'decimalFullWidth2' | 'aiueoFullWidth' | 'irohaFullWidth' | 'decimalZero' | 'bullet' | 'ganada' | 'chosung' | 'decimalEnclosedFullstop' | 'decimalEnclosedParen' | 'decimalEnclosedCircleChinese' | 'ideographEnclosedCircle' | 'ideographTraditional' | 'ideographZodiac' | 'ideographZodiacTraditional' | 'taiwaneseCounting' | 'ideographLegalTraditional' | 'taiwaneseCountingThousand' | 'taiwaneseDigital' | 'chineseCounting' | 'chineseLegalSimplified' | 'chineseCountingThousand' | 'koreanDigital' | 'koreanCounting' | 'koreanLegal' | 'koreanDigital2' | 'vietnameseCounting' | 'russianLower' | 'russianUpper' | 'none' | 'numberInDash' | 'hebrew1' | 'hebrew2' | 'arabicAlpha' | 'arabicAbjad' | 'hindiVowels' | 'hindiConsonants' | 'hindiNumbers' | 'hindiCounting' | 'thaiLetters' | 'thaiNumbers' | 'thaiCounting';
442
- /**
443
- * Multi-level suffix (what follows the number)
444
- */
445
- type LevelSuffix = 'tab' | 'space' | 'nothing';
446
- /**
447
- * List level definition
448
- */
449
- interface ListLevel {
450
- /** Level index (0-8) */
451
- ilvl: number;
452
- /** Starting number */
453
- start?: number;
454
- /** Number format */
455
- numFmt: NumberFormat;
456
- /** Level text (e.g., "%1." or "•") */
457
- lvlText: string;
458
- /** Justification */
459
- lvlJc?: 'left' | 'center' | 'right';
460
- /** Suffix after number */
461
- suffix?: LevelSuffix;
462
- /** Paragraph properties for this level */
463
- pPr?: ParagraphFormatting;
464
- /** Run properties for the number/bullet */
465
- rPr?: TextFormatting;
466
- /** Restart numbering from higher level */
467
- lvlRestart?: number;
468
- /** Is legal numbering style */
469
- isLgl?: boolean;
470
- /** Legacy settings */
471
- legacy?: {
472
- legacy?: boolean;
473
- legacySpace?: number;
474
- legacyIndent?: number;
475
- };
476
- }
477
- /**
478
- * Abstract numbering definition (w:abstractNum)
479
- */
480
- interface AbstractNumbering {
481
- /** Abstract numbering ID */
482
- abstractNumId: number;
483
- /** Multi-level type */
484
- multiLevelType?: 'hybridMultilevel' | 'multilevel' | 'singleLevel';
485
- /** Numbering style link */
486
- numStyleLink?: string;
487
- /** Style link */
488
- styleLink?: string;
489
- /** Level definitions */
490
- levels: ListLevel[];
491
- /** Name */
492
- name?: string;
493
- }
494
- /**
495
- * Numbering instance (w:num)
496
- */
497
- interface NumberingInstance {
498
- /** Numbering ID (referenced by paragraphs) */
499
- numId: number;
500
- /** Reference to abstract numbering */
501
- abstractNumId: number;
502
- /** Level overrides */
503
- levelOverrides?: Array<{
504
- ilvl: number;
505
- startOverride?: number;
506
- lvl?: ListLevel;
507
- }>;
508
- }
509
- /**
510
- * Computed list rendering info
511
- */
512
- interface ListRendering {
513
- /** Computed marker text (e.g., "1.", "a)", "•") */
514
- marker: string;
515
- /** List level (0-8) */
516
- level: number;
517
- /** Numbering ID */
518
- numId: number;
519
- /** Whether this is a bullet or numbered list */
520
- isBullet: boolean;
521
- /** Number format type (decimal, lowerRoman, upperRoman, etc.) */
522
- numFmt?: NumberFormat;
523
- /** Whether the list marker is hidden (w:vanish on level rPr) */
524
- markerHidden?: boolean;
525
- /** Marker font family from numbering level rPr (ascii name) */
526
- markerFontFamily?: string;
527
- /** Marker font size from numbering level rPr, in points */
528
- markerFontSize?: number;
529
- /**
530
- * NumberFormat for each level from 0..ilvl (inclusive).
531
- * Used to resolve multi-level templates like "%1.%2." where each %N
532
- * may need a different format (e.g., upperRoman parent + decimal child).
533
- */
534
- levelNumFmts?: NumberFormat[];
535
- }
536
- /**
537
- * Complete numbering definitions
538
- */
539
- interface NumberingDefinitions {
540
- /** Abstract numbering definitions */
541
- abstractNums: AbstractNumbering[];
542
- /** Numbering instances */
543
- nums: NumberingInstance[];
544
- }
545
-
546
- /**
547
- * Document Content Model
20
+ * This file declares what subset of Microsoft Word's Office.js JavaScript API
21
+ * (https://learn.microsoft.com/en-us/javascript/api/word) we mirror, **at the
22
+ * type level**. It is checked at compile time: `EditorBridge` must satisfy
23
+ * `WordCompatBridge` (verified via the static assertion at the bottom).
548
24
  *
549
- * All content-bearing types: runs, hyperlinks, bookmarks, fields,
550
- * images, shapes, tables, lists, paragraphs, headers/footers,
551
- * footnotes/endnotes, and sections.
25
+ * The assertion is the source of truth. If you change the bridge surface and
26
+ * forget to update parity, typecheck breaks.
552
27
  *
553
- * These types form a deeply interrelated tree (Paragraph ↔ Table ↔ ShapeTextBody)
554
- * and are kept together to avoid circular import issues.
555
- */
556
-
557
- /**
558
- * Plain text content
559
- */
560
- interface TextContent {
561
- type: 'text';
562
- /** The text string */
563
- text: string;
564
- /** Preserve whitespace (xml:space="preserve") */
565
- preserveSpace?: boolean;
566
- }
567
- /**
568
- * Tab character
569
- */
570
- interface TabContent {
571
- type: 'tab';
572
- }
573
- /**
574
- * Line break
575
- */
576
- interface BreakContent {
577
- type: 'break';
578
- /** Break type */
579
- breakType?: 'page' | 'column' | 'textWrapping';
580
- /** Clear type for text wrapping break */
581
- clear?: 'none' | 'left' | 'right' | 'all';
582
- }
583
- /**
584
- * Symbol character (special font character)
585
- */
586
- interface SymbolContent {
587
- type: 'symbol';
588
- /** Font name */
589
- font: string;
590
- /** Character code */
591
- char: string;
592
- }
593
- /**
594
- * Footnote or endnote reference
595
- */
596
- interface NoteReferenceContent {
597
- type: 'footnoteRef' | 'endnoteRef';
598
- /** Note ID */
599
- id: number;
600
- }
601
- /**
602
- * Field character (begin/separate/end)
603
- */
604
- interface FieldCharContent {
605
- type: 'fieldChar';
606
- /** Field character type */
607
- charType: 'begin' | 'separate' | 'end';
608
- /** Field is locked */
609
- fldLock?: boolean;
610
- /** Field is dirty (needs update) */
611
- dirty?: boolean;
612
- }
613
- /**
614
- * Field instruction text
615
- */
616
- interface InstrTextContent {
617
- type: 'instrText';
618
- /** Field instruction */
619
- text: string;
620
- }
621
- /**
622
- * Soft hyphen
623
- */
624
- interface SoftHyphenContent {
625
- type: 'softHyphen';
626
- }
627
- /**
628
- * Non-breaking hyphen
629
- */
630
- interface NoBreakHyphenContent {
631
- type: 'noBreakHyphen';
632
- }
633
- /**
634
- * Drawing/image reference
635
- */
636
- interface DrawingContent {
637
- type: 'drawing';
638
- /** Image data */
639
- image: Image;
640
- }
641
- /**
642
- * Shape reference
643
- */
644
- interface ShapeContent {
645
- type: 'shape';
646
- /** Shape data */
647
- shape: Shape;
648
- }
649
- /**
650
- * All possible run content types
651
- */
652
- type RunContent = TextContent | TabContent | BreakContent | SymbolContent | NoteReferenceContent | FieldCharContent | InstrTextContent | SoftHyphenContent | NoBreakHyphenContent | DrawingContent | ShapeContent;
653
- /**
654
- * A run is a contiguous region of text with the same formatting
655
- */
656
- interface Run {
657
- type: 'run';
658
- /** Text formatting properties */
659
- formatting?: TextFormatting;
660
- /** Run-level tracked property changes (w:rPrChange) */
661
- propertyChanges?: RunPropertyChange[];
662
- /** Run content (text, tabs, breaks, etc.) */
663
- content: RunContent[];
664
- }
665
- /**
666
- * Hyperlink (w:hyperlink)
667
- */
668
- interface Hyperlink {
669
- type: 'hyperlink';
670
- /** Relationship ID for external link */
671
- rId?: string;
672
- /** Resolved URL (from relationships) */
673
- href?: string;
674
- /** Internal bookmark anchor */
675
- anchor?: string;
676
- /** Tooltip text */
677
- tooltip?: string;
678
- /** Target frame */
679
- target?: string;
680
- /** Link history tracking */
681
- history?: boolean;
682
- /** Document location */
683
- docLocation?: string;
684
- /** Child runs */
685
- children: (Run | BookmarkStart | BookmarkEnd)[];
686
- }
687
- /**
688
- * Bookmark start marker (w:bookmarkStart)
689
- */
690
- interface BookmarkStart {
691
- type: 'bookmarkStart';
692
- /** Bookmark ID */
693
- id: number;
694
- /** Bookmark name */
695
- name: string;
696
- /** Column index for table bookmarks */
697
- colFirst?: number;
698
- colLast?: number;
699
- }
700
- /**
701
- * Bookmark end marker (w:bookmarkEnd)
702
- */
703
- interface BookmarkEnd {
704
- type: 'bookmarkEnd';
705
- /** Bookmark ID */
706
- id: number;
707
- }
708
- /**
709
- * Known field types
710
- */
711
- type FieldType = 'PAGE' | 'NUMPAGES' | 'NUMWORDS' | 'NUMCHARS' | 'DATE' | 'TIME' | 'CREATEDATE' | 'SAVEDATE' | 'PRINTDATE' | 'AUTHOR' | 'TITLE' | 'SUBJECT' | 'KEYWORDS' | 'COMMENTS' | 'FILENAME' | 'FILESIZE' | 'TEMPLATE' | 'DOCPROPERTY' | 'DOCVARIABLE' | 'REF' | 'PAGEREF' | 'NOTEREF' | 'HYPERLINK' | 'TOC' | 'TOA' | 'INDEX' | 'SEQ' | 'STYLEREF' | 'AUTONUM' | 'AUTONUMLGL' | 'AUTONUMOUT' | 'IF' | 'MERGEFIELD' | 'NEXT' | 'NEXTIF' | 'ASK' | 'SET' | 'QUOTE' | 'INCLUDETEXT' | 'INCLUDEPICTURE' | 'SYMBOL' | 'ADVANCE' | 'EDITTIME' | 'REVNUM' | 'SECTION' | 'SECTIONPAGES' | 'USERADDRESS' | 'USERNAME' | 'USERINITIALS' | 'UNKNOWN';
712
- /**
713
- * Simple field (w:fldSimple)
714
- */
715
- interface SimpleField {
716
- type: 'simpleField';
717
- /** Field instruction (e.g., "PAGE \\* MERGEFORMAT") */
718
- instruction: string;
719
- /** Parsed field type */
720
- fieldType: FieldType;
721
- /** Current display value */
722
- content: (Run | Hyperlink)[];
723
- /** Field is locked */
724
- fldLock?: boolean;
725
- /** Field is dirty */
726
- dirty?: boolean;
727
- }
728
- /**
729
- * Complex field (w:fldChar begin/separate/end with w:instrText)
730
- */
731
- interface ComplexField {
732
- type: 'complexField';
733
- /** Field instruction */
734
- instruction: string;
735
- /** Parsed field type */
736
- fieldType: FieldType;
737
- /** Field code runs */
738
- fieldCode: Run[];
739
- /** Display result runs */
740
- fieldResult: Run[];
741
- /** Field is locked */
742
- fldLock?: boolean;
743
- /** Field is dirty */
744
- dirty?: boolean;
745
- }
746
- /**
747
- * Image size specification
748
- */
749
- interface ImageSize {
750
- /** Width in EMUs (English Metric Units) */
751
- width: number;
752
- /** Height in EMUs */
753
- height: number;
754
- }
755
- /**
756
- * Image wrap type for floating images
757
- */
758
- interface ImageWrap {
759
- type: 'inline' | 'square' | 'tight' | 'through' | 'topAndBottom' | 'behind' | 'inFront';
760
- /** Wrap text direction */
761
- wrapText?: 'bothSides' | 'left' | 'right' | 'largest';
762
- /** Distance from text */
763
- distT?: number;
764
- distB?: number;
765
- distL?: number;
766
- distR?: number;
767
- }
768
- /**
769
- * Position for floating images
770
- */
771
- interface ImagePosition {
772
- /** Horizontal positioning */
773
- horizontal: {
774
- relativeTo: 'character' | 'column' | 'insideMargin' | 'leftMargin' | 'margin' | 'outsideMargin' | 'page' | 'rightMargin';
775
- alignment?: 'left' | 'right' | 'center' | 'inside' | 'outside';
776
- posOffset?: number;
777
- };
778
- /** Vertical positioning */
779
- vertical: {
780
- relativeTo: 'insideMargin' | 'line' | 'margin' | 'outsideMargin' | 'page' | 'paragraph' | 'topMargin' | 'bottomMargin';
781
- alignment?: 'top' | 'bottom' | 'center' | 'inside' | 'outside';
782
- posOffset?: number;
783
- };
784
- }
785
- /**
786
- * Image transformation
787
- */
788
- interface ImageTransform {
789
- /** Rotation in degrees */
790
- rotation?: number;
791
- /** Flip horizontal */
792
- flipH?: boolean;
793
- /** Flip vertical */
794
- flipV?: boolean;
795
- }
796
- /**
797
- * Image padding/margins
798
- */
799
- interface ImagePadding {
800
- top?: number;
801
- bottom?: number;
802
- left?: number;
803
- right?: number;
804
- }
805
- /**
806
- * Embedded image (w:drawing)
807
- */
808
- interface Image {
809
- type: 'image';
810
- /** Unique ID */
811
- id?: string;
812
- /** Relationship ID for the image data */
813
- rId: string;
814
- /** Resolved image data (base64 or blob URL) */
815
- src?: string;
816
- /** Image MIME type */
817
- mimeType?: string;
818
- /** Original filename */
819
- filename?: string;
820
- /** Alt text for accessibility */
821
- alt?: string;
822
- /** Title/description */
823
- title?: string;
824
- /** Image size */
825
- size: ImageSize;
826
- /** Original size before any transforms */
827
- originalSize?: ImageSize;
828
- /** Wrap settings */
829
- wrap: ImageWrap;
830
- /** Position for floating images */
831
- position?: ImagePosition;
832
- /** Image transformations */
833
- transform?: ImageTransform;
834
- /** Padding around image */
835
- padding?: ImagePadding;
836
- /** Whether this is a decorative image */
837
- decorative?: boolean;
838
- /** Hyperlink URL for clickable image */
839
- hlinkHref?: string;
840
- /** Image outline/border */
841
- outline?: ShapeOutline;
842
- /** Image effects */
843
- effects?: {
844
- brightness?: number;
845
- contrast?: number;
846
- saturation?: number;
847
- };
848
- }
849
- /**
850
- * Shape types
851
- */
852
- type ShapeType = 'rect' | 'roundRect' | 'ellipse' | 'triangle' | 'rtTriangle' | 'parallelogram' | 'trapezoid' | 'pentagon' | 'hexagon' | 'heptagon' | 'octagon' | 'decagon' | 'dodecagon' | 'star4' | 'star5' | 'star6' | 'star7' | 'star8' | 'star10' | 'star12' | 'star16' | 'star24' | 'star32' | 'line' | 'straightConnector1' | 'bentConnector2' | 'bentConnector3' | 'bentConnector4' | 'bentConnector5' | 'curvedConnector2' | 'curvedConnector3' | 'curvedConnector4' | 'curvedConnector5' | 'rightArrow' | 'leftArrow' | 'upArrow' | 'downArrow' | 'leftRightArrow' | 'upDownArrow' | 'quadArrow' | 'leftRightUpArrow' | 'bentArrow' | 'uturnArrow' | 'leftUpArrow' | 'bentUpArrow' | 'curvedRightArrow' | 'curvedLeftArrow' | 'curvedUpArrow' | 'curvedDownArrow' | 'stripedRightArrow' | 'notchedRightArrow' | 'homePlate' | 'chevron' | 'rightArrowCallout' | 'downArrowCallout' | 'leftArrowCallout' | 'upArrowCallout' | 'leftRightArrowCallout' | 'quadArrowCallout' | 'circularArrow' | 'flowChartProcess' | 'flowChartAlternateProcess' | 'flowChartDecision' | 'flowChartInputOutput' | 'flowChartPredefinedProcess' | 'flowChartInternalStorage' | 'flowChartDocument' | 'flowChartMultidocument' | 'flowChartTerminator' | 'flowChartPreparation' | 'flowChartManualInput' | 'flowChartManualOperation' | 'flowChartConnector' | 'flowChartOffpageConnector' | 'flowChartPunchedCard' | 'flowChartPunchedTape' | 'flowChartSummingJunction' | 'flowChartOr' | 'flowChartCollate' | 'flowChartSort' | 'flowChartExtract' | 'flowChartMerge' | 'flowChartOnlineStorage' | 'flowChartDelay' | 'flowChartMagneticTape' | 'flowChartMagneticDisk' | 'flowChartMagneticDrum' | 'flowChartDisplay' | 'wedgeRectCallout' | 'wedgeRoundRectCallout' | 'wedgeEllipseCallout' | 'cloudCallout' | 'borderCallout1' | 'borderCallout2' | 'borderCallout3' | 'accentCallout1' | 'accentCallout2' | 'accentCallout3' | 'callout1' | 'callout2' | 'callout3' | 'accentBorderCallout1' | 'accentBorderCallout2' | 'accentBorderCallout3' | 'actionButtonBlank' | 'actionButtonHome' | 'actionButtonHelp' | 'actionButtonInformation' | 'actionButtonBackPrevious' | 'actionButtonForwardNext' | 'actionButtonBeginning' | 'actionButtonEnd' | 'actionButtonReturn' | 'actionButtonDocument' | 'actionButtonSound' | 'actionButtonMovie' | 'irregularSeal1' | 'irregularSeal2' | 'frame' | 'halfFrame' | 'corner' | 'diagStripe' | 'chord' | 'arc' | 'bracketPair' | 'bracePair' | 'leftBracket' | 'rightBracket' | 'leftBrace' | 'rightBrace' | 'can' | 'cube' | 'bevel' | 'donut' | 'noSmoking' | 'blockArc' | 'foldedCorner' | 'smileyFace' | 'heart' | 'lightningBolt' | 'sun' | 'moon' | 'cloud' | 'snip1Rect' | 'snip2SameRect' | 'snip2DiagRect' | 'snipRoundRect' | 'round1Rect' | 'round2SameRect' | 'round2DiagRect' | 'plaque' | 'teardrop' | 'mathPlus' | 'mathMinus' | 'mathMultiply' | 'mathDivide' | 'mathEqual' | 'mathNotEqual' | 'gear6' | 'gear9' | 'funnel' | 'pieWedge' | 'pie' | 'leftCircularArrow' | 'leftRightCircularArrow' | 'swooshArrow' | 'textBox';
853
- /**
854
- * Shape fill type
855
- */
856
- interface ShapeFill {
857
- type: 'none' | 'solid' | 'gradient' | 'pattern' | 'picture';
858
- /** Solid fill color */
859
- color?: ColorValue;
860
- /** Gradient stops for gradient fill */
861
- gradient?: {
862
- type: 'linear' | 'radial' | 'rectangular' | 'path';
863
- angle?: number;
864
- stops: Array<{
865
- position: number;
866
- color: ColorValue;
867
- }>;
868
- };
869
- }
870
- /**
871
- * Shape outline/stroke
872
- */
873
- interface ShapeOutline {
874
- /** Line width in EMUs */
875
- width?: number;
876
- /** Line color */
877
- color?: ColorValue;
878
- /** Line style */
879
- style?: 'solid' | 'dot' | 'dash' | 'lgDash' | 'dashDot' | 'lgDashDot' | 'lgDashDotDot' | 'sysDot' | 'sysDash' | 'sysDashDot' | 'sysDashDotDot';
880
- /** Line cap */
881
- cap?: 'flat' | 'round' | 'square';
882
- /** Line join */
883
- join?: 'bevel' | 'miter' | 'round';
884
- /** Head arrow */
885
- headEnd?: {
886
- type: 'none' | 'triangle' | 'stealth' | 'diamond' | 'oval' | 'arrow';
887
- width?: 'sm' | 'med' | 'lg';
888
- length?: 'sm' | 'med' | 'lg';
889
- };
890
- /** Tail arrow */
891
- tailEnd?: {
892
- type: 'none' | 'triangle' | 'stealth' | 'diamond' | 'oval' | 'arrow';
893
- width?: 'sm' | 'med' | 'lg';
894
- length?: 'sm' | 'med' | 'lg';
895
- };
896
- }
897
- /**
898
- * Text body inside a shape
899
- */
900
- interface ShapeTextBody {
901
- /** Text direction */
902
- vertical?: boolean;
903
- /** Rotation */
904
- rotation?: number;
905
- /** Anchor/vertical alignment */
906
- anchor?: 'top' | 'middle' | 'bottom' | 'distributed' | 'justified';
907
- /** Anchor center */
908
- anchorCenter?: boolean;
909
- /** Auto fit */
910
- autoFit?: 'none' | 'normal' | 'shape';
911
- /** Text margins */
912
- margins?: {
913
- top?: number;
914
- bottom?: number;
915
- left?: number;
916
- right?: number;
917
- };
918
- /** Paragraphs inside the shape */
919
- content: Paragraph[];
920
- }
921
- /**
922
- * Shape/drawing object (wps:wsp)
923
- */
924
- interface Shape {
925
- type: 'shape';
926
- /** Shape type preset */
927
- shapeType: ShapeType;
928
- /** Unique ID */
929
- id?: string;
930
- /** Name */
931
- name?: string;
932
- /** Size in EMUs */
933
- size: ImageSize;
934
- /** Position for floating shapes */
935
- position?: ImagePosition;
936
- /** Wrap settings */
937
- wrap?: ImageWrap;
938
- /** Fill */
939
- fill?: ShapeFill;
940
- /** Outline/stroke */
941
- outline?: ShapeOutline;
942
- /** Transform */
943
- transform?: ImageTransform;
944
- /** Text content inside the shape */
945
- textBody?: ShapeTextBody;
946
- /** Custom geometry points */
947
- customGeometry?: string;
948
- }
949
- /**
950
- * Table cell
951
- */
952
- interface TableCell {
953
- type: 'tableCell';
954
- /** Cell formatting */
955
- formatting?: TableCellFormatting;
956
- /** Cell-level tracked property changes (w:tcPrChange) */
957
- propertyChanges?: TableCellPropertyChange[];
958
- /** Tracked structural changes (cell insert/delete/merge) */
959
- structuralChange?: TableStructuralChangeInfo;
960
- /** Cell content (paragraphs, tables, etc.) */
961
- content: (Paragraph | Table)[];
962
- }
963
- /**
964
- * Table row
965
- */
966
- interface TableRow {
967
- type: 'tableRow';
968
- /** Row formatting */
969
- formatting?: TableRowFormatting;
970
- /** Row-level tracked property changes (w:trPrChange) */
971
- propertyChanges?: TableRowPropertyChange[];
972
- /** Tracked structural changes (row insert/delete) */
973
- structuralChange?: TableStructuralChangeInfo;
974
- /** Cells in this row */
975
- cells: TableCell[];
976
- }
977
- /**
978
- * Table (w:tbl)
979
- */
980
- interface Table {
981
- type: 'table';
982
- /** Table formatting */
983
- formatting?: TableFormatting;
984
- /** Table-level tracked property changes (w:tblPrChange) */
985
- propertyChanges?: TablePropertyChange[];
986
- /** Column widths in twips */
987
- columnWidths?: number[];
988
- /** Table rows */
989
- rows: TableRow[];
990
- }
991
- /**
992
- * A comment (w:comment) from comments.xml
993
- */
994
- interface Comment {
995
- /** Comment ID (matches commentRangeStart/End) */
996
- id: number;
997
- /** Author name */
998
- author: string;
999
- /** Author initials */
1000
- initials?: string;
1001
- /** Date */
1002
- date?: string;
1003
- /** Comment content (paragraphs) */
1004
- content: Paragraph[];
1005
- /** Parent comment ID (for replies) */
1006
- parentId?: number;
1007
- /** Whether the comment is resolved/done */
1008
- done?: boolean;
1009
- }
1010
- /**
1011
- * Comment range start marker in paragraph content
1012
- */
1013
- interface CommentRangeStart {
1014
- type: 'commentRangeStart';
1015
- id: number;
1016
- }
1017
- /**
1018
- * Comment range end marker in paragraph content
1019
- */
1020
- interface CommentRangeEnd {
1021
- type: 'commentRangeEnd';
1022
- id: number;
1023
- }
1024
- /**
1025
- * Math equation content (m:oMath or m:oMathPara)
1026
- */
1027
- interface MathEquation {
1028
- type: 'mathEquation';
1029
- /** Whether this is a block (oMathPara) or inline (oMath) equation */
1030
- display: 'inline' | 'block';
1031
- /** Raw OMML XML for round-trip preservation */
1032
- ommlXml: string;
1033
- /** Plain text representation for accessibility/fallback */
1034
- plainText?: string;
1035
- }
1036
- /**
1037
- * Tracked change metadata (w:ins, w:del attributes)
1038
- */
1039
- interface TrackedChangeInfo {
1040
- /** Revision ID */
1041
- id: number;
1042
- /** Author who made the change */
1043
- author: string;
1044
- /** Date of the change */
1045
- date?: string;
1046
- }
1047
- /**
1048
- * Generic tracked property-change wrapper metadata (w:*PrChange)
1049
- */
1050
- interface PropertyChangeInfo extends TrackedChangeInfo {
1051
- /** Optional revision session ID */
1052
- rsid?: string;
1053
- }
1054
- /**
1055
- * Insertion wrapper (w:ins) — runs inserted by tracked changes
1056
- */
1057
- interface Insertion {
1058
- type: 'insertion';
1059
- /** Tracked change metadata */
1060
- info: TrackedChangeInfo;
1061
- /** Inserted content */
1062
- content: (Run | Hyperlink)[];
1063
- }
1064
- /**
1065
- * Deletion wrapper (w:del) — runs deleted by tracked changes
1066
- */
1067
- interface Deletion {
1068
- type: 'deletion';
1069
- /** Tracked change metadata */
1070
- info: TrackedChangeInfo;
1071
- /** Deleted content */
1072
- content: (Run | Hyperlink)[];
1073
- }
1074
- /**
1075
- * Move-from wrapper (w:moveFrom) — content moved away from this position
1076
- */
1077
- interface MoveFrom {
1078
- type: 'moveFrom';
1079
- /** Tracked change metadata */
1080
- info: TrackedChangeInfo;
1081
- /** Moved content */
1082
- content: (Run | Hyperlink)[];
1083
- }
1084
- /**
1085
- * Move-to wrapper (w:moveTo) — content moved into this position
1086
- */
1087
- interface MoveTo {
1088
- type: 'moveTo';
1089
- /** Tracked change metadata */
1090
- info: TrackedChangeInfo;
1091
- /** Moved content */
1092
- content: (Run | Hyperlink)[];
1093
- }
1094
- /**
1095
- * Move-from range start marker (w:moveFromRangeStart) — ECMA-376 §17.13.5.22
1096
- * Pairs with moveFromRangeEnd to delimit the source of a move in the document.
1097
- */
1098
- interface MoveFromRangeStart {
1099
- type: 'moveFromRangeStart';
1100
- id: number;
1101
- name: string;
1102
- }
1103
- /**
1104
- * Move-from range end marker (w:moveFromRangeEnd)
1105
- */
1106
- interface MoveFromRangeEnd {
1107
- type: 'moveFromRangeEnd';
1108
- id: number;
1109
- }
1110
- /**
1111
- * Move-to range start marker (w:moveToRangeStart) — ECMA-376 §17.13.5.24
1112
- * Pairs with moveToRangeEnd to delimit the destination of a move.
1113
- */
1114
- interface MoveToRangeStart {
1115
- type: 'moveToRangeStart';
1116
- id: number;
1117
- name: string;
1118
- }
1119
- /**
1120
- * Move-to range end marker (w:moveToRangeEnd)
1121
- */
1122
- interface MoveToRangeEnd {
1123
- type: 'moveToRangeEnd';
1124
- id: number;
1125
- }
1126
- /**
1127
- * Run property change (w:rPrChange)
1128
- */
1129
- interface RunPropertyChange {
1130
- type: 'runPropertyChange';
1131
- /** Tracked change metadata */
1132
- info: PropertyChangeInfo;
1133
- /** Run properties before the tracked change */
1134
- previousFormatting?: TextFormatting;
1135
- /** Run properties after the tracked change (editor model convenience) */
1136
- currentFormatting?: TextFormatting;
1137
- }
1138
- /**
1139
- * Paragraph property change (w:pPrChange)
1140
- */
1141
- interface ParagraphPropertyChange {
1142
- type: 'paragraphPropertyChange';
1143
- /** Tracked change metadata */
1144
- info: PropertyChangeInfo;
1145
- /** Paragraph properties before the tracked change */
1146
- previousFormatting?: ParagraphFormatting;
1147
- /** Paragraph properties after the tracked change (editor model convenience) */
1148
- currentFormatting?: ParagraphFormatting;
1149
- }
1150
- /**
1151
- * Table property change (w:tblPrChange)
1152
- */
1153
- interface TablePropertyChange {
1154
- type: 'tablePropertyChange';
1155
- /** Tracked change metadata */
1156
- info: PropertyChangeInfo;
1157
- /** Table properties before the tracked change */
1158
- previousFormatting?: TableFormatting;
1159
- /** Table properties after the tracked change (editor model convenience) */
1160
- currentFormatting?: TableFormatting;
1161
- }
1162
- /**
1163
- * Table row property change (w:trPrChange)
1164
- */
1165
- interface TableRowPropertyChange {
1166
- type: 'tableRowPropertyChange';
1167
- /** Tracked change metadata */
1168
- info: PropertyChangeInfo;
1169
- /** Row properties before the tracked change */
1170
- previousFormatting?: TableRowFormatting;
1171
- /** Row properties after the tracked change (editor model convenience) */
1172
- currentFormatting?: TableRowFormatting;
1173
- }
1174
- /**
1175
- * Table cell property change (w:tcPrChange)
1176
- */
1177
- interface TableCellPropertyChange {
1178
- type: 'tableCellPropertyChange';
1179
- /** Tracked change metadata */
1180
- info: PropertyChangeInfo;
1181
- /** Cell properties before the tracked change */
1182
- previousFormatting?: TableCellFormatting;
1183
- /** Cell properties after the tracked change (editor model convenience) */
1184
- currentFormatting?: TableCellFormatting;
1185
- }
1186
- /**
1187
- * Table structural tracked change metadata (row/cell insert/delete/merge)
1188
- */
1189
- interface TableStructuralChangeInfo {
1190
- type: 'tableRowInsertion' | 'tableRowDeletion' | 'tableCellInsertion' | 'tableCellDeletion' | 'tableCellMerge';
1191
- /** Tracked change metadata */
1192
- info: TrackedChangeInfo;
1193
- }
1194
- /**
1195
- * SDT type (content control type)
1196
- */
1197
- type SdtType = 'richText' | 'plainText' | 'date' | 'dropdown' | 'comboBox' | 'checkbox' | 'picture' | 'buildingBlockGallery' | 'group' | 'unknown';
1198
- /**
1199
- * SDT properties (w:sdtPr)
1200
- */
1201
- interface SdtProperties {
1202
- /** SDT type */
1203
- sdtType: SdtType;
1204
- /** Alias (friendly name) */
1205
- alias?: string;
1206
- /** Tag (developer identifier) */
1207
- tag?: string;
1208
- /** Lock content editing */
1209
- lock?: 'sdtLocked' | 'contentLocked' | 'sdtContentLocked' | 'unlocked';
1210
- /** Placeholder text */
1211
- placeholder?: string;
1212
- /** Whether showing placeholder */
1213
- showingPlaceholder?: boolean;
1214
- /** Date format for date controls */
1215
- dateFormat?: string;
1216
- /** Dropdown/combobox list items */
1217
- listItems?: {
1218
- displayText: string;
1219
- value: string;
1220
- }[];
1221
- /** Checkbox checked state */
1222
- checked?: boolean;
1223
- }
1224
- /**
1225
- * Inline SDT (content control within a paragraph)
1226
- */
1227
- interface InlineSdt {
1228
- type: 'inlineSdt';
1229
- /** SDT properties */
1230
- properties: SdtProperties;
1231
- /** Content runs inside the control */
1232
- content: (Run | Hyperlink)[];
1233
- }
1234
- /**
1235
- * Block-level SDT (content control wrapping paragraphs/tables)
1236
- */
1237
- interface BlockSdt {
1238
- type: 'blockSdt';
1239
- /** SDT properties */
1240
- properties: SdtProperties;
1241
- /** Block content inside the control */
1242
- content: (Paragraph | Table)[];
1243
- }
1244
- /**
1245
- * Paragraph content types
1246
- */
1247
- type ParagraphContent = Run | Hyperlink | BookmarkStart | BookmarkEnd | SimpleField | ComplexField | InlineSdt | CommentRangeStart | CommentRangeEnd | Insertion | Deletion | MoveFrom | MoveTo | MoveFromRangeStart | MoveFromRangeEnd | MoveToRangeStart | MoveToRangeEnd | MathEquation;
1248
- /**
1249
- * Paragraph (w:p)
1250
- */
1251
- interface Paragraph {
1252
- type: 'paragraph';
1253
- /** Unique paragraph ID */
1254
- paraId?: string;
1255
- /** Text ID */
1256
- textId?: string;
1257
- /** Paragraph formatting */
1258
- formatting?: ParagraphFormatting;
1259
- /** Paragraph-level tracked property changes (w:pPrChange) */
1260
- propertyChanges?: ParagraphPropertyChange[];
1261
- /** Paragraph content */
1262
- content: ParagraphContent[];
1263
- /** Computed list rendering (if this is a list item) */
1264
- listRendering?: ListRendering;
1265
- /** Section properties (if this paragraph ends a section) */
1266
- sectionProperties?: SectionProperties;
1267
- }
1268
- /**
1269
- * Header/footer type
1270
- */
1271
- type HeaderFooterType = 'default' | 'first' | 'even';
1272
- /**
1273
- * Header or footer reference
1274
- */
1275
- interface HeaderReference {
1276
- type: HeaderFooterType;
1277
- rId: string;
1278
- }
1279
- interface FooterReference {
1280
- type: HeaderFooterType;
1281
- rId: string;
1282
- }
1283
- /**
1284
- * Header or footer content
1285
- */
1286
- interface HeaderFooter {
1287
- type: 'header' | 'footer';
1288
- /** Header/footer type */
1289
- hdrFtrType: HeaderFooterType;
1290
- /** Content (paragraphs, tables, etc.) */
1291
- content: (Paragraph | Table)[];
1292
- }
1293
- /**
1294
- * Footnote position
1295
- */
1296
- type FootnotePosition = 'pageBottom' | 'beneathText' | 'sectEnd' | 'docEnd';
1297
- /**
1298
- * Endnote position
1299
- */
1300
- type EndnotePosition = 'sectEnd' | 'docEnd';
1301
- /**
1302
- * Number restart type
1303
- */
1304
- type NoteNumberRestart = 'continuous' | 'eachSect' | 'eachPage';
1305
- /**
1306
- * Footnote properties
1307
- */
1308
- interface FootnoteProperties {
1309
- position?: FootnotePosition;
1310
- numFmt?: NumberFormat;
1311
- numStart?: number;
1312
- numRestart?: NoteNumberRestart;
1313
- }
1314
- /**
1315
- * Endnote properties
1316
- */
1317
- interface EndnoteProperties {
1318
- position?: EndnotePosition;
1319
- numFmt?: NumberFormat;
1320
- numStart?: number;
1321
- numRestart?: NoteNumberRestart;
1322
- }
1323
- /**
1324
- * Footnote (w:footnote)
1325
- */
1326
- interface Footnote {
1327
- type: 'footnote';
1328
- /** Footnote ID */
1329
- id: number;
1330
- /** Special footnote type */
1331
- noteType?: 'normal' | 'separator' | 'continuationSeparator' | 'continuationNotice';
1332
- /** Content */
1333
- content: Paragraph[];
1334
- }
1335
- /**
1336
- * Endnote (w:endnote)
1337
- */
1338
- interface Endnote {
1339
- type: 'endnote';
1340
- /** Endnote ID */
1341
- id: number;
1342
- /** Special endnote type */
1343
- noteType?: 'normal' | 'separator' | 'continuationSeparator' | 'continuationNotice';
1344
- /** Content */
1345
- content: Paragraph[];
1346
- }
1347
- /**
1348
- * Page orientation
1349
- */
1350
- type PageOrientation = 'portrait' | 'landscape';
1351
- /**
1352
- * Section start type
1353
- */
1354
- type SectionStart = 'continuous' | 'nextPage' | 'oddPage' | 'evenPage' | 'nextColumn';
1355
- /**
1356
- * Vertical alignment
1357
- */
1358
- type VerticalAlign = 'top' | 'center' | 'both' | 'bottom';
1359
- /**
1360
- * Line number restart type
1361
- */
1362
- type LineNumberRestart = 'continuous' | 'newPage' | 'newSection';
1363
- /**
1364
- * Column definition
1365
- */
1366
- interface Column {
1367
- /** Column width in twips */
1368
- width?: number;
1369
- /** Space after column in twips */
1370
- space?: number;
1371
- }
1372
- /**
1373
- * Section properties (w:sectPr)
1374
- */
1375
- interface SectionProperties {
1376
- /** Page width in twips */
1377
- pageWidth?: number;
1378
- /** Page height in twips */
1379
- pageHeight?: number;
1380
- /** Page orientation */
1381
- orientation?: PageOrientation;
1382
- /** Top margin in twips */
1383
- marginTop?: number;
1384
- /** Bottom margin in twips */
1385
- marginBottom?: number;
1386
- /** Left margin in twips */
1387
- marginLeft?: number;
1388
- /** Right margin in twips */
1389
- marginRight?: number;
1390
- /** Header distance from top in twips */
1391
- headerDistance?: number;
1392
- /** Footer distance from bottom in twips */
1393
- footerDistance?: number;
1394
- /** Gutter margin in twips */
1395
- gutter?: number;
1396
- /** Number of columns */
1397
- columnCount?: number;
1398
- /** Space between columns in twips */
1399
- columnSpace?: number;
1400
- /** Equal width columns */
1401
- equalWidth?: boolean;
1402
- /** Separator line between columns */
1403
- separator?: boolean;
1404
- /** Individual column definitions */
1405
- columns?: Column[];
1406
- /** Section start type */
1407
- sectionStart?: SectionStart;
1408
- /** Vertical alignment of text */
1409
- verticalAlign?: VerticalAlign;
1410
- /** Right-to-left section */
1411
- bidi?: boolean;
1412
- /** Header references */
1413
- headerReferences?: HeaderReference[];
1414
- /** Footer references */
1415
- footerReferences?: FooterReference[];
1416
- /** Different first page header/footer */
1417
- titlePg?: boolean;
1418
- /** Different odd/even page headers/footers */
1419
- evenAndOddHeaders?: boolean;
1420
- /** Line numbering settings */
1421
- lineNumbers?: {
1422
- start?: number;
1423
- countBy?: number;
1424
- distance?: number;
1425
- restart?: LineNumberRestart;
1426
- };
1427
- /** Page borders */
1428
- pageBorders?: {
1429
- top?: BorderSpec;
1430
- bottom?: BorderSpec;
1431
- left?: BorderSpec;
1432
- right?: BorderSpec;
1433
- /** Display setting */
1434
- display?: 'allPages' | 'firstPage' | 'notFirstPage';
1435
- /** Offset from */
1436
- offsetFrom?: 'page' | 'text';
1437
- /** Z-order */
1438
- zOrder?: 'front' | 'back';
1439
- };
1440
- /** Page background */
1441
- background?: {
1442
- color?: ColorValue;
1443
- themeColor?: ThemeColorSlot;
1444
- themeTint?: string;
1445
- themeShade?: string;
1446
- };
1447
- /** Footnote properties for this section */
1448
- footnotePr?: FootnoteProperties;
1449
- /** Endnote properties for this section */
1450
- endnotePr?: EndnoteProperties;
1451
- /** Document grid */
1452
- docGrid?: {
1453
- type?: 'default' | 'lines' | 'linesAndChars' | 'snapToChars';
1454
- linePitch?: number;
1455
- charSpace?: number;
1456
- };
1457
- /** First page paper source */
1458
- paperSrcFirst?: number;
1459
- /** Other pages paper source */
1460
- paperSrcOther?: number;
1461
- }
1462
- /**
1463
- * Block-level content types
1464
- */
1465
- type BlockContent = Paragraph | Table | BlockSdt;
1466
- /**
1467
- * Section (implicit or explicit based on sectPr)
1468
- */
1469
- interface Section {
1470
- /** Section properties */
1471
- properties: SectionProperties;
1472
- /** Content in this section */
1473
- content: BlockContent[];
1474
- /** Headers for this section */
1475
- headers?: Map<HeaderFooterType, HeaderFooter>;
1476
- /** Footers for this section */
1477
- footers?: Map<HeaderFooterType, HeaderFooter>;
1478
- }
1479
- /**
1480
- * Document body (w:body)
1481
- */
1482
- interface DocumentBody {
1483
- /** All content (paragraphs, tables) */
1484
- content: BlockContent[];
1485
- /** Sections (derived from sectPr in paragraphs and final sectPr) */
1486
- sections?: Section[];
1487
- /** Final section properties (from body's sectPr) */
1488
- finalSectionProperties?: SectionProperties;
1489
- /** Comments from comments.xml */
1490
- comments?: Comment[];
1491
- }
1492
-
1493
- /**
1494
- * Styles, Theme, Font Table, Relationships & Media Types
28
+ * ## What we mirror ()
1495
29
  *
1496
- * Types for document-level definitions that don't form the content tree.
1497
- */
1498
-
1499
- /**
1500
- * Style type
1501
- */
1502
- type StyleType = 'paragraph' | 'character' | 'numbering' | 'table';
1503
- /**
1504
- * Style definition
1505
- */
1506
- interface Style {
1507
- /** Style ID */
1508
- styleId: string;
1509
- /** Style type */
1510
- type: StyleType;
1511
- /** Display name */
1512
- name?: string;
1513
- /** Based on style ID */
1514
- basedOn?: string;
1515
- /** Next style after Enter (for paragraph styles) */
1516
- next?: string;
1517
- /** Linked style (paragraph/character pair) */
1518
- link?: string;
1519
- /** UI sort priority */
1520
- uiPriority?: number;
1521
- /** Hidden from UI */
1522
- hidden?: boolean;
1523
- /** Semi-hidden from UI */
1524
- semiHidden?: boolean;
1525
- /** Unhide when used */
1526
- unhideWhenUsed?: boolean;
1527
- /** Quick format in gallery */
1528
- qFormat?: boolean;
1529
- /** Is default style */
1530
- default?: boolean;
1531
- /** Personal style (custom) */
1532
- personal?: boolean;
1533
- /** Paragraph properties (for paragraph/table styles) */
1534
- pPr?: ParagraphFormatting;
1535
- /** Run properties */
1536
- rPr?: TextFormatting;
1537
- /** Table properties (for table styles) */
1538
- tblPr?: TableFormatting;
1539
- /** Table row properties */
1540
- trPr?: TableRowFormatting;
1541
- /** Table cell properties */
1542
- tcPr?: TableCellFormatting;
1543
- /** Conditional table style parts */
1544
- tblStylePr?: Array<{
1545
- type: 'band1Horz' | 'band1Vert' | 'band2Horz' | 'band2Vert' | 'firstCol' | 'firstRow' | 'lastCol' | 'lastRow' | 'neCell' | 'nwCell' | 'seCell' | 'swCell';
1546
- pPr?: ParagraphFormatting;
1547
- rPr?: TextFormatting;
1548
- tblPr?: TableFormatting;
1549
- trPr?: TableRowFormatting;
1550
- tcPr?: TableCellFormatting;
1551
- }>;
1552
- }
1553
- /**
1554
- * Document defaults (w:docDefaults)
1555
- */
1556
- interface DocDefaults {
1557
- /** Default run properties */
1558
- rPr?: TextFormatting;
1559
- /** Default paragraph properties */
1560
- pPr?: ParagraphFormatting;
1561
- }
1562
- /**
1563
- * Style definitions from styles.xml
1564
- */
1565
- interface StyleDefinitions {
1566
- /** Document defaults */
1567
- docDefaults?: DocDefaults;
1568
- /** Latent styles */
1569
- latentStyles?: {
1570
- defLockedState?: boolean;
1571
- defUIPriority?: number;
1572
- defSemiHidden?: boolean;
1573
- defUnhideWhenUsed?: boolean;
1574
- defQFormat?: boolean;
1575
- count?: number;
1576
- };
1577
- /** Style definitions */
1578
- styles: Style[];
1579
- }
1580
- /**
1581
- * Theme color scheme (a:clrScheme)
1582
- */
1583
- interface ThemeColorScheme {
1584
- /** Dark 1 color (usually black) */
1585
- dk1?: string;
1586
- /** Light 1 color (usually white) */
1587
- lt1?: string;
1588
- /** Dark 2 color */
1589
- dk2?: string;
1590
- /** Light 2 color */
1591
- lt2?: string;
1592
- /** Accent colors 1-6 */
1593
- accent1?: string;
1594
- accent2?: string;
1595
- accent3?: string;
1596
- accent4?: string;
1597
- accent5?: string;
1598
- accent6?: string;
1599
- /** Hyperlink color */
1600
- hlink?: string;
1601
- /** Followed hyperlink color */
1602
- folHlink?: string;
1603
- }
1604
- /**
1605
- * Theme font (with script variants)
1606
- */
1607
- interface ThemeFont {
1608
- /** Latin font */
1609
- latin?: string;
1610
- /** East Asian font */
1611
- ea?: string;
1612
- /** Complex script font */
1613
- cs?: string;
1614
- /** Script-specific fonts */
1615
- fonts?: Record<string, string>;
1616
- }
1617
- /**
1618
- * Theme font scheme (a:fontScheme)
1619
- */
1620
- interface ThemeFontScheme {
1621
- /** Major font (headings) */
1622
- majorFont?: ThemeFont;
1623
- /** Minor font (body text) */
1624
- minorFont?: ThemeFont;
1625
- }
1626
- /**
1627
- * Theme (from theme1.xml)
1628
- */
1629
- interface Theme {
1630
- /** Theme name */
1631
- name?: string;
1632
- /** Color scheme */
1633
- colorScheme?: ThemeColorScheme;
1634
- /** Font scheme */
1635
- fontScheme?: ThemeFontScheme;
1636
- /** Format scheme (fills, lines, effects) - simplified */
1637
- formatScheme?: {
1638
- name?: string;
1639
- };
1640
- }
1641
- /**
1642
- * Font info from fontTable.xml
1643
- */
1644
- interface FontInfo {
1645
- /** Font name */
1646
- name: string;
1647
- /** Alternate names */
1648
- altName?: string;
1649
- /** Panose-1 classification */
1650
- panose1?: string;
1651
- /** Character set */
1652
- charset?: string;
1653
- /** Font family type */
1654
- family?: 'decorative' | 'modern' | 'roman' | 'script' | 'swiss' | 'auto';
1655
- /** Pitch (fixed or variable) */
1656
- pitch?: 'default' | 'fixed' | 'variable';
1657
- /** Signature */
1658
- sig?: {
1659
- usb0?: string;
1660
- usb1?: string;
1661
- usb2?: string;
1662
- usb3?: string;
1663
- csb0?: string;
1664
- csb1?: string;
1665
- };
1666
- /** Embedded font data reference */
1667
- embedRegular?: string;
1668
- embedBold?: string;
1669
- embedItalic?: string;
1670
- embedBoldItalic?: string;
1671
- }
1672
- /**
1673
- * Font table from fontTable.xml
1674
- */
1675
- interface FontTable {
1676
- fonts: FontInfo[];
1677
- }
1678
- /**
1679
- * Relationship type
1680
- */
1681
- type RelationshipType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image' | 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink' | 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/header' | 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer' | 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes' | 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes' | 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles' | 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering' | 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable' | 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme' | 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings' | 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings' | 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject' | 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart' | 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramData' | string;
1682
- /**
1683
- * Relationship entry
1684
- */
1685
- interface Relationship {
1686
- /** Relationship ID (e.g., "rId1") */
1687
- id: string;
1688
- /** Relationship type URI */
1689
- type: RelationshipType;
1690
- /** Target path or URL */
1691
- target: string;
1692
- /** Target mode */
1693
- targetMode?: 'External' | 'Internal';
1694
- }
1695
- /**
1696
- * Relationship map (keyed by rId)
1697
- */
1698
- type RelationshipMap = Map<string, Relationship>;
1699
- /**
1700
- * Media file from word/media/
1701
- */
1702
- interface MediaFile {
1703
- /** File path in ZIP */
1704
- path: string;
1705
- /** Original filename */
1706
- filename?: string;
1707
- /** MIME type */
1708
- mimeType: string;
1709
- /** Binary data */
1710
- data: ArrayBuffer;
1711
- /** Base64 encoded data for rendering */
1712
- base64?: string;
1713
- /** Data URL for direct use in src attributes */
1714
- dataUrl?: string;
1715
- }
1716
-
1717
- /**
1718
- * Comprehensive TypeScript types for full DOCX document representation
30
+ * | Word JS API | Our equivalent |
31
+ * | ----------------------------------- | ------------------------------------- |
32
+ * | `Range` (stable handle) | `paraId: string` |
33
+ * | `body.search(text)` → Ranges | `findText(query, opts) → FoundMatch[]`|
34
+ * | `range.insertComment(text)` | `addComment({paraId, text, search?})` |
35
+ * | `comment.reply(text)` | `replyTo(commentId, {text})` |
36
+ * | `comment.resolved = true` | `resolveComment(commentId)` |
37
+ * | `range.insertText(text, location)` | `proposeChange({paraId, search, replaceWith})` (3 modes via empty-string semantics) |
38
+ * | `document.getSelection()` | `getSelection() → SelectionInfo|null` |
39
+ * | `range.scrollIntoView()` | `scrollTo(paraId)` |
40
+ * | `commentCollection.getItems()` | `getComments(filter?)` |
41
+ * | `body.paragraphs.getItems()` | `getContent(opts?)` |
42
+ * | `document.body.text` | `getContentAsText(opts?)` |
43
+ * | `revisionCollection.getItems()` | `getChanges(filter?)` |
44
+ * | `Document.onContentChanged.add(...)`| `onContentChange(listener)` |
45
+ * | `Document.onSelectionChanged.add()` | `onSelectionChange(listener)` |
46
+ * | `Range.font.bold` / `italic` / `color` / `size` / `name` | `applyFormatting({paraId, search?, marks})` |
47
+ * | `ParagraphFormat.style` / `applyStyle(...)` | `setParagraphStyle({paraId, styleId})` |
1719
48
  *
1720
- * This barrel file re-exports all types from the split modules.
1721
- * Existing imports from './types/document' continue to work unchanged.
49
+ * ## Beyond Word's surface (paged-document affordances)
1722
50
  *
1723
- * Module structure:
1724
- * - colors.ts — Color primitives, borders, shading
1725
- * - formatting.ts — Text, paragraph, and table formatting properties
1726
- * - lists.ts — Numbering and list definitions
1727
- * - content.ts — Content model (runs, images, shapes, tables, paragraphs, sections)
1728
- * - styles.ts — Styles, theme, fonts, relationships, media
1729
- */
1730
-
1731
- /**
1732
- * Complete DOCX package structure
1733
- */
1734
- interface DocxPackage {
1735
- /** Document body */
1736
- document: DocumentBody;
1737
- /** Style definitions */
1738
- styles?: StyleDefinitions;
1739
- /** Theme */
1740
- theme?: Theme;
1741
- /** Numbering definitions */
1742
- numbering?: NumberingDefinitions;
1743
- /** Font table */
1744
- fontTable?: FontTable;
1745
- /** Footnotes */
1746
- footnotes?: Footnote[];
1747
- /** Endnotes */
1748
- endnotes?: Endnote[];
1749
- /** Headers by relationship ID */
1750
- headers?: Map<string, HeaderFooter>;
1751
- /** Footers by relationship ID */
1752
- footers?: Map<string, HeaderFooter>;
1753
- /** Document relationships */
1754
- relationships?: RelationshipMap;
1755
- /** Media files */
1756
- media?: Map<string, MediaFile>;
1757
- /** Document properties */
1758
- properties?: {
1759
- title?: string;
1760
- subject?: string;
1761
- creator?: string;
1762
- keywords?: string;
1763
- description?: string;
1764
- lastModifiedBy?: string;
1765
- revision?: number;
1766
- created?: Date;
1767
- modified?: Date;
1768
- };
1769
- }
1770
- /**
1771
- * Complete parsed DOCX document
1772
- */
1773
- interface Document {
1774
- /** DOCX package with all parsed content */
1775
- package: DocxPackage;
1776
- /** Original ArrayBuffer for round-trip */
1777
- originalBuffer?: ArrayBuffer;
1778
- /** Detected template variables ({{...}}) */
1779
- templateVariables?: string[];
1780
- /** Parsing warnings/errors */
1781
- warnings?: string[];
1782
- }
1783
-
1784
- /**
1785
- * Types for @eigenpal/docx-editor-agents
51
+ * - `getPage(n)` / `getPages({from, to})` / `getTotalPages()` — Word's JS API
52
+ * doesn't model pages as first-class addressable units. We do, because the
53
+ * editor is paged. Backed by the layout-painter's page boundary state.
54
+ *
55
+ * ## Differences (intentional, documented)
56
+ *
57
+ * - All "insertText" overloads collapse into `proposeChange` with empty-string
58
+ * semantics: replaceWith="" deletes; search="" inserts at paragraph end;
59
+ * both non-empty replaces. Word has separate `insertText(...,'Replace')`,
60
+ * `insertText(...,'Before')`, etc.; we found three modes were enough and
61
+ * serialize cleaner for LLM tool calls.
62
+ * - Tracked changes are always *suggestions* in our world. Word lets the
63
+ * range mutate directly; we always go through the tracked-change path so
64
+ * the human keeps the final say. (This matches the agent UX.)
65
+ * - Word's `Range.context.sync()` is unnecessary — every call is one PM
66
+ * transaction.
67
+ * - Word's `Range` is a stateful object. Ours is a plain `{paraId, search?}`
68
+ * JSON value, so it survives JSON.stringify and works for tool calls / MCP.
69
+ *
70
+ * ## Out of scope (gaps we deliberately don't implement)
71
+ *
72
+ * - Paragraph creation (`body.insertParagraph`). Out of scope for v1.
73
+ * - Table mutation (insert row/col, delete cell). Read-only.
74
+ * - Headers / footers / sections.
75
+ * - `Range.getOoxml()` / `getHtml()`. Plain text only.
76
+ * - `customXmlParts` / `contentControls`.
77
+ * - Accept / reject tracked changes. Human-only by design.
78
+ *
79
+ * Future versions can grow these by extending this interface — typecheck
80
+ * will then enforce the new contract.
1786
81
  */
1787
- interface HeadingBlock {
1788
- type: 'heading';
1789
- index: number;
1790
- level: number;
1791
- text: string;
1792
- }
1793
- interface ParagraphBlock {
1794
- type: 'paragraph';
1795
- index: number;
1796
- text: string;
1797
- }
1798
- interface TableBlock {
1799
- type: 'table';
1800
- index: number;
1801
- rows: string[][];
1802
- }
1803
- interface ListItemBlock {
1804
- type: 'list-item';
1805
- index: number;
1806
- text: string;
1807
- listLevel: number;
1808
- listType: 'bullet' | 'number';
1809
- }
1810
- type ContentBlock = HeadingBlock | ParagraphBlock | TableBlock | ListItemBlock;
1811
- interface GetContentOptions {
1812
- fromIndex?: number;
1813
- toIndex?: number;
1814
- /** Annotate tracked changes inline. Default: true */
1815
- includeTrackedChanges?: boolean;
1816
- /** Annotate comments inline. Default: true */
1817
- includeCommentAnchors?: boolean;
1818
- }
1819
- interface ReviewChange {
1820
- id: number;
1821
- type: 'insertion' | 'deletion' | 'moveFrom' | 'moveTo';
1822
- author: string;
1823
- date: string | null;
1824
- text: string;
1825
- context: string;
1826
- paragraphIndex: number;
1827
- }
1828
- interface ReviewCommentReply {
1829
- id: number;
1830
- author: string;
1831
- date: string | null;
1832
- text: string;
1833
- }
1834
- interface ReviewComment {
1835
- id: number;
1836
- author: string;
1837
- date: string | null;
1838
- text: string;
1839
- anchoredText: string;
1840
- paragraphIndex: number;
1841
- replies: ReviewCommentReply[];
1842
- done: boolean;
1843
- }
1844
- interface ChangeFilter {
1845
- author?: string;
1846
- type?: 'insertion' | 'deletion' | 'moveFrom' | 'moveTo';
1847
- }
1848
- interface CommentFilter {
1849
- author?: string;
1850
- done?: boolean;
1851
- }
1852
- interface AddCommentOptions {
1853
- paragraphIndex: number;
1854
- text: string;
1855
- author?: string;
1856
- /** Optional: anchor to specific text. Omit to anchor whole paragraph. */
1857
- search?: string;
1858
- }
1859
- interface ReplyOptions {
1860
- text: string;
1861
- author?: string;
1862
- }
1863
- interface ProposeReplacementOptions {
1864
- paragraphIndex: number;
1865
- search: string;
1866
- replaceWith: string;
1867
- author?: string;
1868
- }
1869
- interface ProposeInsertionOptions {
1870
- paragraphIndex: number;
1871
- insertText: string;
1872
- author?: string;
1873
- position?: 'before' | 'after';
1874
- search?: string;
1875
- }
1876
- interface ProposeDeletionOptions {
1877
- paragraphIndex: number;
1878
- search: string;
1879
- author?: string;
1880
- }
1881
- interface BatchReviewOptions {
1882
- accept?: number[];
1883
- reject?: number[];
1884
- comments?: AddCommentOptions[];
1885
- replies?: (ReplyOptions & {
1886
- commentId: number;
1887
- })[];
1888
- proposals?: ProposeReplacementOptions[];
1889
- }
1890
- interface BatchError {
1891
- operation: string;
1892
- id?: number;
1893
- search?: string;
1894
- error: string;
1895
- }
1896
- interface BatchResult {
1897
- accepted: number;
1898
- rejected: number;
1899
- commentsAdded: number;
1900
- repliesAdded: number;
1901
- proposalsAdded: number;
1902
- errors: BatchError[];
1903
- }
1904
82
 
1905
83
  /**
1906
- * DocxReviewer Word-like API for AI document review.
84
+ * The formal Word-JS-API parity surface. Each method maps to one or more
85
+ * Word API methods (named in the JSDoc above each member).
1907
86
  *
1908
- * @example
1909
- * ```ts
1910
- * const reviewer = await DocxReviewer.fromBuffer(buffer, 'AI Reviewer');
1911
- * const text = reviewer.getContentAsText();
1912
- * reviewer.addComment(5, 'Fix this paragraph.');
1913
- * reviewer.replace(5, '$50k', '$500k');
1914
- * const output = await reviewer.toBuffer();
1915
- * ```
87
+ * If you change the EditorBridge surface, this interface must change too —
88
+ * the static assertion at the bottom of the file enforces it.
1916
89
  */
1917
-
1918
- declare class DocxReviewer {
1919
- private doc;
1920
- /** Default author for comments and tracked changes. Set once, used everywhere. */
1921
- readonly author: string;
1922
- /**
1923
- * Create a reviewer from a parsed Document.
1924
- * @param document - Parsed Document from @eigenpal/docx-core
1925
- * @param author - Default author name for comments and changes. (default: 'AI')
1926
- * @param originalBuffer - Original DOCX buffer, needed for toBuffer()
1927
- */
1928
- constructor(document: Document, author?: string, originalBuffer?: ArrayBuffer);
1929
- /**
1930
- * Create a reviewer from a DOCX file buffer.
1931
- * @param buffer - ArrayBuffer of the DOCX file
1932
- * @param author - Default author name for comments and changes. (default: 'AI')
1933
- */
1934
- static fromBuffer(buffer: ArrayBuffer, author?: string): Promise<DocxReviewer>;
1935
- private get body();
1936
- private resolveAuthor;
1937
- /** Get document content as structured blocks (headings, paragraphs, tables, lists). */
1938
- getContent(options?: GetContentOptions): ContentBlock[];
1939
- /**
1940
- * Get document content as plain text for LLM prompts.
1941
- * Each paragraph is prefixed with its index: `[0] text`, `[1] text`, etc.
1942
- * Table cells include position: `[5] (table, row 1, col 2) cell text`.
1943
- * Avoids JSON quote-escaping issues — LLMs can copy text verbatim.
1944
- */
90
+ interface WordCompatBridge {
91
+ /** Word: `document.body.text` (stringified, indexed lines). */
1945
92
  getContentAsText(options?: GetContentOptions): string;
1946
- /** Get all tracked changes in the document. */
1947
- getChanges(filter?: ChangeFilter): ReviewChange[];
1948
- /** Get all comments with their replies. */
93
+ /** Word: `body.paragraphs.getItems()`. */
94
+ getContent(options?: GetContentOptions): ContentBlock[];
95
+ /** Word: `commentCollection.getItems()`. */
1949
96
  getComments(filter?: CommentFilter): ReviewComment[];
97
+ /** Word: `revisionCollection.getItems()`. */
98
+ getChanges(filter?: ChangeFilter): ReviewChange[];
99
+ /** Word: `body.search(text)` returning Range[]. */
100
+ findText(query: string, options?: {
101
+ caseSensitive?: boolean;
102
+ limit?: number;
103
+ }): FoundMatch[];
104
+ /** Word: `document.getSelection()`. */
105
+ getSelection(): SelectionInfo | null;
106
+ /** Word: `range.insertComment(text)`. Anchored by paraId (Range handle). */
107
+ addComment(options: AddCommentByParaIdOptions): number | null;
108
+ /** Word: `comment.reply(text)`. */
109
+ replyTo(commentId: number, options: ReplyOptions): number | null;
110
+ /** Word: `comment.resolved = true`. */
111
+ resolveComment(commentId: number): void;
1950
112
  /**
1951
- * Add a comment on a paragraph.
1952
- * @param paragraphIndex - Index of the paragraph to comment on
1953
- * @param text - Comment text
1954
- * @returns The new comment ID
1955
- */
1956
- addComment(paragraphIndex: number, text: string): number;
1957
- /**
1958
- * Add a comment with full options (custom author, anchored to specific text).
1959
- * @param options - Comment options
1960
- * @returns The new comment ID
1961
- */
1962
- addComment(options: AddCommentOptions): number;
1963
- /**
1964
- * Reply to an existing comment.
1965
- * @param commentId - ID of the comment to reply to
1966
- * @param text - Reply text
1967
- * @returns The new reply comment ID
1968
- */
1969
- replyTo(commentId: number, text: string): number;
1970
- /** Reply to an existing comment with full options. */
1971
- replyTo(commentId: number, options: ReplyOptions): number;
1972
- /**
1973
- * Remove a comment by ID. Removing a top-level comment also removes its
1974
- * replies and the anchored range markers. Removing a reply only removes
1975
- * that reply.
1976
- * @param commentId - ID of the comment to remove
113
+ * Word: `range.insertText(text, location)` collapsed into one verb.
114
+ * - replacement: search non-empty, replaceWith non-empty
115
+ * - deletion: search non-empty, replaceWith ""
116
+ * - insertion: search "", replaceWith non-empty (paragraph end)
1977
117
  */
1978
- removeComment(commentId: number): void;
118
+ proposeChange(options: ProposeChangeOptions): boolean;
1979
119
  /**
1980
- * Replace text in a paragraph. Creates a tracked change (deletion + insertion).
1981
- * @param paragraphIndex - Index of the paragraph
1982
- * @param search - Short phrase to find within the paragraph
1983
- * @param replaceWith - Replacement text
120
+ * Word: `range.font.bold = true` / `range.font.italic = true` / etc.
121
+ * Applied to a paragraph or to a unique phrase within it. Direct edit,
122
+ * not a tracked change.
1984
123
  */
1985
- replace(paragraphIndex: number, search: string, replaceWith: string): void;
1986
- /** Replace text with full options. */
1987
- replace(options: ProposeReplacementOptions): void;
1988
- /** @deprecated Use replace() instead. */
1989
- proposeReplacement(options: ProposeReplacementOptions): void;
1990
- /** Insert text as a tracked change. */
1991
- proposeInsertion(options: ProposeInsertionOptions): void;
1992
- /** Delete text as a tracked change. */
1993
- proposeDeletion(options: ProposeDeletionOptions): void;
1994
- /** Accept a tracked change by its revision ID. */
1995
- acceptChange(id: number): void;
1996
- /** Reject a tracked change by its revision ID. */
1997
- rejectChange(id: number): void;
1998
- /** Accept all tracked changes. Returns count accepted. */
1999
- acceptAll(): number;
2000
- /** Reject all tracked changes. Returns count rejected. */
2001
- rejectAll(): number;
124
+ applyFormatting(options: ApplyFormattingOptions): boolean;
125
+ /** Word: `paragraph.styleBuiltIn = ...` / `paragraph.style = 'Heading 1'`. */
126
+ setParagraphStyle(options: SetParagraphStyleOptions): boolean;
2002
127
  /**
2003
- * Apply multiple review operations in one call.
2004
- * Uses the reviewer's default author. Individual failures are collected, not thrown.
128
+ * Read one rendered page (1-indexed). Word's JS API does not expose pages
129
+ * as first-class objects; we do because the editor is paged.
2005
130
  */
2006
- applyReview(ops: BatchReviewOptions): BatchResult;
2007
- /** Get the modified Document model. */
2008
- toDocument(): Document;
2009
- /** Serialize back to a DOCX buffer. Requires the original buffer. */
2010
- toBuffer(): Promise<ArrayBuffer>;
2011
- }
2012
-
2013
- /**
2014
- * Error classes for @eigenpal/docx-editor-agents
2015
- */
2016
- declare class TextNotFoundError extends Error {
2017
- constructor(search: string, paragraphIndex?: number);
2018
- }
2019
- declare class ChangeNotFoundError extends Error {
2020
- constructor(id: number);
2021
- }
2022
- declare class CommentNotFoundError extends Error {
2023
- constructor(id: number);
131
+ getPage(pageNumber: number): PageContent | null;
132
+ /** Read a range of rendered pages (1-indexed, inclusive). */
133
+ getPages(options: {
134
+ from: number;
135
+ to: number;
136
+ }): PageContent[];
137
+ /** Total number of pages currently rendered. */
138
+ getTotalPages(): number;
139
+ /** Word: `range.scrollIntoView()`. */
140
+ scrollTo(paraId: string): boolean;
141
+ /** Word: `Document.onContentChanged.add(handler)`. Returns unsubscribe. */
142
+ onContentChange(listener: (event: ContentChangeEvent) => void): () => void;
143
+ /** Word: `Document.onSelectionChanged.add(handler)`. Returns unsubscribe. */
144
+ onSelectionChange(listener: (event: SelectionChangeEvent) => void): () => void;
2024
145
  }
2025
146
 
2026
- export { type BatchError, type BatchResult, type BatchReviewOptions, ChangeNotFoundError, CommentNotFoundError, type ContentBlock, DocxReviewer, type GetContentOptions, type ReviewChange, type ReviewComment, TextNotFoundError };
147
+ export { ChangeNotFoundError, CommentNotFoundError, ContentBlock, GetContentOptions, ReviewChange, ReviewComment, TextNotFoundError, type WordCompatBridge };