abstract-document 6.0.2 → 6.0.3

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 (269) hide show
  1. package/CHANGELOG.md +58 -58
  2. package/LICENSE +21 -0
  3. package/README.md +45 -45
  4. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/group.js +90 -90
  5. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/header-and-footer.js +69 -69
  6. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/hello.js +51 -51
  7. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/mixed-hyperlink-and-textrun.js +115 -115
  8. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/mixed-textrun-and-images.js +169 -169
  9. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/multiple-images.js +141 -141
  10. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/multiple-tables.js +467 -467
  11. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/multiple-textrun-with-center-alignment.js +97 -97
  12. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/multiple-textrun-with-end-alignment.js +97 -97
  13. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/multiple-textrun-with-start-alignment-that-linebreaks.js +96 -96
  14. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/multiple-textrun-with-start-alignment.js +96 -96
  15. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/page-numbering.js +102 -102
  16. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/simple-table.js +167 -167
  17. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-hyperlink.js +70 -70
  18. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-image.js +97 -97
  19. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-center-alignment-that-linebreaks.js +68 -68
  20. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-center-alignment.js +68 -68
  21. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-end-alignment-that-linebreaks.js +68 -68
  22. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-end-alignment.js +68 -68
  23. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-start-alignment-that-linebreaks.js +68 -68
  24. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-start-alignment.js +68 -68
  25. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun.js +68 -68
  26. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/world.js +51 -51
  27. package/lib/{abstract-document/__tests__/markdown/test-defs/markdown.d.ts → abstract-document-exporters/__tests__/pdf/test-defs/simple-table-auto-cell-widths.d.ts} +1 -1
  28. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-auto-cell-widths.d.ts.map +1 -0
  29. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-auto-cell-widths.js +105 -0
  30. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-auto-cell-widths.js.map +1 -0
  31. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-fixed-cell-widths.d.ts +3 -0
  32. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-fixed-cell-widths.d.ts.map +1 -0
  33. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-fixed-cell-widths.js +104 -0
  34. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-fixed-cell-widths.js.map +1 -0
  35. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-hex.d.ts.map +1 -1
  36. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-hex.js +0 -1
  37. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-hex.js.map +1 -1
  38. package/lib/abstract-document-exporters/__tests__/{docx2/test-defs/table-of-content-separator.d.ts → pdf/test-defs/single-image-svg-color-url.d.ts} +1 -1
  39. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-url.d.ts.map +1 -0
  40. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-url.js +108 -0
  41. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-url.js.map +1 -0
  42. package/lib/abstract-document-exporters/pdf/render-image.js +2 -2
  43. package/lib/abstract-document-exporters/pdf/render-image.js.map +1 -1
  44. package/package.json +4 -3
  45. package/src/abstract-document/__tests__/hello-world-abstract-doc.ts +245 -245
  46. package/src/abstract-document/__tests__/markdown/export-test-def.ts +10 -10
  47. package/src/abstract-document/__tests__/markdown/export.test.tsx +15 -15
  48. package/src/abstract-document/__tests__/markdown/test-defs/markdown-bold-italic.tsx +30 -30
  49. package/src/abstract-document/__tests__/markdown/test-defs/markdown-bold.tsx +30 -30
  50. package/src/abstract-document/__tests__/markdown/test-defs/markdown-empty-keepTogether.tsx +43 -43
  51. package/src/abstract-document/__tests__/markdown/test-defs/markdown-header.tsx +37 -37
  52. package/src/abstract-document/__tests__/markdown/test-defs/markdown-italic.tsx +30 -30
  53. package/src/abstract-document/__tests__/markdown/test-defs/markdown-keepTogether.tsx +50 -50
  54. package/src/abstract-document/__tests__/markdown/test-defs/markdown-subscript.tsx +44 -44
  55. package/src/abstract-document/__tests__/markdown/test-defs/markdown-superscript.tsx +37 -37
  56. package/src/abstract-document/__tests__/model-builder._test.ts +48 -48
  57. package/src/abstract-document/abstract-doc.ts +19 -19
  58. package/src/abstract-document/atoms/atom.ts +14 -14
  59. package/src/abstract-document/atoms/hyper-link.ts +27 -27
  60. package/src/abstract-document/atoms/image.ts +21 -21
  61. package/src/abstract-document/atoms/link-target.ts +15 -15
  62. package/src/abstract-document/atoms/text-field.ts +36 -36
  63. package/src/abstract-document/atoms/text-run.ts +25 -25
  64. package/src/abstract-document/atoms/toc-separator.ts +14 -14
  65. package/src/abstract-document/default-styles.ts +145 -145
  66. package/src/abstract-document/index.ts +83 -83
  67. package/src/abstract-document/markdown/markdown.ts +142 -142
  68. package/src/abstract-document/markdown/types.ts +78 -78
  69. package/src/abstract-document/numberings/numbering-definition.ts +17 -17
  70. package/src/abstract-document/numberings/numbering-format.ts +7 -7
  71. package/src/abstract-document/numberings/numbering-level-definition.ts +42 -42
  72. package/src/abstract-document/numberings/numbering.ts +3 -3
  73. package/src/abstract-document/page/master-page.ts +23 -23
  74. package/src/abstract-document/page/section.ts +27 -27
  75. package/src/abstract-document/primitives/font.ts +37 -37
  76. package/src/abstract-document/primitives/image-resource.ts +27 -27
  77. package/src/abstract-document/primitives/layout-foundation.ts +37 -37
  78. package/src/abstract-document/primitives/length.ts +11 -11
  79. package/src/abstract-document/primitives/point.ts +11 -11
  80. package/src/abstract-document/primitives/rect.ts +15 -15
  81. package/src/abstract-document/primitives/size.ts +13 -13
  82. package/src/abstract-document/resources.ts +101 -101
  83. package/src/abstract-document/section-elements/group.ts +25 -25
  84. package/src/abstract-document/section-elements/page-break.ts +14 -14
  85. package/src/abstract-document/section-elements/paragraph-numbering.ts +6 -6
  86. package/src/abstract-document/section-elements/paragraph.ts +30 -30
  87. package/src/abstract-document/section-elements/section-element.ts +6 -6
  88. package/src/abstract-document/section-elements/table.ts +37 -37
  89. package/src/abstract-document/styles/page-style.ts +76 -76
  90. package/src/abstract-document/styles/paragraph-style.ts +45 -45
  91. package/src/abstract-document/styles/style-key.ts +5 -5
  92. package/src/abstract-document/styles/style.ts +44 -44
  93. package/src/abstract-document/styles/table-cell-style.ts +54 -54
  94. package/src/abstract-document/styles/table-style.ts +45 -45
  95. package/src/abstract-document/styles/text-style.ts +73 -73
  96. package/src/abstract-document/table/table-cell.ts +29 -29
  97. package/src/abstract-document/table/table-row.ts +17 -17
  98. package/src/abstract-document/types.ts +3 -3
  99. package/src/abstract-document-exporters/__tests__/docx2/export-test-def.ts +10 -10
  100. package/src/abstract-document-exporters/__tests__/docx2/export.test.tsx +67 -67
  101. package/src/abstract-document-exporters/__tests__/docx2/test-defs/group.tsx +114 -114
  102. package/src/abstract-document-exporters/__tests__/docx2/test-defs/header-and-footer.tsx +110 -110
  103. package/src/abstract-document-exporters/__tests__/docx2/test-defs/hello.tsx +70 -70
  104. package/src/abstract-document-exporters/__tests__/docx2/test-defs/mixed-hyperlink-and-textrun.tsx +137 -137
  105. package/src/abstract-document-exporters/__tests__/docx2/test-defs/mixed-textrun-and-images.tsx +212 -212
  106. package/src/abstract-document-exporters/__tests__/docx2/test-defs/multiple-images.tsx +182 -182
  107. package/src/abstract-document-exporters/__tests__/docx2/test-defs/multiple-tables.tsx +553 -553
  108. package/src/abstract-document-exporters/__tests__/docx2/test-defs/multiple-textrun-with-center-alignment.tsx +119 -119
  109. package/src/abstract-document-exporters/__tests__/docx2/test-defs/multiple-textrun-with-end-alignment.tsx +119 -119
  110. package/src/abstract-document-exporters/__tests__/docx2/test-defs/multiple-textrun-with-start-alignment-that-linebreaks.tsx +121 -121
  111. package/src/abstract-document-exporters/__tests__/docx2/test-defs/multiple-textrun-with-start-alignment.tsx +118 -118
  112. package/src/abstract-document-exporters/__tests__/docx2/test-defs/page-numbering.tsx +123 -123
  113. package/src/abstract-document-exporters/__tests__/docx2/test-defs/simple-table.tsx +210 -210
  114. package/src/abstract-document-exporters/__tests__/docx2/test-defs/single-hyperlink.tsx +89 -89
  115. package/src/abstract-document-exporters/__tests__/docx2/test-defs/single-image.tsx +137 -137
  116. package/src/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-center-alignment-that-linebreaks.tsx +88 -88
  117. package/src/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-center-alignment.tsx +88 -88
  118. package/src/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-end-alignment-that-linebreaks.tsx +88 -88
  119. package/src/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-end-alignment.tsx +88 -88
  120. package/src/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-start-alignment-that-linebreaks.tsx +88 -88
  121. package/src/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-start-alignment.tsx +88 -88
  122. package/src/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun.tsx +87 -87
  123. package/src/abstract-document-exporters/__tests__/docx2/test-defs/world.tsx +70 -70
  124. package/src/abstract-document-exporters/__tests__/docx2/tmp/Group.docx +0 -0
  125. package/src/abstract-document-exporters/__tests__/docx2/tmp/Header and footer.docx and b/package/src/abstract-document-exporters/__tests__/docx2/tmp/Header → footer.docx +0 -0
  126. package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed hyperlink and textrun.docx and b/package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed hyperlink → textrun.docx +0 -0
  127. package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed textrun and images.docx and b/package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed textrun → images.docx +0 -0
  128. package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple images.docx +0 -0
  129. package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple tables.docx +0 -0
  130. package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with Center alignment.docx +0 -0
  131. package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with End alignment.docx +0 -0
  132. package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with Start alignment that linebreaks.docx +0 -0
  133. package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with Start alignment.docx +0 -0
  134. package/src/abstract-document-exporters/__tests__/docx2/tmp/Page numbering.docx +0 -0
  135. package/src/abstract-document-exporters/__tests__/docx2/tmp/Simple table.docx +0 -0
  136. package/src/abstract-document-exporters/__tests__/docx2/tmp/Single hyperlink.docx +0 -0
  137. package/src/abstract-document-exporters/__tests__/docx2/tmp/Single image.docx +0 -0
  138. package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Center alignment that linebreaks.docx +0 -0
  139. package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Center alignment.docx +0 -0
  140. package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with End alignment that linebreaks.docx +0 -0
  141. package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with End alignment.docx +0 -0
  142. package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Start alignment that linebreaks.docx +0 -0
  143. package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Start alignment.docx +0 -0
  144. package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun.docx +0 -0
  145. package/src/abstract-document-exporters/__tests__/docx2/tmp/hello.docx +0 -0
  146. package/src/abstract-document-exporters/__tests__/docx2/tmp/world.docx +0 -0
  147. package/src/abstract-document-exporters/__tests__/pdf/export-test-def.ts +10 -10
  148. package/src/abstract-document-exporters/__tests__/pdf/export.test.tsx +46 -46
  149. package/src/abstract-document-exporters/__tests__/pdf/test-defs/date.tsx +66 -66
  150. package/src/abstract-document-exporters/__tests__/pdf/test-defs/group-paragraphs.tsx +1291 -1291
  151. package/src/abstract-document-exporters/__tests__/pdf/test-defs/group-tables.tsx +1314 -1314
  152. package/src/abstract-document-exporters/__tests__/pdf/test-defs/header-and-footer.tsx +162 -162
  153. package/src/abstract-document-exporters/__tests__/pdf/test-defs/hello.tsx +45 -45
  154. package/src/abstract-document-exporters/__tests__/pdf/test-defs/margins-header-body-footer.tsx +1008 -1008
  155. package/src/abstract-document-exporters/__tests__/pdf/test-defs/mixed-hyperlink-and-textrun.tsx +113 -113
  156. package/src/abstract-document-exporters/__tests__/pdf/test-defs/mixed-textrun-and-images.tsx +104 -104
  157. package/src/abstract-document-exporters/__tests__/pdf/test-defs/multiple-images.tsx +71 -71
  158. package/src/abstract-document-exporters/__tests__/pdf/test-defs/multiple-textrun-with-center-alignment.tsx +98 -98
  159. package/src/abstract-document-exporters/__tests__/pdf/test-defs/multiple-textrun-with-end-alignment.tsx +98 -98
  160. package/src/abstract-document-exporters/__tests__/pdf/test-defs/multiple-textrun-with-start-alignment-that-linebreaks.tsx +116 -116
  161. package/src/abstract-document-exporters/__tests__/pdf/test-defs/multiple-textrun-with-start-alignment.tsx +98 -98
  162. package/src/abstract-document-exporters/__tests__/pdf/test-defs/page-numbering.tsx +97 -97
  163. package/src/abstract-document-exporters/__tests__/pdf/test-defs/pagebreak.tsx +102 -102
  164. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-all-auto-cell-widths.tsx +119 -119
  165. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-all-fixed-cell-widths.tsx +119 -119
  166. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-cell-padding-image.tsx +200 -200
  167. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-cell-padding-text.tsx +338 -338
  168. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-center-alignment.tsx +114 -114
  169. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-mix-auto-fix-cell-widths.tsx +119 -119
  170. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-padding.tsx +115 -115
  171. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-right-alignment.tsx +115 -115
  172. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-row-alignment.tsx +297 -297
  173. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-text-alignment-in-cell-wrapping.tsx +491 -491
  174. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-text-alignment-in-cell.tsx +248 -248
  175. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-hyperlink.tsx +65 -65
  176. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-hex.tsx +272 -273
  177. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-name.tsx +272 -272
  178. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-url.tsx +97 -0
  179. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-image.tsx +70 -70
  180. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun-with-center-alignment-that-linebreaks.tsx +81 -81
  181. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun-with-center-alignment.tsx +66 -66
  182. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun-with-end-alignment-that-linebreaks.tsx +81 -81
  183. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun-with-end-alignment.tsx +66 -66
  184. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun-with-start-alignment-that-linebreaks.tsx +81 -81
  185. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun-with-start-alignment.tsx +66 -66
  186. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun.tsx +45 -45
  187. package/src/abstract-document-exporters/__tests__/pdf/test-defs/table-of-content-separator.tsx +81 -81
  188. package/src/abstract-document-exporters/__tests__/pdf/test-defs/world.tsx +45 -45
  189. package/src/abstract-document-exporters/__tests__/pdf/tmp/Group Paragraphs.pdf +2 -2
  190. package/src/abstract-document-exporters/__tests__/pdf/tmp/Group Paratraphs.pdf +912 -0
  191. package/src/abstract-document-exporters/__tests__/pdf/tmp/Group Tables.pdf +2 -2
  192. package/src/abstract-document-exporters/__tests__/pdf/tmp/Group.pdf +2 -2
  193. package/src/abstract-document-exporters/__tests__/pdf/tmp/Header and footer.pdf +2 -2
  194. package/src/abstract-document-exporters/__tests__/pdf/tmp/Margins header body footer.pdf +2 -2
  195. package/src/abstract-document-exporters/__tests__/pdf/tmp/Margins header body footer1.pdf +640 -0
  196. package/src/abstract-document-exporters/__tests__/pdf/tmp/Margins header body footer2.pdf +609 -0
  197. package/src/abstract-document-exporters/__tests__/pdf/tmp/Margins header body footer3.pdf +1188 -0
  198. package/src/abstract-document-exporters/__tests__/pdf/tmp/Margins header body footer4.pdf +1188 -0
  199. package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed hyperlink and textrun.pdf +2 -2
  200. package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed textrun and images.pdf and b/package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed textrun → images.pdf +0 -0
  201. package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple images.pdf +0 -0
  202. package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with Center alignment.pdf +2 -2
  203. package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with End alignment.pdf +2 -2
  204. package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with Start alignment that linebreaks.pdf +2 -2
  205. package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with Start alignment.pdf +2 -2
  206. package/src/abstract-document-exporters/__tests__/pdf/tmp/Page numbering.pdf +2 -2
  207. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table all auto.pdf +2 -2
  208. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table all fix.pdf +2 -2
  209. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table auto.pdf +133 -0
  210. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table cell padding of image.pdf +0 -0
  211. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table cell padding of text.pdf +2 -2
  212. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table center alignment.pdf +2 -2
  213. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table mix auto fix.pdf +2 -2
  214. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table one auto.pdf +133 -0
  215. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table padding.pdf +2 -2
  216. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table padding1.pdf +133 -0
  217. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table right alignment.pdf +2 -2
  218. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table row alignment.pdf +2 -2
  219. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table text alignment in cell with wrapping.pdf +2 -2
  220. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table text alignment in cell.pdf +2 -2
  221. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table.pdf +2 -2
  222. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single date.pdf +14 -14
  223. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single hyperlink.pdf +2 -2
  224. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg color hex.pdf +2 -2
  225. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg color name.pdf +179 -0
  226. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg color url.pdf +222 -0
  227. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg color.pdf +179 -0
  228. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image.pdf +0 -0
  229. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Center alignment that linebreaks.pdf +2 -2
  230. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Center alignment.pdf +2 -2
  231. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with End alignment that linebreaks.pdf +2 -2
  232. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with End alignment.pdf +2 -2
  233. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Start alignment that linebreaks.pdf +2 -2
  234. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Start alignment.pdf +2 -2
  235. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun.pdf +2 -2
  236. package/src/abstract-document-exporters/__tests__/pdf/tmp/Table of content separator.pdf +2 -2
  237. package/src/abstract-document-exporters/__tests__/pdf/tmp/hello.pdf +2 -2
  238. package/src/abstract-document-exporters/__tests__/pdf/tmp/world.pdf +2 -2
  239. package/src/abstract-document-exporters/docx/document-container.ts +18 -18
  240. package/src/abstract-document-exporters/docx/docx-constants.ts +46 -46
  241. package/src/abstract-document-exporters/docx/docx-document-renderer.ts +1084 -1084
  242. package/src/abstract-document-exporters/docx/ref-container.ts +53 -53
  243. package/src/abstract-document-exporters/docx/string-utils.ts +39 -39
  244. package/src/abstract-document-exporters/docx/xml-writer.ts +333 -333
  245. package/src/abstract-document-exporters/docx2/render-image.ts +159 -159
  246. package/src/abstract-document-exporters/docx2/render.ts +476 -476
  247. package/src/abstract-document-exporters/index.ts +5 -5
  248. package/src/abstract-document-exporters/pdf/font.ts +67 -67
  249. package/src/abstract-document-exporters/pdf/measure.ts +410 -410
  250. package/src/abstract-document-exporters/pdf/paginate.ts +337 -337
  251. package/src/abstract-document-exporters/pdf/pre-process.ts +363 -363
  252. package/src/abstract-document-exporters/pdf/render-image.ts +189 -189
  253. package/src/abstract-document-exporters/pdf/render.ts +752 -752
  254. package/src/abstract-document-exporters/pdf/update-refs.ts +163 -163
  255. package/src/abstract-document-exporters/shared/get_resources.ts +71 -71
  256. package/src/abstract-document-jsx/index.ts +86 -86
  257. package/src/index.ts +5 -5
  258. package/lib/abstract-document/__tests__/markdown/test-defs/markdown.d.ts.map +0 -1
  259. package/lib/abstract-document/__tests__/markdown/test-defs/markdown.js +0 -14
  260. package/lib/abstract-document/__tests__/markdown/test-defs/markdown.js.map +0 -1
  261. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/table-of-content-separator.d.ts.map +0 -1
  262. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/table-of-content-separator.js +0 -18
  263. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/table-of-content-separator.js.map +0 -1
  264. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-date.d.ts +0 -1
  265. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-date.d.ts.map +0 -1
  266. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-date.js +0 -70
  267. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-date.js.map +0 -1
  268. package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple tables.zip +0 -0
  269. package/src/abstract-document-exporters/__tests__/docx2/tmp/Table of content separator.docx +0 -0
@@ -1,476 +1,476 @@
1
- import * as AD from "../../abstract-document";
2
- import * as DOCXJS from "docx";
3
- import { renderImage } from "./render-image";
4
- import { Readable } from "stream";
5
-
6
- const abstractDocToDocxFontRatio = 2;
7
- const abstractDocPixelToDocxDXARatio = 20;
8
-
9
- export function exportToHTML5Blob(doc: AD.AbstractDoc.AbstractDoc): Promise<Blob> {
10
- return new Promise((resolve) => {
11
- const docx = createDocument(doc);
12
- DOCXJS.Packer.toBlob(docx).then((blob) => {
13
- resolve(blob);
14
- });
15
- });
16
- }
17
-
18
- export function exportToStream(blobStream: NodeJS.WritableStream, doc: AD.AbstractDoc.AbstractDoc): void {
19
- const docx = createDocument(doc);
20
-
21
- DOCXJS.Packer.toBuffer(docx).then((buffer) => {
22
- const readableStream = new Readable();
23
- readableStream.push(buffer);
24
- readableStream.push(null);
25
- readableStream.pipe(blobStream);
26
- });
27
- }
28
-
29
- /**
30
- * On the client side the stream can be a BlobStream from the blob-stream package.
31
- * On the server-side the stream can be a file stream from the fs package.
32
- * @param blobStream
33
- * @param doc
34
- */
35
-
36
- function createDocument(doc: AD.AbstractDoc.AbstractDoc): DOCXJS.Document {
37
- const docx = new DOCXJS.Document({
38
- sections: doc.children.map((s) => renderSection(s, doc)),
39
- });
40
- return docx;
41
- }
42
-
43
- function renderSection(section: AD.Section.Section, parentResources: AD.Resources.Resources): DOCXJS.ISectionOptions {
44
- const resources = AD.Resources.mergeResources([parentResources, section]);
45
-
46
- const headerChildren = section.page.header.reduce((sofar, c) => {
47
- sofar.push(...renderSectionElement(c, resources));
48
- return sofar;
49
- }, [] as Array<DOCXJS.Paragraph | DOCXJS.Table>);
50
-
51
- const footerChildren = [
52
- ...section.page.footer.reduce((sofar, c) => {
53
- sofar.push(...renderSectionElement(c, resources));
54
- return sofar;
55
- }, [] as Array<DOCXJS.Paragraph | DOCXJS.Table>),
56
- ];
57
-
58
- const contentChildren = [
59
- new DOCXJS.Paragraph({
60
- spacing: { before: 0, after: 0, line: 1 },
61
- children: [
62
- new DOCXJS.Bookmark({
63
- id: section.id,
64
- children: [],
65
- }),
66
- ],
67
- }),
68
- ...section.children.reduce((sofar, c) => {
69
- sofar.push(...renderSectionElement(c, resources));
70
- return sofar;
71
- }, [] as Array<DOCXJS.Paragraph | DOCXJS.Table>),
72
- ];
73
-
74
- return {
75
- properties: {
76
- page: {
77
- size: {
78
- orientation:
79
- section.page.style.orientation === "Landscape"
80
- ? DOCXJS.PageOrientation.LANDSCAPE
81
- : DOCXJS.PageOrientation.PORTRAIT,
82
- },
83
- margin: {
84
- bottom: section.page.style.contentMargins.bottom * abstractDocPixelToDocxDXARatio,
85
- top: section.page.style.contentMargins.top * abstractDocPixelToDocxDXARatio,
86
- right: section.page.style.contentMargins.right * abstractDocPixelToDocxDXARatio,
87
- left: section.page.style.contentMargins.left * abstractDocPixelToDocxDXARatio,
88
- header: section.page.style.headerMargins.top * abstractDocPixelToDocxDXARatio,
89
- footer: section.page.style.footerMargins.bottom * abstractDocPixelToDocxDXARatio,
90
- },
91
- },
92
- },
93
- headers: {
94
- default: new DOCXJS.Header({
95
- children: headerChildren,
96
- }),
97
- },
98
- footers: {
99
- default: new DOCXJS.Footer({
100
- children: footerChildren,
101
- }),
102
- },
103
- children: contentChildren,
104
- };
105
- }
106
-
107
- function renderHyperLink(
108
- hyperLink: AD.HyperLink.HyperLink,
109
- style: AD.TextStyle.TextStyle
110
- ): DOCXJS.InternalHyperlink | DOCXJS.ExternalHyperlink {
111
- const fontSize = AD.TextStyle.calculateFontSize(style, 10) * 2;
112
- const textRun = new DOCXJS.TextRun({
113
- text: hyperLink.text,
114
- font: "Arial",
115
- size: fontSize,
116
- color: style.color || "blue",
117
- bold: style.bold,
118
- underline: style.underline
119
- ? {
120
- color: style.color || "blue",
121
- type: DOCXJS.UnderlineType.SINGLE,
122
- }
123
- : undefined,
124
- });
125
-
126
- if (hyperLink.target.startsWith("#") && !hyperLink.target.startsWith("#page=")) {
127
- return new DOCXJS.InternalHyperlink({
128
- anchor: hyperLink.target,
129
- child: textRun,
130
- });
131
- } else {
132
- return new DOCXJS.ExternalHyperlink({
133
- link: hyperLink.target,
134
- child: textRun,
135
- });
136
- }
137
- }
138
-
139
- function renderSectionElement(
140
- element: AD.SectionElement.SectionElement,
141
- parentResources: AD.Resources.Resources
142
- ): ReadonlyArray<DOCXJS.Paragraph | DOCXJS.Table> /*| DOCXJS.TableOfContents | DOCXJS.HyperlinkRef */ {
143
- const resources = AD.Resources.mergeResources([parentResources, element]);
144
- switch (element.type) {
145
- case "Paragraph":
146
- return [renderParagraph(element, resources)];
147
- case "Group":
148
- return [...renderGroup(element, parentResources)];
149
- case "Table":
150
- return [
151
- renderTable(element, resources),
152
- new DOCXJS.Paragraph({ children: [new DOCXJS.TextRun({ text: ".", size: 0.000001 })] }),
153
- ];
154
- case "PageBreak":
155
- return [
156
- new DOCXJS.Paragraph({
157
- pageBreakBefore: true,
158
- }),
159
- ];
160
- default:
161
- return [new DOCXJS.Paragraph({})];
162
- }
163
- }
164
-
165
- function renderTable(table: AD.Table.Table, resources: AD.Resources.Resources): DOCXJS.Table {
166
- const style = AD.Resources.getStyle(
167
- undefined,
168
- table.style,
169
- "TableStyle",
170
- table.styleName,
171
- resources
172
- ) as AD.TableStyle.TableStyle;
173
-
174
- const fullWidth = table.columnWidths.some((c) => !Number.isFinite(c));
175
- const columnWidths = table.columnWidths.map((c) => c * abstractDocPixelToDocxDXARatio);
176
- return new DOCXJS.Table({
177
- alignment:
178
- style.alignment === "Left"
179
- ? DOCXJS.AlignmentType.LEFT
180
- : style.alignment === "Right"
181
- ? DOCXJS.AlignmentType.RIGHT
182
- : DOCXJS.AlignmentType.CENTER,
183
- margins: {
184
- top: style.margins.top * abstractDocPixelToDocxDXARatio,
185
- bottom: style.margins.bottom * abstractDocPixelToDocxDXARatio,
186
- left: style.margins.left * abstractDocPixelToDocxDXARatio,
187
- right: style.margins.right * abstractDocPixelToDocxDXARatio,
188
- },
189
- width: fullWidth
190
- ? {
191
- size: 100,
192
- type: DOCXJS.WidthType.PERCENTAGE,
193
- }
194
- : {
195
- type: DOCXJS.WidthType.DXA,
196
- size: columnWidths.reduce((a, b) => a + b),
197
- },
198
- borders: {
199
- top: {
200
- color: style.cellStyle.borderColor ?? "",
201
- size: 0,
202
- style: DOCXJS.BorderStyle.NONE,
203
- },
204
- right: {
205
- color: style.cellStyle.borderColor ?? "",
206
- size: 0,
207
- style: DOCXJS.BorderStyle.NONE,
208
- },
209
- bottom: {
210
- color: style.cellStyle.borderColor ?? "",
211
- size: 0,
212
- style: DOCXJS.BorderStyle.NONE,
213
- },
214
- left: {
215
- color: style.cellStyle.borderColor ?? "",
216
- size: 0,
217
- style: DOCXJS.BorderStyle.NONE,
218
- },
219
- insideHorizontal: {
220
- color: style.cellStyle.borderColor ?? "",
221
- size: 0,
222
- style: DOCXJS.BorderStyle.NONE,
223
- },
224
- insideVertical: {
225
- color: style.cellStyle.borderColor ?? "",
226
- size: 0,
227
- style: DOCXJS.BorderStyle.NONE,
228
- },
229
- },
230
- rows: table.children.map((c) => renderRow(c, resources, style.cellStyle, columnWidths)),
231
- });
232
- }
233
-
234
- function renderRow(
235
- row: AD.TableRow.TableRow,
236
- resources: AD.Resources.Resources,
237
- tableCellStyle: AD.TableCellStyle.TableCellStyle,
238
- columnWidths: ReadonlyArray<number>
239
- ): DOCXJS.TableRow {
240
- return new DOCXJS.TableRow({
241
- cantSplit: true,
242
- children: row.children.map((c, ix) => renderCell(c, resources, tableCellStyle, columnWidths[ix])),
243
- });
244
- }
245
-
246
- function renderCell(
247
- cell: AD.TableCell.TableCell,
248
- resources: AD.Resources.Resources,
249
- tableCellStyle: AD.TableCellStyle.TableCellStyle,
250
- width: number
251
- ): DOCXJS.TableCell {
252
- const style = AD.Resources.getStyle(
253
- tableCellStyle,
254
- cell.style,
255
- "TableCellStyle",
256
- cell.styleName,
257
- resources
258
- ) as AD.TableCellStyle.TableCellStyle;
259
-
260
- return new DOCXJS.TableCell({
261
- verticalAlign:
262
- (style.verticalAlignment && style.verticalAlignment === "Top"
263
- ? DOCXJS.VerticalAlign.TOP
264
- : style.verticalAlignment === "Bottom"
265
- ? DOCXJS.VerticalAlign.BOTTOM
266
- : DOCXJS.VerticalAlign.CENTER) || undefined,
267
- shading: {
268
- fill: style.background ? style.background : undefined,
269
- },
270
- columnSpan: cell.columnSpan,
271
- width: isFinite(width)
272
- ? {
273
- type: DOCXJS.WidthType.DXA,
274
- size: width,
275
- }
276
- : {
277
- type: DOCXJS.WidthType.AUTO,
278
- size: "",
279
- },
280
- margins: {
281
- top: Math.max(style.padding.top, 0) * abstractDocPixelToDocxDXARatio,
282
- bottom: Math.max(style.padding.bottom, 0) * abstractDocPixelToDocxDXARatio,
283
- left: Math.max(style.padding.left, 0) * abstractDocPixelToDocxDXARatio,
284
- right: Math.max(style.padding.right, 0) * abstractDocPixelToDocxDXARatio,
285
- },
286
- borders: {
287
- top: {
288
- color: style.borderColor ?? "",
289
- size: style.borders.top,
290
- style: style.borders.top ? DOCXJS.BorderStyle.SINGLE : DOCXJS.BorderStyle.NONE,
291
- },
292
- right: {
293
- color: style.borderColor ?? "",
294
- size: style.borders.right,
295
- style: style.borders.right ? DOCXJS.BorderStyle.SINGLE : DOCXJS.BorderStyle.NONE,
296
- },
297
- bottom: {
298
- color: style.borderColor ?? "",
299
- size: style.borders.bottom,
300
- style: style.borders.bottom ? DOCXJS.BorderStyle.SINGLE : DOCXJS.BorderStyle.NONE,
301
- },
302
- left: {
303
- color: style.borderColor ?? "",
304
- size: style.borders.left,
305
- style: style.borders.left ? DOCXJS.BorderStyle.SINGLE : DOCXJS.BorderStyle.NONE,
306
- },
307
- },
308
-
309
- children: cell.children.reduce((sofar, c) => {
310
- sofar.push(...renderSectionElement(c, resources));
311
- return sofar;
312
- }, [] as Array<DOCXJS.Paragraph | DOCXJS.Table>),
313
- });
314
- }
315
-
316
- function renderAtom(
317
- resources: AD.Resources.Resources,
318
- textStyle: AD.TextStyle.TextStyle,
319
- atom: AD.Atom.Atom
320
- ):
321
- | DOCXJS.TextRun
322
- | DOCXJS.ImageRun
323
- | DOCXJS.SymbolRun
324
- | DOCXJS.Bookmark
325
- | DOCXJS.PageBreak
326
- | DOCXJS.SequentialIdentifier
327
- | DOCXJS.FootnoteReferenceRun
328
- | DOCXJS.InsertedTextRun
329
- | DOCXJS.DeletedTextRun
330
- | DOCXJS.InternalHyperlink
331
- | DOCXJS.ExternalHyperlink
332
- | DOCXJS.Math {
333
- switch (atom.type) {
334
- case "TextField":
335
- return renderTextField(resources, textStyle, atom);
336
- case "TextRun":
337
- return renderTextRun(resources, textStyle, atom);
338
- case "Image":
339
- return renderImage(atom, textStyle);
340
- case "HyperLink":
341
- return renderHyperLink(atom, textStyle);
342
- default:
343
- return new DOCXJS.TextRun({ text: "missed" }); // TODO
344
- }
345
- }
346
-
347
- function renderTextField(
348
- resources: AD.Resources.Resources,
349
- textStyle: AD.TextStyle.TextStyle,
350
- textField: AD.TextField.TextField
351
- ): DOCXJS.TextRun {
352
- const style = AD.Resources.getStyle(
353
- textStyle,
354
- textField.style,
355
- "TextStyle",
356
- textField.styleName,
357
- resources
358
- ) as AD.TextStyle.TextStyle;
359
- switch (textField.fieldType) {
360
- case "Date":
361
- return renderText(style, new Date(Date.now()).toDateString());
362
- case "PageNumber":
363
- return renderPageNumber(style);
364
- case "TotalPages":
365
- return renderTotalPages(style);
366
- default:
367
- return renderText(style, "");
368
- }
369
- }
370
-
371
- function renderTextRun(
372
- resources: AD.Resources.Resources,
373
- textStyle: AD.TextStyle.TextStyle,
374
- textRun: AD.TextRun.TextRun
375
- ): DOCXJS.TextRun {
376
- const style = AD.Resources.getNestedStyle(
377
- textStyle,
378
- textRun.style,
379
- "TextStyle",
380
- textRun.styleName,
381
- resources,
382
- textRun.nestedStyleNames || []
383
- ) as AD.TextStyle.TextStyle;
384
-
385
- return renderText(style, textRun.text);
386
- }
387
-
388
- function renderPageNumber(style: AD.TextStyle.TextStyle): DOCXJS.TextRun {
389
- const fontSize = AD.TextStyle.calculateFontSize(style, 10) * abstractDocToDocxFontRatio;
390
- return new DOCXJS.TextRun({
391
- font: "Arial",
392
- size: fontSize,
393
- color: style.color || "black",
394
- bold: style.bold,
395
- underline: style.underline
396
- ? {
397
- color: style.color,
398
- type: DOCXJS.UnderlineType.SINGLE,
399
- }
400
- : undefined,
401
- children: [DOCXJS.PageNumber.CURRENT],
402
- });
403
- }
404
-
405
- function renderTotalPages(style: AD.TextStyle.TextStyle): DOCXJS.TextRun {
406
- const fontSize = AD.TextStyle.calculateFontSize(style, 10) * abstractDocToDocxFontRatio;
407
- return new DOCXJS.TextRun({
408
- font: "Arial",
409
- size: fontSize,
410
- color: style.color || "black",
411
- bold: style.bold,
412
- underline: style.underline
413
- ? {
414
- color: style.color,
415
- type: DOCXJS.UnderlineType.SINGLE,
416
- }
417
- : undefined,
418
- children: [DOCXJS.PageNumber.TOTAL_PAGES],
419
- });
420
- }
421
-
422
- function renderText(style: AD.TextStyle.TextStyle, text: string): DOCXJS.TextRun {
423
- const fontSize = AD.TextStyle.calculateFontSize(style, 10) * abstractDocToDocxFontRatio;
424
-
425
- return new DOCXJS.TextRun({
426
- text: text,
427
- font: "Arial",
428
- size: fontSize,
429
- color: style.color || "black",
430
- bold: style.bold,
431
- underline: style.underline
432
- ? {
433
- color: style.color,
434
- type: DOCXJS.UnderlineType.SINGLE,
435
- }
436
- : undefined,
437
- });
438
- }
439
-
440
- function renderGroup(group: AD.Group.Group, resources: AD.Resources.Resources): Array<DOCXJS.Paragraph | DOCXJS.Table> {
441
- return group.children.reduce((sofar, c) => {
442
- sofar.push(...renderSectionElement(c, resources));
443
- return sofar;
444
- }, [] as Array<DOCXJS.Paragraph | DOCXJS.Table>);
445
- }
446
-
447
- function renderParagraph(paragraph: AD.Paragraph.Paragraph, resources: AD.Resources.Resources): DOCXJS.Paragraph {
448
- const style = AD.Resources.getStyle(
449
- undefined,
450
- paragraph.style,
451
- "ParagraphStyle",
452
- paragraph.styleName,
453
- resources
454
- ) as AD.ParagraphStyle.ParagraphStyle;
455
-
456
- return new DOCXJS.Paragraph({
457
- alignment:
458
- (style.alignment &&
459
- (style.alignment === "Center"
460
- ? DOCXJS.AlignmentType.CENTER
461
- : style.alignment === "End"
462
- ? DOCXJS.AlignmentType.END
463
- : DOCXJS.AlignmentType.START)) ||
464
- undefined,
465
-
466
- spacing: {
467
- before: Math.max(style.margins.top, 0) * abstractDocPixelToDocxDXARatio,
468
- after: Math.max(style.margins.bottom, 0) * abstractDocPixelToDocxDXARatio,
469
- },
470
- indent: {
471
- left: Math.max(style.margins.left, 0) * abstractDocPixelToDocxDXARatio,
472
- right: Math.max(style.margins.right, 0) * abstractDocPixelToDocxDXARatio,
473
- },
474
- children: paragraph.children.map((atom) => renderAtom(resources, style.textStyle, atom)),
475
- });
476
- }
1
+ import * as AD from "../../abstract-document";
2
+ import * as DOCXJS from "docx";
3
+ import { renderImage } from "./render-image";
4
+ import { Readable } from "stream";
5
+
6
+ const abstractDocToDocxFontRatio = 2;
7
+ const abstractDocPixelToDocxDXARatio = 20;
8
+
9
+ export function exportToHTML5Blob(doc: AD.AbstractDoc.AbstractDoc): Promise<Blob> {
10
+ return new Promise((resolve) => {
11
+ const docx = createDocument(doc);
12
+ DOCXJS.Packer.toBlob(docx).then((blob) => {
13
+ resolve(blob);
14
+ });
15
+ });
16
+ }
17
+
18
+ export function exportToStream(blobStream: NodeJS.WritableStream, doc: AD.AbstractDoc.AbstractDoc): void {
19
+ const docx = createDocument(doc);
20
+
21
+ DOCXJS.Packer.toBuffer(docx).then((buffer) => {
22
+ const readableStream = new Readable();
23
+ readableStream.push(buffer);
24
+ readableStream.push(null);
25
+ readableStream.pipe(blobStream);
26
+ });
27
+ }
28
+
29
+ /**
30
+ * On the client side the stream can be a BlobStream from the blob-stream package.
31
+ * On the server-side the stream can be a file stream from the fs package.
32
+ * @param blobStream
33
+ * @param doc
34
+ */
35
+
36
+ function createDocument(doc: AD.AbstractDoc.AbstractDoc): DOCXJS.Document {
37
+ const docx = new DOCXJS.Document({
38
+ sections: doc.children.map((s) => renderSection(s, doc)),
39
+ });
40
+ return docx;
41
+ }
42
+
43
+ function renderSection(section: AD.Section.Section, parentResources: AD.Resources.Resources): DOCXJS.ISectionOptions {
44
+ const resources = AD.Resources.mergeResources([parentResources, section]);
45
+
46
+ const headerChildren = section.page.header.reduce((sofar, c) => {
47
+ sofar.push(...renderSectionElement(c, resources));
48
+ return sofar;
49
+ }, [] as Array<DOCXJS.Paragraph | DOCXJS.Table>);
50
+
51
+ const footerChildren = [
52
+ ...section.page.footer.reduce((sofar, c) => {
53
+ sofar.push(...renderSectionElement(c, resources));
54
+ return sofar;
55
+ }, [] as Array<DOCXJS.Paragraph | DOCXJS.Table>),
56
+ ];
57
+
58
+ const contentChildren = [
59
+ new DOCXJS.Paragraph({
60
+ spacing: { before: 0, after: 0, line: 1 },
61
+ children: [
62
+ new DOCXJS.Bookmark({
63
+ id: section.id,
64
+ children: [],
65
+ }),
66
+ ],
67
+ }),
68
+ ...section.children.reduce((sofar, c) => {
69
+ sofar.push(...renderSectionElement(c, resources));
70
+ return sofar;
71
+ }, [] as Array<DOCXJS.Paragraph | DOCXJS.Table>),
72
+ ];
73
+
74
+ return {
75
+ properties: {
76
+ page: {
77
+ size: {
78
+ orientation:
79
+ section.page.style.orientation === "Landscape"
80
+ ? DOCXJS.PageOrientation.LANDSCAPE
81
+ : DOCXJS.PageOrientation.PORTRAIT,
82
+ },
83
+ margin: {
84
+ bottom: section.page.style.contentMargins.bottom * abstractDocPixelToDocxDXARatio,
85
+ top: section.page.style.contentMargins.top * abstractDocPixelToDocxDXARatio,
86
+ right: section.page.style.contentMargins.right * abstractDocPixelToDocxDXARatio,
87
+ left: section.page.style.contentMargins.left * abstractDocPixelToDocxDXARatio,
88
+ header: section.page.style.headerMargins.top * abstractDocPixelToDocxDXARatio,
89
+ footer: section.page.style.footerMargins.bottom * abstractDocPixelToDocxDXARatio,
90
+ },
91
+ },
92
+ },
93
+ headers: {
94
+ default: new DOCXJS.Header({
95
+ children: headerChildren,
96
+ }),
97
+ },
98
+ footers: {
99
+ default: new DOCXJS.Footer({
100
+ children: footerChildren,
101
+ }),
102
+ },
103
+ children: contentChildren,
104
+ };
105
+ }
106
+
107
+ function renderHyperLink(
108
+ hyperLink: AD.HyperLink.HyperLink,
109
+ style: AD.TextStyle.TextStyle
110
+ ): DOCXJS.InternalHyperlink | DOCXJS.ExternalHyperlink {
111
+ const fontSize = AD.TextStyle.calculateFontSize(style, 10) * 2;
112
+ const textRun = new DOCXJS.TextRun({
113
+ text: hyperLink.text,
114
+ font: "Arial",
115
+ size: fontSize,
116
+ color: style.color || "blue",
117
+ bold: style.bold,
118
+ underline: style.underline
119
+ ? {
120
+ color: style.color || "blue",
121
+ type: DOCXJS.UnderlineType.SINGLE,
122
+ }
123
+ : undefined,
124
+ });
125
+
126
+ if (hyperLink.target.startsWith("#") && !hyperLink.target.startsWith("#page=")) {
127
+ return new DOCXJS.InternalHyperlink({
128
+ anchor: hyperLink.target,
129
+ child: textRun,
130
+ });
131
+ } else {
132
+ return new DOCXJS.ExternalHyperlink({
133
+ link: hyperLink.target,
134
+ child: textRun,
135
+ });
136
+ }
137
+ }
138
+
139
+ function renderSectionElement(
140
+ element: AD.SectionElement.SectionElement,
141
+ parentResources: AD.Resources.Resources
142
+ ): ReadonlyArray<DOCXJS.Paragraph | DOCXJS.Table> /*| DOCXJS.TableOfContents | DOCXJS.HyperlinkRef */ {
143
+ const resources = AD.Resources.mergeResources([parentResources, element]);
144
+ switch (element.type) {
145
+ case "Paragraph":
146
+ return [renderParagraph(element, resources)];
147
+ case "Group":
148
+ return [...renderGroup(element, parentResources)];
149
+ case "Table":
150
+ return [
151
+ renderTable(element, resources),
152
+ new DOCXJS.Paragraph({ children: [new DOCXJS.TextRun({ text: ".", size: 0.000001 })] }),
153
+ ];
154
+ case "PageBreak":
155
+ return [
156
+ new DOCXJS.Paragraph({
157
+ pageBreakBefore: true,
158
+ }),
159
+ ];
160
+ default:
161
+ return [new DOCXJS.Paragraph({})];
162
+ }
163
+ }
164
+
165
+ function renderTable(table: AD.Table.Table, resources: AD.Resources.Resources): DOCXJS.Table {
166
+ const style = AD.Resources.getStyle(
167
+ undefined,
168
+ table.style,
169
+ "TableStyle",
170
+ table.styleName,
171
+ resources
172
+ ) as AD.TableStyle.TableStyle;
173
+
174
+ const fullWidth = table.columnWidths.some((c) => !Number.isFinite(c));
175
+ const columnWidths = table.columnWidths.map((c) => c * abstractDocPixelToDocxDXARatio);
176
+ return new DOCXJS.Table({
177
+ alignment:
178
+ style.alignment === "Left"
179
+ ? DOCXJS.AlignmentType.LEFT
180
+ : style.alignment === "Right"
181
+ ? DOCXJS.AlignmentType.RIGHT
182
+ : DOCXJS.AlignmentType.CENTER,
183
+ margins: {
184
+ top: style.margins.top * abstractDocPixelToDocxDXARatio,
185
+ bottom: style.margins.bottom * abstractDocPixelToDocxDXARatio,
186
+ left: style.margins.left * abstractDocPixelToDocxDXARatio,
187
+ right: style.margins.right * abstractDocPixelToDocxDXARatio,
188
+ },
189
+ width: fullWidth
190
+ ? {
191
+ size: 100,
192
+ type: DOCXJS.WidthType.PERCENTAGE,
193
+ }
194
+ : {
195
+ type: DOCXJS.WidthType.DXA,
196
+ size: columnWidths.reduce((a, b) => a + b),
197
+ },
198
+ borders: {
199
+ top: {
200
+ color: style.cellStyle.borderColor ?? "",
201
+ size: 0,
202
+ style: DOCXJS.BorderStyle.NONE,
203
+ },
204
+ right: {
205
+ color: style.cellStyle.borderColor ?? "",
206
+ size: 0,
207
+ style: DOCXJS.BorderStyle.NONE,
208
+ },
209
+ bottom: {
210
+ color: style.cellStyle.borderColor ?? "",
211
+ size: 0,
212
+ style: DOCXJS.BorderStyle.NONE,
213
+ },
214
+ left: {
215
+ color: style.cellStyle.borderColor ?? "",
216
+ size: 0,
217
+ style: DOCXJS.BorderStyle.NONE,
218
+ },
219
+ insideHorizontal: {
220
+ color: style.cellStyle.borderColor ?? "",
221
+ size: 0,
222
+ style: DOCXJS.BorderStyle.NONE,
223
+ },
224
+ insideVertical: {
225
+ color: style.cellStyle.borderColor ?? "",
226
+ size: 0,
227
+ style: DOCXJS.BorderStyle.NONE,
228
+ },
229
+ },
230
+ rows: table.children.map((c) => renderRow(c, resources, style.cellStyle, columnWidths)),
231
+ });
232
+ }
233
+
234
+ function renderRow(
235
+ row: AD.TableRow.TableRow,
236
+ resources: AD.Resources.Resources,
237
+ tableCellStyle: AD.TableCellStyle.TableCellStyle,
238
+ columnWidths: ReadonlyArray<number>
239
+ ): DOCXJS.TableRow {
240
+ return new DOCXJS.TableRow({
241
+ cantSplit: true,
242
+ children: row.children.map((c, ix) => renderCell(c, resources, tableCellStyle, columnWidths[ix])),
243
+ });
244
+ }
245
+
246
+ function renderCell(
247
+ cell: AD.TableCell.TableCell,
248
+ resources: AD.Resources.Resources,
249
+ tableCellStyle: AD.TableCellStyle.TableCellStyle,
250
+ width: number
251
+ ): DOCXJS.TableCell {
252
+ const style = AD.Resources.getStyle(
253
+ tableCellStyle,
254
+ cell.style,
255
+ "TableCellStyle",
256
+ cell.styleName,
257
+ resources
258
+ ) as AD.TableCellStyle.TableCellStyle;
259
+
260
+ return new DOCXJS.TableCell({
261
+ verticalAlign:
262
+ (style.verticalAlignment && style.verticalAlignment === "Top"
263
+ ? DOCXJS.VerticalAlign.TOP
264
+ : style.verticalAlignment === "Bottom"
265
+ ? DOCXJS.VerticalAlign.BOTTOM
266
+ : DOCXJS.VerticalAlign.CENTER) || undefined,
267
+ shading: {
268
+ fill: style.background ? style.background : undefined,
269
+ },
270
+ columnSpan: cell.columnSpan,
271
+ width: isFinite(width)
272
+ ? {
273
+ type: DOCXJS.WidthType.DXA,
274
+ size: width,
275
+ }
276
+ : {
277
+ type: DOCXJS.WidthType.AUTO,
278
+ size: "",
279
+ },
280
+ margins: {
281
+ top: Math.max(style.padding.top, 0) * abstractDocPixelToDocxDXARatio,
282
+ bottom: Math.max(style.padding.bottom, 0) * abstractDocPixelToDocxDXARatio,
283
+ left: Math.max(style.padding.left, 0) * abstractDocPixelToDocxDXARatio,
284
+ right: Math.max(style.padding.right, 0) * abstractDocPixelToDocxDXARatio,
285
+ },
286
+ borders: {
287
+ top: {
288
+ color: style.borderColor ?? "",
289
+ size: style.borders.top,
290
+ style: style.borders.top ? DOCXJS.BorderStyle.SINGLE : DOCXJS.BorderStyle.NONE,
291
+ },
292
+ right: {
293
+ color: style.borderColor ?? "",
294
+ size: style.borders.right,
295
+ style: style.borders.right ? DOCXJS.BorderStyle.SINGLE : DOCXJS.BorderStyle.NONE,
296
+ },
297
+ bottom: {
298
+ color: style.borderColor ?? "",
299
+ size: style.borders.bottom,
300
+ style: style.borders.bottom ? DOCXJS.BorderStyle.SINGLE : DOCXJS.BorderStyle.NONE,
301
+ },
302
+ left: {
303
+ color: style.borderColor ?? "",
304
+ size: style.borders.left,
305
+ style: style.borders.left ? DOCXJS.BorderStyle.SINGLE : DOCXJS.BorderStyle.NONE,
306
+ },
307
+ },
308
+
309
+ children: cell.children.reduce((sofar, c) => {
310
+ sofar.push(...renderSectionElement(c, resources));
311
+ return sofar;
312
+ }, [] as Array<DOCXJS.Paragraph | DOCXJS.Table>),
313
+ });
314
+ }
315
+
316
+ function renderAtom(
317
+ resources: AD.Resources.Resources,
318
+ textStyle: AD.TextStyle.TextStyle,
319
+ atom: AD.Atom.Atom
320
+ ):
321
+ | DOCXJS.TextRun
322
+ | DOCXJS.ImageRun
323
+ | DOCXJS.SymbolRun
324
+ | DOCXJS.Bookmark
325
+ | DOCXJS.PageBreak
326
+ | DOCXJS.SequentialIdentifier
327
+ | DOCXJS.FootnoteReferenceRun
328
+ | DOCXJS.InsertedTextRun
329
+ | DOCXJS.DeletedTextRun
330
+ | DOCXJS.InternalHyperlink
331
+ | DOCXJS.ExternalHyperlink
332
+ | DOCXJS.Math {
333
+ switch (atom.type) {
334
+ case "TextField":
335
+ return renderTextField(resources, textStyle, atom);
336
+ case "TextRun":
337
+ return renderTextRun(resources, textStyle, atom);
338
+ case "Image":
339
+ return renderImage(atom, textStyle);
340
+ case "HyperLink":
341
+ return renderHyperLink(atom, textStyle);
342
+ default:
343
+ return new DOCXJS.TextRun({ text: "missed" }); // TODO
344
+ }
345
+ }
346
+
347
+ function renderTextField(
348
+ resources: AD.Resources.Resources,
349
+ textStyle: AD.TextStyle.TextStyle,
350
+ textField: AD.TextField.TextField
351
+ ): DOCXJS.TextRun {
352
+ const style = AD.Resources.getStyle(
353
+ textStyle,
354
+ textField.style,
355
+ "TextStyle",
356
+ textField.styleName,
357
+ resources
358
+ ) as AD.TextStyle.TextStyle;
359
+ switch (textField.fieldType) {
360
+ case "Date":
361
+ return renderText(style, new Date(Date.now()).toDateString());
362
+ case "PageNumber":
363
+ return renderPageNumber(style);
364
+ case "TotalPages":
365
+ return renderTotalPages(style);
366
+ default:
367
+ return renderText(style, "");
368
+ }
369
+ }
370
+
371
+ function renderTextRun(
372
+ resources: AD.Resources.Resources,
373
+ textStyle: AD.TextStyle.TextStyle,
374
+ textRun: AD.TextRun.TextRun
375
+ ): DOCXJS.TextRun {
376
+ const style = AD.Resources.getNestedStyle(
377
+ textStyle,
378
+ textRun.style,
379
+ "TextStyle",
380
+ textRun.styleName,
381
+ resources,
382
+ textRun.nestedStyleNames || []
383
+ ) as AD.TextStyle.TextStyle;
384
+
385
+ return renderText(style, textRun.text);
386
+ }
387
+
388
+ function renderPageNumber(style: AD.TextStyle.TextStyle): DOCXJS.TextRun {
389
+ const fontSize = AD.TextStyle.calculateFontSize(style, 10) * abstractDocToDocxFontRatio;
390
+ return new DOCXJS.TextRun({
391
+ font: "Arial",
392
+ size: fontSize,
393
+ color: style.color || "black",
394
+ bold: style.bold,
395
+ underline: style.underline
396
+ ? {
397
+ color: style.color,
398
+ type: DOCXJS.UnderlineType.SINGLE,
399
+ }
400
+ : undefined,
401
+ children: [DOCXJS.PageNumber.CURRENT],
402
+ });
403
+ }
404
+
405
+ function renderTotalPages(style: AD.TextStyle.TextStyle): DOCXJS.TextRun {
406
+ const fontSize = AD.TextStyle.calculateFontSize(style, 10) * abstractDocToDocxFontRatio;
407
+ return new DOCXJS.TextRun({
408
+ font: "Arial",
409
+ size: fontSize,
410
+ color: style.color || "black",
411
+ bold: style.bold,
412
+ underline: style.underline
413
+ ? {
414
+ color: style.color,
415
+ type: DOCXJS.UnderlineType.SINGLE,
416
+ }
417
+ : undefined,
418
+ children: [DOCXJS.PageNumber.TOTAL_PAGES],
419
+ });
420
+ }
421
+
422
+ function renderText(style: AD.TextStyle.TextStyle, text: string): DOCXJS.TextRun {
423
+ const fontSize = AD.TextStyle.calculateFontSize(style, 10) * abstractDocToDocxFontRatio;
424
+
425
+ return new DOCXJS.TextRun({
426
+ text: text,
427
+ font: "Arial",
428
+ size: fontSize,
429
+ color: style.color || "black",
430
+ bold: style.bold,
431
+ underline: style.underline
432
+ ? {
433
+ color: style.color,
434
+ type: DOCXJS.UnderlineType.SINGLE,
435
+ }
436
+ : undefined,
437
+ });
438
+ }
439
+
440
+ function renderGroup(group: AD.Group.Group, resources: AD.Resources.Resources): Array<DOCXJS.Paragraph | DOCXJS.Table> {
441
+ return group.children.reduce((sofar, c) => {
442
+ sofar.push(...renderSectionElement(c, resources));
443
+ return sofar;
444
+ }, [] as Array<DOCXJS.Paragraph | DOCXJS.Table>);
445
+ }
446
+
447
+ function renderParagraph(paragraph: AD.Paragraph.Paragraph, resources: AD.Resources.Resources): DOCXJS.Paragraph {
448
+ const style = AD.Resources.getStyle(
449
+ undefined,
450
+ paragraph.style,
451
+ "ParagraphStyle",
452
+ paragraph.styleName,
453
+ resources
454
+ ) as AD.ParagraphStyle.ParagraphStyle;
455
+
456
+ return new DOCXJS.Paragraph({
457
+ alignment:
458
+ (style.alignment &&
459
+ (style.alignment === "Center"
460
+ ? DOCXJS.AlignmentType.CENTER
461
+ : style.alignment === "End"
462
+ ? DOCXJS.AlignmentType.END
463
+ : DOCXJS.AlignmentType.START)) ||
464
+ undefined,
465
+
466
+ spacing: {
467
+ before: Math.max(style.margins.top, 0) * abstractDocPixelToDocxDXARatio,
468
+ after: Math.max(style.margins.bottom, 0) * abstractDocPixelToDocxDXARatio,
469
+ },
470
+ indent: {
471
+ left: Math.max(style.margins.left, 0) * abstractDocPixelToDocxDXARatio,
472
+ right: Math.max(style.margins.right, 0) * abstractDocPixelToDocxDXARatio,
473
+ },
474
+ children: paragraph.children.map((atom) => renderAtom(resources, style.textStyle, atom)),
475
+ });
476
+ }