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,46 @@
1
+ import { __values } from '../../../node_modules/tslib/tslib.es6.js';
2
+ import { getVal } from '../../../OpenXML.js';
3
+ import { Lvl } from './Lvl.js';
4
+
5
+ var Num = /** @class */ (function () {
6
+ function Num() {
7
+ this.lvlOverride = { lvls: {} };
8
+ }
9
+ Num.fromXML = function (word, element) {
10
+ var e_1, _a;
11
+ var num = new Num();
12
+ num.numId = element.getAttribute('w:numId') || '';
13
+ var abstractNumId = element.querySelector('abstractNumId');
14
+ if (abstractNumId) {
15
+ num.abstractNumId = getVal(abstractNumId);
16
+ }
17
+ var lvlOverride = element.querySelector('lvlOverride');
18
+ if (lvlOverride) {
19
+ try {
20
+ for (var _b = __values(lvlOverride.children), _c = _b.next(); !_c.done; _c = _b.next()) {
21
+ var child = _c.value;
22
+ var tagName = child.tagName;
23
+ switch (tagName) {
24
+ case 'w:lvl':
25
+ var lvlId = child.getAttribute('w:lvlId') || '';
26
+ num.lvlOverride.lvls[lvlId] = Lvl.fromXML(word, child);
27
+ break;
28
+ default:
29
+ console.warn("Num: Unknown tag ", tagName, child);
30
+ }
31
+ }
32
+ }
33
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
34
+ finally {
35
+ try {
36
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
37
+ }
38
+ finally { if (e_1) throw e_1.error; }
39
+ }
40
+ }
41
+ return num;
42
+ };
43
+ return Num;
44
+ }());
45
+
46
+ export { Num };
@@ -0,0 +1,6 @@
1
+ import Word from '../../../Word';
2
+ export declare class NumberPr {
3
+ ilvl: string;
4
+ numId: string;
5
+ static fromXML(word: Word, element: Element): NumberPr;
6
+ }
@@ -0,0 +1,21 @@
1
+ import { getVal } from '../../../OpenXML.js';
2
+
3
+ var NumberPr = /** @class */ (function () {
4
+ function NumberPr() {
5
+ }
6
+ NumberPr.fromXML = function (word, element) {
7
+ var numPr = new NumberPr();
8
+ var ilvl = element.querySelector('ilvl');
9
+ if (ilvl) {
10
+ numPr.ilvl = getVal(ilvl);
11
+ }
12
+ var numId = element.querySelector('numId');
13
+ if (numId) {
14
+ numPr.numId = getVal(numId);
15
+ }
16
+ return numPr;
17
+ };
18
+ return NumberPr;
19
+ }());
20
+
21
+ export { NumberPr };
@@ -0,0 +1,9 @@
1
+ import Word from '../../../Word';
2
+ import { AbstractNum } from './AbstractNum';
3
+ import { Num } from './Num';
4
+ export declare class Numbering {
5
+ abstractNums: Record<string, AbstractNum>;
6
+ nums: Record<string, Num>;
7
+ numData: Record<string, Record<string, number>>;
8
+ static fromXML(word: Word, element: Document): Numbering;
9
+ }
@@ -0,0 +1,50 @@
1
+ import { __values } from '../../../node_modules/tslib/tslib.es6.js';
2
+ import { AbstractNum } from './AbstractNum.js';
3
+ import { Num } from './Num.js';
4
+
5
+ var Numbering = /** @class */ (function () {
6
+ function Numbering() {
7
+ this.abstractNums = {};
8
+ this.nums = {};
9
+ // 某个 numId 当前值,如果要重新渲染文档,需要将这个置空,
10
+ // 第一个 key 是 numId,第二个 key 是 ilvl,第一个 key 会自动初始化
11
+ this.numData = {};
12
+ }
13
+ Numbering.fromXML = function (word, element) {
14
+ var e_1, _a, e_2, _b;
15
+ var numbering = new Numbering();
16
+ try {
17
+ for (var _c = __values(element.getElementsByTagName('w:abstractNum')), _d = _c.next(); !_d.done; _d = _c.next()) {
18
+ var abstractNumElement = _d.value;
19
+ var abstractNum = AbstractNum.fromXML(word, abstractNumElement);
20
+ numbering.abstractNums[abstractNum.abstractNumId] = abstractNum;
21
+ }
22
+ }
23
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
24
+ finally {
25
+ try {
26
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
27
+ }
28
+ finally { if (e_1) throw e_1.error; }
29
+ }
30
+ try {
31
+ for (var _e = __values(element.getElementsByTagName('w:num')), _f = _e.next(); !_f.done; _f = _e.next()) {
32
+ var numElement = _f.value;
33
+ var num = Num.fromXML(word, numElement);
34
+ numbering.nums[num.numId] = num;
35
+ numbering.numData[num.numId] = {};
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
+ return numbering;
46
+ };
47
+ return Numbering;
48
+ }());
49
+
50
+ export { Numbering };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 属性通用设置项
3
+ */
4
+ import { CSSStyle } from '../../Style';
5
+ export interface Properties {
6
+ /**
7
+ * 解析后的 css 样式
8
+ */
9
+ cssStyle?: CSSStyle;
10
+ pStyle?: string;
11
+ rStyle?: string;
12
+ }
@@ -0,0 +1,46 @@
1
+ import Word from '../../../Word';
2
+ import { CSSStyle } from '../../Style';
3
+ import { Paragraph } from '../Paragraph';
4
+ import { Table } from '../Table';
5
+ import { ST_Merge } from '../../Types';
6
+ export interface TcPr {
7
+ cssStyle?: CSSStyle;
8
+ hideMark?: false;
9
+ vMerge?: ST_Merge;
10
+ gridSpan?: number;
11
+ rowSpan?: number;
12
+ /**
13
+ * 内部 border,需要作用于非第一列的单元格
14
+ */
15
+ insideBorder?: {
16
+ H?: string;
17
+ V?: string;
18
+ };
19
+ }
20
+ type TcChild = Paragraph | Table;
21
+ export declare function parseCellMargin(element: Element, style: CSSStyle): void;
22
+ export declare function parseTblCellSpacing(element: Element, style: CSSStyle): void;
23
+ /**
24
+ * parseBorders 不支持 insideH 和 insideV,所以单独支持一下
25
+ * 实际显示时需要过滤掉第一列
26
+ */
27
+ export declare function parseInsideBorders(word: Word, element: Element): {
28
+ H: string | undefined;
29
+ V: string | undefined;
30
+ };
31
+ /**
32
+ * http://officeopenxml.com/WPtableWidth.php
33
+ */
34
+ export declare function parseTblWidth(element: Element): string;
35
+ export declare class Tc {
36
+ properties: TcPr;
37
+ children: TcChild[];
38
+ add(child: TcChild): void;
39
+ static parseTcPr(word: Word, element: Element): TcPr;
40
+ static fromXML(word: Word, element: Element, currentCol: {
41
+ index: number;
42
+ }, rowSpanMap: {
43
+ [key: string]: Tc;
44
+ }): Tc | null;
45
+ }
46
+ export {};
@@ -0,0 +1,234 @@
1
+ import { __values } from '../../../node_modules/tslib/tslib.es6.js';
2
+ import { getVal, getValNumber, getValBoolean } from '../../../OpenXML.js';
3
+ import { Paragraph } from '../Paragraph.js';
4
+ import { Table } from '../Table.js';
5
+ import { parseSize, LengthUsage } from '../../../parse/parseSize.js';
6
+ import { parseShdColor } from '../../../parse/parseColor.js';
7
+ import { parseBorders, parseBorder } from '../../../parse/parseBorder.js';
8
+ import { parseTextDirection } from '../../../parse/parseTextDirection.js';
9
+ import { ST_Merge, ST_VerticalJc, ST_TblWidth } from '../../Types.js';
10
+
11
+ // http://officeopenxml.com/WPtableCellProperties-Margins.php
12
+ function parseCellMargin(element, style) {
13
+ var e_1, _a;
14
+ try {
15
+ for (var _b = __values(element.children), _c = _b.next(); !_c.done; _c = _b.next()) {
16
+ var child = _c.value;
17
+ var tagName = child.tagName;
18
+ switch (tagName) {
19
+ case 'w:left':
20
+ case 'w:start':
21
+ style['padding-left'] = parseSize(child, 'w:w');
22
+ break;
23
+ case 'w:right':
24
+ case 'w:end':
25
+ style['padding-right'] = parseSize(child, 'w:w');
26
+ break;
27
+ case 'w:top':
28
+ style['padding-top'] = parseSize(child, 'w:w');
29
+ break;
30
+ case 'w:bottom':
31
+ style['padding-bottom'] = parseSize(child, 'w:w');
32
+ break;
33
+ }
34
+ }
35
+ }
36
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
37
+ finally {
38
+ try {
39
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
40
+ }
41
+ finally { if (e_1) throw e_1.error; }
42
+ }
43
+ }
44
+ function parseVAlign(element, style) {
45
+ var vAlign = getVal(element);
46
+ switch (vAlign) {
47
+ case ST_VerticalJc.bottom:
48
+ style['vertical-align'] = 'bottom';
49
+ break;
50
+ case ST_VerticalJc.center:
51
+ style['vertical-align'] = 'middle';
52
+ break;
53
+ case ST_VerticalJc.top:
54
+ style['vertical-align'] = 'top';
55
+ break;
56
+ }
57
+ }
58
+ function parseTblCellSpacing(element, style) {
59
+ var width = parseTblWidth(element);
60
+ if (width) {
61
+ style['cell-spacing'] = width;
62
+ }
63
+ }
64
+ /**
65
+ * parseBorders 不支持 insideH 和 insideV,所以单独支持一下
66
+ * 实际显示时需要过滤掉第一列
67
+ */
68
+ function parseInsideBorders(word, element) {
69
+ var H;
70
+ var insideH = element.querySelector('insideH');
71
+ if (insideH) {
72
+ H = parseBorder(word, insideH);
73
+ }
74
+ var V;
75
+ var insideV = element.querySelector('insideV');
76
+ if (insideV) {
77
+ V = parseBorder(word, insideV);
78
+ }
79
+ return {
80
+ H: H,
81
+ V: V
82
+ };
83
+ }
84
+ /**
85
+ * http://officeopenxml.com/WPtableWidth.php
86
+ */
87
+ function parseTblWidth(element) {
88
+ var type = element.getAttribute('w:type');
89
+ if (!type || type === ST_TblWidth.dxa) {
90
+ return parseSize(element, 'w:w');
91
+ }
92
+ else if (type === ST_TblWidth.pct) {
93
+ return parseSize(element, 'w:w', LengthUsage.Percent);
94
+ }
95
+ else if (type === ST_TblWidth.auto) {
96
+ return 'auto';
97
+ }
98
+ else {
99
+ console.warn('parseTblWidth: ignore type', type, element);
100
+ }
101
+ return '';
102
+ }
103
+ function parseTcW(element, style) {
104
+ var width = parseTblWidth(element);
105
+ if (width) {
106
+ style.width = width;
107
+ }
108
+ }
109
+ var Tc = /** @class */ (function () {
110
+ function Tc() {
111
+ this.properties = {};
112
+ this.children = [];
113
+ }
114
+ Tc.prototype.add = function (child) {
115
+ if (child) {
116
+ this.children.push(child);
117
+ }
118
+ };
119
+ Tc.parseTcPr = function (word, element) {
120
+ var e_2, _a;
121
+ var properties = {};
122
+ var style = {};
123
+ properties.cssStyle = style;
124
+ try {
125
+ for (var _b = __values(element.children), _c = _b.next(); !_c.done; _c = _b.next()) {
126
+ var child = _c.value;
127
+ var tagName = child.tagName;
128
+ switch (tagName) {
129
+ case 'w:tcMar':
130
+ parseCellMargin(child, style);
131
+ break;
132
+ case 'w:shd':
133
+ style['background-color'] = parseShdColor(word, child);
134
+ break;
135
+ case 'w:tcW':
136
+ parseTcW(child, style);
137
+ break;
138
+ case 'w:noWrap':
139
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/noWrap.html
140
+ var noWrap = getValBoolean(child);
141
+ if (noWrap) {
142
+ style['white-space'] = 'nowrap';
143
+ }
144
+ break;
145
+ case 'w:vAlign':
146
+ parseVAlign(child, style);
147
+ break;
148
+ case 'w:tcBorders':
149
+ parseBorders(word, child, style);
150
+ properties.insideBorder = parseInsideBorders(word, child);
151
+ break;
152
+ case 'w:gridSpan':
153
+ properties.gridSpan = getValNumber(child);
154
+ break;
155
+ case 'w:vMerge':
156
+ properties.vMerge = getVal(child) || ST_Merge.continue;
157
+ break;
158
+ case 'w:textDirection':
159
+ parseTextDirection(child, style);
160
+ break;
161
+ case 'w:cnfStyle':
162
+ // 目前是自动计算的,所以不需要这个了
163
+ break;
164
+ default:
165
+ console.warn('parseTcPr: ignore', tagName, child);
166
+ }
167
+ }
168
+ }
169
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
170
+ finally {
171
+ try {
172
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
173
+ }
174
+ finally { if (e_2) throw e_2.error; }
175
+ }
176
+ return properties;
177
+ };
178
+ Tc.fromXML = function (word, element, currentCol, rowSpanMap) {
179
+ var e_3, _a;
180
+ var tc = new Tc();
181
+ try {
182
+ for (var _b = __values(element.children), _c = _b.next(); !_c.done; _c = _b.next()) {
183
+ var child = _c.value;
184
+ var tagName = child.tagName;
185
+ switch (tagName) {
186
+ case 'w:tcPr':
187
+ tc.properties = Tc.parseTcPr(word, child);
188
+ break;
189
+ case 'w:p':
190
+ tc.add(Paragraph.fromXML(word, child));
191
+ break;
192
+ case 'w:tbl':
193
+ tc.add(Table.fromXML(word, child));
194
+ break;
195
+ }
196
+ }
197
+ }
198
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
199
+ finally {
200
+ try {
201
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
202
+ }
203
+ finally { if (e_3) throw e_3.error; }
204
+ }
205
+ var lastCol = rowSpanMap[currentCol.index];
206
+ // 如果是 continue 意味着这个被合并了
207
+ if (tc.properties.vMerge) {
208
+ if (tc.properties.vMerge === ST_Merge.restart) {
209
+ tc.properties.rowSpan = 1;
210
+ rowSpanMap[currentCol.index] = tc;
211
+ }
212
+ else if (lastCol) {
213
+ if (lastCol.properties && lastCol.properties.rowSpan) {
214
+ lastCol.properties.rowSpan = lastCol.properties.rowSpan + 1;
215
+ var colSpan_1 = tc.properties.gridSpan || 1;
216
+ currentCol.index += colSpan_1;
217
+ return null;
218
+ }
219
+ else {
220
+ console.warn('Tc.fromXML: continue but not found lastCol', currentCol.index, tc, rowSpanMap);
221
+ }
222
+ }
223
+ }
224
+ else {
225
+ delete rowSpanMap[currentCol.index];
226
+ }
227
+ var colSpan = tc.properties.gridSpan || 1;
228
+ currentCol.index += colSpan;
229
+ return tc;
230
+ };
231
+ return Tc;
232
+ }());
233
+
234
+ export { Tc, parseCellMargin, parseInsideBorders, parseTblCellSpacing, parseTblWidth };
@@ -0,0 +1,18 @@
1
+ import { CSSStyle } from '../../Style';
2
+ import { Tc } from './Tc';
3
+ import Word from '../../../Word';
4
+ export interface TrPr {
5
+ cssStyle?: CSSStyle;
6
+ /**
7
+ * 单元格样式
8
+ */
9
+ tcStyle?: CSSStyle;
10
+ }
11
+ export declare class Tr {
12
+ properties: TrPr;
13
+ tcs: Tc[];
14
+ static parseTrPr(word: Word, element: Element): TrPr;
15
+ static fromXML(word: Word, element: Element, rowSpanMap: {
16
+ [key: string]: Tc;
17
+ }): Tr;
18
+ }
@@ -0,0 +1,106 @@
1
+ import { __values } from '../../../node_modules/tslib/tslib.es6.js';
2
+ import { getVal, getValBoolean } from '../../../OpenXML.js';
3
+ import { parseTblCellSpacing, Tc } from './Tc.js';
4
+ import { parseTrHeight } from '../../../parse/parseTrHeight.js';
5
+ import { jcToTextAlign } from '../../../parse/jcToTextAlign.js';
6
+ import { Table } from '../Table.js';
7
+
8
+ var Tr = /** @class */ (function () {
9
+ function Tr() {
10
+ this.properties = {};
11
+ this.tcs = [];
12
+ }
13
+ Tr.parseTrPr = function (word, element) {
14
+ var e_1, _a;
15
+ var cssStyle = {};
16
+ var tcStyle = {};
17
+ try {
18
+ for (var _b = __values(element.children), _c = _b.next(); !_c.done; _c = _b.next()) {
19
+ var child = _c.value;
20
+ var tagName = child.tagName;
21
+ switch (tagName) {
22
+ case 'w:hidden':
23
+ if (getValBoolean(child)) {
24
+ cssStyle.display = 'none';
25
+ }
26
+ break;
27
+ case 'w:trHeight':
28
+ parseTrHeight(child, cssStyle);
29
+ break;
30
+ case 'w:jc':
31
+ cssStyle['text-align'] = jcToTextAlign(getVal(child));
32
+ break;
33
+ case 'w:cantSplit':
34
+ // 目前也不支持分页
35
+ break;
36
+ case 'w:tblPrEx':
37
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/tblPrEx_1.html
38
+ var tablePr = Table.parseTablePr(word, child);
39
+ Object.assign(cssStyle, tablePr.cssStyle);
40
+ break;
41
+ case 'w:tblCellSpacing':
42
+ parseTblCellSpacing(child, tcStyle);
43
+ break;
44
+ case 'w:cnfStyle':
45
+ // 目前是自动计算的,所以不需要这个了
46
+ break;
47
+ default:
48
+ console.warn("Tr: Unknown tag ", tagName, child);
49
+ }
50
+ }
51
+ }
52
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
53
+ finally {
54
+ try {
55
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
56
+ }
57
+ finally { if (e_1) throw e_1.error; }
58
+ }
59
+ return {
60
+ cssStyle: cssStyle
61
+ };
62
+ };
63
+ Tr.fromXML = function (word, element, rowSpanMap) {
64
+ var e_2, _a;
65
+ var tr = new Tr();
66
+ // 做成对象是为了传递引用来修改
67
+ var currentCol = {
68
+ index: 0
69
+ };
70
+ try {
71
+ for (var _b = __values(element.children), _c = _b.next(); !_c.done; _c = _b.next()) {
72
+ var child = _c.value;
73
+ var tagName = child.tagName;
74
+ switch (tagName) {
75
+ case 'w:tc':
76
+ var tc = Tc.fromXML(word, child, currentCol, rowSpanMap);
77
+ if (tc) {
78
+ tr.tcs.push(tc);
79
+ }
80
+ break;
81
+ case 'w:trPr':
82
+ tr.properties = Tr.parseTrPr(word, child);
83
+ break;
84
+ case 'w:tblPrEx':
85
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/tblPrEx_1.html
86
+ var tablePr = Table.parseTablePr(word, child);
87
+ Object.assign(tr.properties.cssStyle || {}, tablePr.cssStyle);
88
+ break;
89
+ default:
90
+ console.warn("Tr: Unknown tag ", tagName, child);
91
+ }
92
+ }
93
+ }
94
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
95
+ finally {
96
+ try {
97
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
98
+ }
99
+ finally { if (e_2) throw e_2.error; }
100
+ }
101
+ return tr;
102
+ };
103
+ return Tr;
104
+ }());
105
+
106
+ export { Tr };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 文件加载器默认是直接读取 zip,如果要对文件做特殊加密处理,可以实现这个接口
3
+ */
4
+ export interface PackageParser {
5
+ load(docxFile: ArrayBuffer | string): void;
6
+ /**
7
+ * 读取 xml 文件,转成 json 对象
8
+ * @param filePath 文件路径
9
+ * @returns 转成 json 的结果
10
+ */
11
+ getXML(filePath: string): Document;
12
+ /**
13
+ * 根据类型读取文件
14
+ */
15
+ getFileByType(filePath: string, type: 'string' | 'blob'): string | Blob;
16
+ /**
17
+ * 文件是否存在
18
+ */
19
+ fileExists(filePath: string): boolean;
20
+ /**
21
+ * 生成新的 zip 文件
22
+ *
23
+ * @param docContent 新的 word/document.xml 文件内容
24
+ */
25
+ generateZip(docContent: string): Blob;
26
+ }
@@ -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
+ }