wordinweb 0.3.7 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2944 @@
1
+ interface XmlElement {
2
+ name: string;
3
+ attrs: Record<string, string>;
4
+ children: XmlElement[];
5
+ /** Concatenated character data directly inside this element. */
6
+ text: string;
7
+ /** Editor placeholder retained in memory but omitted from XML while empty. */
8
+ omitWhenEmpty?: boolean;
9
+ }
10
+
11
+ /**
12
+ * Typed document model produced by the parser and consumed by the layout
13
+ * engine. All lengths are CSS px (see units.ts) unless a field name says
14
+ * otherwise. Property bags are Partial-style: `undefined` means "not set at
15
+ * this level" so the style-inheritance merge can distinguish absence from an
16
+ * explicit value.
17
+ *
18
+ * Model nodes keep `src` references to the XML elements they were parsed
19
+ * from: the XML tree is the source of truth for editing — commands mutate it
20
+ * and the model is re-derived, which preserves round-trip fidelity for
21
+ * everything untouched.
22
+ */
23
+
24
+ type BorderStyle = "none" | "single" | "double" | "dotted" | "dashed" | "thick" | "wave" | "dotDash" | "dotDotDash" | "thinThickSmallGap" | "triple";
25
+ interface Border {
26
+ style: BorderStyle;
27
+ /** Stroke width in px. */
28
+ width: number;
29
+ /** CSS color. */
30
+ color: string;
31
+ /** Gap between border and content in px (w:space, points in OOXML). */
32
+ space: number;
33
+ /** Declared stroke width in px BEFORE the 0.75px paint floor (w:sz/8 pt).
34
+ * Word's LAYOUT math (table row border share) uses this true width — a
35
+ * sz-4 rule contributes 0.5pt, not the floored 0.5625pt (phase23 p66:
36
+ * 45 rows drift 2.5px down without it). */
37
+ rawWidth?: number;
38
+ /** w:shadow: a strip outside the right and bottom borders. */
39
+ shadow?: boolean;
40
+ }
41
+ interface ParagraphBorders {
42
+ top?: Border;
43
+ bottom?: Border;
44
+ left?: Border;
45
+ right?: Border;
46
+ /** Drawn between consecutive paragraphs that both specify it. */
47
+ between?: Border;
48
+ }
49
+ type LineSpacingRule = "auto" | "atLeast" | "exact";
50
+ interface LineSpacing {
51
+ rule: LineSpacingRule;
52
+ /**
53
+ * For "auto": multiple of single line height (240ths in OOXML, stored here
54
+ * as the multiplier, e.g. 1.15). For atLeast/exact: px.
55
+ */
56
+ value: number;
57
+ }
58
+ type Alignment = "left" | "center" | "right" | "justify";
59
+ interface TabStop {
60
+ /** px from the left text edge */
61
+ pos: number;
62
+ align: "left" | "center" | "right" | "decimal" | "bar";
63
+ leader: "none" | "dot" | "hyphen" | "underscore" | "middleDot";
64
+ /** w:val="clear": removes the inherited stop at this pos when tab lists
65
+ * merge down the style chain (never a live stop itself). */
66
+ clear?: boolean;
67
+ }
68
+ interface RunProps {
69
+ bold?: boolean;
70
+ italic?: boolean;
71
+ underline?: string;
72
+ strike?: boolean;
73
+ doubleStrike?: boolean;
74
+ /** Resolved primary font family name (ascii/hAnsi, theme-resolved). */
75
+ font?: string;
76
+ /** East Asian font (rFonts w:eastAsia): used for CJK codepoints. */
77
+ fontEastAsia?: string;
78
+ /** hAnsi font (rFonts w:hAnsi, theme-resolved): Word uses this channel for
79
+ * non-ASCII, non-CJK, non-complex characters (curly quotes, ≤, dashes). A
80
+ * run that declares only w:ascii leaves it inherited from the style chain. */
81
+ fontHAnsi?: string;
82
+ /** Complex-script font (rFonts w:cs): used for RTL/complex runs. */
83
+ fontComplex?: string;
84
+ /** w:rtl — this run's text is right-to-left (Arabic/Hebrew). */
85
+ rtl?: boolean;
86
+ /** Font size in px. */
87
+ size?: number;
88
+ /** CSS color; "auto" resolved to inherit/black by renderer. */
89
+ color?: string;
90
+ highlight?: string;
91
+ /** Character shading fill (w:shd). */
92
+ shading?: string;
93
+ /** Run border (w:bdr): a box painted around the run. Word merges adjacent
94
+ * runs with identical borders into one box; a run wrapping across lines
95
+ * closes the box on every line segment. */
96
+ border?: Border;
97
+ verticalAlign?: "baseline" | "superscript" | "subscript";
98
+ caps?: boolean;
99
+ smallCaps?: boolean;
100
+ /** Letter spacing px (w:spacing, twips in OOXML). */
101
+ letterSpacing?: number;
102
+ /** Minimum font size in px at which w:kern enables pair kerning; null is
103
+ * the explicit w:kern=0 override. */
104
+ kerningThreshold?: number | null;
105
+ /** Paint-only letter spacing when layout advances intentionally differ. */
106
+ paintLetterSpacing?: number;
107
+ /** w:w horizontal character scaling as a fraction (1.5 = 150%). */
108
+ textScale?: number;
109
+ /** w:fitText target width in px: the run's advances scale so its text
110
+ * occupies exactly this width (resolved to textScale at layout time). */
111
+ fitText?: number;
112
+ /** w:position baseline shift in px, positive = raised. */
113
+ raise?: number;
114
+ /** w:outline — hollow stroked glyphs. */
115
+ outline?: boolean;
116
+ /** w14:textOutline — glyph outline stroke (WordArt gallery styles). */
117
+ textOutline?: {
118
+ color: string;
119
+ width: number;
120
+ };
121
+ /** w:shadow / w14:shadow — offset glyph shadow. */
122
+ textShadow?: boolean;
123
+ /** w:emboss / w:imprint — Word triple-draws offset copies. */
124
+ emboss?: boolean;
125
+ imprint?: boolean;
126
+ vanish?: boolean;
127
+ /** w:rPr w:snapToGrid: whether this run participates in the section's
128
+ * docGrid. A line whose runs ALL declare 0 lays off the grid (see
129
+ * finishLine); ParaProps.snapToGrid covers the whole paragraph. */
130
+ snapToGrid?: boolean;
131
+ /** Character style id (w:rStyle). */
132
+ styleId?: string;
133
+ lang?: string;
134
+ /** w:lang w:bidi — the language of the run's complex-script text (Arabic, Hebrew, Indic, Thai, ...). */
135
+ langBidi?: string;
136
+ }
137
+ interface NumberingRef {
138
+ numId: number;
139
+ ilvl: number;
140
+ }
141
+ interface ParaProps {
142
+ styleId?: string;
143
+ alignment?: Alignment;
144
+ /** The exact OOXML w:jc value when it is a "justify" flavor whose behavior
145
+ * differs from plain "both": `distribute` also stretches the LAST line, and
146
+ * the Arabic `*Kashida` levels elongate glyphs (kashida) so lines pack fewer
147
+ * words and — at medium/high — wrap to more lines. Absent for plain "both".
148
+ * `alignment` stays "justify" for all of these. */
149
+ justifyKind?: "distribute" | "lowKashida" | "mediumKashida" | "highKashida";
150
+ /** w:bidi — right-to-left paragraph: lines assemble RTL and default
151
+ * alignment flips to the right edge. */
152
+ bidi?: boolean;
153
+ /** px */
154
+ indentLeft?: number;
155
+ indentRight?: number;
156
+ /** Positive px; mutually exclusive with hanging in effect. */
157
+ indentFirstLine?: number;
158
+ /** Positive px hanging indent. */
159
+ indentHanging?: number;
160
+ spacingBefore?: number;
161
+ spacingAfter?: number;
162
+ /** w:beforeAutospacing/afterAutospacing: HTML-style automatic paragraph
163
+ * spacing — Word ignores the literal before/after and inserts one blank
164
+ * line's worth of space. */
165
+ beforeAutospacing?: boolean;
166
+ afterAutospacing?: boolean;
167
+ /** Word's default when absent is auto/1.0 via docDefaults. */
168
+ lineSpacing?: LineSpacing;
169
+ /** w:snapToGrid: whether this paragraph's lines use the section docGrid. */
170
+ snapToGrid?: boolean;
171
+ contextualSpacing?: boolean;
172
+ keepNext?: boolean;
173
+ /** w:framePr w:dropCap: the paragraph is a drop-cap letter frame. */
174
+ dropCap?: {
175
+ mode: "drop" | "margin";
176
+ lines: number;
177
+ hSpace: number;
178
+ pageAnchored?: boolean;
179
+ };
180
+ /** w:framePr positioned text frame (absolute-positioned paragraph the body
181
+ * text wraps around). Geometry in px. Individual attributes are optional so a
182
+ * framePr merges attribute-by-attribute across the style cascade (a direct
183
+ * framePr that sets only h/x/y keeps the style framePr's width/anchor — IEEE
184
+ * authors); the engine normalizes defaults at layout time. */
185
+ frame?: {
186
+ w?: number;
187
+ h?: number;
188
+ hRule?: "auto" | "atLeast" | "exact";
189
+ x?: number;
190
+ y?: number;
191
+ hAnchor?: "page" | "margin" | "text" | "column";
192
+ vAnchor?: "page" | "margin" | "text" | "paragraph";
193
+ xAlign?: "left" | "center" | "right" | "inside" | "outside";
194
+ yAlign?: "top" | "center" | "bottom" | "inside" | "outside" | "inline";
195
+ wrap?: "around" | "auto" | "notBeside" | "through" | "tight" | "none";
196
+ /** w:hSpace / w:vSpace: horizontal/vertical margin around the frame (px). */
197
+ hSpace?: number;
198
+ vSpace?: number;
199
+ };
200
+ keepLines?: boolean;
201
+ pageBreakBefore?: boolean;
202
+ widowControl?: boolean;
203
+ borders?: ParagraphBorders;
204
+ /** Paragraph shading fill as CSS color. */
205
+ shading?: string;
206
+ numbering?: NumberingRef | null;
207
+ /** A numPr that carries ilvl but no numId (Heading3 basedOn Heading2)
208
+ * overrides only the list LEVEL, keeping the inherited numId; the style
209
+ * chain applies it to `numbering` on merge. */
210
+ numberingLevelOverride?: number;
211
+ tabs?: TabStop[];
212
+ outlineLevel?: number;
213
+ /** Run props declared on pPr/rPr — apply to the paragraph mark & numbering label. */
214
+ markRunProps?: RunProps;
215
+ /**
216
+ * styleId of the enclosing table (set on cell paragraphs at parse time).
217
+ * A table style's own pPr layers between docDefaults and the paragraph
218
+ * style, e.g. TableGrid's `spacing after=0 line=240` overrides docDefaults'
219
+ * `after=200 line=276` so list cells lay out compactly.
220
+ */
221
+ tableStyleId?: string;
222
+ /**
223
+ * Grid position of the enclosing cell plus the table's tblLook (set on cell
224
+ * paragraphs at parse time, like tableStyleId). Lets run/paragraph
225
+ * resolution layer the applicable w:tblStylePr conditional formats (e.g.
226
+ * firstRow bold + white) between the table style's own rPr and the
227
+ * paragraph style chain.
228
+ */
229
+ tableCellCond?: {
230
+ look?: TableLook;
231
+ rowIdx: number;
232
+ nRows: number;
233
+ colStart: number;
234
+ colSpan: number;
235
+ nCols: number;
236
+ };
237
+ }
238
+ interface TextContent {
239
+ kind: "text";
240
+ text: string;
241
+ /** Source w:t element inside the run, when this text came verbatim from one. */
242
+ srcT?: XmlElement;
243
+ /** When this text is the glyph of a modern checkbox content control, the
244
+ * source `w14:checkbox` element (in the enclosing w:sdt's sdtPr). Its
245
+ * presence makes the glyph a click-to-toggle target rather than plain text. */
246
+ checkbox?: XmlElement;
247
+ }
248
+ interface BreakContent {
249
+ kind: "break";
250
+ breakType: "line" | "page" | "column";
251
+ }
252
+ interface TabContent {
253
+ kind: "tab";
254
+ }
255
+ interface PTabContent {
256
+ kind: "ptab";
257
+ /** Absolute-position tab: jump to left/center/right of the base. */
258
+ alignment: "left" | "center" | "right";
259
+ relativeTo: "margin" | "indent";
260
+ }
261
+ interface ImageContent {
262
+ kind: "image";
263
+ /** Part path of the image inside the package. */
264
+ part: string;
265
+ width: number;
266
+ height: number;
267
+ /** True when the drawing is floating (wp:anchor); v1 lays it out inline. */
268
+ anchored?: boolean;
269
+ /** a:srcRect crop, fractions of the source bitmap. */
270
+ crop?: {
271
+ l: number;
272
+ t: number;
273
+ r: number;
274
+ b: number;
275
+ };
276
+ /** a:xfrm rotation, degrees clockwise. */
277
+ rotation?: number;
278
+ /** a:ln picture outline (Word draws it just outside the image). */
279
+ border?: {
280
+ color: string;
281
+ width: number;
282
+ };
283
+ /** Source w:drawing (or pict) element, for resize/move editing. */
284
+ srcDrawing?: XmlElement;
285
+ /** Native Office 3D model shown through its saved poster raster. */
286
+ model3D?: Model3DReference;
287
+ /** Word online-video metadata shown through its saved poster raster. */
288
+ webVideo?: WebVideoReference;
289
+ /** Embedded OLE package activated as a safe download in the browser. */
290
+ embeddedObject?: EmbeddedObjectReference;
291
+ }
292
+ interface Model3DReference {
293
+ part: string;
294
+ posterPart: string;
295
+ /** Native Office model orientation, in degrees around the X/Y/Z axes. */
296
+ rotation?: {
297
+ x: number;
298
+ y: number;
299
+ z: number;
300
+ };
301
+ }
302
+ interface WebVideoReference {
303
+ url: string;
304
+ embeddedHtml: string;
305
+ width: number;
306
+ height: number;
307
+ }
308
+ interface EmbeddedObjectReference {
309
+ part: string;
310
+ filename: string;
311
+ progId: string;
312
+ }
313
+ /** OMML equation node (subset: runs, scripts, fractions, radicals). */
314
+ type MathNode = ({
315
+ t: "run";
316
+ text: string;
317
+ normal?: boolean;
318
+ /** m:func function name (cos, log, …): Word kerns a thin space on
319
+ * both sides of the name. */
320
+ fname?: boolean;
321
+ /** The run's w:rPr color (hex, no #), strike and underline, when set:
322
+ * a redline marks an equation's runs with them. */
323
+ color?: string;
324
+ strike?: boolean;
325
+ underline?: string;
326
+ } | {
327
+ t: "sup" | "sub";
328
+ base: MathNode[];
329
+ script: MathNode[];
330
+ } | {
331
+ t: "frac";
332
+ num: MathNode[];
333
+ den: MathNode[];
334
+ bar?: boolean;
335
+ }
336
+ /** Radical; deg is the optional m:deg index (∛), absent when m:degHide. */
337
+ | {
338
+ t: "rad";
339
+ e: MathNode[];
340
+ deg?: MathNode[];
341
+ }
342
+ /** n-ary operator (sum/integral); chr defaults to the integral sign. */
343
+ | {
344
+ t: "nary";
345
+ chr: string;
346
+ sub: MathNode[];
347
+ sup: MathNode[];
348
+ e: MathNode[];
349
+ }
350
+ /** Delimiters grown to the content height; beg/end default to parens.
351
+ * An empty beg/end string means that side has no delimiter (cases "{"). */
352
+ | {
353
+ t: "dlm";
354
+ beg: string;
355
+ end: string;
356
+ e: MathNode[][];
357
+ }
358
+ /** Matrix: rows x cells. */
359
+ | {
360
+ t: "mat";
361
+ rows: MathNode[][][];
362
+ }
363
+ /** m:eqArr equation array (cases/piecewise rows). */
364
+ | {
365
+ t: "eqarr";
366
+ rows: MathNode[][];
367
+ }
368
+ /** m:acc combining accent (hat/bar/vector) over the base. */
369
+ | {
370
+ t: "acc";
371
+ chr: string;
372
+ e: MathNode[];
373
+ }
374
+ /** m:groupChr horizontal group character (over/under brace). */
375
+ | {
376
+ t: "grp";
377
+ chr: string;
378
+ pos: "top" | "bot";
379
+ vertJc: "top" | "bot";
380
+ e: MathNode[];
381
+ }
382
+ /** m:limLow / m:limUpp limit stacked under/over a text operator. */
383
+ | {
384
+ t: "lim";
385
+ pos: "low" | "upp";
386
+ e: MathNode[];
387
+ lim: MathNode[];
388
+ }) & {
389
+ /**
390
+ * The OMML element this node was read from. Only the math EDITOR's reader
391
+ * (edit/math.ts) sets it; the renderer's parser leaves it undefined. Editing
392
+ * re-emits through it, so the properties the linear syntax does not spell
393
+ * out — run fonts, m:ctrlPr, a matrix's column specs, an n-ary's limit
394
+ * placement — survive a text edit instead of being dropped.
395
+ */
396
+ src?: XmlElement;
397
+ };
398
+ interface MathContent {
399
+ kind: "math";
400
+ nodes: MathNode[];
401
+ /** Source m:oMath element (math editing). */
402
+ src?: XmlElement;
403
+ /** Display equation (wrapped in m:oMathPara): centered on its own line with
404
+ * display-style layout - larger n-ary operators with limits stacked
405
+ * above/below, and full-size fraction numerators/denominators. */
406
+ display?: boolean;
407
+ /** Display group with several direct equations. Word leaves a small
408
+ * advance after script clusters in these grouped displays. */
409
+ multiEquationDisplay?: boolean;
410
+ /** m:oMathParaPr/m:jc - display-equation justification. Absent: the
411
+ * document default (settings m:mathPr/m:defJc, itself "centerGroup" when
412
+ * unset). */
413
+ jc?: "left" | "right" | "center" | "centerGroup";
414
+ }
415
+ interface FieldContent {
416
+ kind: "field";
417
+ /** Raw field instruction, e.g. ` PAGE \\* MERGEFORMAT `. */
418
+ instruction: string;
419
+ /** Instruction text and nested fields in source order. `instruction` uses
420
+ * their stored results; layout evaluates these parts to build the code. */
421
+ instructionParts?: (string | FieldContent)[];
422
+ /** Last cached result text from the file, used for unsupported fields. */
423
+ cachedResult: string;
424
+ /** When this field is a legacy FORMCHECKBOX, the source `w:checkBox` element
425
+ * (in the fldChar begin's w:ffData). Its presence makes the rendered ballot
426
+ * box a click-to-toggle target; the glyph derives from its w:checked child. */
427
+ checkbox?: XmlElement;
428
+ /** The field's own XML: the `w:fldSimple`, or the `w:fldChar` begin of a
429
+ * complex field. The update pass (edit/update-fields.ts) writes a recomputed
430
+ * result back through it — layout resolves fields from this model, so
431
+ * without the link the computed value has nowhere to land in the file. */
432
+ src?: XmlElement;
433
+ }
434
+ /** What an anchored shape's coordinates are measured from. "char" (relH=
435
+ * "character") measures from the anchor run's pen position; "line" (relV=
436
+ * "line") from the top of the line holding the anchor — both resolved from
437
+ * the anchor paragraph's first-pass layout. */
438
+ type AnchorRel = "page" | "margin" | "text" | "column" | "char" | "line";
439
+ interface ShapeLine {
440
+ type: "line";
441
+ x1: number;
442
+ y1: number;
443
+ x2: number;
444
+ y2: number;
445
+ color: string;
446
+ /** Stroke weight px. */
447
+ weight: number;
448
+ style?: "single" | "dotted" | "dashed";
449
+ hRel: AnchorRel;
450
+ vRel: AnchorRel;
451
+ /** Source VML v:line for selection and save-back editing. */
452
+ src?: XmlElement;
453
+ }
454
+ interface ShapeTextbox {
455
+ type: "textbox";
456
+ x: number;
457
+ y: number;
458
+ width: number;
459
+ height: number;
460
+ hRel: AnchorRel;
461
+ vRel: AnchorRel;
462
+ blocks: Block[];
463
+ /** Background fill (CSS color) painted behind the text. */
464
+ fill?: string;
465
+ /** Outline. */
466
+ stroke?: {
467
+ color: string;
468
+ weight: number;
469
+ };
470
+ /** Alignment-based positioning (mso-position-horizontal/vertical). */
471
+ hAlign?: "left" | "center" | "right";
472
+ vAlign?: "top" | "center" | "bottom";
473
+ /** Percent-of-base geometry, 0..1 (mso-*-percent / wp14 pct offsets).
474
+ * Bases: pctWidthRel/pctHeightRel say page vs margin. */
475
+ pctX?: number;
476
+ pctY?: number;
477
+ pctWidth?: number;
478
+ pctHeight?: number;
479
+ pctWidthRel?: "page" | "margin";
480
+ pctHeightRel?: "page" | "margin";
481
+ /** Vertical anchoring of the text INSIDE the box (v-text-anchor). */
482
+ textAnchor?: "top" | "middle" | "bottom";
483
+ /** Text direction: clockwise top-to-bottom or counter-clockwise bottom-to-top. */
484
+ vert?: "vert" | "vert270";
485
+ /** How body text flows around a DrawingML textbox (wp:wrap*). */
486
+ wrap?: WrapMode;
487
+ /** behindDoc: paint under the body text, never displace it. */
488
+ behind?: boolean;
489
+ /** wp:anchor @allowOverlap="0": Word shifts this shape clear of earlier
490
+ * overlapping floats rather than letting them overlap. Default true. */
491
+ allowOverlap?: boolean;
492
+ /** Wrap distances px (wp:anchor distT/B/L/R). */
493
+ dist?: {
494
+ t: number;
495
+ b: number;
496
+ l: number;
497
+ r: number;
498
+ };
499
+ /** a:xfrm rotation, degrees clockwise (rotates the whole box). */
500
+ rotation?: number;
501
+ /** Text insets px (bodyPr lIns/tIns/rIns/bIns); default 9.6/4.8. For
502
+ * non-rect preset geometries these INCLUDE the geometry's text-rectangle
503
+ * insets (ellipse: inscribed rect; diamond: middle-half rect). */
504
+ insets?: {
505
+ l: number;
506
+ t: number;
507
+ r: number;
508
+ b: number;
509
+ };
510
+ /** Non-rect preset geometry: paint these outline paths (in a viewW x viewH
511
+ * space scaled to the shape box) instead of a rectangle. Each path carries
512
+ * its resolved fill colour (undefined = unfilled) and whether the shape's
513
+ * stroke applies to it. */
514
+ geom?: {
515
+ viewW: number;
516
+ viewH: number;
517
+ paths: {
518
+ d: string;
519
+ fill?: string;
520
+ stroke: boolean;
521
+ }[];
522
+ };
523
+ /** bodyPr a:noAutofit: the box does NOT grow with its text — Word hides
524
+ * whole lines that stick out past the shape bottom (phase23 p12 ovals:
525
+ * "Was 0 / B" visible, the wrapped tail rows hidden). */
526
+ clipText?: boolean;
527
+ /** bodyPr a:spAutoFit: the box grows in height to exactly fit its laid text
528
+ * plus the top/bottom insets (the stored cy is only Word's last cached
529
+ * value). Width is fixed. */
530
+ autofitHeight?: boolean;
531
+ /** bodyPr a:normAutofit — "shrink text on overflow". The mode is recorded
532
+ * because the fit report names it, NOT because it changes the layout:
533
+ * probe-shapefit measured fourteen normAutofit shapes through desktop Word
534
+ * and every one paints at its authored size and clips at the box bottom,
535
+ * exactly like a:noAutofit. `clipText` is set alongside this and is what the
536
+ * layout reads. */
537
+ shrinkText?: boolean;
538
+ /** Linked text-box chain id (wps:txbx/@id or wps:linkedTxbx/@id): boxes with
539
+ * the same id form one story. The seq-0 box (wps:txbx) holds the content;
540
+ * later boxes (wps:linkedTxbx, chainSeq>0) are empty sinks that continue the
541
+ * overflow. */
542
+ chainId?: string;
543
+ /** Position in the linked chain (0 = the content box). */
544
+ chainSeq?: number;
545
+ /** Source w:drawing element, attached at parse time so the shape's fill can
546
+ * be an interactive hit target (select the shape instead of the body text
547
+ * behind it). */
548
+ srcDrawing?: XmlElement;
549
+ /** Header/footer-owned textbox whose text is edited as an independent story. */
550
+ textboxStory?: boolean;
551
+ /** DrawingML WordArt, including the identity textNoShape preset. */
552
+ wordArt?: boolean;
553
+ /** WordArt glyph fill from w14:textFill or the fallback run color. */
554
+ wordArtFill?: string;
555
+ /** WordArt glyph alpha, 0..1. */
556
+ wordArtOpacity?: number;
557
+ /** bodyPr a:prstTxWarp preset name (textArchUp, textWave1, textChevron,
558
+ * textCirclePour, …): the shape's text is bent onto the preset's envelope
559
+ * rather than flowed as ordinary lines. "textNoShape" (no warp) is dropped. */
560
+ warp?: string;
561
+ }
562
+ /** WordArt (VML v:textpath, e.g. a "CONFIDENTIAL" watermark): text scaled to
563
+ * fill a box, optionally rotated, painted semi-transparent behind the body. */
564
+ interface ShapeWordArt {
565
+ type: "wordart";
566
+ text: string;
567
+ fontFamily: string;
568
+ bold?: boolean;
569
+ italic?: boolean;
570
+ /** CSS fill color. */
571
+ fill: string;
572
+ /** 0..1 alpha. */
573
+ opacity: number;
574
+ x: number;
575
+ y: number;
576
+ width: number;
577
+ height: number;
578
+ hRel: AnchorRel;
579
+ vRel: AnchorRel;
580
+ hAlign?: "left" | "center" | "right";
581
+ vAlign?: "top" | "center" | "bottom";
582
+ /** Clockwise degrees. */
583
+ rotation: number;
584
+ behind?: boolean;
585
+ /** The source v:textpath font-size (px). */
586
+ fontSize?: number;
587
+ /** The referenced v:shapetype has a malformed text-guide path (missing
588
+ * coordinates), so Word collapses its horizontal glyph outlines into a thin
589
+ * vertical band instead of painting a box-filling watermark. */
590
+ noFit?: boolean;
591
+ /** Source VML shape element (v:shape / v:rect) for interactive editing:
592
+ * the v:textpath string, fill/opacity, and rotation live under it. */
593
+ src?: XmlElement;
594
+ }
595
+ interface ShapeArt {
596
+ type: "art";
597
+ srcDrawing?: XmlElement;
598
+ /** A freehand stroke, selectable by the Draw ribbon's stroke eraser. */
599
+ ink?: boolean;
600
+ x: number;
601
+ y: number;
602
+ /** Percent-of-page offsets (wp14:pctPos*Offset), 0..1. */
603
+ pctX?: number;
604
+ pctY?: number;
605
+ width: number;
606
+ height: number;
607
+ hRel: AnchorRel;
608
+ vRel: AnchorRel;
609
+ hAlign?: "left" | "center" | "right";
610
+ vAlign?: "top" | "center" | "bottom";
611
+ behind?: boolean;
612
+ /** a:xfrm rotation, degrees clockwise. */
613
+ rotation?: number;
614
+ /** wp:wrapSquare/.../wrapTopAndBottom on the anchor (w10:wrap on a VML
615
+ * group): text wraps around the art as around a text box. */
616
+ wrap?: WrapMode;
617
+ /** wp:anchor dist* in px, used with `wrap`. */
618
+ dist?: {
619
+ t: number;
620
+ b: number;
621
+ l: number;
622
+ r: number;
623
+ };
624
+ lines: DrawingLine[];
625
+ images: DrawingImage[];
626
+ paths: DrawingPath[];
627
+ /** Positioned text bodies inside the group (wps textboxes, dsp:sp txBody). */
628
+ texts?: DrawingTextShape[];
629
+ }
630
+ /** How text interacts with a floating image. */
631
+ type WrapMode = "square" | "topAndBottom" | "none";
632
+ interface ShapeImage {
633
+ type: "image";
634
+ part: string;
635
+ /** Offset from the anchor origin, px. */
636
+ x: number;
637
+ y: number;
638
+ width: number;
639
+ height: number;
640
+ hRel: AnchorRel;
641
+ vRel: AnchorRel;
642
+ /** Horizontal alignment when the file uses wp:align instead of an offset. */
643
+ hAlign?: "left" | "center" | "right";
644
+ /** Vertical alignment keyword (VML mso-position-vertical; watermarks center). */
645
+ vAlign?: "top" | "center" | "bottom";
646
+ wrap: WrapMode;
647
+ /** behindDoc anchors render under the text and never displace it. */
648
+ behind?: boolean;
649
+ /** Wrap distances px (wp:anchor distT/B/L/R); text clears the image by these. */
650
+ dist?: {
651
+ t: number;
652
+ b: number;
653
+ l: number;
654
+ r: number;
655
+ };
656
+ crop?: {
657
+ l: number;
658
+ t: number;
659
+ r: number;
660
+ b: number;
661
+ };
662
+ rotation?: number;
663
+ /** Watermark "washout" recolor (VML v:imagedata gain/blacklevel, 0..1). */
664
+ washout?: {
665
+ gain: number;
666
+ blacklevel: number;
667
+ };
668
+ /** Source w:drawing element (editing). */
669
+ srcDrawing?: XmlElement;
670
+ model3D?: Model3DReference;
671
+ webVideo?: WebVideoReference;
672
+ embeddedObject?: EmbeddedObjectReference;
673
+ }
674
+ type Shape = (ShapeLine | ShapeTextbox | ShapeImage | ShapeArt | ShapeWordArt) & {
675
+ /** wp:anchor relativeHeight, used for object stacking order. */
676
+ z?: number;
677
+ /** Print with markup only: the shape's run is a tracked change, so the
678
+ * layout frames the shape's box in the author's color, struck through
679
+ * when the change is a deletion or a move away. The balloon and the
680
+ * change bar come from the run's changes, at the anchor's line. */
681
+ revision?: {
682
+ color: string;
683
+ struck: boolean;
684
+ };
685
+ };
686
+ /**
687
+ * Floating/anchored object: does not occupy inline space; positioned against
688
+ * page/margin/paragraph during layout. (How classic pleading paper draws its
689
+ * margin line numbers and vertical rules.)
690
+ */
691
+ interface AnchorContent {
692
+ kind: "anchor";
693
+ shape: Shape;
694
+ }
695
+ /** A stroked segment inside a composite drawing, px relative to its box. */
696
+ interface DrawingLine {
697
+ x1: number;
698
+ y1: number;
699
+ x2: number;
700
+ y2: number;
701
+ color: string;
702
+ weight: number;
703
+ style?: "single" | "dotted" | "dashed";
704
+ }
705
+ interface DrawingImage {
706
+ part: string;
707
+ x: number;
708
+ y: number;
709
+ width: number;
710
+ height: number;
711
+ crop?: {
712
+ l: number;
713
+ t: number;
714
+ r: number;
715
+ b: number;
716
+ };
717
+ rotation?: number;
718
+ /** a:ln picture outline (Word draws it just outside the image). */
719
+ border?: {
720
+ color: string;
721
+ width: number;
722
+ };
723
+ }
724
+ /**
725
+ * Composite inline drawing (DrawingML groups): vector lines + placed images
726
+ * inside a width×height box that flows like an image.
727
+ */
728
+ interface DrawingContent {
729
+ kind: "drawing";
730
+ width: number;
731
+ height: number;
732
+ lines: DrawingLine[];
733
+ images: DrawingImage[];
734
+ /** Native ChartML chart data resolved from the related chart part. */
735
+ chart?: ChartData;
736
+ /** Native SmartArt diagram data resolved from its diagram parts. */
737
+ smartArt?: SmartArtData;
738
+ /** Freeform vector shapes (a:custGeom), as SVG path data. */
739
+ paths?: DrawingPath[];
740
+ /** An INLINE wps text box (wp:inline wps:txbx): a fixed-extent box that
741
+ * flows in the text (occupying its width x height like an inline image) and
742
+ * carries a fill/border + its own block content. Distinct from the floating
743
+ * ShapeTextbox, which is absolutely placed via a wp:anchor. */
744
+ textbox?: {
745
+ blocks: Block[];
746
+ fill?: string;
747
+ stroke?: {
748
+ color: string;
749
+ weight: number;
750
+ };
751
+ insets?: {
752
+ l: number;
753
+ t: number;
754
+ r: number;
755
+ b: number;
756
+ };
757
+ textAnchor?: "top" | "middle" | "bottom";
758
+ };
759
+ /** Source w:drawing element (select/move as a group). */
760
+ srcDrawing?: XmlElement;
761
+ /** Positioned text bodies inside the drawing (multi-textbox groups and
762
+ * SmartArt cached-drawing shapes). Painted above lines/paths. */
763
+ texts?: DrawingTextShape[];
764
+ }
765
+ /** The c:chartSpace plot kinds the renderer paints. Anything else (3-D, radar,
766
+ * surface, stock, bubble) parses with `unsupported` set instead. */
767
+ type ChartType = "column" | "bar" | "line" | "pie" | "doughnut" | "area" | "scatter";
768
+ interface ChartSeries {
769
+ name: string;
770
+ values: number[];
771
+ /** c:xVal of a scatter series. Every other type shares one category axis,
772
+ * so only scatter carries per-series x values. */
773
+ xValues?: number[];
774
+ /** Explicit series fill/line from c:spPr, overriding the palette slot. */
775
+ color?: string;
776
+ /** Explicit c:dPt fills, keyed by point index (pie slices, single bars). */
777
+ pointColors?: Record<number, string>;
778
+ /** c:smooth — draw the line series through a spline instead of segments. */
779
+ smooth?: boolean;
780
+ /** c:spPr/a:ln/@w, in px. A line or scatter series says here how heavy its
781
+ * stroke is; a scatter series, whose stroke is optional, says it has one. */
782
+ lineWidth?: number;
783
+ /** c:marker/c:symbol, an ST_MarkerStyle name. "none" draws no marker, and a
784
+ * name with no shape behind it takes the series' slot in Word's sequence. */
785
+ markerSymbol?: string;
786
+ /** c:marker/c:size, the width across the marker in px. */
787
+ markerSize?: number;
788
+ }
789
+ type ChartTickMark = "none" | "in" | "out" | "cross";
790
+ /** One axis of a 2-D chart (c:catAx/c:valAx/c:dateAx). */
791
+ interface ChartAxis {
792
+ /** c:delete val="1": Word draws no line, ticks or labels for the axis. */
793
+ hidden?: boolean;
794
+ /** A c:majorGridlines child is present. */
795
+ gridlines?: boolean;
796
+ /** c:numFmt formatCode applied to the tick labels, e.g. "0.0%". */
797
+ format?: string;
798
+ title?: string;
799
+ /** c:scaling overrides of the automatic scale. */
800
+ min?: number;
801
+ max?: number;
802
+ majorUnit?: number;
803
+ /** c:scaling/c:orientation val="maxMin". */
804
+ reversed?: boolean;
805
+ /** c:majorTickMark / c:minorTickMark. The schema default is "out" for major
806
+ * and "none" for minor; Word writes both explicitly. */
807
+ majorTick?: ChartTickMark;
808
+ minorTick?: ChartTickMark;
809
+ /** c:tickLblPos val="none" keeps the axis but drops its labels. */
810
+ labels?: boolean;
811
+ /** c:crossBetween on a value axis, which decides where the category axis puts
812
+ * its points: "between" insets them by half a category (Word's choice for
813
+ * bar and column), "midCat" seats the first and last on the plot's edges
814
+ * (Word's choice for line and area). */
815
+ crossBetween?: "between" | "midCat";
816
+ }
817
+ interface ChartData {
818
+ type: ChartType;
819
+ /** Local name of a plot the renderer does not paint (bar3DChart, radarChart,
820
+ * …). When set, `type` is a placeholder and the renderer draws a labeled box
821
+ * rather than pretending the data is a column chart. */
822
+ unsupported?: string;
823
+ title?: string;
824
+ categories: string[];
825
+ series: ChartSeries[];
826
+ /** c:grouping — how bar/column/area series stack. */
827
+ grouping?: "clustered" | "stacked" | "percentStacked";
828
+ /** Legend edge. Absent when the chart has no c:legend. */
829
+ legend?: "l" | "r" | "t" | "b" | "tr";
830
+ /** c:dLbls showVal on the plot or on every series. */
831
+ dataLabels?: boolean;
832
+ /** c:varyColors — give each point of a single series its own palette slot. */
833
+ varyColors?: boolean;
834
+ categoryAxis?: ChartAxis;
835
+ valueAxis?: ChartAxis;
836
+ /** c:holeSize percent of a doughnut (Word's default is 75). */
837
+ holeSize?: number;
838
+ /** c:gapWidth percent between bar/column categories (Word's default is 150). */
839
+ gapWidth?: number;
840
+ /** c:overlap percent between bars of one category (Word: -27 clustered,
841
+ * 100 stacked). */
842
+ overlap?: number;
843
+ /** c:marker val="1" on a line chart: draw a point marker at each value. */
844
+ markers?: boolean;
845
+ /** Font size in px from c:title//a:defRPr@sz. Word's default title is 14pt. */
846
+ titleSize?: number;
847
+ /** Font size in px from c:txPr//a:defRPr@sz, the chart-wide text size. Word's
848
+ * default for axis labels, legend entries and data labels is 9pt. */
849
+ textSize?: number;
850
+ }
851
+ type SmartArtLayout = "process" | "cycle" | "hierarchy" | "list";
852
+ interface SmartArtData {
853
+ layout: SmartArtLayout;
854
+ items: string[];
855
+ }
856
+ /** A text body positioned inside a composite drawing (a wps textbox in a
857
+ * group, or a SmartArt dsp:sp txBody), px relative to the drawing's box. */
858
+ interface DrawingTextShape {
859
+ x: number;
860
+ y: number;
861
+ width: number;
862
+ height: number;
863
+ blocks: Block[];
864
+ /** Background fill painted behind the text box. */
865
+ fill?: string;
866
+ /** Outline. */
867
+ stroke?: {
868
+ color: string;
869
+ weight: number;
870
+ };
871
+ /** Text insets px (bodyPr lIns/tIns/rIns/bIns). */
872
+ insets: {
873
+ l: number;
874
+ t: number;
875
+ r: number;
876
+ b: number;
877
+ };
878
+ /** Vertical anchoring of the text inside the box (bodyPr anchor). */
879
+ textAnchor?: "top" | "middle" | "bottom";
880
+ /** DrawingML cached text paint-only baseline adjustment in px. */
881
+ paintOffsetY?: number;
882
+ }
883
+ interface DrawingPath {
884
+ /** Position/size inside the drawing, px. */
885
+ x: number;
886
+ y: number;
887
+ width: number;
888
+ height: number;
889
+ /** SVG path in the `viewW x viewH` source coordinate space. */
890
+ d: string;
891
+ viewW: number;
892
+ viewH: number;
893
+ fill?: string;
894
+ stroke?: {
895
+ color: string;
896
+ width: number;
897
+ opacity?: number;
898
+ };
899
+ /** Zero-based visible SmartArt node this path paints. */
900
+ smartArtNodeIndex?: number;
901
+ }
902
+ /**
903
+ * Footnote/endnote reference mark. In body text (w:footnoteReference /
904
+ * w:endnoteReference) `id` points into the notes part. Inside a note body,
905
+ * w:footnoteRef / w:endnoteRef render the note's own mark: `self` is true and
906
+ * `id` is meaningless.
907
+ */
908
+ interface NoteRefContent {
909
+ kind: "noteRef";
910
+ noteType: "footnote" | "endnote";
911
+ id: number;
912
+ self?: boolean;
913
+ /** The document supplies the visible mark in the following run content. */
914
+ customMarkFollows?: boolean;
915
+ }
916
+ /** w:ruby — an East-Asian ruby (furigana) cluster: an annotation run (w:rt)
917
+ * riding above a base run (w:rubyBase). Both sides render as their own runs;
918
+ * the annotation is centered over the base and raised above its baseline. */
919
+ interface RubyContent {
920
+ kind: "ruby";
921
+ base: Run;
922
+ rt: Run;
923
+ /** w:rubyPr/w:hpsRaise — annotation baseline raise above the base baseline,
924
+ * half-points. */
925
+ hpsRaise?: number;
926
+ /** w:rubyPr/w:rubyAlign — how the annotation distributes over the base. */
927
+ align?: "center" | "distributeLetter" | "distributeSpace" | "left" | "right" | "rightVertical";
928
+ }
929
+ type RunContent = MathContent | TextContent | BreakContent | TabContent | PTabContent | ImageContent | FieldContent | AnchorContent | DrawingContent | NoteRefContent | RubyContent;
930
+ /**
931
+ * A tracked change a printed markup page shows beside its text (see
932
+ * pdf/comments.ts): what it is, in Word's words, and who made it when.
933
+ * Set only when the document is parsed for print with author colors.
934
+ */
935
+ interface Revision {
936
+ /** Unique over the document: the element's kind and w:id. */
937
+ id: string;
938
+ kind: "ins" | "del" | "moveTo" | "moveFrom" | "format";
939
+ author: string;
940
+ /** ISO timestamp from w:date, verbatim. */
941
+ date?: string;
942
+ /** The balloon's text: "Inserted", "Deleted", "Moved from", "Moved to",
943
+ * "Inserted row", "Deleted row", "Formatted: Font: Bold", ... */
944
+ label: string;
945
+ }
946
+ interface Run {
947
+ type: "run";
948
+ props: RunProps;
949
+ content: RunContent[];
950
+ /** Source w:r element. */
951
+ src?: XmlElement;
952
+ /** The tracked changes this run is part of, or whose balloon anchors at
953
+ * it (a paragraph's, row's or table's format change is put on each of its
954
+ * runs). Print with markup only. */
955
+ changes?: Revision[];
956
+ /** Element whose children array contains src (w:p, w:hyperlink, …). */
957
+ srcParent?: XmlElement;
958
+ }
959
+ interface Hyperlink {
960
+ type: "hyperlink";
961
+ href?: string;
962
+ anchor?: string;
963
+ /** Complex HYPERLINK whose target contains nested fields. */
964
+ field?: FieldContent;
965
+ runs: Run[];
966
+ }
967
+ type ParaChild = Run | Hyperlink;
968
+ interface Paragraph {
969
+ type: "paragraph";
970
+ props: ParaProps;
971
+ children: ParaChild[];
972
+ /** Section break attached to this paragraph's pPr (ends a section). */
973
+ sectionBreak?: SectionProps;
974
+ /** w:bookmarkStart names in this paragraph (PAGEREF targets). */
975
+ bookmarks?: string[];
976
+ /** Final revision view: the paragraph mark AND all content are tracked
977
+ * deletions — the paragraph does not exist (no line, no numbering). */
978
+ revisionHidden?: boolean;
979
+ /** Markup view: the paragraph mark itself is a tracked insertion or
980
+ * deletion (a suggested line break, or a suggested merge). Layout draws it
981
+ * as a pilcrow in the revision's colors after the paragraph's content; it is
982
+ * not text, so find, word count and the like never see it. */
983
+ markRevision?: "ins" | "del";
984
+ /** The mark's pilcrow color when the markup is printed with author colors. */
985
+ markRevisionColor?: string;
986
+ /** Print with markup only: the tracked changes anchored at the paragraph
987
+ * mark, which the layout's mark run carries so they get a balloon and a
988
+ * change bar — the mark's own insertion or deletion, and the body's final
989
+ * section change (w:sectPrChange) on the last paragraph. */
990
+ markChanges?: Revision[];
991
+ /** Source w:p element. */
992
+ src?: XmlElement;
993
+ }
994
+ interface TableCellProps {
995
+ /** Preferred width px (from tcW when dxa). */
996
+ width?: number;
997
+ /** Preferred width as a fraction of the table width (from tcW when pct). */
998
+ widthPct?: number;
999
+ /** The source explicitly declares tcW type="auto" (distinct from no tcW). */
1000
+ widthAuto?: boolean;
1001
+ gridSpan: number;
1002
+ vMerge?: "restart" | "continue";
1003
+ borders?: {
1004
+ top?: Border;
1005
+ bottom?: Border;
1006
+ left?: Border;
1007
+ right?: Border;
1008
+ tl2br?: Border;
1009
+ tr2bl?: Border;
1010
+ };
1011
+ shading?: string;
1012
+ /** Cell margins px. */
1013
+ margins?: {
1014
+ top?: number;
1015
+ right?: number;
1016
+ bottom?: number;
1017
+ left?: number;
1018
+ };
1019
+ verticalAlign?: "top" | "center" | "bottom";
1020
+ textDirection?: "btLr" | "tbRl";
1021
+ }
1022
+ interface TableCell {
1023
+ props: TableCellProps;
1024
+ blocks: Block[];
1025
+ }
1026
+ interface TableRowProps {
1027
+ /** Empty grid columns before/after the row's cells. */
1028
+ gridBefore?: number;
1029
+ gridAfter?: number;
1030
+ /** Preferred widths in px of the omitted columns (wBefore/wAfter). */
1031
+ widthBefore?: number;
1032
+ widthAfter?: number;
1033
+ /** px; undefined = auto */
1034
+ height?: number;
1035
+ heightRule?: "auto" | "atLeast" | "exact";
1036
+ cantSplit?: boolean;
1037
+ /** Repeat as header row on each page. */
1038
+ tblHeader?: boolean;
1039
+ }
1040
+ interface TableRow {
1041
+ props: TableRowProps;
1042
+ cells: TableCell[];
1043
+ }
1044
+ interface TableProps {
1045
+ styleId?: string;
1046
+ /** px table indent from left margin. */
1047
+ indent?: number;
1048
+ alignment?: Alignment;
1049
+ /** w:bidiVisual — RTL table: column order reverses and the table hugs the
1050
+ * right margin. */
1051
+ bidiVisual?: boolean;
1052
+ borders?: {
1053
+ top?: Border;
1054
+ bottom?: Border;
1055
+ left?: Border;
1056
+ right?: Border;
1057
+ insideH?: Border;
1058
+ insideV?: Border;
1059
+ };
1060
+ /** Default cell margins px. */
1061
+ cellMargins?: {
1062
+ top?: number;
1063
+ right?: number;
1064
+ bottom?: number;
1065
+ left?: number;
1066
+ };
1067
+ /** w:tblCellSpacing px — old-style separated cell borders: every cell gets
1068
+ * its own border box inset by this much from the grid slot on all sides
1069
+ * (adjacent cells end up 2x apart), and the table outline is a separate box
1070
+ * around everything. */
1071
+ cellSpacing?: number;
1072
+ /** w:tblpPr — floating table: absolutely positioned against page/margin/
1073
+ * column, painted over an opaque white sheet, with body text (including
1074
+ * text EARLIER in the flow on the same page) wrapping square around it. */
1075
+ floating?: {
1076
+ hAnchor: "page" | "margin" | "text";
1077
+ vAnchor: "page" | "margin" | "text";
1078
+ /** tblpX/tblpY px (absent when an alignment keyword is used). */
1079
+ x?: number;
1080
+ y?: number;
1081
+ xAlign?: "left" | "center" | "right";
1082
+ yAlign?: "top" | "center" | "bottom";
1083
+ /** Wrap distances px (leftFromText, …). */
1084
+ dist: {
1085
+ l: number;
1086
+ r: number;
1087
+ t: number;
1088
+ b: number;
1089
+ };
1090
+ /** w:tblOverlap "never": shift clear of earlier floating tables. */
1091
+ allowOverlap: boolean;
1092
+ };
1093
+ /** Preferred total width px (tblW dxa) or undefined for auto. */
1094
+ width?: number;
1095
+ /** Preferred total width as a fraction of available width (tblW pct). */
1096
+ widthPct?: number;
1097
+ layout?: "fixed" | "autofit";
1098
+ /** w:tblLook flags controlling which conditional formats apply. */
1099
+ tblLook?: TableLook;
1100
+ }
1101
+ /** w:tblLook flags controlling which conditional table-style formats apply. */
1102
+ interface TableLook {
1103
+ firstRow: boolean;
1104
+ lastRow: boolean;
1105
+ firstColumn: boolean;
1106
+ lastColumn: boolean;
1107
+ noHBand: boolean;
1108
+ noVBand: boolean;
1109
+ }
1110
+ interface Table {
1111
+ type: "table";
1112
+ props: TableProps;
1113
+ /** Column grid widths px (tblGrid). */
1114
+ grid: number[];
1115
+ rows: TableRow[];
1116
+ /** Source w:tbl element. */
1117
+ src?: XmlElement;
1118
+ }
1119
+ type Block = Paragraph | Table;
1120
+ interface HeaderFooterRefs {
1121
+ default?: string;
1122
+ first?: string;
1123
+ even?: string;
1124
+ }
1125
+ interface ColumnSpec {
1126
+ count: number;
1127
+ /** Space between columns px. */
1128
+ space: number;
1129
+ /** Explicit widths px when equalWidth=false. */
1130
+ widths?: number[];
1131
+ /** Per-column trailing space px (w:col w:space), when explicit w:col
1132
+ * entries are present. spaces[i] separates column i from column i+1. */
1133
+ spaces?: number[];
1134
+ /** w:cols w:sep: paint a vertical rule centered in each inter-column gap. */
1135
+ sep?: boolean;
1136
+ }
1137
+ interface SectionProps {
1138
+ pageWidth: number;
1139
+ pageHeight: number;
1140
+ marginTop: number;
1141
+ marginRight: number;
1142
+ marginBottom: number;
1143
+ marginLeft: number;
1144
+ /** Distance of header top from page top, px (w:headerReference distance). */
1145
+ headerDistance: number;
1146
+ footerDistance: number;
1147
+ gutter: number;
1148
+ headerRefs: HeaderFooterRefs;
1149
+ footerRefs: HeaderFooterRefs;
1150
+ /** Different first-page header/footer enabled. */
1151
+ titlePage: boolean;
1152
+ /** Page numbering restart value, if set. */
1153
+ pageNumberStart?: number;
1154
+ pageNumberFormat?: string;
1155
+ columns: ColumnSpec;
1156
+ /** w:docGrid type=lines/linesAndChars: minimum single-line height (px) that
1157
+ * the line-spacing multiplier is applied over. Word snaps every line's font
1158
+ * height up to this grid pitch (CJK documents). */
1159
+ docGridLinePitch?: number;
1160
+ /** Present w:docGrid type; omitted w:type means "default". */
1161
+ docGridType?: "default" | "lines" | "linesAndChars" | "snapToChars";
1162
+ /** w:docGrid type="charsAndLines": a combined char+line grid that (in compat
1163
+ * 15) keeps natural East-Asian line pitch. Drives the CJK line-height
1164
+ * correction during measurement. */
1165
+ docGridCharGrid?: boolean;
1166
+ type?: "nextPage" | "continuous" | "evenPage" | "oddPage" | "nextColumn";
1167
+ /** Vertical alignment of page content. */
1168
+ vAlign?: "top" | "center" | "both" | "bottom";
1169
+ /** w:pgBorders. Offsets (border.space, px) measure from text or page edge. */
1170
+ pageBorders?: {
1171
+ top?: Border;
1172
+ bottom?: Border;
1173
+ left?: Border;
1174
+ right?: Border;
1175
+ offsetFrom: "text" | "page";
1176
+ };
1177
+ /** w:lnNumType: margin line numbering. distance px from the text edge.
1178
+ * start is the raw w:start OFFSET (0 when the attribute is absent, its
1179
+ * literal value otherwise) added to the running per-line count — see
1180
+ * parse/section.ts for why an absent attribute isn't just "start 1". */
1181
+ lineNumbering?: {
1182
+ countBy: number;
1183
+ start: number;
1184
+ distance: number;
1185
+ restart: "continuous" | "newPage" | "newSection";
1186
+ };
1187
+ /** Footnote/endnote mark numbering (w:footnotePr / w:endnotePr). */
1188
+ footnoteNumFmt?: string;
1189
+ footnoteNumStart?: number;
1190
+ endnoteNumFmt?: string;
1191
+ endnoteNumStart?: number;
1192
+ /** w:numRestart: when the mark counter resets. Absent means "continuous"
1193
+ * (the whole document shares one counter — this engine's only honored
1194
+ * value; eachSect/eachPage are round-trip preserved but not laid out). */
1195
+ footnoteNumRestart?: "continuous" | "eachSect" | "eachPage";
1196
+ endnoteNumRestart?: "continuous" | "eachSect" | "eachPage";
1197
+ /** w:pos: where the note text is placed. Round-trip preserved only — the
1198
+ * layout always places footnotes at the page bottom and endnotes at the
1199
+ * document end, regardless of this value. */
1200
+ footnotePos?: "pageBottom" | "beneathText";
1201
+ endnotePos?: "sectEnd" | "docEnd";
1202
+ /** w:textDirection tbRl: the whole section flows as East-Asian vertical
1203
+ * writing — lines run top-to-bottom, progressing right-to-left. */
1204
+ textDirection?: "tbRl";
1205
+ }
1206
+ interface Section {
1207
+ props: SectionProps;
1208
+ blocks: Block[];
1209
+ }
1210
+ /** A review comment from word/comments.xml. */
1211
+ interface DocComment {
1212
+ id: string;
1213
+ author: string;
1214
+ initials?: string;
1215
+ /** ISO timestamp from w:date, verbatim. */
1216
+ date?: string;
1217
+ /** Plain text of the comment body (paragraphs joined with newlines). */
1218
+ text: string;
1219
+ /** w14:paraId of the comment's last body paragraph (threading key). */
1220
+ paraId?: string;
1221
+ /** Parent comment id when this comment is a reply (commentsExtended). */
1222
+ parentId?: string;
1223
+ /** Thread resolved (w15:commentEx w15:done="1" — the [MS-DOCX] CT_CommentEx
1224
+ * extension; ECMA-376 itself has no resolved state). Meaningful on the
1225
+ * thread parent; Word grays the whole thread from the parent's flag. */
1226
+ resolved?: boolean;
1227
+ }
1228
+ /** A reviewer from word/people.xml (w15:person): the display name, and the
1229
+ * identity the presence provider knows them by (w15:presenceInfo). */
1230
+ interface DocPerson {
1231
+ author: string;
1232
+ providerId?: string;
1233
+ userId?: string;
1234
+ }
1235
+ /** A font file the package embeds (word/fonts/*.odttf), from fontTable.xml:
1236
+ * a w:font's w:embedRegular, w:embedBold, w:embedItalic or w:embedBoldItalic. */
1237
+ interface DocEmbeddedFont {
1238
+ /** The family the document names (w:font w:name). */
1239
+ family: string;
1240
+ bold: boolean;
1241
+ italic: boolean;
1242
+ /** The package part that holds the file. */
1243
+ part: string;
1244
+ /** The w:fontKey GUID the file is obfuscated with (ECMA-376 Part 1
1245
+ * §17.8.1); absent when the file is a plain font. */
1246
+ key?: string;
1247
+ }
1248
+ interface HeaderFooter {
1249
+ blocks: Block[];
1250
+ }
1251
+ /** One w:tblStylePr conditional-formatting block (firstRow, band1Horz, …). */
1252
+ interface TableCondFormat {
1253
+ /** Cell shading fill as CSS color. */
1254
+ shd?: string;
1255
+ /** Conditional cell borders. */
1256
+ borders?: {
1257
+ top?: Border;
1258
+ bottom?: Border;
1259
+ left?: Border;
1260
+ right?: Border;
1261
+ insideH?: Border;
1262
+ insideV?: Border;
1263
+ };
1264
+ /** Conditional run bold (firstRow/firstCol headers). */
1265
+ bold?: boolean;
1266
+ /** Full conditional run props (w:tblStylePr > w:rPr). */
1267
+ rPr?: RunProps;
1268
+ }
1269
+ type TableCondType = "wholeTable" | "band1Vert" | "band2Vert" | "band1Horz" | "band2Horz" | "firstRow" | "lastRow" | "firstCol" | "lastCol" | "nwCell" | "neCell" | "swCell" | "seCell";
1270
+ interface Style {
1271
+ id: string;
1272
+ type: "paragraph" | "character" | "table" | "numbering";
1273
+ name?: string;
1274
+ basedOn?: string;
1275
+ isDefault?: boolean;
1276
+ pPr?: ParaProps;
1277
+ rPr?: RunProps;
1278
+ tblPr?: TableProps;
1279
+ /** w:tblStylePr conditional formats, by type (table styles only). */
1280
+ condFormats?: Map<TableCondType, TableCondFormat>;
1281
+ /** w:tblStyleRowBandSize / ColBandSize (default 1). */
1282
+ rowBandSize?: number;
1283
+ colBandSize?: number;
1284
+ }
1285
+ interface Styles {
1286
+ byId: Map<string, Style>;
1287
+ defaultParagraphStyle?: string;
1288
+ defaultRPr: RunProps;
1289
+ defaultPPr: ParaProps;
1290
+ }
1291
+ interface NumberingLevel {
1292
+ ilvl: number;
1293
+ start: number;
1294
+ format: string;
1295
+ /** Template like "%1." */
1296
+ text: string;
1297
+ alignment: Alignment;
1298
+ /** Paragraph props contributed by the level (indents). */
1299
+ pPr?: ParaProps;
1300
+ rPr?: RunProps;
1301
+ suffix: "tab" | "space" | "nothing";
1302
+ restartAfter?: number;
1303
+ }
1304
+ interface AbstractNum {
1305
+ id: number;
1306
+ levels: Map<number, NumberingLevel>;
1307
+ numStyleLink?: string;
1308
+ }
1309
+ interface NumInstance {
1310
+ numId: number;
1311
+ abstractNumId: number;
1312
+ overrides: Map<number, {
1313
+ startOverride?: number;
1314
+ level?: NumberingLevel;
1315
+ }>;
1316
+ }
1317
+ interface Numbering {
1318
+ abstract: Map<number, AbstractNum>;
1319
+ instances: Map<number, NumInstance>;
1320
+ }
1321
+ interface Theme {
1322
+ majorFont: string;
1323
+ minorFont: string;
1324
+ majorBidiFont?: string;
1325
+ minorBidiFont?: string;
1326
+ /** East Asian faces from theme <a:ea> (fontScheme major/minorFont). Word's
1327
+ * eastAsiaTheme="minor/majorEastAsia" resolves through these, NOT the Latin
1328
+ * minor/major font — routing a CJK run's theme reference to the Latin face
1329
+ * (Calibri) leaves East Asian text in a glyphless Latin font. */
1330
+ majorEastAsiaFont?: string;
1331
+ minorEastAsiaFont?: string;
1332
+ colors: Map<string, string>;
1333
+ }
1334
+
1335
+ /** A read-only view over the OPC (zip) package inside a .docx file. */
1336
+ declare class Package {
1337
+ private files;
1338
+ /** Every entry is held to ZipBudget before any is inflated. fflate
1339
+ * inflates an entry into a buffer of the size the directory gives, so an
1340
+ * entry whose data holds more stops there: memory stays within the
1341
+ * budget, and the entry fails, or comes out cut short (an XML part then
1342
+ * fails to parse). */
1343
+ constructor(data: Uint8Array);
1344
+ static from(data: ArrayBuffer | Uint8Array): Package;
1345
+ /** A package over an already-unzipped entry map (DocxDocument.clone). */
1346
+ static fromFiles(files: Record<string, Uint8Array>): Package;
1347
+ has(name: string): boolean;
1348
+ binary(name: string): Uint8Array | undefined;
1349
+ text(name: string): string | undefined;
1350
+ names(): string[];
1351
+ /** Raw entry map (shared, do not mutate) — used for write-back. */
1352
+ raw(): Record<string, Uint8Array>;
1353
+ /** OPC part names never start with '/' inside the zip; tolerate both. */
1354
+ private normalize;
1355
+ }
1356
+
1357
+ /**
1358
+ * Stable node identity for replicated editing.
1359
+ *
1360
+ * Positions on the wire cannot be object references, and numeric child paths
1361
+ * shift under concurrent structural edits — so blocks (w:p, w:tbl) and runs
1362
+ * (w:r) get stable numeric ids held in an in-memory side table. The table is
1363
+ * identity-keyed and NEVER serialized into the XML: writing ids as attributes
1364
+ * would dirty every part on open and break the byte-identical round-trip
1365
+ * guarantee for untouched parts.
1366
+ *
1367
+ * Assignment is deterministic: a document-order walk over the given roots,
1368
+ * so two replicas that parse the same document derive the same table. Nodes
1369
+ * created later by edits get ids explicitly (locally via `assign`, or from a
1370
+ * replicated edit that carries the originating client's allocation) — a
1371
+ * re-walk after edits only fills gaps and never renumbers survivors, because
1372
+ * the table is keyed by element identity and in-place XML mutation preserves
1373
+ * identity across `refresh()`.
1374
+ */
1375
+ type StableId = number;
1376
+ interface EncodedCaret {
1377
+ blockId: StableId;
1378
+ runId: StableId;
1379
+ /** Offset in the run's WIRE space: cumulative through the run's inline
1380
+ * content in document order, where each w:t contributes its text length
1381
+ * and each inline separator (w:tab / w:br / w:cr) contributes ONE unit.
1382
+ * Counting separators makes encoding ONE-TO-ONE: a caret at the end of
1383
+ * the w:t before a tab and one at the start of the w:t after it are
1384
+ * different physical positions and get different wire offsets — without
1385
+ * the separator unit both collapsed to the same number and the decoder
1386
+ * had to guess (review bug: boundary intents applied into the wrong w:t
1387
+ * on remote replicas, and boundary-starting ranges always rejected). */
1388
+ offset: number;
1389
+ }
1390
+ declare class StableIds {
1391
+ private byEl;
1392
+ private byId;
1393
+ private next;
1394
+ /** Document-order assignment over the given roots (typically
1395
+ * `doc.editableRoots()`). Idempotent: elements that already have ids keep
1396
+ * them; untracked ids are assigned in walk order. Call after load and
1397
+ * after any edit that created tracked nodes without explicit ids. */
1398
+ assignFromRoots(roots: XmlElement[]): void;
1399
+ /**
1400
+ * Assign ids inside the given subtrees only — the scoped counterpart of
1401
+ * assignFromRoots, for an edit that is known to have created nodes in one
1402
+ * or two paragraphs (dirty-scoped reconciliation, perf B9/B10).
1403
+ *
1404
+ * EQUIVALENCE (the property the scoped hot path rests on): this produces
1405
+ * the same table a full assignFromRoots would, PROVIDED every tracked node
1406
+ * outside the subtrees already has an id. Assignment is order-dependent —
1407
+ * fresh nodes take sequential numbers from `next` in walk order — and a
1408
+ * subtree walk visits exactly a contiguous slice of the document-order
1409
+ * walk, in the same order. So the only way the two can disagree is an
1410
+ * un-id'd node elsewhere that the full walk would have numbered first.
1411
+ * That invariant holds inductively: load/importSidecar ids everything, and
1412
+ * every apply either ids the nodes it creates (carried ids), reports
1413
+ * document scope (full refresh + full assign), or creates nodes only
1414
+ * inside the subtrees passed here. Callers that cannot establish it must
1415
+ * fall back to assignFromRoots.
1416
+ */
1417
+ assignFromSubtrees(subtrees: XmlElement[]): void;
1418
+ private walk;
1419
+ /** Explicitly assign an id to a newly created node. Local edits allocate
1420
+ * (`assign(el)`); applying a replicated edit installs the carried value
1421
+ * (`assign(el, carriedId)`). Carried ids must not collide. */
1422
+ assign(el: XmlElement, id?: StableId): StableId;
1423
+ /** Force `el` to carry `id`, replacing any id it already has (e.g. one
1424
+ * auto-assigned by a refresh() before a carried id could be installed).
1425
+ * The previous id is retired. Throws if `id` is held by a different element. */
1426
+ reassign(el: XmlElement, id: StableId): void;
1427
+ /** Drop an element's mapping entirely; its id retires (never reused —
1428
+ * `next` stays monotonic). Used before carried-id assignment: a refresh
1429
+ * inside a mutation auto-assigns sequential ids to the nodes it created,
1430
+ * and one of those autos can equal a LATER id of the same carried batch,
1431
+ * which would make reassign throw on a perfectly good intent. No-op for an
1432
+ * unmapped element. */
1433
+ unassign(el: XmlElement): void;
1434
+ private install;
1435
+ idOf(el: XmlElement): StableId | undefined;
1436
+ elOf(id: StableId): XmlElement | undefined;
1437
+ /** Drop mappings for elements no longer reachable from the given roots
1438
+ * (deleted content). Keeps the table from growing across long sessions.
1439
+ * Ids of dropped elements are retired, never reused. */
1440
+ prune(roots: XmlElement[]): void;
1441
+ size(): number;
1442
+ /** Snapshot the table as [id, element] pairs against a parallel clone of
1443
+ * the tree: `pairs` maps originals→clones (as produced by walking original
1444
+ * and cloned roots in step). Used by the reconciliation snapshot (plan
1445
+ * doc 03) so a restore re-keys the table to the restored elements. */
1446
+ captureForClone(originalToClone: Map<XmlElement, XmlElement>): Map<StableId, XmlElement>;
1447
+ /** Replace the table wholesale from a captured mapping (restore path). */
1448
+ restore(fromCapture: Map<StableId, XmlElement>, nextId: StableId): void;
1449
+ nextId(): StableId;
1450
+ /**
1451
+ * Export the table as `(id, path)` pairs, where a path is the structural
1452
+ * location of the id'd element within the given roots: `[rootIndex,
1453
+ * childIndex, childIndex, …]`. This is the checkpoint ID sidecar (plan doc
1454
+ * 03): it lets a replica that reloads a snapshot reproduce the exact id
1455
+ * table — parse-order re-derivation cannot, because split-created nodes
1456
+ * carry non-sequential ids. Also carries `next` so id allocation resumes
1457
+ * consistently.
1458
+ */
1459
+ exportSidecar(roots: XmlElement[]): {
1460
+ next: StableId;
1461
+ entries: [StableId, number[]][];
1462
+ };
1463
+ /** Rebuild the table from a sidecar against freshly parsed roots (the
1464
+ * snapshot the sidecar was exported from). Replaces any current mappings. */
1465
+ importSidecar(roots: XmlElement[], sidecar: {
1466
+ next: StableId;
1467
+ entries: [StableId, number[]][];
1468
+ }): void;
1469
+ /** Encode a caret as wire-stable addresses. `t` is the w:t (or other text
1470
+ * holder) the caret sits in; the run is its nearest tracked ancestor run,
1471
+ * the block the nearest tracked block above that. Returns null when the
1472
+ * position isn't inside id-tracked content (e.g. math internals) — such
1473
+ * positions are not yet addressable on the wire. */
1474
+ encodeCaret(t: XmlElement, offset: number, parentOf: (el: XmlElement) => XmlElement | null): EncodedCaret | null;
1475
+ /** Resolve an encoded caret back to a concrete (w:t, offset) in THIS
1476
+ * table's tree — the inverse of encodeCaret, for restoring a caret across
1477
+ * a reconciliation reload (the ids survive via the sidecar; the node
1478
+ * references do not). When the exact run is gone (deleted or replaced by
1479
+ * a concurrent edit) the caret falls back to the block's first text; null
1480
+ * when nothing addressable remains. */
1481
+ decodeCaret(pos: EncodedCaret): {
1482
+ t: XmlElement;
1483
+ offset: number;
1484
+ } | null;
1485
+ }
1486
+
1487
+ interface ParseContext {
1488
+ theme?: Theme;
1489
+ /** Tracked-changes display: "final" hides deletions and shows insertions
1490
+ * plain (default); "markup" colors both. */
1491
+ revisionView?: "final" | "markup";
1492
+ /** Markup printed with Word's author colors: each author's color, in the
1493
+ * order the authors first appear; a run in a change records the change
1494
+ * (Run.changes). Absent, the markup view colors insertions green and
1495
+ * deletions red for every author, as the editor shows them. */
1496
+ revisionColor?: (author: string) => string;
1497
+ }
1498
+
1499
+ interface Relationship {
1500
+ id: string;
1501
+ type: string;
1502
+ target: string;
1503
+ external: boolean;
1504
+ }
1505
+ type Relationships = Map<string, Relationship>;
1506
+
1507
+ interface DocParseContext extends ParseContext {
1508
+ rels: Relationships;
1509
+ /** Text boxes parsed from a header/footer part edit as independent stories. */
1510
+ independentTextboxStories?: boolean;
1511
+ /** Read another package part's XML (SmartArt cached drawings live in
1512
+ * word/diagrams/drawing*.xml, reachable only through the data part). */
1513
+ readPart?: (part: string) => XmlElement | undefined;
1514
+ /** Cross-reference bookmark capture: Word's Insert-Cross-Reference targets
1515
+ * are `_RefNNN` bookmarks whose range delimits the referenced text (e.g. a
1516
+ * caption's "Figure " + SEQ field). REF fields re-render that text at
1517
+ * layout time — the docx cache is stale. `open` is keyed by bookmark id
1518
+ * while the range is unclosed; `byName` keeps the finished run lists. */
1519
+ refBookmarks?: {
1520
+ open: Map<string, Run[]>;
1521
+ byName: Map<string, Run[]>;
1522
+ };
1523
+ }
1524
+
1525
+ /** The two note parts a document can carry — see notePartsHolding. */
1526
+ type NotePart = "footnotes" | "endnotes";
1527
+ interface FromFilesOptions {
1528
+ /** Build the header and footer block models (`headers`, `footers`). Default true. */
1529
+ headerFooterBlocks?: boolean;
1530
+ /** Tracked-changes display from the start, so the parts parsed at load
1531
+ * (headers, footers, notes) follow it too. Default "final". */
1532
+ revisionView?: "final" | "markup";
1533
+ /** Print markup: each author's changes in Word's color for that author,
1534
+ * and every change recorded on its runs (see Revision). */
1535
+ revisionColors?: boolean;
1536
+ /** With revisionColors: false gives every author's changes the first
1537
+ * color, red, so that no color tells one author from another (print
1538
+ * without authors). Default true. */
1539
+ revisionAuthors?: boolean;
1540
+ }
1541
+ declare class DocxDocument$1 {
1542
+ /** Changes whenever refresh() rebuilds the parsed model. Plain in-place text
1543
+ * edits can keep this stable so incremental layout reuses model-only caches. */
1544
+ private _modelVersion;
1545
+ private _packageResourceVersion;
1546
+ get modelVersion(): number;
1547
+ /** Invalidate layout derived from related parts such as ChartML. */
1548
+ markPackageResourceChanged(): void;
1549
+ readonly pkg: Package;
1550
+ readonly theme: Theme;
1551
+ styles: Styles;
1552
+ numbering: Numbering;
1553
+ sections: Section[];
1554
+ /** Header/footer parts keyed by relationship id from document.xml.rels.
1555
+ * Empty when the document was opened without them (fromFiles). */
1556
+ readonly headers: Map<string, HeaderFooter>;
1557
+ readonly footers: Map<string, HeaderFooter>;
1558
+ private readonly headerFooterBlocks;
1559
+ /** Note content by note id. */
1560
+ readonly footnotes: Map<number, Block[]>;
1561
+ readonly endnotes: Map<number, Block[]>;
1562
+ /** The separator paragraph controls the gap between its rule and the first
1563
+ * footnote. */
1564
+ readonly footnoteSeparator: Block[];
1565
+ /** The w:continuationSeparator footnote: it opens a note area that starts
1566
+ * with a note continued from the previous page. */
1567
+ readonly footnoteContinuationSeparator: Block[];
1568
+ /** `_Ref` cross-reference bookmark ranges (name → captured runs). REF
1569
+ * fields re-render the referenced text from these — Word recomputes REF on
1570
+ * open, so the cached field result in the file is stale. */
1571
+ refBookmarks: Map<string, Run[]>;
1572
+ readonly documentRels: Relationships;
1573
+ /** settings.xml w:evenAndOddHeaders — enables the "even" header/footer variants. */
1574
+ readonly evenAndOddHeaders: boolean;
1575
+ /** settings.xml w:autoHyphenation (§17.15.1.10). This engine's layout does
1576
+ * not hyphenate automatically — the setting is round-trip state that
1577
+ * governs Word's own rendering of the document. */
1578
+ readonly autoHyphenation: boolean;
1579
+ /** settings.xml w:hyphenationZone/@w:val in twips (§17.15.1.53); null when
1580
+ * the document does not declare one (Word defaults to 360 = 0.25"). */
1581
+ readonly hyphenationZoneTwips: number | null;
1582
+ /** settings.xml w:doNotHyphenateCaps (§17.15.1.41). */
1583
+ readonly doNotHyphenateCaps: boolean;
1584
+ /** settings.xml w:mirrorMargins — facing-page (book fold) margins: even
1585
+ * (verso) pages swap the left/right margins and place the gutter on the
1586
+ * inside (right) edge so the binding margin stays on the inner side of
1587
+ * each spread. */
1588
+ readonly mirrorMargins: boolean;
1589
+ /** settings.xml w:compat w:suppressTopSpacing: the first line of a page
1590
+ * takes its character height, not its authored (exact) line spacing. */
1591
+ readonly suppressTopSpacing: boolean;
1592
+ /** settings.xml w:defaultTabStop in px (Word default 0.5"). */
1593
+ readonly defaultTabStop: number;
1594
+ /** settings.xml w:compat compatibilityMode (12=Word2007, 14=Word2010,
1595
+ * 15=Word2013+). Word 2013 (mode 15) introduced suppressing a paragraph's
1596
+ * space-before when it lands at the top of a page; mode 14 and earlier keep
1597
+ * it (nccih: a Heading1/2 after a page break sits at margin + its before).
1598
+ * Absent → treated as current (15). */
1599
+ readonly compatibilityMode: number;
1600
+ /** The compatibilityMode settings.xml actually declares, or undefined when
1601
+ * the setting (or settings.xml itself) is missing. `compatibilityMode`
1602
+ * defaults an omitted value to 15, but a table's percentage width needs the
1603
+ * distinction: Word fits the horizontal cell margins inside the table box at
1604
+ * an EXPLICIT 15 and adds them around it when the setting is absent. */
1605
+ readonly declaredCompatibilityMode: number | undefined;
1606
+ /** settings.xml m:mathPr/m:defJc — default justification for display
1607
+ * equations whose m:oMathParaPr carries no explicit m:jc (Word default:
1608
+ * centerGroup — the rows of a broken equation left-align to each other and
1609
+ * the group is centered in the column). */
1610
+ readonly mathDefJc: "left" | "right" | "center" | "centerGroup";
1611
+ /** settings.xml m:mathPr/m:wrapIndent in px (Word default 1440tw = 1"):
1612
+ * indent of auto-wrapped display-equation continuation rows from the
1613
+ * equation group's left edge (dense p13: the "+Dc(...)" continuations sit
1614
+ * exactly 72pt right of the explicit rows). */
1615
+ readonly mathWrapIndent: number;
1616
+ /** Review comments from word/comments.xml (empty when the part is absent).
1617
+ * Re-derived from the retained comments XML on every refresh(). */
1618
+ comments: DocComment[];
1619
+ /** The reviewers word/people.xml names (empty when the part is absent). */
1620
+ readonly people: DocPerson[];
1621
+ /** The font files the package embeds, as fontTable.xml lists them (empty when it embeds none). */
1622
+ readonly embeddedFonts: DocEmbeddedFont[];
1623
+ /** Retained comments.xml tree (editing + save round-trip), when present. */
1624
+ private commentsPart;
1625
+ private commentsRoot;
1626
+ /** Retained commentsExtended.xml tree (comment threading), when present. */
1627
+ private commentsExtPart;
1628
+ private commentsExtRoot;
1629
+ private commentsExtDirty;
1630
+ /** Conditional table formats per table style id, keyed by the Styles object
1631
+ * so re-parsing styles.xml (edits) naturally invalidates the cache. */
1632
+ private tableCondCache;
1633
+ /** Retained styles.xml tree (built-in style injection + save). */
1634
+ private stylesPart;
1635
+ private stylesRoot;
1636
+ /** Retained numbering.xml tree (list creation + save round-trip). */
1637
+ private numberingPart;
1638
+ private numberingRoot;
1639
+ private numberingDirty;
1640
+ /** Retained footnotes.xml tree (footnote insertion + save round-trip). */
1641
+ private footnotesPart;
1642
+ private footnotesRoot;
1643
+ private footnotesDirty;
1644
+ private footnotesRels;
1645
+ /** Retained endnotes.xml tree (endnote insertion + save round-trip). */
1646
+ private endnotesPart;
1647
+ private endnotesRoot;
1648
+ private endnotesDirty;
1649
+ private endnotesRels;
1650
+ /** Retained bibliography sources part (the customXml b:Sources data of
1651
+ * ECMA-376 §22.6), when present. Source-management editing mutates this
1652
+ * tree in place; a document with none gets the part on first create. */
1653
+ private sourcesPart;
1654
+ private sourcesRoot;
1655
+ private sourcesDirty;
1656
+ /** Companion parts written when THIS session created the sources part
1657
+ * (itemProps + its .rels); an arriving part keeps its own companions. */
1658
+ private sourcesAux;
1659
+ /** Retained glossary document part (word/glossary/document.xml, ECMA-376
1660
+ * §17.12: glossaryDocument/docParts/docPart — Word's Quick Parts / Building
1661
+ * Blocks store), when present. Building-block editing mutates this tree in
1662
+ * place; a document with none gets the part on first create. Unlike
1663
+ * headers/footers, a docPart's body is never caret-editable — it is only
1664
+ * ever cloned INTO the main document body (insertBuildingBlock) or captured
1665
+ * OUT of a selection (createBuildingBlock) — so this part carries no
1666
+ * editableRoots()/stable-id integration of its own. */
1667
+ private glossaryPart;
1668
+ private glossaryRoot;
1669
+ private glossaryDirty;
1670
+ /** Serialize retained optional parts only once actually mutated, keeping
1671
+ * untouched parts byte-identical through save(). */
1672
+ private stylesDirty;
1673
+ private commentsDirty;
1674
+ /** Retained XML roots — source of truth for editing and save(). */
1675
+ private readonly docPart;
1676
+ /** Retained settings.xml tree. A synthetic empty root keeps history root
1677
+ * indices stable for documents that did not originally contain the part. */
1678
+ private readonly settingsPart;
1679
+ private readonly settingsRoot;
1680
+ private settingsDirty;
1681
+ /** Parsed document.xml root (read-only outside the class; the layout engine
1682
+ * scans it for incremental-reuse eligibility, tests walk it). */
1683
+ readonly docRoot: XmlElement;
1684
+ private readonly hfParts;
1685
+ private readonly ctxBase;
1686
+ /** Tracked-changes display mode; refresh() re-derives after changes. */
1687
+ revisionView: "final" | "markup";
1688
+ /** The revision authors in the order they first appeared, for revisionColor. */
1689
+ private readonly revisionAuthors;
1690
+ /** FromFilesOptions.revisionAuthors. */
1691
+ private revisionAuthorColors;
1692
+ private readonly relsPath;
1693
+ private relsRoot;
1694
+ private contentTypesRoot;
1695
+ /** A fingerprint of the canonical XML first parsed from each always-modeled
1696
+ * package part. If the retained tree still matches on save, keep the part's
1697
+ * original bytes instead of replacing producer formatting such as CRLF line
1698
+ * ends. A fingerprint and not the XML itself: the XML was a second copy of
1699
+ * every document part, 30 MB for a 0.85 MB .docx. */
1700
+ private readonly originalModeledXml;
1701
+ private docPrIdCounter;
1702
+ /** Transient layout state: set by the engine while laying out a docGrid
1703
+ * type="charsAndLines" section so line measurement can give East-Asian
1704
+ * glyphs their true (uninflated) grid line height. Off outside such a
1705
+ * section. Safe as document-scoped mutable state because layout is
1706
+ * single-threaded and sequential per section. */
1707
+ charGridEa: boolean;
1708
+ protected constructor(pkg: Package, options?: FromFilesOptions);
1709
+ private readonly coreProperties;
1710
+ /** Resolve the content controls under `root` as the document's own were
1711
+ * resolved when it loaded, for body XML parsed outside it (stream/body.ts). */
1712
+ hydrateControls(root: XmlElement): void;
1713
+ /** Resolve content controls mapped to standard package core properties.
1714
+ * Word refreshes these bindings on open, so the serialized sdtContent can
1715
+ * be stale even though the visible value comes from docProps/core.xml. */
1716
+ private hydrateCorePropertyControls;
1717
+ /** Repair only objects emitted by older WordInWeb builds that Word rejects. */
1718
+ private repairLegacyWordInWebObjects;
1719
+ /**
1720
+ * Re-derive the document model from the retained XML trees. Called after
1721
+ * edit commands mutate the XML.
1722
+ */
1723
+ /** An author's revision color: Word's "by author" palette, given out in
1724
+ * the order the authors first appear (the parts parsed at load, headers,
1725
+ * footers and notes, before the body), the ninth author taking the first
1726
+ * color again. Without authors (FromFilesOptions.revisionAuthors), the
1727
+ * first color for all. */
1728
+ revisionColor(author: string): string;
1729
+ /** Switch tracked-changes display and re-derive the model. */
1730
+ setRevisionView(view: "final" | "markup"): void;
1731
+ /** Invalidated on refresh; see layoutGlobalSig. */
1732
+ private _layoutGlobalSig;
1733
+ /** Signature of everything OUTSIDE a paragraph's own XML that affects how it
1734
+ * breaks into lines: style + numbering definitions, doc-level layout scalars,
1735
+ * and the tracked-changes view mode. The line-break cache (layout/inline.ts)
1736
+ * combines this with a paragraph's own content signature so a style/numbering/
1737
+ * settings edit invalidates cached breaks even though the paragraph XML is
1738
+ * unchanged. Memoized until the next refresh() (styles/numbering trees are
1739
+ * stable across a plain text edit). */
1740
+ layoutGlobalSig(): string;
1741
+ refresh(): void;
1742
+ /** Stable node-id side table for replicated editing. Null (and zero cost)
1743
+ * for local-only documents; call `enableStableIds()` to populate and
1744
+ * maintain it. Kept in memory only — never serialized into the XML. */
1745
+ stableIds: StableIds | null;
1746
+ /** Populate the stable-id table from current content and keep it updated
1747
+ * on every subsequent refresh(). Idempotent. */
1748
+ enableStableIds(): StableIds;
1749
+ /** Reparse the two sibling body-story paragraphs created by Enter without
1750
+ * rebuilding the complete document model. Paragraphs nested in table cells
1751
+ * are included because legal documents spend most of their body inside
1752
+ * tables; revisions, bookmarks, fields, and section breaks use refresh(). */
1753
+ reparseDirectBodyParagraphSplit(beforeSource: XmlElement, afterSource: XmlElement): {
1754
+ before: Paragraph;
1755
+ after: Paragraph;
1756
+ } | null;
1757
+ /**
1758
+ * The parsed body-story block list holding the paragraph parsed from
1759
+ * `source`, and its index in it — searching sections and, recursively,
1760
+ * table cells. Null when the model doesn't hold that paragraph (it lives in
1761
+ * a header/footer/footnote part, or the model predates its creation), which
1762
+ * is every targeted-reparse helper's signal to fall back to a full
1763
+ * refresh(). Shared by those helpers and by paragraphBySource.
1764
+ */
1765
+ private locateParagraph;
1766
+ private _paraLoc;
1767
+ /** The parsed Paragraph for a retained w:p in the body story (table cells
1768
+ * included), or null when the model doesn't hold it. Lets a caller that
1769
+ * already knows which paragraph an edit addresses reach that paragraph's
1770
+ * runs without walking the whole model. */
1771
+ paragraphBySource(source: XmlElement): Paragraph | null;
1772
+ /** Insert a new paragraph immediately before a retained body paragraph
1773
+ * without rebuilding the complete document model. Used by Enter at the
1774
+ * exact paragraph start, where the existing paragraph itself is unchanged. */
1775
+ insertDirectBodyParagraphBefore(referenceSource: XmlElement, insertedSource: XmlElement): Paragraph | null;
1776
+ /** Reparse a body paragraph plus several new siblings created by
1777
+ * click-and-type without rebuilding the complete document model. */
1778
+ reparseDirectBodyParagraphSplits(beforeSource: XmlElement, afterSources: XmlElement[]): Paragraph[] | null;
1779
+ /** Reparse one retained body-story paragraph after a structural edit that
1780
+ * leaves its surrounding block list unchanged, such as inserting ink. */
1781
+ reparseBodyParagraph(source: XmlElement): Paragraph | null;
1782
+ /** Reparse two sibling body-story paragraphs after Backspace/Delete merged
1783
+ * their XML into one. Keeps the parsed model generation stable so long
1784
+ * documents can use incremental layout instead of repaginating in full. */
1785
+ reparseDirectBodyParagraphMerge(beforeSource: XmlElement, afterSource: XmlElement, survivorSource: XmlElement): Paragraph | null;
1786
+ private deriveComments;
1787
+ /** Retained comments tree for edit commands (null when the doc has none). */
1788
+ /**
1789
+ * Retained comments tree. With create=true, a missing comments.xml part is
1790
+ * created and registered (content type + document relationship) so newly
1791
+ * added comments serialize and round-trip through Word.
1792
+ */
1793
+ commentsTree(create?: boolean): XmlElement | null;
1794
+ /**
1795
+ * Make sure a paragraph style is usable: Word ships built-in definitions
1796
+ * for Heading 1-6/Title even when a file doesn't declare them, so applying
1797
+ * one to such a file must inject a standard definition (otherwise the
1798
+ * paragraph would reference an undefined style and render as Normal).
1799
+ */
1800
+ ensureParagraphStyle(styleId: string): boolean;
1801
+ /**
1802
+ * Retained numbering tree. With create=true, a missing numbering.xml part
1803
+ * is created and registered (content type + document relationship) so list
1804
+ * definitions added by editing serialize and round-trip.
1805
+ */
1806
+ numberingTree(create?: boolean): XmlElement | null;
1807
+ markNumberingChanged(): void;
1808
+ /** Retained styles.xml tree, or null when the package has no styles part.
1809
+ * Style-definition editing mutates this tree in place. */
1810
+ stylesTree(): XmlElement | null;
1811
+ /**
1812
+ * Re-resolve the style cascade after a definition changed in place.
1813
+ *
1814
+ * A style definition is not addressed by any paragraph's XML, so mutating one
1815
+ * changes how EVERY paragraph resolves without changing a single w:p. Two
1816
+ * things therefore have to be reset by hand: the parsed Styles map every
1817
+ * effective-props call reads, and layoutGlobalSig, which is what makes the
1818
+ * line-break cache treat cached breaks for unchanged paragraph XML as stale.
1819
+ */
1820
+ markStylesChanged(): void;
1821
+ /**
1822
+ * Retained bibliography sources tree (b:Sources), or null when the package
1823
+ * has no sources part. With create=true, a missing part is created and
1824
+ * registered the way Word lays one out (ECMA-376 §22.6 + Part 2 custom XML
1825
+ * data storage): the data itself as customXml/itemN.xml, a datastore-item
1826
+ * properties part (itemPropsN.xml) declaring the Bibliography schema URI as
1827
+ * its schemaRef, a .rels from the item to its properties, a customXml
1828
+ * relationship from the main document part, and the content-type overrides.
1829
+ *
1830
+ * DETERMINISM. Everything written is a pure function of the package —
1831
+ * the item number is the first free one, and the datastore itemID GUID is a
1832
+ * fixed constant rather than Word's random draw — so two replicas creating
1833
+ * the part through the same sequenced operation write identical bytes.
1834
+ */
1835
+ sourcesTree(create?: boolean): XmlElement | null;
1836
+ /**
1837
+ * Invalidate what a sources-part edit changes downstream. Like
1838
+ * markStylesChanged, the part is addressed by no paragraph's XML: a
1839
+ * CITATION field's painted text resolves from the part at layout, so the
1840
+ * layout signature has to drop for unchanged paragraph XML to repaint.
1841
+ */
1842
+ markSourcesChanged(): void;
1843
+ /**
1844
+ * Retained glossary document tree (w:glossaryDocument), or null when the
1845
+ * package has no glossary part. With create=true, a missing part is
1846
+ * created and registered — package part, document relationship,
1847
+ * content-type override — the createNotesPart discipline.
1848
+ *
1849
+ * The glossary part gets none of the sources part's companion machinery
1850
+ * (no datastore item, no random itemID): it is an ordinary WordprocessingML
1851
+ * part named by relationship TYPE, so creation just mints an empty
1852
+ * `<w:glossaryDocument><w:docParts/></w:glossaryDocument>` and wires it up
1853
+ * — closer to createNotesPart than to sourcesTree. A real Word-authored
1854
+ * glossary part additionally carries its own styles.xml / settings.xml /
1855
+ * fontTable.xml; this engine writes none of them, because a docPart's
1856
+ * content is read once — to clone its blocks into the main document, where
1857
+ * they resolve styles against the MAIN document's own styles.xml — and is
1858
+ * never laid out or rendered as its own story the way a header/footer is.
1859
+ *
1860
+ * DETERMINISM: nothing here depends on Word's random draws (no GUID is
1861
+ * written at all — w:docPartPr/w:guid is optional and this engine never
1862
+ * reads it back), so two replicas creating the part through the same
1863
+ * sequenced operation write identical bytes.
1864
+ */
1865
+ glossaryTree(create?: boolean): XmlElement | null;
1866
+ /** Invalidate what a glossary-part edit changes: nothing downstream, since
1867
+ * createBuildingBlock/deleteBuildingBlock touch only the glossary tree, not
1868
+ * any paragraph the layout reads. Exists for the same "explicit intent to
1869
+ * persist" reason markSourcesChanged does. */
1870
+ markGlossaryChanged(): void;
1871
+ /**
1872
+ * Retained footnotes tree. With create=true, a missing footnotes.xml part
1873
+ * is created and registered (with Word's required separator footnotes) so
1874
+ * inserted footnotes serialize and round-trip.
1875
+ */
1876
+ footnotesTree(create?: boolean): XmlElement | null;
1877
+ /** Retained endnotes tree; the endnote mirror of footnotesTree. */
1878
+ endnotesTree(create?: boolean): XmlElement | null;
1879
+ /** Register a new notes part in document.xml.rels and [Content_Types].xml,
1880
+ * and return the part path. The tree itself is the caller's. */
1881
+ private createNotesPart;
1882
+ /**
1883
+ * Create an empty header/footer part (with a default-type reference in
1884
+ * every sectPr) when the document has none - Word does this implicitly the
1885
+ * first time you edit the header area. Returns the part's root.
1886
+ */
1887
+ /** Whether the document declares any section properties at all. A blank
1888
+ * minimal document has none; see ensureHfPart. */
1889
+ private hasSectPr;
1890
+ /** Whether a header (or footer) part already exists — the precondition
1891
+ * `ensureHfPart` tests internally, exposed so a caller can tell a real
1892
+ * creation from a no-op before mutating (the collab apply needs to know
1893
+ * whether an ensureHeaderFooter intent has anything to do). */
1894
+ hasHfPart(kind: "header" | "footer"): boolean;
1895
+ ensureHfPart(kind: "header" | "footer"): XmlElement;
1896
+ /** A w:headerReference / w:footerReference element. */
1897
+ private hfReference;
1898
+ /** Materialize the default body-level sectPr when the document declares no
1899
+ * section properties at all (schema: the body's sectPr is its LAST child). */
1900
+ private ensureBodySectPr;
1901
+ /**
1902
+ * Give every section a header and footer reference of the given variant
1903
+ * type, creating one empty part per band the way Word does the first time
1904
+ * "different first page" (type "first") or "different odd & even pages"
1905
+ * (type "even") is enabled. Sections that already carry a reference of the
1906
+ * type keep it — and its part's content. True when anything was added.
1907
+ */
1908
+ ensureHfVariantParts(type: "first" | "even"): boolean;
1909
+ /**
1910
+ * A new empty header or footer part, referenced as `type` from `sectPr`
1911
+ * alone. Returns the part's target, as headerFooterRoot and
1912
+ * relationshipsOf take it. compareDocuments gives a header the revised
1913
+ * document lost one of these, to hold the original's content struck.
1914
+ */
1915
+ addHfPart(kind: "header" | "footer", type: "default" | "first" | "even", sectPr: XmlElement): string;
1916
+ /** Create and register a new empty header/footer part — package part,
1917
+ * document relationship, content-type override, hfParts entry — with no
1918
+ * section references of its own; the caller decides which sectPrs point at
1919
+ * it and with which w:type. */
1920
+ private createHfPart;
1921
+ markFootnotesChanged(): void;
1922
+ markEndnotesChanged(): void;
1923
+ /** Re-derive both id -> blocks maps from the retained trees, so layout sees
1924
+ * an inserted or edited note. */
1925
+ private rederiveNotes;
1926
+ /** Called by comment edit commands after mutating the comments tree. */
1927
+ markCommentsChanged(): void;
1928
+ /**
1929
+ * Retained commentsExtended tree (threading). With create=true, a missing
1930
+ * part is created and registered (content type + document relationship) so
1931
+ * Word picks up reply threading.
1932
+ */
1933
+ commentsExtendedTree(create?: boolean): XmlElement | null;
1934
+ markCommentsExtendedChanged(): void;
1935
+ /**
1936
+ * The w:t elements covered by each comment's range, in document order.
1937
+ * Point comments (a bare commentReference with no range) anchor to the
1938
+ * nearest preceding w:t.
1939
+ */
1940
+ commentAnchors(): Map<string, XmlElement[]>;
1941
+ /** Flag a notes part dirty when `t` lives inside it, so save()
1942
+ * re-serializes footnotes.xml / endnotes.xml. Called by the editor after a
1943
+ * text edit; a no-op for body/header/footer targets. */
1944
+ markDirtyIfFootnote(t: XmlElement): void;
1945
+ /**
1946
+ * Which note parts hold `el` right now. An operation that DETACHES `el` —
1947
+ * accepting or rejecting a revision, for one — has to ask BEFORE it mutates
1948
+ * and mark the answer afterwards: a detached element belongs to no part, so
1949
+ * a containment test run after the fact reports nothing and save() then
1950
+ * leaves the stale footnotes.xml / endnotes.xml in the package.
1951
+ */
1952
+ notePartsHolding(el: XmlElement): NotePart[];
1953
+ /** Flag the given note parts dirty, so save() re-serializes exactly those. */
1954
+ markNotePartsChanged(parts: readonly NotePart[]): void;
1955
+ /** The mutable XML roots (document body, related modeled parts, settings).
1956
+ * settingsRoot is always second and always present so its history snapshot
1957
+ * index stays stable even when optional related roots are created later. */
1958
+ editableRoots(): XmlElement[];
1959
+ /** CT_Settings children that precede w:mirrorMargins in the schema sequence
1960
+ * (§17.15.1.78). Insertions go before the first child that is not a
1961
+ * predecessor, so Word never has to repair settings.xml. */
1962
+ private static readonly SETTINGS_BEFORE_MIRROR;
1963
+ /** The schema predecessors of w:evenAndOddHeaders (§17.10.1): everything up
1964
+ * to mirrorMargins, then the sequence through defaultTableStyle. */
1965
+ private static readonly SETTINGS_BEFORE_EVEN_AND_ODD;
1966
+ /** Set or remove one settings.xml element at its schema position. Null
1967
+ * removes; otherwise the element is (re)inserted before the first child
1968
+ * that is not a schema predecessor. */
1969
+ private setSettingsElement;
1970
+ /** Set or remove one on/off settings.xml toggle at its schema position. */
1971
+ private setSettingsToggle;
1972
+ /** The schema predecessors of w:autoHyphenation: everything through
1973
+ * w:defaultTabStop (§17.15.1.78). Its cluster mates append in order. */
1974
+ private static readonly SETTINGS_BEFORE_AUTO_HYPHENATION;
1975
+ /**
1976
+ * Patch the hyphenation settings (w:autoHyphenation §17.15.1.10,
1977
+ * w:hyphenationZone §17.15.1.53, w:doNotHyphenateCaps §17.15.1.41). Each
1978
+ * present key is written; `zoneTwips: null` removes the zone element. True
1979
+ * when anything changed — the honest no-op a replicated document-scoped
1980
+ * operation needs. This engine's layout does not hyphenate automatically;
1981
+ * the settings govern Word's own rendering of the file.
1982
+ */
1983
+ setHyphenation(patch: {
1984
+ auto?: boolean;
1985
+ zoneTwips?: number | null;
1986
+ noCaps?: boolean;
1987
+ }): boolean;
1988
+ /** Toggle the document-global facing-page margin mode in settings.xml. */
1989
+ setMirrorMargins(enabled: boolean): void;
1990
+ /** Toggle w:evenAndOddHeaders (§17.10.1) — the document-global switch that
1991
+ * makes even pages use the "even" header/footer variants. */
1992
+ setEvenAndOddHeaders(enabled: boolean): void;
1993
+ /** Register settings.xml in document.xml.rels and [Content_Types].xml when
1994
+ * the package was born without it (a minimal document). */
1995
+ private registerSettingsPart;
1996
+ /**
1997
+ * Find the parent element of `target` in any modeled XML tree (document
1998
+ * body, headers, footers). Linear scan — documents are small and this only
1999
+ * runs on structural edits (Enter, paragraph merge).
2000
+ */
2001
+ /** The header part roots, in package order. A watermark is authored into
2002
+ * every one of them: Word paints it on every page, and a document with a
2003
+ * first-page or even-page header has more than one header part. */
2004
+ /** The root of the header or footer part at `target`, if this document has one. */
2005
+ headerFooterRoot(target: string): XmlElement | undefined;
2006
+ headerRoots(): XmlElement[];
2007
+ /** The footer part roots, in package order — headerRoots' counterpart, for
2008
+ * operations that walk both bands (the page-number gallery's removal
2009
+ * sweep). */
2010
+ footerRoots(): XmlElement[];
2011
+ /** XML roots that can carry tracked changes: body, headers/footers, notes. */
2012
+ revisionRoots(): XmlElement[];
2013
+ /** Body, header/footer and note roots — every tree the caret can reach. */
2014
+ private contentRoots;
2015
+ /**
2016
+ * Memoized child→parent links. Nothing invalidates this map — the tree is
2017
+ * spliced constantly — so every answer is RE-DERIVED before it is returned:
2018
+ * the memoized parent must still list the target among its children, and
2019
+ * must still hang off a root (see memoIsLive). A stale entry can then only
2020
+ * cost a cache miss, never a wrong answer.
2021
+ *
2022
+ * Both halves are needed. Containment alone is not proof of a live parent:
2023
+ * a run split for formatting is spliced OUT of its paragraph while its own
2024
+ * `children` array still lists the elements that moved into the replacement
2025
+ * runs, so a containment-only check would hand back the detached run where a
2026
+ * walk from the roots finds the new one.
2027
+ */
2028
+ private _parentMemo;
2029
+ private memoIsLive;
2030
+ findParentOf(target: XmlElement): XmlElement | undefined;
2031
+ /** Record a parent link the caller just created (a splice), so the next
2032
+ * lookup skips the full-document walk. Advisory only — findParentOf
2033
+ * verifies every memo against the live tree before trusting it. */
2034
+ noteParent(child: XmlElement, parent: XmlElement): void;
2035
+ /**
2036
+ * Serialize the (possibly edited) document back to .docx bytes. Only the
2037
+ * XML parts we model are re-serialized; every other part round-trips
2038
+ * byte-for-byte.
2039
+ */
2040
+ private rememberOriginalXml;
2041
+ private writeModeledXml;
2042
+ /**
2043
+ * Canonicalize producer shorthand that Google Docs otherwise interprets as
2044
+ * a fixed, few-twip table. Word treats `tblW="100%"` plus a placeholder
2045
+ * grid as autofit; Google needs the standard pct value and a usable cached
2046
+ * grid. The cached widths follow the same content-dominant shape and do not
2047
+ * change Word's autofit result.
2048
+ */
2049
+ /** Undo closures recorded by save-time fixups while `saveJournal` is
2050
+ * active, so `save()` can revert every live-tree mutation and remain
2051
+ * side-effect-free. Collaborative checkpoints re-serialize the
2052
+ * authoritative document repeatedly; a save that mutated the tree would
2053
+ * change its hash outside the intent stream and desync the fleet. */
2054
+ private saveJournal;
2055
+ private journalSetAttr;
2056
+ private normalizePercentageTableGrids;
2057
+ save(): Uint8Array;
2058
+ /**
2059
+ * An independent copy: what `DocxDocument.load(doc.save())` gives, without
2060
+ * zipping the package and unzipping it again. compareDocuments starts from a
2061
+ * copy of the revised document, and the round trip through the zip was a
2062
+ * third of its time on a document that had not changed at all.
2063
+ */
2064
+ clone(): DocxDocument$1;
2065
+ /**
2066
+ * The package's parts as save() writes them, before they are zipped: a
2067
+ * writer that streams the zip to disk (compare-cli) takes them one at a
2068
+ * time, without a zip of them all in memory and its unzip.
2069
+ */
2070
+ saveFiles(): Record<string, Uint8Array>;
2071
+ saveAsync(): Promise<Uint8Array>;
2072
+ private buildPackage;
2073
+ private buildPackageFiles;
2074
+ /**
2075
+ * Leave out the chart parts the document no longer references.
2076
+ *
2077
+ * Deleting a chart splices its w:drawing out of the story, but the chart
2078
+ * part, its rels part, its embedded workbook, the document relationship, and
2079
+ * the two [Content_Types].xml overrides all stay. An agent that inserts a
2080
+ * chart, deletes it, and inserts a replacement therefore saves TWO chart
2081
+ * parts for the one chart the document shows.
2082
+ *
2083
+ * The release happens here, at save time, rather than when the drawing goes,
2084
+ * because undo restores the drawing XML — r:id and all — from a snapshot
2085
+ * that models package parts but no relationship state. Dropping the
2086
+ * relationship early would make undo produce a chart pointing at nothing.
2087
+ * The live tree keeps everything; only the written bytes lose the orphans,
2088
+ * and the saveJournal puts back the two trees this touches.
2089
+ *
2090
+ * Relationship ids are scoped to the part that owns the rels file, so the
2091
+ * document body is the only place that can reference these ids, and reading
2092
+ * it is a complete check. Headers, footers, and notes carry their own rels.
2093
+ */
2094
+ private dropOrphanChartParts;
2095
+ /** Fresh unique docPr id for inserted drawings. Seeded once past the
2096
+ * highest id already present in any editable root (floor 1000, matching
2097
+ * the historical seed for documents with no drawings) so a document that
2098
+ * already carries drawings never gets a colliding id. */
2099
+ nextDrawingId(): number;
2100
+ /** Next unused revision id (w:id on w:ins/w:del). Seeded once past the
2101
+ * highest id already present in any editable root so a document that
2102
+ * already has tracked changes never collides. */
2103
+ private revIdCounter;
2104
+ nextRevisionId(): number;
2105
+ /**
2106
+ * Add image bytes as a new media part + relationship (+ content-type
2107
+ * default). Returns the relationship id for use in a w:drawing.
2108
+ */
2109
+ private ensureRelsRoot;
2110
+ /** Register an external hyperlink relationship and return its rId. */
2111
+ /**
2112
+ * Copy the part that `source`'s main-document relationship `relId` points
2113
+ * at into this package, with every part it references in turn (a chart's
2114
+ * embedded workbook, SmartArt's layout, style and colour parts) and their
2115
+ * content types, and add a relationship to it. Returns the new
2116
+ * relationship id, or null when the source has no such internal part.
2117
+ *
2118
+ * compareDocuments needs this for struck content: a removed picture keeps
2119
+ * its w:drawing, and without its image part the result's reject-all
2120
+ * brought the picture back as an empty frame.
2121
+ */
2122
+ adoptRelFrom(source: DocxDocument$1, relId: string, scope?: {
2123
+ from?: string | null;
2124
+ into?: string | null;
2125
+ }): string | null;
2126
+ /** Give a part copied from `source` the content type it had there. */
2127
+ private adoptContentType;
2128
+ addHyperlinkRel(url: string, ownerPart?: string | null): string;
2129
+ /** Retarget an existing external relationship (hyperlink href edit). */
2130
+ setRelTarget(relId: string, url: string): boolean;
2131
+ /** The relationships owned by `part` (a header or footer part), or by the
2132
+ * document part when null; a header or footer gets a rels root on demand. */
2133
+ private relsOwnerOf;
2134
+ /** The relationships of `part` (a header or footer), or of the document part. */
2135
+ relationshipsOf(part?: string | null): Relationships;
2136
+ /** The relationships of the part that holds `source`: a header or footer
2137
+ * part when the element is inside one, else the document part. */
2138
+ private imageRelsOwner;
2139
+ /** Add an image relationship pointing at `part`, in the relationships of
2140
+ * whichever part holds `source`. */
2141
+ private addImageRel;
2142
+ /**
2143
+ * Point a SECOND part at an image part this document already has.
2144
+ *
2145
+ * Word's picture watermark is ONE media part that every header part
2146
+ * references. Registering the image again per header would put a full copy
2147
+ * of the bytes in the package for each one — three headers, three copies of
2148
+ * the same logo — and give the media-install path three pending parts to
2149
+ * fill from one upload.
2150
+ */
2151
+ linkImageResource(part: string, source: XmlElement): string;
2152
+ private addImageResourceAt;
2153
+ addImageResource(bytes: Uint8Array, ext: string): string;
2154
+ /** Add a GLB model part and its Office 2019 model3d relationship. */
2155
+ addModel3DResource(bytes: Uint8Array): {
2156
+ relId: string;
2157
+ part: string;
2158
+ };
2159
+ /** Add an OLE package part used by a Word w:object. */
2160
+ addEmbeddedObjectResource(bytes: Uint8Array): {
2161
+ relId: string;
2162
+ part: string;
2163
+ };
2164
+ /** Add a DOCX package embedded as an activatable Word.Document.12 object. */
2165
+ addEmbeddedWordDocumentResource(bytes: Uint8Array): {
2166
+ relId: string;
2167
+ part: string;
2168
+ };
2169
+ /** Add a native ChartML part and its embedded editable workbook. */
2170
+ addChartResource(chartXml: string, workbook: Uint8Array): {
2171
+ relId: string;
2172
+ part: string;
2173
+ };
2174
+ /** Add the SmartArt data/layout/style/color parts and its cached diagram drawing. */
2175
+ addSmartArtResources(layoutXml: string, styleXml: string, colorsXml: string, drawingXml: string, dataXml: (drawingRelId: string) => string): {
2176
+ dataRelId: string;
2177
+ layoutRelId: string;
2178
+ styleRelId: string;
2179
+ colorsRelId: string;
2180
+ drawingRelId: string;
2181
+ };
2182
+ /** A document from .docx bytes, including Strict Open XML packages. */
2183
+ static load(data: ArrayBuffer | Uint8Array): DocxDocument$1;
2184
+ /** A document over parts already unzipped (stream/body.ts's shell). */
2185
+ /**
2186
+ * A document over an already-unzipped entry map. With `headerFooterBlocks`
2187
+ * false, `headers` and `footers` stay empty: their XML is still read,
2188
+ * compared and saved, but no block models are built from it (about 1 KB a
2189
+ * paragraph), for a caller that compares the document and never lays it out
2190
+ * (compare-cli).
2191
+ */
2192
+ static fromFiles(files: Record<string, Uint8Array>, options?: FromFilesOptions): DocxDocument$1;
2193
+ /** The context the body's blocks are parsed with, for a caller that keeps
2194
+ * the body outside the document (stream/body.ts). Its REF bookmark capture
2195
+ * starts empty; the caller decides whether `refBookmarks` reads from it. */
2196
+ bodyParseContext(): DocParseContext;
2197
+ media(part: string): Uint8Array | undefined;
2198
+ /**
2199
+ * Pending-media registry (plan doc 05 change 1 / doc 16 §6): parts whose
2200
+ * XML registration (rels + content-type + extent geometry) exists but
2201
+ * whose BYTES have not arrived yet — the out-of-band media model. Layout
2202
+ * needs no bytes (extents live in the XML), so a doc with pending parts
2203
+ * lays out pixel-identically; the renderer shows a placeholder until
2204
+ * `installMedia`. Keyed by part name; the value is the doc-16 §5.3
2205
+ * metadata (declared sha + optional E2EE iv/epoch for re-supply).
2206
+ */
2207
+ readonly pendingMedia: Map<string, {
2208
+ sha: string;
2209
+ iv?: string;
2210
+ genesisId?: string;
2211
+ }>;
2212
+ /** DISPLAY-ONLY transfer state for a pending part (doc 16 §5.2 step 4), so
2213
+ * the skeleton can say "fetching" versus "nobody online has this yet".
2214
+ * Written by the media transfer layer, read by the renderer; never part of
2215
+ * the document's identity and never serialized. */
2216
+ readonly mediaTransferState: Map<string, "unavailable" | "fetching" | "waiting">;
2217
+ /** Per-part media metadata that PERSISTS after install (doc 16 §5.3):
2218
+ * holder duty needs the sha (and E2EE iv/epoch) of READY parts to answer
2219
+ * re-supply requests; pendingMedia above only tracks not-yet-arrived. */
2220
+ readonly mediaMeta: Map<string, {
2221
+ sha: string;
2222
+ iv?: string;
2223
+ genesisId?: string;
2224
+ }>;
2225
+ /** "ready" = bytes present; "pending" = registered, bytes absent (doc 05).
2226
+ * Unregistered parts report "pending" too — a rel pointing at a missing
2227
+ * zip entry after a save/parse round-trip IS the pending state (a hole is
2228
+ * detectable, never corrupt — doc 16 §6 round-trip rule). */
2229
+ mediaStatus(part: string): "ready" | "pending";
2230
+ /**
2231
+ * Register an image part + relationship WITHOUT bytes (doc 16 §2: the
2232
+ * intent carries the sha; bytes travel out of band). Same deterministic
2233
+ * naming/rId scan as addImageResource so every replica applying the same
2234
+ * canonical intent derives identical registration.
2235
+ */
2236
+ registerPendingImage(sha: string, ext: string, meta?: {
2237
+ iv?: string;
2238
+ genesisId?: string;
2239
+ }, source?: XmlElement): string;
2240
+ /** As registerPendingImage, and also names the part it made — what a second
2241
+ * part needs to reach the same image through linkImageResource. */
2242
+ registerPendingImagePart(sha: string, ext: string, meta?: {
2243
+ iv?: string;
2244
+ genesisId?: string;
2245
+ }, source?: XmlElement): {
2246
+ relId: string;
2247
+ part: string;
2248
+ };
2249
+ /** Install fetched bytes into a pending part (doc 05). The caller has
2250
+ * ALREADY verified the sha against the intent's declaration (the
2251
+ * reservation is the hash commitment — doc 16 §1.1); this installs and
2252
+ * clears the pending record. Returns false for unknown parts. */
2253
+ installMedia(part: string, bytes: Uint8Array): boolean;
2254
+ /** Effective paragraph properties: docDefaults → table style → style chain → direct. */
2255
+ effectiveParaProps(para: Paragraph): ParaProps;
2256
+ /**
2257
+ * Run props contributed by the enclosing table style's conditional
2258
+ * w:tblStylePr blocks for this paragraph's cell (undefined when the
2259
+ * paragraph isn't in a styled table cell or nothing applies).
2260
+ */
2261
+ private tableCondRPr;
2262
+ /** Effective run properties for a run inside a paragraph. */
2263
+ effectiveRunProps(para: Paragraph, runProps: RunProps): RunProps;
2264
+ numberingLevel(numId: number, ilvl: number): NumberingLevel | undefined;
2265
+ numberingInstance(numId: number): NumInstance | undefined;
2266
+ private findDocumentPart;
2267
+ private readXmlOptional;
2268
+ /** A part Word prints (the document, a header or footer, the notes, the
2269
+ * comments), refused when it holds a w:altChunk anywhere. */
2270
+ private readPrintedXml;
2271
+ }
2272
+
2273
+ /** Word documents, including binary .doc and the oldest Word formats. */
2274
+ declare class DocxDocument extends DocxDocument$1 {
2275
+ private constructor();
2276
+ static load(data: ArrayBuffer | Uint8Array): DocxDocument;
2277
+ static fromFiles(files: Record<string, Uint8Array>, options?: FromFilesOptions): DocxDocument;
2278
+ clone(): DocxDocument;
2279
+ }
2280
+
2281
+ /** Maps a rendered text item back to its source XML for editing. */
2282
+ interface TextSource {
2283
+ run: Run;
2284
+ /** Source w:t; null when the text is synthetic (fields, symbols). */
2285
+ t: XmlElement | null;
2286
+ /** Char offset of this item's first character within t's text. */
2287
+ offset: number;
2288
+ }
2289
+ /**
2290
+ * Layout output: pages of absolutely positioned primitives (px, page-relative).
2291
+ * The renderer maps these 1:1 to DOM/canvas/SVG — no further layout happens
2292
+ * downstream, which is what guarantees pagination fidelity.
2293
+ */
2294
+ interface FontSpec {
2295
+ family: string;
2296
+ size: number;
2297
+ bold: boolean;
2298
+ italic: boolean;
2299
+ /** Pair kerning is active because the run met its w:kern size threshold. */
2300
+ kerning?: boolean;
2301
+ /** The run's complex-script language (w:lang w:bidi, BCP 47), for the
2302
+ * shaper's language-specific forms; absent when the run names none. */
2303
+ lang?: string;
2304
+ /** Optional PAINT-only family tried before `family` in the CSS stack, without
2305
+ * affecting metrics or width lookups (keyed by `family`). Used for CJK: the
2306
+ * line-pitch profile stays keyed by the macOS substitute face while the real
2307
+ * Windows glyphs (MS Mincho, Microsoft JhengHei, …) paint when available. */
2308
+ paintFamily?: string;
2309
+ /** PAINT-only vertical nudge (CSS px, positive = down) applied to the glyphs
2310
+ * without touching layout metrics or advances. Used when a substitute face
2311
+ * (Latha for Word's Tamil Vijaya) sits on a different baseline than the face
2312
+ * Word rasterized; the shift lands the glyphs on Word's baseline. */
2313
+ paintDY?: number;
2314
+ }
2315
+ interface PathItem {
2316
+ kind: "path";
2317
+ x: number;
2318
+ y: number;
2319
+ width: number;
2320
+ height: number;
2321
+ /** SVG path data in a `viewW x viewH` coordinate space. */
2322
+ d: string;
2323
+ viewW: number;
2324
+ viewH: number;
2325
+ fill?: string;
2326
+ stroke?: {
2327
+ color: string;
2328
+ width: number;
2329
+ opacity?: number;
2330
+ };
2331
+ rotate?: {
2332
+ deg: number;
2333
+ ox: number;
2334
+ oy: number;
2335
+ };
2336
+ /** Paint under / over the body text (anchored-shape layering). */
2337
+ behind?: boolean;
2338
+ front?: boolean;
2339
+ z?: number;
2340
+ }
2341
+ interface TextItem {
2342
+ kind: "text";
2343
+ x: number;
2344
+ /** Baseline y. */
2345
+ baseline: number;
2346
+ width: number;
2347
+ text: string;
2348
+ props: RunProps;
2349
+ font: FontSpec;
2350
+ /** Footnote/endnote id referenced by this run (registration happens when
2351
+ * the item lands on a real page - split table rows carry it across). */
2352
+ noteId?: number;
2353
+ /** Vertical stretch for tall delimiter glyphs (Word's glyph variants). */
2354
+ mathScaleY?: number;
2355
+ /** Horizontal stretch for wide brace glyphs (Word's over/under brace
2356
+ * variants), applied about the glyph box's horizontal center. */
2357
+ mathScaleX?: number;
2358
+ /** Stretch anchor above the baseline, px. */
2359
+ mathScaleAnchor?: number;
2360
+ /** Line box for selection/highlight backgrounds. */
2361
+ lineTop: number;
2362
+ lineHeight: number;
2363
+ /** Exact glyph box for baseline-shifted runs (superscript/subscript):
2364
+ * the renderer anchors these instead of bottoming on the line box. */
2365
+ glyphTop?: number;
2366
+ glyphBoxH?: number;
2367
+ /** Small-caps reduced segment: the base run font that must supply the
2368
+ * strut so the painted baseline matches neighboring full-size spans (the
2369
+ * renderer sizes the outer span with this font and shrinks the text via
2370
+ * a baseline-aligned inner span). */
2371
+ strutFont?: FontSpec;
2372
+ /** PAGEREF bookmark name: the final pass rewrites this item's text with
2373
+ * the bookmark's page number (Word recomputes PAGEREF on open; the docx
2374
+ * cached result is stale in real TOCs). */
2375
+ pageRef?: string;
2376
+ /** DOCX bookmarks that begin on this text item. */
2377
+ bookmarks?: string[];
2378
+ /** Source m:oMath element when this text is a piece of an equation. */
2379
+ mathSrc?: XmlElement;
2380
+ href?: string;
2381
+ /** Present for editable text (absent on numbering labels etc.). */
2382
+ src?: TextSource;
2383
+ /** This line is one a fixed-size text box hides past its bottom edge (see
2384
+ * LaidOutPage.hiddenText). It mounts unpainted so a caret can bind to it, so
2385
+ * anything that draws from item geometry — selection, comment highlights —
2386
+ * must skip it or it paints a block where there is no text. */
2387
+ hidden?: true;
2388
+ /** The box an exact-height table row clips this line to (page px): the
2389
+ * line starts inside the row but crosses its bottom edge, and only the
2390
+ * part inside the box is drawn, as Word draws it. */
2391
+ clip?: {
2392
+ top: number;
2393
+ bottom: number;
2394
+ };
2395
+ /** The text is part of a tracked change, or its paragraph's format was
2396
+ * changed: a printed markup page bars the line in the margin. */
2397
+ changed?: true;
2398
+ /** Printed markup: this empty item is the clear space after a tracked
2399
+ * change that ends inside a word, where the change's bar goes. */
2400
+ changeGap?: true;
2401
+ /** Source drawing when this text belongs to an independently editable
2402
+ * text-box story. */
2403
+ textboxStory?: XmlElement;
2404
+ /** Rotate about a point (px, relative to this item's top-left). */
2405
+ rotate?: {
2406
+ deg: number;
2407
+ ox: number;
2408
+ oy: number;
2409
+ };
2410
+ /** Paint under the body text (behindDoc textbox content). */
2411
+ behind?: boolean;
2412
+ /** Paint over the body text (non-behindDoc anchored shape content: Word
2413
+ * layers in-front shapes above the text layer). */
2414
+ front?: boolean;
2415
+ z?: number;
2416
+ /** Paint-only alpha for decorative text such as DrawingML WordArt. */
2417
+ opacity?: number;
2418
+ /** Right-to-left run: renderer sets direction:rtl so the browser shapes and
2419
+ * orders the (Arabic/Hebrew) glyphs within the span box. */
2420
+ rtl?: boolean;
2421
+ /** Ordinal of the source paragraph within its cell/frame. Set only for
2422
+ * widow-controlled paragraphs; row splitting uses it to scope Word's
2423
+ * widow/orphan rules to the paragraph straddling the cut. */
2424
+ paraSeq?: number;
2425
+ /** Editor-only: maximum caret x for this item — a trailing hanging space
2426
+ * confined to its table cell pins the caret at the cell's content edge
2427
+ * (Word behavior) while the span keeps its true hanging layout x. */
2428
+ caretClampX?: number;
2429
+ /** A trailing space hung past the line's end: it draws no underline or strike. */
2430
+ hanging?: boolean;
2431
+ }
2432
+ interface RectItem {
2433
+ kind: "rect";
2434
+ x: number;
2435
+ y: number;
2436
+ width: number;
2437
+ height: number;
2438
+ fill: string;
2439
+ /** Semantic paint provenance used by render-layer comparison. */
2440
+ role?: "table-fill";
2441
+ /** Rotate about a point (px, relative to this item's top-left). */
2442
+ rotate?: {
2443
+ deg: number;
2444
+ ox: number;
2445
+ oy: number;
2446
+ };
2447
+ behind?: boolean;
2448
+ /** Paint over the body text (non-behindDoc anchored shape fill). */
2449
+ front?: boolean;
2450
+ z?: number;
2451
+ }
2452
+ interface LineEdgeItem {
2453
+ kind: "edge";
2454
+ x1: number;
2455
+ y1: number;
2456
+ x2: number;
2457
+ y2: number;
2458
+ border: Border;
2459
+ /** PDF paint extensions along the rule; layout keeps the original endpoints. */
2460
+ extendStart?: number;
2461
+ extendEnd?: number;
2462
+ /** The box's shadow strip, and its extension past the bottom-right corner. */
2463
+ shadowSide?: "right" | "bottom";
2464
+ shadowEnd?: number;
2465
+ /** Semantic paint provenance used by render-layer comparison. */
2466
+ role?: "table-rule";
2467
+ /** Rotate about a point (px, relative to this item's top-left). */
2468
+ rotate?: {
2469
+ deg: number;
2470
+ ox: number;
2471
+ oy: number;
2472
+ };
2473
+ /** Paint over the body text (non-behindDoc anchored shape border). */
2474
+ front?: boolean;
2475
+ /** Paint below the body text (behindDoc anchored shape border). */
2476
+ behind?: boolean;
2477
+ z?: number;
2478
+ }
2479
+ interface ImageItem {
2480
+ kind: "image";
2481
+ x: number;
2482
+ y: number;
2483
+ width: number;
2484
+ height: number;
2485
+ /** Package part path; renderer resolves bytes via DocxDocument.media(). */
2486
+ part: string;
2487
+ /** a:srcRect crop (fractions) and a:xfrm rotation (degrees). */
2488
+ crop?: {
2489
+ l: number;
2490
+ t: number;
2491
+ r: number;
2492
+ b: number;
2493
+ };
2494
+ rotation?: number;
2495
+ /** Whole-group rotation about an external origin. */
2496
+ rotate?: {
2497
+ deg: number;
2498
+ ox: number;
2499
+ oy: number;
2500
+ };
2501
+ /** Picture-watermark "washout" (VML v:imagedata gain/blacklevel, 0..1
2502
+ * fractions). Per-channel linear recolor, measured against Word's PDF of
2503
+ * probe2-picture-watermark (gain 0.3, blacklevel 0.35: source 32 -> 215,
2504
+ * 74 -> 227, 135 -> 246, 210 -> clamped 255):
2505
+ * out = in * gain + 255 * (blacklevel * (1 + gain) + (1 - gain) / 2) */
2506
+ washout?: {
2507
+ gain: number;
2508
+ blacklevel: number;
2509
+ };
2510
+ /** a:ln picture outline, drawn just outside the image (Word hairline). */
2511
+ border?: {
2512
+ color: string;
2513
+ width: number;
2514
+ };
2515
+ /** behindDoc: paint under the text layer. */
2516
+ behind?: boolean;
2517
+ /** wrapNone + !behindDoc ("in front of text"): paint ABOVE the text layer
2518
+ * (Word's z-order; without this, later-emitted text spans cover the image
2519
+ * and it neither shows in front nor receives clicks/drags). */
2520
+ front?: boolean;
2521
+ z?: number;
2522
+ /** Source w:drawing element (for interactive resize/move). */
2523
+ src?: XmlElement;
2524
+ model3D?: Model3DReference;
2525
+ webVideo?: WebVideoReference;
2526
+ embeddedObject?: EmbeddedObjectReference;
2527
+ /** Printed markup: the tracked changes the picture's run is part of, and
2528
+ * the run's revision color, which frames the picture (and strikes a
2529
+ * deleted one). A balloon and a change bar go with them, as for text. */
2530
+ changes?: Revision[];
2531
+ changeColor?: string;
2532
+ }
2533
+ interface ChartItem {
2534
+ kind: "chart";
2535
+ x: number;
2536
+ y: number;
2537
+ width: number;
2538
+ height: number;
2539
+ data: ChartData;
2540
+ }
2541
+ /** bodyPr autofit mode: how a shape reconciles its text with its box.
2542
+ * "resizeShape" is a:spAutoFit (grow the box), "shrinkText" is a:normAutofit
2543
+ * (scale the text down), "none" is a:noAutofit or no bodyPr autofit at all. */
2544
+ type ShapeAutofit = "none" | "resizeShape" | "shrinkText";
2545
+ /** What a text-bearing shape's laid-out text measured, beside the frame that
2546
+ * holds it. The layout already measures the text to place it; recording the
2547
+ * measurement here is what lets an agent see whether the text fits without
2548
+ * re-measuring anything. */
2549
+ interface DrawingTextFit {
2550
+ /** Widest laid line, px (the text extent, not the box). It can exceed the
2551
+ * box's inset width by a trailing space or an unbreakable token. */
2552
+ textW: number;
2553
+ /** Full laid text height, px. */
2554
+ textH: number;
2555
+ /** The text is taller than the box's insets leave room for. Overflow is a
2556
+ * vertical question: the text is wrapped to the box width by construction,
2557
+ * and a token too wide to wrap spends its excess on extra LINES. */
2558
+ overflow: boolean;
2559
+ /** Lines the box hides because they fall past its bottom. */
2560
+ clippedLines: number;
2561
+ autofit: ShapeAutofit;
2562
+ }
2563
+ /** Interactive resize zone over a table boundary (column or row). */
2564
+ interface DrawingHitItem {
2565
+ kind: "drawingHit";
2566
+ x: number;
2567
+ y: number;
2568
+ width: number;
2569
+ height: number;
2570
+ /** Source w:drawing element (select/move the whole drawing). */
2571
+ src: XmlElement;
2572
+ /** Anchored drawings drag by offset; inline ones re-anchor into text. */
2573
+ anchored: boolean;
2574
+ /** Freehand stroke that may be removed with the Draw ribbon's eraser. */
2575
+ ink?: boolean;
2576
+ /** Native SmartArt diagram selection target. */
2577
+ smartArt?: boolean;
2578
+ /** Node hit boxes inside the SmartArt drawing, relative to this item. */
2579
+ smartArtNodes?: Array<{
2580
+ index: number;
2581
+ x: number;
2582
+ y: number;
2583
+ width: number;
2584
+ height: number;
2585
+ }>;
2586
+ chartData?: ChartData;
2587
+ smartArtData?: SmartArtData;
2588
+ /** A shape fill hit that sits UNDER the shape's own text spans (same z): a
2589
+ * click on bare fill selects or drags the shape, while clicks on its text
2590
+ * glyphs still reach the text editor. */
2591
+ belowText?: boolean;
2592
+ /** Keep a behindDoc drawing target under the body text. */
2593
+ behind?: boolean;
2594
+ /** The drawing owns an independently editable text-box story. */
2595
+ textboxStory?: boolean;
2596
+ /** Measured text extent for a text-bearing shape (agent fit inspection).
2597
+ * Absent on drawings that flow no text: pictures, lines, charts, WordArt. */
2598
+ textFit?: DrawingTextFit;
2599
+ rotate?: {
2600
+ deg: number;
2601
+ ox: number;
2602
+ oy: number;
2603
+ };
2604
+ z?: number;
2605
+ }
2606
+ interface GripItem {
2607
+ kind: "grip";
2608
+ /** "col": vertical zone at x spanning y1..y2. "row": horizontal zone at y1
2609
+ * spanning x..x2. "move": table bounds x..x2, y1..y2. */
2610
+ axis: "col" | "row" | "move";
2611
+ x: number;
2612
+ y1: number;
2613
+ y2: number;
2614
+ /** Right edge for row grips. */
2615
+ x2?: number;
2616
+ /** Source w:tbl element. */
2617
+ tbl: XmlElement;
2618
+ /** col: boundary 1..n (n = right edge). row: row index above the boundary. */
2619
+ boundary: number;
2620
+ /** Laid-out height of the row above (row grips), px. */
2621
+ rowHeightPx?: number;
2622
+ /** Rendered column widths px (col grips) — resize works in this space. */
2623
+ renderedWidths?: number[];
2624
+ }
2625
+ /** WordArt/watermark text scaled to fill a box, rotated about its center. */
2626
+ interface WordArtItem {
2627
+ kind: "wordart";
2628
+ /** Box top-left, px. */
2629
+ x: number;
2630
+ y: number;
2631
+ width: number;
2632
+ height: number;
2633
+ text: string;
2634
+ fontFamily: string;
2635
+ bold?: boolean;
2636
+ italic?: boolean;
2637
+ fill: string;
2638
+ opacity: number;
2639
+ /** Clockwise degrees. */
2640
+ rotation: number;
2641
+ behind?: boolean;
2642
+ /** Source v:textpath font-size (px). */
2643
+ fontSize?: number;
2644
+ /** Malformed shapetype guide path: Word collapses the fitted glyph outlines
2645
+ * into a thin vertical band. */
2646
+ noFit?: boolean;
2647
+ /** Source VML shape element (v:shape / v:rect), for interactive select/edit. */
2648
+ src?: XmlElement;
2649
+ }
2650
+ /** DrawingML a:prstTxWarp text: the shape's single text line bent onto a
2651
+ * preset envelope (arch/wave/chevron/circle-pour), filling the shape box. */
2652
+ interface WarpTextItem {
2653
+ kind: "warptext";
2654
+ /** Shape box top-left, px. */
2655
+ x: number;
2656
+ y: number;
2657
+ width: number;
2658
+ height: number;
2659
+ text: string;
2660
+ fontFamily: string;
2661
+ /** Run font size px (the text's natural size; presets that don't fill the
2662
+ * box — textArchUp — ride the text at this size). */
2663
+ fontSize: number;
2664
+ bold?: boolean;
2665
+ italic?: boolean;
2666
+ /** CSS text color. */
2667
+ fill: string;
2668
+ /** WordArt glyph alpha, 0..1. */
2669
+ opacity?: number;
2670
+ /** w14:textOutline glyph stroke. */
2671
+ outline?: {
2672
+ color: string;
2673
+ width: number;
2674
+ };
2675
+ /** w14:shadow / w:shadow offset glyph shadow. */
2676
+ shadow?: boolean;
2677
+ /** Preset name (textArchUp, textWave1, textChevron, textCirclePour, …). */
2678
+ warp: string;
2679
+ rotate?: {
2680
+ deg: number;
2681
+ ox: number;
2682
+ oy: number;
2683
+ };
2684
+ behind?: boolean;
2685
+ front?: boolean;
2686
+ z?: number;
2687
+ }
2688
+ type PageItem = TextItem | PathItem | RectItem | LineEdgeItem | ImageItem | ChartItem | DrawingHitItem | GripItem | WordArtItem | WarpTextItem;
2689
+ interface LaidOutPage {
2690
+ width: number;
2691
+ height: number;
2692
+ /** 1-based physical index. */
2693
+ index: number;
2694
+ /** Display page number after pgNumType.start is applied. */
2695
+ number: number;
2696
+ items: PageItem[];
2697
+ /** Body box (for header/footer editing chrome). */
2698
+ bodyTop: number;
2699
+ bodyBottom: number;
2700
+ /** Items from this index on belong to the header/footer parts. */
2701
+ hfStart: number;
2702
+ /** Column geometry for editor hit-testing. A page can contain more than one
2703
+ * band when a continuous section changes the column layout mid-page. */
2704
+ columnBands: Array<{
2705
+ top: number;
2706
+ colXs: number[];
2707
+ colWidths: number[];
2708
+ }>;
2709
+ /** Lines a fixed-size text box (a:noAutofit) hides past its bottom edge.
2710
+ * Held apart from `items` so nothing that paints, measures, or reads the
2711
+ * page picks them up: they exist only so a caret that lands in the hidden
2712
+ * part of a text-box story still has a place to be. */
2713
+ hiddenText?: TextItem[];
2714
+ }
2715
+ /** Internal page-model window used by the DOM virtualizer. */
2716
+ interface LayoutWindow {
2717
+ /** Ensure that each requested page has a complete positioned item model. */
2718
+ materialize(pageIndexes: Iterable<number>): void;
2719
+ /** Release positioned items outside the requested page window. */
2720
+ releaseExcept(pageIndexes: Iterable<number>): void;
2721
+ /** Return the pages whose positioned items are retained. */
2722
+ retainedPages(): Set<number>;
2723
+ }
2724
+ interface LayoutFontSample {
2725
+ font: FontSpec;
2726
+ text: string;
2727
+ }
2728
+ interface LayoutResult {
2729
+ pages: LaidOutPage[];
2730
+ totalPages: number;
2731
+ /** Opaque incremental-reuse state (engine-internal); pass a previous result
2732
+ * back as LayoutOptions.prev to enable incremental relayout. Not part of the
2733
+ * rendered output and ignored by the equivalence harness. */
2734
+ _incr?: unknown;
2735
+ /** Internal marker: unchanged pages in this result retain exact object
2736
+ * identity from the previous layout, so the DOM diff can use identity
2737
+ * instead of structurally walking a dense changed page. */
2738
+ _incremental?: boolean;
2739
+ /** Exclusive global page index through which an incremental render may run
2740
+ * pageEq before the page containing the exact dirty text source. */
2741
+ _incrementalStructuralPrefixEnd?: number;
2742
+ /** Opaque page state used to refresh headers/footers without repaginating
2743
+ * the body when their measured geometry is unchanged. */
2744
+ _hf?: unknown;
2745
+ /** Internal positioned-model window. */
2746
+ _window?: LayoutWindow;
2747
+ /** Font samples collected before offscreen page items were released. */
2748
+ _fontSamples?: LayoutFontSample[];
2749
+ /** True when any page contains a 3D model item. */
2750
+ _hasModel3D?: boolean;
2751
+ }
2752
+
2753
+ interface FontMetrics {
2754
+ /** px above baseline (raw font ascent - anchors CSS glyph boxes). */
2755
+ ascent: number;
2756
+ /** px below baseline, raw (positive - anchors CSS glyph boxes). */
2757
+ descent: number;
2758
+ /** Natural single-spaced line height px (what Word calls single spacing). */
2759
+ lineHeight: number;
2760
+ /** Word's below-baseline share of lineHeight (quantized); use for
2761
+ * baseline placement. Falls back to `descent` when absent. */
2762
+ lineDescent?: number;
2763
+ }
2764
+ interface TextMeasurer {
2765
+ width(text: string, font: FontSpec, letterSpacing?: number): number;
2766
+ /** Whether each suffix of this text has nondecreasing prefix widths.
2767
+ * Lets emergency wrapping search near the line end without measuring the
2768
+ * entire remaining token on every line. */
2769
+ isPrefixWidthMonotone?(text: string, font: FontSpec, letterSpacing?: number): boolean;
2770
+ metrics(font: FontSpec): FontMetrics;
2771
+ /** The browser's own font box (fontBoundingBoxAscent/Descent) for the
2772
+ * resolved first face of this font's CSS stack, when the host can know it.
2773
+ * Used to anchor paint-routed CJK spans: the DOM renderer centers glyphs
2774
+ * by the browser strut, which differs from the engine's calibrated line
2775
+ * profile (Hiragino/PingFang) whenever the real Windows face paints. */
2776
+ paintBox?(font: FontSpec): {
2777
+ ascent: number;
2778
+ descent: number;
2779
+ } | undefined;
2780
+ /** Ink extents (actualBoundingBox*) of `text` in the RESOLVED paint face,
2781
+ * px above/below the baseline. The radical join needs the √ glyph's real
2782
+ * ink — which face paints it (real Cambria Math vs the STIX substitute)
2783
+ * changes the extents, so a baked table can't cover both. */
2784
+ inkBox?(text: string, font: FontSpec): {
2785
+ ascent: number;
2786
+ descent: number;
2787
+ } | undefined;
2788
+ }
2789
+
2790
+ /** One mail-merge data record: column name → this record's value. The host
2791
+ * parses the data file and hands over plain strings; the engine never learns a
2792
+ * path, a connection string or a query. */
2793
+ type MergeRecord = Readonly<Record<string, string>>;
2794
+ interface LayoutOptions {
2795
+ measurer?: TextMeasurer;
2796
+ /** Retain positioned items only for a viewport-sized page window. */
2797
+ windowModel?: boolean;
2798
+ /** Mail-merge PREVIEW: the active record's column values, substituted into
2799
+ * MERGEFIELD fields as they are painted. Nothing is written to the document —
2800
+ * see FieldContext.mergeField. Absent renders the «Name» placeholders. */
2801
+ mergeRecord?: MergeRecord;
2802
+ /** Previous layout result (from an earlier layoutDocument call on the same
2803
+ * document). Enables incremental relayout: pages whose input blocks and
2804
+ * lead-in state are unchanged are reused instead of re-laid. The engine falls
2805
+ * back to a full layout whenever it cannot prove reuse is byte-identical. */
2806
+ prev?: LayoutResult;
2807
+ /** The top-level block XML element (w:p / w:tbl) the editor mutated IN PLACE
2808
+ * since `prev` — the paragraph the caret sits in for a single-character
2809
+ * type/delete. Lets the incremental scan skip re-hashing every block: it
2810
+ * re-hashes only the hinted block and its two neighbours and reuses prev's
2811
+ * per-block signatures for the rest. Purely an optimisation — the fast path
2812
+ * is gated on block identity/count and neighbour-signature checks, so a stale
2813
+ * or wrong hint falls through to the full block scan. */
2814
+ dirtyHint?: XmlElement;
2815
+ /** Exact retained text element changed by a local edit. Used only to bound
2816
+ * structural page comparison before the first actually dirty page. */
2817
+ dirtySource?: XmlElement;
2818
+ }
2819
+ interface AsyncLayoutOptions extends LayoutOptions {
2820
+ /** Cancels a superseded background layout before its result is painted. */
2821
+ signal?: AbortSignal;
2822
+ /** Maximum main-thread time spent between event-loop yields. */
2823
+ sliceMs?: number;
2824
+ }
2825
+ declare function layoutDocument(doc: DocxDocument, options?: LayoutOptions): LayoutResult;
2826
+ /** Full layout that yields between top-level blocks for large interactive
2827
+ * documents. The completed result is identical to layoutDocument; callers
2828
+ * should paint it atomically and discard it when the signal is aborted. */
2829
+ declare function layoutDocumentAsync(doc: DocxDocument, options?: AsyncLayoutOptions): Promise<LayoutResult>;
2830
+
2831
+ interface RenderOptions {
2832
+ /** Zoom factor (1 = 100%). */
2833
+ zoom?: number;
2834
+ /** Gap between pages, px. */
2835
+ pageGap?: number;
2836
+ /** Page drop shadow / chrome. */
2837
+ pageShadow?: boolean;
2838
+ /** Materialize interactive affordances (table resize grips). */
2839
+ interactive?: boolean;
2840
+ /** Keep only nearby page contents mounted. Page shells always remain so
2841
+ * scroll geometry is unchanged. Intended for long interactive documents. */
2842
+ virtualize?: boolean;
2843
+ /** Called after the mounted page window changes so editor chrome can be
2844
+ * restored on newly-mounted pages. */
2845
+ onViewportChange?: () => void;
2846
+ /** Show review comments (highlight + margin balloons). Default true. */
2847
+ comments?: boolean;
2848
+ /** Called when the user deletes a comment from its balloon. The balloon
2849
+ * shows a delete button only when this is provided. */
2850
+ onDeleteComment?: (id: string) => void;
2851
+ /** Called when the user submits a reply from a balloon's reply box. The
2852
+ * reply box only renders when this is provided. */
2853
+ onReplyComment?: (id: string, text: string) => void;
2854
+ /** Called when the user resolves (true) or reopens (false) a thread from
2855
+ * its balloon. The button only renders when this is provided. */
2856
+ onResolveComment?: (id: string, resolved: boolean) => void;
2857
+ /** Called when the user commits an in-balloon edit of a comment's text.
2858
+ * Offered only on comments whose author matches `commentAuthor`. */
2859
+ onEditComment?: (id: string, text: string) => void;
2860
+ /** The local user's comment author name — gates the edit affordance to
2861
+ * their own comments (Word's edit-my-comment rule). */
2862
+ commentAuthor?: string;
2863
+ }
2864
+ interface TextBinding {
2865
+ el: HTMLElement;
2866
+ item: TextItem;
2867
+ }
2868
+ interface GripBinding {
2869
+ el: HTMLElement;
2870
+ item: GripItem;
2871
+ }
2872
+ interface ImageBinding {
2873
+ el: HTMLElement;
2874
+ item: ImageItem;
2875
+ }
2876
+ interface DrawingBinding {
2877
+ el: HTMLElement;
2878
+ item: DrawingHitItem;
2879
+ }
2880
+ interface WordArtBinding {
2881
+ el: HTMLElement;
2882
+ item: WordArtItem;
2883
+ }
2884
+ interface RenderHandle {
2885
+ /** Root element containing all pages. */
2886
+ root: HTMLElement;
2887
+ /** Rendered text elements in paint order, for selection mapping. */
2888
+ bindings: TextBinding[];
2889
+ /** Mounted text bindings indexed by their retained source w:t element. */
2890
+ bindingsByText: Map<XmlElement, TextBinding[]>;
2891
+ /** Table resize grips (only when options.interactive). */
2892
+ grips: GripBinding[];
2893
+ /** Rendered images, for interactive select/resize/move. */
2894
+ images: ImageBinding[];
2895
+ /** Transparent hit targets over vector drawings/icons (select/move). */
2896
+ drawings: DrawingBinding[];
2897
+ /** WordArt / text watermarks, for interactive select/edit. */
2898
+ wordarts: WordArtBinding[];
2899
+ /** Revoke object URLs etc. */
2900
+ destroy: () => void;
2901
+ /** Temporarily mount every page, returning a function that restores the
2902
+ * viewport window. Used by the synchronous print-clone path. */
2903
+ materializeAll?: () => () => void;
2904
+ /** Recompute the mounted page window after an external scroll/resize. */
2905
+ updateViewport?: () => void;
2906
+ /** Per-page render records, retained so the next render can reuse the DOM of
2907
+ * pages whose layout is unchanged (see renderToDom's `prev` parameter). */
2908
+ _pages?: PageRender[];
2909
+ /** Whether this render drew the comments overlay. Comment highlights live
2910
+ * INSIDE page surfaces, so the next render must sweep them out of any page
2911
+ * DOM it adopts before re-running the overlay. */
2912
+ _hadComments?: boolean;
2913
+ /** Zoom this render painted at — adoption is only valid at the same zoom. */
2914
+ _zoom?: number;
2915
+ /** Whether this handle keeps only a viewport-sized page window mounted. */
2916
+ _virtualized?: boolean;
2917
+ /** Parsed-model generation whose source bindings this handle owns. */
2918
+ _modelVersion?: number;
2919
+ /** Remove viewport listeners before this handle is replaced. */
2920
+ _stopVirtualizer?: () => void;
2921
+ }
2922
+ /** One page's DOM element plus the editor bindings it owns and the object URLs
2923
+ * it created. Retained on the handle so an incremental re-render can adopt an
2924
+ * unchanged page wholesale instead of tearing it down and rebuilding it. */
2925
+ interface PageRender {
2926
+ el: HTMLElement;
2927
+ page: LaidOutPage;
2928
+ bindings: TextBinding[];
2929
+ grips: GripBinding[];
2930
+ images: ImageBinding[];
2931
+ drawings: DrawingBinding[];
2932
+ wordarts: WordArtBinding[];
2933
+ urls: string[];
2934
+ mounted: boolean;
2935
+ }
2936
+ declare function renderToDom(doc: DocxDocument, layout: LayoutResult, container: HTMLElement, options?: RenderOptions, prev?: RenderHandle): RenderHandle;
2937
+ /**
2938
+ * Print the rendered pages (browser print -> paper or PDF): clones the page
2939
+ * DOM into a hidden same-origin iframe sized to the document's page, strips
2940
+ * screen chrome (shadows, gaps), and invokes the print dialog.
2941
+ */
2942
+ declare function printPages(root: HTMLElement, pageWidthPx: number, pageHeightPx: number): void;
2943
+
2944
+ export { type ChartData as C, DocxDocument as D, type EncodedCaret as E, type MergeRecord as M, type RunProps as R, StableIds as S, type XmlElement as X, type Run as a, type SmartArtData as b, DocxDocument$1 as c, layoutDocumentAsync as d, layoutDocument as l, printPages as p, renderToDom as r };