@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,42 +1,97 @@
1
- import { UNDERSTOOD_NAMESPACES } from './understood.mjs';
1
+ import { READ_UNDERSTOOD_NAMESPACES } from './understood.mjs';
2
2
  export const MCE_NS = 'http://schemas.openxmlformats.org/markup-compatibility/2006';
3
- /** The default preprocessor, over the object model's namespaces. */
4
- export function mcePreprocess(doc, _part) {
5
- resolveAlternateContent(doc, UNDERSTOOD_NAMESPACES);
3
+ /**
4
+ * The hosts whose mc:AlternateContent is kept whole on load, as `{namespace}localName`
5
+ * (CR-010 phase 1): a chart's `c:chartSpace` and SpreadsheetML's `workbook`.
6
+ */
7
+ export const KEPT_HOSTS = new Set([
8
+ '{http://schemas.openxmlformats.org/drawingml/2006/chart}chartSpace',
9
+ '{http://schemas.openxmlformats.org/spreadsheetml/2006/main}workbook',
10
+ ]);
11
+ /**
12
+ * Load's preprocessor since CR-010 phase 4: every mc:AlternateContent is kept, and the part's
13
+ * warnings are what resolving would report. Returns them.
14
+ */
15
+ export function mceKeep(doc, part) {
16
+ return preprocessAlternateContent(doc, { resolve: false, partName: part === null || part === void 0 ? void 0 : part.partName.name }).warnings;
6
17
  }
7
- /** A preprocessor over a namespace set of your own. */
18
+ /** The resolving preprocessor (`mcePreprocess: true`), over `READ_UNDERSTOOD_NAMESPACES`. Returns the part's warnings. */
19
+ export function mcePreprocess(doc, part) {
20
+ return preprocessAlternateContent(doc, { partName: part === null || part === void 0 ? void 0 : part.partName.name }).warnings;
21
+ }
22
+ /** A preprocessor over a namespace set (or kept hosts) of your own. */
8
23
  export function createMcePreprocessor(options) {
9
- var _a;
10
- const understood = (_a = options.understood) !== null && _a !== void 0 ? _a : UNDERSTOOD_NAMESPACES;
11
- return (doc) => resolveAlternateContent(doc, understood);
24
+ return (doc, part) => preprocessAlternateContent(doc, { ...options, partName: part === null || part === void 0 ? void 0 : part.partName.name }).warnings;
25
+ }
26
+ /**
27
+ * Resolves every mc:AlternateContent under a node, outermost first, but those `KEPT_HOSTS` and the
28
+ * nothing-selectable rule keep (see the file comment). Returns the number resolved.
29
+ */
30
+ export function resolveAlternateContent(root, understood = READ_UNDERSTOOD_NAMESPACES) {
31
+ return preprocessAlternateContent(root, { understood }).resolved;
12
32
  }
13
33
  /**
14
- * Resolves every mc:AlternateContent under a node, innermost first (a chosen branch may contain
15
- * another). Returns the number resolved.
34
+ * The pass itself: what it resolved, kept and reported. With `resolve: false` it visits the elements
35
+ * resolving would, outermost first and into the branch the rule selects, reports the same warnings,
36
+ * and leaves the DOM as it was.
16
37
  */
17
- export function resolveAlternateContent(root, understood = UNDERSTOOD_NAMESPACES) {
18
- let count = 0;
38
+ export function preprocessAlternateContent(root, options = {}) {
39
+ var _a, _b, _c;
40
+ const understood = (_a = options.understood) !== null && _a !== void 0 ? _a : READ_UNDERSTOOD_NAMESPACES;
41
+ const keptHosts = (_b = options.keptHosts) !== null && _b !== void 0 ? _b : KEPT_HOSTS;
42
+ const resolve = (_c = options.resolve) !== null && _c !== void 0 ? _c : true;
43
+ const result = { resolved: 0, kept: 0, warnings: [] };
19
44
  const visit = (node) => {
20
- // Snapshot: replacing a child mutates the list.
21
- const children = [];
45
+ var _a;
46
+ const hostKept = node.nodeType === 1 && keptHosts.has(`{${(_a = node.namespaceURI) !== null && _a !== void 0 ? _a : ''}}${node.localName}`);
47
+ // A work list, not the live child list: resolving replaces a child with the branch's content,
48
+ // which is visited in its turn (it may hold, or be, another mc:AlternateContent).
49
+ const queue = [];
22
50
  for (let c = node.firstChild; c; c = c.nextSibling)
23
- children.push(c);
24
- for (const child of children) {
25
- if (child.nodeType !== 1)
51
+ queue.push(c);
52
+ for (let i = 0; i < queue.length; i++) {
53
+ if (queue[i].nodeType !== 1)
54
+ continue;
55
+ const el = queue[i];
56
+ if (!isAlternateContent(el)) {
57
+ visit(el);
58
+ continue;
59
+ }
60
+ const { choices, fallback } = branchesOf(el);
61
+ const chosen = choices.find((c) => choiceUnderstood(c, understood));
62
+ const branch = chosen !== null && chosen !== void 0 ? chosen : fallback;
63
+ if (hostKept || (branch === undefined && choices.length > 0)) {
64
+ result.kept++;
65
+ continue;
66
+ }
67
+ const warning = branchesDiffer(el, choices, fallback, branch, understood, options.partName);
68
+ if (warning)
69
+ result.warnings.push(warning);
70
+ if (!resolve) {
71
+ result.kept++;
72
+ if (branch)
73
+ visit(branch);
26
74
  continue;
27
- visit(child);
28
- const el = child;
29
- if (el.namespaceURI === MCE_NS && el.localName === 'AlternateContent') {
30
- replaceAlternateContent(el, understood);
31
- count++;
32
75
  }
76
+ const moved = [];
77
+ if (branch)
78
+ for (let c = branch.firstChild; c; c = c.nextSibling)
79
+ moved.push(c);
80
+ for (const n of moved)
81
+ node.insertBefore(n, el);
82
+ node.removeChild(el);
83
+ queue.splice(i + 1, 0, ...moved);
84
+ result.resolved++;
33
85
  }
34
86
  };
35
87
  visit(root);
36
- return count;
88
+ return result;
37
89
  }
38
- function replaceAlternateContent(ac, understood) {
39
- let chosen;
90
+ function isAlternateContent(el) {
91
+ return el.namespaceURI === MCE_NS && el.localName === 'AlternateContent';
92
+ }
93
+ function branchesOf(ac) {
94
+ const choices = [];
40
95
  let fallback;
41
96
  for (let c = ac.firstChild; c; c = c.nextSibling) {
42
97
  if (c.nodeType !== 1)
@@ -44,21 +99,12 @@ function replaceAlternateContent(ac, understood) {
44
99
  const el = c;
45
100
  if (el.namespaceURI !== MCE_NS)
46
101
  continue;
47
- if (el.localName === 'Choice' && !chosen && choiceUnderstood(el, understood))
48
- chosen = el;
102
+ if (el.localName === 'Choice')
103
+ choices.push(el);
49
104
  else if (el.localName === 'Fallback' && !fallback)
50
105
  fallback = el;
51
106
  }
52
- const branch = chosen !== null && chosen !== void 0 ? chosen : fallback;
53
- const parent = ac.parentNode;
54
- if (branch) {
55
- const moved = [];
56
- for (let c = branch.firstChild; c; c = c.nextSibling)
57
- moved.push(c);
58
- for (const n of moved)
59
- parent.insertBefore(n, ac);
60
- }
61
- parent.removeChild(ac);
107
+ return { choices, fallback };
62
108
  }
63
109
  function choiceUnderstood(choice, understood) {
64
110
  var _a;
@@ -72,3 +118,64 @@ function choiceUnderstood(choice, understood) {
72
118
  }
73
119
  return true;
74
120
  }
121
+ /** The text elements a branch's text is read from: WordprocessingML's, DrawingML's and OMML's `t`. */
122
+ const TEXT_NAMESPACES = new Set([
123
+ 'http://schemas.openxmlformats.org/wordprocessingml/2006/main',
124
+ 'http://schemas.openxmlformats.org/drawingml/2006/main',
125
+ 'http://schemas.openxmlformats.org/officeDocument/2006/math',
126
+ ]);
127
+ /**
128
+ * The text a branch holds: its w:t, a:t and m:t, whitespace collapsed. A nested
129
+ * mc:AlternateContent contributes the branch the same rule selects, or its first Choice when
130
+ * nothing is selectable (the reading rule).
131
+ */
132
+ function textOfBranch(node, understood) {
133
+ const out = [];
134
+ const walk = (n) => {
135
+ var _a, _b, _c, _d;
136
+ for (let c = n.firstChild; c; c = c.nextSibling) {
137
+ if (c.nodeType !== 1)
138
+ continue;
139
+ const el = c;
140
+ if (isAlternateContent(el)) {
141
+ const { choices, fallback } = branchesOf(el);
142
+ const branch = (_b = (_a = choices.find((x) => choiceUnderstood(x, understood))) !== null && _a !== void 0 ? _a : fallback) !== null && _b !== void 0 ? _b : choices[0];
143
+ if (branch)
144
+ walk(branch);
145
+ }
146
+ else if (el.localName === 't' && TEXT_NAMESPACES.has((_c = el.namespaceURI) !== null && _c !== void 0 ? _c : ''))
147
+ out.push((_d = el.textContent) !== null && _d !== void 0 ? _d : '');
148
+ else
149
+ walk(el);
150
+ }
151
+ };
152
+ walk(node);
153
+ return out.join('').replace(/\s+/g, ' ').trim();
154
+ }
155
+ function branchName(branch) {
156
+ var _a;
157
+ return branch.localName === 'Choice' ? `Choice(${((_a = branch.getAttribute('Requires')) !== null && _a !== void 0 ? _a : '').trim()})` : 'Fallback';
158
+ }
159
+ function branchesDiffer(ac, choices, fallback, selected, understood, partName) {
160
+ const all = fallback ? [...choices, fallback] : choices;
161
+ if (all.length < 2 || selected === undefined)
162
+ return undefined;
163
+ const branches = all.map((b) => ({ branch: branchName(b), text: textOfBranch(b, understood) }));
164
+ const taken = branches[all.indexOf(selected)];
165
+ if (branches.every((b) => b.text === taken.text))
166
+ return undefined;
167
+ const located = ac;
168
+ const where = typeof located.lineNumber === 'number' ? ` (line ${located.lineNumber}, column ${located.columnNumber})` : '';
169
+ const others = branches.filter((b) => b !== taken).map((b) => `${b.branch} ${JSON.stringify(abbreviate(b.text))}`).join(', ');
170
+ return {
171
+ code: 'mce.branches_differ',
172
+ partName,
173
+ ...(typeof located.lineNumber === 'number' ? { line: located.lineNumber, column: located.columnNumber } : {}),
174
+ selected: taken.branch,
175
+ branches,
176
+ message: `${partName !== null && partName !== void 0 ? partName : 'a part'}${where}: mc:AlternateContent's branches say different things; ${taken.branch} was read (${JSON.stringify(abbreviate(taken.text))}), not ${others}`,
177
+ };
178
+ }
179
+ function abbreviate(text) {
180
+ return text.length > 60 ? `${text.slice(0, 57)}...` : text;
181
+ }
@@ -1 +1,35 @@
1
1
  export declare const UNDERSTOOD_NAMESPACES: ReadonlySet<string>;
2
+ /**
3
+ * The conventional prefixes of `UNDERSTOOD_NAMESPACES` (`NAMESPACE_PREFIXES`), the object model's namespaces
4
+ * expressed as prefixes (CR-010 section 11.5): the unmarshalled model does not keep the declarations in
5
+ * force at the element, so the objects package's `mcBranchOf` compares prefixes, and its default set,
6
+ * every prefix `NAMESPACE_PREFIXES` knows, is wider than what load understands. The readers match
7
+ * against `READ_UNDERSTOOD_PREFIXES`, this and four more. An understood namespace with no conventional
8
+ * prefix has no entry.
9
+ */
10
+ export declare const UNDERSTOOD_PREFIXES: ReadonlySet<string>;
11
+ /**
12
+ * The namespaces a reader of a kept mc:AlternateContent counts as understood beyond `UNDERSTOOD_NAMESPACES`
13
+ * (CR-010 section 15): Word 365 takes a Choice requiring any of them (measured 2026-10-20), and docx4j's
14
+ * published understood list (`understood-namespaces.txt`) has all four, among the 11 its JAXB contexts
15
+ * bind and no generated module here does. The name is CR-010's, when only the readers counted them;
16
+ * since CR-013 (D3) resolving does too (`READ_UNDERSTOOD_NAMESPACES`). Resolving turns the Choice it takes
17
+ * into typed content, which no module types here, but what Word writes in these namespaces survives a
18
+ * re-marshal: in every file seen it is attributes only (`w16du:dateUtc`, `w16sdtdh:storeItemChecksum`,
19
+ * `x14ac:dyDescent` and `x14ac:knownFonts`; `w16sdtfl` is only declared), measured 2026-10-21.
20
+ */
21
+ export declare const READ_ONLY_UNDERSTOOD_NAMESPACES: ReadonlySet<string>;
22
+ /**
23
+ * What a reader of a kept mc:AlternateContent matches `mc:Choice/@Requires` against (`selectedBranchOf`,
24
+ * docx4j's `McMode.READ`): `UNDERSTOOD_PREFIXES` and the conventional prefixes of
25
+ * `READ_ONLY_UNDERSTOOD_NAMESPACES`. A Choice requiring only these is taken by the gate alone, as REQ-302
26
+ * of the text extraction specification reads, whatever its content (CR-010 section 15).
27
+ */
28
+ export declare const READ_UNDERSTOOD_PREFIXES: ReadonlySet<string>;
29
+ /**
30
+ * What load selects by, as namespaces: `UNDERSTOOD_NAMESPACES` and `READ_ONLY_UNDERSTOOD_NAMESPACES`, the
31
+ * readers' set (`READ_UNDERSTOOD_PREFIXES`) by URI. Resolving (`mcePreprocess: true`) takes the Choice it
32
+ * names, and the default load's `mce.branches_differ` reports it as the selected branch, so a resolved load
33
+ * takes the branch the readers of a kept load take, as Word 365 does (CR-013 D3).
34
+ */
35
+ export declare const READ_UNDERSTOOD_NAMESPACES: ReadonlySet<string>;
@@ -4,10 +4,12 @@
4
4
  //
5
5
  // It is the defaultElementNamespaceURI of every generated module of @docx4j/generated-objects-ts
6
6
  // (0.3.0), which `mce.test.mjs` asserts so that the next regeneration announces an addition, plus
7
- // two groups of hand-kept entries, each marked below: namespaces no module *defaults* to but which
8
- // the model binds anyway (attributes, or elements a module of another namespace declares), and the
7
+ // three groups of hand-kept entries, each marked below: namespaces no module *defaults* to but which
8
+ // the model binds anyway (attributes, or elements a module of another namespace declares), the
9
9
  // slicer namespaces of CR-004 phase B, whose content the model does not bind at all but carries
10
- // through as DOM.
10
+ // through as DOM, and the chartex namespaces Office gates a chart's frame with, which nothing in the
11
+ // Choice uses (CR-009 section 8).
12
+ import { NAMESPACE_PREFIXES } from '@docx4j/generated-objects-ts';
11
13
  export const UNDERSTOOD_NAMESPACES = new Set([
12
14
  'http://schemas.openxmlformats.org/wordprocessingml/2006/main',
13
15
  'http://schemas.openxmlformats.org/package/2006/relationships',
@@ -124,4 +126,54 @@ export const UNDERSTOOD_NAMESPACES = new Set([
124
126
  'http://schemas.microsoft.com/office/drawing/2010/slicer',
125
127
  'http://schemas.microsoft.com/office/drawing/2012/slicer',
126
128
  'http://schemas.microsoft.com/office/drawing/2012/timeslicer',
129
+ // Office's chartex charts (CR-009 section 8). Word, Excel and PowerPoint gate a chartex frame with
130
+ // a later chartex namespace than the chart's own: Requires="cx1" (2015/9/8) for a waterfall or a
131
+ // histogram, "cx2" (2015/10/21) for a funnel. Nothing in the Choice is in it: the frame's
132
+ // a:graphicData holds a cx:chart of the 2014 namespace, which the model binds. Nothing binds these
133
+ // two (docx4j has no schema for them), but the Choice round-trips whole, and the Fallback is only a
134
+ // picture of the chart, or in Excel a box saying the chart is not available, so leaving it would
135
+ // lose the chart on any save that re-marshals the part. Office's other chartex namespaces are not
136
+ // here: no file seen gates a Choice with one.
137
+ 'http://schemas.microsoft.com/office/drawing/2015/9/8/chartex',
138
+ 'http://schemas.microsoft.com/office/drawing/2015/10/21/chartex',
127
139
  ]);
140
+ const prefixesOf = (namespaces) => [...namespaces].map((uri) => NAMESPACE_PREFIXES[uri]).filter((prefix) => prefix !== undefined && prefix !== '');
141
+ /**
142
+ * The conventional prefixes of `UNDERSTOOD_NAMESPACES` (`NAMESPACE_PREFIXES`), the object model's namespaces
143
+ * expressed as prefixes (CR-010 section 11.5): the unmarshalled model does not keep the declarations in
144
+ * force at the element, so the objects package's `mcBranchOf` compares prefixes, and its default set,
145
+ * every prefix `NAMESPACE_PREFIXES` knows, is wider than what load understands. The readers match
146
+ * against `READ_UNDERSTOOD_PREFIXES`, this and four more. An understood namespace with no conventional
147
+ * prefix has no entry.
148
+ */
149
+ export const UNDERSTOOD_PREFIXES = new Set(prefixesOf(UNDERSTOOD_NAMESPACES));
150
+ /**
151
+ * The namespaces a reader of a kept mc:AlternateContent counts as understood beyond `UNDERSTOOD_NAMESPACES`
152
+ * (CR-010 section 15): Word 365 takes a Choice requiring any of them (measured 2026-10-20), and docx4j's
153
+ * published understood list (`understood-namespaces.txt`) has all four, among the 11 its JAXB contexts
154
+ * bind and no generated module here does. The name is CR-010's, when only the readers counted them;
155
+ * since CR-013 (D3) resolving does too (`READ_UNDERSTOOD_NAMESPACES`). Resolving turns the Choice it takes
156
+ * into typed content, which no module types here, but what Word writes in these namespaces survives a
157
+ * re-marshal: in every file seen it is attributes only (`w16du:dateUtc`, `w16sdtdh:storeItemChecksum`,
158
+ * `x14ac:dyDescent` and `x14ac:knownFonts`; `w16sdtfl` is only declared), measured 2026-10-21.
159
+ */
160
+ export const READ_ONLY_UNDERSTOOD_NAMESPACES = new Set([
161
+ 'http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash', // w16sdtdh
162
+ 'http://schemas.microsoft.com/office/word/2024/wordml/sdtformatlock', // w16sdtfl
163
+ 'http://schemas.microsoft.com/office/word/2023/wordml/word16du', // w16du
164
+ 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac', // x14ac
165
+ ]);
166
+ /**
167
+ * What a reader of a kept mc:AlternateContent matches `mc:Choice/@Requires` against (`selectedBranchOf`,
168
+ * docx4j's `McMode.READ`): `UNDERSTOOD_PREFIXES` and the conventional prefixes of
169
+ * `READ_ONLY_UNDERSTOOD_NAMESPACES`. A Choice requiring only these is taken by the gate alone, as REQ-302
170
+ * of the text extraction specification reads, whatever its content (CR-010 section 15).
171
+ */
172
+ export const READ_UNDERSTOOD_PREFIXES = new Set([...UNDERSTOOD_PREFIXES, ...prefixesOf(READ_ONLY_UNDERSTOOD_NAMESPACES)]);
173
+ /**
174
+ * What load selects by, as namespaces: `UNDERSTOOD_NAMESPACES` and `READ_ONLY_UNDERSTOOD_NAMESPACES`, the
175
+ * readers' set (`READ_UNDERSTOOD_PREFIXES`) by URI. Resolving (`mcePreprocess: true`) takes the Choice it
176
+ * names, and the default load's `mce.branches_differ` reports it as the selected branch, so a resolved load
177
+ * takes the branch the readers of a kept load take, as Word 365 does (CR-013 D3).
178
+ */
179
+ export const READ_UNDERSTOOD_NAMESPACES = new Set([...UNDERSTOOD_NAMESPACES, ...READ_ONLY_UNDERSTOOD_NAMESPACES]);
@@ -4,11 +4,13 @@ import { ContentTypeManager } from '../opc/ContentTypeManager.mjs';
4
4
  import { type PartStore, type PartSink } from '../opc/PartStore.mjs';
5
5
  import { type FlatOpcSinkOptions } from '../opc/FlatOpcPartStore.mjs';
6
6
  import { type LoadOptions } from '../opc/Load.mjs';
7
+ import { type SaveReport } from '../opc/Save.mjs';
7
8
  import { Part, type RelationshipSource } from '../parts/Part.mjs';
8
9
  import { Parts } from '../parts/Parts.mjs';
9
10
  import { RelationshipsPart, type AddPartBehaviour } from '../parts/RelationshipsPart.mjs';
10
11
  import type { CustomXmlDataStoragePart } from '../parts/DefaultXmlPart.mjs';
11
12
  import { DocPropsCorePart, DocPropsExtendedPart, DocPropsCustomPart } from '../parts/docProps/index.mjs';
13
+ import { type PartWarning } from '../opc/mce/preprocessor.mjs';
12
14
  /** Anything `OpcPackage.load` accepts: zip bytes, a flat OPC string, or a container. */
13
15
  export type PackageSource = Uint8Array | ArrayBuffer | string | PartStore;
14
16
  /**
@@ -30,6 +32,18 @@ export declare class OpcPackage implements RelationshipSource {
30
32
  docPropsCorePart: DocPropsCorePart | undefined;
31
33
  docPropsExtendedPart: DocPropsExtendedPart | undefined;
32
34
  docPropsCustomPart: DocPropsCustomPart | undefined;
35
+ /**
36
+ * Whether a save writes run properties in their normal form (CR-015 D2; docx4j CR-061's
37
+ * `setNormaliseOnSave`): a colour Word accepts as upper-case `RRGGBB`, one it rejects left out (a text or
38
+ * underline colour) or `auto` (a fill's, a border's), a `w:highlight`, `w:vertAlign` or `w:em` Word repairs away
39
+ * left out; a revision's former properties too. Only what is written changes: the tree keeps what it read, and a
40
+ * part nobody unmarshalled is still copied byte for byte. Undefined defers to the objects package's process-wide
41
+ * `setNormaliseOnSave` (on unless set off); a package's own setting wins over it. False writes values as read.
42
+ * On/off values and `w:u`'s are settled when the part is read, so they are written the same either way.
43
+ */
44
+ normaliseOnSave: boolean | undefined;
45
+ /** What the last save did beyond writing the package: each value it normalised (CR-015 D8). Undefined until one. */
46
+ lastSave: SaveReport | undefined;
33
47
  constructor();
34
48
  get package(): OpcPackage;
35
49
  /**
@@ -44,6 +58,12 @@ export declare class OpcPackage implements RelationshipSource {
44
58
  setPartShortcut(part: Part, relationshipType: string): boolean;
45
59
  /** The main part: the target of the officeDocument relationship. */
46
60
  getMainPart(): Part | undefined;
61
+ /**
62
+ * The warnings of every part parsed so far (each XML part's `warnings`, CR-010 phase 1). A part
63
+ * is parsed when something reads it, so a reader that wants a whole package's warnings reads its
64
+ * parts first; `unmarshalAll()` does, at the cost of re-marshalling every part on save.
65
+ */
66
+ get warnings(): PartWarning[];
47
67
  /** Unmarshals every XML part, so that `contents` is available synchronously everywhere. */
48
68
  unmarshalAll(): Promise<void>;
49
69
  /** Adds empty core properties if absent (docx4j addDocPropsCorePart). */
@@ -11,7 +11,7 @@ import { Parts } from '../parts/Parts.mjs';
11
11
  import { XmlPart } from '../parts/XmlPart.mjs';
12
12
  import { RelationshipsPart } from '../parts/RelationshipsPart.mjs';
13
13
  import { DocPropsCorePart, DocPropsExtendedPart } from '../parts/docProps/index.mjs';
14
- import { mcePreprocess } from '../opc/mce/preprocessor.mjs';
14
+ import { mceKeep, mcePreprocess } from '../opc/mce/preprocessor.mjs';
15
15
  import { createPackageForContentType, registerGenericPackageClass } from './registry.mjs';
16
16
  /**
17
17
  * An Open Packaging Conventions package (docx4j org.docx4j.openpackaging.packages.OpcPackage):
@@ -41,8 +41,8 @@ export class OpcPackage {
41
41
  static async load(source, options = {}) {
42
42
  const store = toStore(source);
43
43
  const opts = { ...options };
44
- if (opts.preprocessor === undefined && opts.mcePreprocess !== false)
45
- opts.preprocessor = mcePreprocess;
44
+ if (opts.preprocessor === undefined)
45
+ opts.preprocessor = opts.mcePreprocess === true ? mcePreprocess : mceKeep;
46
46
  const pkg = await loadPackage(store, createPackageForContentType, opts);
47
47
  pkg.loadOptions = opts;
48
48
  return pkg;
@@ -79,6 +79,18 @@ export class OpcPackage {
79
79
  const rel = (_a = this.relationshipsPart.getRelationshipByType(Namespaces.DOCUMENT)) !== null && _a !== void 0 ? _a : this.relationshipsPart.getRelationshipByType(Namespaces.DOCUMENT_STRICT);
80
80
  return rel ? this.relationshipsPart.getPart(rel) : undefined;
81
81
  }
82
+ /**
83
+ * The warnings of every part parsed so far (each XML part's `warnings`, CR-010 phase 1). A part
84
+ * is parsed when something reads it, so a reader that wants a whole package's warnings reads its
85
+ * parts first; `unmarshalAll()` does, at the cost of re-marshalling every part on save.
86
+ */
87
+ get warnings() {
88
+ const out = [];
89
+ for (const part of this.parts)
90
+ if (part instanceof XmlPart)
91
+ out.push(...part.warnings);
92
+ return out;
93
+ }
82
94
  /** Unmarshals every XML part, so that `contents` is available synchronously everywhere. */
83
95
  async unmarshalAll() {
84
96
  for (const part of this.parts)
@@ -123,6 +135,7 @@ export class OpcPackage {
123
135
  if (copy.constructor !== this.constructor) {
124
136
  throw new Docx4JException(`Cloning ${this.constructor.name} produced ${copy.constructor.name}`);
125
137
  }
138
+ copy.normaliseOnSave = this.normaliseOnSave;
126
139
  this.copyPackageSettingsTo(copy);
127
140
  return copy;
128
141
  }
@@ -3,7 +3,8 @@ import type { LoadOptions } from '../opc/Load.mjs';
3
3
  import type { Part } from '../parts/Part.mjs';
4
4
  import { MainDocumentPart, StyleDefinitionsPart, type NumberingDefinitionsPart } from '../parts/wml/index.mjs';
5
5
  import { type FontSettings, type DefaultThemeValue } from '../model/fonts/defaultTheme.mjs';
6
- import type { Body, Address, Outline, OutlineParagraph, OutlineTable } from '../model/content/Body.mjs';
6
+ import { Body, type Address, type Outline, type OutlineParagraph, type OutlineTable } from '../model/content/Body.mjs';
7
+ import { type TrackedChangeSelection } from '../model/content/trackedChangeFilter.mjs';
7
8
  import type { Paragraph } from '../model/content/Paragraph.mjs';
8
9
  import type { Author } from '../model/content/comments.mjs';
9
10
  import { CustomXmlPartCollection } from '../model/customxml/CustomXmlPartCollection.mjs';
@@ -11,13 +12,18 @@ import { type XPathEngine } from '../model/customxml/xpath.mjs';
11
12
  import { ChangeTracker, type ChangeTrackingMode, type TrackingHost, type TrackingScope } from '../model/content/tracking.mjs';
12
13
  import { NumberingFacade } from '../model/content/List.mjs';
13
14
  import { StylesFacade } from '../model/content/stylesFacade.mjs';
15
+ import { GlossaryEntries } from '../model/content/placeholders.mjs';
14
16
  import type { Bound } from '../model/content/binder.mjs';
15
17
  import { PropertyResolver } from '../model/properties/PropertyResolver.mjs';
16
18
  import type { Emulator } from '../model/listnumbering/Emulator.mjs';
17
- import type { TrackedChange } from '../model/content/TrackedChange.mjs';
19
+ import { type TrackedChange, type NoteRemovals } from '../model/content/TrackedChange.mjs';
20
+ import { type RelationshipRemovals } from '../model/content/relationships.mjs';
18
21
  import { XmlPart } from '../parts/XmlPart.mjs';
19
22
  import type { PartSink } from '../opc/PartStore.mjs';
20
23
  import '../parts/wml/comments.mjs';
24
+ import '../model/text/outline.mjs';
25
+ import type { TextContext } from '../model/text/TextContext.mjs';
26
+ import type { TextOptions, TextOptionsInit } from '../model/text/TextOptions.mjs';
21
27
  /** The outline of a document: the body's paragraphs and tables, then each header's and footer's (loaded ones only). */
22
28
  export interface DocumentOutline extends Outline {
23
29
  headers: {
@@ -87,6 +93,26 @@ export declare class WordprocessingMLPackage extends OpcPackage implements Track
87
93
  * the package is saved (check 32; `TrackedChange`). An extension.
88
94
  */
89
95
  readonly pendingCommentRemovals: Set<number>;
96
+ /**
97
+ * Footnotes and endnotes whose references went with content a tracked change took away (a rejected
98
+ * insertion, an accepted deletion, a row or cell, a move's other half): their entries go from the
99
+ * notes parts when the package is saved, each unless a reference to it still stands, as Word took
100
+ * them (CR-002 section 44; `TrackedChange`). An extension.
101
+ */
102
+ readonly pendingNoteRemovals: NoteRemovals;
103
+ /**
104
+ * Relationships, by the name of their part, that a picture removed outright referenced (tracking off,
105
+ * or a picture taken back from its author's own insertion): each goes when the package is saved if
106
+ * nothing then references it, and its part with it when nothing else targets that (CR-002 section
107
+ * 47). Settled on save, not at once, so a picture cut and pasted back keeps its image. An extension.
108
+ */
109
+ readonly pendingRelationshipRemovals: RelationshipRemovals;
110
+ /**
111
+ * The glossary's placeholder entries: read privately when a body is first read (`getBody`, `Word.run`), and those a
112
+ * placeholder written since names, which go into the glossary when the package is saved, the glossary made where the
113
+ * file has none (CR-002 section 63, D8 and D9). An extension.
114
+ */
115
+ readonly glossaryEntries: GlossaryEntries;
90
116
  /**
91
117
  * The parts `seedAnnotationIds()` has read, with what it read: `true` for a part still holding its
92
118
  * source, whose bytes cannot change, and otherwise the bytes that were set, which stay the same
@@ -197,10 +223,46 @@ export declare class WordprocessingMLPackage extends OpcPackage implements Track
197
223
  private settingsPart;
198
224
  /**
199
225
  * Office JS `document.getTrackedChanges()`: every tracked change in the main document part,
200
- * in document order (headers and footers have their own `Body`). The part must be
201
- * unmarshalled, as `body` needs it to be.
226
+ * in document order (headers and footers have their own `Body`; `getAllTrackedChanges` lists
227
+ * every story). The part must be unmarshalled, as `body` needs it to be.
202
228
  */
203
229
  getTrackedChanges(): TrackedChange[];
230
+ /**
231
+ * Every tracked change in every story, in docx4j's order (its CR-043 `TrackedChanges.in`, CR-011):
232
+ * the main document, each footnote, each endnote, each comment, then the headers and footers in the
233
+ * order the sections reference them; a text box's after the story it is in. Each story's are its
234
+ * `Body.getTrackedChanges()`, grouped as Office JS groups them, so changes never group across two
235
+ * stories. `TrackedChange.part` says which part each is in.
236
+ *
237
+ * With a filter, the changes with a piece it matches, each whole (docx4j's `in(pkg, filter)`).
238
+ *
239
+ * A story part whose source holds no revision markup is not read, so it keeps its bytes; one that
240
+ * does is unmarshalled, since the views returned must be resolvable, and so is re-marshalled on save.
241
+ * An extension: Office JS lists one body at a time.
242
+ */
243
+ getAllTrackedChanges(filter?: TrackedChangeSelection): Promise<TrackedChange[]>;
244
+ /**
245
+ * Accepts every tracked change in every story: the main document, the footnotes, the endnotes and
246
+ * the comments, the headers and footers, and the text boxes in each. Word's
247
+ * `Document.AcceptAllRevisions` did that on docx4j's CR-043 probe (Word 16.0.20326), and left no
248
+ * revision in any story; `Body.acceptAll` resolves its own story only, as Office JS's `body` does
249
+ * (CR-002 section 49). A story part with no revision markup is not read, so it keeps its bytes.
250
+ * Returns how many changes were listed, story by story. An extension, named after Word's verb.
251
+ *
252
+ * With a filter (CR-011), only the single changes it matches are accepted, as `Body.acceptAll`
253
+ * takes one, and the count is of the listed changes with a matching piece.
254
+ */
255
+ acceptAllRevisions(filter?: TrackedChangeSelection): Promise<number>;
256
+ /** Rejects every tracked change in every story, as `acceptAllRevisions` accepts them (Word's `Document.RejectAllRevisions`). */
257
+ rejectAllRevisions(filter?: TrackedChangeSelection): Promise<number>;
258
+ private resolveEveryStory;
259
+ /**
260
+ * The body of every story whose part holds revision markup, in docx4j's order (its CR-043
261
+ * `TrackedChanges.in`): the main document, each footnote, each endnote, each comment, then the
262
+ * headers and footers in section order (`inSectionOrder`). A footnote, an endnote or a comment is a
263
+ * body of its own over its content.
264
+ */
265
+ private revisedStories;
204
266
  /** The tracker every content-API mutation asks for; undefined while the mode is `Off`. */
205
267
  get changeTracker(): ChangeTracker | undefined;
206
268
  /**
@@ -261,10 +323,18 @@ export declare class WordprocessingMLPackage extends OpcPackage implements Track
261
323
  /** A clone carries the identity, the tracking date, the theme setting, the XPath engine and the styles still to ensure. */
262
324
  protected copyPackageSettingsTo(target: OpcPackage): void;
263
325
  saveTo<R>(sink: PartSink<R>): Promise<R>;
264
- /** The paragraph at an address anywhere in the document: 'body/3', 'header:rId5/0', a paraId, or a text match. */
326
+ /**
327
+ * The paragraph at an address anywhere in the document: 'body/3', 'header:rId5/0', 'footnote:2/0',
328
+ * 'endnote:1/0', 'comment:5/0', 'body/3/textbox:0/1' (a text box's paragraph, read-only: CR-012 D4 and
329
+ * D5), a paraId, or a text match. Undefined where the address names no paragraph.
330
+ */
265
331
  paragraphAt(address: Address): Promise<Paragraph | undefined>;
266
- /** Every paragraph and table with its address, style and text (CR-002 section 3.3). Unmarshals the main part, headers and footers. */
267
- outline(): Promise<DocumentOutline>;
332
+ /**
333
+ * Every paragraph and table with its address, style and text (CR-002 section 3.3), read by the text model
334
+ * under one context (CR-012 D3: `Body.outline`, whose options it takes): the main document, then each
335
+ * header and footer. Unmarshals the main part, headers and footers.
336
+ */
337
+ outline(options?: TextOptionsInit | TextOptions, context?: TextContext): Promise<DocumentOutline>;
268
338
  private bodies;
269
339
  /**
270
340
  * The XPath engine the custom XML views use (CR-002 section 3.6): `document.evaluate` in a