@docx4j/core-ts 0.5.0 → 0.7.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 (207) hide show
  1. package/NOTICE +4 -0
  2. package/README.md +92 -4
  3. package/dist/html/convert.mjs +2 -1
  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 +145 -23
  24. package/dist/model/content/Body.mjs +507 -150
  25. package/dist/model/content/Comment.d.mts +23 -5
  26. package/dist/model/content/Comment.mjs +207 -26
  27. package/dist/model/content/ContentControl.d.mts +198 -19
  28. package/dist/model/content/ContentControl.mjs +672 -99
  29. package/dist/model/content/Font.d.mts +70 -17
  30. package/dist/model/content/Font.mjs +119 -36
  31. package/dist/model/content/InlinePicture.d.mts +11 -0
  32. package/dist/model/content/InlinePicture.mjs +21 -1
  33. package/dist/model/content/List.d.mts +6 -3
  34. package/dist/model/content/List.mjs +18 -8
  35. package/dist/model/content/Paragraph.d.mts +200 -14
  36. package/dist/model/content/Paragraph.mjs +898 -82
  37. package/dist/model/content/Range.d.mts +227 -12
  38. package/dist/model/content/Range.mjs +785 -59
  39. package/dist/model/content/ResolvedView.d.mts +104 -0
  40. package/dist/model/content/ResolvedView.mjs +596 -0
  41. package/dist/model/content/Table.d.mts +29 -3
  42. package/dist/model/content/Table.mjs +135 -49
  43. package/dist/model/content/TrackedChange.d.mts +174 -15
  44. package/dist/model/content/TrackedChange.mjs +734 -170
  45. package/dist/model/content/comments.d.mts +20 -6
  46. package/dist/model/content/comments.mjs +67 -57
  47. package/dist/model/content/generalException.d.mts +18 -0
  48. package/dist/model/content/generalException.mjs +24 -0
  49. package/dist/model/content/index.d.mts +10 -3
  50. package/dist/model/content/index.mjs +10 -2
  51. package/dist/model/content/mathText.d.mts +21 -0
  52. package/dist/model/content/mathText.mjs +267 -0
  53. package/dist/model/content/officeText.d.mts +27 -0
  54. package/dist/model/content/officeText.mjs +74 -0
  55. package/dist/model/content/ooxml.mjs +12 -1
  56. package/dist/model/content/outline.d.mts +5 -0
  57. package/dist/model/content/outline.mjs +13 -0
  58. package/dist/model/content/paraIds.d.mts +5 -0
  59. package/dist/model/content/paraIds.mjs +54 -0
  60. package/dist/model/content/placeholders.d.mts +110 -0
  61. package/dist/model/content/placeholders.mjs +253 -0
  62. package/dist/model/content/search.d.mts +74 -0
  63. package/dist/model/content/search.mjs +255 -9
  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 +47 -0
  67. package/dist/model/content/story.mjs +95 -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 +102 -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 +63 -6
  79. package/dist/model/content/tracking.mjs +242 -22
  80. package/dist/model/content/tree.d.mts +172 -24
  81. package/dist/model/content/tree.mjs +328 -54
  82. package/dist/model/content/wordRange.d.mts +48 -0
  83. package/dist/model/content/wordRange.mjs +97 -0
  84. package/dist/model/customxml/CustomXmlPartCollection.d.mts +30 -1
  85. package/dist/model/customxml/CustomXmlPartCollection.mjs +81 -12
  86. package/dist/model/customxml/XmlMapping.d.mts +32 -8
  87. package/dist/model/customxml/XmlMapping.mjs +64 -10
  88. package/dist/model/customxml/bindings.d.mts +33 -4
  89. package/dist/model/customxml/bindings.mjs +171 -45
  90. package/dist/model/customxml/index.d.mts +1 -0
  91. package/dist/model/customxml/index.mjs +1 -0
  92. package/dist/model/customxml/kinds.d.mts +8 -3
  93. package/dist/model/customxml/kinds.mjs +26 -5
  94. package/dist/model/customxml/opendope.d.mts +4 -1
  95. package/dist/model/customxml/opendope.mjs +9 -6
  96. package/dist/model/customxml/picturePlaceholder.d.mts +17 -0
  97. package/dist/model/customxml/picturePlaceholder.mjs +32 -0
  98. package/dist/model/customxml/pictures.d.mts +4 -3
  99. package/dist/model/customxml/pictures.mjs +22 -8
  100. package/dist/model/customxml/storeItems.d.mts +57 -0
  101. package/dist/model/customxml/storeItems.mjs +122 -0
  102. package/dist/model/customxml/xhtml.mjs +23 -22
  103. package/dist/model/dateZone.d.mts +25 -0
  104. package/dist/model/dateZone.mjs +57 -0
  105. package/dist/model/index.d.mts +3 -0
  106. package/dist/model/index.mjs +5 -0
  107. package/dist/model/listnumbering/Emulator.d.mts +37 -5
  108. package/dist/model/listnumbering/Emulator.mjs +63 -9
  109. package/dist/model/properties/PropertyResolver.d.mts +74 -2
  110. package/dist/model/properties/PropertyResolver.mjs +133 -5
  111. package/dist/model/properties/catalogue.d.mts +19 -5
  112. package/dist/model/properties/catalogue.mjs +41 -15
  113. package/dist/model/properties/index.d.mts +1 -1
  114. package/dist/model/properties/log.d.mts +1 -1
  115. package/dist/model/properties/log.mjs +5 -5
  116. package/dist/model/properties/styleUtil.d.mts +3 -1
  117. package/dist/model/properties/styleUtil.mjs +20 -24
  118. package/dist/model/properties/table.mjs +4 -2
  119. package/dist/model/text/CaseMapping.d.mts +38 -0
  120. package/dist/model/text/CaseMapping.mjs +86 -0
  121. package/dist/model/text/Extractor.d.mts +349 -0
  122. package/dist/model/text/Extractor.mjs +2406 -0
  123. package/dist/model/text/LinkTargets.d.mts +45 -0
  124. package/dist/model/text/LinkTargets.mjs +170 -0
  125. package/dist/model/text/MarkdownExporter.d.mts +140 -0
  126. package/dist/model/text/MarkdownExporter.mjs +255 -0
  127. package/dist/model/text/PlainText.d.mts +29 -0
  128. package/dist/model/text/PlainText.mjs +542 -0
  129. package/dist/model/text/TextContext.d.mts +256 -0
  130. package/dist/model/text/TextContext.mjs +600 -0
  131. package/dist/model/text/TextOptions.d.mts +233 -0
  132. package/dist/model/text/TextOptions.mjs +419 -0
  133. package/dist/model/text/TextResult.d.mts +621 -0
  134. package/dist/model/text/TextResult.mjs +629 -0
  135. package/dist/model/text/Texts.d.mts +99 -0
  136. package/dist/model/text/Texts.mjs +187 -0
  137. package/dist/model/text/WmlToMarkdown.d.mts +120 -0
  138. package/dist/model/text/WmlToMarkdown.mjs +936 -0
  139. package/dist/model/text/caseMapping.generated.d.mts +7 -0
  140. package/dist/model/text/caseMapping.generated.mjs +214 -0
  141. package/dist/model/text/commonmark.d.mts +121 -0
  142. package/dist/model/text/commonmark.mjs +655 -0
  143. package/dist/model/text/index.d.mts +8 -0
  144. package/dist/model/text/index.mjs +9 -0
  145. package/dist/model/text/normalize.d.mts +8 -0
  146. package/dist/model/text/normalize.mjs +13 -0
  147. package/dist/model/text/outline.d.mts +4 -0
  148. package/dist/model/text/outline.mjs +71 -0
  149. package/dist/model/wordIntegers.d.mts +29 -0
  150. package/dist/model/wordIntegers.mjs +78 -0
  151. package/dist/office-js/document.mjs +15 -1
  152. package/dist/office-js/fragment.d.mts +7 -5
  153. package/dist/office-js/fragment.mjs +63 -14
  154. package/dist/office-js/proxy.d.mts +8 -0
  155. package/dist/office-js/proxy.mjs +29 -0
  156. package/dist/office-js/run.mjs +2 -0
  157. package/dist/office-js/supported.generated.mjs +16 -0
  158. package/dist/office-js/toApiScript.mjs +29 -12
  159. package/dist/opc/DirectoryPartStore.d.mts +6 -2
  160. package/dist/opc/DirectoryPartStore.mjs +11 -4
  161. package/dist/opc/FlatOpcPartStore.d.mts +4 -2
  162. package/dist/opc/FlatOpcPartStore.mjs +11 -8
  163. package/dist/opc/Load.d.mts +32 -0
  164. package/dist/opc/Load.mjs +115 -5
  165. package/dist/opc/PartStore.d.mts +34 -1
  166. package/dist/opc/PartStore.mjs +71 -8
  167. package/dist/opc/Save.d.mts +32 -0
  168. package/dist/opc/Save.mjs +110 -4
  169. package/dist/opc/ZipPartStore.d.mts +4 -2
  170. package/dist/opc/ZipPartStore.mjs +12 -7
  171. package/dist/opc/exceptions.d.mts +140 -0
  172. package/dist/opc/exceptions.mjs +108 -0
  173. package/dist/opc/index.d.mts +8 -5
  174. package/dist/opc/index.mjs +5 -3
  175. package/dist/opc/mce/preprocessor.d.mts +141 -5
  176. package/dist/opc/mce/preprocessor.mjs +119 -18
  177. package/dist/opc/mce/understood.d.mts +3 -11
  178. package/dist/opc/mce/understood.mjs +27 -23
  179. package/dist/opc/repair/breaks.d.mts +23 -0
  180. package/dist/opc/repair/breaks.mjs +288 -0
  181. package/dist/opc/repair/hosts.d.mts +12 -0
  182. package/dist/opc/repair/hosts.mjs +33 -0
  183. package/dist/opc/repair/mainRoot.d.mts +19 -0
  184. package/dist/opc/repair/mainRoot.mjs +168 -0
  185. package/dist/opc/repair/unknownElements.d.mts +8 -0
  186. package/dist/opc/repair/unknownElements.mjs +180 -0
  187. package/dist/opc/repair/wmlNames.generated.d.mts +2 -0
  188. package/dist/opc/repair/wmlNames.generated.mjs +80 -0
  189. package/dist/opc/skipped.d.mts +50 -0
  190. package/dist/opc/skipped.mjs +140 -0
  191. package/dist/packages/OpcPackage.d.mts +110 -4
  192. package/dist/packages/OpcPackage.mjs +123 -7
  193. package/dist/packages/WordprocessingMLPackage.d.mts +45 -8
  194. package/dist/packages/WordprocessingMLPackage.mjs +158 -21
  195. package/dist/packages/index.d.mts +1 -1
  196. package/dist/parts/DefaultXmlPart.mjs +2 -2
  197. package/dist/parts/Part.d.mts +14 -2
  198. package/dist/parts/RelationshipsPart.d.mts +15 -0
  199. package/dist/parts/RelationshipsPart.mjs +66 -1
  200. package/dist/parts/XmlPart.d.mts +63 -32
  201. package/dist/parts/XmlPart.mjs +240 -96
  202. package/dist/parts/wml/comments.mjs +30 -0
  203. package/dist/parts/wml/index.d.mts +12 -1
  204. package/dist/parts/wml/index.mjs +37 -1
  205. package/dist/xml/dom.d.mts +7 -0
  206. package/dist/xml/dom.mjs +18 -0
  207. package/package.json +2 -2
@@ -1,16 +1,20 @@
1
1
  import * as el from '@docx4j/generated-objects-ts/el/org_docx4j_wml';
2
2
  import { tr as rowOf } from '@docx4j/generated-objects-ts/builders/wml';
3
3
  import { Docx4JException } from '../../opc/exceptions.mjs';
4
- import { typeNameOf, childrenOf, linkParents, textOf, rowsOf, cellsOf } from './tree.mjs';
4
+ import { typeNameOf, childrenOf, linkParents, rowsOf, cellsOf, inBranch, assertOutsideBranch } from './tree.mjs';
5
5
  import { builtInOf, idOfBuiltIn, styleNameOf, styleIdOf } from './styles.mjs';
6
6
  import { trackInsertedBlocks } from './tracking.mjs';
7
7
  import { insertGridColumns, deleteGridColumns, gridRangeOf, textWidthTwips, widthTypeOf, layoutModeOf } from './tableColumns.mjs';
8
+ import { withinWord, WORD_STORAGE } from './wordRange.mjs';
9
+ import { assignParaIds } from './paraIds.mjs';
8
10
  /** The default table width in twips (A4 with 2.54 cm margins), as the objects package's `tbl` builder uses. */
9
11
  const DEFAULT_WIDTH = 9026;
10
12
  const TWIPS_PER_POINT = 20;
11
13
  /**
12
14
  * A subset of Office JS `Word.Table` over a `w:tbl`. Rows are read through row-level content
13
- * controls (an OpenDoPE repeat wraps its `w:tr` in a `w:sdt`), so `rows` is what Word shows.
15
+ * controls (an OpenDoPE repeat wraps its `w:tr` in a `w:sdt`), and through the selected branch of a
16
+ * kept row-level `mc:AlternateContent` (CR-013 phase 2), so `rows` is what Word shows. A table, row or
17
+ * cell in a branch is read-only (D4), and so is a write that would reach one.
14
18
  */
15
19
  export class Table {
16
20
  constructor(
@@ -32,17 +36,38 @@ export class Table {
32
36
  return this.container.indexOf(this.element);
33
37
  }
34
38
  get rowCount() {
35
- return rowsOf(this.tbl).length;
39
+ return rowsOf(this.tbl, 'read').length;
36
40
  }
37
41
  get rows() {
38
- return rowsOf(this.tbl).map((r) => new TableRow(r.element, r.container, this));
42
+ return rowsOf(this.tbl, 'read').map((r) => new TableRow(r.element, r.container, this));
43
+ }
44
+ /**
45
+ * The table's range (Office JS `Table.getRange`; CR-014 phase 1): 'Whole' from its first cell's start to its
46
+ * last cell's end, its text the table's in `body.text`'s form, every row ended `\r\n` as Word 365 gives it
47
+ * (check 52); 'Start' and 'End' collapsed at those two ends, and 'After' at the start of the paragraph after
48
+ * the table.
49
+ */
50
+ getRange(location = 'Whole') {
51
+ const paragraphs = this.rows.flatMap((row) => row.cells.flatMap((cell) => cell.paragraphs));
52
+ const first = paragraphs[0];
53
+ if (!first)
54
+ throw new Docx4JException('This table holds no paragraph');
55
+ const last = paragraphs[paragraphs.length - 1];
56
+ if (location === 'Start')
57
+ return first.getRange('Start');
58
+ if (location === 'End')
59
+ return last.getRange('End');
60
+ const whole = first.rangeTo(last, true, '\r\n');
61
+ return location === 'After' ? whole.getRange('After') : whole;
39
62
  }
40
63
  /** The text of every cell, row by row (Office JS values). */
41
64
  get values() {
42
65
  return this.rows.map((row) => row.values);
43
66
  }
44
67
  set values(values) {
68
+ this.assertWritable();
45
69
  const rows = this.rows;
70
+ rows.slice(0, values.length).forEach((row, i) => row.assertValuesWritable(values[i].length)); // nothing written before a refusal
46
71
  values.forEach((row, i) => { if (i < rows.length)
47
72
  rows[i].values = row; });
48
73
  }
@@ -52,6 +77,7 @@ export class Table {
52
77
  return (_c = (_b = (_a = this.tbl.tblPr) === null || _a === void 0 ? void 0 : _a.tblStyle) === null || _b === void 0 ? void 0 : _b.val) !== null && _c !== void 0 ? _c : '';
53
78
  }
54
79
  set styleId(id) {
80
+ this.assertWritable();
55
81
  if (id === '') {
56
82
  if (this.tbl.tblPr)
57
83
  delete this.tbl.tblPr.tblStyle;
@@ -83,6 +109,9 @@ export class Table {
83
109
  return n;
84
110
  }
85
111
  set headerRowCount(count) {
112
+ this.assertWritable();
113
+ for (const row of this.rows)
114
+ row.assertWritable();
86
115
  this.rows.forEach((row, i) => { row.isHeader = i < count; });
87
116
  }
88
117
  /** The cell at a row and cell index; throws when there is none, as Office JS's getCell does. */
@@ -99,17 +128,19 @@ export class Table {
99
128
  addRows(location, rowCount, values) {
100
129
  var _a;
101
130
  var _b;
131
+ this.assertWritable();
102
132
  const widths = this.columnWidths();
103
133
  const added = [];
104
134
  for (let i = 0; i < rowCount; i++)
105
135
  added.push(rowElement(widths, values === null || values === void 0 ? void 0 : values[i]));
106
136
  // New rows go into the table's own content, not into a row-level content control.
107
137
  const container = ((_a = (_b = this.tbl).content) !== null && _a !== void 0 ? _a : (_b.content = []));
108
- const first = rowsOf(this.tbl)[0];
138
+ const first = rowsOf(this.tbl, 'read')[0];
109
139
  const at = location === 'Start' && first && first.container === container ? container.indexOf(first.element) : location === 'Start' ? 0 : container.length;
110
140
  container.splice(at, 0, ...added);
111
141
  for (const row of added)
112
142
  linkParents(row, this.tbl);
143
+ assignParaIds(this.tbl, added);
113
144
  markRowsInserted(this.changeTracker, added);
114
145
  return added.map((element) => new TableRow(element, container, this));
115
146
  }
@@ -118,12 +149,17 @@ export class Table {
118
149
  * tracks changes the rows stay and take a `w:trPr/w:del` instead (CR-002 phase F).
119
150
  */
120
151
  deleteRows(rowIndex, rowCount = 1) {
152
+ this.assertWritable();
153
+ // indices count the rows a reader sees; a row in a branch is not deleted from here (D4)
154
+ const rows = this.rows.slice(rowIndex, rowIndex + rowCount);
155
+ for (const row of rows)
156
+ row.assertWritable();
121
157
  const tracker = this.changeTracker;
122
158
  if (tracker) {
123
- markRowsDeleted(tracker, this.rows.slice(rowIndex, rowIndex + rowCount));
159
+ markRowsDeleted(tracker, rows.map((row) => row.element), this.parentBody);
124
160
  return;
125
161
  }
126
- for (const row of rowsOf(this.tbl).slice(rowIndex, rowIndex + rowCount).reverse()) {
162
+ for (const row of rows.reverse()) {
127
163
  const i = row.container.indexOf(row.element);
128
164
  if (i >= 0)
129
165
  row.container.splice(i, 1);
@@ -140,8 +176,10 @@ export class Table {
140
176
  * table change is recorded as Office JS records one and the new cells' text is an insertion.
141
177
  */
142
178
  addColumns(location, columnCount, values) {
179
+ this.assertWritable();
143
180
  const at = location === 'Start' ? 0 : this.columnWidths().length;
144
181
  const inserted = insertGridColumns(this.tbl, this.textWidth(), at, columnCount, values, this.changeTracker);
182
+ assignParaIds(this.tbl, inserted.cells);
145
183
  return this.cellViewsOf(inserted.cells);
146
184
  }
147
185
  /**
@@ -152,8 +190,11 @@ export class Table {
152
190
  */
153
191
  deleteColumns(columnIndex, columnCount = 1) {
154
192
  var _a, _b, _c;
193
+ this.assertWritable();
155
194
  deleteGridColumns(this.tbl, this.textWidth(), columnIndex, columnCount, this.changeTracker);
156
- if (((_c = (_b = (_a = this.tbl.tblGrid) === null || _a === void 0 ? void 0 : _a.gridCol) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) === 0 || rowsOf(this.tbl).every((row) => cellsOf(row.element.value).length === 0))
195
+ // a cell in any branch of a kept mc:AlternateContent keeps the table (CR-013 phase 2): counted outside
196
+ // the branches alone, a table whose cells were all in one went with them
197
+ if (((_c = (_b = (_a = this.tbl.tblGrid) === null || _a === void 0 ? void 0 : _a.gridCol) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) === 0 || rowsOf(this.tbl, 'every').every((row) => cellsOf(row.element.value, 'every').length === 0))
157
198
  this.delete();
158
199
  }
159
200
  /** Which of Word's three layout modes the table is in: fixed, AutoFit to window, or AutoFit to contents (extension). */
@@ -176,9 +217,11 @@ export class Table {
176
217
  }
177
218
  /** Removes the table from its container; tracked, every row is marked deleted instead. */
178
219
  delete() {
220
+ this.assertWritable();
179
221
  const tracker = this.changeTracker;
222
+ // every branch's rows (CR-013 phase 3)
180
223
  if (tracker) {
181
- markRowsDeleted(tracker, this.rows);
224
+ markRowsDeleted(tracker, rowsOf(this.tbl, 'every').map((row) => row.element), this.parentBody);
182
225
  return;
183
226
  }
184
227
  const i = this.index;
@@ -193,9 +236,9 @@ export class Table {
193
236
  get parentTableCell() {
194
237
  return cellOf(this.tbl, this.parentBody);
195
238
  }
196
- /** The text of the table: a line per paragraph, as docx4j TextUtils (extension). */
239
+ /** The text of the table: a line per paragraph, each `Paragraph.text` (extension; CR-012 phase 4). */
197
240
  get text() {
198
- return textOf(this.tbl);
241
+ return this.rows.flatMap((row) => row.cells.flatMap((cell) => cell.paragraphs)).map((p) => p.text).join('\n');
199
242
  }
200
243
  /** The column widths in twips, from the grid or from the first row (extension). */
201
244
  columnWidths() {
@@ -203,8 +246,8 @@ export class Table {
203
246
  const grid = (_a = this.tbl.tblGrid) === null || _a === void 0 ? void 0 : _a.gridCol;
204
247
  if (grid && grid.length)
205
248
  return grid.map((c) => { var _a; return (_a = c.w) !== null && _a !== void 0 ? _a : Math.floor(DEFAULT_WIDTH / grid.length); });
206
- const first = rowsOf(this.tbl)[0];
207
- const cells = first ? cellsOf(first.element.value) : [];
249
+ const first = rowsOf(this.tbl, 'read')[0];
250
+ const cells = first ? cellsOf(first.element.value, 'read') : [];
208
251
  const n = Math.max(1, cells.length);
209
252
  const each = Math.floor(DEFAULT_WIDTH / n);
210
253
  return Array.from({ length: n }, (_, i) => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = cells[i]) === null || _a === void 0 ? void 0 : _a.element.value.tcPr) === null || _b === void 0 ? void 0 : _b.tcW) === null || _c === void 0 ? void 0 : _c.w) !== null && _d !== void 0 ? _d : each; });
@@ -214,6 +257,14 @@ export class Table {
214
257
  var _b;
215
258
  return ((_a = (_b = this.tbl).tblPr) !== null && _a !== void 0 ? _a : (_b.tblPr = {}));
216
259
  }
260
+ /** True for a table in the selected branch of a kept block-level `mc:AlternateContent` (CR-013 phase 2): read-only (D4). */
261
+ get inBranch() {
262
+ return inBranch(this.tbl);
263
+ }
264
+ /** Refuses a write to a table in a branch (CR-013 D4). Internal: the table's mutators call it first. */
265
+ assertWritable() {
266
+ assertOutsideBranch(this.tbl, 'Table');
267
+ }
217
268
  }
218
269
  /** A subset of Office JS `Word.TableRow` over a `w:tr`. */
219
270
  export class TableRow {
@@ -229,19 +280,20 @@ export class TableRow {
229
280
  }
230
281
  /** The row's index among the table's rows. */
231
282
  get rowIndex() {
232
- return rowsOf(this.parentTable.tbl).findIndex((r) => r.element === this.element);
283
+ return rowsOf(this.parentTable.tbl, 'read').findIndex((r) => r.element === this.element);
233
284
  }
234
285
  get cellCount() {
235
- return cellsOf(this.tr).length;
286
+ return cellsOf(this.tr, 'read').length;
236
287
  }
237
288
  get cells() {
238
- return cellsOf(this.tr).map((c) => new TableCell(c.element, c.container, this));
289
+ return cellsOf(this.tr, 'read').map((c) => new TableCell(c.element, c.container, this));
239
290
  }
240
291
  /** The text of the row's cells. */
241
292
  get values() {
242
293
  return this.cells.map((c) => c.text);
243
294
  }
244
295
  set values(values) {
296
+ this.assertValuesWritable(values.length);
245
297
  const cells = this.cells;
246
298
  values.forEach((v, i) => { if (i < cells.length)
247
299
  cells[i].value = v; });
@@ -254,6 +306,7 @@ export class TableRow {
254
306
  set isHeader(header) {
255
307
  var _a, _b, _c, _d;
256
308
  var _e;
309
+ this.assertWritable();
257
310
  const items = (_a = this.tr.trPr) === null || _a === void 0 ? void 0 : _a.cnfStyleOrDivIdOrGridBefore;
258
311
  const at = (_b = items === null || items === void 0 ? void 0 : items.findIndex((i) => i.name.localPart === 'tblHeader')) !== null && _b !== void 0 ? _b : -1;
259
312
  if (!header) {
@@ -269,6 +322,7 @@ export class TableRow {
269
322
  /** New rows before or after this one, with this table's columns. */
270
323
  insertRows(location, rowCount, values) {
271
324
  var _a;
325
+ this.assertWritable();
272
326
  const widths = this.parentTable.columnWidths();
273
327
  const added = [];
274
328
  for (let i = 0; i < rowCount; i++)
@@ -278,20 +332,36 @@ export class TableRow {
278
332
  const owner = (_a = ownerOfArray(this.container, this.parentTable.tbl)) !== null && _a !== void 0 ? _a : this.parentTable.tbl;
279
333
  for (const row of added)
280
334
  linkParents(row, owner);
335
+ assignParaIds(this.parentTable.tbl, added);
281
336
  markRowsInserted(this.parentTable.changeTracker, added);
282
337
  return added.map((element) => new TableRow(element, this.container, this.parentTable));
283
338
  }
284
339
  /** Removes the row; tracked, it stays and takes a `w:trPr/w:del` (CR-002 phase F). */
285
340
  delete() {
341
+ this.assertWritable();
286
342
  const tracker = this.parentTable.changeTracker;
287
343
  if (tracker) {
288
- markRowsDeleted(tracker, [this]);
344
+ markRowsDeleted(tracker, [this.element], this.parentTable.parentBody);
289
345
  return;
290
346
  }
291
347
  const i = this.container.indexOf(this.element);
292
348
  if (i >= 0)
293
349
  this.container.splice(i, 1);
294
350
  }
351
+ /** True for a row in a branch of a kept `mc:AlternateContent`, or in a table in one (CR-013 phase 2): read-only (D4). */
352
+ get inBranch() {
353
+ return inBranch(this.tr);
354
+ }
355
+ /** Refuses a write to a row in a branch (CR-013 D4). Internal. */
356
+ assertWritable() {
357
+ assertOutsideBranch(this.tr, 'TableRow');
358
+ }
359
+ /** Refuses `values` of `count` cells where the row, or one of those cells, is in a branch. Internal. */
360
+ assertValuesWritable(count) {
361
+ this.assertWritable();
362
+ for (const cell of this.cells.slice(0, count))
363
+ cell.assertWritable();
364
+ }
295
365
  trPrItem(localPart) {
296
366
  var _a, _b;
297
367
  return (_b = (_a = this.tr.trPr) === null || _a === void 0 ? void 0 : _a.cnfStyleOrDivIdOrGridBefore) === null || _b === void 0 ? void 0 : _b.find((i) => i.name.localPart === localPart);
@@ -316,7 +386,7 @@ export class TableCell {
316
386
  return this.parentRow.rowIndex;
317
387
  }
318
388
  get cellIndex() {
319
- return cellsOf(this.parentRow.tr).findIndex((c) => c.element === this.element);
389
+ return cellsOf(this.parentRow.tr, 'read').findIndex((c) => c.element === this.element);
320
390
  }
321
391
  /**
322
392
  * The cell's content as a `Body` (Office JS TableCell.body): the same part and package as the
@@ -333,16 +403,19 @@ export class TableCell {
333
403
  get tables() {
334
404
  return this.body.tables;
335
405
  }
336
- /** The cell's text, a line per paragraph. */
406
+ /**
407
+ * The cell's text as Office JS's `tableCell.value` gives it: its body's text (`Body.text`), its paragraphs'
408
+ * `Paragraph.text` a mark `\r` apart (check 51: `value`, `values` and `body.text` alike).
409
+ */
337
410
  get text() {
338
- return textOf(this.tc);
411
+ return this.body.text;
339
412
  }
340
413
  /** Office JS TableCell.value: the text, replaced as one paragraph when set. */
341
414
  get value() {
342
415
  return this.text;
343
416
  }
344
417
  set value(text) {
345
- this.body.clear();
418
+ this.body.clearContent(false); // its own paragraph ends the cell (CR-002 section 55)
346
419
  this.body.insertParagraph(text, 'End');
347
420
  }
348
421
  insertParagraph(text, location) {
@@ -365,16 +438,15 @@ export class TableCell {
365
438
  set width(points) {
366
439
  var _a, _b;
367
440
  var _c, _d;
368
- const twips = Math.round(points * TWIPS_PER_POINT);
441
+ this.assertWritable();
442
+ // within the range Word 365 stores w:tcW/@w:w in, a percentage's fiftieths too (CR-002 section 65), before anything changes
443
+ const pct = widthTypeOf(this.tc, this.parentTable.tbl) === 'pct';
444
+ const w = pct
445
+ ? withinWord('TableCell.width', points, WORD_STORAGE.tcWPct, Math.round((Math.round(points * TWIPS_PER_POINT) * 5000) / this.parentTable.textWidth()))
446
+ : withinWord('TableCell.width', points, WORD_STORAGE.tcWDxa);
369
447
  const tcW = ((_b = (_d = ((_a = (_c = this.tc).tcPr) !== null && _a !== void 0 ? _a : (_c.tcPr = {}))).tcW) !== null && _b !== void 0 ? _b : (_d.tcW = {}));
370
- if (widthTypeOf(this.tc, this.parentTable.tbl) === 'pct') {
371
- tcW.w = Math.round((twips * 5000) / this.parentTable.textWidth());
372
- tcW.type = 'pct';
373
- }
374
- else {
375
- tcW.w = twips;
376
- tcW.type = 'dxa';
377
- }
448
+ tcW.w = w;
449
+ tcW.type = pct ? 'pct' : 'dxa';
378
450
  }
379
451
  /**
380
452
  * New columns before or after this cell (Office JS `TableCell.insertColumns`), the new cells
@@ -382,20 +454,31 @@ export class TableCell {
382
454
  * row (extension).
383
455
  */
384
456
  insertColumns(location, columnCount, values) {
457
+ this.assertWritable();
385
458
  const range = gridRangeOf(this.parentRow.tr, this.tc);
386
459
  if (!range)
387
460
  throw new Docx4JException('This cell is not in its row');
388
461
  const table = this.parentTable;
389
462
  const inserted = insertGridColumns(table.tbl, table.textWidth(), location === 'Before' ? range.start : range.end, columnCount, values, table.changeTracker);
463
+ assignParaIds(table.tbl, inserted.cells);
390
464
  return table.cellViewsOf(inserted.cells);
391
465
  }
392
466
  /** Removes the grid columns this cell covers (Office JS `TableCell.deleteColumn`); tracked as `Table.deleteColumns` is. */
393
467
  deleteColumn() {
468
+ this.assertWritable();
394
469
  const range = gridRangeOf(this.parentRow.tr, this.tc);
395
470
  if (!range)
396
471
  throw new Docx4JException('This cell is not in its row');
397
472
  this.parentTable.deleteColumns(range.start, range.end - range.start);
398
473
  }
474
+ /** True for a cell in a branch of a kept `mc:AlternateContent`, or in a row or table in one (CR-013 phase 2): read-only (D4). */
475
+ get inBranch() {
476
+ return inBranch(this.tc);
477
+ }
478
+ /** Refuses a write to a cell in a branch (CR-013 D4); its body's writes refuse too. Internal. */
479
+ assertWritable() {
480
+ assertOutsideBranch(this.tc, 'TableCell');
481
+ }
399
482
  /** Office JS TableCell.columnWidth, the same value. */
400
483
  get columnWidth() {
401
484
  return this.width;
@@ -440,8 +523,8 @@ export function cellOf(value, parentBody) {
440
523
  }
441
524
  if (!tc)
442
525
  return undefined;
443
- // a cell-level content control sits between the cell and the row
444
- const tr = ancestorOf(tc, 'org_docx4j_wml.Tr', 4);
526
+ // cell-level content controls sit between the cell and the row, nested to any depth
527
+ const tr = ancestorOf(tc, 'org_docx4j_wml.Tr');
445
528
  if (!tr)
446
529
  return undefined;
447
530
  const tbl = ancestorTable(tr);
@@ -452,21 +535,27 @@ export function cellOf(value, parentBody) {
452
535
  if (!tblElement || !tblContainer)
453
536
  return undefined;
454
537
  const table = new Table(tblElement, tblContainer, parentBody);
455
- const row = rowsOf(tbl).find((r) => r.element.value === tr);
538
+ const row = rowsOf(tbl, 'read').find((r) => r.element.value === tr);
456
539
  if (!row)
457
540
  return undefined;
458
541
  const rowView = new TableRow(row.element, row.container, table);
459
- const cell = cellsOf(tr).find((c) => c.element.value === tc);
542
+ const cell = cellsOf(tr, 'read').find((c) => c.element.value === tc);
460
543
  return cell ? new TableCell(cell.element, cell.container, rowView) : undefined;
461
544
  }
462
- /** The w:tbl a row is in, through a row-level content control if there is one. */
545
+ /**
546
+ * The w:tbl a row is in, through the row-level content controls around it, nested to any depth: a repeating section's
547
+ * item inside the section puts four holders between the row and its table (the editor's finding on `invoice2013.docx`, 2026-10-26; CR-002 section 64).
548
+ */
463
549
  function ancestorTable(tr) {
464
- return ancestorOf(tr, 'org_docx4j_wml.Tbl', 4);
550
+ return ancestorOf(tr, 'org_docx4j_wml.Tbl');
465
551
  }
466
- /** The nearest ancestor of a type, at most `depth` PARENT steps up (the sdt wrappers are steps). */
467
- function ancestorOf(value, typeName, depth) {
552
+ /**
553
+ * The nearest ancestor of a type. Only holders stand between a cell and its row, or a row and its table (content
554
+ * controls, custom XML, a kept `mc:AlternateContent`'s branch), so the nearest is the one; the guard only stops a cycle.
555
+ */
556
+ function ancestorOf(value, typeName) {
468
557
  let current = value.PARENT;
469
- for (let guard = 0; current && guard < depth; guard++) {
558
+ for (let guard = 0; current && guard < 256; guard++) {
470
559
  if (typeNameOf(current) === typeName)
471
560
  return current;
472
561
  current = current.PARENT;
@@ -479,15 +568,12 @@ function ancestorOf(value, typeName, depth) {
479
568
  * with `w:delText` for its text, and every paragraph mark `w:pPr/w:rPr/w:del` (CR-002 section 13).
480
569
  * The mirror of `markRowsInserted`. Rows of a nested table go the same way.
481
570
  */
482
- function markRowsDeleted(tracker, rows) {
571
+ function markRowsDeleted(tracker, rows, parentBody) {
572
+ // every branch of a kept mc:AlternateContent among the cells and in them (CR-013 phase 3)
483
573
  for (const row of rows.slice().reverse()) {
484
- tracker.markRowDeleted(row.tr);
485
- for (const cell of row.cells) {
486
- for (const paragraph of cell.paragraphs)
487
- paragraph.markDeletedInPlace(tracker);
488
- for (const nested of cell.tables)
489
- markRowsDeleted(tracker, nested.rows);
490
- }
574
+ tracker.markRowDeleted(row.value);
575
+ for (const cell of cellsOf(row.value, 'every'))
576
+ parentBody.sub(cell.element.value).markContentDeleted(tracker);
491
577
  }
492
578
  }
493
579
  /** A new row is an insertion: `w:trPr/w:ins` on it and a `w:ins` around every run it holds. */
@@ -498,8 +584,8 @@ function markRowsInserted(tracker, rows) {
498
584
  for (const row of rows) {
499
585
  if (!((_a = row.value.trPr) === null || _a === void 0 ? void 0 : _a.ins))
500
586
  tracker.markRowInserted(row.value);
501
- // nested tables and block controls in a new row's cells too (CR-002 section 37)
502
- for (const cell of cellsOf(row.value))
587
+ // nested tables and block controls in a new row's cells too (CR-002 section 37), in every branch
588
+ for (const cell of cellsOf(row.value, 'every'))
503
589
  trackInsertedBlocks(tracker, childrenOf(cell.element.value));
504
590
  }
505
591
  }