@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,828 @@
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/formatting-commands.ts
21
+ var formatting_commands_exports = {};
22
+ __export(formatting_commands_exports, {
23
+ applyFormattingOperationToDocument: () => applyFormattingOperationToDocument,
24
+ getFormattingStateFromRenderSnapshot: () => getFormattingStateFromRenderSnapshot,
25
+ isMarkActive: () => isMarkActive,
26
+ makeSetAlignment: () => makeSetAlignment,
27
+ makeSetFontFamily: () => makeSetFontFamily,
28
+ makeSetFontSize: () => makeSetFontSize,
29
+ makeSetHighlight: () => makeSetHighlight,
30
+ makeSetTextColor: () => makeSetTextColor,
31
+ makeToggleAllCaps: () => makeToggleAllCaps,
32
+ makeToggleBold: () => makeToggleBold,
33
+ makeToggleItalic: () => makeToggleItalic,
34
+ makeToggleSmallCaps: () => makeToggleSmallCaps,
35
+ makeToggleStrikethrough: () => makeToggleStrikethrough,
36
+ makeToggleSubscript: () => makeToggleSubscript,
37
+ makeToggleSuperscript: () => makeToggleSuperscript,
38
+ makeToggleUnderline: () => makeToggleUnderline
39
+ });
40
+ module.exports = __toCommonJS(formatting_commands_exports);
41
+ var import_prosemirror_commands = require("prosemirror-commands");
42
+ function makeToggleBold(schema) {
43
+ return (0, import_prosemirror_commands.toggleMark)(schema.marks.bold);
44
+ }
45
+ function makeToggleItalic(schema) {
46
+ return (0, import_prosemirror_commands.toggleMark)(schema.marks.italic);
47
+ }
48
+ function makeToggleUnderline(schema) {
49
+ return (0, import_prosemirror_commands.toggleMark)(schema.marks.underline);
50
+ }
51
+ function makeToggleStrikethrough(schema) {
52
+ return (0, import_prosemirror_commands.toggleMark)(schema.marks.strikethrough);
53
+ }
54
+ function makeToggleSuperscript(schema) {
55
+ return (0, import_prosemirror_commands.toggleMark)(schema.marks.superscript);
56
+ }
57
+ function makeToggleSubscript(schema) {
58
+ return (0, import_prosemirror_commands.toggleMark)(schema.marks.subscript);
59
+ }
60
+ function makeToggleSmallCaps(schema) {
61
+ return (0, import_prosemirror_commands.toggleMark)(schema.marks.small_caps);
62
+ }
63
+ function makeToggleAllCaps(schema) {
64
+ return (0, import_prosemirror_commands.toggleMark)(schema.marks.all_caps);
65
+ }
66
+ function makeSetValueMark(markType, attrKey, value) {
67
+ return (state, dispatch) => {
68
+ const { from, to, empty } = state.selection;
69
+ if (empty) return false;
70
+ if (!dispatch) return true;
71
+ const tr = state.tr;
72
+ if (value === null) {
73
+ tr.removeMark(from, to, markType);
74
+ } else {
75
+ const mark = markType.create({ [attrKey]: value });
76
+ tr.addMark(from, to, mark);
77
+ }
78
+ dispatch(tr);
79
+ return true;
80
+ };
81
+ }
82
+ function makeSetFontFamily(schema, family) {
83
+ return makeSetValueMark(schema.marks.font_family, "family", family);
84
+ }
85
+ function makeSetFontSize(schema, size) {
86
+ return makeSetValueMark(schema.marks.font_size, "size", size);
87
+ }
88
+ function makeSetTextColor(schema, color) {
89
+ return makeSetValueMark(schema.marks.text_color, "color", color);
90
+ }
91
+ function makeSetHighlight(schema, color) {
92
+ return makeSetValueMark(schema.marks.highlight, "color", color);
93
+ }
94
+ function makeSetAlignment(schema, alignment) {
95
+ return (state, dispatch) => {
96
+ const { from, to } = state.selection;
97
+ if (!dispatch) return true;
98
+ const tr = state.tr;
99
+ let applied = false;
100
+ state.doc.nodesBetween(from, to, (node, pos) => {
101
+ if (node.type === schema.nodes.paragraph) {
102
+ tr.setNodeMarkup(pos, void 0, { ...node.attrs, alignment });
103
+ applied = true;
104
+ }
105
+ });
106
+ if (!applied) return false;
107
+ dispatch(tr);
108
+ return true;
109
+ };
110
+ }
111
+ function isMarkActive(schema, markName, state) {
112
+ const markType = schema.marks[markName];
113
+ if (!markType) return false;
114
+ const { from, to, empty } = state.selection;
115
+ if (empty) {
116
+ return Boolean(markType.isInSet(state.storedMarks ?? state.selection.$from.marks()));
117
+ }
118
+ let active = true;
119
+ state.doc.nodesBetween(from, to, (node) => {
120
+ if (node.isText && !markType.isInSet(node.marks)) {
121
+ active = false;
122
+ return false;
123
+ }
124
+ });
125
+ return active;
126
+ }
127
+ var DEFAULT_FORMATTING_STATE = {
128
+ bold: false,
129
+ italic: false,
130
+ underline: false,
131
+ strikethrough: false,
132
+ superscript: false,
133
+ subscript: false,
134
+ breadcrumb: []
135
+ };
136
+ var INDENT_STEP_TWIPS = 720;
137
+ function getFormattingStateFromRenderSnapshot(snapshot) {
138
+ const surface = snapshot.surface;
139
+ if (!surface) {
140
+ return { ...DEFAULT_FORMATTING_STATE };
141
+ }
142
+ const paragraphs = collectParagraphSurfaces(surface.blocks).filter(
143
+ (paragraph) => selectionTouchesRange(
144
+ snapshot.selection.anchor,
145
+ snapshot.selection.head,
146
+ paragraph.from,
147
+ paragraph.to
148
+ )
149
+ );
150
+ const textSegments = collectFormattingTextSegments(paragraphs, snapshot.selection);
151
+ return {
152
+ bold: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "bold")) : false,
153
+ italic: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "italic")) : false,
154
+ underline: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "underline")) : false,
155
+ strikethrough: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "strikethrough")) : false,
156
+ superscript: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "superscript")) : false,
157
+ subscript: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "subscript")) : false,
158
+ fontFamily: getConsistentValue(textSegments, (segment) => segment.markAttrs?.fontFamily),
159
+ fontSize: getConsistentValue(textSegments, (segment) => {
160
+ const size = segment.markAttrs?.fontSize;
161
+ return typeof size === "number" ? size / 2 : void 0;
162
+ }),
163
+ textColor: getConsistentValue(
164
+ textSegments,
165
+ (segment) => toPublicColor(segment.markAttrs?.textColor)
166
+ ),
167
+ highlightColor: getConsistentValue(
168
+ textSegments,
169
+ (segment) => toPublicColor(segment.markAttrs?.backgroundColor) ?? null,
170
+ {
171
+ emptyFallback: null
172
+ }
173
+ ),
174
+ alignment: getConsistentValue(
175
+ paragraphs,
176
+ (paragraph) => toPublicAlignment(paragraph.alignment)
177
+ ),
178
+ paragraphStyleId: getConsistentValue(paragraphs, (paragraph) => paragraph.styleId),
179
+ breadcrumb: getSelectionBreadcrumb(surface.blocks, snapshot.selection)
180
+ };
181
+ }
182
+ function getSelectionBreadcrumb(blocks, selection) {
183
+ const paths = collectSelectionBreadcrumbPaths(blocks, selection);
184
+ if (paths.length === 0) {
185
+ return [];
186
+ }
187
+ let commonLength = paths[0]?.length ?? 0;
188
+ for (let pathIndex = 1; pathIndex < paths.length; pathIndex += 1) {
189
+ const currentPath = paths[pathIndex] ?? [];
190
+ commonLength = Math.min(commonLength, currentPath.length);
191
+ let compareIndex = 0;
192
+ while (compareIndex < commonLength && breadcrumbItemsEqual(paths[0][compareIndex], currentPath[compareIndex])) {
193
+ compareIndex += 1;
194
+ }
195
+ commonLength = compareIndex;
196
+ }
197
+ return paths[0].slice(0, commonLength);
198
+ }
199
+ function collectSelectionBreadcrumbPaths(blocks, selection, path = [], output = []) {
200
+ for (let blockIndex = 0; blockIndex < blocks.length; blockIndex += 1) {
201
+ const block = blocks[blockIndex];
202
+ if (!block) {
203
+ continue;
204
+ }
205
+ if (!selectionTouchesRange(
206
+ selection.anchor,
207
+ selection.head,
208
+ block.from,
209
+ block.to
210
+ )) {
211
+ continue;
212
+ }
213
+ if (block.kind === "paragraph") {
214
+ output.push([
215
+ ...path,
216
+ {
217
+ kind: "paragraph",
218
+ label: block.styleId ? `Paragraph (${block.styleId})` : "Paragraph",
219
+ from: block.from,
220
+ to: block.to
221
+ }
222
+ ]);
223
+ continue;
224
+ }
225
+ if (block.kind === "opaque_block") {
226
+ output.push([
227
+ ...path,
228
+ {
229
+ kind: "opaque_block",
230
+ label: block.label,
231
+ from: block.from,
232
+ to: block.to
233
+ }
234
+ ]);
235
+ continue;
236
+ }
237
+ if (block.kind === "sdt_block") {
238
+ collectSelectionBreadcrumbPaths(
239
+ block.children,
240
+ selection,
241
+ [
242
+ ...path,
243
+ {
244
+ kind: "sdt_block",
245
+ label: block.alias ?? block.tag ?? block.sdtType ?? "Content control",
246
+ from: block.from,
247
+ to: block.to
248
+ }
249
+ ],
250
+ output
251
+ );
252
+ continue;
253
+ }
254
+ if (block.kind === "table") {
255
+ const tablePath = [
256
+ ...path,
257
+ {
258
+ kind: "table",
259
+ label: block.styleId ? `Table (${block.styleId})` : "Table",
260
+ from: block.from,
261
+ to: block.to
262
+ }
263
+ ];
264
+ for (let rowIndex = 0; rowIndex < block.rows.length; rowIndex += 1) {
265
+ const row = block.rows[rowIndex];
266
+ if (!row) {
267
+ continue;
268
+ }
269
+ const rowRange = getTableRowRange(block, row);
270
+ if (!selectionTouchesRange(
271
+ selection.anchor,
272
+ selection.head,
273
+ rowRange.from,
274
+ rowRange.to
275
+ )) {
276
+ continue;
277
+ }
278
+ const rowPath = [
279
+ ...tablePath,
280
+ {
281
+ kind: "table_row",
282
+ label: `Row ${rowIndex + 1}`,
283
+ from: rowRange.from,
284
+ to: rowRange.to
285
+ }
286
+ ];
287
+ for (let cellIndex = 0; cellIndex < row.cells.length; cellIndex += 1) {
288
+ const cell = row.cells[cellIndex];
289
+ if (!cell) {
290
+ continue;
291
+ }
292
+ const cellRange = getTableCellRange(block, cell);
293
+ if (!selectionTouchesRange(
294
+ selection.anchor,
295
+ selection.head,
296
+ cellRange.from,
297
+ cellRange.to
298
+ )) {
299
+ continue;
300
+ }
301
+ collectSelectionBreadcrumbPaths(
302
+ cell.content,
303
+ selection,
304
+ [
305
+ ...rowPath,
306
+ {
307
+ kind: "table_cell",
308
+ label: `Cell ${cellIndex + 1}`,
309
+ from: cellRange.from,
310
+ to: cellRange.to
311
+ }
312
+ ],
313
+ output
314
+ );
315
+ }
316
+ }
317
+ }
318
+ }
319
+ return output;
320
+ }
321
+ function getTableRowRange(table, row) {
322
+ let from = Number.POSITIVE_INFINITY;
323
+ let to = Number.NEGATIVE_INFINITY;
324
+ for (const cell of row.cells) {
325
+ const range = getTableCellRange(table, cell);
326
+ from = Math.min(from, range.from);
327
+ to = Math.max(to, range.to);
328
+ }
329
+ return Number.isFinite(from) && Number.isFinite(to) ? { from, to } : { from: table.from, to: table.to };
330
+ }
331
+ function getTableCellRange(table, cell) {
332
+ if (cell.content.length === 0) {
333
+ return { from: table.from, to: table.to };
334
+ }
335
+ let from = Number.POSITIVE_INFINITY;
336
+ let to = Number.NEGATIVE_INFINITY;
337
+ for (const child of cell.content) {
338
+ from = Math.min(from, child.from);
339
+ to = Math.max(to, child.to);
340
+ }
341
+ return Number.isFinite(from) && Number.isFinite(to) ? { from, to } : { from: table.from, to: table.to };
342
+ }
343
+ function breadcrumbItemsEqual(left, right) {
344
+ return left.kind === right.kind && left.label === right.label && left.from === right.from && left.to === right.to;
345
+ }
346
+ function applyFormattingOperationToDocument(document, snapshot, operation) {
347
+ const surface = snapshot.surface;
348
+ if (!surface) {
349
+ return {
350
+ document,
351
+ selection: snapshot.selection,
352
+ changed: false
353
+ };
354
+ }
355
+ const nextDocument = structuredClone(document);
356
+ const root = nextDocument.content;
357
+ let changed = false;
358
+ const selectionFrom = Math.min(snapshot.selection.anchor, snapshot.selection.head);
359
+ const selectionTo = Math.max(snapshot.selection.anchor, snapshot.selection.head);
360
+ if (operation.type === "set-alignment" || operation.type === "indent" || operation.type === "outdent") {
361
+ visitParagraphBindings(root.children, surface.blocks, (paragraph, paragraphSurface) => {
362
+ if (!selectionTouchesRange(
363
+ snapshot.selection.anchor,
364
+ snapshot.selection.head,
365
+ paragraphSurface.from,
366
+ paragraphSurface.to
367
+ )) {
368
+ return;
369
+ }
370
+ const paragraphChanged = operation.type === "set-alignment" ? applyAlignment(paragraph, operation.alignment) : applyIndentation(paragraph, operation.type === "indent" ? 1 : -1);
371
+ changed = changed || paragraphChanged;
372
+ });
373
+ return {
374
+ document: changed ? nextDocument : document,
375
+ selection: snapshot.selection,
376
+ changed
377
+ };
378
+ }
379
+ if (selectionFrom === selectionTo) {
380
+ return {
381
+ document,
382
+ selection: snapshot.selection,
383
+ changed: false
384
+ };
385
+ }
386
+ const nextMarks = resolveMarkUpdater(snapshot, operation);
387
+ visitParagraphBindings(root.children, surface.blocks, (paragraph, paragraphSurface) => {
388
+ if (!rangesOverlap(
389
+ selectionFrom,
390
+ selectionTo,
391
+ paragraphSurface.from,
392
+ paragraphSurface.to
393
+ )) {
394
+ return;
395
+ }
396
+ const transformed = transformInlineNodes(
397
+ paragraph.children,
398
+ paragraphSurface.from,
399
+ selectionFrom,
400
+ selectionTo,
401
+ nextMarks
402
+ );
403
+ if (!transformed.changed) {
404
+ return;
405
+ }
406
+ paragraph.children = transformed.nodes;
407
+ changed = true;
408
+ });
409
+ return {
410
+ document: changed ? nextDocument : document,
411
+ selection: snapshot.selection,
412
+ changed
413
+ };
414
+ }
415
+ function resolveMarkUpdater(snapshot, operation) {
416
+ const formatting = getFormattingStateFromRenderSnapshot(snapshot);
417
+ switch (operation.type) {
418
+ case "toggle":
419
+ return (marks) => toggleMarks(marks, operation.mark, !formatting[operation.mark]);
420
+ case "set-font-family":
421
+ return (marks) => setMarkValue(marks, "fontFamily", sanitizeFontFamily(operation.fontFamily));
422
+ case "set-font-size":
423
+ return (marks) => setMarkValue(marks, "fontSize", sanitizeFontSize(operation.size));
424
+ case "set-text-color":
425
+ return (marks) => setMarkValue(marks, "textColor", sanitizeColor(operation.color));
426
+ case "set-highlight-color":
427
+ return (marks) => setMarkValue(marks, "backgroundColor", sanitizeColor(operation.color));
428
+ }
429
+ }
430
+ function applyAlignment(paragraph, alignment) {
431
+ const nextAlignment = alignment === "justify" ? "both" : alignment;
432
+ if (paragraph.alignment === nextAlignment) {
433
+ return false;
434
+ }
435
+ paragraph.alignment = nextAlignment;
436
+ return true;
437
+ }
438
+ function applyIndentation(paragraph, delta) {
439
+ if (paragraph.numbering) {
440
+ const nextLevel = clamp(paragraph.numbering.level + delta, 0, 8);
441
+ if (nextLevel === paragraph.numbering.level) {
442
+ return false;
443
+ }
444
+ paragraph.numbering = {
445
+ ...paragraph.numbering,
446
+ level: nextLevel
447
+ };
448
+ return true;
449
+ }
450
+ const currentLeft = paragraph.indentation?.left ?? 0;
451
+ const nextLeft = Math.max(0, currentLeft + delta * INDENT_STEP_TWIPS);
452
+ if (nextLeft === currentLeft) {
453
+ return false;
454
+ }
455
+ const nextIndentation = {
456
+ ...paragraph.indentation ?? {}
457
+ };
458
+ if (nextLeft > 0) {
459
+ nextIndentation.left = nextLeft;
460
+ paragraph.indentation = nextIndentation;
461
+ } else if (paragraph.indentation) {
462
+ delete nextIndentation.left;
463
+ paragraph.indentation = Object.keys(nextIndentation).length > 0 ? nextIndentation : void 0;
464
+ }
465
+ return true;
466
+ }
467
+ function collectParagraphSurfaces(blocks, output = []) {
468
+ for (const block of blocks) {
469
+ if (block.kind === "paragraph") {
470
+ output.push(block);
471
+ continue;
472
+ }
473
+ if (block.kind === "table") {
474
+ for (const row of block.rows) {
475
+ for (const cell of row.cells) {
476
+ collectParagraphSurfaces(cell.content, output);
477
+ }
478
+ }
479
+ continue;
480
+ }
481
+ if (block.kind === "sdt_block") {
482
+ collectParagraphSurfaces(block.children, output);
483
+ }
484
+ }
485
+ return output;
486
+ }
487
+ function collectFormattingTextSegments(paragraphs, selection) {
488
+ const caret = selection.anchor;
489
+ const isCollapsed = selection.isCollapsed;
490
+ const selectionFrom = Math.min(selection.anchor, selection.head);
491
+ const selectionTo = Math.max(selection.anchor, selection.head);
492
+ const segments = [];
493
+ for (const paragraph of paragraphs) {
494
+ for (const segment of paragraph.segments) {
495
+ if (segment.kind !== "text") {
496
+ continue;
497
+ }
498
+ if (isCollapsed ? segmentContainsCaret(segment, caret) : rangesOverlap(selectionFrom, selectionTo, segment.from, segment.to)) {
499
+ segments.push(segment);
500
+ }
501
+ }
502
+ }
503
+ if (!isCollapsed || segments.length > 0) {
504
+ return segments;
505
+ }
506
+ for (const paragraph of paragraphs) {
507
+ const fallback = paragraph.segments.find(
508
+ (segment) => segment.kind === "text" && segment.to === caret
509
+ );
510
+ if (fallback) {
511
+ return [fallback];
512
+ }
513
+ }
514
+ return [];
515
+ }
516
+ function segmentContainsCaret(segment, caret) {
517
+ return segment.from <= caret && (caret < segment.to || segment.to === caret && segment.to > segment.from);
518
+ }
519
+ function segmentHasMark(segment, mark) {
520
+ const marks = segment.marks ?? [];
521
+ if (mark === "superscript") {
522
+ return marks.includes("superscript");
523
+ }
524
+ if (mark === "subscript") {
525
+ return marks.includes("subscript");
526
+ }
527
+ return marks.includes(mark);
528
+ }
529
+ function getConsistentValue(items, getter, options = {}) {
530
+ if (items.length === 0) {
531
+ return options.emptyFallback;
532
+ }
533
+ let value = void 0;
534
+ let initialized = false;
535
+ for (const item of items) {
536
+ const next = getter(item);
537
+ if (!initialized) {
538
+ value = next;
539
+ initialized = true;
540
+ continue;
541
+ }
542
+ if (next !== value) {
543
+ return void 0;
544
+ }
545
+ }
546
+ return value;
547
+ }
548
+ function visitParagraphBindings(blocks, surfaceBlocks, visitor) {
549
+ for (let index = 0; index < Math.min(blocks.length, surfaceBlocks.length); index += 1) {
550
+ const block = blocks[index];
551
+ const surface = surfaceBlocks[index];
552
+ if (!block || !surface) {
553
+ continue;
554
+ }
555
+ if (block.type === "paragraph" && surface.kind === "paragraph") {
556
+ visitor(block, surface);
557
+ continue;
558
+ }
559
+ if (block.type === "table" && surface.kind === "table") {
560
+ for (let rowIndex = 0; rowIndex < Math.min(block.rows.length, surface.rows.length); rowIndex += 1) {
561
+ const row = block.rows[rowIndex];
562
+ const surfaceRow = surface.rows[rowIndex];
563
+ if (!row || !surfaceRow) {
564
+ continue;
565
+ }
566
+ for (let cellIndex = 0; cellIndex < Math.min(row.cells.length, surfaceRow.cells.length); cellIndex += 1) {
567
+ const cell = row.cells[cellIndex];
568
+ const surfaceCell = surfaceRow.cells[cellIndex];
569
+ if (!cell || !surfaceCell) {
570
+ continue;
571
+ }
572
+ visitParagraphBindings(cell.children, surfaceCell.content, visitor);
573
+ }
574
+ }
575
+ continue;
576
+ }
577
+ if (block.type === "sdt" && surface.kind === "sdt_block") {
578
+ visitParagraphBindings(block.children, surface.children, visitor);
579
+ }
580
+ }
581
+ }
582
+ function transformInlineNodes(nodes, start, selectionFrom, selectionTo, updateMarks) {
583
+ let changed = false;
584
+ let position = start;
585
+ const nextNodes = [];
586
+ for (const node of nodes) {
587
+ if (node.type === "text") {
588
+ const transformed = transformTextNode(
589
+ node,
590
+ position,
591
+ selectionFrom,
592
+ selectionTo,
593
+ updateMarks
594
+ );
595
+ nextNodes.push(...transformed.nodes);
596
+ position = transformed.nextPosition;
597
+ changed = changed || transformed.changed;
598
+ continue;
599
+ }
600
+ if (node.type === "hyperlink") {
601
+ const transformed = transformInlineNodes(
602
+ node.children,
603
+ position,
604
+ selectionFrom,
605
+ selectionTo,
606
+ updateMarks
607
+ );
608
+ nextNodes.push(
609
+ transformed.changed ? {
610
+ ...node,
611
+ children: transformed.nodes
612
+ } : node
613
+ );
614
+ position = transformed.nextPosition;
615
+ changed = changed || transformed.changed;
616
+ continue;
617
+ }
618
+ nextNodes.push(node);
619
+ position += inlineNodeLength(node);
620
+ }
621
+ return {
622
+ nodes: nextNodes,
623
+ changed,
624
+ nextPosition: position
625
+ };
626
+ }
627
+ function transformTextNode(node, start, selectionFrom, selectionTo, updateMarks) {
628
+ const characters = Array.from(node.text);
629
+ const end = start + characters.length;
630
+ const overlapFrom = Math.max(selectionFrom, start);
631
+ const overlapTo = Math.min(selectionTo, end);
632
+ if (overlapFrom >= overlapTo) {
633
+ return {
634
+ nodes: [node],
635
+ changed: false,
636
+ nextPosition: end
637
+ };
638
+ }
639
+ const localFrom = overlapFrom - start;
640
+ const localTo = overlapTo - start;
641
+ const nextNodes = [];
642
+ if (localFrom > 0) {
643
+ nextNodes.push(createTextNode(characters.slice(0, localFrom).join(""), node.marks));
644
+ }
645
+ const transformedMarks = updateMarks(node.marks);
646
+ nextNodes.push(
647
+ createTextNode(characters.slice(localFrom, localTo).join(""), transformedMarks)
648
+ );
649
+ if (localTo < characters.length) {
650
+ nextNodes.push(createTextNode(characters.slice(localTo).join(""), node.marks));
651
+ }
652
+ return {
653
+ nodes: nextNodes.filter((candidate) => candidate.text.length > 0),
654
+ changed: !marksEqual(node.marks, transformedMarks) || localFrom > 0 || localTo < characters.length,
655
+ nextPosition: end
656
+ };
657
+ }
658
+ function createTextNode(text, marks) {
659
+ return {
660
+ type: "text",
661
+ text,
662
+ ...marks && marks.length > 0 ? { marks: cloneMarks(marks) } : {}
663
+ };
664
+ }
665
+ function toggleMarks(marks, mark, enabled) {
666
+ const nextMarks = cloneMarks(marks);
667
+ if (mark === "superscript" || mark === "subscript") {
668
+ const filtered2 = nextMarks.filter((candidate) => candidate.type !== "position");
669
+ if (enabled) {
670
+ filtered2.push({
671
+ type: "position",
672
+ val: mark === "superscript" ? 1 : -1
673
+ });
674
+ }
675
+ return filtered2.length > 0 ? filtered2 : void 0;
676
+ }
677
+ const filtered = nextMarks.filter((candidate) => candidate.type !== mark);
678
+ if (enabled) {
679
+ filtered.push({ type: mark });
680
+ }
681
+ return filtered.length > 0 ? filtered : void 0;
682
+ }
683
+ function setMarkValue(marks, markType, value) {
684
+ const nextMarks = cloneMarks(marks).filter((candidate) => {
685
+ if (markType === "backgroundColor") {
686
+ return candidate.type !== "backgroundColor" && candidate.type !== "highlight";
687
+ }
688
+ return candidate.type !== markType;
689
+ });
690
+ if (value !== null) {
691
+ switch (markType) {
692
+ case "fontFamily":
693
+ nextMarks.push({ type: "fontFamily", val: value });
694
+ break;
695
+ case "fontSize":
696
+ nextMarks.push({ type: "fontSize", val: value });
697
+ break;
698
+ case "textColor":
699
+ nextMarks.push({ type: "textColor", color: value });
700
+ break;
701
+ case "backgroundColor":
702
+ nextMarks.push({ type: "backgroundColor", color: value });
703
+ break;
704
+ }
705
+ }
706
+ return nextMarks.length > 0 ? nextMarks : void 0;
707
+ }
708
+ function cloneMarks(marks) {
709
+ return marks ? marks.map((mark) => ({ ...mark })) : [];
710
+ }
711
+ function marksEqual(left, right) {
712
+ if (!left?.length && !right?.length) {
713
+ return true;
714
+ }
715
+ if (!left || !right || left.length !== right.length) {
716
+ return false;
717
+ }
718
+ return left.every((mark, index) => JSON.stringify(mark) === JSON.stringify(right[index]));
719
+ }
720
+ function inlineNodeLength(node) {
721
+ switch (node.type) {
722
+ case "text":
723
+ return Array.from(node.text).length;
724
+ case "hyperlink":
725
+ return node.children.reduce(
726
+ (total, child) => total + inlineNodeLength(child),
727
+ 0
728
+ );
729
+ case "hard_break":
730
+ case "column_break":
731
+ case "tab":
732
+ case "symbol":
733
+ case "image":
734
+ case "opaque_inline":
735
+ case "footnote_ref":
736
+ case "chart_preview":
737
+ case "smartart_preview":
738
+ case "shape":
739
+ case "wordart":
740
+ case "vml_shape":
741
+ return 1;
742
+ case "field":
743
+ return node.children.reduce(
744
+ (total, child) => total + inlineNodeLength(child),
745
+ 0
746
+ );
747
+ case "bookmark_start":
748
+ case "bookmark_end":
749
+ return 0;
750
+ }
751
+ }
752
+ function toPublicAlignment(alignment) {
753
+ switch (alignment) {
754
+ case "both":
755
+ case "distribute":
756
+ return "justify";
757
+ case "left":
758
+ case "center":
759
+ case "right":
760
+ return alignment;
761
+ default:
762
+ return void 0;
763
+ }
764
+ }
765
+ function toPublicColor(color) {
766
+ if (!color) {
767
+ return void 0;
768
+ }
769
+ return /^[0-9A-F]{3,8}$/iu.test(color) ? `#${color.toUpperCase()}` : color;
770
+ }
771
+ function sanitizeFontFamily(fontFamily) {
772
+ const normalized = fontFamily?.trim();
773
+ return normalized ? normalized : null;
774
+ }
775
+ function sanitizeFontSize(size) {
776
+ if (typeof size !== "number" || !Number.isFinite(size) || size <= 0) {
777
+ return null;
778
+ }
779
+ return Math.round(size * 2);
780
+ }
781
+ function sanitizeColor(color) {
782
+ const normalized = color?.trim();
783
+ if (!normalized) {
784
+ return null;
785
+ }
786
+ const raw = normalized.startsWith("#") ? normalized.slice(1) : normalized;
787
+ return /^[0-9A-F]{3,8}$/iu.test(raw) ? raw.toUpperCase() : null;
788
+ }
789
+ function selectionTouchesRange(anchor, head, rangeFrom, rangeTo) {
790
+ const selectionFrom = Math.min(anchor, head);
791
+ const selectionTo = Math.max(anchor, head);
792
+ if (selectionFrom === selectionTo) {
793
+ return selectionFrom >= rangeFrom && selectionFrom <= rangeTo;
794
+ }
795
+ return rangesOverlap(selectionFrom, selectionTo, rangeFrom, rangeTo);
796
+ }
797
+ function rangesOverlap(leftFrom, leftTo, rightFrom, rightTo) {
798
+ if (leftFrom === leftTo) {
799
+ return leftFrom >= rightFrom && leftFrom <= rightTo;
800
+ }
801
+ if (rightFrom === rightTo) {
802
+ return rightFrom >= leftFrom && rightFrom <= leftTo;
803
+ }
804
+ return leftFrom < rightTo && leftTo > rightFrom;
805
+ }
806
+ function clamp(value, min, max) {
807
+ return Math.min(max, Math.max(min, value));
808
+ }
809
+ // Annotate the CommonJS export names for ESM import in node:
810
+ 0 && (module.exports = {
811
+ applyFormattingOperationToDocument,
812
+ getFormattingStateFromRenderSnapshot,
813
+ isMarkActive,
814
+ makeSetAlignment,
815
+ makeSetFontFamily,
816
+ makeSetFontSize,
817
+ makeSetHighlight,
818
+ makeSetTextColor,
819
+ makeToggleAllCaps,
820
+ makeToggleBold,
821
+ makeToggleItalic,
822
+ makeToggleSmallCaps,
823
+ makeToggleStrikethrough,
824
+ makeToggleSubscript,
825
+ makeToggleSuperscript,
826
+ makeToggleUnderline
827
+ });
828
+ //# sourceMappingURL=formatting-commands.cjs.map