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,329 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var tslib_es6 = require('../node_modules/tslib/tslib.es6.js');
6
+ var Types = require('../openxml/Types.js');
7
+ var parseSize = require('./parseSize.js');
8
+ var OpenXML = require('../OpenXML.js');
9
+ var parseBorder = require('./parseBorder.js');
10
+ var parseColor = require('./parseColor.js');
11
+ var parseInd = require('./parseInd.js');
12
+ var parseSpacing = require('./parseSpacing.js');
13
+ var parseFont = require('./parseFont.js');
14
+ var parseTrHeight = require('./parseTrHeight.js');
15
+ var jcToTextAlign = require('./jcToTextAlign.js');
16
+ var parseTextDirection = require('./parseTextDirection.js');
17
+
18
+ /**
19
+ * 解析 underline 并附上样式
20
+ * http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/u.html
21
+ */
22
+ function parseUnderline(word, element, style) {
23
+ var val = OpenXML.getVal(element);
24
+ if (val == null)
25
+ return;
26
+ switch (val) {
27
+ case 'dash':
28
+ case 'dashDotDotHeavy':
29
+ case 'dashDotHeavy':
30
+ case 'dashedHeavy':
31
+ case 'dashLong':
32
+ case 'dashLongHeavy':
33
+ case 'dotDash':
34
+ case 'dotDotDash':
35
+ style['text-decoration-style'] = 'dashed';
36
+ break;
37
+ case 'dotted':
38
+ case 'dottedHeavy':
39
+ style['text-decoration-style'] = 'dotted';
40
+ break;
41
+ case 'double':
42
+ style['text-decoration-style'] = 'double';
43
+ break;
44
+ case 'single':
45
+ case 'thick':
46
+ style['text-decoration'] = 'underline';
47
+ break;
48
+ case 'wave':
49
+ case 'wavyDouble':
50
+ case 'wavyHeavy':
51
+ style['text-decoration-style'] = 'wavy';
52
+ break;
53
+ case 'words':
54
+ style['text-decoration'] = 'underline';
55
+ break;
56
+ case 'none':
57
+ style['text-decoration'] = 'none';
58
+ break;
59
+ }
60
+ var color = parseColor.parseColorAttr(word, element);
61
+ if (color) {
62
+ style['text-decoration-color'] = color;
63
+ }
64
+ }
65
+ /**
66
+ * 目前只有部分支持
67
+ * http://officeopenxml.com/WPparagraph-textFrames.php
68
+ */
69
+ function parseFrame(element, style) {
70
+ var e_1, _a;
71
+ try {
72
+ for (var _b = tslib_es6.__values(element.attributes), _c = _b.next(); !_c.done; _c = _b.next()) {
73
+ var attribute = _c.value;
74
+ var name_1 = attribute.name;
75
+ var value = attribute.value;
76
+ switch (name_1) {
77
+ case 'w:dropCap':
78
+ if (value === 'drop') {
79
+ style['float'] = 'left';
80
+ }
81
+ break;
82
+ case 'w:h':
83
+ if (typeof value === 'object' && !Array.isArray(value)) {
84
+ style['height'] = parseSize.parseSize(value, 'w:h');
85
+ }
86
+ break;
87
+ case 'w:w':
88
+ if (typeof value === 'object' && !Array.isArray(value)) {
89
+ style['width'] = parseSize.parseSize(value, 'w:w');
90
+ }
91
+ break;
92
+ default:
93
+ console.warn('parseFrame: unknown attribute ' + name_1, attribute);
94
+ }
95
+ }
96
+ }
97
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
98
+ finally {
99
+ try {
100
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
101
+ }
102
+ finally { if (e_1) throw e_1.error; }
103
+ }
104
+ }
105
+ var HighLightColor = 'transparent';
106
+ /**
107
+ * 解析各种 pPr 及 rPr,返回样式
108
+ * @param type 所属类型
109
+ * @returns 样式
110
+ */
111
+ function parsePr(word, element, type) {
112
+ var e_2, _a;
113
+ var style = {};
114
+ try {
115
+ for (var _b = tslib_es6.__values(element.children), _c = _b.next(); !_c.done; _c = _b.next()) {
116
+ var child = _c.value;
117
+ var tagName = child.tagName;
118
+ switch (tagName) {
119
+ case 'w:sz':
120
+ case 'w:szCs':
121
+ style['font-size'] = parseSize.parseSize(child, 'w:val', parseSize.LengthUsage.FontSize);
122
+ break;
123
+ case 'w:jc':
124
+ style['text-align'] = jcToTextAlign.jcToTextAlign(OpenXML.getVal(child));
125
+ break;
126
+ case 'w:framePr':
127
+ parseFrame(child, style);
128
+ break;
129
+ case 'w:pBdr':
130
+ parseBorder.parseBorders(word, child, style);
131
+ break;
132
+ case 'w:ind':
133
+ parseInd.parseInd(child, style);
134
+ break;
135
+ case 'w:color':
136
+ style['color'] = parseColor.parseColor(word, child);
137
+ break;
138
+ case 'w:shd':
139
+ // 如果已经有设置说明是 highlight
140
+ if (!('background-color' in style)) {
141
+ // http://officeopenxml.com/WPshading.php
142
+ style['background-color'] = parseColor.parseShdColor(word, child);
143
+ }
144
+ break;
145
+ case 'w:spacing':
146
+ parseSpacing.parseSpacing(word, child, style);
147
+ break;
148
+ case 'w:highlight':
149
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/highlight.html
150
+ // 这个按文档是重要性高于 shd
151
+ style['background-color'] = parseColor.parseColorAttr(word, child, 'w:fill', HighLightColor);
152
+ break;
153
+ case 'w:vertAlign':
154
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/vertAlign.html
155
+ // 这个其实和 position 有冲突,但预计这两个同时出现的概率不高
156
+ var vertAlign = OpenXML.getVal(child);
157
+ if (vertAlign === Types.ST_VerticalAlignRun.superscript) {
158
+ style['vertical-align'] = 'super';
159
+ }
160
+ else if (vertAlign === Types.ST_VerticalAlignRun.subscript) {
161
+ style['vertical-align'] = 'sub';
162
+ }
163
+ break;
164
+ case 'w:position':
165
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/position.html
166
+ style['vertical-align'] = parseSize.parseSize(child, 'w:val', parseSize.LengthUsage.FontSize);
167
+ break;
168
+ case 'w:trHeight':
169
+ parseTrHeight.parseTrHeight(child, style);
170
+ break;
171
+ case 'w:strike':
172
+ case 'w:dstrike':
173
+ // 其实不支持 dstrike,都统一为 strike
174
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/dstrike.html
175
+ style['text-decoration'] = OpenXML.getValBoolean(child)
176
+ ? 'line-through'
177
+ : 'none';
178
+ break;
179
+ case 'w:b':
180
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/b.html
181
+ style['font-weight'] = OpenXML.getValBoolean(child) ? 'bold' : 'normal';
182
+ break;
183
+ case 'w:adjustRightInd':
184
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/adjustRightInd.html
185
+ // 似乎没法处理
186
+ break;
187
+ case 'w:bCs':
188
+ case 'w:iCs':
189
+ // 忽略,因为 CSS 没法按这个判断
190
+ break;
191
+ case 'w:i':
192
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/i.html
193
+ style['font-style'] = OpenXML.getValBoolean(child) ? 'italic' : 'normal';
194
+ break;
195
+ case 'w:caps':
196
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/caps.html
197
+ style['text-transform'] = OpenXML.getValBoolean(child) ? 'uppercase' : 'normal';
198
+ break;
199
+ case 'w:smallCaps':
200
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/smallCaps.html
201
+ style['text-transform'] = OpenXML.getValBoolean(child) ? 'lowercase' : 'normal';
202
+ break;
203
+ case 'w:u':
204
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/u.html
205
+ parseUnderline(word, child, style);
206
+ break;
207
+ case 'w:rFonts':
208
+ parseFont.parseFont(word, child, style);
209
+ break;
210
+ case 'w:tblCellSpacing':
211
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/tblCellSpacing_1.html
212
+ style['border-spacing'] = parseSize.parseSize(child, 'w:w');
213
+ style['border-collapse'] = 'separate';
214
+ break;
215
+ case 'w:bdr':
216
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/bdr.html
217
+ style['border'] = parseBorder.parseBorder(word, child);
218
+ break;
219
+ case 'w:vanish':
220
+ if (OpenXML.getValBoolean(child)) {
221
+ // 这里其实没试过 word 里到底是不是 none
222
+ style['display'] = 'none';
223
+ }
224
+ break;
225
+ case 'w:kern':
226
+ // todo: 这里显示不正确
227
+ // style['letter-spacing'] = parseSize(
228
+ // child,
229
+ // 'w:val',
230
+ // LengthUsage.FontSize
231
+ // );
232
+ break;
233
+ case 'w:pStyle':
234
+ // 这个需要特殊处理
235
+ break;
236
+ case 'w:lang':
237
+ case 'w:noProof':
238
+ // 用于拼写检查
239
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/lang.html
240
+ break;
241
+ case 'w:keepLines':
242
+ case 'w:keepNext':
243
+ case 'w:widowControl':
244
+ case 'w:pageBreakBefore':
245
+ // 用于分页的场景,目前还不支持 TODO:
246
+ break;
247
+ case 'w:outlineLvl':
248
+ // 似乎是用于目录的,目前还不支持
249
+ break;
250
+ case 'w:contextualSpacing':
251
+ // 还没空看
252
+ break;
253
+ case 'w:numPr':
254
+ // 这个在 parseParagraphProperties 里处理了
255
+ break;
256
+ case 'w:rPr':
257
+ // TODO: 这个有时候会不正确,需要再看看
258
+ break;
259
+ case 'w:rStyle':
260
+ // 在 Run 里地方处理了
261
+ break;
262
+ case 'w:webHidden':
263
+ // web 模式隐藏
264
+ style['display'] = 'none';
265
+ break;
266
+ case 'w:tabs':
267
+ // 这个在 parseParagraphProperties 里处理了
268
+ break;
269
+ case 'w:snapToGrid':
270
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/snapToGrid_2.html
271
+ // 目前还不支持 grid
272
+ break;
273
+ case 'w:wordWrap':
274
+ // 不太确定这里是用 word-break 还是 overflow-wrap
275
+ if (OpenXML.getValBoolean(child)) {
276
+ style['word-break'] = 'break-all';
277
+ }
278
+ break;
279
+ case 'w:textAlignment':
280
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/textAlignment.html
281
+ var alignment = OpenXML.getVal(child);
282
+ if (alignment === Types.ST_TextAlignment.center) {
283
+ style['vertical-align'] = 'middle';
284
+ }
285
+ else if (alignment !== Types.ST_TextAlignment.auto) {
286
+ style['vertical-align'] = alignment;
287
+ }
288
+ break;
289
+ case 'w:textDirection':
290
+ parseTextDirection.parseTextDirection(child, style);
291
+ break;
292
+ case 'w:cnfStyle':
293
+ // 目前是自动计算的,所以不需要这个了
294
+ break;
295
+ case 'w:bidi':
296
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/bidi_1.html
297
+ // TODO: 还不清楚和 w:textDirection 是什么关系
298
+ if (OpenXML.getValBoolean(child, true)) {
299
+ console.warn('w:bidi is not supported.');
300
+ }
301
+ break;
302
+ case 'w:autoSpaceDE':
303
+ case 'w:autoSpaceDN':
304
+ // 这个在其它地方实现了
305
+ break;
306
+ case 'w:kinsoku':
307
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/kinsoku.html
308
+ // 控制不了所以忽略了
309
+ break;
310
+ case 'w:overflowPunct':
311
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/overflowPunct.html
312
+ // 支持不了
313
+ break;
314
+ default:
315
+ console.warn('parsePr Unknown tagName', tagName, child);
316
+ }
317
+ }
318
+ }
319
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
320
+ finally {
321
+ try {
322
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
323
+ }
324
+ finally { if (e_2) throw e_2.error; }
325
+ }
326
+ return style;
327
+ }
328
+
329
+ exports.parsePr = parsePr;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 解析 _rels/.rels 文件
3
+ */
4
+ export interface Relationship {
5
+ id: string;
6
+ type: string;
7
+ target: string;
8
+ targetMode?: string;
9
+ part: 'root' | 'word';
10
+ }
11
+ export declare function parseRelationship(element: Element, part: 'root' | 'word'): Relationship;
12
+ export declare function parseRelationships(element: Document, part: 'root' | 'word'): Record<string, Relationship>;
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var tslib_es6 = require('../node_modules/tslib/tslib.es6.js');
6
+
7
+ /**
8
+ * 解析 _rels/.rels 文件
9
+ */
10
+ function parseRelationship(element, part) {
11
+ var id = element.getAttribute('Id') || '';
12
+ var type = element.getAttribute('Type') || '';
13
+ var target = element.getAttribute('Target') || '';
14
+ var targetMode = element.getAttribute('TargetMode') || '';
15
+ return {
16
+ id: id,
17
+ type: type,
18
+ target: target,
19
+ targetMode: targetMode,
20
+ part: part
21
+ };
22
+ }
23
+ function parseRelationships(element, part) {
24
+ var e_1, _a;
25
+ var relationships = {};
26
+ var relationshipElements = element.getElementsByTagName('Relationship');
27
+ try {
28
+ for (var relationshipElements_1 = tslib_es6.__values(relationshipElements), relationshipElements_1_1 = relationshipElements_1.next(); !relationshipElements_1_1.done; relationshipElements_1_1 = relationshipElements_1.next()) {
29
+ var relationshipElement = relationshipElements_1_1.value;
30
+ var relationship = parseRelationship(relationshipElement, part);
31
+ relationships[relationship.id] = relationship;
32
+ }
33
+ }
34
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
35
+ finally {
36
+ try {
37
+ if (relationshipElements_1_1 && !relationshipElements_1_1.done && (_a = relationshipElements_1.return)) _a.call(relationshipElements_1);
38
+ }
39
+ finally { if (e_1) throw e_1.error; }
40
+ }
41
+ return relationships;
42
+ }
43
+
44
+ exports.parseRelationship = parseRelationship;
45
+ exports.parseRelationships = parseRelationships;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * 单位相关的解析,参考了 docxjs 里的实现
3
+ */
4
+ export type LengthType = 'px' | 'pt' | '%' | '';
5
+ export type LengthUsageType = {
6
+ mul: number;
7
+ unit: LengthType;
8
+ };
9
+ export declare const LengthUsage: Record<string, LengthUsageType>;
10
+ export declare function convertLength(val: string, usage?: LengthUsageType): string;
11
+ /**
12
+ * 转换布尔值
13
+ */
14
+ export declare function convertBoolean(v: string, defaultValue?: boolean): boolean;
15
+ export declare function convertPercentage(val: string): number;
16
+ /**
17
+ * 解析尺寸,返回 css 值
18
+ *
19
+ * @param element 节点
20
+ * @param attrName 属性名
21
+ * @param usage 类型
22
+ */
23
+ export declare function parseSize(element: Element, attrName: string, usage?: LengthUsageType): string;
24
+ /**
25
+ * 参考 docxjs 的方法,后面可以优化一下,不使用 calc
26
+ */
27
+ export declare function addSize(a: string, b: string): string;
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /**
6
+ * 单位相关的解析,参考了 docxjs 里的实现
7
+ */
8
+ var ptToPx = 1.3333;
9
+ var LengthUsage = {
10
+ Dxa: { mul: ptToPx * 0.05, unit: 'px' },
11
+ Emu: { mul: (ptToPx * 1) / 12700, unit: 'px' },
12
+ FontSize: { mul: ptToPx * 0.5, unit: 'px' },
13
+ Border: { mul: ptToPx * 0.125, unit: 'px' },
14
+ Point: { mul: ptToPx * 1, unit: 'px' },
15
+ Percent: { mul: 0.02, unit: '%' },
16
+ LineHeight: { mul: 1 / 240, unit: '' },
17
+ VmlEmu: { mul: 1 / 12700, unit: '' }
18
+ };
19
+ function convertLength(val, usage) {
20
+ if (usage === void 0) { usage = LengthUsage.Dxa; }
21
+ if (val == null || /.+(p[xt]|[%])$/.test(val)) {
22
+ return val;
23
+ }
24
+ return "".concat((parseInt(val) * usage.mul).toFixed(2)).concat(usage.unit);
25
+ }
26
+ /**
27
+ * 解析尺寸,返回 css 值
28
+ *
29
+ * @param element 节点
30
+ * @param attrName 属性名
31
+ * @param usage 类型
32
+ */
33
+ function parseSize(element, attrName, usage) {
34
+ if (usage === void 0) { usage = LengthUsage.Dxa; }
35
+ var size = element.getAttribute(attrName);
36
+ if (size) {
37
+ return convertLength(String(size), usage);
38
+ }
39
+ return '';
40
+ }
41
+
42
+ exports.LengthUsage = LengthUsage;
43
+ exports.convertLength = convertLength;
44
+ exports.parseSize = parseSize;
@@ -0,0 +1,7 @@
1
+ import { CSSStyle } from '../openxml/Style';
2
+ import Word from '../Word';
3
+ /**
4
+ * 解析 spacing
5
+ * http://officeopenxml.com/WPspacing.php
6
+ */
7
+ export declare function parseSpacing(word: Word, element: Element, style: CSSStyle): void;
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var parseSize = require('./parseSize.js');
6
+
7
+ /**
8
+ * 解析 spacing
9
+ * http://officeopenxml.com/WPspacing.php
10
+ */
11
+ function parseSpacing(word, element, style) {
12
+ var before = parseSize.parseSize(element, 'w:before');
13
+ var after = parseSize.parseSize(element, 'w:after');
14
+ var lineRule = element.getAttribute('w:lineRule');
15
+ if (before) {
16
+ style['margin-top'] = before;
17
+ }
18
+ if (after) {
19
+ style['margin-bottom'] = after;
20
+ }
21
+ var line = element.getAttribute('w:line');
22
+ if (line) {
23
+ // 强制行高
24
+ if (word.renderOptions.forceLineHeight) {
25
+ style['line-height'] = word.renderOptions.forceLineHeight;
26
+ return;
27
+ }
28
+ var lineNum = parseInt(line, 10);
29
+ var minLineHeight = word.renderOptions.minLineHeight || 1.0;
30
+ switch (lineRule) {
31
+ case 'auto':
32
+ var lineHeight = Math.max(minLineHeight, lineNum / 240);
33
+ style['line-height'] = "".concat(lineHeight.toFixed(2));
34
+ break;
35
+ case 'atLeast':
36
+ // 不知道这样处理是否正确,先用默认好了
37
+ // style['line-height'] = `calc(100% + ${lineNum / 20}pt)`;
38
+ break;
39
+ default:
40
+ var lineHeightMin = Math.max(minLineHeight, lineNum / 20);
41
+ style['line-height'] = style['min-height'] = "".concat(lineHeightMin, "pt");
42
+ break;
43
+ }
44
+ }
45
+ }
46
+
47
+ exports.parseSpacing = parseSpacing;
@@ -0,0 +1,2 @@
1
+ import { CSSStyle } from '../openxml/Style';
2
+ export declare function parseTextDirection(element: Element, style: CSSStyle): void;
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var Types = require('../openxml/Types.js');
6
+
7
+ function parseTextDirection(element, style) {
8
+ var val = element.getAttribute('w:val');
9
+ // 目前值支持 ltr 或 rtl
10
+ // 奇怪这里的类型定义不完整,可能是脚本的问题
11
+ switch (val) {
12
+ case Types.ST_TextDirection.lr:
13
+ case Types.ST_TextDirection.lrV:
14
+ case 'btLr':
15
+ case 'lrTb':
16
+ case 'lrTbV':
17
+ case 'tbLrV':
18
+ style['direction'] = 'ltr';
19
+ break;
20
+ case Types.ST_TextDirection.rl:
21
+ case Types.ST_TextDirection.rlV:
22
+ case 'tbRl':
23
+ case 'tbRlV':
24
+ style['direction'] = 'rtl';
25
+ break;
26
+ }
27
+ }
28
+
29
+ exports.parseTextDirection = parseTextDirection;
@@ -0,0 +1,2 @@
1
+ import { CSSStyle } from '../openxml/Style';
2
+ export declare function parseTrHeight(child: Element, style: CSSStyle): void;
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var parseSize = require('./parseSize.js');
6
+
7
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/trHeight.html
8
+ function parseTrHeight(child, style) {
9
+ var height = parseSize.parseSize(child, 'w:val');
10
+ var hRule = child.getAttribute('w:hRule');
11
+ if (hRule === 'exact') {
12
+ style['height'] = height;
13
+ }
14
+ else if (hRule === 'atLeast') {
15
+ // tr 设置 min-height 似乎是没效果的
16
+ style['height'] = height;
17
+ style['min-height'] = height;
18
+ }
19
+ }
20
+
21
+ exports.parseTrHeight = parseTrHeight;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 渲染 body 节点
3
+ */
4
+ import Word from '../Word';
5
+ import { Body } from '../openxml/word/Body';
6
+ export default function renderBody(word: Word, parent: HTMLElement, body: Body): void;
@@ -0,0 +1,57 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var tslib_es6 = require('../node_modules/tslib/tslib.es6.js');
6
+ var dom = require('../util/dom.js');
7
+ var Paragraph = require('../openxml/word/Paragraph.js');
8
+ var Table = require('../openxml/word/Table.js');
9
+ var Hyperlink = require('../openxml/word/Hyperlink.js');
10
+ var renderParagraph = require('./renderParagraph.js');
11
+ var renderSection = require('./renderSection.js');
12
+ var renderTable = require('./renderTable.js');
13
+
14
+ /**
15
+ * 渲染 body 节点
16
+ */
17
+ function renderBody(word, parent, body) {
18
+ var e_1, _a, e_2, _b;
19
+ try {
20
+ for (var _c = tslib_es6.__values(body.sections), _d = _c.next(); !_d.done; _d = _c.next()) {
21
+ var section = _d.value;
22
+ var sectionEl = renderSection.renderSection(word, section);
23
+ dom.appendChild(parent, sectionEl);
24
+ try {
25
+ for (var _e = (e_2 = void 0, tslib_es6.__values(section.children)), _f = _e.next(); !_f.done; _f = _e.next()) {
26
+ var child = _f.value;
27
+ if (child instanceof Paragraph.Paragraph) {
28
+ var p = renderParagraph["default"](word, child);
29
+ dom.appendChild(sectionEl, p);
30
+ }
31
+ else if (child instanceof Table.Table) {
32
+ dom.appendChild(sectionEl, renderTable["default"](word, child));
33
+ }
34
+ else if (child instanceof Hyperlink.Hyperlink) {
35
+ }
36
+ }
37
+ }
38
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
39
+ finally {
40
+ try {
41
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
42
+ }
43
+ finally { if (e_2) throw e_2.error; }
44
+ }
45
+ dom.appendChild(parent, sectionEl);
46
+ }
47
+ }
48
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
49
+ finally {
50
+ try {
51
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
52
+ }
53
+ finally { if (e_1) throw e_1.error; }
54
+ }
55
+ }
56
+
57
+ exports["default"] = renderBody;
@@ -0,0 +1,6 @@
1
+ import { BookmarkStart } from '../openxml/word/Bookmark';
2
+ import Word from '../Word';
3
+ /**
4
+ * 渲染书签
5
+ */
6
+ export declare function renderBookmarkStart(word: Word, bookmarkStart: BookmarkStart): HTMLAnchorElement | null;
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var dom = require('../util/dom.js');
6
+
7
+ /**
8
+ * 渲染书签
9
+ */
10
+ function renderBookmarkStart(word, bookmarkStart) {
11
+ var name = bookmarkStart.name;
12
+ if (name) {
13
+ var bookmark = dom.createElement('a');
14
+ bookmark.name = name;
15
+ bookmark.id = name;
16
+ return bookmark;
17
+ }
18
+ return null;
19
+ }
20
+
21
+ exports.renderBookmarkStart = renderBookmarkStart;