@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,1212 @@
1
+ import type {
2
+ BlockNode,
3
+ FootnoteRefNode,
4
+ HeaderFooterVariant,
5
+ InlineNode,
6
+ ParagraphIndentation,
7
+ ParagraphNode,
8
+ ParagraphSpacing,
9
+ TabStop,
10
+ TableCellNode,
11
+ TableNode,
12
+ TableRowNode,
13
+ TextMark,
14
+ } from "../../model/canonical-document.ts";
15
+ import { resolveHighlightColor } from "./highlight-colors.ts";
16
+ import { classifyFieldInstruction } from "./parse-fields.ts";
17
+ import {
18
+ readCellBorders,
19
+ readCellShading,
20
+ readCellVerticalAlign,
21
+ readCellWidth,
22
+ readGridColumns as readSharedGridColumns,
23
+ readRowHeight,
24
+ readRowHeightRule,
25
+ readRowIsHeader,
26
+ readTableAlignment,
27
+ readTableBorders,
28
+ readTableCellMargins,
29
+ readTableLook,
30
+ readTableStyleId,
31
+ readTableWidth,
32
+ } from "./parse-tables.ts";
33
+ import { parseShapeXml, parseVmlXml } from "./parse-shapes.ts";
34
+
35
+ // ---- Public types ----
36
+
37
+ export interface ParsedHeaderFooterReference {
38
+ variant: HeaderFooterVariant;
39
+ relationshipId: string;
40
+ kind: "header" | "footer";
41
+ sectionIndex?: number;
42
+ }
43
+
44
+ export interface ParsedHeaderFooterDocument {
45
+ blocks: BlockNode[];
46
+ }
47
+
48
+ // ---- XML node types (inline, no external dep) ----
49
+
50
+ interface XmlElementNode {
51
+ type: "element";
52
+ name: string;
53
+ attributes: Record<string, string>;
54
+ children: XmlNode[];
55
+ start: number;
56
+ end: number;
57
+ }
58
+
59
+ interface XmlTextNode {
60
+ type: "text";
61
+ text: string;
62
+ start: number;
63
+ end: number;
64
+ }
65
+
66
+ type XmlNode = XmlElementNode | XmlTextNode;
67
+
68
+ let currentSourceXml = "";
69
+
70
+ // ---- Public API ----
71
+
72
+ /**
73
+ * Scan a document body XML for w:headerReference / w:footerReference elements
74
+ * inside w:sectPr and return the relationship references.
75
+ */
76
+ export function parseHeaderFooterReferences(
77
+ documentXml: string,
78
+ ): ParsedHeaderFooterReference[] {
79
+ const root = parseXml(documentXml);
80
+ const documentElement = findChildElementOptional(root, "document");
81
+ if (!documentElement) {
82
+ return [];
83
+ }
84
+
85
+ const bodyElement = findChildElementOptional(documentElement, "body");
86
+ if (!bodyElement) {
87
+ return [];
88
+ }
89
+
90
+ const refs: ParsedHeaderFooterReference[] = [];
91
+
92
+ // Collect all sectPr elements (can appear in paragraph pPr and at body level)
93
+ collectSectPrReferences(bodyElement, refs);
94
+
95
+ return refs;
96
+ }
97
+
98
+ /**
99
+ * Parse a headerN.xml part (<w:hdr> root) into block nodes.
100
+ */
101
+ export function parseHeaderXml(xml: string): ParsedHeaderFooterDocument {
102
+ return parseHdrFtrXml(xml, "hdr");
103
+ }
104
+
105
+ /**
106
+ * Parse a footerN.xml part (<w:ftr> root) into block nodes.
107
+ */
108
+ export function parseFooterXml(xml: string): ParsedHeaderFooterDocument {
109
+ return parseHdrFtrXml(xml, "ftr");
110
+ }
111
+
112
+ // ---- Internal helpers ----
113
+
114
+ function collectSectPrReferences(
115
+ element: XmlElementNode,
116
+ refs: ParsedHeaderFooterReference[],
117
+ ): void {
118
+ let sectionIndex = 0;
119
+ for (const child of element.children) {
120
+ if (child.type !== "element") {
121
+ continue;
122
+ }
123
+
124
+ const name = localName(child.name);
125
+
126
+ if (name === "sectPr") {
127
+ // Body-level sectPr is the final section
128
+ extractSectPrRefs(child, refs, sectionIndex);
129
+ } else if (name === "p") {
130
+ // Check paragraph properties for sectPr (non-final section break)
131
+ const pPr = findChildElementOptional(child, "pPr");
132
+ if (pPr) {
133
+ const sectPr = findChildElementOptional(pPr, "sectPr");
134
+ if (sectPr) {
135
+ extractSectPrRefs(sectPr, refs, sectionIndex);
136
+ sectionIndex++;
137
+ }
138
+ }
139
+ }
140
+ }
141
+ }
142
+
143
+ function extractSectPrRefs(
144
+ sectPr: XmlElementNode,
145
+ refs: ParsedHeaderFooterReference[],
146
+ sectionIndex: number,
147
+ ): void {
148
+ for (const child of sectPr.children) {
149
+ if (child.type !== "element") {
150
+ continue;
151
+ }
152
+
153
+ const name = localName(child.name);
154
+ if (name === "headerReference" || name === "footerReference") {
155
+ const kind: "header" | "footer" = name === "headerReference" ? "header" : "footer";
156
+ const rawType =
157
+ child.attributes["w:type"] ?? child.attributes.type ?? "default";
158
+ const variant = toHeaderFooterVariant(rawType);
159
+ const relationshipId =
160
+ child.attributes["r:id"] ??
161
+ child.attributes["r:Id"] ??
162
+ child.attributes.id ??
163
+ child.attributes.Id ??
164
+ "";
165
+
166
+ if (relationshipId) {
167
+ // Avoid duplicates (multiple sectPr may reference same header)
168
+ const dedupeKey = `${kind}:${variant}:${relationshipId}`;
169
+ const alreadyAdded = refs.some(
170
+ (ref) => `${ref.kind}:${ref.variant}:${ref.relationshipId}` === dedupeKey,
171
+ );
172
+ if (!alreadyAdded) {
173
+ refs.push({ variant, relationshipId, kind, sectionIndex });
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
179
+
180
+ function toHeaderFooterVariant(raw: string): HeaderFooterVariant {
181
+ if (raw === "first") {
182
+ return "first";
183
+ }
184
+ if (raw === "even") {
185
+ return "even";
186
+ }
187
+ return "default";
188
+ }
189
+
190
+ function parseHdrFtrXml(
191
+ xml: string,
192
+ rootLocalName: "hdr" | "ftr",
193
+ ): ParsedHeaderFooterDocument {
194
+ const root = parseXml(xml);
195
+ const hdrFtrElement = findChildElementOptional(root, rootLocalName);
196
+ if (!hdrFtrElement) {
197
+ return { blocks: [] };
198
+ }
199
+
200
+ const blocks: BlockNode[] = [];
201
+
202
+ for (const child of hdrFtrElement.children) {
203
+ if (child.type !== "element") {
204
+ continue;
205
+ }
206
+
207
+ const name = localName(child.name);
208
+
209
+ if (name === "p") {
210
+ blocks.push(parseParagraphElement(child));
211
+ } else if (name === "tbl") {
212
+ // Simple tables (no revisions, fields, or nested tables) are promoted
213
+ // to supported-roundtrip; structurally risky tables stay opaque.
214
+ if (isSimpleSecondaryStoryTable(child)) {
215
+ blocks.push(parseSimpleTableElement(child));
216
+ } else {
217
+ blocks.push({
218
+ type: "opaque_block",
219
+ fragmentId: "fragment:hdrftr-tbl",
220
+ warningId: "warning:hdrftr-opaque-table",
221
+ rawXml: serializeElementToXml(child),
222
+ });
223
+ }
224
+ } else {
225
+ // Other block-level elements: treat as opaque
226
+ blocks.push({
227
+ type: "opaque_block",
228
+ fragmentId: "fragment:hdrftr-opaque",
229
+ warningId: "warning:hdrftr-opaque-block",
230
+ rawXml: serializeElementToXml(child),
231
+ });
232
+ }
233
+ }
234
+
235
+ return { blocks };
236
+ }
237
+
238
+ function parseParagraphElement(pElement: XmlElementNode): ParagraphNode {
239
+ let styleId: string | undefined;
240
+ let alignment: ParagraphNode["alignment"];
241
+ let spacing: ParagraphNode["spacing"];
242
+ let indentation: ParagraphNode["indentation"];
243
+ let tabStops: ParagraphNode["tabStops"];
244
+ const children: InlineNode[] = [];
245
+ let activeComplexField: {
246
+ instruction: string;
247
+ children: Array<Extract<InlineNode, { type: "text" | "hard_break" | "tab" }>>;
248
+ mode: "instruction" | "result";
249
+ } | null = null;
250
+
251
+ for (const child of pElement.children) {
252
+ if (child.type !== "element") {
253
+ continue;
254
+ }
255
+
256
+ const name = localName(child.name);
257
+
258
+ if (name === "pPr") {
259
+ const pStyle = findChildElementOptional(child, "pStyle");
260
+ styleId = pStyle?.attributes["w:val"] ?? pStyle?.attributes.val;
261
+ const jc = findChildElementOptional(child, "jc");
262
+ const jcVal = jc?.attributes["w:val"] ?? jc?.attributes.val;
263
+ if (jcVal === "left" || jcVal === "center" || jcVal === "right" || jcVal === "both" || jcVal === "distribute") {
264
+ alignment = jcVal;
265
+ }
266
+ spacing = readParagraphSpacing(child);
267
+ indentation = readParagraphIndentation(child);
268
+ tabStops = readParagraphTabStops(child);
269
+ } else if (name === "r") {
270
+ activeComplexField = appendRunNodes(child, children, activeComplexField);
271
+ } else if (name === "hyperlink") {
272
+ children.push(parseHyperlinkElement(child));
273
+ } else if (name === "bookmarkStart" || name === "bookmarkEnd") {
274
+ children.push(parseBookmarkElement(child));
275
+ } else if (name === "fldSimple") {
276
+ if (activeComplexField && activeComplexField.instruction.trim().length > 0) {
277
+ children.push({
278
+ type: "field",
279
+ fieldType: "complex",
280
+ instruction: activeComplexField.instruction,
281
+ children: activeComplexField.children,
282
+ });
283
+ activeComplexField = null;
284
+ }
285
+ pushFieldNode(children, child, "simple");
286
+ }
287
+ }
288
+
289
+ if (activeComplexField && activeComplexField.instruction.trim().length > 0) {
290
+ children.push({
291
+ type: "field",
292
+ fieldType: "complex",
293
+ instruction: activeComplexField.instruction,
294
+ children: activeComplexField.children,
295
+ });
296
+ }
297
+
298
+ return {
299
+ type: "paragraph",
300
+ ...(styleId ? { styleId } : {}),
301
+ ...(alignment ? { alignment } : {}),
302
+ ...(spacing ? { spacing } : {}),
303
+ ...(indentation ? { indentation } : {}),
304
+ ...(tabStops && tabStops.length > 0 ? { tabStops } : {}),
305
+ children,
306
+ };
307
+ }
308
+
309
+ function appendRunNodes(
310
+ rElement: XmlElementNode,
311
+ nodes: InlineNode[],
312
+ activeComplexField: {
313
+ instruction: string;
314
+ children: Array<Extract<InlineNode, { type: "text" | "hard_break" | "tab" }>>;
315
+ mode: "instruction" | "result";
316
+ } | null,
317
+ ): {
318
+ instruction: string;
319
+ children: Array<Extract<InlineNode, { type: "text" | "hard_break" | "tab" }>>;
320
+ mode: "instruction" | "result";
321
+ } | null {
322
+ const marks: TextMark[] = parseRunProperties(rElement);
323
+
324
+ for (const child of rElement.children) {
325
+ if (child.type !== "element") {
326
+ continue;
327
+ }
328
+
329
+ const name = localName(child.name);
330
+ if (name === "fldChar") {
331
+ const fldType = child.attributes["w:fldCharType"] ?? child.attributes.fldCharType;
332
+ if (fldType === "begin") {
333
+ activeComplexField = { instruction: "", children: [], mode: "instruction" };
334
+ } else if (fldType === "separate" && activeComplexField) {
335
+ activeComplexField.mode = "result";
336
+ } else if (fldType === "end" && activeComplexField) {
337
+ if (activeComplexField.instruction.trim().length > 0) {
338
+ nodes.push({
339
+ type: "field",
340
+ fieldType: "complex",
341
+ instruction: activeComplexField.instruction,
342
+ children: activeComplexField.children,
343
+ });
344
+ }
345
+ activeComplexField = null;
346
+ }
347
+ continue;
348
+ }
349
+
350
+ if (name === "instrText") {
351
+ if (activeComplexField) {
352
+ activeComplexField.instruction += extractTextContent(child);
353
+ } else {
354
+ pushFieldNode(nodes, child, "complex");
355
+ }
356
+ continue;
357
+ }
358
+
359
+ const inlineNode = parseRunChildNode(child, marks);
360
+ if (!inlineNode) {
361
+ continue;
362
+ }
363
+
364
+ if (activeComplexField?.mode === "result") {
365
+ if (
366
+ inlineNode.type === "text" ||
367
+ inlineNode.type === "hard_break" ||
368
+ inlineNode.type === "tab"
369
+ ) {
370
+ activeComplexField.children.push(inlineNode);
371
+ }
372
+ continue;
373
+ }
374
+
375
+ nodes.push(inlineNode);
376
+ }
377
+
378
+ return activeComplexField;
379
+ }
380
+
381
+ function parseRunElement(rElement: XmlElementNode): InlineNode[] {
382
+ const nodes: InlineNode[] = [];
383
+ const marks: TextMark[] = parseRunProperties(rElement);
384
+
385
+ for (const child of rElement.children) {
386
+ if (child.type !== "element") {
387
+ continue;
388
+ }
389
+
390
+ const name = localName(child.name);
391
+
392
+ if (name === "t") {
393
+ const text = extractTextContent(child);
394
+ if (text.length > 0) {
395
+ nodes.push({
396
+ type: "text",
397
+ text,
398
+ ...(marks.length > 0 ? { marks } : {}),
399
+ });
400
+ }
401
+ } else if (name === "br") {
402
+ nodes.push({ type: "hard_break" });
403
+ } else if (name === "tab") {
404
+ nodes.push({ type: "tab" });
405
+ } else if (name === "footnoteReference") {
406
+ const noteId =
407
+ child.attributes["w:id"] ?? child.attributes.id ?? "";
408
+ if (noteId) {
409
+ const ref: FootnoteRefNode = {
410
+ type: "footnote_ref",
411
+ noteId,
412
+ noteKind: "footnote",
413
+ };
414
+ nodes.push(ref);
415
+ }
416
+ } else if (name === "endnoteReference") {
417
+ const noteId =
418
+ child.attributes["w:id"] ?? child.attributes.id ?? "";
419
+ if (noteId) {
420
+ const ref: FootnoteRefNode = {
421
+ type: "footnote_ref",
422
+ noteId,
423
+ noteKind: "endnote",
424
+ };
425
+ nodes.push(ref);
426
+ }
427
+ } else if (name === "bookmarkStart" || name === "bookmarkEnd") {
428
+ nodes.push(parseBookmarkElement(child));
429
+ } else if (name === "instrText") {
430
+ pushFieldNode(nodes, child, "complex");
431
+ } else if (name === "drawing") {
432
+ const drawingXml = currentSourceXml.slice(child.start, child.end);
433
+ const shapeResult = parseShapeXml(drawingXml);
434
+ if (shapeResult) {
435
+ nodes.push(shapeResult);
436
+ }
437
+ } else if (name === "pict") {
438
+ const pictXml = currentSourceXml.slice(child.start, child.end);
439
+ const vmlResult = parseVmlXml(pictXml);
440
+ if (vmlResult) {
441
+ nodes.push(vmlResult);
442
+ }
443
+ } else if (name === "AlternateContent") {
444
+ const drawingNode = findFirstDescendant(child, "drawing");
445
+ if (drawingNode) {
446
+ const drawingXml = currentSourceXml.slice(drawingNode.start, drawingNode.end);
447
+ const shapeResult = parseShapeXml(drawingXml);
448
+ if (shapeResult) {
449
+ nodes.push({
450
+ ...shapeResult,
451
+ rawXml: currentSourceXml.slice(child.start, child.end),
452
+ });
453
+ continue;
454
+ }
455
+ }
456
+ const pictNode = findFirstDescendant(child, "pict");
457
+ if (pictNode) {
458
+ const pictXml = currentSourceXml.slice(pictNode.start, pictNode.end);
459
+ const vmlResult = parseVmlXml(pictXml);
460
+ if (vmlResult) {
461
+ nodes.push({
462
+ ...vmlResult,
463
+ rawXml: currentSourceXml.slice(child.start, child.end),
464
+ });
465
+ }
466
+ }
467
+ }
468
+ }
469
+
470
+ return nodes;
471
+ }
472
+
473
+ function parseRunChildNode(
474
+ child: XmlElementNode,
475
+ marks: TextMark[],
476
+ ): InlineNode | null {
477
+ const name = localName(child.name);
478
+
479
+ if (name === "t") {
480
+ const text = extractTextContent(child);
481
+ if (text.length > 0) {
482
+ return {
483
+ type: "text",
484
+ text,
485
+ ...(marks.length > 0 ? { marks } : {}),
486
+ };
487
+ }
488
+ return null;
489
+ }
490
+ if (name === "br") {
491
+ return { type: "hard_break" };
492
+ }
493
+ if (name === "tab") {
494
+ return { type: "tab" };
495
+ }
496
+ if (name === "footnoteReference") {
497
+ const noteId =
498
+ child.attributes["w:id"] ?? child.attributes.id ?? "";
499
+ if (noteId) {
500
+ const ref: FootnoteRefNode = {
501
+ type: "footnote_ref",
502
+ noteId,
503
+ noteKind: "footnote",
504
+ };
505
+ return ref;
506
+ }
507
+ return null;
508
+ }
509
+ if (name === "endnoteReference") {
510
+ const noteId =
511
+ child.attributes["w:id"] ?? child.attributes.id ?? "";
512
+ if (noteId) {
513
+ const ref: FootnoteRefNode = {
514
+ type: "footnote_ref",
515
+ noteId,
516
+ noteKind: "endnote",
517
+ };
518
+ return ref;
519
+ }
520
+ return null;
521
+ }
522
+ if (name === "bookmarkStart" || name === "bookmarkEnd") {
523
+ return parseBookmarkElement(child);
524
+ }
525
+ if (name === "drawing") {
526
+ const drawingXml = currentSourceXml.slice(child.start, child.end);
527
+ return parseShapeXml(drawingXml);
528
+ }
529
+ if (name === "pict") {
530
+ const pictXml = currentSourceXml.slice(child.start, child.end);
531
+ return parseVmlXml(pictXml);
532
+ }
533
+ if (name === "AlternateContent") {
534
+ const drawingNode = findFirstDescendant(child, "drawing");
535
+ if (drawingNode) {
536
+ const drawingXml = currentSourceXml.slice(drawingNode.start, drawingNode.end);
537
+ const shapeResult = parseShapeXml(drawingXml);
538
+ if (shapeResult) {
539
+ return {
540
+ ...shapeResult,
541
+ rawXml: currentSourceXml.slice(child.start, child.end),
542
+ };
543
+ }
544
+ }
545
+ const pictNode = findFirstDescendant(child, "pict");
546
+ if (pictNode) {
547
+ const pictXml = currentSourceXml.slice(pictNode.start, pictNode.end);
548
+ const vmlResult = parseVmlXml(pictXml);
549
+ if (vmlResult) {
550
+ return {
551
+ ...vmlResult,
552
+ rawXml: currentSourceXml.slice(child.start, child.end),
553
+ };
554
+ }
555
+ }
556
+ }
557
+
558
+ return null;
559
+ }
560
+
561
+ function parseHyperlinkElement(element: XmlElementNode): Extract<InlineNode, { type: "hyperlink" }> {
562
+ const href = element.attributes["w:anchor"]
563
+ ? `#${element.attributes["w:anchor"]}`
564
+ : element.attributes["r:id"] ?? "relationship:unknown";
565
+ const children: Array<Extract<InlineNode, { type: "text" | "hard_break" | "tab" }>> = [];
566
+
567
+ for (const child of element.children) {
568
+ if (child.type === "element" && localName(child.name) === "r") {
569
+ for (const runChild of parseRunElement(child)) {
570
+ if (runChild.type === "text" || runChild.type === "hard_break" || runChild.type === "tab") {
571
+ children.push(runChild);
572
+ }
573
+ }
574
+ }
575
+ }
576
+
577
+ return {
578
+ type: "hyperlink",
579
+ href,
580
+ children,
581
+ };
582
+ }
583
+
584
+ function parseBookmarkElement(
585
+ element: XmlElementNode,
586
+ ): Extract<InlineNode, { type: "bookmark_start" | "bookmark_end" }> {
587
+ const bookmarkId = element.attributes["w:id"] ?? element.attributes.id ?? "0";
588
+ if (localName(element.name) === "bookmarkStart") {
589
+ return {
590
+ type: "bookmark_start",
591
+ bookmarkId,
592
+ name: element.attributes["w:name"] ?? element.attributes.name ?? "",
593
+ };
594
+ }
595
+
596
+ return {
597
+ type: "bookmark_end",
598
+ bookmarkId,
599
+ };
600
+ }
601
+
602
+ function pushFieldNode(
603
+ nodes: InlineNode[],
604
+ element: XmlElementNode,
605
+ fieldType: "simple" | "complex",
606
+ ): void {
607
+ const instruction = readFieldInstruction(element);
608
+ if (!instruction) {
609
+ return;
610
+ }
611
+
612
+ nodes.push({
613
+ type: "field",
614
+ fieldType,
615
+ instruction,
616
+ children: [],
617
+ });
618
+ }
619
+
620
+ function readFieldInstruction(element: XmlElementNode): string | undefined {
621
+ const instruction =
622
+ element.attributes["w:instr"] ??
623
+ element.attributes.instr ??
624
+ extractTextContent(element);
625
+ return instruction.trim().length > 0 ? instruction : undefined;
626
+ }
627
+
628
+ function parseRunProperties(rElement: XmlElementNode): TextMark[] {
629
+ const rPr = findChildElementOptional(rElement, "rPr");
630
+ if (!rPr) {
631
+ return [];
632
+ }
633
+
634
+ const marks: TextMark[] = [];
635
+
636
+ for (const child of rPr.children) {
637
+ if (child.type !== "element") {
638
+ continue;
639
+ }
640
+
641
+ const name = localName(child.name);
642
+ const val = child.attributes["w:val"] ?? child.attributes.val ?? "true";
643
+
644
+ switch (name) {
645
+ case "b":
646
+ if (val !== "0" && val !== "false") {
647
+ marks.push({ type: "bold" });
648
+ }
649
+ break;
650
+ case "i":
651
+ if (val !== "0" && val !== "false") {
652
+ marks.push({ type: "italic" });
653
+ }
654
+ break;
655
+ case "u":
656
+ if (val !== "none" && val !== "0") {
657
+ marks.push({ type: "underline" });
658
+ }
659
+ break;
660
+ case "strike":
661
+ if (val !== "0" && val !== "false") {
662
+ marks.push({ type: "strikethrough" });
663
+ }
664
+ break;
665
+ case "dstrike":
666
+ if (val !== "0" && val !== "false") {
667
+ marks.push({ type: "doubleStrikethrough" });
668
+ }
669
+ break;
670
+ case "rFonts": {
671
+ const family =
672
+ child.attributes["w:ascii"] ??
673
+ child.attributes["w:hAnsi"] ??
674
+ child.attributes.ascii ??
675
+ child.attributes.hAnsi;
676
+ if (family) {
677
+ marks.push({ type: "fontFamily", val: family });
678
+ }
679
+ break;
680
+ }
681
+ case "sz": {
682
+ const szVal = child.attributes["w:val"] ?? child.attributes.val;
683
+ if (szVal) {
684
+ const size = Number.parseInt(szVal, 10);
685
+ if (Number.isFinite(size) && size > 0) {
686
+ marks.push({ type: "fontSize", val: size });
687
+ }
688
+ }
689
+ break;
690
+ }
691
+ case "color": {
692
+ const colorVal = child.attributes["w:val"] ?? child.attributes.val;
693
+ if (colorVal && colorVal !== "auto") {
694
+ marks.push({ type: "textColor", color: colorVal });
695
+ }
696
+ break;
697
+ }
698
+ case "shd": {
699
+ const fill = child.attributes["w:fill"] ?? child.attributes.fill;
700
+ if (fill && fill !== "auto") {
701
+ marks.push({ type: "backgroundColor", color: fill });
702
+ }
703
+ break;
704
+ }
705
+ case "highlight": {
706
+ const resolvedHighlight = resolveHighlightColor(
707
+ child.attributes["w:val"] ?? child.attributes.val,
708
+ );
709
+ if (resolvedHighlight) {
710
+ marks.push({
711
+ type: "highlight",
712
+ color: resolvedHighlight.color,
713
+ val: resolvedHighlight.val,
714
+ });
715
+ }
716
+ break;
717
+ }
718
+ case "smallCaps":
719
+ if (val !== "0" && val !== "false") {
720
+ marks.push({ type: "smallCaps" });
721
+ }
722
+ break;
723
+ case "caps":
724
+ if (val !== "0" && val !== "false") {
725
+ marks.push({ type: "allCaps" });
726
+ }
727
+ break;
728
+ }
729
+ }
730
+
731
+ return marks;
732
+ }
733
+
734
+ function readParagraphSpacing(pPr: XmlElementNode): ParagraphSpacing | undefined {
735
+ const spacingNode = findChildElementOptional(pPr, "spacing");
736
+ if (!spacingNode) return undefined;
737
+ const result: ParagraphSpacing = {};
738
+ const before = spacingNode.attributes["w:before"] ?? spacingNode.attributes.before;
739
+ if (before) result.before = Number.parseInt(before, 10);
740
+ const after = spacingNode.attributes["w:after"] ?? spacingNode.attributes.after;
741
+ if (after) result.after = Number.parseInt(after, 10);
742
+ const line = spacingNode.attributes["w:line"] ?? spacingNode.attributes.line;
743
+ if (line) result.line = Number.parseInt(line, 10);
744
+ const lineRule = spacingNode.attributes["w:lineRule"] ?? spacingNode.attributes.lineRule;
745
+ if (lineRule === "auto" || lineRule === "exact" || lineRule === "atLeast") {
746
+ result.lineRule = lineRule;
747
+ }
748
+ return Object.keys(result).length > 0 ? result : undefined;
749
+ }
750
+
751
+ function readParagraphIndentation(pPr: XmlElementNode): ParagraphIndentation | undefined {
752
+ const indNode = findChildElementOptional(pPr, "ind");
753
+ if (!indNode) return undefined;
754
+ const result: ParagraphIndentation = {};
755
+ const left = indNode.attributes["w:left"] ?? indNode.attributes.left;
756
+ if (left) result.left = Number.parseInt(left, 10);
757
+ const right = indNode.attributes["w:right"] ?? indNode.attributes.right;
758
+ if (right) result.right = Number.parseInt(right, 10);
759
+ const firstLine = indNode.attributes["w:firstLine"] ?? indNode.attributes.firstLine;
760
+ if (firstLine) result.firstLine = Number.parseInt(firstLine, 10);
761
+ const hanging = indNode.attributes["w:hanging"] ?? indNode.attributes.hanging;
762
+ if (hanging) result.hanging = Number.parseInt(hanging, 10);
763
+ return Object.keys(result).length > 0 ? result : undefined;
764
+ }
765
+
766
+ function readParagraphTabStops(pPr: XmlElementNode): TabStop[] | undefined {
767
+ const tabsNode = findChildElementOptional(pPr, "tabs");
768
+ if (!tabsNode) return undefined;
769
+
770
+ const tabStops: TabStop[] = [];
771
+ for (const child of tabsNode.children) {
772
+ if (child.type !== "element" || localName(child.name) !== "tab") continue;
773
+ const pos = child.attributes["w:pos"] ?? child.attributes.pos;
774
+ const val = (child.attributes["w:val"] ?? child.attributes.val ?? "left").toLowerCase();
775
+ const leader = (child.attributes["w:leader"] ?? child.attributes.leader ?? "none").toLowerCase();
776
+
777
+ if (pos === undefined) continue;
778
+ const position = Number.parseInt(pos, 10);
779
+ if (!Number.isFinite(position)) continue;
780
+
781
+ const align = (["left", "center", "right", "decimal", "bar", "clear"] as const).includes(
782
+ val as "left" | "center" | "right" | "decimal" | "bar" | "clear",
783
+ )
784
+ ? (val as TabStop["align"])
785
+ : "left";
786
+
787
+ const leaderValue =
788
+ leader === "none" ||
789
+ leader === "dot" ||
790
+ leader === "hyphen" ||
791
+ leader === "underscore" ||
792
+ leader === "heavy"
793
+ ? (leader as Exclude<TabStop["leader"], "middleDot">)
794
+ : leader === "middledot"
795
+ ? "middleDot"
796
+ : undefined;
797
+
798
+ tabStops.push({
799
+ position,
800
+ align,
801
+ ...(leaderValue && leaderValue !== "none" ? { leader: leaderValue } : {}),
802
+ });
803
+ }
804
+
805
+ return tabStops.length > 0 ? tabStops : undefined;
806
+ }
807
+
808
+ function extractTextContent(tElement: XmlElementNode): string {
809
+ let text = "";
810
+ for (const child of tElement.children) {
811
+ if (child.type === "text") {
812
+ text += child.text;
813
+ }
814
+ }
815
+ return text;
816
+ }
817
+
818
+ function findChildElementOptional(
819
+ node: XmlElementNode,
820
+ childLocalName: string,
821
+ ): XmlElementNode | undefined {
822
+ return node.children.find(
823
+ (entry): entry is XmlElementNode =>
824
+ entry.type === "element" && localName(entry.name) === childLocalName,
825
+ );
826
+ }
827
+
828
+ function findFirstDescendant(
829
+ node: XmlElementNode,
830
+ childLocalName: string,
831
+ ): XmlElementNode | undefined {
832
+ for (const child of node.children) {
833
+ if (child.type !== "element") continue;
834
+ if (localName(child.name) === childLocalName) {
835
+ return child;
836
+ }
837
+ const nested = findFirstDescendant(child, childLocalName);
838
+ if (nested) {
839
+ return nested;
840
+ }
841
+ }
842
+ return undefined;
843
+ }
844
+
845
+ function localName(name: string): string {
846
+ const separatorIndex = name.indexOf(":");
847
+ return separatorIndex >= 0 ? name.slice(separatorIndex + 1) : name;
848
+ }
849
+
850
+ // ---- Simple secondary-story table support ----
851
+
852
+ /**
853
+ * Revision-bearing, field-bearing, or structurally risky elements that
854
+ * disqualify a secondary-story table from supported-roundtrip.
855
+ */
856
+ const RISKY_TABLE_ELEMENT_NAMES = new Set([
857
+ "ins",
858
+ "del",
859
+ "moveFrom",
860
+ "moveTo",
861
+ "tblPrChange",
862
+ "trPrChange",
863
+ "tcPrChange",
864
+ "rPrChange",
865
+ "pPrChange",
866
+ "sectPrChange",
867
+ "sdt",
868
+ "customXml",
869
+ ]);
870
+
871
+ function isSimpleSecondaryStoryTable(tblElement: XmlElementNode): boolean {
872
+ return !containsRiskyElement(tblElement);
873
+ }
874
+
875
+ function containsRiskyElement(element: XmlElementNode): boolean {
876
+ for (const child of element.children) {
877
+ if (child.type !== "element") {
878
+ continue;
879
+ }
880
+ const name = localName(child.name);
881
+ if (name === "fldSimple" || name === "instrText") {
882
+ const instruction =
883
+ child.attributes["w:instr"] ??
884
+ child.attributes.instr ??
885
+ extractTextContent(child);
886
+ const classification = classifyFieldInstruction(instruction);
887
+ if (!isSafeSecondaryStoryFieldFamily(classification.family)) {
888
+ return true;
889
+ }
890
+ continue;
891
+ }
892
+ if (RISKY_TABLE_ELEMENT_NAMES.has(name)) {
893
+ return true;
894
+ }
895
+ if (name === "fldChar") {
896
+ continue;
897
+ }
898
+ // Nested tables remain risky
899
+ if (name === "tbl") {
900
+ return true;
901
+ }
902
+ if (containsRiskyElement(child)) {
903
+ return true;
904
+ }
905
+ }
906
+ return false;
907
+ }
908
+
909
+ function isSafeSecondaryStoryFieldFamily(family: string): boolean {
910
+ return (
911
+ family === "REF" ||
912
+ family === "PAGEREF" ||
913
+ family === "NOTEREF" ||
914
+ family === "TOC" ||
915
+ family === "PAGE" ||
916
+ family === "NUMPAGES"
917
+ );
918
+ }
919
+
920
+ function parseSimpleTableElement(tblElement: XmlElementNode): TableNode {
921
+ let gridColumns: number[] = [];
922
+ const rows: TableRowNode[] = [];
923
+ let propertiesXml: string | undefined;
924
+ let styleId: string | undefined;
925
+ let width: TableNode["width"];
926
+ let alignment: TableNode["alignment"];
927
+ let borders: TableNode["borders"];
928
+ let cellMargins: TableNode["cellMargins"];
929
+ let tblLook: TableNode["tblLook"];
930
+
931
+ for (const child of tblElement.children) {
932
+ if (child.type !== "element") continue;
933
+ const name = localName(child.name);
934
+
935
+ if (name === "tblPr") {
936
+ propertiesXml = serializeElementToXml(child);
937
+ styleId = readTableStyleId(child);
938
+ width = readTableWidth(child);
939
+ alignment = readTableAlignment(child);
940
+ borders = readTableBorders(child);
941
+ cellMargins = readTableCellMargins(child);
942
+ tblLook = readTableLook(child);
943
+ } else if (name === "tblGrid") {
944
+ gridColumns = readGridColumns(child);
945
+ } else if (name === "tr") {
946
+ rows.push(parseSimpleTableRow(child));
947
+ }
948
+ }
949
+
950
+ return {
951
+ type: "table",
952
+ ...(styleId ? { styleId } : {}),
953
+ ...(propertiesXml ? { propertiesXml } : {}),
954
+ gridColumns,
955
+ rows,
956
+ ...(width ? { width } : {}),
957
+ ...(alignment ? { alignment } : {}),
958
+ ...(borders ? { borders } : {}),
959
+ ...(cellMargins ? { cellMargins } : {}),
960
+ ...(tblLook ? { tblLook } : {}),
961
+ };
962
+ }
963
+
964
+ function readGridColumns(tblGrid: XmlElementNode): number[] {
965
+ return readSharedGridColumns(tblGrid);
966
+ }
967
+
968
+ function parseSimpleTableRow(trElement: XmlElementNode): TableRowNode {
969
+ const cells: TableCellNode[] = [];
970
+ let propertiesXml: string | undefined;
971
+ let height: TableRowNode["height"];
972
+ let heightRule: TableRowNode["heightRule"];
973
+ let isHeader: TableRowNode["isHeader"];
974
+
975
+ for (const child of trElement.children) {
976
+ if (child.type !== "element") continue;
977
+ const name = localName(child.name);
978
+
979
+ if (name === "trPr") {
980
+ propertiesXml = serializeElementToXml(child);
981
+ height = readRowHeight(child);
982
+ heightRule = readRowHeightRule(child);
983
+ isHeader = readRowIsHeader(child);
984
+ } else if (name === "tc") {
985
+ cells.push(parseSimpleTableCell(child));
986
+ }
987
+ }
988
+
989
+ return {
990
+ type: "table_row",
991
+ ...(propertiesXml ? { propertiesXml } : {}),
992
+ ...(height !== undefined ? { height } : {}),
993
+ ...(heightRule ? { heightRule } : {}),
994
+ ...(isHeader !== undefined ? { isHeader } : {}),
995
+ cells,
996
+ };
997
+ }
998
+
999
+ function parseSimpleTableCell(tcElement: XmlElementNode): TableCellNode {
1000
+ const children: BlockNode[] = [];
1001
+ let propertiesXml: string | undefined;
1002
+ let gridSpan: number | undefined;
1003
+ let verticalMerge: "restart" | "continue" | undefined;
1004
+ let width: TableCellNode["width"];
1005
+ let borders: TableCellNode["borders"];
1006
+ let shading: TableCellNode["shading"];
1007
+ let verticalAlign: TableCellNode["verticalAlign"];
1008
+
1009
+ for (const child of tcElement.children) {
1010
+ if (child.type !== "element") continue;
1011
+ const name = localName(child.name);
1012
+
1013
+ if (name === "tcPr") {
1014
+ propertiesXml = serializeElementToXml(child);
1015
+ const gsEl = findChildElementOptional(child, "gridSpan");
1016
+ const gsVal = gsEl?.attributes["w:val"] ?? gsEl?.attributes.val;
1017
+ if (gsVal) gridSpan = Number.parseInt(gsVal, 10) || undefined;
1018
+
1019
+ const vmEl = findChildElementOptional(child, "vMerge");
1020
+ if (vmEl) {
1021
+ const vmVal = vmEl.attributes["w:val"] ?? vmEl.attributes.val ?? "continue";
1022
+ verticalMerge = vmVal === "restart" ? "restart" : "continue";
1023
+ }
1024
+ width = readCellWidth(child);
1025
+ borders = readCellBorders(child);
1026
+ shading = readCellShading(child);
1027
+ verticalAlign = readCellVerticalAlign(child);
1028
+ } else if (name === "p") {
1029
+ children.push(parseParagraphElement(child));
1030
+ }
1031
+ }
1032
+
1033
+ return {
1034
+ type: "table_cell",
1035
+ ...(propertiesXml ? { propertiesXml } : {}),
1036
+ ...(gridSpan ? { gridSpan } : {}),
1037
+ ...(verticalMerge ? { verticalMerge } : {}),
1038
+ ...(width ? { width } : {}),
1039
+ ...(borders ? { borders } : {}),
1040
+ ...(shading ? { shading } : {}),
1041
+ ...(verticalAlign ? { verticalAlign } : {}),
1042
+ children: children.length > 0 ? children : [{ type: "paragraph", children: [] }],
1043
+ };
1044
+ }
1045
+
1046
+ /**
1047
+ * Serialize an XmlElementNode back to XML string for propertiesXml preservation.
1048
+ */
1049
+ function serializeElementToXml(element: XmlElementNode): string {
1050
+ const attrs = Object.entries(element.attributes)
1051
+ .map(([key, value]) => ` ${key}="${escapeXmlAttribute(value)}"`)
1052
+ .join("");
1053
+ const children = element.children
1054
+ .map((child) => {
1055
+ if (child.type === "text") {
1056
+ return escapeXmlText(child.text);
1057
+ }
1058
+ return serializeElementToXml(child);
1059
+ })
1060
+ .join("");
1061
+ if (children.length === 0) {
1062
+ return `<${element.name}${attrs}/>`;
1063
+ }
1064
+ return `<${element.name}${attrs}>${children}</${element.name}>`;
1065
+ }
1066
+
1067
+ function escapeXmlAttribute(text: string): string {
1068
+ return text
1069
+ .replace(/&/g, "&amp;")
1070
+ .replace(/"/g, "&quot;")
1071
+ .replace(/</g, "&lt;")
1072
+ .replace(/>/g, "&gt;");
1073
+ }
1074
+
1075
+ function escapeXmlText(text: string): string {
1076
+ return text
1077
+ .replace(/&/g, "&amp;")
1078
+ .replace(/</g, "&lt;")
1079
+ .replace(/>/g, "&gt;");
1080
+ }
1081
+
1082
+ // ---- Minimal XML parser (same pattern as parse-numbering.ts) ----
1083
+
1084
+ function parseXml(xml: string): XmlElementNode {
1085
+ currentSourceXml = xml;
1086
+ const root: XmlElementNode = {
1087
+ type: "element",
1088
+ name: "__root__",
1089
+ attributes: {},
1090
+ children: [],
1091
+ start: 0,
1092
+ end: xml.length,
1093
+ };
1094
+ const stack: XmlElementNode[] = [root];
1095
+ let cursor = 0;
1096
+
1097
+ while (cursor < xml.length) {
1098
+ if (xml.startsWith("<!--", cursor)) {
1099
+ const end = xml.indexOf("-->", cursor);
1100
+ cursor = end >= 0 ? end + 3 : xml.length;
1101
+ continue;
1102
+ }
1103
+
1104
+ if (xml.startsWith("<?", cursor)) {
1105
+ const end = xml.indexOf("?>", cursor);
1106
+ cursor = end >= 0 ? end + 2 : xml.length;
1107
+ continue;
1108
+ }
1109
+
1110
+ if (xml.startsWith("<![CDATA[", cursor)) {
1111
+ const end = xml.indexOf("]]>", cursor);
1112
+ const textEnd = end >= 0 ? end : xml.length;
1113
+ stack[stack.length - 1]?.children.push({
1114
+ type: "text",
1115
+ text: xml.slice(cursor + 9, textEnd),
1116
+ start: cursor,
1117
+ end: end >= 0 ? end + 3 : xml.length,
1118
+ });
1119
+ cursor = end >= 0 ? end + 3 : xml.length;
1120
+ continue;
1121
+ }
1122
+
1123
+ if (xml[cursor] !== "<") {
1124
+ const nextTag = xml.indexOf("<", cursor);
1125
+ const end = nextTag >= 0 ? nextTag : xml.length;
1126
+ const text = decodeXmlEntities(xml.slice(cursor, end));
1127
+ if (text.trim().length > 0 || (text.length > 0 && stack.length > 1)) {
1128
+ stack[stack.length - 1]?.children.push({ type: "text", text, start: cursor, end });
1129
+ }
1130
+ cursor = end;
1131
+ continue;
1132
+ }
1133
+
1134
+ // Closing tag
1135
+ if (xml[cursor + 1] === "/") {
1136
+ const end = xml.indexOf(">", cursor);
1137
+ if (end < 0) {
1138
+ break;
1139
+ }
1140
+ const current = stack.pop();
1141
+ if (current) {
1142
+ current.end = end + 1;
1143
+ }
1144
+ cursor = end + 1;
1145
+ continue;
1146
+ }
1147
+
1148
+ // Open or self-closing tag
1149
+ const tagEnd = xml.indexOf(">", cursor);
1150
+ if (tagEnd < 0) {
1151
+ break;
1152
+ }
1153
+
1154
+ const tagContent = xml.slice(cursor + 1, tagEnd);
1155
+ const selfClosing = tagContent.endsWith("/");
1156
+ const normalized = selfClosing ? tagContent.slice(0, -1).trimEnd() : tagContent;
1157
+
1158
+ const spaceIndex = normalized.search(/\s/);
1159
+ const tagName =
1160
+ spaceIndex >= 0 ? normalized.slice(0, spaceIndex) : normalized;
1161
+ const attrString =
1162
+ spaceIndex >= 0 ? normalized.slice(spaceIndex + 1) : "";
1163
+ const attributes = parseAttributes(attrString);
1164
+
1165
+ const element: XmlElementNode = {
1166
+ type: "element",
1167
+ name: tagName,
1168
+ attributes,
1169
+ children: [],
1170
+ start: cursor,
1171
+ end: tagEnd + 1,
1172
+ };
1173
+
1174
+ stack[stack.length - 1]?.children.push(element);
1175
+
1176
+ if (!selfClosing) {
1177
+ stack.push(element);
1178
+ }
1179
+
1180
+ cursor = tagEnd + 1;
1181
+ }
1182
+
1183
+ return root;
1184
+ }
1185
+
1186
+ function parseAttributes(attrString: string): Record<string, string> {
1187
+ const attrs: Record<string, string> = {};
1188
+ const pattern = /([A-Za-z_:][A-Za-z0-9:._-]*)\s*=\s*("([^"]*)"|'([^']*)')/gu;
1189
+
1190
+ for (const match of attrString.matchAll(pattern)) {
1191
+ const name = match[1];
1192
+ const value = match[3] ?? match[4] ?? "";
1193
+ if (name) {
1194
+ attrs[name] = decodeXmlEntities(value);
1195
+ }
1196
+ }
1197
+
1198
+ return attrs;
1199
+ }
1200
+
1201
+ function decodeXmlEntities(text: string): string {
1202
+ return text
1203
+ .replace(/&amp;/g, "&")
1204
+ .replace(/&lt;/g, "<")
1205
+ .replace(/&gt;/g, ">")
1206
+ .replace(/&quot;/g, '"')
1207
+ .replace(/&apos;/g, "'")
1208
+ .replace(/&#(\d+);/g, (_, dec) => String.fromCodePoint(Number.parseInt(dec, 10)))
1209
+ .replace(/&#x([0-9a-fA-F]+);/g, (_, hex) =>
1210
+ String.fromCodePoint(Number.parseInt(hex, 16)),
1211
+ );
1212
+ }