docx 7.8.2 → 8.0.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 (422) hide show
  1. package/README.md +2 -1
  2. package/build/export/formatter.d.ts +4 -4
  3. package/build/export/index.d.ts +1 -1
  4. package/build/export/packer/image-replacer.d.ts +5 -5
  5. package/build/export/packer/next-compiler.d.ts +11 -11
  6. package/build/export/packer/numbering-replacer.d.ts +4 -4
  7. package/build/export/packer/packer.d.ts +18 -18
  8. package/build/file/app-properties/app-properties-attributes.d.ts +10 -10
  9. package/build/file/app-properties/app-properties.d.ts +4 -4
  10. package/build/file/border/border.d.ts +39 -39
  11. package/build/file/border/index.d.ts +1 -1
  12. package/build/file/content-types/content-types-attributes.d.ts +8 -8
  13. package/build/file/content-types/content-types.d.ts +6 -6
  14. package/build/file/content-types/default/default-attributes.d.ts +10 -10
  15. package/build/file/content-types/default/default.d.ts +4 -4
  16. package/build/file/content-types/override/override-attributes.d.ts +10 -10
  17. package/build/file/content-types/override/override.d.ts +4 -4
  18. package/build/file/core-properties/index.d.ts +1 -1
  19. package/build/file/core-properties/properties.d.ts +40 -40
  20. package/build/file/custom-properties/custom-properties-attributes.d.ts +10 -10
  21. package/build/file/custom-properties/custom-properties.d.ts +9 -9
  22. package/build/file/custom-properties/custom-property-attributes.d.ts +12 -12
  23. package/build/file/custom-properties/custom-property.d.ts +11 -11
  24. package/build/file/custom-properties/index.d.ts +2 -2
  25. package/build/file/document/body/body.d.ts +10 -10
  26. package/build/file/document/body/index.d.ts +2 -2
  27. package/build/file/document/body/section-properties/index.d.ts +2 -2
  28. package/build/file/document/body/section-properties/properties/column.d.ts +10 -14
  29. package/build/file/document/body/section-properties/properties/columns.d.ts +13 -20
  30. package/build/file/document/body/section-properties/properties/doc-grid.d.ts +22 -22
  31. package/build/file/document/body/section-properties/properties/header-footer-reference.d.ts +17 -17
  32. package/build/file/document/body/section-properties/properties/index.d.ts +12 -12
  33. package/build/file/document/body/section-properties/properties/line-number.d.ts +16 -23
  34. package/build/file/document/body/section-properties/properties/page-borders.d.ts +30 -30
  35. package/build/file/document/body/section-properties/properties/page-margin.d.ts +14 -24
  36. package/build/file/document/body/section-properties/properties/page-number.d.ts +24 -24
  37. package/build/file/document/body/section-properties/properties/page-size.d.ts +14 -20
  38. package/build/file/document/body/section-properties/properties/page-text-direction.d.ts +8 -8
  39. package/build/file/document/body/section-properties/properties/section-type.d.ts +18 -18
  40. package/build/file/document/body/section-properties/section-properties.d.ts +53 -53
  41. package/build/file/document/document-attributes.d.ts +85 -85
  42. package/build/file/document/document-background/document-background.d.ts +23 -23
  43. package/build/file/document/document-background/index.d.ts +1 -1
  44. package/build/file/document/document.d.ts +15 -15
  45. package/build/file/document/index.d.ts +4 -4
  46. package/build/file/document-wrapper.d.ts +16 -16
  47. package/build/file/drawing/anchor/anchor-attributes.d.ts +24 -24
  48. package/build/file/drawing/anchor/anchor.d.ts +6 -6
  49. package/build/file/drawing/anchor/index.d.ts +2 -2
  50. package/build/file/drawing/doc-properties/doc-properties-children.d.ts +3 -0
  51. package/build/file/drawing/doc-properties/doc-properties.d.ts +10 -9
  52. package/build/file/drawing/drawing.d.ts +18 -18
  53. package/build/file/drawing/effect-extent/effect-extent-attributes.d.ts +14 -14
  54. package/build/file/drawing/effect-extent/effect-extent.d.ts +4 -4
  55. package/build/file/drawing/extent/extent-attributes.d.ts +10 -10
  56. package/build/file/drawing/extent/extent.d.ts +5 -5
  57. package/build/file/drawing/floating/align.d.ts +5 -5
  58. package/build/file/drawing/floating/floating-position.d.ts +49 -49
  59. package/build/file/drawing/floating/horizontal-position.d.ts +5 -5
  60. package/build/file/drawing/floating/index.d.ts +4 -4
  61. package/build/file/drawing/floating/position-offset.d.ts +4 -4
  62. package/build/file/drawing/floating/simple-pos.d.ts +4 -4
  63. package/build/file/drawing/floating/vertical-position.d.ts +5 -5
  64. package/build/file/drawing/graphic-frame/graphic-frame-locks/graphic-frame-lock-attributes.d.ts +10 -10
  65. package/build/file/drawing/graphic-frame/graphic-frame-locks/graphic-frame-locks.d.ts +4 -4
  66. package/build/file/drawing/graphic-frame/graphic-frame-properties.d.ts +4 -4
  67. package/build/file/drawing/index.d.ts +3 -3
  68. package/build/file/drawing/inline/graphic/graphic-data/graphic-data-attribute.d.ts +8 -8
  69. package/build/file/drawing/inline/graphic/graphic-data/graphic-data.d.ts +6 -6
  70. package/build/file/drawing/inline/graphic/graphic-data/index.d.ts +1 -1
  71. package/build/file/drawing/inline/graphic/graphic-data/pic/blip/blip-fill.d.ts +5 -5
  72. package/build/file/drawing/inline/graphic/graphic-data/pic/blip/blip.d.ts +5 -5
  73. package/build/file/drawing/inline/graphic/graphic-data/pic/blip/source-rectangle.d.ts +4 -4
  74. package/build/file/drawing/inline/graphic/graphic-data/pic/blip/stretch.d.ts +4 -4
  75. package/build/file/drawing/inline/graphic/graphic-data/pic/index.d.ts +1 -1
  76. package/build/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/child-non-visual-pic-properties/child-non-visual-pic-properties.d.ts +4 -4
  77. package/build/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/child-non-visual-pic-properties/pic-locks/pic-locks-attributes.d.ts +10 -10
  78. package/build/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/child-non-visual-pic-properties/pic-locks/pic-locks.d.ts +4 -4
  79. package/build/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-pic-properties.d.ts +4 -4
  80. package/build/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-properties/non-visual-properties-attributes.d.ts +12 -12
  81. package/build/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-properties/non-visual-properties.d.ts +5 -4
  82. package/build/file/drawing/inline/graphic/graphic-data/pic/pic-attributes.d.ts +8 -8
  83. package/build/file/drawing/inline/graphic/graphic-data/pic/pic.d.ts +5 -5
  84. package/build/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/extents/extents-attributes.d.ts +10 -10
  85. package/build/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/extents/extents.d.ts +5 -5
  86. package/build/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/form.d.ts +17 -17
  87. package/build/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/index.d.ts +1 -1
  88. package/build/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/offset/off-attributes.d.ts +10 -10
  89. package/build/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/offset/off.d.ts +4 -4
  90. package/build/file/drawing/inline/graphic/graphic-data/pic/shape-properties/outline/no-fill.d.ts +4 -4
  91. package/build/file/drawing/inline/graphic/graphic-data/pic/shape-properties/outline/outline.d.ts +4 -4
  92. package/build/file/drawing/inline/graphic/graphic-data/pic/shape-properties/preset-geometry/adjustment-values/adjustment-values.d.ts +4 -4
  93. package/build/file/drawing/inline/graphic/graphic-data/pic/shape-properties/preset-geometry/preset-geometry-attributes.d.ts +8 -8
  94. package/build/file/drawing/inline/graphic/graphic-data/pic/shape-properties/preset-geometry/preset-geometry.d.ts +4 -4
  95. package/build/file/drawing/inline/graphic/graphic-data/pic/shape-properties/shape-properties-attributes.d.ts +8 -8
  96. package/build/file/drawing/inline/graphic/graphic-data/pic/shape-properties/shape-properties.d.ts +6 -6
  97. package/build/file/drawing/inline/graphic/graphic.d.ts +6 -6
  98. package/build/file/drawing/inline/graphic/index.d.ts +1 -1
  99. package/build/file/drawing/inline/index.d.ts +1 -1
  100. package/build/file/drawing/inline/inline-attributes.d.ts +10 -10
  101. package/build/file/drawing/inline/inline.d.ts +14 -14
  102. package/build/file/drawing/text-wrap/index.d.ts +5 -5
  103. package/build/file/drawing/text-wrap/text-wrapping.d.ts +18 -18
  104. package/build/file/drawing/text-wrap/wrap-none.d.ts +4 -4
  105. package/build/file/drawing/text-wrap/wrap-square.d.ts +6 -6
  106. package/build/file/drawing/text-wrap/wrap-tight.d.ts +5 -5
  107. package/build/file/drawing/text-wrap/wrap-top-and-bottom.d.ts +5 -5
  108. package/build/file/file-child.d.ts +4 -0
  109. package/build/file/file.d.ts +69 -72
  110. package/build/file/footer/footer-attributes.d.ts +50 -50
  111. package/build/file/footer/footer.d.ts +9 -9
  112. package/build/file/footer/index.d.ts +1 -1
  113. package/build/file/footer-wrapper.d.ts +23 -23
  114. package/build/file/footnotes/footnote/footnote-attributes.d.ts +10 -10
  115. package/build/file/footnotes/footnote/footnote.d.ts +14 -14
  116. package/build/file/footnotes/footnote/index.d.ts +1 -1
  117. package/build/file/footnotes/footnote/run/continuation-seperator-run.d.ts +4 -4
  118. package/build/file/footnotes/footnote/run/continuation-seperator.d.ts +4 -4
  119. package/build/file/footnotes/footnote/run/footnote-ref-run.d.ts +4 -4
  120. package/build/file/footnotes/footnote/run/footnote-ref.d.ts +4 -4
  121. package/build/file/footnotes/footnote/run/index.d.ts +1 -1
  122. package/build/file/footnotes/footnote/run/reference-run.d.ts +15 -15
  123. package/build/file/footnotes/footnote/run/seperator-run.d.ts +4 -4
  124. package/build/file/footnotes/footnote/run/seperator.d.ts +4 -4
  125. package/build/file/footnotes/footnotes-attributes.d.ts +40 -40
  126. package/build/file/footnotes/footnotes.d.ts +6 -6
  127. package/build/file/footnotes/index.d.ts +2 -2
  128. package/build/file/footnotes-wrapper.d.ts +10 -10
  129. package/build/file/header/header-attributes.d.ts +72 -72
  130. package/build/file/header/header.d.ts +9 -9
  131. package/build/file/header/index.d.ts +1 -1
  132. package/build/file/header-wrapper.d.ts +23 -23
  133. package/build/file/header.d.ts +13 -13
  134. package/build/file/index.d.ts +19 -20
  135. package/build/file/media/data.d.ts +22 -22
  136. package/build/file/media/index.d.ts +2 -2
  137. package/build/file/media/media.d.ts +16 -19
  138. package/build/file/numbering/abstract-numbering.d.ts +6 -6
  139. package/build/file/numbering/index.d.ts +4 -4
  140. package/build/file/numbering/level.d.ts +96 -96
  141. package/build/file/numbering/multi-level-type.d.ts +4 -4
  142. package/build/file/numbering/num.d.ts +22 -20
  143. package/build/file/numbering/numbering.d.ts +19 -19
  144. package/build/file/paragraph/formatting/alignment.d.ts +26 -26
  145. package/build/file/paragraph/formatting/border.d.ts +14 -14
  146. package/build/file/paragraph/formatting/break.d.ts +11 -11
  147. package/build/file/paragraph/formatting/indent.d.ts +13 -12
  148. package/build/file/paragraph/formatting/index.d.ts +8 -8
  149. package/build/file/paragraph/formatting/spacing.d.ts +18 -18
  150. package/build/file/paragraph/formatting/style.d.ts +13 -13
  151. package/build/file/paragraph/formatting/tab-stop.d.ts +44 -44
  152. package/build/file/paragraph/formatting/unordered-list.d.ts +4 -4
  153. package/build/file/paragraph/formatting/word-wrap.d.ts +11 -11
  154. package/build/file/paragraph/frame/frame-properties.d.ts +90 -90
  155. package/build/file/paragraph/frame/index.d.ts +1 -1
  156. package/build/file/paragraph/index.d.ts +7 -7
  157. package/build/file/paragraph/links/bookmark-attributes.d.ts +17 -17
  158. package/build/file/paragraph/links/bookmark.d.ts +17 -17
  159. package/build/file/paragraph/links/hyperlink-attributes.d.ts +13 -13
  160. package/build/file/paragraph/links/hyperlink.d.ts +26 -26
  161. package/build/file/paragraph/links/index.d.ts +4 -4
  162. package/build/file/paragraph/links/outline-level.d.ts +5 -5
  163. package/build/file/paragraph/links/pageref-field-instruction.d.ts +5 -5
  164. package/build/file/paragraph/links/pageref-properties.d.ts +4 -4
  165. package/build/file/paragraph/links/pageref.d.ts +5 -5
  166. package/build/file/paragraph/math/brackets/index.d.ts +4 -4
  167. package/build/file/paragraph/math/brackets/math-angled-brackets.d.ts +7 -7
  168. package/build/file/paragraph/math/brackets/math-beginning-character.d.ts +4 -4
  169. package/build/file/paragraph/math/brackets/math-bracket-properties.d.ts +7 -7
  170. package/build/file/paragraph/math/brackets/math-curly-brackets.d.ts +7 -7
  171. package/build/file/paragraph/math/brackets/math-ending-char.d.ts +4 -4
  172. package/build/file/paragraph/math/brackets/math-round-brackets.d.ts +7 -7
  173. package/build/file/paragraph/math/brackets/math-square-brackets.d.ts +7 -7
  174. package/build/file/paragraph/math/fraction/index.d.ts +3 -3
  175. package/build/file/paragraph/math/fraction/math-denominator.d.ts +5 -5
  176. package/build/file/paragraph/math/fraction/math-fraction.d.ts +9 -9
  177. package/build/file/paragraph/math/fraction/math-numerator.d.ts +5 -5
  178. package/build/file/paragraph/math/function/index.d.ts +3 -3
  179. package/build/file/paragraph/math/function/math-function-name.d.ts +5 -5
  180. package/build/file/paragraph/math/function/math-function-properties.d.ts +4 -4
  181. package/build/file/paragraph/math/function/math-function.d.ts +9 -9
  182. package/build/file/paragraph/math/index.d.ts +9 -9
  183. package/build/file/paragraph/math/math-component.d.ts +9 -9
  184. package/build/file/paragraph/math/math-run.d.ts +4 -4
  185. package/build/file/paragraph/math/math-text.d.ts +4 -4
  186. package/build/file/paragraph/math/math.d.ts +8 -8
  187. package/build/file/paragraph/math/n-ary/index.d.ts +8 -8
  188. package/build/file/paragraph/math/n-ary/math-accent-character.d.ts +4 -4
  189. package/build/file/paragraph/math/n-ary/math-base.d.ts +5 -5
  190. package/build/file/paragraph/math/n-ary/math-integral.d.ts +10 -10
  191. package/build/file/paragraph/math/n-ary/math-limit-location.d.ts +4 -4
  192. package/build/file/paragraph/math/n-ary/math-n-ary-properties.d.ts +4 -4
  193. package/build/file/paragraph/math/n-ary/math-sub-script-hide.d.ts +4 -4
  194. package/build/file/paragraph/math/n-ary/math-sub-script.d.ts +5 -5
  195. package/build/file/paragraph/math/n-ary/math-sum.d.ts +10 -10
  196. package/build/file/paragraph/math/n-ary/math-super-script-hide.d.ts +4 -4
  197. package/build/file/paragraph/math/n-ary/math-super-script.d.ts +5 -5
  198. package/build/file/paragraph/math/radical/index.d.ts +3 -3
  199. package/build/file/paragraph/math/radical/math-degree-hide.d.ts +4 -4
  200. package/build/file/paragraph/math/radical/math-degree.d.ts +5 -5
  201. package/build/file/paragraph/math/radical/math-radical-properties.d.ts +4 -4
  202. package/build/file/paragraph/math/radical/math-radical.d.ts +9 -9
  203. package/build/file/paragraph/math/script/index.d.ts +4 -4
  204. package/build/file/paragraph/math/script/pre-sub-super-script/index.d.ts +2 -2
  205. package/build/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function-properties.d.ts +4 -4
  206. package/build/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.d.ts +10 -10
  207. package/build/file/paragraph/math/script/sub-script/index.d.ts +2 -2
  208. package/build/file/paragraph/math/script/sub-script/math-sub-script-function-properties.d.ts +4 -4
  209. package/build/file/paragraph/math/script/sub-script/math-sub-script-function.d.ts +9 -9
  210. package/build/file/paragraph/math/script/sub-super-script/index.d.ts +2 -2
  211. package/build/file/paragraph/math/script/sub-super-script/math-sub-super-script-function-properties.d.ts +4 -4
  212. package/build/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.d.ts +10 -10
  213. package/build/file/paragraph/math/script/super-script/index.d.ts +2 -2
  214. package/build/file/paragraph/math/script/super-script/math-super-script-function-properties.d.ts +4 -4
  215. package/build/file/paragraph/math/script/super-script/math-super-script-function.d.ts +9 -9
  216. package/build/file/paragraph/paragraph.d.ts +21 -20
  217. package/build/file/paragraph/properties.d.ts +53 -52
  218. package/build/file/paragraph/run/break.d.ts +4 -4
  219. package/build/file/paragraph/run/comment-run.d.ts +27 -26
  220. package/build/file/paragraph/run/emphasis-mark.d.ts +13 -13
  221. package/build/file/paragraph/run/empty-children.d.ts +52 -0
  222. package/build/file/paragraph/run/field.d.ts +10 -10
  223. package/build/file/paragraph/run/formatting.d.ts +14 -13
  224. package/build/file/paragraph/run/image-run.d.ts +19 -19
  225. package/build/file/paragraph/run/index.d.ts +13 -12
  226. package/build/file/paragraph/run/language.d.ts +7 -0
  227. package/build/file/paragraph/run/page-number.d.ts +10 -10
  228. package/build/file/paragraph/run/positional-tab.d.ts +25 -0
  229. package/build/file/paragraph/run/properties.d.ts +76 -59
  230. package/build/file/paragraph/run/run-components/symbol.d.ts +4 -4
  231. package/build/file/paragraph/run/run-components/text.d.ts +10 -10
  232. package/build/file/paragraph/run/run-fonts.d.ts +12 -12
  233. package/build/file/paragraph/run/run.d.ts +22 -20
  234. package/build/file/paragraph/run/script.d.ts +10 -10
  235. package/build/file/paragraph/run/sequential-identifier-instruction.d.ts +4 -4
  236. package/build/file/paragraph/run/sequential-identifier.d.ts +4 -4
  237. package/build/file/paragraph/run/simple-field.d.ts +7 -7
  238. package/build/file/paragraph/run/symbol-run.d.ts +8 -8
  239. package/build/file/paragraph/run/text-attributes.d.ts +9 -9
  240. package/build/file/paragraph/run/text-run.d.ts +4 -4
  241. package/build/file/paragraph/run/underline.d.ts +24 -24
  242. package/build/file/relationships/attributes.d.ts +8 -8
  243. package/build/file/relationships/index.d.ts +1 -1
  244. package/build/file/relationships/relationship/relationship-attributes.d.ts +14 -14
  245. package/build/file/relationships/relationship/relationship.d.ts +8 -8
  246. package/build/file/relationships/relationships.d.ts +7 -8
  247. package/build/file/settings/compatibility-setting/compatibility-setting.d.ts +15 -15
  248. package/build/file/settings/compatibility.d.ts +72 -72
  249. package/build/file/settings/index.d.ts +1 -1
  250. package/build/file/settings/settings.d.ts +51 -51
  251. package/build/file/shading/index.d.ts +1 -1
  252. package/build/file/shading/shading.d.ts +48 -48
  253. package/build/file/shared/alignment.d.ts +14 -14
  254. package/build/file/shared/index.d.ts +3 -3
  255. package/build/file/shared/number-format.d.ts +64 -64
  256. package/build/file/shared/space-type.d.ts +4 -4
  257. package/build/file/styles/defaults/document-defaults.d.ts +12 -12
  258. package/build/file/styles/defaults/index.d.ts +3 -3
  259. package/build/file/styles/defaults/paragraph-properties.d.ts +5 -5
  260. package/build/file/styles/defaults/run-properties.d.ts +5 -5
  261. package/build/file/styles/external-styles-factory.d.ts +4 -4
  262. package/build/file/styles/factory.d.ts +22 -22
  263. package/build/file/styles/index.d.ts +4 -4
  264. package/build/file/styles/latent-styles/exceptions.d.ts +20 -20
  265. package/build/file/styles/latent-styles/index.d.ts +1 -1
  266. package/build/file/styles/latent-styles/latent-styles.d.ts +5 -5
  267. package/build/file/styles/sample/default-style.d.ts +1 -1
  268. package/build/file/styles/sample/index.d.ts +1 -1
  269. package/build/file/styles/style/character-style.d.ts +13 -13
  270. package/build/file/styles/style/components.d.ts +11 -11
  271. package/build/file/styles/style/default-styles.d.ts +44 -44
  272. package/build/file/styles/style/index.d.ts +4 -4
  273. package/build/file/styles/style/paragraph-style.d.ts +15 -15
  274. package/build/file/styles/style/style.d.ts +20 -20
  275. package/build/file/styles/styles.d.ts +15 -15
  276. package/build/file/table/grid.d.ts +8 -7
  277. package/build/file/table/index.d.ts +5 -5
  278. package/build/file/table/table-cell/index.d.ts +2 -2
  279. package/build/file/table/table-cell/table-cell-components.d.ts +31 -31
  280. package/build/file/table/table-cell/table-cell-properties.d.ts +20 -20
  281. package/build/file/table/table-cell/table-cell.d.ts +12 -12
  282. package/build/file/table/table-properties/index.d.ts +4 -4
  283. package/build/file/table/table-properties/table-borders.d.ts +45 -45
  284. package/build/file/table/table-properties/table-cell-margin.d.ts +16 -16
  285. package/build/file/table/table-properties/table-float-properties.d.ts +42 -55
  286. package/build/file/table/table-properties/table-layout.d.ts +8 -8
  287. package/build/file/table/table-properties/table-properties.d.ts +23 -23
  288. package/build/file/table/table-row/index.d.ts +3 -3
  289. package/build/file/table/table-row/table-row-height.d.ts +19 -18
  290. package/build/file/table/table-row/table-row-properties.d.ts +14 -13
  291. package/build/file/table/table-row/table-row.d.ts +16 -16
  292. package/build/file/table/table-width.d.ts +15 -14
  293. package/build/file/table/table.d.ts +23 -23
  294. package/build/file/table-of-contents/field-instruction.d.ts +6 -6
  295. package/build/file/table-of-contents/index.d.ts +2 -2
  296. package/build/file/table-of-contents/sdt-content.d.ts +4 -4
  297. package/build/file/table-of-contents/sdt-properties.d.ts +4 -4
  298. package/build/file/table-of-contents/table-of-contents-properties.d.ts +23 -23
  299. package/build/file/table-of-contents/table-of-contents.d.ts +5 -5
  300. package/build/file/track-revision/index.d.ts +2 -2
  301. package/build/file/track-revision/track-revision-components/deleted-page-number.d.ts +10 -10
  302. package/build/file/track-revision/track-revision-components/deleted-text-run.d.ts +13 -13
  303. package/build/file/track-revision/track-revision-components/deleted-text.d.ts +4 -4
  304. package/build/file/track-revision/track-revision-components/inserted-text-run.d.ts +9 -9
  305. package/build/file/track-revision/track-revision.d.ts +13 -13
  306. package/build/file/vertical-align/index.d.ts +1 -1
  307. package/build/file/vertical-align/vertical-align.d.ts +16 -16
  308. package/build/file/xml-components/attributes.d.ts +46 -46
  309. package/build/file/xml-components/base.d.ts +13 -12
  310. package/build/file/xml-components/default-attributes.d.ts +25 -11
  311. package/build/file/xml-components/imported-xml-component.d.ts +14 -14
  312. package/build/file/xml-components/index.d.ts +8 -8
  313. package/build/file/xml-components/initializable-xml-component.d.ts +4 -4
  314. package/build/file/xml-components/simple-elements.d.ts +29 -19
  315. package/build/file/xml-components/xml-component.d.ts +12 -12
  316. package/build/file/xml-components/xmlable-object.d.ts +7 -7
  317. package/build/index.d.ts +5 -5
  318. package/build/index.js +1 -1
  319. package/build/patcher/content-types-manager.d.ts +2 -0
  320. package/build/patcher/from-docx.d.ts +25 -0
  321. package/build/patcher/index.d.ts +1 -0
  322. package/build/patcher/paragraph-split-inject.d.ts +6 -0
  323. package/build/patcher/paragraph-token-replacer.d.ts +8 -0
  324. package/build/patcher/relationship-manager.d.ts +4 -0
  325. package/build/patcher/replacer.d.ts +5 -0
  326. package/build/patcher/run-renderer.d.ts +22 -0
  327. package/build/patcher/traverser.d.ts +8 -0
  328. package/build/patcher/util.d.ts +5 -0
  329. package/build/tests/utility.d.ts +3 -3
  330. package/build/util/convenience-functions.d.ts +4 -4
  331. package/build/util/index.d.ts +2 -2
  332. package/build/util/values.d.ts +20 -17
  333. package/package.json +10 -8
  334. package/src/export/formatter.ts +1 -1
  335. package/src/export/packer/next-compiler.ts +23 -5
  336. package/src/file/document/body/section-properties/properties/column.ts +13 -15
  337. package/src/file/document/body/section-properties/properties/columns.ts +10 -19
  338. package/src/file/document/body/section-properties/properties/line-number.ts +13 -17
  339. package/src/file/document/body/section-properties/properties/page-margin.ts +26 -38
  340. package/src/file/document/body/section-properties/properties/page-size.ts +11 -19
  341. package/src/file/document/body/section-properties/section-properties.ts +5 -5
  342. package/src/file/drawing/doc-properties/doc-properties-children.spec.ts +61 -0
  343. package/src/file/drawing/doc-properties/doc-properties-children.ts +57 -0
  344. package/src/file/drawing/doc-properties/doc-properties.ts +49 -19
  345. package/src/file/drawing/drawing.spec.ts +254 -0
  346. package/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-properties/non-visual-properties.ts +31 -1
  347. package/src/file/file-child.ts +5 -0
  348. package/src/file/file.spec.ts +1 -25
  349. package/src/file/file.ts +5 -31
  350. package/src/file/index.ts +0 -1
  351. package/src/file/media/media.spec.ts +13 -79
  352. package/src/file/media/media.ts +0 -49
  353. package/src/file/numbering/concrete-numbering.spec.ts +185 -10
  354. package/src/file/numbering/num.ts +10 -6
  355. package/src/file/numbering/numbering.ts +6 -4
  356. package/src/file/paragraph/formatting/indent.ts +54 -40
  357. package/src/file/paragraph/paragraph.spec.ts +1 -0
  358. package/src/file/paragraph/paragraph.ts +3 -2
  359. package/src/file/paragraph/properties.spec.ts +16 -0
  360. package/src/file/paragraph/properties.ts +9 -0
  361. package/src/file/paragraph/run/comment-run.spec.ts +10 -8
  362. package/src/file/paragraph/run/comment-run.ts +6 -6
  363. package/src/file/paragraph/run/empty-children.spec.ts +229 -0
  364. package/src/file/paragraph/run/empty-children.ts +127 -0
  365. package/src/file/paragraph/run/formatting.ts +2 -2
  366. package/src/file/paragraph/run/image-run.spec.ts +4 -0
  367. package/src/file/paragraph/run/index.ts +2 -1
  368. package/src/file/paragraph/run/language.spec.ts +29 -0
  369. package/src/file/paragraph/run/language.ts +35 -0
  370. package/src/file/paragraph/run/positional-tab.spec.ts +27 -0
  371. package/src/file/paragraph/run/positional-tab.ts +80 -0
  372. package/src/file/paragraph/run/properties.ts +44 -2
  373. package/src/file/paragraph/run/run.spec.ts +143 -0
  374. package/src/file/paragraph/run/run.ts +83 -2
  375. package/src/file/relationships/relationships.ts +1 -5
  376. package/src/file/styles/sample/default-style.ts +7 -1
  377. package/src/file/table/grid.ts +9 -9
  378. package/src/file/table/table-properties/table-float-properties.spec.ts +1 -3
  379. package/src/file/table/table-properties/table-float-properties.ts +56 -42
  380. package/src/file/table/table-row/table-row-height.ts +2 -2
  381. package/src/file/table/table-row/table-row-properties.ts +2 -1
  382. package/src/file/table/table-width.ts +12 -10
  383. package/src/file/table/table.ts +2 -2
  384. package/src/file/table-of-contents/table-of-contents.ts +2 -2
  385. package/src/file/xml-components/base.ts +2 -0
  386. package/src/file/xml-components/default-attributes.ts +18 -5
  387. package/src/file/xml-components/imported-xml-component.spec.ts +1 -1
  388. package/src/file/xml-components/simple-elements.spec.ts +41 -0
  389. package/src/file/xml-components/simple-elements.ts +29 -3
  390. package/src/file/xml-components/xml-component.ts +11 -0
  391. package/src/index.ts +1 -1
  392. package/src/patcher/content-types-manager.spec.ts +51 -0
  393. package/src/patcher/content-types-manager.ts +16 -0
  394. package/src/patcher/from-docx.spec.ts +370 -0
  395. package/src/patcher/from-docx.ts +233 -0
  396. package/src/patcher/index.ts +1 -0
  397. package/src/patcher/paragraph-split-inject.spec.ts +224 -0
  398. package/src/patcher/paragraph-split-inject.ts +54 -0
  399. package/src/patcher/paragraph-token-replacer.spec.ts +165 -0
  400. package/src/patcher/paragraph-token-replacer.ts +69 -0
  401. package/src/patcher/relationship-manager.spec.ts +87 -0
  402. package/src/patcher/relationship-manager.ts +42 -0
  403. package/src/patcher/replacer.spec.ts +206 -0
  404. package/src/patcher/replacer.ts +83 -0
  405. package/src/patcher/run-renderer.spec.ts +96 -0
  406. package/src/patcher/run-renderer.ts +109 -0
  407. package/src/patcher/traverser.spec.ts +599 -0
  408. package/src/patcher/traverser.ts +45 -0
  409. package/src/patcher/util.spec.ts +50 -0
  410. package/src/patcher/util.ts +30 -0
  411. package/src/util/values.spec.ts +0 -22
  412. package/src/util/values.ts +29 -25
  413. package/build/file/file-properties.d.ts +0 -5
  414. package/build/file/paragraph/run/tab.d.ts +0 -4
  415. package/build/import-dotx/import-dotx.d.ts +0 -23
  416. package/build/import-dotx/index.d.ts +0 -1
  417. package/src/file/file-properties.ts +0 -11
  418. package/src/file/paragraph/run/tab.spec.ts +0 -22
  419. package/src/file/paragraph/run/tab.ts +0 -14
  420. package/src/import-dotx/import-dotx.spec.ts +0 -26
  421. package/src/import-dotx/import-dotx.ts +0 -266
  422. package/src/import-dotx/index.ts +0 -1
@@ -0,0 +1,370 @@
1
+ import * as chai from "chai";
2
+ import * as sinon from "sinon";
3
+ import * as JSZip from "jszip";
4
+ import * as chaiAsPromised from "chai-as-promised";
5
+
6
+ import { ExternalHyperlink, ImageRun, Paragraph, TextRun } from "@file/paragraph";
7
+
8
+ import { patchDocument, PatchType } from "./from-docx";
9
+
10
+ chai.use(chaiAsPromised);
11
+ const { expect } = chai;
12
+
13
+ const MOCK_XML = `
14
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
15
+ <w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
16
+ xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex"
17
+ xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex"
18
+ xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex"
19
+ xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex"
20
+ xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex"
21
+ xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex"
22
+ xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex"
23
+ xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex"
24
+ xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex"
25
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
26
+ xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink"
27
+ xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d"
28
+ xmlns:o="urn:schemas-microsoft-com:office:office"
29
+ xmlns:oel="http://schemas.microsoft.com/office/2019/extlst"
30
+ xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
31
+ xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
32
+ xmlns:v="urn:schemas-microsoft-com:vml"
33
+ xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
34
+ xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
35
+ xmlns:w10="urn:schemas-microsoft-com:office:word"
36
+ xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
37
+ xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
38
+ xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml"
39
+ xmlns:w16cex="http://schemas.microsoft.com/office/word/2018/wordml/cex"
40
+ xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid"
41
+ xmlns:w16="http://schemas.microsoft.com/office/word/2018/wordml"
42
+ xmlns:w16sdtdh="http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash"
43
+ xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex"
44
+ xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
45
+ xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
46
+ xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
47
+ xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
48
+ <w:body>
49
+ <w:p w14:paraId="2499FE9F" w14:textId="0A3D130F" w:rsidR="00B51233"
50
+ w:rsidRDefault="007B52ED" w:rsidP="007B52ED">
51
+ <w:pPr>
52
+ <w:pStyle w:val="Title" />
53
+ </w:pPr>
54
+ <w:r>
55
+ <w:t>Hello World</w:t>
56
+ </w:r>
57
+ </w:p>
58
+ <w:p w14:paraId="6410D9A0" w14:textId="7579AB49" w:rsidR="007B52ED"
59
+ w:rsidRDefault="007B52ED" />
60
+ <w:p w14:paraId="57ACF964" w14:textId="315D7A05" w:rsidR="007B52ED"
61
+ w:rsidRDefault="007B52ED">
62
+ <w:r>
63
+ <w:t>Hello {{name}},</w:t>
64
+ </w:r>
65
+ <w:r w:rsidR="008126CB">
66
+ <w:t xml:space="preserve"> how are you?</w:t>
67
+ </w:r>
68
+ </w:p>
69
+ <w:p w14:paraId="38C7DF4A" w14:textId="66CDEC9A" w:rsidR="007B52ED"
70
+ w:rsidRDefault="007B52ED" />
71
+ <w:p w14:paraId="04FABE2B" w14:textId="3DACA001" w:rsidR="007B52ED"
72
+ w:rsidRDefault="007B52ED">
73
+ <w:r>
74
+ <w:t>{{paragraph_replace}}</w:t>
75
+ </w:r>
76
+ </w:p>
77
+ <w:p w14:paraId="7AD7975D" w14:textId="77777777" w:rsidR="00EF161F"
78
+ w:rsidRDefault="00EF161F" />
79
+ <w:p w14:paraId="3BD6D75A" w14:textId="19AE3121" w:rsidR="00EF161F"
80
+ w:rsidRDefault="00EF161F">
81
+ <w:r>
82
+ <w:t>{{table}}</w:t>
83
+ </w:r>
84
+ </w:p>
85
+ <w:p w14:paraId="76023962" w14:textId="4E606AB9" w:rsidR="007B52ED"
86
+ w:rsidRDefault="007B52ED" />
87
+ <w:tbl>
88
+ <w:tblPr>
89
+ <w:tblStyle w:val="TableGrid" />
90
+ <w:tblW w:w="0" w:type="auto" />
91
+ <w:tblLook w:val="04A0" w:firstRow="1" w:lastRow="0" w:firstColumn="1"
92
+ w:lastColumn="0" w:noHBand="0" w:noVBand="1" />
93
+ </w:tblPr>
94
+ <w:tblGrid>
95
+ <w:gridCol w:w="3003" />
96
+ <w:gridCol w:w="3003" />
97
+ <w:gridCol w:w="3004" />
98
+ </w:tblGrid>
99
+ <w:tr w:rsidR="00EF161F" w14:paraId="1DEC5955" w14:textId="77777777" w:rsidTr="00EF161F">
100
+ <w:tc>
101
+ <w:tcPr>
102
+ <w:tcW w:w="3003" w:type="dxa" />
103
+ </w:tcPr>
104
+ <w:p w14:paraId="54DA5587" w14:textId="625BAC60" w:rsidR="00EF161F"
105
+ w:rsidRDefault="00EF161F">
106
+ <w:r>
107
+ <w:t>{{table_heading_1}}</w:t>
108
+ </w:r>
109
+ </w:p>
110
+ </w:tc>
111
+ <w:tc>
112
+ <w:tcPr>
113
+ <w:tcW w:w="3003" w:type="dxa" />
114
+ </w:tcPr>
115
+ <w:p w14:paraId="57100910" w14:textId="71FD5616" w:rsidR="00EF161F"
116
+ w:rsidRDefault="00EF161F" />
117
+ </w:tc>
118
+ <w:tc>
119
+ <w:tcPr>
120
+ <w:tcW w:w="3004" w:type="dxa" />
121
+ </w:tcPr>
122
+ <w:p w14:paraId="1D388FAB" w14:textId="77777777" w:rsidR="00EF161F"
123
+ w:rsidRDefault="00EF161F" />
124
+ </w:tc>
125
+ </w:tr>
126
+ <w:tr w:rsidR="00EF161F" w14:paraId="0F53D2DC" w14:textId="77777777" w:rsidTr="00EF161F">
127
+ <w:tc>
128
+ <w:tcPr>
129
+ <w:tcW w:w="3003" w:type="dxa" />
130
+ </w:tcPr>
131
+ <w:p w14:paraId="0F2BCCED" w14:textId="3C3B6706" w:rsidR="00EF161F"
132
+ w:rsidRDefault="00EF161F">
133
+ <w:r>
134
+ <w:t>Item: {{item_1}}</w:t>
135
+ </w:r>
136
+ </w:p>
137
+ </w:tc>
138
+ <w:tc>
139
+ <w:tcPr>
140
+ <w:tcW w:w="3003" w:type="dxa" />
141
+ </w:tcPr>
142
+ <w:p w14:paraId="1E6158AC" w14:textId="77777777" w:rsidR="00EF161F"
143
+ w:rsidRDefault="00EF161F" />
144
+ </w:tc>
145
+ <w:tc>
146
+ <w:tcPr>
147
+ <w:tcW w:w="3004" w:type="dxa" />
148
+ </w:tcPr>
149
+ <w:p w14:paraId="17937748" w14:textId="77777777" w:rsidR="00EF161F"
150
+ w:rsidRDefault="00EF161F" />
151
+ </w:tc>
152
+ </w:tr>
153
+ <w:tr w:rsidR="00EF161F" w14:paraId="781DAC1A" w14:textId="77777777" w:rsidTr="00EF161F">
154
+ <w:tc>
155
+ <w:tcPr>
156
+ <w:tcW w:w="3003" w:type="dxa" />
157
+ </w:tcPr>
158
+ <w:p w14:paraId="1DCD0343" w14:textId="77777777" w:rsidR="00EF161F"
159
+ w:rsidRDefault="00EF161F" />
160
+ </w:tc>
161
+ <w:tc>
162
+ <w:tcPr>
163
+ <w:tcW w:w="3003" w:type="dxa" />
164
+ </w:tcPr>
165
+ <w:p w14:paraId="5D02E3CD" w14:textId="77777777" w:rsidR="00EF161F"
166
+ w:rsidRDefault="00EF161F" />
167
+ </w:tc>
168
+ <w:tc>
169
+ <w:tcPr>
170
+ <w:tcW w:w="3004" w:type="dxa" />
171
+ </w:tcPr>
172
+ <w:p w14:paraId="52EA0DBB" w14:textId="77777777" w:rsidR="00EF161F"
173
+ w:rsidRDefault="00EF161F" />
174
+ </w:tc>
175
+ </w:tr>
176
+ </w:tbl>
177
+ <w:p w14:paraId="47CD1FBC" w14:textId="23474CBC" w:rsidR="007B52ED"
178
+ w:rsidRDefault="007B52ED" />
179
+ <w:p w14:paraId="0ACCEE90" w14:textId="67907499" w:rsidR="00EF161F"
180
+ w:rsidRDefault="0077578F">
181
+ <w:r>
182
+ <w:t>{{image_test}}</w:t>
183
+ </w:r>
184
+ </w:p>
185
+ <w:p w14:paraId="23FA9862" w14:textId="77777777" w:rsidR="0077578F"
186
+ w:rsidRDefault="0077578F" />
187
+ <w:p w14:paraId="01578F2F" w14:textId="3BDC6C85" w:rsidR="007B52ED"
188
+ w:rsidRDefault="007B52ED">
189
+ <w:r>
190
+ <w:t>Thank you</w:t>
191
+ </w:r>
192
+ </w:p>
193
+ <w:sectPr w:rsidR="007B52ED" w:rsidSect="0072043F">
194
+ <w:headerReference w:type="default" r:id="rId6" />
195
+ <w:footerReference w:type="default" r:id="rId7" />
196
+ <w:pgSz w:w="11900" w:h="16840" />
197
+ <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708"
198
+ w:footer="708" w:gutter="0" />
199
+ <w:cols w:space="708" />
200
+ <w:docGrid w:linePitch="360" />
201
+ </w:sectPr>
202
+ </w:body>
203
+ </w:document>
204
+ `;
205
+
206
+ describe("from-docx", () => {
207
+ describe("patchDocument", () => {
208
+ describe("document.xml and [Content_Types].xml", () => {
209
+ before(() => {
210
+ sinon.createStubInstance(JSZip, {});
211
+ sinon.stub(JSZip, "loadAsync").callsFake(
212
+ () =>
213
+ new Promise<JSZip>((resolve) => {
214
+ const zip = new JSZip();
215
+
216
+ zip.file("word/document.xml", MOCK_XML);
217
+ zip.file("[Content_Types].xml", `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>`);
218
+ resolve(zip);
219
+ }),
220
+ );
221
+ });
222
+
223
+ after(() => {
224
+ (JSZip.loadAsync as unknown as sinon.SinonStub).restore();
225
+ });
226
+
227
+ it("should patch the document", async () => {
228
+ const output = await patchDocument(Buffer.from(""), {
229
+ patches: {
230
+ name: {
231
+ type: PatchType.PARAGRAPH,
232
+ children: [new TextRun("Sir. "), new TextRun("John Doe"), new TextRun("(The Conqueror)")],
233
+ },
234
+ item_1: {
235
+ type: PatchType.PARAGRAPH,
236
+ children: [
237
+ new TextRun("#657"),
238
+ new ExternalHyperlink({
239
+ children: [
240
+ new TextRun({
241
+ text: "BBC News Link",
242
+ }),
243
+ ],
244
+ link: "https://www.bbc.co.uk/news",
245
+ }),
246
+ ],
247
+ },
248
+ // eslint-disable-next-line @typescript-eslint/naming-convention
249
+ paragraph_replace: {
250
+ type: PatchType.DOCUMENT,
251
+ children: [
252
+ new Paragraph({
253
+ children: [
254
+ new TextRun("This is a "),
255
+ new ExternalHyperlink({
256
+ children: [
257
+ new TextRun({
258
+ text: "Google Link",
259
+ }),
260
+ ],
261
+ link: "https://www.google.co.uk",
262
+ }),
263
+ new ImageRun({
264
+ data: Buffer.from(""),
265
+ transformation: { width: 100, height: 100 },
266
+ }),
267
+ ],
268
+ }),
269
+ ],
270
+ },
271
+ // eslint-disable-next-line @typescript-eslint/naming-convention
272
+ image_test: {
273
+ type: PatchType.PARAGRAPH,
274
+ children: [
275
+ new ImageRun({
276
+ data: Buffer.from(""),
277
+ transformation: { width: 100, height: 100 },
278
+ }),
279
+ ],
280
+ },
281
+ },
282
+ });
283
+ expect(output).to.not.be.undefined;
284
+ });
285
+
286
+ it("should patch the document", async () => {
287
+ const output = await patchDocument(Buffer.from(""), {
288
+ patches: {},
289
+ });
290
+ expect(output).to.not.be.undefined;
291
+ });
292
+ });
293
+
294
+ describe("document.xml and [Content_Types].xml with relationships", () => {
295
+ before(() => {
296
+ sinon.createStubInstance(JSZip, {});
297
+ sinon.stub(JSZip, "loadAsync").callsFake(
298
+ () =>
299
+ new Promise<JSZip>((resolve) => {
300
+ const zip = new JSZip();
301
+
302
+ zip.file("word/document.xml", MOCK_XML);
303
+ zip.file("word/_rels/document.xml.rels", `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>`);
304
+ zip.file("[Content_Types].xml", `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>`);
305
+ resolve(zip);
306
+ }),
307
+ );
308
+ });
309
+
310
+ after(() => {
311
+ (JSZip.loadAsync as unknown as sinon.SinonStub).restore();
312
+ });
313
+
314
+ it("should use the relationships file rather than create one", async () => {
315
+ const output = await patchDocument(Buffer.from(""), {
316
+ patches: {
317
+ // eslint-disable-next-line @typescript-eslint/naming-convention
318
+ image_test: {
319
+ type: PatchType.PARAGRAPH,
320
+ children: [
321
+ new ImageRun({
322
+ data: Buffer.from(""),
323
+ transformation: { width: 100, height: 100 },
324
+ }),
325
+ ],
326
+ },
327
+ },
328
+ });
329
+ expect(output).to.not.be.undefined;
330
+ });
331
+ });
332
+
333
+ describe("document.xml", () => {
334
+ before(() => {
335
+ sinon.createStubInstance(JSZip, {});
336
+ sinon.stub(JSZip, "loadAsync").callsFake(
337
+ () =>
338
+ new Promise<JSZip>((resolve) => {
339
+ const zip = new JSZip();
340
+
341
+ zip.file("word/document.xml", MOCK_XML);
342
+ resolve(zip);
343
+ }),
344
+ );
345
+ });
346
+
347
+ after(() => {
348
+ (JSZip.loadAsync as unknown as sinon.SinonStub).restore();
349
+ });
350
+
351
+ it("should throw an error if the content types is not found", () =>
352
+ expect(
353
+ patchDocument(Buffer.from(""), {
354
+ patches: {
355
+ // eslint-disable-next-line @typescript-eslint/naming-convention
356
+ image_test: {
357
+ type: PatchType.PARAGRAPH,
358
+ children: [
359
+ new ImageRun({
360
+ data: Buffer.from(""),
361
+ transformation: { width: 100, height: 100 },
362
+ }),
363
+ ],
364
+ },
365
+ },
366
+ }),
367
+ ).to.eventually.be.rejected);
368
+ });
369
+ });
370
+ });
@@ -0,0 +1,233 @@
1
+ import * as JSZip from "jszip";
2
+ import { Element, js2xml } from "xml-js";
3
+
4
+ import { ConcreteHyperlink, ExternalHyperlink, ParagraphChild } from "@file/paragraph";
5
+ import { FileChild } from "@file/file-child";
6
+ import { IMediaData, Media } from "@file/media";
7
+ import { IViewWrapper } from "@file/document-wrapper";
8
+ import { File } from "@file/file";
9
+ import { IContext } from "@file/xml-components";
10
+ import { ImageReplacer } from "@export/packer/image-replacer";
11
+ import { TargetModeType } from "@file/relationships/relationship/relationship";
12
+ import { uniqueId } from "@util/convenience-functions";
13
+
14
+ import { replacer } from "./replacer";
15
+ import { findLocationOfText } from "./traverser";
16
+ import { toJson } from "./util";
17
+ import { appendRelationship, getNextRelationshipIndex } from "./relationship-manager";
18
+ import { appendContentType } from "./content-types-manager";
19
+
20
+ // eslint-disable-next-line functional/prefer-readonly-type
21
+ type InputDataType = Buffer | string | number[] | Uint8Array | ArrayBuffer | Blob | NodeJS.ReadableStream;
22
+
23
+ export enum PatchType {
24
+ DOCUMENT = "file",
25
+ PARAGRAPH = "paragraph",
26
+ }
27
+
28
+ type ParagraphPatch = {
29
+ readonly type: PatchType.PARAGRAPH;
30
+ readonly children: readonly ParagraphChild[];
31
+ };
32
+
33
+ type FilePatch = {
34
+ readonly type: PatchType.DOCUMENT;
35
+ readonly children: readonly FileChild[];
36
+ };
37
+
38
+ interface IImageRelationshipAddition {
39
+ readonly key: string;
40
+ readonly mediaDatas: readonly IMediaData[];
41
+ }
42
+
43
+ interface IHyperlinkRelationshipAddition {
44
+ readonly key: string;
45
+ readonly hyperlink: { readonly id: string; readonly link: string };
46
+ }
47
+
48
+ export type IPatch = ParagraphPatch | FilePatch;
49
+
50
+ export interface PatchDocumentOptions {
51
+ readonly patches: { readonly [key: string]: IPatch };
52
+ }
53
+
54
+ const imageReplacer = new ImageReplacer();
55
+
56
+ export const patchDocument = async (data: InputDataType, options: PatchDocumentOptions): Promise<Buffer> => {
57
+ const zipContent = await JSZip.loadAsync(data);
58
+ const contexts = new Map<string, IContext>();
59
+ const file = {
60
+ Media: new Media(),
61
+ } as unknown as File;
62
+
63
+ const map = new Map<string, Element>();
64
+
65
+ // eslint-disable-next-line functional/prefer-readonly-type
66
+ const imageRelationshipAdditions: IImageRelationshipAddition[] = [];
67
+ // eslint-disable-next-line functional/prefer-readonly-type
68
+ const hyperlinkRelationshipAdditions: IHyperlinkRelationshipAddition[] = [];
69
+ let hasMedia = false;
70
+
71
+ for (const [key, value] of Object.entries(zipContent.files)) {
72
+ const json = toJson(await value.async("text"));
73
+ if (key.startsWith("word/") && !key.endsWith(".xml.rels")) {
74
+ const context: IContext = {
75
+ file,
76
+ viewWrapper: {
77
+ Relationships: {
78
+ createRelationship: (linkId: string, _: string, target: string, __: TargetModeType) => {
79
+ // eslint-disable-next-line functional/immutable-data
80
+ hyperlinkRelationshipAdditions.push({
81
+ key,
82
+ hyperlink: {
83
+ id: linkId,
84
+ link: target,
85
+ },
86
+ });
87
+ },
88
+ },
89
+ } as unknown as IViewWrapper,
90
+ stack: [],
91
+ };
92
+ contexts.set(key, context);
93
+
94
+ for (const [patchKey, patchValue] of Object.entries(options.patches)) {
95
+ const patchText = `{{${patchKey}}}`;
96
+ const renderedParagraphs = findLocationOfText(json, patchText);
97
+ // TODO: mutates json. Make it immutable
98
+ replacer(
99
+ json,
100
+ {
101
+ ...patchValue,
102
+ children: patchValue.children.map((element) => {
103
+ // We need to replace external hyperlinks with concrete hyperlinks
104
+ if (element instanceof ExternalHyperlink) {
105
+ const concreteHyperlink = new ConcreteHyperlink(element.options.children, uniqueId());
106
+ // eslint-disable-next-line functional/immutable-data
107
+ hyperlinkRelationshipAdditions.push({
108
+ key,
109
+ hyperlink: {
110
+ id: concreteHyperlink.linkId,
111
+ link: element.options.link,
112
+ },
113
+ });
114
+ return concreteHyperlink;
115
+ } else {
116
+ return element;
117
+ }
118
+ }),
119
+ },
120
+ patchText,
121
+ renderedParagraphs,
122
+ context,
123
+ );
124
+ }
125
+
126
+ const mediaDatas = imageReplacer.getMediaData(JSON.stringify(json), context.file.Media);
127
+ if (mediaDatas.length > 0) {
128
+ hasMedia = true;
129
+ // eslint-disable-next-line functional/immutable-data
130
+ imageRelationshipAdditions.push({
131
+ key,
132
+ mediaDatas,
133
+ });
134
+ }
135
+ }
136
+
137
+ map.set(key, json);
138
+ }
139
+
140
+ for (const { key, mediaDatas } of imageRelationshipAdditions) {
141
+ // eslint-disable-next-line functional/immutable-data
142
+ const relationshipKey = `word/_rels/${key.split("/").pop()}.rels`;
143
+ const relationshipsJson = map.get(relationshipKey) ?? createRelationshipFile();
144
+ map.set(relationshipKey, relationshipsJson);
145
+
146
+ const index = getNextRelationshipIndex(relationshipsJson);
147
+ const newJson = imageReplacer.replace(JSON.stringify(map.get(key)), mediaDatas, index);
148
+ map.set(key, JSON.parse(newJson) as Element);
149
+
150
+ for (let i = 0; i < mediaDatas.length; i++) {
151
+ const { fileName } = mediaDatas[i];
152
+ appendRelationship(
153
+ relationshipsJson,
154
+ index + i,
155
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
156
+ `media/${fileName}`,
157
+ );
158
+ }
159
+ }
160
+
161
+ for (const { key, hyperlink } of hyperlinkRelationshipAdditions) {
162
+ // eslint-disable-next-line functional/immutable-data
163
+ const relationshipKey = `word/_rels/${key.split("/").pop()}.rels`;
164
+
165
+ const relationshipsJson = map.get(relationshipKey) ?? createRelationshipFile();
166
+ map.set(relationshipKey, relationshipsJson);
167
+
168
+ appendRelationship(
169
+ relationshipsJson,
170
+ hyperlink.id,
171
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",
172
+ hyperlink.link,
173
+ TargetModeType.EXTERNAL,
174
+ );
175
+ }
176
+
177
+ if (hasMedia) {
178
+ const contentTypesJson = map.get("[Content_Types].xml");
179
+
180
+ if (!contentTypesJson) {
181
+ throw new Error("Could not find content types file");
182
+ }
183
+
184
+ appendContentType(contentTypesJson, "image/png", "png");
185
+ appendContentType(contentTypesJson, "image/jpeg", "jpeg");
186
+ appendContentType(contentTypesJson, "image/jpeg", "jpg");
187
+ appendContentType(contentTypesJson, "image/bmp", "bmp");
188
+ appendContentType(contentTypesJson, "image/gif", "gif");
189
+ }
190
+
191
+ const zip = new JSZip();
192
+
193
+ for (const [key, value] of map) {
194
+ const output = toXml(value);
195
+
196
+ zip.file(key, output);
197
+ }
198
+
199
+ for (const { stream, fileName } of file.Media.Array) {
200
+ zip.file(`word/media/${fileName}`, stream);
201
+ }
202
+
203
+ return zip.generateAsync({
204
+ type: "nodebuffer",
205
+ mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
206
+ compression: "DEFLATE",
207
+ });
208
+ };
209
+
210
+ const toXml = (jsonObj: Element): string => {
211
+ const output = js2xml(jsonObj);
212
+ return output;
213
+ };
214
+
215
+ const createRelationshipFile = (): Element => ({
216
+ declaration: {
217
+ attributes: {
218
+ version: "1.0",
219
+ encoding: "UTF-8",
220
+ standalone: "yes",
221
+ },
222
+ },
223
+ elements: [
224
+ {
225
+ type: "element",
226
+ name: "Relationships",
227
+ attributes: {
228
+ xmlns: "http://schemas.openxmlformats.org/package/2006/relationships",
229
+ },
230
+ elements: [],
231
+ },
232
+ ],
233
+ });
@@ -0,0 +1 @@
1
+ export * from "./from-docx";