wordinweb 0.3.7 → 0.3.9

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,2729 +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
- /** Markup view: the paragraph mark itself is a tracked insertion or
948
- * deletion (a suggested line break, or a suggested merge). Layout draws it
949
- * as a pilcrow in the revision's colors after the paragraph's content; it is
950
- * not text, so find, word count and the like never see it. */
951
- markRevision?: "ins" | "del";
952
- /** Source w:p element. */
953
- src?: XmlElement;
954
- }
955
- interface TableCellProps {
956
- /** Preferred width px (from tcW when dxa). */
957
- width?: number;
958
- /** Preferred width as a fraction of the table width (from tcW when pct). */
959
- widthPct?: number;
960
- /** The source explicitly declares tcW type="auto" (distinct from no tcW). */
961
- widthAuto?: boolean;
962
- gridSpan: number;
963
- vMerge?: "restart" | "continue";
964
- borders?: {
965
- top?: Border;
966
- bottom?: Border;
967
- left?: Border;
968
- right?: Border;
969
- tl2br?: Border;
970
- tr2bl?: Border;
971
- };
972
- shading?: string;
973
- /** Cell margins px. */
974
- margins?: {
975
- top?: number;
976
- right?: number;
977
- bottom?: number;
978
- left?: number;
979
- };
980
- verticalAlign?: "top" | "center" | "bottom";
981
- textDirection?: "btLr" | "tbRl";
982
- }
983
- interface TableCell {
984
- props: TableCellProps;
985
- blocks: Block[];
986
- }
987
- interface TableRowProps {
988
- /** px; undefined = auto */
989
- height?: number;
990
- heightRule?: "auto" | "atLeast" | "exact";
991
- cantSplit?: boolean;
992
- /** Repeat as header row on each page. */
993
- tblHeader?: boolean;
994
- }
995
- interface TableRow {
996
- props: TableRowProps;
997
- cells: TableCell[];
998
- }
999
- interface TableProps {
1000
- styleId?: string;
1001
- /** px table indent from left margin. */
1002
- indent?: number;
1003
- alignment?: Alignment;
1004
- /** w:bidiVisual — RTL table: column order reverses and the table hugs the
1005
- * right margin. */
1006
- bidiVisual?: boolean;
1007
- borders?: {
1008
- top?: Border;
1009
- bottom?: Border;
1010
- left?: Border;
1011
- right?: Border;
1012
- insideH?: Border;
1013
- insideV?: Border;
1014
- };
1015
- /** Default cell margins px. */
1016
- cellMargins?: {
1017
- top?: number;
1018
- right?: number;
1019
- bottom?: number;
1020
- left?: number;
1021
- };
1022
- /** w:tblCellSpacing px — old-style separated cell borders: every cell gets
1023
- * its own border box inset by this much from the grid slot on all sides
1024
- * (adjacent cells end up 2x apart), and the table outline is a separate box
1025
- * around everything. */
1026
- cellSpacing?: number;
1027
- /** w:tblpPr — floating table: absolutely positioned against page/margin/
1028
- * column, painted over an opaque white sheet, with body text (including
1029
- * text EARLIER in the flow on the same page) wrapping square around it. */
1030
- floating?: {
1031
- hAnchor: "page" | "margin" | "text";
1032
- vAnchor: "page" | "margin" | "text";
1033
- /** tblpX/tblpY px (absent when an alignment keyword is used). */
1034
- x?: number;
1035
- y?: number;
1036
- xAlign?: "left" | "center" | "right";
1037
- yAlign?: "top" | "center" | "bottom";
1038
- /** Wrap distances px (leftFromText, …). */
1039
- dist: {
1040
- l: number;
1041
- r: number;
1042
- t: number;
1043
- b: number;
1044
- };
1045
- /** w:tblOverlap "never": shift clear of earlier floating tables. */
1046
- allowOverlap: boolean;
1047
- };
1048
- /** Preferred total width px (tblW dxa) or undefined for auto. */
1049
- width?: number;
1050
- /** Preferred total width as a fraction of available width (tblW pct). */
1051
- widthPct?: number;
1052
- layout?: "fixed" | "autofit";
1053
- /** w:tblLook flags controlling which conditional formats apply. */
1054
- tblLook?: TableLook;
1055
- }
1056
- /** w:tblLook flags controlling which conditional table-style formats apply. */
1057
- interface TableLook {
1058
- firstRow: boolean;
1059
- lastRow: boolean;
1060
- firstColumn: boolean;
1061
- lastColumn: boolean;
1062
- noHBand: boolean;
1063
- noVBand: boolean;
1064
- }
1065
- interface Table {
1066
- type: "table";
1067
- props: TableProps;
1068
- /** Column grid widths px (tblGrid). */
1069
- grid: number[];
1070
- rows: TableRow[];
1071
- /** Source w:tbl element. */
1072
- src?: XmlElement;
1073
- }
1074
- type Block = Paragraph | Table;
1075
- interface HeaderFooterRefs {
1076
- default?: string;
1077
- first?: string;
1078
- even?: string;
1079
- }
1080
- interface ColumnSpec {
1081
- count: number;
1082
- /** Space between columns px. */
1083
- space: number;
1084
- /** Explicit widths px when equalWidth=false. */
1085
- widths?: number[];
1086
- /** Per-column trailing space px (w:col w:space), when explicit w:col
1087
- * entries are present. spaces[i] separates column i from column i+1. */
1088
- spaces?: number[];
1089
- /** w:cols w:sep: paint a vertical rule centered in each inter-column gap. */
1090
- sep?: boolean;
1091
- }
1092
- interface SectionProps {
1093
- pageWidth: number;
1094
- pageHeight: number;
1095
- marginTop: number;
1096
- marginRight: number;
1097
- marginBottom: number;
1098
- marginLeft: number;
1099
- /** Distance of header top from page top, px (w:headerReference distance). */
1100
- headerDistance: number;
1101
- footerDistance: number;
1102
- gutter: number;
1103
- headerRefs: HeaderFooterRefs;
1104
- footerRefs: HeaderFooterRefs;
1105
- /** Different first-page header/footer enabled. */
1106
- titlePage: boolean;
1107
- /** Page numbering restart value, if set. */
1108
- pageNumberStart?: number;
1109
- pageNumberFormat?: string;
1110
- columns: ColumnSpec;
1111
- /** w:docGrid type=lines/linesAndChars: minimum single-line height (px) that
1112
- * the line-spacing multiplier is applied over. Word snaps every line's font
1113
- * height up to this grid pitch (CJK documents). */
1114
- docGridLinePitch?: number;
1115
- /** Present w:docGrid type; omitted w:type means "default". */
1116
- docGridType?: "default" | "lines" | "linesAndChars" | "snapToChars";
1117
- /** w:docGrid type="charsAndLines": a combined char+line grid that (in compat
1118
- * 15) keeps natural East-Asian line pitch. Drives the CJK line-height
1119
- * correction during measurement. */
1120
- docGridCharGrid?: boolean;
1121
- type?: "nextPage" | "continuous" | "evenPage" | "oddPage" | "nextColumn";
1122
- /** Vertical alignment of page content. */
1123
- vAlign?: "top" | "center" | "both" | "bottom";
1124
- /** w:pgBorders. Offsets (border.space, px) measure from text or page edge. */
1125
- pageBorders?: {
1126
- top?: Border;
1127
- bottom?: Border;
1128
- left?: Border;
1129
- right?: Border;
1130
- offsetFrom: "text" | "page";
1131
- };
1132
- /** w:lnNumType: margin line numbering. distance px from the text edge.
1133
- * start is the raw w:start OFFSET (0 when the attribute is absent, its
1134
- * literal value otherwise) added to the running per-line count — see
1135
- * parse/section.ts for why an absent attribute isn't just "start 1". */
1136
- lineNumbering?: {
1137
- countBy: number;
1138
- start: number;
1139
- distance: number;
1140
- restart: "continuous" | "newPage" | "newSection";
1141
- };
1142
- /** Footnote/endnote mark numbering (w:footnotePr / w:endnotePr). */
1143
- footnoteNumFmt?: string;
1144
- footnoteNumStart?: number;
1145
- endnoteNumFmt?: string;
1146
- endnoteNumStart?: number;
1147
- /** w:numRestart: when the mark counter resets. Absent means "continuous"
1148
- * (the whole document shares one counter — this engine's only honored
1149
- * value; eachSect/eachPage are round-trip preserved but not laid out). */
1150
- footnoteNumRestart?: "continuous" | "eachSect" | "eachPage";
1151
- endnoteNumRestart?: "continuous" | "eachSect" | "eachPage";
1152
- /** w:pos: where the note text is placed. Round-trip preserved only — the
1153
- * layout always places footnotes at the page bottom and endnotes at the
1154
- * document end, regardless of this value. */
1155
- footnotePos?: "pageBottom" | "beneathText";
1156
- endnotePos?: "sectEnd" | "docEnd";
1157
- /** w:textDirection tbRl: the whole section flows as East-Asian vertical
1158
- * writing — lines run top-to-bottom, progressing right-to-left. */
1159
- textDirection?: "tbRl";
1160
- }
1161
- interface Section {
1162
- props: SectionProps;
1163
- blocks: Block[];
1164
- }
1165
- /** A review comment from word/comments.xml. */
1166
- interface DocComment {
1167
- id: string;
1168
- author: string;
1169
- initials?: string;
1170
- /** ISO timestamp from w:date, verbatim. */
1171
- date?: string;
1172
- /** Plain text of the comment body (paragraphs joined with newlines). */
1173
- text: string;
1174
- /** w14:paraId of the comment's last body paragraph (threading key). */
1175
- paraId?: string;
1176
- /** Parent comment id when this comment is a reply (commentsExtended). */
1177
- parentId?: string;
1178
- /** Thread resolved (w15:commentEx w15:done="1" — the [MS-DOCX] CT_CommentEx
1179
- * extension; ECMA-376 itself has no resolved state). Meaningful on the
1180
- * thread parent; Word grays the whole thread from the parent's flag. */
1181
- resolved?: boolean;
1182
- }
1183
- interface HeaderFooter {
1184
- blocks: Block[];
1185
- }
1186
- /** One w:tblStylePr conditional-formatting block (firstRow, band1Horz, …). */
1187
- interface TableCondFormat {
1188
- /** Cell shading fill as CSS color. */
1189
- shd?: string;
1190
- /** Conditional cell borders. */
1191
- borders?: {
1192
- top?: Border;
1193
- bottom?: Border;
1194
- left?: Border;
1195
- right?: Border;
1196
- insideH?: Border;
1197
- insideV?: Border;
1198
- };
1199
- /** Conditional run bold (firstRow/firstCol headers). */
1200
- bold?: boolean;
1201
- /** Full conditional run props (w:tblStylePr > w:rPr). */
1202
- rPr?: RunProps;
1203
- }
1204
- type TableCondType = "wholeTable" | "band1Vert" | "band2Vert" | "band1Horz" | "band2Horz" | "firstRow" | "lastRow" | "firstCol" | "lastCol" | "nwCell" | "neCell" | "swCell" | "seCell";
1205
- interface Style {
1206
- id: string;
1207
- type: "paragraph" | "character" | "table" | "numbering";
1208
- name?: string;
1209
- basedOn?: string;
1210
- isDefault?: boolean;
1211
- pPr?: ParaProps;
1212
- rPr?: RunProps;
1213
- tblPr?: TableProps;
1214
- /** w:tblStylePr conditional formats, by type (table styles only). */
1215
- condFormats?: Map<TableCondType, TableCondFormat>;
1216
- /** w:tblStyleRowBandSize / ColBandSize (default 1). */
1217
- rowBandSize?: number;
1218
- colBandSize?: number;
1219
- }
1220
- interface Styles {
1221
- byId: Map<string, Style>;
1222
- defaultParagraphStyle?: string;
1223
- defaultRPr: RunProps;
1224
- defaultPPr: ParaProps;
1225
- }
1226
- interface NumberingLevel {
1227
- ilvl: number;
1228
- start: number;
1229
- format: string;
1230
- /** Template like "%1." */
1231
- text: string;
1232
- alignment: Alignment;
1233
- /** Paragraph props contributed by the level (indents). */
1234
- pPr?: ParaProps;
1235
- rPr?: RunProps;
1236
- suffix: "tab" | "space" | "nothing";
1237
- restartAfter?: number;
1238
- }
1239
- interface AbstractNum {
1240
- id: number;
1241
- levels: Map<number, NumberingLevel>;
1242
- numStyleLink?: string;
1243
- }
1244
- interface NumInstance {
1245
- numId: number;
1246
- abstractNumId: number;
1247
- overrides: Map<number, {
1248
- startOverride?: number;
1249
- level?: NumberingLevel;
1250
- }>;
1251
- }
1252
- interface Numbering {
1253
- abstract: Map<number, AbstractNum>;
1254
- instances: Map<number, NumInstance>;
1255
- }
1256
- interface Theme {
1257
- majorFont: string;
1258
- minorFont: string;
1259
- majorBidiFont?: string;
1260
- minorBidiFont?: string;
1261
- /** East Asian faces from theme <a:ea> (fontScheme major/minorFont). Word's
1262
- * eastAsiaTheme="minor/majorEastAsia" resolves through these, NOT the Latin
1263
- * minor/major font — routing a CJK run's theme reference to the Latin face
1264
- * (Calibri) leaves East Asian text in a glyphless Latin font. */
1265
- majorEastAsiaFont?: string;
1266
- minorEastAsiaFont?: string;
1267
- colors: Map<string, string>;
1268
- }
1269
-
1270
- /** A read-only view over the OPC (zip) package inside a .docx file. */
1271
- declare class Package {
1272
- private files;
1273
- constructor(data: Uint8Array);
1274
- static from(data: ArrayBuffer | Uint8Array): Package;
1275
- /** A package over an already-unzipped entry map (DocxDocument.clone). */
1276
- static fromFiles(files: Record<string, Uint8Array>): Package;
1277
- has(name: string): boolean;
1278
- binary(name: string): Uint8Array | undefined;
1279
- text(name: string): string | undefined;
1280
- names(): string[];
1281
- /** Raw entry map (shared, do not mutate) — used for write-back. */
1282
- raw(): Record<string, Uint8Array>;
1283
- /** OPC part names never start with '/' inside the zip; tolerate both. */
1284
- private normalize;
1285
- }
1286
-
1287
- /**
1288
- * Stable node identity for replicated editing.
1289
- *
1290
- * Positions on the wire cannot be object references, and numeric child paths
1291
- * shift under concurrent structural edits — so blocks (w:p, w:tbl) and runs
1292
- * (w:r) get stable numeric ids held in an in-memory side table. The table is
1293
- * identity-keyed and NEVER serialized into the XML: writing ids as attributes
1294
- * would dirty every part on open and break the byte-identical round-trip
1295
- * guarantee for untouched parts.
1296
- *
1297
- * Assignment is deterministic: a document-order walk over the given roots,
1298
- * so two replicas that parse the same document derive the same table. Nodes
1299
- * created later by edits get ids explicitly (locally via `assign`, or from a
1300
- * replicated edit that carries the originating client's allocation) — a
1301
- * re-walk after edits only fills gaps and never renumbers survivors, because
1302
- * the table is keyed by element identity and in-place XML mutation preserves
1303
- * identity across `refresh()`.
1304
- */
1305
- type StableId$2 = number;
1306
- interface EncodedCaret {
1307
- blockId: StableId$2;
1308
- runId: StableId$2;
1309
- /** Offset in the run's WIRE space: cumulative through the run's inline
1310
- * content in document order, where each w:t contributes its text length
1311
- * and each inline separator (w:tab / w:br / w:cr) contributes ONE unit.
1312
- * Counting separators makes encoding ONE-TO-ONE: a caret at the end of
1313
- * the w:t before a tab and one at the start of the w:t after it are
1314
- * different physical positions and get different wire offsets — without
1315
- * the separator unit both collapsed to the same number and the decoder
1316
- * had to guess (review bug: boundary intents applied into the wrong w:t
1317
- * on remote replicas, and boundary-starting ranges always rejected). */
1318
- offset: number;
1319
- }
1320
- declare class StableIds {
1321
- private byEl;
1322
- private byId;
1323
- private next;
1324
- /** Document-order assignment over the given roots (typically
1325
- * `doc.editableRoots()`). Idempotent: elements that already have ids keep
1326
- * them; untracked ids are assigned in walk order. Call after load and
1327
- * after any edit that created tracked nodes without explicit ids. */
1328
- assignFromRoots(roots: XmlElement[]): void;
1329
- /**
1330
- * Assign ids inside the given subtrees only — the scoped counterpart of
1331
- * assignFromRoots, for an edit that is known to have created nodes in one
1332
- * or two paragraphs (dirty-scoped reconciliation, perf B9/B10).
1333
- *
1334
- * EQUIVALENCE (the property the scoped hot path rests on): this produces
1335
- * the same table a full assignFromRoots would, PROVIDED every tracked node
1336
- * outside the subtrees already has an id. Assignment is order-dependent —
1337
- * fresh nodes take sequential numbers from `next` in walk order — and a
1338
- * subtree walk visits exactly a contiguous slice of the document-order
1339
- * walk, in the same order. So the only way the two can disagree is an
1340
- * un-id'd node elsewhere that the full walk would have numbered first.
1341
- * That invariant holds inductively: load/importSidecar ids everything, and
1342
- * every apply either ids the nodes it creates (carried ids), reports
1343
- * document scope (full refresh + full assign), or creates nodes only
1344
- * inside the subtrees passed here. Callers that cannot establish it must
1345
- * fall back to assignFromRoots.
1346
- */
1347
- assignFromSubtrees(subtrees: XmlElement[]): void;
1348
- private walk;
1349
- /** Explicitly assign an id to a newly created node. Local edits allocate
1350
- * (`assign(el)`); applying a replicated edit installs the carried value
1351
- * (`assign(el, carriedId)`). Carried ids must not collide. */
1352
- assign(el: XmlElement, id?: StableId$2): StableId$2;
1353
- /** Force `el` to carry `id`, replacing any id it already has (e.g. one
1354
- * auto-assigned by a refresh() before a carried id could be installed).
1355
- * The previous id is retired. Throws if `id` is held by a different element. */
1356
- reassign(el: XmlElement, id: StableId$2): void;
1357
- /** Drop an element's mapping entirely; its id retires (never reused —
1358
- * `next` stays monotonic). Used before carried-id assignment: a refresh
1359
- * inside a mutation auto-assigns sequential ids to the nodes it created,
1360
- * and one of those autos can equal a LATER id of the same carried batch,
1361
- * which would make reassign throw on a perfectly good intent. No-op for an
1362
- * unmapped element. */
1363
- unassign(el: XmlElement): void;
1364
- private install;
1365
- idOf(el: XmlElement): StableId$2 | undefined;
1366
- elOf(id: StableId$2): XmlElement | undefined;
1367
- /** Drop mappings for elements no longer reachable from the given roots
1368
- * (deleted content). Keeps the table from growing across long sessions.
1369
- * Ids of dropped elements are retired, never reused. */
1370
- prune(roots: XmlElement[]): void;
1371
- size(): number;
1372
- /** Snapshot the table as [id, element] pairs against a parallel clone of
1373
- * the tree: `pairs` maps originals→clones (as produced by walking original
1374
- * and cloned roots in step). Used by the reconciliation snapshot (plan
1375
- * doc 03) so a restore re-keys the table to the restored elements. */
1376
- captureForClone(originalToClone: Map<XmlElement, XmlElement>): Map<StableId$2, XmlElement>;
1377
- /** Replace the table wholesale from a captured mapping (restore path). */
1378
- restore(fromCapture: Map<StableId$2, XmlElement>, nextId: StableId$2): void;
1379
- nextId(): StableId$2;
1380
- /**
1381
- * Export the table as `(id, path)` pairs, where a path is the structural
1382
- * location of the id'd element within the given roots: `[rootIndex,
1383
- * childIndex, childIndex, …]`. This is the checkpoint ID sidecar (plan doc
1384
- * 03): it lets a replica that reloads a snapshot reproduce the exact id
1385
- * table — parse-order re-derivation cannot, because split-created nodes
1386
- * carry non-sequential ids. Also carries `next` so id allocation resumes
1387
- * consistently.
1388
- */
1389
- exportSidecar(roots: XmlElement[]): {
1390
- next: StableId$2;
1391
- entries: [StableId$2, number[]][];
1392
- };
1393
- /** Rebuild the table from a sidecar against freshly parsed roots (the
1394
- * snapshot the sidecar was exported from). Replaces any current mappings. */
1395
- importSidecar(roots: XmlElement[], sidecar: {
1396
- next: StableId$2;
1397
- entries: [StableId$2, number[]][];
1398
- }): void;
1399
- /** Encode a caret as wire-stable addresses. `t` is the w:t (or other text
1400
- * holder) the caret sits in; the run is its nearest tracked ancestor run,
1401
- * the block the nearest tracked block above that. Returns null when the
1402
- * position isn't inside id-tracked content (e.g. math internals) — such
1403
- * positions are not yet addressable on the wire. */
1404
- encodeCaret(t: XmlElement, offset: number, parentOf: (el: XmlElement) => XmlElement | null): EncodedCaret | null;
1405
- /** Resolve an encoded caret back to a concrete (w:t, offset) in THIS
1406
- * table's tree — the inverse of encodeCaret, for restoring a caret across
1407
- * a reconciliation reload (the ids survive via the sidecar; the node
1408
- * references do not). When the exact run is gone (deleted or replaced by
1409
- * a concurrent edit) the caret falls back to the block's first text; null
1410
- * when nothing addressable remains. */
1411
- decodeCaret(pos: EncodedCaret): {
1412
- t: XmlElement;
1413
- offset: number;
1414
- } | null;
1415
- }
1416
-
1417
- interface Relationship {
1418
- id: string;
1419
- type: string;
1420
- target: string;
1421
- external: boolean;
1422
- }
1423
- type Relationships = Map<string, Relationship>;
1424
-
1425
- /** The two note parts a document can carry — see notePartsHolding. */
1426
- type NotePart = "footnotes" | "endnotes";
1427
- /**
1428
- * A fully parsed .docx: sections of blocks, styles, numbering, theme, and
1429
- * header/footer parts, with helpers to resolve effective formatting.
1430
- */
1431
- declare class DocxDocument {
1432
- /** Changes whenever refresh() rebuilds the parsed model. Plain in-place text
1433
- * edits can keep this stable so incremental layout reuses model-only caches. */
1434
- private _modelVersion;
1435
- private _packageResourceVersion;
1436
- get modelVersion(): number;
1437
- /** Invalidate layout derived from related parts such as ChartML. */
1438
- markPackageResourceChanged(): void;
1439
- readonly pkg: Package;
1440
- readonly theme: Theme;
1441
- styles: Styles;
1442
- numbering: Numbering;
1443
- sections: Section[];
1444
- /** Header/footer parts keyed by relationship id from document.xml.rels. */
1445
- readonly headers: Map<string, HeaderFooter>;
1446
- readonly footers: Map<string, HeaderFooter>;
1447
- /** Note content by note id. */
1448
- readonly footnotes: Map<number, Block[]>;
1449
- readonly endnotes: Map<number, Block[]>;
1450
- /** The separator paragraph controls the gap between its rule and the first
1451
- * footnote. */
1452
- readonly footnoteSeparator: Block[];
1453
- /** `_Ref` cross-reference bookmark ranges (name → captured runs). REF
1454
- * fields re-render the referenced text from these — Word recomputes REF on
1455
- * open, so the cached field result in the file is stale. */
1456
- refBookmarks: Map<string, Run[]>;
1457
- readonly documentRels: Relationships;
1458
- /** settings.xml w:evenAndOddHeaders — enables the "even" header/footer variants. */
1459
- readonly evenAndOddHeaders: boolean;
1460
- /** settings.xml w:autoHyphenation (§17.15.1.10). This engine's layout does
1461
- * not hyphenate automatically — the setting is round-trip state that
1462
- * governs Word's own rendering of the document. */
1463
- readonly autoHyphenation: boolean;
1464
- /** settings.xml w:hyphenationZone/@w:val in twips (§17.15.1.53); null when
1465
- * the document does not declare one (Word defaults to 360 = 0.25"). */
1466
- readonly hyphenationZoneTwips: number | null;
1467
- /** settings.xml w:doNotHyphenateCaps (§17.15.1.41). */
1468
- readonly doNotHyphenateCaps: boolean;
1469
- /** settings.xml w:mirrorMargins — facing-page (book fold) margins: even
1470
- * (verso) pages swap the left/right margins and place the gutter on the
1471
- * inside (right) edge so the binding margin stays on the inner side of
1472
- * each spread. */
1473
- readonly mirrorMargins: boolean;
1474
- /** settings.xml w:compat w:suppressTopSpacing: the first line of a page
1475
- * takes its character height, not its authored (exact) line spacing. */
1476
- readonly suppressTopSpacing: boolean;
1477
- /** settings.xml w:defaultTabStop in px (Word default 0.5"). */
1478
- readonly defaultTabStop: number;
1479
- /** settings.xml w:compat compatibilityMode (12=Word2007, 14=Word2010,
1480
- * 15=Word2013+). Word 2013 (mode 15) introduced suppressing a paragraph's
1481
- * space-before when it lands at the top of a page; mode 14 and earlier keep
1482
- * it (nccih: a Heading1/2 after a page break sits at margin + its before).
1483
- * Absent → treated as current (15). */
1484
- readonly compatibilityMode: number;
1485
- /** The compatibilityMode settings.xml actually declares, or undefined when
1486
- * the setting (or settings.xml itself) is missing. `compatibilityMode`
1487
- * defaults an omitted value to 15, but a table's percentage width needs the
1488
- * distinction: Word fits the horizontal cell margins inside the table box at
1489
- * an EXPLICIT 15 and adds them around it when the setting is absent. */
1490
- readonly declaredCompatibilityMode: number | undefined;
1491
- /** settings.xml m:mathPr/m:defJc — default justification for display
1492
- * equations whose m:oMathParaPr carries no explicit m:jc (Word default:
1493
- * centerGroup — the rows of a broken equation left-align to each other and
1494
- * the group is centered in the column). */
1495
- readonly mathDefJc: "left" | "right" | "center" | "centerGroup";
1496
- /** settings.xml m:mathPr/m:wrapIndent in px (Word default 1440tw = 1"):
1497
- * indent of auto-wrapped display-equation continuation rows from the
1498
- * equation group's left edge (dense p13: the "+Dc(...)" continuations sit
1499
- * exactly 72pt right of the explicit rows). */
1500
- readonly mathWrapIndent: number;
1501
- /** Review comments from word/comments.xml (empty when the part is absent).
1502
- * Re-derived from the retained comments XML on every refresh(). */
1503
- comments: DocComment[];
1504
- /** Retained comments.xml tree (editing + save round-trip), when present. */
1505
- private commentsPart;
1506
- private commentsRoot;
1507
- /** Retained commentsExtended.xml tree (comment threading), when present. */
1508
- private commentsExtPart;
1509
- private commentsExtRoot;
1510
- private commentsExtDirty;
1511
- /** Conditional table formats per table style id, keyed by the Styles object
1512
- * so re-parsing styles.xml (edits) naturally invalidates the cache. */
1513
- private tableCondCache;
1514
- /** Retained styles.xml tree (built-in style injection + save). */
1515
- private stylesPart;
1516
- private stylesRoot;
1517
- /** Retained numbering.xml tree (list creation + save round-trip). */
1518
- private numberingPart;
1519
- private numberingRoot;
1520
- private numberingDirty;
1521
- /** Retained footnotes.xml tree (footnote insertion + save round-trip). */
1522
- private footnotesPart;
1523
- private footnotesRoot;
1524
- private footnotesDirty;
1525
- private footnotesRels;
1526
- /** Retained endnotes.xml tree (endnote insertion + save round-trip). */
1527
- private endnotesPart;
1528
- private endnotesRoot;
1529
- private endnotesDirty;
1530
- private endnotesRels;
1531
- /** Retained bibliography sources part (the customXml b:Sources data of
1532
- * ECMA-376 §22.6), when present. Source-management editing mutates this
1533
- * tree in place; a document with none gets the part on first create. */
1534
- private sourcesPart;
1535
- private sourcesRoot;
1536
- private sourcesDirty;
1537
- /** Companion parts written when THIS session created the sources part
1538
- * (itemProps + its .rels); an arriving part keeps its own companions. */
1539
- private sourcesAux;
1540
- /** Retained glossary document part (word/glossary/document.xml, ECMA-376
1541
- * §17.12: glossaryDocument/docParts/docPart — Word's Quick Parts / Building
1542
- * Blocks store), when present. Building-block editing mutates this tree in
1543
- * place; a document with none gets the part on first create. Unlike
1544
- * headers/footers, a docPart's body is never caret-editable — it is only
1545
- * ever cloned INTO the main document body (insertBuildingBlock) or captured
1546
- * OUT of a selection (createBuildingBlock) — so this part carries no
1547
- * editableRoots()/stable-id integration of its own. */
1548
- private glossaryPart;
1549
- private glossaryRoot;
1550
- private glossaryDirty;
1551
- /** Serialize retained optional parts only once actually mutated, keeping
1552
- * untouched parts byte-identical through save(). */
1553
- private stylesDirty;
1554
- private commentsDirty;
1555
- /** Retained XML roots — source of truth for editing and save(). */
1556
- private readonly docPart;
1557
- /** Retained settings.xml tree. A synthetic empty root keeps history root
1558
- * indices stable for documents that did not originally contain the part. */
1559
- private readonly settingsPart;
1560
- private readonly settingsRoot;
1561
- private settingsDirty;
1562
- /** Parsed document.xml root (read-only outside the class; the layout engine
1563
- * scans it for incremental-reuse eligibility, tests walk it). */
1564
- readonly docRoot: XmlElement;
1565
- private readonly hfParts;
1566
- private readonly ctxBase;
1567
- /** Tracked-changes display mode; refresh() re-derives after changes. */
1568
- revisionView: "final" | "markup";
1569
- private readonly relsPath;
1570
- private relsRoot;
1571
- private contentTypesRoot;
1572
- /** Canonical XML as first parsed from each always-modeled package part.
1573
- * If the retained tree still matches on save, keep the part's original
1574
- * bytes instead of replacing producer formatting such as CRLF line ends. */
1575
- private readonly originalModeledXml;
1576
- private docPrIdCounter;
1577
- /** Transient layout state: set by the engine while laying out a docGrid
1578
- * type="charsAndLines" section so line measurement can give East-Asian
1579
- * glyphs their true (uninflated) grid line height. Off outside such a
1580
- * section. Safe as document-scoped mutable state because layout is
1581
- * single-threaded and sequential per section. */
1582
- charGridEa: boolean;
1583
- private constructor();
1584
- /** Resolve content controls mapped to standard package core properties.
1585
- * Word refreshes these bindings on open, so the serialized sdtContent can
1586
- * be stale even though the visible value comes from docProps/core.xml. */
1587
- private hydrateCorePropertyControls;
1588
- /** Repair only objects emitted by older WordInWeb builds that Word rejects. */
1589
- private repairLegacyWordInWebObjects;
1590
- /**
1591
- * Re-derive the document model from the retained XML trees. Called after
1592
- * edit commands mutate the XML.
1593
- */
1594
- /** Switch tracked-changes display and re-derive the model. */
1595
- setRevisionView(view: "final" | "markup"): void;
1596
- /** Invalidated on refresh; see layoutGlobalSig. */
1597
- private _layoutGlobalSig;
1598
- /** Signature of everything OUTSIDE a paragraph's own XML that affects how it
1599
- * breaks into lines: style + numbering definitions, doc-level layout scalars,
1600
- * and the tracked-changes view mode. The line-break cache (layout/inline.ts)
1601
- * combines this with a paragraph's own content signature so a style/numbering/
1602
- * settings edit invalidates cached breaks even though the paragraph XML is
1603
- * unchanged. Memoized until the next refresh() (styles/numbering trees are
1604
- * stable across a plain text edit). */
1605
- layoutGlobalSig(): string;
1606
- refresh(): void;
1607
- /** Stable node-id side table for replicated editing. Null (and zero cost)
1608
- * for local-only documents; call `enableStableIds()` to populate and
1609
- * maintain it. Kept in memory only — never serialized into the XML. */
1610
- stableIds: StableIds | null;
1611
- /** Populate the stable-id table from current content and keep it updated
1612
- * on every subsequent refresh(). Idempotent. */
1613
- enableStableIds(): StableIds;
1614
- /** Reparse the two sibling body-story paragraphs created by Enter without
1615
- * rebuilding the complete document model. Paragraphs nested in table cells
1616
- * are included because legal documents spend most of their body inside
1617
- * tables; revisions, bookmarks, fields, and section breaks use refresh(). */
1618
- reparseDirectBodyParagraphSplit(beforeSource: XmlElement, afterSource: XmlElement): {
1619
- before: Paragraph;
1620
- after: Paragraph;
1621
- } | null;
1622
- /**
1623
- * The parsed body-story block list holding the paragraph parsed from
1624
- * `source`, and its index in it — searching sections and, recursively,
1625
- * table cells. Null when the model doesn't hold that paragraph (it lives in
1626
- * a header/footer/footnote part, or the model predates its creation), which
1627
- * is every targeted-reparse helper's signal to fall back to a full
1628
- * refresh(). Shared by those helpers and by paragraphBySource.
1629
- */
1630
- private locateParagraph;
1631
- private _paraLoc;
1632
- /** The parsed Paragraph for a retained w:p in the body story (table cells
1633
- * included), or null when the model doesn't hold it. Lets a caller that
1634
- * already knows which paragraph an edit addresses reach that paragraph's
1635
- * runs without walking the whole model. */
1636
- paragraphBySource(source: XmlElement): Paragraph | null;
1637
- /** Insert a new paragraph immediately before a retained body paragraph
1638
- * without rebuilding the complete document model. Used by Enter at the
1639
- * exact paragraph start, where the existing paragraph itself is unchanged. */
1640
- insertDirectBodyParagraphBefore(referenceSource: XmlElement, insertedSource: XmlElement): Paragraph | null;
1641
- /** Reparse a body paragraph plus several new siblings created by
1642
- * click-and-type without rebuilding the complete document model. */
1643
- reparseDirectBodyParagraphSplits(beforeSource: XmlElement, afterSources: XmlElement[]): Paragraph[] | null;
1644
- /** Reparse one retained body-story paragraph after a structural edit that
1645
- * leaves its surrounding block list unchanged, such as inserting ink. */
1646
- reparseBodyParagraph(source: XmlElement): Paragraph | null;
1647
- /** Reparse two sibling body-story paragraphs after Backspace/Delete merged
1648
- * their XML into one. Keeps the parsed model generation stable so long
1649
- * documents can use incremental layout instead of repaginating in full. */
1650
- reparseDirectBodyParagraphMerge(beforeSource: XmlElement, afterSource: XmlElement, survivorSource: XmlElement): Paragraph | null;
1651
- private deriveComments;
1652
- /** Retained comments tree for edit commands (null when the doc has none). */
1653
- /**
1654
- * Retained comments tree. With create=true, a missing comments.xml part is
1655
- * created and registered (content type + document relationship) so newly
1656
- * added comments serialize and round-trip through Word.
1657
- */
1658
- commentsTree(create?: boolean): XmlElement | null;
1659
- /**
1660
- * Make sure a paragraph style is usable: Word ships built-in definitions
1661
- * for Heading 1-6/Title even when a file doesn't declare them, so applying
1662
- * one to such a file must inject a standard definition (otherwise the
1663
- * paragraph would reference an undefined style and render as Normal).
1664
- */
1665
- ensureParagraphStyle(styleId: string): boolean;
1666
- /**
1667
- * Retained numbering tree. With create=true, a missing numbering.xml part
1668
- * is created and registered (content type + document relationship) so list
1669
- * definitions added by editing serialize and round-trip.
1670
- */
1671
- numberingTree(create?: boolean): XmlElement | null;
1672
- markNumberingChanged(): void;
1673
- /** Retained styles.xml tree, or null when the package has no styles part.
1674
- * Style-definition editing mutates this tree in place. */
1675
- stylesTree(): XmlElement | null;
1676
- /**
1677
- * Re-resolve the style cascade after a definition changed in place.
1678
- *
1679
- * A style definition is not addressed by any paragraph's XML, so mutating one
1680
- * changes how EVERY paragraph resolves without changing a single w:p. Two
1681
- * things therefore have to be reset by hand: the parsed Styles map every
1682
- * effective-props call reads, and layoutGlobalSig, which is what makes the
1683
- * line-break cache treat cached breaks for unchanged paragraph XML as stale.
1684
- */
1685
- markStylesChanged(): void;
1686
- /**
1687
- * Retained bibliography sources tree (b:Sources), or null when the package
1688
- * has no sources part. With create=true, a missing part is created and
1689
- * registered the way Word lays one out (ECMA-376 §22.6 + Part 2 custom XML
1690
- * data storage): the data itself as customXml/itemN.xml, a datastore-item
1691
- * properties part (itemPropsN.xml) declaring the Bibliography schema URI as
1692
- * its schemaRef, a .rels from the item to its properties, a customXml
1693
- * relationship from the main document part, and the content-type overrides.
1694
- *
1695
- * DETERMINISM. Everything written is a pure function of the package —
1696
- * the item number is the first free one, and the datastore itemID GUID is a
1697
- * fixed constant rather than Word's random draw — so two replicas creating
1698
- * the part through the same sequenced operation write identical bytes.
1699
- */
1700
- sourcesTree(create?: boolean): XmlElement | null;
1701
- /**
1702
- * Invalidate what a sources-part edit changes downstream. Like
1703
- * markStylesChanged, the part is addressed by no paragraph's XML: a
1704
- * CITATION field's painted text resolves from the part at layout, so the
1705
- * layout signature has to drop for unchanged paragraph XML to repaint.
1706
- */
1707
- markSourcesChanged(): void;
1708
- /**
1709
- * Retained glossary document tree (w:glossaryDocument), or null when the
1710
- * package has no glossary part. With create=true, a missing part is
1711
- * created and registered — package part, document relationship,
1712
- * content-type override — the createNotesPart discipline.
1713
- *
1714
- * The glossary part gets none of the sources part's companion machinery
1715
- * (no datastore item, no random itemID): it is an ordinary WordprocessingML
1716
- * part named by relationship TYPE, so creation just mints an empty
1717
- * `<w:glossaryDocument><w:docParts/></w:glossaryDocument>` and wires it up
1718
- * — closer to createNotesPart than to sourcesTree. A real Word-authored
1719
- * glossary part additionally carries its own styles.xml / settings.xml /
1720
- * fontTable.xml; this engine writes none of them, because a docPart's
1721
- * content is read once — to clone its blocks into the main document, where
1722
- * they resolve styles against the MAIN document's own styles.xml — and is
1723
- * never laid out or rendered as its own story the way a header/footer is.
1724
- *
1725
- * DETERMINISM: nothing here depends on Word's random draws (no GUID is
1726
- * written at all — w:docPartPr/w:guid is optional and this engine never
1727
- * reads it back), so two replicas creating the part through the same
1728
- * sequenced operation write identical bytes.
1729
- */
1730
- glossaryTree(create?: boolean): XmlElement | null;
1731
- /** Invalidate what a glossary-part edit changes: nothing downstream, since
1732
- * createBuildingBlock/deleteBuildingBlock touch only the glossary tree, not
1733
- * any paragraph the layout reads. Exists for the same "explicit intent to
1734
- * persist" reason markSourcesChanged does. */
1735
- markGlossaryChanged(): void;
1736
- /**
1737
- * Retained footnotes tree. With create=true, a missing footnotes.xml part
1738
- * is created and registered (with Word's required separator footnotes) so
1739
- * inserted footnotes serialize and round-trip.
1740
- */
1741
- footnotesTree(create?: boolean): XmlElement | null;
1742
- /** Retained endnotes tree; the endnote mirror of footnotesTree. */
1743
- endnotesTree(create?: boolean): XmlElement | null;
1744
- /** Register a new notes part in document.xml.rels and [Content_Types].xml,
1745
- * and return the part path. The tree itself is the caller's. */
1746
- private createNotesPart;
1747
- /**
1748
- * Create an empty header/footer part (with a default-type reference in
1749
- * every sectPr) when the document has none - Word does this implicitly the
1750
- * first time you edit the header area. Returns the part's root.
1751
- */
1752
- /** Whether the document declares any section properties at all. A blank
1753
- * minimal document has none; see ensureHfPart. */
1754
- private hasSectPr;
1755
- /** Whether a header (or footer) part already exists — the precondition
1756
- * `ensureHfPart` tests internally, exposed so a caller can tell a real
1757
- * creation from a no-op before mutating (the collab apply needs to know
1758
- * whether an ensureHeaderFooter intent has anything to do). */
1759
- hasHfPart(kind: "header" | "footer"): boolean;
1760
- ensureHfPart(kind: "header" | "footer"): XmlElement;
1761
- /** A w:headerReference / w:footerReference element. */
1762
- private hfReference;
1763
- /** Materialize the default body-level sectPr when the document declares no
1764
- * section properties at all (schema: the body's sectPr is its LAST child). */
1765
- private ensureBodySectPr;
1766
- /**
1767
- * Give every section a header and footer reference of the given variant
1768
- * type, creating one empty part per band the way Word does the first time
1769
- * "different first page" (type "first") or "different odd & even pages"
1770
- * (type "even") is enabled. Sections that already carry a reference of the
1771
- * type keep it — and its part's content. True when anything was added.
1772
- */
1773
- ensureHfVariantParts(type: "first" | "even"): boolean;
1774
- /** Create and register a new empty header/footer part — package part,
1775
- * document relationship, content-type override, hfParts entry — with no
1776
- * section references of its own; the caller decides which sectPrs point at
1777
- * it and with which w:type. */
1778
- private createHfPart;
1779
- markFootnotesChanged(): void;
1780
- markEndnotesChanged(): void;
1781
- /** Re-derive both id -> blocks maps from the retained trees, so layout sees
1782
- * an inserted or edited note. */
1783
- private rederiveNotes;
1784
- /** Called by comment edit commands after mutating the comments tree. */
1785
- markCommentsChanged(): void;
1786
- /**
1787
- * Retained commentsExtended tree (threading). With create=true, a missing
1788
- * part is created and registered (content type + document relationship) so
1789
- * Word picks up reply threading.
1790
- */
1791
- commentsExtendedTree(create?: boolean): XmlElement | null;
1792
- markCommentsExtendedChanged(): void;
1793
- /**
1794
- * The w:t elements covered by each comment's range, in document order.
1795
- * Point comments (a bare commentReference with no range) anchor to the
1796
- * nearest preceding w:t.
1797
- */
1798
- commentAnchors(): Map<string, XmlElement[]>;
1799
- /** Flag a notes part dirty when `t` lives inside it, so save()
1800
- * re-serializes footnotes.xml / endnotes.xml. Called by the editor after a
1801
- * text edit; a no-op for body/header/footer targets. */
1802
- markDirtyIfFootnote(t: XmlElement): void;
1803
- /**
1804
- * Which note parts hold `el` right now. An operation that DETACHES `el` —
1805
- * accepting or rejecting a revision, for one — has to ask BEFORE it mutates
1806
- * and mark the answer afterwards: a detached element belongs to no part, so
1807
- * a containment test run after the fact reports nothing and save() then
1808
- * leaves the stale footnotes.xml / endnotes.xml in the package.
1809
- */
1810
- notePartsHolding(el: XmlElement): NotePart[];
1811
- /** Flag the given note parts dirty, so save() re-serializes exactly those. */
1812
- markNotePartsChanged(parts: readonly NotePart[]): void;
1813
- /** The mutable XML roots (document body, related modeled parts, settings).
1814
- * settingsRoot is always second and always present so its history snapshot
1815
- * index stays stable even when optional related roots are created later. */
1816
- editableRoots(): XmlElement[];
1817
- /** CT_Settings children that precede w:mirrorMargins in the schema sequence
1818
- * (§17.15.1.78). Insertions go before the first child that is not a
1819
- * predecessor, so Word never has to repair settings.xml. */
1820
- private static readonly SETTINGS_BEFORE_MIRROR;
1821
- /** The schema predecessors of w:evenAndOddHeaders (§17.10.1): everything up
1822
- * to mirrorMargins, then the sequence through defaultTableStyle. */
1823
- private static readonly SETTINGS_BEFORE_EVEN_AND_ODD;
1824
- /** Set or remove one settings.xml element at its schema position. Null
1825
- * removes; otherwise the element is (re)inserted before the first child
1826
- * that is not a schema predecessor. */
1827
- private setSettingsElement;
1828
- /** Set or remove one on/off settings.xml toggle at its schema position. */
1829
- private setSettingsToggle;
1830
- /** The schema predecessors of w:autoHyphenation: everything through
1831
- * w:defaultTabStop (§17.15.1.78). Its cluster mates append in order. */
1832
- private static readonly SETTINGS_BEFORE_AUTO_HYPHENATION;
1833
- /**
1834
- * Patch the hyphenation settings (w:autoHyphenation §17.15.1.10,
1835
- * w:hyphenationZone §17.15.1.53, w:doNotHyphenateCaps §17.15.1.41). Each
1836
- * present key is written; `zoneTwips: null` removes the zone element. True
1837
- * when anything changed — the honest no-op a replicated document-scoped
1838
- * operation needs. This engine's layout does not hyphenate automatically;
1839
- * the settings govern Word's own rendering of the file.
1840
- */
1841
- setHyphenation(patch: {
1842
- auto?: boolean;
1843
- zoneTwips?: number | null;
1844
- noCaps?: boolean;
1845
- }): boolean;
1846
- /** Toggle the document-global facing-page margin mode in settings.xml. */
1847
- setMirrorMargins(enabled: boolean): void;
1848
- /** Toggle w:evenAndOddHeaders (§17.10.1) — the document-global switch that
1849
- * makes even pages use the "even" header/footer variants. */
1850
- setEvenAndOddHeaders(enabled: boolean): void;
1851
- /** Register settings.xml in document.xml.rels and [Content_Types].xml when
1852
- * the package was born without it (a minimal document). */
1853
- private registerSettingsPart;
1854
- /**
1855
- * Find the parent element of `target` in any modeled XML tree (document
1856
- * body, headers, footers). Linear scan — documents are small and this only
1857
- * runs on structural edits (Enter, paragraph merge).
1858
- */
1859
- /** The header part roots, in package order. A watermark is authored into
1860
- * every one of them: Word paints it on every page, and a document with a
1861
- * first-page or even-page header has more than one header part. */
1862
- /** The root of the header or footer part at `target`, if this document has one. */
1863
- headerFooterRoot(target: string): XmlElement | undefined;
1864
- headerRoots(): XmlElement[];
1865
- /** The footer part roots, in package order — headerRoots' counterpart, for
1866
- * operations that walk both bands (the page-number gallery's removal
1867
- * sweep). */
1868
- footerRoots(): XmlElement[];
1869
- /** XML roots that can carry tracked changes: body, headers/footers, notes. */
1870
- revisionRoots(): XmlElement[];
1871
- /** Body, header/footer and note roots — every tree the caret can reach. */
1872
- private contentRoots;
1873
- /**
1874
- * Memoized child→parent links. Nothing invalidates this map — the tree is
1875
- * spliced constantly — so every answer is RE-DERIVED before it is returned:
1876
- * the memoized parent must still list the target among its children, and
1877
- * must still hang off a root (see memoIsLive). A stale entry can then only
1878
- * cost a cache miss, never a wrong answer.
1879
- *
1880
- * Both halves are needed. Containment alone is not proof of a live parent:
1881
- * a run split for formatting is spliced OUT of its paragraph while its own
1882
- * `children` array still lists the elements that moved into the replacement
1883
- * runs, so a containment-only check would hand back the detached run where a
1884
- * walk from the roots finds the new one.
1885
- */
1886
- private _parentMemo;
1887
- private memoIsLive;
1888
- findParentOf(target: XmlElement): XmlElement | undefined;
1889
- /** Record a parent link the caller just created (a splice), so the next
1890
- * lookup skips the full-document walk. Advisory only — findParentOf
1891
- * verifies every memo against the live tree before trusting it. */
1892
- noteParent(child: XmlElement, parent: XmlElement): void;
1893
- /**
1894
- * Serialize the (possibly edited) document back to .docx bytes. Only the
1895
- * XML parts we model are re-serialized; every other part round-trips
1896
- * byte-for-byte.
1897
- */
1898
- private rememberOriginalXml;
1899
- private writeModeledXml;
1900
- /**
1901
- * Canonicalize producer shorthand that Google Docs otherwise interprets as
1902
- * a fixed, few-twip table. Word treats `tblW="100%"` plus a placeholder
1903
- * grid as autofit; Google needs the standard pct value and a usable cached
1904
- * grid. The cached widths follow the same content-dominant shape and do not
1905
- * change Word's autofit result.
1906
- */
1907
- /** Undo closures recorded by save-time fixups while `saveJournal` is
1908
- * active, so `save()` can revert every live-tree mutation and remain
1909
- * side-effect-free. Collaborative checkpoints re-serialize the
1910
- * authoritative document repeatedly; a save that mutated the tree would
1911
- * change its hash outside the intent stream and desync the fleet. */
1912
- private saveJournal;
1913
- private journalSetAttr;
1914
- private normalizePercentageTableGrids;
1915
- save(): Uint8Array;
1916
- /**
1917
- * An independent copy: what `DocxDocument.load(doc.save())` gives, without
1918
- * zipping the package and unzipping it again. compareDocuments starts from a
1919
- * copy of the revised document, and the round trip through the zip was a
1920
- * third of its time on a document that had not changed at all.
1921
- */
1922
- clone(): DocxDocument;
1923
- saveAsync(): Promise<Uint8Array>;
1924
- private buildPackage;
1925
- private buildPackageFiles;
1926
- /**
1927
- * Leave out the chart parts the document no longer references.
1928
- *
1929
- * Deleting a chart splices its w:drawing out of the story, but the chart
1930
- * part, its rels part, its embedded workbook, the document relationship, and
1931
- * the two [Content_Types].xml overrides all stay. An agent that inserts a
1932
- * chart, deletes it, and inserts a replacement therefore saves TWO chart
1933
- * parts for the one chart the document shows.
1934
- *
1935
- * The release happens here, at save time, rather than when the drawing goes,
1936
- * because undo restores the drawing XML — r:id and all — from a snapshot
1937
- * that models package parts but no relationship state. Dropping the
1938
- * relationship early would make undo produce a chart pointing at nothing.
1939
- * The live tree keeps everything; only the written bytes lose the orphans,
1940
- * and the saveJournal puts back the two trees this touches.
1941
- *
1942
- * Relationship ids are scoped to the part that owns the rels file, so the
1943
- * document body is the only place that can reference these ids, and reading
1944
- * it is a complete check. Headers, footers, and notes carry their own rels.
1945
- */
1946
- private dropOrphanChartParts;
1947
- /** Fresh unique docPr id for inserted drawings. Seeded once past the
1948
- * highest id already present in any editable root (floor 1000, matching
1949
- * the historical seed for documents with no drawings) so a document that
1950
- * already carries drawings never gets a colliding id. */
1951
- nextDrawingId(): number;
1952
- /** Next unused revision id (w:id on w:ins/w:del). Seeded once past the
1953
- * highest id already present in any editable root so a document that
1954
- * already has tracked changes never collides. */
1955
- private revIdCounter;
1956
- nextRevisionId(): number;
1957
- /**
1958
- * Add image bytes as a new media part + relationship (+ content-type
1959
- * default). Returns the relationship id for use in a w:drawing.
1960
- */
1961
- private ensureRelsRoot;
1962
- /** Register an external hyperlink relationship and return its rId. */
1963
- /**
1964
- * Copy the part that `source`'s main-document relationship `relId` points
1965
- * at into this package, with every part it references in turn (a chart's
1966
- * embedded workbook, SmartArt's layout, style and colour parts) and their
1967
- * content types, and add a relationship to it. Returns the new
1968
- * relationship id, or null when the source has no such internal part.
1969
- *
1970
- * compareDocuments needs this for struck content: a removed picture keeps
1971
- * its w:drawing, and without its image part the result's reject-all
1972
- * brought the picture back as an empty frame.
1973
- */
1974
- adoptRelFrom(source: DocxDocument, relId: string, scope?: {
1975
- from?: string | null;
1976
- into?: string | null;
1977
- }): string | null;
1978
- /** Give a part copied from `source` the content type it had there. */
1979
- private adoptContentType;
1980
- addHyperlinkRel(url: string, ownerPart?: string | null): string;
1981
- /** Retarget an existing external relationship (hyperlink href edit). */
1982
- setRelTarget(relId: string, url: string): boolean;
1983
- /** The relationships owned by `part` (a header or footer part), or by the
1984
- * document part when null; a header or footer gets a rels root on demand. */
1985
- private relsOwnerOf;
1986
- /** The relationships of `part` (a header or footer), or of the document part. */
1987
- relationshipsOf(part?: string | null): Relationships;
1988
- /** The relationships of the part that holds `source`: a header or footer
1989
- * part when the element is inside one, else the document part. */
1990
- private imageRelsOwner;
1991
- /** Add an image relationship pointing at `part`, in the relationships of
1992
- * whichever part holds `source`. */
1993
- private addImageRel;
1994
- /**
1995
- * Point a SECOND part at an image part this document already has.
1996
- *
1997
- * Word's picture watermark is ONE media part that every header part
1998
- * references. Registering the image again per header would put a full copy
1999
- * of the bytes in the package for each one — three headers, three copies of
2000
- * the same logo — and give the media-install path three pending parts to
2001
- * fill from one upload.
2002
- */
2003
- linkImageResource(part: string, source: XmlElement): string;
2004
- private addImageResourceAt;
2005
- addImageResource(bytes: Uint8Array, ext: string): string;
2006
- /** Add a GLB model part and its Office 2019 model3d relationship. */
2007
- addModel3DResource(bytes: Uint8Array): {
2008
- relId: string;
2009
- part: string;
2010
- };
2011
- /** Add an OLE package part used by a Word w:object. */
2012
- addEmbeddedObjectResource(bytes: Uint8Array): {
2013
- relId: string;
2014
- part: string;
2015
- };
2016
- /** Add a DOCX package embedded as an activatable Word.Document.12 object. */
2017
- addEmbeddedWordDocumentResource(bytes: Uint8Array): {
2018
- relId: string;
2019
- part: string;
2020
- };
2021
- /** Add a native ChartML part and its embedded editable workbook. */
2022
- addChartResource(chartXml: string, workbook: Uint8Array): {
2023
- relId: string;
2024
- part: string;
2025
- };
2026
- /** Add the SmartArt data/layout/style/color parts and its cached diagram drawing. */
2027
- addSmartArtResources(layoutXml: string, styleXml: string, colorsXml: string, drawingXml: string, dataXml: (drawingRelId: string) => string): {
2028
- dataRelId: string;
2029
- layoutRelId: string;
2030
- styleRelId: string;
2031
- colorsRelId: string;
2032
- drawingRelId: string;
2033
- };
2034
- static load(data: ArrayBuffer | Uint8Array): DocxDocument;
2035
- media(part: string): Uint8Array | undefined;
2036
- /**
2037
- * Pending-media registry (plan doc 05 change 1 / doc 16 §6): parts whose
2038
- * XML registration (rels + content-type + extent geometry) exists but
2039
- * whose BYTES have not arrived yet — the out-of-band media model. Layout
2040
- * needs no bytes (extents live in the XML), so a doc with pending parts
2041
- * lays out pixel-identically; the renderer shows a placeholder until
2042
- * `installMedia`. Keyed by part name; the value is the doc-16 §5.3
2043
- * metadata (declared sha + optional E2EE iv/epoch for re-supply).
2044
- */
2045
- readonly pendingMedia: Map<string, {
2046
- sha: string;
2047
- iv?: string;
2048
- genesisId?: string;
2049
- }>;
2050
- /** DISPLAY-ONLY transfer state for a pending part (doc 16 §5.2 step 4), so
2051
- * the skeleton can say "fetching" versus "nobody online has this yet".
2052
- * Written by the media transfer layer, read by the renderer; never part of
2053
- * the document's identity and never serialized. */
2054
- readonly mediaTransferState: Map<string, "unavailable" | "fetching" | "waiting">;
2055
- /** Per-part media metadata that PERSISTS after install (doc 16 §5.3):
2056
- * holder duty needs the sha (and E2EE iv/epoch) of READY parts to answer
2057
- * re-supply requests; pendingMedia above only tracks not-yet-arrived. */
2058
- readonly mediaMeta: Map<string, {
2059
- sha: string;
2060
- iv?: string;
2061
- genesisId?: string;
2062
- }>;
2063
- /** "ready" = bytes present; "pending" = registered, bytes absent (doc 05).
2064
- * Unregistered parts report "pending" too — a rel pointing at a missing
2065
- * zip entry after a save/parse round-trip IS the pending state (a hole is
2066
- * detectable, never corrupt — doc 16 §6 round-trip rule). */
2067
- mediaStatus(part: string): "ready" | "pending";
2068
- /**
2069
- * Register an image part + relationship WITHOUT bytes (doc 16 §2: the
2070
- * intent carries the sha; bytes travel out of band). Same deterministic
2071
- * naming/rId scan as addImageResource so every replica applying the same
2072
- * canonical intent derives identical registration.
2073
- */
2074
- registerPendingImage(sha: string, ext: string, meta?: {
2075
- iv?: string;
2076
- genesisId?: string;
2077
- }, source?: XmlElement): string;
2078
- /** As registerPendingImage, and also names the part it made — what a second
2079
- * part needs to reach the same image through linkImageResource. */
2080
- registerPendingImagePart(sha: string, ext: string, meta?: {
2081
- iv?: string;
2082
- genesisId?: string;
2083
- }, source?: XmlElement): {
2084
- relId: string;
2085
- part: string;
2086
- };
2087
- /** Install fetched bytes into a pending part (doc 05). The caller has
2088
- * ALREADY verified the sha against the intent's declaration (the
2089
- * reservation is the hash commitment — doc 16 §1.1); this installs and
2090
- * clears the pending record. Returns false for unknown parts. */
2091
- installMedia(part: string, bytes: Uint8Array): boolean;
2092
- /** Effective paragraph properties: docDefaults → table style → style chain → direct. */
2093
- effectiveParaProps(para: Paragraph): ParaProps;
2094
- /**
2095
- * Run props contributed by the enclosing table style's conditional
2096
- * w:tblStylePr blocks for this paragraph's cell (undefined when the
2097
- * paragraph isn't in a styled table cell or nothing applies).
2098
- */
2099
- private tableCondRPr;
2100
- /** Effective run properties for a run inside a paragraph. */
2101
- effectiveRunProps(para: Paragraph, runProps: RunProps): RunProps;
2102
- numberingLevel(numId: number, ilvl: number): NumberingLevel | undefined;
2103
- numberingInstance(numId: number): NumInstance | undefined;
2104
- private findDocumentPart;
2105
- private readXmlOptional;
2106
- }
2107
-
2108
- /** Maps a rendered text item back to its source XML for editing. */
2109
- interface TextSource {
2110
- run: Run;
2111
- /** Source w:t; null when the text is synthetic (fields, symbols). */
2112
- t: XmlElement | null;
2113
- /** Char offset of this item's first character within t's text. */
2114
- offset: number;
2115
- }
2116
- /**
2117
- * Layout output: pages of absolutely positioned primitives (px, page-relative).
2118
- * The renderer maps these 1:1 to DOM/canvas/SVG — no further layout happens
2119
- * downstream, which is what guarantees pagination fidelity.
2120
- */
2121
- interface FontSpec {
2122
- family: string;
2123
- size: number;
2124
- bold: boolean;
2125
- italic: boolean;
2126
- /** Pair kerning is active because the run met its w:kern size threshold. */
2127
- kerning?: boolean;
2128
- /** Optional PAINT-only family tried before `family` in the CSS stack, without
2129
- * affecting metrics or width lookups (keyed by `family`). Used for CJK: the
2130
- * line-pitch profile stays keyed by the macOS substitute face while the real
2131
- * Windows glyphs (MS Mincho, Microsoft JhengHei, …) paint when available. */
2132
- paintFamily?: string;
2133
- /** PAINT-only vertical nudge (CSS px, positive = down) applied to the glyphs
2134
- * without touching layout metrics or advances. Used when a substitute face
2135
- * (Latha for Word's Tamil Vijaya) sits on a different baseline than the face
2136
- * Word rasterized; the shift lands the glyphs on Word's baseline. */
2137
- paintDY?: number;
2138
- }
2139
- interface PathItem {
2140
- kind: "path";
2141
- x: number;
2142
- y: number;
2143
- width: number;
2144
- height: number;
2145
- /** SVG path data in a `viewW x viewH` coordinate space. */
2146
- d: string;
2147
- viewW: number;
2148
- viewH: number;
2149
- fill?: string;
2150
- stroke?: {
2151
- color: string;
2152
- width: number;
2153
- opacity?: number;
2154
- };
2155
- rotate?: {
2156
- deg: number;
2157
- ox: number;
2158
- oy: number;
2159
- };
2160
- /** Paint under / over the body text (anchored-shape layering). */
2161
- behind?: boolean;
2162
- front?: boolean;
2163
- z?: number;
2164
- }
2165
- interface TextItem {
2166
- kind: "text";
2167
- x: number;
2168
- /** Baseline y. */
2169
- baseline: number;
2170
- width: number;
2171
- text: string;
2172
- props: RunProps;
2173
- font: FontSpec;
2174
- /** Footnote/endnote id referenced by this run (registration happens when
2175
- * the item lands on a real page - split table rows carry it across). */
2176
- noteId?: number;
2177
- /** Vertical stretch for tall delimiter glyphs (Word's glyph variants). */
2178
- mathScaleY?: number;
2179
- /** Horizontal stretch for wide brace glyphs (Word's over/under brace
2180
- * variants), applied about the glyph box's horizontal center. */
2181
- mathScaleX?: number;
2182
- /** Stretch anchor above the baseline, px. */
2183
- mathScaleAnchor?: number;
2184
- /** Line box for selection/highlight backgrounds. */
2185
- lineTop: number;
2186
- lineHeight: number;
2187
- /** Exact glyph box for baseline-shifted runs (superscript/subscript):
2188
- * the renderer anchors these instead of bottoming on the line box. */
2189
- glyphTop?: number;
2190
- glyphBoxH?: number;
2191
- /** Small-caps reduced segment: the base run font that must supply the
2192
- * strut so the painted baseline matches neighboring full-size spans (the
2193
- * renderer sizes the outer span with this font and shrinks the text via
2194
- * a baseline-aligned inner span). */
2195
- strutFont?: FontSpec;
2196
- /** PAGEREF bookmark name: the final pass rewrites this item's text with
2197
- * the bookmark's page number (Word recomputes PAGEREF on open; the docx
2198
- * cached result is stale in real TOCs). */
2199
- pageRef?: string;
2200
- /** DOCX bookmarks that begin on this text item. */
2201
- bookmarks?: string[];
2202
- /** Source m:oMath element when this text is a piece of an equation. */
2203
- mathSrc?: XmlElement;
2204
- href?: string;
2205
- /** Present for editable text (absent on numbering labels etc.). */
2206
- src?: TextSource;
2207
- /** This line is one a fixed-size text box hides past its bottom edge (see
2208
- * LaidOutPage.hiddenText). It mounts unpainted so a caret can bind to it, so
2209
- * anything that draws from item geometry — selection, comment highlights —
2210
- * must skip it or it paints a block where there is no text. */
2211
- hidden?: true;
2212
- /** Source drawing when this text belongs to an independently editable
2213
- * text-box story. */
2214
- textboxStory?: XmlElement;
2215
- /** Rotate about a point (px, relative to this item's top-left). */
2216
- rotate?: {
2217
- deg: number;
2218
- ox: number;
2219
- oy: number;
2220
- };
2221
- /** Paint under the body text (behindDoc textbox content). */
2222
- behind?: boolean;
2223
- /** Paint over the body text (non-behindDoc anchored shape content: Word
2224
- * layers in-front shapes above the text layer). */
2225
- front?: boolean;
2226
- z?: number;
2227
- /** Paint-only alpha for decorative text such as DrawingML WordArt. */
2228
- opacity?: number;
2229
- /** Right-to-left run: renderer sets direction:rtl so the browser shapes and
2230
- * orders the (Arabic/Hebrew) glyphs within the span box. */
2231
- rtl?: boolean;
2232
- /** Ordinal of the source paragraph within its cell/frame. Set only for
2233
- * widow-controlled paragraphs; row splitting uses it to scope Word's
2234
- * widow/orphan rules to the paragraph straddling the cut. */
2235
- paraSeq?: number;
2236
- /** Editor-only: maximum caret x for this item — a trailing hanging space
2237
- * confined to its table cell pins the caret at the cell's content edge
2238
- * (Word behavior) while the span keeps its true hanging layout x. */
2239
- caretClampX?: number;
2240
- }
2241
- interface RectItem {
2242
- kind: "rect";
2243
- x: number;
2244
- y: number;
2245
- width: number;
2246
- height: number;
2247
- fill: string;
2248
- /** Semantic paint provenance used by render-layer comparison. */
2249
- role?: "table-fill";
2250
- /** Rotate about a point (px, relative to this item's top-left). */
2251
- rotate?: {
2252
- deg: number;
2253
- ox: number;
2254
- oy: number;
2255
- };
2256
- behind?: boolean;
2257
- /** Paint over the body text (non-behindDoc anchored shape fill). */
2258
- front?: boolean;
2259
- z?: number;
2260
- }
2261
- interface LineEdgeItem {
2262
- kind: "edge";
2263
- x1: number;
2264
- y1: number;
2265
- x2: number;
2266
- y2: number;
2267
- border: Border;
2268
- /** Semantic paint provenance used by render-layer comparison. */
2269
- role?: "table-rule";
2270
- /** Rotate about a point (px, relative to this item's top-left). */
2271
- rotate?: {
2272
- deg: number;
2273
- ox: number;
2274
- oy: number;
2275
- };
2276
- /** Paint over the body text (non-behindDoc anchored shape border). */
2277
- front?: boolean;
2278
- /** Paint below the body text (behindDoc anchored shape border). */
2279
- behind?: boolean;
2280
- z?: number;
2281
- }
2282
- interface ImageItem {
2283
- kind: "image";
2284
- x: number;
2285
- y: number;
2286
- width: number;
2287
- height: number;
2288
- /** Package part path; renderer resolves bytes via DocxDocument.media(). */
2289
- part: string;
2290
- /** a:srcRect crop (fractions) and a:xfrm rotation (degrees). */
2291
- crop?: {
2292
- l: number;
2293
- t: number;
2294
- r: number;
2295
- b: number;
2296
- };
2297
- rotation?: number;
2298
- /** Whole-group rotation about an external origin. */
2299
- rotate?: {
2300
- deg: number;
2301
- ox: number;
2302
- oy: number;
2303
- };
2304
- /** Picture-watermark "washout" (VML v:imagedata gain/blacklevel, 0..1
2305
- * fractions). Per-channel linear recolor, measured against Word's PDF of
2306
- * probe2-picture-watermark (gain 0.3, blacklevel 0.35: source 32 -> 215,
2307
- * 74 -> 227, 135 -> 246, 210 -> clamped 255):
2308
- * out = in * gain + 255 * (blacklevel * (1 + gain) + (1 - gain) / 2) */
2309
- washout?: {
2310
- gain: number;
2311
- blacklevel: number;
2312
- };
2313
- /** a:ln picture outline, drawn just outside the image (Word hairline). */
2314
- border?: {
2315
- color: string;
2316
- width: number;
2317
- };
2318
- /** behindDoc: paint under the text layer. */
2319
- behind?: boolean;
2320
- /** wrapNone + !behindDoc ("in front of text"): paint ABOVE the text layer
2321
- * (Word's z-order; without this, later-emitted text spans cover the image
2322
- * and it neither shows in front nor receives clicks/drags). */
2323
- front?: boolean;
2324
- z?: number;
2325
- /** Source w:drawing element (for interactive resize/move). */
2326
- src?: XmlElement;
2327
- model3D?: Model3DReference;
2328
- webVideo?: WebVideoReference;
2329
- embeddedObject?: EmbeddedObjectReference;
2330
- }
2331
- interface ChartItem {
2332
- kind: "chart";
2333
- x: number;
2334
- y: number;
2335
- width: number;
2336
- height: number;
2337
- data: ChartData;
2338
- }
2339
- /** bodyPr autofit mode: how a shape reconciles its text with its box.
2340
- * "resizeShape" is a:spAutoFit (grow the box), "shrinkText" is a:normAutofit
2341
- * (scale the text down), "none" is a:noAutofit or no bodyPr autofit at all. */
2342
- type ShapeAutofit = "none" | "resizeShape" | "shrinkText";
2343
- /** What a text-bearing shape's laid-out text measured, beside the frame that
2344
- * holds it. The layout already measures the text to place it; recording the
2345
- * measurement here is what lets an agent see whether the text fits without
2346
- * re-measuring anything. */
2347
- interface DrawingTextFit {
2348
- /** Widest laid line, px (the text extent, not the box). It can exceed the
2349
- * box's inset width by a trailing space or an unbreakable token. */
2350
- textW: number;
2351
- /** Full laid text height, px. */
2352
- textH: number;
2353
- /** The text is taller than the box's insets leave room for. Overflow is a
2354
- * vertical question: the text is wrapped to the box width by construction,
2355
- * and a token too wide to wrap spends its excess on extra LINES. */
2356
- overflow: boolean;
2357
- /** Lines the box hides because they fall past its bottom. */
2358
- clippedLines: number;
2359
- autofit: ShapeAutofit;
2360
- }
2361
- /** Interactive resize zone over a table boundary (column or row). */
2362
- interface DrawingHitItem {
2363
- kind: "drawingHit";
2364
- x: number;
2365
- y: number;
2366
- width: number;
2367
- height: number;
2368
- /** Source w:drawing element (select/move the whole drawing). */
2369
- src: XmlElement;
2370
- /** Anchored drawings drag by offset; inline ones re-anchor into text. */
2371
- anchored: boolean;
2372
- /** Freehand stroke that may be removed with the Draw ribbon's eraser. */
2373
- ink?: boolean;
2374
- /** Native SmartArt diagram selection target. */
2375
- smartArt?: boolean;
2376
- /** Node hit boxes inside the SmartArt drawing, relative to this item. */
2377
- smartArtNodes?: Array<{
2378
- index: number;
2379
- x: number;
2380
- y: number;
2381
- width: number;
2382
- height: number;
2383
- }>;
2384
- chartData?: ChartData;
2385
- smartArtData?: SmartArtData;
2386
- /** A shape fill hit that sits UNDER the shape's own text spans (same z): a
2387
- * click on bare fill selects or drags the shape, while clicks on its text
2388
- * glyphs still reach the text editor. */
2389
- belowText?: boolean;
2390
- /** Keep a behindDoc drawing target under the body text. */
2391
- behind?: boolean;
2392
- /** The drawing owns an independently editable text-box story. */
2393
- textboxStory?: boolean;
2394
- /** Measured text extent for a text-bearing shape (agent fit inspection).
2395
- * Absent on drawings that flow no text: pictures, lines, charts, WordArt. */
2396
- textFit?: DrawingTextFit;
2397
- rotate?: {
2398
- deg: number;
2399
- ox: number;
2400
- oy: number;
2401
- };
2402
- z?: number;
2403
- }
2404
- interface GripItem {
2405
- kind: "grip";
2406
- /** "col": vertical zone at x spanning y1..y2. "row": horizontal zone at y1
2407
- * spanning x..x2. "move": table bounds x..x2, y1..y2. */
2408
- axis: "col" | "row" | "move";
2409
- x: number;
2410
- y1: number;
2411
- y2: number;
2412
- /** Right edge for row grips. */
2413
- x2?: number;
2414
- /** Source w:tbl element. */
2415
- tbl: XmlElement;
2416
- /** col: boundary 1..n (n = right edge). row: row index above the boundary. */
2417
- boundary: number;
2418
- /** Laid-out height of the row above (row grips), px. */
2419
- rowHeightPx?: number;
2420
- /** Rendered column widths px (col grips) — resize works in this space. */
2421
- renderedWidths?: number[];
2422
- }
2423
- /** WordArt/watermark text scaled to fill a box, rotated about its center. */
2424
- interface WordArtItem {
2425
- kind: "wordart";
2426
- /** Box top-left, px. */
2427
- x: number;
2428
- y: number;
2429
- width: number;
2430
- height: number;
2431
- text: string;
2432
- fontFamily: string;
2433
- bold?: boolean;
2434
- italic?: boolean;
2435
- fill: string;
2436
- opacity: number;
2437
- /** Clockwise degrees. */
2438
- rotation: number;
2439
- behind?: boolean;
2440
- /** Source v:textpath font-size (px). */
2441
- fontSize?: number;
2442
- /** Malformed shapetype guide path: Word collapses the fitted glyph outlines
2443
- * into a thin vertical band. */
2444
- noFit?: boolean;
2445
- /** Source VML shape element (v:shape / v:rect), for interactive select/edit. */
2446
- src?: XmlElement;
2447
- }
2448
- /** DrawingML a:prstTxWarp text: the shape's single text line bent onto a
2449
- * preset envelope (arch/wave/chevron/circle-pour), filling the shape box. */
2450
- interface WarpTextItem {
2451
- kind: "warptext";
2452
- /** Shape box top-left, px. */
2453
- x: number;
2454
- y: number;
2455
- width: number;
2456
- height: number;
2457
- text: string;
2458
- fontFamily: string;
2459
- /** Run font size px (the text's natural size; presets that don't fill the
2460
- * box — textArchUp — ride the text at this size). */
2461
- fontSize: number;
2462
- bold?: boolean;
2463
- italic?: boolean;
2464
- /** CSS text color. */
2465
- fill: string;
2466
- /** WordArt glyph alpha, 0..1. */
2467
- opacity?: number;
2468
- /** w14:textOutline glyph stroke. */
2469
- outline?: {
2470
- color: string;
2471
- width: number;
2472
- };
2473
- /** w14:shadow / w:shadow offset glyph shadow. */
2474
- shadow?: boolean;
2475
- /** Preset name (textArchUp, textWave1, textChevron, textCirclePour, …). */
2476
- warp: string;
2477
- rotate?: {
2478
- deg: number;
2479
- ox: number;
2480
- oy: number;
2481
- };
2482
- behind?: boolean;
2483
- front?: boolean;
2484
- z?: number;
2485
- }
2486
- type PageItem = TextItem | PathItem | RectItem | LineEdgeItem | ImageItem | ChartItem | DrawingHitItem | GripItem | WordArtItem | WarpTextItem;
2487
- interface LaidOutPage {
2488
- width: number;
2489
- height: number;
2490
- /** 1-based physical index. */
2491
- index: number;
2492
- /** Display page number after pgNumType.start is applied. */
2493
- number: number;
2494
- items: PageItem[];
2495
- /** Body box (for header/footer editing chrome). */
2496
- bodyTop: number;
2497
- bodyBottom: number;
2498
- /** Items from this index on belong to the header/footer parts. */
2499
- hfStart: number;
2500
- /** Column geometry for editor hit-testing. A page can contain more than one
2501
- * band when a continuous section changes the column layout mid-page. */
2502
- columnBands: Array<{
2503
- top: number;
2504
- colXs: number[];
2505
- colWidths: number[];
2506
- }>;
2507
- /** Lines a fixed-size text box (a:noAutofit) hides past its bottom edge.
2508
- * Held apart from `items` so nothing that paints, measures, or reads the
2509
- * page picks them up: they exist only so a caret that lands in the hidden
2510
- * part of a text-box story still has a place to be. */
2511
- hiddenText?: TextItem[];
2512
- }
2513
- /** Internal page-model window used by the DOM virtualizer. */
2514
- interface LayoutWindow {
2515
- /** Ensure that each requested page has a complete positioned item model. */
2516
- materialize(pageIndexes: Iterable<number>): void;
2517
- /** Release positioned items outside the requested page window. */
2518
- releaseExcept(pageIndexes: Iterable<number>): void;
2519
- /** Return the pages whose positioned items are retained. */
2520
- retainedPages(): Set<number>;
2521
- }
2522
- interface LayoutFontSample {
2523
- font: FontSpec;
2524
- text: string;
2525
- }
2526
- interface LayoutResult {
2527
- pages: LaidOutPage[];
2528
- totalPages: number;
2529
- /** Opaque incremental-reuse state (engine-internal); pass a previous result
2530
- * back as LayoutOptions.prev to enable incremental relayout. Not part of the
2531
- * rendered output and ignored by the equivalence harness. */
2532
- _incr?: unknown;
2533
- /** Internal marker: unchanged pages in this result retain exact object
2534
- * identity from the previous layout, so the DOM diff can use identity
2535
- * instead of structurally walking a dense changed page. */
2536
- _incremental?: boolean;
2537
- /** Exclusive global page index through which an incremental render may run
2538
- * pageEq before the page containing the exact dirty text source. */
2539
- _incrementalStructuralPrefixEnd?: number;
2540
- /** Opaque page state used to refresh headers/footers without repaginating
2541
- * the body when their measured geometry is unchanged. */
2542
- _hf?: unknown;
2543
- /** Internal positioned-model window. */
2544
- _window?: LayoutWindow;
2545
- /** Font samples collected before offscreen page items were released. */
2546
- _fontSamples?: LayoutFontSample[];
2547
- /** True when any page contains a 3D model item. */
2548
- _hasModel3D?: boolean;
2549
- }
2550
-
2551
- interface FontMetrics {
2552
- /** px above baseline (raw font ascent - anchors CSS glyph boxes). */
2553
- ascent: number;
2554
- /** px below baseline, raw (positive - anchors CSS glyph boxes). */
2555
- descent: number;
2556
- /** Natural single-spaced line height px (what Word calls single spacing). */
2557
- lineHeight: number;
2558
- /** Word's below-baseline share of lineHeight (quantized); use for
2559
- * baseline placement. Falls back to `descent` when absent. */
2560
- lineDescent?: number;
2561
- }
2562
- interface TextMeasurer {
2563
- width(text: string, font: FontSpec, letterSpacing?: number): number;
2564
- metrics(font: FontSpec): FontMetrics;
2565
- /** The browser's own font box (fontBoundingBoxAscent/Descent) for the
2566
- * resolved first face of this font's CSS stack, when the host can know it.
2567
- * Used to anchor paint-routed CJK spans: the DOM renderer centers glyphs
2568
- * by the browser strut, which differs from the engine's calibrated line
2569
- * profile (Hiragino/PingFang) whenever the real Windows face paints. */
2570
- paintBox?(font: FontSpec): {
2571
- ascent: number;
2572
- descent: number;
2573
- } | undefined;
2574
- /** Ink extents (actualBoundingBox*) of `text` in the RESOLVED paint face,
2575
- * px above/below the baseline. The radical join needs the √ glyph's real
2576
- * ink — which face paints it (real Cambria Math vs the STIX substitute)
2577
- * changes the extents, so a baked table can't cover both. */
2578
- inkBox?(text: string, font: FontSpec): {
2579
- ascent: number;
2580
- descent: number;
2581
- } | undefined;
2582
- }
2583
-
2584
- /** One mail-merge data record: column name → this record's value. The host
2585
- * parses the data file and hands over plain strings; the engine never learns a
2586
- * path, a connection string or a query. */
2587
- type MergeRecord = Readonly<Record<string, string>>;
2588
- interface LayoutOptions {
2589
- measurer?: TextMeasurer;
2590
- /** Retain positioned items only for a viewport-sized page window. */
2591
- windowModel?: boolean;
2592
- /** Mail-merge PREVIEW: the active record's column values, substituted into
2593
- * MERGEFIELD fields as they are painted. Nothing is written to the document —
2594
- * see FieldContext.mergeField. Absent renders the «Name» placeholders. */
2595
- mergeRecord?: MergeRecord;
2596
- /** Previous layout result (from an earlier layoutDocument call on the same
2597
- * document). Enables incremental relayout: pages whose input blocks and
2598
- * lead-in state are unchanged are reused instead of re-laid. The engine falls
2599
- * back to a full layout whenever it cannot prove reuse is byte-identical. */
2600
- prev?: LayoutResult;
2601
- /** The top-level block XML element (w:p / w:tbl) the editor mutated IN PLACE
2602
- * since `prev` — the paragraph the caret sits in for a single-character
2603
- * type/delete. Lets the incremental scan skip re-hashing every block: it
2604
- * re-hashes only the hinted block and its two neighbours and reuses prev's
2605
- * per-block signatures for the rest. Purely an optimisation — the fast path
2606
- * is gated on block identity/count and neighbour-signature checks, so a stale
2607
- * or wrong hint falls through to the full block scan. */
2608
- dirtyHint?: XmlElement;
2609
- /** Exact retained text element changed by a local edit. Used only to bound
2610
- * structural page comparison before the first actually dirty page. */
2611
- dirtySource?: XmlElement;
2612
- }
2613
- declare function layoutDocument(doc: DocxDocument, options?: LayoutOptions): LayoutResult;
2614
-
2615
- interface RenderOptions {
2616
- /** Zoom factor (1 = 100%). */
2617
- zoom?: number;
2618
- /** Gap between pages, px. */
2619
- pageGap?: number;
2620
- /** Page drop shadow / chrome. */
2621
- pageShadow?: boolean;
2622
- /** Materialize interactive affordances (table resize grips). */
2623
- interactive?: boolean;
2624
- /** Keep only nearby page contents mounted. Page shells always remain so
2625
- * scroll geometry is unchanged. Intended for long interactive documents. */
2626
- virtualize?: boolean;
2627
- /** Called after the mounted page window changes so editor chrome can be
2628
- * restored on newly-mounted pages. */
2629
- onViewportChange?: () => void;
2630
- /** Show review comments (highlight + margin balloons). Default true. */
2631
- comments?: boolean;
2632
- /** Called when the user deletes a comment from its balloon. The balloon
2633
- * shows a delete button only when this is provided. */
2634
- onDeleteComment?: (id: string) => void;
2635
- /** Called when the user submits a reply from a balloon's reply box. The
2636
- * reply box only renders when this is provided. */
2637
- onReplyComment?: (id: string, text: string) => void;
2638
- /** Called when the user resolves (true) or reopens (false) a thread from
2639
- * its balloon. The button only renders when this is provided. */
2640
- onResolveComment?: (id: string, resolved: boolean) => void;
2641
- /** Called when the user commits an in-balloon edit of a comment's text.
2642
- * Offered only on comments whose author matches `commentAuthor`. */
2643
- onEditComment?: (id: string, text: string) => void;
2644
- /** The local user's comment author name — gates the edit affordance to
2645
- * their own comments (Word's edit-my-comment rule). */
2646
- commentAuthor?: string;
2647
- }
2648
- interface TextBinding {
2649
- el: HTMLElement;
2650
- item: TextItem;
2651
- }
2652
- interface GripBinding {
2653
- el: HTMLElement;
2654
- item: GripItem;
2655
- }
2656
- interface ImageBinding {
2657
- el: HTMLElement;
2658
- item: ImageItem;
2659
- }
2660
- interface DrawingBinding {
2661
- el: HTMLElement;
2662
- item: DrawingHitItem;
2663
- }
2664
- interface WordArtBinding {
2665
- el: HTMLElement;
2666
- item: WordArtItem;
2667
- }
2668
- interface RenderHandle {
2669
- /** Root element containing all pages. */
2670
- root: HTMLElement;
2671
- /** Rendered text elements in paint order, for selection mapping. */
2672
- bindings: TextBinding[];
2673
- /** Mounted text bindings indexed by their retained source w:t element. */
2674
- bindingsByText: Map<XmlElement, TextBinding[]>;
2675
- /** Table resize grips (only when options.interactive). */
2676
- grips: GripBinding[];
2677
- /** Rendered images, for interactive select/resize/move. */
2678
- images: ImageBinding[];
2679
- /** Transparent hit targets over vector drawings/icons (select/move). */
2680
- drawings: DrawingBinding[];
2681
- /** WordArt / text watermarks, for interactive select/edit. */
2682
- wordarts: WordArtBinding[];
2683
- /** Revoke object URLs etc. */
2684
- destroy: () => void;
2685
- /** Temporarily mount every page, returning a function that restores the
2686
- * viewport window. Used by the synchronous print-clone path. */
2687
- materializeAll?: () => () => void;
2688
- /** Recompute the mounted page window after an external scroll/resize. */
2689
- updateViewport?: () => void;
2690
- /** Per-page render records, retained so the next render can reuse the DOM of
2691
- * pages whose layout is unchanged (see renderToDom's `prev` parameter). */
2692
- _pages?: PageRender[];
2693
- /** Whether this render drew the comments overlay. Comment highlights live
2694
- * INSIDE page surfaces, so the next render must sweep them out of any page
2695
- * DOM it adopts before re-running the overlay. */
2696
- _hadComments?: boolean;
2697
- /** Zoom this render painted at — adoption is only valid at the same zoom. */
2698
- _zoom?: number;
2699
- /** Whether this handle keeps only a viewport-sized page window mounted. */
2700
- _virtualized?: boolean;
2701
- /** Parsed-model generation whose source bindings this handle owns. */
2702
- _modelVersion?: number;
2703
- /** Remove viewport listeners before this handle is replaced. */
2704
- _stopVirtualizer?: () => void;
2705
- }
2706
- /** One page's DOM element plus the editor bindings it owns and the object URLs
2707
- * it created. Retained on the handle so an incremental re-render can adopt an
2708
- * unchanged page wholesale instead of tearing it down and rebuilding it. */
2709
- interface PageRender {
2710
- el: HTMLElement;
2711
- page: LaidOutPage;
2712
- bindings: TextBinding[];
2713
- grips: GripBinding[];
2714
- images: ImageBinding[];
2715
- drawings: DrawingBinding[];
2716
- wordarts: WordArtBinding[];
2717
- urls: string[];
2718
- mounted: boolean;
2719
- }
2720
- declare function renderToDom(doc: DocxDocument, layout: LayoutResult, container: HTMLElement, options?: RenderOptions, prev?: RenderHandle): RenderHandle;
2721
- /**
2722
- * Print the rendered pages (browser print -> paper or PDF): clones the page
2723
- * DOM into a hidden same-origin iframe sized to the document's page, strips
2724
- * screen chrome (shadows, gaps), and invokes the print dialog.
2725
- */
2726
- 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-jIZisiQh.js';
2727
3
 
2728
4
  /** The legacy named presets, or any DrawingML ST_ShapeType name the preset
2729
5
  * geometry table knows (isValidShapePreset). */
@@ -4026,10 +1302,15 @@ type EditorIntent = RegisteredOperationBody | {
4026
1302
  * INSIDE it). Such a paragraph is never word-diffed: if it changed at all it
4027
1303
  * is struck whole and the new one inserted whole, and `onNote` says so.
4028
1304
  *
4029
- * **Headers, footers, footnotes, endnotes, comments, styles and numbering —
4030
- * NOT compared.** The result carries `revised`'s. `onNote` reports when
4031
- * `original`'s differ, so a reviewer is never told "no change" about something
4032
- * 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.
4033
1314
  *
4034
1315
  * **Moves — not detected, by architecture.** `RevisionKind` has no moveFrom /
4035
1316
  * moveTo member and nothing in suggest.ts writes those elements, so a move is
@@ -4052,6 +1333,10 @@ interface CompareNote {
4052
1333
  | "no-common-paragraph"
4053
1334
  /** Original-only content referencing a relationship the result does not have. */
4054
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"
4055
1340
  /** An input held tracked changes; it was compared as if they were accepted. */
4056
1341
  | "existing-revisions-accepted";
4057
1342
  detail: string;
@@ -4142,10 +1427,11 @@ interface WatermarkSpec {
4142
1427
  }
4143
1428
 
4144
1429
  /**
4145
- * Lay out and render a whole .docx into `container` for a headless browser
4146
- * to print. Resolves once the pages are final: fonts loaded, every image
4147
- * converted and decoded. Print with the CSS page size to get one PDF page
4148
- * 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.
4149
1435
  */
4150
1436
  declare function renderForPrint(bytes: Uint8Array, container: HTMLElement): Promise<{
4151
1437
  pageCount: number;
@@ -6629,4 +3915,4 @@ declare function useAgentDocumentSession(binding: AgentDocumentViewBinding): Pic
6629
3915
  */
6630
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;
6631
3917
 
6632
- 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 };