@docx4j/core-ts 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/NOTICE +4 -0
  2. package/README.md +34 -3
  3. package/dist/html/convert.mjs +40 -15
  4. package/dist/html/elements.mjs +2 -1
  5. package/dist/model/color/ColorMath.d.mts +29 -0
  6. package/dist/model/color/ColorMath.mjs +146 -0
  7. package/dist/model/color/ColorTables.d.mts +6 -0
  8. package/dist/model/color/ColorTables.mjs +83 -0
  9. package/dist/model/color/DrawingMLColors.d.mts +52 -0
  10. package/dist/model/color/DrawingMLColors.mjs +374 -0
  11. package/dist/model/color/ResolvedColor.d.mts +36 -0
  12. package/dist/model/color/ResolvedColor.mjs +65 -0
  13. package/dist/model/color/SpreadsheetColors.d.mts +36 -0
  14. package/dist/model/color/SpreadsheetColors.mjs +84 -0
  15. package/dist/model/color/StyleFill.d.mts +28 -0
  16. package/dist/model/color/StyleFill.mjs +21 -0
  17. package/dist/model/color/ThemeColors.d.mts +86 -0
  18. package/dist/model/color/ThemeColors.mjs +304 -0
  19. package/dist/model/color/WordColors.d.mts +71 -0
  20. package/dist/model/color/WordColors.mjs +121 -0
  21. package/dist/model/color/index.d.mts +6 -0
  22. package/dist/model/color/index.mjs +30 -0
  23. package/dist/model/content/Body.d.mts +153 -19
  24. package/dist/model/content/Body.mjs +570 -131
  25. package/dist/model/content/Comment.d.mts +21 -3
  26. package/dist/model/content/Comment.mjs +202 -19
  27. package/dist/model/content/ContentControl.d.mts +197 -18
  28. package/dist/model/content/ContentControl.mjs +664 -95
  29. package/dist/model/content/Font.d.mts +67 -17
  30. package/dist/model/content/Font.mjs +114 -35
  31. package/dist/model/content/InlinePicture.d.mts +82 -7
  32. package/dist/model/content/InlinePicture.mjs +221 -28
  33. package/dist/model/content/List.mjs +13 -1
  34. package/dist/model/content/Paragraph.d.mts +213 -14
  35. package/dist/model/content/Paragraph.mjs +936 -100
  36. package/dist/model/content/Range.d.mts +242 -11
  37. package/dist/model/content/Range.mjs +975 -119
  38. package/dist/model/content/ResolvedView.d.mts +104 -0
  39. package/dist/model/content/ResolvedView.mjs +596 -0
  40. package/dist/model/content/Table.d.mts +29 -3
  41. package/dist/model/content/Table.mjs +109 -33
  42. package/dist/model/content/TrackedChange.d.mts +301 -16
  43. package/dist/model/content/TrackedChange.mjs +1284 -158
  44. package/dist/model/content/binder.d.mts +2 -1
  45. package/dist/model/content/binder.mjs +48 -1
  46. package/dist/model/content/comments.d.mts +20 -6
  47. package/dist/model/content/comments.mjs +67 -57
  48. package/dist/model/content/generalException.d.mts +18 -0
  49. package/dist/model/content/generalException.mjs +24 -0
  50. package/dist/model/content/index.d.mts +8 -3
  51. package/dist/model/content/index.mjs +7 -2
  52. package/dist/model/content/mathText.d.mts +21 -0
  53. package/dist/model/content/mathText.mjs +267 -0
  54. package/dist/model/content/officeText.d.mts +27 -0
  55. package/dist/model/content/officeText.mjs +74 -0
  56. package/dist/model/content/outline.d.mts +5 -0
  57. package/dist/model/content/outline.mjs +13 -0
  58. package/dist/model/content/placeholders.d.mts +110 -0
  59. package/dist/model/content/placeholders.mjs +253 -0
  60. package/dist/model/content/relationships.d.mts +30 -0
  61. package/dist/model/content/relationships.mjs +133 -0
  62. package/dist/model/content/search.d.mts +72 -0
  63. package/dist/model/content/search.mjs +204 -2
  64. package/dist/model/content/spanEdits.d.mts +159 -0
  65. package/dist/model/content/spanEdits.mjs +728 -0
  66. package/dist/model/content/story.d.mts +44 -0
  67. package/dist/model/content/story.mjs +92 -0
  68. package/dist/model/content/tableColumns.d.mts +1 -1
  69. package/dist/model/content/tableColumns.mjs +108 -80
  70. package/dist/model/content/tableRevisions.d.mts +11 -3
  71. package/dist/model/content/tableRevisions.mjs +72 -42
  72. package/dist/model/content/tableRules.d.mts +30 -0
  73. package/dist/model/content/tableRules.mjs +100 -0
  74. package/dist/model/content/textBoxes.d.mts +18 -0
  75. package/dist/model/content/textBoxes.mjs +105 -0
  76. package/dist/model/content/trackedChangeFilter.d.mts +39 -0
  77. package/dist/model/content/trackedChangeFilter.mjs +81 -0
  78. package/dist/model/content/tracking.d.mts +28 -0
  79. package/dist/model/content/tracking.mjs +149 -10
  80. package/dist/model/content/tree.d.mts +212 -13
  81. package/dist/model/content/tree.mjs +356 -35
  82. package/dist/model/customxml/CustomXmlPartCollection.d.mts +8 -0
  83. package/dist/model/customxml/CustomXmlPartCollection.mjs +34 -11
  84. package/dist/model/customxml/XmlMapping.d.mts +1 -1
  85. package/dist/model/customxml/XmlMapping.mjs +11 -0
  86. package/dist/model/customxml/bindings.d.mts +21 -2
  87. package/dist/model/customxml/bindings.mjs +76 -32
  88. package/dist/model/customxml/kinds.d.mts +8 -3
  89. package/dist/model/customxml/kinds.mjs +26 -5
  90. package/dist/model/customxml/picturePlaceholder.d.mts +17 -0
  91. package/dist/model/customxml/picturePlaceholder.mjs +32 -0
  92. package/dist/model/customxml/pictures.d.mts +9 -5
  93. package/dist/model/customxml/pictures.mjs +31 -13
  94. package/dist/model/customxml/xhtml.mjs +8 -2
  95. package/dist/model/fonts/families.generated.mjs +2 -2
  96. package/dist/model/fonts/registry.mjs +7 -1
  97. package/dist/model/fonts/substitutions.generated.mjs +2 -2
  98. package/dist/model/fonts/themes.generated.mjs +1 -1
  99. package/dist/model/index.d.mts +2 -0
  100. package/dist/model/index.mjs +4 -0
  101. package/dist/model/listnumbering/Emulator.d.mts +37 -5
  102. package/dist/model/listnumbering/Emulator.mjs +63 -9
  103. package/dist/model/listnumbering/definitions.mjs +18 -0
  104. package/dist/model/properties/PropertyResolver.d.mts +87 -7
  105. package/dist/model/properties/PropertyResolver.mjs +197 -17
  106. package/dist/model/properties/catalogue.d.mts +32 -4
  107. package/dist/model/properties/catalogue.mjs +115 -36
  108. package/dist/model/properties/log.d.mts +1 -1
  109. package/dist/model/properties/log.mjs +5 -5
  110. package/dist/model/properties/table.d.mts +16 -2
  111. package/dist/model/properties/table.mjs +17 -5
  112. package/dist/model/text/Extractor.d.mts +289 -0
  113. package/dist/model/text/Extractor.mjs +2162 -0
  114. package/dist/model/text/LinkTargets.d.mts +45 -0
  115. package/dist/model/text/LinkTargets.mjs +170 -0
  116. package/dist/model/text/MarkdownExporter.d.mts +140 -0
  117. package/dist/model/text/MarkdownExporter.mjs +255 -0
  118. package/dist/model/text/PlainText.d.mts +29 -0
  119. package/dist/model/text/PlainText.mjs +539 -0
  120. package/dist/model/text/TextContext.d.mts +161 -0
  121. package/dist/model/text/TextContext.mjs +425 -0
  122. package/dist/model/text/TextOptions.d.mts +150 -0
  123. package/dist/model/text/TextOptions.mjs +278 -0
  124. package/dist/model/text/TextResult.d.mts +504 -0
  125. package/dist/model/text/TextResult.mjs +526 -0
  126. package/dist/model/text/Texts.d.mts +99 -0
  127. package/dist/model/text/Texts.mjs +187 -0
  128. package/dist/model/text/WmlToMarkdown.d.mts +120 -0
  129. package/dist/model/text/WmlToMarkdown.mjs +911 -0
  130. package/dist/model/text/commonmark.d.mts +121 -0
  131. package/dist/model/text/commonmark.mjs +655 -0
  132. package/dist/model/text/index.d.mts +7 -0
  133. package/dist/model/text/index.mjs +8 -0
  134. package/dist/model/text/normalize.d.mts +8 -0
  135. package/dist/model/text/normalize.mjs +13 -0
  136. package/dist/model/text/outline.d.mts +4 -0
  137. package/dist/model/text/outline.mjs +71 -0
  138. package/dist/office-js/fragment.d.mts +7 -5
  139. package/dist/office-js/fragment.mjs +63 -14
  140. package/dist/office-js/proxy.d.mts +8 -0
  141. package/dist/office-js/proxy.mjs +29 -0
  142. package/dist/office-js/run.mjs +2 -0
  143. package/dist/office-js/supported.generated.mjs +16 -0
  144. package/dist/office-js/toApiScript.mjs +21 -5
  145. package/dist/opc/Load.d.mts +9 -2
  146. package/dist/opc/Save.d.mts +17 -0
  147. package/dist/opc/Save.mjs +12 -2
  148. package/dist/opc/index.d.mts +3 -3
  149. package/dist/opc/index.mjs +2 -2
  150. package/dist/opc/mce/preprocessor.d.mts +88 -7
  151. package/dist/opc/mce/preprocessor.mjs +144 -37
  152. package/dist/opc/mce/understood.d.mts +34 -0
  153. package/dist/opc/mce/understood.mjs +55 -3
  154. package/dist/packages/OpcPackage.d.mts +20 -0
  155. package/dist/packages/OpcPackage.mjs +16 -3
  156. package/dist/packages/WordprocessingMLPackage.d.mts +77 -7
  157. package/dist/packages/WordprocessingMLPackage.mjs +242 -11
  158. package/dist/parts/DefaultXmlPart.mjs +2 -2
  159. package/dist/parts/Part.d.mts +10 -2
  160. package/dist/parts/XmlPart.d.mts +35 -32
  161. package/dist/parts/XmlPart.mjs +107 -107
  162. package/dist/parts/wml/comments.mjs +30 -0
  163. package/dist/parts/wml/index.mjs +12 -0
  164. package/dist/xml/dom.d.mts +7 -0
  165. package/dist/xml/dom.mjs +18 -0
  166. package/package.json +2 -2
@@ -1,3 +1,4 @@
1
+ import { WordColors } from '../color/WordColors.mjs';
1
2
  // ---------------------------------------------------------------- copying
2
3
  /**
3
4
  * A structural copy of a leaf value, without its `PARENT` link: what the merges store, so
@@ -29,9 +30,21 @@ function emptyThemeColor(value) {
29
30
  function attr(source, destination) {
30
31
  return source === undefined ? destination : source;
31
32
  }
32
- /** docx4j `StyleUtil.apply(STThemeColor, STThemeColor)`: `none` does not override. */
33
- function themeColor(source, destination) {
34
- return emptyThemeColor(source) ? destination : source;
33
+ /**
34
+ * docx4j `StyleUtil.statesColour`: a colour's value or theme reference is stated, so the colour
35
+ * inherits as one (docx4j CR-034, 2e381ef26; see {@link mergeColor}).
36
+ */
37
+ function statesColour(val, theme) {
38
+ return !emptyString(val) || !emptyThemeColor(theme);
39
+ }
40
+ /**
41
+ * docx4j `StyleUtil.statesWordColour` (its CR-060, 1d1b824a9): as {@link statesColour}, for a text or underline
42
+ * colour, whose value Word reads as absent where it rejects it ({@link WordColors.stated}: `F00`, `bogus`, `Auto`).
43
+ * A fill's or a border's colour keeps {@link statesColour}: Word reads any value there, one it rejects as automatic,
44
+ * which overrides a style's (CR-015 section 2, rule 5).
45
+ */
46
+ function statesWordColour(val, theme) {
47
+ return WordColors.stated(val) || !emptyThemeColor(theme);
35
48
  }
36
49
  /** A merge with no per-attribute rule: a copy of the source where it has one, else the inherited. */
37
50
  export function mergeReplace(source, destination) {
@@ -71,14 +84,39 @@ export function isEmptyRFonts(value) {
71
84
  && emptyString(value.eastAsia) && value.eastAsiaTheme === undefined
72
85
  && emptyString(value.hAnsi) && value.hAnsiTheme === undefined);
73
86
  }
87
+ /**
88
+ * A `w:color` stating only a theme colour is not empty: it is inherited, where until docx4j CR-034
89
+ * (2e381ef26) it was dropped. A value Word reads as absent (`F00`, `bogus`, `Auto`) is empty, so a style's
90
+ * colour beneath still shows, and only exactly `auto` overrides it (docx4j CR-060, {@link WordColors.stated};
91
+ * CR-015 section 2, rules 4 and 5).
92
+ */
74
93
  export function isEmptyColor(value) {
75
- return value === undefined || emptyString(value.val);
94
+ return value === undefined
95
+ || (!WordColors.stated(value.val) && value.themeColor === undefined
96
+ && emptyString(value.themeTint) && emptyString(value.themeShade));
76
97
  }
98
+ /**
99
+ * The underline's colour attributes count, the theme ones too (docx4j CR-034, 2e381ef26); a colour Word reads as
100
+ * absent doesn't (docx4j CR-060, {@link WordColors.stated}).
101
+ */
77
102
  export function isEmptyU(value) {
78
- return value === undefined || (value.val === undefined && emptyString(value.color));
103
+ return value === undefined
104
+ || (value.val === undefined && !WordColors.stated(value.color) && value.themeColor === undefined
105
+ && emptyString(value.themeTint) && emptyString(value.themeShade));
106
+ }
107
+ /** `ST_HighlightColor`'s values, which Word compares case-exactly (docx4j `WordRepairs`). */
108
+ const HIGHLIGHT_COLORS = new Set(['black', 'blue', 'cyan', 'green', 'magenta', 'red', 'yellow',
109
+ 'white', 'darkBlue', 'darkCyan', 'darkGreen', 'darkMagenta', 'darkRed', 'darkYellow', 'darkGray', 'lightGray', 'none']);
110
+ /** Whether a `w:highlight` value is one of `ST_HighlightColor`'s, compared case-exactly, as Word does (docx4j `WordRepairs.isHighlightColor`). */
111
+ export function isHighlightColor(val) {
112
+ return val !== undefined && HIGHLIGHT_COLORS.has(val);
79
113
  }
114
+ /**
115
+ * A value outside `ST_HighlightColor` (`YELLOW`, `bogus`), or none, is empty: Word's repair drops it, so a style's
116
+ * highlight beneath still shows (docx4j CR-060, its `StyleUtil.isEmpty(Highlight)`).
117
+ */
80
118
  export function isEmptyHighlight(value) {
81
- return value === undefined || emptyString(value.val);
119
+ return value === undefined || !isHighlightColor(value.val);
82
120
  }
83
121
  /** @since CR-015 phase 1: a style stating only `w:lang` used to count as empty and was never applied. */
84
122
  export function isEmptyLang(value) {
@@ -139,16 +177,18 @@ export function isEmptyNumPr(value) {
139
177
  || ((value.numId === undefined || value.numId.val === undefined)
140
178
  && (value.ilvl === undefined || value.ilvl.val === undefined));
141
179
  }
142
- /** `w:anchorLock` defaults to true, so only an explicit `w:anchorLock="0"` makes a frame non-empty by itself. */
180
+ /**
181
+ * Empty only with `w:anchorLock` absent too, as docx4j 82c64bf14 reads it (its CR-059: until then
182
+ * `isAnchorLock()`, which the schema's old `default="true"` made true for an absent attribute).
183
+ */
143
184
  export function isEmptyFramePr(value) {
144
- var _a;
145
185
  return value === undefined
146
186
  || (value.dropCap === undefined && value.lines === undefined && value.w === undefined
147
187
  && value.h === undefined && value.vSpace === undefined && value.hSpace === undefined
148
188
  && value.wrap === undefined && value.hAnchor === undefined && value.vAnchor === undefined
149
189
  && value.x === undefined && value.xAlign === undefined
150
190
  && value.y === undefined && value.yAlign === undefined && value.hRule === undefined
151
- && ((_a = value.anchorLock) !== null && _a !== void 0 ? _a : true));
191
+ && value.anchorLock === undefined);
152
192
  }
153
193
  function isEmptyTblWidth(value) {
154
194
  // @w:type is ignored, as docx4j does
@@ -291,28 +331,49 @@ export const mergeRFonts = (source, destination) => {
291
331
  out.hint = source.hint;
292
332
  return out;
293
333
  };
334
+ /**
335
+ * A colour inherits as one (docx4j CR-034, 2e381ef26): where the source states a value or a theme
336
+ * reference, its value, theme colour, tint and shade replace the destination's together. Word
337
+ * draws a theme reference over the value written beside it, so taken one by one, a run's
338
+ * `w:val="FF0000"` under a style's `w:themeColor="accent1"` would keep the style's reference and
339
+ * draw accent1, where Word draws red. A tint or shade stated alone still inherits on its own. The
340
+ * same holds for the colours of `w:u`, `w:shd` (its pattern colour and its fill) and the borders.
341
+ * (Attribute by attribute until then, CR-015 phase 1.)
342
+ */
294
343
  export const mergeColor = (source, destination) => {
295
344
  if (isEmptyColor(source))
296
345
  return destination;
297
346
  const s = source;
298
347
  const out = (destination !== null && destination !== void 0 ? destination : {});
299
- out.themeColor = themeColor(s.themeColor, out.themeColor);
300
- out.themeShade = attr(s.themeShade, out.themeShade);
301
- out.themeTint = attr(s.themeTint, out.themeTint);
302
- out.val = attr(s.val, out.val);
348
+ if (statesWordColour(s.val, s.themeColor)) {
349
+ out.val = s.val;
350
+ out.themeColor = s.themeColor;
351
+ out.themeTint = s.themeTint;
352
+ out.themeShade = s.themeShade;
353
+ }
354
+ else {
355
+ out.themeShade = attr(s.themeShade, out.themeShade);
356
+ out.themeTint = attr(s.themeTint, out.themeTint);
357
+ }
303
358
  return out;
304
359
  };
305
- /** `w:val` and the colour attributes each inherit on their own (CR-015 phase 1). */
360
+ /** `w:val` and the colour inherit on their own (CR-015 phase 1), the colour as one ({@link mergeColor}). */
306
361
  export const mergeU = (source, destination) => {
307
362
  if (isEmptyU(source))
308
363
  return destination;
309
364
  const s = source;
310
365
  const out = destination !== null && destination !== void 0 ? destination : {};
311
366
  out.val = attr(s.val, out.val);
312
- out.color = attr(s.color, out.color);
313
- out.themeColor = themeColor(s.themeColor, out.themeColor);
314
- out.themeTint = attr(s.themeTint, out.themeTint);
315
- out.themeShade = attr(s.themeShade, out.themeShade);
367
+ if (statesWordColour(s.color, s.themeColor)) {
368
+ out.color = s.color;
369
+ out.themeColor = s.themeColor;
370
+ out.themeTint = s.themeTint;
371
+ out.themeShade = s.themeShade;
372
+ }
373
+ else {
374
+ out.themeTint = attr(s.themeTint, out.themeTint);
375
+ out.themeShade = attr(s.themeShade, out.themeShade);
376
+ }
316
377
  return out;
317
378
  };
318
379
  /** `w:val`, `w:eastAsia` and `w:bidi` each name the language of one script range and each inherits. */
@@ -331,16 +392,29 @@ export const mergeShd = (source, destination) => {
331
392
  return destination;
332
393
  const s = source;
333
394
  const out = (destination !== null && destination !== void 0 ? destination : {});
334
- out.color = attr(s.color, out.color);
335
- out.fill = attr(s.fill, out.fill);
336
395
  out.val = attr(s.val, out.val);
337
- out.themeTint = attr(s.themeTint, out.themeTint);
338
- out.themeShade = attr(s.themeShade, out.themeShade);
339
- out.themeFillTint = attr(s.themeFillTint, out.themeFillTint);
340
- out.themeFillShade = attr(s.themeFillShade, out.themeFillShade);
341
- // the enums only when the source states them (until CR-015 a null source cleared them)
342
- out.themeColor = themeColor(s.themeColor, out.themeColor);
343
- out.themeFill = themeColor(s.themeFill, out.themeFill);
396
+ // the pattern colour and the fill each inherit as one (see mergeColor), so a direct w:shd
397
+ // stating no fill still leaves an inherited w:themeFill (CR-015)
398
+ if (statesColour(s.color, s.themeColor)) {
399
+ out.color = s.color;
400
+ out.themeColor = s.themeColor;
401
+ out.themeTint = s.themeTint;
402
+ out.themeShade = s.themeShade;
403
+ }
404
+ else {
405
+ out.themeTint = attr(s.themeTint, out.themeTint);
406
+ out.themeShade = attr(s.themeShade, out.themeShade);
407
+ }
408
+ if (statesColour(s.fill, s.themeFill)) {
409
+ out.fill = s.fill;
410
+ out.themeFill = s.themeFill;
411
+ out.themeFillTint = s.themeFillTint;
412
+ out.themeFillShade = s.themeFillShade;
413
+ }
414
+ else {
415
+ out.themeFillTint = attr(s.themeFillTint, out.themeFillTint);
416
+ out.themeFillShade = attr(s.themeFillShade, out.themeFillShade);
417
+ }
344
418
  return out;
345
419
  };
346
420
  export const mergeBorder = (source, destination) => {
@@ -348,13 +422,20 @@ export const mergeBorder = (source, destination) => {
348
422
  return destination;
349
423
  const s = source;
350
424
  const out = (destination !== null && destination !== void 0 ? destination : {});
351
- out.color = attr(s.color, out.color);
352
425
  out.space = attr(s.space, out.space);
353
426
  out.sz = attr(s.sz, out.sz);
354
- out.themeColor = themeColor(s.themeColor, out.themeColor);
355
- out.themeShade = attr(s.themeShade, out.themeShade);
356
- out.themeTint = attr(s.themeTint, out.themeTint);
357
427
  out.val = attr(s.val, out.val);
428
+ // the colour inherits as one (see mergeColor)
429
+ if (statesColour(s.color, s.themeColor)) {
430
+ out.color = s.color;
431
+ out.themeColor = s.themeColor;
432
+ out.themeTint = s.themeTint;
433
+ out.themeShade = s.themeShade;
434
+ }
435
+ else {
436
+ out.themeShade = attr(s.themeShade, out.themeShade);
437
+ out.themeTint = attr(s.themeTint, out.themeTint);
438
+ }
358
439
  return out;
359
440
  };
360
441
  export const mergePBdr = (source, destination) => {
@@ -483,11 +564,10 @@ export const mergeTabs = (source, destination) => {
483
564
  };
484
565
  /**
485
566
  * `w:framePr`'s attributes each inherit on their own: a paragraph whose direct `w:framePr`
486
- * gives only `w:x`/`w:y` keeps the anchors its style states. `w:anchorLock` defaults to true,
487
- * and docx4j's merge writes that default out explicitly.
567
+ * gives only `w:x`/`w:y` keeps the anchors its style states, `w:anchorLock` among them (docx4j
568
+ * 82c64bf14 merges it as stated; until then its merge wrote `isAnchorLock()`'s default out).
488
569
  */
489
570
  export const mergeFramePr = (source, destination) => {
490
- var _a;
491
571
  if (isEmptyFramePr(source))
492
572
  return destination;
493
573
  const s = source;
@@ -506,8 +586,7 @@ export const mergeFramePr = (source, destination) => {
506
586
  out.y = attr(s.y, out.y);
507
587
  out.yAlign = attr(s.yAlign, out.yAlign);
508
588
  out.hRule = attr(s.hRule, out.hRule);
509
- // docx4j reads this through isAnchorLock(), which answers true when the attribute is absent
510
- out.anchorLock = (_a = s.anchorLock) !== null && _a !== void 0 ? _a : true;
589
+ out.anchorLock = attr(s.anchorLock, out.anchorLock);
511
590
  return out;
512
591
  };
513
592
  const mergeTblWidth = (source, destination) => {
@@ -1,7 +1,7 @@
1
1
  export interface Logger {
2
2
  warn(message: string): void;
3
3
  }
4
- /** The logger property resolution writes to. */
4
+ /** The logger property resolution and the Markdown export write to. */
5
5
  export declare const log: Logger;
6
6
  /** Replaces the sink; pass nothing to go back to `console.warn`. */
7
7
  export declare function setLogger(logger?: Logger): void;
@@ -1,7 +1,7 @@
1
- // The one place property resolution writes a diagnostic. docx4j logs through SLF4J; this
2
- // package has no logging framework, so a missing style or a style cycle goes to `console.warn`
3
- // behind a settable sink (an add-in that must stay silent, or a test that wants to assert what
4
- // was logged, replaces it).
1
+ // The one place property resolution writes a diagnostic, and the Markdown export a refused link
2
+ // target (CR-012 section 21). docx4j logs through SLF4J; this package has no logging framework, so
3
+ // a missing style, a style cycle or a refused link goes to `console.warn` behind a settable sink
4
+ // (an add-in that must stay silent, or a test that wants to assert what was logged, replaces it).
5
5
  //
6
6
  // Resolution logs a missing style *once per id* (a `w:pStyle` naming a deleted style is common
7
7
  // in real documents, and docx4j used to log one ERROR per paragraph); the resolver keeps that
@@ -13,7 +13,7 @@ const consoleLogger = {
13
13
  },
14
14
  };
15
15
  let sink = consoleLogger;
16
- /** The logger property resolution writes to. */
16
+ /** The logger property resolution and the Markdown export write to. */
17
17
  export const log = {
18
18
  warn(message) {
19
19
  sink.warn(message);
@@ -40,9 +40,21 @@ export declare class CellContext {
40
40
  /**
41
41
  * Whether the table style gives this paragraph anything at all: its own `w:pPr` or `w:rPr`, or
42
42
  * a conditional format with one. Where it does not, resolving with this context gives the same
43
- * answer as resolving without one.
43
+ * answer as resolving without one - except under [MS-DOCX]'s size exception, for which see
44
+ * {@link styleFormatsText}.
44
45
  */
45
46
  readonly formatsText: boolean;
47
+ /**
48
+ * Whether the table style formats text anywhere: its own `w:pPr` or `w:rPr`, or a conditional
49
+ * format with one, whether or not that condition holds for this paragraph. Below compatibility
50
+ * mode 15 this, not what applies here, is what brings [MS-DOCX]'s size exception into play:
51
+ * measured on docx4j's table-style-size-trigger probes (its corpus document 1912), a table
52
+ * style with only a `w:pPr`, only an `w:rPr` colour, or only a `firstRow` format sets every row
53
+ * of its table at the document defaults' size where Normal states 12pt - the `firstRow`
54
+ * format's second row included - while a style with none of these leaves Normal's 12pt.
55
+ * docx4j `styleFormatsText()` (900b6a212, 17.3.2).
56
+ */
57
+ readonly styleFormatsText: boolean;
46
58
  /** What the table level's composition depends on. A value, for keying caches. */
47
59
  readonly key: CellContextKey;
48
60
  constructor(
@@ -138,7 +150,9 @@ export declare class TableContextTracker {
138
150
  /**
139
151
  * Walks everything under `root` (an object, an element pair or an array of them), in document
140
152
  * order, calling `visit` for each paragraph with its context. It descends through every
141
- * member but the `PARENT` pointers, so a text box's paragraphs are reached, in no table.
153
+ * member but the `PARENT` pointers, so a text box's paragraphs are reached, in no table. A kept
154
+ * `mc:AlternateContent` is descended through its selected branch alone (`selectedBranchOf`,
155
+ * docx4j's `McMode.READ`), so a text box held in both branches is visited once (CR-010 phase 3).
142
156
  */
143
157
  walk(root: unknown, visit: (p: wml.P, cellContext: CellContext | undefined) => void): void;
144
158
  }
@@ -1,5 +1,5 @@
1
1
  import { isEmptyPPr, isEmptyRPr } from './styleUtil.mjs';
2
- import { rowsOf, cellsOf } from '../content/tree.mjs';
2
+ import { rowsOf, cellsOf, selectedBranchOf, ALTERNATE_CONTENT } from '../content/tree.mjs';
3
3
  import { PRECEDENCE, DEFAULT_LOOK, lookOf, rowBandSize, colBandSize, rowCnf, resolve, rowConditions, applicable, formatsText, key as conditionsKey, } from './tableStyleConditions.mjs';
4
4
  /** The conditions as bits over {@link PRECEDENCE}: an exact value for keying caches. */
5
5
  function maskOf(conditions) {
@@ -43,6 +43,7 @@ export class CellContext {
43
43
  tableStyleId,
44
44
  /** That style's `w:basedOn` chain merged (`getTableStyleChain`): shared, read it only. */
45
45
  tableStyle, conditions) {
46
+ var _a;
46
47
  this.tableStyleId = tableStyleId;
47
48
  this.tableStyle = tableStyle;
48
49
  const c = new Set(conditions !== null && conditions !== void 0 ? conditions : []);
@@ -56,7 +57,10 @@ export class CellContext {
56
57
  }
57
58
  }
58
59
  this.textConditions = text;
59
- this.formatsText = text.length > 0 || !isEmptyPPr(tableStyle.pPr) || !isEmptyRPr(tableStyle.rPr);
60
+ const own = !isEmptyPPr(tableStyle.pPr) || !isEmptyRPr(tableStyle.rPr);
61
+ this.formatsText = text.length > 0 || own;
62
+ this.styleFormatsText = own
63
+ || ((_a = tableStyle.tblStylePr) !== null && _a !== void 0 ? _a : []).some((pr) => pr !== undefined && pr !== null && formatsText(pr));
60
64
  this.key = new CellContextKey(tableStyleId, named);
61
65
  }
62
66
  toString() {
@@ -106,14 +110,16 @@ export class TableContext {
106
110
  this.look = DEFAULT_LOOK;
107
111
  this.rowBandSize = (tblPr === null || tblPr === void 0 ? void 0 : tblPr.tblStyleRowBandSize) !== undefined ? rowBandSize(tblPr) : rowBandSize(stylePr);
108
112
  this.colBandSize = (tblPr === null || tblPr === void 0 ? void 0 : tblPr.tblStyleColBandSize) !== undefined ? colBandSize(tblPr) : colBandSize(stylePr);
109
- const rows = rowsOf(tbl);
113
+ // the rows and cells Word reads: a kept row- or cell-level mc:AlternateContent's selected branch (CR-013
114
+ // phase 2), so that its rows count for the first row, the last and the bands
115
+ const rows = rowsOf(tbl, 'read');
110
116
  let cols = 0;
111
117
  rows.forEach((located, r) => {
112
118
  var _a, _b;
113
119
  const tr = located.element.value;
114
120
  this.rowIndex.set(tr, r);
115
121
  let c = gridOf(tr, 'gridBefore');
116
- for (const cell of cellsOf(tr)) {
122
+ for (const cell of cellsOf(tr, 'read')) {
117
123
  const tc = cell.element.value;
118
124
  const val = (_b = (_a = tc.tcPr) === null || _a === void 0 ? void 0 : _a.gridSpan) === null || _b === void 0 ? void 0 : _b.val;
119
125
  const span = typeof val === 'number' ? Math.max(1, Math.trunc(val)) : 1;
@@ -248,7 +254,9 @@ export class TableContextTracker {
248
254
  /**
249
255
  * Walks everything under `root` (an object, an element pair or an array of them), in document
250
256
  * order, calling `visit` for each paragraph with its context. It descends through every
251
- * member but the `PARENT` pointers, so a text box's paragraphs are reached, in no table.
257
+ * member but the `PARENT` pointers, so a text box's paragraphs are reached, in no table. A kept
258
+ * `mc:AlternateContent` is descended through its selected branch alone (`selectedBranchOf`,
259
+ * docx4j's `McMode.READ`), so a text box held in both branches is visited once (CR-010 phase 3).
252
260
  */
253
261
  walk(root, visit) {
254
262
  const seen = new Set();
@@ -264,6 +272,10 @@ export class TableContextTracker {
264
272
  return;
265
273
  seen.add(o);
266
274
  const typeName = o.TYPE_NAME;
275
+ if (typeName === ALTERNATE_CONTENT) {
276
+ descend(selectedBranchOf(o), depth + 1);
277
+ return;
278
+ }
267
279
  if (typeName === P)
268
280
  visit(o, this.cellContext(o));
269
281
  const leave = this.enter(o);