reactjs-tiptap-editor 1.0.25 → 1.0.26

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 (289) hide show
  1. package/lib/{ActionMenuButton-8cTG45Ft.js → ActionMenuButton-B4KDkZ0z.js} +1 -1
  2. package/lib/{ActionMenuButton-CXeFhner.cjs → ActionMenuButton-C3Cfeza9.cjs} +1 -1
  3. package/lib/Attachment.cjs +1 -1
  4. package/lib/Attachment.js +25 -25
  5. package/lib/Blockquote.cjs +5 -5
  6. package/lib/Blockquote.js +1490 -53
  7. package/lib/Bold.cjs +1 -1
  8. package/lib/Bold.js +3 -3
  9. package/lib/BulletList.cjs +1 -1
  10. package/lib/BulletList.js +2 -2
  11. package/lib/Callout.cjs +1 -1
  12. package/lib/Callout.js +222 -8
  13. package/lib/Clear.cjs +1 -1
  14. package/lib/Clear.js +2 -2
  15. package/lib/Code.cjs +1 -1
  16. package/lib/Code.js +56 -39
  17. package/lib/CodeBlock.cjs +1 -1
  18. package/lib/CodeBlock.js +8 -4
  19. package/lib/CodeView.cjs +1 -1
  20. package/lib/CodeView.js +2 -2
  21. package/lib/Color.cjs +1 -1
  22. package/lib/Color.js +3 -3
  23. package/lib/Column.cjs +1 -1
  24. package/lib/Column.js +2 -2
  25. package/lib/{Drawer-TJY4NuHx.cjs → Drawer-D7E9kTca.cjs} +1 -1
  26. package/lib/{Drawer-C-EO1uoK.js → Drawer-DA0FLHs9.js} +20 -20
  27. package/lib/Drawer.cjs +1 -1
  28. package/lib/Drawer.js +4 -4
  29. package/lib/Emoji.cjs +1 -1
  30. package/lib/Emoji.js +1644 -148
  31. package/lib/Excalidraw.cjs +1 -1
  32. package/lib/Excalidraw.js +10 -10
  33. package/lib/ExportPdf.cjs +1 -1
  34. package/lib/ExportPdf.js +2 -2
  35. package/lib/ExportWord.cjs +1 -1
  36. package/lib/ExportWord.js +2 -2
  37. package/lib/FontFamily.cjs +1 -1
  38. package/lib/FontFamily.js +5 -5
  39. package/lib/FontSize.cjs +1 -1
  40. package/lib/FontSize.js +5 -5
  41. package/lib/FormatPainter.cjs +1 -0
  42. package/lib/FormatPainter.js +133 -0
  43. package/lib/Heading.cjs +1 -1
  44. package/lib/Heading.js +10 -6
  45. package/lib/Highlight.cjs +1 -1
  46. package/lib/Highlight.js +3 -3
  47. package/lib/History.cjs +7 -1
  48. package/lib/History.js +519 -478
  49. package/lib/HorizontalRule.cjs +1 -1
  50. package/lib/HorizontalRule.js +2 -2
  51. package/lib/{Iframe-CGb6-2LD.js → Iframe-DZ3r3QzK.js} +7 -7
  52. package/lib/{Iframe-5zx43DL4.cjs → Iframe-OMVd0xa_.cjs} +1 -1
  53. package/lib/Iframe.cjs +1 -1
  54. package/lib/Iframe.js +3 -3
  55. package/lib/Image.cjs +1 -1
  56. package/lib/Image.js +6 -6
  57. package/lib/ImageGif.cjs +1 -1
  58. package/lib/ImageGif.js +35 -35
  59. package/lib/ImportWord.cjs +1 -1
  60. package/lib/ImportWord.js +15 -15
  61. package/lib/{Indent-DuwV8s1t.cjs → Indent-QgCoonRk.cjs} +1 -1
  62. package/lib/{Indent-CdMYsDNS.js → Indent-kI4G-clX.js} +2 -2
  63. package/lib/Indent.cjs +1 -1
  64. package/lib/Indent.js +2 -2
  65. package/lib/Italic.cjs +1 -1
  66. package/lib/Italic.js +2 -2
  67. package/lib/{Katex-CCP_ZQz2.js → Katex-BPbXjcZQ.js} +6 -7
  68. package/lib/Katex-CUofhjB5.cjs +4 -0
  69. package/lib/Katex.cjs +1 -1
  70. package/lib/Katex.js +3 -3
  71. package/lib/LineHeight.cjs +1 -1
  72. package/lib/LineHeight.js +4 -4
  73. package/lib/Link.cjs +1 -1
  74. package/lib/Link.js +2 -2
  75. package/lib/{LinkEditBlock-B1m-TVMu.js → LinkEditBlock-BYWwH2_x.js} +59 -32
  76. package/lib/{LinkEditBlock-DQ8-iufJ.cjs → LinkEditBlock-Z7RRurvx.cjs} +2 -2
  77. package/lib/MarkdownPaste.cjs +1 -1
  78. package/lib/MarkdownPaste.js +1 -1
  79. package/lib/Mention.cjs +1 -1
  80. package/lib/Mention.js +9 -5
  81. package/lib/Mermaid.cjs +2 -2
  82. package/lib/Mermaid.js +61 -62
  83. package/lib/MoreMark.cjs +1 -1
  84. package/lib/MoreMark.js +5 -5
  85. package/lib/OrderedList.cjs +1 -1
  86. package/lib/OrderedList.js +2 -2
  87. package/lib/SearchAndReplace.cjs +1 -1
  88. package/lib/SearchAndReplace.js +14 -14
  89. package/lib/SlashCommand.cjs +1 -1
  90. package/lib/SlashCommand.js +7 -7
  91. package/lib/{SlashCommandNodeView-Dt6n1SP9.js → SlashCommandNodeView-C0l3Fb_3.js} +10 -10
  92. package/lib/{SlashCommandNodeView-DNixmQGa.cjs → SlashCommandNodeView-DPPmYEjC.cjs} +1 -1
  93. package/lib/Strike.cjs +1 -1
  94. package/lib/Strike.js +2 -2
  95. package/lib/{Table-C5JxBXef.cjs → Table-D5G3rfwb.cjs} +5 -5
  96. package/lib/{Table-DdEgaUwa.js → Table-DwseaFSD.js} +115 -97
  97. package/lib/Table.cjs +1 -1
  98. package/lib/Table.js +1 -1
  99. package/lib/TaskList.cjs +1 -1
  100. package/lib/TaskList.js +2 -2
  101. package/lib/TextAlign.cjs +1 -1
  102. package/lib/TextAlign.js +11 -11
  103. package/lib/TextDirection.cjs +1 -1
  104. package/lib/TextDirection.js +3 -3
  105. package/lib/TextUnderline.cjs +1 -1
  106. package/lib/TextUnderline.js +2 -2
  107. package/lib/{Twitter-Dnz9qyW0.js → Twitter-DP26Lkn8.js} +195 -195
  108. package/lib/Twitter-q4ZGZL0i.cjs +1 -0
  109. package/lib/Twitter.cjs +1 -1
  110. package/lib/Twitter.js +3 -3
  111. package/lib/Video.cjs +1 -1
  112. package/lib/Video.js +5 -5
  113. package/lib/bubble.cjs +6 -6
  114. package/lib/bubble.js +2783 -2137
  115. package/lib/{clsx-D6gYQn3o.cjs → clsx-DRbkQ4T7.cjs} +1 -1
  116. package/lib/{clsx-0OU6n9va.js → clsx-_bq4MQQ7.js} +14 -4
  117. package/lib/components/Bubble/RichTextBubbleCallout.d.ts +1 -1
  118. package/lib/components/Bubble/RichTextBubbleCodeBlock.d.ts +1 -1
  119. package/lib/components/Bubble/RichTextBubbleColumns.d.ts +1 -1
  120. package/lib/components/Bubble/RichTextBubbleDrawer.d.ts +1 -1
  121. package/lib/components/Bubble/RichTextBubbleExcalidraw.d.ts +1 -1
  122. package/lib/components/Bubble/RichTextBubbleIframe.d.ts +1 -1
  123. package/lib/components/Bubble/RichTextBubbleKatex.d.ts +2 -1
  124. package/lib/components/Bubble/RichTextBubbleLink.d.ts +1 -1
  125. package/lib/components/Bubble/RichTextBubbleMedia.d.ts +3 -3
  126. package/lib/components/Bubble/RichTextBubbleMenuDragHandle.d.ts +2 -1
  127. package/lib/components/Bubble/RichTextBubbleMermaid.d.ts +1 -1
  128. package/lib/components/Bubble/RichTextBubbleTable.d.ts +1 -1
  129. package/lib/components/Bubble/RichTextBubbleText.d.ts +1 -1
  130. package/lib/components/Bubble/RichTextBubbleTwitter.d.ts +1 -1
  131. package/lib/components/ColorPicker.d.ts +1 -1
  132. package/lib/components/ReactBus.d.ts +1 -1
  133. package/lib/components/RichTextProvider.d.ts +1 -1
  134. package/lib/components/SlashDialogTrigger/RenderDialogUploadImage.d.ts +1 -1
  135. package/lib/components/SlashDialogTrigger/RenderDialogUploadVideo.d.ts +1 -1
  136. package/lib/components/SlashDialogTrigger/SlashDialogTrigger.d.ts +2 -1
  137. package/lib/components/icons/Activity.d.ts +2 -1
  138. package/lib/components/icons/Animas.d.ts +2 -1
  139. package/lib/components/icons/AspectRatio.d.ts +1 -1
  140. package/lib/components/icons/Blockquote.d.ts +1 -1
  141. package/lib/components/icons/CodeView.d.ts +1 -1
  142. package/lib/components/icons/ColumnAddLeft.d.ts +1 -1
  143. package/lib/components/icons/ColumnAddRight.d.ts +1 -1
  144. package/lib/components/icons/DeleteColumn.d.ts +1 -1
  145. package/lib/components/icons/DeleteRow.d.ts +1 -1
  146. package/lib/components/icons/Direction.d.ts +1 -1
  147. package/lib/components/icons/Excalidraw.d.ts +1 -1
  148. package/lib/components/icons/ExportPdf.d.ts +1 -1
  149. package/lib/components/icons/ExportWord.d.ts +2 -1
  150. package/lib/components/icons/FileWordOutline.d.ts +1 -1
  151. package/lib/components/icons/Flag.d.ts +2 -1
  152. package/lib/components/icons/Food.d.ts +2 -1
  153. package/lib/components/icons/GIfIcon.d.ts +1 -1
  154. package/lib/components/icons/Html.d.ts +1 -1
  155. package/lib/components/icons/Icon.d.ts +1 -1
  156. package/lib/components/icons/IconColorFill.d.ts +1 -1
  157. package/lib/components/icons/IconHighlightFill.d.ts +1 -1
  158. package/lib/components/icons/ImportWord.d.ts +2 -1
  159. package/lib/components/icons/LeftToRight.d.ts +1 -1
  160. package/lib/components/icons/LineHeight.d.ts +1 -1
  161. package/lib/components/icons/MenuDown.d.ts +1 -1
  162. package/lib/components/icons/Mermaid.d.ts +1 -1
  163. package/lib/components/icons/NoFill.d.ts +1 -1
  164. package/lib/components/icons/Object.d.ts +2 -1
  165. package/lib/components/icons/RightToLeft.d.ts +1 -1
  166. package/lib/components/icons/SizeL.d.ts +1 -1
  167. package/lib/components/icons/SizeM.d.ts +1 -1
  168. package/lib/components/icons/SizeS.d.ts +1 -1
  169. package/lib/components/icons/Symbol.d.ts +2 -1
  170. package/lib/components/icons/Travel.d.ts +2 -1
  171. package/lib/components/icons/Twitter.d.ts +1 -1
  172. package/lib/components/ui/dialog.d.ts +2 -2
  173. package/lib/components/ui/dropdown-menu.d.ts +1 -1
  174. package/lib/components/ui/emoji-picker.d.ts +4 -4
  175. package/lib/components/ui/toaster.d.ts +1 -1
  176. package/lib/{dropdown-menu-ROihzXsP.js → dropdown-menu-BKSX4gvT.js} +1 -1
  177. package/lib/{dropdown-menu-yQ-sQ1k4.cjs → dropdown-menu-CURWpB9o.cjs} +1 -1
  178. package/lib/extensions/Attachment/components/NodeViewAttachment/FileIcon.d.ts +1 -1
  179. package/lib/extensions/Attachment/components/NodeViewAttachment/NodeViewAttachment.d.ts +1 -1
  180. package/lib/extensions/Attachment/components/RichTextAttachment.d.ts +1 -1
  181. package/lib/extensions/Blockquote/components/RichTextBlockquote.d.ts +1 -1
  182. package/lib/extensions/Bold/components/RichTextBold.d.ts +1 -1
  183. package/lib/extensions/BulletList/components/RichTextBulletList.d.ts +1 -1
  184. package/lib/extensions/Callout/components/NodeViewCallout/NodeViewCallout.d.ts +1 -1
  185. package/lib/extensions/Callout/components/RichTextCallout.d.ts +1 -1
  186. package/lib/extensions/Clear/components/RichTextClear.d.ts +1 -1
  187. package/lib/extensions/Code/components/RichTextCode.d.ts +1 -1
  188. package/lib/extensions/CodeBlock/components/RichTextCodeBlock.d.ts +2 -1
  189. package/lib/extensions/CodeView/components/RichTextCodeView.d.ts +1 -1
  190. package/lib/extensions/Color/components/RichTextColor.d.ts +1 -1
  191. package/lib/extensions/Column/components/RichTextColumn.d.ts +1 -1
  192. package/lib/extensions/Drawer/components/ControlDrawer/ControlDrawer.d.ts +2 -1
  193. package/lib/extensions/Drawer/components/ControlDrawer/icon.d.ts +27 -27
  194. package/lib/extensions/Drawer/components/EditDrawerBlock.d.ts +1 -1
  195. package/lib/extensions/Drawer/components/NodeViewDrawer/NodeViewDrawer.d.ts +2 -1
  196. package/lib/extensions/Drawer/components/RichTextDrawer.d.ts +1 -1
  197. package/lib/extensions/Emoji/components/RichTextEmoji.d.ts +2 -1
  198. package/lib/extensions/Excalidraw/components/NodeViewExcalidraw/NodeViewExcalidraw.d.ts +2 -1
  199. package/lib/extensions/Excalidraw/components/RichTextExcalidraw.d.ts +1 -1
  200. package/lib/extensions/ExportPdf/components/RichTextExportPdf.d.ts +1 -1
  201. package/lib/extensions/ExportWord/components/RichTextExportWord.d.ts +1 -1
  202. package/lib/extensions/FontFamily/components/RichTextFontFamily.d.ts +1 -1
  203. package/lib/extensions/FontSize/components/RichTextFontSize.d.ts +1 -1
  204. package/lib/extensions/FormatPainter/FormatPainter.d.ts +17 -0
  205. package/lib/extensions/FormatPainter/components/RichTextFormatPainter.d.ts +1 -0
  206. package/lib/extensions/FormatPainter/index.d.ts +1 -0
  207. package/lib/extensions/Heading/components/RichTextHeading.d.ts +1 -1
  208. package/lib/extensions/Highlight/components/RichTextHighlight.d.ts +2 -1
  209. package/lib/extensions/History/components/RichTextHistory.d.ts +3 -2
  210. package/lib/extensions/HorizontalRule/components/RichTextHorizontalRule.d.ts +1 -1
  211. package/lib/extensions/Iframe/components/IframeNodeView.d.ts +1 -1
  212. package/lib/extensions/Iframe/components/RichTextIframe.d.ts +1 -1
  213. package/lib/extensions/Image/components/ImageCropper.d.ts +2 -1
  214. package/lib/extensions/Image/components/ImageView.d.ts +2 -1
  215. package/lib/extensions/Image/components/RichTextImage.d.ts +1 -1
  216. package/lib/extensions/ImageGif/components/ImageGifView.d.ts +2 -1
  217. package/lib/extensions/ImageGif/components/RichTextImageGif.d.ts +2 -1
  218. package/lib/extensions/ImportWord/components/RichTextImportWord.d.ts +1 -1
  219. package/lib/extensions/Indent/components/RichTextIndent.d.ts +1 -1
  220. package/lib/extensions/Italic/components/RichTextItalic.d.ts +1 -1
  221. package/lib/extensions/Katex/components/KatexWrapper.d.ts +1 -1
  222. package/lib/extensions/Katex/components/RichTextKatex.d.ts +1 -1
  223. package/lib/extensions/LineHeight/components/RichTextLightHeight.d.ts +1 -1
  224. package/lib/extensions/Link/components/LinkEditBlock.d.ts +1 -1
  225. package/lib/extensions/Link/components/LinkViewBlock.d.ts +2 -1
  226. package/lib/extensions/Link/components/RichTextLink.d.ts +1 -1
  227. package/lib/extensions/Mermaid/components/NodeViewMermaid/NodeViewMermaid.d.ts +2 -1
  228. package/lib/extensions/Mermaid/components/RichTextMermaid.d.ts +1 -1
  229. package/lib/extensions/MoreMark/components/RichTextMoreMark.d.ts +1 -1
  230. package/lib/extensions/OrderedList/components/RichTextOrderedList.d.ts +1 -1
  231. package/lib/extensions/SearchAndReplace/components/RichTextSearchAndReplace.d.ts +1 -1
  232. package/lib/extensions/SlashCommand/components/SlashCommandList.d.ts +1 -1
  233. package/lib/extensions/Strike/components/RichTextStrike.d.ts +1 -1
  234. package/lib/extensions/Table/components/CreateTablePopover.d.ts +2 -1
  235. package/lib/extensions/Table/components/RichTextTable.d.ts +2 -1
  236. package/lib/extensions/TaskList/components/RichTextTaskList.d.ts +1 -1
  237. package/lib/extensions/TextAlign/components/RichTextAlign.d.ts +1 -1
  238. package/lib/extensions/TextDirection/components/RichTextTextDirection.d.ts +1 -1
  239. package/lib/extensions/TextUnderline/components/RichTextUnderline.d.ts +1 -1
  240. package/lib/extensions/Twitter/components/FormEditLinkTwitter.d.ts +1 -1
  241. package/lib/extensions/Twitter/components/NodeViewTweet.d.ts +1 -1
  242. package/lib/extensions/Twitter/components/RichTextTwitter.d.ts +1 -1
  243. package/lib/extensions/Video/components/RichTextVideo.d.ts +1 -1
  244. package/lib/index-BGfIcDCQ.cjs +26 -0
  245. package/lib/index-BaR0Brts.js +1115 -0
  246. package/lib/index-BgNKVyMW.cjs +2 -0
  247. package/lib/index-BpLw6ebr.cjs +1 -0
  248. package/lib/{index-X6WZUM9O.js → index-C52cuQ_Y.js} +1503 -1352
  249. package/lib/index-CDw4Eszh.cjs +12 -0
  250. package/lib/{index-CUvjYuRp.cjs → index-CHVV5iY-.cjs} +1 -1
  251. package/lib/{index-zw-Kd38i.js → index-CJMI7Fjf.js} +1 -1
  252. package/lib/{index-D-Ouz0vF.js → index-DQy9iBzV.js} +1 -1
  253. package/lib/index-Dbm_Mans.js +1756 -0
  254. package/lib/{index-oj858lQO.js → index-DtyAGMbq.js} +208 -208
  255. package/lib/{index-BblvcbTH.js → index-Dx-Dh7KS.js} +1464 -1348
  256. package/lib/{index-BAb_UADw.cjs → index-SEMQrdk2.cjs} +1 -1
  257. package/lib/index-aujjnfSJ.cjs +1 -0
  258. package/lib/index.cjs +1 -1
  259. package/lib/index.js +12 -12
  260. package/lib/{jsx-runtime-CT7Pcg-t.js → jsx-runtime-DE8oVoME.js} +3 -1
  261. package/lib/locale-bundle.cjs +1 -1
  262. package/lib/locale-bundle.js +1 -1
  263. package/lib/locales/index.d.ts +1 -1
  264. package/lib/{popover-BfWFqCIs.js → popover-BB-ZDnqk.js} +1 -1
  265. package/lib/{popover-BPzkMuyi.cjs → popover-CrywEkBR.cjs} +1 -1
  266. package/lib/{renderNodeView-D--fDFov.cjs → renderNodeView-5h3-p80E.cjs} +1 -1
  267. package/lib/{renderNodeView-CfWJK4rG.js → renderNodeView-DoKZ4GYy.js} +2 -2
  268. package/lib/{separator-DpaS43Gt.cjs → separator-BGO9AZp4.cjs} +1 -1
  269. package/lib/{separator-CBPrZizK.js → separator-DuuOJRQd.js} +21 -21
  270. package/lib/store/EditorEditableReactive.d.ts +1 -1
  271. package/lib/store/ThemeColorReactive.d.ts +1 -1
  272. package/lib/style.css +1 -1
  273. package/lib/types.d.ts +2 -2
  274. package/lib/{updatePosition-DGPtRfWN.cjs → updatePosition-B1oRJE1x.cjs} +1 -1
  275. package/lib/{updatePosition-BwzAsiY0.js → updatePosition-CFTYKYNJ.js} +2 -2
  276. package/package.json +79 -66
  277. package/lib/Callout-DWOMZPiP.cjs +0 -1
  278. package/lib/Callout-ZlPQrMEt.js +0 -340
  279. package/lib/Katex-D9FP7EUE.cjs +0 -4
  280. package/lib/Twitter--tfifMt1.cjs +0 -1
  281. package/lib/index-BF3EVCB1.cjs +0 -2
  282. package/lib/index-Bcj8cyOO.cjs +0 -24
  283. package/lib/index-CGjT-a9h.js +0 -1377
  284. package/lib/index-CPTpXLfX.cjs +0 -11
  285. package/lib/index-CWw4s87s.cjs +0 -1
  286. package/lib/index-Cal5SPfB.js +0 -779
  287. package/lib/index-Gi752TMk.cjs +0 -1
  288. package/lib/textarea-Bl64keav.js +0 -20
  289. package/lib/textarea-wvARZKyA.cjs +0 -1
package/lib/bubble.cjs CHANGED
@@ -1,6 +1,6 @@
1
- "use strict";var So=Object.create;var jn=Object.defineProperty;var Co=Object.getOwnPropertyDescriptor;var ko=Object.getOwnPropertyNames;var Eo=Object.getPrototypeOf,_o=Object.prototype.hasOwnProperty;var To=(e,t,n)=>t in e?jn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Do=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ko(t))!_o.call(e,s)&&s!==n&&jn(e,s,{get:()=>t[s],enumerable:!(i=Co(t,s))||i.enumerable});return e};var Ao=(e,t,n)=>(n=e!=null?So(Eo(e)):{},Do(t||!e||!e.__esModule?jn(n,"default",{value:e,enumerable:!0}):n,e));var Ne=(e,t,n)=>To(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),T=require("./index-Bcj8cyOO.cjs"),q=require("./index-BF3EVCB1.cjs"),Y=require("@tiptap/pm/state"),Ls=require("./Table-C5JxBXef.cjs"),Ps=require("./clsx-D6gYQn3o.cjs"),b=require("react"),wi=require("react-dom"),m=require("./index-Gi752TMk.cjs"),St=require("./Callout-DWOMZPiP.cjs"),dt=require("./Katex-D9FP7EUE.cjs"),B=require("./index-CWw4s87s.cjs"),Pt=require("lucide-react"),Rn=require("./CodeBlock.cjs"),wt=require("./separator-DpaS43Gt.cjs"),kt=require("./popover-BPzkMuyi.cjs"),Gi=require("./Column.cjs");require("./theme.cjs");const Fe=require("./Drawer-TJY4NuHx.cjs"),Yi=require("easydrawer"),Je=require("./shortId-Bfj8TyNr.cjs"),ue=require("./Excalidraw.cjs"),Wt=require("./Iframe-5zx43DL4.cjs"),Io=require("./ImageGif.cjs"),Mo=require("katex"),Zn=require("./textarea-wvARZKyA.cjs"),Ve=require("./LinkEditBlock-DQ8-iufJ.cjs"),Nn=require("@tiptap/pm/view"),Oo=require("@tiptap/pm/model"),jo=require("./Clear.cjs"),de=require("./Indent-DuwV8s1t.cjs"),Us=require("./TextAlign.cjs"),U=require("./dropdown-menu-yQ-sQ1k4.cjs"),Qn=require("./Mermaid.cjs"),Ro=require("./Bold.cjs"),No=require("./Code.cjs");require("./index-BAb_UADw.cjs");const Bo=require("./Color.cjs"),Lo=require("./Highlight.cjs"),Po=require("./Italic.cjs"),Uo=require("./SlashCommandNodeView-DNixmQGa.cjs"),$o=require("./Strike.cjs"),Fo=require("./TextUnderline.cjs"),Bn=require("./Twitter--tfifMt1.cjs");function Vo(e,t){const n=Math.min(e.top,t.top),i=Math.max(e.bottom,t.bottom),s=Math.min(e.left,t.left),o=Math.max(e.right,t.right)-s,l=i-n,c=s,a=n;return new DOMRect(c,a,o,l)}var Ho=class{constructor({editor:e,element:t,view:n,pluginKey:i="bubbleMenu",updateDelay:s=250,resizeDelay:r=60,shouldShow:o,appendTo:l,getReferencedVirtualElement:c,options:a}){this.preventHide=!1,this.isVisible=!1,this.scrollTarget=window,this.floatingUIOptions={strategy:"absolute",placement:"top",offset:8,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1,onShow:void 0,onHide:void 0,onUpdate:void 0,onDestroy:void 0},this.shouldShow=({view:h,state:f,from:p,to:g})=>{const{doc:x,selection:w}=f,{empty:y}=w,C=!x.textBetween(p,g).length&&T.isTextSelection(f.selection),S=this.element.contains(document.activeElement);return!(!(h.hasFocus()||S)||y||C||!this.editor.isEditable)},this.mousedownHandler=()=>{this.preventHide=!0},this.dragstartHandler=()=>{this.hide()},this.resizeHandler=()=>{this.resizeDebounceTimer&&clearTimeout(this.resizeDebounceTimer),this.resizeDebounceTimer=window.setTimeout(()=>{this.updatePosition()},this.resizeDelay)},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:h})=>{var f;if(this.editor.isDestroyed){this.destroy();return}if(this.preventHide){this.preventHide=!1;return}h!=null&&h.relatedTarget&&((f=this.element.parentNode)!=null&&f.contains(h.relatedTarget))||(h==null?void 0:h.relatedTarget)!==this.editor.view.dom&&this.hide()},this.handleDebouncedUpdate=(h,f)=>{const p=!(f!=null&&f.selection.eq(h.state.selection)),g=!(f!=null&&f.doc.eq(h.state.doc));!p&&!g||(this.updateDebounceTimer&&clearTimeout(this.updateDebounceTimer),this.updateDebounceTimer=window.setTimeout(()=>{this.updateHandler(h,p,g,f)},this.updateDelay))},this.updateHandler=(h,f,p,g)=>{const{composing:x}=h;if(x||!f&&!p)return;if(!this.getShouldShow(g)){this.hide();return}this.show(),this.updatePosition()},this.transactionHandler=({transaction:h})=>{const f=h.getMeta(this.pluginKey);f==="updatePosition"?this.updatePosition():f&&typeof f=="object"&&f.type==="updateOptions"?this.updateOptions(f.options):f==="hide"?this.hide():f==="show"&&(this.updatePosition(),this.show())};var u;this.editor=e,this.element=t,this.view=n,this.pluginKey=i,this.updateDelay=s,this.resizeDelay=r,this.appendTo=l,this.scrollTarget=(u=a==null?void 0:a.scrollTarget)!=null?u:window,this.getReferencedVirtualElement=c,this.floatingUIOptions={...this.floatingUIOptions,...a},this.element.tabIndex=0,o&&(this.shouldShow=o),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.view.dom.addEventListener("dragstart",this.dragstartHandler),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.editor.on("transaction",this.transactionHandler),window.addEventListener("resize",this.resizeHandler),this.scrollTarget.addEventListener("scroll",this.resizeHandler),this.update(n,n.state),this.getShouldShow()&&(this.show(),this.updatePosition())}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(q.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(q.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(q.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(q.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(q.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(q.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(q.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(q.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}get virtualElement(){var e,t,n;const{selection:i}=this.editor.state,s=(e=this.getReferencedVirtualElement)==null?void 0:e.call(this);if(s)return s;if(!((n=(t=this.view)==null?void 0:t.dom)!=null&&n.parentNode))return;const r=T.posToDOMRect(this.view,i.from,i.to);let o={getBoundingClientRect:()=>r,getClientRects:()=>[r]};if(i instanceof Y.NodeSelection){let l=this.view.nodeDOM(i.from);const c=l.dataset.nodeViewWrapper?l:l.querySelector("[data-node-view-wrapper]");c&&(l=c),l&&(o={getBoundingClientRect:()=>l.getBoundingClientRect(),getClientRects:()=>[l.getBoundingClientRect()]})}if(i instanceof Ls.CellSelection){const{$anchorCell:l,$headCell:c}=i,a=l?l.pos:c.pos,u=c?c.pos:l.pos,h=this.view.nodeDOM(a),f=this.view.nodeDOM(u);if(!h||!f)return;const p=h===f?h.getBoundingClientRect():Vo(h.getBoundingClientRect(),f.getBoundingClientRect());o={getBoundingClientRect:()=>p,getClientRects:()=>[p]}}return o}updatePosition(){if(!this.isVisible)return;const e=this.virtualElement;e&&q.computePosition(e,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:t,y:n,strategy:i,middlewareData:s})=>{var r,o;if(!(!this.isVisible||this.editor.isDestroyed||!this.element.isConnected)){if((r=s.hide)!=null&&r.referenceHidden||(o=s.hide)!=null&&o.escaped){this.element.style.visibility="hidden";return}this.element.style.visibility="visible",this.element.style.width="max-content",this.element.style.position=i,this.element.style.left=`${t}px`,this.element.style.top=`${n}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()}})}update(e,t){const{state:n}=e,i=n.selection.from!==n.selection.to;if(this.updateDelay>0&&i){this.handleDebouncedUpdate(e,t);return}const s=!(t!=null&&t.selection.eq(e.state.selection)),r=!(t!=null&&t.doc.eq(e.state.doc));this.updateHandler(e,s,r,t)}getShouldShow(e){var t;const{state:n}=this.view,{selection:i}=n,{ranges:s}=i,r=Math.min(...s.map(c=>c.$from.pos)),o=Math.max(...s.map(c=>c.$to.pos));return((t=this.shouldShow)==null?void 0:t.call(this,{editor:this.editor,element:this.element,view:this.view,state:n,oldState:e,from:r,to:o}))||!1}show(){var e;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const t=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(e=t??this.view.dom.parentElement)==null||e.appendChild(this.element),this.floatingUIOptions.onShow&&this.floatingUIOptions.onShow(),this.isVisible=!0}hide(){this.isVisible&&(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.remove(),this.floatingUIOptions.onHide&&this.floatingUIOptions.onHide(),this.isVisible=!1)}updateOptions(e){var t;if(e.updateDelay!==void 0&&(this.updateDelay=e.updateDelay),e.resizeDelay!==void 0&&(this.resizeDelay=e.resizeDelay),e.appendTo!==void 0&&(this.appendTo=e.appendTo),e.getReferencedVirtualElement!==void 0&&(this.getReferencedVirtualElement=e.getReferencedVirtualElement),e.shouldShow!==void 0&&e.shouldShow&&(this.shouldShow=e.shouldShow),e.options!==void 0){const n=(t=e.options.scrollTarget)!=null?t:window;n!==this.scrollTarget&&(this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.scrollTarget=n,this.scrollTarget.addEventListener("scroll",this.resizeHandler)),this.floatingUIOptions={...this.floatingUIOptions,...e.options}}}destroy(){this.hide(),this.element.removeEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.view.dom.removeEventListener("dragstart",this.dragstartHandler),window.removeEventListener("resize",this.resizeHandler),this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.editor.off("transaction",this.transactionHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},$s=e=>new Y.Plugin({key:typeof e.pluginKey=="string"?new Y.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Ho({view:t,...e})});T.Extension.create({name:"bubbleMenu",addOptions(){return{element:null,pluginKey:"bubbleMenu",updateDelay:void 0,appendTo:void 0,shouldShow:null}},addProseMirrorPlugins(){return this.options.element?[$s({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,updateDelay:this.options.updateDelay,options:this.options.options,appendTo:this.options.appendTo,getReferencedVirtualElement:this.options.getReferencedVirtualElement,shouldShow:this.options.shouldShow})]:[]}});var zo=class{constructor({editor:e,element:t,view:n,pluginKey:i="floatingMenu",updateDelay:s=250,resizeDelay:r=60,options:o,appendTo:l,shouldShow:c}){this.preventHide=!1,this.isVisible=!1,this.scrollTarget=window,this.shouldShow=({view:u,state:h})=>{const{selection:f}=h,{$anchor:p,empty:g}=f,x=p.depth===1,w=p.parent.isTextblock&&!p.parent.type.spec.code&&!p.parent.textContent&&p.parent.childCount===0&&!this.getTextContent(p.parent);return!(!u.hasFocus()||!g||!x||!w||!this.editor.isEditable)},this.floatingUIOptions={strategy:"absolute",placement:"right",offset:8,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1},this.updateHandler=(u,h,f,p)=>{const{composing:g}=u;if(g||!h&&!f)return;if(!this.getShouldShow(p)){this.hide();return}this.updatePosition(),this.show()},this.mousedownHandler=()=>{this.preventHide=!0},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:u})=>{var h;if(this.preventHide){this.preventHide=!1;return}u!=null&&u.relatedTarget&&((h=this.element.parentNode)!=null&&h.contains(u.relatedTarget))||(u==null?void 0:u.relatedTarget)!==this.editor.view.dom&&this.hide()},this.transactionHandler=({transaction:u})=>{const h=u.getMeta(this.pluginKey);h==="updatePosition"?this.updatePosition():h&&typeof h=="object"&&h.type==="updateOptions"?this.updateOptions(h.options):h==="hide"?this.hide():h==="show"&&(this.updatePosition(),this.show())},this.resizeHandler=()=>{this.resizeDebounceTimer&&clearTimeout(this.resizeDebounceTimer),this.resizeDebounceTimer=window.setTimeout(()=>{this.updatePosition()},this.resizeDelay)};var a;this.editor=e,this.element=t,this.view=n,this.pluginKey=i,this.updateDelay=s,this.resizeDelay=r,this.appendTo=l,this.scrollTarget=(a=o==null?void 0:o.scrollTarget)!=null?a:window,this.floatingUIOptions={...this.floatingUIOptions,...o},this.element.tabIndex=0,c&&(this.shouldShow=c),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.editor.on("transaction",this.transactionHandler),window.addEventListener("resize",this.resizeHandler),this.scrollTarget.addEventListener("scroll",this.resizeHandler),this.update(n,n.state),this.getShouldShow()&&(this.show(),this.updatePosition())}getTextContent(e){return T.getText(e,{textSerializers:T.getTextSerializersFromSchema(this.editor.schema)})}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(q.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(q.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(q.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(q.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(q.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(q.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(q.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(q.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}getShouldShow(e){var t;const{state:n}=this.view,{selection:i}=n,{ranges:s}=i,r=Math.min(...s.map(c=>c.$from.pos)),o=Math.max(...s.map(c=>c.$to.pos));return(t=this.shouldShow)==null?void 0:t.call(this,{editor:this.editor,view:this.view,state:n,oldState:e,from:r,to:o})}updateOptions(e){var t;if(e.updateDelay!==void 0&&(this.updateDelay=e.updateDelay),e.resizeDelay!==void 0&&(this.resizeDelay=e.resizeDelay),e.appendTo!==void 0&&(this.appendTo=e.appendTo),e.shouldShow!==void 0&&e.shouldShow&&(this.shouldShow=e.shouldShow),e.options!==void 0){const n=(t=e.options.scrollTarget)!=null?t:window;n!==this.scrollTarget&&(this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.scrollTarget=n,this.scrollTarget.addEventListener("scroll",this.resizeHandler)),this.floatingUIOptions={...this.floatingUIOptions,...e.options}}}updatePosition(){var e,t;if(!((t=(e=this.view)==null?void 0:e.dom)!=null&&t.parentNode))return;const{selection:n}=this.editor.state,i=T.posToDOMRect(this.view,n.from,n.to),s={getBoundingClientRect:()=>i,getClientRects:()=>[i]};q.computePosition(s,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:r,y:o,strategy:l,middlewareData:c})=>{var a,u;if((a=c.hide)!=null&&a.referenceHidden||(u=c.hide)!=null&&u.escaped){this.element.style.visibility="hidden";return}this.element.style.visibility="visible",this.element.style.width="max-content",this.element.style.position=l,this.element.style.left=`${r}px`,this.element.style.top=`${o}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()})}update(e,t){const n=!(t!=null&&t.selection.eq(e.state.selection)),i=!(t!=null&&t.doc.eq(e.state.doc));this.updateHandler(e,n,i,t)}show(){var e;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const t=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(e=t??this.view.dom.parentElement)==null||e.appendChild(this.element),this.floatingUIOptions.onShow&&this.floatingUIOptions.onShow(),this.isVisible=!0}hide(){this.isVisible&&(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.remove(),this.floatingUIOptions.onHide&&this.floatingUIOptions.onHide(),this.isVisible=!1)}destroy(){this.hide(),this.element.removeEventListener("mousedown",this.mousedownHandler,{capture:!0}),window.removeEventListener("resize",this.resizeHandler),this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.editor.off("transaction",this.transactionHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},Fs=e=>new Y.Plugin({key:typeof e.pluginKey=="string"?new Y.PluginKey(e.pluginKey):e.pluginKey,view:t=>new zo({view:t,...e})});T.Extension.create({name:"floatingMenu",addOptions(){return{element:null,options:{},pluginKey:"floatingMenu",updateDelay:void 0,resizeDelay:void 0,appendTo:void 0,shouldShow:null}},addCommands(){return{updateFloatingMenuPosition:()=>({tr:e,dispatch:t})=>(t&&e.setMeta(this.options.pluginKey,"updatePosition"),!0)}},addProseMirrorPlugins(){return this.options.element?[Fs({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,updateDelay:this.options.updateDelay,resizeDelay:this.options.resizeDelay,options:this.options.options,appendTo:this.options.appendTo,shouldShow:this.options.shouldShow})]:[]}});function Vs(e,t){return e??new Y.PluginKey(t)}var Ko=typeof window<"u"?b.useLayoutEffect:b.useEffect,Hs=new Set(["left","opacity","position","top","visibility","width"]),qo=new Set(["animationIterationCount","aspectRatio","borderImageOutset","borderImageSlice","borderImageWidth","columnCount","columns","fillOpacity","flex","flexGrow","flexShrink","fontWeight","gridArea","gridColumn","gridColumnEnd","gridColumnStart","gridRow","gridRowEnd","gridRowStart","lineClamp","lineHeight","opacity","order","orphans","scale","stopOpacity","strokeDasharray","strokeDashoffset","strokeMiterlimit","strokeOpacity","strokeWidth","tabSize","widows","zIndex","zoom"]),Wo=new Set(["children","className","style"]),Go=new Set(["tabIndex"]),Yo=new Set(["accessKey","autoCapitalize","contentEditable","contextMenu","dir","draggable","enterKeyHint","hidden","id","lang","nonce","role","slot","spellCheck","tabIndex","title","translate"]),Jo={Blur:"focusout",DoubleClick:"dblclick",Focus:"focusin",MouseEnter:"mouseenter",MouseLeave:"mouseleave"};function ti(e,t){return/^on[A-Z]/.test(e)&&typeof t=="function"}function Xo(e){return e.startsWith("aria-")||e.startsWith("data-"),e}function Zo(e){return e.startsWith("aria-")||e.startsWith("data-")||Yo.has(e)}function zs(e){return e.startsWith("--")?e:e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}function Qo(e){var t;const n=e.endsWith("Capture"),s=(n?e.slice(0,-7):e).slice(2);return{eventName:(t=Jo[s])!=null?t:s.toLowerCase(),options:n?{capture:!0}:void 0}}function tl(e,t){let n=t.defaultPrevented,i=!1;const s=Object.create(t);return Object.defineProperties(s,{nativeEvent:{value:t},currentTarget:{value:e},target:{value:t.target},persist:{value:()=>{}},isDefaultPrevented:{value:()=>n},isPropagationStopped:{value:()=>i},preventDefault:{value:()=>{n=!0,t.preventDefault()}},stopPropagation:{value:()=>{i=!0,t.stopPropagation()}}}),s}function Ln(e){return Go.has(e)}function Ji(e,t,n){if(t==="tabIndex"){e.tabIndex=Number(n);return}e[t]=n}function el(e,t){if(t==="tabIndex"){e.removeAttribute("tabindex");return}const n=e[t];if(typeof n=="boolean"){e[t]=!1;return}if(typeof n=="number"){e[t]=0;return}e[t]=""}function nl(e,t){return typeof t!="number"||t===0||e.startsWith("--")||qo.has(e)?String(t):`${t}px`}function il(e,t){Hs.has(t)||e.style.removeProperty(zs(t))}function sl(e,t,n){Hs.has(t)||e.style.setProperty(zs(t),nl(t,n))}function rl(e,t,n){new Set([...Object.keys(t),...Object.keys(n)]).forEach(s=>{if(Wo.has(s)||!Zo(s)||ti(s,t[s])||ti(s,n[s]))return;const r=t[s],o=n[s];if(r===o)return;const l=Xo(s);if(o==null||o===!1){Ln(s)&&el(e,s),e.removeAttribute(l);return}if(o===!0){Ln(s)&&Ji(e,s,!0),e.setAttribute(l,"");return}if(Ln(s)){Ji(e,s,o);return}e.setAttribute(l,String(o))})}function ol(e,t,n){if(t!==n){if(n){e.className=n;return}e.removeAttribute("class")}}function ll(e,t,n){const i=t??{},s=n??{};new Set([...Object.keys(i),...Object.keys(s)]).forEach(o=>{const l=i[o],c=s[o];if(l!==c){if(c==null){il(e,o);return}sl(e,o,c)}})}function cl(e,t,n){t.forEach(({eventName:s,listener:r,options:o})=>{e.removeEventListener(s,r,o)});const i=[];return Object.entries(n).forEach(([s,r])=>{if(!ti(s,r))return;const{eventName:o,options:l}=Qo(s),c=a=>{r(tl(e,a))};e.addEventListener(o,c,l),i.push({eventName:o,listener:c,options:l})}),i}function Ks(e,t){const n=b.useRef({}),i=b.useRef([]);Ko(()=>{const s=n.current;return ol(e,s.className,t.className),ll(e,s.style,t.style),rl(e,s,t),i.current=cl(e,i.current,t),n.current=t,()=>{i.current.forEach(({eventName:r,listener:o,options:l})=>{e.removeEventListener(r,o,l)}),i.current=[]}},[e,t])}var nt=b.forwardRef(({pluginKey:e,editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:r=null,getReferencedVirtualElement:o,options:l,children:c,...a},u)=>{const h=b.useRef(document.createElement("div")),f=b.useRef(Vs(e,"bubbleMenu")).current;Ks(h.current,a),typeof u=="function"?u(h.current):u&&(u.current=h.current);const{editor:p}=Ps.useCurrentEditor(),g=t||p,x={updateDelay:n,resizeDelay:i,appendTo:s,pluginKey:f,shouldShow:r,getReferencedVirtualElement:o,options:l},w=b.useRef(x);w.current=x;const[y,C]=b.useState(!1),S=b.useRef(!0);return b.useEffect(()=>{if(g!=null&&g.isDestroyed)return;if(!g){console.warn("BubbleMenu component is not rendered inside of an editor component or does not have editor prop.");return}const D=h.current;D.style.visibility="hidden",D.style.position="absolute";const H=$s({...w.current,editor:g,element:D});g.registerPlugin(H);const A=w.current.pluginKey;return S.current=!0,C(!0),()=>{C(!1),g.unregisterPlugin(A),window.requestAnimationFrame(()=>{D.parentNode&&D.parentNode.removeChild(D)})}},[g]),b.useEffect(()=>{if(!(!y||!g||g.isDestroyed)){if(S.current){S.current=!1;return}g.view.dispatch(g.state.tr.setMeta(f,{type:"updateOptions",options:w.current}))}},[y,g,n,i,r,l,s,o,f]),wi.createPortal(c,h.current)});b.forwardRef(({pluginKey:e,editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:r=null,options:o,children:l,...c},a)=>{const u=b.useRef(document.createElement("div")),h=b.useRef(Vs(e,"floatingMenu")).current;Ks(u.current,c),typeof a=="function"?a(u.current):a&&(a.current=u.current);const{editor:f}=Ps.useCurrentEditor(),p=t||f,g={updateDelay:n,resizeDelay:i,appendTo:s,pluginKey:h,shouldShow:r,options:o},x=b.useRef(g);x.current=g;const[w,y]=b.useState(!1),C=b.useRef(!0);return b.useEffect(()=>{if(p!=null&&p.isDestroyed)return;if(!p){console.warn("FloatingMenu component is not rendered inside of an editor component or does not have editor prop.");return}const S=u.current;S.style.visibility="hidden",S.style.position="absolute";const D=Fs({...x.current,editor:p,element:S});p.registerPlugin(D);const H=x.current.pluginKey;return C.current=!0,y(!0),()=>{y(!1),p.unregisterPlugin(H),window.requestAnimationFrame(()=>{S.parentNode&&S.parentNode.removeChild(S)})}},[p]),b.useEffect(()=>{if(!(!w||!p||p.isDestroyed)){if(C.current){C.current=!1;return}p.view.dispatch(p.state.tr.setMeta(h,{type:"updateOptions",options:x.current}))}},[w,p,n,i,r,o,s,h]),wi.createPortal(l,u.current)});function Ht(e,t){const{state:n}=t,i=n.selection.$anchor;let s=!1;if(i.depth)for(let r=i.depth;r>0;r--)i.node(r).type.name===e&&(t.dispatchTransaction&&t.dispatchTransaction(n.tr.delete(i.before(r),i.after(r)).scrollIntoView()),s=!0);else{const r=n.selection.node;r&&r.type.name===e&&(t.chain().deleteSelection().run(),s=!0)}if(!s){const r=i.pos;if(r){const o=n.tr.doc.nodeAt(r);o&&o.type.name===e&&(t.dispatchTransaction&&t.dispatchTransaction(n.tr.delete(r,r+o.nodeSize)),s=!0)}}return s}const al=[{value:"note",label:"Note",icon:"Info"},{value:"tip",label:"Tip",icon:"Lightbulb"},{value:"important",label:"Important",icon:"AlertCircle"},{value:"warning",label:"Warning",icon:"TriangleAlert"},{value:"caution",label:"Caution",icon:"OctagonAlert"}];function hl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=B.useLocale(),{type:i,title:s,body:r}=dt.useAttributes(t,St.Callout.name,{type:"note",title:"",body:""}),[o,l]=b.useState(!1),[c,a]=b.useState("note"),[u,h]=b.useState(""),[f,p]=b.useState("");b.useEffect(()=>{o&&(a(i||"note"),h(s||""),p(r||""))},[o,i,s,r]);const g=b.useCallback(()=>{t&&(t.chain().updateAttributes(St.Callout.name,{type:c,title:u,body:f}).focus().run(),l(!1))},[t,c,u,f]),x=b.useCallback(()=>{l(!1)},[]),w=b.useCallback(()=>{Ht(St.Callout.name,t)},[t]),y=b.useCallback(()=>t.isActive(St.Callout.name),[t]);return e?d.jsx(nt,{editor:t,options:{placement:"top",offset:8,flip:!0},pluginKey:"RichTextBubbleCallout",shouldShow:y,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsxs(m.Dialog,{onOpenChange:l,open:o,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{icon:"Pencil",tooltip:n("editor.callout.edit.title")})}),d.jsxs(m.DialogContent,{children:[d.jsx(m.DialogTitle,{children:n("editor.callout.edit.title")}),d.jsxs("div",{className:"richtext-space-y-4 richtext-py-4",children:[d.jsxs("div",{className:"richtext-space-y-2",children:[d.jsx(m.Label,{children:n("editor.callout.dialog.type")}),d.jsxs(St.Select,{onValueChange:a,value:c,children:[d.jsx(St.SelectTrigger,{children:d.jsx(St.SelectValue,{className:"richtext-text-accent",placeholder:n("editor.callout.dialog.type.placeholder")})}),d.jsx(St.SelectContent,{children:al.map(C=>d.jsx(St.SelectItem,{value:C.value,children:n(`editor.callout.type.${C.value}`)},C.value))})]})]}),d.jsxs("div",{className:"richtext-space-y-2",children:[d.jsx(m.Label,{children:n("editor.callout.dialog.title.label")}),d.jsx(m.Input,{onChange:C=>h(C.target.value),placeholder:n("editor.callout.dialog.title.placeholder"),type:"text",value:u})]}),d.jsxs("div",{className:"richtext-space-y-2",children:[d.jsx(m.Label,{children:n("editor.callout.dialog.body.label")}),d.jsx(m.Input,{onChange:C=>p(C.target.value),placeholder:n("editor.callout.dialog.body.placeholder"),type:"text",value:f})]})]}),d.jsxs(m.DialogFooter,{children:[d.jsx(m.Button,{onClick:x,variant:"outline",children:n("editor.callout.dialog.button.cancel")}),d.jsx(m.Button,{onClick:g,children:n("editor.callout.dialog.button.apply")})]})]})]}),d.jsx(m.ActionButton,{action:w,icon:"Trash2",tooltip:n("editor.delete")})]})}):d.jsx(d.Fragment,{})}function ul(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=B.useLocale(),i=b.useCallback(()=>t.isActive(Gi.MultipleColumnNode.name),[t]),s=b.useCallback(()=>Ht(Gi.MultipleColumnNode.name,t),[t]),r=b.useCallback(()=>t.chain().focus().addColBefore().run(),[t]),o=b.useCallback(()=>t.chain().focus().addColAfter().run(),[t]),l=b.useCallback(()=>t.chain().focus().deleteCol().run(),[t]);return e?d.jsx(nt,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleColumns",shouldShow:i,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{action:r,icon:"ColumnAddLeft",tooltip:n("editor.table.menu.insertColumnBefore")}),d.jsx(m.ActionButton,{action:o,icon:"ColumnAddRight",tooltip:n("editor.table.menu.insertColumnAfter")}),d.jsx(m.ActionButton,{action:l,icon:"DeleteColumn",tooltip:n("editor.table.menu.deleteColumn")}),d.jsx(m.ActionButton,{action:s,icon:"Trash2",tooltip:n("editor.table.menu.delete_column")})]})}):d.jsx(d.Fragment,{})}function dl(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,r)=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[r],action:()=>e.commands.updateImage({width:B.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:B.IMAGE_SIZE[s]})}}))}function fl(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,r)=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[r],action:()=>e.commands.updateImageGif({width:B.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:B.IMAGE_SIZE[s]})}}))}function pl(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImage)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function gl(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImageGif)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function ml(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImageMermaid)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function xl(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImageDrawer)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function bl(e){return[{type:"flex-start",icon:"AlignLeft",tooltip:"Align left"},{type:"center",icon:"AlignCenter",tooltip:"Align center"},{type:"flex-end",icon:"AlignRight",tooltip:"Align right"}].map(n=>({type:`video-align-${n.type}`,component:m.ActionButton,componentProps:{tooltip:n.tooltip,icon:n.icon,action:()=>e.commands.updateVideo({align:n.type}),isActive:()=>e.getAttributes("video").align===n.type}}))}function wl(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,r)=>({type:`video-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[r],action:()=>e.commands.updateVideo({width:B.VIDEO_SIZE[s]}),isActive:()=>e.isActive("video",{width:B.VIDEO_SIZE[s]})}}))}function yl(e,t){return[{type:"flipX",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.tooltip.flipX"),icon:"FlipX",action:()=>{const n=e.getAttributes("image"),{flipX:i}=n;e.chain().focus(void 0,{scrollIntoView:!1}).updateImage({flipX:!i}).run()}}},{type:"flipY",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.tooltip.flipY"),icon:"FlipY",action:()=>{const n=e.getAttributes("image"),{flipY:i}=n;e.chain().focus(void 0,{scrollIntoView:!1}).updateImage({flipY:!i}).run()}}},...dl(e,t),...pl(e,t),{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;T.deleteSelection(n,i)}}}]}function vl(e,t){return[...fl(e,t),...gl(e,t),{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;T.deleteSelection(n,i)}}}]}function Sl(e,t){return[...ml(e,t),{type:"edit",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;T.deleteSelection(n,i)}}}]}function Cl(e,t){return[...xl(e,t),{type:"edit",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;T.deleteSelection(n,i)}}}]}function kl(e,t){return[...wl(e,t),...bl(e),{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;T.deleteSelection(n,i)}}}]}let fe=!1;function El({editor:e,attrs:t,extension:n}){const[i,s]=b.useState(!1),r=b.useRef(null),o=b.useRef(null),{alt:l,align:c}=t,a=n==null?void 0:n.options.upload,u=()=>{(async()=>{const v=document.querySelector("#easydrawer");v&&(r.current=new Yi.Editor(v,{wheelEventsEnabled:!1,disableZoom:!0}),o.current=Yi.makeDropdownToolbar(r.current),o.current.addDefaultToolWidgets(),r.current.loadFromSVG(decodeURIComponent(l)))})()};b.useEffect(()=>{i&&setTimeout(()=>{u()},200)},[i]);const h=async()=>{if(r.current){const A=r.current.toSVG(),v=A.outerHTML,k=`drawer-${Je.shortId()}.svg`;let L=Je.i(A.outerHTML);if(a){const z=m.dataURLtoFile(L,k);L=await a(z)}e==null||e.chain().focus().setDrawer({type:"drawer",src:L,alt:encodeURIComponent(v),width:426,height:212},!!v).run(),e==null||e.commands.setAlignImageDrawer(c)}s(!1)},f=A=>{const v=r.current.toolController.getPrimaryTools()[2],k=o.current.getWidgetById("pen-1");v&&k&&(v.setColor(A),k.serializeState())},p=A=>{const v=r.current.toolController.getPrimaryTools()[2],k=o.current.getWidgetById("pen-1");v&&k&&(v.setThickness(A),k.serializeState())},g=A=>{const v=r.current.toolController.getPrimaryTools()[3],k=o.current.getWidgetById("pen-2");v&&k&&(v.setColor(A),k.serializeState())},x=A=>{const v=o.current.getWidgetById("shape");v&&v.setShapeType(A)},w=A=>{const v=r.current.toolController.getPrimaryTools()[5],k=o.current.getWidgetById("shape");v&&k&&(v.setColor(A),k.serializeState())},y=A=>{const v=r.current.toolController.getPrimaryTools()[5],k=o.current.getWidgetById("shape");v&&k&&(v.setThickness(A),k.serializeState())},C=A=>{const v=r.current.toolController.getPrimaryTools()[5],k=o.current.getWidgetById("shape");v&&k&&(v.setBorderColor(A),k.serializeState())},S=()=>{if(fe){for(;r.current.history.redoStackSize>0;)r.current.history.redo();fe=!1;return}r.current.history.undo()},D=()=>{fe||r.current.history.redo()},H=()=>{if(!fe){for(;r.current.history.undoStackSize>0;)S();fe=!0}};return d.jsxs(m.Dialog,{onOpenChange:s,open:i,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{action:()=>s(!0),icon:"Pencil",tooltip:"Edit Drawer"})}),d.jsxs(m.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[d.jsx(m.DialogTitle,{children:"Edit Drawer"}),d.jsxs("div",{style:{height:"100%",borderWidth:1,background:"white",position:"relative"},children:[d.jsx("div",{className:"richtext-size-full",id:"easydrawer"}),d.jsx(Fe.ControlDrawer,{changeBorderColorShape:C,changeColorShape:w,changeShape:x,onClear:H,onRedo:D,onThicknessChange:y,onUndo:S,refEditor:r,setColorHighlight:g,setColorPen:f,setThicknessPen:p})]}),d.jsx(m.DialogFooter,{children:d.jsx(m.Button,{onClick:h,type:"button",children:"Save changes"})})]})]})}function _l({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?d.jsx(b.Fragment,{children:e.type==="divider"?d.jsx(wt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):d.jsx(i,{...e.componentProps,disabled:t||((s=e==null?void 0:e.componentProps)==null?void 0:s.disabled),editor:n})}):d.jsx(d.Fragment,{})}function Tl(){const{lang:e,t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=dt.useAttributes(i,Fe.Drawer.name),r=m.useExtension(Fe.Drawer.name),o=({editor:c})=>{const{selection:a}=c.view.state,{$from:u,to:h}=a;let f=!1;return c.view.state.doc.nodesBetween(u.pos,h,p=>{if(p.type.name===Fe.Drawer.name)return f=!0,!1}),f},l=b.useMemo(()=>Cl(i,t),[i,e,t]);return n?d.jsx(nt,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleDrawer",shouldShow:o,children:l!=null&&l.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:l==null?void 0:l.map((c,a)=>c.type==="edit"&&(s!=null&&s.src)?d.jsx(El,{attrs:s,editor:i,extension:r},`bubbleMenu-drawer-${a}`):d.jsx(_l,{editor:i,item:c},`bubbleMenu-drawer-${a}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}const qs=({width:e,maxWidth:t,height:n,onOk:i,children:s})=>{const{t:r}=B.useLocale(),[o,l]=b.useState({width:"",height:"",maxWidth:""});b.useEffect(()=>{l({width:e,height:n,maxWidth:t})},[n,t,e]);function c(a){a.preventDefault(),a.stopPropagation(),i(o)}return d.jsxs(kt.Popover,{modal:!0,children:[d.jsx(kt.PopoverTrigger,{asChild:!0,children:s}),d.jsx(kt.PopoverContent,{children:d.jsxs("form",{className:"richtext-flex richtext-flex-col richtext-gap-2",onSubmit:c,children:[d.jsx(m.Label,{className:"mb-[6px]",children:"Width"}),d.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:d.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:d.jsx(m.Input,{onChange:a=>l({...o,width:a.target.value}),required:!0,type:"number",value:o.width})})}),d.jsx(m.Label,{className:"mb-[6px]",children:"Max Width"}),d.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:d.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:d.jsx(m.Input,{onChange:a=>l({...o,maxWidth:a.target.value}),required:!0,type:"number",value:o.maxWidth})})}),d.jsx(m.Label,{className:"mb-[6px]",children:"Height"}),d.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:d.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:d.jsx(m.Input,{onChange:a=>l({...o,height:a.target.value}),required:!0,type:"number",value:o.height})})}),d.jsx(m.Button,{className:"richtext-mt-2 richtext-self-end",type:"submit",children:r("editor.link.dialog.button.apply")})]})})]})},Nt=new Map;function Dl(e){const t=e.options.element;Nt.has("width")||Nt.set("width",t.clientWidth),Nt.has("width")&&Nt.get("width")<=0&&Nt.set("width",t.clientWidth);const n={attributes:!0,childList:!0,subtree:!0},i=function(){Nt.set("width",t.clientWidth)},s=new MutationObserver(i);return s.observe(t,n),e.on("destroy",()=>{s.disconnect()}),{width:Nt.get("width")}}function Al(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=B.useLocale(),{width:i}=Dl(t),s=dt.useAttributes(t,ue.Excalidraw.name,{defaultShowPicker:!1,createUser:"",width:0,height:0}),{defaultShowPicker:r,createUser:o,width:l,height:c}=s,a=b.useCallback(p=>{t.chain().updateAttributes(ue.Excalidraw.name,p).setNodeSelection(t.state.selection.from).focus().run()},[t]),u=b.useCallback(()=>{const p=m.EVENTS.EXCALIDRAW(t.id);m.emit(p,s)},[t,s]),h=b.useCallback(()=>t.isActive(ue.Excalidraw.name),[t]),f=b.useCallback(()=>Ht(ue.Excalidraw.name,t),[t]);return b.useEffect(()=>{r&&(u(),t.chain().updateAttributes(ue.Excalidraw.name,{defaultShowPicker:!1}).focus().run())},[o,r,t,u]),e?d.jsx(nt,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleExcalidraw",shouldShow:h,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{action:u,icon:"Pencil",tooltip:n("editor.edit")}),d.jsx(qs,{height:c,maxWidth:i,onOk:a,width:l,children:d.jsx(m.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),d.jsx(m.ActionButton,{action:f,icon:"Trash2",tooltip:n("editor.delete")})]})}):d.jsx(d.Fragment,{})}function Il(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=B.useLocale(),{width:i,height:s,src:r}=dt.useAttributes(t,Wt.Iframe.name,{width:0,height:0,src:"",defaultShowPicker:!1}),[o,l]=b.useState(!1),[c,a]=b.useState(""),u=b.useCallback(w=>{var y;(y=w==null?void 0:w.preventDefault)==null||y.call(w),l(!1)},[l]);b.useEffect(()=>{o&&a(r)},[o,r]);const h=b.useCallback(w=>{var C;(C=w==null?void 0:w.preventDefault)==null||C.call(w);const y=Wt.getServiceSrc(c);t.chain().updateAttributes(Wt.Iframe.name,{src:(y==null?void 0:y.src)||c}).setNodeSelection(t.state.selection.from).focus().run(),l(!1)},[t,c,l]),f=b.useCallback(()=>{window.open(r,"_blank")},[r]),p=b.useCallback(w=>{t.chain().updateAttributes(Wt.Iframe.name,w).setNodeSelection(t.state.selection.from).focus().run()},[t]),g=b.useCallback(()=>t.isActive(Wt.Iframe.name)&&!r,[t,r]),x=b.useCallback(()=>Ht(Wt.Iframe.name,t),[t]);return e?d.jsx(d.Fragment,{children:d.jsx(nt,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleIframe",shouldShow:g,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{action:f,icon:"Eye",tooltip:"Visit Link"}),d.jsxs(m.Dialog,{onOpenChange:l,open:o,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{icon:"Pencil",tooltip:"Open Edit Link"})}),d.jsxs(m.DialogContent,{children:[d.jsx(m.DialogHeader,{children:d.jsx(m.DialogTitle,{children:"Edit Link Iframe"})}),d.jsx(m.Input,{autoFocus:!0,onInput:w=>a(w.target.value),placeholder:"Enter link",type:"url",value:c}),d.jsxs(m.DialogFooter,{children:[d.jsx(m.Button,{onClick:u,type:"button",children:"Cancel"}),d.jsx(m.Button,{onClick:h,type:"button",children:"OK"})]})]})]}),d.jsx(qs,{height:s,onOk:p,width:i,children:d.jsx(m.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),d.jsx(m.ActionButton,{action:x,icon:"Trash2",tooltip:n("editor.delete")})]})})}):d.jsx(d.Fragment,{})}function Ml({children:e,visible:t,toggleVisible:n}){const{t:i}=B.useLocale(),s=m.useEditorInstance(),r=dt.useAttributes(s,dt.Katex.name,{text:"",macros:""}),{text:o,macros:l}=r,[c,a]=b.useState(decodeURIComponent(o||"")),[u,h]=b.useState(decodeURIComponent(l||""));b.useEffect(()=>{t&&(a(decodeURIComponent(o||"")),h(decodeURIComponent(l||"")))},[t]);const f=b.useCallback(()=>{s.chain().focus().setKatex({text:encodeURIComponent(c),macros:encodeURIComponent(u)}).run(),a(""),h(""),n(!1)},[s,c,u,n]),p=b.useMemo(()=>{try{return Mo.renderToString(c,{macros:dt.safeJSONParse(u||"")})}catch{return c}},[c,u]),g=b.useMemo(()=>`${c}`.trim()?p:null,[c,p]);return d.jsxs(m.Dialog,{onOpenChange:n,open:t,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:e}),d.jsxs(m.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[d.jsx(m.DialogTitle,{children:i("editor.formula.dialog.text")}),d.jsx("div",{style:{height:"100%",border:"1px solid hsl(var(--border))"},children:d.jsxs("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[d.jsxs("div",{className:"richtext-flex-1",children:[d.jsx(m.Label,{className:"mb-[6px]",children:"Expression"}),d.jsx(Zn.Textarea,{autoFocus:!0,className:"richtext-mb-[10px]",onChange:x=>a(x.target.value),placeholder:"Text",required:!0,rows:10,value:c,style:{color:"hsl(var(--foreground))"}}),d.jsx(m.Label,{className:"mb-[6px]",children:"Macros"}),d.jsx(Zn.Textarea,{onChange:x=>h(x.target.value),placeholder:"Macros",rows:10,value:u,style:{color:"hsl(var(--foreground))"}})]}),d.jsx("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:g||""},style:{height:"100%",borderWidth:1,minHeight:500,background:"#fff"}})]})}),d.jsx(m.DialogFooter,{children:d.jsx(m.Button,{onClick:f,type:"button",children:"Save changes"})})]})]})}function Ol(){const e=m.useEditableEditor(),t=m.useEditorInstance(),[n,i]=b.useState(!1),s=b.useCallback(()=>t.isActive(dt.Katex.name),[t]),r=b.useCallback(()=>Ht(dt.Katex.name,t),[t]);return e?d.jsx(nt,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleKatex",shouldShow:s,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(Ml,{toggleVisible:i,visible:n,children:d.jsx(m.ActionButton,{action:()=>i(!n),tooltip:"Edit",children:d.jsx(Pt.Pencil,{size:16})})}),d.jsx(m.ActionButton,{action:r,tooltip:"Delete",children:d.jsx(Pt.Trash2,{size:16})})]})}):d.jsx(d.Fragment,{})}function jl(e){const{t}=B.useLocale();return d.jsxs("div",{className:"richtext-flex richtext-flex-nowrap",children:[d.jsx(m.ActionButton,{disabled:!(e!=null&&e.link),icon:"ExternalLink",tooltip:t("editor.link.open.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{window.open(e==null?void 0:e.link,"_blank")}}),d.jsx(m.ActionButton,{icon:"Pencil",tooltip:t("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onEdit()}}),d.jsx(m.ActionButton,{icon:"Unlink",tooltip:t("editor.link.unlink.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onClear()}})]})}function Rl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),[n,i]=b.useState(!1),s=dt.useAttributes(t,Ve.Link.name),r=s==null?void 0:s.href,o=b.useCallback(({editor:u})=>u.isActive(Ve.Link.name),[]),l=(u,h,f)=>{const p=t.state.selection,{from:g}=p,x=(h==null?void 0:h.length)??0,w=g+x;t.chain().extendMarkRange("link").insertContent({type:"text",text:h,marks:[{type:"link",attrs:{href:u,target:f?"_blank":""}}]}).setLink({href:u}).setTextSelection({from:g,to:w}).focus().run(),i(!1)},c=b.useCallback(()=>{t.chain().extendMarkRange("link").unsetLink().focus().run(),i(!1)},[t]),a=()=>{i(!1)};return e?d.jsx(nt,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleLink",shouldShow:o,children:d.jsx(d.Fragment,{children:n?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-4 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(Ve.LinkEditBlock,{editor:t,onClose:a,onSetLink:l})}):d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(jl,{editor:t,link:r,onClear:c,onEdit:()=>{i(!0)}})})})}):d.jsx(d.Fragment,{})}function yi({item:e,disabled:t,editor:n}){const i=e.component;return i?d.jsx(b.Fragment,{children:e.type==="divider"?d.jsx(wt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):d.jsx(i,{...e.componentProps,disabled:t||(e==null?void 0:e.componentdisabled),editor:n})}):d.jsx(d.Fragment,{})}function Nl(e){return e.type.name===m.Image.name}function Bl(e){return e.type.name===Io.ImageGif.name}function Ll(e){return e.type.name===m.Video.name}function Pl(){const{lang:e,t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:o})=>{const{selection:l}=o.view.state,{$from:c,to:a}=l;let u=!1;return o.view.state.doc.nodesBetween(c.pos,a,h=>{if(Nl(h))return u=!0,!1}),u},r=b.useMemo(()=>yl(i,t),[i,e,t]);return n?d.jsx(nt,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImage",shouldShow:s,children:r!=null&&r.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:r==null?void 0:r.map((o,l)=>d.jsx(yi,{editor:i,item:o},`bubbleMenu-image-${l}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function Ul(){const{lang:e,t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:o})=>{const{selection:l}=o.view.state,{$from:c,to:a}=l;let u=!1;return o.view.state.doc.nodesBetween(c.pos,a,h=>{if(Bl(h))return u=!0,!1}),u},r=b.useMemo(()=>vl(i,t),[i,t,e]);return n?d.jsx(nt,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImageGif",shouldShow:s,children:r!=null&&r.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:r==null?void 0:r.map((o,l)=>d.jsx(yi,{editor:i,item:o},`bubbleMenu-image-gif-${l}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function $l(){const{t:e}=B.useLocale(),t=m.useEditableEditor(),n=m.useEditorInstance(),i=({editor:r})=>{const{selection:o}=r.view.state,{$from:l,to:c}=o;let a=!1;return r.view.state.doc.nodesBetween(l.pos,c,u=>{if(Ll(u))return a=!0,!1}),a},s=b.useMemo(()=>kl(n,e),[n,e]);return t?d.jsx(nt,{editor:n,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleVideo",shouldShow:i,children:s!=null&&s.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:s==null?void 0:s.map((r,o)=>d.jsx(yi,{editor:n,item:r},`bubbleMenu-video-${o}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}const Xi=`graph TB
2
- a-->b`,Fl=({editor:e,attrs:t,extension:n})=>{const{alt:i,align:s}=t,[r,o]=b.useState(decodeURIComponent(i??Xi)),[l,c]=b.useState(""),[a,u]=b.useState(!1),h=b.useRef(null),[f,p]=b.useState(null),g=n==null?void 0:n.options.upload,x=b.useCallback(S=>{S&&import("mermaid").then(D=>{p(D.default)})},[]),w=async S=>{try{const{svg:D}=await f.render("mermaid-svg",S);c(D)}catch{c("")}},y=()=>{f.initialize({darkMode:!1,startOnLoad:!1,fontSize:12,theme:"base"}),w(r)};b.useEffect(()=>{f&&a&&y()},[f,a]),b.useEffect(()=>{f&&a&&w(r)},[f,r]);const C=async()=>{if(r!==""){if(r){const S=h.current.querySelector("svg"),{width:D,height:H}=S.getBoundingClientRect(),A=`mermaid-${Je.shortId()}.svg`;let v=Je.i(S.outerHTML);if(g){const k=m.dataURLtoFile(v,A);v=await g(k)}e==null||e.chain().focus().setMermaid({type:"mermaid",src:v,alt:encodeURIComponent(r),width:D,height:H},!!r).run(),e==null||e.commands.setAlignImageMermaid(s)}u(!1)}};return d.jsxs(m.Dialog,{onOpenChange:u,open:a,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{action:()=>u(!0),icon:"Pencil",tooltip:"Edit Mermaid"})}),d.jsxs(m.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[d.jsx(m.DialogTitle,{children:"Edit Mermaid"}),d.jsx("div",{ref:x,style:{height:"100%",border:"1px solid hsl(var(--border))"},children:d.jsxs("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[d.jsx(Zn.Textarea,{autoFocus:!0,className:"richtext-flex-1",defaultValue:Xi,onChange:S=>o(S.target.value),placeholder:"Text",required:!0,rows:10,value:r,style:{color:"hsl(var(--foreground))"}}),d.jsx("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:l},ref:h,style:{height:"100%",border:"1px solid hsl(var(--border))",minHeight:500}})]})}),d.jsx(m.DialogFooter,{children:d.jsx(m.Button,{onClick:C,type:"button",children:"Save changes"})})]})]})};function Vl({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?d.jsx(b.Fragment,{children:e.type==="divider"?d.jsx(wt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):d.jsx(i,{...e.componentProps,disabled:t||((s=e==null?void 0:e.componentProps)==null?void 0:s.disabled),editor:n})}):d.jsx(d.Fragment,{})}function Hl(e){return e.type.name===Qn.Mermaid.name}function zl(){const{lang:e,t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=dt.useAttributes(i,Qn.Mermaid.name),r=m.useExtension(Qn.Mermaid.name),o=({editor:c})=>{const{selection:a}=c.view.state,{$from:u,to:h}=a;let f=!1;return c.view.state.doc.nodesBetween(u.pos,h,p=>{if(Hl(p))return f=!0,!1}),f},l=b.useMemo(()=>Sl(i,t),[i,e,t]);return n?d.jsx(nt,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleMermaid",shouldShow:o,children:l!=null&&l.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:l==null?void 0:l.map((c,a)=>c.type==="edit"&&(s!=null&&s.src)?d.jsx(Fl,{attrs:s,editor:i,extension:r},`bubbleMenu-mermaid-${a}`):d.jsx(Vl,{editor:i,item:c},`bubbleMenu-mermaid-${a}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function Kl({hiddenActions:e=[]}){var x,w,y,C,S,D,H,A,v,k,L,z,M,P,K,E,ot,Re;const{t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:qt})=>T.isActive(qt.view.state,Ls.Table.name),r=qt=>e.includes(qt);function o(){i.chain().focus().addColumnBefore().run()}function l(){i.chain().focus().addColumnAfter().run()}function c(){i.chain().focus().deleteColumn().run()}function a(){i.chain().focus().addRowBefore().run()}function u(){i.chain().focus().addRowAfter().run()}function h(){i.chain().focus().deleteRow().run()}function f(){i.chain().focus().mergeCells().run()}function p(){i==null||i.chain().focus().splitCell().run()}function g(){i.chain().focus().deleteTable().run()}return n?d.jsx(nt,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTable",shouldShow:s,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[!r("addColumnBefore")&&d.jsx(m.ActionButton,{action:o,disabled:!((w=(x=i==null?void 0:i.can())==null?void 0:x.addColumnBefore)!=null&&w.call(x)),icon:"BetweenHorizonalEnd",tooltip:t("editor.table.menu.insertColumnBefore"),tooltipOptions:{sideOffset:15}}),!r("addColumnAfter")&&d.jsx(m.ActionButton,{action:l,disabled:!((C=(y=i==null?void 0:i.can())==null?void 0:y.addColumnAfter)!=null&&C.call(y)),icon:"BetweenHorizonalStart",tooltip:t("editor.table.menu.insertColumnAfter"),tooltipOptions:{sideOffset:15}}),!r("deleteColumn")&&d.jsx(m.ActionButton,{action:c,disabled:!((D=i==null?void 0:(S=i.can()).deleteColumn)!=null&&D.call(S)),icon:"DeleteColumn",tooltip:t("editor.table.menu.deleteColumn"),tooltipOptions:{sideOffset:15}}),d.jsx(wt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!r("addRowAbove")&&d.jsx(m.ActionButton,{action:a,disabled:!((A=i==null?void 0:(H=i.can()).addRowBefore)!=null&&A.call(H)),icon:"BetweenVerticalEnd",tooltip:t("editor.table.menu.insertRowAbove"),tooltipOptions:{sideOffset:15}}),!r("addRowBelow")&&d.jsx(m.ActionButton,{action:u,disabled:!((k=(v=i==null?void 0:i.can())==null?void 0:v.addRowAfter)!=null&&k.call(v)),icon:"BetweenVerticalStart",tooltip:t("editor.table.menu.insertRowBelow"),tooltipOptions:{sideOffset:15}}),!r("deleteRow")&&d.jsx(m.ActionButton,{action:h,disabled:!((z=(L=i==null?void 0:i.can())==null?void 0:L.deleteRow)!=null&&z.call(L)),icon:"DeleteRow",tooltip:t("editor.table.menu.deleteRow"),tooltipOptions:{sideOffset:15}}),d.jsx(wt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!r("mergeCells")&&d.jsx(m.ActionButton,{action:f,disabled:!((P=(M=i==null?void 0:i.can())==null?void 0:M.mergeCells)!=null&&P.call(M)),icon:"TableCellsMerge",tooltip:t("editor.table.menu.mergeCells"),tooltipOptions:{sideOffset:15}}),!r("splitCells")&&d.jsx(m.ActionButton,{action:p,disabled:!((E=(K=i==null?void 0:i.can())==null?void 0:K.splitCell)!=null&&E.call(K)),icon:"TableCellsSplit",tooltip:t("editor.table.menu.splitCells"),tooltipOptions:{sideOffset:15}}),d.jsx(wt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!r("deleteTable")&&d.jsx(m.ActionButton,{action:g,disabled:!((Re=(ot=i==null?void 0:i.can())==null?void 0:ot.deleteTable)!=null&&Re.call(ot)),icon:"Trash2",tooltip:t("editor.table.menu.deleteTable"),tooltipOptions:{sideOffset:15}})]})}):d.jsx(d.Fragment,{})}function ql(){const{t:e}=B.useLocale(),[t,n]=b.useState(!1),i=m.useEditorInstance(),s=b.useMemo(()=>{var o,l;return(l=(o=Uo.renderCommandListDefault({t:e}))==null?void 0:o[0])==null?void 0:l.commands},[e]),r=b.useMemo(()=>{var l;return(l=s==null?void 0:s.find(c=>{var a;return(a=c==null?void 0:c.isActive)==null?void 0:a.call(c,i)}))==null?void 0:l.label},[i.state.selection.ranges,t,i,s,e]);return d.jsxs(kt.Popover,{modal:!0,onOpenChange:n,open:t,children:[d.jsx(kt.PopoverTrigger,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:d.jsxs(m.ActionButton,{dataState:!!r,children:[r?d.jsx(d.Fragment,{children:r}):d.jsx(d.Fragment,{children:e("editor.paragraph.tooltip")}),d.jsx(m.IconComponent,{className:"richtext-ml-1 richtext-size-3 richtext-text-zinc-500",name:"MenuDown"})]})}),d.jsx(kt.PopoverContent,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:s==null?void 0:s.map(o=>{var c;const l=(c=o==null?void 0:o.isActive)==null?void 0:c.call(o,i);return d.jsxs("div",{className:"richtext-flex richtext-w-full richtext-items-center richtext-gap-3 richtext-rounded-sm !richtext-border-none !richtext-bg-transparent richtext-px-2 richtext-py-1.5 richtext-text-left richtext-text-sm richtext-text-foreground !richtext-outline-none richtext-transition-colors hover:!richtext-bg-accent",onClick:a=>{a.preventDefault(),o.action({editor:i,range:i.state.selection.ranges}),n(!1)},children:[d.jsxs("div",{className:"!richtext-min-w-[20px]",children:[l&&d.jsx(Pt.Check,{size:16}),!r&&o.label===e("editor.paragraph.tooltip")&&!l&&d.jsx(Pt.Check,{size:16})]}),d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:[o.iconName&&d.jsx(m.IconComponent,{className:"!richtext-mr-1 !richtext-text-lg",name:o.iconName}),o.label]})]},o.name)})})]})}function Wl(){return d.jsxs(d.Fragment,{children:[d.jsx(ql,{}),d.jsx(wt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(Ro.RichTextBold,{}),d.jsx(Po.RichTextItalic,{}),d.jsx(Fo.RichTextUnderline,{}),d.jsx($o.RichTextStrike,{}),d.jsx(No.RichTextCode,{}),d.jsx(Ve.RichTextLink,{}),d.jsx(wt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(Bo.RichTextColor,{}),d.jsx(Lo.RichTextHighlight,{}),d.jsx(Us.RichTextAlign,{})]})}function Gl({buttonBubble:e}){const t=m.useEditorInstance(),n=m.useEditableEditor(),i=({editor:s})=>{const{selection:r}=s.view.state,{$from:o,to:l}=r;return s.isActive("codeBlock")||o.pos===l?!1:r instanceof Y.TextSelection};return n?d.jsx(nt,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleText",shouldShow:i,children:e?d.jsx(d.Fragment,{children:e}):d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(Wl,{})})}):d.jsx(d.Fragment,{})}function Yl(){const{t:e}=B.useLocale(),t=m.useEditableEditor(),n=m.useEditorInstance(),[i,s]=b.useState(!1),r=b.useCallback(({editor:c})=>c.isActive(Bn.Twitter.name),[]),o=c=>{n.commands.updateTweet({src:c}),s(!1)},l=b.useCallback(()=>Ht(Bn.Twitter.name,n),[n]);return t?d.jsx(nt,{editor:n,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTwitter",shouldShow:r,children:d.jsx(d.Fragment,{children:i?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-4 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(Bn.FormEditLinkTwitter,{editor:n,onSetLink:o})}):d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{icon:"Pencil",tooltip:e("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{s(!0)}}),d.jsx(m.ActionButton,{action:l,icon:"Trash",tooltip:e("editor.delete"),tooltipOptions:{sideOffset:15}})]})})}):d.jsx(d.Fragment,{})}const ft=()=>new Map,ei=e=>{const t=ft();return e.forEach((n,i)=>{t.set(i,n)}),t},Tt=(e,t,n)=>{let i=e.get(t);return i===void 0&&e.set(t,i=n()),i},Jl=(e,t)=>{const n=[];for(const[i,s]of e)n.push(t(s,i));return n},Xl=(e,t)=>{for(const[n,i]of e)if(t(i,n))return!0;return!1},Ut=()=>new Set,Pn=e=>e[e.length-1],Zl=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},$t=Array.from,vi=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},Si=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},Ql=(e,t)=>{const n=new Array(e);for(let i=0;i<e;i++)n[i]=t(i,n);return n},te=Array.isArray;class Ws{constructor(){this._observers=ft()}on(t,n){return Tt(this._observers,t,Ut).add(n),n}once(t,n){const i=(...s)=>{this.off(t,i),n(...s)};this.on(t,i)}off(t,n){const i=this._observers.get(t);i!==void 0&&(i.delete(n),i.size===0&&this._observers.delete(t))}emit(t,n){return $t((this._observers.get(t)||ft()).values()).forEach(i=>i(...n))}destroy(){this._observers=ft()}}const pt=Math.floor,He=Math.abs,ee=(e,t)=>e<t?e:t,Ot=(e,t)=>e>t?e:t,Gs=e=>e!==0?e<0:1/e<0,Zi=1,Qi=2,Un=4,$n=8,xe=32,Et=64,tt=128,tc=1<<29,mn=31,ni=63,Lt=127,ec=2147483647,Xe=Number.MAX_SAFE_INTEGER,ts=Number.MIN_SAFE_INTEGER,nc=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&pt(e)===e),Ys=String.fromCharCode,ic=e=>e.toLowerCase(),sc=/^\s*/g,rc=e=>e.replace(sc,""),oc=/([A-Z])/g,es=(e,t)=>rc(e.replace(oc,n=>`${t}${ic(n)}`)),lc=e=>{const t=unescape(encodeURIComponent(e)),n=t.length,i=new Uint8Array(n);for(let s=0;s<n;s++)i[s]=t.codePointAt(s);return i},be=typeof TextEncoder<"u"?new TextEncoder:null,cc=e=>be.encode(e),ac=be?cc:lc;let ge=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});ge&&ge.decode(new Uint8Array).length===1&&(ge=null);const hc=(e,t)=>Ql(t,()=>e).join("");class Ae{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Ie=()=>new Ae,uc=e=>{const t=Ie();return e(t),ut(t)},dc=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},ut=e=>{const t=new Uint8Array(dc(e));let n=0;for(let i=0;i<e.bufs.length;i++){const s=e.bufs[i];t.set(s,n),n+=s.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},fc=(e,t)=>{const n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(Ot(n,t)*2),e.cpos=0)},W=(e,t)=>{const n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},ii=W,I=(e,t)=>{for(;t>Lt;)W(e,tt|Lt&t),t=pt(t/128);W(e,Lt&t)},Ci=(e,t)=>{const n=Gs(t);for(n&&(t=-t),W(e,(t>ni?tt:0)|(n?Et:0)|ni&t),t=pt(t/64);t>0;)W(e,(t>Lt?tt:0)|Lt&t),t=pt(t/128)},si=new Uint8Array(3e4),pc=si.length/3,gc=(e,t)=>{if(t.length<pc){const n=be.encodeInto(t,si).written||0;I(e,n);for(let i=0;i<n;i++)W(e,si[i])}else st(e,ac(t))},mc=(e,t)=>{const n=unescape(encodeURIComponent(t)),i=n.length;I(e,i);for(let s=0;s<i;s++)W(e,n.codePointAt(s))},Yt=be&&be.encodeInto?gc:mc,xn=(e,t)=>{const n=e.cbuf.length,i=e.cpos,s=ee(n-i,t.length),r=t.length-s;e.cbuf.set(t.subarray(0,s),i),e.cpos+=s,r>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(Ot(n*2,r)),e.cbuf.set(t.subarray(s)),e.cpos=r)},st=(e,t)=>{I(e,t.byteLength),xn(e,t)},ki=(e,t)=>{fc(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},xc=(e,t)=>ki(e,4).setFloat32(0,t,!1),bc=(e,t)=>ki(e,8).setFloat64(0,t,!1),wc=(e,t)=>ki(e,8).setBigInt64(0,t,!1),ns=new DataView(new ArrayBuffer(4)),yc=e=>(ns.setFloat32(0,e),ns.getFloat32(0)===e),ne=(e,t)=>{switch(typeof t){case"string":W(e,119),Yt(e,t);break;case"number":nc(t)&&He(t)<=ec?(W(e,125),Ci(e,t)):yc(t)?(W(e,124),xc(e,t)):(W(e,123),bc(e,t));break;case"bigint":W(e,122),wc(e,t);break;case"object":if(t===null)W(e,126);else if(te(t)){W(e,117),I(e,t.length);for(let n=0;n<t.length;n++)ne(e,t[n])}else if(t instanceof Uint8Array)W(e,116),st(e,t);else{W(e,118);const n=Object.keys(t);I(e,n.length);for(let i=0;i<n.length;i++){const s=n[i];Yt(e,s),ne(e,t[s])}}break;case"boolean":W(e,t?120:121);break;default:W(e,127)}};class is extends Ae{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&I(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const ss=e=>{e.count>0&&(Ci(e.encoder,e.count===1?e.s:-e.s),e.count>1&&I(e.encoder,e.count-2))};class ze{constructor(){this.encoder=new Ae,this.s=0,this.count=0}write(t){this.s===t?this.count++:(ss(this),this.count=1,this.s=t)}toUint8Array(){return ss(this),ut(this.encoder)}}const rs=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);Ci(e.encoder,t),e.count>1&&I(e.encoder,e.count-2)}};class Fn{constructor(){this.encoder=new Ae,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(rs(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return rs(this),ut(this.encoder)}}class vc{constructor(){this.sarr=[],this.s="",this.lensE=new ze}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new Ae;return this.sarr.push(this.s),this.s="",Yt(t,this.sarr.join("")),xn(t,this.lensE.toUint8Array()),ut(t)}}const vt=e=>new Error(e),at=()=>{throw vt("Method unimplemented")},et=()=>{throw vt("Unexpected case")},Js=vt("Unexpected end of array"),Xs=vt("Integer out of Range");class bn{constructor(t){this.arr=t,this.pos=0}}const Ei=e=>new bn(e),Sc=e=>e.pos!==e.arr.length,Cc=(e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},lt=e=>Cc(e,R(e)),we=e=>e.arr[e.pos++],R=e=>{let t=0,n=1;const i=e.arr.length;for(;e.pos<i;){const s=e.arr[e.pos++];if(t=t+(s&Lt)*n,n*=128,s<tt)return t;if(t>Xe)throw Xs}throw Js},_i=e=>{let t=e.arr[e.pos++],n=t&ni,i=64;const s=(t&Et)>0?-1:1;if((t&tt)===0)return s*n;const r=e.arr.length;for(;e.pos<r;){if(t=e.arr[e.pos++],n=n+(t&Lt)*i,i*=128,t<tt)return s*n;if(n>Xe)throw Xs}throw Js},kc=e=>{let t=R(e);if(t===0)return"";{let n=String.fromCodePoint(we(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(we(e));else for(;t>0;){const i=t<1e4?t:1e4,s=e.arr.subarray(e.pos,e.pos+i);e.pos+=i,n+=String.fromCodePoint.apply(null,s),t-=i}return decodeURIComponent(escape(n))}},Ec=e=>ge.decode(lt(e)),ri=ge?Ec:kc,Ti=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},_c=e=>Ti(e,4).getFloat32(0,!1),Tc=e=>Ti(e,8).getFloat64(0,!1),Dc=e=>Ti(e,8).getBigInt64(0,!1),Ac=[e=>{},e=>null,_i,_c,Tc,Dc,e=>!1,e=>!0,ri,e=>{const t=R(e),n={};for(let i=0;i<t;i++){const s=ri(e);n[s]=Ze(e)}return n},e=>{const t=R(e),n=[];for(let i=0;i<t;i++)n.push(Ze(e));return n},lt],Ze=e=>Ac[127-we(e)](e);class os extends bn{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Sc(this)?this.count=R(this)+1:this.count=-1),this.count--,this.s}}class Ke extends bn{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=_i(this);const t=Gs(this.s);this.count=1,t&&(this.s=-this.s,this.count=R(this)+2)}return this.count--,this.s}}class Vn extends bn{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=_i(this),n=t&1;this.diff=pt(t/2),this.count=1,n&&(this.count=R(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Ic{constructor(t){this.decoder=new Ke(t),this.str=ri(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}}const Mc=crypto.getRandomValues.bind(crypto),Oc=Math.random,Zs=()=>Mc(new Uint32Array(1))[0],jc=e=>e[pt(Oc()*e.length)],Rc="10000000-1000-4000-8000"+-1e11,Nc=()=>Rc.replace(/[018]/g,e=>(e^Zs()&15>>e/4).toString(16)),Bc=Date.now,ls=e=>new Promise(e);Promise.all.bind(Promise);const cs=e=>e===void 0?null:e;class Lc{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}}let Qs=new Lc,Pc=!0;try{typeof localStorage<"u"&&localStorage&&(Qs=localStorage,Pc=!1)}catch{}const Uc=Qs,ye=Symbol("Equality"),tr=(e,t)=>{var n;return e===t||!!((n=e==null?void 0:e[ye])!=null&&n.call(e,t))||!1},$c=e=>typeof e=="object",Fc=Object.assign,er=Object.keys,Vc=(e,t)=>{for(const n in e)t(e[n],n)},Qe=e=>er(e).length,Hc=e=>{for(const t in e)return!1;return!0},oe=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},Di=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),zc=(e,t)=>e===t||Qe(e)===Qe(t)&&oe(e,(n,i)=>(n!==void 0||Di(t,i))&&tr(t[i],n)),Kc=Object.freeze,nr=e=>{for(const t in e){const n=e[t];(typeof n=="object"||typeof n=="function")&&nr(e[t])}return Kc(e)},Ai=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Ai(e,t,n+1)}},qe=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[ye]!=null)return e[ye](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:{if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break}case Set:{if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;break}case Map:{if(e.size!==t.size)return!1;for(const n of e.keys())if(!t.has(n)||!qe(e.get(n),t.get(n)))return!1;break}case void 0:case Object:if(Qe(e)!==Qe(t))return!1;for(const n in e)if(!Di(e,n)||!qe(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!qe(e[n],t[n]))return!1;break;default:return!1}return!0},qc=(e,t)=>t.includes(e),ie=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",ir=typeof window<"u"&&typeof document<"u"&&!ie;let bt;const Wc=()=>{if(bt===void 0)if(ie){bt=ft();const e=process.argv;let t=null;for(let n=0;n<e.length;n++){const i=e[n];i[0]==="-"?(t!==null&&bt.set(t,""),t=i):t!==null&&(bt.set(t,i),t=null)}t!==null&&bt.set(t,"")}else typeof location=="object"?(bt=ft(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){const[t,n]=e.split("=");bt.set(`--${es(t,"-")}`,n),bt.set(`-${es(t,"-")}`,n)}})):bt=ft();return bt},oi=e=>Wc().has(e),tn=e=>cs(ie?process.env[e.toUpperCase().replaceAll("-","_")]:Uc.getItem(e)),sr=e=>oi("--"+e)||tn(e)!==null,Gc=sr("production"),Yc=ie&&qc(process.env.FORCE_COLOR,["true","1","2"]),Jc=Yc||!oi("--no-colors")&&!sr("no-color")&&(!ie||process.stdout.isTTY)&&(!ie||oi("--color")||tn("COLORTERM")!==null||(tn("TERM")||"").includes("color")),Xc=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=Ys(e[n]);return btoa(t)},Zc=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),Qc=ir?Xc:Zc,ta=e=>uc(t=>ne(t,e));class ea{constructor(t,n){this.left=t,this.right=n}}const Ct=(e,t)=>new ea(e,t),as=e=>e.next()>=.5,Hn=(e,t,n)=>pt(e.next()*(n+1-t)+t),rr=(e,t,n)=>pt(e.next()*(n+1-t)+t),Ii=(e,t,n)=>rr(e,t,n),na=e=>Ys(Ii(e,97,122)),ia=(e,t=0,n=20)=>{const i=Ii(e,t,n);let s="";for(let r=0;r<i;r++)s+=na(e);return s},zn=(e,t)=>t[Ii(e,0,t.length-1)],sa=Symbol("0schema");class ra{constructor(){this._rerrs=[]}extend(t,n,i,s=null){this._rerrs.push({path:t,expected:n,has:i,message:s})}toString(){const t=[];for(let n=this._rerrs.length-1;n>0;n--){const i=this._rerrs[n];t.push(hc(" ",(this._rerrs.length-n)*2)+`${i.path!=null?`[${i.path}] `:""}${i.has} doesn't match ${i.expected}. ${i.message}`)}return t.join(`
3
- `)}}const li=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[ye]?tr(e,t):te(e)?vi(e,n=>Si(t,i=>li(n,i))):$c(e)?oe(e,(n,i)=>li(n,t[i])):!1;class Z{extends(t){let[n,i]=[this.shape,t.shape];return this.constructor._dilutes&&([i,n]=[n,i]),li(n,i)}equals(t){return this.constructor===t.constructor&&qe(this.shape,t.shape)}[sa](){return!0}[ye](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){at()}get nullable(){return le(this,Cn)}get optional(){return new cr(this)}cast(t){return hs(t,this),t}expect(t){return hs(t,this),t}}Ne(Z,"_dilutes",!1);class Mi extends Z{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n=void 0){const i=(t==null?void 0:t.constructor)===this.shape&&(this._c==null||this._c(t));return!i&&(n==null||n.extend(null,this.shape.name,t==null?void 0:t.constructor.name,(t==null?void 0:t.constructor)!==this.shape?"Constructor match failed":"Check failed")),i}}const V=(e,t=null)=>new Mi(e,t);V(Mi);class Oi extends Z{constructor(t){super(),this.shape=t}check(t,n){const i=this.shape(t);return!i&&(n==null||n.extend(null,"custom prop",t==null?void 0:t.constructor.name,"failed to check custom prop")),i}}const J=e=>new Oi(e);V(Oi);class wn extends Z{constructor(t){super(),this.shape=t}check(t,n){const i=this.shape.some(s=>s===t);return!i&&(n==null||n.extend(null,this.shape.join(" | "),t.toString())),i}}const yn=(...e)=>new wn(e),or=V(wn),oa=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,t=>"\\"+t)),lr=e=>{if(se.check(e))return[oa(e)];if(or.check(e))return e.shape.map(t=>t+"");if(xr.check(e))return["[+-]?\\d+.?\\d*"];if(br.check(e))return[".*"];if(nn.check(e))return e.shape.map(lr).flat(1);et()};class la extends Z{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(lr).map(n=>`(${n.join("|")})`).join("")+"$")}check(t,n){const i=this._r.exec(t)!=null;return!i&&(n==null||n.extend(null,this._r.toString(),t.toString(),"String doesn't match string template.")),i}}V(la);const ca=Symbol("optional");class cr extends Z{constructor(t){super(),this.shape=t}check(t,n){const i=t===void 0||this.shape.check(t);return!i&&(n==null||n.extend(null,"undefined (optional)","()")),i}get[ca](){return!0}}const aa=V(cr);class ha extends Z{check(t,n){return n==null||n.extend(null,"never",typeof t),!1}}V(ha);const gn=class gn extends Z{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}get partial(){return new gn(this.shape,!0)}check(t,n){return t==null?(n==null||n.extend(null,"object","null"),!1):oe(this.shape,(i,s)=>{const r=this._isPartial&&!Di(t,s)||i.check(t[s],n);return!r&&(n==null||n.extend(s.toString(),i.toString(),typeof t[s],"Object property does not match")),r})}};Ne(gn,"_dilutes",!0);let en=gn;const ua=e=>new en(e),da=V(en),fa=J(e=>e!=null&&(e.constructor===Object||e.constructor==null));class ar extends Z{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return t!=null&&oe(t,(i,s)=>{const r=this.shape.keys.check(s,n);return!r&&(n==null||n.extend(s+"","Record",typeof t,r?"Key doesn't match schema":"Value doesn't match value")),r&&this.shape.values.check(i,n)})}}const hr=(e,t)=>new ar(e,t),pa=V(ar);class ur extends Z{constructor(t){super(),this.shape=t}check(t,n){return t!=null&&oe(this.shape,(i,s)=>{const r=i.check(t[s],n);return!r&&(n==null||n.extend(s.toString(),"Tuple",typeof i)),r})}}const ga=(...e)=>new ur(e);V(ur);class dr extends Z{constructor(t){super(),this.shape=t.length===1?t[0]:new vn(t)}check(t,n){const i=te(t)&&vi(t,s=>this.shape.check(s));return!i&&(n==null||n.extend(null,"Array","")),i}}const fr=(...e)=>new dr(e),ma=V(dr),xa=J(e=>te(e));class pr extends Z{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n){const i=t instanceof this.shape&&(this._c==null||this._c(t));return!i&&(n==null||n.extend(null,this.shape.name,t==null?void 0:t.constructor.name)),i}}const ba=(e,t=null)=>new pr(e,t);V(pr);const wa=ba(Z);class ya extends Z{constructor(t){super(),this.len=t.length-1,this.args=ga(...t.slice(-1)),this.res=t[this.len]}check(t,n){const i=t.constructor===Function&&t.length<=this.len;return!i&&(n==null||n.extend(null,"function",typeof t)),i}}const va=V(ya),Sa=J(e=>typeof e=="function");class Ca extends Z{constructor(t){super(),this.shape=t}check(t,n){const i=vi(this.shape,s=>s.check(t,n));return!i&&(n==null||n.extend(null,"Intersectinon",typeof t)),i}}V(Ca,e=>e.shape.length>0);class vn extends Z{constructor(t){super(),this.shape=t}check(t,n){const i=Si(this.shape,s=>s.check(t,n));return n==null||n.extend(null,"Union",typeof t),i}}Ne(vn,"_dilutes",!0);const le=(...e)=>e.findIndex(t=>nn.check(t))>=0?le(...e.map(t=>ve(t)).map(t=>nn.check(t)?t.shape:[t]).flat(1)):e.length===1?e[0]:new vn(e),nn=V(vn),gr=()=>!0,sn=J(gr),ka=V(Oi,e=>e.shape===gr),ji=J(e=>typeof e=="bigint"),Ea=J(e=>e===ji),mr=J(e=>typeof e=="symbol");J(e=>e===mr);const Jt=J(e=>typeof e=="number"),xr=J(e=>e===Jt),se=J(e=>typeof e=="string"),br=J(e=>e===se),Sn=J(e=>typeof e=="boolean"),_a=J(e=>e===Sn),wr=yn(void 0);V(wn,e=>e.shape.length===1&&e.shape[0]===void 0);yn(void 0);const Cn=yn(null),Ta=V(wn,e=>e.shape.length===1&&e.shape[0]===null);V(Uint8Array);V(Mi,e=>e.shape===Uint8Array);const Da=le(Jt,se,Cn,wr,ji,Sn,mr);(()=>{const e=fr(sn),t=hr(se,sn),n=le(Jt,se,Cn,Sn,e,t);return e.shape=n,t.shape.values=n,n})();const ve=e=>{if(wa.check(e))return e;if(fa.check(e)){const t={};for(const n in e)t[n]=ve(e[n]);return ua(t)}else{if(xa.check(e))return le(...e.map(ve));if(Da.check(e))return yn(e);if(Sa.check(e))return V(e)}et()},hs=Gc?()=>{}:(e,t)=>{const n=new ra;if(!t.check(e,n))throw vt(`Expected value to be of type ${t.constructor.name}.
4
- ${n.toString()}`)};class Aa{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:ve(t),h:n}),this}else(t){return this.if(sn,t)}done(){return(t,n)=>{for(let i=0;i<this.patterns.length;i++){const s=this.patterns[i];if(s.if.check(t))return s.h(t,n)}throw vt("Unhandled pattern")}}}const Ia=e=>new Aa(e),yr=Ia(sn).if(xr,(e,t)=>Hn(t,ts,Xe)).if(br,(e,t)=>ia(t)).if(_a,(e,t)=>as(t)).if(Ea,(e,t)=>BigInt(Hn(t,ts,Xe))).if(nn,(e,t)=>Gt(t,zn(t,e.shape))).if(da,(e,t)=>{const n={};for(const i in e.shape){let s=e.shape[i];if(aa.check(s)){if(as(t))continue;s=s.shape}n[i]=yr(s,t)}return n}).if(ma,(e,t)=>{const n=[],i=rr(t,0,42);for(let s=0;s<i;s++)n.push(Gt(t,e.shape));return n}).if(or,(e,t)=>zn(t,e.shape)).if(Ta,(e,t)=>null).if(va,(e,t)=>{const n=Gt(t,e.res);return()=>n}).if(ka,(e,t)=>Gt(t,zn(t,[Jt,se,Cn,wr,ji,Sn,fr(Jt),hr(le("a","b","c"),Jt)]))).if(pa,(e,t)=>{const n={},i=Hn(t,0,3);for(let s=0;s<i;s++){const r=Gt(t,e.shape.keys),o=Gt(t,e.shape.values);n[r]=o}return n}).done(),Gt=(e,t)=>yr(ve(t),e),Me=typeof document<"u"?document:{};J(e=>e.nodeType===Na);typeof DOMParser<"u"&&new DOMParser;J(e=>e.nodeType===Oa);J(e=>e.nodeType===ja);const Ma=e=>Jl(e,(t,n)=>`${n}:${t};`).join(""),Oa=Me.ELEMENT_NODE,ja=Me.TEXT_NODE,Ra=Me.DOCUMENT_NODE,Na=Me.DOCUMENT_FRAGMENT_NODE;J(e=>e.nodeType===Ra);const Ba=e=>class{constructor(n){this._=n}destroy(){e(this._)}},La=Ba(clearTimeout),vr=(e,t)=>new La(setTimeout(t,e)),Dt=Symbol,Sr=Dt(),Cr=Dt(),Pa=Dt(),Ua=Dt(),$a=Dt(),kr=Dt(),Fa=Dt(),Ri=Dt(),Va=Dt(),Ha=e=>{var s;e.length===1&&((s=e[0])==null?void 0:s.constructor)===Function&&(e=e[0]());const t=[],n=[];let i=0;for(;i<e.length;i++){const r=e[i];if(r===void 0)break;if(r.constructor===String||r.constructor===Number)t.push(r);else if(r.constructor===Object)break}for(i>0&&n.push(t.join(""));i<e.length;i++){const r=e[i];r instanceof Symbol||n.push(r)}return n},za={[Sr]:Ct("font-weight","bold"),[Cr]:Ct("font-weight","normal"),[Pa]:Ct("color","blue"),[$a]:Ct("color","green"),[Ua]:Ct("color","grey"),[kr]:Ct("color","red"),[Fa]:Ct("color","purple"),[Ri]:Ct("color","orange"),[Va]:Ct("color","black")},Ka=e=>{var o;e.length===1&&((o=e[0])==null?void 0:o.constructor)===Function&&(e=e[0]());const t=[],n=[],i=ft();let s=[],r=0;for(;r<e.length;r++){const l=e[r],c=za[l];if(c!==void 0)i.set(c.left,c.right);else{if(l===void 0)break;if(l.constructor===String||l.constructor===Number){const a=Ma(i);r>0||a.length>0?(t.push("%c"+l),n.push(a)):t.push(l)}else break}}for(r>0&&(s=n,s.unshift(t.join("")));r<e.length;r++){const l=e[r];l instanceof Symbol||s.push(l)}return s},Er=Jc?Ka:Ha,qa=(...e)=>{console.log(...Er(e)),Tr.forEach(t=>t.print(e))},_r=(...e)=>{console.warn(...Er(e)),e.unshift(Ri),Tr.forEach(t=>t.print(e))},Tr=Ut(),Dr=e=>({[Symbol.iterator](){return this},next:e}),Wa=(e,t)=>Dr(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),Kn=(e,t)=>Dr(()=>{const{done:n,value:i}=e.next();return{done:n,value:n?void 0:t(i)}});class kn{constructor(t,n){this.clock=t,this.len=n}}class ce{constructor(){this.clients=new Map}}const jt=(e,t,n)=>t.clients.forEach((i,s)=>{const r=e.doc.store.clients.get(s);if(r!=null){const o=r[r.length-1],l=o.id.clock+o.length;for(let c=0,a=i[c];c<i.length&&a.clock<l;a=i[++c])Br(e,r,a.clock,a.len,n)}}),Ga=(e,t)=>{let n=0,i=e.length-1;for(;n<=i;){const s=pt((n+i)/2),r=e[s],o=r.clock;if(o<=t){if(t<o+r.len)return s;n=s+1}else i=s-1}return null},ae=(e,t)=>{const n=e.clients.get(t.client);return n!==void 0&&Ga(n,t.clock)!==null},Ni=e=>{e.clients.forEach(t=>{t.sort((s,r)=>s.clock-r.clock);let n,i;for(n=1,i=1;n<t.length;n++){const s=t[i-1],r=t[n];s.clock+s.len>=r.clock?t[i-1]=new kn(s.clock,Ot(s.len,r.clock+r.len-s.clock)):(i<n&&(t[i]=r),i++)}t.length=i})},ci=e=>{const t=new ce;for(let n=0;n<e.length;n++)e[n].clients.forEach((i,s)=>{if(!t.clients.has(s)){const r=i.slice();for(let o=n+1;o<e.length;o++)Zl(r,e[o].clients.get(s)||[]);t.clients.set(s,r)}});return Ni(t),t},Se=(e,t,n,i)=>{Tt(e.clients,t,()=>[]).push(new kn(n,i))},Ar=()=>new ce,Ya=e=>{const t=Ar();return e.clients.forEach((n,i)=>{const s=[];for(let r=0;r<n.length;r++){const o=n[r];if(o.deleted){const l=o.id.clock;let c=o.length;if(r+1<n.length)for(let a=n[r+1];r+1<n.length&&a.deleted;a=n[++r+1])c+=a.length;s.push(new kn(l,c))}}s.length>0&&t.clients.set(i,s)}),t},Bi=(e,t)=>{I(e.restEncoder,t.clients.size),$t(t.clients.entries()).sort((n,i)=>i[0]-n[0]).forEach(([n,i])=>{e.resetDsCurVal(),I(e.restEncoder,n);const s=i.length;I(e.restEncoder,s);for(let r=0;r<s;r++){const o=i[r];e.writeDsClock(o.clock),e.writeDsLen(o.len)}})},Ja=e=>{const t=new ce,n=R(e.restDecoder);for(let i=0;i<n;i++){e.resetDsCurVal();const s=R(e.restDecoder),r=R(e.restDecoder);if(r>0){const o=Tt(t.clients,s,()=>[]);for(let l=0;l<r;l++)o.push(new kn(e.readDsClock(),e.readDsLen()))}}return t},us=(e,t,n)=>{const i=new ce,s=R(e.restDecoder);for(let r=0;r<s;r++){e.resetDsCurVal();const o=R(e.restDecoder),l=R(e.restDecoder),c=n.clients.get(o)||[],a=$(n,o);for(let u=0;u<l;u++){const h=e.readDsClock(),f=h+e.readDsLen();if(h<a){a<f&&Se(i,o,a,f-a);let p=gt(c,h),g=c[p];for(!g.deleted&&g.id.clock<h&&(c.splice(p+1,0,un(t,g,h-g.id.clock)),p++);p<c.length&&(g=c[p++],g.id.clock<f);)g.deleted||(f<g.id.clock+g.length&&c.splice(p,0,un(t,g,f-g.id.clock)),g.delete(t))}else Se(i,o,h,f-h)}}if(i.clients.size>0){const r=new En;return I(r.restEncoder,0),Bi(r,i),r.toUint8Array()}return null},Ir=Zs;class zt extends Ws{constructor({guid:t=Nc(),collectionid:n=null,gc:i=!0,gcFilter:s=()=>!0,meta:r=null,autoLoad:o=!1,shouldLoad:l=!0}={}){super(),this.gc=i,this.gcFilter=s,this.clientID=Ir(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new Rr,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=o,this.meta=r,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=ls(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const c=()=>ls(a=>{const u=h=>{(h===void 0||h===!0)&&(this.off("sync",u),a())};this.on("sync",u)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=a===void 0||a===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=c()}load(){const t=this._item;t!==null&&!this.shouldLoad&&j(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set($t(this.subdocs).map(t=>t.guid))}transact(t,n=null){return j(this,t,n)}get(t,n=G){const i=Tt(this.share,t,()=>{const r=new n;return r._integrate(this,null),r}),s=i.constructor;if(n!==G&&s!==n)if(s===G){const r=new n;r._map=i._map,i._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=r}),r._start=i._start;for(let o=r._start;o!==null;o=o.right)o.parent=r;return r._length=i._length,this.share.set(t,r),r._integrate(this,null),r}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return i}getArray(t=""){return this.get(t,Qt)}getText(t=""){return this.get(t,Rt)}getMap(t=""){return this.get(t,re)}getXmlElement(t=""){return this.get(t,Q)}getXmlFragment(t=""){return this.get(t,Ft)}toJSON(){const t={};return this.share.forEach((n,i)=>{t[i]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,$t(this.subdocs).forEach(n=>n.destroy());const t=this._item;if(t!==null){this._item=null;const n=t.content;n.doc=new zt({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,j(t.parent.doc,i=>{const s=n.doc;t.deleted||i.subdocsAdded.add(s),i.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class Xa{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=R(this.restDecoder),this.dsCurrVal}readDsLen(){const t=R(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class rn extends Xa{constructor(t){super(t),this.keys=[],R(t),this.keyClockDecoder=new Vn(lt(t)),this.clientDecoder=new Ke(lt(t)),this.leftClockDecoder=new Vn(lt(t)),this.rightClockDecoder=new Vn(lt(t)),this.infoDecoder=new os(lt(t),we),this.stringDecoder=new Ic(lt(t)),this.parentInfoDecoder=new os(lt(t),we),this.typeRefDecoder=new Ke(lt(t)),this.lenDecoder=new Ke(lt(t))}readLeftID(){return new Xt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Xt(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Ze(this.restDecoder)}readBuf(){return lt(this.restDecoder)}readJSON(){return Ze(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{const n=this.stringDecoder.read();return this.keys.push(n),n}}}class Za{constructor(){this.restEncoder=Ie()}toUint8Array(){return ut(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){I(this.restEncoder,t)}writeDsLen(t){I(this.restEncoder,t)}}class Qa extends Za{writeLeftID(t){I(this.restEncoder,t.client),I(this.restEncoder,t.clock)}writeRightID(t){I(this.restEncoder,t.client),I(this.restEncoder,t.clock)}writeClient(t){I(this.restEncoder,t)}writeInfo(t){ii(this.restEncoder,t)}writeString(t){Yt(this.restEncoder,t)}writeParentInfo(t){I(this.restEncoder,t?1:0)}writeTypeRef(t){I(this.restEncoder,t)}writeLen(t){I(this.restEncoder,t)}writeAny(t){ne(this.restEncoder,t)}writeBuf(t){st(this.restEncoder,t)}writeJSON(t){Yt(this.restEncoder,JSON.stringify(t))}writeKey(t){Yt(this.restEncoder,t)}}class th{constructor(){this.restEncoder=Ie(),this.dsCurrVal=0}toUint8Array(){return ut(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,I(this.restEncoder,n)}writeDsLen(t){t===0&&et(),I(this.restEncoder,t-1),this.dsCurrVal+=t}}class En extends th{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Fn,this.clientEncoder=new ze,this.leftClockEncoder=new Fn,this.rightClockEncoder=new Fn,this.infoEncoder=new is(ii),this.stringEncoder=new vc,this.parentInfoEncoder=new is(ii),this.typeRefEncoder=new ze,this.lenEncoder=new ze}toUint8Array(){const t=Ie();return I(t,0),st(t,this.keyClockEncoder.toUint8Array()),st(t,this.clientEncoder.toUint8Array()),st(t,this.leftClockEncoder.toUint8Array()),st(t,this.rightClockEncoder.toUint8Array()),st(t,ut(this.infoEncoder)),st(t,this.stringEncoder.toUint8Array()),st(t,ut(this.parentInfoEncoder)),st(t,this.typeRefEncoder.toUint8Array()),st(t,this.lenEncoder.toUint8Array()),xn(t,ut(this.restEncoder)),ut(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){ne(this.restEncoder,t)}writeBuf(t){st(this.restEncoder,t)}writeJSON(t){ne(this.restEncoder,t)}writeKey(t){const n=this.keyMap.get(t);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}}const eh=(e,t,n,i)=>{i=Ot(i,t[0].id.clock);const s=gt(t,i);I(e.restEncoder,t.length-s),e.writeClient(n),I(e.restEncoder,i);const r=t[s];r.write(e,i-r.id.clock);for(let o=s+1;o<t.length;o++)t[o].write(e,0)},Mr=(e,t,n)=>{const i=new Map;n.forEach((s,r)=>{$(t,r)>s&&i.set(r,s)}),_n(t).forEach((s,r)=>{n.has(r)||i.set(r,0)}),I(e.restEncoder,i.size),$t(i.entries()).sort((s,r)=>r[0]-s[0]).forEach(([s,r])=>{eh(e,t.clients.get(s),s,r)})},nh=(e,t)=>{const n=ft(),i=R(e.restDecoder);for(let s=0;s<i;s++){const r=R(e.restDecoder),o=new Array(r),l=e.readClient();let c=R(e.restDecoder);n.set(l,{i:0,refs:o});for(let a=0;a<r;a++){const u=e.readInfo();switch(mn&u){case 0:{const h=e.readLen();o[a]=new ct(_(l,c),h),c+=h;break}case 10:{const h=R(e.restDecoder);o[a]=new ht(_(l,c),h),c+=h;break}default:{const h=(u&(Et|tt))===0,f=new O(_(l,c),null,(u&tt)===tt?e.readLeftID():null,null,(u&Et)===Et?e.readRightID():null,h?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,h&&(u&xe)===xe?e.readString():null,so(e,u));o[a]=f,c+=f.length}}}}return n},ih=(e,t,n)=>{const i=[];let s=$t(n.keys()).sort((p,g)=>p-g);if(s.length===0)return null;const r=()=>{if(s.length===0)return null;let p=n.get(s[s.length-1]);for(;p.refs.length===p.i;)if(s.pop(),s.length>0)p=n.get(s[s.length-1]);else return null;return p};let o=r();if(o===null)return null;const l=new Rr,c=new Map,a=(p,g)=>{const x=c.get(p);(x==null||x>g)&&c.set(p,g)};let u=o.refs[o.i++];const h=new Map,f=()=>{for(const p of i){const g=p.id.client,x=n.get(g);x?(x.i--,l.clients.set(g,x.refs.slice(x.i)),n.delete(g),x.i=0,x.refs=[]):l.clients.set(g,[p]),s=s.filter(w=>w!==g)}i.length=0};for(;;){if(u.constructor!==ht){const g=Tt(h,u.id.client,()=>$(t,u.id.client))-u.id.clock;if(g<0)i.push(u),a(u.id.client,u.id.clock-1),f();else{const x=u.getMissing(e,t);if(x!==null){i.push(u);const w=n.get(x)||{refs:[],i:0};if(w.refs.length===w.i)a(x,$(t,x)),f();else{u=w.refs[w.i++];continue}}else(g===0||g<u.length)&&(u.integrate(e,g),h.set(u.id.client,u.id.clock+u.length))}}if(i.length>0)u=i.pop();else if(o!==null&&o.i<o.refs.length)u=o.refs[o.i++];else{if(o=r(),o===null)break;u=o.refs[o.i++]}}if(l.clients.size>0){const p=new En;return Mr(p,l,new Map),I(p.restEncoder,0),{missing:c,update:p.toUint8Array()}}return null},sh=(e,t)=>Mr(e,t.doc.store,t.beforeState),rh=(e,t,n,i=new rn(e))=>j(t,s=>{s.local=!1;let r=!1;const o=s.doc,l=o.store,c=nh(i,o),a=ih(s,l,c),u=l.pendingStructs;if(u){for(const[f,p]of u.missing)if(p<$(l,f)){r=!0;break}if(a){for(const[f,p]of a.missing){const g=u.missing.get(f);(g==null||g>p)&&u.missing.set(f,p)}u.update=ys([u.update,a.update])}}else l.pendingStructs=a;const h=us(i,s,l);if(l.pendingDs){const f=new rn(Ei(l.pendingDs));R(f.restDecoder);const p=us(f,s,l);h&&p?l.pendingDs=ys([h,p]):l.pendingDs=h||p}else l.pendingDs=h;if(r){const f=l.pendingStructs.update;l.pendingStructs=null,ai(s.doc,f)}},n,!1),ai=(e,t,n,i=rn)=>{const s=Ei(t);rh(s,e,n,new i(s))};class oh{constructor(){this.l=[]}}const ds=()=>new oh,fs=(e,t)=>e.l.push(t),ps=(e,t)=>{const n=e.l,i=n.length;e.l=n.filter(s=>t!==s),i===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Or=(e,t,n)=>Ai(e.l,[t,n]);class Xt{constructor(t,n){this.client=t,this.clock=n}}const Be=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,_=(e,t)=>new Xt(e,t),Ce=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw et()},ke=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1};class on{constructor(t,n,i,s=0){this.type=t,this.tname=n,this.item=i,this.assoc=s}}class lh{constructor(t,n,i=0){this.type=t,this.index=n,this.assoc=i}}const ch=(e,t,n=0)=>new lh(e,t,n),Le=(e,t,n)=>{let i=null,s=null;return e._item===null?s=Ce(e):i=_(e._item.id.client,e._item.id.clock),new on(i,s,t,n)},qn=(e,t,n=0)=>{let i=e._start;if(n<0){if(t===0)return Le(e,null,n);t--}for(;i!==null;){if(!i.deleted&&i.countable){if(i.length>t)return Le(e,_(i.id.client,i.id.clock+t),n);t-=i.length}if(i.right===null&&n<0)return Le(e,i.lastId,n);i=i.right}return Le(e,null,n)},ah=(e,t)=>{const n=Zt(e,t),i=t.clock-n.id.clock;return{item:n,diff:i}},hh=(e,t,n=!0)=>{const i=t.store,s=e.item,r=e.type,o=e.tname,l=e.assoc;let c=null,a=0;if(s!==null){if($(i,s.client)<=s.clock)return null;const u=n?fi(i,s):ah(i,s),h=u.item;if(!(h instanceof O))return null;if(c=h.parent,c._item===null||!c._item.deleted){a=h.deleted||!h.countable?0:u.diff+(l>=0?0:1);let f=h.left;for(;f!==null;)!f.deleted&&f.countable&&(a+=f.length),f=f.left}}else{if(o!==null)c=t.get(o);else if(r!==null){if($(i,r.client)<=r.clock)return null;const{item:u}=n?fi(i,r):{item:Zt(i,r)};if(u instanceof O&&u.content instanceof xt)c=u.content.type;else return null}else throw et();l>=0?a=c._length:a=0}return ch(c,a,e.assoc)};class Li{constructor(t,n){this.ds=t,this.sv=n}}const jr=(e,t)=>new Li(e,t),Wn=e=>jr(Ya(e.store),_n(e.store)),Bt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!ae(t.ds,e.id),hi=(e,t)=>{const n=Tt(e.meta,hi,Ut),i=e.doc.store;n.has(t)||(t.sv.forEach((s,r)=>{s<$(i,r)&&it(e,_(r,s))}),jt(e,t.ds,s=>{}),n.add(t))};class Rr{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const _n=e=>{const t=new Map;return e.clients.forEach((n,i)=>{const s=n[n.length-1];t.set(i,s.id.clock+s.length)}),t},$=(e,t)=>{const n=e.clients.get(t);if(n===void 0)return 0;const i=n[n.length-1];return i.id.clock+i.length},Nr=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{const i=n[n.length-1];if(i.id.clock+i.length!==t.id.clock)throw et()}n.push(t)},gt=(e,t)=>{let n=0,i=e.length-1,s=e[i],r=s.id.clock;if(r===t)return i;let o=pt(t/(r+s.length-1)*i);for(;n<=i;){if(s=e[o],r=s.id.clock,r<=t){if(t<r+s.length)return o;n=o+1}else i=o-1;o=pt((n+i)/2)}throw et()},uh=(e,t)=>{const n=e.clients.get(t.client);return n[gt(n,t.clock)]},Zt=uh,ui=(e,t,n)=>{const i=gt(t,n),s=t[i];return s.id.clock<n&&s instanceof O?(t.splice(i+1,0,un(e,s,n-s.id.clock)),i+1):i},it=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[ui(e,n,t.clock)]},gs=(e,t,n)=>{const i=t.clients.get(n.client),s=gt(i,n.clock),r=i[s];return n.clock!==r.id.clock+r.length-1&&r.constructor!==ct&&i.splice(s+1,0,un(e,r,n.clock-r.id.clock+1)),r},dh=(e,t,n)=>{const i=e.clients.get(t.id.client);i[gt(i,t.id.clock)]=n},Br=(e,t,n,i,s)=>{if(i===0)return;const r=n+i;let o=ui(e,t,n),l;do l=t[o++],r<l.id.clock+l.length&&ui(e,t,r),s(l);while(o<t.length&&t[o].id.clock<r)};class fh{constructor(t,n,i){this.doc=t,this.deleteSet=new ce,this.beforeState=_n(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=i,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const ms=(e,t)=>t.deleteSet.clients.size===0&&!Xl(t.afterState,(n,i)=>t.beforeState.get(i)!==n)?!1:(Ni(t.deleteSet),sh(e,t),Bi(e,t.deleteSet),!0),xs=(e,t,n)=>{const i=t._item;(i===null||i.id.clock<(e.beforeState.get(i.id.client)||0)&&!i.deleted)&&Tt(e.changed,t,Ut).add(n)},We=(e,t)=>{let n=e[t],i=e[t-1],s=t;for(;s>0;n=i,i=e[--s-1]){if(i.deleted===n.deleted&&i.constructor===n.constructor&&i.mergeWith(n)){n instanceof O&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,i);continue}break}const r=t-s;return r&&e.splice(t+1-r,r),r},ph=(e,t,n)=>{for(const[i,s]of e.clients.entries()){const r=t.clients.get(i);for(let o=s.length-1;o>=0;o--){const l=s[o],c=l.clock+l.len;for(let a=gt(r,l.clock),u=r[a];a<r.length&&u.id.clock<c;u=r[++a]){const h=r[a];if(l.clock+l.len<=h.id.clock)break;h instanceof O&&h.deleted&&!h.keep&&n(h)&&h.gc(t,!1)}}}},gh=(e,t)=>{e.clients.forEach((n,i)=>{const s=t.clients.get(i);for(let r=n.length-1;r>=0;r--){const o=n[r],l=ee(s.length-1,1+gt(s,o.clock+o.len-1));for(let c=l,a=s[c];c>0&&a.id.clock>=o.clock;a=s[c])c-=1+We(s,c)}})},Lr=(e,t)=>{if(t<e.length){const n=e[t],i=n.doc,s=i.store,r=n.deleteSet,o=n._mergeStructs;try{Ni(r),n.afterState=_n(n.doc.store),i.emit("beforeObserverCalls",[n,i]);const l=[];n.changed.forEach((c,a)=>l.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(n,c)})),l.push(()=>{n.changedParentTypes.forEach((c,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(c=c.filter(u=>u.target._item===null||!u.target._item.deleted),c.forEach(u=>{u.currentTarget=a,u._path=null}),c.sort((u,h)=>u.path.length-h.path.length),l.push(()=>{Or(a._dEH,c,n)}))}),l.push(()=>i.emit("afterTransaction",[n,i])),l.push(()=>{n._needFormattingCleanup&&Nh(n)})}),Ai(l,[])}finally{i.gc&&ph(r,s,i.gcFilter),gh(r,s),n.afterState.forEach((u,h)=>{const f=n.beforeState.get(h)||0;if(f!==u){const p=s.clients.get(h),g=Ot(gt(p,f),1);for(let x=p.length-1;x>=g;)x-=1+We(p,x)}});for(let u=o.length-1;u>=0;u--){const{client:h,clock:f}=o[u].id,p=s.clients.get(h),g=gt(p,f);g+1<p.length&&We(p,g+1)>1||g>0&&We(p,g)}if(!n.local&&n.afterState.get(i.clientID)!==n.beforeState.get(i.clientID)&&(qa(Ri,Sr,"[yjs] ",Cr,kr,"Changed the client-id because another client seems to be using it."),i.clientID=Ir()),i.emit("afterTransactionCleanup",[n,i]),i._observers.has("update")){const u=new Qa;ms(u,n)&&i.emit("update",[u.toUint8Array(),n.origin,i,n])}if(i._observers.has("updateV2")){const u=new En;ms(u,n)&&i.emit("updateV2",[u.toUint8Array(),n.origin,i,n])}const{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=n;(l.size>0||a.size>0||c.size>0)&&(l.forEach(u=>{u.clientID=i.clientID,u.collectionid==null&&(u.collectionid=i.collectionid),i.subdocs.add(u)}),a.forEach(u=>i.subdocs.delete(u)),i.emit("subdocs",[{loaded:c,added:l,removed:a},i,n]),a.forEach(u=>u.destroy())),e.length<=t+1?(i._transactionCleanups=[],i.emit("afterAllTransactions",[i,e])):Lr(e,t+1)}}},j=(e,t,n=null,i=!0)=>{const s=e._transactionCleanups;let r=!1,o=null;e._transaction===null&&(r=!0,e._transaction=new fh(e,n,i),s.push(e._transaction),s.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(r){const l=e._transaction===s[0];e._transaction=null,l&&Lr(s,0)}}return o};class mh{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const bs=(e,t,n)=>{jt(e,n.deletions,i=>{i instanceof O&&t.scope.some(s=>s===e.doc||ke(s,i))&&Vi(i,!1)})},ws=(e,t,n)=>{let i=null;const s=e.doc,r=e.scope;j(s,l=>{for(;t.length>0&&e.currStackItem===null;){const c=s.store,a=t.pop(),u=new Set,h=[];let f=!1;jt(l,a.insertions,p=>{if(p instanceof O){if(p.redone!==null){let{item:g,diff:x}=fi(c,p.id);x>0&&(g=it(l,_(g.id.client,g.id.clock+x))),p=g}!p.deleted&&r.some(g=>g===l.doc||ke(g,p))&&h.push(p)}}),jt(l,a.deletions,p=>{p instanceof O&&r.some(g=>g===l.doc||ke(g,p))&&!ae(a.insertions,p.id)&&u.add(p)}),u.forEach(p=>{f=io(l,p,u,a.insertions,e.ignoreRemoteMapChanges,e)!==null||f});for(let p=h.length-1;p>=0;p--){const g=h[p];e.deleteFilter(g)&&(g.delete(l),f=!0)}e.currStackItem=f?a:null}l.changed.forEach((c,a)=>{c.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),i=l},e);const o=e.currStackItem;if(o!=null){const l=i.changedParentTypes;e.emit("stack-item-popped",[{stackItem:o,type:n,changedParentTypes:l,origin:e},e]),e.currStackItem=null}return o};class Pr extends Ws{constructor(t,{captureTimeout:n=500,captureTransaction:i=c=>!0,deleteFilter:s=()=>!0,trackedOrigins:r=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:l=te(t)?t[0].doc:t instanceof zt?t:t.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(t),this.deleteFilter=s,r.add(this),this.trackedOrigins=r,this.captureTransaction=i,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=n,this.afterTransactionHandler=c=>{if(!this.captureTransaction(c)||!this.scope.some(w=>c.changedParentTypes.has(w)||w===this.doc)||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;const a=this.undoing,u=this.redoing,h=a?this.redoStack:this.undoStack;a?this.stopCapturing():u||this.clear(!1,!0);const f=new ce;c.afterState.forEach((w,y)=>{const C=c.beforeState.get(y)||0,S=w-C;S>0&&Se(f,y,C,S)});const p=Bc();let g=!1;if(this.lastChange>0&&p-this.lastChange<this.captureTimeout&&h.length>0&&!a&&!u){const w=h[h.length-1];w.deletions=ci([w.deletions,c.deleteSet]),w.insertions=ci([w.insertions,f])}else h.push(new mh(c.deleteSet,f)),g=!0;!a&&!u&&(this.lastChange=p),jt(c,c.deleteSet,w=>{w instanceof O&&this.scope.some(y=>y===c.doc||ke(y,w))&&Vi(w,!0)});const x=[{stackItem:h[h.length-1],origin:c.origin,type:a?"redo":"undo",changedParentTypes:c.changedParentTypes},this];g?this.emit("stack-item-added",x):this.emit("stack-item-updated",x)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){const n=new Set(this.scope);t=te(t)?t:[t],t.forEach(i=>{n.has(i)||(n.add(i),(i instanceof G?i.doc!==this.doc:i!==this.doc)&&_r("[yjs#509] Not same Y.Doc"),this.scope.push(i))})}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,n=!0){(t&&this.canUndo()||n&&this.canRedo())&&this.doc.transact(i=>{t&&(this.undoStack.forEach(s=>bs(i,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>bs(i,this,s)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let t;try{t=ws(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=ws(this,this.redoStack,"redo")}finally{this.redoing=!1}return t}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}}function*xh(e){const t=R(e.restDecoder);for(let n=0;n<t;n++){const i=R(e.restDecoder),s=e.readClient();let r=R(e.restDecoder);for(let o=0;o<i;o++){const l=e.readInfo();if(l===10){const c=R(e.restDecoder);yield new ht(_(s,r),c),r+=c}else if((mn&l)!==0){const c=(l&(Et|tt))===0,a=new O(_(s,r),null,(l&tt)===tt?e.readLeftID():null,null,(l&Et)===Et?e.readRightID():null,c?e.readParentInfo()?e.readString():e.readLeftID():null,c&&(l&xe)===xe?e.readString():null,so(e,l));yield a,r+=a.length}else{const c=e.readLen();yield new ct(_(s,r),c),r+=c}}}}class bh{constructor(t,n){this.gen=xh(t),this.curr=null,this.done=!1,this.filterSkips=n,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===ht);return this.curr}}class wh{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const yh=(e,t)=>{if(e.constructor===ct){const{client:n,clock:i}=e.id;return new ct(_(n,i+t),e.length-t)}else if(e.constructor===ht){const{client:n,clock:i}=e.id;return new ht(_(n,i+t),e.length-t)}else{const n=e,{client:i,clock:s}=n.id;return new O(_(i,s+t),null,_(i,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},ys=(e,t=rn,n=En)=>{if(e.length===1)return e[0];const i=e.map(u=>new t(Ei(u)));let s=i.map(u=>new bh(u,!0)),r=null;const o=new n,l=new wh(o);for(;s=s.filter(f=>f.curr!==null),s.sort((f,p)=>{if(f.curr.id.client===p.curr.id.client){const g=f.curr.id.clock-p.curr.id.clock;return g===0?f.curr.constructor===p.curr.constructor?0:f.curr.constructor===ht?1:-1:g}else return p.curr.id.client-f.curr.id.client}),s.length!==0;){const u=s[0],h=u.curr.id.client;if(r!==null){let f=u.curr,p=!1;for(;f!==null&&f.id.clock+f.length<=r.struct.id.clock+r.struct.length&&f.id.client>=r.struct.id.client;)f=u.next(),p=!0;if(f===null||f.id.client!==h||p&&f.id.clock>r.struct.id.clock+r.struct.length)continue;if(h!==r.struct.id.client)pe(l,r.struct,r.offset),r={struct:f,offset:0},u.next();else if(r.struct.id.clock+r.struct.length<f.id.clock)if(r.struct.constructor===ht)r.struct.length=f.id.clock+f.length-r.struct.id.clock;else{pe(l,r.struct,r.offset);const g=f.id.clock-r.struct.id.clock-r.struct.length;r={struct:new ht(_(h,r.struct.id.clock+r.struct.length),g),offset:0}}else{const g=r.struct.id.clock+r.struct.length-f.id.clock;g>0&&(r.struct.constructor===ht?r.struct.length-=g:f=yh(f,g)),r.struct.mergeWith(f)||(pe(l,r.struct,r.offset),r={struct:f,offset:0},u.next())}}else r={struct:u.curr,offset:0},u.next();for(let f=u.curr;f!==null&&f.id.client===h&&f.id.clock===r.struct.id.clock+r.struct.length&&f.constructor!==ht;f=u.next())pe(l,r.struct,r.offset),r={struct:f,offset:0}}r!==null&&(pe(l,r.struct,r.offset),r=null),vh(l);const c=i.map(u=>Ja(u)),a=ci(c);return Bi(o,a),o.toUint8Array()},Ur=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:ut(e.encoder.restEncoder)}),e.encoder.restEncoder=Ie(),e.written=0)},pe=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Ur(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),I(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},vh=e=>{Ur(e);const t=e.encoder.restEncoder;I(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const i=e.clientStructs[n];I(t,i.written),xn(t,i.restEncoder)}},vs="You must not compute changes after the event-handler fired.";class Tn{constructor(t,n){this.target=t,this.currentTarget=t,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Sh(this.currentTarget,this.target))}deletes(t){return ae(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw vt(vs);const t=new Map,n=this.target;this.transaction.changed.get(n).forEach(s=>{if(s!==null){const r=n._map.get(s);let o,l;if(this.adds(r)){let c=r.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(r))if(c!==null&&this.deletes(c))o="delete",l=Pn(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Pn(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(r))o="delete",l=Pn(r.content.getContent());else return;t.set(s,{action:o,oldValue:l})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw vt(vs);const n=this.target,i=Ut(),s=Ut(),r=[];if(t={added:i,deleted:s,delta:r,keys:this.keys},this.transaction.changed.get(n).has(null)){let l=null;const c=()=>{l&&r.push(l)};for(let a=n._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((l===null||l.delete===void 0)&&(c(),l={delete:0}),l.delete+=a.length,s.add(a)):this.adds(a)?((l===null||l.insert===void 0)&&(c(),l={insert:[]}),l.insert=l.insert.concat(a.content.getContent()),i.add(a)):((l===null||l.retain===void 0)&&(c(),l={retain:0}),l.retain+=a.length);l!==null&&l.retain===void 0&&c()}this._changes=t}return t}}const Sh=(e,t)=>{const n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let i=0,s=t._item.parent._start;for(;s!==t._item&&s!==null;)!s.deleted&&s.countable&&(i+=s.length),s=s.right;n.unshift(i)}t=t._item.parent}return n},X=()=>{_r("Invalid access: Add Yjs type to a document before reading data.")},$r=80;let Pi=0;class Ch{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=Pi++}}const kh=e=>{e.timestamp=Pi++},Fr=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Pi++},Eh=(e,t,n)=>{if(e.length>=$r){const i=e.reduce((s,r)=>s.timestamp<r.timestamp?s:r);return Fr(i,t,n),i}else{const i=new Ch(t,n);return e.push(i),i}},Dn=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;const n=e._searchMarker.length===0?null:e._searchMarker.reduce((r,o)=>He(t-r.index)<He(t-o.index)?r:o);let i=e._start,s=0;for(n!==null&&(i=n.p,s=n.index,kh(n));i.right!==null&&s<t;){if(!i.deleted&&i.countable){if(t<s+i.length)break;s+=i.length}i=i.right}for(;i.left!==null&&s>t;)i=i.left,!i.deleted&&i.countable&&(s-=i.length);for(;i.left!==null&&i.left.id.client===i.id.client&&i.left.id.clock+i.left.length===i.id.clock;)i=i.left,!i.deleted&&i.countable&&(s-=i.length);return n!==null&&He(n.index-s)<i.parent.length/$r?(Fr(n,i,s),n):Eh(e._searchMarker,i,s)},Ee=(e,t,n)=>{for(let i=e.length-1;i>=0;i--){const s=e[i];if(n>0){let r=s.p;for(r.marker=!1;r&&(r.deleted||!r.countable);)r=r.left,r&&!r.deleted&&r.countable&&(s.index-=r.length);if(r===null||r.marker===!0){e.splice(i,1);continue}s.p=r,r.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=Ot(t,s.index+n))}},An=(e,t,n)=>{const i=e,s=t.changedParentTypes;for(;Tt(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Or(i._eH,n,t)};class G{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ds(),this._dEH=ds(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw at()}clone(){throw at()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,n){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){fs(this._eH,t)}observeDeep(t){fs(this._dEH,t)}unobserve(t){ps(this._eH,t)}unobserveDeep(t){ps(this._dEH,t)}toJSON(){}}const Vr=(e,t,n)=>{e.doc??X(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let i=n-t;const s=[];let r=e._start;for(;r!==null&&i>0;){if(r.countable&&!r.deleted){const o=r.content.getContent();if(o.length<=t)t-=o.length;else{for(let l=t;l<o.length&&i>0;l++)s.push(o[l]),i--;t=0}}r=r.right}return s},Hr=e=>{e.doc??X();const t=[];let n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){const i=n.content.getContent();for(let s=0;s<i.length;s++)t.push(i[s])}n=n.right}return t},zr=(e,t)=>{const n=[];let i=e._start;for(;i!==null;){if(i.countable&&Bt(i,t)){const s=i.content.getContent();for(let r=0;r<s.length;r++)n.push(s[r])}i=i.right}return n},_e=(e,t)=>{let n=0,i=e._start;for(e.doc??X();i!==null;){if(i.countable&&!i.deleted){const s=i.content.getContent();for(let r=0;r<s.length;r++)t(s[r],n++,e)}i=i.right}},Kr=(e,t)=>{const n=[];return _e(e,(i,s)=>{n.push(t(i,s,e))}),n},_h=e=>{let t=e._start,n=null,i=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),i=0,t=t.right}const s=n[i++];return n.length<=i&&(n=null),{done:!1,value:s}}}},qr=(e,t)=>{e.doc??X();const n=Dn(e,t);let i=e._start;for(n!==null&&(i=n.p,t-=n.index);i!==null;i=i.right)if(!i.deleted&&i.countable){if(t<i.length)return i.content.getContent()[t];t-=i.length}},ln=(e,t,n,i)=>{let s=n;const r=e.doc,o=r.clientID,l=r.store,c=n===null?t._start:n.right;let a=[];const u=()=>{a.length>0&&(s=new O(_(o,$(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new Vt(a)),s.integrate(e,0),a=[])};i.forEach(h=>{if(h===null)a.push(h);else switch(h.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(h);break;default:switch(u(),h.constructor){case Uint8Array:case ArrayBuffer:s=new O(_(o,$(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new Oe(new Uint8Array(h))),s.integrate(e,0);break;case zt:s=new O(_(o,$(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new je(h)),s.integrate(e,0);break;default:if(h instanceof G)s=new O(_(o,$(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new xt(h)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),u()},Wr=()=>vt("Length exceeded!"),Gr=(e,t,n,i)=>{if(n>t._length)throw Wr();if(n===0)return t._searchMarker&&Ee(t._searchMarker,n,i.length),ln(e,t,null,i);const s=n,r=Dn(t,n);let o=t._start;for(r!==null&&(o=r.p,n-=r.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&it(e,_(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&Ee(t._searchMarker,s,i.length),ln(e,t,o,i)},Th=(e,t,n)=>{let s=(t._searchMarker||[]).reduce((r,o)=>o.index>r.index?o:r,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return ln(e,t,s,n)},Yr=(e,t,n,i)=>{if(i===0)return;const s=n,r=i,o=Dn(t,n);let l=t._start;for(o!==null&&(l=o.p,n-=o.index);l!==null&&n>0;l=l.right)!l.deleted&&l.countable&&(n<l.length&&it(e,_(l.id.client,l.id.clock+n)),n-=l.length);for(;i>0&&l!==null;)l.deleted||(i<l.length&&it(e,_(l.id.client,l.id.clock+i)),l.delete(e),i-=l.length),l=l.right;if(i>0)throw Wr();t._searchMarker&&Ee(t._searchMarker,s,-r+i)},cn=(e,t,n)=>{const i=t._map.get(n);i!==void 0&&i.delete(e)},Ui=(e,t,n,i)=>{const s=t._map.get(n)||null,r=e.doc,o=r.clientID;let l;if(i==null)l=new Vt([i]);else switch(i.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new Vt([i]);break;case Uint8Array:l=new Oe(i);break;case zt:l=new je(i);break;default:if(i instanceof G)l=new xt(i);else throw new Error("Unexpected content type")}new O(_(o,$(r.store,o)),s,s&&s.lastId,null,null,t,n,l).integrate(e,0)},$i=(e,t)=>{e.doc??X();const n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Jr=e=>{const t={};return e.doc??X(),e._map.forEach((n,i)=>{n.deleted||(t[i]=n.content.getContent()[n.length-1])}),t},Xr=(e,t)=>{e.doc??X();const n=e._map.get(t);return n!==void 0&&!n.deleted},Dh=(e,t)=>{const n={};return e._map.forEach((i,s)=>{let r=i;for(;r!==null&&(!t.sv.has(r.id.client)||r.id.clock>=(t.sv.get(r.id.client)||0));)r=r.left;r!==null&&Bt(r,t)&&(n[s]=r.content.getContent()[r.length-1])}),n},Pe=e=>(e.doc??X(),Wa(e._map.entries(),t=>!t[1].deleted));class Ah extends Tn{}class Qt extends G{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new Qt;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Qt}clone(){const t=new Qt;return t.insert(0,this.toArray().map(n=>n instanceof G?n.clone():n)),t}get length(){return this.doc??X(),this._length}_callObserver(t,n){super._callObserver(t,n),An(this,t,new Ah(this,t))}insert(t,n){this.doc!==null?j(this.doc,i=>{Gr(i,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?j(this.doc,n=>{Th(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?j(this.doc,i=>{Yr(i,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return qr(this,t)}toArray(){return Hr(this)}slice(t=0,n=this.length){return Vr(this,t,n)}toJSON(){return this.map(t=>t instanceof G?t.toJSON():t)}map(t){return Kr(this,t)}forEach(t){_e(this,t)}[Symbol.iterator](){return _h(this)}_write(t){t.writeTypeRef(tu)}}const Ih=e=>new Qt;class Mh extends Tn{constructor(t,n,i){super(t,n),this.keysChanged=i}}class re extends G{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach((i,s)=>{this.set(s,i)}),this._prelimContent=null}_copy(){return new re}clone(){const t=new re;return this.forEach((n,i)=>{t.set(i,n instanceof G?n.clone():n)}),t}_callObserver(t,n){An(this,t,new Mh(this,t,n))}toJSON(){this.doc??X();const t={};return this._map.forEach((n,i)=>{if(!n.deleted){const s=n.content.getContent()[n.length-1];t[i]=s instanceof G?s.toJSON():s}}),t}get size(){return[...Pe(this)].length}keys(){return Kn(Pe(this),t=>t[0])}values(){return Kn(Pe(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Kn(Pe(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??X(),this._map.forEach((n,i)=>{n.deleted||t(n.content.getContent()[n.length-1],i,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?j(this.doc,n=>{cn(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?j(this.doc,i=>{Ui(i,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return $i(this,t)}has(t){return Xr(this,t)}clear(){this.doc!==null?j(this.doc,t=>{this.forEach(function(n,i,s){cn(t,s,i)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(eu)}}const Oh=e=>new re,It=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&zc(e,t);class di{constructor(t,n,i,s){this.left=t,this.right=n,this.index=i,this.currentAttributes=s}forward(){switch(this.right===null&&et(),this.right.content.constructor){case F:this.right.deleted||he(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}}const Ss=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case F:t.right.deleted||he(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&it(e,_(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length);break}t.left=t.right,t.right=t.right.right}return t},Ue=(e,t,n,i)=>{const s=new Map,r=i?Dn(t,n):null;if(r){const o=new di(r.p.left,r.p,r.index,s);return Ss(e,o,n-r.index)}else{const o=new di(null,t._start,0,s);return Ss(e,o,n)}},Zr=(e,t,n,i)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===F&&It(i.get(n.right.content.key),n.right.content.value));)n.right.deleted||i.delete(n.right.content.key),n.forward();const s=e.doc,r=s.clientID;i.forEach((o,l)=>{const c=n.left,a=n.right,u=new O(_(r,$(s.store,r)),c,c&&c.lastId,a,a&&a.id,t,null,new F(l,o));u.integrate(e,0),n.right=u,n.forward()})},he=(e,t)=>{const{key:n,value:i}=t;i===null?e.delete(n):e.set(n,i)},Qr=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===F&&It(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},to=(e,t,n,i)=>{const s=e.doc,r=s.clientID,o=new Map;for(const l in i){const c=i[l],a=n.currentAttributes.get(l)??null;if(!It(a,c)){o.set(l,a);const{left:u,right:h}=n;n.right=new O(_(r,$(s.store,r)),u,u&&u.lastId,h,h&&h.id,t,null,new F(l,c)),n.right.integrate(e,0),n.forward()}}return o},Gn=(e,t,n,i,s)=>{n.currentAttributes.forEach((f,p)=>{s[p]===void 0&&(s[p]=null)});const r=e.doc,o=r.clientID;Qr(n,s);const l=to(e,t,n,s),c=i.constructor===String?new mt(i):i instanceof G?new xt(i):new Kt(i);let{left:a,right:u,index:h}=n;t._searchMarker&&Ee(t._searchMarker,n.index,c.getLength()),u=new O(_(o,$(r.store,o)),a,a&&a.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=h,n.forward(),Zr(e,t,n,l)},Cs=(e,t,n,i,s)=>{const r=e.doc,o=r.clientID;Qr(n,s);const l=to(e,t,n,s);t:for(;n.right!==null&&(i>0||l.size>0&&(n.right.deleted||n.right.content.constructor===F));){if(!n.right.deleted)switch(n.right.content.constructor){case F:{const{key:c,value:a}=n.right.content,u=s[c];if(u!==void 0){if(It(u,a))l.delete(c);else{if(i===0)break t;l.set(c,a)}n.right.delete(e)}else n.currentAttributes.set(c,a);break}default:i<n.right.length&&it(e,_(n.right.id.client,n.right.id.clock+i)),i-=n.right.length;break}n.forward()}if(i>0){let c="";for(;i>0;i--)c+=`
5
- `;n.right=new O(_(o,$(r.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new mt(c)),n.right.integrate(e,0),n.forward()}Zr(e,t,n,l)},eo=(e,t,n,i,s)=>{let r=t;const o=ft();for(;r&&(!r.countable||r.deleted);){if(!r.deleted&&r.content.constructor===F){const a=r.content;o.set(a.key,a)}r=r.right}let l=0,c=!1;for(;t!==r;){if(n===t&&(c=!0),!t.deleted){const a=t.content;switch(a.constructor){case F:{const{key:u,value:h}=a,f=i.get(u)??null;(o.get(u)!==a||f===h)&&(t.delete(e),l++,!c&&(s.get(u)??null)===h&&f!==h&&(f===null?s.delete(u):s.set(u,f))),!c&&!t.deleted&&he(s,a);break}}}t=t.right}return l},jh=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===F){const i=t.content.key;n.has(i)?t.delete(e):n.add(i)}t=t.left}},Rh=e=>{let t=0;return j(e.doc,n=>{let i=e._start,s=e._start,r=ft();const o=ei(r);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case F:he(o,s.content);break;default:t+=eo(n,i,s,r,o),r=ei(o),i=s;break}s=s.right}}),t},Nh=e=>{const t=new Set,n=e.doc;for(const[i,s]of e.afterState.entries()){const r=e.beforeState.get(i)||0;s!==r&&Br(e,n.store.clients.get(i),r,s,o=>{!o.deleted&&o.content.constructor===F&&o.constructor!==ct&&t.add(o.parent)})}j(n,i=>{jt(e,e.deleteSet,s=>{if(s instanceof ct||!s.parent._hasFormatting||t.has(s.parent))return;const r=s.parent;s.content.constructor===F?t.add(r):jh(i,s)});for(const s of t)Rh(s)})},ks=(e,t,n)=>{const i=n,s=ei(t.currentAttributes),r=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case xt:case Kt:case mt:n<t.right.length&&it(e,_(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}r&&eo(e,r,t.right,s,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&Ee(o._searchMarker,t.index,-i+n),t};class Bh extends Tn{constructor(t,n,i){super(t,n),this.childListChanged=!1,this.keysChanged=new Set,i.forEach(s=>{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}get changes(){if(this._changes===null){const t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){const t=this.target.doc,n=[];j(t,i=>{const s=new Map,r=new Map;let o=this.target._start,l=null;const c={};let a="",u=0,h=0;const f=()=>{if(l!==null){let p=null;switch(l){case"delete":h>0&&(p={delete:h}),h=0;break;case"insert":(typeof a=="object"||a.length>0)&&(p={insert:a},s.size>0&&(p.attributes={},s.forEach((g,x)=>{g!==null&&(p.attributes[x]=g)}))),a="";break;case"retain":u>0&&(p={retain:u},Hc(c)||(p.attributes=Fc({},c))),u=0;break}p&&n.push(p),l=null}};for(;o!==null;){switch(o.content.constructor){case xt:case Kt:this.adds(o)?this.deletes(o)||(f(),l="insert",a=o.content.getContent()[0],f()):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),h+=1):o.deleted||(l!=="retain"&&(f(),l="retain"),u+=1);break;case mt:this.adds(o)?this.deletes(o)||(l!=="insert"&&(f(),l="insert"),a+=o.content.str):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),h+=o.length):o.deleted||(l!=="retain"&&(f(),l="retain"),u+=o.length);break;case F:{const{key:p,value:g}=o.content;if(this.adds(o)){if(!this.deletes(o)){const x=s.get(p)??null;It(x,g)?g!==null&&o.delete(i):(l==="retain"&&f(),It(g,r.get(p)??null)?delete c[p]:c[p]=g)}}else if(this.deletes(o)){r.set(p,g);const x=s.get(p)??null;It(x,g)||(l==="retain"&&f(),c[p]=x)}else if(!o.deleted){r.set(p,g);const x=c[p];x!==void 0&&(It(x,g)?x!==null&&o.delete(i):(l==="retain"&&f(),g===null?delete c[p]:c[p]=g))}o.deleted||(l==="insert"&&f(),he(s,o.content));break}}o=o.right}for(f();n.length>0;){const p=n[n.length-1];if(p.retain!==void 0&&p.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class Rt extends G{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??X(),this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach(i=>i())}catch(i){console.error(i)}this._pending=null}_copy(){return new Rt}clone(){const t=new Rt;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const i=new Bh(this,t,n);An(this,t,i),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??X();let t="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===mt&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){this.doc!==null?j(this.doc,i=>{const s=new di(null,this._start,0,new Map);for(let r=0;r<t.length;r++){const o=t[r];if(o.insert!==void 0){const l=!n&&typeof o.insert=="string"&&r===t.length-1&&s.right===null&&o.insert.slice(-1)===`
6
- `?o.insert.slice(0,-1):o.insert;(typeof l!="string"||l.length>0)&&Gn(i,this,s,l,o.attributes||{})}else o.retain!==void 0?Cs(i,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&ks(i,s,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,i){this.doc??X();const s=[],r=new Map,o=this.doc;let l="",c=this._start;function a(){if(l.length>0){const h={};let f=!1;r.forEach((g,x)=>{f=!0,h[x]=g});const p={insert:l};f&&(p.attributes=h),s.push(p),l=""}}const u=()=>{for(;c!==null;){if(Bt(c,t)||n!==void 0&&Bt(c,n))switch(c.content.constructor){case mt:{const h=r.get("ychange");t!==void 0&&!Bt(c,t)?(h===void 0||h.user!==c.id.client||h.type!=="removed")&&(a(),r.set("ychange",i?i("removed",c.id):{type:"removed"})):n!==void 0&&!Bt(c,n)?(h===void 0||h.user!==c.id.client||h.type!=="added")&&(a(),r.set("ychange",i?i("added",c.id):{type:"added"})):h!==void 0&&(a(),r.delete("ychange")),l+=c.content.str;break}case xt:case Kt:{a();const h={insert:c.content.getContent()[0]};if(r.size>0){const f={};h.attributes=f,r.forEach((p,g)=>{f[g]=p})}s.push(h);break}case F:Bt(c,t)&&(a(),he(r,c.content));break}c=c.right}a()};return t||n?j(o,h=>{t&&hi(h,t),n&&hi(h,n),u()},"cleanup"):u(),s}insert(t,n,i){if(n.length<=0)return;const s=this.doc;s!==null?j(s,r=>{const o=Ue(r,this,t,!i);i||(i={},o.currentAttributes.forEach((l,c)=>{i[c]=l})),Gn(r,this,o,n,i)}):this._pending.push(()=>this.insert(t,n,i))}insertEmbed(t,n,i){const s=this.doc;s!==null?j(s,r=>{const o=Ue(r,this,t,!i);Gn(r,this,o,n,i||{})}):this._pending.push(()=>this.insertEmbed(t,n,i||{}))}delete(t,n){if(n===0)return;const i=this.doc;i!==null?j(i,s=>{ks(s,Ue(s,this,t,!0),n)}):this._pending.push(()=>this.delete(t,n))}format(t,n,i){if(n===0)return;const s=this.doc;s!==null?j(s,r=>{const o=Ue(r,this,t,!1);o.right!==null&&Cs(r,this,o,n,i)}):this._pending.push(()=>this.format(t,n,i))}removeAttribute(t){this.doc!==null?j(this.doc,n=>{cn(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?j(this.doc,i=>{Ui(i,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return $i(this,t)}getAttributes(){return Jr(this)}_write(t){t.writeTypeRef(nu)}}const Lh=e=>new Rt;class Yn{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??X()}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(n)))do if(n=t.content.type,!t.deleted&&(n.constructor===Q||n.constructor===Ft)&&n._start!==null)t=n._start;else for(;t!==null;){const i=t.next;if(i!==null){t=i;break}else t.parent===this._root?t=null:t=t.parent._item}while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class Ft extends G{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Ft}clone(){const t=new Ft;return t.insert(0,this.toArray().map(n=>n instanceof G?n.clone():n)),t}get length(){return this.doc??X(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Yn(this,t)}querySelector(t){t=t.toUpperCase();const i=new Yn(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return i.done?null:i.value}querySelectorAll(t){return t=t.toUpperCase(),$t(new Yn(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){An(this,t,new $h(this,n,t))}toString(){return Kr(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},i){const s=t.createDocumentFragment();return i!==void 0&&i._createAssociation(s,this),_e(this,r=>{s.insertBefore(r.toDOM(t,n,i),null)}),s}insert(t,n){this.doc!==null?j(this.doc,i=>{Gr(i,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)j(this.doc,i=>{const s=t&&t instanceof G?t._item:t;ln(i,this,s,n)});else{const i=this._prelimContent,s=t===null?0:i.findIndex(r=>r===t)+1;if(s===0&&t!==null)throw vt("Reference item not found");i.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?j(this.doc,i=>{Yr(i,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return Hr(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return qr(this,t)}slice(t=0,n=this.length){return Vr(this,t,n)}forEach(t){_e(this,t)}_write(t){t.writeTypeRef(su)}}const Ph=e=>new Ft;class Q extends Ft{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach((i,s)=>{this.setAttribute(s,i)}),this._prelimAttrs=null}_copy(){return new Q(this.nodeName)}clone(){const t=new Q(this.nodeName),n=this.getAttributes();return Vc(n,(i,s)=>{t.setAttribute(s,i)}),t.insert(0,this.toArray().map(i=>i instanceof G?i.clone():i)),t}toString(){const t=this.getAttributes(),n=[],i=[];for(const l in t)i.push(l);i.sort();const s=i.length;for(let l=0;l<s;l++){const c=i[l];n.push(c+'="'+t[c]+'"')}const r=this.nodeName.toLocaleLowerCase(),o=n.length>0?" "+n.join(" "):"";return`<${r}${o}>${super.toString()}</${r}>`}removeAttribute(t){this.doc!==null?j(this.doc,n=>{cn(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?j(this.doc,i=>{Ui(i,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return $i(this,t)}hasAttribute(t){return Xr(this,t)}getAttributes(t){return t?Dh(this,t):Jr(this)}toDOM(t=document,n={},i){const s=t.createElement(this.nodeName),r=this.getAttributes();for(const o in r){const l=r[o];typeof l=="string"&&s.setAttribute(o,l)}return _e(this,o=>{s.appendChild(o.toDOM(t,n,i))}),i!==void 0&&i._createAssociation(s,this),s}_write(t){t.writeTypeRef(iu),t.writeKey(this.nodeName)}}const Uh=e=>new Q(e.readKey());class $h extends Tn{constructor(t,n,i){super(t,i),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}}class an extends re{constructor(t){super(),this.hookName=t}_copy(){return new an(this.hookName)}clone(){const t=new an(this.hookName);return this.forEach((n,i)=>{t.set(i,n)}),t}toDOM(t=document,n={},i){const s=n[this.hookName];let r;return s!==void 0?r=s.createDom(this):r=document.createElement(this.hookName),r.setAttribute("data-yjs-hook",this.hookName),i!==void 0&&i._createAssociation(r,this),r}_write(t){t.writeTypeRef(ru),t.writeKey(this.hookName)}}const Fh=e=>new an(e.readKey());class rt extends Rt{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new rt}clone(){const t=new rt;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,i){const s=t.createTextNode(this.toString());return i!==void 0&&i._createAssociation(s,this),s}toString(){return this.toDelta().map(t=>{const n=[];for(const s in t.attributes){const r=[];for(const o in t.attributes[s])r.push({key:o,value:t.attributes[s][o]});r.sort((o,l)=>o.key<l.key?-1:1),n.push({nodeName:s,attrs:r})}n.sort((s,r)=>s.nodeName<r.nodeName?-1:1);let i="";for(let s=0;s<n.length;s++){const r=n[s];i+=`<${r.nodeName}`;for(let o=0;o<r.attrs.length;o++){const l=r.attrs[o];i+=` ${l.key}="${l.value}"`}i+=">"}i+=t.insert;for(let s=n.length-1;s>=0;s--)i+=`</${n[s].nodeName}>`;return i}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(ou)}}const Vh=e=>new rt;class Fi{constructor(t,n){this.id=t,this.length=n}get deleted(){throw at()}mergeWith(t){return!1}write(t,n,i){throw at()}integrate(t,n){throw at()}}const Hh=0;class ct extends Fi{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){n>0&&(this.id.clock+=n,this.length-=n),Nr(t.doc.store,this)}write(t,n){t.writeInfo(Hh),t.writeLen(this.length-n)}getMissing(t,n){return null}}class Oe{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Oe(this.content)}splice(t){throw at()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}const zh=e=>new Oe(e.readBuf());class Te{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Te(this.len)}splice(t){const n=new Te(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){Se(t.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(t){}gc(t){}write(t,n){t.writeLen(this.len-n)}getRef(){return 1}}const Kh=e=>new Te(e.readLen()),no=(e,t)=>new zt({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class je{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const n={};this.opts=n,t.gc||(n.gc=!1),t.autoLoad&&(n.autoLoad=!0),t.meta!==null&&(n.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new je(no(this.doc.guid,this.opts))}splice(t){throw at()}mergeWith(t){return!1}integrate(t,n){this.doc._item=n,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,n){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}const qh=e=>new je(no(e.readString(),e.readAny()));class Kt{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Kt(this.embed)}splice(t){throw at()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}const Wh=e=>new Kt(e.readJSON());class F{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new F(this.key,this.value)}splice(t){throw at()}mergeWith(t){return!1}integrate(t,n){const i=n.parent;i._searchMarker=null,i._hasFormatting=!0}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}const Gh=e=>new F(e.readKey(),e.readJSON());class hn{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new hn(this.arr)}splice(t){const n=new hn(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const i=this.arr.length;t.writeLen(i-n);for(let s=n;s<i;s++){const r=this.arr[s];t.writeString(r===void 0?"undefined":JSON.stringify(r))}}getRef(){return 2}}const Yh=e=>{const t=e.readLen(),n=[];for(let i=0;i<t;i++){const s=e.readString();s==="undefined"?n.push(void 0):n.push(JSON.parse(s))}return new hn(n)},Jh=tn("node_env")==="development";class Vt{constructor(t){this.arr=t,Jh&&nr(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Vt(this.arr)}splice(t){const n=new Vt(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const i=this.arr.length;t.writeLen(i-n);for(let s=n;s<i;s++){const r=this.arr[s];t.writeAny(r)}}getRef(){return 8}}const Xh=e=>{const t=e.readLen(),n=[];for(let i=0;i<t;i++)n.push(e.readAny());return new Vt(n)};class mt{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new mt(this.str)}splice(t){const n=new mt(this.str.slice(t));this.str=this.str.slice(0,t);const i=this.str.charCodeAt(t-1);return i>=55296&&i<=56319&&(this.str=this.str.slice(0,t-1)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(t){return this.str+=t.str,!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}}const Zh=e=>new mt(e.readString()),Qh=[Ih,Oh,Lh,Uh,Ph,Fh,Vh],tu=0,eu=1,nu=2,iu=3,su=4,ru=5,ou=6;class xt{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new xt(this.type._copy())}splice(t){throw at()}mergeWith(t){return!1}integrate(t,n){this.type._integrate(t.doc,n)}delete(t){let n=this.type._start;for(;n!==null;)n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t),n=n.right;this.type._map.forEach(i=>{i.deleted?i.id.clock<(t.beforeState.get(i.id.client)||0)&&t._mergeStructs.push(i):i.delete(t)}),t.changed.delete(this.type)}gc(t){let n=this.type._start;for(;n!==null;)n.gc(t,!0),n=n.right;this.type._start=null,this.type._map.forEach(i=>{for(;i!==null;)i.gc(t,!0),i=i.left}),this.type._map=new Map}write(t,n){this.type._write(t)}getRef(){return 7}}const lu=e=>new xt(Qh[e.readTypeRef()](e)),fi=(e,t)=>{let n=t,i=0,s;do i>0&&(n=_(n.client,n.clock+i)),s=Zt(e,n),i=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof O);return{item:s,diff:i}},Vi=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},un=(e,t,n)=>{const{client:i,clock:s}=t.id,r=new O(_(i,s+n),t,_(i,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&r.markDeleted(),t.keep&&(r.keep=!0),t.redone!==null&&(r.redone=_(t.redone.client,t.redone.clock+n)),t.right=r,r.right!==null&&(r.right.left=r),e._mergeStructs.push(r),r.parentSub!==null&&r.right===null&&r.parent._map.set(r.parentSub,r),t.length=n,r},Es=(e,t)=>Si(e,n=>ae(n.deletions,t)),io=(e,t,n,i,s,r)=>{const o=e.doc,l=o.store,c=o.clientID,a=t.redone;if(a!==null)return it(e,a);let u=t.parent._item,h=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||io(e,u,n,i,s,r)===null))return null;for(;u.redone!==null;)u=it(e,u.redone)}const p=u===null?t.parent:u.content.type;if(t.parentSub===null){for(h=t.left,f=t;h!==null;){let y=h;for(;y!==null&&y.parent._item!==u;)y=y.redone===null?null:it(e,y.redone);if(y!==null&&y.parent._item===u){h=y;break}h=h.left}for(;f!==null;){let y=f;for(;y!==null&&y.parent._item!==u;)y=y.redone===null?null:it(e,y.redone);if(y!==null&&y.parent._item===u){f=y;break}f=f.right}}else if(f=null,t.right&&!s){for(h=t;h!==null&&h.right!==null&&(h.right.redone||ae(i,h.right.id)||Es(r.undoStack,h.right.id)||Es(r.redoStack,h.right.id));)for(h=h.right;h.redone;)h=it(e,h.redone);if(h&&h.right!==null)return null}else h=p._map.get(t.parentSub)||null;const g=$(l,c),x=_(c,g),w=new O(x,h,h&&h.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=x,Vi(w,!0),w.integrate(e,0),w};class O extends Fi{constructor(t,n,i,s,r,o,l,c){super(t,c.getLength()),this.origin=i,this.left=n,this.right=s,this.rightOrigin=r,this.parent=o,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?Qi:0}set marker(t){(this.info&$n)>0!==t&&(this.info^=$n)}get marker(){return(this.info&$n)>0}get keep(){return(this.info&Zi)>0}set keep(t){this.keep!==t&&(this.info^=Zi)}get countable(){return(this.info&Qi)>0}get deleted(){return(this.info&Un)>0}set deleted(t){this.deleted!==t&&(this.info^=Un)}markDeleted(){this.info|=Un}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=$(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=$(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Xt&&this.id.client!==this.parent.client&&this.parent.clock>=$(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=gs(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=it(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===ct||this.right&&this.right.constructor===ct)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===O?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===O&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Xt){const i=Zt(n,this.parent);i.constructor===ct?this.parent=null:this.parent=i.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=gs(t,t.doc.store,_(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let i=this.left,s;if(i!==null)s=i.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;const r=new Set,o=new Set;for(;s!==null&&s!==this.right;){if(o.add(s),r.add(s),Be(this.origin,s.origin)){if(s.id.client<this.id.client)i=s,r.clear();else if(Be(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&o.has(Zt(t.doc.store,s.origin)))r.has(Zt(t.doc.store,s.origin))||(i=s,r.clear());else break;s=s.right}this.left=i}if(this.left!==null){const i=this.left.right;this.right=i,this.left.right=this}else{let i;if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start,this.parent._start=this;this.right=i}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Nr(t.doc.store,this),this.content.integrate(t,this),xs(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new ct(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;t!==null&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;t!==null&&t.deleted;)t=t.left;return t}get lastId(){return this.length===1?this.id:_(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Be(t.origin,this.lastId)&&this.right===t&&Be(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const n=this.parent._searchMarker;return n&&n.forEach(i=>{i.p===t&&(i.p=this,!this.deleted&&this.countable&&(i.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),Se(t.deleteSet,this.id.client,this.id.clock,this.length),xs(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw et();this.content.gc(t),n?dh(t,this,new ct(this.id,this.length)):this.content=new Te(this.length)}write(t,n){const i=n>0?_(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,r=this.parentSub,o=this.content.getRef()&mn|(i===null?0:tt)|(s===null?0:Et)|(r===null?0:xe);if(t.writeInfo(o),i!==null&&t.writeLeftID(i),s!==null&&t.writeRightID(s),i===null&&s===null){const l=this.parent;if(l._item!==void 0){const c=l._item;if(c===null){const a=Ce(l);t.writeParentInfo(!0),t.writeString(a)}else t.writeParentInfo(!1),t.writeLeftID(c.id)}else l.constructor===String?(t.writeParentInfo(!0),t.writeString(l)):l.constructor===Xt?(t.writeParentInfo(!1),t.writeLeftID(l)):et();r!==null&&t.writeString(r)}this.content.write(t,n)}}const so=(e,t)=>cu[t&mn](e),cu=[()=>{et()},Kh,Yh,zh,Zh,Wh,Gh,lu,Xh,qh,()=>{et()}],au=10;class ht extends Fi{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){et()}write(t,n){t.writeInfo(au),I(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const ro=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},oo="__ $YJS$ __";ro[oo]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");ro[oo]=!0;const hu=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},uu=/[\uD800-\uDBFF]/,du=/[\uDC00-\uDFFF]/,fu=(e,t)=>{let n=0,i=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&uu.test(e[n-1])&&n--;i+n<e.length&&i+n<t.length&&e[e.length-i-1]===t[t.length-i-1];)i++;return i>0&&du.test(e[e.length-i])&&i--,{index:n,remove:e.length-n-i,insert:t.slice(n,t.length-i)}},pu=fu,yt=(e,t)=>e>>>t|e<<32-t,gu=e=>yt(e,2)^yt(e,13)^yt(e,22),mu=e=>yt(e,6)^yt(e,11)^yt(e,25),xu=e=>yt(e,7)^yt(e,18)^e>>>3,bu=e=>yt(e,17)^yt(e,19)^e>>>10,wu=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),yu=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class vu{constructor(){const t=new ArrayBuffer(320);this._H=new Uint32Array(t,0,8),this._H.set(yu),this._W=new Uint32Array(t,64,64)}_updateHash(){const t=this._H,n=this._W;for(let h=16;h<64;h++)n[h]=bu(n[h-2])+n[h-7]+xu(n[h-15])+n[h-16];let i=t[0],s=t[1],r=t[2],o=t[3],l=t[4],c=t[5],a=t[6],u=t[7];for(let h=0,f,p;h<64;h++)f=u+mu(l)+(l&c^~l&a)+wu[h]+n[h]>>>0,p=gu(i)+(i&s^i&r^s&r)>>>0,u=a,a=c,c=l,l=o+f>>>0,o=r,r=s,s=i,i=f+p>>>0;t[0]+=i,t[1]+=s,t[2]+=r,t[3]+=o,t[4]+=l,t[5]+=c,t[6]+=a,t[7]+=u}digest(t){let n=0;for(;n+56<=t.length;){let o=0;for(;o<16&&n+3<t.length;o++)this._W[o]=t[n++]<<24|t[n++]<<16|t[n++]<<8|t[n++];if(n%64!==0){for(this._W.fill(0,o,16);n<t.length;)this._W[o]|=t[n]<<(3-n%4)*8,n++;this._W[o]|=tt<<(3-n%4)*8}this._updateHash()}const i=n%64!==0;this._W.fill(0,0,16);let s=0;for(;n<t.length;s++)for(let o=3;o>=0&&n<t.length;o--)this._W[s]|=t[n++]<<o*8;i||(this._W[s-(n%4===0?0:1)]|=tt<<(3-n%4)*8),this._W[14]=t.byteLength/tc,this._W[15]=t.byteLength*8,this._updateHash();const r=new Uint8Array(32);for(let o=0;o<this._H.length;o++)for(let l=0;l<4;l++)r[o*4+l]=this._H[o]>>>(3-l)*8;return r}}const Su=e=>new vu().digest(e),N=new T.PluginKey("y-sync"),_t=new T.PluginKey("y-undo");new T.PluginKey("yjs-cursor");const Cu=e=>{for(let n=6;n<e.length;n++)e[n%6]=e[n%6]^e[n];return e.slice(0,6)},ku=e=>Qc(Cu(Su(ta(e)))),dn=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!ae(t.ds,e.id),Eu=[{light:"#ecd44433",dark:"#ecd444"}],_u=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){const i=Ut();e.forEach(s=>i.add(s)),t=t.filter(s=>!i.has(s))}e.set(n,jc(t))}return e.get(n)},Tu=(e,{colors:t=Eu,colorMapping:n=new Map,permanentUserData:i=null,onFirstRender:s=()=>{},mapping:r}={})=>{let o=!1;const l=new Iu(e,r),c=new T.Plugin({props:{editable:a=>{const u=N.getState(a);return u.snapshot==null&&u.prevSnapshot==null}},key:N,state:{init:(a,u)=>({type:e,doc:e.doc,binding:l,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:t,colorMapping:n,permanentUserData:i}),apply:(a,u)=>{const h=a.getMeta(N);if(h!==void 0){u=Object.assign({},u);for(const f in h)u[f]=h[f]}return u.addToHistory=a.getMeta("addToHistory")!==!1,u.isChangeOrigin=h!==void 0&&!!h.isChangeOrigin,u.isUndoRedoOperation=h!==void 0&&!!h.isChangeOrigin&&!!h.isUndoRedoOperation,l.prosemirrorView!==null&&h!==void 0&&(h.snapshot!=null||h.prevSnapshot!=null)&&vr(0,()=>{l.prosemirrorView!=null&&(h.restore==null?l._renderSnapshot(h.snapshot,h.prevSnapshot,u):(l._renderSnapshot(h.snapshot,h.snapshot,u),delete u.restore,delete u.snapshot,delete u.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),u}},view:a=>(l.initView(a),r==null&&l._forceRerender(),s(),{update:()=>{const u=c.getState(a.state);if(u.snapshot==null&&u.prevSnapshot==null&&(o||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(o=!0,u.addToHistory===!1&&!u.isChangeOrigin){const h=_t.getState(a.state),f=h&&h.undoManager;f&&f.stopCapturing()}l.mux(()=>{u.doc.transact(h=>{h.meta.set("addToHistory",u.addToHistory),l._prosemirrorChanged(a.state.doc)},N)})}},destroy:()=>{l.destroy()}})});return c},Du=(e,t,n)=>{if(t!==null&&t.anchor!==null&&t.head!==null)if(t.type==="all")e.setSelection(new T.AllSelection(e.doc));else if(t.type==="node"){const i=me(n.doc,n.type,t.anchor,n.mapping);e.setSelection(Au(e,i))}else{const i=me(n.doc,n.type,t.anchor,n.mapping),s=me(n.doc,n.type,t.head,n.mapping);i!==null&&s!==null&&e.setSelection(T.TextSelection.between(e.doc.resolve(i),e.doc.resolve(s)))}},Au=(e,t)=>{const n=e.doc.resolve(t);return n.nodeAfter?T.NodeSelection.create(e.doc,t):T.TextSelection.near(n)},pi=(e,t)=>({type:t.selection.jsonID,anchor:pn(t.selection.anchor,e.type,e.mapping),head:pn(t.selection.head,e.type,e.mapping)});class Iu{constructor(t,n=new Map){this.type=t,this.prosemirrorView=null,this.mux=hu(),this.mapping=n,this.isOMark=new Map,this._observeFunction=this._typeChanged.bind(this),this.doc=t.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=pi(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return this.prosemirrorView.hasFocus()?(ir&&this._domSelectionInView===null&&(vr(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){const t=this.prosemirrorView._root.getSelection();if(t==null||t.anchorNode==null)return!1;const n=this.prosemirrorView._root.createRange();n.setStart(t.anchorNode,t.anchorOffset),n.setEnd(t.focusNode,t.focusOffset),n.getClientRects().length===0&&n.startContainer&&n.collapsed&&n.selectNodeContents(n.startContainer);const s=n.getBoundingClientRect(),r=Me.documentElement;return s.bottom>=0&&s.right>=0&&s.left<=(window.innerWidth||r.clientWidth||0)&&s.top<=(window.innerHeight||r.clientHeight||0)}renderSnapshot(t,n){n||(n=jr(Ar(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(N,{snapshot:t,prevSnapshot:n}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{const t=this.type.toArray().map(i=>Ge(i,this.prosemirrorView.state.schema,this)).filter(i=>i!==null),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new T.Slice(T.Fragment.from(t),0,0));n.setMeta(N,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(n)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{const t=this.beforeTransactionSelection!==null?null:this.prosemirrorView.state.selection,n=this.type.toArray().map(s=>Ge(s,this.prosemirrorView.state.schema,this)).filter(s=>s!==null),i=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new T.Slice(T.Fragment.from(n),0,0));if(t){const s=ee(Ot(t.anchor,0),i.doc.content.size),r=ee(Ot(t.head,0),i.doc.content.size);i.setSelection(T.TextSelection.create(i.doc,s,r))}this.prosemirrorView.dispatch(i.setMeta(N,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(t,n,i){let s=this.doc,r=this.type;if(t||(t=Wn(this.doc)),t instanceof Uint8Array||n instanceof Uint8Array)if((!(t instanceof Uint8Array)||!(n instanceof Uint8Array))&&et(),s=new zt({gc:!1}),ai(s,n),n=Wn(s),ai(s,t),t=Wn(s),r._item===null){const o=Array.from(this.doc.share.keys()).find(l=>this.doc.share.get(l)===this.type);r=s.getXmlFragment(o)}else{const o=s.store.clients.get(r._item.id.client)??[],l=gt(o,r._item.id.clock);r=o[l].content.type}this.mapping.clear(),this.mux(()=>{s.transact(o=>{const l=i.permanentUserData;l&&l.dss.forEach(h=>{jt(o,h,f=>{})});const c=(h,f)=>{const p=h==="added"?l.getUserByClientId(f.client):l.getUserByDeletedId(f);return{user:p,type:h,color:_u(i.colorMapping,i.colors,p)}},a=zr(r,new Li(n.ds,t.sv)).map(h=>!h._item.deleted||dn(h._item,t)||dn(h._item,n)?Ge(h,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},t,n,c):null).filter(h=>h!==null),u=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new T.Slice(T.Fragment.from(a),0,0));this.prosemirrorView.dispatch(u.setMeta(N,{isChangeOrigin:!0}))},N)})}_typeChanged(t,n){if(this.prosemirrorView==null)return;const i=N.getState(this.prosemirrorView.state);if(t.length===0||i.snapshot!=null||i.prevSnapshot!=null){this.renderSnapshot(i.snapshot,i.prevSnapshot);return}this.mux(()=>{const s=(l,c)=>this.mapping.delete(c);jt(n,n.deleteSet,l=>{if(l.constructor===O){const c=l.content.type;c&&this.mapping.delete(c)}}),n.changed.forEach(s),n.changedParentTypes.forEach(s);const r=this.type.toArray().map(l=>lo(l,this.prosemirrorView.state.schema,this)).filter(l=>l!==null);let o=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new T.Slice(T.Fragment.from(r),0,0));Du(o,this.beforeTransactionSelection,this),o=o.setMeta(N,{isChangeOrigin:!0,isUndoRedoOperation:n.origin instanceof Pr}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)})}_prosemirrorChanged(t){this.doc.transact(()=>{mi(this.doc,this.type,t,this),this.beforeTransactionSelection=pi(this,this.prosemirrorView.state)},N)}initView(t){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=t,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}}const lo=(e,t,n,i,s,r)=>{const o=n.mapping.get(e);if(o===void 0){if(e instanceof Q)return Ge(e,t,n,i,s,r);throw at()}return o},Ge=(e,t,n,i,s,r)=>{const o=[],l=c=>{var a,u;if(c instanceof Q){const h=lo(c,t,n,i,s,r);h!==null&&o.push(h)}else{const h=(u=(a=c._item.right)==null?void 0:a.content)==null?void 0:u.type;h instanceof Rt&&!h._item.deleted&&h._item.id.client===h.doc.clientID&&(c.applyDelta([{retain:c.length},...h.toDelta()]),h.doc.transact(p=>{h._item.delete(p)}));const f=Mu(c,t,n,i,s,r);f!==null&&f.forEach(p=>{p!==null&&o.push(p)})}};i===void 0||s===void 0?e.toArray().forEach(l):zr(e,new Li(s.ds,i.sv)).forEach(l);try{const c=e.getAttributes(i);i!==void 0&&(dn(e._item,i)?dn(e._item,s)||(c.ychange=r?r("added",e._item.id):{type:"added"}):c.ychange=r?r("removed",e._item.id):{type:"removed"});const a=t.node(e.nodeName,c,o);return n.mapping.set(e,a),a}catch{return e.doc.transact(a=>{e._item.delete(a)},N),n.mapping.delete(e),null}},Mu=(e,t,n,i,s,r)=>{const o=[],l=e.toDelta(i,s,r);try{for(let c=0;c<l.length;c++){const a=l[c];o.push(t.text(a.insert,Lu(a.attributes,t)))}}catch{return e.doc.transact(a=>{e._item.delete(a)},N),null}return o},Ou=(e,t)=>{const n=new rt,i=e.map(s=>({insert:s.text,attributes:ho(s.marks,t)}));return n.applyDelta(i),t.mapping.set(n,e),n},ju=(e,t)=>{const n=new Q(e.type.name);for(const i in e.attrs){const s=e.attrs[i];s!==null&&i!=="ychange"&&n.setAttribute(i,s)}return n.insert(0,In(e).map(i=>gi(i,t))),t.mapping.set(n,e),n},gi=(e,t)=>e instanceof Array?Ou(e,t):ju(e,t),_s=e=>typeof e=="object"&&e!==null,Hi=(e,t)=>{const n=Object.keys(e).filter(s=>e[s]!==null);let i=n.length===Object.keys(t).filter(s=>t[s]!==null).length;for(let s=0;s<n.length&&i;s++){const r=n[s],o=e[r],l=t[r];i=r==="ychange"||o===l||_s(o)&&_s(l)&&Hi(o,l)}return i},In=e=>{const t=e.content.content,n=[];for(let i=0;i<t.length;i++){const s=t[i];if(s.isText){const r=[];for(let o=t[i];i<t.length&&o.isText;o=t[++i])r.push(o);i--,n.push(r)}else n.push(s)}return n},co=(e,t)=>{const n=e.toDelta();return n.length===t.length&&n.every((i,s)=>i.insert===t[s].text&&er(i.attributes||{}).length===t[s].marks.length&&oe(i.attributes,(r,o)=>{var u;const l=ao(o),c=t[s].marks;return c.find(h=>h.type.name===l)?Hi(r,(u=c.find(h=>h.type.name===l))==null?void 0:u.attrs):!1}))},De=(e,t)=>{if(e instanceof Q&&!(t instanceof Array)&&xi(e,t)){const n=In(t);return e._length===n.length&&Hi(e.getAttributes(),t.attrs)&&e.toArray().every((i,s)=>De(i,n[s]))}return e instanceof rt&&t instanceof Array&&co(e,t)},fn=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((n,i)=>t[i]===n),Ts=(e,t,n)=>{const i=e.toArray(),s=In(t),r=s.length,o=i.length,l=ee(o,r);let c=0,a=0,u=!1;for(;c<l;c++){const h=i[c],f=s[c];if(fn(n.mapping.get(h),f))u=!0;else if(!De(h,f))break}for(;c+a<l;a++){const h=i[o-a-1],f=s[r-a-1];if(fn(n.mapping.get(h),f))u=!0;else if(!De(h,f))break}return{equalityFactor:c+a,foundMappedChild:u}},Ru=e=>{let t="",n=e._start;const i={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof mt?t+=n.content.str:n.content instanceof F&&(i[n.content.key]=null)),n=n.right;return{str:t,nAttrs:i}},Nu=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:i,str:s}=Ru(e),r=t.map(a=>({insert:a.text,attributes:Object.assign({},i,ho(a.marks,n))})),{insert:o,remove:l,index:c}=pu(s,r.map(a=>a.insert).join(""));e.delete(c,l),e.insert(c,o),e.applyDelta(r.map(a=>({retain:a.insert.length,attributes:a.attributes})))},Bu=/(.*)(--[a-zA-Z0-9+/=]{8})$/,ao=e=>{var t;return((t=Bu.exec(e))==null?void 0:t[1])??e},Lu=(e,t)=>{const n=[];for(const i in e)n.push(t.mark(ao(i),e[i]));return n},ho=(e,t)=>{const n={};return e.forEach(i=>{if(i.type.name!=="ychange"){const s=Tt(t.isOMark,i.type,()=>!i.type.excludes(i.type));n[s?`${i.type.name}--${ku(i.toJSON())}`:i.type.name]=i.attrs}}),n},mi=(e,t,n,i)=>{if(t instanceof Q&&t.nodeName!==n.type.name)throw new Error("node name mismatch!");if(i.mapping.set(t,n),t instanceof Q){const h=t.getAttributes(),f=n.attrs;for(const p in f)f[p]!==null?h[p]!==f[p]&&p!=="ychange"&&t.setAttribute(p,f[p]):t.removeAttribute(p);for(const p in h)f[p]===void 0&&t.removeAttribute(p)}const s=In(n),r=s.length,o=t.toArray(),l=o.length,c=ee(r,l);let a=0,u=0;for(;a<c;a++){const h=o[a],f=s[a];if(!fn(i.mapping.get(h),f))if(De(h,f))i.mapping.set(h,f);else break}for(;u+a+1<c;u++){const h=o[l-u-1],f=s[r-u-1];if(!fn(i.mapping.get(h),f))if(De(h,f))i.mapping.set(h,f);else break}e.transact(()=>{for(;l-a-u>0&&r-a-u>0;){const f=o[a],p=s[a],g=o[l-u-1],x=s[r-u-1];if(f instanceof rt&&p instanceof Array)co(f,p)||Nu(f,p,i),a+=1;else{let w=f instanceof Q&&xi(f,p),y=g instanceof Q&&xi(g,x);if(w&&y){const C=Ts(f,p,i),S=Ts(g,x,i);C.foundMappedChild&&!S.foundMappedChild?y=!1:!C.foundMappedChild&&S.foundMappedChild||C.equalityFactor<S.equalityFactor?w=!1:y=!1}w?(mi(e,f,p,i),a+=1):y?(mi(e,g,x,i),u+=1):(i.mapping.delete(t.get(a)),t.delete(a,1),t.insert(a,[gi(p,i)]),a+=1)}}const h=l-a-u;if(l===1&&r===0&&o[0]instanceof rt?(i.mapping.delete(o[0]),o[0].delete(0,o[0].length)):h>0&&(t.slice(a,a+h).forEach(f=>i.mapping.delete(f)),t.delete(a,h)),a+u<r){const f=[];for(let p=a;p<r-u;p++)f.push(gi(s[p],i));t.insert(a,f)}},N)},xi=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,pn=(e,t,n)=>{if(e===0)return qn(t,0,-1);let i=t._first===null?null:t._first.content.type;for(;i!==null&&t!==i;){if(i instanceof rt){if(i._length>=e)return qn(i,e,-1);if(e-=i._length,i._item!==null&&i._item.next!==null)i=i._item.next.content.type;else{do i=i._item===null?null:i._item.parent,e--;while(i!==t&&i!==null&&i._item!==null&&i._item.next===null);i!==null&&i!==t&&(i=i._item===null?null:i._item.next.content.type)}}else{const s=(n.get(i)||{nodeSize:0}).nodeSize;if(i._first!==null&&e<s)i=i._first.content.type,e--;else{if(e===1&&i._length===0&&s>1)return new on(i._item===null?null:i._item.id,i._item===null?Ce(i):null,null);if(e-=s,i._item!==null&&i._item.next!==null)i=i._item.next.content.type;else{if(e===0)return i=i._item===null?i:i._item.parent,new on(i._item===null?null:i._item.id,i._item===null?Ce(i):null,null);do i=i._item.parent,e--;while(i!==t&&i._item.next===null);i!==t&&(i=i._item.next.content.type)}}}if(i===null)throw et();if(e===0&&i.constructor!==rt&&i!==t)return Pu(i._item.parent,i._item)}return qn(t,t._length,-1)},Pu=(e,t)=>{let n=null,i=null;return e._item===null?i=Ce(e):n=_(e._item.id.client,e._item.id.clock),new on(n,i,t.id)},me=(e,t,n,i)=>{const s=hh(n,e);if(s===null||s.type!==t&&!ke(t,s.type._item))return null;let r=s.type,o=0;if(r.constructor===rt)o=s.index;else if(r._item===null||!r._item.deleted){let l=r._first,c=0;for(;c<r._length&&c<s.index&&l!==null;){if(!l.deleted){const a=l.content.type;c++,a instanceof rt?o+=a._length:o+=i.get(a).nodeSize}l=l.right}o+=1}for(;r!==t&&r._item!==null;){const l=r._item.parent;if(l._item===null||!l._item.deleted){o+=1;let c=l._first;for(;c!==null;){const a=c.content.type;if(a===r)break;c.deleted||(a instanceof rt?o+=a._length:o+=i.get(a).nodeSize),c=c.right}}r=l}return o-1},Uu=e=>{const t=_t.getState(e).undoManager;if(t!=null)return t.undo(),!0},$u=e=>{const t=_t.getState(e).undoManager;if(t!=null)return t.redo(),!0},Fu=new Set(["paragraph"]),Vu=(e,t)=>!(e instanceof O)||!(e.content instanceof xt)||!(e.content.type instanceof Rt||e.content.type instanceof Q&&t.has(e.content.type.nodeName))||e.content.type._length===0,Hu=({protectedNodes:e=Fu,trackedOrigins:t=[],undoManager:n=null}={})=>new T.Plugin({key:_t,state:{init:(i,s)=>{const r=N.getState(s),o=n||new Pr(r.type,{trackedOrigins:new Set([N].concat(t)),deleteFilter:l=>Vu(l,e),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(i,s,r,o)=>{const l=N.getState(o).binding,c=s.undoManager,a=c.undoStack.length>0,u=c.redoStack.length>0;return l?{undoManager:c,prevSel:pi(l,r),hasUndoOps:a,hasRedoOps:u}:a!==s.hasUndoOps||u!==s.hasRedoOps?Object.assign({},s,{hasUndoOps:c.undoStack.length>0,hasRedoOps:c.redoStack.length>0}):s}},view:i=>{const s=N.getState(i.state),r=_t.getState(i.state).undoManager;return r.on("stack-item-added",({stackItem:o})=>{const l=s.binding;l&&o.meta.set(l,_t.getState(i.state).prevSel)}),r.on("stack-item-popped",({stackItem:o})=>{const l=s.binding;l&&(l.beforeTransactionSelection=o.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{r.destroy()}}}});function zi(e){return!!e.getMeta(N)}function zu(e,t){const n=N.getState(e);return me(n.doc,n.type,t,n.binding.mapping)||0}function uo(e,t){const n=N.getState(e);return pn(t,n.type,n.binding.mapping)}var Ye=class fo extends T.MappablePosition{constructor(t,n){super(t),this.yRelativePosition=n}static fromJSON(t){return new fo(t.position,t.yRelativePosition)}toJSON(){return{position:this.position,yRelativePosition:this.yRelativePosition}}};function Ku(e,t){const n=uo(t,e);return new Ye(e,n)}function qu(e,t,n){const i=e instanceof Ye?e.yRelativePosition:null;if(zi(t)&&i){const o=zu(n,i);return{position:new Ye(o,i),mapResult:null}}const s=T.getUpdatedPosition(e,t),r=s.position.position;return{position:new Ye(r,i??uo(n,r)),mapResult:s.mapResult}}T.Extension.create({name:"collaboration",priority:1e3,addOptions(){return{document:null,field:"default",fragment:null,provider:null}},addStorage(){return{isDisabled:!1}},onCreate(){this.editor.extensionManager.extensions.find(e=>e.name==="undoRedo")&&console.warn('[tiptap warn]: "@tiptap/extension-collaboration" comes with its own history support and is not compatible with "@tiptap/extension-undo-redo".')},onBeforeCreate(){this.editor.utils.getUpdatedPosition=(e,t)=>qu(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>Ku(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),_t.getState(t).undoManager.undoStack.length===0?!1:n?Uu(t):!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),_t.getState(t).undoManager.redoStack.length===0?!1:n?$u(t):!0)}},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo()}},addProseMirrorPlugins(){const e=this.options.fragment?this.options.fragment:this.options.document.getXmlFragment(this.options.field),t=Hu(this.options.yUndoOptions),n=t.spec.view;t.spec.view=r=>{const{undoManager:o}=_t.getState(r.state);o.restore&&(o.restore(),o.restore=()=>{});const l=n?n(r):void 0;return{destroy:()=>{const c=o.trackedOrigins.has(o),a=o._observers;o.restore=()=>{c&&o.trackedOrigins.add(o),o.doc.on("afterTransaction",o.afterTransactionHandler),o._observers=a},l!=null&&l.destroy&&l.destroy()}}};const i={...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender};return[Tu(e,i),t,this.editor.options.enableContentCheck&&new Y.Plugin({key:new Y.PluginKey("filterInvalidContent"),filterTransaction:r=>{if(!zi(r))return!0;if(this.storage.isDisabled)return!1;if(!r.docChanged)return!0;try{return r.doc.check(),!0}catch(o){return this.storage.isDisabled=!0,this.editor.emit("contentError",{error:o,editor:this.editor,disableCollaboration:()=>{var l;(l=e.doc)==null||l.destroy()}}),!1}}})].filter(Boolean)}});function Ds(e){if(!e.length)return Nn.DecorationSet.empty;const t=[],n=e[0].$from.node(0);return e.forEach(i=>{const s=i.$from.pos,r=i.$from.nodeAfter;r&&t.push(Nn.Decoration.node(s,s+r.nodeSize,{class:"ProseMirror-selectednoderange"}))}),Nn.DecorationSet.create(n,t)}function Wu(e,t,n){const i=n.isText||n.isAtom?0:1;return{start:e+i,end:e+t-i}}function Mn(e,t,n,i={}){const s=[],r=e.node(0),{extendOnBoundaryOverlap:o=!0}=i;typeof n=="number"&&n>=0||(e.sameParent(t)?n=Math.max(0,e.sharedDepth(t.pos)-1):n=e.sharedDepth(t.pos));const l=new Oo.NodeRange(e,t,n),c=l.depth===0?0:r.resolve(l.start).posAtIndex(0);return l.parent.forEach((a,u)=>{const h=c+u,f=h+a.nodeSize,p=Wu(h,a.nodeSize,a),g=o?t.pos>=p.start&&e.pos<=p.end:t.pos>p.start&&e.pos<p.end;if(h<l.start||h>=l.end||!g)return;const x=new Y.SelectionRange(r.resolve(h),r.resolve(f));s.push(x)}),s}var Gu=class po{constructor(t,n){this.anchor=t,this.head=n}map(t){return new po(t.map(this.anchor),t.map(this.head))}resolve(t){const n=t.resolve(this.anchor),i=t.resolve(this.head);return new Mt(n,i)}},Mt=class At extends Y.Selection{constructor(t,n,i,s=1){const{doc:r}=t,o=t===n,l=t.pos===r.content.size&&n.pos===r.content.size,c=o&&!l?r.resolve(n.pos+(s>0?1:-1)):n,a=o&&l?r.resolve(t.pos-(s>0?1:-1)):t,u=Mn(a.min(c),a.max(c),i),h=c.pos>=t.pos?u[0].$from:u[u.length-1].$to,f=c.pos>=t.pos?u[u.length-1].$to:u[0].$from;super(h,f,u),this.depth=i}get $to(){return this.ranges[this.ranges.length-1].$to}eq(t){return t instanceof At&&t.$from.pos===this.$from.pos&&t.$to.pos===this.$to.pos}map(t,n){const i=t.resolve(n.map(this.anchor)),s=t.resolve(n.map(this.head));return new At(i,s)}toJSON(){return{type:"nodeRange",anchor:this.anchor,head:this.head}}get isForwards(){return this.head>=this.anchor}get isBackwards(){return!this.isForwards}extendBackwards(){const{doc:t}=this.$from;if(this.isForwards&&this.ranges.length>1){const s=this.ranges.slice(0,-1),r=s[0].$from,o=s[s.length-1].$to;return new At(r,o,this.depth)}const n=this.ranges[0],i=t.resolve(Math.max(0,n.$from.pos-1));return new At(this.$anchor,i,this.depth)}extendForwards(){const{doc:t}=this.$from;if(this.isBackwards&&this.ranges.length>1){const s=this.ranges.slice(1),r=s[0].$from,o=s[s.length-1].$to;return new At(o,r,this.depth)}const n=this.ranges[this.ranges.length-1],i=t.resolve(Math.min(t.content.size,n.$to.pos+1));return new At(this.$anchor,i,this.depth)}static fromJSON(t,n){return new At(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,i,s,r=1){return new this(t.resolve(n),t.resolve(i),s,r)}getBookmark(){return new Gu(this.anchor,this.head)}};Mt.prototype.visible=!1;function $e(e){return e instanceof Mt}T.Extension.create({name:"nodeRange",addOptions(){return{depth:void 0,key:"Mod"}},addKeyboardShortcuts(){return{"Shift-ArrowUp":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,selection:r,tr:o}=i,{anchor:l,head:c}=r;if(!$e(r)){const u=Mt.create(s,l,c,t,-1);return o.setSelection(u),n.dispatch(o),!0}const a=r.extendBackwards();return o.setSelection(a),n.dispatch(o),!0},"Shift-ArrowDown":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,selection:r,tr:o}=i,{anchor:l,head:c}=r;if(!$e(r)){const u=Mt.create(s,l,c,t);return o.setSelection(u),n.dispatch(o),!0}const a=r.extendForwards();return o.setSelection(a),n.dispatch(o),!0},"Mod-a":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,tr:r}=i,o=Mt.create(s,0,s.content.size,t);return r.setSelection(o),n.dispatch(r),!0}}},onSelectionUpdate(){const{selection:e}=this.editor.state;$e(e)&&this.editor.view.dom.classList.add("ProseMirror-noderangeselection")},addProseMirrorPlugins(){let e=!1,t=!1;return[new Y.Plugin({key:new Y.PluginKey("nodeRange"),props:{attributes:()=>e?{class:"ProseMirror-noderangeselection"}:{class:""},handleDOMEvents:{mousedown:(n,i)=>{const{key:s}=this.options,r=/Mac/.test(navigator.platform),o=!!i.shiftKey,l=!!i.ctrlKey,c=!!i.altKey,a=!!i.metaKey,u=r?a:l;return(s==null||s==="Shift"&&o||s==="Control"&&l||s==="Alt"&&c||s==="Meta"&&a||s==="Mod"&&u)&&(t=!0),t&&document.addEventListener("mouseup",()=>{t=!1;const{state:h}=n,{doc:f,selection:p,tr:g}=h,{$anchor:x,$head:w}=p;if(x.sameParent(w))return;const y=Mt.create(f,x.pos,w.pos,this.options.depth);g.setSelection(y),n.dispatch(g)},{once:!0}),!1}},decorations:n=>{const{selection:i}=n,s=$e(i);if(e=!1,!t)return s?(e=!0,Ds(i.ranges)):null;const{$from:r,$to:o}=i;if(!s&&r.sameParent(o))return null;const l=Mn(r,o,this.options.depth);return l.length?(e=!0,Ds(l)):null}}})]}});function Yu(e,t){const n=getComputedStyle(e);if(t)return t.filter(s=>s.trim().length>0).map(s=>`${s}:${n.getPropertyValue(s)};`).join("");let i="";for(let s=0;s<n.length;s+=1)i+=`${n[s]}:${n.getPropertyValue(n[s])};`;return i}function Ju(e,t){const n=e.cloneNode(!0),i=[e,...Array.from(e.getElementsByTagName("*"))],s=[n,...Array.from(n.getElementsByTagName("*"))];return i.forEach((r,o)=>{s[o].style.cssText=Yu(r,t)}),n}var Xu={id:"listItemFirstChild",evaluate:({parent:e,isFirst:t})=>t&&e&&["listItem","taskItem"].includes(e.type.name)?1e3:0},Zu={id:"listWrapperDeprioritize",evaluate:({node:e})=>{const t=["listItem","taskItem"],n=e.firstChild;return n&&t.includes(n.type.name)?1e3:0}},Qu={id:"tableStructure",evaluate:({node:e,parent:t})=>["tableRow","tableCell","tableHeader"].includes(e.type.name)||t&&t.type.name==="tableHeader"?1e3:0},td={id:"inlineContent",evaluate:({node:e})=>e.isInline||e.isText?1e3:0},ed=[Xu,Zu,Qu,td],As={edges:["left","top"],threshold:12,strength:500};function Jn(e){return e===void 0||e==="left"?{...As}:e==="right"?{edges:["right","top"],threshold:12,strength:500}:e==="both"?{edges:["left","right","top"],threshold:12,strength:500}:e==="none"?{edges:[],threshold:0,strength:0}:{...As,...e}}function nd(e,t,n){if(n.edges.length===0)return!1;const i=t.getBoundingClientRect(),{threshold:s,edges:r}=n;return r.some(o=>o==="left"?e.x-i.left<s:o==="right"?i.right-e.x<s:o==="top"?e.y-i.top<s:o==="bottom"?i.bottom-e.y<s:!1)}function id(e,t,n,i){return!t||n.edges.length===0?0:nd(e,t,n)?n.strength*i:0}var sd=1e3;function Is(e,t,n,i){let s=sd,r=!1;if(t.every(l=>{const c=l.evaluate(e);return s-=c,s<=0?(r=!0,!1):!0}),r)return-1;const o=e.view.nodeDOM(e.pos);return s-=id(i,o,n,e.depth),s<=0?-1:s}function Ms(e,t,n){return Array.from({length:t},(s,r)=>t-1-r).some(s=>n.includes(e.node(s).type.name))}function rd(e,t,n){if(!Number.isFinite(t.x)||!Number.isFinite(t.y))return null;const i=e.posAtCoords({left:t.x,top:t.y});if(!i)return null;const{doc:s}=e.state,r=s.resolve(i.pos),o=[];n.defaultRules&&o.push(...ed),o.push(...n.rules);const c=Array.from({length:r.depth},(h,f)=>r.depth-f).map(h=>{const f=r.node(h),p=r.before(h);if(n.allowedContainers&&h>0&&!Ms(r,h,n.allowedContainers))return null;const g=h>0?r.node(h-1):null,x=h>0?r.index(h-1):0,w=g?g.childCount:1,y={node:f,pos:p,depth:h,parent:g,index:x,isFirst:x===0,isLast:x===w-1,$pos:r,view:e},C=Is(y,o,n.edgeDetection,t);if(C<0)return null;const S=e.nodeDOM(p);return{node:f,pos:p,depth:h,score:C,dom:S}}).filter(h=>h!==null),a=r.nodeAfter;if(a&&a.isAtom&&!a.isInline){const h=i.pos,f=r.depth+1,p=r.parent,g=r.index(),x=p.childCount;let w=!0;if(n.allowedContainers&&(w=Ms(r,f,n.allowedContainers)),w){const y={node:a,pos:h,depth:f,parent:p,index:g,isFirst:g===0,isLast:g===x-1,$pos:r,view:e},C=Is(y,o,n.edgeDetection,t);if(C>=0){const S=e.nodeDOM(h);S&&c.push({node:a,pos:h,depth:f,score:C,dom:S})}}}if(c.length===0)return null;c.sort((h,f)=>f.score!==h.score?f.score-h.score:f.depth-h.depth);const u=c[0];return u.dom?{node:u.node,pos:u.pos,dom:u.dom}:null}function od(e,t){let n=e;for(;n!=null&&n.parentElement&&n.parentElement!==t.dom;)n=n.parentElement;return(n==null?void 0:n.parentElement)===t.dom?n:void 0}function Os(e){return Number.isFinite(e.top)&&Number.isFinite(e.bottom)&&Number.isFinite(e.left)&&Number.isFinite(e.right)&&e.width>0&&e.height>0}function ld(e,t,n,i=5){if(!Number.isFinite(t)||!Number.isFinite(n))return null;const s=e.dom,r=s.firstElementChild,o=s.lastElementChild;if(!r||!o)return null;const l=r.getBoundingClientRect(),c=o.getBoundingClientRect();if(!Os(l)||!Os(c))return null;const a=Math.min(Math.max(l.top+i,n),c.bottom-i),u=.5,h=Math.abs(l.left-c.left)<u,f=Math.abs(l.right-c.right)<u;let p=l;h&&f&&(p=l);const g=Math.min(Math.max(p.left+i,t),p.right-i);return!Number.isFinite(g)||!Number.isFinite(a)?null:{x:g,y:a}}var go=e=>{const{x:t,y:n,editor:i,nestedOptions:s}=e,{view:r,state:o}=i,l=ld(r,t,n,5);if(!l)return{resultElement:null,resultNode:null,pos:null};const{x:c,y:a}=l;if(s!=null&&s.enabled){const g=rd(r,{x:c,y:a},s);return g?{resultElement:g.dom,resultNode:g.node,pos:g.pos}:{resultElement:null,resultNode:null,pos:null}}const u=r.root.elementsFromPoint(c,a);let h;if(Array.prototype.some.call(u,g=>{if(!r.dom.contains(g))return!1;const x=od(g,r);return x?(h=x,!0):!1}),!h){const g=r.posAtCoords({left:c,top:a});if(g){const x=o.doc.resolve(g.pos),w=Math.min(x.depth,1),y=w>0?x.before(w):x.pos,C=o.doc.nodeAt(y);if(C){const S=r.nodeDOM(y);return{resultElement:S instanceof HTMLElement?S:null,resultNode:C,pos:y}}}return{resultElement:null,resultNode:null,pos:null}}let f;try{f=r.posAtDOM(h,0)}catch{return{resultElement:null,resultNode:null,pos:null}}const p=o.doc.nodeAt(f);if(!p){const g=o.doc.resolve(f),x=g.parent;return{resultElement:h,resultNode:x,pos:g.start()}}return{resultElement:h,resultNode:p,pos:f}};function mo(e,t){const n=e.nodeDOM(t);if(n instanceof Element&&n!==e.dom)return n;const{node:i,offset:s}=e.domAtPos(t),r=i.childNodes[s];return r instanceof Element?r:i instanceof Element?i:i.nodeType===Node.TEXT_NODE&&i.parentElement?i.parentElement:null}function cd(e,t){const n=mo(e,t);return(n?getComputedStyle(n).direction:getComputedStyle(e.dom).direction)||"ltr"}function xo(e){var t;(t=e.parentNode)==null||t.removeChild(e)}function ad(e,t){return e==="rtl"?t:0}function hd(e,t,n,i){const{doc:s}=t.view.state;if(n!=null&&n.enabled&&(i!=null&&i.node)&&i.pos>=0){const a=i.pos,u=i.pos+i.node.nodeSize;return[{$from:s.resolve(a),$to:s.resolve(u)}]}const r=go({editor:t,x:e.clientX,y:e.clientY,nestedOptions:n});if(!r.resultNode||r.pos===null)return[];const o=r.resultNode.isText||r.resultNode.isAtom?0:-1,l=s.resolve(r.pos),c=s.resolve(r.pos+r.resultNode.nodeSize+o);return Mn(l,c,0,{extendOnBoundaryOverlap:!1})}function ud(e,t,n,i,s){const{view:r}=t;if(!e.dataTransfer)return;const{empty:o,$from:l,$to:c}=r.state.selection,a=hd(e,t,n,i),u=Mn(l,c,0,{extendOnBoundaryOverlap:!1}),h=u.some(z=>a.find(M=>M.$from===z.$from&&M.$to===z.$to)),f=o||!h?a:u;if(!f.length)return;const{tr:p}=r.state,g=document.createElement("div"),x=f[0].$from.pos,w=f[f.length-1].$to.pos,y=cd(r,x);g.setAttribute("dir",y);const C=(n==null?void 0:n.enabled)&&(i==null?void 0:i.node);let S,D;C?(S=r.state.doc.slice(x,w),D=Y.NodeSelection.create(r.state.doc,x)):(D=Mt.create(r.state.doc,x,w),S=D.content()),f.forEach(z=>{const M=mo(r,z.$from.pos);if(!M)return;const P=Ju(M,s);P.style.margin="0",g.append(P)}),g.style.position="absolute",g.style.top="-10000px",document.body.append(g),e.dataTransfer.clearData();const H=g.getBoundingClientRect(),A=ad(y,H.width);e.dataTransfer.setDragImage(g,A,0);let v=!1;const k=()=>{v||(v=!0,xo(g),document.removeEventListener("drop",k),document.removeEventListener("dragend",k))},L=D instanceof Y.NodeSelection?D:void 0;r.dragging={slice:S,move:!0,node:L},p.setSelection(D),r.dispatch(p),document.addEventListener("drop",k),document.addEventListener("dragend",k)}var js=(e,t)=>{const n=e.resolve(t),{depth:i}=n;return i===0?t:n.pos-n.parentOffset-1},Rs=(e,t)=>{const n=e.nodeAt(t),i=e.resolve(t);let{depth:s}=i,r=n;for(;s>0;){const o=i.node(s);s-=1,s===0&&(r=o)}return r},Xn=(e,t)=>{const n=N.getState(e);return n?pn(t,n.type,n.binding.mapping):null},dd=(e,t)=>{const n=N.getState(e);return n?me(n.doc,n.type,t,n.binding.mapping)||0:-1},Ns=(e,t)=>{let n=t;for(;n!=null&&n.parentNode&&n.parentNode!==e.dom;)n=n.parentNode;return n},bo=new Y.PluginKey("dragHandle"),wo=({pluginKey:e=bo,element:t,editor:n,computePositionConfig:i,getReferencedVirtualElement:s,onNodeChange:r,onElementDragStart:o,onElementDragEnd:l,nestedOptions:c,dragImageProperties:a})=>{const u=document.createElement("div");let h=!1,f=null,p=-1,g,x=null,w=null;function y(){t&&(t.style.visibility="hidden",t.style.pointerEvents="none")}function C(){if(t){if(!n.isEditable){y();return}t.style.visibility="",t.style.pointerEvents="auto"}}function S(v){const k=(s==null?void 0:s())||{getBoundingClientRect:()=>v.getBoundingClientRect()};q.computePosition(k,t,i).then(L=>{Object.assign(t.style,{position:L.strategy,left:`${L.x}px`,top:`${L.y}px`})})}function D(v){o==null||o(v),ud(v,n,c,{node:f,pos:p},a),t&&(t.dataset.dragging="true"),setTimeout(()=>{t&&(t.style.pointerEvents="none")},0)}function H(v){l==null||l(v),y(),t&&(t.style.pointerEvents="auto",t.dataset.dragging="false")}function A(){if(T.isFirefox()){const v=n.view.dom;requestAnimationFrame(()=>{v.isContentEditable&&(v.contentEditable="false",v.contentEditable="true")})}}return u.appendChild(t),{unbind(){t.removeEventListener("dragstart",D),t.removeEventListener("dragend",H),document.removeEventListener("drop",A),x&&(cancelAnimationFrame(x),x=null,w=null)},plugin:new Y.Plugin({key:typeof e=="string"?new Y.PluginKey(e):e,state:{init(){return{locked:!1}},apply(v,k,L,z){const M=v.getMeta("lockDragHandle"),P=v.getMeta("hideDragHandle");if(M!==void 0&&(h=M),P)return y(),h=!1,f=null,p=-1,r==null||r({editor:n,node:null,pos:-1}),k;if(v.docChanged&&p!==-1&&t)if(zi(v)){const K=dd(z,g);K!==p&&(p=K)}else{const K=v.mapping.map(p);K!==p&&(p=K,g=Xn(z,p))}return k}},view:v=>{var k;return t.draggable=!0,t.style.pointerEvents="auto",t.dataset.dragging="false",(k=n.view.dom.parentElement)==null||k.appendChild(u),u.style.pointerEvents="none",u.style.position="absolute",u.style.top="0",u.style.left="0",t.addEventListener("dragstart",D),t.addEventListener("dragend",H),document.addEventListener("drop",A),{update(L,z){if(!t)return;if(!n.isEditable){y();return}if(h?t.draggable=!1:t.draggable=!0,v.state.doc.eq(z.doc)||p===-1)return;let M=v.nodeDOM(p);if(M=Ns(v,M),M===v.dom||(M==null?void 0:M.nodeType)!==1)return;const P=v.posAtDOM(M,0),K=Rs(n.state.doc,P),E=js(n.state.doc,P);f=K,p=E,g=Xn(v.state,p),r==null||r({editor:n,node:f,pos:p}),S(M)},destroy(){t.removeEventListener("dragstart",D),t.removeEventListener("dragend",H),document.removeEventListener("drop",A),x&&(cancelAnimationFrame(x),x=null,w=null),t&&xo(u)}}},props:{handleDOMEvents:{keydown(v){return!t||h||v.hasFocus()&&(y(),f=null,p=-1,r==null||r({editor:n,node:null,pos:-1})),!1},mouseleave(v,k){return h||k.target&&!u.contains(k.relatedTarget)&&(y(),f=null,p=-1,r==null||r({editor:n,node:null,pos:-1})),!1},mousemove(v,k){return!t||h||(w={x:k.clientX,y:k.clientY},x)||(x=requestAnimationFrame(()=>{if(x=null,!w)return;const{x:L,y:z}=w;w=null;const M=go({x:L,y:z,editor:n,nestedOptions:c});if(!M.resultElement)return;let P=M.resultElement,K=M.resultNode,E=M.pos;if(!(c!=null&&c.enabled)){if(P=Ns(v,P),P===v.dom||(P==null?void 0:P.nodeType)!==1)return;const ot=v.posAtDOM(P,0);K=Rs(n.state.doc,ot),E=js(n.state.doc,ot)}K!==f&&(f=K,p=E??-1,g=Xn(v.state,p),r==null||r({editor:n,node:f,pos:p}),S(P),C())})),!1}}}})}};function yo(e){var t,n;return e===!1||e===void 0?{enabled:!1,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Jn("none")}:e===!0?{enabled:!0,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Jn("left")}:{enabled:!0,rules:(t=e.rules)!=null?t:[],defaultRules:(n=e.defaultRules)!=null?n:!0,allowedContainers:e.allowedContainers,edgeDetection:Jn(e.edgeDetection)}}var bi={placement:"left-start",strategy:"absolute"};T.Extension.create({name:"dragHandle",addOptions(){return{render(){const e=document.createElement("div");return e.classList.add("drag-handle"),e},computePositionConfig:{},locked:!1,onNodeChange:()=>null,onElementDragStart:void 0,onElementDragEnd:void 0,nested:!1,dragImageProperties:void 0}},addCommands(){return{lockDragHandle:()=>({editor:e})=>(this.options.locked=!0,e.commands.setMeta("lockDragHandle",this.options.locked)),unlockDragHandle:()=>({editor:e})=>(this.options.locked=!1,e.commands.setMeta("lockDragHandle",this.options.locked)),toggleDragHandle:()=>({editor:e})=>(this.options.locked=!this.options.locked,e.commands.setMeta("lockDragHandle",this.options.locked))}},addProseMirrorPlugins(){const e=this.options.render(),t=yo(this.options.nested);return[wo({computePositionConfig:{...bi,...this.options.computePositionConfig},getReferencedVirtualElement:this.options.getReferencedVirtualElement,element:e,editor:this.editor,onNodeChange:this.options.onNodeChange,onElementDragStart:this.options.onElementDragStart,onElementDragEnd:this.options.onElementDragEnd,nestedOptions:t,dragImageProperties:this.options.dragImageProperties}).plugin]}});var fd=e=>{const{className:t="drag-handle",children:n,editor:i,pluginKey:s=bo,onNodeChange:r,onElementDragStart:o,onElementDragEnd:l,getReferencedVirtualElement:c,computePositionConfig:a=bi,nested:u=!1}=e,[h]=b.useState(()=>typeof document>"u"?null:document.createElement("div")),f=b.useMemo(()=>yo(u),[JSON.stringify(u)]);return b.useEffect(()=>{h&&(h.className=t,h.style.visibility="hidden",h.style.position="absolute",h.dataset.dragging="false")},[t,h]),b.useEffect(()=>{if(!h||i.isDestroyed)return;const{plugin:p,unbind:g}=wo({editor:i,element:h,pluginKey:s,computePositionConfig:{...bi,...a},onElementDragStart:o,onElementDragEnd:l,onNodeChange:r,getReferencedVirtualElement:c,nestedOptions:f});return i.registerPlugin(p),()=>{i.isDestroyed||i.unregisterPlugin(s),g()}},[h,i,r,c,s,a,o,l,f]),h?wi.createPortal(n,h):null},pd=fd;function gd(){var A,v,k,L,z,M,P,K;const e=m.useEditorInstance(),t=m.useEditableEditor(),{t:n}=B.useLocale(),[i,s]=b.useState(null),[r,o]=b.useState(-1),[l,c]=b.useState(!1),a=(v=(A=e==null?void 0:e.extensionManager)==null?void 0:A.extensions)==null?void 0:v.some(E=>(E==null?void 0:E.name)===Us.TextAlign.name),u=(L=(k=e==null?void 0:e.extensionManager)==null?void 0:k.extensions)==null?void 0:L.some(E=>(E==null?void 0:E.name)===de.Indent.name),h=(M=(z=e==null?void 0:e.extensionManager)==null?void 0:z.extensions)==null?void 0:M.some(E=>(E==null?void 0:E.name)===jo.Clear.name);function f(){const E=e.chain();E.setNodeSelection(r).unsetAllMarks(),(i==null?void 0:i.type.name)!=="paragraph"&&E.setParagraph(),E.run()}function p(){e.chain().focus().setNodeSelection(r).run(),document.execCommand("copy")}function g(){e.commands.setNodeSelection(r);const{$anchor:E}=e.state.selection,ot=E.node(1)||e.state.selection.node;e.chain().setMeta("hideDragHandle",!0).insertContentAt(r+((i==null?void 0:i.nodeSize)||0),ot.toJSON()).run()}function x(E){e.commands.setTextAlign(E)}function w(){const E=de.setNodeIndentMarkup(e.state.tr,r,1);E.setMeta("hideDragHandle",!0),e.view.dispatch&&e.view.dispatch(E)}function y(){const E=de.setNodeIndentMarkup(e.state.tr,r,-1);e.view.dispatch&&e.view.dispatch(E)}function C(){e.chain().setMeta("hideDragHandle",!0).setNodeSelection(r).deleteSelection().run()}const S=b.useCallback(E=>{E.node&&s(E.node),o(E.pos),requestAnimationFrame(()=>{E.editor.commands.focus()})},[]),D=E=>{var ot;if(E.preventDefault(),r!==-1){const Re=(i==null?void 0:i.nodeSize)||0,qt=r+Re,Ki=(i==null?void 0:i.type.name)==="paragraph"&&((ot=i==null?void 0:i.content)==null?void 0:ot.size)===0,vo=Ki?r+2:qt+2;e.chain().command(({dispatch:qi,tr:On,state:Wi})=>qi?(Ki?On.insertText("/",r,r+1):On.insert(qt,Wi.schema.nodes.paragraph.create(null,[Wi.schema.text("/")])),qi(On)):!0).focus(vo).run()}};b.useEffect(()=>(l?e.commands.setMeta("lockDragHandle",!0):e.commands.setMeta("lockDragHandle",!1),()=>{e.commands.setMeta("lockDragHandle",!1)}),[l]);const H=E=>{t&&c(E)};return d.jsx(pd,{className:"richtext-transition-all richtext-duration-200 richtext-ease-out",editor:e,onNodeChange:S,pluginKey:"RichTextBubbleMenuDragHandle",children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-0.5",children:[d.jsx(m.ActionButton,{action:D,disabled:!t,icon:"Plus",tooltip:n("editor.draghandle.insertBlock")}),d.jsx(m.ActionButton,{disabled:!t,icon:"Grip",tooltip:n("editor.draghandle.grip"),action:E=>{E.preventDefault(),E.stopPropagation(),H(!l)}}),d.jsxs(U.DropdownMenu,{onOpenChange:H,open:l,children:[d.jsx(U.DropdownMenuTrigger,{className:"richtext-pointer-events-none"}),d.jsxs(U.DropdownMenuContent,{align:"start",className:"richtext-w-48",hideWhenDetached:!0,side:"bottom",sideOffset:0,children:[d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3 richtext-bg-opacity-10 hover:richtext-bg-red-400 hover:richtext-bg-opacity-20 focus:richtext-bg-red-400 focus:richtext-bg-opacity-30 focus:richtext-text-red-500 dark:hover:richtext-bg-opacity-20 dark:hover:richtext-text-red-500",onClick:C,children:[d.jsx(m.IconComponent,{name:"Trash2"}),d.jsx("span",{children:n("editor.remove")})]}),h?d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:f,children:[d.jsx(m.IconComponent,{name:"PaintRoller"}),d.jsx("span",{children:n("editor.clear.tooltip")})]}):null,d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:p,children:[d.jsx(m.IconComponent,{name:"Clipboard"}),d.jsx("span",{children:n("editor.copyToClipboard")})]}),d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:g,children:[d.jsx(m.IconComponent,{name:"Copy"}),d.jsx("span",{children:n("editor.copy")})]}),a||u?d.jsx(U.DropdownMenuSeparator,{}):null,a?d.jsxs(U.DropdownMenuSub,{children:[d.jsxs(U.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[d.jsx(m.IconComponent,{name:"AlignCenter"}),d.jsx("span",{children:n("editor.textalign.tooltip")})]}),d.jsx(U.DropdownMenuPortal,{children:d.jsxs(U.DropdownMenuSubContent,{children:[d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("left"),children:[d.jsx(m.IconComponent,{name:"AlignLeft"}),d.jsx("span",{children:n("editor.textalign.left.tooltip")})]}),d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("center"),children:[d.jsx(m.IconComponent,{name:"AlignCenter"}),d.jsx("span",{children:n("editor.textalign.center.tooltip")})]}),d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("right"),children:[d.jsx(m.IconComponent,{name:"AlignRight"}),d.jsx("span",{children:n("editor.textalign.right.tooltip")})]})]})})]}):null,u?d.jsxs(U.DropdownMenuSub,{children:[d.jsxs(U.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[d.jsx(m.IconComponent,{name:"IndentIncrease"}),d.jsx("span",{children:n("editor.indent")})]}),d.jsx(U.DropdownMenuPortal,{children:d.jsxs(U.DropdownMenuSubContent,{children:[d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((P=i==null?void 0:i.attrs)==null?void 0:P.indent)>=de.IndentProps.max,onClick:w,children:[d.jsx(m.IconComponent,{name:"IndentIncrease"}),d.jsx("span",{children:n("editor.indent.tooltip")})]}),d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((K=i==null?void 0:i.attrs)==null?void 0:K.indent)<=de.IndentProps.min,onClick:y,children:[d.jsx(m.IconComponent,{name:"IndentDecrease"}),d.jsx("span",{children:n("editor.outdent.tooltip")})]})]})})]}):null]})]})]})})}const Bs={plaintext:"Plain Text",js:"JavaScript",ts:"TypeScript",css:"CSS",html:"HTML",python:"Python",bash:"Bash"};function md({listLanguages:e}){const{t}=B.useLocale(),[n,i]=b.useState(!1),s=m.useEditorInstance(),r=b.useMemo(()=>{const{selection:l}=s.state,c=l.$from.parent;if(c.type.name==="codeBlock"){const a=c.attrs.language||"plaintext";return Bs[a]||a}},[s.state,e]),o=b.useMemo(()=>{let l=e||[];return e!=null&&e.includes("plaintext")||(l=["plaintext",...l]),l.map(c=>({label:Bs[c]||c,value:c}))},[e]);return d.jsxs(kt.Popover,{modal:!0,onOpenChange:i,open:n,children:[d.jsx(kt.PopoverTrigger,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:d.jsxs(m.ActionButton,{dataState:!!r,children:[r?d.jsx(d.Fragment,{children:r}):d.jsx(d.Fragment,{children:t("editor.paragraph.tooltip")}),d.jsx(m.IconComponent,{className:"richtext-ml-1 richtext-size-3 richtext-text-zinc-500",name:"MenuDown"})]})}),d.jsx(kt.PopoverContent,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:o==null?void 0:o.map(l=>d.jsxs("div",{className:"richtext-flex richtext-w-full richtext-items-center richtext-gap-3 richtext-rounded-sm !richtext-border-none !richtext-bg-transparent richtext-px-2 richtext-py-1.5 richtext-text-left richtext-text-sm richtext-text-foreground !richtext-outline-none richtext-transition-colors hover:!richtext-bg-accent",onClick:c=>{c.preventDefault(),s.chain().focus().setCodeBlock({language:l.value}).run(),i(!1)},children:[d.jsx("div",{className:"!richtext-min-w-[20px]",children:r===l.value&&d.jsx(Pt.Check,{size:16})}),d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:l.label})]},l.value))})]})}function xd(){const e=m.useEditableEditor(),t=m.useEditorInstance(),n=m.useExtension(Rn.CodeBlock.name),i=b.useCallback(({editor:c})=>c.isActive(Rn.CodeBlock.name),[]),s=b.useMemo(()=>{var c,a,u;return n?((u=(a=(c=n.options)==null?void 0:c.lowlight)==null?void 0:a.listLanguages)==null?void 0:u.call(a))||["plaintext","html","css","js","ts"]:[]},[n]),r=b.useCallback(()=>Ht(Rn.CodeBlock.name,t),[t]),o=()=>{const{from:c}=t.state.selection,a=t.state.doc.resolve(c);for(let u=a.depth;u>=0;u--){const h=a.node(u);if(h.type.name==="codeBlock")return h.textContent}return""},l=()=>{const c=o();navigator.clipboard.writeText(c)};return e?d.jsx(nt,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleCodeBlock",shouldShow:i,getReferencedVirtualElement:()=>{const{from:c}=t.state.selection,u=t.view.domAtPos(c).node.parentElement;return u?{getBoundingClientRect:()=>u.getBoundingClientRect()}:null},children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(md,{listLanguages:s}),d.jsx(wt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(m.ActionButton,{action:l,tooltip:"Copy",children:d.jsx(Pt.Copy,{size:16})}),d.jsx(wt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(m.ActionButton,{action:r,tooltip:"Delete",children:d.jsx(Pt.Trash2,{size:16})})]})}):d.jsx(d.Fragment,{})}exports.RichTextBubbleCallout=hl;exports.RichTextBubbleCodeBlock=xd;exports.RichTextBubbleColumns=ul;exports.RichTextBubbleDrawer=Tl;exports.RichTextBubbleExcalidraw=Al;exports.RichTextBubbleIframe=Il;exports.RichTextBubbleImage=Pl;exports.RichTextBubbleImageGif=Ul;exports.RichTextBubbleKatex=Ol;exports.RichTextBubbleLink=Rl;exports.RichTextBubbleMenuDragHandle=gd;exports.RichTextBubbleMermaid=zl;exports.RichTextBubbleTable=Kl;exports.RichTextBubbleText=Gl;exports.RichTextBubbleTwitter=Yl;exports.RichTextBubbleVideo=$l;
1
+ "use strict";var Io=Object.create;var Un=Object.defineProperty;var Mo=Object.getOwnPropertyDescriptor;var Oo=Object.getOwnPropertyNames;var Ro=Object.getPrototypeOf,jo=Object.prototype.hasOwnProperty;var No=(e,t,n)=>t in e?Un(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Bo=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Oo(t))!jo.call(e,s)&&s!==n&&Un(e,s,{get:()=>t[s],enumerable:!(i=Mo(t,s))||i.enumerable});return e};var Lo=(e,t,n)=>(n=e!=null?Io(Ro(e)):{},Bo(t||!e||!e.__esModule?Un(n,"default",{value:e,enumerable:!0}):n,e));var ze=(e,t,n)=>No(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),O=require("./index-BGfIcDCQ.cjs"),W=require("./index-BgNKVyMW.cjs"),G=require("@tiptap/pm/state"),Vs=require("./Table-D5G3rfwb.cjs"),Fs=require("./clsx-DRbkQ4T7.cjs"),w=require("react"),Ei=require("react-dom"),m=require("./index-aujjnfSJ.cjs"),$e=require("./Callout.cjs"),xt=require("./Katex-CUofhjB5.cjs"),P=require("./index-BpLw6ebr.cjs"),Ht=require("lucide-react"),At=require("./popover-CrywEkBR.cjs"),Et=require("./separator-BGO9AZp4.cjs"),zn=require("./CodeBlock.cjs"),Zi=require("./Column.cjs");require("./theme.cjs");const We=require("./Drawer-D7E9kTca.cjs"),Qi=require("easydrawer"),nn=require("./shortId-Bfj8TyNr.cjs"),xe=require("./Excalidraw.cjs"),Zt=require("./Iframe-OMVd0xa_.cjs"),Po=require("./ImageGif.cjs"),Uo=require("katex"),Ge=require("./LinkEditBlock-Z7RRurvx.cjs"),$n=require("@tiptap/pm/view"),zo=require("@tiptap/pm/model"),z=require("./dropdown-menu-CURWpB9o.cjs"),$o=require("./Clear.cjs"),we=require("./Indent-QgCoonRk.cjs"),Hs=require("./TextAlign.cjs"),ri=require("./Mermaid.cjs"),Vo=require("./Bold.cjs"),Fo=require("./Code.cjs");require("./index-SEMQrdk2.cjs");const Ho=require("./Color.cjs"),Ko=require("./Highlight.cjs"),qo=require("./Italic.cjs"),Wo=require("./SlashCommandNodeView-DPPmYEjC.cjs"),Go=require("./Strike.cjs"),Yo=require("./TextUnderline.cjs"),Vn=require("./Twitter-q4ZGZL0i.cjs");function Jo(e,t){const n=Math.min(e.top,t.top),i=Math.max(e.bottom,t.bottom),s=Math.min(e.left,t.left),o=Math.max(e.right,t.right)-s,l=i-n,c=s,a=n;return new DOMRect(c,a,o,l)}var Xo=class{constructor({editor:e,element:t,view:n,pluginKey:i="bubbleMenu",updateDelay:s=250,resizeDelay:r=60,shouldShow:o,appendTo:l,getReferencedVirtualElement:c,options:a}){this.preventHide=!1,this.isVisible=!1,this.scrollTarget=window,this.floatingUIOptions={strategy:"absolute",placement:"top",offset:8,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1,onShow:void 0,onHide:void 0,onUpdate:void 0,onDestroy:void 0},this.shouldShow=({view:h,state:f,from:p,to:g})=>{const{doc:x,selection:b}=f,{empty:y}=b,C=!x.textBetween(p,g).length&&O.isTextSelection(f.selection),S=this.element.contains(document.activeElement);return!(!(h.hasFocus()||S)||y||C||!this.editor.isEditable)},this.mousedownHandler=()=>{this.preventHide=!0},this.dragstartHandler=()=>{this.hide()},this.resizeHandler=()=>{this.resizeDebounceTimer&&clearTimeout(this.resizeDebounceTimer),this.resizeDebounceTimer=window.setTimeout(()=>{this.updatePosition()},this.resizeDelay)},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:h})=>{var f;if(this.editor.isDestroyed){this.destroy();return}if(this.preventHide){this.preventHide=!1;return}h!=null&&h.relatedTarget&&((f=this.element.parentNode)!=null&&f.contains(h.relatedTarget))||(h==null?void 0:h.relatedTarget)!==this.editor.view.dom&&this.hide()},this.handleDebouncedUpdate=(h,f)=>{const p=!(f!=null&&f.selection.eq(h.state.selection)),g=!(f!=null&&f.doc.eq(h.state.doc));!p&&!g||(this.updateDebounceTimer&&clearTimeout(this.updateDebounceTimer),this.updateDebounceTimer=window.setTimeout(()=>{this.updateHandler(h,p,g,f)},this.updateDelay))},this.updateHandler=(h,f,p,g)=>{const{composing:x}=h;if(x||!f&&!p)return;if(!this.getShouldShow(g)){this.hide();return}this.show(),this.updatePosition()},this.transactionHandler=({transaction:h})=>{const f=h.getMeta(this.pluginKey);f==="updatePosition"?this.updatePosition():f&&typeof f=="object"&&f.type==="updateOptions"?this.updateOptions(f.options):f==="hide"?this.hide():f==="show"&&(this.updatePosition(),this.show())};var u;this.editor=e,this.element=t,this.view=n,this.pluginKey=i,this.updateDelay=s,this.resizeDelay=r,this.appendTo=l,this.scrollTarget=(u=a==null?void 0:a.scrollTarget)!=null?u:window,this.getReferencedVirtualElement=c,this.floatingUIOptions={...this.floatingUIOptions,...a},this.element.tabIndex=0,o&&(this.shouldShow=o),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.view.dom.addEventListener("dragstart",this.dragstartHandler),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.editor.on("transaction",this.transactionHandler),window.addEventListener("resize",this.resizeHandler),this.scrollTarget.addEventListener("scroll",this.resizeHandler),this.update(n,n.state),this.getShouldShow()&&(this.show(),this.updatePosition())}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(W.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(W.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(W.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(W.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(W.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(W.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(W.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(W.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}get virtualElement(){var e,t,n;const{selection:i}=this.editor.state,s=(e=this.getReferencedVirtualElement)==null?void 0:e.call(this);if(s)return s;if(!((n=(t=this.view)==null?void 0:t.dom)!=null&&n.parentNode))return;const r=O.posToDOMRect(this.view,i.from,i.to);let o={getBoundingClientRect:()=>r,getClientRects:()=>[r]};if(i instanceof G.NodeSelection){let l=this.view.nodeDOM(i.from);const c=l.dataset.nodeViewWrapper?l:l.querySelector("[data-node-view-wrapper]");c&&(l=c),l&&(o={getBoundingClientRect:()=>l.getBoundingClientRect(),getClientRects:()=>[l.getBoundingClientRect()]})}if(i instanceof Vs.CellSelection){const{$anchorCell:l,$headCell:c}=i,a=l?l.pos:c.pos,u=c?c.pos:l.pos,h=this.view.nodeDOM(a),f=this.view.nodeDOM(u);if(!h||!f)return;const p=h===f?h.getBoundingClientRect():Jo(h.getBoundingClientRect(),f.getBoundingClientRect());o={getBoundingClientRect:()=>p,getClientRects:()=>[p]}}return o}updatePosition(){if(!this.isVisible)return;const e=this.virtualElement;e&&W.computePosition(e,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:t,y:n,strategy:i,middlewareData:s})=>{var r,o;if(!(!this.isVisible||this.editor.isDestroyed||!this.element.isConnected)){if((r=s.hide)!=null&&r.referenceHidden||(o=s.hide)!=null&&o.escaped){this.element.style.visibility="hidden";return}this.element.style.visibility="visible",this.element.style.width="max-content",this.element.style.position=i,this.element.style.left=`${t}px`,this.element.style.top=`${n}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()}})}update(e,t){const{state:n}=e,i=n.selection.from!==n.selection.to;if(this.updateDelay>0&&i){this.handleDebouncedUpdate(e,t);return}const s=!(t!=null&&t.selection.eq(e.state.selection)),r=!(t!=null&&t.doc.eq(e.state.doc));this.updateHandler(e,s,r,t)}getShouldShow(e){var t;const{state:n}=this.view,{selection:i}=n,{ranges:s}=i,r=Math.min(...s.map(c=>c.$from.pos)),o=Math.max(...s.map(c=>c.$to.pos));return((t=this.shouldShow)==null?void 0:t.call(this,{editor:this.editor,element:this.element,view:this.view,state:n,oldState:e,from:r,to:o}))||!1}show(){var e;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const t=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(e=t??this.view.dom.parentElement)==null||e.appendChild(this.element),this.floatingUIOptions.onShow&&this.floatingUIOptions.onShow(),this.isVisible=!0}hide(){this.isVisible&&(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.remove(),this.floatingUIOptions.onHide&&this.floatingUIOptions.onHide(),this.isVisible=!1)}updateOptions(e){var t;if(e.updateDelay!==void 0&&(this.updateDelay=e.updateDelay),e.resizeDelay!==void 0&&(this.resizeDelay=e.resizeDelay),e.appendTo!==void 0&&(this.appendTo=e.appendTo),e.getReferencedVirtualElement!==void 0&&(this.getReferencedVirtualElement=e.getReferencedVirtualElement),e.shouldShow!==void 0&&e.shouldShow&&(this.shouldShow=e.shouldShow),e.options!==void 0){const n=(t=e.options.scrollTarget)!=null?t:window;n!==this.scrollTarget&&(this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.scrollTarget=n,this.scrollTarget.addEventListener("scroll",this.resizeHandler)),this.floatingUIOptions={...this.floatingUIOptions,...e.options}}}destroy(){this.hide(),this.element.removeEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.view.dom.removeEventListener("dragstart",this.dragstartHandler),window.removeEventListener("resize",this.resizeHandler),this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.editor.off("transaction",this.transactionHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},Ks=e=>new G.Plugin({key:typeof e.pluginKey=="string"?new G.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Xo({view:t,...e})});O.Extension.create({name:"bubbleMenu",addOptions(){return{element:null,pluginKey:"bubbleMenu",updateDelay:void 0,appendTo:void 0,shouldShow:null}},addProseMirrorPlugins(){return this.options.element?[Ks({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,updateDelay:this.options.updateDelay,options:this.options.options,appendTo:this.options.appendTo,getReferencedVirtualElement:this.options.getReferencedVirtualElement,shouldShow:this.options.shouldShow})]:[]}});var Zo=class{constructor({editor:e,element:t,view:n,pluginKey:i="floatingMenu",updateDelay:s=250,resizeDelay:r=60,options:o,appendTo:l,shouldShow:c}){this.preventHide=!1,this.isVisible=!1,this.scrollTarget=window,this.shouldShow=({view:u,state:h})=>{const{selection:f}=h,{$anchor:p,empty:g}=f,x=p.depth===1,b=p.parent.isTextblock&&!p.parent.type.spec.code&&!p.parent.textContent&&p.parent.childCount===0&&!this.getTextContent(p.parent);return!(!u.hasFocus()||!g||!x||!b||!this.editor.isEditable)},this.floatingUIOptions={strategy:"absolute",placement:"right",offset:8,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1},this.updateHandler=(u,h,f,p)=>{const{composing:g}=u;if(g||!h&&!f)return;if(!this.getShouldShow(p)){this.hide();return}this.updatePosition(),this.show()},this.mousedownHandler=()=>{this.preventHide=!0},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:u})=>{var h;if(this.preventHide){this.preventHide=!1;return}u!=null&&u.relatedTarget&&((h=this.element.parentNode)!=null&&h.contains(u.relatedTarget))||(u==null?void 0:u.relatedTarget)!==this.editor.view.dom&&this.hide()},this.transactionHandler=({transaction:u})=>{const h=u.getMeta(this.pluginKey);h==="updatePosition"?this.updatePosition():h&&typeof h=="object"&&h.type==="updateOptions"?this.updateOptions(h.options):h==="hide"?this.hide():h==="show"&&(this.updatePosition(),this.show())},this.resizeHandler=()=>{this.resizeDebounceTimer&&clearTimeout(this.resizeDebounceTimer),this.resizeDebounceTimer=window.setTimeout(()=>{this.updatePosition()},this.resizeDelay)};var a;this.editor=e,this.element=t,this.view=n,this.pluginKey=i,this.updateDelay=s,this.resizeDelay=r,this.appendTo=l,this.scrollTarget=(a=o==null?void 0:o.scrollTarget)!=null?a:window,this.floatingUIOptions={...this.floatingUIOptions,...o},this.element.tabIndex=0,c&&(this.shouldShow=c),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.editor.on("transaction",this.transactionHandler),window.addEventListener("resize",this.resizeHandler),this.scrollTarget.addEventListener("scroll",this.resizeHandler),this.update(n,n.state),this.getShouldShow()&&(this.show(),this.updatePosition())}getTextContent(e){return O.getText(e,{textSerializers:O.getTextSerializersFromSchema(this.editor.schema)})}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(W.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(W.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(W.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(W.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(W.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(W.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(W.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(W.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}getShouldShow(e){var t;const{state:n}=this.view,{selection:i}=n,{ranges:s}=i,r=Math.min(...s.map(c=>c.$from.pos)),o=Math.max(...s.map(c=>c.$to.pos));return(t=this.shouldShow)==null?void 0:t.call(this,{editor:this.editor,view:this.view,state:n,oldState:e,from:r,to:o})}updateOptions(e){var t;if(e.updateDelay!==void 0&&(this.updateDelay=e.updateDelay),e.resizeDelay!==void 0&&(this.resizeDelay=e.resizeDelay),e.appendTo!==void 0&&(this.appendTo=e.appendTo),e.shouldShow!==void 0&&e.shouldShow&&(this.shouldShow=e.shouldShow),e.options!==void 0){const n=(t=e.options.scrollTarget)!=null?t:window;n!==this.scrollTarget&&(this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.scrollTarget=n,this.scrollTarget.addEventListener("scroll",this.resizeHandler)),this.floatingUIOptions={...this.floatingUIOptions,...e.options}}}updatePosition(){var e,t;if(!((t=(e=this.view)==null?void 0:e.dom)!=null&&t.parentNode))return;const{selection:n}=this.editor.state,i=O.posToDOMRect(this.view,n.from,n.to),s={getBoundingClientRect:()=>i,getClientRects:()=>[i]};W.computePosition(s,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:r,y:o,strategy:l,middlewareData:c})=>{var a,u;if((a=c.hide)!=null&&a.referenceHidden||(u=c.hide)!=null&&u.escaped){this.element.style.visibility="hidden";return}this.element.style.visibility="visible",this.element.style.width="max-content",this.element.style.position=l,this.element.style.left=`${r}px`,this.element.style.top=`${o}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()})}update(e,t){const n=!(t!=null&&t.selection.eq(e.state.selection)),i=!(t!=null&&t.doc.eq(e.state.doc));this.updateHandler(e,n,i,t)}show(){var e;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const t=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(e=t??this.view.dom.parentElement)==null||e.appendChild(this.element),this.floatingUIOptions.onShow&&this.floatingUIOptions.onShow(),this.isVisible=!0}hide(){this.isVisible&&(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.remove(),this.floatingUIOptions.onHide&&this.floatingUIOptions.onHide(),this.isVisible=!1)}destroy(){this.hide(),this.element.removeEventListener("mousedown",this.mousedownHandler,{capture:!0}),window.removeEventListener("resize",this.resizeHandler),this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.editor.off("transaction",this.transactionHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},qs=e=>new G.Plugin({key:typeof e.pluginKey=="string"?new G.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Zo({view:t,...e})});O.Extension.create({name:"floatingMenu",addOptions(){return{element:null,options:{},pluginKey:"floatingMenu",updateDelay:void 0,resizeDelay:void 0,appendTo:void 0,shouldShow:null}},addCommands(){return{updateFloatingMenuPosition:()=>({tr:e,dispatch:t})=>(t&&e.setMeta(this.options.pluginKey,"updatePosition"),!0)}},addProseMirrorPlugins(){return this.options.element?[qs({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,updateDelay:this.options.updateDelay,resizeDelay:this.options.resizeDelay,options:this.options.options,appendTo:this.options.appendTo,shouldShow:this.options.shouldShow})]:[]}});function Ws(e,t){return e??new G.PluginKey(t)}var Qo=typeof window<"u"?w.useLayoutEffect:w.useEffect,Gs=new Set(["left","opacity","position","top","visibility","width"]),tl=new Set(["animationIterationCount","aspectRatio","borderImageOutset","borderImageSlice","borderImageWidth","columnCount","columns","fillOpacity","flex","flexGrow","flexShrink","fontWeight","gridArea","gridColumn","gridColumnEnd","gridColumnStart","gridRow","gridRowEnd","gridRowStart","lineClamp","lineHeight","opacity","order","orphans","scale","stopOpacity","strokeDasharray","strokeDashoffset","strokeMiterlimit","strokeOpacity","strokeWidth","tabSize","widows","zIndex","zoom"]),el=new Set(["children","className","style"]),nl=new Set(["tabIndex"]),il=new Set(["accessKey","autoCapitalize","contentEditable","contextMenu","dir","draggable","enterKeyHint","hidden","id","lang","nonce","role","slot","spellCheck","tabIndex","title","translate"]),sl={Blur:"focusout",DoubleClick:"dblclick",Focus:"focusin",MouseEnter:"mouseenter",MouseLeave:"mouseleave"};function oi(e,t){return/^on[A-Z]/.test(e)&&typeof t=="function"}function rl(e){return e.startsWith("aria-")||e.startsWith("data-"),e}function ol(e){return e.startsWith("aria-")||e.startsWith("data-")||il.has(e)}function Ys(e){return e.startsWith("--")?e:e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}function ll(e){var t;const n=e.endsWith("Capture"),s=(n?e.slice(0,-7):e).slice(2);return{eventName:(t=sl[s])!=null?t:s.toLowerCase(),options:n?{capture:!0}:void 0}}function cl(e,t){let n=t.defaultPrevented,i=!1;const s=Object.create(t);return Object.defineProperties(s,{nativeEvent:{value:t},currentTarget:{value:e},target:{value:t.target},persist:{value:()=>{}},isDefaultPrevented:{value:()=>n},isPropagationStopped:{value:()=>i},preventDefault:{value:()=>{n=!0,t.preventDefault()}},stopPropagation:{value:()=>{i=!0,t.stopPropagation()}}}),s}function Fn(e){return nl.has(e)}function ts(e,t,n){if(t==="tabIndex"){e.tabIndex=Number(n);return}e[t]=n}function al(e,t){if(t==="tabIndex"){e.removeAttribute("tabindex");return}const n=e[t];if(typeof n=="boolean"){e[t]=!1;return}if(typeof n=="number"){e[t]=0;return}e[t]=""}function hl(e,t){return typeof t!="number"||t===0||e.startsWith("--")||tl.has(e)?String(t):`${t}px`}function ul(e,t){Gs.has(t)||e.style.removeProperty(Ys(t))}function dl(e,t,n){Gs.has(t)||e.style.setProperty(Ys(t),hl(t,n))}function fl(e,t,n){new Set([...Object.keys(t),...Object.keys(n)]).forEach(s=>{if(el.has(s)||!ol(s)||oi(s,t[s])||oi(s,n[s]))return;const r=t[s],o=n[s];if(r===o)return;const l=rl(s);if(o==null||o===!1){Fn(s)&&al(e,s),e.removeAttribute(l);return}if(o===!0){Fn(s)&&ts(e,s,!0),e.setAttribute(l,"");return}if(Fn(s)){ts(e,s,o);return}e.setAttribute(l,String(o))})}function pl(e,t,n){if(t!==n){if(n){e.className=n;return}e.removeAttribute("class")}}function gl(e,t,n){const i=t??{},s=n??{};new Set([...Object.keys(i),...Object.keys(s)]).forEach(o=>{const l=i[o],c=s[o];if(l!==c){if(c==null){ul(e,o);return}dl(e,o,c)}})}function ml(e,t,n){t.forEach(({eventName:s,listener:r,options:o})=>{e.removeEventListener(s,r,o)});const i=[];return Object.entries(n).forEach(([s,r])=>{if(!oi(s,r))return;const{eventName:o,options:l}=ll(s),c=a=>{r(cl(e,a))};e.addEventListener(o,c,l),i.push({eventName:o,listener:c,options:l})}),i}function Js(e,t){const n=w.useRef({}),i=w.useRef([]);Qo(()=>{const s=n.current;return pl(e,s.className,t.className),gl(e,s.style,t.style),fl(e,s,t),i.current=ml(e,i.current,t),n.current=t,()=>{i.current.forEach(({eventName:r,listener:o,options:l})=>{e.removeEventListener(r,o,l)}),i.current=[]}},[e,t])}var ot=w.forwardRef(({pluginKey:e,editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:r=null,getReferencedVirtualElement:o,options:l,children:c,...a},u)=>{const h=w.useRef(document.createElement("div")),f=w.useRef(Ws(e,"bubbleMenu")).current;Js(h.current,a),typeof u=="function"?u(h.current):u&&(u.current=h.current);const{editor:p}=Fs.useCurrentEditor(),g=t||p,x={updateDelay:n,resizeDelay:i,appendTo:s,pluginKey:f,shouldShow:r,getReferencedVirtualElement:o,options:l},b=w.useRef(x);b.current=x;const[y,C]=w.useState(!1),S=w.useRef(!0);return w.useEffect(()=>{if(g!=null&&g.isDestroyed)return;if(!g){console.warn("BubbleMenu component is not rendered inside of an editor component or does not have editor prop.");return}const _=h.current;_.style.visibility="hidden",_.style.position="absolute";const U=Ks({...b.current,editor:g,element:_});g.registerPlugin(U);const I=b.current.pluginKey;return S.current=!0,C(!0),()=>{C(!1),g.unregisterPlugin(I),window.requestAnimationFrame(()=>{_.parentNode&&_.parentNode.removeChild(_)})}},[g]),w.useEffect(()=>{if(!(!y||!g||g.isDestroyed)){if(S.current){S.current=!1;return}g.view.dispatch(g.state.tr.setMeta(f,{type:"updateOptions",options:b.current}))}},[y,g,n,i,r,l,s,o,f]),Ei.createPortal(c,h.current)});w.forwardRef(({pluginKey:e,editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:r=null,options:o,children:l,...c},a)=>{const u=w.useRef(document.createElement("div")),h=w.useRef(Ws(e,"floatingMenu")).current;Js(u.current,c),typeof a=="function"?a(u.current):a&&(a.current=u.current);const{editor:f}=Fs.useCurrentEditor(),p=t||f,g={updateDelay:n,resizeDelay:i,appendTo:s,pluginKey:h,shouldShow:r,options:o},x=w.useRef(g);x.current=g;const[b,y]=w.useState(!1),C=w.useRef(!0);return w.useEffect(()=>{if(p!=null&&p.isDestroyed)return;if(!p){console.warn("FloatingMenu component is not rendered inside of an editor component or does not have editor prop.");return}const S=u.current;S.style.visibility="hidden",S.style.position="absolute";const _=qs({...x.current,editor:p,element:S});p.registerPlugin(_);const U=x.current.pluginKey;return C.current=!0,y(!0),()=>{y(!1),p.unregisterPlugin(U),window.requestAnimationFrame(()=>{S.parentNode&&S.parentNode.removeChild(S)})}},[p]),w.useEffect(()=>{if(!(!b||!p||p.isDestroyed)){if(C.current){C.current=!1;return}p.view.dispatch(p.state.tr.setMeta(h,{type:"updateOptions",options:x.current}))}},[b,p,n,i,r,o,s,h]),Ei.createPortal(l,u.current)});function Yt(e,t){const{state:n}=t,i=n.selection.$anchor;let s=!1;if(i.depth)for(let r=i.depth;r>0;r--)i.node(r).type.name===e&&(t.dispatchTransaction&&t.dispatchTransaction(n.tr.delete(i.before(r),i.after(r)).scrollIntoView()),s=!0);else{const r=n.selection.node;r&&r.type.name===e&&(t.chain().deleteSelection().run(),s=!0)}if(!s){const r=i.pos;if(r){const o=n.tr.doc.nodeAt(r);o&&o.type.name===e&&(t.dispatchTransaction&&t.dispatchTransaction(n.tr.delete(r,r+o.nodeSize)),s=!0)}}return s}const xl=[{value:"note",label:"Note",icon:"Info"},{value:"tip",label:"Tip",icon:"Lightbulb"},{value:"important",label:"Important",icon:"AlertCircle"},{value:"warning",label:"Warning",icon:"TriangleAlert"},{value:"caution",label:"Caution",icon:"OctagonAlert"}];function wl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=P.useLocale(),{type:i,title:s,body:r}=xt.useAttributes(t,$e.Callout.name,{type:"note",title:"",body:""}),[o,l]=w.useState(!1),[c,a]=w.useState("note"),[u,h]=w.useState(""),[f,p]=w.useState("");w.useEffect(()=>{o&&(a(i||"note"),h(s||""),p(r||""))},[o,i,s,r]);const g=w.useCallback(()=>{t&&(t.chain().updateAttributes($e.Callout.name,{type:c,title:u,body:f}).focus().run(),l(!1))},[t,c,u,f]),x=w.useCallback(()=>{l(!1)},[]),b=w.useCallback(()=>{Yt($e.Callout.name,t)},[t]),y=w.useCallback(()=>t.isActive($e.Callout.name),[t]);return e?d.jsx(ot,{editor:t,options:{placement:"top",offset:8,flip:!0},pluginKey:"RichTextBubbleCallout",shouldShow:y,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsxs(m.Dialog,{onOpenChange:l,open:o,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{icon:"Pencil",tooltip:n("editor.callout.edit.title")})}),d.jsxs(m.DialogContent,{children:[d.jsx(m.DialogTitle,{children:n("editor.callout.edit.title")}),d.jsxs("div",{className:"richtext-space-y-4 richtext-py-4",children:[d.jsxs("div",{className:"richtext-space-y-2",children:[d.jsx(m.Label,{children:n("editor.callout.dialog.type")}),d.jsxs(m.Select,{onValueChange:a,value:c,children:[d.jsx(m.SelectTrigger,{children:d.jsx(m.SelectValue,{className:"richtext-text-accent",placeholder:n("editor.callout.dialog.type.placeholder")})}),d.jsx(m.SelectContent,{children:xl.map(C=>d.jsx(m.SelectItem,{value:C.value,children:n(`editor.callout.type.${C.value}`)},C.value))})]})]}),d.jsxs("div",{className:"richtext-space-y-2",children:[d.jsx(m.Label,{children:n("editor.callout.dialog.title.label")}),d.jsx(m.Input,{onChange:C=>h(C.target.value),placeholder:n("editor.callout.dialog.title.placeholder"),type:"text",value:u})]}),d.jsxs("div",{className:"richtext-space-y-2",children:[d.jsx(m.Label,{children:n("editor.callout.dialog.body.label")}),d.jsx(m.Input,{onChange:C=>p(C.target.value),placeholder:n("editor.callout.dialog.body.placeholder"),type:"text",value:f})]})]}),d.jsxs(m.DialogFooter,{children:[d.jsx(m.Button,{onClick:x,variant:"outline",children:n("editor.callout.dialog.button.cancel")}),d.jsx(m.Button,{onClick:g,children:n("editor.callout.dialog.button.apply")})]})]})]}),d.jsx(m.ActionButton,{action:b,icon:"Trash2",tooltip:n("editor.delete")})]})}):d.jsx(d.Fragment,{})}function bl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=P.useLocale(),i=w.useCallback(()=>t.isActive(Zi.MultipleColumnNode.name),[t]),s=w.useCallback(()=>Yt(Zi.MultipleColumnNode.name,t),[t]),r=w.useCallback(()=>t.chain().focus().addColBefore().run(),[t]),o=w.useCallback(()=>t.chain().focus().addColAfter().run(),[t]),l=w.useCallback(()=>t.chain().focus().deleteCol().run(),[t]);return e?d.jsx(ot,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleColumns",shouldShow:i,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{action:r,icon:"ColumnAddLeft",tooltip:n("editor.table.menu.insertColumnBefore")}),d.jsx(m.ActionButton,{action:o,icon:"ColumnAddRight",tooltip:n("editor.table.menu.insertColumnAfter")}),d.jsx(m.ActionButton,{action:l,icon:"DeleteColumn",tooltip:n("editor.table.menu.deleteColumn")}),d.jsx(m.ActionButton,{action:s,icon:"Trash2",tooltip:n("editor.table.menu.delete_column")})]})}):d.jsx(d.Fragment,{})}function yl(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,r)=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[r],action:()=>e.commands.updateImage({width:P.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:P.IMAGE_SIZE[s]})}}))}function Sl(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,r)=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[r],action:()=>e.commands.updateImageGif({width:P.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:P.IMAGE_SIZE[s]})}}))}function vl(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImage)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function Cl(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImageGif)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function kl(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImageMermaid)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function El(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImageDrawer)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function Tl(e){return[{type:"flex-start",icon:"AlignLeft",tooltip:"Align left"},{type:"center",icon:"AlignCenter",tooltip:"Align center"},{type:"flex-end",icon:"AlignRight",tooltip:"Align right"}].map(n=>({type:`video-align-${n.type}`,component:m.ActionButton,componentProps:{tooltip:n.tooltip,icon:n.icon,action:()=>e.commands.updateVideo({align:n.type}),isActive:()=>e.getAttributes("video").align===n.type}}))}function _l(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,r)=>({type:`video-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[r],action:()=>e.commands.updateVideo({width:P.VIDEO_SIZE[s]}),isActive:()=>e.isActive("video",{width:P.VIDEO_SIZE[s]})}}))}function Dl(e,t){return[{type:"flipX",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.tooltip.flipX"),icon:"FlipX",action:()=>{const n=e.getAttributes("image"),{flipX:i}=n;e.chain().focus(void 0,{scrollIntoView:!1}).updateImage({flipX:!i}).run()}}},{type:"flipY",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.tooltip.flipY"),icon:"FlipY",action:()=>{const n=e.getAttributes("image"),{flipY:i}=n;e.chain().focus(void 0,{scrollIntoView:!1}).updateImage({flipY:!i}).run()}}},...yl(e,t),...vl(e,t),{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;O.deleteSelection(n,i)}}}]}function Al(e,t){return[...Sl(e,t),...Cl(e,t),{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;O.deleteSelection(n,i)}}}]}function Il(e,t){return[...kl(e,t),{type:"edit",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;O.deleteSelection(n,i)}}}]}function Ml(e,t){return[...El(e,t),{type:"edit",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;O.deleteSelection(n,i)}}}]}function Ol(e,t){return[..._l(e,t),...Tl(e),{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;O.deleteSelection(n,i)}}}]}let be=!1;function Rl({editor:e,attrs:t,extension:n}){const[i,s]=w.useState(!1),r=w.useRef(null),o=w.useRef(null),{alt:l,align:c}=t,a=n==null?void 0:n.options.upload,u=()=>{(async()=>{const E=document.querySelector("#easydrawer");E&&(r.current=new Qi.Editor(E,{wheelEventsEnabled:!1,disableZoom:!0}),o.current=Qi.makeDropdownToolbar(r.current),o.current.addDefaultToolWidgets(),r.current.loadFromSVG(decodeURIComponent(l)))})()};w.useEffect(()=>{i&&setTimeout(()=>{u()},200)},[i]);const h=async()=>{if(r.current){const I=r.current.toSVG(),E=I.outerHTML,M=`drawer-${nn.shortId()}.svg`;let Q=nn.i(I.outerHTML);if(a){const nt=m.dataURLtoFile(Q,M);Q=await a(nt)}e==null||e.chain().focus().setDrawer({type:"drawer",src:Q,alt:encodeURIComponent(E),width:426,height:212},!!E).run(),e==null||e.commands.setAlignImageDrawer(c)}s(!1)},f=I=>{const E=r.current.toolController.getPrimaryTools()[2],M=o.current.getWidgetById("pen-1");E&&M&&(E.setColor(I),M.serializeState())},p=I=>{const E=r.current.toolController.getPrimaryTools()[2],M=o.current.getWidgetById("pen-1");E&&M&&(E.setThickness(I),M.serializeState())},g=I=>{const E=r.current.toolController.getPrimaryTools()[3],M=o.current.getWidgetById("pen-2");E&&M&&(E.setColor(I),M.serializeState())},x=I=>{const E=o.current.getWidgetById("shape");E&&E.setShapeType(I)},b=I=>{const E=r.current.toolController.getPrimaryTools()[5],M=o.current.getWidgetById("shape");E&&M&&(E.setColor(I),M.serializeState())},y=I=>{const E=r.current.toolController.getPrimaryTools()[5],M=o.current.getWidgetById("shape");E&&M&&(E.setThickness(I),M.serializeState())},C=I=>{const E=r.current.toolController.getPrimaryTools()[5],M=o.current.getWidgetById("shape");E&&M&&(E.setBorderColor(I),M.serializeState())},S=()=>{if(be){for(;r.current.history.redoStackSize>0;)r.current.history.redo();be=!1;return}r.current.history.undo()},_=()=>{be||r.current.history.redo()},U=()=>{if(!be){for(;r.current.history.undoStackSize>0;)S();be=!0}};return d.jsxs(m.Dialog,{onOpenChange:s,open:i,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{action:()=>s(!0),icon:"Pencil",tooltip:"Edit Drawer"})}),d.jsxs(m.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[d.jsx(m.DialogTitle,{children:"Edit Drawer"}),d.jsxs("div",{style:{height:"100%",borderWidth:1,background:"white",position:"relative"},children:[d.jsx("div",{className:"richtext-size-full",id:"easydrawer"}),d.jsx(We.ControlDrawer,{changeBorderColorShape:C,changeColorShape:b,changeShape:x,onClear:U,onRedo:_,onThicknessChange:y,onUndo:S,refEditor:r,setColorHighlight:g,setColorPen:f,setThicknessPen:p})]}),d.jsx(m.DialogFooter,{children:d.jsx(m.Button,{onClick:h,type:"button",children:"Save changes"})})]})]})}function jl({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?d.jsx(w.Fragment,{children:e.type==="divider"?d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):d.jsx(i,{...e.componentProps,disabled:t||((s=e==null?void 0:e.componentProps)==null?void 0:s.disabled),editor:n})}):d.jsx(d.Fragment,{})}function Nl(){const{lang:e,t}=P.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=xt.useAttributes(i,We.Drawer.name),r=m.useExtension(We.Drawer.name),o=({editor:c})=>{const{selection:a}=c.view.state,{$from:u,to:h}=a;let f=!1;return c.view.state.doc.nodesBetween(u.pos,h,p=>{if(p.type.name===We.Drawer.name)return f=!0,!1}),f},l=w.useMemo(()=>Ml(i,t),[i,e,t]);return n?d.jsx(ot,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleDrawer",shouldShow:o,children:l!=null&&l.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:l==null?void 0:l.map((c,a)=>c.type==="edit"&&(s!=null&&s.src)?d.jsx(Rl,{attrs:s,editor:i,extension:r},`bubbleMenu-drawer-${a}`):d.jsx(jl,{editor:i,item:c},`bubbleMenu-drawer-${a}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}const Xs=({width:e,maxWidth:t,height:n,onOk:i,children:s})=>{const{t:r}=P.useLocale(),[o,l]=w.useState({width:"",height:"",maxWidth:""});w.useEffect(()=>{l({width:e,height:n,maxWidth:t})},[n,t,e]);function c(a){a.preventDefault(),a.stopPropagation(),i(o)}return d.jsxs(At.Popover,{modal:!0,children:[d.jsx(At.PopoverTrigger,{asChild:!0,children:s}),d.jsx(At.PopoverContent,{children:d.jsxs("form",{className:"richtext-flex richtext-flex-col richtext-gap-2",onSubmit:c,children:[d.jsx(m.Label,{className:"mb-[6px]",children:"Width"}),d.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:d.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:d.jsx(m.Input,{onChange:a=>l({...o,width:a.target.value}),required:!0,type:"number",value:o.width})})}),d.jsx(m.Label,{className:"mb-[6px]",children:"Max Width"}),d.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:d.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:d.jsx(m.Input,{onChange:a=>l({...o,maxWidth:a.target.value}),required:!0,type:"number",value:o.maxWidth})})}),d.jsx(m.Label,{className:"mb-[6px]",children:"Height"}),d.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:d.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:d.jsx(m.Input,{onChange:a=>l({...o,height:a.target.value}),required:!0,type:"number",value:o.height})})}),d.jsx(m.Button,{className:"richtext-mt-2 richtext-self-end",type:"submit",children:r("editor.link.dialog.button.apply")})]})})]})},zt=new Map;function Bl(e){const t=e.options.element;zt.has("width")||zt.set("width",t.clientWidth),zt.has("width")&&zt.get("width")<=0&&zt.set("width",t.clientWidth);const n={attributes:!0,childList:!0,subtree:!0},i=function(){zt.set("width",t.clientWidth)},s=new MutationObserver(i);return s.observe(t,n),e.on("destroy",()=>{s.disconnect()}),{width:zt.get("width")}}function Ll(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=P.useLocale(),{width:i}=Bl(t),s=xt.useAttributes(t,xe.Excalidraw.name,{defaultShowPicker:!1,createUser:"",width:0,height:0}),{defaultShowPicker:r,createUser:o,width:l,height:c}=s,a=w.useCallback(p=>{t.chain().updateAttributes(xe.Excalidraw.name,p).setNodeSelection(t.state.selection.from).focus().run()},[t]),u=w.useCallback(()=>{const p=m.EVENTS.EXCALIDRAW(t.id);m.emit(p,s)},[t,s]),h=w.useCallback(()=>t.isActive(xe.Excalidraw.name),[t]),f=w.useCallback(()=>Yt(xe.Excalidraw.name,t),[t]);return w.useEffect(()=>{r&&(u(),t.chain().updateAttributes(xe.Excalidraw.name,{defaultShowPicker:!1}).focus().run())},[o,r,t,u]),e?d.jsx(ot,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleExcalidraw",shouldShow:h,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{action:u,icon:"Pencil",tooltip:n("editor.edit")}),d.jsx(Xs,{height:c,maxWidth:i,onOk:a,width:l,children:d.jsx(m.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),d.jsx(m.ActionButton,{action:f,icon:"Trash2",tooltip:n("editor.delete")})]})}):d.jsx(d.Fragment,{})}function Pl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=P.useLocale(),{width:i,height:s,src:r}=xt.useAttributes(t,Zt.Iframe.name,{width:0,height:0,src:"",defaultShowPicker:!1}),[o,l]=w.useState(!1),[c,a]=w.useState(""),u=w.useCallback(b=>{var y;(y=b==null?void 0:b.preventDefault)==null||y.call(b),l(!1)},[l]);w.useEffect(()=>{o&&a(r)},[o,r]);const h=w.useCallback(b=>{var C;(C=b==null?void 0:b.preventDefault)==null||C.call(b);const y=Zt.getServiceSrc(c);t.chain().updateAttributes(Zt.Iframe.name,{src:(y==null?void 0:y.src)||c}).setNodeSelection(t.state.selection.from).focus().run(),l(!1)},[t,c,l]),f=w.useCallback(()=>{window.open(r,"_blank")},[r]),p=w.useCallback(b=>{t.chain().updateAttributes(Zt.Iframe.name,b).setNodeSelection(t.state.selection.from).focus().run()},[t]),g=w.useCallback(()=>t.isActive(Zt.Iframe.name)&&!r,[t,r]),x=w.useCallback(()=>Yt(Zt.Iframe.name,t),[t]);return e?d.jsx(d.Fragment,{children:d.jsx(ot,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleIframe",shouldShow:g,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{action:f,icon:"Eye",tooltip:"Visit Link"}),d.jsxs(m.Dialog,{onOpenChange:l,open:o,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{icon:"Pencil",tooltip:"Open Edit Link"})}),d.jsxs(m.DialogContent,{children:[d.jsx(m.DialogHeader,{children:d.jsx(m.DialogTitle,{children:"Edit Link Iframe"})}),d.jsx(m.Input,{autoFocus:!0,onInput:b=>a(b.target.value),placeholder:"Enter link",type:"url",value:c}),d.jsxs(m.DialogFooter,{children:[d.jsx(m.Button,{onClick:u,type:"button",children:"Cancel"}),d.jsx(m.Button,{onClick:h,type:"button",children:"OK"})]})]})]}),d.jsx(Xs,{height:s,onOk:p,width:i,children:d.jsx(m.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),d.jsx(m.ActionButton,{action:x,icon:"Trash2",tooltip:n("editor.delete")})]})})}):d.jsx(d.Fragment,{})}function Ul({children:e,visible:t,toggleVisible:n}){const{t:i}=P.useLocale(),s=m.useEditorInstance(),r=xt.useAttributes(s,xt.Katex.name,{text:"",macros:""}),{text:o,macros:l}=r,[c,a]=w.useState(decodeURIComponent(o||"")),[u,h]=w.useState(decodeURIComponent(l||""));w.useEffect(()=>{t&&(a(decodeURIComponent(o||"")),h(decodeURIComponent(l||"")))},[t]);const f=w.useCallback(()=>{s.chain().focus().setKatex({text:encodeURIComponent(c),macros:encodeURIComponent(u)}).run(),a(""),h(""),n(!1)},[s,c,u,n]),p=w.useMemo(()=>{try{return Uo.renderToString(c,{macros:xt.safeJSONParse(u||"")})}catch{return c}},[c,u]),g=w.useMemo(()=>`${c}`.trim()?p:null,[c,p]);return d.jsxs(m.Dialog,{onOpenChange:n,open:t,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:e}),d.jsxs(m.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[d.jsx(m.DialogTitle,{children:i("editor.formula.dialog.text")}),d.jsx("div",{style:{height:"100%",border:"1px solid hsl(var(--border))"},children:d.jsxs("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[d.jsxs("div",{className:"richtext-flex-1",children:[d.jsx(m.Label,{className:"mb-[6px]",children:"Expression"}),d.jsx(m.Textarea,{autoFocus:!0,className:"richtext-mb-[10px]",onChange:x=>a(x.target.value),placeholder:"Text",required:!0,rows:10,value:c,style:{color:"hsl(var(--foreground))"}}),d.jsx(m.Label,{className:"mb-[6px]",children:"Macros"}),d.jsx(m.Textarea,{onChange:x=>h(x.target.value),placeholder:"Macros",rows:10,value:u,style:{color:"hsl(var(--foreground))"}})]}),d.jsx("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:g||""},style:{height:"100%",borderWidth:1,minHeight:500,background:"#fff"}})]})}),d.jsx(m.DialogFooter,{children:d.jsx(m.Button,{onClick:f,type:"button",children:"Save changes"})})]})]})}function zl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),[n,i]=w.useState(!1),s=w.useCallback(()=>t.isActive(xt.Katex.name),[t]),r=w.useCallback(()=>Yt(xt.Katex.name,t),[t]);return e?d.jsx(ot,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleKatex",shouldShow:s,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(Ul,{toggleVisible:i,visible:n,children:d.jsx(m.ActionButton,{action:()=>i(!n),tooltip:"Edit",children:d.jsx(Ht.Pencil,{size:16})})}),d.jsx(m.ActionButton,{action:r,tooltip:"Delete",children:d.jsx(Ht.Trash2,{size:16})})]})}):d.jsx(d.Fragment,{})}function $l(e){const{t}=P.useLocale();return d.jsxs("div",{className:"richtext-flex richtext-flex-nowrap",children:[d.jsx(m.ActionButton,{disabled:!(e!=null&&e.link),icon:"ExternalLink",tooltip:t("editor.link.open.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{window.open(e==null?void 0:e.link,"_blank")}}),d.jsx(m.ActionButton,{icon:"Pencil",tooltip:t("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onEdit()}}),d.jsx(m.ActionButton,{icon:"Unlink",tooltip:t("editor.link.unlink.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onClear()}})]})}function Vl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),[n,i]=w.useState(!1),s=xt.useAttributes(t,Ge.Link.name),r=s==null?void 0:s.href,o=w.useCallback(({editor:u})=>u.isActive(Ge.Link.name),[]),l=(u,h,f)=>{const p=t.state.selection,{from:g}=p,x=(h==null?void 0:h.length)??0,b=g+x;t.chain().extendMarkRange("link").insertContent({type:"text",text:h,marks:[{type:"link",attrs:{href:u,target:f?"_blank":""}}]}).setLink({href:u}).setTextSelection({from:g,to:b}).focus().run(),i(!1)},c=w.useCallback(()=>{t.chain().extendMarkRange("link").unsetLink().focus().run(),i(!1)},[t]),a=()=>{i(!1)};return e?d.jsx(ot,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleLink",shouldShow:o,children:d.jsx(d.Fragment,{children:n?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-4 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(Ge.LinkEditBlock,{editor:t,onClose:a,onSetLink:l})}):d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx($l,{editor:t,link:r,onClear:c,onEdit:()=>{i(!0)}})})})}):d.jsx(d.Fragment,{})}function Ti({item:e,disabled:t,editor:n}){const i=e.component;return i?d.jsx(w.Fragment,{children:e.type==="divider"?d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):d.jsx(i,{...e.componentProps,disabled:t||(e==null?void 0:e.componentdisabled),editor:n})}):d.jsx(d.Fragment,{})}function Fl(e){return e.type.name===m.Image.name}function Hl(e){return e.type.name===Po.ImageGif.name}function Kl(e){return e.type.name===m.Video.name}function ql(){const{lang:e,t}=P.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:o})=>{const{selection:l}=o.view.state,{$from:c,to:a}=l;let u=!1;return o.view.state.doc.nodesBetween(c.pos,a,h=>{if(Fl(h))return u=!0,!1}),u},r=w.useMemo(()=>Dl(i,t),[i,e,t]);return n?d.jsx(ot,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImage",shouldShow:s,children:r!=null&&r.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:r==null?void 0:r.map((o,l)=>d.jsx(Ti,{editor:i,item:o},`bubbleMenu-image-${l}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function Wl(){const{lang:e,t}=P.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:o})=>{const{selection:l}=o.view.state,{$from:c,to:a}=l;let u=!1;return o.view.state.doc.nodesBetween(c.pos,a,h=>{if(Hl(h))return u=!0,!1}),u},r=w.useMemo(()=>Al(i,t),[i,t,e]);return n?d.jsx(ot,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImageGif",shouldShow:s,children:r!=null&&r.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:r==null?void 0:r.map((o,l)=>d.jsx(Ti,{editor:i,item:o},`bubbleMenu-image-gif-${l}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function Gl(){const{t:e}=P.useLocale(),t=m.useEditableEditor(),n=m.useEditorInstance(),i=({editor:r})=>{const{selection:o}=r.view.state,{$from:l,to:c}=o;let a=!1;return r.view.state.doc.nodesBetween(l.pos,c,u=>{if(Kl(u))return a=!0,!1}),a},s=w.useMemo(()=>Ol(n,e),[n,e]);return t?d.jsx(ot,{editor:n,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleVideo",shouldShow:i,children:s!=null&&s.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:s==null?void 0:s.map((r,o)=>d.jsx(Ti,{editor:n,item:r},`bubbleMenu-video-${o}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}const es=`graph TB
2
+ a-->b`,Yl=({editor:e,attrs:t,extension:n})=>{const{alt:i,align:s}=t,[r,o]=w.useState(decodeURIComponent(i??es)),[l,c]=w.useState(""),[a,u]=w.useState(!1),h=w.useRef(null),[f,p]=w.useState(null),g=n==null?void 0:n.options.upload,x=w.useCallback(S=>{S&&import("mermaid").then(_=>{p(_.default)})},[]),b=async S=>{try{const{svg:_}=await f.render("mermaid-svg",S);c(_)}catch{c("")}},y=()=>{f.initialize({darkMode:!1,startOnLoad:!1,fontSize:12,theme:"base"}),b(r)};w.useEffect(()=>{f&&a&&y()},[f,a]),w.useEffect(()=>{f&&a&&b(r)},[f,r]);const C=async()=>{if(r!==""){if(r){const S=h.current.querySelector("svg"),{width:_,height:U}=S.getBoundingClientRect(),I=`mermaid-${nn.shortId()}.svg`;let E=nn.i(S.outerHTML);if(g){const M=m.dataURLtoFile(E,I);E=await g(M)}e==null||e.chain().focus().setMermaid({type:"mermaid",src:E,alt:encodeURIComponent(r),width:_,height:U},!!r).run(),e==null||e.commands.setAlignImageMermaid(s)}u(!1)}};return d.jsxs(m.Dialog,{onOpenChange:u,open:a,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{action:()=>u(!0),icon:"Pencil",tooltip:"Edit Mermaid"})}),d.jsxs(m.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[d.jsx(m.DialogTitle,{children:"Edit Mermaid"}),d.jsx("div",{ref:x,style:{height:"100%",border:"1px solid hsl(var(--border))"},children:d.jsxs("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[d.jsx(m.Textarea,{autoFocus:!0,className:"richtext-flex-1",defaultValue:es,onChange:S=>o(S.target.value),placeholder:"Text",required:!0,rows:10,value:r,style:{color:"hsl(var(--foreground))"}}),d.jsx("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:l},ref:h,style:{height:"100%",border:"1px solid hsl(var(--border))",minHeight:500}})]})}),d.jsx(m.DialogFooter,{children:d.jsx(m.Button,{onClick:C,type:"button",children:"Save changes"})})]})]})};function Jl({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?d.jsx(w.Fragment,{children:e.type==="divider"?d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):d.jsx(i,{...e.componentProps,disabled:t||((s=e==null?void 0:e.componentProps)==null?void 0:s.disabled),editor:n})}):d.jsx(d.Fragment,{})}function Xl(e){return e.type.name===ri.Mermaid.name}function Zl(){const{lang:e,t}=P.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=xt.useAttributes(i,ri.Mermaid.name),r=m.useExtension(ri.Mermaid.name),o=({editor:c})=>{const{selection:a}=c.view.state,{$from:u,to:h}=a;let f=!1;return c.view.state.doc.nodesBetween(u.pos,h,p=>{if(Xl(p))return f=!0,!1}),f},l=w.useMemo(()=>Il(i,t),[i,e,t]);return n?d.jsx(ot,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleMermaid",shouldShow:o,children:l!=null&&l.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:l==null?void 0:l.map((c,a)=>c.type==="edit"&&(s!=null&&s.src)?d.jsx(Yl,{attrs:s,editor:i,extension:r},`bubbleMenu-mermaid-${a}`):d.jsx(Jl,{editor:i,item:c},`bubbleMenu-mermaid-${a}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function Ql({hiddenActions:e=[]}){var x,b,y,C,S,_,U,I,E,M,Q,nt,ht,k,D,v,K,V;const{t}=P.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:q})=>O.isActive(q.view.state,Vs.Table.name),r=q=>e.includes(q);function o(){i.chain().focus().addColumnBefore().run()}function l(){i.chain().focus().addColumnAfter().run()}function c(){i.chain().focus().deleteColumn().run()}function a(){i.chain().focus().addRowBefore().run()}function u(){i.chain().focus().addRowAfter().run()}function h(){i.chain().focus().deleteRow().run()}function f(){i.chain().focus().mergeCells().run()}function p(){i==null||i.chain().focus().splitCell().run()}function g(){i.chain().focus().deleteTable().run()}return n?d.jsx(ot,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTable",shouldShow:s,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[!r("addColumnBefore")&&d.jsx(m.ActionButton,{action:o,disabled:!((b=(x=i==null?void 0:i.can())==null?void 0:x.addColumnBefore)!=null&&b.call(x)),icon:"BetweenHorizonalEnd",tooltip:t("editor.table.menu.insertColumnBefore"),tooltipOptions:{sideOffset:15}}),!r("addColumnAfter")&&d.jsx(m.ActionButton,{action:l,disabled:!((C=(y=i==null?void 0:i.can())==null?void 0:y.addColumnAfter)!=null&&C.call(y)),icon:"BetweenHorizonalStart",tooltip:t("editor.table.menu.insertColumnAfter"),tooltipOptions:{sideOffset:15}}),!r("deleteColumn")&&d.jsx(m.ActionButton,{action:c,disabled:!((_=i==null?void 0:(S=i.can()).deleteColumn)!=null&&_.call(S)),icon:"DeleteColumn",tooltip:t("editor.table.menu.deleteColumn"),tooltipOptions:{sideOffset:15}}),d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!r("addRowAbove")&&d.jsx(m.ActionButton,{action:a,disabled:!((I=i==null?void 0:(U=i.can()).addRowBefore)!=null&&I.call(U)),icon:"BetweenVerticalEnd",tooltip:t("editor.table.menu.insertRowAbove"),tooltipOptions:{sideOffset:15}}),!r("addRowBelow")&&d.jsx(m.ActionButton,{action:u,disabled:!((M=(E=i==null?void 0:i.can())==null?void 0:E.addRowAfter)!=null&&M.call(E)),icon:"BetweenVerticalStart",tooltip:t("editor.table.menu.insertRowBelow"),tooltipOptions:{sideOffset:15}}),!r("deleteRow")&&d.jsx(m.ActionButton,{action:h,disabled:!((nt=(Q=i==null?void 0:i.can())==null?void 0:Q.deleteRow)!=null&&nt.call(Q)),icon:"DeleteRow",tooltip:t("editor.table.menu.deleteRow"),tooltipOptions:{sideOffset:15}}),d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!r("mergeCells")&&d.jsx(m.ActionButton,{action:f,disabled:!((k=(ht=i==null?void 0:i.can())==null?void 0:ht.mergeCells)!=null&&k.call(ht)),icon:"TableCellsMerge",tooltip:t("editor.table.menu.mergeCells"),tooltipOptions:{sideOffset:15}}),!r("splitCells")&&d.jsx(m.ActionButton,{action:p,disabled:!((v=(D=i==null?void 0:i.can())==null?void 0:D.splitCell)!=null&&v.call(D)),icon:"TableCellsSplit",tooltip:t("editor.table.menu.splitCells"),tooltipOptions:{sideOffset:15}}),d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!r("deleteTable")&&d.jsx(m.ActionButton,{action:g,disabled:!((V=(K=i==null?void 0:i.can())==null?void 0:K.deleteTable)!=null&&V.call(K)),icon:"Trash2",tooltip:t("editor.table.menu.deleteTable"),tooltipOptions:{sideOffset:15}})]})}):d.jsx(d.Fragment,{})}function tc(){const{t:e}=P.useLocale(),[t,n]=w.useState(!1),i=m.useEditorInstance(),s=w.useMemo(()=>{var o,l;return(l=(o=Wo.renderCommandListDefault({t:e}))==null?void 0:o[0])==null?void 0:l.commands},[e]),r=w.useMemo(()=>{var l;return(l=s==null?void 0:s.find(c=>{var a;return(a=c==null?void 0:c.isActive)==null?void 0:a.call(c,i)}))==null?void 0:l.label},[i.state.selection.ranges,t,i,s,e]);return d.jsxs(At.Popover,{modal:!0,onOpenChange:n,open:t,children:[d.jsx(At.PopoverTrigger,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:d.jsxs(m.ActionButton,{dataState:!!r,children:[r?d.jsx(d.Fragment,{children:r}):d.jsx(d.Fragment,{children:e("editor.paragraph.tooltip")}),d.jsx(m.IconComponent,{className:"richtext-ml-1 richtext-size-3 richtext-text-zinc-500",name:"MenuDown"})]})}),d.jsx(At.PopoverContent,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:s==null?void 0:s.map(o=>{var c;const l=(c=o==null?void 0:o.isActive)==null?void 0:c.call(o,i);return d.jsxs("div",{className:"richtext-flex richtext-w-full richtext-items-center richtext-gap-3 richtext-rounded-sm !richtext-border-none !richtext-bg-transparent richtext-px-2 richtext-py-1.5 richtext-text-left richtext-text-sm richtext-text-foreground !richtext-outline-none richtext-transition-colors hover:!richtext-bg-accent",onClick:a=>{a.preventDefault(),o.action({editor:i,range:i.state.selection.ranges}),n(!1)},children:[d.jsxs("div",{className:"!richtext-min-w-[20px]",children:[l&&d.jsx(Ht.Check,{size:16}),!r&&o.label===e("editor.paragraph.tooltip")&&!l&&d.jsx(Ht.Check,{size:16})]}),d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:[o.iconName&&d.jsx(m.IconComponent,{className:"!richtext-mr-1 !richtext-text-lg",name:o.iconName}),o.label]})]},o.name)})})]})}function ec(){return d.jsxs(d.Fragment,{children:[d.jsx(tc,{}),d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(Vo.RichTextBold,{}),d.jsx(qo.RichTextItalic,{}),d.jsx(Yo.RichTextUnderline,{}),d.jsx(Go.RichTextStrike,{}),d.jsx(Fo.RichTextCode,{}),d.jsx(Ge.RichTextLink,{}),d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(Ho.RichTextColor,{}),d.jsx(Ko.RichTextHighlight,{}),d.jsx(Hs.RichTextAlign,{})]})}function nc({buttonBubble:e}){const t=m.useEditorInstance(),n=m.useEditableEditor(),i=({editor:s})=>{const{selection:r}=s.view.state,{$from:o,to:l}=r;return s.isActive("codeBlock")||o.pos===l?!1:r instanceof G.TextSelection};return n?d.jsx(ot,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleText",shouldShow:i,children:e?d.jsx(d.Fragment,{children:e}):d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(ec,{})})}):d.jsx(d.Fragment,{})}function ic(){const{t:e}=P.useLocale(),t=m.useEditableEditor(),n=m.useEditorInstance(),[i,s]=w.useState(!1),r=w.useCallback(({editor:c})=>c.isActive(Vn.Twitter.name),[]),o=c=>{n.commands.updateTweet({src:c}),s(!1)},l=w.useCallback(()=>Yt(Vn.Twitter.name,n),[n]);return t?d.jsx(ot,{editor:n,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTwitter",shouldShow:r,children:d.jsx(d.Fragment,{children:i?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-4 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(Vn.FormEditLinkTwitter,{editor:n,onSetLink:o})}):d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{icon:"Pencil",tooltip:e("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{s(!0)}}),d.jsx(m.ActionButton,{action:l,icon:"Trash",tooltip:e("editor.delete"),tooltipOptions:{sideOffset:15}})]})})}):d.jsx(d.Fragment,{})}const wt=()=>new Map,li=e=>{const t=wt();return e.forEach((n,i)=>{t.set(i,n)}),t},Ot=(e,t,n)=>{let i=e.get(t);return i===void 0&&e.set(t,i=n()),i},sc=(e,t)=>{const n=[];for(const[i,s]of e)n.push(t(s,i));return n},rc=(e,t)=>{for(const[n,i]of e)if(t(i,n))return!0;return!1},Kt=()=>new Set,Hn=e=>e[e.length-1],oc=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},qt=Array.from,_i=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},Di=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},lc=(e,t)=>{const n=new Array(e);for(let i=0;i<e;i++)n[i]=t(i,n);return n},re=Array.isArray;class Zs{constructor(){this._observers=wt()}on(t,n){return Ot(this._observers,t,Kt).add(n),n}once(t,n){const i=(...s)=>{this.off(t,i),n(...s)};this.on(t,i)}off(t,n){const i=this._observers.get(t);i!==void 0&&(i.delete(n),i.size===0&&this._observers.delete(t))}emit(t,n){return qt((this._observers.get(t)||wt()).values()).forEach(i=>i(...n))}destroy(){this._observers=wt()}}const bt=Math.floor,Ye=Math.abs,oe=(e,t)=>e<t?e:t,Bt=(e,t)=>e>t?e:t,Qs=e=>e!==0?e<0:1/e<0,ns=1,is=2,Kn=4,qn=8,Ce=32,It=64,st=128,cc=1<<29,vn=31,ci=63,Ft=127,ac=2147483647,sn=Number.MAX_SAFE_INTEGER,ss=Number.MIN_SAFE_INTEGER,hc=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&bt(e)===e),tr=String.fromCharCode,uc=e=>e.toLowerCase(),dc=/^\s*/g,fc=e=>e.replace(dc,""),pc=/([A-Z])/g,rs=(e,t)=>fc(e.replace(pc,n=>`${t}${uc(n)}`)),gc=e=>{const t=unescape(encodeURIComponent(e)),n=t.length,i=new Uint8Array(n);for(let s=0;s<n;s++)i[s]=t.codePointAt(s);return i},ke=typeof TextEncoder<"u"?new TextEncoder:null,mc=e=>ke.encode(e),xc=ke?mc:gc;let ve=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});ve&&ve.decode(new Uint8Array).length===1&&(ve=null);const wc=(e,t)=>lc(t,()=>e).join("");class Ne{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Be=()=>new Ne,bc=e=>{const t=Be();return e(t),mt(t)},yc=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},mt=e=>{const t=new Uint8Array(yc(e));let n=0;for(let i=0;i<e.bufs.length;i++){const s=e.bufs[i];t.set(s,n),n+=s.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},Sc=(e,t)=>{const n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(Bt(n,t)*2),e.cpos=0)},Y=(e,t)=>{const n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},ai=Y,A=(e,t)=>{for(;t>Ft;)Y(e,st|Ft&t),t=bt(t/128);Y(e,Ft&t)},Ai=(e,t)=>{const n=Qs(t);for(n&&(t=-t),Y(e,(t>ci?st:0)|(n?It:0)|ci&t),t=bt(t/64);t>0;)Y(e,(t>Ft?st:0)|Ft&t),t=bt(t/128)},hi=new Uint8Array(3e4),vc=hi.length/3,Cc=(e,t)=>{if(t.length<vc){const n=ke.encodeInto(t,hi).written||0;A(e,n);for(let i=0;i<n;i++)Y(e,hi[i])}else ct(e,xc(t))},kc=(e,t)=>{const n=unescape(encodeURIComponent(t)),i=n.length;A(e,i);for(let s=0;s<i;s++)Y(e,n.codePointAt(s))},te=ke&&ke.encodeInto?Cc:kc,Cn=(e,t)=>{const n=e.cbuf.length,i=e.cpos,s=oe(n-i,t.length),r=t.length-s;e.cbuf.set(t.subarray(0,s),i),e.cpos+=s,r>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(Bt(n*2,r)),e.cbuf.set(t.subarray(s)),e.cpos=r)},ct=(e,t)=>{A(e,t.byteLength),Cn(e,t)},Ii=(e,t)=>{Sc(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Ec=(e,t)=>Ii(e,4).setFloat32(0,t,!1),Tc=(e,t)=>Ii(e,8).setFloat64(0,t,!1),_c=(e,t)=>Ii(e,8).setBigInt64(0,t,!1),os=new DataView(new ArrayBuffer(4)),Dc=e=>(os.setFloat32(0,e),os.getFloat32(0)===e),le=(e,t)=>{switch(typeof t){case"string":Y(e,119),te(e,t);break;case"number":hc(t)&&Ye(t)<=ac?(Y(e,125),Ai(e,t)):Dc(t)?(Y(e,124),Ec(e,t)):(Y(e,123),Tc(e,t));break;case"bigint":Y(e,122),_c(e,t);break;case"object":if(t===null)Y(e,126);else if(re(t)){Y(e,117),A(e,t.length);for(let n=0;n<t.length;n++)le(e,t[n])}else if(t instanceof Uint8Array)Y(e,116),ct(e,t);else{Y(e,118);const n=Object.keys(t);A(e,n.length);for(let i=0;i<n.length;i++){const s=n[i];te(e,s),le(e,t[s])}}break;case"boolean":Y(e,t?120:121);break;default:Y(e,127)}};class ls extends Ne{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&A(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const cs=e=>{e.count>0&&(Ai(e.encoder,e.count===1?e.s:-e.s),e.count>1&&A(e.encoder,e.count-2))};class Je{constructor(){this.encoder=new Ne,this.s=0,this.count=0}write(t){this.s===t?this.count++:(cs(this),this.count=1,this.s=t)}toUint8Array(){return cs(this),mt(this.encoder)}}const as=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);Ai(e.encoder,t),e.count>1&&A(e.encoder,e.count-2)}};class Wn{constructor(){this.encoder=new Ne,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(as(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return as(this),mt(this.encoder)}}class Ac{constructor(){this.sarr=[],this.s="",this.lensE=new Je}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new Ne;return this.sarr.push(this.s),this.s="",te(t,this.sarr.join("")),Cn(t,this.lensE.toUint8Array()),mt(t)}}const _t=e=>new Error(e),pt=()=>{throw _t("Method unimplemented")},rt=()=>{throw _t("Unexpected case")},er=_t("Unexpected end of array"),nr=_t("Integer out of Range");class kn{constructor(t){this.arr=t,this.pos=0}}const Mi=e=>new kn(e),Ic=e=>e.pos!==e.arr.length,Mc=(e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},ut=e=>Mc(e,N(e)),Ee=e=>e.arr[e.pos++],N=e=>{let t=0,n=1;const i=e.arr.length;for(;e.pos<i;){const s=e.arr[e.pos++];if(t=t+(s&Ft)*n,n*=128,s<st)return t;if(t>sn)throw nr}throw er},Oi=e=>{let t=e.arr[e.pos++],n=t&ci,i=64;const s=(t&It)>0?-1:1;if((t&st)===0)return s*n;const r=e.arr.length;for(;e.pos<r;){if(t=e.arr[e.pos++],n=n+(t&Ft)*i,i*=128,t<st)return s*n;if(n>sn)throw nr}throw er},Oc=e=>{let t=N(e);if(t===0)return"";{let n=String.fromCodePoint(Ee(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(Ee(e));else for(;t>0;){const i=t<1e4?t:1e4,s=e.arr.subarray(e.pos,e.pos+i);e.pos+=i,n+=String.fromCodePoint.apply(null,s),t-=i}return decodeURIComponent(escape(n))}},Rc=e=>ve.decode(ut(e)),ui=ve?Rc:Oc,Ri=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},jc=e=>Ri(e,4).getFloat32(0,!1),Nc=e=>Ri(e,8).getFloat64(0,!1),Bc=e=>Ri(e,8).getBigInt64(0,!1),Lc=[e=>{},e=>null,Oi,jc,Nc,Bc,e=>!1,e=>!0,ui,e=>{const t=N(e),n={};for(let i=0;i<t;i++){const s=ui(e);n[s]=rn(e)}return n},e=>{const t=N(e),n=[];for(let i=0;i<t;i++)n.push(rn(e));return n},ut],rn=e=>Lc[127-Ee(e)](e);class hs extends kn{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Ic(this)?this.count=N(this)+1:this.count=-1),this.count--,this.s}}class Xe extends kn{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Oi(this);const t=Qs(this.s);this.count=1,t&&(this.s=-this.s,this.count=N(this)+2)}return this.count--,this.s}}class Gn extends kn{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=Oi(this),n=t&1;this.diff=bt(t/2),this.count=1,n&&(this.count=N(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Pc{constructor(t){this.decoder=new Xe(t),this.str=ui(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}}const Uc=crypto.getRandomValues.bind(crypto),zc=Math.random,ir=()=>Uc(new Uint32Array(1))[0],$c=e=>e[bt(zc()*e.length)],Vc="10000000-1000-4000-8000"+-1e11,Fc=()=>Vc.replace(/[018]/g,e=>(e^ir()&15>>e/4).toString(16)),Hc=Date.now,us=e=>new Promise(e);Promise.all.bind(Promise);const ds=e=>e===void 0?null:e;class Kc{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}}let sr=new Kc,qc=!0;try{typeof localStorage<"u"&&localStorage&&(sr=localStorage,qc=!1)}catch{}const Wc=sr,Te=Symbol("Equality"),rr=(e,t)=>{var n;return e===t||!!((n=e==null?void 0:e[Te])!=null&&n.call(e,t))||!1},Gc=e=>typeof e=="object",Yc=Object.assign,or=Object.keys,Jc=(e,t)=>{for(const n in e)t(e[n],n)},on=e=>or(e).length,Xc=e=>{for(const t in e)return!1;return!0},ue=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},ji=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Zc=(e,t)=>e===t||on(e)===on(t)&&ue(e,(n,i)=>(n!==void 0||ji(t,i))&&rr(t[i],n)),Qc=Object.freeze,lr=e=>{for(const t in e){const n=e[t];(typeof n=="object"||typeof n=="function")&&lr(e[t])}return Qc(e)},Ni=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Ni(e,t,n+1)}},Ze=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[Te]!=null)return e[Te](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:{if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break}case Set:{if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;break}case Map:{if(e.size!==t.size)return!1;for(const n of e.keys())if(!t.has(n)||!Ze(e.get(n),t.get(n)))return!1;break}case void 0:case Object:if(on(e)!==on(t))return!1;for(const n in e)if(!ji(e,n)||!Ze(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Ze(e[n],t[n]))return!1;break;default:return!1}return!0},ta=(e,t)=>t.includes(e),ce=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",cr=typeof window<"u"&&typeof document<"u"&&!ce;let Ct;const ea=()=>{if(Ct===void 0)if(ce){Ct=wt();const e=process.argv;let t=null;for(let n=0;n<e.length;n++){const i=e[n];i[0]==="-"?(t!==null&&Ct.set(t,""),t=i):t!==null&&(Ct.set(t,i),t=null)}t!==null&&Ct.set(t,"")}else typeof location=="object"?(Ct=wt(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){const[t,n]=e.split("=");Ct.set(`--${rs(t,"-")}`,n),Ct.set(`-${rs(t,"-")}`,n)}})):Ct=wt();return Ct},di=e=>ea().has(e),ln=e=>ds(ce?process.env[e.toUpperCase().replaceAll("-","_")]:Wc.getItem(e)),ar=e=>di("--"+e)||ln(e)!==null,na=ar("production"),ia=ce&&ta(process.env.FORCE_COLOR,["true","1","2"]),sa=ia||!di("--no-colors")&&!ar("no-color")&&(!ce||process.stdout.isTTY)&&(!ce||di("--color")||ln("COLORTERM")!==null||(ln("TERM")||"").includes("color")),ra=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=tr(e[n]);return btoa(t)},oa=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),la=cr?ra:oa,ca=e=>bc(t=>le(t,e));class aa{constructor(t,n){this.left=t,this.right=n}}const Dt=(e,t)=>new aa(e,t),fs=e=>e.next()>=.5,Yn=(e,t,n)=>bt(e.next()*(n+1-t)+t),hr=(e,t,n)=>bt(e.next()*(n+1-t)+t),Bi=(e,t,n)=>hr(e,t,n),ha=e=>tr(Bi(e,97,122)),ua=(e,t=0,n=20)=>{const i=Bi(e,t,n);let s="";for(let r=0;r<i;r++)s+=ha(e);return s},Jn=(e,t)=>t[Bi(e,0,t.length-1)],da=Symbol("0schema");class fa{constructor(){this._rerrs=[]}extend(t,n,i,s=null){this._rerrs.push({path:t,expected:n,has:i,message:s})}toString(){const t=[];for(let n=this._rerrs.length-1;n>0;n--){const i=this._rerrs[n];t.push(wc(" ",(this._rerrs.length-n)*2)+`${i.path!=null?`[${i.path}] `:""}${i.has} doesn't match ${i.expected}. ${i.message}`)}return t.join(`
3
+ `)}}const fi=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[Te]?rr(e,t):re(e)?_i(e,n=>Di(t,i=>fi(n,i))):Gc(e)?ue(e,(n,i)=>fi(n,t[i])):!1;class et{extends(t){let[n,i]=[this.shape,t.shape];return this.constructor._dilutes&&([i,n]=[n,i]),fi(n,i)}equals(t){return this.constructor===t.constructor&&Ze(this.shape,t.shape)}[da](){return!0}[Te](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){pt()}get nullable(){return de(this,An)}get optional(){return new fr(this)}cast(t){return ps(t,this),t}expect(t){return ps(t,this),t}}ze(et,"_dilutes",!1);class Li extends et{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n=void 0){const i=(t==null?void 0:t.constructor)===this.shape&&(this._c==null||this._c(t));return!i&&(n==null||n.extend(null,this.shape.name,t==null?void 0:t.constructor.name,(t==null?void 0:t.constructor)!==this.shape?"Constructor match failed":"Check failed")),i}}const H=(e,t=null)=>new Li(e,t);H(Li);class Pi extends et{constructor(t){super(),this.shape=t}check(t,n){const i=this.shape(t);return!i&&(n==null||n.extend(null,"custom prop",t==null?void 0:t.constructor.name,"failed to check custom prop")),i}}const X=e=>new Pi(e);H(Pi);class En extends et{constructor(t){super(),this.shape=t}check(t,n){const i=this.shape.some(s=>s===t);return!i&&(n==null||n.extend(null,this.shape.join(" | "),t.toString())),i}}const Tn=(...e)=>new En(e),ur=H(En),pa=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,t=>"\\"+t)),dr=e=>{if(ae.check(e))return[pa(e)];if(ur.check(e))return e.shape.map(t=>t+"");if(vr.check(e))return["[+-]?\\d+.?\\d*"];if(Cr.check(e))return[".*"];if(an.check(e))return e.shape.map(dr).flat(1);rt()};class ga extends et{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(dr).map(n=>`(${n.join("|")})`).join("")+"$")}check(t,n){const i=this._r.exec(t)!=null;return!i&&(n==null||n.extend(null,this._r.toString(),t.toString(),"String doesn't match string template.")),i}}H(ga);const ma=Symbol("optional");class fr extends et{constructor(t){super(),this.shape=t}check(t,n){const i=t===void 0||this.shape.check(t);return!i&&(n==null||n.extend(null,"undefined (optional)","()")),i}get[ma](){return!0}}const xa=H(fr);class wa extends et{check(t,n){return n==null||n.extend(null,"never",typeof t),!1}}H(wa);const Sn=class Sn extends et{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}get partial(){return new Sn(this.shape,!0)}check(t,n){return t==null?(n==null||n.extend(null,"object","null"),!1):ue(this.shape,(i,s)=>{const r=this._isPartial&&!ji(t,s)||i.check(t[s],n);return!r&&(n==null||n.extend(s.toString(),i.toString(),typeof t[s],"Object property does not match")),r})}};ze(Sn,"_dilutes",!0);let cn=Sn;const ba=e=>new cn(e),ya=H(cn),Sa=X(e=>e!=null&&(e.constructor===Object||e.constructor==null));class pr extends et{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return t!=null&&ue(t,(i,s)=>{const r=this.shape.keys.check(s,n);return!r&&(n==null||n.extend(s+"","Record",typeof t,r?"Key doesn't match schema":"Value doesn't match value")),r&&this.shape.values.check(i,n)})}}const gr=(e,t)=>new pr(e,t),va=H(pr);class mr extends et{constructor(t){super(),this.shape=t}check(t,n){return t!=null&&ue(this.shape,(i,s)=>{const r=i.check(t[s],n);return!r&&(n==null||n.extend(s.toString(),"Tuple",typeof i)),r})}}const Ca=(...e)=>new mr(e);H(mr);class xr extends et{constructor(t){super(),this.shape=t.length===1?t[0]:new _n(t)}check(t,n){const i=re(t)&&_i(t,s=>this.shape.check(s));return!i&&(n==null||n.extend(null,"Array","")),i}}const wr=(...e)=>new xr(e),ka=H(xr),Ea=X(e=>re(e));class br extends et{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n){const i=t instanceof this.shape&&(this._c==null||this._c(t));return!i&&(n==null||n.extend(null,this.shape.name,t==null?void 0:t.constructor.name)),i}}const Ta=(e,t=null)=>new br(e,t);H(br);const _a=Ta(et);class Da extends et{constructor(t){super(),this.len=t.length-1,this.args=Ca(...t.slice(-1)),this.res=t[this.len]}check(t,n){const i=t.constructor===Function&&t.length<=this.len;return!i&&(n==null||n.extend(null,"function",typeof t)),i}}const Aa=H(Da),Ia=X(e=>typeof e=="function");class Ma extends et{constructor(t){super(),this.shape=t}check(t,n){const i=_i(this.shape,s=>s.check(t,n));return!i&&(n==null||n.extend(null,"Intersectinon",typeof t)),i}}H(Ma,e=>e.shape.length>0);class _n extends et{constructor(t){super(),this.shape=t}check(t,n){const i=Di(this.shape,s=>s.check(t,n));return n==null||n.extend(null,"Union",typeof t),i}}ze(_n,"_dilutes",!0);const de=(...e)=>e.findIndex(t=>an.check(t))>=0?de(...e.map(t=>_e(t)).map(t=>an.check(t)?t.shape:[t]).flat(1)):e.length===1?e[0]:new _n(e),an=H(_n),yr=()=>!0,hn=X(yr),Oa=H(Pi,e=>e.shape===yr),Ui=X(e=>typeof e=="bigint"),Ra=X(e=>e===Ui),Sr=X(e=>typeof e=="symbol");X(e=>e===Sr);const ee=X(e=>typeof e=="number"),vr=X(e=>e===ee),ae=X(e=>typeof e=="string"),Cr=X(e=>e===ae),Dn=X(e=>typeof e=="boolean"),ja=X(e=>e===Dn),kr=Tn(void 0);H(En,e=>e.shape.length===1&&e.shape[0]===void 0);Tn(void 0);const An=Tn(null),Na=H(En,e=>e.shape.length===1&&e.shape[0]===null);H(Uint8Array);H(Li,e=>e.shape===Uint8Array);const Ba=de(ee,ae,An,kr,Ui,Dn,Sr);(()=>{const e=wr(hn),t=gr(ae,hn),n=de(ee,ae,An,Dn,e,t);return e.shape=n,t.shape.values=n,n})();const _e=e=>{if(_a.check(e))return e;if(Sa.check(e)){const t={};for(const n in e)t[n]=_e(e[n]);return ba(t)}else{if(Ea.check(e))return de(...e.map(_e));if(Ba.check(e))return Tn(e);if(Ia.check(e))return H(e)}rt()},ps=na?()=>{}:(e,t)=>{const n=new fa;if(!t.check(e,n))throw _t(`Expected value to be of type ${t.constructor.name}.
4
+ ${n.toString()}`)};class La{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:_e(t),h:n}),this}else(t){return this.if(hn,t)}done(){return(t,n)=>{for(let i=0;i<this.patterns.length;i++){const s=this.patterns[i];if(s.if.check(t))return s.h(t,n)}throw _t("Unhandled pattern")}}}const Pa=e=>new La(e),Er=Pa(hn).if(vr,(e,t)=>Yn(t,ss,sn)).if(Cr,(e,t)=>ua(t)).if(ja,(e,t)=>fs(t)).if(Ra,(e,t)=>BigInt(Yn(t,ss,sn))).if(an,(e,t)=>Qt(t,Jn(t,e.shape))).if(ya,(e,t)=>{const n={};for(const i in e.shape){let s=e.shape[i];if(xa.check(s)){if(fs(t))continue;s=s.shape}n[i]=Er(s,t)}return n}).if(ka,(e,t)=>{const n=[],i=hr(t,0,42);for(let s=0;s<i;s++)n.push(Qt(t,e.shape));return n}).if(ur,(e,t)=>Jn(t,e.shape)).if(Na,(e,t)=>null).if(Aa,(e,t)=>{const n=Qt(t,e.res);return()=>n}).if(Oa,(e,t)=>Qt(t,Jn(t,[ee,ae,An,kr,Ui,Dn,wr(ee),gr(de("a","b","c"),ee)]))).if(va,(e,t)=>{const n={},i=Yn(t,0,3);for(let s=0;s<i;s++){const r=Qt(t,e.shape.keys),o=Qt(t,e.shape.values);n[r]=o}return n}).done(),Qt=(e,t)=>Er(_e(t),e),Le=typeof document<"u"?document:{};X(e=>e.nodeType===Fa);typeof DOMParser<"u"&&new DOMParser;X(e=>e.nodeType===za);X(e=>e.nodeType===$a);const Ua=e=>sc(e,(t,n)=>`${n}:${t};`).join(""),za=Le.ELEMENT_NODE,$a=Le.TEXT_NODE,Va=Le.DOCUMENT_NODE,Fa=Le.DOCUMENT_FRAGMENT_NODE;X(e=>e.nodeType===Va);const Ha=e=>class{constructor(n){this._=n}destroy(){e(this._)}},Ka=Ha(clearTimeout),Tr=(e,t)=>new Ka(setTimeout(t,e)),Rt=Symbol,_r=Rt(),Dr=Rt(),qa=Rt(),Wa=Rt(),Ga=Rt(),Ar=Rt(),Ya=Rt(),zi=Rt(),Ja=Rt(),Xa=e=>{var s;e.length===1&&((s=e[0])==null?void 0:s.constructor)===Function&&(e=e[0]());const t=[],n=[];let i=0;for(;i<e.length;i++){const r=e[i];if(r===void 0)break;if(r.constructor===String||r.constructor===Number)t.push(r);else if(r.constructor===Object)break}for(i>0&&n.push(t.join(""));i<e.length;i++){const r=e[i];r instanceof Symbol||n.push(r)}return n},Za={[_r]:Dt("font-weight","bold"),[Dr]:Dt("font-weight","normal"),[qa]:Dt("color","blue"),[Ga]:Dt("color","green"),[Wa]:Dt("color","grey"),[Ar]:Dt("color","red"),[Ya]:Dt("color","purple"),[zi]:Dt("color","orange"),[Ja]:Dt("color","black")},Qa=e=>{var o;e.length===1&&((o=e[0])==null?void 0:o.constructor)===Function&&(e=e[0]());const t=[],n=[],i=wt();let s=[],r=0;for(;r<e.length;r++){const l=e[r],c=Za[l];if(c!==void 0)i.set(c.left,c.right);else{if(l===void 0)break;if(l.constructor===String||l.constructor===Number){const a=Ua(i);r>0||a.length>0?(t.push("%c"+l),n.push(a)):t.push(l)}else break}}for(r>0&&(s=n,s.unshift(t.join("")));r<e.length;r++){const l=e[r];l instanceof Symbol||s.push(l)}return s},Ir=sa?Qa:Xa,th=(...e)=>{console.log(...Ir(e)),Or.forEach(t=>t.print(e))},Mr=(...e)=>{console.warn(...Ir(e)),e.unshift(zi),Or.forEach(t=>t.print(e))},Or=Kt(),Rr=e=>({[Symbol.iterator](){return this},next:e}),eh=(e,t)=>Rr(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),Xn=(e,t)=>Rr(()=>{const{done:n,value:i}=e.next();return{done:n,value:n?void 0:t(i)}});class In{constructor(t,n){this.clock=t,this.len=n}}class fe{constructor(){this.clients=new Map}}const Lt=(e,t,n)=>t.clients.forEach((i,s)=>{const r=e.doc.store.clients.get(s);if(r!=null){const o=r[r.length-1],l=o.id.clock+o.length;for(let c=0,a=i[c];c<i.length&&a.clock<l;a=i[++c])$r(e,r,a.clock,a.len,n)}}),nh=(e,t)=>{let n=0,i=e.length-1;for(;n<=i;){const s=bt((n+i)/2),r=e[s],o=r.clock;if(o<=t){if(t<o+r.len)return s;n=s+1}else i=s-1}return null},pe=(e,t)=>{const n=e.clients.get(t.client);return n!==void 0&&nh(n,t.clock)!==null},$i=e=>{e.clients.forEach(t=>{t.sort((s,r)=>s.clock-r.clock);let n,i;for(n=1,i=1;n<t.length;n++){const s=t[i-1],r=t[n];s.clock+s.len>=r.clock?t[i-1]=new In(s.clock,Bt(s.len,r.clock+r.len-s.clock)):(i<n&&(t[i]=r),i++)}t.length=i})},pi=e=>{const t=new fe;for(let n=0;n<e.length;n++)e[n].clients.forEach((i,s)=>{if(!t.clients.has(s)){const r=i.slice();for(let o=n+1;o<e.length;o++)oc(r,e[o].clients.get(s)||[]);t.clients.set(s,r)}});return $i(t),t},De=(e,t,n,i)=>{Ot(e.clients,t,()=>[]).push(new In(n,i))},jr=()=>new fe,ih=e=>{const t=jr();return e.clients.forEach((n,i)=>{const s=[];for(let r=0;r<n.length;r++){const o=n[r];if(o.deleted){const l=o.id.clock;let c=o.length;if(r+1<n.length)for(let a=n[r+1];r+1<n.length&&a.deleted;a=n[++r+1])c+=a.length;s.push(new In(l,c))}}s.length>0&&t.clients.set(i,s)}),t},Vi=(e,t)=>{A(e.restEncoder,t.clients.size),qt(t.clients.entries()).sort((n,i)=>i[0]-n[0]).forEach(([n,i])=>{e.resetDsCurVal(),A(e.restEncoder,n);const s=i.length;A(e.restEncoder,s);for(let r=0;r<s;r++){const o=i[r];e.writeDsClock(o.clock),e.writeDsLen(o.len)}})},sh=e=>{const t=new fe,n=N(e.restDecoder);for(let i=0;i<n;i++){e.resetDsCurVal();const s=N(e.restDecoder),r=N(e.restDecoder);if(r>0){const o=Ot(t.clients,s,()=>[]);for(let l=0;l<r;l++)o.push(new In(e.readDsClock(),e.readDsLen()))}}return t},gs=(e,t,n)=>{const i=new fe,s=N(e.restDecoder);for(let r=0;r<s;r++){e.resetDsCurVal();const o=N(e.restDecoder),l=N(e.restDecoder),c=n.clients.get(o)||[],a=$(n,o);for(let u=0;u<l;u++){const h=e.readDsClock(),f=h+e.readDsLen();if(h<a){a<f&&De(i,o,a,f-a);let p=yt(c,h),g=c[p];for(!g.deleted&&g.id.clock<h&&(c.splice(p+1,0,xn(t,g,h-g.id.clock)),p++);p<c.length&&(g=c[p++],g.id.clock<f);)g.deleted||(f<g.id.clock+g.length&&c.splice(p,0,xn(t,g,f-g.id.clock)),g.delete(t))}else De(i,o,h,f-h)}}if(i.clients.size>0){const r=new Mn;return A(r.restEncoder,0),Vi(r,i),r.toUint8Array()}return null},Nr=ir;class Jt extends Zs{constructor({guid:t=Fc(),collectionid:n=null,gc:i=!0,gcFilter:s=()=>!0,meta:r=null,autoLoad:o=!1,shouldLoad:l=!0}={}){super(),this.gc=i,this.gcFilter=s,this.clientID=Nr(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new Ur,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=o,this.meta=r,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=us(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const c=()=>us(a=>{const u=h=>{(h===void 0||h===!0)&&(this.off("sync",u),a())};this.on("sync",u)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=a===void 0||a===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=c()}load(){const t=this._item;t!==null&&!this.shouldLoad&&j(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(qt(this.subdocs).map(t=>t.guid))}transact(t,n=null){return j(this,t,n)}get(t,n=J){const i=Ot(this.share,t,()=>{const r=new n;return r._integrate(this,null),r}),s=i.constructor;if(n!==J&&s!==n)if(s===J){const r=new n;r._map=i._map,i._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=r}),r._start=i._start;for(let o=r._start;o!==null;o=o.right)o.parent=r;return r._length=i._length,this.share.set(t,r),r._integrate(this,null),r}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return i}getArray(t=""){return this.get(t,se)}getText(t=""){return this.get(t,Pt)}getMap(t=""){return this.get(t,he)}getXmlElement(t=""){return this.get(t,it)}getXmlFragment(t=""){return this.get(t,Wt)}toJSON(){const t={};return this.share.forEach((n,i)=>{t[i]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,qt(this.subdocs).forEach(n=>n.destroy());const t=this._item;if(t!==null){this._item=null;const n=t.content;n.doc=new Jt({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,j(t.parent.doc,i=>{const s=n.doc;t.deleted||i.subdocsAdded.add(s),i.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class rh{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=N(this.restDecoder),this.dsCurrVal}readDsLen(){const t=N(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class un extends rh{constructor(t){super(t),this.keys=[],N(t),this.keyClockDecoder=new Gn(ut(t)),this.clientDecoder=new Xe(ut(t)),this.leftClockDecoder=new Gn(ut(t)),this.rightClockDecoder=new Gn(ut(t)),this.infoDecoder=new hs(ut(t),Ee),this.stringDecoder=new Pc(ut(t)),this.parentInfoDecoder=new hs(ut(t),Ee),this.typeRefDecoder=new Xe(ut(t)),this.lenDecoder=new Xe(ut(t))}readLeftID(){return new ne(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new ne(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return rn(this.restDecoder)}readBuf(){return ut(this.restDecoder)}readJSON(){return rn(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{const n=this.stringDecoder.read();return this.keys.push(n),n}}}class oh{constructor(){this.restEncoder=Be()}toUint8Array(){return mt(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){A(this.restEncoder,t)}writeDsLen(t){A(this.restEncoder,t)}}class lh extends oh{writeLeftID(t){A(this.restEncoder,t.client),A(this.restEncoder,t.clock)}writeRightID(t){A(this.restEncoder,t.client),A(this.restEncoder,t.clock)}writeClient(t){A(this.restEncoder,t)}writeInfo(t){ai(this.restEncoder,t)}writeString(t){te(this.restEncoder,t)}writeParentInfo(t){A(this.restEncoder,t?1:0)}writeTypeRef(t){A(this.restEncoder,t)}writeLen(t){A(this.restEncoder,t)}writeAny(t){le(this.restEncoder,t)}writeBuf(t){ct(this.restEncoder,t)}writeJSON(t){te(this.restEncoder,JSON.stringify(t))}writeKey(t){te(this.restEncoder,t)}}class ch{constructor(){this.restEncoder=Be(),this.dsCurrVal=0}toUint8Array(){return mt(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,A(this.restEncoder,n)}writeDsLen(t){t===0&&rt(),A(this.restEncoder,t-1),this.dsCurrVal+=t}}class Mn extends ch{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Wn,this.clientEncoder=new Je,this.leftClockEncoder=new Wn,this.rightClockEncoder=new Wn,this.infoEncoder=new ls(ai),this.stringEncoder=new Ac,this.parentInfoEncoder=new ls(ai),this.typeRefEncoder=new Je,this.lenEncoder=new Je}toUint8Array(){const t=Be();return A(t,0),ct(t,this.keyClockEncoder.toUint8Array()),ct(t,this.clientEncoder.toUint8Array()),ct(t,this.leftClockEncoder.toUint8Array()),ct(t,this.rightClockEncoder.toUint8Array()),ct(t,mt(this.infoEncoder)),ct(t,this.stringEncoder.toUint8Array()),ct(t,mt(this.parentInfoEncoder)),ct(t,this.typeRefEncoder.toUint8Array()),ct(t,this.lenEncoder.toUint8Array()),Cn(t,mt(this.restEncoder)),mt(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){le(this.restEncoder,t)}writeBuf(t){ct(this.restEncoder,t)}writeJSON(t){le(this.restEncoder,t)}writeKey(t){const n=this.keyMap.get(t);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}}const ah=(e,t,n,i)=>{i=Bt(i,t[0].id.clock);const s=yt(t,i);A(e.restEncoder,t.length-s),e.writeClient(n),A(e.restEncoder,i);const r=t[s];r.write(e,i-r.id.clock);for(let o=s+1;o<t.length;o++)t[o].write(e,0)},Br=(e,t,n)=>{const i=new Map;n.forEach((s,r)=>{$(t,r)>s&&i.set(r,s)}),On(t).forEach((s,r)=>{n.has(r)||i.set(r,0)}),A(e.restEncoder,i.size),qt(i.entries()).sort((s,r)=>r[0]-s[0]).forEach(([s,r])=>{ah(e,t.clients.get(s),s,r)})},hh=(e,t)=>{const n=wt(),i=N(e.restDecoder);for(let s=0;s<i;s++){const r=N(e.restDecoder),o=new Array(r),l=e.readClient();let c=N(e.restDecoder);n.set(l,{i:0,refs:o});for(let a=0;a<r;a++){const u=e.readInfo();switch(vn&u){case 0:{const h=e.readLen();o[a]=new dt(T(l,c),h),c+=h;break}case 10:{const h=N(e.restDecoder);o[a]=new gt(T(l,c),h),c+=h;break}default:{const h=(u&(It|st))===0,f=new R(T(l,c),null,(u&st)===st?e.readLeftID():null,null,(u&It)===It?e.readRightID():null,h?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,h&&(u&Ce)===Ce?e.readString():null,ao(e,u));o[a]=f,c+=f.length}}}}return n},uh=(e,t,n)=>{const i=[];let s=qt(n.keys()).sort((p,g)=>p-g);if(s.length===0)return null;const r=()=>{if(s.length===0)return null;let p=n.get(s[s.length-1]);for(;p.refs.length===p.i;)if(s.pop(),s.length>0)p=n.get(s[s.length-1]);else return null;return p};let o=r();if(o===null)return null;const l=new Ur,c=new Map,a=(p,g)=>{const x=c.get(p);(x==null||x>g)&&c.set(p,g)};let u=o.refs[o.i++];const h=new Map,f=()=>{for(const p of i){const g=p.id.client,x=n.get(g);x?(x.i--,l.clients.set(g,x.refs.slice(x.i)),n.delete(g),x.i=0,x.refs=[]):l.clients.set(g,[p]),s=s.filter(b=>b!==g)}i.length=0};for(;;){if(u.constructor!==gt){const g=Ot(h,u.id.client,()=>$(t,u.id.client))-u.id.clock;if(g<0)i.push(u),a(u.id.client,u.id.clock-1),f();else{const x=u.getMissing(e,t);if(x!==null){i.push(u);const b=n.get(x)||{refs:[],i:0};if(b.refs.length===b.i)a(x,$(t,x)),f();else{u=b.refs[b.i++];continue}}else(g===0||g<u.length)&&(u.integrate(e,g),h.set(u.id.client,u.id.clock+u.length))}}if(i.length>0)u=i.pop();else if(o!==null&&o.i<o.refs.length)u=o.refs[o.i++];else{if(o=r(),o===null)break;u=o.refs[o.i++]}}if(l.clients.size>0){const p=new Mn;return Br(p,l,new Map),A(p.restEncoder,0),{missing:c,update:p.toUint8Array()}}return null},dh=(e,t)=>Br(e,t.doc.store,t.beforeState),fh=(e,t,n,i=new un(e))=>j(t,s=>{s.local=!1;let r=!1;const o=s.doc,l=o.store,c=hh(i,o),a=uh(s,l,c),u=l.pendingStructs;if(u){for(const[f,p]of u.missing)if(p<$(l,f)){r=!0;break}if(a){for(const[f,p]of a.missing){const g=u.missing.get(f);(g==null||g>p)&&u.missing.set(f,p)}u.update=ks([u.update,a.update])}}else l.pendingStructs=a;const h=gs(i,s,l);if(l.pendingDs){const f=new un(Mi(l.pendingDs));N(f.restDecoder);const p=gs(f,s,l);h&&p?l.pendingDs=ks([h,p]):l.pendingDs=h||p}else l.pendingDs=h;if(r){const f=l.pendingStructs.update;l.pendingStructs=null,gi(s.doc,f)}},n,!1),gi=(e,t,n,i=un)=>{const s=Mi(t);fh(s,e,n,new i(s))};class ph{constructor(){this.l=[]}}const ms=()=>new ph,xs=(e,t)=>e.l.push(t),ws=(e,t)=>{const n=e.l,i=n.length;e.l=n.filter(s=>t!==s),i===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Lr=(e,t,n)=>Ni(e.l,[t,n]);class ne{constructor(t,n){this.client=t,this.clock=n}}const Ve=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,T=(e,t)=>new ne(e,t),Ae=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw rt()},Ie=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1};class dn{constructor(t,n,i,s=0){this.type=t,this.tname=n,this.item=i,this.assoc=s}}class gh{constructor(t,n,i=0){this.type=t,this.index=n,this.assoc=i}}const mh=(e,t,n=0)=>new gh(e,t,n),Fe=(e,t,n)=>{let i=null,s=null;return e._item===null?s=Ae(e):i=T(e._item.id.client,e._item.id.clock),new dn(i,s,t,n)},Zn=(e,t,n=0)=>{let i=e._start;if(n<0){if(t===0)return Fe(e,null,n);t--}for(;i!==null;){if(!i.deleted&&i.countable){if(i.length>t)return Fe(e,T(i.id.client,i.id.clock+t),n);t-=i.length}if(i.right===null&&n<0)return Fe(e,i.lastId,n);i=i.right}return Fe(e,null,n)},xh=(e,t)=>{const n=ie(e,t),i=t.clock-n.id.clock;return{item:n,diff:i}},wh=(e,t,n=!0)=>{const i=t.store,s=e.item,r=e.type,o=e.tname,l=e.assoc;let c=null,a=0;if(s!==null){if($(i,s.client)<=s.clock)return null;const u=n?bi(i,s):xh(i,s),h=u.item;if(!(h instanceof R))return null;if(c=h.parent,c._item===null||!c._item.deleted){a=h.deleted||!h.countable?0:u.diff+(l>=0?0:1);let f=h.left;for(;f!==null;)!f.deleted&&f.countable&&(a+=f.length),f=f.left}}else{if(o!==null)c=t.get(o);else if(r!==null){if($(i,r.client)<=r.clock)return null;const{item:u}=n?bi(i,r):{item:ie(i,r)};if(u instanceof R&&u.content instanceof vt)c=u.content.type;else return null}else throw rt();l>=0?a=c._length:a=0}return mh(c,a,e.assoc)};class Fi{constructor(t,n){this.ds=t,this.sv=n}}const Pr=(e,t)=>new Fi(e,t),Qn=e=>Pr(ih(e.store),On(e.store)),$t=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!pe(t.ds,e.id),mi=(e,t)=>{const n=Ot(e.meta,mi,Kt),i=e.doc.store;n.has(t)||(t.sv.forEach((s,r)=>{s<$(i,r)&&lt(e,T(r,s))}),Lt(e,t.ds,s=>{}),n.add(t))};class Ur{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const On=e=>{const t=new Map;return e.clients.forEach((n,i)=>{const s=n[n.length-1];t.set(i,s.id.clock+s.length)}),t},$=(e,t)=>{const n=e.clients.get(t);if(n===void 0)return 0;const i=n[n.length-1];return i.id.clock+i.length},zr=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{const i=n[n.length-1];if(i.id.clock+i.length!==t.id.clock)throw rt()}n.push(t)},yt=(e,t)=>{let n=0,i=e.length-1,s=e[i],r=s.id.clock;if(r===t)return i;let o=bt(t/(r+s.length-1)*i);for(;n<=i;){if(s=e[o],r=s.id.clock,r<=t){if(t<r+s.length)return o;n=o+1}else i=o-1;o=bt((n+i)/2)}throw rt()},bh=(e,t)=>{const n=e.clients.get(t.client);return n[yt(n,t.clock)]},ie=bh,xi=(e,t,n)=>{const i=yt(t,n),s=t[i];return s.id.clock<n&&s instanceof R?(t.splice(i+1,0,xn(e,s,n-s.id.clock)),i+1):i},lt=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[xi(e,n,t.clock)]},bs=(e,t,n)=>{const i=t.clients.get(n.client),s=yt(i,n.clock),r=i[s];return n.clock!==r.id.clock+r.length-1&&r.constructor!==dt&&i.splice(s+1,0,xn(e,r,n.clock-r.id.clock+1)),r},yh=(e,t,n)=>{const i=e.clients.get(t.id.client);i[yt(i,t.id.clock)]=n},$r=(e,t,n,i,s)=>{if(i===0)return;const r=n+i;let o=xi(e,t,n),l;do l=t[o++],r<l.id.clock+l.length&&xi(e,t,r),s(l);while(o<t.length&&t[o].id.clock<r)};class Sh{constructor(t,n,i){this.doc=t,this.deleteSet=new fe,this.beforeState=On(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=i,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const ys=(e,t)=>t.deleteSet.clients.size===0&&!rc(t.afterState,(n,i)=>t.beforeState.get(i)!==n)?!1:($i(t.deleteSet),dh(e,t),Vi(e,t.deleteSet),!0),Ss=(e,t,n)=>{const i=t._item;(i===null||i.id.clock<(e.beforeState.get(i.id.client)||0)&&!i.deleted)&&Ot(e.changed,t,Kt).add(n)},Qe=(e,t)=>{let n=e[t],i=e[t-1],s=t;for(;s>0;n=i,i=e[--s-1]){if(i.deleted===n.deleted&&i.constructor===n.constructor&&i.mergeWith(n)){n instanceof R&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,i);continue}break}const r=t-s;return r&&e.splice(t+1-r,r),r},vh=(e,t,n)=>{for(const[i,s]of e.clients.entries()){const r=t.clients.get(i);for(let o=s.length-1;o>=0;o--){const l=s[o],c=l.clock+l.len;for(let a=yt(r,l.clock),u=r[a];a<r.length&&u.id.clock<c;u=r[++a]){const h=r[a];if(l.clock+l.len<=h.id.clock)break;h instanceof R&&h.deleted&&!h.keep&&n(h)&&h.gc(t,!1)}}}},Ch=(e,t)=>{e.clients.forEach((n,i)=>{const s=t.clients.get(i);for(let r=n.length-1;r>=0;r--){const o=n[r],l=oe(s.length-1,1+yt(s,o.clock+o.len-1));for(let c=l,a=s[c];c>0&&a.id.clock>=o.clock;a=s[c])c-=1+Qe(s,c)}})},Vr=(e,t)=>{if(t<e.length){const n=e[t],i=n.doc,s=i.store,r=n.deleteSet,o=n._mergeStructs;try{$i(r),n.afterState=On(n.doc.store),i.emit("beforeObserverCalls",[n,i]);const l=[];n.changed.forEach((c,a)=>l.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(n,c)})),l.push(()=>{n.changedParentTypes.forEach((c,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(c=c.filter(u=>u.target._item===null||!u.target._item.deleted),c.forEach(u=>{u.currentTarget=a,u._path=null}),c.sort((u,h)=>u.path.length-h.path.length),l.push(()=>{Lr(a._dEH,c,n)}))}),l.push(()=>i.emit("afterTransaction",[n,i])),l.push(()=>{n._needFormattingCleanup&&Fh(n)})}),Ni(l,[])}finally{i.gc&&vh(r,s,i.gcFilter),Ch(r,s),n.afterState.forEach((u,h)=>{const f=n.beforeState.get(h)||0;if(f!==u){const p=s.clients.get(h),g=Bt(yt(p,f),1);for(let x=p.length-1;x>=g;)x-=1+Qe(p,x)}});for(let u=o.length-1;u>=0;u--){const{client:h,clock:f}=o[u].id,p=s.clients.get(h),g=yt(p,f);g+1<p.length&&Qe(p,g+1)>1||g>0&&Qe(p,g)}if(!n.local&&n.afterState.get(i.clientID)!==n.beforeState.get(i.clientID)&&(th(zi,_r,"[yjs] ",Dr,Ar,"Changed the client-id because another client seems to be using it."),i.clientID=Nr()),i.emit("afterTransactionCleanup",[n,i]),i._observers.has("update")){const u=new lh;ys(u,n)&&i.emit("update",[u.toUint8Array(),n.origin,i,n])}if(i._observers.has("updateV2")){const u=new Mn;ys(u,n)&&i.emit("updateV2",[u.toUint8Array(),n.origin,i,n])}const{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=n;(l.size>0||a.size>0||c.size>0)&&(l.forEach(u=>{u.clientID=i.clientID,u.collectionid==null&&(u.collectionid=i.collectionid),i.subdocs.add(u)}),a.forEach(u=>i.subdocs.delete(u)),i.emit("subdocs",[{loaded:c,added:l,removed:a},i,n]),a.forEach(u=>u.destroy())),e.length<=t+1?(i._transactionCleanups=[],i.emit("afterAllTransactions",[i,e])):Vr(e,t+1)}}},j=(e,t,n=null,i=!0)=>{const s=e._transactionCleanups;let r=!1,o=null;e._transaction===null&&(r=!0,e._transaction=new Sh(e,n,i),s.push(e._transaction),s.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(r){const l=e._transaction===s[0];e._transaction=null,l&&Vr(s,0)}}return o};class kh{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const vs=(e,t,n)=>{Lt(e,n.deletions,i=>{i instanceof R&&t.scope.some(s=>s===e.doc||Ie(s,i))&&Gi(i,!1)})},Cs=(e,t,n)=>{let i=null;const s=e.doc,r=e.scope;j(s,l=>{for(;t.length>0&&e.currStackItem===null;){const c=s.store,a=t.pop(),u=new Set,h=[];let f=!1;Lt(l,a.insertions,p=>{if(p instanceof R){if(p.redone!==null){let{item:g,diff:x}=bi(c,p.id);x>0&&(g=lt(l,T(g.id.client,g.id.clock+x))),p=g}!p.deleted&&r.some(g=>g===l.doc||Ie(g,p))&&h.push(p)}}),Lt(l,a.deletions,p=>{p instanceof R&&r.some(g=>g===l.doc||Ie(g,p))&&!pe(a.insertions,p.id)&&u.add(p)}),u.forEach(p=>{f=co(l,p,u,a.insertions,e.ignoreRemoteMapChanges,e)!==null||f});for(let p=h.length-1;p>=0;p--){const g=h[p];e.deleteFilter(g)&&(g.delete(l),f=!0)}e.currStackItem=f?a:null}l.changed.forEach((c,a)=>{c.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),i=l},e);const o=e.currStackItem;if(o!=null){const l=i.changedParentTypes;e.emit("stack-item-popped",[{stackItem:o,type:n,changedParentTypes:l,origin:e},e]),e.currStackItem=null}return o};class Fr extends Zs{constructor(t,{captureTimeout:n=500,captureTransaction:i=c=>!0,deleteFilter:s=()=>!0,trackedOrigins:r=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:l=re(t)?t[0].doc:t instanceof Jt?t:t.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(t),this.deleteFilter=s,r.add(this),this.trackedOrigins=r,this.captureTransaction=i,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=n,this.afterTransactionHandler=c=>{if(!this.captureTransaction(c)||!this.scope.some(b=>c.changedParentTypes.has(b)||b===this.doc)||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;const a=this.undoing,u=this.redoing,h=a?this.redoStack:this.undoStack;a?this.stopCapturing():u||this.clear(!1,!0);const f=new fe;c.afterState.forEach((b,y)=>{const C=c.beforeState.get(y)||0,S=b-C;S>0&&De(f,y,C,S)});const p=Hc();let g=!1;if(this.lastChange>0&&p-this.lastChange<this.captureTimeout&&h.length>0&&!a&&!u){const b=h[h.length-1];b.deletions=pi([b.deletions,c.deleteSet]),b.insertions=pi([b.insertions,f])}else h.push(new kh(c.deleteSet,f)),g=!0;!a&&!u&&(this.lastChange=p),Lt(c,c.deleteSet,b=>{b instanceof R&&this.scope.some(y=>y===c.doc||Ie(y,b))&&Gi(b,!0)});const x=[{stackItem:h[h.length-1],origin:c.origin,type:a?"redo":"undo",changedParentTypes:c.changedParentTypes},this];g?this.emit("stack-item-added",x):this.emit("stack-item-updated",x)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){const n=new Set(this.scope);t=re(t)?t:[t],t.forEach(i=>{n.has(i)||(n.add(i),(i instanceof J?i.doc!==this.doc:i!==this.doc)&&Mr("[yjs#509] Not same Y.Doc"),this.scope.push(i))})}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,n=!0){(t&&this.canUndo()||n&&this.canRedo())&&this.doc.transact(i=>{t&&(this.undoStack.forEach(s=>vs(i,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>vs(i,this,s)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let t;try{t=Cs(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=Cs(this,this.redoStack,"redo")}finally{this.redoing=!1}return t}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}}function*Eh(e){const t=N(e.restDecoder);for(let n=0;n<t;n++){const i=N(e.restDecoder),s=e.readClient();let r=N(e.restDecoder);for(let o=0;o<i;o++){const l=e.readInfo();if(l===10){const c=N(e.restDecoder);yield new gt(T(s,r),c),r+=c}else if((vn&l)!==0){const c=(l&(It|st))===0,a=new R(T(s,r),null,(l&st)===st?e.readLeftID():null,null,(l&It)===It?e.readRightID():null,c?e.readParentInfo()?e.readString():e.readLeftID():null,c&&(l&Ce)===Ce?e.readString():null,ao(e,l));yield a,r+=a.length}else{const c=e.readLen();yield new dt(T(s,r),c),r+=c}}}}class Th{constructor(t,n){this.gen=Eh(t),this.curr=null,this.done=!1,this.filterSkips=n,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===gt);return this.curr}}class _h{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const Dh=(e,t)=>{if(e.constructor===dt){const{client:n,clock:i}=e.id;return new dt(T(n,i+t),e.length-t)}else if(e.constructor===gt){const{client:n,clock:i}=e.id;return new gt(T(n,i+t),e.length-t)}else{const n=e,{client:i,clock:s}=n.id;return new R(T(i,s+t),null,T(i,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},ks=(e,t=un,n=Mn)=>{if(e.length===1)return e[0];const i=e.map(u=>new t(Mi(u)));let s=i.map(u=>new Th(u,!0)),r=null;const o=new n,l=new _h(o);for(;s=s.filter(f=>f.curr!==null),s.sort((f,p)=>{if(f.curr.id.client===p.curr.id.client){const g=f.curr.id.clock-p.curr.id.clock;return g===0?f.curr.constructor===p.curr.constructor?0:f.curr.constructor===gt?1:-1:g}else return p.curr.id.client-f.curr.id.client}),s.length!==0;){const u=s[0],h=u.curr.id.client;if(r!==null){let f=u.curr,p=!1;for(;f!==null&&f.id.clock+f.length<=r.struct.id.clock+r.struct.length&&f.id.client>=r.struct.id.client;)f=u.next(),p=!0;if(f===null||f.id.client!==h||p&&f.id.clock>r.struct.id.clock+r.struct.length)continue;if(h!==r.struct.id.client)ye(l,r.struct,r.offset),r={struct:f,offset:0},u.next();else if(r.struct.id.clock+r.struct.length<f.id.clock)if(r.struct.constructor===gt)r.struct.length=f.id.clock+f.length-r.struct.id.clock;else{ye(l,r.struct,r.offset);const g=f.id.clock-r.struct.id.clock-r.struct.length;r={struct:new gt(T(h,r.struct.id.clock+r.struct.length),g),offset:0}}else{const g=r.struct.id.clock+r.struct.length-f.id.clock;g>0&&(r.struct.constructor===gt?r.struct.length-=g:f=Dh(f,g)),r.struct.mergeWith(f)||(ye(l,r.struct,r.offset),r={struct:f,offset:0},u.next())}}else r={struct:u.curr,offset:0},u.next();for(let f=u.curr;f!==null&&f.id.client===h&&f.id.clock===r.struct.id.clock+r.struct.length&&f.constructor!==gt;f=u.next())ye(l,r.struct,r.offset),r={struct:f,offset:0}}r!==null&&(ye(l,r.struct,r.offset),r=null),Ah(l);const c=i.map(u=>sh(u)),a=pi(c);return Vi(o,a),o.toUint8Array()},Hr=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:mt(e.encoder.restEncoder)}),e.encoder.restEncoder=Be(),e.written=0)},ye=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Hr(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),A(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Ah=e=>{Hr(e);const t=e.encoder.restEncoder;A(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const i=e.clientStructs[n];A(t,i.written),Cn(t,i.restEncoder)}},Es="You must not compute changes after the event-handler fired.";class Rn{constructor(t,n){this.target=t,this.currentTarget=t,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Ih(this.currentTarget,this.target))}deletes(t){return pe(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw _t(Es);const t=new Map,n=this.target;this.transaction.changed.get(n).forEach(s=>{if(s!==null){const r=n._map.get(s);let o,l;if(this.adds(r)){let c=r.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(r))if(c!==null&&this.deletes(c))o="delete",l=Hn(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Hn(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(r))o="delete",l=Hn(r.content.getContent());else return;t.set(s,{action:o,oldValue:l})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw _t(Es);const n=this.target,i=Kt(),s=Kt(),r=[];if(t={added:i,deleted:s,delta:r,keys:this.keys},this.transaction.changed.get(n).has(null)){let l=null;const c=()=>{l&&r.push(l)};for(let a=n._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((l===null||l.delete===void 0)&&(c(),l={delete:0}),l.delete+=a.length,s.add(a)):this.adds(a)?((l===null||l.insert===void 0)&&(c(),l={insert:[]}),l.insert=l.insert.concat(a.content.getContent()),i.add(a)):((l===null||l.retain===void 0)&&(c(),l={retain:0}),l.retain+=a.length);l!==null&&l.retain===void 0&&c()}this._changes=t}return t}}const Ih=(e,t)=>{const n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let i=0,s=t._item.parent._start;for(;s!==t._item&&s!==null;)!s.deleted&&s.countable&&(i+=s.length),s=s.right;n.unshift(i)}t=t._item.parent}return n},tt=()=>{Mr("Invalid access: Add Yjs type to a document before reading data.")},Kr=80;let Hi=0;class Mh{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=Hi++}}const Oh=e=>{e.timestamp=Hi++},qr=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Hi++},Rh=(e,t,n)=>{if(e.length>=Kr){const i=e.reduce((s,r)=>s.timestamp<r.timestamp?s:r);return qr(i,t,n),i}else{const i=new Mh(t,n);return e.push(i),i}},jn=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;const n=e._searchMarker.length===0?null:e._searchMarker.reduce((r,o)=>Ye(t-r.index)<Ye(t-o.index)?r:o);let i=e._start,s=0;for(n!==null&&(i=n.p,s=n.index,Oh(n));i.right!==null&&s<t;){if(!i.deleted&&i.countable){if(t<s+i.length)break;s+=i.length}i=i.right}for(;i.left!==null&&s>t;)i=i.left,!i.deleted&&i.countable&&(s-=i.length);for(;i.left!==null&&i.left.id.client===i.id.client&&i.left.id.clock+i.left.length===i.id.clock;)i=i.left,!i.deleted&&i.countable&&(s-=i.length);return n!==null&&Ye(n.index-s)<i.parent.length/Kr?(qr(n,i,s),n):Rh(e._searchMarker,i,s)},Me=(e,t,n)=>{for(let i=e.length-1;i>=0;i--){const s=e[i];if(n>0){let r=s.p;for(r.marker=!1;r&&(r.deleted||!r.countable);)r=r.left,r&&!r.deleted&&r.countable&&(s.index-=r.length);if(r===null||r.marker===!0){e.splice(i,1);continue}s.p=r,r.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=Bt(t,s.index+n))}},Nn=(e,t,n)=>{const i=e,s=t.changedParentTypes;for(;Ot(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Lr(i._eH,n,t)};class J{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ms(),this._dEH=ms(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw pt()}clone(){throw pt()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,n){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){xs(this._eH,t)}observeDeep(t){xs(this._dEH,t)}unobserve(t){ws(this._eH,t)}unobserveDeep(t){ws(this._dEH,t)}toJSON(){}}const Wr=(e,t,n)=>{e.doc??tt(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let i=n-t;const s=[];let r=e._start;for(;r!==null&&i>0;){if(r.countable&&!r.deleted){const o=r.content.getContent();if(o.length<=t)t-=o.length;else{for(let l=t;l<o.length&&i>0;l++)s.push(o[l]),i--;t=0}}r=r.right}return s},Gr=e=>{e.doc??tt();const t=[];let n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){const i=n.content.getContent();for(let s=0;s<i.length;s++)t.push(i[s])}n=n.right}return t},Yr=(e,t)=>{const n=[];let i=e._start;for(;i!==null;){if(i.countable&&$t(i,t)){const s=i.content.getContent();for(let r=0;r<s.length;r++)n.push(s[r])}i=i.right}return n},Oe=(e,t)=>{let n=0,i=e._start;for(e.doc??tt();i!==null;){if(i.countable&&!i.deleted){const s=i.content.getContent();for(let r=0;r<s.length;r++)t(s[r],n++,e)}i=i.right}},Jr=(e,t)=>{const n=[];return Oe(e,(i,s)=>{n.push(t(i,s,e))}),n},jh=e=>{let t=e._start,n=null,i=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),i=0,t=t.right}const s=n[i++];return n.length<=i&&(n=null),{done:!1,value:s}}}},Xr=(e,t)=>{e.doc??tt();const n=jn(e,t);let i=e._start;for(n!==null&&(i=n.p,t-=n.index);i!==null;i=i.right)if(!i.deleted&&i.countable){if(t<i.length)return i.content.getContent()[t];t-=i.length}},fn=(e,t,n,i)=>{let s=n;const r=e.doc,o=r.clientID,l=r.store,c=n===null?t._start:n.right;let a=[];const u=()=>{a.length>0&&(s=new R(T(o,$(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new Gt(a)),s.integrate(e,0),a=[])};i.forEach(h=>{if(h===null)a.push(h);else switch(h.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(h);break;default:switch(u(),h.constructor){case Uint8Array:case ArrayBuffer:s=new R(T(o,$(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new Pe(new Uint8Array(h))),s.integrate(e,0);break;case Jt:s=new R(T(o,$(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new Ue(h)),s.integrate(e,0);break;default:if(h instanceof J)s=new R(T(o,$(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new vt(h)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),u()},Zr=()=>_t("Length exceeded!"),Qr=(e,t,n,i)=>{if(n>t._length)throw Zr();if(n===0)return t._searchMarker&&Me(t._searchMarker,n,i.length),fn(e,t,null,i);const s=n,r=jn(t,n);let o=t._start;for(r!==null&&(o=r.p,n-=r.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&lt(e,T(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&Me(t._searchMarker,s,i.length),fn(e,t,o,i)},Nh=(e,t,n)=>{let s=(t._searchMarker||[]).reduce((r,o)=>o.index>r.index?o:r,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return fn(e,t,s,n)},to=(e,t,n,i)=>{if(i===0)return;const s=n,r=i,o=jn(t,n);let l=t._start;for(o!==null&&(l=o.p,n-=o.index);l!==null&&n>0;l=l.right)!l.deleted&&l.countable&&(n<l.length&&lt(e,T(l.id.client,l.id.clock+n)),n-=l.length);for(;i>0&&l!==null;)l.deleted||(i<l.length&&lt(e,T(l.id.client,l.id.clock+i)),l.delete(e),i-=l.length),l=l.right;if(i>0)throw Zr();t._searchMarker&&Me(t._searchMarker,s,-r+i)},pn=(e,t,n)=>{const i=t._map.get(n);i!==void 0&&i.delete(e)},Ki=(e,t,n,i)=>{const s=t._map.get(n)||null,r=e.doc,o=r.clientID;let l;if(i==null)l=new Gt([i]);else switch(i.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new Gt([i]);break;case Uint8Array:l=new Pe(i);break;case Jt:l=new Ue(i);break;default:if(i instanceof J)l=new vt(i);else throw new Error("Unexpected content type")}new R(T(o,$(r.store,o)),s,s&&s.lastId,null,null,t,n,l).integrate(e,0)},qi=(e,t)=>{e.doc??tt();const n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},eo=e=>{const t={};return e.doc??tt(),e._map.forEach((n,i)=>{n.deleted||(t[i]=n.content.getContent()[n.length-1])}),t},no=(e,t)=>{e.doc??tt();const n=e._map.get(t);return n!==void 0&&!n.deleted},Bh=(e,t)=>{const n={};return e._map.forEach((i,s)=>{let r=i;for(;r!==null&&(!t.sv.has(r.id.client)||r.id.clock>=(t.sv.get(r.id.client)||0));)r=r.left;r!==null&&$t(r,t)&&(n[s]=r.content.getContent()[r.length-1])}),n},He=e=>(e.doc??tt(),eh(e._map.entries(),t=>!t[1].deleted));class Lh extends Rn{}class se extends J{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new se;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new se}clone(){const t=new se;return t.insert(0,this.toArray().map(n=>n instanceof J?n.clone():n)),t}get length(){return this.doc??tt(),this._length}_callObserver(t,n){super._callObserver(t,n),Nn(this,t,new Lh(this,t))}insert(t,n){this.doc!==null?j(this.doc,i=>{Qr(i,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?j(this.doc,n=>{Nh(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?j(this.doc,i=>{to(i,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return Xr(this,t)}toArray(){return Gr(this)}slice(t=0,n=this.length){return Wr(this,t,n)}toJSON(){return this.map(t=>t instanceof J?t.toJSON():t)}map(t){return Jr(this,t)}forEach(t){Oe(this,t)}[Symbol.iterator](){return jh(this)}_write(t){t.writeTypeRef(cu)}}const Ph=e=>new se;class Uh extends Rn{constructor(t,n,i){super(t,n),this.keysChanged=i}}class he extends J{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach((i,s)=>{this.set(s,i)}),this._prelimContent=null}_copy(){return new he}clone(){const t=new he;return this.forEach((n,i)=>{t.set(i,n instanceof J?n.clone():n)}),t}_callObserver(t,n){Nn(this,t,new Uh(this,t,n))}toJSON(){this.doc??tt();const t={};return this._map.forEach((n,i)=>{if(!n.deleted){const s=n.content.getContent()[n.length-1];t[i]=s instanceof J?s.toJSON():s}}),t}get size(){return[...He(this)].length}keys(){return Xn(He(this),t=>t[0])}values(){return Xn(He(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Xn(He(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??tt(),this._map.forEach((n,i)=>{n.deleted||t(n.content.getContent()[n.length-1],i,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?j(this.doc,n=>{pn(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?j(this.doc,i=>{Ki(i,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return qi(this,t)}has(t){return no(this,t)}clear(){this.doc!==null?j(this.doc,t=>{this.forEach(function(n,i,s){pn(t,s,i)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(au)}}const zh=e=>new he,Nt=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&Zc(e,t);class wi{constructor(t,n,i,s){this.left=t,this.right=n,this.index=i,this.currentAttributes=s}forward(){switch(this.right===null&&rt(),this.right.content.constructor){case F:this.right.deleted||ge(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}}const Ts=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case F:t.right.deleted||ge(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&lt(e,T(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length);break}t.left=t.right,t.right=t.right.right}return t},Ke=(e,t,n,i)=>{const s=new Map,r=i?jn(t,n):null;if(r){const o=new wi(r.p.left,r.p,r.index,s);return Ts(e,o,n-r.index)}else{const o=new wi(null,t._start,0,s);return Ts(e,o,n)}},io=(e,t,n,i)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===F&&Nt(i.get(n.right.content.key),n.right.content.value));)n.right.deleted||i.delete(n.right.content.key),n.forward();const s=e.doc,r=s.clientID;i.forEach((o,l)=>{const c=n.left,a=n.right,u=new R(T(r,$(s.store,r)),c,c&&c.lastId,a,a&&a.id,t,null,new F(l,o));u.integrate(e,0),n.right=u,n.forward()})},ge=(e,t)=>{const{key:n,value:i}=t;i===null?e.delete(n):e.set(n,i)},so=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===F&&Nt(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},ro=(e,t,n,i)=>{const s=e.doc,r=s.clientID,o=new Map;for(const l in i){const c=i[l],a=n.currentAttributes.get(l)??null;if(!Nt(a,c)){o.set(l,a);const{left:u,right:h}=n;n.right=new R(T(r,$(s.store,r)),u,u&&u.lastId,h,h&&h.id,t,null,new F(l,c)),n.right.integrate(e,0),n.forward()}}return o},ti=(e,t,n,i,s)=>{n.currentAttributes.forEach((f,p)=>{s[p]===void 0&&(s[p]=null)});const r=e.doc,o=r.clientID;so(n,s);const l=ro(e,t,n,s),c=i.constructor===String?new St(i):i instanceof J?new vt(i):new Xt(i);let{left:a,right:u,index:h}=n;t._searchMarker&&Me(t._searchMarker,n.index,c.getLength()),u=new R(T(o,$(r.store,o)),a,a&&a.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=h,n.forward(),io(e,t,n,l)},_s=(e,t,n,i,s)=>{const r=e.doc,o=r.clientID;so(n,s);const l=ro(e,t,n,s);t:for(;n.right!==null&&(i>0||l.size>0&&(n.right.deleted||n.right.content.constructor===F));){if(!n.right.deleted)switch(n.right.content.constructor){case F:{const{key:c,value:a}=n.right.content,u=s[c];if(u!==void 0){if(Nt(u,a))l.delete(c);else{if(i===0)break t;l.set(c,a)}n.right.delete(e)}else n.currentAttributes.set(c,a);break}default:i<n.right.length&&lt(e,T(n.right.id.client,n.right.id.clock+i)),i-=n.right.length;break}n.forward()}if(i>0){let c="";for(;i>0;i--)c+=`
5
+ `;n.right=new R(T(o,$(r.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new St(c)),n.right.integrate(e,0),n.forward()}io(e,t,n,l)},oo=(e,t,n,i,s)=>{let r=t;const o=wt();for(;r&&(!r.countable||r.deleted);){if(!r.deleted&&r.content.constructor===F){const a=r.content;o.set(a.key,a)}r=r.right}let l=0,c=!1;for(;t!==r;){if(n===t&&(c=!0),!t.deleted){const a=t.content;switch(a.constructor){case F:{const{key:u,value:h}=a,f=i.get(u)??null;(o.get(u)!==a||f===h)&&(t.delete(e),l++,!c&&(s.get(u)??null)===h&&f!==h&&(f===null?s.delete(u):s.set(u,f))),!c&&!t.deleted&&ge(s,a);break}}}t=t.right}return l},$h=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===F){const i=t.content.key;n.has(i)?t.delete(e):n.add(i)}t=t.left}},Vh=e=>{let t=0;return j(e.doc,n=>{let i=e._start,s=e._start,r=wt();const o=li(r);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case F:ge(o,s.content);break;default:t+=oo(n,i,s,r,o),r=li(o),i=s;break}s=s.right}}),t},Fh=e=>{const t=new Set,n=e.doc;for(const[i,s]of e.afterState.entries()){const r=e.beforeState.get(i)||0;s!==r&&$r(e,n.store.clients.get(i),r,s,o=>{!o.deleted&&o.content.constructor===F&&o.constructor!==dt&&t.add(o.parent)})}j(n,i=>{Lt(e,e.deleteSet,s=>{if(s instanceof dt||!s.parent._hasFormatting||t.has(s.parent))return;const r=s.parent;s.content.constructor===F?t.add(r):$h(i,s)});for(const s of t)Vh(s)})},Ds=(e,t,n)=>{const i=n,s=li(t.currentAttributes),r=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case vt:case Xt:case St:n<t.right.length&&lt(e,T(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}r&&oo(e,r,t.right,s,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&Me(o._searchMarker,t.index,-i+n),t};class Hh extends Rn{constructor(t,n,i){super(t,n),this.childListChanged=!1,this.keysChanged=new Set,i.forEach(s=>{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}get changes(){if(this._changes===null){const t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){const t=this.target.doc,n=[];j(t,i=>{const s=new Map,r=new Map;let o=this.target._start,l=null;const c={};let a="",u=0,h=0;const f=()=>{if(l!==null){let p=null;switch(l){case"delete":h>0&&(p={delete:h}),h=0;break;case"insert":(typeof a=="object"||a.length>0)&&(p={insert:a},s.size>0&&(p.attributes={},s.forEach((g,x)=>{g!==null&&(p.attributes[x]=g)}))),a="";break;case"retain":u>0&&(p={retain:u},Xc(c)||(p.attributes=Yc({},c))),u=0;break}p&&n.push(p),l=null}};for(;o!==null;){switch(o.content.constructor){case vt:case Xt:this.adds(o)?this.deletes(o)||(f(),l="insert",a=o.content.getContent()[0],f()):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),h+=1):o.deleted||(l!=="retain"&&(f(),l="retain"),u+=1);break;case St:this.adds(o)?this.deletes(o)||(l!=="insert"&&(f(),l="insert"),a+=o.content.str):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),h+=o.length):o.deleted||(l!=="retain"&&(f(),l="retain"),u+=o.length);break;case F:{const{key:p,value:g}=o.content;if(this.adds(o)){if(!this.deletes(o)){const x=s.get(p)??null;Nt(x,g)?g!==null&&o.delete(i):(l==="retain"&&f(),Nt(g,r.get(p)??null)?delete c[p]:c[p]=g)}}else if(this.deletes(o)){r.set(p,g);const x=s.get(p)??null;Nt(x,g)||(l==="retain"&&f(),c[p]=x)}else if(!o.deleted){r.set(p,g);const x=c[p];x!==void 0&&(Nt(x,g)?x!==null&&o.delete(i):(l==="retain"&&f(),g===null?delete c[p]:c[p]=g))}o.deleted||(l==="insert"&&f(),ge(s,o.content));break}}o=o.right}for(f();n.length>0;){const p=n[n.length-1];if(p.retain!==void 0&&p.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class Pt extends J{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??tt(),this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach(i=>i())}catch(i){console.error(i)}this._pending=null}_copy(){return new Pt}clone(){const t=new Pt;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const i=new Hh(this,t,n);Nn(this,t,i),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??tt();let t="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===St&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){this.doc!==null?j(this.doc,i=>{const s=new wi(null,this._start,0,new Map);for(let r=0;r<t.length;r++){const o=t[r];if(o.insert!==void 0){const l=!n&&typeof o.insert=="string"&&r===t.length-1&&s.right===null&&o.insert.slice(-1)===`
6
+ `?o.insert.slice(0,-1):o.insert;(typeof l!="string"||l.length>0)&&ti(i,this,s,l,o.attributes||{})}else o.retain!==void 0?_s(i,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&Ds(i,s,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,i){this.doc??tt();const s=[],r=new Map,o=this.doc;let l="",c=this._start;function a(){if(l.length>0){const h={};let f=!1;r.forEach((g,x)=>{f=!0,h[x]=g});const p={insert:l};f&&(p.attributes=h),s.push(p),l=""}}const u=()=>{for(;c!==null;){if($t(c,t)||n!==void 0&&$t(c,n))switch(c.content.constructor){case St:{const h=r.get("ychange");t!==void 0&&!$t(c,t)?(h===void 0||h.user!==c.id.client||h.type!=="removed")&&(a(),r.set("ychange",i?i("removed",c.id):{type:"removed"})):n!==void 0&&!$t(c,n)?(h===void 0||h.user!==c.id.client||h.type!=="added")&&(a(),r.set("ychange",i?i("added",c.id):{type:"added"})):h!==void 0&&(a(),r.delete("ychange")),l+=c.content.str;break}case vt:case Xt:{a();const h={insert:c.content.getContent()[0]};if(r.size>0){const f={};h.attributes=f,r.forEach((p,g)=>{f[g]=p})}s.push(h);break}case F:$t(c,t)&&(a(),ge(r,c.content));break}c=c.right}a()};return t||n?j(o,h=>{t&&mi(h,t),n&&mi(h,n),u()},"cleanup"):u(),s}insert(t,n,i){if(n.length<=0)return;const s=this.doc;s!==null?j(s,r=>{const o=Ke(r,this,t,!i);i||(i={},o.currentAttributes.forEach((l,c)=>{i[c]=l})),ti(r,this,o,n,i)}):this._pending.push(()=>this.insert(t,n,i))}insertEmbed(t,n,i){const s=this.doc;s!==null?j(s,r=>{const o=Ke(r,this,t,!i);ti(r,this,o,n,i||{})}):this._pending.push(()=>this.insertEmbed(t,n,i||{}))}delete(t,n){if(n===0)return;const i=this.doc;i!==null?j(i,s=>{Ds(s,Ke(s,this,t,!0),n)}):this._pending.push(()=>this.delete(t,n))}format(t,n,i){if(n===0)return;const s=this.doc;s!==null?j(s,r=>{const o=Ke(r,this,t,!1);o.right!==null&&_s(r,this,o,n,i)}):this._pending.push(()=>this.format(t,n,i))}removeAttribute(t){this.doc!==null?j(this.doc,n=>{pn(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?j(this.doc,i=>{Ki(i,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return qi(this,t)}getAttributes(){return eo(this)}_write(t){t.writeTypeRef(hu)}}const Kh=e=>new Pt;class ei{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??tt()}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(n)))do if(n=t.content.type,!t.deleted&&(n.constructor===it||n.constructor===Wt)&&n._start!==null)t=n._start;else for(;t!==null;){const i=t.next;if(i!==null){t=i;break}else t.parent===this._root?t=null:t=t.parent._item}while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class Wt extends J{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Wt}clone(){const t=new Wt;return t.insert(0,this.toArray().map(n=>n instanceof J?n.clone():n)),t}get length(){return this.doc??tt(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new ei(this,t)}querySelector(t){t=t.toUpperCase();const i=new ei(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return i.done?null:i.value}querySelectorAll(t){return t=t.toUpperCase(),qt(new ei(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){Nn(this,t,new Gh(this,n,t))}toString(){return Jr(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},i){const s=t.createDocumentFragment();return i!==void 0&&i._createAssociation(s,this),Oe(this,r=>{s.insertBefore(r.toDOM(t,n,i),null)}),s}insert(t,n){this.doc!==null?j(this.doc,i=>{Qr(i,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)j(this.doc,i=>{const s=t&&t instanceof J?t._item:t;fn(i,this,s,n)});else{const i=this._prelimContent,s=t===null?0:i.findIndex(r=>r===t)+1;if(s===0&&t!==null)throw _t("Reference item not found");i.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?j(this.doc,i=>{to(i,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return Gr(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Xr(this,t)}slice(t=0,n=this.length){return Wr(this,t,n)}forEach(t){Oe(this,t)}_write(t){t.writeTypeRef(du)}}const qh=e=>new Wt;class it extends Wt{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach((i,s)=>{this.setAttribute(s,i)}),this._prelimAttrs=null}_copy(){return new it(this.nodeName)}clone(){const t=new it(this.nodeName),n=this.getAttributes();return Jc(n,(i,s)=>{t.setAttribute(s,i)}),t.insert(0,this.toArray().map(i=>i instanceof J?i.clone():i)),t}toString(){const t=this.getAttributes(),n=[],i=[];for(const l in t)i.push(l);i.sort();const s=i.length;for(let l=0;l<s;l++){const c=i[l];n.push(c+'="'+t[c]+'"')}const r=this.nodeName.toLocaleLowerCase(),o=n.length>0?" "+n.join(" "):"";return`<${r}${o}>${super.toString()}</${r}>`}removeAttribute(t){this.doc!==null?j(this.doc,n=>{pn(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?j(this.doc,i=>{Ki(i,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return qi(this,t)}hasAttribute(t){return no(this,t)}getAttributes(t){return t?Bh(this,t):eo(this)}toDOM(t=document,n={},i){const s=t.createElement(this.nodeName),r=this.getAttributes();for(const o in r){const l=r[o];typeof l=="string"&&s.setAttribute(o,l)}return Oe(this,o=>{s.appendChild(o.toDOM(t,n,i))}),i!==void 0&&i._createAssociation(s,this),s}_write(t){t.writeTypeRef(uu),t.writeKey(this.nodeName)}}const Wh=e=>new it(e.readKey());class Gh extends Rn{constructor(t,n,i){super(t,i),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}}class gn extends he{constructor(t){super(),this.hookName=t}_copy(){return new gn(this.hookName)}clone(){const t=new gn(this.hookName);return this.forEach((n,i)=>{t.set(i,n)}),t}toDOM(t=document,n={},i){const s=n[this.hookName];let r;return s!==void 0?r=s.createDom(this):r=document.createElement(this.hookName),r.setAttribute("data-yjs-hook",this.hookName),i!==void 0&&i._createAssociation(r,this),r}_write(t){t.writeTypeRef(fu),t.writeKey(this.hookName)}}const Yh=e=>new gn(e.readKey());class at extends Pt{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new at}clone(){const t=new at;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,i){const s=t.createTextNode(this.toString());return i!==void 0&&i._createAssociation(s,this),s}toString(){return this.toDelta().map(t=>{const n=[];for(const s in t.attributes){const r=[];for(const o in t.attributes[s])r.push({key:o,value:t.attributes[s][o]});r.sort((o,l)=>o.key<l.key?-1:1),n.push({nodeName:s,attrs:r})}n.sort((s,r)=>s.nodeName<r.nodeName?-1:1);let i="";for(let s=0;s<n.length;s++){const r=n[s];i+=`<${r.nodeName}`;for(let o=0;o<r.attrs.length;o++){const l=r.attrs[o];i+=` ${l.key}="${l.value}"`}i+=">"}i+=t.insert;for(let s=n.length-1;s>=0;s--)i+=`</${n[s].nodeName}>`;return i}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(pu)}}const Jh=e=>new at;class Wi{constructor(t,n){this.id=t,this.length=n}get deleted(){throw pt()}mergeWith(t){return!1}write(t,n,i){throw pt()}integrate(t,n){throw pt()}}const Xh=0;class dt extends Wi{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){n>0&&(this.id.clock+=n,this.length-=n),zr(t.doc.store,this)}write(t,n){t.writeInfo(Xh),t.writeLen(this.length-n)}getMissing(t,n){return null}}class Pe{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Pe(this.content)}splice(t){throw pt()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}const Zh=e=>new Pe(e.readBuf());class Re{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Re(this.len)}splice(t){const n=new Re(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){De(t.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(t){}gc(t){}write(t,n){t.writeLen(this.len-n)}getRef(){return 1}}const Qh=e=>new Re(e.readLen()),lo=(e,t)=>new Jt({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Ue{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const n={};this.opts=n,t.gc||(n.gc=!1),t.autoLoad&&(n.autoLoad=!0),t.meta!==null&&(n.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Ue(lo(this.doc.guid,this.opts))}splice(t){throw pt()}mergeWith(t){return!1}integrate(t,n){this.doc._item=n,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,n){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}const tu=e=>new Ue(lo(e.readString(),e.readAny()));class Xt{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Xt(this.embed)}splice(t){throw pt()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}const eu=e=>new Xt(e.readJSON());class F{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new F(this.key,this.value)}splice(t){throw pt()}mergeWith(t){return!1}integrate(t,n){const i=n.parent;i._searchMarker=null,i._hasFormatting=!0}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}const nu=e=>new F(e.readKey(),e.readJSON());class mn{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new mn(this.arr)}splice(t){const n=new mn(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const i=this.arr.length;t.writeLen(i-n);for(let s=n;s<i;s++){const r=this.arr[s];t.writeString(r===void 0?"undefined":JSON.stringify(r))}}getRef(){return 2}}const iu=e=>{const t=e.readLen(),n=[];for(let i=0;i<t;i++){const s=e.readString();s==="undefined"?n.push(void 0):n.push(JSON.parse(s))}return new mn(n)},su=ln("node_env")==="development";class Gt{constructor(t){this.arr=t,su&&lr(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Gt(this.arr)}splice(t){const n=new Gt(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const i=this.arr.length;t.writeLen(i-n);for(let s=n;s<i;s++){const r=this.arr[s];t.writeAny(r)}}getRef(){return 8}}const ru=e=>{const t=e.readLen(),n=[];for(let i=0;i<t;i++)n.push(e.readAny());return new Gt(n)};class St{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new St(this.str)}splice(t){const n=new St(this.str.slice(t));this.str=this.str.slice(0,t);const i=this.str.charCodeAt(t-1);return i>=55296&&i<=56319&&(this.str=this.str.slice(0,t-1)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(t){return this.str+=t.str,!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}}const ou=e=>new St(e.readString()),lu=[Ph,zh,Kh,Wh,qh,Yh,Jh],cu=0,au=1,hu=2,uu=3,du=4,fu=5,pu=6;class vt{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new vt(this.type._copy())}splice(t){throw pt()}mergeWith(t){return!1}integrate(t,n){this.type._integrate(t.doc,n)}delete(t){let n=this.type._start;for(;n!==null;)n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t),n=n.right;this.type._map.forEach(i=>{i.deleted?i.id.clock<(t.beforeState.get(i.id.client)||0)&&t._mergeStructs.push(i):i.delete(t)}),t.changed.delete(this.type)}gc(t){let n=this.type._start;for(;n!==null;)n.gc(t,!0),n=n.right;this.type._start=null,this.type._map.forEach(i=>{for(;i!==null;)i.gc(t,!0),i=i.left}),this.type._map=new Map}write(t,n){this.type._write(t)}getRef(){return 7}}const gu=e=>new vt(lu[e.readTypeRef()](e)),bi=(e,t)=>{let n=t,i=0,s;do i>0&&(n=T(n.client,n.clock+i)),s=ie(e,n),i=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof R);return{item:s,diff:i}},Gi=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},xn=(e,t,n)=>{const{client:i,clock:s}=t.id,r=new R(T(i,s+n),t,T(i,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&r.markDeleted(),t.keep&&(r.keep=!0),t.redone!==null&&(r.redone=T(t.redone.client,t.redone.clock+n)),t.right=r,r.right!==null&&(r.right.left=r),e._mergeStructs.push(r),r.parentSub!==null&&r.right===null&&r.parent._map.set(r.parentSub,r),t.length=n,r},As=(e,t)=>Di(e,n=>pe(n.deletions,t)),co=(e,t,n,i,s,r)=>{const o=e.doc,l=o.store,c=o.clientID,a=t.redone;if(a!==null)return lt(e,a);let u=t.parent._item,h=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||co(e,u,n,i,s,r)===null))return null;for(;u.redone!==null;)u=lt(e,u.redone)}const p=u===null?t.parent:u.content.type;if(t.parentSub===null){for(h=t.left,f=t;h!==null;){let y=h;for(;y!==null&&y.parent._item!==u;)y=y.redone===null?null:lt(e,y.redone);if(y!==null&&y.parent._item===u){h=y;break}h=h.left}for(;f!==null;){let y=f;for(;y!==null&&y.parent._item!==u;)y=y.redone===null?null:lt(e,y.redone);if(y!==null&&y.parent._item===u){f=y;break}f=f.right}}else{if(f=null,t.right&&!s){for(h=t;h!==null&&h.right!==null&&(h.right.redone||pe(i,h.right.id)||As(r.undoStack,h.right.id)||As(r.redoStack,h.right.id));)for(h=h.right;h.redone;)h=lt(e,h.redone);if(h&&h.right!==null)return null}else h=p._map.get(t.parentSub)||null;h!==null&&h.parent._item!==u&&(h=p._map.get(t.parentSub)||null)}const g=$(l,c),x=T(c,g),b=new R(x,h,h&&h.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=x,Gi(b,!0),b.integrate(e,0),b};class R extends Wi{constructor(t,n,i,s,r,o,l,c){super(t,c.getLength()),this.origin=i,this.left=n,this.right=s,this.rightOrigin=r,this.parent=o,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?is:0}set marker(t){(this.info&qn)>0!==t&&(this.info^=qn)}get marker(){return(this.info&qn)>0}get keep(){return(this.info&ns)>0}set keep(t){this.keep!==t&&(this.info^=ns)}get countable(){return(this.info&is)>0}get deleted(){return(this.info&Kn)>0}set deleted(t){this.deleted!==t&&(this.info^=Kn)}markDeleted(){this.info|=Kn}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=$(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=$(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ne&&this.id.client!==this.parent.client&&this.parent.clock>=$(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=bs(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=lt(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===dt||this.right&&this.right.constructor===dt)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===R?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===R&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===ne){const i=ie(n,this.parent);i.constructor===dt?this.parent=null:this.parent=i.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=bs(t,t.doc.store,T(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let i=this.left,s;if(i!==null)s=i.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;const r=new Set,o=new Set;for(;s!==null&&s!==this.right;){if(o.add(s),r.add(s),Ve(this.origin,s.origin)){if(s.id.client<this.id.client)i=s,r.clear();else if(Ve(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&o.has(ie(t.doc.store,s.origin)))r.has(ie(t.doc.store,s.origin))||(i=s,r.clear());else break;s=s.right}this.left=i}if(this.left!==null){const i=this.left.right;this.right=i,this.left.right=this}else{let i;if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start,this.parent._start=this;this.right=i}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),zr(t.doc.store,this),this.content.integrate(t,this),Ss(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new dt(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;t!==null&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;t!==null&&t.deleted;)t=t.left;return t}get lastId(){return this.length===1?this.id:T(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Ve(t.origin,this.lastId)&&this.right===t&&Ve(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const n=this.parent._searchMarker;return n&&n.forEach(i=>{i.p===t&&(i.p=this,!this.deleted&&this.countable&&(i.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),De(t.deleteSet,this.id.client,this.id.clock,this.length),Ss(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw rt();this.content.gc(t),n?yh(t,this,new dt(this.id,this.length)):this.content=new Re(this.length)}write(t,n){const i=n>0?T(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,r=this.parentSub,o=this.content.getRef()&vn|(i===null?0:st)|(s===null?0:It)|(r===null?0:Ce);if(t.writeInfo(o),i!==null&&t.writeLeftID(i),s!==null&&t.writeRightID(s),i===null&&s===null){const l=this.parent;if(l._item!==void 0){const c=l._item;if(c===null){const a=Ae(l);t.writeParentInfo(!0),t.writeString(a)}else t.writeParentInfo(!1),t.writeLeftID(c.id)}else l.constructor===String?(t.writeParentInfo(!0),t.writeString(l)):l.constructor===ne?(t.writeParentInfo(!1),t.writeLeftID(l)):rt();r!==null&&t.writeString(r)}this.content.write(t,n)}}const ao=(e,t)=>mu[t&vn](e),mu=[()=>{rt()},Qh,iu,Zh,ou,eu,nu,gu,ru,tu,()=>{rt()}],xu=10;class gt extends Wi{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){rt()}write(t,n){t.writeInfo(xu),A(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const ho=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},uo="__ $YJS$ __";ho[uo]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");ho[uo]=!0;const wu=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}};function fo(e,t,n){for(let i=0;;i++){if(i==e.childCount||i==t.childCount)return e.childCount==t.childCount?null:n;let s=e.child(i),r=t.child(i);if(s==r){n+=s.nodeSize;continue}if(!s.sameMarkup(r))return n;if(s.isText&&s.text!=r.text){for(let o=0;s.text[o]==r.text[o];o++)n++;return n}if(s.content.size||r.content.size){let o=fo(s.content,r.content,n+1);if(o!=null)return o}n+=s.nodeSize}}function po(e,t,n,i){for(let s=e.childCount,r=t.childCount;;){if(s==0||r==0)return s==r?null:{a:n,b:i};let o=e.child(--s),l=t.child(--r),c=o.nodeSize;if(o==l){n-=c,i-=c;continue}if(!o.sameMarkup(l))return{a:n,b:i};if(o.isText&&o.text!=l.text){let a=0,u=Math.min(o.text.length,l.text.length);for(;a<u&&o.text[o.text.length-a-1]==l.text[l.text.length-a-1];)a++,n--,i--;return{a:n,b:i}}if(o.content.size||l.content.size){let a=po(o.content,l.content,n-1,i-1);if(a)return a}n-=c,i-=c}}class L{constructor(t,n){if(this.content=t,this.size=n||0,n==null)for(let i=0;i<t.length;i++)this.size+=t[i].nodeSize}nodesBetween(t,n,i,s=0,r){for(let o=0,l=0;l<n;o++){let c=this.content[o],a=l+c.nodeSize;if(a>t&&i(c,s+l,r||null,o)!==!1&&c.content.size){let u=l+1;c.nodesBetween(Math.max(0,t-u),Math.min(c.content.size,n-u),i,s+u)}l=a}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,n,i,s){let r="",o=!0;return this.nodesBetween(t,n,(l,c)=>{let a=l.isText?l.text.slice(Math.max(t,c)-c,n-c):l.isLeaf?s?typeof s=="function"?s(l):s:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&a||l.isTextblock)&&i&&(o?o=!1:r+=i),r+=a},0),r}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,i=t.firstChild,s=this.content.slice(),r=0;for(n.isText&&n.sameMarkup(i)&&(s[s.length-1]=n.withText(n.text+i.text),r=1);r<t.content.length;r++)s.push(t.content[r]);return new L(s,this.size+t.size)}cut(t,n=this.size){if(t==0&&n==this.size)return this;let i=[],s=0;if(n>t)for(let r=0,o=0;o<n;r++){let l=this.content[r],c=o+l.nodeSize;c>t&&((o<t||c>n)&&(l.isText?l=l.cut(Math.max(0,t-o),Math.min(l.text.length,n-o)):l=l.cut(Math.max(0,t-o-1),Math.min(l.content.size,n-o-1))),i.push(l),s+=l.nodeSize),o=c}return new L(i,s)}cutByIndex(t,n){return t==n?L.empty:t==0&&n==this.content.length?this:new L(this.content.slice(t,n))}replaceChild(t,n){let i=this.content[t];if(i==n)return this;let s=this.content.slice(),r=this.size+n.nodeSize-i.nodeSize;return s[t]=n,new L(s,r)}addToStart(t){return new L([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new L(this.content.concat(t),this.size+t.nodeSize)}eq(t){if(this.content.length!=t.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(t.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(t){let n=this.content[t];if(!n)throw new RangeError("Index "+t+" out of range for "+this);return n}maybeChild(t){return this.content[t]||null}forEach(t){for(let n=0,i=0;n<this.content.length;n++){let s=this.content[n];t(s,i,n),i+=s.nodeSize}}findDiffStart(t,n=0){return fo(this,t,n)}findDiffEnd(t,n=this.size,i=t.size){return po(this,t,n,i)}findIndex(t){if(t==0)return qe(0,t);if(t==this.size)return qe(this.content.length,t);if(t>this.size||t<0)throw new RangeError(`Position ${t} outside of fragment (${this})`);for(let n=0,i=0;;n++){let s=this.child(n),r=i+s.nodeSize;if(r>=t)return r==t?qe(n+1,r):qe(n,i);i=r}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(t=>t.toJSON()):null}static fromJSON(t,n){if(!n)return L.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new L(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return L.empty;let n,i=0;for(let s=0;s<t.length;s++){let r=t[s];i+=r.nodeSize,s&&r.isText&&t[s-1].sameMarkup(r)?(n||(n=t.slice(0,s)),n[n.length-1]=r.withText(n[n.length-1].text+r.text)):n&&n.push(r)}return new L(n||t,i)}static from(t){if(!t)return L.empty;if(t instanceof L)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new L([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}L.empty=new L([],0);const ni={index:0,offset:0};function qe(e,t){return ni.index=e,ni.offset=t,ni}class ft{constructor(t,n,i){this.content=t,this.openStart=n,this.openEnd=i}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let i=mo(this.content,t+this.openStart,n);return i&&new ft(i,this.openStart,this.openEnd)}removeBetween(t,n){return new ft(go(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(t){return this.content.eq(t.content)&&this.openStart==t.openStart&&this.openEnd==t.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let t={content:this.content.toJSON()};return this.openStart>0&&(t.openStart=this.openStart),this.openEnd>0&&(t.openEnd=this.openEnd),t}static fromJSON(t,n){if(!n)return ft.empty;let i=n.openStart||0,s=n.openEnd||0;if(typeof i!="number"||typeof s!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new ft(L.fromJSON(t,n.content),i,s)}static maxOpen(t,n=!0){let i=0,s=0;for(let r=t.firstChild;r&&!r.isLeaf&&(n||!r.type.spec.isolating);r=r.firstChild)i++;for(let r=t.lastChild;r&&!r.isLeaf&&(n||!r.type.spec.isolating);r=r.lastChild)s++;return new ft(t,i,s)}}ft.empty=new ft(L.empty,0,0);function go(e,t,n){let{index:i,offset:s}=e.findIndex(t),r=e.maybeChild(i),{index:o,offset:l}=e.findIndex(n);if(s==t||r.isText){if(l!=n&&!e.child(o).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(i!=o)throw new RangeError("Removing non-flat range");return e.replaceChild(i,r.copy(go(r.content,t-s-1,n-s-1)))}function mo(e,t,n,i){let{index:s,offset:r}=e.findIndex(t),o=e.maybeChild(s);if(r==t||o.isText)return i&&!i.canReplace(s,s,n)?null:e.cut(0,t).append(n).append(e.cut(t));let l=mo(o.content,t-r-1,n,o);return l&&e.replaceChild(s,o.copy(l))}const bu=/[\uD800-\uDBFF]/,yu=/[\uDC00-\uDFFF]/,Su=(e,t)=>{let n=0,i=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&bu.test(e[n-1])&&n--;i+n<e.length&&i+n<t.length&&e[e.length-i-1]===t[t.length-i-1];)i++;return i>0&&yu.test(e[e.length-i])&&i--,{index:n,remove:e.length-n-i,insert:t.slice(n,t.length-i)}},vu=Su,Tt=(e,t)=>e>>>t|e<<32-t,Cu=e=>Tt(e,2)^Tt(e,13)^Tt(e,22),ku=e=>Tt(e,6)^Tt(e,11)^Tt(e,25),Eu=e=>Tt(e,7)^Tt(e,18)^e>>>3,Tu=e=>Tt(e,17)^Tt(e,19)^e>>>10,_u=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Du=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class Au{constructor(){const t=new ArrayBuffer(320);this._H=new Uint32Array(t,0,8),this._H.set(Du),this._W=new Uint32Array(t,64,64)}_updateHash(){const t=this._H,n=this._W;for(let h=16;h<64;h++)n[h]=Tu(n[h-2])+n[h-7]+Eu(n[h-15])+n[h-16];let i=t[0],s=t[1],r=t[2],o=t[3],l=t[4],c=t[5],a=t[6],u=t[7];for(let h=0,f,p;h<64;h++)f=u+ku(l)+(l&c^~l&a)+_u[h]+n[h]>>>0,p=Cu(i)+(i&s^i&r^s&r)>>>0,u=a,a=c,c=l,l=o+f>>>0,o=r,r=s,s=i,i=f+p>>>0;t[0]+=i,t[1]+=s,t[2]+=r,t[3]+=o,t[4]+=l,t[5]+=c,t[6]+=a,t[7]+=u}digest(t){let n=0;for(;n+56<=t.length;){let o=0;for(;o<16&&n+3<t.length;o++)this._W[o]=t[n++]<<24|t[n++]<<16|t[n++]<<8|t[n++];if(n%64!==0){for(this._W.fill(0,o,16);n<t.length;)this._W[o]|=t[n]<<(3-n%4)*8,n++;this._W[o]|=st<<(3-n%4)*8}this._updateHash()}const i=n%64!==0;this._W.fill(0,0,16);let s=0;for(;n<t.length;s++)for(let o=3;o>=0&&n<t.length;o--)this._W[s]|=t[n++]<<o*8;i||(this._W[s-(n%4===0?0:1)]|=st<<(3-n%4)*8),this._W[14]=t.byteLength/cc,this._W[15]=t.byteLength*8,this._updateHash();const r=new Uint8Array(32);for(let o=0;o<this._H.length;o++)for(let l=0;l<4;l++)r[o*4+l]=this._H[o]>>>(3-l)*8;return r}}const Iu=e=>new Au().digest(e),B=new O.PluginKey("y-sync"),Mt=new O.PluginKey("y-undo");new O.PluginKey("yjs-cursor");const Mu=e=>{for(let n=6;n<e.length;n++)e[n%6]=e[n%6]^e[n];return e.slice(0,6)},Ou=e=>la(Mu(Iu(ca(e)))),wn=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!pe(t.ds,e.id),Ru=[{light:"#ecd44433",dark:"#ecd444"}],ju=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){const i=Kt();e.forEach(s=>i.add(s)),t=t.filter(s=>!i.has(s))}e.set(n,$c(t))}return e.get(n)},Nu=(e,{colors:t=Ru,colorMapping:n=new Map,permanentUserData:i=null,onFirstRender:s=()=>{},mapping:r}={})=>{let o=!1;const l=new Uu(e,r),c=new O.Plugin({props:{editable:a=>{const u=B.getState(a);return u.snapshot==null&&u.prevSnapshot==null}},key:B,state:{init:(a,u)=>({type:e,doc:e.doc,binding:l,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:t,colorMapping:n,permanentUserData:i}),apply:(a,u)=>{const h=a.getMeta(B);if(h!==void 0){u=Object.assign({},u);for(const f in h)u[f]=h[f]}return u.addToHistory=a.getMeta("addToHistory")!==!1,u.isChangeOrigin=h!==void 0&&!!h.isChangeOrigin,u.isUndoRedoOperation=h!==void 0&&!!h.isChangeOrigin&&!!h.isUndoRedoOperation,l.prosemirrorView!==null&&h!==void 0&&(h.snapshot!=null||h.prevSnapshot!=null)&&Tr(0,()=>{l.prosemirrorView!=null&&(h.restore==null?l._renderSnapshot(h.snapshot,h.prevSnapshot,u):(l._renderSnapshot(h.snapshot,h.snapshot,u),delete u.restore,delete u.snapshot,delete u.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),u}},view:a=>(l.initView(a),r==null&&l._forceRerender(),s(),{update:()=>{const u=c.getState(a.state);if(u.snapshot==null&&u.prevSnapshot==null&&(o||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(o=!0,u.addToHistory===!1&&!u.isChangeOrigin){const h=Mt.getState(a.state),f=h&&h.undoManager;f&&f.stopCapturing()}l.mux(()=>{u.doc.transact(h=>{h.meta.set("addToHistory",u.addToHistory),l._prosemirrorChanged(a.state.doc)},B)})}},destroy:()=>{l.destroy()}})});return c},Bu=(e,t,n)=>{if(t!==null&&t.anchor!==null&&t.head!==null)if(t.type==="all")e.setSelection(new O.AllSelection(e.doc));else if(t.type==="node"){const i=Vt(n.doc,n.type,t.anchor,n.mapping);i!==null&&e.setSelection(Lu(e,i))}else if(t.type==="nodeRange"){const i=Vt(n.doc,n.type,t.anchor,n.mapping),s=Vt(n.doc,n.type,t.head,n.mapping),r=Pu(e,i,s,t.depth);r!==null&&e.setSelection(r)}else{const i=Vt(n.doc,n.type,t.anchor,n.mapping),s=Vt(n.doc,n.type,t.head,n.mapping);i!==null&&s!==null&&e.setSelection(O.TextSelection.between(e.doc.resolve(i),e.doc.resolve(s)))}},Lu=(e,t)=>{const n=e.doc.resolve(t);return n.nodeAfter?O.NodeSelection.create(e.doc,t):O.TextSelection.near(n)},Pu=(e,t,n,i)=>{if(t===null||n===null)return null;const s=Math.min(Math.max(t,0),e.doc.content.size),r=Math.min(Math.max(n,0),e.doc.content.size);try{const o=O.Selection.fromJSON(e.doc,{type:"nodeRange",anchor:s,head:r,depth:i});return o.ranges.length?o:O.TextSelection.near(e.doc.resolve(s))}catch{return O.TextSelection.near(e.doc.resolve(s))}},yi=(e,t)=>{const n=t.selection.jsonID;return{type:n,depth:n==="nodeRange"?t.selection.depth:void 0,anchor:yn(t.selection.anchor,e.type,e.mapping),head:yn(t.selection.head,e.type,e.mapping)}};class Uu{constructor(t,n=new Map){this.type=t,this.prosemirrorView=null,this.mux=wu(),this.mapping=n,this.isOMark=new Map,this._observeFunction=this._typeChanged.bind(this),this.doc=t.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=yi(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return this.prosemirrorView.hasFocus()?(cr&&this._domSelectionInView===null&&(Tr(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){const t=this.prosemirrorView._root.getSelection();if(t==null||t.anchorNode==null)return!1;const n=this.prosemirrorView._root.createRange();n.setStart(t.anchorNode,t.anchorOffset),n.setEnd(t.focusNode,t.focusOffset),n.getClientRects().length===0&&n.startContainer&&n.collapsed&&n.selectNodeContents(n.startContainer);const s=n.getBoundingClientRect(),r=Le.documentElement;return s.bottom>=0&&s.right>=0&&s.left<=(window.innerWidth||r.clientWidth||0)&&s.top<=(window.innerHeight||r.clientHeight||0)}renderSnapshot(t,n){n||(n=Pr(jr(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(B,{snapshot:t,prevSnapshot:n}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{const t=this.type.toArray().map(i=>tn(i,this.prosemirrorView.state.schema,this)).filter(i=>i!==null),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new ft(L.from(t),0,0));n.setMeta(B,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(n)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{const t=this.beforeTransactionSelection!==null?null:this.prosemirrorView.state.selection,n=this.type.toArray().map(s=>tn(s,this.prosemirrorView.state.schema,this)).filter(s=>s!==null),i=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new ft(L.from(n),0,0));if(t){const s=oe(Bt(t.anchor,0),i.doc.content.size),r=oe(Bt(t.head,0),i.doc.content.size);i.setSelection(O.TextSelection.create(i.doc,s,r))}this.prosemirrorView.dispatch(i.setMeta(B,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(t,n,i){let s=this.doc,r=this.type;if(t||(t=Qn(this.doc)),t instanceof Uint8Array||n instanceof Uint8Array)if((!(t instanceof Uint8Array)||!(n instanceof Uint8Array))&&rt(),s=new Jt({gc:!1}),gi(s,n),n=Qn(s),gi(s,t),t=Qn(s),r._item===null){const o=Array.from(this.doc.share.keys()).find(l=>this.doc.share.get(l)===this.type);r=s.getXmlFragment(o)}else{const o=s.store.clients.get(r._item.id.client)??[],l=yt(o,r._item.id.clock);r=o[l].content.type}this.mapping.clear(),this.mux(()=>{s.transact(o=>{const l=i.permanentUserData;l&&l.dss.forEach(h=>{Lt(o,h,f=>{})});const c=(h,f)=>{const p=h==="added"?l.getUserByClientId(f.client):l.getUserByDeletedId(f);return{user:p,type:h,color:ju(i.colorMapping,i.colors,p)}},a=Yr(r,new Fi(n.ds,t.sv)).map(h=>!h._item.deleted||wn(h._item,t)||wn(h._item,n)?tn(h,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},t,n,c):null).filter(h=>h!==null),u=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new ft(L.from(a),0,0));this.prosemirrorView.dispatch(u.setMeta(B,{isChangeOrigin:!0}))},B)})}_typeChanged(t,n){if(this.prosemirrorView==null)return;const i=B.getState(this.prosemirrorView.state);if(t.length===0||i.snapshot!=null||i.prevSnapshot!=null){this.renderSnapshot(i.snapshot,i.prevSnapshot);return}this.mux(()=>{const s=(l,c)=>this.mapping.delete(c);Lt(n,n.deleteSet,l=>{if(l.constructor===R){const c=l.content.type;c&&this.mapping.delete(c)}}),n.changed.forEach(s),n.changedParentTypes.forEach(s);const r=this.type.toArray().map(l=>xo(l,this.prosemirrorView.state.schema,this)).filter(l=>l!==null);let o=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new ft(L.from(r),0,0));Bu(o,this.beforeTransactionSelection,this),o=o.setMeta(B,{isChangeOrigin:!0,isUndoRedoOperation:n.origin instanceof Fr}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)})}_prosemirrorChanged(t){this.doc.transact(()=>{vi(this.doc,this.type,t,this),this.beforeTransactionSelection=yi(this,this.prosemirrorView.state)},B)}initView(t){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=t,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}}const xo=(e,t,n,i,s,r)=>{const o=n.mapping.get(e);if(o===void 0){if(e instanceof it)return tn(e,t,n,i,s,r);throw pt()}return o},tn=(e,t,n,i,s,r)=>{const o=[],l=c=>{var a,u;if(c instanceof it){const h=xo(c,t,n,i,s,r);h!==null&&o.push(h)}else{const h=(u=(a=c._item.right)==null?void 0:a.content)==null?void 0:u.type;h instanceof Pt&&!h._item.deleted&&h._item.id.client===h.doc.clientID&&(c.applyDelta([{retain:c.length},...h.toDelta()]),h.doc.transact(p=>{h._item.delete(p)}));const f=zu(c,t,n,i,s,r);f!==null&&f.forEach(p=>{p!==null&&o.push(p)})}};i===void 0||s===void 0?e.toArray().forEach(l):Yr(e,new Fi(s.ds,i.sv)).forEach(l);try{const c=e.getAttributes(i);i!==void 0&&(wn(e._item,i)?wn(e._item,s)||(c.ychange=r?r("added",e._item.id):{type:"added"}):c.ychange=r?r("removed",e._item.id):{type:"removed"});const a=t.node(e.nodeName,c,o);return n.mapping.set(e,a),a}catch{return e.doc.transact(a=>{e._item.delete(a)},B),n.mapping.delete(e),null}},zu=(e,t,n,i,s,r)=>{const o=[],l=e.toDelta(i,s,r);try{for(let c=0;c<l.length;c++){const a=l[c];o.push(t.text(a.insert,qu(a.attributes,t)))}}catch{return e.doc.transact(a=>{e._item.delete(a)},B),null}return o},$u=(e,t)=>{const n=new at,i=e.map(s=>({insert:s.text,attributes:yo(s.marks,t)}));return n.applyDelta(i),t.mapping.set(n,e),n},Vu=(e,t)=>{const n=new it(e.type.name);for(const i in e.attrs){const s=e.attrs[i];s!==null&&i!=="ychange"&&n.setAttribute(i,s)}return n.insert(0,Bn(e).map(i=>Si(i,t))),t.mapping.set(n,e),n},Si=(e,t)=>e instanceof Array?$u(e,t):Vu(e,t),Is=e=>typeof e=="object"&&e!==null,Yi=(e,t)=>{const n=Object.keys(e).filter(s=>e[s]!==null);let i=n.length===Object.keys(t).filter(s=>t[s]!==null).length;for(let s=0;s<n.length&&i;s++){const r=n[s],o=e[r],l=t[r];i=r==="ychange"||o===l||Is(o)&&Is(l)&&Yi(o,l)}return i},Bn=e=>{const t=e.content.content,n=[];for(let i=0;i<t.length;i++){const s=t[i];if(s.isText){const r=[];for(let o=t[i];i<t.length&&o.isText;o=t[++i])r.push(o);i--,n.push(r)}else n.push(s)}return n},wo=(e,t)=>{const n=e.toDelta();return n.length===t.length&&n.every((i,s)=>i.insert===t[s].text&&or(i.attributes||{}).length===t[s].marks.length&&ue(i.attributes,(r,o)=>{var u;const l=bo(o),c=t[s].marks;return c.find(h=>h.type.name===l)?Yi(r,(u=c.find(h=>h.type.name===l))==null?void 0:u.attrs):!1}))},je=(e,t)=>{if(e instanceof it&&!(t instanceof Array)&&Ci(e,t)){const n=Bn(t);return e._length===n.length&&Yi(e.getAttributes(),t.attrs)&&e.toArray().every((i,s)=>je(i,n[s]))}return e instanceof at&&t instanceof Array&&wo(e,t)},bn=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((n,i)=>t[i]===n),Ms=(e,t,n)=>{const i=e.toArray(),s=Bn(t),r=s.length,o=i.length,l=oe(o,r);let c=0,a=0,u=!1;for(;c<l;c++){const h=i[c],f=s[c];if(bn(n.mapping.get(h),f))u=!0;else if(!je(h,f))break}for(;c+a<l;a++){const h=i[o-a-1],f=s[r-a-1];if(bn(n.mapping.get(h),f))u=!0;else if(!je(h,f))break}return{equalityFactor:c+a,foundMappedChild:u}},Fu=e=>{let t="",n=e._start;const i={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof St?t+=n.content.str:n.content instanceof F&&(i[n.content.key]=null)),n=n.right;return{str:t,nAttrs:i}},Hu=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:i,str:s}=Fu(e),r=t.map(a=>({insert:a.text,attributes:Object.assign({},i,yo(a.marks,n))})),{insert:o,remove:l,index:c}=vu(s,r.map(a=>a.insert).join(""));e.delete(c,l),e.insert(c,o),e.applyDelta(r.map(a=>({retain:a.insert.length,attributes:a.attributes})))},Ku=/(.*)(--[a-zA-Z0-9+/=]{8})$/,bo=e=>{var t;return((t=Ku.exec(e))==null?void 0:t[1])??e},qu=(e,t)=>{const n=[];for(const i in e)n.push(t.mark(bo(i),e[i]));return n},yo=(e,t)=>{const n={};return e.forEach(i=>{if(i.type.name!=="ychange"){const s=Ot(t.isOMark,i.type,()=>!i.type.excludes(i.type));n[s?`${i.type.name}--${Ou(i.toJSON())}`:i.type.name]=i.attrs}}),n},vi=(e,t,n,i)=>{if(t instanceof it&&t.nodeName!==n.type.name)throw new Error("node name mismatch!");if(i.mapping.set(t,n),t instanceof it){const h=t.getAttributes(),f=n.attrs;for(const p in f)f[p]!==null?h[p]!==f[p]&&p!=="ychange"&&t.setAttribute(p,f[p]):t.removeAttribute(p);for(const p in h)f[p]===void 0&&t.removeAttribute(p)}const s=Bn(n),r=s.length,o=t.toArray(),l=o.length,c=oe(r,l);let a=0,u=0;for(;a<c;a++){const h=o[a],f=s[a];if(!bn(i.mapping.get(h),f))if(je(h,f))i.mapping.set(h,f);else break}for(;u+a+1<c;u++){const h=o[l-u-1],f=s[r-u-1];if(!bn(i.mapping.get(h),f))if(je(h,f))i.mapping.set(h,f);else break}e.transact(()=>{for(;l-a-u>0&&r-a-u>0;){const f=o[a],p=s[a],g=o[l-u-1],x=s[r-u-1];if(f instanceof at&&p instanceof Array)wo(f,p)||Hu(f,p,i),a+=1;else{let b=f instanceof it&&Ci(f,p),y=g instanceof it&&Ci(g,x);if(b&&y){const C=Ms(f,p,i),S=Ms(g,x,i);C.foundMappedChild&&!S.foundMappedChild?y=!1:!C.foundMappedChild&&S.foundMappedChild||C.equalityFactor<S.equalityFactor?b=!1:y=!1}b?(vi(e,f,p,i),a+=1):y?(vi(e,g,x,i),u+=1):(i.mapping.delete(t.get(a)),t.delete(a,1),t.insert(a,[Si(p,i)]),a+=1)}}const h=l-a-u;if(l===1&&r===0&&o[0]instanceof at?(i.mapping.delete(o[0]),o[0].delete(0,o[0].length)):h>0&&(t.slice(a,a+h).forEach(f=>i.mapping.delete(f)),t.delete(a,h)),a+u<r){const f=[];for(let p=a;p<r-u;p++)f.push(Si(s[p],i));t.insert(a,f)}},B)},Ci=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,yn=(e,t,n)=>{if(e===0)return Zn(t,0,-1);let i=t._first===null?null:t._first.content.type;for(;i!==null&&t!==i;){if(i instanceof at){if(i._length>=e)return Zn(i,e,-1);if(e-=i._length,i._item!==null&&i._item.next!==null)i=i._item.next.content.type;else{do i=i._item===null?null:i._item.parent,e--;while(i!==t&&i!==null&&i._item!==null&&i._item.next===null);i!==null&&i!==t&&(i=i._item===null?null:i._item.next.content.type)}}else{const s=(n.get(i)||{nodeSize:0}).nodeSize;if(i._first!==null&&e<s)i=i._first.content.type,e--;else{if(e===1&&i._length===0&&s>1)return new dn(i._item===null?null:i._item.id,i._item===null?Ae(i):null,null);if(e-=s,i._item!==null&&i._item.next!==null)i=i._item.next.content.type;else{if(e===0)return i=i._item===null?i:i._item.parent,new dn(i._item===null?null:i._item.id,i._item===null?Ae(i):null,null);do i=i._item.parent,e--;while(i!==t&&i._item.next===null);i!==t&&(i=i._item.next.content.type)}}}if(i===null)throw rt();if(e===0&&i.constructor!==at&&i!==t)return Wu(i._item.parent,i._item)}return Zn(t,t._length,-1)},Wu=(e,t)=>{let n=null,i=null;return e._item===null?i=Ae(e):n=T(e._item.id.client,e._item.id.clock),new dn(n,i,t.id)},Vt=(e,t,n,i)=>{const s=wh(n,e);if(s===null||s.type!==t&&!Ie(t,s.type._item))return null;let r=s.type,o=0;if(r.constructor===at)o=s.index;else if(r._item===null||!r._item.deleted){let l=r._first,c=0;for(;c<r._length&&c<s.index&&l!==null;){if(!l.deleted){const a=l.content.type;if(c++,a instanceof at)o+=a._length;else{const u=i.get(a);if(u==null)return null;o+=u.nodeSize}}l=l.right}o+=1}for(;r!==t&&r._item!==null;){const l=r._item.parent;if(l._item===null||!l._item.deleted){o+=1;let c=l._first;for(;c!==null;){const a=c.content.type;if(a===r)break;if(!c.deleted)if(a instanceof at)o+=a._length;else{const u=i.get(a);if(u==null)return null;o+=u.nodeSize}c=c.right}}r=l}return o-1},Gu=e=>{const t=Mt.getState(e).undoManager;if(t!=null)return t.undo(),!0},Yu=e=>{const t=Mt.getState(e).undoManager;if(t!=null)return t.redo(),!0},Ju=new Set(["paragraph"]),Xu=(e,t)=>!(e instanceof R)||!(e.content instanceof vt)||!(e.content.type instanceof Pt||e.content.type instanceof it&&t.has(e.content.type.nodeName))||e.content.type._length===0,Zu=({protectedNodes:e=Ju,trackedOrigins:t=[],undoManager:n=null}={})=>new O.Plugin({key:Mt,state:{init:(i,s)=>{const r=B.getState(s);let o=n;if(!o){const l=r.doc,c=new Set(l?l._observers.get("destroy"):[]);o=new Fr(r.type,{trackedOrigins:new Set([B].concat(t)),deleteFilter:u=>Xu(u,e),captureTransaction:u=>u.meta.get("addToHistory")!==!1});const a=l?l._observers.get("destroy"):new Set;o._yTiptapDocDestroyListeners=Array.from(a||[]).filter(u=>!c.has(u))}return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(i,s,r,o)=>{const l=B.getState(o).binding,c=s.undoManager,a=c.undoStack.length>0,u=c.redoStack.length>0;return l?{undoManager:c,prevSel:yi(l,r),hasUndoOps:a,hasRedoOps:u}:a!==s.hasUndoOps||u!==s.hasRedoOps?Object.assign({},s,{hasUndoOps:c.undoStack.length>0,hasRedoOps:c.redoStack.length>0}):s}},view:i=>{const s=B.getState(i.state),r=Mt.getState(i.state).undoManager;return r.on("stack-item-added",({stackItem:o})=>{const l=s.binding;l&&o.meta.set(l,Mt.getState(i.state).prevSel)}),r.on("stack-item-popped",({stackItem:o})=>{const l=s.binding;l&&(l.beforeTransactionSelection=o.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{r.destroy();const o=r._yTiptapDocDestroyListeners;o&&r.doc&&(o.forEach(l=>r.doc.off("destroy",l)),r._yTiptapDocDestroyListeners=null)}}}});function Ji(e){return!!e.getMeta(B)}function Qu(e,t){const n=B.getState(e);return Vt(n.doc,n.type,t,n.binding.mapping)||0}function So(e,t){const n=B.getState(e);return yn(t,n.type,n.binding.mapping)}var en=class vo extends O.MappablePosition{constructor(t,n){super(t),this.yRelativePosition=n}static fromJSON(t){return new vo(t.position,t.yRelativePosition)}toJSON(){return{position:this.position,yRelativePosition:this.yRelativePosition}}};function td(e,t){const n=So(t,e);return new en(e,n)}function ed(e,t,n){const i=e instanceof en?e.yRelativePosition:null;if(Ji(t)&&i){const o=Qu(n,i);return{position:new en(o,i),mapResult:null}}const s=O.getUpdatedPosition(e,t),r=s.position.position;return{position:new en(r,i??So(n,r)),mapResult:s.mapResult}}O.Extension.create({name:"collaboration",priority:1e3,addOptions(){return{document:null,field:"default",fragment:null,provider:null}},addStorage(){return{isDisabled:!1}},onCreate(){this.editor.extensionManager.extensions.find(e=>e.name==="undoRedo")&&console.warn('[tiptap warn]: "@tiptap/extension-collaboration" comes with its own history support and is not compatible with "@tiptap/extension-undo-redo".')},onBeforeCreate(){this.editor.utils.getUpdatedPosition=(e,t)=>ed(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>td(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),Mt.getState(t).undoManager.undoStack.length===0?!1:n?Gu(t):!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),Mt.getState(t).undoManager.redoStack.length===0?!1:n?Yu(t):!0)}},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo()}},addProseMirrorPlugins(){const e=this.options.fragment?this.options.fragment:this.options.document.getXmlFragment(this.options.field),t=Zu(this.options.yUndoOptions),n=t.spec.view;t.spec.view=r=>{const{undoManager:o}=Mt.getState(r.state);o.restore&&(o.restore(),o.restore=()=>{});const l=n?n(r):void 0;return{destroy:()=>{const c=o.trackedOrigins.has(o),a=o._observers;o.restore=()=>{c&&o.trackedOrigins.add(o),o.doc.on("afterTransaction",o.afterTransactionHandler),o._observers=a},l!=null&&l.destroy&&l.destroy()}}};const i={...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender};return[Nu(e,i),t,this.editor.options.enableContentCheck&&new G.Plugin({key:new G.PluginKey("filterInvalidContent"),filterTransaction:r=>{if(!Ji(r))return!0;if(this.storage.isDisabled)return!1;if(!r.docChanged)return!0;try{return r.doc.check(),!0}catch(o){return this.storage.isDisabled=!0,this.editor.emit("contentError",{error:o,editor:this.editor,disableCollaboration:()=>{var l;(l=e.doc)==null||l.destroy()}}),!0}}})].filter(Boolean)}});function Os(e){if(!e.length)return $n.DecorationSet.empty;const t=[],n=e[0].$from.node(0);return e.forEach(i=>{const s=i.$from.pos,r=i.$from.nodeAfter;r&&t.push($n.Decoration.node(s,s+r.nodeSize,{class:"ProseMirror-selectednoderange"}))}),$n.DecorationSet.create(n,t)}function nd(e,t,n){const i=n.isText||n.isAtom?0:1;return{start:e+i,end:e+t-i}}function Ln(e,t,n,i={}){const s=[],r=e.node(0),{extendOnBoundaryOverlap:o=!0}=i;typeof n=="number"&&n>=0||(e.sameParent(t)?n=Math.max(0,e.sharedDepth(t.pos)-1):n=e.sharedDepth(t.pos));const l=new zo.NodeRange(e,t,n),c=l.depth===0?0:r.resolve(l.start).posAtIndex(0);return l.parent.forEach((a,u)=>{const h=c+u,f=h+a.nodeSize,p=nd(h,a.nodeSize,a),g=o?t.pos>=p.start&&e.pos<=p.end:t.pos>p.start&&e.pos<p.end;if(h<l.start||h>=l.end||!g)return;const x=new G.SelectionRange(r.resolve(h),r.resolve(f));s.push(x)}),s}var id=class Co{constructor(t,n,i){this.anchor=t,this.head=n,this.depth=i??0}map(t){return new Co(t.map(this.anchor),t.map(this.head),this.depth)}resolve(t){const n=t.resolve(this.anchor),i=t.resolve(this.head);return new kt(n,i,this.depth)}},kt=class jt extends G.Selection{constructor(t,n,i,s=1){const{doc:r}=t,o=t===n,l=t.pos===r.content.size&&n.pos===r.content.size,c=o&&!l?r.resolve(n.pos+(s>0?1:-1)):n,a=o&&l?r.resolve(t.pos-(s>0?1:-1)):t,u=Ln(a.min(c),a.max(c),i),h=c.pos>=t.pos?u[0].$from:u[u.length-1].$to,f=c.pos>=t.pos?u[u.length-1].$to:u[0].$from;super(h,f,u),this.depth=i}get $to(){return this.ranges[this.ranges.length-1].$to}eq(t){return t instanceof jt&&t.$from.pos===this.$from.pos&&t.$to.pos===this.$to.pos}map(t,n){const i=t.resolve(n.map(this.anchor)),s=t.resolve(n.map(this.head));return new jt(i,s,this.depth)}toJSON(){return{type:"nodeRange",anchor:this.anchor,head:this.head,depth:this.depth}}get isForwards(){return this.head>=this.anchor}get isBackwards(){return!this.isForwards}extendBackwards(){const{doc:t}=this.$from;if(this.isForwards&&this.ranges.length>1){const s=this.ranges.slice(0,-1),r=s[0].$from,o=s[s.length-1].$to;return new jt(r,o,this.depth)}const n=this.ranges[0],i=t.resolve(Math.max(0,n.$from.pos-1));return new jt(this.$anchor,i,this.depth)}extendForwards(){const{doc:t}=this.$from;if(this.isBackwards&&this.ranges.length>1){const s=this.ranges.slice(1),r=s[0].$from,o=s[s.length-1].$to;return new jt(o,r,this.depth)}const n=this.ranges[this.ranges.length-1],i=t.resolve(Math.min(t.content.size,n.$to.pos+1));return new jt(this.$anchor,i,this.depth)}static fromJSON(t,n){return new jt(t.resolve(n.anchor),t.resolve(n.head),n.depth)}static create(t,n,i,s,r=1){return new this(t.resolve(n),t.resolve(i),s,r)}getBookmark(){return new id(this.anchor,this.head,this.depth)}};kt.prototype.visible=!1;try{G.Selection.jsonID("nodeRange",kt)}catch{}function Se(e){return e instanceof kt}O.Extension.create({name:"nodeRange",addOptions(){return{depth:void 0,key:"Mod"}},addKeyboardShortcuts(){return{"Shift-ArrowUp":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,selection:r,tr:o}=i,{anchor:l,head:c}=r;if(!Se(r)){const u=kt.create(s,l,c,t,-1);return o.setSelection(u),n.dispatch(o),!0}const a=r.extendBackwards();return o.setSelection(a),n.dispatch(o),!0},"Shift-ArrowDown":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,selection:r,tr:o}=i,{anchor:l,head:c}=r;if(!Se(r)){const u=kt.create(s,l,c,t);return o.setSelection(u),n.dispatch(o),!0}const a=r.extendForwards();return o.setSelection(a),n.dispatch(o),!0},"Mod-a":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,tr:r}=i,o=kt.create(s,0,s.content.size,t);return r.setSelection(o),n.dispatch(r),!0}}},onSelectionUpdate(){const{selection:e}=this.editor.state;Se(e)&&this.editor.view.dom.classList.add("ProseMirror-noderangeselection")},addProseMirrorPlugins(){let e=!1,t=!1;return[new G.Plugin({key:new G.PluginKey("nodeRange"),props:{attributes:()=>e?{class:"ProseMirror-noderangeselection"}:{class:""},handleDOMEvents:{mousedown:(n,i)=>{const{key:s}=this.options,r=/Mac/.test(navigator.platform),o=!!i.shiftKey,l=!!i.ctrlKey,c=!!i.altKey,a=!!i.metaKey,u=r?a:l;return(s==null||s==="Shift"&&o||s==="Control"&&l||s==="Alt"&&c||s==="Meta"&&a||s==="Mod"&&u)&&(t=!0),t&&document.addEventListener("mouseup",()=>{t=!1;const{state:h}=n,{doc:f,selection:p,tr:g}=h,{$anchor:x,$head:b}=p;if(x.sameParent(b))return;const y=kt.create(f,x.pos,b.pos,this.options.depth);g.setSelection(y),n.dispatch(g)},{once:!0}),!1}},decorations:n=>{const{selection:i}=n,s=Se(i);if(e=!1,!t)return s?(e=!0,Os(i.ranges)):null;const{$from:r,$to:o}=i;if(!s&&r.sameParent(o))return null;const l=Ln(r,o,this.options.depth);return l.length?(e=!0,Os(l)):null}}})]}});function sd(e,t){const n=getComputedStyle(e);if(t)return t.map(s=>s.trim()).filter(s=>s.length>0).map(s=>`${s}:${n.getPropertyValue(s)};`).join("");let i="";for(let s=0;s<n.length;s+=1)i+=`${n[s]}:${n.getPropertyValue(n[s])};`;return i}function rd(e,t){const n=e.cloneNode(!0),i=[e,...Array.from(e.getElementsByTagName("*"))],s=[n,...Array.from(n.getElementsByTagName("*"))];return i.forEach((r,o)=>{s[o].style.cssText=sd(r,t)}),n}var od={id:"listItemFirstChild",evaluate:({parent:e,isFirst:t})=>t&&e&&["listItem","taskItem"].includes(e.type.name)?1e3:0},ld={id:"listWrapperDeprioritize",evaluate:({node:e})=>{const t=["listItem","taskItem"],n=e.firstChild;return n&&t.includes(n.type.name)?1e3:0}},cd={id:"tableStructure",evaluate:({node:e,parent:t})=>["tableRow","tableCell","tableHeader"].includes(e.type.name)||t&&t.type.name==="tableHeader"?1e3:0},ad={id:"inlineContent",evaluate:({node:e})=>e.isInline||e.isText?1e3:0},hd=[od,ld,cd,ad],Rs={edges:["left","top"],threshold:12,strength:500};function ii(e){return e===void 0||e==="left"?{...Rs}:e==="right"?{edges:["right","top"],threshold:12,strength:500}:e==="both"?{edges:["left","right","top"],threshold:12,strength:500}:e==="none"?{edges:[],threshold:0,strength:0}:{...Rs,...e}}function ud(e,t,n){if(n.edges.length===0)return!1;const i=t.getBoundingClientRect(),{threshold:s,edges:r}=n;return r.some(o=>o==="left"?e.x-i.left<s:o==="right"?i.right-e.x<s:o==="top"?e.y-i.top<s:o==="bottom"?i.bottom-e.y<s:!1)}function dd(e,t,n,i){return!t||n.edges.length===0?0:ud(e,t,n)?n.strength*i:0}var fd=1e3;function js(e,t,n,i){let s=fd,r=!1;if(t.every(l=>{const c=l.evaluate(e);return s-=c,s<=0?(r=!0,!1):!0}),r)return-1;const o=e.view.nodeDOM(e.pos);return s-=dd(i,o,n,e.depth),s<=0?-1:s}function Ns(e,t,n){return Array.from({length:t},(s,r)=>t-1-r).some(s=>n.includes(e.node(s).type.name))}function pd(e,t,n){if(!Number.isFinite(t.x)||!Number.isFinite(t.y))return null;const i=e.posAtCoords({left:t.x,top:t.y});if(!i)return null;const{doc:s}=e.state,r=s.resolve(i.pos),o=[];n.defaultRules&&o.push(...hd),o.push(...n.rules);const c=Array.from({length:r.depth},(h,f)=>r.depth-f).map(h=>{const f=r.node(h),p=r.before(h);if(n.allowedContainers&&h>0&&!Ns(r,h,n.allowedContainers))return null;const g=h>0?r.node(h-1):null,x=h>0?r.index(h-1):0,b=g?g.childCount:1,y={node:f,pos:p,depth:h,parent:g,index:x,isFirst:x===0,isLast:x===b-1,$pos:r,view:e},C=js(y,o,n.edgeDetection,t);if(C<0)return null;const S=e.nodeDOM(p);return{node:f,pos:p,depth:h,score:C,dom:S}}).filter(h=>h!==null),a=r.nodeAfter;if(a&&a.isAtom&&!a.isInline){const h=i.pos,f=r.depth+1,p=r.parent,g=r.index(),x=p.childCount;let b=!0;if(n.allowedContainers&&(b=Ns(r,f,n.allowedContainers)),b){const y={node:a,pos:h,depth:f,parent:p,index:g,isFirst:g===0,isLast:g===x-1,$pos:r,view:e},C=js(y,o,n.edgeDetection,t);if(C>=0){const S=e.nodeDOM(h);S&&c.push({node:a,pos:h,depth:f,score:C,dom:S})}}}if(c.length===0)return null;c.sort((h,f)=>f.score!==h.score?f.score-h.score:f.depth-h.depth);const u=c[0];return u.dom?{node:u.node,pos:u.pos,dom:u.dom}:null}function gd(e,t){let n=e;for(;n!=null&&n.parentElement&&n.parentElement!==t.dom;)n=n.parentElement;return(n==null?void 0:n.parentElement)===t.dom?n:void 0}function Bs(e){return Number.isFinite(e.top)&&Number.isFinite(e.bottom)&&Number.isFinite(e.left)&&Number.isFinite(e.right)&&e.width>0&&e.height>0}function md(e,t,n,i=5){if(!Number.isFinite(t)||!Number.isFinite(n))return null;const s=e.dom,r=s.firstElementChild,o=s.lastElementChild;if(!r||!o)return null;const l=r.getBoundingClientRect(),c=o.getBoundingClientRect();if(!Bs(l)||!Bs(c))return null;const a=Math.min(Math.max(l.top+i,n),c.bottom-i),u=.5,h=Math.abs(l.left-c.left)<u,f=Math.abs(l.right-c.right)<u;let p=l;h&&f&&(p=l);const g=Math.min(Math.max(p.left+i,t),p.right-i);return!Number.isFinite(g)||!Number.isFinite(a)?null:{x:g,y:a}}var ko=e=>{const{x:t,y:n,editor:i,nestedOptions:s}=e,{view:r,state:o}=i,l=md(r,t,n,5);if(!l)return{resultElement:null,resultNode:null,pos:null};const{x:c,y:a}=l;if(s!=null&&s.enabled){const g=pd(r,{x:c,y:a},s);return g?{resultElement:g.dom,resultNode:g.node,pos:g.pos}:{resultElement:null,resultNode:null,pos:null}}const u=r.root.elementsFromPoint(c,a);let h;if(Array.prototype.some.call(u,g=>{if(!r.dom.contains(g))return!1;const x=gd(g,r);return x?(h=x,!0):!1}),!h){const g=r.posAtCoords({left:c,top:a});if(g){const x=o.doc.resolve(g.pos),b=Math.min(x.depth,1),y=b>0?x.before(b):x.pos,C=o.doc.nodeAt(y);if(C){const S=r.nodeDOM(y);return{resultElement:S instanceof HTMLElement?S:null,resultNode:C,pos:y}}}return{resultElement:null,resultNode:null,pos:null}}let f;try{f=r.posAtDOM(h,0)}catch{return{resultElement:null,resultNode:null,pos:null}}const p=o.doc.nodeAt(f);if(!p){const g=o.doc.resolve(f),x=g.parent;return{resultElement:h,resultNode:x,pos:g.start()}}return{resultElement:h,resultNode:p,pos:f}};function Eo(e,t){const n=e.nodeDOM(t);if(n instanceof Element&&n!==e.dom)return n;const{node:i,offset:s}=e.domAtPos(t),r=i.childNodes[s];return r instanceof Element?r:i instanceof Element?i:i.nodeType===Node.TEXT_NODE&&i.parentElement?i.parentElement:null}function xd(e,t){const n=Eo(e,t);return(n?getComputedStyle(n).direction:getComputedStyle(e.dom).direction)||"ltr"}function To(e){var t;(t=e.parentNode)==null||t.removeChild(e)}function wd(e,t){return e==="rtl"?t:0}function bd(e){return e?!e.some(t=>{const n=t.trim().toLowerCase();return n==="margin"||n.startsWith("margin-")}):!0}function yd(e,t,n,i){const{doc:s}=t.view.state;if(n!=null&&n.enabled&&(i!=null&&i.node)&&i.pos>=0){const a=i.pos,u=i.pos+i.node.nodeSize;return[{$from:s.resolve(a),$to:s.resolve(u)}]}const r=ko({editor:t,x:e.clientX,y:e.clientY,nestedOptions:n});if(!r.resultNode||r.pos===null)return[];const o=r.resultNode.isText||r.resultNode.isAtom?0:-1,l=s.resolve(r.pos),c=s.resolve(r.pos+r.resultNode.nodeSize+o);return Ln(l,c,0,{extendOnBoundaryOverlap:!1})}function Sd(e,t,n,i,s){const{view:r}=t;if(!e.dataTransfer)return;const{empty:o,$from:l,$to:c}=r.state.selection,a=yd(e,t,n,i),u=Ln(l,c,0,{extendOnBoundaryOverlap:!1}),h=u.some(k=>a.find(D=>D.$from===k.$from&&D.$to===k.$to)),f=o||!h?a:u;if(!f.length)return;const{tr:p}=r.state,g=document.createElement("div"),x=f[0].$from.pos,b=f[f.length-1].$to.pos,y=xd(r,x);g.setAttribute("dir",y);const C=(n==null?void 0:n.enabled)&&(i==null?void 0:i.node),S=f.length===1;let _,U;C&&S?(_=r.state.doc.slice(x,b),U=G.NodeSelection.create(r.state.doc,x)):(U=kt.create(r.state.doc,x,b),_=U.content());const I=bd(s);f.forEach(k=>{const D=Eo(r,k.$from.pos);if(!D)return;const v=rd(D,s);I&&(v.style.margin="0"),g.append(v)}),g.style.position="absolute",g.style.top="-10000px",document.body.append(g),e.dataTransfer.clearData();const E=g.getBoundingClientRect(),M=wd(y,E.width);e.dataTransfer.setDragImage(g,M,0);let Q=!1;const nt=()=>{Q||(Q=!0,To(g),document.removeEventListener("drop",nt),document.removeEventListener("dragend",nt))},ht=U instanceof G.NodeSelection?U:void 0;r.dragging={slice:_,move:!0,node:ht},p.setSelection(U),r.dispatch(p),document.addEventListener("drop",nt),document.addEventListener("dragend",nt)}function Ls(e,t,n){let i=0;for(let s=t;s<n;s+=1)i+=e.child(s).nodeSize;return i}function vd(e){var t;return Se(e)?{anchorPos:e.from,nodeCount:e.ranges.length,depth:(t=e.depth)!=null?t:0}:null}function Cd(e,t,n,i){const s=e.resolve(t),r=s.node(i);let o=s.index(i);o>=r.childCount&&(o=Math.max(0,r.childCount-n));const l=Math.min(n,r.childCount-o);if(l<=0)return null;const c=s.start(i)+Ls(r,0,o),a=c+Ls(r,o,o+l);return{anchor:c,head:a,count:l}}function kd(e,t,n,i){try{const s=Cd(e,t,n,i);if(!s)return null;const r=kt.create(e,s.anchor,s.head,i);return r.ranges.length===n?r:null}catch{return null}}var Ps=(e,t)=>{const n=e.resolve(t),{depth:i}=n;return i===0?t:n.pos-n.parentOffset-1},Us=(e,t)=>{const n=e.nodeAt(t),i=e.resolve(t);let{depth:s}=i,r=n;for(;s>0;){const o=i.node(s);s-=1,s===0&&(r=o)}return r},si=(e,t)=>{const n=B.getState(e);return n?yn(t,n.type,n.binding.mapping):null},Ed=(e,t)=>{const n=B.getState(e);return n?Vt(n.doc,n.type,t,n.binding.mapping)||0:-1},zs=(e,t)=>{let n=t;for(;n!=null&&n.parentNode&&n.parentNode!==e.dom;)n=n.parentNode;return n},_o=new G.PluginKey("dragHandle"),Do=({pluginKey:e=_o,element:t,editor:n,computePositionConfig:i,getReferencedVirtualElement:s,onNodeChange:r,onElementDragStart:o,onElementDragEnd:l,nestedOptions:c,dragImageProperties:a})=>{const u=document.createElement("div");let h=!1,f=null,p=-1,g,x=null,b=null,y=null,C=null,S=null;function _(){t&&(t.style.visibility="hidden",t.style.pointerEvents="none")}function U(){if(t){if(!n.isEditable){_();return}t.style.visibility="",t.style.pointerEvents="auto"}}function I(k){const D=(s==null?void 0:s())||{getBoundingClientRect:()=>k.getBoundingClientRect()};W.computePosition(D,t,i).then(v=>{Object.assign(t.style,{position:v.strategy,left:`${v.x}px`,top:`${v.y}px`})})}function E(k){o==null||o(k),Sd(k,n,c,{node:f,pos:p},a),C=vd(n.state.selection),t&&(t.dataset.dragging="true"),setTimeout(()=>{t&&(t.style.pointerEvents="none")},0)}function M(k){l==null||l(k),C=null,_(),t&&(t.style.pointerEvents="auto",t.dataset.dragging="false")}function Q({nodeCount:k,depth:D,anchorPos:v}){const K=kd(n.state.doc,v,k,D);K&&n.view.dispatch(n.state.tr.setSelection(K))}function nt(k){if(!(!k.target||!n.view.dom.contains(k.target))){if(O.isFirefox()){const D=n.view.dom;requestAnimationFrame(()=>{D.isContentEditable&&(D.contentEditable="false",D.contentEditable="true")})}!C||n.view.state.selection.empty||(S={...C,anchorPos:n.state.selection.from},b=requestAnimationFrame(()=>{b=null,S&&(Q(S),S=null)}))}}function ht(){t.removeEventListener("dragstart",E),t.removeEventListener("dragend",M),document.removeEventListener("drop",nt),x&&(cancelAnimationFrame(x),x=null,y=null),b&&(cancelAnimationFrame(b),b=null)}return u.appendChild(t),{unbind(){ht()},plugin:new G.Plugin({key:typeof e=="string"?new G.PluginKey(e):e,state:{init(){return{locked:!1}},apply(k,D,v,K){if(S&&k.docChanged){const Z=k.mapping.mapResult(S.anchorPos,1);Z.deleted?S=null:S.anchorPos=Z.pos}const V=k.getMeta("lockDragHandle"),q=k.getMeta("hideDragHandle");if(V!==void 0&&(h=V),q)return _(),h=!1,f=null,p=-1,r==null||r({editor:n,node:null,pos:-1}),D;if(k.docChanged&&p!==-1&&t)if(Ji(k)){const Z=Ed(K,g);Z!==p&&(p=Z)}else{const Z=k.mapping.map(p);Z!==p&&(p=Z,g=si(K,p))}return D}},view:k=>{var D;return t.draggable=!0,t.style.pointerEvents="auto",t.dataset.dragging="false",(D=n.view.dom.parentElement)==null||D.appendChild(u),u.style.pointerEvents="none",u.style.position="absolute",u.style.top="0",u.style.left="0",t.addEventListener("dragstart",E),t.addEventListener("dragend",M),document.addEventListener("drop",nt),{update(v,K){if(!t)return;if(!n.isEditable){_();return}if(h?t.draggable=!1:t.draggable=!0,k.state.doc.eq(K.doc)||p===-1)return;let V=k.nodeDOM(p);if(V=zs(k,V),V===k.dom||(V==null?void 0:V.nodeType)!==1)return;const q=k.posAtDOM(V,0),Z=Us(n.state.doc,q),Ut=Ps(n.state.doc,q);f=Z,p=Ut,g=si(k.state,p),r==null||r({editor:n,node:f,pos:p}),I(V)},destroy(){ht(),t&&To(u)}}},props:{handleDOMEvents:{keydown(k){return!t||h||k.hasFocus()&&(_(),f=null,p=-1,r==null||r({editor:n,node:null,pos:-1})),!1},mouseleave(k,D){return h||D.target&&!u.contains(D.relatedTarget)&&(_(),f=null,p=-1,r==null||r({editor:n,node:null,pos:-1})),!1},mousemove(k,D){return!t||h||(y={x:D.clientX,y:D.clientY},x)||(x=requestAnimationFrame(()=>{if(x=null,!y)return;const{x:v,y:K}=y;y=null;const V=ko({x:v,y:K,editor:n,nestedOptions:c});if(!V.resultElement)return;let q=V.resultElement,Z=V.resultNode,Ut=V.pos;if(!(c!=null&&c.enabled)){if(q=zs(k,q),q===k.dom||(q==null?void 0:q.nodeType)!==1)return;const me=k.posAtDOM(q,0);Z=Us(n.state.doc,me),Ut=Ps(n.state.doc,me)}Z!==f&&(f=Z,p=Ut??-1,g=si(k.state,p),r==null||r({editor:n,node:f,pos:p}),I(q),U())})),!1}}}})}};function Ao(e){var t,n;return e===!1||e===void 0?{enabled:!1,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:ii("none")}:e===!0?{enabled:!0,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:ii("left")}:{enabled:!0,rules:(t=e.rules)!=null?t:[],defaultRules:(n=e.defaultRules)!=null?n:!0,allowedContainers:e.allowedContainers,edgeDetection:ii(e.edgeDetection)}}var ki={placement:"left-start",strategy:"absolute"};O.Extension.create({name:"dragHandle",addOptions(){return{render(){const e=document.createElement("div");return e.classList.add("drag-handle"),e},computePositionConfig:{},locked:!1,onNodeChange:()=>null,onElementDragStart:void 0,onElementDragEnd:void 0,nested:!1,dragImageProperties:void 0}},addCommands(){return{lockDragHandle:()=>({editor:e})=>(this.options.locked=!0,e.commands.setMeta("lockDragHandle",this.options.locked)),unlockDragHandle:()=>({editor:e})=>(this.options.locked=!1,e.commands.setMeta("lockDragHandle",this.options.locked)),toggleDragHandle:()=>({editor:e})=>(this.options.locked=!this.options.locked,e.commands.setMeta("lockDragHandle",this.options.locked))}},addProseMirrorPlugins(){const e=this.options.render(),t=Ao(this.options.nested);return[Do({computePositionConfig:{...ki,...this.options.computePositionConfig},getReferencedVirtualElement:this.options.getReferencedVirtualElement,element:e,editor:this.editor,onNodeChange:this.options.onNodeChange,onElementDragStart:this.options.onElementDragStart,onElementDragEnd:this.options.onElementDragEnd,nestedOptions:t,dragImageProperties:this.options.dragImageProperties}).plugin]}});var Td=e=>{const{className:t="drag-handle",children:n,editor:i,pluginKey:s=_o,onNodeChange:r,onElementDragStart:o,onElementDragEnd:l,getReferencedVirtualElement:c,computePositionConfig:a=ki,nested:u=!1}=e,[h]=w.useState(()=>typeof document>"u"?null:document.createElement("div")),f=w.useMemo(()=>Ao(u),[JSON.stringify(u)]);return w.useEffect(()=>{h&&(h.className=t,h.style.visibility="hidden",h.style.position="absolute",h.dataset.dragging="false")},[t,h]),w.useEffect(()=>{if(!h||i.isDestroyed)return;const{plugin:p,unbind:g}=Do({editor:i,element:h,pluginKey:s,computePositionConfig:{...ki,...a},onElementDragStart:o,onElementDragEnd:l,onNodeChange:r,getReferencedVirtualElement:c,nestedOptions:f});return i.registerPlugin(p),()=>{i.isDestroyed||i.unregisterPlugin(s),g()}},[h,i,r,c,s,a,o,l,f]),h?Ei.createPortal(n,h):null},_d=Td;function Dd(){var I,E,M,Q,nt,ht,k,D;const e=m.useEditorInstance(),t=m.useEditableEditor(),{t:n}=P.useLocale(),[i,s]=w.useState(null),[r,o]=w.useState(-1),[l,c]=w.useState(!1),a=(E=(I=e==null?void 0:e.extensionManager)==null?void 0:I.extensions)==null?void 0:E.some(v=>(v==null?void 0:v.name)===Hs.TextAlign.name),u=(Q=(M=e==null?void 0:e.extensionManager)==null?void 0:M.extensions)==null?void 0:Q.some(v=>(v==null?void 0:v.name)===we.Indent.name),h=(ht=(nt=e==null?void 0:e.extensionManager)==null?void 0:nt.extensions)==null?void 0:ht.some(v=>(v==null?void 0:v.name)===$o.Clear.name);function f(){const v=e.chain();v.setNodeSelection(r).unsetAllMarks(),(i==null?void 0:i.type.name)!=="paragraph"&&v.setParagraph(),v.run()}function p(){e.chain().focus().setNodeSelection(r).run(),document.execCommand("copy")}function g(){e.commands.setNodeSelection(r);const{$anchor:v}=e.state.selection,K=v.node(1)||e.state.selection.node;e.chain().setMeta("hideDragHandle",!0).insertContentAt(r+((i==null?void 0:i.nodeSize)||0),K.toJSON()).run()}function x(v){e.commands.setTextAlign(v)}function b(){const v=we.setNodeIndentMarkup(e.state.tr,r,1);v.setMeta("hideDragHandle",!0),e.view.dispatch&&e.view.dispatch(v)}function y(){const v=we.setNodeIndentMarkup(e.state.tr,r,-1);e.view.dispatch&&e.view.dispatch(v)}function C(){e.chain().setMeta("hideDragHandle",!0).setNodeSelection(r).deleteSelection().run()}const S=w.useCallback(v=>{v.node&&s(v.node),o(v.pos),requestAnimationFrame(()=>{v.editor.commands.focus()})},[]),_=v=>{var K;if(v.preventDefault(),r!==-1){const V=(i==null?void 0:i.nodeSize)||0,q=r+V,Z=(i==null?void 0:i.type.name)==="paragraph"&&((K=i==null?void 0:i.content)==null?void 0:K.size)===0,Ut=Z?r+2:q+2;e.chain().command(({dispatch:me,tr:Pn,state:Xi})=>me?(Z?Pn.insertText("/",r,r+1):Pn.insert(q,Xi.schema.nodes.paragraph.create(null,[Xi.schema.text("/")])),me(Pn)):!0).focus(Ut).run()}};w.useEffect(()=>(l?e.commands.setMeta("lockDragHandle",!0):e.commands.setMeta("lockDragHandle",!1),()=>{e.commands.setMeta("lockDragHandle",!1)}),[l]);const U=v=>{t&&c(v)};return d.jsx(_d,{className:"richtext-transition-all richtext-duration-200 richtext-ease-out",editor:e,onNodeChange:S,pluginKey:"RichTextBubbleMenuDragHandle",children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-0.5",children:[d.jsx(m.ActionButton,{action:_,disabled:!t,icon:"Plus",tooltip:n("editor.draghandle.insertBlock")}),d.jsx(m.ActionButton,{disabled:!t,icon:"Grip",tooltip:n("editor.draghandle.grip"),action:v=>{v.preventDefault(),v.stopPropagation(),U(!l)}}),d.jsxs(z.DropdownMenu,{onOpenChange:U,open:l,children:[d.jsx(z.DropdownMenuTrigger,{className:"richtext-pointer-events-none"}),d.jsxs(z.DropdownMenuContent,{align:"start",className:"richtext-w-48",hideWhenDetached:!0,side:"bottom",sideOffset:0,children:[d.jsxs(z.DropdownMenuItem,{className:"richtext-flex richtext-gap-3 richtext-bg-opacity-10 hover:richtext-bg-red-400 hover:richtext-bg-opacity-20 focus:richtext-bg-red-400 focus:richtext-bg-opacity-30 focus:richtext-text-red-500 dark:hover:richtext-bg-opacity-20 dark:hover:richtext-text-red-500",onClick:C,children:[d.jsx(m.IconComponent,{name:"Trash2"}),d.jsx("span",{children:n("editor.remove")})]}),h?d.jsxs(z.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:f,children:[d.jsx(m.IconComponent,{name:"PaintRoller"}),d.jsx("span",{children:n("editor.clear.tooltip")})]}):null,d.jsxs(z.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:p,children:[d.jsx(m.IconComponent,{name:"Clipboard"}),d.jsx("span",{children:n("editor.copyToClipboard")})]}),d.jsxs(z.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:g,children:[d.jsx(m.IconComponent,{name:"Copy"}),d.jsx("span",{children:n("editor.copy")})]}),a||u?d.jsx(z.DropdownMenuSeparator,{}):null,a?d.jsxs(z.DropdownMenuSub,{children:[d.jsxs(z.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[d.jsx(m.IconComponent,{name:"AlignCenter"}),d.jsx("span",{children:n("editor.textalign.tooltip")})]}),d.jsx(z.DropdownMenuPortal,{children:d.jsxs(z.DropdownMenuSubContent,{children:[d.jsxs(z.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("left"),children:[d.jsx(m.IconComponent,{name:"AlignLeft"}),d.jsx("span",{children:n("editor.textalign.left.tooltip")})]}),d.jsxs(z.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("center"),children:[d.jsx(m.IconComponent,{name:"AlignCenter"}),d.jsx("span",{children:n("editor.textalign.center.tooltip")})]}),d.jsxs(z.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("right"),children:[d.jsx(m.IconComponent,{name:"AlignRight"}),d.jsx("span",{children:n("editor.textalign.right.tooltip")})]})]})})]}):null,u?d.jsxs(z.DropdownMenuSub,{children:[d.jsxs(z.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[d.jsx(m.IconComponent,{name:"IndentIncrease"}),d.jsx("span",{children:n("editor.indent")})]}),d.jsx(z.DropdownMenuPortal,{children:d.jsxs(z.DropdownMenuSubContent,{children:[d.jsxs(z.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((k=i==null?void 0:i.attrs)==null?void 0:k.indent)>=we.IndentProps.max,onClick:b,children:[d.jsx(m.IconComponent,{name:"IndentIncrease"}),d.jsx("span",{children:n("editor.indent.tooltip")})]}),d.jsxs(z.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((D=i==null?void 0:i.attrs)==null?void 0:D.indent)<=we.IndentProps.min,onClick:y,children:[d.jsx(m.IconComponent,{name:"IndentDecrease"}),d.jsx("span",{children:n("editor.outdent.tooltip")})]})]})})]}):null]})]})]})})}const $s={plaintext:"Plain Text",js:"JavaScript",ts:"TypeScript",css:"CSS",html:"HTML",python:"Python",bash:"Bash"};function Ad({listLanguages:e}){const{t}=P.useLocale(),[n,i]=w.useState(!1),s=m.useEditorInstance(),r=w.useMemo(()=>{const{selection:l}=s.state,c=l.$from.parent;if(c.type.name==="codeBlock"){const a=c.attrs.language||"plaintext";return $s[a]||a}},[s.state,e]),o=w.useMemo(()=>{let l=e||[];return e!=null&&e.includes("plaintext")||(l=["plaintext",...l]),l.map(c=>({label:$s[c]||c,value:c}))},[e]);return d.jsxs(At.Popover,{modal:!0,onOpenChange:i,open:n,children:[d.jsx(At.PopoverTrigger,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:d.jsxs(m.ActionButton,{dataState:!!r,children:[r?d.jsx(d.Fragment,{children:r}):d.jsx(d.Fragment,{children:t("editor.paragraph.tooltip")}),d.jsx(m.IconComponent,{className:"richtext-ml-1 richtext-size-3 richtext-text-zinc-500",name:"MenuDown"})]})}),d.jsx(At.PopoverContent,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:o==null?void 0:o.map(l=>d.jsxs("div",{className:"richtext-flex richtext-w-full richtext-items-center richtext-gap-3 richtext-rounded-sm !richtext-border-none !richtext-bg-transparent richtext-px-2 richtext-py-1.5 richtext-text-left richtext-text-sm richtext-text-foreground !richtext-outline-none richtext-transition-colors hover:!richtext-bg-accent",onClick:c=>{c.preventDefault(),s.chain().focus().setCodeBlock({language:l.value}).run(),i(!1)},children:[d.jsx("div",{className:"!richtext-min-w-[20px]",children:r===l.value&&d.jsx(Ht.Check,{size:16})}),d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:l.label})]},l.value))})]})}function Id(){const e=m.useEditableEditor(),t=m.useEditorInstance(),n=m.useExtension(zn.CodeBlock.name),i=w.useCallback(({editor:c})=>c.isActive(zn.CodeBlock.name),[]),s=w.useMemo(()=>{var c,a,u;return n?((u=(a=(c=n.options)==null?void 0:c.lowlight)==null?void 0:a.listLanguages)==null?void 0:u.call(a))||["plaintext","html","css","js","ts"]:[]},[n]),r=w.useCallback(()=>Yt(zn.CodeBlock.name,t),[t]),o=()=>{const{from:c}=t.state.selection,a=t.state.doc.resolve(c);for(let u=a.depth;u>=0;u--){const h=a.node(u);if(h.type.name==="codeBlock")return h.textContent}return""},l=()=>{const c=o();navigator.clipboard.writeText(c)};return e?d.jsx(ot,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleCodeBlock",shouldShow:i,getReferencedVirtualElement:()=>{const{from:c}=t.state.selection,u=t.view.domAtPos(c).node.parentElement;return u?{getBoundingClientRect:()=>u.getBoundingClientRect()}:null},children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(Ad,{listLanguages:s}),d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(m.ActionButton,{action:l,tooltip:"Copy",children:d.jsx(Ht.Copy,{size:16})}),d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(m.ActionButton,{action:r,tooltip:"Delete",children:d.jsx(Ht.Trash2,{size:16})})]})}):d.jsx(d.Fragment,{})}exports.RichTextBubbleCallout=wl;exports.RichTextBubbleCodeBlock=Id;exports.RichTextBubbleColumns=bl;exports.RichTextBubbleDrawer=Nl;exports.RichTextBubbleExcalidraw=Ll;exports.RichTextBubbleIframe=Pl;exports.RichTextBubbleImage=ql;exports.RichTextBubbleImageGif=Wl;exports.RichTextBubbleKatex=zl;exports.RichTextBubbleLink=Vl;exports.RichTextBubbleMenuDragHandle=Dd;exports.RichTextBubbleMermaid=Zl;exports.RichTextBubbleTable=Ql;exports.RichTextBubbleText=nc;exports.RichTextBubbleTwitter=ic;exports.RichTextBubbleVideo=Gl;