@beyondwork/docx-react-component 1.0.27 → 1.0.29

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 (356) hide show
  1. package/dist/canonical-document-BLEbzL2J.d.cts +844 -0
  2. package/dist/canonical-document-BLEbzL2J.d.ts +844 -0
  3. package/dist/chunk-2FJS5GZM.js +763 -0
  4. package/dist/chunk-2FJS5GZM.js.map +1 -0
  5. package/{src/core/commands/section-layout-commands.ts → dist/chunk-2OQBZS3F.js} +106 -340
  6. package/dist/chunk-2OQBZS3F.js.map +1 -0
  7. package/dist/chunk-2S7W4KFO.js +127 -0
  8. package/dist/chunk-2S7W4KFO.js.map +1 -0
  9. package/dist/chunk-2TG72QSW.js +3874 -0
  10. package/dist/chunk-2TG72QSW.js.map +1 -0
  11. package/{src/core/commands/table-structure-commands.ts → dist/chunk-36QNIZBO.js} +126 -315
  12. package/dist/chunk-36QNIZBO.js.map +1 -0
  13. package/dist/chunk-4AQOYAW4.js +3069 -0
  14. package/dist/chunk-4AQOYAW4.js.map +1 -0
  15. package/dist/chunk-4D5EWJ3P.js +77 -0
  16. package/dist/chunk-4D5EWJ3P.js.map +1 -0
  17. package/dist/chunk-5FN54NDH.js +2257 -0
  18. package/dist/chunk-5FN54NDH.js.map +1 -0
  19. package/dist/chunk-BOYGQYRQ.js +7306 -0
  20. package/dist/chunk-BOYGQYRQ.js.map +1 -0
  21. package/dist/chunk-CN3XMECL.js +212 -0
  22. package/dist/chunk-CN3XMECL.js.map +1 -0
  23. package/dist/chunk-EBI3BX6U.js +164 -0
  24. package/dist/chunk-EBI3BX6U.js.map +1 -0
  25. package/dist/chunk-EILUG3VB.js +1275 -0
  26. package/dist/chunk-EILUG3VB.js.map +1 -0
  27. package/dist/chunk-FUDY333O.js +70 -0
  28. package/dist/chunk-FUDY333O.js.map +1 -0
  29. package/dist/chunk-GBVOWFIK.js +1237 -0
  30. package/dist/chunk-GBVOWFIK.js.map +1 -0
  31. package/dist/chunk-H4TQ3H3Y.js +262 -0
  32. package/dist/chunk-H4TQ3H3Y.js.map +1 -0
  33. package/{src/core/commands/style-commands.ts → dist/chunk-JGB3IXZO.js} +40 -113
  34. package/dist/chunk-JGB3IXZO.js.map +1 -0
  35. package/dist/chunk-KD2QRQPY.js +4342 -0
  36. package/dist/chunk-KD2QRQPY.js.map +1 -0
  37. package/dist/chunk-KLMXQVYK.js +369 -0
  38. package/dist/chunk-KLMXQVYK.js.map +1 -0
  39. package/dist/chunk-KZUG5KFQ.js +214 -0
  40. package/dist/chunk-KZUG5KFQ.js.map +1 -0
  41. package/{src/core/state/text-transaction.ts → dist/chunk-QDAQ4CJU.js} +79 -236
  42. package/dist/chunk-QDAQ4CJU.js.map +1 -0
  43. package/{src/legal/bookmarks.ts → dist/chunk-RMH72RZI.js} +44 -130
  44. package/dist/chunk-RMH72RZI.js.map +1 -0
  45. package/dist/chunk-SWKWQZXM.js +117 -0
  46. package/dist/chunk-SWKWQZXM.js.map +1 -0
  47. package/{src/core/commands/formatting-commands.ts → dist/chunk-TJBP2K4T.js} +196 -536
  48. package/dist/chunk-TJBP2K4T.js.map +1 -0
  49. package/dist/chunk-TLCEAQDQ.js +542 -0
  50. package/dist/chunk-TLCEAQDQ.js.map +1 -0
  51. package/{src/core/commands/text-commands.ts → dist/chunk-UZXBISGO.js} +86 -142
  52. package/dist/chunk-UZXBISGO.js.map +1 -0
  53. package/dist/chunk-WGBAKP3Q.js +3220 -0
  54. package/dist/chunk-WGBAKP3Q.js.map +1 -0
  55. package/dist/compare/index.cjs +5475 -0
  56. package/dist/compare/index.cjs.map +1 -0
  57. package/dist/compare/index.d.cts +114 -0
  58. package/dist/compare/index.d.ts +114 -0
  59. package/dist/compare/index.js +731 -0
  60. package/dist/compare/index.js.map +1 -0
  61. package/dist/core/commands/formatting-commands.cjs +828 -0
  62. package/dist/core/commands/formatting-commands.cjs.map +1 -0
  63. package/dist/core/commands/formatting-commands.d.cts +63 -0
  64. package/dist/core/commands/formatting-commands.d.ts +63 -0
  65. package/dist/core/commands/formatting-commands.js +37 -0
  66. package/dist/core/commands/formatting-commands.js.map +1 -0
  67. package/dist/core/commands/image-commands.cjs +2023 -0
  68. package/dist/core/commands/image-commands.cjs.map +1 -0
  69. package/dist/core/commands/image-commands.d.cts +58 -0
  70. package/dist/core/commands/image-commands.d.ts +58 -0
  71. package/dist/core/commands/image-commands.js +18 -0
  72. package/dist/core/commands/image-commands.js.map +1 -0
  73. package/dist/core/commands/section-layout-commands.cjs +477 -0
  74. package/dist/core/commands/section-layout-commands.cjs.map +1 -0
  75. package/dist/core/commands/section-layout-commands.d.cts +62 -0
  76. package/dist/core/commands/section-layout-commands.d.ts +62 -0
  77. package/dist/core/commands/section-layout-commands.js +21 -0
  78. package/dist/core/commands/section-layout-commands.js.map +1 -0
  79. package/dist/core/commands/style-commands.cjs +214 -0
  80. package/dist/core/commands/style-commands.cjs.map +1 -0
  81. package/dist/core/commands/style-commands.d.cts +13 -0
  82. package/dist/core/commands/style-commands.d.ts +13 -0
  83. package/dist/core/commands/style-commands.js +9 -0
  84. package/dist/core/commands/style-commands.js.map +1 -0
  85. package/dist/core/commands/table-structure-commands.cjs +1883 -0
  86. package/dist/core/commands/table-structure-commands.cjs.map +1 -0
  87. package/dist/core/commands/table-structure-commands.d.cts +59 -0
  88. package/dist/core/commands/table-structure-commands.d.ts +59 -0
  89. package/dist/core/commands/table-structure-commands.js +12 -0
  90. package/dist/core/commands/table-structure-commands.js.map +1 -0
  91. package/dist/core/commands/text-commands.cjs +2391 -0
  92. package/dist/core/commands/text-commands.cjs.map +1 -0
  93. package/dist/core/commands/text-commands.d.cts +24 -0
  94. package/dist/core/commands/text-commands.d.ts +24 -0
  95. package/dist/core/commands/text-commands.js +28 -0
  96. package/dist/core/commands/text-commands.js.map +1 -0
  97. package/dist/core/selection/mapping.cjs +200 -0
  98. package/dist/core/selection/mapping.cjs.map +1 -0
  99. package/dist/core/selection/mapping.d.cts +2 -0
  100. package/dist/core/selection/mapping.d.ts +2 -0
  101. package/dist/core/selection/mapping.js +31 -0
  102. package/dist/core/selection/mapping.js.map +1 -0
  103. package/dist/core/state/editor-state.cjs +2278 -0
  104. package/dist/core/state/editor-state.cjs.map +1 -0
  105. package/dist/core/state/editor-state.d.cts +2 -0
  106. package/dist/core/state/editor-state.d.ts +2 -0
  107. package/dist/core/state/editor-state.js +26 -0
  108. package/dist/core/state/editor-state.js.map +1 -0
  109. package/dist/index.cjs +38553 -0
  110. package/dist/index.cjs.map +1 -0
  111. package/dist/index.d.cts +15 -0
  112. package/dist/index.d.ts +15 -0
  113. package/dist/index.js +7856 -0
  114. package/dist/index.js.map +1 -0
  115. package/dist/io/docx-session.cjs +16236 -0
  116. package/dist/io/docx-session.cjs.map +1 -0
  117. package/dist/io/docx-session.d.cts +21 -0
  118. package/dist/io/docx-session.d.ts +21 -0
  119. package/dist/io/docx-session.js +18 -0
  120. package/dist/io/docx-session.js.map +1 -0
  121. package/dist/legal/index.cjs +3900 -0
  122. package/dist/legal/index.cjs.map +1 -0
  123. package/dist/legal/index.d.cts +86 -0
  124. package/dist/legal/index.d.ts +86 -0
  125. package/dist/legal/index.js +616 -0
  126. package/dist/legal/index.js.map +1 -0
  127. package/dist/public-types-7ZL_94cz.d.ts +1573 -0
  128. package/dist/public-types-CeMaDueh.d.cts +1573 -0
  129. package/dist/public-types.cjs +19 -0
  130. package/dist/public-types.cjs.map +1 -0
  131. package/dist/public-types.d.cts +2 -0
  132. package/dist/public-types.d.ts +2 -0
  133. package/dist/public-types.js +1 -0
  134. package/dist/public-types.js.map +1 -0
  135. package/dist/runtime/document-runtime.cjs +11140 -0
  136. package/dist/runtime/document-runtime.cjs.map +1 -0
  137. package/dist/runtime/document-runtime.d.cts +231 -0
  138. package/dist/runtime/document-runtime.d.ts +231 -0
  139. package/dist/runtime/document-runtime.js +21 -0
  140. package/dist/runtime/document-runtime.js.map +1 -0
  141. package/dist/structural-helpers-CilgOVhh.d.cts +10 -0
  142. package/dist/structural-helpers-q0Gd-eBN.d.ts +10 -0
  143. package/dist/ui-tailwind/editor-surface/search-plugin.cjs +313 -0
  144. package/dist/ui-tailwind/editor-surface/search-plugin.cjs.map +1 -0
  145. package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +67 -0
  146. package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +67 -0
  147. package/dist/ui-tailwind/editor-surface/search-plugin.js +23 -0
  148. package/dist/ui-tailwind/editor-surface/search-plugin.js.map +1 -0
  149. package/dist/ui-tailwind/index.cjs +4833 -0
  150. package/dist/ui-tailwind/index.cjs.map +1 -0
  151. package/dist/ui-tailwind/index.d.cts +617 -0
  152. package/dist/ui-tailwind/index.d.ts +617 -0
  153. package/dist/ui-tailwind/index.js +575 -0
  154. package/dist/ui-tailwind/index.js.map +1 -0
  155. package/package.json +64 -54
  156. package/src/README.md +0 -85
  157. package/src/api/README.md +0 -26
  158. package/src/api/public-types.ts +0 -1418
  159. package/src/api/session-state.ts +0 -60
  160. package/src/compare/diff-engine.ts +0 -623
  161. package/src/compare/export-redlines.ts +0 -280
  162. package/src/compare/index.ts +0 -25
  163. package/src/compare/snapshot.ts +0 -97
  164. package/src/component-inventory.md +0 -99
  165. package/src/core/README.md +0 -10
  166. package/src/core/commands/README.md +0 -3
  167. package/src/core/commands/image-commands.ts +0 -373
  168. package/src/core/commands/index.ts +0 -1757
  169. package/src/core/commands/list-commands.ts +0 -565
  170. package/src/core/commands/paragraph-layout-commands.ts +0 -339
  171. package/src/core/commands/review-commands.ts +0 -108
  172. package/src/core/commands/structural-helpers.ts +0 -309
  173. package/src/core/schema/README.md +0 -3
  174. package/src/core/schema/text-schema.ts +0 -516
  175. package/src/core/search/search-text.ts +0 -357
  176. package/src/core/selection/README.md +0 -3
  177. package/src/core/selection/mapping.ts +0 -289
  178. package/src/core/selection/review-anchors.ts +0 -183
  179. package/src/core/state/README.md +0 -3
  180. package/src/core/state/editor-state.ts +0 -892
  181. package/src/formats/xlsx/io/parse-shared-strings.ts +0 -41
  182. package/src/formats/xlsx/io/parse-sheet.ts +0 -459
  183. package/src/formats/xlsx/io/parse-styles.ts +0 -59
  184. package/src/formats/xlsx/io/parse-workbook.ts +0 -75
  185. package/src/formats/xlsx/io/serialize-shared-strings.ts +0 -72
  186. package/src/formats/xlsx/io/serialize-sheet.ts +0 -333
  187. package/src/formats/xlsx/io/serialize-styles.ts +0 -98
  188. package/src/formats/xlsx/io/serialize-workbook.ts +0 -429
  189. package/src/formats/xlsx/io/xlsx-session.ts +0 -314
  190. package/src/formats/xlsx/model/cell.ts +0 -189
  191. package/src/formats/xlsx/model/sheet.ts +0 -326
  192. package/src/formats/xlsx/model/styles.ts +0 -118
  193. package/src/formats/xlsx/model/workbook.ts +0 -453
  194. package/src/formats/xlsx/runtime/cell-commands.ts +0 -567
  195. package/src/formats/xlsx/runtime/sheet-commands.ts +0 -206
  196. package/src/formats/xlsx/runtime/workbook-runtime.ts +0 -177
  197. package/src/formats/xlsx/runtime/workbook-transaction.ts +0 -822
  198. package/src/index.ts +0 -101
  199. package/src/io/README.md +0 -10
  200. package/src/io/docx-session.ts +0 -2882
  201. package/src/io/export/README.md +0 -3
  202. package/src/io/export/export-session.ts +0 -220
  203. package/src/io/export/minimal-docx.ts +0 -115
  204. package/src/io/export/reattach-preserved-parts.ts +0 -54
  205. package/src/io/export/serialize-comments.ts +0 -947
  206. package/src/io/export/serialize-footnotes.ts +0 -399
  207. package/src/io/export/serialize-headers-footers.ts +0 -372
  208. package/src/io/export/serialize-main-document.ts +0 -1376
  209. package/src/io/export/serialize-numbering.ts +0 -118
  210. package/src/io/export/serialize-revisions.ts +0 -389
  211. package/src/io/export/serialize-runtime-revisions.ts +0 -269
  212. package/src/io/export/serialize-tables.ts +0 -174
  213. package/src/io/export/split-review-boundaries.ts +0 -356
  214. package/src/io/normalize/README.md +0 -3
  215. package/src/io/normalize/normalize-text.ts +0 -639
  216. package/src/io/ooxml/README.md +0 -3
  217. package/src/io/ooxml/highlight-colors.ts +0 -39
  218. package/src/io/ooxml/numbering-sentinels.ts +0 -44
  219. package/src/io/ooxml/parse-comments.ts +0 -846
  220. package/src/io/ooxml/parse-complex-content.ts +0 -287
  221. package/src/io/ooxml/parse-fields.ts +0 -834
  222. package/src/io/ooxml/parse-footnotes.ts +0 -896
  223. package/src/io/ooxml/parse-headers-footers.ts +0 -1169
  224. package/src/io/ooxml/parse-inline-media.ts +0 -461
  225. package/src/io/ooxml/parse-main-document.ts +0 -2877
  226. package/src/io/ooxml/parse-numbering.ts +0 -432
  227. package/src/io/ooxml/parse-revisions.ts +0 -931
  228. package/src/io/ooxml/parse-settings.ts +0 -184
  229. package/src/io/ooxml/parse-shapes.ts +0 -296
  230. package/src/io/ooxml/parse-styles.ts +0 -463
  231. package/src/io/ooxml/parse-tables.ts +0 -618
  232. package/src/io/ooxml/parse-theme.ts +0 -346
  233. package/src/io/ooxml/part-manifest.ts +0 -136
  234. package/src/io/ooxml/revision-boundaries.ts +0 -351
  235. package/src/io/opc/README.md +0 -3
  236. package/src/io/opc/corrupt-package.ts +0 -166
  237. package/src/io/opc/docx-package.ts +0 -74
  238. package/src/io/opc/package-reader.ts +0 -325
  239. package/src/io/opc/package-writer.ts +0 -273
  240. package/src/io/source-package-provenance.ts +0 -241
  241. package/src/legal/cross-references.ts +0 -414
  242. package/src/legal/defined-terms.ts +0 -203
  243. package/src/legal/index.ts +0 -32
  244. package/src/legal/signature-blocks.ts +0 -259
  245. package/src/model/README.md +0 -3
  246. package/src/model/canonical-document.ts +0 -2632
  247. package/src/model/cds-1.0.0.ts +0 -212
  248. package/src/model/snapshot.ts +0 -649
  249. package/src/preservation/README.md +0 -3
  250. package/src/preservation/markup-compatibility.ts +0 -48
  251. package/src/preservation/opaque-fragment-store.ts +0 -89
  252. package/src/preservation/opaque-region.ts +0 -233
  253. package/src/preservation/package-preservation.ts +0 -113
  254. package/src/preservation/preserved-part-manifest.ts +0 -56
  255. package/src/preservation/relationship-retention.ts +0 -57
  256. package/src/preservation/store.ts +0 -185
  257. package/src/review/README.md +0 -16
  258. package/src/review/store/README.md +0 -3
  259. package/src/review/store/comment-anchors.ts +0 -70
  260. package/src/review/store/comment-remapping.ts +0 -154
  261. package/src/review/store/comment-store.ts +0 -331
  262. package/src/review/store/comment-thread.ts +0 -109
  263. package/src/review/store/revision-actions.ts +0 -394
  264. package/src/review/store/revision-store.ts +0 -312
  265. package/src/review/store/revision-types.ts +0 -171
  266. package/src/review/store/runtime-comment-store.ts +0 -43
  267. package/src/runtime/README.md +0 -3
  268. package/src/runtime/ai-action-policy.ts +0 -764
  269. package/src/runtime/collab-review-sync.ts +0 -254
  270. package/src/runtime/document-layout.ts +0 -332
  271. package/src/runtime/document-navigation.ts +0 -603
  272. package/src/runtime/document-runtime.ts +0 -3159
  273. package/src/runtime/document-search.ts +0 -145
  274. package/src/runtime/numbering-prefix.ts +0 -216
  275. package/src/runtime/page-layout-estimation.ts +0 -212
  276. package/src/runtime/read-only-diagnostics-runtime.ts +0 -241
  277. package/src/runtime/review-runtime.ts +0 -44
  278. package/src/runtime/revision-runtime.ts +0 -107
  279. package/src/runtime/session-capabilities.ts +0 -192
  280. package/src/runtime/story-context.ts +0 -164
  281. package/src/runtime/story-targeting.ts +0 -162
  282. package/src/runtime/surface-projection.ts +0 -1357
  283. package/src/runtime/table-commands.ts +0 -173
  284. package/src/runtime/table-schema.ts +0 -309
  285. package/src/runtime/view-state.ts +0 -477
  286. package/src/runtime/virtualized-rendering.ts +0 -258
  287. package/src/runtime/workflow-markup.ts +0 -353
  288. package/src/ui/README.md +0 -30
  289. package/src/ui/WordReviewEditor.tsx +0 -4097
  290. package/src/ui/browser-export.ts +0 -52
  291. package/src/ui/comments/README.md +0 -3
  292. package/src/ui/compatibility/README.md +0 -3
  293. package/src/ui/editor-command-bag.ts +0 -120
  294. package/src/ui/editor-runtime-boundary.ts +0 -1457
  295. package/src/ui/editor-shell-view.tsx +0 -142
  296. package/src/ui/editor-surface/README.md +0 -3
  297. package/src/ui/editor-surface-controller.tsx +0 -63
  298. package/src/ui/headless/comment-decoration-model.ts +0 -124
  299. package/src/ui/headless/preserve-editor-selection.ts +0 -5
  300. package/src/ui/headless/revision-decoration-model.ts +0 -128
  301. package/src/ui/headless/selection-helpers.ts +0 -54
  302. package/src/ui/headless/selection-toolbar-model.ts +0 -34
  303. package/src/ui/headless/use-editor-keyboard.ts +0 -103
  304. package/src/ui/review/README.md +0 -3
  305. package/src/ui/runtime-snapshot-selectors.ts +0 -197
  306. package/src/ui/shared/revision-filters.ts +0 -31
  307. package/src/ui/status/README.md +0 -3
  308. package/src/ui/theme/README.md +0 -3
  309. package/src/ui/toolbar/README.md +0 -3
  310. package/src/ui/workflow-surface-blocked-rails.ts +0 -94
  311. package/src/ui-tailwind/chrome/tw-alert-banner.tsx +0 -64
  312. package/src/ui-tailwind/chrome/tw-image-context-toolbar.tsx +0 -129
  313. package/src/ui-tailwind/chrome/tw-layout-panel.tsx +0 -114
  314. package/src/ui-tailwind/chrome/tw-object-context-toolbar.tsx +0 -34
  315. package/src/ui-tailwind/chrome/tw-page-ruler.tsx +0 -386
  316. package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +0 -186
  317. package/src/ui-tailwind/chrome/tw-suggestion-card.tsx +0 -139
  318. package/src/ui-tailwind/chrome/tw-table-context-toolbar.tsx +0 -128
  319. package/src/ui-tailwind/chrome/tw-unsaved-modal.tsx +0 -58
  320. package/src/ui-tailwind/chrome/use-before-unload.ts +0 -20
  321. package/src/ui-tailwind/editor-surface/perf-probe.ts +0 -179
  322. package/src/ui-tailwind/editor-surface/pm-collab-plugins.ts +0 -40
  323. package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +0 -178
  324. package/src/ui-tailwind/editor-surface/pm-contextual-ui.ts +0 -31
  325. package/src/ui-tailwind/editor-surface/pm-decorations.ts +0 -427
  326. package/src/ui-tailwind/editor-surface/pm-position-map.ts +0 -123
  327. package/src/ui-tailwind/editor-surface/pm-schema.ts +0 -876
  328. package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +0 -504
  329. package/src/ui-tailwind/editor-surface/search-plugin.ts +0 -168
  330. package/src/ui-tailwind/editor-surface/surface-build-keys.ts +0 -61
  331. package/src/ui-tailwind/editor-surface/tw-caret.tsx +0 -12
  332. package/src/ui-tailwind/editor-surface/tw-editor-surface.tsx +0 -150
  333. package/src/ui-tailwind/editor-surface/tw-inline-token.tsx +0 -129
  334. package/src/ui-tailwind/editor-surface/tw-opaque-block.tsx +0 -58
  335. package/src/ui-tailwind/editor-surface/tw-paragraph-block.tsx +0 -151
  336. package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +0 -973
  337. package/src/ui-tailwind/editor-surface/tw-segment-view.tsx +0 -111
  338. package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +0 -436
  339. package/src/ui-tailwind/index.ts +0 -62
  340. package/src/ui-tailwind/page-chrome-model.ts +0 -27
  341. package/src/ui-tailwind/review/tw-comment-sidebar.tsx +0 -406
  342. package/src/ui-tailwind/review/tw-health-panel.tsx +0 -149
  343. package/src/ui-tailwind/review/tw-review-rail.tsx +0 -120
  344. package/src/ui-tailwind/review/tw-revision-sidebar.tsx +0 -164
  345. package/src/ui-tailwind/status/tw-status-bar.tsx +0 -61
  346. package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +0 -52
  347. package/src/ui-tailwind/toolbar/tw-toolbar.tsx +0 -1064
  348. package/src/ui-tailwind/tw-review-workspace.tsx +0 -1417
  349. package/src/validation/README.md +0 -3
  350. package/src/validation/compatibility-engine.ts +0 -634
  351. package/src/validation/compatibility-report.ts +0 -161
  352. package/src/validation/diagnostics.ts +0 -204
  353. package/src/validation/docx-comment-proof.ts +0 -707
  354. package/src/validation/import-diagnostics.ts +0 -128
  355. package/src/validation/low-priority-word-surfaces.ts +0 -373
  356. /package/{src → dist}/ui-tailwind/theme/editor-theme.css +0 -0
@@ -0,0 +1,3069 @@
1
+ import {
2
+ normalizePartPath,
3
+ resolveRelationshipTarget
4
+ } from "./chunk-FUDY333O.js";
5
+ import {
6
+ classifyFieldInstruction
7
+ } from "./chunk-TLCEAQDQ.js";
8
+
9
+ // src/io/ooxml/parse-numbering.ts
10
+ function parseNumberingXml(xml) {
11
+ const root = parseXml(xml);
12
+ const numberingElement = findChildElement(root, "numbering");
13
+ const abstractDefinitions = {};
14
+ const instances = {};
15
+ for (const child of numberingElement.children) {
16
+ if (child.type !== "element") {
17
+ continue;
18
+ }
19
+ switch (localName(child.name)) {
20
+ case "abstractNum": {
21
+ const rawId = child.attributes["w:abstractNumId"] ?? child.attributes.abstractNumId;
22
+ if (!rawId) {
23
+ continue;
24
+ }
25
+ const abstractNumberingId = toCanonicalAbstractNumberingId(rawId);
26
+ abstractDefinitions[abstractNumberingId] = {
27
+ abstractNumberingId,
28
+ levels: readLevels(child)
29
+ };
30
+ break;
31
+ }
32
+ case "num": {
33
+ const rawId = child.attributes["w:numId"] ?? child.attributes.numId;
34
+ const abstractReference = findChildElementOptional(child, "abstractNumId");
35
+ const rawAbstractId = abstractReference?.attributes["w:val"] ?? abstractReference?.attributes.val;
36
+ if (!rawId || !rawAbstractId) {
37
+ continue;
38
+ }
39
+ const numberingInstanceId = toCanonicalNumberingInstanceId(rawId);
40
+ instances[numberingInstanceId] = {
41
+ numberingInstanceId,
42
+ abstractNumberingId: toCanonicalAbstractNumberingId(rawAbstractId),
43
+ overrides: readOverrides(child)
44
+ };
45
+ break;
46
+ }
47
+ }
48
+ }
49
+ return {
50
+ abstractDefinitions,
51
+ instances
52
+ };
53
+ }
54
+ function toCanonicalAbstractNumberingId(value) {
55
+ return value.startsWith("abstract-num:") ? value : `abstract-num:${value}`;
56
+ }
57
+ function toCanonicalNumberingInstanceId(value) {
58
+ return value.startsWith("num:") ? value : `num:${value}`;
59
+ }
60
+ function readLevels(abstractNode) {
61
+ const levels = [];
62
+ for (const child of abstractNode.children) {
63
+ if (child.type !== "element" || localName(child.name) !== "lvl") {
64
+ continue;
65
+ }
66
+ const rawLevel = child.attributes["w:ilvl"] ?? child.attributes.ilvl;
67
+ const level = rawLevel === void 0 ? void 0 : parseInteger(rawLevel);
68
+ if (level === void 0) {
69
+ continue;
70
+ }
71
+ const startNode = findChildElementOptional(child, "start");
72
+ const formatNode = findChildElementOptional(child, "numFmt");
73
+ const textNode = findChildElementOptional(child, "lvlText");
74
+ const paragraphStyleNode = findChildElementOptional(child, "pStyle");
75
+ const rawStart = startNode?.attributes["w:val"] ?? startNode?.attributes.val;
76
+ const startAt = rawStart === void 0 ? void 0 : parseInteger(rawStart);
77
+ const format = formatNode?.attributes["w:val"] ?? formatNode?.attributes.val ?? "decimal";
78
+ const text = textNode?.attributes["w:val"] ?? textNode?.attributes.val ?? `%${level + 1}.`;
79
+ const paragraphStyleId = paragraphStyleNode?.attributes["w:val"] ?? paragraphStyleNode?.attributes.val;
80
+ const isLegalNode = findChildElementOptional(child, "isLgl");
81
+ const isLegalNumbering = isLegalNode !== void 0;
82
+ const suffixNode = findChildElementOptional(child, "suff");
83
+ const suffixVal = suffixNode?.attributes["w:val"] ?? suffixNode?.attributes.val;
84
+ const suffix = suffixVal === "space" || suffixVal === "nothing" ? suffixVal : suffixVal === "tab" ? "tab" : void 0;
85
+ levels.push({
86
+ level,
87
+ format,
88
+ text,
89
+ ...startAt !== void 0 ? { startAt } : {},
90
+ ...paragraphStyleId ? { paragraphStyleId } : {},
91
+ ...isLegalNumbering ? { isLegalNumbering } : {},
92
+ ...suffix ? { suffix } : {}
93
+ });
94
+ }
95
+ return levels.sort((left, right) => left.level - right.level);
96
+ }
97
+ function readOverrides(numNode) {
98
+ const overrides = [];
99
+ for (const child of numNode.children) {
100
+ if (child.type !== "element" || localName(child.name) !== "lvlOverride") {
101
+ continue;
102
+ }
103
+ const rawLevel = child.attributes["w:ilvl"] ?? child.attributes.ilvl;
104
+ const level = rawLevel === void 0 ? void 0 : parseInteger(rawLevel);
105
+ if (level === void 0) {
106
+ continue;
107
+ }
108
+ const startOverrideNode = findChildElementOptional(child, "startOverride");
109
+ const rawStart = startOverrideNode?.attributes["w:val"] ?? startOverrideNode?.attributes.val;
110
+ const startAt = rawStart === void 0 ? void 0 : parseInteger(rawStart);
111
+ overrides.push({
112
+ level,
113
+ ...startAt !== void 0 ? { startAt } : {}
114
+ });
115
+ }
116
+ return overrides.sort((left, right) => left.level - right.level);
117
+ }
118
+ function findChildElement(node, childLocalName) {
119
+ const child = findChildElementOptional(node, childLocalName);
120
+ if (!child) {
121
+ throw new Error(`Expected <${childLocalName}> element in numbering XML.`);
122
+ }
123
+ return child;
124
+ }
125
+ function findChildElementOptional(node, childLocalName) {
126
+ return node.children.find(
127
+ (entry) => entry.type === "element" && localName(entry.name) === childLocalName
128
+ );
129
+ }
130
+ function localName(name) {
131
+ const separatorIndex = name.indexOf(":");
132
+ return separatorIndex >= 0 ? name.slice(separatorIndex + 1) : name;
133
+ }
134
+ function parseInteger(value) {
135
+ if (!/^-?\d+$/.test(value)) {
136
+ return void 0;
137
+ }
138
+ return Number.parseInt(value, 10);
139
+ }
140
+ function parseXml(xml) {
141
+ const root = {
142
+ type: "element",
143
+ name: "__root__",
144
+ attributes: {},
145
+ children: []
146
+ };
147
+ const stack = [root];
148
+ let cursor = 0;
149
+ while (cursor < xml.length) {
150
+ if (xml.startsWith("<!--", cursor)) {
151
+ const end = xml.indexOf("-->", cursor);
152
+ cursor = end >= 0 ? end + 3 : xml.length;
153
+ continue;
154
+ }
155
+ if (xml.startsWith("<?", cursor)) {
156
+ const end = xml.indexOf("?>", cursor);
157
+ cursor = end >= 0 ? end + 2 : xml.length;
158
+ continue;
159
+ }
160
+ if (xml.startsWith("<![CDATA[", cursor)) {
161
+ const end = xml.indexOf("]]>", cursor);
162
+ const textEnd = end >= 0 ? end : xml.length;
163
+ stack[stack.length - 1]?.children.push({
164
+ type: "text",
165
+ text: xml.slice(cursor + 9, textEnd)
166
+ });
167
+ cursor = end >= 0 ? end + 3 : xml.length;
168
+ continue;
169
+ }
170
+ if (xml[cursor] !== "<") {
171
+ const nextTag = xml.indexOf("<", cursor);
172
+ const end = nextTag >= 0 ? nextTag : xml.length;
173
+ const text = decodeXmlEntities(xml.slice(cursor, end));
174
+ if (text.length > 0) {
175
+ stack[stack.length - 1]?.children.push({
176
+ type: "text",
177
+ text
178
+ });
179
+ }
180
+ cursor = end;
181
+ continue;
182
+ }
183
+ if (xml[cursor + 1] === "/") {
184
+ const end = xml.indexOf(">", cursor);
185
+ if (end < 0) {
186
+ throw new Error("Malformed XML: missing closing >.");
187
+ }
188
+ const name2 = xml.slice(cursor + 2, end).trim();
189
+ const current = stack.pop();
190
+ if (!current || localName(current.name) !== localName(name2)) {
191
+ throw new Error(`Malformed XML: unexpected closing tag </${name2}>.`);
192
+ }
193
+ cursor = end + 1;
194
+ continue;
195
+ }
196
+ const tagEnd = findTagEnd(xml, cursor);
197
+ const tagBody = xml.slice(cursor + 1, tagEnd);
198
+ const selfClosing = /\/\s*$/.test(tagBody);
199
+ const { name, attributes } = parseTag(tagBody.replace(/\/\s*$/, "").trim());
200
+ const element = {
201
+ type: "element",
202
+ name,
203
+ attributes,
204
+ children: []
205
+ };
206
+ stack[stack.length - 1]?.children.push(element);
207
+ if (!selfClosing) {
208
+ stack.push(element);
209
+ }
210
+ cursor = tagEnd + 1;
211
+ }
212
+ if (stack.length !== 1) {
213
+ throw new Error("Malformed XML: unclosed element.");
214
+ }
215
+ return root;
216
+ }
217
+ function parseTag(tagBody) {
218
+ let cursor = 0;
219
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
220
+ cursor += 1;
221
+ }
222
+ const nameStart = cursor;
223
+ while (cursor < tagBody.length && !/\s/.test(tagBody[cursor] ?? "")) {
224
+ cursor += 1;
225
+ }
226
+ const name = tagBody.slice(nameStart, cursor);
227
+ const attributes = {};
228
+ while (cursor < tagBody.length) {
229
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
230
+ cursor += 1;
231
+ }
232
+ if (cursor >= tagBody.length) {
233
+ break;
234
+ }
235
+ const keyStart = cursor;
236
+ while (cursor < tagBody.length && !/[\s=]/.test(tagBody[cursor] ?? "")) {
237
+ cursor += 1;
238
+ }
239
+ const key = tagBody.slice(keyStart, cursor);
240
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
241
+ cursor += 1;
242
+ }
243
+ if (tagBody[cursor] !== "=") {
244
+ attributes[key] = "";
245
+ continue;
246
+ }
247
+ cursor += 1;
248
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
249
+ cursor += 1;
250
+ }
251
+ const quote = tagBody[cursor];
252
+ if (quote !== `"` && quote !== `'`) {
253
+ throw new Error(`Malformed XML attribute ${key}.`);
254
+ }
255
+ cursor += 1;
256
+ const valueStart = cursor;
257
+ while (cursor < tagBody.length && tagBody[cursor] !== quote) {
258
+ cursor += 1;
259
+ }
260
+ const rawValue = tagBody.slice(valueStart, cursor);
261
+ attributes[key] = decodeXmlEntities(rawValue);
262
+ cursor += 1;
263
+ }
264
+ return { name, attributes };
265
+ }
266
+ function findTagEnd(xml, start) {
267
+ let cursor = start + 1;
268
+ let quote = null;
269
+ while (cursor < xml.length) {
270
+ const current = xml[cursor];
271
+ if (quote) {
272
+ if (current === quote) {
273
+ quote = null;
274
+ }
275
+ cursor += 1;
276
+ continue;
277
+ }
278
+ if (current === `"` || current === `'`) {
279
+ quote = current;
280
+ cursor += 1;
281
+ continue;
282
+ }
283
+ if (current === ">") {
284
+ return cursor;
285
+ }
286
+ cursor += 1;
287
+ }
288
+ throw new Error("Malformed XML: missing >.");
289
+ }
290
+ function decodeXmlEntities(value) {
291
+ return value.replace(/&(#x[0-9a-fA-F]+|#\d+|amp|lt|gt|quot|apos);/g, (match, entity) => {
292
+ switch (entity) {
293
+ case "amp":
294
+ return "&";
295
+ case "lt":
296
+ return "<";
297
+ case "gt":
298
+ return ">";
299
+ case "quot":
300
+ return `"`;
301
+ case "apos":
302
+ return "'";
303
+ default:
304
+ if (entity.startsWith("#x")) {
305
+ return String.fromCodePoint(Number.parseInt(entity.slice(2), 16));
306
+ }
307
+ if (entity.startsWith("#")) {
308
+ return String.fromCodePoint(Number.parseInt(entity.slice(1), 10));
309
+ }
310
+ return match;
311
+ }
312
+ });
313
+ }
314
+
315
+ // src/io/ooxml/parse-inline-media.ts
316
+ function parseInlineMediaXml(xml, relationships, mediaParts = /* @__PURE__ */ new Map(), sourcePartPath = "/word/document.xml") {
317
+ const root = parseXml2(xml);
318
+ const relationshipMap = new Map(relationships.map((relationship) => [relationship.id, relationship]));
319
+ const drawings = findDescendants(root, "drawing");
320
+ const media = [];
321
+ for (const drawing of drawings) {
322
+ const inline = findFirstDescendant(drawing, "inline");
323
+ const anchor = findFirstDescendant(drawing, "anchor");
324
+ const container = anchor ?? inline;
325
+ const blip = findFirstDescendant(drawing, "blip");
326
+ if (!container || !blip) {
327
+ continue;
328
+ }
329
+ const relationshipId = blip.attributes["r:embed"] ?? blip.attributes.embed;
330
+ if (!relationshipId) {
331
+ continue;
332
+ }
333
+ const relationship = relationshipMap.get(relationshipId);
334
+ if (!relationship || !relationship.type.endsWith("/image")) {
335
+ continue;
336
+ }
337
+ const packagePartName = normalizePartPath(
338
+ resolveRelationshipTarget(sourcePartPath, relationship)
339
+ );
340
+ const mediaPart = mediaParts.get(packagePartName);
341
+ const docProperties = findFirstDescendant(container, "docPr");
342
+ const altText = readAltText(docProperties);
343
+ const floating = anchor ? readFloatingProperties(anchor) : void 0;
344
+ const extent = findDrawingExtent(container);
345
+ const widthEmu = extent ? readEmuAttribute(extent, "cx") : void 0;
346
+ const heightEmu = extent ? readEmuAttribute(extent, "cy") : void 0;
347
+ media.push({
348
+ type: "image",
349
+ mediaId: `media:${packagePartName.slice(1)}`,
350
+ relationshipId,
351
+ packagePartName,
352
+ ...mediaPart ? { contentType: mediaPart.contentType } : {},
353
+ filename: packagePartName.slice(packagePartName.lastIndexOf("/") + 1),
354
+ ...altText ? { altText } : {},
355
+ ...widthEmu !== void 0 ? { widthEmu } : {},
356
+ ...heightEmu !== void 0 ? { heightEmu } : {},
357
+ ...anchor ? { display: "floating" } : {},
358
+ ...floating ? { floating } : {}
359
+ });
360
+ }
361
+ return media;
362
+ }
363
+ function findDrawingExtent(node) {
364
+ const wordProcessingExtent = findFirstDescendant(node, "extent");
365
+ if (wordProcessingExtent) {
366
+ return wordProcessingExtent;
367
+ }
368
+ const transform = findFirstDescendant(node, "xfrm");
369
+ if (!transform) {
370
+ return void 0;
371
+ }
372
+ return findFirstDescendant(transform, "ext");
373
+ }
374
+ function readFloatingProperties(node) {
375
+ const horizontalPosition = findFirstDescendant(node, "positionH");
376
+ const verticalPosition = findFirstDescendant(node, "positionV");
377
+ const wrap = findFirstDescendant(node, "wrapNone") ?? findFirstDescendant(node, "wrapSquare") ?? findFirstDescendant(node, "wrapTight") ?? findFirstDescendant(node, "wrapThrough") ?? findFirstDescendant(node, "wrapTopAndBottom");
378
+ const properties = {};
379
+ const horizontalAxis = readAxisPosition(horizontalPosition);
380
+ const verticalAxis = readAxisPosition(verticalPosition);
381
+ if (horizontalAxis) {
382
+ properties.horizontalPosition = horizontalAxis;
383
+ }
384
+ if (verticalAxis) {
385
+ properties.verticalPosition = verticalAxis;
386
+ }
387
+ if (wrap) {
388
+ const wrapName = localName2(wrap.name);
389
+ properties.wrap = wrapName === "wrapSquare" ? "square" : wrapName === "wrapTight" ? "tight" : wrapName === "wrapThrough" ? "through" : wrapName === "wrapTopAndBottom" ? "topAndBottom" : "none";
390
+ }
391
+ properties.behindDoc = readBooleanAttribute(node, "behindDoc");
392
+ properties.layoutInCell = readBooleanAttribute(node, "layoutInCell");
393
+ properties.allowOverlap = readBooleanAttribute(node, "allowOverlap");
394
+ return Object.values(properties).some((value) => value !== void 0) ? properties : void 0;
395
+ }
396
+ function readAxisPosition(node) {
397
+ if (!node) {
398
+ return void 0;
399
+ }
400
+ const align = findFirstDescendant(node, "align");
401
+ const posOffset = findFirstDescendant(node, "posOffset");
402
+ const position = {
403
+ ...readOptionalAttribute(node, "relativeFrom") ? { relativeFrom: readOptionalAttribute(node, "relativeFrom") } : {},
404
+ ...align && extractText(align).trim() ? { align: extractText(align).trim() } : {}
405
+ };
406
+ if (posOffset) {
407
+ const offset = Number.parseInt(extractText(posOffset).trim(), 10);
408
+ if (Number.isFinite(offset)) {
409
+ position.offset = offset;
410
+ }
411
+ }
412
+ return Object.keys(position).length > 0 ? position : void 0;
413
+ }
414
+ function readAltText(node) {
415
+ if (!node) {
416
+ return void 0;
417
+ }
418
+ const description = node.attributes.descr?.trim();
419
+ if (description) {
420
+ return description;
421
+ }
422
+ const title = node.attributes.title?.trim();
423
+ if (title) {
424
+ return title;
425
+ }
426
+ const name = node.attributes.name?.trim();
427
+ return name || void 0;
428
+ }
429
+ function findFirstDescendant(node, local) {
430
+ for (const child of node.children) {
431
+ if (child.type !== "element") {
432
+ continue;
433
+ }
434
+ if (localName2(child.name) === local) {
435
+ return child;
436
+ }
437
+ const nested = findFirstDescendant(child, local);
438
+ if (nested) {
439
+ return nested;
440
+ }
441
+ }
442
+ return void 0;
443
+ }
444
+ function findDescendants(node, local) {
445
+ const results = [];
446
+ for (const child of node.children) {
447
+ if (child.type !== "element") {
448
+ continue;
449
+ }
450
+ if (localName2(child.name) === local) {
451
+ results.push(child);
452
+ }
453
+ results.push(...findDescendants(child, local));
454
+ }
455
+ return results;
456
+ }
457
+ function localName2(name) {
458
+ const separatorIndex = name.indexOf(":");
459
+ return separatorIndex >= 0 ? name.slice(separatorIndex + 1) : name;
460
+ }
461
+ function extractText(node) {
462
+ return node.children.map((child) => child.type === "text" ? child.text : extractText(child)).join("");
463
+ }
464
+ function readOptionalAttribute(node, name) {
465
+ return node.attributes[`wp:${name}`] ?? node.attributes[`w:${name}`] ?? node.attributes[name];
466
+ }
467
+ function readEmuAttribute(node, name) {
468
+ const value = node.attributes[name] ?? node.attributes[`wp:${name}`];
469
+ if (value === void 0) return void 0;
470
+ const parsed = Number.parseInt(value, 10);
471
+ return Number.isFinite(parsed) && parsed >= 0 ? parsed : void 0;
472
+ }
473
+ function readBooleanAttribute(node, name) {
474
+ const value = readOptionalAttribute(node, name);
475
+ if (value === void 0) {
476
+ return void 0;
477
+ }
478
+ return value !== "0" && value !== "false" && value !== "off";
479
+ }
480
+ function parseXml2(xml) {
481
+ const root = {
482
+ type: "element",
483
+ name: "__root__",
484
+ attributes: {},
485
+ children: []
486
+ };
487
+ const stack = [root];
488
+ let cursor = 0;
489
+ while (cursor < xml.length) {
490
+ if (xml.startsWith("<!--", cursor)) {
491
+ const end = xml.indexOf("-->", cursor);
492
+ cursor = end >= 0 ? end + 3 : xml.length;
493
+ continue;
494
+ }
495
+ if (xml.startsWith("<?", cursor)) {
496
+ const end = xml.indexOf("?>", cursor);
497
+ cursor = end >= 0 ? end + 2 : xml.length;
498
+ continue;
499
+ }
500
+ if (xml[cursor] !== "<") {
501
+ const nextTag = xml.indexOf("<", cursor);
502
+ const end = nextTag >= 0 ? nextTag : xml.length;
503
+ const text = decodeXmlEntities2(xml.slice(cursor, end));
504
+ if (text.length > 0) {
505
+ stack[stack.length - 1]?.children.push({ type: "text", text });
506
+ }
507
+ cursor = end;
508
+ continue;
509
+ }
510
+ if (xml[cursor + 1] === "/") {
511
+ const end = xml.indexOf(">", cursor);
512
+ const current = stack.pop();
513
+ const name2 = xml.slice(cursor + 2, end).trim();
514
+ if (!current || localName2(current.name) !== localName2(name2)) {
515
+ throw new Error(`Malformed XML: unexpected closing tag </${name2}>.`);
516
+ }
517
+ cursor = end + 1;
518
+ continue;
519
+ }
520
+ const tagEnd = findTagEnd2(xml, cursor);
521
+ const tagBody = xml.slice(cursor + 1, tagEnd);
522
+ const selfClosing = /\/\s*$/.test(tagBody);
523
+ const { name, attributes } = parseTag2(tagBody.replace(/\/\s*$/, "").trim());
524
+ const element = {
525
+ type: "element",
526
+ name,
527
+ attributes,
528
+ children: []
529
+ };
530
+ stack[stack.length - 1]?.children.push(element);
531
+ if (!selfClosing) {
532
+ stack.push(element);
533
+ }
534
+ cursor = tagEnd + 1;
535
+ }
536
+ if (stack.length !== 1) {
537
+ throw new Error("Malformed XML: unclosed element.");
538
+ }
539
+ return root;
540
+ }
541
+ function parseTag2(tagBody) {
542
+ let cursor = 0;
543
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
544
+ cursor += 1;
545
+ }
546
+ const nameStart = cursor;
547
+ while (cursor < tagBody.length && !/\s/.test(tagBody[cursor] ?? "")) {
548
+ cursor += 1;
549
+ }
550
+ const name = tagBody.slice(nameStart, cursor);
551
+ const attributes = {};
552
+ while (cursor < tagBody.length) {
553
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
554
+ cursor += 1;
555
+ }
556
+ if (cursor >= tagBody.length) {
557
+ break;
558
+ }
559
+ const keyStart = cursor;
560
+ while (cursor < tagBody.length && !/[\s=]/.test(tagBody[cursor] ?? "")) {
561
+ cursor += 1;
562
+ }
563
+ const key = tagBody.slice(keyStart, cursor);
564
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
565
+ cursor += 1;
566
+ }
567
+ if (tagBody[cursor] !== "=") {
568
+ attributes[key] = "";
569
+ continue;
570
+ }
571
+ cursor += 1;
572
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
573
+ cursor += 1;
574
+ }
575
+ const quote = tagBody[cursor];
576
+ if (quote !== `"` && quote !== `'`) {
577
+ throw new Error(`Malformed XML attribute ${key}.`);
578
+ }
579
+ cursor += 1;
580
+ const valueStart = cursor;
581
+ while (cursor < tagBody.length && tagBody[cursor] !== quote) {
582
+ cursor += 1;
583
+ }
584
+ attributes[key] = decodeXmlEntities2(tagBody.slice(valueStart, cursor));
585
+ cursor += 1;
586
+ }
587
+ return { name, attributes };
588
+ }
589
+ function findTagEnd2(xml, start) {
590
+ let cursor = start + 1;
591
+ let quote = null;
592
+ while (cursor < xml.length) {
593
+ const current = xml[cursor];
594
+ if (quote) {
595
+ if (current === quote) {
596
+ quote = null;
597
+ }
598
+ cursor += 1;
599
+ continue;
600
+ }
601
+ if (current === `"` || current === `'`) {
602
+ quote = current;
603
+ cursor += 1;
604
+ continue;
605
+ }
606
+ if (current === ">") {
607
+ return cursor;
608
+ }
609
+ cursor += 1;
610
+ }
611
+ throw new Error("Malformed XML: missing >.");
612
+ }
613
+ function decodeXmlEntities2(value) {
614
+ return value.replace(/&(#x[0-9a-fA-F]+|#\d+|amp|lt|gt|quot|apos);/g, (match, entity) => {
615
+ switch (entity) {
616
+ case "amp":
617
+ return "&";
618
+ case "lt":
619
+ return "<";
620
+ case "gt":
621
+ return ">";
622
+ case "quot":
623
+ return `"`;
624
+ case "apos":
625
+ return "'";
626
+ default:
627
+ if (entity.startsWith("#x")) {
628
+ return String.fromCodePoint(Number.parseInt(entity.slice(2), 16));
629
+ }
630
+ if (entity.startsWith("#")) {
631
+ return String.fromCodePoint(Number.parseInt(entity.slice(1), 10));
632
+ }
633
+ return match;
634
+ }
635
+ });
636
+ }
637
+
638
+ // src/io/ooxml/parse-complex-content.ts
639
+ var CHART_GRAPHIC_URI = "http://schemas.openxmlformats.org/drawingml/2006/chart";
640
+ var CHART_GRAPHIC_URI_ALT = "http://schemas.microsoft.com/office/drawing/2007/8/2/chart";
641
+ var SMARTART_GRAPHIC_URI = "http://schemas.microsoft.com/office/drawing/2007/8/2/diagram";
642
+ var SMARTART_GRAPHIC_URI_ALT = "http://schemas.openxmlformats.org/drawingml/2006/diagram";
643
+ function parseComplexContentXml(drawingXml, relationships, mediaParts = /* @__PURE__ */ new Map(), sourcePartPath = "/word/document.xml") {
644
+ const root = parseXml3(drawingXml);
645
+ const relationshipMap = new Map(relationships.map((r) => [r.id, r]));
646
+ const altContent = findFirstDescendant2(root, "AlternateContent");
647
+ if (altContent) {
648
+ return parseAlternateContent(altContent, drawingXml, relationshipMap, mediaParts, sourcePartPath);
649
+ }
650
+ const graphicData = findFirstDescendant2(root, "graphicData");
651
+ if (!graphicData) {
652
+ return null;
653
+ }
654
+ const uri = graphicData.attributes.uri ?? graphicData.attributes["uri"] ?? "";
655
+ if (isChartUri(uri)) {
656
+ return { type: "chart_preview", rawXml: drawingXml };
657
+ }
658
+ if (isSmartArtUri(uri)) {
659
+ return { type: "smartart_preview", rawXml: drawingXml };
660
+ }
661
+ return null;
662
+ }
663
+ function parseAlternateContent(altContent, fullDrawingXml, relationshipMap, mediaParts, sourcePartPath) {
664
+ const choice = findFirstChild(altContent, "Choice");
665
+ const fallback = findFirstChild(altContent, "Fallback");
666
+ const choiceGraphicData = choice ? findFirstDescendant2(choice, "graphicData") : null;
667
+ const choiceUri = choiceGraphicData?.attributes.uri ?? "";
668
+ let contentType = null;
669
+ if (isChartUri(choiceUri)) {
670
+ contentType = "chart_preview";
671
+ } else if (isSmartArtUri(choiceUri)) {
672
+ contentType = "smartart_preview";
673
+ } else {
674
+ const chartRef = choice ? findFirstDescendant2(choice, "chart") : null;
675
+ if (chartRef) {
676
+ contentType = "chart_preview";
677
+ }
678
+ const dmRef = choice ? findFirstDescendant2(choice, "relIds") : null;
679
+ if (dmRef) {
680
+ contentType = "smartart_preview";
681
+ }
682
+ }
683
+ if (!contentType) {
684
+ return null;
685
+ }
686
+ let previewMediaId;
687
+ if (fallback) {
688
+ const fallbackBlip = findFirstDescendant2(fallback, "blip");
689
+ if (fallbackBlip) {
690
+ const rId = fallbackBlip.attributes["r:embed"] ?? fallbackBlip.attributes.embed ?? fallbackBlip.attributes["r:link"];
691
+ if (rId) {
692
+ const rel = relationshipMap.get(rId);
693
+ if (rel && rel.type.endsWith("/image")) {
694
+ const packagePartName = normalizePartPath(
695
+ resolveRelationshipTarget(sourcePartPath, rel)
696
+ );
697
+ const mediaPart = mediaParts.get(packagePartName);
698
+ if (mediaPart) {
699
+ previewMediaId = `media:${packagePartName.slice(1)}`;
700
+ }
701
+ }
702
+ }
703
+ }
704
+ }
705
+ return {
706
+ type: contentType,
707
+ ...previewMediaId ? { previewMediaId } : {},
708
+ rawXml: fullDrawingXml
709
+ };
710
+ }
711
+ function isChartUri(uri) {
712
+ return uri === CHART_GRAPHIC_URI || uri === CHART_GRAPHIC_URI_ALT;
713
+ }
714
+ function isSmartArtUri(uri) {
715
+ return uri === SMARTART_GRAPHIC_URI || uri === SMARTART_GRAPHIC_URI_ALT || uri.includes("diagram") || uri.includes("dgm");
716
+ }
717
+ function findFirstChild(node, local) {
718
+ for (const child of node.children) {
719
+ if (child.type === "element" && localName3(child.name) === local) {
720
+ return child;
721
+ }
722
+ }
723
+ return void 0;
724
+ }
725
+ function findFirstDescendant2(node, local) {
726
+ for (const child of node.children) {
727
+ if (child.type !== "element") continue;
728
+ if (localName3(child.name) === local) return child;
729
+ const nested = findFirstDescendant2(child, local);
730
+ if (nested) return nested;
731
+ }
732
+ return void 0;
733
+ }
734
+ function localName3(name) {
735
+ const i = name.indexOf(":");
736
+ return i >= 0 ? name.slice(i + 1) : name;
737
+ }
738
+ function parseXml3(xml) {
739
+ const root = { type: "element", name: "__root__", attributes: {}, children: [] };
740
+ const stack = [root];
741
+ let cursor = 0;
742
+ while (cursor < xml.length) {
743
+ if (xml.startsWith("<!--", cursor)) {
744
+ const end = xml.indexOf("-->", cursor);
745
+ cursor = end >= 0 ? end + 3 : xml.length;
746
+ continue;
747
+ }
748
+ if (xml.startsWith("<?", cursor)) {
749
+ const end = xml.indexOf("?>", cursor);
750
+ cursor = end >= 0 ? end + 2 : xml.length;
751
+ continue;
752
+ }
753
+ if (xml[cursor] !== "<") {
754
+ const nextTag = xml.indexOf("<", cursor);
755
+ const end = nextTag >= 0 ? nextTag : xml.length;
756
+ const text = xml.slice(cursor, end);
757
+ if (text.length > 0) {
758
+ stack[stack.length - 1]?.children.push({ type: "text", text });
759
+ }
760
+ cursor = end;
761
+ continue;
762
+ }
763
+ if (xml[cursor + 1] === "/") {
764
+ const end = xml.indexOf(">", cursor);
765
+ stack.pop();
766
+ cursor = end + 1;
767
+ continue;
768
+ }
769
+ const tagEnd = findTagEnd3(xml, cursor);
770
+ const tagBody = xml.slice(cursor + 1, tagEnd);
771
+ const selfClosing = /\/\s*$/.test(tagBody);
772
+ const { name, attributes } = parseTag3(tagBody.replace(/\/\s*$/, "").trim());
773
+ const element = { type: "element", name, attributes, children: [] };
774
+ stack[stack.length - 1]?.children.push(element);
775
+ if (!selfClosing) stack.push(element);
776
+ cursor = tagEnd + 1;
777
+ }
778
+ return root;
779
+ }
780
+ function parseTag3(tagBody) {
781
+ let cursor = 0;
782
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor++;
783
+ const nameStart = cursor;
784
+ while (cursor < tagBody.length && !/\s/.test(tagBody[cursor] ?? "")) cursor++;
785
+ const name = tagBody.slice(nameStart, cursor);
786
+ const attributes = {};
787
+ while (cursor < tagBody.length) {
788
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor++;
789
+ if (cursor >= tagBody.length) break;
790
+ const keyStart = cursor;
791
+ while (cursor < tagBody.length && !/[\s=]/.test(tagBody[cursor] ?? "")) cursor++;
792
+ const key = tagBody.slice(keyStart, cursor);
793
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor++;
794
+ if (tagBody[cursor] !== "=") {
795
+ attributes[key] = "";
796
+ continue;
797
+ }
798
+ cursor++;
799
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor++;
800
+ const quote = tagBody[cursor];
801
+ if (quote !== `"` && quote !== `'`) break;
802
+ cursor++;
803
+ const valueStart = cursor;
804
+ while (cursor < tagBody.length && tagBody[cursor] !== quote) cursor++;
805
+ attributes[key] = tagBody.slice(valueStart, cursor);
806
+ cursor++;
807
+ }
808
+ return { name, attributes };
809
+ }
810
+ function findTagEnd3(xml, start) {
811
+ let cursor = start + 1;
812
+ let quote = null;
813
+ while (cursor < xml.length) {
814
+ const c = xml[cursor];
815
+ if (quote) {
816
+ if (c === quote) quote = null;
817
+ cursor++;
818
+ continue;
819
+ }
820
+ if (c === `"` || c === `'`) {
821
+ quote = c;
822
+ cursor++;
823
+ continue;
824
+ }
825
+ if (c === ">") return cursor;
826
+ cursor++;
827
+ }
828
+ return xml.length - 1;
829
+ }
830
+
831
+ // src/io/ooxml/parse-shapes.ts
832
+ var WPS_SHAPE_GRAPHIC_URI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
833
+ function parseShapeXml(drawingXml) {
834
+ const root = parseXml4(drawingXml);
835
+ const graphicData = findFirstDescendant3(root, "graphicData");
836
+ if (!graphicData) return null;
837
+ const uri = graphicData.attributes.uri ?? "";
838
+ if (uri !== WPS_SHAPE_GRAPHIC_URI) return null;
839
+ const wsp = findFirstDescendant3(root, "wsp");
840
+ if (!wsp) return null;
841
+ const spPr = findFirstChild2(wsp, "spPr");
842
+ const prstGeom = spPr ? findFirstDescendant3(spPr, "prstGeom") : null;
843
+ const prst = prstGeom?.attributes.prst ?? prstGeom?.attributes["prst"] ?? void 0;
844
+ const txbx = findFirstChild2(wsp, "txbx");
845
+ const txbxContent = txbx ? findFirstDescendant3(txbx, "txbxContent") : null;
846
+ const text = txbxContent ? extractAllText(txbxContent).trim() || void 0 : void 0;
847
+ if (prst && /^text/i.test(prst)) {
848
+ return {
849
+ type: "wordart",
850
+ text: text ?? "",
851
+ ...prst ? { geometry: prst } : {},
852
+ rawXml: drawingXml
853
+ };
854
+ }
855
+ const isTextBox = Boolean(txbxContent && (!prst || prst === "rect"));
856
+ const txbxContentXml = txbxContent ? extractRawXml(txbxContent, drawingXml) : void 0;
857
+ return {
858
+ type: "shape",
859
+ ...isTextBox ? { isTextBox: true } : {},
860
+ ...text ? { text } : {},
861
+ ...txbxContentXml ? { txbxContentXml } : {},
862
+ ...prst ? { geometry: prst } : {},
863
+ rawXml: drawingXml
864
+ };
865
+ }
866
+ function parseVmlXml(pictXml) {
867
+ const root = parseXml4(pictXml);
868
+ const vShape = findFirstDescendant3(root, "shape");
869
+ const vRect = findFirstDescendant3(root, "rect");
870
+ const vTextbox = findFirstDescendant3(root, "textbox");
871
+ const vmlNode = vShape ?? vRect ?? vTextbox;
872
+ if (!vmlNode) return null;
873
+ const shapeType = vShape?.attributes.type ?? vShape?.attributes["type"] ?? void 0;
874
+ let text;
875
+ const textboxNode = findFirstDescendant3(vmlNode, "textbox") ?? (localName4(vmlNode.name) === "textbox" ? vmlNode : null);
876
+ if (textboxNode) {
877
+ const txbxContent = findFirstDescendant3(textboxNode, "txbxContent");
878
+ if (txbxContent) {
879
+ text = extractAllText(txbxContent).trim() || void 0;
880
+ } else {
881
+ text = extractAllText(textboxNode).trim() || void 0;
882
+ }
883
+ }
884
+ return {
885
+ type: "vml_shape",
886
+ ...shapeType ? { shapeType } : {},
887
+ ...text ? { text } : {},
888
+ rawXml: pictXml
889
+ };
890
+ }
891
+ function extractRawXml(node, sourceXml) {
892
+ const tagName = node.name;
893
+ const openIdx = sourceXml.indexOf(`<${tagName}`);
894
+ if (openIdx < 0) return void 0;
895
+ const closeTag = `</${tagName}>`;
896
+ const closeIdx = sourceXml.indexOf(closeTag, openIdx);
897
+ if (closeIdx < 0) return void 0;
898
+ return sourceXml.slice(openIdx, closeIdx + closeTag.length);
899
+ }
900
+ function extractAllText(node) {
901
+ return node.children.map((child) => {
902
+ if (child.type === "text") return child.text;
903
+ if (child.type === "element" && localName4(child.name) === "t") {
904
+ return extractAllText(child);
905
+ }
906
+ return extractAllText(child);
907
+ }).join("");
908
+ }
909
+ function findFirstChild2(node, local) {
910
+ for (const child of node.children) {
911
+ if (child.type === "element" && localName4(child.name) === local) return child;
912
+ }
913
+ return void 0;
914
+ }
915
+ function findFirstDescendant3(node, local) {
916
+ for (const child of node.children) {
917
+ if (child.type !== "element") continue;
918
+ if (localName4(child.name) === local) return child;
919
+ const nested = findFirstDescendant3(child, local);
920
+ if (nested) return nested;
921
+ }
922
+ return void 0;
923
+ }
924
+ function localName4(name) {
925
+ const i = name.indexOf(":");
926
+ return i >= 0 ? name.slice(i + 1) : name;
927
+ }
928
+ function parseXml4(xml) {
929
+ const root = { type: "element", name: "__root__", attributes: {}, children: [] };
930
+ const stack = [root];
931
+ let cursor = 0;
932
+ while (cursor < xml.length) {
933
+ if (xml.startsWith("<!--", cursor)) {
934
+ const end = xml.indexOf("-->", cursor);
935
+ cursor = end >= 0 ? end + 3 : xml.length;
936
+ continue;
937
+ }
938
+ if (xml.startsWith("<?", cursor)) {
939
+ const end = xml.indexOf("?>", cursor);
940
+ cursor = end >= 0 ? end + 2 : xml.length;
941
+ continue;
942
+ }
943
+ if (xml[cursor] !== "<") {
944
+ const nextTag = xml.indexOf("<", cursor);
945
+ const end = nextTag >= 0 ? nextTag : xml.length;
946
+ const text = xml.slice(cursor, end);
947
+ if (text.length > 0) stack[stack.length - 1]?.children.push({ type: "text", text });
948
+ cursor = end;
949
+ continue;
950
+ }
951
+ if (xml[cursor + 1] === "/") {
952
+ const end = xml.indexOf(">", cursor);
953
+ stack.pop();
954
+ cursor = end + 1;
955
+ continue;
956
+ }
957
+ const tagEnd = findTagEnd4(xml, cursor);
958
+ const tagBody = xml.slice(cursor + 1, tagEnd);
959
+ const selfClosing = /\/\s*$/.test(tagBody);
960
+ const { name, attributes } = parseTag4(tagBody.replace(/\/\s*$/, "").trim());
961
+ const element = { type: "element", name, attributes, children: [] };
962
+ stack[stack.length - 1]?.children.push(element);
963
+ if (!selfClosing) stack.push(element);
964
+ cursor = tagEnd + 1;
965
+ }
966
+ return root;
967
+ }
968
+ function parseTag4(tagBody) {
969
+ let cursor = 0;
970
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor++;
971
+ const nameStart = cursor;
972
+ while (cursor < tagBody.length && !/\s/.test(tagBody[cursor] ?? "")) cursor++;
973
+ const name = tagBody.slice(nameStart, cursor);
974
+ const attributes = {};
975
+ while (cursor < tagBody.length) {
976
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor++;
977
+ if (cursor >= tagBody.length) break;
978
+ const keyStart = cursor;
979
+ while (cursor < tagBody.length && !/[\s=]/.test(tagBody[cursor] ?? "")) cursor++;
980
+ const key = tagBody.slice(keyStart, cursor);
981
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor++;
982
+ if (tagBody[cursor] !== "=") {
983
+ attributes[key] = "";
984
+ continue;
985
+ }
986
+ cursor++;
987
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor++;
988
+ const quote = tagBody[cursor];
989
+ if (quote !== `"` && quote !== `'`) break;
990
+ cursor++;
991
+ const valueStart = cursor;
992
+ while (cursor < tagBody.length && tagBody[cursor] !== quote) cursor++;
993
+ attributes[key] = tagBody.slice(valueStart, cursor);
994
+ cursor++;
995
+ }
996
+ return { name, attributes };
997
+ }
998
+ function findTagEnd4(xml, start) {
999
+ let cursor = start + 1;
1000
+ let quote = null;
1001
+ while (cursor < xml.length) {
1002
+ const c = xml[cursor];
1003
+ if (quote) {
1004
+ if (c === quote) quote = null;
1005
+ cursor++;
1006
+ continue;
1007
+ }
1008
+ if (c === `"` || c === `'`) {
1009
+ quote = c;
1010
+ cursor++;
1011
+ continue;
1012
+ }
1013
+ if (c === ">") return cursor;
1014
+ cursor++;
1015
+ }
1016
+ return xml.length - 1;
1017
+ }
1018
+
1019
+ // src/io/ooxml/highlight-colors.ts
1020
+ var HIGHLIGHT_COLOR_MAP = {
1021
+ black: "000000",
1022
+ blue: "0000FF",
1023
+ cyan: "00FFFF",
1024
+ darkBlue: "000080",
1025
+ darkCyan: "008080",
1026
+ darkGray: "808080",
1027
+ darkGreen: "008000",
1028
+ darkMagenta: "800080",
1029
+ darkRed: "8B0000",
1030
+ darkYellow: "808000",
1031
+ green: "00FF00",
1032
+ lightGray: "C0C0C0",
1033
+ magenta: "FF00FF",
1034
+ red: "FF0000",
1035
+ white: "FFFFFF",
1036
+ yellow: "FFFF00"
1037
+ };
1038
+ function resolveHighlightColor(value) {
1039
+ if (!value || value === "none") {
1040
+ return void 0;
1041
+ }
1042
+ const normalizedValue = value;
1043
+ const color = HIGHLIGHT_COLOR_MAP[normalizedValue];
1044
+ if (!color) {
1045
+ return void 0;
1046
+ }
1047
+ return {
1048
+ color,
1049
+ val: normalizedValue
1050
+ };
1051
+ }
1052
+
1053
+ // src/io/ooxml/parse-main-document.ts
1054
+ var HYPERLINK_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
1055
+ function parseMainDocumentXml(xml, relationships = [], mediaParts = /* @__PURE__ */ new Map(), sourcePartPath = "/word/document.xml") {
1056
+ const root = parseXml5(xml);
1057
+ const documentElement = findChildElement2(root, "document");
1058
+ const bodyElement = findChildElement2(documentElement, "body");
1059
+ const relationshipMap = new Map(relationships.map((relationship) => [relationship.id, relationship]));
1060
+ const allBlocks = bodyElement.children.filter((node) => node.type === "element").map((node) => parseBodyChild(node, xml, relationshipMap, relationships, mediaParts, sourcePartPath));
1061
+ let finalSectionProperties;
1062
+ const blocks = [];
1063
+ for (let i = 0; i < allBlocks.length; i++) {
1064
+ const block = allBlocks[i];
1065
+ if (block.type === "section_break" && i === allBlocks.length - 1) {
1066
+ finalSectionProperties = block.sectionProperties;
1067
+ } else {
1068
+ blocks.push(block);
1069
+ }
1070
+ }
1071
+ return { blocks, finalSectionProperties };
1072
+ }
1073
+ function parseBodyChild(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath) {
1074
+ const nodeType = localName5(node.name);
1075
+ if (nodeType === "tbl") {
1076
+ const rawTableXml = sourceXml.slice(node.start, node.end);
1077
+ if (tableRequiresOpaquePreservation(rawTableXml)) {
1078
+ return {
1079
+ type: "opaque_block",
1080
+ rawXml: rawTableXml
1081
+ };
1082
+ }
1083
+ try {
1084
+ return parseTableElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath);
1085
+ } catch {
1086
+ return {
1087
+ type: "opaque_block",
1088
+ rawXml: rawTableXml
1089
+ };
1090
+ }
1091
+ }
1092
+ if (nodeType === "sdt") {
1093
+ return parseSdtElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath);
1094
+ }
1095
+ if (nodeType === "customXml") {
1096
+ return parseCustomXmlElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath);
1097
+ }
1098
+ if (nodeType === "altChunk") {
1099
+ return parseAltChunkElement(node, sourceXml);
1100
+ }
1101
+ if (nodeType === "sectPr") {
1102
+ return parseSectionBreakElement(node, sourceXml);
1103
+ }
1104
+ if (nodeType !== "p") {
1105
+ return {
1106
+ type: "opaque_block",
1107
+ rawXml: sourceXml.slice(node.start, node.end)
1108
+ };
1109
+ }
1110
+ let styleId;
1111
+ let numbering;
1112
+ let alignment;
1113
+ let spacing;
1114
+ let contextualSpacing;
1115
+ let indentation;
1116
+ let tabStops;
1117
+ let keepNext;
1118
+ let keepLines;
1119
+ let outlineLevel;
1120
+ let pageBreakBefore;
1121
+ let widowControl;
1122
+ let borders;
1123
+ let shading;
1124
+ let bidi;
1125
+ let suppressLineNumbers;
1126
+ let cnfStyle;
1127
+ let sectionProperties;
1128
+ let sectionPropertiesXml;
1129
+ let paragraphSupported = true;
1130
+ const children = [];
1131
+ let activeComplexField = null;
1132
+ for (const child of node.children) {
1133
+ if (child.type !== "element") {
1134
+ continue;
1135
+ }
1136
+ switch (localName5(child.name)) {
1137
+ case "pPr":
1138
+ styleId = readParagraphStyleId(child);
1139
+ numbering = readParagraphNumbering(child);
1140
+ alignment = readParagraphAlignment(child);
1141
+ spacing = readParagraphSpacing(child);
1142
+ contextualSpacing = readOptionalOnOffParagraphProperty(child, "contextualSpacing");
1143
+ indentation = readParagraphIndentation(child);
1144
+ tabStops = readParagraphTabStops(child);
1145
+ keepNext = readOnOffParagraphProperty(child, "keepNext");
1146
+ keepLines = readOnOffParagraphProperty(child, "keepLines");
1147
+ outlineLevel = readParagraphOutlineLevel(child);
1148
+ pageBreakBefore = readOnOffParagraphProperty(child, "pageBreakBefore");
1149
+ widowControl = readOnOffParagraphProperty(child, "widowControl");
1150
+ borders = readParagraphBorders(child);
1151
+ shading = readParagraphShading(child);
1152
+ bidi = readOnOffParagraphProperty(child, "bidi");
1153
+ suppressLineNumbers = readOnOffParagraphProperty(child, "suppressLineNumbers");
1154
+ cnfStyle = readParagraphCnfStyle(child);
1155
+ sectionProperties = readSectionPropertiesFromPPr(child);
1156
+ sectionPropertiesXml = readSectionPropertiesXmlFromPPr(child, sourceXml);
1157
+ paragraphSupported = paragraphSupported && supportsParagraphProperties(child);
1158
+ break;
1159
+ case "r":
1160
+ activeComplexField = appendParagraphRunNodes(
1161
+ child,
1162
+ children,
1163
+ activeComplexField,
1164
+ sourceXml,
1165
+ relationships,
1166
+ mediaParts,
1167
+ sourcePartPath
1168
+ );
1169
+ break;
1170
+ case "hyperlink": {
1171
+ flushActiveComplexField(children, () => {
1172
+ activeComplexField = null;
1173
+ }, activeComplexField);
1174
+ const hyperlink = parseHyperlink(child, sourceXml, relationshipMap);
1175
+ children.push(hyperlink);
1176
+ break;
1177
+ }
1178
+ case "ins":
1179
+ case "del": {
1180
+ flushActiveComplexField(children, () => {
1181
+ activeComplexField = null;
1182
+ }, activeComplexField);
1183
+ children.push(...parseRevisionContainer(child, sourceXml, relationshipMap));
1184
+ break;
1185
+ }
1186
+ case "commentRangeStart":
1187
+ case "commentRangeEnd":
1188
+ break;
1189
+ case "bookmarkStart": {
1190
+ const bkId = child.attributes["w:id"] ?? child.attributes.id ?? "";
1191
+ const bkName = child.attributes["w:name"] ?? child.attributes.name ?? "";
1192
+ if (bkId) {
1193
+ const bookmarkNode = {
1194
+ type: "bookmark_start",
1195
+ bookmarkId: bkId,
1196
+ name: bkName,
1197
+ rawXml: sourceXml.slice(child.start, child.end)
1198
+ };
1199
+ flushActiveComplexField(children, () => {
1200
+ activeComplexField = null;
1201
+ }, activeComplexField);
1202
+ children.push(bookmarkNode);
1203
+ } else {
1204
+ flushActiveComplexField(children, () => {
1205
+ activeComplexField = null;
1206
+ }, activeComplexField);
1207
+ children.push({ type: "opaque_inline", rawXml: sourceXml.slice(child.start, child.end) });
1208
+ }
1209
+ break;
1210
+ }
1211
+ case "bookmarkEnd": {
1212
+ const bkEndId = child.attributes["w:id"] ?? child.attributes.id ?? "";
1213
+ if (bkEndId) {
1214
+ const bookmarkNode = {
1215
+ type: "bookmark_end",
1216
+ bookmarkId: bkEndId,
1217
+ rawXml: sourceXml.slice(child.start, child.end)
1218
+ };
1219
+ flushActiveComplexField(children, () => {
1220
+ activeComplexField = null;
1221
+ }, activeComplexField);
1222
+ children.push(bookmarkNode);
1223
+ } else {
1224
+ flushActiveComplexField(children, () => {
1225
+ activeComplexField = null;
1226
+ }, activeComplexField);
1227
+ children.push({ type: "opaque_inline", rawXml: sourceXml.slice(child.start, child.end) });
1228
+ }
1229
+ break;
1230
+ }
1231
+ case "fldSimple": {
1232
+ flushActiveComplexField(children, () => {
1233
+ activeComplexField = null;
1234
+ }, activeComplexField);
1235
+ const fieldInstr = child.attributes["w:instr"] ?? child.attributes.instr ?? "";
1236
+ const fieldContentXml = child.children.filter((c) => c.type === "element").map((c) => sourceXml.slice(c.start, c.end)).join("");
1237
+ children.push({
1238
+ type: "field",
1239
+ fieldType: "simple",
1240
+ instruction: fieldInstr,
1241
+ contentXml: fieldContentXml,
1242
+ rawXml: sourceXml.slice(child.start, child.end)
1243
+ });
1244
+ break;
1245
+ }
1246
+ case "proofErr":
1247
+ flushActiveComplexField(children, () => {
1248
+ activeComplexField = null;
1249
+ }, activeComplexField);
1250
+ children.push({
1251
+ type: "opaque_inline",
1252
+ rawXml: sourceXml.slice(child.start, child.end)
1253
+ });
1254
+ break;
1255
+ case "permStart":
1256
+ flushActiveComplexField(children, () => {
1257
+ activeComplexField = null;
1258
+ }, activeComplexField);
1259
+ children.push(parsePermStartNode(child, sourceXml));
1260
+ break;
1261
+ case "permEnd":
1262
+ flushActiveComplexField(children, () => {
1263
+ activeComplexField = null;
1264
+ }, activeComplexField);
1265
+ children.push(parsePermEndNode(child, sourceXml));
1266
+ break;
1267
+ case "footnoteReference": {
1268
+ flushActiveComplexField(children, () => {
1269
+ activeComplexField = null;
1270
+ }, activeComplexField);
1271
+ const noteId = child.attributes["w:id"] ?? child.attributes.id ?? "";
1272
+ if (noteId) {
1273
+ children.push({
1274
+ type: "footnote_ref",
1275
+ noteId,
1276
+ noteKind: "footnote"
1277
+ });
1278
+ }
1279
+ break;
1280
+ }
1281
+ case "endnoteReference": {
1282
+ flushActiveComplexField(children, () => {
1283
+ activeComplexField = null;
1284
+ }, activeComplexField);
1285
+ const noteId = child.attributes["w:id"] ?? child.attributes.id ?? "";
1286
+ if (noteId) {
1287
+ children.push({
1288
+ type: "footnote_ref",
1289
+ noteId,
1290
+ noteKind: "endnote"
1291
+ });
1292
+ }
1293
+ break;
1294
+ }
1295
+ default:
1296
+ flushActiveComplexField(children, () => {
1297
+ activeComplexField = null;
1298
+ }, activeComplexField);
1299
+ children.push({
1300
+ type: "opaque_inline",
1301
+ rawXml: sourceXml.slice(child.start, child.end)
1302
+ });
1303
+ break;
1304
+ }
1305
+ }
1306
+ flushActiveComplexField(children, () => {
1307
+ activeComplexField = null;
1308
+ }, activeComplexField);
1309
+ if (!paragraphSupported) {
1310
+ return {
1311
+ type: "opaque_block",
1312
+ rawXml: sourceXml.slice(node.start, node.end)
1313
+ };
1314
+ }
1315
+ return {
1316
+ type: "paragraph",
1317
+ styleId,
1318
+ ...numbering ? { numbering } : {},
1319
+ ...alignment ? { alignment } : {},
1320
+ ...spacing ? { spacing } : {},
1321
+ ...contextualSpacing !== void 0 ? { contextualSpacing } : {},
1322
+ ...indentation ? { indentation } : {},
1323
+ ...tabStops && tabStops.length > 0 ? { tabStops } : {},
1324
+ ...keepNext ? { keepNext } : {},
1325
+ ...keepLines ? { keepLines } : {},
1326
+ ...outlineLevel !== void 0 ? { outlineLevel } : {},
1327
+ ...pageBreakBefore ? { pageBreakBefore } : {},
1328
+ ...widowControl ? { widowControl } : {},
1329
+ ...borders ? { borders } : {},
1330
+ ...shading ? { shading } : {},
1331
+ ...bidi ? { bidi } : {},
1332
+ ...suppressLineNumbers ? { suppressLineNumbers } : {},
1333
+ ...cnfStyle ? { cnfStyle } : {},
1334
+ ...sectionProperties ? { sectionProperties } : {},
1335
+ ...sectionPropertiesXml ? { sectionPropertiesXml } : {},
1336
+ children,
1337
+ rawXml: sourceXml.slice(node.start, node.end)
1338
+ };
1339
+ }
1340
+ function appendParagraphRunNodes(node, children, activeComplexField, sourceXml, relationships, mediaParts, sourcePartPath) {
1341
+ const hasFieldMarkers = node.children.some(
1342
+ (child) => child.type === "element" && (localName5(child.name) === "fldChar" || localName5(child.name) === "instrText")
1343
+ );
1344
+ if (activeComplexField?.mode === "result" && !hasFieldMarkers) {
1345
+ const run = parseRunContentOnly(node, sourceXml);
1346
+ if (run.supported && run.nodes.every(
1347
+ (child) => child.type === "text" || child.type === "hard_break" || child.type === "tab"
1348
+ )) {
1349
+ activeComplexField.children.push(...run.nodes);
1350
+ return activeComplexField;
1351
+ }
1352
+ }
1353
+ if (!hasFieldMarkers) {
1354
+ children.push(...parseRun(node, sourceXml, relationships, mediaParts, sourcePartPath));
1355
+ return activeComplexField;
1356
+ }
1357
+ for (const child of node.children) {
1358
+ if (child.type !== "element") {
1359
+ continue;
1360
+ }
1361
+ const name = localName5(child.name);
1362
+ if (name === "fldChar") {
1363
+ const fldType = child.attributes["w:fldCharType"] ?? child.attributes.fldCharType;
1364
+ if (fldType === "begin") {
1365
+ activeComplexField = { instruction: "", children: [], mode: "instruction" };
1366
+ } else if (fldType === "separate" && activeComplexField) {
1367
+ activeComplexField.mode = "result";
1368
+ } else if (fldType === "end" && activeComplexField) {
1369
+ flushActiveComplexField(children, () => {
1370
+ activeComplexField = null;
1371
+ }, activeComplexField);
1372
+ }
1373
+ continue;
1374
+ }
1375
+ if (name === "instrText") {
1376
+ const instruction = child.children.filter((entry) => entry.type === "text").map((entry) => entry.text).join("");
1377
+ if (activeComplexField) {
1378
+ activeComplexField.instruction += instruction;
1379
+ } else if (instruction.trim().length > 0) {
1380
+ children.push({
1381
+ type: "field",
1382
+ fieldType: "complex",
1383
+ instruction,
1384
+ children: [],
1385
+ rawXml: sourceXml.slice(node.start, node.end)
1386
+ });
1387
+ }
1388
+ continue;
1389
+ }
1390
+ }
1391
+ return activeComplexField;
1392
+ }
1393
+ function flushActiveComplexField(children, reset, activeComplexField) {
1394
+ if (!activeComplexField || activeComplexField.instruction.trim().length === 0) {
1395
+ return;
1396
+ }
1397
+ children.push({
1398
+ type: "field",
1399
+ fieldType: "complex",
1400
+ instruction: activeComplexField.instruction,
1401
+ children: activeComplexField.children,
1402
+ rawXml: ""
1403
+ });
1404
+ reset();
1405
+ }
1406
+ function parseTableElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath) {
1407
+ let styleId;
1408
+ let tblLook;
1409
+ let propertiesXml;
1410
+ let gridColumns = [];
1411
+ const rows = [];
1412
+ for (const child of node.children) {
1413
+ if (child.type !== "element") continue;
1414
+ switch (localName5(child.name)) {
1415
+ case "tblPr": {
1416
+ propertiesXml = sourceXml.slice(child.start, child.end);
1417
+ styleId = readTableStyleId(child);
1418
+ tblLook = readTableLook(child);
1419
+ break;
1420
+ }
1421
+ case "tblGrid": {
1422
+ gridColumns = readTableGridColumns(child);
1423
+ break;
1424
+ }
1425
+ case "tr": {
1426
+ rows.push(parseTableRowElement(child, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath));
1427
+ break;
1428
+ }
1429
+ }
1430
+ }
1431
+ return {
1432
+ type: "table",
1433
+ ...styleId ? { styleId } : {},
1434
+ ...tblLook ? { tblLook } : {},
1435
+ ...propertiesXml ? { propertiesXml } : {},
1436
+ gridColumns,
1437
+ rows,
1438
+ rawXml: sourceXml.slice(node.start, node.end)
1439
+ };
1440
+ }
1441
+ function parseTableRowElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath) {
1442
+ let propertiesXml;
1443
+ let gridBefore;
1444
+ let widthBefore;
1445
+ let gridAfter;
1446
+ let widthAfter;
1447
+ const cells = [];
1448
+ for (const child of node.children) {
1449
+ if (child.type !== "element") continue;
1450
+ switch (localName5(child.name)) {
1451
+ case "trPr":
1452
+ propertiesXml = sourceXml.slice(child.start, child.end);
1453
+ gridBefore = readTableRowGridPosition(child, "gridBefore");
1454
+ widthBefore = readTableRowWidth(child, "wBefore");
1455
+ gridAfter = readTableRowGridPosition(child, "gridAfter");
1456
+ widthAfter = readTableRowWidth(child, "wAfter");
1457
+ break;
1458
+ case "tc":
1459
+ cells.push(parseTableCellElement(child, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath));
1460
+ break;
1461
+ }
1462
+ }
1463
+ return {
1464
+ type: "table_row",
1465
+ ...propertiesXml ? { propertiesXml } : {},
1466
+ ...gridBefore !== void 0 ? { gridBefore } : {},
1467
+ ...widthBefore ? { widthBefore } : {},
1468
+ ...gridAfter !== void 0 ? { gridAfter } : {},
1469
+ ...widthAfter ? { widthAfter } : {},
1470
+ cells,
1471
+ rawXml: sourceXml.slice(node.start, node.end)
1472
+ };
1473
+ }
1474
+ function parseTableCellElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath) {
1475
+ let propertiesXml;
1476
+ let gridSpan;
1477
+ let verticalMerge;
1478
+ const children = [];
1479
+ for (const child of node.children) {
1480
+ if (child.type !== "element") continue;
1481
+ switch (localName5(child.name)) {
1482
+ case "tcPr": {
1483
+ propertiesXml = sourceXml.slice(child.start, child.end);
1484
+ gridSpan = readCellGridSpan(child);
1485
+ verticalMerge = readCellVerticalMerge(child);
1486
+ break;
1487
+ }
1488
+ default: {
1489
+ children.push(parseBodyChild(child, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath));
1490
+ break;
1491
+ }
1492
+ }
1493
+ }
1494
+ return {
1495
+ type: "table_cell",
1496
+ ...propertiesXml ? { propertiesXml } : {},
1497
+ ...gridSpan ? { gridSpan } : {},
1498
+ ...verticalMerge ? { verticalMerge } : {},
1499
+ children,
1500
+ rawXml: sourceXml.slice(node.start, node.end)
1501
+ };
1502
+ }
1503
+ function parseSdtElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath) {
1504
+ const propertiesNode = node.children.find(
1505
+ (child) => child.type === "element" && localName5(child.name) === "sdtPr"
1506
+ );
1507
+ const contentNode = node.children.find(
1508
+ (child) => child.type === "element" && localName5(child.name) === "sdtContent"
1509
+ );
1510
+ if (!contentNode) {
1511
+ return {
1512
+ type: "opaque_block",
1513
+ rawXml: sourceXml.slice(node.start, node.end)
1514
+ };
1515
+ }
1516
+ const children = contentNode.children.filter((child) => child.type === "element").map((child) => parseBodyChild(child, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath));
1517
+ return {
1518
+ type: "sdt",
1519
+ properties: readSdtProperties(propertiesNode, sourceXml),
1520
+ children,
1521
+ rawXml: sourceXml.slice(node.start, node.end)
1522
+ };
1523
+ }
1524
+ function parseCustomXmlElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath) {
1525
+ const uri = readOptionalAttribute2(node, "uri");
1526
+ const element = readOptionalAttribute2(node, "element");
1527
+ if (!uri && !element) {
1528
+ return {
1529
+ type: "opaque_block",
1530
+ rawXml: sourceXml.slice(node.start, node.end)
1531
+ };
1532
+ }
1533
+ const children = node.children.filter(
1534
+ (child) => child.type === "element" && localName5(child.name) !== "customXmlPr"
1535
+ ).map((child) => parseBodyChild(child, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath));
1536
+ return {
1537
+ type: "custom_xml",
1538
+ ...uri ? { uri } : {},
1539
+ ...element ? { element } : {},
1540
+ children,
1541
+ rawXml: sourceXml.slice(node.start, node.end)
1542
+ };
1543
+ }
1544
+ function parseAltChunkElement(node, sourceXml) {
1545
+ const relationshipId = readOptionalAttribute2(node, "id");
1546
+ if (!relationshipId) {
1547
+ return {
1548
+ type: "opaque_block",
1549
+ rawXml: sourceXml.slice(node.start, node.end)
1550
+ };
1551
+ }
1552
+ return {
1553
+ type: "alt_chunk",
1554
+ relationshipId,
1555
+ rawXml: sourceXml.slice(node.start, node.end)
1556
+ };
1557
+ }
1558
+ function readSdtProperties(node, sourceXml) {
1559
+ if (!node) {
1560
+ return {};
1561
+ }
1562
+ const properties = {
1563
+ propertiesXml: sourceXml.slice(node.start, node.end)
1564
+ };
1565
+ for (const child of node.children) {
1566
+ if (child.type !== "element") {
1567
+ continue;
1568
+ }
1569
+ const name = localName5(child.name);
1570
+ if (name === "alias") {
1571
+ properties.alias = readOptionalAttribute2(child, "val");
1572
+ continue;
1573
+ }
1574
+ if (name === "tag") {
1575
+ properties.tag = readOptionalAttribute2(child, "val");
1576
+ continue;
1577
+ }
1578
+ if (name === "lock") {
1579
+ properties.lock = readOptionalAttribute2(child, "val");
1580
+ continue;
1581
+ }
1582
+ if (name === "showingPlcHdr") {
1583
+ const val = readOptionalAttribute2(child, "val");
1584
+ properties.showingPlcHdr = val !== "false" && val !== "0";
1585
+ continue;
1586
+ }
1587
+ if (name === "checkbox") {
1588
+ properties.sdtType = "checkbox";
1589
+ const checkedNode = findFirstDescendant4(child, "checked");
1590
+ const checkedVal = checkedNode ? readOptionalAttribute2(checkedNode, "val") ?? "0" : "0";
1591
+ const checkedCharNode = findFirstDescendant4(child, "checkedState");
1592
+ const uncheckedCharNode = findFirstDescendant4(child, "uncheckedState");
1593
+ properties.checkbox = {
1594
+ checked: checkedVal === "1" || checkedVal === "true",
1595
+ ...checkedCharNode ? { checkedChar: readOptionalAttribute2(checkedCharNode, "val") } : {},
1596
+ ...uncheckedCharNode ? { uncheckedChar: readOptionalAttribute2(uncheckedCharNode, "val") } : {}
1597
+ };
1598
+ continue;
1599
+ }
1600
+ if (name === "date") {
1601
+ properties.sdtType = "date";
1602
+ const fullDate = readOptionalAttribute2(child, "fullDate");
1603
+ const dateFormatNode = findFirstChild3(child, "dateFormat");
1604
+ const lidNode = findFirstChild3(child, "lid");
1605
+ properties.datePicker = {
1606
+ ...fullDate ? { fullDate } : {},
1607
+ ...dateFormatNode ? { dateFormat: readOptionalAttribute2(dateFormatNode, "val") } : {},
1608
+ ...lidNode ? { lid: readOptionalAttribute2(lidNode, "val") } : {}
1609
+ };
1610
+ continue;
1611
+ }
1612
+ if (name === "dropDownList") {
1613
+ properties.sdtType = "dropDownList";
1614
+ properties.dropdownList = readSdtListItems(child);
1615
+ continue;
1616
+ }
1617
+ if (name === "comboBox") {
1618
+ properties.sdtType = "comboBox";
1619
+ properties.comboBox = readSdtListItems(child);
1620
+ continue;
1621
+ }
1622
+ if (name === "text") {
1623
+ properties.sdtType = "plainText";
1624
+ continue;
1625
+ }
1626
+ if (name === "richText") {
1627
+ properties.sdtType = "richText";
1628
+ continue;
1629
+ }
1630
+ if (!properties.sdtType && name !== "id" && name !== "placeholder" && name !== "showingPlcHdr" && name !== "rPr") {
1631
+ properties.sdtType = name;
1632
+ }
1633
+ }
1634
+ return properties;
1635
+ }
1636
+ function readSdtListItems(node) {
1637
+ const items = [];
1638
+ for (const child of node.children) {
1639
+ if (child.type !== "element" || localName5(child.name) !== "listItem") continue;
1640
+ const value = readOptionalAttribute2(child, "value") ?? "";
1641
+ const displayText = readOptionalAttribute2(child, "displayText");
1642
+ items.push({ value, ...displayText ? { displayText } : {} });
1643
+ }
1644
+ return items;
1645
+ }
1646
+ function findFirstChild3(node, local) {
1647
+ for (const child of node.children) {
1648
+ if (child.type === "element" && localName5(child.name) === local) return child;
1649
+ }
1650
+ return void 0;
1651
+ }
1652
+ function findFirstDescendant4(node, local) {
1653
+ for (const child of node.children) {
1654
+ if (child.type !== "element") continue;
1655
+ if (localName5(child.name) === local) return child;
1656
+ const nested = findFirstDescendant4(child, local);
1657
+ if (nested) return nested;
1658
+ }
1659
+ return void 0;
1660
+ }
1661
+ function readTableStyleId(node) {
1662
+ for (const child of node.children) {
1663
+ if (child.type !== "element" || localName5(child.name) !== "tblStyle") continue;
1664
+ const styleId = child.attributes["w:val"] ?? child.attributes.val;
1665
+ if (styleId) return styleId;
1666
+ }
1667
+ return void 0;
1668
+ }
1669
+ function readTableLook(node) {
1670
+ const tblLookNode = node.children.find(
1671
+ (child) => child.type === "element" && localName5(child.name) === "tblLook"
1672
+ );
1673
+ if (!tblLookNode) {
1674
+ return void 0;
1675
+ }
1676
+ const tableLook = {};
1677
+ const val = tblLookNode.attributes["w:val"] ?? tblLookNode.attributes.val;
1678
+ if (val) {
1679
+ tableLook.val = val;
1680
+ }
1681
+ for (const [attribute, key] of [
1682
+ ["w:firstRow", "firstRow"],
1683
+ ["w:lastRow", "lastRow"],
1684
+ ["w:firstColumn", "firstColumn"],
1685
+ ["w:lastColumn", "lastColumn"],
1686
+ ["w:noHBand", "noHBand"],
1687
+ ["w:noVBand", "noVBand"]
1688
+ ]) {
1689
+ const fallback = attribute.replace("w:", "");
1690
+ const raw = tblLookNode.attributes[attribute] ?? tblLookNode.attributes[fallback];
1691
+ if (raw !== void 0) {
1692
+ tableLook[key] = raw !== "0" && raw !== "false" && raw !== "off";
1693
+ }
1694
+ }
1695
+ return Object.keys(tableLook).length > 0 ? tableLook : void 0;
1696
+ }
1697
+ function readTableGridColumns(node) {
1698
+ return node.children.filter((child) => child.type === "element" && localName5(child.name) === "gridCol").map((child) => {
1699
+ const raw = child.attributes["w:w"] ?? child.attributes.w ?? "0";
1700
+ const value = Number.parseInt(raw, 10);
1701
+ return Number.isFinite(value) && value > 0 ? value : 0;
1702
+ });
1703
+ }
1704
+ function tableRequiresOpaquePreservation(rawXml) {
1705
+ if (/<w:(ins|del|rPrChange|pPrChange|tblPrChange|trPrChange|tcPrChange|sectPrChange|cellIns|cellDel|cellMerge|smartTag|tblCellSpacing)\b/.test(rawXml)) {
1706
+ return true;
1707
+ }
1708
+ const simpleInstructions = [...rawXml.matchAll(/\bw:instr="([^"]*)"/g)].map((match) => match[1] ?? "");
1709
+ const complexInstructions = extractComplexFieldInstructions(rawXml);
1710
+ for (const instruction of [...simpleInstructions, ...complexInstructions]) {
1711
+ const classification = classifyFieldInstruction(instruction);
1712
+ if (!isSafeMainStoryTableFieldFamily(classification.family)) {
1713
+ return true;
1714
+ }
1715
+ }
1716
+ return false;
1717
+ }
1718
+ function isSafeMainStoryTableFieldFamily(family) {
1719
+ return family === "REF" || family === "PAGEREF" || family === "NOTEREF" || family === "TOC" || family === "PAGE" || family === "NUMPAGES";
1720
+ }
1721
+ function extractComplexFieldInstructions(rawXml) {
1722
+ const tokenPattern = /<(?:\w+:)?fldChar\b[^>]*?(?:\w+:)?fldCharType="(begin|separate|end)"[^>]*?(?:\/>|>[\s\S]*?<\/(?:\w+:)?fldChar>)|<(?:\w+:)?instrText\b[^>]*>([\s\S]*?)<\/(?:\w+:)?instrText>/gu;
1723
+ const instructions = [];
1724
+ let activeInstruction = "";
1725
+ let capturingInstruction = false;
1726
+ for (const match of rawXml.matchAll(tokenPattern)) {
1727
+ const fldCharType = match[1];
1728
+ const instrText = match[2];
1729
+ if (fldCharType === "begin") {
1730
+ activeInstruction = "";
1731
+ capturingInstruction = true;
1732
+ continue;
1733
+ }
1734
+ if (fldCharType === "separate" || fldCharType === "end") {
1735
+ if (capturingInstruction && activeInstruction.trim().length > 0) {
1736
+ instructions.push(activeInstruction);
1737
+ }
1738
+ activeInstruction = "";
1739
+ capturingInstruction = false;
1740
+ continue;
1741
+ }
1742
+ if (capturingInstruction && instrText !== void 0) {
1743
+ activeInstruction += decodeXmlEntities3(instrText);
1744
+ }
1745
+ }
1746
+ return instructions;
1747
+ }
1748
+ function readTableRowGridPosition(node, local) {
1749
+ const positionNode = node.children.find(
1750
+ (child) => child.type === "element" && localName5(child.name) === local
1751
+ );
1752
+ if (!positionNode) return void 0;
1753
+ const raw = positionNode.attributes["w:val"] ?? positionNode.attributes.val;
1754
+ const value = Number.parseInt(raw ?? "", 10);
1755
+ return Number.isFinite(value) && value > 0 ? value : 0;
1756
+ }
1757
+ function readTableRowWidth(node, local) {
1758
+ const widthNode = node.children.find(
1759
+ (child) => child.type === "element" && localName5(child.name) === local
1760
+ );
1761
+ if (!widthNode) return void 0;
1762
+ const rawValue = widthNode.attributes["w:w"] ?? widthNode.attributes.w;
1763
+ const value = Number.parseInt(rawValue ?? "", 10);
1764
+ if (!Number.isFinite(value)) {
1765
+ return void 0;
1766
+ }
1767
+ const rawType = (widthNode.attributes["w:type"] ?? widthNode.attributes.type ?? "dxa").toLowerCase();
1768
+ const type = rawType === "auto" ? "auto" : rawType === "pct" ? "pct" : rawType === "nil" ? "nil" : "dxa";
1769
+ return { value, type };
1770
+ }
1771
+ function readCellGridSpan(node) {
1772
+ const gridSpanNode = node.children.find(
1773
+ (child) => child.type === "element" && localName5(child.name) === "gridSpan"
1774
+ );
1775
+ if (!gridSpanNode) return void 0;
1776
+ const raw = gridSpanNode.attributes["w:val"] ?? gridSpanNode.attributes.val;
1777
+ const value = Number.parseInt(raw ?? "0", 10);
1778
+ return Number.isFinite(value) && value > 1 ? value : void 0;
1779
+ }
1780
+ function readCellVerticalMerge(node) {
1781
+ const vMergeNode = node.children.find(
1782
+ (child) => child.type === "element" && localName5(child.name) === "vMerge"
1783
+ );
1784
+ if (!vMergeNode) return void 0;
1785
+ const raw = (vMergeNode.attributes["w:val"] ?? vMergeNode.attributes.val ?? "continue").toLowerCase();
1786
+ return raw === "restart" ? "restart" : "continue";
1787
+ }
1788
+ function readParagraphAlignment(node) {
1789
+ const jcNode = node.children.find(
1790
+ (child) => child.type === "element" && localName5(child.name) === "jc"
1791
+ );
1792
+ if (!jcNode) return void 0;
1793
+ const val = (jcNode.attributes["w:val"] ?? jcNode.attributes.val ?? "").toLowerCase();
1794
+ if (val === "left" || val === "center" || val === "right" || val === "both" || val === "distribute") {
1795
+ return val;
1796
+ }
1797
+ return void 0;
1798
+ }
1799
+ function readParagraphSpacing(node) {
1800
+ const spacingNode = node.children.find(
1801
+ (child) => child.type === "element" && localName5(child.name) === "spacing"
1802
+ );
1803
+ if (!spacingNode) return void 0;
1804
+ const spacing = {};
1805
+ const before = spacingNode.attributes["w:before"] ?? spacingNode.attributes.before;
1806
+ const after = spacingNode.attributes["w:after"] ?? spacingNode.attributes.after;
1807
+ const line = spacingNode.attributes["w:line"] ?? spacingNode.attributes.line;
1808
+ const lineRule = spacingNode.attributes["w:lineRule"] ?? spacingNode.attributes.lineRule;
1809
+ if (before !== void 0) {
1810
+ const v = Number.parseInt(before, 10);
1811
+ if (Number.isFinite(v)) spacing.before = v;
1812
+ }
1813
+ if (after !== void 0) {
1814
+ const v = Number.parseInt(after, 10);
1815
+ if (Number.isFinite(v)) spacing.after = v;
1816
+ }
1817
+ if (line !== void 0) {
1818
+ const v = Number.parseInt(line, 10);
1819
+ if (Number.isFinite(v)) spacing.line = v;
1820
+ }
1821
+ if (lineRule !== void 0) {
1822
+ const lr = lineRule.toLowerCase();
1823
+ if (lr === "auto" || lr === "exact") {
1824
+ spacing.lineRule = lr;
1825
+ } else if (lr === "atleast") {
1826
+ spacing.lineRule = "atLeast";
1827
+ }
1828
+ }
1829
+ if (spacing.before === void 0 && spacing.after === void 0 && spacing.line === void 0 && spacing.lineRule === void 0) {
1830
+ return void 0;
1831
+ }
1832
+ return spacing;
1833
+ }
1834
+ function readParagraphIndentation(node) {
1835
+ const indNode = node.children.find(
1836
+ (child) => child.type === "element" && localName5(child.name) === "ind"
1837
+ );
1838
+ if (!indNode) return void 0;
1839
+ const indentation = {};
1840
+ const left = indNode.attributes["w:left"] ?? indNode.attributes.left;
1841
+ const right = indNode.attributes["w:right"] ?? indNode.attributes.right;
1842
+ const firstLine = indNode.attributes["w:firstLine"] ?? indNode.attributes.firstLine;
1843
+ const hanging = indNode.attributes["w:hanging"] ?? indNode.attributes.hanging;
1844
+ if (left !== void 0) {
1845
+ const v = Number.parseInt(left, 10);
1846
+ if (Number.isFinite(v)) indentation.left = v;
1847
+ }
1848
+ if (right !== void 0) {
1849
+ const v = Number.parseInt(right, 10);
1850
+ if (Number.isFinite(v)) indentation.right = v;
1851
+ }
1852
+ if (firstLine !== void 0) {
1853
+ const v = Number.parseInt(firstLine, 10);
1854
+ if (Number.isFinite(v)) indentation.firstLine = v;
1855
+ }
1856
+ if (hanging !== void 0) {
1857
+ const v = Number.parseInt(hanging, 10);
1858
+ if (Number.isFinite(v)) indentation.hanging = v;
1859
+ }
1860
+ if (indentation.left === void 0 && indentation.right === void 0 && indentation.firstLine === void 0 && indentation.hanging === void 0) {
1861
+ return void 0;
1862
+ }
1863
+ return indentation;
1864
+ }
1865
+ function readParagraphTabStops(node) {
1866
+ const tabsNode = node.children.find(
1867
+ (child) => child.type === "element" && localName5(child.name) === "tabs"
1868
+ );
1869
+ if (!tabsNode) return void 0;
1870
+ const tabStops = [];
1871
+ for (const child of tabsNode.children) {
1872
+ if (child.type !== "element" || localName5(child.name) !== "tab") continue;
1873
+ const pos = child.attributes["w:pos"] ?? child.attributes.pos;
1874
+ const val = (child.attributes["w:val"] ?? child.attributes.val ?? "left").toLowerCase();
1875
+ const leader = (child.attributes["w:leader"] ?? child.attributes.leader ?? "none").toLowerCase();
1876
+ if (pos === void 0) continue;
1877
+ const position = Number.parseInt(pos, 10);
1878
+ if (!Number.isFinite(position)) continue;
1879
+ const align = ["left", "center", "right", "decimal", "bar", "clear"].includes(
1880
+ val
1881
+ ) ? val : "left";
1882
+ const leaderValue = leader === "none" || leader === "dot" || leader === "hyphen" || leader === "underscore" || leader === "heavy" ? leader : leader === "middledot" ? "middleDot" : void 0;
1883
+ tabStops.push({
1884
+ position,
1885
+ align,
1886
+ ...leaderValue && leaderValue !== "none" ? { leader: leaderValue } : {}
1887
+ });
1888
+ }
1889
+ return tabStops.length > 0 ? tabStops : void 0;
1890
+ }
1891
+ function readOnOffParagraphProperty(node, name) {
1892
+ const propNode = node.children.find(
1893
+ (child) => child.type === "element" && localName5(child.name) === name
1894
+ );
1895
+ if (!propNode) return void 0;
1896
+ const val = (propNode.attributes["w:val"] ?? propNode.attributes.val ?? "true").toLowerCase();
1897
+ return val !== "false" && val !== "0" && val !== "off" ? true : void 0;
1898
+ }
1899
+ function readOptionalOnOffParagraphProperty(node, name) {
1900
+ const propNode = node.children.find(
1901
+ (child) => child.type === "element" && localName5(child.name) === name
1902
+ );
1903
+ if (!propNode) return void 0;
1904
+ const val = (propNode.attributes["w:val"] ?? propNode.attributes.val ?? "true").toLowerCase();
1905
+ return val !== "false" && val !== "0" && val !== "off";
1906
+ }
1907
+ function readParagraphOutlineLevel(node) {
1908
+ const propNode = node.children.find(
1909
+ (child) => child.type === "element" && localName5(child.name) === "outlineLvl"
1910
+ );
1911
+ if (!propNode) return void 0;
1912
+ const val = propNode.attributes["w:val"] ?? propNode.attributes.val;
1913
+ if (val === void 0) return void 0;
1914
+ const level = Number.parseInt(val, 10);
1915
+ return Number.isFinite(level) ? level : void 0;
1916
+ }
1917
+ function readParagraphBorders(node) {
1918
+ const borderContainer = node.children.find(
1919
+ (child) => child.type === "element" && localName5(child.name) === "pBdr"
1920
+ );
1921
+ if (!borderContainer) {
1922
+ return void 0;
1923
+ }
1924
+ const borders = {};
1925
+ for (const [name, key] of [
1926
+ ["top", "top"],
1927
+ ["left", "left"],
1928
+ ["bottom", "bottom"],
1929
+ ["right", "right"],
1930
+ ["bar", "bar"],
1931
+ ["between", "between"]
1932
+ ]) {
1933
+ const borderNode = borderContainer.children.find(
1934
+ (child) => child.type === "element" && localName5(child.name) === name
1935
+ );
1936
+ if (borderNode) {
1937
+ const border = readBorder(borderNode);
1938
+ if (border) {
1939
+ borders[key] = border;
1940
+ }
1941
+ }
1942
+ }
1943
+ return Object.keys(borders).length > 0 ? borders : void 0;
1944
+ }
1945
+ function readParagraphShading(node) {
1946
+ const shadingNode = node.children.find(
1947
+ (child) => child.type === "element" && localName5(child.name) === "shd"
1948
+ );
1949
+ if (!shadingNode) {
1950
+ return void 0;
1951
+ }
1952
+ const shading = {};
1953
+ const fill = shadingNode.attributes["w:fill"] ?? shadingNode.attributes.fill;
1954
+ const color = shadingNode.attributes["w:color"] ?? shadingNode.attributes.color;
1955
+ const val = shadingNode.attributes["w:val"] ?? shadingNode.attributes.val;
1956
+ if (fill) shading.fill = fill;
1957
+ if (color) shading.color = color;
1958
+ if (val) shading.val = val;
1959
+ return Object.keys(shading).length > 0 ? shading : void 0;
1960
+ }
1961
+ function readParagraphCnfStyle(node) {
1962
+ const cnfStyleNode = node.children.find(
1963
+ (child) => child.type === "element" && localName5(child.name) === "cnfStyle"
1964
+ );
1965
+ return cnfStyleNode?.attributes["w:val"] ?? cnfStyleNode?.attributes.val;
1966
+ }
1967
+ function readBorder(node) {
1968
+ const border = {};
1969
+ const value = node.attributes["w:val"] ?? node.attributes.val;
1970
+ const size = node.attributes["w:sz"] ?? node.attributes.sz;
1971
+ const space = node.attributes["w:space"] ?? node.attributes.space;
1972
+ const color = node.attributes["w:color"] ?? node.attributes.color;
1973
+ if (value) border.value = value;
1974
+ if (size !== void 0) {
1975
+ const parsedSize = Number.parseInt(size, 10);
1976
+ if (Number.isFinite(parsedSize)) border.size = parsedSize;
1977
+ }
1978
+ if (space !== void 0) {
1979
+ const parsedSpace = Number.parseInt(space, 10);
1980
+ if (Number.isFinite(parsedSpace)) border.space = parsedSpace;
1981
+ }
1982
+ if (color) border.color = color;
1983
+ return Object.keys(border).length > 0 ? border : void 0;
1984
+ }
1985
+ function readParagraphStyleId(node) {
1986
+ for (const child of node.children) {
1987
+ if (child.type !== "element" || localName5(child.name) !== "pStyle") {
1988
+ continue;
1989
+ }
1990
+ const styleId = child.attributes["w:val"] ?? child.attributes.val;
1991
+ if (styleId) {
1992
+ return styleId;
1993
+ }
1994
+ }
1995
+ return void 0;
1996
+ }
1997
+ function readParagraphNumbering(node) {
1998
+ const numberingProperties = node.children.find(
1999
+ (child) => child.type === "element" && localName5(child.name) === "numPr"
2000
+ );
2001
+ if (!numberingProperties) {
2002
+ return void 0;
2003
+ }
2004
+ const levelNode = numberingProperties.children.find(
2005
+ (child) => child.type === "element" && localName5(child.name) === "ilvl"
2006
+ );
2007
+ const instanceNode = numberingProperties.children.find(
2008
+ (child) => child.type === "element" && localName5(child.name) === "numId"
2009
+ );
2010
+ const rawLevel = levelNode?.attributes["w:val"] ?? levelNode?.attributes.val;
2011
+ const rawInstanceId = instanceNode?.attributes["w:val"] ?? instanceNode?.attributes.val;
2012
+ if (!rawInstanceId || rawLevel === void 0 || !/^-?\d+$/.test(rawLevel)) {
2013
+ return void 0;
2014
+ }
2015
+ return {
2016
+ numberingInstanceId: toCanonicalNumberingInstanceId(rawInstanceId),
2017
+ level: Number.parseInt(rawLevel, 10)
2018
+ };
2019
+ }
2020
+ function parseRun(node, sourceXml, relationships, mediaParts, sourcePartPath) {
2021
+ const marksResult = readRunMarks(node, sourceXml);
2022
+ if (!marksResult.supported) {
2023
+ return [
2024
+ {
2025
+ type: "opaque_inline",
2026
+ rawXml: sourceXml.slice(node.start, node.end)
2027
+ }
2028
+ ];
2029
+ }
2030
+ const marks = marksResult.marks;
2031
+ const result = [];
2032
+ let encounteredUnsupportedChild = false;
2033
+ for (const child of node.children) {
2034
+ if (child.type !== "element") {
2035
+ continue;
2036
+ }
2037
+ switch (localName5(child.name)) {
2038
+ case "rPr":
2039
+ break;
2040
+ case "t": {
2041
+ const text = child.children.filter((entry) => entry.type === "text").map((entry) => entry.text).join("");
2042
+ result.push({
2043
+ type: "text",
2044
+ text,
2045
+ ...marks.length > 0 ? { marks } : {}
2046
+ });
2047
+ break;
2048
+ }
2049
+ case "tab":
2050
+ result.push({ type: "tab" });
2051
+ break;
2052
+ case "sym": {
2053
+ const symbol = parseSymbolNode(child, marks);
2054
+ if (!symbol) {
2055
+ encounteredUnsupportedChild = true;
2056
+ result.push({
2057
+ type: "opaque_inline",
2058
+ rawXml: sourceXml.slice(child.start, child.end)
2059
+ });
2060
+ break;
2061
+ }
2062
+ result.push(symbol);
2063
+ break;
2064
+ }
2065
+ case "br":
2066
+ if (isColumnBreak(child)) {
2067
+ result.push({ type: "column_break" });
2068
+ } else if (isSimpleLineBreak(child)) {
2069
+ result.push({ type: "hard_break" });
2070
+ } else {
2071
+ result.push({
2072
+ type: "opaque_inline",
2073
+ rawXml: sourceXml.slice(child.start, child.end)
2074
+ });
2075
+ }
2076
+ break;
2077
+ case "drawing": {
2078
+ const drawingXml = sourceXml.slice(child.start, child.end);
2079
+ try {
2080
+ const complexContent = parseComplexContentXml(
2081
+ drawingXml,
2082
+ relationships,
2083
+ mediaParts,
2084
+ sourcePartPath
2085
+ );
2086
+ if (complexContent) {
2087
+ result.push(complexContent);
2088
+ break;
2089
+ }
2090
+ } catch {
2091
+ }
2092
+ try {
2093
+ const shapeResult = parseShapeXml(drawingXml);
2094
+ if (shapeResult) {
2095
+ result.push(shapeResult);
2096
+ break;
2097
+ }
2098
+ } catch {
2099
+ }
2100
+ const parsedMedia = parseInlineMediaXml(
2101
+ drawingXml,
2102
+ relationships,
2103
+ mediaParts,
2104
+ sourcePartPath
2105
+ );
2106
+ if (parsedMedia.length === 0) {
2107
+ encounteredUnsupportedChild = true;
2108
+ result.push({
2109
+ type: "opaque_inline",
2110
+ rawXml: sourceXml.slice(node.start, node.end)
2111
+ });
2112
+ break;
2113
+ }
2114
+ const semanticChildren = node.children.filter(
2115
+ (entry) => entry.type === "element" && localName5(entry.name) !== "rPr"
2116
+ );
2117
+ const placementXml = semanticChildren.length === 1 ? sourceXml.slice(node.start, node.end) : sourceXml.slice(child.start, child.end);
2118
+ result.push(
2119
+ ...parsedMedia.map((media) => ({
2120
+ type: "image",
2121
+ mediaId: media.mediaId,
2122
+ relationshipId: media.relationshipId,
2123
+ packagePartName: media.packagePartName,
2124
+ contentType: media.contentType,
2125
+ filename: media.filename,
2126
+ ...media.altText ? { altText: media.altText } : {},
2127
+ ...media.widthEmu !== void 0 ? { widthEmu: media.widthEmu } : {},
2128
+ ...media.heightEmu !== void 0 ? { heightEmu: media.heightEmu } : {},
2129
+ placementXml,
2130
+ ...media.display ? { display: media.display } : {},
2131
+ ...media.floating ? { floating: media.floating } : {}
2132
+ }))
2133
+ );
2134
+ break;
2135
+ }
2136
+ case "pict": {
2137
+ const pictXml = sourceXml.slice(child.start, child.end);
2138
+ try {
2139
+ const vmlResult = parseVmlXml(pictXml);
2140
+ if (vmlResult) {
2141
+ result.push({
2142
+ ...vmlResult,
2143
+ rawXml: sourceXml.slice(node.start, node.end)
2144
+ });
2145
+ break;
2146
+ }
2147
+ } catch {
2148
+ }
2149
+ encounteredUnsupportedChild = true;
2150
+ result.push({
2151
+ type: "opaque_inline",
2152
+ rawXml: pictXml
2153
+ });
2154
+ break;
2155
+ }
2156
+ case "commentReference":
2157
+ break;
2158
+ case "footnoteReference": {
2159
+ const noteId = child.attributes["w:id"] ?? child.attributes.id ?? "";
2160
+ if (noteId) {
2161
+ result.push({
2162
+ type: "footnote_ref",
2163
+ noteId,
2164
+ noteKind: "footnote"
2165
+ });
2166
+ }
2167
+ break;
2168
+ }
2169
+ case "endnoteReference": {
2170
+ const noteId = child.attributes["w:id"] ?? child.attributes.id ?? "";
2171
+ if (noteId) {
2172
+ result.push({
2173
+ type: "footnote_ref",
2174
+ noteId,
2175
+ noteKind: "endnote"
2176
+ });
2177
+ }
2178
+ break;
2179
+ }
2180
+ case "lastRenderedPageBreak":
2181
+ case "proofErr":
2182
+ result.push({
2183
+ type: "opaque_inline",
2184
+ rawXml: sourceXml.slice(child.start, child.end)
2185
+ });
2186
+ break;
2187
+ default:
2188
+ encounteredUnsupportedChild = true;
2189
+ result.push({
2190
+ type: "opaque_inline",
2191
+ rawXml: sourceXml.slice(child.start, child.end)
2192
+ });
2193
+ break;
2194
+ }
2195
+ }
2196
+ if (encounteredUnsupportedChild && result.every((child) => child.type === "opaque_inline")) {
2197
+ return [
2198
+ {
2199
+ type: "opaque_inline",
2200
+ rawXml: sourceXml.slice(node.start, node.end)
2201
+ }
2202
+ ];
2203
+ }
2204
+ return result;
2205
+ }
2206
+ function parseRevisionContainer(node, sourceXml, relationshipMap) {
2207
+ const result = [];
2208
+ const allowsDeletedText = localName5(node.name) === "del";
2209
+ for (const child of node.children) {
2210
+ if (child.type !== "element") {
2211
+ continue;
2212
+ }
2213
+ switch (localName5(child.name)) {
2214
+ case "r": {
2215
+ const run = parseRunContentOnly(child, sourceXml, {
2216
+ allowDeletedText: allowsDeletedText,
2217
+ preserveUnsupportedReviewMarkup: true
2218
+ });
2219
+ if (!run.supported) {
2220
+ return [
2221
+ {
2222
+ type: "opaque_inline",
2223
+ rawXml: sourceXml.slice(node.start, node.end)
2224
+ }
2225
+ ];
2226
+ }
2227
+ result.push(...run.nodes);
2228
+ break;
2229
+ }
2230
+ case "hyperlink": {
2231
+ const hyperlink = parseHyperlink(child, sourceXml, relationshipMap, {
2232
+ allowDeletedText: allowsDeletedText,
2233
+ preserveUnsupportedReviewMarkup: true
2234
+ });
2235
+ if (hyperlink.type === "opaque_inline") {
2236
+ return [
2237
+ {
2238
+ type: "opaque_inline",
2239
+ rawXml: sourceXml.slice(node.start, node.end)
2240
+ }
2241
+ ];
2242
+ }
2243
+ result.push(hyperlink);
2244
+ break;
2245
+ }
2246
+ case "commentRangeStart":
2247
+ case "commentRangeEnd":
2248
+ case "bookmarkStart":
2249
+ case "bookmarkEnd":
2250
+ case "proofErr":
2251
+ case "lastRenderedPageBreak":
2252
+ return [
2253
+ {
2254
+ type: "opaque_inline",
2255
+ rawXml: sourceXml.slice(node.start, node.end)
2256
+ }
2257
+ ];
2258
+ case "permStart":
2259
+ result.push(parsePermStartNode(child, sourceXml));
2260
+ break;
2261
+ case "permEnd":
2262
+ result.push(parsePermEndNode(child, sourceXml));
2263
+ break;
2264
+ default:
2265
+ return [
2266
+ {
2267
+ type: "opaque_inline",
2268
+ rawXml: sourceXml.slice(node.start, node.end)
2269
+ }
2270
+ ];
2271
+ }
2272
+ }
2273
+ return result;
2274
+ }
2275
+ function parseHyperlink(node, sourceXml, relationshipMap, options = {}) {
2276
+ const relationshipId = node.attributes["r:id"] ?? node.attributes.id;
2277
+ const anchor = node.attributes["w:anchor"] ?? node.attributes.anchor;
2278
+ let href;
2279
+ if (relationshipId) {
2280
+ const relationship = relationshipMap.get(relationshipId);
2281
+ if (relationship && relationship.type === HYPERLINK_RELATIONSHIP_TYPE && relationship.targetMode === "external") {
2282
+ href = relationship.target;
2283
+ }
2284
+ } else if (anchor) {
2285
+ href = `#${anchor}`;
2286
+ }
2287
+ if (!href) {
2288
+ return {
2289
+ type: "opaque_inline",
2290
+ rawXml: sourceXml.slice(node.start, node.end)
2291
+ };
2292
+ }
2293
+ const children = [];
2294
+ for (const child of node.children) {
2295
+ if (child.type !== "element") {
2296
+ continue;
2297
+ }
2298
+ if (localName5(child.name) !== "r") {
2299
+ return {
2300
+ type: "opaque_inline",
2301
+ rawXml: sourceXml.slice(node.start, node.end)
2302
+ };
2303
+ }
2304
+ const run = parseRunContentOnly(child, sourceXml, {
2305
+ allowDeletedText: options.allowDeletedText,
2306
+ preserveUnsupportedReviewMarkup: options.preserveUnsupportedReviewMarkup
2307
+ });
2308
+ if (!run.supported) {
2309
+ return {
2310
+ type: "opaque_inline",
2311
+ rawXml: sourceXml.slice(node.start, node.end)
2312
+ };
2313
+ }
2314
+ children.push(...run.nodes);
2315
+ }
2316
+ return {
2317
+ type: "hyperlink",
2318
+ href,
2319
+ children,
2320
+ rawXml: sourceXml.slice(node.start, node.end)
2321
+ };
2322
+ }
2323
+ function parseRunContentOnly(node, _sourceXml, options = {}) {
2324
+ const marksResult = readRunMarks(node, _sourceXml);
2325
+ if (!marksResult.supported) {
2326
+ return { nodes: [], supported: false };
2327
+ }
2328
+ const marks = marksResult.marks;
2329
+ const nodes = [];
2330
+ for (const child of node.children) {
2331
+ if (child.type !== "element") {
2332
+ continue;
2333
+ }
2334
+ switch (localName5(child.name)) {
2335
+ case "rPr":
2336
+ break;
2337
+ case "t": {
2338
+ const text = child.children.filter((entry) => entry.type === "text").map((entry) => entry.text).join("");
2339
+ nodes.push({
2340
+ type: "text",
2341
+ text,
2342
+ ...marks.length > 0 ? { marks } : {}
2343
+ });
2344
+ break;
2345
+ }
2346
+ case "delText":
2347
+ case "delInstrText":
2348
+ if (!options.allowDeletedText) {
2349
+ return { nodes: [], supported: false };
2350
+ }
2351
+ nodes.push({
2352
+ type: "text",
2353
+ text: child.children.filter((entry) => entry.type === "text").map((entry) => entry.text).join(""),
2354
+ ...marks.length > 0 ? { marks } : {}
2355
+ });
2356
+ break;
2357
+ case "tab":
2358
+ nodes.push({ type: "tab" });
2359
+ break;
2360
+ case "sym": {
2361
+ const symbol = parseSymbolNode(child, marks);
2362
+ if (!symbol) {
2363
+ return { nodes: [], supported: false };
2364
+ }
2365
+ nodes.push(symbol);
2366
+ break;
2367
+ }
2368
+ case "br":
2369
+ if (isColumnBreak(child)) {
2370
+ nodes.push({ type: "column_break" });
2371
+ break;
2372
+ }
2373
+ if (!isSimpleLineBreak(child)) {
2374
+ return { nodes: [], supported: false };
2375
+ }
2376
+ nodes.push({ type: "hard_break" });
2377
+ break;
2378
+ case "commentReference":
2379
+ case "lastRenderedPageBreak":
2380
+ case "proofErr":
2381
+ if (options.preserveUnsupportedReviewMarkup) {
2382
+ return { nodes: [], supported: false };
2383
+ }
2384
+ break;
2385
+ default:
2386
+ return { nodes: [], supported: false };
2387
+ }
2388
+ }
2389
+ return { nodes, supported: true };
2390
+ }
2391
+ function readRunMarks(node, sourceXml) {
2392
+ const properties = node.children.find(
2393
+ (child) => child.type === "element" && localName5(child.name) === "rPr"
2394
+ );
2395
+ if (!properties) {
2396
+ return { marks: [], supported: true };
2397
+ }
2398
+ if (properties.children.some(
2399
+ (child) => child.type === "element" && DISALLOWED_RUN_PROPERTY_NAMES.has(localName5(child.name))
2400
+ )) {
2401
+ return {
2402
+ marks: [],
2403
+ supported: false
2404
+ };
2405
+ }
2406
+ const marks = [];
2407
+ if (hasOnOffProperty(properties, "b")) {
2408
+ marks.push({ type: "bold" });
2409
+ }
2410
+ if (hasOnOffProperty(properties, "i")) {
2411
+ marks.push({ type: "italic" });
2412
+ }
2413
+ if (hasUnderlineProperty(properties)) {
2414
+ marks.push({ type: "underline" });
2415
+ }
2416
+ if (hasOnOffProperty(properties, "strike")) {
2417
+ marks.push({ type: "strikethrough" });
2418
+ }
2419
+ if (hasOnOffProperty(properties, "dstrike")) {
2420
+ marks.push({ type: "doubleStrikethrough" });
2421
+ }
2422
+ if (hasOnOffProperty(properties, "vanish")) {
2423
+ marks.push({ type: "vanish" });
2424
+ }
2425
+ const langMark = readRunLang(properties);
2426
+ if (langMark) {
2427
+ marks.push(langMark);
2428
+ }
2429
+ const backgroundColorMark = readRunBackgroundColor(properties);
2430
+ if (backgroundColorMark) {
2431
+ marks.push(backgroundColorMark);
2432
+ }
2433
+ const highlightMark = readRunHighlight(properties);
2434
+ if (highlightMark) {
2435
+ marks.push(highlightMark);
2436
+ }
2437
+ const charSpacingMark = readNumericRunMark(properties, "spacing", "charSpacing");
2438
+ if (charSpacingMark) {
2439
+ marks.push(charSpacingMark);
2440
+ }
2441
+ const kerningMark = readNumericRunMark(properties, "kern", "kerning");
2442
+ if (kerningMark) {
2443
+ marks.push(kerningMark);
2444
+ }
2445
+ const positionMark = readNumericRunMark(properties, "position", "position");
2446
+ if (positionMark) {
2447
+ marks.push(positionMark);
2448
+ }
2449
+ if (hasOnOffProperty(properties, "emboss")) {
2450
+ marks.push({ type: "emboss" });
2451
+ }
2452
+ if (hasOnOffProperty(properties, "imprint")) {
2453
+ marks.push({ type: "imprint" });
2454
+ }
2455
+ if (hasOnOffProperty(properties, "shadow")) {
2456
+ marks.push({ type: "shadow" });
2457
+ }
2458
+ const textFillMark = readRunTextFill(properties, sourceXml);
2459
+ if (textFillMark) {
2460
+ marks.push(textFillMark);
2461
+ }
2462
+ const rFontsNode = properties.children.find(
2463
+ (child) => child.type === "element" && localName5(child.name) === "rFonts"
2464
+ );
2465
+ if (rFontsNode) {
2466
+ const family = rFontsNode.attributes["w:ascii"] ?? rFontsNode.attributes["w:hAnsi"] ?? rFontsNode.attributes.ascii ?? rFontsNode.attributes.hAnsi;
2467
+ if (family) {
2468
+ marks.push({ type: "fontFamily", val: family });
2469
+ }
2470
+ }
2471
+ const szNode = properties.children.find(
2472
+ (child) => child.type === "element" && localName5(child.name) === "sz"
2473
+ );
2474
+ if (szNode) {
2475
+ const szVal = szNode.attributes["w:val"] ?? szNode.attributes.val;
2476
+ if (szVal) {
2477
+ const size = Number.parseInt(szVal, 10);
2478
+ if (Number.isFinite(size) && size > 0) {
2479
+ marks.push({ type: "fontSize", val: size });
2480
+ }
2481
+ }
2482
+ }
2483
+ const colorNode = properties.children.find(
2484
+ (child) => child.type === "element" && localName5(child.name) === "color"
2485
+ );
2486
+ if (colorNode) {
2487
+ const colorVal = colorNode.attributes["w:val"] ?? colorNode.attributes.val;
2488
+ if (colorVal && colorVal !== "auto") {
2489
+ marks.push({ type: "textColor", color: colorVal });
2490
+ }
2491
+ }
2492
+ if (hasOnOffProperty(properties, "smallCaps")) {
2493
+ marks.push({ type: "smallCaps" });
2494
+ }
2495
+ if (hasOnOffProperty(properties, "caps")) {
2496
+ marks.push({ type: "allCaps" });
2497
+ }
2498
+ return {
2499
+ marks,
2500
+ supported: true
2501
+ };
2502
+ }
2503
+ function readRunLang(properties) {
2504
+ const langNode = properties.children.find(
2505
+ (child) => child.type === "element" && localName5(child.name) === "lang"
2506
+ );
2507
+ if (!langNode) return void 0;
2508
+ const val = langNode.attributes["w:val"] ?? langNode.attributes.val ?? langNode.attributes["w:bidi"] ?? langNode.attributes.bidi;
2509
+ if (!val) return void 0;
2510
+ return { type: "lang", val };
2511
+ }
2512
+ function readRunBackgroundColor(properties) {
2513
+ const shadingNode = properties.children.find(
2514
+ (child) => child.type === "element" && localName5(child.name) === "shd"
2515
+ );
2516
+ if (!shadingNode) {
2517
+ return void 0;
2518
+ }
2519
+ const fill = shadingNode.attributes["w:fill"] ?? shadingNode.attributes.fill;
2520
+ if (!fill || fill === "auto") {
2521
+ return void 0;
2522
+ }
2523
+ return { type: "backgroundColor", color: fill };
2524
+ }
2525
+ function readRunHighlight(properties) {
2526
+ const highlightNode = properties.children.find(
2527
+ (child) => child.type === "element" && localName5(child.name) === "highlight"
2528
+ );
2529
+ if (!highlightNode) {
2530
+ return void 0;
2531
+ }
2532
+ const highlightValue = highlightNode.attributes["w:val"] ?? highlightNode.attributes.val;
2533
+ const resolvedHighlight = resolveHighlightColor(highlightValue);
2534
+ if (!resolvedHighlight) {
2535
+ return void 0;
2536
+ }
2537
+ return {
2538
+ type: "highlight",
2539
+ color: resolvedHighlight.color,
2540
+ val: resolvedHighlight.val
2541
+ };
2542
+ }
2543
+ function readNumericRunMark(properties, elementName, markType) {
2544
+ const propertyNode = properties.children.find(
2545
+ (child) => child.type === "element" && localName5(child.name) === elementName
2546
+ );
2547
+ if (!propertyNode) {
2548
+ return void 0;
2549
+ }
2550
+ const rawValue = propertyNode.attributes["w:val"] ?? propertyNode.attributes.val;
2551
+ if (rawValue === void 0) {
2552
+ return void 0;
2553
+ }
2554
+ const value = Number.parseInt(rawValue, 10);
2555
+ if (!Number.isFinite(value)) {
2556
+ return void 0;
2557
+ }
2558
+ return { type: markType, val: value };
2559
+ }
2560
+ function readRunTextFill(properties, sourceXml) {
2561
+ const textFillNode = properties.children.find(
2562
+ (child) => child.type === "element" && localName5(child.name) === "textFill"
2563
+ );
2564
+ if (!textFillNode) {
2565
+ return void 0;
2566
+ }
2567
+ return {
2568
+ type: "textFill",
2569
+ xml: sourceXml.slice(textFillNode.start, textFillNode.end)
2570
+ };
2571
+ }
2572
+ function parseSymbolNode(node, marks) {
2573
+ const char = node.attributes["w:char"] ?? node.attributes.char;
2574
+ if (!char) {
2575
+ return void 0;
2576
+ }
2577
+ const font = node.attributes["w:font"] ?? node.attributes.font;
2578
+ return {
2579
+ type: "symbol",
2580
+ char,
2581
+ ...font ? { font } : {},
2582
+ ...marks.length > 0 ? { marks } : {}
2583
+ };
2584
+ }
2585
+ function supportsParagraphProperties(node) {
2586
+ for (const child of node.children) {
2587
+ if (child.type !== "element") {
2588
+ continue;
2589
+ }
2590
+ const name = localName5(child.name);
2591
+ if (name === "pPrChange") {
2592
+ return false;
2593
+ }
2594
+ if (name === "rPr") {
2595
+ if (child.children.some(
2596
+ (entry) => entry.type === "element" && DISALLOWED_PARAGRAPH_PROPERTY_NAMES.has(localName5(entry.name))
2597
+ )) {
2598
+ return false;
2599
+ }
2600
+ }
2601
+ }
2602
+ return true;
2603
+ }
2604
+ var DISALLOWED_RUN_PROPERTY_NAMES = /* @__PURE__ */ new Set(["rPrChange"]);
2605
+ var DISALLOWED_PARAGRAPH_PROPERTY_NAMES = /* @__PURE__ */ new Set(["pPrChange", "rPrChange"]);
2606
+ function hasOnOffProperty(properties, propertyName) {
2607
+ const property = properties.children.find(
2608
+ (child) => child.type === "element" && localName5(child.name) === propertyName
2609
+ );
2610
+ if (!property) {
2611
+ return false;
2612
+ }
2613
+ const value = (property.attributes["w:val"] ?? property.attributes.val ?? "true").toLowerCase();
2614
+ return value !== "false" && value !== "0" && value !== "off";
2615
+ }
2616
+ function hasUnderlineProperty(properties) {
2617
+ const property = properties.children.find(
2618
+ (child) => child.type === "element" && localName5(child.name) === "u"
2619
+ );
2620
+ if (!property) {
2621
+ return false;
2622
+ }
2623
+ const value = (property.attributes["w:val"] ?? property.attributes.val ?? "single").toLowerCase();
2624
+ return value !== "none";
2625
+ }
2626
+ function isSimpleLineBreak(node) {
2627
+ const value = (node.attributes["w:type"] ?? node.attributes.type ?? "textWrapping").toLowerCase();
2628
+ return value === "textwrapping" || value === "line";
2629
+ }
2630
+ function isColumnBreak(node) {
2631
+ const value = (node.attributes["w:type"] ?? node.attributes.type ?? "").toLowerCase();
2632
+ return value === "column";
2633
+ }
2634
+ function findChildElement2(node, childLocalName) {
2635
+ const child = node.children.find(
2636
+ (entry) => entry.type === "element" && localName5(entry.name) === childLocalName
2637
+ );
2638
+ if (!child) {
2639
+ throw new Error(`Expected <${childLocalName}> element in main document XML.`);
2640
+ }
2641
+ return child;
2642
+ }
2643
+ function localName5(name) {
2644
+ const separatorIndex = name.indexOf(":");
2645
+ return separatorIndex >= 0 ? name.slice(separatorIndex + 1) : name;
2646
+ }
2647
+ function readOptionalAttribute2(node, name) {
2648
+ return node.attributes[`w:${name}`] ?? node.attributes[`r:${name}`] ?? node.attributes[name];
2649
+ }
2650
+ function parseXml5(xml) {
2651
+ const root = {
2652
+ type: "element",
2653
+ name: "__root__",
2654
+ attributes: {},
2655
+ children: [],
2656
+ start: 0,
2657
+ end: xml.length
2658
+ };
2659
+ const stack = [root];
2660
+ let cursor = 0;
2661
+ while (cursor < xml.length) {
2662
+ if (xml.startsWith("<!--", cursor)) {
2663
+ const end = xml.indexOf("-->", cursor);
2664
+ cursor = end >= 0 ? end + 3 : xml.length;
2665
+ continue;
2666
+ }
2667
+ if (xml.startsWith("<?", cursor)) {
2668
+ const end = xml.indexOf("?>", cursor);
2669
+ cursor = end >= 0 ? end + 2 : xml.length;
2670
+ continue;
2671
+ }
2672
+ if (xml.startsWith("<![CDATA[", cursor)) {
2673
+ const end = xml.indexOf("]]>", cursor);
2674
+ const textEnd = end >= 0 ? end : xml.length;
2675
+ stack[stack.length - 1]?.children.push({
2676
+ type: "text",
2677
+ text: xml.slice(cursor + 9, textEnd),
2678
+ start: cursor,
2679
+ end: end >= 0 ? end + 3 : xml.length
2680
+ });
2681
+ cursor = end >= 0 ? end + 3 : xml.length;
2682
+ continue;
2683
+ }
2684
+ const currentChar = xml[cursor];
2685
+ if (currentChar !== "<") {
2686
+ const nextTag = xml.indexOf("<", cursor);
2687
+ const end = nextTag >= 0 ? nextTag : xml.length;
2688
+ const text = decodeXmlEntities3(xml.slice(cursor, end));
2689
+ if (text.length > 0) {
2690
+ stack[stack.length - 1]?.children.push({
2691
+ type: "text",
2692
+ text,
2693
+ start: cursor,
2694
+ end
2695
+ });
2696
+ }
2697
+ cursor = end;
2698
+ continue;
2699
+ }
2700
+ if (xml[cursor + 1] === "/") {
2701
+ const end = xml.indexOf(">", cursor);
2702
+ if (end < 0) {
2703
+ throw new Error("Malformed XML: missing closing >.");
2704
+ }
2705
+ const name2 = xml.slice(cursor + 2, end).trim();
2706
+ const current = stack.pop();
2707
+ if (!current || localName5(current.name) !== localName5(name2)) {
2708
+ throw new Error(`Malformed XML: unexpected closing tag </${name2}>.`);
2709
+ }
2710
+ current.end = end + 1;
2711
+ cursor = end + 1;
2712
+ continue;
2713
+ }
2714
+ const tagEnd = findTagEnd5(xml, cursor);
2715
+ const tagBody = xml.slice(cursor + 1, tagEnd);
2716
+ const selfClosing = /\/\s*$/.test(tagBody);
2717
+ const { name, attributes } = parseTag5(tagBody.replace(/\/\s*$/, "").trim());
2718
+ const element = {
2719
+ type: "element",
2720
+ name,
2721
+ attributes,
2722
+ children: [],
2723
+ start: cursor,
2724
+ end: tagEnd + 1
2725
+ };
2726
+ stack[stack.length - 1]?.children.push(element);
2727
+ if (!selfClosing) {
2728
+ stack.push(element);
2729
+ }
2730
+ cursor = tagEnd + 1;
2731
+ }
2732
+ if (stack.length !== 1) {
2733
+ throw new Error("Malformed XML: unclosed element in main document XML.");
2734
+ }
2735
+ return root;
2736
+ }
2737
+ function parseTag5(tagBody) {
2738
+ let cursor = 0;
2739
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
2740
+ cursor += 1;
2741
+ }
2742
+ const nameStart = cursor;
2743
+ while (cursor < tagBody.length && !/\s/.test(tagBody[cursor] ?? "")) {
2744
+ cursor += 1;
2745
+ }
2746
+ const name = tagBody.slice(nameStart, cursor);
2747
+ const attributes = {};
2748
+ while (cursor < tagBody.length) {
2749
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
2750
+ cursor += 1;
2751
+ }
2752
+ if (cursor >= tagBody.length) {
2753
+ break;
2754
+ }
2755
+ const keyStart = cursor;
2756
+ while (cursor < tagBody.length && !/[\s=]/.test(tagBody[cursor] ?? "")) {
2757
+ cursor += 1;
2758
+ }
2759
+ const key = tagBody.slice(keyStart, cursor);
2760
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
2761
+ cursor += 1;
2762
+ }
2763
+ if (tagBody[cursor] !== "=") {
2764
+ attributes[key] = "";
2765
+ continue;
2766
+ }
2767
+ cursor += 1;
2768
+ while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
2769
+ cursor += 1;
2770
+ }
2771
+ const quote = tagBody[cursor];
2772
+ if (quote !== `"` && quote !== `'`) {
2773
+ throw new Error(`Malformed XML attribute ${key}.`);
2774
+ }
2775
+ cursor += 1;
2776
+ const valueStart = cursor;
2777
+ while (cursor < tagBody.length && tagBody[cursor] !== quote) {
2778
+ cursor += 1;
2779
+ }
2780
+ const rawValue = tagBody.slice(valueStart, cursor);
2781
+ attributes[key] = decodeXmlEntities3(rawValue);
2782
+ cursor += 1;
2783
+ }
2784
+ return { name, attributes };
2785
+ }
2786
+ function findTagEnd5(xml, start) {
2787
+ let cursor = start + 1;
2788
+ let quote = null;
2789
+ while (cursor < xml.length) {
2790
+ const current = xml[cursor];
2791
+ if (quote) {
2792
+ if (current === quote) {
2793
+ quote = null;
2794
+ }
2795
+ cursor += 1;
2796
+ continue;
2797
+ }
2798
+ if (current === `"` || current === `'`) {
2799
+ quote = current;
2800
+ cursor += 1;
2801
+ continue;
2802
+ }
2803
+ if (current === ">") {
2804
+ return cursor;
2805
+ }
2806
+ cursor += 1;
2807
+ }
2808
+ throw new Error("Malformed XML: missing >.");
2809
+ }
2810
+ function decodeXmlEntities3(value) {
2811
+ return value.replace(/&(#x[0-9a-fA-F]+|#\d+|amp|lt|gt|quot|apos);/g, (match, entity) => {
2812
+ switch (entity) {
2813
+ case "amp":
2814
+ return "&";
2815
+ case "lt":
2816
+ return "<";
2817
+ case "gt":
2818
+ return ">";
2819
+ case "quot":
2820
+ return `"`;
2821
+ case "apos":
2822
+ return "'";
2823
+ default:
2824
+ if (entity.startsWith("#x")) {
2825
+ return String.fromCodePoint(Number.parseInt(entity.slice(2), 16));
2826
+ }
2827
+ if (entity.startsWith("#")) {
2828
+ return String.fromCodePoint(Number.parseInt(entity.slice(1), 10));
2829
+ }
2830
+ return match;
2831
+ }
2832
+ });
2833
+ }
2834
+ function parseSectionBreakElement(node, sourceXml) {
2835
+ const props = parseSectionPropertiesFromElement(node);
2836
+ return {
2837
+ type: "section_break",
2838
+ sectionPropertiesXml: sourceXml.slice(node.start, node.end),
2839
+ sectionProperties: props
2840
+ };
2841
+ }
2842
+ function readSectionPropertiesFromPPr(pPrNode) {
2843
+ for (const child of pPrNode.children) {
2844
+ if (child.type === "element" && localName5(child.name) === "sectPr") {
2845
+ return parseSectionPropertiesFromElement(child);
2846
+ }
2847
+ }
2848
+ return void 0;
2849
+ }
2850
+ function readSectionPropertiesXmlFromPPr(pPrNode, sourceXml) {
2851
+ for (const child of pPrNode.children) {
2852
+ if (child.type === "element" && localName5(child.name) === "sectPr") {
2853
+ return sourceXml.slice(child.start, child.end);
2854
+ }
2855
+ }
2856
+ return void 0;
2857
+ }
2858
+ function parseSectionPropertiesFromElement(node) {
2859
+ const props = {};
2860
+ for (const child of node.children) {
2861
+ if (child.type !== "element") continue;
2862
+ const name = localName5(child.name);
2863
+ switch (name) {
2864
+ case "pgSz": {
2865
+ const w = safeParseInt(child.attributes["w:w"]);
2866
+ const h = safeParseInt(child.attributes["w:h"]);
2867
+ if (w !== void 0 && h !== void 0) {
2868
+ const pageSize = { width: w, height: h };
2869
+ const orient = child.attributes["w:orient"];
2870
+ if (orient === "landscape" || orient === "portrait") {
2871
+ pageSize.orientation = orient;
2872
+ }
2873
+ props.pageSize = pageSize;
2874
+ }
2875
+ break;
2876
+ }
2877
+ case "pgMar": {
2878
+ const top = safeParseInt(child.attributes["w:top"]);
2879
+ const right = safeParseInt(child.attributes["w:right"]);
2880
+ const bottom = safeParseInt(child.attributes["w:bottom"]);
2881
+ const left = safeParseInt(child.attributes["w:left"]);
2882
+ if (top !== void 0 && right !== void 0 && bottom !== void 0 && left !== void 0) {
2883
+ const margins = { top, right, bottom, left };
2884
+ const header = safeParseInt(child.attributes["w:header"]);
2885
+ const footer = safeParseInt(child.attributes["w:footer"]);
2886
+ const gutter = safeParseInt(child.attributes["w:gutter"]);
2887
+ if (header !== void 0) margins.header = header;
2888
+ if (footer !== void 0) margins.footer = footer;
2889
+ if (gutter !== void 0) margins.gutter = gutter;
2890
+ props.pageMargins = margins;
2891
+ }
2892
+ break;
2893
+ }
2894
+ case "cols": {
2895
+ const columns = {};
2896
+ const num = safeParseInt(child.attributes["w:num"]);
2897
+ const space = safeParseInt(child.attributes["w:space"]);
2898
+ const equalWidth = child.attributes["w:equalWidth"];
2899
+ const sep = child.attributes["w:sep"];
2900
+ if (num !== void 0) columns.count = num;
2901
+ if (space !== void 0) columns.space = space;
2902
+ if (equalWidth !== void 0) columns.equalWidth = equalWidth !== "0" && equalWidth !== "false";
2903
+ if (sep === "1" || sep === "true") columns.separator = true;
2904
+ const colDefs = [];
2905
+ for (const colChild of child.children) {
2906
+ if (colChild.type === "element" && localName5(colChild.name) === "col") {
2907
+ const colW = safeParseInt(colChild.attributes["w:w"]);
2908
+ const colSpace = safeParseInt(colChild.attributes["w:space"]);
2909
+ if (colW !== void 0) {
2910
+ colDefs.push(colSpace !== void 0 ? { width: colW, space: colSpace } : { width: colW });
2911
+ }
2912
+ }
2913
+ }
2914
+ if (colDefs.length > 0) columns.columns = colDefs;
2915
+ if (Object.keys(columns).length > 0) props.columns = columns;
2916
+ break;
2917
+ }
2918
+ case "pgNumType": {
2919
+ const numbering = {};
2920
+ const fmt = child.attributes["w:fmt"];
2921
+ const start = safeParseInt(child.attributes["w:start"]);
2922
+ const chapStyle = child.attributes["w:chapStyle"];
2923
+ const chapSep = child.attributes["w:chapSep"];
2924
+ if (fmt) numbering.format = fmt;
2925
+ if (start !== void 0) numbering.start = start;
2926
+ if (chapStyle) numbering.chapStyle = chapStyle;
2927
+ if (chapSep) numbering.chapSep = chapSep;
2928
+ if (Object.keys(numbering).length > 0) props.pageNumbering = numbering;
2929
+ break;
2930
+ }
2931
+ case "lnNumType": {
2932
+ const lineNumbering = {};
2933
+ const countBy = safeParseInt(child.attributes["w:countBy"]);
2934
+ const start = safeParseInt(child.attributes["w:start"]);
2935
+ const distance = safeParseInt(child.attributes["w:distance"]);
2936
+ const restart = child.attributes["w:restart"];
2937
+ if (countBy !== void 0) lineNumbering.countBy = countBy;
2938
+ if (start !== void 0) lineNumbering.start = start;
2939
+ if (distance !== void 0) lineNumbering.distance = distance;
2940
+ if (restart === "newPage" || restart === "newSection" || restart === "continuous") {
2941
+ lineNumbering.restart = restart;
2942
+ }
2943
+ if (Object.keys(lineNumbering).length > 0) {
2944
+ props.lineNumbering = lineNumbering;
2945
+ }
2946
+ break;
2947
+ }
2948
+ case "pgBorders": {
2949
+ const pageBorders = {};
2950
+ const offsetFrom = child.attributes["w:offsetFrom"];
2951
+ const display = child.attributes["w:display"];
2952
+ const zOrder = child.attributes["w:zOrder"];
2953
+ if (offsetFrom === "page" || offsetFrom === "text") {
2954
+ pageBorders.offsetFrom = offsetFrom;
2955
+ }
2956
+ if (display === "allPages" || display === "firstPage" || display === "notFirstPage") {
2957
+ pageBorders.display = display;
2958
+ }
2959
+ if (zOrder === "front" || zOrder === "back") {
2960
+ pageBorders.zOrder = zOrder;
2961
+ }
2962
+ for (const borderChild of child.children) {
2963
+ if (borderChild.type !== "element") continue;
2964
+ const borderName = localName5(borderChild.name);
2965
+ const border = parseBorderSpec(borderChild);
2966
+ if (!border) continue;
2967
+ if (borderName === "top" || borderName === "left" || borderName === "bottom" || borderName === "right") {
2968
+ pageBorders[borderName] = border;
2969
+ }
2970
+ }
2971
+ if (Object.keys(pageBorders).length > 0) {
2972
+ props.pageBorders = pageBorders;
2973
+ }
2974
+ break;
2975
+ }
2976
+ case "docGrid": {
2977
+ const documentGrid = {};
2978
+ const type = child.attributes["w:type"];
2979
+ const linePitch = safeParseInt(child.attributes["w:linePitch"]);
2980
+ const charSpace = safeParseInt(child.attributes["w:charSpace"]);
2981
+ if (type === "default" || type === "lines" || type === "linesAndChars" || type === "snapToChars") {
2982
+ documentGrid.type = type;
2983
+ }
2984
+ if (linePitch !== void 0) documentGrid.linePitch = linePitch;
2985
+ if (charSpace !== void 0) documentGrid.charSpace = charSpace;
2986
+ if (Object.keys(documentGrid).length > 0) {
2987
+ props.documentGrid = documentGrid;
2988
+ }
2989
+ break;
2990
+ }
2991
+ case "headerReference": {
2992
+ const variant = child.attributes["w:type"];
2993
+ const rId = child.attributes["r:id"];
2994
+ if (variant && rId) {
2995
+ if (!props.headerReferences) props.headerReferences = [];
2996
+ props.headerReferences.push({ variant, relationshipId: rId });
2997
+ }
2998
+ break;
2999
+ }
3000
+ case "footerReference": {
3001
+ const variant = child.attributes["w:type"];
3002
+ const rId = child.attributes["r:id"];
3003
+ if (variant && rId) {
3004
+ if (!props.footerReferences) props.footerReferences = [];
3005
+ props.footerReferences.push({ variant, relationshipId: rId });
3006
+ }
3007
+ break;
3008
+ }
3009
+ case "type": {
3010
+ const val = child.attributes["w:val"];
3011
+ if (val === "continuous" || val === "nextPage" || val === "evenPage" || val === "oddPage" || val === "nextColumn") {
3012
+ props.sectionType = val;
3013
+ }
3014
+ break;
3015
+ }
3016
+ case "titlePg": {
3017
+ const val = child.attributes["w:val"];
3018
+ props.titlePage = val !== "false" && val !== "0";
3019
+ break;
3020
+ }
3021
+ }
3022
+ }
3023
+ return props;
3024
+ }
3025
+ function safeParseInt(value) {
3026
+ if (value === void 0) return void 0;
3027
+ const n = Number.parseInt(value, 10);
3028
+ return Number.isFinite(n) ? n : void 0;
3029
+ }
3030
+ function parseBorderSpec(node) {
3031
+ const border = {};
3032
+ const value = node.attributes["w:val"];
3033
+ const size = safeParseInt(node.attributes["w:sz"]);
3034
+ const space = safeParseInt(node.attributes["w:space"]);
3035
+ const color = node.attributes["w:color"];
3036
+ if (value) border.value = value;
3037
+ if (size !== void 0) border.size = size;
3038
+ if (space !== void 0) border.space = space;
3039
+ if (color) border.color = color;
3040
+ return Object.keys(border).length > 0 ? border : void 0;
3041
+ }
3042
+ function parsePermStartNode(node, sourceXml) {
3043
+ const rangeId = node.attributes["w:id"] ?? node.attributes.id ?? "";
3044
+ const edGrp = node.attributes["w:edGrp"] ?? node.attributes.edGrp;
3045
+ const ed = node.attributes["w:ed"] ?? node.attributes.ed;
3046
+ return {
3047
+ type: "perm_start",
3048
+ rangeId,
3049
+ ...edGrp ? { editorGroup: edGrp } : {},
3050
+ ...ed ? { editor: ed } : {},
3051
+ rawXml: sourceXml.slice(node.start, node.end)
3052
+ };
3053
+ }
3054
+ function parsePermEndNode(node, sourceXml) {
3055
+ return {
3056
+ type: "perm_end",
3057
+ rangeId: node.attributes["w:id"] ?? node.attributes.id ?? "",
3058
+ rawXml: sourceXml.slice(node.start, node.end)
3059
+ };
3060
+ }
3061
+
3062
+ export {
3063
+ parseNumberingXml,
3064
+ parseShapeXml,
3065
+ parseVmlXml,
3066
+ resolveHighlightColor,
3067
+ parseMainDocumentXml
3068
+ };
3069
+ //# sourceMappingURL=chunk-4AQOYAW4.js.map