@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,2391 +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/text-commands.ts
21
- var text_commands_exports = {};
22
- __export(text_commands_exports, {
23
- deleteSelectionOrBackward: () => deleteSelectionOrBackward,
24
- deleteSelectionOrForward: () => deleteSelectionOrForward,
25
- insertHardBreak: () => insertHardBreak,
26
- insertPageBreak: () => insertPageBreak,
27
- insertTab: () => insertTab,
28
- insertTable: () => insertTable,
29
- insertText: () => insertText,
30
- splitParagraph: () => splitParagraph
31
- });
32
- module.exports = __toCommonJS(text_commands_exports);
33
-
34
- // src/core/selection/mapping.ts
35
- var DEFAULT_BOUNDARY_ASSOC = {
36
- start: 1,
37
- end: -1
38
- };
39
- function createRangeAnchor(from, to = from, assoc = DEFAULT_BOUNDARY_ASSOC) {
40
- return {
41
- kind: "range",
42
- range: normalizeRange({ from, to }),
43
- assoc
44
- };
45
- }
46
- function normalizeRange(range) {
47
- return range.from <= range.to ? { from: range.from, to: range.to } : { from: range.to, to: range.from };
48
- }
49
-
50
- // src/core/state/editor-state.ts
51
- function createSelectionSnapshot(anchor = 0, head = anchor) {
52
- return {
53
- anchor,
54
- head,
55
- isCollapsed: anchor === head,
56
- activeRange: createRangeAnchor(anchor, head, DEFAULT_BOUNDARY_ASSOC)
57
- };
58
- }
59
-
60
- // src/core/schema/text-schema.ts
61
- function parseTextStory(content) {
62
- const root = normalizeDocumentRoot(content);
63
- const firstParagraphNode = root.children.find(isParagraphNode);
64
- const firstParagraph = firstParagraphNode ? extractParagraphProperties(firstParagraphNode) : cloneParagraphProperties(EMPTY_PARAGRAPH_PROPERTIES);
65
- const units = [];
66
- for (let index = 0; index < root.children.length; index += 1) {
67
- const block = root.children[index];
68
- const nextBlock = root.children[index + 1];
69
- if (isParagraphNode(block)) {
70
- units.push(...flattenInlineNodes(block.children));
71
- if (isParagraphNode(nextBlock)) {
72
- units.push({
73
- kind: "paragraph_break",
74
- nextParagraph: extractParagraphProperties(nextBlock)
75
- });
76
- }
77
- continue;
78
- }
79
- if (block.type !== "opaque_block") {
80
- continue;
81
- }
82
- units.push({
83
- kind: "opaque_block",
84
- fragmentId: block.fragmentId,
85
- warningId: block.warningId,
86
- ...isParagraphNode(nextBlock) ? { nextParagraph: extractParagraphProperties(nextBlock) } : {}
87
- });
88
- }
89
- return {
90
- firstParagraph,
91
- units,
92
- size: units.length
93
- };
94
- }
95
- function serializeTextStory(story) {
96
- const blocks = [];
97
- let currentParagraph = createParagraph(story.firstParagraph);
98
- let currentHyperlink;
99
- let activeTextBuffer;
100
- const ensureCurrentParagraph = () => {
101
- if (!currentParagraph) {
102
- currentParagraph = createParagraph(EMPTY_PARAGRAPH_PROPERTIES);
103
- }
104
- };
105
- const flushTextBuffer = () => {
106
- if (!activeTextBuffer || activeTextBuffer.text.length === 0) {
107
- activeTextBuffer = void 0;
108
- return;
109
- }
110
- const textNode = {
111
- type: "text",
112
- text: activeTextBuffer.text,
113
- ...activeTextBuffer.marks ? { marks: cloneMarks(activeTextBuffer.marks) } : {}
114
- };
115
- ensureCurrentParagraph();
116
- if (activeTextBuffer.hyperlinkHref) {
117
- if (!currentHyperlink || currentHyperlink.href !== activeTextBuffer.hyperlinkHref) {
118
- flushHyperlink();
119
- currentHyperlink = {
120
- type: "hyperlink",
121
- href: activeTextBuffer.hyperlinkHref,
122
- children: []
123
- };
124
- }
125
- currentHyperlink.children.push(textNode);
126
- } else {
127
- flushHyperlink();
128
- currentParagraph.children.push(textNode);
129
- }
130
- activeTextBuffer = void 0;
131
- };
132
- const flushHyperlink = () => {
133
- if (currentHyperlink) {
134
- ensureCurrentParagraph();
135
- currentParagraph.children.push(currentHyperlink);
136
- currentHyperlink = void 0;
137
- }
138
- };
139
- const flushParagraph = () => {
140
- flushTextBuffer();
141
- flushHyperlink();
142
- if (!currentParagraph) {
143
- return;
144
- }
145
- blocks.push(currentParagraph);
146
- currentParagraph = void 0;
147
- };
148
- const pushInlineNode = (node, hyperlinkHref) => {
149
- flushTextBuffer();
150
- ensureCurrentParagraph();
151
- if (hyperlinkHref) {
152
- if (!currentHyperlink || currentHyperlink.href !== hyperlinkHref) {
153
- flushHyperlink();
154
- currentHyperlink = {
155
- type: "hyperlink",
156
- href: hyperlinkHref,
157
- children: []
158
- };
159
- }
160
- currentHyperlink.children.push(node);
161
- return;
162
- }
163
- flushHyperlink();
164
- currentParagraph.children.push(node);
165
- };
166
- for (const unit of story.units) {
167
- if (unit.kind === "paragraph_break") {
168
- flushParagraph();
169
- currentParagraph = createParagraph(unit.nextParagraph);
170
- continue;
171
- }
172
- if (unit.kind === "opaque_block") {
173
- flushParagraph();
174
- blocks.push({
175
- type: "opaque_block",
176
- fragmentId: unit.fragmentId,
177
- warningId: unit.warningId
178
- });
179
- currentParagraph = unit.nextParagraph ? createParagraph(unit.nextParagraph) : void 0;
180
- continue;
181
- }
182
- if (unit.kind === "text") {
183
- const shouldExtendBuffer = activeTextBuffer && activeTextBuffer.hyperlinkHref === unit.hyperlinkHref && haveEqualMarks(activeTextBuffer.marks, unit.marks);
184
- if (shouldExtendBuffer && activeTextBuffer) {
185
- activeTextBuffer.text += unit.value;
186
- } else {
187
- flushTextBuffer();
188
- activeTextBuffer = {
189
- text: unit.value,
190
- ...unit.marks ? { marks: cloneMarks(unit.marks) } : {},
191
- ...unit.hyperlinkHref ? { hyperlinkHref: unit.hyperlinkHref } : {}
192
- };
193
- }
194
- continue;
195
- }
196
- switch (unit.kind) {
197
- case "tab":
198
- pushInlineNode({ type: "tab" }, unit.hyperlinkHref);
199
- break;
200
- case "hard_break":
201
- pushInlineNode({ type: "hard_break" }, unit.hyperlinkHref);
202
- break;
203
- case "image":
204
- pushInlineNode({
205
- type: "image",
206
- mediaId: unit.mediaId,
207
- ...unit.altText ? { altText: unit.altText } : {}
208
- });
209
- break;
210
- case "opaque_inline":
211
- pushInlineNode({
212
- type: "opaque_inline",
213
- fragmentId: unit.fragmentId,
214
- warningId: unit.warningId
215
- });
216
- break;
217
- }
218
- }
219
- flushParagraph();
220
- if (blocks.length === 0) {
221
- blocks.push(createParagraph(story.firstParagraph));
222
- }
223
- return {
224
- type: "doc",
225
- children: blocks
226
- };
227
- }
228
- function createPlainText(story) {
229
- return story.units.map((unit) => {
230
- switch (unit.kind) {
231
- case "text":
232
- return unit.value;
233
- case "tab":
234
- return " ";
235
- case "hard_break":
236
- return "\n";
237
- case "paragraph_break":
238
- return "\n";
239
- case "image":
240
- return "\uFFFC";
241
- case "opaque_inline":
242
- return "\uFFF9";
243
- case "opaque_block":
244
- return "\uFFFA";
245
- }
246
- }).join("");
247
- }
248
- function cloneStoryUnit(unit) {
249
- switch (unit.kind) {
250
- case "text":
251
- return {
252
- kind: "text",
253
- value: unit.value,
254
- ...unit.marks ? { marks: cloneMarks(unit.marks) } : {},
255
- ...unit.hyperlinkHref ? { hyperlinkHref: unit.hyperlinkHref } : {}
256
- };
257
- case "tab":
258
- return {
259
- kind: "tab",
260
- ...unit.hyperlinkHref ? { hyperlinkHref: unit.hyperlinkHref } : {}
261
- };
262
- case "hard_break":
263
- return {
264
- kind: "hard_break",
265
- ...unit.hyperlinkHref ? { hyperlinkHref: unit.hyperlinkHref } : {}
266
- };
267
- case "image":
268
- return {
269
- kind: "image",
270
- mediaId: unit.mediaId,
271
- ...unit.altText ? { altText: unit.altText } : {}
272
- };
273
- case "opaque_inline":
274
- return {
275
- kind: "opaque_inline",
276
- fragmentId: unit.fragmentId,
277
- warningId: unit.warningId
278
- };
279
- case "opaque_block":
280
- return {
281
- kind: "opaque_block",
282
- fragmentId: unit.fragmentId,
283
- warningId: unit.warningId,
284
- ...unit.nextParagraph ? { nextParagraph: cloneParagraphProperties(unit.nextParagraph) } : {}
285
- };
286
- case "paragraph_break":
287
- return {
288
- kind: "paragraph_break",
289
- nextParagraph: cloneParagraphProperties(unit.nextParagraph)
290
- };
291
- }
292
- }
293
- function cloneParagraphProperties(properties) {
294
- return {
295
- ...properties.styleId ? { styleId: properties.styleId } : {},
296
- ...properties.numbering ? {
297
- numbering: {
298
- numberingInstanceId: properties.numbering.numberingInstanceId,
299
- level: properties.numbering.level
300
- }
301
- } : {}
302
- };
303
- }
304
- function normalizeDocumentRoot(content) {
305
- if (isDocumentRootNode(content)) {
306
- return content;
307
- }
308
- if (Array.isArray(content)) {
309
- return {
310
- type: "doc",
311
- children: content.filter(
312
- (block) => isParagraphNode(block) || isOpaqueBlockNode(block)
313
- )
314
- };
315
- }
316
- return {
317
- type: "doc",
318
- children: [createEmptyParagraph()]
319
- };
320
- }
321
- function flattenInlineNodes(nodes, hyperlinkHref) {
322
- const units = [];
323
- for (const node of nodes) {
324
- switch (node.type) {
325
- case "text":
326
- for (const character of Array.from(node.text)) {
327
- units.push({
328
- kind: "text",
329
- value: character,
330
- ...node.marks ? { marks: cloneMarks(node.marks) } : {},
331
- ...hyperlinkHref ? { hyperlinkHref } : {}
332
- });
333
- }
334
- break;
335
- case "tab":
336
- units.push({
337
- kind: "tab",
338
- ...hyperlinkHref ? { hyperlinkHref } : {}
339
- });
340
- break;
341
- case "hard_break":
342
- units.push({
343
- kind: "hard_break",
344
- ...hyperlinkHref ? { hyperlinkHref } : {}
345
- });
346
- break;
347
- case "hyperlink":
348
- units.push(...flattenInlineNodes(node.children, node.href));
349
- break;
350
- case "image":
351
- units.push({
352
- kind: "image",
353
- mediaId: node.mediaId,
354
- ...node.altText ? { altText: node.altText } : {}
355
- });
356
- break;
357
- case "opaque_inline":
358
- units.push({
359
- kind: "opaque_inline",
360
- fragmentId: node.fragmentId,
361
- warningId: node.warningId
362
- });
363
- break;
364
- }
365
- }
366
- return units;
367
- }
368
- function extractParagraphProperties(paragraph) {
369
- return {
370
- ...paragraph.styleId ? { styleId: paragraph.styleId } : {},
371
- ...paragraph.numbering ? {
372
- numbering: {
373
- numberingInstanceId: paragraph.numbering.numberingInstanceId,
374
- level: paragraph.numbering.level
375
- }
376
- } : {}
377
- };
378
- }
379
- function createParagraph(properties) {
380
- return {
381
- type: "paragraph",
382
- ...properties.styleId ? { styleId: properties.styleId } : {},
383
- ...properties.numbering ? {
384
- numbering: {
385
- numberingInstanceId: properties.numbering.numberingInstanceId,
386
- level: properties.numbering.level
387
- }
388
- } : {},
389
- children: []
390
- };
391
- }
392
- function createEmptyParagraph() {
393
- return {
394
- type: "paragraph",
395
- children: []
396
- };
397
- }
398
- var EMPTY_PARAGRAPH_PROPERTIES = {};
399
- function cloneMarks(marks) {
400
- return marks.map((mark) => ({ ...mark }));
401
- }
402
- function haveEqualMarks(left, right) {
403
- if (!left && !right) {
404
- return true;
405
- }
406
- if (!left || !right || left.length !== right.length) {
407
- return false;
408
- }
409
- return left.every((mark, index) => mark.type === right[index]?.type);
410
- }
411
- function isDocumentRootNode(value) {
412
- return Boolean(value) && typeof value === "object" && value.type === "doc";
413
- }
414
- function isParagraphNode(value) {
415
- return Boolean(value) && typeof value === "object" && value.type === "paragraph";
416
- }
417
- function isOpaqueBlockNode(value) {
418
- return Boolean(value) && typeof value === "object" && value.type === "opaque_block";
419
- }
420
-
421
- // src/preservation/store.ts
422
- function getOpaqueFragment(store, fragmentId) {
423
- return normalizeOpaqueFragmentMap(store)[fragmentId];
424
- }
425
- function describeOpaqueFragment(fragment) {
426
- const xml = fragment.payloadReference;
427
- const detail = createDetail(fragment);
428
- if (/\b(?:w:)?sectPr\b/u.test(xml)) {
429
- return {
430
- featureKey: "sections",
431
- label: "Section properties",
432
- detail
433
- };
434
- }
435
- if (/\b(?:w:)?tbl\b/u.test(xml)) {
436
- return {
437
- featureKey: "tables",
438
- label: "Preserved table structure",
439
- detail
440
- };
441
- }
442
- if (/\b(?:w:)?hdr\b|\b(?:w:)?ftr\b/u.test(xml)) {
443
- return {
444
- featureKey: "headers-footers",
445
- label: "Header or footer content",
446
- detail
447
- };
448
- }
449
- if (/\b(?:w:)?fldSimple\b|\b(?:w:)?fldChar\b|\b(?:w:)?instrText\b/u.test(xml)) {
450
- return {
451
- featureKey: "fields",
452
- label: "Word field content",
453
- detail
454
- };
455
- }
456
- if (/\b(?:w:)?sdt\b/u.test(xml)) {
457
- return {
458
- featureKey: "content-controls",
459
- label: "Content control",
460
- detail
461
- };
462
- }
463
- if (/\b(?:w:)?customXml\b/u.test(xml)) {
464
- return {
465
- featureKey: "custom-xml",
466
- label: "Custom XML wrapper",
467
- detail
468
- };
469
- }
470
- if (/\b(?:w:)?altChunk\b/u.test(xml)) {
471
- return {
472
- featureKey: "alt-chunk",
473
- label: "Alternate content import",
474
- detail
475
- };
476
- }
477
- if (/\b(?:w:)?object\b|\b(?:o:)?OLEObject\b/u.test(xml)) {
478
- return {
479
- featureKey: "embedded-objects",
480
- label: "Embedded object",
481
- detail
482
- };
483
- }
484
- if (/\b(?:mc:)?AlternateContent\b/u.test(xml)) {
485
- return {
486
- featureKey: "alternate-content",
487
- label: "Markup compatibility block",
488
- detail
489
- };
490
- }
491
- return {
492
- featureKey: "unknown-ooxml",
493
- label: "Unsupported OOXML fragment",
494
- detail
495
- };
496
- }
497
- function createDetail(fragment) {
498
- const detail = [
499
- `Preserved whole-unit from ${fragment.lastKnownRange.from}-${fragment.lastKnownRange.to}.`,
500
- fragment.packagePartName ? `Part ${fragment.packagePartName}.` : null,
501
- fragment.relationshipId ? `Relationship ${fragment.relationshipId}.` : null
502
- ].filter(Boolean).join(" ");
503
- return detail.length > 0 ? detail : "Preserved whole-unit to keep unsupported OOXML intact.";
504
- }
505
- function normalizeOpaqueFragmentMap(store) {
506
- return store && typeof store === "object" && store.opaqueFragments && typeof store.opaqueFragments === "object" ? store.opaqueFragments : {};
507
- }
508
-
509
- // src/runtime/story-context.ts
510
- function collectSectionContexts(document) {
511
- const sections = [];
512
- let sectionIndex = 0;
513
- for (const block of document.content.children) {
514
- if (block.type !== "section_break") {
515
- continue;
516
- }
517
- sections.push({
518
- index: sectionIndex,
519
- properties: block.sectionProperties
520
- });
521
- sectionIndex += 1;
522
- }
523
- sections.push({
524
- index: sectionIndex,
525
- properties: document.subParts?.finalSectionProperties
526
- });
527
- return sections;
528
- }
529
- function resolveSectionVariants(kind, sectionIndex, explicitReferences, documents) {
530
- if (explicitReferences && explicitReferences.length > 0) {
531
- return explicitReferences.map((ref) => ({
532
- variant: ref.variant,
533
- relationshipId: ref.relationshipId
534
- }));
535
- }
536
- return documents.filter(
537
- (entry) => entry.sectionIndex === void 0 || entry.sectionIndex === sectionIndex
538
- ).map((entry) => ({
539
- variant: entry.variant,
540
- relationshipId: entry.relationshipId
541
- }));
542
- }
543
- function findHeaderFooterDocumentEntry(document, target) {
544
- const documents = target.kind === "header" ? document.subParts?.headers ?? [] : document.subParts?.footers ?? [];
545
- const matches = documents.filter(
546
- (entry) => entry.relationshipId === target.relationshipId && entry.variant === target.variant
547
- );
548
- if (matches.length === 0) {
549
- return void 0;
550
- }
551
- if (target.sectionIndex !== void 0) {
552
- return matches.find((entry) => entry.sectionIndex === target.sectionIndex) ?? matches.find((entry) => entry.sectionIndex === void 0) ?? matches[0];
553
- }
554
- return matches[0];
555
- }
556
- function sectionSupportsStoryTarget(document, sectionIndex, target) {
557
- if (!findHeaderFooterDocumentEntry(document, target)) {
558
- return false;
559
- }
560
- const section = collectSectionContexts(document).find(
561
- (candidate) => candidate.index === sectionIndex
562
- );
563
- if (!section) {
564
- return false;
565
- }
566
- const variants = resolveSectionVariants(
567
- target.kind,
568
- sectionIndex,
569
- target.kind === "header" ? section.properties?.headerReferences : section.properties?.footerReferences,
570
- target.kind === "header" ? document.subParts?.headers ?? [] : document.subParts?.footers ?? []
571
- );
572
- return variants.some(
573
- (variant) => variant.relationshipId === target.relationshipId && variant.variant === target.variant
574
- );
575
- }
576
- function normalizeHeaderFooterTarget(document, target, preferredSectionIndex) {
577
- if (!findHeaderFooterDocumentEntry(document, target)) {
578
- return void 0;
579
- }
580
- if (target.sectionIndex !== void 0) {
581
- return sectionSupportsStoryTarget(document, target.sectionIndex, target) ? target : void 0;
582
- }
583
- const candidateIndexes = collectSectionContexts(document).map((section) => section.index).filter(
584
- (sectionIndex) => sectionSupportsStoryTarget(document, sectionIndex, target)
585
- );
586
- if (candidateIndexes.length === 0) {
587
- return void 0;
588
- }
589
- const resolvedSectionIndex = preferredSectionIndex !== void 0 && candidateIndexes.includes(preferredSectionIndex) ? preferredSectionIndex : candidateIndexes[0];
590
- return {
591
- ...target,
592
- sectionIndex: resolvedSectionIndex
593
- };
594
- }
595
-
596
- // src/runtime/story-targeting.ts
597
- function getStoryBlocks(document, target) {
598
- if (target.kind === "main") {
599
- return document.content.children;
600
- }
601
- const subParts = document.subParts;
602
- if (!subParts) {
603
- return [];
604
- }
605
- switch (target.kind) {
606
- case "header": {
607
- const resolvedTarget = normalizeHeaderFooterTarget(document, target);
608
- return (resolvedTarget && findHeaderFooterDocumentEntry(document, resolvedTarget)?.blocks) ?? [];
609
- }
610
- case "footer": {
611
- const resolvedTarget = normalizeHeaderFooterTarget(document, target);
612
- return (resolvedTarget && findHeaderFooterDocumentEntry(document, resolvedTarget)?.blocks) ?? [];
613
- }
614
- case "footnote":
615
- return subParts.footnoteCollection?.footnotes[target.noteId]?.blocks ?? [];
616
- case "endnote":
617
- return subParts.footnoteCollection?.endnotes[target.noteId]?.blocks ?? [];
618
- }
619
- }
620
-
621
- // src/runtime/numbering-prefix.ts
622
- var DEFAULT_START_AT = 1;
623
- function createNumberingPrefixResolver(catalog) {
624
- const sequenceStates = /* @__PURE__ */ new Map();
625
- function resolveInternal(numbering) {
626
- if (!numbering) {
627
- return null;
628
- }
629
- const instance = catalog.instances[numbering.numberingInstanceId];
630
- if (!instance) {
631
- return null;
632
- }
633
- const definition = catalog.abstractDefinitions[instance.abstractNumberingId];
634
- if (!definition) {
635
- return null;
636
- }
637
- const levelDefinitions = new Map(
638
- definition.levels.map((level) => [level.level, level])
639
- );
640
- const levelDefinition = levelDefinitions.get(numbering.level);
641
- if (!levelDefinition || levelDefinition.format === "none") {
642
- return null;
643
- }
644
- const sequenceState = getSequenceState(sequenceStates, numbering.numberingInstanceId);
645
- advanceSequence(sequenceState, numbering.level, levelDefinitions, instance.overrides);
646
- const effectiveLevelDefs = levelDefinition.isLegalNumbering ? new Map(Array.from(levelDefinitions.entries()).map(([k, v]) => [k, { ...v, format: "decimal" }])) : levelDefinitions;
647
- const text = renderLevelText(levelDefinition.text, sequenceState.counters, effectiveLevelDefs);
648
- if (text === null) return null;
649
- return { text, suffix: levelDefinition.suffix };
650
- }
651
- return {
652
- resolve(numbering) {
653
- const result = resolveInternal(numbering);
654
- return result?.text ?? null;
655
- },
656
- resolveDetailed(numbering) {
657
- return resolveInternal(numbering);
658
- }
659
- };
660
- }
661
- function getSequenceState(states, numberingInstanceId) {
662
- const existing = states.get(numberingInstanceId);
663
- if (existing) {
664
- return existing;
665
- }
666
- const created = {
667
- counters: [],
668
- lastLevel: null
669
- };
670
- states.set(numberingInstanceId, created);
671
- return created;
672
- }
673
- function advanceSequence(state, currentLevel, levelDefinitions, overrides) {
674
- if (state.lastLevel !== null && currentLevel <= state.lastLevel) {
675
- state.counters.length = currentLevel + 1;
676
- }
677
- const startAt = getLevelStartAt(currentLevel, levelDefinitions, overrides);
678
- const currentValue = state.counters[currentLevel];
679
- state.counters[currentLevel] = currentValue === void 0 ? startAt : currentValue + 1;
680
- state.lastLevel = currentLevel;
681
- }
682
- function getLevelStartAt(level, levelDefinitions, overrides) {
683
- const override = overrides.find((entry) => entry.level === level);
684
- if (override?.startAt !== void 0) {
685
- return override.startAt;
686
- }
687
- return levelDefinitions.get(level)?.startAt ?? DEFAULT_START_AT;
688
- }
689
- function renderLevelText(text, counters, levelDefinitions) {
690
- if (!text) {
691
- return null;
692
- }
693
- if (!text.includes("%")) {
694
- return text;
695
- }
696
- const rendered = text.replace(/%([1-9])/g, (_match, token) => {
697
- const level = Number.parseInt(token, 10) - 1;
698
- const counter = counters[level];
699
- if (counter === void 0) {
700
- return "";
701
- }
702
- const format = levelDefinitions.get(level)?.format ?? "decimal";
703
- return formatCounter(counter, format);
704
- });
705
- return rendered.trim().length > 0 ? rendered : null;
706
- }
707
- function formatCounter(value, format) {
708
- switch (format) {
709
- case "decimal":
710
- return String(value);
711
- case "decimalZero":
712
- return String(value).padStart(2, "0");
713
- case "upperLetter":
714
- return toAlphabetic(value).toUpperCase();
715
- case "lowerLetter":
716
- return toAlphabetic(value).toLowerCase();
717
- case "upperRoman":
718
- return toRoman(value).toUpperCase();
719
- case "lowerRoman":
720
- return toRoman(value).toLowerCase();
721
- case "none":
722
- return "";
723
- default:
724
- return String(value);
725
- }
726
- }
727
- function toAlphabetic(value) {
728
- if (value <= 0) {
729
- return String(value);
730
- }
731
- let remainder = value;
732
- let result = "";
733
- while (remainder > 0) {
734
- remainder -= 1;
735
- result = String.fromCharCode(65 + remainder % 26) + result;
736
- remainder = Math.floor(remainder / 26);
737
- }
738
- return result;
739
- }
740
- function toRoman(value) {
741
- if (value <= 0 || value >= 4e3) {
742
- return String(value);
743
- }
744
- const numerals = [
745
- [1e3, "M"],
746
- [900, "CM"],
747
- [500, "D"],
748
- [400, "CD"],
749
- [100, "C"],
750
- [90, "XC"],
751
- [50, "L"],
752
- [40, "XL"],
753
- [10, "X"],
754
- [9, "IX"],
755
- [5, "V"],
756
- [4, "IV"],
757
- [1, "I"]
758
- ];
759
- let remaining = value;
760
- let result = "";
761
- for (const [amount, numeral] of numerals) {
762
- while (remaining >= amount) {
763
- remaining -= amount;
764
- result += numeral;
765
- }
766
- }
767
- return result;
768
- }
769
-
770
- // src/runtime/surface-projection.ts
771
- function createEditorSurfaceSnapshot(document, _selection, activeStory = { kind: "main" }) {
772
- const root = normalizeDocumentRoot2({
773
- type: "doc",
774
- children: [...getStoryBlocks(document, activeStory)]
775
- });
776
- const blocks = [];
777
- const lockedFragmentIds = [];
778
- const numberingPrefixResolver = createNumberingPrefixResolver(document.numbering);
779
- let cursor = 0;
780
- const counters = {
781
- paragraph: 0,
782
- table: 0,
783
- opaque: 0,
784
- sdt: 0,
785
- customXml: 0,
786
- altChunk: 0
787
- };
788
- for (let index = 0; index < root.children.length; index += 1) {
789
- const surfaceBlock = createSurfaceBlock(
790
- root.children[index],
791
- document,
792
- cursor,
793
- counters,
794
- numberingPrefixResolver
795
- );
796
- blocks.push(surfaceBlock.block);
797
- lockedFragmentIds.push(...surfaceBlock.lockedFragmentIds);
798
- cursor = surfaceBlock.nextCursor;
799
- if (index < root.children.length - 1 && root.children[index + 1]?.type === "paragraph") {
800
- cursor += 1;
801
- }
802
- }
803
- const secondaryStories = createSecondaryStorySurfaces(document);
804
- return {
805
- storySize: cursor,
806
- plainText: createPlainText2(blocks),
807
- blocks,
808
- lockedFragmentIds,
809
- secondaryStories
810
- };
811
- }
812
- function createSurfaceBlock(block, document, cursor, counters, numberingPrefixResolver) {
813
- if (block.type === "opaque_block") {
814
- const fragment = getOpaqueFragment(document.preservation, block.fragmentId);
815
- const descriptor = fragment ? describeOpaqueFragment(fragment) : null;
816
- const blockId = `opaque-${counters.opaque}`;
817
- counters.opaque += 1;
818
- return {
819
- block: {
820
- blockId,
821
- kind: "opaque_block",
822
- from: cursor,
823
- to: cursor + 1,
824
- fragmentId: block.fragmentId,
825
- warningId: block.warningId,
826
- label: descriptor?.label ?? "Unsupported OOXML fragment",
827
- detail: descriptor?.detail ?? "Locked whole-unit to keep unsupported OOXML intact through export.",
828
- state: "locked-preserve-only"
829
- },
830
- lockedFragmentIds: [block.fragmentId],
831
- nextCursor: cursor + 1
832
- };
833
- }
834
- if (block.type === "table") {
835
- const tableIndex = counters.table;
836
- counters.table += 1;
837
- return createTableBlock(
838
- tableIndex,
839
- block,
840
- document,
841
- cursor,
842
- counters,
843
- numberingPrefixResolver
844
- );
845
- }
846
- if (block.type === "sdt") {
847
- const sdtIndex = counters.sdt;
848
- counters.sdt += 1;
849
- return createSdtBlock(
850
- sdtIndex,
851
- block,
852
- document,
853
- cursor,
854
- counters,
855
- numberingPrefixResolver
856
- );
857
- }
858
- if (block.type === "custom_xml") {
859
- const blockId = `custom-xml-${counters.customXml}`;
860
- counters.customXml += 1;
861
- return {
862
- block: {
863
- blockId,
864
- kind: "opaque_block",
865
- from: cursor,
866
- to: cursor + 1,
867
- fragmentId: blockId,
868
- warningId: blockId,
869
- label: "Custom XML block",
870
- 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.",
871
- state: "locked-preserve-only"
872
- },
873
- lockedFragmentIds: [],
874
- nextCursor: cursor + 1
875
- };
876
- }
877
- if (block.type === "alt_chunk") {
878
- const blockId = `alt-chunk-${counters.altChunk}`;
879
- counters.altChunk += 1;
880
- return {
881
- block: {
882
- blockId,
883
- kind: "opaque_block",
884
- from: cursor,
885
- to: cursor + 1,
886
- fragmentId: blockId,
887
- warningId: blockId,
888
- label: "AltChunk import",
889
- detail: `Alternate content import remains read-only through relationship ${block.relationshipId}.`,
890
- state: "locked-preserve-only"
891
- },
892
- lockedFragmentIds: [],
893
- nextCursor: cursor + 1
894
- };
895
- }
896
- if (block.type === "section_break") {
897
- const blockId = `section-break-${counters.opaque}`;
898
- counters.opaque += 1;
899
- return {
900
- block: {
901
- blockId,
902
- kind: "opaque_block",
903
- from: cursor,
904
- to: cursor + 1,
905
- fragmentId: blockId,
906
- warningId: blockId,
907
- label: "Section break",
908
- detail: "Section properties preserved as a read-only boundary.",
909
- state: "locked-preserve-only"
910
- },
911
- lockedFragmentIds: [],
912
- nextCursor: cursor + 1
913
- };
914
- }
915
- const paragraphIndex = counters.paragraph;
916
- counters.paragraph += 1;
917
- return createParagraphBlock(
918
- paragraphIndex,
919
- block,
920
- document,
921
- cursor,
922
- numberingPrefixResolver
923
- );
924
- }
925
- function createTableBlock(tableIndex, table, document, cursor, counters, numberingPrefixResolver) {
926
- const lockedFragmentIds = [];
927
- let innerCursor = cursor;
928
- const rows = [];
929
- const rowSpans = computeTableRowSpans(table);
930
- for (const [rowIndex, row] of table.rows.entries()) {
931
- const cells = [];
932
- for (const [cellIndex, cell] of row.cells.entries()) {
933
- const cellContent = [];
934
- for (const child of cell.children) {
935
- const result = createSurfaceBlock(
936
- child,
937
- document,
938
- innerCursor,
939
- counters,
940
- numberingPrefixResolver
941
- );
942
- cellContent.push(result.block);
943
- lockedFragmentIds.push(...result.lockedFragmentIds);
944
- innerCursor = result.nextCursor;
945
- }
946
- const cellBorders = resolveCellBorderStyles(cell.borders);
947
- cells.push({
948
- gridSpan: cell.gridSpan ?? 1,
949
- verticalMerge: cell.verticalMerge ?? null,
950
- colspan: cell.gridSpan ?? 1,
951
- rowspan: rowSpans.get(`${rowIndex}:${cellIndex}`) ?? 1,
952
- ...cell.shading?.fill ? { backgroundColor: `#${cell.shading.fill}` } : {},
953
- ...cell.verticalAlign ? { verticalAlign: cell.verticalAlign } : {},
954
- ...cellBorders.borderTop ? { borderTop: cellBorders.borderTop } : {},
955
- ...cellBorders.borderRight ? { borderRight: cellBorders.borderRight } : {},
956
- ...cellBorders.borderBottom ? { borderBottom: cellBorders.borderBottom } : {},
957
- ...cellBorders.borderLeft ? { borderLeft: cellBorders.borderLeft } : {},
958
- content: cellContent
959
- });
960
- }
961
- rows.push({
962
- cells,
963
- ...row.gridBefore !== void 0 ? { gridBefore: row.gridBefore } : {},
964
- ...row.gridAfter !== void 0 ? { gridAfter: row.gridAfter } : {},
965
- ...row.height !== void 0 ? { height: row.height } : {},
966
- ...row.heightRule ? { heightRule: row.heightRule } : {},
967
- ...row.isHeader ? { isHeader: row.isHeader } : {}
968
- });
969
- }
970
- return {
971
- block: {
972
- blockId: `table-${tableIndex}`,
973
- kind: "table",
974
- from: cursor,
975
- to: innerCursor,
976
- styleId: table.styleId,
977
- gridColumns: table.gridColumns,
978
- ...table.alignment ? { alignment: table.alignment } : {},
979
- ...table.tblLook ? { tblLook: table.tblLook } : {},
980
- rows
981
- },
982
- lockedFragmentIds,
983
- nextCursor: innerCursor
984
- };
985
- }
986
- function computeTableRowSpans(table) {
987
- const positionedRows = table.rows.map((row) => {
988
- let startColumn = 0;
989
- return row.cells.map((cell, cellIndex) => {
990
- const width = cell.gridSpan ?? 1;
991
- const positionedCell = {
992
- cell,
993
- cellIndex,
994
- startColumn,
995
- endColumn: startColumn + width - 1
996
- };
997
- startColumn += width;
998
- return positionedCell;
999
- });
1000
- });
1001
- const rowSpans = /* @__PURE__ */ new Map();
1002
- for (const [rowIndex, row] of positionedRows.entries()) {
1003
- for (const positionedCell of row) {
1004
- if (positionedCell.cell.verticalMerge !== "restart") {
1005
- rowSpans.set(`${rowIndex}:${positionedCell.cellIndex}`, 1);
1006
- continue;
1007
- }
1008
- let rowspan = 1;
1009
- for (let nextRowIndex = rowIndex + 1; nextRowIndex < positionedRows.length; nextRowIndex += 1) {
1010
- const continuedCell = positionedRows[nextRowIndex]?.find(
1011
- (candidate) => candidate.cell.verticalMerge === "continue" && candidate.startColumn === positionedCell.startColumn && candidate.endColumn === positionedCell.endColumn
1012
- );
1013
- if (!continuedCell) {
1014
- break;
1015
- }
1016
- rowspan += 1;
1017
- }
1018
- rowSpans.set(`${rowIndex}:${positionedCell.cellIndex}`, rowspan);
1019
- }
1020
- }
1021
- return rowSpans;
1022
- }
1023
- function resolveCellBorderStyles(borders) {
1024
- if (!borders) return {};
1025
- const result = {};
1026
- const sides = [["top", "borderTop"], ["right", "borderRight"], ["bottom", "borderBottom"], ["left", "borderLeft"]];
1027
- for (const [side, key] of sides) {
1028
- const spec = borders[side];
1029
- if (!spec || spec.value === "none" || spec.value === "nil") continue;
1030
- const width = spec.size ? `${Math.max(1, Math.round(spec.size / 8))}px` : "1px";
1031
- const style = spec.value === "double" ? "double" : spec.value === "dashed" || spec.value === "dashSmallGap" ? "dashed" : spec.value === "dotted" ? "dotted" : "solid";
1032
- const color = spec.color && spec.color !== "auto" ? `#${spec.color}` : "currentColor";
1033
- result[key] = `${width} ${style} ${color}`;
1034
- }
1035
- return result;
1036
- }
1037
- function createSdtBlock(sdtIndex, block, document, cursor, counters, numberingPrefixResolver) {
1038
- const children = [];
1039
- const lockedFragmentIds = [];
1040
- let innerCursor = cursor;
1041
- for (const child of block.children) {
1042
- const result = createSurfaceBlock(
1043
- child,
1044
- document,
1045
- innerCursor,
1046
- counters,
1047
- numberingPrefixResolver
1048
- );
1049
- children.push(result.block);
1050
- lockedFragmentIds.push(...result.lockedFragmentIds);
1051
- innerCursor = result.nextCursor;
1052
- }
1053
- return {
1054
- block: {
1055
- blockId: `sdt-${sdtIndex}`,
1056
- kind: "sdt_block",
1057
- from: cursor,
1058
- to: innerCursor,
1059
- ...block.properties.sdtType ? { sdtType: block.properties.sdtType } : {},
1060
- ...block.properties.alias ? { alias: block.properties.alias } : {},
1061
- ...block.properties.tag ? { tag: block.properties.tag } : {},
1062
- ...block.properties.lock ? { lock: block.properties.lock } : {},
1063
- ...block.properties.checkbox ? { checkboxChecked: block.properties.checkbox.checked } : {},
1064
- ...block.properties.datePicker?.fullDate ? { dateValue: block.properties.datePicker.fullDate } : {},
1065
- ...block.properties.dropdownList ? { dropdownItems: block.properties.dropdownList } : {},
1066
- ...block.properties.comboBox ? { comboBoxItems: block.properties.comboBox } : {},
1067
- ...block.properties.showingPlcHdr ? { showingPlcHdr: true } : {},
1068
- children
1069
- },
1070
- lockedFragmentIds,
1071
- nextCursor: innerCursor
1072
- };
1073
- }
1074
- function createParagraphBlock(paragraphIndex, paragraph, document, start, numberingPrefixResolver) {
1075
- const accumulator = {
1076
- blockId: `paragraph-${paragraphIndex}`,
1077
- kind: "paragraph",
1078
- from: start,
1079
- to: start,
1080
- ...paragraph.styleId ? { styleId: paragraph.styleId } : {},
1081
- ...paragraph.numbering ? { numbering: paragraph.numbering } : {},
1082
- ...paragraph.numbering ? (() => {
1083
- const detailed = numberingPrefixResolver.resolveDetailed(paragraph.numbering);
1084
- return detailed ? {
1085
- numberingPrefix: detailed.text,
1086
- ...detailed.suffix ? { numberingSuffix: detailed.suffix } : {}
1087
- } : {};
1088
- })() : {},
1089
- ...paragraph.alignment ? { alignment: paragraph.alignment } : {},
1090
- ...paragraph.spacing ? { spacing: paragraph.spacing } : {},
1091
- ...paragraph.contextualSpacing !== void 0 ? { contextualSpacing: paragraph.contextualSpacing } : {},
1092
- ...paragraph.indentation ? { indentation: paragraph.indentation } : {},
1093
- ...paragraph.borders ? { borders: paragraph.borders } : {},
1094
- ...paragraph.shading ? { shading: paragraph.shading } : {},
1095
- ...paragraph.tabStops && paragraph.tabStops.length > 0 ? { tabStops: paragraph.tabStops.map((tabStop) => toSurfaceTabStop(tabStop)) } : {},
1096
- ...paragraph.keepNext ? { keepNext: true } : {},
1097
- ...paragraph.keepLines ? { keepLines: true } : {},
1098
- ...paragraph.pageBreakBefore ? { pageBreakBefore: true } : {},
1099
- ...paragraph.outlineLevel !== void 0 ? { outlineLevel: paragraph.outlineLevel } : {},
1100
- ...paragraph.bidi ? { bidi: true } : {},
1101
- ...paragraph.suppressLineNumbers ? { suppressLineNumbers: true } : {},
1102
- segments: []
1103
- };
1104
- const lockedFragmentIds = [];
1105
- let cursor = start;
1106
- const children = Array.isArray(paragraph.children) ? paragraph.children : [];
1107
- for (const child of children) {
1108
- const result = appendInlineSegments(accumulator, child, document, cursor);
1109
- cursor = result.nextCursor;
1110
- lockedFragmentIds.push(...result.lockedFragmentIds);
1111
- }
1112
- accumulator.to = cursor;
1113
- return {
1114
- block: accumulator,
1115
- nextCursor: cursor,
1116
- lockedFragmentIds
1117
- };
1118
- }
1119
- function appendInlineSegments(paragraph, node, document, start, hyperlinkHref) {
1120
- switch (node.type) {
1121
- case "text":
1122
- paragraph.segments.push({
1123
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
1124
- kind: "text",
1125
- from: start,
1126
- to: start + Array.from(node.text).length,
1127
- text: node.text,
1128
- ...node.marks ? (() => {
1129
- const result = cloneMarks2(node.marks);
1130
- return {
1131
- ...result.marks.length > 0 ? { marks: result.marks } : {},
1132
- ...result.markAttrs ? { markAttrs: result.markAttrs } : {}
1133
- };
1134
- })() : {},
1135
- ...hyperlinkHref ? { hyperlinkHref } : {}
1136
- });
1137
- return { nextCursor: start + Array.from(node.text).length, lockedFragmentIds: [] };
1138
- case "tab":
1139
- paragraph.segments.push({
1140
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
1141
- kind: "tab",
1142
- from: start,
1143
- to: start + 1,
1144
- ...hyperlinkHref ? { hyperlinkHref } : {}
1145
- });
1146
- return { nextCursor: start + 1, lockedFragmentIds: [] };
1147
- case "hard_break":
1148
- paragraph.segments.push({
1149
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
1150
- kind: "hard_break",
1151
- from: start,
1152
- to: start + 1,
1153
- ...hyperlinkHref ? { hyperlinkHref } : {}
1154
- });
1155
- return { nextCursor: start + 1, lockedFragmentIds: [] };
1156
- case "hyperlink": {
1157
- let cursor = start;
1158
- for (const child of node.children) {
1159
- const result = appendInlineSegments(paragraph, child, document, cursor, node.href);
1160
- cursor = result.nextCursor;
1161
- }
1162
- return { nextCursor: cursor, lockedFragmentIds: [] };
1163
- }
1164
- case "image":
1165
- paragraph.segments.push({
1166
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
1167
- kind: "image",
1168
- from: start,
1169
- to: start + 1,
1170
- mediaId: node.mediaId,
1171
- altText: node.altText,
1172
- state: hasMediaItem(document.media, node.mediaId) ? "editable" : "missing",
1173
- ...node.display ? { display: node.display } : {},
1174
- detail: node.display === "floating" ? createFloatingImageDetail(node.altText, node.floating) : node.altText ? `Alt text ${node.altText}.` : "Inline image remains a whole-unit render surface."
1175
- });
1176
- return { nextCursor: start + 1, lockedFragmentIds: [] };
1177
- case "opaque_inline": {
1178
- const fragment = getOpaqueFragment(document.preservation, node.fragmentId);
1179
- const descriptor = fragment ? describeOpaqueFragment(fragment) : null;
1180
- const preview = fragment ? describePreservedInlinePreview(fragment.payloadReference) : null;
1181
- paragraph.segments.push({
1182
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
1183
- kind: "opaque_inline",
1184
- from: start,
1185
- to: start + 1,
1186
- fragmentId: node.fragmentId,
1187
- warningId: node.warningId,
1188
- label: preview?.label ?? descriptor?.label ?? "Unsupported inline OOXML",
1189
- detail: preview?.detail ?? descriptor?.detail ?? "Locked whole-unit to keep unsupported inline OOXML intact through export.",
1190
- ...preview?.presentation ? { presentation: preview.presentation } : {},
1191
- state: "locked-preserve-only"
1192
- });
1193
- return { nextCursor: start + 1, lockedFragmentIds: [node.fragmentId] };
1194
- }
1195
- case "chart_preview":
1196
- return appendComplexPreviewSegment(paragraph, node, start, "Embedded chart", createChartDetail(node));
1197
- case "smartart_preview":
1198
- return appendComplexPreviewSegment(paragraph, node, start, "SmartArt diagram", createSmartArtDetail(node));
1199
- case "shape":
1200
- return appendComplexPreviewSegment(
1201
- paragraph,
1202
- node,
1203
- start,
1204
- node.isTextBox ? "Text box" : "Drawing shape",
1205
- createShapeDetail(node)
1206
- );
1207
- case "wordart":
1208
- return appendComplexPreviewSegment(paragraph, node, start, "WordArt", createWordArtDetail(node));
1209
- case "vml_shape":
1210
- return appendComplexPreviewSegment(paragraph, node, start, "Legacy VML drawing", createVmlDetail(node));
1211
- case "symbol":
1212
- paragraph.segments.push({
1213
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
1214
- kind: "text",
1215
- from: start,
1216
- to: start + 1,
1217
- text: node.char ? String.fromCodePoint(parseInt(node.char, 16)) : "\uFFFD"
1218
- });
1219
- return { nextCursor: start + 1, lockedFragmentIds: [] };
1220
- case "column_break":
1221
- paragraph.segments.push({
1222
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
1223
- kind: "opaque_inline",
1224
- from: start,
1225
- to: start + 1,
1226
- fragmentId: "",
1227
- warningId: "",
1228
- label: "Column break",
1229
- detail: "Column break marker preserved for export.",
1230
- state: "locked-preserve-only"
1231
- });
1232
- return { nextCursor: start + 1, lockedFragmentIds: [] };
1233
- case "footnote_ref":
1234
- paragraph.segments.push({
1235
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
1236
- kind: "note_ref",
1237
- from: start,
1238
- to: start + 1,
1239
- noteKind: node.noteKind ?? "footnote",
1240
- noteId: node.noteId ?? "",
1241
- label: node.noteId ?? "*"
1242
- });
1243
- return { nextCursor: start + 1, lockedFragmentIds: [] };
1244
- case "field": {
1245
- const isSupportedField = node.fieldFamily === "REF" || node.fieldFamily === "PAGEREF" || node.fieldFamily === "NOTEREF" || node.fieldFamily === "TOC";
1246
- if (node.children && node.children.length > 0) {
1247
- let cursor = start;
1248
- const lockedIds = [];
1249
- for (const child of node.children) {
1250
- const result = appendInlineSegments(paragraph, child, document, cursor);
1251
- cursor = result.nextCursor;
1252
- lockedIds.push(...result.lockedFragmentIds);
1253
- }
1254
- return { nextCursor: cursor, lockedFragmentIds: lockedIds };
1255
- }
1256
- if (isSupportedField) {
1257
- const fieldLabel = node.fieldFamily === "TOC" ? "Table of Contents" : `${node.fieldFamily ?? "Field"}: ${node.fieldTarget ?? node.instruction.trim()}`;
1258
- paragraph.segments.push({
1259
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
1260
- kind: "field_ref",
1261
- from: start,
1262
- to: start + 1,
1263
- fieldFamily: node.fieldFamily,
1264
- fieldTarget: node.fieldTarget,
1265
- instruction: node.instruction,
1266
- refreshStatus: node.refreshStatus ?? "stale",
1267
- label: fieldLabel
1268
- });
1269
- return { nextCursor: start + 1, lockedFragmentIds: [] };
1270
- }
1271
- paragraph.segments.push({
1272
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
1273
- kind: "opaque_inline",
1274
- from: start,
1275
- to: start + 1,
1276
- fragmentId: "",
1277
- warningId: "",
1278
- label: "Field",
1279
- detail: `Preserve-only field: ${node.instruction.trim()}`,
1280
- state: "locked-preserve-only"
1281
- });
1282
- return { nextCursor: start + 1, lockedFragmentIds: [] };
1283
- }
1284
- case "bookmark_start":
1285
- case "bookmark_end":
1286
- return { nextCursor: start, lockedFragmentIds: [] };
1287
- default:
1288
- return { nextCursor: start + 1, lockedFragmentIds: [] };
1289
- }
1290
- }
1291
- function appendComplexPreviewSegment(paragraph, node, start, label, detail) {
1292
- paragraph.segments.push({
1293
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
1294
- kind: "opaque_inline",
1295
- from: start,
1296
- to: start + 1,
1297
- fragmentId: `complex:${label.replace(/\s/g, "-").toLowerCase()}:${start}`,
1298
- warningId: `warning:complex-preview:${start}`,
1299
- label,
1300
- detail,
1301
- state: "locked-preserve-only"
1302
- });
1303
- return { nextCursor: start + 1, lockedFragmentIds: [] };
1304
- }
1305
- function createChartDetail(node) {
1306
- const parts = ["Embedded chart."];
1307
- if (node.previewMediaId) {
1308
- parts.push(`Preview available via fallback image (${node.previewMediaId}).`);
1309
- } else {
1310
- parts.push("No fallback preview image found; chart data preserved in package.");
1311
- }
1312
- parts.push("Edit in Word to modify chart data. Original DrawingML preserved for lossless export.");
1313
- return parts.join(" ");
1314
- }
1315
- function createSmartArtDetail(node) {
1316
- const parts = ["SmartArt diagram."];
1317
- if (node.previewMediaId) {
1318
- parts.push(`Preview available via fallback image (${node.previewMediaId}).`);
1319
- } else {
1320
- parts.push("No fallback preview image found; diagram structure preserved in package.");
1321
- }
1322
- parts.push("Edit in Word to modify diagram layout and content. Original DrawingML preserved for lossless export.");
1323
- return parts.join(" ");
1324
- }
1325
- function createShapeDetail(node) {
1326
- if (node.isTextBox) {
1327
- const parts2 = ["Text box."];
1328
- if (node.text) parts2.push(`Content: "${node.text}".`);
1329
- parts2.push("Text content is visible; formatting and geometry preserved for export.");
1330
- return parts2.join(" ");
1331
- }
1332
- const parts = ["Drawing shape."];
1333
- if (node.geometry) parts.push(`Geometry: ${node.geometry}.`);
1334
- if (node.text) parts.push(`Text content: "${node.text}".`);
1335
- parts.push("Visual geometry is preview-only. Original DrawingML preserved for export.");
1336
- return parts.join(" ");
1337
- }
1338
- function createWordArtDetail(node) {
1339
- const parts = ["WordArt decorative text."];
1340
- if (node.text) parts.push(`Text: "${node.text}".`);
1341
- if (node.geometry) parts.push(`Effect: ${node.geometry}.`);
1342
- parts.push("Text effect is preview-only. Edit in Word for full formatting. Original DrawingML preserved for export.");
1343
- return parts.join(" ");
1344
- }
1345
- function createVmlDetail(node) {
1346
- const parts = ["Legacy VML drawing."];
1347
- if (node.shapeType) parts.push(`Type: ${node.shapeType}.`);
1348
- if (node.text) parts.push(`Text content: "${node.text}".`);
1349
- parts.push("VML content is preview-only. Edit in Word for full control. Original VML XML preserved for export.");
1350
- return parts.join(" ");
1351
- }
1352
- function createPlainText2(blocks) {
1353
- const text = [];
1354
- for (const block of blocks) {
1355
- if (block.kind === "opaque_block") {
1356
- if (block.fragmentId.startsWith("preview:")) {
1357
- continue;
1358
- }
1359
- text.push("\uFFFA");
1360
- continue;
1361
- }
1362
- if (block.kind === "table") {
1363
- for (const row of block.rows) {
1364
- for (const cell of row.cells) {
1365
- text.push(createPlainText2(cell.content));
1366
- }
1367
- }
1368
- continue;
1369
- }
1370
- if (block.kind === "sdt_block") {
1371
- text.push(createPlainText2(block.children));
1372
- continue;
1373
- }
1374
- for (const segment of block.segments) {
1375
- switch (segment.kind) {
1376
- case "text":
1377
- text.push(segment.text);
1378
- break;
1379
- case "tab":
1380
- text.push(" ");
1381
- break;
1382
- case "hard_break":
1383
- text.push("\n");
1384
- break;
1385
- case "image":
1386
- text.push("\uFFFC");
1387
- break;
1388
- case "opaque_inline":
1389
- text.push("\uFFF9");
1390
- break;
1391
- }
1392
- }
1393
- }
1394
- return text.join("");
1395
- }
1396
- function createSecondaryStorySurfaces(document) {
1397
- const surfaces = [];
1398
- const subParts = document.subParts;
1399
- if (!subParts) {
1400
- return surfaces;
1401
- }
1402
- const numberingPrefixResolver = createNumberingPrefixResolver(document.numbering);
1403
- for (const section of collectSectionContexts(document)) {
1404
- const headerVariants = resolveSectionVariants(
1405
- "header",
1406
- section.index,
1407
- section.properties?.headerReferences,
1408
- subParts.headers ?? []
1409
- );
1410
- for (const headerVariant of headerVariants) {
1411
- const target = {
1412
- kind: "header",
1413
- relationshipId: headerVariant.relationshipId,
1414
- variant: headerVariant.variant,
1415
- sectionIndex: section.index
1416
- };
1417
- const header = findHeaderFooterDocumentEntry(document, target);
1418
- if (!header) {
1419
- continue;
1420
- }
1421
- surfaces.push(
1422
- createStorySurface(
1423
- target,
1424
- `Header \xB7 ${headerVariant.variant}`,
1425
- header.blocks,
1426
- document,
1427
- numberingPrefixResolver
1428
- )
1429
- );
1430
- }
1431
- const footerVariants = resolveSectionVariants(
1432
- "footer",
1433
- section.index,
1434
- section.properties?.footerReferences,
1435
- subParts.footers ?? []
1436
- );
1437
- for (const footerVariant of footerVariants) {
1438
- const target = {
1439
- kind: "footer",
1440
- relationshipId: footerVariant.relationshipId,
1441
- variant: footerVariant.variant,
1442
- sectionIndex: section.index
1443
- };
1444
- const footer = findHeaderFooterDocumentEntry(document, target);
1445
- if (!footer) {
1446
- continue;
1447
- }
1448
- surfaces.push(
1449
- createStorySurface(
1450
- target,
1451
- `Footer \xB7 ${footerVariant.variant}`,
1452
- footer.blocks,
1453
- document,
1454
- numberingPrefixResolver
1455
- )
1456
- );
1457
- }
1458
- }
1459
- const footnotes = Object.values(subParts.footnoteCollection?.footnotes ?? {}).sort(compareNoteIds);
1460
- for (const note of footnotes) {
1461
- const target = { kind: "footnote", noteId: note.noteId };
1462
- surfaces.push(createStorySurface(target, `Footnote ${note.noteId}`, note.blocks, document, numberingPrefixResolver));
1463
- }
1464
- const endnotes = Object.values(subParts.footnoteCollection?.endnotes ?? {}).sort(compareNoteIds);
1465
- for (const note of endnotes) {
1466
- const target = { kind: "endnote", noteId: note.noteId };
1467
- surfaces.push(createStorySurface(target, `Endnote ${note.noteId}`, note.blocks, document, numberingPrefixResolver));
1468
- }
1469
- return surfaces;
1470
- }
1471
- function createStorySurface(target, label, blocks, document, numberingPrefixResolver) {
1472
- const surfaceBlocks = [];
1473
- let cursor = 0;
1474
- const counters = {
1475
- paragraph: 0,
1476
- table: 0,
1477
- opaque: 0,
1478
- sdt: 0,
1479
- customXml: 0,
1480
- altChunk: 0
1481
- };
1482
- for (let index = 0; index < blocks.length; index += 1) {
1483
- const surfaceBlock = createSurfaceBlock(
1484
- blocks[index],
1485
- document,
1486
- cursor,
1487
- counters,
1488
- numberingPrefixResolver
1489
- );
1490
- surfaceBlocks.push(surfaceBlock.block);
1491
- cursor = surfaceBlock.nextCursor;
1492
- if (index < blocks.length - 1 && blocks[index + 1]?.type === "paragraph") {
1493
- cursor += 1;
1494
- }
1495
- }
1496
- return {
1497
- target,
1498
- label,
1499
- storySize: cursor,
1500
- blocks: surfaceBlocks
1501
- };
1502
- }
1503
- function compareNoteIds(left, right) {
1504
- return Number.parseInt(left.noteId, 10) - Number.parseInt(right.noteId, 10);
1505
- }
1506
- function toSurfaceTabStop(tabStop) {
1507
- return {
1508
- pos: tabStop.position,
1509
- ...tabStop.align ? { val: tabStop.align } : {},
1510
- ...tabStop.leader ? { leader: tabStop.leader } : {}
1511
- };
1512
- }
1513
- function describePreservedInlinePreview(payloadReference) {
1514
- if (/\b(?:w:)?proofErr\b/u.test(payloadReference)) {
1515
- const proofType = /\bw:type="([^"]+)"/u.exec(payloadReference)?.[1];
1516
- return {
1517
- label: "Proofing marker",
1518
- detail: proofType && proofType.trim().length > 0 ? `Word proofing marker (${proofType}) preserved for export safety.` : "Word proofing marker preserved for export safety.",
1519
- presentation: "quiet-marker"
1520
- };
1521
- }
1522
- if (/\b(?:w:)?lastRenderedPageBreak\b/u.test(payloadReference)) {
1523
- return {
1524
- label: "Rendered page break",
1525
- detail: "Word rendered page-break marker preserved for export safety.",
1526
- presentation: "quiet-marker"
1527
- };
1528
- }
1529
- if (/\b(?:w:)?permStart\b/u.test(payloadReference)) {
1530
- const editorGroup = /\bw:edGrp="([^"]+)"/u.exec(payloadReference)?.[1];
1531
- return {
1532
- label: "Protected range start",
1533
- detail: editorGroup && editorGroup.trim().length > 0 ? `Protected range start for ${editorGroup} preserved for export safety.` : "Protected range start preserved for export safety.",
1534
- presentation: "quiet-marker"
1535
- };
1536
- }
1537
- if (/\b(?:w:)?permEnd\b/u.test(payloadReference)) {
1538
- return {
1539
- label: "Protected range end",
1540
- detail: "Protected range end preserved for export safety.",
1541
- presentation: "quiet-marker"
1542
- };
1543
- }
1544
- if (/\b(?:w:)?bookmarkStart\b/u.test(payloadReference)) {
1545
- const name = /\bw:name="([^"]+)"/u.exec(payloadReference)?.[1];
1546
- return {
1547
- label: name ? `Bookmark \xB7 ${name}` : "Bookmark",
1548
- 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."
1549
- };
1550
- }
1551
- if (/\b(?:w:)?bookmarkEnd\b/u.test(payloadReference)) {
1552
- return {
1553
- label: "Bookmark end",
1554
- detail: "Bookmark end marker is preserved as a read-only inline token for export safety."
1555
- };
1556
- }
1557
- if (/\b(?:w:)?fldSimple\b|\b(?:w:)?fldChar\b|\b(?:w:)?instrText\b/u.test(payloadReference)) {
1558
- const simpleInstruction = /\bw:instr="([^"]*)"/u.exec(payloadReference)?.[1];
1559
- const complexInstruction = [...payloadReference.matchAll(/<(?:\w+:)?instrText\b[^>]*>([\s\S]*?)<\/(?:\w+:)?instrText>/gu)].map((match) => decodeXmlEntities(match[1] ?? "")).join("").trim();
1560
- const instruction = (simpleInstruction ?? complexInstruction ?? "").trim();
1561
- const family = /^([A-Z]+)/i.exec(instruction)?.[1]?.toUpperCase();
1562
- const label = family === "TOC" ? "Table of Contents field" : family ? `${family} field` : "Field";
1563
- return {
1564
- label,
1565
- detail: instruction.length > 0 ? `Read-only field preserved for export safety. Instruction: ${instruction}.` : "Read-only field preserved for export safety."
1566
- };
1567
- }
1568
- return null;
1569
- }
1570
- function decodeXmlEntities(text) {
1571
- return text.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, "&");
1572
- }
1573
- function cloneMarks2(marks) {
1574
- const supported = [];
1575
- const attrs = {};
1576
- let shadingColor;
1577
- let highlightColor;
1578
- for (const mark of marks) {
1579
- switch (mark.type) {
1580
- case "bold":
1581
- case "italic":
1582
- case "underline":
1583
- case "strikethrough":
1584
- case "doubleStrikethrough":
1585
- case "vanish":
1586
- case "emboss":
1587
- case "imprint":
1588
- case "shadow":
1589
- supported.push(mark.type);
1590
- break;
1591
- case "position":
1592
- if (mark.val > 0) supported.push("superscript");
1593
- else if (mark.val < 0) supported.push("subscript");
1594
- break;
1595
- case "backgroundColor":
1596
- shadingColor = mark.color;
1597
- break;
1598
- case "highlight":
1599
- highlightColor = mark.color;
1600
- break;
1601
- case "charSpacing":
1602
- attrs.charSpacing = mark.val;
1603
- break;
1604
- case "kerning":
1605
- attrs.kerning = mark.val;
1606
- break;
1607
- case "textFill":
1608
- attrs.textFill = mark.xml;
1609
- break;
1610
- case "fontFamily":
1611
- attrs.fontFamily = mark.val;
1612
- break;
1613
- case "fontSize":
1614
- attrs.fontSize = mark.val;
1615
- break;
1616
- case "textColor":
1617
- attrs.textColor = mark.color;
1618
- break;
1619
- case "smallCaps":
1620
- supported.push("smallCaps");
1621
- break;
1622
- case "allCaps":
1623
- supported.push("allCaps");
1624
- break;
1625
- case "lang":
1626
- break;
1627
- }
1628
- }
1629
- if (highlightColor || shadingColor) {
1630
- attrs.backgroundColor = highlightColor ?? shadingColor;
1631
- }
1632
- const hasAttrs = Object.keys(attrs).length > 0;
1633
- return hasAttrs ? { marks: supported, markAttrs: attrs } : { marks: supported };
1634
- }
1635
- function normalizeDocumentRoot2(content) {
1636
- if (content && typeof content === "object" && (content.type === "doc" || content.type === "document_root")) {
1637
- return content;
1638
- }
1639
- if (Array.isArray(content)) {
1640
- return {
1641
- type: "doc",
1642
- children: content.filter(
1643
- (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")
1644
- )
1645
- };
1646
- }
1647
- return {
1648
- type: "doc",
1649
- children: [{ type: "paragraph", children: [] }]
1650
- };
1651
- }
1652
- function createFloatingImageDetail(altText, floating) {
1653
- const parts = [altText ? `Alt text ${altText}.` : "Floating image rendered inline in the editor."];
1654
- if (floating?.wrap) {
1655
- parts.push(`Wrap ${floating.wrap}.`);
1656
- }
1657
- if (floating?.horizontalPosition?.align || floating?.horizontalPosition?.offset !== void 0) {
1658
- parts.push(
1659
- `Horizontal ${floating.horizontalPosition.align ?? floating.horizontalPosition.offset}.`
1660
- );
1661
- }
1662
- if (floating?.verticalPosition?.align || floating?.verticalPosition?.offset !== void 0) {
1663
- parts.push(
1664
- `Vertical ${floating.verticalPosition.align ?? floating.verticalPosition.offset}.`
1665
- );
1666
- }
1667
- return parts.join(" ");
1668
- }
1669
- function hasMediaItem(media, mediaId) {
1670
- return mediaId in media.items;
1671
- }
1672
-
1673
- // src/core/state/text-transaction.ts
1674
- var TextTransactionError = class extends Error {
1675
- code;
1676
- constructor(code, message) {
1677
- super(message);
1678
- this.name = "TextTransactionError";
1679
- this.code = code;
1680
- }
1681
- };
1682
- function applyTextTransaction(document, selection, intent, options) {
1683
- const tableScopedResult = tryApplyTableParagraphTransaction(
1684
- document,
1685
- selection,
1686
- intent,
1687
- options
1688
- );
1689
- if (tableScopedResult) {
1690
- return tableScopedResult;
1691
- }
1692
- return applyLinearTextTransaction(document, selection, intent, options);
1693
- }
1694
- function applyLinearTextTransaction(document, selection, intent, options) {
1695
- const story = parseTextStory(document.content);
1696
- const normalizedRange = resolveRange(selection, story.size, intent);
1697
- const insertionUnits = createInsertionUnits(intent, story, normalizedRange.from);
1698
- ensureEditableRange(story.units.slice(normalizedRange.from, normalizedRange.to));
1699
- const nextUnits = [
1700
- ...story.units.slice(0, normalizedRange.from).map(cloneStoryUnit),
1701
- ...insertionUnits.map(cloneStoryUnit),
1702
- ...story.units.slice(normalizedRange.to).map(cloneStoryUnit)
1703
- ];
1704
- const nextStory = {
1705
- firstParagraph: cloneParagraphProperties(story.firstParagraph),
1706
- units: normalizeStoryUnits(nextUnits),
1707
- size: 0
1708
- };
1709
- nextStory.size = nextStory.units.length;
1710
- const caret = normalizedRange.from + insertionUnits.length;
1711
- return {
1712
- document: {
1713
- ...document,
1714
- updatedAt: options.timestamp,
1715
- content: serializeTextStory(nextStory)
1716
- },
1717
- selection: createSelectionSnapshot(caret, caret),
1718
- mapping: {
1719
- steps: [
1720
- {
1721
- from: normalizedRange.from,
1722
- to: normalizedRange.to,
1723
- insertSize: insertionUnits.length
1724
- }
1725
- ],
1726
- metadata: {
1727
- affectsComments: true,
1728
- affectsRevisions: true,
1729
- ...containsParagraphBoundaryChange(story, normalizedRange, insertionUnits) ? { invalidatesStructures: true } : {}
1730
- }
1731
- },
1732
- storyText: createPlainText(nextStory)
1733
- };
1734
- }
1735
- function tryApplyTableParagraphTransaction(document, selection, intent, options) {
1736
- const scope = resolveTableParagraphScope(document, selection);
1737
- if (!scope) {
1738
- return null;
1739
- }
1740
- if (scope === "unsupported") {
1741
- throw new TextTransactionError(
1742
- "unsupported_content",
1743
- "Text transactions inside table structures are only supported when the selection stays within one paragraph-backed table cell."
1744
- );
1745
- }
1746
- const localDocument = {
1747
- ...document,
1748
- content: {
1749
- type: "doc",
1750
- children: [scope.paragraph]
1751
- }
1752
- };
1753
- const localSelection = createSelectionSnapshot(
1754
- selection.anchor - scope.paragraphStart,
1755
- selection.head - scope.paragraphStart
1756
- );
1757
- const localResult = applyLinearTextTransaction(localDocument, localSelection, intent, options);
1758
- const nextParagraphBlocks = localResult.document.content.children;
1759
- const nextRoot = {
1760
- ...scope.root,
1761
- children: scope.root.children.map((child, blockIndex) => {
1762
- if (blockIndex !== scope.tableBlockIndex) {
1763
- return child;
1764
- }
1765
- const table = child;
1766
- return {
1767
- ...table,
1768
- rows: table.rows.map((row, rowIndex) => {
1769
- if (rowIndex !== scope.rowIndex) {
1770
- return row;
1771
- }
1772
- return {
1773
- ...row,
1774
- cells: row.cells.map((cell, cellIndex) => {
1775
- if (cellIndex !== scope.cellIndex) {
1776
- return cell;
1777
- }
1778
- return {
1779
- ...cell,
1780
- children: [
1781
- ...cell.children.slice(0, scope.childIndex),
1782
- ...nextParagraphBlocks,
1783
- ...cell.children.slice(scope.childIndex + 1)
1784
- ]
1785
- };
1786
- })
1787
- };
1788
- })
1789
- };
1790
- })
1791
- };
1792
- return {
1793
- document: {
1794
- ...document,
1795
- updatedAt: options.timestamp,
1796
- content: nextRoot
1797
- },
1798
- selection: createSelectionSnapshot(
1799
- localResult.selection.anchor + scope.paragraphStart,
1800
- localResult.selection.head + scope.paragraphStart
1801
- ),
1802
- mapping: {
1803
- ...localResult.mapping,
1804
- steps: localResult.mapping.steps.map((step) => ({
1805
- ...step,
1806
- from: step.from + scope.paragraphStart,
1807
- to: step.to + scope.paragraphStart
1808
- }))
1809
- },
1810
- storyText: localResult.storyText
1811
- };
1812
- }
1813
- function resolveTableParagraphScope(document, selection) {
1814
- const root = document.content;
1815
- if (!root || root.type !== "doc" || !Array.isArray(root.children)) {
1816
- return null;
1817
- }
1818
- const surface = createEditorSurfaceSnapshot(document, selection);
1819
- const selectionFrom = Math.min(selection.anchor, selection.head);
1820
- const selectionTo = Math.max(selection.anchor, selection.head);
1821
- for (let blockIndex = 0; blockIndex < root.children.length; blockIndex += 1) {
1822
- const block = root.children[blockIndex];
1823
- const surfaceBlock = surface.blocks[blockIndex];
1824
- if (block?.type !== "table" || surfaceBlock?.kind !== "table") {
1825
- continue;
1826
- }
1827
- const insideTable = selectionFallsWithinSurfaceRange(
1828
- selectionFrom,
1829
- selectionTo,
1830
- surfaceBlock.from,
1831
- surfaceBlock.to
1832
- );
1833
- if (!insideTable) {
1834
- continue;
1835
- }
1836
- for (let rowIndex = 0; rowIndex < block.rows.length; rowIndex += 1) {
1837
- const row = block.rows[rowIndex];
1838
- const surfaceRow = surfaceBlock.rows[rowIndex];
1839
- if (!row || !surfaceRow) {
1840
- continue;
1841
- }
1842
- for (let cellIndex = 0; cellIndex < row.cells.length; cellIndex += 1) {
1843
- const cell = row.cells[cellIndex];
1844
- const surfaceCell = surfaceRow.cells[cellIndex];
1845
- if (!cell || !surfaceCell) {
1846
- continue;
1847
- }
1848
- for (let childIndex = 0; childIndex < Math.min(cell.children.length, surfaceCell.content.length); childIndex += 1) {
1849
- const child = cell.children[childIndex];
1850
- const surfaceChild = surfaceCell.content[childIndex];
1851
- if (child?.type !== "paragraph" || surfaceChild?.kind !== "paragraph") {
1852
- continue;
1853
- }
1854
- const insideParagraph = selectionFallsWithinSurfaceRange(
1855
- selectionFrom,
1856
- selectionTo,
1857
- surfaceChild.from,
1858
- surfaceChild.to
1859
- );
1860
- if (!insideParagraph) {
1861
- continue;
1862
- }
1863
- return {
1864
- root,
1865
- tableBlockIndex: blockIndex,
1866
- rowIndex,
1867
- cellIndex,
1868
- childIndex,
1869
- paragraph: child,
1870
- paragraphStart: surfaceChild.from
1871
- };
1872
- }
1873
- }
1874
- }
1875
- return "unsupported";
1876
- }
1877
- return null;
1878
- }
1879
- function selectionFallsWithinSurfaceRange(selectionFrom, selectionTo, rangeFrom, rangeTo) {
1880
- if (rangeFrom === rangeTo) {
1881
- return selectionFrom === rangeFrom && selectionTo === rangeTo;
1882
- }
1883
- return selectionFrom >= rangeFrom && selectionTo <= rangeTo && selectionFrom < rangeTo;
1884
- }
1885
- function resolveRange(selection, storySize, intent) {
1886
- const from = Math.max(0, Math.min(selection.anchor, selection.head));
1887
- const to = Math.max(0, Math.max(selection.anchor, selection.head));
1888
- if (from > storySize || to > storySize) {
1889
- throw new TextTransactionError(
1890
- "invalid_selection",
1891
- `Selection ${from}-${to} exceeds story size ${storySize}.`
1892
- );
1893
- }
1894
- if (intent.type === "replace") {
1895
- if (intent.range) {
1896
- const explicitFrom = Math.max(0, Math.min(intent.range.from, intent.range.to));
1897
- const explicitTo = Math.max(0, Math.max(intent.range.from, intent.range.to));
1898
- if (explicitFrom > storySize || explicitTo > storySize) {
1899
- throw new TextTransactionError(
1900
- "invalid_selection",
1901
- `Explicit range ${explicitFrom}-${explicitTo} exceeds story size ${storySize}.`
1902
- );
1903
- }
1904
- return {
1905
- from: explicitFrom,
1906
- to: explicitTo
1907
- };
1908
- }
1909
- return { from, to };
1910
- }
1911
- if (from !== to) {
1912
- return { from, to };
1913
- }
1914
- if (intent.type === "delete_backward") {
1915
- return {
1916
- from: Math.max(0, from - 1),
1917
- to: from
1918
- };
1919
- }
1920
- return {
1921
- from,
1922
- to: Math.min(storySize, from + 1)
1923
- };
1924
- }
1925
- function createInsertionUnits(intent, story, position) {
1926
- if (intent.type !== "replace") {
1927
- return [];
1928
- }
1929
- const inheritedProps = resolveParagraphPropertiesAtPosition(story, position);
1930
- return intent.insertion.flatMap((entry) => {
1931
- switch (entry.type) {
1932
- case "text":
1933
- return Array.from(entry.text).map((character) => ({
1934
- kind: "text",
1935
- value: character
1936
- }));
1937
- case "tab":
1938
- return [{ kind: "tab" }];
1939
- case "hard_break":
1940
- return [{ kind: "hard_break" }];
1941
- case "paragraph_break":
1942
- return [
1943
- {
1944
- kind: "paragraph_break",
1945
- nextParagraph: cloneParagraphProperties(inheritedProps)
1946
- }
1947
- ];
1948
- }
1949
- });
1950
- }
1951
- function resolveParagraphPropertiesAtPosition(story, position) {
1952
- let current = cloneParagraphProperties(story.firstParagraph);
1953
- for (let index = 0; index < Math.min(position, story.units.length); index += 1) {
1954
- const unit = story.units[index];
1955
- if (unit.kind === "paragraph_break") {
1956
- current = cloneParagraphProperties(unit.nextParagraph);
1957
- } else if (unit.kind === "opaque_block" && unit.nextParagraph) {
1958
- current = cloneParagraphProperties(unit.nextParagraph);
1959
- }
1960
- }
1961
- return current;
1962
- }
1963
- function normalizeStoryUnits(units) {
1964
- if (units.length === 0) {
1965
- return [];
1966
- }
1967
- const normalized = [];
1968
- for (const unit of units) {
1969
- if (unit.kind === "paragraph_break" && normalized[normalized.length - 1]?.kind === "paragraph_break") {
1970
- normalized.push({
1971
- kind: "paragraph_break",
1972
- nextParagraph: cloneParagraphProperties(unit.nextParagraph)
1973
- });
1974
- continue;
1975
- }
1976
- normalized.push(cloneStoryUnit(unit));
1977
- }
1978
- return normalized;
1979
- }
1980
- function ensureEditableRange(units) {
1981
- const protectedUnit = units.find(
1982
- (unit) => unit.kind === "opaque_inline" || unit.kind === "opaque_block" || unit.kind === "image"
1983
- );
1984
- if (!protectedUnit) {
1985
- return;
1986
- }
1987
- throw new TextTransactionError(
1988
- "unsupported_content",
1989
- `Text transaction crosses protected ${protectedUnit.kind} content.`
1990
- );
1991
- }
1992
- function containsParagraphBoundaryChange(story, range, insertionUnits) {
1993
- if (insertionUnits.some((unit) => unit.kind === "paragraph_break")) {
1994
- return true;
1995
- }
1996
- return story.units.slice(range.from, range.to).some((unit) => unit.kind === "paragraph_break");
1997
- }
1998
-
1999
- // src/core/commands/structural-helpers.ts
2000
- var DEFAULT_TABLE_COLUMN_WIDTH = 2400;
2001
- function createNoopStructuralMutation(document, selection) {
2002
- return {
2003
- changed: false,
2004
- document,
2005
- selection
2006
- };
2007
- }
2008
- function resolveParagraphScope(document, selection) {
2009
- const root = asDocumentRoot(document);
2010
- if (!root) {
2011
- return null;
2012
- }
2013
- const surface = createEditorSurfaceSnapshot(document, selection);
2014
- const selectionFrom = Math.min(selection.anchor, selection.head);
2015
- const selectionTo = Math.max(selection.anchor, selection.head);
2016
- for (let blockIndex = 0; blockIndex < root.children.length; blockIndex += 1) {
2017
- const block = root.children[blockIndex];
2018
- const surfaceBlock = surface.blocks[blockIndex];
2019
- if (!surfaceBlock) {
2020
- continue;
2021
- }
2022
- if (block.type === "paragraph" && surfaceBlock.kind === "paragraph" && selectionWithinRange(selectionFrom, selectionTo, surfaceBlock.from, surfaceBlock.to)) {
2023
- return {
2024
- kind: "top-level",
2025
- blockIndex,
2026
- paragraph: cloneParagraph(block),
2027
- paragraphStart: surfaceBlock.from
2028
- };
2029
- }
2030
- if (block.type !== "table" || surfaceBlock.kind !== "table") {
2031
- continue;
2032
- }
2033
- for (let rowIndex = 0; rowIndex < block.rows.length; rowIndex += 1) {
2034
- const row = block.rows[rowIndex];
2035
- const surfaceRow = surfaceBlock.rows[rowIndex];
2036
- if (!surfaceRow) {
2037
- continue;
2038
- }
2039
- for (let cellIndex = 0; cellIndex < row.cells.length; cellIndex += 1) {
2040
- const cell = row.cells[cellIndex];
2041
- const surfaceCell = surfaceRow.cells[cellIndex];
2042
- if (!surfaceCell) {
2043
- continue;
2044
- }
2045
- for (let childIndex = 0; childIndex < cell.children.length; childIndex += 1) {
2046
- const child = cell.children[childIndex];
2047
- const surfaceChild = surfaceCell.content[childIndex];
2048
- if (child?.type === "paragraph" && surfaceChild?.kind === "paragraph" && selectionWithinRange(selectionFrom, selectionTo, surfaceChild.from, surfaceChild.to)) {
2049
- return {
2050
- kind: "table-cell",
2051
- tableBlockIndex: blockIndex,
2052
- rowIndex,
2053
- cellIndex,
2054
- childIndex,
2055
- paragraph: cloneParagraph(child),
2056
- paragraphStart: surfaceChild.from
2057
- };
2058
- }
2059
- }
2060
- }
2061
- }
2062
- }
2063
- return null;
2064
- }
2065
- function replaceParagraphScope(document, scope, replacementParagraphs) {
2066
- const root = asDocumentRoot(document);
2067
- if (!root) {
2068
- return document;
2069
- }
2070
- const nextRoot = scope.kind === "top-level" ? {
2071
- ...root,
2072
- children: [
2073
- ...root.children.slice(0, scope.blockIndex),
2074
- ...replacementParagraphs,
2075
- ...root.children.slice(scope.blockIndex + 1)
2076
- ]
2077
- } : {
2078
- ...root,
2079
- children: root.children.map((child, blockIndex) => {
2080
- if (blockIndex !== scope.tableBlockIndex || child.type !== "table") {
2081
- return child;
2082
- }
2083
- return {
2084
- ...child,
2085
- rows: child.rows.map((row, rowIndex) => {
2086
- if (rowIndex !== scope.rowIndex) {
2087
- return row;
2088
- }
2089
- return {
2090
- ...row,
2091
- cells: row.cells.map((cell, cellIndex) => {
2092
- if (cellIndex !== scope.cellIndex) {
2093
- return cell;
2094
- }
2095
- return {
2096
- ...cell,
2097
- children: [
2098
- ...cell.children.slice(0, scope.childIndex),
2099
- ...replacementParagraphs,
2100
- ...cell.children.slice(scope.childIndex + 1)
2101
- ]
2102
- };
2103
- })
2104
- };
2105
- })
2106
- };
2107
- })
2108
- };
2109
- return {
2110
- ...document,
2111
- content: nextRoot
2112
- };
2113
- }
2114
- function createEmptyParagraph2() {
2115
- return {
2116
- type: "paragraph",
2117
- children: []
2118
- };
2119
- }
2120
- function createInsertedTableBlock(rows, columns, styleId) {
2121
- const safeRows = Math.max(1, Math.floor(rows));
2122
- const safeColumns = Math.max(1, Math.floor(columns));
2123
- const nextRows = [];
2124
- for (let rowIndex = 0; rowIndex < safeRows; rowIndex += 1) {
2125
- const cells = [];
2126
- for (let columnIndex = 0; columnIndex < safeColumns; columnIndex += 1) {
2127
- cells.push({
2128
- type: "table_cell",
2129
- children: [createEmptyParagraph2()]
2130
- });
2131
- }
2132
- nextRows.push({
2133
- type: "table_row",
2134
- cells
2135
- });
2136
- }
2137
- return {
2138
- type: "table",
2139
- ...styleId ? { styleId } : {},
2140
- gridColumns: Array.from({ length: safeColumns }, () => DEFAULT_TABLE_COLUMN_WIDTH),
2141
- rows: nextRows
2142
- };
2143
- }
2144
- function resolveInsertedTableStyleId(document) {
2145
- const styles = document.styles?.tables;
2146
- if (!styles || typeof styles !== "object") {
2147
- return void 0;
2148
- }
2149
- return "TableGrid" in styles ? "TableGrid" : void 0;
2150
- }
2151
- function findTableCellParagraphSelection(document, tableBlockIndex, rowIndex, cellIndex) {
2152
- const surface = createEditorSurfaceSnapshot(document, createSelectionSnapshot(0, 0));
2153
- const tableBlock = surface.blocks[tableBlockIndex];
2154
- if (!tableBlock || tableBlock.kind !== "table") {
2155
- return null;
2156
- }
2157
- const paragraph = tableBlock.rows[rowIndex]?.cells[cellIndex]?.content.find(
2158
- (block) => block.kind === "paragraph"
2159
- );
2160
- if (!paragraph || paragraph.kind !== "paragraph") {
2161
- return null;
2162
- }
2163
- return createSelectionSnapshot(paragraph.from, paragraph.from);
2164
- }
2165
- function asDocumentRoot(document) {
2166
- const root = document.content;
2167
- if (!root || root.type !== "doc" || !Array.isArray(root.children)) {
2168
- return null;
2169
- }
2170
- return root;
2171
- }
2172
- function selectionWithinRange(selectionFrom, selectionTo, rangeFrom, rangeTo) {
2173
- return selectionFrom >= rangeFrom && selectionTo <= rangeTo;
2174
- }
2175
- function cloneParagraph(paragraph) {
2176
- return structuredClone(paragraph);
2177
- }
2178
-
2179
- // src/core/commands/text-commands.ts
2180
- function insertText(document, selection, text, context) {
2181
- return applyTextTransaction(
2182
- document,
2183
- selection,
2184
- {
2185
- type: "replace",
2186
- insertion: [
2187
- {
2188
- type: "text",
2189
- text
2190
- }
2191
- ]
2192
- },
2193
- context
2194
- );
2195
- }
2196
- function deleteSelectionOrBackward(document, selection, context) {
2197
- return applyTextTransaction(
2198
- document,
2199
- selection,
2200
- selection.isCollapsed ? {
2201
- type: "delete_backward"
2202
- } : {
2203
- type: "replace",
2204
- insertion: []
2205
- },
2206
- context
2207
- );
2208
- }
2209
- function deleteSelectionOrForward(document, selection, context) {
2210
- return applyTextTransaction(
2211
- document,
2212
- selection,
2213
- selection.isCollapsed ? {
2214
- type: "delete_forward"
2215
- } : {
2216
- type: "replace",
2217
- insertion: []
2218
- },
2219
- context
2220
- );
2221
- }
2222
- function insertTab(document, selection, context) {
2223
- return applyTextTransaction(
2224
- document,
2225
- selection,
2226
- {
2227
- type: "replace",
2228
- insertion: [{ type: "tab" }]
2229
- },
2230
- context
2231
- );
2232
- }
2233
- function insertHardBreak(document, selection, context) {
2234
- return applyTextTransaction(
2235
- document,
2236
- selection,
2237
- {
2238
- type: "replace",
2239
- insertion: [{ type: "hard_break" }]
2240
- },
2241
- context
2242
- );
2243
- }
2244
- function splitParagraph(document, selection, context) {
2245
- return applyTextTransaction(
2246
- document,
2247
- selection,
2248
- {
2249
- type: "replace",
2250
- insertion: [{ type: "paragraph_break" }]
2251
- },
2252
- context
2253
- );
2254
- }
2255
- function insertPageBreak(document, selection, context) {
2256
- const scope = resolveParagraphScope(document, selection);
2257
- if (!scope) {
2258
- return createNoopStructuralMutation(document, selection);
2259
- }
2260
- const localDocument = {
2261
- ...document,
2262
- content: {
2263
- type: "doc",
2264
- children: [scope.paragraph]
2265
- }
2266
- };
2267
- const localSelection = createSelectionSnapshot(
2268
- selection.anchor - scope.paragraphStart,
2269
- selection.head - scope.paragraphStart
2270
- );
2271
- const splitResult = splitParagraph(localDocument, localSelection, context);
2272
- const splitRoot = splitResult.document.content;
2273
- if (!splitRoot || splitRoot.type !== "doc") {
2274
- return createNoopStructuralMutation(document, selection);
2275
- }
2276
- const replacementParagraphs = splitRoot.children.filter((block) => block.type === "paragraph").map(
2277
- (block, index) => index === 1 ? {
2278
- ...block,
2279
- pageBreakBefore: true
2280
- } : block
2281
- );
2282
- if (replacementParagraphs.length < 2) {
2283
- return createNoopStructuralMutation(document, selection);
2284
- }
2285
- const nextDocument = replaceParagraphScope(document, scope, replacementParagraphs);
2286
- return {
2287
- changed: true,
2288
- document: {
2289
- ...nextDocument,
2290
- updatedAt: context.timestamp
2291
- },
2292
- selection: createSelectionSnapshot(
2293
- splitResult.selection.anchor + scope.paragraphStart,
2294
- splitResult.selection.head + scope.paragraphStart
2295
- ),
2296
- mapping: {
2297
- ...splitResult.mapping,
2298
- steps: splitResult.mapping.steps.map((step) => ({
2299
- ...step,
2300
- from: step.from + scope.paragraphStart,
2301
- to: step.to + scope.paragraphStart
2302
- }))
2303
- }
2304
- };
2305
- }
2306
- function insertTable(document, selection, options, context) {
2307
- const scope = resolveParagraphScope(document, selection);
2308
- if (!scope || scope.kind !== "top-level") {
2309
- return createNoopStructuralMutation(document, selection);
2310
- }
2311
- const safeRows = Math.max(1, Math.floor(options.rows));
2312
- const safeColumns = Math.max(1, Math.floor(options.columns));
2313
- if (!Number.isFinite(safeRows) || !Number.isFinite(safeColumns)) {
2314
- return createNoopStructuralMutation(document, selection);
2315
- }
2316
- const localDocument = {
2317
- ...document,
2318
- content: {
2319
- type: "doc",
2320
- children: [scope.paragraph]
2321
- }
2322
- };
2323
- const localSelection = createSelectionSnapshot(
2324
- selection.anchor - scope.paragraphStart,
2325
- selection.head - scope.paragraphStart
2326
- );
2327
- const splitResult = splitParagraph(localDocument, localSelection, context);
2328
- const splitRoot = splitResult.document.content;
2329
- if (!splitRoot || splitRoot.type !== "doc") {
2330
- return createNoopStructuralMutation(document, selection);
2331
- }
2332
- const replacementParagraphs = splitRoot.children.filter(
2333
- (block) => block.type === "paragraph"
2334
- );
2335
- if (replacementParagraphs.length < 2) {
2336
- return createNoopStructuralMutation(document, selection);
2337
- }
2338
- const nextRoot = document.content;
2339
- if (!nextRoot || nextRoot.type !== "doc") {
2340
- return createNoopStructuralMutation(document, selection);
2341
- }
2342
- const insertedTable = createInsertedTableBlock(
2343
- safeRows,
2344
- safeColumns,
2345
- resolveInsertedTableStyleId(document)
2346
- );
2347
- const nextDocument = {
2348
- ...document,
2349
- updatedAt: context.timestamp,
2350
- content: {
2351
- ...nextRoot,
2352
- children: [
2353
- ...nextRoot.children.slice(0, scope.blockIndex),
2354
- replacementParagraphs[0],
2355
- insertedTable,
2356
- replacementParagraphs[1],
2357
- ...nextRoot.children.slice(scope.blockIndex + 1)
2358
- ]
2359
- }
2360
- };
2361
- return {
2362
- changed: true,
2363
- document: nextDocument,
2364
- selection: findTableCellParagraphSelection(
2365
- nextDocument,
2366
- scope.blockIndex + 1,
2367
- 0,
2368
- 0
2369
- ) ?? selection,
2370
- mapping: {
2371
- ...splitResult.mapping,
2372
- steps: splitResult.mapping.steps.map((step) => ({
2373
- ...step,
2374
- from: step.from + scope.paragraphStart,
2375
- to: step.to + scope.paragraphStart
2376
- }))
2377
- }
2378
- };
2379
- }
2380
- // Annotate the CommonJS export names for ESM import in node:
2381
- 0 && (module.exports = {
2382
- deleteSelectionOrBackward,
2383
- deleteSelectionOrForward,
2384
- insertHardBreak,
2385
- insertPageBreak,
2386
- insertTab,
2387
- insertTable,
2388
- insertText,
2389
- splitParagraph
2390
- });
2391
- //# sourceMappingURL=text-commands.cjs.map