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