@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
@@ -0,0 +1,629 @@
1
+ // The tree objects a block or run was read from: kept out of the block model's JSON (REQ-706 holds no
2
+ // tree objects; CR-012 section 4.4), so held here rather than as properties.
3
+ const blockSources = new WeakMap();
4
+ const blockJoins = new WeakMap();
5
+ const runSources = new WeakMap();
6
+ /**
7
+ * A run's revision in the `markup` view (WD REQ-706): `w:ins` and `w:moveTo` are insertions, `w:del`
8
+ * and `w:moveFrom` deletions, with their author and date as written. docx4j `TextRevision`.
9
+ */
10
+ export class TextRevision {
11
+ constructor(type, author,
12
+ /** The date as the package wrote it (`w:date`), or undefined. */
13
+ date) {
14
+ this.type = type;
15
+ this.author = author;
16
+ this.date = date;
17
+ }
18
+ equals(o) {
19
+ return o !== undefined && this.type === o.type && this.author === o.author && this.date === o.date;
20
+ }
21
+ toString() {
22
+ return this.type + (this.author === undefined ? '' : ` by ${this.author}`) + (this.date === undefined ? '' : ` ${this.date}`);
23
+ }
24
+ }
25
+ /**
26
+ * An image's description (WD REQ-514) and where it came from: the document's author, or a describer
27
+ * that generated it. Plain text writes it `[image: ...]` or `[image, generated: ...]` under
28
+ * `alt_text: true` (REQ-707). docx4j `ImageDescription`.
29
+ */
30
+ export class ImageDescription {
31
+ constructor(text, provenance) {
32
+ this.text = text;
33
+ this.provenance = provenance;
34
+ }
35
+ /** An author's description. */
36
+ static author(text) {
37
+ return new ImageDescription(text, 'AUTHOR');
38
+ }
39
+ /** A generated description. */
40
+ static generated(text) {
41
+ return new ImageDescription(text, 'GENERATED');
42
+ }
43
+ toString() {
44
+ return this.provenance === 'GENERATED' ? `generated: ${this.text}` : this.text;
45
+ }
46
+ }
47
+ /**
48
+ * A picture as the document gives it, for an `ImageDescriber` (WD REQ-514): its alt text
49
+ * (`wp:docPr/@descr`, or VML's `v:shape/@alt`), its name and title, whether it is marked decorative
50
+ * (`adec:decorative`), and its image part where the package holds one. The title is never read as text.
51
+ * docx4j `TextImage`.
52
+ */
53
+ export class TextImage {
54
+ constructor(
55
+ /**
56
+ * The alt text: `wp:docPr/@descr` (or a nested picture's `pic:cNvPr/@descr`), `''` where a DrawingML picture has
57
+ * none (the schema's default); VML `v:shape/@alt`.
58
+ */
59
+ descr,
60
+ /** `wp:docPr/@name` (`pic:cNvPr/@name`); undefined for a VML picture. */
61
+ name,
62
+ /** `wp:docPr/@title`, `''` where it has none (the schema's default); undefined for a VML picture. */
63
+ title,
64
+ /** True for a picture marked decorative (`adec:decorative val="1"` in `wp:docPr`'s extensions). */
65
+ decorative,
66
+ /** True for a VML picture (`v:shape` with `v:imagedata`). */
67
+ vml,
68
+ /**
69
+ * The image part (`a:blip/@r:embed`, else its `asvg:svgBlip`'s; `v:imagedata/@r:id`), or undefined
70
+ * for a linked or missing one.
71
+ */
72
+ part,
73
+ /** The tree object the picture is read from: a `wp:inline`, `wp:anchor`, `pic:pic` or `v:shape`. */
74
+ source) {
75
+ this.descr = descr;
76
+ this.name = name;
77
+ this.title = title;
78
+ this.decorative = decorative;
79
+ this.vml = vml;
80
+ this.part = part;
81
+ this.source = source;
82
+ }
83
+ toJSON() {
84
+ var _a;
85
+ return { descr: this.descr, name: this.name, title: this.title, decorative: this.decorative, vml: this.vml, part: (_a = this.part) === null || _a === void 0 ? void 0 : _a.partName.name };
86
+ }
87
+ }
88
+ /**
89
+ * The default `ImageDescriber` (WD REQ-514): the author's alt text, `wp:docPr/@descr`, else the
90
+ * picture's `@name`; for VML, `v:shape/@alt`; nothing for a picture marked decorative.
91
+ * docx4j `AltTextDescriber`.
92
+ */
93
+ export const AltTextDescriber = {
94
+ INSTANCE: ((image) => {
95
+ if (!image || image.decorative)
96
+ return undefined;
97
+ if (image.descr)
98
+ return ImageDescription.author(image.descr);
99
+ if (image.name)
100
+ return ImageDescription.author(image.name);
101
+ return undefined;
102
+ }),
103
+ };
104
+ /**
105
+ * A piece of a block's content (WD REQ-706): document text, or a typed item whose text, if any, the
106
+ * serialiser adds (a note reference is written `[n]` in plain text, REQ-707; it is a field of the run
107
+ * here, never text). docx4j `TextRun`.
108
+ *
109
+ * `source` and `officeOffset` are this package's (CR-012 section 4.4; WD REQ-202's emulated-API
110
+ * exemption): where the run's text was read from, and where it lies in its paragraph's `Paragraph.text`.
111
+ */
112
+ export class TextRun {
113
+ constructor(kind,
114
+ /** The text: the document's for `TEXT`, `FIELD_CODE` and `LIST_LABEL`; empty for the others. */
115
+ text,
116
+ /** The run's revision in the `markup` view; undefined in the other views and for an unrevised run. */
117
+ revision) {
118
+ this.kind = kind;
119
+ this.text = text;
120
+ this.revision = revision;
121
+ /** True for hidden text included under `hidden: true` (REQ-507). */
122
+ this.hidden = false;
123
+ /** True for a content control's placeholder text (REQ-508). */
124
+ this.placeholder = false;
125
+ /** For a note reference or mark: its number in reference order, from 1; 0 for a custom mark. */
126
+ this.noteNumber = 0;
127
+ /** For a page marker: the number of the page that begins there, from 2. */
128
+ this.pageNumber = 0;
129
+ /** Bold where its paragraph's style is not: the run's `w:b`, else its styles' (CR-046 phase 3). */
130
+ this.bold = false;
131
+ /** Italic where its paragraph's style is not. */
132
+ this.italic = false;
133
+ /** Struck through where its paragraph's style is not: `w:strike`, or `w:dstrike`, struck twice (CR-012 section 24.5). */
134
+ this.strike = false;
135
+ /** In a monospaced font where its paragraph's style is not in one. */
136
+ this.monospace = false;
137
+ /**
138
+ * Shown in capitals (`w:caps`): the run's own property, else its styles', the paragraph style's among them (the case is
139
+ * the text's, not emphasis). `text` stays the stored characters; the plain-text and Markdown writers write them in
140
+ * capitals by `language` (`CaseMapping`; WD REQ-607, CR-012 section 24).
141
+ */
142
+ this.caps = false;
143
+ /**
144
+ * In small capitals (`w:smallCaps`), folded as `caps` is, and not caps: a run under both is a caps run. The writers write
145
+ * its stored characters, unless `small_caps: upper` is set (WD REQ-607).
146
+ */
147
+ this.smallCaps = false;
148
+ /**
149
+ * The text's `w:vertAlign`, the run's own, else its styles' (WD REQ-710); `BASELINE` for a note reference, which is a
150
+ * reference (REQ-503), not a superscript.
151
+ */
152
+ this.verticalAlignment = 'BASELINE';
153
+ /** True for an equation (REQ-604). */
154
+ this.math = false;
155
+ /** True for a display equation (`m:oMathPara`). */
156
+ this.displayMath = false;
157
+ }
158
+ /** Where the run's text was read from (not in the JSON). */
159
+ get source() {
160
+ return runSources.get(this);
161
+ }
162
+ set source(value) {
163
+ if (value)
164
+ runSources.set(this, value);
165
+ else
166
+ runSources.delete(this);
167
+ }
168
+ /** Whether two runs' text can be one run: the same formatting, link and equation. */
169
+ sameFormat(o) {
170
+ return this.bold === o.bold && this.italic === o.italic && this.strike === o.strike && this.monospace === o.monospace
171
+ && this.caps === o.caps && this.smallCaps === o.smallCaps && this.verticalAlignment === o.verticalAlignment
172
+ && this.language === o.language
173
+ && this.link === o.link && this.math === o.math && this.displayMath === o.displayMath;
174
+ }
175
+ copyFormat(from) {
176
+ this.bold = from.bold;
177
+ this.italic = from.italic;
178
+ this.strike = from.strike;
179
+ this.monospace = from.monospace;
180
+ this.caps = from.caps;
181
+ this.smallCaps = from.smallCaps;
182
+ this.verticalAlignment = from.verticalAlignment;
183
+ this.language = from.language;
184
+ this.link = from.link;
185
+ this.math = from.math;
186
+ this.displayMath = from.displayMath;
187
+ }
188
+ toString() {
189
+ return this.kind + (this.text === '' ? '' : ` '${this.text}'`) + (this.revision ? ` [${this.revision.toString()}]` : '');
190
+ }
191
+ }
192
+ /**
193
+ * A field in a block (WD REQ-505): its instruction, and its cached result, undefined where it has none.
194
+ * docx4j `TextField`.
195
+ */
196
+ export class TextField {
197
+ constructor(
198
+ /** The instruction (`w:instrText`, `w:fldSimple/@instr`), as written. */
199
+ instr,
200
+ /** The cached result's text in the view; undefined for a field with none. */
201
+ result,
202
+ /** True when the result was computed under `fields: update` (REQ-506), rather than cached. */
203
+ updated = false) {
204
+ this.instr = instr;
205
+ this.result = result;
206
+ this.updated = updated;
207
+ }
208
+ toString() {
209
+ return `field{${this.instr}${this.updated ? ' => ' : ' -> '}${String(this.result)}}`;
210
+ }
211
+ }
212
+ /**
213
+ * A paragraph's numbering, as its effective `w:numPr` and the numbering definitions give it: what
214
+ * Markdown's list markers are made from (WD REQ-510, REQ-703). The label itself is the block's
215
+ * `listLabel`, under `list_labels: true`. docx4j `TextNumbering`.
216
+ */
217
+ export class TextNumbering {
218
+ constructor(
219
+ /** The `w:numId`. */
220
+ numId,
221
+ /** The level, `w:ilvl`: 0 to 8. */
222
+ level,
223
+ /** The level's `w:numFmt` value, or undefined where the definitions don't give one. */
224
+ format,
225
+ /** The level's `w:lvlText` value, or undefined. */
226
+ levelText,
227
+ /** The level's `w:start`: 1 where it has none. */
228
+ start) {
229
+ this.numId = numId;
230
+ this.level = level;
231
+ this.format = format;
232
+ this.levelText = levelText;
233
+ this.start = start;
234
+ }
235
+ /** True for a bullet level. */
236
+ get bullet() {
237
+ return this.format === 'bullet';
238
+ }
239
+ /** True for a level that is a label rather than a number: not a bullet, and its format `none` or its text with no `%n`. */
240
+ get label() {
241
+ if (this.bullet || (this.format === undefined && this.levelText === undefined))
242
+ return false;
243
+ return this.format === 'none' || this.levelText === undefined || !this.levelText.includes('%');
244
+ }
245
+ toString() {
246
+ return `${this.numId}/${this.level} ${String(this.format)} '${String(this.levelText)}' from ${this.start}${this.value === undefined ? '' : ` = ${this.value}`}`;
247
+ }
248
+ }
249
+ /**
250
+ * A table row of the block model: its cells, and whether it is a header row (`w:tblHeader`).
251
+ * docx4j `TextRow`.
252
+ */
253
+ export class TextRow {
254
+ constructor(address) {
255
+ this.address = address;
256
+ this.cells = [];
257
+ /** True for a row marked `w:tblHeader`. */
258
+ this.header = false;
259
+ }
260
+ }
261
+ /**
262
+ * A table cell of the block model: its blocks (paragraphs, and nested tables), how many grid columns it
263
+ * spans, and whether it is in a vertical merge. docx4j `TextCell`.
264
+ */
265
+ export class TextCell {
266
+ constructor(address) {
267
+ this.address = address;
268
+ this.blocks = [];
269
+ /** `w:gridSpan`, 1 by default. */
270
+ this.gridSpan = 1;
271
+ /** True for a cell continuing a vertical merge (`w:vMerge` without `restart`). */
272
+ this.mergeContinue = false;
273
+ /** True for a cell starting a vertical merge (`w:vMerge w:val="restart"`). */
274
+ this.mergeRestart = false;
275
+ }
276
+ }
277
+ /**
278
+ * A block of the block model (WD REQ-706): a paragraph, a table whose cells hold blocks, or a chart. A
279
+ * paragraph's text is its runs' in the view; what an extractor adds in plain text (note numbers, a
280
+ * table-format note, an image's bracket) is not in it, but carried as fields (REQ-707). docx4j `TextBlock`.
281
+ *
282
+ * Addresses are CR-002 section 3.3's ordinal form, on the unresolved document (REQ-405, REQ-518):
283
+ * `body/3`, `body/4/1/0/2` (a table's row 1, cell 0, block 2), `header:rId3/0`, `footnote:2/0`,
284
+ * `comment:5/0`, and what follows an anchoring paragraph is addressed from it, each kind counted apart
285
+ * (REQ-519): `body/3/textbox:0/1` (legacy WordArt too), `body/3/chart:0`, `body/3/smartart:0/1`,
286
+ * `body/3/object:0/...`, `body/7/altchunk:0/...`; the glossary's `glossary:0/1`. A paragraph joined to
287
+ * the next in the `accepted` view (a deleted mark) takes the first paragraph's address and `w14:paraId`.
288
+ */
289
+ export class TextBlock {
290
+ constructor(kind,
291
+ /** The story; not readonly, since an embedded package's or a chunk's content takes the story it is read into. */
292
+ story, address) {
293
+ this.kind = kind;
294
+ this.story = story;
295
+ this.address = address;
296
+ this.runs = [];
297
+ /** The fields whose result or instruction is in the block (REQ-505). */
298
+ this.fields = [];
299
+ /** A table's rows; empty for a paragraph. */
300
+ this.rows = [];
301
+ /** True for a hidden paragraph included under `hidden: true`: its runs and mark are hidden (REQ-507). */
302
+ this.hidden = false;
303
+ /** How many revisions (run-level revisions and paragraph marks) the block's paragraphs hold, in any view. */
304
+ this.revisions = 0;
305
+ /** True when every text run is in a monospaced font, and at least one is. */
306
+ this.monospace = false;
307
+ /** True when the paragraph has a bottom border of its own (`w:pBdr/w:bottom` in its `w:pPr`). */
308
+ this.bottomBorder = false;
309
+ /** For a note's block: the note's number in reference order; else 0. */
310
+ this.noteNumber = 0;
311
+ /** The section the block ends or is in (main story only). */
312
+ this.section = 0;
313
+ /** For a table: always written in REQ-605's simple form (an embedded workbook's sheet). */
314
+ this.simpleForm = false;
315
+ /** For a chart: its table's column headings. */
316
+ this.chartHeader = [];
317
+ /** For a chart: its table's rows. */
318
+ this.chartRows = [];
319
+ }
320
+ /**
321
+ * What the block was read from (CR-012 section 4.4; not in the JSON): a paragraph's `w:p` (a joined
322
+ * block's first, as its paraId is, REQ-405), a table's `w:tbl`, a bound control's `w:sdt`; undefined
323
+ * for a block the model makes (a chart, a WordArt line).
324
+ */
325
+ get source() {
326
+ return blockSources.get(this);
327
+ }
328
+ set source(value) {
329
+ if (value)
330
+ blockSources.set(this, value);
331
+ else
332
+ blockSources.delete(this);
333
+ }
334
+ /**
335
+ * For a paragraph the view joins to the paragraphs after it (a deleted mark in `accepted`, an inserted one
336
+ * in `original`), their addresses, in order; empty for any other block (CR-012 section 17.13; not in the JSON).
337
+ */
338
+ get joined() {
339
+ var _a;
340
+ return (_a = blockJoins.get(this)) !== null && _a !== void 0 ? _a : [];
341
+ }
342
+ set joined(value) {
343
+ if (value.length > 0)
344
+ blockJoins.set(this, value);
345
+ else
346
+ blockJoins.delete(this);
347
+ }
348
+ /** True when the block holds placeholder text (REQ-508). */
349
+ get placeholder() {
350
+ return this.runs.some((r) => r.placeholder);
351
+ }
352
+ /** True for a block in a text box (REQ-518). */
353
+ get textbox() {
354
+ return this.story === 'TEXT_BOX';
355
+ }
356
+ /** True for a paragraph whose only content is one or more pictures marked decorative (REQ-514). */
357
+ get decorative() {
358
+ let decorative = false;
359
+ for (const r of this.runs) {
360
+ if (r.kind === 'IMAGE') {
361
+ if (!r.image || !r.image.decorative)
362
+ return false;
363
+ decorative = true;
364
+ }
365
+ else if (r.kind === 'TEXT' && r.text !== '') {
366
+ return false;
367
+ }
368
+ }
369
+ return decorative;
370
+ }
371
+ /**
372
+ * The block's text in the view: its text runs (and field codes, where included); for a table, its
373
+ * rows a line apart, their cells a tab apart. No list label, note number or comment.
374
+ */
375
+ get text() {
376
+ return this.textWith((r) => r.text);
377
+ }
378
+ /** `text` with each text run's text as the function gives it (`CaseMapping.written`). */
379
+ textWith(runText) {
380
+ var _a;
381
+ if (this.kind === 'CHART') {
382
+ let out = (_a = this.chartTitle) !== null && _a !== void 0 ? _a : '';
383
+ if (this.chartHeader.length > 0)
384
+ out += (out === '' ? '' : '\n') + this.chartHeader.join('\t');
385
+ for (const row of this.chartRows)
386
+ out += `\n${row.join('\t')}`;
387
+ return out;
388
+ }
389
+ if (this.kind === 'TABLE') {
390
+ return this.rows.map((row) => row.cells.map((cell) => cell.blocks.map((b) => b.textWith(runText)).join(' ')).join('\t')).join('\n');
391
+ }
392
+ let out = '';
393
+ for (const r of this.runs)
394
+ if (r.kind === 'TEXT' || r.kind === 'FIELD_CODE')
395
+ out += runText(r);
396
+ return out;
397
+ }
398
+ /** The block model's JSON (REQ-706): the fields, the text and the flags; never a tree object. */
399
+ toJSON() {
400
+ const out = { ...this, text: this.text, placeholder: this.placeholder, textbox: this.textbox, decorative: this.decorative };
401
+ if (this.kind !== 'CHART') {
402
+ delete out.chartTitle;
403
+ delete out.chart;
404
+ delete out.chartHeader;
405
+ delete out.chartRows;
406
+ }
407
+ return out;
408
+ }
409
+ toString() {
410
+ return `${this.address} ${this.story} '${this.text}'`;
411
+ }
412
+ }
413
+ /**
414
+ * A comment (WD REQ-504): its author, date and blocks, the comment it replies to, and whether it is
415
+ * resolved (`w15:done`). Plain text renders a comment at its reference, replies after it. docx4j `TextComment`.
416
+ */
417
+ export class TextComment {
418
+ constructor(/** The comment's `w:id`. */ id) {
419
+ this.id = id;
420
+ /** True when the comment is resolved (`w15:done`). */
421
+ this.resolved = false;
422
+ this.blocks = [];
423
+ /** The replies, in the comments part's order. */
424
+ this.replies = [];
425
+ }
426
+ /** The comment's text: its blocks a line apart. */
427
+ get text() {
428
+ return this.blocks.map((b) => b.text).join('\n');
429
+ }
430
+ toJSON() {
431
+ return { id: this.id, author: this.author, initials: this.initials, date: this.date, parentId: this.parentId, resolved: this.resolved, blocks: this.blocks, replies: this.replies.map((r) => r.id) };
432
+ }
433
+ }
434
+ /**
435
+ * Where a result is not the whole document (WD section 8, REQ-801): a kind, the address it is at where
436
+ * there is one, and its selector: for `mce.branches_differ` the name of the branch selected, for
437
+ * `altchunk.not_expanded`, `content.not_read` and `image.not_described` the part's name (the chunk's since
438
+ * CR-012 section 22.2 (a), WD 0.47; it was the chunk's content type, which the warning still carries), for
439
+ * `paragraph.drop_cap_joined` the name of the part the paragraphs are in. Never the document's text (REQ-802).
440
+ * docx4j `TextWarning`.
441
+ */
442
+ export class TextWarning {
443
+ constructor(kind,
444
+ /** The address of the block it is in (REQ-518's grammar), or undefined. */
445
+ address,
446
+ /** For `mce.branches_differ`, the selected branch (`mc:Choice Requires="wps"`, `mc:Fallback`). */
447
+ branch,
448
+ /** For `altchunk.not_expanded`, the chunk's content type as the package declares it. */
449
+ contentType,
450
+ /**
451
+ * For `content.not_read`, `part.not_read` and `part.absent`, the part's name; for `image.not_described`, the image part's; for `altchunk.not_expanded`,
452
+ * the chunk's (`/word/afchunk.rtf`), so that a host can read it itself; for `paragraph.drop_cap_joined`, the part the
453
+ * paragraphs are in (`/word/document.xml`); for `package.multiple_main_parts` and `package.external_main_part`, the part
454
+ * read; for `package.relationships_namespace`, the relationships part; for `mce.nothing_selected`,
455
+ * the part holding the element.
456
+ */
457
+ partName,
458
+ /**
459
+ * What the kind says beyond its selector (REQ-801's `detail`): for `package.duplicate_entry`, the entries of the name; for
460
+ * `package.multiple_main_parts`, the relationships; for `package.external_main_part`, the first URL as written; for
461
+ * `package.relationships_namespace`, the relationships read; for `mce.nothing_selected`, the namespaces required.
462
+ */
463
+ detail) {
464
+ this.kind = kind;
465
+ this.address = address;
466
+ this.branch = branch;
467
+ this.contentType = contentType;
468
+ this.partName = partName;
469
+ this.detail = detail;
470
+ }
471
+ /**
472
+ * The selector of REQ-801: the branch, else the part's name, else the content type (a warning made without a part
473
+ * name). `altchunk.not_expanded`'s is its part name since CR-012 section 22.2 (a) (WD 0.47), its content type before.
474
+ */
475
+ get selector() {
476
+ var _a, _b;
477
+ return (_b = (_a = this.branch) !== null && _a !== void 0 ? _a : this.partName) !== null && _b !== void 0 ? _b : this.contentType;
478
+ }
479
+ /** The identity a result keeps each warning once by. */
480
+ get key() {
481
+ return [this.kind, this.address, this.branch, this.contentType, this.partName, this.detail].map((v) => v !== null && v !== void 0 ? v : '\u0000').join('\u0001');
482
+ }
483
+ toJSON() {
484
+ return { kind: this.kind, address: this.address, selector: this.selector, ...(this.detail === undefined ? {} : { detail: this.detail }) };
485
+ }
486
+ toString() {
487
+ return this.kind + (this.address === undefined ? '' : ` at ${this.address}`) + (this.branch === undefined ? '' : ` (${this.branch})`)
488
+ + (this.contentType === undefined ? '' : ` (${this.contentType})`) + (this.partName === undefined ? '' : ` (${this.partName})`);
489
+ }
490
+ }
491
+ /** Both branches of an `mc:AlternateContent` hold text, and the texts differ (REQ-307). */
492
+ TextWarning.MCE_BRANCHES_DIFFER = 'mce.branches_differ';
493
+ /**
494
+ * An `mc:AlternateContent` with Choices, none understood, and no Fallback, so it reads as absent (REQ-305): at its address,
495
+ * or with none where the walk can't meet it (a resolved load took it out, or it is a part's root). The part's name is the
496
+ * selector, and `detail` the namespaces its Choices require, as one string of URIs, empty if every prefix binds to nothing.
497
+ */
498
+ TextWarning.MCE_NOTHING_SELECTED = 'mce.nothing_selected';
499
+ /**
500
+ * An `mc:Ignorable` listing a prefix no declaration in scope binds, read as though the list didn't hold it (REQ-323, CR-030):
501
+ * once a part the reading took, no address, the part's name the selector and `detail` the prefixes, separated by spaces.
502
+ */
503
+ TextWarning.MCE_UNDECLARED_PREFIX = 'mce.undeclared_prefix';
504
+ /**
505
+ * A main document part whose root Word opens showing nothing of, read as an empty document (REQ-320, CR-028 D11): once, no
506
+ * address, the part's name the selector and `detail` the root's qualified name.
507
+ */
508
+ TextWarning.PART_UNEXPECTED_ROOT = 'part.unexpected_root';
509
+ /** A field with no cached result (REQ-505). */
510
+ TextWarning.FIELD_NO_RESULT = 'field.no_result';
511
+ /** A data-bound control whose surface differs from its bound value (REQ-509). */
512
+ TextWarning.SDT_BINDING_DIFFERS = 'sdt.binding_differs';
513
+ /** An `altChunk` not expanded (REQ-513). */
514
+ TextWarning.ALTCHUNK_NOT_EXPANDED = 'altchunk.not_expanded';
515
+ /** A chart, a SmartArt data part, or an embedded package or a part inside it, that can't be read. */
516
+ TextWarning.CONTENT_NOT_READ = 'content.not_read';
517
+ /**
518
+ * A part the reading consulted and needed for this document, but does not emit, that cannot be read (REQ-801, WD 0.66):
519
+ * a styles, numbering or settings part, a document-properties part where the metadata is written, or a custom XML store
520
+ * a binding names. The reading proceeds as for a package that lacks it; once per part, no address, the part's name the
521
+ * selector (CR-012 section 28).
522
+ */
523
+ TextWarning.PART_NOT_READ = 'part.not_read';
524
+ /**
525
+ * A part the reading needed that the package does not hold, where the reading supplies what it would have: the numbering
526
+ * part, for a numbered paragraph, counted as Word's default definition (REQ-510, WD 0.76). Once, no address, the name the
527
+ * package would have held the part under (`/word/numbering.xml`) the selector.
528
+ */
529
+ TextWarning.PART_ABSENT = 'part.absent';
530
+ /**
531
+ * A name the package's container holds more than one entry of, read from the first under `repair: 'word'`
532
+ * (REQ-206, CR-024): no address, the entry as its first copy spells it the selector, the number of entries `detail`.
533
+ */
534
+ TextWarning.PACKAGE_DUPLICATE_ENTRY = 'package.duplicate_entry';
535
+ /**
536
+ * A package with more than one officeDocument relationship, the last's target read under `repair: 'word'`
537
+ * (REQ-206's statement, CR-024 section 9): once a package, no address, that part's name the selector, the number of relationships `detail`.
538
+ */
539
+ TextWarning.PACKAGE_MULTIPLE_MAIN_PARTS = 'package.multiple_main_parts';
540
+ /**
541
+ * An `External` officeDocument relationship beside an internal one, dropped under `repair: 'all'`, a repair of this package's
542
+ * own (REQ-206's NOTE, CR-031): once a package, no address, the part read the selector, the first URL as written `detail`.
543
+ */
544
+ TextWarning.PACKAGE_EXTERNAL_MAIN_PART = 'package.external_main_part';
545
+ /**
546
+ * A relationships part in a wrong namespace, read by local name under `repair: 'word'` (REQ-801's NOTE, CR-031 section 2.3):
547
+ * once a part, no address, the relationships part's name the selector, the relationships read `detail`.
548
+ */
549
+ TextWarning.PACKAGE_RELATIONSHIPS_NAMESPACE = 'package.relationships_namespace';
550
+ /** An image the `ImageDescriber` failed to describe (REQ-514). */
551
+ TextWarning.IMAGE_NOT_DESCRIBED = 'image.not_described';
552
+ /**
553
+ * A drop cap's frame paragraph joined to the paragraph after it, two `w:p` read as one (REQ-521): at the frame paragraph's
554
+ * address (CR-012 section 24.3).
555
+ */
556
+ TextWarning.DROP_CAP_JOINED = 'paragraph.drop_cap_joined';
557
+ /**
558
+ * A text in the block model (WD sections 7.4 and 8): the blocks in reading order, the comments, the
559
+ * warnings and the metadata. Plain text (`PlainText`) and the other serialisations are written from it
560
+ * (REQ-202). docx4j `TextResult`.
561
+ */
562
+ export class TextResult {
563
+ constructor(
564
+ /** The blocks in reading order (REQ-501, REQ-502, REQ-518, REQ-606). Comments are not among them. */
565
+ blocks,
566
+ /** The comments the view includes, by `w:id`, in the comments part's order (REQ-504). */
567
+ comments,
568
+ /** The warnings raised (REQ-801), never with the document's text (REQ-802). */
569
+ warnings,
570
+ /**
571
+ * The result's metadata (REQ-801, REQ-515), whatever the options: `fields_update_on_open`, `repaired` (REQ-207), and the
572
+ * document properties under `core`, `app` and `custom`, each a record, present when the package has
573
+ * that part. Property values are document text, in the text stream only under `metadata: true`.
574
+ */
575
+ metadata,
576
+ /** The options the result was made with. */
577
+ options) {
578
+ this.blocks = blocks;
579
+ this.comments = comments;
580
+ this.warnings = warnings;
581
+ this.metadata = metadata;
582
+ this.options = options;
583
+ }
584
+ /**
585
+ * Several results as one, in the order given (CR-012 section 4.4): the blocks one after another, the
586
+ * comments together, each warning once, the metadata and options the first's. What the editor
587
+ * assembles from its per-part calls under one `TextContext`.
588
+ */
589
+ static concat(...results) {
590
+ if (results.length === 0)
591
+ throw new RangeError('TextResult.concat needs a result');
592
+ const blocks = [];
593
+ const comments = new Map();
594
+ const warnings = [];
595
+ const seen = new Set();
596
+ const metadata = {};
597
+ for (const r of results) {
598
+ blocks.push(...r.blocks);
599
+ for (const [id, c] of r.comments)
600
+ if (!comments.has(id))
601
+ comments.set(id, c);
602
+ for (const w of r.warnings)
603
+ if (!seen.has(w.key)) {
604
+ seen.add(w.key);
605
+ warnings.push(w);
606
+ }
607
+ for (const [k, v] of Object.entries(r.metadata))
608
+ if (!(k in metadata))
609
+ metadata[k] = v;
610
+ }
611
+ return new TextResult(blocks, comments, warnings, metadata, results[0].options);
612
+ }
613
+ toJSON() {
614
+ return { blocks: this.blocks, comments: Object.fromEntries(this.comments), warnings: this.warnings, metadata: this.metadata, options: this.options };
615
+ }
616
+ }
617
+ /** The metadata's key for the settings' `w:updateFields` (REQ-506, REQ-801): a boolean. */
618
+ TextResult.FIELDS_UPDATE_ON_OPEN = 'fields_update_on_open';
619
+ /**
620
+ * The metadata's key for what the load repaired (REQ-207, REQ-801; CR-031): `none`, `word` where only Word's repairs were
621
+ * followed, `own` where a repair of this package's own was made. docx4j `TextResult.REPAIRED`.
622
+ */
623
+ TextResult.REPAIRED = 'repaired';
624
+ /** The metadata's key for the core properties (REQ-515): each property's element name to its value. */
625
+ TextResult.CORE = 'core';
626
+ /** The metadata's key for the application properties (REQ-515), the statistics left out. */
627
+ TextResult.APP = 'app';
628
+ /** The metadata's key for the custom properties (REQ-515): each property's name to its typed value. */
629
+ TextResult.CUSTOM = 'custom';