@beyondwork/docx-react-component 1.0.29 → 1.0.31

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 (383) 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/responsive-chrome.ts +46 -0
  180. package/src/ui-tailwind/chrome/review-queue-bar.tsx +97 -0
  181. package/src/ui-tailwind/chrome/tw-alert-banner.tsx +64 -0
  182. package/src/ui-tailwind/chrome/tw-context-analytics-summary.tsx +122 -0
  183. package/src/ui-tailwind/chrome/tw-image-context-toolbar.tsx +121 -0
  184. package/src/ui-tailwind/chrome/tw-layout-panel.tsx +114 -0
  185. package/src/ui-tailwind/chrome/tw-object-context-toolbar.tsx +30 -0
  186. package/src/ui-tailwind/chrome/tw-page-ruler.tsx +365 -0
  187. package/src/ui-tailwind/chrome/tw-selection-tool-blocked.tsx +23 -0
  188. package/src/ui-tailwind/chrome/tw-selection-tool-comment.tsx +35 -0
  189. package/src/ui-tailwind/chrome/tw-selection-tool-formatting.tsx +37 -0
  190. package/src/ui-tailwind/chrome/tw-selection-tool-host.tsx +303 -0
  191. package/src/ui-tailwind/chrome/tw-selection-tool-structure.tsx +116 -0
  192. package/src/ui-tailwind/chrome/tw-selection-tool-suggestion.tsx +29 -0
  193. package/src/ui-tailwind/chrome/tw-selection-tool-workflow.tsx +27 -0
  194. package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +186 -0
  195. package/src/ui-tailwind/chrome/tw-suggestion-card.tsx +139 -0
  196. package/src/ui-tailwind/chrome/tw-table-context-toolbar.tsx +250 -0
  197. package/src/ui-tailwind/chrome/tw-unsaved-modal.tsx +58 -0
  198. package/src/ui-tailwind/chrome/use-before-unload.ts +20 -0
  199. package/src/ui-tailwind/editor-surface/perf-probe.ts +179 -0
  200. package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +189 -0
  201. package/src/ui-tailwind/editor-surface/pm-contextual-ui.ts +31 -0
  202. package/src/ui-tailwind/editor-surface/pm-decorations.ts +411 -0
  203. package/src/ui-tailwind/editor-surface/pm-position-map.ts +123 -0
  204. package/src/ui-tailwind/editor-surface/pm-schema.ts +927 -0
  205. package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +567 -0
  206. package/src/ui-tailwind/editor-surface/search-plugin.ts +168 -0
  207. package/src/ui-tailwind/editor-surface/surface-build-keys.ts +63 -0
  208. package/src/ui-tailwind/editor-surface/tw-caret.tsx +12 -0
  209. package/src/ui-tailwind/editor-surface/tw-editor-surface.tsx +150 -0
  210. package/src/ui-tailwind/editor-surface/tw-inline-token.tsx +129 -0
  211. package/src/ui-tailwind/editor-surface/tw-opaque-block.tsx +58 -0
  212. package/src/ui-tailwind/editor-surface/tw-paragraph-block.tsx +151 -0
  213. package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +1047 -0
  214. package/src/ui-tailwind/editor-surface/tw-segment-view.tsx +111 -0
  215. package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +503 -0
  216. package/src/ui-tailwind/index.ts +62 -0
  217. package/src/ui-tailwind/page-chrome-model.ts +27 -0
  218. package/src/ui-tailwind/review/tw-comment-sidebar.tsx +406 -0
  219. package/src/ui-tailwind/review/tw-health-panel.tsx +149 -0
  220. package/src/ui-tailwind/review/tw-review-rail.tsx +130 -0
  221. package/src/ui-tailwind/review/tw-revision-sidebar.tsx +164 -0
  222. package/src/ui-tailwind/status/tw-status-bar.tsx +65 -0
  223. package/{dist → src}/ui-tailwind/theme/editor-theme.css +58 -40
  224. package/src/ui-tailwind/toolbar/toolbar-layout.ts +47 -0
  225. package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +52 -0
  226. package/src/ui-tailwind/toolbar/tw-toolbar.tsx +1478 -0
  227. package/src/ui-tailwind/tw-review-workspace.tsx +1587 -0
  228. package/src/validation/README.md +3 -0
  229. package/src/validation/compatibility-engine.ts +878 -0
  230. package/src/validation/compatibility-report.ts +161 -0
  231. package/src/validation/diagnostics.ts +204 -0
  232. package/src/validation/docx-comment-proof.ts +720 -0
  233. package/src/validation/import-diagnostics.ts +128 -0
  234. package/src/validation/low-priority-word-surfaces.ts +373 -0
  235. package/dist/canonical-document-BLEbzL2J.d.cts +0 -844
  236. package/dist/canonical-document-BLEbzL2J.d.ts +0 -844
  237. package/dist/chunk-2FJS5GZM.js +0 -763
  238. package/dist/chunk-2FJS5GZM.js.map +0 -1
  239. package/dist/chunk-2OQBZS3F.js +0 -446
  240. package/dist/chunk-2OQBZS3F.js.map +0 -1
  241. package/dist/chunk-2S7W4KFO.js +0 -127
  242. package/dist/chunk-2S7W4KFO.js.map +0 -1
  243. package/dist/chunk-2TG72QSW.js +0 -3874
  244. package/dist/chunk-2TG72QSW.js.map +0 -1
  245. package/dist/chunk-36QNIZBO.js +0 -532
  246. package/dist/chunk-36QNIZBO.js.map +0 -1
  247. package/dist/chunk-4AQOYAW4.js +0 -3069
  248. package/dist/chunk-4AQOYAW4.js.map +0 -1
  249. package/dist/chunk-4D5EWJ3P.js +0 -77
  250. package/dist/chunk-4D5EWJ3P.js.map +0 -1
  251. package/dist/chunk-5FN54NDH.js +0 -2257
  252. package/dist/chunk-5FN54NDH.js.map +0 -1
  253. package/dist/chunk-BOYGQYRQ.js +0 -7306
  254. package/dist/chunk-BOYGQYRQ.js.map +0 -1
  255. package/dist/chunk-CN3XMECL.js +0 -212
  256. package/dist/chunk-CN3XMECL.js.map +0 -1
  257. package/dist/chunk-EBI3BX6U.js +0 -164
  258. package/dist/chunk-EBI3BX6U.js.map +0 -1
  259. package/dist/chunk-EILUG3VB.js +0 -1275
  260. package/dist/chunk-EILUG3VB.js.map +0 -1
  261. package/dist/chunk-FUDY333O.js +0 -70
  262. package/dist/chunk-FUDY333O.js.map +0 -1
  263. package/dist/chunk-GBVOWFIK.js +0 -1237
  264. package/dist/chunk-GBVOWFIK.js.map +0 -1
  265. package/dist/chunk-H4TQ3H3Y.js +0 -262
  266. package/dist/chunk-H4TQ3H3Y.js.map +0 -1
  267. package/dist/chunk-JGB3IXZO.js +0 -189
  268. package/dist/chunk-JGB3IXZO.js.map +0 -1
  269. package/dist/chunk-KD2QRQPY.js +0 -4342
  270. package/dist/chunk-KD2QRQPY.js.map +0 -1
  271. package/dist/chunk-KLMXQVYK.js +0 -369
  272. package/dist/chunk-KLMXQVYK.js.map +0 -1
  273. package/dist/chunk-KZUG5KFQ.js +0 -214
  274. package/dist/chunk-KZUG5KFQ.js.map +0 -1
  275. package/dist/chunk-QDAQ4CJU.js +0 -345
  276. package/dist/chunk-QDAQ4CJU.js.map +0 -1
  277. package/dist/chunk-RMH72RZI.js.map +0 -1
  278. package/dist/chunk-SWKWQZXM.js +0 -117
  279. package/dist/chunk-SWKWQZXM.js.map +0 -1
  280. package/dist/chunk-TJBP2K4T.js.map +0 -1
  281. package/dist/chunk-TLCEAQDQ.js +0 -542
  282. package/dist/chunk-TLCEAQDQ.js.map +0 -1
  283. package/dist/chunk-UZXBISGO.js.map +0 -1
  284. package/dist/chunk-WGBAKP3Q.js +0 -3220
  285. package/dist/chunk-WGBAKP3Q.js.map +0 -1
  286. package/dist/compare/index.cjs +0 -5475
  287. package/dist/compare/index.cjs.map +0 -1
  288. package/dist/compare/index.d.cts +0 -114
  289. package/dist/compare/index.d.ts +0 -114
  290. package/dist/compare/index.js +0 -731
  291. package/dist/compare/index.js.map +0 -1
  292. package/dist/core/commands/formatting-commands.cjs +0 -828
  293. package/dist/core/commands/formatting-commands.cjs.map +0 -1
  294. package/dist/core/commands/formatting-commands.d.cts +0 -63
  295. package/dist/core/commands/formatting-commands.d.ts +0 -63
  296. package/dist/core/commands/formatting-commands.js +0 -37
  297. package/dist/core/commands/formatting-commands.js.map +0 -1
  298. package/dist/core/commands/image-commands.cjs +0 -2023
  299. package/dist/core/commands/image-commands.cjs.map +0 -1
  300. package/dist/core/commands/image-commands.d.cts +0 -58
  301. package/dist/core/commands/image-commands.d.ts +0 -58
  302. package/dist/core/commands/image-commands.js +0 -18
  303. package/dist/core/commands/image-commands.js.map +0 -1
  304. package/dist/core/commands/section-layout-commands.cjs.map +0 -1
  305. package/dist/core/commands/section-layout-commands.d.cts +0 -62
  306. package/dist/core/commands/section-layout-commands.d.ts +0 -62
  307. package/dist/core/commands/section-layout-commands.js +0 -21
  308. package/dist/core/commands/section-layout-commands.js.map +0 -1
  309. package/dist/core/commands/style-commands.cjs.map +0 -1
  310. package/dist/core/commands/style-commands.d.cts +0 -13
  311. package/dist/core/commands/style-commands.d.ts +0 -13
  312. package/dist/core/commands/style-commands.js +0 -9
  313. package/dist/core/commands/style-commands.js.map +0 -1
  314. package/dist/core/commands/table-structure-commands.cjs +0 -1883
  315. package/dist/core/commands/table-structure-commands.cjs.map +0 -1
  316. package/dist/core/commands/table-structure-commands.d.cts +0 -59
  317. package/dist/core/commands/table-structure-commands.d.ts +0 -59
  318. package/dist/core/commands/table-structure-commands.js +0 -12
  319. package/dist/core/commands/table-structure-commands.js.map +0 -1
  320. package/dist/core/commands/text-commands.cjs +0 -2391
  321. package/dist/core/commands/text-commands.cjs.map +0 -1
  322. package/dist/core/commands/text-commands.d.cts +0 -24
  323. package/dist/core/commands/text-commands.d.ts +0 -24
  324. package/dist/core/commands/text-commands.js +0 -28
  325. package/dist/core/commands/text-commands.js.map +0 -1
  326. package/dist/core/selection/mapping.cjs +0 -200
  327. package/dist/core/selection/mapping.cjs.map +0 -1
  328. package/dist/core/selection/mapping.d.cts +0 -2
  329. package/dist/core/selection/mapping.d.ts +0 -2
  330. package/dist/core/selection/mapping.js +0 -31
  331. package/dist/core/selection/mapping.js.map +0 -1
  332. package/dist/core/state/editor-state.cjs +0 -2278
  333. package/dist/core/state/editor-state.cjs.map +0 -1
  334. package/dist/core/state/editor-state.d.cts +0 -2
  335. package/dist/core/state/editor-state.d.ts +0 -2
  336. package/dist/core/state/editor-state.js +0 -26
  337. package/dist/core/state/editor-state.js.map +0 -1
  338. package/dist/index.cjs +0 -38553
  339. package/dist/index.cjs.map +0 -1
  340. package/dist/index.d.cts +0 -15
  341. package/dist/index.d.ts +0 -15
  342. package/dist/index.js +0 -7856
  343. package/dist/index.js.map +0 -1
  344. package/dist/io/docx-session.cjs +0 -16236
  345. package/dist/io/docx-session.cjs.map +0 -1
  346. package/dist/io/docx-session.d.cts +0 -21
  347. package/dist/io/docx-session.d.ts +0 -21
  348. package/dist/io/docx-session.js +0 -18
  349. package/dist/io/docx-session.js.map +0 -1
  350. package/dist/legal/index.cjs +0 -3900
  351. package/dist/legal/index.cjs.map +0 -1
  352. package/dist/legal/index.d.cts +0 -86
  353. package/dist/legal/index.d.ts +0 -86
  354. package/dist/legal/index.js +0 -616
  355. package/dist/legal/index.js.map +0 -1
  356. package/dist/public-types-7ZL_94cz.d.ts +0 -1573
  357. package/dist/public-types-CeMaDueh.d.cts +0 -1573
  358. package/dist/public-types.cjs +0 -19
  359. package/dist/public-types.cjs.map +0 -1
  360. package/dist/public-types.d.cts +0 -2
  361. package/dist/public-types.d.ts +0 -2
  362. package/dist/public-types.js +0 -1
  363. package/dist/public-types.js.map +0 -1
  364. package/dist/runtime/document-runtime.cjs +0 -11140
  365. package/dist/runtime/document-runtime.cjs.map +0 -1
  366. package/dist/runtime/document-runtime.d.cts +0 -231
  367. package/dist/runtime/document-runtime.d.ts +0 -231
  368. package/dist/runtime/document-runtime.js +0 -21
  369. package/dist/runtime/document-runtime.js.map +0 -1
  370. package/dist/structural-helpers-CilgOVhh.d.cts +0 -10
  371. package/dist/structural-helpers-q0Gd-eBN.d.ts +0 -10
  372. package/dist/ui-tailwind/editor-surface/search-plugin.cjs +0 -313
  373. package/dist/ui-tailwind/editor-surface/search-plugin.cjs.map +0 -1
  374. package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +0 -67
  375. package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +0 -67
  376. package/dist/ui-tailwind/editor-surface/search-plugin.js +0 -23
  377. package/dist/ui-tailwind/editor-surface/search-plugin.js.map +0 -1
  378. package/dist/ui-tailwind/index.cjs +0 -4833
  379. package/dist/ui-tailwind/index.cjs.map +0 -1
  380. package/dist/ui-tailwind/index.d.cts +0 -617
  381. package/dist/ui-tailwind/index.d.ts +0 -617
  382. package/dist/ui-tailwind/index.js +0 -575
  383. package/dist/ui-tailwind/index.js.map +0 -1
@@ -0,0 +1,952 @@
1
+ import type {
2
+ BlockNode,
3
+ FootnoteCollection,
4
+ FootnoteDefinition,
5
+ InlineNode,
6
+ ParagraphIndentation,
7
+ ParagraphNode,
8
+ ParagraphSpacing,
9
+ TableCellNode,
10
+ TableNode,
11
+ TableRowNode,
12
+ TextMark,
13
+ } from "../../model/canonical-document.ts";
14
+ import {
15
+ readCellBorders,
16
+ readCellShading,
17
+ readCellVerticalAlign,
18
+ readCellWidth,
19
+ readGridColumns as readSharedGridColumns,
20
+ readRowHeight,
21
+ readRowHeightRule,
22
+ readRowIsHeader,
23
+ readTableAlignment,
24
+ readTableBorders,
25
+ readTableCellMargins,
26
+ readTableLook,
27
+ readTableStyleId,
28
+ readTableWidth,
29
+ } from "./parse-tables.ts";
30
+
31
+ // ---- XML node types (inline, no external dep) ----
32
+
33
+ interface XmlElementNode {
34
+ type: "element";
35
+ name: string;
36
+ attributes: Record<string, string>;
37
+ children: XmlNode[];
38
+ start: number;
39
+ end: number;
40
+ }
41
+
42
+ interface XmlTextNode {
43
+ type: "text";
44
+ text: string;
45
+ start: number;
46
+ end: number;
47
+ }
48
+
49
+ type XmlNode = XmlElementNode | XmlTextNode;
50
+
51
+ // ---- Special footnote/endnote IDs to skip ----
52
+
53
+ const SPECIAL_NOTE_IDS = new Set(["-1", "0"]);
54
+ const SPECIAL_NOTE_TYPES = new Set(["separator", "continuationSeparator"]);
55
+
56
+ // ---- Public API ----
57
+
58
+ /**
59
+ * Parse footnotes.xml (<w:footnotes> root) into a FootnoteCollection.
60
+ * Also accepts endnotes.xml (<w:endnotes> root).
61
+ */
62
+ export function parseFootnotesXml(xml: string): FootnoteCollection {
63
+ const root = parseXml(xml);
64
+
65
+ const footnotesElement = findChildElementOptional(root, "footnotes");
66
+ const endnotesElement = findChildElementOptional(root, "endnotes");
67
+
68
+ const footnotes: Record<string, FootnoteDefinition> = {};
69
+ const endnotes: Record<string, FootnoteDefinition> = {};
70
+
71
+ if (footnotesElement) {
72
+ for (const child of footnotesElement.children) {
73
+ if (child.type !== "element") {
74
+ continue;
75
+ }
76
+ if (localName(child.name) !== "footnote") {
77
+ continue;
78
+ }
79
+ const definition = parseNoteElement(child, "footnote");
80
+ if (definition) {
81
+ footnotes[definition.noteId] = definition;
82
+ }
83
+ }
84
+ }
85
+
86
+ if (endnotesElement) {
87
+ for (const child of endnotesElement.children) {
88
+ if (child.type !== "element") {
89
+ continue;
90
+ }
91
+ if (localName(child.name) !== "endnote") {
92
+ continue;
93
+ }
94
+ const definition = parseNoteElement(child, "endnote");
95
+ if (definition) {
96
+ endnotes[definition.noteId] = definition;
97
+ }
98
+ }
99
+ }
100
+
101
+ return { footnotes, endnotes };
102
+ }
103
+
104
+ /**
105
+ * Parse a standalone endnotes.xml (<w:endnotes> root).
106
+ * Merges into the provided collection or creates a new one.
107
+ */
108
+ export function parseEndnotesXml(
109
+ xml: string,
110
+ existing?: FootnoteCollection,
111
+ ): FootnoteCollection {
112
+ const root = parseXml(xml);
113
+ const endnotesElement = findChildElementOptional(root, "endnotes");
114
+ const endnotes: Record<string, FootnoteDefinition> = {
115
+ ...(existing?.endnotes ?? {}),
116
+ };
117
+
118
+ if (endnotesElement) {
119
+ for (const child of endnotesElement.children) {
120
+ if (child.type !== "element") {
121
+ continue;
122
+ }
123
+ if (localName(child.name) !== "endnote") {
124
+ continue;
125
+ }
126
+ const definition = parseNoteElement(child, "endnote");
127
+ if (definition) {
128
+ endnotes[definition.noteId] = definition;
129
+ }
130
+ }
131
+ }
132
+
133
+ return {
134
+ footnotes: existing?.footnotes ?? {},
135
+ endnotes,
136
+ };
137
+ }
138
+
139
+ // ---- Internal helpers ----
140
+
141
+ function parseNoteElement(
142
+ element: XmlElementNode,
143
+ kind: "footnote" | "endnote",
144
+ ): FootnoteDefinition | undefined {
145
+ const rawId =
146
+ element.attributes["w:id"] ?? element.attributes.id ?? "";
147
+ const rawType =
148
+ element.attributes["w:type"] ?? element.attributes.type ?? "";
149
+
150
+ if (!rawId || SPECIAL_NOTE_IDS.has(rawId) || SPECIAL_NOTE_TYPES.has(rawType)) {
151
+ return undefined;
152
+ }
153
+
154
+ const noteId = rawId;
155
+ const blocks: BlockNode[] = [];
156
+
157
+ for (const child of element.children) {
158
+ if (child.type !== "element") {
159
+ continue;
160
+ }
161
+ const name = localName(child.name);
162
+ if (name === "p") {
163
+ blocks.push(parseParagraphElement(child));
164
+ } else if (name === "tbl") {
165
+ // Simple tables (no revisions, fields, or nested tables) are promoted
166
+ // to supported-roundtrip; structurally risky tables stay opaque.
167
+ if (isSimpleSecondaryStoryTable(child)) {
168
+ blocks.push(parseSimpleTableElement(child));
169
+ } else {
170
+ blocks.push({
171
+ type: "opaque_block",
172
+ fragmentId: `fragment:note-tbl-${noteId}`,
173
+ warningId: `warning:note-opaque-table`,
174
+ rawXml: serializeElementToXml(child),
175
+ });
176
+ }
177
+ } else {
178
+ blocks.push({
179
+ type: "opaque_block",
180
+ fragmentId: `fragment:note-opaque-${noteId}`,
181
+ warningId: `warning:note-opaque-block`,
182
+ rawXml: serializeElementToXml(child),
183
+ });
184
+ }
185
+ }
186
+
187
+ return { noteId, kind, blocks };
188
+ }
189
+
190
+ function parseParagraphElement(pElement: XmlElementNode): ParagraphNode {
191
+ let styleId: string | undefined;
192
+ let alignment: ParagraphNode["alignment"];
193
+ let spacing: ParagraphNode["spacing"];
194
+ let indentation: ParagraphNode["indentation"];
195
+ const children: InlineNode[] = [];
196
+ let activeComplexField: {
197
+ instruction: string;
198
+ children: InlineNode[];
199
+ mode: "instruction" | "result";
200
+ } | null = null;
201
+
202
+ for (const child of pElement.children) {
203
+ if (child.type !== "element") {
204
+ continue;
205
+ }
206
+
207
+ const name = localName(child.name);
208
+
209
+ if (name === "pPr") {
210
+ const pStyle = findChildElementOptional(child, "pStyle");
211
+ styleId = pStyle?.attributes["w:val"] ?? pStyle?.attributes.val;
212
+ const jc = findChildElementOptional(child, "jc");
213
+ const jcVal = jc?.attributes["w:val"] ?? jc?.attributes.val;
214
+ if (jcVal === "left" || jcVal === "center" || jcVal === "right" || jcVal === "both" || jcVal === "distribute") {
215
+ alignment = jcVal;
216
+ }
217
+ spacing = readParagraphSpacing(child);
218
+ indentation = readParagraphIndentation(child);
219
+ } else if (name === "r") {
220
+ activeComplexField = appendRunNodes(child, children, activeComplexField);
221
+ } else if (name === "hyperlink") {
222
+ if (activeComplexField && activeComplexField.instruction.trim().length > 0) {
223
+ children.push({
224
+ type: "field",
225
+ fieldType: "complex",
226
+ instruction: activeComplexField.instruction,
227
+ children: activeComplexField.children,
228
+ });
229
+ activeComplexField = null;
230
+ }
231
+ children.push(parseHyperlinkElement(child));
232
+ } else if (name === "bookmarkStart" || name === "bookmarkEnd") {
233
+ const bookmarkNode = parseBookmarkElement(child);
234
+ if (activeComplexField?.mode === "result") {
235
+ activeComplexField.children.push(bookmarkNode);
236
+ } else {
237
+ if (activeComplexField && activeComplexField.instruction.trim().length > 0) {
238
+ children.push({
239
+ type: "field",
240
+ fieldType: "complex",
241
+ instruction: activeComplexField.instruction,
242
+ children: activeComplexField.children,
243
+ });
244
+ activeComplexField = null;
245
+ }
246
+ children.push(bookmarkNode);
247
+ }
248
+ } else if (name === "fldSimple") {
249
+ if (activeComplexField && activeComplexField.instruction.trim().length > 0) {
250
+ children.push({
251
+ type: "field",
252
+ fieldType: "complex",
253
+ instruction: activeComplexField.instruction,
254
+ children: activeComplexField.children,
255
+ });
256
+ activeComplexField = null;
257
+ }
258
+ pushFieldNode(children, child, "simple");
259
+ }
260
+ }
261
+
262
+ if (activeComplexField && activeComplexField.instruction.trim().length > 0) {
263
+ children.push({
264
+ type: "field",
265
+ fieldType: "complex",
266
+ instruction: activeComplexField.instruction,
267
+ children: activeComplexField.children,
268
+ });
269
+ }
270
+
271
+ return {
272
+ type: "paragraph",
273
+ ...(styleId ? { styleId } : {}),
274
+ ...(alignment ? { alignment } : {}),
275
+ ...(spacing ? { spacing } : {}),
276
+ ...(indentation ? { indentation } : {}),
277
+ children,
278
+ };
279
+ }
280
+
281
+ function appendRunNodes(
282
+ rElement: XmlElementNode,
283
+ nodes: InlineNode[],
284
+ activeComplexField: {
285
+ instruction: string;
286
+ children: InlineNode[];
287
+ mode: "instruction" | "result";
288
+ } | null,
289
+ ): {
290
+ instruction: string;
291
+ children: InlineNode[];
292
+ mode: "instruction" | "result";
293
+ } | null {
294
+ const marks: TextMark[] = parseRunProperties(rElement);
295
+
296
+ for (const child of rElement.children) {
297
+ if (child.type !== "element") {
298
+ continue;
299
+ }
300
+
301
+ const name = localName(child.name);
302
+ if (name === "fldChar") {
303
+ const fldType = child.attributes["w:fldCharType"] ?? child.attributes.fldCharType;
304
+ if (fldType === "begin") {
305
+ activeComplexField = { instruction: "", children: [], mode: "instruction" };
306
+ } else if (fldType === "separate" && activeComplexField) {
307
+ activeComplexField.mode = "result";
308
+ } else if (fldType === "end" && activeComplexField) {
309
+ if (activeComplexField.instruction.trim().length > 0) {
310
+ nodes.push({
311
+ type: "field",
312
+ fieldType: "complex",
313
+ instruction: activeComplexField.instruction,
314
+ children: activeComplexField.children,
315
+ });
316
+ }
317
+ activeComplexField = null;
318
+ }
319
+ continue;
320
+ }
321
+
322
+ if (name === "instrText") {
323
+ if (activeComplexField) {
324
+ activeComplexField.instruction += extractTextContent(child);
325
+ } else {
326
+ pushFieldNode(nodes, child, "complex");
327
+ }
328
+ continue;
329
+ }
330
+
331
+ const inlineNode = parseRunChildNode(child, marks);
332
+ if (!inlineNode) {
333
+ continue;
334
+ }
335
+
336
+ if (activeComplexField?.mode === "result") {
337
+ activeComplexField.children.push(inlineNode);
338
+ continue;
339
+ }
340
+
341
+ nodes.push(inlineNode);
342
+ }
343
+
344
+ return activeComplexField;
345
+ }
346
+
347
+ function parseRunElement(rElement: XmlElementNode): InlineNode[] {
348
+ const nodes: InlineNode[] = [];
349
+ const marks: TextMark[] = parseRunProperties(rElement);
350
+
351
+ for (const child of rElement.children) {
352
+ if (child.type !== "element") {
353
+ continue;
354
+ }
355
+
356
+ const name = localName(child.name);
357
+
358
+ if (name === "t") {
359
+ const text = extractTextContent(child);
360
+ if (text.length > 0) {
361
+ nodes.push({
362
+ type: "text",
363
+ text,
364
+ ...(marks.length > 0 ? { marks } : {}),
365
+ });
366
+ }
367
+ } else if (name === "br") {
368
+ nodes.push({ type: "hard_break" });
369
+ } else if (name === "tab") {
370
+ nodes.push({ type: "tab" });
371
+ } else if (name === "footnoteRef" || name === "endnoteRef") {
372
+ // The in-note reference marker (superscript) - skip, rendered by the host
373
+ } else if (name === "footnoteReference") {
374
+ const noteId =
375
+ child.attributes["w:id"] ?? child.attributes.id ?? "";
376
+ if (noteId) {
377
+ nodes.push({ type: "footnote_ref", noteId, noteKind: "footnote" });
378
+ }
379
+ } else if (name === "endnoteReference") {
380
+ const noteId =
381
+ child.attributes["w:id"] ?? child.attributes.id ?? "";
382
+ if (noteId) {
383
+ nodes.push({ type: "footnote_ref", noteId, noteKind: "endnote" });
384
+ }
385
+ } else if (name === "bookmarkStart" || name === "bookmarkEnd") {
386
+ nodes.push(parseBookmarkElement(child));
387
+ } else if (name === "instrText") {
388
+ pushFieldNode(nodes, child, "complex");
389
+ }
390
+ }
391
+
392
+ return nodes;
393
+ }
394
+
395
+ function parseRunChildNode(
396
+ child: XmlElementNode,
397
+ marks: TextMark[],
398
+ ): InlineNode | null {
399
+ const name = localName(child.name);
400
+
401
+ if (name === "t") {
402
+ const text = extractTextContent(child);
403
+ if (text.length > 0) {
404
+ return {
405
+ type: "text",
406
+ text,
407
+ ...(marks.length > 0 ? { marks } : {}),
408
+ };
409
+ }
410
+ return null;
411
+ }
412
+ if (name === "br") {
413
+ return { type: "hard_break" };
414
+ }
415
+ if (name === "tab") {
416
+ return { type: "tab" };
417
+ }
418
+ if (name === "footnoteReference") {
419
+ const noteId =
420
+ child.attributes["w:id"] ?? child.attributes.id ?? "";
421
+ if (noteId) {
422
+ return { type: "footnote_ref", noteId, noteKind: "footnote" };
423
+ }
424
+ return null;
425
+ }
426
+ if (name === "endnoteReference") {
427
+ const noteId =
428
+ child.attributes["w:id"] ?? child.attributes.id ?? "";
429
+ if (noteId) {
430
+ return { type: "footnote_ref", noteId, noteKind: "endnote" };
431
+ }
432
+ return null;
433
+ }
434
+ if (name === "bookmarkStart" || name === "bookmarkEnd") {
435
+ return parseBookmarkElement(child);
436
+ }
437
+
438
+ return null;
439
+ }
440
+
441
+ function parseHyperlinkElement(element: XmlElementNode): Extract<InlineNode, { type: "hyperlink" }> {
442
+ const href = element.attributes["w:anchor"]
443
+ ? `#${element.attributes["w:anchor"]}`
444
+ : element.attributes["r:id"] ?? "relationship:unknown";
445
+ const children: Array<Extract<InlineNode, { type: "text" | "hard_break" | "tab" }>> = [];
446
+
447
+ for (const child of element.children) {
448
+ if (child.type === "element" && localName(child.name) === "r") {
449
+ for (const runChild of parseRunElement(child)) {
450
+ if (runChild.type === "text" || runChild.type === "hard_break" || runChild.type === "tab") {
451
+ children.push(runChild);
452
+ }
453
+ }
454
+ }
455
+ }
456
+
457
+ return {
458
+ type: "hyperlink",
459
+ href,
460
+ children,
461
+ };
462
+ }
463
+
464
+ function parseBookmarkElement(
465
+ element: XmlElementNode,
466
+ ): Extract<InlineNode, { type: "bookmark_start" | "bookmark_end" }> {
467
+ const bookmarkId = element.attributes["w:id"] ?? element.attributes.id ?? "0";
468
+ if (localName(element.name) === "bookmarkStart") {
469
+ return {
470
+ type: "bookmark_start",
471
+ bookmarkId,
472
+ name: element.attributes["w:name"] ?? element.attributes.name ?? "",
473
+ };
474
+ }
475
+
476
+ return {
477
+ type: "bookmark_end",
478
+ bookmarkId,
479
+ };
480
+ }
481
+
482
+ function pushFieldNode(
483
+ nodes: InlineNode[],
484
+ element: XmlElementNode,
485
+ fieldType: "simple" | "complex",
486
+ ): void {
487
+ const instruction = readFieldInstruction(element);
488
+ if (!instruction) {
489
+ return;
490
+ }
491
+
492
+ nodes.push({
493
+ type: "field",
494
+ fieldType,
495
+ instruction,
496
+ children: [],
497
+ });
498
+ }
499
+
500
+ function readFieldInstruction(element: XmlElementNode): string | undefined {
501
+ const instruction =
502
+ element.attributes["w:instr"] ??
503
+ element.attributes.instr ??
504
+ extractTextContent(element);
505
+ return instruction.trim().length > 0 ? instruction : undefined;
506
+ }
507
+
508
+ function parseRunProperties(rElement: XmlElementNode): TextMark[] {
509
+ const rPr = findChildElementOptional(rElement, "rPr");
510
+ if (!rPr) {
511
+ return [];
512
+ }
513
+
514
+ const marks: TextMark[] = [];
515
+
516
+ for (const child of rPr.children) {
517
+ if (child.type !== "element") {
518
+ continue;
519
+ }
520
+
521
+ const name = localName(child.name);
522
+ const val = child.attributes["w:val"] ?? child.attributes.val ?? "true";
523
+
524
+ switch (name) {
525
+ case "b":
526
+ if (val !== "0" && val !== "false") marks.push({ type: "bold" });
527
+ break;
528
+ case "i":
529
+ if (val !== "0" && val !== "false") marks.push({ type: "italic" });
530
+ break;
531
+ case "u":
532
+ if (val !== "none" && val !== "0") marks.push({ type: "underline" });
533
+ break;
534
+ case "strike":
535
+ if (val !== "0" && val !== "false") marks.push({ type: "strikethrough" });
536
+ break;
537
+ case "dstrike":
538
+ if (val !== "0" && val !== "false") marks.push({ type: "doubleStrikethrough" });
539
+ break;
540
+ case "rFonts": {
541
+ const family =
542
+ child.attributes["w:ascii"] ??
543
+ child.attributes["w:hAnsi"] ??
544
+ child.attributes.ascii ??
545
+ child.attributes.hAnsi;
546
+ if (family) marks.push({ type: "fontFamily", val: family });
547
+ break;
548
+ }
549
+ case "sz": {
550
+ const szVal = child.attributes["w:val"] ?? child.attributes.val;
551
+ if (szVal) {
552
+ const size = Number.parseInt(szVal, 10);
553
+ if (Number.isFinite(size) && size > 0) marks.push({ type: "fontSize", val: size });
554
+ }
555
+ break;
556
+ }
557
+ case "color": {
558
+ const colorVal = child.attributes["w:val"] ?? child.attributes.val;
559
+ if (colorVal && colorVal !== "auto") marks.push({ type: "textColor", color: colorVal });
560
+ break;
561
+ }
562
+ case "smallCaps":
563
+ if (val !== "0" && val !== "false") marks.push({ type: "smallCaps" });
564
+ break;
565
+ case "caps":
566
+ if (val !== "0" && val !== "false") marks.push({ type: "allCaps" });
567
+ break;
568
+ }
569
+ }
570
+
571
+ return marks;
572
+ }
573
+
574
+ function readParagraphSpacing(pPr: XmlElementNode): ParagraphSpacing | undefined {
575
+ const spacingNode = findChildElementOptional(pPr, "spacing");
576
+ if (!spacingNode) return undefined;
577
+ const result: ParagraphSpacing = {};
578
+ const before = spacingNode.attributes["w:before"] ?? spacingNode.attributes.before;
579
+ if (before) result.before = Number.parseInt(before, 10);
580
+ const after = spacingNode.attributes["w:after"] ?? spacingNode.attributes.after;
581
+ if (after) result.after = Number.parseInt(after, 10);
582
+ const line = spacingNode.attributes["w:line"] ?? spacingNode.attributes.line;
583
+ if (line) result.line = Number.parseInt(line, 10);
584
+ const lineRule = spacingNode.attributes["w:lineRule"] ?? spacingNode.attributes.lineRule;
585
+ if (lineRule === "auto" || lineRule === "exact" || lineRule === "atLeast") {
586
+ result.lineRule = lineRule;
587
+ }
588
+ return Object.keys(result).length > 0 ? result : undefined;
589
+ }
590
+
591
+ function readParagraphIndentation(pPr: XmlElementNode): ParagraphIndentation | undefined {
592
+ const indNode = findChildElementOptional(pPr, "ind");
593
+ if (!indNode) return undefined;
594
+ const result: ParagraphIndentation = {};
595
+ const left = indNode.attributes["w:left"] ?? indNode.attributes.left;
596
+ if (left) result.left = Number.parseInt(left, 10);
597
+ const right = indNode.attributes["w:right"] ?? indNode.attributes.right;
598
+ if (right) result.right = Number.parseInt(right, 10);
599
+ const firstLine = indNode.attributes["w:firstLine"] ?? indNode.attributes.firstLine;
600
+ if (firstLine) result.firstLine = Number.parseInt(firstLine, 10);
601
+ const hanging = indNode.attributes["w:hanging"] ?? indNode.attributes.hanging;
602
+ if (hanging) result.hanging = Number.parseInt(hanging, 10);
603
+ return Object.keys(result).length > 0 ? result : undefined;
604
+ }
605
+
606
+ function extractTextContent(tElement: XmlElementNode): string {
607
+ let text = "";
608
+ for (const child of tElement.children) {
609
+ if (child.type === "text") {
610
+ text += child.text;
611
+ }
612
+ }
613
+ return text;
614
+ }
615
+
616
+ function findChildElementOptional(
617
+ node: XmlElementNode,
618
+ childLocalName: string,
619
+ ): XmlElementNode | undefined {
620
+ return node.children.find(
621
+ (entry): entry is XmlElementNode =>
622
+ entry.type === "element" && localName(entry.name) === childLocalName,
623
+ );
624
+ }
625
+
626
+ function localName(name: string): string {
627
+ const idx = name.indexOf(":");
628
+ return idx >= 0 ? name.slice(idx + 1) : name;
629
+ }
630
+
631
+ // ---- Simple secondary-story table support ----
632
+
633
+ const RISKY_TABLE_ELEMENT_NAMES = new Set([
634
+ "ins",
635
+ "del",
636
+ "moveFrom",
637
+ "moveTo",
638
+ "tblPrChange",
639
+ "trPrChange",
640
+ "tcPrChange",
641
+ "rPrChange",
642
+ "pPrChange",
643
+ "sectPrChange",
644
+ "fldSimple",
645
+ "fldChar",
646
+ "instrText",
647
+ "sdt",
648
+ "customXml",
649
+ ]);
650
+
651
+ function isSimpleSecondaryStoryTable(tblElement: XmlElementNode): boolean {
652
+ return !containsRiskyElement(tblElement);
653
+ }
654
+
655
+ function containsRiskyElement(element: XmlElementNode): boolean {
656
+ for (const child of element.children) {
657
+ if (child.type !== "element") {
658
+ continue;
659
+ }
660
+ const name = localName(child.name);
661
+ if (RISKY_TABLE_ELEMENT_NAMES.has(name)) {
662
+ return true;
663
+ }
664
+ if (name === "tbl") {
665
+ return true;
666
+ }
667
+ if (containsRiskyElement(child)) {
668
+ return true;
669
+ }
670
+ }
671
+ return false;
672
+ }
673
+
674
+ function parseSimpleTableElement(tblElement: XmlElementNode): TableNode {
675
+ let gridColumns: number[] = [];
676
+ const rows: TableRowNode[] = [];
677
+ let propertiesXml: string | undefined;
678
+ let styleId: string | undefined;
679
+ let width: TableNode["width"];
680
+ let alignment: TableNode["alignment"];
681
+ let borders: TableNode["borders"];
682
+ let cellMargins: TableNode["cellMargins"];
683
+ let tblLook: TableNode["tblLook"];
684
+
685
+ for (const child of tblElement.children) {
686
+ if (child.type !== "element") continue;
687
+ const name = localName(child.name);
688
+
689
+ if (name === "tblPr") {
690
+ propertiesXml = serializeElementToXml(child);
691
+ styleId = readTableStyleId(child);
692
+ width = readTableWidth(child);
693
+ alignment = readTableAlignment(child);
694
+ borders = readTableBorders(child);
695
+ cellMargins = readTableCellMargins(child);
696
+ tblLook = readTableLook(child);
697
+ } else if (name === "tblGrid") {
698
+ gridColumns = readGridColumns(child);
699
+ } else if (name === "tr") {
700
+ rows.push(parseSimpleTableRow(child));
701
+ }
702
+ }
703
+
704
+ return {
705
+ type: "table",
706
+ ...(styleId ? { styleId } : {}),
707
+ ...(propertiesXml ? { propertiesXml } : {}),
708
+ gridColumns,
709
+ rows,
710
+ ...(width ? { width } : {}),
711
+ ...(alignment ? { alignment } : {}),
712
+ ...(borders ? { borders } : {}),
713
+ ...(cellMargins ? { cellMargins } : {}),
714
+ ...(tblLook ? { tblLook } : {}),
715
+ };
716
+ }
717
+
718
+ function readGridColumns(tblGrid: XmlElementNode): number[] {
719
+ return readSharedGridColumns(tblGrid);
720
+ }
721
+
722
+ function parseSimpleTableRow(trElement: XmlElementNode): TableRowNode {
723
+ const cells: TableCellNode[] = [];
724
+ let propertiesXml: string | undefined;
725
+ let height: TableRowNode["height"];
726
+ let heightRule: TableRowNode["heightRule"];
727
+ let isHeader: TableRowNode["isHeader"];
728
+
729
+ for (const child of trElement.children) {
730
+ if (child.type !== "element") continue;
731
+ const name = localName(child.name);
732
+
733
+ if (name === "trPr") {
734
+ propertiesXml = serializeElementToXml(child);
735
+ height = readRowHeight(child);
736
+ heightRule = readRowHeightRule(child);
737
+ isHeader = readRowIsHeader(child);
738
+ } else if (name === "tc") {
739
+ cells.push(parseSimpleTableCell(child));
740
+ }
741
+ }
742
+
743
+ return {
744
+ type: "table_row",
745
+ ...(propertiesXml ? { propertiesXml } : {}),
746
+ ...(height !== undefined ? { height } : {}),
747
+ ...(heightRule ? { heightRule } : {}),
748
+ ...(isHeader !== undefined ? { isHeader } : {}),
749
+ cells,
750
+ };
751
+ }
752
+
753
+ function parseSimpleTableCell(tcElement: XmlElementNode): TableCellNode {
754
+ const children: BlockNode[] = [];
755
+ let propertiesXml: string | undefined;
756
+ let gridSpan: number | undefined;
757
+ let verticalMerge: "restart" | "continue" | undefined;
758
+ let width: TableCellNode["width"];
759
+ let borders: TableCellNode["borders"];
760
+ let shading: TableCellNode["shading"];
761
+ let verticalAlign: TableCellNode["verticalAlign"];
762
+
763
+ for (const child of tcElement.children) {
764
+ if (child.type !== "element") continue;
765
+ const name = localName(child.name);
766
+
767
+ if (name === "tcPr") {
768
+ propertiesXml = serializeElementToXml(child);
769
+ const gsEl = findChildElementOptional(child, "gridSpan");
770
+ const gsVal = gsEl?.attributes["w:val"] ?? gsEl?.attributes.val;
771
+ if (gsVal) gridSpan = Number.parseInt(gsVal, 10) || undefined;
772
+
773
+ const vmEl = findChildElementOptional(child, "vMerge");
774
+ if (vmEl) {
775
+ const vmVal = vmEl.attributes["w:val"] ?? vmEl.attributes.val ?? "continue";
776
+ verticalMerge = vmVal === "restart" ? "restart" : "continue";
777
+ }
778
+ width = readCellWidth(child);
779
+ borders = readCellBorders(child);
780
+ shading = readCellShading(child);
781
+ verticalAlign = readCellVerticalAlign(child);
782
+ } else if (name === "p") {
783
+ children.push(parseParagraphElement(child));
784
+ }
785
+ }
786
+
787
+ return {
788
+ type: "table_cell",
789
+ ...(propertiesXml ? { propertiesXml } : {}),
790
+ ...(gridSpan ? { gridSpan } : {}),
791
+ ...(verticalMerge ? { verticalMerge } : {}),
792
+ ...(width ? { width } : {}),
793
+ ...(borders ? { borders } : {}),
794
+ ...(shading ? { shading } : {}),
795
+ ...(verticalAlign ? { verticalAlign } : {}),
796
+ children: children.length > 0 ? children : [{ type: "paragraph", children: [] }],
797
+ };
798
+ }
799
+
800
+ function serializeElementToXml(element: XmlElementNode): string {
801
+ const attrs = Object.entries(element.attributes)
802
+ .map(([key, value]) => ` ${key}="${escapeXmlAttribute(value)}"`)
803
+ .join("");
804
+ const children = element.children
805
+ .map((child) => {
806
+ if (child.type === "text") {
807
+ return escapeXmlText(child.text);
808
+ }
809
+ return serializeElementToXml(child);
810
+ })
811
+ .join("");
812
+ if (children.length === 0) {
813
+ return `<${element.name}${attrs}/>`;
814
+ }
815
+ return `<${element.name}${attrs}>${children}</${element.name}>`;
816
+ }
817
+
818
+ function escapeXmlAttribute(text: string): string {
819
+ return text
820
+ .replace(/&/g, "&amp;")
821
+ .replace(/"/g, "&quot;")
822
+ .replace(/</g, "&lt;")
823
+ .replace(/>/g, "&gt;");
824
+ }
825
+
826
+ function escapeXmlText(text: string): string {
827
+ return text
828
+ .replace(/&/g, "&amp;")
829
+ .replace(/</g, "&lt;")
830
+ .replace(/>/g, "&gt;");
831
+ }
832
+
833
+ // ---- Minimal XML parser (same pattern as parse-numbering.ts) ----
834
+
835
+ function parseXml(xml: string): XmlElementNode {
836
+ const root: XmlElementNode = {
837
+ type: "element",
838
+ name: "__root__",
839
+ attributes: {},
840
+ children: [],
841
+ start: 0,
842
+ end: xml.length,
843
+ };
844
+ const stack: XmlElementNode[] = [root];
845
+ let cursor = 0;
846
+
847
+ while (cursor < xml.length) {
848
+ if (xml.startsWith("<!--", cursor)) {
849
+ const end = xml.indexOf("-->", cursor);
850
+ cursor = end >= 0 ? end + 3 : xml.length;
851
+ continue;
852
+ }
853
+
854
+ if (xml.startsWith("<?", cursor)) {
855
+ const end = xml.indexOf("?>", cursor);
856
+ cursor = end >= 0 ? end + 2 : xml.length;
857
+ continue;
858
+ }
859
+
860
+ if (xml.startsWith("<![CDATA[", cursor)) {
861
+ const end = xml.indexOf("]]>", cursor);
862
+ const textEnd = end >= 0 ? end : xml.length;
863
+ stack[stack.length - 1]?.children.push({
864
+ type: "text",
865
+ text: xml.slice(cursor + 9, textEnd),
866
+ start: cursor,
867
+ end: end >= 0 ? end + 3 : xml.length,
868
+ });
869
+ cursor = end >= 0 ? end + 3 : xml.length;
870
+ continue;
871
+ }
872
+
873
+ if (xml[cursor] !== "<") {
874
+ const nextTag = xml.indexOf("<", cursor);
875
+ const end = nextTag >= 0 ? nextTag : xml.length;
876
+ const text = decodeXmlEntities(xml.slice(cursor, end));
877
+ if (text.trim().length > 0 || (text.length > 0 && stack.length > 1)) {
878
+ stack[stack.length - 1]?.children.push({ type: "text", text, start: cursor, end });
879
+ }
880
+ cursor = end;
881
+ continue;
882
+ }
883
+
884
+ if (xml[cursor + 1] === "/") {
885
+ const end = xml.indexOf(">", cursor);
886
+ if (end < 0) break;
887
+ const current = stack.pop();
888
+ if (current) {
889
+ current.end = end + 1;
890
+ }
891
+ cursor = end + 1;
892
+ continue;
893
+ }
894
+
895
+ const tagEnd = xml.indexOf(">", cursor);
896
+ if (tagEnd < 0) break;
897
+
898
+ const tagContent = xml.slice(cursor + 1, tagEnd);
899
+ const selfClosing = tagContent.endsWith("/");
900
+ const normalized = selfClosing ? tagContent.slice(0, -1).trimEnd() : tagContent;
901
+
902
+ const spaceIndex = normalized.search(/\s/);
903
+ const tagName = spaceIndex >= 0 ? normalized.slice(0, spaceIndex) : normalized;
904
+ const attrString = spaceIndex >= 0 ? normalized.slice(spaceIndex + 1) : "";
905
+ const attributes = parseAttributes(attrString);
906
+
907
+ const element: XmlElementNode = {
908
+ type: "element",
909
+ name: tagName,
910
+ attributes,
911
+ children: [],
912
+ start: cursor,
913
+ end: tagEnd + 1,
914
+ };
915
+
916
+ stack[stack.length - 1]?.children.push(element);
917
+
918
+ if (!selfClosing) {
919
+ stack.push(element);
920
+ }
921
+
922
+ cursor = tagEnd + 1;
923
+ }
924
+
925
+ return root;
926
+ }
927
+
928
+ function parseAttributes(attrString: string): Record<string, string> {
929
+ const attrs: Record<string, string> = {};
930
+ const pattern = /([A-Za-z_:][A-Za-z0-9:._-]*)\s*=\s*("([^"]*)"|'([^']*)')/gu;
931
+ for (const match of attrString.matchAll(pattern)) {
932
+ const name = match[1];
933
+ const value = match[3] ?? match[4] ?? "";
934
+ if (name) {
935
+ attrs[name] = decodeXmlEntities(value);
936
+ }
937
+ }
938
+ return attrs;
939
+ }
940
+
941
+ function decodeXmlEntities(text: string): string {
942
+ return text
943
+ .replace(/&amp;/g, "&")
944
+ .replace(/&lt;/g, "<")
945
+ .replace(/&gt;/g, ">")
946
+ .replace(/&quot;/g, '"')
947
+ .replace(/&apos;/g, "'")
948
+ .replace(/&#(\d+);/g, (_, dec) => String.fromCodePoint(Number.parseInt(dec, 10)))
949
+ .replace(/&#x([0-9a-fA-F]+);/g, (_, hex) =>
950
+ String.fromCodePoint(Number.parseInt(hex, 16)),
951
+ );
952
+ }