@kg-ui/kg-ui-plus 0.1.46 → 0.1.48
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/dist/es/KgCopilot/CopiCanvas/index.vue.mjs +1 -1
- package/dist/es/KgCopilot/CopiCanvas/index.vue2.mjs +4 -5
- package/dist/es/KgCopilot/CopiCanvas/index.vue3.mjs +2 -2
- package/dist/es/KgCopilot/CopiCanvas/testWPS.vue.mjs +7 -0
- package/dist/es/KgCopilot/CopiCanvas/testWPS.vue2.mjs +51 -0
- package/dist/es/KgCopilot/CopiCanvas/testWPS.vue3.mjs +4 -0
- package/dist/es/KgCopilot/CopiCanvas/web-office-sdk-solution-v2.0.7.es.mjs +854 -0
- package/dist/es/KgCopilot/CopiFooter/SearchInput/InputFootTool.vue2.mjs +1 -1
- package/dist/es/KgCopilot/CopiFooter/SearchInput/SelectPluginByKey.vue2.mjs +1 -1
- package/dist/es/KgCopilot/CopiFooter/SearchInput/index.vue2.mjs +1 -1
- package/dist/es/KgCopilot/dialogue/SuggestMessage.vue2.mjs +1 -1
- package/dist/es/KgCopilot/dialogue/messageParse/readMd.vue2.mjs +3 -3
- package/dist/es/KgCopilot/historyRecord/index.vue.mjs +1 -1
- package/dist/es/KgCopilot/historyRecord/index.vue2.mjs +7 -7
- package/dist/es/KgCopilot/historyRecord/index.vue3.mjs +2 -2
- package/dist/es/KgCopilot/index.vue.mjs +1 -1
- package/dist/es/KgCopilot/index.vue2.mjs +8 -5
- package/dist/es/KgCopilot/index.vue3.mjs +2 -2
- package/dist/es/api/copilot.mjs +0 -8
- package/dist/es/directives/heighlight/index.mjs +27 -27
- package/dist/es/home/LFilter/FilterHead.vue.mjs +1 -1
- package/dist/es/node_modules/.pnpm/@vueuse_core@9.13.0_vue@3.2.45/node_modules/@vueuse/core/index.mjs +1 -3
- package/dist/es/node_modules/.pnpm/@vueuse_shared@9.13.0_vue@3.2.45/node_modules/@vueuse/shared/index.mjs +1 -52
- package/dist/es/node_modules/.pnpm/{dompurify@3.2.3 → dompurify@3.0.10}/node_modules/dompurify/dist/purify.es.mjs +91 -119
- package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/apache.mjs +0 -4
- package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/bash.mjs +2 -20
- package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/basic.mjs +1 -7
- package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/c.mjs +4 -19
- package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/css.mjs +8 -214
- package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/dart.mjs +2 -10
- package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/erlang.mjs +6 -48
- package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/go.mjs +3 -23
- package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/java.mjs +1 -3
- package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/javascript.mjs +11 -15
- package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/json.mjs +0 -1
- package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/markdown.mjs +1 -7
- package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/php.mjs +2 -16
- package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/python.mjs +1 -3
- package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/ruby.mjs +1 -1
- package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/stylus.mjs +8 -214
- package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/swift.mjs +14 -60
- package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/typescript.mjs +18 -45
- package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/lib/core.mjs +8 -8
- package/dist/es/node_modules/.pnpm/{marked@12.0.2 → marked@12.0.1}/node_modules/marked/lib/marked.esm.mjs +1 -2
- package/dist/es/store/modules/copilot.mjs +8 -2
- package/dist/es/style.css +1 -1
- package/dist/es/utils/http/index.mjs +4 -0
- package/package.json +2 -2
- package/dist/es/KgCopilot/CopiCanvas/FilePreview.vue.mjs +0 -7
- package/dist/es/KgCopilot/CopiCanvas/FilePreview.vue2.mjs +0 -295
- package/dist/es/KgCopilot/CopiCanvas/FilePreview.vue3.mjs +0 -4
- package/dist/es/KgCopilot/CopiCanvas/FileSkeletion.vue.mjs +0 -96
- package/dist/es/KgCopilot/CopiCanvas/FileSkeletion.vue2.mjs +0 -4
- package/dist/es/KgCopilot/CopiCanvas/InitWrap.vue.mjs +0 -7
- package/dist/es/KgCopilot/CopiCanvas/InitWrap.vue2.mjs +0 -41
- package/dist/es/KgCopilot/CopiCanvas/InitWrap.vue3.mjs +0 -4
- package/dist/es/_virtual/_commonjs-dynamic-modules.mjs +0 -6
- package/dist/es/_virtual/jszip.min.mjs +0 -13
- package/dist/es/assets/empty.png.mjs +0 -4
- package/dist/es/node_modules/.pnpm/@iconify-icons_ep@1.2.12/node_modules/@iconify-icons/ep/folder-opened.mjs +0 -8
- package/dist/es/node_modules/.pnpm/@iconify-icons_ri@1.2.3/node_modules/@iconify-icons/ri/file-damage-line.mjs +0 -8
- package/dist/es/node_modules/.pnpm/docx-preview@0.3.3/node_modules/docx-preview/dist/docx-preview.mjs +0 -3877
- package/dist/es/node_modules/.pnpm/jszip@3.10.1/node_modules/jszip/dist/jszip.min.mjs +0 -2649
- /package/dist/es/node_modules/.pnpm/{@iconify-icons_ep@1.2.12 → @iconify-icons_ep@1.2.7}/node_modules/@iconify-icons/ep/arrow-left.mjs +0 -0
- /package/dist/es/node_modules/.pnpm/{@iconify-icons_ep@1.2.12 → @iconify-icons_ep@1.2.7}/node_modules/@iconify-icons/ep/arrow-right.mjs +0 -0
- /package/dist/es/node_modules/.pnpm/{@iconify-icons_ep@1.2.12 → @iconify-icons_ep@1.2.7}/node_modules/@iconify-icons/ep/check.mjs +0 -0
- /package/dist/es/node_modules/.pnpm/{@iconify-icons_ep@1.2.12 → @iconify-icons_ep@1.2.7}/node_modules/@iconify-icons/ep/close.mjs +0 -0
- /package/dist/es/node_modules/.pnpm/{@iconify-icons_ep@1.2.12 → @iconify-icons_ep@1.2.7}/node_modules/@iconify-icons/ep/copy-document.mjs +0 -0
- /package/dist/es/node_modules/.pnpm/{@iconify-icons_ep@1.2.12 → @iconify-icons_ep@1.2.7}/node_modules/@iconify-icons/ep/delete.mjs +0 -0
- /package/dist/es/node_modules/.pnpm/{@iconify-icons_ep@1.2.12 → @iconify-icons_ep@1.2.7}/node_modules/@iconify-icons/ep/edit.mjs +0 -0
- /package/dist/es/node_modules/.pnpm/{@iconify-icons_ep@1.2.12 → @iconify-icons_ep@1.2.7}/node_modules/@iconify-icons/ep/notebook.mjs +0 -0
- /package/dist/es/node_modules/.pnpm/{@iconify-icons_ep@1.2.12 → @iconify-icons_ep@1.2.7}/node_modules/@iconify-icons/ep/promotion.mjs +0 -0
- /package/dist/es/node_modules/.pnpm/{@iconify-icons_ep@1.2.12 → @iconify-icons_ep@1.2.7}/node_modules/@iconify-icons/ep/reading.mjs +0 -0
- /package/dist/es/node_modules/.pnpm/{@iconify-icons_ep@1.2.12 → @iconify-icons_ep@1.2.7}/node_modules/@iconify-icons/ep/search.mjs +0 -0
- /package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/core.mjs +0 -0
- /package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/django.mjs +0 -0
- /package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/dns.mjs +0 -0
- /package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/dos.mjs +0 -0
- /package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/dust.mjs +0 -0
- /package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/http.mjs +0 -0
- /package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/nginx.mjs +0 -0
- /package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/es/languages/xml.mjs +0 -0
- /package/dist/es/node_modules/.pnpm/{highlight.js@11.11.1 → highlight.js@11.9.0}/node_modules/highlight.js/styles/sunburst.css.mjs +0 -0
@@ -1,3877 +0,0 @@
|
|
1
|
-
import "../../../../jszip@3.10.1/node_modules/jszip/dist/jszip.min.mjs";
|
2
|
-
import { exports as jszip_minExports } from "../../../../../../_virtual/jszip.min.mjs";
|
3
|
-
var RelationshipTypes;
|
4
|
-
(function(RelationshipTypes2) {
|
5
|
-
RelationshipTypes2["OfficeDocument"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
|
6
|
-
RelationshipTypes2["FontTable"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable";
|
7
|
-
RelationshipTypes2["Image"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
|
8
|
-
RelationshipTypes2["Numbering"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering";
|
9
|
-
RelationshipTypes2["Styles"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";
|
10
|
-
RelationshipTypes2["StylesWithEffects"] = "http://schemas.microsoft.com/office/2007/relationships/stylesWithEffects";
|
11
|
-
RelationshipTypes2["Theme"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";
|
12
|
-
RelationshipTypes2["Settings"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings";
|
13
|
-
RelationshipTypes2["WebSettings"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings";
|
14
|
-
RelationshipTypes2["Hyperlink"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
|
15
|
-
RelationshipTypes2["Footnotes"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes";
|
16
|
-
RelationshipTypes2["Endnotes"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes";
|
17
|
-
RelationshipTypes2["Footer"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer";
|
18
|
-
RelationshipTypes2["Header"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header";
|
19
|
-
RelationshipTypes2["ExtendedProperties"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties";
|
20
|
-
RelationshipTypes2["CoreProperties"] = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
|
21
|
-
RelationshipTypes2["CustomProperties"] = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/custom-properties";
|
22
|
-
RelationshipTypes2["Comments"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments";
|
23
|
-
RelationshipTypes2["CommentsExtended"] = "http://schemas.microsoft.com/office/2011/relationships/commentsExtended";
|
24
|
-
})(RelationshipTypes || (RelationshipTypes = {}));
|
25
|
-
function parseRelationships(root, xml) {
|
26
|
-
return xml.elements(root).map((e) => ({
|
27
|
-
id: xml.attr(e, "Id"),
|
28
|
-
type: xml.attr(e, "Type"),
|
29
|
-
target: xml.attr(e, "Target"),
|
30
|
-
targetMode: xml.attr(e, "TargetMode")
|
31
|
-
}));
|
32
|
-
}
|
33
|
-
const ns$1 = {
|
34
|
-
wordml: "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
|
35
|
-
drawingml: "http://schemas.openxmlformats.org/drawingml/2006/main",
|
36
|
-
picture: "http://schemas.openxmlformats.org/drawingml/2006/picture",
|
37
|
-
compatibility: "http://schemas.openxmlformats.org/markup-compatibility/2006",
|
38
|
-
math: "http://schemas.openxmlformats.org/officeDocument/2006/math"
|
39
|
-
};
|
40
|
-
const LengthUsage = {
|
41
|
-
Dxa: { mul: 0.05, unit: "pt" },
|
42
|
-
Emu: { mul: 1 / 12700, unit: "pt" },
|
43
|
-
FontSize: { mul: 0.5, unit: "pt" },
|
44
|
-
Border: { mul: 0.125, unit: "pt" },
|
45
|
-
Point: { mul: 1, unit: "pt" },
|
46
|
-
Percent: { mul: 0.02, unit: "%" },
|
47
|
-
LineHeight: { mul: 1 / 240, unit: "" },
|
48
|
-
VmlEmu: { mul: 1 / 12700, unit: "" }
|
49
|
-
};
|
50
|
-
function convertLength(val, usage = LengthUsage.Dxa) {
|
51
|
-
if (val == null || /.+(p[xt]|[%])$/.test(val)) {
|
52
|
-
return val;
|
53
|
-
}
|
54
|
-
return `${(parseInt(val) * usage.mul).toFixed(2)}${usage.unit}`;
|
55
|
-
}
|
56
|
-
function convertBoolean(v, defaultValue = false) {
|
57
|
-
switch (v) {
|
58
|
-
case "1":
|
59
|
-
return true;
|
60
|
-
case "0":
|
61
|
-
return false;
|
62
|
-
case "on":
|
63
|
-
return true;
|
64
|
-
case "off":
|
65
|
-
return false;
|
66
|
-
case "true":
|
67
|
-
return true;
|
68
|
-
case "false":
|
69
|
-
return false;
|
70
|
-
default:
|
71
|
-
return defaultValue;
|
72
|
-
}
|
73
|
-
}
|
74
|
-
function parseCommonProperty(elem, props, xml) {
|
75
|
-
if (elem.namespaceURI != ns$1.wordml)
|
76
|
-
return false;
|
77
|
-
switch (elem.localName) {
|
78
|
-
case "color":
|
79
|
-
props.color = xml.attr(elem, "val");
|
80
|
-
break;
|
81
|
-
case "sz":
|
82
|
-
props.fontSize = xml.lengthAttr(elem, "val", LengthUsage.FontSize);
|
83
|
-
break;
|
84
|
-
default:
|
85
|
-
return false;
|
86
|
-
}
|
87
|
-
return true;
|
88
|
-
}
|
89
|
-
function parseXmlString(xmlString, trimXmlDeclaration = false) {
|
90
|
-
if (trimXmlDeclaration)
|
91
|
-
xmlString = xmlString.replace(/<[?].*[?]>/, "");
|
92
|
-
xmlString = removeUTF8BOM(xmlString);
|
93
|
-
const result = new DOMParser().parseFromString(xmlString, "application/xml");
|
94
|
-
const errorText = hasXmlParserError(result);
|
95
|
-
if (errorText)
|
96
|
-
throw new Error(errorText);
|
97
|
-
return result;
|
98
|
-
}
|
99
|
-
function hasXmlParserError(doc) {
|
100
|
-
var _a;
|
101
|
-
return (_a = doc.getElementsByTagName("parsererror")[0]) == null ? void 0 : _a.textContent;
|
102
|
-
}
|
103
|
-
function removeUTF8BOM(data) {
|
104
|
-
return data.charCodeAt(0) === 65279 ? data.substring(1) : data;
|
105
|
-
}
|
106
|
-
function serializeXmlString(elem) {
|
107
|
-
return new XMLSerializer().serializeToString(elem);
|
108
|
-
}
|
109
|
-
class XmlParser {
|
110
|
-
elements(elem, localName = null) {
|
111
|
-
const result = [];
|
112
|
-
for (let i = 0, l = elem.childNodes.length; i < l; i++) {
|
113
|
-
let c = elem.childNodes.item(i);
|
114
|
-
if (c.nodeType == 1 && (localName == null || c.localName == localName))
|
115
|
-
result.push(c);
|
116
|
-
}
|
117
|
-
return result;
|
118
|
-
}
|
119
|
-
element(elem, localName) {
|
120
|
-
for (let i = 0, l = elem.childNodes.length; i < l; i++) {
|
121
|
-
let c = elem.childNodes.item(i);
|
122
|
-
if (c.nodeType == 1 && c.localName == localName)
|
123
|
-
return c;
|
124
|
-
}
|
125
|
-
return null;
|
126
|
-
}
|
127
|
-
elementAttr(elem, localName, attrLocalName) {
|
128
|
-
var el = this.element(elem, localName);
|
129
|
-
return el ? this.attr(el, attrLocalName) : void 0;
|
130
|
-
}
|
131
|
-
attrs(elem) {
|
132
|
-
return Array.from(elem.attributes);
|
133
|
-
}
|
134
|
-
attr(elem, localName) {
|
135
|
-
for (let i = 0, l = elem.attributes.length; i < l; i++) {
|
136
|
-
let a = elem.attributes.item(i);
|
137
|
-
if (a.localName == localName)
|
138
|
-
return a.value;
|
139
|
-
}
|
140
|
-
return null;
|
141
|
-
}
|
142
|
-
intAttr(node, attrName, defaultValue = null) {
|
143
|
-
var val = this.attr(node, attrName);
|
144
|
-
return val ? parseInt(val) : defaultValue;
|
145
|
-
}
|
146
|
-
hexAttr(node, attrName, defaultValue = null) {
|
147
|
-
var val = this.attr(node, attrName);
|
148
|
-
return val ? parseInt(val, 16) : defaultValue;
|
149
|
-
}
|
150
|
-
floatAttr(node, attrName, defaultValue = null) {
|
151
|
-
var val = this.attr(node, attrName);
|
152
|
-
return val ? parseFloat(val) : defaultValue;
|
153
|
-
}
|
154
|
-
boolAttr(node, attrName, defaultValue = null) {
|
155
|
-
return convertBoolean(this.attr(node, attrName), defaultValue);
|
156
|
-
}
|
157
|
-
lengthAttr(node, attrName, usage = LengthUsage.Dxa) {
|
158
|
-
return convertLength(this.attr(node, attrName), usage);
|
159
|
-
}
|
160
|
-
}
|
161
|
-
const globalXmlParser = new XmlParser();
|
162
|
-
class Part {
|
163
|
-
constructor(_package, path) {
|
164
|
-
this._package = _package;
|
165
|
-
this.path = path;
|
166
|
-
}
|
167
|
-
async load() {
|
168
|
-
this.rels = await this._package.loadRelationships(this.path);
|
169
|
-
const xmlText = await this._package.load(this.path);
|
170
|
-
const xmlDoc = this._package.parseXmlDocument(xmlText);
|
171
|
-
if (this._package.options.keepOrigin) {
|
172
|
-
this._xmlDocument = xmlDoc;
|
173
|
-
}
|
174
|
-
this.parseXml(xmlDoc.firstElementChild);
|
175
|
-
}
|
176
|
-
save() {
|
177
|
-
this._package.update(this.path, serializeXmlString(this._xmlDocument));
|
178
|
-
}
|
179
|
-
parseXml(root) {
|
180
|
-
}
|
181
|
-
}
|
182
|
-
const embedFontTypeMap = {
|
183
|
-
embedRegular: "regular",
|
184
|
-
embedBold: "bold",
|
185
|
-
embedItalic: "italic",
|
186
|
-
embedBoldItalic: "boldItalic"
|
187
|
-
};
|
188
|
-
function parseFonts(root, xml) {
|
189
|
-
return xml.elements(root).map((el) => parseFont(el, xml));
|
190
|
-
}
|
191
|
-
function parseFont(elem, xml) {
|
192
|
-
let result = {
|
193
|
-
name: xml.attr(elem, "name"),
|
194
|
-
embedFontRefs: []
|
195
|
-
};
|
196
|
-
for (let el of xml.elements(elem)) {
|
197
|
-
switch (el.localName) {
|
198
|
-
case "family":
|
199
|
-
result.family = xml.attr(el, "val");
|
200
|
-
break;
|
201
|
-
case "altName":
|
202
|
-
result.altName = xml.attr(el, "val");
|
203
|
-
break;
|
204
|
-
case "embedRegular":
|
205
|
-
case "embedBold":
|
206
|
-
case "embedItalic":
|
207
|
-
case "embedBoldItalic":
|
208
|
-
result.embedFontRefs.push(parseEmbedFontRef(el, xml));
|
209
|
-
break;
|
210
|
-
}
|
211
|
-
}
|
212
|
-
return result;
|
213
|
-
}
|
214
|
-
function parseEmbedFontRef(elem, xml) {
|
215
|
-
return {
|
216
|
-
id: xml.attr(elem, "id"),
|
217
|
-
key: xml.attr(elem, "fontKey"),
|
218
|
-
type: embedFontTypeMap[elem.localName]
|
219
|
-
};
|
220
|
-
}
|
221
|
-
class FontTablePart extends Part {
|
222
|
-
parseXml(root) {
|
223
|
-
this.fonts = parseFonts(root, this._package.xmlParser);
|
224
|
-
}
|
225
|
-
}
|
226
|
-
function escapeClassName(className) {
|
227
|
-
return className == null ? void 0 : className.replace(/[ .]+/g, "-").replace(/[&]+/g, "and").toLowerCase();
|
228
|
-
}
|
229
|
-
function encloseFontFamily(fontFamily) {
|
230
|
-
return /^[^"'].*\s.*[^"']$/.test(fontFamily) ? `'${fontFamily}'` : fontFamily;
|
231
|
-
}
|
232
|
-
function splitPath(path) {
|
233
|
-
let si = path.lastIndexOf("/") + 1;
|
234
|
-
let folder = si == 0 ? "" : path.substring(0, si);
|
235
|
-
let fileName = si == 0 ? path : path.substring(si);
|
236
|
-
return [folder, fileName];
|
237
|
-
}
|
238
|
-
function resolvePath(path, base) {
|
239
|
-
try {
|
240
|
-
const prefix = "http://docx/";
|
241
|
-
const url = new URL(path, prefix + base).toString();
|
242
|
-
return url.substring(prefix.length);
|
243
|
-
} catch {
|
244
|
-
return `${base}${path}`;
|
245
|
-
}
|
246
|
-
}
|
247
|
-
function keyBy(array, by) {
|
248
|
-
return array.reduce((a, x) => {
|
249
|
-
a[by(x)] = x;
|
250
|
-
return a;
|
251
|
-
}, {});
|
252
|
-
}
|
253
|
-
function blobToBase64(blob) {
|
254
|
-
return new Promise((resolve, reject) => {
|
255
|
-
const reader = new FileReader();
|
256
|
-
reader.onloadend = () => resolve(reader.result);
|
257
|
-
reader.onerror = () => reject();
|
258
|
-
reader.readAsDataURL(blob);
|
259
|
-
});
|
260
|
-
}
|
261
|
-
function isObject(item) {
|
262
|
-
return item && typeof item === "object" && !Array.isArray(item);
|
263
|
-
}
|
264
|
-
function isString(item) {
|
265
|
-
return typeof item === "string" || item instanceof String;
|
266
|
-
}
|
267
|
-
function mergeDeep(target, ...sources) {
|
268
|
-
if (!sources.length)
|
269
|
-
return target;
|
270
|
-
const source = sources.shift();
|
271
|
-
if (isObject(target) && isObject(source)) {
|
272
|
-
for (const key in source) {
|
273
|
-
if (isObject(source[key])) {
|
274
|
-
const val = target[key] ?? (target[key] = {});
|
275
|
-
mergeDeep(val, source[key]);
|
276
|
-
} else {
|
277
|
-
target[key] = source[key];
|
278
|
-
}
|
279
|
-
}
|
280
|
-
}
|
281
|
-
return mergeDeep(target, ...sources);
|
282
|
-
}
|
283
|
-
function asArray(val) {
|
284
|
-
return Array.isArray(val) ? val : [val];
|
285
|
-
}
|
286
|
-
class OpenXmlPackage {
|
287
|
-
constructor(_zip, options) {
|
288
|
-
this._zip = _zip;
|
289
|
-
this.options = options;
|
290
|
-
this.xmlParser = new XmlParser();
|
291
|
-
}
|
292
|
-
get(path) {
|
293
|
-
const p = normalizePath(path);
|
294
|
-
return this._zip.files[p] ?? this._zip.files[p.replace(/\//g, "\\")];
|
295
|
-
}
|
296
|
-
update(path, content) {
|
297
|
-
this._zip.file(path, content);
|
298
|
-
}
|
299
|
-
static async load(input, options) {
|
300
|
-
const zip = await jszip_minExports.loadAsync(input);
|
301
|
-
return new OpenXmlPackage(zip, options);
|
302
|
-
}
|
303
|
-
save(type = "blob") {
|
304
|
-
return this._zip.generateAsync({ type });
|
305
|
-
}
|
306
|
-
load(path, type = "string") {
|
307
|
-
var _a;
|
308
|
-
return ((_a = this.get(path)) == null ? void 0 : _a.async(type)) ?? Promise.resolve(null);
|
309
|
-
}
|
310
|
-
async loadRelationships(path = null) {
|
311
|
-
let relsPath = `_rels/.rels`;
|
312
|
-
if (path != null) {
|
313
|
-
const [f, fn] = splitPath(path);
|
314
|
-
relsPath = `${f}_rels/${fn}.rels`;
|
315
|
-
}
|
316
|
-
const txt = await this.load(relsPath);
|
317
|
-
return txt ? parseRelationships(this.parseXmlDocument(txt).firstElementChild, this.xmlParser) : null;
|
318
|
-
}
|
319
|
-
parseXmlDocument(txt) {
|
320
|
-
return parseXmlString(txt, this.options.trimXmlDeclaration);
|
321
|
-
}
|
322
|
-
}
|
323
|
-
function normalizePath(path) {
|
324
|
-
return path.startsWith("/") ? path.substr(1) : path;
|
325
|
-
}
|
326
|
-
class DocumentPart extends Part {
|
327
|
-
constructor(pkg, path, parser) {
|
328
|
-
super(pkg, path);
|
329
|
-
this._documentParser = parser;
|
330
|
-
}
|
331
|
-
parseXml(root) {
|
332
|
-
this.body = this._documentParser.parseDocumentFile(root);
|
333
|
-
}
|
334
|
-
}
|
335
|
-
function parseBorder(elem, xml) {
|
336
|
-
return {
|
337
|
-
type: xml.attr(elem, "val"),
|
338
|
-
color: xml.attr(elem, "color"),
|
339
|
-
size: xml.lengthAttr(elem, "sz", LengthUsage.Border),
|
340
|
-
offset: xml.lengthAttr(elem, "space", LengthUsage.Point),
|
341
|
-
frame: xml.boolAttr(elem, "frame"),
|
342
|
-
shadow: xml.boolAttr(elem, "shadow")
|
343
|
-
};
|
344
|
-
}
|
345
|
-
function parseBorders(elem, xml) {
|
346
|
-
var result = {};
|
347
|
-
for (let e of xml.elements(elem)) {
|
348
|
-
switch (e.localName) {
|
349
|
-
case "left":
|
350
|
-
result.left = parseBorder(e, xml);
|
351
|
-
break;
|
352
|
-
case "top":
|
353
|
-
result.top = parseBorder(e, xml);
|
354
|
-
break;
|
355
|
-
case "right":
|
356
|
-
result.right = parseBorder(e, xml);
|
357
|
-
break;
|
358
|
-
case "bottom":
|
359
|
-
result.bottom = parseBorder(e, xml);
|
360
|
-
break;
|
361
|
-
}
|
362
|
-
}
|
363
|
-
return result;
|
364
|
-
}
|
365
|
-
var SectionType;
|
366
|
-
(function(SectionType2) {
|
367
|
-
SectionType2["Continuous"] = "continuous";
|
368
|
-
SectionType2["NextPage"] = "nextPage";
|
369
|
-
SectionType2["NextColumn"] = "nextColumn";
|
370
|
-
SectionType2["EvenPage"] = "evenPage";
|
371
|
-
SectionType2["OddPage"] = "oddPage";
|
372
|
-
})(SectionType || (SectionType = {}));
|
373
|
-
function parseSectionProperties(elem, xml = globalXmlParser) {
|
374
|
-
var section = {};
|
375
|
-
for (let e of xml.elements(elem)) {
|
376
|
-
switch (e.localName) {
|
377
|
-
case "pgSz":
|
378
|
-
section.pageSize = {
|
379
|
-
width: xml.lengthAttr(e, "w"),
|
380
|
-
height: xml.lengthAttr(e, "h"),
|
381
|
-
orientation: xml.attr(e, "orient")
|
382
|
-
};
|
383
|
-
break;
|
384
|
-
case "type":
|
385
|
-
section.type = xml.attr(e, "val");
|
386
|
-
break;
|
387
|
-
case "pgMar":
|
388
|
-
section.pageMargins = {
|
389
|
-
left: xml.lengthAttr(e, "left"),
|
390
|
-
right: xml.lengthAttr(e, "right"),
|
391
|
-
top: xml.lengthAttr(e, "top"),
|
392
|
-
bottom: xml.lengthAttr(e, "bottom"),
|
393
|
-
header: xml.lengthAttr(e, "header"),
|
394
|
-
footer: xml.lengthAttr(e, "footer"),
|
395
|
-
gutter: xml.lengthAttr(e, "gutter")
|
396
|
-
};
|
397
|
-
break;
|
398
|
-
case "cols":
|
399
|
-
section.columns = parseColumns(e, xml);
|
400
|
-
break;
|
401
|
-
case "headerReference":
|
402
|
-
(section.headerRefs ?? (section.headerRefs = [])).push(parseFooterHeaderReference(e, xml));
|
403
|
-
break;
|
404
|
-
case "footerReference":
|
405
|
-
(section.footerRefs ?? (section.footerRefs = [])).push(parseFooterHeaderReference(e, xml));
|
406
|
-
break;
|
407
|
-
case "titlePg":
|
408
|
-
section.titlePage = xml.boolAttr(e, "val", true);
|
409
|
-
break;
|
410
|
-
case "pgBorders":
|
411
|
-
section.pageBorders = parseBorders(e, xml);
|
412
|
-
break;
|
413
|
-
case "pgNumType":
|
414
|
-
section.pageNumber = parsePageNumber(e, xml);
|
415
|
-
break;
|
416
|
-
}
|
417
|
-
}
|
418
|
-
return section;
|
419
|
-
}
|
420
|
-
function parseColumns(elem, xml) {
|
421
|
-
return {
|
422
|
-
numberOfColumns: xml.intAttr(elem, "num"),
|
423
|
-
space: xml.lengthAttr(elem, "space"),
|
424
|
-
separator: xml.boolAttr(elem, "sep"),
|
425
|
-
equalWidth: xml.boolAttr(elem, "equalWidth", true),
|
426
|
-
columns: xml.elements(elem, "col").map((e) => ({
|
427
|
-
width: xml.lengthAttr(e, "w"),
|
428
|
-
space: xml.lengthAttr(e, "space")
|
429
|
-
}))
|
430
|
-
};
|
431
|
-
}
|
432
|
-
function parsePageNumber(elem, xml) {
|
433
|
-
return {
|
434
|
-
chapSep: xml.attr(elem, "chapSep"),
|
435
|
-
chapStyle: xml.attr(elem, "chapStyle"),
|
436
|
-
format: xml.attr(elem, "fmt"),
|
437
|
-
start: xml.intAttr(elem, "start")
|
438
|
-
};
|
439
|
-
}
|
440
|
-
function parseFooterHeaderReference(elem, xml) {
|
441
|
-
return {
|
442
|
-
id: xml.attr(elem, "id"),
|
443
|
-
type: xml.attr(elem, "type")
|
444
|
-
};
|
445
|
-
}
|
446
|
-
function parseLineSpacing(elem, xml) {
|
447
|
-
return {
|
448
|
-
before: xml.lengthAttr(elem, "before"),
|
449
|
-
after: xml.lengthAttr(elem, "after"),
|
450
|
-
line: xml.intAttr(elem, "line"),
|
451
|
-
lineRule: xml.attr(elem, "lineRule")
|
452
|
-
};
|
453
|
-
}
|
454
|
-
function parseRunProperties(elem, xml) {
|
455
|
-
let result = {};
|
456
|
-
for (let el of xml.elements(elem)) {
|
457
|
-
parseRunProperty(el, result, xml);
|
458
|
-
}
|
459
|
-
return result;
|
460
|
-
}
|
461
|
-
function parseRunProperty(elem, props, xml) {
|
462
|
-
if (parseCommonProperty(elem, props, xml))
|
463
|
-
return true;
|
464
|
-
return false;
|
465
|
-
}
|
466
|
-
function parseParagraphProperties(elem, xml) {
|
467
|
-
let result = {};
|
468
|
-
for (let el of xml.elements(elem)) {
|
469
|
-
parseParagraphProperty(el, result, xml);
|
470
|
-
}
|
471
|
-
return result;
|
472
|
-
}
|
473
|
-
function parseParagraphProperty(elem, props, xml) {
|
474
|
-
if (elem.namespaceURI != ns$1.wordml)
|
475
|
-
return false;
|
476
|
-
if (parseCommonProperty(elem, props, xml))
|
477
|
-
return true;
|
478
|
-
switch (elem.localName) {
|
479
|
-
case "tabs":
|
480
|
-
props.tabs = parseTabs(elem, xml);
|
481
|
-
break;
|
482
|
-
case "sectPr":
|
483
|
-
props.sectionProps = parseSectionProperties(elem, xml);
|
484
|
-
break;
|
485
|
-
case "numPr":
|
486
|
-
props.numbering = parseNumbering$1(elem, xml);
|
487
|
-
break;
|
488
|
-
case "spacing":
|
489
|
-
props.lineSpacing = parseLineSpacing(elem, xml);
|
490
|
-
return false;
|
491
|
-
case "textAlignment":
|
492
|
-
props.textAlignment = xml.attr(elem, "val");
|
493
|
-
return false;
|
494
|
-
case "keepLines":
|
495
|
-
props.keepLines = xml.boolAttr(elem, "val", true);
|
496
|
-
break;
|
497
|
-
case "keepNext":
|
498
|
-
props.keepNext = xml.boolAttr(elem, "val", true);
|
499
|
-
break;
|
500
|
-
case "pageBreakBefore":
|
501
|
-
props.pageBreakBefore = xml.boolAttr(elem, "val", true);
|
502
|
-
break;
|
503
|
-
case "outlineLvl":
|
504
|
-
props.outlineLevel = xml.intAttr(elem, "val");
|
505
|
-
break;
|
506
|
-
case "pStyle":
|
507
|
-
props.styleName = xml.attr(elem, "val");
|
508
|
-
break;
|
509
|
-
case "rPr":
|
510
|
-
props.runProps = parseRunProperties(elem, xml);
|
511
|
-
break;
|
512
|
-
default:
|
513
|
-
return false;
|
514
|
-
}
|
515
|
-
return true;
|
516
|
-
}
|
517
|
-
function parseTabs(elem, xml) {
|
518
|
-
return xml.elements(elem, "tab").map((e) => ({
|
519
|
-
position: xml.lengthAttr(e, "pos"),
|
520
|
-
leader: xml.attr(e, "leader"),
|
521
|
-
style: xml.attr(e, "val")
|
522
|
-
}));
|
523
|
-
}
|
524
|
-
function parseNumbering$1(elem, xml) {
|
525
|
-
var result = {};
|
526
|
-
for (let e of xml.elements(elem)) {
|
527
|
-
switch (e.localName) {
|
528
|
-
case "numId":
|
529
|
-
result.id = xml.attr(e, "val");
|
530
|
-
break;
|
531
|
-
case "ilvl":
|
532
|
-
result.level = xml.intAttr(e, "val");
|
533
|
-
break;
|
534
|
-
}
|
535
|
-
}
|
536
|
-
return result;
|
537
|
-
}
|
538
|
-
function parseNumberingPart(elem, xml) {
|
539
|
-
let result = {
|
540
|
-
numberings: [],
|
541
|
-
abstractNumberings: [],
|
542
|
-
bulletPictures: []
|
543
|
-
};
|
544
|
-
for (let e of xml.elements(elem)) {
|
545
|
-
switch (e.localName) {
|
546
|
-
case "num":
|
547
|
-
result.numberings.push(parseNumbering(e, xml));
|
548
|
-
break;
|
549
|
-
case "abstractNum":
|
550
|
-
result.abstractNumberings.push(parseAbstractNumbering(e, xml));
|
551
|
-
break;
|
552
|
-
case "numPicBullet":
|
553
|
-
result.bulletPictures.push(parseNumberingBulletPicture(e, xml));
|
554
|
-
break;
|
555
|
-
}
|
556
|
-
}
|
557
|
-
return result;
|
558
|
-
}
|
559
|
-
function parseNumbering(elem, xml) {
|
560
|
-
let result = {
|
561
|
-
id: xml.attr(elem, "numId"),
|
562
|
-
overrides: []
|
563
|
-
};
|
564
|
-
for (let e of xml.elements(elem)) {
|
565
|
-
switch (e.localName) {
|
566
|
-
case "abstractNumId":
|
567
|
-
result.abstractId = xml.attr(e, "val");
|
568
|
-
break;
|
569
|
-
case "lvlOverride":
|
570
|
-
result.overrides.push(parseNumberingLevelOverrride(e, xml));
|
571
|
-
break;
|
572
|
-
}
|
573
|
-
}
|
574
|
-
return result;
|
575
|
-
}
|
576
|
-
function parseAbstractNumbering(elem, xml) {
|
577
|
-
let result = {
|
578
|
-
id: xml.attr(elem, "abstractNumId"),
|
579
|
-
levels: []
|
580
|
-
};
|
581
|
-
for (let e of xml.elements(elem)) {
|
582
|
-
switch (e.localName) {
|
583
|
-
case "name":
|
584
|
-
result.name = xml.attr(e, "val");
|
585
|
-
break;
|
586
|
-
case "multiLevelType":
|
587
|
-
result.multiLevelType = xml.attr(e, "val");
|
588
|
-
break;
|
589
|
-
case "numStyleLink":
|
590
|
-
result.numberingStyleLink = xml.attr(e, "val");
|
591
|
-
break;
|
592
|
-
case "styleLink":
|
593
|
-
result.styleLink = xml.attr(e, "val");
|
594
|
-
break;
|
595
|
-
case "lvl":
|
596
|
-
result.levels.push(parseNumberingLevel(e, xml));
|
597
|
-
break;
|
598
|
-
}
|
599
|
-
}
|
600
|
-
return result;
|
601
|
-
}
|
602
|
-
function parseNumberingLevel(elem, xml) {
|
603
|
-
let result = {
|
604
|
-
level: xml.intAttr(elem, "ilvl")
|
605
|
-
};
|
606
|
-
for (let e of xml.elements(elem)) {
|
607
|
-
switch (e.localName) {
|
608
|
-
case "start":
|
609
|
-
result.start = xml.attr(e, "val");
|
610
|
-
break;
|
611
|
-
case "lvlRestart":
|
612
|
-
result.restart = xml.intAttr(e, "val");
|
613
|
-
break;
|
614
|
-
case "numFmt":
|
615
|
-
result.format = xml.attr(e, "val");
|
616
|
-
break;
|
617
|
-
case "lvlText":
|
618
|
-
result.text = xml.attr(e, "val");
|
619
|
-
break;
|
620
|
-
case "lvlJc":
|
621
|
-
result.justification = xml.attr(e, "val");
|
622
|
-
break;
|
623
|
-
case "lvlPicBulletId":
|
624
|
-
result.bulletPictureId = xml.attr(e, "val");
|
625
|
-
break;
|
626
|
-
case "pStyle":
|
627
|
-
result.paragraphStyle = xml.attr(e, "val");
|
628
|
-
break;
|
629
|
-
case "pPr":
|
630
|
-
result.paragraphProps = parseParagraphProperties(e, xml);
|
631
|
-
break;
|
632
|
-
case "rPr":
|
633
|
-
result.runProps = parseRunProperties(e, xml);
|
634
|
-
break;
|
635
|
-
}
|
636
|
-
}
|
637
|
-
return result;
|
638
|
-
}
|
639
|
-
function parseNumberingLevelOverrride(elem, xml) {
|
640
|
-
let result = {
|
641
|
-
level: xml.intAttr(elem, "ilvl")
|
642
|
-
};
|
643
|
-
for (let e of xml.elements(elem)) {
|
644
|
-
switch (e.localName) {
|
645
|
-
case "startOverride":
|
646
|
-
result.start = xml.intAttr(e, "val");
|
647
|
-
break;
|
648
|
-
case "lvl":
|
649
|
-
result.numberingLevel = parseNumberingLevel(e, xml);
|
650
|
-
break;
|
651
|
-
}
|
652
|
-
}
|
653
|
-
return result;
|
654
|
-
}
|
655
|
-
function parseNumberingBulletPicture(elem, xml) {
|
656
|
-
var pict = xml.element(elem, "pict");
|
657
|
-
var shape = pict && xml.element(pict, "shape");
|
658
|
-
var imagedata = shape && xml.element(shape, "imagedata");
|
659
|
-
return imagedata ? {
|
660
|
-
id: xml.attr(elem, "numPicBulletId"),
|
661
|
-
referenceId: xml.attr(imagedata, "id"),
|
662
|
-
style: xml.attr(shape, "style")
|
663
|
-
} : null;
|
664
|
-
}
|
665
|
-
class NumberingPart extends Part {
|
666
|
-
constructor(pkg, path, parser) {
|
667
|
-
super(pkg, path);
|
668
|
-
this._documentParser = parser;
|
669
|
-
}
|
670
|
-
parseXml(root) {
|
671
|
-
Object.assign(this, parseNumberingPart(root, this._package.xmlParser));
|
672
|
-
this.domNumberings = this._documentParser.parseNumberingFile(root);
|
673
|
-
}
|
674
|
-
}
|
675
|
-
class StylesPart extends Part {
|
676
|
-
constructor(pkg, path, parser) {
|
677
|
-
super(pkg, path);
|
678
|
-
this._documentParser = parser;
|
679
|
-
}
|
680
|
-
parseXml(root) {
|
681
|
-
this.styles = this._documentParser.parseStylesFile(root);
|
682
|
-
}
|
683
|
-
}
|
684
|
-
var DomType;
|
685
|
-
(function(DomType2) {
|
686
|
-
DomType2["Document"] = "document";
|
687
|
-
DomType2["Paragraph"] = "paragraph";
|
688
|
-
DomType2["Run"] = "run";
|
689
|
-
DomType2["Break"] = "break";
|
690
|
-
DomType2["NoBreakHyphen"] = "noBreakHyphen";
|
691
|
-
DomType2["Table"] = "table";
|
692
|
-
DomType2["Row"] = "row";
|
693
|
-
DomType2["Cell"] = "cell";
|
694
|
-
DomType2["Hyperlink"] = "hyperlink";
|
695
|
-
DomType2["SmartTag"] = "smartTag";
|
696
|
-
DomType2["Drawing"] = "drawing";
|
697
|
-
DomType2["Image"] = "image";
|
698
|
-
DomType2["Text"] = "text";
|
699
|
-
DomType2["Tab"] = "tab";
|
700
|
-
DomType2["Symbol"] = "symbol";
|
701
|
-
DomType2["BookmarkStart"] = "bookmarkStart";
|
702
|
-
DomType2["BookmarkEnd"] = "bookmarkEnd";
|
703
|
-
DomType2["Footer"] = "footer";
|
704
|
-
DomType2["Header"] = "header";
|
705
|
-
DomType2["FootnoteReference"] = "footnoteReference";
|
706
|
-
DomType2["EndnoteReference"] = "endnoteReference";
|
707
|
-
DomType2["Footnote"] = "footnote";
|
708
|
-
DomType2["Endnote"] = "endnote";
|
709
|
-
DomType2["SimpleField"] = "simpleField";
|
710
|
-
DomType2["ComplexField"] = "complexField";
|
711
|
-
DomType2["Instruction"] = "instruction";
|
712
|
-
DomType2["VmlPicture"] = "vmlPicture";
|
713
|
-
DomType2["MmlMath"] = "mmlMath";
|
714
|
-
DomType2["MmlMathParagraph"] = "mmlMathParagraph";
|
715
|
-
DomType2["MmlFraction"] = "mmlFraction";
|
716
|
-
DomType2["MmlFunction"] = "mmlFunction";
|
717
|
-
DomType2["MmlFunctionName"] = "mmlFunctionName";
|
718
|
-
DomType2["MmlNumerator"] = "mmlNumerator";
|
719
|
-
DomType2["MmlDenominator"] = "mmlDenominator";
|
720
|
-
DomType2["MmlRadical"] = "mmlRadical";
|
721
|
-
DomType2["MmlBase"] = "mmlBase";
|
722
|
-
DomType2["MmlDegree"] = "mmlDegree";
|
723
|
-
DomType2["MmlSuperscript"] = "mmlSuperscript";
|
724
|
-
DomType2["MmlSubscript"] = "mmlSubscript";
|
725
|
-
DomType2["MmlPreSubSuper"] = "mmlPreSubSuper";
|
726
|
-
DomType2["MmlSubArgument"] = "mmlSubArgument";
|
727
|
-
DomType2["MmlSuperArgument"] = "mmlSuperArgument";
|
728
|
-
DomType2["MmlNary"] = "mmlNary";
|
729
|
-
DomType2["MmlDelimiter"] = "mmlDelimiter";
|
730
|
-
DomType2["MmlRun"] = "mmlRun";
|
731
|
-
DomType2["MmlEquationArray"] = "mmlEquationArray";
|
732
|
-
DomType2["MmlLimit"] = "mmlLimit";
|
733
|
-
DomType2["MmlLimitLower"] = "mmlLimitLower";
|
734
|
-
DomType2["MmlMatrix"] = "mmlMatrix";
|
735
|
-
DomType2["MmlMatrixRow"] = "mmlMatrixRow";
|
736
|
-
DomType2["MmlBox"] = "mmlBox";
|
737
|
-
DomType2["MmlBar"] = "mmlBar";
|
738
|
-
DomType2["MmlGroupChar"] = "mmlGroupChar";
|
739
|
-
DomType2["VmlElement"] = "vmlElement";
|
740
|
-
DomType2["Inserted"] = "inserted";
|
741
|
-
DomType2["Deleted"] = "deleted";
|
742
|
-
DomType2["DeletedText"] = "deletedText";
|
743
|
-
DomType2["Comment"] = "comment";
|
744
|
-
DomType2["CommentReference"] = "commentReference";
|
745
|
-
DomType2["CommentRangeStart"] = "commentRangeStart";
|
746
|
-
DomType2["CommentRangeEnd"] = "commentRangeEnd";
|
747
|
-
})(DomType || (DomType = {}));
|
748
|
-
class OpenXmlElementBase {
|
749
|
-
constructor() {
|
750
|
-
this.children = [];
|
751
|
-
this.cssStyle = {};
|
752
|
-
}
|
753
|
-
}
|
754
|
-
class WmlHeader extends OpenXmlElementBase {
|
755
|
-
constructor() {
|
756
|
-
super(...arguments);
|
757
|
-
this.type = DomType.Header;
|
758
|
-
}
|
759
|
-
}
|
760
|
-
class WmlFooter extends OpenXmlElementBase {
|
761
|
-
constructor() {
|
762
|
-
super(...arguments);
|
763
|
-
this.type = DomType.Footer;
|
764
|
-
}
|
765
|
-
}
|
766
|
-
class BaseHeaderFooterPart extends Part {
|
767
|
-
constructor(pkg, path, parser) {
|
768
|
-
super(pkg, path);
|
769
|
-
this._documentParser = parser;
|
770
|
-
}
|
771
|
-
parseXml(root) {
|
772
|
-
this.rootElement = this.createRootElement();
|
773
|
-
this.rootElement.children = this._documentParser.parseBodyElements(root);
|
774
|
-
}
|
775
|
-
}
|
776
|
-
class HeaderPart extends BaseHeaderFooterPart {
|
777
|
-
createRootElement() {
|
778
|
-
return new WmlHeader();
|
779
|
-
}
|
780
|
-
}
|
781
|
-
class FooterPart extends BaseHeaderFooterPart {
|
782
|
-
createRootElement() {
|
783
|
-
return new WmlFooter();
|
784
|
-
}
|
785
|
-
}
|
786
|
-
function parseExtendedProps(root, xmlParser) {
|
787
|
-
const result = {};
|
788
|
-
for (let el of xmlParser.elements(root)) {
|
789
|
-
switch (el.localName) {
|
790
|
-
case "Template":
|
791
|
-
result.template = el.textContent;
|
792
|
-
break;
|
793
|
-
case "Pages":
|
794
|
-
result.pages = safeParseToInt(el.textContent);
|
795
|
-
break;
|
796
|
-
case "Words":
|
797
|
-
result.words = safeParseToInt(el.textContent);
|
798
|
-
break;
|
799
|
-
case "Characters":
|
800
|
-
result.characters = safeParseToInt(el.textContent);
|
801
|
-
break;
|
802
|
-
case "Application":
|
803
|
-
result.application = el.textContent;
|
804
|
-
break;
|
805
|
-
case "Lines":
|
806
|
-
result.lines = safeParseToInt(el.textContent);
|
807
|
-
break;
|
808
|
-
case "Paragraphs":
|
809
|
-
result.paragraphs = safeParseToInt(el.textContent);
|
810
|
-
break;
|
811
|
-
case "Company":
|
812
|
-
result.company = el.textContent;
|
813
|
-
break;
|
814
|
-
case "AppVersion":
|
815
|
-
result.appVersion = el.textContent;
|
816
|
-
break;
|
817
|
-
}
|
818
|
-
}
|
819
|
-
return result;
|
820
|
-
}
|
821
|
-
function safeParseToInt(value) {
|
822
|
-
if (typeof value === "undefined")
|
823
|
-
return;
|
824
|
-
return parseInt(value);
|
825
|
-
}
|
826
|
-
class ExtendedPropsPart extends Part {
|
827
|
-
parseXml(root) {
|
828
|
-
this.props = parseExtendedProps(root, this._package.xmlParser);
|
829
|
-
}
|
830
|
-
}
|
831
|
-
function parseCoreProps(root, xmlParser) {
|
832
|
-
const result = {};
|
833
|
-
for (let el of xmlParser.elements(root)) {
|
834
|
-
switch (el.localName) {
|
835
|
-
case "title":
|
836
|
-
result.title = el.textContent;
|
837
|
-
break;
|
838
|
-
case "description":
|
839
|
-
result.description = el.textContent;
|
840
|
-
break;
|
841
|
-
case "subject":
|
842
|
-
result.subject = el.textContent;
|
843
|
-
break;
|
844
|
-
case "creator":
|
845
|
-
result.creator = el.textContent;
|
846
|
-
break;
|
847
|
-
case "keywords":
|
848
|
-
result.keywords = el.textContent;
|
849
|
-
break;
|
850
|
-
case "language":
|
851
|
-
result.language = el.textContent;
|
852
|
-
break;
|
853
|
-
case "lastModifiedBy":
|
854
|
-
result.lastModifiedBy = el.textContent;
|
855
|
-
break;
|
856
|
-
case "revision":
|
857
|
-
el.textContent && (result.revision = parseInt(el.textContent));
|
858
|
-
break;
|
859
|
-
}
|
860
|
-
}
|
861
|
-
return result;
|
862
|
-
}
|
863
|
-
class CorePropsPart extends Part {
|
864
|
-
parseXml(root) {
|
865
|
-
this.props = parseCoreProps(root, this._package.xmlParser);
|
866
|
-
}
|
867
|
-
}
|
868
|
-
class DmlTheme {
|
869
|
-
}
|
870
|
-
function parseTheme(elem, xml) {
|
871
|
-
var result = new DmlTheme();
|
872
|
-
var themeElements = xml.element(elem, "themeElements");
|
873
|
-
for (let el of xml.elements(themeElements)) {
|
874
|
-
switch (el.localName) {
|
875
|
-
case "clrScheme":
|
876
|
-
result.colorScheme = parseColorScheme(el, xml);
|
877
|
-
break;
|
878
|
-
case "fontScheme":
|
879
|
-
result.fontScheme = parseFontScheme(el, xml);
|
880
|
-
break;
|
881
|
-
}
|
882
|
-
}
|
883
|
-
return result;
|
884
|
-
}
|
885
|
-
function parseColorScheme(elem, xml) {
|
886
|
-
var result = {
|
887
|
-
name: xml.attr(elem, "name"),
|
888
|
-
colors: {}
|
889
|
-
};
|
890
|
-
for (let el of xml.elements(elem)) {
|
891
|
-
var srgbClr = xml.element(el, "srgbClr");
|
892
|
-
var sysClr = xml.element(el, "sysClr");
|
893
|
-
if (srgbClr) {
|
894
|
-
result.colors[el.localName] = xml.attr(srgbClr, "val");
|
895
|
-
} else if (sysClr) {
|
896
|
-
result.colors[el.localName] = xml.attr(sysClr, "lastClr");
|
897
|
-
}
|
898
|
-
}
|
899
|
-
return result;
|
900
|
-
}
|
901
|
-
function parseFontScheme(elem, xml) {
|
902
|
-
var result = {
|
903
|
-
name: xml.attr(elem, "name")
|
904
|
-
};
|
905
|
-
for (let el of xml.elements(elem)) {
|
906
|
-
switch (el.localName) {
|
907
|
-
case "majorFont":
|
908
|
-
result.majorFont = parseFontInfo(el, xml);
|
909
|
-
break;
|
910
|
-
case "minorFont":
|
911
|
-
result.minorFont = parseFontInfo(el, xml);
|
912
|
-
break;
|
913
|
-
}
|
914
|
-
}
|
915
|
-
return result;
|
916
|
-
}
|
917
|
-
function parseFontInfo(elem, xml) {
|
918
|
-
return {
|
919
|
-
latinTypeface: xml.elementAttr(elem, "latin", "typeface"),
|
920
|
-
eaTypeface: xml.elementAttr(elem, "ea", "typeface"),
|
921
|
-
csTypeface: xml.elementAttr(elem, "cs", "typeface")
|
922
|
-
};
|
923
|
-
}
|
924
|
-
class ThemePart extends Part {
|
925
|
-
constructor(pkg, path) {
|
926
|
-
super(pkg, path);
|
927
|
-
}
|
928
|
-
parseXml(root) {
|
929
|
-
this.theme = parseTheme(root, this._package.xmlParser);
|
930
|
-
}
|
931
|
-
}
|
932
|
-
class WmlBaseNote {
|
933
|
-
}
|
934
|
-
class WmlFootnote extends WmlBaseNote {
|
935
|
-
constructor() {
|
936
|
-
super(...arguments);
|
937
|
-
this.type = DomType.Footnote;
|
938
|
-
}
|
939
|
-
}
|
940
|
-
class WmlEndnote extends WmlBaseNote {
|
941
|
-
constructor() {
|
942
|
-
super(...arguments);
|
943
|
-
this.type = DomType.Endnote;
|
944
|
-
}
|
945
|
-
}
|
946
|
-
class BaseNotePart extends Part {
|
947
|
-
constructor(pkg, path, parser) {
|
948
|
-
super(pkg, path);
|
949
|
-
this._documentParser = parser;
|
950
|
-
}
|
951
|
-
}
|
952
|
-
class FootnotesPart extends BaseNotePart {
|
953
|
-
constructor(pkg, path, parser) {
|
954
|
-
super(pkg, path, parser);
|
955
|
-
}
|
956
|
-
parseXml(root) {
|
957
|
-
this.notes = this._documentParser.parseNotes(root, "footnote", WmlFootnote);
|
958
|
-
}
|
959
|
-
}
|
960
|
-
class EndnotesPart extends BaseNotePart {
|
961
|
-
constructor(pkg, path, parser) {
|
962
|
-
super(pkg, path, parser);
|
963
|
-
}
|
964
|
-
parseXml(root) {
|
965
|
-
this.notes = this._documentParser.parseNotes(root, "endnote", WmlEndnote);
|
966
|
-
}
|
967
|
-
}
|
968
|
-
function parseSettings(elem, xml) {
|
969
|
-
var result = {};
|
970
|
-
for (let el of xml.elements(elem)) {
|
971
|
-
switch (el.localName) {
|
972
|
-
case "defaultTabStop":
|
973
|
-
result.defaultTabStop = xml.lengthAttr(el, "val");
|
974
|
-
break;
|
975
|
-
case "footnotePr":
|
976
|
-
result.footnoteProps = parseNoteProperties(el, xml);
|
977
|
-
break;
|
978
|
-
case "endnotePr":
|
979
|
-
result.endnoteProps = parseNoteProperties(el, xml);
|
980
|
-
break;
|
981
|
-
case "autoHyphenation":
|
982
|
-
result.autoHyphenation = xml.boolAttr(el, "val");
|
983
|
-
break;
|
984
|
-
}
|
985
|
-
}
|
986
|
-
return result;
|
987
|
-
}
|
988
|
-
function parseNoteProperties(elem, xml) {
|
989
|
-
var result = {
|
990
|
-
defaultNoteIds: []
|
991
|
-
};
|
992
|
-
for (let el of xml.elements(elem)) {
|
993
|
-
switch (el.localName) {
|
994
|
-
case "numFmt":
|
995
|
-
result.nummeringFormat = xml.attr(el, "val");
|
996
|
-
break;
|
997
|
-
case "footnote":
|
998
|
-
case "endnote":
|
999
|
-
result.defaultNoteIds.push(xml.attr(el, "id"));
|
1000
|
-
break;
|
1001
|
-
}
|
1002
|
-
}
|
1003
|
-
return result;
|
1004
|
-
}
|
1005
|
-
class SettingsPart extends Part {
|
1006
|
-
constructor(pkg, path) {
|
1007
|
-
super(pkg, path);
|
1008
|
-
}
|
1009
|
-
parseXml(root) {
|
1010
|
-
this.settings = parseSettings(root, this._package.xmlParser);
|
1011
|
-
}
|
1012
|
-
}
|
1013
|
-
function parseCustomProps(root, xml) {
|
1014
|
-
return xml.elements(root, "property").map((e) => {
|
1015
|
-
const firstChild = e.firstChild;
|
1016
|
-
return {
|
1017
|
-
formatId: xml.attr(e, "fmtid"),
|
1018
|
-
name: xml.attr(e, "name"),
|
1019
|
-
type: firstChild.nodeName,
|
1020
|
-
value: firstChild.textContent
|
1021
|
-
};
|
1022
|
-
});
|
1023
|
-
}
|
1024
|
-
class CustomPropsPart extends Part {
|
1025
|
-
parseXml(root) {
|
1026
|
-
this.props = parseCustomProps(root, this._package.xmlParser);
|
1027
|
-
}
|
1028
|
-
}
|
1029
|
-
class CommentsPart extends Part {
|
1030
|
-
constructor(pkg, path, parser) {
|
1031
|
-
super(pkg, path);
|
1032
|
-
this._documentParser = parser;
|
1033
|
-
}
|
1034
|
-
parseXml(root) {
|
1035
|
-
this.comments = this._documentParser.parseComments(root);
|
1036
|
-
this.commentMap = keyBy(this.comments, (x) => x.id);
|
1037
|
-
}
|
1038
|
-
}
|
1039
|
-
class CommentsExtendedPart extends Part {
|
1040
|
-
constructor(pkg, path) {
|
1041
|
-
super(pkg, path);
|
1042
|
-
this.comments = [];
|
1043
|
-
}
|
1044
|
-
parseXml(root) {
|
1045
|
-
const xml = this._package.xmlParser;
|
1046
|
-
for (let el of xml.elements(root, "commentEx")) {
|
1047
|
-
this.comments.push({
|
1048
|
-
paraId: xml.attr(el, "paraId"),
|
1049
|
-
paraIdParent: xml.attr(el, "paraIdParent"),
|
1050
|
-
done: xml.boolAttr(el, "done")
|
1051
|
-
});
|
1052
|
-
}
|
1053
|
-
this.commentMap = keyBy(this.comments, (x) => x.paraId);
|
1054
|
-
}
|
1055
|
-
}
|
1056
|
-
const topLevelRels = [
|
1057
|
-
{ type: RelationshipTypes.OfficeDocument, target: "word/document.xml" },
|
1058
|
-
{ type: RelationshipTypes.ExtendedProperties, target: "docProps/app.xml" },
|
1059
|
-
{ type: RelationshipTypes.CoreProperties, target: "docProps/core.xml" },
|
1060
|
-
{ type: RelationshipTypes.CustomProperties, target: "docProps/custom.xml" }
|
1061
|
-
];
|
1062
|
-
class WordDocument {
|
1063
|
-
constructor() {
|
1064
|
-
this.parts = [];
|
1065
|
-
this.partsMap = {};
|
1066
|
-
}
|
1067
|
-
static async load(blob, parser, options) {
|
1068
|
-
var d = new WordDocument();
|
1069
|
-
d._options = options;
|
1070
|
-
d._parser = parser;
|
1071
|
-
d._package = await OpenXmlPackage.load(blob, options);
|
1072
|
-
d.rels = await d._package.loadRelationships();
|
1073
|
-
await Promise.all(topLevelRels.map((rel) => {
|
1074
|
-
const r = d.rels.find((x) => x.type === rel.type) ?? rel;
|
1075
|
-
return d.loadRelationshipPart(r.target, r.type);
|
1076
|
-
}));
|
1077
|
-
return d;
|
1078
|
-
}
|
1079
|
-
save(type = "blob") {
|
1080
|
-
return this._package.save(type);
|
1081
|
-
}
|
1082
|
-
async loadRelationshipPart(path, type) {
|
1083
|
-
var _a;
|
1084
|
-
if (this.partsMap[path])
|
1085
|
-
return this.partsMap[path];
|
1086
|
-
if (!this._package.get(path))
|
1087
|
-
return null;
|
1088
|
-
let part = null;
|
1089
|
-
switch (type) {
|
1090
|
-
case RelationshipTypes.OfficeDocument:
|
1091
|
-
this.documentPart = part = new DocumentPart(this._package, path, this._parser);
|
1092
|
-
break;
|
1093
|
-
case RelationshipTypes.FontTable:
|
1094
|
-
this.fontTablePart = part = new FontTablePart(this._package, path);
|
1095
|
-
break;
|
1096
|
-
case RelationshipTypes.Numbering:
|
1097
|
-
this.numberingPart = part = new NumberingPart(this._package, path, this._parser);
|
1098
|
-
break;
|
1099
|
-
case RelationshipTypes.Styles:
|
1100
|
-
this.stylesPart = part = new StylesPart(this._package, path, this._parser);
|
1101
|
-
break;
|
1102
|
-
case RelationshipTypes.Theme:
|
1103
|
-
this.themePart = part = new ThemePart(this._package, path);
|
1104
|
-
break;
|
1105
|
-
case RelationshipTypes.Footnotes:
|
1106
|
-
this.footnotesPart = part = new FootnotesPart(this._package, path, this._parser);
|
1107
|
-
break;
|
1108
|
-
case RelationshipTypes.Endnotes:
|
1109
|
-
this.endnotesPart = part = new EndnotesPart(this._package, path, this._parser);
|
1110
|
-
break;
|
1111
|
-
case RelationshipTypes.Footer:
|
1112
|
-
part = new FooterPart(this._package, path, this._parser);
|
1113
|
-
break;
|
1114
|
-
case RelationshipTypes.Header:
|
1115
|
-
part = new HeaderPart(this._package, path, this._parser);
|
1116
|
-
break;
|
1117
|
-
case RelationshipTypes.CoreProperties:
|
1118
|
-
this.corePropsPart = part = new CorePropsPart(this._package, path);
|
1119
|
-
break;
|
1120
|
-
case RelationshipTypes.ExtendedProperties:
|
1121
|
-
this.extendedPropsPart = part = new ExtendedPropsPart(this._package, path);
|
1122
|
-
break;
|
1123
|
-
case RelationshipTypes.CustomProperties:
|
1124
|
-
part = new CustomPropsPart(this._package, path);
|
1125
|
-
break;
|
1126
|
-
case RelationshipTypes.Settings:
|
1127
|
-
this.settingsPart = part = new SettingsPart(this._package, path);
|
1128
|
-
break;
|
1129
|
-
case RelationshipTypes.Comments:
|
1130
|
-
this.commentsPart = part = new CommentsPart(this._package, path, this._parser);
|
1131
|
-
break;
|
1132
|
-
case RelationshipTypes.CommentsExtended:
|
1133
|
-
this.commentsExtendedPart = part = new CommentsExtendedPart(this._package, path);
|
1134
|
-
break;
|
1135
|
-
}
|
1136
|
-
if (part == null)
|
1137
|
-
return Promise.resolve(null);
|
1138
|
-
this.partsMap[path] = part;
|
1139
|
-
this.parts.push(part);
|
1140
|
-
await part.load();
|
1141
|
-
if (((_a = part.rels) == null ? void 0 : _a.length) > 0) {
|
1142
|
-
const [folder] = splitPath(part.path);
|
1143
|
-
await Promise.all(part.rels.map((rel) => this.loadRelationshipPart(resolvePath(rel.target, folder), rel.type)));
|
1144
|
-
}
|
1145
|
-
return part;
|
1146
|
-
}
|
1147
|
-
async loadDocumentImage(id, part) {
|
1148
|
-
const x = await this.loadResource(part ?? this.documentPart, id, "blob");
|
1149
|
-
return this.blobToURL(x);
|
1150
|
-
}
|
1151
|
-
async loadNumberingImage(id) {
|
1152
|
-
const x = await this.loadResource(this.numberingPart, id, "blob");
|
1153
|
-
return this.blobToURL(x);
|
1154
|
-
}
|
1155
|
-
async loadFont(id, key) {
|
1156
|
-
const x = await this.loadResource(this.fontTablePart, id, "uint8array");
|
1157
|
-
return x ? this.blobToURL(new Blob([deobfuscate(x, key)])) : x;
|
1158
|
-
}
|
1159
|
-
blobToURL(blob) {
|
1160
|
-
if (!blob)
|
1161
|
-
return null;
|
1162
|
-
if (this._options.useBase64URL) {
|
1163
|
-
return blobToBase64(blob);
|
1164
|
-
}
|
1165
|
-
return URL.createObjectURL(blob);
|
1166
|
-
}
|
1167
|
-
findPartByRelId(id, basePart = null) {
|
1168
|
-
var rel = (basePart.rels ?? this.rels).find((r) => r.id == id);
|
1169
|
-
const folder = basePart ? splitPath(basePart.path)[0] : "";
|
1170
|
-
return rel ? this.partsMap[resolvePath(rel.target, folder)] : null;
|
1171
|
-
}
|
1172
|
-
getPathById(part, id) {
|
1173
|
-
const rel = part.rels.find((x) => x.id == id);
|
1174
|
-
const [folder] = splitPath(part.path);
|
1175
|
-
return rel ? resolvePath(rel.target, folder) : null;
|
1176
|
-
}
|
1177
|
-
loadResource(part, id, outputType) {
|
1178
|
-
const path = this.getPathById(part, id);
|
1179
|
-
return path ? this._package.load(path, outputType) : Promise.resolve(null);
|
1180
|
-
}
|
1181
|
-
}
|
1182
|
-
function deobfuscate(data, guidKey) {
|
1183
|
-
const len = 16;
|
1184
|
-
const trimmed = guidKey.replace(/{|}|-/g, "");
|
1185
|
-
const numbers = new Array(len);
|
1186
|
-
for (let i = 0; i < len; i++)
|
1187
|
-
numbers[len - i - 1] = parseInt(trimmed.substr(i * 2, 2), 16);
|
1188
|
-
for (let i = 0; i < 32; i++)
|
1189
|
-
data[i] = data[i] ^ numbers[i % len];
|
1190
|
-
return data;
|
1191
|
-
}
|
1192
|
-
function parseBookmarkStart(elem, xml) {
|
1193
|
-
return {
|
1194
|
-
type: DomType.BookmarkStart,
|
1195
|
-
id: xml.attr(elem, "id"),
|
1196
|
-
name: xml.attr(elem, "name"),
|
1197
|
-
colFirst: xml.intAttr(elem, "colFirst"),
|
1198
|
-
colLast: xml.intAttr(elem, "colLast")
|
1199
|
-
};
|
1200
|
-
}
|
1201
|
-
function parseBookmarkEnd(elem, xml) {
|
1202
|
-
return {
|
1203
|
-
type: DomType.BookmarkEnd,
|
1204
|
-
id: xml.attr(elem, "id")
|
1205
|
-
};
|
1206
|
-
}
|
1207
|
-
class VmlElement extends OpenXmlElementBase {
|
1208
|
-
constructor() {
|
1209
|
-
super(...arguments);
|
1210
|
-
this.type = DomType.VmlElement;
|
1211
|
-
this.attrs = {};
|
1212
|
-
}
|
1213
|
-
}
|
1214
|
-
function parseVmlElement(elem, parser) {
|
1215
|
-
var result = new VmlElement();
|
1216
|
-
switch (elem.localName) {
|
1217
|
-
case "rect":
|
1218
|
-
result.tagName = "rect";
|
1219
|
-
Object.assign(result.attrs, { width: "100%", height: "100%" });
|
1220
|
-
break;
|
1221
|
-
case "oval":
|
1222
|
-
result.tagName = "ellipse";
|
1223
|
-
Object.assign(result.attrs, { cx: "50%", cy: "50%", rx: "50%", ry: "50%" });
|
1224
|
-
break;
|
1225
|
-
case "line":
|
1226
|
-
result.tagName = "line";
|
1227
|
-
break;
|
1228
|
-
case "shape":
|
1229
|
-
result.tagName = "g";
|
1230
|
-
break;
|
1231
|
-
case "textbox":
|
1232
|
-
result.tagName = "foreignObject";
|
1233
|
-
Object.assign(result.attrs, { width: "100%", height: "100%" });
|
1234
|
-
break;
|
1235
|
-
default:
|
1236
|
-
return null;
|
1237
|
-
}
|
1238
|
-
for (const at of globalXmlParser.attrs(elem)) {
|
1239
|
-
switch (at.localName) {
|
1240
|
-
case "style":
|
1241
|
-
result.cssStyleText = at.value;
|
1242
|
-
break;
|
1243
|
-
case "fillcolor":
|
1244
|
-
result.attrs.fill = at.value;
|
1245
|
-
break;
|
1246
|
-
case "from":
|
1247
|
-
const [x1, y1] = parsePoint(at.value);
|
1248
|
-
Object.assign(result.attrs, { x1, y1 });
|
1249
|
-
break;
|
1250
|
-
case "to":
|
1251
|
-
const [x2, y2] = parsePoint(at.value);
|
1252
|
-
Object.assign(result.attrs, { x2, y2 });
|
1253
|
-
break;
|
1254
|
-
}
|
1255
|
-
}
|
1256
|
-
for (const el of globalXmlParser.elements(elem)) {
|
1257
|
-
switch (el.localName) {
|
1258
|
-
case "stroke":
|
1259
|
-
Object.assign(result.attrs, parseStroke(el));
|
1260
|
-
break;
|
1261
|
-
case "fill":
|
1262
|
-
Object.assign(result.attrs, parseFill());
|
1263
|
-
break;
|
1264
|
-
case "imagedata":
|
1265
|
-
result.tagName = "image";
|
1266
|
-
Object.assign(result.attrs, { width: "100%", height: "100%" });
|
1267
|
-
result.imageHref = {
|
1268
|
-
id: globalXmlParser.attr(el, "id"),
|
1269
|
-
title: globalXmlParser.attr(el, "title")
|
1270
|
-
};
|
1271
|
-
break;
|
1272
|
-
case "txbxContent":
|
1273
|
-
result.children.push(...parser.parseBodyElements(el));
|
1274
|
-
break;
|
1275
|
-
default:
|
1276
|
-
const child = parseVmlElement(el, parser);
|
1277
|
-
child && result.children.push(child);
|
1278
|
-
break;
|
1279
|
-
}
|
1280
|
-
}
|
1281
|
-
return result;
|
1282
|
-
}
|
1283
|
-
function parseStroke(el) {
|
1284
|
-
return {
|
1285
|
-
"stroke": globalXmlParser.attr(el, "color"),
|
1286
|
-
"stroke-width": globalXmlParser.lengthAttr(el, "weight", LengthUsage.Emu) ?? "1px"
|
1287
|
-
};
|
1288
|
-
}
|
1289
|
-
function parseFill(el) {
|
1290
|
-
return {};
|
1291
|
-
}
|
1292
|
-
function parsePoint(val) {
|
1293
|
-
return val.split(",");
|
1294
|
-
}
|
1295
|
-
class WmlComment extends OpenXmlElementBase {
|
1296
|
-
constructor() {
|
1297
|
-
super(...arguments);
|
1298
|
-
this.type = DomType.Comment;
|
1299
|
-
}
|
1300
|
-
}
|
1301
|
-
class WmlCommentReference extends OpenXmlElementBase {
|
1302
|
-
constructor(id) {
|
1303
|
-
super();
|
1304
|
-
this.id = id;
|
1305
|
-
this.type = DomType.CommentReference;
|
1306
|
-
}
|
1307
|
-
}
|
1308
|
-
class WmlCommentRangeStart extends OpenXmlElementBase {
|
1309
|
-
constructor(id) {
|
1310
|
-
super();
|
1311
|
-
this.id = id;
|
1312
|
-
this.type = DomType.CommentRangeStart;
|
1313
|
-
}
|
1314
|
-
}
|
1315
|
-
class WmlCommentRangeEnd extends OpenXmlElementBase {
|
1316
|
-
constructor(id) {
|
1317
|
-
super();
|
1318
|
-
this.id = id;
|
1319
|
-
this.type = DomType.CommentRangeEnd;
|
1320
|
-
}
|
1321
|
-
}
|
1322
|
-
var autos = {
|
1323
|
-
shd: "inherit",
|
1324
|
-
color: "black",
|
1325
|
-
borderColor: "black",
|
1326
|
-
highlight: "transparent"
|
1327
|
-
};
|
1328
|
-
const supportedNamespaceURIs = [];
|
1329
|
-
const mmlTagMap = {
|
1330
|
-
"oMath": DomType.MmlMath,
|
1331
|
-
"oMathPara": DomType.MmlMathParagraph,
|
1332
|
-
"f": DomType.MmlFraction,
|
1333
|
-
"func": DomType.MmlFunction,
|
1334
|
-
"fName": DomType.MmlFunctionName,
|
1335
|
-
"num": DomType.MmlNumerator,
|
1336
|
-
"den": DomType.MmlDenominator,
|
1337
|
-
"rad": DomType.MmlRadical,
|
1338
|
-
"deg": DomType.MmlDegree,
|
1339
|
-
"e": DomType.MmlBase,
|
1340
|
-
"sSup": DomType.MmlSuperscript,
|
1341
|
-
"sSub": DomType.MmlSubscript,
|
1342
|
-
"sPre": DomType.MmlPreSubSuper,
|
1343
|
-
"sup": DomType.MmlSuperArgument,
|
1344
|
-
"sub": DomType.MmlSubArgument,
|
1345
|
-
"d": DomType.MmlDelimiter,
|
1346
|
-
"nary": DomType.MmlNary,
|
1347
|
-
"eqArr": DomType.MmlEquationArray,
|
1348
|
-
"lim": DomType.MmlLimit,
|
1349
|
-
"limLow": DomType.MmlLimitLower,
|
1350
|
-
"m": DomType.MmlMatrix,
|
1351
|
-
"mr": DomType.MmlMatrixRow,
|
1352
|
-
"box": DomType.MmlBox,
|
1353
|
-
"bar": DomType.MmlBar,
|
1354
|
-
"groupChr": DomType.MmlGroupChar
|
1355
|
-
};
|
1356
|
-
class DocumentParser {
|
1357
|
-
constructor(options) {
|
1358
|
-
this.options = {
|
1359
|
-
ignoreWidth: false,
|
1360
|
-
debug: false,
|
1361
|
-
...options
|
1362
|
-
};
|
1363
|
-
}
|
1364
|
-
parseNotes(xmlDoc, elemName, elemClass) {
|
1365
|
-
var result = [];
|
1366
|
-
for (let el of globalXmlParser.elements(xmlDoc, elemName)) {
|
1367
|
-
const node = new elemClass();
|
1368
|
-
node.id = globalXmlParser.attr(el, "id");
|
1369
|
-
node.noteType = globalXmlParser.attr(el, "type");
|
1370
|
-
node.children = this.parseBodyElements(el);
|
1371
|
-
result.push(node);
|
1372
|
-
}
|
1373
|
-
return result;
|
1374
|
-
}
|
1375
|
-
parseComments(xmlDoc) {
|
1376
|
-
var result = [];
|
1377
|
-
for (let el of globalXmlParser.elements(xmlDoc, "comment")) {
|
1378
|
-
const item = new WmlComment();
|
1379
|
-
item.id = globalXmlParser.attr(el, "id");
|
1380
|
-
item.author = globalXmlParser.attr(el, "author");
|
1381
|
-
item.initials = globalXmlParser.attr(el, "initials");
|
1382
|
-
item.date = globalXmlParser.attr(el, "date");
|
1383
|
-
item.children = this.parseBodyElements(el);
|
1384
|
-
result.push(item);
|
1385
|
-
}
|
1386
|
-
return result;
|
1387
|
-
}
|
1388
|
-
parseDocumentFile(xmlDoc) {
|
1389
|
-
var xbody = globalXmlParser.element(xmlDoc, "body");
|
1390
|
-
var background = globalXmlParser.element(xmlDoc, "background");
|
1391
|
-
var sectPr = globalXmlParser.element(xbody, "sectPr");
|
1392
|
-
return {
|
1393
|
-
type: DomType.Document,
|
1394
|
-
children: this.parseBodyElements(xbody),
|
1395
|
-
props: sectPr ? parseSectionProperties(sectPr, globalXmlParser) : {},
|
1396
|
-
cssStyle: background ? this.parseBackground(background) : {}
|
1397
|
-
};
|
1398
|
-
}
|
1399
|
-
parseBackground(elem) {
|
1400
|
-
var result = {};
|
1401
|
-
var color = xmlUtil.colorAttr(elem, "color");
|
1402
|
-
if (color) {
|
1403
|
-
result["background-color"] = color;
|
1404
|
-
}
|
1405
|
-
return result;
|
1406
|
-
}
|
1407
|
-
parseBodyElements(element) {
|
1408
|
-
var children = [];
|
1409
|
-
for (let elem of globalXmlParser.elements(element)) {
|
1410
|
-
switch (elem.localName) {
|
1411
|
-
case "p":
|
1412
|
-
children.push(this.parseParagraph(elem));
|
1413
|
-
break;
|
1414
|
-
case "tbl":
|
1415
|
-
children.push(this.parseTable(elem));
|
1416
|
-
break;
|
1417
|
-
case "sdt":
|
1418
|
-
children.push(...this.parseSdt(elem, (e) => this.parseBodyElements(e)));
|
1419
|
-
break;
|
1420
|
-
}
|
1421
|
-
}
|
1422
|
-
return children;
|
1423
|
-
}
|
1424
|
-
parseStylesFile(xstyles) {
|
1425
|
-
var result = [];
|
1426
|
-
xmlUtil.foreach(xstyles, (n) => {
|
1427
|
-
switch (n.localName) {
|
1428
|
-
case "style":
|
1429
|
-
result.push(this.parseStyle(n));
|
1430
|
-
break;
|
1431
|
-
case "docDefaults":
|
1432
|
-
result.push(this.parseDefaultStyles(n));
|
1433
|
-
break;
|
1434
|
-
}
|
1435
|
-
});
|
1436
|
-
return result;
|
1437
|
-
}
|
1438
|
-
parseDefaultStyles(node) {
|
1439
|
-
var result = {
|
1440
|
-
id: null,
|
1441
|
-
name: null,
|
1442
|
-
target: null,
|
1443
|
-
basedOn: null,
|
1444
|
-
styles: []
|
1445
|
-
};
|
1446
|
-
xmlUtil.foreach(node, (c) => {
|
1447
|
-
switch (c.localName) {
|
1448
|
-
case "rPrDefault":
|
1449
|
-
var rPr = globalXmlParser.element(c, "rPr");
|
1450
|
-
if (rPr)
|
1451
|
-
result.styles.push({
|
1452
|
-
target: "span",
|
1453
|
-
values: this.parseDefaultProperties(rPr, {})
|
1454
|
-
});
|
1455
|
-
break;
|
1456
|
-
case "pPrDefault":
|
1457
|
-
var pPr = globalXmlParser.element(c, "pPr");
|
1458
|
-
if (pPr)
|
1459
|
-
result.styles.push({
|
1460
|
-
target: "p",
|
1461
|
-
values: this.parseDefaultProperties(pPr, {})
|
1462
|
-
});
|
1463
|
-
break;
|
1464
|
-
}
|
1465
|
-
});
|
1466
|
-
return result;
|
1467
|
-
}
|
1468
|
-
parseStyle(node) {
|
1469
|
-
var result = {
|
1470
|
-
id: globalXmlParser.attr(node, "styleId"),
|
1471
|
-
isDefault: globalXmlParser.boolAttr(node, "default"),
|
1472
|
-
name: null,
|
1473
|
-
target: null,
|
1474
|
-
basedOn: null,
|
1475
|
-
styles: [],
|
1476
|
-
linked: null
|
1477
|
-
};
|
1478
|
-
switch (globalXmlParser.attr(node, "type")) {
|
1479
|
-
case "paragraph":
|
1480
|
-
result.target = "p";
|
1481
|
-
break;
|
1482
|
-
case "table":
|
1483
|
-
result.target = "table";
|
1484
|
-
break;
|
1485
|
-
case "character":
|
1486
|
-
result.target = "span";
|
1487
|
-
break;
|
1488
|
-
}
|
1489
|
-
xmlUtil.foreach(node, (n) => {
|
1490
|
-
switch (n.localName) {
|
1491
|
-
case "basedOn":
|
1492
|
-
result.basedOn = globalXmlParser.attr(n, "val");
|
1493
|
-
break;
|
1494
|
-
case "name":
|
1495
|
-
result.name = globalXmlParser.attr(n, "val");
|
1496
|
-
break;
|
1497
|
-
case "link":
|
1498
|
-
result.linked = globalXmlParser.attr(n, "val");
|
1499
|
-
break;
|
1500
|
-
case "next":
|
1501
|
-
result.next = globalXmlParser.attr(n, "val");
|
1502
|
-
break;
|
1503
|
-
case "aliases":
|
1504
|
-
result.aliases = globalXmlParser.attr(n, "val").split(",");
|
1505
|
-
break;
|
1506
|
-
case "pPr":
|
1507
|
-
result.styles.push({
|
1508
|
-
target: "p",
|
1509
|
-
values: this.parseDefaultProperties(n, {})
|
1510
|
-
});
|
1511
|
-
result.paragraphProps = parseParagraphProperties(n, globalXmlParser);
|
1512
|
-
break;
|
1513
|
-
case "rPr":
|
1514
|
-
result.styles.push({
|
1515
|
-
target: "span",
|
1516
|
-
values: this.parseDefaultProperties(n, {})
|
1517
|
-
});
|
1518
|
-
result.runProps = parseRunProperties(n, globalXmlParser);
|
1519
|
-
break;
|
1520
|
-
case "tblPr":
|
1521
|
-
case "tcPr":
|
1522
|
-
result.styles.push({
|
1523
|
-
target: "td",
|
1524
|
-
values: this.parseDefaultProperties(n, {})
|
1525
|
-
});
|
1526
|
-
break;
|
1527
|
-
case "tblStylePr":
|
1528
|
-
for (let s of this.parseTableStyle(n))
|
1529
|
-
result.styles.push(s);
|
1530
|
-
break;
|
1531
|
-
case "rsid":
|
1532
|
-
case "qFormat":
|
1533
|
-
case "hidden":
|
1534
|
-
case "semiHidden":
|
1535
|
-
case "unhideWhenUsed":
|
1536
|
-
case "autoRedefine":
|
1537
|
-
case "uiPriority":
|
1538
|
-
break;
|
1539
|
-
default:
|
1540
|
-
this.options.debug && console.warn(`DOCX: Unknown style element: ${n.localName}`);
|
1541
|
-
}
|
1542
|
-
});
|
1543
|
-
return result;
|
1544
|
-
}
|
1545
|
-
parseTableStyle(node) {
|
1546
|
-
var result = [];
|
1547
|
-
var type = globalXmlParser.attr(node, "type");
|
1548
|
-
var selector = "";
|
1549
|
-
var modificator = "";
|
1550
|
-
switch (type) {
|
1551
|
-
case "firstRow":
|
1552
|
-
modificator = ".first-row";
|
1553
|
-
selector = "tr.first-row td";
|
1554
|
-
break;
|
1555
|
-
case "lastRow":
|
1556
|
-
modificator = ".last-row";
|
1557
|
-
selector = "tr.last-row td";
|
1558
|
-
break;
|
1559
|
-
case "firstCol":
|
1560
|
-
modificator = ".first-col";
|
1561
|
-
selector = "td.first-col";
|
1562
|
-
break;
|
1563
|
-
case "lastCol":
|
1564
|
-
modificator = ".last-col";
|
1565
|
-
selector = "td.last-col";
|
1566
|
-
break;
|
1567
|
-
case "band1Vert":
|
1568
|
-
modificator = ":not(.no-vband)";
|
1569
|
-
selector = "td.odd-col";
|
1570
|
-
break;
|
1571
|
-
case "band2Vert":
|
1572
|
-
modificator = ":not(.no-vband)";
|
1573
|
-
selector = "td.even-col";
|
1574
|
-
break;
|
1575
|
-
case "band1Horz":
|
1576
|
-
modificator = ":not(.no-hband)";
|
1577
|
-
selector = "tr.odd-row";
|
1578
|
-
break;
|
1579
|
-
case "band2Horz":
|
1580
|
-
modificator = ":not(.no-hband)";
|
1581
|
-
selector = "tr.even-row";
|
1582
|
-
break;
|
1583
|
-
default:
|
1584
|
-
return [];
|
1585
|
-
}
|
1586
|
-
xmlUtil.foreach(node, (n) => {
|
1587
|
-
switch (n.localName) {
|
1588
|
-
case "pPr":
|
1589
|
-
result.push({
|
1590
|
-
target: `${selector} p`,
|
1591
|
-
mod: modificator,
|
1592
|
-
values: this.parseDefaultProperties(n, {})
|
1593
|
-
});
|
1594
|
-
break;
|
1595
|
-
case "rPr":
|
1596
|
-
result.push({
|
1597
|
-
target: `${selector} span`,
|
1598
|
-
mod: modificator,
|
1599
|
-
values: this.parseDefaultProperties(n, {})
|
1600
|
-
});
|
1601
|
-
break;
|
1602
|
-
case "tblPr":
|
1603
|
-
case "tcPr":
|
1604
|
-
result.push({
|
1605
|
-
target: selector,
|
1606
|
-
mod: modificator,
|
1607
|
-
values: this.parseDefaultProperties(n, {})
|
1608
|
-
});
|
1609
|
-
break;
|
1610
|
-
}
|
1611
|
-
});
|
1612
|
-
return result;
|
1613
|
-
}
|
1614
|
-
parseNumberingFile(xnums) {
|
1615
|
-
var result = [];
|
1616
|
-
var mapping = {};
|
1617
|
-
var bullets = [];
|
1618
|
-
xmlUtil.foreach(xnums, (n) => {
|
1619
|
-
switch (n.localName) {
|
1620
|
-
case "abstractNum":
|
1621
|
-
this.parseAbstractNumbering(n, bullets).forEach((x) => result.push(x));
|
1622
|
-
break;
|
1623
|
-
case "numPicBullet":
|
1624
|
-
bullets.push(this.parseNumberingPicBullet(n));
|
1625
|
-
break;
|
1626
|
-
case "num":
|
1627
|
-
var numId = globalXmlParser.attr(n, "numId");
|
1628
|
-
var abstractNumId = globalXmlParser.elementAttr(n, "abstractNumId", "val");
|
1629
|
-
mapping[abstractNumId] = numId;
|
1630
|
-
break;
|
1631
|
-
}
|
1632
|
-
});
|
1633
|
-
result.forEach((x) => x.id = mapping[x.id]);
|
1634
|
-
return result;
|
1635
|
-
}
|
1636
|
-
parseNumberingPicBullet(elem) {
|
1637
|
-
var pict = globalXmlParser.element(elem, "pict");
|
1638
|
-
var shape = pict && globalXmlParser.element(pict, "shape");
|
1639
|
-
var imagedata = shape && globalXmlParser.element(shape, "imagedata");
|
1640
|
-
return imagedata ? {
|
1641
|
-
id: globalXmlParser.intAttr(elem, "numPicBulletId"),
|
1642
|
-
src: globalXmlParser.attr(imagedata, "id"),
|
1643
|
-
style: globalXmlParser.attr(shape, "style")
|
1644
|
-
} : null;
|
1645
|
-
}
|
1646
|
-
parseAbstractNumbering(node, bullets) {
|
1647
|
-
var result = [];
|
1648
|
-
var id = globalXmlParser.attr(node, "abstractNumId");
|
1649
|
-
xmlUtil.foreach(node, (n) => {
|
1650
|
-
switch (n.localName) {
|
1651
|
-
case "lvl":
|
1652
|
-
result.push(this.parseNumberingLevel(id, n, bullets));
|
1653
|
-
break;
|
1654
|
-
}
|
1655
|
-
});
|
1656
|
-
return result;
|
1657
|
-
}
|
1658
|
-
parseNumberingLevel(id, node, bullets) {
|
1659
|
-
var result = {
|
1660
|
-
id,
|
1661
|
-
level: globalXmlParser.intAttr(node, "ilvl"),
|
1662
|
-
start: 1,
|
1663
|
-
pStyleName: void 0,
|
1664
|
-
pStyle: {},
|
1665
|
-
rStyle: {},
|
1666
|
-
suff: "tab"
|
1667
|
-
};
|
1668
|
-
xmlUtil.foreach(node, (n) => {
|
1669
|
-
switch (n.localName) {
|
1670
|
-
case "start":
|
1671
|
-
result.start = globalXmlParser.intAttr(n, "val");
|
1672
|
-
break;
|
1673
|
-
case "pPr":
|
1674
|
-
this.parseDefaultProperties(n, result.pStyle);
|
1675
|
-
break;
|
1676
|
-
case "rPr":
|
1677
|
-
this.parseDefaultProperties(n, result.rStyle);
|
1678
|
-
break;
|
1679
|
-
case "lvlPicBulletId":
|
1680
|
-
var id2 = globalXmlParser.intAttr(n, "val");
|
1681
|
-
result.bullet = bullets.find((x) => (x == null ? void 0 : x.id) == id2);
|
1682
|
-
break;
|
1683
|
-
case "lvlText":
|
1684
|
-
result.levelText = globalXmlParser.attr(n, "val");
|
1685
|
-
break;
|
1686
|
-
case "pStyle":
|
1687
|
-
result.pStyleName = globalXmlParser.attr(n, "val");
|
1688
|
-
break;
|
1689
|
-
case "numFmt":
|
1690
|
-
result.format = globalXmlParser.attr(n, "val");
|
1691
|
-
break;
|
1692
|
-
case "suff":
|
1693
|
-
result.suff = globalXmlParser.attr(n, "val");
|
1694
|
-
break;
|
1695
|
-
}
|
1696
|
-
});
|
1697
|
-
return result;
|
1698
|
-
}
|
1699
|
-
parseSdt(node, parser) {
|
1700
|
-
const sdtContent = globalXmlParser.element(node, "sdtContent");
|
1701
|
-
return sdtContent ? parser(sdtContent) : [];
|
1702
|
-
}
|
1703
|
-
parseInserted(node, parentParser) {
|
1704
|
-
var _a;
|
1705
|
-
return {
|
1706
|
-
type: DomType.Inserted,
|
1707
|
-
children: ((_a = parentParser(node)) == null ? void 0 : _a.children) ?? []
|
1708
|
-
};
|
1709
|
-
}
|
1710
|
-
parseDeleted(node, parentParser) {
|
1711
|
-
var _a;
|
1712
|
-
return {
|
1713
|
-
type: DomType.Deleted,
|
1714
|
-
children: ((_a = parentParser(node)) == null ? void 0 : _a.children) ?? []
|
1715
|
-
};
|
1716
|
-
}
|
1717
|
-
parseParagraph(node) {
|
1718
|
-
var result = { type: DomType.Paragraph, children: [] };
|
1719
|
-
for (let el of globalXmlParser.elements(node)) {
|
1720
|
-
switch (el.localName) {
|
1721
|
-
case "pPr":
|
1722
|
-
this.parseParagraphProperties(el, result);
|
1723
|
-
break;
|
1724
|
-
case "r":
|
1725
|
-
result.children.push(this.parseRun(el, result));
|
1726
|
-
break;
|
1727
|
-
case "hyperlink":
|
1728
|
-
result.children.push(this.parseHyperlink(el, result));
|
1729
|
-
break;
|
1730
|
-
case "smartTag":
|
1731
|
-
result.children.push(this.parseSmartTag(el, result));
|
1732
|
-
break;
|
1733
|
-
case "bookmarkStart":
|
1734
|
-
result.children.push(parseBookmarkStart(el, globalXmlParser));
|
1735
|
-
break;
|
1736
|
-
case "bookmarkEnd":
|
1737
|
-
result.children.push(parseBookmarkEnd(el, globalXmlParser));
|
1738
|
-
break;
|
1739
|
-
case "commentRangeStart":
|
1740
|
-
result.children.push(new WmlCommentRangeStart(globalXmlParser.attr(el, "id")));
|
1741
|
-
break;
|
1742
|
-
case "commentRangeEnd":
|
1743
|
-
result.children.push(new WmlCommentRangeEnd(globalXmlParser.attr(el, "id")));
|
1744
|
-
break;
|
1745
|
-
case "oMath":
|
1746
|
-
case "oMathPara":
|
1747
|
-
result.children.push(this.parseMathElement(el));
|
1748
|
-
break;
|
1749
|
-
case "sdt":
|
1750
|
-
result.children.push(...this.parseSdt(el, (e) => this.parseParagraph(e).children));
|
1751
|
-
break;
|
1752
|
-
case "ins":
|
1753
|
-
result.children.push(this.parseInserted(el, (e) => this.parseParagraph(e)));
|
1754
|
-
break;
|
1755
|
-
case "del":
|
1756
|
-
result.children.push(this.parseDeleted(el, (e) => this.parseParagraph(e)));
|
1757
|
-
break;
|
1758
|
-
}
|
1759
|
-
}
|
1760
|
-
return result;
|
1761
|
-
}
|
1762
|
-
parseParagraphProperties(elem, paragraph) {
|
1763
|
-
this.parseDefaultProperties(elem, paragraph.cssStyle = {}, null, (c) => {
|
1764
|
-
if (parseParagraphProperty(c, paragraph, globalXmlParser))
|
1765
|
-
return true;
|
1766
|
-
switch (c.localName) {
|
1767
|
-
case "pStyle":
|
1768
|
-
paragraph.styleName = globalXmlParser.attr(c, "val");
|
1769
|
-
break;
|
1770
|
-
case "cnfStyle":
|
1771
|
-
paragraph.className = values.classNameOfCnfStyle(c);
|
1772
|
-
break;
|
1773
|
-
case "framePr":
|
1774
|
-
this.parseFrame(c, paragraph);
|
1775
|
-
break;
|
1776
|
-
case "rPr":
|
1777
|
-
break;
|
1778
|
-
default:
|
1779
|
-
return false;
|
1780
|
-
}
|
1781
|
-
return true;
|
1782
|
-
});
|
1783
|
-
}
|
1784
|
-
parseFrame(node, paragraph) {
|
1785
|
-
var dropCap = globalXmlParser.attr(node, "dropCap");
|
1786
|
-
if (dropCap == "drop")
|
1787
|
-
paragraph.cssStyle["float"] = "left";
|
1788
|
-
}
|
1789
|
-
parseHyperlink(node, parent) {
|
1790
|
-
var result = { type: DomType.Hyperlink, parent, children: [] };
|
1791
|
-
var anchor = globalXmlParser.attr(node, "anchor");
|
1792
|
-
var relId = globalXmlParser.attr(node, "id");
|
1793
|
-
if (anchor)
|
1794
|
-
result.href = "#" + anchor;
|
1795
|
-
if (relId)
|
1796
|
-
result.id = relId;
|
1797
|
-
xmlUtil.foreach(node, (c) => {
|
1798
|
-
switch (c.localName) {
|
1799
|
-
case "r":
|
1800
|
-
result.children.push(this.parseRun(c, result));
|
1801
|
-
break;
|
1802
|
-
}
|
1803
|
-
});
|
1804
|
-
return result;
|
1805
|
-
}
|
1806
|
-
parseSmartTag(node, parent) {
|
1807
|
-
var result = { type: DomType.SmartTag, parent, children: [] };
|
1808
|
-
var uri = globalXmlParser.attr(node, "uri");
|
1809
|
-
var element = globalXmlParser.attr(node, "element");
|
1810
|
-
if (uri)
|
1811
|
-
result.uri = uri;
|
1812
|
-
if (element)
|
1813
|
-
result.element = element;
|
1814
|
-
xmlUtil.foreach(node, (c) => {
|
1815
|
-
switch (c.localName) {
|
1816
|
-
case "r":
|
1817
|
-
result.children.push(this.parseRun(c, result));
|
1818
|
-
break;
|
1819
|
-
}
|
1820
|
-
});
|
1821
|
-
return result;
|
1822
|
-
}
|
1823
|
-
parseRun(node, parent) {
|
1824
|
-
var result = { type: DomType.Run, parent, children: [] };
|
1825
|
-
xmlUtil.foreach(node, (c) => {
|
1826
|
-
c = this.checkAlternateContent(c);
|
1827
|
-
switch (c.localName) {
|
1828
|
-
case "t":
|
1829
|
-
result.children.push({
|
1830
|
-
type: DomType.Text,
|
1831
|
-
text: c.textContent
|
1832
|
-
});
|
1833
|
-
break;
|
1834
|
-
case "delText":
|
1835
|
-
result.children.push({
|
1836
|
-
type: DomType.DeletedText,
|
1837
|
-
text: c.textContent
|
1838
|
-
});
|
1839
|
-
break;
|
1840
|
-
case "commentReference":
|
1841
|
-
result.children.push(new WmlCommentReference(globalXmlParser.attr(c, "id")));
|
1842
|
-
break;
|
1843
|
-
case "fldSimple":
|
1844
|
-
result.children.push({
|
1845
|
-
type: DomType.SimpleField,
|
1846
|
-
instruction: globalXmlParser.attr(c, "instr"),
|
1847
|
-
lock: globalXmlParser.boolAttr(c, "lock", false),
|
1848
|
-
dirty: globalXmlParser.boolAttr(c, "dirty", false)
|
1849
|
-
});
|
1850
|
-
break;
|
1851
|
-
case "instrText":
|
1852
|
-
result.fieldRun = true;
|
1853
|
-
result.children.push({
|
1854
|
-
type: DomType.Instruction,
|
1855
|
-
text: c.textContent
|
1856
|
-
});
|
1857
|
-
break;
|
1858
|
-
case "fldChar":
|
1859
|
-
result.fieldRun = true;
|
1860
|
-
result.children.push({
|
1861
|
-
type: DomType.ComplexField,
|
1862
|
-
charType: globalXmlParser.attr(c, "fldCharType"),
|
1863
|
-
lock: globalXmlParser.boolAttr(c, "lock", false),
|
1864
|
-
dirty: globalXmlParser.boolAttr(c, "dirty", false)
|
1865
|
-
});
|
1866
|
-
break;
|
1867
|
-
case "noBreakHyphen":
|
1868
|
-
result.children.push({ type: DomType.NoBreakHyphen });
|
1869
|
-
break;
|
1870
|
-
case "br":
|
1871
|
-
result.children.push({
|
1872
|
-
type: DomType.Break,
|
1873
|
-
break: globalXmlParser.attr(c, "type") || "textWrapping"
|
1874
|
-
});
|
1875
|
-
break;
|
1876
|
-
case "lastRenderedPageBreak":
|
1877
|
-
result.children.push({
|
1878
|
-
type: DomType.Break,
|
1879
|
-
break: "lastRenderedPageBreak"
|
1880
|
-
});
|
1881
|
-
break;
|
1882
|
-
case "sym":
|
1883
|
-
result.children.push({
|
1884
|
-
type: DomType.Symbol,
|
1885
|
-
font: globalXmlParser.attr(c, "font"),
|
1886
|
-
char: globalXmlParser.attr(c, "char")
|
1887
|
-
});
|
1888
|
-
break;
|
1889
|
-
case "tab":
|
1890
|
-
result.children.push({ type: DomType.Tab });
|
1891
|
-
break;
|
1892
|
-
case "footnoteReference":
|
1893
|
-
result.children.push({
|
1894
|
-
type: DomType.FootnoteReference,
|
1895
|
-
id: globalXmlParser.attr(c, "id")
|
1896
|
-
});
|
1897
|
-
break;
|
1898
|
-
case "endnoteReference":
|
1899
|
-
result.children.push({
|
1900
|
-
type: DomType.EndnoteReference,
|
1901
|
-
id: globalXmlParser.attr(c, "id")
|
1902
|
-
});
|
1903
|
-
break;
|
1904
|
-
case "drawing":
|
1905
|
-
let d = this.parseDrawing(c);
|
1906
|
-
if (d)
|
1907
|
-
result.children = [d];
|
1908
|
-
break;
|
1909
|
-
case "pict":
|
1910
|
-
result.children.push(this.parseVmlPicture(c));
|
1911
|
-
break;
|
1912
|
-
case "rPr":
|
1913
|
-
this.parseRunProperties(c, result);
|
1914
|
-
break;
|
1915
|
-
}
|
1916
|
-
});
|
1917
|
-
return result;
|
1918
|
-
}
|
1919
|
-
parseMathElement(elem) {
|
1920
|
-
const propsTag = `${elem.localName}Pr`;
|
1921
|
-
const result = { type: mmlTagMap[elem.localName], children: [] };
|
1922
|
-
for (const el of globalXmlParser.elements(elem)) {
|
1923
|
-
const childType = mmlTagMap[el.localName];
|
1924
|
-
if (childType) {
|
1925
|
-
result.children.push(this.parseMathElement(el));
|
1926
|
-
} else if (el.localName == "r") {
|
1927
|
-
var run = this.parseRun(el);
|
1928
|
-
run.type = DomType.MmlRun;
|
1929
|
-
result.children.push(run);
|
1930
|
-
} else if (el.localName == propsTag) {
|
1931
|
-
result.props = this.parseMathProperies(el);
|
1932
|
-
}
|
1933
|
-
}
|
1934
|
-
return result;
|
1935
|
-
}
|
1936
|
-
parseMathProperies(elem) {
|
1937
|
-
const result = {};
|
1938
|
-
for (const el of globalXmlParser.elements(elem)) {
|
1939
|
-
switch (el.localName) {
|
1940
|
-
case "chr":
|
1941
|
-
result.char = globalXmlParser.attr(el, "val");
|
1942
|
-
break;
|
1943
|
-
case "vertJc":
|
1944
|
-
result.verticalJustification = globalXmlParser.attr(el, "val");
|
1945
|
-
break;
|
1946
|
-
case "pos":
|
1947
|
-
result.position = globalXmlParser.attr(el, "val");
|
1948
|
-
break;
|
1949
|
-
case "degHide":
|
1950
|
-
result.hideDegree = globalXmlParser.boolAttr(el, "val");
|
1951
|
-
break;
|
1952
|
-
case "begChr":
|
1953
|
-
result.beginChar = globalXmlParser.attr(el, "val");
|
1954
|
-
break;
|
1955
|
-
case "endChr":
|
1956
|
-
result.endChar = globalXmlParser.attr(el, "val");
|
1957
|
-
break;
|
1958
|
-
}
|
1959
|
-
}
|
1960
|
-
return result;
|
1961
|
-
}
|
1962
|
-
parseRunProperties(elem, run) {
|
1963
|
-
this.parseDefaultProperties(elem, run.cssStyle = {}, null, (c) => {
|
1964
|
-
switch (c.localName) {
|
1965
|
-
case "rStyle":
|
1966
|
-
run.styleName = globalXmlParser.attr(c, "val");
|
1967
|
-
break;
|
1968
|
-
case "vertAlign":
|
1969
|
-
run.verticalAlign = values.valueOfVertAlign(c, true);
|
1970
|
-
break;
|
1971
|
-
default:
|
1972
|
-
return false;
|
1973
|
-
}
|
1974
|
-
return true;
|
1975
|
-
});
|
1976
|
-
}
|
1977
|
-
parseVmlPicture(elem) {
|
1978
|
-
const result = { type: DomType.VmlPicture, children: [] };
|
1979
|
-
for (const el of globalXmlParser.elements(elem)) {
|
1980
|
-
const child = parseVmlElement(el, this);
|
1981
|
-
child && result.children.push(child);
|
1982
|
-
}
|
1983
|
-
return result;
|
1984
|
-
}
|
1985
|
-
checkAlternateContent(elem) {
|
1986
|
-
var _a;
|
1987
|
-
if (elem.localName != "AlternateContent")
|
1988
|
-
return elem;
|
1989
|
-
var choice = globalXmlParser.element(elem, "Choice");
|
1990
|
-
if (choice) {
|
1991
|
-
var requires = globalXmlParser.attr(choice, "Requires");
|
1992
|
-
var namespaceURI = elem.lookupNamespaceURI(requires);
|
1993
|
-
if (supportedNamespaceURIs.includes(namespaceURI))
|
1994
|
-
return choice.firstElementChild;
|
1995
|
-
}
|
1996
|
-
return (_a = globalXmlParser.element(elem, "Fallback")) == null ? void 0 : _a.firstElementChild;
|
1997
|
-
}
|
1998
|
-
parseDrawing(node) {
|
1999
|
-
for (var n of globalXmlParser.elements(node)) {
|
2000
|
-
switch (n.localName) {
|
2001
|
-
case "inline":
|
2002
|
-
case "anchor":
|
2003
|
-
return this.parseDrawingWrapper(n);
|
2004
|
-
}
|
2005
|
-
}
|
2006
|
-
}
|
2007
|
-
parseDrawingWrapper(node) {
|
2008
|
-
var result = { type: DomType.Drawing, children: [], cssStyle: {} };
|
2009
|
-
var isAnchor = node.localName == "anchor";
|
2010
|
-
let wrapType = null;
|
2011
|
-
let simplePos = globalXmlParser.boolAttr(node, "simplePos");
|
2012
|
-
globalXmlParser.boolAttr(node, "behindDoc");
|
2013
|
-
let posX = { relative: "page", align: "left", offset: "0" };
|
2014
|
-
let posY = { relative: "page", align: "top", offset: "0" };
|
2015
|
-
for (var n of globalXmlParser.elements(node)) {
|
2016
|
-
switch (n.localName) {
|
2017
|
-
case "simplePos":
|
2018
|
-
if (simplePos) {
|
2019
|
-
posX.offset = globalXmlParser.lengthAttr(n, "x", LengthUsage.Emu);
|
2020
|
-
posY.offset = globalXmlParser.lengthAttr(n, "y", LengthUsage.Emu);
|
2021
|
-
}
|
2022
|
-
break;
|
2023
|
-
case "extent":
|
2024
|
-
result.cssStyle["width"] = globalXmlParser.lengthAttr(n, "cx", LengthUsage.Emu);
|
2025
|
-
result.cssStyle["height"] = globalXmlParser.lengthAttr(n, "cy", LengthUsage.Emu);
|
2026
|
-
break;
|
2027
|
-
case "positionH":
|
2028
|
-
case "positionV":
|
2029
|
-
if (!simplePos) {
|
2030
|
-
let pos = n.localName == "positionH" ? posX : posY;
|
2031
|
-
var alignNode = globalXmlParser.element(n, "align");
|
2032
|
-
var offsetNode = globalXmlParser.element(n, "posOffset");
|
2033
|
-
pos.relative = globalXmlParser.attr(n, "relativeFrom") ?? pos.relative;
|
2034
|
-
if (alignNode)
|
2035
|
-
pos.align = alignNode.textContent;
|
2036
|
-
if (offsetNode)
|
2037
|
-
pos.offset = xmlUtil.sizeValue(offsetNode, LengthUsage.Emu);
|
2038
|
-
}
|
2039
|
-
break;
|
2040
|
-
case "wrapTopAndBottom":
|
2041
|
-
wrapType = "wrapTopAndBottom";
|
2042
|
-
break;
|
2043
|
-
case "wrapNone":
|
2044
|
-
wrapType = "wrapNone";
|
2045
|
-
break;
|
2046
|
-
case "graphic":
|
2047
|
-
var g = this.parseGraphic(n);
|
2048
|
-
if (g)
|
2049
|
-
result.children.push(g);
|
2050
|
-
break;
|
2051
|
-
}
|
2052
|
-
}
|
2053
|
-
if (wrapType == "wrapTopAndBottom") {
|
2054
|
-
result.cssStyle["display"] = "block";
|
2055
|
-
if (posX.align) {
|
2056
|
-
result.cssStyle["text-align"] = posX.align;
|
2057
|
-
result.cssStyle["width"] = "100%";
|
2058
|
-
}
|
2059
|
-
} else if (wrapType == "wrapNone") {
|
2060
|
-
result.cssStyle["display"] = "block";
|
2061
|
-
result.cssStyle["position"] = "relative";
|
2062
|
-
result.cssStyle["width"] = "0px";
|
2063
|
-
result.cssStyle["height"] = "0px";
|
2064
|
-
if (posX.offset)
|
2065
|
-
result.cssStyle["left"] = posX.offset;
|
2066
|
-
if (posY.offset)
|
2067
|
-
result.cssStyle["top"] = posY.offset;
|
2068
|
-
} else if (isAnchor && (posX.align == "left" || posX.align == "right")) {
|
2069
|
-
result.cssStyle["float"] = posX.align;
|
2070
|
-
}
|
2071
|
-
return result;
|
2072
|
-
}
|
2073
|
-
parseGraphic(elem) {
|
2074
|
-
var graphicData = globalXmlParser.element(elem, "graphicData");
|
2075
|
-
for (let n of globalXmlParser.elements(graphicData)) {
|
2076
|
-
switch (n.localName) {
|
2077
|
-
case "pic":
|
2078
|
-
return this.parsePicture(n);
|
2079
|
-
}
|
2080
|
-
}
|
2081
|
-
return null;
|
2082
|
-
}
|
2083
|
-
parsePicture(elem) {
|
2084
|
-
var result = { type: DomType.Image, src: "", cssStyle: {} };
|
2085
|
-
var blipFill = globalXmlParser.element(elem, "blipFill");
|
2086
|
-
var blip = globalXmlParser.element(blipFill, "blip");
|
2087
|
-
result.src = globalXmlParser.attr(blip, "embed");
|
2088
|
-
var spPr = globalXmlParser.element(elem, "spPr");
|
2089
|
-
var xfrm = globalXmlParser.element(spPr, "xfrm");
|
2090
|
-
result.cssStyle["position"] = "relative";
|
2091
|
-
for (var n of globalXmlParser.elements(xfrm)) {
|
2092
|
-
switch (n.localName) {
|
2093
|
-
case "ext":
|
2094
|
-
result.cssStyle["width"] = globalXmlParser.lengthAttr(n, "cx", LengthUsage.Emu);
|
2095
|
-
result.cssStyle["height"] = globalXmlParser.lengthAttr(n, "cy", LengthUsage.Emu);
|
2096
|
-
break;
|
2097
|
-
case "off":
|
2098
|
-
result.cssStyle["left"] = globalXmlParser.lengthAttr(n, "x", LengthUsage.Emu);
|
2099
|
-
result.cssStyle["top"] = globalXmlParser.lengthAttr(n, "y", LengthUsage.Emu);
|
2100
|
-
break;
|
2101
|
-
}
|
2102
|
-
}
|
2103
|
-
return result;
|
2104
|
-
}
|
2105
|
-
parseTable(node) {
|
2106
|
-
var result = { type: DomType.Table, children: [] };
|
2107
|
-
xmlUtil.foreach(node, (c) => {
|
2108
|
-
switch (c.localName) {
|
2109
|
-
case "tr":
|
2110
|
-
result.children.push(this.parseTableRow(c));
|
2111
|
-
break;
|
2112
|
-
case "tblGrid":
|
2113
|
-
result.columns = this.parseTableColumns(c);
|
2114
|
-
break;
|
2115
|
-
case "tblPr":
|
2116
|
-
this.parseTableProperties(c, result);
|
2117
|
-
break;
|
2118
|
-
}
|
2119
|
-
});
|
2120
|
-
return result;
|
2121
|
-
}
|
2122
|
-
parseTableColumns(node) {
|
2123
|
-
var result = [];
|
2124
|
-
xmlUtil.foreach(node, (n) => {
|
2125
|
-
switch (n.localName) {
|
2126
|
-
case "gridCol":
|
2127
|
-
result.push({ width: globalXmlParser.lengthAttr(n, "w") });
|
2128
|
-
break;
|
2129
|
-
}
|
2130
|
-
});
|
2131
|
-
return result;
|
2132
|
-
}
|
2133
|
-
parseTableProperties(elem, table) {
|
2134
|
-
table.cssStyle = {};
|
2135
|
-
table.cellStyle = {};
|
2136
|
-
this.parseDefaultProperties(elem, table.cssStyle, table.cellStyle, (c) => {
|
2137
|
-
switch (c.localName) {
|
2138
|
-
case "tblStyle":
|
2139
|
-
table.styleName = globalXmlParser.attr(c, "val");
|
2140
|
-
break;
|
2141
|
-
case "tblLook":
|
2142
|
-
table.className = values.classNameOftblLook(c);
|
2143
|
-
break;
|
2144
|
-
case "tblpPr":
|
2145
|
-
this.parseTablePosition(c, table);
|
2146
|
-
break;
|
2147
|
-
case "tblStyleColBandSize":
|
2148
|
-
table.colBandSize = globalXmlParser.intAttr(c, "val");
|
2149
|
-
break;
|
2150
|
-
case "tblStyleRowBandSize":
|
2151
|
-
table.rowBandSize = globalXmlParser.intAttr(c, "val");
|
2152
|
-
break;
|
2153
|
-
default:
|
2154
|
-
return false;
|
2155
|
-
}
|
2156
|
-
return true;
|
2157
|
-
});
|
2158
|
-
switch (table.cssStyle["text-align"]) {
|
2159
|
-
case "center":
|
2160
|
-
delete table.cssStyle["text-align"];
|
2161
|
-
table.cssStyle["margin-left"] = "auto";
|
2162
|
-
table.cssStyle["margin-right"] = "auto";
|
2163
|
-
break;
|
2164
|
-
case "right":
|
2165
|
-
delete table.cssStyle["text-align"];
|
2166
|
-
table.cssStyle["margin-left"] = "auto";
|
2167
|
-
break;
|
2168
|
-
}
|
2169
|
-
}
|
2170
|
-
parseTablePosition(node, table) {
|
2171
|
-
var topFromText = globalXmlParser.lengthAttr(node, "topFromText");
|
2172
|
-
var bottomFromText = globalXmlParser.lengthAttr(node, "bottomFromText");
|
2173
|
-
var rightFromText = globalXmlParser.lengthAttr(node, "rightFromText");
|
2174
|
-
var leftFromText = globalXmlParser.lengthAttr(node, "leftFromText");
|
2175
|
-
table.cssStyle["float"] = "left";
|
2176
|
-
table.cssStyle["margin-bottom"] = values.addSize(table.cssStyle["margin-bottom"], bottomFromText);
|
2177
|
-
table.cssStyle["margin-left"] = values.addSize(table.cssStyle["margin-left"], leftFromText);
|
2178
|
-
table.cssStyle["margin-right"] = values.addSize(table.cssStyle["margin-right"], rightFromText);
|
2179
|
-
table.cssStyle["margin-top"] = values.addSize(table.cssStyle["margin-top"], topFromText);
|
2180
|
-
}
|
2181
|
-
parseTableRow(node) {
|
2182
|
-
var result = { type: DomType.Row, children: [] };
|
2183
|
-
xmlUtil.foreach(node, (c) => {
|
2184
|
-
switch (c.localName) {
|
2185
|
-
case "tc":
|
2186
|
-
result.children.push(this.parseTableCell(c));
|
2187
|
-
break;
|
2188
|
-
case "trPr":
|
2189
|
-
this.parseTableRowProperties(c, result);
|
2190
|
-
break;
|
2191
|
-
}
|
2192
|
-
});
|
2193
|
-
return result;
|
2194
|
-
}
|
2195
|
-
parseTableRowProperties(elem, row) {
|
2196
|
-
row.cssStyle = this.parseDefaultProperties(elem, {}, null, (c) => {
|
2197
|
-
switch (c.localName) {
|
2198
|
-
case "cnfStyle":
|
2199
|
-
row.className = values.classNameOfCnfStyle(c);
|
2200
|
-
break;
|
2201
|
-
case "tblHeader":
|
2202
|
-
row.isHeader = globalXmlParser.boolAttr(c, "val");
|
2203
|
-
break;
|
2204
|
-
default:
|
2205
|
-
return false;
|
2206
|
-
}
|
2207
|
-
return true;
|
2208
|
-
});
|
2209
|
-
}
|
2210
|
-
parseTableCell(node) {
|
2211
|
-
var result = { type: DomType.Cell, children: [] };
|
2212
|
-
xmlUtil.foreach(node, (c) => {
|
2213
|
-
switch (c.localName) {
|
2214
|
-
case "tbl":
|
2215
|
-
result.children.push(this.parseTable(c));
|
2216
|
-
break;
|
2217
|
-
case "p":
|
2218
|
-
result.children.push(this.parseParagraph(c));
|
2219
|
-
break;
|
2220
|
-
case "tcPr":
|
2221
|
-
this.parseTableCellProperties(c, result);
|
2222
|
-
break;
|
2223
|
-
}
|
2224
|
-
});
|
2225
|
-
return result;
|
2226
|
-
}
|
2227
|
-
parseTableCellProperties(elem, cell) {
|
2228
|
-
cell.cssStyle = this.parseDefaultProperties(elem, {}, null, (c) => {
|
2229
|
-
switch (c.localName) {
|
2230
|
-
case "gridSpan":
|
2231
|
-
cell.span = globalXmlParser.intAttr(c, "val", null);
|
2232
|
-
break;
|
2233
|
-
case "vMerge":
|
2234
|
-
cell.verticalMerge = globalXmlParser.attr(c, "val") ?? "continue";
|
2235
|
-
break;
|
2236
|
-
case "cnfStyle":
|
2237
|
-
cell.className = values.classNameOfCnfStyle(c);
|
2238
|
-
break;
|
2239
|
-
default:
|
2240
|
-
return false;
|
2241
|
-
}
|
2242
|
-
return true;
|
2243
|
-
});
|
2244
|
-
this.parseTableCellVerticalText(elem, cell);
|
2245
|
-
}
|
2246
|
-
parseTableCellVerticalText(elem, cell) {
|
2247
|
-
const directionMap = {
|
2248
|
-
"btLr": {
|
2249
|
-
writingMode: "vertical-rl",
|
2250
|
-
transform: "rotate(180deg)"
|
2251
|
-
},
|
2252
|
-
"lrTb": {
|
2253
|
-
writingMode: "vertical-lr",
|
2254
|
-
transform: "none"
|
2255
|
-
},
|
2256
|
-
"tbRl": {
|
2257
|
-
writingMode: "vertical-rl",
|
2258
|
-
transform: "none"
|
2259
|
-
}
|
2260
|
-
};
|
2261
|
-
xmlUtil.foreach(elem, (c) => {
|
2262
|
-
if (c.localName === "textDirection") {
|
2263
|
-
const direction = globalXmlParser.attr(c, "val");
|
2264
|
-
const style = directionMap[direction] || { writingMode: "horizontal-tb" };
|
2265
|
-
cell.cssStyle["writing-mode"] = style.writingMode;
|
2266
|
-
cell.cssStyle["transform"] = style.transform;
|
2267
|
-
}
|
2268
|
-
});
|
2269
|
-
}
|
2270
|
-
parseDefaultProperties(elem, style = null, childStyle = null, handler = null) {
|
2271
|
-
style = style || {};
|
2272
|
-
xmlUtil.foreach(elem, (c) => {
|
2273
|
-
if (handler == null ? void 0 : handler(c))
|
2274
|
-
return;
|
2275
|
-
switch (c.localName) {
|
2276
|
-
case "jc":
|
2277
|
-
style["text-align"] = values.valueOfJc(c);
|
2278
|
-
break;
|
2279
|
-
case "textAlignment":
|
2280
|
-
style["vertical-align"] = values.valueOfTextAlignment(c);
|
2281
|
-
break;
|
2282
|
-
case "color":
|
2283
|
-
style["color"] = xmlUtil.colorAttr(c, "val", null, autos.color);
|
2284
|
-
break;
|
2285
|
-
case "sz":
|
2286
|
-
style["font-size"] = style["min-height"] = globalXmlParser.lengthAttr(c, "val", LengthUsage.FontSize);
|
2287
|
-
break;
|
2288
|
-
case "shd":
|
2289
|
-
style["background-color"] = xmlUtil.colorAttr(c, "fill", null, autos.shd);
|
2290
|
-
break;
|
2291
|
-
case "highlight":
|
2292
|
-
style["background-color"] = xmlUtil.colorAttr(c, "val", null, autos.highlight);
|
2293
|
-
break;
|
2294
|
-
case "vertAlign":
|
2295
|
-
break;
|
2296
|
-
case "position":
|
2297
|
-
style.verticalAlign = globalXmlParser.lengthAttr(c, "val", LengthUsage.FontSize);
|
2298
|
-
break;
|
2299
|
-
case "tcW":
|
2300
|
-
if (this.options.ignoreWidth)
|
2301
|
-
break;
|
2302
|
-
case "tblW":
|
2303
|
-
style["width"] = values.valueOfSize(c, "w");
|
2304
|
-
break;
|
2305
|
-
case "trHeight":
|
2306
|
-
this.parseTrHeight(c, style);
|
2307
|
-
break;
|
2308
|
-
case "strike":
|
2309
|
-
style["text-decoration"] = globalXmlParser.boolAttr(c, "val", true) ? "line-through" : "none";
|
2310
|
-
break;
|
2311
|
-
case "b":
|
2312
|
-
style["font-weight"] = globalXmlParser.boolAttr(c, "val", true) ? "bold" : "normal";
|
2313
|
-
break;
|
2314
|
-
case "i":
|
2315
|
-
style["font-style"] = globalXmlParser.boolAttr(c, "val", true) ? "italic" : "normal";
|
2316
|
-
break;
|
2317
|
-
case "caps":
|
2318
|
-
style["text-transform"] = globalXmlParser.boolAttr(c, "val", true) ? "uppercase" : "none";
|
2319
|
-
break;
|
2320
|
-
case "smallCaps":
|
2321
|
-
style["font-variant"] = globalXmlParser.boolAttr(c, "val", true) ? "small-caps" : "none";
|
2322
|
-
break;
|
2323
|
-
case "u":
|
2324
|
-
this.parseUnderline(c, style);
|
2325
|
-
break;
|
2326
|
-
case "ind":
|
2327
|
-
case "tblInd":
|
2328
|
-
this.parseIndentation(c, style);
|
2329
|
-
break;
|
2330
|
-
case "rFonts":
|
2331
|
-
this.parseFont(c, style);
|
2332
|
-
break;
|
2333
|
-
case "tblBorders":
|
2334
|
-
this.parseBorderProperties(c, childStyle || style);
|
2335
|
-
break;
|
2336
|
-
case "tblCellSpacing":
|
2337
|
-
style["border-spacing"] = values.valueOfMargin(c);
|
2338
|
-
style["border-collapse"] = "separate";
|
2339
|
-
break;
|
2340
|
-
case "pBdr":
|
2341
|
-
this.parseBorderProperties(c, style);
|
2342
|
-
break;
|
2343
|
-
case "bdr":
|
2344
|
-
style["border"] = values.valueOfBorder(c);
|
2345
|
-
break;
|
2346
|
-
case "tcBorders":
|
2347
|
-
this.parseBorderProperties(c, style);
|
2348
|
-
break;
|
2349
|
-
case "vanish":
|
2350
|
-
if (globalXmlParser.boolAttr(c, "val", true))
|
2351
|
-
style["display"] = "none";
|
2352
|
-
break;
|
2353
|
-
case "kern":
|
2354
|
-
break;
|
2355
|
-
case "noWrap":
|
2356
|
-
break;
|
2357
|
-
case "tblCellMar":
|
2358
|
-
case "tcMar":
|
2359
|
-
this.parseMarginProperties(c, childStyle || style);
|
2360
|
-
break;
|
2361
|
-
case "tblLayout":
|
2362
|
-
style["table-layout"] = values.valueOfTblLayout(c);
|
2363
|
-
break;
|
2364
|
-
case "vAlign":
|
2365
|
-
style["vertical-align"] = values.valueOfTextAlignment(c);
|
2366
|
-
break;
|
2367
|
-
case "spacing":
|
2368
|
-
if (elem.localName == "pPr")
|
2369
|
-
this.parseSpacing(c, style);
|
2370
|
-
break;
|
2371
|
-
case "wordWrap":
|
2372
|
-
if (globalXmlParser.boolAttr(c, "val"))
|
2373
|
-
style["overflow-wrap"] = "break-word";
|
2374
|
-
break;
|
2375
|
-
case "suppressAutoHyphens":
|
2376
|
-
style["hyphens"] = globalXmlParser.boolAttr(c, "val", true) ? "none" : "auto";
|
2377
|
-
break;
|
2378
|
-
case "lang":
|
2379
|
-
style["$lang"] = globalXmlParser.attr(c, "val");
|
2380
|
-
break;
|
2381
|
-
case "bCs":
|
2382
|
-
case "iCs":
|
2383
|
-
case "szCs":
|
2384
|
-
case "tabs":
|
2385
|
-
case "outlineLvl":
|
2386
|
-
case "contextualSpacing":
|
2387
|
-
case "tblStyleColBandSize":
|
2388
|
-
case "tblStyleRowBandSize":
|
2389
|
-
case "webHidden":
|
2390
|
-
case "pageBreakBefore":
|
2391
|
-
case "suppressLineNumbers":
|
2392
|
-
case "keepLines":
|
2393
|
-
case "keepNext":
|
2394
|
-
case "widowControl":
|
2395
|
-
case "bidi":
|
2396
|
-
case "rtl":
|
2397
|
-
case "noProof":
|
2398
|
-
break;
|
2399
|
-
default:
|
2400
|
-
if (this.options.debug)
|
2401
|
-
console.warn(`DOCX: Unknown document element: ${elem.localName}.${c.localName}`);
|
2402
|
-
break;
|
2403
|
-
}
|
2404
|
-
});
|
2405
|
-
return style;
|
2406
|
-
}
|
2407
|
-
parseUnderline(node, style) {
|
2408
|
-
var val = globalXmlParser.attr(node, "val");
|
2409
|
-
if (val == null)
|
2410
|
-
return;
|
2411
|
-
switch (val) {
|
2412
|
-
case "dash":
|
2413
|
-
case "dashDotDotHeavy":
|
2414
|
-
case "dashDotHeavy":
|
2415
|
-
case "dashedHeavy":
|
2416
|
-
case "dashLong":
|
2417
|
-
case "dashLongHeavy":
|
2418
|
-
case "dotDash":
|
2419
|
-
case "dotDotDash":
|
2420
|
-
style["text-decoration"] = "underline dashed";
|
2421
|
-
break;
|
2422
|
-
case "dotted":
|
2423
|
-
case "dottedHeavy":
|
2424
|
-
style["text-decoration"] = "underline dotted";
|
2425
|
-
break;
|
2426
|
-
case "double":
|
2427
|
-
style["text-decoration"] = "underline double";
|
2428
|
-
break;
|
2429
|
-
case "single":
|
2430
|
-
case "thick":
|
2431
|
-
style["text-decoration"] = "underline";
|
2432
|
-
break;
|
2433
|
-
case "wave":
|
2434
|
-
case "wavyDouble":
|
2435
|
-
case "wavyHeavy":
|
2436
|
-
style["text-decoration"] = "underline wavy";
|
2437
|
-
break;
|
2438
|
-
case "words":
|
2439
|
-
style["text-decoration"] = "underline";
|
2440
|
-
break;
|
2441
|
-
case "none":
|
2442
|
-
style["text-decoration"] = "none";
|
2443
|
-
break;
|
2444
|
-
}
|
2445
|
-
var col = xmlUtil.colorAttr(node, "color");
|
2446
|
-
if (col)
|
2447
|
-
style["text-decoration-color"] = col;
|
2448
|
-
}
|
2449
|
-
parseFont(node, style) {
|
2450
|
-
var ascii = globalXmlParser.attr(node, "ascii");
|
2451
|
-
var asciiTheme = values.themeValue(node, "asciiTheme");
|
2452
|
-
var eastAsia = globalXmlParser.attr(node, "eastAsia");
|
2453
|
-
var fonts = [ascii, asciiTheme, eastAsia].filter((x) => x).map((x) => encloseFontFamily(x));
|
2454
|
-
if (fonts.length > 0)
|
2455
|
-
style["font-family"] = [...new Set(fonts)].join(", ");
|
2456
|
-
}
|
2457
|
-
parseIndentation(node, style) {
|
2458
|
-
var firstLine = globalXmlParser.lengthAttr(node, "firstLine");
|
2459
|
-
var hanging = globalXmlParser.lengthAttr(node, "hanging");
|
2460
|
-
var left = globalXmlParser.lengthAttr(node, "left");
|
2461
|
-
var start = globalXmlParser.lengthAttr(node, "start");
|
2462
|
-
var right = globalXmlParser.lengthAttr(node, "right");
|
2463
|
-
var end = globalXmlParser.lengthAttr(node, "end");
|
2464
|
-
if (firstLine)
|
2465
|
-
style["text-indent"] = firstLine;
|
2466
|
-
if (hanging)
|
2467
|
-
style["text-indent"] = `-${hanging}`;
|
2468
|
-
if (left || start)
|
2469
|
-
style["margin-left"] = left || start;
|
2470
|
-
if (right || end)
|
2471
|
-
style["margin-right"] = right || end;
|
2472
|
-
}
|
2473
|
-
parseSpacing(node, style) {
|
2474
|
-
var before = globalXmlParser.lengthAttr(node, "before");
|
2475
|
-
var after = globalXmlParser.lengthAttr(node, "after");
|
2476
|
-
var line = globalXmlParser.intAttr(node, "line", null);
|
2477
|
-
var lineRule = globalXmlParser.attr(node, "lineRule");
|
2478
|
-
if (before)
|
2479
|
-
style["margin-top"] = before;
|
2480
|
-
if (after)
|
2481
|
-
style["margin-bottom"] = after;
|
2482
|
-
if (line !== null) {
|
2483
|
-
switch (lineRule) {
|
2484
|
-
case "auto":
|
2485
|
-
style["line-height"] = `${(line / 240).toFixed(2)}`;
|
2486
|
-
break;
|
2487
|
-
case "atLeast":
|
2488
|
-
style["line-height"] = `calc(100% + ${line / 20}pt)`;
|
2489
|
-
break;
|
2490
|
-
default:
|
2491
|
-
style["line-height"] = style["min-height"] = `${line / 20}pt`;
|
2492
|
-
break;
|
2493
|
-
}
|
2494
|
-
}
|
2495
|
-
}
|
2496
|
-
parseMarginProperties(node, output) {
|
2497
|
-
xmlUtil.foreach(node, (c) => {
|
2498
|
-
switch (c.localName) {
|
2499
|
-
case "left":
|
2500
|
-
output["padding-left"] = values.valueOfMargin(c);
|
2501
|
-
break;
|
2502
|
-
case "right":
|
2503
|
-
output["padding-right"] = values.valueOfMargin(c);
|
2504
|
-
break;
|
2505
|
-
case "top":
|
2506
|
-
output["padding-top"] = values.valueOfMargin(c);
|
2507
|
-
break;
|
2508
|
-
case "bottom":
|
2509
|
-
output["padding-bottom"] = values.valueOfMargin(c);
|
2510
|
-
break;
|
2511
|
-
}
|
2512
|
-
});
|
2513
|
-
}
|
2514
|
-
parseTrHeight(node, output) {
|
2515
|
-
switch (globalXmlParser.attr(node, "hRule")) {
|
2516
|
-
case "exact":
|
2517
|
-
output["height"] = globalXmlParser.lengthAttr(node, "val");
|
2518
|
-
break;
|
2519
|
-
case "atLeast":
|
2520
|
-
default:
|
2521
|
-
output["height"] = globalXmlParser.lengthAttr(node, "val");
|
2522
|
-
break;
|
2523
|
-
}
|
2524
|
-
}
|
2525
|
-
parseBorderProperties(node, output) {
|
2526
|
-
xmlUtil.foreach(node, (c) => {
|
2527
|
-
switch (c.localName) {
|
2528
|
-
case "start":
|
2529
|
-
case "left":
|
2530
|
-
output["border-left"] = values.valueOfBorder(c);
|
2531
|
-
break;
|
2532
|
-
case "end":
|
2533
|
-
case "right":
|
2534
|
-
output["border-right"] = values.valueOfBorder(c);
|
2535
|
-
break;
|
2536
|
-
case "top":
|
2537
|
-
output["border-top"] = values.valueOfBorder(c);
|
2538
|
-
break;
|
2539
|
-
case "bottom":
|
2540
|
-
output["border-bottom"] = values.valueOfBorder(c);
|
2541
|
-
break;
|
2542
|
-
}
|
2543
|
-
});
|
2544
|
-
}
|
2545
|
-
}
|
2546
|
-
const knownColors = ["black", "blue", "cyan", "darkBlue", "darkCyan", "darkGray", "darkGreen", "darkMagenta", "darkRed", "darkYellow", "green", "lightGray", "magenta", "none", "red", "white", "yellow"];
|
2547
|
-
class xmlUtil {
|
2548
|
-
static foreach(node, cb) {
|
2549
|
-
for (var i = 0; i < node.childNodes.length; i++) {
|
2550
|
-
let n = node.childNodes[i];
|
2551
|
-
if (n.nodeType == Node.ELEMENT_NODE)
|
2552
|
-
cb(n);
|
2553
|
-
}
|
2554
|
-
}
|
2555
|
-
static colorAttr(node, attrName, defValue = null, autoColor = "black") {
|
2556
|
-
var v = globalXmlParser.attr(node, attrName);
|
2557
|
-
if (v) {
|
2558
|
-
if (v == "auto") {
|
2559
|
-
return autoColor;
|
2560
|
-
} else if (knownColors.includes(v)) {
|
2561
|
-
return v;
|
2562
|
-
}
|
2563
|
-
return `#${v}`;
|
2564
|
-
}
|
2565
|
-
var themeColor = globalXmlParser.attr(node, "themeColor");
|
2566
|
-
return themeColor ? `var(--docx-${themeColor}-color)` : defValue;
|
2567
|
-
}
|
2568
|
-
static sizeValue(node, type = LengthUsage.Dxa) {
|
2569
|
-
return convertLength(node.textContent, type);
|
2570
|
-
}
|
2571
|
-
}
|
2572
|
-
class values {
|
2573
|
-
static themeValue(c, attr) {
|
2574
|
-
var val = globalXmlParser.attr(c, attr);
|
2575
|
-
return val ? `var(--docx-${val}-font)` : null;
|
2576
|
-
}
|
2577
|
-
static valueOfSize(c, attr) {
|
2578
|
-
var type = LengthUsage.Dxa;
|
2579
|
-
switch (globalXmlParser.attr(c, "type")) {
|
2580
|
-
case "dxa":
|
2581
|
-
break;
|
2582
|
-
case "pct":
|
2583
|
-
type = LengthUsage.Percent;
|
2584
|
-
break;
|
2585
|
-
case "auto":
|
2586
|
-
return "auto";
|
2587
|
-
}
|
2588
|
-
return globalXmlParser.lengthAttr(c, attr, type);
|
2589
|
-
}
|
2590
|
-
static valueOfMargin(c) {
|
2591
|
-
return globalXmlParser.lengthAttr(c, "w");
|
2592
|
-
}
|
2593
|
-
static valueOfBorder(c) {
|
2594
|
-
var type = globalXmlParser.attr(c, "val");
|
2595
|
-
if (type == "nil")
|
2596
|
-
return "none";
|
2597
|
-
var color = xmlUtil.colorAttr(c, "color");
|
2598
|
-
var size = globalXmlParser.lengthAttr(c, "sz", LengthUsage.Border);
|
2599
|
-
return `${size} solid ${color == "auto" ? autos.borderColor : color}`;
|
2600
|
-
}
|
2601
|
-
static valueOfTblLayout(c) {
|
2602
|
-
var type = globalXmlParser.attr(c, "val");
|
2603
|
-
return type == "fixed" ? "fixed" : "auto";
|
2604
|
-
}
|
2605
|
-
static classNameOfCnfStyle(c) {
|
2606
|
-
const val = globalXmlParser.attr(c, "val");
|
2607
|
-
const classes = [
|
2608
|
-
"first-row",
|
2609
|
-
"last-row",
|
2610
|
-
"first-col",
|
2611
|
-
"last-col",
|
2612
|
-
"odd-col",
|
2613
|
-
"even-col",
|
2614
|
-
"odd-row",
|
2615
|
-
"even-row",
|
2616
|
-
"ne-cell",
|
2617
|
-
"nw-cell",
|
2618
|
-
"se-cell",
|
2619
|
-
"sw-cell"
|
2620
|
-
];
|
2621
|
-
return classes.filter((_, i) => val[i] == "1").join(" ");
|
2622
|
-
}
|
2623
|
-
static valueOfJc(c) {
|
2624
|
-
var type = globalXmlParser.attr(c, "val");
|
2625
|
-
switch (type) {
|
2626
|
-
case "start":
|
2627
|
-
case "left":
|
2628
|
-
return "left";
|
2629
|
-
case "center":
|
2630
|
-
return "center";
|
2631
|
-
case "end":
|
2632
|
-
case "right":
|
2633
|
-
return "right";
|
2634
|
-
case "both":
|
2635
|
-
return "justify";
|
2636
|
-
}
|
2637
|
-
return type;
|
2638
|
-
}
|
2639
|
-
static valueOfVertAlign(c, asTagName = false) {
|
2640
|
-
var type = globalXmlParser.attr(c, "val");
|
2641
|
-
switch (type) {
|
2642
|
-
case "subscript":
|
2643
|
-
return "sub";
|
2644
|
-
case "superscript":
|
2645
|
-
return asTagName ? "sup" : "super";
|
2646
|
-
}
|
2647
|
-
return asTagName ? null : type;
|
2648
|
-
}
|
2649
|
-
static valueOfTextAlignment(c) {
|
2650
|
-
var type = globalXmlParser.attr(c, "val");
|
2651
|
-
switch (type) {
|
2652
|
-
case "auto":
|
2653
|
-
case "baseline":
|
2654
|
-
return "baseline";
|
2655
|
-
case "top":
|
2656
|
-
return "top";
|
2657
|
-
case "center":
|
2658
|
-
return "middle";
|
2659
|
-
case "bottom":
|
2660
|
-
return "bottom";
|
2661
|
-
}
|
2662
|
-
return type;
|
2663
|
-
}
|
2664
|
-
static addSize(a, b) {
|
2665
|
-
if (a == null)
|
2666
|
-
return b;
|
2667
|
-
if (b == null)
|
2668
|
-
return a;
|
2669
|
-
return `calc(${a} + ${b})`;
|
2670
|
-
}
|
2671
|
-
static classNameOftblLook(c) {
|
2672
|
-
const val = globalXmlParser.hexAttr(c, "val", 0);
|
2673
|
-
let className = "";
|
2674
|
-
if (globalXmlParser.boolAttr(c, "firstRow") || val & 32)
|
2675
|
-
className += " first-row";
|
2676
|
-
if (globalXmlParser.boolAttr(c, "lastRow") || val & 64)
|
2677
|
-
className += " last-row";
|
2678
|
-
if (globalXmlParser.boolAttr(c, "firstColumn") || val & 128)
|
2679
|
-
className += " first-col";
|
2680
|
-
if (globalXmlParser.boolAttr(c, "lastColumn") || val & 256)
|
2681
|
-
className += " last-col";
|
2682
|
-
if (globalXmlParser.boolAttr(c, "noHBand") || val & 512)
|
2683
|
-
className += " no-hband";
|
2684
|
-
if (globalXmlParser.boolAttr(c, "noVBand") || val & 1024)
|
2685
|
-
className += " no-vband";
|
2686
|
-
return className.trim();
|
2687
|
-
}
|
2688
|
-
}
|
2689
|
-
const defaultTab = { pos: 0, leader: "none", style: "left" };
|
2690
|
-
const maxTabs = 50;
|
2691
|
-
function computePixelToPoint(container = document.body) {
|
2692
|
-
const temp = document.createElement("div");
|
2693
|
-
temp.style.width = "100pt";
|
2694
|
-
container.appendChild(temp);
|
2695
|
-
const result = 100 / temp.offsetWidth;
|
2696
|
-
container.removeChild(temp);
|
2697
|
-
return result;
|
2698
|
-
}
|
2699
|
-
function updateTabStop(elem, tabs, defaultTabSize, pixelToPoint = 72 / 96) {
|
2700
|
-
const p = elem.closest("p");
|
2701
|
-
const ebb = elem.getBoundingClientRect();
|
2702
|
-
const pbb = p.getBoundingClientRect();
|
2703
|
-
const pcs = getComputedStyle(p);
|
2704
|
-
const tabStops = (tabs == null ? void 0 : tabs.length) > 0 ? tabs.map((t) => ({
|
2705
|
-
pos: lengthToPoint(t.position),
|
2706
|
-
leader: t.leader,
|
2707
|
-
style: t.style
|
2708
|
-
})).sort((a, b) => a.pos - b.pos) : [defaultTab];
|
2709
|
-
const lastTab = tabStops[tabStops.length - 1];
|
2710
|
-
const pWidthPt = pbb.width * pixelToPoint;
|
2711
|
-
const size = lengthToPoint(defaultTabSize);
|
2712
|
-
let pos = lastTab.pos + size;
|
2713
|
-
if (pos < pWidthPt) {
|
2714
|
-
for (; pos < pWidthPt && tabStops.length < maxTabs; pos += size) {
|
2715
|
-
tabStops.push({ ...defaultTab, pos });
|
2716
|
-
}
|
2717
|
-
}
|
2718
|
-
const marginLeft = parseFloat(pcs.marginLeft);
|
2719
|
-
const pOffset = pbb.left + marginLeft;
|
2720
|
-
const left = (ebb.left - pOffset) * pixelToPoint;
|
2721
|
-
const tab = tabStops.find((t) => t.style != "clear" && t.pos > left);
|
2722
|
-
if (tab == null)
|
2723
|
-
return;
|
2724
|
-
let width = 1;
|
2725
|
-
if (tab.style == "right" || tab.style == "center") {
|
2726
|
-
const tabStops2 = Array.from(p.querySelectorAll(`.${elem.className}`));
|
2727
|
-
const nextIdx = tabStops2.indexOf(elem) + 1;
|
2728
|
-
const range = document.createRange();
|
2729
|
-
range.setStart(elem, 1);
|
2730
|
-
if (nextIdx < tabStops2.length) {
|
2731
|
-
range.setEndBefore(tabStops2[nextIdx]);
|
2732
|
-
} else {
|
2733
|
-
range.setEndAfter(p);
|
2734
|
-
}
|
2735
|
-
const mul = tab.style == "center" ? 0.5 : 1;
|
2736
|
-
const nextBB = range.getBoundingClientRect();
|
2737
|
-
const offset = nextBB.left + mul * nextBB.width - (pbb.left - marginLeft);
|
2738
|
-
width = tab.pos - offset * pixelToPoint;
|
2739
|
-
} else {
|
2740
|
-
width = tab.pos - left;
|
2741
|
-
}
|
2742
|
-
elem.innerHTML = " ";
|
2743
|
-
elem.style.textDecoration = "inherit";
|
2744
|
-
elem.style.wordSpacing = `${width.toFixed(0)}pt`;
|
2745
|
-
switch (tab.leader) {
|
2746
|
-
case "dot":
|
2747
|
-
case "middleDot":
|
2748
|
-
elem.style.textDecoration = "underline";
|
2749
|
-
elem.style.textDecorationStyle = "dotted";
|
2750
|
-
break;
|
2751
|
-
case "hyphen":
|
2752
|
-
case "heavy":
|
2753
|
-
case "underscore":
|
2754
|
-
elem.style.textDecoration = "underline";
|
2755
|
-
break;
|
2756
|
-
}
|
2757
|
-
}
|
2758
|
-
function lengthToPoint(length) {
|
2759
|
-
return parseFloat(length);
|
2760
|
-
}
|
2761
|
-
const ns = {
|
2762
|
-
svg: "http://www.w3.org/2000/svg",
|
2763
|
-
mathML: "http://www.w3.org/1998/Math/MathML"
|
2764
|
-
};
|
2765
|
-
class HtmlRenderer {
|
2766
|
-
constructor(htmlDocument) {
|
2767
|
-
this.htmlDocument = htmlDocument;
|
2768
|
-
this.className = "docx";
|
2769
|
-
this.styleMap = {};
|
2770
|
-
this.currentPart = null;
|
2771
|
-
this.tableVerticalMerges = [];
|
2772
|
-
this.currentVerticalMerge = null;
|
2773
|
-
this.tableCellPositions = [];
|
2774
|
-
this.currentCellPosition = null;
|
2775
|
-
this.footnoteMap = {};
|
2776
|
-
this.endnoteMap = {};
|
2777
|
-
this.currentEndnoteIds = [];
|
2778
|
-
this.usedHederFooterParts = [];
|
2779
|
-
this.currentTabs = [];
|
2780
|
-
this.commentMap = {};
|
2781
|
-
this.tasks = [];
|
2782
|
-
this.postRenderTasks = [];
|
2783
|
-
}
|
2784
|
-
async render(document2, bodyContainer, styleContainer = null, options) {
|
2785
|
-
var _a;
|
2786
|
-
this.document = document2;
|
2787
|
-
this.options = options;
|
2788
|
-
this.className = options.className;
|
2789
|
-
this.rootSelector = options.inWrapper ? `.${this.className}-wrapper` : ":root";
|
2790
|
-
this.styleMap = null;
|
2791
|
-
this.tasks = [];
|
2792
|
-
if (this.options.renderComments && globalThis.Highlight) {
|
2793
|
-
this.commentHighlight = new Highlight();
|
2794
|
-
}
|
2795
|
-
styleContainer = styleContainer || bodyContainer;
|
2796
|
-
removeAllElements(styleContainer);
|
2797
|
-
removeAllElements(bodyContainer);
|
2798
|
-
styleContainer.appendChild(this.createComment("docxjs library predefined styles"));
|
2799
|
-
styleContainer.appendChild(this.renderDefaultStyle());
|
2800
|
-
if (document2.themePart) {
|
2801
|
-
styleContainer.appendChild(this.createComment("docxjs document theme values"));
|
2802
|
-
this.renderTheme(document2.themePart, styleContainer);
|
2803
|
-
}
|
2804
|
-
if (document2.stylesPart != null) {
|
2805
|
-
this.styleMap = this.processStyles(document2.stylesPart.styles);
|
2806
|
-
styleContainer.appendChild(this.createComment("docxjs document styles"));
|
2807
|
-
styleContainer.appendChild(this.renderStyles(document2.stylesPart.styles));
|
2808
|
-
}
|
2809
|
-
if (document2.numberingPart) {
|
2810
|
-
this.prodessNumberings(document2.numberingPart.domNumberings);
|
2811
|
-
styleContainer.appendChild(this.createComment("docxjs document numbering styles"));
|
2812
|
-
styleContainer.appendChild(this.renderNumbering(document2.numberingPart.domNumberings, styleContainer));
|
2813
|
-
}
|
2814
|
-
if (document2.footnotesPart) {
|
2815
|
-
this.footnoteMap = keyBy(document2.footnotesPart.notes, (x) => x.id);
|
2816
|
-
}
|
2817
|
-
if (document2.endnotesPart) {
|
2818
|
-
this.endnoteMap = keyBy(document2.endnotesPart.notes, (x) => x.id);
|
2819
|
-
}
|
2820
|
-
if (document2.settingsPart) {
|
2821
|
-
this.defaultTabSize = (_a = document2.settingsPart.settings) == null ? void 0 : _a.defaultTabStop;
|
2822
|
-
}
|
2823
|
-
if (!options.ignoreFonts && document2.fontTablePart)
|
2824
|
-
this.renderFontTable(document2.fontTablePart, styleContainer);
|
2825
|
-
var sectionElements = this.renderSections(document2.documentPart.body);
|
2826
|
-
if (this.options.inWrapper) {
|
2827
|
-
bodyContainer.appendChild(this.renderWrapper(sectionElements));
|
2828
|
-
} else {
|
2829
|
-
appendChildren(bodyContainer, sectionElements);
|
2830
|
-
}
|
2831
|
-
if (this.commentHighlight && options.renderComments) {
|
2832
|
-
CSS.highlights.set(`${this.className}-comments`, this.commentHighlight);
|
2833
|
-
}
|
2834
|
-
this.postRenderTasks.forEach((t) => t());
|
2835
|
-
await Promise.allSettled(this.tasks);
|
2836
|
-
this.refreshTabStops();
|
2837
|
-
}
|
2838
|
-
renderTheme(themePart, styleContainer) {
|
2839
|
-
var _a, _b;
|
2840
|
-
const variables = {};
|
2841
|
-
const fontScheme = (_a = themePart.theme) == null ? void 0 : _a.fontScheme;
|
2842
|
-
if (fontScheme) {
|
2843
|
-
if (fontScheme.majorFont) {
|
2844
|
-
variables["--docx-majorHAnsi-font"] = fontScheme.majorFont.latinTypeface;
|
2845
|
-
}
|
2846
|
-
if (fontScheme.minorFont) {
|
2847
|
-
variables["--docx-minorHAnsi-font"] = fontScheme.minorFont.latinTypeface;
|
2848
|
-
}
|
2849
|
-
}
|
2850
|
-
const colorScheme = (_b = themePart.theme) == null ? void 0 : _b.colorScheme;
|
2851
|
-
if (colorScheme) {
|
2852
|
-
for (let [k, v] of Object.entries(colorScheme.colors)) {
|
2853
|
-
variables[`--docx-${k}-color`] = `#${v}`;
|
2854
|
-
}
|
2855
|
-
}
|
2856
|
-
const cssText = this.styleToString(`.${this.className}`, variables);
|
2857
|
-
styleContainer.appendChild(this.createStyleElement(cssText));
|
2858
|
-
}
|
2859
|
-
renderFontTable(fontsPart, styleContainer) {
|
2860
|
-
for (let f of fontsPart.fonts) {
|
2861
|
-
for (let ref of f.embedFontRefs) {
|
2862
|
-
this.tasks.push(this.document.loadFont(ref.id, ref.key).then((fontData) => {
|
2863
|
-
const cssValues = {
|
2864
|
-
"font-family": encloseFontFamily(f.name),
|
2865
|
-
"src": `url(${fontData})`
|
2866
|
-
};
|
2867
|
-
if (ref.type == "bold" || ref.type == "boldItalic") {
|
2868
|
-
cssValues["font-weight"] = "bold";
|
2869
|
-
}
|
2870
|
-
if (ref.type == "italic" || ref.type == "boldItalic") {
|
2871
|
-
cssValues["font-style"] = "italic";
|
2872
|
-
}
|
2873
|
-
const cssText = this.styleToString("@font-face", cssValues);
|
2874
|
-
styleContainer.appendChild(this.createComment(`docxjs ${f.name} font`));
|
2875
|
-
styleContainer.appendChild(this.createStyleElement(cssText));
|
2876
|
-
}));
|
2877
|
-
}
|
2878
|
-
}
|
2879
|
-
}
|
2880
|
-
processStyleName(className) {
|
2881
|
-
return className ? `${this.className}_${escapeClassName(className)}` : this.className;
|
2882
|
-
}
|
2883
|
-
processStyles(styles) {
|
2884
|
-
const stylesMap = keyBy(styles.filter((x) => x.id != null), (x) => x.id);
|
2885
|
-
for (const style of styles.filter((x) => x.basedOn)) {
|
2886
|
-
var baseStyle = stylesMap[style.basedOn];
|
2887
|
-
if (baseStyle) {
|
2888
|
-
style.paragraphProps = mergeDeep(style.paragraphProps, baseStyle.paragraphProps);
|
2889
|
-
style.runProps = mergeDeep(style.runProps, baseStyle.runProps);
|
2890
|
-
for (const baseValues of baseStyle.styles) {
|
2891
|
-
const styleValues = style.styles.find((x) => x.target == baseValues.target);
|
2892
|
-
if (styleValues) {
|
2893
|
-
this.copyStyleProperties(baseValues.values, styleValues.values);
|
2894
|
-
} else {
|
2895
|
-
style.styles.push({ ...baseValues, values: { ...baseValues.values } });
|
2896
|
-
}
|
2897
|
-
}
|
2898
|
-
} else if (this.options.debug)
|
2899
|
-
console.warn(`Can't find base style ${style.basedOn}`);
|
2900
|
-
}
|
2901
|
-
for (let style of styles) {
|
2902
|
-
style.cssName = this.processStyleName(style.id);
|
2903
|
-
}
|
2904
|
-
return stylesMap;
|
2905
|
-
}
|
2906
|
-
prodessNumberings(numberings) {
|
2907
|
-
var _a;
|
2908
|
-
for (let num of numberings.filter((n) => n.pStyleName)) {
|
2909
|
-
const style = this.findStyle(num.pStyleName);
|
2910
|
-
if ((_a = style == null ? void 0 : style.paragraphProps) == null ? void 0 : _a.numbering) {
|
2911
|
-
style.paragraphProps.numbering.level = num.level;
|
2912
|
-
}
|
2913
|
-
}
|
2914
|
-
}
|
2915
|
-
processElement(element) {
|
2916
|
-
if (element.children) {
|
2917
|
-
for (var e of element.children) {
|
2918
|
-
e.parent = element;
|
2919
|
-
if (e.type == DomType.Table) {
|
2920
|
-
this.processTable(e);
|
2921
|
-
} else {
|
2922
|
-
this.processElement(e);
|
2923
|
-
}
|
2924
|
-
}
|
2925
|
-
}
|
2926
|
-
}
|
2927
|
-
processTable(table) {
|
2928
|
-
for (var r of table.children) {
|
2929
|
-
for (var c of r.children) {
|
2930
|
-
c.cssStyle = this.copyStyleProperties(table.cellStyle, c.cssStyle, [
|
2931
|
-
"border-left",
|
2932
|
-
"border-right",
|
2933
|
-
"border-top",
|
2934
|
-
"border-bottom",
|
2935
|
-
"padding-left",
|
2936
|
-
"padding-right",
|
2937
|
-
"padding-top",
|
2938
|
-
"padding-bottom"
|
2939
|
-
]);
|
2940
|
-
this.processElement(c);
|
2941
|
-
}
|
2942
|
-
}
|
2943
|
-
}
|
2944
|
-
copyStyleProperties(input, output, attrs = null) {
|
2945
|
-
if (!input)
|
2946
|
-
return output;
|
2947
|
-
if (output == null)
|
2948
|
-
output = {};
|
2949
|
-
if (attrs == null)
|
2950
|
-
attrs = Object.getOwnPropertyNames(input);
|
2951
|
-
for (var key of attrs) {
|
2952
|
-
if (input.hasOwnProperty(key) && !output.hasOwnProperty(key))
|
2953
|
-
output[key] = input[key];
|
2954
|
-
}
|
2955
|
-
return output;
|
2956
|
-
}
|
2957
|
-
createPageElement(className, props) {
|
2958
|
-
var elem = this.createElement("section", { className });
|
2959
|
-
if (props) {
|
2960
|
-
if (props.pageMargins) {
|
2961
|
-
elem.style.paddingLeft = props.pageMargins.left;
|
2962
|
-
elem.style.paddingRight = props.pageMargins.right;
|
2963
|
-
elem.style.paddingTop = props.pageMargins.top;
|
2964
|
-
elem.style.paddingBottom = props.pageMargins.bottom;
|
2965
|
-
}
|
2966
|
-
if (props.pageSize) {
|
2967
|
-
if (!this.options.ignoreWidth)
|
2968
|
-
elem.style.width = props.pageSize.width;
|
2969
|
-
if (!this.options.ignoreHeight)
|
2970
|
-
elem.style.minHeight = props.pageSize.height;
|
2971
|
-
}
|
2972
|
-
}
|
2973
|
-
return elem;
|
2974
|
-
}
|
2975
|
-
createSectionContent(props) {
|
2976
|
-
var elem = this.createElement("article");
|
2977
|
-
if (props.columns && props.columns.numberOfColumns) {
|
2978
|
-
elem.style.columnCount = `${props.columns.numberOfColumns}`;
|
2979
|
-
elem.style.columnGap = props.columns.space;
|
2980
|
-
if (props.columns.separator) {
|
2981
|
-
elem.style.columnRule = "1px solid black";
|
2982
|
-
}
|
2983
|
-
}
|
2984
|
-
return elem;
|
2985
|
-
}
|
2986
|
-
renderSections(document2) {
|
2987
|
-
const result = [];
|
2988
|
-
this.processElement(document2);
|
2989
|
-
const sections = this.splitBySection(document2.children, document2.props);
|
2990
|
-
const pages = this.groupByPageBreaks(sections);
|
2991
|
-
let prevProps = null;
|
2992
|
-
for (let i = 0, l = pages.length; i < l; i++) {
|
2993
|
-
this.currentFootnoteIds = [];
|
2994
|
-
const section = pages[i][0];
|
2995
|
-
let props = section.sectProps;
|
2996
|
-
const pageElement = this.createPageElement(this.className, props);
|
2997
|
-
this.renderStyleValues(document2.cssStyle, pageElement);
|
2998
|
-
this.options.renderHeaders && this.renderHeaderFooter(props.headerRefs, props, result.length, prevProps != props, pageElement);
|
2999
|
-
for (const sect of pages[i]) {
|
3000
|
-
var contentElement = this.createSectionContent(sect.sectProps);
|
3001
|
-
this.renderElements(sect.elements, contentElement);
|
3002
|
-
pageElement.appendChild(contentElement);
|
3003
|
-
props = sect.sectProps;
|
3004
|
-
}
|
3005
|
-
if (this.options.renderFootnotes) {
|
3006
|
-
this.renderNotes(this.currentFootnoteIds, this.footnoteMap, pageElement);
|
3007
|
-
}
|
3008
|
-
if (this.options.renderEndnotes && i == l - 1) {
|
3009
|
-
this.renderNotes(this.currentEndnoteIds, this.endnoteMap, pageElement);
|
3010
|
-
}
|
3011
|
-
this.options.renderFooters && this.renderHeaderFooter(props.footerRefs, props, result.length, prevProps != props, pageElement);
|
3012
|
-
result.push(pageElement);
|
3013
|
-
prevProps = props;
|
3014
|
-
}
|
3015
|
-
return result;
|
3016
|
-
}
|
3017
|
-
renderHeaderFooter(refs, props, page, firstOfSection, into) {
|
3018
|
-
if (!refs)
|
3019
|
-
return;
|
3020
|
-
var ref = (props.titlePage && firstOfSection ? refs.find((x) => x.type == "first") : null) ?? (page % 2 == 1 ? refs.find((x) => x.type == "even") : null) ?? refs.find((x) => x.type == "default");
|
3021
|
-
var part = ref && this.document.findPartByRelId(ref.id, this.document.documentPart);
|
3022
|
-
if (part) {
|
3023
|
-
this.currentPart = part;
|
3024
|
-
if (!this.usedHederFooterParts.includes(part.path)) {
|
3025
|
-
this.processElement(part.rootElement);
|
3026
|
-
this.usedHederFooterParts.push(part.path);
|
3027
|
-
}
|
3028
|
-
const [el] = this.renderElements([part.rootElement], into);
|
3029
|
-
if (props == null ? void 0 : props.pageMargins) {
|
3030
|
-
if (part.rootElement.type === DomType.Header) {
|
3031
|
-
el.style.marginTop = `calc(${props.pageMargins.header} - ${props.pageMargins.top})`;
|
3032
|
-
el.style.minHeight = `calc(${props.pageMargins.top} - ${props.pageMargins.header})`;
|
3033
|
-
} else if (part.rootElement.type === DomType.Footer) {
|
3034
|
-
el.style.marginBottom = `calc(${props.pageMargins.footer} - ${props.pageMargins.bottom})`;
|
3035
|
-
el.style.minHeight = `calc(${props.pageMargins.bottom} - ${props.pageMargins.footer})`;
|
3036
|
-
}
|
3037
|
-
}
|
3038
|
-
this.currentPart = null;
|
3039
|
-
}
|
3040
|
-
}
|
3041
|
-
isPageBreakElement(elem) {
|
3042
|
-
if (elem.type != DomType.Break)
|
3043
|
-
return false;
|
3044
|
-
if (elem.break == "lastRenderedPageBreak")
|
3045
|
-
return !this.options.ignoreLastRenderedPageBreak;
|
3046
|
-
return elem.break == "page";
|
3047
|
-
}
|
3048
|
-
isPageBreakSection(prev, next) {
|
3049
|
-
var _a, _b, _c, _d, _e, _f;
|
3050
|
-
if (!prev)
|
3051
|
-
return false;
|
3052
|
-
if (!next)
|
3053
|
-
return false;
|
3054
|
-
return ((_a = prev.pageSize) == null ? void 0 : _a.orientation) != ((_b = next.pageSize) == null ? void 0 : _b.orientation) || ((_c = prev.pageSize) == null ? void 0 : _c.width) != ((_d = next.pageSize) == null ? void 0 : _d.width) || ((_e = prev.pageSize) == null ? void 0 : _e.height) != ((_f = next.pageSize) == null ? void 0 : _f.height);
|
3055
|
-
}
|
3056
|
-
splitBySection(elements, defaultProps) {
|
3057
|
-
var _a;
|
3058
|
-
var current = { sectProps: null, elements: [], pageBreak: false };
|
3059
|
-
var result = [current];
|
3060
|
-
for (let elem of elements) {
|
3061
|
-
if (elem.type == DomType.Paragraph) {
|
3062
|
-
const s = this.findStyle(elem.styleName);
|
3063
|
-
if ((_a = s == null ? void 0 : s.paragraphProps) == null ? void 0 : _a.pageBreakBefore) {
|
3064
|
-
current.sectProps = sectProps;
|
3065
|
-
current.pageBreak = true;
|
3066
|
-
current = { sectProps: null, elements: [], pageBreak: false };
|
3067
|
-
result.push(current);
|
3068
|
-
}
|
3069
|
-
}
|
3070
|
-
current.elements.push(elem);
|
3071
|
-
if (elem.type == DomType.Paragraph) {
|
3072
|
-
const p = elem;
|
3073
|
-
var sectProps = p.sectionProps;
|
3074
|
-
var pBreakIndex = -1;
|
3075
|
-
var rBreakIndex = -1;
|
3076
|
-
if (this.options.breakPages && p.children) {
|
3077
|
-
pBreakIndex = p.children.findIndex((r) => {
|
3078
|
-
var _a2;
|
3079
|
-
rBreakIndex = ((_a2 = r.children) == null ? void 0 : _a2.findIndex(this.isPageBreakElement.bind(this))) ?? -1;
|
3080
|
-
return rBreakIndex != -1;
|
3081
|
-
});
|
3082
|
-
}
|
3083
|
-
if (sectProps || pBreakIndex != -1) {
|
3084
|
-
current.sectProps = sectProps;
|
3085
|
-
current.pageBreak = pBreakIndex != -1;
|
3086
|
-
current = { sectProps: null, elements: [], pageBreak: false };
|
3087
|
-
result.push(current);
|
3088
|
-
}
|
3089
|
-
if (pBreakIndex != -1) {
|
3090
|
-
let breakRun = p.children[pBreakIndex];
|
3091
|
-
let splitRun = rBreakIndex < breakRun.children.length - 1;
|
3092
|
-
if (pBreakIndex < p.children.length - 1 || splitRun) {
|
3093
|
-
var children = elem.children;
|
3094
|
-
var newParagraph = { ...elem, children: children.slice(pBreakIndex) };
|
3095
|
-
elem.children = children.slice(0, pBreakIndex);
|
3096
|
-
current.elements.push(newParagraph);
|
3097
|
-
if (splitRun) {
|
3098
|
-
let runChildren = breakRun.children;
|
3099
|
-
let newRun = { ...breakRun, children: runChildren.slice(0, rBreakIndex) };
|
3100
|
-
elem.children.push(newRun);
|
3101
|
-
breakRun.children = runChildren.slice(rBreakIndex);
|
3102
|
-
}
|
3103
|
-
}
|
3104
|
-
}
|
3105
|
-
}
|
3106
|
-
}
|
3107
|
-
let currentSectProps = null;
|
3108
|
-
for (let i = result.length - 1; i >= 0; i--) {
|
3109
|
-
if (result[i].sectProps == null) {
|
3110
|
-
result[i].sectProps = currentSectProps ?? defaultProps;
|
3111
|
-
} else {
|
3112
|
-
currentSectProps = result[i].sectProps;
|
3113
|
-
}
|
3114
|
-
}
|
3115
|
-
return result;
|
3116
|
-
}
|
3117
|
-
groupByPageBreaks(sections) {
|
3118
|
-
let current = [];
|
3119
|
-
let prev;
|
3120
|
-
const result = [current];
|
3121
|
-
for (let s of sections) {
|
3122
|
-
current.push(s);
|
3123
|
-
if (this.options.ignoreLastRenderedPageBreak || s.pageBreak || this.isPageBreakSection(prev, s.sectProps))
|
3124
|
-
result.push(current = []);
|
3125
|
-
prev = s.sectProps;
|
3126
|
-
}
|
3127
|
-
return result.filter((x) => x.length > 0);
|
3128
|
-
}
|
3129
|
-
renderWrapper(children) {
|
3130
|
-
return this.createElement("div", { className: `${this.className}-wrapper` }, children);
|
3131
|
-
}
|
3132
|
-
renderDefaultStyle() {
|
3133
|
-
var c = this.className;
|
3134
|
-
var styleText = `
|
3135
|
-
.${c}-wrapper { background: gray; padding: 30px; padding-bottom: 0px; display: flex; flex-flow: column; align-items: center; }
|
3136
|
-
.${c}-wrapper>section.${c} { background: white; box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); margin-bottom: 30px; }
|
3137
|
-
.${c} { color: black; hyphens: auto; text-underline-position: from-font; }
|
3138
|
-
section.${c} { box-sizing: border-box; display: flex; flex-flow: column nowrap; position: relative; overflow: hidden; }
|
3139
|
-
section.${c}>article { margin-bottom: auto; z-index: 1; }
|
3140
|
-
section.${c}>footer { z-index: 1; }
|
3141
|
-
.${c} table { border-collapse: collapse; }
|
3142
|
-
.${c} table td, .${c} table th { vertical-align: top; }
|
3143
|
-
.${c} p { margin: 0pt; min-height: 1em; }
|
3144
|
-
.${c} span { white-space: pre-wrap; overflow-wrap: break-word; }
|
3145
|
-
.${c} a { color: inherit; text-decoration: inherit; }
|
3146
|
-
.${c} svg { fill: transparent; }
|
3147
|
-
`;
|
3148
|
-
if (this.options.renderComments) {
|
3149
|
-
styleText += `
|
3150
|
-
.${c}-comment-ref { cursor: default; }
|
3151
|
-
.${c}-comment-popover { display: none; z-index: 1000; padding: 0.5rem; background: white; position: absolute; box-shadow: 0 0 0.25rem rgba(0, 0, 0, 0.25); width: 30ch; }
|
3152
|
-
.${c}-comment-ref:hover~.${c}-comment-popover { display: block; }
|
3153
|
-
.${c}-comment-author,.${c}-comment-date { font-size: 0.875rem; color: #888; }
|
3154
|
-
`;
|
3155
|
-
}
|
3156
|
-
return this.createStyleElement(styleText);
|
3157
|
-
}
|
3158
|
-
renderNumbering(numberings, styleContainer) {
|
3159
|
-
var styleText = "";
|
3160
|
-
var resetCounters = [];
|
3161
|
-
for (var num of numberings) {
|
3162
|
-
var selector = `p.${this.numberingClass(num.id, num.level)}`;
|
3163
|
-
var listStyleType = "none";
|
3164
|
-
if (num.bullet) {
|
3165
|
-
let valiable = `--${this.className}-${num.bullet.src}`.toLowerCase();
|
3166
|
-
styleText += this.styleToString(`${selector}:before`, {
|
3167
|
-
"content": "' '",
|
3168
|
-
"display": "inline-block",
|
3169
|
-
"background": `var(${valiable})`
|
3170
|
-
}, num.bullet.style);
|
3171
|
-
this.tasks.push(this.document.loadNumberingImage(num.bullet.src).then((data) => {
|
3172
|
-
var text = `${this.rootSelector} { ${valiable}: url(${data}) }`;
|
3173
|
-
styleContainer.appendChild(this.createStyleElement(text));
|
3174
|
-
}));
|
3175
|
-
} else if (num.levelText) {
|
3176
|
-
let counter = this.numberingCounter(num.id, num.level);
|
3177
|
-
const counterReset = counter + " " + (num.start - 1);
|
3178
|
-
if (num.level > 0) {
|
3179
|
-
styleText += this.styleToString(`p.${this.numberingClass(num.id, num.level - 1)}`, {
|
3180
|
-
"counter-reset": counterReset
|
3181
|
-
});
|
3182
|
-
}
|
3183
|
-
resetCounters.push(counterReset);
|
3184
|
-
styleText += this.styleToString(`${selector}:before`, {
|
3185
|
-
"content": this.levelTextToContent(num.levelText, num.suff, num.id, this.numFormatToCssValue(num.format)),
|
3186
|
-
"counter-increment": counter,
|
3187
|
-
...num.rStyle
|
3188
|
-
});
|
3189
|
-
} else {
|
3190
|
-
listStyleType = this.numFormatToCssValue(num.format);
|
3191
|
-
}
|
3192
|
-
styleText += this.styleToString(selector, {
|
3193
|
-
"display": "list-item",
|
3194
|
-
"list-style-position": "inside",
|
3195
|
-
"list-style-type": listStyleType,
|
3196
|
-
...num.pStyle
|
3197
|
-
});
|
3198
|
-
}
|
3199
|
-
if (resetCounters.length > 0) {
|
3200
|
-
styleText += this.styleToString(this.rootSelector, {
|
3201
|
-
"counter-reset": resetCounters.join(" ")
|
3202
|
-
});
|
3203
|
-
}
|
3204
|
-
return this.createStyleElement(styleText);
|
3205
|
-
}
|
3206
|
-
renderStyles(styles) {
|
3207
|
-
var styleText = "";
|
3208
|
-
const stylesMap = this.styleMap;
|
3209
|
-
const defautStyles = keyBy(styles.filter((s) => s.isDefault), (s) => s.target);
|
3210
|
-
for (const style of styles) {
|
3211
|
-
var subStyles = style.styles;
|
3212
|
-
if (style.linked) {
|
3213
|
-
var linkedStyle = style.linked && stylesMap[style.linked];
|
3214
|
-
if (linkedStyle)
|
3215
|
-
subStyles = subStyles.concat(linkedStyle.styles);
|
3216
|
-
else if (this.options.debug)
|
3217
|
-
console.warn(`Can't find linked style ${style.linked}`);
|
3218
|
-
}
|
3219
|
-
for (const subStyle of subStyles) {
|
3220
|
-
var selector = `${style.target ?? ""}.${style.cssName}`;
|
3221
|
-
if (style.target != subStyle.target)
|
3222
|
-
selector += ` ${subStyle.target}`;
|
3223
|
-
if (defautStyles[style.target] == style)
|
3224
|
-
selector = `.${this.className} ${style.target}, ` + selector;
|
3225
|
-
styleText += this.styleToString(selector, subStyle.values);
|
3226
|
-
}
|
3227
|
-
}
|
3228
|
-
return this.createStyleElement(styleText);
|
3229
|
-
}
|
3230
|
-
renderNotes(noteIds, notesMap, into) {
|
3231
|
-
var notes = noteIds.map((id) => notesMap[id]).filter((x) => x);
|
3232
|
-
if (notes.length > 0) {
|
3233
|
-
var result = this.createElement("ol", null, this.renderElements(notes));
|
3234
|
-
into.appendChild(result);
|
3235
|
-
}
|
3236
|
-
}
|
3237
|
-
renderElement(elem) {
|
3238
|
-
switch (elem.type) {
|
3239
|
-
case DomType.Paragraph:
|
3240
|
-
return this.renderParagraph(elem);
|
3241
|
-
case DomType.BookmarkStart:
|
3242
|
-
return this.renderBookmarkStart(elem);
|
3243
|
-
case DomType.BookmarkEnd:
|
3244
|
-
return null;
|
3245
|
-
case DomType.Run:
|
3246
|
-
return this.renderRun(elem);
|
3247
|
-
case DomType.Table:
|
3248
|
-
return this.renderTable(elem);
|
3249
|
-
case DomType.Row:
|
3250
|
-
return this.renderTableRow(elem);
|
3251
|
-
case DomType.Cell:
|
3252
|
-
return this.renderTableCell(elem);
|
3253
|
-
case DomType.Hyperlink:
|
3254
|
-
return this.renderHyperlink(elem);
|
3255
|
-
case DomType.SmartTag:
|
3256
|
-
return this.renderSmartTag(elem);
|
3257
|
-
case DomType.Drawing:
|
3258
|
-
return this.renderDrawing(elem);
|
3259
|
-
case DomType.Image:
|
3260
|
-
return this.renderImage(elem);
|
3261
|
-
case DomType.Text:
|
3262
|
-
return this.renderText(elem);
|
3263
|
-
case DomType.Text:
|
3264
|
-
return this.renderText(elem);
|
3265
|
-
case DomType.DeletedText:
|
3266
|
-
return this.renderDeletedText(elem);
|
3267
|
-
case DomType.Tab:
|
3268
|
-
return this.renderTab(elem);
|
3269
|
-
case DomType.Symbol:
|
3270
|
-
return this.renderSymbol(elem);
|
3271
|
-
case DomType.Break:
|
3272
|
-
return this.renderBreak(elem);
|
3273
|
-
case DomType.Footer:
|
3274
|
-
return this.renderContainer(elem, "footer");
|
3275
|
-
case DomType.Header:
|
3276
|
-
return this.renderContainer(elem, "header");
|
3277
|
-
case DomType.Footnote:
|
3278
|
-
case DomType.Endnote:
|
3279
|
-
return this.renderContainer(elem, "li");
|
3280
|
-
case DomType.FootnoteReference:
|
3281
|
-
return this.renderFootnoteReference(elem);
|
3282
|
-
case DomType.EndnoteReference:
|
3283
|
-
return this.renderEndnoteReference(elem);
|
3284
|
-
case DomType.NoBreakHyphen:
|
3285
|
-
return this.createElement("wbr");
|
3286
|
-
case DomType.VmlPicture:
|
3287
|
-
return this.renderVmlPicture(elem);
|
3288
|
-
case DomType.VmlElement:
|
3289
|
-
return this.renderVmlElement(elem);
|
3290
|
-
case DomType.MmlMath:
|
3291
|
-
return this.renderContainerNS(elem, ns.mathML, "math", { xmlns: ns.mathML });
|
3292
|
-
case DomType.MmlMathParagraph:
|
3293
|
-
return this.renderContainer(elem, "span");
|
3294
|
-
case DomType.MmlFraction:
|
3295
|
-
return this.renderContainerNS(elem, ns.mathML, "mfrac");
|
3296
|
-
case DomType.MmlBase:
|
3297
|
-
return this.renderContainerNS(elem, ns.mathML, elem.parent.type == DomType.MmlMatrixRow ? "mtd" : "mrow");
|
3298
|
-
case DomType.MmlNumerator:
|
3299
|
-
case DomType.MmlDenominator:
|
3300
|
-
case DomType.MmlFunction:
|
3301
|
-
case DomType.MmlLimit:
|
3302
|
-
case DomType.MmlBox:
|
3303
|
-
return this.renderContainerNS(elem, ns.mathML, "mrow");
|
3304
|
-
case DomType.MmlGroupChar:
|
3305
|
-
return this.renderMmlGroupChar(elem);
|
3306
|
-
case DomType.MmlLimitLower:
|
3307
|
-
return this.renderContainerNS(elem, ns.mathML, "munder");
|
3308
|
-
case DomType.MmlMatrix:
|
3309
|
-
return this.renderContainerNS(elem, ns.mathML, "mtable");
|
3310
|
-
case DomType.MmlMatrixRow:
|
3311
|
-
return this.renderContainerNS(elem, ns.mathML, "mtr");
|
3312
|
-
case DomType.MmlRadical:
|
3313
|
-
return this.renderMmlRadical(elem);
|
3314
|
-
case DomType.MmlSuperscript:
|
3315
|
-
return this.renderContainerNS(elem, ns.mathML, "msup");
|
3316
|
-
case DomType.MmlSubscript:
|
3317
|
-
return this.renderContainerNS(elem, ns.mathML, "msub");
|
3318
|
-
case DomType.MmlDegree:
|
3319
|
-
case DomType.MmlSuperArgument:
|
3320
|
-
case DomType.MmlSubArgument:
|
3321
|
-
return this.renderContainerNS(elem, ns.mathML, "mn");
|
3322
|
-
case DomType.MmlFunctionName:
|
3323
|
-
return this.renderContainerNS(elem, ns.mathML, "ms");
|
3324
|
-
case DomType.MmlDelimiter:
|
3325
|
-
return this.renderMmlDelimiter(elem);
|
3326
|
-
case DomType.MmlRun:
|
3327
|
-
return this.renderMmlRun(elem);
|
3328
|
-
case DomType.MmlNary:
|
3329
|
-
return this.renderMmlNary(elem);
|
3330
|
-
case DomType.MmlPreSubSuper:
|
3331
|
-
return this.renderMmlPreSubSuper(elem);
|
3332
|
-
case DomType.MmlBar:
|
3333
|
-
return this.renderMmlBar(elem);
|
3334
|
-
case DomType.MmlEquationArray:
|
3335
|
-
return this.renderMllList(elem);
|
3336
|
-
case DomType.Inserted:
|
3337
|
-
return this.renderInserted(elem);
|
3338
|
-
case DomType.Deleted:
|
3339
|
-
return this.renderDeleted(elem);
|
3340
|
-
case DomType.CommentRangeStart:
|
3341
|
-
return this.renderCommentRangeStart(elem);
|
3342
|
-
case DomType.CommentRangeEnd:
|
3343
|
-
return this.renderCommentRangeEnd(elem);
|
3344
|
-
case DomType.CommentReference:
|
3345
|
-
return this.renderCommentReference(elem);
|
3346
|
-
}
|
3347
|
-
return null;
|
3348
|
-
}
|
3349
|
-
renderElements(elems, into) {
|
3350
|
-
if (elems == null)
|
3351
|
-
return null;
|
3352
|
-
var result = elems.flatMap((e) => this.renderElement(e)).filter((e) => e != null);
|
3353
|
-
if (into)
|
3354
|
-
appendChildren(into, result);
|
3355
|
-
return result;
|
3356
|
-
}
|
3357
|
-
renderContainer(elem, tagName, props) {
|
3358
|
-
return this.createElement(tagName, props, this.renderElements(elem.children));
|
3359
|
-
}
|
3360
|
-
renderContainerNS(elem, ns2, tagName, props) {
|
3361
|
-
return this.createElementNS(ns2, tagName, props, this.renderElements(elem.children));
|
3362
|
-
}
|
3363
|
-
renderParagraph(elem) {
|
3364
|
-
var _a, _b;
|
3365
|
-
var result = this.renderContainer(elem, "p");
|
3366
|
-
const style = this.findStyle(elem.styleName);
|
3367
|
-
elem.tabs ?? (elem.tabs = (_a = style == null ? void 0 : style.paragraphProps) == null ? void 0 : _a.tabs);
|
3368
|
-
this.renderClass(elem, result);
|
3369
|
-
this.renderStyleValues(elem.cssStyle, result);
|
3370
|
-
this.renderCommonProperties(result.style, elem);
|
3371
|
-
const numbering = elem.numbering ?? ((_b = style == null ? void 0 : style.paragraphProps) == null ? void 0 : _b.numbering);
|
3372
|
-
if (numbering) {
|
3373
|
-
result.classList.add(this.numberingClass(numbering.id, numbering.level));
|
3374
|
-
}
|
3375
|
-
return result;
|
3376
|
-
}
|
3377
|
-
renderRunProperties(style, props) {
|
3378
|
-
this.renderCommonProperties(style, props);
|
3379
|
-
}
|
3380
|
-
renderCommonProperties(style, props) {
|
3381
|
-
if (props == null)
|
3382
|
-
return;
|
3383
|
-
if (props.color) {
|
3384
|
-
style["color"] = props.color;
|
3385
|
-
}
|
3386
|
-
if (props.fontSize) {
|
3387
|
-
style["font-size"] = props.fontSize;
|
3388
|
-
}
|
3389
|
-
}
|
3390
|
-
renderHyperlink(elem) {
|
3391
|
-
var result = this.renderContainer(elem, "a");
|
3392
|
-
this.renderStyleValues(elem.cssStyle, result);
|
3393
|
-
if (elem.href) {
|
3394
|
-
result.href = elem.href;
|
3395
|
-
} else if (elem.id) {
|
3396
|
-
const rel = this.document.documentPart.rels.find((it) => it.id == elem.id && it.targetMode === "External");
|
3397
|
-
result.href = rel == null ? void 0 : rel.target;
|
3398
|
-
}
|
3399
|
-
return result;
|
3400
|
-
}
|
3401
|
-
renderSmartTag(elem) {
|
3402
|
-
return this.renderContainer(elem, "span");
|
3403
|
-
}
|
3404
|
-
renderCommentRangeStart(commentStart) {
|
3405
|
-
var _a;
|
3406
|
-
if (!this.options.renderComments)
|
3407
|
-
return null;
|
3408
|
-
const rng = new Range();
|
3409
|
-
(_a = this.commentHighlight) == null ? void 0 : _a.add(rng);
|
3410
|
-
const result = this.htmlDocument.createComment(`start of comment #${commentStart.id}`);
|
3411
|
-
this.later(() => rng.setStart(result, 0));
|
3412
|
-
this.commentMap[commentStart.id] = rng;
|
3413
|
-
return result;
|
3414
|
-
}
|
3415
|
-
renderCommentRangeEnd(commentEnd) {
|
3416
|
-
if (!this.options.renderComments)
|
3417
|
-
return null;
|
3418
|
-
const rng = this.commentMap[commentEnd.id];
|
3419
|
-
const result = this.htmlDocument.createComment(`end of comment #${commentEnd.id}`);
|
3420
|
-
this.later(() => rng == null ? void 0 : rng.setEnd(result, 0));
|
3421
|
-
return result;
|
3422
|
-
}
|
3423
|
-
renderCommentReference(commentRef) {
|
3424
|
-
var _a;
|
3425
|
-
if (!this.options.renderComments)
|
3426
|
-
return null;
|
3427
|
-
var comment = (_a = this.document.commentsPart) == null ? void 0 : _a.commentMap[commentRef.id];
|
3428
|
-
if (!comment)
|
3429
|
-
return null;
|
3430
|
-
const frg = new DocumentFragment();
|
3431
|
-
const commentRefEl = this.createElement("span", { className: `${this.className}-comment-ref` }, ["💬"]);
|
3432
|
-
const commentsContainerEl = this.createElement("div", { className: `${this.className}-comment-popover` });
|
3433
|
-
this.renderCommentContent(comment, commentsContainerEl);
|
3434
|
-
frg.appendChild(this.htmlDocument.createComment(`comment #${comment.id} by ${comment.author} on ${comment.date}`));
|
3435
|
-
frg.appendChild(commentRefEl);
|
3436
|
-
frg.appendChild(commentsContainerEl);
|
3437
|
-
return frg;
|
3438
|
-
}
|
3439
|
-
renderCommentContent(comment, container) {
|
3440
|
-
container.appendChild(this.createElement("div", { className: `${this.className}-comment-author` }, [comment.author]));
|
3441
|
-
container.appendChild(this.createElement("div", { className: `${this.className}-comment-date` }, [new Date(comment.date).toLocaleString()]));
|
3442
|
-
this.renderElements(comment.children, container);
|
3443
|
-
}
|
3444
|
-
renderDrawing(elem) {
|
3445
|
-
var result = this.renderContainer(elem, "div");
|
3446
|
-
result.style.display = "inline-block";
|
3447
|
-
result.style.position = "relative";
|
3448
|
-
result.style.textIndent = "0px";
|
3449
|
-
this.renderStyleValues(elem.cssStyle, result);
|
3450
|
-
return result;
|
3451
|
-
}
|
3452
|
-
renderImage(elem) {
|
3453
|
-
let result = this.createElement("img");
|
3454
|
-
this.renderStyleValues(elem.cssStyle, result);
|
3455
|
-
if (this.document) {
|
3456
|
-
this.tasks.push(this.document.loadDocumentImage(elem.src, this.currentPart).then((x) => {
|
3457
|
-
result.src = x;
|
3458
|
-
}));
|
3459
|
-
}
|
3460
|
-
return result;
|
3461
|
-
}
|
3462
|
-
renderText(elem) {
|
3463
|
-
return this.htmlDocument.createTextNode(elem.text);
|
3464
|
-
}
|
3465
|
-
renderDeletedText(elem) {
|
3466
|
-
return this.options.renderEndnotes ? this.htmlDocument.createTextNode(elem.text) : null;
|
3467
|
-
}
|
3468
|
-
renderBreak(elem) {
|
3469
|
-
if (elem.break == "textWrapping") {
|
3470
|
-
return this.createElement("br");
|
3471
|
-
}
|
3472
|
-
return null;
|
3473
|
-
}
|
3474
|
-
renderInserted(elem) {
|
3475
|
-
if (this.options.renderChanges)
|
3476
|
-
return this.renderContainer(elem, "ins");
|
3477
|
-
return this.renderElements(elem.children);
|
3478
|
-
}
|
3479
|
-
renderDeleted(elem) {
|
3480
|
-
if (this.options.renderChanges)
|
3481
|
-
return this.renderContainer(elem, "del");
|
3482
|
-
return null;
|
3483
|
-
}
|
3484
|
-
renderSymbol(elem) {
|
3485
|
-
var span = this.createElement("span");
|
3486
|
-
span.style.fontFamily = elem.font;
|
3487
|
-
span.innerHTML = `&#x${elem.char};`;
|
3488
|
-
return span;
|
3489
|
-
}
|
3490
|
-
renderFootnoteReference(elem) {
|
3491
|
-
var result = this.createElement("sup");
|
3492
|
-
this.currentFootnoteIds.push(elem.id);
|
3493
|
-
result.textContent = `${this.currentFootnoteIds.length}`;
|
3494
|
-
return result;
|
3495
|
-
}
|
3496
|
-
renderEndnoteReference(elem) {
|
3497
|
-
var result = this.createElement("sup");
|
3498
|
-
this.currentEndnoteIds.push(elem.id);
|
3499
|
-
result.textContent = `${this.currentEndnoteIds.length}`;
|
3500
|
-
return result;
|
3501
|
-
}
|
3502
|
-
renderTab(elem) {
|
3503
|
-
var _a;
|
3504
|
-
var tabSpan = this.createElement("span");
|
3505
|
-
tabSpan.innerHTML = " ";
|
3506
|
-
if (this.options.experimental) {
|
3507
|
-
tabSpan.className = this.tabStopClass();
|
3508
|
-
var stops = (_a = findParent(elem, DomType.Paragraph)) == null ? void 0 : _a.tabs;
|
3509
|
-
this.currentTabs.push({ stops, span: tabSpan });
|
3510
|
-
}
|
3511
|
-
return tabSpan;
|
3512
|
-
}
|
3513
|
-
renderBookmarkStart(elem) {
|
3514
|
-
return this.createElement("span", { id: elem.name });
|
3515
|
-
}
|
3516
|
-
renderRun(elem) {
|
3517
|
-
if (elem.fieldRun)
|
3518
|
-
return null;
|
3519
|
-
const result = this.createElement("span");
|
3520
|
-
if (elem.id)
|
3521
|
-
result.id = elem.id;
|
3522
|
-
this.renderClass(elem, result);
|
3523
|
-
this.renderStyleValues(elem.cssStyle, result);
|
3524
|
-
if (elem.verticalAlign) {
|
3525
|
-
const wrapper = this.createElement(elem.verticalAlign);
|
3526
|
-
this.renderElements(elem.children, wrapper);
|
3527
|
-
result.appendChild(wrapper);
|
3528
|
-
} else {
|
3529
|
-
this.renderElements(elem.children, result);
|
3530
|
-
}
|
3531
|
-
return result;
|
3532
|
-
}
|
3533
|
-
renderTable(elem) {
|
3534
|
-
let result = this.createElement("table");
|
3535
|
-
this.tableCellPositions.push(this.currentCellPosition);
|
3536
|
-
this.tableVerticalMerges.push(this.currentVerticalMerge);
|
3537
|
-
this.currentVerticalMerge = {};
|
3538
|
-
this.currentCellPosition = { col: 0, row: 0 };
|
3539
|
-
if (elem.columns)
|
3540
|
-
result.appendChild(this.renderTableColumns(elem.columns));
|
3541
|
-
this.renderClass(elem, result);
|
3542
|
-
this.renderElements(elem.children, result);
|
3543
|
-
this.renderStyleValues(elem.cssStyle, result);
|
3544
|
-
this.currentVerticalMerge = this.tableVerticalMerges.pop();
|
3545
|
-
this.currentCellPosition = this.tableCellPositions.pop();
|
3546
|
-
return result;
|
3547
|
-
}
|
3548
|
-
renderTableColumns(columns) {
|
3549
|
-
let result = this.createElement("colgroup");
|
3550
|
-
for (let col of columns) {
|
3551
|
-
let colElem = this.createElement("col");
|
3552
|
-
if (col.width)
|
3553
|
-
colElem.style.width = col.width;
|
3554
|
-
result.appendChild(colElem);
|
3555
|
-
}
|
3556
|
-
return result;
|
3557
|
-
}
|
3558
|
-
renderTableRow(elem) {
|
3559
|
-
let result = this.renderContainer(elem, "tr");
|
3560
|
-
this.currentCellPosition.col = 0;
|
3561
|
-
this.renderClass(elem, result);
|
3562
|
-
this.renderStyleValues(elem.cssStyle, result);
|
3563
|
-
this.currentCellPosition.row++;
|
3564
|
-
return result;
|
3565
|
-
}
|
3566
|
-
renderTableCell(elem) {
|
3567
|
-
let result = this.renderContainer(elem, "td");
|
3568
|
-
const key = this.currentCellPosition.col;
|
3569
|
-
if (elem.verticalMerge) {
|
3570
|
-
if (elem.verticalMerge == "restart") {
|
3571
|
-
this.currentVerticalMerge[key] = result;
|
3572
|
-
result.rowSpan = 1;
|
3573
|
-
} else if (this.currentVerticalMerge[key]) {
|
3574
|
-
this.currentVerticalMerge[key].rowSpan += 1;
|
3575
|
-
result.style.display = "none";
|
3576
|
-
}
|
3577
|
-
} else {
|
3578
|
-
this.currentVerticalMerge[key] = null;
|
3579
|
-
}
|
3580
|
-
this.renderClass(elem, result);
|
3581
|
-
this.renderStyleValues(elem.cssStyle, result);
|
3582
|
-
if (elem.span)
|
3583
|
-
result.colSpan = elem.span;
|
3584
|
-
this.currentCellPosition.col += result.colSpan;
|
3585
|
-
return result;
|
3586
|
-
}
|
3587
|
-
renderVmlPicture(elem) {
|
3588
|
-
return this.renderContainer(elem, "div");
|
3589
|
-
}
|
3590
|
-
renderVmlElement(elem) {
|
3591
|
-
var _a, _b;
|
3592
|
-
var container = this.createSvgElement("svg");
|
3593
|
-
container.setAttribute("style", elem.cssStyleText);
|
3594
|
-
const result = this.renderVmlChildElement(elem);
|
3595
|
-
if ((_a = elem.imageHref) == null ? void 0 : _a.id) {
|
3596
|
-
this.tasks.push((_b = this.document) == null ? void 0 : _b.loadDocumentImage(elem.imageHref.id, this.currentPart).then((x) => result.setAttribute("href", x)));
|
3597
|
-
}
|
3598
|
-
container.appendChild(result);
|
3599
|
-
requestAnimationFrame(() => {
|
3600
|
-
const bb = container.firstElementChild.getBBox();
|
3601
|
-
container.setAttribute("width", `${Math.ceil(bb.x + bb.width)}`);
|
3602
|
-
container.setAttribute("height", `${Math.ceil(bb.y + bb.height)}`);
|
3603
|
-
});
|
3604
|
-
return container;
|
3605
|
-
}
|
3606
|
-
renderVmlChildElement(elem) {
|
3607
|
-
const result = this.createSvgElement(elem.tagName);
|
3608
|
-
Object.entries(elem.attrs).forEach(([k, v]) => result.setAttribute(k, v));
|
3609
|
-
for (let child of elem.children) {
|
3610
|
-
if (child.type == DomType.VmlElement) {
|
3611
|
-
result.appendChild(this.renderVmlChildElement(child));
|
3612
|
-
} else {
|
3613
|
-
result.appendChild(...asArray(this.renderElement(child)));
|
3614
|
-
}
|
3615
|
-
}
|
3616
|
-
return result;
|
3617
|
-
}
|
3618
|
-
renderMmlRadical(elem) {
|
3619
|
-
var _a;
|
3620
|
-
const base = elem.children.find((el) => el.type == DomType.MmlBase);
|
3621
|
-
if ((_a = elem.props) == null ? void 0 : _a.hideDegree) {
|
3622
|
-
return this.createElementNS(ns.mathML, "msqrt", null, this.renderElements([base]));
|
3623
|
-
}
|
3624
|
-
const degree = elem.children.find((el) => el.type == DomType.MmlDegree);
|
3625
|
-
return this.createElementNS(ns.mathML, "mroot", null, this.renderElements([base, degree]));
|
3626
|
-
}
|
3627
|
-
renderMmlDelimiter(elem) {
|
3628
|
-
const children = [];
|
3629
|
-
children.push(this.createElementNS(ns.mathML, "mo", null, [elem.props.beginChar ?? "("]));
|
3630
|
-
children.push(...this.renderElements(elem.children));
|
3631
|
-
children.push(this.createElementNS(ns.mathML, "mo", null, [elem.props.endChar ?? ")"]));
|
3632
|
-
return this.createElementNS(ns.mathML, "mrow", null, children);
|
3633
|
-
}
|
3634
|
-
renderMmlNary(elem) {
|
3635
|
-
var _a;
|
3636
|
-
const children = [];
|
3637
|
-
const grouped = keyBy(elem.children, (x) => x.type);
|
3638
|
-
const sup = grouped[DomType.MmlSuperArgument];
|
3639
|
-
const sub = grouped[DomType.MmlSubArgument];
|
3640
|
-
const supElem = sup ? this.createElementNS(ns.mathML, "mo", null, asArray(this.renderElement(sup))) : null;
|
3641
|
-
const subElem = sub ? this.createElementNS(ns.mathML, "mo", null, asArray(this.renderElement(sub))) : null;
|
3642
|
-
const charElem = this.createElementNS(ns.mathML, "mo", null, [((_a = elem.props) == null ? void 0 : _a.char) ?? "∫"]);
|
3643
|
-
if (supElem || subElem) {
|
3644
|
-
children.push(this.createElementNS(ns.mathML, "munderover", null, [charElem, subElem, supElem]));
|
3645
|
-
} else if (supElem) {
|
3646
|
-
children.push(this.createElementNS(ns.mathML, "mover", null, [charElem, supElem]));
|
3647
|
-
} else if (subElem) {
|
3648
|
-
children.push(this.createElementNS(ns.mathML, "munder", null, [charElem, subElem]));
|
3649
|
-
} else {
|
3650
|
-
children.push(charElem);
|
3651
|
-
}
|
3652
|
-
children.push(...this.renderElements(grouped[DomType.MmlBase].children));
|
3653
|
-
return this.createElementNS(ns.mathML, "mrow", null, children);
|
3654
|
-
}
|
3655
|
-
renderMmlPreSubSuper(elem) {
|
3656
|
-
const children = [];
|
3657
|
-
const grouped = keyBy(elem.children, (x) => x.type);
|
3658
|
-
const sup = grouped[DomType.MmlSuperArgument];
|
3659
|
-
const sub = grouped[DomType.MmlSubArgument];
|
3660
|
-
const supElem = sup ? this.createElementNS(ns.mathML, "mo", null, asArray(this.renderElement(sup))) : null;
|
3661
|
-
const subElem = sub ? this.createElementNS(ns.mathML, "mo", null, asArray(this.renderElement(sub))) : null;
|
3662
|
-
const stubElem = this.createElementNS(ns.mathML, "mo", null);
|
3663
|
-
children.push(this.createElementNS(ns.mathML, "msubsup", null, [stubElem, subElem, supElem]));
|
3664
|
-
children.push(...this.renderElements(grouped[DomType.MmlBase].children));
|
3665
|
-
return this.createElementNS(ns.mathML, "mrow", null, children);
|
3666
|
-
}
|
3667
|
-
renderMmlGroupChar(elem) {
|
3668
|
-
const tagName = elem.props.verticalJustification === "bot" ? "mover" : "munder";
|
3669
|
-
const result = this.renderContainerNS(elem, ns.mathML, tagName);
|
3670
|
-
if (elem.props.char) {
|
3671
|
-
result.appendChild(this.createElementNS(ns.mathML, "mo", null, [elem.props.char]));
|
3672
|
-
}
|
3673
|
-
return result;
|
3674
|
-
}
|
3675
|
-
renderMmlBar(elem) {
|
3676
|
-
const result = this.renderContainerNS(elem, ns.mathML, "mrow");
|
3677
|
-
switch (elem.props.position) {
|
3678
|
-
case "top":
|
3679
|
-
result.style.textDecoration = "overline";
|
3680
|
-
break;
|
3681
|
-
case "bottom":
|
3682
|
-
result.style.textDecoration = "underline";
|
3683
|
-
break;
|
3684
|
-
}
|
3685
|
-
return result;
|
3686
|
-
}
|
3687
|
-
renderMmlRun(elem) {
|
3688
|
-
const result = this.createElementNS(ns.mathML, "ms", null, this.renderElements(elem.children));
|
3689
|
-
this.renderClass(elem, result);
|
3690
|
-
this.renderStyleValues(elem.cssStyle, result);
|
3691
|
-
return result;
|
3692
|
-
}
|
3693
|
-
renderMllList(elem) {
|
3694
|
-
const result = this.createElementNS(ns.mathML, "mtable");
|
3695
|
-
this.renderClass(elem, result);
|
3696
|
-
this.renderStyleValues(elem.cssStyle, result);
|
3697
|
-
for (let child of this.renderElements(elem.children)) {
|
3698
|
-
result.appendChild(this.createElementNS(ns.mathML, "mtr", null, [
|
3699
|
-
this.createElementNS(ns.mathML, "mtd", null, [child])
|
3700
|
-
]));
|
3701
|
-
}
|
3702
|
-
return result;
|
3703
|
-
}
|
3704
|
-
renderStyleValues(style, ouput) {
|
3705
|
-
for (let k in style) {
|
3706
|
-
if (k.startsWith("$")) {
|
3707
|
-
ouput.setAttribute(k.slice(1), style[k]);
|
3708
|
-
} else {
|
3709
|
-
ouput.style[k] = style[k];
|
3710
|
-
}
|
3711
|
-
}
|
3712
|
-
}
|
3713
|
-
renderClass(input, ouput) {
|
3714
|
-
if (input.className)
|
3715
|
-
ouput.className = input.className;
|
3716
|
-
if (input.styleName)
|
3717
|
-
ouput.classList.add(this.processStyleName(input.styleName));
|
3718
|
-
}
|
3719
|
-
findStyle(styleName) {
|
3720
|
-
var _a;
|
3721
|
-
return styleName && ((_a = this.styleMap) == null ? void 0 : _a[styleName]);
|
3722
|
-
}
|
3723
|
-
numberingClass(id, lvl) {
|
3724
|
-
return `${this.className}-num-${id}-${lvl}`;
|
3725
|
-
}
|
3726
|
-
tabStopClass() {
|
3727
|
-
return `${this.className}-tab-stop`;
|
3728
|
-
}
|
3729
|
-
styleToString(selectors, values2, cssText = null) {
|
3730
|
-
let result = `${selectors} {\r
|
3731
|
-
`;
|
3732
|
-
for (const key in values2) {
|
3733
|
-
if (key.startsWith("$"))
|
3734
|
-
continue;
|
3735
|
-
result += ` ${key}: ${values2[key]};\r
|
3736
|
-
`;
|
3737
|
-
}
|
3738
|
-
if (cssText)
|
3739
|
-
result += cssText;
|
3740
|
-
return result + "}\r\n";
|
3741
|
-
}
|
3742
|
-
numberingCounter(id, lvl) {
|
3743
|
-
return `${this.className}-num-${id}-${lvl}`;
|
3744
|
-
}
|
3745
|
-
levelTextToContent(text, suff, id, numformat) {
|
3746
|
-
const suffMap = {
|
3747
|
-
"tab": "\\9",
|
3748
|
-
"space": "\\a0"
|
3749
|
-
};
|
3750
|
-
var result = text.replace(/%\d*/g, (s) => {
|
3751
|
-
let lvl = parseInt(s.substring(1), 10) - 1;
|
3752
|
-
return `"counter(${this.numberingCounter(id, lvl)}, ${numformat})"`;
|
3753
|
-
});
|
3754
|
-
return `"${result}${suffMap[suff] ?? ""}"`;
|
3755
|
-
}
|
3756
|
-
numFormatToCssValue(format) {
|
3757
|
-
var mapping = {
|
3758
|
-
none: "none",
|
3759
|
-
bullet: "disc",
|
3760
|
-
decimal: "decimal",
|
3761
|
-
lowerLetter: "lower-alpha",
|
3762
|
-
upperLetter: "upper-alpha",
|
3763
|
-
lowerRoman: "lower-roman",
|
3764
|
-
upperRoman: "upper-roman",
|
3765
|
-
decimalZero: "decimal-leading-zero",
|
3766
|
-
aiueo: "katakana",
|
3767
|
-
aiueoFullWidth: "katakana",
|
3768
|
-
chineseCounting: "simp-chinese-informal",
|
3769
|
-
chineseCountingThousand: "simp-chinese-informal",
|
3770
|
-
chineseLegalSimplified: "simp-chinese-formal",
|
3771
|
-
chosung: "hangul-consonant",
|
3772
|
-
ideographDigital: "cjk-ideographic",
|
3773
|
-
ideographTraditional: "cjk-heavenly-stem",
|
3774
|
-
ideographLegalTraditional: "trad-chinese-formal",
|
3775
|
-
ideographZodiac: "cjk-earthly-branch",
|
3776
|
-
iroha: "katakana-iroha",
|
3777
|
-
irohaFullWidth: "katakana-iroha",
|
3778
|
-
japaneseCounting: "japanese-informal",
|
3779
|
-
japaneseDigitalTenThousand: "cjk-decimal",
|
3780
|
-
japaneseLegal: "japanese-formal",
|
3781
|
-
thaiNumbers: "thai",
|
3782
|
-
koreanCounting: "korean-hangul-formal",
|
3783
|
-
koreanDigital: "korean-hangul-formal",
|
3784
|
-
koreanDigital2: "korean-hanja-informal",
|
3785
|
-
hebrew1: "hebrew",
|
3786
|
-
hebrew2: "hebrew",
|
3787
|
-
hindiNumbers: "devanagari",
|
3788
|
-
ganada: "hangul",
|
3789
|
-
taiwaneseCounting: "cjk-ideographic",
|
3790
|
-
taiwaneseCountingThousand: "cjk-ideographic",
|
3791
|
-
taiwaneseDigital: "cjk-decimal"
|
3792
|
-
};
|
3793
|
-
return mapping[format] ?? format;
|
3794
|
-
}
|
3795
|
-
refreshTabStops() {
|
3796
|
-
if (!this.options.experimental)
|
3797
|
-
return;
|
3798
|
-
setTimeout(() => {
|
3799
|
-
const pixelToPoint = computePixelToPoint();
|
3800
|
-
for (let tab of this.currentTabs) {
|
3801
|
-
updateTabStop(tab.span, tab.stops, this.defaultTabSize, pixelToPoint);
|
3802
|
-
}
|
3803
|
-
}, 500);
|
3804
|
-
}
|
3805
|
-
createElementNS(ns2, tagName, props, children) {
|
3806
|
-
var result = ns2 ? this.htmlDocument.createElementNS(ns2, tagName) : this.htmlDocument.createElement(tagName);
|
3807
|
-
Object.assign(result, props);
|
3808
|
-
children && appendChildren(result, children);
|
3809
|
-
return result;
|
3810
|
-
}
|
3811
|
-
createElement(tagName, props, children) {
|
3812
|
-
return this.createElementNS(void 0, tagName, props, children);
|
3813
|
-
}
|
3814
|
-
createSvgElement(tagName, props, children) {
|
3815
|
-
return this.createElementNS(ns.svg, tagName, props, children);
|
3816
|
-
}
|
3817
|
-
createStyleElement(cssText) {
|
3818
|
-
return this.createElement("style", { innerHTML: cssText });
|
3819
|
-
}
|
3820
|
-
createComment(text) {
|
3821
|
-
return this.htmlDocument.createComment(text);
|
3822
|
-
}
|
3823
|
-
later(func) {
|
3824
|
-
this.postRenderTasks.push(func);
|
3825
|
-
}
|
3826
|
-
}
|
3827
|
-
function removeAllElements(elem) {
|
3828
|
-
elem.innerHTML = "";
|
3829
|
-
}
|
3830
|
-
function appendChildren(elem, children) {
|
3831
|
-
children.forEach((c) => elem.appendChild(isString(c) ? document.createTextNode(c) : c));
|
3832
|
-
}
|
3833
|
-
function findParent(elem, type) {
|
3834
|
-
var parent = elem.parent;
|
3835
|
-
while (parent != null && parent.type != type)
|
3836
|
-
parent = parent.parent;
|
3837
|
-
return parent;
|
3838
|
-
}
|
3839
|
-
const defaultOptions = {
|
3840
|
-
ignoreHeight: false,
|
3841
|
-
ignoreWidth: false,
|
3842
|
-
ignoreFonts: false,
|
3843
|
-
breakPages: true,
|
3844
|
-
debug: false,
|
3845
|
-
experimental: false,
|
3846
|
-
className: "docx",
|
3847
|
-
inWrapper: true,
|
3848
|
-
trimXmlDeclaration: true,
|
3849
|
-
ignoreLastRenderedPageBreak: true,
|
3850
|
-
renderHeaders: true,
|
3851
|
-
renderFooters: true,
|
3852
|
-
renderFootnotes: true,
|
3853
|
-
renderEndnotes: true,
|
3854
|
-
useBase64URL: false,
|
3855
|
-
renderChanges: false,
|
3856
|
-
renderComments: false
|
3857
|
-
};
|
3858
|
-
function parseAsync(data, userOptions) {
|
3859
|
-
const ops = { ...defaultOptions, ...userOptions };
|
3860
|
-
return WordDocument.load(data, new DocumentParser(ops), ops);
|
3861
|
-
}
|
3862
|
-
async function renderDocument(document2, bodyContainer, styleContainer, userOptions) {
|
3863
|
-
const ops = { ...defaultOptions, ...userOptions };
|
3864
|
-
const renderer = new HtmlRenderer(window.document);
|
3865
|
-
return await renderer.render(document2, bodyContainer, styleContainer, ops);
|
3866
|
-
}
|
3867
|
-
async function renderAsync(data, bodyContainer, styleContainer, userOptions) {
|
3868
|
-
const doc = await parseAsync(data, userOptions);
|
3869
|
-
await renderDocument(doc, bodyContainer, styleContainer, userOptions);
|
3870
|
-
return doc;
|
3871
|
-
}
|
3872
|
-
export {
|
3873
|
-
defaultOptions,
|
3874
|
-
parseAsync,
|
3875
|
-
renderAsync,
|
3876
|
-
renderDocument
|
3877
|
-
};
|