@beyondwork/docx-react-component 1.0.27 → 1.0.29

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 (356) hide show
  1. package/dist/canonical-document-BLEbzL2J.d.cts +844 -0
  2. package/dist/canonical-document-BLEbzL2J.d.ts +844 -0
  3. package/dist/chunk-2FJS5GZM.js +763 -0
  4. package/dist/chunk-2FJS5GZM.js.map +1 -0
  5. package/{src/core/commands/section-layout-commands.ts → dist/chunk-2OQBZS3F.js} +106 -340
  6. package/dist/chunk-2OQBZS3F.js.map +1 -0
  7. package/dist/chunk-2S7W4KFO.js +127 -0
  8. package/dist/chunk-2S7W4KFO.js.map +1 -0
  9. package/dist/chunk-2TG72QSW.js +3874 -0
  10. package/dist/chunk-2TG72QSW.js.map +1 -0
  11. package/{src/core/commands/table-structure-commands.ts → dist/chunk-36QNIZBO.js} +126 -315
  12. package/dist/chunk-36QNIZBO.js.map +1 -0
  13. package/dist/chunk-4AQOYAW4.js +3069 -0
  14. package/dist/chunk-4AQOYAW4.js.map +1 -0
  15. package/dist/chunk-4D5EWJ3P.js +77 -0
  16. package/dist/chunk-4D5EWJ3P.js.map +1 -0
  17. package/dist/chunk-5FN54NDH.js +2257 -0
  18. package/dist/chunk-5FN54NDH.js.map +1 -0
  19. package/dist/chunk-BOYGQYRQ.js +7306 -0
  20. package/dist/chunk-BOYGQYRQ.js.map +1 -0
  21. package/dist/chunk-CN3XMECL.js +212 -0
  22. package/dist/chunk-CN3XMECL.js.map +1 -0
  23. package/dist/chunk-EBI3BX6U.js +164 -0
  24. package/dist/chunk-EBI3BX6U.js.map +1 -0
  25. package/dist/chunk-EILUG3VB.js +1275 -0
  26. package/dist/chunk-EILUG3VB.js.map +1 -0
  27. package/dist/chunk-FUDY333O.js +70 -0
  28. package/dist/chunk-FUDY333O.js.map +1 -0
  29. package/dist/chunk-GBVOWFIK.js +1237 -0
  30. package/dist/chunk-GBVOWFIK.js.map +1 -0
  31. package/dist/chunk-H4TQ3H3Y.js +262 -0
  32. package/dist/chunk-H4TQ3H3Y.js.map +1 -0
  33. package/{src/core/commands/style-commands.ts → dist/chunk-JGB3IXZO.js} +40 -113
  34. package/dist/chunk-JGB3IXZO.js.map +1 -0
  35. package/dist/chunk-KD2QRQPY.js +4342 -0
  36. package/dist/chunk-KD2QRQPY.js.map +1 -0
  37. package/dist/chunk-KLMXQVYK.js +369 -0
  38. package/dist/chunk-KLMXQVYK.js.map +1 -0
  39. package/dist/chunk-KZUG5KFQ.js +214 -0
  40. package/dist/chunk-KZUG5KFQ.js.map +1 -0
  41. package/{src/core/state/text-transaction.ts → dist/chunk-QDAQ4CJU.js} +79 -236
  42. package/dist/chunk-QDAQ4CJU.js.map +1 -0
  43. package/{src/legal/bookmarks.ts → dist/chunk-RMH72RZI.js} +44 -130
  44. package/dist/chunk-RMH72RZI.js.map +1 -0
  45. package/dist/chunk-SWKWQZXM.js +117 -0
  46. package/dist/chunk-SWKWQZXM.js.map +1 -0
  47. package/{src/core/commands/formatting-commands.ts → dist/chunk-TJBP2K4T.js} +196 -536
  48. package/dist/chunk-TJBP2K4T.js.map +1 -0
  49. package/dist/chunk-TLCEAQDQ.js +542 -0
  50. package/dist/chunk-TLCEAQDQ.js.map +1 -0
  51. package/{src/core/commands/text-commands.ts → dist/chunk-UZXBISGO.js} +86 -142
  52. package/dist/chunk-UZXBISGO.js.map +1 -0
  53. package/dist/chunk-WGBAKP3Q.js +3220 -0
  54. package/dist/chunk-WGBAKP3Q.js.map +1 -0
  55. package/dist/compare/index.cjs +5475 -0
  56. package/dist/compare/index.cjs.map +1 -0
  57. package/dist/compare/index.d.cts +114 -0
  58. package/dist/compare/index.d.ts +114 -0
  59. package/dist/compare/index.js +731 -0
  60. package/dist/compare/index.js.map +1 -0
  61. package/dist/core/commands/formatting-commands.cjs +828 -0
  62. package/dist/core/commands/formatting-commands.cjs.map +1 -0
  63. package/dist/core/commands/formatting-commands.d.cts +63 -0
  64. package/dist/core/commands/formatting-commands.d.ts +63 -0
  65. package/dist/core/commands/formatting-commands.js +37 -0
  66. package/dist/core/commands/formatting-commands.js.map +1 -0
  67. package/dist/core/commands/image-commands.cjs +2023 -0
  68. package/dist/core/commands/image-commands.cjs.map +1 -0
  69. package/dist/core/commands/image-commands.d.cts +58 -0
  70. package/dist/core/commands/image-commands.d.ts +58 -0
  71. package/dist/core/commands/image-commands.js +18 -0
  72. package/dist/core/commands/image-commands.js.map +1 -0
  73. package/dist/core/commands/section-layout-commands.cjs +477 -0
  74. package/dist/core/commands/section-layout-commands.cjs.map +1 -0
  75. package/dist/core/commands/section-layout-commands.d.cts +62 -0
  76. package/dist/core/commands/section-layout-commands.d.ts +62 -0
  77. package/dist/core/commands/section-layout-commands.js +21 -0
  78. package/dist/core/commands/section-layout-commands.js.map +1 -0
  79. package/dist/core/commands/style-commands.cjs +214 -0
  80. package/dist/core/commands/style-commands.cjs.map +1 -0
  81. package/dist/core/commands/style-commands.d.cts +13 -0
  82. package/dist/core/commands/style-commands.d.ts +13 -0
  83. package/dist/core/commands/style-commands.js +9 -0
  84. package/dist/core/commands/style-commands.js.map +1 -0
  85. package/dist/core/commands/table-structure-commands.cjs +1883 -0
  86. package/dist/core/commands/table-structure-commands.cjs.map +1 -0
  87. package/dist/core/commands/table-structure-commands.d.cts +59 -0
  88. package/dist/core/commands/table-structure-commands.d.ts +59 -0
  89. package/dist/core/commands/table-structure-commands.js +12 -0
  90. package/dist/core/commands/table-structure-commands.js.map +1 -0
  91. package/dist/core/commands/text-commands.cjs +2391 -0
  92. package/dist/core/commands/text-commands.cjs.map +1 -0
  93. package/dist/core/commands/text-commands.d.cts +24 -0
  94. package/dist/core/commands/text-commands.d.ts +24 -0
  95. package/dist/core/commands/text-commands.js +28 -0
  96. package/dist/core/commands/text-commands.js.map +1 -0
  97. package/dist/core/selection/mapping.cjs +200 -0
  98. package/dist/core/selection/mapping.cjs.map +1 -0
  99. package/dist/core/selection/mapping.d.cts +2 -0
  100. package/dist/core/selection/mapping.d.ts +2 -0
  101. package/dist/core/selection/mapping.js +31 -0
  102. package/dist/core/selection/mapping.js.map +1 -0
  103. package/dist/core/state/editor-state.cjs +2278 -0
  104. package/dist/core/state/editor-state.cjs.map +1 -0
  105. package/dist/core/state/editor-state.d.cts +2 -0
  106. package/dist/core/state/editor-state.d.ts +2 -0
  107. package/dist/core/state/editor-state.js +26 -0
  108. package/dist/core/state/editor-state.js.map +1 -0
  109. package/dist/index.cjs +38553 -0
  110. package/dist/index.cjs.map +1 -0
  111. package/dist/index.d.cts +15 -0
  112. package/dist/index.d.ts +15 -0
  113. package/dist/index.js +7856 -0
  114. package/dist/index.js.map +1 -0
  115. package/dist/io/docx-session.cjs +16236 -0
  116. package/dist/io/docx-session.cjs.map +1 -0
  117. package/dist/io/docx-session.d.cts +21 -0
  118. package/dist/io/docx-session.d.ts +21 -0
  119. package/dist/io/docx-session.js +18 -0
  120. package/dist/io/docx-session.js.map +1 -0
  121. package/dist/legal/index.cjs +3900 -0
  122. package/dist/legal/index.cjs.map +1 -0
  123. package/dist/legal/index.d.cts +86 -0
  124. package/dist/legal/index.d.ts +86 -0
  125. package/dist/legal/index.js +616 -0
  126. package/dist/legal/index.js.map +1 -0
  127. package/dist/public-types-7ZL_94cz.d.ts +1573 -0
  128. package/dist/public-types-CeMaDueh.d.cts +1573 -0
  129. package/dist/public-types.cjs +19 -0
  130. package/dist/public-types.cjs.map +1 -0
  131. package/dist/public-types.d.cts +2 -0
  132. package/dist/public-types.d.ts +2 -0
  133. package/dist/public-types.js +1 -0
  134. package/dist/public-types.js.map +1 -0
  135. package/dist/runtime/document-runtime.cjs +11140 -0
  136. package/dist/runtime/document-runtime.cjs.map +1 -0
  137. package/dist/runtime/document-runtime.d.cts +231 -0
  138. package/dist/runtime/document-runtime.d.ts +231 -0
  139. package/dist/runtime/document-runtime.js +21 -0
  140. package/dist/runtime/document-runtime.js.map +1 -0
  141. package/dist/structural-helpers-CilgOVhh.d.cts +10 -0
  142. package/dist/structural-helpers-q0Gd-eBN.d.ts +10 -0
  143. package/dist/ui-tailwind/editor-surface/search-plugin.cjs +313 -0
  144. package/dist/ui-tailwind/editor-surface/search-plugin.cjs.map +1 -0
  145. package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +67 -0
  146. package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +67 -0
  147. package/dist/ui-tailwind/editor-surface/search-plugin.js +23 -0
  148. package/dist/ui-tailwind/editor-surface/search-plugin.js.map +1 -0
  149. package/dist/ui-tailwind/index.cjs +4833 -0
  150. package/dist/ui-tailwind/index.cjs.map +1 -0
  151. package/dist/ui-tailwind/index.d.cts +617 -0
  152. package/dist/ui-tailwind/index.d.ts +617 -0
  153. package/dist/ui-tailwind/index.js +575 -0
  154. package/dist/ui-tailwind/index.js.map +1 -0
  155. package/package.json +64 -54
  156. package/src/README.md +0 -85
  157. package/src/api/README.md +0 -26
  158. package/src/api/public-types.ts +0 -1418
  159. package/src/api/session-state.ts +0 -60
  160. package/src/compare/diff-engine.ts +0 -623
  161. package/src/compare/export-redlines.ts +0 -280
  162. package/src/compare/index.ts +0 -25
  163. package/src/compare/snapshot.ts +0 -97
  164. package/src/component-inventory.md +0 -99
  165. package/src/core/README.md +0 -10
  166. package/src/core/commands/README.md +0 -3
  167. package/src/core/commands/image-commands.ts +0 -373
  168. package/src/core/commands/index.ts +0 -1757
  169. package/src/core/commands/list-commands.ts +0 -565
  170. package/src/core/commands/paragraph-layout-commands.ts +0 -339
  171. package/src/core/commands/review-commands.ts +0 -108
  172. package/src/core/commands/structural-helpers.ts +0 -309
  173. package/src/core/schema/README.md +0 -3
  174. package/src/core/schema/text-schema.ts +0 -516
  175. package/src/core/search/search-text.ts +0 -357
  176. package/src/core/selection/README.md +0 -3
  177. package/src/core/selection/mapping.ts +0 -289
  178. package/src/core/selection/review-anchors.ts +0 -183
  179. package/src/core/state/README.md +0 -3
  180. package/src/core/state/editor-state.ts +0 -892
  181. package/src/formats/xlsx/io/parse-shared-strings.ts +0 -41
  182. package/src/formats/xlsx/io/parse-sheet.ts +0 -459
  183. package/src/formats/xlsx/io/parse-styles.ts +0 -59
  184. package/src/formats/xlsx/io/parse-workbook.ts +0 -75
  185. package/src/formats/xlsx/io/serialize-shared-strings.ts +0 -72
  186. package/src/formats/xlsx/io/serialize-sheet.ts +0 -333
  187. package/src/formats/xlsx/io/serialize-styles.ts +0 -98
  188. package/src/formats/xlsx/io/serialize-workbook.ts +0 -429
  189. package/src/formats/xlsx/io/xlsx-session.ts +0 -314
  190. package/src/formats/xlsx/model/cell.ts +0 -189
  191. package/src/formats/xlsx/model/sheet.ts +0 -326
  192. package/src/formats/xlsx/model/styles.ts +0 -118
  193. package/src/formats/xlsx/model/workbook.ts +0 -453
  194. package/src/formats/xlsx/runtime/cell-commands.ts +0 -567
  195. package/src/formats/xlsx/runtime/sheet-commands.ts +0 -206
  196. package/src/formats/xlsx/runtime/workbook-runtime.ts +0 -177
  197. package/src/formats/xlsx/runtime/workbook-transaction.ts +0 -822
  198. package/src/index.ts +0 -101
  199. package/src/io/README.md +0 -10
  200. package/src/io/docx-session.ts +0 -2882
  201. package/src/io/export/README.md +0 -3
  202. package/src/io/export/export-session.ts +0 -220
  203. package/src/io/export/minimal-docx.ts +0 -115
  204. package/src/io/export/reattach-preserved-parts.ts +0 -54
  205. package/src/io/export/serialize-comments.ts +0 -947
  206. package/src/io/export/serialize-footnotes.ts +0 -399
  207. package/src/io/export/serialize-headers-footers.ts +0 -372
  208. package/src/io/export/serialize-main-document.ts +0 -1376
  209. package/src/io/export/serialize-numbering.ts +0 -118
  210. package/src/io/export/serialize-revisions.ts +0 -389
  211. package/src/io/export/serialize-runtime-revisions.ts +0 -269
  212. package/src/io/export/serialize-tables.ts +0 -174
  213. package/src/io/export/split-review-boundaries.ts +0 -356
  214. package/src/io/normalize/README.md +0 -3
  215. package/src/io/normalize/normalize-text.ts +0 -639
  216. package/src/io/ooxml/README.md +0 -3
  217. package/src/io/ooxml/highlight-colors.ts +0 -39
  218. package/src/io/ooxml/numbering-sentinels.ts +0 -44
  219. package/src/io/ooxml/parse-comments.ts +0 -846
  220. package/src/io/ooxml/parse-complex-content.ts +0 -287
  221. package/src/io/ooxml/parse-fields.ts +0 -834
  222. package/src/io/ooxml/parse-footnotes.ts +0 -896
  223. package/src/io/ooxml/parse-headers-footers.ts +0 -1169
  224. package/src/io/ooxml/parse-inline-media.ts +0 -461
  225. package/src/io/ooxml/parse-main-document.ts +0 -2877
  226. package/src/io/ooxml/parse-numbering.ts +0 -432
  227. package/src/io/ooxml/parse-revisions.ts +0 -931
  228. package/src/io/ooxml/parse-settings.ts +0 -184
  229. package/src/io/ooxml/parse-shapes.ts +0 -296
  230. package/src/io/ooxml/parse-styles.ts +0 -463
  231. package/src/io/ooxml/parse-tables.ts +0 -618
  232. package/src/io/ooxml/parse-theme.ts +0 -346
  233. package/src/io/ooxml/part-manifest.ts +0 -136
  234. package/src/io/ooxml/revision-boundaries.ts +0 -351
  235. package/src/io/opc/README.md +0 -3
  236. package/src/io/opc/corrupt-package.ts +0 -166
  237. package/src/io/opc/docx-package.ts +0 -74
  238. package/src/io/opc/package-reader.ts +0 -325
  239. package/src/io/opc/package-writer.ts +0 -273
  240. package/src/io/source-package-provenance.ts +0 -241
  241. package/src/legal/cross-references.ts +0 -414
  242. package/src/legal/defined-terms.ts +0 -203
  243. package/src/legal/index.ts +0 -32
  244. package/src/legal/signature-blocks.ts +0 -259
  245. package/src/model/README.md +0 -3
  246. package/src/model/canonical-document.ts +0 -2632
  247. package/src/model/cds-1.0.0.ts +0 -212
  248. package/src/model/snapshot.ts +0 -649
  249. package/src/preservation/README.md +0 -3
  250. package/src/preservation/markup-compatibility.ts +0 -48
  251. package/src/preservation/opaque-fragment-store.ts +0 -89
  252. package/src/preservation/opaque-region.ts +0 -233
  253. package/src/preservation/package-preservation.ts +0 -113
  254. package/src/preservation/preserved-part-manifest.ts +0 -56
  255. package/src/preservation/relationship-retention.ts +0 -57
  256. package/src/preservation/store.ts +0 -185
  257. package/src/review/README.md +0 -16
  258. package/src/review/store/README.md +0 -3
  259. package/src/review/store/comment-anchors.ts +0 -70
  260. package/src/review/store/comment-remapping.ts +0 -154
  261. package/src/review/store/comment-store.ts +0 -331
  262. package/src/review/store/comment-thread.ts +0 -109
  263. package/src/review/store/revision-actions.ts +0 -394
  264. package/src/review/store/revision-store.ts +0 -312
  265. package/src/review/store/revision-types.ts +0 -171
  266. package/src/review/store/runtime-comment-store.ts +0 -43
  267. package/src/runtime/README.md +0 -3
  268. package/src/runtime/ai-action-policy.ts +0 -764
  269. package/src/runtime/collab-review-sync.ts +0 -254
  270. package/src/runtime/document-layout.ts +0 -332
  271. package/src/runtime/document-navigation.ts +0 -603
  272. package/src/runtime/document-runtime.ts +0 -3159
  273. package/src/runtime/document-search.ts +0 -145
  274. package/src/runtime/numbering-prefix.ts +0 -216
  275. package/src/runtime/page-layout-estimation.ts +0 -212
  276. package/src/runtime/read-only-diagnostics-runtime.ts +0 -241
  277. package/src/runtime/review-runtime.ts +0 -44
  278. package/src/runtime/revision-runtime.ts +0 -107
  279. package/src/runtime/session-capabilities.ts +0 -192
  280. package/src/runtime/story-context.ts +0 -164
  281. package/src/runtime/story-targeting.ts +0 -162
  282. package/src/runtime/surface-projection.ts +0 -1357
  283. package/src/runtime/table-commands.ts +0 -173
  284. package/src/runtime/table-schema.ts +0 -309
  285. package/src/runtime/view-state.ts +0 -477
  286. package/src/runtime/virtualized-rendering.ts +0 -258
  287. package/src/runtime/workflow-markup.ts +0 -353
  288. package/src/ui/README.md +0 -30
  289. package/src/ui/WordReviewEditor.tsx +0 -4097
  290. package/src/ui/browser-export.ts +0 -52
  291. package/src/ui/comments/README.md +0 -3
  292. package/src/ui/compatibility/README.md +0 -3
  293. package/src/ui/editor-command-bag.ts +0 -120
  294. package/src/ui/editor-runtime-boundary.ts +0 -1457
  295. package/src/ui/editor-shell-view.tsx +0 -142
  296. package/src/ui/editor-surface/README.md +0 -3
  297. package/src/ui/editor-surface-controller.tsx +0 -63
  298. package/src/ui/headless/comment-decoration-model.ts +0 -124
  299. package/src/ui/headless/preserve-editor-selection.ts +0 -5
  300. package/src/ui/headless/revision-decoration-model.ts +0 -128
  301. package/src/ui/headless/selection-helpers.ts +0 -54
  302. package/src/ui/headless/selection-toolbar-model.ts +0 -34
  303. package/src/ui/headless/use-editor-keyboard.ts +0 -103
  304. package/src/ui/review/README.md +0 -3
  305. package/src/ui/runtime-snapshot-selectors.ts +0 -197
  306. package/src/ui/shared/revision-filters.ts +0 -31
  307. package/src/ui/status/README.md +0 -3
  308. package/src/ui/theme/README.md +0 -3
  309. package/src/ui/toolbar/README.md +0 -3
  310. package/src/ui/workflow-surface-blocked-rails.ts +0 -94
  311. package/src/ui-tailwind/chrome/tw-alert-banner.tsx +0 -64
  312. package/src/ui-tailwind/chrome/tw-image-context-toolbar.tsx +0 -129
  313. package/src/ui-tailwind/chrome/tw-layout-panel.tsx +0 -114
  314. package/src/ui-tailwind/chrome/tw-object-context-toolbar.tsx +0 -34
  315. package/src/ui-tailwind/chrome/tw-page-ruler.tsx +0 -386
  316. package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +0 -186
  317. package/src/ui-tailwind/chrome/tw-suggestion-card.tsx +0 -139
  318. package/src/ui-tailwind/chrome/tw-table-context-toolbar.tsx +0 -128
  319. package/src/ui-tailwind/chrome/tw-unsaved-modal.tsx +0 -58
  320. package/src/ui-tailwind/chrome/use-before-unload.ts +0 -20
  321. package/src/ui-tailwind/editor-surface/perf-probe.ts +0 -179
  322. package/src/ui-tailwind/editor-surface/pm-collab-plugins.ts +0 -40
  323. package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +0 -178
  324. package/src/ui-tailwind/editor-surface/pm-contextual-ui.ts +0 -31
  325. package/src/ui-tailwind/editor-surface/pm-decorations.ts +0 -427
  326. package/src/ui-tailwind/editor-surface/pm-position-map.ts +0 -123
  327. package/src/ui-tailwind/editor-surface/pm-schema.ts +0 -876
  328. package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +0 -504
  329. package/src/ui-tailwind/editor-surface/search-plugin.ts +0 -168
  330. package/src/ui-tailwind/editor-surface/surface-build-keys.ts +0 -61
  331. package/src/ui-tailwind/editor-surface/tw-caret.tsx +0 -12
  332. package/src/ui-tailwind/editor-surface/tw-editor-surface.tsx +0 -150
  333. package/src/ui-tailwind/editor-surface/tw-inline-token.tsx +0 -129
  334. package/src/ui-tailwind/editor-surface/tw-opaque-block.tsx +0 -58
  335. package/src/ui-tailwind/editor-surface/tw-paragraph-block.tsx +0 -151
  336. package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +0 -973
  337. package/src/ui-tailwind/editor-surface/tw-segment-view.tsx +0 -111
  338. package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +0 -436
  339. package/src/ui-tailwind/index.ts +0 -62
  340. package/src/ui-tailwind/page-chrome-model.ts +0 -27
  341. package/src/ui-tailwind/review/tw-comment-sidebar.tsx +0 -406
  342. package/src/ui-tailwind/review/tw-health-panel.tsx +0 -149
  343. package/src/ui-tailwind/review/tw-review-rail.tsx +0 -120
  344. package/src/ui-tailwind/review/tw-revision-sidebar.tsx +0 -164
  345. package/src/ui-tailwind/status/tw-status-bar.tsx +0 -61
  346. package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +0 -52
  347. package/src/ui-tailwind/toolbar/tw-toolbar.tsx +0 -1064
  348. package/src/ui-tailwind/tw-review-workspace.tsx +0 -1417
  349. package/src/validation/README.md +0 -3
  350. package/src/validation/compatibility-engine.ts +0 -634
  351. package/src/validation/compatibility-report.ts +0 -161
  352. package/src/validation/diagnostics.ts +0 -204
  353. package/src/validation/docx-comment-proof.ts +0 -707
  354. package/src/validation/import-diagnostics.ts +0 -128
  355. package/src/validation/low-priority-word-surfaces.ts +0 -373
  356. /package/{src → dist}/ui-tailwind/theme/editor-theme.css +0 -0
@@ -0,0 +1,369 @@
1
+ // src/core/schema/text-schema.ts
2
+ function parseTextStory(content) {
3
+ const root = normalizeDocumentRoot(content);
4
+ const firstParagraphNode = root.children.find(isParagraphNode);
5
+ const firstParagraph = firstParagraphNode ? extractParagraphProperties(firstParagraphNode) : cloneParagraphProperties(EMPTY_PARAGRAPH_PROPERTIES);
6
+ const units = [];
7
+ for (let index = 0; index < root.children.length; index += 1) {
8
+ const block = root.children[index];
9
+ const nextBlock = root.children[index + 1];
10
+ if (isParagraphNode(block)) {
11
+ units.push(...flattenInlineNodes(block.children));
12
+ if (isParagraphNode(nextBlock)) {
13
+ units.push({
14
+ kind: "paragraph_break",
15
+ nextParagraph: extractParagraphProperties(nextBlock)
16
+ });
17
+ }
18
+ continue;
19
+ }
20
+ if (block.type !== "opaque_block") {
21
+ continue;
22
+ }
23
+ units.push({
24
+ kind: "opaque_block",
25
+ fragmentId: block.fragmentId,
26
+ warningId: block.warningId,
27
+ ...isParagraphNode(nextBlock) ? { nextParagraph: extractParagraphProperties(nextBlock) } : {}
28
+ });
29
+ }
30
+ return {
31
+ firstParagraph,
32
+ units,
33
+ size: units.length
34
+ };
35
+ }
36
+ function serializeTextStory(story) {
37
+ const blocks = [];
38
+ let currentParagraph = createParagraph(story.firstParagraph);
39
+ let currentHyperlink;
40
+ let activeTextBuffer;
41
+ const ensureCurrentParagraph = () => {
42
+ if (!currentParagraph) {
43
+ currentParagraph = createParagraph(EMPTY_PARAGRAPH_PROPERTIES);
44
+ }
45
+ };
46
+ const flushTextBuffer = () => {
47
+ if (!activeTextBuffer || activeTextBuffer.text.length === 0) {
48
+ activeTextBuffer = void 0;
49
+ return;
50
+ }
51
+ const textNode = {
52
+ type: "text",
53
+ text: activeTextBuffer.text,
54
+ ...activeTextBuffer.marks ? { marks: cloneMarks(activeTextBuffer.marks) } : {}
55
+ };
56
+ ensureCurrentParagraph();
57
+ if (activeTextBuffer.hyperlinkHref) {
58
+ if (!currentHyperlink || currentHyperlink.href !== activeTextBuffer.hyperlinkHref) {
59
+ flushHyperlink();
60
+ currentHyperlink = {
61
+ type: "hyperlink",
62
+ href: activeTextBuffer.hyperlinkHref,
63
+ children: []
64
+ };
65
+ }
66
+ currentHyperlink.children.push(textNode);
67
+ } else {
68
+ flushHyperlink();
69
+ currentParagraph.children.push(textNode);
70
+ }
71
+ activeTextBuffer = void 0;
72
+ };
73
+ const flushHyperlink = () => {
74
+ if (currentHyperlink) {
75
+ ensureCurrentParagraph();
76
+ currentParagraph.children.push(currentHyperlink);
77
+ currentHyperlink = void 0;
78
+ }
79
+ };
80
+ const flushParagraph = () => {
81
+ flushTextBuffer();
82
+ flushHyperlink();
83
+ if (!currentParagraph) {
84
+ return;
85
+ }
86
+ blocks.push(currentParagraph);
87
+ currentParagraph = void 0;
88
+ };
89
+ const pushInlineNode = (node, hyperlinkHref) => {
90
+ flushTextBuffer();
91
+ ensureCurrentParagraph();
92
+ if (hyperlinkHref) {
93
+ if (!currentHyperlink || currentHyperlink.href !== hyperlinkHref) {
94
+ flushHyperlink();
95
+ currentHyperlink = {
96
+ type: "hyperlink",
97
+ href: hyperlinkHref,
98
+ children: []
99
+ };
100
+ }
101
+ currentHyperlink.children.push(node);
102
+ return;
103
+ }
104
+ flushHyperlink();
105
+ currentParagraph.children.push(node);
106
+ };
107
+ for (const unit of story.units) {
108
+ if (unit.kind === "paragraph_break") {
109
+ flushParagraph();
110
+ currentParagraph = createParagraph(unit.nextParagraph);
111
+ continue;
112
+ }
113
+ if (unit.kind === "opaque_block") {
114
+ flushParagraph();
115
+ blocks.push({
116
+ type: "opaque_block",
117
+ fragmentId: unit.fragmentId,
118
+ warningId: unit.warningId
119
+ });
120
+ currentParagraph = unit.nextParagraph ? createParagraph(unit.nextParagraph) : void 0;
121
+ continue;
122
+ }
123
+ if (unit.kind === "text") {
124
+ const shouldExtendBuffer = activeTextBuffer && activeTextBuffer.hyperlinkHref === unit.hyperlinkHref && haveEqualMarks(activeTextBuffer.marks, unit.marks);
125
+ if (shouldExtendBuffer && activeTextBuffer) {
126
+ activeTextBuffer.text += unit.value;
127
+ } else {
128
+ flushTextBuffer();
129
+ activeTextBuffer = {
130
+ text: unit.value,
131
+ ...unit.marks ? { marks: cloneMarks(unit.marks) } : {},
132
+ ...unit.hyperlinkHref ? { hyperlinkHref: unit.hyperlinkHref } : {}
133
+ };
134
+ }
135
+ continue;
136
+ }
137
+ switch (unit.kind) {
138
+ case "tab":
139
+ pushInlineNode({ type: "tab" }, unit.hyperlinkHref);
140
+ break;
141
+ case "hard_break":
142
+ pushInlineNode({ type: "hard_break" }, unit.hyperlinkHref);
143
+ break;
144
+ case "image":
145
+ pushInlineNode({
146
+ type: "image",
147
+ mediaId: unit.mediaId,
148
+ ...unit.altText ? { altText: unit.altText } : {}
149
+ });
150
+ break;
151
+ case "opaque_inline":
152
+ pushInlineNode({
153
+ type: "opaque_inline",
154
+ fragmentId: unit.fragmentId,
155
+ warningId: unit.warningId
156
+ });
157
+ break;
158
+ }
159
+ }
160
+ flushParagraph();
161
+ if (blocks.length === 0) {
162
+ blocks.push(createParagraph(story.firstParagraph));
163
+ }
164
+ return {
165
+ type: "doc",
166
+ children: blocks
167
+ };
168
+ }
169
+ function createPlainText(story) {
170
+ return story.units.map((unit) => {
171
+ switch (unit.kind) {
172
+ case "text":
173
+ return unit.value;
174
+ case "tab":
175
+ return " ";
176
+ case "hard_break":
177
+ return "\n";
178
+ case "paragraph_break":
179
+ return "\n";
180
+ case "image":
181
+ return "\uFFFC";
182
+ case "opaque_inline":
183
+ return "\uFFF9";
184
+ case "opaque_block":
185
+ return "\uFFFA";
186
+ }
187
+ }).join("");
188
+ }
189
+ function cloneStoryUnit(unit) {
190
+ switch (unit.kind) {
191
+ case "text":
192
+ return {
193
+ kind: "text",
194
+ value: unit.value,
195
+ ...unit.marks ? { marks: cloneMarks(unit.marks) } : {},
196
+ ...unit.hyperlinkHref ? { hyperlinkHref: unit.hyperlinkHref } : {}
197
+ };
198
+ case "tab":
199
+ return {
200
+ kind: "tab",
201
+ ...unit.hyperlinkHref ? { hyperlinkHref: unit.hyperlinkHref } : {}
202
+ };
203
+ case "hard_break":
204
+ return {
205
+ kind: "hard_break",
206
+ ...unit.hyperlinkHref ? { hyperlinkHref: unit.hyperlinkHref } : {}
207
+ };
208
+ case "image":
209
+ return {
210
+ kind: "image",
211
+ mediaId: unit.mediaId,
212
+ ...unit.altText ? { altText: unit.altText } : {}
213
+ };
214
+ case "opaque_inline":
215
+ return {
216
+ kind: "opaque_inline",
217
+ fragmentId: unit.fragmentId,
218
+ warningId: unit.warningId
219
+ };
220
+ case "opaque_block":
221
+ return {
222
+ kind: "opaque_block",
223
+ fragmentId: unit.fragmentId,
224
+ warningId: unit.warningId,
225
+ ...unit.nextParagraph ? { nextParagraph: cloneParagraphProperties(unit.nextParagraph) } : {}
226
+ };
227
+ case "paragraph_break":
228
+ return {
229
+ kind: "paragraph_break",
230
+ nextParagraph: cloneParagraphProperties(unit.nextParagraph)
231
+ };
232
+ }
233
+ }
234
+ function cloneParagraphProperties(properties) {
235
+ return {
236
+ ...properties.styleId ? { styleId: properties.styleId } : {},
237
+ ...properties.numbering ? {
238
+ numbering: {
239
+ numberingInstanceId: properties.numbering.numberingInstanceId,
240
+ level: properties.numbering.level
241
+ }
242
+ } : {}
243
+ };
244
+ }
245
+ function normalizeDocumentRoot(content) {
246
+ if (isDocumentRootNode(content)) {
247
+ return content;
248
+ }
249
+ if (Array.isArray(content)) {
250
+ return {
251
+ type: "doc",
252
+ children: content.filter(
253
+ (block) => isParagraphNode(block) || isOpaqueBlockNode(block)
254
+ )
255
+ };
256
+ }
257
+ return {
258
+ type: "doc",
259
+ children: [createEmptyParagraph()]
260
+ };
261
+ }
262
+ function flattenInlineNodes(nodes, hyperlinkHref) {
263
+ const units = [];
264
+ for (const node of nodes) {
265
+ switch (node.type) {
266
+ case "text":
267
+ for (const character of Array.from(node.text)) {
268
+ units.push({
269
+ kind: "text",
270
+ value: character,
271
+ ...node.marks ? { marks: cloneMarks(node.marks) } : {},
272
+ ...hyperlinkHref ? { hyperlinkHref } : {}
273
+ });
274
+ }
275
+ break;
276
+ case "tab":
277
+ units.push({
278
+ kind: "tab",
279
+ ...hyperlinkHref ? { hyperlinkHref } : {}
280
+ });
281
+ break;
282
+ case "hard_break":
283
+ units.push({
284
+ kind: "hard_break",
285
+ ...hyperlinkHref ? { hyperlinkHref } : {}
286
+ });
287
+ break;
288
+ case "hyperlink":
289
+ units.push(...flattenInlineNodes(node.children, node.href));
290
+ break;
291
+ case "image":
292
+ units.push({
293
+ kind: "image",
294
+ mediaId: node.mediaId,
295
+ ...node.altText ? { altText: node.altText } : {}
296
+ });
297
+ break;
298
+ case "opaque_inline":
299
+ units.push({
300
+ kind: "opaque_inline",
301
+ fragmentId: node.fragmentId,
302
+ warningId: node.warningId
303
+ });
304
+ break;
305
+ }
306
+ }
307
+ return units;
308
+ }
309
+ function extractParagraphProperties(paragraph) {
310
+ return {
311
+ ...paragraph.styleId ? { styleId: paragraph.styleId } : {},
312
+ ...paragraph.numbering ? {
313
+ numbering: {
314
+ numberingInstanceId: paragraph.numbering.numberingInstanceId,
315
+ level: paragraph.numbering.level
316
+ }
317
+ } : {}
318
+ };
319
+ }
320
+ function createParagraph(properties) {
321
+ return {
322
+ type: "paragraph",
323
+ ...properties.styleId ? { styleId: properties.styleId } : {},
324
+ ...properties.numbering ? {
325
+ numbering: {
326
+ numberingInstanceId: properties.numbering.numberingInstanceId,
327
+ level: properties.numbering.level
328
+ }
329
+ } : {},
330
+ children: []
331
+ };
332
+ }
333
+ function createEmptyParagraph() {
334
+ return {
335
+ type: "paragraph",
336
+ children: []
337
+ };
338
+ }
339
+ var EMPTY_PARAGRAPH_PROPERTIES = {};
340
+ function cloneMarks(marks) {
341
+ return marks.map((mark) => ({ ...mark }));
342
+ }
343
+ function haveEqualMarks(left, right) {
344
+ if (!left && !right) {
345
+ return true;
346
+ }
347
+ if (!left || !right || left.length !== right.length) {
348
+ return false;
349
+ }
350
+ return left.every((mark, index) => mark.type === right[index]?.type);
351
+ }
352
+ function isDocumentRootNode(value) {
353
+ return Boolean(value) && typeof value === "object" && value.type === "doc";
354
+ }
355
+ function isParagraphNode(value) {
356
+ return Boolean(value) && typeof value === "object" && value.type === "paragraph";
357
+ }
358
+ function isOpaqueBlockNode(value) {
359
+ return Boolean(value) && typeof value === "object" && value.type === "opaque_block";
360
+ }
361
+
362
+ export {
363
+ parseTextStory,
364
+ serializeTextStory,
365
+ createPlainText,
366
+ cloneStoryUnit,
367
+ cloneParagraphProperties
368
+ };
369
+ //# sourceMappingURL=chunk-KLMXQVYK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/schema/text-schema.ts"],"sourcesContent":["import type {\n DocumentRootNode,\n HyperlinkNode,\n InlineNode,\n OpaqueBlockNode,\n OpaqueInlineNode,\n ParagraphNode,\n TextMark,\n} from \"../../model/canonical-document.ts\";\n\nexport interface ParagraphProperties {\n styleId?: string;\n numbering?: ParagraphNode[\"numbering\"];\n}\n\nexport interface TextStory {\n firstParagraph: ParagraphProperties;\n units: StoryUnit[];\n size: number;\n}\n\nexport type StoryUnit =\n | TextCharacterUnit\n | TabUnit\n | HardBreakUnit\n | ImageUnit\n | OpaqueInlineUnit\n | OpaqueBlockUnit\n | ParagraphBreakUnit;\n\nexport interface TextCharacterUnit {\n kind: \"text\";\n value: string;\n marks?: TextMark[];\n hyperlinkHref?: string;\n}\n\nexport interface TabUnit {\n kind: \"tab\";\n hyperlinkHref?: string;\n}\n\nexport interface HardBreakUnit {\n kind: \"hard_break\";\n hyperlinkHref?: string;\n}\n\nexport interface ImageUnit {\n kind: \"image\";\n mediaId: string;\n altText?: string;\n}\n\nexport interface OpaqueInlineUnit {\n kind: \"opaque_inline\";\n fragmentId: string;\n warningId: string;\n}\n\nexport interface OpaqueBlockUnit {\n kind: \"opaque_block\";\n fragmentId: string;\n warningId: string;\n nextParagraph?: ParagraphProperties;\n}\n\nexport interface ParagraphBreakUnit {\n kind: \"paragraph_break\";\n nextParagraph: ParagraphProperties;\n}\n\nexport function parseTextStory(content: unknown): TextStory {\n const root = normalizeDocumentRoot(content);\n const firstParagraphNode = root.children.find(isParagraphNode);\n const firstParagraph = firstParagraphNode\n ? extractParagraphProperties(firstParagraphNode)\n : cloneParagraphProperties(EMPTY_PARAGRAPH_PROPERTIES);\n const units: StoryUnit[] = [];\n\n for (let index = 0; index < root.children.length; index += 1) {\n const block = root.children[index];\n const nextBlock = root.children[index + 1];\n\n if (isParagraphNode(block)) {\n units.push(...flattenInlineNodes(block.children));\n\n if (isParagraphNode(nextBlock)) {\n units.push({\n kind: \"paragraph_break\",\n nextParagraph: extractParagraphProperties(nextBlock),\n });\n }\n\n continue;\n }\n\n if (block.type !== \"opaque_block\") {\n continue;\n }\n\n units.push({\n kind: \"opaque_block\",\n fragmentId: block.fragmentId,\n warningId: block.warningId,\n ...(isParagraphNode(nextBlock)\n ? { nextParagraph: extractParagraphProperties(nextBlock) }\n : {}),\n });\n }\n\n return {\n firstParagraph,\n units,\n size: units.length,\n };\n}\n\nexport function serializeTextStory(story: TextStory): DocumentRootNode {\n const blocks: Array<ParagraphNode | OpaqueBlockNode> = [];\n let currentParagraph: ParagraphNode | undefined = createParagraph(story.firstParagraph);\n let currentHyperlink: HyperlinkNode | undefined;\n let activeTextBuffer:\n | {\n text: string;\n marks?: TextMark[];\n hyperlinkHref?: string;\n }\n | undefined;\n\n const ensureCurrentParagraph = () => {\n if (!currentParagraph) {\n currentParagraph = createParagraph(EMPTY_PARAGRAPH_PROPERTIES);\n }\n };\n\n const flushTextBuffer = () => {\n if (!activeTextBuffer || activeTextBuffer.text.length === 0) {\n activeTextBuffer = undefined;\n return;\n }\n\n const textNode = {\n type: \"text\" as const,\n text: activeTextBuffer.text,\n ...(activeTextBuffer.marks ? { marks: cloneMarks(activeTextBuffer.marks) } : {}),\n };\n\n ensureCurrentParagraph();\n\n if (activeTextBuffer.hyperlinkHref) {\n if (!currentHyperlink || currentHyperlink.href !== activeTextBuffer.hyperlinkHref) {\n flushHyperlink();\n currentHyperlink = {\n type: \"hyperlink\",\n href: activeTextBuffer.hyperlinkHref,\n children: [],\n };\n }\n\n currentHyperlink.children.push(textNode);\n } else {\n flushHyperlink();\n currentParagraph!.children.push(textNode);\n }\n\n activeTextBuffer = undefined;\n };\n\n const flushHyperlink = () => {\n if (currentHyperlink) {\n ensureCurrentParagraph();\n currentParagraph!.children.push(currentHyperlink);\n currentHyperlink = undefined;\n }\n };\n\n const flushParagraph = () => {\n flushTextBuffer();\n flushHyperlink();\n\n if (!currentParagraph) {\n return;\n }\n\n blocks.push(currentParagraph);\n currentParagraph = undefined;\n };\n\n const pushInlineNode = (\n node: Exclude<InlineNode, { type: \"text\" }>,\n hyperlinkHref?: string,\n ) => {\n flushTextBuffer();\n ensureCurrentParagraph();\n\n if (hyperlinkHref) {\n if (!currentHyperlink || currentHyperlink.href !== hyperlinkHref) {\n flushHyperlink();\n currentHyperlink = {\n type: \"hyperlink\",\n href: hyperlinkHref,\n children: [],\n };\n }\n\n currentHyperlink.children.push(node as HyperlinkNode[\"children\"][number]);\n return;\n }\n\n flushHyperlink();\n currentParagraph!.children.push(node);\n };\n\n for (const unit of story.units) {\n if (unit.kind === \"paragraph_break\") {\n flushParagraph();\n currentParagraph = createParagraph(unit.nextParagraph);\n continue;\n }\n\n if (unit.kind === \"opaque_block\") {\n flushParagraph();\n blocks.push({\n type: \"opaque_block\",\n fragmentId: unit.fragmentId,\n warningId: unit.warningId,\n });\n currentParagraph = unit.nextParagraph\n ? createParagraph(unit.nextParagraph)\n : undefined;\n continue;\n }\n\n if (unit.kind === \"text\") {\n const shouldExtendBuffer =\n activeTextBuffer &&\n activeTextBuffer.hyperlinkHref === unit.hyperlinkHref &&\n haveEqualMarks(activeTextBuffer.marks, unit.marks);\n\n if (shouldExtendBuffer && activeTextBuffer) {\n activeTextBuffer.text += unit.value;\n } else {\n flushTextBuffer();\n activeTextBuffer = {\n text: unit.value,\n ...(unit.marks ? { marks: cloneMarks(unit.marks) } : {}),\n ...(unit.hyperlinkHref ? { hyperlinkHref: unit.hyperlinkHref } : {}),\n };\n }\n\n continue;\n }\n\n switch (unit.kind) {\n case \"tab\":\n pushInlineNode({ type: \"tab\" }, unit.hyperlinkHref);\n break;\n case \"hard_break\":\n pushInlineNode({ type: \"hard_break\" }, unit.hyperlinkHref);\n break;\n case \"image\":\n pushInlineNode({\n type: \"image\",\n mediaId: unit.mediaId,\n ...(unit.altText ? { altText: unit.altText } : {}),\n });\n break;\n case \"opaque_inline\":\n pushInlineNode({\n type: \"opaque_inline\",\n fragmentId: unit.fragmentId,\n warningId: unit.warningId,\n });\n break;\n }\n }\n\n flushParagraph();\n\n if (blocks.length === 0) {\n blocks.push(createParagraph(story.firstParagraph));\n }\n\n return {\n type: \"doc\",\n children: blocks,\n };\n}\n\nexport function createPlainText(story: TextStory): string {\n return story.units\n .map((unit) => {\n switch (unit.kind) {\n case \"text\":\n return unit.value;\n case \"tab\":\n return \"\\t\";\n case \"hard_break\":\n return \"\\n\";\n case \"paragraph_break\":\n return \"\\n\";\n case \"image\":\n return \"\\uFFFC\";\n case \"opaque_inline\":\n return \"\\uFFF9\";\n case \"opaque_block\":\n return \"\\uFFFA\";\n }\n })\n .join(\"\");\n}\n\nexport function cloneStoryUnit(unit: StoryUnit): StoryUnit {\n switch (unit.kind) {\n case \"text\":\n return {\n kind: \"text\",\n value: unit.value,\n ...(unit.marks ? { marks: cloneMarks(unit.marks) } : {}),\n ...(unit.hyperlinkHref ? { hyperlinkHref: unit.hyperlinkHref } : {}),\n };\n case \"tab\":\n return {\n kind: \"tab\",\n ...(unit.hyperlinkHref ? { hyperlinkHref: unit.hyperlinkHref } : {}),\n };\n case \"hard_break\":\n return {\n kind: \"hard_break\",\n ...(unit.hyperlinkHref ? { hyperlinkHref: unit.hyperlinkHref } : {}),\n };\n case \"image\":\n return {\n kind: \"image\",\n mediaId: unit.mediaId,\n ...(unit.altText ? { altText: unit.altText } : {}),\n };\n case \"opaque_inline\":\n return {\n kind: \"opaque_inline\",\n fragmentId: unit.fragmentId,\n warningId: unit.warningId,\n };\n case \"opaque_block\":\n return {\n kind: \"opaque_block\",\n fragmentId: unit.fragmentId,\n warningId: unit.warningId,\n ...(unit.nextParagraph\n ? { nextParagraph: cloneParagraphProperties(unit.nextParagraph) }\n : {}),\n };\n case \"paragraph_break\":\n return {\n kind: \"paragraph_break\",\n nextParagraph: cloneParagraphProperties(unit.nextParagraph),\n };\n }\n}\n\nexport function cloneParagraphProperties(\n properties: ParagraphProperties,\n): ParagraphProperties {\n return {\n ...(properties.styleId ? { styleId: properties.styleId } : {}),\n ...(properties.numbering\n ? {\n numbering: {\n numberingInstanceId: properties.numbering.numberingInstanceId,\n level: properties.numbering.level,\n },\n }\n : {}),\n };\n}\n\nfunction normalizeDocumentRoot(content: unknown): DocumentRootNode {\n if (isDocumentRootNode(content)) {\n return content;\n }\n\n if (Array.isArray(content)) {\n return {\n type: \"doc\",\n children: content.filter(\n (block): block is DocumentRootNode[\"children\"][number] =>\n isParagraphNode(block) || isOpaqueBlockNode(block),\n ),\n };\n }\n\n return {\n type: \"doc\",\n children: [createEmptyParagraph()],\n };\n}\n\nfunction flattenInlineNodes(\n nodes: ParagraphNode[\"children\"],\n hyperlinkHref?: string,\n): StoryUnit[] {\n const units: StoryUnit[] = [];\n\n for (const node of nodes) {\n switch (node.type) {\n case \"text\":\n for (const character of Array.from(node.text)) {\n units.push({\n kind: \"text\",\n value: character,\n ...(node.marks ? { marks: cloneMarks(node.marks) } : {}),\n ...(hyperlinkHref ? { hyperlinkHref } : {}),\n });\n }\n break;\n case \"tab\":\n units.push({\n kind: \"tab\",\n ...(hyperlinkHref ? { hyperlinkHref } : {}),\n });\n break;\n case \"hard_break\":\n units.push({\n kind: \"hard_break\",\n ...(hyperlinkHref ? { hyperlinkHref } : {}),\n });\n break;\n case \"hyperlink\":\n units.push(...flattenInlineNodes(node.children, node.href));\n break;\n case \"image\":\n units.push({\n kind: \"image\",\n mediaId: node.mediaId,\n ...(node.altText ? { altText: node.altText } : {}),\n });\n break;\n case \"opaque_inline\":\n units.push({\n kind: \"opaque_inline\",\n fragmentId: node.fragmentId,\n warningId: node.warningId,\n });\n break;\n }\n }\n\n return units;\n}\n\nfunction extractParagraphProperties(paragraph: ParagraphNode): ParagraphProperties {\n return {\n ...(paragraph.styleId ? { styleId: paragraph.styleId } : {}),\n ...(paragraph.numbering\n ? {\n numbering: {\n numberingInstanceId: paragraph.numbering.numberingInstanceId,\n level: paragraph.numbering.level,\n },\n }\n : {}),\n };\n}\n\nfunction createParagraph(properties: ParagraphProperties): ParagraphNode {\n return {\n type: \"paragraph\",\n ...(properties.styleId ? { styleId: properties.styleId } : {}),\n ...(properties.numbering\n ? {\n numbering: {\n numberingInstanceId: properties.numbering.numberingInstanceId,\n level: properties.numbering.level,\n },\n }\n : {}),\n children: [],\n };\n}\n\nfunction createEmptyParagraph(): ParagraphNode {\n return {\n type: \"paragraph\",\n children: [],\n };\n}\n\nconst EMPTY_PARAGRAPH_PROPERTIES: ParagraphProperties = {};\n\nfunction cloneMarks(marks: TextMark[]): TextMark[] {\n return marks.map((mark) => ({ ...mark }));\n}\n\nfunction haveEqualMarks(left?: TextMark[], right?: TextMark[]): boolean {\n if (!left && !right) {\n return true;\n }\n\n if (!left || !right || left.length !== right.length) {\n return false;\n }\n\n return left.every((mark, index) => mark.type === right[index]?.type);\n}\n\nfunction isDocumentRootNode(value: unknown): value is DocumentRootNode {\n return Boolean(value) && typeof value === \"object\" && (value as { type?: string }).type === \"doc\";\n}\n\nfunction isParagraphNode(value: unknown): value is ParagraphNode {\n return Boolean(value) && typeof value === \"object\" && (value as { type?: string }).type === \"paragraph\";\n}\n\nfunction isOpaqueBlockNode(value: unknown): value is OpaqueBlockNode {\n return Boolean(value) && typeof value === \"object\" && (value as { type?: string }).type === \"opaque_block\";\n}\n"],"mappings":";AAuEO,SAAS,eAAe,SAA6B;AAC1D,QAAM,OAAO,sBAAsB,OAAO;AAC1C,QAAM,qBAAqB,KAAK,SAAS,KAAK,eAAe;AAC7D,QAAM,iBAAiB,qBAC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AkD,CAAC;AAEzD,SAAS,WAAW,OAA+B;AACjD,SAAO,MAAM,IAAI,CAAC,UAAU,EAAE,GAAG,KAAK,EAAE;AAC1C;AAEA,SAAS,eAAe,MAAmB,OAA6B;AACtE,MAAI,CAAC,QAAQ,CAAC,OAAO;AACnB,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,QAAQ,CAAC,SAAS,KAAK,WAAW,MAAM,QAAQ;AACnD,WAAO;AAAA,EACT;AAEA,SAAO,KAAK,MAAM,CAAC,MAAM,UAAU,KAAK,SAAS,MAAM,KAAK,GAAG,IAAI;AACrE;AAEA,SAAS,mBAAmB,OAA2C;AACrE,SAAO,QAAQ,KAAK,KAAK,OAAO,UAAU,YAAa,MAA4B,SAAS;AAC9F;AAEA,SAAS,gBAAgB,OAAwC;AAC/D,SAAO,QAAQ,KAAK,KAAK,OAAO,UAAU,YAAa,MAA4B,SAAS;AAC9F;AAEA,SAAS,kBAAkB,OAA0C;AACnE,SAAO,QAAQ,KAAK,KAAK,OAAO,UAAU,YAAa,MAA4B,SAAS;AAC9F;","names":[]}
@@ -0,0 +1,214 @@
1
+ import {
2
+ createEditorSurfaceSnapshot
3
+ } from "./chunk-EILUG3VB.js";
4
+ import {
5
+ createSelectionSnapshot
6
+ } from "./chunk-5FN54NDH.js";
7
+
8
+ // src/core/commands/structural-helpers.ts
9
+ var DEFAULT_TABLE_COLUMN_WIDTH = 2400;
10
+ function createNoopStructuralMutation(document, selection) {
11
+ return {
12
+ changed: false,
13
+ document,
14
+ selection
15
+ };
16
+ }
17
+ function resolveParagraphScope(document, selection) {
18
+ const root = asDocumentRoot(document);
19
+ if (!root) {
20
+ return null;
21
+ }
22
+ const surface = createEditorSurfaceSnapshot(document, selection);
23
+ const selectionFrom = Math.min(selection.anchor, selection.head);
24
+ const selectionTo = Math.max(selection.anchor, selection.head);
25
+ for (let blockIndex = 0; blockIndex < root.children.length; blockIndex += 1) {
26
+ const block = root.children[blockIndex];
27
+ const surfaceBlock = surface.blocks[blockIndex];
28
+ if (!surfaceBlock) {
29
+ continue;
30
+ }
31
+ if (block.type === "paragraph" && surfaceBlock.kind === "paragraph" && selectionWithinRange(selectionFrom, selectionTo, surfaceBlock.from, surfaceBlock.to)) {
32
+ return {
33
+ kind: "top-level",
34
+ blockIndex,
35
+ paragraph: cloneParagraph(block),
36
+ paragraphStart: surfaceBlock.from
37
+ };
38
+ }
39
+ if (block.type !== "table" || surfaceBlock.kind !== "table") {
40
+ continue;
41
+ }
42
+ for (let rowIndex = 0; rowIndex < block.rows.length; rowIndex += 1) {
43
+ const row = block.rows[rowIndex];
44
+ const surfaceRow = surfaceBlock.rows[rowIndex];
45
+ if (!surfaceRow) {
46
+ continue;
47
+ }
48
+ for (let cellIndex = 0; cellIndex < row.cells.length; cellIndex += 1) {
49
+ const cell = row.cells[cellIndex];
50
+ const surfaceCell = surfaceRow.cells[cellIndex];
51
+ if (!surfaceCell) {
52
+ continue;
53
+ }
54
+ for (let childIndex = 0; childIndex < cell.children.length; childIndex += 1) {
55
+ const child = cell.children[childIndex];
56
+ const surfaceChild = surfaceCell.content[childIndex];
57
+ if (child?.type === "paragraph" && surfaceChild?.kind === "paragraph" && selectionWithinRange(selectionFrom, selectionTo, surfaceChild.from, surfaceChild.to)) {
58
+ return {
59
+ kind: "table-cell",
60
+ tableBlockIndex: blockIndex,
61
+ rowIndex,
62
+ cellIndex,
63
+ childIndex,
64
+ paragraph: cloneParagraph(child),
65
+ paragraphStart: surfaceChild.from
66
+ };
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+ return null;
73
+ }
74
+ function replaceParagraphScope(document, scope, replacementParagraphs) {
75
+ const root = asDocumentRoot(document);
76
+ if (!root) {
77
+ return document;
78
+ }
79
+ const nextRoot = scope.kind === "top-level" ? {
80
+ ...root,
81
+ children: [
82
+ ...root.children.slice(0, scope.blockIndex),
83
+ ...replacementParagraphs,
84
+ ...root.children.slice(scope.blockIndex + 1)
85
+ ]
86
+ } : {
87
+ ...root,
88
+ children: root.children.map((child, blockIndex) => {
89
+ if (blockIndex !== scope.tableBlockIndex || child.type !== "table") {
90
+ return child;
91
+ }
92
+ return {
93
+ ...child,
94
+ rows: child.rows.map((row, rowIndex) => {
95
+ if (rowIndex !== scope.rowIndex) {
96
+ return row;
97
+ }
98
+ return {
99
+ ...row,
100
+ cells: row.cells.map((cell, cellIndex) => {
101
+ if (cellIndex !== scope.cellIndex) {
102
+ return cell;
103
+ }
104
+ return {
105
+ ...cell,
106
+ children: [
107
+ ...cell.children.slice(0, scope.childIndex),
108
+ ...replacementParagraphs,
109
+ ...cell.children.slice(scope.childIndex + 1)
110
+ ]
111
+ };
112
+ })
113
+ };
114
+ })
115
+ };
116
+ })
117
+ };
118
+ return {
119
+ ...document,
120
+ content: nextRoot
121
+ };
122
+ }
123
+ function createEmptyParagraph() {
124
+ return {
125
+ type: "paragraph",
126
+ children: []
127
+ };
128
+ }
129
+ function createInsertedTableBlock(rows, columns, styleId) {
130
+ const safeRows = Math.max(1, Math.floor(rows));
131
+ const safeColumns = Math.max(1, Math.floor(columns));
132
+ const nextRows = [];
133
+ for (let rowIndex = 0; rowIndex < safeRows; rowIndex += 1) {
134
+ const cells = [];
135
+ for (let columnIndex = 0; columnIndex < safeColumns; columnIndex += 1) {
136
+ cells.push({
137
+ type: "table_cell",
138
+ children: [createEmptyParagraph()]
139
+ });
140
+ }
141
+ nextRows.push({
142
+ type: "table_row",
143
+ cells
144
+ });
145
+ }
146
+ return {
147
+ type: "table",
148
+ ...styleId ? { styleId } : {},
149
+ gridColumns: Array.from({ length: safeColumns }, () => DEFAULT_TABLE_COLUMN_WIDTH),
150
+ rows: nextRows
151
+ };
152
+ }
153
+ function resolveInsertedTableStyleId(document) {
154
+ const styles = document.styles?.tables;
155
+ if (!styles || typeof styles !== "object") {
156
+ return void 0;
157
+ }
158
+ return "TableGrid" in styles ? "TableGrid" : void 0;
159
+ }
160
+ function findTableCellParagraphSelection(document, tableBlockIndex, rowIndex, cellIndex) {
161
+ const surface = createEditorSurfaceSnapshot(document, createSelectionSnapshot(0, 0));
162
+ const tableBlock = surface.blocks[tableBlockIndex];
163
+ if (!tableBlock || tableBlock.kind !== "table") {
164
+ return null;
165
+ }
166
+ const paragraph = tableBlock.rows[rowIndex]?.cells[cellIndex]?.content.find(
167
+ (block) => block.kind === "paragraph"
168
+ );
169
+ if (!paragraph || paragraph.kind !== "paragraph") {
170
+ return null;
171
+ }
172
+ return createSelectionSnapshot(paragraph.from, paragraph.from);
173
+ }
174
+ function findTopLevelParagraphSelectionNearBlock(document, preferredBlockIndex) {
175
+ const surface = createEditorSurfaceSnapshot(document, createSelectionSnapshot(0, 0));
176
+ for (let index = preferredBlockIndex; index < surface.blocks.length; index += 1) {
177
+ const block = surface.blocks[index];
178
+ if (block?.kind === "paragraph") {
179
+ return createSelectionSnapshot(block.from, block.from);
180
+ }
181
+ }
182
+ for (let index = Math.min(preferredBlockIndex - 1, surface.blocks.length - 1); index >= 0; index -= 1) {
183
+ const block = surface.blocks[index];
184
+ if (block?.kind === "paragraph") {
185
+ return createSelectionSnapshot(block.from, block.from);
186
+ }
187
+ }
188
+ return null;
189
+ }
190
+ function asDocumentRoot(document) {
191
+ const root = document.content;
192
+ if (!root || root.type !== "doc" || !Array.isArray(root.children)) {
193
+ return null;
194
+ }
195
+ return root;
196
+ }
197
+ function selectionWithinRange(selectionFrom, selectionTo, rangeFrom, rangeTo) {
198
+ return selectionFrom >= rangeFrom && selectionTo <= rangeTo;
199
+ }
200
+ function cloneParagraph(paragraph) {
201
+ return structuredClone(paragraph);
202
+ }
203
+
204
+ export {
205
+ createNoopStructuralMutation,
206
+ resolveParagraphScope,
207
+ replaceParagraphScope,
208
+ createEmptyParagraph,
209
+ createInsertedTableBlock,
210
+ resolveInsertedTableStyleId,
211
+ findTableCellParagraphSelection,
212
+ findTopLevelParagraphSelectionNearBlock
213
+ };
214
+ //# sourceMappingURL=chunk-KZUG5KFQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/commands/structural-helpers.ts"],"sourcesContent":["import {\n createSelectionSnapshot,\n type CanonicalDocumentEnvelope,\n type SelectionSnapshot,\n} from \"../state/editor-state.ts\";\nimport type { TransactionMapping } from \"../selection/mapping.ts\";\nimport type {\n DocumentRootNode,\n ParagraphNode,\n TableCellNode,\n TableNode,\n TableRowNode,\n} from \"../../model/canonical-document.ts\";\nimport { createEditorSurfaceSnapshot } from \"../../runtime/surface-projection.ts\";\n\nexport interface TopLevelParagraphScope {\n kind: \"top-level\";\n blockIndex: number;\n paragraph: ParagraphNode;\n paragraphStart: number;\n}\n\nexport interface TableParagraphScope {\n kind: \"table-cell\";\n tableBlockIndex: number;\n rowIndex: number;\n cellIndex: number;\n childIndex: number;\n paragraph: ParagraphNode;\n paragraphStart: number;\n}\n\nexport type ParagraphScope = TopLevelParagraphScope | TableParagraphScope;\n\nexport interface StructuralMutationResult {\n changed: boolean;\n document: CanonicalDocumentEnvelope;\n selection: SelectionSnapshot;\n mapping?: TransactionMapping;\n}\n\nconst DEFAULT_TABLE_COLUMN_WIDTH = 2400;\n\nexport function createNoopStructuralMutation(\n document: CanonicalDocumentEnvelope,\n selection: SelectionSnapshot,\n): StructuralMutationResult {\n return {\n changed: false,\n document,\n selection,\n };\n}\n\nexport function resolveParagraphScope(\n document: CanonicalDocumentEnvelope,\n selection: SelectionSnapshot,\n): ParagraphScope | null {\n const root = asDocumentRoot(document);\n if (!root) {\n return null;\n }\n\n const surface = createEditorSurfaceSnapshot(document, selection);\n const selectionFrom = Math.min(selection.anchor, selection.head);\n const selectionTo = Math.max(selection.anchor, selection.head);\n\n for (let blockIndex = 0; blockIndex < root.children.length; blockIndex += 1) {\n const block = root.children[blockIndex];\n const surfaceBlock = surface.blocks[blockIndex];\n\n if (!surfaceBlock) {\n continue;\n }\n\n if (\n block.type === \"paragraph\" &&\n surfaceBlock.kind === \"paragraph\" &&\n selectionWithinRange(selectionFrom, selectionTo, surfaceBlock.from, surfaceBlock.to)\n ) {\n return {\n kind: \"top-level\",\n blockIndex,\n paragraph: cloneParagraph(block),\n paragraphStart: surfaceBlock.from,\n };\n }\n\n if (block.type !== \"table\" || surfaceBlock.kind !== \"table\") {\n continue;\n }\n\n for (let rowIndex = 0; rowIndex < block.rows.length; rowIndex += 1) {\n const row = block.rows[rowIndex];\n const surfaceRow = surfaceBlock.rows[rowIndex];\n if (!surfaceRow) {\n continue;\n }\n\n for (let cellIndex = 0; cellIndex < row.cells.length; cellIndex += 1) {\n const cell = row.cells[cellIndex];\n const surfaceCell = surfaceRow.cells[cellIndex];\n if (!surfaceCell) {\n continue;\n }\n\n for (let childIndex = 0; childIndex < cell.children.length; childIndex += 1) {\n const child = cell.children[childIndex];\n const surfaceChild = surfaceCell.content[childIndex];\n if (\n child?.type === \"paragraph\" &&\n surfaceChild?.kind === \"paragraph\" &&\n selectionWithinRange(selectionFrom, selectionTo, surfaceChild.from, surfaceChild.to)\n ) {\n return {\n kind: \"table-cell\",\n tableBlockIndex: blockIndex,\n rowIndex,\n cellIndex,\n childIndex,\n paragraph: cloneParagraph(child),\n paragraphStart: surfaceChild.from,\n };\n }\n }\n }\n }\n }\n\n return null;\n}\n\nexport function replaceParagraphScope(\n document: CanonicalDocumentEnvelope,\n scope: ParagraphScope,\n replacementParagraphs: ParagraphNode[],\n): CanonicalDocumentEnvelope {\n const root = asDocumentRoot(document);\n if (!root) {\n return document;\n }\n\n const nextRoot: DocumentRootNode =\n scope.kind === \"top-level\"\n ? {\n ...root,\n children: [\n ...root.children.slice(0, scope.blockIndex),\n ...replacementParagraphs,\n ...root.children.slice(scope.blockIndex + 1),\n ],\n }\n : {\n ...root,\n children: root.children.map((child, blockIndex) => {\n if (blockIndex !== scope.tableBlockIndex || child.type !== \"table\") {\n return child;\n }\n\n return {\n ...child,\n rows: child.rows.map((row, rowIndex) => {\n if (rowIndex !== scope.rowIndex) {\n return row;\n }\n\n return {\n ...row,\n cells: row.cells.map((cell, cellIndex) => {\n if (cellIndex !== scope.cellIndex) {\n return cell;\n }\n\n return {\n ...cell,\n children: [\n ...cell.children.slice(0, scope.childIndex),\n ...replacementParagraphs,\n ...cell.children.slice(scope.childIndex + 1),\n ],\n };\n }),\n };\n }),\n };\n }),\n };\n\n return {\n ...document,\n content: nextRoot,\n };\n}\n\nexport function createEmptyParagraph(): ParagraphNode {\n return {\n type: \"paragraph\",\n children: [],\n };\n}\n\nexport function createInsertedTableBlock(\n rows: number,\n columns: number,\n styleId?: string,\n): TableNode {\n const safeRows = Math.max(1, Math.floor(rows));\n const safeColumns = Math.max(1, Math.floor(columns));\n const nextRows: TableRowNode[] = [];\n\n for (let rowIndex = 0; rowIndex < safeRows; rowIndex += 1) {\n const cells: TableCellNode[] = [];\n for (let columnIndex = 0; columnIndex < safeColumns; columnIndex += 1) {\n cells.push({\n type: \"table_cell\",\n children: [createEmptyParagraph()],\n });\n }\n nextRows.push({\n type: \"table_row\",\n cells,\n });\n }\n\n return {\n type: \"table\",\n ...(styleId ? { styleId } : {}),\n gridColumns: Array.from({ length: safeColumns }, () => DEFAULT_TABLE_COLUMN_WIDTH),\n rows: nextRows,\n };\n}\n\nexport function resolveInsertedTableStyleId(\n document: CanonicalDocumentEnvelope,\n): string | undefined {\n const styles = document.styles?.tables;\n if (!styles || typeof styles !== \"object\") {\n return undefined;\n }\n return \"TableGrid\" in styles ? \"TableGrid\" : undefined;\n}\n\nexport function findTableCellParagraphSelection(\n document: CanonicalDocumentEnvelope,\n tableBlockIndex: number,\n rowIndex: number,\n cellIndex: number,\n): SelectionSnapshot | null {\n const surface = createEditorSurfaceSnapshot(document, createSelectionSnapshot(0, 0));\n const tableBlock = surface.blocks[tableBlockIndex];\n if (!tableBlock || tableBlock.kind !== \"table\") {\n return null;\n }\n\n const paragraph = tableBlock.rows[rowIndex]?.cells[cellIndex]?.content.find(\n (block) => block.kind === \"paragraph\",\n );\n if (!paragraph || paragraph.kind !== \"paragraph\") {\n return null;\n }\n\n return createSelectionSnapshot(paragraph.from, paragraph.from);\n}\n\nexport function findTopLevelParagraphSelectionNearBlock(\n document: CanonicalDocumentEnvelope,\n preferredBlockIndex: number,\n): SelectionSnapshot | null {\n const surface = createEditorSurfaceSnapshot(document, createSelectionSnapshot(0, 0));\n\n for (let index = preferredBlockIndex; index < surface.blocks.length; index += 1) {\n const block = surface.blocks[index];\n if (block?.kind === \"paragraph\") {\n return createSelectionSnapshot(block.from, block.from);\n }\n }\n\n for (let index = Math.min(preferredBlockIndex - 1, surface.blocks.length - 1); index >= 0; index -= 1) {\n const block = surface.blocks[index];\n if (block?.kind === \"paragraph\") {\n return createSelectionSnapshot(block.from, block.from);\n }\n }\n\n return null;\n}\n\nfunction asDocumentRoot(\n document: CanonicalDocumentEnvelope,\n): DocumentRootNode | null {\n const root = document.content;\n if (!root || root.type !== \"doc\" || !Array.isArray(root.children)) {\n return null;\n }\n return root;\n}\n\nfunction selectionWithinRange(\n selectionFrom: number,\n selectionTo: number,\n rangeFrom: number,\n rangeTo: number,\n): boolean {\n return selectionFrom >= rangeFrom && selectionTo <= rangeTo;\n}\n\nfunction cloneParagraph(paragraph: ParagraphNode): ParagraphNode {\n return structuredClone(paragraph) as ParagraphNode;\n}\n"],"mappings":";;;;;;;;AAyCA,IAAM,6BAA6B;AAE5B,SAAS,6BACd,UACA,WAC0B;AAC1B,SAAO;AAAA,IACL,SAAS;AAAA,IACT;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,sBACd,UACA,WACuB;AACvB,QAAM,OAAO,eAAe,QAAQ;AACpC,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,4BAA4B,UAAU,SAAS;AAC/D,QAAM,gBAAgB,KAAK,IAAI,UAAU,QAAQ,UAAU,IAAI;AAC/D,QAAM,cAAc,KAAK,IAAI,UAAU,QAAQ,UAAU,IAAI;AAE7D,WAAS,aAAa,GAAG,aAAa,KAAK,SAAS,QAAQ,cAAc,GAAG;AAC3E,UAAM,QAAQ,KAAK,SAAS,UAAU;AACtC,UAAM,eAAe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