document-viewer-vue3 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +178 -0
- package/THIRD_PARTY_NOTICES.md +43 -0
- package/document-viewer-vue3/README.md +178 -0
- package/document-viewer-vue3/chunks/defineProperty-CGeCBTWF.js +39 -0
- package/document-viewer-vue3/chunks/jszip.min-BuCM2Hjj.js +3051 -0
- package/document-viewer-vue3/chunks/pdf-DaNcdZr-.js +14983 -0
- package/document-viewer-vue3/chunks/presentation-m6mYdP0-.js +97 -0
- package/document-viewer-vue3/chunks/spreadsheet-DLmwTbuh.js +16350 -0
- package/document-viewer-vue3/chunks/word-B__uJIJJ.js +3188 -0
- package/document-viewer-vue3/chunks/word-binary-DsiUIgdh.js +6144 -0
- package/document-viewer-vue3/chunks/word-ml-5809L5ca.js +161 -0
- package/document-viewer-vue3/document-viewer-vue3.js +317 -0
- package/document-viewer-vue3/document-viewer-vue3.umd.cjs +94 -0
- package/document-viewer-vue3/style.css +2 -0
- package/document-viewer-vue3/types/components/DocumentViewer.vue.d.ts +42 -0
- package/document-viewer-vue3/types/formats.d.ts +7 -0
- package/document-viewer-vue3/types/index.d.ts +11 -0
- package/document-viewer-vue3/types/types.d.ts +80 -0
- package/package.json +87 -0
|
@@ -0,0 +1,3188 @@
|
|
|
1
|
+
import { n as e, t } from "./jszip.min-BuCM2Hjj.js";
|
|
2
|
+
//#region node_modules/.pnpm/docx-preview@0.4.1/node_modules/docx-preview/dist/docx-preview.mjs
|
|
3
|
+
var n = /* @__PURE__ */ e(t(), 1), r;
|
|
4
|
+
(function(e) {
|
|
5
|
+
e.OfficeDocument = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", e.FontTable = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable", e.Image = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", e.Numbering = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", e.Styles = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", e.StylesWithEffects = "http://schemas.microsoft.com/office/2007/relationships/stylesWithEffects", e.Theme = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme", e.Settings = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings", e.WebSettings = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings", e.Hyperlink = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", e.Footnotes = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes", e.Endnotes = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes", e.Footer = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", e.Header = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", e.ExtendedProperties = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", e.CoreProperties = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties", e.CustomProperties = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/custom-properties", e.Comments = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments", e.CommentsExtended = "http://schemas.microsoft.com/office/2011/relationships/commentsExtended", e.AltChunk = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk";
|
|
6
|
+
})(r || (r = {}));
|
|
7
|
+
function i(e, t) {
|
|
8
|
+
return t.elements(e).map((e) => ({
|
|
9
|
+
id: t.attr(e, "Id"),
|
|
10
|
+
type: t.attr(e, "Type"),
|
|
11
|
+
target: t.attr(e, "Target"),
|
|
12
|
+
targetMode: t.attr(e, "TargetMode")
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
function a(e) {
|
|
16
|
+
return e?.replace(/[ .]+/g, "-").replace(/[&]+/g, "and").toLowerCase();
|
|
17
|
+
}
|
|
18
|
+
function o(e) {
|
|
19
|
+
return /^[^"'].*\s.*[^"']$/.test(e) ? `'${e}'` : e;
|
|
20
|
+
}
|
|
21
|
+
function s(e) {
|
|
22
|
+
let t = e.lastIndexOf("/") + 1;
|
|
23
|
+
return [t == 0 ? "" : e.substring(0, t), t == 0 ? e : e.substring(t)];
|
|
24
|
+
}
|
|
25
|
+
function c(e, t) {
|
|
26
|
+
try {
|
|
27
|
+
return new URL(e, "http://docx/" + t).toString().substring(12);
|
|
28
|
+
} catch {
|
|
29
|
+
return `${t}${e}`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function l(e, t) {
|
|
33
|
+
return e.reduce((e, n) => (e[t(n)] = n, e), {});
|
|
34
|
+
}
|
|
35
|
+
function u(e) {
|
|
36
|
+
return new Promise((t, n) => {
|
|
37
|
+
let r = new FileReader();
|
|
38
|
+
r.onloadend = () => t(r.result), r.onerror = () => n(), r.readAsDataURL(e);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function d(e) {
|
|
42
|
+
return e && typeof e == "object" && !Array.isArray(e);
|
|
43
|
+
}
|
|
44
|
+
function f(e) {
|
|
45
|
+
return typeof e == "string" || e instanceof String;
|
|
46
|
+
}
|
|
47
|
+
function p(e, ...t) {
|
|
48
|
+
if (!t.length) return e;
|
|
49
|
+
let n = t.shift();
|
|
50
|
+
if (d(e) && d(n)) for (let t in n) d(n[t]) ? p(e[t] ?? (e[t] = {}), n[t]) : e[t] = n[t];
|
|
51
|
+
return p(e, ...t);
|
|
52
|
+
}
|
|
53
|
+
function m(e) {
|
|
54
|
+
return Array.isArray(e) ? e : [e];
|
|
55
|
+
}
|
|
56
|
+
function h(e, t, n) {
|
|
57
|
+
return t > e ? t : n < e ? n : e;
|
|
58
|
+
}
|
|
59
|
+
var g = { wordml: "http://schemas.openxmlformats.org/wordprocessingml/2006/main" }, _ = {
|
|
60
|
+
Dxa: {
|
|
61
|
+
mul: .05,
|
|
62
|
+
unit: "pt"
|
|
63
|
+
},
|
|
64
|
+
Emu: {
|
|
65
|
+
mul: 1 / 12700,
|
|
66
|
+
unit: "pt"
|
|
67
|
+
},
|
|
68
|
+
FontSize: {
|
|
69
|
+
mul: .5,
|
|
70
|
+
unit: "pt"
|
|
71
|
+
},
|
|
72
|
+
Border: {
|
|
73
|
+
mul: .125,
|
|
74
|
+
unit: "pt",
|
|
75
|
+
min: .25,
|
|
76
|
+
max: 12
|
|
77
|
+
},
|
|
78
|
+
Point: {
|
|
79
|
+
mul: 1,
|
|
80
|
+
unit: "pt"
|
|
81
|
+
},
|
|
82
|
+
Percent: {
|
|
83
|
+
mul: .02,
|
|
84
|
+
unit: "%"
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
function v(e, t = _.Dxa) {
|
|
88
|
+
if (e == null || /.+(p[xt]|[%])$/.test(e)) return e;
|
|
89
|
+
var n = parseInt(e) * t.mul;
|
|
90
|
+
return t.min && t.max && (n = h(n, t.min, t.max)), `${n.toFixed(2)}${t.unit}`;
|
|
91
|
+
}
|
|
92
|
+
function ee(e, t = !1) {
|
|
93
|
+
switch (e) {
|
|
94
|
+
case "1": return !0;
|
|
95
|
+
case "0": return !1;
|
|
96
|
+
case "on": return !0;
|
|
97
|
+
case "off": return !1;
|
|
98
|
+
case "true": return !0;
|
|
99
|
+
case "false": return !1;
|
|
100
|
+
default: return t;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function y(e, t, n) {
|
|
104
|
+
if (e.namespaceURI != g.wordml) return !1;
|
|
105
|
+
switch (e.localName) {
|
|
106
|
+
case "color":
|
|
107
|
+
t.color = n.attr(e, "val");
|
|
108
|
+
break;
|
|
109
|
+
case "sz":
|
|
110
|
+
t.fontSize = n.lengthAttr(e, "val", _.FontSize);
|
|
111
|
+
break;
|
|
112
|
+
default: return !1;
|
|
113
|
+
}
|
|
114
|
+
return !0;
|
|
115
|
+
}
|
|
116
|
+
function te(e, t = !1) {
|
|
117
|
+
t && (e = e.replace(/<[?].*[?]>/, "")), e = re(e);
|
|
118
|
+
let n = new DOMParser().parseFromString(e, "application/xml"), r = ne(n);
|
|
119
|
+
if (r) throw Error(r);
|
|
120
|
+
return n;
|
|
121
|
+
}
|
|
122
|
+
function ne(e) {
|
|
123
|
+
return e.getElementsByTagName("parsererror")[0]?.textContent;
|
|
124
|
+
}
|
|
125
|
+
function re(e) {
|
|
126
|
+
return e.charCodeAt(0) === 65279 ? e.substring(1) : e;
|
|
127
|
+
}
|
|
128
|
+
function ie(e) {
|
|
129
|
+
return new XMLSerializer().serializeToString(e);
|
|
130
|
+
}
|
|
131
|
+
var b = class {
|
|
132
|
+
elements(e, t = null) {
|
|
133
|
+
let n = [];
|
|
134
|
+
for (let r = 0, i = e.childNodes.length; r < i; r++) {
|
|
135
|
+
let i = e.childNodes.item(r);
|
|
136
|
+
i.nodeType == Node.ELEMENT_NODE && (t == null || i.localName == t) && n.push(i);
|
|
137
|
+
}
|
|
138
|
+
return n;
|
|
139
|
+
}
|
|
140
|
+
element(e, t) {
|
|
141
|
+
for (let n = 0, r = e.childNodes.length; n < r; n++) {
|
|
142
|
+
let r = e.childNodes.item(n);
|
|
143
|
+
if (r.nodeType == 1 && r.localName == t) return r;
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
elementAttr(e, t, n) {
|
|
148
|
+
var r = this.element(e, t);
|
|
149
|
+
return r ? this.attr(r, n) : void 0;
|
|
150
|
+
}
|
|
151
|
+
attrs(e) {
|
|
152
|
+
return Array.from(e.attributes);
|
|
153
|
+
}
|
|
154
|
+
attr(e, t) {
|
|
155
|
+
for (let n = 0, r = e.attributes.length; n < r; n++) {
|
|
156
|
+
let r = e.attributes.item(n);
|
|
157
|
+
if (r.localName == t) return r.value;
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
intAttr(e, t, n = null) {
|
|
162
|
+
var r = this.attr(e, t);
|
|
163
|
+
return r ? parseInt(r) : n;
|
|
164
|
+
}
|
|
165
|
+
hexAttr(e, t, n = null) {
|
|
166
|
+
var r = this.attr(e, t);
|
|
167
|
+
return r ? parseInt(r, 16) : n;
|
|
168
|
+
}
|
|
169
|
+
floatAttr(e, t, n = null) {
|
|
170
|
+
var r = this.attr(e, t);
|
|
171
|
+
return r ? parseFloat(r) : n;
|
|
172
|
+
}
|
|
173
|
+
boolAttr(e, t, n = null) {
|
|
174
|
+
return ee(this.attr(e, t), n);
|
|
175
|
+
}
|
|
176
|
+
lengthAttr(e, t, n = _.Dxa) {
|
|
177
|
+
return v(this.attr(e, t), n);
|
|
178
|
+
}
|
|
179
|
+
}, x = new b(), S = class {
|
|
180
|
+
constructor(e, t) {
|
|
181
|
+
this._package = e, this.path = t;
|
|
182
|
+
}
|
|
183
|
+
async load() {
|
|
184
|
+
this.rels = await this._package.loadRelationships(this.path);
|
|
185
|
+
let e = await this._package.load(this.path), t = this._package.parseXmlDocument(e);
|
|
186
|
+
this._package.options.keepOrigin && (this._xmlDocument = t), this.parseXml(t.firstElementChild);
|
|
187
|
+
}
|
|
188
|
+
save() {
|
|
189
|
+
this._package.update(this.path, ie(this._xmlDocument));
|
|
190
|
+
}
|
|
191
|
+
parseXml(e) {}
|
|
192
|
+
}, ae = {
|
|
193
|
+
embedRegular: "regular",
|
|
194
|
+
embedBold: "bold",
|
|
195
|
+
embedItalic: "italic",
|
|
196
|
+
embedBoldItalic: "boldItalic"
|
|
197
|
+
};
|
|
198
|
+
function oe(e, t) {
|
|
199
|
+
return t.elements(e).map((e) => se(e, t));
|
|
200
|
+
}
|
|
201
|
+
function se(e, t) {
|
|
202
|
+
let n = {
|
|
203
|
+
name: t.attr(e, "name"),
|
|
204
|
+
embedFontRefs: []
|
|
205
|
+
};
|
|
206
|
+
for (let r of t.elements(e)) switch (r.localName) {
|
|
207
|
+
case "family":
|
|
208
|
+
n.family = t.attr(r, "val");
|
|
209
|
+
break;
|
|
210
|
+
case "altName":
|
|
211
|
+
n.altName = t.attr(r, "val");
|
|
212
|
+
break;
|
|
213
|
+
case "embedRegular":
|
|
214
|
+
case "embedBold":
|
|
215
|
+
case "embedItalic":
|
|
216
|
+
case "embedBoldItalic": n.embedFontRefs.push(ce(r, t));
|
|
217
|
+
}
|
|
218
|
+
return n;
|
|
219
|
+
}
|
|
220
|
+
function ce(e, t) {
|
|
221
|
+
return {
|
|
222
|
+
id: t.attr(e, "id"),
|
|
223
|
+
key: t.attr(e, "fontKey"),
|
|
224
|
+
type: ae[e.localName]
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
var le = class extends S {
|
|
228
|
+
parseXml(e) {
|
|
229
|
+
this.fonts = oe(e, this._package.xmlParser);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
function ue(e, t) {
|
|
233
|
+
return t.elements(e).map((e) => ({
|
|
234
|
+
extension: t.attr(e, "Extension"),
|
|
235
|
+
partName: t.attr(e, "PartName"),
|
|
236
|
+
contentType: t.attr(e, "ContentType")
|
|
237
|
+
}));
|
|
238
|
+
}
|
|
239
|
+
var de = class e {
|
|
240
|
+
constructor(e, t) {
|
|
241
|
+
this._zip = e, this.options = t, this.xmlParser = new b();
|
|
242
|
+
}
|
|
243
|
+
get(e) {
|
|
244
|
+
let t = C(e);
|
|
245
|
+
return this._zip.files[t] ?? this._zip.files[t.replace(/\//g, "\\")];
|
|
246
|
+
}
|
|
247
|
+
update(e, t) {
|
|
248
|
+
this._zip.file(e, t);
|
|
249
|
+
}
|
|
250
|
+
static async load(t, r) {
|
|
251
|
+
let i = await n.default.loadAsync(t);
|
|
252
|
+
return new e(i, r);
|
|
253
|
+
}
|
|
254
|
+
save(e = "blob") {
|
|
255
|
+
return this._zip.generateAsync({ type: e });
|
|
256
|
+
}
|
|
257
|
+
load(e, t = "string") {
|
|
258
|
+
return this.get(e)?.async(t) ?? Promise.resolve(null);
|
|
259
|
+
}
|
|
260
|
+
async loadRelationships(e = null) {
|
|
261
|
+
let t = "_rels/.rels";
|
|
262
|
+
if (e != null) {
|
|
263
|
+
let [n, r] = s(e);
|
|
264
|
+
t = `${n}_rels/${r}.rels`;
|
|
265
|
+
}
|
|
266
|
+
let n = await this.load(t);
|
|
267
|
+
return n ? i(this.parseXmlDocument(n).firstElementChild, this.xmlParser) : null;
|
|
268
|
+
}
|
|
269
|
+
async loadContentTypes() {
|
|
270
|
+
let e = await this.load("[Content_Types].xml");
|
|
271
|
+
return e ? ue(this.parseXmlDocument(e).firstElementChild, this.xmlParser) : [];
|
|
272
|
+
}
|
|
273
|
+
parseXmlDocument(e) {
|
|
274
|
+
return te(e, this.options.trimXmlDeclaration);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
function C(e) {
|
|
278
|
+
return e.startsWith("/") ? e.substr(1) : e;
|
|
279
|
+
}
|
|
280
|
+
var fe = class extends S {
|
|
281
|
+
constructor(e, t, n) {
|
|
282
|
+
super(e, t), this._documentParser = n;
|
|
283
|
+
}
|
|
284
|
+
parseXml(e) {
|
|
285
|
+
this.body = this._documentParser.parseDocumentFile(e);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
function w(e, t) {
|
|
289
|
+
return {
|
|
290
|
+
type: t.attr(e, "val"),
|
|
291
|
+
color: t.attr(e, "color"),
|
|
292
|
+
size: t.lengthAttr(e, "sz", _.Border),
|
|
293
|
+
offset: t.lengthAttr(e, "space", _.Point),
|
|
294
|
+
frame: t.boolAttr(e, "frame"),
|
|
295
|
+
shadow: t.boolAttr(e, "shadow")
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function pe(e, t) {
|
|
299
|
+
var n = {};
|
|
300
|
+
for (let r of t.elements(e)) switch (r.localName) {
|
|
301
|
+
case "left":
|
|
302
|
+
n.left = w(r, t);
|
|
303
|
+
break;
|
|
304
|
+
case "top":
|
|
305
|
+
n.top = w(r, t);
|
|
306
|
+
break;
|
|
307
|
+
case "right":
|
|
308
|
+
n.right = w(r, t);
|
|
309
|
+
break;
|
|
310
|
+
case "bottom": n.bottom = w(r, t);
|
|
311
|
+
}
|
|
312
|
+
return n;
|
|
313
|
+
}
|
|
314
|
+
var T;
|
|
315
|
+
(function(e) {
|
|
316
|
+
e.Continuous = "continuous", e.NextPage = "nextPage", e.NextColumn = "nextColumn", e.EvenPage = "evenPage", e.OddPage = "oddPage";
|
|
317
|
+
})(T || (T = {}));
|
|
318
|
+
function E(e, t = x) {
|
|
319
|
+
var n = {};
|
|
320
|
+
for (let r of t.elements(e)) switch (r.localName) {
|
|
321
|
+
case "pgSz":
|
|
322
|
+
n.pageSize = {
|
|
323
|
+
width: t.lengthAttr(r, "w"),
|
|
324
|
+
height: t.lengthAttr(r, "h"),
|
|
325
|
+
orientation: t.attr(r, "orient")
|
|
326
|
+
};
|
|
327
|
+
break;
|
|
328
|
+
case "type":
|
|
329
|
+
n.type = t.attr(r, "val");
|
|
330
|
+
break;
|
|
331
|
+
case "pgMar":
|
|
332
|
+
n.pageMargins = {
|
|
333
|
+
left: t.lengthAttr(r, "left"),
|
|
334
|
+
right: t.lengthAttr(r, "right"),
|
|
335
|
+
top: t.lengthAttr(r, "top"),
|
|
336
|
+
bottom: t.lengthAttr(r, "bottom"),
|
|
337
|
+
header: t.lengthAttr(r, "header"),
|
|
338
|
+
footer: t.lengthAttr(r, "footer"),
|
|
339
|
+
gutter: t.lengthAttr(r, "gutter")
|
|
340
|
+
};
|
|
341
|
+
break;
|
|
342
|
+
case "cols":
|
|
343
|
+
n.columns = me(r, t);
|
|
344
|
+
break;
|
|
345
|
+
case "headerReference":
|
|
346
|
+
(n.headerRefs ?? (n.headerRefs = [])).push(D(r, t));
|
|
347
|
+
break;
|
|
348
|
+
case "footerReference":
|
|
349
|
+
(n.footerRefs ?? (n.footerRefs = [])).push(D(r, t));
|
|
350
|
+
break;
|
|
351
|
+
case "titlePg":
|
|
352
|
+
n.titlePage = t.boolAttr(r, "val", !0);
|
|
353
|
+
break;
|
|
354
|
+
case "pgBorders":
|
|
355
|
+
n.pageBorders = pe(r, t);
|
|
356
|
+
break;
|
|
357
|
+
case "pgNumType": n.pageNumber = he(r, t);
|
|
358
|
+
}
|
|
359
|
+
return n;
|
|
360
|
+
}
|
|
361
|
+
function me(e, t) {
|
|
362
|
+
return {
|
|
363
|
+
numberOfColumns: t.intAttr(e, "num"),
|
|
364
|
+
space: t.lengthAttr(e, "space"),
|
|
365
|
+
separator: t.boolAttr(e, "sep"),
|
|
366
|
+
equalWidth: t.boolAttr(e, "equalWidth", !0),
|
|
367
|
+
columns: t.elements(e, "col").map((e) => ({
|
|
368
|
+
width: t.lengthAttr(e, "w"),
|
|
369
|
+
space: t.lengthAttr(e, "space")
|
|
370
|
+
}))
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
function he(e, t) {
|
|
374
|
+
return {
|
|
375
|
+
chapSep: t.attr(e, "chapSep"),
|
|
376
|
+
chapStyle: t.attr(e, "chapStyle"),
|
|
377
|
+
format: t.attr(e, "fmt"),
|
|
378
|
+
start: t.intAttr(e, "start")
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
function D(e, t) {
|
|
382
|
+
return {
|
|
383
|
+
id: t.attr(e, "id"),
|
|
384
|
+
type: t.attr(e, "type")
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
function ge(e, t) {
|
|
388
|
+
return {
|
|
389
|
+
before: t.lengthAttr(e, "before"),
|
|
390
|
+
after: t.lengthAttr(e, "after"),
|
|
391
|
+
line: t.intAttr(e, "line"),
|
|
392
|
+
lineRule: t.attr(e, "lineRule")
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
function O(e, t) {
|
|
396
|
+
let n = {};
|
|
397
|
+
for (let r of t.elements(e)) _e(r, n, t);
|
|
398
|
+
return n;
|
|
399
|
+
}
|
|
400
|
+
function _e(e, t, n) {
|
|
401
|
+
return !!y(e, t, n);
|
|
402
|
+
}
|
|
403
|
+
function k(e, t) {
|
|
404
|
+
let n = {};
|
|
405
|
+
for (let r of t.elements(e)) A(r, n, t);
|
|
406
|
+
return n;
|
|
407
|
+
}
|
|
408
|
+
function A(e, t, n) {
|
|
409
|
+
if (e.namespaceURI != g.wordml) return !1;
|
|
410
|
+
if (y(e, t, n)) return !0;
|
|
411
|
+
switch (e.localName) {
|
|
412
|
+
case "tabs":
|
|
413
|
+
t.tabs = ve(e, n);
|
|
414
|
+
break;
|
|
415
|
+
case "sectPr":
|
|
416
|
+
t.sectionProps = E(e, n);
|
|
417
|
+
break;
|
|
418
|
+
case "numPr":
|
|
419
|
+
t.numbering = ye(e, n);
|
|
420
|
+
break;
|
|
421
|
+
case "spacing": return t.lineSpacing = ge(e, n), !1;
|
|
422
|
+
case "textAlignment": return t.textAlignment = n.attr(e, "val"), !1;
|
|
423
|
+
case "keepLines":
|
|
424
|
+
t.keepLines = n.boolAttr(e, "val", !0);
|
|
425
|
+
break;
|
|
426
|
+
case "keepNext":
|
|
427
|
+
t.keepNext = n.boolAttr(e, "val", !0);
|
|
428
|
+
break;
|
|
429
|
+
case "pageBreakBefore":
|
|
430
|
+
t.pageBreakBefore = n.boolAttr(e, "val", !0);
|
|
431
|
+
break;
|
|
432
|
+
case "outlineLvl":
|
|
433
|
+
t.outlineLevel = n.intAttr(e, "val");
|
|
434
|
+
break;
|
|
435
|
+
case "pStyle":
|
|
436
|
+
t.styleName = n.attr(e, "val");
|
|
437
|
+
break;
|
|
438
|
+
case "rPr":
|
|
439
|
+
t.runProps = O(e, n);
|
|
440
|
+
break;
|
|
441
|
+
default: return !1;
|
|
442
|
+
}
|
|
443
|
+
return !0;
|
|
444
|
+
}
|
|
445
|
+
function ve(e, t) {
|
|
446
|
+
return t.elements(e, "tab").map((e) => ({
|
|
447
|
+
position: t.lengthAttr(e, "pos"),
|
|
448
|
+
leader: t.attr(e, "leader"),
|
|
449
|
+
style: t.attr(e, "val")
|
|
450
|
+
}));
|
|
451
|
+
}
|
|
452
|
+
function ye(e, t) {
|
|
453
|
+
var n = {};
|
|
454
|
+
for (let r of t.elements(e)) switch (r.localName) {
|
|
455
|
+
case "numId":
|
|
456
|
+
n.id = t.attr(r, "val");
|
|
457
|
+
break;
|
|
458
|
+
case "ilvl": n.level = t.intAttr(r, "val");
|
|
459
|
+
}
|
|
460
|
+
return n;
|
|
461
|
+
}
|
|
462
|
+
function be(e, t) {
|
|
463
|
+
let n = {
|
|
464
|
+
numberings: [],
|
|
465
|
+
abstractNumberings: [],
|
|
466
|
+
bulletPictures: []
|
|
467
|
+
};
|
|
468
|
+
for (let r of t.elements(e)) switch (r.localName) {
|
|
469
|
+
case "num":
|
|
470
|
+
n.numberings.push(j(r, t));
|
|
471
|
+
break;
|
|
472
|
+
case "abstractNum":
|
|
473
|
+
n.abstractNumberings.push(M(r, t));
|
|
474
|
+
break;
|
|
475
|
+
case "numPicBullet": n.bulletPictures.push(Se(r, t));
|
|
476
|
+
}
|
|
477
|
+
return n;
|
|
478
|
+
}
|
|
479
|
+
function j(e, t) {
|
|
480
|
+
let n = {
|
|
481
|
+
id: t.attr(e, "numId"),
|
|
482
|
+
overrides: []
|
|
483
|
+
};
|
|
484
|
+
for (let r of t.elements(e)) switch (r.localName) {
|
|
485
|
+
case "abstractNumId":
|
|
486
|
+
n.abstractId = t.attr(r, "val");
|
|
487
|
+
break;
|
|
488
|
+
case "lvlOverride": n.overrides.push(xe(r, t));
|
|
489
|
+
}
|
|
490
|
+
return n;
|
|
491
|
+
}
|
|
492
|
+
function M(e, t) {
|
|
493
|
+
let n = {
|
|
494
|
+
id: t.attr(e, "abstractNumId"),
|
|
495
|
+
levels: []
|
|
496
|
+
};
|
|
497
|
+
for (let r of t.elements(e)) switch (r.localName) {
|
|
498
|
+
case "name":
|
|
499
|
+
n.name = t.attr(r, "val");
|
|
500
|
+
break;
|
|
501
|
+
case "multiLevelType":
|
|
502
|
+
n.multiLevelType = t.attr(r, "val");
|
|
503
|
+
break;
|
|
504
|
+
case "numStyleLink":
|
|
505
|
+
n.numberingStyleLink = t.attr(r, "val");
|
|
506
|
+
break;
|
|
507
|
+
case "styleLink":
|
|
508
|
+
n.styleLink = t.attr(r, "val");
|
|
509
|
+
break;
|
|
510
|
+
case "lvl": n.levels.push(N(r, t));
|
|
511
|
+
}
|
|
512
|
+
return n;
|
|
513
|
+
}
|
|
514
|
+
function N(e, t) {
|
|
515
|
+
let n = { level: t.intAttr(e, "ilvl") };
|
|
516
|
+
for (let r of t.elements(e)) switch (r.localName) {
|
|
517
|
+
case "start":
|
|
518
|
+
n.start = t.attr(r, "val");
|
|
519
|
+
break;
|
|
520
|
+
case "lvlRestart":
|
|
521
|
+
n.restart = t.intAttr(r, "val");
|
|
522
|
+
break;
|
|
523
|
+
case "numFmt":
|
|
524
|
+
n.format = t.attr(r, "val");
|
|
525
|
+
break;
|
|
526
|
+
case "lvlText":
|
|
527
|
+
n.text = t.attr(r, "val");
|
|
528
|
+
break;
|
|
529
|
+
case "lvlJc":
|
|
530
|
+
n.justification = t.attr(r, "val");
|
|
531
|
+
break;
|
|
532
|
+
case "lvlPicBulletId":
|
|
533
|
+
n.bulletPictureId = t.attr(r, "val");
|
|
534
|
+
break;
|
|
535
|
+
case "pStyle":
|
|
536
|
+
n.paragraphStyle = t.attr(r, "val");
|
|
537
|
+
break;
|
|
538
|
+
case "pPr":
|
|
539
|
+
n.paragraphProps = k(r, t);
|
|
540
|
+
break;
|
|
541
|
+
case "rPr": n.runProps = O(r, t);
|
|
542
|
+
}
|
|
543
|
+
return n;
|
|
544
|
+
}
|
|
545
|
+
function xe(e, t) {
|
|
546
|
+
let n = { level: t.intAttr(e, "ilvl") };
|
|
547
|
+
for (let r of t.elements(e)) switch (r.localName) {
|
|
548
|
+
case "startOverride":
|
|
549
|
+
n.start = t.intAttr(r, "val");
|
|
550
|
+
break;
|
|
551
|
+
case "lvl": n.numberingLevel = N(r, t);
|
|
552
|
+
}
|
|
553
|
+
return n;
|
|
554
|
+
}
|
|
555
|
+
function Se(e, t) {
|
|
556
|
+
var n = t.element(e, "pict"), r = n && t.element(n, "shape"), i = r && t.element(r, "imagedata");
|
|
557
|
+
return i ? {
|
|
558
|
+
id: t.attr(e, "numPicBulletId"),
|
|
559
|
+
referenceId: t.attr(i, "id"),
|
|
560
|
+
style: t.attr(r, "style")
|
|
561
|
+
} : null;
|
|
562
|
+
}
|
|
563
|
+
var Ce = class extends S {
|
|
564
|
+
constructor(e, t, n) {
|
|
565
|
+
super(e, t), this._documentParser = n;
|
|
566
|
+
}
|
|
567
|
+
parseXml(e) {
|
|
568
|
+
Object.assign(this, be(e, this._package.xmlParser)), this.domNumberings = this._documentParser.parseNumberingFile(e);
|
|
569
|
+
}
|
|
570
|
+
}, we = class extends S {
|
|
571
|
+
constructor(e, t, n) {
|
|
572
|
+
super(e, t), this._documentParser = n;
|
|
573
|
+
}
|
|
574
|
+
parseXml(e) {
|
|
575
|
+
this.styles = this._documentParser.parseStylesFile(e);
|
|
576
|
+
}
|
|
577
|
+
}, P;
|
|
578
|
+
(function(e) {
|
|
579
|
+
e.Document = "document", e.Paragraph = "paragraph", e.Run = "run", e.Break = "break", e.NoBreakHyphen = "noBreakHyphen", e.Table = "table", e.Row = "row", e.Cell = "cell", e.Hyperlink = "hyperlink", e.SmartTag = "smartTag", e.Drawing = "drawing", e.Image = "image", e.Text = "text", e.Tab = "tab", e.Symbol = "symbol", e.BookmarkStart = "bookmarkStart", e.BookmarkEnd = "bookmarkEnd", e.Footer = "footer", e.Header = "header", e.FootnoteReference = "footnoteReference", e.EndnoteReference = "endnoteReference", e.Footnote = "footnote", e.Endnote = "endnote", e.SimpleField = "simpleField", e.ComplexField = "complexField", e.Instruction = "instruction", e.VmlPicture = "vmlPicture", e.MmlMath = "mmlMath", e.MmlMathParagraph = "mmlMathParagraph", e.MmlFraction = "mmlFraction", e.MmlFunction = "mmlFunction", e.MmlFunctionName = "mmlFunctionName", e.MmlNumerator = "mmlNumerator", e.MmlDenominator = "mmlDenominator", e.MmlRadical = "mmlRadical", e.MmlBase = "mmlBase", e.MmlDegree = "mmlDegree", e.MmlSuperscript = "mmlSuperscript", e.MmlSubscript = "mmlSubscript", e.MmlPreSubSuper = "mmlPreSubSuper", e.MmlSubArgument = "mmlSubArgument", e.MmlSuperArgument = "mmlSuperArgument", e.MmlNary = "mmlNary", e.MmlDelimiter = "mmlDelimiter", e.MmlRun = "mmlRun", e.MmlEquationArray = "mmlEquationArray", e.MmlLimit = "mmlLimit", e.MmlLimitLower = "mmlLimitLower", e.MmlMatrix = "mmlMatrix", e.MmlMatrixRow = "mmlMatrixRow", e.MmlBox = "mmlBox", e.MmlBar = "mmlBar", e.MmlGroupChar = "mmlGroupChar", e.VmlElement = "vmlElement", e.Inserted = "inserted", e.Deleted = "deleted", e.DeletedText = "deletedText", e.Comment = "comment", e.CommentReference = "commentReference", e.CommentRangeStart = "commentRangeStart", e.CommentRangeEnd = "commentRangeEnd", e.AltChunk = "altChunk";
|
|
580
|
+
})(P || (P = {}));
|
|
581
|
+
var F = class {
|
|
582
|
+
constructor() {
|
|
583
|
+
this.children = [], this.cssStyle = {};
|
|
584
|
+
}
|
|
585
|
+
}, Te = class extends F {
|
|
586
|
+
constructor() {
|
|
587
|
+
super(...arguments), this.type = P.Header;
|
|
588
|
+
}
|
|
589
|
+
}, Ee = class extends F {
|
|
590
|
+
constructor() {
|
|
591
|
+
super(...arguments), this.type = P.Footer;
|
|
592
|
+
}
|
|
593
|
+
}, I = class extends S {
|
|
594
|
+
constructor(e, t, n) {
|
|
595
|
+
super(e, t), this._documentParser = n;
|
|
596
|
+
}
|
|
597
|
+
parseXml(e) {
|
|
598
|
+
this.rootElement = this.createRootElement(), this.rootElement.children = this._documentParser.parseBodyElements(e);
|
|
599
|
+
}
|
|
600
|
+
}, De = class extends I {
|
|
601
|
+
createRootElement() {
|
|
602
|
+
return new Te();
|
|
603
|
+
}
|
|
604
|
+
}, Oe = class extends I {
|
|
605
|
+
createRootElement() {
|
|
606
|
+
return new Ee();
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
function ke(e, t) {
|
|
610
|
+
let n = {};
|
|
611
|
+
for (let r of t.elements(e)) switch (r.localName) {
|
|
612
|
+
case "Template":
|
|
613
|
+
n.template = r.textContent;
|
|
614
|
+
break;
|
|
615
|
+
case "Pages":
|
|
616
|
+
n.pages = L(r.textContent);
|
|
617
|
+
break;
|
|
618
|
+
case "Words":
|
|
619
|
+
n.words = L(r.textContent);
|
|
620
|
+
break;
|
|
621
|
+
case "Characters":
|
|
622
|
+
n.characters = L(r.textContent);
|
|
623
|
+
break;
|
|
624
|
+
case "Application":
|
|
625
|
+
n.application = r.textContent;
|
|
626
|
+
break;
|
|
627
|
+
case "Lines":
|
|
628
|
+
n.lines = L(r.textContent);
|
|
629
|
+
break;
|
|
630
|
+
case "Paragraphs":
|
|
631
|
+
n.paragraphs = L(r.textContent);
|
|
632
|
+
break;
|
|
633
|
+
case "Company":
|
|
634
|
+
n.company = r.textContent;
|
|
635
|
+
break;
|
|
636
|
+
case "AppVersion": n.appVersion = r.textContent;
|
|
637
|
+
}
|
|
638
|
+
return n;
|
|
639
|
+
}
|
|
640
|
+
function L(e) {
|
|
641
|
+
if (e !== void 0) return parseInt(e);
|
|
642
|
+
}
|
|
643
|
+
var Ae = class extends S {
|
|
644
|
+
parseXml(e) {
|
|
645
|
+
this.props = ke(e, this._package.xmlParser);
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
function je(e, t) {
|
|
649
|
+
let n = {};
|
|
650
|
+
for (let r of t.elements(e)) switch (r.localName) {
|
|
651
|
+
case "title":
|
|
652
|
+
n.title = r.textContent;
|
|
653
|
+
break;
|
|
654
|
+
case "description":
|
|
655
|
+
n.description = r.textContent;
|
|
656
|
+
break;
|
|
657
|
+
case "subject":
|
|
658
|
+
n.subject = r.textContent;
|
|
659
|
+
break;
|
|
660
|
+
case "creator":
|
|
661
|
+
n.creator = r.textContent;
|
|
662
|
+
break;
|
|
663
|
+
case "keywords":
|
|
664
|
+
n.keywords = r.textContent;
|
|
665
|
+
break;
|
|
666
|
+
case "language":
|
|
667
|
+
n.language = r.textContent;
|
|
668
|
+
break;
|
|
669
|
+
case "lastModifiedBy":
|
|
670
|
+
n.lastModifiedBy = r.textContent;
|
|
671
|
+
break;
|
|
672
|
+
case "revision": r.textContent && (n.revision = parseInt(r.textContent));
|
|
673
|
+
}
|
|
674
|
+
return n;
|
|
675
|
+
}
|
|
676
|
+
var Me = class extends S {
|
|
677
|
+
parseXml(e) {
|
|
678
|
+
this.props = je(e, this._package.xmlParser);
|
|
679
|
+
}
|
|
680
|
+
}, Ne = class {};
|
|
681
|
+
function Pe(e, t) {
|
|
682
|
+
var n = new Ne(), r = t.element(e, "themeElements");
|
|
683
|
+
for (let e of t.elements(r)) switch (e.localName) {
|
|
684
|
+
case "clrScheme":
|
|
685
|
+
n.colorScheme = Fe(e, t);
|
|
686
|
+
break;
|
|
687
|
+
case "fontScheme": n.fontScheme = Ie(e, t);
|
|
688
|
+
}
|
|
689
|
+
return n;
|
|
690
|
+
}
|
|
691
|
+
function Fe(e, t) {
|
|
692
|
+
var n = {
|
|
693
|
+
name: t.attr(e, "name"),
|
|
694
|
+
colors: {}
|
|
695
|
+
};
|
|
696
|
+
for (let a of t.elements(e)) {
|
|
697
|
+
var r = t.element(a, "srgbClr"), i = t.element(a, "sysClr");
|
|
698
|
+
r ? n.colors[a.localName] = t.attr(r, "val") : i && (n.colors[a.localName] = t.attr(i, "lastClr"));
|
|
699
|
+
}
|
|
700
|
+
return n;
|
|
701
|
+
}
|
|
702
|
+
function Ie(e, t) {
|
|
703
|
+
var n = { name: t.attr(e, "name") };
|
|
704
|
+
for (let r of t.elements(e)) switch (r.localName) {
|
|
705
|
+
case "majorFont":
|
|
706
|
+
n.majorFont = R(r, t);
|
|
707
|
+
break;
|
|
708
|
+
case "minorFont": n.minorFont = R(r, t);
|
|
709
|
+
}
|
|
710
|
+
return n;
|
|
711
|
+
}
|
|
712
|
+
function R(e, t) {
|
|
713
|
+
return {
|
|
714
|
+
latinTypeface: t.elementAttr(e, "latin", "typeface"),
|
|
715
|
+
eaTypeface: t.elementAttr(e, "ea", "typeface"),
|
|
716
|
+
csTypeface: t.elementAttr(e, "cs", "typeface")
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
var Le = class extends S {
|
|
720
|
+
constructor(e, t) {
|
|
721
|
+
super(e, t);
|
|
722
|
+
}
|
|
723
|
+
parseXml(e) {
|
|
724
|
+
this.theme = Pe(e, this._package.xmlParser);
|
|
725
|
+
}
|
|
726
|
+
}, z = class {}, Re = class extends z {
|
|
727
|
+
constructor() {
|
|
728
|
+
super(...arguments), this.type = P.Footnote;
|
|
729
|
+
}
|
|
730
|
+
}, ze = class extends z {
|
|
731
|
+
constructor() {
|
|
732
|
+
super(...arguments), this.type = P.Endnote;
|
|
733
|
+
}
|
|
734
|
+
}, B = class extends S {
|
|
735
|
+
constructor(e, t, n) {
|
|
736
|
+
super(e, t), this._documentParser = n;
|
|
737
|
+
}
|
|
738
|
+
}, Be = class extends B {
|
|
739
|
+
constructor(e, t, n) {
|
|
740
|
+
super(e, t, n);
|
|
741
|
+
}
|
|
742
|
+
parseXml(e) {
|
|
743
|
+
this.notes = this._documentParser.parseNotes(e, "footnote", Re);
|
|
744
|
+
}
|
|
745
|
+
}, V = class extends B {
|
|
746
|
+
constructor(e, t, n) {
|
|
747
|
+
super(e, t, n);
|
|
748
|
+
}
|
|
749
|
+
parseXml(e) {
|
|
750
|
+
this.notes = this._documentParser.parseNotes(e, "endnote", ze);
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
function Ve(e, t) {
|
|
754
|
+
var n = {};
|
|
755
|
+
for (let r of t.elements(e)) switch (r.localName) {
|
|
756
|
+
case "defaultTabStop":
|
|
757
|
+
n.defaultTabStop = t.lengthAttr(r, "val");
|
|
758
|
+
break;
|
|
759
|
+
case "footnotePr":
|
|
760
|
+
n.footnoteProps = H(r, t);
|
|
761
|
+
break;
|
|
762
|
+
case "endnotePr":
|
|
763
|
+
n.endnoteProps = H(r, t);
|
|
764
|
+
break;
|
|
765
|
+
case "autoHyphenation":
|
|
766
|
+
n.autoHyphenation = t.boolAttr(r, "val");
|
|
767
|
+
break;
|
|
768
|
+
case "evenAndOddHeaders": n.evenAndOddHeaders = t.boolAttr(r, "val", !0);
|
|
769
|
+
}
|
|
770
|
+
return n;
|
|
771
|
+
}
|
|
772
|
+
function H(e, t) {
|
|
773
|
+
var n = { defaultNoteIds: [] };
|
|
774
|
+
for (let r of t.elements(e)) switch (r.localName) {
|
|
775
|
+
case "numFmt":
|
|
776
|
+
n.nummeringFormat = t.attr(r, "val");
|
|
777
|
+
break;
|
|
778
|
+
case "footnote":
|
|
779
|
+
case "endnote": n.defaultNoteIds.push(t.attr(r, "id"));
|
|
780
|
+
}
|
|
781
|
+
return n;
|
|
782
|
+
}
|
|
783
|
+
var He = class extends S {
|
|
784
|
+
constructor(e, t) {
|
|
785
|
+
super(e, t);
|
|
786
|
+
}
|
|
787
|
+
parseXml(e) {
|
|
788
|
+
this.settings = Ve(e, this._package.xmlParser);
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
function Ue(e, t) {
|
|
792
|
+
return t.elements(e, "property").map((e) => {
|
|
793
|
+
let n = e.firstChild;
|
|
794
|
+
return {
|
|
795
|
+
formatId: t.attr(e, "fmtid"),
|
|
796
|
+
name: t.attr(e, "name"),
|
|
797
|
+
type: n.nodeName,
|
|
798
|
+
value: n.textContent
|
|
799
|
+
};
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
var We = class extends S {
|
|
803
|
+
parseXml(e) {
|
|
804
|
+
this.props = Ue(e, this._package.xmlParser);
|
|
805
|
+
}
|
|
806
|
+
}, Ge = class extends S {
|
|
807
|
+
constructor(e, t, n) {
|
|
808
|
+
super(e, t), this._documentParser = n;
|
|
809
|
+
}
|
|
810
|
+
parseXml(e) {
|
|
811
|
+
this.comments = this._documentParser.parseComments(e), this.commentMap = l(this.comments, (e) => e.id);
|
|
812
|
+
}
|
|
813
|
+
}, Ke = class extends S {
|
|
814
|
+
constructor(e, t) {
|
|
815
|
+
super(e, t), this.comments = [];
|
|
816
|
+
}
|
|
817
|
+
parseXml(e) {
|
|
818
|
+
let t = this._package.xmlParser;
|
|
819
|
+
for (let n of t.elements(e, "commentEx")) this.comments.push({
|
|
820
|
+
paraId: t.attr(n, "paraId"),
|
|
821
|
+
paraIdParent: t.attr(n, "paraIdParent"),
|
|
822
|
+
done: t.boolAttr(n, "done")
|
|
823
|
+
});
|
|
824
|
+
this.commentMap = l(this.comments, (e) => e.paraId);
|
|
825
|
+
}
|
|
826
|
+
}, qe = [
|
|
827
|
+
{
|
|
828
|
+
type: r.OfficeDocument,
|
|
829
|
+
target: "word/document.xml"
|
|
830
|
+
},
|
|
831
|
+
{
|
|
832
|
+
type: r.ExtendedProperties,
|
|
833
|
+
target: "docProps/app.xml"
|
|
834
|
+
},
|
|
835
|
+
{
|
|
836
|
+
type: r.CoreProperties,
|
|
837
|
+
target: "docProps/core.xml"
|
|
838
|
+
},
|
|
839
|
+
{
|
|
840
|
+
type: r.CustomProperties,
|
|
841
|
+
target: "docProps/custom.xml"
|
|
842
|
+
}
|
|
843
|
+
], Je = class e {
|
|
844
|
+
constructor() {
|
|
845
|
+
this.parts = [], this.partsMap = {}, this.contentTypes = [];
|
|
846
|
+
}
|
|
847
|
+
static async load(t, n, r) {
|
|
848
|
+
var i = new e();
|
|
849
|
+
return i._options = r, i._parser = n, i._package = await de.load(t, r), i.rels = await i._package.loadRelationships(), i.contentTypes = await i._package.loadContentTypes(), await Promise.all(qe.map((e) => {
|
|
850
|
+
let t = i.rels.find((t) => t.type === e.type) ?? e;
|
|
851
|
+
return i.loadRelationshipPart(t.target, t.type);
|
|
852
|
+
})), i;
|
|
853
|
+
}
|
|
854
|
+
save(e = "blob") {
|
|
855
|
+
return this._package.save(e);
|
|
856
|
+
}
|
|
857
|
+
async loadRelationshipPart(e, t) {
|
|
858
|
+
if (this.partsMap[e]) return this.partsMap[e];
|
|
859
|
+
if (!this._package.get(e)) return null;
|
|
860
|
+
let n = null;
|
|
861
|
+
switch (t) {
|
|
862
|
+
case r.OfficeDocument:
|
|
863
|
+
this.documentPart = n = new fe(this._package, e, this._parser);
|
|
864
|
+
break;
|
|
865
|
+
case r.FontTable:
|
|
866
|
+
this.fontTablePart = n = new le(this._package, e);
|
|
867
|
+
break;
|
|
868
|
+
case r.Numbering:
|
|
869
|
+
this.numberingPart = n = new Ce(this._package, e, this._parser);
|
|
870
|
+
break;
|
|
871
|
+
case r.Styles:
|
|
872
|
+
this.stylesPart = n = new we(this._package, e, this._parser);
|
|
873
|
+
break;
|
|
874
|
+
case r.Theme:
|
|
875
|
+
this.themePart = n = new Le(this._package, e);
|
|
876
|
+
break;
|
|
877
|
+
case r.Footnotes:
|
|
878
|
+
this.footnotesPart = n = new Be(this._package, e, this._parser);
|
|
879
|
+
break;
|
|
880
|
+
case r.Endnotes:
|
|
881
|
+
this.endnotesPart = n = new V(this._package, e, this._parser);
|
|
882
|
+
break;
|
|
883
|
+
case r.Footer:
|
|
884
|
+
n = new Oe(this._package, e, this._parser);
|
|
885
|
+
break;
|
|
886
|
+
case r.Header:
|
|
887
|
+
n = new De(this._package, e, this._parser);
|
|
888
|
+
break;
|
|
889
|
+
case r.CoreProperties:
|
|
890
|
+
this.corePropsPart = n = new Me(this._package, e);
|
|
891
|
+
break;
|
|
892
|
+
case r.ExtendedProperties:
|
|
893
|
+
this.extendedPropsPart = n = new Ae(this._package, e);
|
|
894
|
+
break;
|
|
895
|
+
case r.CustomProperties:
|
|
896
|
+
n = new We(this._package, e);
|
|
897
|
+
break;
|
|
898
|
+
case r.Settings:
|
|
899
|
+
this.settingsPart = n = new He(this._package, e);
|
|
900
|
+
break;
|
|
901
|
+
case r.Comments:
|
|
902
|
+
this.commentsPart = n = new Ge(this._package, e, this._parser);
|
|
903
|
+
break;
|
|
904
|
+
case r.CommentsExtended: this.commentsExtendedPart = n = new Ke(this._package, e);
|
|
905
|
+
}
|
|
906
|
+
if (n == null) return Promise.resolve(null);
|
|
907
|
+
if (this.partsMap[e] = n, this.parts.push(n), await n.load(), n.rels?.length > 0) {
|
|
908
|
+
let [e] = s(n.path);
|
|
909
|
+
await Promise.all(n.rels.map((t) => this.loadRelationshipPart(c(t.target, e), t.type)));
|
|
910
|
+
}
|
|
911
|
+
return n;
|
|
912
|
+
}
|
|
913
|
+
async loadDocumentImage(e, t) {
|
|
914
|
+
let n = this.getPathById(t ?? this.documentPart, e);
|
|
915
|
+
return n ? this.blobToURL(await this._package.load(n, "blob"), n) : null;
|
|
916
|
+
}
|
|
917
|
+
async loadNumberingImage(e) {
|
|
918
|
+
let t = this.getPathById(this.numberingPart, e);
|
|
919
|
+
return t ? this.blobToURL(await this._package.load(t, "blob"), t) : null;
|
|
920
|
+
}
|
|
921
|
+
async loadFont(e, t) {
|
|
922
|
+
let n = this.getPathById(this.fontTablePart, e);
|
|
923
|
+
if (!n) return null;
|
|
924
|
+
let r = await this._package.load(n, "uint8array");
|
|
925
|
+
return r && this.blobToURL(new Blob([Ye(r, t)]), n);
|
|
926
|
+
}
|
|
927
|
+
async loadAltChunk(e, t) {
|
|
928
|
+
let n = this.getPathById(t ?? this.documentPart, e);
|
|
929
|
+
return n ? this._package.load(n, "string") : Promise.resolve(null);
|
|
930
|
+
}
|
|
931
|
+
blobToURL(e, t) {
|
|
932
|
+
if (!e) return null;
|
|
933
|
+
if (t) {
|
|
934
|
+
let n = this.contentTypes.find((e) => e.partName === t || e.extension && t.endsWith(`.${e.extension}`));
|
|
935
|
+
e = n ? new Blob([e], { type: n.contentType }) : e;
|
|
936
|
+
}
|
|
937
|
+
return this._options.useBase64URL ? u(e) : URL.createObjectURL(e);
|
|
938
|
+
}
|
|
939
|
+
findPartByRelId(e, t = null) {
|
|
940
|
+
var n = (t.rels ?? this.rels).find((t) => t.id == e);
|
|
941
|
+
let r = t ? s(t.path)[0] : "";
|
|
942
|
+
return n ? this.partsMap[c(n.target, r)] : null;
|
|
943
|
+
}
|
|
944
|
+
getPathById(e, t) {
|
|
945
|
+
let n = e.rels.find((e) => e.id == t), [r] = s(e.path);
|
|
946
|
+
return n ? c(n.target, r) : null;
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
function Ye(e, t) {
|
|
950
|
+
let n = t.replace(/{|}|-/g, ""), r = Array(16);
|
|
951
|
+
for (let e = 0; e < 16; e++) r[16 - e - 1] = parseInt(n.substring(e * 2, e * 2 + 2), 16);
|
|
952
|
+
for (let t = 0; t < 32; t++) e[t] = e[t] ^ r[t % 16];
|
|
953
|
+
return e;
|
|
954
|
+
}
|
|
955
|
+
function Xe(e, t) {
|
|
956
|
+
return {
|
|
957
|
+
type: P.BookmarkStart,
|
|
958
|
+
id: t.attr(e, "id"),
|
|
959
|
+
name: t.attr(e, "name"),
|
|
960
|
+
colFirst: t.intAttr(e, "colFirst"),
|
|
961
|
+
colLast: t.intAttr(e, "colLast")
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
function Ze(e, t) {
|
|
965
|
+
return {
|
|
966
|
+
type: P.BookmarkEnd,
|
|
967
|
+
id: t.attr(e, "id")
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
var Qe = class extends F {
|
|
971
|
+
constructor() {
|
|
972
|
+
super(...arguments), this.type = P.VmlElement, this.attrs = {};
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
function U(e, t) {
|
|
976
|
+
var n = new Qe();
|
|
977
|
+
switch (e.localName) {
|
|
978
|
+
case "rect":
|
|
979
|
+
n.tagName = "rect", Object.assign(n.attrs, {
|
|
980
|
+
width: "100%",
|
|
981
|
+
height: "100%"
|
|
982
|
+
});
|
|
983
|
+
break;
|
|
984
|
+
case "oval":
|
|
985
|
+
n.tagName = "ellipse", Object.assign(n.attrs, {
|
|
986
|
+
cx: "50%",
|
|
987
|
+
cy: "50%",
|
|
988
|
+
rx: "50%",
|
|
989
|
+
ry: "50%"
|
|
990
|
+
});
|
|
991
|
+
break;
|
|
992
|
+
case "line":
|
|
993
|
+
n.tagName = "line";
|
|
994
|
+
break;
|
|
995
|
+
case "shape":
|
|
996
|
+
n.tagName = "g";
|
|
997
|
+
break;
|
|
998
|
+
case "textbox":
|
|
999
|
+
n.tagName = "foreignObject", Object.assign(n.attrs, {
|
|
1000
|
+
width: "100%",
|
|
1001
|
+
height: "100%"
|
|
1002
|
+
});
|
|
1003
|
+
break;
|
|
1004
|
+
default: return null;
|
|
1005
|
+
}
|
|
1006
|
+
for (let t of x.attrs(e)) switch (t.localName) {
|
|
1007
|
+
case "style":
|
|
1008
|
+
n.cssStyleText = t.value;
|
|
1009
|
+
break;
|
|
1010
|
+
case "fillcolor":
|
|
1011
|
+
n.attrs.fill = t.value;
|
|
1012
|
+
break;
|
|
1013
|
+
case "from":
|
|
1014
|
+
let [e, r] = W(t.value);
|
|
1015
|
+
Object.assign(n.attrs, {
|
|
1016
|
+
x1: e,
|
|
1017
|
+
y1: r
|
|
1018
|
+
});
|
|
1019
|
+
break;
|
|
1020
|
+
case "to":
|
|
1021
|
+
let [i, a] = W(t.value);
|
|
1022
|
+
Object.assign(n.attrs, {
|
|
1023
|
+
x2: i,
|
|
1024
|
+
y2: a
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
for (let r of x.elements(e)) switch (r.localName) {
|
|
1028
|
+
case "stroke":
|
|
1029
|
+
Object.assign(n.attrs, $e(r));
|
|
1030
|
+
break;
|
|
1031
|
+
case "fill":
|
|
1032
|
+
Object.assign(n.attrs, et());
|
|
1033
|
+
break;
|
|
1034
|
+
case "imagedata":
|
|
1035
|
+
n.tagName = "image", Object.assign(n.attrs, {
|
|
1036
|
+
width: "100%",
|
|
1037
|
+
height: "100%"
|
|
1038
|
+
}), n.imageHref = {
|
|
1039
|
+
id: x.attr(r, "id"),
|
|
1040
|
+
title: x.attr(r, "title")
|
|
1041
|
+
};
|
|
1042
|
+
break;
|
|
1043
|
+
case "txbxContent":
|
|
1044
|
+
n.children.push(...t.parseBodyElements(r));
|
|
1045
|
+
break;
|
|
1046
|
+
default:
|
|
1047
|
+
let e = U(r, t);
|
|
1048
|
+
e && n.children.push(e);
|
|
1049
|
+
}
|
|
1050
|
+
return n;
|
|
1051
|
+
}
|
|
1052
|
+
function $e(e) {
|
|
1053
|
+
return {
|
|
1054
|
+
stroke: x.attr(e, "color"),
|
|
1055
|
+
"stroke-width": x.lengthAttr(e, "weight", _.Emu) ?? "1px"
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
function et(e) {
|
|
1059
|
+
return {};
|
|
1060
|
+
}
|
|
1061
|
+
function W(e) {
|
|
1062
|
+
return e.split(",");
|
|
1063
|
+
}
|
|
1064
|
+
var tt = class extends F {
|
|
1065
|
+
constructor() {
|
|
1066
|
+
super(...arguments), this.type = P.Comment;
|
|
1067
|
+
}
|
|
1068
|
+
}, nt = class extends F {
|
|
1069
|
+
constructor(e) {
|
|
1070
|
+
super(), this.id = e, this.type = P.CommentReference;
|
|
1071
|
+
}
|
|
1072
|
+
}, rt = class extends F {
|
|
1073
|
+
constructor(e) {
|
|
1074
|
+
super(), this.id = e, this.type = P.CommentRangeStart;
|
|
1075
|
+
}
|
|
1076
|
+
}, it = class extends F {
|
|
1077
|
+
constructor(e) {
|
|
1078
|
+
super(), this.id = e, this.type = P.CommentRangeEnd;
|
|
1079
|
+
}
|
|
1080
|
+
}, G = {
|
|
1081
|
+
shd: "inherit",
|
|
1082
|
+
color: "black",
|
|
1083
|
+
borderColor: "black",
|
|
1084
|
+
highlight: "transparent"
|
|
1085
|
+
}, at = [], K = {
|
|
1086
|
+
oMath: P.MmlMath,
|
|
1087
|
+
oMathPara: P.MmlMathParagraph,
|
|
1088
|
+
f: P.MmlFraction,
|
|
1089
|
+
func: P.MmlFunction,
|
|
1090
|
+
fName: P.MmlFunctionName,
|
|
1091
|
+
num: P.MmlNumerator,
|
|
1092
|
+
den: P.MmlDenominator,
|
|
1093
|
+
rad: P.MmlRadical,
|
|
1094
|
+
deg: P.MmlDegree,
|
|
1095
|
+
e: P.MmlBase,
|
|
1096
|
+
sSup: P.MmlSuperscript,
|
|
1097
|
+
sSub: P.MmlSubscript,
|
|
1098
|
+
sPre: P.MmlPreSubSuper,
|
|
1099
|
+
sup: P.MmlSuperArgument,
|
|
1100
|
+
sub: P.MmlSubArgument,
|
|
1101
|
+
d: P.MmlDelimiter,
|
|
1102
|
+
nary: P.MmlNary,
|
|
1103
|
+
eqArr: P.MmlEquationArray,
|
|
1104
|
+
lim: P.MmlLimit,
|
|
1105
|
+
limLow: P.MmlLimitLower,
|
|
1106
|
+
m: P.MmlMatrix,
|
|
1107
|
+
mr: P.MmlMatrixRow,
|
|
1108
|
+
box: P.MmlBox,
|
|
1109
|
+
bar: P.MmlBar,
|
|
1110
|
+
groupChr: P.MmlGroupChar
|
|
1111
|
+
}, ot = class {
|
|
1112
|
+
constructor(e) {
|
|
1113
|
+
this.options = {
|
|
1114
|
+
ignoreWidth: !1,
|
|
1115
|
+
debug: !1,
|
|
1116
|
+
...e
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
parseNotes(e, t, n) {
|
|
1120
|
+
var r = [];
|
|
1121
|
+
for (let i of x.elements(e, t)) {
|
|
1122
|
+
let e = new n();
|
|
1123
|
+
e.id = x.attr(i, "id"), e.noteType = x.attr(i, "type"), e.children = this.parseBodyElements(i), r.push(e);
|
|
1124
|
+
}
|
|
1125
|
+
return r;
|
|
1126
|
+
}
|
|
1127
|
+
parseComments(e) {
|
|
1128
|
+
var t = [];
|
|
1129
|
+
for (let n of x.elements(e, "comment")) {
|
|
1130
|
+
let e = new tt();
|
|
1131
|
+
e.id = x.attr(n, "id"), e.author = x.attr(n, "author"), e.initials = x.attr(n, "initials"), e.date = x.attr(n, "date"), e.children = this.parseBodyElements(n), t.push(e);
|
|
1132
|
+
}
|
|
1133
|
+
return t;
|
|
1134
|
+
}
|
|
1135
|
+
parseDocumentFile(e) {
|
|
1136
|
+
var t = x.element(e, "body"), n = x.element(e, "background"), r = x.element(t, "sectPr");
|
|
1137
|
+
return {
|
|
1138
|
+
type: P.Document,
|
|
1139
|
+
children: this.parseBodyElements(t),
|
|
1140
|
+
props: r ? E(r, x) : {},
|
|
1141
|
+
cssStyle: n ? this.parseBackground(n) : {}
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
parseBackground(e) {
|
|
1145
|
+
var t = {}, n = q.colorAttr(e, "color");
|
|
1146
|
+
return n && (t["background-color"] = n), t;
|
|
1147
|
+
}
|
|
1148
|
+
parseBodyElements(e) {
|
|
1149
|
+
var t = [];
|
|
1150
|
+
for (let n of x.elements(e)) switch (n.localName) {
|
|
1151
|
+
case "p":
|
|
1152
|
+
t.push(this.parseParagraph(n));
|
|
1153
|
+
break;
|
|
1154
|
+
case "altChunk":
|
|
1155
|
+
t.push(this.parseAltChunk(n));
|
|
1156
|
+
break;
|
|
1157
|
+
case "tbl":
|
|
1158
|
+
t.push(this.parseTable(n));
|
|
1159
|
+
break;
|
|
1160
|
+
case "sdt": t.push(...this.parseSdt(n, (e) => this.parseBodyElements(e)));
|
|
1161
|
+
}
|
|
1162
|
+
return t;
|
|
1163
|
+
}
|
|
1164
|
+
parseStylesFile(e) {
|
|
1165
|
+
var t = [];
|
|
1166
|
+
for (let n of x.elements(e)) switch (n.localName) {
|
|
1167
|
+
case "style":
|
|
1168
|
+
t.push(this.parseStyle(n));
|
|
1169
|
+
break;
|
|
1170
|
+
case "docDefaults": t.push(this.parseDefaultStyles(n));
|
|
1171
|
+
}
|
|
1172
|
+
return t;
|
|
1173
|
+
}
|
|
1174
|
+
parseDefaultStyles(e) {
|
|
1175
|
+
var t = {
|
|
1176
|
+
id: null,
|
|
1177
|
+
name: null,
|
|
1178
|
+
target: null,
|
|
1179
|
+
basedOn: null,
|
|
1180
|
+
styles: []
|
|
1181
|
+
};
|
|
1182
|
+
for (let i of x.elements(e)) switch (i.localName) {
|
|
1183
|
+
case "rPrDefault":
|
|
1184
|
+
var n = x.element(i, "rPr");
|
|
1185
|
+
n && t.styles.push({
|
|
1186
|
+
target: "span",
|
|
1187
|
+
values: this.parseDefaultProperties(n, {})
|
|
1188
|
+
});
|
|
1189
|
+
break;
|
|
1190
|
+
case "pPrDefault":
|
|
1191
|
+
var r = x.element(i, "pPr");
|
|
1192
|
+
r && t.styles.push({
|
|
1193
|
+
target: "p",
|
|
1194
|
+
values: this.parseDefaultProperties(r, {})
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
return t;
|
|
1198
|
+
}
|
|
1199
|
+
parseStyle(e) {
|
|
1200
|
+
var t = {
|
|
1201
|
+
id: x.attr(e, "styleId"),
|
|
1202
|
+
isDefault: x.boolAttr(e, "default"),
|
|
1203
|
+
name: null,
|
|
1204
|
+
target: null,
|
|
1205
|
+
basedOn: null,
|
|
1206
|
+
styles: [],
|
|
1207
|
+
linked: null
|
|
1208
|
+
};
|
|
1209
|
+
switch (x.attr(e, "type")) {
|
|
1210
|
+
case "paragraph":
|
|
1211
|
+
t.target = "p";
|
|
1212
|
+
break;
|
|
1213
|
+
case "table":
|
|
1214
|
+
t.target = "table";
|
|
1215
|
+
break;
|
|
1216
|
+
case "character": t.target = "span";
|
|
1217
|
+
}
|
|
1218
|
+
for (let n of x.elements(e)) switch (n.localName) {
|
|
1219
|
+
case "basedOn":
|
|
1220
|
+
t.basedOn = x.attr(n, "val");
|
|
1221
|
+
break;
|
|
1222
|
+
case "name":
|
|
1223
|
+
t.name = x.attr(n, "val");
|
|
1224
|
+
break;
|
|
1225
|
+
case "link":
|
|
1226
|
+
t.linked = x.attr(n, "val");
|
|
1227
|
+
break;
|
|
1228
|
+
case "next":
|
|
1229
|
+
t.next = x.attr(n, "val");
|
|
1230
|
+
break;
|
|
1231
|
+
case "aliases":
|
|
1232
|
+
t.aliases = x.attr(n, "val").split(",");
|
|
1233
|
+
break;
|
|
1234
|
+
case "pPr":
|
|
1235
|
+
t.styles.push({
|
|
1236
|
+
target: "p",
|
|
1237
|
+
values: this.parseDefaultProperties(n, {})
|
|
1238
|
+
}), t.paragraphProps = k(n, x);
|
|
1239
|
+
break;
|
|
1240
|
+
case "rPr":
|
|
1241
|
+
t.styles.push({
|
|
1242
|
+
target: "span",
|
|
1243
|
+
values: this.parseDefaultProperties(n, {})
|
|
1244
|
+
}), t.runProps = O(n, x);
|
|
1245
|
+
break;
|
|
1246
|
+
case "tblPr":
|
|
1247
|
+
case "tcPr":
|
|
1248
|
+
t.styles.push({
|
|
1249
|
+
target: "td",
|
|
1250
|
+
values: this.parseDefaultProperties(n, {})
|
|
1251
|
+
});
|
|
1252
|
+
break;
|
|
1253
|
+
case "tblStylePr":
|
|
1254
|
+
for (let e of this.parseTableStyle(n)) t.styles.push(e);
|
|
1255
|
+
break;
|
|
1256
|
+
case "rsid":
|
|
1257
|
+
case "qFormat":
|
|
1258
|
+
case "hidden":
|
|
1259
|
+
case "semiHidden":
|
|
1260
|
+
case "unhideWhenUsed":
|
|
1261
|
+
case "autoRedefine":
|
|
1262
|
+
case "uiPriority": break;
|
|
1263
|
+
default: this.options.debug && console.warn(`DOCX: Unknown style element: ${n.localName}`);
|
|
1264
|
+
}
|
|
1265
|
+
return t;
|
|
1266
|
+
}
|
|
1267
|
+
parseTableStyle(e) {
|
|
1268
|
+
var t = [], n = x.attr(e, "type"), r = "", i = "";
|
|
1269
|
+
switch (n) {
|
|
1270
|
+
case "firstRow":
|
|
1271
|
+
i = ".first-row", r = "tr.first-row td";
|
|
1272
|
+
break;
|
|
1273
|
+
case "lastRow":
|
|
1274
|
+
i = ".last-row", r = "tr.last-row td";
|
|
1275
|
+
break;
|
|
1276
|
+
case "firstCol":
|
|
1277
|
+
i = ".first-col", r = "td.first-col";
|
|
1278
|
+
break;
|
|
1279
|
+
case "lastCol":
|
|
1280
|
+
i = ".last-col", r = "td.last-col";
|
|
1281
|
+
break;
|
|
1282
|
+
case "band1Vert":
|
|
1283
|
+
i = ":not(.no-vband)", r = "td.odd-col";
|
|
1284
|
+
break;
|
|
1285
|
+
case "band2Vert":
|
|
1286
|
+
i = ":not(.no-vband)", r = "td.even-col";
|
|
1287
|
+
break;
|
|
1288
|
+
case "band1Horz":
|
|
1289
|
+
i = ":not(.no-hband)", r = "tr.odd-row";
|
|
1290
|
+
break;
|
|
1291
|
+
case "band2Horz":
|
|
1292
|
+
i = ":not(.no-hband)", r = "tr.even-row";
|
|
1293
|
+
break;
|
|
1294
|
+
default: return [];
|
|
1295
|
+
}
|
|
1296
|
+
for (let n of x.elements(e)) switch (n.localName) {
|
|
1297
|
+
case "pPr":
|
|
1298
|
+
t.push({
|
|
1299
|
+
target: `${r} p`,
|
|
1300
|
+
mod: i,
|
|
1301
|
+
values: this.parseDefaultProperties(n, {})
|
|
1302
|
+
});
|
|
1303
|
+
break;
|
|
1304
|
+
case "rPr":
|
|
1305
|
+
t.push({
|
|
1306
|
+
target: `${r} span`,
|
|
1307
|
+
mod: i,
|
|
1308
|
+
values: this.parseDefaultProperties(n, {})
|
|
1309
|
+
});
|
|
1310
|
+
break;
|
|
1311
|
+
case "tblPr":
|
|
1312
|
+
case "tcPr": t.push({
|
|
1313
|
+
target: r,
|
|
1314
|
+
mod: i,
|
|
1315
|
+
values: this.parseDefaultProperties(n, {})
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1318
|
+
return t;
|
|
1319
|
+
}
|
|
1320
|
+
parseNumberingFile(e) {
|
|
1321
|
+
let t = [], n = [], r = [];
|
|
1322
|
+
for (let i of x.elements(e)) switch (i.localName) {
|
|
1323
|
+
case "abstractNum":
|
|
1324
|
+
t.push(...this.parseAbstractNumbering(i, r));
|
|
1325
|
+
break;
|
|
1326
|
+
case "numPicBullet":
|
|
1327
|
+
r.push(this.parseNumberingPicBullet(i));
|
|
1328
|
+
break;
|
|
1329
|
+
case "num": n.push({
|
|
1330
|
+
numId: x.attr(i, "numId"),
|
|
1331
|
+
abstractNumId: x.elementAttr(i, "abstractNumId", "val")
|
|
1332
|
+
});
|
|
1333
|
+
}
|
|
1334
|
+
return n.flatMap((e) => t.filter((t) => e.abstractNumId == t.id).map((t) => ({
|
|
1335
|
+
...t,
|
|
1336
|
+
id: e.numId
|
|
1337
|
+
})));
|
|
1338
|
+
}
|
|
1339
|
+
parseNumberingPicBullet(e) {
|
|
1340
|
+
var t = x.element(e, "pict"), n = t && x.element(t, "shape"), r = n && x.element(n, "imagedata");
|
|
1341
|
+
return r ? {
|
|
1342
|
+
id: x.intAttr(e, "numPicBulletId"),
|
|
1343
|
+
src: x.attr(r, "id"),
|
|
1344
|
+
style: x.attr(n, "style")
|
|
1345
|
+
} : null;
|
|
1346
|
+
}
|
|
1347
|
+
parseAbstractNumbering(e, t) {
|
|
1348
|
+
var n = [], r = x.attr(e, "abstractNumId");
|
|
1349
|
+
for (let i of x.elements(e)) switch (i.localName) {
|
|
1350
|
+
case "lvl": n.push(this.parseNumberingLevel(r, i, t));
|
|
1351
|
+
}
|
|
1352
|
+
return n;
|
|
1353
|
+
}
|
|
1354
|
+
parseNumberingLevel(e, t, n) {
|
|
1355
|
+
var r = {
|
|
1356
|
+
id: e,
|
|
1357
|
+
level: x.intAttr(t, "ilvl"),
|
|
1358
|
+
start: 1,
|
|
1359
|
+
pStyleName: void 0,
|
|
1360
|
+
pStyle: {},
|
|
1361
|
+
rStyle: {},
|
|
1362
|
+
suff: "tab"
|
|
1363
|
+
};
|
|
1364
|
+
for (let e of x.elements(t)) switch (e.localName) {
|
|
1365
|
+
case "start":
|
|
1366
|
+
r.start = x.intAttr(e, "val");
|
|
1367
|
+
break;
|
|
1368
|
+
case "pPr":
|
|
1369
|
+
this.parseDefaultProperties(e, r.pStyle);
|
|
1370
|
+
break;
|
|
1371
|
+
case "rPr":
|
|
1372
|
+
this.parseDefaultProperties(e, r.rStyle);
|
|
1373
|
+
break;
|
|
1374
|
+
case "lvlPicBulletId":
|
|
1375
|
+
var i = x.intAttr(e, "val");
|
|
1376
|
+
r.bullet = n.find((e) => e?.id == i);
|
|
1377
|
+
break;
|
|
1378
|
+
case "lvlText":
|
|
1379
|
+
r.levelText = x.attr(e, "val");
|
|
1380
|
+
break;
|
|
1381
|
+
case "pStyle":
|
|
1382
|
+
r.pStyleName = x.attr(e, "val");
|
|
1383
|
+
break;
|
|
1384
|
+
case "numFmt":
|
|
1385
|
+
r.format = x.attr(e, "val");
|
|
1386
|
+
break;
|
|
1387
|
+
case "suff": r.suff = x.attr(e, "val");
|
|
1388
|
+
}
|
|
1389
|
+
return r;
|
|
1390
|
+
}
|
|
1391
|
+
parseSdt(e, t) {
|
|
1392
|
+
let n = x.element(e, "sdtContent");
|
|
1393
|
+
return n ? t(n) : [];
|
|
1394
|
+
}
|
|
1395
|
+
parseChange(e, t, n) {
|
|
1396
|
+
return {
|
|
1397
|
+
type: e,
|
|
1398
|
+
children: n(t)?.children ?? [],
|
|
1399
|
+
id: x.attr(t, "id"),
|
|
1400
|
+
author: x.attr(t, "author"),
|
|
1401
|
+
date: x.attr(t, "date")
|
|
1402
|
+
};
|
|
1403
|
+
}
|
|
1404
|
+
parseAltChunk(e) {
|
|
1405
|
+
return {
|
|
1406
|
+
type: P.AltChunk,
|
|
1407
|
+
children: [],
|
|
1408
|
+
id: x.attr(e, "id")
|
|
1409
|
+
};
|
|
1410
|
+
}
|
|
1411
|
+
parseParagraph(e) {
|
|
1412
|
+
var t = {
|
|
1413
|
+
type: P.Paragraph,
|
|
1414
|
+
children: []
|
|
1415
|
+
};
|
|
1416
|
+
for (let n of x.elements(e)) switch (n.localName) {
|
|
1417
|
+
case "pPr":
|
|
1418
|
+
this.parseParagraphProperties(n, t);
|
|
1419
|
+
break;
|
|
1420
|
+
case "r":
|
|
1421
|
+
t.children.push(this.parseRun(n, t));
|
|
1422
|
+
break;
|
|
1423
|
+
case "hyperlink":
|
|
1424
|
+
t.children.push(this.parseHyperlink(n, t));
|
|
1425
|
+
break;
|
|
1426
|
+
case "smartTag":
|
|
1427
|
+
t.children.push(this.parseSmartTag(n, t));
|
|
1428
|
+
break;
|
|
1429
|
+
case "bookmarkStart":
|
|
1430
|
+
t.children.push(Xe(n, x));
|
|
1431
|
+
break;
|
|
1432
|
+
case "bookmarkEnd":
|
|
1433
|
+
t.children.push(Ze(n, x));
|
|
1434
|
+
break;
|
|
1435
|
+
case "commentRangeStart":
|
|
1436
|
+
t.children.push(new rt(x.attr(n, "id")));
|
|
1437
|
+
break;
|
|
1438
|
+
case "commentRangeEnd":
|
|
1439
|
+
t.children.push(new it(x.attr(n, "id")));
|
|
1440
|
+
break;
|
|
1441
|
+
case "oMath":
|
|
1442
|
+
case "oMathPara":
|
|
1443
|
+
t.children.push(this.parseMathElement(n));
|
|
1444
|
+
break;
|
|
1445
|
+
case "sdt":
|
|
1446
|
+
t.children.push(...this.parseSdt(n, (e) => this.parseParagraph(e).children));
|
|
1447
|
+
break;
|
|
1448
|
+
case "ins":
|
|
1449
|
+
t.children.push(this.parseChange(P.Inserted, n, (e) => this.parseParagraph(e)));
|
|
1450
|
+
break;
|
|
1451
|
+
case "del": t.children.push(this.parseChange(P.Deleted, n, (e) => this.parseParagraph(e)));
|
|
1452
|
+
}
|
|
1453
|
+
return t;
|
|
1454
|
+
}
|
|
1455
|
+
parseParagraphProperties(e, t) {
|
|
1456
|
+
this.parseDefaultProperties(e, t.cssStyle = {}, null, (e) => {
|
|
1457
|
+
if (A(e, t, x)) return !0;
|
|
1458
|
+
switch (e.localName) {
|
|
1459
|
+
case "pStyle":
|
|
1460
|
+
t.styleName = x.attr(e, "val");
|
|
1461
|
+
break;
|
|
1462
|
+
case "cnfStyle":
|
|
1463
|
+
t.className = J.classNameOfCnfStyle(e);
|
|
1464
|
+
break;
|
|
1465
|
+
case "framePr":
|
|
1466
|
+
this.parseFrame(e, t);
|
|
1467
|
+
break;
|
|
1468
|
+
case "rPr": break;
|
|
1469
|
+
default: return !1;
|
|
1470
|
+
}
|
|
1471
|
+
return !0;
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
parseFrame(e, t) {
|
|
1475
|
+
x.attr(e, "dropCap") == "drop" && (t.cssStyle.float = "left");
|
|
1476
|
+
}
|
|
1477
|
+
parseHyperlink(e, t) {
|
|
1478
|
+
var n = {
|
|
1479
|
+
type: P.Hyperlink,
|
|
1480
|
+
parent: t,
|
|
1481
|
+
children: []
|
|
1482
|
+
};
|
|
1483
|
+
n.anchor = x.attr(e, "anchor"), n.id = x.attr(e, "id");
|
|
1484
|
+
for (let t of x.elements(e)) switch (t.localName) {
|
|
1485
|
+
case "r": n.children.push(this.parseRun(t, n));
|
|
1486
|
+
}
|
|
1487
|
+
return n;
|
|
1488
|
+
}
|
|
1489
|
+
parseSmartTag(e, t) {
|
|
1490
|
+
var n = {
|
|
1491
|
+
type: P.SmartTag,
|
|
1492
|
+
parent: t,
|
|
1493
|
+
children: []
|
|
1494
|
+
}, r = x.attr(e, "uri"), i = x.attr(e, "element");
|
|
1495
|
+
r && (n.uri = r), i && (n.element = i);
|
|
1496
|
+
for (let t of x.elements(e)) switch (t.localName) {
|
|
1497
|
+
case "r":
|
|
1498
|
+
n.children.push(this.parseRun(t, n));
|
|
1499
|
+
break;
|
|
1500
|
+
case "smartTag": n.children.push(this.parseSmartTag(t, n));
|
|
1501
|
+
}
|
|
1502
|
+
return n;
|
|
1503
|
+
}
|
|
1504
|
+
parseRun(e, t) {
|
|
1505
|
+
var n = {
|
|
1506
|
+
type: P.Run,
|
|
1507
|
+
parent: t,
|
|
1508
|
+
children: []
|
|
1509
|
+
};
|
|
1510
|
+
for (let t of x.elements(e)) switch (t = this.checkAlternateContent(t), t?.localName) {
|
|
1511
|
+
case "t":
|
|
1512
|
+
n.children.push({
|
|
1513
|
+
type: P.Text,
|
|
1514
|
+
text: t.textContent
|
|
1515
|
+
});
|
|
1516
|
+
break;
|
|
1517
|
+
case "delText":
|
|
1518
|
+
n.children.push({
|
|
1519
|
+
type: P.DeletedText,
|
|
1520
|
+
text: t.textContent
|
|
1521
|
+
});
|
|
1522
|
+
break;
|
|
1523
|
+
case "commentReference":
|
|
1524
|
+
n.children.push(new nt(x.attr(t, "id")));
|
|
1525
|
+
break;
|
|
1526
|
+
case "fldSimple":
|
|
1527
|
+
n.children.push({
|
|
1528
|
+
type: P.SimpleField,
|
|
1529
|
+
instruction: x.attr(t, "instr"),
|
|
1530
|
+
lock: x.boolAttr(t, "lock", !1),
|
|
1531
|
+
dirty: x.boolAttr(t, "dirty", !1)
|
|
1532
|
+
});
|
|
1533
|
+
break;
|
|
1534
|
+
case "instrText":
|
|
1535
|
+
n.fieldRun = !0, n.children.push({
|
|
1536
|
+
type: P.Instruction,
|
|
1537
|
+
text: t.textContent
|
|
1538
|
+
});
|
|
1539
|
+
break;
|
|
1540
|
+
case "fldChar":
|
|
1541
|
+
n.fieldRun = !0, n.children.push({
|
|
1542
|
+
type: P.ComplexField,
|
|
1543
|
+
charType: x.attr(t, "fldCharType"),
|
|
1544
|
+
lock: x.boolAttr(t, "lock", !1),
|
|
1545
|
+
dirty: x.boolAttr(t, "dirty", !1)
|
|
1546
|
+
});
|
|
1547
|
+
break;
|
|
1548
|
+
case "noBreakHyphen":
|
|
1549
|
+
n.children.push({ type: P.NoBreakHyphen });
|
|
1550
|
+
break;
|
|
1551
|
+
case "br":
|
|
1552
|
+
n.children.push({
|
|
1553
|
+
type: P.Break,
|
|
1554
|
+
break: x.attr(t, "type") || "textWrapping"
|
|
1555
|
+
});
|
|
1556
|
+
break;
|
|
1557
|
+
case "lastRenderedPageBreak":
|
|
1558
|
+
n.children.push({
|
|
1559
|
+
type: P.Break,
|
|
1560
|
+
break: "lastRenderedPageBreak"
|
|
1561
|
+
});
|
|
1562
|
+
break;
|
|
1563
|
+
case "sym":
|
|
1564
|
+
n.children.push({
|
|
1565
|
+
type: P.Symbol,
|
|
1566
|
+
font: o(x.attr(t, "font")),
|
|
1567
|
+
char: x.hexAttr(t, "char")
|
|
1568
|
+
});
|
|
1569
|
+
break;
|
|
1570
|
+
case "tab":
|
|
1571
|
+
n.children.push({ type: P.Tab });
|
|
1572
|
+
break;
|
|
1573
|
+
case "footnoteReference":
|
|
1574
|
+
n.children.push({
|
|
1575
|
+
type: P.FootnoteReference,
|
|
1576
|
+
id: x.attr(t, "id")
|
|
1577
|
+
});
|
|
1578
|
+
break;
|
|
1579
|
+
case "endnoteReference":
|
|
1580
|
+
n.children.push({
|
|
1581
|
+
type: P.EndnoteReference,
|
|
1582
|
+
id: x.attr(t, "id")
|
|
1583
|
+
});
|
|
1584
|
+
break;
|
|
1585
|
+
case "drawing":
|
|
1586
|
+
let e = this.parseDrawing(t);
|
|
1587
|
+
e && n.children.push(e);
|
|
1588
|
+
break;
|
|
1589
|
+
case "pict":
|
|
1590
|
+
n.children.push(this.parseVmlPicture(t));
|
|
1591
|
+
break;
|
|
1592
|
+
case "rPr": this.parseRunProperties(t, n);
|
|
1593
|
+
}
|
|
1594
|
+
return n;
|
|
1595
|
+
}
|
|
1596
|
+
parseMathElement(e) {
|
|
1597
|
+
let t = `${e.localName}Pr`, n = {
|
|
1598
|
+
type: K[e.localName],
|
|
1599
|
+
children: []
|
|
1600
|
+
};
|
|
1601
|
+
for (let i of x.elements(e)) if (K[i.localName]) n.children.push(this.parseMathElement(i));
|
|
1602
|
+
else if (i.localName == "r") {
|
|
1603
|
+
var r = this.parseRun(i);
|
|
1604
|
+
r.type = P.MmlRun, n.children.push(r);
|
|
1605
|
+
} else i.localName == t && (n.props = this.parseMathProperies(i));
|
|
1606
|
+
return n;
|
|
1607
|
+
}
|
|
1608
|
+
parseMathProperies(e) {
|
|
1609
|
+
let t = {};
|
|
1610
|
+
for (let n of x.elements(e)) switch (n.localName) {
|
|
1611
|
+
case "chr":
|
|
1612
|
+
t.char = x.attr(n, "val");
|
|
1613
|
+
break;
|
|
1614
|
+
case "vertJc":
|
|
1615
|
+
t.verticalJustification = x.attr(n, "val");
|
|
1616
|
+
break;
|
|
1617
|
+
case "pos":
|
|
1618
|
+
t.position = x.attr(n, "val");
|
|
1619
|
+
break;
|
|
1620
|
+
case "degHide":
|
|
1621
|
+
t.hideDegree = x.boolAttr(n, "val");
|
|
1622
|
+
break;
|
|
1623
|
+
case "begChr":
|
|
1624
|
+
t.beginChar = x.attr(n, "val");
|
|
1625
|
+
break;
|
|
1626
|
+
case "endChr": t.endChar = x.attr(n, "val");
|
|
1627
|
+
}
|
|
1628
|
+
return t;
|
|
1629
|
+
}
|
|
1630
|
+
parseRunProperties(e, t) {
|
|
1631
|
+
this.parseDefaultProperties(e, t.cssStyle = {}, null, (e) => {
|
|
1632
|
+
switch (e.localName) {
|
|
1633
|
+
case "rStyle":
|
|
1634
|
+
t.styleName = x.attr(e, "val");
|
|
1635
|
+
break;
|
|
1636
|
+
case "vertAlign":
|
|
1637
|
+
t.verticalAlign = J.valueOfVertAlign(e, !0);
|
|
1638
|
+
break;
|
|
1639
|
+
default: return !1;
|
|
1640
|
+
}
|
|
1641
|
+
return !0;
|
|
1642
|
+
});
|
|
1643
|
+
}
|
|
1644
|
+
parseVmlPicture(e) {
|
|
1645
|
+
let t = {
|
|
1646
|
+
type: P.VmlPicture,
|
|
1647
|
+
children: []
|
|
1648
|
+
};
|
|
1649
|
+
for (let n of x.elements(e)) {
|
|
1650
|
+
let e = U(n, this);
|
|
1651
|
+
e && t.children.push(e);
|
|
1652
|
+
}
|
|
1653
|
+
return t;
|
|
1654
|
+
}
|
|
1655
|
+
checkAlternateContent(e) {
|
|
1656
|
+
if (e.localName != "AlternateContent") return e;
|
|
1657
|
+
var t = x.element(e, "Choice");
|
|
1658
|
+
if (t) {
|
|
1659
|
+
var n = x.attr(t, "Requires"), r = e.lookupNamespaceURI(n);
|
|
1660
|
+
if (at.includes(r)) return t.firstElementChild;
|
|
1661
|
+
}
|
|
1662
|
+
return x.element(e, "Fallback")?.firstElementChild;
|
|
1663
|
+
}
|
|
1664
|
+
parseDrawing(e) {
|
|
1665
|
+
for (var t of x.elements(e)) switch (t.localName) {
|
|
1666
|
+
case "inline":
|
|
1667
|
+
case "anchor": return this.parseDrawingWrapper(t);
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
parseDrawingWrapper(e) {
|
|
1671
|
+
var t = {
|
|
1672
|
+
type: P.Drawing,
|
|
1673
|
+
children: [],
|
|
1674
|
+
cssStyle: {}
|
|
1675
|
+
}, n = e.localName == "anchor";
|
|
1676
|
+
let r = null, i = x.boolAttr(e, "simplePos");
|
|
1677
|
+
x.boolAttr(e, "behindDoc");
|
|
1678
|
+
let a = {
|
|
1679
|
+
relative: "page",
|
|
1680
|
+
align: "left",
|
|
1681
|
+
offset: "0"
|
|
1682
|
+
}, o = {
|
|
1683
|
+
relative: "page",
|
|
1684
|
+
align: "top",
|
|
1685
|
+
offset: "0"
|
|
1686
|
+
};
|
|
1687
|
+
for (var s of x.elements(e)) switch (s.localName) {
|
|
1688
|
+
case "simplePos":
|
|
1689
|
+
i && (a.offset = x.lengthAttr(s, "x", _.Emu), o.offset = x.lengthAttr(s, "y", _.Emu));
|
|
1690
|
+
break;
|
|
1691
|
+
case "extent":
|
|
1692
|
+
t.cssStyle.width = x.lengthAttr(s, "cx", _.Emu), t.cssStyle.height = x.lengthAttr(s, "cy", _.Emu);
|
|
1693
|
+
break;
|
|
1694
|
+
case "positionH":
|
|
1695
|
+
case "positionV":
|
|
1696
|
+
if (!i) {
|
|
1697
|
+
let e = s.localName == "positionH" ? a : o;
|
|
1698
|
+
var c = x.element(s, "align"), l = x.element(s, "posOffset");
|
|
1699
|
+
e.relative = x.attr(s, "relativeFrom") ?? e.relative, c && (e.align = c.textContent), l && (e.offset = v(l.textContent, _.Emu));
|
|
1700
|
+
}
|
|
1701
|
+
break;
|
|
1702
|
+
case "wrapTopAndBottom":
|
|
1703
|
+
r = "wrapTopAndBottom";
|
|
1704
|
+
break;
|
|
1705
|
+
case "wrapNone":
|
|
1706
|
+
r = "wrapNone";
|
|
1707
|
+
break;
|
|
1708
|
+
case "graphic":
|
|
1709
|
+
var u = this.parseGraphic(s);
|
|
1710
|
+
u && t.children.push(u);
|
|
1711
|
+
}
|
|
1712
|
+
return r == "wrapTopAndBottom" ? (t.cssStyle.display = "block", a.align && (t.cssStyle["text-align"] = a.align, t.cssStyle.width = "100%")) : r == "wrapNone" ? (t.cssStyle.display = "block", t.cssStyle.position = "relative", t.cssStyle.width = "0px", t.cssStyle.height = "0px", a.offset && (t.cssStyle.left = a.offset), o.offset && (t.cssStyle.top = o.offset)) : n && (a.align == "left" || a.align == "right") && (t.cssStyle.float = a.align), t;
|
|
1713
|
+
}
|
|
1714
|
+
parseGraphic(e) {
|
|
1715
|
+
var t = x.element(e, "graphicData");
|
|
1716
|
+
for (let e of x.elements(t)) switch (e.localName) {
|
|
1717
|
+
case "pic": return this.parsePicture(e);
|
|
1718
|
+
}
|
|
1719
|
+
return null;
|
|
1720
|
+
}
|
|
1721
|
+
parsePicture(e) {
|
|
1722
|
+
var t = {
|
|
1723
|
+
type: P.Image,
|
|
1724
|
+
src: "",
|
|
1725
|
+
cssStyle: {}
|
|
1726
|
+
}, n = x.element(e, "blipFill"), r = x.element(n, "blip"), i = x.element(n, "srcRect");
|
|
1727
|
+
t.src = x.attr(r, "embed"), i && (t.srcRect = [
|
|
1728
|
+
x.intAttr(i, "l", 0) / 1e5,
|
|
1729
|
+
x.intAttr(i, "t", 0) / 1e5,
|
|
1730
|
+
x.intAttr(i, "r", 0) / 1e5,
|
|
1731
|
+
x.intAttr(i, "b", 0) / 1e5
|
|
1732
|
+
]);
|
|
1733
|
+
var a = x.element(e, "spPr"), o = x.element(a, "xfrm");
|
|
1734
|
+
if (t.cssStyle.position = "relative", o) {
|
|
1735
|
+
t.rotation = x.intAttr(o, "rot", 0) / 6e4;
|
|
1736
|
+
for (var s of x.elements(o)) switch (s.localName) {
|
|
1737
|
+
case "ext":
|
|
1738
|
+
t.cssStyle.width = x.lengthAttr(s, "cx", _.Emu), t.cssStyle.height = x.lengthAttr(s, "cy", _.Emu);
|
|
1739
|
+
break;
|
|
1740
|
+
case "off": t.cssStyle.left = x.lengthAttr(s, "x", _.Emu), t.cssStyle.top = x.lengthAttr(s, "y", _.Emu);
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
return t;
|
|
1744
|
+
}
|
|
1745
|
+
parseTable(e) {
|
|
1746
|
+
var t = {
|
|
1747
|
+
type: P.Table,
|
|
1748
|
+
children: []
|
|
1749
|
+
};
|
|
1750
|
+
for (let n of x.elements(e)) switch (n.localName) {
|
|
1751
|
+
case "tr":
|
|
1752
|
+
t.children.push(this.parseTableRow(n));
|
|
1753
|
+
break;
|
|
1754
|
+
case "tblGrid":
|
|
1755
|
+
t.columns = this.parseTableColumns(n);
|
|
1756
|
+
break;
|
|
1757
|
+
case "tblPr": this.parseTableProperties(n, t);
|
|
1758
|
+
}
|
|
1759
|
+
return t;
|
|
1760
|
+
}
|
|
1761
|
+
parseTableColumns(e) {
|
|
1762
|
+
var t = [];
|
|
1763
|
+
for (let n of x.elements(e)) switch (n.localName) {
|
|
1764
|
+
case "gridCol": t.push({ width: x.lengthAttr(n, "w") });
|
|
1765
|
+
}
|
|
1766
|
+
return t;
|
|
1767
|
+
}
|
|
1768
|
+
parseTableProperties(e, t) {
|
|
1769
|
+
switch (t.cssStyle = {}, t.cellStyle = {}, this.parseDefaultProperties(e, t.cssStyle, t.cellStyle, (e) => {
|
|
1770
|
+
switch (e.localName) {
|
|
1771
|
+
case "tblStyle":
|
|
1772
|
+
t.styleName = x.attr(e, "val");
|
|
1773
|
+
break;
|
|
1774
|
+
case "tblLook":
|
|
1775
|
+
t.className = J.classNameOftblLook(e);
|
|
1776
|
+
break;
|
|
1777
|
+
case "tblpPr":
|
|
1778
|
+
this.parseTablePosition(e, t);
|
|
1779
|
+
break;
|
|
1780
|
+
case "tblStyleColBandSize":
|
|
1781
|
+
t.colBandSize = x.intAttr(e, "val");
|
|
1782
|
+
break;
|
|
1783
|
+
case "tblStyleRowBandSize":
|
|
1784
|
+
t.rowBandSize = x.intAttr(e, "val");
|
|
1785
|
+
break;
|
|
1786
|
+
case "hidden":
|
|
1787
|
+
t.cssStyle.display = "none";
|
|
1788
|
+
break;
|
|
1789
|
+
default: return !1;
|
|
1790
|
+
}
|
|
1791
|
+
return !0;
|
|
1792
|
+
}), t.cssStyle["text-align"]) {
|
|
1793
|
+
case "center":
|
|
1794
|
+
delete t.cssStyle["text-align"], t.cssStyle["margin-left"] = "auto", t.cssStyle["margin-right"] = "auto";
|
|
1795
|
+
break;
|
|
1796
|
+
case "right": delete t.cssStyle["text-align"], t.cssStyle["margin-left"] = "auto";
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
parseTablePosition(e, t) {
|
|
1800
|
+
var n = x.lengthAttr(e, "topFromText"), r = x.lengthAttr(e, "bottomFromText"), i = x.lengthAttr(e, "rightFromText"), a = x.lengthAttr(e, "leftFromText");
|
|
1801
|
+
t.cssStyle.float = "left", t.cssStyle["margin-bottom"] = J.addSize(t.cssStyle["margin-bottom"], r), t.cssStyle["margin-left"] = J.addSize(t.cssStyle["margin-left"], a), t.cssStyle["margin-right"] = J.addSize(t.cssStyle["margin-right"], i), t.cssStyle["margin-top"] = J.addSize(t.cssStyle["margin-top"], n);
|
|
1802
|
+
}
|
|
1803
|
+
parseTableRow(e) {
|
|
1804
|
+
var t = {
|
|
1805
|
+
type: P.Row,
|
|
1806
|
+
children: []
|
|
1807
|
+
};
|
|
1808
|
+
for (let n of x.elements(e)) switch (n.localName) {
|
|
1809
|
+
case "tc":
|
|
1810
|
+
t.children.push(this.parseTableCell(n));
|
|
1811
|
+
break;
|
|
1812
|
+
case "trPr":
|
|
1813
|
+
case "tblPrEx": this.parseTableRowProperties(n, t);
|
|
1814
|
+
}
|
|
1815
|
+
return t;
|
|
1816
|
+
}
|
|
1817
|
+
parseTableRowProperties(e, t) {
|
|
1818
|
+
t.cssStyle = this.parseDefaultProperties(e, {}, null, (e) => {
|
|
1819
|
+
switch (e.localName) {
|
|
1820
|
+
case "cnfStyle":
|
|
1821
|
+
t.className = J.classNameOfCnfStyle(e);
|
|
1822
|
+
break;
|
|
1823
|
+
case "tblHeader":
|
|
1824
|
+
t.isHeader = x.boolAttr(e, "val");
|
|
1825
|
+
break;
|
|
1826
|
+
case "gridBefore":
|
|
1827
|
+
t.gridBefore = x.intAttr(e, "val");
|
|
1828
|
+
break;
|
|
1829
|
+
case "gridAfter":
|
|
1830
|
+
t.gridAfter = x.intAttr(e, "val");
|
|
1831
|
+
break;
|
|
1832
|
+
default: return !1;
|
|
1833
|
+
}
|
|
1834
|
+
return !0;
|
|
1835
|
+
});
|
|
1836
|
+
}
|
|
1837
|
+
parseTableCell(e) {
|
|
1838
|
+
var t = {
|
|
1839
|
+
type: P.Cell,
|
|
1840
|
+
children: []
|
|
1841
|
+
};
|
|
1842
|
+
for (let n of x.elements(e)) switch (n.localName) {
|
|
1843
|
+
case "tbl":
|
|
1844
|
+
t.children.push(this.parseTable(n));
|
|
1845
|
+
break;
|
|
1846
|
+
case "p":
|
|
1847
|
+
t.children.push(this.parseParagraph(n));
|
|
1848
|
+
break;
|
|
1849
|
+
case "tcPr": this.parseTableCellProperties(n, t);
|
|
1850
|
+
}
|
|
1851
|
+
return t;
|
|
1852
|
+
}
|
|
1853
|
+
parseTableCellProperties(e, t) {
|
|
1854
|
+
t.cssStyle = this.parseDefaultProperties(e, {}, null, (e) => {
|
|
1855
|
+
switch (e.localName) {
|
|
1856
|
+
case "gridSpan":
|
|
1857
|
+
t.span = x.intAttr(e, "val", null);
|
|
1858
|
+
break;
|
|
1859
|
+
case "vMerge":
|
|
1860
|
+
t.verticalMerge = x.attr(e, "val") ?? "continue";
|
|
1861
|
+
break;
|
|
1862
|
+
case "cnfStyle":
|
|
1863
|
+
t.className = J.classNameOfCnfStyle(e);
|
|
1864
|
+
break;
|
|
1865
|
+
default: return !1;
|
|
1866
|
+
}
|
|
1867
|
+
return !0;
|
|
1868
|
+
}), this.parseTableCellVerticalText(e, t);
|
|
1869
|
+
}
|
|
1870
|
+
parseTableCellVerticalText(e, t) {
|
|
1871
|
+
let n = {
|
|
1872
|
+
btLr: {
|
|
1873
|
+
writingMode: "vertical-rl",
|
|
1874
|
+
transform: "rotate(180deg)"
|
|
1875
|
+
},
|
|
1876
|
+
lrTb: {
|
|
1877
|
+
writingMode: "vertical-lr",
|
|
1878
|
+
transform: "none"
|
|
1879
|
+
},
|
|
1880
|
+
tbRl: {
|
|
1881
|
+
writingMode: "vertical-rl",
|
|
1882
|
+
transform: "none"
|
|
1883
|
+
}
|
|
1884
|
+
};
|
|
1885
|
+
for (let r of x.elements(e)) if (r.localName === "textDirection") {
|
|
1886
|
+
let e = n[x.attr(r, "val")] || { writingMode: "horizontal-tb" };
|
|
1887
|
+
t.cssStyle["writing-mode"] = e.writingMode, t.cssStyle.transform = e.transform;
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
parseDefaultProperties(e, t = null, n = null, r = null) {
|
|
1891
|
+
t = t || {};
|
|
1892
|
+
for (let i of x.elements(e)) if (!r?.(i)) switch (i.localName) {
|
|
1893
|
+
case "jc":
|
|
1894
|
+
t["text-align"] = J.valueOfJc(i);
|
|
1895
|
+
break;
|
|
1896
|
+
case "textAlignment":
|
|
1897
|
+
t["vertical-align"] = J.valueOfTextAlignment(i);
|
|
1898
|
+
break;
|
|
1899
|
+
case "color":
|
|
1900
|
+
t.color = q.colorAttr(i, "val", null, G.color);
|
|
1901
|
+
break;
|
|
1902
|
+
case "sz":
|
|
1903
|
+
t["font-size"] = t["min-height"] = x.lengthAttr(i, "val", _.FontSize);
|
|
1904
|
+
break;
|
|
1905
|
+
case "shd":
|
|
1906
|
+
t["background-color"] = q.colorAttr(i, "fill", null, G.shd);
|
|
1907
|
+
break;
|
|
1908
|
+
case "highlight":
|
|
1909
|
+
t["background-color"] = q.colorAttr(i, "val", null, G.highlight);
|
|
1910
|
+
break;
|
|
1911
|
+
case "vertAlign": break;
|
|
1912
|
+
case "position":
|
|
1913
|
+
t.verticalAlign = x.lengthAttr(i, "val", _.FontSize);
|
|
1914
|
+
break;
|
|
1915
|
+
case "tcW": if (this.options.ignoreWidth) break;
|
|
1916
|
+
case "tblW":
|
|
1917
|
+
t.width = J.valueOfSize(i, "w");
|
|
1918
|
+
break;
|
|
1919
|
+
case "trHeight":
|
|
1920
|
+
this.parseTrHeight(i, t);
|
|
1921
|
+
break;
|
|
1922
|
+
case "strike":
|
|
1923
|
+
t["text-decoration"] = x.boolAttr(i, "val", !0) ? "line-through" : "none";
|
|
1924
|
+
break;
|
|
1925
|
+
case "b":
|
|
1926
|
+
t["font-weight"] = x.boolAttr(i, "val", !0) ? "bold" : "normal";
|
|
1927
|
+
break;
|
|
1928
|
+
case "i":
|
|
1929
|
+
t["font-style"] = x.boolAttr(i, "val", !0) ? "italic" : "normal";
|
|
1930
|
+
break;
|
|
1931
|
+
case "caps":
|
|
1932
|
+
t["text-transform"] = x.boolAttr(i, "val", !0) ? "uppercase" : "none";
|
|
1933
|
+
break;
|
|
1934
|
+
case "smallCaps":
|
|
1935
|
+
t["font-variant"] = x.boolAttr(i, "val", !0) ? "small-caps" : "none";
|
|
1936
|
+
break;
|
|
1937
|
+
case "u":
|
|
1938
|
+
this.parseUnderline(i, t);
|
|
1939
|
+
break;
|
|
1940
|
+
case "ind":
|
|
1941
|
+
case "tblInd":
|
|
1942
|
+
this.parseIndentation(i, t);
|
|
1943
|
+
break;
|
|
1944
|
+
case "rFonts":
|
|
1945
|
+
this.parseFont(i, t);
|
|
1946
|
+
break;
|
|
1947
|
+
case "tblBorders":
|
|
1948
|
+
this.parseBorderProperties(i, n || t);
|
|
1949
|
+
break;
|
|
1950
|
+
case "tblCellSpacing":
|
|
1951
|
+
t["border-spacing"] = J.valueOfMargin(i), t["border-collapse"] = "separate";
|
|
1952
|
+
break;
|
|
1953
|
+
case "pBdr":
|
|
1954
|
+
this.parseBorderProperties(i, t);
|
|
1955
|
+
break;
|
|
1956
|
+
case "bdr":
|
|
1957
|
+
t.border = J.valueOfBorder(i);
|
|
1958
|
+
break;
|
|
1959
|
+
case "tcBorders":
|
|
1960
|
+
this.parseBorderProperties(i, t);
|
|
1961
|
+
break;
|
|
1962
|
+
case "vanish":
|
|
1963
|
+
x.boolAttr(i, "val", !0) && (t.display = "none");
|
|
1964
|
+
break;
|
|
1965
|
+
case "kern": break;
|
|
1966
|
+
case "noWrap": break;
|
|
1967
|
+
case "tblCellMar":
|
|
1968
|
+
case "tcMar":
|
|
1969
|
+
this.parseMarginProperties(i, n || t);
|
|
1970
|
+
break;
|
|
1971
|
+
case "tblLayout":
|
|
1972
|
+
t["table-layout"] = J.valueOfTblLayout(i);
|
|
1973
|
+
break;
|
|
1974
|
+
case "vAlign":
|
|
1975
|
+
t["vertical-align"] = J.valueOfTextAlignment(i);
|
|
1976
|
+
break;
|
|
1977
|
+
case "spacing":
|
|
1978
|
+
e.localName == "pPr" && this.parseSpacing(i, t);
|
|
1979
|
+
break;
|
|
1980
|
+
case "wordWrap":
|
|
1981
|
+
x.boolAttr(i, "val") && (t["overflow-wrap"] = "break-word");
|
|
1982
|
+
break;
|
|
1983
|
+
case "suppressAutoHyphens":
|
|
1984
|
+
t.hyphens = x.boolAttr(i, "val", !0) ? "none" : "auto";
|
|
1985
|
+
break;
|
|
1986
|
+
case "lang":
|
|
1987
|
+
t.$lang = x.attr(i, "val");
|
|
1988
|
+
break;
|
|
1989
|
+
case "rtl":
|
|
1990
|
+
case "bidi":
|
|
1991
|
+
x.boolAttr(i, "val", !0) && (t.direction = "rtl");
|
|
1992
|
+
break;
|
|
1993
|
+
case "bCs":
|
|
1994
|
+
case "iCs":
|
|
1995
|
+
case "szCs":
|
|
1996
|
+
case "tabs":
|
|
1997
|
+
case "outlineLvl":
|
|
1998
|
+
case "contextualSpacing":
|
|
1999
|
+
case "tblStyleColBandSize":
|
|
2000
|
+
case "tblStyleRowBandSize":
|
|
2001
|
+
case "webHidden":
|
|
2002
|
+
case "pageBreakBefore":
|
|
2003
|
+
case "suppressLineNumbers":
|
|
2004
|
+
case "keepLines":
|
|
2005
|
+
case "keepNext":
|
|
2006
|
+
case "widowControl":
|
|
2007
|
+
case "noProof": break;
|
|
2008
|
+
default: this.options.debug && console.warn(`DOCX: Unknown document element: ${e.localName}.${i.localName}`);
|
|
2009
|
+
}
|
|
2010
|
+
return t;
|
|
2011
|
+
}
|
|
2012
|
+
parseUnderline(e, t) {
|
|
2013
|
+
var n = x.attr(e, "val");
|
|
2014
|
+
if (n != null) {
|
|
2015
|
+
switch (n) {
|
|
2016
|
+
case "dash":
|
|
2017
|
+
case "dashDotDotHeavy":
|
|
2018
|
+
case "dashDotHeavy":
|
|
2019
|
+
case "dashedHeavy":
|
|
2020
|
+
case "dashLong":
|
|
2021
|
+
case "dashLongHeavy":
|
|
2022
|
+
case "dotDash":
|
|
2023
|
+
case "dotDotDash":
|
|
2024
|
+
t["text-decoration"] = "underline dashed";
|
|
2025
|
+
break;
|
|
2026
|
+
case "dotted":
|
|
2027
|
+
case "dottedHeavy":
|
|
2028
|
+
t["text-decoration"] = "underline dotted";
|
|
2029
|
+
break;
|
|
2030
|
+
case "double":
|
|
2031
|
+
t["text-decoration"] = "underline double";
|
|
2032
|
+
break;
|
|
2033
|
+
case "single":
|
|
2034
|
+
case "thick":
|
|
2035
|
+
t["text-decoration"] = "underline";
|
|
2036
|
+
break;
|
|
2037
|
+
case "wave":
|
|
2038
|
+
case "wavyDouble":
|
|
2039
|
+
case "wavyHeavy":
|
|
2040
|
+
t["text-decoration"] = "underline wavy";
|
|
2041
|
+
break;
|
|
2042
|
+
case "words":
|
|
2043
|
+
t["text-decoration"] = "underline";
|
|
2044
|
+
break;
|
|
2045
|
+
case "none": t["text-decoration"] = "none";
|
|
2046
|
+
}
|
|
2047
|
+
var r = q.colorAttr(e, "color");
|
|
2048
|
+
r && (t["text-decoration-color"] = r);
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
parseFont(e, t) {
|
|
2052
|
+
var n = [
|
|
2053
|
+
x.attr(e, "ascii"),
|
|
2054
|
+
J.themeValue(e, "asciiTheme"),
|
|
2055
|
+
x.attr(e, "eastAsia")
|
|
2056
|
+
].filter((e) => e).map((e) => o(e));
|
|
2057
|
+
n.length > 0 && (t["font-family"] = [...new Set(n)].join(", "));
|
|
2058
|
+
}
|
|
2059
|
+
parseIndentation(e, t) {
|
|
2060
|
+
var n = x.lengthAttr(e, "firstLine"), r = x.lengthAttr(e, "hanging"), i = x.lengthAttr(e, "left"), a = x.lengthAttr(e, "start"), o = x.lengthAttr(e, "right"), s = x.lengthAttr(e, "end");
|
|
2061
|
+
n && (t["text-indent"] = n), r && (t["text-indent"] = `-${r}`), (i || a) && (t["margin-inline-start"] = i || a), (o || s) && (t["margin-inline-end"] = o || s);
|
|
2062
|
+
}
|
|
2063
|
+
parseSpacing(e, t) {
|
|
2064
|
+
var n = x.lengthAttr(e, "before"), r = x.lengthAttr(e, "after"), i = x.intAttr(e, "line", null), a = x.attr(e, "lineRule");
|
|
2065
|
+
if (n && (t["margin-top"] = n), r && (t["margin-bottom"] = r), i !== null) switch (a) {
|
|
2066
|
+
case "auto":
|
|
2067
|
+
t["line-height"] = `${(i / 240).toFixed(2)}`;
|
|
2068
|
+
break;
|
|
2069
|
+
case "atLeast":
|
|
2070
|
+
t["line-height"] = `calc(100% + ${i / 20}pt)`;
|
|
2071
|
+
break;
|
|
2072
|
+
default: t["line-height"] = t["min-height"] = `${i / 20}pt`;
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
parseMarginProperties(e, t) {
|
|
2076
|
+
for (let n of x.elements(e)) switch (n.localName) {
|
|
2077
|
+
case "left":
|
|
2078
|
+
t["padding-left"] = J.valueOfMargin(n);
|
|
2079
|
+
break;
|
|
2080
|
+
case "right":
|
|
2081
|
+
t["padding-right"] = J.valueOfMargin(n);
|
|
2082
|
+
break;
|
|
2083
|
+
case "top":
|
|
2084
|
+
t["padding-top"] = J.valueOfMargin(n);
|
|
2085
|
+
break;
|
|
2086
|
+
case "bottom": t["padding-bottom"] = J.valueOfMargin(n);
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
parseTrHeight(e, t) {
|
|
2090
|
+
switch (x.attr(e, "hRule")) {
|
|
2091
|
+
case "exact":
|
|
2092
|
+
t.height = x.lengthAttr(e, "val");
|
|
2093
|
+
break;
|
|
2094
|
+
default: t.height = x.lengthAttr(e, "val");
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
parseBorderProperties(e, t) {
|
|
2098
|
+
for (let n of x.elements(e)) switch (n.localName) {
|
|
2099
|
+
case "start":
|
|
2100
|
+
case "left":
|
|
2101
|
+
t["border-left"] = J.valueOfBorder(n);
|
|
2102
|
+
break;
|
|
2103
|
+
case "end":
|
|
2104
|
+
case "right":
|
|
2105
|
+
t["border-right"] = J.valueOfBorder(n);
|
|
2106
|
+
break;
|
|
2107
|
+
case "top":
|
|
2108
|
+
t["border-top"] = J.valueOfBorder(n);
|
|
2109
|
+
break;
|
|
2110
|
+
case "bottom": t["border-bottom"] = J.valueOfBorder(n);
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
}, st = [
|
|
2114
|
+
"black",
|
|
2115
|
+
"blue",
|
|
2116
|
+
"cyan",
|
|
2117
|
+
"darkBlue",
|
|
2118
|
+
"darkCyan",
|
|
2119
|
+
"darkGray",
|
|
2120
|
+
"darkGreen",
|
|
2121
|
+
"darkMagenta",
|
|
2122
|
+
"darkRed",
|
|
2123
|
+
"darkYellow",
|
|
2124
|
+
"green",
|
|
2125
|
+
"lightGray",
|
|
2126
|
+
"magenta",
|
|
2127
|
+
"none",
|
|
2128
|
+
"red",
|
|
2129
|
+
"white",
|
|
2130
|
+
"yellow"
|
|
2131
|
+
], q = class {
|
|
2132
|
+
static colorAttr(e, t, n = null, r = "black") {
|
|
2133
|
+
var i = x.attr(e, t);
|
|
2134
|
+
if (i) return i == "auto" ? r : st.includes(i) ? i : `#${i}`;
|
|
2135
|
+
var a = x.attr(e, "themeColor");
|
|
2136
|
+
return a ? `var(--docx-${a}-color)` : n;
|
|
2137
|
+
}
|
|
2138
|
+
}, J = class e {
|
|
2139
|
+
static themeValue(e, t) {
|
|
2140
|
+
var n = x.attr(e, t);
|
|
2141
|
+
return n ? `var(--docx-${n}-font)` : null;
|
|
2142
|
+
}
|
|
2143
|
+
static valueOfSize(e, t) {
|
|
2144
|
+
var n = _.Dxa;
|
|
2145
|
+
switch (x.attr(e, "type")) {
|
|
2146
|
+
case "dxa": break;
|
|
2147
|
+
case "pct":
|
|
2148
|
+
n = _.Percent;
|
|
2149
|
+
break;
|
|
2150
|
+
case "auto": return "auto";
|
|
2151
|
+
}
|
|
2152
|
+
return x.lengthAttr(e, t, n);
|
|
2153
|
+
}
|
|
2154
|
+
static valueOfMargin(e) {
|
|
2155
|
+
return x.lengthAttr(e, "w");
|
|
2156
|
+
}
|
|
2157
|
+
static valueOfBorder(t) {
|
|
2158
|
+
var n = e.parseBorderType(x.attr(t, "val"));
|
|
2159
|
+
if (n == "none") return "none";
|
|
2160
|
+
var r = q.colorAttr(t, "color");
|
|
2161
|
+
return `${x.lengthAttr(t, "sz", _.Border)} ${n} ${r == "auto" ? G.borderColor : r}`;
|
|
2162
|
+
}
|
|
2163
|
+
static parseBorderType(e) {
|
|
2164
|
+
switch (e) {
|
|
2165
|
+
case "single": return "solid";
|
|
2166
|
+
case "dashDotStroked": return "solid";
|
|
2167
|
+
case "dashed": return "dashed";
|
|
2168
|
+
case "dashSmallGap": return "dashed";
|
|
2169
|
+
case "dotDash": return "dotted";
|
|
2170
|
+
case "dotDotDash": return "dotted";
|
|
2171
|
+
case "dotted": return "dotted";
|
|
2172
|
+
case "double": return "double";
|
|
2173
|
+
case "doubleWave": return "double";
|
|
2174
|
+
case "inset": return "inset";
|
|
2175
|
+
case "nil": return "none";
|
|
2176
|
+
case "none": return "none";
|
|
2177
|
+
case "outset": return "outset";
|
|
2178
|
+
case "thick": return "solid";
|
|
2179
|
+
case "thickThinLargeGap": return "solid";
|
|
2180
|
+
case "thickThinMediumGap": return "solid";
|
|
2181
|
+
case "thickThinSmallGap": return "solid";
|
|
2182
|
+
case "thinThickLargeGap": return "solid";
|
|
2183
|
+
case "thinThickMediumGap": return "solid";
|
|
2184
|
+
case "thinThickSmallGap": return "solid";
|
|
2185
|
+
case "thinThickThinLargeGap": return "solid";
|
|
2186
|
+
case "thinThickThinMediumGap": return "solid";
|
|
2187
|
+
case "thinThickThinSmallGap": return "solid";
|
|
2188
|
+
case "threeDEmboss": return "solid";
|
|
2189
|
+
case "threeDEngrave": return "solid";
|
|
2190
|
+
case "triple": return "double";
|
|
2191
|
+
case "wave": return "solid";
|
|
2192
|
+
}
|
|
2193
|
+
return "solid";
|
|
2194
|
+
}
|
|
2195
|
+
static valueOfTblLayout(e) {
|
|
2196
|
+
return x.attr(e, "val") == "fixed" ? "fixed" : "auto";
|
|
2197
|
+
}
|
|
2198
|
+
static classNameOfCnfStyle(e) {
|
|
2199
|
+
let t = x.attr(e, "val"), n = [
|
|
2200
|
+
"first-row",
|
|
2201
|
+
"last-row",
|
|
2202
|
+
"first-col",
|
|
2203
|
+
"last-col",
|
|
2204
|
+
"odd-col",
|
|
2205
|
+
"even-col",
|
|
2206
|
+
"odd-row",
|
|
2207
|
+
"even-row",
|
|
2208
|
+
"ne-cell",
|
|
2209
|
+
"nw-cell",
|
|
2210
|
+
"se-cell",
|
|
2211
|
+
"sw-cell"
|
|
2212
|
+
];
|
|
2213
|
+
if (t) return n.filter((e, n) => t[n] == "1").join(" ");
|
|
2214
|
+
let r = [
|
|
2215
|
+
"firstRow",
|
|
2216
|
+
"lastRow",
|
|
2217
|
+
"firstColumn",
|
|
2218
|
+
"lastColumn",
|
|
2219
|
+
"oddVBand",
|
|
2220
|
+
"evenVBand",
|
|
2221
|
+
"oddHBand",
|
|
2222
|
+
"evenHBand",
|
|
2223
|
+
"firstRowLastColumn",
|
|
2224
|
+
"firstRowFirstColumn",
|
|
2225
|
+
"lastRowLastColumn",
|
|
2226
|
+
"lastRowFirstColumn"
|
|
2227
|
+
];
|
|
2228
|
+
return n.filter((t, n) => x.boolAttr(e, r[n])).join(" ");
|
|
2229
|
+
}
|
|
2230
|
+
static valueOfJc(e) {
|
|
2231
|
+
var t = x.attr(e, "val");
|
|
2232
|
+
switch (t) {
|
|
2233
|
+
case "start":
|
|
2234
|
+
case "left": return "left";
|
|
2235
|
+
case "center": return "center";
|
|
2236
|
+
case "end":
|
|
2237
|
+
case "right": return "right";
|
|
2238
|
+
case "both": return "justify";
|
|
2239
|
+
}
|
|
2240
|
+
return t;
|
|
2241
|
+
}
|
|
2242
|
+
static valueOfVertAlign(e, t = !1) {
|
|
2243
|
+
var n = x.attr(e, "val");
|
|
2244
|
+
switch (n) {
|
|
2245
|
+
case "subscript": return "sub";
|
|
2246
|
+
case "superscript": return t ? "sup" : "super";
|
|
2247
|
+
}
|
|
2248
|
+
return t ? null : n;
|
|
2249
|
+
}
|
|
2250
|
+
static valueOfTextAlignment(e) {
|
|
2251
|
+
var t = x.attr(e, "val");
|
|
2252
|
+
switch (t) {
|
|
2253
|
+
case "auto":
|
|
2254
|
+
case "baseline": return "baseline";
|
|
2255
|
+
case "top": return "top";
|
|
2256
|
+
case "center": return "middle";
|
|
2257
|
+
case "bottom": return "bottom";
|
|
2258
|
+
}
|
|
2259
|
+
return t;
|
|
2260
|
+
}
|
|
2261
|
+
static addSize(e, t) {
|
|
2262
|
+
return e == null ? t : t == null ? e : `calc(${e} + ${t})`;
|
|
2263
|
+
}
|
|
2264
|
+
static classNameOftblLook(e) {
|
|
2265
|
+
let t = x.hexAttr(e, "val", 0), n = "";
|
|
2266
|
+
return (x.boolAttr(e, "firstRow") || t & 32) && (n += " first-row"), (x.boolAttr(e, "lastRow") || t & 64) && (n += " last-row"), (x.boolAttr(e, "firstColumn") || t & 128) && (n += " first-col"), (x.boolAttr(e, "lastColumn") || t & 256) && (n += " last-col"), (x.boolAttr(e, "noHBand") || t & 512) && (n += " no-hband"), (x.boolAttr(e, "noVBand") || t & 1024) && (n += " no-vband"), n.trim();
|
|
2267
|
+
}
|
|
2268
|
+
}, Y = {
|
|
2269
|
+
pos: 0,
|
|
2270
|
+
leader: "none",
|
|
2271
|
+
style: "left"
|
|
2272
|
+
}, ct = 50;
|
|
2273
|
+
function lt(e = document.body) {
|
|
2274
|
+
let t = document.createElement("div");
|
|
2275
|
+
t.style.width = "100pt", e.appendChild(t);
|
|
2276
|
+
let n = 100 / t.offsetWidth;
|
|
2277
|
+
return e.removeChild(t), n;
|
|
2278
|
+
}
|
|
2279
|
+
function ut(e, t, n, r = 72 / 96) {
|
|
2280
|
+
let i = e.closest("p"), a = e.getBoundingClientRect(), o = i.getBoundingClientRect(), s = getComputedStyle(i), c = t?.length > 0 ? t.map((e) => ({
|
|
2281
|
+
pos: X(e.position),
|
|
2282
|
+
leader: e.leader,
|
|
2283
|
+
style: e.style
|
|
2284
|
+
})).sort((e, t) => e.pos - t.pos) : [Y], l = c[c.length - 1], u = o.width * r, d = X(n), f = l.pos + d;
|
|
2285
|
+
if (f < u) for (; f < u && c.length < ct; f += d) c.push({
|
|
2286
|
+
...Y,
|
|
2287
|
+
pos: f
|
|
2288
|
+
});
|
|
2289
|
+
let p = parseFloat(s.marginLeft), m = o.left + p, h = (a.left - m) * r, g = c.find((e) => e.style != "clear" && e.pos > h);
|
|
2290
|
+
if (g == null) return;
|
|
2291
|
+
let _ = 1;
|
|
2292
|
+
if (g.style == "right" || g.style == "center") {
|
|
2293
|
+
let t = Array.from(i.querySelectorAll(`.${e.className}`)), n = t.indexOf(e) + 1, a = document.createRange();
|
|
2294
|
+
a.setStart(e, 1), n < t.length ? a.setEndBefore(t[n]) : a.setEndAfter(i);
|
|
2295
|
+
let s = g.style == "center" ? .5 : 1, c = a.getBoundingClientRect(), l = c.left + s * c.width - (o.left - p);
|
|
2296
|
+
_ = g.pos - l * r;
|
|
2297
|
+
} else _ = g.pos - h;
|
|
2298
|
+
switch (e.innerHTML = " ", e.style.textDecoration = "inherit", e.style.wordSpacing = `${_.toFixed(0)}pt`, g.leader) {
|
|
2299
|
+
case "dot":
|
|
2300
|
+
case "middleDot":
|
|
2301
|
+
e.style.textDecoration = "underline", e.style.textDecorationStyle = "dotted";
|
|
2302
|
+
break;
|
|
2303
|
+
case "hyphen":
|
|
2304
|
+
case "heavy":
|
|
2305
|
+
case "underscore": e.style.textDecoration = "underline";
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
function X(e) {
|
|
2309
|
+
return parseFloat(e);
|
|
2310
|
+
}
|
|
2311
|
+
var Z;
|
|
2312
|
+
(function(e) {
|
|
2313
|
+
e.html = "http://www.w3.org/1999/xhtml", e.svg = "http://www.w3.org/2000/svg", e.mathML = "http://www.w3.org/1998/Math/MathML";
|
|
2314
|
+
})(Z || (Z = {}));
|
|
2315
|
+
function Q(e) {
|
|
2316
|
+
if (f(e)) return document.createTextNode(e);
|
|
2317
|
+
if (e instanceof Node) return e;
|
|
2318
|
+
let { ns: t, tagName: n, className: r, style: i, children: a, ...o } = e;
|
|
2319
|
+
if (n === "#fragment") {
|
|
2320
|
+
let e = document.createDocumentFragment();
|
|
2321
|
+
return a && a.forEach((t) => e.appendChild(Q(t))), e;
|
|
2322
|
+
}
|
|
2323
|
+
if (n === "#comment") return document.createComment(a ? a[0] : "");
|
|
2324
|
+
let s = t ? document.createElementNS(t, n) : document.createElement(n);
|
|
2325
|
+
if (r && s.setAttribute("class", r), i && (f(i) ? s.setAttribute("style", i) : Object.assign(s.style, i)), o) for (let [e, t] of Object.entries(o)) t !== void 0 && (s[e] = t);
|
|
2326
|
+
return a && a.forEach((e) => s.appendChild(Q(e))), s;
|
|
2327
|
+
}
|
|
2328
|
+
function dt(...e) {
|
|
2329
|
+
return e.filter(Boolean).join(" ");
|
|
2330
|
+
}
|
|
2331
|
+
var ft = class {
|
|
2332
|
+
constructor() {
|
|
2333
|
+
this.className = "docx", this.styleMap = {}, this.currentPart = null, this.tableVerticalMerges = [], this.currentVerticalMerge = null, this.tableCellPositions = [], this.currentCellPosition = null, this.footnoteMap = {}, this.endnoteMap = {}, this.currentEndnoteIds = [], this.usedHederFooterParts = [], this.currentTabs = [], this.commentMap = {}, this.tasks = [], this.postRenderTasks = [], this.h = Q;
|
|
2334
|
+
}
|
|
2335
|
+
async render(e, t) {
|
|
2336
|
+
this.document = e, this.options = t, this.className = t.className, this.rootSelector = t.inWrapper ? `.${this.className}-wrapper` : ":root", this.h = t.h ?? Q, this.styleMap = null, this.tasks = [], this.options.renderComments && globalThis.Highlight && (this.commentHighlight = new Highlight());
|
|
2337
|
+
let n = [...this.renderDefaultStyle()];
|
|
2338
|
+
e.themePart && n.push(...this.renderTheme(e.themePart)), e.stylesPart != null && (this.styleMap = this.processStyles(e.stylesPart.styles), n.push(...this.renderStyles(e.stylesPart.styles))), e.numberingPart && (this.prodessNumberings(e.numberingPart.domNumberings), n.push(...await this.renderNumbering(e.numberingPart.domNumberings))), e.footnotesPart && (this.footnoteMap = l(e.footnotesPart.notes, (e) => e.id)), e.endnotesPart && (this.endnoteMap = l(e.endnotesPart.notes, (e) => e.id)), e.settingsPart && (this.defaultTabSize = e.settingsPart.settings?.defaultTabStop), !t.ignoreFonts && e.fontTablePart && n.push(...await this.renderFontTable(e.fontTablePart));
|
|
2339
|
+
var r = this.renderSections(e.documentPart.body);
|
|
2340
|
+
return this.options.inWrapper ? n.push(this.renderWrapper(r)) : n.push(...r), this.commentHighlight && t.renderComments && CSS.highlights.set(`${this.className}-comments`, this.commentHighlight), this.postRenderTasks.forEach((e) => e()), await Promise.allSettled(this.tasks), this.refreshTabStops(), n;
|
|
2341
|
+
}
|
|
2342
|
+
renderTheme(e) {
|
|
2343
|
+
let t = {}, n = e.theme?.fontScheme;
|
|
2344
|
+
n && (n.majorFont && (t["--docx-majorHAnsi-font"] = n.majorFont.latinTypeface), n.minorFont && (t["--docx-minorHAnsi-font"] = n.minorFont.latinTypeface));
|
|
2345
|
+
let r = e.theme?.colorScheme;
|
|
2346
|
+
if (r) for (let [e, n] of Object.entries(r.colors)) t[`--docx-${e}-color`] = `#${n}`;
|
|
2347
|
+
let i = this.styleToString(`.${this.className}`, t);
|
|
2348
|
+
return [this.h({
|
|
2349
|
+
tagName: "#comment",
|
|
2350
|
+
children: ["docxjs document theme values"]
|
|
2351
|
+
}), this.h({
|
|
2352
|
+
tagName: "style",
|
|
2353
|
+
children: [i]
|
|
2354
|
+
})];
|
|
2355
|
+
}
|
|
2356
|
+
async renderFontTable(e) {
|
|
2357
|
+
let t = [];
|
|
2358
|
+
for (let n of e.fonts) for (let e of n.embedFontRefs) try {
|
|
2359
|
+
let r = await this.document.loadFont(e.id, e.key), i = {
|
|
2360
|
+
"font-family": o(n.name),
|
|
2361
|
+
src: `url(${r})`
|
|
2362
|
+
};
|
|
2363
|
+
(e.type == "bold" || e.type == "boldItalic") && (i["font-weight"] = "bold"), (e.type == "italic" || e.type == "boldItalic") && (i["font-style"] = "italic"), t.push(this.h({
|
|
2364
|
+
tagName: "#comment",
|
|
2365
|
+
children: [`docxjs ${n.name} font`]
|
|
2366
|
+
})), t.push(this.h({
|
|
2367
|
+
tagName: "style",
|
|
2368
|
+
children: [this.styleToString("@font-face", i)]
|
|
2369
|
+
}));
|
|
2370
|
+
} catch {
|
|
2371
|
+
this.options.debug && console.warn(`Can't load font with id ${e.id} and key ${e.key}`);
|
|
2372
|
+
}
|
|
2373
|
+
return t;
|
|
2374
|
+
}
|
|
2375
|
+
processStyleName(e) {
|
|
2376
|
+
return e ? `${this.className}_${a(e)}` : this.className;
|
|
2377
|
+
}
|
|
2378
|
+
processStyles(e) {
|
|
2379
|
+
let t = l(e.filter((e) => e.id != null), (e) => e.id);
|
|
2380
|
+
for (let r of e.filter((e) => e.basedOn)) {
|
|
2381
|
+
var n = t[r.basedOn];
|
|
2382
|
+
if (n) {
|
|
2383
|
+
r.paragraphProps = p(r.paragraphProps, n.paragraphProps), r.runProps = p(r.runProps, n.runProps);
|
|
2384
|
+
for (let e of n.styles) {
|
|
2385
|
+
let t = r.styles.find((t) => t.target == e.target);
|
|
2386
|
+
t ? this.copyStyleProperties(e.values, t.values) : r.styles.push({
|
|
2387
|
+
...e,
|
|
2388
|
+
values: { ...e.values }
|
|
2389
|
+
});
|
|
2390
|
+
}
|
|
2391
|
+
} else this.options.debug && console.warn(`Can't find base style ${r.basedOn}`);
|
|
2392
|
+
}
|
|
2393
|
+
for (let t of e) t.cssName = this.processStyleName(t.id);
|
|
2394
|
+
return t;
|
|
2395
|
+
}
|
|
2396
|
+
prodessNumberings(e) {
|
|
2397
|
+
for (let t of e.filter((e) => e.pStyleName)) {
|
|
2398
|
+
let e = this.findStyle(t.pStyleName);
|
|
2399
|
+
e?.paragraphProps?.numbering && (e.paragraphProps.numbering.level = t.level);
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
processElement(e) {
|
|
2403
|
+
if (e.children) for (var t of e.children) t.parent = e, t.type == P.Table ? this.processTable(t) : this.processElement(t);
|
|
2404
|
+
}
|
|
2405
|
+
processTable(e) {
|
|
2406
|
+
for (var t of e.children) for (var n of t.children) n.cssStyle = this.copyStyleProperties(e.cellStyle, n.cssStyle, [
|
|
2407
|
+
"border-left",
|
|
2408
|
+
"border-right",
|
|
2409
|
+
"border-top",
|
|
2410
|
+
"border-bottom",
|
|
2411
|
+
"padding-left",
|
|
2412
|
+
"padding-right",
|
|
2413
|
+
"padding-top",
|
|
2414
|
+
"padding-bottom"
|
|
2415
|
+
]), this.processElement(n);
|
|
2416
|
+
}
|
|
2417
|
+
copyStyleProperties(e, t, n = null) {
|
|
2418
|
+
if (!e) return t;
|
|
2419
|
+
t ?? (t = {}), n ?? (n = Object.getOwnPropertyNames(e));
|
|
2420
|
+
for (var r of n) e.hasOwnProperty(r) && !t.hasOwnProperty(r) && (t[r] = e[r]);
|
|
2421
|
+
return t;
|
|
2422
|
+
}
|
|
2423
|
+
createPageElement(e, t, n) {
|
|
2424
|
+
let r = { ...n };
|
|
2425
|
+
return t && (t.pageMargins && (r.paddingLeft = t.pageMargins.left, r.paddingRight = t.pageMargins.right, r.paddingTop = t.pageMargins.top, r.paddingBottom = t.pageMargins.bottom), t.pageSize && (this.options.ignoreWidth || (r.width = t.pageSize.width), this.options.ignoreHeight || (r.minHeight = t.pageSize.height))), this.h({
|
|
2426
|
+
tagName: "section",
|
|
2427
|
+
className: e,
|
|
2428
|
+
style: r
|
|
2429
|
+
});
|
|
2430
|
+
}
|
|
2431
|
+
createSectionContent(e) {
|
|
2432
|
+
let t = {};
|
|
2433
|
+
return e.columns && e.columns.numberOfColumns && (t.columnCount = `${e.columns.numberOfColumns}`, t.columnGap = e.columns.space, e.columns.separator && (t.columnRule = "1px solid black")), this.h({
|
|
2434
|
+
tagName: "article",
|
|
2435
|
+
style: t
|
|
2436
|
+
});
|
|
2437
|
+
}
|
|
2438
|
+
renderSections(e) {
|
|
2439
|
+
let t = [];
|
|
2440
|
+
this.processElement(e);
|
|
2441
|
+
let n = this.splitBySection(e.children, e.props), r = this.groupByPageBreaks(n), i = null;
|
|
2442
|
+
for (let n = 0, o = r.length; n < o; n++) {
|
|
2443
|
+
this.currentFootnoteIds = [];
|
|
2444
|
+
let s = r[n][0].sectProps, c = this.createPageElement(this.className, s, e.cssStyle);
|
|
2445
|
+
this.options.renderHeaders && this.renderHeaderFooter(s.headerRefs, s, t.length, i != s, c);
|
|
2446
|
+
for (let e of r[n]) {
|
|
2447
|
+
var a = this.createSectionContent(e.sectProps);
|
|
2448
|
+
this.renderElements(e.elements, a), c.appendChild(a), s = e.sectProps;
|
|
2449
|
+
}
|
|
2450
|
+
if (this.options.renderFootnotes) {
|
|
2451
|
+
let e = this.renderNotes(this.currentFootnoteIds, this.footnoteMap);
|
|
2452
|
+
e && c.appendChild(e);
|
|
2453
|
+
}
|
|
2454
|
+
if (this.options.renderEndnotes && n == o - 1) {
|
|
2455
|
+
let e = this.renderNotes(this.currentEndnoteIds, this.endnoteMap);
|
|
2456
|
+
e && c.appendChild(e);
|
|
2457
|
+
}
|
|
2458
|
+
this.options.renderFooters && this.renderHeaderFooter(s.footerRefs, s, t.length, i != s, c), t.push(c), i = s;
|
|
2459
|
+
}
|
|
2460
|
+
return t;
|
|
2461
|
+
}
|
|
2462
|
+
renderHeaderFooter(e, t, n, r, i) {
|
|
2463
|
+
if (!e) return;
|
|
2464
|
+
let a = this.document.settingsPart?.settings?.evenAndOddHeaders ?? !1;
|
|
2465
|
+
var o = (t.titlePage && r ? e.find((e) => e.type == "first") : null) ?? (n % 2 == 1 && a ? e.find((e) => e.type == "even") : null) ?? e.find((e) => e.type == "default"), s = o && this.document.findPartByRelId(o.id, this.document.documentPart);
|
|
2466
|
+
if (s) {
|
|
2467
|
+
this.currentPart = s, this.usedHederFooterParts.includes(s.path) || (this.processElement(s.rootElement), this.usedHederFooterParts.push(s.path));
|
|
2468
|
+
let [e] = this.renderElements([s.rootElement], i);
|
|
2469
|
+
t?.pageMargins && (s.rootElement.type === P.Header ? (e.style.marginTop = `calc(${t.pageMargins.header} - ${t.pageMargins.top})`, e.style.minHeight = `calc(${t.pageMargins.top} - ${t.pageMargins.header})`) : s.rootElement.type === P.Footer && (e.style.marginBottom = `calc(${t.pageMargins.footer} - ${t.pageMargins.bottom})`, e.style.minHeight = `calc(${t.pageMargins.bottom} - ${t.pageMargins.footer})`)), this.currentPart = null;
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
isPageBreakElement(e) {
|
|
2473
|
+
return e.type == P.Break ? e.break == "lastRenderedPageBreak" ? !this.options.ignoreLastRenderedPageBreak : e.break == "page" : !1;
|
|
2474
|
+
}
|
|
2475
|
+
isPageBreakSection(e, t) {
|
|
2476
|
+
return !e || !t ? !1 : e.pageSize?.orientation != t.pageSize?.orientation || e.pageSize?.width != t.pageSize?.width || e.pageSize?.height != t.pageSize?.height;
|
|
2477
|
+
}
|
|
2478
|
+
splitBySection(e, t) {
|
|
2479
|
+
var n = {
|
|
2480
|
+
sectProps: null,
|
|
2481
|
+
elements: [],
|
|
2482
|
+
pageBreak: !1
|
|
2483
|
+
}, r = [n];
|
|
2484
|
+
for (let t of e) {
|
|
2485
|
+
if (t.type == P.Paragraph) {
|
|
2486
|
+
let e = t, a = this.findStyle(e.styleName);
|
|
2487
|
+
(e.pageBreakBefore || a?.paragraphProps?.pageBreakBefore) && (n.sectProps = i, n.pageBreak = !0, n = {
|
|
2488
|
+
sectProps: null,
|
|
2489
|
+
elements: [],
|
|
2490
|
+
pageBreak: !1
|
|
2491
|
+
}, r.push(n));
|
|
2492
|
+
}
|
|
2493
|
+
if (n.elements.push(t), t.type == P.Paragraph) {
|
|
2494
|
+
let e = t;
|
|
2495
|
+
var i = e.sectionProps, a = -1, o = -1;
|
|
2496
|
+
if (this.options.breakPages && e.children && (a = e.children.findIndex((e) => (o = e.children?.findIndex(this.isPageBreakElement.bind(this)) ?? -1, o != -1))), (i || a != -1) && (n.sectProps = i, n.pageBreak = a != -1, n = {
|
|
2497
|
+
sectProps: null,
|
|
2498
|
+
elements: [],
|
|
2499
|
+
pageBreak: !1
|
|
2500
|
+
}, r.push(n)), a != -1) {
|
|
2501
|
+
let r = e.children[a], i = o < r.children.length - 1;
|
|
2502
|
+
if (a < e.children.length - 1 || i) {
|
|
2503
|
+
var s = t.children, c = {
|
|
2504
|
+
...t,
|
|
2505
|
+
children: s.slice(a)
|
|
2506
|
+
};
|
|
2507
|
+
if (t.children = s.slice(0, a), n.elements.push(c), i) {
|
|
2508
|
+
let e = r.children, n = {
|
|
2509
|
+
...r,
|
|
2510
|
+
children: e.slice(0, o)
|
|
2511
|
+
};
|
|
2512
|
+
t.children.push(n), r.children = e.slice(o);
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
}
|
|
2518
|
+
let l = null;
|
|
2519
|
+
for (let e = r.length - 1; e >= 0; e--) r[e].sectProps == null ? r[e].sectProps = l ?? t : l = r[e].sectProps;
|
|
2520
|
+
return r;
|
|
2521
|
+
}
|
|
2522
|
+
groupByPageBreaks(e) {
|
|
2523
|
+
let t = [], n, r = [t];
|
|
2524
|
+
for (let i of e) t.push(i), (this.options.ignoreLastRenderedPageBreak || i.pageBreak || this.isPageBreakSection(n, i.sectProps)) && r.push(t = []), n = i.sectProps;
|
|
2525
|
+
return r.filter((e) => e.length > 0);
|
|
2526
|
+
}
|
|
2527
|
+
renderWrapper(e) {
|
|
2528
|
+
return this.h({
|
|
2529
|
+
tagName: "div",
|
|
2530
|
+
className: `${this.className}-wrapper`,
|
|
2531
|
+
children: e
|
|
2532
|
+
});
|
|
2533
|
+
}
|
|
2534
|
+
renderDefaultStyle() {
|
|
2535
|
+
var e = this.className, t = `
|
|
2536
|
+
.${e}-wrapper { background: gray; padding: 30px; padding-bottom: 0px; display: flex; flex-flow: column; align-items: center; }
|
|
2537
|
+
.${e}-wrapper>section.${e} { background: white; box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); margin-bottom: 30px; }`;
|
|
2538
|
+
this.options.hideWrapperOnPrint && (t = `@media not print { ${t} }`);
|
|
2539
|
+
var n = `${t}
|
|
2540
|
+
.${e} { color: black; hyphens: auto; text-underline-position: from-font; }
|
|
2541
|
+
section.${e} { box-sizing: border-box; display: flex; flex-flow: column nowrap; position: relative; overflow: hidden; }
|
|
2542
|
+
section.${e}>article { margin-bottom: auto; z-index: 1; }
|
|
2543
|
+
section.${e}>footer { z-index: 1; }
|
|
2544
|
+
.${e} table { border-collapse: collapse; }
|
|
2545
|
+
.${e} table td, .${e} table th { vertical-align: top; }
|
|
2546
|
+
.${e} p { margin: 0pt; min-height: 1em; }
|
|
2547
|
+
.${e} span { white-space: pre-wrap; overflow-wrap: break-word; }
|
|
2548
|
+
.${e} a { color: inherit; text-decoration: inherit; }
|
|
2549
|
+
.${e} svg { fill: transparent; }
|
|
2550
|
+
`;
|
|
2551
|
+
return this.options.renderComments && (n += `
|
|
2552
|
+
.${e}-comment-ref { cursor: default; }
|
|
2553
|
+
.${e}-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; }
|
|
2554
|
+
.${e}-comment-ref:hover~.${e}-comment-popover { display: block; }
|
|
2555
|
+
.${e}-comment-author,.${e}-comment-date { font-size: 0.875rem; color: #888; }
|
|
2556
|
+
`), [this.h({
|
|
2557
|
+
tagName: "#comment",
|
|
2558
|
+
children: ["docxjs library predefined styles"]
|
|
2559
|
+
}), this.h({
|
|
2560
|
+
tagName: "style",
|
|
2561
|
+
children: [n]
|
|
2562
|
+
})];
|
|
2563
|
+
}
|
|
2564
|
+
async renderNumbering(e) {
|
|
2565
|
+
var t = "", n = [];
|
|
2566
|
+
for (var r of e) {
|
|
2567
|
+
var i = `p.${this.numberingClass(r.id, r.level)}`, a = "none";
|
|
2568
|
+
if (r.bullet) {
|
|
2569
|
+
let e = `--${this.className}-${r.bullet.src}`.toLowerCase();
|
|
2570
|
+
t += this.styleToString(`${i}:before`, {
|
|
2571
|
+
content: "' '",
|
|
2572
|
+
display: "inline-block",
|
|
2573
|
+
background: `var(${e})`
|
|
2574
|
+
}, r.bullet.style);
|
|
2575
|
+
try {
|
|
2576
|
+
let n = await this.document.loadNumberingImage(r.bullet.src);
|
|
2577
|
+
t += `${this.rootSelector} { ${e}: url(${n}) }`;
|
|
2578
|
+
} catch {
|
|
2579
|
+
this.options.debug && console.warn(`Can't load numbering image with src ${r.bullet.src}`);
|
|
2580
|
+
}
|
|
2581
|
+
} else if (r.levelText) {
|
|
2582
|
+
let e = this.numberingCounter(r.id, r.level), a = e + " " + (r.start - 1);
|
|
2583
|
+
r.level > 0 && (t += this.styleToString(`p.${this.numberingClass(r.id, r.level - 1)}`, { "counter-set": a })), n.push(a), t += this.styleToString(`${i}:before`, {
|
|
2584
|
+
content: this.levelTextToContent(r.levelText, r.suff, r.id, this.numFormatToCssValue(r.format)),
|
|
2585
|
+
"counter-increment": e,
|
|
2586
|
+
...r.rStyle
|
|
2587
|
+
});
|
|
2588
|
+
} else a = this.numFormatToCssValue(r.format);
|
|
2589
|
+
t += this.styleToString(i, {
|
|
2590
|
+
display: "list-item",
|
|
2591
|
+
"list-style-position": "inside",
|
|
2592
|
+
"list-style-type": a,
|
|
2593
|
+
...r.pStyle
|
|
2594
|
+
});
|
|
2595
|
+
}
|
|
2596
|
+
return n.length > 0 && (t += this.styleToString(this.rootSelector, { "counter-reset": n.join(" ") })), [this.h({
|
|
2597
|
+
tagName: "#comment",
|
|
2598
|
+
children: ["docxjs document numbering styles"]
|
|
2599
|
+
}), this.h({
|
|
2600
|
+
tagName: "style",
|
|
2601
|
+
children: [t]
|
|
2602
|
+
})];
|
|
2603
|
+
}
|
|
2604
|
+
renderStyles(e) {
|
|
2605
|
+
var t = "";
|
|
2606
|
+
let n = this.styleMap, r = l(e.filter((e) => e.isDefault), (e) => e.target);
|
|
2607
|
+
for (let s of e) {
|
|
2608
|
+
var i = s.styles;
|
|
2609
|
+
if (s.linked) {
|
|
2610
|
+
var a = s.linked && n[s.linked];
|
|
2611
|
+
a ? i = i.concat(a.styles) : this.options.debug && console.warn(`Can't find linked style ${s.linked}`);
|
|
2612
|
+
}
|
|
2613
|
+
for (let e of i) {
|
|
2614
|
+
var o = `${s.target ?? ""}.${s.cssName}`;
|
|
2615
|
+
s.target != e.target && (o += ` ${e.target}`), r[s.target] == s && (o = `.${this.className} ${s.target}, ` + o), t += this.styleToString(o, e.values);
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
return [this.h({
|
|
2619
|
+
tagName: "#comment",
|
|
2620
|
+
children: ["docxjs document styles"]
|
|
2621
|
+
}), this.h({
|
|
2622
|
+
tagName: "style",
|
|
2623
|
+
children: [t]
|
|
2624
|
+
})];
|
|
2625
|
+
}
|
|
2626
|
+
renderNotes(e, t) {
|
|
2627
|
+
var n = e.map((e) => t[e]).filter((e) => e);
|
|
2628
|
+
if (n.length > 0) return this.h({
|
|
2629
|
+
tagName: "ol",
|
|
2630
|
+
children: this.renderElements(n)
|
|
2631
|
+
});
|
|
2632
|
+
}
|
|
2633
|
+
renderElement(e) {
|
|
2634
|
+
switch (e.type) {
|
|
2635
|
+
case P.Paragraph: return this.renderParagraph(e);
|
|
2636
|
+
case P.BookmarkStart: return this.renderBookmarkStart(e);
|
|
2637
|
+
case P.BookmarkEnd: return null;
|
|
2638
|
+
case P.Run: return this.renderRun(e);
|
|
2639
|
+
case P.Table: return this.renderTable(e);
|
|
2640
|
+
case P.Row: return this.renderTableRow(e);
|
|
2641
|
+
case P.Cell: return this.renderTableCell(e);
|
|
2642
|
+
case P.Hyperlink: return this.renderHyperlink(e);
|
|
2643
|
+
case P.SmartTag: return this.renderSmartTag(e);
|
|
2644
|
+
case P.Drawing: return this.renderDrawing(e);
|
|
2645
|
+
case P.Image: return this.renderImage(e);
|
|
2646
|
+
case P.Text: return this.renderText(e);
|
|
2647
|
+
case P.Text: return this.renderText(e);
|
|
2648
|
+
case P.DeletedText: return this.renderDeletedText(e);
|
|
2649
|
+
case P.Tab: return this.renderTab(e);
|
|
2650
|
+
case P.Symbol: return this.renderSymbol(e);
|
|
2651
|
+
case P.Break: return this.renderBreak(e);
|
|
2652
|
+
case P.Footer: return this.renderContainer(e, "footer");
|
|
2653
|
+
case P.Header: return this.renderContainer(e, "header");
|
|
2654
|
+
case P.Footnote:
|
|
2655
|
+
case P.Endnote: return this.renderContainer(e, "li");
|
|
2656
|
+
case P.FootnoteReference: return this.renderFootnoteReference(e);
|
|
2657
|
+
case P.EndnoteReference: return this.renderEndnoteReference(e);
|
|
2658
|
+
case P.NoBreakHyphen: return this.h({ tagName: "wbr" });
|
|
2659
|
+
case P.VmlPicture: return this.renderVmlPicture(e);
|
|
2660
|
+
case P.VmlElement: return this.renderVmlElement(e);
|
|
2661
|
+
case P.MmlMath: return this.renderContainerNS(e, Z.mathML, "math", { xmlns: Z.mathML });
|
|
2662
|
+
case P.MmlMathParagraph: return this.renderContainer(e, "span");
|
|
2663
|
+
case P.MmlFraction: return this.renderContainerNS(e, Z.mathML, "mfrac");
|
|
2664
|
+
case P.MmlBase: return this.renderContainerNS(e, Z.mathML, e.parent.type == P.MmlMatrixRow ? "mtd" : "mrow");
|
|
2665
|
+
case P.MmlNumerator:
|
|
2666
|
+
case P.MmlDenominator:
|
|
2667
|
+
case P.MmlFunction:
|
|
2668
|
+
case P.MmlLimit:
|
|
2669
|
+
case P.MmlBox: return this.renderContainerNS(e, Z.mathML, "mrow");
|
|
2670
|
+
case P.MmlGroupChar: return this.renderMmlGroupChar(e);
|
|
2671
|
+
case P.MmlLimitLower: return this.renderContainerNS(e, Z.mathML, "munder");
|
|
2672
|
+
case P.MmlMatrix: return this.renderContainerNS(e, Z.mathML, "mtable");
|
|
2673
|
+
case P.MmlMatrixRow: return this.renderContainerNS(e, Z.mathML, "mtr");
|
|
2674
|
+
case P.MmlRadical: return this.renderMmlRadical(e);
|
|
2675
|
+
case P.MmlSuperscript: return this.renderContainerNS(e, Z.mathML, "msup");
|
|
2676
|
+
case P.MmlSubscript: return this.renderContainerNS(e, Z.mathML, "msub");
|
|
2677
|
+
case P.MmlDegree:
|
|
2678
|
+
case P.MmlSuperArgument:
|
|
2679
|
+
case P.MmlSubArgument: return this.renderContainerNS(e, Z.mathML, "mn");
|
|
2680
|
+
case P.MmlFunctionName: return this.renderContainerNS(e, Z.mathML, "ms");
|
|
2681
|
+
case P.MmlDelimiter: return this.renderMmlDelimiter(e);
|
|
2682
|
+
case P.MmlRun: return this.renderMmlRun(e);
|
|
2683
|
+
case P.MmlNary: return this.renderMmlNary(e);
|
|
2684
|
+
case P.MmlPreSubSuper: return this.renderMmlPreSubSuper(e);
|
|
2685
|
+
case P.MmlBar: return this.renderMmlBar(e);
|
|
2686
|
+
case P.MmlEquationArray: return this.renderMllList(e);
|
|
2687
|
+
case P.Inserted: return this.renderInserted(e);
|
|
2688
|
+
case P.Deleted: return this.renderDeleted(e);
|
|
2689
|
+
case P.CommentRangeStart: return this.renderCommentRangeStart(e);
|
|
2690
|
+
case P.CommentRangeEnd: return this.renderCommentRangeEnd(e);
|
|
2691
|
+
case P.CommentReference: return this.renderCommentReference(e);
|
|
2692
|
+
case P.AltChunk: return this.renderAltChunk(e);
|
|
2693
|
+
}
|
|
2694
|
+
return null;
|
|
2695
|
+
}
|
|
2696
|
+
renderElements(e, t) {
|
|
2697
|
+
if (e == null) return null;
|
|
2698
|
+
var n = e.flatMap((e) => this.renderElement(e)).filter((e) => e != null);
|
|
2699
|
+
return t && n.forEach((e) => t.appendChild(f(e) ? document.createTextNode(e) : e)), n;
|
|
2700
|
+
}
|
|
2701
|
+
renderContainer(e, t, n) {
|
|
2702
|
+
return this.h({
|
|
2703
|
+
tagName: t,
|
|
2704
|
+
children: this.renderElements(e.children),
|
|
2705
|
+
...n
|
|
2706
|
+
});
|
|
2707
|
+
}
|
|
2708
|
+
renderContainerNS(e, t, n, r) {
|
|
2709
|
+
return this.h({
|
|
2710
|
+
ns: t,
|
|
2711
|
+
tagName: n,
|
|
2712
|
+
children: this.renderElements(e.children),
|
|
2713
|
+
...r
|
|
2714
|
+
});
|
|
2715
|
+
}
|
|
2716
|
+
renderParagraph(e) {
|
|
2717
|
+
var t = this.toHTML(e, Z.html, "p");
|
|
2718
|
+
let n = this.findStyle(e.styleName);
|
|
2719
|
+
e.tabs ?? (e.tabs = n?.paragraphProps?.tabs);
|
|
2720
|
+
let r = e.numbering ?? n?.paragraphProps?.numbering;
|
|
2721
|
+
return r && t.classList.add(this.numberingClass(r.id, r.level)), t;
|
|
2722
|
+
}
|
|
2723
|
+
renderHyperlink(e) {
|
|
2724
|
+
let t = this.toH(e, Z.html, "a");
|
|
2725
|
+
return t.href = "", e.id && (t.href = this.document.documentPart.rels.find((t) => t.id == e.id && t.targetMode === "External")?.target ?? t.href), e.anchor && (t.href += `#${e.anchor}`), this.h(t);
|
|
2726
|
+
}
|
|
2727
|
+
renderSmartTag(e) {
|
|
2728
|
+
return this.renderContainer(e, "span");
|
|
2729
|
+
}
|
|
2730
|
+
renderCommentRangeStart(e) {
|
|
2731
|
+
if (!this.options.renderComments) return null;
|
|
2732
|
+
let t = new Range();
|
|
2733
|
+
this.commentHighlight?.add(t);
|
|
2734
|
+
let n = this.h({
|
|
2735
|
+
tagName: "#comment",
|
|
2736
|
+
children: [`start of comment #${e.id}`]
|
|
2737
|
+
});
|
|
2738
|
+
return this.later(() => t.setStart(n, 0)), this.commentMap[e.id] = t, n;
|
|
2739
|
+
}
|
|
2740
|
+
renderCommentRangeEnd(e) {
|
|
2741
|
+
if (!this.options.renderComments) return null;
|
|
2742
|
+
let t = this.commentMap[e.id], n = this.h({
|
|
2743
|
+
tagName: "#comment",
|
|
2744
|
+
children: [`end of comment #${e.id}`]
|
|
2745
|
+
});
|
|
2746
|
+
return this.later(() => t?.setEnd(n, 0)), n;
|
|
2747
|
+
}
|
|
2748
|
+
renderCommentReference(e) {
|
|
2749
|
+
if (!this.options.renderComments) return null;
|
|
2750
|
+
var t = this.document.commentsPart?.commentMap[e.id];
|
|
2751
|
+
if (!t) return null;
|
|
2752
|
+
let n = this.h({
|
|
2753
|
+
tagName: "span",
|
|
2754
|
+
className: `${this.className}-comment-ref`,
|
|
2755
|
+
children: ["💬"]
|
|
2756
|
+
}), r = this.h({
|
|
2757
|
+
tagName: "div",
|
|
2758
|
+
className: `${this.className}-comment-popover`,
|
|
2759
|
+
children: [
|
|
2760
|
+
this.h({
|
|
2761
|
+
tagName: "div",
|
|
2762
|
+
className: `${this.className}-comment-author`,
|
|
2763
|
+
children: [t.author]
|
|
2764
|
+
}),
|
|
2765
|
+
this.h({
|
|
2766
|
+
tagName: "div",
|
|
2767
|
+
className: `${this.className}-comment-date`,
|
|
2768
|
+
children: [new Date(t.date).toLocaleString()]
|
|
2769
|
+
}),
|
|
2770
|
+
...this.renderElements(t.children)
|
|
2771
|
+
]
|
|
2772
|
+
});
|
|
2773
|
+
return this.h({
|
|
2774
|
+
tagName: "#fragment",
|
|
2775
|
+
children: [
|
|
2776
|
+
this.h({
|
|
2777
|
+
tagName: "#comment",
|
|
2778
|
+
children: [`comment #${t.id} by ${t.author} on ${t.date}`]
|
|
2779
|
+
}),
|
|
2780
|
+
n,
|
|
2781
|
+
r
|
|
2782
|
+
]
|
|
2783
|
+
});
|
|
2784
|
+
}
|
|
2785
|
+
renderAltChunk(e) {
|
|
2786
|
+
if (!this.options.renderAltChunks) return null;
|
|
2787
|
+
var t = this.h({ tagName: "iframe" });
|
|
2788
|
+
return this.tasks.push(this.document.loadAltChunk(e.id, this.currentPart).then((e) => {
|
|
2789
|
+
t.srcdoc = e;
|
|
2790
|
+
})), t;
|
|
2791
|
+
}
|
|
2792
|
+
renderDrawing(e) {
|
|
2793
|
+
var t = this.toHTML(e, Z.html, "div");
|
|
2794
|
+
return t.style.display = "inline-block", t.style.position = "relative", t.style.textIndent = "0px", t;
|
|
2795
|
+
}
|
|
2796
|
+
renderImage(e) {
|
|
2797
|
+
let t = this.toHTML(e, Z.html, "img", []), n = e.cssStyle?.transform;
|
|
2798
|
+
if (e.srcRect && e.srcRect.some((e) => e != 0)) {
|
|
2799
|
+
var [r, i, a, o] = e.srcRect;
|
|
2800
|
+
n = `scale(${1 / (1 - r - a)}, ${1 / (1 - i - o)})`, t.style["clip-path"] = `rect(${(100 * i).toFixed(2)}% ${(100 * (1 - a)).toFixed(2)}% ${(100 * (1 - o)).toFixed(2)}% ${(100 * r).toFixed(2)}%)`;
|
|
2801
|
+
}
|
|
2802
|
+
return e.rotation && (n = `rotate(${e.rotation}deg) ${n ?? ""}`), t.style.transform = n?.trim(), this.document && this.tasks.push(this.document.loadDocumentImage(e.src, this.currentPart).then((e) => {
|
|
2803
|
+
t.src = e;
|
|
2804
|
+
})), t;
|
|
2805
|
+
}
|
|
2806
|
+
renderText(e) {
|
|
2807
|
+
return this.h(e.text);
|
|
2808
|
+
}
|
|
2809
|
+
renderDeletedText(e) {
|
|
2810
|
+
return this.options.renderChanges ? this.renderText(e) : null;
|
|
2811
|
+
}
|
|
2812
|
+
renderBreak(e) {
|
|
2813
|
+
return e.break == "textWrapping" ? this.h({ tagName: "br" }) : null;
|
|
2814
|
+
}
|
|
2815
|
+
renderInserted(e) {
|
|
2816
|
+
return this.options.renderChanges ? this.renderChange(e, "ins") : this.renderElements(e.children);
|
|
2817
|
+
}
|
|
2818
|
+
renderDeleted(e) {
|
|
2819
|
+
return this.options.renderChanges ? this.renderChange(e, "del") : null;
|
|
2820
|
+
}
|
|
2821
|
+
renderChange(e, t) {
|
|
2822
|
+
return this.renderContainer(e, t, { dateTime: e.date });
|
|
2823
|
+
}
|
|
2824
|
+
renderSymbol(e) {
|
|
2825
|
+
return this.h({
|
|
2826
|
+
tagName: "span",
|
|
2827
|
+
children: [String.fromCharCode(e.char)],
|
|
2828
|
+
style: { fontFamily: e.font }
|
|
2829
|
+
});
|
|
2830
|
+
}
|
|
2831
|
+
renderFootnoteReference(e) {
|
|
2832
|
+
return this.currentFootnoteIds.push(e.id), this.h({
|
|
2833
|
+
tagName: "sup",
|
|
2834
|
+
children: [`${this.currentFootnoteIds.length}`]
|
|
2835
|
+
});
|
|
2836
|
+
}
|
|
2837
|
+
renderEndnoteReference(e) {
|
|
2838
|
+
return this.currentEndnoteIds.push(e.id), this.h({
|
|
2839
|
+
tagName: "sup",
|
|
2840
|
+
children: [`${this.currentEndnoteIds.length}`]
|
|
2841
|
+
});
|
|
2842
|
+
}
|
|
2843
|
+
renderTab(e) {
|
|
2844
|
+
var t = this.h({
|
|
2845
|
+
tagName: "span",
|
|
2846
|
+
children: [" "]
|
|
2847
|
+
});
|
|
2848
|
+
if (this.options.experimental) {
|
|
2849
|
+
t.className = this.tabStopClass();
|
|
2850
|
+
var n = pt(e, P.Paragraph)?.tabs;
|
|
2851
|
+
this.currentTabs.push({
|
|
2852
|
+
stops: n,
|
|
2853
|
+
span: t
|
|
2854
|
+
});
|
|
2855
|
+
}
|
|
2856
|
+
return t;
|
|
2857
|
+
}
|
|
2858
|
+
renderBookmarkStart(e) {
|
|
2859
|
+
return this.h({
|
|
2860
|
+
tagName: "span",
|
|
2861
|
+
id: e.name
|
|
2862
|
+
});
|
|
2863
|
+
}
|
|
2864
|
+
renderRun(e) {
|
|
2865
|
+
if (e.fieldRun) return null;
|
|
2866
|
+
let t = this.renderElements(e.children);
|
|
2867
|
+
e.verticalAlign && (t = [this.h({
|
|
2868
|
+
tagName: e.verticalAlign,
|
|
2869
|
+
children: this.renderElements(e.children)
|
|
2870
|
+
})]);
|
|
2871
|
+
let n = this.toHTML(e, Z.html, "span", t);
|
|
2872
|
+
return e.id && (n.id = e.id), n;
|
|
2873
|
+
}
|
|
2874
|
+
renderTable(e) {
|
|
2875
|
+
this.tableCellPositions.push(this.currentCellPosition), this.tableVerticalMerges.push(this.currentVerticalMerge), this.currentVerticalMerge = {}, this.currentCellPosition = {
|
|
2876
|
+
col: 0,
|
|
2877
|
+
row: 0
|
|
2878
|
+
};
|
|
2879
|
+
let t = [];
|
|
2880
|
+
return e.columns && t.push(this.renderTableColumns(e.columns)), t.push(...this.renderElements(e.children)), this.currentVerticalMerge = this.tableVerticalMerges.pop(), this.currentCellPosition = this.tableCellPositions.pop(), this.toHTML(e, Z.html, "table", t);
|
|
2881
|
+
}
|
|
2882
|
+
renderTableColumns(e) {
|
|
2883
|
+
let t = e.map((e) => this.h({
|
|
2884
|
+
tagName: "col",
|
|
2885
|
+
style: { width: e.width }
|
|
2886
|
+
}));
|
|
2887
|
+
return this.h({
|
|
2888
|
+
tagName: "colgroup",
|
|
2889
|
+
children: t
|
|
2890
|
+
});
|
|
2891
|
+
}
|
|
2892
|
+
renderTableRow(e) {
|
|
2893
|
+
this.currentCellPosition.col = 0;
|
|
2894
|
+
let t = [];
|
|
2895
|
+
return e.gridBefore && t.push(this.renderTableCellPlaceholder(e.gridBefore)), t.push(...this.renderElements(e.children)), e.gridAfter && t.push(this.renderTableCellPlaceholder(e.gridAfter)), this.currentCellPosition.row++, this.toHTML(e, Z.html, "tr", t);
|
|
2896
|
+
}
|
|
2897
|
+
renderTableCellPlaceholder(e) {
|
|
2898
|
+
return this.h({
|
|
2899
|
+
tagName: "td",
|
|
2900
|
+
colSpan: e,
|
|
2901
|
+
style: { border: "none" }
|
|
2902
|
+
});
|
|
2903
|
+
}
|
|
2904
|
+
renderTableCell(e) {
|
|
2905
|
+
let t = this.toHTML(e, Z.html, "td"), n = this.currentCellPosition.col;
|
|
2906
|
+
return e.verticalMerge ? e.verticalMerge == "restart" ? (this.currentVerticalMerge[n] = t, t.rowSpan = 1) : this.currentVerticalMerge[n] && (this.currentVerticalMerge[n].rowSpan += 1, t.style.display = "none") : this.currentVerticalMerge[n] = null, e.span && (t.colSpan = e.span), this.currentCellPosition.col += t.colSpan, t;
|
|
2907
|
+
}
|
|
2908
|
+
renderVmlPicture(e) {
|
|
2909
|
+
return this.renderContainer(e, "div");
|
|
2910
|
+
}
|
|
2911
|
+
renderVmlElement(e) {
|
|
2912
|
+
var t = this.h({
|
|
2913
|
+
ns: Z.svg,
|
|
2914
|
+
tagName: "svg",
|
|
2915
|
+
style: e.cssStyleText
|
|
2916
|
+
});
|
|
2917
|
+
let n = this.renderVmlChildElement(e);
|
|
2918
|
+
return e.imageHref?.id && this.tasks.push(this.document?.loadDocumentImage(e.imageHref.id, this.currentPart).then((e) => n.setAttribute("href", e))), t.appendChild(n), requestAnimationFrame(() => {
|
|
2919
|
+
let e = t.firstElementChild.getBBox();
|
|
2920
|
+
t.setAttribute("width", `${Math.ceil(e.x + e.width)}`), t.setAttribute("height", `${Math.ceil(e.y + e.height)}`);
|
|
2921
|
+
}), t;
|
|
2922
|
+
}
|
|
2923
|
+
renderVmlChildElement(e) {
|
|
2924
|
+
let t = this.createSvgElement(e.tagName);
|
|
2925
|
+
Object.entries(e.attrs).forEach(([e, n]) => t.setAttribute(e, n));
|
|
2926
|
+
for (let n of e.children) n.type == P.VmlElement ? t.appendChild(this.renderVmlChildElement(n)) : t.appendChild(...m(this.renderElement(n)));
|
|
2927
|
+
return t;
|
|
2928
|
+
}
|
|
2929
|
+
renderMmlRadical(e) {
|
|
2930
|
+
let t = e.children.find((e) => e.type == P.MmlBase);
|
|
2931
|
+
if (e.props?.hideDegree) return this.createMathMLElement("msqrt", null, this.renderElements([t]));
|
|
2932
|
+
let n = e.children.find((e) => e.type == P.MmlDegree);
|
|
2933
|
+
return this.createMathMLElement("mroot", null, this.renderElements([t, n]));
|
|
2934
|
+
}
|
|
2935
|
+
renderMmlDelimiter(e) {
|
|
2936
|
+
let t = [];
|
|
2937
|
+
return t.push(this.createMathMLElement("mo", null, [e.props.beginChar ?? "("])), t.push(...this.renderElements(e.children)), t.push(this.createMathMLElement("mo", null, [e.props.endChar ?? ")"])), this.createMathMLElement("mrow", null, t);
|
|
2938
|
+
}
|
|
2939
|
+
renderMmlNary(e) {
|
|
2940
|
+
let t = [], n = l(e.children, (e) => e.type), r = n[P.MmlSuperArgument], i = n[P.MmlSubArgument], a = r ? this.createMathMLElement("mo", null, m(this.renderElement(r))) : null, o = i ? this.createMathMLElement("mo", null, m(this.renderElement(i))) : null, s = this.createMathMLElement("mo", null, [e.props?.char ?? "∫"]);
|
|
2941
|
+
return a || o ? t.push(this.createMathMLElement("munderover", null, [
|
|
2942
|
+
s,
|
|
2943
|
+
o,
|
|
2944
|
+
a
|
|
2945
|
+
])) : a ? t.push(this.createMathMLElement("mover", null, [s, a])) : o ? t.push(this.createMathMLElement("munder", null, [s, o])) : t.push(s), t.push(...this.renderElements(n[P.MmlBase].children)), this.createMathMLElement("mrow", null, t);
|
|
2946
|
+
}
|
|
2947
|
+
renderMmlPreSubSuper(e) {
|
|
2948
|
+
let t = [], n = l(e.children, (e) => e.type), r = n[P.MmlSuperArgument], i = n[P.MmlSubArgument], a = r ? this.createMathMLElement("mo", null, m(this.renderElement(r))) : null, o = i ? this.createMathMLElement("mo", null, m(this.renderElement(i))) : null, s = this.createMathMLElement("mo", null);
|
|
2949
|
+
return t.push(this.createMathMLElement("msubsup", null, [
|
|
2950
|
+
s,
|
|
2951
|
+
o,
|
|
2952
|
+
a
|
|
2953
|
+
])), t.push(...this.renderElements(n[P.MmlBase].children)), this.createMathMLElement("mrow", null, t);
|
|
2954
|
+
}
|
|
2955
|
+
renderMmlGroupChar(e) {
|
|
2956
|
+
let t = e.props.verticalJustification === "bot" ? "mover" : "munder", n = this.renderContainerNS(e, Z.mathML, t);
|
|
2957
|
+
return e.props.char && n.appendChild(this.createMathMLElement("mo", null, [e.props.char])), n;
|
|
2958
|
+
}
|
|
2959
|
+
renderMmlBar(e) {
|
|
2960
|
+
let t = {};
|
|
2961
|
+
switch (e.props.position) {
|
|
2962
|
+
case "top":
|
|
2963
|
+
t.textDecoration = "overline";
|
|
2964
|
+
break;
|
|
2965
|
+
case "bottom": t.textDecoration = "underline";
|
|
2966
|
+
}
|
|
2967
|
+
return this.renderContainerNS(e, Z.mathML, "mrow", { style: t });
|
|
2968
|
+
}
|
|
2969
|
+
renderMmlRun(e) {
|
|
2970
|
+
return this.toHTML(e, Z.mathML, "ms");
|
|
2971
|
+
}
|
|
2972
|
+
renderMllList(e) {
|
|
2973
|
+
let t = this.renderElements(e.children).map((e) => this.createMathMLElement("mtr", null, [this.createMathMLElement("mtd", null, [e])]));
|
|
2974
|
+
return this.toHTML(e, Z.mathML, "mtable", t);
|
|
2975
|
+
}
|
|
2976
|
+
toH(e, t, n, r = null) {
|
|
2977
|
+
let { $lang: i, ...a } = e.cssStyle ?? {};
|
|
2978
|
+
return {
|
|
2979
|
+
ns: t,
|
|
2980
|
+
tagName: n,
|
|
2981
|
+
className: dt(e.className, e.styleName && this.processStyleName(e.styleName)),
|
|
2982
|
+
lang: i,
|
|
2983
|
+
style: a,
|
|
2984
|
+
children: r ?? this.renderElements(e.children)
|
|
2985
|
+
};
|
|
2986
|
+
}
|
|
2987
|
+
toHTML(e, t, n, r = null) {
|
|
2988
|
+
return this.h(this.toH(e, t, n, r));
|
|
2989
|
+
}
|
|
2990
|
+
findStyle(e) {
|
|
2991
|
+
return e && this.styleMap?.[e];
|
|
2992
|
+
}
|
|
2993
|
+
numberingClass(e, t) {
|
|
2994
|
+
return `${this.className}-num-${e}-${t}`;
|
|
2995
|
+
}
|
|
2996
|
+
tabStopClass() {
|
|
2997
|
+
return `${this.className}-tab-stop`;
|
|
2998
|
+
}
|
|
2999
|
+
styleToString(e, t, n = null) {
|
|
3000
|
+
let r = `${e} {\r\n`;
|
|
3001
|
+
for (let e in t) e.startsWith("$") || (r += ` ${e}: ${t[e]};\r\n`);
|
|
3002
|
+
return n && (r += n), r + "}\r\n";
|
|
3003
|
+
}
|
|
3004
|
+
numberingCounter(e, t) {
|
|
3005
|
+
return `${this.className}-num-${e}-${t}`;
|
|
3006
|
+
}
|
|
3007
|
+
levelTextToContent(e, t, n, r) {
|
|
3008
|
+
return `"${e.replace(/%\d*/g, (e) => {
|
|
3009
|
+
let t = parseInt(e.substring(1), 10) - 1;
|
|
3010
|
+
return `"counter(${this.numberingCounter(n, t)}, ${r})"`;
|
|
3011
|
+
})}${{
|
|
3012
|
+
tab: "\\9",
|
|
3013
|
+
space: "\\a0"
|
|
3014
|
+
}[t] ?? ""}"`;
|
|
3015
|
+
}
|
|
3016
|
+
numFormatToCssValue(e) {
|
|
3017
|
+
return {
|
|
3018
|
+
none: "none",
|
|
3019
|
+
bullet: "disc",
|
|
3020
|
+
decimal: "decimal",
|
|
3021
|
+
lowerLetter: "lower-alpha",
|
|
3022
|
+
upperLetter: "upper-alpha",
|
|
3023
|
+
lowerRoman: "lower-roman",
|
|
3024
|
+
upperRoman: "upper-roman",
|
|
3025
|
+
decimalZero: "decimal-leading-zero",
|
|
3026
|
+
aiueo: "katakana",
|
|
3027
|
+
aiueoFullWidth: "katakana",
|
|
3028
|
+
chineseCounting: "simp-chinese-informal",
|
|
3029
|
+
chineseCountingThousand: "simp-chinese-informal",
|
|
3030
|
+
chineseLegalSimplified: "simp-chinese-formal",
|
|
3031
|
+
chosung: "hangul-consonant",
|
|
3032
|
+
ideographDigital: "cjk-ideographic",
|
|
3033
|
+
ideographTraditional: "cjk-heavenly-stem",
|
|
3034
|
+
ideographLegalTraditional: "trad-chinese-formal",
|
|
3035
|
+
ideographZodiac: "cjk-earthly-branch",
|
|
3036
|
+
iroha: "katakana-iroha",
|
|
3037
|
+
irohaFullWidth: "katakana-iroha",
|
|
3038
|
+
japaneseCounting: "japanese-informal",
|
|
3039
|
+
japaneseDigitalTenThousand: "cjk-decimal",
|
|
3040
|
+
japaneseLegal: "japanese-formal",
|
|
3041
|
+
thaiNumbers: "thai",
|
|
3042
|
+
koreanCounting: "korean-hangul-formal",
|
|
3043
|
+
koreanDigital: "korean-hangul-formal",
|
|
3044
|
+
koreanDigital2: "korean-hanja-informal",
|
|
3045
|
+
hebrew1: "hebrew",
|
|
3046
|
+
hebrew2: "hebrew",
|
|
3047
|
+
hindiNumbers: "devanagari",
|
|
3048
|
+
ganada: "hangul",
|
|
3049
|
+
taiwaneseCounting: "cjk-ideographic",
|
|
3050
|
+
taiwaneseCountingThousand: "cjk-ideographic",
|
|
3051
|
+
taiwaneseDigital: "cjk-decimal"
|
|
3052
|
+
}[e] ?? e;
|
|
3053
|
+
}
|
|
3054
|
+
refreshTabStops() {
|
|
3055
|
+
this.options.experimental && setTimeout(() => {
|
|
3056
|
+
let e = lt();
|
|
3057
|
+
for (let t of this.currentTabs) ut(t.span, t.stops, this.defaultTabSize, e);
|
|
3058
|
+
}, 500);
|
|
3059
|
+
}
|
|
3060
|
+
createElementNS(e, t, n, r) {
|
|
3061
|
+
return this.h({
|
|
3062
|
+
ns: e,
|
|
3063
|
+
tagName: t,
|
|
3064
|
+
children: r,
|
|
3065
|
+
...n
|
|
3066
|
+
});
|
|
3067
|
+
}
|
|
3068
|
+
createElement(e, t, n) {
|
|
3069
|
+
return this.createElementNS(Z.html, e, t, n);
|
|
3070
|
+
}
|
|
3071
|
+
createMathMLElement(e, t, n) {
|
|
3072
|
+
return this.createElementNS(Z.mathML, e, t, n);
|
|
3073
|
+
}
|
|
3074
|
+
createSvgElement(e, t, n) {
|
|
3075
|
+
return this.createElementNS(Z.svg, e, t, n);
|
|
3076
|
+
}
|
|
3077
|
+
later(e) {
|
|
3078
|
+
this.postRenderTasks.push(e);
|
|
3079
|
+
}
|
|
3080
|
+
};
|
|
3081
|
+
function pt(e, t) {
|
|
3082
|
+
for (var n = e.parent; n != null && n.type != t;) n = n.parent;
|
|
3083
|
+
return n;
|
|
3084
|
+
}
|
|
3085
|
+
var $ = {
|
|
3086
|
+
ignoreHeight: !1,
|
|
3087
|
+
ignoreWidth: !1,
|
|
3088
|
+
ignoreFonts: !1,
|
|
3089
|
+
breakPages: !0,
|
|
3090
|
+
debug: !1,
|
|
3091
|
+
experimental: !1,
|
|
3092
|
+
className: "docx",
|
|
3093
|
+
inWrapper: !0,
|
|
3094
|
+
hideWrapperOnPrint: !1,
|
|
3095
|
+
trimXmlDeclaration: !0,
|
|
3096
|
+
ignoreLastRenderedPageBreak: !0,
|
|
3097
|
+
renderHeaders: !0,
|
|
3098
|
+
renderFooters: !0,
|
|
3099
|
+
renderFootnotes: !0,
|
|
3100
|
+
renderEndnotes: !0,
|
|
3101
|
+
useBase64URL: !1,
|
|
3102
|
+
renderChanges: !1,
|
|
3103
|
+
renderComments: !1,
|
|
3104
|
+
renderAltChunks: !0,
|
|
3105
|
+
h: Q
|
|
3106
|
+
};
|
|
3107
|
+
function mt(e, t) {
|
|
3108
|
+
let n = {
|
|
3109
|
+
...$,
|
|
3110
|
+
...t
|
|
3111
|
+
};
|
|
3112
|
+
return Je.load(e, new ot(n), n);
|
|
3113
|
+
}
|
|
3114
|
+
async function ht(e, t) {
|
|
3115
|
+
let n = {
|
|
3116
|
+
...$,
|
|
3117
|
+
...t
|
|
3118
|
+
};
|
|
3119
|
+
return await new ft().render(e, n);
|
|
3120
|
+
}
|
|
3121
|
+
async function gt(e, t, n, r) {
|
|
3122
|
+
let i = await mt(e, r), a = await ht(i, r);
|
|
3123
|
+
n ?? (n = t), n.innerHTML = "", t.innerHTML = "";
|
|
3124
|
+
for (let e of a) (e.nodeName === "STYLE" ? n : t).appendChild(e);
|
|
3125
|
+
return i;
|
|
3126
|
+
}
|
|
3127
|
+
//#endregion
|
|
3128
|
+
//#region src/engines/word.ts
|
|
3129
|
+
function _t(e) {
|
|
3130
|
+
if (e.byteLength < 2) return "binary";
|
|
3131
|
+
let t = new Uint8Array(e, 0, 2);
|
|
3132
|
+
if (t[0] === 80 && t[1] === 75) return "openxml";
|
|
3133
|
+
let n = new Uint8Array(e, 0, Math.min(e.byteLength, 8192)), r = t[0] === 255 && t[1] === 254 || t[0] === 60 && t[1] === 0, i = t[0] === 254 && t[1] === 255 || t[0] === 0 && t[1] === 60, a = new TextDecoder(r ? "utf-16le" : i ? "utf-16be" : "utf-8").decode(n);
|
|
3134
|
+
return /<(?:[\w.-]+:)?wordDocument(?:\s|>)/.test(a) && a.includes("http://schemas.microsoft.com/office/word/2003/wordml") ? "wordml" : "binary";
|
|
3135
|
+
}
|
|
3136
|
+
var vt = async ({ buffer: e, container: t, extension: n, signal: r, onProgress: i }) => {
|
|
3137
|
+
if (r.aborted) throw new DOMException("Document load aborted", "AbortError");
|
|
3138
|
+
if (t.classList.add("document-renderer", "document-renderer--word"), i({
|
|
3139
|
+
current: 0,
|
|
3140
|
+
total: 1,
|
|
3141
|
+
label: "正在解析 Word 文档"
|
|
3142
|
+
}), n === "doc" || n === "dot") {
|
|
3143
|
+
let a = _t(e);
|
|
3144
|
+
if (a === "binary") {
|
|
3145
|
+
let { renderBinaryWordDocument: a } = await import("./word-binary-DsiUIgdh.js");
|
|
3146
|
+
return a({
|
|
3147
|
+
buffer: e,
|
|
3148
|
+
container: t,
|
|
3149
|
+
extension: n,
|
|
3150
|
+
filename: "",
|
|
3151
|
+
signal: r,
|
|
3152
|
+
options: {},
|
|
3153
|
+
onProgress: i
|
|
3154
|
+
});
|
|
3155
|
+
}
|
|
3156
|
+
if (a === "wordml") {
|
|
3157
|
+
let { convertWordMlToDocx: n } = await import("./word-ml-5809L5ca.js");
|
|
3158
|
+
e = await n(e, t);
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
if (await gt(e, t, void 0, {
|
|
3162
|
+
className: "document-viewer-docx",
|
|
3163
|
+
inWrapper: !0,
|
|
3164
|
+
breakPages: !0,
|
|
3165
|
+
ignoreWidth: !1,
|
|
3166
|
+
ignoreHeight: !1,
|
|
3167
|
+
ignoreFonts: !1,
|
|
3168
|
+
renderHeaders: !0,
|
|
3169
|
+
renderFooters: !0,
|
|
3170
|
+
renderFootnotes: !0,
|
|
3171
|
+
renderEndnotes: !0,
|
|
3172
|
+
useBase64URL: !0,
|
|
3173
|
+
trimXmlDeclaration: !0
|
|
3174
|
+
}), r.aborted) throw new DOMException("Document load aborted", "AbortError");
|
|
3175
|
+
let a = Math.max(1, t.querySelectorAll("section.docx > article").length || t.querySelectorAll("section.docx").length);
|
|
3176
|
+
return i({
|
|
3177
|
+
current: 1,
|
|
3178
|
+
total: 1,
|
|
3179
|
+
label: "Word 文档已就绪"
|
|
3180
|
+
}), {
|
|
3181
|
+
pageCount: a,
|
|
3182
|
+
destroy() {
|
|
3183
|
+
t.replaceChildren(), t.classList.remove("document-renderer", "document-renderer--word");
|
|
3184
|
+
}
|
|
3185
|
+
};
|
|
3186
|
+
};
|
|
3187
|
+
//#endregion
|
|
3188
|
+
export { vt as renderWordDocument };
|