@docx4j/core-ts 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +4 -0
- package/README.md +32 -4
- package/dist/html/convert.mjs +2 -1
- package/dist/html/elements.mjs +2 -1
- package/dist/model/color/ColorMath.d.mts +29 -0
- package/dist/model/color/ColorMath.mjs +146 -0
- package/dist/model/color/ColorTables.d.mts +6 -0
- package/dist/model/color/ColorTables.mjs +83 -0
- package/dist/model/color/DrawingMLColors.d.mts +52 -0
- package/dist/model/color/DrawingMLColors.mjs +374 -0
- package/dist/model/color/ResolvedColor.d.mts +36 -0
- package/dist/model/color/ResolvedColor.mjs +65 -0
- package/dist/model/color/SpreadsheetColors.d.mts +36 -0
- package/dist/model/color/SpreadsheetColors.mjs +84 -0
- package/dist/model/color/StyleFill.d.mts +28 -0
- package/dist/model/color/StyleFill.mjs +21 -0
- package/dist/model/color/ThemeColors.d.mts +86 -0
- package/dist/model/color/ThemeColors.mjs +304 -0
- package/dist/model/color/WordColors.d.mts +71 -0
- package/dist/model/color/WordColors.mjs +121 -0
- package/dist/model/color/index.d.mts +6 -0
- package/dist/model/color/index.mjs +30 -0
- package/dist/model/content/Body.d.mts +145 -23
- package/dist/model/content/Body.mjs +509 -141
- package/dist/model/content/Comment.d.mts +21 -3
- package/dist/model/content/Comment.mjs +195 -19
- package/dist/model/content/ContentControl.d.mts +197 -18
- package/dist/model/content/ContentControl.mjs +664 -95
- package/dist/model/content/Font.d.mts +67 -17
- package/dist/model/content/Font.mjs +114 -35
- package/dist/model/content/InlinePicture.d.mts +11 -0
- package/dist/model/content/InlinePicture.mjs +21 -1
- package/dist/model/content/List.mjs +3 -0
- package/dist/model/content/Paragraph.d.mts +189 -13
- package/dist/model/content/Paragraph.mjs +870 -74
- package/dist/model/content/Range.d.mts +227 -12
- package/dist/model/content/Range.mjs +785 -59
- package/dist/model/content/ResolvedView.d.mts +104 -0
- package/dist/model/content/ResolvedView.mjs +596 -0
- package/dist/model/content/Table.d.mts +29 -3
- package/dist/model/content/Table.mjs +109 -33
- package/dist/model/content/TrackedChange.d.mts +172 -13
- package/dist/model/content/TrackedChange.mjs +728 -167
- package/dist/model/content/comments.d.mts +20 -6
- package/dist/model/content/comments.mjs +67 -57
- package/dist/model/content/generalException.d.mts +18 -0
- package/dist/model/content/generalException.mjs +24 -0
- package/dist/model/content/index.d.mts +8 -3
- package/dist/model/content/index.mjs +7 -2
- package/dist/model/content/mathText.d.mts +21 -0
- package/dist/model/content/mathText.mjs +267 -0
- package/dist/model/content/officeText.d.mts +27 -0
- package/dist/model/content/officeText.mjs +74 -0
- package/dist/model/content/outline.d.mts +5 -0
- package/dist/model/content/outline.mjs +13 -0
- package/dist/model/content/placeholders.d.mts +110 -0
- package/dist/model/content/placeholders.mjs +253 -0
- package/dist/model/content/search.d.mts +72 -0
- package/dist/model/content/search.mjs +204 -2
- package/dist/model/content/spanEdits.d.mts +159 -0
- package/dist/model/content/spanEdits.mjs +728 -0
- package/dist/model/content/story.d.mts +44 -0
- package/dist/model/content/story.mjs +92 -0
- package/dist/model/content/tableColumns.d.mts +1 -1
- package/dist/model/content/tableColumns.mjs +108 -80
- package/dist/model/content/tableRevisions.d.mts +11 -3
- package/dist/model/content/tableRevisions.mjs +72 -42
- package/dist/model/content/tableRules.d.mts +30 -0
- package/dist/model/content/tableRules.mjs +100 -0
- package/dist/model/content/textBoxes.d.mts +18 -0
- package/dist/model/content/textBoxes.mjs +105 -0
- package/dist/model/content/trackedChangeFilter.d.mts +39 -0
- package/dist/model/content/trackedChangeFilter.mjs +81 -0
- package/dist/model/content/tracking.d.mts +28 -0
- package/dist/model/content/tracking.mjs +149 -10
- package/dist/model/content/tree.d.mts +171 -22
- package/dist/model/content/tree.mjs +329 -53
- package/dist/model/customxml/CustomXmlPartCollection.d.mts +8 -0
- package/dist/model/customxml/CustomXmlPartCollection.mjs +34 -11
- package/dist/model/customxml/XmlMapping.d.mts +1 -1
- package/dist/model/customxml/XmlMapping.mjs +11 -0
- package/dist/model/customxml/bindings.d.mts +21 -2
- package/dist/model/customxml/bindings.mjs +76 -32
- package/dist/model/customxml/kinds.d.mts +8 -3
- package/dist/model/customxml/kinds.mjs +26 -5
- package/dist/model/customxml/picturePlaceholder.d.mts +17 -0
- package/dist/model/customxml/picturePlaceholder.mjs +32 -0
- package/dist/model/customxml/pictures.d.mts +4 -3
- package/dist/model/customxml/pictures.mjs +18 -6
- package/dist/model/customxml/xhtml.mjs +8 -2
- package/dist/model/index.d.mts +2 -0
- package/dist/model/index.mjs +4 -0
- package/dist/model/listnumbering/Emulator.d.mts +37 -5
- package/dist/model/listnumbering/Emulator.mjs +63 -9
- package/dist/model/properties/PropertyResolver.d.mts +60 -1
- package/dist/model/properties/PropertyResolver.mjs +115 -2
- package/dist/model/properties/catalogue.d.mts +19 -5
- package/dist/model/properties/catalogue.mjs +41 -15
- package/dist/model/properties/log.d.mts +1 -1
- package/dist/model/properties/log.mjs +5 -5
- package/dist/model/properties/table.mjs +4 -2
- package/dist/model/text/Extractor.d.mts +289 -0
- package/dist/model/text/Extractor.mjs +2162 -0
- package/dist/model/text/LinkTargets.d.mts +45 -0
- package/dist/model/text/LinkTargets.mjs +170 -0
- package/dist/model/text/MarkdownExporter.d.mts +140 -0
- package/dist/model/text/MarkdownExporter.mjs +255 -0
- package/dist/model/text/PlainText.d.mts +29 -0
- package/dist/model/text/PlainText.mjs +539 -0
- package/dist/model/text/TextContext.d.mts +161 -0
- package/dist/model/text/TextContext.mjs +425 -0
- package/dist/model/text/TextOptions.d.mts +150 -0
- package/dist/model/text/TextOptions.mjs +278 -0
- package/dist/model/text/TextResult.d.mts +504 -0
- package/dist/model/text/TextResult.mjs +526 -0
- package/dist/model/text/Texts.d.mts +99 -0
- package/dist/model/text/Texts.mjs +187 -0
- package/dist/model/text/WmlToMarkdown.d.mts +120 -0
- package/dist/model/text/WmlToMarkdown.mjs +911 -0
- package/dist/model/text/commonmark.d.mts +121 -0
- package/dist/model/text/commonmark.mjs +655 -0
- package/dist/model/text/index.d.mts +7 -0
- package/dist/model/text/index.mjs +8 -0
- package/dist/model/text/normalize.d.mts +8 -0
- package/dist/model/text/normalize.mjs +13 -0
- package/dist/model/text/outline.d.mts +4 -0
- package/dist/model/text/outline.mjs +71 -0
- package/dist/office-js/fragment.d.mts +7 -5
- package/dist/office-js/fragment.mjs +63 -14
- package/dist/office-js/proxy.d.mts +8 -0
- package/dist/office-js/proxy.mjs +29 -0
- package/dist/office-js/run.mjs +2 -0
- package/dist/office-js/supported.generated.mjs +16 -0
- package/dist/office-js/toApiScript.mjs +21 -5
- package/dist/opc/Save.d.mts +17 -0
- package/dist/opc/Save.mjs +12 -2
- package/dist/opc/index.d.mts +3 -3
- package/dist/opc/index.mjs +1 -1
- package/dist/opc/mce/preprocessor.d.mts +28 -3
- package/dist/opc/mce/preprocessor.mjs +4 -4
- package/dist/opc/mce/understood.d.mts +30 -6
- package/dist/opc/mce/understood.mjs +37 -7
- package/dist/packages/OpcPackage.d.mts +13 -0
- package/dist/packages/OpcPackage.mjs +1 -0
- package/dist/packages/WordprocessingMLPackage.d.mts +45 -8
- package/dist/packages/WordprocessingMLPackage.mjs +155 -20
- package/dist/parts/DefaultXmlPart.mjs +2 -2
- package/dist/parts/Part.d.mts +10 -2
- package/dist/parts/XmlPart.d.mts +12 -30
- package/dist/parts/XmlPart.mjs +44 -93
- package/dist/parts/wml/comments.mjs +30 -0
- package/dist/parts/wml/index.mjs +12 -0
- package/dist/xml/dom.d.mts +7 -0
- package/dist/xml/dom.mjs +18 -0
- package/package.json +2 -2
package/dist/parts/XmlPart.mjs
CHANGED
|
@@ -1,24 +1,8 @@
|
|
|
1
1
|
import { unmarshalNode, marshalNode, NAMESPACE_PREFIXES } from '@docx4j/generated-objects-ts';
|
|
2
2
|
import { Part } from './Part.mjs';
|
|
3
|
-
import { Namespaces } from './Namespaces.mjs';
|
|
4
3
|
import { Docx4JException, PartUnmarshalException } from '../opc/exceptions.mjs';
|
|
5
|
-
import { parseXml, serializeXml, encodeText, decodeXmlText, XML_DECLARATION } from '../xml/dom.mjs';
|
|
6
|
-
import { log } from '../model/properties/log.mjs';
|
|
4
|
+
import { parseXml, serializeXml, encodeText, decodeXmlText, XML_DECLARATION, assertXmlCharacters } from '../xml/dom.mjs';
|
|
7
5
|
import { bindSnapshot, boundsOf } from '../model/content/binder.mjs';
|
|
8
|
-
const XMLNS_NS = 'http://www.w3.org/2000/xmlns/';
|
|
9
|
-
const MC_NS = Namespaces.MARKUP_COMPATIBILITY;
|
|
10
|
-
/** The objects package's prefix table the other way round, prefix to URI, built once. */
|
|
11
|
-
let prefixToUri;
|
|
12
|
-
function knownUriOf(prefix) {
|
|
13
|
-
if (prefixToUri === undefined) {
|
|
14
|
-
prefixToUri = new Map();
|
|
15
|
-
for (const [uri, p] of Object.entries(NAMESPACE_PREFIXES))
|
|
16
|
-
if (p !== '' && !prefixToUri.has(p))
|
|
17
|
-
prefixToUri.set(p, uri);
|
|
18
|
-
}
|
|
19
|
-
return prefixToUri.get(prefix);
|
|
20
|
-
}
|
|
21
|
-
const warnedPrefixes = new Set();
|
|
22
6
|
/**
|
|
23
7
|
* The element or attribute a located runtime error names, out of its message: jsonix writes
|
|
24
8
|
* `w:sz/@w:val (line 7): ...` when it could place the fault and `w:bogus (line 3): ...` for an
|
|
@@ -39,6 +23,22 @@ function positionOf(line, column) {
|
|
|
39
23
|
return '';
|
|
40
24
|
return column === undefined ? ` (line ${line})` : ` (line ${line}, column ${column})`;
|
|
41
25
|
}
|
|
26
|
+
/** A value the objects facade read by Word's rule, as a warning on the part (CR-015 D8). */
|
|
27
|
+
function valueKept(reading, partName) {
|
|
28
|
+
var _a, _b, _c;
|
|
29
|
+
const node = reading.element;
|
|
30
|
+
const name = reading.attribute;
|
|
31
|
+
const attribute = (_c = (_b = (_a = node.getAttributeNodeNS) === null || _a === void 0 ? void 0 : _a.call(node, name.namespaceURI || null, name.localPart)) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : name.localPart;
|
|
32
|
+
const value = reading.value;
|
|
33
|
+
const read = value === true ? 'on' : value === undefined ? 'absent' : JSON.stringify(value);
|
|
34
|
+
return {
|
|
35
|
+
code: reading.kind, partName,
|
|
36
|
+
...(typeof node.lineNumber === 'number' ? { line: node.lineNumber } : {}),
|
|
37
|
+
...(typeof node.columnNumber === 'number' ? { column: node.columnNumber } : {}),
|
|
38
|
+
element: node.nodeName, attribute, text: reading.text, value,
|
|
39
|
+
message: `${partName}: ${node.nodeName}/@${attribute}=${JSON.stringify(reading.text)}${positionOf(node.lineNumber, node.columnNumber)} is not a value its type allows; read as ${read}, as Word 365 reads it`,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
42
|
/** The objects package's prefix table as XPath wants it, prefix to URI; built once. */
|
|
43
43
|
const NAMESPACE_PREFIXES_BY_PREFIX = (() => {
|
|
44
44
|
const out = {};
|
|
@@ -75,9 +75,10 @@ export class XmlPart extends Part {
|
|
|
75
75
|
return this.element === undefined && this.bytes === undefined;
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
|
-
* What the
|
|
79
|
-
*
|
|
80
|
-
*
|
|
78
|
+
* What the last parse of this part reported: an mc:AlternateContent whose branches' text differs
|
|
79
|
+
* (`mce.branches_differ`, CR-010 phase 1), and each attribute value its type refuses that was read as
|
|
80
|
+
* Word 365 reads it (`value.kept.exact`, `value.kept.invalid`: CR-015 D8). Empty until the part is
|
|
81
|
+
* parsed, by `getContents()` or a private read, and again once its contents are set.
|
|
81
82
|
*/
|
|
82
83
|
get warnings() {
|
|
83
84
|
return this.parseWarnings;
|
|
@@ -100,7 +101,6 @@ export class XmlPart extends Part {
|
|
|
100
101
|
if (bytes === undefined)
|
|
101
102
|
throw new Docx4JException(`Part ${this.partName} has no content: set contents or load it from a container`);
|
|
102
103
|
const doc = this.parse(bytes);
|
|
103
|
-
this.recordDeclarations(doc);
|
|
104
104
|
this.preprocess(doc);
|
|
105
105
|
this.element = await this.unmarshal(doc);
|
|
106
106
|
(_b = this.rootName) !== null && _b !== void 0 ? _b : (this.rootName = { namespaceURI: this.element.name.namespaceURI, localPart: this.element.name.localPart });
|
|
@@ -125,7 +125,6 @@ export class XmlPart extends Part {
|
|
|
125
125
|
if (bytes === undefined)
|
|
126
126
|
throw new Docx4JException(`Part ${this.partName} has no content: set contents or load it from a container`);
|
|
127
127
|
const doc = this.parse(bytes);
|
|
128
|
-
this.recordDeclarations(doc);
|
|
129
128
|
this.preprocess(doc);
|
|
130
129
|
return (await this.unmarshal(doc)).value;
|
|
131
130
|
}
|
|
@@ -158,9 +157,9 @@ export class XmlPart extends Part {
|
|
|
158
157
|
return decodeXmlText(await this.getBytes());
|
|
159
158
|
}
|
|
160
159
|
/** Marshalled bytes when unmarshalled or set, else the source bytes untouched. */
|
|
161
|
-
async getBytes() {
|
|
160
|
+
async getBytes(options) {
|
|
162
161
|
if (this.element !== undefined)
|
|
163
|
-
return encodeText(XML_DECLARATION + serializeXml(await this.marshalToNode()));
|
|
162
|
+
return encodeText(assertXmlCharacters(XML_DECLARATION + serializeXml(await this.marshalToNode(options)), `Part ${this.partName}`));
|
|
164
163
|
if (this.bytes !== undefined)
|
|
165
164
|
return this.bytes;
|
|
166
165
|
const loaded = await this.loadSourceBytes();
|
|
@@ -198,13 +197,22 @@ export class XmlPart extends Part {
|
|
|
198
197
|
const namespaces = { ...NAMESPACE_PREFIXES_BY_PREFIX, ...options.namespaces };
|
|
199
198
|
return boundsOf(engine.select(xpath, snapshot.root, namespaces), snapshot);
|
|
200
199
|
}
|
|
201
|
-
/**
|
|
202
|
-
|
|
200
|
+
/**
|
|
201
|
+
* The root element as a DOM element (docx4j XmlUtils.marshaltoW3CDomDocument). Run properties are written in
|
|
202
|
+
* their normal form unless the package's `normaliseOnSave` (else the objects package's `setNormaliseOnSave`) is
|
|
203
|
+
* false (CR-015 D2, the objects facade's CR-013 phase C): the tree keeps what it read.
|
|
204
|
+
*/
|
|
205
|
+
async marshalToNode(options) {
|
|
206
|
+
var _a;
|
|
203
207
|
if (this.element === undefined)
|
|
204
208
|
await this.getContents();
|
|
205
|
-
const
|
|
206
|
-
this.
|
|
207
|
-
|
|
209
|
+
const marshal = {};
|
|
210
|
+
const normalise = (_a = this.package) === null || _a === void 0 ? void 0 : _a.normaliseOnSave;
|
|
211
|
+
if (normalise !== undefined)
|
|
212
|
+
marshal.normaliseOnSave = normalise;
|
|
213
|
+
if ((options === null || options === void 0 ? void 0 : options.onNormalised) !== undefined)
|
|
214
|
+
marshal.onNormalised = options.onNormalised;
|
|
215
|
+
return marshalNode(this.element, marshal);
|
|
208
216
|
}
|
|
209
217
|
/**
|
|
210
218
|
* Parses the part's bytes, and names the part when the XML is not well-formed. xmldom's error
|
|
@@ -236,8 +244,14 @@ export class XmlPart extends Part {
|
|
|
236
244
|
*/
|
|
237
245
|
async unmarshal(doc) {
|
|
238
246
|
var _a, _b, _c, _d, _e, _f;
|
|
247
|
+
const kept = [];
|
|
239
248
|
try {
|
|
240
|
-
|
|
249
|
+
const element = await unmarshalNode(doc, {
|
|
250
|
+
onWordReading: (reading) => kept.push(valueKept(reading, this.partName.name)),
|
|
251
|
+
});
|
|
252
|
+
if (kept.length > 0)
|
|
253
|
+
this.parseWarnings = [...this.parseWarnings, ...kept];
|
|
254
|
+
return element;
|
|
241
255
|
}
|
|
242
256
|
catch (cause) {
|
|
243
257
|
const located = cause;
|
|
@@ -256,67 +270,4 @@ export class XmlPart extends Part {
|
|
|
256
270
|
throw new PartUnmarshalException(`${this.partName}: ${detail}`, this.partName.name, { cause, location, line, column });
|
|
257
271
|
}
|
|
258
272
|
}
|
|
259
|
-
/** The source root element's namespace declarations, prefix to URI (`xmlns=` is the empty prefix). */
|
|
260
|
-
recordDeclarations(doc) {
|
|
261
|
-
var _a;
|
|
262
|
-
const root = doc.documentElement;
|
|
263
|
-
if (!root)
|
|
264
|
-
return;
|
|
265
|
-
const map = new Map();
|
|
266
|
-
for (const attr of Array.from(root.attributes)) {
|
|
267
|
-
if (attr.name === 'xmlns')
|
|
268
|
-
map.set('', attr.value);
|
|
269
|
-
else if (attr.namespaceURI === XMLNS_NS || attr.name.startsWith('xmlns:'))
|
|
270
|
-
map.set((_a = attr.localName) !== null && _a !== void 0 ? _a : attr.name.slice(6), attr.value);
|
|
271
|
-
}
|
|
272
|
-
this.sourceDeclarations = map;
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Every prefix the marshalled root's `mc:Ignorable` names must be declared on that root
|
|
276
|
-
* (ECMA-376 Part 3 10.1.2; Word and Excel treat an undeclared one as a corrupt part and offer
|
|
277
|
-
* to repair the file). The object model binds only the namespaces it has modules for, so an
|
|
278
|
-
* `mc:Ignorable` prefix whose content was dropped on unmarshal - `xr6`, `xr10` and `xr2` on
|
|
279
|
-
* Excel's `xl/workbook.xml`, for instance - loses its declaration: the runtime declares one
|
|
280
|
-
* prefix per entry of the objects package's table and the facade can only *remove* unused
|
|
281
|
-
* declarations, never add one it never made (CR-001 section 17).
|
|
282
|
-
*
|
|
283
|
-
* So the part re-declares them itself: from what the source root declared, else from the
|
|
284
|
-
* objects package's `NAMESPACE_PREFIXES`. A prefix neither knows is dropped from
|
|
285
|
-
* `mc:Ignorable` - an undeclared prefix is the one thing that must not be written - and warned
|
|
286
|
-
* about once.
|
|
287
|
-
*/
|
|
288
|
-
declareIgnorablePrefixes(root) {
|
|
289
|
-
var _a, _b;
|
|
290
|
-
const attr = Array.from(root.attributes).find((a) => { var _a; return a.namespaceURI === MC_NS && ((_a = a.localName) !== null && _a !== void 0 ? _a : a.name) === 'Ignorable'; });
|
|
291
|
-
if (!attr)
|
|
292
|
-
return;
|
|
293
|
-
const prefixes = attr.value.split(/\s+/).filter((p) => p !== '');
|
|
294
|
-
if (prefixes.length === 0)
|
|
295
|
-
return;
|
|
296
|
-
const kept = [];
|
|
297
|
-
let dropped = false;
|
|
298
|
-
for (const prefix of prefixes) {
|
|
299
|
-
if (root.getAttributeNS(XMLNS_NS, prefix) || root.getAttribute(`xmlns:${prefix}`)) {
|
|
300
|
-
kept.push(prefix);
|
|
301
|
-
continue;
|
|
302
|
-
}
|
|
303
|
-
const uri = (_b = (_a = this.sourceDeclarations) === null || _a === void 0 ? void 0 : _a.get(prefix)) !== null && _b !== void 0 ? _b : knownUriOf(prefix);
|
|
304
|
-
if (uri === undefined) {
|
|
305
|
-
dropped = true;
|
|
306
|
-
if (!warnedPrefixes.has(prefix)) {
|
|
307
|
-
warnedPrefixes.add(prefix);
|
|
308
|
-
log.warn(`${this.partName}: mc:Ignorable names the prefix "${prefix}", which nothing declares; dropping it (an undeclared prefix makes Word and Excel offer to repair the file)`);
|
|
309
|
-
}
|
|
310
|
-
continue;
|
|
311
|
-
}
|
|
312
|
-
root.setAttributeNS(XMLNS_NS, `xmlns:${prefix}`, uri);
|
|
313
|
-
kept.push(prefix);
|
|
314
|
-
}
|
|
315
|
-
if (!dropped)
|
|
316
|
-
return;
|
|
317
|
-
if (kept.length === 0)
|
|
318
|
-
root.removeAttributeNode(attr);
|
|
319
|
-
else
|
|
320
|
-
root.setAttributeNS(MC_NS, attr.name, kept.join(' '));
|
|
321
|
-
}
|
|
322
273
|
}
|
|
@@ -47,6 +47,36 @@ class DocumentCommentParts {
|
|
|
47
47
|
this.loadedAll = true;
|
|
48
48
|
return this;
|
|
49
49
|
}
|
|
50
|
+
async loadExisting() {
|
|
51
|
+
var _a, _b, _c;
|
|
52
|
+
const main = this.main;
|
|
53
|
+
if (main.commentsExtendedPart)
|
|
54
|
+
(_a = this.commentsEx) !== null && _a !== void 0 ? _a : (this.commentsEx = await main.commentsExtendedPart.getContents());
|
|
55
|
+
if (main.commentsIdsPart)
|
|
56
|
+
(_b = this.commentsIds) !== null && _b !== void 0 ? _b : (this.commentsIds = await main.commentsIdsPart.getContents());
|
|
57
|
+
(_c = this.extensible) !== null && _c !== void 0 ? _c : (this.extensible = await loadExtensible(main));
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
drop(people) {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
const main = this.main;
|
|
63
|
+
const parts = [main.commentsPart, main.commentsExtendedPart, main.commentsIdsPart, main.commentsExtensiblePart, people ? main.peoplePart : undefined];
|
|
64
|
+
for (const part of parts) {
|
|
65
|
+
if (!part)
|
|
66
|
+
continue;
|
|
67
|
+
const rels = main.relationshipsPart;
|
|
68
|
+
const rel = rels === null || rels === void 0 ? void 0 : rels.getRel(part.partName);
|
|
69
|
+
if (rel)
|
|
70
|
+
rels.removeRelationship(rel);
|
|
71
|
+
if (part.sourceRelationships.length > 0)
|
|
72
|
+
continue;
|
|
73
|
+
(_a = part.relationshipsPart) === null || _a === void 0 ? void 0 : _a.removeParts();
|
|
74
|
+
(_b = part.package) === null || _b === void 0 ? void 0 : _b.parts.remove(part.partName);
|
|
75
|
+
}
|
|
76
|
+
main.commentsPart = main.commentsExtendedPart = main.commentsIdsPart = main.commentsExtensiblePart = undefined;
|
|
77
|
+
if (people)
|
|
78
|
+
main.peoplePart = undefined;
|
|
79
|
+
}
|
|
50
80
|
}
|
|
51
81
|
/** The document part a body's comments belong to: the body's own part, else the package's main part. */
|
|
52
82
|
function mainPartOf(body) {
|
package/dist/parts/wml/index.mjs
CHANGED
|
@@ -23,6 +23,15 @@ async function ensurePropertyResolver(part) {
|
|
|
23
23
|
const pkg = part.package;
|
|
24
24
|
await ((_a = pkg === null || pkg === void 0 ? void 0 : pkg.getPropertyResolver) === null || _a === void 0 ? void 0 : _a.call(pkg));
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* The glossary's placeholder entries, read privately, which `ContentControl.placeholderText` reads synchronously
|
|
28
|
+
* (CR-002 section 63, D8).
|
|
29
|
+
*/
|
|
30
|
+
async function ensureGlossaryEntries(part) {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
const pkg = part.package;
|
|
33
|
+
await ((_a = pkg === null || pkg === void 0 ? void 0 : pkg.glossaryEntries) === null || _a === void 0 ? void 0 : _a.load((_b = pkg.mainDocumentPart) === null || _b === void 0 ? void 0 : _b.glossaryDocumentPart));
|
|
34
|
+
}
|
|
26
35
|
/** The Body view of a part's block-level container, one per container object. */
|
|
27
36
|
function bodyOf(part, container, prefix) {
|
|
28
37
|
if (!container)
|
|
@@ -124,6 +133,7 @@ export class MainDocumentPart extends DocumentPart {
|
|
|
124
133
|
async getBody() {
|
|
125
134
|
await this.getContents();
|
|
126
135
|
await ensurePropertyResolver(this);
|
|
136
|
+
await ensureGlossaryEntries(this);
|
|
127
137
|
return this.body;
|
|
128
138
|
}
|
|
129
139
|
/**
|
|
@@ -439,6 +449,7 @@ export class HeaderPart extends XmlPart {
|
|
|
439
449
|
async getBody() {
|
|
440
450
|
await this.getContents();
|
|
441
451
|
await ensurePropertyResolver(this);
|
|
452
|
+
await ensureGlossaryEntries(this);
|
|
442
453
|
return this.body;
|
|
443
454
|
}
|
|
444
455
|
}
|
|
@@ -454,6 +465,7 @@ export class FooterPart extends XmlPart {
|
|
|
454
465
|
async getBody() {
|
|
455
466
|
await this.getContents();
|
|
456
467
|
await ensurePropertyResolver(this);
|
|
468
|
+
await ensureGlossaryEntries(this);
|
|
457
469
|
return this.body;
|
|
458
470
|
}
|
|
459
471
|
}
|
package/dist/xml/dom.d.mts
CHANGED
|
@@ -14,6 +14,13 @@ export declare function parseXml(text: string): Document;
|
|
|
14
14
|
/** Serialises a node (document or element) without an XML declaration. */
|
|
15
15
|
export declare function serializeXml(node: Node): string;
|
|
16
16
|
export declare function createDocument(): Document;
|
|
17
|
+
/**
|
|
18
|
+
* The XML, refused where it holds a character XML 1.0 excludes, which no escape can write (CR-002 section 60 D3): the
|
|
19
|
+
* part would not be well-formed, and a conforming parser must refuse it. The content API's writers drop such characters
|
|
20
|
+
* or write them as their elements; this catches what reached the tree some other way (an attribute, a custom XML
|
|
21
|
+
* node's value, a caller's own edit of the tree).
|
|
22
|
+
*/
|
|
23
|
+
export declare function assertXmlCharacters(xml: string, where: string): string;
|
|
17
24
|
/** XML declaration plus the serialised document element, as one string. */
|
|
18
25
|
export declare function serializeXmlPart(node: Node): string;
|
|
19
26
|
/** UTF-8 bytes of a string. */
|
package/dist/xml/dom.mjs
CHANGED
|
@@ -59,6 +59,24 @@ export function serializeXml(node) {
|
|
|
59
59
|
export function createDocument() {
|
|
60
60
|
return DOM.createDocument();
|
|
61
61
|
}
|
|
62
|
+
/** A character XML 1.0 excludes: a C0 control but tab, line feed and carriage return, U+FFFE, U+FFFF, an unpaired surrogate. */
|
|
63
|
+
const NOT_XML = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
|
|
64
|
+
/**
|
|
65
|
+
* The XML, refused where it holds a character XML 1.0 excludes, which no escape can write (CR-002 section 60 D3): the
|
|
66
|
+
* part would not be well-formed, and a conforming parser must refuse it. The content API's writers drop such characters
|
|
67
|
+
* or write them as their elements; this catches what reached the tree some other way (an attribute, a custom XML
|
|
68
|
+
* node's value, a caller's own edit of the tree).
|
|
69
|
+
*/
|
|
70
|
+
export function assertXmlCharacters(xml, where) {
|
|
71
|
+
const m = NOT_XML.exec(xml);
|
|
72
|
+
if (m) {
|
|
73
|
+
const code = m[0].charCodeAt(0).toString(16).toUpperCase().padStart(4, '0');
|
|
74
|
+
const before = xml.slice(Math.max(0, m.index - 40), m.index).replace(/[^\x20-\x7e]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, '0')}`);
|
|
75
|
+
throw new Docx4JException(`${where} holds U+${code}, which XML 1.0 excludes, so it can't be written as well-formed XML `
|
|
76
|
+
+ `(character ${m.index}, after "${before}"); remove it, or write it as the element it stands for (CR-002 section 60)`);
|
|
77
|
+
}
|
|
78
|
+
return xml;
|
|
79
|
+
}
|
|
62
80
|
/** XML declaration plus the serialised document element, as one string. */
|
|
63
81
|
export function serializeXmlPart(node) {
|
|
64
82
|
const el = node.nodeType === 9 ? node.documentElement : node;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docx4j/core-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "docx4j-core for TypeScript: Open Packaging (docx/pptx/xlsx zip and flat OPC), typed parts and relationships, style, numbering and font resolution over @docx4j/generated-objects-ts. Node, browsers, Word add-ins.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
},
|
|
84
84
|
"license": "Apache-2.0",
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@docx4j/generated-objects-ts": "^0.
|
|
86
|
+
"@docx4j/generated-objects-ts": "^0.5.0",
|
|
87
87
|
"fflate": "^0.8.2"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|