@docx4j/core-ts 0.1.0 → 0.1.2

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 (172) hide show
  1. package/README.md +410 -10
  2. package/dist/model/content/Body.d.mts +109 -4
  3. package/dist/model/content/Body.mjs +300 -29
  4. package/dist/model/content/Comment.d.mts +78 -0
  5. package/dist/model/content/Comment.mjs +429 -0
  6. package/dist/model/content/ContentControl.d.mts +173 -0
  7. package/dist/model/content/ContentControl.mjs +638 -0
  8. package/dist/model/content/Font.d.mts +48 -8
  9. package/dist/model/content/Font.mjs +55 -13
  10. package/dist/model/content/InlinePicture.d.mts +103 -0
  11. package/dist/model/content/InlinePicture.mjs +361 -0
  12. package/dist/model/content/List.d.mts +253 -0
  13. package/dist/model/content/List.mjs +778 -0
  14. package/dist/model/content/Paragraph.d.mts +213 -16
  15. package/dist/model/content/Paragraph.mjs +611 -57
  16. package/dist/model/content/Range.d.mts +48 -4
  17. package/dist/model/content/Range.mjs +161 -4
  18. package/dist/model/content/Table.d.mts +130 -0
  19. package/dist/model/content/Table.mjs +429 -0
  20. package/dist/model/content/TrackedChange.d.mts +96 -0
  21. package/dist/model/content/TrackedChange.mjs +352 -0
  22. package/dist/model/content/comments.d.mts +122 -0
  23. package/dist/model/content/comments.mjs +248 -0
  24. package/dist/model/content/index.d.mts +13 -3
  25. package/dist/model/content/index.mjs +15 -3
  26. package/dist/model/content/ooxml.d.mts +17 -0
  27. package/dist/model/content/ooxml.mjs +214 -0
  28. package/dist/model/content/styles.d.mts +21 -0
  29. package/dist/model/content/styles.mjs +86 -0
  30. package/dist/model/content/tracking.d.mts +104 -0
  31. package/dist/model/content/tracking.mjs +313 -0
  32. package/dist/model/content/tree.d.mts +56 -9
  33. package/dist/model/content/tree.mjs +104 -31
  34. package/dist/model/customxml/CustomXmlPart.d.mts +158 -0
  35. package/dist/model/customxml/CustomXmlPart.mjs +415 -0
  36. package/dist/model/customxml/CustomXmlPartCollection.d.mts +68 -0
  37. package/dist/model/customxml/CustomXmlPartCollection.mjs +183 -0
  38. package/dist/model/customxml/XmlMapping.d.mts +46 -0
  39. package/dist/model/customxml/XmlMapping.mjs +98 -0
  40. package/dist/model/customxml/bindings.d.mts +41 -0
  41. package/dist/model/customxml/bindings.mjs +230 -0
  42. package/dist/model/customxml/index.d.mts +7 -0
  43. package/dist/model/customxml/index.mjs +9 -0
  44. package/dist/model/customxml/insert.d.mts +20 -0
  45. package/dist/model/customxml/insert.mjs +22 -0
  46. package/dist/model/customxml/kinds.d.mts +103 -0
  47. package/dist/model/customxml/kinds.mjs +267 -0
  48. package/dist/model/customxml/xpath.d.mts +52 -0
  49. package/dist/model/customxml/xpath.mjs +205 -0
  50. package/dist/model/fonts/CJKToEnglish.d.mts +2 -0
  51. package/dist/model/fonts/CJKToEnglish.mjs +16 -0
  52. package/dist/model/fonts/FontFallback.d.mts +58 -0
  53. package/dist/model/fonts/FontFallback.mjs +219 -0
  54. package/dist/model/fonts/IdentityPlusMapper.d.mts +7 -0
  55. package/dist/model/fonts/IdentityPlusMapper.mjs +19 -0
  56. package/dist/model/fonts/LanguageTagToScriptMapping.d.mts +7 -0
  57. package/dist/model/fonts/LanguageTagToScriptMapping.mjs +67 -0
  58. package/dist/model/fonts/Mapper.d.mts +190 -0
  59. package/dist/model/fonts/Mapper.mjs +481 -0
  60. package/dist/model/fonts/PhysicalFont.d.mts +34 -0
  61. package/dist/model/fonts/PhysicalFont.mjs +62 -0
  62. package/dist/model/fonts/RunFontSelector.d.mts +194 -0
  63. package/dist/model/fonts/RunFontSelector.mjs +441 -0
  64. package/dist/model/fonts/ThemeFonts.d.mts +17 -0
  65. package/dist/model/fonts/ThemeFonts.mjs +76 -0
  66. package/dist/model/fonts/defaultTheme.d.mts +37 -0
  67. package/dist/model/fonts/defaultTheme.mjs +57 -0
  68. package/dist/model/fonts/families.generated.d.mts +11 -0
  69. package/dist/model/fonts/families.generated.mjs +17 -0
  70. package/dist/model/fonts/fontsInUse.d.mts +39 -0
  71. package/dist/model/fonts/fontsInUse.mjs +183 -0
  72. package/dist/model/fonts/index.d.mts +14 -0
  73. package/dist/model/fonts/index.mjs +29 -0
  74. package/dist/model/fonts/lookup.d.mts +5 -0
  75. package/dist/model/fonts/lookup.mjs +12 -0
  76. package/dist/model/fonts/registry.d.mts +31 -0
  77. package/dist/model/fonts/registry.mjs +103 -0
  78. package/dist/model/fonts/scripts.d.mts +2 -0
  79. package/dist/model/fonts/scripts.mjs +78 -0
  80. package/dist/model/fonts/substitutions.generated.d.mts +30 -0
  81. package/dist/model/fonts/substitutions.generated.mjs +12 -0
  82. package/dist/model/fonts/themes.generated.d.mts +6 -0
  83. package/dist/model/fonts/themes.generated.mjs +11 -0
  84. package/dist/model/index.d.mts +5 -0
  85. package/dist/model/index.mjs +13 -1
  86. package/dist/model/listnumbering/Emulator.d.mts +187 -0
  87. package/dist/model/listnumbering/Emulator.mjs +332 -0
  88. package/dist/model/listnumbering/definitions.d.mts +251 -0
  89. package/dist/model/listnumbering/definitions.mjs +571 -0
  90. package/dist/model/listnumbering/formats.d.mts +25 -0
  91. package/dist/model/listnumbering/formats.mjs +320 -0
  92. package/dist/model/listnumbering/index.d.mts +4 -0
  93. package/dist/model/listnumbering/index.mjs +15 -0
  94. package/dist/model/listnumbering/state.d.mts +97 -0
  95. package/dist/model/listnumbering/state.mjs +179 -0
  96. package/dist/model/properties/PropertyResolver.d.mts +216 -0
  97. package/dist/model/properties/PropertyResolver.mjs +524 -0
  98. package/dist/model/properties/catalogue.d.mts +179 -0
  99. package/dist/model/properties/catalogue.mjs +860 -0
  100. package/dist/model/properties/index.d.mts +4 -0
  101. package/dist/model/properties/index.mjs +9 -0
  102. package/dist/model/properties/log.d.mts +7 -0
  103. package/dist/model/properties/log.mjs +25 -0
  104. package/dist/model/properties/styleUtil.d.mts +112 -0
  105. package/dist/model/properties/styleUtil.mjs +359 -0
  106. package/dist/node/index.d.mts +1 -0
  107. package/dist/node/index.mjs +12 -0
  108. package/dist/office-js/document.d.mts +111 -0
  109. package/dist/office-js/document.mjs +267 -0
  110. package/dist/office-js/enums.d.mts +187 -0
  111. package/dist/office-js/enums.mjs +176 -0
  112. package/dist/office-js/errors.d.mts +29 -0
  113. package/dist/office-js/errors.mjs +39 -0
  114. package/dist/office-js/extras.d.mts +5 -0
  115. package/dist/office-js/extras.mjs +29 -0
  116. package/dist/office-js/fragment.d.mts +10 -0
  117. package/dist/office-js/fragment.mjs +23 -0
  118. package/dist/office-js/index.d.mts +183 -0
  119. package/dist/office-js/index.mjs +54 -0
  120. package/dist/office-js/proxy.d.mts +72 -0
  121. package/dist/office-js/proxy.mjs +279 -0
  122. package/dist/office-js/run.d.mts +32 -0
  123. package/dist/office-js/run.mjs +66 -0
  124. package/dist/office-js/supported.d.mts +7 -0
  125. package/dist/office-js/supported.generated.d.mts +1 -0
  126. package/dist/office-js/supported.generated.mjs +235 -0
  127. package/dist/office-js/supported.mjs +53 -0
  128. package/dist/office-js/toApiScript.d.mts +25 -0
  129. package/dist/office-js/toApiScript.mjs +394 -0
  130. package/dist/opc/ContentTypes.d.mts +11 -0
  131. package/dist/opc/ContentTypes.mjs +14 -0
  132. package/dist/opc/DirectoryPartStore.d.mts +47 -0
  133. package/dist/opc/DirectoryPartStore.mjs +123 -0
  134. package/dist/opc/exceptions.d.mts +30 -0
  135. package/dist/opc/exceptions.mjs +38 -0
  136. package/dist/opc/index.d.mts +1 -1
  137. package/dist/opc/index.mjs +1 -1
  138. package/dist/packages/OpcPackage.d.mts +19 -1
  139. package/dist/packages/OpcPackage.mjs +29 -0
  140. package/dist/packages/PresentationMLPackage.d.mts +71 -1
  141. package/dist/packages/PresentationMLPackage.mjs +179 -0
  142. package/dist/packages/SpreadsheetMLPackage.d.mts +30 -1
  143. package/dist/packages/SpreadsheetMLPackage.mjs +78 -0
  144. package/dist/packages/WordprocessingMLPackage.d.mts +124 -2
  145. package/dist/packages/WordprocessingMLPackage.mjs +309 -2
  146. package/dist/packages/index.d.mts +1 -1
  147. package/dist/packages/index.mjs +1 -1
  148. package/dist/parts/DefaultXmlPart.d.mts +18 -0
  149. package/dist/parts/DefaultXmlPart.mjs +34 -5
  150. package/dist/parts/Namespaces.d.mts +18 -0
  151. package/dist/parts/Namespaces.mjs +20 -0
  152. package/dist/parts/Part.d.mts +6 -0
  153. package/dist/parts/Part.mjs +13 -0
  154. package/dist/parts/PartRegistry.mjs +13 -1
  155. package/dist/parts/XmlPart.d.mts +33 -0
  156. package/dist/parts/XmlPart.mjs +105 -2
  157. package/dist/parts/pml/defaults.d.mts +6 -0
  158. package/dist/parts/pml/defaults.mjs +53 -0
  159. package/dist/parts/pml/index.d.mts +66 -3
  160. package/dist/parts/pml/index.mjs +206 -7
  161. package/dist/parts/pml/placeholders.d.mts +71 -0
  162. package/dist/parts/pml/placeholders.mjs +141 -0
  163. package/dist/parts/sml/index.d.mts +80 -1
  164. package/dist/parts/sml/index.mjs +154 -1
  165. package/dist/parts/wml/comments.d.mts +1 -0
  166. package/dist/parts/wml/comments.mjs +179 -0
  167. package/dist/parts/wml/defaultNumbering.d.mts +1 -0
  168. package/dist/parts/wml/defaultNumbering.mjs +216 -0
  169. package/dist/parts/wml/index.d.mts +121 -0
  170. package/dist/parts/wml/index.mjs +291 -0
  171. package/dist/xml/dom.mjs +1 -2
  172. package/package.json +25 -4
@@ -1,8 +1,12 @@
1
1
  import type * as wml from '@docx4j/generated-objects-ts/modules/org_docx4j_wml';
2
2
  import { Font } from './Font.mjs';
3
- import type { Paragraph } from './Paragraph.mjs';
4
- import type { Element } from './tree.mjs';
3
+ import type { Paragraph, FormattingOptions } from './Paragraph.mjs';
4
+ import type { BlockElement } from './Body.mjs';
5
+ import { type Element, type TextViewOptions } from './tree.mjs';
6
+ import { ContentControl, type ContentControlType } from './ContentControl.mjs';
5
7
  import { type SearchOptions } from './search.mjs';
8
+ import type { Comment } from './Comment.mjs';
9
+ import type { TrackedChange } from './TrackedChange.mjs';
6
10
  /**
7
11
  * A subset of Office JS `Word.Range`: a span of text within one paragraph, [start, end) in the
8
12
  * paragraph's text. Positions are recomputed from the tree on every use, so a range stays
@@ -16,19 +20,59 @@ export declare class Range {
16
20
  get paragraphs(): Paragraph[];
17
21
  get text(): string;
18
22
  set text(value: string);
19
- /** The paragraph's style (Office JS reports the range's paragraph style). */
23
+ /** The paragraph's style id (extension, as on Paragraph). */
24
+ get styleId(): string;
25
+ set styleId(id: string);
26
+ /** The paragraph's style name (Office JS reports the range's paragraph style). */
20
27
  get style(): string;
21
28
  set style(id: string);
22
- /** Direct formatting of exactly this span: runs are split at the boundaries so that a write touches only the span. */
29
+ /**
30
+ * The text in one of the two views (extension; `text` is the accepted one). `{ view: 'original' }`
31
+ * is offered on `Paragraph` and `Body`; on a `Range` it is the accepted-view span only, since a
32
+ * range's offsets are accepted-view offsets.
33
+ */
34
+ getText(options?: TextViewOptions): string;
35
+ /**
36
+ * The formatting of exactly this span: reads the first run's *effective* properties, writes
37
+ * direct formatting, splitting the runs at the boundaries so that a write touches only the
38
+ * span.
39
+ */
23
40
  get font(): Font;
41
+ /** `font`, with `{ direct: true }` for the direct formatting of the first run (extension). */
42
+ getFont(options?: FormattingOptions): Font;
24
43
  /** The runs the span covers (a run partly inside counts). */
25
44
  get runs(): Element<wml.R>[];
26
45
  insertText(text: string, location: 'Before' | 'After' | 'Start' | 'End' | 'Replace'): Range;
27
46
  insertParagraph(text: string, location: 'Before' | 'After'): Paragraph;
47
+ /**
48
+ * Word's `insertOoxml` at range level: a flat OPC `pkg:package` (or a bare fragment). One
49
+ * incoming paragraph's runs go at the start or the end of the span, or in its place; anything
50
+ * else is inserted as blocks before or after the paragraph. Returns what was inserted, as
51
+ * `insertXml` does.
52
+ */
53
+ insertOoxml(ooxml: string, location: 'Before' | 'After' | 'Replace'): Promise<(Paragraph | BlockElement)[]>;
28
54
  /** Removes the span's text. */
29
55
  delete(): void;
30
56
  search(text: string, options?: SearchOptions): Range[];
57
+ /** Replaces every match in this span, last first so the offsets stay valid; returns the count (CR-002 section 3.7). */
58
+ replaceText(find: string, replace: string, options?: SearchOptions): number;
59
+ /** The tracked changes this span covers, in document order (CR-002 phase F). */
60
+ getTrackedChanges(): TrackedChange[];
31
61
  getRange(location?: 'Whole' | 'Start' | 'End' | 'Content'): Range;
32
62
  /** The span's text as it stands (extension; Office JS getOoxml wraps it in a package). */
33
63
  toString(): string;
64
+ /** The comments this span touches, replies nested under their parent. */
65
+ getComments(): Promise<Comment[]>;
66
+ /**
67
+ * Comments the span: the markers and the reference run around it (runs are split at the
68
+ * boundaries, as `font` does), the comment itself and the side-part entries, creating any of
69
+ * the comment parts the document lacks. Asynchronous because it unmarshals those parts.
70
+ */
71
+ insertComment(text: string): Promise<Comment>;
72
+ /**
73
+ * Wraps the runs this span covers in a run-level content control (Office JS
74
+ * `Range.insertContentControl`), splitting the runs at the boundaries as `font` does. An empty
75
+ * span gets an empty control at its position. Returns the control.
76
+ */
77
+ insertContentControl(kind?: ContentControlType): ContentControl;
34
78
  }
@@ -1,5 +1,13 @@
1
1
  import { Font } from './Font.mjs';
2
+ import { runFontSelectorOf } from '../fonts/lookup.mjs';
3
+ import { typeNameOf, linkParents, runItemsOf } from './tree.mjs';
4
+ import { Docx4JException } from '../../opc/exceptions.mjs';
5
+ import { ContentControl } from './ContentControl.mjs';
6
+ import { sdt as sdtOf, nextSdtId } from '@docx4j/generated-objects-ts/builders/wml';
7
+ import { controlIdScope, sdtKindFor } from '../customxml/insert.mjs';
8
+ import { contentOf } from './ooxml.mjs';
2
9
  import { searchPattern, findAll } from './search.mjs';
10
+ import { commentApi } from './comments.mjs';
3
11
  /**
4
12
  * A subset of Office JS `Word.Range`: a span of text within one paragraph, [start, end) in the
5
13
  * paragraph's text. Positions are recomputed from the tree on every use, so a range stays
@@ -20,22 +28,50 @@ export class Range {
20
28
  set text(value) {
21
29
  this.insertText(value, 'Replace');
22
30
  }
23
- /** The paragraph's style (Office JS reports the range's paragraph style). */
31
+ /** The paragraph's style id (extension, as on Paragraph). */
32
+ get styleId() {
33
+ return this.paragraph.styleId;
34
+ }
35
+ set styleId(id) {
36
+ this.paragraph.styleId = id;
37
+ }
38
+ /** The paragraph's style name (Office JS reports the range's paragraph style). */
24
39
  get style() {
25
40
  return this.paragraph.style;
26
41
  }
27
42
  set style(id) {
28
43
  this.paragraph.style = id;
29
44
  }
30
- /** Direct formatting of exactly this span: runs are split at the boundaries so that a write touches only the span. */
45
+ /**
46
+ * The text in one of the two views (extension; `text` is the accepted one). `{ view: 'original' }`
47
+ * is offered on `Paragraph` and `Body`; on a `Range` it is the accepted-view span only, since a
48
+ * range's offsets are accepted-view offsets.
49
+ */
50
+ getText(options) {
51
+ if ((options === null || options === void 0 ? void 0 : options.view) === 'original')
52
+ throw new Docx4JException("A Range's offsets are accepted-view offsets; read the original view on its Paragraph");
53
+ return this.text;
54
+ }
55
+ /**
56
+ * The formatting of exactly this span: reads the first run's *effective* properties, writes
57
+ * direct formatting, splitting the runs at the boundaries so that a write touches only the
58
+ * span.
59
+ */
31
60
  get font() {
32
- return new Font(() => {
61
+ return this.getFont();
62
+ }
63
+ /** `font`, with `{ direct: true }` for the direct formatting of the first run (extension). */
64
+ getFont(options) {
65
+ const holders = () => {
33
66
  if (this.start === this.end)
34
67
  return [];
35
68
  this.paragraph.splitAt(this.start);
36
69
  this.paragraph.splitAt(this.end);
37
70
  return this.runs.map((r) => r.value);
38
- });
71
+ };
72
+ if ((options === null || options === void 0 ? void 0 : options.direct) === true)
73
+ return new Font(holders, () => this.paragraph.fontTracking());
74
+ return new Font(holders, () => this.paragraph.fontTracking(), (rPr) => this.paragraph.parentBody.propertyResolver.getEffectiveRPr(rPr, this.paragraph.p.pPr), (rPr) => { var _a; return (_a = runFontSelectorOf(this.paragraph.parentBody.package_)) === null || _a === void 0 ? void 0 : _a.asciiFontName(rPr); });
39
75
  }
40
76
  /** The runs the span covers (a run partly inside counts). */
41
77
  get runs() {
@@ -71,6 +107,39 @@ export class Range {
71
107
  insertParagraph(text, location) {
72
108
  return this.paragraph.insertParagraph(text, location);
73
109
  }
110
+ /**
111
+ * Word's `insertOoxml` at range level: a flat OPC `pkg:package` (or a bare fragment). One
112
+ * incoming paragraph's runs go at the start or the end of the span, or in its place; anything
113
+ * else is inserted as blocks before or after the paragraph. Returns what was inserted, as
114
+ * `insertXml` does.
115
+ */
116
+ async insertOoxml(ooxml, location) {
117
+ var _a, _b, _c;
118
+ const body = this.paragraph.parentBody;
119
+ const preprocess = (_a = body.package_) === null || _a === void 0 ? void 0 : _a.loadOptions.preprocessor;
120
+ const elements = await contentOf(ooxml, { preprocess: preprocess ? (doc) => preprocess(doc) : undefined, target: body.part });
121
+ if (elements.length === 0)
122
+ return [];
123
+ const only = elements.length === 1 && typeNameOf(elements[0]) === 'org_docx4j_wml.P' ? elements[0].value : undefined;
124
+ if (only) {
125
+ if (location === 'Replace') {
126
+ this.delete();
127
+ this.paragraph.insertItemsAt(this.start, ((_b = only.content) !== null && _b !== void 0 ? _b : []));
128
+ }
129
+ else
130
+ this.paragraph.insertItemsAt(location === 'Before' ? this.start : this.end, ((_c = only.content) !== null && _c !== void 0 ? _c : []));
131
+ return [this.paragraph];
132
+ }
133
+ body.insertElement(elements, location === 'Before' ? 'Before' : 'After', this.paragraph);
134
+ if (location === 'Replace')
135
+ this.delete();
136
+ return elements.map((el) => {
137
+ var _a;
138
+ return typeNameOf(el) === 'org_docx4j_wml.P'
139
+ ? (_a = body.paragraphFor(el.value)) !== null && _a !== void 0 ? _a : { element: el, container: this.paragraph.container }
140
+ : { element: el, container: this.paragraph.container };
141
+ });
142
+ }
74
143
  /** Removes the span's text. */
75
144
  delete() {
76
145
  this.paragraph.splice(this.start, this.end, '');
@@ -80,6 +149,22 @@ export class Range {
80
149
  const base = this.start;
81
150
  return findAll(this.text, searchPattern(text, options)).map(([s, e]) => new Range(this.paragraph, base + s, base + e));
82
151
  }
152
+ /** Replaces every match in this span, last first so the offsets stay valid; returns the count (CR-002 section 3.7). */
153
+ replaceText(find, replace, options) {
154
+ const matches = this.search(find, options);
155
+ for (let i = matches.length - 1; i >= 0; i--)
156
+ matches[i].insertText(replace, 'Replace');
157
+ return matches.length;
158
+ }
159
+ /** The tracked changes this span covers, in document order (CR-002 phase F). */
160
+ getTrackedChanges() {
161
+ return this.paragraph.getTrackedChanges().filter((change) => {
162
+ const range = change.getRange();
163
+ if (!range)
164
+ return false;
165
+ return range.start <= this.end && range.end >= this.start;
166
+ });
167
+ }
83
168
  getRange(location = 'Whole') {
84
169
  if (location === 'Start')
85
170
  return new Range(this.paragraph, this.start, this.start);
@@ -91,4 +176,76 @@ export class Range {
91
176
  toString() {
92
177
  return this.text;
93
178
  }
179
+ // --- comments (CR-002 phase G) ---
180
+ /** The comments this span touches, replies nested under their parent. */
181
+ async getComments() {
182
+ return commentApi().commentsOf(this);
183
+ }
184
+ /**
185
+ * Comments the span: the markers and the reference run around it (runs are split at the
186
+ * boundaries, as `font` does), the comment itself and the side-part entries, creating any of
187
+ * the comment parts the document lacks. Asynchronous because it unmarshals those parts.
188
+ */
189
+ async insertComment(text) {
190
+ return commentApi().insertComment(this, text);
191
+ }
192
+ // --- content controls (CR-002 phase E) ---
193
+ /**
194
+ * Wraps the runs this span covers in a run-level content control (Office JS
195
+ * `Range.insertContentControl`), splitting the runs at the boundaries as `font` does. An empty
196
+ * span gets an empty control at its position. Returns the control.
197
+ */
198
+ insertContentControl(kind) {
199
+ var _a;
200
+ const paragraph = this.paragraph;
201
+ const body = paragraph.parentBody;
202
+ // The control is built empty first: `sdt` refuses a kind that cannot be run-level (a repeating
203
+ // section), and that refusal must come before any run is split.
204
+ const sdt = sdtOf([], { kind: sdtKindFor(kind), id: nextSdtId(controlIdScope(body)), form: 'run' });
205
+ if (this.start === this.end) {
206
+ paragraph.insertItemsAt(this.start, [sdt]);
207
+ return new ContentControl(sdt, containerOf(sdt, paragraph), body);
208
+ }
209
+ paragraph.splitAt(this.start);
210
+ paragraph.splitAt(this.end);
211
+ const segments = paragraph.segments().filter((s) => s.start >= this.start && s.end <= this.end);
212
+ if (segments.length === 0)
213
+ throw new Docx4JException('This range covers no run');
214
+ const owner = segments[0].runOwner;
215
+ if (segments.some((s) => s.runOwner !== owner)) {
216
+ throw new Docx4JException('This range spans more than one run holder (a hyperlink or a tracked change); wrap a narrower span');
217
+ }
218
+ const items = [];
219
+ for (const segment of segments) {
220
+ const element = owner[segment.runIndex];
221
+ if (!items.includes(element))
222
+ items.push(element);
223
+ }
224
+ const at = owner.indexOf(items[0]);
225
+ sdt.value.sdtContent.content = items;
226
+ owner.splice(at, items.length, sdt);
227
+ linkParents(sdt, (_a = segments[0].run.PARENT) !== null && _a !== void 0 ? _a : paragraph.p);
228
+ return new ContentControl(sdt, owner, body);
229
+ }
230
+ }
231
+ /** The run-level array holding an element, after `insertItemsAt` put it somewhere in the paragraph. */
232
+ function containerOf(element, paragraph) {
233
+ var _a, _b;
234
+ var _c;
235
+ const seek = (items) => {
236
+ if (!items)
237
+ return undefined;
238
+ if (items.includes(element))
239
+ return items;
240
+ for (const item of items) {
241
+ const value = item.value;
242
+ if (typeof value !== 'object' || value === null)
243
+ continue;
244
+ const found = seek(runItemsOf(value));
245
+ if (found)
246
+ return found;
247
+ }
248
+ return undefined;
249
+ };
250
+ return (_a = seek(runItemsOf(paragraph.p))) !== null && _a !== void 0 ? _a : ((_b = (_c = paragraph.p).content) !== null && _b !== void 0 ? _b : (_c.content = []));
94
251
  }
@@ -0,0 +1,130 @@
1
+ import type * as wml from '@docx4j/generated-objects-ts/modules/org_docx4j_wml';
2
+ import { type Element } from './tree.mjs';
3
+ import type { Body } from './Body.mjs';
4
+ import type { Paragraph } from './Paragraph.mjs';
5
+ import type { Range } from './Range.mjs';
6
+ import { type ChangeTracker } from './tracking.mjs';
7
+ /**
8
+ * A subset of Office JS `Word.Table` over a `w:tbl`. Rows are read through row-level content
9
+ * controls (an OpenDoPE repeat wraps its `w:tr` in a `w:sdt`), so `rows` is what Word shows.
10
+ */
11
+ export declare class Table {
12
+ /** The `w:tbl` element pair. */
13
+ readonly element: Element<wml.Tbl>;
14
+ /** The content array holding the element. */
15
+ readonly container: Element[];
16
+ /** The body the table is in (the part's), for addresses and paragraph ids. */
17
+ readonly parentBody: Body;
18
+ constructor(
19
+ /** The `w:tbl` element pair. */
20
+ element: Element<wml.Tbl>,
21
+ /** The content array holding the element. */
22
+ container: Element[],
23
+ /** The body the table is in (the part's), for addresses and paragraph ids. */
24
+ parentBody: Body);
25
+ /** The table value (docx4j: the Tbl). */
26
+ get tbl(): wml.Tbl;
27
+ get index(): number;
28
+ get rowCount(): number;
29
+ get rows(): TableRow[];
30
+ /** The text of every cell, row by row (Office JS values). */
31
+ get values(): string[][];
32
+ set values(values: string[][]);
33
+ /** The table style id (w:tblStyle; docx4j's name for it); '' when none is set. Extension, as on Paragraph. */
34
+ get styleId(): string;
35
+ set styleId(id: string);
36
+ /** The style's display name ('Table Grid'), as Office JS; '' when none is set. Setting accepts a name or an id, as Paragraph. */
37
+ get style(): string;
38
+ set style(name: string);
39
+ /** The `Word.Style` value ('TableGrid'), or 'Other', as Office JS. */
40
+ get styleBuiltIn(): string;
41
+ set styleBuiltIn(value: string);
42
+ /** The number of leading rows marked as header rows (w:tblHeader), as Office JS. */
43
+ get headerRowCount(): number;
44
+ set headerRowCount(count: number);
45
+ /** The cell at a row and cell index; throws when there is none, as Office JS's getCell does. */
46
+ getCell(rowIndex: number, cellIndex: number): TableCell;
47
+ /** Adds rows at the start or the end, with the column count and widths of this table. */
48
+ addRows(location: 'Start' | 'End', rowCount: number, values?: string[][]): TableRow[];
49
+ /**
50
+ * Removes `rowCount` rows from `rowIndex` (one by default), as Office JS. While the package
51
+ * tracks changes the rows stay and take a `w:trPr/w:del` instead (CR-002 phase F).
52
+ */
53
+ deleteRows(rowIndex: number, rowCount?: number): void;
54
+ /** Removes the table from its container; tracked, every row is marked deleted instead. */
55
+ delete(): void;
56
+ /** The package's change tracker while `changeTrackingMode` is on (CR-002 phase F). */
57
+ get changeTracker(): ChangeTracker | undefined;
58
+ /** The cell this table is nested in, if any (extension). */
59
+ get parentTableCell(): TableCell | undefined;
60
+ /** The text of the table: a line per paragraph, as docx4j TextUtils (extension). */
61
+ get text(): string;
62
+ /** The column widths in twips, from the grid or from the first row (extension). */
63
+ columnWidths(): number[];
64
+ private tblPr;
65
+ }
66
+ /** A subset of Office JS `Word.TableRow` over a `w:tr`. */
67
+ export declare class TableRow {
68
+ readonly element: Element<wml.Tr>;
69
+ /** The array holding the row: the table's content, or a row-level content control's. */
70
+ readonly container: Element[];
71
+ readonly parentTable: Table;
72
+ constructor(element: Element<wml.Tr>,
73
+ /** The array holding the row: the table's content, or a row-level content control's. */
74
+ container: Element[], parentTable: Table);
75
+ get tr(): wml.Tr;
76
+ /** The row's index among the table's rows. */
77
+ get rowIndex(): number;
78
+ get cellCount(): number;
79
+ get cells(): TableCell[];
80
+ /** The text of the row's cells. */
81
+ get values(): string[];
82
+ set values(values: string[]);
83
+ /** w:tblHeader: the row repeats at the top of every page (Office JS Table.headerRowCount). */
84
+ get isHeader(): boolean;
85
+ set isHeader(header: boolean);
86
+ /** New rows before or after this one, with this table's columns. */
87
+ insertRows(location: 'Before' | 'After', rowCount: number, values?: string[][]): TableRow[];
88
+ /** Removes the row; tracked, it stays and takes a `w:trPr/w:del` (CR-002 phase F). */
89
+ delete(): void;
90
+ private trPrItem;
91
+ }
92
+ /** A subset of Office JS `Word.TableCell` over a `w:tc`: a body of its own, plus its position. */
93
+ export declare class TableCell {
94
+ readonly element: Element<wml.Tc>;
95
+ /** The array holding the cell: the row's content, or a cell-level content control's. */
96
+ readonly container: Element[];
97
+ readonly parentRow: TableRow;
98
+ constructor(element: Element<wml.Tc>,
99
+ /** The array holding the cell: the row's content, or a cell-level content control's. */
100
+ container: Element[], parentRow: TableRow);
101
+ get tc(): wml.Tc;
102
+ get parentTable(): Table;
103
+ get rowIndex(): number;
104
+ get cellIndex(): number;
105
+ /**
106
+ * The cell's content as a `Body` (Office JS TableCell.body): the same part and package as the
107
+ * table's body, addressed from the cell (`body/4/0/1`).
108
+ */
109
+ get body(): Body;
110
+ get paragraphs(): Paragraph[];
111
+ get tables(): Table[];
112
+ /** The cell's text, a line per paragraph. */
113
+ get text(): string;
114
+ /** Office JS TableCell.value: the text, replaced as one paragraph when set. */
115
+ get value(): string;
116
+ set value(text: string);
117
+ insertParagraph(text: string, location: 'Start' | 'End'): Paragraph;
118
+ insertText(text: string, location: 'Start' | 'End' | 'Replace'): Range;
119
+ /** The cell width in points (w:tcW in twips), as Office JS reports it; 0 when it is not a fixed width. */
120
+ get width(): number;
121
+ set width(points: number);
122
+ /** Office JS TableCell.columnWidth, the same value. */
123
+ get columnWidth(): number;
124
+ set columnWidth(points: number);
125
+ }
126
+ /**
127
+ * The cell a value is in, from its PARENT links; undefined when it is not in a table. Shared by
128
+ * `Paragraph.parentTableCell` and `Table.parentTableCell`.
129
+ */
130
+ export declare function cellOf(value: object, parentBody: Body): TableCell | undefined;