@beyondwork/docx-react-component 1.0.29 → 1.0.30

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 (381) hide show
  1. package/package.json +65 -96
  2. package/src/README.md +85 -0
  3. package/src/api/README.md +26 -0
  4. package/src/api/public-types.ts +1952 -0
  5. package/src/api/session-state.ts +62 -0
  6. package/src/compare/diff-engine.ts +623 -0
  7. package/src/compare/export-redlines.ts +280 -0
  8. package/src/compare/index.ts +25 -0
  9. package/src/compare/snapshot.ts +97 -0
  10. package/src/component-inventory.md +99 -0
  11. package/src/core/README.md +10 -0
  12. package/src/core/commands/README.md +3 -0
  13. package/{dist/chunk-TJBP2K4T.js → src/core/commands/formatting-commands.ts} +536 -196
  14. package/src/core/commands/image-commands.ts +373 -0
  15. package/src/core/commands/index.ts +1879 -0
  16. package/src/core/commands/list-commands.ts +565 -0
  17. package/src/core/commands/paragraph-layout-commands.ts +339 -0
  18. package/src/core/commands/review-commands.ts +108 -0
  19. package/{dist/core/commands/section-layout-commands.cjs → src/core/commands/section-layout-commands.ts} +340 -137
  20. package/src/core/commands/structural-helpers.ts +309 -0
  21. package/{dist/core/commands/style-commands.cjs → src/core/commands/style-commands.ts} +113 -65
  22. package/src/core/commands/table-structure-commands.ts +854 -0
  23. package/{dist/chunk-UZXBISGO.js → src/core/commands/text-commands.ts} +142 -86
  24. package/src/core/schema/README.md +3 -0
  25. package/src/core/schema/text-schema.ts +516 -0
  26. package/src/core/search/search-text.ts +357 -0
  27. package/src/core/selection/README.md +3 -0
  28. package/src/core/selection/mapping.ts +289 -0
  29. package/src/core/selection/review-anchors.ts +183 -0
  30. package/src/core/state/README.md +3 -0
  31. package/src/core/state/editor-state.ts +892 -0
  32. package/src/core/state/text-transaction.ts +869 -0
  33. package/src/formats/xlsx/io/parse-shared-strings.ts +41 -0
  34. package/src/formats/xlsx/io/parse-sheet.ts +459 -0
  35. package/src/formats/xlsx/io/parse-styles.ts +59 -0
  36. package/src/formats/xlsx/io/parse-workbook.ts +75 -0
  37. package/src/formats/xlsx/io/serialize-shared-strings.ts +72 -0
  38. package/src/formats/xlsx/io/serialize-sheet.ts +333 -0
  39. package/src/formats/xlsx/io/serialize-styles.ts +98 -0
  40. package/src/formats/xlsx/io/serialize-workbook.ts +429 -0
  41. package/src/formats/xlsx/io/xlsx-session.ts +314 -0
  42. package/src/formats/xlsx/model/cell.ts +189 -0
  43. package/src/formats/xlsx/model/sheet.ts +326 -0
  44. package/src/formats/xlsx/model/styles.ts +118 -0
  45. package/src/formats/xlsx/model/workbook.ts +453 -0
  46. package/src/formats/xlsx/runtime/cell-commands.ts +567 -0
  47. package/src/formats/xlsx/runtime/sheet-commands.ts +206 -0
  48. package/src/formats/xlsx/runtime/workbook-runtime.ts +177 -0
  49. package/src/formats/xlsx/runtime/workbook-transaction.ts +822 -0
  50. package/src/index.ts +142 -0
  51. package/src/io/README.md +10 -0
  52. package/src/io/docx-session.ts +3175 -0
  53. package/src/io/export/README.md +3 -0
  54. package/src/io/export/export-session.ts +220 -0
  55. package/src/io/export/minimal-docx.ts +115 -0
  56. package/src/io/export/reattach-preserved-parts.ts +54 -0
  57. package/src/io/export/serialize-comments.ts +947 -0
  58. package/src/io/export/serialize-footnotes.ts +394 -0
  59. package/src/io/export/serialize-headers-footers.ts +368 -0
  60. package/src/io/export/serialize-main-document.ts +1342 -0
  61. package/src/io/export/serialize-numbering.ts +218 -0
  62. package/src/io/export/serialize-revisions.ts +389 -0
  63. package/src/io/export/serialize-runtime-revisions.ts +463 -0
  64. package/src/io/export/serialize-tables.ts +174 -0
  65. package/src/io/export/split-review-boundaries.ts +356 -0
  66. package/src/io/export/split-story-blocks-for-runtime-revisions.ts +252 -0
  67. package/src/io/export/table-properties-xml.ts +318 -0
  68. package/src/io/normalize/README.md +3 -0
  69. package/src/io/normalize/normalize-text.ts +670 -0
  70. package/src/io/ooxml/README.md +3 -0
  71. package/src/io/ooxml/highlight-colors.ts +39 -0
  72. package/src/io/ooxml/numbering-sentinels.ts +44 -0
  73. package/src/io/ooxml/parse-comments.ts +852 -0
  74. package/src/io/ooxml/parse-complex-content.ts +287 -0
  75. package/src/io/ooxml/parse-fields.ts +834 -0
  76. package/src/io/ooxml/parse-footnotes.ts +952 -0
  77. package/src/io/ooxml/parse-headers-footers.ts +1212 -0
  78. package/src/io/ooxml/parse-inline-media.ts +461 -0
  79. package/src/io/ooxml/parse-main-document.ts +2947 -0
  80. package/src/io/ooxml/parse-numbering.ts +747 -0
  81. package/src/io/ooxml/parse-revisions.ts +1045 -0
  82. package/src/io/ooxml/parse-settings.ts +184 -0
  83. package/src/io/ooxml/parse-shapes.ts +296 -0
  84. package/src/io/ooxml/parse-styles.ts +639 -0
  85. package/src/io/ooxml/parse-tables.ts +627 -0
  86. package/src/io/ooxml/parse-theme.ts +346 -0
  87. package/src/io/ooxml/part-manifest.ts +136 -0
  88. package/src/io/ooxml/revision-boundaries.ts +475 -0
  89. package/src/io/ooxml/workflow-payload.ts +544 -0
  90. package/src/io/opc/README.md +3 -0
  91. package/src/io/opc/corrupt-package.ts +166 -0
  92. package/src/io/opc/docx-package.ts +74 -0
  93. package/src/io/opc/package-reader.ts +325 -0
  94. package/src/io/opc/package-writer.ts +273 -0
  95. package/src/io/source-package-provenance.ts +241 -0
  96. package/{dist/chunk-RMH72RZI.js → src/legal/bookmarks.ts} +130 -44
  97. package/src/legal/cross-references.ts +414 -0
  98. package/src/legal/defined-terms.ts +203 -0
  99. package/src/legal/index.ts +32 -0
  100. package/src/legal/signature-blocks.ts +259 -0
  101. package/src/model/README.md +3 -0
  102. package/src/model/canonical-document.ts +2722 -0
  103. package/src/model/cds-1.0.0.ts +212 -0
  104. package/src/model/snapshot.ts +760 -0
  105. package/src/preservation/README.md +3 -0
  106. package/src/preservation/markup-compatibility.ts +48 -0
  107. package/src/preservation/opaque-fragment-store.ts +89 -0
  108. package/src/preservation/opaque-region.ts +233 -0
  109. package/src/preservation/package-preservation.ts +113 -0
  110. package/src/preservation/preserved-part-manifest.ts +56 -0
  111. package/src/preservation/relationship-retention.ts +57 -0
  112. package/src/preservation/store.ts +255 -0
  113. package/src/review/README.md +16 -0
  114. package/src/review/store/README.md +3 -0
  115. package/src/review/store/comment-anchors.ts +70 -0
  116. package/src/review/store/comment-remapping.ts +154 -0
  117. package/src/review/store/comment-store.ts +349 -0
  118. package/src/review/store/comment-thread.ts +109 -0
  119. package/src/review/store/revision-actions.ts +423 -0
  120. package/src/review/store/revision-store.ts +323 -0
  121. package/src/review/store/revision-types.ts +182 -0
  122. package/src/review/store/runtime-comment-store.ts +43 -0
  123. package/src/runtime/README.md +3 -0
  124. package/src/runtime/ai-action-policy.ts +764 -0
  125. package/src/runtime/context-analytics.ts +824 -0
  126. package/src/runtime/document-layout.ts +332 -0
  127. package/src/runtime/document-locations.ts +521 -0
  128. package/src/runtime/document-navigation.ts +616 -0
  129. package/src/runtime/document-outline.ts +440 -0
  130. package/src/runtime/document-runtime.ts +4055 -0
  131. package/src/runtime/document-search.ts +145 -0
  132. package/src/runtime/event-refresh-hints.ts +137 -0
  133. package/src/runtime/numbering-prefix.ts +244 -0
  134. package/src/runtime/page-layout-estimation.ts +305 -0
  135. package/src/runtime/read-only-diagnostics-runtime.ts +241 -0
  136. package/src/runtime/resolved-numbering-geometry.ts +293 -0
  137. package/src/runtime/review-runtime.ts +44 -0
  138. package/src/runtime/revision-runtime.ts +107 -0
  139. package/src/runtime/session-capabilities.ts +192 -0
  140. package/src/runtime/story-context.ts +164 -0
  141. package/src/runtime/story-targeting.ts +162 -0
  142. package/src/runtime/suggestions-snapshot.ts +137 -0
  143. package/src/runtime/surface-projection.ts +1553 -0
  144. package/src/runtime/table-commands.ts +173 -0
  145. package/src/runtime/table-schema.ts +309 -0
  146. package/src/runtime/table-style-resolver.ts +409 -0
  147. package/src/runtime/view-state.ts +493 -0
  148. package/src/runtime/virtualized-rendering.ts +258 -0
  149. package/src/runtime/workflow-markup.ts +393 -0
  150. package/src/ui/README.md +30 -0
  151. package/src/ui/WordReviewEditor.tsx +5268 -0
  152. package/src/ui/browser-export.ts +52 -0
  153. package/src/ui/comments/README.md +3 -0
  154. package/src/ui/compatibility/README.md +3 -0
  155. package/src/ui/editor-command-bag.ts +127 -0
  156. package/src/ui/editor-runtime-boundary.ts +1558 -0
  157. package/src/ui/editor-shell-view.tsx +144 -0
  158. package/src/ui/editor-surface/README.md +3 -0
  159. package/src/ui/editor-surface-controller.tsx +66 -0
  160. package/src/ui/headless/comment-decoration-model.ts +124 -0
  161. package/src/ui/headless/preserve-editor-selection.ts +5 -0
  162. package/src/ui/headless/revision-decoration-model.ts +128 -0
  163. package/src/ui/headless/selection-helpers.ts +54 -0
  164. package/src/ui/headless/selection-tool-context.ts +19 -0
  165. package/src/ui/headless/selection-tool-resolver.ts +752 -0
  166. package/src/ui/headless/selection-tool-types.ts +129 -0
  167. package/src/ui/headless/selection-toolbar-model.ts +11 -0
  168. package/src/ui/headless/use-editor-keyboard.ts +103 -0
  169. package/src/ui/review/README.md +3 -0
  170. package/src/ui/runtime-shortcut-dispatch.ts +365 -0
  171. package/src/ui/runtime-snapshot-selectors.ts +197 -0
  172. package/src/ui/shared/revision-filters.ts +31 -0
  173. package/src/ui/status/README.md +3 -0
  174. package/src/ui/theme/README.md +3 -0
  175. package/src/ui/toolbar/README.md +3 -0
  176. package/src/ui/workflow-surface-blocked-rails.ts +94 -0
  177. package/src/ui-tailwind/chrome/chrome-preset-model.ts +107 -0
  178. package/src/ui-tailwind/chrome/chrome-preset-toolbar.tsx +15 -0
  179. package/src/ui-tailwind/chrome/review-queue-bar.tsx +97 -0
  180. package/src/ui-tailwind/chrome/tw-alert-banner.tsx +64 -0
  181. package/src/ui-tailwind/chrome/tw-context-analytics-summary.tsx +122 -0
  182. package/src/ui-tailwind/chrome/tw-image-context-toolbar.tsx +121 -0
  183. package/src/ui-tailwind/chrome/tw-layout-panel.tsx +114 -0
  184. package/src/ui-tailwind/chrome/tw-object-context-toolbar.tsx +30 -0
  185. package/src/ui-tailwind/chrome/tw-page-ruler.tsx +365 -0
  186. package/src/ui-tailwind/chrome/tw-selection-tool-blocked.tsx +23 -0
  187. package/src/ui-tailwind/chrome/tw-selection-tool-comment.tsx +35 -0
  188. package/src/ui-tailwind/chrome/tw-selection-tool-formatting.tsx +37 -0
  189. package/src/ui-tailwind/chrome/tw-selection-tool-host.tsx +298 -0
  190. package/src/ui-tailwind/chrome/tw-selection-tool-structure.tsx +116 -0
  191. package/src/ui-tailwind/chrome/tw-selection-tool-suggestion.tsx +29 -0
  192. package/src/ui-tailwind/chrome/tw-selection-tool-workflow.tsx +27 -0
  193. package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +186 -0
  194. package/src/ui-tailwind/chrome/tw-suggestion-card.tsx +139 -0
  195. package/src/ui-tailwind/chrome/tw-table-context-toolbar.tsx +200 -0
  196. package/src/ui-tailwind/chrome/tw-unsaved-modal.tsx +58 -0
  197. package/src/ui-tailwind/chrome/use-before-unload.ts +20 -0
  198. package/src/ui-tailwind/editor-surface/perf-probe.ts +179 -0
  199. package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +189 -0
  200. package/src/ui-tailwind/editor-surface/pm-contextual-ui.ts +31 -0
  201. package/src/ui-tailwind/editor-surface/pm-decorations.ts +411 -0
  202. package/src/ui-tailwind/editor-surface/pm-position-map.ts +123 -0
  203. package/src/ui-tailwind/editor-surface/pm-schema.ts +927 -0
  204. package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +567 -0
  205. package/src/ui-tailwind/editor-surface/search-plugin.ts +168 -0
  206. package/src/ui-tailwind/editor-surface/surface-build-keys.ts +65 -0
  207. package/src/ui-tailwind/editor-surface/tw-caret.tsx +12 -0
  208. package/src/ui-tailwind/editor-surface/tw-editor-surface.tsx +150 -0
  209. package/src/ui-tailwind/editor-surface/tw-inline-token.tsx +129 -0
  210. package/src/ui-tailwind/editor-surface/tw-opaque-block.tsx +58 -0
  211. package/src/ui-tailwind/editor-surface/tw-paragraph-block.tsx +151 -0
  212. package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +1047 -0
  213. package/src/ui-tailwind/editor-surface/tw-segment-view.tsx +111 -0
  214. package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +503 -0
  215. package/src/ui-tailwind/index.ts +62 -0
  216. package/src/ui-tailwind/page-chrome-model.ts +27 -0
  217. package/src/ui-tailwind/review/tw-comment-sidebar.tsx +406 -0
  218. package/src/ui-tailwind/review/tw-health-panel.tsx +149 -0
  219. package/src/ui-tailwind/review/tw-review-rail.tsx +122 -0
  220. package/src/ui-tailwind/review/tw-revision-sidebar.tsx +164 -0
  221. package/src/ui-tailwind/status/tw-status-bar.tsx +65 -0
  222. package/{dist → src}/ui-tailwind/theme/editor-theme.css +58 -40
  223. package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +52 -0
  224. package/src/ui-tailwind/toolbar/tw-toolbar.tsx +1133 -0
  225. package/src/ui-tailwind/tw-review-workspace.tsx +1460 -0
  226. package/src/validation/README.md +3 -0
  227. package/src/validation/compatibility-engine.ts +878 -0
  228. package/src/validation/compatibility-report.ts +161 -0
  229. package/src/validation/diagnostics.ts +204 -0
  230. package/src/validation/docx-comment-proof.ts +720 -0
  231. package/src/validation/import-diagnostics.ts +128 -0
  232. package/src/validation/low-priority-word-surfaces.ts +373 -0
  233. package/dist/canonical-document-BLEbzL2J.d.cts +0 -844
  234. package/dist/canonical-document-BLEbzL2J.d.ts +0 -844
  235. package/dist/chunk-2FJS5GZM.js +0 -763
  236. package/dist/chunk-2FJS5GZM.js.map +0 -1
  237. package/dist/chunk-2OQBZS3F.js +0 -446
  238. package/dist/chunk-2OQBZS3F.js.map +0 -1
  239. package/dist/chunk-2S7W4KFO.js +0 -127
  240. package/dist/chunk-2S7W4KFO.js.map +0 -1
  241. package/dist/chunk-2TG72QSW.js +0 -3874
  242. package/dist/chunk-2TG72QSW.js.map +0 -1
  243. package/dist/chunk-36QNIZBO.js +0 -532
  244. package/dist/chunk-36QNIZBO.js.map +0 -1
  245. package/dist/chunk-4AQOYAW4.js +0 -3069
  246. package/dist/chunk-4AQOYAW4.js.map +0 -1
  247. package/dist/chunk-4D5EWJ3P.js +0 -77
  248. package/dist/chunk-4D5EWJ3P.js.map +0 -1
  249. package/dist/chunk-5FN54NDH.js +0 -2257
  250. package/dist/chunk-5FN54NDH.js.map +0 -1
  251. package/dist/chunk-BOYGQYRQ.js +0 -7306
  252. package/dist/chunk-BOYGQYRQ.js.map +0 -1
  253. package/dist/chunk-CN3XMECL.js +0 -212
  254. package/dist/chunk-CN3XMECL.js.map +0 -1
  255. package/dist/chunk-EBI3BX6U.js +0 -164
  256. package/dist/chunk-EBI3BX6U.js.map +0 -1
  257. package/dist/chunk-EILUG3VB.js +0 -1275
  258. package/dist/chunk-EILUG3VB.js.map +0 -1
  259. package/dist/chunk-FUDY333O.js +0 -70
  260. package/dist/chunk-FUDY333O.js.map +0 -1
  261. package/dist/chunk-GBVOWFIK.js +0 -1237
  262. package/dist/chunk-GBVOWFIK.js.map +0 -1
  263. package/dist/chunk-H4TQ3H3Y.js +0 -262
  264. package/dist/chunk-H4TQ3H3Y.js.map +0 -1
  265. package/dist/chunk-JGB3IXZO.js +0 -189
  266. package/dist/chunk-JGB3IXZO.js.map +0 -1
  267. package/dist/chunk-KD2QRQPY.js +0 -4342
  268. package/dist/chunk-KD2QRQPY.js.map +0 -1
  269. package/dist/chunk-KLMXQVYK.js +0 -369
  270. package/dist/chunk-KLMXQVYK.js.map +0 -1
  271. package/dist/chunk-KZUG5KFQ.js +0 -214
  272. package/dist/chunk-KZUG5KFQ.js.map +0 -1
  273. package/dist/chunk-QDAQ4CJU.js +0 -345
  274. package/dist/chunk-QDAQ4CJU.js.map +0 -1
  275. package/dist/chunk-RMH72RZI.js.map +0 -1
  276. package/dist/chunk-SWKWQZXM.js +0 -117
  277. package/dist/chunk-SWKWQZXM.js.map +0 -1
  278. package/dist/chunk-TJBP2K4T.js.map +0 -1
  279. package/dist/chunk-TLCEAQDQ.js +0 -542
  280. package/dist/chunk-TLCEAQDQ.js.map +0 -1
  281. package/dist/chunk-UZXBISGO.js.map +0 -1
  282. package/dist/chunk-WGBAKP3Q.js +0 -3220
  283. package/dist/chunk-WGBAKP3Q.js.map +0 -1
  284. package/dist/compare/index.cjs +0 -5475
  285. package/dist/compare/index.cjs.map +0 -1
  286. package/dist/compare/index.d.cts +0 -114
  287. package/dist/compare/index.d.ts +0 -114
  288. package/dist/compare/index.js +0 -731
  289. package/dist/compare/index.js.map +0 -1
  290. package/dist/core/commands/formatting-commands.cjs +0 -828
  291. package/dist/core/commands/formatting-commands.cjs.map +0 -1
  292. package/dist/core/commands/formatting-commands.d.cts +0 -63
  293. package/dist/core/commands/formatting-commands.d.ts +0 -63
  294. package/dist/core/commands/formatting-commands.js +0 -37
  295. package/dist/core/commands/formatting-commands.js.map +0 -1
  296. package/dist/core/commands/image-commands.cjs +0 -2023
  297. package/dist/core/commands/image-commands.cjs.map +0 -1
  298. package/dist/core/commands/image-commands.d.cts +0 -58
  299. package/dist/core/commands/image-commands.d.ts +0 -58
  300. package/dist/core/commands/image-commands.js +0 -18
  301. package/dist/core/commands/image-commands.js.map +0 -1
  302. package/dist/core/commands/section-layout-commands.cjs.map +0 -1
  303. package/dist/core/commands/section-layout-commands.d.cts +0 -62
  304. package/dist/core/commands/section-layout-commands.d.ts +0 -62
  305. package/dist/core/commands/section-layout-commands.js +0 -21
  306. package/dist/core/commands/section-layout-commands.js.map +0 -1
  307. package/dist/core/commands/style-commands.cjs.map +0 -1
  308. package/dist/core/commands/style-commands.d.cts +0 -13
  309. package/dist/core/commands/style-commands.d.ts +0 -13
  310. package/dist/core/commands/style-commands.js +0 -9
  311. package/dist/core/commands/style-commands.js.map +0 -1
  312. package/dist/core/commands/table-structure-commands.cjs +0 -1883
  313. package/dist/core/commands/table-structure-commands.cjs.map +0 -1
  314. package/dist/core/commands/table-structure-commands.d.cts +0 -59
  315. package/dist/core/commands/table-structure-commands.d.ts +0 -59
  316. package/dist/core/commands/table-structure-commands.js +0 -12
  317. package/dist/core/commands/table-structure-commands.js.map +0 -1
  318. package/dist/core/commands/text-commands.cjs +0 -2391
  319. package/dist/core/commands/text-commands.cjs.map +0 -1
  320. package/dist/core/commands/text-commands.d.cts +0 -24
  321. package/dist/core/commands/text-commands.d.ts +0 -24
  322. package/dist/core/commands/text-commands.js +0 -28
  323. package/dist/core/commands/text-commands.js.map +0 -1
  324. package/dist/core/selection/mapping.cjs +0 -200
  325. package/dist/core/selection/mapping.cjs.map +0 -1
  326. package/dist/core/selection/mapping.d.cts +0 -2
  327. package/dist/core/selection/mapping.d.ts +0 -2
  328. package/dist/core/selection/mapping.js +0 -31
  329. package/dist/core/selection/mapping.js.map +0 -1
  330. package/dist/core/state/editor-state.cjs +0 -2278
  331. package/dist/core/state/editor-state.cjs.map +0 -1
  332. package/dist/core/state/editor-state.d.cts +0 -2
  333. package/dist/core/state/editor-state.d.ts +0 -2
  334. package/dist/core/state/editor-state.js +0 -26
  335. package/dist/core/state/editor-state.js.map +0 -1
  336. package/dist/index.cjs +0 -38553
  337. package/dist/index.cjs.map +0 -1
  338. package/dist/index.d.cts +0 -15
  339. package/dist/index.d.ts +0 -15
  340. package/dist/index.js +0 -7856
  341. package/dist/index.js.map +0 -1
  342. package/dist/io/docx-session.cjs +0 -16236
  343. package/dist/io/docx-session.cjs.map +0 -1
  344. package/dist/io/docx-session.d.cts +0 -21
  345. package/dist/io/docx-session.d.ts +0 -21
  346. package/dist/io/docx-session.js +0 -18
  347. package/dist/io/docx-session.js.map +0 -1
  348. package/dist/legal/index.cjs +0 -3900
  349. package/dist/legal/index.cjs.map +0 -1
  350. package/dist/legal/index.d.cts +0 -86
  351. package/dist/legal/index.d.ts +0 -86
  352. package/dist/legal/index.js +0 -616
  353. package/dist/legal/index.js.map +0 -1
  354. package/dist/public-types-7ZL_94cz.d.ts +0 -1573
  355. package/dist/public-types-CeMaDueh.d.cts +0 -1573
  356. package/dist/public-types.cjs +0 -19
  357. package/dist/public-types.cjs.map +0 -1
  358. package/dist/public-types.d.cts +0 -2
  359. package/dist/public-types.d.ts +0 -2
  360. package/dist/public-types.js +0 -1
  361. package/dist/public-types.js.map +0 -1
  362. package/dist/runtime/document-runtime.cjs +0 -11140
  363. package/dist/runtime/document-runtime.cjs.map +0 -1
  364. package/dist/runtime/document-runtime.d.cts +0 -231
  365. package/dist/runtime/document-runtime.d.ts +0 -231
  366. package/dist/runtime/document-runtime.js +0 -21
  367. package/dist/runtime/document-runtime.js.map +0 -1
  368. package/dist/structural-helpers-CilgOVhh.d.cts +0 -10
  369. package/dist/structural-helpers-q0Gd-eBN.d.ts +0 -10
  370. package/dist/ui-tailwind/editor-surface/search-plugin.cjs +0 -313
  371. package/dist/ui-tailwind/editor-surface/search-plugin.cjs.map +0 -1
  372. package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +0 -67
  373. package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +0 -67
  374. package/dist/ui-tailwind/editor-surface/search-plugin.js +0 -23
  375. package/dist/ui-tailwind/editor-surface/search-plugin.js.map +0 -1
  376. package/dist/ui-tailwind/index.cjs +0 -4833
  377. package/dist/ui-tailwind/index.cjs.map +0 -1
  378. package/dist/ui-tailwind/index.d.cts +0 -617
  379. package/dist/ui-tailwind/index.d.ts +0 -617
  380. package/dist/ui-tailwind/index.js +0 -575
  381. package/dist/ui-tailwind/index.js.map +0 -1
@@ -1,3069 +0,0 @@
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