reamkit 1.15.1 → 1.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (316) hide show
  1. package/dist/esm/core/arc-to-bezier.d.ts +23 -0
  2. package/dist/esm/core/arc-to-bezier.js +23 -0
  3. package/dist/esm/core/bidi/algorithm.d.ts +26 -0
  4. package/dist/esm/core/bidi/algorithm.js +21 -0
  5. package/dist/esm/core/bidi/char-types.d.ts +17 -0
  6. package/dist/esm/core/bidi/char-types.js +10 -0
  7. package/dist/esm/core/bidi/index.d.ts +42 -0
  8. package/dist/esm/core/bidi/index.js +27 -0
  9. package/dist/esm/core/bidi/segments.d.ts +22 -0
  10. package/dist/esm/core/bidi/segments.js +14 -0
  11. package/dist/esm/core/bytes.d.ts +20 -0
  12. package/dist/esm/core/bytes.js +24 -1
  13. package/dist/esm/core/converter/facade.d.ts +38 -1
  14. package/dist/esm/core/converter/facade.js +25 -0
  15. package/dist/esm/core/converter/project.d.ts +12 -0
  16. package/dist/esm/core/converter/project.js +11 -0
  17. package/dist/esm/core/converter/ream.d.ts +107 -0
  18. package/dist/esm/core/converter/ream.js +76 -0
  19. package/dist/esm/core/crypto/asn1.d.ts +77 -0
  20. package/dist/esm/core/crypto/asn1.js +65 -0
  21. package/dist/esm/core/crypto/cms.d.ts +25 -0
  22. package/dist/esm/core/crypto/cms.js +8 -0
  23. package/dist/esm/core/document-model/index.d.ts +7 -0
  24. package/dist/esm/core/document-model/types.d.ts +328 -0
  25. package/dist/esm/core/drawingml/chart-geometry.d.ts +125 -0
  26. package/dist/esm/core/drawingml/chart-geometry.js +96 -0
  27. package/dist/esm/core/drawingml/chart-parser.d.ts +34 -0
  28. package/dist/esm/core/drawingml/chart-parser.js +34 -0
  29. package/dist/esm/core/drawingml/chart-serializer.d.ts +12 -0
  30. package/dist/esm/core/drawingml/chart-serializer.js +12 -0
  31. package/dist/esm/core/drawingml/colors.d.ts +53 -0
  32. package/dist/esm/core/drawingml/colors.js +41 -0
  33. package/dist/esm/core/drawingml/preset-geometry.d.ts +30 -0
  34. package/dist/esm/core/drawingml/preset-geometry.js +30 -0
  35. package/dist/esm/core/drawingml/shape-render.d.ts +54 -0
  36. package/dist/esm/core/drawingml/shape-render.js +54 -0
  37. package/dist/esm/core/drawingml/sparkline-geometry.d.ts +15 -0
  38. package/dist/esm/core/drawingml/sparkline-geometry.js +13 -0
  39. package/dist/esm/core/drawingml/theme-parser.d.ts +11 -0
  40. package/dist/esm/core/drawingml/theme-parser.js +11 -0
  41. package/dist/esm/core/font/arabic-joining.d.ts +21 -0
  42. package/dist/esm/core/font/arabic-joining.js +16 -0
  43. package/dist/esm/core/font/binary-reader.d.ts +17 -0
  44. package/dist/esm/core/font/binary-reader.js +17 -0
  45. package/dist/esm/core/font/font-registry.d.ts +37 -0
  46. package/dist/esm/core/font/font-registry.js +31 -0
  47. package/dist/esm/core/font/measure.d.ts +20 -0
  48. package/dist/esm/core/font/measure.js +11 -0
  49. package/dist/esm/core/font/opentype-layout.d.ts +49 -0
  50. package/dist/esm/core/font/opentype-layout.js +37 -0
  51. package/dist/esm/core/font/ttf-parser.d.ts +32 -0
  52. package/dist/esm/core/font/ttf-parser.js +7 -0
  53. package/dist/esm/core/font/ttf-subset.d.ts +21 -0
  54. package/dist/esm/core/font/ttf-subset.js +21 -0
  55. package/dist/esm/core/fonts/provider.d.ts +8 -1
  56. package/dist/esm/core/fonts/provider.js +1 -0
  57. package/dist/esm/core/fonts/remote-fonts.d.ts +22 -0
  58. package/dist/esm/core/fonts/remote-fonts.js +16 -0
  59. package/dist/esm/core/hyphenation/index.d.ts +25 -0
  60. package/dist/esm/core/hyphenation/index.js +17 -0
  61. package/dist/esm/core/hyphenation/liang.d.ts +27 -0
  62. package/dist/esm/core/hyphenation/liang.js +14 -0
  63. package/dist/esm/core/images.d.ts +32 -0
  64. package/dist/esm/core/images.js +12 -0
  65. package/dist/esm/core/ir/adapters.d.ts +23 -0
  66. package/dist/esm/core/ir/features.d.ts +8 -0
  67. package/dist/esm/core/ir/features.js +1 -0
  68. package/dist/esm/core/ir/flow.d.ts +20 -0
  69. package/dist/esm/core/ir/index.d.ts +7 -0
  70. package/dist/esm/core/ir/loss.d.ts +12 -0
  71. package/dist/esm/core/ir/loss.js +8 -0
  72. package/dist/esm/core/ir/resources.d.ts +12 -0
  73. package/dist/esm/core/ir/resources.js +11 -0
  74. package/dist/esm/core/ir/sheet.d.ts +81 -0
  75. package/dist/esm/core/ir/units.d.ts +9 -0
  76. package/dist/esm/core/ir/units.js +2 -0
  77. package/dist/esm/core/line-breaker/cjk.d.ts +26 -0
  78. package/dist/esm/core/line-breaker/cjk.js +60 -0
  79. package/dist/esm/core/line-breaker/greedy.d.ts +14 -0
  80. package/dist/esm/core/line-breaker/greedy.js +14 -0
  81. package/dist/esm/core/line-breaker/index.d.ts +1 -0
  82. package/dist/esm/core/line-breaker/index.js +3 -0
  83. package/dist/esm/core/line-breaker/knuth-plass.d.ts +29 -5
  84. package/dist/esm/core/line-breaker/knuth-plass.js +10 -5
  85. package/dist/esm/core/numbering/apply.d.ts +19 -0
  86. package/dist/esm/core/numbering/apply.js +19 -0
  87. package/dist/esm/core/numbering/state.d.ts +15 -0
  88. package/dist/esm/core/numbering/state.js +15 -0
  89. package/dist/esm/core/ole/cfb.d.ts +19 -0
  90. package/dist/esm/core/ole/cfb.js +16 -0
  91. package/dist/esm/core/opc/core-properties.d.ts +12 -0
  92. package/dist/esm/core/opc/core-properties.js +5 -0
  93. package/dist/esm/core/opc/opc-writer.d.ts +24 -4
  94. package/dist/esm/core/opc/opc-writer.js +12 -0
  95. package/dist/esm/core/opc/package.d.ts +55 -0
  96. package/dist/esm/core/opc/package.js +49 -1
  97. package/dist/esm/core/opc/relationship-types.d.ts +8 -0
  98. package/dist/esm/core/opc/relationship-types.js +5 -0
  99. package/dist/esm/core/opc/relationships.d.ts +12 -0
  100. package/dist/esm/core/opc/relationships.js +7 -0
  101. package/dist/esm/core/po-helpers.d.ts +38 -0
  102. package/dist/esm/core/po-helpers.js +33 -0
  103. package/dist/esm/core/spreadsheet-model/types.d.ts +302 -0
  104. package/dist/esm/core/style-cascade/resolver.d.ts +31 -0
  105. package/dist/esm/core/style-cascade/resolver.js +31 -0
  106. package/dist/esm/core/style-cascade/table.d.ts +7 -0
  107. package/dist/esm/core/style-cascade/table.js +7 -0
  108. package/dist/esm/core/style-cascade/types.d.ts +27 -0
  109. package/dist/esm/core/style-cascade/types.js +2 -0
  110. package/dist/esm/core/vector.d.ts +67 -0
  111. package/dist/esm/core/vector.js +23 -0
  112. package/dist/esm/excel/activex-parser.d.ts +31 -0
  113. package/dist/esm/excel/activex-parser.js +24 -0
  114. package/dist/esm/excel/cell-reference.d.ts +14 -0
  115. package/dist/esm/excel/cell-reference.js +9 -0
  116. package/dist/esm/excel/column-bands.d.ts +29 -0
  117. package/dist/esm/excel/column-bands.js +27 -7
  118. package/dist/esm/excel/comments-parser.d.ts +19 -0
  119. package/dist/esm/excel/comments-parser.js +19 -0
  120. package/dist/esm/excel/conditional-format.d.ts +38 -0
  121. package/dist/esm/excel/conditional-format.js +25 -0
  122. package/dist/esm/excel/defined-name-ref.d.ts +21 -0
  123. package/dist/esm/excel/defined-name-ref.js +20 -0
  124. package/dist/esm/excel/form-control-parser.d.ts +13 -0
  125. package/dist/esm/excel/form-control-parser.js +5 -0
  126. package/dist/esm/excel/formula/context.d.ts +37 -0
  127. package/dist/esm/excel/formula/dates.d.ts +23 -0
  128. package/dist/esm/excel/formula/dates.js +20 -0
  129. package/dist/esm/excel/formula/eval.d.ts +21 -0
  130. package/dist/esm/excel/formula/eval.js +11 -0
  131. package/dist/esm/excel/formula/functions.d.ts +12 -0
  132. package/dist/esm/excel/formula/functions.js +12 -0
  133. package/dist/esm/excel/formula/index.d.ts +21 -0
  134. package/dist/esm/excel/formula/index.js +16 -0
  135. package/dist/esm/excel/formula/lexer.d.ts +12 -0
  136. package/dist/esm/excel/formula/lexer.js +10 -0
  137. package/dist/esm/excel/formula/parser.d.ts +20 -0
  138. package/dist/esm/excel/formula/parser.js +53 -0
  139. package/dist/esm/excel/formula/value.d.ts +53 -0
  140. package/dist/esm/excel/formula/value.js +30 -0
  141. package/dist/esm/excel/header-footer.d.ts +9 -0
  142. package/dist/esm/excel/header-footer.js +9 -0
  143. package/dist/esm/excel/number-format.d.ts +34 -0
  144. package/dist/esm/excel/number-format.js +34 -0
  145. package/dist/esm/excel/pivot-table-parser.d.ts +8 -0
  146. package/dist/esm/excel/pivot-table-parser.js +8 -0
  147. package/dist/esm/excel/print-model.d.ts +77 -1
  148. package/dist/esm/excel/print-model.js +230 -26
  149. package/dist/esm/excel/shared-strings-parser.d.ts +13 -0
  150. package/dist/esm/excel/shared-strings-parser.js +5 -0
  151. package/dist/esm/excel/sheet-drawing.d.ts +34 -0
  152. package/dist/esm/excel/sheet-drawing.js +21 -0
  153. package/dist/esm/excel/sheet-shape-parser.d.ts +12 -0
  154. package/dist/esm/excel/sheet-shape-parser.js +12 -0
  155. package/dist/esm/excel/sheet-to-flow.d.ts +29 -0
  156. package/dist/esm/excel/sheet-to-flow.js +24 -7
  157. package/dist/esm/excel/slicer-parser.d.ts +23 -0
  158. package/dist/esm/excel/slicer-parser.js +10 -0
  159. package/dist/esm/excel/styles-parser.d.ts +8 -0
  160. package/dist/esm/excel/styles-parser.js +8 -0
  161. package/dist/esm/excel/table-parser.d.ts +24 -0
  162. package/dist/esm/excel/table-parser.js +5 -0
  163. package/dist/esm/excel/workbook-parser.d.ts +17 -0
  164. package/dist/esm/excel/workbook-parser.js +5 -0
  165. package/dist/esm/excel/worksheet-parser.d.ts +9 -0
  166. package/dist/esm/excel/worksheet-parser.js +39 -6
  167. package/dist/esm/excel/xls/biff-chart.d.ts +10 -0
  168. package/dist/esm/excel/xls/biff-chart.js +10 -0
  169. package/dist/esm/excel/xls/biff-reader.d.ts +27 -0
  170. package/dist/esm/excel/xls/biff-reader.js +44 -0
  171. package/dist/esm/excel/xls/biff-styles.d.ts +20 -0
  172. package/dist/esm/excel/xls/biff-styles.js +20 -0
  173. package/dist/esm/excel/xls/escher.d.ts +27 -0
  174. package/dist/esm/excel/xls/escher.js +18 -0
  175. package/dist/esm/excel/xls/xls-reader.d.ts +6 -0
  176. package/dist/esm/excel/xls/xls-reader.js +6 -0
  177. package/dist/esm/excel/xlsx-reader.d.ts +30 -0
  178. package/dist/esm/excel/xlsx-reader.js +38 -4
  179. package/dist/esm/excel/xlsx-to-pdf.d.ts +27 -0
  180. package/dist/esm/excel/xlsx-writer.d.ts +14 -0
  181. package/dist/esm/excel/xlsx-writer.js +13 -0
  182. package/dist/esm/html/html-writer.d.ts +18 -0
  183. package/dist/esm/html/html-writer.js +18 -0
  184. package/dist/esm/index.d.ts +23 -0
  185. package/dist/esm/layout/math-layout.d.ts +39 -0
  186. package/dist/esm/layout/math-layout.js +18 -0
  187. package/dist/esm/layout/page-doc.d.ts +91 -0
  188. package/dist/esm/layout/styled-layout.d.ts +175 -0
  189. package/dist/esm/layout/styled-layout.js +136 -4
  190. package/dist/esm/pdf/builtin-fonts.d.ts +5 -0
  191. package/dist/esm/pdf/cid-font.d.ts +22 -0
  192. package/dist/esm/pdf/cid-font.js +10 -0
  193. package/dist/esm/pdf/embedded-file.d.ts +16 -0
  194. package/dist/esm/pdf/embedded-file.js +9 -0
  195. package/dist/esm/pdf/encryption.d.ts +59 -0
  196. package/dist/esm/pdf/encryption.js +37 -0
  197. package/dist/esm/pdf/icc-profile.d.ts +8 -0
  198. package/dist/esm/pdf/icc-profile.js +8 -0
  199. package/dist/esm/pdf/image-xobject.d.ts +19 -0
  200. package/dist/esm/pdf/image-xobject.js +9 -0
  201. package/dist/esm/pdf/objects.d.ts +40 -0
  202. package/dist/esm/pdf/objects.js +36 -0
  203. package/dist/esm/pdf/serialize.d.ts +18 -0
  204. package/dist/esm/pdf/serialize.js +18 -0
  205. package/dist/esm/pdf/shading.d.ts +16 -0
  206. package/dist/esm/pdf/shading.js +16 -0
  207. package/dist/esm/pdf/signature.d.ts +36 -0
  208. package/dist/esm/pdf/signature.js +22 -0
  209. package/dist/esm/pdf/struct-tree.d.ts +64 -0
  210. package/dist/esm/pdf/struct-tree.js +60 -0
  211. package/dist/esm/pdf/styled-page-emitter.d.ts +33 -0
  212. package/dist/esm/pdf/styled-page-emitter.js +21 -0
  213. package/dist/esm/pdf/styled-page-renderer.d.ts +18 -0
  214. package/dist/esm/pdf/styled-page-renderer.js +18 -0
  215. package/dist/esm/pdf/text-encoding.d.ts +16 -0
  216. package/dist/esm/pdf/text-page-renderer.d.ts +11 -0
  217. package/dist/esm/pdf/vector-graphics.d.ts +12 -0
  218. package/dist/esm/pdf/vector-graphics.js +12 -0
  219. package/dist/esm/pdf/writer.d.ts +39 -0
  220. package/dist/esm/pdf/writer.js +27 -0
  221. package/dist/esm/pdf/xmp.d.ts +16 -0
  222. package/dist/esm/pdf/xmp.js +9 -0
  223. package/dist/esm/pdf-reader/ccitt.d.ts +25 -0
  224. package/dist/esm/pdf-reader/ccitt.js +15 -0
  225. package/dist/esm/pdf-reader/cmap.d.ts +12 -0
  226. package/dist/esm/pdf-reader/cmap.js +9 -0
  227. package/dist/esm/pdf-reader/content.d.ts +69 -0
  228. package/dist/esm/pdf-reader/content.js +16 -0
  229. package/dist/esm/pdf-reader/crypto.d.ts +5 -0
  230. package/dist/esm/pdf-reader/crypto.js +5 -0
  231. package/dist/esm/pdf-reader/decrypt.d.ts +17 -0
  232. package/dist/esm/pdf-reader/decrypt.js +12 -0
  233. package/dist/esm/pdf-reader/document.d.ts +53 -0
  234. package/dist/esm/pdf-reader/document.js +50 -0
  235. package/dist/esm/pdf-reader/flow-build.d.ts +47 -0
  236. package/dist/esm/pdf-reader/flow-build.js +42 -0
  237. package/dist/esm/pdf-reader/font.d.ts +12 -0
  238. package/dist/esm/pdf-reader/font.js +12 -0
  239. package/dist/esm/pdf-reader/image-decode.d.ts +21 -0
  240. package/dist/esm/pdf-reader/image-decode.js +14 -0
  241. package/dist/esm/pdf-reader/images.d.ts +19 -0
  242. package/dist/esm/pdf-reader/images.js +9 -0
  243. package/dist/esm/pdf-reader/layout.d.ts +15 -0
  244. package/dist/esm/pdf-reader/layout.js +15 -0
  245. package/dist/esm/pdf-reader/lexer.d.ts +43 -0
  246. package/dist/esm/pdf-reader/lexer.js +38 -0
  247. package/dist/esm/pdf-reader/parser.d.ts +15 -0
  248. package/dist/esm/pdf-reader/parser.js +8 -0
  249. package/dist/esm/pdf-reader/png-encode.d.ts +9 -0
  250. package/dist/esm/pdf-reader/png-encode.js +8 -0
  251. package/dist/esm/pdf-reader/predictor.d.ts +9 -0
  252. package/dist/esm/pdf-reader/predictor.js +8 -0
  253. package/dist/esm/pdf-reader/reader.d.ts +16 -0
  254. package/dist/esm/pdf-reader/reader.js +16 -0
  255. package/dist/esm/pdf-reader/shading.d.ts +10 -0
  256. package/dist/esm/pdf-reader/shading.js +10 -0
  257. package/dist/esm/pdf-reader/struct-tree.d.ts +24 -0
  258. package/dist/esm/pdf-reader/struct-tree.js +12 -0
  259. package/dist/esm/pdf-reader/tagged.d.ts +13 -0
  260. package/dist/esm/pdf-reader/tagged.js +13 -0
  261. package/dist/esm/pdf-reader/text.d.ts +11 -0
  262. package/dist/esm/pdf-reader/text.js +11 -0
  263. package/dist/esm/pdf-reader/vector.d.ts +19 -0
  264. package/dist/esm/pdf-reader/vector.js +9 -0
  265. package/dist/esm/pptx/placeholder-cascade.d.ts +21 -0
  266. package/dist/esm/pptx/placeholder-cascade.js +10 -0
  267. package/dist/esm/pptx/ppt/ppt-reader.d.ts +16 -0
  268. package/dist/esm/pptx/ppt/ppt-reader.js +16 -0
  269. package/dist/esm/pptx/ppt/ppt-text.d.ts +55 -0
  270. package/dist/esm/pptx/ppt/ppt-text.js +14 -0
  271. package/dist/esm/pptx/pptx-reader.d.ts +21 -0
  272. package/dist/esm/pptx/pptx-reader.js +23 -2
  273. package/dist/esm/pptx/slide-parser.d.ts +102 -0
  274. package/dist/esm/pptx/slide-parser.js +78 -0
  275. package/dist/esm/pptx/sp-helpers.d.ts +28 -0
  276. package/dist/esm/pptx/sp-helpers.js +22 -0
  277. package/dist/esm/svg/svg-writer.d.ts +17 -0
  278. package/dist/esm/svg/svg-writer.js +16 -0
  279. package/dist/esm/word/doc/doc-reader.d.ts +16 -0
  280. package/dist/esm/word/doc/doc-reader.js +16 -0
  281. package/dist/esm/word/doc/doc-text.d.ts +77 -0
  282. package/dist/esm/word/doc/doc-text.js +13 -0
  283. package/dist/esm/word/document-parser.d.ts +134 -0
  284. package/dist/esm/word/document-parser.js +86 -0
  285. package/dist/esm/word/docx-reader.d.ts +16 -0
  286. package/dist/esm/word/docx-reader.js +18 -2
  287. package/dist/esm/word/docx-to-pdf.d.ts +52 -0
  288. package/dist/esm/word/docx-to-pdf.js +21 -0
  289. package/dist/esm/word/docx-writer.d.ts +17 -0
  290. package/dist/esm/word/docx-writer.js +17 -0
  291. package/dist/esm/word/drawing-parser.d.ts +88 -0
  292. package/dist/esm/word/drawing-parser.js +68 -0
  293. package/dist/esm/word/font-table.d.ts +24 -0
  294. package/dist/esm/word/font-table.js +24 -0
  295. package/dist/esm/word/numbering-parser.d.ts +11 -0
  296. package/dist/esm/word/numbering-parser.js +11 -0
  297. package/dist/esm/word/omml-parser.d.ts +15 -0
  298. package/dist/esm/word/omml-parser.js +15 -0
  299. package/dist/esm/word/omml-serializer.d.ts +9 -0
  300. package/dist/esm/word/omml-serializer.js +9 -0
  301. package/dist/esm/word/paragraph-properties.d.ts +10 -0
  302. package/dist/esm/word/paragraph-properties.js +10 -0
  303. package/dist/esm/word/po-to-flat.d.ts +11 -0
  304. package/dist/esm/word/po-to-flat.js +11 -0
  305. package/dist/esm/word/run-properties.d.ts +10 -0
  306. package/dist/esm/word/run-properties.js +10 -0
  307. package/dist/esm/word/settings-parser.d.ts +13 -0
  308. package/dist/esm/word/settings-parser.js +8 -0
  309. package/dist/esm/word/styles-parser.d.ts +10 -0
  310. package/dist/esm/word/styles-parser.js +10 -0
  311. package/dist/esm/word/table-parser.d.ts +11 -0
  312. package/dist/esm/word/table-parser.js +11 -0
  313. package/dist/esm/word/text-extractor.d.ts +9 -0
  314. package/dist/esm/word/xml-helpers.d.ts +44 -0
  315. package/dist/esm/word/xml-helpers.js +38 -0
  316. package/package.json +5 -2
@@ -28,7 +28,17 @@ var RUN_CONTAINER_TAGS = new Set([
28
28
  "w:ins",
29
29
  "w:moveTo"
30
30
  ]);
31
+ /** The default {@link ParseContext} — just the default colour resolver. */
31
32
  var DEFAULT_PARSE_CONTEXT = { resolveColor: defaultColorResolver };
33
+ /**
34
+ * Parse `word/document.xml` (ECMA-376 Part 1 §17) into a flat list of
35
+ * {@link BodyElement}, preserving the original interleaving of paragraphs and
36
+ * tables.
37
+ *
38
+ * @param documentXml The raw `document.xml` bytes.
39
+ * @param ctx The document-wide parse context.
40
+ * @returns The body elements; empty when the `w:body` is absent.
41
+ */
32
42
  function parseDocument(documentXml, ctx = DEFAULT_PARSE_CONTEXT) {
33
43
  const xml = decoder.decode(documentXml);
34
44
  const body = poFindByPath(parser.parse(xml), ["w:document", "w:body"]);
@@ -40,10 +50,21 @@ var HF_TYPES = new Set([
40
50
  "first",
41
51
  "even"
42
52
  ]);
53
+ /** The empty {@link SectionProperties} fallback (no headers/footers). */
43
54
  var EMPTY_SECTION = {
44
55
  headers: [],
45
56
  footers: []
46
57
  };
58
+ /**
59
+ * Collect every section in the document (ECMA-376 §17.6): one `sectPr` per
60
+ * intermediate paragraph plus the body-final one. Each {@link Section} carries
61
+ * the exclusive `endIndex` into the body-element list, so section `i` applies to
62
+ * `body[sections[i-1].endIndex .. endIndex)`. A document with no `sectPr` at all
63
+ * returns a single empty section spanning the whole body.
64
+ *
65
+ * @param documentXml The raw `document.xml` bytes.
66
+ * @returns The sections in document order; empty when the `w:body` is absent.
67
+ */
47
68
  function parseSections(documentXml) {
48
69
  const xml = decoder.decode(documentXml);
49
70
  const body = poFindByPath(parser.parse(xml), ["w:document", "w:body"]);
@@ -151,11 +172,29 @@ function pushHeaderFooter(node, list) {
151
172
  relationshipId: rId
152
173
  });
153
174
  }
175
+ /**
176
+ * Parse `word/header*.xml` or `word/footer*.xml`. The root is `w:hdr` or
177
+ * `w:ftr`, whose children are the same body-element shape as the main document.
178
+ *
179
+ * @param xml The raw header/footer part bytes.
180
+ * @param ctx The document-wide parse context.
181
+ * @returns The body elements; empty when neither root is found.
182
+ */
154
183
  function parseHeaderFooter(xml, ctx = DEFAULT_PARSE_CONTEXT) {
155
184
  const root = parser.parse(decoder.decode(xml)).find((n) => poIs(n, "w:hdr") || poIs(n, "w:ftr"));
156
185
  if (!root) return [];
157
186
  return parseBodyElements(poChildren(root), ctx);
158
187
  }
188
+ /**
189
+ * Parse a sequence of body-level children (`w:p`, `w:tbl`, `w:sdt`,
190
+ * `w:bookmarkStart`) into {@link BodyElement}s, preserving order. A lone-drawing
191
+ * paragraph collapses to a standalone image/shape/chart block; a block-level SDT
192
+ * unwraps to its content; a body-level bookmark anchors onto the next paragraph.
193
+ *
194
+ * @param children The body-level child nodes.
195
+ * @param ctx The document-wide parse context.
196
+ * @returns The parsed body elements.
197
+ */
159
198
  function parseBodyElements(children, ctx = DEFAULT_PARSE_CONTEXT) {
160
199
  const out = [];
161
200
  let pendingBookmarks;
@@ -538,6 +577,17 @@ function parseRun(r, ctx) {
538
577
  function elementTag(node) {
539
578
  for (const key of Object.keys(node)) if (key !== ":@" && key !== "#text") return key;
540
579
  }
580
+ /**
581
+ * Parse `footnotes.xml` / `endnotes.xml` (§17.11) into note content by id. The
582
+ * separator / continuationSeparator / continuationNotice stubs (negative ids or
583
+ * an explicit `w:type`) are skipped — the layout draws its own separator.
584
+ *
585
+ * @param notesXml The raw notes-part bytes.
586
+ * @param rootTag The part's root element (`w:footnotes` or `w:endnotes`).
587
+ * @param noteTag The per-note element (`w:footnote` or `w:endnote`).
588
+ * @param ctx The document-wide parse context.
589
+ * @returns A map from note id to its body content.
590
+ */
541
591
  function parseNotes(notesXml, rootTag, noteTag, ctx = DEFAULT_PARSE_CONTEXT) {
542
592
  const xml = decoder.decode(notesXml);
543
593
  const root = poFindByPath(parser.parse(xml), [rootTag]);
@@ -588,6 +638,15 @@ function parseCommentsRaw(commentsXml, ctx) {
588
638
  paraIds
589
639
  };
590
640
  }
641
+ /**
642
+ * Parse `word/commentsExtended.xml` (Microsoft w15 `commentsEx`) — a flat list
643
+ * of `commentEx`, each keyed by a comment's `paraId`: `paraIdParent` links a
644
+ * reply to its parent, `done` flags a resolved thread. Prefix-agnostic (w15 by
645
+ * convention).
646
+ *
647
+ * @param xml The raw `commentsExtended.xml` bytes.
648
+ * @returns A map from `paraId` to its {@link CommentExtension}.
649
+ */
591
650
  function parseCommentsExtended(xml) {
592
651
  const tree = parser.parse(decoder.decode(xml));
593
652
  const out = /* @__PURE__ */ new Map();
@@ -627,11 +686,29 @@ function linkCommentThreads(comments, paraIdByComment, ext) {
627
686
  }
628
687
  return out;
629
688
  }
689
+ /**
690
+ * Read comments with their thread metadata: `comments.xml` for content /
691
+ * attribution plus the optional `commentsExtended.xml` for reply links and
692
+ * resolved flags (CM4). A reply gains `parentId`, a resolved thread gains `done`.
693
+ *
694
+ * @param commentsXml The raw `comments.xml` bytes.
695
+ * @param commentsExtendedXml The raw `commentsExtended.xml` bytes, or `undefined`.
696
+ * @param ctx The document-wide parse context.
697
+ * @returns A map from comment id to the parsed, thread-linked comment.
698
+ */
630
699
  function parseCommentThreads(commentsXml, commentsExtendedXml, ctx = DEFAULT_PARSE_CONTEXT) {
631
700
  const { comments, paraIds } = parseCommentsRaw(commentsXml, ctx);
632
701
  if (!commentsExtendedXml) return comments;
633
702
  return linkCommentThreads(comments, paraIds, parseCommentsExtended(commentsExtendedXml));
634
703
  }
704
+ /**
705
+ * Parse `word/people.xml` (Microsoft w15) — maps an author display name to a
706
+ * presence identity (`w15:presenceInfo/@w15:userId`, usually an email), used to
707
+ * enrich a comment's `authorId`. Prefix-agnostic.
708
+ *
709
+ * @param xml The raw `people.xml` bytes.
710
+ * @returns A map from author name to userId.
711
+ */
635
712
  function parsePeople(xml) {
636
713
  const tree = parser.parse(decoder.decode(xml));
637
714
  const out = /* @__PURE__ */ new Map();
@@ -651,6 +728,15 @@ function parsePeople(xml) {
651
728
  }
652
729
  return out;
653
730
  }
731
+ /**
732
+ * Attach each comment's `authorId` by matching its author name against the
733
+ * {@link parsePeople} map. Comments without a matching author pass through
734
+ * unchanged.
735
+ *
736
+ * @param comments The comments by id.
737
+ * @param people The author → userId map from `people.xml`.
738
+ * @returns The comments with `authorId` filled in where resolvable.
739
+ */
654
740
  function applyAuthorIds(comments, people) {
655
741
  if (people.size === 0) return comments;
656
742
  const out = /* @__PURE__ */ new Map();
@@ -1,4 +1,20 @@
1
1
  import { DocumentReader, ReadResult } from '../core/ir/adapters.js';
2
2
  import { FlowDoc } from '../core/ir/flow.js';
3
+ /**
4
+ * Read a `.docx` package into the {@link FlowDoc} interlayer (ir-design §7): the
5
+ * document-derived half of what the converter used to do inline. Parses the main
6
+ * document, styles, numbering, notes, comments, headers/footers, charts, embedded
7
+ * fonts and core properties, runs the body through the stage-6 FlowDoc transforms
8
+ * (list markers then the style cascade), and returns the tree plus any
9
+ * graceful-degradation losses. Caller-supplied conversion options (fonts, PDF/A,
10
+ * signature) stay with the converter/facade.
11
+ *
12
+ * @param docx The raw `.docx` (OPC ZIP) bytes.
13
+ * @returns The parsed {@link FlowDoc} and the losses recorded while reading.
14
+ */
3
15
  export declare function readDocx(docx: Uint8Array): ReadResult<FlowDoc>;
16
+ /**
17
+ * The {@link DocumentReader} registration for `.docx`: its id, the FlowDoc
18
+ * feature set it supports, the sniffer, and the {@link readDocx} entry point.
19
+ */
4
20
  export declare const docxReader: DocumentReader<FlowDoc>;
@@ -5,7 +5,7 @@ import { EMPTY_STYLE_SHEET, resolveBodyStyles, resolveHeadersFootersStyles } fro
5
5
  import { resolveTableStyles } from "../core/style-cascade/table.js";
6
6
  import "../core/style-cascade/index.js";
7
7
  import { poFindDescendant } from "../core/po-helpers.js";
8
- import { bytesInclude } from "../core/bytes.js";
8
+ import { bytesIncludePartName } from "../core/bytes.js";
9
9
  import { DEFAULT_THEME_PALETTE, makeColorResolver } from "../core/drawingml/colors.js";
10
10
  import { parseChart, withChartColorStyle } from "../core/drawingml/chart-parser.js";
11
11
  import { parseTheme } from "../core/drawingml/theme-parser.js";
@@ -33,6 +33,18 @@ var CORE_PROPS_PART = "docProps/core.xml";
33
33
  var MAIN_DOCUMENT_PART = "word/document.xml";
34
34
  var REL_HYPERLINK = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
35
35
  var THEME_PART = "word/theme/theme1.xml";
36
+ /**
37
+ * Read a `.docx` package into the {@link FlowDoc} interlayer (ir-design §7): the
38
+ * document-derived half of what the converter used to do inline. Parses the main
39
+ * document, styles, numbering, notes, comments, headers/footers, charts, embedded
40
+ * fonts and core properties, runs the body through the stage-6 FlowDoc transforms
41
+ * (list markers then the style cascade), and returns the tree plus any
42
+ * graceful-degradation losses. Caller-supplied conversion options (fonts, PDF/A,
43
+ * signature) stay with the converter/facade.
44
+ *
45
+ * @param docx The raw `.docx` (OPC ZIP) bytes.
46
+ * @returns The parsed {@link FlowDoc} and the losses recorded while reading.
47
+ */
36
48
  function readDocx(docx) {
37
49
  const pkg = OpcPackage.open(docx);
38
50
  const main = pkg.getMainDocument();
@@ -110,6 +122,10 @@ function readDocx(docx) {
110
122
  losses
111
123
  };
112
124
  }
125
+ /**
126
+ * The {@link DocumentReader} registration for `.docx`: its id, the FlowDoc
127
+ * feature set it supports, the sniffer, and the {@link readDocx} entry point.
128
+ */
113
129
  var docxReader = {
114
130
  id: "docx",
115
131
  produces: "flow",
@@ -128,7 +144,7 @@ var docxReader = {
128
144
  FEATURES.trackedChanges,
129
145
  FEATURES.fontsEmbedding
130
146
  ]),
131
- sniff: (bytes) => bytes[0] === 80 && bytes[1] === 75 && bytesInclude(bytes, "word/document.xml"),
147
+ sniff: (bytes) => bytes[0] === 80 && bytes[1] === 75 && bytesIncludePartName(bytes, "word/document.xml"),
132
148
  read: (bytes) => readDocx(bytes)
133
149
  };
134
150
  function infoFromCore(core) {
@@ -1,12 +1,34 @@
1
1
  import { FontBytesByVariant, FontRegistry } from '../core/font/index.js';
2
2
  import { FamilyKey, FetchLike } from '../core/fonts/index.js';
3
3
  import { SignatureOptions, StyledRenderOptions } from '../pdf/index.js';
4
+ /**
5
+ * Options for the `.docx` → PDF converters. Extends the low-level
6
+ * {@link StyledRenderOptions} (minus the font `registry` and `styles`, which the
7
+ * converter builds itself) with font supply, substitute-font hints and two
8
+ * source-touching conveniences.
9
+ */
4
10
  export interface ConvertDocxOptions extends Omit<StyledRenderOptions, 'registry' | 'styles'> {
11
+ /** A single regular-variant font as raw bytes. */
5
12
  readonly fontBytes?: Uint8Array;
13
+ /** Explicit font bytes per variant (regular/bold/italic/bold-italic). */
6
14
  readonly fonts?: FontBytesByVariant;
15
+ /**
16
+ * Force a substitute font family for the auto-download path (e.g. `'serif'`).
17
+ * Ignored when `fonts`/`fontBytes` are supplied.
18
+ */
7
19
  readonly fontFamily?: string;
20
+ /** Injectable `fetch` for the auto-download path (defaults to the global `fetch`). */
8
21
  readonly fontFetch?: FetchLike;
22
+ /**
23
+ * For PDF/A-3 only: embed the input `.docx` as an associated source file
24
+ * (`/AFRelationship /Source`) so the archive carries its own source. Ignored
25
+ * for other profiles (PDF/A-1/2 forbid arbitrary embedded files).
26
+ */
9
27
  readonly embedSource?: boolean;
28
+ /**
29
+ * Digitally sign the output (ISO 32000 §12.8). Requires the async
30
+ * {@link convertDocxToPdf} (signing uses WebCrypto); ignored by the sync converter.
31
+ */
10
32
  readonly signature?: SignatureOptions;
11
33
  }
12
34
  /**
@@ -15,6 +37,16 @@ export interface ConvertDocxOptions extends Omit<StyledRenderOptions, 'registry'
15
37
  * Internal since 1.0 — see the async variant above.
16
38
  */
17
39
  export declare function convertDocxToPdfSync(docx: Uint8Array, options: ConvertDocxOptions): Uint8Array;
40
+ /**
41
+ * The distinct curated font families the document references (scanning the
42
+ * `w:ascii` of `styles.xml` + `document.xml`), always including the sans default
43
+ * `'arimo'` as a fallback for unstyled runs / math / charts. The async path
44
+ * fetches one substitute set per family so each run renders in the right one.
45
+ *
46
+ * @param docx The `.docx` bytes.
47
+ * @returns The resolved {@link FamilyKey} set; just the default when the package
48
+ * cannot be opened.
49
+ */
18
50
  export declare function detectDocxFamilyKeys(docx: Uint8Array): Set<FamilyKey>;
19
51
  /**
20
52
  * One-shot .docx → PDF (auto-downloads a substitute font set when the caller
@@ -24,6 +56,17 @@ export declare function detectDocxFamilyKeys(docx: Uint8Array): Set<FamilyKey>;
24
56
  * the createConverter facade and the test suite drive this directly.
25
57
  */
26
58
  export declare function convertDocxToPdf(docx: Uint8Array, options?: ConvertDocxOptions): Promise<Uint8Array>;
59
+ /**
60
+ * Substitute-font auto-download for a `.docx` without caller-supplied fonts:
61
+ * detect the families used and fetch an open set per family (a single-family
62
+ * document takes the simple one-family path). Shared by the converter and the
63
+ * {@link Ream} facade — both work from the same source bytes.
64
+ *
65
+ * @param docx The `.docx` bytes.
66
+ * @param options Optional `fontFamily` override and injectable `fontFetch`.
67
+ * @returns The base font bytes plus, for a multi-family document, a per-family
68
+ * registry map so each run resolves to its own substitute.
69
+ */
27
70
  export declare function resolveDocxAutoFonts(docx: Uint8Array, options?: {
28
71
  readonly fontFamily?: string;
29
72
  readonly fontFetch?: FetchLike;
@@ -31,4 +74,13 @@ export declare function resolveDocxAutoFonts(docx: Uint8Array, options?: {
31
74
  fonts: FontBytesByVariant;
32
75
  registriesByFamily?: Map<FamilyKey, FontRegistry>;
33
76
  }>;
77
+ /**
78
+ * Best-effort detection of the document's primary font family, used to choose a
79
+ * substitute for auto-download. Prefers the document defaults' `w:ascii` font,
80
+ * then falls back to the most frequent run font. A cheap regex over the XML — no
81
+ * need to fully parse for this hint.
82
+ *
83
+ * @param docx The `.docx` bytes.
84
+ * @returns The detected family name, or `undefined` when none is found.
85
+ */
34
86
  export declare function detectDocxFontFamily(docx: Uint8Array): string | undefined;
@@ -48,6 +48,16 @@ function prepareDocxStyledRender(docx, options) {
48
48
  }
49
49
  };
50
50
  }
51
+ /**
52
+ * The distinct curated font families the document references (scanning the
53
+ * `w:ascii` of `styles.xml` + `document.xml`), always including the sans default
54
+ * `'arimo'` as a fallback for unstyled runs / math / charts. The async path
55
+ * fetches one substitute set per family so each run renders in the right one.
56
+ *
57
+ * @param docx The `.docx` bytes.
58
+ * @returns The resolved {@link FamilyKey} set; just the default when the package
59
+ * cannot be opened.
60
+ */
51
61
  function detectDocxFamilyKeys(docx) {
52
62
  const keys = new Set(["arimo"]);
53
63
  let pkg;
@@ -93,6 +103,17 @@ async function buildUnsignedDocxPdf(docx, options) {
93
103
  }
94
104
  return convertDocxToPdfSync(docx, withFonts);
95
105
  }
106
+ /**
107
+ * Substitute-font auto-download for a `.docx` without caller-supplied fonts:
108
+ * detect the families used and fetch an open set per family (a single-family
109
+ * document takes the simple one-family path). Shared by the converter and the
110
+ * {@link Ream} facade — both work from the same source bytes.
111
+ *
112
+ * @param docx The `.docx` bytes.
113
+ * @param options Optional `fontFamily` override and injectable `fontFetch`.
114
+ * @returns The base font bytes plus, for a multi-family document, a per-family
115
+ * registry map so each run resolves to its own substitute.
116
+ */
96
117
  async function resolveDocxAutoFonts(docx, options = {}) {
97
118
  const fetchOpt = options.fontFetch ? { fetch: options.fontFetch } : {};
98
119
  const keys = options.fontFamily ? new Set([resolveFamilyKey(options.fontFamily)]) : detectDocxFamilyKeys(docx);
@@ -1,4 +1,21 @@
1
1
  import { DocumentWriter, WriteResult } from '../core/ir/adapters.js';
2
2
  import { FlowDoc } from '../core/ir/flow.js';
3
+ /**
4
+ * Serialize a {@link FlowDoc} to a WordprocessingML package (E-DOCX) — the
5
+ * inverse of the docx reader. A flow medium with zero layout and zero I/O: the
6
+ * body's resolved properties are written as direct (denormalized) formatting, so
7
+ * the round-trip is semantic, not byte-for-byte. Emits the main document plus
8
+ * numbering, footnotes/endnotes, comments (+ commentsExtended), per-section
9
+ * headers/footers, charts and media parts; anything not yet serialized is
10
+ * reported as a {@link Loss}.
11
+ *
12
+ * @param flow The interlayer to write back.
13
+ * @returns The encoded `.docx` bytes and the loss report.
14
+ */
3
15
  export declare function writeDocx(flow: FlowDoc): WriteResult;
16
+ /**
17
+ * The {@link DocumentWriter} registration for `.docx`: its id, the medium it
18
+ * consumes (`flow`), the feature set it supports, and the {@link writeDocx}
19
+ * entry point.
20
+ */
4
21
  export declare const docxWriter: DocumentWriter<FlowDoc>;
@@ -88,6 +88,18 @@ function newScope() {
88
88
  relIdByResource: /* @__PURE__ */ new Map()
89
89
  };
90
90
  }
91
+ /**
92
+ * Serialize a {@link FlowDoc} to a WordprocessingML package (E-DOCX) — the
93
+ * inverse of the docx reader. A flow medium with zero layout and zero I/O: the
94
+ * body's resolved properties are written as direct (denormalized) formatting, so
95
+ * the round-trip is semantic, not byte-for-byte. Emits the main document plus
96
+ * numbering, footnotes/endnotes, comments (+ commentsExtended), per-section
97
+ * headers/footers, charts and media parts; anything not yet serialized is
98
+ * reported as a {@link Loss}.
99
+ *
100
+ * @param flow The interlayer to write back.
101
+ * @returns The encoded `.docx` bytes and the loss report.
102
+ */
91
103
  function writeDocx(flow) {
92
104
  const losses = [];
93
105
  const body = [];
@@ -334,6 +346,11 @@ function emitHeadersFooters(flow, section, state, docScope, extraParts, extraPar
334
346
  }
335
347
  return refs;
336
348
  }
349
+ /**
350
+ * The {@link DocumentWriter} registration for `.docx`: its id, the medium it
351
+ * consumes (`flow`), the feature set it supports, and the {@link writeDocx}
352
+ * entry point.
353
+ */
337
354
  var docxWriter = {
338
355
  id: "docx",
339
356
  consumes: "flow",
@@ -2,6 +2,11 @@ import { BodyElement, FloatAnchor, ShapeFill, ShapeGeometry, ShapeLine, ShapeTex
2
2
  import { ColorResolver } from '../core/drawingml/colors.js';
3
3
  import { PoNode } from '../core/po-helpers.js';
4
4
  import { Pt } from '../core/ir/index.js';
5
+ /**
6
+ * A parsed DrawingML shape without the owning paragraph's properties (attached by
7
+ * the caller, mirroring how the image branch returns size + id and the caller
8
+ * adds the `pPr`).
9
+ */
5
10
  export interface ShapeData {
6
11
  readonly width: Pt;
7
12
  readonly height: Pt;
@@ -9,14 +14,25 @@ export interface ShapeData {
9
14
  readonly fill: ShapeFill;
10
15
  readonly line?: ShapeLine;
11
16
  readonly transform?: ShapeTransform;
17
+ /** The shape's text body (a `wps:txbx`), when it carries one. */
12
18
  readonly text?: ShapeTextBody;
13
19
  }
20
+ /**
21
+ * Parses the body elements of a `w:txbxContent`. Injected by the caller to avoid
22
+ * a module cycle with `document-parser` (which imports this module).
23
+ */
14
24
  export type ParseBody = (children: ReadonlyArray<PoNode>) => Array<BodyElement>;
25
+ /**
26
+ * The result of parsing a `<w:drawing>` (or legacy VML picture): an embedded
27
+ * picture, a DrawingML shape, a chart reference, or a SmartArt diagram. Each
28
+ * variant carries optional alternate text and a float anchor.
29
+ */
15
30
  export type DrawingContent = {
16
31
  readonly kind: 'image';
17
32
  readonly imageId: string;
18
33
  readonly width: Pt;
19
34
  readonly height: Pt;
35
+ /** `wp:docPr` `@descr`/`@title` — alternate text for the tagged-PDF Figure. */
20
36
  readonly altText?: string;
21
37
  readonly float?: FloatAnchor;
22
38
  } | {
@@ -26,6 +42,7 @@ export type DrawingContent = {
26
42
  readonly float?: FloatAnchor;
27
43
  } | {
28
44
  readonly kind: 'chart';
45
+ /** The `c:chart` `@r:id` relationship id to the chart part. */
29
46
  readonly chartRelId: string;
30
47
  readonly width: Pt;
31
48
  readonly height: Pt;
@@ -33,17 +50,88 @@ export type DrawingContent = {
33
50
  readonly float?: FloatAnchor;
34
51
  } | {
35
52
  readonly kind: 'diagram';
53
+ /** SmartArt data-part relationship id (`dgm:relIds` `@r:dm`); the reader resolves the drawing override. */
36
54
  readonly dmRelId: string;
55
+ /** Frame width in EMU. */
37
56
  readonly widthEmu: number;
57
+ /** Frame height in EMU. */
38
58
  readonly heightEmu: number;
39
59
  readonly altText?: string;
40
60
  readonly float?: FloatAnchor;
41
61
  };
62
+ /**
63
+ * ECMA-376 Part 3 (Markup Compatibility) — resolve an `<mc:AlternateContent>` to
64
+ * the children of the first `<mc:Choice>` whose `Requires` lists only namespaces
65
+ * we understand, else the `<mc:Fallback>` children, else nothing. (`Requires`
66
+ * holds space-separated namespace prefixes as declared in the document.)
67
+ *
68
+ * @param altContent The `mc:AlternateContent` node.
69
+ * @returns The chosen branch's children.
70
+ */
42
71
  export declare function resolveMc(altContent: PoNode): ReadonlyArray<PoNode>;
72
+ /**
73
+ * Flatten a children list, expanding any `<mc:AlternateContent>` to its chosen
74
+ * branch (via {@link resolveMc}) so downstream scanning sees plain elements (a
75
+ * `<w:drawing>`, or the VML we ignore). Used both at run level and inside
76
+ * `a:graphicData`.
77
+ *
78
+ * @param children The raw child list.
79
+ * @returns The flattened children.
80
+ */
43
81
  export declare function expandMcChildren(children: ReadonlyArray<PoNode>): Array<PoNode>;
82
+ /**
83
+ * Parse a `<w:drawing>` (ECMA-376 Part 1 §20) into a {@link DrawingContent}. The
84
+ * `a:graphicData` `@uri` selects the branch: a `wps:wsp` shape, a chart, a
85
+ * SmartArt diagram, or — falling through — an embedded picture from
86
+ * `a:blip @r:embed`.
87
+ *
88
+ * @param drawing The `w:drawing` node.
89
+ * @param resolveColor Resolver for theme/scheme colours used by shape fills/lines.
90
+ * @param parseBody Optional body parser for a shape's text box (omitted ⇒ no text).
91
+ * @returns The parsed content, or `null` when no anchor / recognizable graphic is found.
92
+ */
44
93
  export declare function parseDrawing(drawing: PoNode, resolveColor: ColorResolver, parseBody?: ParseBody): DrawingContent | null;
94
+ /**
95
+ * Parse a legacy `<w:pict>`/`<w:object>` VML picture (ISO/IEC 29500-1 §14, VML
96
+ * transitional) into an `image` {@link DrawingContent}. Modern files use
97
+ * `<w:drawing>` ({@link parseDrawing}); VML still shows up in headers, OLE-object
98
+ * previews (`@o:ole`) and documents last saved by older Word. A VML shape carries
99
+ * an `<v:imagedata r:id>` pointing at the media part and a CSS-like `@style`
100
+ * (`"width:75.6pt;height:49.2pt"`) giving its box; just enough is read to recover
101
+ * the relationship id, the size and the `@alt` text.
102
+ *
103
+ * @param node The `w:pict` / `w:object` node.
104
+ * @returns The picture, or `null` when there is no embedded `v:imagedata` or no usable size.
105
+ */
45
106
  export declare function parseVmlPicture(node: PoNode): DrawingContent | null;
107
+ /**
108
+ * Parse an `a:prstGeom` (§20.1.9.18) into a preset {@link ShapeGeometry}: the
109
+ * `@prst` preset name plus the `a:avLst` adjust values (each `a:gd`'s `val …`
110
+ * formula). Defaults to the `rect` preset when `@prst` is absent.
111
+ */
46
112
  export declare function parsePrstGeom(prst: PoNode): ShapeGeometry;
113
+ /**
114
+ * Parse an `a:custGeom` (ECMA-376 §20.1.9.11) → its first `<a:path>`
115
+ * (§20.1.9.15) into a custom {@link ShapeGeometry}. Coordinates stay in
116
+ * path-space (the geometry layer scales + y-flips them). Multiple subpaths with
117
+ * differing `w`/`h` are a follow-up; falls back to a `rect` preset when the path
118
+ * is empty or has no usable size.
119
+ */
47
120
  export declare function parseCustGeom(cust: PoNode): ShapeGeometry;
121
+ /**
122
+ * Parse a shape's fill from its `a:spPr`: the first of `a:noFill`, `a:solidFill`
123
+ * or `a:gradFill` wins. An unresolvable colour degrades to `{ kind: 'none' }`.
124
+ *
125
+ * @param spPr The `wps:spPr` node.
126
+ * @param resolveColor Resolver for theme/scheme colours.
127
+ */
48
128
  export declare function parseFill(spPr: PoNode, resolveColor: ColorResolver): ShapeFill;
129
+ /**
130
+ * Parse a shape's outline (`a:ln`) from its `a:spPr` into a {@link ShapeLine}:
131
+ * width, cap, solid colour, dash pattern, and an explicit `a:noFill` (an unstroked
132
+ * outline). Returns `undefined` when the shape has no `a:ln`.
133
+ *
134
+ * @param spPr The `wps:spPr` node.
135
+ * @param resolveColor Resolver for theme/scheme colours.
136
+ */
49
137
  export declare function parseLine(spPr: PoNode, resolveColor: ColorResolver): ShapeLine | undefined;
@@ -53,6 +53,15 @@ function parseAnchorPos(anchor, tag, allowed) {
53
53
  ...tag === "wp:positionH" && ANCHOR_ALIGNS.has(alignRaw) ? { align: alignRaw } : {}
54
54
  };
55
55
  }
56
+ /**
57
+ * ECMA-376 Part 3 (Markup Compatibility) — resolve an `<mc:AlternateContent>` to
58
+ * the children of the first `<mc:Choice>` whose `Requires` lists only namespaces
59
+ * we understand, else the `<mc:Fallback>` children, else nothing. (`Requires`
60
+ * holds space-separated namespace prefixes as declared in the document.)
61
+ *
62
+ * @param altContent The `mc:AlternateContent` node.
63
+ * @returns The chosen branch's children.
64
+ */
56
65
  function resolveMc(altContent) {
57
66
  for (const choice of poChildren(altContent)) {
58
67
  if (!poIs(choice, "mc:Choice")) continue;
@@ -62,12 +71,32 @@ function resolveMc(altContent) {
62
71
  const fallback = poChildren(altContent).find((c) => poIs(c, "mc:Fallback"));
63
72
  return fallback ? poChildren(fallback) : [];
64
73
  }
74
+ /**
75
+ * Flatten a children list, expanding any `<mc:AlternateContent>` to its chosen
76
+ * branch (via {@link resolveMc}) so downstream scanning sees plain elements (a
77
+ * `<w:drawing>`, or the VML we ignore). Used both at run level and inside
78
+ * `a:graphicData`.
79
+ *
80
+ * @param children The raw child list.
81
+ * @returns The flattened children.
82
+ */
65
83
  function expandMcChildren(children) {
66
84
  const out = [];
67
85
  for (const c of children) if (poIs(c, "mc:AlternateContent")) out.push(...resolveMc(c));
68
86
  else out.push(c);
69
87
  return out;
70
88
  }
89
+ /**
90
+ * Parse a `<w:drawing>` (ECMA-376 Part 1 §20) into a {@link DrawingContent}. The
91
+ * `a:graphicData` `@uri` selects the branch: a `wps:wsp` shape, a chart, a
92
+ * SmartArt diagram, or — falling through — an embedded picture from
93
+ * `a:blip @r:embed`.
94
+ *
95
+ * @param drawing The `w:drawing` node.
96
+ * @param resolveColor Resolver for theme/scheme colours used by shape fills/lines.
97
+ * @param parseBody Optional body parser for a shape's text box (omitted ⇒ no text).
98
+ * @returns The parsed content, or `null` when no anchor / recognizable graphic is found.
99
+ */
71
100
  function parseDrawing(drawing, resolveColor, parseBody) {
72
101
  const anchor = poChildren(drawing).find((c) => poIs(c, "wp:inline")) ?? poChildren(drawing).find((c) => poIs(c, "wp:anchor"));
73
102
  if (!anchor) return null;
@@ -128,6 +157,18 @@ function parseDrawing(drawing, resolveColor, parseBody) {
128
157
  };
129
158
  return null;
130
159
  }
160
+ /**
161
+ * Parse a legacy `<w:pict>`/`<w:object>` VML picture (ISO/IEC 29500-1 §14, VML
162
+ * transitional) into an `image` {@link DrawingContent}. Modern files use
163
+ * `<w:drawing>` ({@link parseDrawing}); VML still shows up in headers, OLE-object
164
+ * previews (`@o:ole`) and documents last saved by older Word. A VML shape carries
165
+ * an `<v:imagedata r:id>` pointing at the media part and a CSS-like `@style`
166
+ * (`"width:75.6pt;height:49.2pt"`) giving its box; just enough is read to recover
167
+ * the relationship id, the size and the `@alt` text.
168
+ *
169
+ * @param node The `w:pict` / `w:object` node.
170
+ * @returns The picture, or `null` when there is no embedded `v:imagedata` or no usable size.
171
+ */
131
172
  function parseVmlPicture(node) {
132
173
  const imagedata = poFindDescendant(node, "v:imagedata");
133
174
  if (!imagedata) return null;
@@ -242,6 +283,11 @@ function parseXfrm(xfrm) {
242
283
  ...flipV ? { flipV: true } : {}
243
284
  };
244
285
  }
286
+ /**
287
+ * Parse an `a:prstGeom` (§20.1.9.18) into a preset {@link ShapeGeometry}: the
288
+ * `@prst` preset name plus the `a:avLst` adjust values (each `a:gd`'s `val …`
289
+ * formula). Defaults to the `rect` preset when `@prst` is absent.
290
+ */
245
291
  function parsePrstGeom(prst) {
246
292
  const preset = poAttr(prst, "prst") ?? "rect";
247
293
  const adjust = /* @__PURE__ */ new Map();
@@ -260,6 +306,13 @@ function parsePrstGeom(prst) {
260
306
  adjust
261
307
  };
262
308
  }
309
+ /**
310
+ * Parse an `a:custGeom` (ECMA-376 §20.1.9.11) → its first `<a:path>`
311
+ * (§20.1.9.15) into a custom {@link ShapeGeometry}. Coordinates stay in
312
+ * path-space (the geometry layer scales + y-flips them). Multiple subpaths with
313
+ * differing `w`/`h` are a follow-up; falls back to a `rect` preset when the path
314
+ * is empty or has no usable size.
315
+ */
263
316
  function parseCustGeom(cust) {
264
317
  const pathLst = poChildren(cust).find((c) => poIs(c, "a:pathLst"));
265
318
  const path = pathLst ? poChildren(pathLst).find((c) => poIs(c, "a:path")) : void 0;
@@ -355,6 +408,13 @@ function pts(node) {
355
408
  return out;
356
409
  }
357
410
  var firstPt = (node) => pts(node)[0];
411
+ /**
412
+ * Parse a shape's fill from its `a:spPr`: the first of `a:noFill`, `a:solidFill`
413
+ * or `a:gradFill` wins. An unresolvable colour degrades to `{ kind: 'none' }`.
414
+ *
415
+ * @param spPr The `wps:spPr` node.
416
+ * @param resolveColor Resolver for theme/scheme colours.
417
+ */
358
418
  function parseFill(spPr, resolveColor) {
359
419
  for (const child of poChildren(spPr)) {
360
420
  if (poIs(child, "a:noFill")) return { kind: "none" };
@@ -375,6 +435,14 @@ function parseFill(spPr, resolveColor) {
375
435
  }
376
436
  return { kind: "none" };
377
437
  }
438
+ /**
439
+ * Parse a shape's outline (`a:ln`) from its `a:spPr` into a {@link ShapeLine}:
440
+ * width, cap, solid colour, dash pattern, and an explicit `a:noFill` (an unstroked
441
+ * outline). Returns `undefined` when the shape has no `a:ln`.
442
+ *
443
+ * @param spPr The `wps:spPr` node.
444
+ * @param resolveColor Resolver for theme/scheme colours.
445
+ */
378
446
  function parseLine(spPr, resolveColor) {
379
447
  const ln = poChildren(spPr).find((c) => poIs(c, "a:ln"));
380
448
  if (!ln) return void 0;
@@ -9,7 +9,31 @@ interface FontTableEntry {
9
9
  readonly name: string;
10
10
  readonly embeds: Partial<Record<EmbedVariant, EmbedRef>>;
11
11
  }
12
+ /**
13
+ * §17.8.1 — restore an obfuscated embedded font by XOR-ing its first 32 bytes
14
+ * with the `fontKey` GUID bytes in reverse order, recovering a normal sfnt.
15
+ *
16
+ * @param data The obfuscated `.odttf` bytes.
17
+ * @param fontKey The 16-byte `w:fontKey` GUID (with or without braces/dashes).
18
+ * @returns The de-obfuscated bytes, or `data` unchanged when `fontKey` is not a GUID.
19
+ */
12
20
  export declare function deobfuscateEmbeddedFont(data: Uint8Array, fontKey: string): Uint8Array;
21
+ /**
22
+ * Parse `word/fontTable.xml` for its embedded-font references (§17.8). Returns
23
+ * one `FontTableEntry` per `w:font` that carries at least one `w:embed*` child,
24
+ * each naming the relationship id + `w:fontKey` for a Regular/Bold/Italic/
25
+ * BoldItalic face. A regex pass, not a full XML parse — only the embed refs matter.
26
+ */
13
27
  export declare function parseFontTable(data: Uint8Array): Array<FontTableEntry>;
28
+ /**
29
+ * De-obfuscate and load every embedded font in the package, building one
30
+ * {@link FontRegistry} per font keyed by its normalized (trimmed, lower-cased)
31
+ * name so a run's `w:ascii` can match it. Each candidate face is validated
32
+ * against the sfnt signature; a font lacking a usable Regular face, or whose
33
+ * faces fail to parse, is skipped (the family then falls back to substitution).
34
+ *
35
+ * @param pkg The opened OPC package for the `.docx`.
36
+ * @returns A map from normalized font name to its registry (empty when nothing embeds).
37
+ */
14
38
  export declare function loadEmbeddedFonts(pkg: OpcPackage): Map<string, FontRegistry>;
15
39
  export {};