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