reactjs-tiptap-editor 1.0.12 → 1.0.13

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 (180) hide show
  1. package/lib/{ActionMenuButton-CPPHERbq.cjs → ActionMenuButton-DNj0f_A4.cjs} +1 -1
  2. package/lib/{ActionMenuButton-BKqin6Kz.js → ActionMenuButton-l5rSmAO_.js} +11 -11
  3. package/lib/Attachment.cjs +1 -1
  4. package/lib/Attachment.js +6 -6
  5. package/lib/Blockquote.cjs +1 -1
  6. package/lib/Blockquote.js +4 -4
  7. package/lib/Bold.cjs +1 -1
  8. package/lib/Bold.js +4 -4
  9. package/lib/BulletList.cjs +1 -1
  10. package/lib/BulletList.js +4 -4
  11. package/lib/Callout.cjs +1 -0
  12. package/lib/Callout.js +230 -0
  13. package/lib/Clear.cjs +1 -1
  14. package/lib/Clear.js +3 -3
  15. package/lib/Code.cjs +1 -1
  16. package/lib/Code.js +4 -4
  17. package/lib/CodeBlock.cjs +20 -20
  18. package/lib/CodeBlock.js +90 -89
  19. package/lib/CodeView.cjs +1 -1
  20. package/lib/CodeView.js +4 -4
  21. package/lib/Color.cjs +1 -1
  22. package/lib/Color.js +6 -6
  23. package/lib/Column.cjs +1 -1
  24. package/lib/Column.js +4 -4
  25. package/lib/{Drawer-DUPsBE0H.js → Drawer-Cbi_MURj.js} +16 -16
  26. package/lib/{Drawer-fplzqNI6.cjs → Drawer-DKU32YW_.cjs} +1 -1
  27. package/lib/Drawer.cjs +1 -1
  28. package/lib/Drawer.js +3 -3
  29. package/lib/Emoji.cjs +1 -1
  30. package/lib/Emoji.js +16 -16
  31. package/lib/{Excalidraw-BEzpvRLx.js → Excalidraw-CWrVL5hs.js} +30 -30
  32. package/lib/{Excalidraw-qjnQspLq.cjs → Excalidraw-Kb-TRcWY.cjs} +1 -1
  33. package/lib/Excalidraw.cjs +1 -1
  34. package/lib/Excalidraw.js +2 -2
  35. package/lib/ExportPdf.cjs +1 -1
  36. package/lib/ExportPdf.js +4 -4
  37. package/lib/ExportWord.cjs +1 -1
  38. package/lib/ExportWord.js +4 -4
  39. package/lib/FontFamily.cjs +1 -1
  40. package/lib/FontFamily.js +6 -6
  41. package/lib/FontSize.cjs +1 -1
  42. package/lib/FontSize.js +6 -6
  43. package/lib/Heading.cjs +1 -1
  44. package/lib/Heading.js +14 -14
  45. package/lib/Highlight.cjs +1 -1
  46. package/lib/Highlight.js +6 -6
  47. package/lib/History.cjs +1 -1
  48. package/lib/History.js +13 -13
  49. package/lib/HorizontalRule.cjs +1 -1
  50. package/lib/HorizontalRule.js +4 -4
  51. package/lib/{Icon-ONE1AwKo.js → Icon-Ctva8VeB.js} +2 -2
  52. package/lib/{Icon-CiR8RqdQ.cjs → Icon-yqCglrdK.cjs} +1 -1
  53. package/lib/{Iframe-DsUNJ2n2.cjs → Iframe-BczF8Hex.cjs} +1 -1
  54. package/lib/{Iframe-CBTnv2mk.js → Iframe-C942bNjs.js} +12 -12
  55. package/lib/Iframe.cjs +1 -1
  56. package/lib/Iframe.js +2 -2
  57. package/lib/Image.cjs +1 -1
  58. package/lib/Image.js +48 -48
  59. package/lib/ImageGif.cjs +1 -1
  60. package/lib/ImageGif.js +15 -15
  61. package/lib/ImportWord.cjs +2 -2
  62. package/lib/ImportWord.js +9 -9
  63. package/lib/{Indent-B00o0P0M.js → Indent-C_O5WdyR.js} +4 -4
  64. package/lib/{Indent-CaGP0qTp.cjs → Indent-CkEC7x36.cjs} +1 -1
  65. package/lib/Indent.cjs +1 -1
  66. package/lib/Indent.js +2 -2
  67. package/lib/Italic.cjs +1 -1
  68. package/lib/Italic.js +4 -4
  69. package/lib/{Katex-x370CSXZ.js → Katex-D3PEWimM.js} +24 -24
  70. package/lib/{Katex-XsfpKgJU.cjs → Katex-DW_HjgNM.cjs} +2 -2
  71. package/lib/Katex.cjs +1 -1
  72. package/lib/Katex.js +2 -2
  73. package/lib/LineHeight.cjs +1 -1
  74. package/lib/LineHeight.js +14 -14
  75. package/lib/Link.cjs +1 -1
  76. package/lib/Link.js +2 -2
  77. package/lib/{LinkEditBlock-xt88G5fb.cjs → LinkEditBlock-DL1e2ILk.cjs} +2 -2
  78. package/lib/{LinkEditBlock-C_ipl3EA.js → LinkEditBlock-h5054QDo.js} +31 -31
  79. package/lib/Mention.js +3 -3
  80. package/lib/Mermaid.cjs +2 -2
  81. package/lib/Mermaid.js +28 -29
  82. package/lib/MoreMark.cjs +1 -1
  83. package/lib/MoreMark.js +14 -14
  84. package/lib/OrderedList.cjs +1 -1
  85. package/lib/OrderedList.js +4 -4
  86. package/lib/SearchAndReplace.cjs +1 -1
  87. package/lib/SearchAndReplace.js +17 -17
  88. package/lib/SlashCommand.cjs +1 -1
  89. package/lib/SlashCommand.js +6 -6
  90. package/lib/{SlashCommandNodeView-BT5ystah.cjs → SlashCommandNodeView-BqrmHCpu.cjs} +1 -1
  91. package/lib/{SlashCommandNodeView-DX6axvLs.js → SlashCommandNodeView-DXUqkx82.js} +12 -12
  92. package/lib/Strike.cjs +1 -1
  93. package/lib/Strike.js +4 -4
  94. package/lib/{Table-DidusYID.js → Table-DdrY4jcM.js} +7 -7
  95. package/lib/{Table-DSRSwtXx.cjs → Table-kY0nbqJo.cjs} +1 -1
  96. package/lib/Table.cjs +1 -1
  97. package/lib/Table.js +1 -1
  98. package/lib/TaskList.cjs +1 -1
  99. package/lib/TaskList.js +4 -4
  100. package/lib/TextAlign.cjs +1 -1
  101. package/lib/TextAlign.js +16 -16
  102. package/lib/TextDirection.cjs +1 -1
  103. package/lib/TextDirection.js +16 -16
  104. package/lib/TextUnderline.cjs +1 -1
  105. package/lib/TextUnderline.js +4 -4
  106. package/lib/{Twitter-D58T0Zt3.js → Twitter-B-JQ3ZJ1.js} +18 -18
  107. package/lib/{Twitter-CBuVBQM1.cjs → Twitter-DjZcVa3l.cjs} +1 -1
  108. package/lib/Twitter.cjs +1 -1
  109. package/lib/Twitter.js +2 -2
  110. package/lib/Video.cjs +1 -1
  111. package/lib/Video.js +24 -24
  112. package/lib/bubble.cjs +4 -4
  113. package/lib/bubble.js +2083 -1950
  114. package/lib/button-BS3n6_Aq.cjs +1 -0
  115. package/lib/{button-9_8t7ca7.js → button-Uv01FNnd.js} +7 -7
  116. package/lib/{checkbox-BQRKTXXr.cjs → checkbox-C8ByRi7-.cjs} +1 -1
  117. package/lib/{checkbox-DnkkV6qo.js → checkbox-DEFNwGwb.js} +1 -1
  118. package/lib/{clsx-DmuN0U_8.js → clsx-BWSGDJNJ.js} +13 -13
  119. package/lib/components/Bubble/RichTextBubbleCallout.d.ts +1 -0
  120. package/lib/components/Bubble/index.d.ts +1 -0
  121. package/lib/components/ui/index.d.ts +1 -0
  122. package/lib/{dialog-BS3zm-T9.cjs → dialog-Bt5zwGYB.cjs} +1 -1
  123. package/lib/{dialog-DhayAPvV.js → dialog-DwTMZSt6.js} +1 -1
  124. package/lib/{dropdown-menu-DQqKeZcx.js → dropdown-menu-BetI14G6.js} +1 -1
  125. package/lib/{dropdown-menu-CxwWX0yj.cjs → dropdown-menu-Bo68IEOT.cjs} +1 -1
  126. package/lib/extensions/Callout/Callout.d.ts +18 -0
  127. package/lib/extensions/Callout/components/NodeViewCallout/NodeViewCallout.d.ts +1 -0
  128. package/lib/extensions/Callout/components/RichTextCallout.d.ts +1 -0
  129. package/lib/extensions/Callout/index.d.ts +1 -0
  130. package/lib/{index-D1jd7elj.js → index-BDKHXe7R.js} +1 -1
  131. package/lib/{index-CKmT9KAQ.js → index-CHKWG6E8.js} +1 -1
  132. package/lib/{index-EAK64CCA.js → index-CcoWj0mF.js} +131 -130
  133. package/lib/index-D3RLYf-J.cjs +1 -0
  134. package/lib/{index-D9JOHlso.js → index-DF5ZPtWM.js} +369 -482
  135. package/lib/{index-DdEmgiAA.js → index-DJbmnBzK.js} +1 -1
  136. package/lib/index-Doks9cbR.cjs +1 -0
  137. package/lib/{index-BDX1uE62.js → index-Dujzr6bY.js} +135 -39
  138. package/lib/{index-CBFmXCcU.cjs → index-VhKd73hZ.cjs} +1 -1
  139. package/lib/{index-DvvwJvau.js → index-mR8PNv5P.js} +23 -23
  140. package/lib/index.cjs +1 -1
  141. package/lib/index.js +3 -3
  142. package/lib/{input-YoheBL2D.js → input-DUBdJD3L.js} +5 -5
  143. package/lib/{input-BJ7ihMq-.cjs → input-Dt_BA_9B.cjs} +1 -1
  144. package/lib/{isNumber-DmQXlKp3.js → isNumber-CIgubz2e.js} +1 -1
  145. package/lib/{label-Y7_hvqf2.cjs → label-JNOksCA-.cjs} +1 -1
  146. package/lib/{label-C8PLcjFI.js → label-topD46-u.js} +2 -2
  147. package/lib/locale-bundle.cjs +1 -1
  148. package/lib/locale-bundle.js +1 -1
  149. package/lib/locales/en.d.ts +16 -0
  150. package/lib/locales/fi.d.ts +16 -0
  151. package/lib/locales/hu.d.ts +16 -0
  152. package/lib/locales/index.d.ts +96 -0
  153. package/lib/locales/pt-br.d.ts +16 -0
  154. package/lib/locales/vi.d.ts +16 -0
  155. package/lib/locales/zh-cn.d.ts +16 -0
  156. package/lib/{popover-CWmTzHSy.js → popover-LfNBhRyz.js} +1 -1
  157. package/lib/{popover-BiSrlM4j.cjs → popover-mL-2sX5r.cjs} +1 -1
  158. package/lib/select-CwGYPsPq.cjs +1 -0
  159. package/lib/select-DctYuHLH.js +117 -0
  160. package/lib/{separator-C-DKMYmg.js → separator-Ddfrhn4D.js} +18 -18
  161. package/lib/{separator-CJ_adziN.cjs → separator-NoH_SLRW.cjs} +1 -1
  162. package/lib/{store-BKMaw1AW.cjs → store-CkjKIgjQ.cjs} +1 -1
  163. package/lib/{store-DG7cMfET.js → store-DNpS8vXA.js} +1 -1
  164. package/lib/style.css +1 -1
  165. package/lib/{tabs-DxlKKM-N.js → tabs-BT3AeqQQ.js} +1 -1
  166. package/lib/{tabs-DpHSMyF_.cjs → tabs-DRSwUeKP.cjs} +1 -1
  167. package/lib/{textarea-DU9RMi6u.cjs → textarea-BDO6XQoF.cjs} +1 -1
  168. package/lib/{textarea-D7m-apUh.js → textarea-DZzMEDfZ.js} +1 -1
  169. package/lib/{throttle-BRtichEP.js → throttle-IERhwcLa.js} +1 -1
  170. package/lib/{toggle-BYvLnjCL.cjs → toggle-BQHMh_Q-.cjs} +1 -1
  171. package/lib/{toggle-Bxwwb_Kp.js → toggle-DKHg5sLm.js} +10 -10
  172. package/lib/{tooltip-COvf4_R-.cjs → tooltip-BYtGp6FM.cjs} +1 -1
  173. package/lib/{tooltip-BTy5CRrN.js → tooltip-DNKq7zgN.js} +1 -1
  174. package/lib/{updatePosition-CUukgu-Q.js → updatePosition-Bie75EFq.js} +2 -2
  175. package/lib/{useButtonProps-CydzndG1.cjs → useButtonProps-DBJkNDS2.cjs} +1 -1
  176. package/lib/{useButtonProps-CfYtuEnd.js → useButtonProps-DVP4s_ER.js} +3 -3
  177. package/package.json +1 -1
  178. package/lib/button-Cs9TroWr.cjs +0 -1
  179. package/lib/index-CVFzP1Dc.cjs +0 -1
  180. package/lib/index-CX4pNJlH.cjs +0 -1
package/lib/bubble.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var po=Object.create;var pi=Object.defineProperty;var mo=Object.getOwnPropertyDescriptor;var xo=Object.getOwnPropertyNames;var wo=Object.getPrototypeOf,bo=Object.prototype.hasOwnProperty;var yo=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of xo(t))!bo.call(e,s)&&s!==n&&pi(e,s,{get:()=>t[s],enumerable:!(i=mo(t,s))||i.enumerable});return e};var So=(e,t,n)=>(n=e!=null?po(wo(e)):{},yo(t||!e||!e.__esModule?pi(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-runtime"),w=require("react"),E=require("./clsx-CXbNJWDD.cjs"),H=require("./index-Cs6cp0Y6.cjs"),J=require("@tiptap/pm/state"),Xi=require("./Table-DSRSwtXx.cjs"),Zi=require("react-dom"),y=require("./toggle-BYvLnjCL.cjs"),mi=require("./Column.cjs"),V=require("./index-CVFzP1Dc.cjs"),K=require("./useButtonProps-CydzndG1.cjs"),tt=require("./index-CX4pNJlH.cjs"),Se=require("./delete-node-CosiBes5.cjs");require("./theme.cjs");const It=require("./separator-CJ_adziN.cjs"),Re=require("./Drawer-fplzqNI6.cjs"),xi=require("easydrawer"),He=require("./shortId-Bfj8TyNr.cjs"),Xt=require("./button-Cs9TroWr.cjs"),L=require("./dialog-BS3zm-T9.cjs"),Qi=require("./file-i7e4nQY2.cjs"),pt=require("./Katex-XsfpKgJU.cjs"),je=require("./input-BJ7ihMq-.cjs"),ce=require("./label-Y7_hvqf2.cjs"),Kt=require("./popover-BiSrlM4j.cjs"),zt=require("./Excalidraw-qjnQspLq.cjs"),qt=require("./Iframe-DsUNJ2n2.cjs"),ko=require("katex"),$e=require("lucide-react"),In=require("./textarea-DU9RMi6u.cjs"),Ne=require("./LinkEditBlock-xt88G5fb.cjs"),Co=require("./Image.cjs"),vo=require("./ImageGif.cjs"),_o=require("./Video.cjs"),An=require("./Mermaid.cjs"),Eo=require("./Bold.cjs"),Io=require("./Code.cjs");require("./index-CjhjjJsN.cjs");const Ao=require("./Color.cjs"),To=require("./Highlight.cjs"),Do=require("./Italic.cjs"),Mo=require("./SlashCommandNodeView-BT5ystah.cjs"),Oo=require("./Strike.cjs"),ts=require("./TextAlign.cjs"),Ro=require("./TextUnderline.cjs"),et=require("./Icon-CiR8RqdQ.cjs"),gn=require("./Twitter-CBuVBQM1.cjs"),pn=require("@tiptap/pm/view"),jo=require("@tiptap/pm/model"),U=require("./dropdown-menu-CxwWX0yj.cjs"),No=require("./Clear.cjs"),oe=require("./Indent-CaGP0qTp.cjs");function Bo(e,t){const n=Math.min(e.top,t.top),i=Math.max(e.bottom,t.bottom),s=Math.min(e.left,t.left),r=Math.max(e.right,t.right)-s,l=i-n,c=s,a=n;return new DOMRect(c,a,r,l)}var Uo=class{constructor({editor:e,element:t,view:n,updateDelay:i=250,resizeDelay:s=60,shouldShow:o,appendTo:r,getReferencedVirtualElement:l,options:c}){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:d,from:f,to:g})=>{const{doc:p,selection:m}=d,{empty:x}=m,b=!p.textBetween(f,g).length&&E.isTextSelection(d.selection),D=this.element.contains(document.activeElement);return!(!(h.hasFocus()||D)||x||b||!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 d;if(this.editor.isDestroyed){this.destroy();return}if(this.preventHide){this.preventHide=!1;return}h!=null&&h.relatedTarget&&((d=this.element.parentNode)!=null&&d.contains(h.relatedTarget))||(h==null?void 0:h.relatedTarget)!==this.editor.view.dom&&this.hide()},this.handleDebouncedUpdate=(h,d)=>{const f=!(d!=null&&d.selection.eq(h.state.selection)),g=!(d!=null&&d.doc.eq(h.state.doc));!f&&!g||(this.updateDebounceTimer&&clearTimeout(this.updateDebounceTimer),this.updateDebounceTimer=window.setTimeout(()=>{this.updateHandler(h,f,g,d)},this.updateDelay))},this.updateHandler=(h,d,f,g)=>{const{composing:p}=h;if(p||!d&&!f)return;if(!this.getShouldShow(g)){this.hide();return}this.updatePosition(),this.show()},this.transactionHandler=({transaction:h})=>{h.getMeta("bubbleMenu")==="updatePosition"&&this.updatePosition()};var a;this.editor=e,this.element=t,this.view=n,this.updateDelay=i,this.resizeDelay=s,this.appendTo=r,this.scrollTarget=(a=c==null?void 0:c.scrollTarget)!=null?a:window,this.getReferencedVirtualElement=l,this.floatingUIOptions={...this.floatingUIOptions,...c},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(H.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(H.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(H.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(H.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(H.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(H.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(H.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(H.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}get virtualElement(){var e;const{selection:t}=this.editor.state,n=(e=this.getReferencedVirtualElement)==null?void 0:e.call(this);if(n)return n;const i=E.posToDOMRect(this.view,t.from,t.to);let s={getBoundingClientRect:()=>i,getClientRects:()=>[i]};if(t instanceof J.NodeSelection){let o=this.view.nodeDOM(t.from);const r=o.dataset.nodeViewWrapper?o:o.querySelector("[data-node-view-wrapper]");r&&(o=r),o&&(s={getBoundingClientRect:()=>o.getBoundingClientRect(),getClientRects:()=>[o.getBoundingClientRect()]})}if(t instanceof Xi.CellSelection){const{$anchorCell:o,$headCell:r}=t,l=o?o.pos:r.pos,c=r?r.pos:o.pos,a=this.view.nodeDOM(l),h=this.view.nodeDOM(c);if(!a||!h)return;const d=a===h?a.getBoundingClientRect():Bo(a.getBoundingClientRect(),h.getBoundingClientRect());s={getBoundingClientRect:()=>d,getClientRects:()=>[d]}}return s}updatePosition(){const e=this.virtualElement;e&&H.computePosition(e,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:t,y:n,strategy:i})=>{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)),o=!(t!=null&&t.doc.eq(e.state.doc));this.updateHandler(e,s,o,t)}getShouldShow(e){var t;const{state:n}=this.view,{selection:i}=n,{ranges:s}=i,o=Math.min(...s.map(c=>c.$from.pos)),r=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:o,to:r}))||!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)}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()}},es=e=>new J.Plugin({key:typeof e.pluginKey=="string"?new J.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Uo({view:t,...e})});E.Extension.create({name:"bubbleMenu",addOptions(){return{element:null,pluginKey:"bubbleMenu",updateDelay:void 0,appendTo:void 0,shouldShow:null}},addProseMirrorPlugins(){return this.options.element?[es({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 Lo=class{constructor({editor:e,element:t,view:n,options:i,appendTo:s,shouldShow:o}){this.preventHide=!1,this.isVisible=!1,this.shouldShow=({view:r,state:l})=>{const{selection:c}=l,{$anchor:a,empty:h}=c,d=a.depth===1,f=a.parent.isTextblock&&!a.parent.type.spec.code&&!a.parent.textContent&&a.parent.childCount===0&&!this.getTextContent(a.parent);return!(!r.hasFocus()||!h||!d||!f||!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=(r,l,c,a)=>{const{composing:h}=r;if(h||!l&&!c)return;if(!this.getShouldShow(a)){this.hide();return}this.updatePosition(),this.show()},this.mousedownHandler=()=>{this.preventHide=!0},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:r})=>{var l;if(this.preventHide){this.preventHide=!1;return}r!=null&&r.relatedTarget&&((l=this.element.parentNode)!=null&&l.contains(r.relatedTarget))||(r==null?void 0:r.relatedTarget)!==this.editor.view.dom&&this.hide()},this.editor=e,this.element=t,this.view=n,this.appendTo=s,this.floatingUIOptions={...this.floatingUIOptions,...i},this.element.tabIndex=0,o&&(this.shouldShow=o),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.update(n,n.state),this.getShouldShow()&&(this.show(),this.updatePosition())}getTextContent(e){return E.getText(e,{textSerializers:E.getTextSerializersFromSchema(this.editor.schema)})}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(H.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(H.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(H.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(H.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(H.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(H.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(H.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(H.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,o=Math.min(...s.map(c=>c.$from.pos)),r=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:o,to:r})}updatePosition(){const{selection:e}=this.editor.state,t=E.posToDOMRect(this.view,e.from,e.to),n={getBoundingClientRect:()=>t,getClientRects:()=>[t]};H.computePosition(n,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:i,y:s,strategy:o})=>{this.element.style.width="max-content",this.element.style.position=o,this.element.style.left=`${i}px`,this.element.style.top=`${s}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}),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},ns=e=>new J.Plugin({key:typeof e.pluginKey=="string"?new J.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Lo({view:t,...e})});E.Extension.create({name:"floatingMenu",addOptions(){return{element:null,options:{},pluginKey:"floatingMenu",appendTo:void 0,shouldShow:null}},addProseMirrorPlugins(){return this.options.element?[ns({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,options:this.options.options,appendTo:this.options.appendTo,shouldShow:this.options.shouldShow})]:[]}});var it=w.forwardRef(({pluginKey:e="bubbleMenu",editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:o=null,getReferencedVirtualElement:r,options:l,children:c,...a},h)=>{const d=w.useRef(document.createElement("div"));typeof h=="function"?h(d.current):h&&(h.current=d.current);const{editor:f}=E.useCurrentEditor(),g=t||f,p={updateDelay:n,resizeDelay:i,appendTo:s,pluginKey:e,shouldShow:o,getReferencedVirtualElement:r,options:l},m=w.useRef(p);return m.current=p,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 x=d.current;x.style.visibility="hidden",x.style.position="absolute";const b=es({...m.current,editor:g,element:x});g.registerPlugin(b);const D=m.current.pluginKey;return()=>{g.unregisterPlugin(D),window.requestAnimationFrame(()=>{x.parentNode&&x.parentNode.removeChild(x)})}},[g]),Zi.createPortal(u.jsx("div",{...a,children:c}),d.current)});w.forwardRef(({pluginKey:e="floatingMenu",editor:t,appendTo:n,shouldShow:i=null,options:s,children:o,...r},l)=>{const c=w.useRef(document.createElement("div"));typeof l=="function"?l(c.current):l&&(l.current=c.current);const{editor:a}=E.useCurrentEditor();return w.useEffect(()=>{const h=c.current;if(h.style.visibility="hidden",h.style.position="absolute",t!=null&&t.isDestroyed||a!=null&&a.isDestroyed)return;const d=t||a;if(!d){console.warn("FloatingMenu component is not rendered inside of an editor component or does not have editor prop.");return}const f=ns({editor:d,element:h,pluginKey:e,appendTo:n,shouldShow:i,options:s});return d.registerPlugin(f),()=>{d.unregisterPlugin(e),window.requestAnimationFrame(()=>{h.parentNode&&h.parentNode.removeChild(h)})}},[t,a,n,e,i,s]),Zi.createPortal(u.jsx("div",{...r,children:o}),c.current)});function Po(){const e=tt.useEditableEditor(),t=K.useEditorInstance(),{t:n}=V.useLocale(),i=w.useCallback(()=>t.isActive(mi.MultipleColumnNode.name),[t]),s=w.useCallback(()=>Se.deleteNode(mi.MultipleColumnNode.name,t),[t]),o=w.useCallback(()=>t.chain().focus().addColBefore().run(),[t]),r=w.useCallback(()=>t.chain().focus().addColAfter().run(),[t]),l=w.useCallback(()=>t.chain().focus().deleteCol().run(),[t]);return e?u.jsx(it,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleColumns",shouldShow:i,children:u.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:[u.jsx(y.ActionButton,{action:o,icon:"ColumnAddLeft",tooltip:n("editor.table.menu.insertColumnBefore")}),u.jsx(y.ActionButton,{action:r,icon:"ColumnAddRight",tooltip:n("editor.table.menu.insertColumnAfter")}),u.jsx(y.ActionButton,{action:l,icon:"DeleteColumn",tooltip:n("editor.table.menu.deleteColumn")}),u.jsx(y.ActionButton,{action:s,icon:"Trash2",tooltip:n("editor.table.menu.delete_column")})]})}):u.jsx(u.Fragment,{})}function Vo(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,o)=>({type:`image-${s}`,component:y.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[o],action:()=>e.commands.updateImage({width:V.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:V.IMAGE_SIZE[s]})}}))}function Fo(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,o)=>({type:`image-${s}`,component:y.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[o],action:()=>e.commands.updateImageGif({width:V.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:V.IMAGE_SIZE[s]})}}))}function Ho(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:y.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImage)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function $o(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:y.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImageGif)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function zo(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:y.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImageMermaid)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function qo(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:y.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImageDrawer)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function Ko(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:y.ActionButton,componentProps:{tooltip:n.tooltip,icon:n.icon,action:()=>e.commands.updateVideo({align:n.type}),isActive:()=>e.getAttributes("video").align===n.type}}))}function Wo(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,o)=>({type:`video-${s}`,component:y.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[o],action:()=>e.commands.updateVideo({width:V.VIDEO_SIZE[s]}),isActive:()=>e.isActive("video",{width:V.VIDEO_SIZE[s]})}}))}function Yo(e,t){return[{type:"flipX",component:y.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:y.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()}}},...Vo(e,t),...Ho(e,t),{type:"remove",component:y.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}function Go(e,t){return[...Fo(e,t),...$o(e,t),{type:"remove",component:y.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}function Jo(e,t){return[...zo(e,t),{type:"edit",component:y.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:y.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}function Xo(e,t){return[...qo(e,t),{type:"edit",component:y.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:y.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}function Zo(e,t){return[...Wo(e,t),...Ko(e),{type:"remove",component:y.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}let re=!1;function Qo({editor:e,attrs:t,extension:n}){const[i,s]=w.useState(!1),o=w.useRef(null),r=w.useRef(null),{alt:l,align:c}=t,a=n==null?void 0:n.options.upload,h=()=>{(async()=>{const S=document.querySelector("#easydrawer");S&&(o.current=new xi.Editor(S,{wheelEventsEnabled:!1,disableZoom:!0}),r.current=xi.makeDropdownToolbar(o.current),r.current.addDefaultToolWidgets(),o.current.loadFromSVG(decodeURIComponent(l)))})()};w.useEffect(()=>{i&&setTimeout(()=>{h()},200)},[i]);const d=async()=>{if(o.current){const I=o.current.toSVG(),S=I.outerHTML,k=`drawer-${He.shortId()}.svg`;let j=He.i(I.outerHTML);if(a){const $=Qi.dataURLtoFile(j,k);j=await a($)}e==null||e.chain().focus().setDrawer({type:"drawer",src:j,alt:encodeURIComponent(S),width:426,height:212},!!S).run(),e==null||e.commands.setAlignImageDrawer(c)}s(!1)},f=I=>{const S=o.current.toolController.getPrimaryTools()[2],k=r.current.getWidgetById("pen-1");S&&k&&(S.setColor(I),k.serializeState())},g=I=>{const S=o.current.toolController.getPrimaryTools()[2],k=r.current.getWidgetById("pen-1");S&&k&&(S.setThickness(I),k.serializeState())},p=I=>{const S=o.current.toolController.getPrimaryTools()[3],k=r.current.getWidgetById("pen-2");S&&k&&(S.setColor(I),k.serializeState())},m=I=>{const S=r.current.getWidgetById("shape");S&&S.setShapeType(I)},x=I=>{const S=o.current.toolController.getPrimaryTools()[5],k=r.current.getWidgetById("shape");S&&k&&(S.setColor(I),k.serializeState())},b=I=>{const S=o.current.toolController.getPrimaryTools()[5],k=r.current.getWidgetById("shape");S&&k&&(S.setThickness(I),k.serializeState())},D=I=>{const S=o.current.toolController.getPrimaryTools()[5],k=r.current.getWidgetById("shape");S&&k&&(S.setBorderColor(I),k.serializeState())},M=()=>{if(re){for(;o.current.history.redoStackSize>0;)o.current.history.redo();re=!1;return}o.current.history.undo()},C=()=>{re||o.current.history.redo()},B=()=>{if(!re){for(;o.current.history.undoStackSize>0;)M();re=!0}};return u.jsxs(L.Dialog,{onOpenChange:s,open:i,children:[u.jsx(L.DialogTrigger,{asChild:!0,children:u.jsx(y.ActionButton,{action:()=>s(!0),icon:"Pencil",tooltip:"Edit Drawer"})}),u.jsxs(L.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[u.jsx(L.DialogTitle,{children:"Edit Drawer"}),u.jsxs("div",{style:{height:"100%",borderWidth:1,background:"white",position:"relative"},children:[u.jsx("div",{className:"richtext-size-full",id:"easydrawer"}),u.jsx(Re.ControlDrawer,{changeBorderColorShape:D,changeColorShape:x,changeShape:m,onClear:B,onRedo:C,onThicknessChange:b,onUndo:M,refEditor:o,setColorHighlight:p,setColorPen:f,setThicknessPen:g})]}),u.jsx(L.DialogFooter,{children:u.jsx(Xt.Button,{onClick:d,type:"button",children:"Save changes"})})]})]})}function tr({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?u.jsx(w.Fragment,{children:e.type==="divider"?u.jsx(It.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):u.jsx(i,{...e.componentProps,disabled:t||((s=e==null?void 0:e.componentProps)==null?void 0:s.disabled),editor:n})}):u.jsx(u.Fragment,{})}function er(){const{lang:e,t}=V.useLocale(),n=tt.useEditableEditor(),i=K.useEditorInstance(),s=pt.useAttributes(i,Re.Drawer.name),o=K.useExtension(Re.Drawer.name),r=({editor:c})=>{const{selection:a}=c.view.state,{$from:h,to:d}=a;let f=!1;return c.view.state.doc.nodesBetween(h.pos,d,g=>{if(g.type.name===Re.Drawer.name)return f=!0,!1}),f},l=w.useMemo(()=>Xo(i,t),[i,e,t]);return n?u.jsx(it,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleDrawer",shouldShow:r,children:l!=null&&l.length?u.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)?u.jsx(Qo,{attrs:s,editor:i,extension:o},`bubbleMenu-drawer-${a}`):u.jsx(tr,{editor:i,item:c},`bubbleMenu-drawer-${a}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}const is=({width:e,maxWidth:t,height:n,onOk:i,children:s})=>{const{t:o}=V.useLocale(),[r,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(r)}return u.jsxs(Kt.Popover,{modal:!0,children:[u.jsx(Kt.PopoverTrigger,{asChild:!0,children:s}),u.jsx(Kt.PopoverContent,{children:u.jsxs("form",{className:"richtext-flex richtext-flex-col richtext-gap-2",onSubmit:c,children:[u.jsx(ce.Label,{className:"mb-[6px]",children:"Width"}),u.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:u.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:u.jsx(je.Input,{onChange:a=>l({...r,width:a.target.value}),required:!0,type:"number",value:r.width})})}),u.jsx(ce.Label,{className:"mb-[6px]",children:"Max Width"}),u.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:u.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:u.jsx(je.Input,{onChange:a=>l({...r,maxWidth:a.target.value}),required:!0,type:"number",value:r.maxWidth})})}),u.jsx(ce.Label,{className:"mb-[6px]",children:"Height"}),u.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:u.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:u.jsx(je.Input,{onChange:a=>l({...r,height:a.target.value}),required:!0,type:"number",value:r.height})})}),u.jsx(Xt.Button,{className:"richtext-mt-2 richtext-self-end",type:"submit",children:o("editor.link.dialog.button.apply")})]})})]})},jt=new Map;function nr(e){const t=e.options.element;jt.has("width")||jt.set("width",t.clientWidth),jt.has("width")&&jt.get("width")<=0&&jt.set("width",t.clientWidth);const n={attributes:!0,childList:!0,subtree:!0},i=function(){jt.set("width",t.clientWidth)},s=new MutationObserver(i);return s.observe(t,n),e.on("destroy",()=>{s.disconnect()}),{width:jt.get("width")}}function ir(){const e=tt.useEditableEditor(),t=K.useEditorInstance(),{t:n}=V.useLocale(),{width:i}=nr(t),s=pt.useAttributes(t,zt.Excalidraw.name,{defaultShowPicker:!1,createUser:"",width:0,height:0}),{defaultShowPicker:o,createUser:r,width:l,height:c}=s,a=w.useCallback(g=>{t.chain().updateAttributes(zt.Excalidraw.name,g).setNodeSelection(t.state.selection.from).focus().run()},[t]),h=w.useCallback(()=>{zt.triggerOpenExcalidrawSettingModal({...s,editor:t})},[t,s]),d=w.useCallback(()=>t.isActive(zt.Excalidraw.name),[t]),f=w.useCallback(()=>Se.deleteNode(zt.Excalidraw.name,t),[t]);return w.useEffect(()=>{o&&(h(),t.chain().updateAttributes(zt.Excalidraw.name,{defaultShowPicker:!1}).focus().run())},[r,o,t,h]),e?u.jsx(it,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleExcalidraw",shouldShow:d,children:u.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:[u.jsx(y.ActionButton,{action:h,icon:"Pencil",tooltip:n("editor.edit")}),u.jsx(is,{height:c,maxWidth:i,onOk:a,width:l,children:u.jsx(y.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),u.jsx(y.ActionButton,{action:f,icon:"Trash2",tooltip:n("editor.delete")})]})}):u.jsx(u.Fragment,{})}function sr(){const e=tt.useEditableEditor(),t=K.useEditorInstance(),{t:n}=V.useLocale(),{width:i,height:s,src:o}=pt.useAttributes(t,qt.Iframe.name,{width:0,height:0,src:"",defaultShowPicker:!1}),[r,l]=w.useState(!1),[c,a]=w.useState(""),h=w.useCallback(x=>{var b;(b=x==null?void 0:x.preventDefault)==null||b.call(x),l(!1)},[l]);w.useEffect(()=>{r&&a(o)},[r,o]);const d=w.useCallback(x=>{var D;(D=x==null?void 0:x.preventDefault)==null||D.call(x);const b=qt.getServiceSrc(c);t.chain().updateAttributes(qt.Iframe.name,{src:(b==null?void 0:b.src)||c}).setNodeSelection(t.state.selection.from).focus().run(),l(!1)},[t,c,l]),f=w.useCallback(()=>{window.open(o,"_blank")},[o]),g=w.useCallback(x=>{t.chain().updateAttributes(qt.Iframe.name,x).setNodeSelection(t.state.selection.from).focus().run()},[t]),p=w.useCallback(()=>t.isActive(qt.Iframe.name)&&!o,[t,o]),m=w.useCallback(()=>Se.deleteNode(qt.Iframe.name,t),[t]);return e?u.jsx(u.Fragment,{children:u.jsx(it,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleIframe",shouldShow:p,children:u.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:[u.jsx(y.ActionButton,{action:f,icon:"Eye",tooltip:"Visit Link"}),u.jsxs(L.Dialog,{onOpenChange:l,open:r,children:[u.jsx(L.DialogTrigger,{asChild:!0,children:u.jsx(y.ActionButton,{icon:"Pencil",tooltip:"Open Edit Link"})}),u.jsxs(L.DialogContent,{children:[u.jsx(L.DialogHeader,{children:u.jsx(L.DialogTitle,{children:"Edit Link Iframe"})}),u.jsx(je.Input,{autoFocus:!0,onInput:x=>a(x.target.value),placeholder:"Enter link",type:"url",value:c}),u.jsxs(L.DialogFooter,{children:[u.jsx(Xt.Button,{onClick:h,type:"button",children:"Cancel"}),u.jsx(Xt.Button,{onClick:d,type:"button",children:"OK"})]})]})]}),u.jsx(is,{height:s,onOk:g,width:i,children:u.jsx(y.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),u.jsx(y.ActionButton,{action:m,icon:"Trash2",tooltip:n("editor.delete")})]})})}):u.jsx(u.Fragment,{})}function or({children:e,visible:t,toggleVisible:n}){const{t:i}=V.useLocale(),s=K.useEditorInstance(),o=pt.useAttributes(s,pt.Katex.name,{text:"",macros:""}),{text:r,macros:l}=o,[c,a]=w.useState(decodeURIComponent(r||"")),[h,d]=w.useState(decodeURIComponent(l||""));w.useEffect(()=>{t&&(a(decodeURIComponent(r||"")),d(decodeURIComponent(l||"")))},[t]);const f=w.useCallback(()=>{s.chain().focus().setKatex({text:encodeURIComponent(c),macros:encodeURIComponent(h)}).run(),a(""),d(""),n(!1)},[s,c,h,n]),g=w.useMemo(()=>{try{return ko.renderToString(c,{macros:pt.safeJSONParse(h||"")})}catch{return c}},[c,h]),p=w.useMemo(()=>`${c}`.trim()?g:null,[c,g]);return u.jsxs(L.Dialog,{onOpenChange:n,open:t,children:[u.jsx(L.DialogTrigger,{asChild:!0,children:e}),u.jsxs(L.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[u.jsx(L.DialogTitle,{children:i("editor.formula.dialog.text")}),u.jsx("div",{style:{height:"100%",border:"1px solid hsl(var(--border))"},children:u.jsxs("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[u.jsxs("div",{className:"richtext-flex-1",children:[u.jsx(ce.Label,{className:"mb-[6px]",children:"Expression"}),u.jsx(In.Textarea,{autoFocus:!0,className:"richtext-mb-[10px]",onChange:m=>a(m.target.value),placeholder:"Text",required:!0,rows:10,value:c,style:{color:"hsl(var(--foreground))"}}),u.jsx(ce.Label,{className:"mb-[6px]",children:"Macros"}),u.jsx(In.Textarea,{onChange:m=>d(m.target.value),placeholder:"Macros",rows:10,value:h,style:{color:"hsl(var(--foreground))"}})]}),u.jsx("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:p||""},style:{height:"100%",borderWidth:1,minHeight:500,background:"#fff"}})]})}),u.jsx(L.DialogFooter,{children:u.jsx(Xt.Button,{onClick:f,type:"button",children:"Save changes"})})]})]})}function rr(){const e=tt.useEditableEditor(),t=K.useEditorInstance(),[n,i]=w.useState(!1),s=w.useCallback(()=>t.isActive(pt.Katex.name),[t]),o=w.useCallback(()=>Se.deleteNode(pt.Katex.name,t),[t]);return e?u.jsx(it,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleKatex",shouldShow:s,children:u.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:[u.jsx(or,{toggleVisible:i,visible:n,children:u.jsx(y.ActionButton,{action:()=>i(!n),tooltip:"Edit",children:u.jsx($e.Pencil,{size:16})})}),u.jsx(y.ActionButton,{action:o,tooltip:"Delete",children:u.jsx($e.Trash2,{size:16})})]})}):u.jsx(u.Fragment,{})}function lr(e){const{t}=V.useLocale();return u.jsxs("div",{className:"richtext-flex richtext-flex-nowrap",children:[u.jsx(y.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")}}),u.jsx(y.ActionButton,{icon:"Pencil",tooltip:t("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onEdit()}}),u.jsx(y.ActionButton,{icon:"Unlink",tooltip:t("editor.link.unlink.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onClear()}})]})}function cr(){const e=tt.useEditableEditor(),t=K.useEditorInstance(),[n,i]=w.useState(!1),s=pt.useAttributes(t,Ne.Link.name),o=s==null?void 0:s.href,r=w.useCallback(({editor:h})=>h.isActive(Ne.Link.name),[]),l=(h,d,f)=>{const g=t.state.selection,{from:p}=g,m=(d==null?void 0:d.length)??0,x=p+m;t.chain().extendMarkRange("link").insertContent({type:"text",text:d,marks:[{type:"link",attrs:{href:h,target:f?"_blank":""}}]}).setLink({href:h}).setTextSelection({from:p,to:x}).focus().run(),i(!1)},c=w.useCallback(()=>{t.chain().extendMarkRange("link").unsetLink().focus().run(),i(!1)},[t]),a=()=>{i(!1)};return e?u.jsx(it,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleLink",shouldShow:r,children:u.jsx(u.Fragment,{children:n?u.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:u.jsx(Ne.LinkEditBlock,{editor:t,onClose:a,onSetLink:l})}):u.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:u.jsx(lr,{editor:t,link:o,onClear:c,onEdit:()=>{i(!0)}})})})}):u.jsx(u.Fragment,{})}function Wn({item:e,disabled:t,editor:n}){const i=e.component;return i?u.jsx(w.Fragment,{children:e.type==="divider"?u.jsx(It.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):u.jsx(i,{...e.componentProps,disabled:t||(e==null?void 0:e.componentdisabled),editor:n})}):u.jsx(u.Fragment,{})}function ar(e){return e.type.name===Co.Image.name}function hr(e){return e.type.name===vo.ImageGif.name}function dr(e){return e.type.name===_o.Video.name}function ur(){const{lang:e,t}=V.useLocale(),n=tt.useEditableEditor(),i=K.useEditorInstance(),s=({editor:r})=>{const{selection:l}=r.view.state,{$from:c,to:a}=l;let h=!1;return r.view.state.doc.nodesBetween(c.pos,a,d=>{if(ar(d))return h=!0,!1}),h},o=w.useMemo(()=>Yo(i,t),[i,e,t]);return n?u.jsx(it,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImage",shouldShow:s,children:o!=null&&o.length?u.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:o==null?void 0:o.map((r,l)=>u.jsx(Wn,{editor:i,item:r},`bubbleMenu-image-${l}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}function fr(){const{lang:e,t}=V.useLocale(),n=tt.useEditableEditor(),i=K.useEditorInstance(),s=({editor:r})=>{const{selection:l}=r.view.state,{$from:c,to:a}=l;let h=!1;return r.view.state.doc.nodesBetween(c.pos,a,d=>{if(hr(d))return h=!0,!1}),h},o=w.useMemo(()=>Go(i,t),[i,t,e]);return n?u.jsx(it,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImageGif",shouldShow:s,children:o!=null&&o.length?u.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:o==null?void 0:o.map((r,l)=>u.jsx(Wn,{editor:i,item:r},`bubbleMenu-image-gif-${l}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}function gr(){const{t:e}=V.useLocale(),t=tt.useEditableEditor(),n=K.useEditorInstance(),i=({editor:o})=>{const{selection:r}=o.view.state,{$from:l,to:c}=r;let a=!1;return o.view.state.doc.nodesBetween(l.pos,c,h=>{if(dr(h))return a=!0,!1}),a},s=w.useMemo(()=>Zo(n,e),[n,e]);return t?u.jsx(it,{editor:n,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleVideo",shouldShow:i,children:s!=null&&s.length?u.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((o,r)=>u.jsx(Wn,{editor:n,item:o},`bubbleMenu-video-${r}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}const wi=`graph TB
2
- a-->b`,pr=({editor:e,attrs:t,extension:n})=>{const{alt:i,align:s}=t,[o,r]=w.useState(decodeURIComponent(i??wi)),[l,c]=w.useState(""),[a,h]=w.useState(!1),d=w.useRef(null),[f,g]=w.useState(null),p=n==null?void 0:n.options.upload,m=w.useCallback(M=>{M&&import("mermaid").then(C=>{g(C.default)})},[]),x=async M=>{try{const{svg:C}=await f.render("mermaid-svg",M);c(C)}catch{c("")}},b=()=>{f.initialize({darkMode:!1,startOnLoad:!1,fontSize:12,theme:"base"}),x(o)};w.useEffect(()=>{f&&a&&b()},[f,a]),w.useEffect(()=>{f&&a&&x(o)},[f,o]);const D=async()=>{if(o!==""){if(o){const M=d.current.querySelector("svg"),{width:C,height:B}=M.getBoundingClientRect(),I=`mermaid-${He.shortId()}.svg`;let S=He.i(M.outerHTML);if(p){const k=Qi.dataURLtoFile(S,I);S=await p(k)}e==null||e.chain().focus().setMermaid({type:"mermaid",src:S,alt:encodeURIComponent(o),width:C,height:B},!!o).run(),e==null||e.commands.setAlignImageMermaid(s)}h(!1)}};return u.jsxs(L.Dialog,{onOpenChange:h,open:a,children:[u.jsx(L.DialogTrigger,{asChild:!0,children:u.jsx(y.ActionButton,{action:()=>h(!0),icon:"Pencil",tooltip:"Edit Mermaid"})}),u.jsxs(L.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[u.jsx(L.DialogTitle,{children:"Edit Mermaid"}),u.jsx("div",{ref:m,style:{height:"100%",border:"1px solid hsl(var(--border))"},children:u.jsxs("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[u.jsx(In.Textarea,{autoFocus:!0,className:"richtext-flex-1",defaultValue:wi,onChange:M=>r(M.target.value),placeholder:"Text",required:!0,rows:10,value:o,style:{color:"hsl(var(--foreground))"}}),u.jsx("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:l},ref:d,style:{height:"100%",border:"1px solid hsl(var(--border))",minHeight:500}})]})}),u.jsx(L.DialogFooter,{children:u.jsx(Xt.Button,{onClick:D,type:"button",children:"Save changes"})})]})]})};function mr({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?u.jsx(w.Fragment,{children:e.type==="divider"?u.jsx(It.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):u.jsx(i,{...e.componentProps,disabled:t||((s=e==null?void 0:e.componentProps)==null?void 0:s.disabled),editor:n})}):u.jsx(u.Fragment,{})}function xr(e){return e.type.name===An.Mermaid.name}function wr(){const{lang:e,t}=V.useLocale(),n=tt.useEditableEditor(),i=K.useEditorInstance(),s=pt.useAttributes(i,An.Mermaid.name),o=K.useExtension(An.Mermaid.name),r=({editor:c})=>{const{selection:a}=c.view.state,{$from:h,to:d}=a;let f=!1;return c.view.state.doc.nodesBetween(h.pos,d,g=>{if(xr(g))return f=!0,!1}),f},l=w.useMemo(()=>Jo(i,t),[i,e,t]);return n?u.jsx(it,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleMermaid",shouldShow:r,children:l!=null&&l.length?u.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)?u.jsx(pr,{attrs:s,editor:i,extension:o},`bubbleMenu-mermaid-${a}`):u.jsx(mr,{editor:i,item:c},`bubbleMenu-mermaid-${a}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}function br({hiddenActions:e=[]}){var m,x,b,D,M,C,B,I,S,k,j,$,st,Ot,Rt,v,xt,Ee;const{t}=V.useLocale(),n=tt.useEditableEditor(),i=K.useEditorInstance(),s=({editor:$t})=>E.isActive($t.view.state,Xi.Table.name),o=$t=>e.includes($t);function r(){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 h(){i.chain().focus().addRowAfter().run()}function d(){i.chain().focus().deleteRow().run()}function f(){i.chain().focus().mergeCells().run()}function g(){i==null||i.chain().focus().splitCell().run()}function p(){i.chain().focus().deleteTable().run()}return n?u.jsx(it,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTable",shouldShow:s,children:u.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:[!o("addColumnBefore")&&u.jsx(y.ActionButton,{action:r,disabled:!((x=(m=i==null?void 0:i.can())==null?void 0:m.addColumnBefore)!=null&&x.call(m)),icon:"BetweenHorizonalEnd",tooltip:t("editor.table.menu.insertColumnBefore"),tooltipOptions:{sideOffset:15}}),!o("addColumnAfter")&&u.jsx(y.ActionButton,{action:l,disabled:!((D=(b=i==null?void 0:i.can())==null?void 0:b.addColumnAfter)!=null&&D.call(b)),icon:"BetweenHorizonalStart",tooltip:t("editor.table.menu.insertColumnAfter"),tooltipOptions:{sideOffset:15}}),!o("deleteColumn")&&u.jsx(y.ActionButton,{action:c,disabled:!((C=i==null?void 0:(M=i.can()).deleteColumn)!=null&&C.call(M)),icon:"DeleteColumn",tooltip:t("editor.table.menu.deleteColumn"),tooltipOptions:{sideOffset:15}}),u.jsx(It.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!o("addRowAbove")&&u.jsx(y.ActionButton,{action:a,disabled:!((I=i==null?void 0:(B=i.can()).addRowBefore)!=null&&I.call(B)),icon:"BetweenVerticalEnd",tooltip:t("editor.table.menu.insertRowAbove"),tooltipOptions:{sideOffset:15}}),!o("addRowBelow")&&u.jsx(y.ActionButton,{action:h,disabled:!((k=(S=i==null?void 0:i.can())==null?void 0:S.addRowAfter)!=null&&k.call(S)),icon:"BetweenVerticalStart",tooltip:t("editor.table.menu.insertRowBelow"),tooltipOptions:{sideOffset:15}}),!o("deleteRow")&&u.jsx(y.ActionButton,{action:d,disabled:!(($=(j=i==null?void 0:i.can())==null?void 0:j.deleteRow)!=null&&$.call(j)),icon:"DeleteRow",tooltip:t("editor.table.menu.deleteRow"),tooltipOptions:{sideOffset:15}}),u.jsx(It.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!o("mergeCells")&&u.jsx(y.ActionButton,{action:f,disabled:!((Ot=(st=i==null?void 0:i.can())==null?void 0:st.mergeCells)!=null&&Ot.call(st)),icon:"TableCellsMerge",tooltip:t("editor.table.menu.mergeCells"),tooltipOptions:{sideOffset:15}}),!o("splitCells")&&u.jsx(y.ActionButton,{action:g,disabled:!((v=(Rt=i==null?void 0:i.can())==null?void 0:Rt.splitCell)!=null&&v.call(Rt)),icon:"TableCellsSplit",tooltip:t("editor.table.menu.splitCells"),tooltipOptions:{sideOffset:15}}),u.jsx(It.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!o("deleteTable")&&u.jsx(y.ActionButton,{action:p,disabled:!((Ee=(xt=i==null?void 0:i.can())==null?void 0:xt.deleteTable)!=null&&Ee.call(xt)),icon:"Trash2",tooltip:t("editor.table.menu.deleteTable"),tooltipOptions:{sideOffset:15}})]})}):u.jsx(u.Fragment,{})}function yr(){const{t:e}=V.useLocale(),[t,n]=w.useState(!1),i=K.useEditorInstance(),s=w.useMemo(()=>{var r,l;return(l=(r=Mo.renderCommandListDefault({t:e}))==null?void 0:r[0])==null?void 0:l.commands},[e]),o=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 u.jsxs(Kt.Popover,{modal:!0,onOpenChange:n,open:t,children:[u.jsx(Kt.PopoverTrigger,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:u.jsxs(y.ActionButton,{dataState:!!o,children:[o?u.jsx(u.Fragment,{children:o}):u.jsx(u.Fragment,{children:e("editor.paragraph.tooltip")}),u.jsx(et.IconComponent,{className:"richtext-ml-1 richtext-size-3 richtext-text-zinc-500",name:"MenuDown"})]})}),u.jsx(Kt.PopoverContent,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:s==null?void 0:s.map(r=>{var c;const l=(c=r==null?void 0:r.isActive)==null?void 0:c.call(r,i);return u.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(),r.action({editor:i,range:i.state.selection.ranges}),n(!1)},children:[u.jsxs("div",{className:"!richtext-min-w-[20px]",children:[l&&u.jsx($e.Check,{size:16}),!o&&r.label===e("editor.paragraph.tooltip")&&!l&&u.jsx($e.Check,{size:16})]}),u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:[r.iconName&&u.jsx(et.IconComponent,{className:"!richtext-mr-1 !richtext-text-lg",name:r.iconName}),r.label]})]},r.name)})})]})}function Sr(){return u.jsxs(u.Fragment,{children:[u.jsx(yr,{}),u.jsx(It.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),u.jsx(Eo.RichTextBold,{}),u.jsx(Do.RichTextItalic,{}),u.jsx(Ro.RichTextUnderline,{}),u.jsx(Oo.RichTextStrike,{}),u.jsx(Io.RichTextCode,{}),u.jsx(Ne.RichTextLink,{}),u.jsx(It.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),u.jsx(Ao.RichTextColor,{}),u.jsx(To.RichTextHighlight,{}),u.jsx(ts.RichTextAlign,{})]})}function kr({buttonBubble:e}){const t=K.useEditorInstance(),n=tt.useEditableEditor(),i=({editor:s})=>{const{selection:o}=s.view.state,{$from:r,to:l}=o;return r.pos===l?!1:o instanceof J.TextSelection};return n?u.jsx(it,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleText",shouldShow:i,children:e?u.jsx(u.Fragment,{children:e}):u.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:u.jsx(Sr,{})})}):u.jsx(u.Fragment,{})}function Cr(){const{t:e}=V.useLocale(),t=tt.useEditableEditor(),n=K.useEditorInstance(),[i,s]=w.useState(!1),o=w.useCallback(({editor:c})=>c.isActive(gn.Twitter.name),[]),r=c=>{n.commands.updateTweet({src:c}),s(!1)},l=w.useCallback(()=>Se.deleteNode(gn.Twitter.name,n),[n]);return t?u.jsx(it,{editor:n,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTwitter",shouldShow:o,children:u.jsx(u.Fragment,{children:i?u.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:u.jsx(gn.FormEditLinkTwitter,{editor:n,onSetLink:r})}):u.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:[u.jsx(y.ActionButton,{icon:"Pencil",tooltip:e("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{s(!0)}}),u.jsx(y.ActionButton,{action:l,icon:"Trash",tooltip:e("editor.delete"),tooltipOptions:{sideOffset:15}})]})})}):u.jsx(u.Fragment,{})}const at=()=>new Map,Tn=e=>{const t=at();return e.forEach((n,i)=>{t.set(i,n)}),t},kt=(e,t,n)=>{let i=e.get(t);return i===void 0&&e.set(t,i=n()),i},vr=(e,t)=>{const n=[];for(const[i,s]of e)n.push(t(s,i));return n},_r=(e,t)=>{for(const[n,i]of e)if(t(i,n))return!0;return!1},Ut=()=>new Set,mn=e=>e[e.length-1],Er=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},Lt=Array.from,Ir=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},Dn=Array.isArray;class ss{constructor(){this._observers=at()}on(t,n){return kt(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 Lt((this._observers.get(t)||at()).values()).forEach(i=>i(...n))}destroy(){this._observers=at()}}const St=Math.floor,Be=Math.abs,Zt=(e,t)=>e<t?e:t,At=(e,t)=>e>t?e:t,os=e=>e!==0?e<0:1/e<0,bi=1,yi=2,xn=4,wn=8,de=32,bt=64,G=128,Ar=1<<29,nn=31,Mn=63,Bt=127,Tr=2147483647,rs=Number.MAX_SAFE_INTEGER,Dr=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&St(e)===e),Mr=String.fromCharCode,Or=e=>e.toLowerCase(),Rr=/^\s*/g,jr=e=>e.replace(Rr,""),Nr=/([A-Z])/g,Si=(e,t)=>jr(e.replace(Nr,n=>`${t}${Or(n)}`)),Br=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},ue=typeof TextEncoder<"u"?new TextEncoder:null,Ur=e=>ue.encode(e),Lr=ue?Ur:Br;let ae=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});ae&&ae.decode(new Uint8Array).length===1&&(ae=null);class ke{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Ce=()=>new ke,Pr=e=>{const t=Ce();return e(t),ct(t)},Vr=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},ct=e=>{const t=new Uint8Array(Vr(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},Fr=(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(At(n,t)*2),e.cpos=0)},z=(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},On=z,A=(e,t)=>{for(;t>Bt;)z(e,G|Bt&t),t=St(t/128);z(e,Bt&t)},Yn=(e,t)=>{const n=os(t);for(n&&(t=-t),z(e,(t>Mn?G:0)|(n?bt:0)|Mn&t),t=St(t/64);t>0;)z(e,(t>Bt?G:0)|Bt&t),t=St(t/128)},Rn=new Uint8Array(3e4),Hr=Rn.length/3,$r=(e,t)=>{if(t.length<Hr){const n=ue.encodeInto(t,Rn).written||0;A(e,n);for(let i=0;i<n;i++)z(e,Rn[i])}else nt(e,Lr(t))},zr=(e,t)=>{const n=unescape(encodeURIComponent(t)),i=n.length;A(e,i);for(let s=0;s<i;s++)z(e,n.codePointAt(s))},Wt=ue&&ue.encodeInto?$r:zr,sn=(e,t)=>{const n=e.cbuf.length,i=e.cpos,s=Zt(n-i,t.length),o=t.length-s;e.cbuf.set(t.subarray(0,s),i),e.cpos+=s,o>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(At(n*2,o)),e.cbuf.set(t.subarray(s)),e.cpos=o)},nt=(e,t)=>{A(e,t.byteLength),sn(e,t)},Gn=(e,t)=>{Fr(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},qr=(e,t)=>Gn(e,4).setFloat32(0,t,!1),Kr=(e,t)=>Gn(e,8).setFloat64(0,t,!1),Wr=(e,t)=>Gn(e,8).setBigInt64(0,t,!1),ki=new DataView(new ArrayBuffer(4)),Yr=e=>(ki.setFloat32(0,e),ki.getFloat32(0)===e),Qt=(e,t)=>{switch(typeof t){case"string":z(e,119),Wt(e,t);break;case"number":Dr(t)&&Be(t)<=Tr?(z(e,125),Yn(e,t)):Yr(t)?(z(e,124),qr(e,t)):(z(e,123),Kr(e,t));break;case"bigint":z(e,122),Wr(e,t);break;case"object":if(t===null)z(e,126);else if(Dn(t)){z(e,117),A(e,t.length);for(let n=0;n<t.length;n++)Qt(e,t[n])}else if(t instanceof Uint8Array)z(e,116),nt(e,t);else{z(e,118);const n=Object.keys(t);A(e,n.length);for(let i=0;i<n.length;i++){const s=n[i];Wt(e,s),Qt(e,t[s])}}break;case"boolean":z(e,t?120:121);break;default:z(e,127)}};class Ci extends ke{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 vi=e=>{e.count>0&&(Yn(e.encoder,e.count===1?e.s:-e.s),e.count>1&&A(e.encoder,e.count-2))};class Ue{constructor(){this.encoder=new ke,this.s=0,this.count=0}write(t){this.s===t?this.count++:(vi(this),this.count=1,this.s=t)}toUint8Array(){return vi(this),ct(this.encoder)}}const _i=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);Yn(e.encoder,t),e.count>1&&A(e.encoder,e.count-2)}};class bn{constructor(){this.encoder=new ke,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(_i(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return _i(this),ct(this.encoder)}}class Gr{constructor(){this.sarr=[],this.s="",this.lensE=new Ue}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 ke;return this.sarr.push(this.s),this.s="",Wt(t,this.sarr.join("")),sn(t,this.lensE.toUint8Array()),ct(t)}}const Tt=e=>new Error(e),ht=()=>{throw Tt("Method unimplemented")},Q=()=>{throw Tt("Unexpected case")},ls=Tt("Unexpected end of array"),cs=Tt("Integer out of Range");class on{constructor(t){this.arr=t,this.pos=0}}const Jn=e=>new on(e),Jr=e=>e.pos!==e.arr.length,Xr=(e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},ot=e=>Xr(e,R(e)),fe=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&Bt)*n,n*=128,s<G)return t;if(t>rs)throw cs}throw ls},Xn=e=>{let t=e.arr[e.pos++],n=t&Mn,i=64;const s=(t&bt)>0?-1:1;if((t&G)===0)return s*n;const o=e.arr.length;for(;e.pos<o;){if(t=e.arr[e.pos++],n=n+(t&Bt)*i,i*=128,t<G)return s*n;if(n>rs)throw cs}throw ls},Zr=e=>{let t=R(e);if(t===0)return"";{let n=String.fromCodePoint(fe(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(fe(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))}},Qr=e=>ae.decode(ot(e)),jn=ae?Qr:Zr,Zn=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},tl=e=>Zn(e,4).getFloat32(0,!1),el=e=>Zn(e,8).getFloat64(0,!1),nl=e=>Zn(e,8).getBigInt64(0,!1),il=[e=>{},e=>null,Xn,tl,el,nl,e=>!1,e=>!0,jn,e=>{const t=R(e),n={};for(let i=0;i<t;i++){const s=jn(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},ot],ze=e=>il[127-fe(e)](e);class Ei extends on{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Jr(this)?this.count=R(this)+1:this.count=-1),this.count--,this.s}}class Le extends on{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Xn(this);const t=os(this.s);this.count=1,t&&(this.s=-this.s,this.count=R(this)+2)}return this.count--,this.s}}class yn extends on{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=Xn(this),n=t&1;this.diff=St(t/2),this.count=1,n&&(this.count=R(this)+2)}return this.s+=this.diff,this.count--,this.s}}class sl{constructor(t){this.decoder=new Le(t),this.str=jn(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 ol=crypto.getRandomValues.bind(crypto),rl=Math.random,as=()=>ol(new Uint32Array(1))[0],ll=e=>e[St(rl()*e.length)],cl="10000000-1000-4000-8000"+-1e11,al=()=>cl.replace(/[018]/g,e=>(e^as()&15>>e/4).toString(16)),hl=Date.now,Ii=e=>new Promise(e);Promise.all.bind(Promise);const Ai=e=>e===void 0?null:e;class dl{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}}let hs=new dl,ul=!0;try{typeof localStorage<"u"&&localStorage&&(hs=localStorage,ul=!1)}catch{}const fl=hs,gl=Object.assign,ds=Object.keys,pl=(e,t)=>{for(const n in e)t(e[n],n)},Ti=e=>ds(e).length,ml=e=>{for(const t in e)return!1;return!0},us=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},xl=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),wl=(e,t)=>e===t||Ti(e)===Ti(t)&&us(e,(n,i)=>(n!==void 0||xl(t,i))&&t[i]===n),bl=Object.freeze,fs=e=>{for(const t in e){const n=e[t];(typeof n=="object"||typeof n=="function")&&fs(e[t])}return bl(e)},Qn=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Qn(e,t,n+1)}},yl=(e,t)=>t.includes(e),te=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",gs=typeof window<"u"&&typeof document<"u"&&!te;let gt;const Sl=()=>{if(gt===void 0)if(te){gt=at();const e=process.argv;let t=null;for(let n=0;n<e.length;n++){const i=e[n];i[0]==="-"?(t!==null&&gt.set(t,""),t=i):t!==null&&(gt.set(t,i),t=null)}t!==null&&gt.set(t,"")}else typeof location=="object"?(gt=at(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){const[t,n]=e.split("=");gt.set(`--${Si(t,"-")}`,n),gt.set(`-${Si(t,"-")}`,n)}})):gt=at();return gt},Nn=e=>Sl().has(e),qe=e=>Ai(te?process.env[e.toUpperCase().replaceAll("-","_")]:fl.getItem(e)),ps=e=>Nn("--"+e)||qe(e)!==null;ps("production");const kl=te&&yl(process.env.FORCE_COLOR,["true","1","2"]),Cl=kl||!Nn("--no-colors")&&!ps("no-color")&&(!te||process.stdout.isTTY)&&(!te||Nn("--color")||qe("COLORTERM")!==null||(qe("TERM")||"").includes("color")),vl=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=Mr(e[n]);return btoa(t)},_l=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),El=gs?vl:_l,Il=e=>Pr(t=>Qt(t,e));class Al{constructor(t,n){this.left=t,this.right=n}}const wt=(e,t)=>new Al(e,t),Tl=typeof document<"u"?document:{};typeof DOMParser<"u"&&new DOMParser;const Dl=e=>vr(e,(t,n)=>`${n}:${t};`).join(""),Ml=e=>class{constructor(n){this._=n}destroy(){e(this._)}},Ol=Ml(clearTimeout),ms=(e,t)=>new Ol(setTimeout(t,e)),Ct=Symbol,xs=Ct(),ws=Ct(),Rl=Ct(),jl=Ct(),Nl=Ct(),bs=Ct(),Bl=Ct(),ti=Ct(),Ul=Ct(),Ll=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 o=e[i];if(o===void 0)break;if(o.constructor===String||o.constructor===Number)t.push(o);else if(o.constructor===Object)break}for(i>0&&n.push(t.join(""));i<e.length;i++){const o=e[i];o instanceof Symbol||n.push(o)}return n},Pl={[xs]:wt("font-weight","bold"),[ws]:wt("font-weight","normal"),[Rl]:wt("color","blue"),[Nl]:wt("color","green"),[jl]:wt("color","grey"),[bs]:wt("color","red"),[Bl]:wt("color","purple"),[ti]:wt("color","orange"),[Ul]:wt("color","black")},Vl=e=>{var r;e.length===1&&((r=e[0])==null?void 0:r.constructor)===Function&&(e=e[0]());const t=[],n=[],i=at();let s=[],o=0;for(;o<e.length;o++){const l=e[o],c=Pl[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=Dl(i);o>0||a.length>0?(t.push("%c"+l),n.push(a)):t.push(l)}else break}}for(o>0&&(s=n,s.unshift(t.join("")));o<e.length;o++){const l=e[o];l instanceof Symbol||s.push(l)}return s},ys=Cl?Vl:Ll,Fl=(...e)=>{console.log(...ys(e)),ks.forEach(t=>t.print(e))},Ss=(...e)=>{console.warn(...ys(e)),e.unshift(ti),ks.forEach(t=>t.print(e))},ks=Ut(),Cs=e=>({[Symbol.iterator](){return this},next:e}),Hl=(e,t)=>Cs(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),Sn=(e,t)=>Cs(()=>{const{done:n,value:i}=e.next();return{done:n,value:n?void 0:t(i)}});class ei{constructor(t,n){this.clock=t,this.len=n}}class ne{constructor(){this.clients=new Map}}const Dt=(e,t,n)=>t.clients.forEach((i,s)=>{const o=e.doc.store.clients.get(s);if(o!=null){const r=o[o.length-1],l=r.id.clock+r.length;for(let c=0,a=i[c];c<i.length&&a.clock<l;a=i[++c])Ms(e,o,a.clock,a.len,n)}}),$l=(e,t)=>{let n=0,i=e.length-1;for(;n<=i;){const s=St((n+i)/2),o=e[s],r=o.clock;if(r<=t){if(t<r+o.len)return s;n=s+1}else i=s-1}return null},ie=(e,t)=>{const n=e.clients.get(t.client);return n!==void 0&&$l(n,t.clock)!==null},ni=e=>{e.clients.forEach(t=>{t.sort((s,o)=>s.clock-o.clock);let n,i;for(n=1,i=1;n<t.length;n++){const s=t[i-1],o=t[n];s.clock+s.len>=o.clock?s.len=At(s.len,o.clock+o.len-s.clock):(i<n&&(t[i]=o),i++)}t.length=i})},Bn=e=>{const t=new ne;for(let n=0;n<e.length;n++)e[n].clients.forEach((i,s)=>{if(!t.clients.has(s)){const o=i.slice();for(let r=n+1;r<e.length;r++)Er(o,e[r].clients.get(s)||[]);t.clients.set(s,o)}});return ni(t),t},ge=(e,t,n,i)=>{kt(e.clients,t,()=>[]).push(new ei(n,i))},vs=()=>new ne,zl=e=>{const t=vs();return e.clients.forEach((n,i)=>{const s=[];for(let o=0;o<n.length;o++){const r=n[o];if(r.deleted){const l=r.id.clock;let c=r.length;if(o+1<n.length)for(let a=n[o+1];o+1<n.length&&a.deleted;a=n[++o+1])c+=a.length;s.push(new ei(l,c))}}s.length>0&&t.clients.set(i,s)}),t},ii=(e,t)=>{A(e.restEncoder,t.clients.size),Lt(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 o=0;o<s;o++){const r=i[o];e.writeDsClock(r.clock),e.writeDsLen(r.len)}})},ql=e=>{const t=new ne,n=R(e.restDecoder);for(let i=0;i<n;i++){e.resetDsCurVal();const s=R(e.restDecoder),o=R(e.restDecoder);if(o>0){const r=kt(t.clients,s,()=>[]);for(let l=0;l<o;l++)r.push(new ei(e.readDsClock(),e.readDsLen()))}}return t},Di=(e,t,n)=>{const i=new ne,s=R(e.restDecoder);for(let o=0;o<s;o++){e.resetDsCurVal();const r=R(e.restDecoder),l=R(e.restDecoder),c=n.clients.get(r)||[],a=P(n,r);for(let h=0;h<l;h++){const d=e.readDsClock(),f=d+e.readDsLen();if(d<a){a<f&&ge(i,r,a,f-a);let g=dt(c,d),p=c[g];for(!p.deleted&&p.id.clock<d&&(c.splice(g+1,0,Ze(t,p,d-p.id.clock)),g++);g<c.length&&(p=c[g++],p.id.clock<f);)p.deleted||(f<p.id.clock+p.length&&c.splice(g,0,Ze(t,p,f-p.id.clock)),p.delete(t))}else ge(i,r,d,f-d)}}if(i.clients.size>0){const o=new rn;return A(o.restEncoder,0),ii(o,i),o.toUint8Array()}return null},_s=as;class Ft extends ss{constructor({guid:t=al(),collectionid:n=null,gc:i=!0,gcFilter:s=()=>!0,meta:o=null,autoLoad:r=!1,shouldLoad:l=!0}={}){super(),this.gc=i,this.gcFilter=s,this.clientID=_s(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new Ts,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=r,this.meta=o,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Ii(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const c=()=>Ii(a=>{const h=d=>{(d===void 0||d===!0)&&(this.off("sync",h),a())};this.on("sync",h)});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&&O(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Lt(this.subdocs).map(t=>t.guid))}transact(t,n=null){return O(this,t,n)}get(t,n=q){const i=kt(this.share,t,()=>{const o=new n;return o._integrate(this,null),o}),s=i.constructor;if(n!==q&&s!==n)if(s===q){const o=new n;o._map=i._map,i._map.forEach(r=>{for(;r!==null;r=r.left)r.parent=o}),o._start=i._start;for(let r=o._start;r!==null;r=r.right)r.parent=o;return o._length=i._length,this.share.set(t,o),o._integrate(this,null),o}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,Jt)}getText(t=""){return this.get(t,Mt)}getMap(t=""){return this.get(t,ee)}getXmlElement(t=""){return this.get(t,W)}getXmlFragment(t=""){return this.get(t,Pt)}toJSON(){const t={};return this.share.forEach((n,i)=>{t[i]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,Lt(this.subdocs).forEach(n=>n.destroy());const t=this._item;if(t!==null){this._item=null;const n=t.content;n.doc=new Ft({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,O(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 Kl{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 Ke extends Kl{constructor(t){super(t),this.keys=[],R(t),this.keyClockDecoder=new yn(ot(t)),this.clientDecoder=new Le(ot(t)),this.leftClockDecoder=new yn(ot(t)),this.rightClockDecoder=new yn(ot(t)),this.infoDecoder=new Ei(ot(t),fe),this.stringDecoder=new sl(ot(t)),this.parentInfoDecoder=new Ei(ot(t),fe),this.typeRefDecoder=new Le(ot(t)),this.lenDecoder=new Le(ot(t))}readLeftID(){return new Yt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Yt(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 ot(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 Wl{constructor(){this.restEncoder=Ce()}toUint8Array(){return ct(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){A(this.restEncoder,t)}writeDsLen(t){A(this.restEncoder,t)}}class Yl extends Wl{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){On(this.restEncoder,t)}writeString(t){Wt(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){Qt(this.restEncoder,t)}writeBuf(t){nt(this.restEncoder,t)}writeJSON(t){Wt(this.restEncoder,JSON.stringify(t))}writeKey(t){Wt(this.restEncoder,t)}}class Gl{constructor(){this.restEncoder=Ce(),this.dsCurrVal=0}toUint8Array(){return ct(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,A(this.restEncoder,n)}writeDsLen(t){t===0&&Q(),A(this.restEncoder,t-1),this.dsCurrVal+=t}}class rn extends Gl{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new bn,this.clientEncoder=new Ue,this.leftClockEncoder=new bn,this.rightClockEncoder=new bn,this.infoEncoder=new Ci(On),this.stringEncoder=new Gr,this.parentInfoEncoder=new Ci(On),this.typeRefEncoder=new Ue,this.lenEncoder=new Ue}toUint8Array(){const t=Ce();return A(t,0),nt(t,this.keyClockEncoder.toUint8Array()),nt(t,this.clientEncoder.toUint8Array()),nt(t,this.leftClockEncoder.toUint8Array()),nt(t,this.rightClockEncoder.toUint8Array()),nt(t,ct(this.infoEncoder)),nt(t,this.stringEncoder.toUint8Array()),nt(t,ct(this.parentInfoEncoder)),nt(t,this.typeRefEncoder.toUint8Array()),nt(t,this.lenEncoder.toUint8Array()),sn(t,ct(this.restEncoder)),ct(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){Qt(this.restEncoder,t)}writeBuf(t){nt(this.restEncoder,t)}writeJSON(t){Qt(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 Jl=(e,t,n,i)=>{i=At(i,t[0].id.clock);const s=dt(t,i);A(e.restEncoder,t.length-s),e.writeClient(n),A(e.restEncoder,i);const o=t[s];o.write(e,i-o.id.clock);for(let r=s+1;r<t.length;r++)t[r].write(e,0)},Es=(e,t,n)=>{const i=new Map;n.forEach((s,o)=>{P(t,o)>s&&i.set(o,s)}),ln(t).forEach((s,o)=>{n.has(o)||i.set(o,0)}),A(e.restEncoder,i.size),Lt(i.entries()).sort((s,o)=>o[0]-s[0]).forEach(([s,o])=>{Jl(e,t.clients.get(s),s,o)})},Xl=(e,t)=>{const n=at(),i=R(e.restDecoder);for(let s=0;s<i;s++){const o=R(e.restDecoder),r=new Array(o),l=e.readClient();let c=R(e.restDecoder);n.set(l,{i:0,refs:r});for(let a=0;a<o;a++){const h=e.readInfo();switch(nn&h){case 0:{const d=e.readLen();r[a]=new rt(_(l,c),d),c+=d;break}case 10:{const d=R(e.restDecoder);r[a]=new lt(_(l,c),d),c+=d;break}default:{const d=(h&(bt|G))===0,f=new T(_(l,c),null,(h&G)===G?e.readLeftID():null,null,(h&bt)===bt?e.readRightID():null,d?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,d&&(h&de)===de?e.readString():null,Qs(e,h));r[a]=f,c+=f.length}}}}return n},Zl=(e,t,n)=>{const i=[];let s=Lt(n.keys()).sort((g,p)=>g-p);if(s.length===0)return null;const o=()=>{if(s.length===0)return null;let g=n.get(s[s.length-1]);for(;g.refs.length===g.i;)if(s.pop(),s.length>0)g=n.get(s[s.length-1]);else return null;return g};let r=o();if(r===null)return null;const l=new Ts,c=new Map,a=(g,p)=>{const m=c.get(g);(m==null||m>p)&&c.set(g,p)};let h=r.refs[r.i++];const d=new Map,f=()=>{for(const g of i){const p=g.id.client,m=n.get(p);m?(m.i--,l.clients.set(p,m.refs.slice(m.i)),n.delete(p),m.i=0,m.refs=[]):l.clients.set(p,[g]),s=s.filter(x=>x!==p)}i.length=0};for(;;){if(h.constructor!==lt){const p=kt(d,h.id.client,()=>P(t,h.id.client))-h.id.clock;if(p<0)i.push(h),a(h.id.client,h.id.clock-1),f();else{const m=h.getMissing(e,t);if(m!==null){i.push(h);const x=n.get(m)||{refs:[],i:0};if(x.refs.length===x.i)a(m,P(t,m)),f();else{h=x.refs[x.i++];continue}}else(p===0||p<h.length)&&(h.integrate(e,p),d.set(h.id.client,h.id.clock+h.length))}}if(i.length>0)h=i.pop();else if(r!==null&&r.i<r.refs.length)h=r.refs[r.i++];else{if(r=o(),r===null)break;h=r.refs[r.i++]}}if(l.clients.size>0){const g=new rn;return Es(g,l,new Map),A(g.restEncoder,0),{missing:c,update:g.toUint8Array()}}return null},Ql=(e,t)=>Es(e,t.doc.store,t.beforeState),tc=(e,t,n,i=new Ke(e))=>O(t,s=>{s.local=!1;let o=!1;const r=s.doc,l=r.store,c=Xl(i,r),a=Zl(s,l,c),h=l.pendingStructs;if(h){for(const[f,g]of h.missing)if(g<P(l,f)){o=!0;break}if(a){for(const[f,g]of a.missing){const p=h.missing.get(f);(p==null||p>g)&&h.missing.set(f,g)}h.update=Pi([h.update,a.update])}}else l.pendingStructs=a;const d=Di(i,s,l);if(l.pendingDs){const f=new Ke(Jn(l.pendingDs));R(f.restDecoder);const g=Di(f,s,l);d&&g?l.pendingDs=Pi([d,g]):l.pendingDs=d||g}else l.pendingDs=d;if(o){const f=l.pendingStructs.update;l.pendingStructs=null,Un(s.doc,f)}},n,!1),Un=(e,t,n,i=Ke)=>{const s=Jn(t);tc(s,e,n,new i(s))};class ec{constructor(){this.l=[]}}const Mi=()=>new ec,Oi=(e,t)=>e.l.push(t),Ri=(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.")},Is=(e,t,n)=>Qn(e.l,[t,n]);class Yt{constructor(t,n){this.client=t,this.clock=n}}const Ie=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,_=(e,t)=>new Yt(e,t),pe=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw Q()},me=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1};class We{constructor(t,n,i,s=0){this.type=t,this.tname=n,this.item=i,this.assoc=s}}class nc{constructor(t,n,i=0){this.type=t,this.index=n,this.assoc=i}}const ic=(e,t,n=0)=>new nc(e,t,n),Ae=(e,t,n)=>{let i=null,s=null;return e._item===null?s=pe(e):i=_(e._item.id.client,e._item.id.clock),new We(i,s,t,n)},kn=(e,t,n=0)=>{let i=e._start;if(n<0){if(t===0)return Ae(e,null,n);t--}for(;i!==null;){if(!i.deleted&&i.countable){if(i.length>t)return Ae(e,_(i.id.client,i.id.clock+t),n);t-=i.length}if(i.right===null&&n<0)return Ae(e,i.lastId,n);i=i.right}return Ae(e,null,n)},sc=(e,t)=>{const n=Gt(e,t),i=t.clock-n.id.clock;return{item:n,diff:i}},oc=(e,t,n=!0)=>{const i=t.store,s=e.item,o=e.type,r=e.tname,l=e.assoc;let c=null,a=0;if(s!==null){if(P(i,s.client)<=s.clock)return null;const h=n?Fn(i,s):sc(i,s),d=h.item;if(!(d instanceof T))return null;if(c=d.parent,c._item===null||!c._item.deleted){a=d.deleted||!d.countable?0:h.diff+(l>=0?0:1);let f=d.left;for(;f!==null;)!f.deleted&&f.countable&&(a+=f.length),f=f.left}}else{if(r!==null)c=t.get(r);else if(o!==null){if(P(i,o.client)<=o.clock)return null;const{item:h}=n?Fn(i,o):{item:Gt(i,o)};if(h instanceof T&&h.content instanceof ft)c=h.content.type;else return null}else throw Q();l>=0?a=c._length:a=0}return ic(c,a,e.assoc)};class si{constructor(t,n){this.ds=t,this.sv=n}}const As=(e,t)=>new si(e,t),Cn=e=>As(zl(e.store),ln(e.store)),Nt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!ie(t.ds,e.id),Ln=(e,t)=>{const n=kt(e.meta,Ln,Ut),i=e.doc.store;n.has(t)||(t.sv.forEach((s,o)=>{s<P(i,o)&&X(e,_(o,s))}),Dt(e,t.ds,s=>{}),n.add(t))};class Ts{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const ln=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},P=(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},Ds=(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 Q()}n.push(t)},dt=(e,t)=>{let n=0,i=e.length-1,s=e[i],o=s.id.clock;if(o===t)return i;let r=St(t/(o+s.length-1)*i);for(;n<=i;){if(s=e[r],o=s.id.clock,o<=t){if(t<o+s.length)return r;n=r+1}else i=r-1;r=St((n+i)/2)}throw Q()},rc=(e,t)=>{const n=e.clients.get(t.client);return n[dt(n,t.clock)]},Gt=rc,Pn=(e,t,n)=>{const i=dt(t,n),s=t[i];return s.id.clock<n&&s instanceof T?(t.splice(i+1,0,Ze(e,s,n-s.id.clock)),i+1):i},X=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[Pn(e,n,t.clock)]},ji=(e,t,n)=>{const i=t.clients.get(n.client),s=dt(i,n.clock),o=i[s];return n.clock!==o.id.clock+o.length-1&&o.constructor!==rt&&i.splice(s+1,0,Ze(e,o,n.clock-o.id.clock+1)),o},lc=(e,t,n)=>{const i=e.clients.get(t.id.client);i[dt(i,t.id.clock)]=n},Ms=(e,t,n,i,s)=>{if(i===0)return;const o=n+i;let r=Pn(e,t,n),l;do l=t[r++],o<l.id.clock+l.length&&Pn(e,t,o),s(l);while(r<t.length&&t[r].id.clock<o)};class cc{constructor(t,n,i){this.doc=t,this.deleteSet=new ne,this.beforeState=ln(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 Ni=(e,t)=>t.deleteSet.clients.size===0&&!_r(t.afterState,(n,i)=>t.beforeState.get(i)!==n)?!1:(ni(t.deleteSet),Ql(e,t),ii(e,t.deleteSet),!0),Bi=(e,t,n)=>{const i=t._item;(i===null||i.id.clock<(e.beforeState.get(i.id.client)||0)&&!i.deleted)&&kt(e.changed,t,Ut).add(n)},Pe=(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 T&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,i);continue}break}const o=t-s;return o&&e.splice(t+1-o,o),o},ac=(e,t,n)=>{for(const[i,s]of e.clients.entries()){const o=t.clients.get(i);for(let r=s.length-1;r>=0;r--){const l=s[r],c=l.clock+l.len;for(let a=dt(o,l.clock),h=o[a];a<o.length&&h.id.clock<c;h=o[++a]){const d=o[a];if(l.clock+l.len<=d.id.clock)break;d instanceof T&&d.deleted&&!d.keep&&n(d)&&d.gc(t,!1)}}}},hc=(e,t)=>{e.clients.forEach((n,i)=>{const s=t.clients.get(i);for(let o=n.length-1;o>=0;o--){const r=n[o],l=Zt(s.length-1,1+dt(s,r.clock+r.len-1));for(let c=l,a=s[c];c>0&&a.id.clock>=r.clock;a=s[c])c-=1+Pe(s,c)}})},Os=(e,t)=>{if(t<e.length){const n=e[t],i=n.doc,s=i.store,o=n.deleteSet,r=n._mergeStructs;try{ni(o),n.afterState=ln(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(h=>h.target._item===null||!h.target._item.deleted),c.forEach(h=>{h.currentTarget=a,h._path=null}),c.sort((h,d)=>h.path.length-d.path.length),Is(a._dEH,c,n))})}),l.push(()=>i.emit("afterTransaction",[n,i])),Qn(l,[]),n._needFormattingCleanup&&Dc(n)}finally{i.gc&&ac(o,s,i.gcFilter),hc(o,s),n.afterState.forEach((h,d)=>{const f=n.beforeState.get(d)||0;if(f!==h){const g=s.clients.get(d),p=At(dt(g,f),1);for(let m=g.length-1;m>=p;)m-=1+Pe(g,m)}});for(let h=r.length-1;h>=0;h--){const{client:d,clock:f}=r[h].id,g=s.clients.get(d),p=dt(g,f);p+1<g.length&&Pe(g,p+1)>1||p>0&&Pe(g,p)}if(!n.local&&n.afterState.get(i.clientID)!==n.beforeState.get(i.clientID)&&(Fl(ti,xs,"[yjs] ",ws,bs,"Changed the client-id because another client seems to be using it."),i.clientID=_s()),i.emit("afterTransactionCleanup",[n,i]),i._observers.has("update")){const h=new Yl;Ni(h,n)&&i.emit("update",[h.toUint8Array(),n.origin,i,n])}if(i._observers.has("updateV2")){const h=new rn;Ni(h,n)&&i.emit("updateV2",[h.toUint8Array(),n.origin,i,n])}const{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=n;(l.size>0||a.size>0||c.size>0)&&(l.forEach(h=>{h.clientID=i.clientID,h.collectionid==null&&(h.collectionid=i.collectionid),i.subdocs.add(h)}),a.forEach(h=>i.subdocs.delete(h)),i.emit("subdocs",[{loaded:c,added:l,removed:a},i,n]),a.forEach(h=>h.destroy())),e.length<=t+1?(i._transactionCleanups=[],i.emit("afterAllTransactions",[i,e])):Os(e,t+1)}}},O=(e,t,n=null,i=!0)=>{const s=e._transactionCleanups;let o=!1,r=null;e._transaction===null&&(o=!0,e._transaction=new cc(e,n,i),s.push(e._transaction),s.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{r=t(e._transaction)}finally{if(o){const l=e._transaction===s[0];e._transaction=null,l&&Os(s,0)}}return r};class dc{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const Ui=(e,t,n)=>{Dt(e,n.deletions,i=>{i instanceof T&&t.scope.some(s=>s===e.doc||me(s,i))&&ai(i,!1)})},Li=(e,t,n)=>{let i=null;const s=e.doc,o=e.scope;O(s,l=>{for(;t.length>0&&e.currStackItem===null;){const c=s.store,a=t.pop(),h=new Set,d=[];let f=!1;Dt(l,a.insertions,g=>{if(g instanceof T){if(g.redone!==null){let{item:p,diff:m}=Fn(c,g.id);m>0&&(p=X(l,_(p.id.client,p.id.clock+m))),g=p}!g.deleted&&o.some(p=>p===l.doc||me(p,g))&&d.push(g)}}),Dt(l,a.deletions,g=>{g instanceof T&&o.some(p=>p===l.doc||me(p,g))&&!ie(a.insertions,g.id)&&h.add(g)}),h.forEach(g=>{f=Zs(l,g,h,a.insertions,e.ignoreRemoteMapChanges,e)!==null||f});for(let g=d.length-1;g>=0;g--){const p=d[g];e.deleteFilter(p)&&(p.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 r=e.currStackItem;if(r!=null){const l=i.changedParentTypes;e.emit("stack-item-popped",[{stackItem:r,type:n,changedParentTypes:l,origin:e},e]),e.currStackItem=null}return r};class Rs extends ss{constructor(t,{captureTimeout:n=500,captureTransaction:i=c=>!0,deleteFilter:s=()=>!0,trackedOrigins:o=new Set([null]),ignoreRemoteMapChanges:r=!1,doc:l=Dn(t)?t[0].doc:t instanceof Ft?t:t.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(t),this.deleteFilter=s,o.add(this),this.trackedOrigins=o,this.captureTransaction=i,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=r,this.captureTimeout=n,this.afterTransactionHandler=c=>{if(!this.captureTransaction(c)||!this.scope.some(x=>c.changedParentTypes.has(x)||x===this.doc)||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;const a=this.undoing,h=this.redoing,d=a?this.redoStack:this.undoStack;a?this.stopCapturing():h||this.clear(!1,!0);const f=new ne;c.afterState.forEach((x,b)=>{const D=c.beforeState.get(b)||0,M=x-D;M>0&&ge(f,b,D,M)});const g=hl();let p=!1;if(this.lastChange>0&&g-this.lastChange<this.captureTimeout&&d.length>0&&!a&&!h){const x=d[d.length-1];x.deletions=Bn([x.deletions,c.deleteSet]),x.insertions=Bn([x.insertions,f])}else d.push(new dc(c.deleteSet,f)),p=!0;!a&&!h&&(this.lastChange=g),Dt(c,c.deleteSet,x=>{x instanceof T&&this.scope.some(b=>b===c.doc||me(b,x))&&ai(x,!0)});const m=[{stackItem:d[d.length-1],origin:c.origin,type:a?"redo":"undo",changedParentTypes:c.changedParentTypes},this];p?this.emit("stack-item-added",m):this.emit("stack-item-updated",m)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){const n=new Set(this.scope);t=Dn(t)?t:[t],t.forEach(i=>{n.has(i)||(n.add(i),(i instanceof q?i.doc!==this.doc:i!==this.doc)&&Ss("[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=>Ui(i,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>Ui(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=Li(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=Li(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*uc(e){const t=R(e.restDecoder);for(let n=0;n<t;n++){const i=R(e.restDecoder),s=e.readClient();let o=R(e.restDecoder);for(let r=0;r<i;r++){const l=e.readInfo();if(l===10){const c=R(e.restDecoder);yield new lt(_(s,o),c),o+=c}else if((nn&l)!==0){const c=(l&(bt|G))===0,a=new T(_(s,o),null,(l&G)===G?e.readLeftID():null,null,(l&bt)===bt?e.readRightID():null,c?e.readParentInfo()?e.readString():e.readLeftID():null,c&&(l&de)===de?e.readString():null,Qs(e,l));yield a,o+=a.length}else{const c=e.readLen();yield new rt(_(s,o),c),o+=c}}}}class fc{constructor(t,n){this.gen=uc(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===lt);return this.curr}}class gc{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const pc=(e,t)=>{if(e.constructor===rt){const{client:n,clock:i}=e.id;return new rt(_(n,i+t),e.length-t)}else if(e.constructor===lt){const{client:n,clock:i}=e.id;return new lt(_(n,i+t),e.length-t)}else{const n=e,{client:i,clock:s}=n.id;return new T(_(i,s+t),null,_(i,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Pi=(e,t=Ke,n=rn)=>{if(e.length===1)return e[0];const i=e.map(h=>new t(Jn(h)));let s=i.map(h=>new fc(h,!0)),o=null;const r=new n,l=new gc(r);for(;s=s.filter(f=>f.curr!==null),s.sort((f,g)=>{if(f.curr.id.client===g.curr.id.client){const p=f.curr.id.clock-g.curr.id.clock;return p===0?f.curr.constructor===g.curr.constructor?0:f.curr.constructor===lt?1:-1:p}else return g.curr.id.client-f.curr.id.client}),s.length!==0;){const h=s[0],d=h.curr.id.client;if(o!==null){let f=h.curr,g=!1;for(;f!==null&&f.id.clock+f.length<=o.struct.id.clock+o.struct.length&&f.id.client>=o.struct.id.client;)f=h.next(),g=!0;if(f===null||f.id.client!==d||g&&f.id.clock>o.struct.id.clock+o.struct.length)continue;if(d!==o.struct.id.client)le(l,o.struct,o.offset),o={struct:f,offset:0},h.next();else if(o.struct.id.clock+o.struct.length<f.id.clock)if(o.struct.constructor===lt)o.struct.length=f.id.clock+f.length-o.struct.id.clock;else{le(l,o.struct,o.offset);const p=f.id.clock-o.struct.id.clock-o.struct.length;o={struct:new lt(_(d,o.struct.id.clock+o.struct.length),p),offset:0}}else{const p=o.struct.id.clock+o.struct.length-f.id.clock;p>0&&(o.struct.constructor===lt?o.struct.length-=p:f=pc(f,p)),o.struct.mergeWith(f)||(le(l,o.struct,o.offset),o={struct:f,offset:0},h.next())}}else o={struct:h.curr,offset:0},h.next();for(let f=h.curr;f!==null&&f.id.client===d&&f.id.clock===o.struct.id.clock+o.struct.length&&f.constructor!==lt;f=h.next())le(l,o.struct,o.offset),o={struct:f,offset:0}}o!==null&&(le(l,o.struct,o.offset),o=null),mc(l);const c=i.map(h=>ql(h)),a=Bn(c);return ii(r,a),r.toUint8Array()},js=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:ct(e.encoder.restEncoder)}),e.encoder.restEncoder=Ce(),e.written=0)},le=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&js(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++},mc=e=>{js(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),sn(t,i.restEncoder)}},Vi="You must not compute changes after the event-handler fired.";class cn{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=xc(this.currentTarget,this.target))}deletes(t){return ie(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Tt(Vi);const t=new Map,n=this.target;this.transaction.changed.get(n).forEach(s=>{if(s!==null){const o=n._map.get(s);let r,l;if(this.adds(o)){let c=o.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(o))if(c!==null&&this.deletes(c))r="delete",l=mn(c.content.getContent());else return;else c!==null&&this.deletes(c)?(r="update",l=mn(c.content.getContent())):(r="add",l=void 0)}else if(this.deletes(o))r="delete",l=mn(o.content.getContent());else return;t.set(s,{action:r,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 Tt(Vi);const n=this.target,i=Ut(),s=Ut(),o=[];if(t={added:i,deleted:s,delta:o,keys:this.keys},this.transaction.changed.get(n).has(null)){let l=null;const c=()=>{l&&o.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 xc=(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},Y=()=>{Ss("Invalid access: Add Yjs type to a document before reading data.")},Ns=80;let oi=0;class wc{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=oi++}}const bc=e=>{e.timestamp=oi++},Bs=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=oi++},yc=(e,t,n)=>{if(e.length>=Ns){const i=e.reduce((s,o)=>s.timestamp<o.timestamp?s:o);return Bs(i,t,n),i}else{const i=new wc(t,n);return e.push(i),i}},an=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;const n=e._searchMarker.length===0?null:e._searchMarker.reduce((o,r)=>Be(t-o.index)<Be(t-r.index)?o:r);let i=e._start,s=0;for(n!==null&&(i=n.p,s=n.index,bc(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&&Be(n.index-s)<i.parent.length/Ns?(Bs(n,i,s),n):yc(e._searchMarker,i,s)},xe=(e,t,n)=>{for(let i=e.length-1;i>=0;i--){const s=e[i];if(n>0){let o=s.p;for(o.marker=!1;o&&(o.deleted||!o.countable);)o=o.left,o&&!o.deleted&&o.countable&&(s.index-=o.length);if(o===null||o.marker===!0){e.splice(i,1);continue}s.p=o,o.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=At(t,s.index+n))}},hn=(e,t,n)=>{const i=e,s=t.changedParentTypes;for(;kt(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Is(i._eH,n,t)};class q{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Mi(),this._dEH=Mi(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw ht()}clone(){throw ht()}_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){Oi(this._eH,t)}observeDeep(t){Oi(this._dEH,t)}unobserve(t){Ri(this._eH,t)}unobserveDeep(t){Ri(this._dEH,t)}toJSON(){}}const Us=(e,t,n)=>{e.doc??Y(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let i=n-t;const s=[];let o=e._start;for(;o!==null&&i>0;){if(o.countable&&!o.deleted){const r=o.content.getContent();if(r.length<=t)t-=r.length;else{for(let l=t;l<r.length&&i>0;l++)s.push(r[l]),i--;t=0}}o=o.right}return s},Ls=e=>{e.doc??Y();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},Ps=(e,t)=>{const n=[];let i=e._start;for(;i!==null;){if(i.countable&&Nt(i,t)){const s=i.content.getContent();for(let o=0;o<s.length;o++)n.push(s[o])}i=i.right}return n},we=(e,t)=>{let n=0,i=e._start;for(e.doc??Y();i!==null;){if(i.countable&&!i.deleted){const s=i.content.getContent();for(let o=0;o<s.length;o++)t(s[o],n++,e)}i=i.right}},Vs=(e,t)=>{const n=[];return we(e,(i,s)=>{n.push(t(i,s,e))}),n},Sc=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}}}},Fs=(e,t)=>{e.doc??Y();const n=an(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}},Ye=(e,t,n,i)=>{let s=n;const o=e.doc,r=o.clientID,l=o.store,c=n===null?t._start:n.right;let a=[];const h=()=>{a.length>0&&(s=new T(_(r,P(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new Vt(a)),s.integrate(e,0),a=[])};i.forEach(d=>{if(d===null)a.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(d);break;default:switch(h(),d.constructor){case Uint8Array:case ArrayBuffer:s=new T(_(r,P(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new ve(new Uint8Array(d))),s.integrate(e,0);break;case Ft:s=new T(_(r,P(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new _e(d)),s.integrate(e,0);break;default:if(d instanceof q)s=new T(_(r,P(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new ft(d)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},Hs=()=>Tt("Length exceeded!"),$s=(e,t,n,i)=>{if(n>t._length)throw Hs();if(n===0)return t._searchMarker&&xe(t._searchMarker,n,i.length),Ye(e,t,null,i);const s=n,o=an(t,n);let r=t._start;for(o!==null&&(r=o.p,n-=o.index,n===0&&(r=r.prev,n+=r&&r.countable&&!r.deleted?r.length:0));r!==null;r=r.right)if(!r.deleted&&r.countable){if(n<=r.length){n<r.length&&X(e,_(r.id.client,r.id.clock+n));break}n-=r.length}return t._searchMarker&&xe(t._searchMarker,s,i.length),Ye(e,t,r,i)},kc=(e,t,n)=>{let s=(t._searchMarker||[]).reduce((o,r)=>r.index>o.index?r:o,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return Ye(e,t,s,n)},zs=(e,t,n,i)=>{if(i===0)return;const s=n,o=i,r=an(t,n);let l=t._start;for(r!==null&&(l=r.p,n-=r.index);l!==null&&n>0;l=l.right)!l.deleted&&l.countable&&(n<l.length&&X(e,_(l.id.client,l.id.clock+n)),n-=l.length);for(;i>0&&l!==null;)l.deleted||(i<l.length&&X(e,_(l.id.client,l.id.clock+i)),l.delete(e),i-=l.length),l=l.right;if(i>0)throw Hs();t._searchMarker&&xe(t._searchMarker,s,-o+i)},Ge=(e,t,n)=>{const i=t._map.get(n);i!==void 0&&i.delete(e)},ri=(e,t,n,i)=>{const s=t._map.get(n)||null,o=e.doc,r=o.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 ve(i);break;case Ft:l=new _e(i);break;default:if(i instanceof q)l=new ft(i);else throw new Error("Unexpected content type")}new T(_(r,P(o.store,r)),s,s&&s.lastId,null,null,t,n,l).integrate(e,0)},li=(e,t)=>{e.doc??Y();const n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},qs=e=>{const t={};return e.doc??Y(),e._map.forEach((n,i)=>{n.deleted||(t[i]=n.content.getContent()[n.length-1])}),t},Ks=(e,t)=>{e.doc??Y();const n=e._map.get(t);return n!==void 0&&!n.deleted},Cc=(e,t)=>{const n={};return e._map.forEach((i,s)=>{let o=i;for(;o!==null&&(!t.sv.has(o.id.client)||o.id.clock>=(t.sv.get(o.id.client)||0));)o=o.left;o!==null&&Nt(o,t)&&(n[s]=o.content.getContent()[o.length-1])}),n},Te=e=>(e.doc??Y(),Hl(e._map.entries(),t=>!t[1].deleted));class vc extends cn{}class Jt extends q{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new Jt;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Jt}clone(){const t=new Jt;return t.insert(0,this.toArray().map(n=>n instanceof q?n.clone():n)),t}get length(){return this.doc??Y(),this._length}_callObserver(t,n){super._callObserver(t,n),hn(this,t,new vc(this,t))}insert(t,n){this.doc!==null?O(this.doc,i=>{$s(i,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?O(this.doc,n=>{kc(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?O(this.doc,i=>{zs(i,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return Fs(this,t)}toArray(){return Ls(this)}slice(t=0,n=this.length){return Us(this,t,n)}toJSON(){return this.map(t=>t instanceof q?t.toJSON():t)}map(t){return Vs(this,t)}forEach(t){we(this,t)}[Symbol.iterator](){return Sc(this)}_write(t){t.writeTypeRef(Gc)}}const _c=e=>new Jt;class Ec extends cn{constructor(t,n,i){super(t,n),this.keysChanged=i}}class ee extends q{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 ee}clone(){const t=new ee;return this.forEach((n,i)=>{t.set(i,n instanceof q?n.clone():n)}),t}_callObserver(t,n){hn(this,t,new Ec(this,t,n))}toJSON(){this.doc??Y();const t={};return this._map.forEach((n,i)=>{if(!n.deleted){const s=n.content.getContent()[n.length-1];t[i]=s instanceof q?s.toJSON():s}}),t}get size(){return[...Te(this)].length}keys(){return Sn(Te(this),t=>t[0])}values(){return Sn(Te(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Sn(Te(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??Y(),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?O(this.doc,n=>{Ge(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?O(this.doc,i=>{ri(i,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return li(this,t)}has(t){return Ks(this,t)}clear(){this.doc!==null?O(this.doc,t=>{this.forEach(function(n,i,s){Ge(t,s,i)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Jc)}}const Ic=e=>new ee,_t=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&wl(e,t);class Vn{constructor(t,n,i,s){this.left=t,this.right=n,this.index=i,this.currentAttributes=s}forward(){switch(this.right===null&&Q(),this.right.content.constructor){case F:this.right.deleted||se(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 Fi=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case F:t.right.deleted||se(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&X(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},De=(e,t,n,i)=>{const s=new Map,o=i?an(t,n):null;if(o){const r=new Vn(o.p.left,o.p,o.index,s);return Fi(e,r,n-o.index)}else{const r=new Vn(null,t._start,0,s);return Fi(e,r,n)}},Ws=(e,t,n,i)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===F&&_t(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,o=s.clientID;i.forEach((r,l)=>{const c=n.left,a=n.right,h=new T(_(o,P(s.store,o)),c,c&&c.lastId,a,a&&a.id,t,null,new F(l,r));h.integrate(e,0),n.right=h,n.forward()})},se=(e,t)=>{const{key:n,value:i}=t;i===null?e.delete(n):e.set(n,i)},Ys=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===F&&_t(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},Gs=(e,t,n,i)=>{const s=e.doc,o=s.clientID,r=new Map;for(const l in i){const c=i[l],a=n.currentAttributes.get(l)??null;if(!_t(a,c)){r.set(l,a);const{left:h,right:d}=n;n.right=new T(_(o,P(s.store,o)),h,h&&h.lastId,d,d&&d.id,t,null,new F(l,c)),n.right.integrate(e,0),n.forward()}}return r},vn=(e,t,n,i,s)=>{n.currentAttributes.forEach((f,g)=>{s[g]===void 0&&(s[g]=null)});const o=e.doc,r=o.clientID;Ys(n,s);const l=Gs(e,t,n,s),c=i.constructor===String?new ut(i):i instanceof q?new ft(i):new Ht(i);let{left:a,right:h,index:d}=n;t._searchMarker&&xe(t._searchMarker,n.index,c.getLength()),h=new T(_(r,P(o.store,r)),a,a&&a.lastId,h,h&&h.id,t,null,c),h.integrate(e,0),n.right=h,n.index=d,n.forward(),Ws(e,t,n,l)},Hi=(e,t,n,i,s)=>{const o=e.doc,r=o.clientID;Ys(n,s);const l=Gs(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,h=s[c];if(h!==void 0){if(_t(h,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&&X(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+=`
3
- `;n.right=new T(_(r,P(o.store,r)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new ut(c)),n.right.integrate(e,0),n.forward()}Ws(e,t,n,l)},Js=(e,t,n,i,s)=>{let o=t;const r=at();for(;o&&(!o.countable||o.deleted);){if(!o.deleted&&o.content.constructor===F){const a=o.content;r.set(a.key,a)}o=o.right}let l=0,c=!1;for(;t!==o;){if(n===t&&(c=!0),!t.deleted){const a=t.content;switch(a.constructor){case F:{const{key:h,value:d}=a,f=i.get(h)??null;(r.get(h)!==a||f===d)&&(t.delete(e),l++,!c&&(s.get(h)??null)===d&&f!==d&&(f===null?s.delete(h):s.set(h,f))),!c&&!t.deleted&&se(s,a);break}}}t=t.right}return l},Ac=(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}},Tc=e=>{let t=0;return O(e.doc,n=>{let i=e._start,s=e._start,o=at();const r=Tn(o);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case F:se(r,s.content);break;default:t+=Js(n,i,s,o,r),o=Tn(r),i=s;break}s=s.right}}),t},Dc=e=>{const t=new Set,n=e.doc;for(const[i,s]of e.afterState.entries()){const o=e.beforeState.get(i)||0;s!==o&&Ms(e,n.store.clients.get(i),o,s,r=>{!r.deleted&&r.content.constructor===F&&r.constructor!==rt&&t.add(r.parent)})}O(n,i=>{Dt(e,e.deleteSet,s=>{if(s instanceof rt||!s.parent._hasFormatting||t.has(s.parent))return;const o=s.parent;s.content.constructor===F?t.add(o):Ac(i,s)});for(const s of t)Tc(s)})},$i=(e,t,n)=>{const i=n,s=Tn(t.currentAttributes),o=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case ft:case Ht:case ut:n<t.right.length&&X(e,_(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}o&&Js(e,o,t.right,s,t.currentAttributes);const r=(t.left||t.right).parent;return r._searchMarker&&xe(r._searchMarker,t.index,-i+n),t};class Mc extends cn{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=[];O(t,i=>{const s=new Map,o=new Map;let r=this.target._start,l=null;const c={};let a="",h=0,d=0;const f=()=>{if(l!==null){let g=null;switch(l){case"delete":d>0&&(g={delete:d}),d=0;break;case"insert":(typeof a=="object"||a.length>0)&&(g={insert:a},s.size>0&&(g.attributes={},s.forEach((p,m)=>{p!==null&&(g.attributes[m]=p)}))),a="";break;case"retain":h>0&&(g={retain:h},ml(c)||(g.attributes=gl({},c))),h=0;break}g&&n.push(g),l=null}};for(;r!==null;){switch(r.content.constructor){case ft:case Ht:this.adds(r)?this.deletes(r)||(f(),l="insert",a=r.content.getContent()[0],f()):this.deletes(r)?(l!=="delete"&&(f(),l="delete"),d+=1):r.deleted||(l!=="retain"&&(f(),l="retain"),h+=1);break;case ut:this.adds(r)?this.deletes(r)||(l!=="insert"&&(f(),l="insert"),a+=r.content.str):this.deletes(r)?(l!=="delete"&&(f(),l="delete"),d+=r.length):r.deleted||(l!=="retain"&&(f(),l="retain"),h+=r.length);break;case F:{const{key:g,value:p}=r.content;if(this.adds(r)){if(!this.deletes(r)){const m=s.get(g)??null;_t(m,p)?p!==null&&r.delete(i):(l==="retain"&&f(),_t(p,o.get(g)??null)?delete c[g]:c[g]=p)}}else if(this.deletes(r)){o.set(g,p);const m=s.get(g)??null;_t(m,p)||(l==="retain"&&f(),c[g]=m)}else if(!r.deleted){o.set(g,p);const m=c[g];m!==void 0&&(_t(m,p)?m!==null&&r.delete(i):(l==="retain"&&f(),p===null?delete c[g]:c[g]=p))}r.deleted||(l==="insert"&&f(),se(s,r.content));break}}r=r.right}for(f();n.length>0;){const g=n[n.length-1];if(g.retain!==void 0&&g.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class Mt extends q{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??Y(),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 Mt}clone(){const t=new Mt;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const i=new Mc(this,t,n);hn(this,t,i),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??Y();let t="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===ut&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){this.doc!==null?O(this.doc,i=>{const s=new Vn(null,this._start,0,new Map);for(let o=0;o<t.length;o++){const r=t[o];if(r.insert!==void 0){const l=!n&&typeof r.insert=="string"&&o===t.length-1&&s.right===null&&r.insert.slice(-1)===`
4
- `?r.insert.slice(0,-1):r.insert;(typeof l!="string"||l.length>0)&&vn(i,this,s,l,r.attributes||{})}else r.retain!==void 0?Hi(i,this,s,r.retain,r.attributes||{}):r.delete!==void 0&&$i(i,s,r.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,i){this.doc??Y();const s=[],o=new Map,r=this.doc;let l="",c=this._start;function a(){if(l.length>0){const d={};let f=!1;o.forEach((p,m)=>{f=!0,d[m]=p});const g={insert:l};f&&(g.attributes=d),s.push(g),l=""}}const h=()=>{for(;c!==null;){if(Nt(c,t)||n!==void 0&&Nt(c,n))switch(c.content.constructor){case ut:{const d=o.get("ychange");t!==void 0&&!Nt(c,t)?(d===void 0||d.user!==c.id.client||d.type!=="removed")&&(a(),o.set("ychange",i?i("removed",c.id):{type:"removed"})):n!==void 0&&!Nt(c,n)?(d===void 0||d.user!==c.id.client||d.type!=="added")&&(a(),o.set("ychange",i?i("added",c.id):{type:"added"})):d!==void 0&&(a(),o.delete("ychange")),l+=c.content.str;break}case ft:case Ht:{a();const d={insert:c.content.getContent()[0]};if(o.size>0){const f={};d.attributes=f,o.forEach((g,p)=>{f[p]=g})}s.push(d);break}case F:Nt(c,t)&&(a(),se(o,c.content));break}c=c.right}a()};return t||n?O(r,d=>{t&&Ln(d,t),n&&Ln(d,n),h()},"cleanup"):h(),s}insert(t,n,i){if(n.length<=0)return;const s=this.doc;s!==null?O(s,o=>{const r=De(o,this,t,!i);i||(i={},r.currentAttributes.forEach((l,c)=>{i[c]=l})),vn(o,this,r,n,i)}):this._pending.push(()=>this.insert(t,n,i))}insertEmbed(t,n,i){const s=this.doc;s!==null?O(s,o=>{const r=De(o,this,t,!i);vn(o,this,r,n,i||{})}):this._pending.push(()=>this.insertEmbed(t,n,i||{}))}delete(t,n){if(n===0)return;const i=this.doc;i!==null?O(i,s=>{$i(s,De(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?O(s,o=>{const r=De(o,this,t,!1);r.right!==null&&Hi(o,this,r,n,i)}):this._pending.push(()=>this.format(t,n,i))}removeAttribute(t){this.doc!==null?O(this.doc,n=>{Ge(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?O(this.doc,i=>{ri(i,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return li(this,t)}getAttributes(){return qs(this)}_write(t){t.writeTypeRef(Xc)}}const Oc=e=>new Mt;class _n{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??Y()}[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===W||n.constructor===Pt)&&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 Pt extends q{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 Pt}clone(){const t=new Pt;return t.insert(0,this.toArray().map(n=>n instanceof q?n.clone():n)),t}get length(){return this.doc??Y(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new _n(this,t)}querySelector(t){t=t.toUpperCase();const i=new _n(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return i.done?null:i.value}querySelectorAll(t){return t=t.toUpperCase(),Lt(new _n(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){hn(this,t,new Nc(this,n,t))}toString(){return Vs(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),we(this,o=>{s.insertBefore(o.toDOM(t,n,i),null)}),s}insert(t,n){this.doc!==null?O(this.doc,i=>{$s(i,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)O(this.doc,i=>{const s=t&&t instanceof q?t._item:t;Ye(i,this,s,n)});else{const i=this._prelimContent,s=t===null?0:i.findIndex(o=>o===t)+1;if(s===0&&t!==null)throw Tt("Reference item not found");i.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?O(this.doc,i=>{zs(i,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return Ls(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Fs(this,t)}slice(t=0,n=this.length){return Us(this,t,n)}forEach(t){we(this,t)}_write(t){t.writeTypeRef(Qc)}}const Rc=e=>new Pt;class W extends Pt{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 W(this.nodeName)}clone(){const t=new W(this.nodeName),n=this.getAttributes();return pl(n,(i,s)=>{t.setAttribute(s,i)}),t.insert(0,this.toArray().map(i=>i instanceof q?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 o=this.nodeName.toLocaleLowerCase(),r=n.length>0?" "+n.join(" "):"";return`<${o}${r}>${super.toString()}</${o}>`}removeAttribute(t){this.doc!==null?O(this.doc,n=>{Ge(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?O(this.doc,i=>{ri(i,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return li(this,t)}hasAttribute(t){return Ks(this,t)}getAttributes(t){return t?Cc(this,t):qs(this)}toDOM(t=document,n={},i){const s=t.createElement(this.nodeName),o=this.getAttributes();for(const r in o){const l=o[r];typeof l=="string"&&s.setAttribute(r,l)}return we(this,r=>{s.appendChild(r.toDOM(t,n,i))}),i!==void 0&&i._createAssociation(s,this),s}_write(t){t.writeTypeRef(Zc),t.writeKey(this.nodeName)}}const jc=e=>new W(e.readKey());class Nc extends cn{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 Je extends ee{constructor(t){super(),this.hookName=t}_copy(){return new Je(this.hookName)}clone(){const t=new Je(this.hookName);return this.forEach((n,i)=>{t.set(i,n)}),t}toDOM(t=document,n={},i){const s=n[this.hookName];let o;return s!==void 0?o=s.createDom(this):o=document.createElement(this.hookName),o.setAttribute("data-yjs-hook",this.hookName),i!==void 0&&i._createAssociation(o,this),o}_write(t){t.writeTypeRef(ta),t.writeKey(this.hookName)}}const Bc=e=>new Je(e.readKey());class Z extends Mt{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 Z}clone(){const t=new Z;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 o=[];for(const r in t.attributes[s])o.push({key:r,value:t.attributes[s][r]});o.sort((r,l)=>r.key<l.key?-1:1),n.push({nodeName:s,attrs:o})}n.sort((s,o)=>s.nodeName<o.nodeName?-1:1);let i="";for(let s=0;s<n.length;s++){const o=n[s];i+=`<${o.nodeName}`;for(let r=0;r<o.attrs.length;r++){const l=o.attrs[r];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(ea)}}const Uc=e=>new Z;class ci{constructor(t,n){this.id=t,this.length=n}get deleted(){throw ht()}mergeWith(t){return!1}write(t,n,i){throw ht()}integrate(t,n){throw ht()}}const Lc=0;class rt extends ci{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),Ds(t.doc.store,this)}write(t,n){t.writeInfo(Lc),t.writeLen(this.length-n)}getMissing(t,n){return null}}class ve{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new ve(this.content)}splice(t){throw ht()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}const Pc=e=>new ve(e.readBuf());class be{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new be(this.len)}splice(t){const n=new be(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){ge(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 Vc=e=>new be(e.readLen()),Xs=(e,t)=>new Ft({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class _e{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 _e(Xs(this.doc.guid,this.opts))}splice(t){throw ht()}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 Fc=e=>new _e(Xs(e.readString(),e.readAny()));class Ht{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Ht(this.embed)}splice(t){throw ht()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}const Hc=e=>new Ht(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 ht()}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 $c=e=>new F(e.readKey(),e.readJSON());class Xe{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Xe(this.arr)}splice(t){const n=new Xe(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 o=this.arr[s];t.writeString(o===void 0?"undefined":JSON.stringify(o))}}getRef(){return 2}}const zc=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 Xe(n)},qc=qe("node_env")==="development";class Vt{constructor(t){this.arr=t,qc&&fs(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 o=this.arr[s];t.writeAny(o)}}getRef(){return 8}}const Kc=e=>{const t=e.readLen(),n=[];for(let i=0;i<t;i++)n.push(e.readAny());return new Vt(n)};class ut{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new ut(this.str)}splice(t){const n=new ut(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 Wc=e=>new ut(e.readString()),Yc=[_c,Ic,Oc,jc,Rc,Bc,Uc],Gc=0,Jc=1,Xc=2,Zc=3,Qc=4,ta=5,ea=6;class ft{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new ft(this.type._copy())}splice(t){throw ht()}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 na=e=>new ft(Yc[e.readTypeRef()](e)),Fn=(e,t)=>{let n=t,i=0,s;do i>0&&(n=_(n.client,n.clock+i)),s=Gt(e,n),i=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof T);return{item:s,diff:i}},ai=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Ze=(e,t,n)=>{const{client:i,clock:s}=t.id,o=new T(_(i,s+n),t,_(i,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&o.markDeleted(),t.keep&&(o.keep=!0),t.redone!==null&&(o.redone=_(t.redone.client,t.redone.clock+n)),t.right=o,o.right!==null&&(o.right.left=o),e._mergeStructs.push(o),o.parentSub!==null&&o.right===null&&o.parent._map.set(o.parentSub,o),t.length=n,o},zi=(e,t)=>Ir(e,n=>ie(n.deletions,t)),Zs=(e,t,n,i,s,o)=>{const r=e.doc,l=r.store,c=r.clientID,a=t.redone;if(a!==null)return X(e,a);let h=t.parent._item,d=null,f;if(h!==null&&h.deleted===!0){if(h.redone===null&&(!n.has(h)||Zs(e,h,n,i,s,o)===null))return null;for(;h.redone!==null;)h=X(e,h.redone)}const g=h===null?t.parent:h.content.type;if(t.parentSub===null){for(d=t.left,f=t;d!==null;){let b=d;for(;b!==null&&b.parent._item!==h;)b=b.redone===null?null:X(e,b.redone);if(b!==null&&b.parent._item===h){d=b;break}d=d.left}for(;f!==null;){let b=f;for(;b!==null&&b.parent._item!==h;)b=b.redone===null?null:X(e,b.redone);if(b!==null&&b.parent._item===h){f=b;break}f=f.right}}else if(f=null,t.right&&!s){for(d=t;d!==null&&d.right!==null&&(d.right.redone||ie(i,d.right.id)||zi(o.undoStack,d.right.id)||zi(o.redoStack,d.right.id));)for(d=d.right;d.redone;)d=X(e,d.redone);if(d&&d.right!==null)return null}else d=g._map.get(t.parentSub)||null;const p=P(l,c),m=_(c,p),x=new T(m,d,d&&d.lastId,f,f&&f.id,g,t.parentSub,t.content.copy());return t.redone=m,ai(x,!0),x.integrate(e,0),x};class T extends ci{constructor(t,n,i,s,o,r,l,c){super(t,c.getLength()),this.origin=i,this.left=n,this.right=s,this.rightOrigin=o,this.parent=r,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?yi:0}set marker(t){(this.info&wn)>0!==t&&(this.info^=wn)}get marker(){return(this.info&wn)>0}get keep(){return(this.info&bi)>0}set keep(t){this.keep!==t&&(this.info^=bi)}get countable(){return(this.info&yi)>0}get deleted(){return(this.info&xn)>0}set deleted(t){this.deleted!==t&&(this.info^=xn)}markDeleted(){this.info|=xn}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=P(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=P(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Yt&&this.id.client!==this.parent.client&&this.parent.clock>=P(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=ji(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=X(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===rt||this.right&&this.right.constructor===rt)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===T?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===T&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Yt){const i=Gt(n,this.parent);i.constructor===rt?this.parent=null:this.parent=i.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=ji(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 o=new Set,r=new Set;for(;s!==null&&s!==this.right;){if(r.add(s),o.add(s),Ie(this.origin,s.origin)){if(s.id.client<this.id.client)i=s,o.clear();else if(Ie(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&r.has(Gt(t.doc.store,s.origin)))o.has(Gt(t.doc.store,s.origin))||(i=s,o.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),Ds(t.doc.store,this),this.content.integrate(t,this),Bi(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new rt(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&&Ie(t.origin,this.lastId)&&this.right===t&&Ie(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(),ge(t.deleteSet,this.id.client,this.id.clock,this.length),Bi(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw Q();this.content.gc(t),n?lc(t,this,new rt(this.id,this.length)):this.content=new be(this.length)}write(t,n){const i=n>0?_(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,o=this.parentSub,r=this.content.getRef()&nn|(i===null?0:G)|(s===null?0:bt)|(o===null?0:de);if(t.writeInfo(r),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=pe(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===Yt?(t.writeParentInfo(!1),t.writeLeftID(l)):Q();o!==null&&t.writeString(o)}this.content.write(t,n)}}const Qs=(e,t)=>ia[t&nn](e),ia=[()=>{Q()},Vc,zc,Pc,Wc,Hc,$c,na,Kc,Fc,()=>{Q()}],sa=10;class lt extends ci{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){Q()}write(t,n){t.writeInfo(sa),A(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const to=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},eo="__ $YJS$ __";to[eo]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");to[eo]=!0;const oa=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},ra=/[\uD800-\uDBFF]/,la=/[\uDC00-\uDFFF]/,ca=(e,t)=>{let n=0,i=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&ra.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&&la.test(e[e.length-i])&&i--,{index:n,remove:e.length-n-i,insert:t.slice(n,t.length-i)}},aa=ca,mt=(e,t)=>e>>>t|e<<32-t,ha=e=>mt(e,2)^mt(e,13)^mt(e,22),da=e=>mt(e,6)^mt(e,11)^mt(e,25),ua=e=>mt(e,7)^mt(e,18)^e>>>3,fa=e=>mt(e,17)^mt(e,19)^e>>>10,ga=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]),pa=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class ma{constructor(){const t=new ArrayBuffer(320);this._H=new Uint32Array(t,0,8),this._H.set(pa),this._W=new Uint32Array(t,64,64)}_updateHash(){const t=this._H,n=this._W;for(let d=16;d<64;d++)n[d]=fa(n[d-2])+n[d-7]+ua(n[d-15])+n[d-16];let i=t[0],s=t[1],o=t[2],r=t[3],l=t[4],c=t[5],a=t[6],h=t[7];for(let d=0,f,g;d<64;d++)f=h+da(l)+(l&c^~l&a)+ga[d]+n[d]>>>0,g=ha(i)+(i&s^i&o^s&o)>>>0,h=a,a=c,c=l,l=r+f>>>0,r=o,o=s,s=i,i=f+g>>>0;t[0]+=i,t[1]+=s,t[2]+=o,t[3]+=r,t[4]+=l,t[5]+=c,t[6]+=a,t[7]+=h}digest(t){let n=0;for(;n+56<=t.length;){let r=0;for(;r<16&&n+3<t.length;r++)this._W[r]=t[n++]<<24|t[n++]<<16|t[n++]<<8|t[n++];if(n%64!==0){for(this._W.fill(0,r,16);n<t.length;)this._W[r]|=t[n]<<(3-n%4)*8,n++;this._W[r]|=G<<(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 r=3;r>=0&&n<t.length;r--)this._W[s]|=t[n++]<<r*8;i||(this._W[s-(n%4===0?0:1)]|=G<<(3-n%4)*8),this._W[14]=t.byteLength/Ar,this._W[15]=t.byteLength*8,this._updateHash();const o=new Uint8Array(32);for(let r=0;r<this._H.length;r++)for(let l=0;l<4;l++)o[r*4+l]=this._H[r]>>>(3-l)*8;return o}}const xa=e=>new ma().digest(e),N=new E.PluginKey("y-sync"),yt=new E.PluginKey("y-undo");new E.PluginKey("yjs-cursor");const wa=e=>{for(let n=6;n<e.length;n++)e[n%6]=e[n%6]^e[n];return e.slice(0,6)},ba=e=>El(wa(xa(Il(e)))),Qe=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!ie(t.ds,e.id),ya=[{light:"#ecd44433",dark:"#ecd444"}],Sa=(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,ll(t))}return e.get(n)},ka=(e,{colors:t=ya,colorMapping:n=new Map,permanentUserData:i=null,onFirstRender:s=()=>{},mapping:o}={})=>{let r=!1;const l=new _a(e,o),c=new E.Plugin({props:{editable:a=>{const h=N.getState(a);return h.snapshot==null&&h.prevSnapshot==null}},key:N,state:{init:(a,h)=>({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,h)=>{const d=a.getMeta(N);if(d!==void 0){h=Object.assign({},h);for(const f in d)h[f]=d[f]}return h.addToHistory=a.getMeta("addToHistory")!==!1,h.isChangeOrigin=d!==void 0&&!!d.isChangeOrigin,h.isUndoRedoOperation=d!==void 0&&!!d.isChangeOrigin&&!!d.isUndoRedoOperation,l.prosemirrorView!==null&&d!==void 0&&(d.snapshot!=null||d.prevSnapshot!=null)&&ms(0,()=>{l.prosemirrorView!=null&&(d.restore==null?l._renderSnapshot(d.snapshot,d.prevSnapshot,h):(l._renderSnapshot(d.snapshot,d.snapshot,h),delete h.restore,delete h.snapshot,delete h.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),h}},view:a=>(l.initView(a),o==null&&l._forceRerender(),s(),{update:()=>{const h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(r||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(r=!0,h.addToHistory===!1&&!h.isChangeOrigin){const d=yt.getState(a.state),f=d&&d.undoManager;f&&f.stopCapturing()}l.mux(()=>{h.doc.transact(d=>{d.meta.set("addToHistory",h.addToHistory),l._prosemirrorChanged(a.state.doc)},N)})}},destroy:()=>{l.destroy()}})});return c},Ca=(e,t,n)=>{if(t!==null&&t.anchor!==null&&t.head!==null)if(t.type==="all")e.setSelection(new E.AllSelection(e.doc));else if(t.type==="node"){const i=he(n.doc,n.type,t.anchor,n.mapping);e.setSelection(va(e,i))}else{const i=he(n.doc,n.type,t.anchor,n.mapping),s=he(n.doc,n.type,t.head,n.mapping);i!==null&&s!==null&&e.setSelection(E.TextSelection.between(e.doc.resolve(i),e.doc.resolve(s)))}},va=(e,t)=>{const n=e.doc.resolve(t);return n.nodeAfter?E.NodeSelection.create(e.doc,t):E.TextSelection.near(n)},Hn=(e,t)=>({type:t.selection.jsonID,anchor:en(t.selection.anchor,e.type,e.mapping),head:en(t.selection.head,e.type,e.mapping)});class _a{constructor(t,n=new Map){this.type=t,this.prosemirrorView=null,this.mux=oa(),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=Hn(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()?(gs&&this._domSelectionInView===null&&(ms(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(),o=Tl.documentElement;return s.bottom>=0&&s.right>=0&&s.left<=(window.innerWidth||o.clientWidth||0)&&s.top<=(window.innerHeight||o.clientHeight||0)}renderSnapshot(t,n){n||(n=As(vs(),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=>Ve(i,this.prosemirrorView.state.schema,this)).filter(i=>i!==null),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new E.Slice(E.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=>Ve(s,this.prosemirrorView.state.schema,this)).filter(s=>s!==null),i=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new E.Slice(E.Fragment.from(n),0,0));if(t){const s=Zt(At(t.anchor,0),i.doc.content.size),o=Zt(At(t.head,0),i.doc.content.size);i.setSelection(E.TextSelection.create(i.doc,s,o))}this.prosemirrorView.dispatch(i.setMeta(N,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(t,n,i){let s=this.doc,o=this.type;if(t||(t=Cn(this.doc)),t instanceof Uint8Array||n instanceof Uint8Array)if((!(t instanceof Uint8Array)||!(n instanceof Uint8Array))&&Q(),s=new Ft({gc:!1}),Un(s,n),n=Cn(s),Un(s,t),t=Cn(s),o._item===null){const r=Array.from(this.doc.share.keys()).find(l=>this.doc.share.get(l)===this.type);o=s.getXmlFragment(r)}else{const r=s.store.clients.get(o._item.id.client)??[],l=dt(r,o._item.id.clock);o=r[l].content.type}this.mapping.clear(),this.mux(()=>{s.transact(r=>{const l=i.permanentUserData;l&&l.dss.forEach(d=>{Dt(r,d,f=>{})});const c=(d,f)=>{const g=d==="added"?l.getUserByClientId(f.client):l.getUserByDeletedId(f);return{user:g,type:d,color:Sa(i.colorMapping,i.colors,g)}},a=Ps(o,new si(n.ds,t.sv)).map(d=>!d._item.deleted||Qe(d._item,t)||Qe(d._item,n)?Ve(d,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},t,n,c):null).filter(d=>d!==null),h=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new E.Slice(E.Fragment.from(a),0,0));this.prosemirrorView.dispatch(h.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);Dt(n,n.deleteSet,l=>{if(l.constructor===T){const c=l.content.type;c&&this.mapping.delete(c)}}),n.changed.forEach(s),n.changedParentTypes.forEach(s);const o=this.type.toArray().map(l=>no(l,this.prosemirrorView.state.schema,this)).filter(l=>l!==null);let r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new E.Slice(E.Fragment.from(o),0,0));Ca(r,this.beforeTransactionSelection,this),r=r.setMeta(N,{isChangeOrigin:!0,isUndoRedoOperation:n.origin instanceof Rs}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&r.scrollIntoView(),this.prosemirrorView.dispatch(r)})}_prosemirrorChanged(t){this.doc.transact(()=>{zn(this.doc,this.type,t,this),this.beforeTransactionSelection=Hn(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 no=(e,t,n,i,s,o)=>{const r=n.mapping.get(e);if(r===void 0){if(e instanceof W)return Ve(e,t,n,i,s,o);throw ht()}return r},Ve=(e,t,n,i,s,o)=>{const r=[],l=c=>{var a,h;if(c instanceof W){const d=no(c,t,n,i,s,o);d!==null&&r.push(d)}else{const d=(h=(a=c._item.right)==null?void 0:a.content)==null?void 0:h.type;d instanceof Mt&&!d._item.deleted&&d._item.id.client===d.doc.clientID&&(c.applyDelta([{retain:c.length},...d.toDelta()]),d.doc.transact(g=>{d._item.delete(g)}));const f=Ea(c,t,n,i,s,o);f!==null&&f.forEach(g=>{g!==null&&r.push(g)})}};i===void 0||s===void 0?e.toArray().forEach(l):Ps(e,new si(s.ds,i.sv)).forEach(l);try{const c=e.getAttributes(i);i!==void 0&&(Qe(e._item,i)?Qe(e._item,s)||(c.ychange=o?o("added",e._item.id):{type:"added"}):c.ychange=o?o("removed",e._item.id):{type:"removed"});const a=t.node(e.nodeName,c,r);return n.mapping.set(e,a),a}catch{return e.doc.transact(a=>{e._item.delete(a)},N),n.mapping.delete(e),null}},Ea=(e,t,n,i,s,o)=>{const r=[],l=e.toDelta(i,s,o);try{for(let c=0;c<l.length;c++){const a=l[c];r.push(t.text(a.insert,Oa(a.attributes,t)))}}catch{return e.doc.transact(a=>{e._item.delete(a)},N),null}return r},Ia=(e,t)=>{const n=new Z,i=e.map(s=>({insert:s.text,attributes:so(s.marks,t)}));return n.applyDelta(i),t.mapping.set(n,e),n},Aa=(e,t)=>{const n=new W(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,dn(e).map(i=>$n(i,t))),t.mapping.set(n,e),n},$n=(e,t)=>e instanceof Array?Ia(e,t):Aa(e,t),qi=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 o=n[s],r=e[o],l=t[o];i=o==="ychange"||r===l||qi(r)&&qi(l)&&hi(r,l)}return i},dn=e=>{const t=e.content.content,n=[];for(let i=0;i<t.length;i++){const s=t[i];if(s.isText){const o=[];for(let r=t[i];i<t.length&&r.isText;r=t[++i])o.push(r);i--,n.push(o)}else n.push(s)}return n},io=(e,t)=>{const n=e.toDelta();return n.length===t.length&&n.every((i,s)=>i.insert===t[s].text&&ds(i.attributes||{}).length===t[s].marks.length&&us(i.attributes,(o,r)=>{var h;const l=di(r),c=t[s].marks;return c.find(d=>d.type.name===l)?hi(o,(h=c.find(d=>d.type.name===l))==null?void 0:h.attrs):!1}))},ye=(e,t)=>{if(e instanceof W&&!(t instanceof Array)&&qn(e,t)){const n=dn(t);return e._length===n.length&&hi(e.getAttributes(),t.attrs)&&e.toArray().every((i,s)=>ye(i,n[s]))}return e instanceof Z&&t instanceof Array&&io(e,t)},tn=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((n,i)=>t[i]===n),Ki=(e,t,n)=>{const i=e.toArray(),s=dn(t),o=s.length,r=i.length,l=Zt(r,o);let c=0,a=0,h=!1;for(;c<l;c++){const d=i[c],f=s[c];if(tn(n.mapping.get(d),f))h=!0;else if(!ye(d,f))break}for(;c+a<l;a++){const d=i[r-a-1],f=s[o-a-1];if(tn(n.mapping.get(d),f))h=!0;else if(!ye(d,f))break}return{equalityFactor:c+a,foundMappedChild:h}},Ta=e=>{let t="",n=e._start;const i={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof ut?t+=n.content.str:n.content instanceof F&&(i[n.content.key]=null)),n=n.right;return{str:t,nAttrs:i}},Da=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:i,str:s}=Ta(e),o=t.map(a=>({insert:a.text,attributes:Object.assign({},i,so(a.marks,n))})),{insert:r,remove:l,index:c}=aa(s,o.map(a=>a.insert).join(""));e.delete(c,l),e.insert(c,r),e.applyDelta(o.map(a=>({retain:a.insert.length,attributes:a.attributes})))},Ma=/(.*)(--[a-zA-Z0-9+/=]{8})$/,di=e=>{var t;return((t=Ma.exec(e))==null?void 0:t[1])??e},Oa=(e,t)=>{const n=[];for(const i in e)n.push(t.mark(di(i),e[i]));return n},so=(e,t)=>{const n={};return e.forEach(i=>{if(i.type.name!=="ychange"){const s=kt(t.isOMark,i.type,()=>!i.type.excludes(i.type));n[s?`${i.type.name}--${ba(i.toJSON())}`:i.type.name]=i.attrs}}),n},zn=(e,t,n,i)=>{if(t instanceof W&&t.nodeName!==n.type.name)throw new Error("node name mismatch!");if(i.mapping.set(t,n),t instanceof W){const d=t.getAttributes(),f=n.attrs;for(const g in f)f[g]!==null?d[g]!==f[g]&&g!=="ychange"&&t.setAttribute(g,f[g]):t.removeAttribute(g);for(const g in d)f[g]===void 0&&t.removeAttribute(g)}const s=dn(n),o=s.length,r=t.toArray(),l=r.length,c=Zt(o,l);let a=0,h=0;for(;a<c;a++){const d=r[a],f=s[a];if(!tn(i.mapping.get(d),f))if(ye(d,f))i.mapping.set(d,f);else break}for(;h+a+1<c;h++){const d=r[l-h-1],f=s[o-h-1];if(!tn(i.mapping.get(d),f))if(ye(d,f))i.mapping.set(d,f);else break}e.transact(()=>{for(;l-a-h>0&&o-a-h>0;){const f=r[a],g=s[a],p=r[l-h-1],m=s[o-h-1];if(f instanceof Z&&g instanceof Array)io(f,g)||Da(f,g,i),a+=1;else{let x=f instanceof W&&qn(f,g),b=p instanceof W&&qn(p,m);if(x&&b){const D=Ki(f,g,i),M=Ki(p,m,i);D.foundMappedChild&&!M.foundMappedChild?b=!1:!D.foundMappedChild&&M.foundMappedChild||D.equalityFactor<M.equalityFactor?x=!1:b=!1}x?(zn(e,f,g,i),a+=1):b?(zn(e,p,m,i),h+=1):(i.mapping.delete(t.get(a)),t.delete(a,1),t.insert(a,[$n(g,i)]),a+=1)}}const d=l-a-h;if(l===1&&o===0&&r[0]instanceof Z?(i.mapping.delete(r[0]),r[0].delete(0,r[0].length)):d>0&&(t.slice(a,a+d).forEach(f=>i.mapping.delete(f)),t.delete(a,d)),a+h<o){const f=[];for(let g=a;g<o-h;g++)f.push($n(s[g],i));t.insert(a,f)}},N)},qn=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,en=(e,t,n)=>{if(e===0)return kn(t,0,-1);let i=t._first===null?null:t._first.content.type;for(;i!==null&&t!==i;){if(i instanceof Z){if(i._length>=e)return kn(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 We(i._item===null?null:i._item.id,i._item===null?pe(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 We(i._item===null?null:i._item.id,i._item===null?pe(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 Q();if(e===0&&i.constructor!==Z&&i!==t)return Ra(i._item.parent,i._item)}return kn(t,t._length,-1)},Ra=(e,t)=>{let n=null,i=null;return e._item===null?i=pe(e):n=_(e._item.id.client,e._item.id.clock),new We(n,i,t.id)},he=(e,t,n,i)=>{const s=oc(n,e);if(s===null||s.type!==t&&!me(t,s.type._item))return null;let o=s.type,r=0;if(o.constructor===Z)r=s.index;else if(o._item===null||!o._item.deleted){let l=o._first,c=0;for(;c<o._length&&c<s.index&&l!==null;){if(!l.deleted){const a=l.content.type;c++,a instanceof Z?r+=a._length:r+=i.get(a).nodeSize}l=l.right}r+=1}for(;o!==t&&o._item!==null;){const l=o._item.parent;if(l._item===null||!l._item.deleted){r+=1;let c=l._first;for(;c!==null;){const a=c.content.type;if(a===o)break;c.deleted||(a instanceof Z?r+=a._length:r+=i.get(a).nodeSize),c=c.right}}o=l}return r-1};function ja(e){const t=e.toArray(),n=i=>{let s;if(i instanceof Z)s=i.toDelta().map(r=>{const l={type:"text",text:r.insert};return r.attributes&&(l.marks=Object.keys(r.attributes).map(c=>{const a=r.attributes[c],d={type:di(c)};return Object.keys(a)&&(d.attrs=a),d})),l});else if(i instanceof W){s={type:i.nodeName};const o=i.getAttributes();Object.keys(o).length&&(s.attrs=o);const r=i.toArray();r.length&&(s.content=r.map(n).flat())}else Q();return s};return{type:"doc",content:t.map(n)}}const Na=e=>{const t=yt.getState(e).undoManager;if(t!=null)return t.undo(),!0},Ba=e=>{const t=yt.getState(e).undoManager;if(t!=null)return t.redo(),!0},Ua=new Set(["paragraph"]),La=(e,t)=>!(e instanceof T)||!(e.content instanceof ft)||!(e.content.type instanceof Mt||e.content.type instanceof W&&t.has(e.content.type.nodeName))||e.content.type._length===0,Pa=({protectedNodes:e=Ua,trackedOrigins:t=[],undoManager:n=null}={})=>new E.Plugin({key:yt,state:{init:(i,s)=>{const o=N.getState(s),r=n||new Rs(o.type,{trackedOrigins:new Set([N].concat(t)),deleteFilter:l=>La(l,e),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:r,prevSel:null,hasUndoOps:r.undoStack.length>0,hasRedoOps:r.redoStack.length>0}},apply:(i,s,o,r)=>{const l=N.getState(r).binding,c=s.undoManager,a=c.undoStack.length>0,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:Hn(l,o),hasUndoOps:a,hasRedoOps:h}:a!==s.hasUndoOps||h!==s.hasRedoOps?Object.assign({},s,{hasUndoOps:c.undoStack.length>0,hasRedoOps:c.redoStack.length>0}):s}},view:i=>{const s=N.getState(i.state),o=yt.getState(i.state).undoManager;return o.on("stack-item-added",({stackItem:r})=>{const l=s.binding;l&&r.meta.set(l,yt.getState(i.state).prevSel)}),o.on("stack-item-popped",({stackItem:r})=>{const l=s.binding;l&&(l.beforeTransactionSelection=r.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{o.destroy()}}}});function oo(e){return!!e.getMeta(N)}function Va(e,t){const n=N.getState(e);return he(n.doc,n.type,t,n.binding.mapping)||0}function ro(e,t){const n=N.getState(e);return en(t,n.type,n.binding.mapping)}var Fe=class lo extends E.MappablePosition{constructor(t,n){super(t),this.yRelativePosition=n}static fromJSON(t){return new lo(t.position,t.yRelativePosition)}toJSON(){return{position:this.position,yRelativePosition:this.yRelativePosition}}};function Fa(e,t){const n=ro(t,e);return new Fe(e,n)}function Ha(e,t,n){const i=e instanceof Fe?e.yRelativePosition:null;if(oo(t)&&i){const r=Va(n,i);return{position:new Fe(r,i),mapResult:null}}const s=E.getUpdatedPosition(e,t),o=s.position.position;return{position:new Fe(o,i??ro(n,o)),mapResult:s.mapResult}}E.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)=>Ha(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>Fa(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),yt.getState(t).undoManager.undoStack.length===0?!1:n?Na(t):!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),yt.getState(t).undoManager.redoStack.length===0?!1:n?Ba(t):!0)}},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo()}},addProseMirrorPlugins(){var e;const t=this.options.fragment?this.options.fragment:this.options.document.getXmlFragment(this.options.field),n=Pa(this.options.yUndoOptions),i=n.spec.view;n.spec.view=r=>{const{undoManager:l}=yt.getState(r.state);l.restore&&(l.restore(),l.restore=()=>{});const c=i?i(r):void 0;return{destroy:()=>{const a=l.trackedOrigins.has(l),h=l._observers;l.restore=()=>{a&&l.trackedOrigins.add(l),l.doc.on("afterTransaction",l.afterTransactionHandler),l._observers=h},c!=null&&c.destroy&&c.destroy()}}};const s={...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender},o=ka(t,s);return this.editor.options.enableContentCheck&&((e=t.doc)==null||e.on("beforeTransaction",()=>{try{const r=ja(t);if(r.content.length===0)return;this.editor.schema.nodeFromJSON(r).check()}catch(r){return this.editor.emit("contentError",{error:r,editor:this.editor,disableCollaboration:()=>{var l;(l=t.doc)==null||l.destroy(),this.storage.isDisabled=!0}}),!1}})),[o,n,this.editor.options.enableContentCheck&&new J.Plugin({key:new J.PluginKey("filterInvalidContent"),filterTransaction:()=>{var r;return this.storage.isDisabled!==!1&&((r=t.doc)==null||r.destroy()),!0}})].filter(Boolean)}});function Wi(e){if(!e.length)return pn.DecorationSet.empty;const t=[],n=e[0].$from.node(0);return e.forEach(i=>{const s=i.$from.pos,o=i.$from.nodeAfter;o&&t.push(pn.Decoration.node(s,s+o.nodeSize,{class:"ProseMirror-selectednoderange"}))}),pn.DecorationSet.create(n,t)}function un(e,t,n){const i=[],s=e.node(0);typeof n=="number"&&n>=0||(e.sameParent(t)?n=Math.max(0,e.sharedDepth(t.pos)-1):n=e.sharedDepth(t.pos));const o=new jo.NodeRange(e,t,n),r=o.depth===0?0:s.resolve(o.start).posAtIndex(0);return o.parent.forEach((l,c)=>{const a=r+c,h=a+l.nodeSize;if(a<o.start||a>=o.end)return;const d=new J.SelectionRange(s.resolve(a),s.resolve(h));i.push(d)}),i}var $a=class co{constructor(t,n){this.anchor=t,this.head=n}map(t){return new co(t.map(this.anchor),t.map(this.head))}resolve(t){const n=t.resolve(this.anchor),i=t.resolve(this.head);return new Et(n,i)}},Et=class vt extends J.Selection{constructor(t,n,i,s=1){const{doc:o}=t,r=t===n,l=t.pos===o.content.size&&n.pos===o.content.size,c=r&&!l?o.resolve(n.pos+(s>0?1:-1)):n,a=r&&l?o.resolve(t.pos-(s>0?1:-1)):t,h=un(a.min(c),a.max(c),i),d=c.pos>=t.pos?h[0].$from:h[h.length-1].$to,f=c.pos>=t.pos?h[h.length-1].$to:h[0].$from;super(d,f,h),this.depth=i}get $to(){return this.ranges[this.ranges.length-1].$to}eq(t){return t instanceof vt&&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 vt(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),o=s[0].$from,r=s[s.length-1].$to;return new vt(o,r,this.depth)}const n=this.ranges[0],i=t.resolve(Math.max(0,n.$from.pos-1));return new vt(this.$anchor,i,this.depth)}extendForwards(){const{doc:t}=this.$from;if(this.isBackwards&&this.ranges.length>1){const s=this.ranges.slice(1),o=s[0].$from,r=s[s.length-1].$to;return new vt(r,o,this.depth)}const n=this.ranges[this.ranges.length-1],i=t.resolve(Math.min(t.content.size,n.$to.pos+1));return new vt(this.$anchor,i,this.depth)}static fromJSON(t,n){return new vt(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,i,s,o=1){return new this(t.resolve(n),t.resolve(i),s,o)}getBookmark(){return new $a(this.anchor,this.head)}};Et.prototype.visible=!1;function Me(e){return e instanceof Et}E.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:o,tr:r}=i,{anchor:l,head:c}=o;if(!Me(o)){const h=Et.create(s,l,c,t,-1);return r.setSelection(h),n.dispatch(r),!0}const a=o.extendBackwards();return r.setSelection(a),n.dispatch(r),!0},"Shift-ArrowDown":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,selection:o,tr:r}=i,{anchor:l,head:c}=o;if(!Me(o)){const h=Et.create(s,l,c,t);return r.setSelection(h),n.dispatch(r),!0}const a=o.extendForwards();return r.setSelection(a),n.dispatch(r),!0},"Mod-a":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,tr:o}=i,r=Et.create(s,0,s.content.size,t);return o.setSelection(r),n.dispatch(o),!0}}},onSelectionUpdate(){const{selection:e}=this.editor.state;Me(e)&&this.editor.view.dom.classList.add("ProseMirror-noderangeselection")},addProseMirrorPlugins(){let e=!1,t=!1;return[new J.Plugin({key:new J.PluginKey("nodeRange"),props:{attributes:()=>e?{class:"ProseMirror-noderangeselection"}:{class:""},handleDOMEvents:{mousedown:(n,i)=>{const{key:s}=this.options,o=/Mac/.test(navigator.platform),r=!!i.shiftKey,l=!!i.ctrlKey,c=!!i.altKey,a=!!i.metaKey,h=o?a:l;return(s==null||s==="Shift"&&r||s==="Control"&&l||s==="Alt"&&c||s==="Meta"&&a||s==="Mod"&&h)&&(t=!0),t&&document.addEventListener("mouseup",()=>{t=!1;const{state:d}=n,{doc:f,selection:g,tr:p}=d,{$anchor:m,$head:x}=g;if(m.sameParent(x))return;const b=Et.create(f,m.pos,x.pos,this.options.depth);p.setSelection(b),n.dispatch(p)},{once:!0}),!1}},decorations:n=>{const{selection:i}=n,s=Me(i);if(e=!1,!t)return s?(e=!0,Wi(i.ranges)):null;const{$from:o,$to:r}=i;if(!s&&o.sameParent(r))return null;const l=un(o,r,this.options.depth);return l.length?(e=!0,Wi(l)):null}}})]}});function za(e){let t="";const n=getComputedStyle(e);for(let i=0;i<n.length;i+=1)t+=`${n[i]}:${n.getPropertyValue(n[i])};`;return t}function qa(e){const t=e.cloneNode(!0),n=[e,...Array.from(e.getElementsByTagName("*"))],i=[t,...Array.from(t.getElementsByTagName("*"))];return n.forEach((s,o)=>{i[o].style.cssText=za(s)}),t}function Ka(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 Wa(e,t,n,i=5){const s=e.dom,o=s.firstElementChild,r=s.lastElementChild;if(!o||!r)return{x:t,y:n};const l=o.getBoundingClientRect(),c=r.getBoundingClientRect(),a=Math.min(Math.max(l.top+i,n),c.bottom-i),h=.5,d=Math.abs(l.left-c.left)<h,f=Math.abs(l.right-c.right)<h;let g=l;return d&&f&&(g=l),{x:Math.min(Math.max(g.left+i,t),g.right-i),y:a}}var ao=e=>{const{x:t,y:n,editor:i}=e,{view:s,state:o}=i,{x:r,y:l}=Wa(s,t,n,5),c=s.root.elementsFromPoint(r,l);let a;if(Array.prototype.some.call(c,f=>{if(!s.dom.contains(f))return!1;const g=Ka(f,s);return g?(a=g,!0):!1}),!a)return{resultElement:null,resultNode:null,pos:null};let h;try{h=s.posAtDOM(a,0)}catch{return{resultElement:null,resultNode:null,pos:null}}const d=o.doc.nodeAt(h);if(!d){const f=o.doc.resolve(h),g=f.parent;return{resultElement:a,resultNode:g,pos:f.start()}}return{resultElement:a,resultNode:d,pos:h}};function Oe(e,t){return window.getComputedStyle(e)[t]}function Ya(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function Ga(e,t,n){const i=parseInt(Oe(e.dom,"paddingLeft"),10),s=parseInt(Oe(e.dom,"paddingRight"),10),o=parseInt(Oe(e.dom,"borderLeftWidth"),10),r=parseInt(Oe(e.dom,"borderLeftWidth"),10),l=e.dom.getBoundingClientRect();return{left:Ya(t,l.left+i+o,l.right-s-r),top:n}}function ho(e){var t;(t=e.parentNode)==null||t.removeChild(e)}function Ja(e,t){const{doc:n}=t.view.state,i=ao({editor:t,x:e.clientX,y:e.clientY});if(!i.resultNode||i.pos===null)return[];const s=e.clientX,o=Ga(t.view,s,e.clientY),r=t.view.posAtCoords(o);if(!r)return[];const{pos:l}=r;if(!n.resolve(l).parent)return[];const a=n.resolve(i.pos),h=n.resolve(i.pos+1);return un(a,h,0)}function Xa(e,t){const{view:n}=t;if(!e.dataTransfer)return;const{empty:i,$from:s,$to:o}=n.state.selection,r=Ja(e,t),l=un(s,o,0),c=l.some(x=>r.find(b=>b.$from===x.$from&&b.$to===x.$to)),a=i||!c?r:l;if(!a.length)return;const{tr:h}=n.state,d=document.createElement("div"),f=a[0].$from.pos,g=a[a.length-1].$to.pos,p=Et.create(n.state.doc,f,g),m=p.content();a.forEach(x=>{const b=n.nodeDOM(x.$from.pos),D=qa(b);d.append(D)}),d.style.position="absolute",d.style.top="-10000px",document.body.append(d),e.dataTransfer.clearData(),e.dataTransfer.setDragImage(d,0,0),n.dragging={slice:m,move:!0},h.setSelection(p),n.dispatch(h),document.addEventListener("drop",()=>ho(d),{once:!0})}var Yi=(e,t)=>{const n=e.resolve(t),{depth:i}=n;return i===0?t:n.pos-n.parentOffset-1},Gi=(e,t)=>{const n=e.nodeAt(t),i=e.resolve(t);let{depth:s}=i,o=n;for(;s>0;){const r=i.node(s);s-=1,s===0&&(o=r)}return o},En=(e,t)=>{const n=N.getState(e);return n?en(t,n.type,n.binding.mapping):null},Za=(e,t)=>{const n=N.getState(e);return n?he(n.doc,n.type,t,n.binding.mapping)||0:-1},Ji=(e,t)=>{let n=t;for(;n!=null&&n.parentNode&&n.parentNode!==e.dom;)n=n.parentNode;return n},uo=new J.PluginKey("dragHandle"),fo=({pluginKey:e=uo,element:t,editor:n,computePositionConfig:i,getReferencedVirtualElement:s,onNodeChange:o,onElementDragStart:r,onElementDragEnd:l})=>{const c=document.createElement("div");let a=!1,h=null,d=-1,f,g=null,p=null;function m(){t&&(t.style.visibility="hidden",t.style.pointerEvents="none")}function x(){if(t){if(!n.isEditable){m();return}t.style.visibility="",t.style.pointerEvents="auto"}}function b(C){const B=(s==null?void 0:s())||{getBoundingClientRect:()=>C.getBoundingClientRect()};H.computePosition(B,t,i).then(I=>{Object.assign(t.style,{position:I.strategy,left:`${I.x}px`,top:`${I.y}px`})})}function D(C){r==null||r(C),Xa(C,n),t&&(t.dataset.dragging="true"),setTimeout(()=>{t&&(t.style.pointerEvents="none")},0)}function M(C){l==null||l(C),m(),t&&(t.style.pointerEvents="auto",t.dataset.dragging="false")}return t.addEventListener("dragstart",D),t.addEventListener("dragend",M),c.appendChild(t),{unbind(){t.removeEventListener("dragstart",D),t.removeEventListener("dragend",M),g&&(cancelAnimationFrame(g),g=null,p=null)},plugin:new J.Plugin({key:typeof e=="string"?new J.PluginKey(e):e,state:{init(){return{locked:!1}},apply(C,B,I,S){const k=C.getMeta("lockDragHandle"),j=C.getMeta("hideDragHandle");if(k!==void 0&&(a=k),j)return m(),a=!1,h=null,d=-1,o==null||o({editor:n,node:null,pos:-1}),B;if(C.docChanged&&d!==-1&&t)if(oo(C)){const $=Za(S,f);$!==d&&(d=$)}else{const $=C.mapping.map(d);$!==d&&(d=$,f=En(S,d))}return B}},view:C=>{var B;return t.draggable=!0,t.style.pointerEvents="auto",t.dataset.dragging="false",(B=n.view.dom.parentElement)==null||B.appendChild(c),c.style.pointerEvents="none",c.style.position="absolute",c.style.top="0",c.style.left="0",{update(I,S){if(!t)return;if(!n.isEditable){m();return}if(a?t.draggable=!1:t.draggable=!0,C.state.doc.eq(S.doc)||d===-1)return;let k=C.nodeDOM(d);if(k=Ji(C,k),k===C.dom||(k==null?void 0:k.nodeType)!==1)return;const j=C.posAtDOM(k,0),$=Gi(n.state.doc,j),st=Yi(n.state.doc,j);h=$,d=st,f=En(C.state,d),o==null||o({editor:n,node:h,pos:d}),b(k)},destroy(){g&&(cancelAnimationFrame(g),g=null,p=null),t&&ho(c)}}},props:{handleDOMEvents:{keydown(C){return!t||a||C.hasFocus()&&(m(),h=null,d=-1,o==null||o({editor:n,node:null,pos:-1})),!1},mouseleave(C,B){return a||B.target&&!c.contains(B.relatedTarget)&&(m(),h=null,d=-1,o==null||o({editor:n,node:null,pos:-1})),!1},mousemove(C,B){return!t||a||(p={x:B.clientX,y:B.clientY},g)||(g=requestAnimationFrame(()=>{if(g=null,!p)return;const{x:I,y:S}=p;p=null;const k=ao({x:I,y:S,editor:n});if(!k.resultElement)return;let j=k.resultElement;if(j=Ji(C,j),j===C.dom||(j==null?void 0:j.nodeType)!==1)return;const $=C.posAtDOM(j,0),st=Gi(n.state.doc,$);if(st!==h){const Ot=Yi(n.state.doc,$);h=st,d=Ot,f=En(C.state,d),o==null||o({editor:n,node:h,pos:d}),b(j),x()}})),!1}}}})}},Kn={placement:"left-start",strategy:"absolute"};E.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}},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();return[fo({computePositionConfig:{...Kn,...this.options.computePositionConfig},getReferencedVirtualElement:this.options.getReferencedVirtualElement,element:e,editor:this.editor,onNodeChange:this.options.onNodeChange,onElementDragStart:this.options.onElementDragStart,onElementDragEnd:this.options.onElementDragEnd}).plugin]}});var Qa=e=>{const{className:t="drag-handle",children:n,editor:i,pluginKey:s=uo,onNodeChange:o,onElementDragStart:r,onElementDragEnd:l,computePositionConfig:c=Kn}=e,[a,h]=w.useState(null),d=w.useRef(null);return w.useEffect(()=>{let f=null;return a?i.isDestroyed?()=>{d.current=null}:(d.current||(f=fo({editor:i,element:a,pluginKey:s,computePositionConfig:{...Kn,...c},onElementDragStart:r,onElementDragEnd:l,onNodeChange:o}),d.current=f.plugin,i.registerPlugin(d.current)),()=>{i.unregisterPlugin(s),d.current=null,f&&(f.unbind(),f=null)}):()=>{d.current=null}},[a,i,o,s,c,r,l]),u.jsx("div",{className:t,style:{visibility:"hidden",position:"absolute"},"data-dragging":"false",ref:h,children:n})},th=Qa;function eh(){var I,S,k,j,$,st,Ot,Rt;const e=K.useEditorInstance(),t=tt.useEditableEditor(),{t:n}=V.useLocale(),[i,s]=w.useState(null),[o,r]=w.useState(-1),[l,c]=w.useState(!1),a=(S=(I=e==null?void 0:e.extensionManager)==null?void 0:I.extensions)==null?void 0:S.some(v=>(v==null?void 0:v.name)===ts.TextAlign.name),h=(j=(k=e==null?void 0:e.extensionManager)==null?void 0:k.extensions)==null?void 0:j.some(v=>(v==null?void 0:v.name)===oe.Indent.name),d=(st=($=e==null?void 0:e.extensionManager)==null?void 0:$.extensions)==null?void 0:st.some(v=>(v==null?void 0:v.name)===No.Clear.name);function f(){const v=e.chain();v.setNodeSelection(o).unsetAllMarks(),(i==null?void 0:i.type.name)!=="paragraph"&&v.setParagraph(),v.run()}function g(){e.chain().focus().setNodeSelection(o).run(),document.execCommand("copy")}function p(){e.commands.setNodeSelection(o);const{$anchor:v}=e.state.selection,xt=v.node(1)||e.state.selection.node;e.chain().setMeta("hideDragHandle",!0).insertContentAt(o+((i==null?void 0:i.nodeSize)||0),xt.toJSON()).run()}function m(v){e.commands.setTextAlign(v)}function x(){const v=oe.setNodeIndentMarkup(e.state.tr,o,1);v.setMeta("hideDragHandle",!0),e.view.dispatch&&e.view.dispatch(v)}function b(){const v=oe.setNodeIndentMarkup(e.state.tr,o,-1);e.view.dispatch&&e.view.dispatch(v)}function D(){e.chain().setMeta("hideDragHandle",!0).setNodeSelection(o).deleteSelection().run()}const M=w.useCallback(v=>{v.node&&s(v.node),r(v.pos),requestAnimationFrame(()=>{v.editor.commands.focus()})},[]),C=v=>{var xt;if(v.preventDefault(),o!==-1){const Ee=(i==null?void 0:i.nodeSize)||0,$t=o+Ee,ui=(i==null?void 0:i.type.name)==="paragraph"&&((xt=i==null?void 0:i.content)==null?void 0:xt.size)===0,go=ui?o+2:$t+2;e.chain().command(({dispatch:fi,tr:fn,state:gi})=>fi?(ui?fn.insertText("/",o,o+1):fn.insert($t,gi.schema.nodes.paragraph.create(null,[gi.schema.text("/")])),fi(fn)):!0).focus(go).run()}};w.useEffect(()=>(l?e.commands.setMeta("lockDragHandle",!0):e.commands.setMeta("lockDragHandle",!1),()=>{e.commands.setMeta("lockDragHandle",!1)}),[l]);const B=v=>{t&&c(v)};return u.jsx(th,{className:"richtext-transition-all richtext-duration-200 richtext-ease-out",editor:e,onNodeChange:M,pluginKey:"RichTextBubbleMenuDragHandle",children:u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-0.5",children:[u.jsx(y.ActionButton,{action:C,disabled:!t,icon:"Plus",tooltip:"Insert block"}),u.jsx(y.ActionButton,{disabled:!t,icon:"Grip",tooltip:"Click for options, Hold for drag",action:v=>{v.preventDefault(),v.stopPropagation(),B(!l)}}),u.jsxs(U.DropdownMenu,{onOpenChange:B,open:l,children:[u.jsx(U.DropdownMenuTrigger,{className:"richtext-pointer-events-none"}),u.jsxs(U.DropdownMenuContent,{align:"start",className:"richtext-w-48",hideWhenDetached:!0,side:"bottom",sideOffset:0,children:[u.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:D,children:[u.jsx(et.IconComponent,{name:"Trash2"}),u.jsx("span",{children:n("editor.remove")})]}),d?u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:f,children:[u.jsx(et.IconComponent,{name:"PaintRoller"}),u.jsx("span",{children:n("editor.clear.tooltip")})]}):null,u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:g,children:[u.jsx(et.IconComponent,{name:"Clipboard"}),u.jsx("span",{children:n("editor.copyToClipboard")})]}),u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:p,children:[u.jsx(et.IconComponent,{name:"Copy"}),u.jsx("span",{children:n("editor.copy")})]}),a||h?u.jsx(U.DropdownMenuSeparator,{}):null,a?u.jsxs(U.DropdownMenuSub,{children:[u.jsxs(U.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[u.jsx(et.IconComponent,{name:"AlignCenter"}),u.jsx("span",{children:n("editor.textalign.tooltip")})]}),u.jsx(U.DropdownMenuPortal,{children:u.jsxs(U.DropdownMenuSubContent,{children:[u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>m("left"),children:[u.jsx(et.IconComponent,{name:"AlignLeft"}),u.jsx("span",{children:n("editor.textalign.left.tooltip")})]}),u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>m("center"),children:[u.jsx(et.IconComponent,{name:"AlignCenter"}),u.jsx("span",{children:n("editor.textalign.center.tooltip")})]}),u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>m("right"),children:[u.jsx(et.IconComponent,{name:"AlignRight"}),u.jsx("span",{children:n("editor.textalign.right.tooltip")})]})]})})]}):null,h?u.jsxs(U.DropdownMenuSub,{children:[u.jsxs(U.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[u.jsx(et.IconComponent,{name:"IndentIncrease"}),u.jsx("span",{children:n("editor.indent")})]}),u.jsx(U.DropdownMenuPortal,{children:u.jsxs(U.DropdownMenuSubContent,{children:[u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((Ot=i==null?void 0:i.attrs)==null?void 0:Ot.indent)>=oe.IndentProps.max,onClick:x,children:[u.jsx(et.IconComponent,{name:"IndentIncrease"}),u.jsx("span",{children:n("editor.indent.tooltip")})]}),u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((Rt=i==null?void 0:i.attrs)==null?void 0:Rt.indent)<=oe.IndentProps.min,onClick:b,children:[u.jsx(et.IconComponent,{name:"IndentDecrease"}),u.jsx("span",{children:n("editor.outdent.tooltip")})]})]})})]}):null]})]})]})})}exports.RichTextBubbleColumns=Po;exports.RichTextBubbleDrawer=er;exports.RichTextBubbleExcalidraw=ir;exports.RichTextBubbleIframe=sr;exports.RichTextBubbleImage=ur;exports.RichTextBubbleImageGif=fr;exports.RichTextBubbleKatex=rr;exports.RichTextBubbleLink=cr;exports.RichTextBubbleMenuDragHandle=eh;exports.RichTextBubbleMermaid=wr;exports.RichTextBubbleTable=br;exports.RichTextBubbleText=kr;exports.RichTextBubbleTwitter=Cr;exports.RichTextBubbleVideo=gr;
1
+ "use strict";var xo=Object.create;var xi=Object.defineProperty;var wo=Object.getOwnPropertyDescriptor;var bo=Object.getOwnPropertyNames;var yo=Object.getPrototypeOf,So=Object.prototype.hasOwnProperty;var Co=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of bo(t))!So.call(e,s)&&s!==n&&xi(e,s,{get:()=>t[s],enumerable:!(i=wo(t,s))||i.enumerable});return e};var ko=(e,t,n)=>(n=e!=null?xo(yo(e)):{},Co(t||!e||!e.__esModule?xi(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-runtime"),x=require("react"),E=require("./clsx-CXbNJWDD.cjs"),H=require("./index-Cs6cp0Y6.cjs"),J=require("@tiptap/pm/state"),Qi=require("./Table-kY0nbqJo.cjs"),ts=require("react-dom"),y=require("./toggle-BQHMh_Q-.cjs"),O=require("./dialog-Bt5zwGYB.cjs"),ce=require("./select-CwGYPsPq.cjs"),Ae=require("./Callout.cjs"),at=require("./Katex-DW_HjgNM.cjs"),U=require("./index-Doks9cbR.cjs"),$=require("./useButtonProps-DBJkNDS2.cjs"),X=require("./index-D3RLYf-J.cjs"),se=require("./delete-node-CosiBes5.cjs"),It=require("./label-JNOksCA-.cjs"),Yt=require("./input-Dt_BA_9B.cjs"),At=require("./button-BS3n6_Aq.cjs"),wi=require("./Column.cjs");require("./theme.cjs");const Be=require("./Drawer-DKU32YW_.cjs"),bi=require("easydrawer"),ze=require("./shortId-Bfj8TyNr.cjs"),es=require("./file-i7e4nQY2.cjs"),Tt=require("./separator-NoH_SLRW.cjs"),Gt=require("./popover-mL-2sX5r.cjs"),Kt=require("./Excalidraw-Kb-TRcWY.cjs"),Wt=require("./Iframe-BczF8Hex.cjs"),vo=require("katex"),qe=require("lucide-react"),An=require("./textarea-BDO6XQoF.cjs"),Le=require("./LinkEditBlock-DL1e2ILk.cjs"),_o=require("./Image.cjs"),Eo=require("./ImageGif.cjs"),Io=require("./Video.cjs"),Dn=require("./Mermaid.cjs"),To=require("./Bold.cjs"),Ao=require("./Code.cjs");require("./index-CjhjjJsN.cjs");const Do=require("./Color.cjs"),Mo=require("./Highlight.cjs"),jo=require("./Italic.cjs"),Oo=require("./SlashCommandNodeView-BqrmHCpu.cjs"),Ro=require("./Strike.cjs"),ns=require("./TextAlign.cjs"),No=require("./TextUnderline.cjs"),nt=require("./Icon-yqCglrdK.cjs"),mn=require("./Twitter-DjZcVa3l.cjs"),xn=require("@tiptap/pm/view"),Bo=require("@tiptap/pm/model"),Lo=require("./Clear.cjs"),ae=require("./Indent-CkEC7x36.cjs"),P=require("./dropdown-menu-Bo68IEOT.cjs");function Uo(e,t){const n=Math.min(e.top,t.top),i=Math.max(e.bottom,t.bottom),s=Math.min(e.left,t.left),r=Math.max(e.right,t.right)-s,l=i-n,c=s,a=n;return new DOMRect(c,a,r,l)}var Po=class{constructor({editor:e,element:t,view:n,updateDelay:i=250,resizeDelay:s=60,shouldShow:o,appendTo:r,getReferencedVirtualElement:l,options:c}){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:d,from:f,to:g})=>{const{doc:p,selection:m}=d,{empty:w}=m,b=!p.textBetween(f,g).length&&E.isTextSelection(d.selection),I=this.element.contains(document.activeElement);return!(!(h.hasFocus()||I)||w||b||!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 d;if(this.editor.isDestroyed){this.destroy();return}if(this.preventHide){this.preventHide=!1;return}h!=null&&h.relatedTarget&&((d=this.element.parentNode)!=null&&d.contains(h.relatedTarget))||(h==null?void 0:h.relatedTarget)!==this.editor.view.dom&&this.hide()},this.handleDebouncedUpdate=(h,d)=>{const f=!(d!=null&&d.selection.eq(h.state.selection)),g=!(d!=null&&d.doc.eq(h.state.doc));!f&&!g||(this.updateDebounceTimer&&clearTimeout(this.updateDebounceTimer),this.updateDebounceTimer=window.setTimeout(()=>{this.updateHandler(h,f,g,d)},this.updateDelay))},this.updateHandler=(h,d,f,g)=>{const{composing:p}=h;if(p||!d&&!f)return;if(!this.getShouldShow(g)){this.hide();return}this.updatePosition(),this.show()},this.transactionHandler=({transaction:h})=>{h.getMeta("bubbleMenu")==="updatePosition"&&this.updatePosition()};var a;this.editor=e,this.element=t,this.view=n,this.updateDelay=i,this.resizeDelay=s,this.appendTo=r,this.scrollTarget=(a=c==null?void 0:c.scrollTarget)!=null?a:window,this.getReferencedVirtualElement=l,this.floatingUIOptions={...this.floatingUIOptions,...c},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(H.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(H.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(H.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(H.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(H.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(H.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(H.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(H.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}get virtualElement(){var e;const{selection:t}=this.editor.state,n=(e=this.getReferencedVirtualElement)==null?void 0:e.call(this);if(n)return n;const i=E.posToDOMRect(this.view,t.from,t.to);let s={getBoundingClientRect:()=>i,getClientRects:()=>[i]};if(t instanceof J.NodeSelection){let o=this.view.nodeDOM(t.from);const r=o.dataset.nodeViewWrapper?o:o.querySelector("[data-node-view-wrapper]");r&&(o=r),o&&(s={getBoundingClientRect:()=>o.getBoundingClientRect(),getClientRects:()=>[o.getBoundingClientRect()]})}if(t instanceof Qi.CellSelection){const{$anchorCell:o,$headCell:r}=t,l=o?o.pos:r.pos,c=r?r.pos:o.pos,a=this.view.nodeDOM(l),h=this.view.nodeDOM(c);if(!a||!h)return;const d=a===h?a.getBoundingClientRect():Uo(a.getBoundingClientRect(),h.getBoundingClientRect());s={getBoundingClientRect:()=>d,getClientRects:()=>[d]}}return s}updatePosition(){const e=this.virtualElement;e&&H.computePosition(e,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:t,y:n,strategy:i})=>{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)),o=!(t!=null&&t.doc.eq(e.state.doc));this.updateHandler(e,s,o,t)}getShouldShow(e){var t;const{state:n}=this.view,{selection:i}=n,{ranges:s}=i,o=Math.min(...s.map(c=>c.$from.pos)),r=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:o,to:r}))||!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)}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()}},is=e=>new J.Plugin({key:typeof e.pluginKey=="string"?new J.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Po({view:t,...e})});E.Extension.create({name:"bubbleMenu",addOptions(){return{element:null,pluginKey:"bubbleMenu",updateDelay:void 0,appendTo:void 0,shouldShow:null}},addProseMirrorPlugins(){return this.options.element?[is({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 Vo=class{constructor({editor:e,element:t,view:n,options:i,appendTo:s,shouldShow:o}){this.preventHide=!1,this.isVisible=!1,this.shouldShow=({view:r,state:l})=>{const{selection:c}=l,{$anchor:a,empty:h}=c,d=a.depth===1,f=a.parent.isTextblock&&!a.parent.type.spec.code&&!a.parent.textContent&&a.parent.childCount===0&&!this.getTextContent(a.parent);return!(!r.hasFocus()||!h||!d||!f||!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=(r,l,c,a)=>{const{composing:h}=r;if(h||!l&&!c)return;if(!this.getShouldShow(a)){this.hide();return}this.updatePosition(),this.show()},this.mousedownHandler=()=>{this.preventHide=!0},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:r})=>{var l;if(this.preventHide){this.preventHide=!1;return}r!=null&&r.relatedTarget&&((l=this.element.parentNode)!=null&&l.contains(r.relatedTarget))||(r==null?void 0:r.relatedTarget)!==this.editor.view.dom&&this.hide()},this.editor=e,this.element=t,this.view=n,this.appendTo=s,this.floatingUIOptions={...this.floatingUIOptions,...i},this.element.tabIndex=0,o&&(this.shouldShow=o),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.update(n,n.state),this.getShouldShow()&&(this.show(),this.updatePosition())}getTextContent(e){return E.getText(e,{textSerializers:E.getTextSerializersFromSchema(this.editor.schema)})}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(H.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(H.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(H.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(H.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(H.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(H.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(H.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(H.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,o=Math.min(...s.map(c=>c.$from.pos)),r=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:o,to:r})}updatePosition(){const{selection:e}=this.editor.state,t=E.posToDOMRect(this.view,e.from,e.to),n={getBoundingClientRect:()=>t,getClientRects:()=>[t]};H.computePosition(n,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:i,y:s,strategy:o})=>{this.element.style.width="max-content",this.element.style.position=o,this.element.style.left=`${i}px`,this.element.style.top=`${s}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}),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},ss=e=>new J.Plugin({key:typeof e.pluginKey=="string"?new J.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Vo({view:t,...e})});E.Extension.create({name:"floatingMenu",addOptions(){return{element:null,options:{},pluginKey:"floatingMenu",appendTo:void 0,shouldShow:null}},addProseMirrorPlugins(){return this.options.element?[ss({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,options:this.options.options,appendTo:this.options.appendTo,shouldShow:this.options.shouldShow})]:[]}});var et=x.forwardRef(({pluginKey:e="bubbleMenu",editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:o=null,getReferencedVirtualElement:r,options:l,children:c,...a},h)=>{const d=x.useRef(document.createElement("div"));typeof h=="function"?h(d.current):h&&(h.current=d.current);const{editor:f}=E.useCurrentEditor(),g=t||f,p={updateDelay:n,resizeDelay:i,appendTo:s,pluginKey:e,shouldShow:o,getReferencedVirtualElement:r,options:l},m=x.useRef(p);return m.current=p,x.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 w=d.current;w.style.visibility="hidden",w.style.position="absolute";const b=is({...m.current,editor:g,element:w});g.registerPlugin(b);const I=m.current.pluginKey;return()=>{g.unregisterPlugin(I),window.requestAnimationFrame(()=>{w.parentNode&&w.parentNode.removeChild(w)})}},[g]),ts.createPortal(u.jsx("div",{...a,children:c}),d.current)});x.forwardRef(({pluginKey:e="floatingMenu",editor:t,appendTo:n,shouldShow:i=null,options:s,children:o,...r},l)=>{const c=x.useRef(document.createElement("div"));typeof l=="function"?l(c.current):l&&(l.current=c.current);const{editor:a}=E.useCurrentEditor();return x.useEffect(()=>{const h=c.current;if(h.style.visibility="hidden",h.style.position="absolute",t!=null&&t.isDestroyed||a!=null&&a.isDestroyed)return;const d=t||a;if(!d){console.warn("FloatingMenu component is not rendered inside of an editor component or does not have editor prop.");return}const f=ss({editor:d,element:h,pluginKey:e,appendTo:n,shouldShow:i,options:s});return d.registerPlugin(f),()=>{d.unregisterPlugin(e),window.requestAnimationFrame(()=>{h.parentNode&&h.parentNode.removeChild(h)})}},[t,a,n,e,i,s]),ts.createPortal(u.jsx("div",{...r,children:o}),c.current)});const Fo=[{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 Ho(){const e=X.useEditableEditor(),t=$.useEditorInstance(),{t:n}=U.useLocale(),{type:i,title:s,body:o}=at.useAttributes(t,Ae.Callout.name,{type:"note",title:"",body:""}),[r,l]=x.useState(!1),[c,a]=x.useState("note"),[h,d]=x.useState(""),[f,g]=x.useState("");x.useEffect(()=>{r&&(a(i||"note"),d(s||""),g(o||""))},[r,i,s,o]);const p=x.useCallback(()=>{t&&(t.chain().updateAttributes(Ae.Callout.name,{type:c,title:h,body:f}).focus().run(),l(!1))},[t,c,h,f]),m=x.useCallback(()=>{l(!1)},[]),w=x.useCallback(()=>{se.deleteNode(Ae.Callout.name,t)},[t]),b=x.useCallback(()=>t.isActive(Ae.Callout.name),[t]);return e?u.jsx(et,{editor:t,options:{placement:"top",offset:8,flip:!0},pluginKey:"RichTextBubbleCallout",shouldShow:b,children:u.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:[u.jsxs(O.Dialog,{onOpenChange:l,open:r,children:[u.jsx(O.DialogTrigger,{asChild:!0,children:u.jsx(y.ActionButton,{icon:"Pencil",tooltip:n("editor.callout.edit.title")})}),u.jsxs(O.DialogContent,{children:[u.jsx(O.DialogTitle,{children:n("editor.callout.edit.title")}),u.jsxs("div",{className:"richtext-space-y-4 richtext-py-4",children:[u.jsxs("div",{className:"richtext-space-y-2",children:[u.jsx(It.Label,{children:n("editor.callout.dialog.type")}),u.jsxs(ce.Select,{onValueChange:a,value:c,children:[u.jsx(ce.SelectTrigger,{children:u.jsx(ce.SelectValue,{className:"richtext-text-accent",placeholder:n("editor.callout.dialog.type.placeholder")})}),u.jsx(ce.SelectContent,{children:Fo.map(I=>u.jsx(ce.SelectItem,{value:I.value,children:n(`editor.callout.type.${I.value}`)},I.value))})]})]}),u.jsxs("div",{className:"richtext-space-y-2",children:[u.jsx(It.Label,{children:n("editor.callout.dialog.title.label")}),u.jsx(Yt.Input,{onChange:I=>d(I.target.value),placeholder:n("editor.callout.dialog.title.placeholder"),type:"text",value:h})]}),u.jsxs("div",{className:"richtext-space-y-2",children:[u.jsx(It.Label,{children:n("editor.callout.dialog.body.label")}),u.jsx(Yt.Input,{onChange:I=>g(I.target.value),placeholder:n("editor.callout.dialog.body.placeholder"),type:"text",value:f})]})]}),u.jsxs(O.DialogFooter,{children:[u.jsx(At.Button,{onClick:m,variant:"outline",children:n("editor.callout.dialog.button.cancel")}),u.jsx(At.Button,{onClick:p,children:n("editor.callout.dialog.button.apply")})]})]})]}),u.jsx(y.ActionButton,{action:w,icon:"Trash2",tooltip:n("editor.delete")})]})}):u.jsx(u.Fragment,{})}function $o(){const e=X.useEditableEditor(),t=$.useEditorInstance(),{t:n}=U.useLocale(),i=x.useCallback(()=>t.isActive(wi.MultipleColumnNode.name),[t]),s=x.useCallback(()=>se.deleteNode(wi.MultipleColumnNode.name,t),[t]),o=x.useCallback(()=>t.chain().focus().addColBefore().run(),[t]),r=x.useCallback(()=>t.chain().focus().addColAfter().run(),[t]),l=x.useCallback(()=>t.chain().focus().deleteCol().run(),[t]);return e?u.jsx(et,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleColumns",shouldShow:i,children:u.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:[u.jsx(y.ActionButton,{action:o,icon:"ColumnAddLeft",tooltip:n("editor.table.menu.insertColumnBefore")}),u.jsx(y.ActionButton,{action:r,icon:"ColumnAddRight",tooltip:n("editor.table.menu.insertColumnAfter")}),u.jsx(y.ActionButton,{action:l,icon:"DeleteColumn",tooltip:n("editor.table.menu.deleteColumn")}),u.jsx(y.ActionButton,{action:s,icon:"Trash2",tooltip:n("editor.table.menu.delete_column")})]})}):u.jsx(u.Fragment,{})}function zo(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,o)=>({type:`image-${s}`,component:y.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[o],action:()=>e.commands.updateImage({width:U.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:U.IMAGE_SIZE[s]})}}))}function qo(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,o)=>({type:`image-${s}`,component:y.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[o],action:()=>e.commands.updateImageGif({width:U.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:U.IMAGE_SIZE[s]})}}))}function Ko(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:y.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImage)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function Wo(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:y.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImageGif)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function Yo(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:y.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImageMermaid)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function Go(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:y.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImageDrawer)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function Jo(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:y.ActionButton,componentProps:{tooltip:n.tooltip,icon:n.icon,action:()=>e.commands.updateVideo({align:n.type}),isActive:()=>e.getAttributes("video").align===n.type}}))}function Xo(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,o)=>({type:`video-${s}`,component:y.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[o],action:()=>e.commands.updateVideo({width:U.VIDEO_SIZE[s]}),isActive:()=>e.isActive("video",{width:U.VIDEO_SIZE[s]})}}))}function Zo(e,t){return[{type:"flipX",component:y.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:y.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()}}},...zo(e,t),...Ko(e,t),{type:"remove",component:y.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}function Qo(e,t){return[...qo(e,t),...Wo(e,t),{type:"remove",component:y.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}function tr(e,t){return[...Yo(e,t),{type:"edit",component:y.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:y.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}function er(e,t){return[...Go(e,t),{type:"edit",component:y.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:y.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}function nr(e,t){return[...Xo(e,t),...Jo(e),{type:"remove",component:y.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}let he=!1;function ir({editor:e,attrs:t,extension:n}){const[i,s]=x.useState(!1),o=x.useRef(null),r=x.useRef(null),{alt:l,align:c}=t,a=n==null?void 0:n.options.upload,h=()=>{(async()=>{const S=document.querySelector("#easydrawer");S&&(o.current=new bi.Editor(S,{wheelEventsEnabled:!1,disableZoom:!0}),r.current=bi.makeDropdownToolbar(o.current),r.current.addDefaultToolWidgets(),o.current.loadFromSVG(decodeURIComponent(l)))})()};x.useEffect(()=>{i&&setTimeout(()=>{h()},200)},[i]);const d=async()=>{if(o.current){const T=o.current.toSVG(),S=T.outerHTML,C=`drawer-${ze.shortId()}.svg`;let N=ze.i(T.outerHTML);if(a){const z=es.dataURLtoFile(N,C);N=await a(z)}e==null||e.chain().focus().setDrawer({type:"drawer",src:N,alt:encodeURIComponent(S),width:426,height:212},!!S).run(),e==null||e.commands.setAlignImageDrawer(c)}s(!1)},f=T=>{const S=o.current.toolController.getPrimaryTools()[2],C=r.current.getWidgetById("pen-1");S&&C&&(S.setColor(T),C.serializeState())},g=T=>{const S=o.current.toolController.getPrimaryTools()[2],C=r.current.getWidgetById("pen-1");S&&C&&(S.setThickness(T),C.serializeState())},p=T=>{const S=o.current.toolController.getPrimaryTools()[3],C=r.current.getWidgetById("pen-2");S&&C&&(S.setColor(T),C.serializeState())},m=T=>{const S=r.current.getWidgetById("shape");S&&S.setShapeType(T)},w=T=>{const S=o.current.toolController.getPrimaryTools()[5],C=r.current.getWidgetById("shape");S&&C&&(S.setColor(T),C.serializeState())},b=T=>{const S=o.current.toolController.getPrimaryTools()[5],C=r.current.getWidgetById("shape");S&&C&&(S.setThickness(T),C.serializeState())},I=T=>{const S=o.current.toolController.getPrimaryTools()[5],C=r.current.getWidgetById("shape");S&&C&&(S.setBorderColor(T),C.serializeState())},M=()=>{if(he){for(;o.current.history.redoStackSize>0;)o.current.history.redo();he=!1;return}o.current.history.undo()},k=()=>{he||o.current.history.redo()},L=()=>{if(!he){for(;o.current.history.undoStackSize>0;)M();he=!0}};return u.jsxs(O.Dialog,{onOpenChange:s,open:i,children:[u.jsx(O.DialogTrigger,{asChild:!0,children:u.jsx(y.ActionButton,{action:()=>s(!0),icon:"Pencil",tooltip:"Edit Drawer"})}),u.jsxs(O.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[u.jsx(O.DialogTitle,{children:"Edit Drawer"}),u.jsxs("div",{style:{height:"100%",borderWidth:1,background:"white",position:"relative"},children:[u.jsx("div",{className:"richtext-size-full",id:"easydrawer"}),u.jsx(Be.ControlDrawer,{changeBorderColorShape:I,changeColorShape:w,changeShape:m,onClear:L,onRedo:k,onThicknessChange:b,onUndo:M,refEditor:o,setColorHighlight:p,setColorPen:f,setThicknessPen:g})]}),u.jsx(O.DialogFooter,{children:u.jsx(At.Button,{onClick:d,type:"button",children:"Save changes"})})]})]})}function sr({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?u.jsx(x.Fragment,{children:e.type==="divider"?u.jsx(Tt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):u.jsx(i,{...e.componentProps,disabled:t||((s=e==null?void 0:e.componentProps)==null?void 0:s.disabled),editor:n})}):u.jsx(u.Fragment,{})}function or(){const{lang:e,t}=U.useLocale(),n=X.useEditableEditor(),i=$.useEditorInstance(),s=at.useAttributes(i,Be.Drawer.name),o=$.useExtension(Be.Drawer.name),r=({editor:c})=>{const{selection:a}=c.view.state,{$from:h,to:d}=a;let f=!1;return c.view.state.doc.nodesBetween(h.pos,d,g=>{if(g.type.name===Be.Drawer.name)return f=!0,!1}),f},l=x.useMemo(()=>er(i,t),[i,e,t]);return n?u.jsx(et,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleDrawer",shouldShow:r,children:l!=null&&l.length?u.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)?u.jsx(ir,{attrs:s,editor:i,extension:o},`bubbleMenu-drawer-${a}`):u.jsx(sr,{editor:i,item:c},`bubbleMenu-drawer-${a}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}const os=({width:e,maxWidth:t,height:n,onOk:i,children:s})=>{const{t:o}=U.useLocale(),[r,l]=x.useState({width:"",height:"",maxWidth:""});x.useEffect(()=>{l({width:e,height:n,maxWidth:t})},[n,t,e]);function c(a){a.preventDefault(),a.stopPropagation(),i(r)}return u.jsxs(Gt.Popover,{modal:!0,children:[u.jsx(Gt.PopoverTrigger,{asChild:!0,children:s}),u.jsx(Gt.PopoverContent,{children:u.jsxs("form",{className:"richtext-flex richtext-flex-col richtext-gap-2",onSubmit:c,children:[u.jsx(It.Label,{className:"mb-[6px]",children:"Width"}),u.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:u.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:u.jsx(Yt.Input,{onChange:a=>l({...r,width:a.target.value}),required:!0,type:"number",value:r.width})})}),u.jsx(It.Label,{className:"mb-[6px]",children:"Max Width"}),u.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:u.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:u.jsx(Yt.Input,{onChange:a=>l({...r,maxWidth:a.target.value}),required:!0,type:"number",value:r.maxWidth})})}),u.jsx(It.Label,{className:"mb-[6px]",children:"Height"}),u.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:u.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:u.jsx(Yt.Input,{onChange:a=>l({...r,height:a.target.value}),required:!0,type:"number",value:r.height})})}),u.jsx(At.Button,{className:"richtext-mt-2 richtext-self-end",type:"submit",children:o("editor.link.dialog.button.apply")})]})})]})},Bt=new Map;function rr(e){const t=e.options.element;Bt.has("width")||Bt.set("width",t.clientWidth),Bt.has("width")&&Bt.get("width")<=0&&Bt.set("width",t.clientWidth);const n={attributes:!0,childList:!0,subtree:!0},i=function(){Bt.set("width",t.clientWidth)},s=new MutationObserver(i);return s.observe(t,n),e.on("destroy",()=>{s.disconnect()}),{width:Bt.get("width")}}function lr(){const e=X.useEditableEditor(),t=$.useEditorInstance(),{t:n}=U.useLocale(),{width:i}=rr(t),s=at.useAttributes(t,Kt.Excalidraw.name,{defaultShowPicker:!1,createUser:"",width:0,height:0}),{defaultShowPicker:o,createUser:r,width:l,height:c}=s,a=x.useCallback(g=>{t.chain().updateAttributes(Kt.Excalidraw.name,g).setNodeSelection(t.state.selection.from).focus().run()},[t]),h=x.useCallback(()=>{Kt.triggerOpenExcalidrawSettingModal({...s,editor:t})},[t,s]),d=x.useCallback(()=>t.isActive(Kt.Excalidraw.name),[t]),f=x.useCallback(()=>se.deleteNode(Kt.Excalidraw.name,t),[t]);return x.useEffect(()=>{o&&(h(),t.chain().updateAttributes(Kt.Excalidraw.name,{defaultShowPicker:!1}).focus().run())},[r,o,t,h]),e?u.jsx(et,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleExcalidraw",shouldShow:d,children:u.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:[u.jsx(y.ActionButton,{action:h,icon:"Pencil",tooltip:n("editor.edit")}),u.jsx(os,{height:c,maxWidth:i,onOk:a,width:l,children:u.jsx(y.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),u.jsx(y.ActionButton,{action:f,icon:"Trash2",tooltip:n("editor.delete")})]})}):u.jsx(u.Fragment,{})}function cr(){const e=X.useEditableEditor(),t=$.useEditorInstance(),{t:n}=U.useLocale(),{width:i,height:s,src:o}=at.useAttributes(t,Wt.Iframe.name,{width:0,height:0,src:"",defaultShowPicker:!1}),[r,l]=x.useState(!1),[c,a]=x.useState(""),h=x.useCallback(w=>{var b;(b=w==null?void 0:w.preventDefault)==null||b.call(w),l(!1)},[l]);x.useEffect(()=>{r&&a(o)},[r,o]);const d=x.useCallback(w=>{var I;(I=w==null?void 0:w.preventDefault)==null||I.call(w);const b=Wt.getServiceSrc(c);t.chain().updateAttributes(Wt.Iframe.name,{src:(b==null?void 0:b.src)||c}).setNodeSelection(t.state.selection.from).focus().run(),l(!1)},[t,c,l]),f=x.useCallback(()=>{window.open(o,"_blank")},[o]),g=x.useCallback(w=>{t.chain().updateAttributes(Wt.Iframe.name,w).setNodeSelection(t.state.selection.from).focus().run()},[t]),p=x.useCallback(()=>t.isActive(Wt.Iframe.name)&&!o,[t,o]),m=x.useCallback(()=>se.deleteNode(Wt.Iframe.name,t),[t]);return e?u.jsx(u.Fragment,{children:u.jsx(et,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleIframe",shouldShow:p,children:u.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:[u.jsx(y.ActionButton,{action:f,icon:"Eye",tooltip:"Visit Link"}),u.jsxs(O.Dialog,{onOpenChange:l,open:r,children:[u.jsx(O.DialogTrigger,{asChild:!0,children:u.jsx(y.ActionButton,{icon:"Pencil",tooltip:"Open Edit Link"})}),u.jsxs(O.DialogContent,{children:[u.jsx(O.DialogHeader,{children:u.jsx(O.DialogTitle,{children:"Edit Link Iframe"})}),u.jsx(Yt.Input,{autoFocus:!0,onInput:w=>a(w.target.value),placeholder:"Enter link",type:"url",value:c}),u.jsxs(O.DialogFooter,{children:[u.jsx(At.Button,{onClick:h,type:"button",children:"Cancel"}),u.jsx(At.Button,{onClick:d,type:"button",children:"OK"})]})]})]}),u.jsx(os,{height:s,onOk:g,width:i,children:u.jsx(y.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),u.jsx(y.ActionButton,{action:m,icon:"Trash2",tooltip:n("editor.delete")})]})})}):u.jsx(u.Fragment,{})}function ar({children:e,visible:t,toggleVisible:n}){const{t:i}=U.useLocale(),s=$.useEditorInstance(),o=at.useAttributes(s,at.Katex.name,{text:"",macros:""}),{text:r,macros:l}=o,[c,a]=x.useState(decodeURIComponent(r||"")),[h,d]=x.useState(decodeURIComponent(l||""));x.useEffect(()=>{t&&(a(decodeURIComponent(r||"")),d(decodeURIComponent(l||"")))},[t]);const f=x.useCallback(()=>{s.chain().focus().setKatex({text:encodeURIComponent(c),macros:encodeURIComponent(h)}).run(),a(""),d(""),n(!1)},[s,c,h,n]),g=x.useMemo(()=>{try{return vo.renderToString(c,{macros:at.safeJSONParse(h||"")})}catch{return c}},[c,h]),p=x.useMemo(()=>`${c}`.trim()?g:null,[c,g]);return u.jsxs(O.Dialog,{onOpenChange:n,open:t,children:[u.jsx(O.DialogTrigger,{asChild:!0,children:e}),u.jsxs(O.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[u.jsx(O.DialogTitle,{children:i("editor.formula.dialog.text")}),u.jsx("div",{style:{height:"100%",border:"1px solid hsl(var(--border))"},children:u.jsxs("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[u.jsxs("div",{className:"richtext-flex-1",children:[u.jsx(It.Label,{className:"mb-[6px]",children:"Expression"}),u.jsx(An.Textarea,{autoFocus:!0,className:"richtext-mb-[10px]",onChange:m=>a(m.target.value),placeholder:"Text",required:!0,rows:10,value:c,style:{color:"hsl(var(--foreground))"}}),u.jsx(It.Label,{className:"mb-[6px]",children:"Macros"}),u.jsx(An.Textarea,{onChange:m=>d(m.target.value),placeholder:"Macros",rows:10,value:h,style:{color:"hsl(var(--foreground))"}})]}),u.jsx("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:p||""},style:{height:"100%",borderWidth:1,minHeight:500,background:"#fff"}})]})}),u.jsx(O.DialogFooter,{children:u.jsx(At.Button,{onClick:f,type:"button",children:"Save changes"})})]})]})}function hr(){const e=X.useEditableEditor(),t=$.useEditorInstance(),[n,i]=x.useState(!1),s=x.useCallback(()=>t.isActive(at.Katex.name),[t]),o=x.useCallback(()=>se.deleteNode(at.Katex.name,t),[t]);return e?u.jsx(et,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleKatex",shouldShow:s,children:u.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:[u.jsx(ar,{toggleVisible:i,visible:n,children:u.jsx(y.ActionButton,{action:()=>i(!n),tooltip:"Edit",children:u.jsx(qe.Pencil,{size:16})})}),u.jsx(y.ActionButton,{action:o,tooltip:"Delete",children:u.jsx(qe.Trash2,{size:16})})]})}):u.jsx(u.Fragment,{})}function dr(e){const{t}=U.useLocale();return u.jsxs("div",{className:"richtext-flex richtext-flex-nowrap",children:[u.jsx(y.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")}}),u.jsx(y.ActionButton,{icon:"Pencil",tooltip:t("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onEdit()}}),u.jsx(y.ActionButton,{icon:"Unlink",tooltip:t("editor.link.unlink.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onClear()}})]})}function ur(){const e=X.useEditableEditor(),t=$.useEditorInstance(),[n,i]=x.useState(!1),s=at.useAttributes(t,Le.Link.name),o=s==null?void 0:s.href,r=x.useCallback(({editor:h})=>h.isActive(Le.Link.name),[]),l=(h,d,f)=>{const g=t.state.selection,{from:p}=g,m=(d==null?void 0:d.length)??0,w=p+m;t.chain().extendMarkRange("link").insertContent({type:"text",text:d,marks:[{type:"link",attrs:{href:h,target:f?"_blank":""}}]}).setLink({href:h}).setTextSelection({from:p,to:w}).focus().run(),i(!1)},c=x.useCallback(()=>{t.chain().extendMarkRange("link").unsetLink().focus().run(),i(!1)},[t]),a=()=>{i(!1)};return e?u.jsx(et,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleLink",shouldShow:r,children:u.jsx(u.Fragment,{children:n?u.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:u.jsx(Le.LinkEditBlock,{editor:t,onClose:a,onSetLink:l})}):u.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:u.jsx(dr,{editor:t,link:o,onClear:c,onEdit:()=>{i(!0)}})})})}):u.jsx(u.Fragment,{})}function Gn({item:e,disabled:t,editor:n}){const i=e.component;return i?u.jsx(x.Fragment,{children:e.type==="divider"?u.jsx(Tt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):u.jsx(i,{...e.componentProps,disabled:t||(e==null?void 0:e.componentdisabled),editor:n})}):u.jsx(u.Fragment,{})}function fr(e){return e.type.name===_o.Image.name}function gr(e){return e.type.name===Eo.ImageGif.name}function pr(e){return e.type.name===Io.Video.name}function mr(){const{lang:e,t}=U.useLocale(),n=X.useEditableEditor(),i=$.useEditorInstance(),s=({editor:r})=>{const{selection:l}=r.view.state,{$from:c,to:a}=l;let h=!1;return r.view.state.doc.nodesBetween(c.pos,a,d=>{if(fr(d))return h=!0,!1}),h},o=x.useMemo(()=>Zo(i,t),[i,e,t]);return n?u.jsx(et,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImage",shouldShow:s,children:o!=null&&o.length?u.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:o==null?void 0:o.map((r,l)=>u.jsx(Gn,{editor:i,item:r},`bubbleMenu-image-${l}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}function xr(){const{lang:e,t}=U.useLocale(),n=X.useEditableEditor(),i=$.useEditorInstance(),s=({editor:r})=>{const{selection:l}=r.view.state,{$from:c,to:a}=l;let h=!1;return r.view.state.doc.nodesBetween(c.pos,a,d=>{if(gr(d))return h=!0,!1}),h},o=x.useMemo(()=>Qo(i,t),[i,t,e]);return n?u.jsx(et,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImageGif",shouldShow:s,children:o!=null&&o.length?u.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:o==null?void 0:o.map((r,l)=>u.jsx(Gn,{editor:i,item:r},`bubbleMenu-image-gif-${l}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}function wr(){const{t:e}=U.useLocale(),t=X.useEditableEditor(),n=$.useEditorInstance(),i=({editor:o})=>{const{selection:r}=o.view.state,{$from:l,to:c}=r;let a=!1;return o.view.state.doc.nodesBetween(l.pos,c,h=>{if(pr(h))return a=!0,!1}),a},s=x.useMemo(()=>nr(n,e),[n,e]);return t?u.jsx(et,{editor:n,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleVideo",shouldShow:i,children:s!=null&&s.length?u.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((o,r)=>u.jsx(Gn,{editor:n,item:o},`bubbleMenu-video-${r}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}const yi=`graph TB
2
+ a-->b`,br=({editor:e,attrs:t,extension:n})=>{const{alt:i,align:s}=t,[o,r]=x.useState(decodeURIComponent(i??yi)),[l,c]=x.useState(""),[a,h]=x.useState(!1),d=x.useRef(null),[f,g]=x.useState(null),p=n==null?void 0:n.options.upload,m=x.useCallback(M=>{M&&import("mermaid").then(k=>{g(k.default)})},[]),w=async M=>{try{const{svg:k}=await f.render("mermaid-svg",M);c(k)}catch{c("")}},b=()=>{f.initialize({darkMode:!1,startOnLoad:!1,fontSize:12,theme:"base"}),w(o)};x.useEffect(()=>{f&&a&&b()},[f,a]),x.useEffect(()=>{f&&a&&w(o)},[f,o]);const I=async()=>{if(o!==""){if(o){const M=d.current.querySelector("svg"),{width:k,height:L}=M.getBoundingClientRect(),T=`mermaid-${ze.shortId()}.svg`;let S=ze.i(M.outerHTML);if(p){const C=es.dataURLtoFile(S,T);S=await p(C)}e==null||e.chain().focus().setMermaid({type:"mermaid",src:S,alt:encodeURIComponent(o),width:k,height:L},!!o).run(),e==null||e.commands.setAlignImageMermaid(s)}h(!1)}};return u.jsxs(O.Dialog,{onOpenChange:h,open:a,children:[u.jsx(O.DialogTrigger,{asChild:!0,children:u.jsx(y.ActionButton,{action:()=>h(!0),icon:"Pencil",tooltip:"Edit Mermaid"})}),u.jsxs(O.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[u.jsx(O.DialogTitle,{children:"Edit Mermaid"}),u.jsx("div",{ref:m,style:{height:"100%",border:"1px solid hsl(var(--border))"},children:u.jsxs("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[u.jsx(An.Textarea,{autoFocus:!0,className:"richtext-flex-1",defaultValue:yi,onChange:M=>r(M.target.value),placeholder:"Text",required:!0,rows:10,value:o,style:{color:"hsl(var(--foreground))"}}),u.jsx("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:l},ref:d,style:{height:"100%",border:"1px solid hsl(var(--border))",minHeight:500}})]})}),u.jsx(O.DialogFooter,{children:u.jsx(At.Button,{onClick:I,type:"button",children:"Save changes"})})]})]})};function yr({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?u.jsx(x.Fragment,{children:e.type==="divider"?u.jsx(Tt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):u.jsx(i,{...e.componentProps,disabled:t||((s=e==null?void 0:e.componentProps)==null?void 0:s.disabled),editor:n})}):u.jsx(u.Fragment,{})}function Sr(e){return e.type.name===Dn.Mermaid.name}function Cr(){const{lang:e,t}=U.useLocale(),n=X.useEditableEditor(),i=$.useEditorInstance(),s=at.useAttributes(i,Dn.Mermaid.name),o=$.useExtension(Dn.Mermaid.name),r=({editor:c})=>{const{selection:a}=c.view.state,{$from:h,to:d}=a;let f=!1;return c.view.state.doc.nodesBetween(h.pos,d,g=>{if(Sr(g))return f=!0,!1}),f},l=x.useMemo(()=>tr(i,t),[i,e,t]);return n?u.jsx(et,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleMermaid",shouldShow:r,children:l!=null&&l.length?u.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)?u.jsx(br,{attrs:s,editor:i,extension:o},`bubbleMenu-mermaid-${a}`):u.jsx(yr,{editor:i,item:c},`bubbleMenu-mermaid-${a}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}function kr({hiddenActions:e=[]}){var m,w,b,I,M,k,L,T,S,C,N,z,st,Rt,Nt,v,xt,Te;const{t}=U.useLocale(),n=X.useEditableEditor(),i=$.useEditorInstance(),s=({editor:qt})=>E.isActive(qt.view.state,Qi.Table.name),o=qt=>e.includes(qt);function r(){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 h(){i.chain().focus().addRowAfter().run()}function d(){i.chain().focus().deleteRow().run()}function f(){i.chain().focus().mergeCells().run()}function g(){i==null||i.chain().focus().splitCell().run()}function p(){i.chain().focus().deleteTable().run()}return n?u.jsx(et,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTable",shouldShow:s,children:u.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:[!o("addColumnBefore")&&u.jsx(y.ActionButton,{action:r,disabled:!((w=(m=i==null?void 0:i.can())==null?void 0:m.addColumnBefore)!=null&&w.call(m)),icon:"BetweenHorizonalEnd",tooltip:t("editor.table.menu.insertColumnBefore"),tooltipOptions:{sideOffset:15}}),!o("addColumnAfter")&&u.jsx(y.ActionButton,{action:l,disabled:!((I=(b=i==null?void 0:i.can())==null?void 0:b.addColumnAfter)!=null&&I.call(b)),icon:"BetweenHorizonalStart",tooltip:t("editor.table.menu.insertColumnAfter"),tooltipOptions:{sideOffset:15}}),!o("deleteColumn")&&u.jsx(y.ActionButton,{action:c,disabled:!((k=i==null?void 0:(M=i.can()).deleteColumn)!=null&&k.call(M)),icon:"DeleteColumn",tooltip:t("editor.table.menu.deleteColumn"),tooltipOptions:{sideOffset:15}}),u.jsx(Tt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!o("addRowAbove")&&u.jsx(y.ActionButton,{action:a,disabled:!((T=i==null?void 0:(L=i.can()).addRowBefore)!=null&&T.call(L)),icon:"BetweenVerticalEnd",tooltip:t("editor.table.menu.insertRowAbove"),tooltipOptions:{sideOffset:15}}),!o("addRowBelow")&&u.jsx(y.ActionButton,{action:h,disabled:!((C=(S=i==null?void 0:i.can())==null?void 0:S.addRowAfter)!=null&&C.call(S)),icon:"BetweenVerticalStart",tooltip:t("editor.table.menu.insertRowBelow"),tooltipOptions:{sideOffset:15}}),!o("deleteRow")&&u.jsx(y.ActionButton,{action:d,disabled:!((z=(N=i==null?void 0:i.can())==null?void 0:N.deleteRow)!=null&&z.call(N)),icon:"DeleteRow",tooltip:t("editor.table.menu.deleteRow"),tooltipOptions:{sideOffset:15}}),u.jsx(Tt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!o("mergeCells")&&u.jsx(y.ActionButton,{action:f,disabled:!((Rt=(st=i==null?void 0:i.can())==null?void 0:st.mergeCells)!=null&&Rt.call(st)),icon:"TableCellsMerge",tooltip:t("editor.table.menu.mergeCells"),tooltipOptions:{sideOffset:15}}),!o("splitCells")&&u.jsx(y.ActionButton,{action:g,disabled:!((v=(Nt=i==null?void 0:i.can())==null?void 0:Nt.splitCell)!=null&&v.call(Nt)),icon:"TableCellsSplit",tooltip:t("editor.table.menu.splitCells"),tooltipOptions:{sideOffset:15}}),u.jsx(Tt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!o("deleteTable")&&u.jsx(y.ActionButton,{action:p,disabled:!((Te=(xt=i==null?void 0:i.can())==null?void 0:xt.deleteTable)!=null&&Te.call(xt)),icon:"Trash2",tooltip:t("editor.table.menu.deleteTable"),tooltipOptions:{sideOffset:15}})]})}):u.jsx(u.Fragment,{})}function vr(){const{t:e}=U.useLocale(),[t,n]=x.useState(!1),i=$.useEditorInstance(),s=x.useMemo(()=>{var r,l;return(l=(r=Oo.renderCommandListDefault({t:e}))==null?void 0:r[0])==null?void 0:l.commands},[e]),o=x.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 u.jsxs(Gt.Popover,{modal:!0,onOpenChange:n,open:t,children:[u.jsx(Gt.PopoverTrigger,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:u.jsxs(y.ActionButton,{dataState:!!o,children:[o?u.jsx(u.Fragment,{children:o}):u.jsx(u.Fragment,{children:e("editor.paragraph.tooltip")}),u.jsx(nt.IconComponent,{className:"richtext-ml-1 richtext-size-3 richtext-text-zinc-500",name:"MenuDown"})]})}),u.jsx(Gt.PopoverContent,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:s==null?void 0:s.map(r=>{var c;const l=(c=r==null?void 0:r.isActive)==null?void 0:c.call(r,i);return u.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(),r.action({editor:i,range:i.state.selection.ranges}),n(!1)},children:[u.jsxs("div",{className:"!richtext-min-w-[20px]",children:[l&&u.jsx(qe.Check,{size:16}),!o&&r.label===e("editor.paragraph.tooltip")&&!l&&u.jsx(qe.Check,{size:16})]}),u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:[r.iconName&&u.jsx(nt.IconComponent,{className:"!richtext-mr-1 !richtext-text-lg",name:r.iconName}),r.label]})]},r.name)})})]})}function _r(){return u.jsxs(u.Fragment,{children:[u.jsx(vr,{}),u.jsx(Tt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),u.jsx(To.RichTextBold,{}),u.jsx(jo.RichTextItalic,{}),u.jsx(No.RichTextUnderline,{}),u.jsx(Ro.RichTextStrike,{}),u.jsx(Ao.RichTextCode,{}),u.jsx(Le.RichTextLink,{}),u.jsx(Tt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),u.jsx(Do.RichTextColor,{}),u.jsx(Mo.RichTextHighlight,{}),u.jsx(ns.RichTextAlign,{})]})}function Er({buttonBubble:e}){const t=$.useEditorInstance(),n=X.useEditableEditor(),i=({editor:s})=>{const{selection:o}=s.view.state,{$from:r,to:l}=o;return r.pos===l?!1:o instanceof J.TextSelection};return n?u.jsx(et,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleText",shouldShow:i,children:e?u.jsx(u.Fragment,{children:e}):u.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:u.jsx(_r,{})})}):u.jsx(u.Fragment,{})}function Ir(){const{t:e}=U.useLocale(),t=X.useEditableEditor(),n=$.useEditorInstance(),[i,s]=x.useState(!1),o=x.useCallback(({editor:c})=>c.isActive(mn.Twitter.name),[]),r=c=>{n.commands.updateTweet({src:c}),s(!1)},l=x.useCallback(()=>se.deleteNode(mn.Twitter.name,n),[n]);return t?u.jsx(et,{editor:n,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTwitter",shouldShow:o,children:u.jsx(u.Fragment,{children:i?u.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:u.jsx(mn.FormEditLinkTwitter,{editor:n,onSetLink:r})}):u.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:[u.jsx(y.ActionButton,{icon:"Pencil",tooltip:e("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{s(!0)}}),u.jsx(y.ActionButton,{action:l,icon:"Trash",tooltip:e("editor.delete"),tooltipOptions:{sideOffset:15}})]})})}):u.jsx(u.Fragment,{})}const ht=()=>new Map,Mn=e=>{const t=ht();return e.forEach((n,i)=>{t.set(i,n)}),t},Ct=(e,t,n)=>{let i=e.get(t);return i===void 0&&e.set(t,i=n()),i},Tr=(e,t)=>{const n=[];for(const[i,s]of e)n.push(t(s,i));return n},Ar=(e,t)=>{for(const[n,i]of e)if(t(i,n))return!0;return!1},Pt=()=>new Set,wn=e=>e[e.length-1],Dr=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},Vt=Array.from,Mr=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},jn=Array.isArray;class rs{constructor(){this._observers=ht()}on(t,n){return Ct(this._observers,t,Pt).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 Vt((this._observers.get(t)||ht()).values()).forEach(i=>i(...n))}destroy(){this._observers=ht()}}const St=Math.floor,Ue=Math.abs,te=(e,t)=>e<t?e:t,Dt=(e,t)=>e>t?e:t,ls=e=>e!==0?e<0:1/e<0,Si=1,Ci=2,bn=4,yn=8,ge=32,bt=64,G=128,jr=1<<29,on=31,On=63,Ut=127,Or=2147483647,cs=Number.MAX_SAFE_INTEGER,Rr=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&St(e)===e),Nr=String.fromCharCode,Br=e=>e.toLowerCase(),Lr=/^\s*/g,Ur=e=>e.replace(Lr,""),Pr=/([A-Z])/g,ki=(e,t)=>Ur(e.replace(Pr,n=>`${t}${Br(n)}`)),Vr=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},pe=typeof TextEncoder<"u"?new TextEncoder:null,Fr=e=>pe.encode(e),Hr=pe?Fr:Vr;let ue=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});ue&&ue.decode(new Uint8Array).length===1&&(ue=null);class ve{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const _e=()=>new ve,$r=e=>{const t=_e();return e(t),ct(t)},zr=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},ct=e=>{const t=new Uint8Array(zr(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},qr=(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(Dt(n,t)*2),e.cpos=0)},q=(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},Rn=q,A=(e,t)=>{for(;t>Ut;)q(e,G|Ut&t),t=St(t/128);q(e,Ut&t)},Jn=(e,t)=>{const n=ls(t);for(n&&(t=-t),q(e,(t>On?G:0)|(n?bt:0)|On&t),t=St(t/64);t>0;)q(e,(t>Ut?G:0)|Ut&t),t=St(t/128)},Nn=new Uint8Array(3e4),Kr=Nn.length/3,Wr=(e,t)=>{if(t.length<Kr){const n=pe.encodeInto(t,Nn).written||0;A(e,n);for(let i=0;i<n;i++)q(e,Nn[i])}else it(e,Hr(t))},Yr=(e,t)=>{const n=unescape(encodeURIComponent(t)),i=n.length;A(e,i);for(let s=0;s<i;s++)q(e,n.codePointAt(s))},Jt=pe&&pe.encodeInto?Wr:Yr,rn=(e,t)=>{const n=e.cbuf.length,i=e.cpos,s=te(n-i,t.length),o=t.length-s;e.cbuf.set(t.subarray(0,s),i),e.cpos+=s,o>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(Dt(n*2,o)),e.cbuf.set(t.subarray(s)),e.cpos=o)},it=(e,t)=>{A(e,t.byteLength),rn(e,t)},Xn=(e,t)=>{qr(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Gr=(e,t)=>Xn(e,4).setFloat32(0,t,!1),Jr=(e,t)=>Xn(e,8).setFloat64(0,t,!1),Xr=(e,t)=>Xn(e,8).setBigInt64(0,t,!1),vi=new DataView(new ArrayBuffer(4)),Zr=e=>(vi.setFloat32(0,e),vi.getFloat32(0)===e),ee=(e,t)=>{switch(typeof t){case"string":q(e,119),Jt(e,t);break;case"number":Rr(t)&&Ue(t)<=Or?(q(e,125),Jn(e,t)):Zr(t)?(q(e,124),Gr(e,t)):(q(e,123),Jr(e,t));break;case"bigint":q(e,122),Xr(e,t);break;case"object":if(t===null)q(e,126);else if(jn(t)){q(e,117),A(e,t.length);for(let n=0;n<t.length;n++)ee(e,t[n])}else if(t instanceof Uint8Array)q(e,116),it(e,t);else{q(e,118);const n=Object.keys(t);A(e,n.length);for(let i=0;i<n.length;i++){const s=n[i];Jt(e,s),ee(e,t[s])}}break;case"boolean":q(e,t?120:121);break;default:q(e,127)}};class _i extends ve{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 Ei=e=>{e.count>0&&(Jn(e.encoder,e.count===1?e.s:-e.s),e.count>1&&A(e.encoder,e.count-2))};class Pe{constructor(){this.encoder=new ve,this.s=0,this.count=0}write(t){this.s===t?this.count++:(Ei(this),this.count=1,this.s=t)}toUint8Array(){return Ei(this),ct(this.encoder)}}const Ii=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);Jn(e.encoder,t),e.count>1&&A(e.encoder,e.count-2)}};class Sn{constructor(){this.encoder=new ve,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(Ii(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return Ii(this),ct(this.encoder)}}class Qr{constructor(){this.sarr=[],this.s="",this.lensE=new Pe}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 ve;return this.sarr.push(this.s),this.s="",Jt(t,this.sarr.join("")),rn(t,this.lensE.toUint8Array()),ct(t)}}const Mt=e=>new Error(e),dt=()=>{throw Mt("Method unimplemented")},tt=()=>{throw Mt("Unexpected case")},as=Mt("Unexpected end of array"),hs=Mt("Integer out of Range");class ln{constructor(t){this.arr=t,this.pos=0}}const Zn=e=>new ln(e),tl=e=>e.pos!==e.arr.length,el=(e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},ot=e=>el(e,R(e)),me=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&Ut)*n,n*=128,s<G)return t;if(t>cs)throw hs}throw as},Qn=e=>{let t=e.arr[e.pos++],n=t&On,i=64;const s=(t&bt)>0?-1:1;if((t&G)===0)return s*n;const o=e.arr.length;for(;e.pos<o;){if(t=e.arr[e.pos++],n=n+(t&Ut)*i,i*=128,t<G)return s*n;if(n>cs)throw hs}throw as},nl=e=>{let t=R(e);if(t===0)return"";{let n=String.fromCodePoint(me(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(me(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))}},il=e=>ue.decode(ot(e)),Bn=ue?il:nl,ti=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},sl=e=>ti(e,4).getFloat32(0,!1),ol=e=>ti(e,8).getFloat64(0,!1),rl=e=>ti(e,8).getBigInt64(0,!1),ll=[e=>{},e=>null,Qn,sl,ol,rl,e=>!1,e=>!0,Bn,e=>{const t=R(e),n={};for(let i=0;i<t;i++){const s=Bn(e);n[s]=Ke(e)}return n},e=>{const t=R(e),n=[];for(let i=0;i<t;i++)n.push(Ke(e));return n},ot],Ke=e=>ll[127-me(e)](e);class Ti extends ln{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),tl(this)?this.count=R(this)+1:this.count=-1),this.count--,this.s}}class Ve extends ln{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Qn(this);const t=ls(this.s);this.count=1,t&&(this.s=-this.s,this.count=R(this)+2)}return this.count--,this.s}}class Cn extends ln{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=Qn(this),n=t&1;this.diff=St(t/2),this.count=1,n&&(this.count=R(this)+2)}return this.s+=this.diff,this.count--,this.s}}class cl{constructor(t){this.decoder=new Ve(t),this.str=Bn(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 al=crypto.getRandomValues.bind(crypto),hl=Math.random,ds=()=>al(new Uint32Array(1))[0],dl=e=>e[St(hl()*e.length)],ul="10000000-1000-4000-8000"+-1e11,fl=()=>ul.replace(/[018]/g,e=>(e^ds()&15>>e/4).toString(16)),gl=Date.now,Ai=e=>new Promise(e);Promise.all.bind(Promise);const Di=e=>e===void 0?null:e;class pl{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}}let us=new pl,ml=!0;try{typeof localStorage<"u"&&localStorage&&(us=localStorage,ml=!1)}catch{}const xl=us,wl=Object.assign,fs=Object.keys,bl=(e,t)=>{for(const n in e)t(e[n],n)},Mi=e=>fs(e).length,yl=e=>{for(const t in e)return!1;return!0},gs=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},Sl=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Cl=(e,t)=>e===t||Mi(e)===Mi(t)&&gs(e,(n,i)=>(n!==void 0||Sl(t,i))&&t[i]===n),kl=Object.freeze,ps=e=>{for(const t in e){const n=e[t];(typeof n=="object"||typeof n=="function")&&ps(e[t])}return kl(e)},ei=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&ei(e,t,n+1)}},vl=(e,t)=>t.includes(e),ne=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",ms=typeof window<"u"&&typeof document<"u"&&!ne;let pt;const _l=()=>{if(pt===void 0)if(ne){pt=ht();const e=process.argv;let t=null;for(let n=0;n<e.length;n++){const i=e[n];i[0]==="-"?(t!==null&&pt.set(t,""),t=i):t!==null&&(pt.set(t,i),t=null)}t!==null&&pt.set(t,"")}else typeof location=="object"?(pt=ht(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){const[t,n]=e.split("=");pt.set(`--${ki(t,"-")}`,n),pt.set(`-${ki(t,"-")}`,n)}})):pt=ht();return pt},Ln=e=>_l().has(e),We=e=>Di(ne?process.env[e.toUpperCase().replaceAll("-","_")]:xl.getItem(e)),xs=e=>Ln("--"+e)||We(e)!==null;xs("production");const El=ne&&vl(process.env.FORCE_COLOR,["true","1","2"]),Il=El||!Ln("--no-colors")&&!xs("no-color")&&(!ne||process.stdout.isTTY)&&(!ne||Ln("--color")||We("COLORTERM")!==null||(We("TERM")||"").includes("color")),Tl=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=Nr(e[n]);return btoa(t)},Al=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),Dl=ms?Tl:Al,Ml=e=>$r(t=>ee(t,e));class jl{constructor(t,n){this.left=t,this.right=n}}const wt=(e,t)=>new jl(e,t),Ol=typeof document<"u"?document:{};typeof DOMParser<"u"&&new DOMParser;const Rl=e=>Tr(e,(t,n)=>`${n}:${t};`).join(""),Nl=e=>class{constructor(n){this._=n}destroy(){e(this._)}},Bl=Nl(clearTimeout),ws=(e,t)=>new Bl(setTimeout(t,e)),kt=Symbol,bs=kt(),ys=kt(),Ll=kt(),Ul=kt(),Pl=kt(),Ss=kt(),Vl=kt(),ni=kt(),Fl=kt(),Hl=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 o=e[i];if(o===void 0)break;if(o.constructor===String||o.constructor===Number)t.push(o);else if(o.constructor===Object)break}for(i>0&&n.push(t.join(""));i<e.length;i++){const o=e[i];o instanceof Symbol||n.push(o)}return n},$l={[bs]:wt("font-weight","bold"),[ys]:wt("font-weight","normal"),[Ll]:wt("color","blue"),[Pl]:wt("color","green"),[Ul]:wt("color","grey"),[Ss]:wt("color","red"),[Vl]:wt("color","purple"),[ni]:wt("color","orange"),[Fl]:wt("color","black")},zl=e=>{var r;e.length===1&&((r=e[0])==null?void 0:r.constructor)===Function&&(e=e[0]());const t=[],n=[],i=ht();let s=[],o=0;for(;o<e.length;o++){const l=e[o],c=$l[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=Rl(i);o>0||a.length>0?(t.push("%c"+l),n.push(a)):t.push(l)}else break}}for(o>0&&(s=n,s.unshift(t.join("")));o<e.length;o++){const l=e[o];l instanceof Symbol||s.push(l)}return s},Cs=Il?zl:Hl,ql=(...e)=>{console.log(...Cs(e)),vs.forEach(t=>t.print(e))},ks=(...e)=>{console.warn(...Cs(e)),e.unshift(ni),vs.forEach(t=>t.print(e))},vs=Pt(),_s=e=>({[Symbol.iterator](){return this},next:e}),Kl=(e,t)=>_s(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),kn=(e,t)=>_s(()=>{const{done:n,value:i}=e.next();return{done:n,value:n?void 0:t(i)}});class ii{constructor(t,n){this.clock=t,this.len=n}}class oe{constructor(){this.clients=new Map}}const jt=(e,t,n)=>t.clients.forEach((i,s)=>{const o=e.doc.store.clients.get(s);if(o!=null){const r=o[o.length-1],l=r.id.clock+r.length;for(let c=0,a=i[c];c<i.length&&a.clock<l;a=i[++c])Os(e,o,a.clock,a.len,n)}}),Wl=(e,t)=>{let n=0,i=e.length-1;for(;n<=i;){const s=St((n+i)/2),o=e[s],r=o.clock;if(r<=t){if(t<r+o.len)return s;n=s+1}else i=s-1}return null},re=(e,t)=>{const n=e.clients.get(t.client);return n!==void 0&&Wl(n,t.clock)!==null},si=e=>{e.clients.forEach(t=>{t.sort((s,o)=>s.clock-o.clock);let n,i;for(n=1,i=1;n<t.length;n++){const s=t[i-1],o=t[n];s.clock+s.len>=o.clock?s.len=Dt(s.len,o.clock+o.len-s.clock):(i<n&&(t[i]=o),i++)}t.length=i})},Un=e=>{const t=new oe;for(let n=0;n<e.length;n++)e[n].clients.forEach((i,s)=>{if(!t.clients.has(s)){const o=i.slice();for(let r=n+1;r<e.length;r++)Dr(o,e[r].clients.get(s)||[]);t.clients.set(s,o)}});return si(t),t},xe=(e,t,n,i)=>{Ct(e.clients,t,()=>[]).push(new ii(n,i))},Es=()=>new oe,Yl=e=>{const t=Es();return e.clients.forEach((n,i)=>{const s=[];for(let o=0;o<n.length;o++){const r=n[o];if(r.deleted){const l=r.id.clock;let c=r.length;if(o+1<n.length)for(let a=n[o+1];o+1<n.length&&a.deleted;a=n[++o+1])c+=a.length;s.push(new ii(l,c))}}s.length>0&&t.clients.set(i,s)}),t},oi=(e,t)=>{A(e.restEncoder,t.clients.size),Vt(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 o=0;o<s;o++){const r=i[o];e.writeDsClock(r.clock),e.writeDsLen(r.len)}})},Gl=e=>{const t=new oe,n=R(e.restDecoder);for(let i=0;i<n;i++){e.resetDsCurVal();const s=R(e.restDecoder),o=R(e.restDecoder);if(o>0){const r=Ct(t.clients,s,()=>[]);for(let l=0;l<o;l++)r.push(new ii(e.readDsClock(),e.readDsLen()))}}return t},ji=(e,t,n)=>{const i=new oe,s=R(e.restDecoder);for(let o=0;o<s;o++){e.resetDsCurVal();const r=R(e.restDecoder),l=R(e.restDecoder),c=n.clients.get(r)||[],a=V(n,r);for(let h=0;h<l;h++){const d=e.readDsClock(),f=d+e.readDsLen();if(d<a){a<f&&xe(i,r,a,f-a);let g=ut(c,d),p=c[g];for(!p.deleted&&p.id.clock<d&&(c.splice(g+1,0,tn(t,p,d-p.id.clock)),g++);g<c.length&&(p=c[g++],p.id.clock<f);)p.deleted||(f<p.id.clock+p.length&&c.splice(g,0,tn(t,p,f-p.id.clock)),p.delete(t))}else xe(i,r,d,f-d)}}if(i.clients.size>0){const o=new cn;return A(o.restEncoder,0),oi(o,i),o.toUint8Array()}return null},Is=ds;class $t extends rs{constructor({guid:t=fl(),collectionid:n=null,gc:i=!0,gcFilter:s=()=>!0,meta:o=null,autoLoad:r=!1,shouldLoad:l=!0}={}){super(),this.gc=i,this.gcFilter=s,this.clientID=Is(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new Ms,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=r,this.meta=o,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Ai(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const c=()=>Ai(a=>{const h=d=>{(d===void 0||d===!0)&&(this.off("sync",h),a())};this.on("sync",h)});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(Vt(this.subdocs).map(t=>t.guid))}transact(t,n=null){return j(this,t,n)}get(t,n=K){const i=Ct(this.share,t,()=>{const o=new n;return o._integrate(this,null),o}),s=i.constructor;if(n!==K&&s!==n)if(s===K){const o=new n;o._map=i._map,i._map.forEach(r=>{for(;r!==null;r=r.left)r.parent=o}),o._start=i._start;for(let r=o._start;r!==null;r=r.right)r.parent=o;return o._length=i._length,this.share.set(t,o),o._integrate(this,null),o}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,Ot)}getMap(t=""){return this.get(t,ie)}getXmlElement(t=""){return this.get(t,W)}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,Vt(this.subdocs).forEach(n=>n.destroy());const t=this._item;if(t!==null){this._item=null;const n=t.content;n.doc=new $t({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 Jl{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 Ye extends Jl{constructor(t){super(t),this.keys=[],R(t),this.keyClockDecoder=new Cn(ot(t)),this.clientDecoder=new Ve(ot(t)),this.leftClockDecoder=new Cn(ot(t)),this.rightClockDecoder=new Cn(ot(t)),this.infoDecoder=new Ti(ot(t),me),this.stringDecoder=new cl(ot(t)),this.parentInfoDecoder=new Ti(ot(t),me),this.typeRefDecoder=new Ve(ot(t)),this.lenDecoder=new Ve(ot(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 Ke(this.restDecoder)}readBuf(){return ot(this.restDecoder)}readJSON(){return Ke(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 Xl{constructor(){this.restEncoder=_e()}toUint8Array(){return ct(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){A(this.restEncoder,t)}writeDsLen(t){A(this.restEncoder,t)}}class Zl extends Xl{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){Rn(this.restEncoder,t)}writeString(t){Jt(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){ee(this.restEncoder,t)}writeBuf(t){it(this.restEncoder,t)}writeJSON(t){Jt(this.restEncoder,JSON.stringify(t))}writeKey(t){Jt(this.restEncoder,t)}}class Ql{constructor(){this.restEncoder=_e(),this.dsCurrVal=0}toUint8Array(){return ct(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,A(this.restEncoder,n)}writeDsLen(t){t===0&&tt(),A(this.restEncoder,t-1),this.dsCurrVal+=t}}class cn extends Ql{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Sn,this.clientEncoder=new Pe,this.leftClockEncoder=new Sn,this.rightClockEncoder=new Sn,this.infoEncoder=new _i(Rn),this.stringEncoder=new Qr,this.parentInfoEncoder=new _i(Rn),this.typeRefEncoder=new Pe,this.lenEncoder=new Pe}toUint8Array(){const t=_e();return A(t,0),it(t,this.keyClockEncoder.toUint8Array()),it(t,this.clientEncoder.toUint8Array()),it(t,this.leftClockEncoder.toUint8Array()),it(t,this.rightClockEncoder.toUint8Array()),it(t,ct(this.infoEncoder)),it(t,this.stringEncoder.toUint8Array()),it(t,ct(this.parentInfoEncoder)),it(t,this.typeRefEncoder.toUint8Array()),it(t,this.lenEncoder.toUint8Array()),rn(t,ct(this.restEncoder)),ct(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){ee(this.restEncoder,t)}writeBuf(t){it(this.restEncoder,t)}writeJSON(t){ee(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 tc=(e,t,n,i)=>{i=Dt(i,t[0].id.clock);const s=ut(t,i);A(e.restEncoder,t.length-s),e.writeClient(n),A(e.restEncoder,i);const o=t[s];o.write(e,i-o.id.clock);for(let r=s+1;r<t.length;r++)t[r].write(e,0)},Ts=(e,t,n)=>{const i=new Map;n.forEach((s,o)=>{V(t,o)>s&&i.set(o,s)}),an(t).forEach((s,o)=>{n.has(o)||i.set(o,0)}),A(e.restEncoder,i.size),Vt(i.entries()).sort((s,o)=>o[0]-s[0]).forEach(([s,o])=>{tc(e,t.clients.get(s),s,o)})},ec=(e,t)=>{const n=ht(),i=R(e.restDecoder);for(let s=0;s<i;s++){const o=R(e.restDecoder),r=new Array(o),l=e.readClient();let c=R(e.restDecoder);n.set(l,{i:0,refs:r});for(let a=0;a<o;a++){const h=e.readInfo();switch(on&h){case 0:{const d=e.readLen();r[a]=new rt(_(l,c),d),c+=d;break}case 10:{const d=R(e.restDecoder);r[a]=new lt(_(l,c),d),c+=d;break}default:{const d=(h&(bt|G))===0,f=new D(_(l,c),null,(h&G)===G?e.readLeftID():null,null,(h&bt)===bt?e.readRightID():null,d?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,d&&(h&ge)===ge?e.readString():null,eo(e,h));r[a]=f,c+=f.length}}}}return n},nc=(e,t,n)=>{const i=[];let s=Vt(n.keys()).sort((g,p)=>g-p);if(s.length===0)return null;const o=()=>{if(s.length===0)return null;let g=n.get(s[s.length-1]);for(;g.refs.length===g.i;)if(s.pop(),s.length>0)g=n.get(s[s.length-1]);else return null;return g};let r=o();if(r===null)return null;const l=new Ms,c=new Map,a=(g,p)=>{const m=c.get(g);(m==null||m>p)&&c.set(g,p)};let h=r.refs[r.i++];const d=new Map,f=()=>{for(const g of i){const p=g.id.client,m=n.get(p);m?(m.i--,l.clients.set(p,m.refs.slice(m.i)),n.delete(p),m.i=0,m.refs=[]):l.clients.set(p,[g]),s=s.filter(w=>w!==p)}i.length=0};for(;;){if(h.constructor!==lt){const p=Ct(d,h.id.client,()=>V(t,h.id.client))-h.id.clock;if(p<0)i.push(h),a(h.id.client,h.id.clock-1),f();else{const m=h.getMissing(e,t);if(m!==null){i.push(h);const w=n.get(m)||{refs:[],i:0};if(w.refs.length===w.i)a(m,V(t,m)),f();else{h=w.refs[w.i++];continue}}else(p===0||p<h.length)&&(h.integrate(e,p),d.set(h.id.client,h.id.clock+h.length))}}if(i.length>0)h=i.pop();else if(r!==null&&r.i<r.refs.length)h=r.refs[r.i++];else{if(r=o(),r===null)break;h=r.refs[r.i++]}}if(l.clients.size>0){const g=new cn;return Ts(g,l,new Map),A(g.restEncoder,0),{missing:c,update:g.toUint8Array()}}return null},ic=(e,t)=>Ts(e,t.doc.store,t.beforeState),sc=(e,t,n,i=new Ye(e))=>j(t,s=>{s.local=!1;let o=!1;const r=s.doc,l=r.store,c=ec(i,r),a=nc(s,l,c),h=l.pendingStructs;if(h){for(const[f,g]of h.missing)if(g<V(l,f)){o=!0;break}if(a){for(const[f,g]of a.missing){const p=h.missing.get(f);(p==null||p>g)&&h.missing.set(f,g)}h.update=Fi([h.update,a.update])}}else l.pendingStructs=a;const d=ji(i,s,l);if(l.pendingDs){const f=new Ye(Zn(l.pendingDs));R(f.restDecoder);const g=ji(f,s,l);d&&g?l.pendingDs=Fi([d,g]):l.pendingDs=d||g}else l.pendingDs=d;if(o){const f=l.pendingStructs.update;l.pendingStructs=null,Pn(s.doc,f)}},n,!1),Pn=(e,t,n,i=Ye)=>{const s=Zn(t);sc(s,e,n,new i(s))};class oc{constructor(){this.l=[]}}const Oi=()=>new oc,Ri=(e,t)=>e.l.push(t),Ni=(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.")},As=(e,t,n)=>ei(e.l,[t,n]);class Xt{constructor(t,n){this.client=t,this.clock=n}}const De=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,_=(e,t)=>new Xt(e,t),we=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw tt()},be=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1};class Ge{constructor(t,n,i,s=0){this.type=t,this.tname=n,this.item=i,this.assoc=s}}class rc{constructor(t,n,i=0){this.type=t,this.index=n,this.assoc=i}}const lc=(e,t,n=0)=>new rc(e,t,n),Me=(e,t,n)=>{let i=null,s=null;return e._item===null?s=we(e):i=_(e._item.id.client,e._item.id.clock),new Ge(i,s,t,n)},vn=(e,t,n=0)=>{let i=e._start;if(n<0){if(t===0)return Me(e,null,n);t--}for(;i!==null;){if(!i.deleted&&i.countable){if(i.length>t)return Me(e,_(i.id.client,i.id.clock+t),n);t-=i.length}if(i.right===null&&n<0)return Me(e,i.lastId,n);i=i.right}return Me(e,null,n)},cc=(e,t)=>{const n=Zt(e,t),i=t.clock-n.id.clock;return{item:n,diff:i}},ac=(e,t,n=!0)=>{const i=t.store,s=e.item,o=e.type,r=e.tname,l=e.assoc;let c=null,a=0;if(s!==null){if(V(i,s.client)<=s.clock)return null;const h=n?$n(i,s):cc(i,s),d=h.item;if(!(d instanceof D))return null;if(c=d.parent,c._item===null||!c._item.deleted){a=d.deleted||!d.countable?0:h.diff+(l>=0?0:1);let f=d.left;for(;f!==null;)!f.deleted&&f.countable&&(a+=f.length),f=f.left}}else{if(r!==null)c=t.get(r);else if(o!==null){if(V(i,o.client)<=o.clock)return null;const{item:h}=n?$n(i,o):{item:Zt(i,o)};if(h instanceof D&&h.content instanceof gt)c=h.content.type;else return null}else throw tt();l>=0?a=c._length:a=0}return lc(c,a,e.assoc)};class ri{constructor(t,n){this.ds=t,this.sv=n}}const Ds=(e,t)=>new ri(e,t),_n=e=>Ds(Yl(e.store),an(e.store)),Lt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!re(t.ds,e.id),Vn=(e,t)=>{const n=Ct(e.meta,Vn,Pt),i=e.doc.store;n.has(t)||(t.sv.forEach((s,o)=>{s<V(i,o)&&Z(e,_(o,s))}),jt(e,t.ds,s=>{}),n.add(t))};class Ms{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const an=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},V=(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},js=(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 tt()}n.push(t)},ut=(e,t)=>{let n=0,i=e.length-1,s=e[i],o=s.id.clock;if(o===t)return i;let r=St(t/(o+s.length-1)*i);for(;n<=i;){if(s=e[r],o=s.id.clock,o<=t){if(t<o+s.length)return r;n=r+1}else i=r-1;r=St((n+i)/2)}throw tt()},hc=(e,t)=>{const n=e.clients.get(t.client);return n[ut(n,t.clock)]},Zt=hc,Fn=(e,t,n)=>{const i=ut(t,n),s=t[i];return s.id.clock<n&&s instanceof D?(t.splice(i+1,0,tn(e,s,n-s.id.clock)),i+1):i},Z=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[Fn(e,n,t.clock)]},Bi=(e,t,n)=>{const i=t.clients.get(n.client),s=ut(i,n.clock),o=i[s];return n.clock!==o.id.clock+o.length-1&&o.constructor!==rt&&i.splice(s+1,0,tn(e,o,n.clock-o.id.clock+1)),o},dc=(e,t,n)=>{const i=e.clients.get(t.id.client);i[ut(i,t.id.clock)]=n},Os=(e,t,n,i,s)=>{if(i===0)return;const o=n+i;let r=Fn(e,t,n),l;do l=t[r++],o<l.id.clock+l.length&&Fn(e,t,o),s(l);while(r<t.length&&t[r].id.clock<o)};class uc{constructor(t,n,i){this.doc=t,this.deleteSet=new oe,this.beforeState=an(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 Li=(e,t)=>t.deleteSet.clients.size===0&&!Ar(t.afterState,(n,i)=>t.beforeState.get(i)!==n)?!1:(si(t.deleteSet),ic(e,t),oi(e,t.deleteSet),!0),Ui=(e,t,n)=>{const i=t._item;(i===null||i.id.clock<(e.beforeState.get(i.id.client)||0)&&!i.deleted)&&Ct(e.changed,t,Pt).add(n)},Fe=(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 D&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,i);continue}break}const o=t-s;return o&&e.splice(t+1-o,o),o},fc=(e,t,n)=>{for(const[i,s]of e.clients.entries()){const o=t.clients.get(i);for(let r=s.length-1;r>=0;r--){const l=s[r],c=l.clock+l.len;for(let a=ut(o,l.clock),h=o[a];a<o.length&&h.id.clock<c;h=o[++a]){const d=o[a];if(l.clock+l.len<=d.id.clock)break;d instanceof D&&d.deleted&&!d.keep&&n(d)&&d.gc(t,!1)}}}},gc=(e,t)=>{e.clients.forEach((n,i)=>{const s=t.clients.get(i);for(let o=n.length-1;o>=0;o--){const r=n[o],l=te(s.length-1,1+ut(s,r.clock+r.len-1));for(let c=l,a=s[c];c>0&&a.id.clock>=r.clock;a=s[c])c-=1+Fe(s,c)}})},Rs=(e,t)=>{if(t<e.length){const n=e[t],i=n.doc,s=i.store,o=n.deleteSet,r=n._mergeStructs;try{si(o),n.afterState=an(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(h=>h.target._item===null||!h.target._item.deleted),c.forEach(h=>{h.currentTarget=a,h._path=null}),c.sort((h,d)=>h.path.length-d.path.length),As(a._dEH,c,n))})}),l.push(()=>i.emit("afterTransaction",[n,i])),ei(l,[]),n._needFormattingCleanup&&Rc(n)}finally{i.gc&&fc(o,s,i.gcFilter),gc(o,s),n.afterState.forEach((h,d)=>{const f=n.beforeState.get(d)||0;if(f!==h){const g=s.clients.get(d),p=Dt(ut(g,f),1);for(let m=g.length-1;m>=p;)m-=1+Fe(g,m)}});for(let h=r.length-1;h>=0;h--){const{client:d,clock:f}=r[h].id,g=s.clients.get(d),p=ut(g,f);p+1<g.length&&Fe(g,p+1)>1||p>0&&Fe(g,p)}if(!n.local&&n.afterState.get(i.clientID)!==n.beforeState.get(i.clientID)&&(ql(ni,bs,"[yjs] ",ys,Ss,"Changed the client-id because another client seems to be using it."),i.clientID=Is()),i.emit("afterTransactionCleanup",[n,i]),i._observers.has("update")){const h=new Zl;Li(h,n)&&i.emit("update",[h.toUint8Array(),n.origin,i,n])}if(i._observers.has("updateV2")){const h=new cn;Li(h,n)&&i.emit("updateV2",[h.toUint8Array(),n.origin,i,n])}const{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=n;(l.size>0||a.size>0||c.size>0)&&(l.forEach(h=>{h.clientID=i.clientID,h.collectionid==null&&(h.collectionid=i.collectionid),i.subdocs.add(h)}),a.forEach(h=>i.subdocs.delete(h)),i.emit("subdocs",[{loaded:c,added:l,removed:a},i,n]),a.forEach(h=>h.destroy())),e.length<=t+1?(i._transactionCleanups=[],i.emit("afterAllTransactions",[i,e])):Rs(e,t+1)}}},j=(e,t,n=null,i=!0)=>{const s=e._transactionCleanups;let o=!1,r=null;e._transaction===null&&(o=!0,e._transaction=new uc(e,n,i),s.push(e._transaction),s.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{r=t(e._transaction)}finally{if(o){const l=e._transaction===s[0];e._transaction=null,l&&Rs(s,0)}}return r};class pc{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const Pi=(e,t,n)=>{jt(e,n.deletions,i=>{i instanceof D&&t.scope.some(s=>s===e.doc||be(s,i))&&di(i,!1)})},Vi=(e,t,n)=>{let i=null;const s=e.doc,o=e.scope;j(s,l=>{for(;t.length>0&&e.currStackItem===null;){const c=s.store,a=t.pop(),h=new Set,d=[];let f=!1;jt(l,a.insertions,g=>{if(g instanceof D){if(g.redone!==null){let{item:p,diff:m}=$n(c,g.id);m>0&&(p=Z(l,_(p.id.client,p.id.clock+m))),g=p}!g.deleted&&o.some(p=>p===l.doc||be(p,g))&&d.push(g)}}),jt(l,a.deletions,g=>{g instanceof D&&o.some(p=>p===l.doc||be(p,g))&&!re(a.insertions,g.id)&&h.add(g)}),h.forEach(g=>{f=to(l,g,h,a.insertions,e.ignoreRemoteMapChanges,e)!==null||f});for(let g=d.length-1;g>=0;g--){const p=d[g];e.deleteFilter(p)&&(p.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 r=e.currStackItem;if(r!=null){const l=i.changedParentTypes;e.emit("stack-item-popped",[{stackItem:r,type:n,changedParentTypes:l,origin:e},e]),e.currStackItem=null}return r};class Ns extends rs{constructor(t,{captureTimeout:n=500,captureTransaction:i=c=>!0,deleteFilter:s=()=>!0,trackedOrigins:o=new Set([null]),ignoreRemoteMapChanges:r=!1,doc:l=jn(t)?t[0].doc:t instanceof $t?t:t.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(t),this.deleteFilter=s,o.add(this),this.trackedOrigins=o,this.captureTransaction=i,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=r,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,h=this.redoing,d=a?this.redoStack:this.undoStack;a?this.stopCapturing():h||this.clear(!1,!0);const f=new oe;c.afterState.forEach((w,b)=>{const I=c.beforeState.get(b)||0,M=w-I;M>0&&xe(f,b,I,M)});const g=gl();let p=!1;if(this.lastChange>0&&g-this.lastChange<this.captureTimeout&&d.length>0&&!a&&!h){const w=d[d.length-1];w.deletions=Un([w.deletions,c.deleteSet]),w.insertions=Un([w.insertions,f])}else d.push(new pc(c.deleteSet,f)),p=!0;!a&&!h&&(this.lastChange=g),jt(c,c.deleteSet,w=>{w instanceof D&&this.scope.some(b=>b===c.doc||be(b,w))&&di(w,!0)});const m=[{stackItem:d[d.length-1],origin:c.origin,type:a?"redo":"undo",changedParentTypes:c.changedParentTypes},this];p?this.emit("stack-item-added",m):this.emit("stack-item-updated",m)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){const n=new Set(this.scope);t=jn(t)?t:[t],t.forEach(i=>{n.has(i)||(n.add(i),(i instanceof K?i.doc!==this.doc:i!==this.doc)&&ks("[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=>Pi(i,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>Pi(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=Vi(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=Vi(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*mc(e){const t=R(e.restDecoder);for(let n=0;n<t;n++){const i=R(e.restDecoder),s=e.readClient();let o=R(e.restDecoder);for(let r=0;r<i;r++){const l=e.readInfo();if(l===10){const c=R(e.restDecoder);yield new lt(_(s,o),c),o+=c}else if((on&l)!==0){const c=(l&(bt|G))===0,a=new D(_(s,o),null,(l&G)===G?e.readLeftID():null,null,(l&bt)===bt?e.readRightID():null,c?e.readParentInfo()?e.readString():e.readLeftID():null,c&&(l&ge)===ge?e.readString():null,eo(e,l));yield a,o+=a.length}else{const c=e.readLen();yield new rt(_(s,o),c),o+=c}}}}class xc{constructor(t,n){this.gen=mc(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===lt);return this.curr}}class wc{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const bc=(e,t)=>{if(e.constructor===rt){const{client:n,clock:i}=e.id;return new rt(_(n,i+t),e.length-t)}else if(e.constructor===lt){const{client:n,clock:i}=e.id;return new lt(_(n,i+t),e.length-t)}else{const n=e,{client:i,clock:s}=n.id;return new D(_(i,s+t),null,_(i,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Fi=(e,t=Ye,n=cn)=>{if(e.length===1)return e[0];const i=e.map(h=>new t(Zn(h)));let s=i.map(h=>new xc(h,!0)),o=null;const r=new n,l=new wc(r);for(;s=s.filter(f=>f.curr!==null),s.sort((f,g)=>{if(f.curr.id.client===g.curr.id.client){const p=f.curr.id.clock-g.curr.id.clock;return p===0?f.curr.constructor===g.curr.constructor?0:f.curr.constructor===lt?1:-1:p}else return g.curr.id.client-f.curr.id.client}),s.length!==0;){const h=s[0],d=h.curr.id.client;if(o!==null){let f=h.curr,g=!1;for(;f!==null&&f.id.clock+f.length<=o.struct.id.clock+o.struct.length&&f.id.client>=o.struct.id.client;)f=h.next(),g=!0;if(f===null||f.id.client!==d||g&&f.id.clock>o.struct.id.clock+o.struct.length)continue;if(d!==o.struct.id.client)de(l,o.struct,o.offset),o={struct:f,offset:0},h.next();else if(o.struct.id.clock+o.struct.length<f.id.clock)if(o.struct.constructor===lt)o.struct.length=f.id.clock+f.length-o.struct.id.clock;else{de(l,o.struct,o.offset);const p=f.id.clock-o.struct.id.clock-o.struct.length;o={struct:new lt(_(d,o.struct.id.clock+o.struct.length),p),offset:0}}else{const p=o.struct.id.clock+o.struct.length-f.id.clock;p>0&&(o.struct.constructor===lt?o.struct.length-=p:f=bc(f,p)),o.struct.mergeWith(f)||(de(l,o.struct,o.offset),o={struct:f,offset:0},h.next())}}else o={struct:h.curr,offset:0},h.next();for(let f=h.curr;f!==null&&f.id.client===d&&f.id.clock===o.struct.id.clock+o.struct.length&&f.constructor!==lt;f=h.next())de(l,o.struct,o.offset),o={struct:f,offset:0}}o!==null&&(de(l,o.struct,o.offset),o=null),yc(l);const c=i.map(h=>Gl(h)),a=Un(c);return oi(r,a),r.toUint8Array()},Bs=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:ct(e.encoder.restEncoder)}),e.encoder.restEncoder=_e(),e.written=0)},de=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Bs(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++},yc=e=>{Bs(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),rn(t,i.restEncoder)}},Hi="You must not compute changes after the event-handler fired.";class hn{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=Sc(this.currentTarget,this.target))}deletes(t){return re(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Mt(Hi);const t=new Map,n=this.target;this.transaction.changed.get(n).forEach(s=>{if(s!==null){const o=n._map.get(s);let r,l;if(this.adds(o)){let c=o.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(o))if(c!==null&&this.deletes(c))r="delete",l=wn(c.content.getContent());else return;else c!==null&&this.deletes(c)?(r="update",l=wn(c.content.getContent())):(r="add",l=void 0)}else if(this.deletes(o))r="delete",l=wn(o.content.getContent());else return;t.set(s,{action:r,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 Mt(Hi);const n=this.target,i=Pt(),s=Pt(),o=[];if(t={added:i,deleted:s,delta:o,keys:this.keys},this.transaction.changed.get(n).has(null)){let l=null;const c=()=>{l&&o.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 Sc=(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},Y=()=>{ks("Invalid access: Add Yjs type to a document before reading data.")},Ls=80;let li=0;class Cc{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=li++}}const kc=e=>{e.timestamp=li++},Us=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=li++},vc=(e,t,n)=>{if(e.length>=Ls){const i=e.reduce((s,o)=>s.timestamp<o.timestamp?s:o);return Us(i,t,n),i}else{const i=new Cc(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((o,r)=>Ue(t-o.index)<Ue(t-r.index)?o:r);let i=e._start,s=0;for(n!==null&&(i=n.p,s=n.index,kc(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&&Ue(n.index-s)<i.parent.length/Ls?(Us(n,i,s),n):vc(e._searchMarker,i,s)},ye=(e,t,n)=>{for(let i=e.length-1;i>=0;i--){const s=e[i];if(n>0){let o=s.p;for(o.marker=!1;o&&(o.deleted||!o.countable);)o=o.left,o&&!o.deleted&&o.countable&&(s.index-=o.length);if(o===null||o.marker===!0){e.splice(i,1);continue}s.p=o,o.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=Dt(t,s.index+n))}},un=(e,t,n)=>{const i=e,s=t.changedParentTypes;for(;Ct(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;As(i._eH,n,t)};class K{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Oi(),this._dEH=Oi(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw dt()}clone(){throw dt()}_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){Ri(this._eH,t)}observeDeep(t){Ri(this._dEH,t)}unobserve(t){Ni(this._eH,t)}unobserveDeep(t){Ni(this._dEH,t)}toJSON(){}}const Ps=(e,t,n)=>{e.doc??Y(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let i=n-t;const s=[];let o=e._start;for(;o!==null&&i>0;){if(o.countable&&!o.deleted){const r=o.content.getContent();if(r.length<=t)t-=r.length;else{for(let l=t;l<r.length&&i>0;l++)s.push(r[l]),i--;t=0}}o=o.right}return s},Vs=e=>{e.doc??Y();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},Fs=(e,t)=>{const n=[];let i=e._start;for(;i!==null;){if(i.countable&&Lt(i,t)){const s=i.content.getContent();for(let o=0;o<s.length;o++)n.push(s[o])}i=i.right}return n},Se=(e,t)=>{let n=0,i=e._start;for(e.doc??Y();i!==null;){if(i.countable&&!i.deleted){const s=i.content.getContent();for(let o=0;o<s.length;o++)t(s[o],n++,e)}i=i.right}},Hs=(e,t)=>{const n=[];return Se(e,(i,s)=>{n.push(t(i,s,e))}),n},_c=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}}}},$s=(e,t)=>{e.doc??Y();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}},Je=(e,t,n,i)=>{let s=n;const o=e.doc,r=o.clientID,l=o.store,c=n===null?t._start:n.right;let a=[];const h=()=>{a.length>0&&(s=new D(_(r,V(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new Ht(a)),s.integrate(e,0),a=[])};i.forEach(d=>{if(d===null)a.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(d);break;default:switch(h(),d.constructor){case Uint8Array:case ArrayBuffer:s=new D(_(r,V(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new Ee(new Uint8Array(d))),s.integrate(e,0);break;case $t:s=new D(_(r,V(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new Ie(d)),s.integrate(e,0);break;default:if(d instanceof K)s=new D(_(r,V(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new gt(d)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},zs=()=>Mt("Length exceeded!"),qs=(e,t,n,i)=>{if(n>t._length)throw zs();if(n===0)return t._searchMarker&&ye(t._searchMarker,n,i.length),Je(e,t,null,i);const s=n,o=dn(t,n);let r=t._start;for(o!==null&&(r=o.p,n-=o.index,n===0&&(r=r.prev,n+=r&&r.countable&&!r.deleted?r.length:0));r!==null;r=r.right)if(!r.deleted&&r.countable){if(n<=r.length){n<r.length&&Z(e,_(r.id.client,r.id.clock+n));break}n-=r.length}return t._searchMarker&&ye(t._searchMarker,s,i.length),Je(e,t,r,i)},Ec=(e,t,n)=>{let s=(t._searchMarker||[]).reduce((o,r)=>r.index>o.index?r:o,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return Je(e,t,s,n)},Ks=(e,t,n,i)=>{if(i===0)return;const s=n,o=i,r=dn(t,n);let l=t._start;for(r!==null&&(l=r.p,n-=r.index);l!==null&&n>0;l=l.right)!l.deleted&&l.countable&&(n<l.length&&Z(e,_(l.id.client,l.id.clock+n)),n-=l.length);for(;i>0&&l!==null;)l.deleted||(i<l.length&&Z(e,_(l.id.client,l.id.clock+i)),l.delete(e),i-=l.length),l=l.right;if(i>0)throw zs();t._searchMarker&&ye(t._searchMarker,s,-o+i)},Xe=(e,t,n)=>{const i=t._map.get(n);i!==void 0&&i.delete(e)},ci=(e,t,n,i)=>{const s=t._map.get(n)||null,o=e.doc,r=o.clientID;let l;if(i==null)l=new Ht([i]);else switch(i.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new Ht([i]);break;case Uint8Array:l=new Ee(i);break;case $t:l=new Ie(i);break;default:if(i instanceof K)l=new gt(i);else throw new Error("Unexpected content type")}new D(_(r,V(o.store,r)),s,s&&s.lastId,null,null,t,n,l).integrate(e,0)},ai=(e,t)=>{e.doc??Y();const n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Ws=e=>{const t={};return e.doc??Y(),e._map.forEach((n,i)=>{n.deleted||(t[i]=n.content.getContent()[n.length-1])}),t},Ys=(e,t)=>{e.doc??Y();const n=e._map.get(t);return n!==void 0&&!n.deleted},Ic=(e,t)=>{const n={};return e._map.forEach((i,s)=>{let o=i;for(;o!==null&&(!t.sv.has(o.id.client)||o.id.clock>=(t.sv.get(o.id.client)||0));)o=o.left;o!==null&&Lt(o,t)&&(n[s]=o.content.getContent()[o.length-1])}),n},je=e=>(e.doc??Y(),Kl(e._map.entries(),t=>!t[1].deleted));class Tc extends hn{}class Qt extends K{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 K?n.clone():n)),t}get length(){return this.doc??Y(),this._length}_callObserver(t,n){super._callObserver(t,n),un(this,t,new Tc(this,t))}insert(t,n){this.doc!==null?j(this.doc,i=>{qs(i,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?j(this.doc,n=>{Ec(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?j(this.doc,i=>{Ks(i,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return $s(this,t)}toArray(){return Vs(this)}slice(t=0,n=this.length){return Ps(this,t,n)}toJSON(){return this.map(t=>t instanceof K?t.toJSON():t)}map(t){return Hs(this,t)}forEach(t){Se(this,t)}[Symbol.iterator](){return _c(this)}_write(t){t.writeTypeRef(Qc)}}const Ac=e=>new Qt;class Dc extends hn{constructor(t,n,i){super(t,n),this.keysChanged=i}}class ie extends K{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 ie}clone(){const t=new ie;return this.forEach((n,i)=>{t.set(i,n instanceof K?n.clone():n)}),t}_callObserver(t,n){un(this,t,new Dc(this,t,n))}toJSON(){this.doc??Y();const t={};return this._map.forEach((n,i)=>{if(!n.deleted){const s=n.content.getContent()[n.length-1];t[i]=s instanceof K?s.toJSON():s}}),t}get size(){return[...je(this)].length}keys(){return kn(je(this),t=>t[0])}values(){return kn(je(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return kn(je(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??Y(),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=>{Xe(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?j(this.doc,i=>{ci(i,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return ai(this,t)}has(t){return Ys(this,t)}clear(){this.doc!==null?j(this.doc,t=>{this.forEach(function(n,i,s){Xe(t,s,i)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(ta)}}const Mc=e=>new ie,_t=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&Cl(e,t);class Hn{constructor(t,n,i,s){this.left=t,this.right=n,this.index=i,this.currentAttributes=s}forward(){switch(this.right===null&&tt(),this.right.content.constructor){case F:this.right.deleted||le(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 $i=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case F:t.right.deleted||le(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&Z(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},Oe=(e,t,n,i)=>{const s=new Map,o=i?dn(t,n):null;if(o){const r=new Hn(o.p.left,o.p,o.index,s);return $i(e,r,n-o.index)}else{const r=new Hn(null,t._start,0,s);return $i(e,r,n)}},Gs=(e,t,n,i)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===F&&_t(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,o=s.clientID;i.forEach((r,l)=>{const c=n.left,a=n.right,h=new D(_(o,V(s.store,o)),c,c&&c.lastId,a,a&&a.id,t,null,new F(l,r));h.integrate(e,0),n.right=h,n.forward()})},le=(e,t)=>{const{key:n,value:i}=t;i===null?e.delete(n):e.set(n,i)},Js=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===F&&_t(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},Xs=(e,t,n,i)=>{const s=e.doc,o=s.clientID,r=new Map;for(const l in i){const c=i[l],a=n.currentAttributes.get(l)??null;if(!_t(a,c)){r.set(l,a);const{left:h,right:d}=n;n.right=new D(_(o,V(s.store,o)),h,h&&h.lastId,d,d&&d.id,t,null,new F(l,c)),n.right.integrate(e,0),n.forward()}}return r},En=(e,t,n,i,s)=>{n.currentAttributes.forEach((f,g)=>{s[g]===void 0&&(s[g]=null)});const o=e.doc,r=o.clientID;Js(n,s);const l=Xs(e,t,n,s),c=i.constructor===String?new ft(i):i instanceof K?new gt(i):new zt(i);let{left:a,right:h,index:d}=n;t._searchMarker&&ye(t._searchMarker,n.index,c.getLength()),h=new D(_(r,V(o.store,r)),a,a&&a.lastId,h,h&&h.id,t,null,c),h.integrate(e,0),n.right=h,n.index=d,n.forward(),Gs(e,t,n,l)},zi=(e,t,n,i,s)=>{const o=e.doc,r=o.clientID;Js(n,s);const l=Xs(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,h=s[c];if(h!==void 0){if(_t(h,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&&Z(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+=`
3
+ `;n.right=new D(_(r,V(o.store,r)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new ft(c)),n.right.integrate(e,0),n.forward()}Gs(e,t,n,l)},Zs=(e,t,n,i,s)=>{let o=t;const r=ht();for(;o&&(!o.countable||o.deleted);){if(!o.deleted&&o.content.constructor===F){const a=o.content;r.set(a.key,a)}o=o.right}let l=0,c=!1;for(;t!==o;){if(n===t&&(c=!0),!t.deleted){const a=t.content;switch(a.constructor){case F:{const{key:h,value:d}=a,f=i.get(h)??null;(r.get(h)!==a||f===d)&&(t.delete(e),l++,!c&&(s.get(h)??null)===d&&f!==d&&(f===null?s.delete(h):s.set(h,f))),!c&&!t.deleted&&le(s,a);break}}}t=t.right}return l},jc=(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}},Oc=e=>{let t=0;return j(e.doc,n=>{let i=e._start,s=e._start,o=ht();const r=Mn(o);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case F:le(r,s.content);break;default:t+=Zs(n,i,s,o,r),o=Mn(r),i=s;break}s=s.right}}),t},Rc=e=>{const t=new Set,n=e.doc;for(const[i,s]of e.afterState.entries()){const o=e.beforeState.get(i)||0;s!==o&&Os(e,n.store.clients.get(i),o,s,r=>{!r.deleted&&r.content.constructor===F&&r.constructor!==rt&&t.add(r.parent)})}j(n,i=>{jt(e,e.deleteSet,s=>{if(s instanceof rt||!s.parent._hasFormatting||t.has(s.parent))return;const o=s.parent;s.content.constructor===F?t.add(o):jc(i,s)});for(const s of t)Oc(s)})},qi=(e,t,n)=>{const i=n,s=Mn(t.currentAttributes),o=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case gt:case zt:case ft:n<t.right.length&&Z(e,_(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}o&&Zs(e,o,t.right,s,t.currentAttributes);const r=(t.left||t.right).parent;return r._searchMarker&&ye(r._searchMarker,t.index,-i+n),t};class Nc extends hn{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,o=new Map;let r=this.target._start,l=null;const c={};let a="",h=0,d=0;const f=()=>{if(l!==null){let g=null;switch(l){case"delete":d>0&&(g={delete:d}),d=0;break;case"insert":(typeof a=="object"||a.length>0)&&(g={insert:a},s.size>0&&(g.attributes={},s.forEach((p,m)=>{p!==null&&(g.attributes[m]=p)}))),a="";break;case"retain":h>0&&(g={retain:h},yl(c)||(g.attributes=wl({},c))),h=0;break}g&&n.push(g),l=null}};for(;r!==null;){switch(r.content.constructor){case gt:case zt:this.adds(r)?this.deletes(r)||(f(),l="insert",a=r.content.getContent()[0],f()):this.deletes(r)?(l!=="delete"&&(f(),l="delete"),d+=1):r.deleted||(l!=="retain"&&(f(),l="retain"),h+=1);break;case ft:this.adds(r)?this.deletes(r)||(l!=="insert"&&(f(),l="insert"),a+=r.content.str):this.deletes(r)?(l!=="delete"&&(f(),l="delete"),d+=r.length):r.deleted||(l!=="retain"&&(f(),l="retain"),h+=r.length);break;case F:{const{key:g,value:p}=r.content;if(this.adds(r)){if(!this.deletes(r)){const m=s.get(g)??null;_t(m,p)?p!==null&&r.delete(i):(l==="retain"&&f(),_t(p,o.get(g)??null)?delete c[g]:c[g]=p)}}else if(this.deletes(r)){o.set(g,p);const m=s.get(g)??null;_t(m,p)||(l==="retain"&&f(),c[g]=m)}else if(!r.deleted){o.set(g,p);const m=c[g];m!==void 0&&(_t(m,p)?m!==null&&r.delete(i):(l==="retain"&&f(),p===null?delete c[g]:c[g]=p))}r.deleted||(l==="insert"&&f(),le(s,r.content));break}}r=r.right}for(f();n.length>0;){const g=n[n.length-1];if(g.retain!==void 0&&g.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class Ot extends K{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??Y(),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 Ot}clone(){const t=new Ot;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const i=new Nc(this,t,n);un(this,t,i),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??Y();let t="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===ft&&(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 Hn(null,this._start,0,new Map);for(let o=0;o<t.length;o++){const r=t[o];if(r.insert!==void 0){const l=!n&&typeof r.insert=="string"&&o===t.length-1&&s.right===null&&r.insert.slice(-1)===`
4
+ `?r.insert.slice(0,-1):r.insert;(typeof l!="string"||l.length>0)&&En(i,this,s,l,r.attributes||{})}else r.retain!==void 0?zi(i,this,s,r.retain,r.attributes||{}):r.delete!==void 0&&qi(i,s,r.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,i){this.doc??Y();const s=[],o=new Map,r=this.doc;let l="",c=this._start;function a(){if(l.length>0){const d={};let f=!1;o.forEach((p,m)=>{f=!0,d[m]=p});const g={insert:l};f&&(g.attributes=d),s.push(g),l=""}}const h=()=>{for(;c!==null;){if(Lt(c,t)||n!==void 0&&Lt(c,n))switch(c.content.constructor){case ft:{const d=o.get("ychange");t!==void 0&&!Lt(c,t)?(d===void 0||d.user!==c.id.client||d.type!=="removed")&&(a(),o.set("ychange",i?i("removed",c.id):{type:"removed"})):n!==void 0&&!Lt(c,n)?(d===void 0||d.user!==c.id.client||d.type!=="added")&&(a(),o.set("ychange",i?i("added",c.id):{type:"added"})):d!==void 0&&(a(),o.delete("ychange")),l+=c.content.str;break}case gt:case zt:{a();const d={insert:c.content.getContent()[0]};if(o.size>0){const f={};d.attributes=f,o.forEach((g,p)=>{f[p]=g})}s.push(d);break}case F:Lt(c,t)&&(a(),le(o,c.content));break}c=c.right}a()};return t||n?j(r,d=>{t&&Vn(d,t),n&&Vn(d,n),h()},"cleanup"):h(),s}insert(t,n,i){if(n.length<=0)return;const s=this.doc;s!==null?j(s,o=>{const r=Oe(o,this,t,!i);i||(i={},r.currentAttributes.forEach((l,c)=>{i[c]=l})),En(o,this,r,n,i)}):this._pending.push(()=>this.insert(t,n,i))}insertEmbed(t,n,i){const s=this.doc;s!==null?j(s,o=>{const r=Oe(o,this,t,!i);En(o,this,r,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=>{qi(s,Oe(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,o=>{const r=Oe(o,this,t,!1);r.right!==null&&zi(o,this,r,n,i)}):this._pending.push(()=>this.format(t,n,i))}removeAttribute(t){this.doc!==null?j(this.doc,n=>{Xe(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?j(this.doc,i=>{ci(i,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return ai(this,t)}getAttributes(){return Ws(this)}_write(t){t.writeTypeRef(ea)}}const Bc=e=>new Ot;class In{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??Y()}[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===W||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 K{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 K?n.clone():n)),t}get length(){return this.doc??Y(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new In(this,t)}querySelector(t){t=t.toUpperCase();const i=new In(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return i.done?null:i.value}querySelectorAll(t){return t=t.toUpperCase(),Vt(new In(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){un(this,t,new Pc(this,n,t))}toString(){return Hs(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),Se(this,o=>{s.insertBefore(o.toDOM(t,n,i),null)}),s}insert(t,n){this.doc!==null?j(this.doc,i=>{qs(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 K?t._item:t;Je(i,this,s,n)});else{const i=this._prelimContent,s=t===null?0:i.findIndex(o=>o===t)+1;if(s===0&&t!==null)throw Mt("Reference item not found");i.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?j(this.doc,i=>{Ks(i,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return Vs(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return $s(this,t)}slice(t=0,n=this.length){return Ps(this,t,n)}forEach(t){Se(this,t)}_write(t){t.writeTypeRef(ia)}}const Lc=e=>new Ft;class W 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 W(this.nodeName)}clone(){const t=new W(this.nodeName),n=this.getAttributes();return bl(n,(i,s)=>{t.setAttribute(s,i)}),t.insert(0,this.toArray().map(i=>i instanceof K?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 o=this.nodeName.toLocaleLowerCase(),r=n.length>0?" "+n.join(" "):"";return`<${o}${r}>${super.toString()}</${o}>`}removeAttribute(t){this.doc!==null?j(this.doc,n=>{Xe(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?j(this.doc,i=>{ci(i,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return ai(this,t)}hasAttribute(t){return Ys(this,t)}getAttributes(t){return t?Ic(this,t):Ws(this)}toDOM(t=document,n={},i){const s=t.createElement(this.nodeName),o=this.getAttributes();for(const r in o){const l=o[r];typeof l=="string"&&s.setAttribute(r,l)}return Se(this,r=>{s.appendChild(r.toDOM(t,n,i))}),i!==void 0&&i._createAssociation(s,this),s}_write(t){t.writeTypeRef(na),t.writeKey(this.nodeName)}}const Uc=e=>new W(e.readKey());class Pc extends hn{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 Ze extends ie{constructor(t){super(),this.hookName=t}_copy(){return new Ze(this.hookName)}clone(){const t=new Ze(this.hookName);return this.forEach((n,i)=>{t.set(i,n)}),t}toDOM(t=document,n={},i){const s=n[this.hookName];let o;return s!==void 0?o=s.createDom(this):o=document.createElement(this.hookName),o.setAttribute("data-yjs-hook",this.hookName),i!==void 0&&i._createAssociation(o,this),o}_write(t){t.writeTypeRef(sa),t.writeKey(this.hookName)}}const Vc=e=>new Ze(e.readKey());class Q extends Ot{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 Q}clone(){const t=new Q;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 o=[];for(const r in t.attributes[s])o.push({key:r,value:t.attributes[s][r]});o.sort((r,l)=>r.key<l.key?-1:1),n.push({nodeName:s,attrs:o})}n.sort((s,o)=>s.nodeName<o.nodeName?-1:1);let i="";for(let s=0;s<n.length;s++){const o=n[s];i+=`<${o.nodeName}`;for(let r=0;r<o.attrs.length;r++){const l=o.attrs[r];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(oa)}}const Fc=e=>new Q;class hi{constructor(t,n){this.id=t,this.length=n}get deleted(){throw dt()}mergeWith(t){return!1}write(t,n,i){throw dt()}integrate(t,n){throw dt()}}const Hc=0;class rt extends hi{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),js(t.doc.store,this)}write(t,n){t.writeInfo(Hc),t.writeLen(this.length-n)}getMissing(t,n){return null}}class Ee{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Ee(this.content)}splice(t){throw dt()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}const $c=e=>new Ee(e.readBuf());class Ce{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Ce(this.len)}splice(t){const n=new Ce(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){xe(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 zc=e=>new Ce(e.readLen()),Qs=(e,t)=>new $t({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Ie{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 Ie(Qs(this.doc.guid,this.opts))}splice(t){throw dt()}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 qc=e=>new Ie(Qs(e.readString(),e.readAny()));class zt{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new zt(this.embed)}splice(t){throw dt()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}const Kc=e=>new zt(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 dt()}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 Wc=e=>new F(e.readKey(),e.readJSON());class Qe{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Qe(this.arr)}splice(t){const n=new Qe(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 o=this.arr[s];t.writeString(o===void 0?"undefined":JSON.stringify(o))}}getRef(){return 2}}const Yc=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 Qe(n)},Gc=We("node_env")==="development";class Ht{constructor(t){this.arr=t,Gc&&ps(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Ht(this.arr)}splice(t){const n=new Ht(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 o=this.arr[s];t.writeAny(o)}}getRef(){return 8}}const Jc=e=>{const t=e.readLen(),n=[];for(let i=0;i<t;i++)n.push(e.readAny());return new Ht(n)};class ft{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new ft(this.str)}splice(t){const n=new ft(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 Xc=e=>new ft(e.readString()),Zc=[Ac,Mc,Bc,Uc,Lc,Vc,Fc],Qc=0,ta=1,ea=2,na=3,ia=4,sa=5,oa=6;class gt{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new gt(this.type._copy())}splice(t){throw dt()}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 ra=e=>new gt(Zc[e.readTypeRef()](e)),$n=(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 D);return{item:s,diff:i}},di=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},tn=(e,t,n)=>{const{client:i,clock:s}=t.id,o=new D(_(i,s+n),t,_(i,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&o.markDeleted(),t.keep&&(o.keep=!0),t.redone!==null&&(o.redone=_(t.redone.client,t.redone.clock+n)),t.right=o,o.right!==null&&(o.right.left=o),e._mergeStructs.push(o),o.parentSub!==null&&o.right===null&&o.parent._map.set(o.parentSub,o),t.length=n,o},Ki=(e,t)=>Mr(e,n=>re(n.deletions,t)),to=(e,t,n,i,s,o)=>{const r=e.doc,l=r.store,c=r.clientID,a=t.redone;if(a!==null)return Z(e,a);let h=t.parent._item,d=null,f;if(h!==null&&h.deleted===!0){if(h.redone===null&&(!n.has(h)||to(e,h,n,i,s,o)===null))return null;for(;h.redone!==null;)h=Z(e,h.redone)}const g=h===null?t.parent:h.content.type;if(t.parentSub===null){for(d=t.left,f=t;d!==null;){let b=d;for(;b!==null&&b.parent._item!==h;)b=b.redone===null?null:Z(e,b.redone);if(b!==null&&b.parent._item===h){d=b;break}d=d.left}for(;f!==null;){let b=f;for(;b!==null&&b.parent._item!==h;)b=b.redone===null?null:Z(e,b.redone);if(b!==null&&b.parent._item===h){f=b;break}f=f.right}}else if(f=null,t.right&&!s){for(d=t;d!==null&&d.right!==null&&(d.right.redone||re(i,d.right.id)||Ki(o.undoStack,d.right.id)||Ki(o.redoStack,d.right.id));)for(d=d.right;d.redone;)d=Z(e,d.redone);if(d&&d.right!==null)return null}else d=g._map.get(t.parentSub)||null;const p=V(l,c),m=_(c,p),w=new D(m,d,d&&d.lastId,f,f&&f.id,g,t.parentSub,t.content.copy());return t.redone=m,di(w,!0),w.integrate(e,0),w};class D extends hi{constructor(t,n,i,s,o,r,l,c){super(t,c.getLength()),this.origin=i,this.left=n,this.right=s,this.rightOrigin=o,this.parent=r,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?Ci:0}set marker(t){(this.info&yn)>0!==t&&(this.info^=yn)}get marker(){return(this.info&yn)>0}get keep(){return(this.info&Si)>0}set keep(t){this.keep!==t&&(this.info^=Si)}get countable(){return(this.info&Ci)>0}get deleted(){return(this.info&bn)>0}set deleted(t){this.deleted!==t&&(this.info^=bn)}markDeleted(){this.info|=bn}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=V(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=V(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Xt&&this.id.client!==this.parent.client&&this.parent.clock>=V(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Bi(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Z(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===rt||this.right&&this.right.constructor===rt)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===D?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===D&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Xt){const i=Zt(n,this.parent);i.constructor===rt?this.parent=null:this.parent=i.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=Bi(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 o=new Set,r=new Set;for(;s!==null&&s!==this.right;){if(r.add(s),o.add(s),De(this.origin,s.origin)){if(s.id.client<this.id.client)i=s,o.clear();else if(De(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&r.has(Zt(t.doc.store,s.origin)))o.has(Zt(t.doc.store,s.origin))||(i=s,o.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),js(t.doc.store,this),this.content.integrate(t,this),Ui(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new rt(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&&De(t.origin,this.lastId)&&this.right===t&&De(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(),xe(t.deleteSet,this.id.client,this.id.clock,this.length),Ui(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw tt();this.content.gc(t),n?dc(t,this,new rt(this.id,this.length)):this.content=new Ce(this.length)}write(t,n){const i=n>0?_(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,o=this.parentSub,r=this.content.getRef()&on|(i===null?0:G)|(s===null?0:bt)|(o===null?0:ge);if(t.writeInfo(r),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=we(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)):tt();o!==null&&t.writeString(o)}this.content.write(t,n)}}const eo=(e,t)=>la[t&on](e),la=[()=>{tt()},zc,Yc,$c,Xc,Kc,Wc,ra,Jc,qc,()=>{tt()}],ca=10;class lt extends hi{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){tt()}write(t,n){t.writeInfo(ca),A(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const no=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},io="__ $YJS$ __";no[io]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");no[io]=!0;const aa=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},ha=/[\uD800-\uDBFF]/,da=/[\uDC00-\uDFFF]/,ua=(e,t)=>{let n=0,i=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&ha.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&&da.test(e[e.length-i])&&i--,{index:n,remove:e.length-n-i,insert:t.slice(n,t.length-i)}},fa=ua,mt=(e,t)=>e>>>t|e<<32-t,ga=e=>mt(e,2)^mt(e,13)^mt(e,22),pa=e=>mt(e,6)^mt(e,11)^mt(e,25),ma=e=>mt(e,7)^mt(e,18)^e>>>3,xa=e=>mt(e,17)^mt(e,19)^e>>>10,wa=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]),ba=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class ya{constructor(){const t=new ArrayBuffer(320);this._H=new Uint32Array(t,0,8),this._H.set(ba),this._W=new Uint32Array(t,64,64)}_updateHash(){const t=this._H,n=this._W;for(let d=16;d<64;d++)n[d]=xa(n[d-2])+n[d-7]+ma(n[d-15])+n[d-16];let i=t[0],s=t[1],o=t[2],r=t[3],l=t[4],c=t[5],a=t[6],h=t[7];for(let d=0,f,g;d<64;d++)f=h+pa(l)+(l&c^~l&a)+wa[d]+n[d]>>>0,g=ga(i)+(i&s^i&o^s&o)>>>0,h=a,a=c,c=l,l=r+f>>>0,r=o,o=s,s=i,i=f+g>>>0;t[0]+=i,t[1]+=s,t[2]+=o,t[3]+=r,t[4]+=l,t[5]+=c,t[6]+=a,t[7]+=h}digest(t){let n=0;for(;n+56<=t.length;){let r=0;for(;r<16&&n+3<t.length;r++)this._W[r]=t[n++]<<24|t[n++]<<16|t[n++]<<8|t[n++];if(n%64!==0){for(this._W.fill(0,r,16);n<t.length;)this._W[r]|=t[n]<<(3-n%4)*8,n++;this._W[r]|=G<<(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 r=3;r>=0&&n<t.length;r--)this._W[s]|=t[n++]<<r*8;i||(this._W[s-(n%4===0?0:1)]|=G<<(3-n%4)*8),this._W[14]=t.byteLength/jr,this._W[15]=t.byteLength*8,this._updateHash();const o=new Uint8Array(32);for(let r=0;r<this._H.length;r++)for(let l=0;l<4;l++)o[r*4+l]=this._H[r]>>>(3-l)*8;return o}}const Sa=e=>new ya().digest(e),B=new E.PluginKey("y-sync"),yt=new E.PluginKey("y-undo");new E.PluginKey("yjs-cursor");const Ca=e=>{for(let n=6;n<e.length;n++)e[n%6]=e[n%6]^e[n];return e.slice(0,6)},ka=e=>Dl(Ca(Sa(Ml(e)))),en=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!re(t.ds,e.id),va=[{light:"#ecd44433",dark:"#ecd444"}],_a=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){const i=Pt();e.forEach(s=>i.add(s)),t=t.filter(s=>!i.has(s))}e.set(n,dl(t))}return e.get(n)},Ea=(e,{colors:t=va,colorMapping:n=new Map,permanentUserData:i=null,onFirstRender:s=()=>{},mapping:o}={})=>{let r=!1;const l=new Aa(e,o),c=new E.Plugin({props:{editable:a=>{const h=B.getState(a);return h.snapshot==null&&h.prevSnapshot==null}},key:B,state:{init:(a,h)=>({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,h)=>{const d=a.getMeta(B);if(d!==void 0){h=Object.assign({},h);for(const f in d)h[f]=d[f]}return h.addToHistory=a.getMeta("addToHistory")!==!1,h.isChangeOrigin=d!==void 0&&!!d.isChangeOrigin,h.isUndoRedoOperation=d!==void 0&&!!d.isChangeOrigin&&!!d.isUndoRedoOperation,l.prosemirrorView!==null&&d!==void 0&&(d.snapshot!=null||d.prevSnapshot!=null)&&ws(0,()=>{l.prosemirrorView!=null&&(d.restore==null?l._renderSnapshot(d.snapshot,d.prevSnapshot,h):(l._renderSnapshot(d.snapshot,d.snapshot,h),delete h.restore,delete h.snapshot,delete h.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),h}},view:a=>(l.initView(a),o==null&&l._forceRerender(),s(),{update:()=>{const h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(r||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(r=!0,h.addToHistory===!1&&!h.isChangeOrigin){const d=yt.getState(a.state),f=d&&d.undoManager;f&&f.stopCapturing()}l.mux(()=>{h.doc.transact(d=>{d.meta.set("addToHistory",h.addToHistory),l._prosemirrorChanged(a.state.doc)},B)})}},destroy:()=>{l.destroy()}})});return c},Ia=(e,t,n)=>{if(t!==null&&t.anchor!==null&&t.head!==null)if(t.type==="all")e.setSelection(new E.AllSelection(e.doc));else if(t.type==="node"){const i=fe(n.doc,n.type,t.anchor,n.mapping);e.setSelection(Ta(e,i))}else{const i=fe(n.doc,n.type,t.anchor,n.mapping),s=fe(n.doc,n.type,t.head,n.mapping);i!==null&&s!==null&&e.setSelection(E.TextSelection.between(e.doc.resolve(i),e.doc.resolve(s)))}},Ta=(e,t)=>{const n=e.doc.resolve(t);return n.nodeAfter?E.NodeSelection.create(e.doc,t):E.TextSelection.near(n)},zn=(e,t)=>({type:t.selection.jsonID,anchor:sn(t.selection.anchor,e.type,e.mapping),head:sn(t.selection.head,e.type,e.mapping)});class Aa{constructor(t,n=new Map){this.type=t,this.prosemirrorView=null,this.mux=aa(),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=zn(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()?(ms&&this._domSelectionInView===null&&(ws(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(),o=Ol.documentElement;return s.bottom>=0&&s.right>=0&&s.left<=(window.innerWidth||o.clientWidth||0)&&s.top<=(window.innerHeight||o.clientHeight||0)}renderSnapshot(t,n){n||(n=Ds(Es(),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=>He(i,this.prosemirrorView.state.schema,this)).filter(i=>i!==null),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new E.Slice(E.Fragment.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=>He(s,this.prosemirrorView.state.schema,this)).filter(s=>s!==null),i=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new E.Slice(E.Fragment.from(n),0,0));if(t){const s=te(Dt(t.anchor,0),i.doc.content.size),o=te(Dt(t.head,0),i.doc.content.size);i.setSelection(E.TextSelection.create(i.doc,s,o))}this.prosemirrorView.dispatch(i.setMeta(B,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(t,n,i){let s=this.doc,o=this.type;if(t||(t=_n(this.doc)),t instanceof Uint8Array||n instanceof Uint8Array)if((!(t instanceof Uint8Array)||!(n instanceof Uint8Array))&&tt(),s=new $t({gc:!1}),Pn(s,n),n=_n(s),Pn(s,t),t=_n(s),o._item===null){const r=Array.from(this.doc.share.keys()).find(l=>this.doc.share.get(l)===this.type);o=s.getXmlFragment(r)}else{const r=s.store.clients.get(o._item.id.client)??[],l=ut(r,o._item.id.clock);o=r[l].content.type}this.mapping.clear(),this.mux(()=>{s.transact(r=>{const l=i.permanentUserData;l&&l.dss.forEach(d=>{jt(r,d,f=>{})});const c=(d,f)=>{const g=d==="added"?l.getUserByClientId(f.client):l.getUserByDeletedId(f);return{user:g,type:d,color:_a(i.colorMapping,i.colors,g)}},a=Fs(o,new ri(n.ds,t.sv)).map(d=>!d._item.deleted||en(d._item,t)||en(d._item,n)?He(d,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},t,n,c):null).filter(d=>d!==null),h=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new E.Slice(E.Fragment.from(a),0,0));this.prosemirrorView.dispatch(h.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);jt(n,n.deleteSet,l=>{if(l.constructor===D){const c=l.content.type;c&&this.mapping.delete(c)}}),n.changed.forEach(s),n.changedParentTypes.forEach(s);const o=this.type.toArray().map(l=>so(l,this.prosemirrorView.state.schema,this)).filter(l=>l!==null);let r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new E.Slice(E.Fragment.from(o),0,0));Ia(r,this.beforeTransactionSelection,this),r=r.setMeta(B,{isChangeOrigin:!0,isUndoRedoOperation:n.origin instanceof Ns}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&r.scrollIntoView(),this.prosemirrorView.dispatch(r)})}_prosemirrorChanged(t){this.doc.transact(()=>{Kn(this.doc,this.type,t,this),this.beforeTransactionSelection=zn(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 so=(e,t,n,i,s,o)=>{const r=n.mapping.get(e);if(r===void 0){if(e instanceof W)return He(e,t,n,i,s,o);throw dt()}return r},He=(e,t,n,i,s,o)=>{const r=[],l=c=>{var a,h;if(c instanceof W){const d=so(c,t,n,i,s,o);d!==null&&r.push(d)}else{const d=(h=(a=c._item.right)==null?void 0:a.content)==null?void 0:h.type;d instanceof Ot&&!d._item.deleted&&d._item.id.client===d.doc.clientID&&(c.applyDelta([{retain:c.length},...d.toDelta()]),d.doc.transact(g=>{d._item.delete(g)}));const f=Da(c,t,n,i,s,o);f!==null&&f.forEach(g=>{g!==null&&r.push(g)})}};i===void 0||s===void 0?e.toArray().forEach(l):Fs(e,new ri(s.ds,i.sv)).forEach(l);try{const c=e.getAttributes(i);i!==void 0&&(en(e._item,i)?en(e._item,s)||(c.ychange=o?o("added",e._item.id):{type:"added"}):c.ychange=o?o("removed",e._item.id):{type:"removed"});const a=t.node(e.nodeName,c,r);return n.mapping.set(e,a),a}catch{return e.doc.transact(a=>{e._item.delete(a)},B),n.mapping.delete(e),null}},Da=(e,t,n,i,s,o)=>{const r=[],l=e.toDelta(i,s,o);try{for(let c=0;c<l.length;c++){const a=l[c];r.push(t.text(a.insert,Ba(a.attributes,t)))}}catch{return e.doc.transact(a=>{e._item.delete(a)},B),null}return r},Ma=(e,t)=>{const n=new Q,i=e.map(s=>({insert:s.text,attributes:ro(s.marks,t)}));return n.applyDelta(i),t.mapping.set(n,e),n},ja=(e,t)=>{const n=new W(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,fn(e).map(i=>qn(i,t))),t.mapping.set(n,e),n},qn=(e,t)=>e instanceof Array?Ma(e,t):ja(e,t),Wi=e=>typeof e=="object"&&e!==null,ui=(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 o=n[s],r=e[o],l=t[o];i=o==="ychange"||r===l||Wi(r)&&Wi(l)&&ui(r,l)}return i},fn=e=>{const t=e.content.content,n=[];for(let i=0;i<t.length;i++){const s=t[i];if(s.isText){const o=[];for(let r=t[i];i<t.length&&r.isText;r=t[++i])o.push(r);i--,n.push(o)}else n.push(s)}return n},oo=(e,t)=>{const n=e.toDelta();return n.length===t.length&&n.every((i,s)=>i.insert===t[s].text&&fs(i.attributes||{}).length===t[s].marks.length&&gs(i.attributes,(o,r)=>{var h;const l=fi(r),c=t[s].marks;return c.find(d=>d.type.name===l)?ui(o,(h=c.find(d=>d.type.name===l))==null?void 0:h.attrs):!1}))},ke=(e,t)=>{if(e instanceof W&&!(t instanceof Array)&&Wn(e,t)){const n=fn(t);return e._length===n.length&&ui(e.getAttributes(),t.attrs)&&e.toArray().every((i,s)=>ke(i,n[s]))}return e instanceof Q&&t instanceof Array&&oo(e,t)},nn=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((n,i)=>t[i]===n),Yi=(e,t,n)=>{const i=e.toArray(),s=fn(t),o=s.length,r=i.length,l=te(r,o);let c=0,a=0,h=!1;for(;c<l;c++){const d=i[c],f=s[c];if(nn(n.mapping.get(d),f))h=!0;else if(!ke(d,f))break}for(;c+a<l;a++){const d=i[r-a-1],f=s[o-a-1];if(nn(n.mapping.get(d),f))h=!0;else if(!ke(d,f))break}return{equalityFactor:c+a,foundMappedChild:h}},Oa=e=>{let t="",n=e._start;const i={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof ft?t+=n.content.str:n.content instanceof F&&(i[n.content.key]=null)),n=n.right;return{str:t,nAttrs:i}},Ra=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:i,str:s}=Oa(e),o=t.map(a=>({insert:a.text,attributes:Object.assign({},i,ro(a.marks,n))})),{insert:r,remove:l,index:c}=fa(s,o.map(a=>a.insert).join(""));e.delete(c,l),e.insert(c,r),e.applyDelta(o.map(a=>({retain:a.insert.length,attributes:a.attributes})))},Na=/(.*)(--[a-zA-Z0-9+/=]{8})$/,fi=e=>{var t;return((t=Na.exec(e))==null?void 0:t[1])??e},Ba=(e,t)=>{const n=[];for(const i in e)n.push(t.mark(fi(i),e[i]));return n},ro=(e,t)=>{const n={};return e.forEach(i=>{if(i.type.name!=="ychange"){const s=Ct(t.isOMark,i.type,()=>!i.type.excludes(i.type));n[s?`${i.type.name}--${ka(i.toJSON())}`:i.type.name]=i.attrs}}),n},Kn=(e,t,n,i)=>{if(t instanceof W&&t.nodeName!==n.type.name)throw new Error("node name mismatch!");if(i.mapping.set(t,n),t instanceof W){const d=t.getAttributes(),f=n.attrs;for(const g in f)f[g]!==null?d[g]!==f[g]&&g!=="ychange"&&t.setAttribute(g,f[g]):t.removeAttribute(g);for(const g in d)f[g]===void 0&&t.removeAttribute(g)}const s=fn(n),o=s.length,r=t.toArray(),l=r.length,c=te(o,l);let a=0,h=0;for(;a<c;a++){const d=r[a],f=s[a];if(!nn(i.mapping.get(d),f))if(ke(d,f))i.mapping.set(d,f);else break}for(;h+a+1<c;h++){const d=r[l-h-1],f=s[o-h-1];if(!nn(i.mapping.get(d),f))if(ke(d,f))i.mapping.set(d,f);else break}e.transact(()=>{for(;l-a-h>0&&o-a-h>0;){const f=r[a],g=s[a],p=r[l-h-1],m=s[o-h-1];if(f instanceof Q&&g instanceof Array)oo(f,g)||Ra(f,g,i),a+=1;else{let w=f instanceof W&&Wn(f,g),b=p instanceof W&&Wn(p,m);if(w&&b){const I=Yi(f,g,i),M=Yi(p,m,i);I.foundMappedChild&&!M.foundMappedChild?b=!1:!I.foundMappedChild&&M.foundMappedChild||I.equalityFactor<M.equalityFactor?w=!1:b=!1}w?(Kn(e,f,g,i),a+=1):b?(Kn(e,p,m,i),h+=1):(i.mapping.delete(t.get(a)),t.delete(a,1),t.insert(a,[qn(g,i)]),a+=1)}}const d=l-a-h;if(l===1&&o===0&&r[0]instanceof Q?(i.mapping.delete(r[0]),r[0].delete(0,r[0].length)):d>0&&(t.slice(a,a+d).forEach(f=>i.mapping.delete(f)),t.delete(a,d)),a+h<o){const f=[];for(let g=a;g<o-h;g++)f.push(qn(s[g],i));t.insert(a,f)}},B)},Wn=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,sn=(e,t,n)=>{if(e===0)return vn(t,0,-1);let i=t._first===null?null:t._first.content.type;for(;i!==null&&t!==i;){if(i instanceof Q){if(i._length>=e)return vn(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 Ge(i._item===null?null:i._item.id,i._item===null?we(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 Ge(i._item===null?null:i._item.id,i._item===null?we(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 tt();if(e===0&&i.constructor!==Q&&i!==t)return La(i._item.parent,i._item)}return vn(t,t._length,-1)},La=(e,t)=>{let n=null,i=null;return e._item===null?i=we(e):n=_(e._item.id.client,e._item.id.clock),new Ge(n,i,t.id)},fe=(e,t,n,i)=>{const s=ac(n,e);if(s===null||s.type!==t&&!be(t,s.type._item))return null;let o=s.type,r=0;if(o.constructor===Q)r=s.index;else if(o._item===null||!o._item.deleted){let l=o._first,c=0;for(;c<o._length&&c<s.index&&l!==null;){if(!l.deleted){const a=l.content.type;c++,a instanceof Q?r+=a._length:r+=i.get(a).nodeSize}l=l.right}r+=1}for(;o!==t&&o._item!==null;){const l=o._item.parent;if(l._item===null||!l._item.deleted){r+=1;let c=l._first;for(;c!==null;){const a=c.content.type;if(a===o)break;c.deleted||(a instanceof Q?r+=a._length:r+=i.get(a).nodeSize),c=c.right}}o=l}return r-1};function Ua(e){const t=e.toArray(),n=i=>{let s;if(i instanceof Q)s=i.toDelta().map(r=>{const l={type:"text",text:r.insert};return r.attributes&&(l.marks=Object.keys(r.attributes).map(c=>{const a=r.attributes[c],d={type:fi(c)};return Object.keys(a)&&(d.attrs=a),d})),l});else if(i instanceof W){s={type:i.nodeName};const o=i.getAttributes();Object.keys(o).length&&(s.attrs=o);const r=i.toArray();r.length&&(s.content=r.map(n).flat())}else tt();return s};return{type:"doc",content:t.map(n)}}const Pa=e=>{const t=yt.getState(e).undoManager;if(t!=null)return t.undo(),!0},Va=e=>{const t=yt.getState(e).undoManager;if(t!=null)return t.redo(),!0},Fa=new Set(["paragraph"]),Ha=(e,t)=>!(e instanceof D)||!(e.content instanceof gt)||!(e.content.type instanceof Ot||e.content.type instanceof W&&t.has(e.content.type.nodeName))||e.content.type._length===0,$a=({protectedNodes:e=Fa,trackedOrigins:t=[],undoManager:n=null}={})=>new E.Plugin({key:yt,state:{init:(i,s)=>{const o=B.getState(s),r=n||new Ns(o.type,{trackedOrigins:new Set([B].concat(t)),deleteFilter:l=>Ha(l,e),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:r,prevSel:null,hasUndoOps:r.undoStack.length>0,hasRedoOps:r.redoStack.length>0}},apply:(i,s,o,r)=>{const l=B.getState(r).binding,c=s.undoManager,a=c.undoStack.length>0,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:zn(l,o),hasUndoOps:a,hasRedoOps:h}:a!==s.hasUndoOps||h!==s.hasRedoOps?Object.assign({},s,{hasUndoOps:c.undoStack.length>0,hasRedoOps:c.redoStack.length>0}):s}},view:i=>{const s=B.getState(i.state),o=yt.getState(i.state).undoManager;return o.on("stack-item-added",({stackItem:r})=>{const l=s.binding;l&&r.meta.set(l,yt.getState(i.state).prevSel)}),o.on("stack-item-popped",({stackItem:r})=>{const l=s.binding;l&&(l.beforeTransactionSelection=r.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{o.destroy()}}}});function lo(e){return!!e.getMeta(B)}function za(e,t){const n=B.getState(e);return fe(n.doc,n.type,t,n.binding.mapping)||0}function co(e,t){const n=B.getState(e);return sn(t,n.type,n.binding.mapping)}var $e=class ao extends E.MappablePosition{constructor(t,n){super(t),this.yRelativePosition=n}static fromJSON(t){return new ao(t.position,t.yRelativePosition)}toJSON(){return{position:this.position,yRelativePosition:this.yRelativePosition}}};function qa(e,t){const n=co(t,e);return new $e(e,n)}function Ka(e,t,n){const i=e instanceof $e?e.yRelativePosition:null;if(lo(t)&&i){const r=za(n,i);return{position:new $e(r,i),mapResult:null}}const s=E.getUpdatedPosition(e,t),o=s.position.position;return{position:new $e(o,i??co(n,o)),mapResult:s.mapResult}}E.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)=>Ka(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>qa(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),yt.getState(t).undoManager.undoStack.length===0?!1:n?Pa(t):!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),yt.getState(t).undoManager.redoStack.length===0?!1:n?Va(t):!0)}},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo()}},addProseMirrorPlugins(){var e;const t=this.options.fragment?this.options.fragment:this.options.document.getXmlFragment(this.options.field),n=$a(this.options.yUndoOptions),i=n.spec.view;n.spec.view=r=>{const{undoManager:l}=yt.getState(r.state);l.restore&&(l.restore(),l.restore=()=>{});const c=i?i(r):void 0;return{destroy:()=>{const a=l.trackedOrigins.has(l),h=l._observers;l.restore=()=>{a&&l.trackedOrigins.add(l),l.doc.on("afterTransaction",l.afterTransactionHandler),l._observers=h},c!=null&&c.destroy&&c.destroy()}}};const s={...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender},o=Ea(t,s);return this.editor.options.enableContentCheck&&((e=t.doc)==null||e.on("beforeTransaction",()=>{try{const r=Ua(t);if(r.content.length===0)return;this.editor.schema.nodeFromJSON(r).check()}catch(r){return this.editor.emit("contentError",{error:r,editor:this.editor,disableCollaboration:()=>{var l;(l=t.doc)==null||l.destroy(),this.storage.isDisabled=!0}}),!1}})),[o,n,this.editor.options.enableContentCheck&&new J.Plugin({key:new J.PluginKey("filterInvalidContent"),filterTransaction:()=>{var r;return this.storage.isDisabled!==!1&&((r=t.doc)==null||r.destroy()),!0}})].filter(Boolean)}});function Gi(e){if(!e.length)return xn.DecorationSet.empty;const t=[],n=e[0].$from.node(0);return e.forEach(i=>{const s=i.$from.pos,o=i.$from.nodeAfter;o&&t.push(xn.Decoration.node(s,s+o.nodeSize,{class:"ProseMirror-selectednoderange"}))}),xn.DecorationSet.create(n,t)}function gn(e,t,n){const i=[],s=e.node(0);typeof n=="number"&&n>=0||(e.sameParent(t)?n=Math.max(0,e.sharedDepth(t.pos)-1):n=e.sharedDepth(t.pos));const o=new Bo.NodeRange(e,t,n),r=o.depth===0?0:s.resolve(o.start).posAtIndex(0);return o.parent.forEach((l,c)=>{const a=r+c,h=a+l.nodeSize;if(a<o.start||a>=o.end)return;const d=new J.SelectionRange(s.resolve(a),s.resolve(h));i.push(d)}),i}var Wa=class ho{constructor(t,n){this.anchor=t,this.head=n}map(t){return new ho(t.map(this.anchor),t.map(this.head))}resolve(t){const n=t.resolve(this.anchor),i=t.resolve(this.head);return new Et(n,i)}},Et=class vt extends J.Selection{constructor(t,n,i,s=1){const{doc:o}=t,r=t===n,l=t.pos===o.content.size&&n.pos===o.content.size,c=r&&!l?o.resolve(n.pos+(s>0?1:-1)):n,a=r&&l?o.resolve(t.pos-(s>0?1:-1)):t,h=gn(a.min(c),a.max(c),i),d=c.pos>=t.pos?h[0].$from:h[h.length-1].$to,f=c.pos>=t.pos?h[h.length-1].$to:h[0].$from;super(d,f,h),this.depth=i}get $to(){return this.ranges[this.ranges.length-1].$to}eq(t){return t instanceof vt&&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 vt(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),o=s[0].$from,r=s[s.length-1].$to;return new vt(o,r,this.depth)}const n=this.ranges[0],i=t.resolve(Math.max(0,n.$from.pos-1));return new vt(this.$anchor,i,this.depth)}extendForwards(){const{doc:t}=this.$from;if(this.isBackwards&&this.ranges.length>1){const s=this.ranges.slice(1),o=s[0].$from,r=s[s.length-1].$to;return new vt(r,o,this.depth)}const n=this.ranges[this.ranges.length-1],i=t.resolve(Math.min(t.content.size,n.$to.pos+1));return new vt(this.$anchor,i,this.depth)}static fromJSON(t,n){return new vt(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,i,s,o=1){return new this(t.resolve(n),t.resolve(i),s,o)}getBookmark(){return new Wa(this.anchor,this.head)}};Et.prototype.visible=!1;function Re(e){return e instanceof Et}E.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:o,tr:r}=i,{anchor:l,head:c}=o;if(!Re(o)){const h=Et.create(s,l,c,t,-1);return r.setSelection(h),n.dispatch(r),!0}const a=o.extendBackwards();return r.setSelection(a),n.dispatch(r),!0},"Shift-ArrowDown":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,selection:o,tr:r}=i,{anchor:l,head:c}=o;if(!Re(o)){const h=Et.create(s,l,c,t);return r.setSelection(h),n.dispatch(r),!0}const a=o.extendForwards();return r.setSelection(a),n.dispatch(r),!0},"Mod-a":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,tr:o}=i,r=Et.create(s,0,s.content.size,t);return o.setSelection(r),n.dispatch(o),!0}}},onSelectionUpdate(){const{selection:e}=this.editor.state;Re(e)&&this.editor.view.dom.classList.add("ProseMirror-noderangeselection")},addProseMirrorPlugins(){let e=!1,t=!1;return[new J.Plugin({key:new J.PluginKey("nodeRange"),props:{attributes:()=>e?{class:"ProseMirror-noderangeselection"}:{class:""},handleDOMEvents:{mousedown:(n,i)=>{const{key:s}=this.options,o=/Mac/.test(navigator.platform),r=!!i.shiftKey,l=!!i.ctrlKey,c=!!i.altKey,a=!!i.metaKey,h=o?a:l;return(s==null||s==="Shift"&&r||s==="Control"&&l||s==="Alt"&&c||s==="Meta"&&a||s==="Mod"&&h)&&(t=!0),t&&document.addEventListener("mouseup",()=>{t=!1;const{state:d}=n,{doc:f,selection:g,tr:p}=d,{$anchor:m,$head:w}=g;if(m.sameParent(w))return;const b=Et.create(f,m.pos,w.pos,this.options.depth);p.setSelection(b),n.dispatch(p)},{once:!0}),!1}},decorations:n=>{const{selection:i}=n,s=Re(i);if(e=!1,!t)return s?(e=!0,Gi(i.ranges)):null;const{$from:o,$to:r}=i;if(!s&&o.sameParent(r))return null;const l=gn(o,r,this.options.depth);return l.length?(e=!0,Gi(l)):null}}})]}});function Ya(e){let t="";const n=getComputedStyle(e);for(let i=0;i<n.length;i+=1)t+=`${n[i]}:${n.getPropertyValue(n[i])};`;return t}function Ga(e){const t=e.cloneNode(!0),n=[e,...Array.from(e.getElementsByTagName("*"))],i=[t,...Array.from(t.getElementsByTagName("*"))];return n.forEach((s,o)=>{i[o].style.cssText=Ya(s)}),t}function Ja(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 Xa(e,t,n,i=5){const s=e.dom,o=s.firstElementChild,r=s.lastElementChild;if(!o||!r)return{x:t,y:n};const l=o.getBoundingClientRect(),c=r.getBoundingClientRect(),a=Math.min(Math.max(l.top+i,n),c.bottom-i),h=.5,d=Math.abs(l.left-c.left)<h,f=Math.abs(l.right-c.right)<h;let g=l;return d&&f&&(g=l),{x:Math.min(Math.max(g.left+i,t),g.right-i),y:a}}var uo=e=>{const{x:t,y:n,editor:i}=e,{view:s,state:o}=i,{x:r,y:l}=Xa(s,t,n,5),c=s.root.elementsFromPoint(r,l);let a;if(Array.prototype.some.call(c,f=>{if(!s.dom.contains(f))return!1;const g=Ja(f,s);return g?(a=g,!0):!1}),!a)return{resultElement:null,resultNode:null,pos:null};let h;try{h=s.posAtDOM(a,0)}catch{return{resultElement:null,resultNode:null,pos:null}}const d=o.doc.nodeAt(h);if(!d){const f=o.doc.resolve(h),g=f.parent;return{resultElement:a,resultNode:g,pos:f.start()}}return{resultElement:a,resultNode:d,pos:h}};function Ne(e,t){return window.getComputedStyle(e)[t]}function Za(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function Qa(e,t,n){const i=parseInt(Ne(e.dom,"paddingLeft"),10),s=parseInt(Ne(e.dom,"paddingRight"),10),o=parseInt(Ne(e.dom,"borderLeftWidth"),10),r=parseInt(Ne(e.dom,"borderLeftWidth"),10),l=e.dom.getBoundingClientRect();return{left:Za(t,l.left+i+o,l.right-s-r),top:n}}function fo(e){var t;(t=e.parentNode)==null||t.removeChild(e)}function th(e,t){const{doc:n}=t.view.state,i=uo({editor:t,x:e.clientX,y:e.clientY});if(!i.resultNode||i.pos===null)return[];const s=e.clientX,o=Qa(t.view,s,e.clientY),r=t.view.posAtCoords(o);if(!r)return[];const{pos:l}=r;if(!n.resolve(l).parent)return[];const a=n.resolve(i.pos),h=n.resolve(i.pos+1);return gn(a,h,0)}function eh(e,t){const{view:n}=t;if(!e.dataTransfer)return;const{empty:i,$from:s,$to:o}=n.state.selection,r=th(e,t),l=gn(s,o,0),c=l.some(w=>r.find(b=>b.$from===w.$from&&b.$to===w.$to)),a=i||!c?r:l;if(!a.length)return;const{tr:h}=n.state,d=document.createElement("div"),f=a[0].$from.pos,g=a[a.length-1].$to.pos,p=Et.create(n.state.doc,f,g),m=p.content();a.forEach(w=>{const b=n.nodeDOM(w.$from.pos),I=Ga(b);d.append(I)}),d.style.position="absolute",d.style.top="-10000px",document.body.append(d),e.dataTransfer.clearData(),e.dataTransfer.setDragImage(d,0,0),n.dragging={slice:m,move:!0},h.setSelection(p),n.dispatch(h),document.addEventListener("drop",()=>fo(d),{once:!0})}var Ji=(e,t)=>{const n=e.resolve(t),{depth:i}=n;return i===0?t:n.pos-n.parentOffset-1},Xi=(e,t)=>{const n=e.nodeAt(t),i=e.resolve(t);let{depth:s}=i,o=n;for(;s>0;){const r=i.node(s);s-=1,s===0&&(o=r)}return o},Tn=(e,t)=>{const n=B.getState(e);return n?sn(t,n.type,n.binding.mapping):null},nh=(e,t)=>{const n=B.getState(e);return n?fe(n.doc,n.type,t,n.binding.mapping)||0:-1},Zi=(e,t)=>{let n=t;for(;n!=null&&n.parentNode&&n.parentNode!==e.dom;)n=n.parentNode;return n},go=new J.PluginKey("dragHandle"),po=({pluginKey:e=go,element:t,editor:n,computePositionConfig:i,getReferencedVirtualElement:s,onNodeChange:o,onElementDragStart:r,onElementDragEnd:l})=>{const c=document.createElement("div");let a=!1,h=null,d=-1,f,g=null,p=null;function m(){t&&(t.style.visibility="hidden",t.style.pointerEvents="none")}function w(){if(t){if(!n.isEditable){m();return}t.style.visibility="",t.style.pointerEvents="auto"}}function b(k){const L=(s==null?void 0:s())||{getBoundingClientRect:()=>k.getBoundingClientRect()};H.computePosition(L,t,i).then(T=>{Object.assign(t.style,{position:T.strategy,left:`${T.x}px`,top:`${T.y}px`})})}function I(k){r==null||r(k),eh(k,n),t&&(t.dataset.dragging="true"),setTimeout(()=>{t&&(t.style.pointerEvents="none")},0)}function M(k){l==null||l(k),m(),t&&(t.style.pointerEvents="auto",t.dataset.dragging="false")}return t.addEventListener("dragstart",I),t.addEventListener("dragend",M),c.appendChild(t),{unbind(){t.removeEventListener("dragstart",I),t.removeEventListener("dragend",M),g&&(cancelAnimationFrame(g),g=null,p=null)},plugin:new J.Plugin({key:typeof e=="string"?new J.PluginKey(e):e,state:{init(){return{locked:!1}},apply(k,L,T,S){const C=k.getMeta("lockDragHandle"),N=k.getMeta("hideDragHandle");if(C!==void 0&&(a=C),N)return m(),a=!1,h=null,d=-1,o==null||o({editor:n,node:null,pos:-1}),L;if(k.docChanged&&d!==-1&&t)if(lo(k)){const z=nh(S,f);z!==d&&(d=z)}else{const z=k.mapping.map(d);z!==d&&(d=z,f=Tn(S,d))}return L}},view:k=>{var L;return t.draggable=!0,t.style.pointerEvents="auto",t.dataset.dragging="false",(L=n.view.dom.parentElement)==null||L.appendChild(c),c.style.pointerEvents="none",c.style.position="absolute",c.style.top="0",c.style.left="0",{update(T,S){if(!t)return;if(!n.isEditable){m();return}if(a?t.draggable=!1:t.draggable=!0,k.state.doc.eq(S.doc)||d===-1)return;let C=k.nodeDOM(d);if(C=Zi(k,C),C===k.dom||(C==null?void 0:C.nodeType)!==1)return;const N=k.posAtDOM(C,0),z=Xi(n.state.doc,N),st=Ji(n.state.doc,N);h=z,d=st,f=Tn(k.state,d),o==null||o({editor:n,node:h,pos:d}),b(C)},destroy(){g&&(cancelAnimationFrame(g),g=null,p=null),t&&fo(c)}}},props:{handleDOMEvents:{keydown(k){return!t||a||k.hasFocus()&&(m(),h=null,d=-1,o==null||o({editor:n,node:null,pos:-1})),!1},mouseleave(k,L){return a||L.target&&!c.contains(L.relatedTarget)&&(m(),h=null,d=-1,o==null||o({editor:n,node:null,pos:-1})),!1},mousemove(k,L){return!t||a||(p={x:L.clientX,y:L.clientY},g)||(g=requestAnimationFrame(()=>{if(g=null,!p)return;const{x:T,y:S}=p;p=null;const C=uo({x:T,y:S,editor:n});if(!C.resultElement)return;let N=C.resultElement;if(N=Zi(k,N),N===k.dom||(N==null?void 0:N.nodeType)!==1)return;const z=k.posAtDOM(N,0),st=Xi(n.state.doc,z);if(st!==h){const Rt=Ji(n.state.doc,z);h=st,d=Rt,f=Tn(k.state,d),o==null||o({editor:n,node:h,pos:d}),b(N),w()}})),!1}}}})}},Yn={placement:"left-start",strategy:"absolute"};E.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}},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();return[po({computePositionConfig:{...Yn,...this.options.computePositionConfig},getReferencedVirtualElement:this.options.getReferencedVirtualElement,element:e,editor:this.editor,onNodeChange:this.options.onNodeChange,onElementDragStart:this.options.onElementDragStart,onElementDragEnd:this.options.onElementDragEnd}).plugin]}});var ih=e=>{const{className:t="drag-handle",children:n,editor:i,pluginKey:s=go,onNodeChange:o,onElementDragStart:r,onElementDragEnd:l,computePositionConfig:c=Yn}=e,[a,h]=x.useState(null),d=x.useRef(null);return x.useEffect(()=>{let f=null;return a?i.isDestroyed?()=>{d.current=null}:(d.current||(f=po({editor:i,element:a,pluginKey:s,computePositionConfig:{...Yn,...c},onElementDragStart:r,onElementDragEnd:l,onNodeChange:o}),d.current=f.plugin,i.registerPlugin(d.current)),()=>{i.unregisterPlugin(s),d.current=null,f&&(f.unbind(),f=null)}):()=>{d.current=null}},[a,i,o,s,c,r,l]),u.jsx("div",{className:t,style:{visibility:"hidden",position:"absolute"},"data-dragging":"false",ref:h,children:n})},sh=ih;function oh(){var T,S,C,N,z,st,Rt,Nt;const e=$.useEditorInstance(),t=X.useEditableEditor(),{t:n}=U.useLocale(),[i,s]=x.useState(null),[o,r]=x.useState(-1),[l,c]=x.useState(!1),a=(S=(T=e==null?void 0:e.extensionManager)==null?void 0:T.extensions)==null?void 0:S.some(v=>(v==null?void 0:v.name)===ns.TextAlign.name),h=(N=(C=e==null?void 0:e.extensionManager)==null?void 0:C.extensions)==null?void 0:N.some(v=>(v==null?void 0:v.name)===ae.Indent.name),d=(st=(z=e==null?void 0:e.extensionManager)==null?void 0:z.extensions)==null?void 0:st.some(v=>(v==null?void 0:v.name)===Lo.Clear.name);function f(){const v=e.chain();v.setNodeSelection(o).unsetAllMarks(),(i==null?void 0:i.type.name)!=="paragraph"&&v.setParagraph(),v.run()}function g(){e.chain().focus().setNodeSelection(o).run(),document.execCommand("copy")}function p(){e.commands.setNodeSelection(o);const{$anchor:v}=e.state.selection,xt=v.node(1)||e.state.selection.node;e.chain().setMeta("hideDragHandle",!0).insertContentAt(o+((i==null?void 0:i.nodeSize)||0),xt.toJSON()).run()}function m(v){e.commands.setTextAlign(v)}function w(){const v=ae.setNodeIndentMarkup(e.state.tr,o,1);v.setMeta("hideDragHandle",!0),e.view.dispatch&&e.view.dispatch(v)}function b(){const v=ae.setNodeIndentMarkup(e.state.tr,o,-1);e.view.dispatch&&e.view.dispatch(v)}function I(){e.chain().setMeta("hideDragHandle",!0).setNodeSelection(o).deleteSelection().run()}const M=x.useCallback(v=>{v.node&&s(v.node),r(v.pos),requestAnimationFrame(()=>{v.editor.commands.focus()})},[]),k=v=>{var xt;if(v.preventDefault(),o!==-1){const Te=(i==null?void 0:i.nodeSize)||0,qt=o+Te,gi=(i==null?void 0:i.type.name)==="paragraph"&&((xt=i==null?void 0:i.content)==null?void 0:xt.size)===0,mo=gi?o+2:qt+2;e.chain().command(({dispatch:pi,tr:pn,state:mi})=>pi?(gi?pn.insertText("/",o,o+1):pn.insert(qt,mi.schema.nodes.paragraph.create(null,[mi.schema.text("/")])),pi(pn)):!0).focus(mo).run()}};x.useEffect(()=>(l?e.commands.setMeta("lockDragHandle",!0):e.commands.setMeta("lockDragHandle",!1),()=>{e.commands.setMeta("lockDragHandle",!1)}),[l]);const L=v=>{t&&c(v)};return u.jsx(sh,{className:"richtext-transition-all richtext-duration-200 richtext-ease-out",editor:e,onNodeChange:M,pluginKey:"RichTextBubbleMenuDragHandle",children:u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-0.5",children:[u.jsx(y.ActionButton,{action:k,disabled:!t,icon:"Plus",tooltip:"Insert block"}),u.jsx(y.ActionButton,{disabled:!t,icon:"Grip",tooltip:"Click for options, Hold for drag",action:v=>{v.preventDefault(),v.stopPropagation(),L(!l)}}),u.jsxs(P.DropdownMenu,{onOpenChange:L,open:l,children:[u.jsx(P.DropdownMenuTrigger,{className:"richtext-pointer-events-none"}),u.jsxs(P.DropdownMenuContent,{align:"start",className:"richtext-w-48",hideWhenDetached:!0,side:"bottom",sideOffset:0,children:[u.jsxs(P.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:I,children:[u.jsx(nt.IconComponent,{name:"Trash2"}),u.jsx("span",{children:n("editor.remove")})]}),d?u.jsxs(P.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:f,children:[u.jsx(nt.IconComponent,{name:"PaintRoller"}),u.jsx("span",{children:n("editor.clear.tooltip")})]}):null,u.jsxs(P.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:g,children:[u.jsx(nt.IconComponent,{name:"Clipboard"}),u.jsx("span",{children:n("editor.copyToClipboard")})]}),u.jsxs(P.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:p,children:[u.jsx(nt.IconComponent,{name:"Copy"}),u.jsx("span",{children:n("editor.copy")})]}),a||h?u.jsx(P.DropdownMenuSeparator,{}):null,a?u.jsxs(P.DropdownMenuSub,{children:[u.jsxs(P.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[u.jsx(nt.IconComponent,{name:"AlignCenter"}),u.jsx("span",{children:n("editor.textalign.tooltip")})]}),u.jsx(P.DropdownMenuPortal,{children:u.jsxs(P.DropdownMenuSubContent,{children:[u.jsxs(P.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>m("left"),children:[u.jsx(nt.IconComponent,{name:"AlignLeft"}),u.jsx("span",{children:n("editor.textalign.left.tooltip")})]}),u.jsxs(P.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>m("center"),children:[u.jsx(nt.IconComponent,{name:"AlignCenter"}),u.jsx("span",{children:n("editor.textalign.center.tooltip")})]}),u.jsxs(P.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>m("right"),children:[u.jsx(nt.IconComponent,{name:"AlignRight"}),u.jsx("span",{children:n("editor.textalign.right.tooltip")})]})]})})]}):null,h?u.jsxs(P.DropdownMenuSub,{children:[u.jsxs(P.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[u.jsx(nt.IconComponent,{name:"IndentIncrease"}),u.jsx("span",{children:n("editor.indent")})]}),u.jsx(P.DropdownMenuPortal,{children:u.jsxs(P.DropdownMenuSubContent,{children:[u.jsxs(P.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((Rt=i==null?void 0:i.attrs)==null?void 0:Rt.indent)>=ae.IndentProps.max,onClick:w,children:[u.jsx(nt.IconComponent,{name:"IndentIncrease"}),u.jsx("span",{children:n("editor.indent.tooltip")})]}),u.jsxs(P.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((Nt=i==null?void 0:i.attrs)==null?void 0:Nt.indent)<=ae.IndentProps.min,onClick:b,children:[u.jsx(nt.IconComponent,{name:"IndentDecrease"}),u.jsx("span",{children:n("editor.outdent.tooltip")})]})]})})]}):null]})]})]})})}exports.RichTextBubbleCallout=Ho;exports.RichTextBubbleColumns=$o;exports.RichTextBubbleDrawer=or;exports.RichTextBubbleExcalidraw=lr;exports.RichTextBubbleIframe=cr;exports.RichTextBubbleImage=mr;exports.RichTextBubbleImageGif=xr;exports.RichTextBubbleKatex=hr;exports.RichTextBubbleLink=ur;exports.RichTextBubbleMenuDragHandle=oh;exports.RichTextBubbleMermaid=Cr;exports.RichTextBubbleTable=kr;exports.RichTextBubbleText=Er;exports.RichTextBubbleTwitter=Ir;exports.RichTextBubbleVideo=wr;