@docx4j/core-ts 0.1.5 → 0.2.1
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/README.md +81 -0
- package/dist/model/content/Body.d.mts +36 -2
- package/dist/model/content/Body.mjs +79 -4
- package/dist/model/content/Comment.d.mts +15 -5
- package/dist/model/content/Comment.mjs +70 -22
- package/dist/model/content/List.d.mts +13 -2
- package/dist/model/content/List.mjs +48 -9
- package/dist/model/content/Paragraph.d.mts +11 -1
- package/dist/model/content/Paragraph.mjs +37 -21
- package/dist/model/content/Range.d.mts +36 -5
- package/dist/model/content/Range.mjs +97 -26
- package/dist/model/content/binder.d.mts +44 -0
- package/dist/model/content/binder.mjs +128 -0
- package/dist/model/content/comments.d.mts +19 -1
- package/dist/model/content/index.d.mts +5 -3
- package/dist/model/content/index.mjs +3 -1
- package/dist/model/content/search.d.mts +27 -2
- package/dist/model/content/search.mjs +59 -3
- package/dist/model/content/stylesFacade.d.mts +37 -0
- package/dist/model/content/stylesFacade.mjs +114 -0
- package/dist/model/content/tracking.d.mts +57 -2
- package/dist/model/content/tracking.mjs +47 -15
- package/dist/model/customxml/CustomXmlPartCollection.d.mts +7 -0
- package/dist/model/customxml/CustomXmlPartCollection.mjs +40 -6
- package/dist/model/customxml/xpath.d.mts +18 -3
- package/dist/model/customxml/xpath.mjs +18 -3
- package/dist/office-js/index.d.mts +3 -1
- package/dist/office-js/run.d.mts +12 -2
- package/dist/office-js/run.mjs +8 -1
- package/dist/office-js/shimmed.d.mts +46 -0
- package/dist/office-js/shimmed.mjs +1 -0
- package/dist/opc/exceptions.d.mts +25 -0
- package/dist/opc/exceptions.mjs +20 -0
- package/dist/opc/index.d.mts +1 -1
- package/dist/opc/index.mjs +1 -1
- package/dist/opc/mce/understood.mjs +37 -8
- package/dist/packages/WordprocessingMLPackage.d.mts +105 -3
- package/dist/packages/WordprocessingMLPackage.mjs +165 -2
- package/dist/parts/XmlPart.d.mts +44 -0
- package/dist/parts/XmlPart.mjs +86 -3
- package/dist/parts/sml/index.d.mts +9 -8
- package/dist/parts/sml/index.mjs +23 -19
- package/dist/parts/wml/index.d.mts +10 -2
- package/dist/parts/wml/index.mjs +11 -3
- package/dist/parts/wml/spliceableStyles.d.mts +1 -0
- package/dist/parts/wml/spliceableStyles.mjs +122 -0
- package/dist/xml/dom.d.mts +10 -1
- package/dist/xml/dom.mjs +46 -2
- package/package.json +2 -2
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// The style definitions docx4j's own `styles.xml` carries but leaves **commented out**, so that
|
|
2
|
+
// `createPackage()` - which writes that file verbatim (`DEFAULT_STYLES_XML`, generated, faithful to
|
|
3
|
+
// docx4j) - produces a document without them. `pkg.styles.ensure(ids)` splices them in when a caller
|
|
4
|
+
// needs one: inserting a footnote into such a document otherwise shows the note in Normal
|
|
5
|
+
// (CR-002 section 22.2).
|
|
6
|
+
//
|
|
7
|
+
// Taken verbatim from the two comments in
|
|
8
|
+
// docx4j-core/src/main/resources/org/docx4j/openpackaging/parts/WordprocessingML/styles.xml
|
|
9
|
+
// (a UTF-16 file; docx4j VERSION_17_3_0), which is where Word's own definitions of these came from.
|
|
10
|
+
// 9 styles: BlockText, EndnoteText, EndnoteTextChar, Footer, FooterChar, FootnoteText, FootnoteTextChar, FootnoteReference, EndnoteReference.
|
|
11
|
+
export const SPLICEABLE_STYLES_XML = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
12
|
+
<w:styles xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
|
|
13
|
+
<w:style w:type="paragraph" w:styleId="BlockText">
|
|
14
|
+
<w:name w:val="Block Text" />
|
|
15
|
+
<w:basedOn w:val="Normal" />
|
|
16
|
+
<w:uiPriority w:val="99" />
|
|
17
|
+
<w:unhideWhenUsed />
|
|
18
|
+
<w:rsid w:val="00841CD9" />
|
|
19
|
+
<w:pPr>
|
|
20
|
+
<w:pBdr>
|
|
21
|
+
<w:top w:val="single" w:sz="2" w:space="10" w:color="4F81BD" w:themeColor="accent1" w:shadow="1" />
|
|
22
|
+
<w:left w:val="single" w:sz="2" w:space="10" w:color="4F81BD" w:themeColor="accent1" w:shadow="1" />
|
|
23
|
+
<w:bottom w:val="single" w:sz="2" w:space="10" w:color="4F81BD" w:themeColor="accent1" w:shadow="1" />
|
|
24
|
+
<w:right w:val="single" w:sz="2" w:space="10" w:color="4F81BD" w:themeColor="accent1" w:shadow="1" />
|
|
25
|
+
</w:pBdr>
|
|
26
|
+
<w:ind w:left="1152" w:right="1152" />
|
|
27
|
+
</w:pPr>
|
|
28
|
+
<w:rPr>
|
|
29
|
+
<w:rFonts w:eastAsiaTheme="minorEastAsia" />
|
|
30
|
+
<w:i />
|
|
31
|
+
<w:iCs />
|
|
32
|
+
<w:color w:val="4F81BD" w:themeColor="accent1" />
|
|
33
|
+
</w:rPr>
|
|
34
|
+
</w:style>
|
|
35
|
+
<w:style w:type="paragraph" w:styleId="EndnoteText">
|
|
36
|
+
<w:name w:val="endnote text" />
|
|
37
|
+
<w:basedOn w:val="Normal" />
|
|
38
|
+
<w:link w:val="EndnoteTextChar" />
|
|
39
|
+
<w:uiPriority w:val="99" />
|
|
40
|
+
<w:unhideWhenUsed />
|
|
41
|
+
<w:rsid w:val="00841CD9" />
|
|
42
|
+
<w:rPr>
|
|
43
|
+
<w:sz w:val="20" />
|
|
44
|
+
<w:szCs w:val="20" />
|
|
45
|
+
</w:rPr>
|
|
46
|
+
</w:style>
|
|
47
|
+
<w:style w:type="character" w:customStyle="1" w:styleId="EndnoteTextChar">
|
|
48
|
+
<w:name w:val="Endnote Text Char" />
|
|
49
|
+
<w:basedOn w:val="DefaultParagraphFont" />
|
|
50
|
+
<w:link w:val="EndnoteText" />
|
|
51
|
+
<w:uiPriority w:val="99" />
|
|
52
|
+
<w:rsid w:val="00841CD9" />
|
|
53
|
+
<w:rPr>
|
|
54
|
+
<w:sz w:val="20" />
|
|
55
|
+
<w:szCs w:val="20" />
|
|
56
|
+
</w:rPr>
|
|
57
|
+
</w:style>
|
|
58
|
+
<w:style w:type="paragraph" w:styleId="Footer">
|
|
59
|
+
<w:name w:val="footer" />
|
|
60
|
+
<w:basedOn w:val="Normal" />
|
|
61
|
+
<w:link w:val="FooterChar" />
|
|
62
|
+
<w:uiPriority w:val="99" />
|
|
63
|
+
<w:unhideWhenUsed />
|
|
64
|
+
<w:rsid w:val="00841CD9" />
|
|
65
|
+
<w:pPr>
|
|
66
|
+
<w:tabs>
|
|
67
|
+
<w:tab w:val="center" w:pos="4680" />
|
|
68
|
+
<w:tab w:val="right" w:pos="9360" />
|
|
69
|
+
</w:tabs>
|
|
70
|
+
</w:pPr>
|
|
71
|
+
</w:style>
|
|
72
|
+
<w:style w:type="character" w:customStyle="1" w:styleId="FooterChar">
|
|
73
|
+
<w:name w:val="Footer Char" />
|
|
74
|
+
<w:basedOn w:val="DefaultParagraphFont" />
|
|
75
|
+
<w:link w:val="Footer" />
|
|
76
|
+
<w:uiPriority w:val="99" />
|
|
77
|
+
<w:rsid w:val="00841CD9" />
|
|
78
|
+
</w:style>
|
|
79
|
+
<w:style w:type="paragraph" w:styleId="FootnoteText">
|
|
80
|
+
<w:name w:val="footnote text" />
|
|
81
|
+
<w:basedOn w:val="Normal" />
|
|
82
|
+
<w:link w:val="FootnoteTextChar" />
|
|
83
|
+
<w:uiPriority w:val="99" />
|
|
84
|
+
<w:unhideWhenUsed />
|
|
85
|
+
<w:rsid w:val="00841CD9" />
|
|
86
|
+
<w:rPr>
|
|
87
|
+
<w:sz w:val="20" />
|
|
88
|
+
<w:szCs w:val="20" />
|
|
89
|
+
</w:rPr>
|
|
90
|
+
</w:style>
|
|
91
|
+
<w:style w:type="character" w:customStyle="1" w:styleId="FootnoteTextChar">
|
|
92
|
+
<w:name w:val="Footnote Text Char" />
|
|
93
|
+
<w:basedOn w:val="DefaultParagraphFont" />
|
|
94
|
+
<w:link w:val="FootnoteText" />
|
|
95
|
+
<w:uiPriority w:val="99" />
|
|
96
|
+
<w:rsid w:val="00841CD9" />
|
|
97
|
+
<w:rPr>
|
|
98
|
+
<w:sz w:val="20" />
|
|
99
|
+
<w:szCs w:val="20" />
|
|
100
|
+
</w:rPr>
|
|
101
|
+
</w:style>
|
|
102
|
+
<w:style w:type="character" w:styleId="FootnoteReference">
|
|
103
|
+
<w:name w:val="footnote reference" />
|
|
104
|
+
<w:basedOn w:val="DefaultParagraphFont" />
|
|
105
|
+
<w:uiPriority w:val="99" />
|
|
106
|
+
<w:unhideWhenUsed />
|
|
107
|
+
<w:rsid w:val="00D1197D" />
|
|
108
|
+
<w:rPr>
|
|
109
|
+
<w:vertAlign w:val="superscript" />
|
|
110
|
+
</w:rPr>
|
|
111
|
+
</w:style>
|
|
112
|
+
<w:style w:type="character" w:styleId="EndnoteReference">
|
|
113
|
+
<w:name w:val="endnote reference" />
|
|
114
|
+
<w:basedOn w:val="DefaultParagraphFont" />
|
|
115
|
+
<w:uiPriority w:val="99" />
|
|
116
|
+
<w:unhideWhenUsed />
|
|
117
|
+
<w:rsid w:val="00D1197D" />
|
|
118
|
+
<w:rPr>
|
|
119
|
+
<w:vertAlign w:val="superscript" />
|
|
120
|
+
</w:rPr>
|
|
121
|
+
</w:style>
|
|
122
|
+
</w:styles>`;
|
package/dist/xml/dom.d.mts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
/** The declaration docx4j writes on every XML part. */
|
|
2
2
|
export declare const XML_DECLARATION = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Parses XML text to a DOM document; throws on malformed input, in a browser as in Node.
|
|
5
|
+
*
|
|
6
|
+
* xmldom throws. A browser's `DOMParser` does not: Chromium returns the document up to the error
|
|
7
|
+
* with an XHTML `parsererror` element first in the root, and Firefox a `parsererror` root in its
|
|
8
|
+
* own namespace, and handing that on unmarshalled a truncated part without complaint - a settings
|
|
9
|
+
* part with a stray `<` kept its first child and lost the rest, which a save would have written
|
|
10
|
+
* (CR-002 section 33). Such a document is refused here, with the parser's own message, which
|
|
11
|
+
* carries the line and column in both browsers.
|
|
12
|
+
*/
|
|
4
13
|
export declare function parseXml(text: string): Document;
|
|
5
14
|
/** Serialises a node (document or element) without an XML declaration. */
|
|
6
15
|
export declare function serializeXml(node: Node): string;
|
package/dist/xml/dom.mjs
CHANGED
|
@@ -1,12 +1,56 @@
|
|
|
1
1
|
// DOM, text and base64 helpers over the runtime's DOM implementation. In Node the runtime brings
|
|
2
2
|
// @xmldom/xmldom; in browsers it uses the native DOM. Jsonix.DOM is typed since @docx4j/jsonix 3.2.1.
|
|
3
3
|
import { Jsonix } from '@docx4j/generated-objects-ts';
|
|
4
|
+
import { Docx4JException } from '../opc/exceptions.mjs';
|
|
4
5
|
const DOM = Jsonix.DOM;
|
|
5
6
|
/** The declaration docx4j writes on every XML part. */
|
|
6
7
|
export const XML_DECLARATION = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
7
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Parses XML text to a DOM document; throws on malformed input, in a browser as in Node.
|
|
10
|
+
*
|
|
11
|
+
* xmldom throws. A browser's `DOMParser` does not: Chromium returns the document up to the error
|
|
12
|
+
* with an XHTML `parsererror` element first in the root, and Firefox a `parsererror` root in its
|
|
13
|
+
* own namespace, and handing that on unmarshalled a truncated part without complaint - a settings
|
|
14
|
+
* part with a stray `<` kept its first child and lost the rest, which a save would have written
|
|
15
|
+
* (CR-002 section 33). Such a document is refused here, with the parser's own message, which
|
|
16
|
+
* carries the line and column in both browsers.
|
|
17
|
+
*/
|
|
8
18
|
export function parseXml(text) {
|
|
9
|
-
|
|
19
|
+
const doc = DOM.parse(text);
|
|
20
|
+
const error = parserErrorOf(doc);
|
|
21
|
+
if (error !== undefined)
|
|
22
|
+
throw new Docx4JException(`Malformed XML: ${error}`);
|
|
23
|
+
return doc;
|
|
24
|
+
}
|
|
25
|
+
/** The namespaces a browser puts its `parsererror` element in: Chromium and WebKit's, Firefox's. */
|
|
26
|
+
const PARSER_ERROR_NAMESPACES = new Set([
|
|
27
|
+
'http://www.w3.org/1999/xhtml',
|
|
28
|
+
'http://www.mozilla.org/newlayout/xml/parsererror.xml',
|
|
29
|
+
]);
|
|
30
|
+
/**
|
|
31
|
+
* The message of a browser's `parsererror` document - the root, or the root's first element child,
|
|
32
|
+
* named `parsererror` in one of the parser-error namespaces - or undefined for a document that
|
|
33
|
+
* parsed. Chromium's message is the `div` in its element; its `h3`s are boilerplate.
|
|
34
|
+
*/
|
|
35
|
+
function parserErrorOf(doc) {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
const root = doc.documentElement;
|
|
38
|
+
if (!root)
|
|
39
|
+
return undefined;
|
|
40
|
+
let first = null;
|
|
41
|
+
for (let child = root.firstChild; child; child = child.nextSibling) {
|
|
42
|
+
if (child.nodeType === 1) {
|
|
43
|
+
first = child;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
for (const element of [root, first]) {
|
|
48
|
+
if (element === null || element.localName !== 'parsererror' || !PARSER_ERROR_NAMESPACES.has((_a = element.namespaceURI) !== null && _a !== void 0 ? _a : ''))
|
|
49
|
+
continue;
|
|
50
|
+
const div = element.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'div')[0];
|
|
51
|
+
return ((_b = (div !== null && div !== void 0 ? div : element).textContent) !== null && _b !== void 0 ? _b : '').replace(/\s+/g, ' ').trim() || 'the parser reported an error';
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
10
54
|
}
|
|
11
55
|
/** Serialises a node (document or element) without an XML declaration. */
|
|
12
56
|
export function serializeXml(node) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docx4j/core-ts",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
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",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
},
|
|
80
80
|
"license": "Apache-2.0",
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@docx4j/generated-objects-ts": "^0.
|
|
82
|
+
"@docx4j/generated-objects-ts": "^0.3.0",
|
|
83
83
|
"fflate": "^0.8.2"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|