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,31 @@
1
+ /**
2
+ * openxml 默认是 zip 格式,导致构造比较麻烦,所以增加了这种单一格式,所有内容都放在一个 xml 文件里
3
+ */
4
+ import { PackageParser } from './PackageParser';
5
+ export default class XMLPackageParser implements PackageParser {
6
+ private xml;
7
+ private files;
8
+ private contentTypesDoc;
9
+ /**
10
+ * 加载 zip 文件
11
+ */
12
+ load(fileContent: ArrayBuffer | string): void;
13
+ /**
14
+ * 读取 xml 文件,转成 json 对象
15
+ * @param filePath 文件路径
16
+ * @returns 转成 json 的结果
17
+ */
18
+ getXML(filePath: string): Document;
19
+ /**
20
+ * 在 xml 下基本不用这个
21
+ */
22
+ getFileByType(filePath: string, type: 'string' | 'blob'): string;
23
+ /**
24
+ * 判断文件是否存在
25
+ */
26
+ fileExists(filePath: string): boolean;
27
+ /**
28
+ * 生成 zip 文件
29
+ */
30
+ generateZip(docContent: string): Blob;
31
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * zip 文件解析
3
+ */
4
+ import { PackageParser } from './PackageParser';
5
+ export default class ZipPackageParser implements PackageParser {
6
+ private zip;
7
+ /**
8
+ * 加载 zip 文件
9
+ */
10
+ load(docxFile: ArrayBuffer): void;
11
+ /**
12
+ * 读取 xml 文件,转成 json 对象
13
+ * @param filePath 文件路径
14
+ * @returns 转成 json 的结果
15
+ */
16
+ getXML(filePath: string): Document;
17
+ /**
18
+ * 根据类型读取文件
19
+ */
20
+ getFileByType(filePath: string, type: 'string' | 'blob'): string | Blob;
21
+ /**
22
+ * 判断文件是否存在
23
+ */
24
+ fileExists(filePath: string): boolean;
25
+ /**
26
+ * 生成新的 zip 文件
27
+ */
28
+ generateZip(docContent: string): Blob;
29
+ }
@@ -0,0 +1,74 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var fflate = require('fflate');
6
+
7
+ /**
8
+ * zip 文件解析
9
+ */
10
+ var ZipPackageParser = /** @class */ (function () {
11
+ function ZipPackageParser() {
12
+ }
13
+ /**
14
+ * 加载 zip 文件
15
+ */
16
+ ZipPackageParser.prototype.load = function (docxFile) {
17
+ this.zip = fflate.unzipSync(new Uint8Array(docxFile), {
18
+ filter: function (file) {
19
+ // 不解析大于 10 MiB 的文件
20
+ return file.originalSize <= 10000000;
21
+ }
22
+ });
23
+ };
24
+ /**
25
+ * 读取 xml 文件,转成 json 对象
26
+ * @param filePath 文件路径
27
+ * @returns 转成 json 的结果
28
+ */
29
+ ZipPackageParser.prototype.getXML = function (filePath) {
30
+ var fileContent = this.getFileByType(filePath, 'string');
31
+ var doc = new DOMParser().parseFromString(fileContent, 'application/xml');
32
+ var errorNode = doc.querySelector('parsererror');
33
+ if (errorNode) {
34
+ throw new Error(errorNode.textContent || "can't parse xml");
35
+ }
36
+ else {
37
+ return doc;
38
+ }
39
+ };
40
+ /**
41
+ * 根据类型读取文件
42
+ */
43
+ ZipPackageParser.prototype.getFileByType = function (filePath, type) {
44
+ filePath = filePath.startsWith('/') ? filePath.slice(1) : filePath;
45
+ var file = this.zip[filePath];
46
+ if (file) {
47
+ if (type === 'string') {
48
+ return fflate.strFromU8(file);
49
+ }
50
+ else if (type === 'blob') {
51
+ return new Blob([file]);
52
+ }
53
+ }
54
+ throw new Error('file not found');
55
+ };
56
+ /**
57
+ * 判断文件是否存在
58
+ */
59
+ ZipPackageParser.prototype.fileExists = function (filePath) {
60
+ filePath = filePath.startsWith('/') ? filePath.slice(1) : filePath;
61
+ return filePath in this.zip;
62
+ };
63
+ /**
64
+ * 生成新的 zip 文件
65
+ */
66
+ ZipPackageParser.prototype.generateZip = function (docContent) {
67
+ // 其实最好是生成个新的,后续再优化
68
+ this.zip['word/document.xml'] = fflate.strToU8(docContent);
69
+ return new Blob([fflate.zipSync(this.zip)]);
70
+ };
71
+ return ZipPackageParser;
72
+ }());
73
+
74
+ exports["default"] = ZipPackageParser;
@@ -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,25 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /** 将 jc 转成 text-align
6
+ *
7
+ * http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/ST_Jc.html
8
+ */
9
+ function jcToTextAlign(jc) {
10
+ switch (jc) {
11
+ case 'start':
12
+ case 'left':
13
+ return 'left';
14
+ case 'center':
15
+ return 'center';
16
+ case 'end':
17
+ case 'right':
18
+ return 'right';
19
+ case 'both':
20
+ return 'justify';
21
+ }
22
+ return jc;
23
+ }
24
+
25
+ exports.jcToTextAlign = 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,83 @@
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 OpenXML = require('../OpenXML.js');
7
+ var parseColor = require('./parseColor.js');
8
+ var parseSize = require('./parseSize.js');
9
+ var Types = require('../openxml/Types.js');
10
+
11
+ // 默认边框颜色
12
+ var DEFAULT_BORDER_COLOR = 'black';
13
+ /**
14
+ * 解析单个边框样式
15
+ */
16
+ function parseBorder(word, element) {
17
+ var type = OpenXML.getVal(element);
18
+ if (type === Types.ST_Border.nil || type === Types.ST_Border.none) {
19
+ return 'none';
20
+ }
21
+ // 这里和 css 不完全一致,css 能表现的要少很多,也是导致展现效果难以一致的原因
22
+ switch (type) {
23
+ case Types.ST_Border.dashed:
24
+ case Types.ST_Border.dashDotStroked:
25
+ case Types.ST_Border.dashSmallGap:
26
+ break;
27
+ case Types.ST_Border.dotDash:
28
+ case Types.ST_Border.dotDotDash:
29
+ case Types.ST_Border.dotted:
30
+ break;
31
+ case Types.ST_Border.double:
32
+ case Types.ST_Border.doubleWave:
33
+ break;
34
+ case Types.ST_Border.inset:
35
+ break;
36
+ case Types.ST_Border.outset:
37
+ break;
38
+ }
39
+ var color = parseColor.parseColorAttr(word, element);
40
+ var size = parseSize.parseSize(element, 'w:sz', parseSize.LengthUsage.Border);
41
+ return "".concat(size, " solid ").concat(color == 'auto' ? DEFAULT_BORDER_COLOR : color);
42
+ }
43
+ /**
44
+ * 解析边框
45
+ */
46
+ function parseBorders(word, element, style) {
47
+ var e_1, _a;
48
+ try {
49
+ for (var _b = tslib_es6.__values(element.children), _c = _b.next(); !_c.done; _c = _b.next()) {
50
+ var child = _c.value;
51
+ var tagName = child.tagName;
52
+ switch (tagName) {
53
+ case 'w:start':
54
+ case 'w:left':
55
+ style['border-left'] = parseBorder(word, child);
56
+ break;
57
+ case 'w:end':
58
+ case 'w:right':
59
+ style['border-right'] = parseBorder(word, child);
60
+ break;
61
+ case 'w:top':
62
+ style['border-top'] = parseBorder(word, child);
63
+ break;
64
+ case 'w:bottom':
65
+ style['border-bottom'] = parseBorder(word, child);
66
+ break;
67
+ // TODO: 还有个 between 不知道是干啥的
68
+ default:
69
+ break;
70
+ }
71
+ }
72
+ }
73
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
74
+ finally {
75
+ try {
76
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
77
+ }
78
+ finally { if (e_1) throw e_1.error; }
79
+ }
80
+ }
81
+
82
+ exports.parseBorder = parseBorder;
83
+ exports.parseBorders = 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,137 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var OpenXML = require('../OpenXML.js');
6
+ var Types = require('../openxml/Types.js');
7
+
8
+ /**
9
+ * 解析颜色,转成 css 的颜色
10
+ */
11
+ var knownColors = [
12
+ 'black',
13
+ 'blue',
14
+ 'cyan',
15
+ 'darkBlue',
16
+ 'darkCyan',
17
+ 'darkGray',
18
+ 'darkGreen',
19
+ 'darkMagenta',
20
+ 'darkRed',
21
+ 'darkYellow',
22
+ 'green',
23
+ 'lightGray',
24
+ 'magenta',
25
+ 'none',
26
+ 'red',
27
+ 'white',
28
+ 'yellow'
29
+ ];
30
+ /**
31
+ *
32
+ * 解析属性上的 color,比如 <w:top w:val="single" w:sz="24" w:space="1" w:color="FF0000" />
33
+ * @param attrName color 默认属性
34
+ * @param autoColor 默认值
35
+ * @returns css 颜色
36
+ */
37
+ function parseColorAttr(word, element, attrName, autoColor) {
38
+ if (attrName === void 0) { attrName = 'w:color'; }
39
+ if (autoColor === void 0) { autoColor = 'black'; }
40
+ var color = element.getAttribute(attrName);
41
+ if (color) {
42
+ if (color == 'auto') {
43
+ return autoColor;
44
+ }
45
+ else if (typeof color === 'string' && knownColors.includes(color)) {
46
+ return color;
47
+ }
48
+ return "#".concat(color);
49
+ }
50
+ var themeColor = element.getAttribute('w:themeColor');
51
+ return themeColor ? word.getThemeColor(themeColor) : '';
52
+ }
53
+ /**
54
+ * 专门用来支持 shd 的颜色
55
+ * http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/ST_Shd.html
56
+ */
57
+ function parseShdColor(word, element) {
58
+ var color = element.getAttribute('w:fill') || '';
59
+ var val = OpenXML.getVal(element);
60
+ if (color === 'auto') {
61
+ color = 'inherit';
62
+ }
63
+ if (color.length === 6) {
64
+ switch (val) {
65
+ case Types.ST_Shd.clear:
66
+ return "#".concat(color);
67
+ case Types.ST_Shd.pct10:
68
+ return colorPercent(color, 0.1);
69
+ case Types.ST_Shd.pct12:
70
+ return colorPercent(color, 0.125);
71
+ case Types.ST_Shd.pct15:
72
+ return colorPercent(color, 0.15);
73
+ case Types.ST_Shd.pct20:
74
+ return colorPercent(color, 0.2);
75
+ case Types.ST_Shd.pct25:
76
+ return colorPercent(color, 0.25);
77
+ case Types.ST_Shd.pct30:
78
+ return colorPercent(color, 0.3);
79
+ case Types.ST_Shd.pct35:
80
+ return colorPercent(color, 0.35);
81
+ case Types.ST_Shd.pct37:
82
+ return colorPercent(color, 0.375);
83
+ case Types.ST_Shd.pct40:
84
+ return colorPercent(color, 0.4);
85
+ case Types.ST_Shd.pct45:
86
+ return colorPercent(color, 0.45);
87
+ case Types.ST_Shd.pct5:
88
+ return colorPercent(color, 0.05);
89
+ case Types.ST_Shd.pct50:
90
+ return colorPercent(color, 0.5);
91
+ case Types.ST_Shd.pct55:
92
+ return colorPercent(color, 0.55);
93
+ case Types.ST_Shd.pct60:
94
+ return colorPercent(color, 0.6);
95
+ case Types.ST_Shd.pct65:
96
+ return colorPercent(color, 0.65);
97
+ case Types.ST_Shd.pct70:
98
+ return colorPercent(color, 0.7);
99
+ case Types.ST_Shd.pct75:
100
+ return colorPercent(color, 0.75);
101
+ case Types.ST_Shd.pct80:
102
+ return colorPercent(color, 0.8);
103
+ case Types.ST_Shd.pct85:
104
+ return colorPercent(color, 0.85);
105
+ case Types.ST_Shd.pct87:
106
+ return colorPercent(color, 0.87);
107
+ case Types.ST_Shd.pct90:
108
+ return colorPercent(color, 0.9);
109
+ case Types.ST_Shd.pct95:
110
+ return colorPercent(color, 0.95);
111
+ default:
112
+ console.warn('unsupport shd val', val);
113
+ return "#".concat(color);
114
+ }
115
+ }
116
+ return '';
117
+ }
118
+ /**
119
+ * 用 alpha 来模拟 ptc 功能
120
+ */
121
+ function colorPercent(color, percent) {
122
+ var r = parseInt(color.substring(0, 2), 16);
123
+ var g = parseInt(color.substring(2, 4), 16);
124
+ var b = parseInt(color.substring(4, 6), 16);
125
+ return "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(percent, ")");
126
+ }
127
+ /**
128
+ * 解析 color 标签,比如 <w:color w:themeColor="accent3" />
129
+ * @returns css 颜色
130
+ */
131
+ function parseColor(word, element) {
132
+ return parseColorAttr(word, element, 'w:val');
133
+ }
134
+
135
+ exports.parseColor = parseColor;
136
+ exports.parseColorAttr = parseColorAttr;
137
+ exports.parseShdColor = 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,58 @@
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
+ * 解析字体
9
+ * http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/rFonts.html
10
+ */
11
+ function themeFont(font) {
12
+ return "var(--docx-theme-font-".concat(font, ")");
13
+ }
14
+ function parseFont(word, element, style) {
15
+ var e_1, _a;
16
+ var fonts = [];
17
+ var fontMapping = word.renderOptions.fontMapping;
18
+ try {
19
+ for (var _b = tslib_es6.__values(element.attributes), _c = _b.next(); !_c.done; _c = _b.next()) {
20
+ var attribute = _c.value;
21
+ var name_1 = attribute.name;
22
+ var value = attribute.value;
23
+ switch (name_1) {
24
+ case 'w:ascii':
25
+ case 'w:cs':
26
+ case 'w:eastAsia':
27
+ if (fontMapping && value in fontMapping) {
28
+ value = fontMapping[value];
29
+ }
30
+ if (value.indexOf(' ') === -1) {
31
+ fonts.push(value);
32
+ }
33
+ else {
34
+ fonts.push('"' + value + '"');
35
+ }
36
+ break;
37
+ case 'w:asciiTheme':
38
+ case 'w:csTheme':
39
+ case 'w:eastAsiaTheme':
40
+ fonts.push(themeFont(value));
41
+ break;
42
+ }
43
+ }
44
+ }
45
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
46
+ finally {
47
+ try {
48
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
49
+ }
50
+ finally { if (e_1) throw e_1.error; }
51
+ }
52
+ // hint 之类的不支持,因为也很难控制到这个粒度了
53
+ if (fonts.length) {
54
+ style['font-family'] = Array.from(new Set(fonts)).join(', ');
55
+ }
56
+ }
57
+
58
+ exports.parseFont = 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,31 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var parseSize = require('./parseSize.js');
6
+
7
+ /**
8
+ * 解析缩进 http://officeopenxml.com/WPindentation.php
9
+ */
10
+ function parseInd(element, style) {
11
+ var firstLine = parseSize.parseSize(element, 'w:firstLine');
12
+ var hanging = parseSize.parseSize(element, 'w:hanging');
13
+ var left = parseSize.parseSize(element, 'w:left');
14
+ var start = parseSize.parseSize(element, 'w:start');
15
+ var right = parseSize.parseSize(element, 'w:right');
16
+ var end = parseSize.parseSize(element, 'w:end');
17
+ if (firstLine) {
18
+ style['text-indent'] = firstLine;
19
+ }
20
+ if (hanging) {
21
+ style['text-indent'] = "-".concat(hanging);
22
+ }
23
+ if (left || start) {
24
+ style['margin-left'] = left || start;
25
+ }
26
+ if (right || end) {
27
+ style['margin-right'] = right || end;
28
+ }
29
+ }
30
+
31
+ exports.parseInd = 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;