reactjs-tiptap-editor 1.0.6 → 1.0.7

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 (165) hide show
  1. package/lib/{ActionMenuButton-htJNI0Fa.js → ActionMenuButton-fTe9ka2F.js} +10 -13
  2. package/lib/ActionMenuButton-wU6jxKJv.cjs +1 -0
  3. package/lib/Attachment.cjs +2 -2
  4. package/lib/Attachment.js +23 -25
  5. package/lib/Blockquote.cjs +2 -2
  6. package/lib/Blockquote.js +5 -6
  7. package/lib/Bold.cjs +1 -1
  8. package/lib/Bold.js +5 -6
  9. package/lib/BulletList.cjs +1 -1
  10. package/lib/BulletList.js +11 -12
  11. package/lib/Clear.cjs +1 -1
  12. package/lib/Clear.js +3 -3
  13. package/lib/Code.cjs +1 -1
  14. package/lib/Code.js +9 -10
  15. package/lib/CodeBlock.cjs +39 -39
  16. package/lib/CodeBlock.js +837 -946
  17. package/lib/CodeView.cjs +1 -1
  18. package/lib/CodeView.js +8 -9
  19. package/lib/Color.cjs +1 -1
  20. package/lib/Color.js +20 -21
  21. package/lib/Column.cjs +1 -1
  22. package/lib/Column.js +5 -6
  23. package/lib/Drawer-BGSwHoka.cjs +1 -0
  24. package/lib/{Drawer-1211urKj.js → Drawer-DmtILKW4.js} +16 -17
  25. package/lib/Drawer.cjs +1 -1
  26. package/lib/Drawer.js +3 -3
  27. package/lib/Emoji.cjs +1 -1
  28. package/lib/Emoji.js +15 -16
  29. package/lib/Excalidraw-BG2U9i30.cjs +1 -0
  30. package/lib/{Excalidraw-Du3hBR8t.js → Excalidraw-CrG8fW-7.js} +31 -32
  31. package/lib/Excalidraw.cjs +1 -1
  32. package/lib/Excalidraw.js +2 -2
  33. package/lib/ExportPdf.cjs +1 -1
  34. package/lib/ExportPdf.js +17 -18
  35. package/lib/ExportWord.cjs +1 -1
  36. package/lib/ExportWord.js +5 -6
  37. package/lib/FontFamily.cjs +1 -1
  38. package/lib/FontFamily.js +5 -5
  39. package/lib/FontSize.cjs +1 -1
  40. package/lib/FontSize.js +5 -5
  41. package/lib/Heading.cjs +1 -1
  42. package/lib/Heading.js +15 -15
  43. package/lib/Highlight.cjs +1 -1
  44. package/lib/Highlight.js +10 -11
  45. package/lib/History.cjs +1 -1
  46. package/lib/History.js +8 -10
  47. package/lib/HorizontalRule.cjs +1 -1
  48. package/lib/HorizontalRule.js +5 -6
  49. package/lib/Icon-C3j4ls73.cjs +1 -0
  50. package/lib/{Icon-C-qYUAS1.js → Icon-CysGlJkv.js} +3 -4
  51. package/lib/{Iframe-DTYTLQE6.js → Iframe-BmqguWbj.js} +13 -14
  52. package/lib/Iframe-CXDghI6m.cjs +1 -0
  53. package/lib/Iframe.cjs +1 -1
  54. package/lib/Iframe.js +2 -2
  55. package/lib/Image.cjs +1 -1
  56. package/lib/Image.js +48 -49
  57. package/lib/ImageGif.cjs +1 -1
  58. package/lib/ImageGif.js +22 -23
  59. package/lib/ImportWord.cjs +2 -2
  60. package/lib/ImportWord.js +10 -11
  61. package/lib/Indent-B1glTHHl.cjs +1 -0
  62. package/lib/{Indent-jOPn3eUM.js → Indent-BhnGkEaY.js} +24 -25
  63. package/lib/Indent.cjs +1 -1
  64. package/lib/Indent.js +2 -2
  65. package/lib/Italic.cjs +1 -1
  66. package/lib/Italic.js +10 -11
  67. package/lib/Katex-BKL_6NWF.cjs +4 -0
  68. package/lib/{Katex-CERSrcTP.js → Katex-D4eBjS34.js} +21 -22
  69. package/lib/Katex.cjs +1 -1
  70. package/lib/Katex.js +2 -2
  71. package/lib/LineHeight.cjs +1 -1
  72. package/lib/LineHeight.js +15 -16
  73. package/lib/Link.cjs +1 -1
  74. package/lib/Link.js +2 -2
  75. package/lib/{LinkEditBlock-B5SdhOfa.js → LinkEditBlock-D1eSM0kn.js} +55 -56
  76. package/lib/{LinkEditBlock-DaxljgJC.cjs → LinkEditBlock-DW17TyCA.cjs} +2 -2
  77. package/lib/Mention.js +2 -2
  78. package/lib/Mermaid.cjs +2 -2
  79. package/lib/Mermaid.js +20 -20
  80. package/lib/MoreMark.cjs +1 -1
  81. package/lib/MoreMark.js +19 -21
  82. package/lib/OrderedList.cjs +1 -1
  83. package/lib/OrderedList.js +5 -6
  84. package/lib/SearchAndReplace.cjs +1 -1
  85. package/lib/SearchAndReplace.js +22 -23
  86. package/lib/SlashCommand.cjs +1 -1
  87. package/lib/SlashCommand.js +14 -14
  88. package/lib/Strike.cjs +1 -1
  89. package/lib/Strike.js +5 -6
  90. package/lib/{Table-39OkCQbu.js → Table-BIZppoiY.js} +7 -8
  91. package/lib/Table-CIzgfvr9.cjs +9 -0
  92. package/lib/Table.cjs +1 -1
  93. package/lib/Table.js +1 -1
  94. package/lib/TaskList.cjs +1 -1
  95. package/lib/TaskList.js +13 -14
  96. package/lib/TextAlign.cjs +1 -1
  97. package/lib/TextAlign.js +17 -19
  98. package/lib/TextDirection.cjs +1 -1
  99. package/lib/TextDirection.js +17 -19
  100. package/lib/TextUnderline.cjs +1 -1
  101. package/lib/TextUnderline.js +5 -6
  102. package/lib/{Twitter-D7PhLycr.js → Twitter-DhczYjbR.js} +21 -22
  103. package/lib/Twitter-DwWVNAV5.cjs +1 -0
  104. package/lib/Twitter.cjs +1 -1
  105. package/lib/Twitter.js +2 -2
  106. package/lib/Video.cjs +1 -1
  107. package/lib/Video.js +24 -25
  108. package/lib/bubble.cjs +4 -4
  109. package/lib/bubble.js +419 -421
  110. package/lib/button-B6ukqDUf.cjs +1 -0
  111. package/lib/{button-Crm67hfl.js → button-C81t4pb1.js} +3 -4
  112. package/lib/{checkbox-DViVmgJ6.js → checkbox-CUE9ex4D.js} +1 -1
  113. package/lib/{checkbox-NQC2MdGT.cjs → checkbox-ZdxysUFa.cjs} +1 -1
  114. package/lib/{dialog-DaHBd2zw.cjs → dialog-Cfx8yjkr.cjs} +1 -1
  115. package/lib/{dialog-Ce9Cjfft.js → dialog-DMJStzBb.js} +1 -1
  116. package/lib/{dropdown-menu-CQykJhBs.js → dropdown-menu-B8iyTZcP.js} +1 -1
  117. package/lib/{dropdown-menu-CSCDQtq0.cjs → dropdown-menu-Busg3FNn.cjs} +1 -1
  118. package/lib/{index-DuZCJJSp.js → index--knBGB61.js} +1118 -504
  119. package/lib/{index-nFjllrEl.js → index-BvYjBPF9.js} +7 -7
  120. package/lib/index-D42xFOzI.cjs +7 -0
  121. package/lib/{index-D-FhWysc.js → index-Dwt9--mS.js} +1 -1
  122. package/lib/{index-BeUrdBxf.js → index-RKufd2EL.js} +1 -1
  123. package/lib/{index-prphFVsp.js → index-ccgHvIfu.js} +1 -1
  124. package/lib/index.cjs +2 -2
  125. package/lib/index.js +8 -9
  126. package/lib/{input-tU3H__39.cjs → input-BxzQAIRv.cjs} +1 -1
  127. package/lib/{input-DfqFAyKo.js → input-DR_5pbuA.js} +1 -1
  128. package/lib/{isNumber-CTm1pIvN.js → isNumber-1y3eeW-y.js} +1 -1
  129. package/lib/label-BfWfLggp.cjs +1 -0
  130. package/lib/label-D-0oXKCn.js +18 -0
  131. package/lib/{popover-CoepUobG.js → popover-D3spkemr.js} +1 -1
  132. package/lib/{popover-CZWSQZ0q.cjs → popover-sP8CwbV-.cjs} +1 -1
  133. package/lib/{separator-6SnwzytZ.js → separator-rM48NeAo.js} +18 -18
  134. package/lib/{separator-DCQD8P6s.cjs → separator-yycaNdlI.cjs} +1 -1
  135. package/lib/{store-726Zjszt.cjs → store-BajRl43v.cjs} +1 -1
  136. package/lib/{store-ibARMQ3h.js → store-NKeQOve_.js} +1 -1
  137. package/lib/{tabs-DrkJL_C2.js → tabs-Cb6Bmpbb.js} +1 -1
  138. package/lib/{tabs-B_ArrG09.cjs → tabs-D2nCIOVL.cjs} +1 -1
  139. package/lib/{textarea-CIs52G8B.js → textarea-BYZu1lUC.js} +1 -1
  140. package/lib/{textarea-CmZVZKOo.cjs → textarea-Cbwi_h4h.cjs} +1 -1
  141. package/lib/{throttle-CGM5M2yG.js → throttle-CjwXmkIY.js} +1 -1
  142. package/lib/{updatePosition-DpMKxYdN.js → updatePosition-BAGpT34H.js} +1 -1
  143. package/lib/{useButtonProps-D0SrPzuG.js → useButtonProps-BIH_9bXT.js} +35 -47
  144. package/lib/useButtonProps-TfmRCM9r.cjs +1 -0
  145. package/package.json +5 -1
  146. package/lib/ActionMenuButton-DYT5chmX.cjs +0 -1
  147. package/lib/Drawer-DUFUd5BW.cjs +0 -1
  148. package/lib/Excalidraw-CajgZDjU.cjs +0 -1
  149. package/lib/Icon-BjR_or8V.cjs +0 -1
  150. package/lib/Iframe-CM6mRQmv.cjs +0 -1
  151. package/lib/Indent-BmhiEb0S.cjs +0 -1
  152. package/lib/Katex-CUd3LxLh.cjs +0 -4
  153. package/lib/Table-3VstSlg4.cjs +0 -9
  154. package/lib/Twitter-DuHPeVW1.cjs +0 -1
  155. package/lib/button-xNppt_aK.cjs +0 -1
  156. package/lib/index-BQ17A_37.js +0 -393
  157. package/lib/index-CNzHZDls.cjs +0 -7
  158. package/lib/index-DmOTQudI.cjs +0 -1
  159. package/lib/label-DC33TZy_.js +0 -19
  160. package/lib/label-DkDE77kc.cjs +0 -1
  161. package/lib/toggle-DVCNvcqp.cjs +0 -1
  162. package/lib/toggle-xchtz-Kf.js +0 -92
  163. package/lib/tooltip-BTFcHrd9.js +0 -24
  164. package/lib/tooltip-DFjcKu9a.cjs +0 -1
  165. package/lib/useButtonProps-bei1vI37.cjs +0 -1
package/lib/bubble.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var po=Object.create;var ui=Object.defineProperty;var mo=Object.getOwnPropertyDescriptor;var wo=Object.getOwnPropertyNames;var xo=Object.getPrototypeOf,bo=Object.prototype.hasOwnProperty;var yo=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of wo(t))!bo.call(e,s)&&s!==n&&ui(e,s,{get:()=>t[s],enumerable:!(i=mo(t,s))||i.enumerable});return e};var So=(e,t,n)=>(n=e!=null?po(xo(e)):{},yo(t||!e||!e.__esModule?ui(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("./index-DLqogznp.cjs"),H=require("./floating-ui.dom-VCrc58uF.cjs"),J=require("@tiptap/pm/state"),Ji=require("./Table-3VstSlg4.cjs"),Xi=require("react-dom"),y=require("./toggle-DVCNvcqp.cjs"),fi=require("./Column.cjs"),V=require("./index-FSRjMsxW.cjs"),K=require("./useButtonProps-bei1vI37.cjs"),tt=require("./index-CNzHZDls.cjs"),ye=require("./delete-node-CosiBes5.cjs"),Me=require("./Drawer-DUFUd5BW.cjs"),gi=require("easydrawer"),Ve=require("./shortId-Bfj8TyNr.cjs"),L=require("./dialog-DaHBd2zw.cjs"),Zi=require("./file-i7e4nQY2.cjs"),Jt=require("./button-xNppt_aK.cjs"),mt=require("./Katex-CUd3LxLh.cjs"),Nt=require("./separator-DCQD8P6s.cjs"),dn=require("./label-DkDE77kc.cjs"),un=require("./popover-CZWSQZ0q.cjs"),Oe=require("./input-tU3H__39.cjs"),zt=require("./Excalidraw-CajgZDjU.cjs"),qt=require("./Iframe-CM6mRQmv.cjs"),ko=require("katex"),pi=require("lucide-react"),Qi=require("./textarea-CmZVZKOo.cjs"),Re=require("./LinkEditBlock-DaxljgJC.cjs"),Co=require("./Image.cjs"),vo=require("./ImageGif.cjs"),_o=require("./Video.cjs"),En=require("./Mermaid.cjs"),Eo=require("./Bold.cjs"),Io=require("./Code.cjs");require("./index-DylewabB.cjs");const To=require("./Color.cjs"),Ao=require("./Highlight.cjs"),Do=require("./Italic.cjs"),Mo=require("./Strike.cjs"),ts=require("./TextAlign.cjs"),mi=require("./TextUnderline.cjs"),fn=require("./Twitter-DuHPeVW1.cjs"),gn=require("@tiptap/pm/view"),Oo=require("@tiptap/pm/model"),Ro=require("./Clear.cjs"),oe=require("./Indent-BmhiEb0S.cjs"),U=require("./dropdown-menu-CSCDQtq0.cjs"),rt=require("./Icon-BjR_or8V.cjs");function jo(e,t){const n=Math.min(e.top,t.top),i=Math.max(e.bottom,t.bottom),s=Math.min(e.left,t.left),r=Math.max(e.right,t.right)-s,l=i-n,c=s,a=n;return new DOMRect(c,a,r,l)}var No=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:d,state:h,from:f,to:g})=>{const{doc:p,selection:m}=h,{empty:b}=m,x=!p.textBetween(f,g).length&&E.isTextSelection(h.selection),A=this.element.contains(document.activeElement);return!(!(d.hasFocus()||A)||b||x||!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:d})=>{var h;if(this.editor.isDestroyed){this.destroy();return}if(this.preventHide){this.preventHide=!1;return}d!=null&&d.relatedTarget&&((h=this.element.parentNode)!=null&&h.contains(d.relatedTarget))||(d==null?void 0:d.relatedTarget)!==this.editor.view.dom&&this.hide()},this.handleDebouncedUpdate=(d,h)=>{const f=!(h!=null&&h.selection.eq(d.state.selection)),g=!(h!=null&&h.doc.eq(d.state.doc));!f&&!g||(this.updateDebounceTimer&&clearTimeout(this.updateDebounceTimer),this.updateDebounceTimer=window.setTimeout(()=>{this.updateHandler(d,f,g,h)},this.updateDelay))},this.updateHandler=(d,h,f,g)=>{const{composing:p}=d;if(p||!h&&!f)return;if(!this.getShouldShow(g)){this.hide();return}this.updatePosition(),this.show()},this.transactionHandler=({transaction:d})=>{d.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 Ji.CellSelection){const{$anchorCell:o,$headCell:r}=t,l=o?o.pos:r.pos,c=r?r.pos:o.pos,a=this.view.nodeDOM(l),d=this.view.nodeDOM(c);if(!a||!d)return;const h=a===d?a.getBoundingClientRect():jo(a.getBoundingClientRect(),d.getBoundingClientRect());s={getBoundingClientRect:()=>h,getClientRects:()=>[h]}}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 No({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 Bo=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:d}=c,h=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()||!d||!h||!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:d}=r;if(d||!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 Bo({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 nt=w.forwardRef(({pluginKey:e="bubbleMenu",editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:o=null,getReferencedVirtualElement:r,options:l,children:c,...a},d)=>{const h=w.useRef(document.createElement("div"));typeof d=="function"?d(h.current):d&&(d.current=h.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 b=h.current;b.style.visibility="hidden",b.style.position="absolute";const x=es({...m.current,editor:g,element:b});g.registerPlugin(x);const A=m.current.pluginKey;return()=>{g.unregisterPlugin(A),window.requestAnimationFrame(()=>{b.parentNode&&b.parentNode.removeChild(b)})}},[g]),Xi.createPortal(u.jsx("div",{...a,children:c}),h.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 d=c.current;if(d.style.visibility="hidden",d.style.position="absolute",t!=null&&t.isDestroyed||a!=null&&a.isDestroyed)return;const h=t||a;if(!h){console.warn("FloatingMenu component is not rendered inside of an editor component or does not have editor prop.");return}const f=ns({editor:h,element:d,pluginKey:e,appendTo:n,shouldShow:i,options:s});return h.registerPlugin(f),()=>{h.unregisterPlugin(e),window.requestAnimationFrame(()=>{d.parentNode&&d.parentNode.removeChild(d)})}},[t,a,n,e,i,s]),Xi.createPortal(u.jsx("div",{...r,children:o}),c.current)});function Uo(){const e=tt.useEditableEditor(),t=K.useEditorInstance(),{t:n}=V.useLocale(),i=w.useCallback(()=>t.isActive(fi.MultipleColumnNode.name),[t]),s=w.useCallback(()=>ye.deleteNode(fi.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(nt,{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 Lo(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 Po(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 Vo(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 Fo(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 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.setAlignImageMermaid)==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.setAlignImageDrawer)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function zo(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 qo(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 Ko(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()}}},...Lo(e,t),...Vo(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 Wo(e,t){return[...Po(e,t),...Fo(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 Yo(e,t){return[...Ho(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 Go(e,t){return[...$o(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 Jo(e,t){return[...qo(e,t),...zo(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 Xo({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,d=()=>{(async()=>{const S=document.querySelector("#easydrawer");S&&(o.current=new gi.Editor(S,{wheelEventsEnabled:!1,disableZoom:!0}),r.current=gi.makeDropdownToolbar(o.current),r.current.addDefaultToolWidgets(),o.current.loadFromSVG(decodeURIComponent(l)))})()};w.useEffect(()=>{i&&setTimeout(()=>{d()},200)},[i]);const h=async()=>{if(o.current){const I=o.current.toSVG(),S=I.outerHTML,k=`drawer-${Ve.shortId()}.svg`;let j=Ve.i(I.outerHTML);if(a){const $=Zi.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)},b=I=>{const S=o.current.toolController.getPrimaryTools()[5],k=r.current.getWidgetById("shape");S&&k&&(S.setColor(I),k.serializeState())},x=I=>{const S=o.current.toolController.getPrimaryTools()[5],k=r.current.getWidgetById("shape");S&&k&&(S.setThickness(I),k.serializeState())},A=I=>{const S=o.current.toolController.getPrimaryTools()[5],k=r.current.getWidgetById("shape");S&&k&&(S.setBorderColor(I),k.serializeState())},D=()=>{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;)D();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(Me.ControlDrawer,{changeBorderColorShape:A,changeColorShape:b,changeShape:m,onClear:B,onRedo:C,onThicknessChange:x,onUndo:D,refEditor:o,setColorHighlight:p,setColorPen:f,setThicknessPen:g})]}),u.jsx(L.DialogFooter,{children:u.jsx(Jt.Button,{onClick:h,type:"button",children:"Save changes"})})]})]})}function Zo({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?u.jsx(w.Fragment,{children:e.type==="divider"?u.jsx(Nt.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 Qo(){const{lang:e,t}=V.useLocale(),n=tt.useEditableEditor(),i=K.useEditorInstance(),s=mt.useAttributes(i,Me.Drawer.name),o=K.useExtension(Me.Drawer.name),r=({editor:c})=>{const{selection:a}=c.view.state,{$from:d,to:h}=a;let f=!1;return c.view.state.doc.nodesBetween(d.pos,h,g=>{if(g.type.name===Me.Drawer.name)return f=!0,!1}),f},l=w.useMemo(()=>Go(i,t),[i,e,t]);return n?u.jsx(nt,{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(Xo,{attrs:s,editor:i,extension:o},`bubbleMenu-drawer-${a}`):u.jsx(Zo,{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(un.Popover,{modal:!0,children:[u.jsx(un.PopoverTrigger,{asChild:!0,children:s}),u.jsx(un.PopoverContent,{children:u.jsxs("form",{className:"richtext-flex richtext-flex-col richtext-gap-2",onSubmit:c,children:[u.jsx(dn.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(Oe.Input,{onChange:a=>l({...r,width:a.target.value}),required:!0,type:"number",value:r.width})})}),u.jsx(dn.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(Oe.Input,{onChange:a=>l({...r,maxWidth:a.target.value}),required:!0,type:"number",value:r.maxWidth})})}),u.jsx(dn.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(Oe.Input,{onChange:a=>l({...r,height:a.target.value}),required:!0,type:"number",value:r.height})})}),u.jsx(Jt.Button,{className:"richtext-mt-2 richtext-self-end",type:"submit",children:o("editor.link.dialog.button.apply")})]})})]})},Rt=new Map;function tr(e){const t=e.options.element;Rt.has("width")||Rt.set("width",t.clientWidth),Rt.has("width")&&Rt.get("width")<=0&&Rt.set("width",t.clientWidth);const n={attributes:!0,childList:!0,subtree:!0},i=function(){Rt.set("width",t.clientWidth)},s=new MutationObserver(i);return s.observe(t,n),e.on("destroy",()=>{s.disconnect()}),{width:Rt.get("width")}}function er(){const e=tt.useEditableEditor(),t=K.useEditorInstance(),{t:n}=V.useLocale(),{width:i}=tr(t),s=mt.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]),d=w.useCallback(()=>{zt.triggerOpenExcalidrawSettingModal({...s,editor:t})},[t,s]),h=w.useCallback(()=>t.isActive(zt.Excalidraw.name),[t]),f=w.useCallback(()=>ye.deleteNode(zt.Excalidraw.name,t),[t]);return w.useEffect(()=>{o&&(d(),t.chain().updateAttributes(zt.Excalidraw.name,{defaultShowPicker:!1}).focus().run())},[r,o,t,d]),e?u.jsx(nt,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleExcalidraw",shouldShow:h,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:d,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 nr(){const e=tt.useEditableEditor(),t=K.useEditorInstance(),{t:n}=V.useLocale(),{width:i,height:s,src:o}=mt.useAttributes(t,qt.Iframe.name,{width:0,height:0,src:"",defaultShowPicker:!1}),[r,l]=w.useState(!1),[c,a]=w.useState(""),d=w.useCallback(x=>{var A;(A=x==null?void 0:x.preventDefault)==null||A.call(x),l(!1)},[l]);w.useEffect(()=>{r&&a(o)},[r,o]);const h=w.useCallback(x=>{var D;(D=x==null?void 0:x.preventDefault)==null||D.call(x);const A=qt.getServiceSrc(c);t.chain().updateAttributes(qt.Iframe.name,{src:(A==null?void 0:A.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(()=>{l(!0)},[l]),p=w.useCallback(x=>{t.chain().updateAttributes(qt.Iframe.name,x).setNodeSelection(t.state.selection.from).focus().run()},[t]),m=w.useCallback(()=>t.isActive(qt.Iframe.name)&&!o,[t,o]),b=w.useCallback(()=>ye.deleteNode(qt.Iframe.name,t),[t]);return e?u.jsxs(u.Fragment,{children:[u.jsx(nt,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleIframe",shouldShow:m,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.jsx(y.ActionButton,{action:g,icon:"Pencil",tooltip:"Open Edit Link"}),u.jsx(is,{height:s,onOk:p,width:i,children:u.jsx(y.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),u.jsx(y.ActionButton,{action:b,icon:"Trash2",tooltip:n("editor.delete")})]})}),u.jsxs(L.Dialog,{onOpenChange:l,open:r,children:[u.jsx(L.DialogTrigger,{}),u.jsxs(L.DialogContent,{children:[u.jsx(L.DialogHeader,{children:u.jsx(L.DialogTitle,{children:"Edit Link Iframe"})}),u.jsx(Oe.Input,{autoFocus:!0,onInput:x=>a(x.target.value),placeholder:"Enter link",type:"url",value:c}),u.jsxs(L.DialogFooter,{children:[u.jsx(Jt.Button,{onClick:d,type:"button",children:"Cancel"}),u.jsx(Jt.Button,{onClick:h,type:"button",children:"OK"})]})]})]})]}):u.jsx(u.Fragment,{})}function ir({children:e,visible:t,toggleVisible:n}){const{t:i}=V.useLocale(),s=K.useEditorInstance(),o=mt.useAttributes(s,mt.Katex.name,{text:"",defaultShowPicker:!1}),{text:r,defaultShowPicker:l}=o,[c,a]=w.useState(r||"");w.useEffect(()=>{t&&a(r||"")},[t]),w.useEffect(()=>{l&&(n(!0),s.chain().updateAttributes(mt.Katex.name,{defaultShowPicker:!1}).focus().run())},[s,l,n]);const d=w.useCallback(()=>{s.chain().focus().setKatex({text:c}).run(),a(""),n(!1)},[s,c,n]),h=w.useMemo(()=>{try{return ko.renderToString(`${c}`)}catch{return c}},[c]),f=w.useMemo(()=>`${c}`.trim()?h:null,[c,h]);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.jsx(Qi.Textarea,{autoFocus:!0,className:"richtext-flex-1",onChange:g=>a(g.target.value),placeholder:"Text",required:!0,rows:10,value:c,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:f||""},style:{height:"100%",borderWidth:1,minHeight:500,background:"#fff"}})]})}),u.jsx(L.DialogFooter,{children:u.jsx(Jt.Button,{onClick:d,type:"button",children:"Save changes"})})]})]})}function sr(){const e=tt.useEditableEditor(),t=K.useEditorInstance(),[n,i]=w.useState(!1),s=w.useCallback(()=>t.isActive(mt.Katex.name),[t]),o=w.useCallback(()=>ye.deleteNode(mt.Katex.name,t),[t]);return e?u.jsx(nt,{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(ir,{toggleVisible:i,visible:n,children:u.jsx(y.ActionButton,{action:()=>i(!n),tooltip:"Edit",children:u.jsx(pi.Pencil,{size:16})})}),u.jsx(y.ActionButton,{action:o,tooltip:"Delete",children:u.jsx(pi.Trash2,{size:16})})]})}):u.jsx(u.Fragment,{})}function or(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 rr(){const e=tt.useEditableEditor(),t=K.useEditorInstance(),[n,i]=w.useState(!1),s=mt.useAttributes(t,Re.Link.name),o=s==null?void 0:s.href,r=w.useCallback(({editor:d})=>d.isActive(Re.Link.name),[]),l=(d,h,f)=>{const g=t.state.selection,{from:p}=g,m=(h==null?void 0:h.length)??0,b=p+m;t.chain().extendMarkRange("link").insertContent({type:"text",text:h,marks:[{type:"link",attrs:{href:d,target:f?"_blank":""}}]}).setLink({href:d}).setTextSelection({from:p,to:b}).focus().run(),i(!1)},c=w.useCallback(()=>{t.chain().extendMarkRange("link").unsetLink().focus().run(),i(!1)},[t]),a=()=>{i(!1)};return e?u.jsx(nt,{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(Re.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(or,{editor:t,link:o,onClear:c,onEdit:()=>{i(!0)}})})})}):u.jsx(u.Fragment,{})}function qn({item:e,disabled:t,editor:n}){const i=e.component;return i?u.jsx(w.Fragment,{children:e.type==="divider"?u.jsx(Nt.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 lr(e){return e.type.name===Co.Image.name}function cr(e){return e.type.name===vo.ImageGif.name}function ar(e){return e.type.name===_o.Video.name}function hr(){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 d=!1;return r.view.state.doc.nodesBetween(c.pos,a,h=>{if(lr(h))return d=!0,!1}),d},o=w.useMemo(()=>Ko(i,t),[i,e,t]);return n?u.jsx(nt,{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(qn,{editor:i,item:r},`bubbleMenu-image-${l}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}function dr(){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 d=!1;return r.view.state.doc.nodesBetween(c.pos,a,h=>{if(cr(h))return d=!0,!1}),d},o=w.useMemo(()=>Wo(i,t),[i,t,e]);return n?u.jsx(nt,{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(qn,{editor:i,item:r},`bubbleMenu-image-gif-${l}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}function ur(){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,d=>{if(ar(d))return a=!0,!1}),a},s=w.useMemo(()=>Jo(n,e),[n,e]);return t?u.jsx(nt,{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(qn,{editor:n,item:o},`bubbleMenu-video-${r}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}const wi=`graph TB
2
- a-->b`,fr=({editor:e,attrs:t,extension:n})=>{const{alt:i,align:s}=t,[o,r]=w.useState(decodeURIComponent(i??wi)),[l,c]=w.useState(""),[a,d]=w.useState(!1),h=w.useRef(null),[f,g]=w.useState(null),p=n==null?void 0:n.options.upload,m=w.useCallback(D=>{D&&import("mermaid").then(C=>{g(C.default)})},[]),b=async D=>{try{const{svg:C}=await f.render("mermaid-svg",D);c(C)}catch{c("")}},x=()=>{f.initialize({darkMode:!1,startOnLoad:!1,fontSize:12,theme:"base"}),b(o)};w.useEffect(()=>{f&&a&&x()},[f,a]),w.useEffect(()=>{f&&a&&b(o)},[f,o]);const A=async()=>{if(o!==""){if(o){const D=h.current.querySelector("svg"),{width:C,height:B}=D.getBoundingClientRect(),I=`mermaid-${Ve.shortId()}.svg`;let S=Ve.i(D.outerHTML);if(p){const k=Zi.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)}d(!1)}};return u.jsxs(L.Dialog,{onOpenChange:d,open:a,children:[u.jsx(L.DialogTrigger,{asChild:!0,children:u.jsx(y.ActionButton,{action:()=>d(!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(Qi.Textarea,{autoFocus:!0,className:"richtext-flex-1",defaultValue:wi,onChange:D=>r(D.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:h,style:{height:"100%",border:"1px solid hsl(var(--border))",minHeight:500}})]})}),u.jsx(L.DialogFooter,{children:u.jsx(Jt.Button,{onClick:A,type:"button",children:"Save changes"})})]})]})};function gr({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?u.jsx(w.Fragment,{children:e.type==="divider"?u.jsx(Nt.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 pr(e){return e.type.name===En.Mermaid.name}function mr(){const{lang:e,t}=V.useLocale(),n=tt.useEditableEditor(),i=K.useEditorInstance(),s=mt.useAttributes(i,En.Mermaid.name),o=K.useExtension(En.Mermaid.name),r=({editor:c})=>{const{selection:a}=c.view.state,{$from:d,to:h}=a;let f=!1;return c.view.state.doc.nodesBetween(d.pos,h,g=>{if(pr(g))return f=!0,!1}),f},l=w.useMemo(()=>Yo(i,t),[i,e,t]);return n?u.jsx(nt,{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(fr,{attrs:s,editor:i,extension:o},`bubbleMenu-mermaid-${a}`):u.jsx(gr,{editor:i,item:c},`bubbleMenu-mermaid-${a}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}function wr({hiddenActions:e=[]}){var m,b,x,A,D,C,B,I,S,k,j,$,it,Mt,Ot,_,gt,se;const{t}=V.useLocale(),n=tt.useEditableEditor(),i=K.useEditorInstance(),s=({editor:$t})=>E.isActive($t.view.state,Ji.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 d(){i.chain().focus().addRowAfter().run()}function h(){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(nt,{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:!((b=(m=i==null?void 0:i.can())==null?void 0:m.addColumnBefore)!=null&&b.call(m)),icon:"BetweenHorizonalEnd",tooltip:t("editor.table.menu.insertColumnBefore"),tooltipOptions:{sideOffset:15}}),!o("addColumnAfter")&&u.jsx(y.ActionButton,{action:l,disabled:!((A=(x=i==null?void 0:i.can())==null?void 0:x.addColumnAfter)!=null&&A.call(x)),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:(D=i.can()).deleteColumn)!=null&&C.call(D)),icon:"DeleteColumn",tooltip:t("editor.table.menu.deleteColumn"),tooltipOptions:{sideOffset:15}}),u.jsx(Nt.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:d,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:h,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(Nt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!o("mergeCells")&&u.jsx(y.ActionButton,{action:f,disabled:!((Mt=(it=i==null?void 0:i.can())==null?void 0:it.mergeCells)!=null&&Mt.call(it)),icon:"TableCellsMerge",tooltip:t("editor.table.menu.mergeCells"),tooltipOptions:{sideOffset:15}}),!o("splitCells")&&u.jsx(y.ActionButton,{action:g,disabled:!((_=(Ot=i==null?void 0:i.can())==null?void 0:Ot.splitCell)!=null&&_.call(Ot)),icon:"TableCellsSplit",tooltip:t("editor.table.menu.splitCells"),tooltipOptions:{sideOffset:15}}),u.jsx(Nt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!o("deleteTable")&&u.jsx(y.ActionButton,{action:p,disabled:!((se=(gt=i==null?void 0:i.can())==null?void 0:gt.deleteTable)!=null&&se.call(gt)),icon:"Trash2",tooltip:t("editor.table.menu.deleteTable"),tooltipOptions:{sideOffset:15}})]})}):u.jsx(u.Fragment,{})}function xr(){return u.jsxs(u.Fragment,{children:[u.jsx(Eo.RichTextBold,{}),u.jsx(Do.RichTextItalic,{}),u.jsx(mi.RichTextUnderline,{}),u.jsx(mi.RichTextUnderline,{}),u.jsx(Mo.RichTextStrike,{}),u.jsx(Io.RichTextCode,{}),u.jsx(Re.RichTextLink,{}),u.jsx(Nt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),u.jsx(To.RichTextColor,{}),u.jsx(Ao.RichTextHighlight,{}),u.jsx(ts.RichTextAlign,{})]})}function br({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(nt,{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(xr,{})})}):u.jsx(u.Fragment,{})}function yr(){const{t:e}=V.useLocale(),t=tt.useEditableEditor(),n=K.useEditorInstance(),[i,s]=w.useState(!1),o=w.useCallback(({editor:c})=>c.isActive(fn.Twitter.name),[]),r=c=>{n.commands.updateTweet({src:c}),s(!1)},l=w.useCallback(()=>ye.deleteNode(fn.Twitter.name,n),[n]);return t?u.jsx(nt,{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(fn.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,In=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},Sr=(e,t)=>{const n=[];for(const[i,s]of e)n.push(t(s,i));return n},kr=(e,t)=>{for(const[n,i]of e)if(t(i,n))return!0;return!1},Ut=()=>new Set,pn=e=>e[e.length-1],Cr=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},Lt=Array.from,vr=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},Tn=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,je=Math.abs,Xt=(e,t)=>e<t?e:t,It=(e,t)=>e>t?e:t,os=e=>e!==0?e<0:1/e<0,xi=1,bi=2,mn=4,wn=8,he=32,bt=64,G=128,_r=1<<29,Qe=31,An=63,Bt=127,Er=2147483647,rs=Number.MAX_SAFE_INTEGER,Ir=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&St(e)===e),Tr=String.fromCharCode,Ar=e=>e.toLowerCase(),Dr=/^\s*/g,Mr=e=>e.replace(Dr,""),Or=/([A-Z])/g,yi=(e,t)=>Mr(e.replace(Or,n=>`${t}${Ar(n)}`)),Rr=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},de=typeof TextEncoder<"u"?new TextEncoder:null,jr=e=>de.encode(e),Nr=de?jr:Rr;let ce=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});ce&&ce.decode(new Uint8Array).length===1&&(ce=null);class Se{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const ke=()=>new Se,Br=e=>{const t=ke();return e(t),ct(t)},Ur=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(Ur(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},Lr=(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(It(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},Dn=z,T=(e,t)=>{for(;t>Bt;)z(e,G|Bt&t),t=St(t/128);z(e,Bt&t)},Kn=(e,t)=>{const n=os(t);for(n&&(t=-t),z(e,(t>An?G:0)|(n?bt:0)|An&t),t=St(t/64);t>0;)z(e,(t>Bt?G:0)|Bt&t),t=St(t/128)},Mn=new Uint8Array(3e4),Pr=Mn.length/3,Vr=(e,t)=>{if(t.length<Pr){const n=de.encodeInto(t,Mn).written||0;T(e,n);for(let i=0;i<n;i++)z(e,Mn[i])}else et(e,Nr(t))},Fr=(e,t)=>{const n=unescape(encodeURIComponent(t)),i=n.length;T(e,i);for(let s=0;s<i;s++)z(e,n.codePointAt(s))},Kt=de&&de.encodeInto?Vr:Fr,tn=(e,t)=>{const n=e.cbuf.length,i=e.cpos,s=Xt(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(It(n*2,o)),e.cbuf.set(t.subarray(s)),e.cpos=o)},et=(e,t)=>{T(e,t.byteLength),tn(e,t)},Wn=(e,t)=>{Lr(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Hr=(e,t)=>Wn(e,4).setFloat32(0,t,!1),$r=(e,t)=>Wn(e,8).setFloat64(0,t,!1),zr=(e,t)=>Wn(e,8).setBigInt64(0,t,!1),Si=new DataView(new ArrayBuffer(4)),qr=e=>(Si.setFloat32(0,e),Si.getFloat32(0)===e),Zt=(e,t)=>{switch(typeof t){case"string":z(e,119),Kt(e,t);break;case"number":Ir(t)&&je(t)<=Er?(z(e,125),Kn(e,t)):qr(t)?(z(e,124),Hr(e,t)):(z(e,123),$r(e,t));break;case"bigint":z(e,122),zr(e,t);break;case"object":if(t===null)z(e,126);else if(Tn(t)){z(e,117),T(e,t.length);for(let n=0;n<t.length;n++)Zt(e,t[n])}else if(t instanceof Uint8Array)z(e,116),et(e,t);else{z(e,118);const n=Object.keys(t);T(e,n.length);for(let i=0;i<n.length;i++){const s=n[i];Kt(e,s),Zt(e,t[s])}}break;case"boolean":z(e,t?120:121);break;default:z(e,127)}};class ki extends Se{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&T(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const Ci=e=>{e.count>0&&(Kn(e.encoder,e.count===1?e.s:-e.s),e.count>1&&T(e.encoder,e.count-2))};class Ne{constructor(){this.encoder=new Se,this.s=0,this.count=0}write(t){this.s===t?this.count++:(Ci(this),this.count=1,this.s=t)}toUint8Array(){return Ci(this),ct(this.encoder)}}const vi=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);Kn(e.encoder,t),e.count>1&&T(e.encoder,e.count-2)}};class xn{constructor(){this.encoder=new Se,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(vi(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return vi(this),ct(this.encoder)}}class Kr{constructor(){this.sarr=[],this.s="",this.lensE=new Ne}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 Se;return this.sarr.push(this.s),this.s="",Kt(t,this.sarr.join("")),tn(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 en{constructor(t){this.arr=t,this.pos=0}}const Yn=e=>new en(e),Wr=e=>e.pos!==e.arr.length,Yr=(e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},st=e=>Yr(e,R(e)),ue=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},Gn=e=>{let t=e.arr[e.pos++],n=t&An,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},Gr=e=>{let t=R(e);if(t===0)return"";{let n=String.fromCodePoint(ue(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(ue(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))}},Jr=e=>ce.decode(st(e)),On=ce?Jr:Gr,Jn=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},Xr=e=>Jn(e,4).getFloat32(0,!1),Zr=e=>Jn(e,8).getFloat64(0,!1),Qr=e=>Jn(e,8).getBigInt64(0,!1),tl=[e=>{},e=>null,Gn,Xr,Zr,Qr,e=>!1,e=>!0,On,e=>{const t=R(e),n={};for(let i=0;i<t;i++){const s=On(e);n[s]=Fe(e)}return n},e=>{const t=R(e),n=[];for(let i=0;i<t;i++)n.push(Fe(e));return n},st],Fe=e=>tl[127-ue(e)](e);class _i extends en{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Wr(this)?this.count=R(this)+1:this.count=-1),this.count--,this.s}}class Be extends en{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Gn(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 bn extends en{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=Gn(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 el{constructor(t){this.decoder=new Be(t),this.str=On(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 nl=crypto.getRandomValues.bind(crypto),il=Math.random,as=()=>nl(new Uint32Array(1))[0],sl=e=>e[St(il()*e.length)],ol="10000000-1000-4000-8000"+-1e11,rl=()=>ol.replace(/[018]/g,e=>(e^as()&15>>e/4).toString(16)),ll=Date.now,Ei=e=>new Promise(e);Promise.all.bind(Promise);const Ii=e=>e===void 0?null:e;class cl{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}}let hs=new cl,al=!0;try{typeof localStorage<"u"&&localStorage&&(hs=localStorage,al=!1)}catch{}const hl=hs,dl=Object.assign,ds=Object.keys,ul=(e,t)=>{for(const n in e)t(e[n],n)},Ti=e=>ds(e).length,fl=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},gl=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),pl=(e,t)=>e===t||Ti(e)===Ti(t)&&us(e,(n,i)=>(n!==void 0||gl(t,i))&&t[i]===n),ml=Object.freeze,fs=e=>{for(const t in e){const n=e[t];(typeof n=="object"||typeof n=="function")&&fs(e[t])}return ml(e)},Xn=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Xn(e,t,n+1)}},wl=(e,t)=>t.includes(e),Qt=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"&&!Qt;let pt;const xl=()=>{if(pt===void 0)if(Qt){pt=at();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=at(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){const[t,n]=e.split("=");pt.set(`--${yi(t,"-")}`,n),pt.set(`-${yi(t,"-")}`,n)}})):pt=at();return pt},Rn=e=>xl().has(e),He=e=>Ii(Qt?process.env[e.toUpperCase().replaceAll("-","_")]:hl.getItem(e)),ps=e=>Rn("--"+e)||He(e)!==null;ps("production");const bl=Qt&&wl(process.env.FORCE_COLOR,["true","1","2"]),yl=bl||!Rn("--no-colors")&&!ps("no-color")&&(!Qt||process.stdout.isTTY)&&(!Qt||Rn("--color")||He("COLORTERM")!==null||(He("TERM")||"").includes("color")),Sl=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=Tr(e[n]);return btoa(t)},kl=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),Cl=gs?Sl:kl,vl=e=>Br(t=>Zt(t,e));class _l{constructor(t,n){this.left=t,this.right=n}}const xt=(e,t)=>new _l(e,t),El=typeof document<"u"?document:{};typeof DOMParser<"u"&&new DOMParser;const Il=e=>Sr(e,(t,n)=>`${n}:${t};`).join(""),Tl=e=>class{constructor(n){this._=n}destroy(){e(this._)}},Al=Tl(clearTimeout),ms=(e,t)=>new Al(setTimeout(t,e)),Ct=Symbol,ws=Ct(),xs=Ct(),Dl=Ct(),Ml=Ct(),Ol=Ct(),bs=Ct(),Rl=Ct(),Zn=Ct(),jl=Ct(),Nl=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},Bl={[ws]:xt("font-weight","bold"),[xs]:xt("font-weight","normal"),[Dl]:xt("color","blue"),[Ol]:xt("color","green"),[Ml]:xt("color","grey"),[bs]:xt("color","red"),[Rl]:xt("color","purple"),[Zn]:xt("color","orange"),[jl]:xt("color","black")},Ul=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=Bl[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=Il(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=yl?Ul:Nl,Ll=(...e)=>{console.log(...ys(e)),ks.forEach(t=>t.print(e))},Ss=(...e)=>{console.warn(...ys(e)),e.unshift(Zn),ks.forEach(t=>t.print(e))},ks=Ut(),Cs=e=>({[Symbol.iterator](){return this},next:e}),Pl=(e,t)=>Cs(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),yn=(e,t)=>Cs(()=>{const{done:n,value:i}=e.next();return{done:n,value:n?void 0:t(i)}});class Qn{constructor(t,n){this.clock=t,this.len=n}}class ee{constructor(){this.clients=new Map}}const At=(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)}}),Vl=(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},ne=(e,t)=>{const n=e.clients.get(t.client);return n!==void 0&&Vl(n,t.clock)!==null},ti=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=It(s.len,o.clock+o.len-s.clock):(i<n&&(t[i]=o),i++)}t.length=i})},jn=e=>{const t=new ee;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++)Cr(o,e[r].clients.get(s)||[]);t.clients.set(s,o)}});return ti(t),t},fe=(e,t,n,i)=>{kt(e.clients,t,()=>[]).push(new Qn(n,i))},vs=()=>new ee,Fl=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 Qn(l,c))}}s.length>0&&t.clients.set(i,s)}),t},ei=(e,t)=>{T(e.restEncoder,t.clients.size),Lt(t.clients.entries()).sort((n,i)=>i[0]-n[0]).forEach(([n,i])=>{e.resetDsCurVal(),T(e.restEncoder,n);const s=i.length;T(e.restEncoder,s);for(let o=0;o<s;o++){const r=i[o];e.writeDsClock(r.clock),e.writeDsLen(r.len)}})},Hl=e=>{const t=new ee,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 Qn(e.readDsClock(),e.readDsLen()))}}return t},Ai=(e,t,n)=>{const i=new ee,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 d=0;d<l;d++){const h=e.readDsClock(),f=h+e.readDsLen();if(h<a){a<f&&fe(i,r,a,f-a);let g=dt(c,h),p=c[g];for(!p.deleted&&p.id.clock<h&&(c.splice(g+1,0,Ge(t,p,h-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,Ge(t,p,f-p.id.clock)),p.delete(t))}else fe(i,r,h,f-h)}}if(i.clients.size>0){const o=new nn;return T(o.restEncoder,0),ei(o,i),o.toUint8Array()}return null},_s=as;class Ft extends ss{constructor({guid:t=rl(),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 As,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=Ei(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const c=()=>Ei(a=>{const d=h=>{(h===void 0||h===!0)&&(this.off("sync",d),a())};this.on("sync",d)});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,Gt)}getText(t=""){return this.get(t,Dt)}getMap(t=""){return this.get(t,te)}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 $l{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 $e extends $l{constructor(t){super(t),this.keys=[],R(t),this.keyClockDecoder=new bn(st(t)),this.clientDecoder=new Be(st(t)),this.leftClockDecoder=new bn(st(t)),this.rightClockDecoder=new bn(st(t)),this.infoDecoder=new _i(st(t),ue),this.stringDecoder=new el(st(t)),this.parentInfoDecoder=new _i(st(t),ue),this.typeRefDecoder=new Be(st(t)),this.lenDecoder=new Be(st(t))}readLeftID(){return new Wt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Wt(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 Fe(this.restDecoder)}readBuf(){return st(this.restDecoder)}readJSON(){return Fe(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 zl{constructor(){this.restEncoder=ke()}toUint8Array(){return ct(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){T(this.restEncoder,t)}writeDsLen(t){T(this.restEncoder,t)}}class ql extends zl{writeLeftID(t){T(this.restEncoder,t.client),T(this.restEncoder,t.clock)}writeRightID(t){T(this.restEncoder,t.client),T(this.restEncoder,t.clock)}writeClient(t){T(this.restEncoder,t)}writeInfo(t){Dn(this.restEncoder,t)}writeString(t){Kt(this.restEncoder,t)}writeParentInfo(t){T(this.restEncoder,t?1:0)}writeTypeRef(t){T(this.restEncoder,t)}writeLen(t){T(this.restEncoder,t)}writeAny(t){Zt(this.restEncoder,t)}writeBuf(t){et(this.restEncoder,t)}writeJSON(t){Kt(this.restEncoder,JSON.stringify(t))}writeKey(t){Kt(this.restEncoder,t)}}class Kl{constructor(){this.restEncoder=ke(),this.dsCurrVal=0}toUint8Array(){return ct(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,T(this.restEncoder,n)}writeDsLen(t){t===0&&Q(),T(this.restEncoder,t-1),this.dsCurrVal+=t}}class nn extends Kl{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new xn,this.clientEncoder=new Ne,this.leftClockEncoder=new xn,this.rightClockEncoder=new xn,this.infoEncoder=new ki(Dn),this.stringEncoder=new Kr,this.parentInfoEncoder=new ki(Dn),this.typeRefEncoder=new Ne,this.lenEncoder=new Ne}toUint8Array(){const t=ke();return T(t,0),et(t,this.keyClockEncoder.toUint8Array()),et(t,this.clientEncoder.toUint8Array()),et(t,this.leftClockEncoder.toUint8Array()),et(t,this.rightClockEncoder.toUint8Array()),et(t,ct(this.infoEncoder)),et(t,this.stringEncoder.toUint8Array()),et(t,ct(this.parentInfoEncoder)),et(t,this.typeRefEncoder.toUint8Array()),et(t,this.lenEncoder.toUint8Array()),tn(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){Zt(this.restEncoder,t)}writeBuf(t){et(this.restEncoder,t)}writeJSON(t){Zt(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 Wl=(e,t,n,i)=>{i=It(i,t[0].id.clock);const s=dt(t,i);T(e.restEncoder,t.length-s),e.writeClient(n),T(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)}),sn(t).forEach((s,o)=>{n.has(o)||i.set(o,0)}),T(e.restEncoder,i.size),Lt(i.entries()).sort((s,o)=>o[0]-s[0]).forEach(([s,o])=>{Wl(e,t.clients.get(s),s,o)})},Yl=(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 d=e.readInfo();switch(Qe&d){case 0:{const h=e.readLen();r[a]=new ot(v(l,c),h),c+=h;break}case 10:{const h=R(e.restDecoder);r[a]=new lt(v(l,c),h),c+=h;break}default:{const h=(d&(bt|G))===0,f=new M(v(l,c),null,(d&G)===G?e.readLeftID():null,null,(d&bt)===bt?e.readRightID():null,h?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,h&&(d&he)===he?e.readString():null,Qs(e,d));r[a]=f,c+=f.length}}}}return n},Gl=(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 As,c=new Map,a=(g,p)=>{const m=c.get(g);(m==null||m>p)&&c.set(g,p)};let d=r.refs[r.i++];const h=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(b=>b!==p)}i.length=0};for(;;){if(d.constructor!==lt){const p=kt(h,d.id.client,()=>P(t,d.id.client))-d.id.clock;if(p<0)i.push(d),a(d.id.client,d.id.clock-1),f();else{const m=d.getMissing(e,t);if(m!==null){i.push(d);const b=n.get(m)||{refs:[],i:0};if(b.refs.length===b.i)a(m,P(t,m)),f();else{d=b.refs[b.i++];continue}}else(p===0||p<d.length)&&(d.integrate(e,p),h.set(d.id.client,d.id.clock+d.length))}}if(i.length>0)d=i.pop();else if(r!==null&&r.i<r.refs.length)d=r.refs[r.i++];else{if(r=o(),r===null)break;d=r.refs[r.i++]}}if(l.clients.size>0){const g=new nn;return Es(g,l,new Map),T(g.restEncoder,0),{missing:c,update:g.toUint8Array()}}return null},Jl=(e,t)=>Es(e,t.doc.store,t.beforeState),Xl=(e,t,n,i=new $e(e))=>O(t,s=>{s.local=!1;let o=!1;const r=s.doc,l=r.store,c=Yl(i,r),a=Gl(s,l,c),d=l.pendingStructs;if(d){for(const[f,g]of d.missing)if(g<P(l,f)){o=!0;break}if(a){for(const[f,g]of a.missing){const p=d.missing.get(f);(p==null||p>g)&&d.missing.set(f,g)}d.update=Li([d.update,a.update])}}else l.pendingStructs=a;const h=Ai(i,s,l);if(l.pendingDs){const f=new $e(Yn(l.pendingDs));R(f.restDecoder);const g=Ai(f,s,l);h&&g?l.pendingDs=Li([h,g]):l.pendingDs=h||g}else l.pendingDs=h;if(o){const f=l.pendingStructs.update;l.pendingStructs=null,Nn(s.doc,f)}},n,!1),Nn=(e,t,n,i=$e)=>{const s=Yn(t);Xl(s,e,n,new i(s))};class Zl{constructor(){this.l=[]}}const Di=()=>new Zl,Mi=(e,t)=>e.l.push(t),Oi=(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)=>Xn(e.l,[t,n]);class Wt{constructor(t,n){this.client=t,this.clock=n}}const _e=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,v=(e,t)=>new Wt(e,t),ge=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw Q()},pe=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1};class ze{constructor(t,n,i,s=0){this.type=t,this.tname=n,this.item=i,this.assoc=s}}class Ql{constructor(t,n,i=0){this.type=t,this.index=n,this.assoc=i}}const tc=(e,t,n=0)=>new Ql(e,t,n),Ee=(e,t,n)=>{let i=null,s=null;return e._item===null?s=ge(e):i=v(e._item.id.client,e._item.id.clock),new ze(i,s,t,n)},Sn=(e,t,n=0)=>{let i=e._start;if(n<0){if(t===0)return Ee(e,null,n);t--}for(;i!==null;){if(!i.deleted&&i.countable){if(i.length>t)return Ee(e,v(i.id.client,i.id.clock+t),n);t-=i.length}if(i.right===null&&n<0)return Ee(e,i.lastId,n);i=i.right}return Ee(e,null,n)},ec=(e,t)=>{const n=Yt(e,t),i=t.clock-n.id.clock;return{item:n,diff:i}},nc=(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 d=n?Pn(i,s):ec(i,s),h=d.item;if(!(h instanceof M))return null;if(c=h.parent,c._item===null||!c._item.deleted){a=h.deleted||!h.countable?0:d.diff+(l>=0?0:1);let f=h.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:d}=n?Pn(i,o):{item:Yt(i,o)};if(d instanceof M&&d.content instanceof ft)c=d.content.type;else return null}else throw Q();l>=0?a=c._length:a=0}return tc(c,a,e.assoc)};class ni{constructor(t,n){this.ds=t,this.sv=n}}const Ts=(e,t)=>new ni(e,t),kn=e=>Ts(Fl(e.store),sn(e.store)),jt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!ne(t.ds,e.id),Bn=(e,t)=>{const n=kt(e.meta,Bn,Ut),i=e.doc.store;n.has(t)||(t.sv.forEach((s,o)=>{s<P(i,o)&&X(e,v(o,s))}),At(e,t.ds,s=>{}),n.add(t))};class As{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const sn=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()},ic=(e,t)=>{const n=e.clients.get(t.client);return n[dt(n,t.clock)]},Yt=ic,Un=(e,t,n)=>{const i=dt(t,n),s=t[i];return s.id.clock<n&&s instanceof M?(t.splice(i+1,0,Ge(e,s,n-s.id.clock)),i+1):i},X=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[Un(e,n,t.clock)]},Ri=(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!==ot&&i.splice(s+1,0,Ge(e,o,n.clock-o.id.clock+1)),o},sc=(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=Un(e,t,n),l;do l=t[r++],o<l.id.clock+l.length&&Un(e,t,o),s(l);while(r<t.length&&t[r].id.clock<o)};class oc{constructor(t,n,i){this.doc=t,this.deleteSet=new ee,this.beforeState=sn(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 ji=(e,t)=>t.deleteSet.clients.size===0&&!kr(t.afterState,(n,i)=>t.beforeState.get(i)!==n)?!1:(ti(t.deleteSet),Jl(e,t),ei(e,t.deleteSet),!0),Ni=(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)},Ue=(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 M&&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},rc=(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),d=o[a];a<o.length&&d.id.clock<c;d=o[++a]){const h=o[a];if(l.clock+l.len<=h.id.clock)break;h instanceof M&&h.deleted&&!h.keep&&n(h)&&h.gc(t,!1)}}}},lc=(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=Xt(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+Ue(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{ti(o),n.afterState=sn(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(d=>d.target._item===null||!d.target._item.deleted),c.forEach(d=>{d.currentTarget=a,d._path=null}),c.sort((d,h)=>d.path.length-h.path.length),Is(a._dEH,c,n))})}),l.push(()=>i.emit("afterTransaction",[n,i])),Xn(l,[]),n._needFormattingCleanup&&Ic(n)}finally{i.gc&&rc(o,s,i.gcFilter),lc(o,s),n.afterState.forEach((d,h)=>{const f=n.beforeState.get(h)||0;if(f!==d){const g=s.clients.get(h),p=It(dt(g,f),1);for(let m=g.length-1;m>=p;)m-=1+Ue(g,m)}});for(let d=r.length-1;d>=0;d--){const{client:h,clock:f}=r[d].id,g=s.clients.get(h),p=dt(g,f);p+1<g.length&&Ue(g,p+1)>1||p>0&&Ue(g,p)}if(!n.local&&n.afterState.get(i.clientID)!==n.beforeState.get(i.clientID)&&(Ll(Zn,ws,"[yjs] ",xs,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 d=new ql;ji(d,n)&&i.emit("update",[d.toUint8Array(),n.origin,i,n])}if(i._observers.has("updateV2")){const d=new nn;ji(d,n)&&i.emit("updateV2",[d.toUint8Array(),n.origin,i,n])}const{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=n;(l.size>0||a.size>0||c.size>0)&&(l.forEach(d=>{d.clientID=i.clientID,d.collectionid==null&&(d.collectionid=i.collectionid),i.subdocs.add(d)}),a.forEach(d=>i.subdocs.delete(d)),i.emit("subdocs",[{loaded:c,added:l,removed:a},i,n]),a.forEach(d=>d.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 oc(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 cc{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const Bi=(e,t,n)=>{At(e,n.deletions,i=>{i instanceof M&&t.scope.some(s=>s===e.doc||pe(s,i))&&li(i,!1)})},Ui=(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(),d=new Set,h=[];let f=!1;At(l,a.insertions,g=>{if(g instanceof M){if(g.redone!==null){let{item:p,diff:m}=Pn(c,g.id);m>0&&(p=X(l,v(p.id.client,p.id.clock+m))),g=p}!g.deleted&&o.some(p=>p===l.doc||pe(p,g))&&h.push(g)}}),At(l,a.deletions,g=>{g instanceof M&&o.some(p=>p===l.doc||pe(p,g))&&!ne(a.insertions,g.id)&&d.add(g)}),d.forEach(g=>{f=Zs(l,g,d,a.insertions,e.ignoreRemoteMapChanges,e)!==null||f});for(let g=h.length-1;g>=0;g--){const p=h[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=Tn(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(b=>c.changedParentTypes.has(b)||b===this.doc)||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;const a=this.undoing,d=this.redoing,h=a?this.redoStack:this.undoStack;a?this.stopCapturing():d||this.clear(!1,!0);const f=new ee;c.afterState.forEach((b,x)=>{const A=c.beforeState.get(x)||0,D=b-A;D>0&&fe(f,x,A,D)});const g=ll();let p=!1;if(this.lastChange>0&&g-this.lastChange<this.captureTimeout&&h.length>0&&!a&&!d){const b=h[h.length-1];b.deletions=jn([b.deletions,c.deleteSet]),b.insertions=jn([b.insertions,f])}else h.push(new cc(c.deleteSet,f)),p=!0;!a&&!d&&(this.lastChange=g),At(c,c.deleteSet,b=>{b instanceof M&&this.scope.some(x=>x===c.doc||pe(x,b))&&li(b,!0)});const m=[{stackItem:h[h.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=Tn(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=>Bi(i,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>Bi(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=Ui(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=Ui(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*ac(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(v(s,o),c),o+=c}else if((Qe&l)!==0){const c=(l&(bt|G))===0,a=new M(v(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&he)===he?e.readString():null,Qs(e,l));yield a,o+=a.length}else{const c=e.readLen();yield new ot(v(s,o),c),o+=c}}}}class hc{constructor(t,n){this.gen=ac(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 dc{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const uc=(e,t)=>{if(e.constructor===ot){const{client:n,clock:i}=e.id;return new ot(v(n,i+t),e.length-t)}else if(e.constructor===lt){const{client:n,clock:i}=e.id;return new lt(v(n,i+t),e.length-t)}else{const n=e,{client:i,clock:s}=n.id;return new M(v(i,s+t),null,v(i,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Li=(e,t=$e,n=nn)=>{if(e.length===1)return e[0];const i=e.map(d=>new t(Yn(d)));let s=i.map(d=>new hc(d,!0)),o=null;const r=new n,l=new dc(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 d=s[0],h=d.curr.id.client;if(o!==null){let f=d.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=d.next(),g=!0;if(f===null||f.id.client!==h||g&&f.id.clock>o.struct.id.clock+o.struct.length)continue;if(h!==o.struct.id.client)le(l,o.struct,o.offset),o={struct:f,offset:0},d.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(v(h,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=uc(f,p)),o.struct.mergeWith(f)||(le(l,o.struct,o.offset),o={struct:f,offset:0},d.next())}}else o={struct:d.curr,offset:0},d.next();for(let f=d.curr;f!==null&&f.id.client===h&&f.id.clock===o.struct.id.clock+o.struct.length&&f.constructor!==lt;f=d.next())le(l,o.struct,o.offset),o={struct:f,offset:0}}o!==null&&(le(l,o.struct,o.offset),o=null),fc(l);const c=i.map(d=>Hl(d)),a=jn(c);return ei(r,a),r.toUint8Array()},js=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:ct(e.encoder.restEncoder)}),e.encoder.restEncoder=ke(),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),T(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},fc=e=>{js(e);const t=e.encoder.restEncoder;T(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const i=e.clientStructs[n];T(t,i.written),tn(t,i.restEncoder)}},Pi="You must not compute changes after the event-handler fired.";class on{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=gc(this.currentTarget,this.target))}deletes(t){return ne(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Tt(Pi);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=pn(c.content.getContent());else return;else c!==null&&this.deletes(c)?(r="update",l=pn(c.content.getContent())):(r="add",l=void 0)}else if(this.deletes(o))r="delete",l=pn(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(Pi);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 gc=(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 ii=0;class pc{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=ii++}}const mc=e=>{e.timestamp=ii++},Bs=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=ii++},wc=(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 pc(t,n);return e.push(i),i}},rn=(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)=>je(t-o.index)<je(t-r.index)?o:r);let i=e._start,s=0;for(n!==null&&(i=n.p,s=n.index,mc(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&&je(n.index-s)<i.parent.length/Ns?(Bs(n,i,s),n):wc(e._searchMarker,i,s)},me=(e,t,n)=>{for(let i=e.length-1;i>=0;i--){const s=e[i];if(n>0){let 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=It(t,s.index+n))}},ln=(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=Di(),this._dEH=Di(),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){Mi(this._eH,t)}observeDeep(t){Mi(this._dEH,t)}unobserve(t){Oi(this._eH,t)}unobserveDeep(t){Oi(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&&jt(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},xc=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=rn(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}},qe=(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 d=()=>{a.length>0&&(s=new M(v(r,P(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new Vt(a)),s.integrate(e,0),a=[])};i.forEach(h=>{if(h===null)a.push(h);else switch(h.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(h);break;default:switch(d(),h.constructor){case Uint8Array:case ArrayBuffer:s=new M(v(r,P(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new Ce(new Uint8Array(h))),s.integrate(e,0);break;case Ft:s=new M(v(r,P(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new ve(h)),s.integrate(e,0);break;default:if(h instanceof q)s=new M(v(r,P(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new ft(h)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),d()},Hs=()=>Tt("Length exceeded!"),$s=(e,t,n,i)=>{if(n>t._length)throw Hs();if(n===0)return t._searchMarker&&me(t._searchMarker,n,i.length),qe(e,t,null,i);const s=n,o=rn(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,v(r.id.client,r.id.clock+n));break}n-=r.length}return t._searchMarker&&me(t._searchMarker,s,i.length),qe(e,t,r,i)},bc=(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 qe(e,t,s,n)},zs=(e,t,n,i)=>{if(i===0)return;const s=n,o=i,r=rn(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,v(l.id.client,l.id.clock+n)),n-=l.length);for(;i>0&&l!==null;)l.deleted||(i<l.length&&X(e,v(l.id.client,l.id.clock+i)),l.delete(e),i-=l.length),l=l.right;if(i>0)throw Hs();t._searchMarker&&me(t._searchMarker,s,-o+i)},Ke=(e,t,n)=>{const i=t._map.get(n);i!==void 0&&i.delete(e)},si=(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 Ce(i);break;case Ft:l=new ve(i);break;default:if(i instanceof q)l=new ft(i);else throw new Error("Unexpected content type")}new M(v(r,P(o.store,r)),s,s&&s.lastId,null,null,t,n,l).integrate(e,0)},oi=(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},yc=(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&&jt(o,t)&&(n[s]=o.content.getContent()[o.length-1])}),n},Ie=e=>(e.doc??Y(),Pl(e._map.entries(),t=>!t[1].deleted));class Sc extends on{}class Gt extends q{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new Gt;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Gt}clone(){const t=new Gt;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),ln(this,t,new Sc(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=>{bc(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 xc(this)}_write(t){t.writeTypeRef(Kc)}}const kc=e=>new Gt;class Cc extends on{constructor(t,n,i){super(t,n),this.keysChanged=i}}class te 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 te}clone(){const t=new te;return this.forEach((n,i)=>{t.set(i,n instanceof q?n.clone():n)}),t}_callObserver(t,n){ln(this,t,new Cc(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[...Ie(this)].length}keys(){return yn(Ie(this),t=>t[0])}values(){return yn(Ie(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return yn(Ie(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=>{Ke(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?O(this.doc,i=>{si(i,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return oi(this,t)}has(t){return Ks(this,t)}clear(){this.doc!==null?O(this.doc,t=>{this.forEach(function(n,i,s){Ke(t,s,i)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Wc)}}const vc=e=>new te,_t=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&pl(e,t);class Ln{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||ie(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 Vi=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case F:t.right.deleted||ie(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&X(e,v(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},Te=(e,t,n,i)=>{const s=new Map,o=i?rn(t,n):null;if(o){const r=new Ln(o.p.left,o.p,o.index,s);return Vi(e,r,n-o.index)}else{const r=new Ln(null,t._start,0,s);return Vi(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,d=new M(v(o,P(s.store,o)),c,c&&c.lastId,a,a&&a.id,t,null,new F(l,r));d.integrate(e,0),n.right=d,n.forward()})},ie=(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:d,right:h}=n;n.right=new M(v(o,P(s.store,o)),d,d&&d.lastId,h,h&&h.id,t,null,new F(l,c)),n.right.integrate(e,0),n.forward()}}return r},Cn=(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:d,index:h}=n;t._searchMarker&&me(t._searchMarker,n.index,c.getLength()),d=new M(v(r,P(o.store,r)),a,a&&a.lastId,d,d&&d.id,t,null,c),d.integrate(e,0),n.right=d,n.index=h,n.forward(),Ws(e,t,n,l)},Fi=(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,d=s[c];if(d!==void 0){if(_t(d,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,v(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 M(v(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:d,value:h}=a,f=i.get(d)??null;(r.get(d)!==a||f===h)&&(t.delete(e),l++,!c&&(s.get(d)??null)===h&&f!==h&&(f===null?s.delete(d):s.set(d,f))),!c&&!t.deleted&&ie(s,a);break}}}t=t.right}return l},_c=(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}},Ec=e=>{let t=0;return O(e.doc,n=>{let i=e._start,s=e._start,o=at();const r=In(o);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case F:ie(r,s.content);break;default:t+=Js(n,i,s,o,r),o=In(r),i=s;break}s=s.right}}),t},Ic=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!==ot&&t.add(r.parent)})}O(n,i=>{At(e,e.deleteSet,s=>{if(s instanceof ot||!s.parent._hasFormatting||t.has(s.parent))return;const o=s.parent;s.content.constructor===F?t.add(o):_c(i,s)});for(const s of t)Ec(s)})},Hi=(e,t,n)=>{const i=n,s=In(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,v(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&&me(r._searchMarker,t.index,-i+n),t};class Tc extends on{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="",d=0,h=0;const f=()=>{if(l!==null){let g=null;switch(l){case"delete":h>0&&(g={delete:h}),h=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":d>0&&(g={retain:d},fl(c)||(g.attributes=dl({},c))),d=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"),h+=1):r.deleted||(l!=="retain"&&(f(),l="retain"),d+=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"),h+=r.length):r.deleted||(l!=="retain"&&(f(),l="retain"),d+=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(),ie(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 Dt 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 Dt}clone(){const t=new Dt;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const i=new Tc(this,t,n);ln(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 Ln(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)&&Cn(i,this,s,l,r.attributes||{})}else r.retain!==void 0?Fi(i,this,s,r.retain,r.attributes||{}):r.delete!==void 0&&Hi(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 h={};let f=!1;o.forEach((p,m)=>{f=!0,h[m]=p});const g={insert:l};f&&(g.attributes=h),s.push(g),l=""}}const d=()=>{for(;c!==null;){if(jt(c,t)||n!==void 0&&jt(c,n))switch(c.content.constructor){case ut:{const h=o.get("ychange");t!==void 0&&!jt(c,t)?(h===void 0||h.user!==c.id.client||h.type!=="removed")&&(a(),o.set("ychange",i?i("removed",c.id):{type:"removed"})):n!==void 0&&!jt(c,n)?(h===void 0||h.user!==c.id.client||h.type!=="added")&&(a(),o.set("ychange",i?i("added",c.id):{type:"added"})):h!==void 0&&(a(),o.delete("ychange")),l+=c.content.str;break}case ft:case Ht:{a();const h={insert:c.content.getContent()[0]};if(o.size>0){const f={};h.attributes=f,o.forEach((g,p)=>{f[p]=g})}s.push(h);break}case F:jt(c,t)&&(a(),ie(o,c.content));break}c=c.right}a()};return t||n?O(r,h=>{t&&Bn(h,t),n&&Bn(h,n),d()},"cleanup"):d(),s}insert(t,n,i){if(n.length<=0)return;const s=this.doc;s!==null?O(s,o=>{const r=Te(o,this,t,!i);i||(i={},r.currentAttributes.forEach((l,c)=>{i[c]=l})),Cn(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=Te(o,this,t,!i);Cn(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=>{Hi(s,Te(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=Te(o,this,t,!1);r.right!==null&&Fi(o,this,r,n,i)}):this._pending.push(()=>this.format(t,n,i))}removeAttribute(t){this.doc!==null?O(this.doc,n=>{Ke(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?O(this.doc,i=>{si(i,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return oi(this,t)}getAttributes(){return qs(this)}_write(t){t.writeTypeRef(Yc)}}const Ac=e=>new Dt;class vn{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 vn(this,t)}querySelector(t){t=t.toUpperCase();const i=new vn(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return i.done?null:i.value}querySelectorAll(t){return t=t.toUpperCase(),Lt(new vn(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){ln(this,t,new Oc(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;qe(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(Jc)}}const Dc=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 ul(n,(i,s)=>{typeof i=="string"&&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=>{Ke(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?O(this.doc,i=>{si(i,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return oi(this,t)}hasAttribute(t){return Ks(this,t)}getAttributes(t){return t?yc(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(Gc),t.writeKey(this.nodeName)}}const Mc=e=>new W(e.readKey());class Oc extends on{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 We extends te{constructor(t){super(),this.hookName=t}_copy(){return new We(this.hookName)}clone(){const t=new We(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(Xc),t.writeKey(this.hookName)}}const Rc=e=>new We(e.readKey());class Z extends Dt{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(Zc)}}const jc=e=>new Z;class ri{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 Nc=0;class ot extends ri{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(Nc),t.writeLen(this.length-n)}getMissing(t,n){return null}}class Ce{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Ce(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 Bc=e=>new Ce(e.readBuf());class xe{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new xe(this.len)}splice(t){const n=new xe(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){fe(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 Uc=e=>new xe(e.readLen()),Xs=(e,t)=>new Ft({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class ve{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 ve(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 Lc=e=>new ve(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 Pc=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 Vc=e=>new F(e.readKey(),e.readJSON());class Ye{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Ye(this.arr)}splice(t){const n=new Ye(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 Fc=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 Ye(n)},Hc=He("node_env")==="development";class Vt{constructor(t){this.arr=t,Hc&&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 $c=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 zc=e=>new ut(e.readString()),qc=[kc,vc,Ac,Mc,Dc,Rc,jc],Kc=0,Wc=1,Yc=2,Gc=3,Jc=4,Xc=5,Zc=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 Qc=e=>new ft(qc[e.readTypeRef()](e)),Pn=(e,t)=>{let n=t,i=0,s;do i>0&&(n=v(n.client,n.clock+i)),s=Yt(e,n),i=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof M);return{item:s,diff:i}},li=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Ge=(e,t,n)=>{const{client:i,clock:s}=t.id,o=new M(v(i,s+n),t,v(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=v(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},$i=(e,t)=>vr(e,n=>ne(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 d=t.parent._item,h=null,f;if(d!==null&&d.deleted===!0){if(d.redone===null&&(!n.has(d)||Zs(e,d,n,i,s,o)===null))return null;for(;d.redone!==null;)d=X(e,d.redone)}const g=d===null?t.parent:d.content.type;if(t.parentSub===null){for(h=t.left,f=t;h!==null;){let x=h;for(;x!==null&&x.parent._item!==d;)x=x.redone===null?null:X(e,x.redone);if(x!==null&&x.parent._item===d){h=x;break}h=h.left}for(;f!==null;){let x=f;for(;x!==null&&x.parent._item!==d;)x=x.redone===null?null:X(e,x.redone);if(x!==null&&x.parent._item===d){f=x;break}f=f.right}}else if(f=null,t.right&&!s){for(h=t;h!==null&&h.right!==null&&(h.right.redone||ne(i,h.right.id)||$i(o.undoStack,h.right.id)||$i(o.redoStack,h.right.id));)for(h=h.right;h.redone;)h=X(e,h.redone);if(h&&h.right!==null)return null}else h=g._map.get(t.parentSub)||null;const p=P(l,c),m=v(c,p),b=new M(m,h,h&&h.lastId,f,f&&f.id,g,t.parentSub,t.content.copy());return t.redone=m,li(b,!0),b.integrate(e,0),b};class M extends ri{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()?bi:0}set marker(t){(this.info&wn)>0!==t&&(this.info^=wn)}get marker(){return(this.info&wn)>0}get keep(){return(this.info&xi)>0}set keep(t){this.keep!==t&&(this.info^=xi)}get countable(){return(this.info&bi)>0}get deleted(){return(this.info&mn)>0}set deleted(t){this.deleted!==t&&(this.info^=mn)}markDeleted(){this.info|=mn}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===Wt&&this.id.client!==this.parent.client&&this.parent.clock>=P(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Ri(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===ot||this.right&&this.right.constructor===ot)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===M?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===M&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Wt){const i=Yt(n,this.parent);i.constructor===ot?this.parent=null:this.parent=i.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=Ri(t,t.doc.store,v(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),_e(this.origin,s.origin)){if(s.id.client<this.id.client)i=s,o.clear();else if(_e(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&r.has(Yt(t.doc.store,s.origin)))o.has(Yt(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),Ni(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new ot(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:v(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&_e(t.origin,this.lastId)&&this.right===t&&_e(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(),fe(t.deleteSet,this.id.client,this.id.clock,this.length),Ni(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw Q();this.content.gc(t),n?sc(t,this,new ot(this.id,this.length)):this.content=new xe(this.length)}write(t,n){const i=n>0?v(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,o=this.parentSub,r=this.content.getRef()&Qe|(i===null?0:G)|(s===null?0:bt)|(o===null?0:he);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=ge(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===Wt?(t.writeParentInfo(!1),t.writeLeftID(l)):Q();o!==null&&t.writeString(o)}this.content.write(t,n)}}const Qs=(e,t)=>ta[t&Qe](e),ta=[()=>{Q()},Uc,Fc,Bc,zc,Pc,Vc,Qc,$c,Lc,()=>{Q()}],ea=10;class lt extends ri{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(ea),T(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 na=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},ia=/[\uD800-\uDBFF]/,sa=/[\uDC00-\uDFFF]/,oa=(e,t)=>{let n=0,i=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&ia.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&&sa.test(e[e.length-i])&&i--,{index:n,remove:e.length-n-i,insert:t.slice(n,t.length-i)}},ra=oa,wt=(e,t)=>e>>>t|e<<32-t,la=e=>wt(e,2)^wt(e,13)^wt(e,22),ca=e=>wt(e,6)^wt(e,11)^wt(e,25),aa=e=>wt(e,7)^wt(e,18)^e>>>3,ha=e=>wt(e,17)^wt(e,19)^e>>>10,da=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]),ua=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class fa{constructor(){const t=new ArrayBuffer(320);this._H=new Uint32Array(t,0,8),this._H.set(ua),this._W=new Uint32Array(t,64,64)}_updateHash(){const t=this._H,n=this._W;for(let h=16;h<64;h++)n[h]=ha(n[h-2])+n[h-7]+aa(n[h-15])+n[h-16];let i=t[0],s=t[1],o=t[2],r=t[3],l=t[4],c=t[5],a=t[6],d=t[7];for(let h=0,f,g;h<64;h++)f=d+ca(l)+(l&c^~l&a)+da[h]+n[h]>>>0,g=la(i)+(i&s^i&o^s&o)>>>0,d=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]+=d}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/_r,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 ga=e=>new fa().digest(e),N=new E.PluginKey("y-sync"),yt=new E.PluginKey("y-undo");new E.PluginKey("yjs-cursor");const pa=e=>{for(let n=6;n<e.length;n++)e[n%6]=e[n%6]^e[n];return e.slice(0,6)},ma=e=>Cl(pa(ga(vl(e)))),Je=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!ne(t.ds,e.id),wa=[{light:"#ecd44433",dark:"#ecd444"}],xa=(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,sl(t))}return e.get(n)},ba=(e,{colors:t=wa,colorMapping:n=new Map,permanentUserData:i=null,onFirstRender:s=()=>{},mapping:o}={})=>{let r=!1;const l=new ka(e,o),c=new E.Plugin({props:{editable:a=>{const d=N.getState(a);return d.snapshot==null&&d.prevSnapshot==null}},key:N,state:{init:(a,d)=>({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,d)=>{const h=a.getMeta(N);if(h!==void 0){d=Object.assign({},d);for(const f in h)d[f]=h[f]}return d.addToHistory=a.getMeta("addToHistory")!==!1,d.isChangeOrigin=h!==void 0&&!!h.isChangeOrigin,d.isUndoRedoOperation=h!==void 0&&!!h.isChangeOrigin&&!!h.isUndoRedoOperation,l.prosemirrorView!==null&&h!==void 0&&(h.snapshot!=null||h.prevSnapshot!=null)&&ms(0,()=>{l.prosemirrorView!=null&&(h.restore==null?l._renderSnapshot(h.snapshot,h.prevSnapshot,d):(l._renderSnapshot(h.snapshot,h.snapshot,d),delete d.restore,delete d.snapshot,delete d.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),d}},view:a=>(l.initView(a),o==null&&l._forceRerender(),s(),{update:()=>{const d=c.getState(a.state);if(d.snapshot==null&&d.prevSnapshot==null&&(r||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(r=!0,d.addToHistory===!1&&!d.isChangeOrigin){const h=yt.getState(a.state),f=h&&h.undoManager;f&&f.stopCapturing()}l.mux(()=>{d.doc.transact(h=>{h.meta.set("addToHistory",d.addToHistory),l._prosemirrorChanged(a.state.doc)},N)})}},destroy:()=>{l.destroy()}})});return c},ya=(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=ae(n.doc,n.type,t.anchor,n.mapping);e.setSelection(Sa(e,i))}else{const i=ae(n.doc,n.type,t.anchor,n.mapping),s=ae(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)))}},Sa=(e,t)=>{const n=e.doc.resolve(t);return n.nodeAfter?E.NodeSelection.create(e.doc,t):E.TextSelection.near(n)},Vn=(e,t)=>({type:t.selection.jsonID,anchor:Ze(t.selection.anchor,e.type,e.mapping),head:Ze(t.selection.head,e.type,e.mapping)});class ka{constructor(t,n=new Map){this.type=t,this.prosemirrorView=null,this.mux=na(),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=Vn(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=El.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=Ts(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=>Le(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=>Le(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=Xt(It(t.anchor,0),i.doc.content.size),o=Xt(It(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=kn(this.doc)),t instanceof Uint8Array||n instanceof Uint8Array)if((!(t instanceof Uint8Array)||!(n instanceof Uint8Array))&&Q(),s=new Ft({gc:!1}),Nn(s,n),n=kn(s),Nn(s,t),t=kn(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(h=>{At(r,h,f=>{})});const c=(h,f)=>{const g=h==="added"?l.getUserByClientId(f.client):l.getUserByDeletedId(f);return{user:g,type:h,color:xa(i.colorMapping,i.colors,g)}},a=Ps(o,new ni(n.ds,t.sv)).map(h=>!h._item.deleted||Je(h._item,t)||Je(h._item,n)?Le(h,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},t,n,c):null).filter(h=>h!==null),d=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new E.Slice(E.Fragment.from(a),0,0));this.prosemirrorView.dispatch(d.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);At(n,n.deleteSet,l=>{if(l.constructor===M){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));ya(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(()=>{Hn(this.doc,this.type,t,this),this.beforeTransactionSelection=Vn(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 Le(e,t,n,i,s,o);throw ht()}return r},Le=(e,t,n,i,s,o)=>{const r=[],l=c=>{var a,d;if(c instanceof W){const h=no(c,t,n,i,s,o);h!==null&&r.push(h)}else{const h=(d=(a=c._item.right)==null?void 0:a.content)==null?void 0:d.type;h instanceof Dt&&!h._item.deleted&&h._item.id.client===h.doc.clientID&&(c.applyDelta([{retain:c.length},...h.toDelta()]),h.doc.transact(g=>{h._item.delete(g)}));const f=Ca(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 ni(s.ds,i.sv)).forEach(l);try{const c=e.getAttributes(i);i!==void 0&&(Je(e._item,i)?Je(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}},Ca=(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,Aa(a.attributes,t)))}}catch{return e.doc.transact(a=>{e._item.delete(a)},N),null}return r},va=(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},_a=(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,cn(e).map(i=>Fn(i,t))),t.mapping.set(n,e),n},Fn=(e,t)=>e instanceof Array?va(e,t):_a(e,t),zi=e=>typeof e=="object"&&e!==null,ci=(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||zi(r)&&zi(l)&&ci(r,l)}return i},cn=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 d;const l=ai(r),c=t[s].marks;return c.find(h=>h.type.name===l)?ci(o,(d=c.find(h=>h.type.name===l))==null?void 0:d.attrs):!1}))},be=(e,t)=>{if(e instanceof W&&!(t instanceof Array)&&$n(e,t)){const n=cn(t);return e._length===n.length&&ci(e.getAttributes(),t.attrs)&&e.toArray().every((i,s)=>be(i,n[s]))}return e instanceof Z&&t instanceof Array&&io(e,t)},Xe=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((n,i)=>t[i]===n),qi=(e,t,n)=>{const i=e.toArray(),s=cn(t),o=s.length,r=i.length,l=Xt(r,o);let c=0,a=0,d=!1;for(;c<l;c++){const h=i[c],f=s[c];if(Xe(n.mapping.get(h),f))d=!0;else if(!be(h,f))break}for(;c+a<l;a++){const h=i[r-a-1],f=s[o-a-1];if(Xe(n.mapping.get(h),f))d=!0;else if(!be(h,f))break}return{equalityFactor:c+a,foundMappedChild:d}},Ea=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}},Ia=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:i,str:s}=Ea(e),o=t.map(a=>({insert:a.text,attributes:Object.assign({},i,so(a.marks,n))})),{insert:r,remove:l,index:c}=ra(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})))},Ta=/(.*)(--[a-zA-Z0-9+/=]{8})$/,ai=e=>{var t;return((t=Ta.exec(e))==null?void 0:t[1])??e},Aa=(e,t)=>{const n=[];for(const i in e)n.push(t.mark(ai(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}--${ma(i.toJSON())}`:i.type.name]=i.attrs}}),n},Hn=(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 h=t.getAttributes(),f=n.attrs;for(const g in f)f[g]!==null?h[g]!==f[g]&&g!=="ychange"&&t.setAttribute(g,f[g]):t.removeAttribute(g);for(const g in h)f[g]===void 0&&t.removeAttribute(g)}const s=cn(n),o=s.length,r=t.toArray(),l=r.length,c=Xt(o,l);let a=0,d=0;for(;a<c;a++){const h=r[a],f=s[a];if(!Xe(i.mapping.get(h),f))if(be(h,f))i.mapping.set(h,f);else break}for(;d+a+1<c;d++){const h=r[l-d-1],f=s[o-d-1];if(!Xe(i.mapping.get(h),f))if(be(h,f))i.mapping.set(h,f);else break}e.transact(()=>{for(;l-a-d>0&&o-a-d>0;){const f=r[a],g=s[a],p=r[l-d-1],m=s[o-d-1];if(f instanceof Z&&g instanceof Array)io(f,g)||Ia(f,g,i),a+=1;else{let b=f instanceof W&&$n(f,g),x=p instanceof W&&$n(p,m);if(b&&x){const A=qi(f,g,i),D=qi(p,m,i);A.foundMappedChild&&!D.foundMappedChild?x=!1:!A.foundMappedChild&&D.foundMappedChild||A.equalityFactor<D.equalityFactor?b=!1:x=!1}b?(Hn(e,f,g,i),a+=1):x?(Hn(e,p,m,i),d+=1):(i.mapping.delete(t.get(a)),t.delete(a,1),t.insert(a,[Fn(g,i)]),a+=1)}}const h=l-a-d;if(l===1&&o===0&&r[0]instanceof Z?(i.mapping.delete(r[0]),r[0].delete(0,r[0].length)):h>0&&(t.slice(a,a+h).forEach(f=>i.mapping.delete(f)),t.delete(a,h)),a+d<o){const f=[];for(let g=a;g<o-d;g++)f.push(Fn(s[g],i));t.insert(a,f)}},N)},$n=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,Ze=(e,t,n)=>{if(e===0)return Sn(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 Sn(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 ze(i._item===null?null:i._item.id,i._item===null?ge(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 ze(i._item===null?null:i._item.id,i._item===null?ge(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 Da(i._item.parent,i._item)}return Sn(t,t._length,-1)},Da=(e,t)=>{let n=null,i=null;return e._item===null?i=ge(e):n=v(e._item.id.client,e._item.id.clock),new ze(n,i,t.id)},ae=(e,t,n,i)=>{const s=nc(n,e);if(s===null||s.type!==t&&!pe(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 Ma(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],h={type:ai(c)};return Object.keys(a)&&(h.attrs=a),h})),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 Oa=e=>{const t=yt.getState(e).undoManager;if(t!=null)return t.undo(),!0},Ra=e=>{const t=yt.getState(e).undoManager;if(t!=null)return t.redo(),!0},ja=new Set(["paragraph"]),Na=(e,t)=>!(e instanceof M)||!(e.content instanceof ft)||!(e.content.type instanceof Dt||e.content.type instanceof W&&t.has(e.content.type.nodeName))||e.content.type._length===0,Ba=({protectedNodes:e=ja,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=>Na(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,d=c.redoStack.length>0;return l?{undoManager:c,prevSel:Vn(l,o),hasUndoOps:a,hasRedoOps:d}:a!==s.hasUndoOps||d!==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 Ua(e,t){const n=N.getState(e);return ae(n.doc,n.type,t,n.binding.mapping)||0}function ro(e,t){const n=N.getState(e);return Ze(t,n.type,n.binding.mapping)}var Pe=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 La(e,t){const n=ro(t,e);return new Pe(e,n)}function Pa(e,t,n){const i=e instanceof Pe?e.yRelativePosition:null;if(oo(t)&&i){const r=Ua(n,i);return{position:new Pe(r,i),mapResult:null}}const s=E.getUpdatedPosition(e,t),o=s.position.position;return{position:new Pe(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)=>Pa(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>La(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?Oa(t):!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),yt.getState(t).undoManager.redoStack.length===0?!1:n?Ra(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=Ba(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),d=l._observers;l.restore=()=>{a&&l.trackedOrigins.add(l),l.doc.on("afterTransaction",l.afterTransactionHandler),l._observers=d},c!=null&&c.destroy&&c.destroy()}}};const s={...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender},o=ba(t,s);return this.editor.options.enableContentCheck&&((e=t.doc)==null||e.on("beforeTransaction",()=>{try{const r=Ma(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 Ki(e){if(!e.length)return gn.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(gn.Decoration.node(s,s+o.nodeSize,{class:"ProseMirror-selectednoderange"}))}),gn.DecorationSet.create(n,t)}function an(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 Oo.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,d=a+l.nodeSize;if(a<o.start||a>=o.end)return;const h=new J.SelectionRange(s.resolve(a),s.resolve(d));i.push(h)}),i}var Va=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,d=an(a.min(c),a.max(c),i),h=c.pos>=t.pos?d[0].$from:d[d.length-1].$to,f=c.pos>=t.pos?d[d.length-1].$to:d[0].$from;super(h,f,d),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 Va(this.anchor,this.head)}};Et.prototype.visible=!1;function Ae(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(!Ae(o)){const d=Et.create(s,l,c,t,-1);return r.setSelection(d),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(!Ae(o)){const d=Et.create(s,l,c,t);return r.setSelection(d),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;Ae(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,d=o?a:l;return(s==null||s==="Shift"&&r||s==="Control"&&l||s==="Alt"&&c||s==="Meta"&&a||s==="Mod"&&d)&&(t=!0),t&&document.addEventListener("mouseup",()=>{t=!1;const{state:h}=n,{doc:f,selection:g,tr:p}=h,{$anchor:m,$head:b}=g;if(m.sameParent(b))return;const x=Et.create(f,m.pos,b.pos,this.options.depth);p.setSelection(x),n.dispatch(p)},{once:!0}),!1}},decorations:n=>{const{selection:i}=n,s=Ae(i);if(e=!1,!t)return s?(e=!0,Ki(i.ranges)):null;const{$from:o,$to:r}=i;if(!s&&o.sameParent(r))return null;const l=an(o,r,this.options.depth);return l.length?(e=!0,Ki(l)):null}}})]}});function Fa(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 Ha(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=Fa(s)}),t}function $a(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 za(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),d=.5,h=Math.abs(l.left-c.left)<d,f=Math.abs(l.right-c.right)<d;let g=l;return h&&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}=za(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=$a(f,s);return g?(a=g,!0):!1}),!a)return{resultElement:null,resultNode:null,pos:null};let d;try{d=s.posAtDOM(a,0)}catch{return{resultElement:null,resultNode:null,pos:null}}const h=o.doc.nodeAt(d);return{resultElement:a,resultNode:h,pos:d}};function De(e,t){return window.getComputedStyle(e)[t]}function qa(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function Ka(e,t,n){const i=parseInt(De(e.dom,"paddingLeft"),10),s=parseInt(De(e.dom,"paddingRight"),10),o=parseInt(De(e.dom,"borderLeftWidth"),10),r=parseInt(De(e.dom,"borderLeftWidth"),10),l=e.dom.getBoundingClientRect();return{left:qa(t,l.left+i+o,l.right-s-r),top:n}}function ho(e){var t;(t=e.parentNode)==null||t.removeChild(e)}function Wa(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=Ka(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),d=n.resolve(i.pos+1);return an(a,d,0)}function Ya(e,t){const{view:n}=t;if(!e.dataTransfer)return;const{empty:i,$from:s,$to:o}=n.state.selection,r=Wa(e,t),l=an(s,o,0),c=l.some(b=>r.find(x=>x.$from===b.$from&&x.$to===b.$to)),a=i||!c?r:l;if(!a.length)return;const{tr:d}=n.state,h=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(b=>{const x=n.nodeDOM(b.$from.pos),A=Ha(x);h.append(A)}),h.style.position="absolute",h.style.top="-10000px",document.body.append(h),e.dataTransfer.clearData(),e.dataTransfer.setDragImage(h,0,0),n.dragging={slice:m,move:!0},d.setSelection(p),n.dispatch(d),document.addEventListener("drop",()=>ho(h),{once:!0})}var Wi=(e,t)=>{const n=e.resolve(t),{depth:i}=n;return i===0?t:n.pos-n.parentOffset-1},Yi=(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},_n=(e,t)=>{const n=N.getState(e);return n?Ze(t,n.type,n.binding.mapping):null},Ga=(e,t)=>{const n=N.getState(e);return n?ae(n.doc,n.type,t,n.binding.mapping)||0:-1},Gi=(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,d=null,h=-1,f,g=null,p=null;function m(){t&&(t.style.visibility="hidden",t.style.pointerEvents="none")}function b(){if(t){if(!n.isEditable){m();return}t.style.visibility="",t.style.pointerEvents="auto"}}function x(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 A(C){r==null||r(C),Ya(C,n),t&&(t.dataset.dragging="true"),setTimeout(()=>{t&&(t.style.pointerEvents="none")},0)}function D(C){l==null||l(C),m(),t&&(t.style.pointerEvents="auto",t.dataset.dragging="false")}return t.addEventListener("dragstart",A),t.addEventListener("dragend",D),c.appendChild(t),{unbind(){t.removeEventListener("dragstart",A),t.removeEventListener("dragend",D),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,d=null,h=-1,o==null||o({editor:n,node:null,pos:-1}),B;if(C.docChanged&&h!==-1&&t)if(oo(C)){const $=Ga(S,f);$!==h&&(h=$)}else{const $=C.mapping.map(h);$!==h&&(h=$,f=_n(S,h))}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)||h===-1)return;let k=C.nodeDOM(h);if(k=Gi(C,k),k===C.dom||(k==null?void 0:k.nodeType)!==1)return;const j=C.posAtDOM(k,0),$=Yi(n.state.doc,j),it=Wi(n.state.doc,j);d=$,h=it,f=_n(C.state,h),o==null||o({editor:n,node:d,pos:h}),x(k)},destroy(){g&&(cancelAnimationFrame(g),g=null,p=null),t&&ho(c)}}},props:{handleDOMEvents:{keydown(C){return!t||a||C.hasFocus()&&(m(),d=null,h=-1,o==null||o({editor:n,node:null,pos:-1})),!1},mouseleave(C,B){return a||B.target&&!c.contains(B.relatedTarget)&&(m(),d=null,h=-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=Gi(C,j),j===C.dom||(j==null?void 0:j.nodeType)!==1)return;const $=C.posAtDOM(j,0),it=Yi(n.state.doc,$);if(it!==d){const Mt=Wi(n.state.doc,$);d=it,h=Mt,f=_n(C.state,h),o==null||o({editor:n,node:d,pos:h}),x(j),b()}})),!1}}}})}},zn={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:{...zn,...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 Ja=e=>{const{className:t="drag-handle",children:n,editor:i,pluginKey:s=uo,onNodeChange:o,onElementDragStart:r,onElementDragEnd:l,computePositionConfig:c=zn}=e,[a,d]=w.useState(null),h=w.useRef(null);return w.useEffect(()=>{let f=null;return a?i.isDestroyed?()=>{h.current=null}:(h.current||(f=fo({editor:i,element:a,pluginKey:s,computePositionConfig:{...zn,...c},onElementDragStart:r,onElementDragEnd:l,onNodeChange:o}),h.current=f.plugin,i.registerPlugin(h.current)),()=>{i.unregisterPlugin(s),h.current=null,f&&(f.unbind(),f=null)}):()=>{h.current=null}},[a,i,o,s,c,r,l]),u.jsx("div",{className:t,style:{visibility:"hidden",position:"absolute"},"data-dragging":"false",ref:d,children:n})},Xa=Ja;function Za(){var I,S,k,j,$,it,Mt,Ot;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(_=>(_==null?void 0:_.name)===ts.TextAlign.name),d=(j=(k=e==null?void 0:e.extensionManager)==null?void 0:k.extensions)==null?void 0:j.some(_=>(_==null?void 0:_.name)===oe.Indent.name),h=(it=($=e==null?void 0:e.extensionManager)==null?void 0:$.extensions)==null?void 0:it.some(_=>(_==null?void 0:_.name)===Ro.Clear.name);function f(){const _=e.chain();_.setNodeSelection(o).unsetAllMarks(),(i==null?void 0:i.type.name)!=="paragraph"&&_.setParagraph(),_.run()}function g(){e.chain().focus().setNodeSelection(o).run(),document.execCommand("copy")}function p(){e.commands.setNodeSelection(o);const{$anchor:_}=e.state.selection,gt=_.node(1)||e.state.selection.node;e.chain().setMeta("hideDragHandle",!0).insertContentAt(o+((i==null?void 0:i.nodeSize)||0),gt.toJSON()).run()}function m(_){e.commands.setTextAlign(_)}function b(){const _=oe.setNodeIndentMarkup(e.state.tr,o,1);_.setMeta("hideDragHandle",!0),e.view.dispatch&&e.view.dispatch(_)}function x(){const _=oe.setNodeIndentMarkup(e.state.tr,o,-1);e.view.dispatch&&e.view.dispatch(_)}function A(){e.chain().setMeta("hideDragHandle",!0).setNodeSelection(o).deleteSelection().run()}function D({node:_,pos:gt}){_&&s(_),r(gt)}function C(){var _;if(o!==-1){const gt=(i==null?void 0:i.nodeSize)||0,se=o+gt,$t=(i==null?void 0:i.type.name)==="paragraph"&&((_=i==null?void 0:i.content)==null?void 0:_.size)===0,go=$t?o+2:se+2;e.chain().command(({dispatch:hi,tr:hn,state:di})=>hi?($t?hn.insertText("/",o,o+1):hn.insert(se,di.schema.nodes.paragraph.create(null,[di.schema.text("/")])),hi(hn)):!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=_=>{t&&c(_)};return u.jsxs(u.Fragment,{children:[u.jsx(Xa,{editor:e,onNodeChange:D,pluginKey:"RichTextBubbleMenuDragHandle",children:u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-0.5 richtext-duration-200 richtext-ease-in-out [transition-property:top,_left]",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:_=>{_.preventDefault(),_.stopPropagation(),B(!l)}})]})}),u.jsxs(U.DropdownMenu,{onOpenChange:B,open:l,children:[u.jsx("div",{className:"richtext-relative richtext-flex richtext-flex-col",children:u.jsx(U.DropdownMenuTrigger,{className:"richtext-absolute richtext-left-0 richtext-top-0 richtext-z-0 richtext-size-[28px]"})}),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:A,children:[u.jsx(rt.IconComponent,{name:"Trash2"}),u.jsx("span",{children:n("editor.remove")})]}),h?u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:f,children:[u.jsx(rt.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(rt.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(rt.IconComponent,{name:"Copy"}),u.jsx("span",{children:n("editor.copy")})]}),a||d?u.jsx(U.DropdownMenuSeparator,{}):null,a?u.jsxs(U.DropdownMenuSub,{children:[u.jsxs(U.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[u.jsx(rt.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(rt.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(rt.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(rt.IconComponent,{name:"AlignRight"}),u.jsx("span",{children:n("editor.textalign.right.tooltip")})]})]})})]}):null,d?u.jsxs(U.DropdownMenuSub,{children:[u.jsxs(U.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[u.jsx(rt.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:((Mt=i==null?void 0:i.attrs)==null?void 0:Mt.indent)>=oe.IndentProps.max,onClick:b,children:[u.jsx(rt.IconComponent,{name:"IndentIncrease"}),u.jsx("span",{children:n("editor.indent.tooltip")})]}),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.min,onClick:x,children:[u.jsx(rt.IconComponent,{name:"IndentDecrease"}),u.jsx("span",{children:n("editor.outdent.tooltip")})]})]})})]}):null]})]})]})}exports.RichTextBubbleColumns=Uo;exports.RichTextBubbleDrawer=Qo;exports.RichTextBubbleExcalidraw=er;exports.RichTextBubbleIframe=nr;exports.RichTextBubbleImage=hr;exports.RichTextBubbleImageGif=dr;exports.RichTextBubbleKatex=sr;exports.RichTextBubbleLink=rr;exports.RichTextBubbleMenuDragHandle=Za;exports.RichTextBubbleMermaid=mr;exports.RichTextBubbleTable=wr;exports.RichTextBubbleText=br;exports.RichTextBubbleTwitter=yr;exports.RichTextBubbleVideo=ur;
1
+ "use strict";var fo=Object.create;var di=Object.defineProperty;var go=Object.getOwnPropertyDescriptor;var po=Object.getOwnPropertyNames;var mo=Object.getPrototypeOf,wo=Object.prototype.hasOwnProperty;var xo=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of po(t))!wo.call(e,s)&&s!==n&&di(e,s,{get:()=>t[s],enumerable:!(i=go(t,s))||i.enumerable});return e};var bo=(e,t,n)=>(n=e!=null?fo(mo(e)):{},xo(t||!e||!e.__esModule?di(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("./index-DLqogznp.cjs"),H=require("./floating-ui.dom-VCrc58uF.cjs"),J=require("@tiptap/pm/state"),Yi=require("./Table-CIzgfvr9.cjs"),Gi=require("react-dom"),y=require("./index-D42xFOzI.cjs"),ui=require("./Column.cjs"),V=require("./index-FSRjMsxW.cjs"),K=require("./useButtonProps-TfmRCM9r.cjs"),be=require("./delete-node-CosiBes5.cjs"),jt=require("./separator-yycaNdlI.cjs"),De=require("./Drawer-BGSwHoka.cjs"),fi=require("easydrawer"),Pe=require("./shortId-Bfj8TyNr.cjs"),Gt=require("./button-B6ukqDUf.cjs"),L=require("./dialog-Cfx8yjkr.cjs"),Ji=require("./file-i7e4nQY2.cjs"),pt=require("./Katex-BKL_6NWF.cjs"),Me=require("./input-BxzQAIRv.cjs"),hn=require("./label-BfWfLggp.cjs"),dn=require("./popover-sP8CwbV-.cjs"),$t=require("./Excalidraw-BG2U9i30.cjs"),zt=require("./Iframe-CXDghI6m.cjs"),yo=require("katex"),gi=require("lucide-react"),Xi=require("./textarea-Cbwi_h4h.cjs"),Oe=require("./LinkEditBlock-DW17TyCA.cjs"),So=require("./Image.cjs"),ko=require("./ImageGif.cjs"),Co=require("./Video.cjs"),_n=require("./Mermaid.cjs"),vo=require("./Bold.cjs"),_o=require("./Code.cjs");require("./index-DylewabB.cjs");const Eo=require("./Color.cjs"),Io=require("./Highlight.cjs"),Ao=require("./Italic.cjs"),To=require("./Strike.cjs"),Zi=require("./TextAlign.cjs"),Do=require("./TextUnderline.cjs"),un=require("./Twitter-DwWVNAV5.cjs"),fn=require("@tiptap/pm/view"),Mo=require("@tiptap/pm/model"),ot=require("./Icon-C3j4ls73.cjs"),U=require("./dropdown-menu-Busg3FNn.cjs"),Oo=require("./Clear.cjs"),se=require("./Indent-B1glTHHl.cjs");function Ro(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 jo=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:d,state:h,from:f,to:g})=>{const{doc:p,selection:m}=h,{empty:b}=m,x=!p.textBetween(f,g).length&&E.isTextSelection(h.selection),T=this.element.contains(document.activeElement);return!(!(d.hasFocus()||T)||b||x||!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:d})=>{var h;if(this.editor.isDestroyed){this.destroy();return}if(this.preventHide){this.preventHide=!1;return}d!=null&&d.relatedTarget&&((h=this.element.parentNode)!=null&&h.contains(d.relatedTarget))||(d==null?void 0:d.relatedTarget)!==this.editor.view.dom&&this.hide()},this.handleDebouncedUpdate=(d,h)=>{const f=!(h!=null&&h.selection.eq(d.state.selection)),g=!(h!=null&&h.doc.eq(d.state.doc));!f&&!g||(this.updateDebounceTimer&&clearTimeout(this.updateDebounceTimer),this.updateDebounceTimer=window.setTimeout(()=>{this.updateHandler(d,f,g,h)},this.updateDelay))},this.updateHandler=(d,h,f,g)=>{const{composing:p}=d;if(p||!h&&!f)return;if(!this.getShouldShow(g)){this.hide();return}this.updatePosition(),this.show()},this.transactionHandler=({transaction:d})=>{d.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 Yi.CellSelection){const{$anchorCell:o,$headCell:r}=t,l=o?o.pos:r.pos,c=r?r.pos:o.pos,a=this.view.nodeDOM(l),d=this.view.nodeDOM(c);if(!a||!d)return;const h=a===d?a.getBoundingClientRect():Ro(a.getBoundingClientRect(),d.getBoundingClientRect());s={getBoundingClientRect:()=>h,getClientRects:()=>[h]}}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()}},Qi=e=>new J.Plugin({key:typeof e.pluginKey=="string"?new J.PluginKey(e.pluginKey):e.pluginKey,view:t=>new jo({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?[Qi({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 No=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:d}=c,h=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()||!d||!h||!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:d}=r;if(d||!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()}},ts=e=>new J.Plugin({key:typeof e.pluginKey=="string"?new J.PluginKey(e.pluginKey):e.pluginKey,view:t=>new No({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?[ts({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=w.forwardRef(({pluginKey:e="bubbleMenu",editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:o=null,getReferencedVirtualElement:r,options:l,children:c,...a},d)=>{const h=w.useRef(document.createElement("div"));typeof d=="function"?d(h.current):d&&(d.current=h.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 b=h.current;b.style.visibility="hidden",b.style.position="absolute";const x=Qi({...m.current,editor:g,element:b});g.registerPlugin(x);const T=m.current.pluginKey;return()=>{g.unregisterPlugin(T),window.requestAnimationFrame(()=>{b.parentNode&&b.parentNode.removeChild(b)})}},[g]),Gi.createPortal(u.jsx("div",{...a,children:c}),h.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 d=c.current;if(d.style.visibility="hidden",d.style.position="absolute",t!=null&&t.isDestroyed||a!=null&&a.isDestroyed)return;const h=t||a;if(!h){console.warn("FloatingMenu component is not rendered inside of an editor component or does not have editor prop.");return}const f=ts({editor:h,element:d,pluginKey:e,appendTo:n,shouldShow:i,options:s});return h.registerPlugin(f),()=>{h.unregisterPlugin(e),window.requestAnimationFrame(()=>{d.parentNode&&d.parentNode.removeChild(d)})}},[t,a,n,e,i,s]),Gi.createPortal(u.jsx("div",{...r,children:o}),c.current)});function Bo(){const e=y.useEditableEditor(),t=K.useEditorInstance(),{t:n}=V.useLocale(),i=w.useCallback(()=>t.isActive(ui.MultipleColumnNode.name),[t]),s=w.useCallback(()=>be.deleteNode(ui.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(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 Uo(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 Lo(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 Po(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 Vo(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 Fo(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 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.setAlignImageDrawer)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function $o(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 zo(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 qo(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()}}},...Uo(e,t),...Po(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 Ko(e,t){return[...Lo(e,t),...Vo(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 Wo(e,t){return[...Fo(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 Yo(e,t){return[...Ho(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 Go(e,t){return[...zo(e,t),...$o(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 oe=!1;function Jo({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,d=()=>{(async()=>{const S=document.querySelector("#easydrawer");S&&(o.current=new fi.Editor(S,{wheelEventsEnabled:!1,disableZoom:!0}),r.current=fi.makeDropdownToolbar(o.current),r.current.addDefaultToolWidgets(),o.current.loadFromSVG(decodeURIComponent(l)))})()};w.useEffect(()=>{i&&setTimeout(()=>{d()},200)},[i]);const h=async()=>{if(o.current){const I=o.current.toSVG(),S=I.outerHTML,k=`drawer-${Pe.shortId()}.svg`;let j=Pe.i(I.outerHTML);if(a){const $=Ji.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)},b=I=>{const S=o.current.toolController.getPrimaryTools()[5],k=r.current.getWidgetById("shape");S&&k&&(S.setColor(I),k.serializeState())},x=I=>{const S=o.current.toolController.getPrimaryTools()[5],k=r.current.getWidgetById("shape");S&&k&&(S.setThickness(I),k.serializeState())},T=I=>{const S=o.current.toolController.getPrimaryTools()[5],k=r.current.getWidgetById("shape");S&&k&&(S.setBorderColor(I),k.serializeState())},D=()=>{if(oe){for(;o.current.history.redoStackSize>0;)o.current.history.redo();oe=!1;return}o.current.history.undo()},C=()=>{oe||o.current.history.redo()},B=()=>{if(!oe){for(;o.current.history.undoStackSize>0;)D();oe=!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(De.ControlDrawer,{changeBorderColorShape:T,changeColorShape:b,changeShape:m,onClear:B,onRedo:C,onThicknessChange:x,onUndo:D,refEditor:o,setColorHighlight:p,setColorPen:f,setThicknessPen:g})]}),u.jsx(L.DialogFooter,{children:u.jsx(Gt.Button,{onClick:h,type:"button",children:"Save changes"})})]})]})}function Xo({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?u.jsx(w.Fragment,{children:e.type==="divider"?u.jsx(jt.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 Zo(){const{lang:e,t}=V.useLocale(),n=y.useEditableEditor(),i=K.useEditorInstance(),s=pt.useAttributes(i,De.Drawer.name),o=K.useExtension(De.Drawer.name),r=({editor:c})=>{const{selection:a}=c.view.state,{$from:d,to:h}=a;let f=!1;return c.view.state.doc.nodesBetween(d.pos,h,g=>{if(g.type.name===De.Drawer.name)return f=!0,!1}),f},l=w.useMemo(()=>Yo(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(Jo,{attrs:s,editor:i,extension:o},`bubbleMenu-drawer-${a}`):u.jsx(Xo,{editor:i,item:c},`bubbleMenu-drawer-${a}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}const es=({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(dn.Popover,{modal:!0,children:[u.jsx(dn.PopoverTrigger,{asChild:!0,children:s}),u.jsx(dn.PopoverContent,{children:u.jsxs("form",{className:"richtext-flex richtext-flex-col richtext-gap-2",onSubmit:c,children:[u.jsx(hn.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(Me.Input,{onChange:a=>l({...r,width:a.target.value}),required:!0,type:"number",value:r.width})})}),u.jsx(hn.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(Me.Input,{onChange:a=>l({...r,maxWidth:a.target.value}),required:!0,type:"number",value:r.maxWidth})})}),u.jsx(hn.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(Me.Input,{onChange:a=>l({...r,height:a.target.value}),required:!0,type:"number",value:r.height})})}),u.jsx(Gt.Button,{className:"richtext-mt-2 richtext-self-end",type:"submit",children:o("editor.link.dialog.button.apply")})]})})]})},Ot=new Map;function Qo(e){const t=e.options.element;Ot.has("width")||Ot.set("width",t.clientWidth),Ot.has("width")&&Ot.get("width")<=0&&Ot.set("width",t.clientWidth);const n={attributes:!0,childList:!0,subtree:!0},i=function(){Ot.set("width",t.clientWidth)},s=new MutationObserver(i);return s.observe(t,n),e.on("destroy",()=>{s.disconnect()}),{width:Ot.get("width")}}function tr(){const e=y.useEditableEditor(),t=K.useEditorInstance(),{t:n}=V.useLocale(),{width:i}=Qo(t),s=pt.useAttributes(t,$t.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($t.Excalidraw.name,g).setNodeSelection(t.state.selection.from).focus().run()},[t]),d=w.useCallback(()=>{$t.triggerOpenExcalidrawSettingModal({...s,editor:t})},[t,s]),h=w.useCallback(()=>t.isActive($t.Excalidraw.name),[t]),f=w.useCallback(()=>be.deleteNode($t.Excalidraw.name,t),[t]);return w.useEffect(()=>{o&&(d(),t.chain().updateAttributes($t.Excalidraw.name,{defaultShowPicker:!1}).focus().run())},[r,o,t,d]),e?u.jsx(et,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleExcalidraw",shouldShow:h,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:d,icon:"Pencil",tooltip:n("editor.edit")}),u.jsx(es,{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 er(){const e=y.useEditableEditor(),t=K.useEditorInstance(),{t:n}=V.useLocale(),{width:i,height:s,src:o}=pt.useAttributes(t,zt.Iframe.name,{width:0,height:0,src:"",defaultShowPicker:!1}),[r,l]=w.useState(!1),[c,a]=w.useState(""),d=w.useCallback(x=>{var T;(T=x==null?void 0:x.preventDefault)==null||T.call(x),l(!1)},[l]);w.useEffect(()=>{r&&a(o)},[r,o]);const h=w.useCallback(x=>{var D;(D=x==null?void 0:x.preventDefault)==null||D.call(x);const T=zt.getServiceSrc(c);t.chain().updateAttributes(zt.Iframe.name,{src:(T==null?void 0:T.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(()=>{l(!0)},[l]),p=w.useCallback(x=>{t.chain().updateAttributes(zt.Iframe.name,x).setNodeSelection(t.state.selection.from).focus().run()},[t]),m=w.useCallback(()=>t.isActive(zt.Iframe.name)&&!o,[t,o]),b=w.useCallback(()=>be.deleteNode(zt.Iframe.name,t),[t]);return e?u.jsxs(u.Fragment,{children:[u.jsx(et,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleIframe",shouldShow:m,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.jsx(y.ActionButton,{action:g,icon:"Pencil",tooltip:"Open Edit Link"}),u.jsx(es,{height:s,onOk:p,width:i,children:u.jsx(y.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),u.jsx(y.ActionButton,{action:b,icon:"Trash2",tooltip:n("editor.delete")})]})}),u.jsxs(L.Dialog,{onOpenChange:l,open:r,children:[u.jsx(L.DialogTrigger,{}),u.jsxs(L.DialogContent,{children:[u.jsx(L.DialogHeader,{children:u.jsx(L.DialogTitle,{children:"Edit Link Iframe"})}),u.jsx(Me.Input,{autoFocus:!0,onInput:x=>a(x.target.value),placeholder:"Enter link",type:"url",value:c}),u.jsxs(L.DialogFooter,{children:[u.jsx(Gt.Button,{onClick:d,type:"button",children:"Cancel"}),u.jsx(Gt.Button,{onClick:h,type:"button",children:"OK"})]})]})]})]}):u.jsx(u.Fragment,{})}function nr({children:e,visible:t,toggleVisible:n}){const{t:i}=V.useLocale(),s=K.useEditorInstance(),o=pt.useAttributes(s,pt.Katex.name,{text:"",defaultShowPicker:!1}),{text:r,defaultShowPicker:l}=o,[c,a]=w.useState(r||"");w.useEffect(()=>{t&&a(r||"")},[t]),w.useEffect(()=>{l&&(n(!0),s.chain().updateAttributes(pt.Katex.name,{defaultShowPicker:!1}).focus().run())},[s,l,n]);const d=w.useCallback(()=>{s.chain().focus().setKatex({text:c}).run(),a(""),n(!1)},[s,c,n]),h=w.useMemo(()=>{try{return yo.renderToString(`${c}`)}catch{return c}},[c]),f=w.useMemo(()=>`${c}`.trim()?h:null,[c,h]);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.jsx(Xi.Textarea,{autoFocus:!0,className:"richtext-flex-1",onChange:g=>a(g.target.value),placeholder:"Text",required:!0,rows:10,value:c,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:f||""},style:{height:"100%",borderWidth:1,minHeight:500,background:"#fff"}})]})}),u.jsx(L.DialogFooter,{children:u.jsx(Gt.Button,{onClick:d,type:"button",children:"Save changes"})})]})]})}function ir(){const e=y.useEditableEditor(),t=K.useEditorInstance(),[n,i]=w.useState(!1),s=w.useCallback(()=>t.isActive(pt.Katex.name),[t]),o=w.useCallback(()=>be.deleteNode(pt.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(nr,{toggleVisible:i,visible:n,children:u.jsx(y.ActionButton,{action:()=>i(!n),tooltip:"Edit",children:u.jsx(gi.Pencil,{size:16})})}),u.jsx(y.ActionButton,{action:o,tooltip:"Delete",children:u.jsx(gi.Trash2,{size:16})})]})}):u.jsx(u.Fragment,{})}function sr(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 or(){const e=y.useEditableEditor(),t=K.useEditorInstance(),[n,i]=w.useState(!1),s=pt.useAttributes(t,Oe.Link.name),o=s==null?void 0:s.href,r=w.useCallback(({editor:d})=>d.isActive(Oe.Link.name),[]),l=(d,h,f)=>{const g=t.state.selection,{from:p}=g,m=(h==null?void 0:h.length)??0,b=p+m;t.chain().extendMarkRange("link").insertContent({type:"text",text:h,marks:[{type:"link",attrs:{href:d,target:f?"_blank":""}}]}).setLink({href:d}).setTextSelection({from:p,to:b}).focus().run(),i(!1)},c=w.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(Oe.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(sr,{editor:t,link:o,onClear:c,onEdit:()=>{i(!0)}})})})}):u.jsx(u.Fragment,{})}function zn({item:e,disabled:t,editor:n}){const i=e.component;return i?u.jsx(w.Fragment,{children:e.type==="divider"?u.jsx(jt.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 rr(e){return e.type.name===So.Image.name}function lr(e){return e.type.name===ko.ImageGif.name}function cr(e){return e.type.name===Co.Video.name}function ar(){const{lang:e,t}=V.useLocale(),n=y.useEditableEditor(),i=K.useEditorInstance(),s=({editor:r})=>{const{selection:l}=r.view.state,{$from:c,to:a}=l;let d=!1;return r.view.state.doc.nodesBetween(c.pos,a,h=>{if(rr(h))return d=!0,!1}),d},o=w.useMemo(()=>qo(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(zn,{editor:i,item:r},`bubbleMenu-image-${l}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}function hr(){const{lang:e,t}=V.useLocale(),n=y.useEditableEditor(),i=K.useEditorInstance(),s=({editor:r})=>{const{selection:l}=r.view.state,{$from:c,to:a}=l;let d=!1;return r.view.state.doc.nodesBetween(c.pos,a,h=>{if(lr(h))return d=!0,!1}),d},o=w.useMemo(()=>Ko(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(zn,{editor:i,item:r},`bubbleMenu-image-gif-${l}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}function dr(){const{t:e}=V.useLocale(),t=y.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,d=>{if(cr(d))return a=!0,!1}),a},s=w.useMemo(()=>Go(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(zn,{editor:n,item:o},`bubbleMenu-video-${r}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}const pi=`graph TB
2
+ a-->b`,ur=({editor:e,attrs:t,extension:n})=>{const{alt:i,align:s}=t,[o,r]=w.useState(decodeURIComponent(i??pi)),[l,c]=w.useState(""),[a,d]=w.useState(!1),h=w.useRef(null),[f,g]=w.useState(null),p=n==null?void 0:n.options.upload,m=w.useCallback(D=>{D&&import("mermaid").then(C=>{g(C.default)})},[]),b=async D=>{try{const{svg:C}=await f.render("mermaid-svg",D);c(C)}catch{c("")}},x=()=>{f.initialize({darkMode:!1,startOnLoad:!1,fontSize:12,theme:"base"}),b(o)};w.useEffect(()=>{f&&a&&x()},[f,a]),w.useEffect(()=>{f&&a&&b(o)},[f,o]);const T=async()=>{if(o!==""){if(o){const D=h.current.querySelector("svg"),{width:C,height:B}=D.getBoundingClientRect(),I=`mermaid-${Pe.shortId()}.svg`;let S=Pe.i(D.outerHTML);if(p){const k=Ji.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)}d(!1)}};return u.jsxs(L.Dialog,{onOpenChange:d,open:a,children:[u.jsx(L.DialogTrigger,{asChild:!0,children:u.jsx(y.ActionButton,{action:()=>d(!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(Xi.Textarea,{autoFocus:!0,className:"richtext-flex-1",defaultValue:pi,onChange:D=>r(D.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:h,style:{height:"100%",border:"1px solid hsl(var(--border))",minHeight:500}})]})}),u.jsx(L.DialogFooter,{children:u.jsx(Gt.Button,{onClick:T,type:"button",children:"Save changes"})})]})]})};function fr({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?u.jsx(w.Fragment,{children:e.type==="divider"?u.jsx(jt.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 gr(e){return e.type.name===_n.Mermaid.name}function pr(){const{lang:e,t}=V.useLocale(),n=y.useEditableEditor(),i=K.useEditorInstance(),s=pt.useAttributes(i,_n.Mermaid.name),o=K.useExtension(_n.Mermaid.name),r=({editor:c})=>{const{selection:a}=c.view.state,{$from:d,to:h}=a;let f=!1;return c.view.state.doc.nodesBetween(d.pos,h,g=>{if(gr(g))return f=!0,!1}),f},l=w.useMemo(()=>Wo(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(ur,{attrs:s,editor:i,extension:o},`bubbleMenu-mermaid-${a}`):u.jsx(fr,{editor:i,item:c},`bubbleMenu-mermaid-${a}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}function mr({hiddenActions:e=[]}){var m,b,x,T,D,C,B,I,S,k,j,$,nt,Dt,Mt,_,ft,ie;const{t}=V.useLocale(),n=y.useEditableEditor(),i=K.useEditorInstance(),s=({editor:Ht})=>E.isActive(Ht.view.state,Yi.Table.name),o=Ht=>e.includes(Ht);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 d(){i.chain().focus().addRowAfter().run()}function h(){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:!((b=(m=i==null?void 0:i.can())==null?void 0:m.addColumnBefore)!=null&&b.call(m)),icon:"BetweenHorizonalEnd",tooltip:t("editor.table.menu.insertColumnBefore"),tooltipOptions:{sideOffset:15}}),!o("addColumnAfter")&&u.jsx(y.ActionButton,{action:l,disabled:!((T=(x=i==null?void 0:i.can())==null?void 0:x.addColumnAfter)!=null&&T.call(x)),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:(D=i.can()).deleteColumn)!=null&&C.call(D)),icon:"DeleteColumn",tooltip:t("editor.table.menu.deleteColumn"),tooltipOptions:{sideOffset:15}}),u.jsx(jt.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:d,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:h,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(jt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!o("mergeCells")&&u.jsx(y.ActionButton,{action:f,disabled:!((Dt=(nt=i==null?void 0:i.can())==null?void 0:nt.mergeCells)!=null&&Dt.call(nt)),icon:"TableCellsMerge",tooltip:t("editor.table.menu.mergeCells"),tooltipOptions:{sideOffset:15}}),!o("splitCells")&&u.jsx(y.ActionButton,{action:g,disabled:!((_=(Mt=i==null?void 0:i.can())==null?void 0:Mt.splitCell)!=null&&_.call(Mt)),icon:"TableCellsSplit",tooltip:t("editor.table.menu.splitCells"),tooltipOptions:{sideOffset:15}}),u.jsx(jt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!o("deleteTable")&&u.jsx(y.ActionButton,{action:p,disabled:!((ie=(ft=i==null?void 0:i.can())==null?void 0:ft.deleteTable)!=null&&ie.call(ft)),icon:"Trash2",tooltip:t("editor.table.menu.deleteTable"),tooltipOptions:{sideOffset:15}})]})}):u.jsx(u.Fragment,{})}function wr(){return u.jsxs(u.Fragment,{children:[u.jsx(vo.RichTextBold,{}),u.jsx(Ao.RichTextItalic,{}),u.jsx(Do.RichTextUnderline,{}),u.jsx(To.RichTextStrike,{}),u.jsx(_o.RichTextCode,{}),u.jsx(Oe.RichTextLink,{}),u.jsx(jt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),u.jsx(Eo.RichTextColor,{}),u.jsx(Io.RichTextHighlight,{}),u.jsx(Zi.RichTextAlign,{})]})}function xr({buttonBubble:e}){const t=K.useEditorInstance(),n=y.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(wr,{})})}):u.jsx(u.Fragment,{})}function br(){const{t:e}=V.useLocale(),t=y.useEditableEditor(),n=K.useEditorInstance(),[i,s]=w.useState(!1),o=w.useCallback(({editor:c})=>c.isActive(un.Twitter.name),[]),r=c=>{n.commands.updateTweet({src:c}),s(!1)},l=w.useCallback(()=>be.deleteNode(un.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(un.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 ct=()=>new Map,En=e=>{const t=ct();return e.forEach((n,i)=>{t.set(i,n)}),t},St=(e,t,n)=>{let i=e.get(t);return i===void 0&&e.set(t,i=n()),i},yr=(e,t)=>{const n=[];for(const[i,s]of e)n.push(t(s,i));return n},Sr=(e,t)=>{for(const[n,i]of e)if(t(i,n))return!0;return!1},Bt=()=>new Set,gn=e=>e[e.length-1],kr=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},Ut=Array.from,Cr=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},In=Array.isArray;class ns{constructor(){this._observers=ct()}on(t,n){return St(this._observers,t,Bt).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 Ut((this._observers.get(t)||ct()).values()).forEach(i=>i(...n))}destroy(){this._observers=ct()}}const yt=Math.floor,Re=Math.abs,Jt=(e,t)=>e<t?e:t,Et=(e,t)=>e>t?e:t,is=e=>e!==0?e<0:1/e<0,mi=1,wi=2,pn=4,mn=8,ae=32,xt=64,G=128,vr=1<<29,Ze=31,An=63,Nt=127,_r=2147483647,ss=Number.MAX_SAFE_INTEGER,Er=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&yt(e)===e),Ir=String.fromCharCode,Ar=e=>e.toLowerCase(),Tr=/^\s*/g,Dr=e=>e.replace(Tr,""),Mr=/([A-Z])/g,xi=(e,t)=>Dr(e.replace(Mr,n=>`${t}${Ar(n)}`)),Or=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},he=typeof TextEncoder<"u"?new TextEncoder:null,Rr=e=>he.encode(e),jr=he?Rr:Or;let le=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});le&&le.decode(new Uint8Array).length===1&&(le=null);class ye{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Se=()=>new ye,Nr=e=>{const t=Se();return e(t),lt(t)},Br=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},lt=e=>{const t=new Uint8Array(Br(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},Ur=(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(Et(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},Tn=z,A=(e,t)=>{for(;t>Nt;)z(e,G|Nt&t),t=yt(t/128);z(e,Nt&t)},qn=(e,t)=>{const n=is(t);for(n&&(t=-t),z(e,(t>An?G:0)|(n?xt:0)|An&t),t=yt(t/64);t>0;)z(e,(t>Nt?G:0)|Nt&t),t=yt(t/128)},Dn=new Uint8Array(3e4),Lr=Dn.length/3,Pr=(e,t)=>{if(t.length<Lr){const n=he.encodeInto(t,Dn).written||0;A(e,n);for(let i=0;i<n;i++)z(e,Dn[i])}else tt(e,jr(t))},Vr=(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))},qt=he&&he.encodeInto?Pr:Vr,Qe=(e,t)=>{const n=e.cbuf.length,i=e.cpos,s=Jt(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(Et(n*2,o)),e.cbuf.set(t.subarray(s)),e.cpos=o)},tt=(e,t)=>{A(e,t.byteLength),Qe(e,t)},Kn=(e,t)=>{Ur(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Fr=(e,t)=>Kn(e,4).setFloat32(0,t,!1),Hr=(e,t)=>Kn(e,8).setFloat64(0,t,!1),$r=(e,t)=>Kn(e,8).setBigInt64(0,t,!1),bi=new DataView(new ArrayBuffer(4)),zr=e=>(bi.setFloat32(0,e),bi.getFloat32(0)===e),Xt=(e,t)=>{switch(typeof t){case"string":z(e,119),qt(e,t);break;case"number":Er(t)&&Re(t)<=_r?(z(e,125),qn(e,t)):zr(t)?(z(e,124),Fr(e,t)):(z(e,123),Hr(e,t));break;case"bigint":z(e,122),$r(e,t);break;case"object":if(t===null)z(e,126);else if(In(t)){z(e,117),A(e,t.length);for(let n=0;n<t.length;n++)Xt(e,t[n])}else if(t instanceof Uint8Array)z(e,116),tt(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];qt(e,s),Xt(e,t[s])}}break;case"boolean":z(e,t?120:121);break;default:z(e,127)}};class yi extends ye{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 Si=e=>{e.count>0&&(qn(e.encoder,e.count===1?e.s:-e.s),e.count>1&&A(e.encoder,e.count-2))};class je{constructor(){this.encoder=new ye,this.s=0,this.count=0}write(t){this.s===t?this.count++:(Si(this),this.count=1,this.s=t)}toUint8Array(){return Si(this),lt(this.encoder)}}const ki=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);qn(e.encoder,t),e.count>1&&A(e.encoder,e.count-2)}};class wn{constructor(){this.encoder=new ye,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(ki(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return ki(this),lt(this.encoder)}}class qr{constructor(){this.sarr=[],this.s="",this.lensE=new je}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new ye;return this.sarr.push(this.s),this.s="",qt(t,this.sarr.join("")),Qe(t,this.lensE.toUint8Array()),lt(t)}}const It=e=>new Error(e),at=()=>{throw It("Method unimplemented")},Q=()=>{throw It("Unexpected case")},os=It("Unexpected end of array"),rs=It("Integer out of Range");class tn{constructor(t){this.arr=t,this.pos=0}}const Wn=e=>new tn(e),Kr=e=>e.pos!==e.arr.length,Wr=(e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},it=e=>Wr(e,R(e)),de=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&Nt)*n,n*=128,s<G)return t;if(t>ss)throw rs}throw os},Yn=e=>{let t=e.arr[e.pos++],n=t&An,i=64;const s=(t&xt)>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&Nt)*i,i*=128,t<G)return s*n;if(n>ss)throw rs}throw os},Yr=e=>{let t=R(e);if(t===0)return"";{let n=String.fromCodePoint(de(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(de(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))}},Gr=e=>le.decode(it(e)),Mn=le?Gr:Yr,Gn=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},Jr=e=>Gn(e,4).getFloat32(0,!1),Xr=e=>Gn(e,8).getFloat64(0,!1),Zr=e=>Gn(e,8).getBigInt64(0,!1),Qr=[e=>{},e=>null,Yn,Jr,Xr,Zr,e=>!1,e=>!0,Mn,e=>{const t=R(e),n={};for(let i=0;i<t;i++){const s=Mn(e);n[s]=Ve(e)}return n},e=>{const t=R(e),n=[];for(let i=0;i<t;i++)n.push(Ve(e));return n},it],Ve=e=>Qr[127-de(e)](e);class Ci extends tn{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Kr(this)?this.count=R(this)+1:this.count=-1),this.count--,this.s}}class Ne extends tn{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Yn(this);const t=is(this.s);this.count=1,t&&(this.s=-this.s,this.count=R(this)+2)}return this.count--,this.s}}class xn extends tn{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=Yn(this),n=t&1;this.diff=yt(t/2),this.count=1,n&&(this.count=R(this)+2)}return this.s+=this.diff,this.count--,this.s}}class tl{constructor(t){this.decoder=new Ne(t),this.str=Mn(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 el=crypto.getRandomValues.bind(crypto),nl=Math.random,ls=()=>el(new Uint32Array(1))[0],il=e=>e[yt(nl()*e.length)],sl="10000000-1000-4000-8000"+-1e11,ol=()=>sl.replace(/[018]/g,e=>(e^ls()&15>>e/4).toString(16)),rl=Date.now,vi=e=>new Promise(e);Promise.all.bind(Promise);const _i=e=>e===void 0?null:e;class ll{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}}let cs=new ll,cl=!0;try{typeof localStorage<"u"&&localStorage&&(cs=localStorage,cl=!1)}catch{}const al=cs,hl=Object.assign,as=Object.keys,dl=(e,t)=>{for(const n in e)t(e[n],n)},Ei=e=>as(e).length,ul=e=>{for(const t in e)return!1;return!0},hs=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},fl=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),gl=(e,t)=>e===t||Ei(e)===Ei(t)&&hs(e,(n,i)=>(n!==void 0||fl(t,i))&&t[i]===n),pl=Object.freeze,ds=e=>{for(const t in e){const n=e[t];(typeof n=="object"||typeof n=="function")&&ds(e[t])}return pl(e)},Jn=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Jn(e,t,n+1)}},ml=(e,t)=>t.includes(e),Zt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",us=typeof window<"u"&&typeof document<"u"&&!Zt;let gt;const wl=()=>{if(gt===void 0)if(Zt){gt=ct();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=ct(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){const[t,n]=e.split("=");gt.set(`--${xi(t,"-")}`,n),gt.set(`-${xi(t,"-")}`,n)}})):gt=ct();return gt},On=e=>wl().has(e),Fe=e=>_i(Zt?process.env[e.toUpperCase().replaceAll("-","_")]:al.getItem(e)),fs=e=>On("--"+e)||Fe(e)!==null;fs("production");const xl=Zt&&ml(process.env.FORCE_COLOR,["true","1","2"]),bl=xl||!On("--no-colors")&&!fs("no-color")&&(!Zt||process.stdout.isTTY)&&(!Zt||On("--color")||Fe("COLORTERM")!==null||(Fe("TERM")||"").includes("color")),yl=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=Ir(e[n]);return btoa(t)},Sl=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),kl=us?yl:Sl,Cl=e=>Nr(t=>Xt(t,e));class vl{constructor(t,n){this.left=t,this.right=n}}const wt=(e,t)=>new vl(e,t),_l=typeof document<"u"?document:{};typeof DOMParser<"u"&&new DOMParser;const El=e=>yr(e,(t,n)=>`${n}:${t};`).join(""),Il=e=>class{constructor(n){this._=n}destroy(){e(this._)}},Al=Il(clearTimeout),gs=(e,t)=>new Al(setTimeout(t,e)),kt=Symbol,ps=kt(),ms=kt(),Tl=kt(),Dl=kt(),Ml=kt(),ws=kt(),Ol=kt(),Xn=kt(),Rl=kt(),jl=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},Nl={[ps]:wt("font-weight","bold"),[ms]:wt("font-weight","normal"),[Tl]:wt("color","blue"),[Ml]:wt("color","green"),[Dl]:wt("color","grey"),[ws]:wt("color","red"),[Ol]:wt("color","purple"),[Xn]:wt("color","orange"),[Rl]:wt("color","black")},Bl=e=>{var r;e.length===1&&((r=e[0])==null?void 0:r.constructor)===Function&&(e=e[0]());const t=[],n=[],i=ct();let s=[],o=0;for(;o<e.length;o++){const l=e[o],c=Nl[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=El(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},xs=bl?Bl:jl,Ul=(...e)=>{console.log(...xs(e)),ys.forEach(t=>t.print(e))},bs=(...e)=>{console.warn(...xs(e)),e.unshift(Xn),ys.forEach(t=>t.print(e))},ys=Bt(),Ss=e=>({[Symbol.iterator](){return this},next:e}),Ll=(e,t)=>Ss(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),bn=(e,t)=>Ss(()=>{const{done:n,value:i}=e.next();return{done:n,value:n?void 0:t(i)}});class Zn{constructor(t,n){this.clock=t,this.len=n}}class te{constructor(){this.clients=new Map}}const At=(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])Ts(e,o,a.clock,a.len,n)}}),Pl=(e,t)=>{let n=0,i=e.length-1;for(;n<=i;){const s=yt((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},ee=(e,t)=>{const n=e.clients.get(t.client);return n!==void 0&&Pl(n,t.clock)!==null},Qn=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=Et(s.len,o.clock+o.len-s.clock):(i<n&&(t[i]=o),i++)}t.length=i})},Rn=e=>{const t=new te;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++)kr(o,e[r].clients.get(s)||[]);t.clients.set(s,o)}});return Qn(t),t},ue=(e,t,n,i)=>{St(e.clients,t,()=>[]).push(new Zn(n,i))},ks=()=>new te,Vl=e=>{const t=ks();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 Zn(l,c))}}s.length>0&&t.clients.set(i,s)}),t},ti=(e,t)=>{A(e.restEncoder,t.clients.size),Ut(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)}})},Fl=e=>{const t=new te,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=St(t.clients,s,()=>[]);for(let l=0;l<o;l++)r.push(new Zn(e.readDsClock(),e.readDsLen()))}}return t},Ii=(e,t,n)=>{const i=new te,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 d=0;d<l;d++){const h=e.readDsClock(),f=h+e.readDsLen();if(h<a){a<f&&ue(i,r,a,f-a);let g=ht(c,h),p=c[g];for(!p.deleted&&p.id.clock<h&&(c.splice(g+1,0,Ye(t,p,h-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,Ye(t,p,f-p.id.clock)),p.delete(t))}else ue(i,r,h,f-h)}}if(i.clients.size>0){const o=new en;return A(o.restEncoder,0),ti(o,i),o.toUint8Array()}return null},Cs=ls;class Vt extends ns{constructor({guid:t=ol(),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=Cs(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new Is,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=vi(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const c=()=>vi(a=>{const d=h=>{(h===void 0||h===!0)&&(this.off("sync",d),a())};this.on("sync",d)});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(Ut(this.subdocs).map(t=>t.guid))}transact(t,n=null){return O(this,t,n)}get(t,n=q){const i=St(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,Yt)}getText(t=""){return this.get(t,Tt)}getMap(t=""){return this.get(t,Qt)}getXmlElement(t=""){return this.get(t,W)}getXmlFragment(t=""){return this.get(t,Lt)}toJSON(){const t={};return this.share.forEach((n,i)=>{t[i]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,Ut(this.subdocs).forEach(n=>n.destroy());const t=this._item;if(t!==null){this._item=null;const n=t.content;n.doc=new Vt({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 Hl{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 He extends Hl{constructor(t){super(t),this.keys=[],R(t),this.keyClockDecoder=new xn(it(t)),this.clientDecoder=new Ne(it(t)),this.leftClockDecoder=new xn(it(t)),this.rightClockDecoder=new xn(it(t)),this.infoDecoder=new Ci(it(t),de),this.stringDecoder=new tl(it(t)),this.parentInfoDecoder=new Ci(it(t),de),this.typeRefDecoder=new Ne(it(t)),this.lenDecoder=new Ne(it(t))}readLeftID(){return new Kt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Kt(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 Ve(this.restDecoder)}readBuf(){return it(this.restDecoder)}readJSON(){return Ve(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 $l{constructor(){this.restEncoder=Se()}toUint8Array(){return lt(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){A(this.restEncoder,t)}writeDsLen(t){A(this.restEncoder,t)}}class zl extends $l{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){Tn(this.restEncoder,t)}writeString(t){qt(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){Xt(this.restEncoder,t)}writeBuf(t){tt(this.restEncoder,t)}writeJSON(t){qt(this.restEncoder,JSON.stringify(t))}writeKey(t){qt(this.restEncoder,t)}}class ql{constructor(){this.restEncoder=Se(),this.dsCurrVal=0}toUint8Array(){return lt(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 en extends ql{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new wn,this.clientEncoder=new je,this.leftClockEncoder=new wn,this.rightClockEncoder=new wn,this.infoEncoder=new yi(Tn),this.stringEncoder=new qr,this.parentInfoEncoder=new yi(Tn),this.typeRefEncoder=new je,this.lenEncoder=new je}toUint8Array(){const t=Se();return A(t,0),tt(t,this.keyClockEncoder.toUint8Array()),tt(t,this.clientEncoder.toUint8Array()),tt(t,this.leftClockEncoder.toUint8Array()),tt(t,this.rightClockEncoder.toUint8Array()),tt(t,lt(this.infoEncoder)),tt(t,this.stringEncoder.toUint8Array()),tt(t,lt(this.parentInfoEncoder)),tt(t,this.typeRefEncoder.toUint8Array()),tt(t,this.lenEncoder.toUint8Array()),Qe(t,lt(this.restEncoder)),lt(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){Xt(this.restEncoder,t)}writeBuf(t){tt(this.restEncoder,t)}writeJSON(t){Xt(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 Kl=(e,t,n,i)=>{i=Et(i,t[0].id.clock);const s=ht(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)},vs=(e,t,n)=>{const i=new Map;n.forEach((s,o)=>{P(t,o)>s&&i.set(o,s)}),nn(t).forEach((s,o)=>{n.has(o)||i.set(o,0)}),A(e.restEncoder,i.size),Ut(i.entries()).sort((s,o)=>o[0]-s[0]).forEach(([s,o])=>{Kl(e,t.clients.get(s),s,o)})},Wl=(e,t)=>{const n=ct(),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 d=e.readInfo();switch(Ze&d){case 0:{const h=e.readLen();r[a]=new st(v(l,c),h),c+=h;break}case 10:{const h=R(e.restDecoder);r[a]=new rt(v(l,c),h),c+=h;break}default:{const h=(d&(xt|G))===0,f=new M(v(l,c),null,(d&G)===G?e.readLeftID():null,null,(d&xt)===xt?e.readRightID():null,h?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,h&&(d&ae)===ae?e.readString():null,Xs(e,d));r[a]=f,c+=f.length}}}}return n},Yl=(e,t,n)=>{const i=[];let s=Ut(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 Is,c=new Map,a=(g,p)=>{const m=c.get(g);(m==null||m>p)&&c.set(g,p)};let d=r.refs[r.i++];const h=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(b=>b!==p)}i.length=0};for(;;){if(d.constructor!==rt){const p=St(h,d.id.client,()=>P(t,d.id.client))-d.id.clock;if(p<0)i.push(d),a(d.id.client,d.id.clock-1),f();else{const m=d.getMissing(e,t);if(m!==null){i.push(d);const b=n.get(m)||{refs:[],i:0};if(b.refs.length===b.i)a(m,P(t,m)),f();else{d=b.refs[b.i++];continue}}else(p===0||p<d.length)&&(d.integrate(e,p),h.set(d.id.client,d.id.clock+d.length))}}if(i.length>0)d=i.pop();else if(r!==null&&r.i<r.refs.length)d=r.refs[r.i++];else{if(r=o(),r===null)break;d=r.refs[r.i++]}}if(l.clients.size>0){const g=new en;return vs(g,l,new Map),A(g.restEncoder,0),{missing:c,update:g.toUint8Array()}}return null},Gl=(e,t)=>vs(e,t.doc.store,t.beforeState),Jl=(e,t,n,i=new He(e))=>O(t,s=>{s.local=!1;let o=!1;const r=s.doc,l=r.store,c=Wl(i,r),a=Yl(s,l,c),d=l.pendingStructs;if(d){for(const[f,g]of d.missing)if(g<P(l,f)){o=!0;break}if(a){for(const[f,g]of a.missing){const p=d.missing.get(f);(p==null||p>g)&&d.missing.set(f,g)}d.update=Bi([d.update,a.update])}}else l.pendingStructs=a;const h=Ii(i,s,l);if(l.pendingDs){const f=new He(Wn(l.pendingDs));R(f.restDecoder);const g=Ii(f,s,l);h&&g?l.pendingDs=Bi([h,g]):l.pendingDs=h||g}else l.pendingDs=h;if(o){const f=l.pendingStructs.update;l.pendingStructs=null,jn(s.doc,f)}},n,!1),jn=(e,t,n,i=He)=>{const s=Wn(t);Jl(s,e,n,new i(s))};class Xl{constructor(){this.l=[]}}const Ai=()=>new Xl,Ti=(e,t)=>e.l.push(t),Di=(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.")},_s=(e,t,n)=>Jn(e.l,[t,n]);class Kt{constructor(t,n){this.client=t,this.clock=n}}const ve=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,v=(e,t)=>new Kt(e,t),fe=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw Q()},ge=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1};class $e{constructor(t,n,i,s=0){this.type=t,this.tname=n,this.item=i,this.assoc=s}}class Zl{constructor(t,n,i=0){this.type=t,this.index=n,this.assoc=i}}const Ql=(e,t,n=0)=>new Zl(e,t,n),_e=(e,t,n)=>{let i=null,s=null;return e._item===null?s=fe(e):i=v(e._item.id.client,e._item.id.clock),new $e(i,s,t,n)},yn=(e,t,n=0)=>{let i=e._start;if(n<0){if(t===0)return _e(e,null,n);t--}for(;i!==null;){if(!i.deleted&&i.countable){if(i.length>t)return _e(e,v(i.id.client,i.id.clock+t),n);t-=i.length}if(i.right===null&&n<0)return _e(e,i.lastId,n);i=i.right}return _e(e,null,n)},tc=(e,t)=>{const n=Wt(e,t),i=t.clock-n.id.clock;return{item:n,diff:i}},ec=(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 d=n?Ln(i,s):tc(i,s),h=d.item;if(!(h instanceof M))return null;if(c=h.parent,c._item===null||!c._item.deleted){a=h.deleted||!h.countable?0:d.diff+(l>=0?0:1);let f=h.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:d}=n?Ln(i,o):{item:Wt(i,o)};if(d instanceof M&&d.content instanceof ut)c=d.content.type;else return null}else throw Q();l>=0?a=c._length:a=0}return Ql(c,a,e.assoc)};class ei{constructor(t,n){this.ds=t,this.sv=n}}const Es=(e,t)=>new ei(e,t),Sn=e=>Es(Vl(e.store),nn(e.store)),Rt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!ee(t.ds,e.id),Nn=(e,t)=>{const n=St(e.meta,Nn,Bt),i=e.doc.store;n.has(t)||(t.sv.forEach((s,o)=>{s<P(i,o)&&X(e,v(o,s))}),At(e,t.ds,s=>{}),n.add(t))};class Is{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const nn=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},As=(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)},ht=(e,t)=>{let n=0,i=e.length-1,s=e[i],o=s.id.clock;if(o===t)return i;let r=yt(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=yt((n+i)/2)}throw Q()},nc=(e,t)=>{const n=e.clients.get(t.client);return n[ht(n,t.clock)]},Wt=nc,Bn=(e,t,n)=>{const i=ht(t,n),s=t[i];return s.id.clock<n&&s instanceof M?(t.splice(i+1,0,Ye(e,s,n-s.id.clock)),i+1):i},X=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[Bn(e,n,t.clock)]},Mi=(e,t,n)=>{const i=t.clients.get(n.client),s=ht(i,n.clock),o=i[s];return n.clock!==o.id.clock+o.length-1&&o.constructor!==st&&i.splice(s+1,0,Ye(e,o,n.clock-o.id.clock+1)),o},ic=(e,t,n)=>{const i=e.clients.get(t.id.client);i[ht(i,t.id.clock)]=n},Ts=(e,t,n,i,s)=>{if(i===0)return;const o=n+i;let r=Bn(e,t,n),l;do l=t[r++],o<l.id.clock+l.length&&Bn(e,t,o),s(l);while(r<t.length&&t[r].id.clock<o)};class sc{constructor(t,n,i){this.doc=t,this.deleteSet=new te,this.beforeState=nn(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 Oi=(e,t)=>t.deleteSet.clients.size===0&&!Sr(t.afterState,(n,i)=>t.beforeState.get(i)!==n)?!1:(Qn(t.deleteSet),Gl(e,t),ti(e,t.deleteSet),!0),Ri=(e,t,n)=>{const i=t._item;(i===null||i.id.clock<(e.beforeState.get(i.id.client)||0)&&!i.deleted)&&St(e.changed,t,Bt).add(n)},Be=(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 M&&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},oc=(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=ht(o,l.clock),d=o[a];a<o.length&&d.id.clock<c;d=o[++a]){const h=o[a];if(l.clock+l.len<=h.id.clock)break;h instanceof M&&h.deleted&&!h.keep&&n(h)&&h.gc(t,!1)}}}},rc=(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=Jt(s.length-1,1+ht(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+Be(s,c)}})},Ds=(e,t)=>{if(t<e.length){const n=e[t],i=n.doc,s=i.store,o=n.deleteSet,r=n._mergeStructs;try{Qn(o),n.afterState=nn(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(d=>d.target._item===null||!d.target._item.deleted),c.forEach(d=>{d.currentTarget=a,d._path=null}),c.sort((d,h)=>d.path.length-h.path.length),_s(a._dEH,c,n))})}),l.push(()=>i.emit("afterTransaction",[n,i])),Jn(l,[]),n._needFormattingCleanup&&Ec(n)}finally{i.gc&&oc(o,s,i.gcFilter),rc(o,s),n.afterState.forEach((d,h)=>{const f=n.beforeState.get(h)||0;if(f!==d){const g=s.clients.get(h),p=Et(ht(g,f),1);for(let m=g.length-1;m>=p;)m-=1+Be(g,m)}});for(let d=r.length-1;d>=0;d--){const{client:h,clock:f}=r[d].id,g=s.clients.get(h),p=ht(g,f);p+1<g.length&&Be(g,p+1)>1||p>0&&Be(g,p)}if(!n.local&&n.afterState.get(i.clientID)!==n.beforeState.get(i.clientID)&&(Ul(Xn,ps,"[yjs] ",ms,ws,"Changed the client-id because another client seems to be using it."),i.clientID=Cs()),i.emit("afterTransactionCleanup",[n,i]),i._observers.has("update")){const d=new zl;Oi(d,n)&&i.emit("update",[d.toUint8Array(),n.origin,i,n])}if(i._observers.has("updateV2")){const d=new en;Oi(d,n)&&i.emit("updateV2",[d.toUint8Array(),n.origin,i,n])}const{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=n;(l.size>0||a.size>0||c.size>0)&&(l.forEach(d=>{d.clientID=i.clientID,d.collectionid==null&&(d.collectionid=i.collectionid),i.subdocs.add(d)}),a.forEach(d=>i.subdocs.delete(d)),i.emit("subdocs",[{loaded:c,added:l,removed:a},i,n]),a.forEach(d=>d.destroy())),e.length<=t+1?(i._transactionCleanups=[],i.emit("afterAllTransactions",[i,e])):Ds(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 sc(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&&Ds(s,0)}}return r};class lc{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const ji=(e,t,n)=>{At(e,n.deletions,i=>{i instanceof M&&t.scope.some(s=>s===e.doc||ge(s,i))&&ri(i,!1)})},Ni=(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(),d=new Set,h=[];let f=!1;At(l,a.insertions,g=>{if(g instanceof M){if(g.redone!==null){let{item:p,diff:m}=Ln(c,g.id);m>0&&(p=X(l,v(p.id.client,p.id.clock+m))),g=p}!g.deleted&&o.some(p=>p===l.doc||ge(p,g))&&h.push(g)}}),At(l,a.deletions,g=>{g instanceof M&&o.some(p=>p===l.doc||ge(p,g))&&!ee(a.insertions,g.id)&&d.add(g)}),d.forEach(g=>{f=Js(l,g,d,a.insertions,e.ignoreRemoteMapChanges,e)!==null||f});for(let g=h.length-1;g>=0;g--){const p=h[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 Ms extends ns{constructor(t,{captureTimeout:n=500,captureTransaction:i=c=>!0,deleteFilter:s=()=>!0,trackedOrigins:o=new Set([null]),ignoreRemoteMapChanges:r=!1,doc:l=In(t)?t[0].doc:t instanceof Vt?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(b=>c.changedParentTypes.has(b)||b===this.doc)||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;const a=this.undoing,d=this.redoing,h=a?this.redoStack:this.undoStack;a?this.stopCapturing():d||this.clear(!1,!0);const f=new te;c.afterState.forEach((b,x)=>{const T=c.beforeState.get(x)||0,D=b-T;D>0&&ue(f,x,T,D)});const g=rl();let p=!1;if(this.lastChange>0&&g-this.lastChange<this.captureTimeout&&h.length>0&&!a&&!d){const b=h[h.length-1];b.deletions=Rn([b.deletions,c.deleteSet]),b.insertions=Rn([b.insertions,f])}else h.push(new lc(c.deleteSet,f)),p=!0;!a&&!d&&(this.lastChange=g),At(c,c.deleteSet,b=>{b instanceof M&&this.scope.some(x=>x===c.doc||ge(x,b))&&ri(b,!0)});const m=[{stackItem:h[h.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=In(t)?t:[t],t.forEach(i=>{n.has(i)||(n.add(i),(i instanceof q?i.doc!==this.doc:i!==this.doc)&&bs("[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=>ji(i,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>ji(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=Ni(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=Ni(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*cc(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 rt(v(s,o),c),o+=c}else if((Ze&l)!==0){const c=(l&(xt|G))===0,a=new M(v(s,o),null,(l&G)===G?e.readLeftID():null,null,(l&xt)===xt?e.readRightID():null,c?e.readParentInfo()?e.readString():e.readLeftID():null,c&&(l&ae)===ae?e.readString():null,Xs(e,l));yield a,o+=a.length}else{const c=e.readLen();yield new st(v(s,o),c),o+=c}}}}class ac{constructor(t,n){this.gen=cc(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===rt);return this.curr}}class hc{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const dc=(e,t)=>{if(e.constructor===st){const{client:n,clock:i}=e.id;return new st(v(n,i+t),e.length-t)}else if(e.constructor===rt){const{client:n,clock:i}=e.id;return new rt(v(n,i+t),e.length-t)}else{const n=e,{client:i,clock:s}=n.id;return new M(v(i,s+t),null,v(i,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Bi=(e,t=He,n=en)=>{if(e.length===1)return e[0];const i=e.map(d=>new t(Wn(d)));let s=i.map(d=>new ac(d,!0)),o=null;const r=new n,l=new hc(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===rt?1:-1:p}else return g.curr.id.client-f.curr.id.client}),s.length!==0;){const d=s[0],h=d.curr.id.client;if(o!==null){let f=d.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=d.next(),g=!0;if(f===null||f.id.client!==h||g&&f.id.clock>o.struct.id.clock+o.struct.length)continue;if(h!==o.struct.id.client)re(l,o.struct,o.offset),o={struct:f,offset:0},d.next();else if(o.struct.id.clock+o.struct.length<f.id.clock)if(o.struct.constructor===rt)o.struct.length=f.id.clock+f.length-o.struct.id.clock;else{re(l,o.struct,o.offset);const p=f.id.clock-o.struct.id.clock-o.struct.length;o={struct:new rt(v(h,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===rt?o.struct.length-=p:f=dc(f,p)),o.struct.mergeWith(f)||(re(l,o.struct,o.offset),o={struct:f,offset:0},d.next())}}else o={struct:d.curr,offset:0},d.next();for(let f=d.curr;f!==null&&f.id.client===h&&f.id.clock===o.struct.id.clock+o.struct.length&&f.constructor!==rt;f=d.next())re(l,o.struct,o.offset),o={struct:f,offset:0}}o!==null&&(re(l,o.struct,o.offset),o=null),uc(l);const c=i.map(d=>Fl(d)),a=Rn(c);return ti(r,a),r.toUint8Array()},Os=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:lt(e.encoder.restEncoder)}),e.encoder.restEncoder=Se(),e.written=0)},re=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Os(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++},uc=e=>{Os(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),Qe(t,i.restEncoder)}},Ui="You must not compute changes after the event-handler fired.";class sn{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=fc(this.currentTarget,this.target))}deletes(t){return ee(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw It(Ui);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=gn(c.content.getContent());else return;else c!==null&&this.deletes(c)?(r="update",l=gn(c.content.getContent())):(r="add",l=void 0)}else if(this.deletes(o))r="delete",l=gn(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 It(Ui);const n=this.target,i=Bt(),s=Bt(),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 fc=(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=()=>{bs("Invalid access: Add Yjs type to a document before reading data.")},Rs=80;let ni=0;class gc{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=ni++}}const pc=e=>{e.timestamp=ni++},js=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=ni++},mc=(e,t,n)=>{if(e.length>=Rs){const i=e.reduce((s,o)=>s.timestamp<o.timestamp?s:o);return js(i,t,n),i}else{const i=new gc(t,n);return e.push(i),i}},on=(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)=>Re(t-o.index)<Re(t-r.index)?o:r);let i=e._start,s=0;for(n!==null&&(i=n.p,s=n.index,pc(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&&Re(n.index-s)<i.parent.length/Rs?(js(n,i,s),n):mc(e._searchMarker,i,s)},pe=(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=Et(t,s.index+n))}},rn=(e,t,n)=>{const i=e,s=t.changedParentTypes;for(;St(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;_s(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=Ai(),this._dEH=Ai(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw at()}clone(){throw at()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,n){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){Ti(this._eH,t)}observeDeep(t){Ti(this._dEH,t)}unobserve(t){Di(this._eH,t)}unobserveDeep(t){Di(this._dEH,t)}toJSON(){}}const Ns=(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},Bs=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},Us=(e,t)=>{const n=[];let i=e._start;for(;i!==null;){if(i.countable&&Rt(i,t)){const s=i.content.getContent();for(let o=0;o<s.length;o++)n.push(s[o])}i=i.right}return n},me=(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}},Ls=(e,t)=>{const n=[];return me(e,(i,s)=>{n.push(t(i,s,e))}),n},wc=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}}}},Ps=(e,t)=>{e.doc??Y();const n=on(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}},ze=(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 d=()=>{a.length>0&&(s=new M(v(r,P(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new Pt(a)),s.integrate(e,0),a=[])};i.forEach(h=>{if(h===null)a.push(h);else switch(h.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(h);break;default:switch(d(),h.constructor){case Uint8Array:case ArrayBuffer:s=new M(v(r,P(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new ke(new Uint8Array(h))),s.integrate(e,0);break;case Vt:s=new M(v(r,P(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new Ce(h)),s.integrate(e,0);break;default:if(h instanceof q)s=new M(v(r,P(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new ut(h)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),d()},Vs=()=>It("Length exceeded!"),Fs=(e,t,n,i)=>{if(n>t._length)throw Vs();if(n===0)return t._searchMarker&&pe(t._searchMarker,n,i.length),ze(e,t,null,i);const s=n,o=on(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,v(r.id.client,r.id.clock+n));break}n-=r.length}return t._searchMarker&&pe(t._searchMarker,s,i.length),ze(e,t,r,i)},xc=(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 ze(e,t,s,n)},Hs=(e,t,n,i)=>{if(i===0)return;const s=n,o=i,r=on(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,v(l.id.client,l.id.clock+n)),n-=l.length);for(;i>0&&l!==null;)l.deleted||(i<l.length&&X(e,v(l.id.client,l.id.clock+i)),l.delete(e),i-=l.length),l=l.right;if(i>0)throw Vs();t._searchMarker&&pe(t._searchMarker,s,-o+i)},qe=(e,t,n)=>{const i=t._map.get(n);i!==void 0&&i.delete(e)},ii=(e,t,n,i)=>{const s=t._map.get(n)||null,o=e.doc,r=o.clientID;let l;if(i==null)l=new Pt([i]);else switch(i.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new Pt([i]);break;case Uint8Array:l=new ke(i);break;case Vt:l=new Ce(i);break;default:if(i instanceof q)l=new ut(i);else throw new Error("Unexpected content type")}new M(v(r,P(o.store,r)),s,s&&s.lastId,null,null,t,n,l).integrate(e,0)},si=(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},$s=e=>{const t={};return e.doc??Y(),e._map.forEach((n,i)=>{n.deleted||(t[i]=n.content.getContent()[n.length-1])}),t},zs=(e,t)=>{e.doc??Y();const n=e._map.get(t);return n!==void 0&&!n.deleted},bc=(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&&Rt(o,t)&&(n[s]=o.content.getContent()[o.length-1])}),n},Ee=e=>(e.doc??Y(),Ll(e._map.entries(),t=>!t[1].deleted));class yc extends sn{}class Yt extends q{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new Yt;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Yt}clone(){const t=new Yt;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),rn(this,t,new yc(this,t))}insert(t,n){this.doc!==null?O(this.doc,i=>{Fs(i,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?O(this.doc,n=>{xc(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?O(this.doc,i=>{Hs(i,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return Ps(this,t)}toArray(){return Bs(this)}slice(t=0,n=this.length){return Ns(this,t,n)}toJSON(){return this.map(t=>t instanceof q?t.toJSON():t)}map(t){return Ls(this,t)}forEach(t){me(this,t)}[Symbol.iterator](){return wc(this)}_write(t){t.writeTypeRef(qc)}}const Sc=e=>new Yt;class kc extends sn{constructor(t,n,i){super(t,n),this.keysChanged=i}}class Qt 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 Qt}clone(){const t=new Qt;return this.forEach((n,i)=>{t.set(i,n instanceof q?n.clone():n)}),t}_callObserver(t,n){rn(this,t,new kc(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[...Ee(this)].length}keys(){return bn(Ee(this),t=>t[0])}values(){return bn(Ee(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return bn(Ee(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=>{qe(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?O(this.doc,i=>{ii(i,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return si(this,t)}has(t){return zs(this,t)}clear(){this.doc!==null?O(this.doc,t=>{this.forEach(function(n,i,s){qe(t,s,i)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Kc)}}const Cc=e=>new Qt,vt=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&gl(e,t);class Un{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||ne(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 Li=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case F:t.right.deleted||ne(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&X(e,v(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},Ie=(e,t,n,i)=>{const s=new Map,o=i?on(t,n):null;if(o){const r=new Un(o.p.left,o.p,o.index,s);return Li(e,r,n-o.index)}else{const r=new Un(null,t._start,0,s);return Li(e,r,n)}},qs=(e,t,n,i)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===F&&vt(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,d=new M(v(o,P(s.store,o)),c,c&&c.lastId,a,a&&a.id,t,null,new F(l,r));d.integrate(e,0),n.right=d,n.forward()})},ne=(e,t)=>{const{key:n,value:i}=t;i===null?e.delete(n):e.set(n,i)},Ks=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===F&&vt(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},Ws=(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(!vt(a,c)){r.set(l,a);const{left:d,right:h}=n;n.right=new M(v(o,P(s.store,o)),d,d&&d.lastId,h,h&&h.id,t,null,new F(l,c)),n.right.integrate(e,0),n.forward()}}return r},kn=(e,t,n,i,s)=>{n.currentAttributes.forEach((f,g)=>{s[g]===void 0&&(s[g]=null)});const o=e.doc,r=o.clientID;Ks(n,s);const l=Ws(e,t,n,s),c=i.constructor===String?new dt(i):i instanceof q?new ut(i):new Ft(i);let{left:a,right:d,index:h}=n;t._searchMarker&&pe(t._searchMarker,n.index,c.getLength()),d=new M(v(r,P(o.store,r)),a,a&&a.lastId,d,d&&d.id,t,null,c),d.integrate(e,0),n.right=d,n.index=h,n.forward(),qs(e,t,n,l)},Pi=(e,t,n,i,s)=>{const o=e.doc,r=o.clientID;Ks(n,s);const l=Ws(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,d=s[c];if(d!==void 0){if(vt(d,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,v(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 M(v(r,P(o.store,r)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new dt(c)),n.right.integrate(e,0),n.forward()}qs(e,t,n,l)},Ys=(e,t,n,i,s)=>{let o=t;const r=ct();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:d,value:h}=a,f=i.get(d)??null;(r.get(d)!==a||f===h)&&(t.delete(e),l++,!c&&(s.get(d)??null)===h&&f!==h&&(f===null?s.delete(d):s.set(d,f))),!c&&!t.deleted&&ne(s,a);break}}}t=t.right}return l},vc=(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}},_c=e=>{let t=0;return O(e.doc,n=>{let i=e._start,s=e._start,o=ct();const r=En(o);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case F:ne(r,s.content);break;default:t+=Ys(n,i,s,o,r),o=En(r),i=s;break}s=s.right}}),t},Ec=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&&Ts(e,n.store.clients.get(i),o,s,r=>{!r.deleted&&r.content.constructor===F&&r.constructor!==st&&t.add(r.parent)})}O(n,i=>{At(e,e.deleteSet,s=>{if(s instanceof st||!s.parent._hasFormatting||t.has(s.parent))return;const o=s.parent;s.content.constructor===F?t.add(o):vc(i,s)});for(const s of t)_c(s)})},Vi=(e,t,n)=>{const i=n,s=En(t.currentAttributes),o=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case ut:case Ft:case dt:n<t.right.length&&X(e,v(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}o&&Ys(e,o,t.right,s,t.currentAttributes);const r=(t.left||t.right).parent;return r._searchMarker&&pe(r._searchMarker,t.index,-i+n),t};class Ic extends sn{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="",d=0,h=0;const f=()=>{if(l!==null){let g=null;switch(l){case"delete":h>0&&(g={delete:h}),h=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":d>0&&(g={retain:d},ul(c)||(g.attributes=hl({},c))),d=0;break}g&&n.push(g),l=null}};for(;r!==null;){switch(r.content.constructor){case ut:case Ft:this.adds(r)?this.deletes(r)||(f(),l="insert",a=r.content.getContent()[0],f()):this.deletes(r)?(l!=="delete"&&(f(),l="delete"),h+=1):r.deleted||(l!=="retain"&&(f(),l="retain"),d+=1);break;case dt:this.adds(r)?this.deletes(r)||(l!=="insert"&&(f(),l="insert"),a+=r.content.str):this.deletes(r)?(l!=="delete"&&(f(),l="delete"),h+=r.length):r.deleted||(l!=="retain"&&(f(),l="retain"),d+=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;vt(m,p)?p!==null&&r.delete(i):(l==="retain"&&f(),vt(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;vt(m,p)||(l==="retain"&&f(),c[g]=m)}else if(!r.deleted){o.set(g,p);const m=c[g];m!==void 0&&(vt(m,p)?m!==null&&r.delete(i):(l==="retain"&&f(),p===null?delete c[g]:c[g]=p))}r.deleted||(l==="insert"&&f(),ne(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 Tt 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 Tt}clone(){const t=new Tt;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const i=new Ic(this,t,n);rn(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===dt&&(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 Un(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)&&kn(i,this,s,l,r.attributes||{})}else r.retain!==void 0?Pi(i,this,s,r.retain,r.attributes||{}):r.delete!==void 0&&Vi(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 h={};let f=!1;o.forEach((p,m)=>{f=!0,h[m]=p});const g={insert:l};f&&(g.attributes=h),s.push(g),l=""}}const d=()=>{for(;c!==null;){if(Rt(c,t)||n!==void 0&&Rt(c,n))switch(c.content.constructor){case dt:{const h=o.get("ychange");t!==void 0&&!Rt(c,t)?(h===void 0||h.user!==c.id.client||h.type!=="removed")&&(a(),o.set("ychange",i?i("removed",c.id):{type:"removed"})):n!==void 0&&!Rt(c,n)?(h===void 0||h.user!==c.id.client||h.type!=="added")&&(a(),o.set("ychange",i?i("added",c.id):{type:"added"})):h!==void 0&&(a(),o.delete("ychange")),l+=c.content.str;break}case ut:case Ft:{a();const h={insert:c.content.getContent()[0]};if(o.size>0){const f={};h.attributes=f,o.forEach((g,p)=>{f[p]=g})}s.push(h);break}case F:Rt(c,t)&&(a(),ne(o,c.content));break}c=c.right}a()};return t||n?O(r,h=>{t&&Nn(h,t),n&&Nn(h,n),d()},"cleanup"):d(),s}insert(t,n,i){if(n.length<=0)return;const s=this.doc;s!==null?O(s,o=>{const r=Ie(o,this,t,!i);i||(i={},r.currentAttributes.forEach((l,c)=>{i[c]=l})),kn(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=Ie(o,this,t,!i);kn(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=>{Vi(s,Ie(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=Ie(o,this,t,!1);r.right!==null&&Pi(o,this,r,n,i)}):this._pending.push(()=>this.format(t,n,i))}removeAttribute(t){this.doc!==null?O(this.doc,n=>{qe(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?O(this.doc,i=>{ii(i,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return si(this,t)}getAttributes(){return $s(this)}_write(t){t.writeTypeRef(Wc)}}const Ac=e=>new Tt;class Cn{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===Lt)&&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 Lt 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 Lt}clone(){const t=new Lt;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 Cn(this,t)}querySelector(t){t=t.toUpperCase();const i=new Cn(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return i.done?null:i.value}querySelectorAll(t){return t=t.toUpperCase(),Ut(new Cn(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){rn(this,t,new Mc(this,n,t))}toString(){return Ls(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),me(this,o=>{s.insertBefore(o.toDOM(t,n,i),null)}),s}insert(t,n){this.doc!==null?O(this.doc,i=>{Fs(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;ze(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 It("Reference item not found");i.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?O(this.doc,i=>{Hs(i,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return Bs(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Ps(this,t)}slice(t=0,n=this.length){return Ns(this,t,n)}forEach(t){me(this,t)}_write(t){t.writeTypeRef(Gc)}}const Tc=e=>new Lt;class W extends Lt{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 dl(n,(i,s)=>{typeof i=="string"&&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=>{qe(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?O(this.doc,i=>{ii(i,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return si(this,t)}hasAttribute(t){return zs(this,t)}getAttributes(t){return t?bc(this,t):$s(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 me(this,r=>{s.appendChild(r.toDOM(t,n,i))}),i!==void 0&&i._createAssociation(s,this),s}_write(t){t.writeTypeRef(Yc),t.writeKey(this.nodeName)}}const Dc=e=>new W(e.readKey());class Mc extends sn{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 Ke extends Qt{constructor(t){super(),this.hookName=t}_copy(){return new Ke(this.hookName)}clone(){const t=new Ke(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(Jc),t.writeKey(this.hookName)}}const Oc=e=>new Ke(e.readKey());class Z extends Tt{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(Xc)}}const Rc=e=>new Z;class oi{constructor(t,n){this.id=t,this.length=n}get deleted(){throw at()}mergeWith(t){return!1}write(t,n,i){throw at()}integrate(t,n){throw at()}}const jc=0;class st extends oi{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),As(t.doc.store,this)}write(t,n){t.writeInfo(jc),t.writeLen(this.length-n)}getMissing(t,n){return null}}class ke{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new ke(this.content)}splice(t){throw at()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}const Nc=e=>new ke(e.readBuf());class we{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new we(this.len)}splice(t){const n=new we(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){ue(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 Bc=e=>new we(e.readLen()),Gs=(e,t)=>new Vt({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Ce{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 Ce(Gs(this.doc.guid,this.opts))}splice(t){throw at()}mergeWith(t){return!1}integrate(t,n){this.doc._item=n,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,n){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}const Uc=e=>new Ce(Gs(e.readString(),e.readAny()));class Ft{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Ft(this.embed)}splice(t){throw at()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}const Lc=e=>new Ft(e.readJSON());class F{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new F(this.key,this.value)}splice(t){throw at()}mergeWith(t){return!1}integrate(t,n){const i=n.parent;i._searchMarker=null,i._hasFormatting=!0}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}const Pc=e=>new F(e.readKey(),e.readJSON());class We{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new We(this.arr)}splice(t){const n=new We(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 Vc=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 We(n)},Fc=Fe("node_env")==="development";class Pt{constructor(t){this.arr=t,Fc&&ds(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Pt(this.arr)}splice(t){const n=new Pt(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 Hc=e=>{const t=e.readLen(),n=[];for(let i=0;i<t;i++)n.push(e.readAny());return new Pt(n)};class dt{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new dt(this.str)}splice(t){const n=new dt(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 $c=e=>new dt(e.readString()),zc=[Sc,Cc,Ac,Dc,Tc,Oc,Rc],qc=0,Kc=1,Wc=2,Yc=3,Gc=4,Jc=5,Xc=6;class ut{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new ut(this.type._copy())}splice(t){throw at()}mergeWith(t){return!1}integrate(t,n){this.type._integrate(t.doc,n)}delete(t){let n=this.type._start;for(;n!==null;)n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t),n=n.right;this.type._map.forEach(i=>{i.deleted?i.id.clock<(t.beforeState.get(i.id.client)||0)&&t._mergeStructs.push(i):i.delete(t)}),t.changed.delete(this.type)}gc(t){let n=this.type._start;for(;n!==null;)n.gc(t,!0),n=n.right;this.type._start=null,this.type._map.forEach(i=>{for(;i!==null;)i.gc(t,!0),i=i.left}),this.type._map=new Map}write(t,n){this.type._write(t)}getRef(){return 7}}const Zc=e=>new ut(zc[e.readTypeRef()](e)),Ln=(e,t)=>{let n=t,i=0,s;do i>0&&(n=v(n.client,n.clock+i)),s=Wt(e,n),i=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof M);return{item:s,diff:i}},ri=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Ye=(e,t,n)=>{const{client:i,clock:s}=t.id,o=new M(v(i,s+n),t,v(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=v(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},Fi=(e,t)=>Cr(e,n=>ee(n.deletions,t)),Js=(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 d=t.parent._item,h=null,f;if(d!==null&&d.deleted===!0){if(d.redone===null&&(!n.has(d)||Js(e,d,n,i,s,o)===null))return null;for(;d.redone!==null;)d=X(e,d.redone)}const g=d===null?t.parent:d.content.type;if(t.parentSub===null){for(h=t.left,f=t;h!==null;){let x=h;for(;x!==null&&x.parent._item!==d;)x=x.redone===null?null:X(e,x.redone);if(x!==null&&x.parent._item===d){h=x;break}h=h.left}for(;f!==null;){let x=f;for(;x!==null&&x.parent._item!==d;)x=x.redone===null?null:X(e,x.redone);if(x!==null&&x.parent._item===d){f=x;break}f=f.right}}else if(f=null,t.right&&!s){for(h=t;h!==null&&h.right!==null&&(h.right.redone||ee(i,h.right.id)||Fi(o.undoStack,h.right.id)||Fi(o.redoStack,h.right.id));)for(h=h.right;h.redone;)h=X(e,h.redone);if(h&&h.right!==null)return null}else h=g._map.get(t.parentSub)||null;const p=P(l,c),m=v(c,p),b=new M(m,h,h&&h.lastId,f,f&&f.id,g,t.parentSub,t.content.copy());return t.redone=m,ri(b,!0),b.integrate(e,0),b};class M extends oi{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()?wi:0}set marker(t){(this.info&mn)>0!==t&&(this.info^=mn)}get marker(){return(this.info&mn)>0}get keep(){return(this.info&mi)>0}set keep(t){this.keep!==t&&(this.info^=mi)}get countable(){return(this.info&wi)>0}get deleted(){return(this.info&pn)>0}set deleted(t){this.deleted!==t&&(this.info^=pn)}markDeleted(){this.info|=pn}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===Kt&&this.id.client!==this.parent.client&&this.parent.clock>=P(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Mi(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===st||this.right&&this.right.constructor===st)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===M?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===M&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Kt){const i=Wt(n,this.parent);i.constructor===st?this.parent=null:this.parent=i.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=Mi(t,t.doc.store,v(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),ve(this.origin,s.origin)){if(s.id.client<this.id.client)i=s,o.clear();else if(ve(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&r.has(Wt(t.doc.store,s.origin)))o.has(Wt(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),As(t.doc.store,this),this.content.integrate(t,this),Ri(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new st(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:v(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&ve(t.origin,this.lastId)&&this.right===t&&ve(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const n=this.parent._searchMarker;return n&&n.forEach(i=>{i.p===t&&(i.p=this,!this.deleted&&this.countable&&(i.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),ue(t.deleteSet,this.id.client,this.id.clock,this.length),Ri(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw Q();this.content.gc(t),n?ic(t,this,new st(this.id,this.length)):this.content=new we(this.length)}write(t,n){const i=n>0?v(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,o=this.parentSub,r=this.content.getRef()&Ze|(i===null?0:G)|(s===null?0:xt)|(o===null?0:ae);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=fe(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===Kt?(t.writeParentInfo(!1),t.writeLeftID(l)):Q();o!==null&&t.writeString(o)}this.content.write(t,n)}}const Xs=(e,t)=>Qc[t&Ze](e),Qc=[()=>{Q()},Bc,Vc,Nc,$c,Lc,Pc,Zc,Hc,Uc,()=>{Q()}],ta=10;class rt extends oi{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(ta),A(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const Zs=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Qs="__ $YJS$ __";Zs[Qs]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Zs[Qs]=!0;const ea=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},na=/[\uD800-\uDBFF]/,ia=/[\uDC00-\uDFFF]/,sa=(e,t)=>{let n=0,i=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&na.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&&ia.test(e[e.length-i])&&i--,{index:n,remove:e.length-n-i,insert:t.slice(n,t.length-i)}},oa=sa,mt=(e,t)=>e>>>t|e<<32-t,ra=e=>mt(e,2)^mt(e,13)^mt(e,22),la=e=>mt(e,6)^mt(e,11)^mt(e,25),ca=e=>mt(e,7)^mt(e,18)^e>>>3,aa=e=>mt(e,17)^mt(e,19)^e>>>10,ha=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]),da=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class ua{constructor(){const t=new ArrayBuffer(320);this._H=new Uint32Array(t,0,8),this._H.set(da),this._W=new Uint32Array(t,64,64)}_updateHash(){const t=this._H,n=this._W;for(let h=16;h<64;h++)n[h]=aa(n[h-2])+n[h-7]+ca(n[h-15])+n[h-16];let i=t[0],s=t[1],o=t[2],r=t[3],l=t[4],c=t[5],a=t[6],d=t[7];for(let h=0,f,g;h<64;h++)f=d+la(l)+(l&c^~l&a)+ha[h]+n[h]>>>0,g=ra(i)+(i&s^i&o^s&o)>>>0,d=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]+=d}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/vr,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 fa=e=>new ua().digest(e),N=new E.PluginKey("y-sync"),bt=new E.PluginKey("y-undo");new E.PluginKey("yjs-cursor");const ga=e=>{for(let n=6;n<e.length;n++)e[n%6]=e[n%6]^e[n];return e.slice(0,6)},pa=e=>kl(ga(fa(Cl(e)))),Ge=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!ee(t.ds,e.id),ma=[{light:"#ecd44433",dark:"#ecd444"}],wa=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){const i=Bt();e.forEach(s=>i.add(s)),t=t.filter(s=>!i.has(s))}e.set(n,il(t))}return e.get(n)},xa=(e,{colors:t=ma,colorMapping:n=new Map,permanentUserData:i=null,onFirstRender:s=()=>{},mapping:o}={})=>{let r=!1;const l=new Sa(e,o),c=new E.Plugin({props:{editable:a=>{const d=N.getState(a);return d.snapshot==null&&d.prevSnapshot==null}},key:N,state:{init:(a,d)=>({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,d)=>{const h=a.getMeta(N);if(h!==void 0){d=Object.assign({},d);for(const f in h)d[f]=h[f]}return d.addToHistory=a.getMeta("addToHistory")!==!1,d.isChangeOrigin=h!==void 0&&!!h.isChangeOrigin,d.isUndoRedoOperation=h!==void 0&&!!h.isChangeOrigin&&!!h.isUndoRedoOperation,l.prosemirrorView!==null&&h!==void 0&&(h.snapshot!=null||h.prevSnapshot!=null)&&gs(0,()=>{l.prosemirrorView!=null&&(h.restore==null?l._renderSnapshot(h.snapshot,h.prevSnapshot,d):(l._renderSnapshot(h.snapshot,h.snapshot,d),delete d.restore,delete d.snapshot,delete d.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),d}},view:a=>(l.initView(a),o==null&&l._forceRerender(),s(),{update:()=>{const d=c.getState(a.state);if(d.snapshot==null&&d.prevSnapshot==null&&(r||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(r=!0,d.addToHistory===!1&&!d.isChangeOrigin){const h=bt.getState(a.state),f=h&&h.undoManager;f&&f.stopCapturing()}l.mux(()=>{d.doc.transact(h=>{h.meta.set("addToHistory",d.addToHistory),l._prosemirrorChanged(a.state.doc)},N)})}},destroy:()=>{l.destroy()}})});return c},ba=(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=ce(n.doc,n.type,t.anchor,n.mapping);e.setSelection(ya(e,i))}else{const i=ce(n.doc,n.type,t.anchor,n.mapping),s=ce(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)))}},ya=(e,t)=>{const n=e.doc.resolve(t);return n.nodeAfter?E.NodeSelection.create(e.doc,t):E.TextSelection.near(n)},Pn=(e,t)=>({type:t.selection.jsonID,anchor:Xe(t.selection.anchor,e.type,e.mapping),head:Xe(t.selection.head,e.type,e.mapping)});class Sa{constructor(t,n=new Map){this.type=t,this.prosemirrorView=null,this.mux=ea(),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=Pn(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()?(us&&this._domSelectionInView===null&&(gs(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=_l.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=Es(ks(),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=>Ue(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=>Ue(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=Jt(Et(t.anchor,0),i.doc.content.size),o=Jt(Et(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=Sn(this.doc)),t instanceof Uint8Array||n instanceof Uint8Array)if((!(t instanceof Uint8Array)||!(n instanceof Uint8Array))&&Q(),s=new Vt({gc:!1}),jn(s,n),n=Sn(s),jn(s,t),t=Sn(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=ht(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(h=>{At(r,h,f=>{})});const c=(h,f)=>{const g=h==="added"?l.getUserByClientId(f.client):l.getUserByDeletedId(f);return{user:g,type:h,color:wa(i.colorMapping,i.colors,g)}},a=Us(o,new ei(n.ds,t.sv)).map(h=>!h._item.deleted||Ge(h._item,t)||Ge(h._item,n)?Ue(h,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},t,n,c):null).filter(h=>h!==null),d=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new E.Slice(E.Fragment.from(a),0,0));this.prosemirrorView.dispatch(d.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);At(n,n.deleteSet,l=>{if(l.constructor===M){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=>to(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));ba(r,this.beforeTransactionSelection,this),r=r.setMeta(N,{isChangeOrigin:!0,isUndoRedoOperation:n.origin instanceof Ms}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&r.scrollIntoView(),this.prosemirrorView.dispatch(r)})}_prosemirrorChanged(t){this.doc.transact(()=>{Fn(this.doc,this.type,t,this),this.beforeTransactionSelection=Pn(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 to=(e,t,n,i,s,o)=>{const r=n.mapping.get(e);if(r===void 0){if(e instanceof W)return Ue(e,t,n,i,s,o);throw at()}return r},Ue=(e,t,n,i,s,o)=>{const r=[],l=c=>{var a,d;if(c instanceof W){const h=to(c,t,n,i,s,o);h!==null&&r.push(h)}else{const h=(d=(a=c._item.right)==null?void 0:a.content)==null?void 0:d.type;h instanceof Tt&&!h._item.deleted&&h._item.id.client===h.doc.clientID&&(c.applyDelta([{retain:c.length},...h.toDelta()]),h.doc.transact(g=>{h._item.delete(g)}));const f=ka(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):Us(e,new ei(s.ds,i.sv)).forEach(l);try{const c=e.getAttributes(i);i!==void 0&&(Ge(e._item,i)?Ge(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}},ka=(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,Aa(a.attributes,t)))}}catch{return e.doc.transact(a=>{e._item.delete(a)},N),null}return r},Ca=(e,t)=>{const n=new Z,i=e.map(s=>({insert:s.text,attributes:no(s.marks,t)}));return n.applyDelta(i),t.mapping.set(n,e),n},va=(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,ln(e).map(i=>Vn(i,t))),t.mapping.set(n,e),n},Vn=(e,t)=>e instanceof Array?Ca(e,t):va(e,t),Hi=e=>typeof e=="object"&&e!==null,li=(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||Hi(r)&&Hi(l)&&li(r,l)}return i},ln=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},eo=(e,t)=>{const n=e.toDelta();return n.length===t.length&&n.every((i,s)=>i.insert===t[s].text&&as(i.attributes||{}).length===t[s].marks.length&&hs(i.attributes,(o,r)=>{var d;const l=ci(r),c=t[s].marks;return c.find(h=>h.type.name===l)?li(o,(d=c.find(h=>h.type.name===l))==null?void 0:d.attrs):!1}))},xe=(e,t)=>{if(e instanceof W&&!(t instanceof Array)&&Hn(e,t)){const n=ln(t);return e._length===n.length&&li(e.getAttributes(),t.attrs)&&e.toArray().every((i,s)=>xe(i,n[s]))}return e instanceof Z&&t instanceof Array&&eo(e,t)},Je=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((n,i)=>t[i]===n),$i=(e,t,n)=>{const i=e.toArray(),s=ln(t),o=s.length,r=i.length,l=Jt(r,o);let c=0,a=0,d=!1;for(;c<l;c++){const h=i[c],f=s[c];if(Je(n.mapping.get(h),f))d=!0;else if(!xe(h,f))break}for(;c+a<l;a++){const h=i[r-a-1],f=s[o-a-1];if(Je(n.mapping.get(h),f))d=!0;else if(!xe(h,f))break}return{equalityFactor:c+a,foundMappedChild:d}},_a=e=>{let t="",n=e._start;const i={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof dt?t+=n.content.str:n.content instanceof F&&(i[n.content.key]=null)),n=n.right;return{str:t,nAttrs:i}},Ea=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:i,str:s}=_a(e),o=t.map(a=>({insert:a.text,attributes:Object.assign({},i,no(a.marks,n))})),{insert:r,remove:l,index:c}=oa(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})))},Ia=/(.*)(--[a-zA-Z0-9+/=]{8})$/,ci=e=>{var t;return((t=Ia.exec(e))==null?void 0:t[1])??e},Aa=(e,t)=>{const n=[];for(const i in e)n.push(t.mark(ci(i),e[i]));return n},no=(e,t)=>{const n={};return e.forEach(i=>{if(i.type.name!=="ychange"){const s=St(t.isOMark,i.type,()=>!i.type.excludes(i.type));n[s?`${i.type.name}--${pa(i.toJSON())}`:i.type.name]=i.attrs}}),n},Fn=(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 h=t.getAttributes(),f=n.attrs;for(const g in f)f[g]!==null?h[g]!==f[g]&&g!=="ychange"&&t.setAttribute(g,f[g]):t.removeAttribute(g);for(const g in h)f[g]===void 0&&t.removeAttribute(g)}const s=ln(n),o=s.length,r=t.toArray(),l=r.length,c=Jt(o,l);let a=0,d=0;for(;a<c;a++){const h=r[a],f=s[a];if(!Je(i.mapping.get(h),f))if(xe(h,f))i.mapping.set(h,f);else break}for(;d+a+1<c;d++){const h=r[l-d-1],f=s[o-d-1];if(!Je(i.mapping.get(h),f))if(xe(h,f))i.mapping.set(h,f);else break}e.transact(()=>{for(;l-a-d>0&&o-a-d>0;){const f=r[a],g=s[a],p=r[l-d-1],m=s[o-d-1];if(f instanceof Z&&g instanceof Array)eo(f,g)||Ea(f,g,i),a+=1;else{let b=f instanceof W&&Hn(f,g),x=p instanceof W&&Hn(p,m);if(b&&x){const T=$i(f,g,i),D=$i(p,m,i);T.foundMappedChild&&!D.foundMappedChild?x=!1:!T.foundMappedChild&&D.foundMappedChild||T.equalityFactor<D.equalityFactor?b=!1:x=!1}b?(Fn(e,f,g,i),a+=1):x?(Fn(e,p,m,i),d+=1):(i.mapping.delete(t.get(a)),t.delete(a,1),t.insert(a,[Vn(g,i)]),a+=1)}}const h=l-a-d;if(l===1&&o===0&&r[0]instanceof Z?(i.mapping.delete(r[0]),r[0].delete(0,r[0].length)):h>0&&(t.slice(a,a+h).forEach(f=>i.mapping.delete(f)),t.delete(a,h)),a+d<o){const f=[];for(let g=a;g<o-d;g++)f.push(Vn(s[g],i));t.insert(a,f)}},N)},Hn=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,Xe=(e,t,n)=>{if(e===0)return yn(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 yn(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 $e(i._item===null?null:i._item.id,i._item===null?fe(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 $e(i._item===null?null:i._item.id,i._item===null?fe(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 Ta(i._item.parent,i._item)}return yn(t,t._length,-1)},Ta=(e,t)=>{let n=null,i=null;return e._item===null?i=fe(e):n=v(e._item.id.client,e._item.id.clock),new $e(n,i,t.id)},ce=(e,t,n,i)=>{const s=ec(n,e);if(s===null||s.type!==t&&!ge(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 Da(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],h={type:ci(c)};return Object.keys(a)&&(h.attrs=a),h})),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 Ma=e=>{const t=bt.getState(e).undoManager;if(t!=null)return t.undo(),!0},Oa=e=>{const t=bt.getState(e).undoManager;if(t!=null)return t.redo(),!0},Ra=new Set(["paragraph"]),ja=(e,t)=>!(e instanceof M)||!(e.content instanceof ut)||!(e.content.type instanceof Tt||e.content.type instanceof W&&t.has(e.content.type.nodeName))||e.content.type._length===0,Na=({protectedNodes:e=Ra,trackedOrigins:t=[],undoManager:n=null}={})=>new E.Plugin({key:bt,state:{init:(i,s)=>{const o=N.getState(s),r=n||new Ms(o.type,{trackedOrigins:new Set([N].concat(t)),deleteFilter:l=>ja(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,d=c.redoStack.length>0;return l?{undoManager:c,prevSel:Pn(l,o),hasUndoOps:a,hasRedoOps:d}:a!==s.hasUndoOps||d!==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=bt.getState(i.state).undoManager;return o.on("stack-item-added",({stackItem:r})=>{const l=s.binding;l&&r.meta.set(l,bt.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 io(e){return!!e.getMeta(N)}function Ba(e,t){const n=N.getState(e);return ce(n.doc,n.type,t,n.binding.mapping)||0}function so(e,t){const n=N.getState(e);return Xe(t,n.type,n.binding.mapping)}var Le=class oo extends E.MappablePosition{constructor(t,n){super(t),this.yRelativePosition=n}static fromJSON(t){return new oo(t.position,t.yRelativePosition)}toJSON(){return{position:this.position,yRelativePosition:this.yRelativePosition}}};function Ua(e,t){const n=so(t,e);return new Le(e,n)}function La(e,t,n){const i=e instanceof Le?e.yRelativePosition:null;if(io(t)&&i){const r=Ba(n,i);return{position:new Le(r,i),mapResult:null}}const s=E.getUpdatedPosition(e,t),o=s.position.position;return{position:new Le(o,i??so(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)=>La(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>Ua(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),bt.getState(t).undoManager.undoStack.length===0?!1:n?Ma(t):!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),bt.getState(t).undoManager.redoStack.length===0?!1:n?Oa(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=Na(this.options.yUndoOptions),i=n.spec.view;n.spec.view=r=>{const{undoManager:l}=bt.getState(r.state);l.restore&&(l.restore(),l.restore=()=>{});const c=i?i(r):void 0;return{destroy:()=>{const a=l.trackedOrigins.has(l),d=l._observers;l.restore=()=>{a&&l.trackedOrigins.add(l),l.doc.on("afterTransaction",l.afterTransactionHandler),l._observers=d},c!=null&&c.destroy&&c.destroy()}}};const s={...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender},o=xa(t,s);return this.editor.options.enableContentCheck&&((e=t.doc)==null||e.on("beforeTransaction",()=>{try{const r=Da(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 zi(e){if(!e.length)return fn.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(fn.Decoration.node(s,s+o.nodeSize,{class:"ProseMirror-selectednoderange"}))}),fn.DecorationSet.create(n,t)}function cn(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 Mo.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,d=a+l.nodeSize;if(a<o.start||a>=o.end)return;const h=new J.SelectionRange(s.resolve(a),s.resolve(d));i.push(h)}),i}var Pa=class ro{constructor(t,n){this.anchor=t,this.head=n}map(t){return new ro(t.map(this.anchor),t.map(this.head))}resolve(t){const n=t.resolve(this.anchor),i=t.resolve(this.head);return new _t(n,i)}},_t=class Ct 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,d=cn(a.min(c),a.max(c),i),h=c.pos>=t.pos?d[0].$from:d[d.length-1].$to,f=c.pos>=t.pos?d[d.length-1].$to:d[0].$from;super(h,f,d),this.depth=i}get $to(){return this.ranges[this.ranges.length-1].$to}eq(t){return t instanceof Ct&&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 Ct(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 Ct(o,r,this.depth)}const n=this.ranges[0],i=t.resolve(Math.max(0,n.$from.pos-1));return new Ct(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 Ct(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 Ct(this.$anchor,i,this.depth)}static fromJSON(t,n){return new Ct(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 Pa(this.anchor,this.head)}};_t.prototype.visible=!1;function Ae(e){return e instanceof _t}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(!Ae(o)){const d=_t.create(s,l,c,t,-1);return r.setSelection(d),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(!Ae(o)){const d=_t.create(s,l,c,t);return r.setSelection(d),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=_t.create(s,0,s.content.size,t);return o.setSelection(r),n.dispatch(o),!0}}},onSelectionUpdate(){const{selection:e}=this.editor.state;Ae(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,d=o?a:l;return(s==null||s==="Shift"&&r||s==="Control"&&l||s==="Alt"&&c||s==="Meta"&&a||s==="Mod"&&d)&&(t=!0),t&&document.addEventListener("mouseup",()=>{t=!1;const{state:h}=n,{doc:f,selection:g,tr:p}=h,{$anchor:m,$head:b}=g;if(m.sameParent(b))return;const x=_t.create(f,m.pos,b.pos,this.options.depth);p.setSelection(x),n.dispatch(p)},{once:!0}),!1}},decorations:n=>{const{selection:i}=n,s=Ae(i);if(e=!1,!t)return s?(e=!0,zi(i.ranges)):null;const{$from:o,$to:r}=i;if(!s&&o.sameParent(r))return null;const l=cn(o,r,this.options.depth);return l.length?(e=!0,zi(l)):null}}})]}});function Va(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 Fa(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=Va(s)}),t}function Ha(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 $a(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),d=.5,h=Math.abs(l.left-c.left)<d,f=Math.abs(l.right-c.right)<d;let g=l;return h&&f&&(g=l),{x:Math.min(Math.max(g.left+i,t),g.right-i),y:a}}var lo=e=>{const{x:t,y:n,editor:i}=e,{view:s,state:o}=i,{x:r,y:l}=$a(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=Ha(f,s);return g?(a=g,!0):!1}),!a)return{resultElement:null,resultNode:null,pos:null};let d;try{d=s.posAtDOM(a,0)}catch{return{resultElement:null,resultNode:null,pos:null}}const h=o.doc.nodeAt(d);return{resultElement:a,resultNode:h,pos:d}};function Te(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(Te(e.dom,"paddingLeft"),10),s=parseInt(Te(e.dom,"paddingRight"),10),o=parseInt(Te(e.dom,"borderLeftWidth"),10),r=parseInt(Te(e.dom,"borderLeftWidth"),10),l=e.dom.getBoundingClientRect();return{left:za(t,l.left+i+o,l.right-s-r),top:n}}function co(e){var t;(t=e.parentNode)==null||t.removeChild(e)}function Ka(e,t){const{doc:n}=t.view.state,i=lo({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),d=n.resolve(i.pos+1);return cn(a,d,0)}function Wa(e,t){const{view:n}=t;if(!e.dataTransfer)return;const{empty:i,$from:s,$to:o}=n.state.selection,r=Ka(e,t),l=cn(s,o,0),c=l.some(b=>r.find(x=>x.$from===b.$from&&x.$to===b.$to)),a=i||!c?r:l;if(!a.length)return;const{tr:d}=n.state,h=document.createElement("div"),f=a[0].$from.pos,g=a[a.length-1].$to.pos,p=_t.create(n.state.doc,f,g),m=p.content();a.forEach(b=>{const x=n.nodeDOM(b.$from.pos),T=Fa(x);h.append(T)}),h.style.position="absolute",h.style.top="-10000px",document.body.append(h),e.dataTransfer.clearData(),e.dataTransfer.setDragImage(h,0,0),n.dragging={slice:m,move:!0},d.setSelection(p),n.dispatch(d),document.addEventListener("drop",()=>co(h),{once:!0})}var qi=(e,t)=>{const n=e.resolve(t),{depth:i}=n;return i===0?t:n.pos-n.parentOffset-1},Ki=(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},vn=(e,t)=>{const n=N.getState(e);return n?Xe(t,n.type,n.binding.mapping):null},Ya=(e,t)=>{const n=N.getState(e);return n?ce(n.doc,n.type,t,n.binding.mapping)||0:-1},Wi=(e,t)=>{let n=t;for(;n!=null&&n.parentNode&&n.parentNode!==e.dom;)n=n.parentNode;return n},ao=new J.PluginKey("dragHandle"),ho=({pluginKey:e=ao,element:t,editor:n,computePositionConfig:i,getReferencedVirtualElement:s,onNodeChange:o,onElementDragStart:r,onElementDragEnd:l})=>{const c=document.createElement("div");let a=!1,d=null,h=-1,f,g=null,p=null;function m(){t&&(t.style.visibility="hidden",t.style.pointerEvents="none")}function b(){if(t){if(!n.isEditable){m();return}t.style.visibility="",t.style.pointerEvents="auto"}}function x(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 T(C){r==null||r(C),Wa(C,n),t&&(t.dataset.dragging="true"),setTimeout(()=>{t&&(t.style.pointerEvents="none")},0)}function D(C){l==null||l(C),m(),t&&(t.style.pointerEvents="auto",t.dataset.dragging="false")}return t.addEventListener("dragstart",T),t.addEventListener("dragend",D),c.appendChild(t),{unbind(){t.removeEventListener("dragstart",T),t.removeEventListener("dragend",D),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,d=null,h=-1,o==null||o({editor:n,node:null,pos:-1}),B;if(C.docChanged&&h!==-1&&t)if(io(C)){const $=Ya(S,f);$!==h&&(h=$)}else{const $=C.mapping.map(h);$!==h&&(h=$,f=vn(S,h))}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)||h===-1)return;let k=C.nodeDOM(h);if(k=Wi(C,k),k===C.dom||(k==null?void 0:k.nodeType)!==1)return;const j=C.posAtDOM(k,0),$=Ki(n.state.doc,j),nt=qi(n.state.doc,j);d=$,h=nt,f=vn(C.state,h),o==null||o({editor:n,node:d,pos:h}),x(k)},destroy(){g&&(cancelAnimationFrame(g),g=null,p=null),t&&co(c)}}},props:{handleDOMEvents:{keydown(C){return!t||a||C.hasFocus()&&(m(),d=null,h=-1,o==null||o({editor:n,node:null,pos:-1})),!1},mouseleave(C,B){return a||B.target&&!c.contains(B.relatedTarget)&&(m(),d=null,h=-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=lo({x:I,y:S,editor:n});if(!k.resultElement)return;let j=k.resultElement;if(j=Wi(C,j),j===C.dom||(j==null?void 0:j.nodeType)!==1)return;const $=C.posAtDOM(j,0),nt=Ki(n.state.doc,$);if(nt!==d){const Dt=qi(n.state.doc,$);d=nt,h=Dt,f=vn(C.state,h),o==null||o({editor:n,node:d,pos:h}),x(j),b()}})),!1}}}})}},$n={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[ho({computePositionConfig:{...$n,...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 Ga=e=>{const{className:t="drag-handle",children:n,editor:i,pluginKey:s=ao,onNodeChange:o,onElementDragStart:r,onElementDragEnd:l,computePositionConfig:c=$n}=e,[a,d]=w.useState(null),h=w.useRef(null);return w.useEffect(()=>{let f=null;return a?i.isDestroyed?()=>{h.current=null}:(h.current||(f=ho({editor:i,element:a,pluginKey:s,computePositionConfig:{...$n,...c},onElementDragStart:r,onElementDragEnd:l,onNodeChange:o}),h.current=f.plugin,i.registerPlugin(h.current)),()=>{i.unregisterPlugin(s),h.current=null,f&&(f.unbind(),f=null)}):()=>{h.current=null}},[a,i,o,s,c,r,l]),u.jsx("div",{className:t,style:{visibility:"hidden",position:"absolute"},"data-dragging":"false",ref:d,children:n})},Ja=Ga;function Xa(){var I,S,k,j,$,nt,Dt,Mt;const e=K.useEditorInstance(),t=y.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(_=>(_==null?void 0:_.name)===Zi.TextAlign.name),d=(j=(k=e==null?void 0:e.extensionManager)==null?void 0:k.extensions)==null?void 0:j.some(_=>(_==null?void 0:_.name)===se.Indent.name),h=(nt=($=e==null?void 0:e.extensionManager)==null?void 0:$.extensions)==null?void 0:nt.some(_=>(_==null?void 0:_.name)===Oo.Clear.name);function f(){const _=e.chain();_.setNodeSelection(o).unsetAllMarks(),(i==null?void 0:i.type.name)!=="paragraph"&&_.setParagraph(),_.run()}function g(){e.chain().focus().setNodeSelection(o).run(),document.execCommand("copy")}function p(){e.commands.setNodeSelection(o);const{$anchor:_}=e.state.selection,ft=_.node(1)||e.state.selection.node;e.chain().setMeta("hideDragHandle",!0).insertContentAt(o+((i==null?void 0:i.nodeSize)||0),ft.toJSON()).run()}function m(_){e.commands.setTextAlign(_)}function b(){const _=se.setNodeIndentMarkup(e.state.tr,o,1);_.setMeta("hideDragHandle",!0),e.view.dispatch&&e.view.dispatch(_)}function x(){const _=se.setNodeIndentMarkup(e.state.tr,o,-1);e.view.dispatch&&e.view.dispatch(_)}function T(){e.chain().setMeta("hideDragHandle",!0).setNodeSelection(o).deleteSelection().run()}function D({node:_,pos:ft}){_&&s(_),r(ft)}function C(){var _;if(o!==-1){const ft=(i==null?void 0:i.nodeSize)||0,ie=o+ft,Ht=(i==null?void 0:i.type.name)==="paragraph"&&((_=i==null?void 0:i.content)==null?void 0:_.size)===0,uo=Ht?o+2:ie+2;e.chain().command(({dispatch:ai,tr:an,state:hi})=>ai?(Ht?an.insertText("/",o,o+1):an.insert(ie,hi.schema.nodes.paragraph.create(null,[hi.schema.text("/")])),ai(an)):!0).focus(uo).run()}}w.useEffect(()=>(l?e.commands.setMeta("lockDragHandle",!0):e.commands.setMeta("lockDragHandle",!1),()=>{e.commands.setMeta("lockDragHandle",!1)}),[l]);const B=_=>{t&&c(_)};return u.jsxs(u.Fragment,{children:[u.jsx(Ja,{editor:e,onNodeChange:D,pluginKey:"RichTextBubbleMenuDragHandle",children:u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-0.5 richtext-duration-200 richtext-ease-in-out [transition-property:top,_left]",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:_=>{_.preventDefault(),_.stopPropagation(),B(!l)}})]})}),u.jsxs(U.DropdownMenu,{onOpenChange:B,open:l,children:[u.jsx("div",{className:"richtext-relative richtext-flex richtext-flex-col",children:u.jsx(U.DropdownMenuTrigger,{className:"richtext-absolute richtext-left-0 richtext-top-0 richtext-z-0 richtext-size-[28px]"})}),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:T,children:[u.jsx(ot.IconComponent,{name:"Trash2"}),u.jsx("span",{children:n("editor.remove")})]}),h?u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:f,children:[u.jsx(ot.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(ot.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(ot.IconComponent,{name:"Copy"}),u.jsx("span",{children:n("editor.copy")})]}),a||d?u.jsx(U.DropdownMenuSeparator,{}):null,a?u.jsxs(U.DropdownMenuSub,{children:[u.jsxs(U.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[u.jsx(ot.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(ot.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(ot.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(ot.IconComponent,{name:"AlignRight"}),u.jsx("span",{children:n("editor.textalign.right.tooltip")})]})]})})]}):null,d?u.jsxs(U.DropdownMenuSub,{children:[u.jsxs(U.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[u.jsx(ot.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:((Dt=i==null?void 0:i.attrs)==null?void 0:Dt.indent)>=se.IndentProps.max,onClick:b,children:[u.jsx(ot.IconComponent,{name:"IndentIncrease"}),u.jsx("span",{children:n("editor.indent.tooltip")})]}),u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((Mt=i==null?void 0:i.attrs)==null?void 0:Mt.indent)<=se.IndentProps.min,onClick:x,children:[u.jsx(ot.IconComponent,{name:"IndentDecrease"}),u.jsx("span",{children:n("editor.outdent.tooltip")})]})]})})]}):null]})]})]})}exports.RichTextBubbleColumns=Bo;exports.RichTextBubbleDrawer=Zo;exports.RichTextBubbleExcalidraw=tr;exports.RichTextBubbleIframe=er;exports.RichTextBubbleImage=ar;exports.RichTextBubbleImageGif=hr;exports.RichTextBubbleKatex=ir;exports.RichTextBubbleLink=or;exports.RichTextBubbleMenuDragHandle=Xa;exports.RichTextBubbleMermaid=pr;exports.RichTextBubbleTable=mr;exports.RichTextBubbleText=xr;exports.RichTextBubbleTwitter=br;exports.RichTextBubbleVideo=dr;