abstract-document 6.8.1 → 6.8.2

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