@cj-tech-master/excelts 9.5.4 → 9.5.5

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 (767) hide show
  1. package/dist/browser/modules/archive/compression/streaming-compress.browser.js +29 -0
  2. package/dist/browser/modules/archive/compression/streaming-compress.js +9 -0
  3. package/dist/browser/modules/archive/compression/worker-pool/pool.browser.js +26 -1
  4. package/dist/browser/modules/archive/fs/archive-file.d.ts +8 -5
  5. package/dist/browser/modules/archive/fs/archive-file.js +78 -16
  6. package/dist/browser/modules/archive/unzip/stream.browser.js +43 -2
  7. package/dist/browser/modules/excel/chart/chart-ex-builder.js +7 -2
  8. package/dist/browser/modules/excel/chart/chart-ex-renderer.js +4 -9
  9. package/dist/browser/modules/excel/chart/chart-ex-types.d.ts +0 -12
  10. package/dist/browser/modules/excel/chart/chart.d.ts +1 -5
  11. package/dist/browser/modules/excel/chart/chart.js +1 -7
  12. package/dist/browser/modules/excel/chart/types.d.ts +0 -6
  13. package/dist/browser/modules/excel/stream/workbook-reader.browser.js +25 -1
  14. package/dist/browser/modules/excel/stream/workbook-reader.js +9 -0
  15. package/dist/browser/modules/excel/stream/workbook-writer.browser.d.ts +40 -0
  16. package/dist/browser/modules/excel/stream/workbook-writer.browser.js +228 -13
  17. package/dist/browser/modules/excel/utils/string-buf.d.ts +5 -26
  18. package/dist/browser/modules/excel/utils/string-buf.js +4 -81
  19. package/dist/browser/modules/excel/workbook.browser.js +135 -25
  20. package/dist/browser/modules/excel/xlsx/xform/chart/chart-space-xform.js +6 -20
  21. package/dist/browser/modules/excel/xlsx/xlsx.browser.d.ts +19 -9
  22. package/dist/browser/modules/excel/xlsx/xlsx.browser.js +32 -8
  23. package/dist/browser/modules/excel/xlsx/xlsx.d.ts +10 -2
  24. package/dist/browser/modules/excel/xlsx/xlsx.js +9 -1
  25. package/dist/browser/modules/pdf/excel-bridge.d.ts +30 -1
  26. package/dist/browser/modules/pdf/excel-bridge.js +32 -0
  27. package/dist/browser/modules/pdf/font/metrics.d.ts +3 -52
  28. package/dist/browser/modules/pdf/font/metrics.js +3 -237
  29. package/dist/browser/modules/pdf/index.d.ts +1 -1
  30. package/dist/browser/modules/pdf/index.js +1 -1
  31. package/dist/browser/modules/pdf/render-layout-to-pdf.d.ts +66 -0
  32. package/dist/browser/modules/pdf/render-layout-to-pdf.js +647 -0
  33. package/dist/browser/modules/pdf/word-bridge.d.ts +80 -12
  34. package/dist/browser/modules/pdf/word-bridge.js +122 -274
  35. package/dist/browser/modules/stream/index.base.d.ts +2 -0
  36. package/dist/browser/modules/stream/index.base.js +2 -1
  37. package/dist/browser/modules/stream/internal/sink-adapter.d.ts +65 -0
  38. package/dist/browser/modules/stream/internal/sink-adapter.js +198 -0
  39. package/dist/browser/modules/stream/pull-stream.d.ts +19 -2
  40. package/dist/browser/modules/stream/pull-stream.js +51 -5
  41. package/dist/browser/modules/stream/types.d.ts +13 -1
  42. package/dist/browser/modules/word/advanced/diff.d.ts +61 -0
  43. package/dist/browser/modules/word/advanced/diff.js +167 -0
  44. package/dist/browser/modules/word/advanced/drawing-shapes.d.ts +269 -0
  45. package/dist/browser/modules/word/advanced/drawing-shapes.js +268 -0
  46. package/dist/browser/modules/word/advanced/field-engine.d.ts +43 -0
  47. package/dist/browser/modules/word/advanced/field-engine.js +1225 -0
  48. package/dist/browser/modules/word/advanced/glossary.d.ts +86 -0
  49. package/dist/browser/modules/word/advanced/glossary.js +79 -0
  50. package/dist/browser/modules/word/advanced/math-convert.d.ts +30 -0
  51. package/dist/browser/modules/word/advanced/math-convert.js +595 -0
  52. package/dist/browser/modules/word/advanced/ole-objects.d.ts +115 -0
  53. package/dist/browser/modules/word/advanced/ole-objects.js +271 -0
  54. package/dist/browser/modules/word/advanced/style-map.d.ts +105 -0
  55. package/dist/browser/modules/word/advanced/style-map.js +322 -0
  56. package/dist/browser/modules/word/advanced/validation.d.ts +56 -0
  57. package/dist/browser/modules/word/advanced/validation.js +1065 -0
  58. package/dist/browser/modules/word/advanced/vba-project.d.ts +91 -0
  59. package/dist/browser/modules/word/advanced/vba-project.js +265 -0
  60. package/dist/browser/modules/word/bridge/excel-bridge.d.ts +127 -0
  61. package/dist/browser/modules/word/bridge/excel-bridge.js +980 -0
  62. package/dist/browser/modules/word/builder/document-handle.d.ts +151 -0
  63. package/dist/browser/modules/word/builder/document-handle.js +664 -0
  64. package/dist/browser/modules/word/builder/paragraph-builders.d.ts +61 -0
  65. package/dist/browser/modules/word/builder/paragraph-builders.js +90 -0
  66. package/dist/browser/modules/word/builder/run-builders.d.ts +374 -0
  67. package/dist/browser/modules/word/builder/run-builders.js +600 -0
  68. package/dist/browser/modules/word/builder/table-builders.d.ts +23 -0
  69. package/dist/browser/modules/word/builder/table-builders.js +45 -0
  70. package/dist/browser/modules/word/constants.d.ts +39 -1
  71. package/dist/browser/modules/word/constants.js +109 -1
  72. package/dist/browser/modules/word/convert/conversion-ir.d.ts +210 -0
  73. package/dist/browser/modules/word/convert/conversion-ir.js +31 -0
  74. package/dist/browser/modules/word/convert/docx-to-semantic.d.ts +39 -0
  75. package/dist/browser/modules/word/convert/docx-to-semantic.js +499 -0
  76. package/dist/browser/modules/word/convert/flat-opc.d.ts +44 -0
  77. package/dist/browser/modules/word/convert/flat-opc.js +385 -0
  78. package/dist/browser/modules/word/convert/html/html-import.d.ts +50 -0
  79. package/dist/browser/modules/word/convert/html/html-import.js +1907 -0
  80. package/dist/{types/modules/word → browser/modules/word/convert/html}/html-renderer.d.ts +14 -1
  81. package/dist/{esm/modules/word → browser/modules/word/convert/html}/html-renderer.js +420 -69
  82. package/dist/browser/modules/word/convert/html/html.d.ts +15 -0
  83. package/dist/browser/modules/word/convert/html/html.js +15 -0
  84. package/dist/browser/modules/word/convert/markdown/markdown-import.d.ts +68 -0
  85. package/dist/browser/modules/word/convert/markdown/markdown-import.js +1325 -0
  86. package/dist/browser/modules/word/convert/markdown/markdown-renderer.d.ts +25 -0
  87. package/dist/browser/modules/word/convert/markdown/markdown-renderer.js +634 -0
  88. package/dist/browser/modules/word/convert/markdown/markdown.d.ts +15 -0
  89. package/dist/browser/modules/word/convert/markdown/markdown.js +15 -0
  90. package/dist/browser/modules/word/convert/odt/odt.d.ts +41 -0
  91. package/dist/browser/modules/word/convert/odt/odt.js +1932 -0
  92. package/dist/browser/modules/word/{color-utils.d.ts → core/color-utils.d.ts} +8 -1
  93. package/dist/browser/modules/word/core/color-utils.js +43 -0
  94. package/dist/browser/modules/word/core/internal-utils.d.ts +90 -0
  95. package/dist/browser/modules/word/core/internal-utils.js +209 -0
  96. package/dist/browser/modules/word/core/mapper.d.ts +44 -0
  97. package/dist/browser/modules/word/core/mapper.js +427 -0
  98. package/dist/browser/modules/word/core/opc-paths.d.ts +33 -0
  99. package/dist/browser/modules/word/core/opc-paths.js +48 -0
  100. package/dist/browser/modules/word/core/text-utils.d.ts +38 -0
  101. package/dist/browser/modules/word/core/text-utils.js +202 -0
  102. package/dist/browser/modules/word/core/walker.d.ts +119 -0
  103. package/dist/browser/modules/word/core/walker.js +570 -0
  104. package/dist/browser/modules/word/crypto.d.ts +14 -9
  105. package/dist/browser/modules/word/crypto.js +13 -7
  106. package/dist/browser/modules/word/document-io.d.ts +59 -27
  107. package/dist/browser/modules/word/document-io.js +80 -197
  108. package/dist/browser/modules/word/errors.d.ts +44 -1
  109. package/dist/browser/modules/word/errors.js +54 -2
  110. package/dist/browser/modules/word/excel.d.ts +14 -0
  111. package/dist/browser/modules/word/excel.js +13 -0
  112. package/dist/browser/modules/word/font/font-embed.d.ts +112 -0
  113. package/dist/browser/modules/word/font/font-embed.js +646 -0
  114. package/dist/{esm/modules/word → browser/modules/word/font}/font-obfuscation.js +4 -9
  115. package/dist/browser/modules/word/font/hyphenation.d.ts +65 -0
  116. package/dist/browser/modules/word/font/hyphenation.js +4210 -0
  117. package/dist/browser/modules/word/font/text-shaping.d.ts +58 -0
  118. package/dist/browser/modules/word/font/text-shaping.js +635 -0
  119. package/dist/browser/modules/word/html.d.ts +7 -6
  120. package/dist/browser/modules/word/html.js +6 -5
  121. package/dist/browser/modules/word/incremental-edit.d.ts +123 -0
  122. package/dist/browser/modules/word/incremental-edit.js +361 -0
  123. package/dist/browser/modules/word/index.base.d.ts +194 -10
  124. package/dist/browser/modules/word/index.base.js +138 -29
  125. package/dist/browser/modules/word/layout/layout-constants.d.ts +17 -0
  126. package/dist/browser/modules/word/layout/layout-constants.js +17 -0
  127. package/dist/browser/modules/word/layout/layout-full.d.ts +53 -0
  128. package/dist/browser/modules/word/layout/layout-full.js +1696 -0
  129. package/dist/browser/modules/word/layout/layout-model.d.ts +344 -0
  130. package/dist/browser/modules/word/layout/layout-model.js +16 -0
  131. package/dist/browser/modules/word/layout/layout.d.ts +63 -0
  132. package/dist/browser/modules/word/layout/layout.js +1167 -0
  133. package/dist/browser/modules/word/layout/render-page.d.ts +57 -0
  134. package/dist/browser/modules/word/layout/render-page.js +1238 -0
  135. package/dist/browser/modules/word/markdown.d.ts +14 -0
  136. package/dist/browser/modules/word/markdown.js +13 -0
  137. package/dist/browser/modules/word/patcher.d.ts +62 -0
  138. package/dist/browser/modules/word/patcher.js +537 -0
  139. package/dist/browser/modules/word/query/compat.d.ts +25 -0
  140. package/dist/browser/modules/word/query/compat.js +58 -0
  141. package/dist/browser/modules/word/query/data-binding.d.ts +22 -0
  142. package/dist/browser/modules/word/query/data-binding.js +392 -0
  143. package/dist/browser/modules/word/query/form-fields.d.ts +41 -0
  144. package/dist/browser/modules/word/query/form-fields.js +268 -0
  145. package/dist/browser/modules/word/query/format-search.d.ts +99 -0
  146. package/dist/browser/modules/word/query/format-search.js +329 -0
  147. package/dist/browser/modules/word/query/mail-merge.d.ts +25 -0
  148. package/dist/browser/modules/word/query/mail-merge.js +111 -0
  149. package/dist/browser/modules/word/query/merge.d.ts +50 -0
  150. package/dist/browser/modules/word/query/merge.js +617 -0
  151. package/dist/browser/modules/word/query/replace.d.ts +47 -0
  152. package/dist/browser/modules/word/query/replace.js +301 -0
  153. package/dist/browser/modules/word/query/revisions.d.ts +67 -0
  154. package/dist/browser/modules/word/query/revisions.js +879 -0
  155. package/dist/browser/modules/word/query/search.d.ts +129 -0
  156. package/dist/browser/modules/word/query/search.js +346 -0
  157. package/dist/browser/modules/word/query/split.d.ts +44 -0
  158. package/dist/browser/modules/word/query/split.js +135 -0
  159. package/dist/browser/modules/word/query/style-resolve.d.ts +104 -0
  160. package/dist/browser/modules/word/query/style-resolve.js +368 -0
  161. package/dist/browser/modules/word/reader/chart-parser.d.ts +20 -0
  162. package/dist/browser/modules/word/reader/chart-parser.js +810 -0
  163. package/dist/browser/modules/word/reader/comments-parser.d.ts +26 -0
  164. package/dist/browser/modules/word/reader/comments-parser.js +92 -0
  165. package/dist/browser/modules/word/reader/doc-props-parsers.d.ts +15 -0
  166. package/dist/browser/modules/word/reader/doc-props-parsers.js +190 -0
  167. package/dist/browser/modules/word/reader/docx-reader.d.ts +27 -0
  168. package/dist/browser/modules/word/reader/docx-reader.js +2557 -0
  169. package/dist/browser/modules/word/reader/drawing-helpers.d.ts +27 -0
  170. package/dist/browser/modules/word/reader/drawing-helpers.js +84 -0
  171. package/dist/browser/modules/word/reader/form-field-parser.d.ts +21 -0
  172. package/dist/browser/modules/word/reader/form-field-parser.js +82 -0
  173. package/dist/browser/modules/word/reader/image-parsers.d.ts +11 -0
  174. package/dist/browser/modules/word/reader/image-parsers.js +291 -0
  175. package/dist/browser/modules/word/reader/math-parser.d.ts +12 -0
  176. package/dist/browser/modules/word/reader/math-parser.js +422 -0
  177. package/dist/browser/modules/word/reader/metadata-parsers.d.ts +17 -0
  178. package/dist/browser/modules/word/reader/metadata-parsers.js +87 -0
  179. package/dist/browser/modules/word/reader/numbering-parser.d.ts +13 -0
  180. package/dist/browser/modules/word/reader/numbering-parser.js +166 -0
  181. package/dist/browser/modules/word/reader/paragraph-section-parsers.d.ts +12 -0
  182. package/dist/browser/modules/word/reader/paragraph-section-parsers.js +503 -0
  183. package/dist/browser/modules/word/reader/parse-utils.d.ts +91 -0
  184. package/dist/browser/modules/word/reader/parse-utils.js +249 -0
  185. package/dist/browser/modules/word/reader/properties-parsers.d.ts +21 -0
  186. package/dist/browser/modules/word/reader/properties-parsers.js +332 -0
  187. package/dist/browser/modules/word/reader/reader-context.d.ts +69 -0
  188. package/dist/browser/modules/word/reader/reader-context.js +61 -0
  189. package/dist/browser/modules/word/reader/sdt-helpers.d.ts +29 -0
  190. package/dist/browser/modules/word/reader/sdt-helpers.js +111 -0
  191. package/dist/browser/modules/word/reader/settings-parser.d.ts +8 -0
  192. package/dist/browser/modules/word/reader/settings-parser.js +263 -0
  193. package/dist/browser/modules/word/reader/styles-parser.d.ts +12 -0
  194. package/dist/browser/modules/word/reader/styles-parser.js +147 -0
  195. package/dist/browser/modules/word/reader/table-properties-parsers.d.ts +12 -0
  196. package/dist/browser/modules/word/reader/table-properties-parsers.js +234 -0
  197. package/dist/browser/modules/word/reader/theme-parser.d.ts +8 -0
  198. package/dist/browser/modules/word/reader/theme-parser.js +167 -0
  199. package/dist/browser/modules/word/reader/watermark-parser.d.ts +15 -0
  200. package/dist/browser/modules/word/reader/watermark-parser.js +110 -0
  201. package/dist/browser/modules/word/security/cfb-reader.d.ts +37 -0
  202. package/dist/browser/modules/word/security/cfb-reader.js +410 -0
  203. package/dist/browser/modules/word/{digital-signatures.d.ts → security/digital-signatures.d.ts} +19 -11
  204. package/dist/browser/modules/word/{digital-signatures.js → security/digital-signatures.js} +34 -34
  205. package/dist/browser/modules/word/security/document-protection.d.ts +93 -0
  206. package/dist/browser/modules/word/security/document-protection.js +201 -0
  207. package/dist/{types/modules/word → browser/modules/word/security}/encryption.d.ts +51 -4
  208. package/dist/browser/modules/word/security/encryption.js +602 -0
  209. package/dist/browser/modules/word/security/policy.d.ts +80 -0
  210. package/dist/browser/modules/word/security/policy.js +102 -0
  211. package/dist/browser/modules/word/template/template-chart.d.ts +56 -0
  212. package/dist/browser/modules/word/template/template-chart.js +167 -0
  213. package/dist/browser/modules/word/template/template-datasource.d.ts +154 -0
  214. package/dist/browser/modules/word/template/template-datasource.js +541 -0
  215. package/dist/browser/modules/word/template/template-engine.d.ts +121 -0
  216. package/dist/browser/modules/word/template/template-engine.js +1435 -0
  217. package/dist/browser/modules/word/types.d.ts +224 -25
  218. package/dist/browser/modules/word/units.d.ts +26 -0
  219. package/dist/browser/modules/word/units.js +43 -14
  220. package/dist/browser/modules/word/{writers → writer}/chart-writer.js +164 -23
  221. package/dist/browser/modules/word/writer/checkbox-writer.d.ts +17 -0
  222. package/dist/browser/modules/word/writer/checkbox-writer.js +79 -0
  223. package/dist/{types/modules/word/writers → browser/modules/word/writer}/comment-writer.d.ts +2 -1
  224. package/dist/browser/modules/word/{writers → writer}/comment-writer.js +8 -6
  225. package/dist/browser/modules/word/writer/common-parts.d.ts +57 -0
  226. package/dist/browser/modules/word/writer/common-parts.js +101 -0
  227. package/dist/{types/modules/word → browser/modules/word/writer}/content-types.d.ts +2 -2
  228. package/dist/{esm/modules/word → browser/modules/word/writer}/content-types.js +14 -6
  229. package/dist/browser/modules/word/writer/document-writer.d.ts +24 -0
  230. package/dist/browser/modules/word/writer/document-writer.js +473 -0
  231. package/dist/browser/modules/word/writer/docx-packager.d.ts +35 -0
  232. package/dist/browser/modules/word/writer/docx-packager.js +1515 -0
  233. package/dist/{types/modules/word/writers → browser/modules/word/writer}/footnote-writer.d.ts +3 -2
  234. package/dist/{esm/modules/word/writers → browser/modules/word/writer}/footnote-writer.js +13 -10
  235. package/dist/{types/modules/word/writers → browser/modules/word/writer}/header-footer-writer.d.ts +3 -2
  236. package/dist/{esm/modules/word/writers → browser/modules/word/writer}/header-footer-writer.js +39 -21
  237. package/dist/{types/modules/word/writers → browser/modules/word/writer}/image-writer.d.ts +1 -1
  238. package/dist/browser/modules/word/{writers → writer}/image-writer.js +11 -7
  239. package/dist/browser/modules/word/writer/math-writer.d.ts +20 -0
  240. package/dist/{esm/modules/word/writers → browser/modules/word/writer}/math-writer.js +21 -1
  241. package/dist/browser/modules/word/{writers → writer}/numbering-writer.d.ts +1 -1
  242. package/dist/{esm/modules/word/writers → browser/modules/word/writer}/numbering-writer.js +11 -4
  243. package/dist/browser/modules/word/{writers → writer}/paragraph-writer.d.ts +2 -1
  244. package/dist/browser/modules/word/{writers → writer}/paragraph-writer.js +73 -38
  245. package/dist/browser/modules/word/{writers → writer}/parts-writer.d.ts +3 -3
  246. package/dist/{esm/modules/word/writers → browser/modules/word/writer}/parts-writer.js +91 -12
  247. package/dist/browser/modules/word/writer/reference-scanners.d.ts +42 -0
  248. package/dist/browser/modules/word/writer/reference-scanners.js +111 -0
  249. package/dist/browser/modules/word/writer/relationships.d.ts +52 -0
  250. package/dist/browser/modules/word/writer/relationships.js +117 -0
  251. package/dist/browser/modules/word/writer/render-context.d.ts +124 -0
  252. package/dist/browser/modules/word/writer/render-context.js +46 -0
  253. package/dist/browser/modules/word/{writers → writer}/run-writer.d.ts +10 -1
  254. package/dist/{esm/modules/word/writers → browser/modules/word/writer}/run-writer.js +126 -24
  255. package/dist/browser/modules/word/writer/sdt-writer.d.ts +25 -0
  256. package/dist/browser/modules/word/writer/sdt-writer.js +189 -0
  257. package/dist/browser/modules/word/writer/stream-buf.d.ts +37 -0
  258. package/dist/browser/modules/word/writer/stream-buf.js +73 -0
  259. package/dist/browser/modules/word/writer/streaming-writer.d.ts +344 -0
  260. package/dist/browser/modules/word/writer/streaming-writer.js +1382 -0
  261. package/dist/browser/modules/word/writer/string-buf.d.ts +8 -0
  262. package/dist/browser/modules/word/writer/string-buf.js +7 -0
  263. package/dist/browser/modules/word/{writers → writer}/styles-writer.js +32 -1
  264. package/dist/browser/modules/word/{writers → writer}/table-writer.d.ts +2 -1
  265. package/dist/browser/modules/word/{writers → writer}/table-writer.js +94 -11
  266. package/dist/browser/modules/xml/types.d.ts +22 -0
  267. package/dist/browser/utils/crypto.browser.d.ts +3 -1
  268. package/dist/browser/utils/crypto.browser.js +3 -1
  269. package/dist/browser/utils/crypto.d.ts +4 -1
  270. package/dist/browser/utils/crypto.js +4 -1
  271. package/dist/browser/utils/font-metrics.d.ts +63 -0
  272. package/dist/browser/utils/font-metrics.js +293 -0
  273. package/dist/browser/utils/string-buf.d.ts +42 -0
  274. package/dist/browser/utils/string-buf.js +89 -0
  275. package/dist/browser/utils/theme-colors.d.ts +55 -0
  276. package/dist/browser/utils/theme-colors.js +120 -0
  277. package/dist/cjs/modules/archive/compression/streaming-compress.browser.js +29 -0
  278. package/dist/cjs/modules/archive/compression/streaming-compress.js +9 -0
  279. package/dist/cjs/modules/archive/compression/worker-pool/pool.browser.js +26 -1
  280. package/dist/cjs/modules/archive/fs/archive-file.js +78 -16
  281. package/dist/cjs/modules/archive/unzip/stream.browser.js +43 -2
  282. package/dist/cjs/modules/excel/chart/chart-ex-builder.js +7 -2
  283. package/dist/cjs/modules/excel/chart/chart-ex-renderer.js +4 -9
  284. package/dist/cjs/modules/excel/chart/chart.js +1 -7
  285. package/dist/cjs/modules/excel/stream/workbook-reader.browser.js +25 -1
  286. package/dist/cjs/modules/excel/stream/workbook-reader.js +9 -0
  287. package/dist/cjs/modules/excel/stream/workbook-writer.browser.js +228 -13
  288. package/dist/cjs/modules/excel/utils/string-buf.js +5 -81
  289. package/dist/cjs/modules/excel/workbook.browser.js +135 -25
  290. package/dist/cjs/modules/excel/xlsx/xform/chart/chart-space-xform.js +6 -20
  291. package/dist/cjs/modules/excel/xlsx/xlsx.browser.js +32 -8
  292. package/dist/cjs/modules/excel/xlsx/xlsx.js +9 -1
  293. package/dist/cjs/modules/pdf/excel-bridge.js +33 -0
  294. package/dist/cjs/modules/pdf/font/metrics.js +11 -244
  295. package/dist/cjs/modules/pdf/index.js +2 -1
  296. package/dist/cjs/modules/pdf/render-layout-to-pdf.js +651 -0
  297. package/dist/cjs/modules/pdf/word-bridge.js +155 -274
  298. package/dist/cjs/modules/stream/index.base.js +4 -2
  299. package/dist/cjs/modules/stream/internal/sink-adapter.js +202 -0
  300. package/dist/cjs/modules/stream/pull-stream.js +51 -5
  301. package/dist/cjs/modules/word/advanced/diff.js +170 -0
  302. package/dist/cjs/modules/word/advanced/drawing-shapes.js +279 -0
  303. package/dist/cjs/modules/word/advanced/field-engine.js +1229 -0
  304. package/dist/cjs/modules/word/advanced/glossary.js +87 -0
  305. package/dist/cjs/modules/word/advanced/math-convert.js +599 -0
  306. package/dist/cjs/modules/word/advanced/ole-objects.js +277 -0
  307. package/dist/cjs/modules/word/advanced/style-map.js +329 -0
  308. package/dist/cjs/modules/word/advanced/validation.js +1068 -0
  309. package/dist/cjs/modules/word/advanced/vba-project.js +274 -0
  310. package/dist/cjs/modules/word/bridge/excel-bridge.js +1020 -0
  311. package/dist/cjs/modules/word/builder/document-handle.js +667 -0
  312. package/dist/cjs/modules/word/builder/paragraph-builders.js +109 -0
  313. package/dist/cjs/modules/word/builder/run-builders.js +676 -0
  314. package/dist/cjs/modules/word/builder/table-builders.js +53 -0
  315. package/dist/cjs/modules/word/constants.js +111 -2
  316. package/dist/cjs/modules/word/convert/conversion-ir.js +34 -0
  317. package/dist/cjs/modules/word/convert/docx-to-semantic.js +502 -0
  318. package/dist/cjs/modules/word/convert/flat-opc.js +390 -0
  319. package/dist/cjs/modules/word/convert/html/html-import.js +1910 -0
  320. package/dist/cjs/modules/word/{html-renderer.js → convert/html/html-renderer.js} +420 -69
  321. package/dist/cjs/modules/word/convert/html/html.js +20 -0
  322. package/dist/cjs/modules/word/convert/markdown/markdown-import.js +1329 -0
  323. package/dist/cjs/modules/word/convert/markdown/markdown-renderer.js +637 -0
  324. package/dist/cjs/modules/word/convert/markdown/markdown.js +21 -0
  325. package/dist/cjs/modules/word/convert/odt/odt.js +1936 -0
  326. package/dist/cjs/modules/word/core/color-utils.js +47 -0
  327. package/dist/cjs/modules/word/core/internal-utils.js +219 -0
  328. package/dist/cjs/modules/word/core/mapper.js +430 -0
  329. package/dist/cjs/modules/word/core/opc-paths.js +53 -0
  330. package/dist/cjs/modules/word/core/text-utils.js +210 -0
  331. package/dist/cjs/modules/word/core/walker.js +577 -0
  332. package/dist/cjs/modules/word/crypto.js +19 -8
  333. package/dist/cjs/modules/word/document-io.js +117 -197
  334. package/dist/cjs/modules/word/errors.js +59 -13
  335. package/dist/cjs/modules/word/excel.js +22 -0
  336. package/dist/cjs/modules/word/font/font-embed.js +652 -0
  337. package/dist/cjs/modules/word/{font-obfuscation.js → font/font-obfuscation.js} +4 -9
  338. package/dist/cjs/modules/word/font/hyphenation.js +4216 -0
  339. package/dist/cjs/modules/word/font/text-shaping.js +640 -0
  340. package/dist/cjs/modules/word/html.js +9 -7
  341. package/dist/cjs/modules/word/incremental-edit.js +366 -0
  342. package/dist/cjs/modules/word/index.base.js +370 -137
  343. package/dist/cjs/modules/word/layout/layout-constants.js +20 -0
  344. package/dist/cjs/modules/word/layout/layout-full.js +1699 -0
  345. package/dist/cjs/modules/word/layout/layout-model.js +17 -0
  346. package/dist/cjs/modules/word/layout/layout.js +1170 -0
  347. package/dist/cjs/modules/word/layout/render-page.js +1243 -0
  348. package/dist/cjs/modules/word/markdown.js +19 -0
  349. package/dist/cjs/modules/word/patcher.js +539 -0
  350. package/dist/cjs/modules/word/query/compat.js +61 -0
  351. package/dist/cjs/modules/word/query/data-binding.js +395 -0
  352. package/dist/cjs/modules/word/query/form-fields.js +272 -0
  353. package/dist/cjs/modules/word/query/format-search.js +334 -0
  354. package/dist/cjs/modules/word/query/mail-merge.js +114 -0
  355. package/dist/cjs/modules/word/query/merge.js +620 -0
  356. package/dist/cjs/modules/word/query/replace.js +304 -0
  357. package/dist/cjs/modules/word/query/revisions.js +885 -0
  358. package/dist/cjs/modules/word/query/search.js +361 -0
  359. package/dist/cjs/modules/word/query/split.js +138 -0
  360. package/dist/cjs/modules/word/query/style-resolve.js +374 -0
  361. package/dist/cjs/modules/word/reader/chart-parser.js +814 -0
  362. package/dist/cjs/modules/word/reader/comments-parser.js +96 -0
  363. package/dist/cjs/modules/word/reader/doc-props-parsers.js +194 -0
  364. package/dist/cjs/modules/word/reader/docx-reader.js +2560 -0
  365. package/dist/cjs/modules/word/reader/drawing-helpers.js +90 -0
  366. package/dist/cjs/modules/word/reader/form-field-parser.js +85 -0
  367. package/dist/cjs/modules/word/reader/image-parsers.js +293 -0
  368. package/dist/cjs/modules/word/reader/math-parser.js +424 -0
  369. package/dist/cjs/modules/word/reader/metadata-parsers.js +93 -0
  370. package/dist/cjs/modules/word/reader/numbering-parser.js +168 -0
  371. package/dist/cjs/modules/word/reader/paragraph-section-parsers.js +505 -0
  372. package/dist/cjs/modules/word/reader/parse-utils.js +271 -0
  373. package/dist/cjs/modules/word/reader/properties-parsers.js +338 -0
  374. package/dist/cjs/modules/word/reader/reader-context.js +66 -0
  375. package/dist/cjs/modules/word/reader/sdt-helpers.js +114 -0
  376. package/dist/cjs/modules/word/reader/settings-parser.js +265 -0
  377. package/dist/cjs/modules/word/reader/styles-parser.js +149 -0
  378. package/dist/cjs/modules/word/reader/table-properties-parsers.js +237 -0
  379. package/dist/cjs/modules/word/reader/theme-parser.js +169 -0
  380. package/dist/cjs/modules/word/reader/watermark-parser.js +113 -0
  381. package/dist/cjs/modules/word/security/cfb-reader.js +414 -0
  382. package/dist/cjs/modules/word/{digital-signatures.js → security/digital-signatures.js} +34 -34
  383. package/dist/cjs/modules/word/security/document-protection.js +208 -0
  384. package/dist/cjs/modules/word/security/encryption.js +612 -0
  385. package/dist/cjs/modules/word/security/policy.js +106 -0
  386. package/dist/cjs/modules/word/template/template-chart.js +170 -0
  387. package/dist/cjs/modules/word/template/template-datasource.js +549 -0
  388. package/dist/cjs/modules/word/template/template-engine.js +1430 -0
  389. package/dist/cjs/modules/word/units.js +44 -14
  390. package/dist/cjs/modules/word/{writers → writer}/chart-writer.js +163 -22
  391. package/dist/cjs/modules/word/writer/checkbox-writer.js +82 -0
  392. package/dist/cjs/modules/word/{writers → writer}/comment-writer.js +8 -6
  393. package/dist/cjs/modules/word/writer/common-parts.js +104 -0
  394. package/dist/cjs/modules/word/{content-types.js → writer/content-types.js} +14 -6
  395. package/dist/cjs/modules/word/writer/document-writer.js +478 -0
  396. package/dist/cjs/modules/word/writer/docx-packager.js +1551 -0
  397. package/dist/cjs/modules/word/{writers → writer}/footnote-writer.js +13 -10
  398. package/dist/cjs/modules/word/{writers → writer}/header-footer-writer.js +38 -20
  399. package/dist/cjs/modules/word/{writers → writer}/image-writer.js +11 -7
  400. package/dist/cjs/modules/word/{writers → writer}/math-writer.js +21 -1
  401. package/dist/cjs/modules/word/{writers → writer}/numbering-writer.js +11 -4
  402. package/dist/cjs/modules/word/{writers → writer}/paragraph-writer.js +72 -37
  403. package/dist/cjs/modules/word/{writers → writer}/parts-writer.js +91 -12
  404. package/dist/cjs/modules/word/writer/reference-scanners.js +120 -0
  405. package/dist/cjs/modules/word/writer/relationships.js +124 -0
  406. package/dist/cjs/modules/word/writer/render-context.js +51 -0
  407. package/dist/cjs/modules/word/{writers → writer}/run-writer.js +127 -24
  408. package/dist/cjs/modules/word/writer/sdt-writer.js +192 -0
  409. package/dist/cjs/modules/word/writer/stream-buf.js +76 -0
  410. package/dist/cjs/modules/word/writer/streaming-writer.js +1387 -0
  411. package/dist/cjs/modules/word/writer/string-buf.js +11 -0
  412. package/dist/cjs/modules/word/{writers → writer}/styles-writer.js +32 -1
  413. package/dist/cjs/modules/word/{writers → writer}/table-writer.js +94 -11
  414. package/dist/cjs/utils/crypto.browser.js +3 -1
  415. package/dist/cjs/utils/crypto.js +4 -1
  416. package/dist/cjs/utils/font-metrics.js +303 -0
  417. package/dist/cjs/utils/string-buf.js +92 -0
  418. package/dist/cjs/utils/theme-colors.js +126 -0
  419. package/dist/esm/modules/archive/compression/streaming-compress.browser.js +29 -0
  420. package/dist/esm/modules/archive/compression/streaming-compress.js +9 -0
  421. package/dist/esm/modules/archive/compression/worker-pool/pool.browser.js +26 -1
  422. package/dist/esm/modules/archive/fs/archive-file.js +78 -16
  423. package/dist/esm/modules/archive/unzip/stream.browser.js +43 -2
  424. package/dist/esm/modules/excel/chart/chart-ex-builder.js +7 -2
  425. package/dist/esm/modules/excel/chart/chart-ex-renderer.js +4 -9
  426. package/dist/esm/modules/excel/chart/chart.js +1 -7
  427. package/dist/esm/modules/excel/stream/workbook-reader.browser.js +25 -1
  428. package/dist/esm/modules/excel/stream/workbook-reader.js +9 -0
  429. package/dist/esm/modules/excel/stream/workbook-writer.browser.js +228 -13
  430. package/dist/esm/modules/excel/utils/string-buf.js +4 -81
  431. package/dist/esm/modules/excel/workbook.browser.js +135 -25
  432. package/dist/esm/modules/excel/xlsx/xform/chart/chart-space-xform.js +6 -20
  433. package/dist/esm/modules/excel/xlsx/xlsx.browser.js +32 -8
  434. package/dist/esm/modules/excel/xlsx/xlsx.js +9 -1
  435. package/dist/esm/modules/pdf/excel-bridge.js +32 -0
  436. package/dist/esm/modules/pdf/font/metrics.js +3 -237
  437. package/dist/esm/modules/pdf/index.js +1 -1
  438. package/dist/esm/modules/pdf/render-layout-to-pdf.js +647 -0
  439. package/dist/esm/modules/pdf/word-bridge.js +122 -274
  440. package/dist/esm/modules/stream/index.base.js +2 -1
  441. package/dist/esm/modules/stream/internal/sink-adapter.js +198 -0
  442. package/dist/esm/modules/stream/pull-stream.js +51 -5
  443. package/dist/esm/modules/word/advanced/diff.js +167 -0
  444. package/dist/esm/modules/word/advanced/drawing-shapes.js +268 -0
  445. package/dist/esm/modules/word/advanced/field-engine.js +1225 -0
  446. package/dist/esm/modules/word/advanced/glossary.js +79 -0
  447. package/dist/esm/modules/word/advanced/math-convert.js +595 -0
  448. package/dist/esm/modules/word/advanced/ole-objects.js +271 -0
  449. package/dist/esm/modules/word/advanced/style-map.js +322 -0
  450. package/dist/esm/modules/word/advanced/validation.js +1065 -0
  451. package/dist/esm/modules/word/advanced/vba-project.js +265 -0
  452. package/dist/esm/modules/word/bridge/excel-bridge.js +980 -0
  453. package/dist/esm/modules/word/builder/document-handle.js +664 -0
  454. package/dist/esm/modules/word/builder/paragraph-builders.js +90 -0
  455. package/dist/esm/modules/word/builder/run-builders.js +600 -0
  456. package/dist/esm/modules/word/builder/table-builders.js +45 -0
  457. package/dist/esm/modules/word/constants.js +109 -1
  458. package/dist/esm/modules/word/convert/conversion-ir.js +31 -0
  459. package/dist/esm/modules/word/convert/docx-to-semantic.js +499 -0
  460. package/dist/esm/modules/word/convert/flat-opc.js +385 -0
  461. package/dist/esm/modules/word/convert/html/html-import.js +1907 -0
  462. package/dist/{browser/modules/word → esm/modules/word/convert/html}/html-renderer.js +420 -69
  463. package/dist/esm/modules/word/convert/html/html.js +15 -0
  464. package/dist/esm/modules/word/convert/markdown/markdown-import.js +1325 -0
  465. package/dist/esm/modules/word/convert/markdown/markdown-renderer.js +634 -0
  466. package/dist/esm/modules/word/convert/markdown/markdown.js +15 -0
  467. package/dist/esm/modules/word/convert/odt/odt.js +1932 -0
  468. package/dist/esm/modules/word/core/color-utils.js +43 -0
  469. package/dist/esm/modules/word/core/internal-utils.js +209 -0
  470. package/dist/esm/modules/word/core/mapper.js +427 -0
  471. package/dist/esm/modules/word/core/opc-paths.js +48 -0
  472. package/dist/esm/modules/word/core/text-utils.js +202 -0
  473. package/dist/esm/modules/word/core/walker.js +570 -0
  474. package/dist/esm/modules/word/crypto.js +13 -7
  475. package/dist/esm/modules/word/document-io.js +80 -197
  476. package/dist/esm/modules/word/errors.js +54 -2
  477. package/dist/esm/modules/word/excel.js +13 -0
  478. package/dist/esm/modules/word/font/font-embed.js +646 -0
  479. package/dist/{browser/modules/word → esm/modules/word/font}/font-obfuscation.js +4 -9
  480. package/dist/esm/modules/word/font/hyphenation.js +4210 -0
  481. package/dist/esm/modules/word/font/text-shaping.js +635 -0
  482. package/dist/esm/modules/word/html.js +6 -5
  483. package/dist/esm/modules/word/incremental-edit.js +361 -0
  484. package/dist/esm/modules/word/index.base.js +138 -29
  485. package/dist/esm/modules/word/layout/layout-constants.js +17 -0
  486. package/dist/esm/modules/word/layout/layout-full.js +1696 -0
  487. package/dist/esm/modules/word/layout/layout-model.js +16 -0
  488. package/dist/esm/modules/word/layout/layout.js +1167 -0
  489. package/dist/esm/modules/word/layout/render-page.js +1238 -0
  490. package/dist/esm/modules/word/markdown.js +13 -0
  491. package/dist/esm/modules/word/patcher.js +537 -0
  492. package/dist/esm/modules/word/query/compat.js +58 -0
  493. package/dist/esm/modules/word/query/data-binding.js +392 -0
  494. package/dist/esm/modules/word/query/form-fields.js +268 -0
  495. package/dist/esm/modules/word/query/format-search.js +329 -0
  496. package/dist/esm/modules/word/query/mail-merge.js +111 -0
  497. package/dist/esm/modules/word/query/merge.js +617 -0
  498. package/dist/esm/modules/word/query/replace.js +301 -0
  499. package/dist/esm/modules/word/query/revisions.js +879 -0
  500. package/dist/esm/modules/word/query/search.js +346 -0
  501. package/dist/esm/modules/word/query/split.js +135 -0
  502. package/dist/esm/modules/word/query/style-resolve.js +368 -0
  503. package/dist/esm/modules/word/reader/chart-parser.js +810 -0
  504. package/dist/esm/modules/word/reader/comments-parser.js +92 -0
  505. package/dist/esm/modules/word/reader/doc-props-parsers.js +190 -0
  506. package/dist/esm/modules/word/reader/docx-reader.js +2557 -0
  507. package/dist/esm/modules/word/reader/drawing-helpers.js +84 -0
  508. package/dist/esm/modules/word/reader/form-field-parser.js +82 -0
  509. package/dist/esm/modules/word/reader/image-parsers.js +291 -0
  510. package/dist/esm/modules/word/reader/math-parser.js +422 -0
  511. package/dist/esm/modules/word/reader/metadata-parsers.js +87 -0
  512. package/dist/esm/modules/word/reader/numbering-parser.js +166 -0
  513. package/dist/esm/modules/word/reader/paragraph-section-parsers.js +503 -0
  514. package/dist/esm/modules/word/reader/parse-utils.js +249 -0
  515. package/dist/esm/modules/word/reader/properties-parsers.js +332 -0
  516. package/dist/esm/modules/word/reader/reader-context.js +61 -0
  517. package/dist/esm/modules/word/reader/sdt-helpers.js +111 -0
  518. package/dist/esm/modules/word/reader/settings-parser.js +263 -0
  519. package/dist/esm/modules/word/reader/styles-parser.js +147 -0
  520. package/dist/esm/modules/word/reader/table-properties-parsers.js +234 -0
  521. package/dist/esm/modules/word/reader/theme-parser.js +167 -0
  522. package/dist/esm/modules/word/reader/watermark-parser.js +110 -0
  523. package/dist/esm/modules/word/security/cfb-reader.js +410 -0
  524. package/dist/esm/modules/word/{digital-signatures.js → security/digital-signatures.js} +34 -34
  525. package/dist/esm/modules/word/security/document-protection.js +201 -0
  526. package/dist/esm/modules/word/security/encryption.js +602 -0
  527. package/dist/esm/modules/word/security/policy.js +102 -0
  528. package/dist/esm/modules/word/template/template-chart.js +167 -0
  529. package/dist/esm/modules/word/template/template-datasource.js +541 -0
  530. package/dist/esm/modules/word/template/template-engine.js +1435 -0
  531. package/dist/esm/modules/word/units.js +43 -14
  532. package/dist/esm/modules/word/{writers → writer}/chart-writer.js +164 -23
  533. package/dist/esm/modules/word/writer/checkbox-writer.js +79 -0
  534. package/dist/esm/modules/word/{writers → writer}/comment-writer.js +8 -6
  535. package/dist/esm/modules/word/writer/common-parts.js +101 -0
  536. package/dist/{browser/modules/word → esm/modules/word/writer}/content-types.js +14 -6
  537. package/dist/esm/modules/word/writer/document-writer.js +473 -0
  538. package/dist/esm/modules/word/writer/docx-packager.js +1515 -0
  539. package/dist/{browser/modules/word/writers → esm/modules/word/writer}/footnote-writer.js +13 -10
  540. package/dist/{browser/modules/word/writers → esm/modules/word/writer}/header-footer-writer.js +39 -21
  541. package/dist/esm/modules/word/{writers → writer}/image-writer.js +11 -7
  542. package/dist/{browser/modules/word/writers → esm/modules/word/writer}/math-writer.js +21 -1
  543. package/dist/{browser/modules/word/writers → esm/modules/word/writer}/numbering-writer.js +11 -4
  544. package/dist/esm/modules/word/{writers → writer}/paragraph-writer.js +73 -38
  545. package/dist/{browser/modules/word/writers → esm/modules/word/writer}/parts-writer.js +91 -12
  546. package/dist/esm/modules/word/writer/reference-scanners.js +111 -0
  547. package/dist/esm/modules/word/writer/relationships.js +117 -0
  548. package/dist/esm/modules/word/writer/render-context.js +46 -0
  549. package/dist/{browser/modules/word/writers → esm/modules/word/writer}/run-writer.js +126 -24
  550. package/dist/esm/modules/word/writer/sdt-writer.js +189 -0
  551. package/dist/esm/modules/word/writer/stream-buf.js +73 -0
  552. package/dist/esm/modules/word/writer/streaming-writer.js +1382 -0
  553. package/dist/esm/modules/word/writer/string-buf.js +7 -0
  554. package/dist/esm/modules/word/{writers → writer}/styles-writer.js +32 -1
  555. package/dist/esm/modules/word/{writers → writer}/table-writer.js +94 -11
  556. package/dist/esm/utils/crypto.browser.js +3 -1
  557. package/dist/esm/utils/crypto.js +4 -1
  558. package/dist/esm/utils/font-metrics.js +293 -0
  559. package/dist/esm/utils/string-buf.js +89 -0
  560. package/dist/esm/utils/theme-colors.js +120 -0
  561. package/dist/iife/excelts.iife.js +70692 -70337
  562. package/dist/iife/excelts.iife.js.map +1 -1
  563. package/dist/iife/excelts.iife.min.js +57 -57
  564. package/dist/types/modules/archive/fs/archive-file.d.ts +8 -5
  565. package/dist/types/modules/excel/chart/chart-ex-types.d.ts +0 -12
  566. package/dist/types/modules/excel/chart/chart.d.ts +1 -5
  567. package/dist/types/modules/excel/chart/types.d.ts +0 -6
  568. package/dist/types/modules/excel/stream/workbook-writer.browser.d.ts +40 -0
  569. package/dist/types/modules/excel/utils/string-buf.d.ts +5 -26
  570. package/dist/types/modules/excel/xlsx/xlsx.browser.d.ts +19 -9
  571. package/dist/types/modules/excel/xlsx/xlsx.d.ts +10 -2
  572. package/dist/types/modules/pdf/excel-bridge.d.ts +30 -1
  573. package/dist/types/modules/pdf/font/metrics.d.ts +3 -52
  574. package/dist/types/modules/pdf/index.d.ts +1 -1
  575. package/dist/types/modules/pdf/render-layout-to-pdf.d.ts +66 -0
  576. package/dist/types/modules/pdf/word-bridge.d.ts +80 -12
  577. package/dist/types/modules/stream/index.base.d.ts +2 -0
  578. package/dist/types/modules/stream/internal/sink-adapter.d.ts +65 -0
  579. package/dist/types/modules/stream/pull-stream.d.ts +19 -2
  580. package/dist/types/modules/stream/types.d.ts +13 -1
  581. package/dist/types/modules/word/advanced/diff.d.ts +61 -0
  582. package/dist/types/modules/word/advanced/drawing-shapes.d.ts +269 -0
  583. package/dist/types/modules/word/advanced/field-engine.d.ts +43 -0
  584. package/dist/types/modules/word/advanced/glossary.d.ts +86 -0
  585. package/dist/types/modules/word/advanced/math-convert.d.ts +30 -0
  586. package/dist/types/modules/word/advanced/ole-objects.d.ts +115 -0
  587. package/dist/types/modules/word/advanced/style-map.d.ts +105 -0
  588. package/dist/types/modules/word/advanced/validation.d.ts +56 -0
  589. package/dist/types/modules/word/advanced/vba-project.d.ts +91 -0
  590. package/dist/types/modules/word/bridge/excel-bridge.d.ts +127 -0
  591. package/dist/types/modules/word/builder/document-handle.d.ts +151 -0
  592. package/dist/types/modules/word/builder/paragraph-builders.d.ts +61 -0
  593. package/dist/types/modules/word/builder/run-builders.d.ts +374 -0
  594. package/dist/types/modules/word/builder/table-builders.d.ts +23 -0
  595. package/dist/types/modules/word/constants.d.ts +39 -1
  596. package/dist/types/modules/word/convert/conversion-ir.d.ts +210 -0
  597. package/dist/types/modules/word/convert/docx-to-semantic.d.ts +39 -0
  598. package/dist/types/modules/word/convert/flat-opc.d.ts +44 -0
  599. package/dist/types/modules/word/convert/html/html-import.d.ts +50 -0
  600. package/dist/{browser/modules/word → types/modules/word/convert/html}/html-renderer.d.ts +14 -1
  601. package/dist/types/modules/word/convert/html/html.d.ts +15 -0
  602. package/dist/types/modules/word/convert/markdown/markdown-import.d.ts +68 -0
  603. package/dist/types/modules/word/convert/markdown/markdown-renderer.d.ts +25 -0
  604. package/dist/types/modules/word/convert/markdown/markdown.d.ts +15 -0
  605. package/dist/types/modules/word/convert/odt/odt.d.ts +41 -0
  606. package/dist/types/modules/word/{color-utils.d.ts → core/color-utils.d.ts} +8 -1
  607. package/dist/types/modules/word/core/internal-utils.d.ts +90 -0
  608. package/dist/types/modules/word/core/mapper.d.ts +44 -0
  609. package/dist/types/modules/word/core/opc-paths.d.ts +33 -0
  610. package/dist/types/modules/word/core/text-utils.d.ts +38 -0
  611. package/dist/types/modules/word/core/walker.d.ts +119 -0
  612. package/dist/types/modules/word/crypto.d.ts +14 -9
  613. package/dist/types/modules/word/document-io.d.ts +59 -27
  614. package/dist/types/modules/word/errors.d.ts +44 -1
  615. package/dist/types/modules/word/excel.d.ts +14 -0
  616. package/dist/types/modules/word/font/font-embed.d.ts +112 -0
  617. package/dist/types/modules/word/font/hyphenation.d.ts +65 -0
  618. package/dist/types/modules/word/font/text-shaping.d.ts +58 -0
  619. package/dist/types/modules/word/html.d.ts +7 -6
  620. package/dist/types/modules/word/incremental-edit.d.ts +123 -0
  621. package/dist/types/modules/word/index.base.d.ts +194 -10
  622. package/dist/types/modules/word/layout/layout-constants.d.ts +17 -0
  623. package/dist/types/modules/word/layout/layout-full.d.ts +53 -0
  624. package/dist/types/modules/word/layout/layout-model.d.ts +344 -0
  625. package/dist/types/modules/word/layout/layout.d.ts +63 -0
  626. package/dist/types/modules/word/layout/render-page.d.ts +57 -0
  627. package/dist/types/modules/word/markdown.d.ts +14 -0
  628. package/dist/types/modules/word/patcher.d.ts +62 -0
  629. package/dist/types/modules/word/query/compat.d.ts +25 -0
  630. package/dist/types/modules/word/query/data-binding.d.ts +22 -0
  631. package/dist/types/modules/word/query/form-fields.d.ts +41 -0
  632. package/dist/types/modules/word/query/format-search.d.ts +99 -0
  633. package/dist/types/modules/word/query/mail-merge.d.ts +25 -0
  634. package/dist/types/modules/word/query/merge.d.ts +50 -0
  635. package/dist/types/modules/word/query/replace.d.ts +47 -0
  636. package/dist/types/modules/word/query/revisions.d.ts +67 -0
  637. package/dist/types/modules/word/query/search.d.ts +129 -0
  638. package/dist/types/modules/word/query/split.d.ts +44 -0
  639. package/dist/types/modules/word/query/style-resolve.d.ts +104 -0
  640. package/dist/types/modules/word/reader/chart-parser.d.ts +20 -0
  641. package/dist/types/modules/word/reader/comments-parser.d.ts +26 -0
  642. package/dist/types/modules/word/reader/doc-props-parsers.d.ts +15 -0
  643. package/dist/types/modules/word/reader/docx-reader.d.ts +27 -0
  644. package/dist/types/modules/word/reader/drawing-helpers.d.ts +27 -0
  645. package/dist/types/modules/word/reader/form-field-parser.d.ts +21 -0
  646. package/dist/types/modules/word/reader/image-parsers.d.ts +11 -0
  647. package/dist/types/modules/word/reader/math-parser.d.ts +12 -0
  648. package/dist/types/modules/word/reader/metadata-parsers.d.ts +17 -0
  649. package/dist/types/modules/word/reader/numbering-parser.d.ts +13 -0
  650. package/dist/types/modules/word/reader/paragraph-section-parsers.d.ts +12 -0
  651. package/dist/types/modules/word/reader/parse-utils.d.ts +91 -0
  652. package/dist/types/modules/word/reader/properties-parsers.d.ts +21 -0
  653. package/dist/types/modules/word/reader/reader-context.d.ts +69 -0
  654. package/dist/types/modules/word/reader/sdt-helpers.d.ts +29 -0
  655. package/dist/types/modules/word/reader/settings-parser.d.ts +8 -0
  656. package/dist/types/modules/word/reader/styles-parser.d.ts +12 -0
  657. package/dist/types/modules/word/reader/table-properties-parsers.d.ts +12 -0
  658. package/dist/types/modules/word/reader/theme-parser.d.ts +8 -0
  659. package/dist/types/modules/word/reader/watermark-parser.d.ts +15 -0
  660. package/dist/types/modules/word/security/cfb-reader.d.ts +37 -0
  661. package/dist/types/modules/word/{digital-signatures.d.ts → security/digital-signatures.d.ts} +19 -11
  662. package/dist/types/modules/word/security/document-protection.d.ts +93 -0
  663. package/dist/{browser/modules/word → types/modules/word/security}/encryption.d.ts +51 -4
  664. package/dist/types/modules/word/security/policy.d.ts +80 -0
  665. package/dist/types/modules/word/template/template-chart.d.ts +56 -0
  666. package/dist/types/modules/word/template/template-datasource.d.ts +154 -0
  667. package/dist/types/modules/word/template/template-engine.d.ts +121 -0
  668. package/dist/types/modules/word/types.d.ts +224 -25
  669. package/dist/types/modules/word/units.d.ts +26 -0
  670. package/dist/types/modules/word/writer/checkbox-writer.d.ts +17 -0
  671. package/dist/{browser/modules/word/writers → types/modules/word/writer}/comment-writer.d.ts +2 -1
  672. package/dist/types/modules/word/writer/common-parts.d.ts +57 -0
  673. package/dist/{browser/modules/word → types/modules/word/writer}/content-types.d.ts +2 -2
  674. package/dist/types/modules/word/writer/document-writer.d.ts +24 -0
  675. package/dist/types/modules/word/writer/docx-packager.d.ts +35 -0
  676. package/dist/{browser/modules/word/writers → types/modules/word/writer}/footnote-writer.d.ts +3 -2
  677. package/dist/{browser/modules/word/writers → types/modules/word/writer}/header-footer-writer.d.ts +3 -2
  678. package/dist/{browser/modules/word/writers → types/modules/word/writer}/image-writer.d.ts +1 -1
  679. package/dist/types/modules/word/writer/math-writer.d.ts +20 -0
  680. package/dist/types/modules/word/{writers → writer}/numbering-writer.d.ts +1 -1
  681. package/dist/types/modules/word/{writers → writer}/paragraph-writer.d.ts +2 -1
  682. package/dist/types/modules/word/{writers → writer}/parts-writer.d.ts +3 -3
  683. package/dist/types/modules/word/writer/reference-scanners.d.ts +42 -0
  684. package/dist/types/modules/word/writer/relationships.d.ts +52 -0
  685. package/dist/types/modules/word/writer/render-context.d.ts +124 -0
  686. package/dist/types/modules/word/{writers → writer}/run-writer.d.ts +10 -1
  687. package/dist/types/modules/word/writer/sdt-writer.d.ts +25 -0
  688. package/dist/types/modules/word/writer/stream-buf.d.ts +37 -0
  689. package/dist/types/modules/word/writer/streaming-writer.d.ts +344 -0
  690. package/dist/types/modules/word/writer/string-buf.d.ts +8 -0
  691. package/dist/types/modules/word/{writers → writer}/table-writer.d.ts +2 -1
  692. package/dist/types/modules/xml/types.d.ts +22 -0
  693. package/dist/types/utils/crypto.browser.d.ts +3 -1
  694. package/dist/types/utils/crypto.d.ts +4 -1
  695. package/dist/types/utils/font-metrics.d.ts +63 -0
  696. package/dist/types/utils/string-buf.d.ts +42 -0
  697. package/dist/types/utils/theme-colors.d.ts +55 -0
  698. package/package.json +121 -39
  699. package/dist/browser/modules/word/color-utils.js +0 -94
  700. package/dist/browser/modules/word/document.d.ts +0 -657
  701. package/dist/browser/modules/word/document.js +0 -1533
  702. package/dist/browser/modules/word/docx-packager.d.ts +0 -14
  703. package/dist/browser/modules/word/docx-packager.js +0 -822
  704. package/dist/browser/modules/word/docx-reader.d.ts +0 -11
  705. package/dist/browser/modules/word/docx-reader.js +0 -4929
  706. package/dist/browser/modules/word/encryption.js +0 -274
  707. package/dist/browser/modules/word/internal-utils.d.ts +0 -23
  708. package/dist/browser/modules/word/internal-utils.js +0 -54
  709. package/dist/browser/modules/word/namespaces.d.ts +0 -159
  710. package/dist/browser/modules/word/namespaces.js +0 -189
  711. package/dist/browser/modules/word/relationships.d.ts +0 -30
  712. package/dist/browser/modules/word/relationships.js +0 -48
  713. package/dist/browser/modules/word/writers/checkbox-writer.d.ts +0 -9
  714. package/dist/browser/modules/word/writers/checkbox-writer.js +0 -42
  715. package/dist/browser/modules/word/writers/document-writer.d.ts +0 -16
  716. package/dist/browser/modules/word/writers/document-writer.js +0 -461
  717. package/dist/browser/modules/word/writers/math-writer.d.ts +0 -9
  718. package/dist/cjs/modules/word/color-utils.js +0 -97
  719. package/dist/cjs/modules/word/document.js +0 -1645
  720. package/dist/cjs/modules/word/docx-packager.js +0 -825
  721. package/dist/cjs/modules/word/docx-reader.js +0 -4932
  722. package/dist/cjs/modules/word/encryption.js +0 -282
  723. package/dist/cjs/modules/word/internal-utils.js +0 -59
  724. package/dist/cjs/modules/word/namespaces.js +0 -192
  725. package/dist/cjs/modules/word/relationships.js +0 -55
  726. package/dist/cjs/modules/word/writers/checkbox-writer.js +0 -45
  727. package/dist/cjs/modules/word/writers/document-writer.js +0 -465
  728. package/dist/esm/modules/word/color-utils.js +0 -94
  729. package/dist/esm/modules/word/document.js +0 -1533
  730. package/dist/esm/modules/word/docx-packager.js +0 -822
  731. package/dist/esm/modules/word/docx-reader.js +0 -4929
  732. package/dist/esm/modules/word/encryption.js +0 -274
  733. package/dist/esm/modules/word/internal-utils.js +0 -54
  734. package/dist/esm/modules/word/namespaces.js +0 -189
  735. package/dist/esm/modules/word/relationships.js +0 -48
  736. package/dist/esm/modules/word/writers/checkbox-writer.js +0 -42
  737. package/dist/esm/modules/word/writers/document-writer.js +0 -461
  738. package/dist/types/modules/word/document.d.ts +0 -657
  739. package/dist/types/modules/word/docx-packager.d.ts +0 -14
  740. package/dist/types/modules/word/docx-reader.d.ts +0 -11
  741. package/dist/types/modules/word/internal-utils.d.ts +0 -23
  742. package/dist/types/modules/word/namespaces.d.ts +0 -159
  743. package/dist/types/modules/word/relationships.d.ts +0 -30
  744. package/dist/types/modules/word/writers/checkbox-writer.d.ts +0 -9
  745. package/dist/types/modules/word/writers/document-writer.d.ts +0 -16
  746. package/dist/types/modules/word/writers/math-writer.d.ts +0 -9
  747. /package/dist/browser/modules/word/{font-obfuscation.d.ts → font/font-obfuscation.d.ts} +0 -0
  748. /package/dist/browser/modules/word/{writers → writer}/chart-writer.d.ts +0 -0
  749. /package/dist/browser/modules/word/{writers → writer}/section-writer.d.ts +0 -0
  750. /package/dist/browser/modules/word/{writers → writer}/section-writer.js +0 -0
  751. /package/dist/browser/modules/word/{writers → writer}/styles-writer.d.ts +0 -0
  752. /package/dist/browser/modules/word/{writers → writer}/textbox-writer.d.ts +0 -0
  753. /package/dist/browser/modules/word/{writers → writer}/textbox-writer.js +0 -0
  754. /package/dist/browser/modules/word/{writers → writer}/toc-writer.d.ts +0 -0
  755. /package/dist/browser/modules/word/{writers → writer}/toc-writer.js +0 -0
  756. /package/dist/cjs/modules/word/{writers → writer}/section-writer.js +0 -0
  757. /package/dist/cjs/modules/word/{writers → writer}/textbox-writer.js +0 -0
  758. /package/dist/cjs/modules/word/{writers → writer}/toc-writer.js +0 -0
  759. /package/dist/esm/modules/word/{writers → writer}/section-writer.js +0 -0
  760. /package/dist/esm/modules/word/{writers → writer}/textbox-writer.js +0 -0
  761. /package/dist/esm/modules/word/{writers → writer}/toc-writer.js +0 -0
  762. /package/dist/types/modules/word/{font-obfuscation.d.ts → font/font-obfuscation.d.ts} +0 -0
  763. /package/dist/types/modules/word/{writers → writer}/chart-writer.d.ts +0 -0
  764. /package/dist/types/modules/word/{writers → writer}/section-writer.d.ts +0 -0
  765. /package/dist/types/modules/word/{writers → writer}/styles-writer.d.ts +0 -0
  766. /package/dist/types/modules/word/{writers → writer}/textbox-writer.d.ts +0 -0
  767. /package/dist/types/modules/word/{writers → writer}/toc-writer.d.ts +0 -0
@@ -0,0 +1,1170 @@
1
+ "use strict";
2
+ /**
3
+ * Word Document Layout Engine — Advanced Pagination Model
4
+ *
5
+ * Provides page-break calculation for DOCX documents with support for:
6
+ * - Precise line-by-line text wrapping with greedy algorithm
7
+ * - CJK full-width character width awareness
8
+ * - First-line indent / hanging indent
9
+ * - Tab stop positioning
10
+ * - Contextual spacing (paragraph spacing collapse)
11
+ * - Widow & Orphan control
12
+ * - Footnote/Endnote space reservation
13
+ * - Table cell content height calculation
14
+ * - Inline image height contribution
15
+ * - Numbering (bullet/number) indent calculation
16
+ *
17
+ * Units reminder:
18
+ * 1 inch = 1440 twips
19
+ * 1 pt = 20 twips
20
+ * Default US Letter: 12240 × 15840 twips, margins 1440 each
21
+ * Half-point 24 = 12pt font; line height ~14.4pt = 288 twips (single-spaced)
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.layoutDocument = layoutDocument;
25
+ const text_utils_1 = require("../core/text-utils");
26
+ const layout_constants_1 = require("./layout-constants");
27
+ // =============================================================================
28
+ // Internal Constants
29
+ // =============================================================================
30
+ /** 默认字号 (半磅): 24 = 12pt */
31
+ const DEFAULT_FONT_SIZE_HALF_PT = 24;
32
+ /** 默认每行字符数 */
33
+ const DEFAULT_CHARS_PER_LINE = 80;
34
+ /** auto spacing (段前/段后自动间距),约 100 twips ≈ 5pt */
35
+ const AUTO_SPACING_TWIPS = 100;
36
+ /** Default tab stop interval (twips) — Word default is 0.5 inch = 720 twips */
37
+ const DEFAULT_TAB_INTERVAL = 720;
38
+ /** Footnote separator height (twips): line + spacing ≈ 200 twips */
39
+ const FOOTNOTE_SEPARATOR_HEIGHT = 200;
40
+ /** Estimated height per footnote reference (single line + spacing) */
41
+ const FOOTNOTE_ENTRY_HEIGHT = 300;
42
+ // =============================================================================
43
+ // Internal Helpers
44
+ // =============================================================================
45
+ /** 从 SectionProperties 计算可用内容高度 (twips) */
46
+ function computeAvailableHeight(sp) {
47
+ const height = sp?.pageSize?.height ?? layout_constants_1.DEFAULT_PAGE_HEIGHT_TWIPS;
48
+ const marginTop = sp?.margins?.top ?? layout_constants_1.DEFAULT_PAGE_MARGIN_TWIPS;
49
+ const marginBottom = sp?.margins?.bottom ?? layout_constants_1.DEFAULT_PAGE_MARGIN_TWIPS;
50
+ // 可用高度 = 页面高度 - 上边距 - 下边距
51
+ // Word 中 header/footer 区域位于 margin 内部,不额外占用正文空间。
52
+ // 简化模型:不考虑 header/footer 溢出正文区域的情况。
53
+ return Math.max(0, height - marginTop - marginBottom);
54
+ }
55
+ /** 从 SectionProperties 计算可用内容宽度 (twips) */
56
+ function computeAvailableWidth(sp) {
57
+ const width = sp?.pageSize?.width ?? layout_constants_1.DEFAULT_PAGE_WIDTH_TWIPS;
58
+ const marginLeft = sp?.margins?.left ?? layout_constants_1.DEFAULT_PAGE_MARGIN_TWIPS;
59
+ const marginRight = sp?.margins?.right ?? layout_constants_1.DEFAULT_PAGE_MARGIN_TWIPS;
60
+ const gutter = sp?.margins?.gutter ?? 0;
61
+ return Math.max(0, width - marginLeft - marginRight - gutter);
62
+ }
63
+ /**
64
+ * 根据字号计算单行行高 (twips)。
65
+ * 标准排版: 行高 ≈ 字号 × 1.2
66
+ * halfPt 24 (12pt) → 行高 14.4pt = 288 twips
67
+ */
68
+ function baseLineHeight(fontSizeHalfPt) {
69
+ const ptSize = fontSizeHalfPt / 2;
70
+ return Math.round(ptSize * 1.2 * 20); // pt → twips: ×20
71
+ }
72
+ /**
73
+ * 根据 LineSpacing 配置计算实际行高 (twips)。
74
+ * - auto: value 以 240ths 为单位 (240=单倍, 360=1.5倍, 480=双倍)
75
+ * - exact: value 即为 twips
76
+ * - atLeast: value 为最小值 (twips),取 max(value, baseLine)
77
+ */
78
+ function computeLineHeight(spacing, fontSizeHalfPt) {
79
+ const baseLine = baseLineHeight(fontSizeHalfPt);
80
+ if (!spacing?.line) {
81
+ return baseLine;
82
+ }
83
+ const rule = spacing.lineRule ?? "auto";
84
+ switch (rule) {
85
+ case "auto": {
86
+ // spacing.line 以 240ths of a line 为单位
87
+ const multiplier = spacing.line / 240;
88
+ return Math.round(baseLine * multiplier);
89
+ }
90
+ case "exact":
91
+ return spacing.line;
92
+ case "atLeast":
93
+ return Math.max(spacing.line, baseLine);
94
+ default:
95
+ return baseLine;
96
+ }
97
+ }
98
+ /** 提取段落的有效字号 (半磅) */
99
+ function getParagraphFontSize(props, defaultFontSize) {
100
+ // 段落标记的 run properties 可以指示字号
101
+ return props?.markRunProperties?.size ?? defaultFontSize;
102
+ }
103
+ /** 从 Run 的 font 属性中提取字体名 */
104
+ function getRunFontName(run) {
105
+ const font = run.properties?.font;
106
+ if (!font) {
107
+ return "Calibri";
108
+ }
109
+ if (typeof font === "string") {
110
+ return font;
111
+ }
112
+ return font.ascii ?? font.hAnsi ?? "Calibri";
113
+ }
114
+ /** 提取 Run 中的纯文本内容 */
115
+ function getRunText(run) {
116
+ let text = "";
117
+ for (const item of run.content) {
118
+ switch (item.type) {
119
+ case "text":
120
+ text += item.text;
121
+ break;
122
+ case "tab":
123
+ text += " "; // tab 约等于 4 个字符
124
+ break;
125
+ case "symbol":
126
+ text += " ";
127
+ break;
128
+ case "noBreakHyphen":
129
+ case "softHyphen":
130
+ text += "-";
131
+ break;
132
+ default:
133
+ break;
134
+ }
135
+ }
136
+ return text;
137
+ }
138
+ /**
139
+ * Check if a character is CJK (full-width) — takes approximately 2x the width of Latin chars.
140
+ * Covers CJK Unified Ideographs, Katakana, Hiragana, Hangul, fullwidth forms, etc.
141
+ */
142
+ function isCjkChar(code) {
143
+ return ((code >= 0x2e80 && code <= 0x9fff) || // CJK Radicals, Kangxi, Ideographs
144
+ (code >= 0xac00 && code <= 0xd7af) || // Hangul Syllables
145
+ (code >= 0xf900 && code <= 0xfaff) || // CJK Compatibility Ideographs
146
+ (code >= 0xfe30 && code <= 0xfe4f) || // CJK Compatibility Forms
147
+ (code >= 0xff00 && code <= 0xff60) || // Fullwidth Forms
148
+ (code >= 0xffe0 && code <= 0xffe6) || // Fullwidth Signs
149
+ (code >= 0x20000 && code <= 0x2fa1f) // CJK Extension B-F, Compatibility Supplement
150
+ );
151
+ }
152
+ /**
153
+ * Calculate the effective character width units for a text string.
154
+ * CJK characters count as 2 units, Latin/other as 1 unit.
155
+ */
156
+ function getEffectiveTextWidth(text) {
157
+ let width = 0;
158
+ for (let i = 0; i < text.length; i++) {
159
+ const code = text.codePointAt(i);
160
+ if (code > 0xffff) {
161
+ // Supplementary character (surrogate pair) — skip the low surrogate
162
+ i++;
163
+ }
164
+ width += isCjkChar(code) ? 2 : 1;
165
+ }
166
+ return width;
167
+ }
168
+ /**
169
+ * Word-based line count calculation using greedy line-breaking algorithm.
170
+ *
171
+ * Splits text at word boundaries (spaces, hyphens, CJK characters) and places
172
+ * words on lines greedily. Accounts for tab stops at their actual positions.
173
+ *
174
+ * @param children - Paragraph children (runs and hyperlinks)
175
+ * @param firstLineWidth - Available width for the first line (twips)
176
+ * @param subsequentWidth - Available width for subsequent lines (twips)
177
+ * @param averageCharWidth - Average character width (twips)
178
+ * @param tabStops - Custom tab stop positions (twips from left margin)
179
+ * @returns Number of lines the paragraph occupies
180
+ */
181
+ function computeLineCountWordBased(children, firstLineWidth, subsequentWidth, averageCharWidth, tabStops) {
182
+ // Collect all tokens (words, spaces, tabs, images) from all runs
183
+ const tokens = collectTokens(children);
184
+ if (tokens.length === 0) {
185
+ return 1;
186
+ }
187
+ let lineCount = 1;
188
+ let currentLineWidth = firstLineWidth;
189
+ let xPos = 0; // Current x position on the line (in twips)
190
+ for (const token of tokens) {
191
+ if (token.type === "tab") {
192
+ // Advance to next tab stop
193
+ const nextTab = findNextTabStop(xPos, tabStops);
194
+ if (nextTab > currentLineWidth) {
195
+ // Tab would go past line end — wrap to next line
196
+ lineCount++;
197
+ currentLineWidth = subsequentWidth;
198
+ xPos = 0;
199
+ }
200
+ else {
201
+ xPos = nextTab;
202
+ }
203
+ }
204
+ else if (token.type === "break") {
205
+ // Hard line break
206
+ lineCount++;
207
+ currentLineWidth = subsequentWidth;
208
+ xPos = 0;
209
+ }
210
+ else {
211
+ // Word or image token
212
+ const tokenWidth = token.width * averageCharWidth;
213
+ if (xPos + tokenWidth > currentLineWidth && xPos > 0) {
214
+ // Token doesn't fit — wrap to next line
215
+ lineCount++;
216
+ currentLineWidth = subsequentWidth;
217
+ xPos = tokenWidth;
218
+ }
219
+ else {
220
+ xPos += tokenWidth;
221
+ }
222
+ }
223
+ }
224
+ return lineCount;
225
+ }
226
+ /**
227
+ * Collect tokens from paragraph children for line-breaking.
228
+ * Splits text at break opportunities (spaces, after hyphens, between CJK chars).
229
+ */
230
+ function collectTokens(children) {
231
+ const tokens = [];
232
+ for (const child of children) {
233
+ if ((0, text_utils_1.isRun)(child)) {
234
+ collectRunTokens(child, tokens);
235
+ }
236
+ else if ((0, text_utils_1.isHyperlink)(child)) {
237
+ for (const run of child.children) {
238
+ collectRunTokens(run, tokens);
239
+ }
240
+ }
241
+ }
242
+ return tokens;
243
+ }
244
+ function collectRunTokens(run, tokens) {
245
+ for (const item of run.content) {
246
+ switch (item.type) {
247
+ case "text": {
248
+ // Split text into word tokens at break opportunities
249
+ const words = splitIntoWords(item.text);
250
+ for (const word of words) {
251
+ if (word.length > 0) {
252
+ tokens.push({ type: "word", width: getEffectiveTextWidth(word) });
253
+ }
254
+ }
255
+ break;
256
+ }
257
+ case "tab":
258
+ tokens.push({ type: "tab" });
259
+ break;
260
+ case "break":
261
+ tokens.push({ type: "break" });
262
+ break;
263
+ case "image": {
264
+ const img = item;
265
+ const w = img.width ? Math.ceil(emuToTwips(img.width) / 120) : 10;
266
+ tokens.push({ type: "image", width: w });
267
+ break;
268
+ }
269
+ case "symbol":
270
+ tokens.push({ type: "word", width: 1 });
271
+ break;
272
+ case "noBreakHyphen":
273
+ tokens.push({ type: "word", width: 1 });
274
+ break;
275
+ default:
276
+ break;
277
+ }
278
+ }
279
+ }
280
+ /**
281
+ * Split text into words at break opportunities.
282
+ * Break opportunities: after space, after hyphen, between CJK characters.
283
+ * Spaces are included with the preceding word (trailing space model).
284
+ */
285
+ function splitIntoWords(text) {
286
+ const words = [];
287
+ let current = "";
288
+ for (let i = 0; i < text.length; i++) {
289
+ const code = text.codePointAt(i);
290
+ const ch = String.fromCodePoint(code);
291
+ if (code > 0xffff) {
292
+ i++; // Skip surrogate pair low half
293
+ }
294
+ if (code === 0x20 || code === 0x0a) {
295
+ // Space — attach to current word and break after
296
+ current += ch;
297
+ words.push(current);
298
+ current = "";
299
+ }
300
+ else if (code === 0x2d || code === 0x2010 || code === 0x2011) {
301
+ // Hyphen — break after hyphen
302
+ current += ch;
303
+ words.push(current);
304
+ current = "";
305
+ }
306
+ else if (isCjkChar(code)) {
307
+ // CJK characters: each is its own break opportunity
308
+ if (current.length > 0) {
309
+ words.push(current);
310
+ current = "";
311
+ }
312
+ words.push(ch);
313
+ }
314
+ else {
315
+ current += ch;
316
+ }
317
+ }
318
+ if (current.length > 0) {
319
+ words.push(current);
320
+ }
321
+ return words;
322
+ }
323
+ /**
324
+ * Find the next tab stop position (in twips) after the given x position.
325
+ */
326
+ function findNextTabStop(xPos, tabStops) {
327
+ if (tabStops && tabStops.length > 0) {
328
+ // Find the first tab stop after xPos
329
+ for (const stop of tabStops) {
330
+ if (stop > xPos) {
331
+ return stop;
332
+ }
333
+ }
334
+ // All defined stops passed — use interval from last stop
335
+ const lastStop = tabStops[tabStops.length - 1];
336
+ const interval = DEFAULT_TAB_INTERVAL;
337
+ return lastStop + Math.ceil((xPos - lastStop) / interval) * interval + interval;
338
+ }
339
+ // Default: advance to next multiple of DEFAULT_TAB_INTERVAL
340
+ return (Math.floor(xPos / DEFAULT_TAB_INTERVAL) + 1) * DEFAULT_TAB_INTERVAL;
341
+ }
342
+ /**
343
+ * Compute the effective available width for text in a paragraph, accounting for:
344
+ * - First line indent / hanging indent
345
+ * - Numbering indent
346
+ * Returns [firstLineWidth, subsequentLineWidth] in twips.
347
+ */
348
+ function computeParagraphLineWidths(props, availableWidth) {
349
+ const indent = props?.indent;
350
+ const leftIndent = indent?.left ?? 0;
351
+ const rightIndent = indent?.right ?? 0;
352
+ const firstLine = indent?.firstLine ?? 0;
353
+ const hanging = indent?.hanging ?? 0;
354
+ // Base width after left/right indents
355
+ const baseWidth = Math.max(1, availableWidth - leftIndent - rightIndent);
356
+ // firstLine means the first line is indented additionally (less available width)
357
+ // hanging means subsequent lines are indented (first line gets extra width)
358
+ if (hanging > 0) {
359
+ return [Math.max(1, baseWidth + hanging), baseWidth];
360
+ }
361
+ if (firstLine > 0) {
362
+ return [Math.max(1, baseWidth - firstLine), baseWidth];
363
+ }
364
+ return [baseWidth, baseWidth];
365
+ }
366
+ /**
367
+ * Check if a paragraph has an inline image that contributes line height.
368
+ * Returns the maximum image height in twips found in the paragraph, or 0.
369
+ */
370
+ function getInlineImageMaxHeight(children) {
371
+ let maxHeight = 0;
372
+ for (const child of children) {
373
+ if ((0, text_utils_1.isRun)(child)) {
374
+ for (const item of child.content) {
375
+ if (item.type === "image") {
376
+ const img = item;
377
+ if (img.height) {
378
+ const h = emuToTwips(img.height);
379
+ if (h > maxHeight) {
380
+ maxHeight = h;
381
+ }
382
+ }
383
+ }
384
+ }
385
+ }
386
+ }
387
+ return maxHeight;
388
+ }
389
+ /**
390
+ * Count footnote/endnote references in a paragraph.
391
+ */
392
+ function countFootnoteRefs(children) {
393
+ let count = 0;
394
+ for (const child of children) {
395
+ if ((0, text_utils_1.isRun)(child)) {
396
+ for (const item of child.content) {
397
+ if (item.type === "footnoteRef" || item.type === "endnoteRef") {
398
+ count++;
399
+ }
400
+ }
401
+ }
402
+ }
403
+ return count;
404
+ }
405
+ /**
406
+ * Count hard line break elements in a paragraph (type "break" without breakType "page"/"column").
407
+ */
408
+ function countBreakElements(children) {
409
+ let count = 0;
410
+ for (const child of children) {
411
+ if ((0, text_utils_1.isRun)(child)) {
412
+ for (const item of child.content) {
413
+ if (item.type === "break") {
414
+ const breakType = item.breakType;
415
+ if (!breakType || breakType === "textWrapping") {
416
+ count++;
417
+ }
418
+ }
419
+ }
420
+ }
421
+ else if ((0, text_utils_1.isHyperlink)(child)) {
422
+ for (const run of child.children) {
423
+ for (const item of run.content) {
424
+ if (item.type === "break") {
425
+ const breakType = item.breakType;
426
+ if (!breakType || breakType === "textWrapping") {
427
+ count++;
428
+ }
429
+ }
430
+ }
431
+ }
432
+ }
433
+ }
434
+ return count;
435
+ }
436
+ /**
437
+ * 使用 measureText 回调计算段落总文本宽度 (points)。
438
+ * 对每个 Run 根据其字体和字号分别测量,然后求和。
439
+ */
440
+ function measureParagraphTextWidth(children, defaultFontSize, measureFn) {
441
+ let totalWidth = 0;
442
+ for (const child of children) {
443
+ if ((0, text_utils_1.isRun)(child)) {
444
+ const text = getRunText(child);
445
+ if (text.length > 0) {
446
+ const fontName = getRunFontName(child);
447
+ const fontSize = (child.properties?.size ?? defaultFontSize) / 2; // half-pt → pt
448
+ totalWidth += measureFn(text, fontName, fontSize);
449
+ }
450
+ }
451
+ else if ((0, text_utils_1.isHyperlink)(child)) {
452
+ for (const run of child.children) {
453
+ const text = getRunText(run);
454
+ if (text.length > 0) {
455
+ const fontName = getRunFontName(run);
456
+ const fontSize = (run.properties?.size ?? defaultFontSize) / 2;
457
+ totalWidth += measureFn(text, fontName, fontSize);
458
+ }
459
+ }
460
+ }
461
+ }
462
+ return totalWidth;
463
+ }
464
+ /** 获取段落中 run 的最大字号 */
465
+ function getMaxRunFontSize(children, defaultFontSize) {
466
+ let maxSize = 0;
467
+ for (const child of children) {
468
+ if ((0, text_utils_1.isRun)(child)) {
469
+ const size = child.properties?.size ?? defaultFontSize;
470
+ if (size > maxSize) {
471
+ maxSize = size;
472
+ }
473
+ }
474
+ else if ((0, text_utils_1.isHyperlink)(child)) {
475
+ for (const run of child.children) {
476
+ const size = run.properties?.size ?? defaultFontSize;
477
+ if (size > maxSize) {
478
+ maxSize = size;
479
+ }
480
+ }
481
+ }
482
+ }
483
+ return maxSize || defaultFontSize;
484
+ }
485
+ /** 检查段落 run content 中是否有 page break */
486
+ function hasPageBreakInRuns(children) {
487
+ for (const child of children) {
488
+ if ((0, text_utils_1.isRun)(child)) {
489
+ for (const item of child.content) {
490
+ if (item.type === "break" && item.breakType === "page") {
491
+ return true;
492
+ }
493
+ }
494
+ }
495
+ }
496
+ return false;
497
+ }
498
+ /** 检查段落 run content 中是否有 column break */
499
+ function hasColumnBreakInRuns(children) {
500
+ for (const child of children) {
501
+ if ((0, text_utils_1.isRun)(child)) {
502
+ for (const item of child.content) {
503
+ if (item.type === "break" && item.breakType === "column") {
504
+ return true;
505
+ }
506
+ }
507
+ }
508
+ }
509
+ return false;
510
+ }
511
+ /**
512
+ * 估算段落高度 (twips)。
513
+ *
514
+ * 高度 = spaceBefore + (行数 × 行高) + spaceAfter
515
+ *
516
+ * Line count calculation:
517
+ * 1. If measureTextFn is provided → precise measurement
518
+ * 2. Otherwise → CJK-aware effective width estimation with indent handling
519
+ *
520
+ * Also accounts for:
521
+ * - Inline images that exceed line height
522
+ * - First-line / hanging indent
523
+ * - Tab stop positioning
524
+ */
525
+ function estimateParagraphHeight(para, availableWidth, defaultFontSize, defaultCharsPerLine, averageCharWidth, measureTextFn) {
526
+ const props = para.properties;
527
+ const spacing = props?.spacing;
528
+ // 段前间距
529
+ let spaceBefore = 0;
530
+ if (spacing?.beforeAutoSpacing) {
531
+ spaceBefore = AUTO_SPACING_TWIPS;
532
+ }
533
+ else if (spacing?.before != null) {
534
+ spaceBefore = spacing.before;
535
+ }
536
+ // 段后间距
537
+ let spaceAfter = 0;
538
+ if (spacing?.afterAutoSpacing) {
539
+ spaceAfter = AUTO_SPACING_TWIPS;
540
+ }
541
+ else if (spacing?.after != null) {
542
+ spaceAfter = spacing.after;
543
+ }
544
+ // 确定段落字号
545
+ const fontSize = getMaxRunFontSize(para.children, getParagraphFontSize(props, defaultFontSize));
546
+ // 计算行高
547
+ const lineHeight = computeLineHeight(spacing, fontSize);
548
+ // Check if inline images increase the effective line height
549
+ const imgMaxHeight = getInlineImageMaxHeight(para.children);
550
+ const effectiveLineHeight = Math.max(lineHeight, imgMaxHeight);
551
+ // 计算行数
552
+ let lineCount;
553
+ if (measureTextFn) {
554
+ // 精确测量:考虑首行/后续行不同宽度
555
+ const [firstLineW, subsequentW] = computeParagraphLineWidths(props, availableWidth);
556
+ const textWidthPt = measureParagraphTextWidth(para.children, defaultFontSize, measureTextFn);
557
+ const textWidthTwips = textWidthPt * 20; // 1pt = 20 twips
558
+ // Count hard line breaks in the paragraph
559
+ const breakCount = countBreakElements(para.children);
560
+ if (breakCount > 0) {
561
+ // If there are hard breaks, use word-based line counting for accuracy
562
+ const charWidth = averageCharWidth > 0 ? averageCharWidth : 120;
563
+ const tabStops = props?.tabs?.map(t => t.position).filter((p) => p != null);
564
+ lineCount = computeLineCountWordBased(para.children, firstLineW, subsequentW, charWidth, tabStops);
565
+ }
566
+ else if (textWidthTwips <= firstLineW) {
567
+ lineCount = 1;
568
+ }
569
+ else {
570
+ // First line fills firstLineW, remaining fills subsequentW
571
+ const remaining = textWidthTwips - firstLineW;
572
+ lineCount = 1 + Math.max(1, Math.ceil(remaining / subsequentW));
573
+ }
574
+ }
575
+ else {
576
+ // Word-based line breaking with CJK awareness and tab stop support
577
+ const [firstLineW, subsequentW] = computeParagraphLineWidths(props, availableWidth);
578
+ const charWidth = averageCharWidth > 0 ? averageCharWidth : 120;
579
+ // Extract tab stop positions from paragraph properties
580
+ const tabStops = props?.tabs?.map(t => t.position).filter((p) => p != null);
581
+ lineCount = computeLineCountWordBased(para.children, firstLineW, subsequentW, charWidth, tabStops);
582
+ }
583
+ return spaceBefore + lineCount * effectiveLineHeight + spaceAfter;
584
+ }
585
+ /** 估算表格单行高度 (twips),考虑单元格内容 */
586
+ function estimateRowHeight(table, rowIndex, defaultFontSize, availableWidth, defaultCharsPerLine, averageCharWidth, measureTextFn) {
587
+ const row = table.rows[rowIndex];
588
+ // If explicit height is set with "exact" rule, use it directly
589
+ if (row.properties?.height?.value) {
590
+ const rule = row.properties.height.rule;
591
+ if (rule === "exact") {
592
+ return row.properties.height.value;
593
+ }
594
+ }
595
+ // Calculate the maximum content height across all cells in this row
596
+ const colCount = row.cells.length;
597
+ const colWidths = table.columnWidths;
598
+ let maxCellHeight = 0;
599
+ for (let c = 0; c < colCount; c++) {
600
+ const cell = row.cells[c];
601
+ // Estimate cell width from column widths or divide equally
602
+ let cellWidth;
603
+ if (colWidths && c < colWidths.length) {
604
+ const gridSpan = cell.properties?.gridSpan ?? 1;
605
+ cellWidth = 0;
606
+ for (let g = 0; g < gridSpan && c + g < colWidths.length; g++) {
607
+ cellWidth += colWidths[c + g];
608
+ }
609
+ }
610
+ else {
611
+ cellWidth = Math.floor(availableWidth / Math.max(1, colCount));
612
+ }
613
+ // Subtract cell margins (default ~108 twips each side in Word)
614
+ const cellMarginLeft = 108;
615
+ const cellMarginRight = 108;
616
+ const cellContentWidth = Math.max(1, cellWidth - cellMarginLeft - cellMarginRight);
617
+ // Calculate height of cell content (paragraphs + nested tables)
618
+ let cellHeight = 0;
619
+ for (const content of cell.content) {
620
+ if (content.type === "paragraph") {
621
+ cellHeight += estimateParagraphHeight(content, cellContentWidth, defaultFontSize, defaultCharsPerLine, averageCharWidth, measureTextFn);
622
+ }
623
+ else if (content.type === "table") {
624
+ cellHeight += estimateTableHeight(content, defaultFontSize, cellContentWidth, defaultCharsPerLine, averageCharWidth, measureTextFn);
625
+ }
626
+ }
627
+ // Add cell top/bottom padding (default ~40 twips each)
628
+ cellHeight += 80;
629
+ if (cellHeight > maxCellHeight) {
630
+ maxCellHeight = cellHeight;
631
+ }
632
+ }
633
+ // Respect "atLeast" height constraint
634
+ if (row.properties?.height?.value) {
635
+ return Math.max(row.properties.height.value, maxCellHeight);
636
+ }
637
+ // Minimum height: at least one line
638
+ const minHeight = baseLineHeight(defaultFontSize) + 80;
639
+ return Math.max(minHeight, maxCellHeight);
640
+ }
641
+ /** 估算表格总高度 (twips) */
642
+ function estimateTableHeight(table, defaultFontSize, availableWidth, defaultCharsPerLine, averageCharWidth, measureTextFn) {
643
+ let total = 0;
644
+ for (let i = 0; i < table.rows.length; i++) {
645
+ total += estimateRowHeight(table, i, defaultFontSize, availableWidth, defaultCharsPerLine, averageCharWidth, measureTextFn);
646
+ }
647
+ return total;
648
+ }
649
+ /** EMU → twips 转换 (1 inch = 914400 EMU = 1440 twips) */
650
+ function emuToTwips(emu) {
651
+ return Math.round(emu / 635);
652
+ }
653
+ /** 计算浮动图片在文档流中占用的高度 (twips)。
654
+ * - "topAndBottom" 包裹模式:图片占据垂直空间
655
+ * - 其他浮动模式:不占用正文流空间
656
+ */
657
+ function estimateFloatingImageHeight(img) {
658
+ const wrapStyle = img.wrap?.style;
659
+ // topAndBottom wrapping style causes the image to consume vertical space
660
+ if (wrapStyle === "topAndBottom") {
661
+ return emuToTwips(img.height);
662
+ }
663
+ // All other floating modes don't consume flow space
664
+ return 0;
665
+ }
666
+ /** 计算 DrawingShape 在文档流中占用的高度 (twips)。 */
667
+ function estimateDrawingShapeHeight(shape) {
668
+ const wrapStyle = shape.wrap?.style;
669
+ // topAndBottom wrapping style causes the shape to consume vertical space
670
+ if (wrapStyle === "topAndBottom") {
671
+ return emuToTwips(shape.height);
672
+ }
673
+ // Inline/no-wrap shapes that appear in body content consume flow space
674
+ if (!wrapStyle || wrapStyle === "none") {
675
+ return emuToTwips(shape.height);
676
+ }
677
+ return 0;
678
+ }
679
+ /** 计算可用列宽(考虑多栏布局) */
680
+ function computeColumnWidth(availableWidth, columns) {
681
+ if (!columns) {
682
+ return availableWidth;
683
+ }
684
+ const count = columns.count ?? 1;
685
+ if (count <= 1) {
686
+ return availableWidth;
687
+ }
688
+ const space = columns.space ?? 720; // 默认 0.5 inch 间距
689
+ // 总宽度 = count * colWidth + (count - 1) * space
690
+ // colWidth = (totalWidth - (count - 1) * space) / count
691
+ return Math.max(1, Math.floor((availableWidth - (count - 1) * space) / count));
692
+ }
693
+ /** 收集段落中的书签 */
694
+ function collectBookmarks(children, currentPage, bookmarkPages) {
695
+ for (const child of children) {
696
+ if ("type" in child &&
697
+ child.type === "bookmarkStart" &&
698
+ "name" in child) {
699
+ const bookmark = child;
700
+ bookmarkPages.set(bookmark.name, currentPage);
701
+ }
702
+ }
703
+ }
704
+ // =============================================================================
705
+ // Main Layout Function
706
+ // =============================================================================
707
+ /**
708
+ * 对文档进行分页布局计算。
709
+ * 返回每个 body content 所在的页码和总页数。
710
+ */
711
+ function layoutDocument(doc, options) {
712
+ const defaultFontSize = options?.defaultFontSize ?? DEFAULT_FONT_SIZE_HALF_PT;
713
+ const defaultCharsPerLine = options?.defaultCharsPerLine ?? DEFAULT_CHARS_PER_LINE;
714
+ // 平均字符宽度 (twips): 12pt 字体约 6pt 宽 = 120 twips
715
+ const averageCharWidth = options?.averageCharWidth ?? Math.round((defaultFontSize / 2) * 0.5 * 20);
716
+ const measureTextFn = options?.measureText;
717
+ const body = doc.body;
718
+ const contentPages = [];
719
+ const contentSections = [];
720
+ const bookmarkPages = new Map();
721
+ const sectionPageCounts = [];
722
+ // 布局状态
723
+ let currentPage = 1; // 1-based 页码
724
+ let currentSection = 0; // 0-based 节号
725
+ let sectionStartPage = 1; // 当前节起始页码
726
+ let currentY = 0; // 当前页面 Y 偏移 (twips from top of content area)
727
+ // 多栏状态
728
+ let currentColumn = 0; // 当前列(0-based)
729
+ let columnCount = 1; // 当前节的列数
730
+ // 当前节的页面属性(从最后一个 section properties 开始)
731
+ // 文档结构:每个节的 SectionProperties 出现在该节最后一个段落的属性中,
732
+ // 而文档最终节的属性在 doc.sectionProperties 中
733
+ let currentSectionProps = findFirstSectionProps(body) ?? doc.sectionProperties;
734
+ let availableHeight = computeAvailableHeight(currentSectionProps);
735
+ let availableWidth = computeAvailableWidth(currentSectionProps);
736
+ // 实际可用列宽(考虑多栏)
737
+ let effectiveWidth = computeColumnWidth(availableWidth, currentSectionProps?.columns);
738
+ /** 更新列数和有效宽度 */
739
+ function updateColumnLayout() {
740
+ columnCount = currentSectionProps?.columns?.count ?? 1;
741
+ if (columnCount < 1) {
742
+ columnCount = 1;
743
+ }
744
+ effectiveWidth = computeColumnWidth(availableWidth, currentSectionProps?.columns);
745
+ }
746
+ // 初始化多栏
747
+ updateColumnLayout();
748
+ /** 开始新页 */
749
+ function newPage() {
750
+ currentPage++;
751
+ currentY = 0;
752
+ currentColumn = 0;
753
+ }
754
+ /** 进入下一列(多栏布局),如果已在最后一列则换页 */
755
+ function nextColumn() {
756
+ if (columnCount > 1 && currentColumn < columnCount - 1) {
757
+ currentColumn++;
758
+ currentY = 0;
759
+ }
760
+ else {
761
+ newPage();
762
+ }
763
+ }
764
+ /** 开始新节 */
765
+ function newSection(breakType, nextSectionProps) {
766
+ // 记录当前节的页数
767
+ sectionPageCounts.push(currentPage - sectionStartPage + 1);
768
+ currentSection++;
769
+ const nextProps = nextSectionProps ?? doc.sectionProperties;
770
+ switch (breakType) {
771
+ case "nextPage":
772
+ newPage();
773
+ break;
774
+ case "evenPage": {
775
+ // 跳到下一个偶数页
776
+ newPage();
777
+ if (currentPage % 2 !== 0) {
778
+ newPage();
779
+ }
780
+ break;
781
+ }
782
+ case "oddPage": {
783
+ // 跳到下一个奇数页
784
+ newPage();
785
+ if (currentPage % 2 !== 1) {
786
+ newPage();
787
+ }
788
+ break;
789
+ }
790
+ case "continuous": {
791
+ // 如果页面设置(尺寸)改变,则需要分页
792
+ const currentWidth = currentSectionProps?.pageSize?.width ?? layout_constants_1.DEFAULT_PAGE_WIDTH_TWIPS;
793
+ const currentHeight = currentSectionProps?.pageSize?.height ?? layout_constants_1.DEFAULT_PAGE_HEIGHT_TWIPS;
794
+ const nextWidth = nextProps?.pageSize?.width ?? layout_constants_1.DEFAULT_PAGE_WIDTH_TWIPS;
795
+ const nextHeight = nextProps?.pageSize?.height ?? layout_constants_1.DEFAULT_PAGE_HEIGHT_TWIPS;
796
+ if (currentWidth !== nextWidth || currentHeight !== nextHeight) {
797
+ newPage();
798
+ }
799
+ // 否则继续在当前位置
800
+ break;
801
+ }
802
+ case "nextColumn":
803
+ // 多栏布局下进入下一列
804
+ nextColumn();
805
+ break;
806
+ }
807
+ sectionStartPage = currentPage;
808
+ currentSectionProps = nextProps;
809
+ availableHeight = computeAvailableHeight(currentSectionProps);
810
+ availableWidth = computeAvailableWidth(currentSectionProps);
811
+ updateColumnLayout();
812
+ }
813
+ /** 尝试在当前页添加内容,如果放不下则分页 */
814
+ function addContent(height) {
815
+ if (currentY + height > availableHeight && currentY > 0) {
816
+ // 当前页/列放不下,移到下一页/列
817
+ if (columnCount > 1 && currentColumn < columnCount - 1) {
818
+ nextColumn();
819
+ }
820
+ else {
821
+ newPage();
822
+ }
823
+ }
824
+ currentY += height;
825
+ }
826
+ /** 表格跨页布局:逐行分配,处理 cantSplit 和 header 行重复 */
827
+ function layoutTable(table) {
828
+ const totalHeight = estimateTableHeight(table, defaultFontSize, effectiveWidth, defaultCharsPerLine, averageCharWidth, measureTextFn);
829
+ // 快速路径:如果表格整体能放入当前页剩余空间,直接放入
830
+ if (currentY + totalHeight <= availableHeight) {
831
+ currentY += totalHeight;
832
+ return;
833
+ }
834
+ // 如果当前页完全空且表格仍放不下,则需要跨页处理
835
+ // 如果当前页非空且放不下第一行,先换页
836
+ const firstRowHeight = estimateRowHeight(table, 0, defaultFontSize, effectiveWidth, defaultCharsPerLine, averageCharWidth, measureTextFn);
837
+ if (currentY > 0 && currentY + firstRowHeight > availableHeight) {
838
+ if (columnCount > 1 && currentColumn < columnCount - 1) {
839
+ nextColumn();
840
+ }
841
+ else {
842
+ newPage();
843
+ }
844
+ }
845
+ // 确定 header 行(tableHeader = true 的行在每页重复)
846
+ let headerHeight = 0;
847
+ const headerRows = [];
848
+ for (let r = 0; r < table.rows.length; r++) {
849
+ if (table.rows[r].properties?.tableHeader) {
850
+ headerRows.push(r);
851
+ headerHeight += estimateRowHeight(table, r, defaultFontSize, effectiveWidth, defaultCharsPerLine, averageCharWidth, measureTextFn);
852
+ }
853
+ else {
854
+ break; // header 行必须从第一行开始连续
855
+ }
856
+ }
857
+ // 逐行布局
858
+ for (let r = 0; r < table.rows.length; r++) {
859
+ const row = table.rows[r];
860
+ const rowHeight = estimateRowHeight(table, r, defaultFontSize, effectiveWidth, defaultCharsPerLine, averageCharWidth, measureTextFn);
861
+ // header 行在新页开头已经由 headerHeight 预留
862
+ if (headerRows.includes(r)) {
863
+ // header 行直接放入
864
+ currentY += rowHeight;
865
+ continue;
866
+ }
867
+ // cantSplit: 该行不能被分页拆分 — 如果放不下,必须整行移到下一页
868
+ const cantSplit = row.properties?.cantSplit ?? false;
869
+ if (cantSplit || rowHeight <= availableHeight) {
870
+ // 检查当前页是否还能放下这一行
871
+ if (currentY + rowHeight > availableHeight) {
872
+ // 需要换页/换列
873
+ if (columnCount > 1 && currentColumn < columnCount - 1) {
874
+ nextColumn();
875
+ }
876
+ else {
877
+ newPage();
878
+ }
879
+ // 新页顶部先放 header 行
880
+ currentY += headerHeight;
881
+ }
882
+ }
883
+ else {
884
+ // 行高超过整个页面高度(极端情况),只能直接放
885
+ if (currentY + rowHeight > availableHeight && currentY > 0) {
886
+ if (columnCount > 1 && currentColumn < columnCount - 1) {
887
+ nextColumn();
888
+ }
889
+ else {
890
+ newPage();
891
+ }
892
+ currentY += headerHeight;
893
+ }
894
+ }
895
+ currentY += rowHeight;
896
+ }
897
+ }
898
+ // =========================================================================
899
+ // 遍历 body content
900
+ // =========================================================================
901
+ for (let i = 0; i < body.length; i++) {
902
+ const item = body[i];
903
+ switch (item.type) {
904
+ case "paragraph": {
905
+ const para = item;
906
+ const props = para.properties;
907
+ // 收集书签
908
+ collectBookmarks(para.children, currentPage, bookmarkPages);
909
+ // 检查段落 sectionProperties(节内分节符)
910
+ // 注意:带 sectionProperties 的段落是其所属节的最后一个段落
911
+ // sectionProperties 定义了当前节的页面设置
912
+ if (props?.sectionProperties) {
913
+ // 先渲染该段落本身
914
+ const paraHeight = estimateParagraphHeight(para, effectiveWidth, defaultFontSize, defaultCharsPerLine, averageCharWidth, measureTextFn);
915
+ handleParagraphLayout(para, paraHeight, i, body);
916
+ contentPages.push(currentPage);
917
+ contentSections.push(currentSection);
918
+ // 然后开始新节
919
+ const nextSP = findNextSectionProps(body, i + 1) ?? doc.sectionProperties;
920
+ newSection(props.sectionProperties.breakType ?? "nextPage", nextSP);
921
+ break;
922
+ }
923
+ // pageBreakBefore: 强制在段落前分页
924
+ if (props?.pageBreakBefore && currentY > 0) {
925
+ newPage();
926
+ }
927
+ // 检查 run 中是否有 page break
928
+ if (hasPageBreakInRuns(para.children) && currentY > 0) {
929
+ newPage();
930
+ }
931
+ // column break: 多栏布局下进入下一列
932
+ if (hasColumnBreakInRuns(para.children) && currentY > 0) {
933
+ nextColumn();
934
+ }
935
+ const paraHeight = estimateParagraphHeight(para, effectiveWidth, defaultFontSize, defaultCharsPerLine, averageCharWidth, measureTextFn);
936
+ handleParagraphLayout(para, paraHeight, i, body);
937
+ contentPages.push(currentPage);
938
+ contentSections.push(currentSection);
939
+ break;
940
+ }
941
+ case "table": {
942
+ const tableStartPage = currentPage;
943
+ layoutTable(item);
944
+ contentPages.push(tableStartPage);
945
+ contentSections.push(currentSection);
946
+ break;
947
+ }
948
+ default: {
949
+ // FloatingImage, TableOfContents, MathBlock, TextBox, CheckBox,
950
+ // DrawingShape, OpaqueDrawing, ChartContent, AltChunk, SDT
951
+ const minHeight = baseLineHeight(defaultFontSize);
952
+ if (item.type === "tableOfContents") {
953
+ // TOC 通常有多个段落
954
+ const tocParas = item.cachedParagraphs;
955
+ const tocHeight = tocParas
956
+ ? tocParas.length * baseLineHeight(defaultFontSize)
957
+ : minHeight * 5;
958
+ addContent(tocHeight);
959
+ }
960
+ else if (item.type === "floatingImage") {
961
+ // 根据 wrap style 判断是否占用正文流空间
962
+ const imgHeight = estimateFloatingImageHeight(item);
963
+ if (imgHeight > 0) {
964
+ addContent(imgHeight);
965
+ }
966
+ // 其他浮动模式不占用正文流空间
967
+ }
968
+ else if (item.type === "drawingShape") {
969
+ // 根据 wrap style 和尺寸计算占用高度
970
+ const shapeHeight = estimateDrawingShapeHeight(item);
971
+ if (shapeHeight > 0) {
972
+ addContent(shapeHeight);
973
+ }
974
+ else {
975
+ addContent(minHeight);
976
+ }
977
+ }
978
+ else {
979
+ addContent(minHeight);
980
+ }
981
+ contentPages.push(currentPage);
982
+ contentSections.push(currentSection);
983
+ break;
984
+ }
985
+ }
986
+ }
987
+ // 记录最后一个节的页数
988
+ sectionPageCounts.push(currentPage - sectionStartPage + 1);
989
+ return {
990
+ pageCount: currentPage,
991
+ sectionPageCounts,
992
+ contentPages,
993
+ contentSections,
994
+ bookmarkPages
995
+ };
996
+ // =========================================================================
997
+ // 段落布局辅助(处理 keepNext, keepLines, widowControl, orphanControl)
998
+ // =========================================================================
999
+ function handleParagraphLayout(para, paraHeight, index, bodyContent) {
1000
+ const props = para.properties;
1001
+ const spacing = props?.spacing;
1002
+ const fontSize = getMaxRunFontSize(para.children, getParagraphFontSize(props, defaultFontSize));
1003
+ const lineHeight = computeLineHeight(spacing, fontSize);
1004
+ // 计算段落行数(CJK-aware)
1005
+ let lineCount;
1006
+ if (measureTextFn) {
1007
+ const [firstLineW, subsequentW] = computeParagraphLineWidths(props, effectiveWidth);
1008
+ const textWidthPt = measureParagraphTextWidth(para.children, defaultFontSize, measureTextFn);
1009
+ const textWidthTwips = textWidthPt * 20;
1010
+ // Count hard line breaks in the paragraph
1011
+ const breakCount = countBreakElements(para.children);
1012
+ if (breakCount > 0) {
1013
+ // If there are hard breaks, use word-based line counting for accuracy
1014
+ const charWidth = averageCharWidth > 0 ? averageCharWidth : 120;
1015
+ const tabStops = props?.tabs?.map(t => t.position).filter((p) => p != null);
1016
+ lineCount = computeLineCountWordBased(para.children, firstLineW, subsequentW, charWidth, tabStops);
1017
+ }
1018
+ else if (textWidthTwips <= firstLineW) {
1019
+ lineCount = 1;
1020
+ }
1021
+ else {
1022
+ lineCount = 1 + Math.max(1, Math.ceil((textWidthTwips - firstLineW) / subsequentW));
1023
+ }
1024
+ }
1025
+ else {
1026
+ const [firstLineW, subsequentW] = computeParagraphLineWidths(props, effectiveWidth);
1027
+ const charWidth = averageCharWidth > 0 ? averageCharWidth : 120;
1028
+ const tabStops = props?.tabs?.map(t => t.position).filter((p) => p != null);
1029
+ lineCount = computeLineCountWordBased(para.children, firstLineW, subsequentW, charWidth, tabStops);
1030
+ }
1031
+ // Contextual spacing: collapse space between paragraphs with same style
1032
+ if (props?.contextualSpacing && index > 0) {
1033
+ const prevItem = bodyContent[index - 1];
1034
+ if (prevItem.type === "paragraph" && prevItem.properties?.style === props.style) {
1035
+ // Collapse spaceBefore — already accounted for in paraHeight but we subtract it
1036
+ const spaceBefore = spacing?.before ?? 0;
1037
+ if (spaceBefore > 0) {
1038
+ // Adjust currentY back by the collapsed space
1039
+ currentY -= Math.min(spaceBefore, currentY);
1040
+ }
1041
+ }
1042
+ }
1043
+ // keepLines: 整段必须在同一页
1044
+ if (props?.keepLines) {
1045
+ if (currentY + paraHeight > availableHeight && currentY > 0) {
1046
+ if (columnCount > 1 && currentColumn < columnCount - 1) {
1047
+ nextColumn();
1048
+ }
1049
+ else {
1050
+ newPage();
1051
+ }
1052
+ }
1053
+ currentY += paraHeight;
1054
+ // Footnote space reservation
1055
+ reserveFootnoteSpace(para);
1056
+ return;
1057
+ }
1058
+ // widowControl: 避免只有 1 行在当前页(至少 2 行,或者整段移走)
1059
+ // orphanControl: 避免最后 1 行单独在下一页(确保至少 2 行在下一页)
1060
+ if (props?.widowControl !== false && lineCount > 1) {
1061
+ let spaceBefore = 0;
1062
+ if (spacing?.beforeAutoSpacing) {
1063
+ spaceBefore = AUTO_SPACING_TWIPS;
1064
+ }
1065
+ else if (spacing?.before != null) {
1066
+ spaceBefore = spacing.before;
1067
+ }
1068
+ const remainingSpace = availableHeight - currentY;
1069
+ const linesOnCurrentPage = Math.floor(Math.max(0, remainingSpace - spaceBefore) / lineHeight);
1070
+ // Widow: only 1 line fits on current page → move whole paragraph
1071
+ if (linesOnCurrentPage === 1 && lineCount > 1) {
1072
+ if (currentY > 0) {
1073
+ if (columnCount > 1 && currentColumn < columnCount - 1) {
1074
+ nextColumn();
1075
+ }
1076
+ else {
1077
+ newPage();
1078
+ }
1079
+ }
1080
+ }
1081
+ // Orphan: only 1 line would be on next page → keep one more line with it
1082
+ else if (linesOnCurrentPage > 0 && linesOnCurrentPage === lineCount - 1) {
1083
+ // Move one line from current page to keep 2 lines on next page
1084
+ // Effectively: move (lineCount - linesOnCurrentPage + 1) lines to next page
1085
+ // → keep (linesOnCurrentPage - 1) lines on current page
1086
+ if (linesOnCurrentPage > 2) {
1087
+ // Can safely split: leave (lines - 2) on current page, 2 on next
1088
+ // Do nothing special — just let it split naturally, but ensure at least 2 on next
1089
+ // The simplest approach: move whole paragraph if splitting would leave orphan
1090
+ if (currentY > 0) {
1091
+ if (columnCount > 1 && currentColumn < columnCount - 1) {
1092
+ nextColumn();
1093
+ }
1094
+ else {
1095
+ newPage();
1096
+ }
1097
+ }
1098
+ }
1099
+ }
1100
+ }
1101
+ // keepNext: 当前段落需要和下一个段落在同一页
1102
+ if (props?.keepNext && index + 1 < bodyContent.length) {
1103
+ const nextItem = bodyContent[index + 1];
1104
+ if (nextItem.type === "paragraph") {
1105
+ const nextHeight = estimateParagraphHeight(nextItem, effectiveWidth, defaultFontSize, defaultCharsPerLine, averageCharWidth, measureTextFn);
1106
+ // 如果两个段落一起放不下当前页,把当前段移到下一页
1107
+ if (currentY + paraHeight + nextHeight > availableHeight && currentY > 0) {
1108
+ if (columnCount > 1 && currentColumn < columnCount - 1) {
1109
+ nextColumn();
1110
+ }
1111
+ else {
1112
+ newPage();
1113
+ }
1114
+ }
1115
+ }
1116
+ }
1117
+ // 普通添加
1118
+ addContent(paraHeight);
1119
+ // Footnote space reservation
1120
+ reserveFootnoteSpace(para);
1121
+ }
1122
+ /**
1123
+ * Reserve space at the bottom of the page for footnotes.
1124
+ * Each footnote reference in a paragraph adds to the page's footnote area.
1125
+ */
1126
+ function reserveFootnoteSpace(para) {
1127
+ const fnCount = countFootnoteRefs(para.children);
1128
+ if (fnCount > 0) {
1129
+ // Add footnote separator once per page (tracked implicitly by adding space)
1130
+ const fnSpace = FOOTNOTE_SEPARATOR_HEIGHT + fnCount * FOOTNOTE_ENTRY_HEIGHT;
1131
+ // Reduce available height for this page
1132
+ // We implement this by advancing currentY (simplification)
1133
+ currentY += fnSpace;
1134
+ // If this pushes us past the page, let normal pagination handle it
1135
+ if (currentY > availableHeight) {
1136
+ newPage();
1137
+ }
1138
+ }
1139
+ }
1140
+ }
1141
+ // =============================================================================
1142
+ // Section Properties Lookup Helpers
1143
+ // =============================================================================
1144
+ /**
1145
+ * 在 body 中查找第一个节的 SectionProperties。
1146
+ * 文档中,每个节(除最后一节)的属性在该节最后一个段落的 pPr/sectPr 中。
1147
+ * 这里找第一个含 sectionProperties 的段落之前的区域所适用的属性。
1148
+ * 由于第一个节的属性就是第一个 sectPr(如果存在),我们返回它。
1149
+ */
1150
+ function findFirstSectionProps(body) {
1151
+ for (const item of body) {
1152
+ if (item.type === "paragraph" && item.properties?.sectionProperties) {
1153
+ return item.properties.sectionProperties;
1154
+ }
1155
+ }
1156
+ return undefined;
1157
+ }
1158
+ /**
1159
+ * 从指定位置开始查找下一个节的 SectionProperties。
1160
+ * 返回 body[startIndex..] 中第一个包含 sectionProperties 的段落的 sectionProperties。
1161
+ */
1162
+ function findNextSectionProps(body, startIndex) {
1163
+ for (let i = startIndex; i < body.length; i++) {
1164
+ const item = body[i];
1165
+ if (item.type === "paragraph" && item.properties?.sectionProperties) {
1166
+ return item.properties.sectionProperties;
1167
+ }
1168
+ }
1169
+ return undefined;
1170
+ }