ooxml-core 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (586) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +3 -0
  3. package/README.md +125 -0
  4. package/THIRD-PARTY-LICENSES +26 -0
  5. package/dist/collab/assets.d.ts +42 -0
  6. package/dist/collab/assets.d.ts.map +1 -0
  7. package/dist/collab/awareness.d.ts +65 -0
  8. package/dist/collab/awareness.d.ts.map +1 -0
  9. package/dist/collab/binding.d.ts +36 -0
  10. package/dist/collab/binding.d.ts.map +1 -0
  11. package/dist/collab/codec.d.ts +37 -0
  12. package/dist/collab/codec.d.ts.map +1 -0
  13. package/dist/collab/emitter.d.ts +11 -0
  14. package/dist/collab/emitter.d.ts.map +1 -0
  15. package/dist/collab/external-provider.d.ts +50 -0
  16. package/dist/collab/external-provider.d.ts.map +1 -0
  17. package/dist/collab/identity.d.ts +48 -0
  18. package/dist/collab/identity.d.ts.map +1 -0
  19. package/dist/collab/index.cjs +1328 -0
  20. package/dist/collab/index.d.ts +18 -0
  21. package/dist/collab/index.d.ts.map +1 -0
  22. package/dist/collab/index.mjs +1225 -0
  23. package/dist/collab/lifecycle.d.ts +62 -0
  24. package/dist/collab/lifecycle.d.ts.map +1 -0
  25. package/dist/collab/memory-transport.d.ts +19 -0
  26. package/dist/collab/memory-transport.d.ts.map +1 -0
  27. package/dist/collab/ordering.d.ts +53 -0
  28. package/dist/collab/ordering.d.ts.map +1 -0
  29. package/dist/collab/policy.d.ts +39 -0
  30. package/dist/collab/policy.d.ts.map +1 -0
  31. package/dist/collab/presence.d.ts +61 -0
  32. package/dist/collab/presence.d.ts.map +1 -0
  33. package/dist/collab/provider.d.ts +55 -0
  34. package/dist/collab/provider.d.ts.map +1 -0
  35. package/dist/collab/session.d.ts +70 -0
  36. package/dist/collab/session.d.ts.map +1 -0
  37. package/dist/collab/transport-provider.d.ts +13 -0
  38. package/dist/collab/transport-provider.d.ts.map +1 -0
  39. package/dist/collab/validation.d.ts +38 -0
  40. package/dist/collab/validation.d.ts.map +1 -0
  41. package/dist/collab/websocket-transport.d.ts +33 -0
  42. package/dist/collab/websocket-transport.d.ts.map +1 -0
  43. package/dist/color/color-linear.d.ts +5 -0
  44. package/dist/color/color-linear.d.ts.map +1 -0
  45. package/dist/color/color-primitives.d.ts +183 -0
  46. package/dist/color/color-primitives.d.ts.map +1 -0
  47. package/dist/color/index.cjs +177 -0
  48. package/dist/color/index.d.ts +3 -0
  49. package/dist/color/index.d.ts.map +1 -0
  50. package/dist/color/index.mjs +161 -0
  51. package/dist/diagram/attributes.d.ts +12 -0
  52. package/dist/diagram/attributes.d.ts.map +1 -0
  53. package/dist/diagram/data-model.d.ts +18 -0
  54. package/dist/diagram/data-model.d.ts.map +1 -0
  55. package/dist/diagram/definitions.d.ts +14 -0
  56. package/dist/diagram/definitions.d.ts.map +1 -0
  57. package/dist/diagram/dom.d.ts +15 -0
  58. package/dist/diagram/dom.d.ts.map +1 -0
  59. package/dist/diagram/drawing-color.d.ts +28 -0
  60. package/dist/diagram/drawing-color.d.ts.map +1 -0
  61. package/dist/diagram/drawing-fill.d.ts +9 -0
  62. package/dist/diagram/drawing-fill.d.ts.map +1 -0
  63. package/dist/diagram/drawing-geometry.d.ts +23 -0
  64. package/dist/diagram/drawing-geometry.d.ts.map +1 -0
  65. package/dist/diagram/drawing-text.d.ts +5 -0
  66. package/dist/diagram/drawing-text.d.ts.map +1 -0
  67. package/dist/diagram/drawing.d.ts +7 -0
  68. package/dist/diagram/drawing.d.ts.map +1 -0
  69. package/dist/diagram/index.cjs +1193 -0
  70. package/dist/diagram/index.d.ts +14 -0
  71. package/dist/diagram/index.d.ts.map +1 -0
  72. package/dist/diagram/index.mjs +1161 -0
  73. package/dist/diagram/layout-category.d.ts +8 -0
  74. package/dist/diagram/layout-category.d.ts.map +1 -0
  75. package/dist/diagram/load.d.ts +36 -0
  76. package/dist/diagram/load.d.ts.map +1 -0
  77. package/dist/diagram/relationships.d.ts +35 -0
  78. package/dist/diagram/relationships.d.ts.map +1 -0
  79. package/dist/diagram/types.d.ts +306 -0
  80. package/dist/diagram/types.d.ts.map +1 -0
  81. package/dist/docx/block-parser.d.ts +13 -0
  82. package/dist/docx/block-parser.d.ts.map +1 -0
  83. package/dist/docx/bookmarks.d.ts +18 -0
  84. package/dist/docx/bookmarks.d.ts.map +1 -0
  85. package/dist/docx/breaks.d.ts +11 -0
  86. package/dist/docx/breaks.d.ts.map +1 -0
  87. package/dist/docx/character-styles.d.ts +4 -0
  88. package/dist/docx/character-styles.d.ts.map +1 -0
  89. package/dist/docx/comment-spans.d.ts +19 -0
  90. package/dist/docx/comment-spans.d.ts.map +1 -0
  91. package/dist/docx/comments.d.ts +4 -0
  92. package/dist/docx/comments.d.ts.map +1 -0
  93. package/dist/docx/core-properties.d.ts +18 -0
  94. package/dist/docx/core-properties.d.ts.map +1 -0
  95. package/dist/docx/default-styles.d.ts +8 -0
  96. package/dist/docx/default-styles.d.ts.map +1 -0
  97. package/dist/docx/defined-props.d.ts +9 -0
  98. package/dist/docx/defined-props.d.ts.map +1 -0
  99. package/dist/docx/diagram-document.d.ts +9 -0
  100. package/dist/docx/diagram-document.d.ts.map +1 -0
  101. package/dist/docx/diagram-theme.d.ts +8 -0
  102. package/dist/docx/diagram-theme.d.ts.map +1 -0
  103. package/dist/docx/diagram.d.ts +89 -0
  104. package/dist/docx/diagram.d.ts.map +1 -0
  105. package/dist/docx/docpr-ids.d.ts +14 -0
  106. package/dist/docx/docpr-ids.d.ts.map +1 -0
  107. package/dist/docx/document-parts.d.ts +18 -0
  108. package/dist/docx/document-parts.d.ts.map +1 -0
  109. package/dist/docx/drawing.d.ts +13 -0
  110. package/dist/docx/drawing.d.ts.map +1 -0
  111. package/dist/docx/element-order.d.ts +13 -0
  112. package/dist/docx/element-order.d.ts.map +1 -0
  113. package/dist/docx/embedded.cjs +7646 -0
  114. package/dist/docx/embedded.d.ts +5 -0
  115. package/dist/docx/embedded.d.ts.map +1 -0
  116. package/dist/docx/embedded.mjs +7639 -0
  117. package/dist/docx/expect-defined.d.ts +3 -0
  118. package/dist/docx/expect-defined.d.ts.map +1 -0
  119. package/dist/docx/field-date.d.ts +10 -0
  120. package/dist/docx/field-date.d.ts.map +1 -0
  121. package/dist/docx/field-runs.d.ts +10 -0
  122. package/dist/docx/field-runs.d.ts.map +1 -0
  123. package/dist/docx/generated/wml-simple-types.d.ts +298 -0
  124. package/dist/docx/generated/wml-simple-types.d.ts.map +1 -0
  125. package/dist/docx/heading-list-kinds.d.ts +10 -0
  126. package/dist/docx/heading-list-kinds.d.ts.map +1 -0
  127. package/dist/docx/highlight.d.ts +5 -0
  128. package/dist/docx/highlight.d.ts.map +1 -0
  129. package/dist/docx/hyperlink.d.ts +8 -0
  130. package/dist/docx/hyperlink.d.ts.map +1 -0
  131. package/dist/docx/index.cjs +9784 -0
  132. package/dist/docx/index.d.ts +40 -0
  133. package/dist/docx/index.d.ts.map +1 -0
  134. package/dist/docx/index.mjs +9456 -0
  135. package/dist/docx/inline-model.d.ts +68 -0
  136. package/dist/docx/inline-model.d.ts.map +1 -0
  137. package/dist/docx/language.d.ts +3 -0
  138. package/dist/docx/language.d.ts.map +1 -0
  139. package/dist/docx/layout/adapt-drop-cap.d.ts +10 -0
  140. package/dist/docx/layout/adapt-drop-cap.d.ts.map +1 -0
  141. package/dist/docx/layout/adapt-floats.d.ts +8 -0
  142. package/dist/docx/layout/adapt-floats.d.ts.map +1 -0
  143. package/dist/docx/layout/adapt-notes.d.ts +13 -0
  144. package/dist/docx/layout/adapt-notes.d.ts.map +1 -0
  145. package/dist/docx/layout/adapt-paragraph-box.d.ts +12 -0
  146. package/dist/docx/layout/adapt-paragraph-box.d.ts.map +1 -0
  147. package/dist/docx/layout/adapt-table.d.ts +12 -0
  148. package/dist/docx/layout/adapt-table.d.ts.map +1 -0
  149. package/dist/docx/layout/adapter.d.ts +5 -0
  150. package/dist/docx/layout/adapter.d.ts.map +1 -0
  151. package/dist/docx/layout/floats.d.ts +20 -0
  152. package/dist/docx/layout/floats.d.ts.map +1 -0
  153. package/dist/docx/layout/flow-paragraph.d.ts +26 -0
  154. package/dist/docx/layout/flow-paragraph.d.ts.map +1 -0
  155. package/dist/docx/layout/flow-table.d.ts +12 -0
  156. package/dist/docx/layout/flow-table.d.ts.map +1 -0
  157. package/dist/docx/layout/fonts.d.ts +3 -0
  158. package/dist/docx/layout/fonts.d.ts.map +1 -0
  159. package/dist/docx/layout/index.cjs +2537 -0
  160. package/dist/docx/layout/index.d.ts +20 -0
  161. package/dist/docx/layout/index.d.ts.map +1 -0
  162. package/dist/docx/layout/index.mjs +2503 -0
  163. package/dist/docx/layout/input.d.ts +206 -0
  164. package/dist/docx/layout/input.d.ts.map +1 -0
  165. package/dist/docx/layout/keep-rules.d.ts +24 -0
  166. package/dist/docx/layout/keep-rules.d.ts.map +1 -0
  167. package/dist/docx/layout/layout.d.ts +9 -0
  168. package/dist/docx/layout/layout.d.ts.map +1 -0
  169. package/dist/docx/layout/ligatures.d.ts +4 -0
  170. package/dist/docx/layout/ligatures.d.ts.map +1 -0
  171. package/dist/docx/layout/line-metrics.d.ts +21 -0
  172. package/dist/docx/layout/line-metrics.d.ts.map +1 -0
  173. package/dist/docx/layout/measure.d.ts +34 -0
  174. package/dist/docx/layout/measure.d.ts.map +1 -0
  175. package/dist/docx/layout/page-cursor.d.ts +45 -0
  176. package/dist/docx/layout/page-cursor.d.ts.map +1 -0
  177. package/dist/docx/layout/page-flow.d.ts +7 -0
  178. package/dist/docx/layout/page-flow.d.ts.map +1 -0
  179. package/dist/docx/layout/paragraph-fragments.d.ts +6 -0
  180. package/dist/docx/layout/paragraph-fragments.d.ts.map +1 -0
  181. package/dist/docx/layout/paragraph-layout.d.ts +37 -0
  182. package/dist/docx/layout/paragraph-layout.d.ts.map +1 -0
  183. package/dist/docx/layout/paragraph-tokens.d.ts +27 -0
  184. package/dist/docx/layout/paragraph-tokens.d.ts.map +1 -0
  185. package/dist/docx/layout/result.d.ts +139 -0
  186. package/dist/docx/layout/result.d.ts.map +1 -0
  187. package/dist/docx/layout/tab-stops.d.ts +14 -0
  188. package/dist/docx/layout/tab-stops.d.ts.map +1 -0
  189. package/dist/docx/layout/table-layout.d.ts +30 -0
  190. package/dist/docx/layout/table-layout.d.ts.map +1 -0
  191. package/dist/docx/layout/test-helpers.d.ts +3 -0
  192. package/dist/docx/layout/test-helpers.d.ts.map +1 -0
  193. package/dist/docx/layout/text-breaks.d.ts +56 -0
  194. package/dist/docx/layout/text-breaks.d.ts.map +1 -0
  195. package/dist/docx/layout/units.d.ts +17 -0
  196. package/dist/docx/layout/units.d.ts.map +1 -0
  197. package/dist/docx/layout/wrap.d.ts +22 -0
  198. package/dist/docx/layout/wrap.d.ts.map +1 -0
  199. package/dist/docx/ligatures.d.ts +9 -0
  200. package/dist/docx/ligatures.d.ts.map +1 -0
  201. package/dist/docx/load/detect.d.ts +6 -0
  202. package/dist/docx/load/detect.d.ts.map +1 -0
  203. package/dist/docx/load/index.cjs +8869 -0
  204. package/dist/docx/load/index.d.ts +3 -0
  205. package/dist/docx/load/index.d.ts.map +1 -0
  206. package/dist/docx/load/index.mjs +8860 -0
  207. package/dist/docx/load/legacy-doc.d.ts +7 -0
  208. package/dist/docx/load/legacy-doc.d.ts.map +1 -0
  209. package/dist/docx/model-paragraph.d.ts +100 -0
  210. package/dist/docx/model-paragraph.d.ts.map +1 -0
  211. package/dist/docx/model-run.d.ts +110 -0
  212. package/dist/docx/model-run.d.ts.map +1 -0
  213. package/dist/docx/model.d.ts +114 -0
  214. package/dist/docx/model.d.ts.map +1 -0
  215. package/dist/docx/notes.d.ts +9 -0
  216. package/dist/docx/notes.d.ts.map +1 -0
  217. package/dist/docx/numbering-editing.d.ts +30 -0
  218. package/dist/docx/numbering-editing.d.ts.map +1 -0
  219. package/dist/docx/numbering-format.d.ts +17 -0
  220. package/dist/docx/numbering-format.d.ts.map +1 -0
  221. package/dist/docx/numbering-model.d.ts +73 -0
  222. package/dist/docx/numbering-model.d.ts.map +1 -0
  223. package/dist/docx/numbering-package.d.ts +12 -0
  224. package/dist/docx/numbering-package.d.ts.map +1 -0
  225. package/dist/docx/numbering-parse.d.ts +8 -0
  226. package/dist/docx/numbering-parse.d.ts.map +1 -0
  227. package/dist/docx/numbering-parts.d.ts +4 -0
  228. package/dist/docx/numbering-parts.d.ts.map +1 -0
  229. package/dist/docx/numbering-text.d.ts +20 -0
  230. package/dist/docx/numbering-text.d.ts.map +1 -0
  231. package/dist/docx/numbering-write.d.ts +5 -0
  232. package/dist/docx/numbering-write.d.ts.map +1 -0
  233. package/dist/docx/package-parts.d.ts +4 -0
  234. package/dist/docx/package-parts.d.ts.map +1 -0
  235. package/dist/docx/page-background.d.ts +9 -0
  236. package/dist/docx/page-background.d.ts.map +1 -0
  237. package/dist/docx/page-borders.d.ts +9 -0
  238. package/dist/docx/page-borders.d.ts.map +1 -0
  239. package/dist/docx/paragraph-alignment.d.ts +21 -0
  240. package/dist/docx/paragraph-alignment.d.ts.map +1 -0
  241. package/dist/docx/paragraph-styles.d.ts +15 -0
  242. package/dist/docx/paragraph-styles.d.ts.map +1 -0
  243. package/dist/docx/parse-diagnostics.d.ts +10 -0
  244. package/dist/docx/parse-diagnostics.d.ts.map +1 -0
  245. package/dist/docx/parse-revisions.d.ts +36 -0
  246. package/dist/docx/parse-revisions.d.ts.map +1 -0
  247. package/dist/docx/parse-table.d.ts +5 -0
  248. package/dist/docx/parse-table.d.ts.map +1 -0
  249. package/dist/docx/parse-warnings.d.ts +9 -0
  250. package/dist/docx/parse-warnings.d.ts.map +1 -0
  251. package/dist/docx/parse.d.ts +13 -0
  252. package/dist/docx/parse.d.ts.map +1 -0
  253. package/dist/docx/part-relationships.d.ts +12 -0
  254. package/dist/docx/part-relationships.d.ts.map +1 -0
  255. package/dist/docx/relationship-allocator.d.ts +32 -0
  256. package/dist/docx/relationship-allocator.d.ts.map +1 -0
  257. package/dist/docx/relationships.d.ts +3 -0
  258. package/dist/docx/relationships.d.ts.map +1 -0
  259. package/dist/docx/resolve-table.d.ts +8 -0
  260. package/dist/docx/resolve-table.d.ts.map +1 -0
  261. package/dist/docx/revision-commands.d.ts +27 -0
  262. package/dist/docx/revision-commands.d.ts.map +1 -0
  263. package/dist/docx/revision-ids.d.ts +10 -0
  264. package/dist/docx/revision-ids.d.ts.map +1 -0
  265. package/dist/docx/run-formatting.d.ts +16 -0
  266. package/dist/docx/run-formatting.d.ts.map +1 -0
  267. package/dist/docx/run-properties.d.ts +5 -0
  268. package/dist/docx/run-properties.d.ts.map +1 -0
  269. package/dist/docx/run-style-model.d.ts +21 -0
  270. package/dist/docx/run-style-model.d.ts.map +1 -0
  271. package/dist/docx/save.d.ts +5 -0
  272. package/dist/docx/save.d.ts.map +1 -0
  273. package/dist/docx/section-model.d.ts +97 -0
  274. package/dist/docx/section-model.d.ts.map +1 -0
  275. package/dist/docx/sections.d.ts +18 -0
  276. package/dist/docx/sections.d.ts.map +1 -0
  277. package/dist/docx/settings.d.ts +11 -0
  278. package/dist/docx/settings.d.ts.map +1 -0
  279. package/dist/docx/simple-types.d.ts +37 -0
  280. package/dist/docx/simple-types.d.ts.map +1 -0
  281. package/dist/docx/style-numbering-package.d.ts +11 -0
  282. package/dist/docx/style-numbering-package.d.ts.map +1 -0
  283. package/dist/docx/tab-stops.d.ts +8 -0
  284. package/dist/docx/tab-stops.d.ts.map +1 -0
  285. package/dist/docx/table-borders.d.ts +15 -0
  286. package/dist/docx/table-borders.d.ts.map +1 -0
  287. package/dist/docx/table-cell-write.d.ts +12 -0
  288. package/dist/docx/table-cell-write.d.ts.map +1 -0
  289. package/dist/docx/table-defaults.d.ts +20 -0
  290. package/dist/docx/table-defaults.d.ts.map +1 -0
  291. package/dist/docx/table-model.d.ts +101 -0
  292. package/dist/docx/table-model.d.ts.map +1 -0
  293. package/dist/docx/table-of-contents.d.ts +67 -0
  294. package/dist/docx/table-of-contents.d.ts.map +1 -0
  295. package/dist/docx/table-of-figures.d.ts +10 -0
  296. package/dist/docx/table-of-figures.d.ts.map +1 -0
  297. package/dist/docx/table-styles.d.ts +4 -0
  298. package/dist/docx/table-styles.d.ts.map +1 -0
  299. package/dist/docx/table-visuals.d.ts +22 -0
  300. package/dist/docx/table-visuals.d.ts.map +1 -0
  301. package/dist/docx/test-support/access.d.ts +14 -0
  302. package/dist/docx/test-support/access.d.ts.map +1 -0
  303. package/dist/docx/test-support/heading-numbering-fixture.d.ts +5 -0
  304. package/dist/docx/test-support/heading-numbering-fixture.d.ts.map +1 -0
  305. package/dist/docx/test-support/restart-fixture.d.ts +17 -0
  306. package/dist/docx/test-support/restart-fixture.d.ts.map +1 -0
  307. package/dist/docx/test-support/schema-validation.d.ts +24 -0
  308. package/dist/docx/test-support/schema-validation.d.ts.map +1 -0
  309. package/dist/docx/theme-color.d.ts +16 -0
  310. package/dist/docx/theme-color.d.ts.map +1 -0
  311. package/dist/docx/theme-model.d.ts +31 -0
  312. package/dist/docx/theme-model.d.ts.map +1 -0
  313. package/dist/docx/theme.d.ts +6 -0
  314. package/dist/docx/theme.d.ts.map +1 -0
  315. package/dist/docx/underline.d.ts +5 -0
  316. package/dist/docx/underline.d.ts.map +1 -0
  317. package/dist/docx/units.d.ts +2 -0
  318. package/dist/docx/units.d.ts.map +1 -0
  319. package/dist/docx/validate-issues.d.ts +40 -0
  320. package/dist/docx/validate-issues.d.ts.map +1 -0
  321. package/dist/docx/validate-model.d.ts +8 -0
  322. package/dist/docx/validate-model.d.ts.map +1 -0
  323. package/dist/docx/validate-paragraph.d.ts +10 -0
  324. package/dist/docx/validate-paragraph.d.ts.map +1 -0
  325. package/dist/docx/validate-structure.d.ts +10 -0
  326. package/dist/docx/validate-structure.d.ts.map +1 -0
  327. package/dist/docx/watermark.d.ts +14 -0
  328. package/dist/docx/watermark.d.ts.map +1 -0
  329. package/dist/docx/write-comments.d.ts +12 -0
  330. package/dist/docx/write-comments.d.ts.map +1 -0
  331. package/dist/docx/write-drawing.d.ts +12 -0
  332. package/dist/docx/write-drawing.d.ts.map +1 -0
  333. package/dist/docx/write-header-footer.d.ts +21 -0
  334. package/dist/docx/write-header-footer.d.ts.map +1 -0
  335. package/dist/docx/write-inline.d.ts +23 -0
  336. package/dist/docx/write-inline.d.ts.map +1 -0
  337. package/dist/docx/write-notes.d.ts +5 -0
  338. package/dist/docx/write-notes.d.ts.map +1 -0
  339. package/dist/docx/write-paragraph-decoration.d.ts +5 -0
  340. package/dist/docx/write-paragraph-decoration.d.ts.map +1 -0
  341. package/dist/docx/write-paragraph-properties.d.ts +4 -0
  342. package/dist/docx/write-paragraph-properties.d.ts.map +1 -0
  343. package/dist/docx/write-paragraph.d.ts +8 -0
  344. package/dist/docx/write-paragraph.d.ts.map +1 -0
  345. package/dist/docx/write-ranges.d.ts +42 -0
  346. package/dist/docx/write-ranges.d.ts.map +1 -0
  347. package/dist/docx/write-revisions.d.ts +10 -0
  348. package/dist/docx/write-revisions.d.ts.map +1 -0
  349. package/dist/docx/write-run-extra.d.ts +5 -0
  350. package/dist/docx/write-run-extra.d.ts.map +1 -0
  351. package/dist/docx/write-run-validation.d.ts +4 -0
  352. package/dist/docx/write-run-validation.d.ts.map +1 -0
  353. package/dist/docx/write-run.d.ts +7 -0
  354. package/dist/docx/write-run.d.ts.map +1 -0
  355. package/dist/docx/write-sections.d.ts +10 -0
  356. package/dist/docx/write-sections.d.ts.map +1 -0
  357. package/dist/docx/write-table-properties.d.ts +13 -0
  358. package/dist/docx/write-table-properties.d.ts.map +1 -0
  359. package/dist/docx/write-table.d.ts +9 -0
  360. package/dist/docx/write-table.d.ts.map +1 -0
  361. package/dist/docx/write-text-box.d.ts +15 -0
  362. package/dist/docx/write-text-box.d.ts.map +1 -0
  363. package/dist/docx/write.d.ts +25 -0
  364. package/dist/docx/write.d.ts.map +1 -0
  365. package/dist/docx/xml.d.ts +14 -0
  366. package/dist/docx/xml.d.ts.map +1 -0
  367. package/dist/docx/zip-parts.d.ts +5 -0
  368. package/dist/docx/zip-parts.d.ts.map +1 -0
  369. package/dist/geometry/adjustment-aware-shapes.d.ts +63 -0
  370. package/dist/geometry/adjustment-aware-shapes.d.ts.map +1 -0
  371. package/dist/geometry/callout-geometry.d.ts +65 -0
  372. package/dist/geometry/callout-geometry.d.ts.map +1 -0
  373. package/dist/geometry/cloud-bezier-paths.d.ts +55 -0
  374. package/dist/geometry/cloud-bezier-paths.d.ts.map +1 -0
  375. package/dist/geometry/com-avlst-ground-truth.d.ts +48 -0
  376. package/dist/geometry/com-avlst-ground-truth.d.ts.map +1 -0
  377. package/dist/geometry/connector-elbow-geometry.d.ts +41 -0
  378. package/dist/geometry/connector-elbow-geometry.d.ts.map +1 -0
  379. package/dist/geometry/guide-formula-api.d.ts +55 -0
  380. package/dist/geometry/guide-formula-api.d.ts.map +1 -0
  381. package/dist/geometry/guide-formula-eval.d.ts +85 -0
  382. package/dist/geometry/guide-formula-eval.d.ts.map +1 -0
  383. package/dist/geometry/index.cjs +15031 -0
  384. package/dist/geometry/index.d.ts +80 -0
  385. package/dist/geometry/index.d.ts.map +1 -0
  386. package/dist/geometry/index.mjs +14897 -0
  387. package/dist/geometry/indexed.d.ts +6 -0
  388. package/dist/geometry/indexed.d.ts.map +1 -0
  389. package/dist/geometry/preset-clip-paths-core.d.ts +20 -0
  390. package/dist/geometry/preset-clip-paths-core.d.ts.map +1 -0
  391. package/dist/geometry/preset-clip-paths-extended.d.ts +19 -0
  392. package/dist/geometry/preset-clip-paths-extended.d.ts.map +1 -0
  393. package/dist/geometry/preset-connection-sites-action-buttons.d.ts +14 -0
  394. package/dist/geometry/preset-connection-sites-action-buttons.d.ts.map +1 -0
  395. package/dist/geometry/preset-connection-sites-arrows-curved.d.ts +12 -0
  396. package/dist/geometry/preset-connection-sites-arrows-curved.d.ts.map +1 -0
  397. package/dist/geometry/preset-connection-sites-arrows-misc.d.ts +13 -0
  398. package/dist/geometry/preset-connection-sites-arrows-misc.d.ts.map +1 -0
  399. package/dist/geometry/preset-connection-sites-arrows.d.ts +13 -0
  400. package/dist/geometry/preset-connection-sites-arrows.d.ts.map +1 -0
  401. package/dist/geometry/preset-connection-sites-basic-a.d.ts +12 -0
  402. package/dist/geometry/preset-connection-sites-basic-a.d.ts.map +1 -0
  403. package/dist/geometry/preset-connection-sites-basic-b.d.ts +12 -0
  404. package/dist/geometry/preset-connection-sites-basic-b.d.ts.map +1 -0
  405. package/dist/geometry/preset-connection-sites-braces.d.ts +12 -0
  406. package/dist/geometry/preset-connection-sites-braces.d.ts.map +1 -0
  407. package/dist/geometry/preset-connection-sites-callouts-arrow.d.ts +14 -0
  408. package/dist/geometry/preset-connection-sites-callouts-arrow.d.ts.map +1 -0
  409. package/dist/geometry/preset-connection-sites-callouts-basic.d.ts +12 -0
  410. package/dist/geometry/preset-connection-sites-callouts-basic.d.ts.map +1 -0
  411. package/dist/geometry/preset-connection-sites-circular-arrow.d.ts +14 -0
  412. package/dist/geometry/preset-connection-sites-circular-arrow.d.ts.map +1 -0
  413. package/dist/geometry/preset-connection-sites-flowchart.d.ts +19 -0
  414. package/dist/geometry/preset-connection-sites-flowchart.d.ts.map +1 -0
  415. package/dist/geometry/preset-connection-sites-gear9.d.ts +12 -0
  416. package/dist/geometry/preset-connection-sites-gear9.d.ts.map +1 -0
  417. package/dist/geometry/preset-connection-sites-left-circular-arrow.d.ts +12 -0
  418. package/dist/geometry/preset-connection-sites-left-circular-arrow.d.ts.map +1 -0
  419. package/dist/geometry/preset-connection-sites-left-right-circular-arrow.d.ts +13 -0
  420. package/dist/geometry/preset-connection-sites-left-right-circular-arrow.d.ts.map +1 -0
  421. package/dist/geometry/preset-connection-sites-math.d.ts +12 -0
  422. package/dist/geometry/preset-connection-sites-math.d.ts.map +1 -0
  423. package/dist/geometry/preset-connection-sites-misc.d.ts +14 -0
  424. package/dist/geometry/preset-connection-sites-misc.d.ts.map +1 -0
  425. package/dist/geometry/preset-connection-sites-polygons.d.ts +12 -0
  426. package/dist/geometry/preset-connection-sites-polygons.d.ts.map +1 -0
  427. package/dist/geometry/preset-connection-sites-quads.d.ts +14 -0
  428. package/dist/geometry/preset-connection-sites-quads.d.ts.map +1 -0
  429. package/dist/geometry/preset-connection-sites-rects.d.ts +14 -0
  430. package/dist/geometry/preset-connection-sites-rects.d.ts.map +1 -0
  431. package/dist/geometry/preset-connection-sites-ribbons.d.ts +12 -0
  432. package/dist/geometry/preset-connection-sites-ribbons.d.ts.map +1 -0
  433. package/dist/geometry/preset-connection-sites-stars.d.ts +13 -0
  434. package/dist/geometry/preset-connection-sites-stars.d.ts.map +1 -0
  435. package/dist/geometry/preset-connection-sites-table.d.ts +23 -0
  436. package/dist/geometry/preset-connection-sites-table.d.ts.map +1 -0
  437. package/dist/geometry/preset-connection-sites-tabs.d.ts +11 -0
  438. package/dist/geometry/preset-connection-sites-tabs.d.ts.map +1 -0
  439. package/dist/geometry/preset-connection-sites-types.d.ts +52 -0
  440. package/dist/geometry/preset-connection-sites-types.d.ts.map +1 -0
  441. package/dist/geometry/preset-geometry-names.d.ts +53 -0
  442. package/dist/geometry/preset-geometry-names.d.ts.map +1 -0
  443. package/dist/geometry/preset-shape-clip-paths.d.ts +13 -0
  444. package/dist/geometry/preset-shape-clip-paths.d.ts.map +1 -0
  445. package/dist/geometry/preset-shape-definitions-action-buttons.d.ts +45 -0
  446. package/dist/geometry/preset-shape-definitions-action-buttons.d.ts.map +1 -0
  447. package/dist/geometry/preset-shape-definitions-arrow-callouts.d.ts +55 -0
  448. package/dist/geometry/preset-shape-definitions-arrow-callouts.d.ts.map +1 -0
  449. package/dist/geometry/preset-shape-definitions-arrows-refined.d.ts +45 -0
  450. package/dist/geometry/preset-shape-definitions-arrows-refined.d.ts.map +1 -0
  451. package/dist/geometry/preset-shape-definitions-arrows.d.ts +52 -0
  452. package/dist/geometry/preset-shape-definitions-arrows.d.ts.map +1 -0
  453. package/dist/geometry/preset-shape-definitions-chart-marks.d.ts +23 -0
  454. package/dist/geometry/preset-shape-definitions-chart-marks.d.ts.map +1 -0
  455. package/dist/geometry/preset-shape-definitions-cloud-callout.d.ts +28 -0
  456. package/dist/geometry/preset-shape-definitions-cloud-callout.d.ts.map +1 -0
  457. package/dist/geometry/preset-shape-definitions-connectors-brackets.d.ts +37 -0
  458. package/dist/geometry/preset-shape-definitions-connectors-brackets.d.ts.map +1 -0
  459. package/dist/geometry/preset-shape-definitions-curved-arrows-connectors.d.ts +43 -0
  460. package/dist/geometry/preset-shape-definitions-curved-arrows-connectors.d.ts.map +1 -0
  461. package/dist/geometry/preset-shape-definitions-curved-arrows-exact.d.ts +30 -0
  462. package/dist/geometry/preset-shape-definitions-curved-arrows-exact.d.ts.map +1 -0
  463. package/dist/geometry/preset-shape-definitions-flowchart.d.ts +29 -0
  464. package/dist/geometry/preset-shape-definitions-flowchart.d.ts.map +1 -0
  465. package/dist/geometry/preset-shape-definitions-gear6.d.ts +38 -0
  466. package/dist/geometry/preset-shape-definitions-gear6.d.ts.map +1 -0
  467. package/dist/geometry/preset-shape-definitions-gear9.d.ts +24 -0
  468. package/dist/geometry/preset-shape-definitions-gear9.d.ts.map +1 -0
  469. package/dist/geometry/preset-shape-definitions-misc.d.ts +38 -0
  470. package/dist/geometry/preset-shape-definitions-misc.d.ts.map +1 -0
  471. package/dist/geometry/preset-shape-definitions-rects-snips.d.ts +28 -0
  472. package/dist/geometry/preset-shape-definitions-rects-snips.d.ts.map +1 -0
  473. package/dist/geometry/preset-shape-definitions-scrolls-accent-callouts.d.ts +45 -0
  474. package/dist/geometry/preset-shape-definitions-scrolls-accent-callouts.d.ts.map +1 -0
  475. package/dist/geometry/preset-shape-definitions-table.d.ts +121 -0
  476. package/dist/geometry/preset-shape-definitions-table.d.ts.map +1 -0
  477. package/dist/geometry/preset-shape-definitions-tabs-decorations.d.ts +48 -0
  478. package/dist/geometry/preset-shape-definitions-tabs-decorations.d.ts.map +1 -0
  479. package/dist/geometry/preset-shape-definitions.d.ts +28 -0
  480. package/dist/geometry/preset-shape-definitions.d.ts.map +1 -0
  481. package/dist/geometry/preset-shape-paths.d.ts +13 -0
  482. package/dist/geometry/preset-shape-paths.d.ts.map +1 -0
  483. package/dist/geometry/preset-shape-types.d.ts +33 -0
  484. package/dist/geometry/preset-shape-types.d.ts.map +1 -0
  485. package/dist/geometry/preset-text-rect-action-buttons.d.ts +13 -0
  486. package/dist/geometry/preset-text-rect-action-buttons.d.ts.map +1 -0
  487. package/dist/geometry/preset-text-rect-arrows.d.ts +3 -0
  488. package/dist/geometry/preset-text-rect-arrows.d.ts.map +1 -0
  489. package/dist/geometry/preset-text-rect-braces.d.ts +3 -0
  490. package/dist/geometry/preset-text-rect-braces.d.ts.map +1 -0
  491. package/dist/geometry/preset-text-rect-callouts.d.ts +3 -0
  492. package/dist/geometry/preset-text-rect-callouts.d.ts.map +1 -0
  493. package/dist/geometry/preset-text-rect-circular-arrows.d.ts +3 -0
  494. package/dist/geometry/preset-text-rect-circular-arrows.d.ts.map +1 -0
  495. package/dist/geometry/preset-text-rect-flowchart.d.ts +3 -0
  496. package/dist/geometry/preset-text-rect-flowchart.d.ts.map +1 -0
  497. package/dist/geometry/preset-text-rect-misc-a.d.ts +3 -0
  498. package/dist/geometry/preset-text-rect-misc-a.d.ts.map +1 -0
  499. package/dist/geometry/preset-text-rect-misc-b.d.ts +3 -0
  500. package/dist/geometry/preset-text-rect-misc-b.d.ts.map +1 -0
  501. package/dist/geometry/preset-text-rect-polygons.d.ts +3 -0
  502. package/dist/geometry/preset-text-rect-polygons.d.ts.map +1 -0
  503. package/dist/geometry/preset-text-rect-quads.d.ts +3 -0
  504. package/dist/geometry/preset-text-rect-quads.d.ts.map +1 -0
  505. package/dist/geometry/preset-text-rect-ribbons.d.ts +3 -0
  506. package/dist/geometry/preset-text-rect-ribbons.d.ts.map +1 -0
  507. package/dist/geometry/preset-text-rect-stars.d.ts +3 -0
  508. package/dist/geometry/preset-text-rect-stars.d.ts.map +1 -0
  509. package/dist/geometry/preset-text-rect-table.d.ts +20 -0
  510. package/dist/geometry/preset-text-rect-table.d.ts.map +1 -0
  511. package/dist/geometry/preset-text-rect-tabs.d.ts +3 -0
  512. package/dist/geometry/preset-text-rect-tabs.d.ts.map +1 -0
  513. package/dist/geometry/preset-text-rect-types.d.ts +46 -0
  514. package/dist/geometry/preset-text-rect-types.d.ts.map +1 -0
  515. package/dist/geometry/shape-boolean-clipping.d.ts +70 -0
  516. package/dist/geometry/shape-boolean-clipping.d.ts.map +1 -0
  517. package/dist/geometry/shape-boolean-ops.d.ts +142 -0
  518. package/dist/geometry/shape-boolean-ops.d.ts.map +1 -0
  519. package/dist/geometry/shape-boolean-svg.d.ts +31 -0
  520. package/dist/geometry/shape-boolean-svg.d.ts.map +1 -0
  521. package/dist/geometry/shape-boolean-types.d.ts +91 -0
  522. package/dist/geometry/shape-boolean-types.d.ts.map +1 -0
  523. package/dist/geometry/shape-boolean-union.d.ts +79 -0
  524. package/dist/geometry/shape-boolean-union.d.ts.map +1 -0
  525. package/dist/geometry/shape-boolean.d.ts +22 -0
  526. package/dist/geometry/shape-boolean.d.ts.map +1 -0
  527. package/dist/geometry/shape-definitions-extended.d.ts +18 -0
  528. package/dist/geometry/shape-definitions-extended.d.ts.map +1 -0
  529. package/dist/geometry/shape-definitions-primary.d.ts +19 -0
  530. package/dist/geometry/shape-definitions-primary.d.ts.map +1 -0
  531. package/dist/index.cjs +16618 -0
  532. package/dist/index.d.ts +7 -0
  533. package/dist/index.d.ts.map +1 -0
  534. package/dist/index.mjs +16611 -0
  535. package/dist/opc/content-types.d.ts +14 -0
  536. package/dist/opc/content-types.d.ts.map +1 -0
  537. package/dist/opc/index.cjs +228 -0
  538. package/dist/opc/index.d.ts +6 -0
  539. package/dist/opc/index.d.ts.map +1 -0
  540. package/dist/opc/index.mjs +212 -0
  541. package/dist/opc/package.d.ts +14 -0
  542. package/dist/opc/package.d.ts.map +1 -0
  543. package/dist/opc/relationship-types.d.ts +34 -0
  544. package/dist/opc/relationship-types.d.ts.map +1 -0
  545. package/dist/opc/relationships.d.ts +29 -0
  546. package/dist/opc/relationships.d.ts.map +1 -0
  547. package/dist/opc/safe-href.d.ts +3 -0
  548. package/dist/opc/safe-href.d.ts.map +1 -0
  549. package/dist/pptx/chunks/index-CojJtI77.d.ts +9627 -0
  550. package/dist/pptx/chunks/index-CojJtI77.d.ts.map +1 -0
  551. package/dist/pptx/chunks/signature-inspection-status-Bh2oap7B.d.ts +220 -0
  552. package/dist/pptx/chunks/signature-inspection-status-Bh2oap7B.d.ts.map +1 -0
  553. package/dist/pptx/chunks/text-operations-IlJiffp7.d.ts +11122 -0
  554. package/dist/pptx/chunks/text-operations-IlJiffp7.d.ts.map +1 -0
  555. package/dist/pptx/cli/index.cjs +138457 -0
  556. package/dist/pptx/cli/index.d.ts +139 -0
  557. package/dist/pptx/cli/index.d.ts.map +1 -0
  558. package/dist/pptx/cli/index.mjs +138424 -0
  559. package/dist/pptx/converter/index.cjs +32084 -0
  560. package/dist/pptx/converter/index.d.ts +2 -0
  561. package/dist/pptx/converter/index.mjs +32060 -0
  562. package/dist/pptx/index.cjs +172307 -0
  563. package/dist/pptx/index.d.ts +9692 -0
  564. package/dist/pptx/index.d.ts.map +1 -0
  565. package/dist/pptx/index.mjs +171623 -0
  566. package/dist/pptx/signature-node/index.cjs +1299 -0
  567. package/dist/pptx/signature-node/index.d.ts +172 -0
  568. package/dist/pptx/signature-node/index.d.ts.map +1 -0
  569. package/dist/pptx/signature-node/index.mjs +1236 -0
  570. package/dist/units/constants.d.ts +13 -0
  571. package/dist/units/constants.d.ts.map +1 -0
  572. package/dist/units/index.cjs +76 -0
  573. package/dist/units/index.d.ts +3 -0
  574. package/dist/units/index.d.ts.map +1 -0
  575. package/dist/units/index.mjs +45 -0
  576. package/dist/units/units.d.ts +52 -0
  577. package/dist/units/units.d.ts.map +1 -0
  578. package/dist/xml/index.cjs +98 -0
  579. package/dist/xml/index.d.ts +3 -0
  580. package/dist/xml/index.d.ts.map +1 -0
  581. package/dist/xml/index.mjs +85 -0
  582. package/dist/xml/namespaces.d.ts +47 -0
  583. package/dist/xml/namespaces.d.ts.map +1 -0
  584. package/dist/xml/xml.d.ts +31 -0
  585. package/dist/xml/xml.d.ts.map +1 -0
  586. package/package.json +192 -0
@@ -0,0 +1,2537 @@
1
+ 'use strict';
2
+
3
+ // src/units/units.ts
4
+ function integer(unit, value, allowNegative = true) {
5
+ if (!Number.isSafeInteger(value)) throw new RangeError(`${unit} must be a safe integer`);
6
+ if (!allowNegative && value < 0) throw new RangeError(`${unit} must not be negative`);
7
+ return value;
8
+ }
9
+ function finite(unit, value) {
10
+ if (!Number.isFinite(value)) throw new RangeError(`${unit} must be finite`);
11
+ return value;
12
+ }
13
+ var roundAway = (unit, value) => Math.sign(finite(unit, value)) * Math.round(Math.abs(value)) || 0;
14
+ var twips = (value) => integer("twips", value, false);
15
+ var roundSignedTwips = (value) => integer("twips", roundAway("twips", value));
16
+ var twipsToPixels = (value) => value / 15;
17
+
18
+ // src/docx/paragraph-alignment.ts
19
+ function alignFromJustification(jc, rtl) {
20
+ switch (jc) {
21
+ case "left":
22
+ case "center":
23
+ case "right":
24
+ return jc;
25
+ case "start":
26
+ return rtl ? "right" : "left";
27
+ case "end":
28
+ return rtl ? "left" : "right";
29
+ case "both":
30
+ case "distribute":
31
+ case "thaiDistribute":
32
+ case "mediumKashida":
33
+ case "highKashida":
34
+ case "lowKashida":
35
+ return "justify";
36
+ default:
37
+ return void 0;
38
+ }
39
+ }
40
+
41
+ // src/docx/paragraph-styles.ts
42
+ var PAGINATION_KEYS = [
43
+ "keepNext",
44
+ "keepLines",
45
+ "widowControl",
46
+ "contextualSpacing",
47
+ "suppressLineNumbers"
48
+ ];
49
+ function applyStyle(styleId, catalog, out) {
50
+ const chain = [];
51
+ const visited = /* @__PURE__ */ new Set();
52
+ let current = styleId;
53
+ while (current && !visited.has(current)) {
54
+ visited.add(current);
55
+ const style = catalog.styles[current];
56
+ if (!style) break;
57
+ chain.push(style);
58
+ current = style.basedOn;
59
+ }
60
+ for (const style of chain.reverse()) Object.assign(out, style.formatting);
61
+ }
62
+ function resolveParagraphFormatting(paragraph, catalog) {
63
+ const result = { ...catalog.docDefaults };
64
+ const explicitStyle = paragraph.style;
65
+ const defaultStyle = Object.values(catalog.styles).find((style) => style.isDefault)?.id;
66
+ applyStyle(explicitStyle || defaultStyle, catalog, result);
67
+ const direct = {};
68
+ const keys = [
69
+ "align",
70
+ "justification",
71
+ "direction",
72
+ "spacingBeforeTwips",
73
+ "spacingAfterTwips",
74
+ "lineSpacingTwips",
75
+ "lineSpacingRule",
76
+ "indentLeftTwips",
77
+ "indentRightTwips",
78
+ "indentStartTwips",
79
+ "indentEndTwips",
80
+ "firstLineTwips",
81
+ "hangingTwips",
82
+ ...PAGINATION_KEYS,
83
+ "borders",
84
+ "shadingFill"
85
+ ];
86
+ for (const key of keys) {
87
+ const value = paragraph[key];
88
+ if (value !== void 0) Object.assign(direct, { [key]: value });
89
+ }
90
+ Object.assign(result, direct);
91
+ if (paragraph.align !== void 0 && paragraph.justification === void 0)
92
+ delete result.justification;
93
+ if ((result.justification === "start" || result.justification === "end") && result.direction === "rtl" && (paragraph.align === void 0 || paragraph.justification !== void 0) && result.align === alignFromJustification(result.justification, false)) {
94
+ const align = alignFromJustification(result.justification, true);
95
+ if (align === void 0) delete result.align;
96
+ else result.align = align;
97
+ }
98
+ return result;
99
+ }
100
+ function resolveStyleNumbering(styleId, catalog) {
101
+ const chain = [];
102
+ const visited = /* @__PURE__ */ new Set();
103
+ let current = styleId;
104
+ while (current && !visited.has(current)) {
105
+ visited.add(current);
106
+ const style = catalog.styles[current];
107
+ if (!style) break;
108
+ chain.push(style);
109
+ current = style.basedOn;
110
+ }
111
+ return chain.find((style) => style.numbering)?.numbering;
112
+ }
113
+
114
+ // src/docx/resolve-table.ts
115
+ function styleChain(styleId, catalog) {
116
+ if (!styleId || !catalog) return [];
117
+ const chain = [];
118
+ const visited = /* @__PURE__ */ new Set();
119
+ let current = styleId;
120
+ while (current && !visited.has(current)) {
121
+ const style = catalog.styles[current];
122
+ if (!style) break;
123
+ visited.add(current);
124
+ chain.push(style);
125
+ current = style.basedOn;
126
+ }
127
+ return chain.reverse();
128
+ }
129
+ function applicableRegions(look, rowIndex, rowCount, colIndex, colCount) {
130
+ const regions = ["wholeTable"];
131
+ if (!look?.noVBand) regions.push(colIndex % 2 === 0 ? "band1Vert" : "band2Vert");
132
+ if (!look?.noHBand) regions.push(rowIndex % 2 === 0 ? "band1Horz" : "band2Horz");
133
+ if (look?.lastColumn && colIndex === colCount - 1) regions.push("lastCol");
134
+ if (look?.firstColumn && colIndex === 0) regions.push("firstCol");
135
+ if (look?.lastRow && rowIndex === rowCount - 1) regions.push("lastRow");
136
+ if (look?.firstRow && rowIndex === 0) regions.push("firstRow");
137
+ return regions;
138
+ }
139
+ function resolveTableStyleFormatting(tableStyleId, catalog, look, rowIndex, rowCount, colIndex, colCount) {
140
+ const chain = styleChain(tableStyleId, catalog);
141
+ const regions = applicableRegions(look, rowIndex, rowCount, colIndex, colCount);
142
+ const result = {};
143
+ for (const style of chain) {
144
+ if (style.borders) result.borders = { ...result.borders, ...style.borders };
145
+ if (style.shadingFill) result.shadingFill = style.shadingFill;
146
+ for (const region of regions) {
147
+ const formatting = style.conditional[region];
148
+ if (!formatting) continue;
149
+ if (formatting.borders) result.borders = { ...result.borders, ...formatting.borders };
150
+ if (formatting.shadingFill) result.shadingFill = formatting.shadingFill;
151
+ if (formatting.shadingThemeFill) result.shadingThemeFill = formatting.shadingThemeFill;
152
+ if (formatting.run) result.run = { ...result.run, ...formatting.run };
153
+ }
154
+ }
155
+ return result;
156
+ }
157
+
158
+ // src/docx/run-formatting.ts
159
+ var TOGGLE_KEYS = [
160
+ "bold",
161
+ "italic",
162
+ "caps",
163
+ "smallCaps",
164
+ "strike",
165
+ "doubleStrike",
166
+ "vanish"
167
+ ];
168
+ var OVERRIDE_KEYS = [
169
+ "underline",
170
+ "underlineStyle",
171
+ "underlineColor",
172
+ "highlight",
173
+ "verticalAlign",
174
+ "fontSize",
175
+ "fontFamily",
176
+ "fontTheme",
177
+ "color",
178
+ "colorTheme",
179
+ "characterSpacingTwips",
180
+ "textScalePercent",
181
+ "ligatures",
182
+ "kerningHalfPoints",
183
+ "positionHalfPoints",
184
+ "shadingFill",
185
+ "shadingThemeFill"
186
+ ];
187
+ function paragraphStyleRunChain(styleId, paragraphCatalog, runCatalog) {
188
+ if (!paragraphCatalog) return [];
189
+ const chain = [];
190
+ const visited = /* @__PURE__ */ new Set();
191
+ let current = styleId || Object.values(paragraphCatalog.styles).find((style) => style.isDefault)?.id;
192
+ while (current && !visited.has(current)) {
193
+ const style = paragraphCatalog.styles[current];
194
+ if (!style) break;
195
+ visited.add(current);
196
+ const runDefinition = runCatalog?.styles[current];
197
+ if (runDefinition) chain.push(runDefinition.formatting);
198
+ current = style.basedOn;
199
+ }
200
+ return chain.reverse();
201
+ }
202
+ function characterStyleChain(styleId, runCatalog) {
203
+ if (!styleId || !runCatalog) return [];
204
+ const chain = [];
205
+ const visited = /* @__PURE__ */ new Set();
206
+ let current = styleId;
207
+ while (current && !visited.has(current)) {
208
+ const style = runCatalog.styles[current];
209
+ if (!style) break;
210
+ visited.add(current);
211
+ chain.push(style.formatting);
212
+ current = style.basedOn;
213
+ }
214
+ return chain.reverse();
215
+ }
216
+ function resolveRunFormatting(run, context = {}) {
217
+ const docDefaults = context.runCatalog?.docDefaults ?? {};
218
+ const paragraphChain = paragraphStyleRunChain(
219
+ context.paragraphStyleId,
220
+ context.paragraphCatalog,
221
+ context.runCatalog
222
+ );
223
+ const characterChain = characterStyleChain(run.style, context.runCatalog);
224
+ const tableLevels = context.tableStyleRun ? [context.tableStyleRun] : [];
225
+ const levels = [
226
+ docDefaults,
227
+ ...paragraphChain,
228
+ ...tableLevels,
229
+ ...characterChain,
230
+ run
231
+ ];
232
+ const result = {};
233
+ const chainValue = (chain, key) => {
234
+ for (let index = chain.length - 1; index >= 0; index--)
235
+ if (chain[index]?.[key] !== void 0) return Boolean(chain[index]?.[key]);
236
+ return false;
237
+ };
238
+ for (const key of TOGGLE_KEYS) {
239
+ const direct = run[key];
240
+ const state = direct !== void 0 ? Boolean(direct) : Boolean(docDefaults[key]) !== (chainValue(paragraphChain, key) !== (chainValue(tableLevels, key) !== chainValue(characterChain, key)));
241
+ if (state) result[key] = true;
242
+ }
243
+ for (const key of OVERRIDE_KEYS) {
244
+ for (const level of levels) {
245
+ const value = level[key];
246
+ if (value !== void 0) result[key] = value;
247
+ }
248
+ }
249
+ return result;
250
+ }
251
+
252
+ // src/docx/theme-color.ts
253
+ var TOKEN_TO_SLOT = {
254
+ dark1: "dk1",
255
+ light1: "lt1",
256
+ dark2: "dk2",
257
+ light2: "lt2",
258
+ accent1: "accent1",
259
+ accent2: "accent2",
260
+ accent3: "accent3",
261
+ accent4: "accent4",
262
+ accent5: "accent5",
263
+ accent6: "accent6",
264
+ hyperlink: "hlink",
265
+ followedHyperlink: "folHlink"
266
+ };
267
+ var DEFAULT_MAPPING = {
268
+ bg1: "lt1",
269
+ tx1: "dk1",
270
+ bg2: "lt2",
271
+ tx2: "dk2"
272
+ };
273
+ function resolveThemeColorToken(token, theme) {
274
+ const logical = {
275
+ background1: "bg1",
276
+ text1: "tx1",
277
+ background2: "bg2",
278
+ text2: "tx2"
279
+ };
280
+ const logicalKey = logical[token];
281
+ if (logicalKey) {
282
+ const slot2 = theme.colorMapping[logicalKey] ?? DEFAULT_MAPPING[logicalKey];
283
+ return theme.colors[slot2];
284
+ }
285
+ const slot = TOKEN_TO_SLOT[token];
286
+ return slot ? theme.colors[slot] : void 0;
287
+ }
288
+ function hexToRgb(hex) {
289
+ const normalized = hex.replace(/^#/, "");
290
+ if (!/^[0-9a-fA-F]{6}$/.test(normalized)) return null;
291
+ return {
292
+ r: Number.parseInt(normalized.slice(0, 2), 16),
293
+ g: Number.parseInt(normalized.slice(2, 4), 16),
294
+ b: Number.parseInt(normalized.slice(4, 6), 16)
295
+ };
296
+ }
297
+ function toHex(value) {
298
+ return Math.min(255, Math.max(0, Math.round(value))).toString(16).padStart(2, "0").toUpperCase();
299
+ }
300
+ function srgbToLinear(channel) {
301
+ const c = Math.min(1, Math.max(0, channel / 255));
302
+ return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
303
+ }
304
+ function linearToSrgb(linear) {
305
+ const c = Math.min(1, Math.max(0, linear));
306
+ return 255 * (c <= 31308e-7 ? c * 12.92 : 1.055 * c ** (1 / 2.4) - 0.055);
307
+ }
308
+ function applyThemeShade(hex, fraction) {
309
+ const rgb = hexToRgb(hex);
310
+ if (!rgb) return hex;
311
+ const mix = (channel) => linearToSrgb(srgbToLinear(channel) * fraction);
312
+ return `#${toHex(mix(rgb.r))}${toHex(mix(rgb.g))}${toHex(mix(rgb.b))}`;
313
+ }
314
+ function applyThemeTint(hex, fraction) {
315
+ const rgb = hexToRgb(hex);
316
+ if (!rgb) return hex;
317
+ const mix = (channel) => linearToSrgb(1 - (1 - srgbToLinear(channel)) * fraction);
318
+ return `#${toHex(mix(rgb.r))}${toHex(mix(rgb.g))}${toHex(mix(rgb.b))}`;
319
+ }
320
+ function resolveThemeColorReference(ref, theme) {
321
+ const base = resolveThemeColorToken(ref.token, theme);
322
+ if (!base) return void 0;
323
+ let hex = `#${base.replace(/^#/, "")}`;
324
+ if (ref.shade !== void 0) hex = applyThemeShade(hex, ref.shade);
325
+ if (ref.tint !== void 0) hex = applyThemeTint(hex, ref.tint);
326
+ return hex;
327
+ }
328
+
329
+ // src/docx/expect-defined.ts
330
+ function expectDefined(value, context) {
331
+ if (value === void 0 || value === null) {
332
+ throw new Error(`Internal invariant violated: ${context} is missing.`);
333
+ }
334
+ return value;
335
+ }
336
+
337
+ // src/docx/defined-props.ts
338
+ function definedProps(source) {
339
+ return Object.fromEntries(Object.entries(source).filter(([, value]) => value !== void 0));
340
+ }
341
+
342
+ // src/docx/field-runs.ts
343
+ function fieldName(instr) {
344
+ return instr.trim().split(/\s+/)[0]?.toUpperCase() ?? "";
345
+ }
346
+
347
+ // src/docx/notes.ts
348
+ var romanNumerals = [
349
+ [1e3, "M"],
350
+ [900, "CM"],
351
+ [500, "D"],
352
+ [400, "CD"],
353
+ [100, "C"],
354
+ [90, "XC"],
355
+ [50, "L"],
356
+ [40, "XL"],
357
+ [10, "X"],
358
+ [9, "IX"],
359
+ [5, "V"],
360
+ [4, "IV"],
361
+ [1, "I"]
362
+ ];
363
+ function toRoman(value) {
364
+ let remaining = Math.max(1, Math.round(value));
365
+ let result = "";
366
+ for (const [amount, numeral] of romanNumerals) {
367
+ while (remaining >= amount) {
368
+ result += numeral;
369
+ remaining -= amount;
370
+ }
371
+ }
372
+ return result || "I";
373
+ }
374
+ function toLetters(value) {
375
+ let remaining = Math.max(1, Math.round(value));
376
+ let result = "";
377
+ while (remaining > 0) {
378
+ remaining--;
379
+ result = String.fromCharCode(97 + remaining % 26) + result;
380
+ remaining = Math.floor(remaining / 26);
381
+ }
382
+ return result || "a";
383
+ }
384
+ function formatNoteNumber(value, format) {
385
+ switch (format) {
386
+ case "upperRoman":
387
+ return toRoman(value);
388
+ case "lowerRoman":
389
+ return toRoman(value).toLowerCase();
390
+ case "upperLetter":
391
+ return toLetters(value).toUpperCase();
392
+ case "lowerLetter":
393
+ return toLetters(value);
394
+ case "decimalZero":
395
+ return value < 10 ? `0${value}` : String(value);
396
+ default:
397
+ return String(value);
398
+ }
399
+ }
400
+ function walkParagraph(paragraph, kind, order) {
401
+ for (const run of paragraph.runs) {
402
+ if (run.noteReference?.kind === kind && !order.has(run.noteReference.id))
403
+ order.set(run.noteReference.id, order.size + 1);
404
+ }
405
+ }
406
+ function walkBlocks(blocks, kind, order) {
407
+ for (const block of blocks) {
408
+ if (block.type === "paragraph") walkParagraph(block, kind, order);
409
+ else
410
+ for (const row of block.rows)
411
+ for (const cell of row) walkBlocks(cell.paragraphs, kind, order);
412
+ }
413
+ }
414
+ function numberNotesInOrder(blocks, kind) {
415
+ const order = /* @__PURE__ */ new Map();
416
+ walkBlocks(blocks, kind, order);
417
+ return order;
418
+ }
419
+
420
+ // src/docx/numbering-parse.ts
421
+ function resolveNumberingLevel(catalog, numId, level) {
422
+ const num = catalog.nums[numId];
423
+ if (!num) return void 0;
424
+ const override = num.levelOverrides?.[level];
425
+ const base = override?.lvl ?? catalog.abstractNums[num.abstractNumId]?.levels[level];
426
+ if (!base) return void 0;
427
+ return override?.startOverride !== void 0 ? { ...base, start: override.startOverride } : base;
428
+ }
429
+
430
+ // src/docx/numbering-text.ts
431
+ function romanNumeral(n) {
432
+ const values = [1e3, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
433
+ const numerals = [
434
+ "M",
435
+ "CM",
436
+ "D",
437
+ "CD",
438
+ "C",
439
+ "XC",
440
+ "L",
441
+ "XL",
442
+ "X",
443
+ "IX",
444
+ "V",
445
+ "IV",
446
+ "I"
447
+ ];
448
+ let remaining = Math.max(1, Math.min(Math.trunc(n), 3999));
449
+ let result = "";
450
+ for (const [i, value] of values.entries()) {
451
+ while (remaining >= value) {
452
+ result += numerals[i] ?? "";
453
+ remaining -= value;
454
+ }
455
+ }
456
+ return result;
457
+ }
458
+ var LATIN_LOWER = Array.from("abcdefghijklmnopqrstuvwxyz");
459
+ function letterLabel(n) {
460
+ const index = Math.max(0, Math.trunc(n) - 1);
461
+ const letter = LATIN_LOWER[index % LATIN_LOWER.length] ?? "a";
462
+ return letter.repeat(Math.floor(index / LATIN_LOWER.length) + 1);
463
+ }
464
+ var ORDINAL_SUFFIX = (n) => {
465
+ const abs = Math.abs(Math.trunc(n));
466
+ if (abs % 100 >= 11 && abs % 100 <= 13) return "th";
467
+ switch (abs % 10) {
468
+ case 1:
469
+ return "st";
470
+ case 2:
471
+ return "nd";
472
+ case 3:
473
+ return "rd";
474
+ default:
475
+ return "th";
476
+ }
477
+ };
478
+ function ordinalNumeral(n) {
479
+ return `${Math.trunc(n)}${ORDINAL_SUFFIX(n)}`;
480
+ }
481
+ var ONES = [
482
+ "",
483
+ "one",
484
+ "two",
485
+ "three",
486
+ "four",
487
+ "five",
488
+ "six",
489
+ "seven",
490
+ "eight",
491
+ "nine",
492
+ "ten",
493
+ "eleven",
494
+ "twelve",
495
+ "thirteen",
496
+ "fourteen",
497
+ "fifteen",
498
+ "sixteen",
499
+ "seventeen",
500
+ "eighteen",
501
+ "nineteen"
502
+ ];
503
+ var TENS = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"];
504
+ function cardinalWords(n) {
505
+ const value = Math.trunc(n);
506
+ if (value < 0 || value > 999999) return String(value);
507
+ if (value === 0) return "zero";
508
+ const chunk = (v) => {
509
+ const parts = [];
510
+ if (v >= 100) {
511
+ parts.push(ONES[Math.floor(v / 100)] ?? "", "hundred");
512
+ v %= 100;
513
+ }
514
+ if (v >= 20) {
515
+ parts.push((TENS[Math.floor(v / 10)] ?? "") + (v % 10 ? `-${ONES[v % 10] ?? ""}` : ""));
516
+ } else if (v > 0) {
517
+ parts.push(ONES[v] ?? "");
518
+ }
519
+ return parts.join(" ");
520
+ };
521
+ const thousands = Math.floor(value / 1e3);
522
+ const rest = value % 1e3;
523
+ const words = [];
524
+ if (thousands) words.push(chunk(thousands), "thousand");
525
+ if (rest || !thousands) words.push(chunk(rest));
526
+ return words.filter(Boolean).join(" ");
527
+ }
528
+ var ORDINAL_WORDS = {
529
+ one: "first",
530
+ two: "second",
531
+ three: "third",
532
+ five: "fifth",
533
+ eight: "eighth",
534
+ nine: "ninth",
535
+ twelve: "twelfth"
536
+ };
537
+ function ordinalWords(n) {
538
+ const value = Math.trunc(n);
539
+ if (value < 0 || value > 999999) return ordinalNumeral(value);
540
+ const words = cardinalWords(value);
541
+ const splitAt = Math.max(words.lastIndexOf(" "), words.lastIndexOf("-"));
542
+ const head = splitAt >= 0 ? words.slice(0, splitAt + 1) : "";
543
+ const lastWord = splitAt >= 0 ? words.slice(splitAt + 1) : words;
544
+ if (ORDINAL_WORDS[lastWord]) return head + ORDINAL_WORDS[lastWord];
545
+ if (lastWord.endsWith("y")) return `${head}${lastWord.slice(0, -1)}ieth`;
546
+ return `${head}${lastWord}th`;
547
+ }
548
+
549
+ // src/docx/numbering-format.ts
550
+ function formatListNumber(numFmt, value) {
551
+ switch (numFmt) {
552
+ case "decimal":
553
+ return String(value);
554
+ case "decimalZero":
555
+ return value < 10 && value >= 0 ? `0${value}` : String(value);
556
+ case "upperRoman":
557
+ return romanNumeral(value);
558
+ case "lowerRoman":
559
+ return romanNumeral(value).toLowerCase();
560
+ case "upperLetter":
561
+ return letterLabel(value).toUpperCase();
562
+ case "lowerLetter":
563
+ return letterLabel(value);
564
+ case "ordinal":
565
+ return ordinalNumeral(value);
566
+ case "ordinalText":
567
+ return ordinalWords(value);
568
+ case "cardinalText":
569
+ return cardinalWords(value);
570
+ case "none":
571
+ return "";
572
+ case "bullet":
573
+ return "";
574
+ default:
575
+ return String(value);
576
+ }
577
+ }
578
+ function resolveParagraphNumbering(paragraph, styleCatalog, numberingCatalog) {
579
+ if (paragraph.numbering)
580
+ return paragraph.numbering.numId > 0 ? paragraph.numbering : void 0;
581
+ if (!styleCatalog) return void 0;
582
+ const inherited = resolveStyleNumbering(paragraph.style, styleCatalog);
583
+ if (!inherited || inherited.numId <= 0) return void 0;
584
+ if (numberingCatalog && paragraph.style && styleCatalog.styles[paragraph.style]) {
585
+ for (let level = 0; level < 9; level++) {
586
+ const definition = resolveNumberingLevel(numberingCatalog, String(inherited.numId), level);
587
+ if (definition?.paragraphStyleId === paragraph.style)
588
+ return { numId: inherited.numId, level };
589
+ }
590
+ }
591
+ return inherited;
592
+ }
593
+ function flattenParagraphs(blocks) {
594
+ const result = [];
595
+ for (const block of blocks) {
596
+ if (block.type === "paragraph") result.push(block);
597
+ else for (const row of block.rows) for (const cell of row) result.push(...cell.paragraphs);
598
+ }
599
+ return result;
600
+ }
601
+ var NumberingCounters = class {
602
+ counts = /* @__PURE__ */ new Map();
603
+ started = /* @__PURE__ */ new Map();
604
+ forNum(numId) {
605
+ let counts = this.counts.get(numId);
606
+ if (!counts) {
607
+ counts = /* @__PURE__ */ new Map();
608
+ this.counts.set(numId, counts);
609
+ }
610
+ return counts;
611
+ }
612
+ startedLevels(numId) {
613
+ let started = this.started.get(numId);
614
+ if (!started) {
615
+ started = /* @__PURE__ */ new Set();
616
+ this.started.set(numId, started);
617
+ }
618
+ return started;
619
+ }
620
+ /** Advances one level and resets deeper counters according to their resolved restart rules. */
621
+ advance(numId, level, def, catalog) {
622
+ const counts = this.forNum(numId);
623
+ const started = this.startedLevels(numId);
624
+ const next = started.has(level) ? (counts.get(level) ?? def.start) + 1 : def.start;
625
+ counts.set(level, next);
626
+ started.add(level);
627
+ for (const deeper of [...started]) {
628
+ if (deeper <= level) continue;
629
+ const deeperDef = resolveNumberingLevel(catalog, numId, deeper);
630
+ const restart = deeperDef?.lvlRestart;
631
+ if (restart === 0) continue;
632
+ const trigger = restart !== void 0 && restart > 0 && restart <= deeper ? restart - 1 : deeper - 1;
633
+ if (level > trigger) continue;
634
+ counts.delete(deeper);
635
+ started.delete(deeper);
636
+ }
637
+ for (let ancestor = 0; ancestor < level; ancestor++) {
638
+ if (started.has(ancestor)) continue;
639
+ const ancestorDef = resolveNumberingLevel(catalog, numId, ancestor);
640
+ if (!ancestorDef) continue;
641
+ counts.set(ancestor, ancestorDef.start);
642
+ started.add(ancestor);
643
+ }
644
+ return next;
645
+ }
646
+ /** Current value for an ancestor placeholder, defaulting to its own start when never instantiated. */
647
+ current(numId, level, start) {
648
+ return this.forNum(numId).get(level) ?? start;
649
+ }
650
+ };
651
+ function substituteLvlText(lvlText, numId, level, catalog, counters, forceDecimal) {
652
+ return lvlText.replace(/%([1-9])/g, (match, digit) => {
653
+ const ancestorLevel = Number(digit) - 1;
654
+ if (ancestorLevel > level) return match;
655
+ const ancestorDef = resolveNumberingLevel(catalog, numId, ancestorLevel);
656
+ const start = ancestorDef?.start ?? 1;
657
+ const value = counters.current(numId, ancestorLevel, start);
658
+ const fmt = forceDecimal ? "decimal" : ancestorDef?.numFmt ?? "decimal";
659
+ return formatListNumber(fmt, value);
660
+ });
661
+ }
662
+ function computeListLabels(model) {
663
+ const catalog = model.numberingCatalog;
664
+ const labels = /* @__PURE__ */ new Map();
665
+ if (!catalog) return labels;
666
+ const counters = new NumberingCounters();
667
+ for (const paragraph of flattenParagraphs(model.blocks)) {
668
+ const numbering = resolveParagraphNumbering(paragraph, model.paragraphStyles, catalog);
669
+ if (!numbering) continue;
670
+ const numId = String(numbering.numId);
671
+ const level = Math.min(8, Math.max(0, numbering.level));
672
+ const def = resolveNumberingLevel(catalog, numId, level);
673
+ if (!def) continue;
674
+ if (def.numFmt === "none") continue;
675
+ counters.advance(numId, level, def, catalog);
676
+ const text = def.numFmt === "bullet" ? def.lvlText : substituteLvlText(def.lvlText, numId, level, catalog, counters, Boolean(def.isLgl));
677
+ labels.set(paragraph.id, {
678
+ numId,
679
+ level,
680
+ text,
681
+ suffix: def.suffix ?? "tab",
682
+ ...definedProps({
683
+ alignment: def.lvlJc,
684
+ indentLeftTwips: def.indentLeftTwips,
685
+ hangingTwips: def.hangingTwips,
686
+ firstLineTwips: def.firstLineTwips,
687
+ markerFormat: def.markerFormat,
688
+ tabStopTwips: def.tabStopTwips
689
+ })
690
+ });
691
+ }
692
+ return labels;
693
+ }
694
+ var SYMBOL_BULLETS = {
695
+ "\uF0B7": "\u2022",
696
+ "\uF0A7": "\u25AA",
697
+ "\uF0D8": "\u27A2",
698
+ "\uF076": "\u2756",
699
+ "\uF0FC": "\u2713",
700
+ "\uF06E": "\u25A0",
701
+ "\uF071": "\u2751",
702
+ "\uF0E0": "\u27A9",
703
+ "\uF0B2": "\u25CB"
704
+ };
705
+ function displayListLabel(text) {
706
+ return text.replace(/[-]/g, (char) => SYMBOL_BULLETS[char] ?? "\u2022");
707
+ }
708
+
709
+ // src/docx/field-date.ts
710
+ function datePicture(instr) {
711
+ const match = /\\@\s*(?:"([^"]*)"|(\S+))/.exec(instr);
712
+ return match ? match[1] ?? match[2] : void 0;
713
+ }
714
+ var TOKENS = /yyyy|yy|MMMM|MMM|MM|M|dddd|ddd|dd|d|HH|H|hh|h|mm|ss|am\/pm|AM\/PM|'[^']*'/g;
715
+ function formatWordDate(date, picture, locale = "en-US") {
716
+ const name = (options) => new Intl.DateTimeFormat(locale, options).format(date);
717
+ const pad = (value) => String(value).padStart(2, "0");
718
+ const hours12 = date.getHours() % 12 || 12;
719
+ return picture.replace(TOKENS, (token) => {
720
+ switch (token) {
721
+ case "yyyy":
722
+ return String(date.getFullYear());
723
+ case "yy":
724
+ return pad(date.getFullYear() % 100);
725
+ case "MMMM":
726
+ return name({ month: "long" });
727
+ case "MMM":
728
+ return name({ month: "short" });
729
+ case "MM":
730
+ return pad(date.getMonth() + 1);
731
+ case "M":
732
+ return String(date.getMonth() + 1);
733
+ case "dddd":
734
+ return name({ weekday: "long" });
735
+ case "ddd":
736
+ return name({ weekday: "short" });
737
+ case "dd":
738
+ return pad(date.getDate());
739
+ case "d":
740
+ return String(date.getDate());
741
+ case "HH":
742
+ return pad(date.getHours());
743
+ case "H":
744
+ return String(date.getHours());
745
+ case "hh":
746
+ return pad(hours12);
747
+ case "h":
748
+ return String(hours12);
749
+ case "mm":
750
+ return pad(date.getMinutes());
751
+ case "ss":
752
+ return pad(date.getSeconds());
753
+ case "am/pm":
754
+ return date.getHours() < 12 ? "am" : "pm";
755
+ case "AM/PM":
756
+ return date.getHours() < 12 ? "AM" : "PM";
757
+ default:
758
+ return token.slice(1, -1);
759
+ }
760
+ });
761
+ }
762
+ function dateFieldResult(name, instr, now, locale) {
763
+ const picture = datePicture(instr) ?? (name === "DATE" ? "M/d/yyyy" : "h:mm am/pm");
764
+ return formatWordDate(now, picture, locale);
765
+ }
766
+
767
+ // src/docx/table-visuals.ts
768
+ var NONE = { style: "none" };
769
+ function edgeFrom(borders, side, onBoundary) {
770
+ if (!borders) return void 0;
771
+ if (onBoundary) return borders[side];
772
+ return side === "top" || side === "bottom" ? borders.insideH : borders.insideV;
773
+ }
774
+ function resolveCellVisuals(table, cell, placement, styles) {
775
+ const styled = table.style ? resolveTableStyleFormatting(
776
+ table.style,
777
+ styles,
778
+ table.look,
779
+ placement.row,
780
+ placement.rowCount,
781
+ placement.column,
782
+ placement.columnCount
783
+ ) : {};
784
+ const hasBorderInfo = Boolean(styled.borders || table.borders || cell.borders);
785
+ const shadingFill = cell.shadingFill ?? styled.shadingFill;
786
+ if (!hasBorderInfo) return shadingFill ? { shadingFill } : {};
787
+ const boundary = {
788
+ top: placement.row === 0,
789
+ bottom: placement.lastRow === placement.rowCount - 1,
790
+ left: placement.column === 0,
791
+ right: placement.lastColumn === placement.columnCount - 1
792
+ };
793
+ const borders = {};
794
+ for (const side of ["top", "bottom", "left", "right"])
795
+ borders[side] = cell.borders?.[side] ?? edgeFrom(table.borders, side, boundary[side]) ?? edgeFrom(styled.borders, side, boundary[side]) ?? NONE;
796
+ return { borders, ...shadingFill ? { shadingFill } : {} };
797
+ }
798
+
799
+ // src/docx/layout/units.ts
800
+ function twipsToPx(value) {
801
+ return value * 96 / 1440;
802
+ }
803
+ var NO_TWIPS = twips(0);
804
+ function pxToTwips(px) {
805
+ return roundSignedTwips(px * 1440 / 96);
806
+ }
807
+ function ptToPx(pt) {
808
+ return pt * 96 / 72;
809
+ }
810
+ var DEFAULT_TAB_STOP_PX = twipsToPx(twips(720));
811
+ var DEFAULT_FONT_FAMILY = "Calibri";
812
+ var DEFAULT_FONT_SIZE_PT = 11;
813
+ var SINGLE_LINE_SPACING_UNITS = 240;
814
+
815
+ // src/docx/layout/measure.ts
816
+ function fontMetrics(measurer, font) {
817
+ const height = measurer.lineHeightOf(font);
818
+ const ascent = Math.min(height, measurer.ascentOf?.(font) ?? height * 0.8);
819
+ return { ascent, descent: height - ascent };
820
+ }
821
+ function createFakeMeasurer(options = {}) {
822
+ const charWidthFactor = options.charWidthFactor ?? 0.6;
823
+ const lineHeightFactor = options.lineHeightFactor ?? 1.15;
824
+ return {
825
+ widthOf(text, font) {
826
+ let width = 0;
827
+ for (const ch of text) {
828
+ if (ch === " " || ch === "\n") continue;
829
+ width += font.sizePx * charWidthFactor * (font.bold ? 1.08 : 1) * (ch === " " ? 0.6 : 1);
830
+ }
831
+ return width;
832
+ },
833
+ lineHeightOf(font) {
834
+ return font.sizePx * lineHeightFactor;
835
+ }
836
+ };
837
+ }
838
+
839
+ // src/docx/layout/ligatures.ts
840
+ function ligatureCss(value) {
841
+ const enabled = (token) => value === "all" || value.toLowerCase().includes(token);
842
+ return `${enabled("standard") ? "common-ligatures" : "no-common-ligatures"} ${enabled("contextual") ? "contextual" : "no-contextual"} ${enabled("historical") ? "historical-ligatures" : "no-historical-ligatures"} ${enabled("discretional") ? "discretionary-ligatures" : "no-discretionary-ligatures"}`;
843
+ }
844
+
845
+ // src/docx/layout/text-breaks.ts
846
+ function isEastAsianChar(ch) {
847
+ const cp = ch.codePointAt(0) ?? 0;
848
+ return cp >= 4352 && cp <= 4607 || cp >= 11904 && cp <= 40959 || cp >= 43360 && cp <= 43391 || cp >= 44032 && cp <= 55295 || cp >= 63744 && cp <= 64255 || cp >= 65072 && cp <= 65103 || cp >= 65280 && cp <= 65519 || cp >= 131072 && cp <= 262143;
849
+ }
850
+ function tokenizeRun(text, runIndex) {
851
+ const tokens = [];
852
+ let word = "";
853
+ let wordStart = 0;
854
+ const flushWord = () => {
855
+ if (word) tokens.push({ kind: "word", text: word, runIndex, sourceStart: wordStart });
856
+ word = "";
857
+ };
858
+ const chars = [...new Intl.Segmenter(void 0, { granularity: "grapheme" }).segment(text)].map(
859
+ (part) => part.segment
860
+ );
861
+ let offset = 0;
862
+ for (const ch of chars) {
863
+ if (ch === "\n") {
864
+ flushWord();
865
+ tokens.push({ kind: "lineBreak", runIndex, sourceStart: offset });
866
+ } else if (ch === " ") {
867
+ flushWord();
868
+ tokens.push({ kind: "tab", runIndex, sourceStart: offset });
869
+ } else if (ch === " ") {
870
+ flushWord();
871
+ tokens.push({ kind: "space", text: ch, runIndex, sourceStart: offset });
872
+ } else if (isEastAsianChar(ch)) {
873
+ flushWord();
874
+ tokens.push({ kind: "word", text: ch, runIndex, sourceStart: offset });
875
+ } else {
876
+ if (!word) wordStart = offset;
877
+ word += ch;
878
+ if (ch === "-") flushWord();
879
+ }
880
+ offset += ch.length;
881
+ }
882
+ flushWord();
883
+ return tokens;
884
+ }
885
+ function appendBreakMarker(tokens, runIndex, sourceStart, kind) {
886
+ tokens.push({ kind: kind === "page" ? "pageBreak" : "columnBreak", runIndex, sourceStart });
887
+ }
888
+
889
+ // src/docx/layout/tab-stops.ts
890
+ function placeTab(positionPx, stops, hangingStopPx, followingPx, beforeDecimalPx) {
891
+ const epsilon = 0.5;
892
+ const custom = stops.filter((stop) => stop.align !== "clear" && stop.align !== "bar").sort((a, b) => a.posPx - b.posPx).find((stop) => stop.posPx > positionPx + epsilon);
893
+ if (custom) {
894
+ const distance = custom.posPx - positionPx;
895
+ const shift = custom.align === "right" || custom.align === "end" ? followingPx : custom.align === "center" ? followingPx / 2 : custom.align === "decimal" ? beforeDecimalPx : 0;
896
+ return {
897
+ widthPx: Math.max(0, distance - shift),
898
+ ...custom.leader && custom.leader !== "none" ? { leader: custom.leader } : {}
899
+ };
900
+ }
901
+ if (hangingStopPx !== void 0 && hangingStopPx > positionPx + epsilon)
902
+ return { widthPx: hangingStopPx - positionPx };
903
+ const next = (Math.floor(positionPx / DEFAULT_TAB_STOP_PX) + 1) * DEFAULT_TAB_STOP_PX;
904
+ return { widthPx: next - positionPx };
905
+ }
906
+
907
+ // src/docx/layout/paragraph-tokens.ts
908
+ var SCRIPT_SCALE = 0.65;
909
+ function fontOf(run) {
910
+ return {
911
+ family: run.fontFamily || DEFAULT_FONT_FAMILY,
912
+ sizePx: ptToPx(run.fontSizePt ?? DEFAULT_FONT_SIZE_PT) * (run.script ? SCRIPT_SCALE : 1),
913
+ ...definedProps({ bold: run.bold, italic: run.italic, ligatures: run.ligatures }),
914
+ ...run.kerningThresholdPt === void 0 ? {} : {
915
+ kerning: run.kerningThresholdPt > 0 && (run.fontSizePt ?? DEFAULT_FONT_SIZE_PT) >= run.kerningThresholdPt ? "normal" : "none"
916
+ }
917
+ };
918
+ }
919
+ var graphemes = new Intl.Segmenter(void 0, { granularity: "grapheme" });
920
+ function runTextWidth(text, run, measurer) {
921
+ return Math.max(
922
+ 0,
923
+ measurer.widthOf(text, fontOf(run)) * (run.textScalePercent ?? 100) / 100 + [...graphemes.segment(text)].length * (run.characterSpacingPx ?? 0)
924
+ );
925
+ }
926
+ function resolveIndents(paragraph) {
927
+ const rtl = paragraph.direction === "rtl";
928
+ const startTwips = paragraph.indentStartTwips ?? (rtl ? paragraph.indentRightTwips : paragraph.indentLeftTwips) ?? NO_TWIPS;
929
+ const endTwips = paragraph.indentEndTwips ?? (rtl ? paragraph.indentLeftTwips : paragraph.indentRightTwips) ?? NO_TWIPS;
930
+ const leftTwips = rtl ? endTwips : startTwips;
931
+ const rightTwips = rtl ? startTwips : endTwips;
932
+ const firstLineExtraPx = paragraph.hangingTwips != null ? -twipsToPx(paragraph.hangingTwips) : twipsToPx(paragraph.firstLineTwips ?? NO_TWIPS);
933
+ return {
934
+ leftPx: twipsToPx(leftTwips),
935
+ rightPx: twipsToPx(rightTwips),
936
+ firstLineExtraPx
937
+ };
938
+ }
939
+ function tokenizeParagraph(paragraph) {
940
+ const tokens = [];
941
+ const runOffsets = [];
942
+ let cursor = 0;
943
+ paragraph.runs.forEach((run, runIndex) => {
944
+ runOffsets.push(cursor);
945
+ if (run.object) tokens.push({ kind: "object", runIndex, sourceStart: 0 });
946
+ else if (run.marker) {
947
+ tokens.push({
948
+ kind: "word",
949
+ runIndex,
950
+ sourceStart: 0,
951
+ text: run.text.slice(0, run.marker.length)
952
+ });
953
+ tokens.push(...tokenizeRun(run.text.slice(run.marker.length), runIndex));
954
+ } else tokens.push(...tokenizeRun(run.text, runIndex));
955
+ if (run.breakAfter) appendBreakMarker(tokens, runIndex, run.text.length, run.breakAfter);
956
+ if (run.synthetic) {
957
+ for (const token of tokens) if (token.runIndex === runIndex) token.sourceStart = 0;
958
+ } else cursor += run.text.length;
959
+ });
960
+ return { tokens, runOffsets };
961
+ }
962
+
963
+ // src/docx/layout/line-metrics.ts
964
+ var SUPER_RAISE = 0.33;
965
+ function tokenExtent(token, paragraph, fonts, measurer) {
966
+ const run = paragraph.runs[token.runIndex];
967
+ if (token.kind === "object" && run?.object)
968
+ return { above: run.object.heightPx, below: 0, ascent: run.object.heightPx, descent: 0 };
969
+ const { ascent, descent } = fontMetrics(measurer, fonts[token.runIndex] ?? fontOf({ }));
970
+ const size = ptToPx(run?.fontSizePt ?? DEFAULT_FONT_SIZE_PT);
971
+ const scriptShift = run?.script === "super" ? SUPER_RAISE * size : run?.script === "sub" ? -0.14 * size : 0;
972
+ const shift = scriptShift + (run?.positionPx ?? 0);
973
+ return { above: ascent + shift, below: descent - shift, ascent, descent };
974
+ }
975
+ function lineMetrics(placed, fonts, paragraph, measurer) {
976
+ const tokens = placed.length ? placed.map((p) => p.token) : [{ kind: "space", text: " ", runIndex: 0, sourceStart: 0 }];
977
+ let above = 0;
978
+ let below = 0;
979
+ for (const token of tokens) {
980
+ const extent = tokenExtent(token, paragraph, fonts, measurer);
981
+ above = Math.max(above, extent.above);
982
+ below = Math.max(below, extent.below);
983
+ }
984
+ const natural = above + below;
985
+ const rule = paragraph.lineSpacingRule ?? "auto";
986
+ const spacingTwips = paragraph.lineSpacingTwips;
987
+ const heightPx = rule === "exact" ? spacingTwips != null ? twipsToPx(spacingTwips) : natural : rule === "atLeast" ? Math.max(natural, spacingTwips != null ? twipsToPx(spacingTwips) : 0) : natural * ((spacingTwips ?? 240) / 240);
988
+ return { heightPx, baselinePx: heightPx - below };
989
+ }
990
+
991
+ // src/docx/layout/paragraph-fragments.ts
992
+ function buildFragments(tokensOnLine, paragraph) {
993
+ const fragments = [];
994
+ let x = 0;
995
+ for (const { token, widthPx, leader, xOffsetPx, advancePx } of tokensOnLine) {
996
+ const run = paragraph.runs[token.runIndex];
997
+ const text = token.kind === "word" || token.kind === "space" ? token.text : "";
998
+ fragments.push({
999
+ text,
1000
+ xPx: x + (xOffsetPx ?? 0),
1001
+ widthPx,
1002
+ runIndex: token.runIndex,
1003
+ ...definedProps({
1004
+ bold: run?.bold,
1005
+ italic: run?.italic,
1006
+ fontFamily: run?.fontFamily,
1007
+ fontSizePt: run?.fontSizePt,
1008
+ textScalePercent: run?.textScalePercent,
1009
+ ligatures: run?.ligatures,
1010
+ characterSpacingPx: run?.characterSpacingPx,
1011
+ kerningThresholdPt: run?.kerningThresholdPt
1012
+ }),
1013
+ ...leader ? { leader } : {},
1014
+ ...run?.script ? { script: run.script } : {},
1015
+ ...run?.color ? { color: run.color } : {},
1016
+ ...run?.underline ? { underline: true } : {},
1017
+ ...run?.strike ? { strike: true } : {},
1018
+ ...token.kind === "object" && run?.object ? { object: run.object } : {}
1019
+ });
1020
+ x += advancePx ?? widthPx;
1021
+ }
1022
+ return fragments;
1023
+ }
1024
+ function justify(fragments, width) {
1025
+ const spaceIndices = fragments.map((f, i) => f.text === " " ? i : -1).filter((i) => i >= 0);
1026
+ if (!spaceIndices.length || !fragments.length) return fragments;
1027
+ const natural = fragments.at(-1).xPx + fragments.at(-1).widthPx;
1028
+ const extra = Math.max(0, width - natural) / spaceIndices.length;
1029
+ if (extra <= 0) return fragments;
1030
+ let shift = 0;
1031
+ return fragments.map((fragment, index) => {
1032
+ const placedFragment = { ...fragment, xPx: fragment.xPx + shift };
1033
+ if (spaceIndices.includes(index)) {
1034
+ placedFragment.widthPx += extra;
1035
+ shift += extra;
1036
+ }
1037
+ return placedFragment;
1038
+ });
1039
+ }
1040
+ function alignFragments(fragments, width, isLastLine, effectiveAlign) {
1041
+ if (!fragments.length) return fragments;
1042
+ if (effectiveAlign === "justify" && !isLastLine) return justify(fragments, width);
1043
+ const natural = fragments.at(-1).xPx + fragments.at(-1).widthPx;
1044
+ const offset = effectiveAlign === "center" ? Math.max(0, width - natural) / 2 : effectiveAlign === "right" ? Math.max(0, width - natural) : 0;
1045
+ return offset === 0 ? fragments : fragments.map((f) => ({ ...f, xPx: f.xPx + offset }));
1046
+ }
1047
+
1048
+ // src/docx/layout/paragraph-layout.ts
1049
+ function layoutParagraph(paragraph, contentWidthPx, measurer, note, lineBox, startToken = 0) {
1050
+ const { leftPx, rightPx, firstLineExtraPx: initialIndent } = resolveIndents(paragraph);
1051
+ const firstLineExtraPx = startToken ? 0 : initialIndent;
1052
+ const bodyWidth = Math.max(1, contentWidthPx - leftPx - rightPx);
1053
+ const fonts = paragraph.runs.map(fontOf);
1054
+ const { tokens, runOffsets } = tokenizeParagraph(paragraph);
1055
+ const globalOffset = (token) => expectDefined(runOffsets[token.runIndex], "run offset index") + token.sourceStart;
1056
+ const effectiveAlign = paragraph.align ?? (paragraph.direction === "rtl" ? "right" : "left");
1057
+ const lines = [];
1058
+ const pageBreakAfterLine = /* @__PURE__ */ new Set();
1059
+ const columnBreakAfterLine = /* @__PURE__ */ new Set();
1060
+ let widthOverflowNoted = false;
1061
+ let placed = [];
1062
+ let lineWidthPx = 0;
1063
+ let tokenCursor = startToken;
1064
+ let firstToken = startToken;
1065
+ const boxes = [];
1066
+ let runningY = 0;
1067
+ const guessHeight = measurer.lineHeightOf(fonts[0] ?? fontOf({ }));
1068
+ const boxFor = (lineIndex) => {
1069
+ if (!boxes[lineIndex]) {
1070
+ let gap = 0;
1071
+ let box = lineBox?.(runningY, guessHeight);
1072
+ for (let step = 0; box && box.gapBeforePx > 0 && step < 8; step++) {
1073
+ gap += box.gapBeforePx;
1074
+ box = lineBox(runningY + gap, guessHeight);
1075
+ }
1076
+ boxes[lineIndex] = {
1077
+ leftInsetPx: box?.leftInsetPx ?? 0,
1078
+ rightInsetPx: box?.rightInsetPx ?? 0,
1079
+ gapBeforePx: gap
1080
+ };
1081
+ }
1082
+ return expectDefined(boxes[lineIndex], "line box");
1083
+ };
1084
+ const availableWidth = (lineIndex) => {
1085
+ const box = boxFor(lineIndex);
1086
+ return Math.max(
1087
+ 1,
1088
+ bodyWidth - (lineIndex === 0 ? firstLineExtraPx : 0) - box.leftInsetPx - box.rightInsetPx
1089
+ );
1090
+ };
1091
+ const lineStart = (lineIndex) => leftPx + (lineIndex === 0 ? firstLineExtraPx : 0) + boxFor(lineIndex).leftInsetPx;
1092
+ const tokenWidth = (token) => token.kind === "word" || token.kind === "space" ? runTextWidth(
1093
+ token.text,
1094
+ expectDefined(paragraph.runs[token.runIndex], "token run"),
1095
+ measurer
1096
+ ) : token.kind === "object" ? paragraph.runs[token.runIndex]?.object?.widthPx ?? 0 : 0;
1097
+ const widths = tokens.map(tokenWidth);
1098
+ const ends = /* @__PURE__ */ new Set(["tab", "lineBreak", "pageBreak", "columnBreak"]);
1099
+ function segmentAfter(index) {
1100
+ let followingPx = 0;
1101
+ let beforeDecimalPx;
1102
+ for (let next = index + 1; next < tokens.length; next++) {
1103
+ const token = expectDefined(tokens[next], "token index");
1104
+ if (ends.has(token.kind)) break;
1105
+ if (beforeDecimalPx === void 0 && token.kind === "word" && /[.,]/.test(token.text)) {
1106
+ const prefix = token.text.slice(0, token.text.search(/[.,]/));
1107
+ beforeDecimalPx = followingPx + runTextWidth(
1108
+ prefix,
1109
+ expectDefined(paragraph.runs[token.runIndex], "decimal run"),
1110
+ measurer
1111
+ );
1112
+ }
1113
+ followingPx += widths[next] ?? 0;
1114
+ }
1115
+ return { followingPx, beforeDecimalPx: beforeDecimalPx ?? followingPx };
1116
+ }
1117
+ const hangingStopPx = firstLineExtraPx < 0 ? leftPx : void 0;
1118
+ function flushLine(forceEmpty, forcedByBreak) {
1119
+ if (!placed.length && !forceEmpty) return;
1120
+ const lineIndex = lines.length;
1121
+ const rendered = [...placed];
1122
+ while (rendered.length && rendered.at(-1).token.kind === "space") rendered.pop();
1123
+ const fragments = buildFragments(rendered, paragraph);
1124
+ const [firstPlaced] = placed;
1125
+ const start = firstPlaced ? globalOffset(firstPlaced.token) : 0;
1126
+ const last = placed.at(-1)?.token;
1127
+ const end = last ? globalOffset(last) + (last.kind === "word" || last.kind === "space" ? last.text.length : 1) : start;
1128
+ const gapBeforePx = boxFor(lineIndex).gapBeforePx;
1129
+ const { heightPx, baselinePx } = lineMetrics(placed, fonts, paragraph, measurer);
1130
+ rendered.forEach(({ token }, index) => {
1131
+ const extent2 = tokenExtent(token, paragraph, fonts, measurer);
1132
+ const fragment = expectDefined(fragments[index], "fragment for rendered token");
1133
+ fragment.topPx = baselinePx - extent2.above;
1134
+ if (token.kind !== "object") fragment.boxHeightPx = extent2.ascent + extent2.descent;
1135
+ });
1136
+ lines.push({
1137
+ yPx: 0,
1138
+ heightPx,
1139
+ baselinePx,
1140
+ fragments,
1141
+ sourceStart: start,
1142
+ sourceEnd: end,
1143
+ nextToken: tokenCursor,
1144
+ firstToken,
1145
+ ...gapBeforePx ? { gapBeforePx } : {}
1146
+ });
1147
+ runningY += gapBeforePx + heightPx;
1148
+ if (forcedByBreak === "page") pageBreakAfterLine.add(lineIndex);
1149
+ if (forcedByBreak === "column") columnBreakAfterLine.add(lineIndex);
1150
+ placed = [];
1151
+ lineWidthPx = 0;
1152
+ }
1153
+ for (const [tokenIndex, token] of tokens.entries()) {
1154
+ if (tokenIndex < startToken) continue;
1155
+ tokenCursor = tokenIndex + 1;
1156
+ if (token.kind === "lineBreak") {
1157
+ if (!placed.length) firstToken = tokenIndex;
1158
+ flushLine(true, void 0);
1159
+ continue;
1160
+ }
1161
+ if (token.kind === "pageBreak" || token.kind === "columnBreak") {
1162
+ if (!placed.length) firstToken = tokenIndex;
1163
+ flushLine(true, token.kind === "pageBreak" ? "page" : "column");
1164
+ continue;
1165
+ }
1166
+ let leader;
1167
+ let width = expectDefined(widths[tokenIndex], "token width");
1168
+ const marker = paragraph.runs[token.runIndex]?.marker;
1169
+ const markerFactor = marker && token.kind === "word" && tokenIndex === 0 ? marker.alignment === "right" ? 1 : marker.alignment === "center" ? 0.5 : 0 : 0;
1170
+ const advance = width * (1 - markerFactor);
1171
+ if (token.kind === "tab") {
1172
+ const { followingPx, beforeDecimalPx } = segmentAfter(tokenIndex);
1173
+ const tab = placeTab(
1174
+ lineStart(lines.length) + lineWidthPx,
1175
+ paragraph.tabStops ?? [],
1176
+ hangingStopPx,
1177
+ followingPx,
1178
+ beforeDecimalPx
1179
+ );
1180
+ width = tab.widthPx;
1181
+ leader = tab.leader === "none" ? void 0 : tab.leader;
1182
+ }
1183
+ const lineIndex = lines.length;
1184
+ const limit = availableWidth(lineIndex);
1185
+ const wouldFit = lineWidthPx + (token.kind === "tab" ? width : advance) <= limit || placed.every((placed2) => paragraph.runs[placed2.token.runIndex]?.synthetic);
1186
+ if (!wouldFit && token.kind !== "space") {
1187
+ tokenCursor = tokenIndex;
1188
+ flushLine(false, void 0);
1189
+ tokenCursor = tokenIndex + 1;
1190
+ if (width > availableWidth(lines.length) && !widthOverflowNoted) {
1191
+ widthOverflowNoted = true;
1192
+ note(
1193
+ "A word wider than its line/column was not split mid-word; it overflows the line box."
1194
+ );
1195
+ }
1196
+ }
1197
+ if (token.kind === "space" && placed.length === 0) continue;
1198
+ if (!placed.length) firstToken = tokenIndex;
1199
+ placed.push({
1200
+ token,
1201
+ widthPx: width,
1202
+ ...leader ? { leader } : {},
1203
+ ...markerFactor ? { xOffsetPx: -width * markerFactor, advancePx: advance } : {}
1204
+ });
1205
+ lineWidthPx += token.kind === "tab" ? width : advance;
1206
+ }
1207
+ flushLine(lines.length === 0, void 0);
1208
+ const lastIndex = lines.length - 1;
1209
+ for (const [index, line] of lines.entries()) {
1210
+ lines[index] = {
1211
+ ...line,
1212
+ fragments: alignFragments(
1213
+ line.fragments,
1214
+ availableWidth(index),
1215
+ index === lastIndex,
1216
+ effectiveAlign
1217
+ ).map((fragment) => ({ ...fragment, xPx: fragment.xPx + lineStart(index) }))
1218
+ };
1219
+ }
1220
+ const borders = paragraph.borders;
1221
+ const extent = (side) => borders?.[side] ? borders[side].widthPx + borders[side].spacePx : 0;
1222
+ const insetTopPx = extent("top");
1223
+ const insetBottomPx = extent("bottom");
1224
+ let y = insetTopPx;
1225
+ for (const line of lines) {
1226
+ y += line.gapBeforePx ?? 0;
1227
+ line.yPx = y;
1228
+ y += line.heightPx;
1229
+ }
1230
+ const frame = borders || paragraph.shading ? {
1231
+ leftPx: leftPx - extent("left"),
1232
+ widthPx: bodyWidth + extent("left") + extent("right"),
1233
+ ...borders ? { borders } : {},
1234
+ ...paragraph.shading ? { shading: paragraph.shading } : {}
1235
+ } : void 0;
1236
+ return {
1237
+ lines,
1238
+ spacingBeforePx: twipsToPx(paragraph.spacingBeforeTwips ?? NO_TWIPS),
1239
+ spacingAfterPx: twipsToPx(paragraph.spacingAfterTwips ?? NO_TWIPS),
1240
+ contentHeightPx: y + insetBottomPx,
1241
+ insetTopPx,
1242
+ insetBottomPx,
1243
+ ...frame ? { frame } : {},
1244
+ pageBreakAfterLine,
1245
+ columnBreakAfterLine
1246
+ };
1247
+ }
1248
+
1249
+ // src/docx/layout/keep-rules.ts
1250
+ function adjustForWidowOrphan(totalLines, fittingLines, widowControl) {
1251
+ if (!widowControl) return fittingLines;
1252
+ if (fittingLines <= 0 || fittingLines >= totalLines) return fittingLines;
1253
+ const remaining = totalLines - fittingLines;
1254
+ if (fittingLines === 1) return 0;
1255
+ if (remaining === 1) return fittingLines - 1;
1256
+ return fittingLines;
1257
+ }
1258
+ function suppressesSpacing(previous, current) {
1259
+ if (!previous || !previous.styleId || previous.styleId !== current.styleId) return false;
1260
+ return Boolean(previous.contextualSpacing) || Boolean(current.contextualSpacing);
1261
+ }
1262
+ function widowControlEnabled(value) {
1263
+ return value !== false;
1264
+ }
1265
+
1266
+ // src/docx/layout/table-layout.ts
1267
+ function stackParagraphs(paragraphs, widthPx, measurer, note, topPx = 0, startTokens) {
1268
+ let y = topPx;
1269
+ const boxes = [];
1270
+ for (const paragraph of paragraphs) {
1271
+ const layout = layoutParagraph(
1272
+ paragraph,
1273
+ widthPx,
1274
+ measurer,
1275
+ note,
1276
+ void 0,
1277
+ startTokens?.get(paragraph.id) ?? 0
1278
+ );
1279
+ y += layout.spacingBeforePx;
1280
+ const top = y;
1281
+ const lines = layout.lines.map((line) => ({ ...line, yPx: line.yPx + top }));
1282
+ boxes.push({
1283
+ kind: "paragraph",
1284
+ blockId: paragraph.id,
1285
+ yPx: top,
1286
+ heightPx: layout.contentHeightPx,
1287
+ lines
1288
+ });
1289
+ y += layout.contentHeightPx + layout.spacingAfterPx;
1290
+ }
1291
+ return { heightPx: y, boxes };
1292
+ }
1293
+ function layoutRow(row, tableWidthPx, measurer, note, remaining) {
1294
+ const count = row.cells.length || 1;
1295
+ let x = 0;
1296
+ const geometry = [];
1297
+ const laidOut = row.cells.map((cell) => {
1298
+ const continuation = remaining?.[geometry.length];
1299
+ const starts = continuation ? new Map(continuation.map((box) => [box.blockId, box.lines[0]?.firstToken ?? 0])) : void 0;
1300
+ const widthPx = cell.widthPx ?? tableWidthPx / count;
1301
+ const padding = cell.padding ?? { top: 0, right: 0, bottom: 0, left: 0 };
1302
+ const content2 = stackParagraphs(
1303
+ starts ? cell.paragraphs.filter((paragraph) => starts.has(paragraph.id)) : cell.paragraphs,
1304
+ Math.max(1, widthPx - padding.left - padding.right),
1305
+ measurer,
1306
+ note,
1307
+ padding.top,
1308
+ starts
1309
+ );
1310
+ const heightPx2 = content2.heightPx + padding.bottom;
1311
+ geometry.push({
1312
+ xPx: cell.xPx ?? x,
1313
+ widthPx,
1314
+ paddingLeftPx: padding.left,
1315
+ paddingRightPx: padding.right,
1316
+ contentHeightPx: heightPx2,
1317
+ ...cell.borders ? { borders: cell.borders } : {},
1318
+ ...cell.shading ? { shading: cell.shading } : {},
1319
+ ...cell.verticalAlign ? { verticalAlign: cell.verticalAlign } : {}
1320
+ });
1321
+ x = (cell.xPx ?? x) + widthPx;
1322
+ return { heightPx: heightPx2, boxes: content2.boxes };
1323
+ });
1324
+ const content = Math.max(0, ...laidOut.map((cell) => cell.heightPx));
1325
+ const heightPx = row.heightPx === void 0 ? content : row.heightRule === "exact" ? row.heightPx : Math.max(content, row.heightPx);
1326
+ return { heightPx, cells: laidOut.map((cell) => cell.boxes), geometry };
1327
+ }
1328
+ function splitCellAtHeight(boxes, cutHeightPx) {
1329
+ const before = [];
1330
+ const after = [];
1331
+ let afterOrigin = null;
1332
+ let beforeHeightPx = 0;
1333
+ for (const box of boxes) {
1334
+ if (afterOrigin !== null) {
1335
+ after.push({ ...box, yPx: box.yPx - afterOrigin });
1336
+ continue;
1337
+ }
1338
+ if (box.yPx + box.heightPx <= cutHeightPx) {
1339
+ before.push(box);
1340
+ beforeHeightPx = box.yPx + box.heightPx;
1341
+ continue;
1342
+ }
1343
+ if (box.yPx >= cutHeightPx) {
1344
+ afterOrigin = box.yPx;
1345
+ after.push({ ...box, yPx: 0 });
1346
+ continue;
1347
+ }
1348
+ const beforeLines = box.lines.filter(
1349
+ (line) => box.yPx + line.yPx + line.heightPx <= cutHeightPx
1350
+ );
1351
+ const afterLines = box.lines.slice(beforeLines.length);
1352
+ if (beforeLines.length) {
1353
+ const bottom = beforeLines.at(-1).yPx + beforeLines.at(-1).heightPx;
1354
+ before.push({ ...box, heightPx: bottom, lines: beforeLines });
1355
+ beforeHeightPx = box.yPx + bottom;
1356
+ }
1357
+ if (afterLines.length) {
1358
+ const shift = expectDefined(afterLines[0], "first line after split").yPx;
1359
+ afterOrigin = box.yPx + shift;
1360
+ after.push({
1361
+ ...box,
1362
+ yPx: 0,
1363
+ heightPx: afterLines.at(-1).yPx + afterLines.at(-1).heightPx - shift,
1364
+ lines: afterLines.map((line) => ({ ...line, yPx: line.yPx - shift }))
1365
+ });
1366
+ } else {
1367
+ afterOrigin = box.yPx + box.heightPx;
1368
+ }
1369
+ }
1370
+ return { before, after, beforeHeightPx };
1371
+ }
1372
+ function splitRowAtHeight(row, cutHeightPx) {
1373
+ const splits = row.cells.map((cell) => splitCellAtHeight(cell, cutHeightPx));
1374
+ const anyAfter = splits.some((split) => split.after.length > 0);
1375
+ const before = {
1376
+ heightPx: Math.max(0, ...splits.map((split) => split.beforeHeightPx)),
1377
+ cells: splits.map((split) => split.before),
1378
+ geometry: row.geometry
1379
+ };
1380
+ if (!anyAfter) return { before, after: null };
1381
+ const after = {
1382
+ heightPx: Math.max(
1383
+ 0,
1384
+ ...splits.map(
1385
+ (split) => split.after.reduce((max, box) => Math.max(max, box.yPx + box.heightPx), 0)
1386
+ )
1387
+ ),
1388
+ cells: splits.map((split) => split.after),
1389
+ geometry: row.geometry
1390
+ };
1391
+ return { before, after };
1392
+ }
1393
+
1394
+ // src/docx/layout/page-cursor.ts
1395
+ var FOOTNOTE_SEPARATOR_PX = 12;
1396
+ var PageCursor = class {
1397
+ pages;
1398
+ equalColumnWidthPx;
1399
+ columnHeightPx;
1400
+ geometry;
1401
+ columns;
1402
+ columnIndex = 0;
1403
+ yPx = 0;
1404
+ sectionIndex;
1405
+ pageInSection = 0;
1406
+ /** Height taken by footnotes (and their separator) at the bottom of the current page. */
1407
+ reservedPx = 0;
1408
+ /** Footnotes of the paragraph about to be placed; they join the page its first box lands on. */
1409
+ pending;
1410
+ constructor(pages, geometry, columns, sectionIndex = 0) {
1411
+ this.sectionIndex = sectionIndex;
1412
+ this.pages = pages;
1413
+ this.geometry = geometry;
1414
+ this.columns = columns;
1415
+ const contentWidth = geometry.widthPx - geometry.marginLeftPx - geometry.marginRightPx;
1416
+ this.equalColumnWidthPx = Math.max(
1417
+ 1,
1418
+ (contentWidth - columns.gapPx * (columns.count - 1)) / columns.count
1419
+ );
1420
+ this.columnHeightPx = Math.max(
1421
+ 1,
1422
+ geometry.heightPx - geometry.marginTopPx - geometry.marginBottomPx
1423
+ );
1424
+ this.pushPage();
1425
+ }
1426
+ pushPage() {
1427
+ const columnBoxes = [];
1428
+ let xPx = 0;
1429
+ for (let i = 0; i < this.columns.count; i++) {
1430
+ const explicit = this.columns.widths?.[i];
1431
+ const widthPx = Math.max(1, explicit?.widthPx ?? this.equalColumnWidthPx);
1432
+ columnBoxes.push({
1433
+ xPx,
1434
+ widthPx,
1435
+ blocks: []
1436
+ });
1437
+ xPx += widthPx + (explicit?.gapPx ?? this.columns.gapPx);
1438
+ }
1439
+ this.pages.push({
1440
+ index: this.pages.length,
1441
+ sectionIndex: this.sectionIndex,
1442
+ pageInSection: this.pageInSection++,
1443
+ widthPx: this.geometry.widthPx,
1444
+ heightPx: this.geometry.heightPx,
1445
+ marginTopPx: this.geometry.marginTopPx,
1446
+ marginRightPx: this.geometry.marginRightPx,
1447
+ marginBottomPx: this.geometry.marginBottomPx,
1448
+ marginLeftPx: this.geometry.marginLeftPx,
1449
+ columns: columnBoxes,
1450
+ ...this.columns.separator ? { columnSeparator: true } : {}
1451
+ });
1452
+ this.columnIndex = 0;
1453
+ this.yPx = 0;
1454
+ this.reservedPx = 0;
1455
+ }
1456
+ get page() {
1457
+ return this.pages.at(-1);
1458
+ }
1459
+ get column() {
1460
+ return expectDefined(this.page.columns[this.columnIndex], "current page column");
1461
+ }
1462
+ get columnWidthPx() {
1463
+ return this.column.widthPx;
1464
+ }
1465
+ get y() {
1466
+ return this.yPx;
1467
+ }
1468
+ get atColumnTop() {
1469
+ return this.yPx === 0;
1470
+ }
1471
+ remainingHeightPx() {
1472
+ return this.columnHeightPx - this.yPx - this.reservedPx - this.pendingHeightPx();
1473
+ }
1474
+ pendingHeightPx() {
1475
+ if (!this.pending) return 0;
1476
+ return this.pending.heightPx + (this.page.footnotes?.length ? 0 : FOOTNOTE_SEPARATOR_PX);
1477
+ }
1478
+ /**
1479
+ * Reserves room for a paragraph's footnotes on whichever page its first box is placed, so the
1480
+ * notes print on the same page as their reference, as Word does.
1481
+ */
1482
+ holdFootnotes(blockId, notes) {
1483
+ const heightPx = notes.reduce((sum, note) => sum + note.heightPx, 0);
1484
+ this.pending = notes.length ? { blockId, notes, heightPx } : void 0;
1485
+ }
1486
+ newPage() {
1487
+ this.pushPage();
1488
+ }
1489
+ /** Advances to the next column, or a new page when the section has no more columns. */
1490
+ newColumn() {
1491
+ if (this.columnIndex + 1 < this.columns.count) {
1492
+ this.columnIndex++;
1493
+ this.yPx = 0;
1494
+ } else {
1495
+ this.pushPage();
1496
+ }
1497
+ }
1498
+ /** Places a box at the current fill position (sets its `yPx`) and advances by `advancePx`. */
1499
+ place(box, advancePx) {
1500
+ box.yPx = this.yPx;
1501
+ this.column.blocks.push(box);
1502
+ this.yPx += advancePx;
1503
+ if (this.pending && this.pending.blockId === box.blockId) {
1504
+ this.reservedPx += this.pendingHeightPx();
1505
+ const page = this.page;
1506
+ let top = page.footnotes?.reduce((sum, note) => sum + note.heightPx, 0) ?? 0;
1507
+ for (const note of this.pending.notes) {
1508
+ (page.footnotes ??= []).push({ ...note, yPx: top });
1509
+ top += note.heightPx;
1510
+ }
1511
+ this.pending = void 0;
1512
+ }
1513
+ }
1514
+ };
1515
+
1516
+ // src/docx/layout/flow-paragraph.ts
1517
+ function placeParagraph(cursor, placement, note) {
1518
+ const { paragraph, spacingBeforePx, requiredTogetherPx, reflow } = placement;
1519
+ let layout = placement.layout;
1520
+ let width = cursor.columnWidthPx;
1521
+ if (paragraph.pageBreakBefore && !cursor.atColumnTop) cursor.newPage();
1522
+ if (requiredTogetherPx > 0 && requiredTogetherPx <= cursor.columnHeightPx && requiredTogetherPx > cursor.remainingHeightPx() && !cursor.atColumnTop) {
1523
+ cursor.newColumn();
1524
+ }
1525
+ const widow = widowControlEnabled(paragraph.widowControl);
1526
+ let lineCursor = 0;
1527
+ let nextToken = 0;
1528
+ let firstSegment = true;
1529
+ const reflowIfNeeded = () => {
1530
+ if (!reflow || cursor.columnWidthPx === width) return;
1531
+ layout = reflow(nextToken);
1532
+ lineCursor = 0;
1533
+ width = cursor.columnWidthPx;
1534
+ };
1535
+ reflowIfNeeded();
1536
+ if (!layout.lines.length) {
1537
+ cursor.place(
1538
+ { kind: "paragraph", blockId: paragraph.id, yPx: 0, heightPx: 0, lines: [] },
1539
+ spacingBeforePx + layout.spacingAfterPx
1540
+ );
1541
+ return;
1542
+ }
1543
+ while (lineCursor < layout.lines.length) {
1544
+ reflowIfNeeded();
1545
+ const budget = cursor.remainingHeightPx() - (firstSegment ? spacingBeforePx : 0);
1546
+ let cumulative = 0;
1547
+ let end = lineCursor;
1548
+ let forced;
1549
+ for (let i = lineCursor; i < layout.lines.length; i++) {
1550
+ const line = expectDefined(layout.lines[i], "paragraph line index");
1551
+ const gap = i === lineCursor && !firstSegment ? 0 : line.gapBeforePx ?? 0;
1552
+ const height = line.heightPx + gap;
1553
+ if (cumulative + height > budget && (end > lineCursor || !cursor.atColumnTop)) break;
1554
+ cumulative += height;
1555
+ end = i + 1;
1556
+ if (layout.pageBreakAfterLine.has(i)) {
1557
+ forced = "page";
1558
+ break;
1559
+ }
1560
+ if (layout.columnBreakAfterLine.has(i)) {
1561
+ forced = "column";
1562
+ break;
1563
+ }
1564
+ }
1565
+ let placedCount = end - lineCursor;
1566
+ if (!forced && end < layout.lines.length)
1567
+ placedCount = adjustForWidowOrphan(layout.lines.length - lineCursor, placedCount, widow);
1568
+ if (placedCount === 0) {
1569
+ if (!cursor.atColumnTop) {
1570
+ cursor.newColumn();
1571
+ continue;
1572
+ }
1573
+ note(
1574
+ "A paragraph line was taller than an empty page/column and was placed without splitting."
1575
+ );
1576
+ placedCount = Math.max(1, end - lineCursor);
1577
+ }
1578
+ const first = expectDefined(layout.lines[lineCursor], "first line of paragraph segment");
1579
+ const origin = first.yPx - (firstSegment ? (first.gapBeforePx ?? 0) + layout.insetTopPx : 0);
1580
+ const segmentLines = layout.lines.slice(lineCursor, lineCursor + placedCount).map((line) => ({ ...line, yPx: line.yPx - origin }));
1581
+ const isFinal = lineCursor + placedCount >= layout.lines.length;
1582
+ const lastLine = segmentLines.at(-1);
1583
+ const isLastSegment = lineCursor + placedCount >= layout.lines.length;
1584
+ const segmentHeight = (lastLine ? lastLine.yPx + lastLine.heightPx : 0) + (isLastSegment ? layout.insetBottomPx : 0);
1585
+ const box = {
1586
+ kind: "paragraph",
1587
+ blockId: paragraph.id,
1588
+ yPx: 0,
1589
+ heightPx: segmentHeight,
1590
+ lines: segmentLines,
1591
+ ...layout.frame ? { frame: layout.frame } : {}
1592
+ };
1593
+ const advance = (firstSegment ? spacingBeforePx : 0) + segmentHeight + (isFinal ? layout.spacingAfterPx : 0);
1594
+ cursor.place(box, advance);
1595
+ nextToken = layout.lines[lineCursor + placedCount - 1]?.nextToken ?? nextToken;
1596
+ lineCursor += placedCount;
1597
+ firstSegment = false;
1598
+ if (forced === "page") cursor.newPage();
1599
+ else if (forced === "column") cursor.newColumn();
1600
+ else if (lineCursor < layout.lines.length) cursor.newColumn();
1601
+ }
1602
+ }
1603
+
1604
+ // src/docx/layout/flow-table.ts
1605
+ function placeTable(cursor, table, measurer, note) {
1606
+ const headerRows = table.rows.filter((row) => row.isHeader);
1607
+ const xPosition = () => {
1608
+ const width = table.widthPx ?? cursor.columnWidthPx;
1609
+ return table.alignment === "center" ? Math.max(0, (cursor.columnWidthPx - width) / 2) : table.alignment === "right" ? Math.max(0, cursor.columnWidthPx - width) : table.indentPx ?? 0;
1610
+ };
1611
+ let fragmentRows = [];
1612
+ let fragmentHeight = 0;
1613
+ const toRowBox = (layout, repeated) => {
1614
+ const box = {
1615
+ yPx: fragmentHeight,
1616
+ heightPx: layout.heightPx,
1617
+ repeated,
1618
+ cells: layout.cells,
1619
+ geometry: layout.geometry
1620
+ };
1621
+ fragmentHeight += layout.heightPx;
1622
+ return box;
1623
+ };
1624
+ function flushFragment() {
1625
+ if (!fragmentRows.length) return;
1626
+ const box = {
1627
+ kind: "table",
1628
+ blockId: table.id,
1629
+ ...xPosition() ? { xPx: xPosition() } : {},
1630
+ yPx: 0,
1631
+ heightPx: fragmentHeight,
1632
+ rows: fragmentRows
1633
+ };
1634
+ cursor.place(box, fragmentHeight);
1635
+ fragmentRows = [];
1636
+ fragmentHeight = 0;
1637
+ }
1638
+ function startNewFragment() {
1639
+ flushFragment();
1640
+ cursor.newColumn();
1641
+ for (const header of headerRows)
1642
+ fragmentRows.push(toRowBox(layoutRow(header, cursor.columnWidthPx, measurer, note), true));
1643
+ }
1644
+ function placeRow(row, initial, cantSplit) {
1645
+ let remainingRow = initial;
1646
+ while (remainingRow) {
1647
+ const remaining = cursor.remainingHeightPx() - fragmentHeight;
1648
+ if (remainingRow.heightPx <= remaining) {
1649
+ fragmentRows.push(toRowBox(remainingRow, false));
1650
+ remainingRow = null;
1651
+ continue;
1652
+ }
1653
+ if (cantSplit) {
1654
+ if (fragmentRows.length || !cursor.atColumnTop) {
1655
+ startNewFragment();
1656
+ remainingRow = layoutRow(row, cursor.columnWidthPx, measurer, note);
1657
+ }
1658
+ const freshRemaining = cursor.remainingHeightPx() - fragmentHeight;
1659
+ if (remainingRow.heightPx > freshRemaining)
1660
+ note('A table row marked "keep row together" is taller than an empty page/column.');
1661
+ fragmentRows.push(toRowBox(remainingRow, false));
1662
+ remainingRow = null;
1663
+ continue;
1664
+ }
1665
+ const { before, after } = splitRowAtHeight(remainingRow, Math.max(0, remaining));
1666
+ const previousWidth = cursor.columnWidthPx;
1667
+ if (before.cells.some((cell) => cell.length)) fragmentRows.push(toRowBox(before, false));
1668
+ startNewFragment();
1669
+ remainingRow = after && previousWidth !== cursor.columnWidthPx ? layoutRow(
1670
+ { ...row, heightPx: 0, heightRule: "atLeast" },
1671
+ cursor.columnWidthPx,
1672
+ measurer,
1673
+ note,
1674
+ after.cells
1675
+ ) : after;
1676
+ }
1677
+ }
1678
+ for (const row of table.rows) {
1679
+ const layout = layoutRow(row, cursor.columnWidthPx, measurer, note);
1680
+ placeRow(row, layout, Boolean(row.cantSplit) || row.isHeader === true);
1681
+ }
1682
+ flushFragment();
1683
+ }
1684
+
1685
+ // src/docx/layout/wrap.ts
1686
+ var SIDE_DISTANCE_PX = 12;
1687
+ var MIN_SIDE_WIDTH_PX = 48;
1688
+ function wrapExclusions(pages) {
1689
+ const exclusions = /* @__PURE__ */ new Map();
1690
+ for (const page of pages) {
1691
+ const list = (page.floats ?? []).filter((float) => float.wrap && float.wrap !== "none").map((float) => ({
1692
+ xPx: float.xPx - SIDE_DISTANCE_PX,
1693
+ yPx: float.yPx,
1694
+ widthPx: float.widthPx + SIDE_DISTANCE_PX * 2,
1695
+ heightPx: float.heightPx,
1696
+ topAndBottom: float.wrap === "topAndBottom"
1697
+ }));
1698
+ if (list.length) exclusions.set(page.index, list);
1699
+ }
1700
+ return exclusions;
1701
+ }
1702
+ function sameExclusions(a, b) {
1703
+ const key = (map) => JSON.stringify(
1704
+ [...map].map(([page, list]) => [
1705
+ page,
1706
+ list.map((item) => [Math.round(item.xPx), Math.round(item.yPx), item.topAndBottom])
1707
+ ])
1708
+ );
1709
+ return key(a) === key(b);
1710
+ }
1711
+ function lineBoxesFor(exclusions, topPx, columnLeftPx, columnWidthPx) {
1712
+ return (yPx, heightPx) => {
1713
+ const top = topPx + yPx;
1714
+ let leftInsetPx = 0;
1715
+ let rightInsetPx = 0;
1716
+ let gapBeforePx = 0;
1717
+ for (const exclusion of exclusions) {
1718
+ const overlapsLine = exclusion.yPx < top + heightPx && exclusion.yPx + exclusion.heightPx > top;
1719
+ const start = exclusion.xPx - columnLeftPx;
1720
+ const end = start + exclusion.widthPx;
1721
+ if (!overlapsLine || end <= 0 || start >= columnWidthPx) continue;
1722
+ const left = Math.max(0, start);
1723
+ const right = Math.max(0, columnWidthPx - end);
1724
+ if (exclusion.topAndBottom || Math.max(left, right) < MIN_SIDE_WIDTH_PX) {
1725
+ gapBeforePx = Math.max(gapBeforePx, exclusion.yPx + exclusion.heightPx - top);
1726
+ continue;
1727
+ }
1728
+ if (left >= right) rightInsetPx = Math.max(rightInsetPx, columnWidthPx - start);
1729
+ else leftInsetPx = Math.max(leftInsetPx, end);
1730
+ }
1731
+ return { leftInsetPx, rightInsetPx, gapBeforePx };
1732
+ };
1733
+ }
1734
+
1735
+ // src/docx/layout/page-flow.ts
1736
+ var CONTINUOUS_BREAK_NOTE = "Continuous section breaks are rendered as page breaks; changing page size, margins or column count without starting a new page is not modeled.";
1737
+ var SectionFlow = class {
1738
+ constructor(section, pages, measurer, note, sectionIndex = 0, exclusions) {
1739
+ this.exclusions = exclusions;
1740
+ this.blocks = section.blocks;
1741
+ this.measurer = measurer;
1742
+ this.note = note;
1743
+ this.cursor = new PageCursor(
1744
+ pages,
1745
+ section.page,
1746
+ section.columns ?? { count: 1, gapPx: 0 },
1747
+ sectionIndex
1748
+ );
1749
+ if (section.break === "continuous") note(CONTINUOUS_BREAK_NOTE);
1750
+ }
1751
+ exclusions;
1752
+ cursor;
1753
+ blocks;
1754
+ measurer;
1755
+ note;
1756
+ paragraphCache = /* @__PURE__ */ new Map();
1757
+ firstRowHeightCache = /* @__PURE__ */ new Map();
1758
+ paragraphLayout(index) {
1759
+ const key = `${index}:${this.cursor.columnWidthPx}`;
1760
+ let cached = this.paragraphCache.get(key);
1761
+ if (!cached) {
1762
+ cached = layoutParagraph(
1763
+ this.blocks[index],
1764
+ this.cursor.columnWidthPx,
1765
+ this.measurer,
1766
+ this.note
1767
+ );
1768
+ this.paragraphCache.set(key, cached);
1769
+ }
1770
+ return cached;
1771
+ }
1772
+ firstRowHeight(index) {
1773
+ const key = `${index}:${this.cursor.columnWidthPx}`;
1774
+ let cached = this.firstRowHeightCache.get(key);
1775
+ if (cached === void 0) {
1776
+ const table = this.blocks[index];
1777
+ const [firstRow] = table.rows;
1778
+ cached = firstRow ? layoutRow(firstRow, this.cursor.columnWidthPx, this.measurer, this.note).heightPx : 0;
1779
+ this.firstRowHeightCache.set(key, cached);
1780
+ }
1781
+ return cached;
1782
+ }
1783
+ spacingBeforeFor(index) {
1784
+ const block = this.blocks[index];
1785
+ if (block?.kind !== "paragraph") return 0;
1786
+ const layout = this.paragraphLayout(index);
1787
+ const previous = index > 0 ? this.blocks[index - 1] : void 0;
1788
+ if (previous?.kind === "paragraph" && suppressesSpacing(previous, block)) return 0;
1789
+ return layout.spacingBeforePx;
1790
+ }
1791
+ /** Minimum height that must fit before `index` may start, walking a `keepNext` chain. */
1792
+ requiredKeepHeight(index, depth = 0) {
1793
+ if (index >= this.blocks.length || depth > 64) return 0;
1794
+ const block = expectDefined(this.blocks[index], "keep-chain block index");
1795
+ if (block.kind === "table") return this.firstRowHeight(index);
1796
+ const layout = this.paragraphLayout(index);
1797
+ const before = this.spacingBeforeFor(index);
1798
+ const own = before + (block.keepLines ? layout.contentHeightPx + layout.spacingAfterPx : layout.lines[0]?.heightPx ?? 0);
1799
+ return block.keepNext ? own + this.requiredKeepHeight(index + 1, depth + 1) : own;
1800
+ }
1801
+ /**
1802
+ * The paragraph laid out around wrapped pictures on the current page, when any of them reaches
1803
+ * the paragraph's lines; lines continuing onto a later page keep these widths.
1804
+ */
1805
+ wrappedLayout(index, spacingBeforePx) {
1806
+ const page = this.cursor.page;
1807
+ const exclusions = this.exclusions?.get(page.index);
1808
+ if (!exclusions) return void 0;
1809
+ const plain = this.paragraphLayout(index);
1810
+ const topPx = page.marginTopPx + this.cursor.y + spacingBeforePx;
1811
+ const bottomPx = topPx + plain.contentHeightPx;
1812
+ if (!exclusions.some((item) => item.yPx < bottomPx && item.yPx + item.heightPx > topPx))
1813
+ return void 0;
1814
+ return layoutParagraph(
1815
+ this.blocks[index],
1816
+ this.cursor.columnWidthPx,
1817
+ this.measurer,
1818
+ this.note,
1819
+ lineBoxesFor(
1820
+ exclusions,
1821
+ topPx,
1822
+ page.marginLeftPx + this.cursor.column.xPx,
1823
+ this.cursor.columnWidthPx
1824
+ )
1825
+ );
1826
+ }
1827
+ run() {
1828
+ for (let index = 0; index < this.blocks.length; index++) {
1829
+ const block = expectDefined(this.blocks[index], "flow block index");
1830
+ if (block.kind === "table") {
1831
+ placeTable(this.cursor, block, this.measurer, this.note);
1832
+ continue;
1833
+ }
1834
+ const spacingBeforePx = this.spacingBeforeFor(index);
1835
+ const layout = this.wrappedLayout(index, spacingBeforePx) ?? this.paragraphLayout(index);
1836
+ if (block.footnotes?.length)
1837
+ this.cursor.holdFootnotes(
1838
+ block.id,
1839
+ block.footnotes.map((note) => {
1840
+ const stacked = stackParagraphs(
1841
+ note.paragraphs,
1842
+ this.cursor.columnWidthPx,
1843
+ this.measurer,
1844
+ this.note
1845
+ );
1846
+ return { id: note.id, yPx: 0, heightPx: stacked.heightPx, paragraphs: stacked.boxes };
1847
+ })
1848
+ );
1849
+ const requiredTogetherPx = block.keepNext ? this.requiredKeepHeight(index) : block.keepLines ? spacingBeforePx + layout.contentHeightPx + layout.spacingAfterPx : 0;
1850
+ placeParagraph(
1851
+ this.cursor,
1852
+ {
1853
+ paragraph: block,
1854
+ layout,
1855
+ spacingBeforePx,
1856
+ requiredTogetherPx,
1857
+ reflow: (token) => layoutParagraph(
1858
+ block,
1859
+ this.cursor.columnWidthPx,
1860
+ this.measurer,
1861
+ this.note,
1862
+ void 0,
1863
+ token
1864
+ )
1865
+ },
1866
+ this.note
1867
+ );
1868
+ }
1869
+ }
1870
+ };
1871
+ function insertParityBlank(pages, section) {
1872
+ const previous = pages.at(-1);
1873
+ if (!previous || section.break !== "evenPage" && section.break !== "oddPage") return;
1874
+ const nextNumber = pages.length + 1;
1875
+ const wanted = section.break === "evenPage" ? 0 : 1;
1876
+ if (nextNumber % 2 === wanted) return;
1877
+ pages.push({
1878
+ ...previous,
1879
+ index: pages.length,
1880
+ pageInSection: previous.pageInSection + 1,
1881
+ columns: previous.columns.map((column) => ({ ...column, blocks: [] }))
1882
+ });
1883
+ }
1884
+ function alignVertically(pages, section, note) {
1885
+ const align = section.verticalAlign;
1886
+ if (!align || align === "top") return;
1887
+ if (align === "both") {
1888
+ note("Vertically justified sections are laid out top-aligned.");
1889
+ return;
1890
+ }
1891
+ for (const page of pages) {
1892
+ const available = page.heightPx - page.marginTopPx - page.marginBottomPx;
1893
+ const used = Math.max(
1894
+ 0,
1895
+ ...page.columns.flatMap((column) => column.blocks.map((block) => block.yPx + block.heightPx))
1896
+ );
1897
+ const shift = (available - used) / (align === "center" ? 2 : 1);
1898
+ if (shift <= 0) continue;
1899
+ for (const column of page.columns) for (const block of column.blocks) block.yPx += shift;
1900
+ }
1901
+ }
1902
+ function layoutSections(input, measurer, exclusions) {
1903
+ const approximations = /* @__PURE__ */ new Set();
1904
+ const note = (message) => approximations.add(message);
1905
+ const pages = [];
1906
+ input.sections.forEach((section, index) => {
1907
+ insertParityBlank(pages, section);
1908
+ const first = pages.length;
1909
+ new SectionFlow(section, pages, measurer, note, index, exclusions).run();
1910
+ alignVertically(pages.slice(first), section, note);
1911
+ });
1912
+ return { pages, approximations: [...approximations] };
1913
+ }
1914
+
1915
+ // src/docx/layout/adapt-floats.ts
1916
+ function paragraphFloats(paragraph) {
1917
+ const floats = [];
1918
+ for (const run of paragraph.runs) {
1919
+ const image = run.image;
1920
+ if (!image?.anchored || !image.partName) continue;
1921
+ const placement = image.placement;
1922
+ floats.push({
1923
+ partName: image.partName,
1924
+ contentType: image.contentType,
1925
+ widthPx: image.widthPx,
1926
+ heightPx: image.heightPx,
1927
+ ...placement?.relativeFrom ? { relativeFromH: placement.relativeFrom } : {},
1928
+ ...placement?.align ? { alignH: placement.align } : {},
1929
+ ...placement?.offsetXPx !== void 0 ? { offsetXPx: placement.offsetXPx } : {},
1930
+ ...placement?.relativeFromV ? { relativeFromV: placement.relativeFromV } : {},
1931
+ ...placement?.alignV ? { alignV: placement.alignV } : {},
1932
+ ...placement?.offsetYPx !== void 0 ? { offsetYPx: placement.offsetYPx } : {},
1933
+ ...placement?.behindText ? { behindText: true } : {},
1934
+ ...placement?.wrap ? { wrap: placement.wrap } : {}
1935
+ });
1936
+ }
1937
+ return floats;
1938
+ }
1939
+ function floatsOf(paragraph) {
1940
+ const floats = paragraphFloats(paragraph);
1941
+ return floats.length ? { floats } : {};
1942
+ }
1943
+
1944
+ // src/docx/layout/adapt-table.ts
1945
+ var twipsToPx2 = twipsToPixels;
1946
+ var DEFAULT_PADDING_TWIPS = {
1947
+ top: twips(0),
1948
+ right: twips(108),
1949
+ bottom: twips(0),
1950
+ left: twips(108)
1951
+ };
1952
+ function cssHex(value) {
1953
+ const hex = value?.replace(/^#/, "");
1954
+ return hex && /^[0-9a-f]{6}$/i.test(hex) ? `#${hex}` : void 0;
1955
+ }
1956
+ function border(side, theme) {
1957
+ if (!side?.style || side.style === "none" || side.style === "nil") return void 0;
1958
+ const style = side.style.startsWith("double") ? "double" : /dot/i.test(side.style) ? "dotted" : /dash/i.test(side.style) ? "dashed" : "solid";
1959
+ const themed = side.themeColor && theme ? resolveThemeColorReference({ token: side.themeColor }, theme) : void 0;
1960
+ const hex = cssHex(side.color);
1961
+ const widthPx = Math.max(
1962
+ style === "double" ? 3 : 1,
1963
+ (side.sizeEighthPoints ?? 4) / 8 * 96 / 72
1964
+ );
1965
+ return { widthPx, style, color: themed ?? hex ?? "#000000" };
1966
+ }
1967
+ function rowLayout(props) {
1968
+ if (!props) return {};
1969
+ return {
1970
+ ...props.heightTwips ? { heightPx: twipsToPx2(props.heightTwips), heightRule: props.heightRule ?? "atLeast" } : {},
1971
+ ...props.cantSplit ? { cantSplit: true } : {},
1972
+ ...props.header ? { isHeader: true } : {}
1973
+ };
1974
+ }
1975
+ function adaptTable(table, model, adaptParagraph) {
1976
+ const grid = table.grid?.map(twipsToPx2);
1977
+ const columnCount = grid?.length ?? Math.max(1, ...table.rows.map((row) => row.length));
1978
+ const gridWidth = (start, span) => grid ? grid.slice(start, start + span).reduce((sum, width) => sum + width, 0) : void 0;
1979
+ const gridIndexes = table.rows.map((row) => {
1980
+ let index = 0;
1981
+ return row.map((cell) => {
1982
+ const start = index;
1983
+ index += cell.gridSpan ?? 1;
1984
+ return start;
1985
+ });
1986
+ });
1987
+ const cellAt = (rowIndex, gridIndex) => {
1988
+ const position = gridIndexes[rowIndex]?.indexOf(gridIndex) ?? -1;
1989
+ return position >= 0 ? table.rows[rowIndex]?.[position] : void 0;
1990
+ };
1991
+ return {
1992
+ kind: "table",
1993
+ id: table.id,
1994
+ ...grid ? { widthPx: grid.reduce((sum, width) => sum + width, 0) } : {},
1995
+ ...table.indentTwips ? { indentPx: twipsToPx2(table.indentTwips) } : {},
1996
+ ...table.alignment ? { alignment: table.alignment } : {},
1997
+ rows: table.rows.map((row, rowIndex) => ({
1998
+ ...rowLayout(table.rowProperties?.[rowIndex]),
1999
+ cells: row.map((cell, cellIndex) => {
2000
+ const start = expectDefined(gridIndexes[rowIndex]?.[cellIndex], "table cell grid index");
2001
+ const span = cell.gridSpan ?? 1;
2002
+ const visuals = resolveCellVisuals(
2003
+ table,
2004
+ cell,
2005
+ {
2006
+ row: rowIndex,
2007
+ lastRow: rowIndex,
2008
+ column: start,
2009
+ lastColumn: start + span - 1,
2010
+ rowCount: table.rows.length,
2011
+ columnCount
2012
+ },
2013
+ model.tableStyles
2014
+ );
2015
+ const borders = {};
2016
+ for (const side of ["top", "right", "bottom", "left"]) {
2017
+ const resolved = border(visuals.borders?.[side], model.theme);
2018
+ if (resolved) borders[side] = resolved;
2019
+ }
2020
+ if (cell.verticalMerge === "continue") delete borders.top;
2021
+ if (cellAt(rowIndex + 1, start)?.verticalMerge === "continue") delete borders.bottom;
2022
+ const margins = { ...DEFAULT_PADDING_TWIPS, ...table.cellMargins, ...cell.margins };
2023
+ const padding = {
2024
+ top: twipsToPx2(margins.top),
2025
+ right: twipsToPx2(margins.right),
2026
+ bottom: twipsToPx2(margins.bottom),
2027
+ left: twipsToPx2(margins.left)
2028
+ };
2029
+ const width = gridWidth(start, span) ?? (cell.widthTwips ? twipsToPx2(cell.widthTwips) : void 0);
2030
+ const xPx = grid ? gridWidth(0, start) : void 0;
2031
+ const fill = cssHex(visuals.shadingFill);
2032
+ return {
2033
+ paragraphs: cell.paragraphs.map(adaptParagraph),
2034
+ ...width !== void 0 ? { widthPx: width } : {},
2035
+ ...grid && xPx !== void 0 ? { xPx } : {},
2036
+ padding,
2037
+ ...Object.keys(borders).length ? { borders } : {},
2038
+ ...fill ? { shading: fill } : {},
2039
+ // `both` (vertically justified) has no layout support yet and renders as top, as before.
2040
+ ...cell.verticalAlign ? { verticalAlign: cell.verticalAlign === "both" ? "top" : cell.verticalAlign } : {}
2041
+ };
2042
+ })
2043
+ }))
2044
+ };
2045
+ }
2046
+
2047
+ // src/docx/layout/adapt-drop-cap.ts
2048
+ function foldDropCaps(source, blocks) {
2049
+ const folded = /* @__PURE__ */ new Set();
2050
+ source.forEach((block, index) => {
2051
+ if (block.type !== "paragraph" || !block.dropCap) return;
2052
+ const cap = blocks[index];
2053
+ const next = blocks[index + 1];
2054
+ if (cap?.kind !== "paragraph" || next?.kind !== "paragraph") return;
2055
+ next.runs = [...cap.runs, ...next.runs];
2056
+ folded.add(cap);
2057
+ });
2058
+ return folded;
2059
+ }
2060
+
2061
+ // src/docx/layout/adapt-paragraph-box.ts
2062
+ var pointsToPx = (points) => points * 96 / 72;
2063
+ function paragraphBox(formatting, theme) {
2064
+ const borders = {};
2065
+ let betweenBorder;
2066
+ for (const side of ["top", "bottom", "left", "right", "between"]) {
2067
+ const source = formatting.borders?.[side];
2068
+ const line = border(source, theme);
2069
+ if (!line) continue;
2070
+ const resolved = { ...line, spacePx: pointsToPx(source?.spacePoints ?? 0) };
2071
+ if (side === "between") betweenBorder = resolved;
2072
+ else borders[side] = resolved;
2073
+ }
2074
+ const shading = cssHex(formatting.shadingFill);
2075
+ return {
2076
+ ...Object.keys(borders).length ? { borders } : {},
2077
+ ...shading ? { shading } : {},
2078
+ ...betweenBorder ? { betweenBorder } : {}
2079
+ };
2080
+ }
2081
+ function groupParagraphBorders(blocks, between) {
2082
+ const keys = blocks.map(
2083
+ (block) => block.kind === "paragraph" && block.borders ? JSON.stringify(block.borders) : void 0
2084
+ );
2085
+ blocks.forEach((block, index) => {
2086
+ if (block.kind !== "paragraph" || !block.borders) return;
2087
+ const sameAsPrevious = keys[index - 1] === keys[index];
2088
+ const sameAsNext = keys[index + 1] === keys[index];
2089
+ if (!sameAsPrevious && !sameAsNext) return;
2090
+ const borders = { ...block.borders };
2091
+ if (sameAsNext) delete borders.bottom;
2092
+ if (sameAsPrevious) {
2093
+ const line = between.get(block);
2094
+ if (line) borders.top = line;
2095
+ else delete borders.top;
2096
+ }
2097
+ block.borders = borders;
2098
+ });
2099
+ }
2100
+
2101
+ // src/docx/layout/adapt-notes.ts
2102
+ function noteLabels(model) {
2103
+ const order = {
2104
+ footnote: numberNotesInOrder(model.blocks, "footnote"),
2105
+ endnote: numberNotesInOrder(model.blocks, "endnote")
2106
+ };
2107
+ return (kind, id) => {
2108
+ const number = order[kind].get(id);
2109
+ if (number === void 0) return "";
2110
+ return formatNoteNumber(
2111
+ number,
2112
+ kind === "footnote" ? model.footnoteNumFmt ?? "decimal" : model.endnoteNumFmt ?? "lowerRoman"
2113
+ );
2114
+ };
2115
+ }
2116
+ function adaptNote(note, label, adaptParagraph) {
2117
+ return note.blocks.flatMap(
2118
+ (block) => block.type === "paragraph" ? [adaptParagraph(block, label)] : block.rows.flatMap(
2119
+ (row) => row.flatMap(
2120
+ (cell) => cell.paragraphs.map((paragraph) => adaptParagraph(paragraph, label))
2121
+ )
2122
+ )
2123
+ );
2124
+ }
2125
+ function paragraphFootnotes(paragraph, model, label, adaptParagraph) {
2126
+ const notes = [];
2127
+ for (const run of paragraph.runs) {
2128
+ const reference = run.noteReference;
2129
+ if (reference?.kind !== "footnote") continue;
2130
+ const note = model.footnotes?.find((item) => item.id === reference.id);
2131
+ if (note)
2132
+ notes.push({
2133
+ id: note.id,
2134
+ paragraphs: adaptNote(note, label("footnote", note.id), adaptParagraph)
2135
+ });
2136
+ }
2137
+ return notes;
2138
+ }
2139
+ function endnoteParagraphs(model, label, adaptParagraph) {
2140
+ const order = numberNotesInOrder(model.blocks, "endnote");
2141
+ return [...order.keys()].flatMap((id) => {
2142
+ const note = model.endnotes?.find((item) => item.id === id);
2143
+ return note ? adaptNote(note, label("endnote", id), adaptParagraph) : [];
2144
+ });
2145
+ }
2146
+
2147
+ // src/docx/layout/adapter.ts
2148
+ var TABLE_ROW_NOTE = "Table rows with an exact height clip content that does not fit; text in them is not shrunk.";
2149
+ var VERTICAL_MERGE_NOTE = "Vertically merged table cells are drawn as one cell, but their text stays in the first row of the merge.";
2150
+ var DROP_CAP_NOTE = "Drop caps are laid out as an enlarged first letter (a raised cap), not as a dropped cap.";
2151
+ var TEXT_BOX_NOTE = "Text boxes are shown on the editing surface but are not drawn in Print Layout.";
2152
+ var NEXT_COLUMN_NOTE = 'A "next column" section break is laid out as a continuous section break.';
2153
+ var twipsToPx3 = twipsToPixels;
2154
+ function sectionBreak(type, note) {
2155
+ if (type === "nextColumn") {
2156
+ note(NEXT_COLUMN_NOTE);
2157
+ return "continuous";
2158
+ }
2159
+ return type;
2160
+ }
2161
+ function adaptDocumentModel(model, note = () => {
2162
+ }) {
2163
+ const catalog = model.paragraphStyles;
2164
+ const noted = /* @__PURE__ */ new Set();
2165
+ const reportOnce = (message) => {
2166
+ if (!noted.has(message)) {
2167
+ noted.add(message);
2168
+ note(message);
2169
+ }
2170
+ };
2171
+ const now = /* @__PURE__ */ new Date();
2172
+ const theme = model.theme;
2173
+ function effective(run, paragraphStyleId) {
2174
+ const formatting = resolveRunFormatting(run, {
2175
+ runCatalog: model.characterStyles,
2176
+ paragraphCatalog: catalog,
2177
+ paragraphStyleId
2178
+ });
2179
+ const role = formatting.fontTheme?.ascii ?? formatting.fontTheme?.hAnsi;
2180
+ const family = formatting.fontFamily ?? (role && theme ? theme.fonts[role]?.latin : void 0);
2181
+ const color = formatting.color ?? (formatting.colorTheme && theme ? resolveThemeColorReference(formatting.colorTheme, theme) : void 0);
2182
+ return { formatting, family, color };
2183
+ }
2184
+ const noteLabel = noteLabels(model);
2185
+ function adaptRun(run, paragraphStyleId, markLabel) {
2186
+ const { formatting, family, color } = effective(run, paragraphStyleId);
2187
+ const name = run.field ? fieldName(run.field.instr) : "";
2188
+ const noteText = run.noteReference ? noteLabel(run.noteReference.kind, run.noteReference.id) : run.noteMark ? markLabel ?? "" : void 0;
2189
+ const text = noteText ?? (run.field && (name === "DATE" || name === "TIME") ? dateFieldResult(name, run.field.instr, now) : run.text);
2190
+ const script = formatting.verticalAlign === "superscript" || noteText !== void 0 && formatting.verticalAlign === void 0 ? "super" : formatting.verticalAlign === "subscript" ? "sub" : void 0;
2191
+ const image = run.image;
2192
+ if (image?.unsupported === "Text box") reportOnce(TEXT_BOX_NOTE);
2193
+ const object = image && !image.anchored ? {
2194
+ partName: image.partName,
2195
+ contentType: image.contentType,
2196
+ widthPx: image.widthPx,
2197
+ heightPx: image.heightPx
2198
+ } : void 0;
2199
+ return {
2200
+ // Hidden text (`w:vanish`) takes no space when printed, as in Word by default.
2201
+ text: image || formatting.vanish ? "" : formatting.caps ? text.toUpperCase() : text,
2202
+ ...object ? { object } : {},
2203
+ ...definedProps({
2204
+ bold: formatting.bold,
2205
+ italic: formatting.italic,
2206
+ fontFamily: family,
2207
+ fontSizePt: formatting.fontSize,
2208
+ textScalePercent: formatting.textScalePercent,
2209
+ ligatures: formatting.ligatures,
2210
+ characterSpacingPx: formatting.characterSpacingTwips === void 0 ? void 0 : formatting.characterSpacingTwips / 15,
2211
+ kerningThresholdPt: formatting.kerningHalfPoints === void 0 ? void 0 : formatting.kerningHalfPoints / 2,
2212
+ positionPx: formatting.positionHalfPoints === void 0 ? void 0 : formatting.positionHalfPoints * 2 / 3
2213
+ }),
2214
+ ...color && /^#[0-9a-f]{6}$/i.test(color) ? { color } : {},
2215
+ ...formatting.underline ? { underline: true } : {},
2216
+ ...formatting.strike || formatting.doubleStrike ? { strike: true } : {},
2217
+ ...run.break ? { breakAfter: run.break } : {},
2218
+ ...script ? { script } : {}
2219
+ };
2220
+ }
2221
+ const labels = computeListLabels(model);
2222
+ function labelRun(paragraph, label) {
2223
+ const first = adaptRun(paragraph.runs[0] ?? { text: "" }, paragraph.style);
2224
+ const marker = label.markerFormat;
2225
+ const suffix = label.suffix === "tab" ? " " : label.suffix === "space" ? " " : "";
2226
+ return {
2227
+ text: `${displayListLabel(label.text)}${suffix}`,
2228
+ synthetic: true,
2229
+ marker: { length: displayListLabel(label.text).length, alignment: label.alignment ?? "left" },
2230
+ ...definedProps({
2231
+ bold: marker?.bold ?? first.bold,
2232
+ italic: marker?.italic ?? first.italic,
2233
+ fontFamily: marker?.fontFamily ?? first.fontFamily,
2234
+ fontSizePt: marker?.fontSizeHalfPoints ? marker.fontSizeHalfPoints / 2 : first.fontSizePt
2235
+ }),
2236
+ ...marker?.color || first.color ? { color: marker?.color ?? first.color } : {}
2237
+ };
2238
+ }
2239
+ const betweenBorders = /* @__PURE__ */ new Map();
2240
+ function adaptParagraph(paragraph, markLabel) {
2241
+ const adapted = adaptParagraphOnly(paragraph, markLabel);
2242
+ const between = paragraphBox(
2243
+ catalog ? resolveParagraphFormatting(paragraph, catalog) : paragraph,
2244
+ model.theme
2245
+ ).betweenBorder;
2246
+ if (between) betweenBorders.set(adapted, between);
2247
+ return adapted;
2248
+ }
2249
+ function adaptParagraphOnly(paragraph, markLabel) {
2250
+ const resolved = catalog ? resolveParagraphFormatting(paragraph, catalog) : paragraph;
2251
+ const label = labels.get(paragraph.id);
2252
+ const ownFirstLine = resolved.firstLineTwips !== void 0 || resolved.hangingTwips !== void 0;
2253
+ const runs = paragraph.runs.map((run) => adaptRun(run, paragraph.style, markLabel));
2254
+ const footnotes = paragraphFootnotes(paragraph, model, noteLabel, adaptParagraph);
2255
+ const { betweenBorder: _between, ...box } = paragraphBox(resolved, model.theme);
2256
+ return {
2257
+ kind: "paragraph",
2258
+ id: paragraph.id,
2259
+ runs: label ? [labelRun(paragraph, label), ...runs] : runs,
2260
+ ...footnotes.length ? { footnotes } : {},
2261
+ ...box,
2262
+ ...paragraph.tabStops?.length || label?.tabStopTwips !== void 0 ? {
2263
+ tabStops: [
2264
+ ...(paragraph.tabStops ?? []).map((stop) => ({
2265
+ posPx: twipsToPx3(stop.posTwips),
2266
+ align: stop.align,
2267
+ ...stop.leader ? { leader: stop.leader } : {}
2268
+ })),
2269
+ ...label?.tabStopTwips !== void 0 ? [{ posPx: twipsToPx3(label.tabStopTwips), align: "left" }] : []
2270
+ ].sort((a, b) => a.posPx - b.posPx)
2271
+ } : {},
2272
+ ...floatsOf(paragraph),
2273
+ ...definedProps({
2274
+ align: resolved.align,
2275
+ direction: resolved.direction,
2276
+ spacingBeforeTwips: resolved.spacingBeforeTwips,
2277
+ spacingAfterTwips: resolved.spacingAfterTwips,
2278
+ lineSpacingTwips: resolved.lineSpacingTwips,
2279
+ lineSpacingRule: resolved.lineSpacingRule,
2280
+ indentLeftTwips: resolved.indentLeftTwips ?? label?.indentLeftTwips,
2281
+ indentRightTwips: resolved.indentRightTwips,
2282
+ indentStartTwips: resolved.indentStartTwips,
2283
+ indentEndTwips: resolved.indentEndTwips,
2284
+ firstLineTwips: ownFirstLine ? resolved.firstLineTwips : label?.firstLineTwips,
2285
+ hangingTwips: ownFirstLine ? resolved.hangingTwips : label?.hangingTwips,
2286
+ styleId: paragraph.style
2287
+ }),
2288
+ ...paragraph.pageBreakBefore ? { pageBreakBefore: true } : {},
2289
+ ...resolved.keepNext ? { keepNext: true } : {},
2290
+ ...resolved.keepLines ? { keepLines: true } : {},
2291
+ ...resolved.widowControl === false ? { widowControl: false } : {},
2292
+ ...resolved.contextualSpacing ? { contextualSpacing: true } : {}
2293
+ };
2294
+ }
2295
+ function adaptBlock(block) {
2296
+ if (block.type === "paragraph") return adaptParagraph(block);
2297
+ reportOnce(TABLE_ROW_NOTE);
2298
+ reportOnce(VERTICAL_MERGE_NOTE);
2299
+ return adaptTable(block, model, adaptParagraph);
2300
+ }
2301
+ const blocks = [
2302
+ ...model.blocks.map(adaptBlock),
2303
+ ...endnoteParagraphs(model, noteLabel, adaptParagraph)
2304
+ ];
2305
+ groupParagraphBorders(blocks, betweenBorders);
2306
+ const folded = foldDropCaps(model.blocks, blocks);
2307
+ if (folded.size) reportOnce(DROP_CAP_NOTE);
2308
+ const sections = model.sections;
2309
+ if (!sections || !sections.length) {
2310
+ return {
2311
+ sections: [
2312
+ {
2313
+ page: {
2314
+ widthPx: model.page.width,
2315
+ heightPx: model.page.height,
2316
+ marginTopPx: model.page.marginTop,
2317
+ marginRightPx: model.page.marginRight,
2318
+ marginBottomPx: model.page.marginBottom,
2319
+ marginLeftPx: model.page.marginLeft
2320
+ },
2321
+ blocks: blocks.filter((block) => !folded.has(block))
2322
+ }
2323
+ ]
2324
+ };
2325
+ }
2326
+ const indexById = new Map(model.blocks.map((block, index) => [block.id, index]));
2327
+ let start = 0;
2328
+ const result = sections.map((section, index) => {
2329
+ const last = index === sections.length - 1;
2330
+ const endIndex = last ? blocks.length : (indexById.get(section.endsAtBlockId) ?? start - 1) + 1;
2331
+ const end = Math.max(start, endIndex);
2332
+ const slice = blocks.slice(start, end);
2333
+ start = end;
2334
+ const sectionStart = index === 0 ? void 0 : sectionBreak(section.type, reportOnce);
2335
+ return {
2336
+ page: {
2337
+ widthPx: twipsToPx3(section.pageWidthTwips),
2338
+ heightPx: twipsToPx3(section.pageHeightTwips),
2339
+ marginTopPx: twipsToPx3(section.marginTopTwips),
2340
+ marginRightPx: twipsToPx3(section.marginRightTwips),
2341
+ marginBottomPx: twipsToPx3(section.marginBottomTwips),
2342
+ marginLeftPx: twipsToPx3(section.marginLeftTwips)
2343
+ },
2344
+ ...section.columns.count > 1 ? {
2345
+ columns: {
2346
+ count: section.columns.count,
2347
+ gapPx: twipsToPx3(section.columns.spacingTwips ?? twips(720)),
2348
+ ...section.columns.separator ? { separator: true } : {},
2349
+ ...!section.columns.equalWidth && section.columns.widths?.length ? {
2350
+ widths: section.columns.widths.map((column) => ({
2351
+ widthPx: twipsToPx3(column.widthTwips),
2352
+ gapPx: twipsToPx3(
2353
+ column.spacingTwips ?? section.columns.spacingTwips ?? twips(720)
2354
+ )
2355
+ }))
2356
+ } : {}
2357
+ }
2358
+ } : {},
2359
+ ...sectionStart && { break: sectionStart },
2360
+ ...section.verticalAlign ? { verticalAlign: section.verticalAlign } : {},
2361
+ blocks: slice.filter((block) => !folded.has(block))
2362
+ };
2363
+ });
2364
+ return { sections: result };
2365
+ }
2366
+
2367
+ // src/docx/layout/floats.ts
2368
+ var FLOAT_WRAP_NOTE = "Text wraps around floating pictures on their largest side (square, tight and through wrapping use the picture\u2019s rectangle, not its outline); lines continuing onto a later page keep their wrapped widths.";
2369
+ function horizontalArea(float, page, column) {
2370
+ const contentLeft = page.marginLeftPx;
2371
+ switch (float.relativeFromH) {
2372
+ case "page":
2373
+ return { start: 0, size: page.widthPx };
2374
+ case "margin":
2375
+ return { start: contentLeft, size: page.widthPx - contentLeft - page.marginRightPx };
2376
+ case "leftMargin":
2377
+ case "insideMargin":
2378
+ return { start: 0, size: contentLeft };
2379
+ case "rightMargin":
2380
+ case "outsideMargin":
2381
+ return { start: page.widthPx - page.marginRightPx, size: page.marginRightPx };
2382
+ default:
2383
+ return { start: contentLeft + column.xPx, size: column.widthPx };
2384
+ }
2385
+ }
2386
+ function verticalArea(float, page, paragraphTopPx, paragraphHeightPx) {
2387
+ switch (float.relativeFromV) {
2388
+ case "page":
2389
+ return { start: 0, size: page.heightPx };
2390
+ case "margin":
2391
+ return {
2392
+ start: page.marginTopPx,
2393
+ size: page.heightPx - page.marginTopPx - page.marginBottomPx
2394
+ };
2395
+ case "topMargin":
2396
+ case "insideMargin":
2397
+ return { start: 0, size: page.marginTopPx };
2398
+ case "bottomMargin":
2399
+ case "outsideMargin":
2400
+ return { start: page.heightPx - page.marginBottomPx, size: page.marginBottomPx };
2401
+ default:
2402
+ return { start: paragraphTopPx, size: paragraphHeightPx };
2403
+ }
2404
+ }
2405
+ function place(area, size, align, offset) {
2406
+ if (align === "center") return area.start + (area.size - size) / 2;
2407
+ if (align === "right" || align === "bottom" || align === "outside")
2408
+ return area.start + area.size - size;
2409
+ if (align) return area.start;
2410
+ return area.start + (offset ?? 0);
2411
+ }
2412
+ function floatPosition(float, page, column, paragraph) {
2413
+ const h = horizontalArea(float, page, column);
2414
+ const v = verticalArea(float, page, paragraph.topPx, paragraph.heightPx);
2415
+ return {
2416
+ xPx: place(h, float.widthPx, float.alignH, float.offsetXPx),
2417
+ yPx: place(v, float.heightPx, float.alignV, float.offsetYPx)
2418
+ };
2419
+ }
2420
+ function positionFloats(input, pages) {
2421
+ const floatsById = /* @__PURE__ */ new Map();
2422
+ for (const section of input.sections)
2423
+ for (const block of section.blocks)
2424
+ if (block.kind === "paragraph" && block.floats?.length)
2425
+ floatsById.set(block.id, block.floats);
2426
+ if (!floatsById.size) return false;
2427
+ const placed = /* @__PURE__ */ new Set();
2428
+ for (const page of pages) {
2429
+ const boxes = [];
2430
+ for (const column of page.columns)
2431
+ for (const block of column.blocks) {
2432
+ const floats = block.kind === "paragraph" ? floatsById.get(block.blockId) : void 0;
2433
+ if (!floats || placed.has(block.blockId)) continue;
2434
+ placed.add(block.blockId);
2435
+ const top = page.marginTopPx + block.yPx;
2436
+ for (const float of floats) {
2437
+ const position = floatPosition(float, page, column, {
2438
+ topPx: top,
2439
+ heightPx: block.heightPx
2440
+ });
2441
+ boxes.push({
2442
+ blockId: block.blockId,
2443
+ ...position,
2444
+ widthPx: float.widthPx,
2445
+ heightPx: float.heightPx,
2446
+ partName: float.partName,
2447
+ contentType: float.contentType,
2448
+ behindText: Boolean(float.behindText),
2449
+ ...float.wrap ? { wrap: float.wrap } : {}
2450
+ });
2451
+ }
2452
+ }
2453
+ if (boxes.length) page.floats = boxes;
2454
+ }
2455
+ return true;
2456
+ }
2457
+
2458
+ // src/docx/layout/layout.ts
2459
+ function layoutDocument(input, measurer) {
2460
+ let result = layoutSections(input, measurer);
2461
+ if (!positionFloats(input, result.pages)) return result;
2462
+ let exclusions = wrapExclusions(result.pages);
2463
+ for (let pass = 0; exclusions.size && pass < 3; pass++) {
2464
+ result = layoutSections(input, measurer, exclusions);
2465
+ positionFloats(input, result.pages);
2466
+ const next = wrapExclusions(result.pages);
2467
+ if (sameExclusions(next, exclusions)) break;
2468
+ exclusions = next;
2469
+ }
2470
+ return { ...result, approximations: [.../* @__PURE__ */ new Set([...result.approximations, FLOAT_WRAP_NOTE])] };
2471
+ }
2472
+ function layoutDocumentModel(model, measurer) {
2473
+ const approximations = [];
2474
+ const input = adaptDocumentModel(model, (message) => approximations.push(message));
2475
+ const result = layoutDocument(input, measurer);
2476
+ return {
2477
+ pages: result.pages,
2478
+ approximations: [.../* @__PURE__ */ new Set([...approximations, ...result.approximations])]
2479
+ };
2480
+ }
2481
+
2482
+ // src/docx/layout/fonts.ts
2483
+ var SUBSTITUTES = {
2484
+ calibri: { fallbacks: ["Carlito"], generic: "sans-serif" },
2485
+ "calibri light": { fallbacks: ["Carlito"], generic: "sans-serif" },
2486
+ cambria: { fallbacks: ["Caladea"], generic: "serif" },
2487
+ arial: { fallbacks: ["Arimo", "Liberation Sans"], generic: "sans-serif" },
2488
+ helvetica: { fallbacks: ["Arimo", "Liberation Sans"], generic: "sans-serif" },
2489
+ "times new roman": { fallbacks: ["Tinos", "Liberation Serif"], generic: "serif" },
2490
+ times: { fallbacks: ["Tinos", "Liberation Serif"], generic: "serif" },
2491
+ "courier new": { fallbacks: ["Cousine", "Liberation Mono"], generic: "monospace" },
2492
+ courier: { fallbacks: ["Cousine", "Liberation Mono"], generic: "monospace" },
2493
+ georgia: { fallbacks: ["Gelasio"], generic: "serif" },
2494
+ consolas: { fallbacks: ["Inconsolata"], generic: "monospace" }
2495
+ };
2496
+ var quote = (family) => `"${family.replace(/["\\]/g, "")}"`;
2497
+ function cssFontStack(family) {
2498
+ const name = family?.trim() || DEFAULT_FONT_FAMILY;
2499
+ const known = SUBSTITUTES[name.toLowerCase()];
2500
+ return [quote(name), ...(known?.fallbacks ?? []).map(quote), known?.generic ?? "sans-serif"].join(
2501
+ ", "
2502
+ );
2503
+ }
2504
+
2505
+ exports.DEFAULT_FONT_FAMILY = DEFAULT_FONT_FAMILY;
2506
+ exports.DEFAULT_FONT_SIZE_PT = DEFAULT_FONT_SIZE_PT;
2507
+ exports.DEFAULT_TAB_STOP_PX = DEFAULT_TAB_STOP_PX;
2508
+ exports.FLOAT_WRAP_NOTE = FLOAT_WRAP_NOTE;
2509
+ exports.NO_TWIPS = NO_TWIPS;
2510
+ exports.PageCursor = PageCursor;
2511
+ exports.SINGLE_LINE_SPACING_UNITS = SINGLE_LINE_SPACING_UNITS;
2512
+ exports.adaptDocumentModel = adaptDocumentModel;
2513
+ exports.adjustForWidowOrphan = adjustForWidowOrphan;
2514
+ exports.appendBreakMarker = appendBreakMarker;
2515
+ exports.createFakeMeasurer = createFakeMeasurer;
2516
+ exports.cssFontStack = cssFontStack;
2517
+ exports.floatPosition = floatPosition;
2518
+ exports.fontMetrics = fontMetrics;
2519
+ exports.isEastAsianChar = isEastAsianChar;
2520
+ exports.layoutDocument = layoutDocument;
2521
+ exports.layoutDocumentModel = layoutDocumentModel;
2522
+ exports.layoutParagraph = layoutParagraph;
2523
+ exports.layoutRow = layoutRow;
2524
+ exports.layoutSections = layoutSections;
2525
+ exports.ligatureCss = ligatureCss;
2526
+ exports.paragraphFloats = paragraphFloats;
2527
+ exports.placeParagraph = placeParagraph;
2528
+ exports.placeTab = placeTab;
2529
+ exports.placeTable = placeTable;
2530
+ exports.positionFloats = positionFloats;
2531
+ exports.ptToPx = ptToPx;
2532
+ exports.pxToTwips = pxToTwips;
2533
+ exports.splitRowAtHeight = splitRowAtHeight;
2534
+ exports.suppressesSpacing = suppressesSpacing;
2535
+ exports.tokenizeRun = tokenizeRun;
2536
+ exports.twipsToPx = twipsToPx;
2537
+ exports.widowControlEnabled = widowControlEnabled;