@notectl/core 2.0.0 → 2.0.1

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 (292) hide show
  1. package/dist/chunks/{AttrRegistry-B2AGfTE0.mjs → AttrRegistry-Ckj9eCHj.mjs} +2 -2
  2. package/dist/chunks/{AttrRegistry-B2AGfTE0.mjs.map → AttrRegistry-Ckj9eCHj.mjs.map} +1 -1
  3. package/dist/chunks/AttributedMarkCommands-x7h4Xy7V.mjs +2 -0
  4. package/dist/chunks/AttributedMarkCommands-x7h4Xy7V.mjs.map +1 -0
  5. package/dist/chunks/BlockInsertion-zPxm6oa_.mjs +2 -0
  6. package/dist/chunks/BlockInsertion-zPxm6oa_.mjs.map +1 -0
  7. package/dist/chunks/{ColorPickerPopup-DRzFvt7o.mjs → ColorPickerPopup-CDUvkgcK.mjs} +2 -2
  8. package/dist/chunks/ColorPickerPopup-CDUvkgcK.mjs.map +1 -0
  9. package/dist/chunks/Commands-DwXBBVGR.mjs +2 -0
  10. package/dist/chunks/Commands-DwXBBVGR.mjs.map +1 -0
  11. package/dist/chunks/Document-HC8s50qJ.mjs +2 -0
  12. package/dist/chunks/Document-HC8s50qJ.mjs.map +1 -0
  13. package/dist/chunks/DocumentParser-w70-Axud.mjs +2 -0
  14. package/dist/chunks/DocumentParser-w70-Axud.mjs.map +1 -0
  15. package/dist/chunks/DomUtils-CznMAZZg.mjs +2 -0
  16. package/dist/chunks/DomUtils-CznMAZZg.mjs.map +1 -0
  17. package/dist/chunks/HTMLUtils-Cxy99Ak2.mjs +2 -0
  18. package/dist/chunks/HTMLUtils-Cxy99Ak2.mjs.map +1 -0
  19. package/dist/chunks/HeadingPlugin-B-LF-AMM.mjs +2 -0
  20. package/dist/chunks/HeadingPlugin-B-LF-AMM.mjs.map +1 -0
  21. package/dist/chunks/MarkCommands-CTuVDqnn.mjs +2 -0
  22. package/dist/chunks/MarkCommands-CTuVDqnn.mjs.map +1 -0
  23. package/dist/chunks/{NavigationQueries-ogQuObz7.mjs → NavigationQueries-DCOv4Ca5.mjs} +2 -2
  24. package/dist/chunks/{NavigationQueries-ogQuObz7.mjs.map → NavigationQueries-DCOv4Ca5.mjs.map} +1 -1
  25. package/dist/chunks/NotectlEditor-DBBJkPCW.mjs +3 -0
  26. package/dist/chunks/NotectlEditor-DBBJkPCW.mjs.map +1 -0
  27. package/dist/chunks/PluginHelpers-CdPR0MuT.mjs +2 -0
  28. package/dist/chunks/PluginHelpers-CdPR0MuT.mjs.map +1 -0
  29. package/dist/chunks/PopupManager-Du3dYnsJ.mjs +2 -0
  30. package/dist/chunks/{PopupManager-BM8IT6M7.mjs.map → PopupManager-Du3dYnsJ.mjs.map} +1 -1
  31. package/dist/chunks/PrintTypes-DukwDSWS.mjs +2 -0
  32. package/dist/chunks/{PrintTypes-ehbL7ipA.mjs.map → PrintTypes-DukwDSWS.mjs.map} +1 -1
  33. package/dist/chunks/{RangeIterator-CNI6smOg.mjs → RangeIterator-CprUbOWv.mjs} +2 -2
  34. package/dist/chunks/{RangeIterator-CNI6smOg.mjs.map → RangeIterator-CprUbOWv.mjs.map} +1 -1
  35. package/dist/chunks/{Selection-6-W6Flxc.mjs → Selection-DhbizDM4.mjs} +2 -2
  36. package/dist/chunks/{Selection-6-W6Flxc.mjs.map → Selection-DhbizDM4.mjs.map} +1 -1
  37. package/dist/chunks/{SelectionTransactions-q71GEzgE.mjs → SelectionTransactions-DB3YDIEa.mjs} +2 -2
  38. package/dist/chunks/{SelectionTransactions-q71GEzgE.mjs.map → SelectionTransactions-DB3YDIEa.mjs.map} +1 -1
  39. package/dist/chunks/{TextDirectionLocale-DB_aqrMg.mjs → TextDirectionLocale-BraFI9JF.mjs} +2 -2
  40. package/dist/chunks/{TextDirectionLocale-DB_aqrMg.mjs.map → TextDirectionLocale-BraFI9JF.mjs.map} +1 -1
  41. package/dist/chunks/XmlPatterns-DxQXGjP8.mjs +2 -0
  42. package/dist/chunks/XmlPatterns-DxQXGjP8.mjs.map +1 -0
  43. package/dist/chunks/ar-b6VdnxAs.mjs +2 -0
  44. package/dist/chunks/ar-b6VdnxAs.mjs.map +1 -0
  45. package/dist/chunks/de-fXvs5vQT.mjs +2 -0
  46. package/dist/chunks/de-fXvs5vQT.mjs.map +1 -0
  47. package/dist/chunks/es-BTqy_aQ4.mjs +2 -0
  48. package/dist/chunks/es-BTqy_aQ4.mjs.map +1 -0
  49. package/dist/chunks/fr-VdiCNF4J.mjs +2 -0
  50. package/dist/chunks/fr-VdiCNF4J.mjs.map +1 -0
  51. package/dist/chunks/hi-BdtVhAzs.mjs +2 -0
  52. package/dist/chunks/hi-BdtVhAzs.mjs.map +1 -0
  53. package/dist/chunks/index-CVwf0cdH.mjs +2 -0
  54. package/dist/chunks/index-CVwf0cdH.mjs.map +1 -0
  55. package/dist/chunks/index-D3BZFsAD.mjs +2 -0
  56. package/dist/chunks/index-D3BZFsAD.mjs.map +1 -0
  57. package/dist/chunks/pt-K0BUlM9X.mjs +2 -0
  58. package/dist/chunks/pt-K0BUlM9X.mjs.map +1 -0
  59. package/dist/chunks/ru-Tzd5N37W.mjs +2 -0
  60. package/dist/chunks/ru-Tzd5N37W.mjs.map +1 -0
  61. package/dist/chunks/zh-Di3WqY4_.mjs +2 -0
  62. package/dist/chunks/zh-Di3WqY4_.mjs.map +1 -0
  63. package/dist/{input → commands}/BlockInsertion.d.ts +14 -1
  64. package/dist/commands/BlockInsertion.d.ts.map +1 -0
  65. package/dist/commands/CommandHelpers.d.ts +4 -0
  66. package/dist/commands/CommandHelpers.d.ts.map +1 -1
  67. package/dist/commands/Commands.d.ts.map +1 -1
  68. package/dist/commands/GapCursorCommands.d.ts.map +1 -1
  69. package/dist/commands/NodeSelectionCommands.d.ts.map +1 -1
  70. package/dist/commands/PasteCommand.d.ts.map +1 -1
  71. package/dist/editor/EditorThemeController.d.ts.map +1 -1
  72. package/dist/editor/NotectlEditor.d.ts.map +1 -1
  73. package/dist/editor/styles/code-block.d.ts +1 -1
  74. package/dist/editor/styles/code-block.d.ts.map +1 -1
  75. package/dist/editor/theme/ThemeEngine.d.ts.map +1 -1
  76. package/dist/editor/theme/ThemeTokens.d.ts +17 -1
  77. package/dist/editor/theme/ThemeTokens.d.ts.map +1 -1
  78. package/dist/full.d.ts +1 -0
  79. package/dist/full.d.ts.map +1 -1
  80. package/dist/full.mjs +1 -1
  81. package/dist/html.mjs +1 -1
  82. package/dist/index.d.ts +1 -1
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/input/InputManager.d.ts +2 -0
  85. package/dist/input/InputManager.d.ts.map +1 -1
  86. package/dist/input/InternalClipboard.d.ts +2 -22
  87. package/dist/input/InternalClipboard.d.ts.map +1 -1
  88. package/dist/input/PasteHandler.d.ts +7 -0
  89. package/dist/input/PasteHandler.d.ts.map +1 -1
  90. package/dist/model/Document.d.ts.map +1 -1
  91. package/dist/model/HTMLUtils.d.ts +2 -0
  92. package/dist/model/HTMLUtils.d.ts.map +1 -1
  93. package/dist/model/PasteInterceptor.d.ts +21 -0
  94. package/dist/model/PasteInterceptor.d.ts.map +1 -0
  95. package/dist/model/RichBlockData.d.ts +24 -0
  96. package/dist/model/RichBlockData.d.ts.map +1 -0
  97. package/dist/model/SchemaRegistry.d.ts +2 -0
  98. package/dist/model/SchemaRegistry.d.ts.map +1 -1
  99. package/dist/notectl-core.mjs +1 -1
  100. package/dist/notectl-core.umd.js +1 -1
  101. package/dist/notectl-core.umd.js.map +1 -1
  102. package/dist/plugins/Plugin.d.ts +3 -0
  103. package/dist/plugins/Plugin.d.ts.map +1 -1
  104. package/dist/plugins/PluginManager.d.ts +7 -0
  105. package/dist/plugins/PluginManager.d.ts.map +1 -1
  106. package/dist/plugins/alignment/AlignmentPlugin.d.ts.map +1 -1
  107. package/dist/plugins/alignment.mjs +1 -1
  108. package/dist/plugins/alignment.mjs.map +1 -1
  109. package/dist/plugins/blockquote/BlockquoteKeyboardHandlers.d.ts.map +1 -1
  110. package/dist/plugins/blockquote/BlockquotePlugin.d.ts.map +1 -1
  111. package/dist/plugins/blockquote.mjs +1 -1
  112. package/dist/plugins/blockquote.mjs.map +1 -1
  113. package/dist/plugins/caret-navigation/CaretNavigationPlugin.d.ts.map +1 -1
  114. package/dist/plugins/caret-navigation.mjs +1 -1
  115. package/dist/plugins/code-block/CodeBlockKeyboardHandlers.d.ts.map +1 -1
  116. package/dist/plugins/code-block/CodeBlockPlugin.d.ts +5 -0
  117. package/dist/plugins/code-block/CodeBlockPlugin.d.ts.map +1 -1
  118. package/dist/plugins/code-block/CodeBlockTypes.d.ts +7 -0
  119. package/dist/plugins/code-block/CodeBlockTypes.d.ts.map +1 -1
  120. package/dist/plugins/code-block/highlighter/RegexTokenizer.d.ts +14 -0
  121. package/dist/plugins/code-block/highlighter/RegexTokenizer.d.ts.map +1 -0
  122. package/dist/plugins/code-block/highlighter/TokenizerTypes.d.ts +15 -0
  123. package/dist/plugins/code-block/highlighter/TokenizerTypes.d.ts.map +1 -0
  124. package/dist/plugins/code-block/highlighter/languages/index.d.ts +3 -0
  125. package/dist/plugins/code-block/highlighter/languages/index.d.ts.map +1 -0
  126. package/dist/plugins/code-block/highlighter/languages/json.d.ts +3 -0
  127. package/dist/plugins/code-block/highlighter/languages/json.d.ts.map +1 -0
  128. package/dist/plugins/code-block/highlighter/languages/xml.d.ts +3 -0
  129. package/dist/plugins/code-block/highlighter/languages/xml.d.ts.map +1 -0
  130. package/dist/plugins/code-block/index.d.ts +5 -1
  131. package/dist/plugins/code-block/index.d.ts.map +1 -1
  132. package/dist/plugins/code-block.mjs +1 -1
  133. package/dist/plugins/code-block.mjs.map +1 -1
  134. package/dist/plugins/font/FontPlugin.d.ts.map +1 -1
  135. package/dist/plugins/font-size/FontSizePlugin.d.ts.map +1 -1
  136. package/dist/plugins/font-size.mjs +1 -1
  137. package/dist/plugins/font-size.mjs.map +1 -1
  138. package/dist/plugins/font.mjs +1 -1
  139. package/dist/plugins/font.mjs.map +1 -1
  140. package/dist/plugins/gap-cursor/GapCursorPlugin.d.ts.map +1 -1
  141. package/dist/plugins/gap-cursor.mjs +1 -1
  142. package/dist/plugins/hard-break.mjs +1 -1
  143. package/dist/plugins/heading/HeadingInputRules.d.ts.map +1 -1
  144. package/dist/plugins/heading/HeadingKeyboardHandlers.d.ts.map +1 -1
  145. package/dist/plugins/heading/HeadingPlugin.d.ts.map +1 -1
  146. package/dist/plugins/heading.mjs +1 -1
  147. package/dist/plugins/highlight/HighlightPlugin.d.ts.map +1 -1
  148. package/dist/plugins/highlight.mjs +1 -1
  149. package/dist/plugins/highlight.mjs.map +1 -1
  150. package/dist/plugins/horizontal-rule/HorizontalRulePlugin.d.ts.map +1 -1
  151. package/dist/plugins/horizontal-rule.mjs +1 -1
  152. package/dist/plugins/horizontal-rule.mjs.map +1 -1
  153. package/dist/plugins/image/ImagePlugin.d.ts +0 -1
  154. package/dist/plugins/image/ImagePlugin.d.ts.map +1 -1
  155. package/dist/plugins/image/ImagePopup.d.ts +11 -0
  156. package/dist/plugins/image/ImagePopup.d.ts.map +1 -0
  157. package/dist/plugins/image.mjs +1 -1
  158. package/dist/plugins/image.mjs.map +1 -1
  159. package/dist/plugins/link/LinkPlugin.d.ts.map +1 -1
  160. package/dist/plugins/link.mjs +1 -1
  161. package/dist/plugins/link.mjs.map +1 -1
  162. package/dist/plugins/list/ListPlugin.d.ts.map +1 -1
  163. package/dist/plugins/list.mjs +1 -1
  164. package/dist/plugins/list.mjs.map +1 -1
  165. package/dist/plugins/print/PrintPlugin.d.ts.map +1 -1
  166. package/dist/plugins/print.mjs +1 -1
  167. package/dist/plugins/print.mjs.map +1 -1
  168. package/dist/plugins/shared/ColorMarkOperations.d.ts +1 -2
  169. package/dist/plugins/shared/ColorMarkOperations.d.ts.map +1 -1
  170. package/dist/plugins/shared/ColorPickerPopup.d.ts +1 -8
  171. package/dist/plugins/shared/ColorPickerPopup.d.ts.map +1 -1
  172. package/dist/plugins/shared/PluginHelpers.d.ts +8 -0
  173. package/dist/plugins/shared/PluginHelpers.d.ts.map +1 -1
  174. package/dist/plugins/shared/XmlPatterns.d.ts +10 -0
  175. package/dist/plugins/shared/XmlPatterns.d.ts.map +1 -0
  176. package/dist/plugins/shared/index.d.ts +1 -0
  177. package/dist/plugins/shared/index.d.ts.map +1 -1
  178. package/dist/plugins/shared.mjs +1 -1
  179. package/dist/plugins/shared.mjs.map +1 -1
  180. package/dist/plugins/smart-paste/SmartPasteLocale.d.ts +7 -0
  181. package/dist/plugins/smart-paste/SmartPasteLocale.d.ts.map +1 -0
  182. package/dist/plugins/smart-paste/SmartPastePlugin.d.ts +19 -0
  183. package/dist/plugins/smart-paste/SmartPastePlugin.d.ts.map +1 -0
  184. package/dist/plugins/smart-paste/SmartPasteTypes.d.ts +24 -0
  185. package/dist/plugins/smart-paste/SmartPasteTypes.d.ts.map +1 -0
  186. package/dist/plugins/smart-paste/detectors/JsonDetector.d.ts +6 -0
  187. package/dist/plugins/smart-paste/detectors/JsonDetector.d.ts.map +1 -0
  188. package/dist/plugins/smart-paste/detectors/XmlDetector.d.ts +26 -0
  189. package/dist/plugins/smart-paste/detectors/XmlDetector.d.ts.map +1 -0
  190. package/dist/plugins/smart-paste/index.d.ts +7 -0
  191. package/dist/plugins/smart-paste/index.d.ts.map +1 -0
  192. package/dist/plugins/smart-paste/locales/ar.d.ts +4 -0
  193. package/dist/plugins/smart-paste/locales/ar.d.ts.map +1 -0
  194. package/dist/plugins/smart-paste/locales/de.d.ts +4 -0
  195. package/dist/plugins/smart-paste/locales/de.d.ts.map +1 -0
  196. package/dist/plugins/smart-paste/locales/es.d.ts +4 -0
  197. package/dist/plugins/smart-paste/locales/es.d.ts.map +1 -0
  198. package/dist/plugins/smart-paste/locales/fr.d.ts +4 -0
  199. package/dist/plugins/smart-paste/locales/fr.d.ts.map +1 -0
  200. package/dist/plugins/smart-paste/locales/hi.d.ts +4 -0
  201. package/dist/plugins/smart-paste/locales/hi.d.ts.map +1 -0
  202. package/dist/plugins/smart-paste/locales/pt.d.ts +4 -0
  203. package/dist/plugins/smart-paste/locales/pt.d.ts.map +1 -0
  204. package/dist/plugins/smart-paste/locales/ru.d.ts +4 -0
  205. package/dist/plugins/smart-paste/locales/ru.d.ts.map +1 -0
  206. package/dist/plugins/smart-paste/locales/zh.d.ts +4 -0
  207. package/dist/plugins/smart-paste/locales/zh.d.ts.map +1 -0
  208. package/dist/plugins/smart-paste.mjs +2 -0
  209. package/dist/plugins/smart-paste.mjs.map +1 -0
  210. package/dist/plugins/strikethrough/StrikethroughPlugin.d.ts.map +1 -1
  211. package/dist/plugins/strikethrough.mjs +1 -1
  212. package/dist/plugins/strikethrough.mjs.map +1 -1
  213. package/dist/plugins/super-sub/SuperSubPlugin.d.ts.map +1 -1
  214. package/dist/plugins/super-sub.mjs +1 -1
  215. package/dist/plugins/super-sub.mjs.map +1 -1
  216. package/dist/plugins/table/TableCommands.d.ts.map +1 -1
  217. package/dist/plugins/table/TableNavigation.d.ts.map +1 -1
  218. package/dist/plugins/table/TablePlugin.d.ts.map +1 -1
  219. package/dist/plugins/table/index.d.ts +1 -0
  220. package/dist/plugins/table/index.d.ts.map +1 -1
  221. package/dist/plugins/table.mjs +1 -1
  222. package/dist/plugins/table.mjs.map +1 -1
  223. package/dist/plugins/text-color/TextColorPlugin.d.ts.map +1 -1
  224. package/dist/plugins/text-color.mjs +1 -1
  225. package/dist/plugins/text-color.mjs.map +1 -1
  226. package/dist/plugins/text-direction/TextDirectionCorePlugin.d.ts.map +1 -1
  227. package/dist/plugins/text-direction/TextDirectionPlugin.d.ts.map +1 -1
  228. package/dist/plugins/text-direction-advanced.mjs +1 -1
  229. package/dist/plugins/text-direction-advanced.mjs.map +1 -1
  230. package/dist/plugins/text-direction.mjs +1 -1
  231. package/dist/plugins/text-direction.mjs.map +1 -1
  232. package/dist/plugins/text-formatting/TextFormattingPlugin.d.ts.map +1 -1
  233. package/dist/plugins/text-formatting.mjs +1 -1
  234. package/dist/plugins/text-formatting.mjs.map +1 -1
  235. package/dist/plugins/toolbar/ToolbarPlugin.d.ts.map +1 -1
  236. package/dist/plugins/toolbar.mjs +1 -1
  237. package/dist/plugins/toolbar.mjs.map +1 -1
  238. package/dist/presets/FullPreset.d.ts.map +1 -1
  239. package/dist/presets/PresetTypes.d.ts +2 -0
  240. package/dist/presets/PresetTypes.d.ts.map +1 -1
  241. package/dist/presets/full.mjs +1 -1
  242. package/dist/presets/full.mjs.map +1 -1
  243. package/dist/serialization/DocumentSerializer.d.ts.map +1 -1
  244. package/dist/state/InlineContentOps.d.ts.map +1 -1
  245. package/dist/state/StepInversion.d.ts +7 -0
  246. package/dist/state/StepInversion.d.ts.map +1 -0
  247. package/dist/state/Steps.d.ts +108 -0
  248. package/dist/state/Steps.d.ts.map +1 -0
  249. package/dist/state/Transaction.d.ts +5 -174
  250. package/dist/state/Transaction.d.ts.map +1 -1
  251. package/dist/state/TransactionBuilder.d.ts +69 -0
  252. package/dist/state/TransactionBuilder.d.ts.map +1 -0
  253. package/dist/test/TestUtils.d.ts.map +1 -1
  254. package/dist/view/CaretNavigation.d.ts.map +1 -1
  255. package/dist/view/DomUtils.d.ts +10 -1
  256. package/dist/view/DomUtils.d.ts.map +1 -1
  257. package/dist/view/EditorView.d.ts +2 -2
  258. package/dist/view/EditorView.d.ts.map +1 -1
  259. package/dist/view/ViewMovementCommands.d.ts.map +1 -1
  260. package/package.json +11 -1
  261. package/dist/chunks/AttributedMarkCommands-BB7lzFct.mjs +0 -2
  262. package/dist/chunks/AttributedMarkCommands-BB7lzFct.mjs.map +0 -1
  263. package/dist/chunks/ColorPickerPopup-DRzFvt7o.mjs.map +0 -1
  264. package/dist/chunks/Commands-P9wS8qtN.mjs +0 -2
  265. package/dist/chunks/Commands-P9wS8qtN.mjs.map +0 -1
  266. package/dist/chunks/Document-BFYAonMF.mjs +0 -2
  267. package/dist/chunks/Document-BFYAonMF.mjs.map +0 -1
  268. package/dist/chunks/DocumentParser-DFcvVMGY.mjs +0 -2
  269. package/dist/chunks/DocumentParser-DFcvVMGY.mjs.map +0 -1
  270. package/dist/chunks/DomUtils-Cdz1eDKM.mjs +0 -2
  271. package/dist/chunks/DomUtils-Cdz1eDKM.mjs.map +0 -1
  272. package/dist/chunks/HTMLUtils-CCvQ5f83.mjs +0 -2
  273. package/dist/chunks/HTMLUtils-CCvQ5f83.mjs.map +0 -1
  274. package/dist/chunks/HeadingPlugin-DYy3IoT_.mjs +0 -2
  275. package/dist/chunks/HeadingPlugin-DYy3IoT_.mjs.map +0 -1
  276. package/dist/chunks/LocaleService-B6Z-wyAF.mjs +0 -2
  277. package/dist/chunks/LocaleService-B6Z-wyAF.mjs.map +0 -1
  278. package/dist/chunks/MarkCommands-B_erV7zz.mjs +0 -2
  279. package/dist/chunks/MarkCommands-B_erV7zz.mjs.map +0 -1
  280. package/dist/chunks/NotectlEditor-4NFnXLyD.mjs +0 -2
  281. package/dist/chunks/NotectlEditor-4NFnXLyD.mjs.map +0 -1
  282. package/dist/chunks/Plugin-OzM8Oxm_.mjs +0 -2
  283. package/dist/chunks/Plugin-OzM8Oxm_.mjs.map +0 -1
  284. package/dist/chunks/PluginHelpers-DjZt0pQi.mjs +0 -2
  285. package/dist/chunks/PluginHelpers-DjZt0pQi.mjs.map +0 -1
  286. package/dist/chunks/PopupManager-BM8IT6M7.mjs +0 -2
  287. package/dist/chunks/PrintTypes-ehbL7ipA.mjs +0 -2
  288. package/dist/chunks/index-C8xtb3SM.mjs +0 -2
  289. package/dist/chunks/index-C8xtb3SM.mjs.map +0 -1
  290. package/dist/chunks/index-DAoSt12h.mjs +0 -2
  291. package/dist/chunks/index-DAoSt12h.mjs.map +0 -1
  292. package/dist/input/BlockInsertion.d.ts.map +0 -1
@@ -1,2 +1,2 @@
1
- import{o as n}from"./Document-BFYAonMF.mjs";function t(n,t){return n.type===t}function e(n,t){return n.type===t}function r(t,e){return n(t)&&t.inlineType===e}export{e as a,t as b,r as i};
2
- //# sourceMappingURL=AttrRegistry-B2AGfTE0.mjs.map
1
+ import{o as n}from"./Document-HC8s50qJ.mjs";function t(n,t){return n.type===t}function e(n,t){return n.type===t}function r(t,e){return n(t)&&t.inlineType===e}export{e as a,t as b,r as i};
2
+ //# sourceMappingURL=AttrRegistry-Ckj9eCHj.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"AttrRegistry-B2AGfTE0.mjs","sources":["../../src/model/AttrRegistry.ts"],"sourcesContent":["/**\n * Module-augmentable attribute registries for type-safe node/mark attributes.\n *\n * Plugins extend these interfaces via `declare module`:\n * @example\n * declare module '../../model/AttrRegistry.js' {\n * interface NodeAttrRegistry {\n * heading: { level: HeadingLevel; align?: BlockAlignment };\n * }\n * }\n */\n\nimport type { BlockAlignment } from './BlockAlignment.js';\nimport type { BlockNode, InlineNode, Mark } from './Document.js';\nimport { isInlineNode } from './Document.js';\n\n/** Plugins augment this interface to register typed node attributes. */\nexport interface NodeAttrRegistry {\n\tparagraph: { align?: BlockAlignment };\n}\n\n/** Plugins augment this interface to register typed mark attributes. */\nexport interface MarkAttrRegistry {\n\tbold: Record<string, never>;\n\titalic: Record<string, never>;\n\tunderline: Record<string, never>;\n}\n\n/** Resolves typed attributes for known node types, falls back for unknown. */\nexport type NodeAttrsFor<T extends string> = T extends keyof NodeAttrRegistry\n\t? NodeAttrRegistry[T]\n\t: Record<string, string | number | boolean>;\n\n/** Resolves typed attributes for known mark types, falls back for unknown. */\nexport type MarkAttrsFor<T extends string> = T extends keyof MarkAttrRegistry\n\t? MarkAttrRegistry[T]\n\t: Record<string, string | number | boolean>;\n\n/** Narrows a BlockNode to a typed variant with known attributes. */\nexport function isNodeOfType<T extends keyof NodeAttrRegistry>(\n\tnode: BlockNode,\n\ttype: T,\n): node is BlockNode & { readonly type: T; readonly attrs: NodeAttrRegistry[T] } {\n\treturn (node.type as string) === type;\n}\n\n/** Narrows a Mark to a typed variant with known attributes. */\nexport function isMarkOfType<T extends keyof MarkAttrRegistry>(\n\tmark: Mark,\n\ttype: T,\n): mark is Mark & { readonly type: T; readonly attrs: MarkAttrRegistry[T] } {\n\treturn (mark.type as string) === type;\n}\n\n// --- InlineNode Attribute Registry ---\n\n/** Plugins augment this interface to register typed inline node attributes. */\n// biome-ignore lint/suspicious/noEmptyInterface: module augmentation requires interface\nexport interface InlineNodeAttrRegistry {}\n\n/** Resolves typed attributes for known inline node types, falls back for unknown. */\nexport type InlineNodeAttrsFor<T extends string> = T extends keyof InlineNodeAttrRegistry\n\t? InlineNodeAttrRegistry[T]\n\t: Record<string, string | number | boolean>;\n\n/** Narrows an InlineNode to a typed variant with known attributes. */\nexport function isInlineNodeOfType<T extends keyof InlineNodeAttrRegistry>(\n\tnode: InlineNode,\n\tinlineNodeType: T,\n): node is InlineNode & {\n\treadonly inlineType: T;\n\treadonly attrs: InlineNodeAttrRegistry[T];\n} {\n\treturn isInlineNode(node) && (node.inlineType as string) === inlineNodeType;\n}\n"],"names":["isNodeOfType","node","type","isMarkOfType","mark","isInlineNodeOfType","inlineNodeType","isInlineNode","inlineType"],"mappings":"4CAuCO,SAASA,EACfC,EACAC,GAEA,OAAQD,EAAKC,OAAoBA,CAClC,CAGO,SAASC,EACfC,EACAF,GAEA,OAAQE,EAAKF,OAAoBA,CAClC,CAcO,SAASG,EACfJ,EACAK,GAKA,OAAOC,EAAaN,IAAUA,EAAKO,aAA0BF,CAC9D"}
1
+ {"version":3,"file":"AttrRegistry-Ckj9eCHj.mjs","sources":["../../src/model/AttrRegistry.ts"],"sourcesContent":["/**\n * Module-augmentable attribute registries for type-safe node/mark attributes.\n *\n * Plugins extend these interfaces via `declare module`:\n * @example\n * declare module '../../model/AttrRegistry.js' {\n * interface NodeAttrRegistry {\n * heading: { level: HeadingLevel; align?: BlockAlignment };\n * }\n * }\n */\n\nimport type { BlockAlignment } from './BlockAlignment.js';\nimport type { BlockNode, InlineNode, Mark } from './Document.js';\nimport { isInlineNode } from './Document.js';\n\n/** Plugins augment this interface to register typed node attributes. */\nexport interface NodeAttrRegistry {\n\tparagraph: { align?: BlockAlignment };\n}\n\n/** Plugins augment this interface to register typed mark attributes. */\nexport interface MarkAttrRegistry {\n\tbold: Record<string, never>;\n\titalic: Record<string, never>;\n\tunderline: Record<string, never>;\n}\n\n/** Resolves typed attributes for known node types, falls back for unknown. */\nexport type NodeAttrsFor<T extends string> = T extends keyof NodeAttrRegistry\n\t? NodeAttrRegistry[T]\n\t: Record<string, string | number | boolean>;\n\n/** Resolves typed attributes for known mark types, falls back for unknown. */\nexport type MarkAttrsFor<T extends string> = T extends keyof MarkAttrRegistry\n\t? MarkAttrRegistry[T]\n\t: Record<string, string | number | boolean>;\n\n/** Narrows a BlockNode to a typed variant with known attributes. */\nexport function isNodeOfType<T extends keyof NodeAttrRegistry>(\n\tnode: BlockNode,\n\ttype: T,\n): node is BlockNode & { readonly type: T; readonly attrs: NodeAttrRegistry[T] } {\n\treturn (node.type as string) === type;\n}\n\n/** Narrows a Mark to a typed variant with known attributes. */\nexport function isMarkOfType<T extends keyof MarkAttrRegistry>(\n\tmark: Mark,\n\ttype: T,\n): mark is Mark & { readonly type: T; readonly attrs: MarkAttrRegistry[T] } {\n\treturn (mark.type as string) === type;\n}\n\n// --- InlineNode Attribute Registry ---\n\n/** Plugins augment this interface to register typed inline node attributes. */\n// biome-ignore lint/suspicious/noEmptyInterface: module augmentation requires interface\nexport interface InlineNodeAttrRegistry {}\n\n/** Resolves typed attributes for known inline node types, falls back for unknown. */\nexport type InlineNodeAttrsFor<T extends string> = T extends keyof InlineNodeAttrRegistry\n\t? InlineNodeAttrRegistry[T]\n\t: Record<string, string | number | boolean>;\n\n/** Narrows an InlineNode to a typed variant with known attributes. */\nexport function isInlineNodeOfType<T extends keyof InlineNodeAttrRegistry>(\n\tnode: InlineNode,\n\tinlineNodeType: T,\n): node is InlineNode & {\n\treadonly inlineType: T;\n\treadonly attrs: InlineNodeAttrRegistry[T];\n} {\n\treturn isInlineNode(node) && (node.inlineType as string) === inlineNodeType;\n}\n"],"names":["isNodeOfType","node","type","isMarkOfType","mark","isInlineNodeOfType","inlineNodeType","isInlineNode","inlineType"],"mappings":"4CAuCO,SAASA,EACfC,EACAC,GAEA,OAAQD,EAAKC,OAAoBA,CAClC,CAGO,SAASC,EACfC,EACAF,GAEA,OAAQE,EAAKF,OAAoBA,CAClC,CAcO,SAASG,EACfJ,EACAK,GAKA,OAAOC,EAAaN,IAAUA,EAAKO,aAA0BF,CAC9D"}
@@ -0,0 +1,2 @@
1
+ import{a as t}from"./AttrRegistry-Ckj9eCHj.mjs";import{h as n,m as o,k as r,q as e}from"./Document-HC8s50qJ.mjs";import{j as s,i as c,s as i}from"./Selection-DhbizDM4.mjs";import{m as a}from"./TypeBrands-Bp_Z_o5Y.mjs";import{f as l}from"./RangeIterator-CprUbOWv.mjs";function f(t,o){const r=t.selection;if(!s(r))return null;const e=a(o.type);if(c(r)){const s=t.getBlock(r.anchor.blockId);if(!s)return null;const c=[...(t.storedMarks??n(s,r.anchor.offset)).filter(t=>t.type!==e),o];return t.transaction("command").setStoredMarks(c,t.storedMarks).setSelection(r).build()}const f=i(r,t.getBlockOrder()),u=t.transaction("command");return l(t,f,(n,r,s)=>{const c=t.getBlock(n);if(c){const t=k(c,e,r,s);t&&u.removeMark(n,r,s,t)}u.addMark(n,r,s,o)}),u.setSelection(r),u.build()}function u(t,r){const e=t.selection;if(!s(e))return null;if(c(e)){const s=t.getBlock(e.anchor.blockId);if(!s)return null;const c=t.storedMarks??n(s,e.anchor.offset);if(!o(c,r))return null;const i=c.filter(t=>t.type!==r);return t.transaction("command").setStoredMarks(i,t.storedMarks).setSelection(e).build()}const a=i(e,t.getBlockOrder()),f=t.transaction("command");return l(t,a,(n,o,e)=>{const s=t.getBlock(n),c=s?k(s,r,o,e):void 0;f.removeMark(n,o,e,c??{type:r})}),f.setSelection(e),f.build()}function m(o,r,e){const i=o.selection;if(!s(i))return null;if(c(i)&&o.storedMarks){const n=o.storedMarks.find(t=>t.type===r);return n&&t(n,r)?e(n):null}const a=o.getBlock(i.anchor.blockId);if(!a)return null;const l=n(a,i.anchor.offset).find(t=>t.type===r);return l&&t(l,r)?e(l):null}function d(t,n){return null!==m(t,n,()=>!0)}function k(t,n,o,s){const c=r(t);let i=0;for(const r of c){if(!e(r)){i+=1;continue}const t=i+r.text.length;if(t>o&&i<s){const t=r.marks.find(t=>t.type===n);if(t)return t}i=t}}export{f as a,m as g,d as i,u as r};
2
+ //# sourceMappingURL=AttributedMarkCommands-x7h4Xy7V.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AttributedMarkCommands-x7h4Xy7V.mjs","sources":["../../src/commands/AttributedMarkCommands.ts"],"sourcesContent":["/**\n * Generic helpers for attributed marks (marks with key/value attrs).\n *\n * Unlike boolean marks (`bold`, `italic`) that toggle on/off, attributed\n * marks (`font`, `fontSize`, `textColor`, `highlight`) carry data and use\n * **replace** semantics: applying a new value removes the old one first.\n *\n * These helpers extract the duplicated collapsed-vs-range branching that\n * was previously copy-pasted across ColorMarkOperations, FontSizeOperations,\n * and FontPlugin.\n */\n\nimport { isMarkOfType } from '../model/AttrRegistry.js';\nimport type { MarkAttrRegistry } from '../model/AttrRegistry.js';\nimport type { BlockNode, Mark, TextNode } from '../model/Document.js';\nimport {\n\tgetBlockMarksAtOffset,\n\tgetInlineChildren,\n\thasMark,\n\tisTextNode,\n} from '../model/Document.js';\nimport type { InlineNode } from '../model/Document.js';\nimport { isCollapsed, isTextSelection, selectionRange } from '../model/Selection.js';\nimport { markType } from '../model/TypeBrands.js';\nimport type { MarkTypeName } from '../model/TypeBrands.js';\nimport type { EditorState } from '../state/EditorState.js';\nimport type { Transaction } from '../state/Transaction.js';\nimport { forEachBlockInRange } from './RangeIterator.js';\n\n/**\n * Applies an attributed mark to the current selection.\n *\n * - **Collapsed cursor**: replaces stored marks (filters out old mark of the\n * same type, appends the new one).\n * - **Range selection**: removes then re-adds the mark in every block span.\n *\n * Returns the built `Transaction`, or `null` when the selection is\n * unsupported (node-selection / gap-cursor) or the anchor block is missing.\n */\nexport function applyAttributedMark(state: EditorState, mark: Mark): Transaction | null {\n\tconst sel = state.selection;\n\tif (!isTextSelection(sel)) return null;\n\n\tconst typeName: MarkTypeName = markType(mark.type as string);\n\n\tif (isCollapsed(sel)) {\n\t\tconst anchorBlock = state.getBlock(sel.anchor.blockId);\n\t\tif (!anchorBlock) return null;\n\t\tconst currentMarks: readonly Mark[] =\n\t\t\tstate.storedMarks ?? getBlockMarksAtOffset(anchorBlock, sel.anchor.offset);\n\t\tconst withoutMark: readonly Mark[] = currentMarks.filter((m) => m.type !== typeName);\n\t\tconst newMarks: readonly Mark[] = [...withoutMark, mark];\n\n\t\treturn state\n\t\t\t.transaction('command')\n\t\t\t.setStoredMarks(newMarks, state.storedMarks)\n\t\t\t.setSelection(sel)\n\t\t\t.build();\n\t}\n\n\tconst range = selectionRange(sel, state.getBlockOrder());\n\tconst builder = state.transaction('command');\n\n\tforEachBlockInRange(state, range, (blockId, from, to) => {\n\t\tconst block: BlockNode | undefined = state.getBlock(blockId);\n\t\tif (block) {\n\t\t\tconst existing: Mark | undefined = findMarkInRange(block, typeName, from, to);\n\t\t\tif (existing) {\n\t\t\t\tbuilder.removeMark(blockId, from, to, existing);\n\t\t\t}\n\t\t}\n\t\tbuilder.addMark(blockId, from, to, mark);\n\t});\n\n\tbuilder.setSelection(sel);\n\treturn builder.build();\n}\n\n/**\n * Removes an attributed mark from the current selection.\n *\n * - **Collapsed cursor**: filters the mark out of stored marks.\n * Returns `null` when the mark was not present.\n * - **Range selection**: removes the mark across all block spans.\n *\n * Returns the built `Transaction`, or `null` when the selection is\n * unsupported or the mark is absent at a collapsed cursor.\n */\nexport function removeAttributedMark(\n\tstate: EditorState,\n\tmarkTypeName: MarkTypeName,\n): Transaction | null {\n\tconst sel = state.selection;\n\tif (!isTextSelection(sel)) return null;\n\n\tif (isCollapsed(sel)) {\n\t\tconst anchorBlock = state.getBlock(sel.anchor.blockId);\n\t\tif (!anchorBlock) return null;\n\t\tconst currentMarks: readonly Mark[] =\n\t\t\tstate.storedMarks ?? getBlockMarksAtOffset(anchorBlock, sel.anchor.offset);\n\t\tif (!hasMark(currentMarks, markTypeName)) return null;\n\n\t\tconst newMarks: readonly Mark[] = currentMarks.filter((m) => m.type !== markTypeName);\n\t\treturn state\n\t\t\t.transaction('command')\n\t\t\t.setStoredMarks(newMarks, state.storedMarks)\n\t\t\t.setSelection(sel)\n\t\t\t.build();\n\t}\n\n\tconst range = selectionRange(sel, state.getBlockOrder());\n\tconst builder = state.transaction('command');\n\n\tforEachBlockInRange(state, range, (blockId, from, to) => {\n\t\tconst block: BlockNode | undefined = state.getBlock(blockId);\n\t\tconst existing: Mark | undefined = block\n\t\t\t? findMarkInRange(block, markTypeName, from, to)\n\t\t\t: undefined;\n\t\tbuilder.removeMark(blockId, from, to, existing ?? { type: markTypeName });\n\t});\n\n\tbuilder.setSelection(sel);\n\treturn builder.build();\n}\n\n/**\n * Extracts a typed attribute value from the mark at the current selection.\n *\n * Looks at stored marks (collapsed w/ stored), block marks at cursor offset\n * (collapsed w/o stored), or anchor-block marks (range).\n *\n * @param extractFn — Narrows the found mark and returns the desired value,\n * or `null` when the mark's attrs don't match expectations.\n */\nexport function getMarkAttrAtSelection<K extends keyof MarkAttrRegistry, V>(\n\tstate: EditorState,\n\tmarkTypeName: K,\n\textractFn: (mark: Mark & { readonly type: K; readonly attrs: MarkAttrRegistry[K] }) => V | null,\n): V | null {\n\tconst sel = state.selection;\n\tif (!isTextSelection(sel)) return null;\n\n\tif (isCollapsed(sel) && state.storedMarks) {\n\t\tconst found = state.storedMarks.find((m) => (m.type as string) === markTypeName);\n\t\treturn found && isMarkOfType(found, markTypeName) ? extractFn(found) : null;\n\t}\n\n\tconst block = state.getBlock(sel.anchor.blockId);\n\tif (!block) return null;\n\tconst marks: readonly Mark[] = getBlockMarksAtOffset(block, sel.anchor.offset);\n\tconst found = marks.find((m) => (m.type as string) === markTypeName);\n\treturn found && isMarkOfType(found, markTypeName) ? extractFn(found) : null;\n}\n\n/**\n * Returns `true` when the given attributed mark type is present at the\n * current selection (collapsed or range).\n */\nexport function isAttributedMarkActive<K extends keyof MarkAttrRegistry>(\n\tstate: EditorState,\n\tmarkTypeName: K,\n): boolean {\n\treturn getMarkAttrAtSelection(state, markTypeName, () => true as const) !== null;\n}\n\n/**\n * Finds the first mark of the given type within an offset range of a block.\n *\n * Returns the full mark (including attrs) so callers can pass it to\n * `removeMark` for correct undo inversion, or `undefined` when absent.\n */\nfunction findMarkInRange(\n\tblock: BlockNode,\n\ttypeName: MarkTypeName,\n\tfrom: number,\n\tto: number,\n): Mark | undefined {\n\tconst children: readonly (TextNode | InlineNode)[] = getInlineChildren(block);\n\tlet pos = 0;\n\n\tfor (const child of children) {\n\t\tif (!isTextNode(child)) {\n\t\t\tpos += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tconst nodeEnd: number = pos + child.text.length;\n\t\tif (nodeEnd > from && pos < to) {\n\t\t\tconst found: Mark | undefined = child.marks.find((m) => m.type === typeName);\n\t\t\tif (found) return found;\n\t\t}\n\t\tpos = nodeEnd;\n\t}\n\treturn undefined;\n}\n"],"names":["applyAttributedMark","state","mark","sel","selection","isTextSelection","typeName","markType","type","isCollapsed","anchorBlock","getBlock","anchor","blockId","newMarks","storedMarks","getBlockMarksAtOffset","offset","filter","m","transaction","setStoredMarks","setSelection","build","range","selectionRange","getBlockOrder","builder","forEachBlockInRange","from","to","block","existing","findMarkInRange","removeMark","addMark","removeAttributedMark","markTypeName","currentMarks","hasMark","getMarkAttrAtSelection","extractFn","found","find","isMarkOfType","isAttributedMarkActive","children","getInlineChildren","pos","child","isTextNode","nodeEnd","text","length","marks"],"mappings":"2QAuCO,SAASA,EAAoBC,EAAoBC,GACvD,MAAMC,EAAMF,EAAMG,UAClB,IAAKC,EAAgBF,GAAM,OAAO,KAElC,MAAMG,EAAyBC,EAASL,EAAKM,MAE7C,GAAIC,EAAYN,GAAM,CACrB,MAAMO,EAAcT,EAAMU,SAASR,EAAIS,OAAOC,SAC9C,IAAKH,EAAa,OAAO,KACzB,MAGMI,EAA4B,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MC,QAC3C,EACHH,EAAQO,WAAWrB,EAASgB,EAAMC,EAAIE,GAAY,CAAExB,KAAM6B,MAG3DV,EAAQL,aAAanB,GACdwB,EAAQJ,OAChB,CAWO,SAASiB,EACfvC,EACAoC,EACAI,GAEA,MAAMtC,EAAMF,EAAMG,UAClB,IAAKC,EAAgBF,GAAM,OAAO,KAElC,GAAIM,EAAYN,IAAQF,EAAMc,YAAa,CAC1C,MAAM2B,EAAQzC,EAAMc,YAAY4B,KAAMxB,GAAOA,EAAEX,OAAoB6B,GACnE,OAAOK,GAASE,EAAaF,EAAOL,GAAgBI,EAAUC,GAAS,IACxE,CAEA,MAAMX,EAAQ9B,EAAMU,SAASR,EAAIS,OAAOC,SACxC,IAAKkB,EAAO,OAAO,KACnB,MACMW,EADyB1B,EAAsBe,EAAO5B,EAAIS,OAAOK,QACnD0B,KAAMxB,GAAOA,EAAEX,OAAoB6B,GACvD,OAAOK,GAASE,EAAaF,EAAOL,GAAgBI,EAAUC,GAAS,IACxE,CAMO,SAASG,EACf5C,EACAoC,GAEA,OAA4E,OAArEG,EAAuBvC,EAAOoC,EAAc,KAAM,EAC1D,CAQA,SAASJ,EACRF,EACAzB,EACAuB,EACAC,GAEA,MAAMgB,EAA+CC,EAAkBhB,GACvE,IAAIiB,EAAM,EAEV,IAAA,MAAWC,KAASH,EAAU,CAC7B,IAAKI,EAAWD,GAAQ,CACvBD,GAAO,EACP,QACD,CACA,MAAMG,EAAkBH,EAAMC,EAAMG,KAAKC,OACzC,GAAIF,EAAUtB,GAAQmB,EAAMlB,EAAI,CAC/B,MAAMY,EAA0BO,EAAMK,MAAMX,KAAMxB,GAAMA,EAAEX,OAASF,GACnE,GAAIoC,EAAO,OAAOA,CACnB,CACAM,EAAMG,CACP,CAED"}
@@ -0,0 +1,2 @@
1
+ import{n as t,s as n,c as e,i as o,e as r}from"./Document-HC8s50qJ.mjs";import{a as s}from"./NavigationQueries-DCOv4Ca5.mjs";import{h as c,g as a}from"./Selection-DhbizDM4.mjs";import{n as i}from"./TypeBrands-Bp_Z_o5Y.mjs";import{g as f,h as u,j as d}from"./Commands-DwXBBVGR.mjs";function p(t,n,e){const o=s(t.doc,n),r=f(o),c=u(t,r),a=d(c,n);if(!(a<0))return{parentPath:r,anchorIndex:a,isAnchorEmpty:b(t,n,e)}}function m(n,e,o,r){const c=s(n.doc,o);if(!c)return;const a=n.getBlock(o);return a?{parentPath:c,anchorIndex:a.children.findIndex(n=>t(n)&&n.id===e),isAnchorEmpty:b(n,e,r)}:void 0}function h(t,n){const e=t.getBlock(n);if("table_cell"===e?.type)return n;const o=s(t.doc,n);if(o)for(const r of o){const n=t.getBlock(r);if("table_cell"===n?.type)return r}}function l(t){return c(t)?t.nodeId:a(t)?t.blockId:t.anchor.blockId}function y(t,n,e,o,r,s){const c=h(t,e);if(c){const r=m(t,e,c,s);if(!r)return!1;const a=r.anchorIndex+1;n.insertNode(r.parentPath,a,o),r.isAnchorEmpty&&r.anchorIndex>=0&&n.removeNode(r.parentPath,r.anchorIndex)}else{const c=p(t,e,s);if(!c)return!1;const i=a(r)&&"before"===r.side?0:1;n.insertNode(c.parentPath,c.anchorIndex+i,o),c.isAnchorEmpty&&!a(r)&&n.removeNode(c.parentPath,c.anchorIndex)}return!0}function g(o,r){const s=o.children.map(e=>t(e)?g(e,n()):e);return e(o.type,s,r,o.attrs)}function x(n,e){if(n.id===e)return n;for(const o of n.children){if(!t(o))continue;const n=x(o,e);if(n)return n}}function I(t,n){if(!n)return;const e={};let o=!1;for(const r of Object.keys(n)){const s=n[r],c=t?.[r];"string"==typeof c||"number"==typeof c||"boolean"==typeof c?e[r]=c:void 0!==s.default&&(e[r]=s.default),r in e&&(o=!0)}return o?e:void 0}function b(t,n,e){const r=t.getBlock(n);if(!r)return!1;const s=e?.getNodeSpec(r.type);return!s?.isVoid&&""===o(r)}function v(t,n){if(!t.type)return;if(!n)return t;const e=n.getNodeSpec(t.type);if(!e)return;const o=I(t.attrs,e.attrs);return{...t,attrs:o}}function k(t){const o=n(),s=function(t,n){return t.segments&&t.segments.length>0?function(t){const n=[];for(const e of t){if(0===e.text.length)continue;const t=e.marks.map(t=>({type:t.type,...t.attrs?{attrs:t.attrs}:{}}));n.push(r(e.text,t))}return n}(t.segments):n?[r(n)]:void 0}(t,t.text??""),c=t.attrs?t.attrs:void 0;return e(i(t.type),s,o,c)}export{p as a,g as b,k as c,x as d,l as e,h as f,y as i,m as r,I as s,v};
2
+ //# sourceMappingURL=BlockInsertion-zPxm6oa_.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlockInsertion-zPxm6oa_.mjs","sources":["../../src/commands/BlockInsertion.ts"],"sourcesContent":["/**\n * Block insertion utilities for paste and clipboard operations.\n *\n * Provides context resolution (parent path, anchor index, empty detection)\n * for inserting blocks into the document tree — both at root level and\n * inside table cells. Also contains pure helpers for block cloning,\n * recursive lookup, and attribute sanitization against a NodeSpec.\n */\n\nimport {\n\ttype BlockAttrs,\n\ttype BlockNode,\n\ttype ChildNode,\n\ttype Mark,\n\ttype TextNode,\n\tcreateBlockNode,\n\tcreateTextNode,\n\tgenerateBlockId,\n\tgetBlockText,\n\tisBlockNode,\n} from '../model/Document.js';\nimport { findNodePath } from '../model/NodeResolver.js';\nimport type { AttrSpec } from '../model/NodeSpec.js';\nimport type { RichBlockData, RichSegment } from '../model/RichBlockData.js';\nimport type { SchemaRegistry } from '../model/SchemaRegistry.js';\nimport type { EditorSelection } from '../model/Selection.js';\nimport { isGapCursor, isNodeSelection } from '../model/Selection.js';\nimport type { BlockId, NodeTypeName } from '../model/TypeBrands.js';\nimport { nodeType } from '../model/TypeBrands.js';\nimport type { EditorState } from '../state/EditorState.js';\nimport type { TransactionBuilder } from '../state/Transaction.js';\nimport { extractParentPath, findSiblingIndex, getSiblings } from './CommandHelpers.js';\n\n/**\n * Resolved insertion target within the document tree.\n * Contains everything needed to insert blocks at a specific anchor position.\n */\nexport interface InsertionContext {\n\treadonly parentPath: readonly BlockId[];\n\treadonly anchorIndex: number;\n\treadonly isAnchorEmpty: boolean;\n}\n\n/**\n * Resolves an insertion context for root-level (or nested-parent-level) insertion.\n * Computes the parent path, anchor index among siblings, and whether the anchor is empty.\n */\nexport function resolveRootInsertionContext(\n\tstate: EditorState,\n\tanchorBlockId: BlockId,\n\tschemaRegistry?: SchemaRegistry,\n): InsertionContext | undefined {\n\tconst path: readonly string[] | undefined = findNodePath(state.doc, anchorBlockId);\n\tconst parentPath: BlockId[] = extractParentPath(path);\n\n\tconst siblings: readonly ChildNode[] = getSiblings(state, parentPath);\n\tconst anchorIndex: number = findSiblingIndex(siblings, anchorBlockId);\n\tif (anchorIndex < 0) return undefined;\n\n\tconst isAnchorEmpty: boolean = isBlockEmpty(state, anchorBlockId, schemaRegistry);\n\treturn { parentPath, anchorIndex, isAnchorEmpty };\n}\n\n/**\n * Resolves an insertion context within a table cell.\n * The parent path points to the cell itself; siblings are the cell's children.\n */\nexport function resolveCellInsertionContext(\n\tstate: EditorState,\n\tanchorBlockId: BlockId,\n\tcellId: BlockId,\n\tschemaRegistry?: SchemaRegistry,\n): InsertionContext | undefined {\n\tconst cellPath: BlockId[] | undefined = findNodePath(state.doc, cellId) as BlockId[] | undefined;\n\tif (!cellPath) return undefined;\n\n\tconst cell: BlockNode | undefined = state.getBlock(cellId);\n\tif (!cell) return undefined;\n\n\tconst anchorIndex: number = cell.children.findIndex(\n\t\t(c) => isBlockNode(c) && c.id === anchorBlockId,\n\t);\n\n\tconst isAnchorEmpty: boolean = isBlockEmpty(state, anchorBlockId, schemaRegistry);\n\treturn { parentPath: cellPath, anchorIndex, isAnchorEmpty };\n}\n\n/**\n * Finds a table_cell ancestor for the given block.\n * Walks the node path upward, returning the first table_cell BlockId found.\n */\nexport function findTableCellAncestor(state: EditorState, blockId: BlockId): BlockId | undefined {\n\tconst block: BlockNode | undefined = state.getBlock(blockId);\n\tif (block?.type === 'table_cell') return blockId;\n\n\tconst path: BlockId[] | undefined = findNodePath(state.doc, blockId) as BlockId[] | undefined;\n\tif (!path) return undefined;\n\n\tfor (const id of path) {\n\t\tconst node: BlockNode | undefined = state.getBlock(id as BlockId);\n\t\tif (node?.type === 'table_cell') return id as BlockId;\n\t}\n\treturn undefined;\n}\n\n/**\n * Resolves the anchor block ID from the current editor selection.\n * Handles text selection, node selection, and gap cursor uniformly.\n */\nexport function resolveAnchorBlockId(selection: EditorSelection): BlockId {\n\tif (isNodeSelection(selection)) return selection.nodeId;\n\tif (isGapCursor(selection)) return selection.blockId;\n\treturn selection.anchor.blockId;\n}\n\n/**\n * Inserts a block node after the anchor position, resolving cell vs root context.\n * Removes the anchor block if it is empty (matching standard paste behavior).\n * Returns true on success, false if context resolution fails.\n */\nexport function insertBlockAfterAnchor(\n\tstate: EditorState,\n\tbuilder: TransactionBuilder,\n\tanchorBlockId: BlockId,\n\tblock: BlockNode,\n\tselection: EditorSelection,\n\tschemaRegistry?: SchemaRegistry,\n): boolean {\n\tconst cellId: BlockId | undefined = findTableCellAncestor(state, anchorBlockId);\n\n\tif (cellId) {\n\t\tconst ctx: InsertionContext | undefined = resolveCellInsertionContext(\n\t\t\tstate,\n\t\t\tanchorBlockId,\n\t\t\tcellId,\n\t\t\tschemaRegistry,\n\t\t);\n\t\tif (!ctx) return false;\n\n\t\tconst insertIndex: number = ctx.anchorIndex + 1;\n\t\tbuilder.insertNode(ctx.parentPath, insertIndex, block);\n\n\t\tif (ctx.isAnchorEmpty && ctx.anchorIndex >= 0) {\n\t\t\tbuilder.removeNode(ctx.parentPath, ctx.anchorIndex);\n\t\t}\n\t} else {\n\t\tconst ctx: InsertionContext | undefined = resolveRootInsertionContext(\n\t\t\tstate,\n\t\t\tanchorBlockId,\n\t\t\tschemaRegistry,\n\t\t);\n\t\tif (!ctx) return false;\n\n\t\tconst insertOffset: number = isGapCursor(selection) && selection.side === 'before' ? 0 : 1;\n\t\tbuilder.insertNode(ctx.parentPath, ctx.anchorIndex + insertOffset, block);\n\n\t\tif (ctx.isAnchorEmpty && !isGapCursor(selection)) {\n\t\t\tbuilder.removeNode(ctx.parentPath, ctx.anchorIndex);\n\t\t}\n\t}\n\n\treturn true;\n}\n\n/** Recursively clones a block tree, assigning new IDs to all block nodes. */\nexport function cloneBlockWithNewIds(block: BlockNode, newId: BlockId): BlockNode {\n\tconst children = block.children.map((child) => {\n\t\tif (isBlockNode(child)) {\n\t\t\treturn cloneBlockWithNewIds(child, generateBlockId());\n\t\t}\n\t\treturn child;\n\t});\n\treturn createBlockNode(block.type, children, newId, block.attrs);\n}\n\n/** Recursively searches a block tree for a block with the given ID (DFS). */\nexport function findBlockRecursive(block: BlockNode, blockId: BlockId): BlockNode | undefined {\n\tif (block.id === blockId) return block;\n\tfor (const child of block.children) {\n\t\tif (!isBlockNode(child)) continue;\n\t\tconst found: BlockNode | undefined = findBlockRecursive(child, blockId);\n\t\tif (found) return found;\n\t}\n\treturn undefined;\n}\n\n/**\n * Validates incoming attributes against the declared AttrSpec.\n * Only keys declared in the spec are kept; non-primitive values fall back to defaults.\n */\nexport function sanitizeAttrs(\n\tincoming: Record<string, unknown> | undefined,\n\tspecAttrs: Readonly<Record<string, AttrSpec>> | undefined,\n): Record<string, string | number | boolean> | undefined {\n\tif (!specAttrs) return undefined;\n\n\tconst result: Record<string, string | number | boolean> = {};\n\tlet hasKeys = false;\n\n\tfor (const key of Object.keys(specAttrs)) {\n\t\tconst spec: AttrSpec = specAttrs[key] as AttrSpec;\n\t\tconst raw: unknown = incoming?.[key];\n\n\t\tif (typeof raw === 'string' || typeof raw === 'number' || typeof raw === 'boolean') {\n\t\t\tresult[key] = raw;\n\t\t} else if (spec.default !== undefined) {\n\t\t\tresult[key] = spec.default;\n\t\t}\n\t\tif (key in result) hasKeys = true;\n\t}\n\n\treturn hasKeys ? result : undefined;\n}\n\n/** Checks whether a block is empty (has no text and is not a void block). */\nfunction isBlockEmpty(\n\tstate: EditorState,\n\tblockId: BlockId,\n\tschemaRegistry?: SchemaRegistry,\n): boolean {\n\tconst block: BlockNode | undefined = state.getBlock(blockId);\n\tif (!block) return false;\n\n\tconst spec = schemaRegistry?.getNodeSpec(block.type);\n\treturn !spec?.isVoid && getBlockText(block) === '';\n}\n\n// --- Rich block creation ---\n\n/**\n * Validates a rich block against the schema registry.\n * Returns undefined for blocks with unknown types; sanitizes attributes\n * against the declared spec.\n */\nexport function validateRichBlockData(\n\traw: RichBlockData,\n\tschemaRegistry?: SchemaRegistry,\n): RichBlockData | undefined {\n\tif (!raw.type) return undefined;\n\tif (!schemaRegistry) return raw;\n\n\tconst spec = schemaRegistry.getNodeSpec(raw.type);\n\tif (!spec) return undefined;\n\n\tconst attrs: Record<string, string | number | boolean> | undefined = sanitizeAttrs(\n\t\traw.attrs,\n\t\tspec.attrs,\n\t);\n\treturn { ...raw, attrs };\n}\n\n/**\n * Creates a BlockNode from validated rich block data.\n * Converts segments or plain text into inline children.\n */\nexport function createBlockFromRichData(blockData: RichBlockData): BlockNode {\n\tconst newId: BlockId = generateBlockId();\n\tconst text: string = blockData.text ?? '';\n\tconst children: TextNode[] | undefined = createChildrenFromRichBlock(blockData, text);\n\tconst attrs: BlockAttrs | undefined = blockData.attrs\n\t\t? (blockData.attrs as BlockAttrs)\n\t\t: undefined;\n\n\treturn createBlockNode(nodeType(blockData.type) as NodeTypeName, children, newId, attrs);\n}\n\n/**\n * Creates inline children from rich block data.\n * Uses mark-preserving segments when available, falls back to plain text.\n */\nfunction createChildrenFromRichBlock(\n\tblockData: RichBlockData,\n\ttext: string,\n): TextNode[] | undefined {\n\tif (blockData.segments && blockData.segments.length > 0) {\n\t\treturn createChildrenFromSegments(blockData.segments);\n\t}\n\treturn text ? [createTextNode(text)] : undefined;\n}\n\n/** Converts rich segments into TextNode children with marks. */\nfunction createChildrenFromSegments(segments: readonly RichSegment[]): TextNode[] {\n\tconst children: TextNode[] = [];\n\tfor (const seg of segments) {\n\t\tif (seg.text.length === 0) continue;\n\t\tconst marks: readonly Mark[] = seg.marks.map((m) => ({\n\t\t\ttype: m.type as Mark['type'],\n\t\t\t...(m.attrs ? { attrs: m.attrs as Mark['attrs'] } : {}),\n\t\t}));\n\t\tchildren.push(createTextNode(seg.text, marks));\n\t}\n\treturn children;\n}\n"],"names":["resolveRootInsertionContext","state","anchorBlockId","schemaRegistry","path","findNodePath","doc","parentPath","extractParentPath","siblings","getSiblings","anchorIndex","findSiblingIndex","isAnchorEmpty","isBlockEmpty","resolveCellInsertionContext","cellId","cellPath","cell","getBlock","children","findIndex","c","isBlockNode","id","findTableCellAncestor","blockId","block","type","node","resolveAnchorBlockId","selection","isNodeSelection","nodeId","isGapCursor","anchor","insertBlockAfterAnchor","builder","ctx","insertIndex","insertNode","removeNode","insertOffset","side","cloneBlockWithNewIds","newId","map","child","generateBlockId","createBlockNode","attrs","findBlockRecursive","found","sanitizeAttrs","incoming","specAttrs","result","hasKeys","key","Object","keys","spec","raw","default","getNodeSpec","isVoid","getBlockText","validateRichBlockData","createBlockFromRichData","blockData","text","segments","length","seg","marks","m","push","createTextNode","createChildrenFromSegments","createChildrenFromRichBlock","nodeType"],"mappings":"yRA+CO,SAASA,EACfC,EACAC,EACAC,GAEA,MAAMC,EAAsCC,EAAaJ,EAAMK,IAAKJ,GAC9DK,EAAwBC,EAAkBJ,GAE1CK,EAAiCC,EAAYT,EAAOM,GACpDI,EAAsBC,EAAiBH,EAAUP,GACvD,KAAIS,EAAc,GAGlB,MAAO,CAAEJ,aAAYI,cAAaE,cADHC,EAAab,EAAOC,EAAeC,GAEnE,CAMO,SAASY,EACfd,EACAC,EACAc,EACAb,GAEA,MAAMc,EAAkCZ,EAAaJ,EAAMK,IAAKU,GAChE,IAAKC,EAAU,OAEf,MAAMC,EAA8BjB,EAAMkB,SAASH,GACnD,OAAKE,EAOE,CAAEX,WAAYU,EAAUN,YALHO,EAAKE,SAASC,UACxCC,GAAMC,EAAYD,IAAMA,EAAEE,KAAOtB,GAISW,cADbC,EAAab,EAAOC,EAAeC,SANlE,CAQD,CAMO,SAASsB,EAAsBxB,EAAoByB,GACzD,MAAMC,EA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C3B,GAAwB,IAApBE,EAAIH,KAAKE,OAAc,SAC3B,MAAME,EAAyBD,EAAIC,MAAM5B,IAAK6B,IAAA,CAC7C/C,KAAM+C,EAAE/C,QACJ+C,EAAEzB,MAAQ,CAAEA,MAAOyB,EAAEzB,OAA2B,CAAA,KAErD9B,EAASwD,KAAKC,EAAeJ,EAAIH,KAAMI,GACxC,CACA,OAAOtD,CACR,CAjBS0D,CAA2BT,EAAUE,UAEtCD,EAAO,CAACO,EAAeP,SAAS,CACxC,CApB0CS,CAA4BV,EADhDA,EAAUC,MAAQ,IAEjCpB,EAAgCmB,EAAUnB,MAC5CmB,EAAUnB,WACX,EAEH,OAAOD,EAAgB+B,EAASX,EAAUzC,MAAuBR,EAAUyB,EAAOK,EACnF"}
@@ -1,2 +1,2 @@
1
- import{r as e}from"./ColorGrid-CpkbKfXg.mjs";import{a as o,g as t,r}from"./AttributedMarkCommands-BB7lzFct.mjs";import{m as a}from"./TypeBrands-Bp_Z_o5Y.mjs";import{i as n}from"./ColorValidation-DCSKq9B2.mjs";function s(e,o){return t(e,o,e=>e.attrs.color??null)}function l(e,o){return null!==s(e,o)}function i(e,t,r,s){if(!n(s))return!1;const l={type:a(r),attrs:{color:s}},i=o(t,l);return!!i&&(e.dispatch(i),!0)}function c(e,o,t){const n=r(o,a(t));return!!n&&(e.dispatch(n),!0)}function m(o,t,r){o.classList.add("notectl-color-picker");const a=s(t.getState(),r.markType),n=r.columns||10,l=t.getContainer(),c=document.createElement("button");c.type="button",c.className="notectl-color-picker__default",c.textContent=r.resetLabel,c.addEventListener("mousedown",e=>{e.preventDefault(),e.stopPropagation(),t.executeCommand(r.resetCommand),r.onClose({restoreFocusTo:l})}),c.addEventListener("keydown",e=>{"Escape"===e.key&&(e.preventDefault(),r.onClose())}),o.appendChild(c),e(o,{colors:r.colors,columns:n,ariaLabel:`${r.ariaLabelPrefix} color picker`,ariaLabelPrefix:r.ariaLabelPrefix,activeColor:a,onSelect:e=>{i(t,t.getState(),r.markType,e),r.onClose({restoreFocusTo:l})},onClose:r.onClose})}export{i as a,m as b,s as g,l as i,c as r};
2
- //# sourceMappingURL=ColorPickerPopup-DRzFvt7o.mjs.map
1
+ import{r as e}from"./ColorGrid-CpkbKfXg.mjs";import{a as o,g as t,r}from"./AttributedMarkCommands-x7h4Xy7V.mjs";import{m as a}from"./TypeBrands-Bp_Z_o5Y.mjs";import{i as n}from"./ColorValidation-DCSKq9B2.mjs";function s(e,o){return t(e,o,e=>e.attrs.color??null)}function l(e,o){return null!==s(e,o)}function i(e,t,r,s){if(!n(s))return!1;const l={type:a(r),attrs:{color:s}},i=o(t,l);return!!i&&(e.dispatch(i),!0)}function c(e,o,t){const n=r(o,a(t));return!!n&&(e.dispatch(n),!0)}function m(o,t,r){o.classList.add("notectl-color-picker");const a=s(t.getState(),r.markType),n=r.columns||10,l=t.getContainer(),c=document.createElement("button");c.type="button",c.className="notectl-color-picker__default",c.textContent=r.resetLabel,c.addEventListener("mousedown",e=>{e.preventDefault(),e.stopPropagation(),t.executeCommand(r.resetCommand),r.onClose({restoreFocusTo:l})}),c.addEventListener("keydown",e=>{"Escape"===e.key&&(e.preventDefault(),r.onClose())}),o.appendChild(c),e(o,{colors:r.colors,columns:n,ariaLabel:`${r.ariaLabelPrefix} color picker`,ariaLabelPrefix:r.ariaLabelPrefix,activeColor:a,onSelect:e=>{i(t,t.getState(),r.markType,e),r.onClose({restoreFocusTo:l})},onClose:r.onClose})}export{i as a,m as b,s as g,l as i,c as r};
2
+ //# sourceMappingURL=ColorPickerPopup-CDUvkgcK.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ColorPickerPopup-CDUvkgcK.mjs","sources":["../../src/plugins/shared/ColorMarkOperations.ts","../../src/plugins/shared/ColorPickerPopup.ts"],"sourcesContent":["/**\n * Shared color mark operations for color-based mark plugins.\n * All functions are parameterized by mark type name so they work\n * identically for TextColor, Highlight, or any future color mark.\n *\n * Delegates to the generic AttributedMarkCommands helpers for the\n * collapsed-vs-range branching logic.\n */\n\nimport {\n\tapplyAttributedMark,\n\tgetMarkAttrAtSelection,\n\tremoveAttributedMark,\n} from '../../commands/AttributedMarkCommands.js';\nimport type { MarkAttrRegistry } from '../../model/AttrRegistry.js';\nimport { markType } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { PluginContext } from '../Plugin.js';\nimport { isValidCSSColor } from './ColorValidation.js';\n\n/** Color mark type names that have `{ color: string }` attrs. */\nexport type ColorMarkType = {\n\t[K in keyof MarkAttrRegistry]: MarkAttrRegistry[K] extends { color: string } ? K : never;\n}[keyof MarkAttrRegistry];\n\n/**\n * Returns the active color value for the given mark type at the current\n * selection, or `null` if the mark is not present.\n */\nexport function getActiveColor(state: EditorState, markTypeName: ColorMarkType): string | null {\n\treturn getMarkAttrAtSelection(state, markTypeName, (m) => m.attrs.color ?? null);\n}\n\n/** Returns `true` when the given color mark is active at the current selection. */\nexport function isColorMarkActive(state: EditorState, markTypeName: ColorMarkType): boolean {\n\treturn getActiveColor(state, markTypeName) !== null;\n}\n\n/**\n * Applies the given color to the selection. For collapsed selections,\n * sets stored marks. For range selections, removes then re-adds the mark.\n */\nexport function applyColorMark(\n\tcontext: PluginContext,\n\tstate: EditorState,\n\tmarkTypeName: ColorMarkType,\n\tcolor: string,\n): boolean {\n\tif (!isValidCSSColor(color)) return false;\n\n\tconst mark = { type: markType(markTypeName), attrs: { color } };\n\tconst tr = applyAttributedMark(state, mark);\n\tif (!tr) return false;\n\n\tcontext.dispatch(tr);\n\treturn true;\n}\n\n/**\n * Removes the given color mark from the selection.\n * Returns `false` when the mark was not present.\n */\nexport function removeColorMark(\n\tcontext: PluginContext,\n\tstate: EditorState,\n\tmarkTypeName: ColorMarkType,\n): boolean {\n\tconst tr = removeAttributedMark(state, markType(markTypeName));\n\tif (!tr) return false;\n\n\tcontext.dispatch(tr);\n\treturn true;\n}\n","/**\n * Shared color picker popup rendering with WAI-ARIA grid keyboard navigation.\n * Used by TextColorPlugin and HighlightPlugin.\n * Delegates grid rendering to the shared ColorGrid module.\n */\n\nimport type { PluginContext } from '../Plugin.js';\nimport { renderColorGrid } from './ColorGrid.js';\nimport type { ColorMarkType } from './ColorMarkOperations.js';\nimport { applyColorMark, getActiveColor } from './ColorMarkOperations.js';\nimport type { PopupCloseOptions } from './PopupManager.js';\n\n/** Configuration for `renderColorPickerPopup`. */\nexport interface ColorPickerConfig {\n\treadonly markType: ColorMarkType;\n\treadonly colors: readonly string[];\n\treadonly columns: number;\n\treadonly resetLabel: string;\n\treadonly resetCommand: string;\n\treadonly ariaLabelPrefix: string;\n\treadonly onClose: (options?: PopupCloseOptions) => void;\n}\n\nconst COLUMNS = 10;\n\n/**\n * Renders an accessible color picker popup into `container`.\n *\n * Features:\n * - WAI-ARIA `role=\"grid\"` with row/gridcell structure\n * - Arrow key navigation (wraps around, clamps on partial last row)\n * - Enter/Space selects color and closes popup\n * - Escape closes popup\n * - Roving tabindex on swatches\n */\nexport function renderColorPickerPopup(\n\tcontainer: HTMLElement,\n\tcontext: PluginContext,\n\tconfig: ColorPickerConfig,\n): void {\n\tcontainer.classList.add('notectl-color-picker');\n\n\tconst state = context.getState();\n\tconst activeColor: string | null = getActiveColor(state, config.markType);\n\tconst columns: number = config.columns || COLUMNS;\n\tconst contentElement: HTMLElement = context.getContainer();\n\n\t// --- Reset button ---\n\tconst resetBtn: HTMLButtonElement = document.createElement('button');\n\tresetBtn.type = 'button';\n\tresetBtn.className = 'notectl-color-picker__default';\n\tresetBtn.textContent = config.resetLabel;\n\tresetBtn.addEventListener('mousedown', (e: MouseEvent) => {\n\t\te.preventDefault();\n\t\te.stopPropagation();\n\t\tcontext.executeCommand(config.resetCommand);\n\t\tconfig.onClose({ restoreFocusTo: contentElement });\n\t});\n\tresetBtn.addEventListener('keydown', (e: KeyboardEvent) => {\n\t\tif (e.key === 'Escape') {\n\t\t\te.preventDefault();\n\t\t\tconfig.onClose();\n\t\t}\n\t});\n\tcontainer.appendChild(resetBtn);\n\n\t// --- Color grid (delegated to shared ColorGrid) ---\n\trenderColorGrid(container, {\n\t\tcolors: config.colors,\n\t\tcolumns,\n\t\tariaLabel: `${config.ariaLabelPrefix} color picker`,\n\t\tariaLabelPrefix: config.ariaLabelPrefix,\n\t\tactiveColor,\n\t\tonSelect: (color: string) => {\n\t\t\tapplyColorMark(context, context.getState(), config.markType, color);\n\t\t\tconfig.onClose({ restoreFocusTo: contentElement });\n\t\t},\n\t\tonClose: config.onClose,\n\t});\n}\n"],"names":["getActiveColor","state","markTypeName","getMarkAttrAtSelection","m","attrs","color","isColorMarkActive","applyColorMark","context","isValidCSSColor","mark","type","markType","tr","applyAttributedMark","dispatch","removeColorMark","removeAttributedMark","renderColorPickerPopup","container","config","classList","add","activeColor","getState","columns","contentElement","getContainer","resetBtn","document","createElement","className","textContent","resetLabel","addEventListener","e","preventDefault","stopPropagation","executeCommand","resetCommand","onClose","restoreFocusTo","key","appendChild","renderColorGrid","colors","ariaLabel","ariaLabelPrefix","onSelect"],"mappings":"iNA6BO,SAASA,EAAeC,EAAoBC,GAClD,OAAOC,EAAuBF,EAAOC,EAAeE,GAAMA,EAAEC,MAAMC,OAAS,KAC5E,CAGO,SAASC,EAAkBN,EAAoBC,GACrD,OAA+C,OAAxCF,EAAeC,EAAOC,EAC9B,CAMO,SAASM,EACfC,EACAR,EACAC,EACAI,GAEA,IAAKI,EAAgBJ,GAAQ,OAAO,EAEpC,MAAMK,EAAO,CAAEC,KAAMC,EAASX,GAAeG,MAAO,CAAEC,UAChDQ,EAAKC,EAAoBd,EAAOU,GACtC,QAAKG,IAELL,EAAQO,SAASF,IACV,EACR,CAMO,SAASG,EACfR,EACAR,EACAC,GAEA,MAAMY,EAAKI,EAAqBjB,EAAOY,EAASX,IAChD,QAAKY,IAELL,EAAQO,SAASF,IACV,EACR,CCrCO,SAASK,EACfC,EACAX,EACAY,GAEAD,EAAUE,UAAUC,IAAI,wBAExB,MACMC,EAA6BxB,EADrBS,EAAQgB,WACmCJ,EAAOR,UAC1Da,EAAkBL,EAAOK,SArBhB,GAsBTC,EAA8BlB,EAAQmB,eAGtCC,EAA8BC,SAASC,cAAc,UAC3DF,EAASjB,KAAO,SAChBiB,EAASG,UAAY,gCACrBH,EAASI,YAAcZ,EAAOa,WAC9BL,EAASM,iBAAiB,YAAcC,IACvCA,EAAEC,iBACFD,EAAEE,kBACF7B,EAAQ8B,eAAelB,EAAOmB,cAC9BnB,EAAOoB,QAAQ,CAAEC,eAAgBf,MAElCE,EAASM,iBAAiB,UAAYC,IACvB,WAAVA,EAAEO,MACLP,EAAEC,iBACFhB,EAAOoB,aAGTrB,EAAUwB,YAAYf,GAGtBgB,EAAgBzB,EAAW,CAC1B0B,OAAQzB,EAAOyB,OACfpB,UACAqB,UAAW,GAAG1B,EAAO2B,+BACrBA,gBAAiB3B,EAAO2B,gBACxBxB,cACAyB,SAAW3C,IACVE,EAAeC,EAASA,EAAQgB,WAAYJ,EAAOR,SAAUP,GAC7De,EAAOoB,QAAQ,CAAEC,eAAgBf,KAElCc,QAASpB,EAAOoB,SAElB"}
@@ -0,0 +1,2 @@
1
+ import{n as t,c as n,e,s as o,f as r,d as c,h as i,p as l}from"./Document-HC8s50qJ.mjs";import{a as s,e as f,d as u,s as d,i as a}from"./NavigationQueries-DCOv4Ca5.mjs";import{i as b,s as k,c as I,h,g,a as m,b as p,j as S,e as B}from"./Selection-DhbizDM4.mjs";import{n as x,i as O}from"./TypeBrands-Bp_Z_o5Y.mjs";function N(t,n){if(0===n.length)return t.doc.children;const e=t.getBlock(n[n.length-1]);return e?e.children:[]}function A(t){return n(x("paragraph"),[e("")],t)}function T(t,n){if(b(t))return{blockId:t.anchor.blockId,offset:t.anchor.offset};const e=k(t,n);return{blockId:e.from.blockId,offset:e.from.offset}}function j(t){return t&&t.length>1?t.slice(0,-1):[]}function v(n,e){return n.findIndex(n=>t(n)&&n.id===e)}function w(n,e){const c=s(n.doc,e.nodeId);if(!c)return null;const i=j(c),l=N(n,i),f=v(l,e.nodeId);if(f<0)return null;const u=n.transaction("input");if(1===l.length&&0===i.length){const t=o();return u.insertNode(i,0,A(t)),u.removeNode(i,1),u.setSelection(I(t,0)),u.build()}u.removeNode(i,f);const d=l[f-1];if(d&&t(d)){const t=y(d);if(t){const e=n.getBlock(t),o=e?r(e):0;u.setSelection(I(t,o))}}else{const n=l[f+1];if(n&&t(n)){const t=_(n);t&&u.setSelection(I(t,0))}}return u.build()}function M(t,n,e){const o=t.selection,c=t.getBlockOrder(),i=!e||"left"!==n&&"right"!==n?n:"left"===n?"right":"left";return h(o)?function(t,n,e,o){const c=o.indexOf(n.nodeId),i=s(t.doc,n.nodeId)??[];if("left"===e||"up"===e){if(c>0){const e=o[c-1];if(!e)return null;if(f(t,e))return t.transaction("input").setSelection(m(n.nodeId,"before",i)).build();const l=t.getBlock(e),s=l?r(l):0;return t.transaction("input").setSelection(I(e,s)).build()}return t.transaction("input").setSelection(m(n.nodeId,"before",i)).build()}if(c<o.length-1){const e=o[c+1];return e?f(t,e)?t.transaction("input").setSelection(m(n.nodeId,"after",i)).build():t.transaction("input").setSelection(I(e,0)).build():null}return t.transaction("input").setSelection(m(n.nodeId,"after",i)).build()}(t,o,i,c):g(o)?null:b(o)?function(t,n,e,o){const c=o.indexOf(n.anchor.blockId),i=t.getBlock(n.anchor.blockId);if(!i)return null;const l=r(i);if(("right"===e||"down"===e)&&n.anchor.offset===l&&c<o.length-1){const n=o[c+1];if(n&&f(t,n)){const e=s(t.doc,n)??[];return t.transaction("input").setSelection(p(n,e)).build()}}if(("left"===e||"up"===e)&&0===n.anchor.offset&&c>0){const n=o[c-1];if(n&&f(t,n)){const e=s(t.doc,n)??[];return t.transaction("input").setSelection(p(n,e)).build()}}return null}(t,o,i,c):null}function _(n){let e=n;for(;;){const n=e.children.find(n=>t(n));if(!n)return e.id;e=n}}function y(n){let e=n;for(;;){let n;for(let o=e.children.length-1;o>=0;o--){const r=e.children[o];if(r&&t(r)){n=r;break}}if(!n)return e.id;e=n}}function D(t,n){if("after"===n.side)return q(t,n);const e=t.getBlockOrder(),o=e.indexOf(n.blockId);if(o<=0)return null;const c=e[o-1];if(!c)return null;if(f(t,c)){const n=s(t.doc,c)??[];return t.transaction("input").setSelection(p(c,n)).build()}const i=t.getBlock(c);if(!i)return null;const l=r(i);return t.transaction("input").setSelection(I(c,l)).build()}function Q(t,n){if("before"===n.side)return q(t,n);const e=t.getBlockOrder(),o=e.indexOf(n.blockId);if(o>=e.length-1)return null;const r=e[o+1];if(!r)return null;if(f(t,r)){const n=s(t.doc,r)??[];return t.transaction("input").setSelection(p(r,n)).build()}return t.transaction("input").setSelection(I(r,0)).build()}function q(t,n){const e=s(t.doc,n.blockId)??[];return w(t,p(n.blockId,e))}function z(t,n,e="input"){const r=t.selection;if(h(r))return function(t,n,e,r){const c=j(s(t.doc,n.nodeId)),i=N(t,c),l=v(i,n.nodeId),f=o(),u=t.transaction(r),d=l>=0?l+1:i.length;return u.insertNode(c,d,A(f)),u.insertText(f,0,e,[]),u.setSelection(I(f,e.length)),u.build()}(t,r,n,e);if(g(r))return function(t,n,e,r){const c=j(s(t.doc,n.blockId)),i=N(t,c),l=v(i,n.blockId),f="before"===n.side?Math.max(l,0):l>=0?l+1:i.length,u=o(),d=t.transaction(r);return d.insertNode(c,f,A(u)),d.insertText(u,0,e,[]),d.setSelection(I(u,e.length)),d.build()}(t,r,n,e);const c=t.transaction(e),l=function(t){if(t.storedMarks)return t.storedMarks;if(!S(t.selection))return[];const n=t.getBlock(t.selection.anchor.blockId);return n?i(n,t.selection.anchor.offset):[]}(t);let f;b(r)||(f=L(t,c));const u=T(r,t.getBlockOrder()),d=f??u.blockId,a=f?0:u.offset;return c.insertText(d,a,n,l),c.setSelection(I(d,a+n.length)),c.build()}function C(t){if(h(t.selection))return w(t,t.selection);if(g(t.selection))return null;if(b(t.selection))return null;const n=t.transaction("input"),e=L(t,n),o=k(t.selection,t.getBlockOrder()),r=e??o.from.blockId,c=e?0:o.from.offset;return n.setSelection(I(r,c)),n.build()}function E(t){const n=t.selection;if(h(n))return function(t,n){const e=s(t.doc,n.nodeId);if(!e)return null;const r=j(e),c=v(N(t,r),n.nodeId);if(c<0)return null;const i=o(),l=t.transaction("input");return l.insertNode(r,c+1,A(i)),l.setSelection(I(i,0)),l.build()}(t,n);if(g(n))return function(t,n){const e=s(t.doc,n.blockId);if(!e)return null;const r=j(e),c=v(N(t,r),n.blockId);if(c<0)return null;const i="before"===n.side?c:c+1,l=o(),f=t.transaction("input");return f.insertNode(r,i,A(l)),f.setSelection(I(l,0)),f.build()}(t,n);const e=t.transaction("input");let r;b(n)||(r=L(t,e));const c=T(n,t.getBlockOrder()),i=r??c.blockId,l=r?0:c.offset,f=o();return e.splitBlock(i,l,f),e.setSelection(I(f,0)),e.build()}function F(t){const n=t.selection;if(!S(n))return null;const e=t.transaction("input");let o;if(b(n)||(o=L(t,e)),o)e.insertInlineNode(o,0,c(O("hard_break"))),e.setSelection(I(o,1));else{const{blockId:o,offset:r}=T(n,t.getBlockOrder());e.insertInlineNode(o,r,c(O("hard_break"))),e.setSelection(I(o,r+1))}return e.build()}function G(t){return J(t,"backward")}function H(t){return J(t,"forward")}function J(t,n){const e=t.selection;if(!S(e))return null;const o=t.getBlockOrder(),c=o.indexOf(e.anchor.blockId),i="backward"===n?c-1:c+1;if(i<0||i>=o.length)return null;const l=o[i];if(!l)return null;if(u(t,e.anchor.blockId)||u(t,l))return null;if(!d(t,e.anchor.blockId,l)&&a(t,e.anchor.blockId))return null;if(f(t,l)){const n=s(t.doc,l)??[];return t.transaction("input").setSelection(p(l,n)).build()}if("backward"===n){const n=t.getBlock(l);if(!n)return null;const o=r(n);return t.transaction("input").mergeBlocksAt(l,e.anchor.blockId).setSelection(I(l,o)).build()}return t.transaction("input").mergeBlocksAt(e.anchor.blockId,l).setSelection(I(e.anchor.blockId,e.anchor.offset)).build()}function K(t){const n=t.doc.children,e=n[0],o=n[n.length-1];if(!e||!o)return t.transaction("command").setSelection(t.selection).build();const c=_(e),i=y(o),l=t.getBlock(i),s=l?r(l):0;return t.transaction("command").setSelection(B({blockId:c,offset:0},{blockId:i,offset:s})).build()}function L(t,n){if(!S(t.selection))return;const e=t.getBlockOrder(),c=k(t.selection,e),i=e.indexOf(c.from.blockId),s=e.indexOf(c.to.blockId);if(i===s)return void n.deleteTextAt(c.from.blockId,c.from.offset,c.to.offset);const f=P(t,c.from.blockId),u=P(t,c.to.blockId);if(!(f===u||f<0||u<0))return function(t,n,e,c,i){const s=t.doc.children[c],f=t.doc.children[i];if(!s||!f)return;const u=l(s),d=l(f);let a,b=0;if(u||(a=o(),n.insertNode([],c,A(a)),b=1),u){const o=t.getBlock(e.from.blockId);if(o){const t=r(o);e.from.offset<t&&n.deleteTextAt(e.from.blockId,e.from.offset,t)}}d&&e.to.offset>0&&n.deleteTextAt(e.to.blockId,0,e.to.offset);const k=u?c+1:c+b;for(let o=d?i-1+b:i+b;o>=k;o--)n.removeNode([],o);return u&&d&&n.mergeBlocksAt(e.from.blockId,e.to.blockId),a}(t,n,c,f,u);!function(t,n,e,o,c,i){const l=t.getBlock(o.from.blockId);if(!l)return;const s=r(l);o.from.offset<s&&n.deleteTextAt(o.from.blockId,o.from.offset,s),o.to.offset>0&&n.deleteTextAt(o.to.blockId,0,o.to.offset);for(let f=c+1;f<i;f++){const c=e[f];if(!c)continue;const i=t.getBlock(c);if(!i)continue;const l=r(i);l>0&&n.deleteTextAt(c,0,l),n.mergeBlocksAt(o.from.blockId,c)}n.mergeBlocksAt(o.from.blockId,o.to.blockId)}(t,n,e,c,i,s)}function P(t,n){const e=s(t.doc,n);if(!e||0===e.length)return-1;const o=e[0];return t.doc.children.findIndex(t=>t.id===o)}export{Q as a,w as b,C as c,D as d,z as e,E as f,j as g,N as h,F as i,v as j,H as k,L as l,G as m,M as n,y as o,T as r,K as s};
2
+ //# sourceMappingURL=Commands-DwXBBVGR.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Commands-DwXBBVGR.mjs","sources":["../../src/commands/CommandHelpers.ts","../../src/commands/NodeSelectionCommands.ts","../../src/commands/GapCursorCommands.ts","../../src/commands/Commands.ts"],"sourcesContent":["/**\n * Shared helpers used across multiple command modules.\n *\n * - {@link getSiblings} — resolves a parent path to its child list\n * - {@link createEmptyParagraph} — builds an empty paragraph BlockNode\n * - {@link resolveInsertPoint} — normalizes a text selection to a single insert position\n */\n\nimport type { BlockNode, ChildNode } from '../model/Document.js';\nimport { createBlockNode, createTextNode, isBlockNode } from '../model/Document.js';\nimport { isCollapsed, selectionRange } from '../model/Selection.js';\nimport type { Selection } from '../model/Selection.js';\nimport type { BlockId } from '../model/TypeBrands.js';\nimport { nodeType } from '../model/TypeBrands.js';\nimport type { EditorState } from '../state/EditorState.js';\n\n/** The resolved insert position within a single block. */\nexport interface InsertPoint {\n\treadonly blockId: BlockId;\n\treadonly offset: number;\n}\n\n/** Resolves the children of a parent path: doc root or a nested block. */\nexport function getSiblings(\n\tstate: EditorState,\n\tparentPath: readonly BlockId[],\n): readonly ChildNode[] {\n\tif (parentPath.length === 0) return state.doc.children;\n\tconst parent: BlockNode | undefined = state.getBlock(\n\t\tparentPath[parentPath.length - 1] as BlockId,\n\t);\n\treturn parent ? parent.children : [];\n}\n\n/** Creates an empty paragraph block node with the given ID. */\nexport function createEmptyParagraph(id: BlockId): BlockNode {\n\treturn createBlockNode(nodeType('paragraph'), [createTextNode('')], id);\n}\n\n/**\n * Normalizes a text selection to a single insert point.\n *\n * - Collapsed selection → anchor position.\n * - Range selection → normalized `from` position (document-order start).\n */\nexport function resolveInsertPoint(sel: Selection, blockOrder: readonly BlockId[]): InsertPoint {\n\tif (isCollapsed(sel)) {\n\t\treturn { blockId: sel.anchor.blockId, offset: sel.anchor.offset };\n\t}\n\tconst range = selectionRange(sel, blockOrder);\n\treturn { blockId: range.from.blockId, offset: range.from.offset };\n}\n\n/** Extracts the parent path from a full node path (all elements except the last). */\nexport function extractParentPath(path: readonly string[] | undefined): BlockId[] {\n\treturn path && path.length > 1 ? (path.slice(0, -1) as BlockId[]) : [];\n}\n\n/** Finds the index of a block by ID within a sibling list. */\nexport function findSiblingIndex(siblings: readonly ChildNode[], targetId: BlockId): number {\n\treturn siblings.findIndex((c) => isBlockNode(c) && c.id === targetId);\n}\n","/**\n * Commands for NodeSelection: deleting void blocks, inserting paragraphs\n * after void blocks, and navigating arrow keys into/out of void blocks.\n */\n\nimport { type BlockNode, generateBlockId, getBlockLength, isBlockNode } from '../model/Document.js';\nimport { findNodePath } from '../model/NodeResolver.js';\nimport type { NodeSelection } from '../model/Selection.js';\nimport {\n\tcreateCollapsedSelection,\n\tcreateGapCursor,\n\tcreateNodeSelection,\n\tisCollapsed,\n\tisGapCursor,\n\tisNodeSelection,\n} from '../model/Selection.js';\nimport type { BlockId } from '../model/TypeBrands.js';\nimport type { EditorState } from '../state/EditorState.js';\nimport { isVoidBlock } from '../state/NavigationQueries.js';\nimport type { Transaction } from '../state/Transaction.js';\nimport {\n\tcreateEmptyParagraph,\n\textractParentPath,\n\tfindSiblingIndex,\n\tgetSiblings,\n} from './CommandHelpers.js';\n\n/**\n * Deletes the void block targeted by a NodeSelection and places cursor\n * on the adjacent block. If it's the only block, replaces with empty paragraph.\n */\nexport function deleteNodeSelection(state: EditorState, sel: NodeSelection): Transaction | null {\n\tconst path = findNodePath(state.doc, sel.nodeId);\n\tif (!path) return null;\n\n\tconst parentPath: BlockId[] = extractParentPath(path);\n\tconst siblings = getSiblings(state, parentPath);\n\n\tconst index: number = findSiblingIndex(siblings, sel.nodeId);\n\tif (index < 0) return null;\n\n\tconst builder = state.transaction('input');\n\n\t// If this is the only block in the document, insert empty paragraph first\n\tif (siblings.length === 1 && parentPath.length === 0) {\n\t\tconst newId = generateBlockId();\n\t\tbuilder.insertNode(parentPath, 0, createEmptyParagraph(newId));\n\t\tbuilder.removeNode(parentPath, 1);\n\t\tbuilder.setSelection(createCollapsedSelection(newId, 0));\n\t\treturn builder.build();\n\t}\n\n\tbuilder.removeNode(parentPath, index);\n\n\t// Find where to place cursor: prefer previous sibling leaf, else next sibling leaf.\n\tconst prevSibling = siblings[index - 1];\n\tif (prevSibling && isBlockNode(prevSibling)) {\n\t\tconst prevLeafId = findLastLeafBlockId(prevSibling);\n\t\tif (prevLeafId) {\n\t\t\tconst prevLeaf = state.getBlock(prevLeafId);\n\t\t\tconst prevLen = prevLeaf ? getBlockLength(prevLeaf) : 0;\n\t\t\tbuilder.setSelection(createCollapsedSelection(prevLeafId, prevLen));\n\t\t}\n\t} else {\n\t\tconst nextSibling = siblings[index + 1];\n\t\tif (nextSibling && isBlockNode(nextSibling)) {\n\t\t\tconst nextLeafId = findFirstLeafBlockId(nextSibling);\n\t\t\tif (nextLeafId) {\n\t\t\t\tbuilder.setSelection(createCollapsedSelection(nextLeafId, 0));\n\t\t\t}\n\t\t}\n\t}\n\n\treturn builder.build();\n}\n\n/** Inserts a new paragraph after a NodeSelection-targeted void block. */\nexport function insertParagraphAfterNodeSelection(\n\tstate: EditorState,\n\tsel: NodeSelection,\n): Transaction | null {\n\tconst path = findNodePath(state.doc, sel.nodeId);\n\tif (!path) return null;\n\n\tconst parentPath: BlockId[] = extractParentPath(path);\n\tconst siblings = getSiblings(state, parentPath);\n\n\tconst index: number = findSiblingIndex(siblings, sel.nodeId);\n\tif (index < 0) return null;\n\n\tconst newId = generateBlockId();\n\tconst builder = state.transaction('input');\n\tbuilder.insertNode(parentPath, index + 1, createEmptyParagraph(newId));\n\tbuilder.setSelection(createCollapsedSelection(newId, 0));\n\treturn builder.build();\n}\n\n/** Inserts text in a new paragraph after a NodeSelection-targeted void block. */\nexport function insertTextAfterNodeSelection(\n\tstate: EditorState,\n\tsel: NodeSelection,\n\ttext: string,\n\torigin: 'input' | 'paste',\n): Transaction {\n\tconst path = findNodePath(state.doc, sel.nodeId);\n\tconst parentPath: BlockId[] = extractParentPath(path);\n\tconst siblings = getSiblings(state, parentPath);\n\n\tconst index: number = findSiblingIndex(siblings, sel.nodeId);\n\n\tconst newId = generateBlockId();\n\tconst builder = state.transaction(origin);\n\n\tconst insertIdx = index >= 0 ? index + 1 : siblings.length;\n\tbuilder.insertNode(parentPath, insertIdx, createEmptyParagraph(newId));\n\tbuilder.insertText(newId, 0, text, []);\n\tbuilder.setSelection(createCollapsedSelection(newId, text.length));\n\treturn builder.build();\n}\n\n/**\n * Navigates arrow keys into/out of void blocks.\n * Returns a transaction if navigation should create a NodeSelection, or null.\n *\n * @param isRtl — When true, flips left/right to account for RTL block direction.\n */\nexport function navigateArrowIntoVoid(\n\tstate: EditorState,\n\tdirection: 'left' | 'right' | 'up' | 'down',\n\tisRtl?: boolean,\n): Transaction | null {\n\tconst sel = state.selection;\n\tconst blockOrder = state.getBlockOrder();\n\tconst effectiveDir: 'left' | 'right' | 'up' | 'down' =\n\t\tisRtl && (direction === 'left' || direction === 'right')\n\t\t\t? direction === 'left'\n\t\t\t\t? 'right'\n\t\t\t\t: 'left'\n\t\t\t: direction;\n\n\t// If currently on a NodeSelection, navigate away from it\n\tif (isNodeSelection(sel)) {\n\t\treturn navigateAwayFromNodeSelection(state, sel, effectiveDir, blockOrder);\n\t}\n\n\t// GapCursor is handled by navigateFromGapCursor in CaretNavigation\n\tif (isGapCursor(sel)) return null;\n\n\t// Text selection: check if navigating into a void block\n\tif (!isCollapsed(sel)) return null;\n\n\treturn navigateIntoVoid(state, sel, effectiveDir, blockOrder);\n}\n\n/** Finds the first leaf (deepest-first-child) block ID in a subtree. */\nexport function findFirstLeafBlockId(node: BlockNode): BlockId {\n\tlet current: BlockNode = node;\n\twhile (true) {\n\t\tconst firstBlockChild = current.children.find((child): child is BlockNode =>\n\t\t\tisBlockNode(child),\n\t\t);\n\t\tif (!firstBlockChild) return current.id;\n\t\tcurrent = firstBlockChild;\n\t}\n}\n\n/** Finds the last leaf (deepest-last-child) block ID in a subtree. */\nexport function findLastLeafBlockId(node: BlockNode): BlockId {\n\tlet current: BlockNode = node;\n\twhile (true) {\n\t\tlet lastBlockChild: BlockNode | undefined;\n\t\tfor (let i = current.children.length - 1; i >= 0; i--) {\n\t\t\tconst child = current.children[i];\n\t\t\tif (child && isBlockNode(child)) {\n\t\t\t\tlastBlockChild = child;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!lastBlockChild) return current.id;\n\t\tcurrent = lastBlockChild;\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\n/** Handles navigation away from a NodeSelection (arrow keys while void is selected). */\nfunction navigateAwayFromNodeSelection(\n\tstate: EditorState,\n\tsel: NodeSelection,\n\tdirection: 'left' | 'right' | 'up' | 'down',\n\tblockOrder: readonly BlockId[],\n): Transaction | null {\n\tconst nodeIdx = blockOrder.indexOf(sel.nodeId);\n\tconst nodePath = (findNodePath(state.doc, sel.nodeId) ?? []) as BlockId[];\n\n\tif (direction === 'left' || direction === 'up') {\n\t\tif (nodeIdx > 0) {\n\t\t\tconst prevId = blockOrder[nodeIdx - 1];\n\t\t\tif (!prevId) return null;\n\t\t\tif (isVoidBlock(state, prevId)) {\n\t\t\t\treturn state\n\t\t\t\t\t.transaction('input')\n\t\t\t\t\t.setSelection(createGapCursor(sel.nodeId, 'before', nodePath))\n\t\t\t\t\t.build();\n\t\t\t}\n\t\t\tconst prevBlock = state.getBlock(prevId);\n\t\t\tconst prevLen = prevBlock ? getBlockLength(prevBlock) : 0;\n\t\t\treturn state\n\t\t\t\t.transaction('input')\n\t\t\t\t.setSelection(createCollapsedSelection(prevId, prevLen))\n\t\t\t\t.build();\n\t\t}\n\t\treturn state\n\t\t\t.transaction('input')\n\t\t\t.setSelection(createGapCursor(sel.nodeId, 'before', nodePath))\n\t\t\t.build();\n\t}\n\n\t// right or down\n\tif (nodeIdx < blockOrder.length - 1) {\n\t\tconst nextId = blockOrder[nodeIdx + 1];\n\t\tif (!nextId) return null;\n\t\tif (isVoidBlock(state, nextId)) {\n\t\t\treturn state\n\t\t\t\t.transaction('input')\n\t\t\t\t.setSelection(createGapCursor(sel.nodeId, 'after', nodePath))\n\t\t\t\t.build();\n\t\t}\n\t\treturn state.transaction('input').setSelection(createCollapsedSelection(nextId, 0)).build();\n\t}\n\treturn state\n\t\t.transaction('input')\n\t\t.setSelection(createGapCursor(sel.nodeId, 'after', nodePath))\n\t\t.build();\n}\n\n/** Handles text selection navigating into an adjacent void block. */\nfunction navigateIntoVoid(\n\tstate: EditorState,\n\tsel: { readonly anchor: { readonly blockId: BlockId; readonly offset: number } },\n\tdirection: 'left' | 'right' | 'up' | 'down',\n\tblockOrder: readonly BlockId[],\n): Transaction | null {\n\tconst blockIdx = blockOrder.indexOf(sel.anchor.blockId);\n\tconst block = state.getBlock(sel.anchor.blockId);\n\tif (!block) return null;\n\tconst blockLen = getBlockLength(block);\n\n\tif (direction === 'right' || direction === 'down') {\n\t\tif (sel.anchor.offset === blockLen && blockIdx < blockOrder.length - 1) {\n\t\t\tconst nextId = blockOrder[blockIdx + 1];\n\t\t\tif (nextId && isVoidBlock(state, nextId)) {\n\t\t\t\tconst path = findNodePath(state.doc, nextId) ?? [];\n\t\t\t\treturn state\n\t\t\t\t\t.transaction('input')\n\t\t\t\t\t.setSelection(createNodeSelection(nextId, path as BlockId[]))\n\t\t\t\t\t.build();\n\t\t\t}\n\t\t}\n\t}\n\n\tif (direction === 'left' || direction === 'up') {\n\t\tif (sel.anchor.offset === 0 && blockIdx > 0) {\n\t\t\tconst prevId = blockOrder[blockIdx - 1];\n\t\t\tif (prevId && isVoidBlock(state, prevId)) {\n\t\t\t\tconst path = findNodePath(state.doc, prevId) ?? [];\n\t\t\t\treturn state\n\t\t\t\t\t.transaction('input')\n\t\t\t\t\t.setSelection(createNodeSelection(prevId, path as BlockId[]))\n\t\t\t\t\t.build();\n\t\t\t}\n\t\t}\n\t}\n\n\treturn null;\n}\n","/**\n * Commands for GapCursor: deleting void blocks adjacent to gap cursors\n * and inserting paragraphs at gap positions.\n */\n\nimport { generateBlockId, getBlockLength } from '../model/Document.js';\nimport { findNodePath } from '../model/NodeResolver.js';\nimport type { GapCursorSelection, NodeSelection } from '../model/Selection.js';\nimport { createCollapsedSelection, createNodeSelection } from '../model/Selection.js';\nimport type { BlockId } from '../model/TypeBrands.js';\nimport type { EditorState } from '../state/EditorState.js';\nimport { isVoidBlock } from '../state/NavigationQueries.js';\nimport type { Transaction } from '../state/Transaction.js';\nimport {\n\tcreateEmptyParagraph,\n\textractParentPath,\n\tfindSiblingIndex,\n\tgetSiblings,\n} from './CommandHelpers.js';\nimport { deleteNodeSelection } from './NodeSelectionCommands.js';\n\n/**\n * Deletes the void block adjacent to a GapCursor when pressing Backspace.\n *\n * - `side === 'after'` → void block is behind the cursor → delete it.\n * - `side === 'before'` → void block is ahead → navigate backward (to previous block).\n * - At document start with `side === 'before'` → `null` (no-op).\n */\nexport function deleteBackwardAtGap(\n\tstate: EditorState,\n\tsel: GapCursorSelection,\n): Transaction | null {\n\tif (sel.side === 'after') {\n\t\treturn deleteVoidAtGap(state, sel);\n\t}\n\n\t// side === 'before': navigate to previous block\n\tconst blockOrder: readonly BlockId[] = state.getBlockOrder();\n\tconst blockIdx: number = blockOrder.indexOf(sel.blockId);\n\n\tif (blockIdx <= 0) return null;\n\n\tconst prevId: BlockId | undefined = blockOrder[blockIdx - 1];\n\tif (!prevId) return null;\n\n\tif (isVoidBlock(state, prevId)) {\n\t\tconst path = findNodePath(state.doc, prevId) ?? [];\n\t\treturn state\n\t\t\t.transaction('input')\n\t\t\t.setSelection(createNodeSelection(prevId, path as BlockId[]))\n\t\t\t.build();\n\t}\n\n\tconst prevBlock = state.getBlock(prevId);\n\tif (!prevBlock) return null;\n\tconst prevLen: number = getBlockLength(prevBlock);\n\treturn state.transaction('input').setSelection(createCollapsedSelection(prevId, prevLen)).build();\n}\n\n/**\n * Deletes the void block adjacent to a GapCursor when pressing Delete.\n *\n * - `side === 'before'` → void block is ahead of the cursor → delete it.\n * - `side === 'after'` → void block is behind → navigate forward (to next block).\n * - At document end with `side === 'after'` → `null` (no-op).\n */\nexport function deleteForwardAtGap(\n\tstate: EditorState,\n\tsel: GapCursorSelection,\n): Transaction | null {\n\tif (sel.side === 'before') {\n\t\treturn deleteVoidAtGap(state, sel);\n\t}\n\n\t// side === 'after': navigate to next block\n\tconst blockOrder: readonly BlockId[] = state.getBlockOrder();\n\tconst blockIdx: number = blockOrder.indexOf(sel.blockId);\n\n\tif (blockIdx >= blockOrder.length - 1) return null;\n\n\tconst nextId: BlockId | undefined = blockOrder[blockIdx + 1];\n\tif (!nextId) return null;\n\n\tif (isVoidBlock(state, nextId)) {\n\t\tconst path = findNodePath(state.doc, nextId) ?? [];\n\t\treturn state\n\t\t\t.transaction('input')\n\t\t\t.setSelection(createNodeSelection(nextId, path as BlockId[]))\n\t\t\t.build();\n\t}\n\n\treturn state.transaction('input').setSelection(createCollapsedSelection(nextId, 0)).build();\n}\n\n/** Deletes the void block that the GapCursor is adjacent to, delegating to deleteNodeSelection. */\nfunction deleteVoidAtGap(state: EditorState, sel: GapCursorSelection): Transaction | null {\n\tconst path = (findNodePath(state.doc, sel.blockId) ?? []) as BlockId[];\n\tconst nodeSel: NodeSelection = createNodeSelection(sel.blockId, path);\n\treturn deleteNodeSelection(state, nodeSel);\n}\n\n/** Inserts a new paragraph at a GapCursor position (before or after the void block). */\nexport function insertParagraphAtGap(\n\tstate: EditorState,\n\tsel: GapCursorSelection,\n): Transaction | null {\n\tconst path = findNodePath(state.doc, sel.blockId);\n\tif (!path) return null;\n\n\tconst parentPath: BlockId[] = extractParentPath(path);\n\tconst siblings = getSiblings(state, parentPath);\n\n\tconst index: number = findSiblingIndex(siblings, sel.blockId);\n\tif (index < 0) return null;\n\n\tconst insertIdx: number = sel.side === 'before' ? index : index + 1;\n\tconst newId = generateBlockId();\n\tconst builder = state.transaction('input');\n\tbuilder.insertNode(parentPath, insertIdx, createEmptyParagraph(newId));\n\tbuilder.setSelection(createCollapsedSelection(newId, 0));\n\treturn builder.build();\n}\n\n/** Inserts text in a new paragraph at a GapCursor position. */\nexport function insertTextAtGap(\n\tstate: EditorState,\n\tsel: GapCursorSelection,\n\ttext: string,\n\torigin: 'input' | 'paste',\n): Transaction {\n\tconst path = findNodePath(state.doc, sel.blockId);\n\tconst parentPath: BlockId[] = extractParentPath(path);\n\tconst siblings = getSiblings(state, parentPath);\n\n\tconst index: number = findSiblingIndex(siblings, sel.blockId);\n\tconst insertIdx: number =\n\t\tsel.side === 'before' ? Math.max(index, 0) : index >= 0 ? index + 1 : siblings.length;\n\n\tconst newId = generateBlockId();\n\tconst builder = state.transaction(origin);\n\tbuilder.insertNode(parentPath, insertIdx, createEmptyParagraph(newId));\n\tbuilder.insertText(newId, 0, text, []);\n\tbuilder.setSelection(createCollapsedSelection(newId, text.length));\n\treturn builder.build();\n}\n","/**\n * Core editor commands and barrel re-exports from submodules.\n *\n * This module contains text insertion, block splitting, block merging,\n * selection deletion, and select-all. Mark, delete, gap-cursor, node-selection,\n * and word-boundary commands are re-exported from their respective modules.\n */\n\nimport {\n\ttype Mark,\n\tcreateInlineNode,\n\tgenerateBlockId,\n\tgetBlockLength,\n\tgetBlockMarksAtOffset,\n\tisLeafBlock,\n} from '../model/Document.js';\nimport { findNodePath } from '../model/NodeResolver.js';\nimport {\n\tcreateCollapsedSelection,\n\tcreateNodeSelection,\n\tcreateSelection,\n\tisCollapsed,\n\tisGapCursor,\n\tisNodeSelection,\n\tisTextSelection,\n\tselectionRange,\n} from '../model/Selection.js';\nimport { type BlockId, inlineType } from '../model/TypeBrands.js';\nimport type { EditorState } from '../state/EditorState.js';\nimport {\n\tisInsideIsolating,\n\tisIsolatingBlock,\n\tisVoidBlock,\n\tsharesParent,\n} from '../state/NavigationQueries.js';\nimport type { Transaction } from '../state/Transaction.js';\nimport type { TransactionBuilder } from '../state/Transaction.js';\nimport { createEmptyParagraph, resolveInsertPoint } from './CommandHelpers.js';\nimport { insertParagraphAtGap, insertTextAtGap } from './GapCursorCommands.js';\nimport {\n\tdeleteNodeSelection,\n\tfindFirstLeafBlockId,\n\tfindLastLeafBlockId,\n\tinsertParagraphAfterNodeSelection,\n\tinsertTextAfterNodeSelection,\n} from './NodeSelectionCommands.js';\n\n// --- Re-exports from submodules ---\n\nexport {\n\tcanCrossBlockBoundary,\n\tisInsideIsolating,\n\tisIsolatingBlock,\n\tisVoidBlock,\n\tsharesParent,\n} from '../state/NavigationQueries.js';\n\nexport type { FeatureConfig } from './MarkCommands.js';\nexport {\n\tisMarkActive,\n\ttoggleBold,\n\ttoggleItalic,\n\ttoggleMark,\n\ttoggleUnderline,\n} from './MarkCommands.js';\n\nexport {\n\tdeleteBackward,\n\tdeleteForward,\n\tdeleteSoftLineBackward,\n\tdeleteSoftLineForward,\n\tdeleteWordBackward,\n\tdeleteWordForward,\n} from './DeleteCommands.js';\n\nexport {\n\tdeleteNodeSelection,\n\tfindFirstLeafBlockId,\n\tfindLastLeafBlockId,\n\tinsertParagraphAfterNodeSelection,\n\tinsertTextAfterNodeSelection,\n\tnavigateArrowIntoVoid,\n} from './NodeSelectionCommands.js';\n\nexport {\n\tdeleteBackwardAtGap,\n\tdeleteForwardAtGap,\n\tinsertParagraphAtGap,\n\tinsertTextAtGap,\n} from './GapCursorCommands.js';\n\nexport {\n\tfindWordBoundaryBackward,\n\tfindWordBoundaryForward,\n} from './WordBoundary.js';\n\nexport {\n\tapplyAttributedMark,\n\tgetMarkAttrAtSelection,\n\tisAttributedMarkActive,\n\tremoveAttributedMark,\n} from './AttributedMarkCommands.js';\n\nexport { forEachBlockInRange } from './RangeIterator.js';\n\n// --- Text Commands ---\n\n/** Inserts text at the current selection, replacing any selected range. */\nexport function insertTextCommand(\n\tstate: EditorState,\n\ttext: string,\n\torigin: 'input' | 'paste' = 'input',\n): Transaction {\n\tconst sel = state.selection;\n\n\t// NodeSelection: insert paragraph after void block with the text\n\tif (isNodeSelection(sel)) {\n\t\treturn insertTextAfterNodeSelection(state, sel, text, origin);\n\t}\n\n\t// GapCursor: insert paragraph at the gap position with the text\n\tif (isGapCursor(sel)) {\n\t\treturn insertTextAtGap(state, sel, text, origin);\n\t}\n\n\tconst builder = state.transaction(origin);\n\tconst marks = resolveActiveMarks(state);\n\n\tlet landingId: BlockId | undefined;\n\tif (!isCollapsed(sel)) {\n\t\tlandingId = addDeleteSelectionSteps(state, builder);\n\t}\n\n\tconst resolved = resolveInsertPoint(sel, state.getBlockOrder());\n\tconst insertBlockId: BlockId = landingId ?? resolved.blockId;\n\tconst insertOffset: number = landingId ? 0 : resolved.offset;\n\n\tbuilder.insertText(insertBlockId, insertOffset, text, marks);\n\tbuilder.setSelection(createCollapsedSelection(insertBlockId, insertOffset + text.length));\n\n\treturn builder.build();\n}\n\n/** Deletes the current selection. */\nexport function deleteSelectionCommand(state: EditorState): Transaction | null {\n\tif (isNodeSelection(state.selection)) {\n\t\treturn deleteNodeSelection(state, state.selection);\n\t}\n\tif (isGapCursor(state.selection)) return null;\n\tif (isCollapsed(state.selection)) return null;\n\n\tconst builder = state.transaction('input');\n\tconst landingId: BlockId | undefined = addDeleteSelectionSteps(state, builder);\n\n\tconst range = selectionRange(state.selection, state.getBlockOrder());\n\tconst cursorBlockId: BlockId = landingId ?? range.from.blockId;\n\tconst cursorOffset: number = landingId ? 0 : range.from.offset;\n\tbuilder.setSelection(createCollapsedSelection(cursorBlockId, cursorOffset));\n\n\treturn builder.build();\n}\n\n/** Splits the current block at the cursor position (Enter key). */\nexport function splitBlockCommand(state: EditorState): Transaction | null {\n\tconst sel = state.selection;\n\n\t// NodeSelection: insert empty paragraph after the void block\n\tif (isNodeSelection(sel)) {\n\t\treturn insertParagraphAfterNodeSelection(state, sel);\n\t}\n\n\t// GapCursor: insert empty paragraph at the gap position\n\tif (isGapCursor(sel)) {\n\t\treturn insertParagraphAtGap(state, sel);\n\t}\n\n\tconst builder = state.transaction('input');\n\n\tlet landingId: BlockId | undefined;\n\tif (!isCollapsed(sel)) {\n\t\tlandingId = addDeleteSelectionSteps(state, builder);\n\t}\n\n\tconst resolved = resolveInsertPoint(sel, state.getBlockOrder());\n\tconst blockId: BlockId = landingId ?? resolved.blockId;\n\tconst offset: number = landingId ? 0 : resolved.offset;\n\tconst newBlockId = generateBlockId();\n\n\t// splitBlock operates at the same level in the tree — the StepApplication\n\t// handles this correctly because it looks up the block by ID recursively.\n\tbuilder.splitBlock(blockId, offset, newBlockId);\n\tbuilder.setSelection(createCollapsedSelection(newBlockId, 0));\n\n\treturn builder.build();\n}\n\n/** Inserts a hard line break (InlineNode) at the current cursor position. */\nexport function insertHardBreakCommand(state: EditorState): Transaction | null {\n\tconst sel = state.selection;\n\n\tif (!isTextSelection(sel)) return null;\n\n\tconst builder = state.transaction('input');\n\n\tlet cursorBlockId: BlockId | undefined;\n\tif (!isCollapsed(sel)) {\n\t\tconst landingId: BlockId | undefined = addDeleteSelectionSteps(state, builder);\n\t\tcursorBlockId = landingId;\n\t}\n\n\tif (cursorBlockId) {\n\t\t// Cross-root deletion replaced from-block; insert hard break in landing block\n\t\tbuilder.insertInlineNode(cursorBlockId, 0, createInlineNode(inlineType('hard_break')));\n\t\tbuilder.setSelection(createCollapsedSelection(cursorBlockId, 1));\n\t} else {\n\t\tconst { blockId: insertBlockId, offset: insertOffset } = resolveInsertPoint(\n\t\t\tsel,\n\t\t\tstate.getBlockOrder(),\n\t\t);\n\t\tbuilder.insertInlineNode(\n\t\t\tinsertBlockId,\n\t\t\tinsertOffset,\n\t\t\tcreateInlineNode(inlineType('hard_break')),\n\t\t);\n\t\tbuilder.setSelection(createCollapsedSelection(insertBlockId, insertOffset + 1));\n\t}\n\n\treturn builder.build();\n}\n\n/**\n * Merges the current block with the previous block, respecting\n * isolating boundaries and void blocks.\n */\nexport function mergeBlockBackward(state: EditorState): Transaction | null {\n\treturn mergeAdjacentBlock(state, 'backward');\n}\n\n/**\n * Merges the next block into the current block, respecting\n * isolating boundaries and void blocks.\n */\nexport function mergeBlockForward(state: EditorState): Transaction | null {\n\treturn mergeAdjacentBlock(state, 'forward');\n}\n\n/**\n * Shared implementation for merging adjacent blocks in either direction.\n * Validates selection, isolating boundaries, and void blocks before merging.\n */\nfunction mergeAdjacentBlock(\n\tstate: EditorState,\n\tdirection: 'backward' | 'forward',\n): Transaction | null {\n\tconst sel = state.selection;\n\tif (!isTextSelection(sel)) return null;\n\n\tconst blockOrder = state.getBlockOrder();\n\tconst blockIdx: number = blockOrder.indexOf(sel.anchor.blockId);\n\n\tconst adjacentIdx: number = direction === 'backward' ? blockIdx - 1 : blockIdx + 1;\n\tif (adjacentIdx < 0 || adjacentIdx >= blockOrder.length) return null;\n\n\tconst adjacentId: BlockId | undefined = blockOrder[adjacentIdx];\n\tif (!adjacentId) return null;\n\n\tif (isIsolatingBlock(state, sel.anchor.blockId) || isIsolatingBlock(state, adjacentId)) {\n\t\treturn null;\n\t}\n\tif (!sharesParent(state, sel.anchor.blockId, adjacentId)) {\n\t\tif (isInsideIsolating(state, sel.anchor.blockId)) return null;\n\t}\n\n\tif (isVoidBlock(state, adjacentId)) {\n\t\tconst path = findNodePath(state.doc, adjacentId) ?? [];\n\t\treturn state\n\t\t\t.transaction('input')\n\t\t\t.setSelection(createNodeSelection(adjacentId, path as BlockId[]))\n\t\t\t.build();\n\t}\n\n\tif (direction === 'backward') {\n\t\tconst prevBlock = state.getBlock(adjacentId);\n\t\tif (!prevBlock) return null;\n\t\tconst prevLen: number = getBlockLength(prevBlock);\n\t\treturn state\n\t\t\t.transaction('input')\n\t\t\t.mergeBlocksAt(adjacentId, sel.anchor.blockId)\n\t\t\t.setSelection(createCollapsedSelection(adjacentId, prevLen))\n\t\t\t.build();\n\t}\n\n\treturn state\n\t\t.transaction('input')\n\t\t.mergeBlocksAt(sel.anchor.blockId, adjacentId)\n\t\t.setSelection(createCollapsedSelection(sel.anchor.blockId, sel.anchor.offset))\n\t\t.build();\n}\n\n/** Selects all content in the editor, using leaf block endpoints. */\nexport function selectAll(state: EditorState): Transaction {\n\tconst blocks = state.doc.children;\n\tconst firstBlock = blocks[0];\n\tconst lastBlock = blocks[blocks.length - 1];\n\tif (!firstBlock || !lastBlock)\n\t\treturn state.transaction('command').setSelection(state.selection).build();\n\n\tconst firstLeafId: BlockId = findFirstLeafBlockId(firstBlock);\n\tconst lastLeafId: BlockId = findLastLeafBlockId(lastBlock);\n\tconst lastLeaf = state.getBlock(lastLeafId);\n\tconst lastLeafLen: number = lastLeaf ? getBlockLength(lastLeaf) : 0;\n\n\treturn state\n\t\t.transaction('command')\n\t\t.setSelection(\n\t\t\tcreateSelection(\n\t\t\t\t{ blockId: firstLeafId, offset: 0 },\n\t\t\t\t{ blockId: lastLeafId, offset: lastLeafLen },\n\t\t\t),\n\t\t)\n\t\t.build();\n}\n\n// --- Internal Helpers ---\n\nfunction resolveActiveMarks(state: EditorState): readonly Mark[] {\n\tif (state.storedMarks) return state.storedMarks;\n\tif (!isTextSelection(state.selection)) return [];\n\n\tconst block = state.getBlock(state.selection.anchor.blockId);\n\tif (!block) return [];\n\n\treturn getBlockMarksAtOffset(block, state.selection.anchor.offset);\n}\n\n/**\n * Adds steps to delete the current text selection.\n * Returns a replacement cursor block ID when the original from-block\n * was inside a composite root that got removed (undefined otherwise).\n */\nexport function addDeleteSelectionSteps(\n\tstate: EditorState,\n\tbuilder: TransactionBuilder,\n): BlockId | undefined {\n\tif (!isTextSelection(state.selection)) return undefined;\n\tconst blockOrder = state.getBlockOrder();\n\tconst range = selectionRange(state.selection, blockOrder);\n\tconst fromIdx = blockOrder.indexOf(range.from.blockId);\n\tconst toIdx = blockOrder.indexOf(range.to.blockId);\n\n\tif (fromIdx === toIdx) {\n\t\tbuilder.deleteTextAt(range.from.blockId, range.from.offset, range.to.offset);\n\t\treturn undefined;\n\t}\n\n\tconst fromRootIdx: number = getRootBlockIndex(state, range.from.blockId);\n\tconst toRootIdx: number = getRootBlockIndex(state, range.to.blockId);\n\n\tif (fromRootIdx === toRootIdx || fromRootIdx < 0 || toRootIdx < 0) {\n\t\tdeleteLeafRange(state, builder, blockOrder, range, fromIdx, toIdx);\n\t\treturn undefined;\n\t}\n\n\treturn deleteCrossRootRange(state, builder, range, fromRootIdx, toRootIdx);\n}\n\n/** Returns the root-level ancestor index in doc.children for a given block. */\nfunction getRootBlockIndex(state: EditorState, blockId: BlockId): number {\n\tconst path = findNodePath(state.doc, blockId);\n\tif (!path || path.length === 0) return -1;\n\tconst rootId: string = path[0] as string;\n\treturn state.doc.children.findIndex((c) => c.id === rootId);\n}\n\n/** Deletes a multi-block selection where all blocks share the same root ancestor. */\nfunction deleteLeafRange(\n\tstate: EditorState,\n\tbuilder: TransactionBuilder,\n\tblockOrder: readonly BlockId[],\n\trange: {\n\t\treadonly from: { readonly blockId: BlockId; readonly offset: number };\n\t\treadonly to: { readonly blockId: BlockId; readonly offset: number };\n\t},\n\tfromIdx: number,\n\ttoIdx: number,\n): void {\n\tconst firstBlock = state.getBlock(range.from.blockId);\n\tif (!firstBlock) return;\n\tconst firstLen = getBlockLength(firstBlock);\n\n\tif (range.from.offset < firstLen) {\n\t\tbuilder.deleteTextAt(range.from.blockId, range.from.offset, firstLen);\n\t}\n\n\tif (range.to.offset > 0) {\n\t\tbuilder.deleteTextAt(range.to.blockId, 0, range.to.offset);\n\t}\n\n\tfor (let i = fromIdx + 1; i < toIdx; i++) {\n\t\tconst midBlockId = blockOrder[i];\n\t\tif (!midBlockId) continue;\n\t\tconst midBlock = state.getBlock(midBlockId);\n\t\tif (!midBlock) continue;\n\t\tconst midLen = getBlockLength(midBlock);\n\t\tif (midLen > 0) {\n\t\t\tbuilder.deleteTextAt(midBlockId, 0, midLen);\n\t\t}\n\t\tbuilder.mergeBlocksAt(range.from.blockId, midBlockId);\n\t}\n\n\tbuilder.mergeBlocksAt(range.from.blockId, range.to.blockId);\n}\n\n/**\n * Deletes a selection spanning different root-level ancestors.\n * Removes intermediate and composite root blocks, merges leaf roots.\n * Returns a replacement cursor block ID if from was inside a removed composite.\n */\nfunction deleteCrossRootRange(\n\tstate: EditorState,\n\tbuilder: TransactionBuilder,\n\trange: {\n\t\treadonly from: { readonly blockId: BlockId; readonly offset: number };\n\t\treadonly to: { readonly blockId: BlockId; readonly offset: number };\n\t},\n\tfromRootIdx: number,\n\ttoRootIdx: number,\n): BlockId | undefined {\n\tconst fromRoot = state.doc.children[fromRootIdx];\n\tconst toRoot = state.doc.children[toRootIdx];\n\tif (!fromRoot || !toRoot) return undefined;\n\n\tconst fromIsLeaf: boolean = isLeafBlock(fromRoot);\n\tconst toIsLeaf: boolean = isLeafBlock(toRoot);\n\n\t// When from is inside a composite root, insert a landing paragraph\n\t// so callers can reference a surviving block for cursor/insert.\n\tlet landingId: BlockId | undefined;\n\tlet indexShift = 0;\n\n\tif (!fromIsLeaf) {\n\t\tlandingId = generateBlockId();\n\t\tbuilder.insertNode([], fromRootIdx, createEmptyParagraph(landingId));\n\t\tindexShift = 1;\n\t}\n\n\t// Delete text in from-leaf (only for leaf roots; composite roots are removed entirely)\n\tif (fromIsLeaf) {\n\t\tconst fromBlock = state.getBlock(range.from.blockId);\n\t\tif (fromBlock) {\n\t\t\tconst fromLen: number = getBlockLength(fromBlock);\n\t\t\tif (range.from.offset < fromLen) {\n\t\t\t\tbuilder.deleteTextAt(range.from.blockId, range.from.offset, fromLen);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Delete text in to-leaf (only for leaf roots)\n\tif (toIsLeaf && range.to.offset > 0) {\n\t\tbuilder.deleteTextAt(range.to.blockId, 0, range.to.offset);\n\t}\n\n\t// Remove root-level blocks in descending index order.\n\t// Keep from-root if it's a leaf; remove if composite (shifted by indexShift).\n\t// Keep to-root if it's a leaf (will merge into from); remove if composite.\n\tconst removeEnd: number = toIsLeaf ? toRootIdx - 1 + indexShift : toRootIdx + indexShift;\n\tconst removeStart: number = fromIsLeaf ? fromRootIdx + 1 : fromRootIdx + indexShift;\n\n\tfor (let i = removeEnd; i >= removeStart; i--) {\n\t\tbuilder.removeNode([], i);\n\t}\n\n\t// Merge to-root into from if both are leaf roots\n\tif (fromIsLeaf && toIsLeaf) {\n\t\tbuilder.mergeBlocksAt(range.from.blockId, range.to.blockId);\n\t}\n\n\treturn landingId;\n}\n"],"names":["getSiblings","state","parentPath","length","doc","children","parent","getBlock","createEmptyParagraph","id","createBlockNode","nodeType","createTextNode","resolveInsertPoint","sel","blockOrder","isCollapsed","blockId","anchor","offset","range","selectionRange","from","extractParentPath","path","slice","findSiblingIndex","siblings","targetId","findIndex","c","isBlockNode","deleteNodeSelection","findNodePath","nodeId","index","builder","transaction","newId","generateBlockId","insertNode","removeNode","setSelection","createCollapsedSelection","build","prevSibling","prevLeafId","findLastLeafBlockId","prevLeaf","prevLen","getBlockLength","nextSibling","nextLeafId","findFirstLeafBlockId","navigateArrowIntoVoid","direction","isRtl","selection","getBlockOrder","effectiveDir","isNodeSelection","nodeIdx","indexOf","nodePath","prevId","isVoidBlock","createGapCursor","prevBlock","nextId","navigateAwayFromNodeSelection","isGapCursor","blockIdx","block","blockLen","createNodeSelection","navigateIntoVoid","node","current","firstBlockChild","find","child","lastBlockChild","i","deleteBackwardAtGap","side","deleteVoidAtGap","deleteForwardAtGap","insertTextCommand","text","origin","insertIdx","insertText","insertTextAfterNodeSelection","Math","max","insertTextAtGap","marks","storedMarks","isTextSelection","getBlockMarksAtOffset","resolveActiveMarks","landingId","addDeleteSelectionSteps","resolved","insertBlockId","insertOffset","deleteSelectionCommand","cursorBlockId","cursorOffset","splitBlockCommand","insertParagraphAfterNodeSelection","insertParagraphAtGap","newBlockId","splitBlock","insertHardBreakCommand","insertInlineNode","createInlineNode","inlineType","mergeBlockBackward","mergeAdjacentBlock","mergeBlockForward","adjacentIdx","adjacentId","isIsolatingBlock","sharesParent","isInsideIsolating","mergeBlocksAt","selectAll","blocks","firstBlock","lastBlock","firstLeafId","lastLeafId","lastLeaf","lastLeafLen","createSelection","fromIdx","toIdx","to","deleteTextAt","fromRootIdx","getRootBlockIndex","toRootIdx","fromRoot","toRoot","fromIsLeaf","isLeafBlock","toIsLeaf","indexShift","fromBlock","fromLen","removeStart","deleteCrossRootRange","firstLen","midBlockId","midBlock","midLen","deleteLeafRange","rootId"],"mappings":"y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BA,EAAKrB,OAAc,OAAO,EACvC,MAAM2J,EAAiBtI,EAAK,GAC5B,OAAOvB,EAAMG,IAAIC,SAASwB,UAAWC,GAAMA,EAAErB,KAAOqJ,EACrD"}
@@ -0,0 +1,2 @@
1
+ function t(t,n,r){const o=[];return function(t,n,r,o){const i=s(t);let f=0;for(const s of i){const t=f+(e(s)?1:s.text.length);if(t<=n||f>=r)f=t;else{if(e(s))o.onInline?.(s);else{const t=Math.max(0,n-f),e=Math.min(s.text.length,r-f),i=s.text.slice(t,e);i.length>0&&o.onText(i,s.marks)}f=t}}}(t,n,r,{onText(t,n){o.push({text:t,marks:n})}}),o}function n(t){return"object"==typeof t&&null!==t&&"text"===t.type&&"string"==typeof t.text}function e(t){return"object"==typeof t&&null!==t&&"inline"===t.type&&"string"==typeof t.inlineType}function r(t){return"object"==typeof t&&null!==t&&"string"==typeof t.id&&"string"==typeof t.type&&"text"!==t.type&&"inline"!==t.type&&Array.isArray(t.children)}function o(t){return t.children.every(t=>n(t)||e(t))}function i(t){return t.children.filter(t=>n(t))}function s(t){return t.children.filter(t=>n(t)||e(t))}function f(t){return t.children.filter(t=>r(t))}function u(){return`block-${crypto.randomUUID()}`}function c(t){return{children:t??[l("paragraph")]}}function l(t,n,e,r){return{id:e??u(),type:t,...r?{attrs:r}:{},children:n??[a("")]}}function a(t,n){return{type:"text",text:t,marks:n??[]}}function h(t,n){return{type:"inline",inlineType:t,attrs:n??{}}}function g(t){const e=s(t);let r="";for(const o of e)n(o)&&(r+=o.text);return r}function y(t){const n=s(t);let r=0;for(const o of n)r+=e(o)?1:o.text.length;return r}function p(t,r){const o=s(t);let i=0;for(const n of o){if(e(n)){if(r===i)return[];i+=1;continue}const t=i+n.text.length;if(r>=i&&r<t)return n.marks;if(r===i&&0===n.text.length)return n.marks;i=t}for(let e=o.length-1;e>=0;e--){const t=o[e];if(t&&n(t))return t.marks}return[]}function x(t,n){return t.length===n.length&&t.every(t=>n.some(n=>function(t,n){if(t.type!==n.type)return!1;const e=t.attrs,r=n.attrs;if(!e&&!r)return!0;if(!e||!r)return!1;const o=Object.keys(e),i=Object.keys(r);return o.length===i.length&&o.every(t=>e[t]===r[t])}(t,n)))}function m(t,n){return t.some(t=>t.type===n)}function k(t,n){return m(t,n.type)?t:[...t,n]}function d(t,n){return t.filter(t=>t.type!==n)}function b(t){if(0===t.length)return[a("")];if(t.every(t=>n(t)))return function(t){if(0===t.length)return[a("")];const n=[];for(const e of t){const t=n[n.length-1];t&&x(t.marks,e.marks)?n[n.length-1]=a(t.text+e.text,t.marks):(e.text.length>0||0===n.length)&&n.push(e)}return 0===n.length?[a("")]:n}(t);const r=[];for(const i of t){if(e(i)){r.push(i);continue}const t=r[r.length-1];t&&n(t)&&x(t.marks,i.marks)?r[r.length-1]=a(t.text+i.text,t.marks):(i.text.length>0||0===r.length)&&r.push(i)}const o=r.filter((t,n)=>{if(e(t))return!0;if(t.text.length>0)return!0;if(1===r.length)return!0;const o=r[n-1],i=r[n+1];return!(o&&e(o)||i&&e(i))});return 0===o.length?[a("")]:o.some(t=>n(t))?o:[a(""),...o]}function j(t,n){const r=s(t);let o=0,i=0;for(const s of r)if(e(s)){if(o>=n)return i;o+=1}else{if(o+s.text.length>=n)return i+(n-o);o+=s.text.length,i+=s.text.length}return i}function v(t,n){const r=s(t);for(const{child:o,from:i}of function*(t){let n=0;for(const r of t){const t=e(r)?1:r.text.length;yield{child:r,from:n,to:n+t},n+=t}}(r)){if(e(o)){if(n===i)return{kind:"inline",node:o};continue}const t=n-i;if(t>=0&&t<o.text.length)return{kind:"text",char:o.text[t]??"",marks:o.marks}}return null}export{c as a,j as b,l as c,h as d,a as e,y as f,f as g,p as h,g as i,v as j,s as k,i as l,m,r as n,e as o,o as p,n as q,x as r,u as s,k as t,d as u,b as v,t as w};
2
+ //# sourceMappingURL=Document-HC8s50qJ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Document-HC8s50qJ.mjs","sources":["../../src/model/Document.ts"],"sourcesContent":["/**\n * Core document model types for the Notectl editor.\n * All types are deeply readonly — mutations create new instances.\n */\n\nimport type { BlockId, InlineTypeName, MarkTypeName, NodeTypeName } from './TypeBrands.js';\n\n// --- Mark Types ---\n\nexport interface Mark {\n\treadonly type: MarkTypeName;\n\treadonly attrs?: Readonly<Record<string, string | number | boolean>>;\n}\n\nexport interface BoldMark extends Mark {\n\treadonly type: MarkTypeName & 'bold';\n}\n\nexport interface ItalicMark extends Mark {\n\treadonly type: MarkTypeName & 'italic';\n}\n\nexport interface UnderlineMark extends Mark {\n\treadonly type: MarkTypeName & 'underline';\n}\n\n// --- Node Types ---\n\nexport interface BlockAttrs {\n\treadonly [key: string]: string | number | boolean;\n}\n\nexport interface TextNode {\n\treadonly type: 'text';\n\treadonly text: string;\n\treadonly marks: readonly Mark[];\n}\n\n/** Atomic inline element (width 1 in offset space). */\nexport interface InlineNode {\n\treadonly type: 'inline';\n\treadonly inlineType: InlineTypeName;\n\treadonly attrs: Readonly<Record<string, string | number | boolean>>;\n}\n\n/** A child of a BlockNode: text, inline element, or nested block. */\nexport type ChildNode = TextNode | InlineNode | BlockNode;\n\nexport interface BlockNode {\n\treadonly id: BlockId;\n\treadonly type: NodeTypeName;\n\treadonly attrs?: BlockAttrs;\n\treadonly children: readonly ChildNode[];\n}\n\nexport interface Document {\n\treadonly children: readonly BlockNode[];\n}\n\n// --- Text Segment (for mark-preserving undo) ---\n\nexport interface TextSegment {\n\treadonly text: string;\n\treadonly marks: readonly Mark[];\n}\n\n/** A content segment: either text (with marks) or an inline node. */\nexport type ContentSegment =\n\t| { readonly kind: 'text'; readonly text: string; readonly marks: readonly Mark[] }\n\t| { readonly kind: 'inline'; readonly node: InlineNode };\n\n/** Extracts TextNode segments within a block for the given offset range. */\nexport function getBlockSegmentsInRange(\n\tblock: BlockNode,\n\tfrom: number,\n\tto: number,\n): readonly TextSegment[] {\n\tconst segments: TextSegment[] = [];\n\twalkBlockRange(block, from, to, {\n\t\tonText(text: string, marks: readonly Mark[]): void {\n\t\t\tsegments.push({ text, marks });\n\t\t},\n\t});\n\treturn segments;\n}\n\n/** Returns content segments (text and inline) for a block range. */\nexport function getBlockContentSegmentsInRange(\n\tblock: BlockNode,\n\tfrom: number,\n\tto: number,\n): readonly ContentSegment[] {\n\tconst segments: ContentSegment[] = [];\n\twalkBlockRange(block, from, to, {\n\t\tonText(text: string, marks: readonly Mark[]): void {\n\t\t\tsegments.push({ kind: 'text', text, marks });\n\t\t},\n\t\tonInline(node: InlineNode): void {\n\t\t\tsegments.push({ kind: 'inline', node });\n\t\t},\n\t});\n\treturn segments;\n}\n\ninterface BlockRangeVisitor {\n\treadonly onText: (text: string, marks: readonly Mark[]) => void;\n\treadonly onInline?: (node: InlineNode) => void;\n}\n\n/** Walks inline children within [from, to) and calls visitor callbacks for each relevant child. */\nfunction walkBlockRange(\n\tblock: BlockNode,\n\tfrom: number,\n\tto: number,\n\tvisitor: BlockRangeVisitor,\n): void {\n\tconst inlineChildren: readonly (TextNode | InlineNode)[] = getInlineChildren(block);\n\tlet pos = 0;\n\n\tfor (const child of inlineChildren) {\n\t\tconst childWidth: number = isInlineNode(child) ? 1 : child.text.length;\n\t\tconst childEnd: number = pos + childWidth;\n\n\t\tif (childEnd <= from || pos >= to) {\n\t\t\tpos = childEnd;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (isInlineNode(child)) {\n\t\t\tvisitor.onInline?.(child);\n\t\t} else {\n\t\t\tconst sliceFrom: number = Math.max(0, from - pos);\n\t\t\tconst sliceTo: number = Math.min(child.text.length, to - pos);\n\t\t\tconst text: string = child.text.slice(sliceFrom, sliceTo);\n\t\t\tif (text.length > 0) {\n\t\t\t\tvisitor.onText(text, child.marks);\n\t\t\t}\n\t\t}\n\n\t\tpos = childEnd;\n\t}\n}\n\n// --- Type Guards ---\n\n/** Checks whether a value is a {@link TextNode}. */\nexport function isTextNode(node: unknown): node is TextNode {\n\treturn (\n\t\ttypeof node === 'object' &&\n\t\tnode !== null &&\n\t\t(node as TextNode).type === 'text' &&\n\t\ttypeof (node as TextNode).text === 'string'\n\t);\n}\n\n/** Checks whether a value is an {@link InlineNode}. */\nexport function isInlineNode(node: unknown): node is InlineNode {\n\treturn (\n\t\ttypeof node === 'object' &&\n\t\tnode !== null &&\n\t\t(node as InlineNode).type === 'inline' &&\n\t\ttypeof (node as InlineNode).inlineType === 'string'\n\t);\n}\n\n/** Checks whether a value is a {@link BlockNode}. */\nexport function isBlockNode(node: unknown): node is BlockNode {\n\treturn (\n\t\ttypeof node === 'object' &&\n\t\tnode !== null &&\n\t\ttypeof (node as BlockNode).id === 'string' &&\n\t\ttypeof (node as BlockNode).type === 'string' &&\n\t\t(node as BlockNode).type !== ('text' as string) &&\n\t\t(node as BlockNode).type !== ('inline' as string) &&\n\t\tArray.isArray((node as BlockNode).children)\n\t);\n}\n\n// --- Child Node Helpers ---\n\n/** Returns true if a block has only inline content (TextNodes and InlineNodes). */\nexport function isLeafBlock(node: BlockNode): boolean {\n\treturn node.children.every((c) => isTextNode(c) || isInlineNode(c));\n}\n\n/** Returns only the TextNode children of a block. */\nexport function getTextChildren(node: BlockNode): readonly TextNode[] {\n\treturn node.children.filter((c): c is TextNode => isTextNode(c));\n}\n\n/** Returns the inline content children (TextNode | InlineNode) of a block. */\nexport function getInlineChildren(node: BlockNode): readonly (TextNode | InlineNode)[] {\n\treturn node.children.filter((c): c is TextNode | InlineNode => isTextNode(c) || isInlineNode(c));\n}\n\n/** Returns only the BlockNode children of a block. */\nexport function getBlockChildren(node: BlockNode): readonly BlockNode[] {\n\treturn node.children.filter((c): c is BlockNode => isBlockNode(c));\n}\n\n// --- Factory Functions ---\n\n/** Generates a unique block ID using crypto.randomUUID(). */\nexport function generateBlockId(): BlockId {\n\treturn `block-${crypto.randomUUID()}` as BlockId;\n}\n\n/** Creates a new empty {@link Document} with a single empty paragraph. */\nexport function createDocument(children?: readonly BlockNode[]): Document {\n\treturn {\n\t\tchildren: children ?? [createBlockNode('paragraph' as NodeTypeName)],\n\t};\n}\n\n/** Creates a new {@link BlockNode}. */\nexport function createBlockNode(\n\ttype: NodeTypeName,\n\tchildren?: readonly ChildNode[],\n\tid?: BlockId,\n\tattrs?: BlockAttrs,\n): BlockNode {\n\treturn {\n\t\tid: id ?? generateBlockId(),\n\t\ttype,\n\t\t...(attrs ? { attrs } : {}),\n\t\tchildren: children ?? [createTextNode('')],\n\t};\n}\n\n/** Creates a new {@link TextNode}. */\nexport function createTextNode(text: string, marks?: readonly Mark[]): TextNode {\n\treturn {\n\t\ttype: 'text',\n\t\ttext,\n\t\tmarks: marks ?? [],\n\t};\n}\n\n/** Creates a new {@link InlineNode}. */\nexport function createInlineNode(\n\tinlineType: InlineTypeName,\n\tattrs?: Readonly<Record<string, string | number | boolean>>,\n): InlineNode {\n\treturn {\n\t\ttype: 'inline',\n\t\tinlineType,\n\t\tattrs: attrs ?? {},\n\t};\n}\n\n// --- Utility Functions ---\n\n/** Extracts plain text from a block (InlineNodes are skipped). */\nexport function getBlockText(block: BlockNode): string {\n\tconst inlineChildren: readonly (TextNode | InlineNode)[] = getInlineChildren(block);\n\tlet text = '';\n\tfor (const child of inlineChildren) {\n\t\tif (isTextNode(child)) {\n\t\t\ttext += child.text;\n\t\t}\n\t}\n\treturn text;\n}\n\n/** Returns the length of a block's inline content (InlineNodes count as 1). */\nexport function getBlockLength(block: BlockNode): number {\n\tconst inlineChildren: readonly (TextNode | InlineNode)[] = getInlineChildren(block);\n\tlet len = 0;\n\tfor (const child of inlineChildren) {\n\t\tlen += isInlineNode(child) ? 1 : child.text.length;\n\t}\n\treturn len;\n}\n\n/** Returns the marks active at the given offset (empty for InlineNode offsets). */\nexport function getBlockMarksAtOffset(block: BlockNode, offset: number): readonly Mark[] {\n\tconst inlineChildren: readonly (TextNode | InlineNode)[] = getInlineChildren(block);\n\tlet pos = 0;\n\n\tfor (const child of inlineChildren) {\n\t\tif (isInlineNode(child)) {\n\t\t\tif (offset === pos) return [];\n\t\t\tpos += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tconst end: number = pos + child.text.length;\n\t\tif (offset >= pos && offset < end) {\n\t\t\treturn child.marks;\n\t\t}\n\t\tif (offset === pos && child.text.length === 0) {\n\t\t\treturn child.marks;\n\t\t}\n\t\tpos = end;\n\t}\n\n\t// Fall back to last text child's marks\n\tfor (let i: number = inlineChildren.length - 1; i >= 0; i--) {\n\t\tconst child: TextNode | InlineNode | undefined = inlineChildren[i];\n\t\tif (child && isTextNode(child)) {\n\t\t\treturn child.marks;\n\t\t}\n\t}\n\treturn [];\n}\n\n/** Checks whether two marks are equal by type and attrs. */\nexport function marksEqual(a: Mark, b: Mark): boolean {\n\tif (a.type !== b.type) return false;\n\tconst aAttrs = a.attrs;\n\tconst bAttrs = b.attrs;\n\tif (!aAttrs && !bAttrs) return true;\n\tif (!aAttrs || !bAttrs) return false;\n\tconst aKeys = Object.keys(aAttrs);\n\tconst bKeys = Object.keys(bAttrs);\n\tif (aKeys.length !== bKeys.length) return false;\n\treturn aKeys.every((key) => aAttrs[key] === bAttrs[key]);\n}\n\n/** Checks whether two mark arrays contain the same marks (order-independent). */\nexport function markSetsEqual(a: readonly Mark[], b: readonly Mark[]): boolean {\n\tif (a.length !== b.length) return false;\n\treturn a.every((markA) => b.some((markB) => marksEqual(markA, markB)));\n}\n\n/** Returns true if the mark set contains a mark of the given type. */\nexport function hasMark(marks: readonly Mark[], markType: MarkTypeName): boolean {\n\treturn marks.some((m) => m.type === markType);\n}\n\n/** Adds a mark to a mark set (no duplicates). */\nexport function addMarkToSet(marks: readonly Mark[], mark: Mark): readonly Mark[] {\n\tif (hasMark(marks, mark.type)) return marks;\n\treturn [...marks, mark];\n}\n\n/** Removes a mark type from a mark set. */\nexport function removeMarkFromSet(marks: readonly Mark[], markType: MarkTypeName): readonly Mark[] {\n\treturn marks.filter((m) => m.type !== markType);\n}\n\n/**\n * Normalizes text nodes within a block: merges adjacent nodes with identical marks,\n * removes empty text nodes (keeping at least one).\n */\nexport function normalizeTextNodes(nodes: readonly TextNode[]): readonly TextNode[] {\n\tif (nodes.length === 0) return [createTextNode('')];\n\n\tconst result: TextNode[] = [];\n\tfor (const node of nodes) {\n\t\tconst prev: TextNode | undefined = result[result.length - 1];\n\t\tif (prev && markSetsEqual(prev.marks, node.marks)) {\n\t\t\tresult[result.length - 1] = createTextNode(prev.text + node.text, prev.marks);\n\t\t} else if (node.text.length > 0 || result.length === 0) {\n\t\t\tresult.push(node);\n\t\t}\n\t}\n\n\treturn result.length === 0 ? [createTextNode('')] : result;\n}\n\n/**\n * Normalizes mixed inline content: merges adjacent TextNodes with same marks,\n * removes empty TextNodes adjacent to InlineNodes, preserves InlineNodes as-is.\n * Guarantees at least one TextNode exists if all text is empty.\n */\nexport function normalizeInlineContent(\n\tnodes: readonly (TextNode | InlineNode)[],\n): readonly (TextNode | InlineNode)[] {\n\tif (nodes.length === 0) return [createTextNode('')];\n\n\t// Fast path: no InlineNodes, delegate to normalizeTextNodes\n\tif (nodes.every((n): n is TextNode => isTextNode(n))) {\n\t\treturn normalizeTextNodes(nodes);\n\t}\n\n\tconst result: (TextNode | InlineNode)[] = [];\n\n\tfor (const node of nodes) {\n\t\tif (isInlineNode(node)) {\n\t\t\tresult.push(node);\n\t\t\tcontinue;\n\t\t}\n\t\t// TextNode: try to merge with previous TextNode\n\t\tconst prev: TextNode | InlineNode | undefined = result[result.length - 1];\n\t\tif (prev && isTextNode(prev) && markSetsEqual(prev.marks, node.marks)) {\n\t\t\tresult[result.length - 1] = createTextNode(prev.text + node.text, prev.marks);\n\t\t} else if (node.text.length > 0 || result.length === 0) {\n\t\t\tresult.push(node);\n\t\t}\n\t}\n\n\t// Remove empty TextNodes that are adjacent to InlineNodes\n\tconst cleaned: (TextNode | InlineNode)[] = result.filter((node, i) => {\n\t\tif (isInlineNode(node)) return true;\n\t\tif (node.text.length > 0) return true;\n\t\t// Keep if it's the only node\n\t\tif (result.length === 1) return true;\n\t\t// Remove empty TextNode if adjacent to InlineNode\n\t\tconst prev: TextNode | InlineNode | undefined = result[i - 1];\n\t\tconst next: TextNode | InlineNode | undefined = result[i + 1];\n\t\tif ((prev && isInlineNode(prev)) || (next && isInlineNode(next))) {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t});\n\n\t// Ensure at least one TextNode exists\n\tif (cleaned.length === 0) return [createTextNode('')];\n\tif (!cleaned.some((n) => isTextNode(n))) {\n\t\treturn [createTextNode(''), ...cleaned];\n\t}\n\n\treturn cleaned;\n}\n\n/** Yields each inline child with its offset range. InlineNodes have width 1. */\nexport function* walkInlineContent(children: readonly (TextNode | InlineNode)[]): Generator<{\n\treadonly child: TextNode | InlineNode;\n\treadonly from: number;\n\treadonly to: number;\n}> {\n\tlet pos = 0;\n\tfor (const child of children) {\n\t\tconst width: number = isInlineNode(child) ? 1 : child.text.length;\n\t\tyield { child, from: pos, to: pos + width };\n\t\tpos += width;\n\t}\n}\n\n/**\n * Converts a block-space offset to a text-space offset.\n *\n * Block-space counts InlineNodes as width 1, but `getBlockText()` skips them.\n * This function maps a block offset to the equivalent position in the\n * text-only string returned by `getBlockText()`.\n */\nexport function blockOffsetToTextOffset(block: BlockNode, blockOffset: number): number {\n\tconst inlineChildren: readonly (TextNode | InlineNode)[] = getInlineChildren(block);\n\tlet blockPos = 0;\n\tlet textPos = 0;\n\n\tfor (const child of inlineChildren) {\n\t\tif (isInlineNode(child)) {\n\t\t\tif (blockPos >= blockOffset) return textPos;\n\t\t\tblockPos += 1;\n\t\t} else {\n\t\t\tif (blockPos + child.text.length >= blockOffset) {\n\t\t\t\treturn textPos + (blockOffset - blockPos);\n\t\t\t}\n\t\t\tblockPos += child.text.length;\n\t\t\ttextPos += child.text.length;\n\t\t}\n\t}\n\n\treturn textPos;\n}\n\n/** Returns the content at a specific offset: text char, inline node, or null. */\nexport function getContentAtOffset(\n\tblock: BlockNode,\n\toffset: number,\n):\n\t| { readonly kind: 'text'; readonly char: string; readonly marks: readonly Mark[] }\n\t| { readonly kind: 'inline'; readonly node: InlineNode }\n\t| null {\n\tconst inlineChildren: readonly (TextNode | InlineNode)[] = getInlineChildren(block);\n\n\tfor (const { child, from } of walkInlineContent(inlineChildren)) {\n\t\tif (isInlineNode(child)) {\n\t\t\tif (offset === from) return { kind: 'inline', node: child };\n\t\t\tcontinue;\n\t\t}\n\t\tconst localOffset: number = offset - from;\n\t\tif (localOffset >= 0 && localOffset < child.text.length) {\n\t\t\treturn {\n\t\t\t\tkind: 'text',\n\t\t\t\tchar: child.text[localOffset] ?? '',\n\t\t\t\tmarks: child.marks,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn null;\n}\n"],"names":["getBlockSegmentsInRange","block","from","to","segments","visitor","inlineChildren","getInlineChildren","pos","child","childEnd","isInlineNode","text","length","onInline","sliceFrom","Math","max","sliceTo","min","slice","onText","marks","walkBlockRange","push","isTextNode","node","type","inlineType","isBlockNode","id","Array","isArray","children","isLeafBlock","every","c","getTextChildren","filter","getBlockChildren","generateBlockId","crypto","randomUUID","createDocument","createBlockNode","attrs","createTextNode","createInlineNode","getBlockText","getBlockLength","len","getBlockMarksAtOffset","offset","end","i","markSetsEqual","a","b","markA","some","markB","aAttrs","bAttrs","aKeys","Object","keys","bKeys","key","marksEqual","hasMark","markType","m","addMarkToSet","mark","removeMarkFromSet","normalizeInlineContent","nodes","n","result","prev","normalizeTextNodes","cleaned","next","blockOffsetToTextOffset","blockOffset","blockPos","textPos","getContentAtOffset","width","walkInlineContent","kind","localOffset","char"],"mappings":"AAwEO,SAASA,EACfC,EACAC,EACAC,GAEA,MAAMC,EAA0B,GAMhC,OA2BD,SACCH,EACAC,EACAC,EACAE,GAEA,MAAMC,EAAqDC,EAAkBN,GAC7E,IAAIO,EAAM,EAEV,IAAA,MAAWC,KAASH,EAAgB,CACnC,MACMI,EAAmBF,GADEG,EAAaF,GAAS,EAAIA,EAAMG,KAAKC,QAGhE,GAAIH,GAAYR,GAAQM,GAAOL,EAC9BK,EAAME,MADP,CAKA,GAAIC,EAAaF,GAChBJ,EAAQS,WAAWL,OAC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AAOE,GAAWF,EAAcC,GAEjCA,GAAY5E,EAAMG,KAAKC,OACvByE,GAAW7E,EAAMG,KAAKC,MACvB,CAGD,OAAOyE,CACR,CAGO,SAASC,EACftF,EACAmD,GAKA,MAAM9C,EAAqDC,EAAkBN,GAE7E,IAAA,MAAWQ,MAAEA,EAAAP,KAAOA,KAnDd,UAA4B+B,GAKlC,IAAIzB,EAAM,EACV,IAAA,MAAWC,KAASwB,EAAU,CAC7B,MAAMuD,EAAgB7E,EAAaF,GAAS,EAAIA,EAAMG,KAAKC,YACrD,CAAEJ,QAAOP,KAAMM,EAAKL,GAAIK,EAAMgF,GACpChF,GAAOgF,CACR,CACD,CAwC+BC,CAAkBnF,GAAiB,CAChE,GAAIK,EAAaF,GAAQ,CACxB,GAAI2C,IAAWlD,EAAM,MAAO,CAAEwF,KAAM,SAAUhE,KAAMjB,GACpD,QACD,CACA,MAAMkF,EAAsBvC,EAASlD,EACrC,GAAIyF,GAAe,GAAKA,EAAclF,EAAMG,KAAKC,OAChD,MAAO,CACN6E,KAAM,OACNE,KAAMnF,EAAMG,KAAK+E,IAAgB,GACjCrE,MAAOb,EAAMa,MAGhB,CAEA,OAAO,IACR"}
@@ -0,0 +1,2 @@
1
+ import t from"dompurify";import{p as e,g as s,k as n,o,q as r,r as i,a as c,e as l,c as a,d as u}from"./Document-HC8s50qJ.mjs";import{a as f,S as p,e as g}from"./HTMLUtils-Cxy99Ak2.mjs";import{n as d,i as h,m as y}from"./TypeBrands-Bp_Z_o5Y.mjs";import{b as m}from"./AttrRegistry-Ckj9eCHj.mjs";function A(t){let e=2166136261;for(let s=0;s<t.length;s++)e^=t.charCodeAt(s),e=Math.imul(e,16777619);return(e>>>0).toString(36).padStart(6,"0")}class L{classMap=/* @__PURE__ */new Map;usedHashes=/* @__PURE__ */new Set;getClassName(t){const e=function(t){return t.split(";").map(t=>t.trim()).filter(t=>t.length>0).sort().join("; ")}(t),s=this.classMap.get(e);if(s)return s;let n=A(e),o=0;for(;this.usedHashes.has(n);)o++,n=A(e+String(o));const r=`notectl-s-${n}`;return this.usedHashes.add(n),this.classMap.set(e,r),r}getAlignmentClassName(t){const e=`text-align: ${t}`,s=this.classMap.get(e);if(s)return s;const n=`notectl-align-${t}`;return this.classMap.set(e,n),n}toCSS(){if(0===this.classMap.size)return"";const t=[];for(const[e,s]of this.classMap)t.push(`.${s} { ${e}; }`);return t.join("\n")}toStyleMap(){const t=/* @__PURE__ */new Map;for(const[e,s]of this.classMap)t.set(s,e);return t}}function T(t){const e=t.getMarkTypes(),s=/* @__PURE__ */new Map;for(const n of e){const e=t.getMarkSpec(n);e&&s.set(n,e.rank??99)}return s}function b(t,e,s,n,o){if(""===t)return"";let r=f(t);if(0===e.length)return r;const i=n??T(s),c=[...e].sort((t,e)=>(i.get(t.type)??99)-(i.get(e.type)??99)),l=[],a=[];for(const u of c){const t=s.getMarkSpec(u.type);if(t?.toHTMLStyle){const e=t.toHTMLStyle(u);e&&l.push(e)}else a.push(u)}if(l.length>0){const t=l.join("; "),e=o?o.styleAttr(t):` style="${t}"`;e&&(r=`<span${e}>${r}</span>`)}for(const u of a){const t=s.getMarkSpec(u.type);t?.toHTMLString&&(r=t.toHTMLString(u,r,o))}return r}function M(t,e,s,n,o,r){if(""===t)return"";let i=f(t);if(0===e.length)return i;const c=o??T(s),l=[...e].sort((t,e)=>(c.get(t.type)??99)-(c.get(e.type)??99)),a=[],u=[];for(const f of l){const t=s.getMarkSpec(f.type);if(t?.toHTMLStyle){const e=t.toHTMLStyle(f);e&&a.push(e)}else u.push(f)}if(a.length>0){const t=a.join("; ");i=`<span class="${n.getClassName(t)}">${i}</span>`}for(const f of u){const t=s.getMarkSpec(f.type);t?.toHTMLString&&(i=t.toHTMLString(f,i,r))}return i}const S=/* @__PURE__ */new Set(["start","center","end","justify"]),$={left:"start",right:"end"},N=/* @__PURE__ */new Set(["ltr","rtl"]);function x(t,e,s){const n=function(t){let e=t.indexOf("<");for(;e>=0;){const s=t[e+1];if(s&&/[A-Za-z]/.test(s)){let s;for(let n=e+2;n<t.length;n++){const o=t[n]??"";if(s)o===s&&(s=void 0);else if('"'!==o&&"'"!==o){if(">"===o)return{start:e,end:n}}else s=o}return}e=t.indexOf("<",e+1)}}(t);if(!n)return t;const o=t.slice(n.start,n.end+1),r=new RegExp(`\\s${e}\\s*=\\s*("([^"]*)"|'([^']*)')`),i=o.match(r);if(i){const c=i[2]??i[3]??"";if("style"===e&&/(?:^|;)\s*text-align\s*:/i.test(c))return t;const l=` ${e}="${c}${"style"===e?"; ":" "}${s}"`,a=o.replace(r,l);return`${t.slice(0,n.start)}${a}${t.slice(n.end+1)}`}const c=o.endsWith("/>")?`${o.slice(0,-2)} ${e}="${s}"/>`:`${o.slice(0,-1)} ${e}="${s}">`;return`${t.slice(0,n.start)}${c}${t.slice(n.end+1)}`}function k(e,s){const n={registry:s,exportCtx:{styleAttr:t=>t?` style="${t}"`:""}},o=_(e.children,n),r=s?s.getAllowedTags():["p","br","div","span"],i=s?s.getAllowedAttrs():["style","dir"];return t.sanitize(o,{ALLOWED_TAGS:r,ALLOWED_ATTR:i,ALLOWED_URI_REGEXP:p})}function E(e,s){const n=new L,o=function(t){return{styleAttr:e=>e?` class="${t.getClassName(e)}"`:""}}(n),r={registry:s,collector:n,exportCtx:o},i=_(e.children,r),c=s?s.getAllowedTags():["p","br","div","span"],l=s?s.getAllowedAttrs():["style","class","dir"];l.includes("class")||l.push("class");const a=l.filter(t=>"style"!==t);return{html:t.sanitize(i,{ALLOWED_TAGS:c,ALLOWED_ATTR:a,ALLOWED_URI_REGEXP:p}),css:n.toCSS(),styleMap:n.toStyleMap()}}function _(t,e){const s=[];let n=0;for(;n<t.length;){const o=t[n];if(o)if(m(o,"list_item")){const o=[];for(;n<t.length;){const e=t[n];if(!e||!m(e,"list_item"))break;o.push(e),n++}s.push(v(o,e))}else s.push(C(o,e)),n++;else n++}return s.join("")}function v(t,e){const s=[],n=[];for(let o=0;o<t.length;o++){const r=t[o];if(!r)continue;const i=r.attrs?.listType??"bullet",c=r.attrs?.indent??0,l="ordered"===i?"ol":"ul";for(;n.length>0;){const t=n[n.length-1];if(!t)break;if(t.indent>c)s.push(`</${t.tag}></li>`),n.pop();else{if(t.indent!==c||t.tag===l)break;s.push(`</${t.tag}></li>`),n.pop()}}if(0===n.length)s.push(`<${l}>`),n.push({tag:l,indent:c});else{const t=n[n.length-1];t&&c>t.indent&&(s.push(`<${l}>`),n.push({tag:l,indent:c}))}const a=C(r,e),u=t[o+1],f=u?u.attrs?.indent??0:void 0;void 0!==f&&f>c?s.push(w(a)):s.push(a)}for(;n.length>0;){const t=n.pop();if(!t)break;s.push(`</${t.tag}>`),n.length>0&&s.push("</li>")}return s.join("")}function w(t){return t.endsWith("</li>")?t.slice(0,-5):t}function C(t,c){const l=e(t)?function(t,e){const s=function(t){if(t.length<=1)return t;const e=[];for(const s of t){if(o(s)){e.push(s);continue}const t=e[e.length-1];t&&r(t)&&i(t.marks,s.marks)?e[e.length-1]={type:"text",text:t.text+s.text,marks:t.marks}:e.push(s)}return e}(n(t)),c=[],l=e.registry?T(e.registry):void 0;for(const n of s)if(o(n)){const t=e.registry?.getInlineNodeSpec(n.inlineType);t?.toHTMLString&&c.push(t.toHTMLString(n))}else e.registry&&e.collector?c.push(M(n.text,n.marks,e.registry,e.collector,l,e.exportCtx)):e.registry?c.push(b(n.text,n.marks,e.registry,l,e.exportCtx)):""!==n.text&&c.push(f(n.text));return c.join("")}(t,c):_(s(t),c),a=c.registry?.getNodeSpec(t.type);let u;u=a?.toHTML?a.toHTML(t,l,c.exportCtx):`<p>${l||"<br>"}</p>`;const p=t.attrs?.align,d=p?$[p]??p:void 0;if(d&&"start"!==d&&S.has(d)){const t=g(d);if(c.collector){const t=c.collector.getAlignmentClassName(d);u=x(u,"class",g(t))}else u=x(u,"style",`text-align: ${t}`)}const h=t.attrs?.dir;if(h&&N.has(h)){const t=u.indexOf(">");u.slice(0,t+1).includes(" dir=")||(u=x(u,"dir",g(h)))}return u}const O=/* @__PURE__ */Object.freeze(/* @__PURE__ */Object.defineProperty({__proto__:null,VALID_ALIGNMENTS:S,VALID_DIRECTIONS:N,serializeDocumentToCSS:E,serializeDocumentToHTML:k},Symbol.toStringTag,{value:"Module"}));function j(e,s,n){const o=s?s.getAllowedTags():["p","br","div","span"],r=s?s.getAllowedAttrs():["style","dir"];n?.styleMap&&!r.includes("class")&&r.push("class");const i=document.createElement("template");i.innerHTML=t.sanitize(e,{ALLOWED_TAGS:o,ALLOWED_ATTR:r,ALLOWED_URI_REGEXP:p});const l=i.content;n?.styleMap&&function(t,e){const s=t.querySelectorAll("[class]");for(const n of Array.from(s)){const t=n,s=Array.from(t.classList),o=[];for(const n of s){const s=e.get(n);if(s){const e=t.getAttribute("style")??"",r=e&&!e.endsWith(";")?"; ":"";t.setAttribute("style",e+r+s),o.push(n)}}for(const e of o)t.classList.remove(e)}}(l,n.styleMap);const a=s?.getBlockParseRules()??[],u=[];for(const t of Array.from(l.childNodes))D(t,u,a,s);return 0===u.length?c():c(u)}function D(t,e,s,n){if(t.nodeType===Node.ELEMENT_NODE){const o=t,r=o.tagName.toLowerCase();if("ul"===r||"ol"===r){const t="ol"===r?"ordered":"bullet",s=o.getAttribute("dir");return void H(o,t,0,e,n,s&&N.has(s)?s:void 0)}if("table"===r)return void function(t,e,s){const n=[],o=function(t){const e=[];for(const s of Array.from(t.children)){const t=s.tagName.toLowerCase();if("tr"===t)e.push(s);else if("thead"===t||"tbody"===t||"tfoot"===t)for(const n of Array.from(s.children))"tr"===n.tagName.toLowerCase()&&e.push(n)}return e}(t);for(const r of o){const t=[];for(const e of Array.from(r.children)){const n=e.tagName.toLowerCase();if("td"!==n&&"th"!==n)continue;const o=e,r=W(o,s),i={};I(o,i);const c=a(d("table_cell"),r,void 0,Object.keys(i).length>0?i:void 0);t.push(c)}t.length>0&&n.push(a(d("table_row"),t))}if(n.length>0){const s={};!function(t,e){const s=t.getAttribute("style")??"",n=R.exec(s);n?.[1]&&(e.borderColor="transparent"===n[1]?"none":n[1])}(t,s),e.push(a(d("table"),n,void 0,Object.keys(s).length>0?s:void 0))}}(o,e,n);const i=function(t,e){const s=t.tagName.toLowerCase();for(const n of e)if(n.rule.tag===s){if(n.rule.getAttrs){const e=n.rule.getAttrs(t);if(!1===e)continue;return{type:n.type,attrs:e}}return{type:n.type}}return null}(o,s);if(i){const t=n?.getNodeSpec(i.type),s=t?.isVoid?[l("")]:z(o,n),r={...i.attrs};return t?.attrs?.align&&U(o,r),t?.attrs?.dir&&G(o,r),void e.push(a(d(i.type),s,void 0,Object.keys(r).length>0?r:void 0))}const c=z(o,n),u={};U(o,u),G(o,u),e.push(a(d("paragraph"),c,void 0,Object.keys(u).length>0?u:void 0))}else t.nodeType===Node.TEXT_NODE&&t.textContent?.trim()&&e.push(a(d("paragraph"),[l(t.textContent.trim())]))}function H(t,e,s,n,o,r){for(const i of Array.from(t.children)){const t=i.tagName.toLowerCase();if("li"===t){const t=i,c=t.querySelector(':scope > input[type="checkbox"]'),l=null!==c,u=c?.hasAttribute("checked")??!1,f=l?"checklist":e,p=z(t,o,!0),g={listType:f,indent:s,checked:u},h=t.getAttribute("dir"),y=h&&N.has(h)?h:r;y&&(g.dir=y),n.push(a(d("list_item"),p,void 0,g));for(const e of Array.from(t.children)){const t=e.tagName.toLowerCase();if("ul"===t||"ol"===t){const r="ol"===t?"ordered":"bullet",i=e.getAttribute("dir");H(e,r,s+1,n,o,i&&N.has(i)?i:y)}}}else if("ul"===t||"ol"===t){const e="ol"===t?"ordered":"bullet",c=i.getAttribute("dir");H(i,e,s+1,n,o,c&&N.has(c)?c:r)}}}const R=/--ntbl-bc:\s*(#[0-9a-fA-F]{3,8}|transparent)/;function I(t,e){const s=t.getAttribute("colspan");if(s){const t=Number.parseInt(s,10);t>1&&(e.colspan=t)}const n=t.getAttribute("rowspan");if(n){const t=Number.parseInt(n,10);t>1&&(e.rowspan=t)}}function W(t,e){const s=e?.getBlockParseRules()??[],n=[];for(const o of Array.from(t.childNodes))D(o,n,s,e);if(0===n.length){const s=z(t,e);n.push(a(d("paragraph"),s))}return n}function z(t,e,s){const n=[];return P(t,[],n,e?.getMarkParseRules()??[],e?.getInlineParseRules()??[],s),n.length>0?n:[l("")]}function P(t,e,s,n,o,r){if(t.nodeType===Node.TEXT_NODE){const n=t.textContent??"";return void(n&&s.push(l(n,[...e])))}if(t.nodeType!==Node.ELEMENT_NODE)return;const i=t,c=i.tagName.toLowerCase();if(r&&("ul"===c||"ol"===c))return;if(r&&"input"===c&&"checkbox"===i.getAttribute("type"))return;for(const l of o)if(l.rule.tag===c){if(l.rule.getAttrs){const t=l.rule.getAttrs(i);if(!1===t)continue;return void s.push(u(h(l.type),t))}return void s.push(u(h(l.type)))}const a=[...e],f=/* @__PURE__ */new Set;for(const l of n)if(l.rule.tag===c&&!f.has(l.type))if(l.rule.getAttrs){const t=l.rule.getAttrs(i);if(!1===t)continue;a.some(t=>t.type===l.type)||(a.push({type:y(l.type),...Object.keys(t).length>0?{attrs:t}:{}}),f.add(l.type))}else a.some(t=>t.type===l.type)||(a.push({type:y(l.type)}),f.add(l.type));for(const l of Array.from(i.childNodes))P(l,a,s,n,o,r)}function G(t,e){const s=t.getAttribute("dir");if(s&&N.has(s))return void(e.dir=s);const n=t.style?.direction??"";n&&N.has(n)&&(e.dir=n)}const X={left:"start",right:"end"};function U(t,e){let s=t.style?.textAlign??"";const n=X[s];if(n&&(s=n),s&&S.has(s))e.align=s;else for(const o of Array.from(t.classList)){const t=o.match(/^notectl-align-(\w+)$/);let s=t?.[1];const n=X[s??""];if(n&&(s=n),s&&S.has(s))return void(e.align=s)}}const V=/* @__PURE__ */Object.freeze(/* @__PURE__ */Object.defineProperty({__proto__:null,parseHTMLToDocument:j},Symbol.toStringTag,{value:"Module"}));export{O as D,S as V,N as a,k as b,T as c,b as d,V as e,j as p,E as s};
2
+ //# sourceMappingURL=DocumentParser-w70-Axud.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DocumentParser-w70-Axud.mjs","sources":["../../src/serialization/CSSClassCollector.ts","../../src/serialization/MarkSerializer.ts","../../src/serialization/DocumentSerializer.ts","../../src/serialization/DocumentParser.ts"],"sourcesContent":["/**\n * CSSClassCollector: maps CSS declarations to unique class names during serialization.\n * Deduplicates identical declaration sets and produces a minimal stylesheet.\n * Uses content-hash (FNV-1a) for deterministic, document-order-independent class names.\n */\n\n/** Prefix for generated style class names (avoids collisions with user classes). */\nconst CLASS_PREFIX = 'notectl-s-';\n\n/** Base for hash encoding output. */\nconst HASH_BASE = 36;\n/** Pad length for consistent 6-char hashes. */\nconst HASH_PAD_LENGTH = 6;\n\n/**\n * Normalizes a CSS declarations string by sorting individual declarations alphabetically.\n * This ensures `\"color: red; font-size: 14px\"` and `\"font-size: 14px; color: red\"` map\n * to the same class name.\n */\nfunction normalizeDeclarations(declarations: string): string {\n\treturn declarations\n\t\t.split(';')\n\t\t.map((d) => d.trim())\n\t\t.filter((d) => d.length > 0)\n\t\t.sort()\n\t\t.join('; ');\n}\n\n/** FNV-1a 32-bit offset basis. */\nconst FNV_OFFSET_BASIS = 0x811c9dc5;\n/** FNV-1a 32-bit prime. */\nconst FNV_PRIME = 0x01000193;\n\n/**\n * FNV-1a 32-bit hash function.\n * Fast, no crypto dependency, excellent distribution for short strings.\n */\nfunction fnv1aHash(input: string): string {\n\tlet hash: number = FNV_OFFSET_BASIS;\n\tfor (let i = 0; i < input.length; i++) {\n\t\thash ^= input.charCodeAt(i);\n\t\thash = Math.imul(hash, FNV_PRIME);\n\t}\n\t// Convert to unsigned 32-bit, then to base-36, padded to 6 chars\n\tconst unsigned: number = hash >>> 0;\n\treturn unsigned.toString(HASH_BASE).padStart(HASH_PAD_LENGTH, '0');\n}\n\n/**\n * Stateful collector that assigns CSS class names to unique declaration sets.\n * Used during a single serialization pass, then produces the collected stylesheet.\n *\n * Class names are deterministic: the same declarations always produce the same\n * class name, regardless of encounter order across documents.\n */\nexport class CSSClassCollector {\n\t/** Maps normalized declarations → class name. */\n\tprivate readonly classMap: Map<string, string> = new Map();\n\t/** Tracks used hashes to handle the (extremely rare) collision case. */\n\tprivate readonly usedHashes: Set<string> = new Set();\n\n\t/**\n\t * Returns the class name for the given CSS declarations.\n\t * If the same (normalized) declarations were seen before, returns the existing class.\n\t */\n\tgetClassName(declarations: string): string {\n\t\tconst normalized: string = normalizeDeclarations(declarations);\n\t\tconst existing: string | undefined = this.classMap.get(normalized);\n\t\tif (existing) return existing;\n\n\t\tlet hash: string = fnv1aHash(normalized);\n\t\tlet suffix = 0;\n\t\t// Collision handling: append suffix counter if the hash is already in use\n\t\t// for a different declarations string\n\t\twhile (this.usedHashes.has(hash)) {\n\t\t\tsuffix++;\n\t\t\thash = fnv1aHash(normalized + String(suffix));\n\t\t}\n\n\t\tconst className: string = `${CLASS_PREFIX}${hash}`;\n\t\tthis.usedHashes.add(hash);\n\t\tthis.classMap.set(normalized, className);\n\t\treturn className;\n\t}\n\n\t/**\n\t * Returns the semantic alignment class name for a given alignment value.\n\t * Unlike style classes, alignment classes use descriptive names.\n\t */\n\tgetAlignmentClassName(alignment: string): string {\n\t\tconst declarations: string = `text-align: ${alignment}`;\n\t\tconst existing: string | undefined = this.classMap.get(declarations);\n\t\tif (existing) return existing;\n\n\t\tconst className = `notectl-align-${alignment}`;\n\t\tthis.classMap.set(declarations, className);\n\t\treturn className;\n\t}\n\n\t/** Produces CSS rules for all collected classes. Returns empty string if none collected. */\n\ttoCSS(): string {\n\t\tif (this.classMap.size === 0) return '';\n\n\t\tconst rules: string[] = [];\n\t\tfor (const [declarations, className] of this.classMap) {\n\t\t\trules.push(`.${className} { ${declarations}; }`);\n\t\t}\n\t\treturn rules.join('\\n');\n\t}\n\n\t/**\n\t * Returns a map from class name → CSS declarations for round-trip support.\n\t * Used by `setContentHTML` to rehydrate class-based HTML.\n\t */\n\ttoStyleMap(): ReadonlyMap<string, string> {\n\t\tconst map = new Map<string, string>();\n\t\tfor (const [declarations, className] of this.classMap) {\n\t\t\tmap.set(className, declarations);\n\t\t}\n\t\treturn map;\n\t}\n}\n","/**\n * MarkSerializer: shared mark serialization logic for DocumentSerializer and ClipboardHandler.\n * Separates style-based marks (merged into a single `<span style>`) from tag-based marks\n * (nested wrappers in rank order).\n */\n\nimport type { Mark } from '../model/Document.js';\nimport { escapeHTML } from '../model/HTMLUtils.js';\nimport type { MarkSpec } from '../model/MarkSpec.js';\nimport type { HTMLExportContext } from '../model/NodeSpec.js';\nimport type { SchemaRegistry } from '../model/SchemaRegistry.js';\nimport type { CSSClassCollector } from './CSSClassCollector.js';\n\n/** Builds a map of mark type name to rank from the registry (compute once per pass). */\nexport function buildMarkOrder(registry: SchemaRegistry): Map<string, number> {\n\tconst types: readonly string[] = registry.getMarkTypes();\n\tconst order = new Map<string, number>();\n\tfor (const t of types) {\n\t\tconst spec: MarkSpec | undefined = registry.getMarkSpec(t);\n\t\tif (spec) order.set(t, spec.rank ?? 99);\n\t}\n\treturn order;\n}\n\n/**\n * Serializes text with marks to HTML.\n * Style-based marks (`toHTMLStyle`) are merged into a single `<span style=\"...\">`.\n * Tag-based marks (`toHTMLString`) wrap the content in rank order.\n */\nexport function serializeMarksToHTML(\n\ttext: string,\n\tmarks: readonly Mark[],\n\tregistry: SchemaRegistry,\n\tmarkOrder?: Map<string, number>,\n\texportCtx?: HTMLExportContext,\n): string {\n\tif (text === '') return '';\n\n\tlet html: string = escapeHTML(text);\n\n\tif (marks.length === 0) return html;\n\n\tconst order: Map<string, number> = markOrder ?? buildMarkOrder(registry);\n\tconst sortedMarks: Mark[] = [...marks].sort(\n\t\t(a, b) => (order.get(a.type) ?? 99) - (order.get(b.type) ?? 99),\n\t);\n\n\tconst styleParts: string[] = [];\n\tconst tagMarks: Mark[] = [];\n\n\tfor (const mark of sortedMarks) {\n\t\tconst markSpec: MarkSpec | undefined = registry.getMarkSpec(mark.type);\n\t\tif (markSpec?.toHTMLStyle) {\n\t\t\tconst style: string | null = markSpec.toHTMLStyle(mark);\n\t\t\tif (style) {\n\t\t\t\tstyleParts.push(style);\n\t\t\t}\n\t\t} else {\n\t\t\ttagMarks.push(mark);\n\t\t}\n\t}\n\n\t// Wrap with merged style span first (closest to text)\n\tif (styleParts.length > 0) {\n\t\tconst declarations: string = styleParts.join('; ');\n\t\tconst attr: string = exportCtx ? exportCtx.styleAttr(declarations) : ` style=\"${declarations}\"`;\n\t\tif (attr) {\n\t\t\thtml = `<span${attr}>${html}</span>`;\n\t\t}\n\t}\n\n\t// Then wrap with tag-based marks in rank order\n\tfor (const mark of tagMarks) {\n\t\tconst markSpec: MarkSpec | undefined = registry.getMarkSpec(mark.type);\n\t\tif (markSpec?.toHTMLString) {\n\t\t\thtml = markSpec.toHTMLString(mark, html, exportCtx);\n\t\t}\n\t}\n\n\treturn html;\n}\n\n/**\n * Serializes text with marks to HTML using CSS class names instead of inline styles.\n * Style-based marks (`toHTMLStyle`) are collected into a `CSSClassCollector` and emitted\n * as `<span class=\"...\">`. Tag-based marks (`toHTMLString`) wrap identically to the inline path.\n */\nexport function serializeMarksToClassHTML(\n\ttext: string,\n\tmarks: readonly Mark[],\n\tregistry: SchemaRegistry,\n\tcollector: CSSClassCollector,\n\tmarkOrder?: Map<string, number>,\n\texportCtx?: HTMLExportContext,\n): string {\n\tif (text === '') return '';\n\n\tlet html: string = escapeHTML(text);\n\n\tif (marks.length === 0) return html;\n\n\tconst order: Map<string, number> = markOrder ?? buildMarkOrder(registry);\n\tconst sortedMarks: Mark[] = [...marks].sort(\n\t\t(a, b) => (order.get(a.type) ?? 99) - (order.get(b.type) ?? 99),\n\t);\n\n\tconst styleParts: string[] = [];\n\tconst tagMarks: Mark[] = [];\n\n\tfor (const mark of sortedMarks) {\n\t\tconst markSpec: MarkSpec | undefined = registry.getMarkSpec(mark.type);\n\t\tif (markSpec?.toHTMLStyle) {\n\t\t\tconst style: string | null = markSpec.toHTMLStyle(mark);\n\t\t\tif (style) {\n\t\t\t\tstyleParts.push(style);\n\t\t\t}\n\t\t} else {\n\t\t\ttagMarks.push(mark);\n\t\t}\n\t}\n\n\t// Wrap with class-based span (closest to text)\n\tif (styleParts.length > 0) {\n\t\tconst declarations: string = styleParts.join('; ');\n\t\tconst className: string = collector.getClassName(declarations);\n\t\thtml = `<span class=\"${className}\">${html}</span>`;\n\t}\n\n\t// Then wrap with tag-based marks in rank order\n\tfor (const mark of tagMarks) {\n\t\tconst markSpec: MarkSpec | undefined = registry.getMarkSpec(mark.type);\n\t\tif (markSpec?.toHTMLString) {\n\t\t\thtml = markSpec.toHTMLString(mark, html, exportCtx);\n\t\t}\n\t}\n\n\treturn html;\n}\n","/**\n * DocumentSerializer: converts an immutable Document into sanitized HTML.\n * Pure functions — operates on Document/SchemaRegistry, no class state.\n */\n\nimport DOMPurify from 'dompurify';\nimport { isNodeOfType } from '../model/AttrRegistry.js';\nimport type { BlockNode, Document, InlineNode, TextNode } from '../model/Document.js';\nimport {\n\tgetBlockChildren,\n\tgetInlineChildren,\n\tisInlineNode,\n\tisLeafBlock,\n\tisTextNode,\n\tmarkSetsEqual,\n} from '../model/Document.js';\nimport { SAFE_URI_REGEXP, escapeAttr, escapeHTML } from '../model/HTMLUtils.js';\nimport type { HTMLExportContext } from '../model/NodeSpec.js';\nimport type { SchemaRegistry } from '../model/SchemaRegistry.js';\nimport { CSSClassCollector } from './CSSClassCollector.js';\nimport type { ContentCSSResult } from './ContentHTMLTypes.js';\nimport {\n\tbuildMarkOrder,\n\tserializeMarksToClassHTML,\n\tserializeMarksToHTML,\n} from './MarkSerializer.js';\n\n/** Internal context threaded through all serialization helpers. */\ninterface SerializerContext {\n\treadonly registry?: SchemaRegistry;\n\treadonly collector?: CSSClassCollector;\n\treadonly exportCtx?: HTMLExportContext;\n}\n\n/** Known-safe alignment values accepted by the serializer (defense-in-depth). */\nexport const VALID_ALIGNMENTS: ReadonlySet<string> = new Set(['start', 'center', 'end', 'justify']);\n\n/** Legacy physical → logical alignment mapping (mirrors DocumentParser). */\nconst LEGACY_ALIGNMENT_MAP: Readonly<Record<string, string>> = { left: 'start', right: 'end' };\n\n/** Known-safe direction values (defense-in-depth). `auto` is excluded — it's the default. */\nexport const VALID_DIRECTIONS: ReadonlySet<string> = new Set(['ltr', 'rtl']);\n\n/** Creates an HTMLExportContext for inline style mode. */\nfunction createInlineExportContext(): HTMLExportContext {\n\treturn {\n\t\tstyleAttr(declarations: string): string {\n\t\t\tif (!declarations) return '';\n\t\t\treturn ` style=\"${declarations}\"`;\n\t\t},\n\t};\n}\n\n/** Creates an HTMLExportContext for CSS class mode. */\nfunction createClassExportContext(collector: CSSClassCollector): HTMLExportContext {\n\treturn {\n\t\tstyleAttr(declarations: string): string {\n\t\t\tif (!declarations) return '';\n\t\t\tconst className: string = collector.getClassName(declarations);\n\t\t\treturn ` class=\"${className}\"`;\n\t\t},\n\t};\n}\n\n/**\n * Injects or merges an attribute into the first opening tag of an HTML fragment.\n * Values are expected to be pre-escaped by the caller.\n */\nfunction injectAttrIntoFirstTag(html: string, attr: string, value: string): string {\n\tconst firstTagRange: { start: number; end: number } | undefined = findFirstOpeningTagRange(html);\n\tif (!firstTagRange) return html;\n\tconst firstTag: string = html.slice(firstTagRange.start, firstTagRange.end + 1);\n\tconst pattern: RegExp = new RegExp(`\\\\s${attr}\\\\s*=\\\\s*(\\\"([^\\\"]*)\\\"|'([^']*)')`);\n\tconst existing: RegExpMatchArray | null = firstTag.match(pattern);\n\tif (existing) {\n\t\tconst existingValue: string = existing[2] ?? existing[3] ?? '';\n\t\tif (attr === 'style' && /(?:^|;)\\s*text-align\\s*:/i.test(existingValue)) {\n\t\t\treturn html;\n\t\t}\n\t\tconst sep: string = attr === 'style' ? '; ' : ' ';\n\t\tconst mergedAttr: string = ` ${attr}=\"${existingValue}${sep}${value}\"`;\n\t\tconst nextFirstTag: string = firstTag.replace(pattern, mergedAttr);\n\t\treturn `${html.slice(0, firstTagRange.start)}${nextFirstTag}${html.slice(firstTagRange.end + 1)}`;\n\t}\n\tconst isSelfClosing: boolean = firstTag.endsWith('/>');\n\tconst injectedFirstTag: string = isSelfClosing\n\t\t? `${firstTag.slice(0, -2)} ${attr}=\"${value}\"/>`\n\t\t: `${firstTag.slice(0, -1)} ${attr}=\"${value}\">`;\n\treturn `${html.slice(0, firstTagRange.start)}${injectedFirstTag}${html.slice(firstTagRange.end + 1)}`;\n}\n\n/** Finds the first opening tag range, treating `>` inside quotes as attribute text. */\nfunction findFirstOpeningTagRange(html: string): { start: number; end: number } | undefined {\n\tlet start: number = html.indexOf('<');\n\twhile (start >= 0) {\n\t\tconst nextChar: string | undefined = html[start + 1];\n\t\tif (nextChar && /[A-Za-z]/.test(nextChar)) {\n\t\t\tlet quote: '\"' | \"'\" | undefined;\n\t\t\tfor (let i = start + 2; i < html.length; i++) {\n\t\t\t\tconst char: string = html[i] ?? '';\n\t\t\t\tif (quote) {\n\t\t\t\t\tif (char === quote) quote = undefined;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (char === '\"' || char === \"'\") {\n\t\t\t\t\tquote = char;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (char === '>') {\n\t\t\t\t\treturn { start, end: i };\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\t\tstart = html.indexOf('<', start + 1);\n\t}\n\treturn undefined;\n}\n\n/** Serializes a full document to sanitized HTML, wrapping list items in `<ul>`/`<ol>`. */\nexport function serializeDocumentToHTML(doc: Document, registry?: SchemaRegistry): string {\n\tconst exportCtx: HTMLExportContext = createInlineExportContext();\n\tconst ctx: SerializerContext = { registry, exportCtx };\n\tconst html: string = serializeBlocks(doc.children, ctx);\n\n\tconst allowedTags: string[] = registry ? registry.getAllowedTags() : ['p', 'br', 'div', 'span'];\n\tconst allowedAttrs: string[] = registry ? registry.getAllowedAttrs() : ['style', 'dir'];\n\n\treturn DOMPurify.sanitize(html, {\n\t\tALLOWED_TAGS: allowedTags,\n\t\tALLOWED_ATTR: allowedAttrs,\n\t\tALLOWED_URI_REGEXP: SAFE_URI_REGEXP,\n\t});\n}\n\n/**\n * Serializes a document to HTML with CSS class names instead of inline styles.\n * Returns the HTML and a collected stylesheet with only the rules actually used.\n */\nexport function serializeDocumentToCSS(doc: Document, registry?: SchemaRegistry): ContentCSSResult {\n\tconst collector = new CSSClassCollector();\n\tconst exportCtx: HTMLExportContext = createClassExportContext(collector);\n\tconst ctx: SerializerContext = { registry, collector, exportCtx };\n\tconst html: string = serializeBlocks(doc.children, ctx);\n\n\tconst allowedTags: string[] = registry ? registry.getAllowedTags() : ['p', 'br', 'div', 'span'];\n\tconst allowedAttrs: string[] = registry ? registry.getAllowedAttrs() : ['style', 'class', 'dir'];\n\n\t// In class mode, allow `class` attribute through DOMPurify\n\tif (!allowedAttrs.includes('class')) {\n\t\tallowedAttrs.push('class');\n\t}\n\n\t// Defense-in-depth: strip `style` attribute in class mode to guarantee\n\t// zero inline styles — even from third-party plugins that forgot to use ctx.styleAttr().\n\tconst filteredAttrs: string[] = allowedAttrs.filter((a) => a !== 'style');\n\n\tconst sanitizedHTML: string = DOMPurify.sanitize(html, {\n\t\tALLOWED_TAGS: allowedTags,\n\t\tALLOWED_ATTR: filteredAttrs,\n\t\tALLOWED_URI_REGEXP: SAFE_URI_REGEXP,\n\t});\n\n\treturn { html: sanitizedHTML, css: collector.toCSS(), styleMap: collector.toStyleMap() };\n}\n\n/** Serializes a sequence of blocks to HTML, grouping consecutive list items into wrappers. */\nfunction serializeBlocks(blocks: readonly BlockNode[], ctx: SerializerContext): string {\n\tconst parts: string[] = [];\n\tlet i = 0;\n\n\twhile (i < blocks.length) {\n\t\tconst block: BlockNode | undefined = blocks[i];\n\t\tif (!block) {\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (isNodeOfType(block, 'list_item')) {\n\t\t\t// Collect consecutive list items\n\t\t\tconst listItems: BlockNode[] = [];\n\t\t\twhile (i < blocks.length) {\n\t\t\t\tconst item: BlockNode | undefined = blocks[i];\n\t\t\t\tif (!item || !isNodeOfType(item, 'list_item')) break;\n\t\t\t\tlistItems.push(item);\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tparts.push(serializeListGroup(listItems, ctx));\n\t\t} else {\n\t\t\tparts.push(serializeBlock(block, ctx));\n\t\t\ti++;\n\t\t}\n\t}\n\n\treturn parts.join('');\n}\n\n/**\n * Serializes a group of consecutive list items into properly nested `<ul>`/`<ol>` wrappers.\n * Uses a stack-based algorithm to handle indent-based nesting.\n * Produces valid HTML5: nested lists open *inside* the parent `<li>`.\n */\nfunction serializeListGroup(items: readonly BlockNode[], ctx: SerializerContext): string {\n\tconst parts: string[] = [];\n\tconst stack: { tag: string; indent: number }[] = [];\n\n\tfor (let idx = 0; idx < items.length; idx++) {\n\t\tconst item: BlockNode | undefined = items[idx];\n\t\tif (!item) continue;\n\n\t\tconst listType: string = (item.attrs?.listType as string) ?? 'bullet';\n\t\tconst indent: number = (item.attrs?.indent as number) ?? 0;\n\t\tconst tag: string = listType === 'ordered' ? 'ol' : 'ul';\n\t\t// Pop wrapper levels that are deeper than current indent,\n\t\t// or at the same level when the tag type changes\n\t\twhile (stack.length > 0) {\n\t\t\tconst top = stack[stack.length - 1];\n\t\t\tif (!top) break;\n\n\t\t\tif (top.indent > indent) {\n\t\t\t\tparts.push(`</${top.tag}></li>`);\n\t\t\t\tstack.pop();\n\t\t\t} else if (top.indent === indent && top.tag !== tag) {\n\t\t\t\tparts.push(`</${top.tag}></li>`);\n\t\t\t\tstack.pop();\n\t\t\t} else {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif (stack.length === 0) {\n\t\t\tparts.push(`<${tag}>`);\n\t\t\tstack.push({ tag, indent });\n\t\t} else {\n\t\t\tconst top = stack[stack.length - 1];\n\t\t\tif (top && indent > top.indent) {\n\t\t\t\tparts.push(`<${tag}>`);\n\t\t\t\tstack.push({ tag, indent });\n\t\t\t}\n\t\t}\n\n\t\tconst content: string = serializeBlock(item, ctx);\n\n\t\t// Look ahead: if the next item is deeper, strip </li> so the nested\n\t\t// list opens inside this <li> (valid HTML5 nesting).\n\t\tconst nextItem: BlockNode | undefined = items[idx + 1];\n\t\tconst nextIndent: number | undefined = nextItem\n\t\t\t? ((nextItem.attrs?.indent as number) ?? 0)\n\t\t\t: undefined;\n\n\t\tif (nextIndent !== undefined && nextIndent > indent) {\n\t\t\tparts.push(stripTrailingLiClose(content));\n\t\t} else {\n\t\t\tparts.push(content);\n\t\t}\n\t}\n\n\t// Close all remaining open wrappers\n\twhile (stack.length > 0) {\n\t\tconst top = stack.pop();\n\t\tif (!top) break;\n\t\tparts.push(`</${top.tag}>`);\n\t\tif (stack.length > 0) {\n\t\t\tparts.push('</li>');\n\t\t}\n\t}\n\n\treturn parts.join('');\n}\n\n/** Removes the trailing `</li>` from serialized list item HTML. */\nfunction stripTrailingLiClose(html: string): string {\n\tconst suffix = '</li>';\n\tif (html.endsWith(suffix)) {\n\t\treturn html.slice(0, -suffix.length);\n\t}\n\treturn html;\n}\n\n/** Serializes a single block to HTML using its NodeSpec. */\nfunction serializeBlock(block: BlockNode, ctx: SerializerContext): string {\n\tconst content: string = isLeafBlock(block)\n\t\t? serializeInlineContent(block, ctx)\n\t\t: serializeBlocks(getBlockChildren(block), ctx);\n\tconst spec = ctx.registry?.getNodeSpec(block.type);\n\n\tlet html: string;\n\tif (spec?.toHTML) {\n\t\thtml = spec.toHTML(block, content, ctx.exportCtx);\n\t} else {\n\t\thtml = `<p>${content || '<br>'}</p>`;\n\t}\n\n\t// Inject alignment into the first opening tag (validated against allowlist).\n\tconst rawAlign: string | undefined = (block.attrs as Record<string, unknown>)?.align as\n\t\t| string\n\t\t| undefined;\n\tconst align: string | undefined = rawAlign\n\t\t? (LEGACY_ALIGNMENT_MAP[rawAlign] ?? rawAlign)\n\t\t: undefined;\n\tif (align && align !== 'start' && VALID_ALIGNMENTS.has(align)) {\n\t\tconst safeAlign: string = escapeAttr(align);\n\t\tif (ctx.collector) {\n\t\t\tconst className: string = ctx.collector.getAlignmentClassName(align);\n\t\t\thtml = injectAttrIntoFirstTag(html, 'class', escapeAttr(className));\n\t\t} else {\n\t\t\thtml = injectAttrIntoFirstTag(html, 'style', `text-align: ${safeAlign}`);\n\t\t}\n\t}\n\n\t// Defense-in-depth: inject dir into the first opening tag if not already present.\n\t// NodeSpec toHTML may already inject it; this ensures it survives even without a plugin.\n\tconst dir: string | undefined = (block.attrs as Record<string, unknown>)?.dir as\n\t\t| string\n\t\t| undefined;\n\tif (dir && VALID_DIRECTIONS.has(dir)) {\n\t\tconst firstTagEnd: number = html.indexOf('>');\n\t\tconst firstTag: string = html.slice(0, firstTagEnd + 1);\n\t\tif (!firstTag.includes(' dir=')) {\n\t\t\thtml = injectAttrIntoFirstTag(html, 'dir', escapeAttr(dir));\n\t\t}\n\t}\n\n\treturn html;\n}\n\n/** Serializes inline children (TextNode + InlineNode) of a block. */\nfunction serializeInlineContent(block: BlockNode, ctx: SerializerContext): string {\n\tconst children: readonly (TextNode | InlineNode)[] = getInlineChildren(block);\n\tconst merged: readonly (TextNode | InlineNode)[] = mergeAdjacentTextNodes(children);\n\tconst parts: string[] = [];\n\tconst markOrder: Map<string, number> | undefined = ctx.registry\n\t\t? buildMarkOrder(ctx.registry)\n\t\t: undefined;\n\n\tfor (const child of merged) {\n\t\tif (isInlineNode(child)) {\n\t\t\tconst inlineSpec = ctx.registry?.getInlineNodeSpec(child.inlineType);\n\t\t\tif (inlineSpec?.toHTMLString) {\n\t\t\t\tparts.push(inlineSpec.toHTMLString(child));\n\t\t\t}\n\t\t} else if (ctx.registry && ctx.collector) {\n\t\t\tparts.push(\n\t\t\t\tserializeMarksToClassHTML(\n\t\t\t\t\tchild.text,\n\t\t\t\t\tchild.marks,\n\t\t\t\t\tctx.registry,\n\t\t\t\t\tctx.collector,\n\t\t\t\t\tmarkOrder,\n\t\t\t\t\tctx.exportCtx,\n\t\t\t\t),\n\t\t\t);\n\t\t} else if (ctx.registry) {\n\t\t\tparts.push(\n\t\t\t\tserializeMarksToHTML(child.text, child.marks, ctx.registry, markOrder, ctx.exportCtx),\n\t\t\t);\n\t\t} else if (child.text !== '') {\n\t\t\tparts.push(escapeHTML(child.text));\n\t\t}\n\t}\n\n\treturn parts.join('');\n}\n\n/**\n * Merges adjacent TextNodes that share identical mark sets.\n * InlineNodes act as merge boundaries.\n */\nfunction mergeAdjacentTextNodes(\n\tchildren: readonly (TextNode | InlineNode)[],\n): readonly (TextNode | InlineNode)[] {\n\tif (children.length <= 1) return children;\n\n\tconst result: (TextNode | InlineNode)[] = [];\n\n\tfor (const child of children) {\n\t\tif (isInlineNode(child)) {\n\t\t\tresult.push(child);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst prev: TextNode | InlineNode | undefined = result[result.length - 1];\n\t\tif (prev && isTextNode(prev) && markSetsEqual(prev.marks, child.marks)) {\n\t\t\tresult[result.length - 1] = {\n\t\t\t\ttype: 'text',\n\t\t\t\ttext: prev.text + child.text,\n\t\t\t\tmarks: prev.marks,\n\t\t\t};\n\t\t} else {\n\t\t\tresult.push(child);\n\t\t}\n\t}\n\n\treturn result;\n}\n","/**\n * DocumentParser: converts sanitized HTML strings into immutable Document instances.\n * Pure functions — no class state, no DOM mutation beyond a temporary `<template>`.\n */\n\nimport DOMPurify from 'dompurify';\nimport type { BlockNode, Document, InlineNode, Mark, TextNode } from '../model/Document.js';\nimport {\n\tcreateBlockNode,\n\tcreateDocument,\n\tcreateInlineNode,\n\tcreateTextNode,\n} from '../model/Document.js';\nimport { SAFE_URI_REGEXP } from '../model/HTMLUtils.js';\nimport type { ParseRule } from '../model/ParseRule.js';\nimport type { SchemaRegistry } from '../model/SchemaRegistry.js';\nimport { type InlineTypeName, inlineType, markType, nodeType } from '../model/TypeBrands.js';\nimport { VALID_ALIGNMENTS, VALID_DIRECTIONS } from './DocumentSerializer.js';\n\n/** Options for `parseHTMLToDocument` when importing class-based HTML. */\nexport interface ParseHTMLOptions {\n\t/**\n\t * Style map from a previous `getContentHTML({ cssMode: 'classes' })` call.\n\t * Used to rehydrate class-based HTML back into styled content.\n\t */\n\treadonly styleMap?: ReadonlyMap<string, string>;\n}\n\n/** Parses an HTML string into a Document, applying sanitization and schema parse rules. */\nexport function parseHTMLToDocument(\n\thtml: string,\n\tregistry?: SchemaRegistry,\n\toptions?: ParseHTMLOptions,\n): Document {\n\tconst allowedTags: string[] = registry ? registry.getAllowedTags() : ['p', 'br', 'div', 'span'];\n\tconst allowedAttrs: string[] = registry ? registry.getAllowedAttrs() : ['style', 'dir'];\n\n\t// When a styleMap is provided, also allow `class` through DOMPurify\n\t// so we can read class names and rehydrate styles before parsing.\n\tif (options?.styleMap && !allowedAttrs.includes('class')) {\n\t\tallowedAttrs.push('class');\n\t}\n\n\tconst template = document.createElement('template');\n\ttemplate.innerHTML = DOMPurify.sanitize(html, {\n\t\tALLOWED_TAGS: allowedTags,\n\t\tALLOWED_ATTR: allowedAttrs,\n\t\tALLOWED_URI_REGEXP: SAFE_URI_REGEXP,\n\t});\n\tconst root: DocumentFragment = template.content;\n\n\t// Rehydrate class-based HTML: convert notectl class names back to inline styles\n\tif (options?.styleMap) {\n\t\trehydrateClasses(root, options.styleMap);\n\t}\n\n\tconst blockRules = registry?.getBlockParseRules() ?? [];\n\tconst blocks: BlockNode[] = [];\n\n\tfor (const child of Array.from(root.childNodes)) {\n\t\tparseChildNode(child, blocks, blockRules, registry);\n\t}\n\n\tif (blocks.length === 0) return createDocument();\n\treturn createDocument(blocks);\n}\n\n/**\n * Parses a single child node into block(s), handling all supported block types:\n * lists, tables, block parse rules (headings, blockquotes, code blocks, images, hr),\n * and fallback paragraphs. Used by both top-level parsing and table cell content parsing.\n */\nfunction parseChildNode(\n\tchild: ChildNode,\n\tblocks: BlockNode[],\n\tblockRules: readonly { readonly rule: ParseRule; readonly type: string }[],\n\tregistry?: SchemaRegistry,\n): void {\n\tif (child.nodeType === Node.ELEMENT_NODE) {\n\t\tconst el = child as HTMLElement;\n\t\tconst tag: string = el.tagName.toLowerCase();\n\n\t\t// Lists need cross-element logic — handle before parse rules\n\t\tif (tag === 'ul' || tag === 'ol') {\n\t\t\tconst listType: string = tag === 'ol' ? 'ordered' : 'bullet';\n\t\t\tconst listDir: string | null = el.getAttribute('dir');\n\t\t\tconst parentDir: string | undefined =\n\t\t\t\tlistDir && VALID_DIRECTIONS.has(listDir) ? listDir : undefined;\n\t\t\tparseListElement(el, listType, 0, blocks, registry, parentDir);\n\t\t\treturn;\n\t\t}\n\n\t\t// Tables produce nested block structure: table > table_row > table_cell > paragraph\n\t\tif (tag === 'table') {\n\t\t\tparseTableElement(el, blocks, registry);\n\t\t\treturn;\n\t\t}\n\n\t\t// Try block parse rules\n\t\tconst match = matchBlockParseRule(el, blockRules);\n\t\tif (match) {\n\t\t\tconst spec = registry?.getNodeSpec(match.type);\n\t\t\tconst children: (TextNode | InlineNode)[] = spec?.isVoid\n\t\t\t\t? [createTextNode('')]\n\t\t\t\t: parseElementToInlineContent(el, registry);\n\t\t\tconst attrs: Record<string, string | number | boolean> = {\n\t\t\t\t...(match.attrs as Record<string, string | number | boolean> | undefined),\n\t\t\t};\n\t\t\tif (spec?.attrs?.align) {\n\t\t\t\textractAlignment(el, attrs);\n\t\t\t}\n\t\t\tif (spec?.attrs?.dir) {\n\t\t\t\textractDirection(el, attrs);\n\t\t\t}\n\t\t\tblocks.push(\n\t\t\t\tcreateBlockNode(\n\t\t\t\t\tnodeType(match.type),\n\t\t\t\t\tchildren,\n\t\t\t\t\tundefined,\n\t\t\t\t\tObject.keys(attrs).length > 0 ? attrs : undefined,\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\t// Fallback to paragraph\n\t\tconst inlineContent = parseElementToInlineContent(el, registry);\n\t\tconst attrs: Record<string, string | number | boolean> = {};\n\t\textractAlignment(el, attrs);\n\t\textractDirection(el, attrs);\n\t\tblocks.push(\n\t\t\tcreateBlockNode(\n\t\t\t\tnodeType('paragraph'),\n\t\t\t\tinlineContent,\n\t\t\t\tundefined,\n\t\t\t\tObject.keys(attrs).length > 0 ? attrs : undefined,\n\t\t\t),\n\t\t);\n\t} else if (child.nodeType === Node.TEXT_NODE && child.textContent?.trim()) {\n\t\tblocks.push(createBlockNode(nodeType('paragraph'), [createTextNode(child.textContent.trim())]));\n\t}\n}\n\n/**\n * Recursively parses a list element (`<ul>` or `<ol>`), creating list_item blocks\n * with correct indent depth. Handles nested lists inside `<li>` elements.\n */\nfunction parseListElement(\n\tlistEl: Element,\n\tlistType: string,\n\tdepth: number,\n\tblocks: BlockNode[],\n\tregistry?: SchemaRegistry,\n\tparentDir?: string,\n): void {\n\tfor (const child of Array.from(listEl.children)) {\n\t\tconst tag: string = child.tagName.toLowerCase();\n\n\t\tif (tag === 'li') {\n\t\t\tconst li: HTMLElement = child as HTMLElement;\n\n\t\t\t// Check for checklist: <input type=\"checkbox\">\n\t\t\tconst checkbox: HTMLInputElement | null = li.querySelector(':scope > input[type=\"checkbox\"]');\n\t\t\tconst isChecklist: boolean = checkbox !== null;\n\t\t\tconst checked: boolean = checkbox?.hasAttribute('checked') ?? false;\n\n\t\t\tconst resolvedType: string = isChecklist ? 'checklist' : listType;\n\n\t\t\tconst inlineContent = parseElementToInlineContent(li, registry, true);\n\t\t\tconst attrs: Record<string, string | number | boolean> = {\n\t\t\t\tlistType: resolvedType,\n\t\t\t\tindent: depth,\n\t\t\t\tchecked,\n\t\t\t};\n\n\t\t\t// Propagate direction: item's own dir > parent list dir\n\t\t\tconst liDir: string | null = li.getAttribute('dir');\n\t\t\tconst effectiveDir: string | undefined =\n\t\t\t\tliDir && VALID_DIRECTIONS.has(liDir) ? liDir : parentDir;\n\t\t\tif (effectiveDir) {\n\t\t\t\tattrs.dir = effectiveDir;\n\t\t\t}\n\n\t\t\tblocks.push(createBlockNode(nodeType('list_item'), inlineContent, undefined, attrs));\n\n\t\t\t// Check for nested lists inside this <li>\n\t\t\tfor (const liChild of Array.from(li.children)) {\n\t\t\t\tconst liChildTag: string = liChild.tagName.toLowerCase();\n\t\t\t\tif (liChildTag === 'ul' || liChildTag === 'ol') {\n\t\t\t\t\tconst nestedType: string = liChildTag === 'ol' ? 'ordered' : 'bullet';\n\t\t\t\t\tconst nestedDir: string | null = liChild.getAttribute('dir');\n\t\t\t\t\tconst nestedEffectiveDir: string | undefined =\n\t\t\t\t\t\tnestedDir && VALID_DIRECTIONS.has(nestedDir) ? nestedDir : effectiveDir;\n\t\t\t\t\tparseListElement(liChild, nestedType, depth + 1, blocks, registry, nestedEffectiveDir);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (tag === 'ul' || tag === 'ol') {\n\t\t\t// Direct nested list without wrapping <li> — increment depth\n\t\t\tconst nestedType: string = tag === 'ol' ? 'ordered' : 'bullet';\n\t\t\tconst nestedDir: string | null = child.getAttribute('dir');\n\t\t\tconst nestedEffectiveDir: string | undefined =\n\t\t\t\tnestedDir && VALID_DIRECTIONS.has(nestedDir) ? nestedDir : parentDir;\n\t\t\tparseListElement(child, nestedType, depth + 1, blocks, registry, nestedEffectiveDir);\n\t\t}\n\t}\n}\n\n/**\n * Parses a `<table>` element into nested block structure:\n * table > table_row > table_cell > paragraph.\n * Handles `<thead>`, `<tbody>`, `<tfoot>` transparently.\n */\nfunction parseTableElement(tableEl: Element, blocks: BlockNode[], registry?: SchemaRegistry): void {\n\tconst rows: BlockNode[] = [];\n\n\t// Collect <tr> elements, handling <thead>/<tbody>/<tfoot> wrappers\n\tconst rowElements: Element[] = collectTableRows(tableEl);\n\n\tfor (const trEl of rowElements) {\n\t\tconst cells: BlockNode[] = [];\n\n\t\tfor (const cellChild of Array.from(trEl.children)) {\n\t\t\tconst cellTag: string = cellChild.tagName.toLowerCase();\n\t\t\tif (cellTag !== 'td' && cellTag !== 'th') continue;\n\n\t\t\tconst cellEl: HTMLElement = cellChild as HTMLElement;\n\t\t\tconst cellContent: BlockNode[] = parseTableCellContent(cellEl, registry);\n\t\t\tconst cellAttrs: Record<string, string | number | boolean> = {};\n\t\t\textractCellSpanAttrs(cellEl, cellAttrs);\n\t\t\tconst cellBlock: BlockNode = createBlockNode(\n\t\t\t\tnodeType('table_cell'),\n\t\t\t\tcellContent,\n\t\t\t\tundefined,\n\t\t\t\tObject.keys(cellAttrs).length > 0 ? cellAttrs : undefined,\n\t\t\t);\n\t\t\tcells.push(cellBlock);\n\t\t}\n\n\t\tif (cells.length > 0) {\n\t\t\trows.push(createBlockNode(nodeType('table_row'), cells));\n\t\t}\n\t}\n\n\tif (rows.length > 0) {\n\t\tconst tableAttrs: Record<string, string | number | boolean> = {};\n\t\textractTableBorderColor(tableEl as HTMLElement, tableAttrs);\n\t\tblocks.push(\n\t\t\tcreateBlockNode(\n\t\t\t\tnodeType('table'),\n\t\t\t\trows,\n\t\t\t\tundefined,\n\t\t\t\tObject.keys(tableAttrs).length > 0 ? tableAttrs : undefined,\n\t\t\t),\n\t\t);\n\t}\n}\n\n/** Collects `<tr>` elements from a table, traversing through `<thead>`/`<tbody>`/`<tfoot>`. */\nfunction collectTableRows(tableEl: Element): Element[] {\n\tconst rows: Element[] = [];\n\tfor (const child of Array.from(tableEl.children)) {\n\t\tconst tag: string = child.tagName.toLowerCase();\n\t\tif (tag === 'tr') {\n\t\t\trows.push(child);\n\t\t} else if (tag === 'thead' || tag === 'tbody' || tag === 'tfoot') {\n\t\t\tfor (const nested of Array.from(child.children)) {\n\t\t\t\tif (nested.tagName.toLowerCase() === 'tr') {\n\t\t\t\t\trows.push(nested);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn rows;\n}\n\n/** Regex to extract the `--ntbl-bc` CSS custom property from inline styles. */\nconst BORDER_COLOR_RE = /--ntbl-bc:\\s*(#[0-9a-fA-F]{3,8}|transparent)/;\n\n/** Extracts `borderColor` from a table element's inline style (`--ntbl-bc` CSS variable). */\nfunction extractTableBorderColor(\n\tel: HTMLElement,\n\tattrs: Record<string, string | number | boolean>,\n): void {\n\tconst style: string = el.getAttribute('style') ?? '';\n\tconst match: RegExpMatchArray | null = BORDER_COLOR_RE.exec(style);\n\tif (!match?.[1]) return;\n\tattrs.borderColor = match[1] === 'transparent' ? 'none' : match[1];\n}\n\n/** Extracts `colspan` and `rowspan` attributes from a table cell element. */\nfunction extractCellSpanAttrs(\n\tel: HTMLElement,\n\tattrs: Record<string, string | number | boolean>,\n): void {\n\tconst colspan: string | null = el.getAttribute('colspan');\n\tif (colspan) {\n\t\tconst value: number = Number.parseInt(colspan, 10);\n\t\tif (value > 1) attrs.colspan = value;\n\t}\n\tconst rowspan: string | null = el.getAttribute('rowspan');\n\tif (rowspan) {\n\t\tconst value: number = Number.parseInt(rowspan, 10);\n\t\tif (value > 1) attrs.rowspan = value;\n\t}\n}\n\n/** Parses a table cell's content into blocks, supporting all block types (lists, quotes, etc.). */\nfunction parseTableCellContent(cellEl: HTMLElement, registry?: SchemaRegistry): BlockNode[] {\n\tconst blockRules = registry?.getBlockParseRules() ?? [];\n\tconst cellBlocks: BlockNode[] = [];\n\n\tfor (const child of Array.from(cellEl.childNodes)) {\n\t\tparseChildNode(child, cellBlocks, blockRules, registry);\n\t}\n\n\t// No blocks produced: treat entire cell content as one paragraph\n\tif (cellBlocks.length === 0) {\n\t\tconst inlineContent = parseElementToInlineContent(cellEl, registry);\n\t\tcellBlocks.push(createBlockNode(nodeType('paragraph'), inlineContent));\n\t}\n\n\treturn cellBlocks;\n}\n\n/**\n * Parses an HTML element's inline children into (TextNode | InlineNode)[].\n * Applies mark parse rules and inline node parse rules.\n */\nfunction parseElementToInlineContent(\n\tel: HTMLElement,\n\tregistry?: SchemaRegistry,\n\tskipNestedLists?: boolean,\n): (TextNode | InlineNode)[] {\n\tconst result: (TextNode | InlineNode)[] = [];\n\tconst markRules = registry?.getMarkParseRules() ?? [];\n\tconst inlineRules = registry?.getInlineParseRules() ?? [];\n\twalkElement(el, [], result, markRules, inlineRules, skipNestedLists);\n\treturn result.length > 0 ? result : [createTextNode('')];\n}\n\n/**\n * Recursively walks DOM nodes, collecting marks from parse rules,\n * matching inline node parse rules, and producing TextNodes/InlineNodes.\n */\nfunction walkElement(\n\tnode: Node,\n\tcurrentMarks: Mark[],\n\tresult: (TextNode | InlineNode)[],\n\tmarkRules: readonly { readonly rule: ParseRule; readonly type: string }[],\n\tinlineRules: readonly { readonly rule: ParseRule; readonly type: string }[],\n\tskipNestedLists?: boolean,\n): void {\n\tif (node.nodeType === Node.TEXT_NODE) {\n\t\tconst text: string = node.textContent ?? '';\n\t\tif (text) {\n\t\t\tresult.push(createTextNode(text, [...currentMarks]));\n\t\t}\n\t\treturn;\n\t}\n\n\tif (node.nodeType !== Node.ELEMENT_NODE) return;\n\n\tconst el = node as HTMLElement;\n\tconst tag: string = el.tagName.toLowerCase();\n\n\t// Skip nested lists inside <li> (handled by parseListElement)\n\tif (skipNestedLists && (tag === 'ul' || tag === 'ol')) return;\n\n\t// Skip checkbox inputs inside list items (already handled by parseListElement)\n\tif (skipNestedLists && tag === 'input' && el.getAttribute('type') === 'checkbox') return;\n\n\t// Try inline node parse rules first (atomic — no recursion)\n\tfor (const entry of inlineRules) {\n\t\tif (entry.rule.tag !== tag) continue;\n\n\t\tif (entry.rule.getAttrs) {\n\t\t\tconst attrs = entry.rule.getAttrs(el);\n\t\t\tif (attrs === false) continue;\n\t\t\tresult.push(\n\t\t\t\tcreateInlineNode(\n\t\t\t\t\tinlineType(entry.type) as InlineTypeName,\n\t\t\t\t\tattrs as Readonly<Record<string, string | number | boolean>>,\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tresult.push(createInlineNode(inlineType(entry.type) as InlineTypeName));\n\t\treturn;\n\t}\n\n\tconst marks: Mark[] = [...currentMarks];\n\n\t// Try mark parse rules — collect all matching marks for this element\n\tconst matchedTypes = new Set<string>();\n\tfor (const entry of markRules) {\n\t\tif (entry.rule.tag !== tag) continue;\n\t\tif (matchedTypes.has(entry.type)) continue;\n\n\t\tif (entry.rule.getAttrs) {\n\t\t\tconst attrs = entry.rule.getAttrs(el);\n\t\t\tif (attrs === false) continue;\n\t\t\tif (!marks.some((m) => m.type === entry.type)) {\n\t\t\t\tmarks.push({\n\t\t\t\t\ttype: markType(entry.type),\n\t\t\t\t\t...(Object.keys(attrs).length > 0 ? { attrs } : {}),\n\t\t\t\t} as Mark);\n\t\t\t\tmatchedTypes.add(entry.type);\n\t\t\t}\n\t\t} else {\n\t\t\tif (!marks.some((m) => m.type === entry.type)) {\n\t\t\t\tmarks.push({ type: markType(entry.type) });\n\t\t\t\tmatchedTypes.add(entry.type);\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (const child of Array.from(el.childNodes)) {\n\t\twalkElement(child, marks, result, markRules, inlineRules, skipNestedLists);\n\t}\n}\n\n/** Extracts a validated `dir` attribute or inline `direction` style from an element. */\nfunction extractDirection(el: HTMLElement, attrs: Record<string, string | number | boolean>): void {\n\tconst dir: string | null = el.getAttribute('dir');\n\tif (dir && VALID_DIRECTIONS.has(dir)) {\n\t\tattrs.dir = dir;\n\t\treturn;\n\t}\n\n\t// Fallback: check inline style `direction: rtl/ltr` (common in paste from Word/Docs)\n\tconst styleDir: string = el.style?.direction ?? '';\n\tif (styleDir && VALID_DIRECTIONS.has(styleDir)) {\n\t\tattrs.dir = styleDir;\n\t}\n}\n\n/** Legacy physical → logical alignment mapping for backward-compatible parsing. */\nconst LEGACY_ALIGNMENT_MAP: Readonly<Record<string, string>> = { left: 'start', right: 'end' };\n\n/** Extracts validated `text-align` from an element's style or class and adds it to attrs. */\nfunction extractAlignment(el: HTMLElement, attrs: Record<string, string | number | boolean>): void {\n\t// Check inline style first (works for both normal and rehydrated HTML)\n\tlet align: string = el.style?.textAlign ?? '';\n\tconst mappedAlign: string | undefined = LEGACY_ALIGNMENT_MAP[align];\n\tif (mappedAlign) align = mappedAlign;\n\tif (align && VALID_ALIGNMENTS.has(align)) {\n\t\tattrs.align = align;\n\t\treturn;\n\t}\n\n\t// Check for notectl-align-* class names (from class-based HTML)\n\tfor (const cls of Array.from(el.classList)) {\n\t\tconst match: RegExpMatchArray | null = cls.match(/^notectl-align-(\\w+)$/);\n\t\tlet alignValue: string | undefined = match?.[1];\n\t\tconst mappedAlignValue: string | undefined = LEGACY_ALIGNMENT_MAP[alignValue ?? ''];\n\t\tif (mappedAlignValue) alignValue = mappedAlignValue;\n\t\tif (alignValue && VALID_ALIGNMENTS.has(alignValue)) {\n\t\t\tattrs.align = alignValue;\n\t\t\treturn;\n\t\t}\n\t}\n}\n\n/**\n * Rehydrates class-based HTML by converting notectl class names back to inline styles.\n * This allows existing parse rules (which read inline styles) to work unchanged.\n */\nfunction rehydrateClasses(root: DocumentFragment, styleMap: ReadonlyMap<string, string>): void {\n\tconst elements: NodeListOf<Element> = root.querySelectorAll('[class]');\n\tfor (const el of Array.from(elements)) {\n\t\tconst htmlEl = el as HTMLElement;\n\t\tconst classes: string[] = Array.from(htmlEl.classList);\n\t\tconst toRemove: string[] = [];\n\n\t\tfor (const cls of classes) {\n\t\t\tconst declarations: string | undefined = styleMap.get(cls);\n\t\t\tif (declarations) {\n\t\t\t\t// Append declarations to existing inline style\n\t\t\t\tconst existing: string = htmlEl.getAttribute('style') ?? '';\n\t\t\t\tconst separator: string = existing && !existing.endsWith(';') ? '; ' : '';\n\t\t\t\thtmlEl.setAttribute('style', existing + separator + declarations);\n\t\t\t\ttoRemove.push(cls);\n\t\t\t}\n\t\t}\n\n\t\t// Remove rehydrated class names\n\t\tfor (const cls of toRemove) {\n\t\t\thtmlEl.classList.remove(cls);\n\t\t}\n\t}\n}\n\n/** Matches an element against block parse rules. Returns matched type and attrs. */\nfunction matchBlockParseRule(\n\tel: HTMLElement,\n\trules: readonly { readonly rule: ParseRule; readonly type: string }[],\n): { readonly type: string; readonly attrs?: Record<string, unknown> } | null {\n\tconst tag: string = el.tagName.toLowerCase();\n\tfor (const entry of rules) {\n\t\tif (entry.rule.tag !== tag) continue;\n\t\tif (entry.rule.getAttrs) {\n\t\t\tconst attrs = entry.rule.getAttrs(el);\n\t\t\tif (attrs === false) continue;\n\t\t\treturn { type: entry.type, attrs };\n\t\t}\n\t\treturn { type: entry.type };\n\t}\n\treturn null;\n}\n"],"names":["fnv1aHash","input","hash","i","length","charCodeAt","Math","imul","toString","padStart","CSSClassCollector","classMap","Map","usedHashes","Set","getClassName","declarations","normalized","split","map","d","trim","filter","sort","join","normalizeDeclarations","existing","this","get","suffix","has","String","className","add","set","getAlignmentClassName","alignment","toCSS","size","rules","push","toStyleMap","buildMarkOrder","registry","types","getMarkTypes","order","t","spec","getMarkSpec","rank","serializeMarksToHTML","text","marks","markOrder","exportCtx","html","escapeHTML","sortedMarks","a","b","type","styleParts","tagMarks","mark","markSpec","toHTMLStyle","style","attr","styleAttr","toHTMLString","serializeMarksToClassHTML","collector","VALID_ALIGNMENTS","LEGACY_ALIGNMENT_MAP","left","right","VALID_DIRECTIONS","injectAttrIntoFirstTag","value","firstTagRange","start","indexOf","nextChar","test","quote","char","end","findFirstOpeningTagRange","firstTag","slice","pattern","RegExp","match","existingValue","mergedAttr","nextFirstTag","replace","injectedFirstTag","endsWith","serializeDocumentToHTML","doc","ctx","serializeBlocks","children","allowedTags","getAllowedTags","allowedAttrs","getAllowedAttrs","DOMPurify","sanitize","ALLOWED_TAGS","ALLOWED_ATTR","ALLOWED_URI_REGEXP","SAFE_URI_REGEXP","serializeDocumentToCSS","createClassExportContext","includes","filteredAttrs","css","styleMap","blocks","parts","block","isNodeOfType","listItems","item","serializeListGroup","serializeBlock","items","stack","idx","listType","attrs","indent","tag","top","pop","content","nextItem","nextIndent","stripTrailingLiClose","isLeafBlock","merged","result","child","isInlineNode","prev","isTextNode","markSetsEqual","mergeAdjacentTextNodes","getInlineChildren","inlineSpec","getInlineNodeSpec","inlineType","serializeInlineContent","getBlockChildren","getNodeSpec","toHTML","rawAlign","align","safeAlign","escapeAttr","dir","firstTagEnd","parseHTMLToDocument","options","template","document","createElement","innerHTML","root","elements","querySelectorAll","el","Array","from","htmlEl","classes","classList","toRemove","cls","getAttribute","separator","setAttribute","remove","rehydrateClasses","blockRules","getBlockParseRules","childNodes","parseChildNode","createDocument","nodeType","Node","ELEMENT_NODE","tagName","toLowerCase","listDir","parseListElement","tableEl","rows","rowElements","nested","collectTableRows","trEl","cells","cellChild","cellTag","cellEl","cellContent","parseTableCellContent","cellAttrs","extractCellSpanAttrs","cellBlock","createBlockNode","Object","keys","tableAttrs","BORDER_COLOR_RE","exec","borderColor","extractTableBorderColor","parseTableElement","entry","rule","getAttrs","matchBlockParseRule","isVoid","createTextNode","parseElementToInlineContent","extractAlignment","extractDirection","inlineContent","TEXT_NODE","textContent","listEl","depth","parentDir","li","checkbox","querySelector","isChecklist","checked","hasAttribute","resolvedType","liDir","effectiveDir","liChild","liChildTag","nestedType","nestedDir","colspan","Number","parseInt","rowspan","cellBlocks","skipNestedLists","walkElement","getMarkParseRules","getInlineParseRules","node","currentMarks","markRules","inlineRules","createInlineNode","matchedTypes","some","m","markType","styleDir","direction","textAlign","mappedAlign","alignValue","mappedAlignValue"],"mappings":"sSAqCA,SAASA,EAAUC,GAClB,IAAIC,EAToB,WAUxB,IAAA,IAASC,EAAI,EAAGA,EAAIF,EAAMG,OAAQD,IACjCD,GAAQD,EAAMI,WAAWF,GACzBD,EAAOI,KAAKC,KAAKL,EAVD,UAcjB,OADyBA,IAAS,GAClBM,SAnCC,IAmCmBC,SAjCb,EAiCuC,IAC/D,CASO,MAAMC,EAEKC,4BAAoCC,IAEpCC,8BAA8BC,IAM/C,YAAAC,CAAaC,GACZ,MAAMC,EA/CR,SAA+BD,GAC9B,OAAOA,EACLE,MAAM,KACNC,IAAKC,GAAMA,EAAEC,QACbC,OAAQF,GAAMA,EAAEhB,OAAS,GACzBmB,OACAC,KAAK,KACR,CAwC6BC,CAAsBT,GAC3CU,EAA+BC,KAAKhB,SAASiB,IAAIX,GACvD,GAAIS,EAAU,OAAOA,EAErB,IAAIxB,EAAeF,EAAUiB,GACzBY,EAAS,EAGb,KAAOF,KAAKd,WAAWiB,IAAI5B,IAC1B2B,IACA3B,EAAOF,EAAUiB,EAAac,OAAOF,IAGtC,MAAMG,EAAoB,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@@ -0,0 +1,2 @@
1
+ import{b as t}from"./TypeBrands-Bp_Z_o5Y.mjs";function e(t,e){const n=document.createElement(t);return n.setAttribute("data-block-id",e),n}function n(e,n){const r=[];let a=n;for(;a&&a!==e;)a.hasAttribute("data-block-id")&&r.unshift(t(a.getAttribute("data-block-id")??"")),a=a.parentElement;return r}function r(t,e){let n=e;for(;n&&n!==t;){if(n instanceof HTMLElement&&n.hasAttribute("data-block-id"))return n;n=n.parentNode}return null}export{n as b,e as c,r as f};
2
+ //# sourceMappingURL=DomUtils-CznMAZZg.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DomUtils-CznMAZZg.mjs","sources":["../../src/view/DomUtils.ts"],"sourcesContent":["/**\n * DOM utility functions for the view layer.\n * Keeps DOM operations out of the model layer.\n */\n\nimport type { BlockId } from '../model/TypeBrands.js';\nimport { blockId as toBlockId } from '../model/TypeBrands.js';\n\n/**\n * Creates an HTMLElement with the required `data-block-id` attribute.\n *\n * Intentionally used by plugins in `NodeSpec.toDOM()` callbacks —\n * this is an accepted targeted import per ARCHITECTURE.md.\n */\nexport function createBlockElement(tag: string, blockId: BlockId): HTMLElement {\n\tconst el = document.createElement(tag);\n\tel.setAttribute('data-block-id', blockId);\n\treturn el;\n}\n\n/** Builds the block path from a leaf element up to the container. */\nexport function buildBlockPath(container: HTMLElement, leafBlockEl: HTMLElement): BlockId[] {\n\tconst path: BlockId[] = [];\n\tlet current: HTMLElement | null = leafBlockEl;\n\twhile (current && current !== container) {\n\t\tif (current.hasAttribute('data-block-id')) {\n\t\t\tpath.unshift(toBlockId(current.getAttribute('data-block-id') ?? ''));\n\t\t}\n\t\tcurrent = current.parentElement;\n\t}\n\treturn path;\n}\n\n/** Finds the nearest ancestor element with a `data-block-id` attribute. */\nexport function findBlockAncestor(container: HTMLElement, node: Node): HTMLElement | null {\n\tlet current: Node | null = node;\n\twhile (current && current !== container) {\n\t\tif (current instanceof HTMLElement && current.hasAttribute('data-block-id')) {\n\t\t\treturn current;\n\t\t}\n\t\tcurrent = current.parentNode;\n\t}\n\treturn null;\n}\n"],"names":["createBlockElement","tag","blockId","el","document","createElement","setAttribute","buildBlockPath","container","leafBlockEl","path","current","hasAttribute","unshift","toBlockId","getAttribute","parentElement","findBlockAncestor","node","HTMLElement","parentNode"],"mappings":"8CAcO,SAASA,EAAmBC,EAAaC,GAC/C,MAAMC,EAAKC,SAASC,cAAcJ,GAElC,OADAE,EAAGG,aAAa,gBAAiBJ,GAC1BC,CACR,CAGO,SAASI,EAAeC,EAAwBC,GACtD,MAAMC,EAAkB,GACxB,IAAIC,EAA8BF,EAClC,KAAOE,GAAWA,IAAYH,GACzBG,EAAQC,aAAa,kBACxBF,EAAKG,QAAQC,EAAUH,EAAQI,aAAa,kBAAoB,KAEjEJ,EAAUA,EAAQK,cAEnB,OAAON,CACR,CAGO,SAASO,EAAkBT,EAAwBU,GACzD,IAAIP,EAAuBO,EAC3B,KAAOP,GAAWA,IAAYH,GAAW,CACxC,GAAIG,aAAmBQ,aAAeR,EAAQC,aAAa,iBAC1D,OAAOD,EAERA,EAAUA,EAAQS,UACnB,CACA,OAAO,IACR"}
@@ -0,0 +1,2 @@
1
+ const t=/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|blob|data):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i;function e(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}const n=e,o=/* @__PURE__ */new Set(["p","div","h1","h2","h3","h4","h5","h6","ul","ol","li","blockquote","table","thead","tbody","tfoot","tr","td","th","pre","figure","figcaption","section","article","header","footer"]),a=/* @__PURE__ */new Set(["br","hr","img","input","col","area","meta","link"]);function s(t,e=" "){const n=function(t){const e=[];let n=0,o=0;for(;o<t.length;){if("<"!==t[o]){o+=1;continue}let a=o+1;a<t.length&&"/"===t[a]&&(a+=1);const s=t[a];if(a>=t.length||!s||!r(s)){o+=1;continue}const c=i(t,a+1);if(void 0===c)break;o>n&&e.push(t.slice(n,o)),e.push(t.slice(o,c+1)),o=c+1,n=o}return n<t.length&&e.push(t.slice(n)),e}(t),s=[];let l=0,h="";const u=()=>{const t=h.trim();t.length>0&&s.push(`${e.repeat(l)}${t}`),h=""};for(const i of n){const t=i.startsWith("<")?c(i):"",n=o.has(t),r=a.has(t);n||r?(u(),i.startsWith("</")?(l=Math.max(0,l-1),s.push(`${e.repeat(l)}${i}`)):(s.push(`${e.repeat(l)}${i}`),!n||r||i.endsWith("/>")||(l+=1))):h+=i}return u(),s.join("\n")}function i(t,e){let n;for(let o=e;o<t.length;o+=1){const e=t[o]??"";if(n)e===n&&(n=void 0);else if('"'!==e&&"'"!==e){if(">"===e)return o}else n=e}}function r(t){return t>="a"&&t<="z"||t>="A"&&t<="Z"}function c(t){const e=t.match(/^<\/?([a-zA-Z][a-zA-Z0-9]*)/);return e?.[1]?.toLowerCase()??""}export{t as S,e as a,n as e,s as f};
2
+ //# sourceMappingURL=HTMLUtils-Cxy99Ak2.mjs.map