ranui 0.1.9 → 0.1.10-alpha.2

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