@beyondwork/docx-react-component 1.0.29 → 1.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (381) hide show
  1. package/package.json +65 -96
  2. package/src/README.md +85 -0
  3. package/src/api/README.md +26 -0
  4. package/src/api/public-types.ts +1952 -0
  5. package/src/api/session-state.ts +62 -0
  6. package/src/compare/diff-engine.ts +623 -0
  7. package/src/compare/export-redlines.ts +280 -0
  8. package/src/compare/index.ts +25 -0
  9. package/src/compare/snapshot.ts +97 -0
  10. package/src/component-inventory.md +99 -0
  11. package/src/core/README.md +10 -0
  12. package/src/core/commands/README.md +3 -0
  13. package/{dist/chunk-TJBP2K4T.js → src/core/commands/formatting-commands.ts} +536 -196
  14. package/src/core/commands/image-commands.ts +373 -0
  15. package/src/core/commands/index.ts +1879 -0
  16. package/src/core/commands/list-commands.ts +565 -0
  17. package/src/core/commands/paragraph-layout-commands.ts +339 -0
  18. package/src/core/commands/review-commands.ts +108 -0
  19. package/{dist/core/commands/section-layout-commands.cjs → src/core/commands/section-layout-commands.ts} +340 -137
  20. package/src/core/commands/structural-helpers.ts +309 -0
  21. package/{dist/core/commands/style-commands.cjs → src/core/commands/style-commands.ts} +113 -65
  22. package/src/core/commands/table-structure-commands.ts +854 -0
  23. package/{dist/chunk-UZXBISGO.js → src/core/commands/text-commands.ts} +142 -86
  24. package/src/core/schema/README.md +3 -0
  25. package/src/core/schema/text-schema.ts +516 -0
  26. package/src/core/search/search-text.ts +357 -0
  27. package/src/core/selection/README.md +3 -0
  28. package/src/core/selection/mapping.ts +289 -0
  29. package/src/core/selection/review-anchors.ts +183 -0
  30. package/src/core/state/README.md +3 -0
  31. package/src/core/state/editor-state.ts +892 -0
  32. package/src/core/state/text-transaction.ts +869 -0
  33. package/src/formats/xlsx/io/parse-shared-strings.ts +41 -0
  34. package/src/formats/xlsx/io/parse-sheet.ts +459 -0
  35. package/src/formats/xlsx/io/parse-styles.ts +59 -0
  36. package/src/formats/xlsx/io/parse-workbook.ts +75 -0
  37. package/src/formats/xlsx/io/serialize-shared-strings.ts +72 -0
  38. package/src/formats/xlsx/io/serialize-sheet.ts +333 -0
  39. package/src/formats/xlsx/io/serialize-styles.ts +98 -0
  40. package/src/formats/xlsx/io/serialize-workbook.ts +429 -0
  41. package/src/formats/xlsx/io/xlsx-session.ts +314 -0
  42. package/src/formats/xlsx/model/cell.ts +189 -0
  43. package/src/formats/xlsx/model/sheet.ts +326 -0
  44. package/src/formats/xlsx/model/styles.ts +118 -0
  45. package/src/formats/xlsx/model/workbook.ts +453 -0
  46. package/src/formats/xlsx/runtime/cell-commands.ts +567 -0
  47. package/src/formats/xlsx/runtime/sheet-commands.ts +206 -0
  48. package/src/formats/xlsx/runtime/workbook-runtime.ts +177 -0
  49. package/src/formats/xlsx/runtime/workbook-transaction.ts +822 -0
  50. package/src/index.ts +142 -0
  51. package/src/io/README.md +10 -0
  52. package/src/io/docx-session.ts +3175 -0
  53. package/src/io/export/README.md +3 -0
  54. package/src/io/export/export-session.ts +220 -0
  55. package/src/io/export/minimal-docx.ts +115 -0
  56. package/src/io/export/reattach-preserved-parts.ts +54 -0
  57. package/src/io/export/serialize-comments.ts +947 -0
  58. package/src/io/export/serialize-footnotes.ts +394 -0
  59. package/src/io/export/serialize-headers-footers.ts +368 -0
  60. package/src/io/export/serialize-main-document.ts +1342 -0
  61. package/src/io/export/serialize-numbering.ts +218 -0
  62. package/src/io/export/serialize-revisions.ts +389 -0
  63. package/src/io/export/serialize-runtime-revisions.ts +463 -0
  64. package/src/io/export/serialize-tables.ts +174 -0
  65. package/src/io/export/split-review-boundaries.ts +356 -0
  66. package/src/io/export/split-story-blocks-for-runtime-revisions.ts +252 -0
  67. package/src/io/export/table-properties-xml.ts +318 -0
  68. package/src/io/normalize/README.md +3 -0
  69. package/src/io/normalize/normalize-text.ts +670 -0
  70. package/src/io/ooxml/README.md +3 -0
  71. package/src/io/ooxml/highlight-colors.ts +39 -0
  72. package/src/io/ooxml/numbering-sentinels.ts +44 -0
  73. package/src/io/ooxml/parse-comments.ts +852 -0
  74. package/src/io/ooxml/parse-complex-content.ts +287 -0
  75. package/src/io/ooxml/parse-fields.ts +834 -0
  76. package/src/io/ooxml/parse-footnotes.ts +952 -0
  77. package/src/io/ooxml/parse-headers-footers.ts +1212 -0
  78. package/src/io/ooxml/parse-inline-media.ts +461 -0
  79. package/src/io/ooxml/parse-main-document.ts +2947 -0
  80. package/src/io/ooxml/parse-numbering.ts +747 -0
  81. package/src/io/ooxml/parse-revisions.ts +1045 -0
  82. package/src/io/ooxml/parse-settings.ts +184 -0
  83. package/src/io/ooxml/parse-shapes.ts +296 -0
  84. package/src/io/ooxml/parse-styles.ts +639 -0
  85. package/src/io/ooxml/parse-tables.ts +627 -0
  86. package/src/io/ooxml/parse-theme.ts +346 -0
  87. package/src/io/ooxml/part-manifest.ts +136 -0
  88. package/src/io/ooxml/revision-boundaries.ts +475 -0
  89. package/src/io/ooxml/workflow-payload.ts +544 -0
  90. package/src/io/opc/README.md +3 -0
  91. package/src/io/opc/corrupt-package.ts +166 -0
  92. package/src/io/opc/docx-package.ts +74 -0
  93. package/src/io/opc/package-reader.ts +325 -0
  94. package/src/io/opc/package-writer.ts +273 -0
  95. package/src/io/source-package-provenance.ts +241 -0
  96. package/{dist/chunk-RMH72RZI.js → src/legal/bookmarks.ts} +130 -44
  97. package/src/legal/cross-references.ts +414 -0
  98. package/src/legal/defined-terms.ts +203 -0
  99. package/src/legal/index.ts +32 -0
  100. package/src/legal/signature-blocks.ts +259 -0
  101. package/src/model/README.md +3 -0
  102. package/src/model/canonical-document.ts +2722 -0
  103. package/src/model/cds-1.0.0.ts +212 -0
  104. package/src/model/snapshot.ts +760 -0
  105. package/src/preservation/README.md +3 -0
  106. package/src/preservation/markup-compatibility.ts +48 -0
  107. package/src/preservation/opaque-fragment-store.ts +89 -0
  108. package/src/preservation/opaque-region.ts +233 -0
  109. package/src/preservation/package-preservation.ts +113 -0
  110. package/src/preservation/preserved-part-manifest.ts +56 -0
  111. package/src/preservation/relationship-retention.ts +57 -0
  112. package/src/preservation/store.ts +255 -0
  113. package/src/review/README.md +16 -0
  114. package/src/review/store/README.md +3 -0
  115. package/src/review/store/comment-anchors.ts +70 -0
  116. package/src/review/store/comment-remapping.ts +154 -0
  117. package/src/review/store/comment-store.ts +349 -0
  118. package/src/review/store/comment-thread.ts +109 -0
  119. package/src/review/store/revision-actions.ts +423 -0
  120. package/src/review/store/revision-store.ts +323 -0
  121. package/src/review/store/revision-types.ts +182 -0
  122. package/src/review/store/runtime-comment-store.ts +43 -0
  123. package/src/runtime/README.md +3 -0
  124. package/src/runtime/ai-action-policy.ts +764 -0
  125. package/src/runtime/context-analytics.ts +824 -0
  126. package/src/runtime/document-layout.ts +332 -0
  127. package/src/runtime/document-locations.ts +521 -0
  128. package/src/runtime/document-navigation.ts +616 -0
  129. package/src/runtime/document-outline.ts +440 -0
  130. package/src/runtime/document-runtime.ts +4055 -0
  131. package/src/runtime/document-search.ts +145 -0
  132. package/src/runtime/event-refresh-hints.ts +137 -0
  133. package/src/runtime/numbering-prefix.ts +244 -0
  134. package/src/runtime/page-layout-estimation.ts +305 -0
  135. package/src/runtime/read-only-diagnostics-runtime.ts +241 -0
  136. package/src/runtime/resolved-numbering-geometry.ts +293 -0
  137. package/src/runtime/review-runtime.ts +44 -0
  138. package/src/runtime/revision-runtime.ts +107 -0
  139. package/src/runtime/session-capabilities.ts +192 -0
  140. package/src/runtime/story-context.ts +164 -0
  141. package/src/runtime/story-targeting.ts +162 -0
  142. package/src/runtime/suggestions-snapshot.ts +137 -0
  143. package/src/runtime/surface-projection.ts +1553 -0
  144. package/src/runtime/table-commands.ts +173 -0
  145. package/src/runtime/table-schema.ts +309 -0
  146. package/src/runtime/table-style-resolver.ts +409 -0
  147. package/src/runtime/view-state.ts +493 -0
  148. package/src/runtime/virtualized-rendering.ts +258 -0
  149. package/src/runtime/workflow-markup.ts +393 -0
  150. package/src/ui/README.md +30 -0
  151. package/src/ui/WordReviewEditor.tsx +5268 -0
  152. package/src/ui/browser-export.ts +52 -0
  153. package/src/ui/comments/README.md +3 -0
  154. package/src/ui/compatibility/README.md +3 -0
  155. package/src/ui/editor-command-bag.ts +127 -0
  156. package/src/ui/editor-runtime-boundary.ts +1558 -0
  157. package/src/ui/editor-shell-view.tsx +144 -0
  158. package/src/ui/editor-surface/README.md +3 -0
  159. package/src/ui/editor-surface-controller.tsx +66 -0
  160. package/src/ui/headless/comment-decoration-model.ts +124 -0
  161. package/src/ui/headless/preserve-editor-selection.ts +5 -0
  162. package/src/ui/headless/revision-decoration-model.ts +128 -0
  163. package/src/ui/headless/selection-helpers.ts +54 -0
  164. package/src/ui/headless/selection-tool-context.ts +19 -0
  165. package/src/ui/headless/selection-tool-resolver.ts +752 -0
  166. package/src/ui/headless/selection-tool-types.ts +129 -0
  167. package/src/ui/headless/selection-toolbar-model.ts +11 -0
  168. package/src/ui/headless/use-editor-keyboard.ts +103 -0
  169. package/src/ui/review/README.md +3 -0
  170. package/src/ui/runtime-shortcut-dispatch.ts +365 -0
  171. package/src/ui/runtime-snapshot-selectors.ts +197 -0
  172. package/src/ui/shared/revision-filters.ts +31 -0
  173. package/src/ui/status/README.md +3 -0
  174. package/src/ui/theme/README.md +3 -0
  175. package/src/ui/toolbar/README.md +3 -0
  176. package/src/ui/workflow-surface-blocked-rails.ts +94 -0
  177. package/src/ui-tailwind/chrome/chrome-preset-model.ts +107 -0
  178. package/src/ui-tailwind/chrome/chrome-preset-toolbar.tsx +15 -0
  179. package/src/ui-tailwind/chrome/review-queue-bar.tsx +97 -0
  180. package/src/ui-tailwind/chrome/tw-alert-banner.tsx +64 -0
  181. package/src/ui-tailwind/chrome/tw-context-analytics-summary.tsx +122 -0
  182. package/src/ui-tailwind/chrome/tw-image-context-toolbar.tsx +121 -0
  183. package/src/ui-tailwind/chrome/tw-layout-panel.tsx +114 -0
  184. package/src/ui-tailwind/chrome/tw-object-context-toolbar.tsx +30 -0
  185. package/src/ui-tailwind/chrome/tw-page-ruler.tsx +365 -0
  186. package/src/ui-tailwind/chrome/tw-selection-tool-blocked.tsx +23 -0
  187. package/src/ui-tailwind/chrome/tw-selection-tool-comment.tsx +35 -0
  188. package/src/ui-tailwind/chrome/tw-selection-tool-formatting.tsx +37 -0
  189. package/src/ui-tailwind/chrome/tw-selection-tool-host.tsx +298 -0
  190. package/src/ui-tailwind/chrome/tw-selection-tool-structure.tsx +116 -0
  191. package/src/ui-tailwind/chrome/tw-selection-tool-suggestion.tsx +29 -0
  192. package/src/ui-tailwind/chrome/tw-selection-tool-workflow.tsx +27 -0
  193. package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +186 -0
  194. package/src/ui-tailwind/chrome/tw-suggestion-card.tsx +139 -0
  195. package/src/ui-tailwind/chrome/tw-table-context-toolbar.tsx +200 -0
  196. package/src/ui-tailwind/chrome/tw-unsaved-modal.tsx +58 -0
  197. package/src/ui-tailwind/chrome/use-before-unload.ts +20 -0
  198. package/src/ui-tailwind/editor-surface/perf-probe.ts +179 -0
  199. package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +189 -0
  200. package/src/ui-tailwind/editor-surface/pm-contextual-ui.ts +31 -0
  201. package/src/ui-tailwind/editor-surface/pm-decorations.ts +411 -0
  202. package/src/ui-tailwind/editor-surface/pm-position-map.ts +123 -0
  203. package/src/ui-tailwind/editor-surface/pm-schema.ts +927 -0
  204. package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +567 -0
  205. package/src/ui-tailwind/editor-surface/search-plugin.ts +168 -0
  206. package/src/ui-tailwind/editor-surface/surface-build-keys.ts +65 -0
  207. package/src/ui-tailwind/editor-surface/tw-caret.tsx +12 -0
  208. package/src/ui-tailwind/editor-surface/tw-editor-surface.tsx +150 -0
  209. package/src/ui-tailwind/editor-surface/tw-inline-token.tsx +129 -0
  210. package/src/ui-tailwind/editor-surface/tw-opaque-block.tsx +58 -0
  211. package/src/ui-tailwind/editor-surface/tw-paragraph-block.tsx +151 -0
  212. package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +1047 -0
  213. package/src/ui-tailwind/editor-surface/tw-segment-view.tsx +111 -0
  214. package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +503 -0
  215. package/src/ui-tailwind/index.ts +62 -0
  216. package/src/ui-tailwind/page-chrome-model.ts +27 -0
  217. package/src/ui-tailwind/review/tw-comment-sidebar.tsx +406 -0
  218. package/src/ui-tailwind/review/tw-health-panel.tsx +149 -0
  219. package/src/ui-tailwind/review/tw-review-rail.tsx +122 -0
  220. package/src/ui-tailwind/review/tw-revision-sidebar.tsx +164 -0
  221. package/src/ui-tailwind/status/tw-status-bar.tsx +65 -0
  222. package/{dist → src}/ui-tailwind/theme/editor-theme.css +58 -40
  223. package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +52 -0
  224. package/src/ui-tailwind/toolbar/tw-toolbar.tsx +1133 -0
  225. package/src/ui-tailwind/tw-review-workspace.tsx +1460 -0
  226. package/src/validation/README.md +3 -0
  227. package/src/validation/compatibility-engine.ts +878 -0
  228. package/src/validation/compatibility-report.ts +161 -0
  229. package/src/validation/diagnostics.ts +204 -0
  230. package/src/validation/docx-comment-proof.ts +720 -0
  231. package/src/validation/import-diagnostics.ts +128 -0
  232. package/src/validation/low-priority-word-surfaces.ts +373 -0
  233. package/dist/canonical-document-BLEbzL2J.d.cts +0 -844
  234. package/dist/canonical-document-BLEbzL2J.d.ts +0 -844
  235. package/dist/chunk-2FJS5GZM.js +0 -763
  236. package/dist/chunk-2FJS5GZM.js.map +0 -1
  237. package/dist/chunk-2OQBZS3F.js +0 -446
  238. package/dist/chunk-2OQBZS3F.js.map +0 -1
  239. package/dist/chunk-2S7W4KFO.js +0 -127
  240. package/dist/chunk-2S7W4KFO.js.map +0 -1
  241. package/dist/chunk-2TG72QSW.js +0 -3874
  242. package/dist/chunk-2TG72QSW.js.map +0 -1
  243. package/dist/chunk-36QNIZBO.js +0 -532
  244. package/dist/chunk-36QNIZBO.js.map +0 -1
  245. package/dist/chunk-4AQOYAW4.js +0 -3069
  246. package/dist/chunk-4AQOYAW4.js.map +0 -1
  247. package/dist/chunk-4D5EWJ3P.js +0 -77
  248. package/dist/chunk-4D5EWJ3P.js.map +0 -1
  249. package/dist/chunk-5FN54NDH.js +0 -2257
  250. package/dist/chunk-5FN54NDH.js.map +0 -1
  251. package/dist/chunk-BOYGQYRQ.js +0 -7306
  252. package/dist/chunk-BOYGQYRQ.js.map +0 -1
  253. package/dist/chunk-CN3XMECL.js +0 -212
  254. package/dist/chunk-CN3XMECL.js.map +0 -1
  255. package/dist/chunk-EBI3BX6U.js +0 -164
  256. package/dist/chunk-EBI3BX6U.js.map +0 -1
  257. package/dist/chunk-EILUG3VB.js +0 -1275
  258. package/dist/chunk-EILUG3VB.js.map +0 -1
  259. package/dist/chunk-FUDY333O.js +0 -70
  260. package/dist/chunk-FUDY333O.js.map +0 -1
  261. package/dist/chunk-GBVOWFIK.js +0 -1237
  262. package/dist/chunk-GBVOWFIK.js.map +0 -1
  263. package/dist/chunk-H4TQ3H3Y.js +0 -262
  264. package/dist/chunk-H4TQ3H3Y.js.map +0 -1
  265. package/dist/chunk-JGB3IXZO.js +0 -189
  266. package/dist/chunk-JGB3IXZO.js.map +0 -1
  267. package/dist/chunk-KD2QRQPY.js +0 -4342
  268. package/dist/chunk-KD2QRQPY.js.map +0 -1
  269. package/dist/chunk-KLMXQVYK.js +0 -369
  270. package/dist/chunk-KLMXQVYK.js.map +0 -1
  271. package/dist/chunk-KZUG5KFQ.js +0 -214
  272. package/dist/chunk-KZUG5KFQ.js.map +0 -1
  273. package/dist/chunk-QDAQ4CJU.js +0 -345
  274. package/dist/chunk-QDAQ4CJU.js.map +0 -1
  275. package/dist/chunk-RMH72RZI.js.map +0 -1
  276. package/dist/chunk-SWKWQZXM.js +0 -117
  277. package/dist/chunk-SWKWQZXM.js.map +0 -1
  278. package/dist/chunk-TJBP2K4T.js.map +0 -1
  279. package/dist/chunk-TLCEAQDQ.js +0 -542
  280. package/dist/chunk-TLCEAQDQ.js.map +0 -1
  281. package/dist/chunk-UZXBISGO.js.map +0 -1
  282. package/dist/chunk-WGBAKP3Q.js +0 -3220
  283. package/dist/chunk-WGBAKP3Q.js.map +0 -1
  284. package/dist/compare/index.cjs +0 -5475
  285. package/dist/compare/index.cjs.map +0 -1
  286. package/dist/compare/index.d.cts +0 -114
  287. package/dist/compare/index.d.ts +0 -114
  288. package/dist/compare/index.js +0 -731
  289. package/dist/compare/index.js.map +0 -1
  290. package/dist/core/commands/formatting-commands.cjs +0 -828
  291. package/dist/core/commands/formatting-commands.cjs.map +0 -1
  292. package/dist/core/commands/formatting-commands.d.cts +0 -63
  293. package/dist/core/commands/formatting-commands.d.ts +0 -63
  294. package/dist/core/commands/formatting-commands.js +0 -37
  295. package/dist/core/commands/formatting-commands.js.map +0 -1
  296. package/dist/core/commands/image-commands.cjs +0 -2023
  297. package/dist/core/commands/image-commands.cjs.map +0 -1
  298. package/dist/core/commands/image-commands.d.cts +0 -58
  299. package/dist/core/commands/image-commands.d.ts +0 -58
  300. package/dist/core/commands/image-commands.js +0 -18
  301. package/dist/core/commands/image-commands.js.map +0 -1
  302. package/dist/core/commands/section-layout-commands.cjs.map +0 -1
  303. package/dist/core/commands/section-layout-commands.d.cts +0 -62
  304. package/dist/core/commands/section-layout-commands.d.ts +0 -62
  305. package/dist/core/commands/section-layout-commands.js +0 -21
  306. package/dist/core/commands/section-layout-commands.js.map +0 -1
  307. package/dist/core/commands/style-commands.cjs.map +0 -1
  308. package/dist/core/commands/style-commands.d.cts +0 -13
  309. package/dist/core/commands/style-commands.d.ts +0 -13
  310. package/dist/core/commands/style-commands.js +0 -9
  311. package/dist/core/commands/style-commands.js.map +0 -1
  312. package/dist/core/commands/table-structure-commands.cjs +0 -1883
  313. package/dist/core/commands/table-structure-commands.cjs.map +0 -1
  314. package/dist/core/commands/table-structure-commands.d.cts +0 -59
  315. package/dist/core/commands/table-structure-commands.d.ts +0 -59
  316. package/dist/core/commands/table-structure-commands.js +0 -12
  317. package/dist/core/commands/table-structure-commands.js.map +0 -1
  318. package/dist/core/commands/text-commands.cjs +0 -2391
  319. package/dist/core/commands/text-commands.cjs.map +0 -1
  320. package/dist/core/commands/text-commands.d.cts +0 -24
  321. package/dist/core/commands/text-commands.d.ts +0 -24
  322. package/dist/core/commands/text-commands.js +0 -28
  323. package/dist/core/commands/text-commands.js.map +0 -1
  324. package/dist/core/selection/mapping.cjs +0 -200
  325. package/dist/core/selection/mapping.cjs.map +0 -1
  326. package/dist/core/selection/mapping.d.cts +0 -2
  327. package/dist/core/selection/mapping.d.ts +0 -2
  328. package/dist/core/selection/mapping.js +0 -31
  329. package/dist/core/selection/mapping.js.map +0 -1
  330. package/dist/core/state/editor-state.cjs +0 -2278
  331. package/dist/core/state/editor-state.cjs.map +0 -1
  332. package/dist/core/state/editor-state.d.cts +0 -2
  333. package/dist/core/state/editor-state.d.ts +0 -2
  334. package/dist/core/state/editor-state.js +0 -26
  335. package/dist/core/state/editor-state.js.map +0 -1
  336. package/dist/index.cjs +0 -38553
  337. package/dist/index.cjs.map +0 -1
  338. package/dist/index.d.cts +0 -15
  339. package/dist/index.d.ts +0 -15
  340. package/dist/index.js +0 -7856
  341. package/dist/index.js.map +0 -1
  342. package/dist/io/docx-session.cjs +0 -16236
  343. package/dist/io/docx-session.cjs.map +0 -1
  344. package/dist/io/docx-session.d.cts +0 -21
  345. package/dist/io/docx-session.d.ts +0 -21
  346. package/dist/io/docx-session.js +0 -18
  347. package/dist/io/docx-session.js.map +0 -1
  348. package/dist/legal/index.cjs +0 -3900
  349. package/dist/legal/index.cjs.map +0 -1
  350. package/dist/legal/index.d.cts +0 -86
  351. package/dist/legal/index.d.ts +0 -86
  352. package/dist/legal/index.js +0 -616
  353. package/dist/legal/index.js.map +0 -1
  354. package/dist/public-types-7ZL_94cz.d.ts +0 -1573
  355. package/dist/public-types-CeMaDueh.d.cts +0 -1573
  356. package/dist/public-types.cjs +0 -19
  357. package/dist/public-types.cjs.map +0 -1
  358. package/dist/public-types.d.cts +0 -2
  359. package/dist/public-types.d.ts +0 -2
  360. package/dist/public-types.js +0 -1
  361. package/dist/public-types.js.map +0 -1
  362. package/dist/runtime/document-runtime.cjs +0 -11140
  363. package/dist/runtime/document-runtime.cjs.map +0 -1
  364. package/dist/runtime/document-runtime.d.cts +0 -231
  365. package/dist/runtime/document-runtime.d.ts +0 -231
  366. package/dist/runtime/document-runtime.js +0 -21
  367. package/dist/runtime/document-runtime.js.map +0 -1
  368. package/dist/structural-helpers-CilgOVhh.d.cts +0 -10
  369. package/dist/structural-helpers-q0Gd-eBN.d.ts +0 -10
  370. package/dist/ui-tailwind/editor-surface/search-plugin.cjs +0 -313
  371. package/dist/ui-tailwind/editor-surface/search-plugin.cjs.map +0 -1
  372. package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +0 -67
  373. package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +0 -67
  374. package/dist/ui-tailwind/editor-surface/search-plugin.js +0 -23
  375. package/dist/ui-tailwind/editor-surface/search-plugin.js.map +0 -1
  376. package/dist/ui-tailwind/index.cjs +0 -4833
  377. package/dist/ui-tailwind/index.cjs.map +0 -1
  378. package/dist/ui-tailwind/index.d.cts +0 -617
  379. package/dist/ui-tailwind/index.d.ts +0 -617
  380. package/dist/ui-tailwind/index.js +0 -575
  381. package/dist/ui-tailwind/index.js.map +0 -1
@@ -1,1883 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/core/commands/table-structure-commands.ts
21
- var table_structure_commands_exports = {};
22
- __export(table_structure_commands_exports, {
23
- applyTableStructureOperation: () => applyTableStructureOperation
24
- });
25
- module.exports = __toCommonJS(table_structure_commands_exports);
26
-
27
- // src/core/selection/mapping.ts
28
- var DEFAULT_BOUNDARY_ASSOC = {
29
- start: 1,
30
- end: -1
31
- };
32
- function createRangeAnchor(from, to = from, assoc = DEFAULT_BOUNDARY_ASSOC) {
33
- return {
34
- kind: "range",
35
- range: normalizeRange({ from, to }),
36
- assoc
37
- };
38
- }
39
- function createNodeAnchor(at, assoc = 1) {
40
- return {
41
- kind: "node",
42
- at,
43
- assoc
44
- };
45
- }
46
- function createDetachedAnchor(lastKnownRange, reason) {
47
- return {
48
- kind: "detached",
49
- lastKnownRange: normalizeRange(lastKnownRange),
50
- reason
51
- };
52
- }
53
- function normalizeRange(range) {
54
- return range.from <= range.to ? { from: range.from, to: range.to } : { from: range.to, to: range.from };
55
- }
56
-
57
- // src/core/state/editor-state.ts
58
- function createSelectionSnapshot(anchor = 0, head = anchor) {
59
- return {
60
- anchor,
61
- head,
62
- isCollapsed: anchor === head,
63
- activeRange: createRangeAnchor(anchor, head, DEFAULT_BOUNDARY_ASSOC)
64
- };
65
- }
66
-
67
- // src/preservation/store.ts
68
- function getOpaqueFragment(store, fragmentId) {
69
- return normalizeOpaqueFragmentMap(store)[fragmentId];
70
- }
71
- function describeOpaqueFragment(fragment) {
72
- const xml = fragment.payloadReference;
73
- const detail = createDetail(fragment);
74
- if (/\b(?:w:)?sectPr\b/u.test(xml)) {
75
- return {
76
- featureKey: "sections",
77
- label: "Section properties",
78
- detail
79
- };
80
- }
81
- if (/\b(?:w:)?tbl\b/u.test(xml)) {
82
- return {
83
- featureKey: "tables",
84
- label: "Preserved table structure",
85
- detail
86
- };
87
- }
88
- if (/\b(?:w:)?hdr\b|\b(?:w:)?ftr\b/u.test(xml)) {
89
- return {
90
- featureKey: "headers-footers",
91
- label: "Header or footer content",
92
- detail
93
- };
94
- }
95
- if (/\b(?:w:)?fldSimple\b|\b(?:w:)?fldChar\b|\b(?:w:)?instrText\b/u.test(xml)) {
96
- return {
97
- featureKey: "fields",
98
- label: "Word field content",
99
- detail
100
- };
101
- }
102
- if (/\b(?:w:)?sdt\b/u.test(xml)) {
103
- return {
104
- featureKey: "content-controls",
105
- label: "Content control",
106
- detail
107
- };
108
- }
109
- if (/\b(?:w:)?customXml\b/u.test(xml)) {
110
- return {
111
- featureKey: "custom-xml",
112
- label: "Custom XML wrapper",
113
- detail
114
- };
115
- }
116
- if (/\b(?:w:)?altChunk\b/u.test(xml)) {
117
- return {
118
- featureKey: "alt-chunk",
119
- label: "Alternate content import",
120
- detail
121
- };
122
- }
123
- if (/\b(?:w:)?object\b|\b(?:o:)?OLEObject\b/u.test(xml)) {
124
- return {
125
- featureKey: "embedded-objects",
126
- label: "Embedded object",
127
- detail
128
- };
129
- }
130
- if (/\b(?:mc:)?AlternateContent\b/u.test(xml)) {
131
- return {
132
- featureKey: "alternate-content",
133
- label: "Markup compatibility block",
134
- detail
135
- };
136
- }
137
- return {
138
- featureKey: "unknown-ooxml",
139
- label: "Unsupported OOXML fragment",
140
- detail
141
- };
142
- }
143
- function createDetail(fragment) {
144
- const detail = [
145
- `Preserved whole-unit from ${fragment.lastKnownRange.from}-${fragment.lastKnownRange.to}.`,
146
- fragment.packagePartName ? `Part ${fragment.packagePartName}.` : null,
147
- fragment.relationshipId ? `Relationship ${fragment.relationshipId}.` : null
148
- ].filter(Boolean).join(" ");
149
- return detail.length > 0 ? detail : "Preserved whole-unit to keep unsupported OOXML intact.";
150
- }
151
- function normalizeOpaqueFragmentMap(store) {
152
- return store && typeof store === "object" && store.opaqueFragments && typeof store.opaqueFragments === "object" ? store.opaqueFragments : {};
153
- }
154
-
155
- // src/runtime/story-context.ts
156
- function collectSectionContexts(document) {
157
- const sections = [];
158
- let sectionIndex = 0;
159
- for (const block of document.content.children) {
160
- if (block.type !== "section_break") {
161
- continue;
162
- }
163
- sections.push({
164
- index: sectionIndex,
165
- properties: block.sectionProperties
166
- });
167
- sectionIndex += 1;
168
- }
169
- sections.push({
170
- index: sectionIndex,
171
- properties: document.subParts?.finalSectionProperties
172
- });
173
- return sections;
174
- }
175
- function resolveSectionVariants(kind, sectionIndex, explicitReferences, documents) {
176
- if (explicitReferences && explicitReferences.length > 0) {
177
- return explicitReferences.map((ref) => ({
178
- variant: ref.variant,
179
- relationshipId: ref.relationshipId
180
- }));
181
- }
182
- return documents.filter(
183
- (entry) => entry.sectionIndex === void 0 || entry.sectionIndex === sectionIndex
184
- ).map((entry) => ({
185
- variant: entry.variant,
186
- relationshipId: entry.relationshipId
187
- }));
188
- }
189
- function findHeaderFooterDocumentEntry(document, target) {
190
- const documents = target.kind === "header" ? document.subParts?.headers ?? [] : document.subParts?.footers ?? [];
191
- const matches = documents.filter(
192
- (entry) => entry.relationshipId === target.relationshipId && entry.variant === target.variant
193
- );
194
- if (matches.length === 0) {
195
- return void 0;
196
- }
197
- if (target.sectionIndex !== void 0) {
198
- return matches.find((entry) => entry.sectionIndex === target.sectionIndex) ?? matches.find((entry) => entry.sectionIndex === void 0) ?? matches[0];
199
- }
200
- return matches[0];
201
- }
202
- function sectionSupportsStoryTarget(document, sectionIndex, target) {
203
- if (!findHeaderFooterDocumentEntry(document, target)) {
204
- return false;
205
- }
206
- const section = collectSectionContexts(document).find(
207
- (candidate) => candidate.index === sectionIndex
208
- );
209
- if (!section) {
210
- return false;
211
- }
212
- const variants = resolveSectionVariants(
213
- target.kind,
214
- sectionIndex,
215
- target.kind === "header" ? section.properties?.headerReferences : section.properties?.footerReferences,
216
- target.kind === "header" ? document.subParts?.headers ?? [] : document.subParts?.footers ?? []
217
- );
218
- return variants.some(
219
- (variant) => variant.relationshipId === target.relationshipId && variant.variant === target.variant
220
- );
221
- }
222
- function normalizeHeaderFooterTarget(document, target, preferredSectionIndex) {
223
- if (!findHeaderFooterDocumentEntry(document, target)) {
224
- return void 0;
225
- }
226
- if (target.sectionIndex !== void 0) {
227
- return sectionSupportsStoryTarget(document, target.sectionIndex, target) ? target : void 0;
228
- }
229
- const candidateIndexes = collectSectionContexts(document).map((section) => section.index).filter(
230
- (sectionIndex) => sectionSupportsStoryTarget(document, sectionIndex, target)
231
- );
232
- if (candidateIndexes.length === 0) {
233
- return void 0;
234
- }
235
- const resolvedSectionIndex = preferredSectionIndex !== void 0 && candidateIndexes.includes(preferredSectionIndex) ? preferredSectionIndex : candidateIndexes[0];
236
- return {
237
- ...target,
238
- sectionIndex: resolvedSectionIndex
239
- };
240
- }
241
-
242
- // src/runtime/story-targeting.ts
243
- function getStoryBlocks(document, target) {
244
- if (target.kind === "main") {
245
- return document.content.children;
246
- }
247
- const subParts = document.subParts;
248
- if (!subParts) {
249
- return [];
250
- }
251
- switch (target.kind) {
252
- case "header": {
253
- const resolvedTarget = normalizeHeaderFooterTarget(document, target);
254
- return (resolvedTarget && findHeaderFooterDocumentEntry(document, resolvedTarget)?.blocks) ?? [];
255
- }
256
- case "footer": {
257
- const resolvedTarget = normalizeHeaderFooterTarget(document, target);
258
- return (resolvedTarget && findHeaderFooterDocumentEntry(document, resolvedTarget)?.blocks) ?? [];
259
- }
260
- case "footnote":
261
- return subParts.footnoteCollection?.footnotes[target.noteId]?.blocks ?? [];
262
- case "endnote":
263
- return subParts.footnoteCollection?.endnotes[target.noteId]?.blocks ?? [];
264
- }
265
- }
266
-
267
- // src/runtime/numbering-prefix.ts
268
- var DEFAULT_START_AT = 1;
269
- function createNumberingPrefixResolver(catalog) {
270
- const sequenceStates = /* @__PURE__ */ new Map();
271
- function resolveInternal(numbering) {
272
- if (!numbering) {
273
- return null;
274
- }
275
- const instance = catalog.instances[numbering.numberingInstanceId];
276
- if (!instance) {
277
- return null;
278
- }
279
- const definition = catalog.abstractDefinitions[instance.abstractNumberingId];
280
- if (!definition) {
281
- return null;
282
- }
283
- const levelDefinitions = new Map(
284
- definition.levels.map((level) => [level.level, level])
285
- );
286
- const levelDefinition = levelDefinitions.get(numbering.level);
287
- if (!levelDefinition || levelDefinition.format === "none") {
288
- return null;
289
- }
290
- const sequenceState = getSequenceState(sequenceStates, numbering.numberingInstanceId);
291
- advanceSequence(sequenceState, numbering.level, levelDefinitions, instance.overrides);
292
- const effectiveLevelDefs = levelDefinition.isLegalNumbering ? new Map(Array.from(levelDefinitions.entries()).map(([k, v]) => [k, { ...v, format: "decimal" }])) : levelDefinitions;
293
- const text = renderLevelText(levelDefinition.text, sequenceState.counters, effectiveLevelDefs);
294
- if (text === null) return null;
295
- return { text, suffix: levelDefinition.suffix };
296
- }
297
- return {
298
- resolve(numbering) {
299
- const result = resolveInternal(numbering);
300
- return result?.text ?? null;
301
- },
302
- resolveDetailed(numbering) {
303
- return resolveInternal(numbering);
304
- }
305
- };
306
- }
307
- function getSequenceState(states, numberingInstanceId) {
308
- const existing = states.get(numberingInstanceId);
309
- if (existing) {
310
- return existing;
311
- }
312
- const created = {
313
- counters: [],
314
- lastLevel: null
315
- };
316
- states.set(numberingInstanceId, created);
317
- return created;
318
- }
319
- function advanceSequence(state, currentLevel, levelDefinitions, overrides) {
320
- if (state.lastLevel !== null && currentLevel <= state.lastLevel) {
321
- state.counters.length = currentLevel + 1;
322
- }
323
- const startAt = getLevelStartAt(currentLevel, levelDefinitions, overrides);
324
- const currentValue = state.counters[currentLevel];
325
- state.counters[currentLevel] = currentValue === void 0 ? startAt : currentValue + 1;
326
- state.lastLevel = currentLevel;
327
- }
328
- function getLevelStartAt(level, levelDefinitions, overrides) {
329
- const override = overrides.find((entry) => entry.level === level);
330
- if (override?.startAt !== void 0) {
331
- return override.startAt;
332
- }
333
- return levelDefinitions.get(level)?.startAt ?? DEFAULT_START_AT;
334
- }
335
- function renderLevelText(text, counters, levelDefinitions) {
336
- if (!text) {
337
- return null;
338
- }
339
- if (!text.includes("%")) {
340
- return text;
341
- }
342
- const rendered = text.replace(/%([1-9])/g, (_match, token) => {
343
- const level = Number.parseInt(token, 10) - 1;
344
- const counter = counters[level];
345
- if (counter === void 0) {
346
- return "";
347
- }
348
- const format = levelDefinitions.get(level)?.format ?? "decimal";
349
- return formatCounter(counter, format);
350
- });
351
- return rendered.trim().length > 0 ? rendered : null;
352
- }
353
- function formatCounter(value, format) {
354
- switch (format) {
355
- case "decimal":
356
- return String(value);
357
- case "decimalZero":
358
- return String(value).padStart(2, "0");
359
- case "upperLetter":
360
- return toAlphabetic(value).toUpperCase();
361
- case "lowerLetter":
362
- return toAlphabetic(value).toLowerCase();
363
- case "upperRoman":
364
- return toRoman(value).toUpperCase();
365
- case "lowerRoman":
366
- return toRoman(value).toLowerCase();
367
- case "none":
368
- return "";
369
- default:
370
- return String(value);
371
- }
372
- }
373
- function toAlphabetic(value) {
374
- if (value <= 0) {
375
- return String(value);
376
- }
377
- let remainder = value;
378
- let result = "";
379
- while (remainder > 0) {
380
- remainder -= 1;
381
- result = String.fromCharCode(65 + remainder % 26) + result;
382
- remainder = Math.floor(remainder / 26);
383
- }
384
- return result;
385
- }
386
- function toRoman(value) {
387
- if (value <= 0 || value >= 4e3) {
388
- return String(value);
389
- }
390
- const numerals = [
391
- [1e3, "M"],
392
- [900, "CM"],
393
- [500, "D"],
394
- [400, "CD"],
395
- [100, "C"],
396
- [90, "XC"],
397
- [50, "L"],
398
- [40, "XL"],
399
- [10, "X"],
400
- [9, "IX"],
401
- [5, "V"],
402
- [4, "IV"],
403
- [1, "I"]
404
- ];
405
- let remaining = value;
406
- let result = "";
407
- for (const [amount, numeral] of numerals) {
408
- while (remaining >= amount) {
409
- remaining -= amount;
410
- result += numeral;
411
- }
412
- }
413
- return result;
414
- }
415
-
416
- // src/runtime/surface-projection.ts
417
- function createEditorSurfaceSnapshot(document, _selection, activeStory = { kind: "main" }) {
418
- const root = normalizeDocumentRoot({
419
- type: "doc",
420
- children: [...getStoryBlocks(document, activeStory)]
421
- });
422
- const blocks = [];
423
- const lockedFragmentIds = [];
424
- const numberingPrefixResolver = createNumberingPrefixResolver(document.numbering);
425
- let cursor = 0;
426
- const counters = {
427
- paragraph: 0,
428
- table: 0,
429
- opaque: 0,
430
- sdt: 0,
431
- customXml: 0,
432
- altChunk: 0
433
- };
434
- for (let index = 0; index < root.children.length; index += 1) {
435
- const surfaceBlock = createSurfaceBlock(
436
- root.children[index],
437
- document,
438
- cursor,
439
- counters,
440
- numberingPrefixResolver
441
- );
442
- blocks.push(surfaceBlock.block);
443
- lockedFragmentIds.push(...surfaceBlock.lockedFragmentIds);
444
- cursor = surfaceBlock.nextCursor;
445
- if (index < root.children.length - 1 && root.children[index + 1]?.type === "paragraph") {
446
- cursor += 1;
447
- }
448
- }
449
- const secondaryStories = createSecondaryStorySurfaces(document);
450
- return {
451
- storySize: cursor,
452
- plainText: createPlainText(blocks),
453
- blocks,
454
- lockedFragmentIds,
455
- secondaryStories
456
- };
457
- }
458
- function createSurfaceBlock(block, document, cursor, counters, numberingPrefixResolver) {
459
- if (block.type === "opaque_block") {
460
- const fragment = getOpaqueFragment(document.preservation, block.fragmentId);
461
- const descriptor = fragment ? describeOpaqueFragment(fragment) : null;
462
- const blockId = `opaque-${counters.opaque}`;
463
- counters.opaque += 1;
464
- return {
465
- block: {
466
- blockId,
467
- kind: "opaque_block",
468
- from: cursor,
469
- to: cursor + 1,
470
- fragmentId: block.fragmentId,
471
- warningId: block.warningId,
472
- label: descriptor?.label ?? "Unsupported OOXML fragment",
473
- detail: descriptor?.detail ?? "Locked whole-unit to keep unsupported OOXML intact through export.",
474
- state: "locked-preserve-only"
475
- },
476
- lockedFragmentIds: [block.fragmentId],
477
- nextCursor: cursor + 1
478
- };
479
- }
480
- if (block.type === "table") {
481
- const tableIndex = counters.table;
482
- counters.table += 1;
483
- return createTableBlock(
484
- tableIndex,
485
- block,
486
- document,
487
- cursor,
488
- counters,
489
- numberingPrefixResolver
490
- );
491
- }
492
- if (block.type === "sdt") {
493
- const sdtIndex = counters.sdt;
494
- counters.sdt += 1;
495
- return createSdtBlock(
496
- sdtIndex,
497
- block,
498
- document,
499
- cursor,
500
- counters,
501
- numberingPrefixResolver
502
- );
503
- }
504
- if (block.type === "custom_xml") {
505
- const blockId = `custom-xml-${counters.customXml}`;
506
- counters.customXml += 1;
507
- return {
508
- block: {
509
- blockId,
510
- kind: "opaque_block",
511
- from: cursor,
512
- to: cursor + 1,
513
- fragmentId: blockId,
514
- warningId: blockId,
515
- label: "Custom XML block",
516
- detail: block.uri || block.element ? `Custom XML wrapper ${[block.element, block.uri].filter(Boolean).join(" ")} preserved as a read-only block.` : "Custom XML wrapper preserved as a read-only block.",
517
- state: "locked-preserve-only"
518
- },
519
- lockedFragmentIds: [],
520
- nextCursor: cursor + 1
521
- };
522
- }
523
- if (block.type === "alt_chunk") {
524
- const blockId = `alt-chunk-${counters.altChunk}`;
525
- counters.altChunk += 1;
526
- return {
527
- block: {
528
- blockId,
529
- kind: "opaque_block",
530
- from: cursor,
531
- to: cursor + 1,
532
- fragmentId: blockId,
533
- warningId: blockId,
534
- label: "AltChunk import",
535
- detail: `Alternate content import remains read-only through relationship ${block.relationshipId}.`,
536
- state: "locked-preserve-only"
537
- },
538
- lockedFragmentIds: [],
539
- nextCursor: cursor + 1
540
- };
541
- }
542
- if (block.type === "section_break") {
543
- const blockId = `section-break-${counters.opaque}`;
544
- counters.opaque += 1;
545
- return {
546
- block: {
547
- blockId,
548
- kind: "opaque_block",
549
- from: cursor,
550
- to: cursor + 1,
551
- fragmentId: blockId,
552
- warningId: blockId,
553
- label: "Section break",
554
- detail: "Section properties preserved as a read-only boundary.",
555
- state: "locked-preserve-only"
556
- },
557
- lockedFragmentIds: [],
558
- nextCursor: cursor + 1
559
- };
560
- }
561
- const paragraphIndex = counters.paragraph;
562
- counters.paragraph += 1;
563
- return createParagraphBlock(
564
- paragraphIndex,
565
- block,
566
- document,
567
- cursor,
568
- numberingPrefixResolver
569
- );
570
- }
571
- function createTableBlock(tableIndex, table, document, cursor, counters, numberingPrefixResolver) {
572
- const lockedFragmentIds = [];
573
- let innerCursor = cursor;
574
- const rows = [];
575
- const rowSpans = computeTableRowSpans(table);
576
- for (const [rowIndex, row] of table.rows.entries()) {
577
- const cells = [];
578
- for (const [cellIndex, cell] of row.cells.entries()) {
579
- const cellContent = [];
580
- for (const child of cell.children) {
581
- const result = createSurfaceBlock(
582
- child,
583
- document,
584
- innerCursor,
585
- counters,
586
- numberingPrefixResolver
587
- );
588
- cellContent.push(result.block);
589
- lockedFragmentIds.push(...result.lockedFragmentIds);
590
- innerCursor = result.nextCursor;
591
- }
592
- const cellBorders = resolveCellBorderStyles(cell.borders);
593
- cells.push({
594
- gridSpan: cell.gridSpan ?? 1,
595
- verticalMerge: cell.verticalMerge ?? null,
596
- colspan: cell.gridSpan ?? 1,
597
- rowspan: rowSpans.get(`${rowIndex}:${cellIndex}`) ?? 1,
598
- ...cell.shading?.fill ? { backgroundColor: `#${cell.shading.fill}` } : {},
599
- ...cell.verticalAlign ? { verticalAlign: cell.verticalAlign } : {},
600
- ...cellBorders.borderTop ? { borderTop: cellBorders.borderTop } : {},
601
- ...cellBorders.borderRight ? { borderRight: cellBorders.borderRight } : {},
602
- ...cellBorders.borderBottom ? { borderBottom: cellBorders.borderBottom } : {},
603
- ...cellBorders.borderLeft ? { borderLeft: cellBorders.borderLeft } : {},
604
- content: cellContent
605
- });
606
- }
607
- rows.push({
608
- cells,
609
- ...row.gridBefore !== void 0 ? { gridBefore: row.gridBefore } : {},
610
- ...row.gridAfter !== void 0 ? { gridAfter: row.gridAfter } : {},
611
- ...row.height !== void 0 ? { height: row.height } : {},
612
- ...row.heightRule ? { heightRule: row.heightRule } : {},
613
- ...row.isHeader ? { isHeader: row.isHeader } : {}
614
- });
615
- }
616
- return {
617
- block: {
618
- blockId: `table-${tableIndex}`,
619
- kind: "table",
620
- from: cursor,
621
- to: innerCursor,
622
- styleId: table.styleId,
623
- gridColumns: table.gridColumns,
624
- ...table.alignment ? { alignment: table.alignment } : {},
625
- ...table.tblLook ? { tblLook: table.tblLook } : {},
626
- rows
627
- },
628
- lockedFragmentIds,
629
- nextCursor: innerCursor
630
- };
631
- }
632
- function computeTableRowSpans(table) {
633
- const positionedRows = table.rows.map((row) => {
634
- let startColumn = 0;
635
- return row.cells.map((cell, cellIndex) => {
636
- const width = cell.gridSpan ?? 1;
637
- const positionedCell = {
638
- cell,
639
- cellIndex,
640
- startColumn,
641
- endColumn: startColumn + width - 1
642
- };
643
- startColumn += width;
644
- return positionedCell;
645
- });
646
- });
647
- const rowSpans = /* @__PURE__ */ new Map();
648
- for (const [rowIndex, row] of positionedRows.entries()) {
649
- for (const positionedCell of row) {
650
- if (positionedCell.cell.verticalMerge !== "restart") {
651
- rowSpans.set(`${rowIndex}:${positionedCell.cellIndex}`, 1);
652
- continue;
653
- }
654
- let rowspan = 1;
655
- for (let nextRowIndex = rowIndex + 1; nextRowIndex < positionedRows.length; nextRowIndex += 1) {
656
- const continuedCell = positionedRows[nextRowIndex]?.find(
657
- (candidate) => candidate.cell.verticalMerge === "continue" && candidate.startColumn === positionedCell.startColumn && candidate.endColumn === positionedCell.endColumn
658
- );
659
- if (!continuedCell) {
660
- break;
661
- }
662
- rowspan += 1;
663
- }
664
- rowSpans.set(`${rowIndex}:${positionedCell.cellIndex}`, rowspan);
665
- }
666
- }
667
- return rowSpans;
668
- }
669
- function resolveCellBorderStyles(borders) {
670
- if (!borders) return {};
671
- const result = {};
672
- const sides = [["top", "borderTop"], ["right", "borderRight"], ["bottom", "borderBottom"], ["left", "borderLeft"]];
673
- for (const [side, key] of sides) {
674
- const spec = borders[side];
675
- if (!spec || spec.value === "none" || spec.value === "nil") continue;
676
- const width = spec.size ? `${Math.max(1, Math.round(spec.size / 8))}px` : "1px";
677
- const style = spec.value === "double" ? "double" : spec.value === "dashed" || spec.value === "dashSmallGap" ? "dashed" : spec.value === "dotted" ? "dotted" : "solid";
678
- const color = spec.color && spec.color !== "auto" ? `#${spec.color}` : "currentColor";
679
- result[key] = `${width} ${style} ${color}`;
680
- }
681
- return result;
682
- }
683
- function createSdtBlock(sdtIndex, block, document, cursor, counters, numberingPrefixResolver) {
684
- const children = [];
685
- const lockedFragmentIds = [];
686
- let innerCursor = cursor;
687
- for (const child of block.children) {
688
- const result = createSurfaceBlock(
689
- child,
690
- document,
691
- innerCursor,
692
- counters,
693
- numberingPrefixResolver
694
- );
695
- children.push(result.block);
696
- lockedFragmentIds.push(...result.lockedFragmentIds);
697
- innerCursor = result.nextCursor;
698
- }
699
- return {
700
- block: {
701
- blockId: `sdt-${sdtIndex}`,
702
- kind: "sdt_block",
703
- from: cursor,
704
- to: innerCursor,
705
- ...block.properties.sdtType ? { sdtType: block.properties.sdtType } : {},
706
- ...block.properties.alias ? { alias: block.properties.alias } : {},
707
- ...block.properties.tag ? { tag: block.properties.tag } : {},
708
- ...block.properties.lock ? { lock: block.properties.lock } : {},
709
- ...block.properties.checkbox ? { checkboxChecked: block.properties.checkbox.checked } : {},
710
- ...block.properties.datePicker?.fullDate ? { dateValue: block.properties.datePicker.fullDate } : {},
711
- ...block.properties.dropdownList ? { dropdownItems: block.properties.dropdownList } : {},
712
- ...block.properties.comboBox ? { comboBoxItems: block.properties.comboBox } : {},
713
- ...block.properties.showingPlcHdr ? { showingPlcHdr: true } : {},
714
- children
715
- },
716
- lockedFragmentIds,
717
- nextCursor: innerCursor
718
- };
719
- }
720
- function createParagraphBlock(paragraphIndex, paragraph, document, start, numberingPrefixResolver) {
721
- const accumulator = {
722
- blockId: `paragraph-${paragraphIndex}`,
723
- kind: "paragraph",
724
- from: start,
725
- to: start,
726
- ...paragraph.styleId ? { styleId: paragraph.styleId } : {},
727
- ...paragraph.numbering ? { numbering: paragraph.numbering } : {},
728
- ...paragraph.numbering ? (() => {
729
- const detailed = numberingPrefixResolver.resolveDetailed(paragraph.numbering);
730
- return detailed ? {
731
- numberingPrefix: detailed.text,
732
- ...detailed.suffix ? { numberingSuffix: detailed.suffix } : {}
733
- } : {};
734
- })() : {},
735
- ...paragraph.alignment ? { alignment: paragraph.alignment } : {},
736
- ...paragraph.spacing ? { spacing: paragraph.spacing } : {},
737
- ...paragraph.contextualSpacing !== void 0 ? { contextualSpacing: paragraph.contextualSpacing } : {},
738
- ...paragraph.indentation ? { indentation: paragraph.indentation } : {},
739
- ...paragraph.borders ? { borders: paragraph.borders } : {},
740
- ...paragraph.shading ? { shading: paragraph.shading } : {},
741
- ...paragraph.tabStops && paragraph.tabStops.length > 0 ? { tabStops: paragraph.tabStops.map((tabStop) => toSurfaceTabStop(tabStop)) } : {},
742
- ...paragraph.keepNext ? { keepNext: true } : {},
743
- ...paragraph.keepLines ? { keepLines: true } : {},
744
- ...paragraph.pageBreakBefore ? { pageBreakBefore: true } : {},
745
- ...paragraph.outlineLevel !== void 0 ? { outlineLevel: paragraph.outlineLevel } : {},
746
- ...paragraph.bidi ? { bidi: true } : {},
747
- ...paragraph.suppressLineNumbers ? { suppressLineNumbers: true } : {},
748
- segments: []
749
- };
750
- const lockedFragmentIds = [];
751
- let cursor = start;
752
- const children = Array.isArray(paragraph.children) ? paragraph.children : [];
753
- for (const child of children) {
754
- const result = appendInlineSegments(accumulator, child, document, cursor);
755
- cursor = result.nextCursor;
756
- lockedFragmentIds.push(...result.lockedFragmentIds);
757
- }
758
- accumulator.to = cursor;
759
- return {
760
- block: accumulator,
761
- nextCursor: cursor,
762
- lockedFragmentIds
763
- };
764
- }
765
- function appendInlineSegments(paragraph, node, document, start, hyperlinkHref) {
766
- switch (node.type) {
767
- case "text":
768
- paragraph.segments.push({
769
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
770
- kind: "text",
771
- from: start,
772
- to: start + Array.from(node.text).length,
773
- text: node.text,
774
- ...node.marks ? (() => {
775
- const result = cloneMarks(node.marks);
776
- return {
777
- ...result.marks.length > 0 ? { marks: result.marks } : {},
778
- ...result.markAttrs ? { markAttrs: result.markAttrs } : {}
779
- };
780
- })() : {},
781
- ...hyperlinkHref ? { hyperlinkHref } : {}
782
- });
783
- return { nextCursor: start + Array.from(node.text).length, lockedFragmentIds: [] };
784
- case "tab":
785
- paragraph.segments.push({
786
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
787
- kind: "tab",
788
- from: start,
789
- to: start + 1,
790
- ...hyperlinkHref ? { hyperlinkHref } : {}
791
- });
792
- return { nextCursor: start + 1, lockedFragmentIds: [] };
793
- case "hard_break":
794
- paragraph.segments.push({
795
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
796
- kind: "hard_break",
797
- from: start,
798
- to: start + 1,
799
- ...hyperlinkHref ? { hyperlinkHref } : {}
800
- });
801
- return { nextCursor: start + 1, lockedFragmentIds: [] };
802
- case "hyperlink": {
803
- let cursor = start;
804
- for (const child of node.children) {
805
- const result = appendInlineSegments(paragraph, child, document, cursor, node.href);
806
- cursor = result.nextCursor;
807
- }
808
- return { nextCursor: cursor, lockedFragmentIds: [] };
809
- }
810
- case "image":
811
- paragraph.segments.push({
812
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
813
- kind: "image",
814
- from: start,
815
- to: start + 1,
816
- mediaId: node.mediaId,
817
- altText: node.altText,
818
- state: hasMediaItem(document.media, node.mediaId) ? "editable" : "missing",
819
- ...node.display ? { display: node.display } : {},
820
- detail: node.display === "floating" ? createFloatingImageDetail(node.altText, node.floating) : node.altText ? `Alt text ${node.altText}.` : "Inline image remains a whole-unit render surface."
821
- });
822
- return { nextCursor: start + 1, lockedFragmentIds: [] };
823
- case "opaque_inline": {
824
- const fragment = getOpaqueFragment(document.preservation, node.fragmentId);
825
- const descriptor = fragment ? describeOpaqueFragment(fragment) : null;
826
- const preview = fragment ? describePreservedInlinePreview(fragment.payloadReference) : null;
827
- paragraph.segments.push({
828
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
829
- kind: "opaque_inline",
830
- from: start,
831
- to: start + 1,
832
- fragmentId: node.fragmentId,
833
- warningId: node.warningId,
834
- label: preview?.label ?? descriptor?.label ?? "Unsupported inline OOXML",
835
- detail: preview?.detail ?? descriptor?.detail ?? "Locked whole-unit to keep unsupported inline OOXML intact through export.",
836
- ...preview?.presentation ? { presentation: preview.presentation } : {},
837
- state: "locked-preserve-only"
838
- });
839
- return { nextCursor: start + 1, lockedFragmentIds: [node.fragmentId] };
840
- }
841
- case "chart_preview":
842
- return appendComplexPreviewSegment(paragraph, node, start, "Embedded chart", createChartDetail(node));
843
- case "smartart_preview":
844
- return appendComplexPreviewSegment(paragraph, node, start, "SmartArt diagram", createSmartArtDetail(node));
845
- case "shape":
846
- return appendComplexPreviewSegment(
847
- paragraph,
848
- node,
849
- start,
850
- node.isTextBox ? "Text box" : "Drawing shape",
851
- createShapeDetail(node)
852
- );
853
- case "wordart":
854
- return appendComplexPreviewSegment(paragraph, node, start, "WordArt", createWordArtDetail(node));
855
- case "vml_shape":
856
- return appendComplexPreviewSegment(paragraph, node, start, "Legacy VML drawing", createVmlDetail(node));
857
- case "symbol":
858
- paragraph.segments.push({
859
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
860
- kind: "text",
861
- from: start,
862
- to: start + 1,
863
- text: node.char ? String.fromCodePoint(parseInt(node.char, 16)) : "\uFFFD"
864
- });
865
- return { nextCursor: start + 1, lockedFragmentIds: [] };
866
- case "column_break":
867
- paragraph.segments.push({
868
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
869
- kind: "opaque_inline",
870
- from: start,
871
- to: start + 1,
872
- fragmentId: "",
873
- warningId: "",
874
- label: "Column break",
875
- detail: "Column break marker preserved for export.",
876
- state: "locked-preserve-only"
877
- });
878
- return { nextCursor: start + 1, lockedFragmentIds: [] };
879
- case "footnote_ref":
880
- paragraph.segments.push({
881
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
882
- kind: "note_ref",
883
- from: start,
884
- to: start + 1,
885
- noteKind: node.noteKind ?? "footnote",
886
- noteId: node.noteId ?? "",
887
- label: node.noteId ?? "*"
888
- });
889
- return { nextCursor: start + 1, lockedFragmentIds: [] };
890
- case "field": {
891
- const isSupportedField = node.fieldFamily === "REF" || node.fieldFamily === "PAGEREF" || node.fieldFamily === "NOTEREF" || node.fieldFamily === "TOC";
892
- if (node.children && node.children.length > 0) {
893
- let cursor = start;
894
- const lockedIds = [];
895
- for (const child of node.children) {
896
- const result = appendInlineSegments(paragraph, child, document, cursor);
897
- cursor = result.nextCursor;
898
- lockedIds.push(...result.lockedFragmentIds);
899
- }
900
- return { nextCursor: cursor, lockedFragmentIds: lockedIds };
901
- }
902
- if (isSupportedField) {
903
- const fieldLabel = node.fieldFamily === "TOC" ? "Table of Contents" : `${node.fieldFamily ?? "Field"}: ${node.fieldTarget ?? node.instruction.trim()}`;
904
- paragraph.segments.push({
905
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
906
- kind: "field_ref",
907
- from: start,
908
- to: start + 1,
909
- fieldFamily: node.fieldFamily,
910
- fieldTarget: node.fieldTarget,
911
- instruction: node.instruction,
912
- refreshStatus: node.refreshStatus ?? "stale",
913
- label: fieldLabel
914
- });
915
- return { nextCursor: start + 1, lockedFragmentIds: [] };
916
- }
917
- paragraph.segments.push({
918
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
919
- kind: "opaque_inline",
920
- from: start,
921
- to: start + 1,
922
- fragmentId: "",
923
- warningId: "",
924
- label: "Field",
925
- detail: `Preserve-only field: ${node.instruction.trim()}`,
926
- state: "locked-preserve-only"
927
- });
928
- return { nextCursor: start + 1, lockedFragmentIds: [] };
929
- }
930
- case "bookmark_start":
931
- case "bookmark_end":
932
- return { nextCursor: start, lockedFragmentIds: [] };
933
- default:
934
- return { nextCursor: start + 1, lockedFragmentIds: [] };
935
- }
936
- }
937
- function appendComplexPreviewSegment(paragraph, node, start, label, detail) {
938
- paragraph.segments.push({
939
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
940
- kind: "opaque_inline",
941
- from: start,
942
- to: start + 1,
943
- fragmentId: `complex:${label.replace(/\s/g, "-").toLowerCase()}:${start}`,
944
- warningId: `warning:complex-preview:${start}`,
945
- label,
946
- detail,
947
- state: "locked-preserve-only"
948
- });
949
- return { nextCursor: start + 1, lockedFragmentIds: [] };
950
- }
951
- function createChartDetail(node) {
952
- const parts = ["Embedded chart."];
953
- if (node.previewMediaId) {
954
- parts.push(`Preview available via fallback image (${node.previewMediaId}).`);
955
- } else {
956
- parts.push("No fallback preview image found; chart data preserved in package.");
957
- }
958
- parts.push("Edit in Word to modify chart data. Original DrawingML preserved for lossless export.");
959
- return parts.join(" ");
960
- }
961
- function createSmartArtDetail(node) {
962
- const parts = ["SmartArt diagram."];
963
- if (node.previewMediaId) {
964
- parts.push(`Preview available via fallback image (${node.previewMediaId}).`);
965
- } else {
966
- parts.push("No fallback preview image found; diagram structure preserved in package.");
967
- }
968
- parts.push("Edit in Word to modify diagram layout and content. Original DrawingML preserved for lossless export.");
969
- return parts.join(" ");
970
- }
971
- function createShapeDetail(node) {
972
- if (node.isTextBox) {
973
- const parts2 = ["Text box."];
974
- if (node.text) parts2.push(`Content: "${node.text}".`);
975
- parts2.push("Text content is visible; formatting and geometry preserved for export.");
976
- return parts2.join(" ");
977
- }
978
- const parts = ["Drawing shape."];
979
- if (node.geometry) parts.push(`Geometry: ${node.geometry}.`);
980
- if (node.text) parts.push(`Text content: "${node.text}".`);
981
- parts.push("Visual geometry is preview-only. Original DrawingML preserved for export.");
982
- return parts.join(" ");
983
- }
984
- function createWordArtDetail(node) {
985
- const parts = ["WordArt decorative text."];
986
- if (node.text) parts.push(`Text: "${node.text}".`);
987
- if (node.geometry) parts.push(`Effect: ${node.geometry}.`);
988
- parts.push("Text effect is preview-only. Edit in Word for full formatting. Original DrawingML preserved for export.");
989
- return parts.join(" ");
990
- }
991
- function createVmlDetail(node) {
992
- const parts = ["Legacy VML drawing."];
993
- if (node.shapeType) parts.push(`Type: ${node.shapeType}.`);
994
- if (node.text) parts.push(`Text content: "${node.text}".`);
995
- parts.push("VML content is preview-only. Edit in Word for full control. Original VML XML preserved for export.");
996
- return parts.join(" ");
997
- }
998
- function createPlainText(blocks) {
999
- const text = [];
1000
- for (const block of blocks) {
1001
- if (block.kind === "opaque_block") {
1002
- if (block.fragmentId.startsWith("preview:")) {
1003
- continue;
1004
- }
1005
- text.push("\uFFFA");
1006
- continue;
1007
- }
1008
- if (block.kind === "table") {
1009
- for (const row of block.rows) {
1010
- for (const cell of row.cells) {
1011
- text.push(createPlainText(cell.content));
1012
- }
1013
- }
1014
- continue;
1015
- }
1016
- if (block.kind === "sdt_block") {
1017
- text.push(createPlainText(block.children));
1018
- continue;
1019
- }
1020
- for (const segment of block.segments) {
1021
- switch (segment.kind) {
1022
- case "text":
1023
- text.push(segment.text);
1024
- break;
1025
- case "tab":
1026
- text.push(" ");
1027
- break;
1028
- case "hard_break":
1029
- text.push("\n");
1030
- break;
1031
- case "image":
1032
- text.push("\uFFFC");
1033
- break;
1034
- case "opaque_inline":
1035
- text.push("\uFFF9");
1036
- break;
1037
- }
1038
- }
1039
- }
1040
- return text.join("");
1041
- }
1042
- function createSecondaryStorySurfaces(document) {
1043
- const surfaces = [];
1044
- const subParts = document.subParts;
1045
- if (!subParts) {
1046
- return surfaces;
1047
- }
1048
- const numberingPrefixResolver = createNumberingPrefixResolver(document.numbering);
1049
- for (const section of collectSectionContexts(document)) {
1050
- const headerVariants = resolveSectionVariants(
1051
- "header",
1052
- section.index,
1053
- section.properties?.headerReferences,
1054
- subParts.headers ?? []
1055
- );
1056
- for (const headerVariant of headerVariants) {
1057
- const target = {
1058
- kind: "header",
1059
- relationshipId: headerVariant.relationshipId,
1060
- variant: headerVariant.variant,
1061
- sectionIndex: section.index
1062
- };
1063
- const header = findHeaderFooterDocumentEntry(document, target);
1064
- if (!header) {
1065
- continue;
1066
- }
1067
- surfaces.push(
1068
- createStorySurface(
1069
- target,
1070
- `Header \xB7 ${headerVariant.variant}`,
1071
- header.blocks,
1072
- document,
1073
- numberingPrefixResolver
1074
- )
1075
- );
1076
- }
1077
- const footerVariants = resolveSectionVariants(
1078
- "footer",
1079
- section.index,
1080
- section.properties?.footerReferences,
1081
- subParts.footers ?? []
1082
- );
1083
- for (const footerVariant of footerVariants) {
1084
- const target = {
1085
- kind: "footer",
1086
- relationshipId: footerVariant.relationshipId,
1087
- variant: footerVariant.variant,
1088
- sectionIndex: section.index
1089
- };
1090
- const footer = findHeaderFooterDocumentEntry(document, target);
1091
- if (!footer) {
1092
- continue;
1093
- }
1094
- surfaces.push(
1095
- createStorySurface(
1096
- target,
1097
- `Footer \xB7 ${footerVariant.variant}`,
1098
- footer.blocks,
1099
- document,
1100
- numberingPrefixResolver
1101
- )
1102
- );
1103
- }
1104
- }
1105
- const footnotes = Object.values(subParts.footnoteCollection?.footnotes ?? {}).sort(compareNoteIds);
1106
- for (const note of footnotes) {
1107
- const target = { kind: "footnote", noteId: note.noteId };
1108
- surfaces.push(createStorySurface(target, `Footnote ${note.noteId}`, note.blocks, document, numberingPrefixResolver));
1109
- }
1110
- const endnotes = Object.values(subParts.footnoteCollection?.endnotes ?? {}).sort(compareNoteIds);
1111
- for (const note of endnotes) {
1112
- const target = { kind: "endnote", noteId: note.noteId };
1113
- surfaces.push(createStorySurface(target, `Endnote ${note.noteId}`, note.blocks, document, numberingPrefixResolver));
1114
- }
1115
- return surfaces;
1116
- }
1117
- function createStorySurface(target, label, blocks, document, numberingPrefixResolver) {
1118
- const surfaceBlocks = [];
1119
- let cursor = 0;
1120
- const counters = {
1121
- paragraph: 0,
1122
- table: 0,
1123
- opaque: 0,
1124
- sdt: 0,
1125
- customXml: 0,
1126
- altChunk: 0
1127
- };
1128
- for (let index = 0; index < blocks.length; index += 1) {
1129
- const surfaceBlock = createSurfaceBlock(
1130
- blocks[index],
1131
- document,
1132
- cursor,
1133
- counters,
1134
- numberingPrefixResolver
1135
- );
1136
- surfaceBlocks.push(surfaceBlock.block);
1137
- cursor = surfaceBlock.nextCursor;
1138
- if (index < blocks.length - 1 && blocks[index + 1]?.type === "paragraph") {
1139
- cursor += 1;
1140
- }
1141
- }
1142
- return {
1143
- target,
1144
- label,
1145
- storySize: cursor,
1146
- blocks: surfaceBlocks
1147
- };
1148
- }
1149
- function compareNoteIds(left, right) {
1150
- return Number.parseInt(left.noteId, 10) - Number.parseInt(right.noteId, 10);
1151
- }
1152
- function toSurfaceTabStop(tabStop) {
1153
- return {
1154
- pos: tabStop.position,
1155
- ...tabStop.align ? { val: tabStop.align } : {},
1156
- ...tabStop.leader ? { leader: tabStop.leader } : {}
1157
- };
1158
- }
1159
- function describePreservedInlinePreview(payloadReference) {
1160
- if (/\b(?:w:)?proofErr\b/u.test(payloadReference)) {
1161
- const proofType = /\bw:type="([^"]+)"/u.exec(payloadReference)?.[1];
1162
- return {
1163
- label: "Proofing marker",
1164
- detail: proofType && proofType.trim().length > 0 ? `Word proofing marker (${proofType}) preserved for export safety.` : "Word proofing marker preserved for export safety.",
1165
- presentation: "quiet-marker"
1166
- };
1167
- }
1168
- if (/\b(?:w:)?lastRenderedPageBreak\b/u.test(payloadReference)) {
1169
- return {
1170
- label: "Rendered page break",
1171
- detail: "Word rendered page-break marker preserved for export safety.",
1172
- presentation: "quiet-marker"
1173
- };
1174
- }
1175
- if (/\b(?:w:)?permStart\b/u.test(payloadReference)) {
1176
- const editorGroup = /\bw:edGrp="([^"]+)"/u.exec(payloadReference)?.[1];
1177
- return {
1178
- label: "Protected range start",
1179
- detail: editorGroup && editorGroup.trim().length > 0 ? `Protected range start for ${editorGroup} preserved for export safety.` : "Protected range start preserved for export safety.",
1180
- presentation: "quiet-marker"
1181
- };
1182
- }
1183
- if (/\b(?:w:)?permEnd\b/u.test(payloadReference)) {
1184
- return {
1185
- label: "Protected range end",
1186
- detail: "Protected range end preserved for export safety.",
1187
- presentation: "quiet-marker"
1188
- };
1189
- }
1190
- if (/\b(?:w:)?bookmarkStart\b/u.test(payloadReference)) {
1191
- const name = /\bw:name="([^"]+)"/u.exec(payloadReference)?.[1];
1192
- return {
1193
- label: name ? `Bookmark \xB7 ${name}` : "Bookmark",
1194
- detail: name ? `Bookmark anchor "${name}" is preserved as a read-only inline token for export safety.` : "Bookmark anchor is preserved as a read-only inline token for export safety."
1195
- };
1196
- }
1197
- if (/\b(?:w:)?bookmarkEnd\b/u.test(payloadReference)) {
1198
- return {
1199
- label: "Bookmark end",
1200
- detail: "Bookmark end marker is preserved as a read-only inline token for export safety."
1201
- };
1202
- }
1203
- if (/\b(?:w:)?fldSimple\b|\b(?:w:)?fldChar\b|\b(?:w:)?instrText\b/u.test(payloadReference)) {
1204
- const simpleInstruction = /\bw:instr="([^"]*)"/u.exec(payloadReference)?.[1];
1205
- const complexInstruction = [...payloadReference.matchAll(/<(?:\w+:)?instrText\b[^>]*>([\s\S]*?)<\/(?:\w+:)?instrText>/gu)].map((match) => decodeXmlEntities(match[1] ?? "")).join("").trim();
1206
- const instruction = (simpleInstruction ?? complexInstruction ?? "").trim();
1207
- const family = /^([A-Z]+)/i.exec(instruction)?.[1]?.toUpperCase();
1208
- const label = family === "TOC" ? "Table of Contents field" : family ? `${family} field` : "Field";
1209
- return {
1210
- label,
1211
- detail: instruction.length > 0 ? `Read-only field preserved for export safety. Instruction: ${instruction}.` : "Read-only field preserved for export safety."
1212
- };
1213
- }
1214
- return null;
1215
- }
1216
- function decodeXmlEntities(text) {
1217
- return text.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, "&");
1218
- }
1219
- function cloneMarks(marks) {
1220
- const supported = [];
1221
- const attrs = {};
1222
- let shadingColor;
1223
- let highlightColor;
1224
- for (const mark of marks) {
1225
- switch (mark.type) {
1226
- case "bold":
1227
- case "italic":
1228
- case "underline":
1229
- case "strikethrough":
1230
- case "doubleStrikethrough":
1231
- case "vanish":
1232
- case "emboss":
1233
- case "imprint":
1234
- case "shadow":
1235
- supported.push(mark.type);
1236
- break;
1237
- case "position":
1238
- if (mark.val > 0) supported.push("superscript");
1239
- else if (mark.val < 0) supported.push("subscript");
1240
- break;
1241
- case "backgroundColor":
1242
- shadingColor = mark.color;
1243
- break;
1244
- case "highlight":
1245
- highlightColor = mark.color;
1246
- break;
1247
- case "charSpacing":
1248
- attrs.charSpacing = mark.val;
1249
- break;
1250
- case "kerning":
1251
- attrs.kerning = mark.val;
1252
- break;
1253
- case "textFill":
1254
- attrs.textFill = mark.xml;
1255
- break;
1256
- case "fontFamily":
1257
- attrs.fontFamily = mark.val;
1258
- break;
1259
- case "fontSize":
1260
- attrs.fontSize = mark.val;
1261
- break;
1262
- case "textColor":
1263
- attrs.textColor = mark.color;
1264
- break;
1265
- case "smallCaps":
1266
- supported.push("smallCaps");
1267
- break;
1268
- case "allCaps":
1269
- supported.push("allCaps");
1270
- break;
1271
- case "lang":
1272
- break;
1273
- }
1274
- }
1275
- if (highlightColor || shadingColor) {
1276
- attrs.backgroundColor = highlightColor ?? shadingColor;
1277
- }
1278
- const hasAttrs = Object.keys(attrs).length > 0;
1279
- return hasAttrs ? { marks: supported, markAttrs: attrs } : { marks: supported };
1280
- }
1281
- function normalizeDocumentRoot(content) {
1282
- if (content && typeof content === "object" && (content.type === "doc" || content.type === "document_root")) {
1283
- return content;
1284
- }
1285
- if (Array.isArray(content)) {
1286
- return {
1287
- type: "doc",
1288
- children: content.filter(
1289
- (value) => Boolean(value) && typeof value === "object" && (value.type === "paragraph" || value.type === "table" || value.type === "sdt" || value.type === "custom_xml" || value.type === "alt_chunk" || value.type === "opaque_block")
1290
- )
1291
- };
1292
- }
1293
- return {
1294
- type: "doc",
1295
- children: [{ type: "paragraph", children: [] }]
1296
- };
1297
- }
1298
- function createFloatingImageDetail(altText, floating) {
1299
- const parts = [altText ? `Alt text ${altText}.` : "Floating image rendered inline in the editor."];
1300
- if (floating?.wrap) {
1301
- parts.push(`Wrap ${floating.wrap}.`);
1302
- }
1303
- if (floating?.horizontalPosition?.align || floating?.horizontalPosition?.offset !== void 0) {
1304
- parts.push(
1305
- `Horizontal ${floating.horizontalPosition.align ?? floating.horizontalPosition.offset}.`
1306
- );
1307
- }
1308
- if (floating?.verticalPosition?.align || floating?.verticalPosition?.offset !== void 0) {
1309
- parts.push(
1310
- `Vertical ${floating.verticalPosition.align ?? floating.verticalPosition.offset}.`
1311
- );
1312
- }
1313
- return parts.join(" ");
1314
- }
1315
- function hasMediaItem(media, mediaId) {
1316
- return mediaId in media.items;
1317
- }
1318
-
1319
- // src/core/commands/structural-helpers.ts
1320
- function createNoopStructuralMutation(document, selection) {
1321
- return {
1322
- changed: false,
1323
- document,
1324
- selection
1325
- };
1326
- }
1327
- function createEmptyParagraph() {
1328
- return {
1329
- type: "paragraph",
1330
- children: []
1331
- };
1332
- }
1333
- function findTableCellParagraphSelection(document, tableBlockIndex, rowIndex, cellIndex) {
1334
- const surface = createEditorSurfaceSnapshot(document, createSelectionSnapshot(0, 0));
1335
- const tableBlock = surface.blocks[tableBlockIndex];
1336
- if (!tableBlock || tableBlock.kind !== "table") {
1337
- return null;
1338
- }
1339
- const paragraph = tableBlock.rows[rowIndex]?.cells[cellIndex]?.content.find(
1340
- (block) => block.kind === "paragraph"
1341
- );
1342
- if (!paragraph || paragraph.kind !== "paragraph") {
1343
- return null;
1344
- }
1345
- return createSelectionSnapshot(paragraph.from, paragraph.from);
1346
- }
1347
- function findTopLevelParagraphSelectionNearBlock(document, preferredBlockIndex) {
1348
- const surface = createEditorSurfaceSnapshot(document, createSelectionSnapshot(0, 0));
1349
- for (let index = preferredBlockIndex; index < surface.blocks.length; index += 1) {
1350
- const block = surface.blocks[index];
1351
- if (block?.kind === "paragraph") {
1352
- return createSelectionSnapshot(block.from, block.from);
1353
- }
1354
- }
1355
- for (let index = Math.min(preferredBlockIndex - 1, surface.blocks.length - 1); index >= 0; index -= 1) {
1356
- const block = surface.blocks[index];
1357
- if (block?.kind === "paragraph") {
1358
- return createSelectionSnapshot(block.from, block.from);
1359
- }
1360
- }
1361
- return null;
1362
- }
1363
-
1364
- // src/core/commands/table-structure-commands.ts
1365
- function applyTableStructureOperation(document, snapshot, selectionDescriptor, operation) {
1366
- const root = document.content;
1367
- const fallbackSelection = toInternalSelectionSnapshot(snapshot.selection);
1368
- if (!root || root.type !== "doc") {
1369
- return createNoopStructuralMutation(document, fallbackSelection);
1370
- }
1371
- const effectiveSelection = selectionDescriptor ?? resolveTableSelectionFromSnapshot(snapshot);
1372
- if (!effectiveSelection) {
1373
- return createNoopStructuralMutation(document, fallbackSelection);
1374
- }
1375
- const target = root.children[effectiveSelection.tableBlockIndex];
1376
- if (!target || target.type !== "table") {
1377
- return createNoopStructuralMutation(document, fallbackSelection);
1378
- }
1379
- switch (operation.type) {
1380
- case "delete-table":
1381
- return deleteTableBlock(document, root, effectiveSelection.tableBlockIndex, fallbackSelection);
1382
- case "set-cell-background":
1383
- return setCellBackground(document, root, target, effectiveSelection, operation.color, fallbackSelection);
1384
- case "split-cell":
1385
- return splitSelectedCell(document, root, target, effectiveSelection, fallbackSelection);
1386
- case "merge-cells":
1387
- return mergeSelectedCells(document, root, target, effectiveSelection, fallbackSelection);
1388
- case "add-row-before":
1389
- return addRow(document, root, target, effectiveSelection, "before", fallbackSelection);
1390
- case "add-row-after":
1391
- return addRow(document, root, target, effectiveSelection, "after", fallbackSelection);
1392
- case "delete-row":
1393
- return deleteRow(document, root, target, effectiveSelection, fallbackSelection);
1394
- case "add-column-before":
1395
- return addColumn(document, root, target, effectiveSelection, "before", fallbackSelection);
1396
- case "add-column-after":
1397
- return addColumn(document, root, target, effectiveSelection, "after", fallbackSelection);
1398
- case "delete-column":
1399
- return deleteColumn(document, root, target, effectiveSelection, fallbackSelection);
1400
- default:
1401
- return createNoopStructuralMutation(document, fallbackSelection);
1402
- }
1403
- }
1404
- function addRow(document, root, table, selection, position, fallbackSelection) {
1405
- if (!isSimpleTable(table)) {
1406
- return createNoopStructuralMutation(document, fallbackSelection);
1407
- }
1408
- const columnCount = getLogicalColumnCount(table);
1409
- const insertIndex = position === "before" ? selection.anchorCell.rowIndex : selection.anchorCell.rowIndex + 1;
1410
- const nextRow = {
1411
- type: "table_row",
1412
- cells: Array.from({ length: columnCount }, () => createEmptyCell())
1413
- };
1414
- const nextTable = {
1415
- ...table,
1416
- rows: [
1417
- ...table.rows.slice(0, insertIndex),
1418
- nextRow,
1419
- ...table.rows.slice(insertIndex)
1420
- ]
1421
- };
1422
- return commitTableChange(
1423
- document,
1424
- root,
1425
- selection.tableBlockIndex,
1426
- nextTable,
1427
- fallbackSelection,
1428
- insertIndex,
1429
- selection.anchorCell.columnIndex
1430
- );
1431
- }
1432
- function deleteRow(document, root, table, selection, fallbackSelection) {
1433
- if (!isSimpleTable(table) || table.rows.length <= 1) {
1434
- return createNoopStructuralMutation(document, fallbackSelection);
1435
- }
1436
- const deleteIndex = selection.anchorCell.rowIndex;
1437
- const nextRows = table.rows.filter((_, rowIndex) => rowIndex !== deleteIndex);
1438
- const focusRowIndex = Math.max(0, Math.min(deleteIndex, nextRows.length - 1));
1439
- const nextTable = {
1440
- ...table,
1441
- rows: nextRows
1442
- };
1443
- return commitTableChange(
1444
- document,
1445
- root,
1446
- selection.tableBlockIndex,
1447
- nextTable,
1448
- fallbackSelection,
1449
- focusRowIndex,
1450
- selection.anchorCell.columnIndex
1451
- );
1452
- }
1453
- function addColumn(document, root, table, selection, position, fallbackSelection) {
1454
- if (!isSimpleTable(table)) {
1455
- return createNoopStructuralMutation(document, fallbackSelection);
1456
- }
1457
- const insertIndex = position === "before" ? selection.anchorCell.columnIndex : selection.anchorCell.columnIndex + 1;
1458
- const nextTable = {
1459
- ...table,
1460
- gridColumns: insertGridColumn(table.gridColumns, insertIndex),
1461
- rows: table.rows.map((row) => ({
1462
- ...row,
1463
- cells: [
1464
- ...row.cells.slice(0, insertIndex),
1465
- createEmptyCell(),
1466
- ...row.cells.slice(insertIndex)
1467
- ]
1468
- }))
1469
- };
1470
- return commitTableChange(
1471
- document,
1472
- root,
1473
- selection.tableBlockIndex,
1474
- nextTable,
1475
- fallbackSelection,
1476
- selection.anchorCell.rowIndex,
1477
- insertIndex
1478
- );
1479
- }
1480
- function deleteColumn(document, root, table, selection, fallbackSelection) {
1481
- if (!isSimpleTable(table) || getLogicalColumnCount(table) <= 1) {
1482
- return createNoopStructuralMutation(document, fallbackSelection);
1483
- }
1484
- const deleteIndex = selection.anchorCell.columnIndex;
1485
- const nextTable = {
1486
- ...table,
1487
- gridColumns: deleteGridColumn(table.gridColumns, deleteIndex),
1488
- rows: table.rows.map((row) => ({
1489
- ...row,
1490
- cells: row.cells.filter((_, cellIndex) => cellIndex !== deleteIndex)
1491
- }))
1492
- };
1493
- const focusColumnIndex = Math.max(0, Math.min(deleteIndex, getLogicalColumnCount(nextTable) - 1));
1494
- return commitTableChange(
1495
- document,
1496
- root,
1497
- selection.tableBlockIndex,
1498
- nextTable,
1499
- fallbackSelection,
1500
- selection.anchorCell.rowIndex,
1501
- focusColumnIndex
1502
- );
1503
- }
1504
- function mergeSelectedCells(document, root, table, selection, fallbackSelection) {
1505
- if (!isSimpleTable(table) || selection.selectionKind !== "cell" || selection.rect.bottom - selection.rect.top < 1 || selection.rect.right - selection.rect.left < 1) {
1506
- return createNoopStructuralMutation(document, fallbackSelection);
1507
- }
1508
- const height = selection.rect.bottom - selection.rect.top;
1509
- const width = selection.rect.right - selection.rect.left;
1510
- if (height === 1 && width === 1) {
1511
- return createNoopStructuralMutation(document, fallbackSelection);
1512
- }
1513
- const nextRows = table.rows.map((row) => ({
1514
- ...row,
1515
- cells: row.cells.map((cell) => cloneCell(cell))
1516
- }));
1517
- const mergedChildren = [];
1518
- for (let rowIndex = selection.rect.top; rowIndex < selection.rect.bottom; rowIndex += 1) {
1519
- const row = nextRows[rowIndex];
1520
- if (!row) {
1521
- return createNoopStructuralMutation(document, fallbackSelection);
1522
- }
1523
- for (let columnIndex = selection.rect.left; columnIndex < selection.rect.right; columnIndex += 1) {
1524
- const cellRef = findCellAtColumn(row, columnIndex);
1525
- if (!cellRef) {
1526
- return createNoopStructuralMutation(document, fallbackSelection);
1527
- }
1528
- const paragraphs = cellRef.cell.children.filter(
1529
- (child) => child.type === "paragraph"
1530
- );
1531
- mergedChildren.push(...paragraphs.map((paragraph) => structuredClone(paragraph)));
1532
- }
1533
- }
1534
- const topRow = nextRows[selection.rect.top];
1535
- if (!topRow) {
1536
- return createNoopStructuralMutation(document, fallbackSelection);
1537
- }
1538
- const topLeftRef = findCellAtColumn(topRow, selection.rect.left);
1539
- if (!topLeftRef) {
1540
- return createNoopStructuralMutation(document, fallbackSelection);
1541
- }
1542
- topRow.cells[topLeftRef.cellIndex] = {
1543
- ...topLeftRef.cell,
1544
- ...width > 1 ? { gridSpan: width } : {},
1545
- ...height > 1 ? { verticalMerge: "restart" } : {},
1546
- children: mergedChildren.length > 0 ? mergedChildren : [createEmptyParagraph()]
1547
- };
1548
- topRow.cells.splice(topLeftRef.cellIndex + 1, width - 1);
1549
- for (let rowIndex = selection.rect.top + 1; rowIndex < selection.rect.bottom; rowIndex += 1) {
1550
- const row = nextRows[rowIndex];
1551
- const leftRef = findCellAtColumn(row, selection.rect.left);
1552
- if (!leftRef) {
1553
- return createNoopStructuralMutation(document, fallbackSelection);
1554
- }
1555
- row.cells.splice(
1556
- leftRef.cellIndex,
1557
- width,
1558
- {
1559
- ...createEmptyCell(),
1560
- ...width > 1 ? { gridSpan: width } : {},
1561
- verticalMerge: "continue"
1562
- }
1563
- );
1564
- }
1565
- const nextTable = {
1566
- ...table,
1567
- rows: nextRows
1568
- };
1569
- return commitTableChange(
1570
- document,
1571
- root,
1572
- selection.tableBlockIndex,
1573
- nextTable,
1574
- fallbackSelection,
1575
- selection.rect.top,
1576
- selection.rect.left
1577
- );
1578
- }
1579
- function splitSelectedCell(document, root, table, selection, fallbackSelection) {
1580
- const row = table.rows[selection.anchorCell.rowIndex];
1581
- if (!row) {
1582
- return createNoopStructuralMutation(document, fallbackSelection);
1583
- }
1584
- const cellRef = findCellAtColumn(row, selection.anchorCell.columnIndex);
1585
- if (!cellRef) {
1586
- return createNoopStructuralMutation(document, fallbackSelection);
1587
- }
1588
- const width = Math.max(1, cellRef.cell.gridSpan ?? 1);
1589
- const height = Math.max(
1590
- 1,
1591
- computeRowSpan(table, selection.anchorCell.rowIndex, selection.anchorCell.columnIndex, width)
1592
- );
1593
- if (width === 1 && height === 1) {
1594
- return createNoopStructuralMutation(document, fallbackSelection);
1595
- }
1596
- const nextRows = table.rows.map((currentRow) => ({
1597
- ...currentRow,
1598
- cells: currentRow.cells.map((cell) => cloneCell(cell))
1599
- }));
1600
- const topRow = nextRows[selection.anchorCell.rowIndex];
1601
- topRow.cells.splice(
1602
- cellRef.cellIndex,
1603
- 1,
1604
- stripCellSpan(cellRef.cell),
1605
- ...Array.from({ length: width - 1 }, () => createEmptyCell())
1606
- );
1607
- for (let rowOffset = 1; rowOffset < height; rowOffset += 1) {
1608
- const rowIndex = selection.anchorCell.rowIndex + rowOffset;
1609
- const currentRow = nextRows[rowIndex];
1610
- if (!currentRow) {
1611
- break;
1612
- }
1613
- const continueRef = findCellAtColumn(currentRow, selection.anchorCell.columnIndex);
1614
- if (!continueRef) {
1615
- return createNoopStructuralMutation(document, fallbackSelection);
1616
- }
1617
- currentRow.cells.splice(
1618
- continueRef.cellIndex,
1619
- 1,
1620
- ...Array.from({ length: width }, () => createEmptyCell())
1621
- );
1622
- }
1623
- const nextTable = {
1624
- ...table,
1625
- rows: nextRows
1626
- };
1627
- return commitTableChange(
1628
- document,
1629
- root,
1630
- selection.tableBlockIndex,
1631
- nextTable,
1632
- fallbackSelection,
1633
- selection.anchorCell.rowIndex,
1634
- selection.anchorCell.columnIndex
1635
- );
1636
- }
1637
- function setCellBackground(document, root, table, selection, color, fallbackSelection) {
1638
- const normalized = normalizeFillColor(color);
1639
- if (!normalized) {
1640
- return createNoopStructuralMutation(document, fallbackSelection);
1641
- }
1642
- const targetRect = selection.selectionKind === "text" ? {
1643
- top: 0,
1644
- left: 0,
1645
- bottom: table.rows.length,
1646
- right: getLogicalColumnCount(table)
1647
- } : selection.rect;
1648
- let changed = false;
1649
- const nextRows = table.rows.map((row, rowIndex) => {
1650
- if (rowIndex < targetRect.top || rowIndex >= targetRect.bottom) {
1651
- return row;
1652
- }
1653
- let cursor = 0;
1654
- const cells = row.cells.map((cell) => {
1655
- const start = cursor;
1656
- const width = cell.gridSpan ?? 1;
1657
- const end = start + width;
1658
- cursor = end;
1659
- if (end <= targetRect.left || start >= targetRect.right) {
1660
- return cell;
1661
- }
1662
- changed = true;
1663
- return {
1664
- ...cell,
1665
- shading: {
1666
- ...cell.shading ?? {},
1667
- fill: normalized
1668
- }
1669
- };
1670
- });
1671
- return {
1672
- ...row,
1673
- cells
1674
- };
1675
- });
1676
- if (!changed) {
1677
- return createNoopStructuralMutation(document, fallbackSelection);
1678
- }
1679
- const nextTable = {
1680
- ...table,
1681
- rows: nextRows
1682
- };
1683
- return commitTableChange(
1684
- document,
1685
- root,
1686
- selection.tableBlockIndex,
1687
- nextTable,
1688
- fallbackSelection,
1689
- selection.anchorCell.rowIndex,
1690
- selection.anchorCell.columnIndex
1691
- );
1692
- }
1693
- function deleteTableBlock(document, root, tableBlockIndex, fallbackSelection) {
1694
- const nextChildren = root.children.filter((_, index) => index !== tableBlockIndex);
1695
- if (nextChildren.length === 0) {
1696
- nextChildren.push(createEmptyParagraph());
1697
- }
1698
- const nextDocument = {
1699
- ...document,
1700
- content: {
1701
- ...root,
1702
- children: nextChildren
1703
- }
1704
- };
1705
- const nextSelection = findTopLevelParagraphSelectionNearBlock(nextDocument, tableBlockIndex) ?? fallbackSelection;
1706
- return {
1707
- changed: true,
1708
- document: nextDocument,
1709
- selection: nextSelection
1710
- };
1711
- }
1712
- function commitTableChange(document, root, tableBlockIndex, nextTable, fallbackSelection, focusRowIndex, focusColumnIndex) {
1713
- const nextDocument = {
1714
- ...document,
1715
- content: {
1716
- ...root,
1717
- children: root.children.map(
1718
- (child, index) => index === tableBlockIndex ? nextTable : child
1719
- )
1720
- }
1721
- };
1722
- const nextSelection = findTableCellParagraphSelection(
1723
- nextDocument,
1724
- tableBlockIndex,
1725
- focusRowIndex,
1726
- focusColumnIndex
1727
- ) ?? fallbackSelection;
1728
- return {
1729
- changed: true,
1730
- document: nextDocument,
1731
- selection: nextSelection
1732
- };
1733
- }
1734
- function resolveTableSelectionFromSnapshot(snapshot) {
1735
- const selectionFrom = Math.min(snapshot.selection.anchor, snapshot.selection.head);
1736
- const selectionTo = Math.max(snapshot.selection.anchor, snapshot.selection.head);
1737
- const surface = snapshot.surface;
1738
- if (!surface) {
1739
- return null;
1740
- }
1741
- for (let tableBlockIndex = 0; tableBlockIndex < surface.blocks.length; tableBlockIndex += 1) {
1742
- const block = surface.blocks[tableBlockIndex];
1743
- if (block.kind !== "table") {
1744
- continue;
1745
- }
1746
- for (let rowIndex = 0; rowIndex < block.rows.length; rowIndex += 1) {
1747
- const row = block.rows[rowIndex];
1748
- for (let cellIndex = 0; cellIndex < row.cells.length; cellIndex += 1) {
1749
- const cell = row.cells[cellIndex];
1750
- const hit = cell.content.find(
1751
- (child) => child.kind === "paragraph" && selectionFrom >= child.from && selectionTo <= child.to
1752
- );
1753
- if (!hit) {
1754
- continue;
1755
- }
1756
- let logicalColumn = 0;
1757
- for (let currentIndex = 0; currentIndex < cellIndex; currentIndex += 1) {
1758
- logicalColumn += row.cells[currentIndex]?.gridSpan ?? 1;
1759
- }
1760
- return {
1761
- tableBlockIndex,
1762
- selectionKind: "text",
1763
- anchorCell: {
1764
- rowIndex,
1765
- columnIndex: logicalColumn
1766
- },
1767
- headCell: {
1768
- rowIndex,
1769
- columnIndex: logicalColumn
1770
- },
1771
- rect: {
1772
- top: rowIndex,
1773
- left: logicalColumn,
1774
- bottom: rowIndex + 1,
1775
- right: logicalColumn + (cell.gridSpan ?? 1)
1776
- }
1777
- };
1778
- }
1779
- }
1780
- }
1781
- return null;
1782
- }
1783
- function toInternalSelectionSnapshot(selection) {
1784
- return {
1785
- anchor: selection.anchor,
1786
- head: selection.head,
1787
- isCollapsed: selection.isCollapsed,
1788
- activeRange: selection.activeRange.kind === "range" ? createRangeAnchor(
1789
- selection.activeRange.from,
1790
- selection.activeRange.to,
1791
- selection.activeRange.assoc
1792
- ) : selection.activeRange.kind === "node" ? createNodeAnchor(selection.activeRange.at, selection.activeRange.assoc) : createDetachedAnchor(
1793
- selection.activeRange.lastKnownRange,
1794
- selection.activeRange.reason
1795
- )
1796
- };
1797
- }
1798
- function isSimpleTable(table) {
1799
- const width = getLogicalColumnCount(table);
1800
- return table.rows.every((row) => {
1801
- let rowWidth = 0;
1802
- for (const cell of row.cells) {
1803
- if ((cell.gridSpan ?? 1) !== 1 || cell.verticalMerge) {
1804
- return false;
1805
- }
1806
- rowWidth += 1;
1807
- }
1808
- return rowWidth === width;
1809
- });
1810
- }
1811
- function getLogicalColumnCount(table) {
1812
- if (table.gridColumns.length > 0) {
1813
- return table.gridColumns.length;
1814
- }
1815
- return table.rows.reduce((max, row) => {
1816
- const width = row.cells.reduce((sum, cell) => sum + (cell.gridSpan ?? 1), 0);
1817
- return Math.max(max, width);
1818
- }, 0);
1819
- }
1820
- function computeRowSpan(table, rowIndex, columnIndex, width) {
1821
- let rowspan = 1;
1822
- for (let currentRowIndex = rowIndex + 1; currentRowIndex < table.rows.length; currentRowIndex += 1) {
1823
- const cellRef = findCellAtColumn(table.rows[currentRowIndex], columnIndex);
1824
- if (!cellRef || cellRef.cell.verticalMerge !== "continue" || (cellRef.cell.gridSpan ?? 1) !== width) {
1825
- break;
1826
- }
1827
- rowspan += 1;
1828
- }
1829
- return rowspan;
1830
- }
1831
- function findCellAtColumn(row, logicalColumnIndex) {
1832
- let cursor = 0;
1833
- for (let cellIndex = 0; cellIndex < row.cells.length; cellIndex += 1) {
1834
- const cell = row.cells[cellIndex];
1835
- const width = cell.gridSpan ?? 1;
1836
- if (logicalColumnIndex >= cursor && logicalColumnIndex < cursor + width) {
1837
- return {
1838
- cellIndex,
1839
- cell
1840
- };
1841
- }
1842
- cursor += width;
1843
- }
1844
- return null;
1845
- }
1846
- function createEmptyCell() {
1847
- return {
1848
- type: "table_cell",
1849
- children: [createEmptyParagraph()]
1850
- };
1851
- }
1852
- function cloneCell(cell) {
1853
- return structuredClone(cell);
1854
- }
1855
- function stripCellSpan(cell) {
1856
- return {
1857
- ...cell,
1858
- gridSpan: void 0,
1859
- verticalMerge: void 0
1860
- };
1861
- }
1862
- function insertGridColumn(columns, index) {
1863
- if (columns.length === 0) {
1864
- return columns;
1865
- }
1866
- const current = columns[index] ?? columns[index - 1] ?? columns[columns.length - 1] ?? 2400;
1867
- return [...columns.slice(0, index), current, ...columns.slice(index)];
1868
- }
1869
- function deleteGridColumn(columns, index) {
1870
- if (columns.length <= 1) {
1871
- return columns;
1872
- }
1873
- return columns.filter((_, columnIndex) => columnIndex !== index);
1874
- }
1875
- function normalizeFillColor(color) {
1876
- const normalized = color.trim().replace(/^#/, "");
1877
- return /^[0-9A-Fa-f]{3,8}$/.test(normalized) ? normalized.toUpperCase() : null;
1878
- }
1879
- // Annotate the CommonJS export names for ESM import in node:
1880
- 0 && (module.exports = {
1881
- applyTableStructureOperation
1882
- });
1883
- //# sourceMappingURL=table-structure-commands.cjs.map