office-viewer 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (318) hide show
  1. package/README.md +23 -0
  2. package/esm/OpenXML.d.ts +21 -0
  3. package/esm/OpenXML.js +60 -0
  4. package/esm/Word.d.ts +208 -0
  5. package/esm/Word.js +370 -0
  6. package/esm/index.d.ts +6 -0
  7. package/esm/index.js +6 -0
  8. package/esm/node_modules/tslib/tslib.es6.js +120 -0
  9. package/esm/openxml/ContentType.d.ts +12 -0
  10. package/esm/openxml/ContentType.js +15 -0
  11. package/esm/openxml/Style.d.ts +41 -0
  12. package/esm/openxml/Style.js +156 -0
  13. package/esm/openxml/Theme.d.ts +26 -0
  14. package/esm/openxml/Theme.js +69 -0
  15. package/esm/openxml/Types.d.ts +2512 -0
  16. package/esm/openxml/Types.js +1003 -0
  17. package/esm/openxml/word/Background.d.ts +11 -0
  18. package/esm/openxml/word/Body.d.ts +18 -0
  19. package/esm/openxml/word/Body.js +67 -0
  20. package/esm/openxml/word/Bookmark.d.ts +6 -0
  21. package/esm/openxml/word/Bookmark.js +18 -0
  22. package/esm/openxml/word/Border.d.ts +10 -0
  23. package/esm/openxml/word/Break.d.ts +13 -0
  24. package/esm/openxml/word/Break.js +19 -0
  25. package/esm/openxml/word/CustomXml.d.ts +8 -0
  26. package/esm/openxml/word/FldSimple.d.ts +7 -0
  27. package/esm/openxml/word/FldSimple.js +15 -0
  28. package/esm/openxml/word/FrameProperties.d.ts +18 -0
  29. package/esm/openxml/word/Hyperlink.d.ts +13 -0
  30. package/esm/openxml/word/Hyperlink.js +53 -0
  31. package/esm/openxml/word/Indent.d.ts +8 -0
  32. package/esm/openxml/word/InlineText.d.ts +14 -0
  33. package/esm/openxml/word/InlineText.js +62 -0
  34. package/esm/openxml/word/InstrText.d.ts +4 -0
  35. package/esm/openxml/word/InstrText.js +8 -0
  36. package/esm/openxml/word/Paragraph.d.ts +34 -0
  37. package/esm/openxml/word/Paragraph.js +133 -0
  38. package/esm/openxml/word/Pict.d.ts +6 -0
  39. package/esm/openxml/word/Pict.js +19 -0
  40. package/esm/openxml/word/Ruby.d.ts +20 -0
  41. package/esm/openxml/word/Ruby.js +87 -0
  42. package/esm/openxml/word/Run.d.ts +31 -0
  43. package/esm/openxml/word/Run.js +98 -0
  44. package/esm/openxml/word/Section.d.ts +38 -0
  45. package/esm/openxml/word/Section.js +59 -0
  46. package/esm/openxml/word/Shading.d.ts +9 -0
  47. package/esm/openxml/word/SmartTag.d.ts +8 -0
  48. package/esm/openxml/word/SmartTag.js +18 -0
  49. package/esm/openxml/word/Spacing.d.ts +9 -0
  50. package/esm/openxml/word/Sym.d.ts +8 -0
  51. package/esm/openxml/word/Sym.js +16 -0
  52. package/esm/openxml/word/Tab.d.ts +8 -0
  53. package/esm/openxml/word/Tab.js +17 -0
  54. package/esm/openxml/word/Table.d.ts +49 -0
  55. package/esm/openxml/word/Table.js +248 -0
  56. package/esm/openxml/word/VerticalAlign.d.ts +6 -0
  57. package/esm/openxml/word/WDocument.d.ts +13 -0
  58. package/esm/openxml/word/WDocument.js +58 -0
  59. package/esm/openxml/word/drawing/Blip.d.ts +6 -0
  60. package/esm/openxml/word/drawing/Blip.js +17 -0
  61. package/esm/openxml/word/drawing/BlipFill.d.ts +9 -0
  62. package/esm/openxml/word/drawing/BlipFill.js +20 -0
  63. package/esm/openxml/word/drawing/Drawing.d.ts +6 -0
  64. package/esm/openxml/word/drawing/Drawing.js +15 -0
  65. package/esm/openxml/word/drawing/Pic.d.ts +8 -0
  66. package/esm/openxml/word/drawing/Pic.js +16 -0
  67. package/esm/openxml/word/drawing/ShapeProperties.d.ts +9 -0
  68. package/esm/openxml/word/drawing/ShapeProperties.js +20 -0
  69. package/esm/openxml/word/drawing/Transform.d.ts +17 -0
  70. package/esm/openxml/word/drawing/Transform.js +30 -0
  71. package/esm/openxml/word/numbering/AbstractNum.d.ts +13 -0
  72. package/esm/openxml/word/numbering/AbstractNum.js +42 -0
  73. package/esm/openxml/word/numbering/Lvl.d.ts +16 -0
  74. package/esm/openxml/word/numbering/Lvl.js +62 -0
  75. package/esm/openxml/word/numbering/Num.d.ts +10 -0
  76. package/esm/openxml/word/numbering/Num.js +46 -0
  77. package/esm/openxml/word/numbering/NumberProperties.d.ts +6 -0
  78. package/esm/openxml/word/numbering/NumberProperties.js +21 -0
  79. package/esm/openxml/word/numbering/Numbering.d.ts +9 -0
  80. package/esm/openxml/word/numbering/Numbering.js +50 -0
  81. package/esm/openxml/word/properties/Properties.d.ts +12 -0
  82. package/esm/openxml/word/table/Tc.d.ts +46 -0
  83. package/esm/openxml/word/table/Tc.js +234 -0
  84. package/esm/openxml/word/table/Tr.d.ts +18 -0
  85. package/esm/openxml/word/table/Tr.js +106 -0
  86. package/esm/package/PackageParser.d.ts +26 -0
  87. package/esm/package/XMLPackageParser.d.ts +31 -0
  88. package/esm/package/ZipPackageParser.d.ts +29 -0
  89. package/esm/package/ZipPackageParser.js +70 -0
  90. package/esm/parse/jcToTextAlign.d.ts +5 -0
  91. package/esm/parse/jcToTextAlign.js +21 -0
  92. package/esm/parse/parseBorder.d.ts +13 -0
  93. package/esm/parse/parseBorder.js +78 -0
  94. package/esm/parse/parseColor.d.ts +22 -0
  95. package/esm/parse/parseColor.js +131 -0
  96. package/esm/parse/parseFont.d.ts +7 -0
  97. package/esm/parse/parseFont.js +54 -0
  98. package/esm/parse/parseInd.d.ts +5 -0
  99. package/esm/parse/parseInd.js +27 -0
  100. package/esm/parse/parsePr.d.ts +8 -0
  101. package/esm/parse/parsePr.js +325 -0
  102. package/esm/parse/parseRelationship.d.ts +12 -0
  103. package/esm/parse/parseRelationship.js +40 -0
  104. package/esm/parse/parseSize.d.ts +27 -0
  105. package/esm/parse/parseSize.js +38 -0
  106. package/esm/parse/parseSpacing.d.ts +7 -0
  107. package/esm/parse/parseSpacing.js +43 -0
  108. package/esm/parse/parseTextDirection.d.ts +2 -0
  109. package/esm/parse/parseTextDirection.js +25 -0
  110. package/esm/parse/parseTrHeight.d.ts +2 -0
  111. package/esm/parse/parseTrHeight.js +17 -0
  112. package/esm/render/renderBody.d.ts +6 -0
  113. package/esm/render/renderBody.js +53 -0
  114. package/esm/render/renderBookmark.d.ts +6 -0
  115. package/esm/render/renderBookmark.js +17 -0
  116. package/esm/render/renderBr.d.ts +7 -0
  117. package/esm/render/renderBr.js +13 -0
  118. package/esm/render/renderDocument.d.ts +7 -0
  119. package/esm/render/renderDocument.js +14 -0
  120. package/esm/render/renderDrawing.d.ts +8 -0
  121. package/esm/render/renderDrawing.js +38 -0
  122. package/esm/render/renderHyperLink.d.ts +7 -0
  123. package/esm/render/renderHyperLink.js +41 -0
  124. package/esm/render/renderInlineText.d.ts +6 -0
  125. package/esm/render/renderInlineText.js +39 -0
  126. package/esm/render/renderInstrText.d.ts +8 -0
  127. package/esm/render/renderInstrText.js +40 -0
  128. package/esm/render/renderNumbering.d.ts +7 -0
  129. package/esm/render/renderNumbering.js +161 -0
  130. package/esm/render/renderParagraph.d.ts +7 -0
  131. package/esm/render/renderParagraph.js +78 -0
  132. package/esm/render/renderPict.d.ts +6 -0
  133. package/esm/render/renderPict.js +19 -0
  134. package/esm/render/renderRuby.d.ts +6 -0
  135. package/esm/render/renderRuby.js +53 -0
  136. package/esm/render/renderRun.d.ts +14 -0
  137. package/esm/render/renderRun.js +116 -0
  138. package/esm/render/renderSection.d.ts +6 -0
  139. package/esm/render/renderSection.js +36 -0
  140. package/esm/render/renderStyle.d.ts +13 -0
  141. package/esm/render/renderStyle.js +194 -0
  142. package/esm/render/renderSym.d.ts +3 -0
  143. package/esm/render/renderSym.js +10 -0
  144. package/esm/render/renderTab.d.ts +7 -0
  145. package/esm/render/renderTab.js +19 -0
  146. package/esm/render/renderTable.d.ts +6 -0
  147. package/esm/render/renderTable.js +186 -0
  148. package/esm/render/setElementStyle.d.ts +6 -0
  149. package/esm/render/setElementStyle.js +21 -0
  150. package/esm/util/autoSpace.d.ts +5 -0
  151. package/esm/util/autoSpace.js +33 -0
  152. package/esm/util/blob.d.ts +9 -0
  153. package/esm/util/blob.js +39 -0
  154. package/esm/util/dom.d.ts +36 -0
  155. package/esm/util/dom.js +63 -0
  156. package/esm/util/mergeRun.d.ts +17 -0
  157. package/esm/util/mergeRun.js +134 -0
  158. package/esm/util/xml.d.ts +8 -0
  159. package/esm/util/xml.js +12 -0
  160. package/lib/OpenXML.d.ts +21 -0
  161. package/lib/OpenXML.js +69 -0
  162. package/lib/Word.d.ts +208 -0
  163. package/lib/Word.js +374 -0
  164. package/lib/index.d.ts +6 -0
  165. package/lib/index.js +10 -0
  166. package/lib/node_modules/tslib/tslib.es6.js +129 -0
  167. package/lib/openxml/ContentType.d.ts +12 -0
  168. package/lib/openxml/ContentType.js +19 -0
  169. package/lib/openxml/Style.d.ts +41 -0
  170. package/lib/openxml/Style.js +160 -0
  171. package/lib/openxml/Theme.d.ts +26 -0
  172. package/lib/openxml/Theme.js +73 -0
  173. package/lib/openxml/Types.d.ts +2512 -0
  174. package/lib/openxml/Types.js +1005 -0
  175. package/lib/openxml/word/Background.d.ts +11 -0
  176. package/lib/openxml/word/Body.d.ts +18 -0
  177. package/lib/openxml/word/Body.js +71 -0
  178. package/lib/openxml/word/Bookmark.d.ts +6 -0
  179. package/lib/openxml/word/Bookmark.js +22 -0
  180. package/lib/openxml/word/Border.d.ts +10 -0
  181. package/lib/openxml/word/Break.d.ts +13 -0
  182. package/lib/openxml/word/Break.js +23 -0
  183. package/lib/openxml/word/CustomXml.d.ts +8 -0
  184. package/lib/openxml/word/FldSimple.d.ts +7 -0
  185. package/lib/openxml/word/FldSimple.js +19 -0
  186. package/lib/openxml/word/FrameProperties.d.ts +18 -0
  187. package/lib/openxml/word/Hyperlink.d.ts +13 -0
  188. package/lib/openxml/word/Hyperlink.js +57 -0
  189. package/lib/openxml/word/Indent.d.ts +8 -0
  190. package/lib/openxml/word/InlineText.d.ts +14 -0
  191. package/lib/openxml/word/InlineText.js +66 -0
  192. package/lib/openxml/word/InstrText.d.ts +4 -0
  193. package/lib/openxml/word/InstrText.js +12 -0
  194. package/lib/openxml/word/Paragraph.d.ts +34 -0
  195. package/lib/openxml/word/Paragraph.js +137 -0
  196. package/lib/openxml/word/Pict.d.ts +6 -0
  197. package/lib/openxml/word/Pict.js +23 -0
  198. package/lib/openxml/word/Ruby.d.ts +20 -0
  199. package/lib/openxml/word/Ruby.js +91 -0
  200. package/lib/openxml/word/Run.d.ts +31 -0
  201. package/lib/openxml/word/Run.js +103 -0
  202. package/lib/openxml/word/Section.d.ts +38 -0
  203. package/lib/openxml/word/Section.js +63 -0
  204. package/lib/openxml/word/Shading.d.ts +9 -0
  205. package/lib/openxml/word/SmartTag.d.ts +8 -0
  206. package/lib/openxml/word/SmartTag.js +22 -0
  207. package/lib/openxml/word/Spacing.d.ts +9 -0
  208. package/lib/openxml/word/Sym.d.ts +8 -0
  209. package/lib/openxml/word/Sym.js +20 -0
  210. package/lib/openxml/word/Tab.d.ts +8 -0
  211. package/lib/openxml/word/Tab.js +21 -0
  212. package/lib/openxml/word/Table.d.ts +49 -0
  213. package/lib/openxml/word/Table.js +252 -0
  214. package/lib/openxml/word/VerticalAlign.d.ts +6 -0
  215. package/lib/openxml/word/WDocument.d.ts +13 -0
  216. package/lib/openxml/word/WDocument.js +62 -0
  217. package/lib/openxml/word/drawing/Blip.d.ts +6 -0
  218. package/lib/openxml/word/drawing/Blip.js +21 -0
  219. package/lib/openxml/word/drawing/BlipFill.d.ts +9 -0
  220. package/lib/openxml/word/drawing/BlipFill.js +24 -0
  221. package/lib/openxml/word/drawing/Drawing.d.ts +6 -0
  222. package/lib/openxml/word/drawing/Drawing.js +19 -0
  223. package/lib/openxml/word/drawing/Pic.d.ts +8 -0
  224. package/lib/openxml/word/drawing/Pic.js +20 -0
  225. package/lib/openxml/word/drawing/ShapeProperties.d.ts +9 -0
  226. package/lib/openxml/word/drawing/ShapeProperties.js +24 -0
  227. package/lib/openxml/word/drawing/Transform.d.ts +17 -0
  228. package/lib/openxml/word/drawing/Transform.js +34 -0
  229. package/lib/openxml/word/numbering/AbstractNum.d.ts +13 -0
  230. package/lib/openxml/word/numbering/AbstractNum.js +46 -0
  231. package/lib/openxml/word/numbering/Lvl.d.ts +16 -0
  232. package/lib/openxml/word/numbering/Lvl.js +66 -0
  233. package/lib/openxml/word/numbering/Num.d.ts +10 -0
  234. package/lib/openxml/word/numbering/Num.js +50 -0
  235. package/lib/openxml/word/numbering/NumberProperties.d.ts +6 -0
  236. package/lib/openxml/word/numbering/NumberProperties.js +25 -0
  237. package/lib/openxml/word/numbering/Numbering.d.ts +9 -0
  238. package/lib/openxml/word/numbering/Numbering.js +54 -0
  239. package/lib/openxml/word/properties/Properties.d.ts +12 -0
  240. package/lib/openxml/word/table/Tc.d.ts +46 -0
  241. package/lib/openxml/word/table/Tc.js +242 -0
  242. package/lib/openxml/word/table/Tr.d.ts +18 -0
  243. package/lib/openxml/word/table/Tr.js +110 -0
  244. package/lib/package/PackageParser.d.ts +26 -0
  245. package/lib/package/XMLPackageParser.d.ts +31 -0
  246. package/lib/package/ZipPackageParser.d.ts +29 -0
  247. package/lib/package/ZipPackageParser.js +74 -0
  248. package/lib/parse/jcToTextAlign.d.ts +5 -0
  249. package/lib/parse/jcToTextAlign.js +25 -0
  250. package/lib/parse/parseBorder.d.ts +13 -0
  251. package/lib/parse/parseBorder.js +83 -0
  252. package/lib/parse/parseColor.d.ts +22 -0
  253. package/lib/parse/parseColor.js +137 -0
  254. package/lib/parse/parseFont.d.ts +7 -0
  255. package/lib/parse/parseFont.js +58 -0
  256. package/lib/parse/parseInd.d.ts +5 -0
  257. package/lib/parse/parseInd.js +31 -0
  258. package/lib/parse/parsePr.d.ts +8 -0
  259. package/lib/parse/parsePr.js +329 -0
  260. package/lib/parse/parseRelationship.d.ts +12 -0
  261. package/lib/parse/parseRelationship.js +45 -0
  262. package/lib/parse/parseSize.d.ts +27 -0
  263. package/lib/parse/parseSize.js +44 -0
  264. package/lib/parse/parseSpacing.d.ts +7 -0
  265. package/lib/parse/parseSpacing.js +47 -0
  266. package/lib/parse/parseTextDirection.d.ts +2 -0
  267. package/lib/parse/parseTextDirection.js +29 -0
  268. package/lib/parse/parseTrHeight.d.ts +2 -0
  269. package/lib/parse/parseTrHeight.js +21 -0
  270. package/lib/render/renderBody.d.ts +6 -0
  271. package/lib/render/renderBody.js +57 -0
  272. package/lib/render/renderBookmark.d.ts +6 -0
  273. package/lib/render/renderBookmark.js +21 -0
  274. package/lib/render/renderBr.d.ts +7 -0
  275. package/lib/render/renderBr.js +17 -0
  276. package/lib/render/renderDocument.d.ts +7 -0
  277. package/lib/render/renderDocument.js +18 -0
  278. package/lib/render/renderDrawing.d.ts +8 -0
  279. package/lib/render/renderDrawing.js +42 -0
  280. package/lib/render/renderHyperLink.d.ts +7 -0
  281. package/lib/render/renderHyperLink.js +45 -0
  282. package/lib/render/renderInlineText.d.ts +6 -0
  283. package/lib/render/renderInlineText.js +43 -0
  284. package/lib/render/renderInstrText.d.ts +8 -0
  285. package/lib/render/renderInstrText.js +44 -0
  286. package/lib/render/renderNumbering.d.ts +7 -0
  287. package/lib/render/renderNumbering.js +165 -0
  288. package/lib/render/renderParagraph.d.ts +7 -0
  289. package/lib/render/renderParagraph.js +82 -0
  290. package/lib/render/renderPict.d.ts +6 -0
  291. package/lib/render/renderPict.js +23 -0
  292. package/lib/render/renderRuby.d.ts +6 -0
  293. package/lib/render/renderRuby.js +57 -0
  294. package/lib/render/renderRun.d.ts +14 -0
  295. package/lib/render/renderRun.js +121 -0
  296. package/lib/render/renderSection.d.ts +6 -0
  297. package/lib/render/renderSection.js +40 -0
  298. package/lib/render/renderStyle.d.ts +13 -0
  299. package/lib/render/renderStyle.js +199 -0
  300. package/lib/render/renderSym.d.ts +3 -0
  301. package/lib/render/renderSym.js +14 -0
  302. package/lib/render/renderTab.d.ts +7 -0
  303. package/lib/render/renderTab.js +23 -0
  304. package/lib/render/renderTable.d.ts +6 -0
  305. package/lib/render/renderTable.js +190 -0
  306. package/lib/render/setElementStyle.d.ts +6 -0
  307. package/lib/render/setElementStyle.js +25 -0
  308. package/lib/util/autoSpace.d.ts +5 -0
  309. package/lib/util/autoSpace.js +37 -0
  310. package/lib/util/blob.d.ts +9 -0
  311. package/lib/util/blob.js +44 -0
  312. package/lib/util/dom.d.ts +36 -0
  313. package/lib/util/dom.js +72 -0
  314. package/lib/util/mergeRun.d.ts +17 -0
  315. package/lib/util/mergeRun.js +140 -0
  316. package/lib/util/xml.d.ts +8 -0
  317. package/lib/util/xml.js +16 -0
  318. package/package.json +91 -0
@@ -0,0 +1,70 @@
1
+ import { unzipSync, strFromU8, strToU8, zipSync } from 'fflate';
2
+
3
+ /**
4
+ * zip 文件解析
5
+ */
6
+ var ZipPackageParser = /** @class */ (function () {
7
+ function ZipPackageParser() {
8
+ }
9
+ /**
10
+ * 加载 zip 文件
11
+ */
12
+ ZipPackageParser.prototype.load = function (docxFile) {
13
+ this.zip = unzipSync(new Uint8Array(docxFile), {
14
+ filter: function (file) {
15
+ // 不解析大于 10 MiB 的文件
16
+ return file.originalSize <= 10000000;
17
+ }
18
+ });
19
+ };
20
+ /**
21
+ * 读取 xml 文件,转成 json 对象
22
+ * @param filePath 文件路径
23
+ * @returns 转成 json 的结果
24
+ */
25
+ ZipPackageParser.prototype.getXML = function (filePath) {
26
+ var fileContent = this.getFileByType(filePath, 'string');
27
+ var doc = new DOMParser().parseFromString(fileContent, 'application/xml');
28
+ var errorNode = doc.querySelector('parsererror');
29
+ if (errorNode) {
30
+ throw new Error(errorNode.textContent || "can't parse xml");
31
+ }
32
+ else {
33
+ return doc;
34
+ }
35
+ };
36
+ /**
37
+ * 根据类型读取文件
38
+ */
39
+ ZipPackageParser.prototype.getFileByType = function (filePath, type) {
40
+ filePath = filePath.startsWith('/') ? filePath.slice(1) : filePath;
41
+ var file = this.zip[filePath];
42
+ if (file) {
43
+ if (type === 'string') {
44
+ return strFromU8(file);
45
+ }
46
+ else if (type === 'blob') {
47
+ return new Blob([file]);
48
+ }
49
+ }
50
+ throw new Error('file not found');
51
+ };
52
+ /**
53
+ * 判断文件是否存在
54
+ */
55
+ ZipPackageParser.prototype.fileExists = function (filePath) {
56
+ filePath = filePath.startsWith('/') ? filePath.slice(1) : filePath;
57
+ return filePath in this.zip;
58
+ };
59
+ /**
60
+ * 生成新的 zip 文件
61
+ */
62
+ ZipPackageParser.prototype.generateZip = function (docContent) {
63
+ // 其实最好是生成个新的,后续再优化
64
+ this.zip['word/document.xml'] = strToU8(docContent);
65
+ return new Blob([zipSync(this.zip)]);
66
+ };
67
+ return ZipPackageParser;
68
+ }());
69
+
70
+ export { ZipPackageParser as default };
@@ -0,0 +1,5 @@
1
+ /** 将 jc 转成 text-align
2
+ *
3
+ * http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/ST_Jc.html
4
+ */
5
+ export declare function jcToTextAlign(jc: string): string;
@@ -0,0 +1,21 @@
1
+ /** 将 jc 转成 text-align
2
+ *
3
+ * http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/ST_Jc.html
4
+ */
5
+ function jcToTextAlign(jc) {
6
+ switch (jc) {
7
+ case 'start':
8
+ case 'left':
9
+ return 'left';
10
+ case 'center':
11
+ return 'center';
12
+ case 'end':
13
+ case 'right':
14
+ return 'right';
15
+ case 'both':
16
+ return 'justify';
17
+ }
18
+ return jc;
19
+ }
20
+
21
+ export { jcToTextAlign };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 解析边框转成 css 样式 http://officeopenxml.com/WPborders.php
3
+ */
4
+ import { CSSStyle } from '../openxml/Style';
5
+ import Word from '../Word';
6
+ /**
7
+ * 解析单个边框样式
8
+ */
9
+ export declare function parseBorder(word: Word, element: Element): string;
10
+ /**
11
+ * 解析边框
12
+ */
13
+ export declare function parseBorders(word: Word, element: Element, style: CSSStyle): void;
@@ -0,0 +1,78 @@
1
+ import { __values } from '../node_modules/tslib/tslib.es6.js';
2
+ import { getVal } from '../OpenXML.js';
3
+ import { parseColorAttr } from './parseColor.js';
4
+ import { parseSize, LengthUsage } from './parseSize.js';
5
+ import { ST_Border } from '../openxml/Types.js';
6
+
7
+ // 默认边框颜色
8
+ var DEFAULT_BORDER_COLOR = 'black';
9
+ /**
10
+ * 解析单个边框样式
11
+ */
12
+ function parseBorder(word, element) {
13
+ var type = getVal(element);
14
+ if (type === ST_Border.nil || type === ST_Border.none) {
15
+ return 'none';
16
+ }
17
+ // 这里和 css 不完全一致,css 能表现的要少很多,也是导致展现效果难以一致的原因
18
+ switch (type) {
19
+ case ST_Border.dashed:
20
+ case ST_Border.dashDotStroked:
21
+ case ST_Border.dashSmallGap:
22
+ break;
23
+ case ST_Border.dotDash:
24
+ case ST_Border.dotDotDash:
25
+ case ST_Border.dotted:
26
+ break;
27
+ case ST_Border.double:
28
+ case ST_Border.doubleWave:
29
+ break;
30
+ case ST_Border.inset:
31
+ break;
32
+ case ST_Border.outset:
33
+ break;
34
+ }
35
+ var color = parseColorAttr(word, element);
36
+ var size = parseSize(element, 'w:sz', LengthUsage.Border);
37
+ return "".concat(size, " solid ").concat(color == 'auto' ? DEFAULT_BORDER_COLOR : color);
38
+ }
39
+ /**
40
+ * 解析边框
41
+ */
42
+ function parseBorders(word, element, style) {
43
+ var e_1, _a;
44
+ try {
45
+ for (var _b = __values(element.children), _c = _b.next(); !_c.done; _c = _b.next()) {
46
+ var child = _c.value;
47
+ var tagName = child.tagName;
48
+ switch (tagName) {
49
+ case 'w:start':
50
+ case 'w:left':
51
+ style['border-left'] = parseBorder(word, child);
52
+ break;
53
+ case 'w:end':
54
+ case 'w:right':
55
+ style['border-right'] = parseBorder(word, child);
56
+ break;
57
+ case 'w:top':
58
+ style['border-top'] = parseBorder(word, child);
59
+ break;
60
+ case 'w:bottom':
61
+ style['border-bottom'] = parseBorder(word, child);
62
+ break;
63
+ // TODO: 还有个 between 不知道是干啥的
64
+ default:
65
+ break;
66
+ }
67
+ }
68
+ }
69
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
70
+ finally {
71
+ try {
72
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
73
+ }
74
+ finally { if (e_1) throw e_1.error; }
75
+ }
76
+ }
77
+
78
+ export { parseBorder, parseBorders };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 解析颜色,转成 css 的颜色
3
+ */
4
+ import Word from '../Word';
5
+ /**
6
+ *
7
+ * 解析属性上的 color,比如 <w:top w:val="single" w:sz="24" w:space="1" w:color="FF0000" />
8
+ * @param attrName color 默认属性
9
+ * @param autoColor 默认值
10
+ * @returns css 颜色
11
+ */
12
+ export declare function parseColorAttr(word: Word, element: Element, attrName?: string, autoColor?: string): string;
13
+ /**
14
+ * 专门用来支持 shd 的颜色
15
+ * http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/ST_Shd.html
16
+ */
17
+ export declare function parseShdColor(word: Word, element: Element): string;
18
+ /**
19
+ * 解析 color 标签,比如 <w:color w:themeColor="accent3" />
20
+ * @returns css 颜色
21
+ */
22
+ export declare function parseColor(word: Word, element: Element): string;
@@ -0,0 +1,131 @@
1
+ import { getVal } from '../OpenXML.js';
2
+ import { ST_Shd } from '../openxml/Types.js';
3
+
4
+ /**
5
+ * 解析颜色,转成 css 的颜色
6
+ */
7
+ var knownColors = [
8
+ 'black',
9
+ 'blue',
10
+ 'cyan',
11
+ 'darkBlue',
12
+ 'darkCyan',
13
+ 'darkGray',
14
+ 'darkGreen',
15
+ 'darkMagenta',
16
+ 'darkRed',
17
+ 'darkYellow',
18
+ 'green',
19
+ 'lightGray',
20
+ 'magenta',
21
+ 'none',
22
+ 'red',
23
+ 'white',
24
+ 'yellow'
25
+ ];
26
+ /**
27
+ *
28
+ * 解析属性上的 color,比如 <w:top w:val="single" w:sz="24" w:space="1" w:color="FF0000" />
29
+ * @param attrName color 默认属性
30
+ * @param autoColor 默认值
31
+ * @returns css 颜色
32
+ */
33
+ function parseColorAttr(word, element, attrName, autoColor) {
34
+ if (attrName === void 0) { attrName = 'w:color'; }
35
+ if (autoColor === void 0) { autoColor = 'black'; }
36
+ var color = element.getAttribute(attrName);
37
+ if (color) {
38
+ if (color == 'auto') {
39
+ return autoColor;
40
+ }
41
+ else if (typeof color === 'string' && knownColors.includes(color)) {
42
+ return color;
43
+ }
44
+ return "#".concat(color);
45
+ }
46
+ var themeColor = element.getAttribute('w:themeColor');
47
+ return themeColor ? word.getThemeColor(themeColor) : '';
48
+ }
49
+ /**
50
+ * 专门用来支持 shd 的颜色
51
+ * http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/ST_Shd.html
52
+ */
53
+ function parseShdColor(word, element) {
54
+ var color = element.getAttribute('w:fill') || '';
55
+ var val = getVal(element);
56
+ if (color === 'auto') {
57
+ color = 'inherit';
58
+ }
59
+ if (color.length === 6) {
60
+ switch (val) {
61
+ case ST_Shd.clear:
62
+ return "#".concat(color);
63
+ case ST_Shd.pct10:
64
+ return colorPercent(color, 0.1);
65
+ case ST_Shd.pct12:
66
+ return colorPercent(color, 0.125);
67
+ case ST_Shd.pct15:
68
+ return colorPercent(color, 0.15);
69
+ case ST_Shd.pct20:
70
+ return colorPercent(color, 0.2);
71
+ case ST_Shd.pct25:
72
+ return colorPercent(color, 0.25);
73
+ case ST_Shd.pct30:
74
+ return colorPercent(color, 0.3);
75
+ case ST_Shd.pct35:
76
+ return colorPercent(color, 0.35);
77
+ case ST_Shd.pct37:
78
+ return colorPercent(color, 0.375);
79
+ case ST_Shd.pct40:
80
+ return colorPercent(color, 0.4);
81
+ case ST_Shd.pct45:
82
+ return colorPercent(color, 0.45);
83
+ case ST_Shd.pct5:
84
+ return colorPercent(color, 0.05);
85
+ case ST_Shd.pct50:
86
+ return colorPercent(color, 0.5);
87
+ case ST_Shd.pct55:
88
+ return colorPercent(color, 0.55);
89
+ case ST_Shd.pct60:
90
+ return colorPercent(color, 0.6);
91
+ case ST_Shd.pct65:
92
+ return colorPercent(color, 0.65);
93
+ case ST_Shd.pct70:
94
+ return colorPercent(color, 0.7);
95
+ case ST_Shd.pct75:
96
+ return colorPercent(color, 0.75);
97
+ case ST_Shd.pct80:
98
+ return colorPercent(color, 0.8);
99
+ case ST_Shd.pct85:
100
+ return colorPercent(color, 0.85);
101
+ case ST_Shd.pct87:
102
+ return colorPercent(color, 0.87);
103
+ case ST_Shd.pct90:
104
+ return colorPercent(color, 0.9);
105
+ case ST_Shd.pct95:
106
+ return colorPercent(color, 0.95);
107
+ default:
108
+ console.warn('unsupport shd val', val);
109
+ return "#".concat(color);
110
+ }
111
+ }
112
+ return '';
113
+ }
114
+ /**
115
+ * 用 alpha 来模拟 ptc 功能
116
+ */
117
+ function colorPercent(color, percent) {
118
+ var r = parseInt(color.substring(0, 2), 16);
119
+ var g = parseInt(color.substring(2, 4), 16);
120
+ var b = parseInt(color.substring(4, 6), 16);
121
+ return "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(percent, ")");
122
+ }
123
+ /**
124
+ * 解析 color 标签,比如 <w:color w:themeColor="accent3" />
125
+ * @returns css 颜色
126
+ */
127
+ function parseColor(word, element) {
128
+ return parseColorAttr(word, element, 'w:val');
129
+ }
130
+
131
+ export { parseColor, parseColorAttr, parseShdColor };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 解析字体
3
+ * http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/rFonts.html
4
+ */
5
+ import { CSSStyle } from '../openxml/Style';
6
+ import Word from '../Word';
7
+ export declare function parseFont(word: Word, element: Element, style: CSSStyle): void;
@@ -0,0 +1,54 @@
1
+ import { __values } from '../node_modules/tslib/tslib.es6.js';
2
+
3
+ /**
4
+ * 解析字体
5
+ * http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/rFonts.html
6
+ */
7
+ function themeFont(font) {
8
+ return "var(--docx-theme-font-".concat(font, ")");
9
+ }
10
+ function parseFont(word, element, style) {
11
+ var e_1, _a;
12
+ var fonts = [];
13
+ var fontMapping = word.renderOptions.fontMapping;
14
+ try {
15
+ for (var _b = __values(element.attributes), _c = _b.next(); !_c.done; _c = _b.next()) {
16
+ var attribute = _c.value;
17
+ var name_1 = attribute.name;
18
+ var value = attribute.value;
19
+ switch (name_1) {
20
+ case 'w:ascii':
21
+ case 'w:cs':
22
+ case 'w:eastAsia':
23
+ if (fontMapping && value in fontMapping) {
24
+ value = fontMapping[value];
25
+ }
26
+ if (value.indexOf(' ') === -1) {
27
+ fonts.push(value);
28
+ }
29
+ else {
30
+ fonts.push('"' + value + '"');
31
+ }
32
+ break;
33
+ case 'w:asciiTheme':
34
+ case 'w:csTheme':
35
+ case 'w:eastAsiaTheme':
36
+ fonts.push(themeFont(value));
37
+ break;
38
+ }
39
+ }
40
+ }
41
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
42
+ finally {
43
+ try {
44
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
45
+ }
46
+ finally { if (e_1) throw e_1.error; }
47
+ }
48
+ // hint 之类的不支持,因为也很难控制到这个粒度了
49
+ if (fonts.length) {
50
+ style['font-family'] = Array.from(new Set(fonts)).join(', ');
51
+ }
52
+ }
53
+
54
+ export { parseFont };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 解析缩进 http://officeopenxml.com/WPindentation.php
3
+ */
4
+ import { CSSStyle } from '../openxml/Style';
5
+ export declare function parseInd(element: Element, style: CSSStyle): void;
@@ -0,0 +1,27 @@
1
+ import { parseSize } from './parseSize.js';
2
+
3
+ /**
4
+ * 解析缩进 http://officeopenxml.com/WPindentation.php
5
+ */
6
+ function parseInd(element, style) {
7
+ var firstLine = parseSize(element, 'w:firstLine');
8
+ var hanging = parseSize(element, 'w:hanging');
9
+ var left = parseSize(element, 'w:left');
10
+ var start = parseSize(element, 'w:start');
11
+ var right = parseSize(element, 'w:right');
12
+ var end = parseSize(element, 'w:end');
13
+ if (firstLine) {
14
+ style['text-indent'] = firstLine;
15
+ }
16
+ if (hanging) {
17
+ style['text-indent'] = "-".concat(hanging);
18
+ }
19
+ if (left || start) {
20
+ style['margin-left'] = left || start;
21
+ }
22
+ if (right || end) {
23
+ style['margin-right'] = right || end;
24
+ }
25
+ }
26
+
27
+ export { parseInd };
@@ -0,0 +1,8 @@
1
+ import { CSSStyle } from '../openxml/Style';
2
+ import Word from '../Word';
3
+ /**
4
+ * 解析各种 pPr 及 rPr,返回样式
5
+ * @param type 所属类型
6
+ * @returns 样式
7
+ */
8
+ export declare function parsePr(word: Word, element: Element, type?: 'r' | 'p'): CSSStyle;