reactjs-tiptap-editor 1.0.26 → 1.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/lib/{ActionMenuButton-B4KDkZ0z.js → ActionMenuButton-BhiGvRJ7.js} +1 -1
  2. package/lib/{ActionMenuButton-C3Cfeza9.cjs → ActionMenuButton-qUxkZlQg.cjs} +1 -1
  3. package/lib/Attachment.cjs +1 -1
  4. package/lib/Attachment.js +27 -27
  5. package/lib/Blockquote.cjs +3 -3
  6. package/lib/Blockquote.js +251 -244
  7. package/lib/Bold.cjs +1 -1
  8. package/lib/Bold.js +2 -2
  9. package/lib/BulletList.cjs +1 -1
  10. package/lib/BulletList.js +2 -2
  11. package/lib/Callout-B9uXfbP3.js +340 -0
  12. package/lib/Callout-C_TXsss3.cjs +1 -0
  13. package/lib/Callout.cjs +1 -1
  14. package/lib/Callout.js +8 -222
  15. package/lib/Clear.cjs +1 -1
  16. package/lib/Clear.js +2 -2
  17. package/lib/Code.cjs +1 -1
  18. package/lib/Code.js +2 -2
  19. package/lib/CodeBlock.cjs +1 -1
  20. package/lib/CodeBlock.js +2 -2
  21. package/lib/CodeView.cjs +1 -1
  22. package/lib/CodeView.js +2 -2
  23. package/lib/Color.cjs +1 -1
  24. package/lib/Color.js +3 -3
  25. package/lib/Column.cjs +1 -1
  26. package/lib/Column.js +2 -2
  27. package/lib/{Drawer-D7E9kTca.cjs → Drawer-D3B4lQJF.cjs} +1 -1
  28. package/lib/{Drawer-DA0FLHs9.js → Drawer-h401Yy6Y.js} +20 -20
  29. package/lib/Drawer.cjs +1 -1
  30. package/lib/Drawer.js +4 -4
  31. package/lib/Emoji.cjs +1 -1
  32. package/lib/Emoji.js +168 -135
  33. package/lib/Excalidraw.cjs +1 -1
  34. package/lib/Excalidraw.js +5 -5
  35. package/lib/ExportPdf.cjs +1 -1
  36. package/lib/ExportPdf.js +2 -2
  37. package/lib/ExportWord.cjs +1 -1
  38. package/lib/ExportWord.js +2 -2
  39. package/lib/FontFamily.cjs +1 -1
  40. package/lib/FontFamily.js +5 -5
  41. package/lib/FontSize.cjs +1 -1
  42. package/lib/FontSize.js +5 -5
  43. package/lib/FormatPainter.cjs +1 -1
  44. package/lib/FormatPainter.js +2 -2
  45. package/lib/Heading.cjs +1 -1
  46. package/lib/Heading.js +10 -10
  47. package/lib/Highlight.cjs +1 -1
  48. package/lib/Highlight.js +3 -3
  49. package/lib/History.cjs +2 -2
  50. package/lib/History.js +584 -531
  51. package/lib/HorizontalRule.cjs +1 -1
  52. package/lib/HorizontalRule.js +2 -2
  53. package/lib/{Iframe-DZ3r3QzK.js → Iframe-Dhn40BXx.js} +3 -3
  54. package/lib/{Iframe-OMVd0xa_.cjs → Iframe-bvGuzYwC.cjs} +1 -1
  55. package/lib/Iframe.cjs +1 -1
  56. package/lib/Iframe.js +3 -3
  57. package/lib/Image.cjs +1 -1
  58. package/lib/Image.js +9 -6
  59. package/lib/ImageGif.cjs +1 -1
  60. package/lib/ImageGif.js +19 -19
  61. package/lib/ImportWord.cjs +1 -1
  62. package/lib/ImportWord.js +15 -15
  63. package/lib/{Indent-kI4G-clX.js → Indent-BK9DvCL7.js} +2 -2
  64. package/lib/{Indent-QgCoonRk.cjs → Indent-IOByomps.cjs} +1 -1
  65. package/lib/Indent.cjs +1 -1
  66. package/lib/Indent.js +2 -2
  67. package/lib/Italic.cjs +1 -1
  68. package/lib/Italic.js +2 -2
  69. package/lib/{Katex-BPbXjcZQ.js → Katex-C_Ah9G9w.js} +7 -6
  70. package/lib/Katex-oLGrtLTf.cjs +4 -0
  71. package/lib/Katex.cjs +1 -1
  72. package/lib/Katex.js +3 -3
  73. package/lib/LineHeight.cjs +1 -1
  74. package/lib/LineHeight.js +4 -4
  75. package/lib/Link.cjs +1 -1
  76. package/lib/Link.js +2 -2
  77. package/lib/{LinkEditBlock-Z7RRurvx.cjs → LinkEditBlock-BojxdGTm.cjs} +2 -2
  78. package/lib/{LinkEditBlock-BYWwH2_x.js → LinkEditBlock-DRdKXffy.js} +39 -35
  79. package/lib/MarkdownPaste.cjs +1 -1
  80. package/lib/MarkdownPaste.js +1 -1
  81. package/lib/Mention.cjs +1 -1
  82. package/lib/Mention.js +4 -4
  83. package/lib/Mermaid.cjs +2 -2
  84. package/lib/Mermaid.js +62 -61
  85. package/lib/MoreMark.cjs +1 -1
  86. package/lib/MoreMark.js +5 -5
  87. package/lib/OrderedList.cjs +1 -1
  88. package/lib/OrderedList.js +2 -2
  89. package/lib/SearchAndReplace.cjs +1 -1
  90. package/lib/SearchAndReplace.js +8 -8
  91. package/lib/SlashCommand.cjs +1 -1
  92. package/lib/SlashCommand.js +7 -7
  93. package/lib/{SlashCommandNodeView-DPPmYEjC.cjs → SlashCommandNodeView-Dai-O3aD.cjs} +1 -1
  94. package/lib/{SlashCommandNodeView-C0l3Fb_3.js → SlashCommandNodeView-qwW9cuYt.js} +6 -6
  95. package/lib/Strike.cjs +1 -1
  96. package/lib/Strike.js +2 -2
  97. package/lib/{Table-DwseaFSD.js → Table-BKM8SvVj.js} +20 -20
  98. package/lib/{Table-D5G3rfwb.cjs → Table-CWI7tKme.cjs} +1 -1
  99. package/lib/Table.cjs +1 -1
  100. package/lib/Table.js +1 -1
  101. package/lib/TaskList.cjs +1 -1
  102. package/lib/TaskList.js +2 -2
  103. package/lib/TextAlign.cjs +1 -1
  104. package/lib/TextAlign.js +3 -3
  105. package/lib/TextDirection.cjs +1 -1
  106. package/lib/TextDirection.js +3 -3
  107. package/lib/TextUnderline.cjs +1 -1
  108. package/lib/TextUnderline.js +2 -2
  109. package/lib/{Twitter-q4ZGZL0i.cjs → Twitter-BfsPzA8_.cjs} +1 -1
  110. package/lib/{Twitter-DP26Lkn8.js → Twitter-CofLQ-zj.js} +9 -9
  111. package/lib/Twitter.cjs +1 -1
  112. package/lib/Twitter.js +3 -3
  113. package/lib/Video.cjs +1 -1
  114. package/lib/Video.js +5 -5
  115. package/lib/bubble.cjs +6 -6
  116. package/lib/bubble.js +2258 -2552
  117. package/lib/{clsx-DRbkQ4T7.cjs → clsx-DJURdKPs.cjs} +2 -2
  118. package/lib/{clsx-_bq4MQQ7.js → clsx-b_2OwHLk.js} +19 -19
  119. package/lib/{dropdown-menu-CURWpB9o.cjs → dropdown-menu-CEMxzgnU.cjs} +1 -1
  120. package/lib/{dropdown-menu-BKSX4gvT.js → dropdown-menu-CKAKsyqu.js} +1 -1
  121. package/lib/extensions/Image/Image.d.ts +13 -1
  122. package/lib/index-BJQ1G8B1.js +311 -0
  123. package/lib/index-BO82_0q8.cjs +1 -0
  124. package/lib/{index-DQy9iBzV.js → index-Bn_WPziX.js} +1 -1
  125. package/lib/{index-BpLw6ebr.cjs → index-CwbGrQFa.cjs} +1 -1
  126. package/lib/{index-DtyAGMbq.js → index-DKruDABV.js} +1 -1
  127. package/lib/{index-SEMQrdk2.cjs → index-DN-IR-K0.cjs} +1 -1
  128. package/lib/{index-C52cuQ_Y.js → index-DRcwHivm.js} +1415 -1350
  129. package/lib/index-DUeBQoIA.cjs +1 -0
  130. package/lib/{index-Dbm_Mans.js → index-DeoYYWEA.js} +1 -1
  131. package/lib/{index-CHVV5iY-.cjs → index-Dgs2thVL.cjs} +1 -1
  132. package/lib/{index-BaR0Brts.js → index-DjB2kNdz.js} +171 -166
  133. package/lib/{index-CJMI7Fjf.js → index-DuWMq-Qs.js} +1 -1
  134. package/lib/{index-BGfIcDCQ.cjs → index-EoGU7W4e.cjs} +1 -1
  135. package/lib/{index-CDw4Eszh.cjs → index-MDz4NZcT.cjs} +9 -9
  136. package/lib/{index-Dx-Dh7KS.js → index-n4kM0Ll-.js} +110 -105
  137. package/lib/{index-BgNKVyMW.cjs → index-qZURFC5Q.cjs} +1 -1
  138. package/lib/index.cjs +1 -1
  139. package/lib/index.js +12 -12
  140. package/lib/locale-bundle.cjs +1 -1
  141. package/lib/locale-bundle.js +1 -1
  142. package/lib/{popover-BB-ZDnqk.js → popover-Beieacfy.js} +1 -1
  143. package/lib/{popover-CrywEkBR.cjs → popover-Bl1kxRJX.cjs} +1 -1
  144. package/lib/{renderNodeView-5h3-p80E.cjs → renderNodeView-BIgT6Ghg.cjs} +1 -1
  145. package/lib/{renderNodeView-DoKZ4GYy.js → renderNodeView-Bi58v3DZ.js} +2 -2
  146. package/lib/{separator-BGO9AZp4.cjs → separator-DMLtkcoo.cjs} +1 -1
  147. package/lib/{separator-DuuOJRQd.js → separator-DfvK668q.js} +14 -14
  148. package/lib/style.css +1 -1
  149. package/lib/textarea-DV9Fw3y1.cjs +1 -0
  150. package/lib/textarea-GXaWJbm9.js +20 -0
  151. package/lib/theme.cjs +1 -1
  152. package/lib/theme.js +1 -1
  153. package/lib/{updatePosition-CFTYKYNJ.js → updatePosition-DY1jI7qb.js} +2 -2
  154. package/lib/{updatePosition-B1oRJE1x.cjs → updatePosition-D_D-TbEu.cjs} +1 -1
  155. package/package.json +59 -59
  156. package/lib/Katex-CUofhjB5.cjs +0 -4
  157. package/lib/index-BG0kQamI.js +0 -285
  158. package/lib/index-NsYff_Ni.cjs +0 -1
  159. package/lib/index-aujjnfSJ.cjs +0 -1
package/lib/bubble.cjs CHANGED
@@ -1,6 +1,6 @@
1
- "use strict";var Io=Object.create;var Un=Object.defineProperty;var Mo=Object.getOwnPropertyDescriptor;var Oo=Object.getOwnPropertyNames;var Ro=Object.getPrototypeOf,jo=Object.prototype.hasOwnProperty;var No=(e,t,n)=>t in e?Un(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Bo=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Oo(t))!jo.call(e,s)&&s!==n&&Un(e,s,{get:()=>t[s],enumerable:!(i=Mo(t,s))||i.enumerable});return e};var Lo=(e,t,n)=>(n=e!=null?Io(Ro(e)):{},Bo(t||!e||!e.__esModule?Un(n,"default",{value:e,enumerable:!0}):n,e));var ze=(e,t,n)=>No(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),O=require("./index-BGfIcDCQ.cjs"),W=require("./index-BgNKVyMW.cjs"),G=require("@tiptap/pm/state"),Vs=require("./Table-D5G3rfwb.cjs"),Fs=require("./clsx-DRbkQ4T7.cjs"),w=require("react"),Ei=require("react-dom"),m=require("./index-aujjnfSJ.cjs"),$e=require("./Callout.cjs"),xt=require("./Katex-CUofhjB5.cjs"),P=require("./index-BpLw6ebr.cjs"),Ht=require("lucide-react"),At=require("./popover-CrywEkBR.cjs"),Et=require("./separator-BGO9AZp4.cjs"),zn=require("./CodeBlock.cjs"),Zi=require("./Column.cjs");require("./theme.cjs");const We=require("./Drawer-D7E9kTca.cjs"),Qi=require("easydrawer"),nn=require("./shortId-Bfj8TyNr.cjs"),xe=require("./Excalidraw.cjs"),Zt=require("./Iframe-OMVd0xa_.cjs"),Po=require("./ImageGif.cjs"),Uo=require("katex"),Ge=require("./LinkEditBlock-Z7RRurvx.cjs"),$n=require("@tiptap/pm/view"),zo=require("@tiptap/pm/model"),z=require("./dropdown-menu-CURWpB9o.cjs"),$o=require("./Clear.cjs"),we=require("./Indent-QgCoonRk.cjs"),Hs=require("./TextAlign.cjs"),ri=require("./Mermaid.cjs"),Vo=require("./Bold.cjs"),Fo=require("./Code.cjs");require("./index-SEMQrdk2.cjs");const Ho=require("./Color.cjs"),Ko=require("./Highlight.cjs"),qo=require("./Italic.cjs"),Wo=require("./SlashCommandNodeView-DPPmYEjC.cjs"),Go=require("./Strike.cjs"),Yo=require("./TextUnderline.cjs"),Vn=require("./Twitter-q4ZGZL0i.cjs");function Jo(e,t){const n=Math.min(e.top,t.top),i=Math.max(e.bottom,t.bottom),s=Math.min(e.left,t.left),o=Math.max(e.right,t.right)-s,l=i-n,c=s,a=n;return new DOMRect(c,a,o,l)}var Xo=class{constructor({editor:e,element:t,view:n,pluginKey:i="bubbleMenu",updateDelay:s=250,resizeDelay:r=60,shouldShow:o,appendTo:l,getReferencedVirtualElement:c,options:a}){this.preventHide=!1,this.isVisible=!1,this.scrollTarget=window,this.floatingUIOptions={strategy:"absolute",placement:"top",offset:8,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1,onShow:void 0,onHide:void 0,onUpdate:void 0,onDestroy:void 0},this.shouldShow=({view:h,state:f,from:p,to:g})=>{const{doc:x,selection:b}=f,{empty:y}=b,C=!x.textBetween(p,g).length&&O.isTextSelection(f.selection),S=this.element.contains(document.activeElement);return!(!(h.hasFocus()||S)||y||C||!this.editor.isEditable)},this.mousedownHandler=()=>{this.preventHide=!0},this.dragstartHandler=()=>{this.hide()},this.resizeHandler=()=>{this.resizeDebounceTimer&&clearTimeout(this.resizeDebounceTimer),this.resizeDebounceTimer=window.setTimeout(()=>{this.updatePosition()},this.resizeDelay)},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:h})=>{var f;if(this.editor.isDestroyed){this.destroy();return}if(this.preventHide){this.preventHide=!1;return}h!=null&&h.relatedTarget&&((f=this.element.parentNode)!=null&&f.contains(h.relatedTarget))||(h==null?void 0:h.relatedTarget)!==this.editor.view.dom&&this.hide()},this.handleDebouncedUpdate=(h,f)=>{const p=!(f!=null&&f.selection.eq(h.state.selection)),g=!(f!=null&&f.doc.eq(h.state.doc));!p&&!g||(this.updateDebounceTimer&&clearTimeout(this.updateDebounceTimer),this.updateDebounceTimer=window.setTimeout(()=>{this.updateHandler(h,p,g,f)},this.updateDelay))},this.updateHandler=(h,f,p,g)=>{const{composing:x}=h;if(x||!f&&!p)return;if(!this.getShouldShow(g)){this.hide();return}this.show(),this.updatePosition()},this.transactionHandler=({transaction:h})=>{const f=h.getMeta(this.pluginKey);f==="updatePosition"?this.updatePosition():f&&typeof f=="object"&&f.type==="updateOptions"?this.updateOptions(f.options):f==="hide"?this.hide():f==="show"&&(this.updatePosition(),this.show())};var u;this.editor=e,this.element=t,this.view=n,this.pluginKey=i,this.updateDelay=s,this.resizeDelay=r,this.appendTo=l,this.scrollTarget=(u=a==null?void 0:a.scrollTarget)!=null?u:window,this.getReferencedVirtualElement=c,this.floatingUIOptions={...this.floatingUIOptions,...a},this.element.tabIndex=0,o&&(this.shouldShow=o),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.view.dom.addEventListener("dragstart",this.dragstartHandler),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.editor.on("transaction",this.transactionHandler),window.addEventListener("resize",this.resizeHandler),this.scrollTarget.addEventListener("scroll",this.resizeHandler),this.update(n,n.state),this.getShouldShow()&&(this.show(),this.updatePosition())}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(W.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(W.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(W.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(W.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(W.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(W.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(W.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(W.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}get virtualElement(){var e,t,n;const{selection:i}=this.editor.state,s=(e=this.getReferencedVirtualElement)==null?void 0:e.call(this);if(s)return s;if(!((n=(t=this.view)==null?void 0:t.dom)!=null&&n.parentNode))return;const r=O.posToDOMRect(this.view,i.from,i.to);let o={getBoundingClientRect:()=>r,getClientRects:()=>[r]};if(i instanceof G.NodeSelection){let l=this.view.nodeDOM(i.from);const c=l.dataset.nodeViewWrapper?l:l.querySelector("[data-node-view-wrapper]");c&&(l=c),l&&(o={getBoundingClientRect:()=>l.getBoundingClientRect(),getClientRects:()=>[l.getBoundingClientRect()]})}if(i instanceof Vs.CellSelection){const{$anchorCell:l,$headCell:c}=i,a=l?l.pos:c.pos,u=c?c.pos:l.pos,h=this.view.nodeDOM(a),f=this.view.nodeDOM(u);if(!h||!f)return;const p=h===f?h.getBoundingClientRect():Jo(h.getBoundingClientRect(),f.getBoundingClientRect());o={getBoundingClientRect:()=>p,getClientRects:()=>[p]}}return o}updatePosition(){if(!this.isVisible)return;const e=this.virtualElement;e&&W.computePosition(e,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:t,y:n,strategy:i,middlewareData:s})=>{var r,o;if(!(!this.isVisible||this.editor.isDestroyed||!this.element.isConnected)){if((r=s.hide)!=null&&r.referenceHidden||(o=s.hide)!=null&&o.escaped){this.element.style.visibility="hidden";return}this.element.style.visibility="visible",this.element.style.width="max-content",this.element.style.position=i,this.element.style.left=`${t}px`,this.element.style.top=`${n}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()}})}update(e,t){const{state:n}=e,i=n.selection.from!==n.selection.to;if(this.updateDelay>0&&i){this.handleDebouncedUpdate(e,t);return}const s=!(t!=null&&t.selection.eq(e.state.selection)),r=!(t!=null&&t.doc.eq(e.state.doc));this.updateHandler(e,s,r,t)}getShouldShow(e){var t;const{state:n}=this.view,{selection:i}=n,{ranges:s}=i,r=Math.min(...s.map(c=>c.$from.pos)),o=Math.max(...s.map(c=>c.$to.pos));return((t=this.shouldShow)==null?void 0:t.call(this,{editor:this.editor,element:this.element,view:this.view,state:n,oldState:e,from:r,to:o}))||!1}show(){var e;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const t=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(e=t??this.view.dom.parentElement)==null||e.appendChild(this.element),this.floatingUIOptions.onShow&&this.floatingUIOptions.onShow(),this.isVisible=!0}hide(){this.isVisible&&(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.remove(),this.floatingUIOptions.onHide&&this.floatingUIOptions.onHide(),this.isVisible=!1)}updateOptions(e){var t;if(e.updateDelay!==void 0&&(this.updateDelay=e.updateDelay),e.resizeDelay!==void 0&&(this.resizeDelay=e.resizeDelay),e.appendTo!==void 0&&(this.appendTo=e.appendTo),e.getReferencedVirtualElement!==void 0&&(this.getReferencedVirtualElement=e.getReferencedVirtualElement),e.shouldShow!==void 0&&e.shouldShow&&(this.shouldShow=e.shouldShow),e.options!==void 0){const n=(t=e.options.scrollTarget)!=null?t:window;n!==this.scrollTarget&&(this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.scrollTarget=n,this.scrollTarget.addEventListener("scroll",this.resizeHandler)),this.floatingUIOptions={...this.floatingUIOptions,...e.options}}}destroy(){this.hide(),this.element.removeEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.view.dom.removeEventListener("dragstart",this.dragstartHandler),window.removeEventListener("resize",this.resizeHandler),this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.editor.off("transaction",this.transactionHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},Ks=e=>new G.Plugin({key:typeof e.pluginKey=="string"?new G.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Xo({view:t,...e})});O.Extension.create({name:"bubbleMenu",addOptions(){return{element:null,pluginKey:"bubbleMenu",updateDelay:void 0,appendTo:void 0,shouldShow:null}},addProseMirrorPlugins(){return this.options.element?[Ks({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,updateDelay:this.options.updateDelay,options:this.options.options,appendTo:this.options.appendTo,getReferencedVirtualElement:this.options.getReferencedVirtualElement,shouldShow:this.options.shouldShow})]:[]}});var Zo=class{constructor({editor:e,element:t,view:n,pluginKey:i="floatingMenu",updateDelay:s=250,resizeDelay:r=60,options:o,appendTo:l,shouldShow:c}){this.preventHide=!1,this.isVisible=!1,this.scrollTarget=window,this.shouldShow=({view:u,state:h})=>{const{selection:f}=h,{$anchor:p,empty:g}=f,x=p.depth===1,b=p.parent.isTextblock&&!p.parent.type.spec.code&&!p.parent.textContent&&p.parent.childCount===0&&!this.getTextContent(p.parent);return!(!u.hasFocus()||!g||!x||!b||!this.editor.isEditable)},this.floatingUIOptions={strategy:"absolute",placement:"right",offset:8,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1},this.updateHandler=(u,h,f,p)=>{const{composing:g}=u;if(g||!h&&!f)return;if(!this.getShouldShow(p)){this.hide();return}this.updatePosition(),this.show()},this.mousedownHandler=()=>{this.preventHide=!0},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:u})=>{var h;if(this.preventHide){this.preventHide=!1;return}u!=null&&u.relatedTarget&&((h=this.element.parentNode)!=null&&h.contains(u.relatedTarget))||(u==null?void 0:u.relatedTarget)!==this.editor.view.dom&&this.hide()},this.transactionHandler=({transaction:u})=>{const h=u.getMeta(this.pluginKey);h==="updatePosition"?this.updatePosition():h&&typeof h=="object"&&h.type==="updateOptions"?this.updateOptions(h.options):h==="hide"?this.hide():h==="show"&&(this.updatePosition(),this.show())},this.resizeHandler=()=>{this.resizeDebounceTimer&&clearTimeout(this.resizeDebounceTimer),this.resizeDebounceTimer=window.setTimeout(()=>{this.updatePosition()},this.resizeDelay)};var a;this.editor=e,this.element=t,this.view=n,this.pluginKey=i,this.updateDelay=s,this.resizeDelay=r,this.appendTo=l,this.scrollTarget=(a=o==null?void 0:o.scrollTarget)!=null?a:window,this.floatingUIOptions={...this.floatingUIOptions,...o},this.element.tabIndex=0,c&&(this.shouldShow=c),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.editor.on("transaction",this.transactionHandler),window.addEventListener("resize",this.resizeHandler),this.scrollTarget.addEventListener("scroll",this.resizeHandler),this.update(n,n.state),this.getShouldShow()&&(this.show(),this.updatePosition())}getTextContent(e){return O.getText(e,{textSerializers:O.getTextSerializersFromSchema(this.editor.schema)})}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(W.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(W.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(W.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(W.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(W.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(W.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(W.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(W.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}getShouldShow(e){var t;const{state:n}=this.view,{selection:i}=n,{ranges:s}=i,r=Math.min(...s.map(c=>c.$from.pos)),o=Math.max(...s.map(c=>c.$to.pos));return(t=this.shouldShow)==null?void 0:t.call(this,{editor:this.editor,view:this.view,state:n,oldState:e,from:r,to:o})}updateOptions(e){var t;if(e.updateDelay!==void 0&&(this.updateDelay=e.updateDelay),e.resizeDelay!==void 0&&(this.resizeDelay=e.resizeDelay),e.appendTo!==void 0&&(this.appendTo=e.appendTo),e.shouldShow!==void 0&&e.shouldShow&&(this.shouldShow=e.shouldShow),e.options!==void 0){const n=(t=e.options.scrollTarget)!=null?t:window;n!==this.scrollTarget&&(this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.scrollTarget=n,this.scrollTarget.addEventListener("scroll",this.resizeHandler)),this.floatingUIOptions={...this.floatingUIOptions,...e.options}}}updatePosition(){var e,t;if(!((t=(e=this.view)==null?void 0:e.dom)!=null&&t.parentNode))return;const{selection:n}=this.editor.state,i=O.posToDOMRect(this.view,n.from,n.to),s={getBoundingClientRect:()=>i,getClientRects:()=>[i]};W.computePosition(s,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:r,y:o,strategy:l,middlewareData:c})=>{var a,u;if((a=c.hide)!=null&&a.referenceHidden||(u=c.hide)!=null&&u.escaped){this.element.style.visibility="hidden";return}this.element.style.visibility="visible",this.element.style.width="max-content",this.element.style.position=l,this.element.style.left=`${r}px`,this.element.style.top=`${o}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()})}update(e,t){const n=!(t!=null&&t.selection.eq(e.state.selection)),i=!(t!=null&&t.doc.eq(e.state.doc));this.updateHandler(e,n,i,t)}show(){var e;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const t=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(e=t??this.view.dom.parentElement)==null||e.appendChild(this.element),this.floatingUIOptions.onShow&&this.floatingUIOptions.onShow(),this.isVisible=!0}hide(){this.isVisible&&(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.remove(),this.floatingUIOptions.onHide&&this.floatingUIOptions.onHide(),this.isVisible=!1)}destroy(){this.hide(),this.element.removeEventListener("mousedown",this.mousedownHandler,{capture:!0}),window.removeEventListener("resize",this.resizeHandler),this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.editor.off("transaction",this.transactionHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},qs=e=>new G.Plugin({key:typeof e.pluginKey=="string"?new G.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Zo({view:t,...e})});O.Extension.create({name:"floatingMenu",addOptions(){return{element:null,options:{},pluginKey:"floatingMenu",updateDelay:void 0,resizeDelay:void 0,appendTo:void 0,shouldShow:null}},addCommands(){return{updateFloatingMenuPosition:()=>({tr:e,dispatch:t})=>(t&&e.setMeta(this.options.pluginKey,"updatePosition"),!0)}},addProseMirrorPlugins(){return this.options.element?[qs({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,updateDelay:this.options.updateDelay,resizeDelay:this.options.resizeDelay,options:this.options.options,appendTo:this.options.appendTo,shouldShow:this.options.shouldShow})]:[]}});function Ws(e,t){return e??new G.PluginKey(t)}var Qo=typeof window<"u"?w.useLayoutEffect:w.useEffect,Gs=new Set(["left","opacity","position","top","visibility","width"]),tl=new Set(["animationIterationCount","aspectRatio","borderImageOutset","borderImageSlice","borderImageWidth","columnCount","columns","fillOpacity","flex","flexGrow","flexShrink","fontWeight","gridArea","gridColumn","gridColumnEnd","gridColumnStart","gridRow","gridRowEnd","gridRowStart","lineClamp","lineHeight","opacity","order","orphans","scale","stopOpacity","strokeDasharray","strokeDashoffset","strokeMiterlimit","strokeOpacity","strokeWidth","tabSize","widows","zIndex","zoom"]),el=new Set(["children","className","style"]),nl=new Set(["tabIndex"]),il=new Set(["accessKey","autoCapitalize","contentEditable","contextMenu","dir","draggable","enterKeyHint","hidden","id","lang","nonce","role","slot","spellCheck","tabIndex","title","translate"]),sl={Blur:"focusout",DoubleClick:"dblclick",Focus:"focusin",MouseEnter:"mouseenter",MouseLeave:"mouseleave"};function oi(e,t){return/^on[A-Z]/.test(e)&&typeof t=="function"}function rl(e){return e.startsWith("aria-")||e.startsWith("data-"),e}function ol(e){return e.startsWith("aria-")||e.startsWith("data-")||il.has(e)}function Ys(e){return e.startsWith("--")?e:e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}function ll(e){var t;const n=e.endsWith("Capture"),s=(n?e.slice(0,-7):e).slice(2);return{eventName:(t=sl[s])!=null?t:s.toLowerCase(),options:n?{capture:!0}:void 0}}function cl(e,t){let n=t.defaultPrevented,i=!1;const s=Object.create(t);return Object.defineProperties(s,{nativeEvent:{value:t},currentTarget:{value:e},target:{value:t.target},persist:{value:()=>{}},isDefaultPrevented:{value:()=>n},isPropagationStopped:{value:()=>i},preventDefault:{value:()=>{n=!0,t.preventDefault()}},stopPropagation:{value:()=>{i=!0,t.stopPropagation()}}}),s}function Fn(e){return nl.has(e)}function ts(e,t,n){if(t==="tabIndex"){e.tabIndex=Number(n);return}e[t]=n}function al(e,t){if(t==="tabIndex"){e.removeAttribute("tabindex");return}const n=e[t];if(typeof n=="boolean"){e[t]=!1;return}if(typeof n=="number"){e[t]=0;return}e[t]=""}function hl(e,t){return typeof t!="number"||t===0||e.startsWith("--")||tl.has(e)?String(t):`${t}px`}function ul(e,t){Gs.has(t)||e.style.removeProperty(Ys(t))}function dl(e,t,n){Gs.has(t)||e.style.setProperty(Ys(t),hl(t,n))}function fl(e,t,n){new Set([...Object.keys(t),...Object.keys(n)]).forEach(s=>{if(el.has(s)||!ol(s)||oi(s,t[s])||oi(s,n[s]))return;const r=t[s],o=n[s];if(r===o)return;const l=rl(s);if(o==null||o===!1){Fn(s)&&al(e,s),e.removeAttribute(l);return}if(o===!0){Fn(s)&&ts(e,s,!0),e.setAttribute(l,"");return}if(Fn(s)){ts(e,s,o);return}e.setAttribute(l,String(o))})}function pl(e,t,n){if(t!==n){if(n){e.className=n;return}e.removeAttribute("class")}}function gl(e,t,n){const i=t??{},s=n??{};new Set([...Object.keys(i),...Object.keys(s)]).forEach(o=>{const l=i[o],c=s[o];if(l!==c){if(c==null){ul(e,o);return}dl(e,o,c)}})}function ml(e,t,n){t.forEach(({eventName:s,listener:r,options:o})=>{e.removeEventListener(s,r,o)});const i=[];return Object.entries(n).forEach(([s,r])=>{if(!oi(s,r))return;const{eventName:o,options:l}=ll(s),c=a=>{r(cl(e,a))};e.addEventListener(o,c,l),i.push({eventName:o,listener:c,options:l})}),i}function Js(e,t){const n=w.useRef({}),i=w.useRef([]);Qo(()=>{const s=n.current;return pl(e,s.className,t.className),gl(e,s.style,t.style),fl(e,s,t),i.current=ml(e,i.current,t),n.current=t,()=>{i.current.forEach(({eventName:r,listener:o,options:l})=>{e.removeEventListener(r,o,l)}),i.current=[]}},[e,t])}var ot=w.forwardRef(({pluginKey:e,editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:r=null,getReferencedVirtualElement:o,options:l,children:c,...a},u)=>{const h=w.useRef(document.createElement("div")),f=w.useRef(Ws(e,"bubbleMenu")).current;Js(h.current,a),typeof u=="function"?u(h.current):u&&(u.current=h.current);const{editor:p}=Fs.useCurrentEditor(),g=t||p,x={updateDelay:n,resizeDelay:i,appendTo:s,pluginKey:f,shouldShow:r,getReferencedVirtualElement:o,options:l},b=w.useRef(x);b.current=x;const[y,C]=w.useState(!1),S=w.useRef(!0);return w.useEffect(()=>{if(g!=null&&g.isDestroyed)return;if(!g){console.warn("BubbleMenu component is not rendered inside of an editor component or does not have editor prop.");return}const _=h.current;_.style.visibility="hidden",_.style.position="absolute";const U=Ks({...b.current,editor:g,element:_});g.registerPlugin(U);const I=b.current.pluginKey;return S.current=!0,C(!0),()=>{C(!1),g.unregisterPlugin(I),window.requestAnimationFrame(()=>{_.parentNode&&_.parentNode.removeChild(_)})}},[g]),w.useEffect(()=>{if(!(!y||!g||g.isDestroyed)){if(S.current){S.current=!1;return}g.view.dispatch(g.state.tr.setMeta(f,{type:"updateOptions",options:b.current}))}},[y,g,n,i,r,l,s,o,f]),Ei.createPortal(c,h.current)});w.forwardRef(({pluginKey:e,editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:r=null,options:o,children:l,...c},a)=>{const u=w.useRef(document.createElement("div")),h=w.useRef(Ws(e,"floatingMenu")).current;Js(u.current,c),typeof a=="function"?a(u.current):a&&(a.current=u.current);const{editor:f}=Fs.useCurrentEditor(),p=t||f,g={updateDelay:n,resizeDelay:i,appendTo:s,pluginKey:h,shouldShow:r,options:o},x=w.useRef(g);x.current=g;const[b,y]=w.useState(!1),C=w.useRef(!0);return w.useEffect(()=>{if(p!=null&&p.isDestroyed)return;if(!p){console.warn("FloatingMenu component is not rendered inside of an editor component or does not have editor prop.");return}const S=u.current;S.style.visibility="hidden",S.style.position="absolute";const _=qs({...x.current,editor:p,element:S});p.registerPlugin(_);const U=x.current.pluginKey;return C.current=!0,y(!0),()=>{y(!1),p.unregisterPlugin(U),window.requestAnimationFrame(()=>{S.parentNode&&S.parentNode.removeChild(S)})}},[p]),w.useEffect(()=>{if(!(!b||!p||p.isDestroyed)){if(C.current){C.current=!1;return}p.view.dispatch(p.state.tr.setMeta(h,{type:"updateOptions",options:x.current}))}},[b,p,n,i,r,o,s,h]),Ei.createPortal(l,u.current)});function Yt(e,t){const{state:n}=t,i=n.selection.$anchor;let s=!1;if(i.depth)for(let r=i.depth;r>0;r--)i.node(r).type.name===e&&(t.dispatchTransaction&&t.dispatchTransaction(n.tr.delete(i.before(r),i.after(r)).scrollIntoView()),s=!0);else{const r=n.selection.node;r&&r.type.name===e&&(t.chain().deleteSelection().run(),s=!0)}if(!s){const r=i.pos;if(r){const o=n.tr.doc.nodeAt(r);o&&o.type.name===e&&(t.dispatchTransaction&&t.dispatchTransaction(n.tr.delete(r,r+o.nodeSize)),s=!0)}}return s}const xl=[{value:"note",label:"Note",icon:"Info"},{value:"tip",label:"Tip",icon:"Lightbulb"},{value:"important",label:"Important",icon:"AlertCircle"},{value:"warning",label:"Warning",icon:"TriangleAlert"},{value:"caution",label:"Caution",icon:"OctagonAlert"}];function wl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=P.useLocale(),{type:i,title:s,body:r}=xt.useAttributes(t,$e.Callout.name,{type:"note",title:"",body:""}),[o,l]=w.useState(!1),[c,a]=w.useState("note"),[u,h]=w.useState(""),[f,p]=w.useState("");w.useEffect(()=>{o&&(a(i||"note"),h(s||""),p(r||""))},[o,i,s,r]);const g=w.useCallback(()=>{t&&(t.chain().updateAttributes($e.Callout.name,{type:c,title:u,body:f}).focus().run(),l(!1))},[t,c,u,f]),x=w.useCallback(()=>{l(!1)},[]),b=w.useCallback(()=>{Yt($e.Callout.name,t)},[t]),y=w.useCallback(()=>t.isActive($e.Callout.name),[t]);return e?d.jsx(ot,{editor:t,options:{placement:"top",offset:8,flip:!0},pluginKey:"RichTextBubbleCallout",shouldShow:y,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsxs(m.Dialog,{onOpenChange:l,open:o,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{icon:"Pencil",tooltip:n("editor.callout.edit.title")})}),d.jsxs(m.DialogContent,{children:[d.jsx(m.DialogTitle,{children:n("editor.callout.edit.title")}),d.jsxs("div",{className:"richtext-space-y-4 richtext-py-4",children:[d.jsxs("div",{className:"richtext-space-y-2",children:[d.jsx(m.Label,{children:n("editor.callout.dialog.type")}),d.jsxs(m.Select,{onValueChange:a,value:c,children:[d.jsx(m.SelectTrigger,{children:d.jsx(m.SelectValue,{className:"richtext-text-accent",placeholder:n("editor.callout.dialog.type.placeholder")})}),d.jsx(m.SelectContent,{children:xl.map(C=>d.jsx(m.SelectItem,{value:C.value,children:n(`editor.callout.type.${C.value}`)},C.value))})]})]}),d.jsxs("div",{className:"richtext-space-y-2",children:[d.jsx(m.Label,{children:n("editor.callout.dialog.title.label")}),d.jsx(m.Input,{onChange:C=>h(C.target.value),placeholder:n("editor.callout.dialog.title.placeholder"),type:"text",value:u})]}),d.jsxs("div",{className:"richtext-space-y-2",children:[d.jsx(m.Label,{children:n("editor.callout.dialog.body.label")}),d.jsx(m.Input,{onChange:C=>p(C.target.value),placeholder:n("editor.callout.dialog.body.placeholder"),type:"text",value:f})]})]}),d.jsxs(m.DialogFooter,{children:[d.jsx(m.Button,{onClick:x,variant:"outline",children:n("editor.callout.dialog.button.cancel")}),d.jsx(m.Button,{onClick:g,children:n("editor.callout.dialog.button.apply")})]})]})]}),d.jsx(m.ActionButton,{action:b,icon:"Trash2",tooltip:n("editor.delete")})]})}):d.jsx(d.Fragment,{})}function bl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=P.useLocale(),i=w.useCallback(()=>t.isActive(Zi.MultipleColumnNode.name),[t]),s=w.useCallback(()=>Yt(Zi.MultipleColumnNode.name,t),[t]),r=w.useCallback(()=>t.chain().focus().addColBefore().run(),[t]),o=w.useCallback(()=>t.chain().focus().addColAfter().run(),[t]),l=w.useCallback(()=>t.chain().focus().deleteCol().run(),[t]);return e?d.jsx(ot,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleColumns",shouldShow:i,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{action:r,icon:"ColumnAddLeft",tooltip:n("editor.table.menu.insertColumnBefore")}),d.jsx(m.ActionButton,{action:o,icon:"ColumnAddRight",tooltip:n("editor.table.menu.insertColumnAfter")}),d.jsx(m.ActionButton,{action:l,icon:"DeleteColumn",tooltip:n("editor.table.menu.deleteColumn")}),d.jsx(m.ActionButton,{action:s,icon:"Trash2",tooltip:n("editor.table.menu.delete_column")})]})}):d.jsx(d.Fragment,{})}function yl(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,r)=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[r],action:()=>e.commands.updateImage({width:P.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:P.IMAGE_SIZE[s]})}}))}function Sl(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,r)=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[r],action:()=>e.commands.updateImageGif({width:P.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:P.IMAGE_SIZE[s]})}}))}function vl(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImage)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function Cl(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImageGif)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function kl(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImageMermaid)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function El(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImageDrawer)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function Tl(e){return[{type:"flex-start",icon:"AlignLeft",tooltip:"Align left"},{type:"center",icon:"AlignCenter",tooltip:"Align center"},{type:"flex-end",icon:"AlignRight",tooltip:"Align right"}].map(n=>({type:`video-align-${n.type}`,component:m.ActionButton,componentProps:{tooltip:n.tooltip,icon:n.icon,action:()=>e.commands.updateVideo({align:n.type}),isActive:()=>e.getAttributes("video").align===n.type}}))}function _l(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,r)=>({type:`video-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[r],action:()=>e.commands.updateVideo({width:P.VIDEO_SIZE[s]}),isActive:()=>e.isActive("video",{width:P.VIDEO_SIZE[s]})}}))}function Dl(e,t){return[{type:"flipX",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.tooltip.flipX"),icon:"FlipX",action:()=>{const n=e.getAttributes("image"),{flipX:i}=n;e.chain().focus(void 0,{scrollIntoView:!1}).updateImage({flipX:!i}).run()}}},{type:"flipY",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.tooltip.flipY"),icon:"FlipY",action:()=>{const n=e.getAttributes("image"),{flipY:i}=n;e.chain().focus(void 0,{scrollIntoView:!1}).updateImage({flipY:!i}).run()}}},...yl(e,t),...vl(e,t),{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;O.deleteSelection(n,i)}}}]}function Al(e,t){return[...Sl(e,t),...Cl(e,t),{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;O.deleteSelection(n,i)}}}]}function Il(e,t){return[...kl(e,t),{type:"edit",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;O.deleteSelection(n,i)}}}]}function Ml(e,t){return[...El(e,t),{type:"edit",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;O.deleteSelection(n,i)}}}]}function Ol(e,t){return[..._l(e,t),...Tl(e),{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;O.deleteSelection(n,i)}}}]}let be=!1;function Rl({editor:e,attrs:t,extension:n}){const[i,s]=w.useState(!1),r=w.useRef(null),o=w.useRef(null),{alt:l,align:c}=t,a=n==null?void 0:n.options.upload,u=()=>{(async()=>{const E=document.querySelector("#easydrawer");E&&(r.current=new Qi.Editor(E,{wheelEventsEnabled:!1,disableZoom:!0}),o.current=Qi.makeDropdownToolbar(r.current),o.current.addDefaultToolWidgets(),r.current.loadFromSVG(decodeURIComponent(l)))})()};w.useEffect(()=>{i&&setTimeout(()=>{u()},200)},[i]);const h=async()=>{if(r.current){const I=r.current.toSVG(),E=I.outerHTML,M=`drawer-${nn.shortId()}.svg`;let Q=nn.i(I.outerHTML);if(a){const nt=m.dataURLtoFile(Q,M);Q=await a(nt)}e==null||e.chain().focus().setDrawer({type:"drawer",src:Q,alt:encodeURIComponent(E),width:426,height:212},!!E).run(),e==null||e.commands.setAlignImageDrawer(c)}s(!1)},f=I=>{const E=r.current.toolController.getPrimaryTools()[2],M=o.current.getWidgetById("pen-1");E&&M&&(E.setColor(I),M.serializeState())},p=I=>{const E=r.current.toolController.getPrimaryTools()[2],M=o.current.getWidgetById("pen-1");E&&M&&(E.setThickness(I),M.serializeState())},g=I=>{const E=r.current.toolController.getPrimaryTools()[3],M=o.current.getWidgetById("pen-2");E&&M&&(E.setColor(I),M.serializeState())},x=I=>{const E=o.current.getWidgetById("shape");E&&E.setShapeType(I)},b=I=>{const E=r.current.toolController.getPrimaryTools()[5],M=o.current.getWidgetById("shape");E&&M&&(E.setColor(I),M.serializeState())},y=I=>{const E=r.current.toolController.getPrimaryTools()[5],M=o.current.getWidgetById("shape");E&&M&&(E.setThickness(I),M.serializeState())},C=I=>{const E=r.current.toolController.getPrimaryTools()[5],M=o.current.getWidgetById("shape");E&&M&&(E.setBorderColor(I),M.serializeState())},S=()=>{if(be){for(;r.current.history.redoStackSize>0;)r.current.history.redo();be=!1;return}r.current.history.undo()},_=()=>{be||r.current.history.redo()},U=()=>{if(!be){for(;r.current.history.undoStackSize>0;)S();be=!0}};return d.jsxs(m.Dialog,{onOpenChange:s,open:i,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{action:()=>s(!0),icon:"Pencil",tooltip:"Edit Drawer"})}),d.jsxs(m.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[d.jsx(m.DialogTitle,{children:"Edit Drawer"}),d.jsxs("div",{style:{height:"100%",borderWidth:1,background:"white",position:"relative"},children:[d.jsx("div",{className:"richtext-size-full",id:"easydrawer"}),d.jsx(We.ControlDrawer,{changeBorderColorShape:C,changeColorShape:b,changeShape:x,onClear:U,onRedo:_,onThicknessChange:y,onUndo:S,refEditor:r,setColorHighlight:g,setColorPen:f,setThicknessPen:p})]}),d.jsx(m.DialogFooter,{children:d.jsx(m.Button,{onClick:h,type:"button",children:"Save changes"})})]})]})}function jl({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?d.jsx(w.Fragment,{children:e.type==="divider"?d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):d.jsx(i,{...e.componentProps,disabled:t||((s=e==null?void 0:e.componentProps)==null?void 0:s.disabled),editor:n})}):d.jsx(d.Fragment,{})}function Nl(){const{lang:e,t}=P.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=xt.useAttributes(i,We.Drawer.name),r=m.useExtension(We.Drawer.name),o=({editor:c})=>{const{selection:a}=c.view.state,{$from:u,to:h}=a;let f=!1;return c.view.state.doc.nodesBetween(u.pos,h,p=>{if(p.type.name===We.Drawer.name)return f=!0,!1}),f},l=w.useMemo(()=>Ml(i,t),[i,e,t]);return n?d.jsx(ot,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleDrawer",shouldShow:o,children:l!=null&&l.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:l==null?void 0:l.map((c,a)=>c.type==="edit"&&(s!=null&&s.src)?d.jsx(Rl,{attrs:s,editor:i,extension:r},`bubbleMenu-drawer-${a}`):d.jsx(jl,{editor:i,item:c},`bubbleMenu-drawer-${a}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}const Xs=({width:e,maxWidth:t,height:n,onOk:i,children:s})=>{const{t:r}=P.useLocale(),[o,l]=w.useState({width:"",height:"",maxWidth:""});w.useEffect(()=>{l({width:e,height:n,maxWidth:t})},[n,t,e]);function c(a){a.preventDefault(),a.stopPropagation(),i(o)}return d.jsxs(At.Popover,{modal:!0,children:[d.jsx(At.PopoverTrigger,{asChild:!0,children:s}),d.jsx(At.PopoverContent,{children:d.jsxs("form",{className:"richtext-flex richtext-flex-col richtext-gap-2",onSubmit:c,children:[d.jsx(m.Label,{className:"mb-[6px]",children:"Width"}),d.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:d.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:d.jsx(m.Input,{onChange:a=>l({...o,width:a.target.value}),required:!0,type:"number",value:o.width})})}),d.jsx(m.Label,{className:"mb-[6px]",children:"Max Width"}),d.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:d.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:d.jsx(m.Input,{onChange:a=>l({...o,maxWidth:a.target.value}),required:!0,type:"number",value:o.maxWidth})})}),d.jsx(m.Label,{className:"mb-[6px]",children:"Height"}),d.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:d.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:d.jsx(m.Input,{onChange:a=>l({...o,height:a.target.value}),required:!0,type:"number",value:o.height})})}),d.jsx(m.Button,{className:"richtext-mt-2 richtext-self-end",type:"submit",children:r("editor.link.dialog.button.apply")})]})})]})},zt=new Map;function Bl(e){const t=e.options.element;zt.has("width")||zt.set("width",t.clientWidth),zt.has("width")&&zt.get("width")<=0&&zt.set("width",t.clientWidth);const n={attributes:!0,childList:!0,subtree:!0},i=function(){zt.set("width",t.clientWidth)},s=new MutationObserver(i);return s.observe(t,n),e.on("destroy",()=>{s.disconnect()}),{width:zt.get("width")}}function Ll(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=P.useLocale(),{width:i}=Bl(t),s=xt.useAttributes(t,xe.Excalidraw.name,{defaultShowPicker:!1,createUser:"",width:0,height:0}),{defaultShowPicker:r,createUser:o,width:l,height:c}=s,a=w.useCallback(p=>{t.chain().updateAttributes(xe.Excalidraw.name,p).setNodeSelection(t.state.selection.from).focus().run()},[t]),u=w.useCallback(()=>{const p=m.EVENTS.EXCALIDRAW(t.id);m.emit(p,s)},[t,s]),h=w.useCallback(()=>t.isActive(xe.Excalidraw.name),[t]),f=w.useCallback(()=>Yt(xe.Excalidraw.name,t),[t]);return w.useEffect(()=>{r&&(u(),t.chain().updateAttributes(xe.Excalidraw.name,{defaultShowPicker:!1}).focus().run())},[o,r,t,u]),e?d.jsx(ot,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleExcalidraw",shouldShow:h,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{action:u,icon:"Pencil",tooltip:n("editor.edit")}),d.jsx(Xs,{height:c,maxWidth:i,onOk:a,width:l,children:d.jsx(m.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),d.jsx(m.ActionButton,{action:f,icon:"Trash2",tooltip:n("editor.delete")})]})}):d.jsx(d.Fragment,{})}function Pl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=P.useLocale(),{width:i,height:s,src:r}=xt.useAttributes(t,Zt.Iframe.name,{width:0,height:0,src:"",defaultShowPicker:!1}),[o,l]=w.useState(!1),[c,a]=w.useState(""),u=w.useCallback(b=>{var y;(y=b==null?void 0:b.preventDefault)==null||y.call(b),l(!1)},[l]);w.useEffect(()=>{o&&a(r)},[o,r]);const h=w.useCallback(b=>{var C;(C=b==null?void 0:b.preventDefault)==null||C.call(b);const y=Zt.getServiceSrc(c);t.chain().updateAttributes(Zt.Iframe.name,{src:(y==null?void 0:y.src)||c}).setNodeSelection(t.state.selection.from).focus().run(),l(!1)},[t,c,l]),f=w.useCallback(()=>{window.open(r,"_blank")},[r]),p=w.useCallback(b=>{t.chain().updateAttributes(Zt.Iframe.name,b).setNodeSelection(t.state.selection.from).focus().run()},[t]),g=w.useCallback(()=>t.isActive(Zt.Iframe.name)&&!r,[t,r]),x=w.useCallback(()=>Yt(Zt.Iframe.name,t),[t]);return e?d.jsx(d.Fragment,{children:d.jsx(ot,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleIframe",shouldShow:g,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{action:f,icon:"Eye",tooltip:"Visit Link"}),d.jsxs(m.Dialog,{onOpenChange:l,open:o,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{icon:"Pencil",tooltip:"Open Edit Link"})}),d.jsxs(m.DialogContent,{children:[d.jsx(m.DialogHeader,{children:d.jsx(m.DialogTitle,{children:"Edit Link Iframe"})}),d.jsx(m.Input,{autoFocus:!0,onInput:b=>a(b.target.value),placeholder:"Enter link",type:"url",value:c}),d.jsxs(m.DialogFooter,{children:[d.jsx(m.Button,{onClick:u,type:"button",children:"Cancel"}),d.jsx(m.Button,{onClick:h,type:"button",children:"OK"})]})]})]}),d.jsx(Xs,{height:s,onOk:p,width:i,children:d.jsx(m.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),d.jsx(m.ActionButton,{action:x,icon:"Trash2",tooltip:n("editor.delete")})]})})}):d.jsx(d.Fragment,{})}function Ul({children:e,visible:t,toggleVisible:n}){const{t:i}=P.useLocale(),s=m.useEditorInstance(),r=xt.useAttributes(s,xt.Katex.name,{text:"",macros:""}),{text:o,macros:l}=r,[c,a]=w.useState(decodeURIComponent(o||"")),[u,h]=w.useState(decodeURIComponent(l||""));w.useEffect(()=>{t&&(a(decodeURIComponent(o||"")),h(decodeURIComponent(l||"")))},[t]);const f=w.useCallback(()=>{s.chain().focus().setKatex({text:encodeURIComponent(c),macros:encodeURIComponent(u)}).run(),a(""),h(""),n(!1)},[s,c,u,n]),p=w.useMemo(()=>{try{return Uo.renderToString(c,{macros:xt.safeJSONParse(u||"")})}catch{return c}},[c,u]),g=w.useMemo(()=>`${c}`.trim()?p:null,[c,p]);return d.jsxs(m.Dialog,{onOpenChange:n,open:t,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:e}),d.jsxs(m.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[d.jsx(m.DialogTitle,{children:i("editor.formula.dialog.text")}),d.jsx("div",{style:{height:"100%",border:"1px solid hsl(var(--border))"},children:d.jsxs("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[d.jsxs("div",{className:"richtext-flex-1",children:[d.jsx(m.Label,{className:"mb-[6px]",children:"Expression"}),d.jsx(m.Textarea,{autoFocus:!0,className:"richtext-mb-[10px]",onChange:x=>a(x.target.value),placeholder:"Text",required:!0,rows:10,value:c,style:{color:"hsl(var(--foreground))"}}),d.jsx(m.Label,{className:"mb-[6px]",children:"Macros"}),d.jsx(m.Textarea,{onChange:x=>h(x.target.value),placeholder:"Macros",rows:10,value:u,style:{color:"hsl(var(--foreground))"}})]}),d.jsx("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:g||""},style:{height:"100%",borderWidth:1,minHeight:500,background:"#fff"}})]})}),d.jsx(m.DialogFooter,{children:d.jsx(m.Button,{onClick:f,type:"button",children:"Save changes"})})]})]})}function zl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),[n,i]=w.useState(!1),s=w.useCallback(()=>t.isActive(xt.Katex.name),[t]),r=w.useCallback(()=>Yt(xt.Katex.name,t),[t]);return e?d.jsx(ot,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleKatex",shouldShow:s,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(Ul,{toggleVisible:i,visible:n,children:d.jsx(m.ActionButton,{action:()=>i(!n),tooltip:"Edit",children:d.jsx(Ht.Pencil,{size:16})})}),d.jsx(m.ActionButton,{action:r,tooltip:"Delete",children:d.jsx(Ht.Trash2,{size:16})})]})}):d.jsx(d.Fragment,{})}function $l(e){const{t}=P.useLocale();return d.jsxs("div",{className:"richtext-flex richtext-flex-nowrap",children:[d.jsx(m.ActionButton,{disabled:!(e!=null&&e.link),icon:"ExternalLink",tooltip:t("editor.link.open.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{window.open(e==null?void 0:e.link,"_blank")}}),d.jsx(m.ActionButton,{icon:"Pencil",tooltip:t("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onEdit()}}),d.jsx(m.ActionButton,{icon:"Unlink",tooltip:t("editor.link.unlink.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onClear()}})]})}function Vl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),[n,i]=w.useState(!1),s=xt.useAttributes(t,Ge.Link.name),r=s==null?void 0:s.href,o=w.useCallback(({editor:u})=>u.isActive(Ge.Link.name),[]),l=(u,h,f)=>{const p=t.state.selection,{from:g}=p,x=(h==null?void 0:h.length)??0,b=g+x;t.chain().extendMarkRange("link").insertContent({type:"text",text:h,marks:[{type:"link",attrs:{href:u,target:f?"_blank":""}}]}).setLink({href:u}).setTextSelection({from:g,to:b}).focus().run(),i(!1)},c=w.useCallback(()=>{t.chain().extendMarkRange("link").unsetLink().focus().run(),i(!1)},[t]),a=()=>{i(!1)};return e?d.jsx(ot,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleLink",shouldShow:o,children:d.jsx(d.Fragment,{children:n?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-4 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(Ge.LinkEditBlock,{editor:t,onClose:a,onSetLink:l})}):d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx($l,{editor:t,link:r,onClear:c,onEdit:()=>{i(!0)}})})})}):d.jsx(d.Fragment,{})}function Ti({item:e,disabled:t,editor:n}){const i=e.component;return i?d.jsx(w.Fragment,{children:e.type==="divider"?d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):d.jsx(i,{...e.componentProps,disabled:t||(e==null?void 0:e.componentdisabled),editor:n})}):d.jsx(d.Fragment,{})}function Fl(e){return e.type.name===m.Image.name}function Hl(e){return e.type.name===Po.ImageGif.name}function Kl(e){return e.type.name===m.Video.name}function ql(){const{lang:e,t}=P.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:o})=>{const{selection:l}=o.view.state,{$from:c,to:a}=l;let u=!1;return o.view.state.doc.nodesBetween(c.pos,a,h=>{if(Fl(h))return u=!0,!1}),u},r=w.useMemo(()=>Dl(i,t),[i,e,t]);return n?d.jsx(ot,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImage",shouldShow:s,children:r!=null&&r.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:r==null?void 0:r.map((o,l)=>d.jsx(Ti,{editor:i,item:o},`bubbleMenu-image-${l}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function Wl(){const{lang:e,t}=P.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:o})=>{const{selection:l}=o.view.state,{$from:c,to:a}=l;let u=!1;return o.view.state.doc.nodesBetween(c.pos,a,h=>{if(Hl(h))return u=!0,!1}),u},r=w.useMemo(()=>Al(i,t),[i,t,e]);return n?d.jsx(ot,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImageGif",shouldShow:s,children:r!=null&&r.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:r==null?void 0:r.map((o,l)=>d.jsx(Ti,{editor:i,item:o},`bubbleMenu-image-gif-${l}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function Gl(){const{t:e}=P.useLocale(),t=m.useEditableEditor(),n=m.useEditorInstance(),i=({editor:r})=>{const{selection:o}=r.view.state,{$from:l,to:c}=o;let a=!1;return r.view.state.doc.nodesBetween(l.pos,c,u=>{if(Kl(u))return a=!0,!1}),a},s=w.useMemo(()=>Ol(n,e),[n,e]);return t?d.jsx(ot,{editor:n,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleVideo",shouldShow:i,children:s!=null&&s.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:s==null?void 0:s.map((r,o)=>d.jsx(Ti,{editor:n,item:r},`bubbleMenu-video-${o}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}const es=`graph TB
2
- a-->b`,Yl=({editor:e,attrs:t,extension:n})=>{const{alt:i,align:s}=t,[r,o]=w.useState(decodeURIComponent(i??es)),[l,c]=w.useState(""),[a,u]=w.useState(!1),h=w.useRef(null),[f,p]=w.useState(null),g=n==null?void 0:n.options.upload,x=w.useCallback(S=>{S&&import("mermaid").then(_=>{p(_.default)})},[]),b=async S=>{try{const{svg:_}=await f.render("mermaid-svg",S);c(_)}catch{c("")}},y=()=>{f.initialize({darkMode:!1,startOnLoad:!1,fontSize:12,theme:"base"}),b(r)};w.useEffect(()=>{f&&a&&y()},[f,a]),w.useEffect(()=>{f&&a&&b(r)},[f,r]);const C=async()=>{if(r!==""){if(r){const S=h.current.querySelector("svg"),{width:_,height:U}=S.getBoundingClientRect(),I=`mermaid-${nn.shortId()}.svg`;let E=nn.i(S.outerHTML);if(g){const M=m.dataURLtoFile(E,I);E=await g(M)}e==null||e.chain().focus().setMermaid({type:"mermaid",src:E,alt:encodeURIComponent(r),width:_,height:U},!!r).run(),e==null||e.commands.setAlignImageMermaid(s)}u(!1)}};return d.jsxs(m.Dialog,{onOpenChange:u,open:a,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{action:()=>u(!0),icon:"Pencil",tooltip:"Edit Mermaid"})}),d.jsxs(m.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[d.jsx(m.DialogTitle,{children:"Edit Mermaid"}),d.jsx("div",{ref:x,style:{height:"100%",border:"1px solid hsl(var(--border))"},children:d.jsxs("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[d.jsx(m.Textarea,{autoFocus:!0,className:"richtext-flex-1",defaultValue:es,onChange:S=>o(S.target.value),placeholder:"Text",required:!0,rows:10,value:r,style:{color:"hsl(var(--foreground))"}}),d.jsx("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:l},ref:h,style:{height:"100%",border:"1px solid hsl(var(--border))",minHeight:500}})]})}),d.jsx(m.DialogFooter,{children:d.jsx(m.Button,{onClick:C,type:"button",children:"Save changes"})})]})]})};function Jl({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?d.jsx(w.Fragment,{children:e.type==="divider"?d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):d.jsx(i,{...e.componentProps,disabled:t||((s=e==null?void 0:e.componentProps)==null?void 0:s.disabled),editor:n})}):d.jsx(d.Fragment,{})}function Xl(e){return e.type.name===ri.Mermaid.name}function Zl(){const{lang:e,t}=P.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=xt.useAttributes(i,ri.Mermaid.name),r=m.useExtension(ri.Mermaid.name),o=({editor:c})=>{const{selection:a}=c.view.state,{$from:u,to:h}=a;let f=!1;return c.view.state.doc.nodesBetween(u.pos,h,p=>{if(Xl(p))return f=!0,!1}),f},l=w.useMemo(()=>Il(i,t),[i,e,t]);return n?d.jsx(ot,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleMermaid",shouldShow:o,children:l!=null&&l.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:l==null?void 0:l.map((c,a)=>c.type==="edit"&&(s!=null&&s.src)?d.jsx(Yl,{attrs:s,editor:i,extension:r},`bubbleMenu-mermaid-${a}`):d.jsx(Jl,{editor:i,item:c},`bubbleMenu-mermaid-${a}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function Ql({hiddenActions:e=[]}){var x,b,y,C,S,_,U,I,E,M,Q,nt,ht,k,D,v,K,V;const{t}=P.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:q})=>O.isActive(q.view.state,Vs.Table.name),r=q=>e.includes(q);function o(){i.chain().focus().addColumnBefore().run()}function l(){i.chain().focus().addColumnAfter().run()}function c(){i.chain().focus().deleteColumn().run()}function a(){i.chain().focus().addRowBefore().run()}function u(){i.chain().focus().addRowAfter().run()}function h(){i.chain().focus().deleteRow().run()}function f(){i.chain().focus().mergeCells().run()}function p(){i==null||i.chain().focus().splitCell().run()}function g(){i.chain().focus().deleteTable().run()}return n?d.jsx(ot,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTable",shouldShow:s,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[!r("addColumnBefore")&&d.jsx(m.ActionButton,{action:o,disabled:!((b=(x=i==null?void 0:i.can())==null?void 0:x.addColumnBefore)!=null&&b.call(x)),icon:"BetweenHorizonalEnd",tooltip:t("editor.table.menu.insertColumnBefore"),tooltipOptions:{sideOffset:15}}),!r("addColumnAfter")&&d.jsx(m.ActionButton,{action:l,disabled:!((C=(y=i==null?void 0:i.can())==null?void 0:y.addColumnAfter)!=null&&C.call(y)),icon:"BetweenHorizonalStart",tooltip:t("editor.table.menu.insertColumnAfter"),tooltipOptions:{sideOffset:15}}),!r("deleteColumn")&&d.jsx(m.ActionButton,{action:c,disabled:!((_=i==null?void 0:(S=i.can()).deleteColumn)!=null&&_.call(S)),icon:"DeleteColumn",tooltip:t("editor.table.menu.deleteColumn"),tooltipOptions:{sideOffset:15}}),d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!r("addRowAbove")&&d.jsx(m.ActionButton,{action:a,disabled:!((I=i==null?void 0:(U=i.can()).addRowBefore)!=null&&I.call(U)),icon:"BetweenVerticalEnd",tooltip:t("editor.table.menu.insertRowAbove"),tooltipOptions:{sideOffset:15}}),!r("addRowBelow")&&d.jsx(m.ActionButton,{action:u,disabled:!((M=(E=i==null?void 0:i.can())==null?void 0:E.addRowAfter)!=null&&M.call(E)),icon:"BetweenVerticalStart",tooltip:t("editor.table.menu.insertRowBelow"),tooltipOptions:{sideOffset:15}}),!r("deleteRow")&&d.jsx(m.ActionButton,{action:h,disabled:!((nt=(Q=i==null?void 0:i.can())==null?void 0:Q.deleteRow)!=null&&nt.call(Q)),icon:"DeleteRow",tooltip:t("editor.table.menu.deleteRow"),tooltipOptions:{sideOffset:15}}),d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!r("mergeCells")&&d.jsx(m.ActionButton,{action:f,disabled:!((k=(ht=i==null?void 0:i.can())==null?void 0:ht.mergeCells)!=null&&k.call(ht)),icon:"TableCellsMerge",tooltip:t("editor.table.menu.mergeCells"),tooltipOptions:{sideOffset:15}}),!r("splitCells")&&d.jsx(m.ActionButton,{action:p,disabled:!((v=(D=i==null?void 0:i.can())==null?void 0:D.splitCell)!=null&&v.call(D)),icon:"TableCellsSplit",tooltip:t("editor.table.menu.splitCells"),tooltipOptions:{sideOffset:15}}),d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!r("deleteTable")&&d.jsx(m.ActionButton,{action:g,disabled:!((V=(K=i==null?void 0:i.can())==null?void 0:K.deleteTable)!=null&&V.call(K)),icon:"Trash2",tooltip:t("editor.table.menu.deleteTable"),tooltipOptions:{sideOffset:15}})]})}):d.jsx(d.Fragment,{})}function tc(){const{t:e}=P.useLocale(),[t,n]=w.useState(!1),i=m.useEditorInstance(),s=w.useMemo(()=>{var o,l;return(l=(o=Wo.renderCommandListDefault({t:e}))==null?void 0:o[0])==null?void 0:l.commands},[e]),r=w.useMemo(()=>{var l;return(l=s==null?void 0:s.find(c=>{var a;return(a=c==null?void 0:c.isActive)==null?void 0:a.call(c,i)}))==null?void 0:l.label},[i.state.selection.ranges,t,i,s,e]);return d.jsxs(At.Popover,{modal:!0,onOpenChange:n,open:t,children:[d.jsx(At.PopoverTrigger,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:d.jsxs(m.ActionButton,{dataState:!!r,children:[r?d.jsx(d.Fragment,{children:r}):d.jsx(d.Fragment,{children:e("editor.paragraph.tooltip")}),d.jsx(m.IconComponent,{className:"richtext-ml-1 richtext-size-3 richtext-text-zinc-500",name:"MenuDown"})]})}),d.jsx(At.PopoverContent,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:s==null?void 0:s.map(o=>{var c;const l=(c=o==null?void 0:o.isActive)==null?void 0:c.call(o,i);return d.jsxs("div",{className:"richtext-flex richtext-w-full richtext-items-center richtext-gap-3 richtext-rounded-sm !richtext-border-none !richtext-bg-transparent richtext-px-2 richtext-py-1.5 richtext-text-left richtext-text-sm richtext-text-foreground !richtext-outline-none richtext-transition-colors hover:!richtext-bg-accent",onClick:a=>{a.preventDefault(),o.action({editor:i,range:i.state.selection.ranges}),n(!1)},children:[d.jsxs("div",{className:"!richtext-min-w-[20px]",children:[l&&d.jsx(Ht.Check,{size:16}),!r&&o.label===e("editor.paragraph.tooltip")&&!l&&d.jsx(Ht.Check,{size:16})]}),d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:[o.iconName&&d.jsx(m.IconComponent,{className:"!richtext-mr-1 !richtext-text-lg",name:o.iconName}),o.label]})]},o.name)})})]})}function ec(){return d.jsxs(d.Fragment,{children:[d.jsx(tc,{}),d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(Vo.RichTextBold,{}),d.jsx(qo.RichTextItalic,{}),d.jsx(Yo.RichTextUnderline,{}),d.jsx(Go.RichTextStrike,{}),d.jsx(Fo.RichTextCode,{}),d.jsx(Ge.RichTextLink,{}),d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(Ho.RichTextColor,{}),d.jsx(Ko.RichTextHighlight,{}),d.jsx(Hs.RichTextAlign,{})]})}function nc({buttonBubble:e}){const t=m.useEditorInstance(),n=m.useEditableEditor(),i=({editor:s})=>{const{selection:r}=s.view.state,{$from:o,to:l}=r;return s.isActive("codeBlock")||o.pos===l?!1:r instanceof G.TextSelection};return n?d.jsx(ot,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleText",shouldShow:i,children:e?d.jsx(d.Fragment,{children:e}):d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(ec,{})})}):d.jsx(d.Fragment,{})}function ic(){const{t:e}=P.useLocale(),t=m.useEditableEditor(),n=m.useEditorInstance(),[i,s]=w.useState(!1),r=w.useCallback(({editor:c})=>c.isActive(Vn.Twitter.name),[]),o=c=>{n.commands.updateTweet({src:c}),s(!1)},l=w.useCallback(()=>Yt(Vn.Twitter.name,n),[n]);return t?d.jsx(ot,{editor:n,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTwitter",shouldShow:r,children:d.jsx(d.Fragment,{children:i?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-4 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(Vn.FormEditLinkTwitter,{editor:n,onSetLink:o})}):d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{icon:"Pencil",tooltip:e("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{s(!0)}}),d.jsx(m.ActionButton,{action:l,icon:"Trash",tooltip:e("editor.delete"),tooltipOptions:{sideOffset:15}})]})})}):d.jsx(d.Fragment,{})}const wt=()=>new Map,li=e=>{const t=wt();return e.forEach((n,i)=>{t.set(i,n)}),t},Ot=(e,t,n)=>{let i=e.get(t);return i===void 0&&e.set(t,i=n()),i},sc=(e,t)=>{const n=[];for(const[i,s]of e)n.push(t(s,i));return n},rc=(e,t)=>{for(const[n,i]of e)if(t(i,n))return!0;return!1},Kt=()=>new Set,Hn=e=>e[e.length-1],oc=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},qt=Array.from,_i=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},Di=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},lc=(e,t)=>{const n=new Array(e);for(let i=0;i<e;i++)n[i]=t(i,n);return n},re=Array.isArray;class Zs{constructor(){this._observers=wt()}on(t,n){return Ot(this._observers,t,Kt).add(n),n}once(t,n){const i=(...s)=>{this.off(t,i),n(...s)};this.on(t,i)}off(t,n){const i=this._observers.get(t);i!==void 0&&(i.delete(n),i.size===0&&this._observers.delete(t))}emit(t,n){return qt((this._observers.get(t)||wt()).values()).forEach(i=>i(...n))}destroy(){this._observers=wt()}}const bt=Math.floor,Ye=Math.abs,oe=(e,t)=>e<t?e:t,Bt=(e,t)=>e>t?e:t,Qs=e=>e!==0?e<0:1/e<0,ns=1,is=2,Kn=4,qn=8,Ce=32,It=64,st=128,cc=1<<29,vn=31,ci=63,Ft=127,ac=2147483647,sn=Number.MAX_SAFE_INTEGER,ss=Number.MIN_SAFE_INTEGER,hc=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&bt(e)===e),tr=String.fromCharCode,uc=e=>e.toLowerCase(),dc=/^\s*/g,fc=e=>e.replace(dc,""),pc=/([A-Z])/g,rs=(e,t)=>fc(e.replace(pc,n=>`${t}${uc(n)}`)),gc=e=>{const t=unescape(encodeURIComponent(e)),n=t.length,i=new Uint8Array(n);for(let s=0;s<n;s++)i[s]=t.codePointAt(s);return i},ke=typeof TextEncoder<"u"?new TextEncoder:null,mc=e=>ke.encode(e),xc=ke?mc:gc;let ve=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});ve&&ve.decode(new Uint8Array).length===1&&(ve=null);const wc=(e,t)=>lc(t,()=>e).join("");class Ne{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Be=()=>new Ne,bc=e=>{const t=Be();return e(t),mt(t)},yc=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},mt=e=>{const t=new Uint8Array(yc(e));let n=0;for(let i=0;i<e.bufs.length;i++){const s=e.bufs[i];t.set(s,n),n+=s.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},Sc=(e,t)=>{const n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(Bt(n,t)*2),e.cpos=0)},Y=(e,t)=>{const n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},ai=Y,A=(e,t)=>{for(;t>Ft;)Y(e,st|Ft&t),t=bt(t/128);Y(e,Ft&t)},Ai=(e,t)=>{const n=Qs(t);for(n&&(t=-t),Y(e,(t>ci?st:0)|(n?It:0)|ci&t),t=bt(t/64);t>0;)Y(e,(t>Ft?st:0)|Ft&t),t=bt(t/128)},hi=new Uint8Array(3e4),vc=hi.length/3,Cc=(e,t)=>{if(t.length<vc){const n=ke.encodeInto(t,hi).written||0;A(e,n);for(let i=0;i<n;i++)Y(e,hi[i])}else ct(e,xc(t))},kc=(e,t)=>{const n=unescape(encodeURIComponent(t)),i=n.length;A(e,i);for(let s=0;s<i;s++)Y(e,n.codePointAt(s))},te=ke&&ke.encodeInto?Cc:kc,Cn=(e,t)=>{const n=e.cbuf.length,i=e.cpos,s=oe(n-i,t.length),r=t.length-s;e.cbuf.set(t.subarray(0,s),i),e.cpos+=s,r>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(Bt(n*2,r)),e.cbuf.set(t.subarray(s)),e.cpos=r)},ct=(e,t)=>{A(e,t.byteLength),Cn(e,t)},Ii=(e,t)=>{Sc(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Ec=(e,t)=>Ii(e,4).setFloat32(0,t,!1),Tc=(e,t)=>Ii(e,8).setFloat64(0,t,!1),_c=(e,t)=>Ii(e,8).setBigInt64(0,t,!1),os=new DataView(new ArrayBuffer(4)),Dc=e=>(os.setFloat32(0,e),os.getFloat32(0)===e),le=(e,t)=>{switch(typeof t){case"string":Y(e,119),te(e,t);break;case"number":hc(t)&&Ye(t)<=ac?(Y(e,125),Ai(e,t)):Dc(t)?(Y(e,124),Ec(e,t)):(Y(e,123),Tc(e,t));break;case"bigint":Y(e,122),_c(e,t);break;case"object":if(t===null)Y(e,126);else if(re(t)){Y(e,117),A(e,t.length);for(let n=0;n<t.length;n++)le(e,t[n])}else if(t instanceof Uint8Array)Y(e,116),ct(e,t);else{Y(e,118);const n=Object.keys(t);A(e,n.length);for(let i=0;i<n.length;i++){const s=n[i];te(e,s),le(e,t[s])}}break;case"boolean":Y(e,t?120:121);break;default:Y(e,127)}};class ls extends Ne{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&A(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const cs=e=>{e.count>0&&(Ai(e.encoder,e.count===1?e.s:-e.s),e.count>1&&A(e.encoder,e.count-2))};class Je{constructor(){this.encoder=new Ne,this.s=0,this.count=0}write(t){this.s===t?this.count++:(cs(this),this.count=1,this.s=t)}toUint8Array(){return cs(this),mt(this.encoder)}}const as=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);Ai(e.encoder,t),e.count>1&&A(e.encoder,e.count-2)}};class Wn{constructor(){this.encoder=new Ne,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(as(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return as(this),mt(this.encoder)}}class Ac{constructor(){this.sarr=[],this.s="",this.lensE=new Je}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new Ne;return this.sarr.push(this.s),this.s="",te(t,this.sarr.join("")),Cn(t,this.lensE.toUint8Array()),mt(t)}}const _t=e=>new Error(e),pt=()=>{throw _t("Method unimplemented")},rt=()=>{throw _t("Unexpected case")},er=_t("Unexpected end of array"),nr=_t("Integer out of Range");class kn{constructor(t){this.arr=t,this.pos=0}}const Mi=e=>new kn(e),Ic=e=>e.pos!==e.arr.length,Mc=(e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},ut=e=>Mc(e,N(e)),Ee=e=>e.arr[e.pos++],N=e=>{let t=0,n=1;const i=e.arr.length;for(;e.pos<i;){const s=e.arr[e.pos++];if(t=t+(s&Ft)*n,n*=128,s<st)return t;if(t>sn)throw nr}throw er},Oi=e=>{let t=e.arr[e.pos++],n=t&ci,i=64;const s=(t&It)>0?-1:1;if((t&st)===0)return s*n;const r=e.arr.length;for(;e.pos<r;){if(t=e.arr[e.pos++],n=n+(t&Ft)*i,i*=128,t<st)return s*n;if(n>sn)throw nr}throw er},Oc=e=>{let t=N(e);if(t===0)return"";{let n=String.fromCodePoint(Ee(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(Ee(e));else for(;t>0;){const i=t<1e4?t:1e4,s=e.arr.subarray(e.pos,e.pos+i);e.pos+=i,n+=String.fromCodePoint.apply(null,s),t-=i}return decodeURIComponent(escape(n))}},Rc=e=>ve.decode(ut(e)),ui=ve?Rc:Oc,Ri=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},jc=e=>Ri(e,4).getFloat32(0,!1),Nc=e=>Ri(e,8).getFloat64(0,!1),Bc=e=>Ri(e,8).getBigInt64(0,!1),Lc=[e=>{},e=>null,Oi,jc,Nc,Bc,e=>!1,e=>!0,ui,e=>{const t=N(e),n={};for(let i=0;i<t;i++){const s=ui(e);n[s]=rn(e)}return n},e=>{const t=N(e),n=[];for(let i=0;i<t;i++)n.push(rn(e));return n},ut],rn=e=>Lc[127-Ee(e)](e);class hs extends kn{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Ic(this)?this.count=N(this)+1:this.count=-1),this.count--,this.s}}class Xe extends kn{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Oi(this);const t=Qs(this.s);this.count=1,t&&(this.s=-this.s,this.count=N(this)+2)}return this.count--,this.s}}class Gn extends kn{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=Oi(this),n=t&1;this.diff=bt(t/2),this.count=1,n&&(this.count=N(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Pc{constructor(t){this.decoder=new Xe(t),this.str=ui(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}}const Uc=crypto.getRandomValues.bind(crypto),zc=Math.random,ir=()=>Uc(new Uint32Array(1))[0],$c=e=>e[bt(zc()*e.length)],Vc="10000000-1000-4000-8000"+-1e11,Fc=()=>Vc.replace(/[018]/g,e=>(e^ir()&15>>e/4).toString(16)),Hc=Date.now,us=e=>new Promise(e);Promise.all.bind(Promise);const ds=e=>e===void 0?null:e;class Kc{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}}let sr=new Kc,qc=!0;try{typeof localStorage<"u"&&localStorage&&(sr=localStorage,qc=!1)}catch{}const Wc=sr,Te=Symbol("Equality"),rr=(e,t)=>{var n;return e===t||!!((n=e==null?void 0:e[Te])!=null&&n.call(e,t))||!1},Gc=e=>typeof e=="object",Yc=Object.assign,or=Object.keys,Jc=(e,t)=>{for(const n in e)t(e[n],n)},on=e=>or(e).length,Xc=e=>{for(const t in e)return!1;return!0},ue=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},ji=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Zc=(e,t)=>e===t||on(e)===on(t)&&ue(e,(n,i)=>(n!==void 0||ji(t,i))&&rr(t[i],n)),Qc=Object.freeze,lr=e=>{for(const t in e){const n=e[t];(typeof n=="object"||typeof n=="function")&&lr(e[t])}return Qc(e)},Ni=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Ni(e,t,n+1)}},Ze=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[Te]!=null)return e[Te](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:{if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break}case Set:{if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;break}case Map:{if(e.size!==t.size)return!1;for(const n of e.keys())if(!t.has(n)||!Ze(e.get(n),t.get(n)))return!1;break}case void 0:case Object:if(on(e)!==on(t))return!1;for(const n in e)if(!ji(e,n)||!Ze(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Ze(e[n],t[n]))return!1;break;default:return!1}return!0},ta=(e,t)=>t.includes(e),ce=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",cr=typeof window<"u"&&typeof document<"u"&&!ce;let Ct;const ea=()=>{if(Ct===void 0)if(ce){Ct=wt();const e=process.argv;let t=null;for(let n=0;n<e.length;n++){const i=e[n];i[0]==="-"?(t!==null&&Ct.set(t,""),t=i):t!==null&&(Ct.set(t,i),t=null)}t!==null&&Ct.set(t,"")}else typeof location=="object"?(Ct=wt(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){const[t,n]=e.split("=");Ct.set(`--${rs(t,"-")}`,n),Ct.set(`-${rs(t,"-")}`,n)}})):Ct=wt();return Ct},di=e=>ea().has(e),ln=e=>ds(ce?process.env[e.toUpperCase().replaceAll("-","_")]:Wc.getItem(e)),ar=e=>di("--"+e)||ln(e)!==null,na=ar("production"),ia=ce&&ta(process.env.FORCE_COLOR,["true","1","2"]),sa=ia||!di("--no-colors")&&!ar("no-color")&&(!ce||process.stdout.isTTY)&&(!ce||di("--color")||ln("COLORTERM")!==null||(ln("TERM")||"").includes("color")),ra=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=tr(e[n]);return btoa(t)},oa=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),la=cr?ra:oa,ca=e=>bc(t=>le(t,e));class aa{constructor(t,n){this.left=t,this.right=n}}const Dt=(e,t)=>new aa(e,t),fs=e=>e.next()>=.5,Yn=(e,t,n)=>bt(e.next()*(n+1-t)+t),hr=(e,t,n)=>bt(e.next()*(n+1-t)+t),Bi=(e,t,n)=>hr(e,t,n),ha=e=>tr(Bi(e,97,122)),ua=(e,t=0,n=20)=>{const i=Bi(e,t,n);let s="";for(let r=0;r<i;r++)s+=ha(e);return s},Jn=(e,t)=>t[Bi(e,0,t.length-1)],da=Symbol("0schema");class fa{constructor(){this._rerrs=[]}extend(t,n,i,s=null){this._rerrs.push({path:t,expected:n,has:i,message:s})}toString(){const t=[];for(let n=this._rerrs.length-1;n>0;n--){const i=this._rerrs[n];t.push(wc(" ",(this._rerrs.length-n)*2)+`${i.path!=null?`[${i.path}] `:""}${i.has} doesn't match ${i.expected}. ${i.message}`)}return t.join(`
3
- `)}}const fi=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[Te]?rr(e,t):re(e)?_i(e,n=>Di(t,i=>fi(n,i))):Gc(e)?ue(e,(n,i)=>fi(n,t[i])):!1;class et{extends(t){let[n,i]=[this.shape,t.shape];return this.constructor._dilutes&&([i,n]=[n,i]),fi(n,i)}equals(t){return this.constructor===t.constructor&&Ze(this.shape,t.shape)}[da](){return!0}[Te](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){pt()}get nullable(){return de(this,An)}get optional(){return new fr(this)}cast(t){return ps(t,this),t}expect(t){return ps(t,this),t}}ze(et,"_dilutes",!1);class Li extends et{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n=void 0){const i=(t==null?void 0:t.constructor)===this.shape&&(this._c==null||this._c(t));return!i&&(n==null||n.extend(null,this.shape.name,t==null?void 0:t.constructor.name,(t==null?void 0:t.constructor)!==this.shape?"Constructor match failed":"Check failed")),i}}const H=(e,t=null)=>new Li(e,t);H(Li);class Pi extends et{constructor(t){super(),this.shape=t}check(t,n){const i=this.shape(t);return!i&&(n==null||n.extend(null,"custom prop",t==null?void 0:t.constructor.name,"failed to check custom prop")),i}}const X=e=>new Pi(e);H(Pi);class En extends et{constructor(t){super(),this.shape=t}check(t,n){const i=this.shape.some(s=>s===t);return!i&&(n==null||n.extend(null,this.shape.join(" | "),t.toString())),i}}const Tn=(...e)=>new En(e),ur=H(En),pa=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,t=>"\\"+t)),dr=e=>{if(ae.check(e))return[pa(e)];if(ur.check(e))return e.shape.map(t=>t+"");if(vr.check(e))return["[+-]?\\d+.?\\d*"];if(Cr.check(e))return[".*"];if(an.check(e))return e.shape.map(dr).flat(1);rt()};class ga extends et{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(dr).map(n=>`(${n.join("|")})`).join("")+"$")}check(t,n){const i=this._r.exec(t)!=null;return!i&&(n==null||n.extend(null,this._r.toString(),t.toString(),"String doesn't match string template.")),i}}H(ga);const ma=Symbol("optional");class fr extends et{constructor(t){super(),this.shape=t}check(t,n){const i=t===void 0||this.shape.check(t);return!i&&(n==null||n.extend(null,"undefined (optional)","()")),i}get[ma](){return!0}}const xa=H(fr);class wa extends et{check(t,n){return n==null||n.extend(null,"never",typeof t),!1}}H(wa);const Sn=class Sn extends et{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}get partial(){return new Sn(this.shape,!0)}check(t,n){return t==null?(n==null||n.extend(null,"object","null"),!1):ue(this.shape,(i,s)=>{const r=this._isPartial&&!ji(t,s)||i.check(t[s],n);return!r&&(n==null||n.extend(s.toString(),i.toString(),typeof t[s],"Object property does not match")),r})}};ze(Sn,"_dilutes",!0);let cn=Sn;const ba=e=>new cn(e),ya=H(cn),Sa=X(e=>e!=null&&(e.constructor===Object||e.constructor==null));class pr extends et{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return t!=null&&ue(t,(i,s)=>{const r=this.shape.keys.check(s,n);return!r&&(n==null||n.extend(s+"","Record",typeof t,r?"Key doesn't match schema":"Value doesn't match value")),r&&this.shape.values.check(i,n)})}}const gr=(e,t)=>new pr(e,t),va=H(pr);class mr extends et{constructor(t){super(),this.shape=t}check(t,n){return t!=null&&ue(this.shape,(i,s)=>{const r=i.check(t[s],n);return!r&&(n==null||n.extend(s.toString(),"Tuple",typeof i)),r})}}const Ca=(...e)=>new mr(e);H(mr);class xr extends et{constructor(t){super(),this.shape=t.length===1?t[0]:new _n(t)}check(t,n){const i=re(t)&&_i(t,s=>this.shape.check(s));return!i&&(n==null||n.extend(null,"Array","")),i}}const wr=(...e)=>new xr(e),ka=H(xr),Ea=X(e=>re(e));class br extends et{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n){const i=t instanceof this.shape&&(this._c==null||this._c(t));return!i&&(n==null||n.extend(null,this.shape.name,t==null?void 0:t.constructor.name)),i}}const Ta=(e,t=null)=>new br(e,t);H(br);const _a=Ta(et);class Da extends et{constructor(t){super(),this.len=t.length-1,this.args=Ca(...t.slice(-1)),this.res=t[this.len]}check(t,n){const i=t.constructor===Function&&t.length<=this.len;return!i&&(n==null||n.extend(null,"function",typeof t)),i}}const Aa=H(Da),Ia=X(e=>typeof e=="function");class Ma extends et{constructor(t){super(),this.shape=t}check(t,n){const i=_i(this.shape,s=>s.check(t,n));return!i&&(n==null||n.extend(null,"Intersectinon",typeof t)),i}}H(Ma,e=>e.shape.length>0);class _n extends et{constructor(t){super(),this.shape=t}check(t,n){const i=Di(this.shape,s=>s.check(t,n));return n==null||n.extend(null,"Union",typeof t),i}}ze(_n,"_dilutes",!0);const de=(...e)=>e.findIndex(t=>an.check(t))>=0?de(...e.map(t=>_e(t)).map(t=>an.check(t)?t.shape:[t]).flat(1)):e.length===1?e[0]:new _n(e),an=H(_n),yr=()=>!0,hn=X(yr),Oa=H(Pi,e=>e.shape===yr),Ui=X(e=>typeof e=="bigint"),Ra=X(e=>e===Ui),Sr=X(e=>typeof e=="symbol");X(e=>e===Sr);const ee=X(e=>typeof e=="number"),vr=X(e=>e===ee),ae=X(e=>typeof e=="string"),Cr=X(e=>e===ae),Dn=X(e=>typeof e=="boolean"),ja=X(e=>e===Dn),kr=Tn(void 0);H(En,e=>e.shape.length===1&&e.shape[0]===void 0);Tn(void 0);const An=Tn(null),Na=H(En,e=>e.shape.length===1&&e.shape[0]===null);H(Uint8Array);H(Li,e=>e.shape===Uint8Array);const Ba=de(ee,ae,An,kr,Ui,Dn,Sr);(()=>{const e=wr(hn),t=gr(ae,hn),n=de(ee,ae,An,Dn,e,t);return e.shape=n,t.shape.values=n,n})();const _e=e=>{if(_a.check(e))return e;if(Sa.check(e)){const t={};for(const n in e)t[n]=_e(e[n]);return ba(t)}else{if(Ea.check(e))return de(...e.map(_e));if(Ba.check(e))return Tn(e);if(Ia.check(e))return H(e)}rt()},ps=na?()=>{}:(e,t)=>{const n=new fa;if(!t.check(e,n))throw _t(`Expected value to be of type ${t.constructor.name}.
4
- ${n.toString()}`)};class La{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:_e(t),h:n}),this}else(t){return this.if(hn,t)}done(){return(t,n)=>{for(let i=0;i<this.patterns.length;i++){const s=this.patterns[i];if(s.if.check(t))return s.h(t,n)}throw _t("Unhandled pattern")}}}const Pa=e=>new La(e),Er=Pa(hn).if(vr,(e,t)=>Yn(t,ss,sn)).if(Cr,(e,t)=>ua(t)).if(ja,(e,t)=>fs(t)).if(Ra,(e,t)=>BigInt(Yn(t,ss,sn))).if(an,(e,t)=>Qt(t,Jn(t,e.shape))).if(ya,(e,t)=>{const n={};for(const i in e.shape){let s=e.shape[i];if(xa.check(s)){if(fs(t))continue;s=s.shape}n[i]=Er(s,t)}return n}).if(ka,(e,t)=>{const n=[],i=hr(t,0,42);for(let s=0;s<i;s++)n.push(Qt(t,e.shape));return n}).if(ur,(e,t)=>Jn(t,e.shape)).if(Na,(e,t)=>null).if(Aa,(e,t)=>{const n=Qt(t,e.res);return()=>n}).if(Oa,(e,t)=>Qt(t,Jn(t,[ee,ae,An,kr,Ui,Dn,wr(ee),gr(de("a","b","c"),ee)]))).if(va,(e,t)=>{const n={},i=Yn(t,0,3);for(let s=0;s<i;s++){const r=Qt(t,e.shape.keys),o=Qt(t,e.shape.values);n[r]=o}return n}).done(),Qt=(e,t)=>Er(_e(t),e),Le=typeof document<"u"?document:{};X(e=>e.nodeType===Fa);typeof DOMParser<"u"&&new DOMParser;X(e=>e.nodeType===za);X(e=>e.nodeType===$a);const Ua=e=>sc(e,(t,n)=>`${n}:${t};`).join(""),za=Le.ELEMENT_NODE,$a=Le.TEXT_NODE,Va=Le.DOCUMENT_NODE,Fa=Le.DOCUMENT_FRAGMENT_NODE;X(e=>e.nodeType===Va);const Ha=e=>class{constructor(n){this._=n}destroy(){e(this._)}},Ka=Ha(clearTimeout),Tr=(e,t)=>new Ka(setTimeout(t,e)),Rt=Symbol,_r=Rt(),Dr=Rt(),qa=Rt(),Wa=Rt(),Ga=Rt(),Ar=Rt(),Ya=Rt(),zi=Rt(),Ja=Rt(),Xa=e=>{var s;e.length===1&&((s=e[0])==null?void 0:s.constructor)===Function&&(e=e[0]());const t=[],n=[];let i=0;for(;i<e.length;i++){const r=e[i];if(r===void 0)break;if(r.constructor===String||r.constructor===Number)t.push(r);else if(r.constructor===Object)break}for(i>0&&n.push(t.join(""));i<e.length;i++){const r=e[i];r instanceof Symbol||n.push(r)}return n},Za={[_r]:Dt("font-weight","bold"),[Dr]:Dt("font-weight","normal"),[qa]:Dt("color","blue"),[Ga]:Dt("color","green"),[Wa]:Dt("color","grey"),[Ar]:Dt("color","red"),[Ya]:Dt("color","purple"),[zi]:Dt("color","orange"),[Ja]:Dt("color","black")},Qa=e=>{var o;e.length===1&&((o=e[0])==null?void 0:o.constructor)===Function&&(e=e[0]());const t=[],n=[],i=wt();let s=[],r=0;for(;r<e.length;r++){const l=e[r],c=Za[l];if(c!==void 0)i.set(c.left,c.right);else{if(l===void 0)break;if(l.constructor===String||l.constructor===Number){const a=Ua(i);r>0||a.length>0?(t.push("%c"+l),n.push(a)):t.push(l)}else break}}for(r>0&&(s=n,s.unshift(t.join("")));r<e.length;r++){const l=e[r];l instanceof Symbol||s.push(l)}return s},Ir=sa?Qa:Xa,th=(...e)=>{console.log(...Ir(e)),Or.forEach(t=>t.print(e))},Mr=(...e)=>{console.warn(...Ir(e)),e.unshift(zi),Or.forEach(t=>t.print(e))},Or=Kt(),Rr=e=>({[Symbol.iterator](){return this},next:e}),eh=(e,t)=>Rr(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),Xn=(e,t)=>Rr(()=>{const{done:n,value:i}=e.next();return{done:n,value:n?void 0:t(i)}});class In{constructor(t,n){this.clock=t,this.len=n}}class fe{constructor(){this.clients=new Map}}const Lt=(e,t,n)=>t.clients.forEach((i,s)=>{const r=e.doc.store.clients.get(s);if(r!=null){const o=r[r.length-1],l=o.id.clock+o.length;for(let c=0,a=i[c];c<i.length&&a.clock<l;a=i[++c])$r(e,r,a.clock,a.len,n)}}),nh=(e,t)=>{let n=0,i=e.length-1;for(;n<=i;){const s=bt((n+i)/2),r=e[s],o=r.clock;if(o<=t){if(t<o+r.len)return s;n=s+1}else i=s-1}return null},pe=(e,t)=>{const n=e.clients.get(t.client);return n!==void 0&&nh(n,t.clock)!==null},$i=e=>{e.clients.forEach(t=>{t.sort((s,r)=>s.clock-r.clock);let n,i;for(n=1,i=1;n<t.length;n++){const s=t[i-1],r=t[n];s.clock+s.len>=r.clock?t[i-1]=new In(s.clock,Bt(s.len,r.clock+r.len-s.clock)):(i<n&&(t[i]=r),i++)}t.length=i})},pi=e=>{const t=new fe;for(let n=0;n<e.length;n++)e[n].clients.forEach((i,s)=>{if(!t.clients.has(s)){const r=i.slice();for(let o=n+1;o<e.length;o++)oc(r,e[o].clients.get(s)||[]);t.clients.set(s,r)}});return $i(t),t},De=(e,t,n,i)=>{Ot(e.clients,t,()=>[]).push(new In(n,i))},jr=()=>new fe,ih=e=>{const t=jr();return e.clients.forEach((n,i)=>{const s=[];for(let r=0;r<n.length;r++){const o=n[r];if(o.deleted){const l=o.id.clock;let c=o.length;if(r+1<n.length)for(let a=n[r+1];r+1<n.length&&a.deleted;a=n[++r+1])c+=a.length;s.push(new In(l,c))}}s.length>0&&t.clients.set(i,s)}),t},Vi=(e,t)=>{A(e.restEncoder,t.clients.size),qt(t.clients.entries()).sort((n,i)=>i[0]-n[0]).forEach(([n,i])=>{e.resetDsCurVal(),A(e.restEncoder,n);const s=i.length;A(e.restEncoder,s);for(let r=0;r<s;r++){const o=i[r];e.writeDsClock(o.clock),e.writeDsLen(o.len)}})},sh=e=>{const t=new fe,n=N(e.restDecoder);for(let i=0;i<n;i++){e.resetDsCurVal();const s=N(e.restDecoder),r=N(e.restDecoder);if(r>0){const o=Ot(t.clients,s,()=>[]);for(let l=0;l<r;l++)o.push(new In(e.readDsClock(),e.readDsLen()))}}return t},gs=(e,t,n)=>{const i=new fe,s=N(e.restDecoder);for(let r=0;r<s;r++){e.resetDsCurVal();const o=N(e.restDecoder),l=N(e.restDecoder),c=n.clients.get(o)||[],a=$(n,o);for(let u=0;u<l;u++){const h=e.readDsClock(),f=h+e.readDsLen();if(h<a){a<f&&De(i,o,a,f-a);let p=yt(c,h),g=c[p];for(!g.deleted&&g.id.clock<h&&(c.splice(p+1,0,xn(t,g,h-g.id.clock)),p++);p<c.length&&(g=c[p++],g.id.clock<f);)g.deleted||(f<g.id.clock+g.length&&c.splice(p,0,xn(t,g,f-g.id.clock)),g.delete(t))}else De(i,o,h,f-h)}}if(i.clients.size>0){const r=new Mn;return A(r.restEncoder,0),Vi(r,i),r.toUint8Array()}return null},Nr=ir;class Jt extends Zs{constructor({guid:t=Fc(),collectionid:n=null,gc:i=!0,gcFilter:s=()=>!0,meta:r=null,autoLoad:o=!1,shouldLoad:l=!0}={}){super(),this.gc=i,this.gcFilter=s,this.clientID=Nr(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new Ur,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=o,this.meta=r,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=us(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const c=()=>us(a=>{const u=h=>{(h===void 0||h===!0)&&(this.off("sync",u),a())};this.on("sync",u)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=a===void 0||a===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=c()}load(){const t=this._item;t!==null&&!this.shouldLoad&&j(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(qt(this.subdocs).map(t=>t.guid))}transact(t,n=null){return j(this,t,n)}get(t,n=J){const i=Ot(this.share,t,()=>{const r=new n;return r._integrate(this,null),r}),s=i.constructor;if(n!==J&&s!==n)if(s===J){const r=new n;r._map=i._map,i._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=r}),r._start=i._start;for(let o=r._start;o!==null;o=o.right)o.parent=r;return r._length=i._length,this.share.set(t,r),r._integrate(this,null),r}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return i}getArray(t=""){return this.get(t,se)}getText(t=""){return this.get(t,Pt)}getMap(t=""){return this.get(t,he)}getXmlElement(t=""){return this.get(t,it)}getXmlFragment(t=""){return this.get(t,Wt)}toJSON(){const t={};return this.share.forEach((n,i)=>{t[i]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,qt(this.subdocs).forEach(n=>n.destroy());const t=this._item;if(t!==null){this._item=null;const n=t.content;n.doc=new Jt({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,j(t.parent.doc,i=>{const s=n.doc;t.deleted||i.subdocsAdded.add(s),i.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class rh{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=N(this.restDecoder),this.dsCurrVal}readDsLen(){const t=N(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class un extends rh{constructor(t){super(t),this.keys=[],N(t),this.keyClockDecoder=new Gn(ut(t)),this.clientDecoder=new Xe(ut(t)),this.leftClockDecoder=new Gn(ut(t)),this.rightClockDecoder=new Gn(ut(t)),this.infoDecoder=new hs(ut(t),Ee),this.stringDecoder=new Pc(ut(t)),this.parentInfoDecoder=new hs(ut(t),Ee),this.typeRefDecoder=new Xe(ut(t)),this.lenDecoder=new Xe(ut(t))}readLeftID(){return new ne(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new ne(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return rn(this.restDecoder)}readBuf(){return ut(this.restDecoder)}readJSON(){return rn(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{const n=this.stringDecoder.read();return this.keys.push(n),n}}}class oh{constructor(){this.restEncoder=Be()}toUint8Array(){return mt(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){A(this.restEncoder,t)}writeDsLen(t){A(this.restEncoder,t)}}class lh extends oh{writeLeftID(t){A(this.restEncoder,t.client),A(this.restEncoder,t.clock)}writeRightID(t){A(this.restEncoder,t.client),A(this.restEncoder,t.clock)}writeClient(t){A(this.restEncoder,t)}writeInfo(t){ai(this.restEncoder,t)}writeString(t){te(this.restEncoder,t)}writeParentInfo(t){A(this.restEncoder,t?1:0)}writeTypeRef(t){A(this.restEncoder,t)}writeLen(t){A(this.restEncoder,t)}writeAny(t){le(this.restEncoder,t)}writeBuf(t){ct(this.restEncoder,t)}writeJSON(t){te(this.restEncoder,JSON.stringify(t))}writeKey(t){te(this.restEncoder,t)}}class ch{constructor(){this.restEncoder=Be(),this.dsCurrVal=0}toUint8Array(){return mt(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,A(this.restEncoder,n)}writeDsLen(t){t===0&&rt(),A(this.restEncoder,t-1),this.dsCurrVal+=t}}class Mn extends ch{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Wn,this.clientEncoder=new Je,this.leftClockEncoder=new Wn,this.rightClockEncoder=new Wn,this.infoEncoder=new ls(ai),this.stringEncoder=new Ac,this.parentInfoEncoder=new ls(ai),this.typeRefEncoder=new Je,this.lenEncoder=new Je}toUint8Array(){const t=Be();return A(t,0),ct(t,this.keyClockEncoder.toUint8Array()),ct(t,this.clientEncoder.toUint8Array()),ct(t,this.leftClockEncoder.toUint8Array()),ct(t,this.rightClockEncoder.toUint8Array()),ct(t,mt(this.infoEncoder)),ct(t,this.stringEncoder.toUint8Array()),ct(t,mt(this.parentInfoEncoder)),ct(t,this.typeRefEncoder.toUint8Array()),ct(t,this.lenEncoder.toUint8Array()),Cn(t,mt(this.restEncoder)),mt(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){le(this.restEncoder,t)}writeBuf(t){ct(this.restEncoder,t)}writeJSON(t){le(this.restEncoder,t)}writeKey(t){const n=this.keyMap.get(t);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}}const ah=(e,t,n,i)=>{i=Bt(i,t[0].id.clock);const s=yt(t,i);A(e.restEncoder,t.length-s),e.writeClient(n),A(e.restEncoder,i);const r=t[s];r.write(e,i-r.id.clock);for(let o=s+1;o<t.length;o++)t[o].write(e,0)},Br=(e,t,n)=>{const i=new Map;n.forEach((s,r)=>{$(t,r)>s&&i.set(r,s)}),On(t).forEach((s,r)=>{n.has(r)||i.set(r,0)}),A(e.restEncoder,i.size),qt(i.entries()).sort((s,r)=>r[0]-s[0]).forEach(([s,r])=>{ah(e,t.clients.get(s),s,r)})},hh=(e,t)=>{const n=wt(),i=N(e.restDecoder);for(let s=0;s<i;s++){const r=N(e.restDecoder),o=new Array(r),l=e.readClient();let c=N(e.restDecoder);n.set(l,{i:0,refs:o});for(let a=0;a<r;a++){const u=e.readInfo();switch(vn&u){case 0:{const h=e.readLen();o[a]=new dt(T(l,c),h),c+=h;break}case 10:{const h=N(e.restDecoder);o[a]=new gt(T(l,c),h),c+=h;break}default:{const h=(u&(It|st))===0,f=new R(T(l,c),null,(u&st)===st?e.readLeftID():null,null,(u&It)===It?e.readRightID():null,h?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,h&&(u&Ce)===Ce?e.readString():null,ao(e,u));o[a]=f,c+=f.length}}}}return n},uh=(e,t,n)=>{const i=[];let s=qt(n.keys()).sort((p,g)=>p-g);if(s.length===0)return null;const r=()=>{if(s.length===0)return null;let p=n.get(s[s.length-1]);for(;p.refs.length===p.i;)if(s.pop(),s.length>0)p=n.get(s[s.length-1]);else return null;return p};let o=r();if(o===null)return null;const l=new Ur,c=new Map,a=(p,g)=>{const x=c.get(p);(x==null||x>g)&&c.set(p,g)};let u=o.refs[o.i++];const h=new Map,f=()=>{for(const p of i){const g=p.id.client,x=n.get(g);x?(x.i--,l.clients.set(g,x.refs.slice(x.i)),n.delete(g),x.i=0,x.refs=[]):l.clients.set(g,[p]),s=s.filter(b=>b!==g)}i.length=0};for(;;){if(u.constructor!==gt){const g=Ot(h,u.id.client,()=>$(t,u.id.client))-u.id.clock;if(g<0)i.push(u),a(u.id.client,u.id.clock-1),f();else{const x=u.getMissing(e,t);if(x!==null){i.push(u);const b=n.get(x)||{refs:[],i:0};if(b.refs.length===b.i)a(x,$(t,x)),f();else{u=b.refs[b.i++];continue}}else(g===0||g<u.length)&&(u.integrate(e,g),h.set(u.id.client,u.id.clock+u.length))}}if(i.length>0)u=i.pop();else if(o!==null&&o.i<o.refs.length)u=o.refs[o.i++];else{if(o=r(),o===null)break;u=o.refs[o.i++]}}if(l.clients.size>0){const p=new Mn;return Br(p,l,new Map),A(p.restEncoder,0),{missing:c,update:p.toUint8Array()}}return null},dh=(e,t)=>Br(e,t.doc.store,t.beforeState),fh=(e,t,n,i=new un(e))=>j(t,s=>{s.local=!1;let r=!1;const o=s.doc,l=o.store,c=hh(i,o),a=uh(s,l,c),u=l.pendingStructs;if(u){for(const[f,p]of u.missing)if(p<$(l,f)){r=!0;break}if(a){for(const[f,p]of a.missing){const g=u.missing.get(f);(g==null||g>p)&&u.missing.set(f,p)}u.update=ks([u.update,a.update])}}else l.pendingStructs=a;const h=gs(i,s,l);if(l.pendingDs){const f=new un(Mi(l.pendingDs));N(f.restDecoder);const p=gs(f,s,l);h&&p?l.pendingDs=ks([h,p]):l.pendingDs=h||p}else l.pendingDs=h;if(r){const f=l.pendingStructs.update;l.pendingStructs=null,gi(s.doc,f)}},n,!1),gi=(e,t,n,i=un)=>{const s=Mi(t);fh(s,e,n,new i(s))};class ph{constructor(){this.l=[]}}const ms=()=>new ph,xs=(e,t)=>e.l.push(t),ws=(e,t)=>{const n=e.l,i=n.length;e.l=n.filter(s=>t!==s),i===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Lr=(e,t,n)=>Ni(e.l,[t,n]);class ne{constructor(t,n){this.client=t,this.clock=n}}const Ve=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,T=(e,t)=>new ne(e,t),Ae=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw rt()},Ie=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1};class dn{constructor(t,n,i,s=0){this.type=t,this.tname=n,this.item=i,this.assoc=s}}class gh{constructor(t,n,i=0){this.type=t,this.index=n,this.assoc=i}}const mh=(e,t,n=0)=>new gh(e,t,n),Fe=(e,t,n)=>{let i=null,s=null;return e._item===null?s=Ae(e):i=T(e._item.id.client,e._item.id.clock),new dn(i,s,t,n)},Zn=(e,t,n=0)=>{let i=e._start;if(n<0){if(t===0)return Fe(e,null,n);t--}for(;i!==null;){if(!i.deleted&&i.countable){if(i.length>t)return Fe(e,T(i.id.client,i.id.clock+t),n);t-=i.length}if(i.right===null&&n<0)return Fe(e,i.lastId,n);i=i.right}return Fe(e,null,n)},xh=(e,t)=>{const n=ie(e,t),i=t.clock-n.id.clock;return{item:n,diff:i}},wh=(e,t,n=!0)=>{const i=t.store,s=e.item,r=e.type,o=e.tname,l=e.assoc;let c=null,a=0;if(s!==null){if($(i,s.client)<=s.clock)return null;const u=n?bi(i,s):xh(i,s),h=u.item;if(!(h instanceof R))return null;if(c=h.parent,c._item===null||!c._item.deleted){a=h.deleted||!h.countable?0:u.diff+(l>=0?0:1);let f=h.left;for(;f!==null;)!f.deleted&&f.countable&&(a+=f.length),f=f.left}}else{if(o!==null)c=t.get(o);else if(r!==null){if($(i,r.client)<=r.clock)return null;const{item:u}=n?bi(i,r):{item:ie(i,r)};if(u instanceof R&&u.content instanceof vt)c=u.content.type;else return null}else throw rt();l>=0?a=c._length:a=0}return mh(c,a,e.assoc)};class Fi{constructor(t,n){this.ds=t,this.sv=n}}const Pr=(e,t)=>new Fi(e,t),Qn=e=>Pr(ih(e.store),On(e.store)),$t=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!pe(t.ds,e.id),mi=(e,t)=>{const n=Ot(e.meta,mi,Kt),i=e.doc.store;n.has(t)||(t.sv.forEach((s,r)=>{s<$(i,r)&&lt(e,T(r,s))}),Lt(e,t.ds,s=>{}),n.add(t))};class Ur{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const On=e=>{const t=new Map;return e.clients.forEach((n,i)=>{const s=n[n.length-1];t.set(i,s.id.clock+s.length)}),t},$=(e,t)=>{const n=e.clients.get(t);if(n===void 0)return 0;const i=n[n.length-1];return i.id.clock+i.length},zr=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{const i=n[n.length-1];if(i.id.clock+i.length!==t.id.clock)throw rt()}n.push(t)},yt=(e,t)=>{let n=0,i=e.length-1,s=e[i],r=s.id.clock;if(r===t)return i;let o=bt(t/(r+s.length-1)*i);for(;n<=i;){if(s=e[o],r=s.id.clock,r<=t){if(t<r+s.length)return o;n=o+1}else i=o-1;o=bt((n+i)/2)}throw rt()},bh=(e,t)=>{const n=e.clients.get(t.client);return n[yt(n,t.clock)]},ie=bh,xi=(e,t,n)=>{const i=yt(t,n),s=t[i];return s.id.clock<n&&s instanceof R?(t.splice(i+1,0,xn(e,s,n-s.id.clock)),i+1):i},lt=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[xi(e,n,t.clock)]},bs=(e,t,n)=>{const i=t.clients.get(n.client),s=yt(i,n.clock),r=i[s];return n.clock!==r.id.clock+r.length-1&&r.constructor!==dt&&i.splice(s+1,0,xn(e,r,n.clock-r.id.clock+1)),r},yh=(e,t,n)=>{const i=e.clients.get(t.id.client);i[yt(i,t.id.clock)]=n},$r=(e,t,n,i,s)=>{if(i===0)return;const r=n+i;let o=xi(e,t,n),l;do l=t[o++],r<l.id.clock+l.length&&xi(e,t,r),s(l);while(o<t.length&&t[o].id.clock<r)};class Sh{constructor(t,n,i){this.doc=t,this.deleteSet=new fe,this.beforeState=On(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=i,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const ys=(e,t)=>t.deleteSet.clients.size===0&&!rc(t.afterState,(n,i)=>t.beforeState.get(i)!==n)?!1:($i(t.deleteSet),dh(e,t),Vi(e,t.deleteSet),!0),Ss=(e,t,n)=>{const i=t._item;(i===null||i.id.clock<(e.beforeState.get(i.id.client)||0)&&!i.deleted)&&Ot(e.changed,t,Kt).add(n)},Qe=(e,t)=>{let n=e[t],i=e[t-1],s=t;for(;s>0;n=i,i=e[--s-1]){if(i.deleted===n.deleted&&i.constructor===n.constructor&&i.mergeWith(n)){n instanceof R&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,i);continue}break}const r=t-s;return r&&e.splice(t+1-r,r),r},vh=(e,t,n)=>{for(const[i,s]of e.clients.entries()){const r=t.clients.get(i);for(let o=s.length-1;o>=0;o--){const l=s[o],c=l.clock+l.len;for(let a=yt(r,l.clock),u=r[a];a<r.length&&u.id.clock<c;u=r[++a]){const h=r[a];if(l.clock+l.len<=h.id.clock)break;h instanceof R&&h.deleted&&!h.keep&&n(h)&&h.gc(t,!1)}}}},Ch=(e,t)=>{e.clients.forEach((n,i)=>{const s=t.clients.get(i);for(let r=n.length-1;r>=0;r--){const o=n[r],l=oe(s.length-1,1+yt(s,o.clock+o.len-1));for(let c=l,a=s[c];c>0&&a.id.clock>=o.clock;a=s[c])c-=1+Qe(s,c)}})},Vr=(e,t)=>{if(t<e.length){const n=e[t],i=n.doc,s=i.store,r=n.deleteSet,o=n._mergeStructs;try{$i(r),n.afterState=On(n.doc.store),i.emit("beforeObserverCalls",[n,i]);const l=[];n.changed.forEach((c,a)=>l.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(n,c)})),l.push(()=>{n.changedParentTypes.forEach((c,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(c=c.filter(u=>u.target._item===null||!u.target._item.deleted),c.forEach(u=>{u.currentTarget=a,u._path=null}),c.sort((u,h)=>u.path.length-h.path.length),l.push(()=>{Lr(a._dEH,c,n)}))}),l.push(()=>i.emit("afterTransaction",[n,i])),l.push(()=>{n._needFormattingCleanup&&Fh(n)})}),Ni(l,[])}finally{i.gc&&vh(r,s,i.gcFilter),Ch(r,s),n.afterState.forEach((u,h)=>{const f=n.beforeState.get(h)||0;if(f!==u){const p=s.clients.get(h),g=Bt(yt(p,f),1);for(let x=p.length-1;x>=g;)x-=1+Qe(p,x)}});for(let u=o.length-1;u>=0;u--){const{client:h,clock:f}=o[u].id,p=s.clients.get(h),g=yt(p,f);g+1<p.length&&Qe(p,g+1)>1||g>0&&Qe(p,g)}if(!n.local&&n.afterState.get(i.clientID)!==n.beforeState.get(i.clientID)&&(th(zi,_r,"[yjs] ",Dr,Ar,"Changed the client-id because another client seems to be using it."),i.clientID=Nr()),i.emit("afterTransactionCleanup",[n,i]),i._observers.has("update")){const u=new lh;ys(u,n)&&i.emit("update",[u.toUint8Array(),n.origin,i,n])}if(i._observers.has("updateV2")){const u=new Mn;ys(u,n)&&i.emit("updateV2",[u.toUint8Array(),n.origin,i,n])}const{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=n;(l.size>0||a.size>0||c.size>0)&&(l.forEach(u=>{u.clientID=i.clientID,u.collectionid==null&&(u.collectionid=i.collectionid),i.subdocs.add(u)}),a.forEach(u=>i.subdocs.delete(u)),i.emit("subdocs",[{loaded:c,added:l,removed:a},i,n]),a.forEach(u=>u.destroy())),e.length<=t+1?(i._transactionCleanups=[],i.emit("afterAllTransactions",[i,e])):Vr(e,t+1)}}},j=(e,t,n=null,i=!0)=>{const s=e._transactionCleanups;let r=!1,o=null;e._transaction===null&&(r=!0,e._transaction=new Sh(e,n,i),s.push(e._transaction),s.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(r){const l=e._transaction===s[0];e._transaction=null,l&&Vr(s,0)}}return o};class kh{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const vs=(e,t,n)=>{Lt(e,n.deletions,i=>{i instanceof R&&t.scope.some(s=>s===e.doc||Ie(s,i))&&Gi(i,!1)})},Cs=(e,t,n)=>{let i=null;const s=e.doc,r=e.scope;j(s,l=>{for(;t.length>0&&e.currStackItem===null;){const c=s.store,a=t.pop(),u=new Set,h=[];let f=!1;Lt(l,a.insertions,p=>{if(p instanceof R){if(p.redone!==null){let{item:g,diff:x}=bi(c,p.id);x>0&&(g=lt(l,T(g.id.client,g.id.clock+x))),p=g}!p.deleted&&r.some(g=>g===l.doc||Ie(g,p))&&h.push(p)}}),Lt(l,a.deletions,p=>{p instanceof R&&r.some(g=>g===l.doc||Ie(g,p))&&!pe(a.insertions,p.id)&&u.add(p)}),u.forEach(p=>{f=co(l,p,u,a.insertions,e.ignoreRemoteMapChanges,e)!==null||f});for(let p=h.length-1;p>=0;p--){const g=h[p];e.deleteFilter(g)&&(g.delete(l),f=!0)}e.currStackItem=f?a:null}l.changed.forEach((c,a)=>{c.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),i=l},e);const o=e.currStackItem;if(o!=null){const l=i.changedParentTypes;e.emit("stack-item-popped",[{stackItem:o,type:n,changedParentTypes:l,origin:e},e]),e.currStackItem=null}return o};class Fr extends Zs{constructor(t,{captureTimeout:n=500,captureTransaction:i=c=>!0,deleteFilter:s=()=>!0,trackedOrigins:r=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:l=re(t)?t[0].doc:t instanceof Jt?t:t.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(t),this.deleteFilter=s,r.add(this),this.trackedOrigins=r,this.captureTransaction=i,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=n,this.afterTransactionHandler=c=>{if(!this.captureTransaction(c)||!this.scope.some(b=>c.changedParentTypes.has(b)||b===this.doc)||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;const a=this.undoing,u=this.redoing,h=a?this.redoStack:this.undoStack;a?this.stopCapturing():u||this.clear(!1,!0);const f=new fe;c.afterState.forEach((b,y)=>{const C=c.beforeState.get(y)||0,S=b-C;S>0&&De(f,y,C,S)});const p=Hc();let g=!1;if(this.lastChange>0&&p-this.lastChange<this.captureTimeout&&h.length>0&&!a&&!u){const b=h[h.length-1];b.deletions=pi([b.deletions,c.deleteSet]),b.insertions=pi([b.insertions,f])}else h.push(new kh(c.deleteSet,f)),g=!0;!a&&!u&&(this.lastChange=p),Lt(c,c.deleteSet,b=>{b instanceof R&&this.scope.some(y=>y===c.doc||Ie(y,b))&&Gi(b,!0)});const x=[{stackItem:h[h.length-1],origin:c.origin,type:a?"redo":"undo",changedParentTypes:c.changedParentTypes},this];g?this.emit("stack-item-added",x):this.emit("stack-item-updated",x)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){const n=new Set(this.scope);t=re(t)?t:[t],t.forEach(i=>{n.has(i)||(n.add(i),(i instanceof J?i.doc!==this.doc:i!==this.doc)&&Mr("[yjs#509] Not same Y.Doc"),this.scope.push(i))})}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,n=!0){(t&&this.canUndo()||n&&this.canRedo())&&this.doc.transact(i=>{t&&(this.undoStack.forEach(s=>vs(i,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>vs(i,this,s)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let t;try{t=Cs(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=Cs(this,this.redoStack,"redo")}finally{this.redoing=!1}return t}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}}function*Eh(e){const t=N(e.restDecoder);for(let n=0;n<t;n++){const i=N(e.restDecoder),s=e.readClient();let r=N(e.restDecoder);for(let o=0;o<i;o++){const l=e.readInfo();if(l===10){const c=N(e.restDecoder);yield new gt(T(s,r),c),r+=c}else if((vn&l)!==0){const c=(l&(It|st))===0,a=new R(T(s,r),null,(l&st)===st?e.readLeftID():null,null,(l&It)===It?e.readRightID():null,c?e.readParentInfo()?e.readString():e.readLeftID():null,c&&(l&Ce)===Ce?e.readString():null,ao(e,l));yield a,r+=a.length}else{const c=e.readLen();yield new dt(T(s,r),c),r+=c}}}}class Th{constructor(t,n){this.gen=Eh(t),this.curr=null,this.done=!1,this.filterSkips=n,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===gt);return this.curr}}class _h{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const Dh=(e,t)=>{if(e.constructor===dt){const{client:n,clock:i}=e.id;return new dt(T(n,i+t),e.length-t)}else if(e.constructor===gt){const{client:n,clock:i}=e.id;return new gt(T(n,i+t),e.length-t)}else{const n=e,{client:i,clock:s}=n.id;return new R(T(i,s+t),null,T(i,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},ks=(e,t=un,n=Mn)=>{if(e.length===1)return e[0];const i=e.map(u=>new t(Mi(u)));let s=i.map(u=>new Th(u,!0)),r=null;const o=new n,l=new _h(o);for(;s=s.filter(f=>f.curr!==null),s.sort((f,p)=>{if(f.curr.id.client===p.curr.id.client){const g=f.curr.id.clock-p.curr.id.clock;return g===0?f.curr.constructor===p.curr.constructor?0:f.curr.constructor===gt?1:-1:g}else return p.curr.id.client-f.curr.id.client}),s.length!==0;){const u=s[0],h=u.curr.id.client;if(r!==null){let f=u.curr,p=!1;for(;f!==null&&f.id.clock+f.length<=r.struct.id.clock+r.struct.length&&f.id.client>=r.struct.id.client;)f=u.next(),p=!0;if(f===null||f.id.client!==h||p&&f.id.clock>r.struct.id.clock+r.struct.length)continue;if(h!==r.struct.id.client)ye(l,r.struct,r.offset),r={struct:f,offset:0},u.next();else if(r.struct.id.clock+r.struct.length<f.id.clock)if(r.struct.constructor===gt)r.struct.length=f.id.clock+f.length-r.struct.id.clock;else{ye(l,r.struct,r.offset);const g=f.id.clock-r.struct.id.clock-r.struct.length;r={struct:new gt(T(h,r.struct.id.clock+r.struct.length),g),offset:0}}else{const g=r.struct.id.clock+r.struct.length-f.id.clock;g>0&&(r.struct.constructor===gt?r.struct.length-=g:f=Dh(f,g)),r.struct.mergeWith(f)||(ye(l,r.struct,r.offset),r={struct:f,offset:0},u.next())}}else r={struct:u.curr,offset:0},u.next();for(let f=u.curr;f!==null&&f.id.client===h&&f.id.clock===r.struct.id.clock+r.struct.length&&f.constructor!==gt;f=u.next())ye(l,r.struct,r.offset),r={struct:f,offset:0}}r!==null&&(ye(l,r.struct,r.offset),r=null),Ah(l);const c=i.map(u=>sh(u)),a=pi(c);return Vi(o,a),o.toUint8Array()},Hr=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:mt(e.encoder.restEncoder)}),e.encoder.restEncoder=Be(),e.written=0)},ye=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Hr(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),A(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Ah=e=>{Hr(e);const t=e.encoder.restEncoder;A(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const i=e.clientStructs[n];A(t,i.written),Cn(t,i.restEncoder)}},Es="You must not compute changes after the event-handler fired.";class Rn{constructor(t,n){this.target=t,this.currentTarget=t,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Ih(this.currentTarget,this.target))}deletes(t){return pe(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw _t(Es);const t=new Map,n=this.target;this.transaction.changed.get(n).forEach(s=>{if(s!==null){const r=n._map.get(s);let o,l;if(this.adds(r)){let c=r.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(r))if(c!==null&&this.deletes(c))o="delete",l=Hn(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Hn(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(r))o="delete",l=Hn(r.content.getContent());else return;t.set(s,{action:o,oldValue:l})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw _t(Es);const n=this.target,i=Kt(),s=Kt(),r=[];if(t={added:i,deleted:s,delta:r,keys:this.keys},this.transaction.changed.get(n).has(null)){let l=null;const c=()=>{l&&r.push(l)};for(let a=n._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((l===null||l.delete===void 0)&&(c(),l={delete:0}),l.delete+=a.length,s.add(a)):this.adds(a)?((l===null||l.insert===void 0)&&(c(),l={insert:[]}),l.insert=l.insert.concat(a.content.getContent()),i.add(a)):((l===null||l.retain===void 0)&&(c(),l={retain:0}),l.retain+=a.length);l!==null&&l.retain===void 0&&c()}this._changes=t}return t}}const Ih=(e,t)=>{const n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let i=0,s=t._item.parent._start;for(;s!==t._item&&s!==null;)!s.deleted&&s.countable&&(i+=s.length),s=s.right;n.unshift(i)}t=t._item.parent}return n},tt=()=>{Mr("Invalid access: Add Yjs type to a document before reading data.")},Kr=80;let Hi=0;class Mh{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=Hi++}}const Oh=e=>{e.timestamp=Hi++},qr=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Hi++},Rh=(e,t,n)=>{if(e.length>=Kr){const i=e.reduce((s,r)=>s.timestamp<r.timestamp?s:r);return qr(i,t,n),i}else{const i=new Mh(t,n);return e.push(i),i}},jn=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;const n=e._searchMarker.length===0?null:e._searchMarker.reduce((r,o)=>Ye(t-r.index)<Ye(t-o.index)?r:o);let i=e._start,s=0;for(n!==null&&(i=n.p,s=n.index,Oh(n));i.right!==null&&s<t;){if(!i.deleted&&i.countable){if(t<s+i.length)break;s+=i.length}i=i.right}for(;i.left!==null&&s>t;)i=i.left,!i.deleted&&i.countable&&(s-=i.length);for(;i.left!==null&&i.left.id.client===i.id.client&&i.left.id.clock+i.left.length===i.id.clock;)i=i.left,!i.deleted&&i.countable&&(s-=i.length);return n!==null&&Ye(n.index-s)<i.parent.length/Kr?(qr(n,i,s),n):Rh(e._searchMarker,i,s)},Me=(e,t,n)=>{for(let i=e.length-1;i>=0;i--){const s=e[i];if(n>0){let r=s.p;for(r.marker=!1;r&&(r.deleted||!r.countable);)r=r.left,r&&!r.deleted&&r.countable&&(s.index-=r.length);if(r===null||r.marker===!0){e.splice(i,1);continue}s.p=r,r.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=Bt(t,s.index+n))}},Nn=(e,t,n)=>{const i=e,s=t.changedParentTypes;for(;Ot(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Lr(i._eH,n,t)};class J{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ms(),this._dEH=ms(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw pt()}clone(){throw pt()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,n){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){xs(this._eH,t)}observeDeep(t){xs(this._dEH,t)}unobserve(t){ws(this._eH,t)}unobserveDeep(t){ws(this._dEH,t)}toJSON(){}}const Wr=(e,t,n)=>{e.doc??tt(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let i=n-t;const s=[];let r=e._start;for(;r!==null&&i>0;){if(r.countable&&!r.deleted){const o=r.content.getContent();if(o.length<=t)t-=o.length;else{for(let l=t;l<o.length&&i>0;l++)s.push(o[l]),i--;t=0}}r=r.right}return s},Gr=e=>{e.doc??tt();const t=[];let n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){const i=n.content.getContent();for(let s=0;s<i.length;s++)t.push(i[s])}n=n.right}return t},Yr=(e,t)=>{const n=[];let i=e._start;for(;i!==null;){if(i.countable&&$t(i,t)){const s=i.content.getContent();for(let r=0;r<s.length;r++)n.push(s[r])}i=i.right}return n},Oe=(e,t)=>{let n=0,i=e._start;for(e.doc??tt();i!==null;){if(i.countable&&!i.deleted){const s=i.content.getContent();for(let r=0;r<s.length;r++)t(s[r],n++,e)}i=i.right}},Jr=(e,t)=>{const n=[];return Oe(e,(i,s)=>{n.push(t(i,s,e))}),n},jh=e=>{let t=e._start,n=null,i=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),i=0,t=t.right}const s=n[i++];return n.length<=i&&(n=null),{done:!1,value:s}}}},Xr=(e,t)=>{e.doc??tt();const n=jn(e,t);let i=e._start;for(n!==null&&(i=n.p,t-=n.index);i!==null;i=i.right)if(!i.deleted&&i.countable){if(t<i.length)return i.content.getContent()[t];t-=i.length}},fn=(e,t,n,i)=>{let s=n;const r=e.doc,o=r.clientID,l=r.store,c=n===null?t._start:n.right;let a=[];const u=()=>{a.length>0&&(s=new R(T(o,$(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new Gt(a)),s.integrate(e,0),a=[])};i.forEach(h=>{if(h===null)a.push(h);else switch(h.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(h);break;default:switch(u(),h.constructor){case Uint8Array:case ArrayBuffer:s=new R(T(o,$(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new Pe(new Uint8Array(h))),s.integrate(e,0);break;case Jt:s=new R(T(o,$(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new Ue(h)),s.integrate(e,0);break;default:if(h instanceof J)s=new R(T(o,$(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new vt(h)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),u()},Zr=()=>_t("Length exceeded!"),Qr=(e,t,n,i)=>{if(n>t._length)throw Zr();if(n===0)return t._searchMarker&&Me(t._searchMarker,n,i.length),fn(e,t,null,i);const s=n,r=jn(t,n);let o=t._start;for(r!==null&&(o=r.p,n-=r.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&lt(e,T(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&Me(t._searchMarker,s,i.length),fn(e,t,o,i)},Nh=(e,t,n)=>{let s=(t._searchMarker||[]).reduce((r,o)=>o.index>r.index?o:r,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return fn(e,t,s,n)},to=(e,t,n,i)=>{if(i===0)return;const s=n,r=i,o=jn(t,n);let l=t._start;for(o!==null&&(l=o.p,n-=o.index);l!==null&&n>0;l=l.right)!l.deleted&&l.countable&&(n<l.length&&lt(e,T(l.id.client,l.id.clock+n)),n-=l.length);for(;i>0&&l!==null;)l.deleted||(i<l.length&&lt(e,T(l.id.client,l.id.clock+i)),l.delete(e),i-=l.length),l=l.right;if(i>0)throw Zr();t._searchMarker&&Me(t._searchMarker,s,-r+i)},pn=(e,t,n)=>{const i=t._map.get(n);i!==void 0&&i.delete(e)},Ki=(e,t,n,i)=>{const s=t._map.get(n)||null,r=e.doc,o=r.clientID;let l;if(i==null)l=new Gt([i]);else switch(i.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new Gt([i]);break;case Uint8Array:l=new Pe(i);break;case Jt:l=new Ue(i);break;default:if(i instanceof J)l=new vt(i);else throw new Error("Unexpected content type")}new R(T(o,$(r.store,o)),s,s&&s.lastId,null,null,t,n,l).integrate(e,0)},qi=(e,t)=>{e.doc??tt();const n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},eo=e=>{const t={};return e.doc??tt(),e._map.forEach((n,i)=>{n.deleted||(t[i]=n.content.getContent()[n.length-1])}),t},no=(e,t)=>{e.doc??tt();const n=e._map.get(t);return n!==void 0&&!n.deleted},Bh=(e,t)=>{const n={};return e._map.forEach((i,s)=>{let r=i;for(;r!==null&&(!t.sv.has(r.id.client)||r.id.clock>=(t.sv.get(r.id.client)||0));)r=r.left;r!==null&&$t(r,t)&&(n[s]=r.content.getContent()[r.length-1])}),n},He=e=>(e.doc??tt(),eh(e._map.entries(),t=>!t[1].deleted));class Lh extends Rn{}class se extends J{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new se;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new se}clone(){const t=new se;return t.insert(0,this.toArray().map(n=>n instanceof J?n.clone():n)),t}get length(){return this.doc??tt(),this._length}_callObserver(t,n){super._callObserver(t,n),Nn(this,t,new Lh(this,t))}insert(t,n){this.doc!==null?j(this.doc,i=>{Qr(i,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?j(this.doc,n=>{Nh(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?j(this.doc,i=>{to(i,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return Xr(this,t)}toArray(){return Gr(this)}slice(t=0,n=this.length){return Wr(this,t,n)}toJSON(){return this.map(t=>t instanceof J?t.toJSON():t)}map(t){return Jr(this,t)}forEach(t){Oe(this,t)}[Symbol.iterator](){return jh(this)}_write(t){t.writeTypeRef(cu)}}const Ph=e=>new se;class Uh extends Rn{constructor(t,n,i){super(t,n),this.keysChanged=i}}class he extends J{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach((i,s)=>{this.set(s,i)}),this._prelimContent=null}_copy(){return new he}clone(){const t=new he;return this.forEach((n,i)=>{t.set(i,n instanceof J?n.clone():n)}),t}_callObserver(t,n){Nn(this,t,new Uh(this,t,n))}toJSON(){this.doc??tt();const t={};return this._map.forEach((n,i)=>{if(!n.deleted){const s=n.content.getContent()[n.length-1];t[i]=s instanceof J?s.toJSON():s}}),t}get size(){return[...He(this)].length}keys(){return Xn(He(this),t=>t[0])}values(){return Xn(He(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Xn(He(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??tt(),this._map.forEach((n,i)=>{n.deleted||t(n.content.getContent()[n.length-1],i,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?j(this.doc,n=>{pn(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?j(this.doc,i=>{Ki(i,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return qi(this,t)}has(t){return no(this,t)}clear(){this.doc!==null?j(this.doc,t=>{this.forEach(function(n,i,s){pn(t,s,i)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(au)}}const zh=e=>new he,Nt=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&Zc(e,t);class wi{constructor(t,n,i,s){this.left=t,this.right=n,this.index=i,this.currentAttributes=s}forward(){switch(this.right===null&&rt(),this.right.content.constructor){case F:this.right.deleted||ge(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}}const Ts=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case F:t.right.deleted||ge(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&lt(e,T(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length);break}t.left=t.right,t.right=t.right.right}return t},Ke=(e,t,n,i)=>{const s=new Map,r=i?jn(t,n):null;if(r){const o=new wi(r.p.left,r.p,r.index,s);return Ts(e,o,n-r.index)}else{const o=new wi(null,t._start,0,s);return Ts(e,o,n)}},io=(e,t,n,i)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===F&&Nt(i.get(n.right.content.key),n.right.content.value));)n.right.deleted||i.delete(n.right.content.key),n.forward();const s=e.doc,r=s.clientID;i.forEach((o,l)=>{const c=n.left,a=n.right,u=new R(T(r,$(s.store,r)),c,c&&c.lastId,a,a&&a.id,t,null,new F(l,o));u.integrate(e,0),n.right=u,n.forward()})},ge=(e,t)=>{const{key:n,value:i}=t;i===null?e.delete(n):e.set(n,i)},so=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===F&&Nt(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},ro=(e,t,n,i)=>{const s=e.doc,r=s.clientID,o=new Map;for(const l in i){const c=i[l],a=n.currentAttributes.get(l)??null;if(!Nt(a,c)){o.set(l,a);const{left:u,right:h}=n;n.right=new R(T(r,$(s.store,r)),u,u&&u.lastId,h,h&&h.id,t,null,new F(l,c)),n.right.integrate(e,0),n.forward()}}return o},ti=(e,t,n,i,s)=>{n.currentAttributes.forEach((f,p)=>{s[p]===void 0&&(s[p]=null)});const r=e.doc,o=r.clientID;so(n,s);const l=ro(e,t,n,s),c=i.constructor===String?new St(i):i instanceof J?new vt(i):new Xt(i);let{left:a,right:u,index:h}=n;t._searchMarker&&Me(t._searchMarker,n.index,c.getLength()),u=new R(T(o,$(r.store,o)),a,a&&a.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=h,n.forward(),io(e,t,n,l)},_s=(e,t,n,i,s)=>{const r=e.doc,o=r.clientID;so(n,s);const l=ro(e,t,n,s);t:for(;n.right!==null&&(i>0||l.size>0&&(n.right.deleted||n.right.content.constructor===F));){if(!n.right.deleted)switch(n.right.content.constructor){case F:{const{key:c,value:a}=n.right.content,u=s[c];if(u!==void 0){if(Nt(u,a))l.delete(c);else{if(i===0)break t;l.set(c,a)}n.right.delete(e)}else n.currentAttributes.set(c,a);break}default:i<n.right.length&&lt(e,T(n.right.id.client,n.right.id.clock+i)),i-=n.right.length;break}n.forward()}if(i>0){let c="";for(;i>0;i--)c+=`
5
- `;n.right=new R(T(o,$(r.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new St(c)),n.right.integrate(e,0),n.forward()}io(e,t,n,l)},oo=(e,t,n,i,s)=>{let r=t;const o=wt();for(;r&&(!r.countable||r.deleted);){if(!r.deleted&&r.content.constructor===F){const a=r.content;o.set(a.key,a)}r=r.right}let l=0,c=!1;for(;t!==r;){if(n===t&&(c=!0),!t.deleted){const a=t.content;switch(a.constructor){case F:{const{key:u,value:h}=a,f=i.get(u)??null;(o.get(u)!==a||f===h)&&(t.delete(e),l++,!c&&(s.get(u)??null)===h&&f!==h&&(f===null?s.delete(u):s.set(u,f))),!c&&!t.deleted&&ge(s,a);break}}}t=t.right}return l},$h=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===F){const i=t.content.key;n.has(i)?t.delete(e):n.add(i)}t=t.left}},Vh=e=>{let t=0;return j(e.doc,n=>{let i=e._start,s=e._start,r=wt();const o=li(r);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case F:ge(o,s.content);break;default:t+=oo(n,i,s,r,o),r=li(o),i=s;break}s=s.right}}),t},Fh=e=>{const t=new Set,n=e.doc;for(const[i,s]of e.afterState.entries()){const r=e.beforeState.get(i)||0;s!==r&&$r(e,n.store.clients.get(i),r,s,o=>{!o.deleted&&o.content.constructor===F&&o.constructor!==dt&&t.add(o.parent)})}j(n,i=>{Lt(e,e.deleteSet,s=>{if(s instanceof dt||!s.parent._hasFormatting||t.has(s.parent))return;const r=s.parent;s.content.constructor===F?t.add(r):$h(i,s)});for(const s of t)Vh(s)})},Ds=(e,t,n)=>{const i=n,s=li(t.currentAttributes),r=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case vt:case Xt:case St:n<t.right.length&&lt(e,T(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}r&&oo(e,r,t.right,s,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&Me(o._searchMarker,t.index,-i+n),t};class Hh extends Rn{constructor(t,n,i){super(t,n),this.childListChanged=!1,this.keysChanged=new Set,i.forEach(s=>{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}get changes(){if(this._changes===null){const t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){const t=this.target.doc,n=[];j(t,i=>{const s=new Map,r=new Map;let o=this.target._start,l=null;const c={};let a="",u=0,h=0;const f=()=>{if(l!==null){let p=null;switch(l){case"delete":h>0&&(p={delete:h}),h=0;break;case"insert":(typeof a=="object"||a.length>0)&&(p={insert:a},s.size>0&&(p.attributes={},s.forEach((g,x)=>{g!==null&&(p.attributes[x]=g)}))),a="";break;case"retain":u>0&&(p={retain:u},Xc(c)||(p.attributes=Yc({},c))),u=0;break}p&&n.push(p),l=null}};for(;o!==null;){switch(o.content.constructor){case vt:case Xt:this.adds(o)?this.deletes(o)||(f(),l="insert",a=o.content.getContent()[0],f()):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),h+=1):o.deleted||(l!=="retain"&&(f(),l="retain"),u+=1);break;case St:this.adds(o)?this.deletes(o)||(l!=="insert"&&(f(),l="insert"),a+=o.content.str):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),h+=o.length):o.deleted||(l!=="retain"&&(f(),l="retain"),u+=o.length);break;case F:{const{key:p,value:g}=o.content;if(this.adds(o)){if(!this.deletes(o)){const x=s.get(p)??null;Nt(x,g)?g!==null&&o.delete(i):(l==="retain"&&f(),Nt(g,r.get(p)??null)?delete c[p]:c[p]=g)}}else if(this.deletes(o)){r.set(p,g);const x=s.get(p)??null;Nt(x,g)||(l==="retain"&&f(),c[p]=x)}else if(!o.deleted){r.set(p,g);const x=c[p];x!==void 0&&(Nt(x,g)?x!==null&&o.delete(i):(l==="retain"&&f(),g===null?delete c[p]:c[p]=g))}o.deleted||(l==="insert"&&f(),ge(s,o.content));break}}o=o.right}for(f();n.length>0;){const p=n[n.length-1];if(p.retain!==void 0&&p.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class Pt extends J{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??tt(),this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach(i=>i())}catch(i){console.error(i)}this._pending=null}_copy(){return new Pt}clone(){const t=new Pt;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const i=new Hh(this,t,n);Nn(this,t,i),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??tt();let t="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===St&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){this.doc!==null?j(this.doc,i=>{const s=new wi(null,this._start,0,new Map);for(let r=0;r<t.length;r++){const o=t[r];if(o.insert!==void 0){const l=!n&&typeof o.insert=="string"&&r===t.length-1&&s.right===null&&o.insert.slice(-1)===`
6
- `?o.insert.slice(0,-1):o.insert;(typeof l!="string"||l.length>0)&&ti(i,this,s,l,o.attributes||{})}else o.retain!==void 0?_s(i,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&Ds(i,s,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,i){this.doc??tt();const s=[],r=new Map,o=this.doc;let l="",c=this._start;function a(){if(l.length>0){const h={};let f=!1;r.forEach((g,x)=>{f=!0,h[x]=g});const p={insert:l};f&&(p.attributes=h),s.push(p),l=""}}const u=()=>{for(;c!==null;){if($t(c,t)||n!==void 0&&$t(c,n))switch(c.content.constructor){case St:{const h=r.get("ychange");t!==void 0&&!$t(c,t)?(h===void 0||h.user!==c.id.client||h.type!=="removed")&&(a(),r.set("ychange",i?i("removed",c.id):{type:"removed"})):n!==void 0&&!$t(c,n)?(h===void 0||h.user!==c.id.client||h.type!=="added")&&(a(),r.set("ychange",i?i("added",c.id):{type:"added"})):h!==void 0&&(a(),r.delete("ychange")),l+=c.content.str;break}case vt:case Xt:{a();const h={insert:c.content.getContent()[0]};if(r.size>0){const f={};h.attributes=f,r.forEach((p,g)=>{f[g]=p})}s.push(h);break}case F:$t(c,t)&&(a(),ge(r,c.content));break}c=c.right}a()};return t||n?j(o,h=>{t&&mi(h,t),n&&mi(h,n),u()},"cleanup"):u(),s}insert(t,n,i){if(n.length<=0)return;const s=this.doc;s!==null?j(s,r=>{const o=Ke(r,this,t,!i);i||(i={},o.currentAttributes.forEach((l,c)=>{i[c]=l})),ti(r,this,o,n,i)}):this._pending.push(()=>this.insert(t,n,i))}insertEmbed(t,n,i){const s=this.doc;s!==null?j(s,r=>{const o=Ke(r,this,t,!i);ti(r,this,o,n,i||{})}):this._pending.push(()=>this.insertEmbed(t,n,i||{}))}delete(t,n){if(n===0)return;const i=this.doc;i!==null?j(i,s=>{Ds(s,Ke(s,this,t,!0),n)}):this._pending.push(()=>this.delete(t,n))}format(t,n,i){if(n===0)return;const s=this.doc;s!==null?j(s,r=>{const o=Ke(r,this,t,!1);o.right!==null&&_s(r,this,o,n,i)}):this._pending.push(()=>this.format(t,n,i))}removeAttribute(t){this.doc!==null?j(this.doc,n=>{pn(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?j(this.doc,i=>{Ki(i,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return qi(this,t)}getAttributes(){return eo(this)}_write(t){t.writeTypeRef(hu)}}const Kh=e=>new Pt;class ei{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??tt()}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(n)))do if(n=t.content.type,!t.deleted&&(n.constructor===it||n.constructor===Wt)&&n._start!==null)t=n._start;else for(;t!==null;){const i=t.next;if(i!==null){t=i;break}else t.parent===this._root?t=null:t=t.parent._item}while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class Wt extends J{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Wt}clone(){const t=new Wt;return t.insert(0,this.toArray().map(n=>n instanceof J?n.clone():n)),t}get length(){return this.doc??tt(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new ei(this,t)}querySelector(t){t=t.toUpperCase();const i=new ei(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return i.done?null:i.value}querySelectorAll(t){return t=t.toUpperCase(),qt(new ei(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){Nn(this,t,new Gh(this,n,t))}toString(){return Jr(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},i){const s=t.createDocumentFragment();return i!==void 0&&i._createAssociation(s,this),Oe(this,r=>{s.insertBefore(r.toDOM(t,n,i),null)}),s}insert(t,n){this.doc!==null?j(this.doc,i=>{Qr(i,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)j(this.doc,i=>{const s=t&&t instanceof J?t._item:t;fn(i,this,s,n)});else{const i=this._prelimContent,s=t===null?0:i.findIndex(r=>r===t)+1;if(s===0&&t!==null)throw _t("Reference item not found");i.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?j(this.doc,i=>{to(i,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return Gr(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Xr(this,t)}slice(t=0,n=this.length){return Wr(this,t,n)}forEach(t){Oe(this,t)}_write(t){t.writeTypeRef(du)}}const qh=e=>new Wt;class it extends Wt{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach((i,s)=>{this.setAttribute(s,i)}),this._prelimAttrs=null}_copy(){return new it(this.nodeName)}clone(){const t=new it(this.nodeName),n=this.getAttributes();return Jc(n,(i,s)=>{t.setAttribute(s,i)}),t.insert(0,this.toArray().map(i=>i instanceof J?i.clone():i)),t}toString(){const t=this.getAttributes(),n=[],i=[];for(const l in t)i.push(l);i.sort();const s=i.length;for(let l=0;l<s;l++){const c=i[l];n.push(c+'="'+t[c]+'"')}const r=this.nodeName.toLocaleLowerCase(),o=n.length>0?" "+n.join(" "):"";return`<${r}${o}>${super.toString()}</${r}>`}removeAttribute(t){this.doc!==null?j(this.doc,n=>{pn(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?j(this.doc,i=>{Ki(i,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return qi(this,t)}hasAttribute(t){return no(this,t)}getAttributes(t){return t?Bh(this,t):eo(this)}toDOM(t=document,n={},i){const s=t.createElement(this.nodeName),r=this.getAttributes();for(const o in r){const l=r[o];typeof l=="string"&&s.setAttribute(o,l)}return Oe(this,o=>{s.appendChild(o.toDOM(t,n,i))}),i!==void 0&&i._createAssociation(s,this),s}_write(t){t.writeTypeRef(uu),t.writeKey(this.nodeName)}}const Wh=e=>new it(e.readKey());class Gh extends Rn{constructor(t,n,i){super(t,i),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}}class gn extends he{constructor(t){super(),this.hookName=t}_copy(){return new gn(this.hookName)}clone(){const t=new gn(this.hookName);return this.forEach((n,i)=>{t.set(i,n)}),t}toDOM(t=document,n={},i){const s=n[this.hookName];let r;return s!==void 0?r=s.createDom(this):r=document.createElement(this.hookName),r.setAttribute("data-yjs-hook",this.hookName),i!==void 0&&i._createAssociation(r,this),r}_write(t){t.writeTypeRef(fu),t.writeKey(this.hookName)}}const Yh=e=>new gn(e.readKey());class at extends Pt{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new at}clone(){const t=new at;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,i){const s=t.createTextNode(this.toString());return i!==void 0&&i._createAssociation(s,this),s}toString(){return this.toDelta().map(t=>{const n=[];for(const s in t.attributes){const r=[];for(const o in t.attributes[s])r.push({key:o,value:t.attributes[s][o]});r.sort((o,l)=>o.key<l.key?-1:1),n.push({nodeName:s,attrs:r})}n.sort((s,r)=>s.nodeName<r.nodeName?-1:1);let i="";for(let s=0;s<n.length;s++){const r=n[s];i+=`<${r.nodeName}`;for(let o=0;o<r.attrs.length;o++){const l=r.attrs[o];i+=` ${l.key}="${l.value}"`}i+=">"}i+=t.insert;for(let s=n.length-1;s>=0;s--)i+=`</${n[s].nodeName}>`;return i}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(pu)}}const Jh=e=>new at;class Wi{constructor(t,n){this.id=t,this.length=n}get deleted(){throw pt()}mergeWith(t){return!1}write(t,n,i){throw pt()}integrate(t,n){throw pt()}}const Xh=0;class dt extends Wi{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){n>0&&(this.id.clock+=n,this.length-=n),zr(t.doc.store,this)}write(t,n){t.writeInfo(Xh),t.writeLen(this.length-n)}getMissing(t,n){return null}}class Pe{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Pe(this.content)}splice(t){throw pt()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}const Zh=e=>new Pe(e.readBuf());class Re{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Re(this.len)}splice(t){const n=new Re(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){De(t.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(t){}gc(t){}write(t,n){t.writeLen(this.len-n)}getRef(){return 1}}const Qh=e=>new Re(e.readLen()),lo=(e,t)=>new Jt({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Ue{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const n={};this.opts=n,t.gc||(n.gc=!1),t.autoLoad&&(n.autoLoad=!0),t.meta!==null&&(n.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Ue(lo(this.doc.guid,this.opts))}splice(t){throw pt()}mergeWith(t){return!1}integrate(t,n){this.doc._item=n,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,n){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}const tu=e=>new Ue(lo(e.readString(),e.readAny()));class Xt{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Xt(this.embed)}splice(t){throw pt()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}const eu=e=>new Xt(e.readJSON());class F{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new F(this.key,this.value)}splice(t){throw pt()}mergeWith(t){return!1}integrate(t,n){const i=n.parent;i._searchMarker=null,i._hasFormatting=!0}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}const nu=e=>new F(e.readKey(),e.readJSON());class mn{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new mn(this.arr)}splice(t){const n=new mn(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const i=this.arr.length;t.writeLen(i-n);for(let s=n;s<i;s++){const r=this.arr[s];t.writeString(r===void 0?"undefined":JSON.stringify(r))}}getRef(){return 2}}const iu=e=>{const t=e.readLen(),n=[];for(let i=0;i<t;i++){const s=e.readString();s==="undefined"?n.push(void 0):n.push(JSON.parse(s))}return new mn(n)},su=ln("node_env")==="development";class Gt{constructor(t){this.arr=t,su&&lr(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Gt(this.arr)}splice(t){const n=new Gt(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const i=this.arr.length;t.writeLen(i-n);for(let s=n;s<i;s++){const r=this.arr[s];t.writeAny(r)}}getRef(){return 8}}const ru=e=>{const t=e.readLen(),n=[];for(let i=0;i<t;i++)n.push(e.readAny());return new Gt(n)};class St{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new St(this.str)}splice(t){const n=new St(this.str.slice(t));this.str=this.str.slice(0,t);const i=this.str.charCodeAt(t-1);return i>=55296&&i<=56319&&(this.str=this.str.slice(0,t-1)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(t){return this.str+=t.str,!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}}const ou=e=>new St(e.readString()),lu=[Ph,zh,Kh,Wh,qh,Yh,Jh],cu=0,au=1,hu=2,uu=3,du=4,fu=5,pu=6;class vt{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new vt(this.type._copy())}splice(t){throw pt()}mergeWith(t){return!1}integrate(t,n){this.type._integrate(t.doc,n)}delete(t){let n=this.type._start;for(;n!==null;)n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t),n=n.right;this.type._map.forEach(i=>{i.deleted?i.id.clock<(t.beforeState.get(i.id.client)||0)&&t._mergeStructs.push(i):i.delete(t)}),t.changed.delete(this.type)}gc(t){let n=this.type._start;for(;n!==null;)n.gc(t,!0),n=n.right;this.type._start=null,this.type._map.forEach(i=>{for(;i!==null;)i.gc(t,!0),i=i.left}),this.type._map=new Map}write(t,n){this.type._write(t)}getRef(){return 7}}const gu=e=>new vt(lu[e.readTypeRef()](e)),bi=(e,t)=>{let n=t,i=0,s;do i>0&&(n=T(n.client,n.clock+i)),s=ie(e,n),i=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof R);return{item:s,diff:i}},Gi=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},xn=(e,t,n)=>{const{client:i,clock:s}=t.id,r=new R(T(i,s+n),t,T(i,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&r.markDeleted(),t.keep&&(r.keep=!0),t.redone!==null&&(r.redone=T(t.redone.client,t.redone.clock+n)),t.right=r,r.right!==null&&(r.right.left=r),e._mergeStructs.push(r),r.parentSub!==null&&r.right===null&&r.parent._map.set(r.parentSub,r),t.length=n,r},As=(e,t)=>Di(e,n=>pe(n.deletions,t)),co=(e,t,n,i,s,r)=>{const o=e.doc,l=o.store,c=o.clientID,a=t.redone;if(a!==null)return lt(e,a);let u=t.parent._item,h=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||co(e,u,n,i,s,r)===null))return null;for(;u.redone!==null;)u=lt(e,u.redone)}const p=u===null?t.parent:u.content.type;if(t.parentSub===null){for(h=t.left,f=t;h!==null;){let y=h;for(;y!==null&&y.parent._item!==u;)y=y.redone===null?null:lt(e,y.redone);if(y!==null&&y.parent._item===u){h=y;break}h=h.left}for(;f!==null;){let y=f;for(;y!==null&&y.parent._item!==u;)y=y.redone===null?null:lt(e,y.redone);if(y!==null&&y.parent._item===u){f=y;break}f=f.right}}else{if(f=null,t.right&&!s){for(h=t;h!==null&&h.right!==null&&(h.right.redone||pe(i,h.right.id)||As(r.undoStack,h.right.id)||As(r.redoStack,h.right.id));)for(h=h.right;h.redone;)h=lt(e,h.redone);if(h&&h.right!==null)return null}else h=p._map.get(t.parentSub)||null;h!==null&&h.parent._item!==u&&(h=p._map.get(t.parentSub)||null)}const g=$(l,c),x=T(c,g),b=new R(x,h,h&&h.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=x,Gi(b,!0),b.integrate(e,0),b};class R extends Wi{constructor(t,n,i,s,r,o,l,c){super(t,c.getLength()),this.origin=i,this.left=n,this.right=s,this.rightOrigin=r,this.parent=o,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?is:0}set marker(t){(this.info&qn)>0!==t&&(this.info^=qn)}get marker(){return(this.info&qn)>0}get keep(){return(this.info&ns)>0}set keep(t){this.keep!==t&&(this.info^=ns)}get countable(){return(this.info&is)>0}get deleted(){return(this.info&Kn)>0}set deleted(t){this.deleted!==t&&(this.info^=Kn)}markDeleted(){this.info|=Kn}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=$(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=$(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ne&&this.id.client!==this.parent.client&&this.parent.clock>=$(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=bs(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=lt(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===dt||this.right&&this.right.constructor===dt)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===R?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===R&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===ne){const i=ie(n,this.parent);i.constructor===dt?this.parent=null:this.parent=i.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=bs(t,t.doc.store,T(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let i=this.left,s;if(i!==null)s=i.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;const r=new Set,o=new Set;for(;s!==null&&s!==this.right;){if(o.add(s),r.add(s),Ve(this.origin,s.origin)){if(s.id.client<this.id.client)i=s,r.clear();else if(Ve(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&o.has(ie(t.doc.store,s.origin)))r.has(ie(t.doc.store,s.origin))||(i=s,r.clear());else break;s=s.right}this.left=i}if(this.left!==null){const i=this.left.right;this.right=i,this.left.right=this}else{let i;if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start,this.parent._start=this;this.right=i}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),zr(t.doc.store,this),this.content.integrate(t,this),Ss(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new dt(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;t!==null&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;t!==null&&t.deleted;)t=t.left;return t}get lastId(){return this.length===1?this.id:T(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Ve(t.origin,this.lastId)&&this.right===t&&Ve(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const n=this.parent._searchMarker;return n&&n.forEach(i=>{i.p===t&&(i.p=this,!this.deleted&&this.countable&&(i.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),De(t.deleteSet,this.id.client,this.id.clock,this.length),Ss(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw rt();this.content.gc(t),n?yh(t,this,new dt(this.id,this.length)):this.content=new Re(this.length)}write(t,n){const i=n>0?T(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,r=this.parentSub,o=this.content.getRef()&vn|(i===null?0:st)|(s===null?0:It)|(r===null?0:Ce);if(t.writeInfo(o),i!==null&&t.writeLeftID(i),s!==null&&t.writeRightID(s),i===null&&s===null){const l=this.parent;if(l._item!==void 0){const c=l._item;if(c===null){const a=Ae(l);t.writeParentInfo(!0),t.writeString(a)}else t.writeParentInfo(!1),t.writeLeftID(c.id)}else l.constructor===String?(t.writeParentInfo(!0),t.writeString(l)):l.constructor===ne?(t.writeParentInfo(!1),t.writeLeftID(l)):rt();r!==null&&t.writeString(r)}this.content.write(t,n)}}const ao=(e,t)=>mu[t&vn](e),mu=[()=>{rt()},Qh,iu,Zh,ou,eu,nu,gu,ru,tu,()=>{rt()}],xu=10;class gt extends Wi{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){rt()}write(t,n){t.writeInfo(xu),A(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const ho=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},uo="__ $YJS$ __";ho[uo]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");ho[uo]=!0;const wu=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}};function fo(e,t,n){for(let i=0;;i++){if(i==e.childCount||i==t.childCount)return e.childCount==t.childCount?null:n;let s=e.child(i),r=t.child(i);if(s==r){n+=s.nodeSize;continue}if(!s.sameMarkup(r))return n;if(s.isText&&s.text!=r.text){for(let o=0;s.text[o]==r.text[o];o++)n++;return n}if(s.content.size||r.content.size){let o=fo(s.content,r.content,n+1);if(o!=null)return o}n+=s.nodeSize}}function po(e,t,n,i){for(let s=e.childCount,r=t.childCount;;){if(s==0||r==0)return s==r?null:{a:n,b:i};let o=e.child(--s),l=t.child(--r),c=o.nodeSize;if(o==l){n-=c,i-=c;continue}if(!o.sameMarkup(l))return{a:n,b:i};if(o.isText&&o.text!=l.text){let a=0,u=Math.min(o.text.length,l.text.length);for(;a<u&&o.text[o.text.length-a-1]==l.text[l.text.length-a-1];)a++,n--,i--;return{a:n,b:i}}if(o.content.size||l.content.size){let a=po(o.content,l.content,n-1,i-1);if(a)return a}n-=c,i-=c}}class L{constructor(t,n){if(this.content=t,this.size=n||0,n==null)for(let i=0;i<t.length;i++)this.size+=t[i].nodeSize}nodesBetween(t,n,i,s=0,r){for(let o=0,l=0;l<n;o++){let c=this.content[o],a=l+c.nodeSize;if(a>t&&i(c,s+l,r||null,o)!==!1&&c.content.size){let u=l+1;c.nodesBetween(Math.max(0,t-u),Math.min(c.content.size,n-u),i,s+u)}l=a}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,n,i,s){let r="",o=!0;return this.nodesBetween(t,n,(l,c)=>{let a=l.isText?l.text.slice(Math.max(t,c)-c,n-c):l.isLeaf?s?typeof s=="function"?s(l):s:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&a||l.isTextblock)&&i&&(o?o=!1:r+=i),r+=a},0),r}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,i=t.firstChild,s=this.content.slice(),r=0;for(n.isText&&n.sameMarkup(i)&&(s[s.length-1]=n.withText(n.text+i.text),r=1);r<t.content.length;r++)s.push(t.content[r]);return new L(s,this.size+t.size)}cut(t,n=this.size){if(t==0&&n==this.size)return this;let i=[],s=0;if(n>t)for(let r=0,o=0;o<n;r++){let l=this.content[r],c=o+l.nodeSize;c>t&&((o<t||c>n)&&(l.isText?l=l.cut(Math.max(0,t-o),Math.min(l.text.length,n-o)):l=l.cut(Math.max(0,t-o-1),Math.min(l.content.size,n-o-1))),i.push(l),s+=l.nodeSize),o=c}return new L(i,s)}cutByIndex(t,n){return t==n?L.empty:t==0&&n==this.content.length?this:new L(this.content.slice(t,n))}replaceChild(t,n){let i=this.content[t];if(i==n)return this;let s=this.content.slice(),r=this.size+n.nodeSize-i.nodeSize;return s[t]=n,new L(s,r)}addToStart(t){return new L([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new L(this.content.concat(t),this.size+t.nodeSize)}eq(t){if(this.content.length!=t.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(t.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(t){let n=this.content[t];if(!n)throw new RangeError("Index "+t+" out of range for "+this);return n}maybeChild(t){return this.content[t]||null}forEach(t){for(let n=0,i=0;n<this.content.length;n++){let s=this.content[n];t(s,i,n),i+=s.nodeSize}}findDiffStart(t,n=0){return fo(this,t,n)}findDiffEnd(t,n=this.size,i=t.size){return po(this,t,n,i)}findIndex(t){if(t==0)return qe(0,t);if(t==this.size)return qe(this.content.length,t);if(t>this.size||t<0)throw new RangeError(`Position ${t} outside of fragment (${this})`);for(let n=0,i=0;;n++){let s=this.child(n),r=i+s.nodeSize;if(r>=t)return r==t?qe(n+1,r):qe(n,i);i=r}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(t=>t.toJSON()):null}static fromJSON(t,n){if(!n)return L.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new L(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return L.empty;let n,i=0;for(let s=0;s<t.length;s++){let r=t[s];i+=r.nodeSize,s&&r.isText&&t[s-1].sameMarkup(r)?(n||(n=t.slice(0,s)),n[n.length-1]=r.withText(n[n.length-1].text+r.text)):n&&n.push(r)}return new L(n||t,i)}static from(t){if(!t)return L.empty;if(t instanceof L)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new L([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}L.empty=new L([],0);const ni={index:0,offset:0};function qe(e,t){return ni.index=e,ni.offset=t,ni}class ft{constructor(t,n,i){this.content=t,this.openStart=n,this.openEnd=i}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let i=mo(this.content,t+this.openStart,n);return i&&new ft(i,this.openStart,this.openEnd)}removeBetween(t,n){return new ft(go(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(t){return this.content.eq(t.content)&&this.openStart==t.openStart&&this.openEnd==t.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let t={content:this.content.toJSON()};return this.openStart>0&&(t.openStart=this.openStart),this.openEnd>0&&(t.openEnd=this.openEnd),t}static fromJSON(t,n){if(!n)return ft.empty;let i=n.openStart||0,s=n.openEnd||0;if(typeof i!="number"||typeof s!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new ft(L.fromJSON(t,n.content),i,s)}static maxOpen(t,n=!0){let i=0,s=0;for(let r=t.firstChild;r&&!r.isLeaf&&(n||!r.type.spec.isolating);r=r.firstChild)i++;for(let r=t.lastChild;r&&!r.isLeaf&&(n||!r.type.spec.isolating);r=r.lastChild)s++;return new ft(t,i,s)}}ft.empty=new ft(L.empty,0,0);function go(e,t,n){let{index:i,offset:s}=e.findIndex(t),r=e.maybeChild(i),{index:o,offset:l}=e.findIndex(n);if(s==t||r.isText){if(l!=n&&!e.child(o).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(i!=o)throw new RangeError("Removing non-flat range");return e.replaceChild(i,r.copy(go(r.content,t-s-1,n-s-1)))}function mo(e,t,n,i){let{index:s,offset:r}=e.findIndex(t),o=e.maybeChild(s);if(r==t||o.isText)return i&&!i.canReplace(s,s,n)?null:e.cut(0,t).append(n).append(e.cut(t));let l=mo(o.content,t-r-1,n,o);return l&&e.replaceChild(s,o.copy(l))}const bu=/[\uD800-\uDBFF]/,yu=/[\uDC00-\uDFFF]/,Su=(e,t)=>{let n=0,i=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&bu.test(e[n-1])&&n--;i+n<e.length&&i+n<t.length&&e[e.length-i-1]===t[t.length-i-1];)i++;return i>0&&yu.test(e[e.length-i])&&i--,{index:n,remove:e.length-n-i,insert:t.slice(n,t.length-i)}},vu=Su,Tt=(e,t)=>e>>>t|e<<32-t,Cu=e=>Tt(e,2)^Tt(e,13)^Tt(e,22),ku=e=>Tt(e,6)^Tt(e,11)^Tt(e,25),Eu=e=>Tt(e,7)^Tt(e,18)^e>>>3,Tu=e=>Tt(e,17)^Tt(e,19)^e>>>10,_u=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Du=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class Au{constructor(){const t=new ArrayBuffer(320);this._H=new Uint32Array(t,0,8),this._H.set(Du),this._W=new Uint32Array(t,64,64)}_updateHash(){const t=this._H,n=this._W;for(let h=16;h<64;h++)n[h]=Tu(n[h-2])+n[h-7]+Eu(n[h-15])+n[h-16];let i=t[0],s=t[1],r=t[2],o=t[3],l=t[4],c=t[5],a=t[6],u=t[7];for(let h=0,f,p;h<64;h++)f=u+ku(l)+(l&c^~l&a)+_u[h]+n[h]>>>0,p=Cu(i)+(i&s^i&r^s&r)>>>0,u=a,a=c,c=l,l=o+f>>>0,o=r,r=s,s=i,i=f+p>>>0;t[0]+=i,t[1]+=s,t[2]+=r,t[3]+=o,t[4]+=l,t[5]+=c,t[6]+=a,t[7]+=u}digest(t){let n=0;for(;n+56<=t.length;){let o=0;for(;o<16&&n+3<t.length;o++)this._W[o]=t[n++]<<24|t[n++]<<16|t[n++]<<8|t[n++];if(n%64!==0){for(this._W.fill(0,o,16);n<t.length;)this._W[o]|=t[n]<<(3-n%4)*8,n++;this._W[o]|=st<<(3-n%4)*8}this._updateHash()}const i=n%64!==0;this._W.fill(0,0,16);let s=0;for(;n<t.length;s++)for(let o=3;o>=0&&n<t.length;o--)this._W[s]|=t[n++]<<o*8;i||(this._W[s-(n%4===0?0:1)]|=st<<(3-n%4)*8),this._W[14]=t.byteLength/cc,this._W[15]=t.byteLength*8,this._updateHash();const r=new Uint8Array(32);for(let o=0;o<this._H.length;o++)for(let l=0;l<4;l++)r[o*4+l]=this._H[o]>>>(3-l)*8;return r}}const Iu=e=>new Au().digest(e),B=new O.PluginKey("y-sync"),Mt=new O.PluginKey("y-undo");new O.PluginKey("yjs-cursor");const Mu=e=>{for(let n=6;n<e.length;n++)e[n%6]=e[n%6]^e[n];return e.slice(0,6)},Ou=e=>la(Mu(Iu(ca(e)))),wn=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!pe(t.ds,e.id),Ru=[{light:"#ecd44433",dark:"#ecd444"}],ju=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){const i=Kt();e.forEach(s=>i.add(s)),t=t.filter(s=>!i.has(s))}e.set(n,$c(t))}return e.get(n)},Nu=(e,{colors:t=Ru,colorMapping:n=new Map,permanentUserData:i=null,onFirstRender:s=()=>{},mapping:r}={})=>{let o=!1;const l=new Uu(e,r),c=new O.Plugin({props:{editable:a=>{const u=B.getState(a);return u.snapshot==null&&u.prevSnapshot==null}},key:B,state:{init:(a,u)=>({type:e,doc:e.doc,binding:l,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:t,colorMapping:n,permanentUserData:i}),apply:(a,u)=>{const h=a.getMeta(B);if(h!==void 0){u=Object.assign({},u);for(const f in h)u[f]=h[f]}return u.addToHistory=a.getMeta("addToHistory")!==!1,u.isChangeOrigin=h!==void 0&&!!h.isChangeOrigin,u.isUndoRedoOperation=h!==void 0&&!!h.isChangeOrigin&&!!h.isUndoRedoOperation,l.prosemirrorView!==null&&h!==void 0&&(h.snapshot!=null||h.prevSnapshot!=null)&&Tr(0,()=>{l.prosemirrorView!=null&&(h.restore==null?l._renderSnapshot(h.snapshot,h.prevSnapshot,u):(l._renderSnapshot(h.snapshot,h.snapshot,u),delete u.restore,delete u.snapshot,delete u.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),u}},view:a=>(l.initView(a),r==null&&l._forceRerender(),s(),{update:()=>{const u=c.getState(a.state);if(u.snapshot==null&&u.prevSnapshot==null&&(o||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(o=!0,u.addToHistory===!1&&!u.isChangeOrigin){const h=Mt.getState(a.state),f=h&&h.undoManager;f&&f.stopCapturing()}l.mux(()=>{u.doc.transact(h=>{h.meta.set("addToHistory",u.addToHistory),l._prosemirrorChanged(a.state.doc)},B)})}},destroy:()=>{l.destroy()}})});return c},Bu=(e,t,n)=>{if(t!==null&&t.anchor!==null&&t.head!==null)if(t.type==="all")e.setSelection(new O.AllSelection(e.doc));else if(t.type==="node"){const i=Vt(n.doc,n.type,t.anchor,n.mapping);i!==null&&e.setSelection(Lu(e,i))}else if(t.type==="nodeRange"){const i=Vt(n.doc,n.type,t.anchor,n.mapping),s=Vt(n.doc,n.type,t.head,n.mapping),r=Pu(e,i,s,t.depth);r!==null&&e.setSelection(r)}else{const i=Vt(n.doc,n.type,t.anchor,n.mapping),s=Vt(n.doc,n.type,t.head,n.mapping);i!==null&&s!==null&&e.setSelection(O.TextSelection.between(e.doc.resolve(i),e.doc.resolve(s)))}},Lu=(e,t)=>{const n=e.doc.resolve(t);return n.nodeAfter?O.NodeSelection.create(e.doc,t):O.TextSelection.near(n)},Pu=(e,t,n,i)=>{if(t===null||n===null)return null;const s=Math.min(Math.max(t,0),e.doc.content.size),r=Math.min(Math.max(n,0),e.doc.content.size);try{const o=O.Selection.fromJSON(e.doc,{type:"nodeRange",anchor:s,head:r,depth:i});return o.ranges.length?o:O.TextSelection.near(e.doc.resolve(s))}catch{return O.TextSelection.near(e.doc.resolve(s))}},yi=(e,t)=>{const n=t.selection.jsonID;return{type:n,depth:n==="nodeRange"?t.selection.depth:void 0,anchor:yn(t.selection.anchor,e.type,e.mapping),head:yn(t.selection.head,e.type,e.mapping)}};class Uu{constructor(t,n=new Map){this.type=t,this.prosemirrorView=null,this.mux=wu(),this.mapping=n,this.isOMark=new Map,this._observeFunction=this._typeChanged.bind(this),this.doc=t.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=yi(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return this.prosemirrorView.hasFocus()?(cr&&this._domSelectionInView===null&&(Tr(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){const t=this.prosemirrorView._root.getSelection();if(t==null||t.anchorNode==null)return!1;const n=this.prosemirrorView._root.createRange();n.setStart(t.anchorNode,t.anchorOffset),n.setEnd(t.focusNode,t.focusOffset),n.getClientRects().length===0&&n.startContainer&&n.collapsed&&n.selectNodeContents(n.startContainer);const s=n.getBoundingClientRect(),r=Le.documentElement;return s.bottom>=0&&s.right>=0&&s.left<=(window.innerWidth||r.clientWidth||0)&&s.top<=(window.innerHeight||r.clientHeight||0)}renderSnapshot(t,n){n||(n=Pr(jr(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(B,{snapshot:t,prevSnapshot:n}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{const t=this.type.toArray().map(i=>tn(i,this.prosemirrorView.state.schema,this)).filter(i=>i!==null),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new ft(L.from(t),0,0));n.setMeta(B,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(n)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{const t=this.beforeTransactionSelection!==null?null:this.prosemirrorView.state.selection,n=this.type.toArray().map(s=>tn(s,this.prosemirrorView.state.schema,this)).filter(s=>s!==null),i=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new ft(L.from(n),0,0));if(t){const s=oe(Bt(t.anchor,0),i.doc.content.size),r=oe(Bt(t.head,0),i.doc.content.size);i.setSelection(O.TextSelection.create(i.doc,s,r))}this.prosemirrorView.dispatch(i.setMeta(B,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(t,n,i){let s=this.doc,r=this.type;if(t||(t=Qn(this.doc)),t instanceof Uint8Array||n instanceof Uint8Array)if((!(t instanceof Uint8Array)||!(n instanceof Uint8Array))&&rt(),s=new Jt({gc:!1}),gi(s,n),n=Qn(s),gi(s,t),t=Qn(s),r._item===null){const o=Array.from(this.doc.share.keys()).find(l=>this.doc.share.get(l)===this.type);r=s.getXmlFragment(o)}else{const o=s.store.clients.get(r._item.id.client)??[],l=yt(o,r._item.id.clock);r=o[l].content.type}this.mapping.clear(),this.mux(()=>{s.transact(o=>{const l=i.permanentUserData;l&&l.dss.forEach(h=>{Lt(o,h,f=>{})});const c=(h,f)=>{const p=h==="added"?l.getUserByClientId(f.client):l.getUserByDeletedId(f);return{user:p,type:h,color:ju(i.colorMapping,i.colors,p)}},a=Yr(r,new Fi(n.ds,t.sv)).map(h=>!h._item.deleted||wn(h._item,t)||wn(h._item,n)?tn(h,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},t,n,c):null).filter(h=>h!==null),u=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new ft(L.from(a),0,0));this.prosemirrorView.dispatch(u.setMeta(B,{isChangeOrigin:!0}))},B)})}_typeChanged(t,n){if(this.prosemirrorView==null)return;const i=B.getState(this.prosemirrorView.state);if(t.length===0||i.snapshot!=null||i.prevSnapshot!=null){this.renderSnapshot(i.snapshot,i.prevSnapshot);return}this.mux(()=>{const s=(l,c)=>this.mapping.delete(c);Lt(n,n.deleteSet,l=>{if(l.constructor===R){const c=l.content.type;c&&this.mapping.delete(c)}}),n.changed.forEach(s),n.changedParentTypes.forEach(s);const r=this.type.toArray().map(l=>xo(l,this.prosemirrorView.state.schema,this)).filter(l=>l!==null);let o=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new ft(L.from(r),0,0));Bu(o,this.beforeTransactionSelection,this),o=o.setMeta(B,{isChangeOrigin:!0,isUndoRedoOperation:n.origin instanceof Fr}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)})}_prosemirrorChanged(t){this.doc.transact(()=>{vi(this.doc,this.type,t,this),this.beforeTransactionSelection=yi(this,this.prosemirrorView.state)},B)}initView(t){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=t,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}}const xo=(e,t,n,i,s,r)=>{const o=n.mapping.get(e);if(o===void 0){if(e instanceof it)return tn(e,t,n,i,s,r);throw pt()}return o},tn=(e,t,n,i,s,r)=>{const o=[],l=c=>{var a,u;if(c instanceof it){const h=xo(c,t,n,i,s,r);h!==null&&o.push(h)}else{const h=(u=(a=c._item.right)==null?void 0:a.content)==null?void 0:u.type;h instanceof Pt&&!h._item.deleted&&h._item.id.client===h.doc.clientID&&(c.applyDelta([{retain:c.length},...h.toDelta()]),h.doc.transact(p=>{h._item.delete(p)}));const f=zu(c,t,n,i,s,r);f!==null&&f.forEach(p=>{p!==null&&o.push(p)})}};i===void 0||s===void 0?e.toArray().forEach(l):Yr(e,new Fi(s.ds,i.sv)).forEach(l);try{const c=e.getAttributes(i);i!==void 0&&(wn(e._item,i)?wn(e._item,s)||(c.ychange=r?r("added",e._item.id):{type:"added"}):c.ychange=r?r("removed",e._item.id):{type:"removed"});const a=t.node(e.nodeName,c,o);return n.mapping.set(e,a),a}catch{return e.doc.transact(a=>{e._item.delete(a)},B),n.mapping.delete(e),null}},zu=(e,t,n,i,s,r)=>{const o=[],l=e.toDelta(i,s,r);try{for(let c=0;c<l.length;c++){const a=l[c];o.push(t.text(a.insert,qu(a.attributes,t)))}}catch{return e.doc.transact(a=>{e._item.delete(a)},B),null}return o},$u=(e,t)=>{const n=new at,i=e.map(s=>({insert:s.text,attributes:yo(s.marks,t)}));return n.applyDelta(i),t.mapping.set(n,e),n},Vu=(e,t)=>{const n=new it(e.type.name);for(const i in e.attrs){const s=e.attrs[i];s!==null&&i!=="ychange"&&n.setAttribute(i,s)}return n.insert(0,Bn(e).map(i=>Si(i,t))),t.mapping.set(n,e),n},Si=(e,t)=>e instanceof Array?$u(e,t):Vu(e,t),Is=e=>typeof e=="object"&&e!==null,Yi=(e,t)=>{const n=Object.keys(e).filter(s=>e[s]!==null);let i=n.length===Object.keys(t).filter(s=>t[s]!==null).length;for(let s=0;s<n.length&&i;s++){const r=n[s],o=e[r],l=t[r];i=r==="ychange"||o===l||Is(o)&&Is(l)&&Yi(o,l)}return i},Bn=e=>{const t=e.content.content,n=[];for(let i=0;i<t.length;i++){const s=t[i];if(s.isText){const r=[];for(let o=t[i];i<t.length&&o.isText;o=t[++i])r.push(o);i--,n.push(r)}else n.push(s)}return n},wo=(e,t)=>{const n=e.toDelta();return n.length===t.length&&n.every((i,s)=>i.insert===t[s].text&&or(i.attributes||{}).length===t[s].marks.length&&ue(i.attributes,(r,o)=>{var u;const l=bo(o),c=t[s].marks;return c.find(h=>h.type.name===l)?Yi(r,(u=c.find(h=>h.type.name===l))==null?void 0:u.attrs):!1}))},je=(e,t)=>{if(e instanceof it&&!(t instanceof Array)&&Ci(e,t)){const n=Bn(t);return e._length===n.length&&Yi(e.getAttributes(),t.attrs)&&e.toArray().every((i,s)=>je(i,n[s]))}return e instanceof at&&t instanceof Array&&wo(e,t)},bn=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((n,i)=>t[i]===n),Ms=(e,t,n)=>{const i=e.toArray(),s=Bn(t),r=s.length,o=i.length,l=oe(o,r);let c=0,a=0,u=!1;for(;c<l;c++){const h=i[c],f=s[c];if(bn(n.mapping.get(h),f))u=!0;else if(!je(h,f))break}for(;c+a<l;a++){const h=i[o-a-1],f=s[r-a-1];if(bn(n.mapping.get(h),f))u=!0;else if(!je(h,f))break}return{equalityFactor:c+a,foundMappedChild:u}},Fu=e=>{let t="",n=e._start;const i={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof St?t+=n.content.str:n.content instanceof F&&(i[n.content.key]=null)),n=n.right;return{str:t,nAttrs:i}},Hu=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:i,str:s}=Fu(e),r=t.map(a=>({insert:a.text,attributes:Object.assign({},i,yo(a.marks,n))})),{insert:o,remove:l,index:c}=vu(s,r.map(a=>a.insert).join(""));e.delete(c,l),e.insert(c,o),e.applyDelta(r.map(a=>({retain:a.insert.length,attributes:a.attributes})))},Ku=/(.*)(--[a-zA-Z0-9+/=]{8})$/,bo=e=>{var t;return((t=Ku.exec(e))==null?void 0:t[1])??e},qu=(e,t)=>{const n=[];for(const i in e)n.push(t.mark(bo(i),e[i]));return n},yo=(e,t)=>{const n={};return e.forEach(i=>{if(i.type.name!=="ychange"){const s=Ot(t.isOMark,i.type,()=>!i.type.excludes(i.type));n[s?`${i.type.name}--${Ou(i.toJSON())}`:i.type.name]=i.attrs}}),n},vi=(e,t,n,i)=>{if(t instanceof it&&t.nodeName!==n.type.name)throw new Error("node name mismatch!");if(i.mapping.set(t,n),t instanceof it){const h=t.getAttributes(),f=n.attrs;for(const p in f)f[p]!==null?h[p]!==f[p]&&p!=="ychange"&&t.setAttribute(p,f[p]):t.removeAttribute(p);for(const p in h)f[p]===void 0&&t.removeAttribute(p)}const s=Bn(n),r=s.length,o=t.toArray(),l=o.length,c=oe(r,l);let a=0,u=0;for(;a<c;a++){const h=o[a],f=s[a];if(!bn(i.mapping.get(h),f))if(je(h,f))i.mapping.set(h,f);else break}for(;u+a+1<c;u++){const h=o[l-u-1],f=s[r-u-1];if(!bn(i.mapping.get(h),f))if(je(h,f))i.mapping.set(h,f);else break}e.transact(()=>{for(;l-a-u>0&&r-a-u>0;){const f=o[a],p=s[a],g=o[l-u-1],x=s[r-u-1];if(f instanceof at&&p instanceof Array)wo(f,p)||Hu(f,p,i),a+=1;else{let b=f instanceof it&&Ci(f,p),y=g instanceof it&&Ci(g,x);if(b&&y){const C=Ms(f,p,i),S=Ms(g,x,i);C.foundMappedChild&&!S.foundMappedChild?y=!1:!C.foundMappedChild&&S.foundMappedChild||C.equalityFactor<S.equalityFactor?b=!1:y=!1}b?(vi(e,f,p,i),a+=1):y?(vi(e,g,x,i),u+=1):(i.mapping.delete(t.get(a)),t.delete(a,1),t.insert(a,[Si(p,i)]),a+=1)}}const h=l-a-u;if(l===1&&r===0&&o[0]instanceof at?(i.mapping.delete(o[0]),o[0].delete(0,o[0].length)):h>0&&(t.slice(a,a+h).forEach(f=>i.mapping.delete(f)),t.delete(a,h)),a+u<r){const f=[];for(let p=a;p<r-u;p++)f.push(Si(s[p],i));t.insert(a,f)}},B)},Ci=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,yn=(e,t,n)=>{if(e===0)return Zn(t,0,-1);let i=t._first===null?null:t._first.content.type;for(;i!==null&&t!==i;){if(i instanceof at){if(i._length>=e)return Zn(i,e,-1);if(e-=i._length,i._item!==null&&i._item.next!==null)i=i._item.next.content.type;else{do i=i._item===null?null:i._item.parent,e--;while(i!==t&&i!==null&&i._item!==null&&i._item.next===null);i!==null&&i!==t&&(i=i._item===null?null:i._item.next.content.type)}}else{const s=(n.get(i)||{nodeSize:0}).nodeSize;if(i._first!==null&&e<s)i=i._first.content.type,e--;else{if(e===1&&i._length===0&&s>1)return new dn(i._item===null?null:i._item.id,i._item===null?Ae(i):null,null);if(e-=s,i._item!==null&&i._item.next!==null)i=i._item.next.content.type;else{if(e===0)return i=i._item===null?i:i._item.parent,new dn(i._item===null?null:i._item.id,i._item===null?Ae(i):null,null);do i=i._item.parent,e--;while(i!==t&&i._item.next===null);i!==t&&(i=i._item.next.content.type)}}}if(i===null)throw rt();if(e===0&&i.constructor!==at&&i!==t)return Wu(i._item.parent,i._item)}return Zn(t,t._length,-1)},Wu=(e,t)=>{let n=null,i=null;return e._item===null?i=Ae(e):n=T(e._item.id.client,e._item.id.clock),new dn(n,i,t.id)},Vt=(e,t,n,i)=>{const s=wh(n,e);if(s===null||s.type!==t&&!Ie(t,s.type._item))return null;let r=s.type,o=0;if(r.constructor===at)o=s.index;else if(r._item===null||!r._item.deleted){let l=r._first,c=0;for(;c<r._length&&c<s.index&&l!==null;){if(!l.deleted){const a=l.content.type;if(c++,a instanceof at)o+=a._length;else{const u=i.get(a);if(u==null)return null;o+=u.nodeSize}}l=l.right}o+=1}for(;r!==t&&r._item!==null;){const l=r._item.parent;if(l._item===null||!l._item.deleted){o+=1;let c=l._first;for(;c!==null;){const a=c.content.type;if(a===r)break;if(!c.deleted)if(a instanceof at)o+=a._length;else{const u=i.get(a);if(u==null)return null;o+=u.nodeSize}c=c.right}}r=l}return o-1},Gu=e=>{const t=Mt.getState(e).undoManager;if(t!=null)return t.undo(),!0},Yu=e=>{const t=Mt.getState(e).undoManager;if(t!=null)return t.redo(),!0},Ju=new Set(["paragraph"]),Xu=(e,t)=>!(e instanceof R)||!(e.content instanceof vt)||!(e.content.type instanceof Pt||e.content.type instanceof it&&t.has(e.content.type.nodeName))||e.content.type._length===0,Zu=({protectedNodes:e=Ju,trackedOrigins:t=[],undoManager:n=null}={})=>new O.Plugin({key:Mt,state:{init:(i,s)=>{const r=B.getState(s);let o=n;if(!o){const l=r.doc,c=new Set(l?l._observers.get("destroy"):[]);o=new Fr(r.type,{trackedOrigins:new Set([B].concat(t)),deleteFilter:u=>Xu(u,e),captureTransaction:u=>u.meta.get("addToHistory")!==!1});const a=l?l._observers.get("destroy"):new Set;o._yTiptapDocDestroyListeners=Array.from(a||[]).filter(u=>!c.has(u))}return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(i,s,r,o)=>{const l=B.getState(o).binding,c=s.undoManager,a=c.undoStack.length>0,u=c.redoStack.length>0;return l?{undoManager:c,prevSel:yi(l,r),hasUndoOps:a,hasRedoOps:u}:a!==s.hasUndoOps||u!==s.hasRedoOps?Object.assign({},s,{hasUndoOps:c.undoStack.length>0,hasRedoOps:c.redoStack.length>0}):s}},view:i=>{const s=B.getState(i.state),r=Mt.getState(i.state).undoManager;return r.on("stack-item-added",({stackItem:o})=>{const l=s.binding;l&&o.meta.set(l,Mt.getState(i.state).prevSel)}),r.on("stack-item-popped",({stackItem:o})=>{const l=s.binding;l&&(l.beforeTransactionSelection=o.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{r.destroy();const o=r._yTiptapDocDestroyListeners;o&&r.doc&&(o.forEach(l=>r.doc.off("destroy",l)),r._yTiptapDocDestroyListeners=null)}}}});function Ji(e){return!!e.getMeta(B)}function Qu(e,t){const n=B.getState(e);return Vt(n.doc,n.type,t,n.binding.mapping)||0}function So(e,t){const n=B.getState(e);return yn(t,n.type,n.binding.mapping)}var en=class vo extends O.MappablePosition{constructor(t,n){super(t),this.yRelativePosition=n}static fromJSON(t){return new vo(t.position,t.yRelativePosition)}toJSON(){return{position:this.position,yRelativePosition:this.yRelativePosition}}};function td(e,t){const n=So(t,e);return new en(e,n)}function ed(e,t,n){const i=e instanceof en?e.yRelativePosition:null;if(Ji(t)&&i){const o=Qu(n,i);return{position:new en(o,i),mapResult:null}}const s=O.getUpdatedPosition(e,t),r=s.position.position;return{position:new en(r,i??So(n,r)),mapResult:s.mapResult}}O.Extension.create({name:"collaboration",priority:1e3,addOptions(){return{document:null,field:"default",fragment:null,provider:null}},addStorage(){return{isDisabled:!1}},onCreate(){this.editor.extensionManager.extensions.find(e=>e.name==="undoRedo")&&console.warn('[tiptap warn]: "@tiptap/extension-collaboration" comes with its own history support and is not compatible with "@tiptap/extension-undo-redo".')},onBeforeCreate(){this.editor.utils.getUpdatedPosition=(e,t)=>ed(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>td(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),Mt.getState(t).undoManager.undoStack.length===0?!1:n?Gu(t):!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),Mt.getState(t).undoManager.redoStack.length===0?!1:n?Yu(t):!0)}},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo()}},addProseMirrorPlugins(){const e=this.options.fragment?this.options.fragment:this.options.document.getXmlFragment(this.options.field),t=Zu(this.options.yUndoOptions),n=t.spec.view;t.spec.view=r=>{const{undoManager:o}=Mt.getState(r.state);o.restore&&(o.restore(),o.restore=()=>{});const l=n?n(r):void 0;return{destroy:()=>{const c=o.trackedOrigins.has(o),a=o._observers;o.restore=()=>{c&&o.trackedOrigins.add(o),o.doc.on("afterTransaction",o.afterTransactionHandler),o._observers=a},l!=null&&l.destroy&&l.destroy()}}};const i={...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender};return[Nu(e,i),t,this.editor.options.enableContentCheck&&new G.Plugin({key:new G.PluginKey("filterInvalidContent"),filterTransaction:r=>{if(!Ji(r))return!0;if(this.storage.isDisabled)return!1;if(!r.docChanged)return!0;try{return r.doc.check(),!0}catch(o){return this.storage.isDisabled=!0,this.editor.emit("contentError",{error:o,editor:this.editor,disableCollaboration:()=>{var l;(l=e.doc)==null||l.destroy()}}),!0}}})].filter(Boolean)}});function Os(e){if(!e.length)return $n.DecorationSet.empty;const t=[],n=e[0].$from.node(0);return e.forEach(i=>{const s=i.$from.pos,r=i.$from.nodeAfter;r&&t.push($n.Decoration.node(s,s+r.nodeSize,{class:"ProseMirror-selectednoderange"}))}),$n.DecorationSet.create(n,t)}function nd(e,t,n){const i=n.isText||n.isAtom?0:1;return{start:e+i,end:e+t-i}}function Ln(e,t,n,i={}){const s=[],r=e.node(0),{extendOnBoundaryOverlap:o=!0}=i;typeof n=="number"&&n>=0||(e.sameParent(t)?n=Math.max(0,e.sharedDepth(t.pos)-1):n=e.sharedDepth(t.pos));const l=new zo.NodeRange(e,t,n),c=l.depth===0?0:r.resolve(l.start).posAtIndex(0);return l.parent.forEach((a,u)=>{const h=c+u,f=h+a.nodeSize,p=nd(h,a.nodeSize,a),g=o?t.pos>=p.start&&e.pos<=p.end:t.pos>p.start&&e.pos<p.end;if(h<l.start||h>=l.end||!g)return;const x=new G.SelectionRange(r.resolve(h),r.resolve(f));s.push(x)}),s}var id=class Co{constructor(t,n,i){this.anchor=t,this.head=n,this.depth=i??0}map(t){return new Co(t.map(this.anchor),t.map(this.head),this.depth)}resolve(t){const n=t.resolve(this.anchor),i=t.resolve(this.head);return new kt(n,i,this.depth)}},kt=class jt extends G.Selection{constructor(t,n,i,s=1){const{doc:r}=t,o=t===n,l=t.pos===r.content.size&&n.pos===r.content.size,c=o&&!l?r.resolve(n.pos+(s>0?1:-1)):n,a=o&&l?r.resolve(t.pos-(s>0?1:-1)):t,u=Ln(a.min(c),a.max(c),i),h=c.pos>=t.pos?u[0].$from:u[u.length-1].$to,f=c.pos>=t.pos?u[u.length-1].$to:u[0].$from;super(h,f,u),this.depth=i}get $to(){return this.ranges[this.ranges.length-1].$to}eq(t){return t instanceof jt&&t.$from.pos===this.$from.pos&&t.$to.pos===this.$to.pos}map(t,n){const i=t.resolve(n.map(this.anchor)),s=t.resolve(n.map(this.head));return new jt(i,s,this.depth)}toJSON(){return{type:"nodeRange",anchor:this.anchor,head:this.head,depth:this.depth}}get isForwards(){return this.head>=this.anchor}get isBackwards(){return!this.isForwards}extendBackwards(){const{doc:t}=this.$from;if(this.isForwards&&this.ranges.length>1){const s=this.ranges.slice(0,-1),r=s[0].$from,o=s[s.length-1].$to;return new jt(r,o,this.depth)}const n=this.ranges[0],i=t.resolve(Math.max(0,n.$from.pos-1));return new jt(this.$anchor,i,this.depth)}extendForwards(){const{doc:t}=this.$from;if(this.isBackwards&&this.ranges.length>1){const s=this.ranges.slice(1),r=s[0].$from,o=s[s.length-1].$to;return new jt(o,r,this.depth)}const n=this.ranges[this.ranges.length-1],i=t.resolve(Math.min(t.content.size,n.$to.pos+1));return new jt(this.$anchor,i,this.depth)}static fromJSON(t,n){return new jt(t.resolve(n.anchor),t.resolve(n.head),n.depth)}static create(t,n,i,s,r=1){return new this(t.resolve(n),t.resolve(i),s,r)}getBookmark(){return new id(this.anchor,this.head,this.depth)}};kt.prototype.visible=!1;try{G.Selection.jsonID("nodeRange",kt)}catch{}function Se(e){return e instanceof kt}O.Extension.create({name:"nodeRange",addOptions(){return{depth:void 0,key:"Mod"}},addKeyboardShortcuts(){return{"Shift-ArrowUp":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,selection:r,tr:o}=i,{anchor:l,head:c}=r;if(!Se(r)){const u=kt.create(s,l,c,t,-1);return o.setSelection(u),n.dispatch(o),!0}const a=r.extendBackwards();return o.setSelection(a),n.dispatch(o),!0},"Shift-ArrowDown":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,selection:r,tr:o}=i,{anchor:l,head:c}=r;if(!Se(r)){const u=kt.create(s,l,c,t);return o.setSelection(u),n.dispatch(o),!0}const a=r.extendForwards();return o.setSelection(a),n.dispatch(o),!0},"Mod-a":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,tr:r}=i,o=kt.create(s,0,s.content.size,t);return r.setSelection(o),n.dispatch(r),!0}}},onSelectionUpdate(){const{selection:e}=this.editor.state;Se(e)&&this.editor.view.dom.classList.add("ProseMirror-noderangeselection")},addProseMirrorPlugins(){let e=!1,t=!1;return[new G.Plugin({key:new G.PluginKey("nodeRange"),props:{attributes:()=>e?{class:"ProseMirror-noderangeselection"}:{class:""},handleDOMEvents:{mousedown:(n,i)=>{const{key:s}=this.options,r=/Mac/.test(navigator.platform),o=!!i.shiftKey,l=!!i.ctrlKey,c=!!i.altKey,a=!!i.metaKey,u=r?a:l;return(s==null||s==="Shift"&&o||s==="Control"&&l||s==="Alt"&&c||s==="Meta"&&a||s==="Mod"&&u)&&(t=!0),t&&document.addEventListener("mouseup",()=>{t=!1;const{state:h}=n,{doc:f,selection:p,tr:g}=h,{$anchor:x,$head:b}=p;if(x.sameParent(b))return;const y=kt.create(f,x.pos,b.pos,this.options.depth);g.setSelection(y),n.dispatch(g)},{once:!0}),!1}},decorations:n=>{const{selection:i}=n,s=Se(i);if(e=!1,!t)return s?(e=!0,Os(i.ranges)):null;const{$from:r,$to:o}=i;if(!s&&r.sameParent(o))return null;const l=Ln(r,o,this.options.depth);return l.length?(e=!0,Os(l)):null}}})]}});function sd(e,t){const n=getComputedStyle(e);if(t)return t.map(s=>s.trim()).filter(s=>s.length>0).map(s=>`${s}:${n.getPropertyValue(s)};`).join("");let i="";for(let s=0;s<n.length;s+=1)i+=`${n[s]}:${n.getPropertyValue(n[s])};`;return i}function rd(e,t){const n=e.cloneNode(!0),i=[e,...Array.from(e.getElementsByTagName("*"))],s=[n,...Array.from(n.getElementsByTagName("*"))];return i.forEach((r,o)=>{s[o].style.cssText=sd(r,t)}),n}var od={id:"listItemFirstChild",evaluate:({parent:e,isFirst:t})=>t&&e&&["listItem","taskItem"].includes(e.type.name)?1e3:0},ld={id:"listWrapperDeprioritize",evaluate:({node:e})=>{const t=["listItem","taskItem"],n=e.firstChild;return n&&t.includes(n.type.name)?1e3:0}},cd={id:"tableStructure",evaluate:({node:e,parent:t})=>["tableRow","tableCell","tableHeader"].includes(e.type.name)||t&&t.type.name==="tableHeader"?1e3:0},ad={id:"inlineContent",evaluate:({node:e})=>e.isInline||e.isText?1e3:0},hd=[od,ld,cd,ad],Rs={edges:["left","top"],threshold:12,strength:500};function ii(e){return e===void 0||e==="left"?{...Rs}:e==="right"?{edges:["right","top"],threshold:12,strength:500}:e==="both"?{edges:["left","right","top"],threshold:12,strength:500}:e==="none"?{edges:[],threshold:0,strength:0}:{...Rs,...e}}function ud(e,t,n){if(n.edges.length===0)return!1;const i=t.getBoundingClientRect(),{threshold:s,edges:r}=n;return r.some(o=>o==="left"?e.x-i.left<s:o==="right"?i.right-e.x<s:o==="top"?e.y-i.top<s:o==="bottom"?i.bottom-e.y<s:!1)}function dd(e,t,n,i){return!t||n.edges.length===0?0:ud(e,t,n)?n.strength*i:0}var fd=1e3;function js(e,t,n,i){let s=fd,r=!1;if(t.every(l=>{const c=l.evaluate(e);return s-=c,s<=0?(r=!0,!1):!0}),r)return-1;const o=e.view.nodeDOM(e.pos);return s-=dd(i,o,n,e.depth),s<=0?-1:s}function Ns(e,t,n){return Array.from({length:t},(s,r)=>t-1-r).some(s=>n.includes(e.node(s).type.name))}function pd(e,t,n){if(!Number.isFinite(t.x)||!Number.isFinite(t.y))return null;const i=e.posAtCoords({left:t.x,top:t.y});if(!i)return null;const{doc:s}=e.state,r=s.resolve(i.pos),o=[];n.defaultRules&&o.push(...hd),o.push(...n.rules);const c=Array.from({length:r.depth},(h,f)=>r.depth-f).map(h=>{const f=r.node(h),p=r.before(h);if(n.allowedContainers&&h>0&&!Ns(r,h,n.allowedContainers))return null;const g=h>0?r.node(h-1):null,x=h>0?r.index(h-1):0,b=g?g.childCount:1,y={node:f,pos:p,depth:h,parent:g,index:x,isFirst:x===0,isLast:x===b-1,$pos:r,view:e},C=js(y,o,n.edgeDetection,t);if(C<0)return null;const S=e.nodeDOM(p);return{node:f,pos:p,depth:h,score:C,dom:S}}).filter(h=>h!==null),a=r.nodeAfter;if(a&&a.isAtom&&!a.isInline){const h=i.pos,f=r.depth+1,p=r.parent,g=r.index(),x=p.childCount;let b=!0;if(n.allowedContainers&&(b=Ns(r,f,n.allowedContainers)),b){const y={node:a,pos:h,depth:f,parent:p,index:g,isFirst:g===0,isLast:g===x-1,$pos:r,view:e},C=js(y,o,n.edgeDetection,t);if(C>=0){const S=e.nodeDOM(h);S&&c.push({node:a,pos:h,depth:f,score:C,dom:S})}}}if(c.length===0)return null;c.sort((h,f)=>f.score!==h.score?f.score-h.score:f.depth-h.depth);const u=c[0];return u.dom?{node:u.node,pos:u.pos,dom:u.dom}:null}function gd(e,t){let n=e;for(;n!=null&&n.parentElement&&n.parentElement!==t.dom;)n=n.parentElement;return(n==null?void 0:n.parentElement)===t.dom?n:void 0}function Bs(e){return Number.isFinite(e.top)&&Number.isFinite(e.bottom)&&Number.isFinite(e.left)&&Number.isFinite(e.right)&&e.width>0&&e.height>0}function md(e,t,n,i=5){if(!Number.isFinite(t)||!Number.isFinite(n))return null;const s=e.dom,r=s.firstElementChild,o=s.lastElementChild;if(!r||!o)return null;const l=r.getBoundingClientRect(),c=o.getBoundingClientRect();if(!Bs(l)||!Bs(c))return null;const a=Math.min(Math.max(l.top+i,n),c.bottom-i),u=.5,h=Math.abs(l.left-c.left)<u,f=Math.abs(l.right-c.right)<u;let p=l;h&&f&&(p=l);const g=Math.min(Math.max(p.left+i,t),p.right-i);return!Number.isFinite(g)||!Number.isFinite(a)?null:{x:g,y:a}}var ko=e=>{const{x:t,y:n,editor:i,nestedOptions:s}=e,{view:r,state:o}=i,l=md(r,t,n,5);if(!l)return{resultElement:null,resultNode:null,pos:null};const{x:c,y:a}=l;if(s!=null&&s.enabled){const g=pd(r,{x:c,y:a},s);return g?{resultElement:g.dom,resultNode:g.node,pos:g.pos}:{resultElement:null,resultNode:null,pos:null}}const u=r.root.elementsFromPoint(c,a);let h;if(Array.prototype.some.call(u,g=>{if(!r.dom.contains(g))return!1;const x=gd(g,r);return x?(h=x,!0):!1}),!h){const g=r.posAtCoords({left:c,top:a});if(g){const x=o.doc.resolve(g.pos),b=Math.min(x.depth,1),y=b>0?x.before(b):x.pos,C=o.doc.nodeAt(y);if(C){const S=r.nodeDOM(y);return{resultElement:S instanceof HTMLElement?S:null,resultNode:C,pos:y}}}return{resultElement:null,resultNode:null,pos:null}}let f;try{f=r.posAtDOM(h,0)}catch{return{resultElement:null,resultNode:null,pos:null}}const p=o.doc.nodeAt(f);if(!p){const g=o.doc.resolve(f),x=g.parent;return{resultElement:h,resultNode:x,pos:g.start()}}return{resultElement:h,resultNode:p,pos:f}};function Eo(e,t){const n=e.nodeDOM(t);if(n instanceof Element&&n!==e.dom)return n;const{node:i,offset:s}=e.domAtPos(t),r=i.childNodes[s];return r instanceof Element?r:i instanceof Element?i:i.nodeType===Node.TEXT_NODE&&i.parentElement?i.parentElement:null}function xd(e,t){const n=Eo(e,t);return(n?getComputedStyle(n).direction:getComputedStyle(e.dom).direction)||"ltr"}function To(e){var t;(t=e.parentNode)==null||t.removeChild(e)}function wd(e,t){return e==="rtl"?t:0}function bd(e){return e?!e.some(t=>{const n=t.trim().toLowerCase();return n==="margin"||n.startsWith("margin-")}):!0}function yd(e,t,n,i){const{doc:s}=t.view.state;if(n!=null&&n.enabled&&(i!=null&&i.node)&&i.pos>=0){const a=i.pos,u=i.pos+i.node.nodeSize;return[{$from:s.resolve(a),$to:s.resolve(u)}]}const r=ko({editor:t,x:e.clientX,y:e.clientY,nestedOptions:n});if(!r.resultNode||r.pos===null)return[];const o=r.resultNode.isText||r.resultNode.isAtom?0:-1,l=s.resolve(r.pos),c=s.resolve(r.pos+r.resultNode.nodeSize+o);return Ln(l,c,0,{extendOnBoundaryOverlap:!1})}function Sd(e,t,n,i,s){const{view:r}=t;if(!e.dataTransfer)return;const{empty:o,$from:l,$to:c}=r.state.selection,a=yd(e,t,n,i),u=Ln(l,c,0,{extendOnBoundaryOverlap:!1}),h=u.some(k=>a.find(D=>D.$from===k.$from&&D.$to===k.$to)),f=o||!h?a:u;if(!f.length)return;const{tr:p}=r.state,g=document.createElement("div"),x=f[0].$from.pos,b=f[f.length-1].$to.pos,y=xd(r,x);g.setAttribute("dir",y);const C=(n==null?void 0:n.enabled)&&(i==null?void 0:i.node),S=f.length===1;let _,U;C&&S?(_=r.state.doc.slice(x,b),U=G.NodeSelection.create(r.state.doc,x)):(U=kt.create(r.state.doc,x,b),_=U.content());const I=bd(s);f.forEach(k=>{const D=Eo(r,k.$from.pos);if(!D)return;const v=rd(D,s);I&&(v.style.margin="0"),g.append(v)}),g.style.position="absolute",g.style.top="-10000px",document.body.append(g),e.dataTransfer.clearData();const E=g.getBoundingClientRect(),M=wd(y,E.width);e.dataTransfer.setDragImage(g,M,0);let Q=!1;const nt=()=>{Q||(Q=!0,To(g),document.removeEventListener("drop",nt),document.removeEventListener("dragend",nt))},ht=U instanceof G.NodeSelection?U:void 0;r.dragging={slice:_,move:!0,node:ht},p.setSelection(U),r.dispatch(p),document.addEventListener("drop",nt),document.addEventListener("dragend",nt)}function Ls(e,t,n){let i=0;for(let s=t;s<n;s+=1)i+=e.child(s).nodeSize;return i}function vd(e){var t;return Se(e)?{anchorPos:e.from,nodeCount:e.ranges.length,depth:(t=e.depth)!=null?t:0}:null}function Cd(e,t,n,i){const s=e.resolve(t),r=s.node(i);let o=s.index(i);o>=r.childCount&&(o=Math.max(0,r.childCount-n));const l=Math.min(n,r.childCount-o);if(l<=0)return null;const c=s.start(i)+Ls(r,0,o),a=c+Ls(r,o,o+l);return{anchor:c,head:a,count:l}}function kd(e,t,n,i){try{const s=Cd(e,t,n,i);if(!s)return null;const r=kt.create(e,s.anchor,s.head,i);return r.ranges.length===n?r:null}catch{return null}}var Ps=(e,t)=>{const n=e.resolve(t),{depth:i}=n;return i===0?t:n.pos-n.parentOffset-1},Us=(e,t)=>{const n=e.nodeAt(t),i=e.resolve(t);let{depth:s}=i,r=n;for(;s>0;){const o=i.node(s);s-=1,s===0&&(r=o)}return r},si=(e,t)=>{const n=B.getState(e);return n?yn(t,n.type,n.binding.mapping):null},Ed=(e,t)=>{const n=B.getState(e);return n?Vt(n.doc,n.type,t,n.binding.mapping)||0:-1},zs=(e,t)=>{let n=t;for(;n!=null&&n.parentNode&&n.parentNode!==e.dom;)n=n.parentNode;return n},_o=new G.PluginKey("dragHandle"),Do=({pluginKey:e=_o,element:t,editor:n,computePositionConfig:i,getReferencedVirtualElement:s,onNodeChange:r,onElementDragStart:o,onElementDragEnd:l,nestedOptions:c,dragImageProperties:a})=>{const u=document.createElement("div");let h=!1,f=null,p=-1,g,x=null,b=null,y=null,C=null,S=null;function _(){t&&(t.style.visibility="hidden",t.style.pointerEvents="none")}function U(){if(t){if(!n.isEditable){_();return}t.style.visibility="",t.style.pointerEvents="auto"}}function I(k){const D=(s==null?void 0:s())||{getBoundingClientRect:()=>k.getBoundingClientRect()};W.computePosition(D,t,i).then(v=>{Object.assign(t.style,{position:v.strategy,left:`${v.x}px`,top:`${v.y}px`})})}function E(k){o==null||o(k),Sd(k,n,c,{node:f,pos:p},a),C=vd(n.state.selection),t&&(t.dataset.dragging="true"),setTimeout(()=>{t&&(t.style.pointerEvents="none")},0)}function M(k){l==null||l(k),C=null,_(),t&&(t.style.pointerEvents="auto",t.dataset.dragging="false")}function Q({nodeCount:k,depth:D,anchorPos:v}){const K=kd(n.state.doc,v,k,D);K&&n.view.dispatch(n.state.tr.setSelection(K))}function nt(k){if(!(!k.target||!n.view.dom.contains(k.target))){if(O.isFirefox()){const D=n.view.dom;requestAnimationFrame(()=>{D.isContentEditable&&(D.contentEditable="false",D.contentEditable="true")})}!C||n.view.state.selection.empty||(S={...C,anchorPos:n.state.selection.from},b=requestAnimationFrame(()=>{b=null,S&&(Q(S),S=null)}))}}function ht(){t.removeEventListener("dragstart",E),t.removeEventListener("dragend",M),document.removeEventListener("drop",nt),x&&(cancelAnimationFrame(x),x=null,y=null),b&&(cancelAnimationFrame(b),b=null)}return u.appendChild(t),{unbind(){ht()},plugin:new G.Plugin({key:typeof e=="string"?new G.PluginKey(e):e,state:{init(){return{locked:!1}},apply(k,D,v,K){if(S&&k.docChanged){const Z=k.mapping.mapResult(S.anchorPos,1);Z.deleted?S=null:S.anchorPos=Z.pos}const V=k.getMeta("lockDragHandle"),q=k.getMeta("hideDragHandle");if(V!==void 0&&(h=V),q)return _(),h=!1,f=null,p=-1,r==null||r({editor:n,node:null,pos:-1}),D;if(k.docChanged&&p!==-1&&t)if(Ji(k)){const Z=Ed(K,g);Z!==p&&(p=Z)}else{const Z=k.mapping.map(p);Z!==p&&(p=Z,g=si(K,p))}return D}},view:k=>{var D;return t.draggable=!0,t.style.pointerEvents="auto",t.dataset.dragging="false",(D=n.view.dom.parentElement)==null||D.appendChild(u),u.style.pointerEvents="none",u.style.position="absolute",u.style.top="0",u.style.left="0",t.addEventListener("dragstart",E),t.addEventListener("dragend",M),document.addEventListener("drop",nt),{update(v,K){if(!t)return;if(!n.isEditable){_();return}if(h?t.draggable=!1:t.draggable=!0,k.state.doc.eq(K.doc)||p===-1)return;let V=k.nodeDOM(p);if(V=zs(k,V),V===k.dom||(V==null?void 0:V.nodeType)!==1)return;const q=k.posAtDOM(V,0),Z=Us(n.state.doc,q),Ut=Ps(n.state.doc,q);f=Z,p=Ut,g=si(k.state,p),r==null||r({editor:n,node:f,pos:p}),I(V)},destroy(){ht(),t&&To(u)}}},props:{handleDOMEvents:{keydown(k){return!t||h||k.hasFocus()&&(_(),f=null,p=-1,r==null||r({editor:n,node:null,pos:-1})),!1},mouseleave(k,D){return h||D.target&&!u.contains(D.relatedTarget)&&(_(),f=null,p=-1,r==null||r({editor:n,node:null,pos:-1})),!1},mousemove(k,D){return!t||h||(y={x:D.clientX,y:D.clientY},x)||(x=requestAnimationFrame(()=>{if(x=null,!y)return;const{x:v,y:K}=y;y=null;const V=ko({x:v,y:K,editor:n,nestedOptions:c});if(!V.resultElement)return;let q=V.resultElement,Z=V.resultNode,Ut=V.pos;if(!(c!=null&&c.enabled)){if(q=zs(k,q),q===k.dom||(q==null?void 0:q.nodeType)!==1)return;const me=k.posAtDOM(q,0);Z=Us(n.state.doc,me),Ut=Ps(n.state.doc,me)}Z!==f&&(f=Z,p=Ut??-1,g=si(k.state,p),r==null||r({editor:n,node:f,pos:p}),I(q),U())})),!1}}}})}};function Ao(e){var t,n;return e===!1||e===void 0?{enabled:!1,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:ii("none")}:e===!0?{enabled:!0,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:ii("left")}:{enabled:!0,rules:(t=e.rules)!=null?t:[],defaultRules:(n=e.defaultRules)!=null?n:!0,allowedContainers:e.allowedContainers,edgeDetection:ii(e.edgeDetection)}}var ki={placement:"left-start",strategy:"absolute"};O.Extension.create({name:"dragHandle",addOptions(){return{render(){const e=document.createElement("div");return e.classList.add("drag-handle"),e},computePositionConfig:{},locked:!1,onNodeChange:()=>null,onElementDragStart:void 0,onElementDragEnd:void 0,nested:!1,dragImageProperties:void 0}},addCommands(){return{lockDragHandle:()=>({editor:e})=>(this.options.locked=!0,e.commands.setMeta("lockDragHandle",this.options.locked)),unlockDragHandle:()=>({editor:e})=>(this.options.locked=!1,e.commands.setMeta("lockDragHandle",this.options.locked)),toggleDragHandle:()=>({editor:e})=>(this.options.locked=!this.options.locked,e.commands.setMeta("lockDragHandle",this.options.locked))}},addProseMirrorPlugins(){const e=this.options.render(),t=Ao(this.options.nested);return[Do({computePositionConfig:{...ki,...this.options.computePositionConfig},getReferencedVirtualElement:this.options.getReferencedVirtualElement,element:e,editor:this.editor,onNodeChange:this.options.onNodeChange,onElementDragStart:this.options.onElementDragStart,onElementDragEnd:this.options.onElementDragEnd,nestedOptions:t,dragImageProperties:this.options.dragImageProperties}).plugin]}});var Td=e=>{const{className:t="drag-handle",children:n,editor:i,pluginKey:s=_o,onNodeChange:r,onElementDragStart:o,onElementDragEnd:l,getReferencedVirtualElement:c,computePositionConfig:a=ki,nested:u=!1}=e,[h]=w.useState(()=>typeof document>"u"?null:document.createElement("div")),f=w.useMemo(()=>Ao(u),[JSON.stringify(u)]);return w.useEffect(()=>{h&&(h.className=t,h.style.visibility="hidden",h.style.position="absolute",h.dataset.dragging="false")},[t,h]),w.useEffect(()=>{if(!h||i.isDestroyed)return;const{plugin:p,unbind:g}=Do({editor:i,element:h,pluginKey:s,computePositionConfig:{...ki,...a},onElementDragStart:o,onElementDragEnd:l,onNodeChange:r,getReferencedVirtualElement:c,nestedOptions:f});return i.registerPlugin(p),()=>{i.isDestroyed||i.unregisterPlugin(s),g()}},[h,i,r,c,s,a,o,l,f]),h?Ei.createPortal(n,h):null},_d=Td;function Dd(){var I,E,M,Q,nt,ht,k,D;const e=m.useEditorInstance(),t=m.useEditableEditor(),{t:n}=P.useLocale(),[i,s]=w.useState(null),[r,o]=w.useState(-1),[l,c]=w.useState(!1),a=(E=(I=e==null?void 0:e.extensionManager)==null?void 0:I.extensions)==null?void 0:E.some(v=>(v==null?void 0:v.name)===Hs.TextAlign.name),u=(Q=(M=e==null?void 0:e.extensionManager)==null?void 0:M.extensions)==null?void 0:Q.some(v=>(v==null?void 0:v.name)===we.Indent.name),h=(ht=(nt=e==null?void 0:e.extensionManager)==null?void 0:nt.extensions)==null?void 0:ht.some(v=>(v==null?void 0:v.name)===$o.Clear.name);function f(){const v=e.chain();v.setNodeSelection(r).unsetAllMarks(),(i==null?void 0:i.type.name)!=="paragraph"&&v.setParagraph(),v.run()}function p(){e.chain().focus().setNodeSelection(r).run(),document.execCommand("copy")}function g(){e.commands.setNodeSelection(r);const{$anchor:v}=e.state.selection,K=v.node(1)||e.state.selection.node;e.chain().setMeta("hideDragHandle",!0).insertContentAt(r+((i==null?void 0:i.nodeSize)||0),K.toJSON()).run()}function x(v){e.commands.setTextAlign(v)}function b(){const v=we.setNodeIndentMarkup(e.state.tr,r,1);v.setMeta("hideDragHandle",!0),e.view.dispatch&&e.view.dispatch(v)}function y(){const v=we.setNodeIndentMarkup(e.state.tr,r,-1);e.view.dispatch&&e.view.dispatch(v)}function C(){e.chain().setMeta("hideDragHandle",!0).setNodeSelection(r).deleteSelection().run()}const S=w.useCallback(v=>{v.node&&s(v.node),o(v.pos),requestAnimationFrame(()=>{v.editor.commands.focus()})},[]),_=v=>{var K;if(v.preventDefault(),r!==-1){const V=(i==null?void 0:i.nodeSize)||0,q=r+V,Z=(i==null?void 0:i.type.name)==="paragraph"&&((K=i==null?void 0:i.content)==null?void 0:K.size)===0,Ut=Z?r+2:q+2;e.chain().command(({dispatch:me,tr:Pn,state:Xi})=>me?(Z?Pn.insertText("/",r,r+1):Pn.insert(q,Xi.schema.nodes.paragraph.create(null,[Xi.schema.text("/")])),me(Pn)):!0).focus(Ut).run()}};w.useEffect(()=>(l?e.commands.setMeta("lockDragHandle",!0):e.commands.setMeta("lockDragHandle",!1),()=>{e.commands.setMeta("lockDragHandle",!1)}),[l]);const U=v=>{t&&c(v)};return d.jsx(_d,{className:"richtext-transition-all richtext-duration-200 richtext-ease-out",editor:e,onNodeChange:S,pluginKey:"RichTextBubbleMenuDragHandle",children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-0.5",children:[d.jsx(m.ActionButton,{action:_,disabled:!t,icon:"Plus",tooltip:n("editor.draghandle.insertBlock")}),d.jsx(m.ActionButton,{disabled:!t,icon:"Grip",tooltip:n("editor.draghandle.grip"),action:v=>{v.preventDefault(),v.stopPropagation(),U(!l)}}),d.jsxs(z.DropdownMenu,{onOpenChange:U,open:l,children:[d.jsx(z.DropdownMenuTrigger,{className:"richtext-pointer-events-none"}),d.jsxs(z.DropdownMenuContent,{align:"start",className:"richtext-w-48",hideWhenDetached:!0,side:"bottom",sideOffset:0,children:[d.jsxs(z.DropdownMenuItem,{className:"richtext-flex richtext-gap-3 richtext-bg-opacity-10 hover:richtext-bg-red-400 hover:richtext-bg-opacity-20 focus:richtext-bg-red-400 focus:richtext-bg-opacity-30 focus:richtext-text-red-500 dark:hover:richtext-bg-opacity-20 dark:hover:richtext-text-red-500",onClick:C,children:[d.jsx(m.IconComponent,{name:"Trash2"}),d.jsx("span",{children:n("editor.remove")})]}),h?d.jsxs(z.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:f,children:[d.jsx(m.IconComponent,{name:"PaintRoller"}),d.jsx("span",{children:n("editor.clear.tooltip")})]}):null,d.jsxs(z.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:p,children:[d.jsx(m.IconComponent,{name:"Clipboard"}),d.jsx("span",{children:n("editor.copyToClipboard")})]}),d.jsxs(z.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:g,children:[d.jsx(m.IconComponent,{name:"Copy"}),d.jsx("span",{children:n("editor.copy")})]}),a||u?d.jsx(z.DropdownMenuSeparator,{}):null,a?d.jsxs(z.DropdownMenuSub,{children:[d.jsxs(z.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[d.jsx(m.IconComponent,{name:"AlignCenter"}),d.jsx("span",{children:n("editor.textalign.tooltip")})]}),d.jsx(z.DropdownMenuPortal,{children:d.jsxs(z.DropdownMenuSubContent,{children:[d.jsxs(z.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("left"),children:[d.jsx(m.IconComponent,{name:"AlignLeft"}),d.jsx("span",{children:n("editor.textalign.left.tooltip")})]}),d.jsxs(z.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("center"),children:[d.jsx(m.IconComponent,{name:"AlignCenter"}),d.jsx("span",{children:n("editor.textalign.center.tooltip")})]}),d.jsxs(z.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("right"),children:[d.jsx(m.IconComponent,{name:"AlignRight"}),d.jsx("span",{children:n("editor.textalign.right.tooltip")})]})]})})]}):null,u?d.jsxs(z.DropdownMenuSub,{children:[d.jsxs(z.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[d.jsx(m.IconComponent,{name:"IndentIncrease"}),d.jsx("span",{children:n("editor.indent")})]}),d.jsx(z.DropdownMenuPortal,{children:d.jsxs(z.DropdownMenuSubContent,{children:[d.jsxs(z.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((k=i==null?void 0:i.attrs)==null?void 0:k.indent)>=we.IndentProps.max,onClick:b,children:[d.jsx(m.IconComponent,{name:"IndentIncrease"}),d.jsx("span",{children:n("editor.indent.tooltip")})]}),d.jsxs(z.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((D=i==null?void 0:i.attrs)==null?void 0:D.indent)<=we.IndentProps.min,onClick:y,children:[d.jsx(m.IconComponent,{name:"IndentDecrease"}),d.jsx("span",{children:n("editor.outdent.tooltip")})]})]})})]}):null]})]})]})})}const $s={plaintext:"Plain Text",js:"JavaScript",ts:"TypeScript",css:"CSS",html:"HTML",python:"Python",bash:"Bash"};function Ad({listLanguages:e}){const{t}=P.useLocale(),[n,i]=w.useState(!1),s=m.useEditorInstance(),r=w.useMemo(()=>{const{selection:l}=s.state,c=l.$from.parent;if(c.type.name==="codeBlock"){const a=c.attrs.language||"plaintext";return $s[a]||a}},[s.state,e]),o=w.useMemo(()=>{let l=e||[];return e!=null&&e.includes("plaintext")||(l=["plaintext",...l]),l.map(c=>({label:$s[c]||c,value:c}))},[e]);return d.jsxs(At.Popover,{modal:!0,onOpenChange:i,open:n,children:[d.jsx(At.PopoverTrigger,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:d.jsxs(m.ActionButton,{dataState:!!r,children:[r?d.jsx(d.Fragment,{children:r}):d.jsx(d.Fragment,{children:t("editor.paragraph.tooltip")}),d.jsx(m.IconComponent,{className:"richtext-ml-1 richtext-size-3 richtext-text-zinc-500",name:"MenuDown"})]})}),d.jsx(At.PopoverContent,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:o==null?void 0:o.map(l=>d.jsxs("div",{className:"richtext-flex richtext-w-full richtext-items-center richtext-gap-3 richtext-rounded-sm !richtext-border-none !richtext-bg-transparent richtext-px-2 richtext-py-1.5 richtext-text-left richtext-text-sm richtext-text-foreground !richtext-outline-none richtext-transition-colors hover:!richtext-bg-accent",onClick:c=>{c.preventDefault(),s.chain().focus().setCodeBlock({language:l.value}).run(),i(!1)},children:[d.jsx("div",{className:"!richtext-min-w-[20px]",children:r===l.value&&d.jsx(Ht.Check,{size:16})}),d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:l.label})]},l.value))})]})}function Id(){const e=m.useEditableEditor(),t=m.useEditorInstance(),n=m.useExtension(zn.CodeBlock.name),i=w.useCallback(({editor:c})=>c.isActive(zn.CodeBlock.name),[]),s=w.useMemo(()=>{var c,a,u;return n?((u=(a=(c=n.options)==null?void 0:c.lowlight)==null?void 0:a.listLanguages)==null?void 0:u.call(a))||["plaintext","html","css","js","ts"]:[]},[n]),r=w.useCallback(()=>Yt(zn.CodeBlock.name,t),[t]),o=()=>{const{from:c}=t.state.selection,a=t.state.doc.resolve(c);for(let u=a.depth;u>=0;u--){const h=a.node(u);if(h.type.name==="codeBlock")return h.textContent}return""},l=()=>{const c=o();navigator.clipboard.writeText(c)};return e?d.jsx(ot,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleCodeBlock",shouldShow:i,getReferencedVirtualElement:()=>{const{from:c}=t.state.selection,u=t.view.domAtPos(c).node.parentElement;return u?{getBoundingClientRect:()=>u.getBoundingClientRect()}:null},children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(Ad,{listLanguages:s}),d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(m.ActionButton,{action:l,tooltip:"Copy",children:d.jsx(Ht.Copy,{size:16})}),d.jsx(Et.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(m.ActionButton,{action:r,tooltip:"Delete",children:d.jsx(Ht.Trash2,{size:16})})]})}):d.jsx(d.Fragment,{})}exports.RichTextBubbleCallout=wl;exports.RichTextBubbleCodeBlock=Id;exports.RichTextBubbleColumns=bl;exports.RichTextBubbleDrawer=Nl;exports.RichTextBubbleExcalidraw=Ll;exports.RichTextBubbleIframe=Pl;exports.RichTextBubbleImage=ql;exports.RichTextBubbleImageGif=Wl;exports.RichTextBubbleKatex=zl;exports.RichTextBubbleLink=Vl;exports.RichTextBubbleMenuDragHandle=Dd;exports.RichTextBubbleMermaid=Zl;exports.RichTextBubbleTable=Ql;exports.RichTextBubbleText=nc;exports.RichTextBubbleTwitter=ic;exports.RichTextBubbleVideo=Gl;
1
+ "use strict";var Io=Object.create;var Pn=Object.defineProperty;var Do=Object.getOwnPropertyDescriptor;var Mo=Object.getOwnPropertyNames;var Oo=Object.getPrototypeOf,Ro=Object.prototype.hasOwnProperty;var jo=(e,t,n)=>t in e?Pn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var No=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Mo(t))!Ro.call(e,s)&&s!==n&&Pn(e,s,{get:()=>t[s],enumerable:!(i=Do(t,s))||i.enumerable});return e};var Bo=(e,t,n)=>(n=e!=null?Io(Oo(e)):{},No(t||!e||!e.__esModule?Pn(n,"default",{value:e,enumerable:!0}):n,e));var $e=(e,t,n)=>jo(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),_=require("./index-EoGU7W4e.cjs"),z=require("./index-qZURFC5Q.cjs"),K=require("@tiptap/pm/state"),Hs=require("./Table-CWI7tKme.cjs"),zs=require("./clsx-DJURdKPs.cjs"),b=require("react"),ki=require("react-dom"),m=require("./index-BO82_0q8.cjs"),Tt=require("./Callout-C_TXsss3.cjs"),mt=require("./Katex-oLGrtLTf.cjs"),L=require("./index-CwbGrQFa.cjs"),zt=require("lucide-react"),Un=require("./CodeBlock.cjs"),kt=require("./separator-DMLtkcoo.cjs"),It=require("./popover-Bl1kxRJX.cjs"),Ji=require("./Column.cjs");require("./theme.cjs");const qe=require("./Drawer-D3B4lQJF.cjs"),Xi=require("easydrawer"),en=require("./shortId-Bfj8TyNr.cjs"),xe=require("./Excalidraw.cjs"),Qt=require("./Iframe-bvGuzYwC.cjs"),Lo=require("./ImageGif.cjs"),Po=require("katex"),ni=require("./textarea-DV9Fw3y1.cjs"),We=require("./LinkEditBlock-BojxdGTm.cjs"),$n=require("@tiptap/pm/view"),Uo=require("@tiptap/pm/model"),$o=require("./Clear.cjs"),be=require("./Indent-IOByomps.cjs"),Ks=require("./TextAlign.cjs"),$=require("./dropdown-menu-CEMxzgnU.cjs"),ii=require("./Mermaid.cjs"),Fo=require("./Bold.cjs"),Vo=require("./Code.cjs");require("./index-DN-IR-K0.cjs");const Ho=require("./Color.cjs"),zo=require("./Highlight.cjs"),Ko=require("./Italic.cjs"),qo=require("./SlashCommandNodeView-Dai-O3aD.cjs"),Wo=require("./Strike.cjs"),Go=require("./TextUnderline.cjs"),Fn=require("./Twitter-BfsPzA8_.cjs");function Yo(e,t){const n=Math.min(e.top,t.top),i=Math.max(e.bottom,t.bottom),s=Math.min(e.left,t.left),o=Math.max(e.right,t.right)-s,l=i-n,c=s,a=n;return new DOMRect(c,a,o,l)}var Jo=class{constructor({editor:e,element:t,view:n,pluginKey:i="bubbleMenu",updateDelay:s=250,resizeDelay:r=60,shouldShow:o,appendTo:l,getReferencedVirtualElement:c,options:a}){this.preventHide=!1,this.isVisible=!1,this.scrollTarget=window,this.floatingUIOptions={strategy:"absolute",placement:"top",offset:8,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1,onShow:void 0,onHide:void 0,onUpdate:void 0,onDestroy:void 0},this.shouldShow=({view:u,state:f,from:p,to:g})=>{const{doc:x,selection:w}=f,{empty:y}=w,S=!x.textBetween(p,g).length&&_.isTextSelection(f.selection),k=this.element.contains(document.activeElement);return!(!(u.hasFocus()||k)||y||S||!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:u})=>{var f;if(this.editor.isDestroyed){this.destroy();return}if(this.preventHide){this.preventHide=!1;return}u!=null&&u.relatedTarget&&((f=this.element.parentNode)!=null&&f.contains(u.relatedTarget))||(u==null?void 0:u.relatedTarget)!==this.editor.view.dom&&this.hide()},this.handleDebouncedUpdate=(u,f)=>{const p=!(f!=null&&f.selection.eq(u.state.selection)),g=!(f!=null&&f.doc.eq(u.state.doc));!p&&!g||(this.updateDebounceTimer&&clearTimeout(this.updateDebounceTimer),this.updateDebounceTimer=window.setTimeout(()=>{this.updateHandler(u,p,g,f)},this.updateDelay))},this.updateHandler=(u,f,p,g)=>{const{composing:x}=u;if(x||!f&&!p)return;if(!this.getShouldShow(g)){this.hide();return}this.show(),this.updatePosition()},this.transactionHandler=({transaction:u})=>{const f=u.getMeta(this.pluginKey);f==="updatePosition"?this.updatePosition():f&&typeof f=="object"&&f.type==="updateOptions"?this.updateOptions(f.options):f==="hide"?this.hide():f==="show"&&(this.updatePosition(),this.show())};var h;this.editor=e,this.element=t,this.view=n,this.pluginKey=i,this.updateDelay=s,this.resizeDelay=r,this.appendTo=l,this.scrollTarget=(h=a==null?void 0:a.scrollTarget)!=null?h:window,this.getReferencedVirtualElement=c,this.floatingUIOptions={...this.floatingUIOptions,...a},this.element.tabIndex=0,o&&(this.shouldShow=o),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.view.dom.addEventListener("dragstart",this.dragstartHandler),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.editor.on("transaction",this.transactionHandler),window.addEventListener("resize",this.resizeHandler),this.scrollTarget.addEventListener("scroll",this.resizeHandler),this.update(n,n.state),this.getShouldShow()&&(this.show(),this.updatePosition())}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(z.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(z.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(z.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(z.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(z.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(z.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(z.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(z.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}get virtualElement(){var e,t,n;const{selection:i}=this.editor.state,s=(e=this.getReferencedVirtualElement)==null?void 0:e.call(this);if(s)return s;if(!((n=(t=this.view)==null?void 0:t.dom)!=null&&n.parentNode))return;const r=_.posToDOMRect(this.view,i.from,i.to);let o={getBoundingClientRect:()=>r,getClientRects:()=>[r]};if(i instanceof K.NodeSelection){let l=this.view.nodeDOM(i.from);const c=l.dataset.nodeViewWrapper?l:l.querySelector("[data-node-view-wrapper]");c&&(l=c),l&&(o={getBoundingClientRect:()=>l.getBoundingClientRect(),getClientRects:()=>[l.getBoundingClientRect()]})}if(i instanceof Hs.CellSelection){const{$anchorCell:l,$headCell:c}=i,a=l?l.pos:c.pos,h=c?c.pos:l.pos,u=this.view.nodeDOM(a),f=this.view.nodeDOM(h);if(!u||!f)return;const p=u===f?u.getBoundingClientRect():Yo(u.getBoundingClientRect(),f.getBoundingClientRect());o={getBoundingClientRect:()=>p,getClientRects:()=>[p]}}return o}updatePosition(){if(!this.isVisible)return;const e=this.virtualElement;e&&z.computePosition(e,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:t,y:n,strategy:i,middlewareData:s})=>{var r,o;if(!(!this.isVisible||this.editor.isDestroyed||!this.element.isConnected)){if((r=s.hide)!=null&&r.referenceHidden||(o=s.hide)!=null&&o.escaped){this.element.style.visibility="hidden";return}this.element.style.visibility="visible",this.element.style.width="max-content",this.element.style.position=i,this.element.style.left=`${t}px`,this.element.style.top=`${n}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()}})}update(e,t){const{state:n}=e,i=n.selection.from!==n.selection.to;if(this.updateDelay>0&&i){this.handleDebouncedUpdate(e,t);return}const s=!(t!=null&&t.selection.eq(e.state.selection)),r=!(t!=null&&t.doc.eq(e.state.doc));this.updateHandler(e,s,r,t)}getShouldShow(e){var t;const{state:n}=this.view,{selection:i}=n,{ranges:s}=i,r=Math.min(...s.map(c=>c.$from.pos)),o=Math.max(...s.map(c=>c.$to.pos));return((t=this.shouldShow)==null?void 0:t.call(this,{editor:this.editor,element:this.element,view:this.view,state:n,oldState:e,from:r,to:o}))||!1}show(){var e;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const t=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(e=t??this.view.dom.parentElement)==null||e.appendChild(this.element),this.floatingUIOptions.onShow&&this.floatingUIOptions.onShow(),this.isVisible=!0}hide(){this.isVisible&&(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.remove(),this.floatingUIOptions.onHide&&this.floatingUIOptions.onHide(),this.isVisible=!1)}updateOptions(e){var t;if(e.updateDelay!==void 0&&(this.updateDelay=e.updateDelay),e.resizeDelay!==void 0&&(this.resizeDelay=e.resizeDelay),e.appendTo!==void 0&&(this.appendTo=e.appendTo),e.getReferencedVirtualElement!==void 0&&(this.getReferencedVirtualElement=e.getReferencedVirtualElement),e.shouldShow!==void 0&&e.shouldShow&&(this.shouldShow=e.shouldShow),e.options!==void 0){const n=(t=e.options.scrollTarget)!=null?t:window;n!==this.scrollTarget&&(this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.scrollTarget=n,this.scrollTarget.addEventListener("scroll",this.resizeHandler)),this.floatingUIOptions={...this.floatingUIOptions,...e.options}}}destroy(){this.hide(),this.element.removeEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.view.dom.removeEventListener("dragstart",this.dragstartHandler),window.removeEventListener("resize",this.resizeHandler),this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.editor.off("transaction",this.transactionHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},qs=e=>new K.Plugin({key:typeof e.pluginKey=="string"?new K.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Jo({view:t,...e})});_.Extension.create({name:"bubbleMenu",addOptions(){return{element:null,pluginKey:"bubbleMenu",updateDelay:void 0,appendTo:void 0,shouldShow:null}},addProseMirrorPlugins(){return this.options.element?[qs({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 Xo=class{constructor({editor:e,element:t,view:n,pluginKey:i="floatingMenu",updateDelay:s=250,resizeDelay:r=60,options:o,appendTo:l,shouldShow:c}){this.preventHide=!1,this.isVisible=!1,this.scrollTarget=window,this.shouldShow=({view:h,state:u})=>{const{selection:f}=u,{$anchor:p,empty:g}=f,x=p.depth===1,w=p.parent.isTextblock&&!p.parent.type.spec.code&&!p.parent.textContent&&p.parent.childCount===0&&!this.getTextContent(p.parent);return!(!h.hasFocus()||!g||!x||!w||!this.editor.isEditable)},this.floatingUIOptions={strategy:"absolute",placement:"right",offset:8,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1},this.updateHandler=(h,u,f,p)=>{const{composing:g}=h;if(g||!u&&!f)return;if(!this.getShouldShow(p)){this.hide();return}this.updatePosition(),this.show()},this.mousedownHandler=()=>{this.preventHide=!0},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:h})=>{var u;if(this.preventHide){this.preventHide=!1;return}h!=null&&h.relatedTarget&&((u=this.element.parentNode)!=null&&u.contains(h.relatedTarget))||(h==null?void 0:h.relatedTarget)!==this.editor.view.dom&&this.hide()},this.transactionHandler=({transaction:h})=>{const u=h.getMeta(this.pluginKey);u==="updatePosition"?this.updatePosition():u&&typeof u=="object"&&u.type==="updateOptions"?this.updateOptions(u.options):u==="hide"?this.hide():u==="show"&&(this.updatePosition(),this.show())},this.resizeHandler=()=>{this.resizeDebounceTimer&&clearTimeout(this.resizeDebounceTimer),this.resizeDebounceTimer=window.setTimeout(()=>{this.updatePosition()},this.resizeDelay)};var a;this.editor=e,this.element=t,this.view=n,this.pluginKey=i,this.updateDelay=s,this.resizeDelay=r,this.appendTo=l,this.scrollTarget=(a=o==null?void 0:o.scrollTarget)!=null?a:window,this.floatingUIOptions={...this.floatingUIOptions,...o},this.element.tabIndex=0,c&&(this.shouldShow=c),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.editor.on("transaction",this.transactionHandler),window.addEventListener("resize",this.resizeHandler),this.scrollTarget.addEventListener("scroll",this.resizeHandler),this.update(n,n.state),this.getShouldShow()&&(this.show(),this.updatePosition())}getTextContent(e){return _.getText(e,{textSerializers:_.getTextSerializersFromSchema(this.editor.schema)})}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(z.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(z.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(z.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(z.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(z.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(z.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(z.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(z.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}getShouldShow(e){var t;const{state:n}=this.view,{selection:i}=n,{ranges:s}=i,r=Math.min(...s.map(c=>c.$from.pos)),o=Math.max(...s.map(c=>c.$to.pos));return(t=this.shouldShow)==null?void 0:t.call(this,{editor:this.editor,view:this.view,state:n,oldState:e,from:r,to:o})}updateOptions(e){var t;if(e.updateDelay!==void 0&&(this.updateDelay=e.updateDelay),e.resizeDelay!==void 0&&(this.resizeDelay=e.resizeDelay),e.appendTo!==void 0&&(this.appendTo=e.appendTo),e.shouldShow!==void 0&&e.shouldShow&&(this.shouldShow=e.shouldShow),e.options!==void 0){const n=(t=e.options.scrollTarget)!=null?t:window;n!==this.scrollTarget&&(this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.scrollTarget=n,this.scrollTarget.addEventListener("scroll",this.resizeHandler)),this.floatingUIOptions={...this.floatingUIOptions,...e.options}}}updatePosition(){var e,t;if(!((t=(e=this.view)==null?void 0:e.dom)!=null&&t.parentNode))return;const{selection:n}=this.editor.state,i=_.posToDOMRect(this.view,n.from,n.to),s={getBoundingClientRect:()=>i,getClientRects:()=>[i]};z.computePosition(s,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:r,y:o,strategy:l,middlewareData:c})=>{var a,h;if((a=c.hide)!=null&&a.referenceHidden||(h=c.hide)!=null&&h.escaped){this.element.style.visibility="hidden";return}this.element.style.visibility="visible",this.element.style.width="max-content",this.element.style.position=l,this.element.style.left=`${r}px`,this.element.style.top=`${o}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()})}update(e,t){const n=!(t!=null&&t.selection.eq(e.state.selection)),i=!(t!=null&&t.doc.eq(e.state.doc));this.updateHandler(e,n,i,t)}show(){var e;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const t=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(e=t??this.view.dom.parentElement)==null||e.appendChild(this.element),this.floatingUIOptions.onShow&&this.floatingUIOptions.onShow(),this.isVisible=!0}hide(){this.isVisible&&(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.remove(),this.floatingUIOptions.onHide&&this.floatingUIOptions.onHide(),this.isVisible=!1)}destroy(){this.hide(),this.element.removeEventListener("mousedown",this.mousedownHandler,{capture:!0}),window.removeEventListener("resize",this.resizeHandler),this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.editor.off("transaction",this.transactionHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},Ws=e=>new K.Plugin({key:typeof e.pluginKey=="string"?new K.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Xo({view:t,...e})});_.Extension.create({name:"floatingMenu",addOptions(){return{element:null,options:{},pluginKey:"floatingMenu",updateDelay:void 0,resizeDelay:void 0,appendTo:void 0,shouldShow:null}},addCommands(){return{updateFloatingMenuPosition:()=>({tr:e,dispatch:t})=>(t&&e.setMeta(this.options.pluginKey,"updatePosition"),!0)}},addProseMirrorPlugins(){return this.options.element?[Ws({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,updateDelay:this.options.updateDelay,resizeDelay:this.options.resizeDelay,options:this.options.options,appendTo:this.options.appendTo,shouldShow:this.options.shouldShow})]:[]}});function Gs(e,t){return e??new K.PluginKey(t)}var Zo=typeof window<"u"?b.useLayoutEffect:b.useEffect,Ys=new Set(["left","opacity","position","top","visibility","width"]),Qo=new Set(["animationIterationCount","aspectRatio","borderImageOutset","borderImageSlice","borderImageWidth","columnCount","columns","fillOpacity","flex","flexGrow","flexShrink","fontWeight","gridArea","gridColumn","gridColumnEnd","gridColumnStart","gridRow","gridRowEnd","gridRowStart","lineClamp","lineHeight","opacity","order","orphans","scale","stopOpacity","strokeDasharray","strokeDashoffset","strokeMiterlimit","strokeOpacity","strokeWidth","tabSize","widows","zIndex","zoom"]),tl=new Set(["children","className","style"]),el=new Set(["tabIndex"]),nl=new Set(["accessKey","autoCapitalize","contentEditable","contextMenu","dir","draggable","enterKeyHint","hidden","id","lang","nonce","role","slot","spellCheck","tabIndex","title","translate"]),il={Blur:"focusout",DoubleClick:"dblclick",Focus:"focusin",MouseEnter:"mouseenter",MouseLeave:"mouseleave"};function si(e,t){return/^on[A-Z]/.test(e)&&typeof t=="function"}function sl(e){return e.startsWith("aria-")||e.startsWith("data-"),e}function rl(e){return e.startsWith("aria-")||e.startsWith("data-")||nl.has(e)}function Js(e){return e.startsWith("--")?e:e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}function ol(e){var t;const n=e.endsWith("Capture"),s=(n?e.slice(0,-7):e).slice(2);return{eventName:(t=il[s])!=null?t:s.toLowerCase(),options:n?{capture:!0}:void 0}}function ll(e,t){let n=t.defaultPrevented,i=!1;const s=Object.create(t);return Object.defineProperties(s,{nativeEvent:{value:t},currentTarget:{value:e},target:{value:t.target},persist:{value:()=>{}},isDefaultPrevented:{value:()=>n},isPropagationStopped:{value:()=>i},preventDefault:{value:()=>{n=!0,t.preventDefault()}},stopPropagation:{value:()=>{i=!0,t.stopPropagation()}}}),s}function Vn(e){return el.has(e)}function Zi(e,t,n){if(t==="tabIndex"){e.tabIndex=Number(n);return}e[t]=n}function cl(e,t){if(t==="tabIndex"){e.removeAttribute("tabindex");return}const n=e[t];if(typeof n=="boolean"){e[t]=!1;return}if(typeof n=="number"){e[t]=0;return}e[t]=""}function al(e,t){return typeof t!="number"||t===0||e.startsWith("--")||Qo.has(e)?String(t):`${t}px`}function ul(e,t){Ys.has(t)||e.style.removeProperty(Js(t))}function hl(e,t,n){Ys.has(t)||e.style.setProperty(Js(t),al(t,n))}function dl(e,t,n){new Set([...Object.keys(t),...Object.keys(n)]).forEach(s=>{if(tl.has(s)||!rl(s)||si(s,t[s])||si(s,n[s]))return;const r=t[s],o=n[s];if(r===o)return;const l=sl(s);if(o==null||o===!1){Vn(s)&&cl(e,s),e.removeAttribute(l);return}if(o===!0){Vn(s)&&Zi(e,s,!0),e.setAttribute(l,"");return}if(Vn(s)){Zi(e,s,o);return}e.setAttribute(l,String(o))})}function fl(e,t,n){if(t!==n){if(n){e.className=n;return}e.removeAttribute("class")}}function pl(e,t,n){const i=t??{},s=n??{};new Set([...Object.keys(i),...Object.keys(s)]).forEach(o=>{const l=i[o],c=s[o];if(l!==c){if(c==null){ul(e,o);return}hl(e,o,c)}})}function gl(e,t,n){t.forEach(({eventName:s,listener:r,options:o})=>{e.removeEventListener(s,r,o)});const i=[];return Object.entries(n).forEach(([s,r])=>{if(!si(s,r))return;const{eventName:o,options:l}=ol(s),c=a=>{r(ll(e,a))};e.addEventListener(o,c,l),i.push({eventName:o,listener:c,options:l})}),i}function Xs(e,t){const n=b.useRef({}),i=b.useRef([]);Zo(()=>{const s=n.current;return fl(e,s.className,t.className),pl(e,s.style,t.style),dl(e,s,t),i.current=gl(e,i.current,t),n.current=t,()=>{i.current.forEach(({eventName:r,listener:o,options:l})=>{e.removeEventListener(r,o,l)}),i.current=[]}},[e,t])}var st=b.forwardRef(({pluginKey:e,editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:r=null,getReferencedVirtualElement:o,options:l,children:c,...a},h)=>{const u=b.useRef(document.createElement("div")),f=b.useRef(Gs(e,"bubbleMenu")).current;Xs(u.current,a),typeof h=="function"?h(u.current):h&&(h.current=u.current);const{editor:p}=zs.useCurrentEditor(),g=t||p,x={updateDelay:n,resizeDelay:i,appendTo:s,pluginKey:f,shouldShow:r,getReferencedVirtualElement:o,options:l},w=b.useRef(x);w.current=x;const[y,S]=b.useState(!1),k=b.useRef(!0);return b.useEffect(()=>{if(g!=null&&g.isDestroyed)return;if(!g){console.warn("BubbleMenu component is not rendered inside of an editor component or does not have editor prop.");return}const M=u.current;M.style.visibility="hidden",M.style.position="absolute";const P=qs({...w.current,editor:g,element:M});g.registerPlugin(P);const A=w.current.pluginKey;return k.current=!0,S(!0),()=>{S(!1),g.unregisterPlugin(A),window.requestAnimationFrame(()=>{M.parentNode&&M.parentNode.removeChild(M)})}},[g]),b.useEffect(()=>{if(!(!y||!g||g.isDestroyed)){if(k.current){k.current=!1;return}g.view.dispatch(g.state.tr.setMeta(f,{type:"updateOptions",options:w.current}))}},[y,g,n,i,r,l,s,o,f]),ki.createPortal(c,u.current)});b.forwardRef(({pluginKey:e,editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:r=null,options:o,children:l,...c},a)=>{const h=b.useRef(document.createElement("div")),u=b.useRef(Gs(e,"floatingMenu")).current;Xs(h.current,c),typeof a=="function"?a(h.current):a&&(a.current=h.current);const{editor:f}=zs.useCurrentEditor(),p=t||f,g={updateDelay:n,resizeDelay:i,appendTo:s,pluginKey:u,shouldShow:r,options:o},x=b.useRef(g);x.current=g;const[w,y]=b.useState(!1),S=b.useRef(!0);return b.useEffect(()=>{if(p!=null&&p.isDestroyed)return;if(!p){console.warn("FloatingMenu component is not rendered inside of an editor component or does not have editor prop.");return}const k=h.current;k.style.visibility="hidden",k.style.position="absolute";const M=Ws({...x.current,editor:p,element:k});p.registerPlugin(M);const P=x.current.pluginKey;return S.current=!0,y(!0),()=>{y(!1),p.unregisterPlugin(P),window.requestAnimationFrame(()=>{k.parentNode&&k.parentNode.removeChild(k)})}},[p]),b.useEffect(()=>{if(!(!w||!p||p.isDestroyed)){if(S.current){S.current=!1;return}p.view.dispatch(p.state.tr.setMeta(u,{type:"updateOptions",options:x.current}))}},[w,p,n,i,r,o,s,u]),ki.createPortal(l,h.current)});function Yt(e,t){const{state:n}=t,i=n.selection.$anchor;let s=!1;if(i.depth)for(let r=i.depth;r>0;r--)i.node(r).type.name===e&&(t.dispatchTransaction&&t.dispatchTransaction(n.tr.delete(i.before(r),i.after(r)).scrollIntoView()),s=!0);else{const r=n.selection.node;r&&r.type.name===e&&(t.chain().deleteSelection().run(),s=!0)}if(!s){const r=i.pos;if(r){const o=n.tr.doc.nodeAt(r);o&&o.type.name===e&&(t.dispatchTransaction&&t.dispatchTransaction(n.tr.delete(r,r+o.nodeSize)),s=!0)}}return s}const ml=[{value:"note",label:"Note",icon:"Info"},{value:"tip",label:"Tip",icon:"Lightbulb"},{value:"important",label:"Important",icon:"AlertCircle"},{value:"warning",label:"Warning",icon:"TriangleAlert"},{value:"caution",label:"Caution",icon:"OctagonAlert"}];function xl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=L.useLocale(),{type:i,title:s,body:r}=mt.useAttributes(t,Tt.Callout.name,{type:"note",title:"",body:""}),[o,l]=b.useState(!1),[c,a]=b.useState("note"),[h,u]=b.useState(""),[f,p]=b.useState("");b.useEffect(()=>{o&&(a(i||"note"),u(s||""),p(r||""))},[o,i,s,r]);const g=b.useCallback(()=>{t&&(t.chain().updateAttributes(Tt.Callout.name,{type:c,title:h,body:f}).focus().run(),l(!1))},[t,c,h,f]),x=b.useCallback(()=>{l(!1)},[]),w=b.useCallback(()=>{Yt(Tt.Callout.name,t)},[t]),y=b.useCallback(()=>t.isActive(Tt.Callout.name),[t]);return e?d.jsx(st,{editor:t,options:{placement:"top",offset:8,flip:!0},pluginKey:"RichTextBubbleCallout",shouldShow:y,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsxs(m.Dialog,{onOpenChange:l,open:o,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{icon:"Pencil",tooltip:n("editor.callout.edit.title")})}),d.jsxs(m.DialogContent,{children:[d.jsx(m.DialogTitle,{children:n("editor.callout.edit.title")}),d.jsxs("div",{className:"richtext-space-y-4 richtext-py-4",children:[d.jsxs("div",{className:"richtext-space-y-2",children:[d.jsx(m.Label,{children:n("editor.callout.dialog.type")}),d.jsxs(Tt.Select,{onValueChange:a,value:c,children:[d.jsx(Tt.SelectTrigger,{children:d.jsx(Tt.SelectValue,{className:"richtext-text-accent",placeholder:n("editor.callout.dialog.type.placeholder")})}),d.jsx(Tt.SelectContent,{children:ml.map(S=>d.jsx(Tt.SelectItem,{value:S.value,children:n(`editor.callout.type.${S.value}`)},S.value))})]})]}),d.jsxs("div",{className:"richtext-space-y-2",children:[d.jsx(m.Label,{children:n("editor.callout.dialog.title.label")}),d.jsx(m.Input,{onChange:S=>u(S.target.value),placeholder:n("editor.callout.dialog.title.placeholder"),type:"text",value:h})]}),d.jsxs("div",{className:"richtext-space-y-2",children:[d.jsx(m.Label,{children:n("editor.callout.dialog.body.label")}),d.jsx(m.Input,{onChange:S=>p(S.target.value),placeholder:n("editor.callout.dialog.body.placeholder"),type:"text",value:f})]})]}),d.jsxs(m.DialogFooter,{children:[d.jsx(m.Button,{onClick:x,variant:"outline",children:n("editor.callout.dialog.button.cancel")}),d.jsx(m.Button,{onClick:g,children:n("editor.callout.dialog.button.apply")})]})]})]}),d.jsx(m.ActionButton,{action:w,icon:"Trash2",tooltip:n("editor.delete")})]})}):d.jsx(d.Fragment,{})}function bl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=L.useLocale(),i=b.useCallback(()=>t.isActive(Ji.MultipleColumnNode.name),[t]),s=b.useCallback(()=>Yt(Ji.MultipleColumnNode.name,t),[t]),r=b.useCallback(()=>t.chain().focus().addColBefore().run(),[t]),o=b.useCallback(()=>t.chain().focus().addColAfter().run(),[t]),l=b.useCallback(()=>t.chain().focus().deleteCol().run(),[t]);return e?d.jsx(st,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleColumns",shouldShow:i,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{action:r,icon:"ColumnAddLeft",tooltip:n("editor.table.menu.insertColumnBefore")}),d.jsx(m.ActionButton,{action:o,icon:"ColumnAddRight",tooltip:n("editor.table.menu.insertColumnAfter")}),d.jsx(m.ActionButton,{action:l,icon:"DeleteColumn",tooltip:n("editor.table.menu.deleteColumn")}),d.jsx(m.ActionButton,{action:s,icon:"Trash2",tooltip:n("editor.table.menu.delete_column")})]})}):d.jsx(d.Fragment,{})}function wl(e){return e.isActive(m.ImageBlock.name)?m.ImageBlock.name:m.Image.name}function Qi(e){return e.getAttributes(wl(e))}function Zs(e,t){return e.isActive(m.Image.name,t)||e.isActive(m.ImageBlock.name,t)}function yl(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,r)=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[r],action:()=>e.commands.updateImage({width:L.IMAGE_SIZE[s]}),isActive:()=>Zs(e,{width:L.IMAGE_SIZE[s]})}}))}function vl(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,r)=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[r],action:()=>e.commands.updateImageGif({width:L.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:L.IMAGE_SIZE[s]})}}))}function Sl(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImage)==null?void 0:o.call(r,s)},isActive:()=>Zs(e,{align:s})||!1,disabled:!1}}))}function Cl(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImageGif)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function kl(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImageMermaid)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function El(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImageDrawer)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function _l(e){return[{type:"flex-start",icon:"AlignLeft",tooltip:"Align left"},{type:"center",icon:"AlignCenter",tooltip:"Align center"},{type:"flex-end",icon:"AlignRight",tooltip:"Align right"}].map(n=>({type:`video-align-${n.type}`,component:m.ActionButton,componentProps:{tooltip:n.tooltip,icon:n.icon,action:()=>e.commands.updateVideo({align:n.type}),isActive:()=>e.getAttributes("video").align===n.type}}))}function Tl(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,r)=>({type:`video-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[r],action:()=>e.commands.updateVideo({width:L.VIDEO_SIZE[s]}),isActive:()=>e.isActive("video",{width:L.VIDEO_SIZE[s]})}}))}function Al(e,t){return[{type:"flipX",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.tooltip.flipX"),icon:"FlipX",action:()=>{const n=Qi(e),{flipX:i}=n;e.chain().focus(void 0,{scrollIntoView:!1}).updateImage({flipX:!i}).run()}}},{type:"flipY",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.tooltip.flipY"),icon:"FlipY",action:()=>{const n=Qi(e),{flipY:i}=n;e.chain().focus(void 0,{scrollIntoView:!1}).updateImage({flipY:!i}).run()}}},...yl(e,t),...Sl(e,t),{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;_.deleteSelection(n,i)}}}]}function Il(e,t){return[...vl(e,t),...Cl(e,t),{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;_.deleteSelection(n,i)}}}]}function Dl(e,t){return[...kl(e,t),{type:"edit",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;_.deleteSelection(n,i)}}}]}function Ml(e,t){return[...El(e,t),{type:"edit",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;_.deleteSelection(n,i)}}}]}function Ol(e,t){return[...Tl(e,t),..._l(e),{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;_.deleteSelection(n,i)}}}]}let we=!1;function Rl({editor:e,attrs:t,extension:n}){const[i,s]=b.useState(!1),r=b.useRef(null),o=b.useRef(null),{alt:l,align:c}=t,a=n==null?void 0:n.options.upload,h=()=>{(async()=>{const E=document.querySelector("#easydrawer");E&&(r.current=new Xi.Editor(E,{wheelEventsEnabled:!1,disableZoom:!0}),o.current=Xi.makeDropdownToolbar(r.current),o.current.addDefaultToolWidgets(),r.current.loadFromSVG(decodeURIComponent(l)))})()};b.useEffect(()=>{i&&setTimeout(()=>{h()},200)},[i]);const u=async()=>{if(r.current){const A=r.current.toSVG(),E=A.outerHTML,D=`drawer-${en.shortId()}.svg`;let Y=en.i(A.outerHTML);if(a){const Q=m.dataURLtoFile(Y,D);Y=await a(Q)}e==null||e.chain().focus().setDrawer({type:"drawer",src:Y,alt:encodeURIComponent(E),width:426,height:212},!!E).run(),e==null||e.commands.setAlignImageDrawer(c)}s(!1)},f=A=>{const E=r.current.toolController.getPrimaryTools()[2],D=o.current.getWidgetById("pen-1");E&&D&&(E.setColor(A),D.serializeState())},p=A=>{const E=r.current.toolController.getPrimaryTools()[2],D=o.current.getWidgetById("pen-1");E&&D&&(E.setThickness(A),D.serializeState())},g=A=>{const E=r.current.toolController.getPrimaryTools()[3],D=o.current.getWidgetById("pen-2");E&&D&&(E.setColor(A),D.serializeState())},x=A=>{const E=o.current.getWidgetById("shape");E&&E.setShapeType(A)},w=A=>{const E=r.current.toolController.getPrimaryTools()[5],D=o.current.getWidgetById("shape");E&&D&&(E.setColor(A),D.serializeState())},y=A=>{const E=r.current.toolController.getPrimaryTools()[5],D=o.current.getWidgetById("shape");E&&D&&(E.setThickness(A),D.serializeState())},S=A=>{const E=r.current.toolController.getPrimaryTools()[5],D=o.current.getWidgetById("shape");E&&D&&(E.setBorderColor(A),D.serializeState())},k=()=>{if(we){for(;r.current.history.redoStackSize>0;)r.current.history.redo();we=!1;return}r.current.history.undo()},M=()=>{we||r.current.history.redo()},P=()=>{if(!we){for(;r.current.history.undoStackSize>0;)k();we=!0}};return d.jsxs(m.Dialog,{onOpenChange:s,open:i,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{action:()=>s(!0),icon:"Pencil",tooltip:"Edit Drawer"})}),d.jsxs(m.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[d.jsx(m.DialogTitle,{children:"Edit Drawer"}),d.jsxs("div",{style:{height:"100%",borderWidth:1,background:"white",position:"relative"},children:[d.jsx("div",{className:"richtext-size-full",id:"easydrawer"}),d.jsx(qe.ControlDrawer,{changeBorderColorShape:S,changeColorShape:w,changeShape:x,onClear:P,onRedo:M,onThicknessChange:y,onUndo:k,refEditor:r,setColorHighlight:g,setColorPen:f,setThicknessPen:p})]}),d.jsx(m.DialogFooter,{children:d.jsx(m.Button,{onClick:u,type:"button",children:"Save changes"})})]})]})}function jl({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?d.jsx(b.Fragment,{children:e.type==="divider"?d.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):d.jsx(i,{...e.componentProps,disabled:t||((s=e==null?void 0:e.componentProps)==null?void 0:s.disabled),editor:n})}):d.jsx(d.Fragment,{})}function Nl(){const{lang:e,t}=L.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=mt.useAttributes(i,qe.Drawer.name),r=m.useExtension(qe.Drawer.name),o=({editor:c})=>{const{selection:a}=c.view.state,{$from:h,to:u}=a;let f=!1;return c.view.state.doc.nodesBetween(h.pos,u,p=>{if(p.type.name===qe.Drawer.name)return f=!0,!1}),f},l=b.useMemo(()=>Ml(i,t),[i,e,t]);return n?d.jsx(st,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleDrawer",shouldShow:o,children:l!=null&&l.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:l==null?void 0:l.map((c,a)=>c.type==="edit"&&(s!=null&&s.src)?d.jsx(Rl,{attrs:s,editor:i,extension:r},`bubbleMenu-drawer-${a}`):d.jsx(jl,{editor:i,item:c},`bubbleMenu-drawer-${a}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}const Qs=({width:e,maxWidth:t,height:n,onOk:i,children:s})=>{const{t:r}=L.useLocale(),[o,l]=b.useState({width:"",height:"",maxWidth:""});b.useEffect(()=>{l({width:e,height:n,maxWidth:t})},[n,t,e]);function c(a){a.preventDefault(),a.stopPropagation(),i(o)}return d.jsxs(It.Popover,{modal:!0,children:[d.jsx(It.PopoverTrigger,{asChild:!0,children:s}),d.jsx(It.PopoverContent,{children:d.jsxs("form",{className:"richtext-flex richtext-flex-col richtext-gap-2",onSubmit:c,children:[d.jsx(m.Label,{className:"mb-[6px]",children:"Width"}),d.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:d.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:d.jsx(m.Input,{onChange:a=>l({...o,width:a.target.value}),required:!0,type:"number",value:o.width})})}),d.jsx(m.Label,{className:"mb-[6px]",children:"Max Width"}),d.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:d.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:d.jsx(m.Input,{onChange:a=>l({...o,maxWidth:a.target.value}),required:!0,type:"number",value:o.maxWidth})})}),d.jsx(m.Label,{className:"mb-[6px]",children:"Height"}),d.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:d.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:d.jsx(m.Input,{onChange:a=>l({...o,height:a.target.value}),required:!0,type:"number",value:o.height})})}),d.jsx(m.Button,{className:"richtext-mt-2 richtext-self-end",type:"submit",children:r("editor.link.dialog.button.apply")})]})})]})},$t=new Map;function Bl(e){const t=e.options.element;$t.has("width")||$t.set("width",t.clientWidth),$t.has("width")&&$t.get("width")<=0&&$t.set("width",t.clientWidth);const n={attributes:!0,childList:!0,subtree:!0},i=function(){$t.set("width",t.clientWidth)},s=new MutationObserver(i);return s.observe(t,n),e.on("destroy",()=>{s.disconnect()}),{width:$t.get("width")}}function Ll(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=L.useLocale(),{width:i}=Bl(t),s=mt.useAttributes(t,xe.Excalidraw.name,{defaultShowPicker:!1,createUser:"",width:0,height:0}),{defaultShowPicker:r,createUser:o,width:l,height:c}=s,a=b.useCallback(p=>{t.chain().updateAttributes(xe.Excalidraw.name,p).setNodeSelection(t.state.selection.from).focus().run()},[t]),h=b.useCallback(()=>{const p=m.EVENTS.EXCALIDRAW(t.id);m.emit(p,s)},[t,s]),u=b.useCallback(()=>t.isActive(xe.Excalidraw.name),[t]),f=b.useCallback(()=>Yt(xe.Excalidraw.name,t),[t]);return b.useEffect(()=>{r&&(h(),t.chain().updateAttributes(xe.Excalidraw.name,{defaultShowPicker:!1}).focus().run())},[o,r,t,h]),e?d.jsx(st,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleExcalidraw",shouldShow:u,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{action:h,icon:"Pencil",tooltip:n("editor.edit")}),d.jsx(Qs,{height:c,maxWidth:i,onOk:a,width:l,children:d.jsx(m.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),d.jsx(m.ActionButton,{action:f,icon:"Trash2",tooltip:n("editor.delete")})]})}):d.jsx(d.Fragment,{})}function Pl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=L.useLocale(),{width:i,height:s,src:r}=mt.useAttributes(t,Qt.Iframe.name,{width:0,height:0,src:"",defaultShowPicker:!1}),[o,l]=b.useState(!1),[c,a]=b.useState(""),h=b.useCallback(w=>{var y;(y=w==null?void 0:w.preventDefault)==null||y.call(w),l(!1)},[l]);b.useEffect(()=>{o&&a(r)},[o,r]);const u=b.useCallback(w=>{var S;(S=w==null?void 0:w.preventDefault)==null||S.call(w);const y=Qt.getServiceSrc(c);t.chain().updateAttributes(Qt.Iframe.name,{src:(y==null?void 0:y.src)||c}).setNodeSelection(t.state.selection.from).focus().run(),l(!1)},[t,c,l]),f=b.useCallback(()=>{window.open(r,"_blank")},[r]),p=b.useCallback(w=>{t.chain().updateAttributes(Qt.Iframe.name,w).setNodeSelection(t.state.selection.from).focus().run()},[t]),g=b.useCallback(()=>t.isActive(Qt.Iframe.name)&&!r,[t,r]),x=b.useCallback(()=>Yt(Qt.Iframe.name,t),[t]);return e?d.jsx(d.Fragment,{children:d.jsx(st,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleIframe",shouldShow:g,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{action:f,icon:"Eye",tooltip:"Visit Link"}),d.jsxs(m.Dialog,{onOpenChange:l,open:o,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{icon:"Pencil",tooltip:"Open Edit Link"})}),d.jsxs(m.DialogContent,{children:[d.jsx(m.DialogHeader,{children:d.jsx(m.DialogTitle,{children:"Edit Link Iframe"})}),d.jsx(m.Input,{autoFocus:!0,onInput:w=>a(w.target.value),placeholder:"Enter link",type:"url",value:c}),d.jsxs(m.DialogFooter,{children:[d.jsx(m.Button,{onClick:h,type:"button",children:"Cancel"}),d.jsx(m.Button,{onClick:u,type:"button",children:"OK"})]})]})]}),d.jsx(Qs,{height:s,onOk:p,width:i,children:d.jsx(m.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),d.jsx(m.ActionButton,{action:x,icon:"Trash2",tooltip:n("editor.delete")})]})})}):d.jsx(d.Fragment,{})}function Ul({children:e,visible:t,toggleVisible:n}){const{t:i}=L.useLocale(),s=m.useEditorInstance(),r=mt.useAttributes(s,mt.Katex.name,{text:"",macros:""}),{text:o,macros:l}=r,[c,a]=b.useState(decodeURIComponent(o||"")),[h,u]=b.useState(decodeURIComponent(l||""));b.useEffect(()=>{t&&(a(decodeURIComponent(o||"")),u(decodeURIComponent(l||"")))},[t]);const f=b.useCallback(()=>{s.chain().focus().setKatex({text:encodeURIComponent(c),macros:encodeURIComponent(h)}).run(),a(""),u(""),n(!1)},[s,c,h,n]),p=b.useMemo(()=>{try{return Po.renderToString(c,{macros:mt.safeJSONParse(h||"")})}catch{return c}},[c,h]),g=b.useMemo(()=>`${c}`.trim()?p:null,[c,p]);return d.jsxs(m.Dialog,{onOpenChange:n,open:t,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:e}),d.jsxs(m.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[d.jsx(m.DialogTitle,{children:i("editor.formula.dialog.text")}),d.jsx("div",{style:{height:"100%",border:"1px solid hsl(var(--border))"},children:d.jsxs("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[d.jsxs("div",{className:"richtext-flex-1",children:[d.jsx(m.Label,{className:"mb-[6px]",children:"Expression"}),d.jsx(ni.Textarea,{autoFocus:!0,className:"richtext-mb-[10px]",onChange:x=>a(x.target.value),placeholder:"Text",required:!0,rows:10,value:c,style:{color:"hsl(var(--foreground))"}}),d.jsx(m.Label,{className:"mb-[6px]",children:"Macros"}),d.jsx(ni.Textarea,{onChange:x=>u(x.target.value),placeholder:"Macros",rows:10,value:h,style:{color:"hsl(var(--foreground))"}})]}),d.jsx("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:g||""},style:{height:"100%",borderWidth:1,minHeight:500,background:"#fff"}})]})}),d.jsx(m.DialogFooter,{children:d.jsx(m.Button,{onClick:f,type:"button",children:"Save changes"})})]})]})}function $l(){const e=m.useEditableEditor(),t=m.useEditorInstance(),[n,i]=b.useState(!1),s=b.useCallback(()=>t.isActive(mt.Katex.name),[t]),r=b.useCallback(()=>Yt(mt.Katex.name,t),[t]);return e?d.jsx(st,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleKatex",shouldShow:s,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(Ul,{toggleVisible:i,visible:n,children:d.jsx(m.ActionButton,{action:()=>i(!n),tooltip:"Edit",children:d.jsx(zt.Pencil,{size:16})})}),d.jsx(m.ActionButton,{action:r,tooltip:"Delete",children:d.jsx(zt.Trash2,{size:16})})]})}):d.jsx(d.Fragment,{})}function Fl(e){const{t}=L.useLocale();return d.jsxs("div",{className:"richtext-flex richtext-flex-nowrap",children:[d.jsx(m.ActionButton,{disabled:!(e!=null&&e.link),icon:"ExternalLink",tooltip:t("editor.link.open.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{window.open(e==null?void 0:e.link,"_blank")}}),d.jsx(m.ActionButton,{icon:"Pencil",tooltip:t("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onEdit()}}),d.jsx(m.ActionButton,{icon:"Unlink",tooltip:t("editor.link.unlink.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onClear()}})]})}function Vl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),[n,i]=b.useState(!1),s=mt.useAttributes(t,We.Link.name),r=s==null?void 0:s.href,o=b.useCallback(({editor:h})=>h.isActive(We.Link.name),[]),l=(h,u,f)=>{const p=t.state.selection,{from:g}=p,x=(u==null?void 0:u.length)??0,w=g+x;t.chain().extendMarkRange("link").insertContent({type:"text",text:u,marks:[{type:"link",attrs:{href:h,target:f?"_blank":""}}]}).setLink({href:h}).setTextSelection({from:g,to:w}).focus().run(),i(!1)},c=b.useCallback(()=>{t.chain().extendMarkRange("link").unsetLink().focus().run(),i(!1)},[t]),a=()=>{i(!1)};return e?d.jsx(st,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleLink",shouldShow:o,children:d.jsx(d.Fragment,{children:n?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-4 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(We.LinkEditBlock,{editor:t,onClose:a,onSetLink:l})}):d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(Fl,{editor:t,link:r,onClear:c,onEdit:()=>{i(!0)}})})})}):d.jsx(d.Fragment,{})}function Ei({item:e,disabled:t,editor:n}){const i=e.component;return i?d.jsx(b.Fragment,{children:e.type==="divider"?d.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):d.jsx(i,{...e.componentProps,disabled:t||(e==null?void 0:e.componentdisabled),editor:n})}):d.jsx(d.Fragment,{})}function Hl(e){return e.type.name===m.Image.name||e.type.name===m.ImageBlock.name}function zl(e){return e.type.name===Lo.ImageGif.name}function Kl(e){return e.type.name===m.Video.name}function ql(){const{lang:e,t}=L.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:o})=>{const{selection:l}=o.view.state,{$from:c,to:a}=l;let h=!1;return o.view.state.doc.nodesBetween(c.pos,a,u=>{if(Hl(u))return h=!0,!1}),h},r=b.useMemo(()=>Al(i,t),[i,e,t]);return n?d.jsx(st,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImage",shouldShow:s,children:r!=null&&r.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:r==null?void 0:r.map((o,l)=>d.jsx(Ei,{editor:i,item:o},`bubbleMenu-image-${l}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function Wl(){const{lang:e,t}=L.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:o})=>{const{selection:l}=o.view.state,{$from:c,to:a}=l;let h=!1;return o.view.state.doc.nodesBetween(c.pos,a,u=>{if(zl(u))return h=!0,!1}),h},r=b.useMemo(()=>Il(i,t),[i,t,e]);return n?d.jsx(st,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImageGif",shouldShow:s,children:r!=null&&r.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:r==null?void 0:r.map((o,l)=>d.jsx(Ei,{editor:i,item:o},`bubbleMenu-image-gif-${l}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function Gl(){const{t:e}=L.useLocale(),t=m.useEditableEditor(),n=m.useEditorInstance(),i=({editor:r})=>{const{selection:o}=r.view.state,{$from:l,to:c}=o;let a=!1;return r.view.state.doc.nodesBetween(l.pos,c,h=>{if(Kl(h))return a=!0,!1}),a},s=b.useMemo(()=>Ol(n,e),[n,e]);return t?d.jsx(st,{editor:n,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleVideo",shouldShow:i,children:s!=null&&s.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:s==null?void 0:s.map((r,o)=>d.jsx(Ei,{editor:n,item:r},`bubbleMenu-video-${o}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}const ts=`graph TB
2
+ a-->b`,Yl=({editor:e,attrs:t,extension:n})=>{const{alt:i,align:s}=t,[r,o]=b.useState(decodeURIComponent(i??ts)),[l,c]=b.useState(""),[a,h]=b.useState(!1),u=b.useRef(null),[f,p]=b.useState(null),g=n==null?void 0:n.options.upload,x=b.useCallback(k=>{k&&import("mermaid").then(M=>{p(M.default)})},[]),w=async k=>{try{const{svg:M}=await f.render("mermaid-svg",k);c(M)}catch{c("")}},y=()=>{f.initialize({darkMode:!1,startOnLoad:!1,fontSize:12,theme:"base"}),w(r)};b.useEffect(()=>{f&&a&&y()},[f,a]),b.useEffect(()=>{f&&a&&w(r)},[f,r]);const S=async()=>{if(r!==""){if(r){const k=u.current.querySelector("svg"),{width:M,height:P}=k.getBoundingClientRect(),A=`mermaid-${en.shortId()}.svg`;let E=en.i(k.outerHTML);if(g){const D=m.dataURLtoFile(E,A);E=await g(D)}e==null||e.chain().focus().setMermaid({type:"mermaid",src:E,alt:encodeURIComponent(r),width:M,height:P},!!r).run(),e==null||e.commands.setAlignImageMermaid(s)}h(!1)}};return d.jsxs(m.Dialog,{onOpenChange:h,open:a,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{action:()=>h(!0),icon:"Pencil",tooltip:"Edit Mermaid"})}),d.jsxs(m.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[d.jsx(m.DialogTitle,{children:"Edit Mermaid"}),d.jsx("div",{ref:x,style:{height:"100%",border:"1px solid hsl(var(--border))"},children:d.jsxs("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[d.jsx(ni.Textarea,{autoFocus:!0,className:"richtext-flex-1",defaultValue:ts,onChange:k=>o(k.target.value),placeholder:"Text",required:!0,rows:10,value:r,style:{color:"hsl(var(--foreground))"}}),d.jsx("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:l},ref:u,style:{height:"100%",border:"1px solid hsl(var(--border))",minHeight:500}})]})}),d.jsx(m.DialogFooter,{children:d.jsx(m.Button,{onClick:S,type:"button",children:"Save changes"})})]})]})};function Jl({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?d.jsx(b.Fragment,{children:e.type==="divider"?d.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):d.jsx(i,{...e.componentProps,disabled:t||((s=e==null?void 0:e.componentProps)==null?void 0:s.disabled),editor:n})}):d.jsx(d.Fragment,{})}function Xl(e){return e.type.name===ii.Mermaid.name}function Zl(){const{lang:e,t}=L.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=mt.useAttributes(i,ii.Mermaid.name),r=m.useExtension(ii.Mermaid.name),o=({editor:c})=>{const{selection:a}=c.view.state,{$from:h,to:u}=a;let f=!1;return c.view.state.doc.nodesBetween(h.pos,u,p=>{if(Xl(p))return f=!0,!1}),f},l=b.useMemo(()=>Dl(i,t),[i,e,t]);return n?d.jsx(st,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleMermaid",shouldShow:o,children:l!=null&&l.length?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:l==null?void 0:l.map((c,a)=>c.type==="edit"&&(s!=null&&s.src)?d.jsx(Yl,{attrs:s,editor:i,extension:r},`bubbleMenu-mermaid-${a}`):d.jsx(Jl,{editor:i,item:c},`bubbleMenu-mermaid-${a}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function Ql({hiddenActions:e=[]}){var x,w,y,S,k,M,P,A,E,D,Y,Q,ut,lt,C,v,N,J;const{t}=L.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:U})=>_.isActive(U.view.state,Hs.Table.name),r=U=>e.includes(U);function o(){i.chain().focus().addColumnBefore().run()}function l(){i.chain().focus().addColumnAfter().run()}function c(){i.chain().focus().deleteColumn().run()}function a(){i.chain().focus().addRowBefore().run()}function h(){i.chain().focus().addRowAfter().run()}function u(){i.chain().focus().deleteRow().run()}function f(){i.chain().focus().mergeCells().run()}function p(){i==null||i.chain().focus().splitCell().run()}function g(){i.chain().focus().deleteTable().run()}return n?d.jsx(st,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTable",shouldShow:s,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[!r("addColumnBefore")&&d.jsx(m.ActionButton,{action:o,disabled:!((w=(x=i==null?void 0:i.can())==null?void 0:x.addColumnBefore)!=null&&w.call(x)),icon:"BetweenHorizonalEnd",tooltip:t("editor.table.menu.insertColumnBefore"),tooltipOptions:{sideOffset:15}}),!r("addColumnAfter")&&d.jsx(m.ActionButton,{action:l,disabled:!((S=(y=i==null?void 0:i.can())==null?void 0:y.addColumnAfter)!=null&&S.call(y)),icon:"BetweenHorizonalStart",tooltip:t("editor.table.menu.insertColumnAfter"),tooltipOptions:{sideOffset:15}}),!r("deleteColumn")&&d.jsx(m.ActionButton,{action:c,disabled:!((M=i==null?void 0:(k=i.can()).deleteColumn)!=null&&M.call(k)),icon:"DeleteColumn",tooltip:t("editor.table.menu.deleteColumn"),tooltipOptions:{sideOffset:15}}),d.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!r("addRowAbove")&&d.jsx(m.ActionButton,{action:a,disabled:!((A=i==null?void 0:(P=i.can()).addRowBefore)!=null&&A.call(P)),icon:"BetweenVerticalEnd",tooltip:t("editor.table.menu.insertRowAbove"),tooltipOptions:{sideOffset:15}}),!r("addRowBelow")&&d.jsx(m.ActionButton,{action:h,disabled:!((D=(E=i==null?void 0:i.can())==null?void 0:E.addRowAfter)!=null&&D.call(E)),icon:"BetweenVerticalStart",tooltip:t("editor.table.menu.insertRowBelow"),tooltipOptions:{sideOffset:15}}),!r("deleteRow")&&d.jsx(m.ActionButton,{action:u,disabled:!((Q=(Y=i==null?void 0:i.can())==null?void 0:Y.deleteRow)!=null&&Q.call(Y)),icon:"DeleteRow",tooltip:t("editor.table.menu.deleteRow"),tooltipOptions:{sideOffset:15}}),d.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!r("mergeCells")&&d.jsx(m.ActionButton,{action:f,disabled:!((lt=(ut=i==null?void 0:i.can())==null?void 0:ut.mergeCells)!=null&&lt.call(ut)),icon:"TableCellsMerge",tooltip:t("editor.table.menu.mergeCells"),tooltipOptions:{sideOffset:15}}),!r("splitCells")&&d.jsx(m.ActionButton,{action:p,disabled:!((v=(C=i==null?void 0:i.can())==null?void 0:C.splitCell)!=null&&v.call(C)),icon:"TableCellsSplit",tooltip:t("editor.table.menu.splitCells"),tooltipOptions:{sideOffset:15}}),d.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!r("deleteTable")&&d.jsx(m.ActionButton,{action:g,disabled:!((J=(N=i==null?void 0:i.can())==null?void 0:N.deleteTable)!=null&&J.call(N)),icon:"Trash2",tooltip:t("editor.table.menu.deleteTable"),tooltipOptions:{sideOffset:15}})]})}):d.jsx(d.Fragment,{})}function tc(){const{t:e}=L.useLocale(),[t,n]=b.useState(!1),i=m.useEditorInstance(),s=b.useMemo(()=>{var o,l;return(l=(o=qo.renderCommandListDefault({t:e}))==null?void 0:o[0])==null?void 0:l.commands},[e]),r=b.useMemo(()=>{var l;return(l=s==null?void 0:s.find(c=>{var a;return(a=c==null?void 0:c.isActive)==null?void 0:a.call(c,i)}))==null?void 0:l.label},[i.state.selection.ranges,t,i,s,e]);return d.jsxs(It.Popover,{modal:!0,onOpenChange:n,open:t,children:[d.jsx(It.PopoverTrigger,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:d.jsxs(m.ActionButton,{dataState:!!r,children:[r?d.jsx(d.Fragment,{children:r}):d.jsx(d.Fragment,{children:e("editor.paragraph.tooltip")}),d.jsx(m.IconComponent,{className:"richtext-ml-1 richtext-size-3 richtext-text-zinc-500",name:"MenuDown"})]})}),d.jsx(It.PopoverContent,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:s==null?void 0:s.map(o=>{var c;const l=(c=o==null?void 0:o.isActive)==null?void 0:c.call(o,i);return d.jsxs("div",{className:"richtext-flex richtext-w-full richtext-items-center richtext-gap-3 richtext-rounded-sm !richtext-border-none !richtext-bg-transparent richtext-px-2 richtext-py-1.5 richtext-text-left richtext-text-sm richtext-text-foreground !richtext-outline-none richtext-transition-colors hover:!richtext-bg-accent",onClick:a=>{a.preventDefault(),o.action({editor:i,range:i.state.selection.ranges}),n(!1)},children:[d.jsxs("div",{className:"!richtext-min-w-[20px]",children:[l&&d.jsx(zt.Check,{size:16}),!r&&o.label===e("editor.paragraph.tooltip")&&!l&&d.jsx(zt.Check,{size:16})]}),d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:[o.iconName&&d.jsx(m.IconComponent,{className:"!richtext-mr-1 !richtext-text-lg",name:o.iconName}),o.label]})]},o.name)})})]})}function ec(){return d.jsxs(d.Fragment,{children:[d.jsx(tc,{}),d.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(Fo.RichTextBold,{}),d.jsx(Ko.RichTextItalic,{}),d.jsx(Go.RichTextUnderline,{}),d.jsx(Wo.RichTextStrike,{}),d.jsx(Vo.RichTextCode,{}),d.jsx(We.RichTextLink,{}),d.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(Ho.RichTextColor,{}),d.jsx(zo.RichTextHighlight,{}),d.jsx(Ks.RichTextAlign,{})]})}function nc({buttonBubble:e}){const t=m.useEditorInstance(),n=m.useEditableEditor(),i=({editor:s})=>{const{selection:r}=s.view.state,{$from:o,to:l}=r;return s.isActive("codeBlock")||o.pos===l?!1:r instanceof K.TextSelection};return n?d.jsx(st,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleText",shouldShow:i,children:e?d.jsx(d.Fragment,{children:e}):d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(ec,{})})}):d.jsx(d.Fragment,{})}function ic(){const{t:e}=L.useLocale(),t=m.useEditableEditor(),n=m.useEditorInstance(),[i,s]=b.useState(!1),r=b.useCallback(({editor:c})=>c.isActive(Fn.Twitter.name),[]),o=c=>{n.commands.updateTweet({src:c}),s(!1)},l=b.useCallback(()=>Yt(Fn.Twitter.name,n),[n]);return t?d.jsx(st,{editor:n,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTwitter",shouldShow:r,children:d.jsx(d.Fragment,{children:i?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-4 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(Fn.FormEditLinkTwitter,{editor:n,onSetLink:o})}):d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{icon:"Pencil",tooltip:e("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{s(!0)}}),d.jsx(m.ActionButton,{action:l,icon:"Trash",tooltip:e("editor.delete"),tooltipOptions:{sideOffset:15}})]})})}):d.jsx(d.Fragment,{})}const xt=()=>new Map,ri=e=>{const t=xt();return e.forEach((n,i)=>{t.set(i,n)}),t},Ot=(e,t,n)=>{let i=e.get(t);return i===void 0&&e.set(t,i=n()),i},sc=(e,t)=>{const n=[];for(const[i,s]of e)n.push(t(s,i));return n},rc=(e,t)=>{for(const[n,i]of e)if(t(i,n))return!0;return!1},Kt=()=>new Set,Hn=e=>e[e.length-1],oc=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},qt=Array.from,_i=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},Ti=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},lc=(e,t)=>{const n=new Array(e);for(let i=0;i<e;i++)n[i]=t(i,n);return n},oe=Array.isArray;class tr{constructor(){this._observers=xt()}on(t,n){return Ot(this._observers,t,Kt).add(n),n}once(t,n){const i=(...s)=>{this.off(t,i),n(...s)};this.on(t,i)}off(t,n){const i=this._observers.get(t);i!==void 0&&(i.delete(n),i.size===0&&this._observers.delete(t))}emit(t,n){return qt((this._observers.get(t)||xt()).values()).forEach(i=>i(...n))}destroy(){this._observers=xt()}}const bt=Math.floor,Ge=Math.abs,le=(e,t)=>e<t?e:t,Lt=(e,t)=>e>t?e:t,er=e=>e!==0?e<0:1/e<0,es=1,ns=2,zn=4,Kn=8,Ce=32,Dt=64,nt=128,cc=1<<29,Sn=31,oi=63,Ht=127,ac=2147483647,nn=Number.MAX_SAFE_INTEGER,is=Number.MIN_SAFE_INTEGER,uc=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&bt(e)===e),nr=String.fromCharCode,hc=e=>e.toLowerCase(),dc=/^\s*/g,fc=e=>e.replace(dc,""),pc=/([A-Z])/g,ss=(e,t)=>fc(e.replace(pc,n=>`${t}${hc(n)}`)),gc=e=>{const t=unescape(encodeURIComponent(e)),n=t.length,i=new Uint8Array(n);for(let s=0;s<n;s++)i[s]=t.codePointAt(s);return i},ke=typeof TextEncoder<"u"?new TextEncoder:null,mc=e=>ke.encode(e),xc=ke?mc:gc;let Se=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Se&&Se.decode(new Uint8Array).length===1&&(Se=null);const bc=(e,t)=>lc(t,()=>e).join("");class Ne{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Be=()=>new Ne,wc=e=>{const t=Be();return e(t),gt(t)},yc=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},gt=e=>{const t=new Uint8Array(yc(e));let n=0;for(let i=0;i<e.bufs.length;i++){const s=e.bufs[i];t.set(s,n),n+=s.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},vc=(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(Lt(n,t)*2),e.cpos=0)},q=(e,t)=>{const n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},li=q,I=(e,t)=>{for(;t>Ht;)q(e,nt|Ht&t),t=bt(t/128);q(e,Ht&t)},Ai=(e,t)=>{const n=er(t);for(n&&(t=-t),q(e,(t>oi?nt:0)|(n?Dt:0)|oi&t),t=bt(t/64);t>0;)q(e,(t>Ht?nt:0)|Ht&t),t=bt(t/128)},ci=new Uint8Array(3e4),Sc=ci.length/3,Cc=(e,t)=>{if(t.length<Sc){const n=ke.encodeInto(t,ci).written||0;I(e,n);for(let i=0;i<n;i++)q(e,ci[i])}else at(e,xc(t))},kc=(e,t)=>{const n=unescape(encodeURIComponent(t)),i=n.length;I(e,i);for(let s=0;s<i;s++)q(e,n.codePointAt(s))},ee=ke&&ke.encodeInto?Cc:kc,Cn=(e,t)=>{const n=e.cbuf.length,i=e.cpos,s=le(n-i,t.length),r=t.length-s;e.cbuf.set(t.subarray(0,s),i),e.cpos+=s,r>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(Lt(n*2,r)),e.cbuf.set(t.subarray(s)),e.cpos=r)},at=(e,t)=>{I(e,t.byteLength),Cn(e,t)},Ii=(e,t)=>{vc(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Ec=(e,t)=>Ii(e,4).setFloat32(0,t,!1),_c=(e,t)=>Ii(e,8).setFloat64(0,t,!1),Tc=(e,t)=>Ii(e,8).setBigInt64(0,t,!1),rs=new DataView(new ArrayBuffer(4)),Ac=e=>(rs.setFloat32(0,e),rs.getFloat32(0)===e),ce=(e,t)=>{switch(typeof t){case"string":q(e,119),ee(e,t);break;case"number":uc(t)&&Ge(t)<=ac?(q(e,125),Ai(e,t)):Ac(t)?(q(e,124),Ec(e,t)):(q(e,123),_c(e,t));break;case"bigint":q(e,122),Tc(e,t);break;case"object":if(t===null)q(e,126);else if(oe(t)){q(e,117),I(e,t.length);for(let n=0;n<t.length;n++)ce(e,t[n])}else if(t instanceof Uint8Array)q(e,116),at(e,t);else{q(e,118);const n=Object.keys(t);I(e,n.length);for(let i=0;i<n.length;i++){const s=n[i];ee(e,s),ce(e,t[s])}}break;case"boolean":q(e,t?120:121);break;default:q(e,127)}};class os extends Ne{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&I(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const ls=e=>{e.count>0&&(Ai(e.encoder,e.count===1?e.s:-e.s),e.count>1&&I(e.encoder,e.count-2))};class Ye{constructor(){this.encoder=new Ne,this.s=0,this.count=0}write(t){this.s===t?this.count++:(ls(this),this.count=1,this.s=t)}toUint8Array(){return ls(this),gt(this.encoder)}}const cs=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);Ai(e.encoder,t),e.count>1&&I(e.encoder,e.count-2)}};class qn{constructor(){this.encoder=new Ne,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(cs(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return cs(this),gt(this.encoder)}}class Ic{constructor(){this.sarr=[],this.s="",this.lensE=new Ye}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new Ne;return this.sarr.push(this.s),this.s="",ee(t,this.sarr.join("")),Cn(t,this.lensE.toUint8Array()),gt(t)}}const _t=e=>new Error(e),ft=()=>{throw _t("Method unimplemented")},it=()=>{throw _t("Unexpected case")},ir=_t("Unexpected end of array"),sr=_t("Integer out of Range");class kn{constructor(t){this.arr=t,this.pos=0}}const Di=e=>new kn(e),Dc=e=>e.pos!==e.arr.length,Mc=(e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},ht=e=>Mc(e,j(e)),Ee=e=>e.arr[e.pos++],j=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&Ht)*n,n*=128,s<nt)return t;if(t>nn)throw sr}throw ir},Mi=e=>{let t=e.arr[e.pos++],n=t&oi,i=64;const s=(t&Dt)>0?-1:1;if((t&nt)===0)return s*n;const r=e.arr.length;for(;e.pos<r;){if(t=e.arr[e.pos++],n=n+(t&Ht)*i,i*=128,t<nt)return s*n;if(n>nn)throw sr}throw ir},Oc=e=>{let t=j(e);if(t===0)return"";{let n=String.fromCodePoint(Ee(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(Ee(e));else for(;t>0;){const i=t<1e4?t:1e4,s=e.arr.subarray(e.pos,e.pos+i);e.pos+=i,n+=String.fromCodePoint.apply(null,s),t-=i}return decodeURIComponent(escape(n))}},Rc=e=>Se.decode(ht(e)),ai=Se?Rc:Oc,Oi=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},jc=e=>Oi(e,4).getFloat32(0,!1),Nc=e=>Oi(e,8).getFloat64(0,!1),Bc=e=>Oi(e,8).getBigInt64(0,!1),Lc=[e=>{},e=>null,Mi,jc,Nc,Bc,e=>!1,e=>!0,ai,e=>{const t=j(e),n={};for(let i=0;i<t;i++){const s=ai(e);n[s]=sn(e)}return n},e=>{const t=j(e),n=[];for(let i=0;i<t;i++)n.push(sn(e));return n},ht],sn=e=>Lc[127-Ee(e)](e);class as extends kn{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Dc(this)?this.count=j(this)+1:this.count=-1),this.count--,this.s}}class Je extends kn{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Mi(this);const t=er(this.s);this.count=1,t&&(this.s=-this.s,this.count=j(this)+2)}return this.count--,this.s}}class Wn extends kn{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=Mi(this),n=t&1;this.diff=bt(t/2),this.count=1,n&&(this.count=j(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Pc{constructor(t){this.decoder=new Je(t),this.str=ai(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}}const Uc=crypto.getRandomValues.bind(crypto),$c=Math.random,rr=()=>Uc(new Uint32Array(1))[0],Fc=e=>e[bt($c()*e.length)],Vc="10000000-1000-4000-8000"+-1e11,Hc=()=>Vc.replace(/[018]/g,e=>(e^rr()&15>>e/4).toString(16)),zc=Date.now,us=e=>new Promise(e);Promise.all.bind(Promise);const hs=e=>e===void 0?null:e;class Kc{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}}let or=new Kc,qc=!0;try{typeof localStorage<"u"&&localStorage&&(or=localStorage,qc=!1)}catch{}const Wc=or,_e=Symbol("Equality"),lr=(e,t)=>{var n;return e===t||!!((n=e==null?void 0:e[_e])!=null&&n.call(e,t))||!1},Gc=e=>typeof e=="object",Yc=Object.assign,cr=Object.keys,Jc=(e,t)=>{for(const n in e)t(e[n],n)},rn=e=>cr(e).length,Xc=e=>{for(const t in e)return!1;return!0},de=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},Ri=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Zc=(e,t)=>e===t||rn(e)===rn(t)&&de(e,(n,i)=>(n!==void 0||Ri(t,i))&&lr(t[i],n)),Qc=Object.freeze,ar=e=>{for(const t in e){const n=e[t];(typeof n=="object"||typeof n=="function")&&ar(e[t])}return Qc(e)},ji=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&ji(e,t,n+1)}},Xe=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[_e]!=null)return e[_e](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:{if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break}case Set:{if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;break}case Map:{if(e.size!==t.size)return!1;for(const n of e.keys())if(!t.has(n)||!Xe(e.get(n),t.get(n)))return!1;break}case void 0:case Object:if(rn(e)!==rn(t))return!1;for(const n in e)if(!Ri(e,n)||!Xe(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Xe(e[n],t[n]))return!1;break;default:return!1}return!0},ta=(e,t)=>t.includes(e),ae=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",ur=typeof window<"u"&&typeof document<"u"&&!ae;let St;const ea=()=>{if(St===void 0)if(ae){St=xt();const e=process.argv;let t=null;for(let n=0;n<e.length;n++){const i=e[n];i[0]==="-"?(t!==null&&St.set(t,""),t=i):t!==null&&(St.set(t,i),t=null)}t!==null&&St.set(t,"")}else typeof location=="object"?(St=xt(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){const[t,n]=e.split("=");St.set(`--${ss(t,"-")}`,n),St.set(`-${ss(t,"-")}`,n)}})):St=xt();return St},ui=e=>ea().has(e),on=e=>hs(ae?process.env[e.toUpperCase().replaceAll("-","_")]:Wc.getItem(e)),hr=e=>ui("--"+e)||on(e)!==null,na=hr("production"),ia=ae&&ta(process.env.FORCE_COLOR,["true","1","2"]),sa=ia||!ui("--no-colors")&&!hr("no-color")&&(!ae||process.stdout.isTTY)&&(!ae||ui("--color")||on("COLORTERM")!==null||(on("TERM")||"").includes("color")),ra=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=nr(e[n]);return btoa(t)},oa=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),la=ur?ra:oa,ca=e=>wc(t=>ce(t,e));class aa{constructor(t,n){this.left=t,this.right=n}}const At=(e,t)=>new aa(e,t),ds=e=>e.next()>=.5,Gn=(e,t,n)=>bt(e.next()*(n+1-t)+t),dr=(e,t,n)=>bt(e.next()*(n+1-t)+t),Ni=(e,t,n)=>dr(e,t,n),ua=e=>nr(Ni(e,97,122)),ha=(e,t=0,n=20)=>{const i=Ni(e,t,n);let s="";for(let r=0;r<i;r++)s+=ua(e);return s},Yn=(e,t)=>t[Ni(e,0,t.length-1)],da=Symbol("0schema");class fa{constructor(){this._rerrs=[]}extend(t,n,i,s=null){this._rerrs.push({path:t,expected:n,has:i,message:s})}toString(){const t=[];for(let n=this._rerrs.length-1;n>0;n--){const i=this._rerrs[n];t.push(bc(" ",(this._rerrs.length-n)*2)+`${i.path!=null?`[${i.path}] `:""}${i.has} doesn't match ${i.expected}. ${i.message}`)}return t.join(`
3
+ `)}}const hi=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[_e]?lr(e,t):oe(e)?_i(e,n=>Ti(t,i=>hi(n,i))):Gc(e)?de(e,(n,i)=>hi(n,t[i])):!1;class Z{extends(t){let[n,i]=[this.shape,t.shape];return this.constructor._dilutes&&([i,n]=[n,i]),hi(n,i)}equals(t){return this.constructor===t.constructor&&Xe(this.shape,t.shape)}[da](){return!0}[_e](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){ft()}get nullable(){return fe(this,In)}get optional(){return new gr(this)}cast(t){return fs(t,this),t}expect(t){return fs(t,this),t}}$e(Z,"_dilutes",!1);class Bi extends Z{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n=void 0){const i=(t==null?void 0:t.constructor)===this.shape&&(this._c==null||this._c(t));return!i&&(n==null||n.extend(null,this.shape.name,t==null?void 0:t.constructor.name,(t==null?void 0:t.constructor)!==this.shape?"Constructor match failed":"Check failed")),i}}const H=(e,t=null)=>new Bi(e,t);H(Bi);class Li extends Z{constructor(t){super(),this.shape=t}check(t,n){const i=this.shape(t);return!i&&(n==null||n.extend(null,"custom prop",t==null?void 0:t.constructor.name,"failed to check custom prop")),i}}const G=e=>new Li(e);H(Li);class En extends Z{constructor(t){super(),this.shape=t}check(t,n){const i=this.shape.some(s=>s===t);return!i&&(n==null||n.extend(null,this.shape.join(" | "),t.toString())),i}}const _n=(...e)=>new En(e),fr=H(En),pa=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,t=>"\\"+t)),pr=e=>{if(ue.check(e))return[pa(e)];if(fr.check(e))return e.shape.map(t=>t+"");if(kr.check(e))return["[+-]?\\d+.?\\d*"];if(Er.check(e))return[".*"];if(cn.check(e))return e.shape.map(pr).flat(1);it()};class ga extends Z{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(pr).map(n=>`(${n.join("|")})`).join("")+"$")}check(t,n){const i=this._r.exec(t)!=null;return!i&&(n==null||n.extend(null,this._r.toString(),t.toString(),"String doesn't match string template.")),i}}H(ga);const ma=Symbol("optional");class gr extends Z{constructor(t){super(),this.shape=t}check(t,n){const i=t===void 0||this.shape.check(t);return!i&&(n==null||n.extend(null,"undefined (optional)","()")),i}get[ma](){return!0}}const xa=H(gr);class ba extends Z{check(t,n){return n==null||n.extend(null,"never",typeof t),!1}}H(ba);const vn=class vn extends Z{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}get partial(){return new vn(this.shape,!0)}check(t,n){return t==null?(n==null||n.extend(null,"object","null"),!1):de(this.shape,(i,s)=>{const r=this._isPartial&&!Ri(t,s)||i.check(t[s],n);return!r&&(n==null||n.extend(s.toString(),i.toString(),typeof t[s],"Object property does not match")),r})}};$e(vn,"_dilutes",!0);let ln=vn;const wa=e=>new ln(e),ya=H(ln),va=G(e=>e!=null&&(e.constructor===Object||e.constructor==null));class mr extends Z{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return t!=null&&de(t,(i,s)=>{const r=this.shape.keys.check(s,n);return!r&&(n==null||n.extend(s+"","Record",typeof t,r?"Key doesn't match schema":"Value doesn't match value")),r&&this.shape.values.check(i,n)})}}const xr=(e,t)=>new mr(e,t),Sa=H(mr);class br extends Z{constructor(t){super(),this.shape=t}check(t,n){return t!=null&&de(this.shape,(i,s)=>{const r=i.check(t[s],n);return!r&&(n==null||n.extend(s.toString(),"Tuple",typeof i)),r})}}const Ca=(...e)=>new br(e);H(br);class wr extends Z{constructor(t){super(),this.shape=t.length===1?t[0]:new Tn(t)}check(t,n){const i=oe(t)&&_i(t,s=>this.shape.check(s));return!i&&(n==null||n.extend(null,"Array","")),i}}const yr=(...e)=>new wr(e),ka=H(wr),Ea=G(e=>oe(e));class vr extends Z{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n){const i=t instanceof this.shape&&(this._c==null||this._c(t));return!i&&(n==null||n.extend(null,this.shape.name,t==null?void 0:t.constructor.name)),i}}const _a=(e,t=null)=>new vr(e,t);H(vr);const Ta=_a(Z);class Aa extends Z{constructor(t){super(),this.len=t.length-1,this.args=Ca(...t.slice(-1)),this.res=t[this.len]}check(t,n){const i=t.constructor===Function&&t.length<=this.len;return!i&&(n==null||n.extend(null,"function",typeof t)),i}}const Ia=H(Aa),Da=G(e=>typeof e=="function");class Ma extends Z{constructor(t){super(),this.shape=t}check(t,n){const i=_i(this.shape,s=>s.check(t,n));return!i&&(n==null||n.extend(null,"Intersectinon",typeof t)),i}}H(Ma,e=>e.shape.length>0);class Tn extends Z{constructor(t){super(),this.shape=t}check(t,n){const i=Ti(this.shape,s=>s.check(t,n));return n==null||n.extend(null,"Union",typeof t),i}}$e(Tn,"_dilutes",!0);const fe=(...e)=>e.findIndex(t=>cn.check(t))>=0?fe(...e.map(t=>Te(t)).map(t=>cn.check(t)?t.shape:[t]).flat(1)):e.length===1?e[0]:new Tn(e),cn=H(Tn),Sr=()=>!0,an=G(Sr),Oa=H(Li,e=>e.shape===Sr),Pi=G(e=>typeof e=="bigint"),Ra=G(e=>e===Pi),Cr=G(e=>typeof e=="symbol");G(e=>e===Cr);const ne=G(e=>typeof e=="number"),kr=G(e=>e===ne),ue=G(e=>typeof e=="string"),Er=G(e=>e===ue),An=G(e=>typeof e=="boolean"),ja=G(e=>e===An),_r=_n(void 0);H(En,e=>e.shape.length===1&&e.shape[0]===void 0);_n(void 0);const In=_n(null),Na=H(En,e=>e.shape.length===1&&e.shape[0]===null);H(Uint8Array);H(Bi,e=>e.shape===Uint8Array);const Ba=fe(ne,ue,In,_r,Pi,An,Cr);(()=>{const e=yr(an),t=xr(ue,an),n=fe(ne,ue,In,An,e,t);return e.shape=n,t.shape.values=n,n})();const Te=e=>{if(Ta.check(e))return e;if(va.check(e)){const t={};for(const n in e)t[n]=Te(e[n]);return wa(t)}else{if(Ea.check(e))return fe(...e.map(Te));if(Ba.check(e))return _n(e);if(Da.check(e))return H(e)}it()},fs=na?()=>{}:(e,t)=>{const n=new fa;if(!t.check(e,n))throw _t(`Expected value to be of type ${t.constructor.name}.
4
+ ${n.toString()}`)};class La{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:Te(t),h:n}),this}else(t){return this.if(an,t)}done(){return(t,n)=>{for(let i=0;i<this.patterns.length;i++){const s=this.patterns[i];if(s.if.check(t))return s.h(t,n)}throw _t("Unhandled pattern")}}}const Pa=e=>new La(e),Tr=Pa(an).if(kr,(e,t)=>Gn(t,is,nn)).if(Er,(e,t)=>ha(t)).if(ja,(e,t)=>ds(t)).if(Ra,(e,t)=>BigInt(Gn(t,is,nn))).if(cn,(e,t)=>te(t,Yn(t,e.shape))).if(ya,(e,t)=>{const n={};for(const i in e.shape){let s=e.shape[i];if(xa.check(s)){if(ds(t))continue;s=s.shape}n[i]=Tr(s,t)}return n}).if(ka,(e,t)=>{const n=[],i=dr(t,0,42);for(let s=0;s<i;s++)n.push(te(t,e.shape));return n}).if(fr,(e,t)=>Yn(t,e.shape)).if(Na,(e,t)=>null).if(Ia,(e,t)=>{const n=te(t,e.res);return()=>n}).if(Oa,(e,t)=>te(t,Yn(t,[ne,ue,In,_r,Pi,An,yr(ne),xr(fe("a","b","c"),ne)]))).if(Sa,(e,t)=>{const n={},i=Gn(t,0,3);for(let s=0;s<i;s++){const r=te(t,e.shape.keys),o=te(t,e.shape.values);n[r]=o}return n}).done(),te=(e,t)=>Tr(Te(t),e),Le=typeof document<"u"?document:{};G(e=>e.nodeType===Ha);typeof DOMParser<"u"&&new DOMParser;G(e=>e.nodeType===$a);G(e=>e.nodeType===Fa);const Ua=e=>sc(e,(t,n)=>`${n}:${t};`).join(""),$a=Le.ELEMENT_NODE,Fa=Le.TEXT_NODE,Va=Le.DOCUMENT_NODE,Ha=Le.DOCUMENT_FRAGMENT_NODE;G(e=>e.nodeType===Va);const za=e=>class{constructor(n){this._=n}destroy(){e(this._)}},Ka=za(clearTimeout),Ar=(e,t)=>new Ka(setTimeout(t,e)),Rt=Symbol,Ir=Rt(),Dr=Rt(),qa=Rt(),Wa=Rt(),Ga=Rt(),Mr=Rt(),Ya=Rt(),Ui=Rt(),Ja=Rt(),Xa=e=>{var s;e.length===1&&((s=e[0])==null?void 0:s.constructor)===Function&&(e=e[0]());const t=[],n=[];let i=0;for(;i<e.length;i++){const r=e[i];if(r===void 0)break;if(r.constructor===String||r.constructor===Number)t.push(r);else if(r.constructor===Object)break}for(i>0&&n.push(t.join(""));i<e.length;i++){const r=e[i];r instanceof Symbol||n.push(r)}return n},Za={[Ir]:At("font-weight","bold"),[Dr]:At("font-weight","normal"),[qa]:At("color","blue"),[Ga]:At("color","green"),[Wa]:At("color","grey"),[Mr]:At("color","red"),[Ya]:At("color","purple"),[Ui]:At("color","orange"),[Ja]:At("color","black")},Qa=e=>{var o;e.length===1&&((o=e[0])==null?void 0:o.constructor)===Function&&(e=e[0]());const t=[],n=[],i=xt();let s=[],r=0;for(;r<e.length;r++){const l=e[r],c=Za[l];if(c!==void 0)i.set(c.left,c.right);else{if(l===void 0)break;if(l.constructor===String||l.constructor===Number){const a=Ua(i);r>0||a.length>0?(t.push("%c"+l),n.push(a)):t.push(l)}else break}}for(r>0&&(s=n,s.unshift(t.join("")));r<e.length;r++){const l=e[r];l instanceof Symbol||s.push(l)}return s},Or=sa?Qa:Xa,tu=(...e)=>{console.log(...Or(e)),jr.forEach(t=>t.print(e))},Rr=(...e)=>{console.warn(...Or(e)),e.unshift(Ui),jr.forEach(t=>t.print(e))},jr=Kt(),Nr=e=>({[Symbol.iterator](){return this},next:e}),eu=(e,t)=>Nr(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),Jn=(e,t)=>Nr(()=>{const{done:n,value:i}=e.next();return{done:n,value:n?void 0:t(i)}});class Dn{constructor(t,n){this.clock=t,this.len=n}}class pe{constructor(){this.clients=new Map}}const Pt=(e,t,n)=>t.clients.forEach((i,s)=>{const r=e.doc.store.clients.get(s);if(r!=null){const o=r[r.length-1],l=o.id.clock+o.length;for(let c=0,a=i[c];c<i.length&&a.clock<l;a=i[++c])zr(e,r,a.clock,a.len,n)}}),nu=(e,t)=>{let n=0,i=e.length-1;for(;n<=i;){const s=bt((n+i)/2),r=e[s],o=r.clock;if(o<=t){if(t<o+r.len)return s;n=s+1}else i=s-1}return null},ge=(e,t)=>{const n=e.clients.get(t.client);return n!==void 0&&nu(n,t.clock)!==null},$i=e=>{e.clients.forEach(t=>{t.sort((s,r)=>s.clock-r.clock);let n,i;for(n=1,i=1;n<t.length;n++){const s=t[i-1],r=t[n];s.clock+s.len>=r.clock?t[i-1]=new Dn(s.clock,Lt(s.len,r.clock+r.len-s.clock)):(i<n&&(t[i]=r),i++)}t.length=i})},di=e=>{const t=new pe;for(let n=0;n<e.length;n++)e[n].clients.forEach((i,s)=>{if(!t.clients.has(s)){const r=i.slice();for(let o=n+1;o<e.length;o++)oc(r,e[o].clients.get(s)||[]);t.clients.set(s,r)}});return $i(t),t},Ae=(e,t,n,i)=>{Ot(e.clients,t,()=>[]).push(new Dn(n,i))},Br=()=>new pe,iu=e=>{const t=Br();return e.clients.forEach((n,i)=>{const s=[];for(let r=0;r<n.length;r++){const o=n[r];if(o.deleted){const l=o.id.clock;let c=o.length;if(r+1<n.length)for(let a=n[r+1];r+1<n.length&&a.deleted;a=n[++r+1])c+=a.length;s.push(new Dn(l,c))}}s.length>0&&t.clients.set(i,s)}),t},Fi=(e,t)=>{I(e.restEncoder,t.clients.size),qt(t.clients.entries()).sort((n,i)=>i[0]-n[0]).forEach(([n,i])=>{e.resetDsCurVal(),I(e.restEncoder,n);const s=i.length;I(e.restEncoder,s);for(let r=0;r<s;r++){const o=i[r];e.writeDsClock(o.clock),e.writeDsLen(o.len)}})},su=e=>{const t=new pe,n=j(e.restDecoder);for(let i=0;i<n;i++){e.resetDsCurVal();const s=j(e.restDecoder),r=j(e.restDecoder);if(r>0){const o=Ot(t.clients,s,()=>[]);for(let l=0;l<r;l++)o.push(new Dn(e.readDsClock(),e.readDsLen()))}}return t},ps=(e,t,n)=>{const i=new pe,s=j(e.restDecoder);for(let r=0;r<s;r++){e.resetDsCurVal();const o=j(e.restDecoder),l=j(e.restDecoder),c=n.clients.get(o)||[],a=F(n,o);for(let h=0;h<l;h++){const u=e.readDsClock(),f=u+e.readDsLen();if(u<a){a<f&&Ae(i,o,a,f-a);let p=wt(c,u),g=c[p];for(!g.deleted&&g.id.clock<u&&(c.splice(p+1,0,mn(t,g,u-g.id.clock)),p++);p<c.length&&(g=c[p++],g.id.clock<f);)g.deleted||(f<g.id.clock+g.length&&c.splice(p,0,mn(t,g,f-g.id.clock)),g.delete(t))}else Ae(i,o,u,f-u)}}if(i.clients.size>0){const r=new Mn;return I(r.restEncoder,0),Fi(r,i),r.toUint8Array()}return null},Lr=rr;class Jt extends tr{constructor({guid:t=Hc(),collectionid:n=null,gc:i=!0,gcFilter:s=()=>!0,meta:r=null,autoLoad:o=!1,shouldLoad:l=!0}={}){super(),this.gc=i,this.gcFilter=s,this.clientID=Lr(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new Vr,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=o,this.meta=r,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=us(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const c=()=>us(a=>{const h=u=>{(u===void 0||u===!0)&&(this.off("sync",h),a())};this.on("sync",h)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=a===void 0||a===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=c()}load(){const t=this._item;t!==null&&!this.shouldLoad&&R(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(qt(this.subdocs).map(t=>t.guid))}transact(t,n=null){return R(this,t,n)}get(t,n=W){const i=Ot(this.share,t,()=>{const r=new n;return r._integrate(this,null),r}),s=i.constructor;if(n!==W&&s!==n)if(s===W){const r=new n;r._map=i._map,i._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=r}),r._start=i._start;for(let o=r._start;o!==null;o=o.right)o.parent=r;return r._length=i._length,this.share.set(t,r),r._integrate(this,null),r}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return i}getArray(t=""){return this.get(t,re)}getText(t=""){return this.get(t,Ut)}getMap(t=""){return this.get(t,he)}getXmlElement(t=""){return this.get(t,et)}getXmlFragment(t=""){return this.get(t,Wt)}toJSON(){const t={};return this.share.forEach((n,i)=>{t[i]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,qt(this.subdocs).forEach(n=>n.destroy());const t=this._item;if(t!==null){this._item=null;const n=t.content;n.doc=new Jt({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,R(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 ru{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=j(this.restDecoder),this.dsCurrVal}readDsLen(){const t=j(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class un extends ru{constructor(t){super(t),this.keys=[],j(t),this.keyClockDecoder=new Wn(ht(t)),this.clientDecoder=new Je(ht(t)),this.leftClockDecoder=new Wn(ht(t)),this.rightClockDecoder=new Wn(ht(t)),this.infoDecoder=new as(ht(t),Ee),this.stringDecoder=new Pc(ht(t)),this.parentInfoDecoder=new as(ht(t),Ee),this.typeRefDecoder=new Je(ht(t)),this.lenDecoder=new Je(ht(t))}readLeftID(){return new ie(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new ie(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 sn(this.restDecoder)}readBuf(){return ht(this.restDecoder)}readJSON(){return sn(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 ou{constructor(){this.restEncoder=Be()}toUint8Array(){return gt(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){I(this.restEncoder,t)}writeDsLen(t){I(this.restEncoder,t)}}class lu extends ou{writeLeftID(t){I(this.restEncoder,t.client),I(this.restEncoder,t.clock)}writeRightID(t){I(this.restEncoder,t.client),I(this.restEncoder,t.clock)}writeClient(t){I(this.restEncoder,t)}writeInfo(t){li(this.restEncoder,t)}writeString(t){ee(this.restEncoder,t)}writeParentInfo(t){I(this.restEncoder,t?1:0)}writeTypeRef(t){I(this.restEncoder,t)}writeLen(t){I(this.restEncoder,t)}writeAny(t){ce(this.restEncoder,t)}writeBuf(t){at(this.restEncoder,t)}writeJSON(t){ee(this.restEncoder,JSON.stringify(t))}writeKey(t){ee(this.restEncoder,t)}}class cu{constructor(){this.restEncoder=Be(),this.dsCurrVal=0}toUint8Array(){return gt(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,I(this.restEncoder,n)}writeDsLen(t){t===0&&it(),I(this.restEncoder,t-1),this.dsCurrVal+=t}}class Mn extends cu{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new qn,this.clientEncoder=new Ye,this.leftClockEncoder=new qn,this.rightClockEncoder=new qn,this.infoEncoder=new os(li),this.stringEncoder=new Ic,this.parentInfoEncoder=new os(li),this.typeRefEncoder=new Ye,this.lenEncoder=new Ye}toUint8Array(){const t=Be();return I(t,0),at(t,this.keyClockEncoder.toUint8Array()),at(t,this.clientEncoder.toUint8Array()),at(t,this.leftClockEncoder.toUint8Array()),at(t,this.rightClockEncoder.toUint8Array()),at(t,gt(this.infoEncoder)),at(t,this.stringEncoder.toUint8Array()),at(t,gt(this.parentInfoEncoder)),at(t,this.typeRefEncoder.toUint8Array()),at(t,this.lenEncoder.toUint8Array()),Cn(t,gt(this.restEncoder)),gt(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){ce(this.restEncoder,t)}writeBuf(t){at(this.restEncoder,t)}writeJSON(t){ce(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 au=(e,t,n,i)=>{i=Lt(i,t[0].id.clock);const s=wt(t,i);I(e.restEncoder,t.length-s),e.writeClient(n),I(e.restEncoder,i);const r=t[s];r.write(e,i-r.id.clock);for(let o=s+1;o<t.length;o++)t[o].write(e,0)},Pr=(e,t,n)=>{const i=new Map;n.forEach((s,r)=>{F(t,r)>s&&i.set(r,s)}),On(t).forEach((s,r)=>{n.has(r)||i.set(r,0)}),I(e.restEncoder,i.size),qt(i.entries()).sort((s,r)=>r[0]-s[0]).forEach(([s,r])=>{au(e,t.clients.get(s),s,r)})},uu=(e,t)=>{const n=xt(),i=j(e.restDecoder);for(let s=0;s<i;s++){const r=j(e.restDecoder),o=new Array(r),l=e.readClient();let c=j(e.restDecoder);n.set(l,{i:0,refs:o});for(let a=0;a<r;a++){const h=e.readInfo();switch(Sn&h){case 0:{const u=e.readLen();o[a]=new dt(T(l,c),u),c+=u;break}case 10:{const u=j(e.restDecoder);o[a]=new pt(T(l,c),u),c+=u;break}default:{const u=(h&(Dt|nt))===0,f=new O(T(l,c),null,(h&nt)===nt?e.readLeftID():null,null,(h&Dt)===Dt?e.readRightID():null,u?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,u&&(h&Ce)===Ce?e.readString():null,fo(e,h));o[a]=f,c+=f.length}}}}return n},hu=(e,t,n)=>{const i=[];let s=qt(n.keys()).sort((p,g)=>p-g);if(s.length===0)return null;const r=()=>{if(s.length===0)return null;let p=n.get(s[s.length-1]);for(;p.refs.length===p.i;)if(s.pop(),s.length>0)p=n.get(s[s.length-1]);else return null;return p};let o=r();if(o===null)return null;const l=new Vr,c=new Map,a=(p,g)=>{const x=c.get(p);(x==null||x>g)&&c.set(p,g)};let h=o.refs[o.i++];const u=new Map,f=()=>{for(const p of i){const g=p.id.client,x=n.get(g);x?(x.i--,l.clients.set(g,x.refs.slice(x.i)),n.delete(g),x.i=0,x.refs=[]):l.clients.set(g,[p]),s=s.filter(w=>w!==g)}i.length=0};for(;;){if(h.constructor!==pt){const g=Ot(u,h.id.client,()=>F(t,h.id.client))-h.id.clock;if(g<0)i.push(h),a(h.id.client,h.id.clock-1),f();else{const x=h.getMissing(e,t);if(x!==null){i.push(h);const w=n.get(x)||{refs:[],i:0};if(w.refs.length===w.i)a(x,F(t,x)),f();else{h=w.refs[w.i++];continue}}else(g===0||g<h.length)&&(h.integrate(e,g),u.set(h.id.client,h.id.clock+h.length))}}if(i.length>0)h=i.pop();else if(o!==null&&o.i<o.refs.length)h=o.refs[o.i++];else{if(o=r(),o===null)break;h=o.refs[o.i++]}}if(l.clients.size>0){const p=new Mn;return Pr(p,l,new Map),I(p.restEncoder,0),{missing:c,update:p.toUint8Array()}}return null},du=(e,t)=>Pr(e,t.doc.store,t.beforeState),fu=(e,t,n,i=new un(e))=>R(t,s=>{s.local=!1;let r=!1;const o=s.doc,l=o.store,c=uu(i,o),a=hu(s,l,c),h=l.pendingStructs;if(h){for(const[f,p]of h.missing)if(p<F(l,f)){r=!0;break}if(a){for(const[f,p]of a.missing){const g=h.missing.get(f);(g==null||g>p)&&h.missing.set(f,p)}h.update=Cs([h.update,a.update])}}else l.pendingStructs=a;const u=ps(i,s,l);if(l.pendingDs){const f=new un(Di(l.pendingDs));j(f.restDecoder);const p=ps(f,s,l);u&&p?l.pendingDs=Cs([u,p]):l.pendingDs=u||p}else l.pendingDs=u;if(r){const f=l.pendingStructs.update;l.pendingStructs=null,fi(s.doc,f)}},n,!1),fi=(e,t,n,i=un)=>{const s=Di(t);fu(s,e,n,new i(s))};class pu{constructor(){this.l=[]}}const gs=()=>new pu,ms=(e,t)=>e.l.push(t),xs=(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.")},Ur=(e,t,n)=>ji(e.l,[t,n]);class ie{constructor(t,n){this.client=t,this.clock=n}}const Fe=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,T=(e,t)=>new ie(e,t),Ie=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw it()},De=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1};class hn{constructor(t,n,i,s=0){this.type=t,this.tname=n,this.item=i,this.assoc=s}}class gu{constructor(t,n,i=0){this.type=t,this.index=n,this.assoc=i}}const mu=(e,t,n=0)=>new gu(e,t,n),Ve=(e,t,n)=>{let i=null,s=null;return e._item===null?s=Ie(e):i=T(e._item.id.client,e._item.id.clock),new hn(i,s,t,n)},Xn=(e,t,n=0)=>{let i=e._start;if(n<0){if(t===0)return Ve(e,null,n);t--}for(;i!==null;){if(!i.deleted&&i.countable){if(i.length>t)return Ve(e,T(i.id.client,i.id.clock+t),n);t-=i.length}if(i.right===null&&n<0)return Ve(e,i.lastId,n);i=i.right}return Ve(e,null,n)},xu=(e,t)=>{const n=se(e,t),i=t.clock-n.id.clock;return{item:n,diff:i}},$r=(e,t,n=!0)=>{const i=t.store,s=e.item,r=e.type,o=e.tname,l=e.assoc;let c=null,a=0;if(s!==null){if(F(i,s.client)<=s.clock)return null;const h=n?xi(i,s):xu(i,s),u=h.item;if(!(u instanceof O))return null;if(c=u.parent,c._item===null||!c._item.deleted){a=u.deleted||!u.countable?0:h.diff+(l>=0?0:1);let f=u.left;for(;f!==null;)!f.deleted&&f.countable&&(a+=f.length),f=f.left}}else{if(o!==null)c=t.get(o);else if(r!==null){if(F(i,r.client)<=r.clock)return null;const{item:h}=n?xi(i,r):{item:se(i,r)};if(h instanceof O&&h.content instanceof vt)c=h.content.type;else return null}else throw it();l>=0?a=c._length:a=0}return mu(c,a,e.assoc)};class Vi{constructor(t,n){this.ds=t,this.sv=n}}const Fr=(e,t)=>new Vi(e,t),Zn=e=>Fr(iu(e.store),On(e.store)),Ft=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!ge(t.ds,e.id),pi=(e,t)=>{const n=Ot(e.meta,pi,Kt),i=e.doc.store;n.has(t)||(t.sv.forEach((s,r)=>{s<F(i,r)&&rt(e,T(r,s))}),Pt(e,t.ds,s=>{}),n.add(t))};class Vr{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const On=e=>{const t=new Map;return e.clients.forEach((n,i)=>{const s=n[n.length-1];t.set(i,s.id.clock+s.length)}),t},F=(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},Hr=(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 it()}n.push(t)},wt=(e,t)=>{let n=0,i=e.length-1,s=e[i],r=s.id.clock;if(r===t)return i;let o=bt(t/(r+s.length-1)*i);for(;n<=i;){if(s=e[o],r=s.id.clock,r<=t){if(t<r+s.length)return o;n=o+1}else i=o-1;o=bt((n+i)/2)}throw it()},bu=(e,t)=>{const n=e.clients.get(t.client);return n[wt(n,t.clock)]},se=bu,gi=(e,t,n)=>{const i=wt(t,n),s=t[i];return s.id.clock<n&&s instanceof O?(t.splice(i+1,0,mn(e,s,n-s.id.clock)),i+1):i},rt=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[gi(e,n,t.clock)]},bs=(e,t,n)=>{const i=t.clients.get(n.client),s=wt(i,n.clock),r=i[s];return n.clock!==r.id.clock+r.length-1&&r.constructor!==dt&&i.splice(s+1,0,mn(e,r,n.clock-r.id.clock+1)),r},wu=(e,t,n)=>{const i=e.clients.get(t.id.client);i[wt(i,t.id.clock)]=n},zr=(e,t,n,i,s)=>{if(i===0)return;const r=n+i;let o=gi(e,t,n),l;do l=t[o++],r<l.id.clock+l.length&&gi(e,t,r),s(l);while(o<t.length&&t[o].id.clock<r)};class yu{constructor(t,n,i){this.doc=t,this.deleteSet=new pe,this.beforeState=On(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=i,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const ws=(e,t)=>t.deleteSet.clients.size===0&&!rc(t.afterState,(n,i)=>t.beforeState.get(i)!==n)?!1:($i(t.deleteSet),du(e,t),Fi(e,t.deleteSet),!0),ys=(e,t,n)=>{const i=t._item;(i===null||i.id.clock<(e.beforeState.get(i.id.client)||0)&&!i.deleted)&&Ot(e.changed,t,Kt).add(n)},Ze=(e,t)=>{let n=e[t],i=e[t-1],s=t;for(;s>0;n=i,i=e[--s-1]){if(i.deleted===n.deleted&&i.constructor===n.constructor&&i.mergeWith(n)){n instanceof O&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,i);continue}break}const r=t-s;return r&&e.splice(t+1-r,r),r},vu=(e,t,n)=>{for(const[i,s]of e.clients.entries()){const r=t.clients.get(i);for(let o=s.length-1;o>=0;o--){const l=s[o],c=l.clock+l.len;for(let a=wt(r,l.clock),h=r[a];a<r.length&&h.id.clock<c;h=r[++a]){const u=r[a];if(l.clock+l.len<=u.id.clock)break;u instanceof O&&u.deleted&&!u.keep&&n(u)&&u.gc(t,!1)}}}},Su=(e,t)=>{e.clients.forEach((n,i)=>{const s=t.clients.get(i);for(let r=n.length-1;r>=0;r--){const o=n[r],l=le(s.length-1,1+wt(s,o.clock+o.len-1));for(let c=l,a=s[c];c>0&&a.id.clock>=o.clock;a=s[c])c-=1+Ze(s,c)}})},Kr=(e,t)=>{if(t<e.length){const n=e[t],i=n.doc,s=i.store,r=n.deleteSet,o=n._mergeStructs;try{$i(r),n.afterState=On(n.doc.store),i.emit("beforeObserverCalls",[n,i]);const l=[];n.changed.forEach((c,a)=>l.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(n,c)})),l.push(()=>{n.changedParentTypes.forEach((c,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(c=c.filter(h=>h.target._item===null||!h.target._item.deleted),c.forEach(h=>{h.currentTarget=a,h._path=null}),c.sort((h,u)=>h.path.length-u.path.length),l.push(()=>{Ur(a._dEH,c,n)}))}),l.push(()=>i.emit("afterTransaction",[n,i])),l.push(()=>{n._needFormattingCleanup&&Vu(n)})}),ji(l,[])}finally{i.gc&&vu(r,s,i.gcFilter),Su(r,s),n.afterState.forEach((h,u)=>{const f=n.beforeState.get(u)||0;if(f!==h){const p=s.clients.get(u),g=Lt(wt(p,f),1);for(let x=p.length-1;x>=g;)x-=1+Ze(p,x)}});for(let h=o.length-1;h>=0;h--){const{client:u,clock:f}=o[h].id,p=s.clients.get(u),g=wt(p,f);g+1<p.length&&Ze(p,g+1)>1||g>0&&Ze(p,g)}if(!n.local&&n.afterState.get(i.clientID)!==n.beforeState.get(i.clientID)&&(tu(Ui,Ir,"[yjs] ",Dr,Mr,"Changed the client-id because another client seems to be using it."),i.clientID=Lr()),i.emit("afterTransactionCleanup",[n,i]),i._observers.has("update")){const h=new lu;ws(h,n)&&i.emit("update",[h.toUint8Array(),n.origin,i,n])}if(i._observers.has("updateV2")){const h=new Mn;ws(h,n)&&i.emit("updateV2",[h.toUint8Array(),n.origin,i,n])}const{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=n;(l.size>0||a.size>0||c.size>0)&&(l.forEach(h=>{h.clientID=i.clientID,h.collectionid==null&&(h.collectionid=i.collectionid),i.subdocs.add(h)}),a.forEach(h=>i.subdocs.delete(h)),i.emit("subdocs",[{loaded:c,added:l,removed:a},i,n]),a.forEach(h=>h.destroy())),e.length<=t+1?(i._transactionCleanups=[],i.emit("afterAllTransactions",[i,e])):Kr(e,t+1)}}},R=(e,t,n=null,i=!0)=>{const s=e._transactionCleanups;let r=!1,o=null;e._transaction===null&&(r=!0,e._transaction=new yu(e,n,i),s.push(e._transaction),s.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(r){const l=e._transaction===s[0];e._transaction=null,l&&Kr(s,0)}}return o};class Cu{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const vs=(e,t,n)=>{Pt(e,n.deletions,i=>{i instanceof O&&t.scope.some(s=>s===e.doc||De(s,i))&&Wi(i,!1)})},Ss=(e,t,n)=>{let i=null;const s=e.doc,r=e.scope;R(s,l=>{for(;t.length>0&&e.currStackItem===null;){const c=s.store,a=t.pop(),h=new Set,u=[];let f=!1;Pt(l,a.insertions,p=>{if(p instanceof O){if(p.redone!==null){let{item:g,diff:x}=xi(c,p.id);x>0&&(g=rt(l,T(g.id.client,g.id.clock+x))),p=g}!p.deleted&&r.some(g=>g===l.doc||De(g,p))&&u.push(p)}}),Pt(l,a.deletions,p=>{p instanceof O&&r.some(g=>g===l.doc||De(g,p))&&!ge(a.insertions,p.id)&&h.add(p)}),h.forEach(p=>{f=ho(l,p,h,a.insertions,e.ignoreRemoteMapChanges,e)!==null||f});for(let p=u.length-1;p>=0;p--){const g=u[p];e.deleteFilter(g)&&(g.delete(l),f=!0)}e.currStackItem=f?a:null}l.changed.forEach((c,a)=>{c.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),i=l},e);const o=e.currStackItem;if(o!=null){const l=i.changedParentTypes;e.emit("stack-item-popped",[{stackItem:o,type:n,changedParentTypes:l,origin:e},e]),e.currStackItem=null}return o};class qr extends tr{constructor(t,{captureTimeout:n=500,captureTransaction:i=c=>!0,deleteFilter:s=()=>!0,trackedOrigins:r=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:l=oe(t)?t[0].doc:t instanceof Jt?t:t.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(t),this.deleteFilter=s,r.add(this),this.trackedOrigins=r,this.captureTransaction=i,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=n,this.afterTransactionHandler=c=>{if(!this.captureTransaction(c)||!this.scope.some(w=>c.changedParentTypes.has(w)||w===this.doc)||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;const a=this.undoing,h=this.redoing,u=a?this.redoStack:this.undoStack;a?this.stopCapturing():h||this.clear(!1,!0);const f=new pe;c.afterState.forEach((w,y)=>{const S=c.beforeState.get(y)||0,k=w-S;k>0&&Ae(f,y,S,k)});const p=zc();let g=!1;if(this.lastChange>0&&p-this.lastChange<this.captureTimeout&&u.length>0&&!a&&!h){const w=u[u.length-1];w.deletions=di([w.deletions,c.deleteSet]),w.insertions=di([w.insertions,f])}else u.push(new Cu(c.deleteSet,f)),g=!0;!a&&!h&&(this.lastChange=p),Pt(c,c.deleteSet,w=>{w instanceof O&&this.scope.some(y=>y===c.doc||De(y,w))&&Wi(w,!0)});const x=[{stackItem:u[u.length-1],origin:c.origin,type:a?"redo":"undo",changedParentTypes:c.changedParentTypes},this];g?this.emit("stack-item-added",x):this.emit("stack-item-updated",x)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){const n=new Set(this.scope);t=oe(t)?t:[t],t.forEach(i=>{n.has(i)||(n.add(i),(i instanceof W?i.doc!==this.doc:i!==this.doc)&&Rr("[yjs#509] Not same Y.Doc"),this.scope.push(i))})}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,n=!0){(t&&this.canUndo()||n&&this.canRedo())&&this.doc.transact(i=>{t&&(this.undoStack.forEach(s=>vs(i,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>vs(i,this,s)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let t;try{t=Ss(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=Ss(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*ku(e){const t=j(e.restDecoder);for(let n=0;n<t;n++){const i=j(e.restDecoder),s=e.readClient();let r=j(e.restDecoder);for(let o=0;o<i;o++){const l=e.readInfo();if(l===10){const c=j(e.restDecoder);yield new pt(T(s,r),c),r+=c}else if((Sn&l)!==0){const c=(l&(Dt|nt))===0,a=new O(T(s,r),null,(l&nt)===nt?e.readLeftID():null,null,(l&Dt)===Dt?e.readRightID():null,c?e.readParentInfo()?e.readString():e.readLeftID():null,c&&(l&Ce)===Ce?e.readString():null,fo(e,l));yield a,r+=a.length}else{const c=e.readLen();yield new dt(T(s,r),c),r+=c}}}}class Eu{constructor(t,n){this.gen=ku(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===pt);return this.curr}}class _u{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const Tu=(e,t)=>{if(e.constructor===dt){const{client:n,clock:i}=e.id;return new dt(T(n,i+t),e.length-t)}else if(e.constructor===pt){const{client:n,clock:i}=e.id;return new pt(T(n,i+t),e.length-t)}else{const n=e,{client:i,clock:s}=n.id;return new O(T(i,s+t),null,T(i,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Cs=(e,t=un,n=Mn)=>{if(e.length===1)return e[0];const i=e.map(h=>new t(Di(h)));let s=i.map(h=>new Eu(h,!0)),r=null;const o=new n,l=new _u(o);for(;s=s.filter(f=>f.curr!==null),s.sort((f,p)=>{if(f.curr.id.client===p.curr.id.client){const g=f.curr.id.clock-p.curr.id.clock;return g===0?f.curr.constructor===p.curr.constructor?0:f.curr.constructor===pt?1:-1:g}else return p.curr.id.client-f.curr.id.client}),s.length!==0;){const h=s[0],u=h.curr.id.client;if(r!==null){let f=h.curr,p=!1;for(;f!==null&&f.id.clock+f.length<=r.struct.id.clock+r.struct.length&&f.id.client>=r.struct.id.client;)f=h.next(),p=!0;if(f===null||f.id.client!==u||p&&f.id.clock>r.struct.id.clock+r.struct.length)continue;if(u!==r.struct.id.client)ye(l,r.struct,r.offset),r={struct:f,offset:0},h.next();else if(r.struct.id.clock+r.struct.length<f.id.clock)if(r.struct.constructor===pt)r.struct.length=f.id.clock+f.length-r.struct.id.clock;else{ye(l,r.struct,r.offset);const g=f.id.clock-r.struct.id.clock-r.struct.length;r={struct:new pt(T(u,r.struct.id.clock+r.struct.length),g),offset:0}}else{const g=r.struct.id.clock+r.struct.length-f.id.clock;g>0&&(r.struct.constructor===pt?r.struct.length-=g:f=Tu(f,g)),r.struct.mergeWith(f)||(ye(l,r.struct,r.offset),r={struct:f,offset:0},h.next())}}else r={struct:h.curr,offset:0},h.next();for(let f=h.curr;f!==null&&f.id.client===u&&f.id.clock===r.struct.id.clock+r.struct.length&&f.constructor!==pt;f=h.next())ye(l,r.struct,r.offset),r={struct:f,offset:0}}r!==null&&(ye(l,r.struct,r.offset),r=null),Au(l);const c=i.map(h=>su(h)),a=di(c);return Fi(o,a),o.toUint8Array()},Wr=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:gt(e.encoder.restEncoder)}),e.encoder.restEncoder=Be(),e.written=0)},ye=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Wr(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),I(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Au=e=>{Wr(e);const t=e.encoder.restEncoder;I(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const i=e.clientStructs[n];I(t,i.written),Cn(t,i.restEncoder)}},ks="You must not compute changes after the event-handler fired.";class Rn{constructor(t,n){this.target=t,this.currentTarget=t,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Iu(this.currentTarget,this.target))}deletes(t){return ge(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw _t(ks);const t=new Map,n=this.target;this.transaction.changed.get(n).forEach(s=>{if(s!==null){const r=n._map.get(s);let o,l;if(this.adds(r)){let c=r.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(r))if(c!==null&&this.deletes(c))o="delete",l=Hn(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Hn(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(r))o="delete",l=Hn(r.content.getContent());else return;t.set(s,{action:o,oldValue:l})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw _t(ks);const n=this.target,i=Kt(),s=Kt(),r=[];if(t={added:i,deleted:s,delta:r,keys:this.keys},this.transaction.changed.get(n).has(null)){let l=null;const c=()=>{l&&r.push(l)};for(let a=n._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((l===null||l.delete===void 0)&&(c(),l={delete:0}),l.delete+=a.length,s.add(a)):this.adds(a)?((l===null||l.insert===void 0)&&(c(),l={insert:[]}),l.insert=l.insert.concat(a.content.getContent()),i.add(a)):((l===null||l.retain===void 0)&&(c(),l={retain:0}),l.retain+=a.length);l!==null&&l.retain===void 0&&c()}this._changes=t}return t}}const Iu=(e,t)=>{const n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let i=0,s=t._item.parent._start;for(;s!==t._item&&s!==null;)!s.deleted&&s.countable&&(i+=s.length),s=s.right;n.unshift(i)}t=t._item.parent}return n},X=()=>{Rr("Invalid access: Add Yjs type to a document before reading data.")},Gr=80;let Hi=0;class Du{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=Hi++}}const Mu=e=>{e.timestamp=Hi++},Yr=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Hi++},Ou=(e,t,n)=>{if(e.length>=Gr){const i=e.reduce((s,r)=>s.timestamp<r.timestamp?s:r);return Yr(i,t,n),i}else{const i=new Du(t,n);return e.push(i),i}},jn=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;const n=e._searchMarker.length===0?null:e._searchMarker.reduce((r,o)=>Ge(t-r.index)<Ge(t-o.index)?r:o);let i=e._start,s=0;for(n!==null&&(i=n.p,s=n.index,Mu(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&&Ge(n.index-s)<i.parent.length/Gr?(Yr(n,i,s),n):Ou(e._searchMarker,i,s)},Me=(e,t,n)=>{for(let i=e.length-1;i>=0;i--){const s=e[i];if(n>0){let r=s.p;for(r.marker=!1;r&&(r.deleted||!r.countable);)r=r.left,r&&!r.deleted&&r.countable&&(s.index-=r.length);if(r===null||r.marker===!0){e.splice(i,1);continue}s.p=r,r.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=Lt(t,s.index+n))}},Nn=(e,t,n)=>{const i=e,s=t.changedParentTypes;for(;Ot(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Ur(i._eH,n,t)};class W{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=gs(),this._dEH=gs(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw ft()}clone(){throw ft()}_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){ms(this._eH,t)}observeDeep(t){ms(this._dEH,t)}unobserve(t){xs(this._eH,t)}unobserveDeep(t){xs(this._dEH,t)}toJSON(){}}const Jr=(e,t,n)=>{e.doc??X(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let i=n-t;const s=[];let r=e._start;for(;r!==null&&i>0;){if(r.countable&&!r.deleted){const o=r.content.getContent();if(o.length<=t)t-=o.length;else{for(let l=t;l<o.length&&i>0;l++)s.push(o[l]),i--;t=0}}r=r.right}return s},Xr=e=>{e.doc??X();const t=[];let n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){const i=n.content.getContent();for(let s=0;s<i.length;s++)t.push(i[s])}n=n.right}return t},Zr=(e,t)=>{const n=[];let i=e._start;for(;i!==null;){if(i.countable&&Ft(i,t)){const s=i.content.getContent();for(let r=0;r<s.length;r++)n.push(s[r])}i=i.right}return n},Oe=(e,t)=>{let n=0,i=e._start;for(e.doc??X();i!==null;){if(i.countable&&!i.deleted){const s=i.content.getContent();for(let r=0;r<s.length;r++)t(s[r],n++,e)}i=i.right}},Qr=(e,t)=>{const n=[];return Oe(e,(i,s)=>{n.push(t(i,s,e))}),n},Ru=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}}}},to=(e,t)=>{e.doc??X();const n=jn(e,t);let i=e._start;for(n!==null&&(i=n.p,t-=n.index);i!==null;i=i.right)if(!i.deleted&&i.countable){if(t<i.length)return i.content.getContent()[t];t-=i.length}},dn=(e,t,n,i)=>{let s=n;const r=e.doc,o=r.clientID,l=r.store,c=n===null?t._start:n.right;let a=[];const h=()=>{a.length>0&&(s=new O(T(o,F(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new Gt(a)),s.integrate(e,0),a=[])};i.forEach(u=>{if(u===null)a.push(u);else switch(u.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(u);break;default:switch(h(),u.constructor){case Uint8Array:case ArrayBuffer:s=new O(T(o,F(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new Pe(new Uint8Array(u))),s.integrate(e,0);break;case Jt:s=new O(T(o,F(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new Ue(u)),s.integrate(e,0);break;default:if(u instanceof W)s=new O(T(o,F(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new vt(u)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},eo=()=>_t("Length exceeded!"),no=(e,t,n,i)=>{if(n>t._length)throw eo();if(n===0)return t._searchMarker&&Me(t._searchMarker,n,i.length),dn(e,t,null,i);const s=n,r=jn(t,n);let o=t._start;for(r!==null&&(o=r.p,n-=r.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&rt(e,T(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&Me(t._searchMarker,s,i.length),dn(e,t,o,i)},ju=(e,t,n)=>{let s=(t._searchMarker||[]).reduce((r,o)=>o.index>r.index?o:r,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return dn(e,t,s,n)},io=(e,t,n,i)=>{if(i===0)return;const s=n,r=i,o=jn(t,n);let l=t._start;for(o!==null&&(l=o.p,n-=o.index);l!==null&&n>0;l=l.right)!l.deleted&&l.countable&&(n<l.length&&rt(e,T(l.id.client,l.id.clock+n)),n-=l.length);for(;i>0&&l!==null;)l.deleted||(i<l.length&&rt(e,T(l.id.client,l.id.clock+i)),l.delete(e),i-=l.length),l=l.right;if(i>0)throw eo();t._searchMarker&&Me(t._searchMarker,s,-r+i)},fn=(e,t,n)=>{const i=t._map.get(n);i!==void 0&&i.delete(e)},zi=(e,t,n,i)=>{const s=t._map.get(n)||null,r=e.doc,o=r.clientID;let l;if(i==null)l=new Gt([i]);else switch(i.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new Gt([i]);break;case Uint8Array:l=new Pe(i);break;case Jt:l=new Ue(i);break;default:if(i instanceof W)l=new vt(i);else throw new Error("Unexpected content type")}new O(T(o,F(r.store,o)),s,s&&s.lastId,null,null,t,n,l).integrate(e,0)},Ki=(e,t)=>{e.doc??X();const n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},so=e=>{const t={};return e.doc??X(),e._map.forEach((n,i)=>{n.deleted||(t[i]=n.content.getContent()[n.length-1])}),t},ro=(e,t)=>{e.doc??X();const n=e._map.get(t);return n!==void 0&&!n.deleted},Nu=(e,t)=>{const n={};return e._map.forEach((i,s)=>{let r=i;for(;r!==null&&(!t.sv.has(r.id.client)||r.id.clock>=(t.sv.get(r.id.client)||0));)r=r.left;r!==null&&Ft(r,t)&&(n[s]=r.content.getContent()[r.length-1])}),n},He=e=>(e.doc??X(),eu(e._map.entries(),t=>!t[1].deleted));class Bu extends Rn{}class re extends W{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new re;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new re}clone(){const t=new re;return t.insert(0,this.toArray().map(n=>n instanceof W?n.clone():n)),t}get length(){return this.doc??X(),this._length}_callObserver(t,n){super._callObserver(t,n),Nn(this,t,new Bu(this,t))}insert(t,n){this.doc!==null?R(this.doc,i=>{no(i,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?R(this.doc,n=>{ju(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?R(this.doc,i=>{io(i,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return to(this,t)}toArray(){return Xr(this)}slice(t=0,n=this.length){return Jr(this,t,n)}toJSON(){return this.map(t=>t instanceof W?t.toJSON():t)}map(t){return Qr(this,t)}forEach(t){Oe(this,t)}[Symbol.iterator](){return Ru(this)}_write(t){t.writeTypeRef(lh)}}const Lu=e=>new re;class Pu extends Rn{constructor(t,n,i){super(t,n),this.keysChanged=i}}class he extends W{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach((i,s)=>{this.set(s,i)}),this._prelimContent=null}_copy(){return new he}clone(){const t=new he;return this.forEach((n,i)=>{t.set(i,n instanceof W?n.clone():n)}),t}_callObserver(t,n){Nn(this,t,new Pu(this,t,n))}toJSON(){this.doc??X();const t={};return this._map.forEach((n,i)=>{if(!n.deleted){const s=n.content.getContent()[n.length-1];t[i]=s instanceof W?s.toJSON():s}}),t}get size(){return[...He(this)].length}keys(){return Jn(He(this),t=>t[0])}values(){return Jn(He(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Jn(He(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??X(),this._map.forEach((n,i)=>{n.deleted||t(n.content.getContent()[n.length-1],i,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?R(this.doc,n=>{fn(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?R(this.doc,i=>{zi(i,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return Ki(this,t)}has(t){return ro(this,t)}clear(){this.doc!==null?R(this.doc,t=>{this.forEach(function(n,i,s){fn(t,s,i)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(ch)}}const Uu=e=>new he,Bt=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&Zc(e,t);class mi{constructor(t,n,i,s){this.left=t,this.right=n,this.index=i,this.currentAttributes=s}forward(){switch(this.right===null&&it(),this.right.content.constructor){case V:this.right.deleted||me(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 Es=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case V:t.right.deleted||me(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&rt(e,T(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length);break}t.left=t.right,t.right=t.right.right}return t},ze=(e,t,n,i)=>{const s=new Map,r=i?jn(t,n):null;if(r){const o=new mi(r.p.left,r.p,r.index,s);return Es(e,o,n-r.index)}else{const o=new mi(null,t._start,0,s);return Es(e,o,n)}},oo=(e,t,n,i)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===V&&Bt(i.get(n.right.content.key),n.right.content.value));)n.right.deleted||i.delete(n.right.content.key),n.forward();const s=e.doc,r=s.clientID;i.forEach((o,l)=>{const c=n.left,a=n.right,h=new O(T(r,F(s.store,r)),c,c&&c.lastId,a,a&&a.id,t,null,new V(l,o));h.integrate(e,0),n.right=h,n.forward()})},me=(e,t)=>{const{key:n,value:i}=t;i===null?e.delete(n):e.set(n,i)},lo=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===V&&Bt(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},co=(e,t,n,i)=>{const s=e.doc,r=s.clientID,o=new Map;for(const l in i){const c=i[l],a=n.currentAttributes.get(l)??null;if(!Bt(a,c)){o.set(l,a);const{left:h,right:u}=n;n.right=new O(T(r,F(s.store,r)),h,h&&h.lastId,u,u&&u.id,t,null,new V(l,c)),n.right.integrate(e,0),n.forward()}}return o},Qn=(e,t,n,i,s)=>{n.currentAttributes.forEach((f,p)=>{s[p]===void 0&&(s[p]=null)});const r=e.doc,o=r.clientID;lo(n,s);const l=co(e,t,n,s),c=i.constructor===String?new yt(i):i instanceof W?new vt(i):new Xt(i);let{left:a,right:h,index:u}=n;t._searchMarker&&Me(t._searchMarker,n.index,c.getLength()),h=new O(T(o,F(r.store,o)),a,a&&a.lastId,h,h&&h.id,t,null,c),h.integrate(e,0),n.right=h,n.index=u,n.forward(),oo(e,t,n,l)},_s=(e,t,n,i,s)=>{const r=e.doc,o=r.clientID;lo(n,s);const l=co(e,t,n,s);t:for(;n.right!==null&&(i>0||l.size>0&&(n.right.deleted||n.right.content.constructor===V));){if(!n.right.deleted)switch(n.right.content.constructor){case V:{const{key:c,value:a}=n.right.content,h=s[c];if(h!==void 0){if(Bt(h,a))l.delete(c);else{if(i===0)break t;l.set(c,a)}n.right.delete(e)}else n.currentAttributes.set(c,a);break}default:i<n.right.length&&rt(e,T(n.right.id.client,n.right.id.clock+i)),i-=n.right.length;break}n.forward()}if(i>0){let c="";for(;i>0;i--)c+=`
5
+ `;n.right=new O(T(o,F(r.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new yt(c)),n.right.integrate(e,0),n.forward()}oo(e,t,n,l)},ao=(e,t,n,i,s)=>{let r=t;const o=xt();for(;r&&(!r.countable||r.deleted);){if(!r.deleted&&r.content.constructor===V){const a=r.content;o.set(a.key,a)}r=r.right}let l=0,c=!1;for(;t!==r;){if(n===t&&(c=!0),!t.deleted){const a=t.content;switch(a.constructor){case V:{const{key:h,value:u}=a,f=i.get(h)??null;(o.get(h)!==a||f===u)&&(t.delete(e),l++,!c&&(s.get(h)??null)===u&&f!==u&&(f===null?s.delete(h):s.set(h,f))),!c&&!t.deleted&&me(s,a);break}}}t=t.right}return l},$u=(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===V){const i=t.content.key;n.has(i)?t.delete(e):n.add(i)}t=t.left}},Fu=e=>{let t=0;return R(e.doc,n=>{let i=e._start,s=e._start,r=xt();const o=ri(r);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case V:me(o,s.content);break;default:t+=ao(n,i,s,r,o),r=ri(o),i=s;break}s=s.right}}),t},Vu=e=>{const t=new Set,n=e.doc;for(const[i,s]of e.afterState.entries()){const r=e.beforeState.get(i)||0;s!==r&&zr(e,n.store.clients.get(i),r,s,o=>{!o.deleted&&o.content.constructor===V&&o.constructor!==dt&&t.add(o.parent)})}R(n,i=>{Pt(e,e.deleteSet,s=>{if(s instanceof dt||!s.parent._hasFormatting||t.has(s.parent))return;const r=s.parent;s.content.constructor===V?t.add(r):$u(i,s)});for(const s of t)Fu(s)})},Ts=(e,t,n)=>{const i=n,s=ri(t.currentAttributes),r=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case vt:case Xt:case yt:n<t.right.length&&rt(e,T(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}r&&ao(e,r,t.right,s,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&Me(o._searchMarker,t.index,-i+n),t};class Hu extends Rn{constructor(t,n,i){super(t,n),this.childListChanged=!1,this.keysChanged=new Set,i.forEach(s=>{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}get changes(){if(this._changes===null){const t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){const t=this.target.doc,n=[];R(t,i=>{const s=new Map,r=new Map;let o=this.target._start,l=null;const c={};let a="",h=0,u=0;const f=()=>{if(l!==null){let p=null;switch(l){case"delete":u>0&&(p={delete:u}),u=0;break;case"insert":(typeof a=="object"||a.length>0)&&(p={insert:a},s.size>0&&(p.attributes={},s.forEach((g,x)=>{g!==null&&(p.attributes[x]=g)}))),a="";break;case"retain":h>0&&(p={retain:h},Xc(c)||(p.attributes=Yc({},c))),h=0;break}p&&n.push(p),l=null}};for(;o!==null;){switch(o.content.constructor){case vt:case Xt:this.adds(o)?this.deletes(o)||(f(),l="insert",a=o.content.getContent()[0],f()):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),u+=1):o.deleted||(l!=="retain"&&(f(),l="retain"),h+=1);break;case yt:this.adds(o)?this.deletes(o)||(l!=="insert"&&(f(),l="insert"),a+=o.content.str):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),u+=o.length):o.deleted||(l!=="retain"&&(f(),l="retain"),h+=o.length);break;case V:{const{key:p,value:g}=o.content;if(this.adds(o)){if(!this.deletes(o)){const x=s.get(p)??null;Bt(x,g)?g!==null&&o.delete(i):(l==="retain"&&f(),Bt(g,r.get(p)??null)?delete c[p]:c[p]=g)}}else if(this.deletes(o)){r.set(p,g);const x=s.get(p)??null;Bt(x,g)||(l==="retain"&&f(),c[p]=x)}else if(!o.deleted){r.set(p,g);const x=c[p];x!==void 0&&(Bt(x,g)?x!==null&&o.delete(i):(l==="retain"&&f(),g===null?delete c[p]:c[p]=g))}o.deleted||(l==="insert"&&f(),me(s,o.content));break}}o=o.right}for(f();n.length>0;){const p=n[n.length-1];if(p.retain!==void 0&&p.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class Ut extends W{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??X(),this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach(i=>i())}catch(i){console.error(i)}this._pending=null}_copy(){return new Ut}clone(){const t=new Ut;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const i=new Hu(this,t,n);Nn(this,t,i),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??X();let t="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===yt&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){this.doc!==null?R(this.doc,i=>{const s=new mi(null,this._start,0,new Map);for(let r=0;r<t.length;r++){const o=t[r];if(o.insert!==void 0){const l=!n&&typeof o.insert=="string"&&r===t.length-1&&s.right===null&&o.insert.slice(-1)===`
6
+ `?o.insert.slice(0,-1):o.insert;(typeof l!="string"||l.length>0)&&Qn(i,this,s,l,o.attributes||{})}else o.retain!==void 0?_s(i,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&Ts(i,s,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,i){this.doc??X();const s=[],r=new Map,o=this.doc;let l="",c=this._start;function a(){if(l.length>0){const u={};let f=!1;r.forEach((g,x)=>{f=!0,u[x]=g});const p={insert:l};f&&(p.attributes=u),s.push(p),l=""}}const h=()=>{for(;c!==null;){if(Ft(c,t)||n!==void 0&&Ft(c,n))switch(c.content.constructor){case yt:{const u=r.get("ychange");t!==void 0&&!Ft(c,t)?(u===void 0||u.user!==c.id.client||u.type!=="removed")&&(a(),r.set("ychange",i?i("removed",c.id):{type:"removed"})):n!==void 0&&!Ft(c,n)?(u===void 0||u.user!==c.id.client||u.type!=="added")&&(a(),r.set("ychange",i?i("added",c.id):{type:"added"})):u!==void 0&&(a(),r.delete("ychange")),l+=c.content.str;break}case vt:case Xt:{a();const u={insert:c.content.getContent()[0]};if(r.size>0){const f={};u.attributes=f,r.forEach((p,g)=>{f[g]=p})}s.push(u);break}case V:Ft(c,t)&&(a(),me(r,c.content));break}c=c.right}a()};return t||n?R(o,u=>{t&&pi(u,t),n&&pi(u,n),h()},"cleanup"):h(),s}insert(t,n,i){if(n.length<=0)return;const s=this.doc;s!==null?R(s,r=>{const o=ze(r,this,t,!i);i||(i={},o.currentAttributes.forEach((l,c)=>{i[c]=l})),Qn(r,this,o,n,i)}):this._pending.push(()=>this.insert(t,n,i))}insertEmbed(t,n,i){const s=this.doc;s!==null?R(s,r=>{const o=ze(r,this,t,!i);Qn(r,this,o,n,i||{})}):this._pending.push(()=>this.insertEmbed(t,n,i||{}))}delete(t,n){if(n===0)return;const i=this.doc;i!==null?R(i,s=>{Ts(s,ze(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?R(s,r=>{const o=ze(r,this,t,!1);o.right!==null&&_s(r,this,o,n,i)}):this._pending.push(()=>this.format(t,n,i))}removeAttribute(t){this.doc!==null?R(this.doc,n=>{fn(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?R(this.doc,i=>{zi(i,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return Ki(this,t)}getAttributes(){return so(this)}_write(t){t.writeTypeRef(ah)}}const zu=e=>new Ut;class ti{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??X()}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(n)))do if(n=t.content.type,!t.deleted&&(n.constructor===et||n.constructor===Wt)&&n._start!==null)t=n._start;else for(;t!==null;){const i=t.next;if(i!==null){t=i;break}else t.parent===this._root?t=null:t=t.parent._item}while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class Wt extends W{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Wt}clone(){const t=new Wt;return t.insert(0,this.toArray().map(n=>n instanceof W?n.clone():n)),t}get length(){return this.doc??X(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new ti(this,t)}querySelector(t){t=t.toUpperCase();const i=new ti(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return i.done?null:i.value}querySelectorAll(t){return t=t.toUpperCase(),qt(new ti(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){Nn(this,t,new Wu(this,n,t))}toString(){return Qr(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},i){const s=t.createDocumentFragment();return i!==void 0&&i._createAssociation(s,this),Oe(this,r=>{s.insertBefore(r.toDOM(t,n,i),null)}),s}insert(t,n){this.doc!==null?R(this.doc,i=>{no(i,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)R(this.doc,i=>{const s=t&&t instanceof W?t._item:t;dn(i,this,s,n)});else{const i=this._prelimContent,s=t===null?0:i.findIndex(r=>r===t)+1;if(s===0&&t!==null)throw _t("Reference item not found");i.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?R(this.doc,i=>{io(i,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return Xr(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return to(this,t)}slice(t=0,n=this.length){return Jr(this,t,n)}forEach(t){Oe(this,t)}_write(t){t.writeTypeRef(hh)}}const Ku=e=>new Wt;class et extends Wt{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach((i,s)=>{this.setAttribute(s,i)}),this._prelimAttrs=null}_copy(){return new et(this.nodeName)}clone(){const t=new et(this.nodeName),n=this.getAttributes();return Jc(n,(i,s)=>{t.setAttribute(s,i)}),t.insert(0,this.toArray().map(i=>i instanceof W?i.clone():i)),t}toString(){const t=this.getAttributes(),n=[],i=[];for(const l in t)i.push(l);i.sort();const s=i.length;for(let l=0;l<s;l++){const c=i[l];n.push(c+'="'+t[c]+'"')}const r=this.nodeName.toLocaleLowerCase(),o=n.length>0?" "+n.join(" "):"";return`<${r}${o}>${super.toString()}</${r}>`}removeAttribute(t){this.doc!==null?R(this.doc,n=>{fn(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?R(this.doc,i=>{zi(i,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return Ki(this,t)}hasAttribute(t){return ro(this,t)}getAttributes(t){return t?Nu(this,t):so(this)}toDOM(t=document,n={},i){const s=t.createElement(this.nodeName),r=this.getAttributes();for(const o in r){const l=r[o];typeof l=="string"&&s.setAttribute(o,l)}return Oe(this,o=>{s.appendChild(o.toDOM(t,n,i))}),i!==void 0&&i._createAssociation(s,this),s}_write(t){t.writeTypeRef(uh),t.writeKey(this.nodeName)}}const qu=e=>new et(e.readKey());class Wu extends Rn{constructor(t,n,i){super(t,i),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}}class pn extends he{constructor(t){super(),this.hookName=t}_copy(){return new pn(this.hookName)}clone(){const t=new pn(this.hookName);return this.forEach((n,i)=>{t.set(i,n)}),t}toDOM(t=document,n={},i){const s=n[this.hookName];let r;return s!==void 0?r=s.createDom(this):r=document.createElement(this.hookName),r.setAttribute("data-yjs-hook",this.hookName),i!==void 0&&i._createAssociation(r,this),r}_write(t){t.writeTypeRef(dh),t.writeKey(this.hookName)}}const Gu=e=>new pn(e.readKey());class ot extends Ut{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 ot}clone(){const t=new ot;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,i){const s=t.createTextNode(this.toString());return i!==void 0&&i._createAssociation(s,this),s}toString(){return this.toDelta().map(t=>{const n=[];for(const s in t.attributes){const r=[];for(const o in t.attributes[s])r.push({key:o,value:t.attributes[s][o]});r.sort((o,l)=>o.key<l.key?-1:1),n.push({nodeName:s,attrs:r})}n.sort((s,r)=>s.nodeName<r.nodeName?-1:1);let i="";for(let s=0;s<n.length;s++){const r=n[s];i+=`<${r.nodeName}`;for(let o=0;o<r.attrs.length;o++){const l=r.attrs[o];i+=` ${l.key}="${l.value}"`}i+=">"}i+=t.insert;for(let s=n.length-1;s>=0;s--)i+=`</${n[s].nodeName}>`;return i}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(fh)}}const Yu=e=>new ot;class qi{constructor(t,n){this.id=t,this.length=n}get deleted(){throw ft()}mergeWith(t){return!1}write(t,n,i){throw ft()}integrate(t,n){throw ft()}}const Ju=0;class dt extends qi{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),Hr(t.doc.store,this)}write(t,n){t.writeInfo(Ju),t.writeLen(this.length-n)}getMissing(t,n){return null}}class Pe{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Pe(this.content)}splice(t){throw ft()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}const Xu=e=>new Pe(e.readBuf());class Re{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Re(this.len)}splice(t){const n=new Re(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){Ae(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 Zu=e=>new Re(e.readLen()),uo=(e,t)=>new Jt({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Ue{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const n={};this.opts=n,t.gc||(n.gc=!1),t.autoLoad&&(n.autoLoad=!0),t.meta!==null&&(n.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Ue(uo(this.doc.guid,this.opts))}splice(t){throw ft()}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 Qu=e=>new Ue(uo(e.readString(),e.readAny()));class Xt{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Xt(this.embed)}splice(t){throw ft()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}const th=e=>new Xt(e.readJSON());class V{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new V(this.key,this.value)}splice(t){throw ft()}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 eh=e=>new V(e.readKey(),e.readJSON());class gn{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new gn(this.arr)}splice(t){const n=new gn(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const i=this.arr.length;t.writeLen(i-n);for(let s=n;s<i;s++){const r=this.arr[s];t.writeString(r===void 0?"undefined":JSON.stringify(r))}}getRef(){return 2}}const nh=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 gn(n)},ih=on("node_env")==="development";class Gt{constructor(t){this.arr=t,ih&&ar(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Gt(this.arr)}splice(t){const n=new Gt(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const i=this.arr.length;t.writeLen(i-n);for(let s=n;s<i;s++){const r=this.arr[s];t.writeAny(r)}}getRef(){return 8}}const sh=e=>{const t=e.readLen(),n=[];for(let i=0;i<t;i++)n.push(e.readAny());return new Gt(n)};class yt{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new yt(this.str)}splice(t){const n=new yt(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 rh=e=>new yt(e.readString()),oh=[Lu,Uu,zu,qu,Ku,Gu,Yu],lh=0,ch=1,ah=2,uh=3,hh=4,dh=5,fh=6;class vt{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new vt(this.type._copy())}splice(t){throw ft()}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 ph=e=>new vt(oh[e.readTypeRef()](e)),xi=(e,t)=>{let n=t,i=0,s;do i>0&&(n=T(n.client,n.clock+i)),s=se(e,n),i=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof O);return{item:s,diff:i}},Wi=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},mn=(e,t,n)=>{const{client:i,clock:s}=t.id,r=new O(T(i,s+n),t,T(i,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&r.markDeleted(),t.keep&&(r.keep=!0),t.redone!==null&&(r.redone=T(t.redone.client,t.redone.clock+n)),t.right=r,r.right!==null&&(r.right.left=r),e._mergeStructs.push(r),r.parentSub!==null&&r.right===null&&r.parent._map.set(r.parentSub,r),t.length=n,r},As=(e,t)=>Ti(e,n=>ge(n.deletions,t)),ho=(e,t,n,i,s,r)=>{const o=e.doc,l=o.store,c=o.clientID,a=t.redone;if(a!==null)return rt(e,a);let h=t.parent._item,u=null,f;if(h!==null&&h.deleted===!0){if(h.redone===null&&(!n.has(h)||ho(e,h,n,i,s,r)===null))return null;for(;h.redone!==null;)h=rt(e,h.redone)}const p=h===null?t.parent:h.content.type;if(t.parentSub===null){for(u=t.left,f=t;u!==null;){let y=u;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:rt(e,y.redone);if(y!==null&&y.parent._item===h){u=y;break}u=u.left}for(;f!==null;){let y=f;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:rt(e,y.redone);if(y!==null&&y.parent._item===h){f=y;break}f=f.right}}else{if(f=null,t.right&&!s){for(u=t;u!==null&&u.right!==null&&(u.right.redone||ge(i,u.right.id)||As(r.undoStack,u.right.id)||As(r.redoStack,u.right.id));)for(u=u.right;u.redone;)u=rt(e,u.redone);if(u&&u.right!==null)return null}else u=p._map.get(t.parentSub)||null;u!==null&&u.parent._item!==h&&(u=p._map.get(t.parentSub)||null)}const g=F(l,c),x=T(c,g),w=new O(x,u,u&&u.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=x,Wi(w,!0),w.integrate(e,0),w};class O extends qi{constructor(t,n,i,s,r,o,l,c){super(t,c.getLength()),this.origin=i,this.left=n,this.right=s,this.rightOrigin=r,this.parent=o,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?ns:0}set marker(t){(this.info&Kn)>0!==t&&(this.info^=Kn)}get marker(){return(this.info&Kn)>0}get keep(){return(this.info&es)>0}set keep(t){this.keep!==t&&(this.info^=es)}get countable(){return(this.info&ns)>0}get deleted(){return(this.info&zn)>0}set deleted(t){this.deleted!==t&&(this.info^=zn)}markDeleted(){this.info|=zn}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=F(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=F(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ie&&this.id.client!==this.parent.client&&this.parent.clock>=F(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=bs(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=rt(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===dt||this.right&&this.right.constructor===dt)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===O?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===O&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===ie){const i=se(n,this.parent);i.constructor===dt?this.parent=null:this.parent=i.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=bs(t,t.doc.store,T(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let i=this.left,s;if(i!==null)s=i.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;const r=new Set,o=new Set;for(;s!==null&&s!==this.right;){if(o.add(s),r.add(s),Fe(this.origin,s.origin)){if(s.id.client<this.id.client)i=s,r.clear();else if(Fe(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&o.has(se(t.doc.store,s.origin)))r.has(se(t.doc.store,s.origin))||(i=s,r.clear());else break;s=s.right}this.left=i}if(this.left!==null){const i=this.left.right;this.right=i,this.left.right=this}else{let i;if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start,this.parent._start=this;this.right=i}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Hr(t.doc.store,this),this.content.integrate(t,this),ys(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new dt(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;t!==null&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;t!==null&&t.deleted;)t=t.left;return t}get lastId(){return this.length===1?this.id:T(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Fe(t.origin,this.lastId)&&this.right===t&&Fe(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(),Ae(t.deleteSet,this.id.client,this.id.clock,this.length),ys(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw it();this.content.gc(t),n?wu(t,this,new dt(this.id,this.length)):this.content=new Re(this.length)}write(t,n){const i=n>0?T(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,r=this.parentSub,o=this.content.getRef()&Sn|(i===null?0:nt)|(s===null?0:Dt)|(r===null?0:Ce);if(t.writeInfo(o),i!==null&&t.writeLeftID(i),s!==null&&t.writeRightID(s),i===null&&s===null){const l=this.parent;if(l._item!==void 0){const c=l._item;if(c===null){const a=Ie(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===ie?(t.writeParentInfo(!1),t.writeLeftID(l)):it();r!==null&&t.writeString(r)}this.content.write(t,n)}}const fo=(e,t)=>gh[t&Sn](e),gh=[()=>{it()},Zu,nh,Xu,rh,th,eh,ph,sh,Qu,()=>{it()}],mh=10;class pt extends qi{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){it()}write(t,n){t.writeInfo(mh),I(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const po=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},go="__ $YJS$ __";po[go]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");po[go]=!0;const xh=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},bh=/[\uD800-\uDBFF]/,wh=/[\uDC00-\uDFFF]/,yh=(e,t)=>{let n=0,i=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&bh.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&&wh.test(e[e.length-i])&&i--,{index:n,remove:e.length-n-i,insert:t.slice(n,t.length-i)}},vh=yh,Et=(e,t)=>e>>>t|e<<32-t,Sh=e=>Et(e,2)^Et(e,13)^Et(e,22),Ch=e=>Et(e,6)^Et(e,11)^Et(e,25),kh=e=>Et(e,7)^Et(e,18)^e>>>3,Eh=e=>Et(e,17)^Et(e,19)^e>>>10,_h=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]),Th=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class Ah{constructor(){const t=new ArrayBuffer(320);this._H=new Uint32Array(t,0,8),this._H.set(Th),this._W=new Uint32Array(t,64,64)}_updateHash(){const t=this._H,n=this._W;for(let u=16;u<64;u++)n[u]=Eh(n[u-2])+n[u-7]+kh(n[u-15])+n[u-16];let i=t[0],s=t[1],r=t[2],o=t[3],l=t[4],c=t[5],a=t[6],h=t[7];for(let u=0,f,p;u<64;u++)f=h+Ch(l)+(l&c^~l&a)+_h[u]+n[u]>>>0,p=Sh(i)+(i&s^i&r^s&r)>>>0,h=a,a=c,c=l,l=o+f>>>0,o=r,r=s,s=i,i=f+p>>>0;t[0]+=i,t[1]+=s,t[2]+=r,t[3]+=o,t[4]+=l,t[5]+=c,t[6]+=a,t[7]+=h}digest(t){let n=0;for(;n+56<=t.length;){let o=0;for(;o<16&&n+3<t.length;o++)this._W[o]=t[n++]<<24|t[n++]<<16|t[n++]<<8|t[n++];if(n%64!==0){for(this._W.fill(0,o,16);n<t.length;)this._W[o]|=t[n]<<(3-n%4)*8,n++;this._W[o]|=nt<<(3-n%4)*8}this._updateHash()}const i=n%64!==0;this._W.fill(0,0,16);let s=0;for(;n<t.length;s++)for(let o=3;o>=0&&n<t.length;o--)this._W[s]|=t[n++]<<o*8;i||(this._W[s-(n%4===0?0:1)]|=nt<<(3-n%4)*8),this._W[14]=t.byteLength/cc,this._W[15]=t.byteLength*8,this._updateHash();const r=new Uint8Array(32);for(let o=0;o<this._H.length;o++)for(let l=0;l<4;l++)r[o*4+l]=this._H[o]>>>(3-l)*8;return r}}const Ih=e=>new Ah().digest(e),B=new _.PluginKey("y-sync"),Mt=new _.PluginKey("y-undo");new _.PluginKey("yjs-cursor");const Dh=e=>{for(let n=6;n<e.length;n++)e[n%6]=e[n%6]^e[n];return e.slice(0,6)},Mh=e=>la(Dh(Ih(ca(e)))),xn=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!ge(t.ds,e.id),Oh=[{light:"#ecd44433",dark:"#ecd444"}],Rh=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){const i=Kt();e.forEach(s=>i.add(s)),t=t.filter(s=>!i.has(s))}e.set(n,Fc(t))}return e.get(n)},jh=(e,{colors:t=Oh,colorMapping:n=new Map,permanentUserData:i=null,onFirstRender:s=()=>{},mapping:r}={})=>{let o=!1;const l=new Ph(e,r),c=new _.Plugin({props:{editable:a=>{const h=B.getState(a);return h.snapshot==null&&h.prevSnapshot==null}},key:B,state:{init:(a,h)=>({type:e,doc:e.doc,binding:l,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:t,colorMapping:n,permanentUserData:i}),apply:(a,h)=>{const u=a.getMeta(B);if(u!==void 0){h=Object.assign({},h);for(const f in u)h[f]=u[f]}return h.addToHistory=a.getMeta("addToHistory")!==!1,h.isChangeOrigin=u!==void 0&&!!u.isChangeOrigin,h.isUndoRedoOperation=u!==void 0&&!!u.isChangeOrigin&&!!u.isUndoRedoOperation,l.prosemirrorView!==null&&u!==void 0&&(u.snapshot!=null||u.prevSnapshot!=null)&&Ar(0,()=>{l.prosemirrorView!=null&&(u.restore==null?l._renderSnapshot(u.snapshot,u.prevSnapshot,h):(l._renderSnapshot(u.snapshot,u.snapshot,h),delete h.restore,delete h.snapshot,delete h.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),h}},view:a=>(l.initView(a),r==null&&l._forceRerender(),s(),{update:()=>{const h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(o||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(o=!0,h.addToHistory===!1&&!h.isChangeOrigin){const u=Mt.getState(a.state),f=u&&u.undoManager;f&&f.stopCapturing()}l.mux(()=>{h.doc.transact(u=>{u.meta.set("addToHistory",h.addToHistory),l._prosemirrorChanged(a.state.doc)},B)})}},destroy:()=>{l.destroy()}})});return c},Nh=(e,t,n,i)=>{if(t!==null&&t.anchor!==null&&t.head!==null)if(t.type==="all")e.setSelection(new _.AllSelection(e.doc));else if(t.type==="node"){const s=Vt(n.doc,n.type,t.anchor,n.mapping);s!==null&&e.setSelection(Bh(e,s))}else if(t.type==="nodeRange"){const s=Vt(n.doc,n.type,t.anchor,n.mapping),r=Vt(n.doc,n.type,t.head,n.mapping),o=Lh(e,s,r,t.depth);o!==null&&e.setSelection(o)}else{let s=Vt(n.doc,n.type,t.anchor,n.mapping),r=Vt(n.doc,n.type,t.head,n.mapping);i!=null&&t.absAnchor!=null&&t.absHead!=null&&(s===null||r===null||t.absAnchor>1&&s!==null&&s<=1||t.absHead>1&&r!==null&&r<=1||Ms(i,e.doc,t.absAnchor,s)||Ms(i,e.doc,t.absHead,r))&&(s=Si(i,e.doc,t.absAnchor),r=Si(i,e.doc,t.absHead)),s!==null&&r!==null&&e.setSelection(_.TextSelection.between(e.doc.resolve(s),e.doc.resolve(r)))}},Bh=(e,t)=>{const n=e.doc.resolve(t);return n.nodeAfter?_.NodeSelection.create(e.doc,t):_.TextSelection.near(n)},Lh=(e,t,n,i)=>{if(t===null||n===null)return null;const s=Math.min(Math.max(t,0),e.doc.content.size),r=Math.min(Math.max(n,0),e.doc.content.size);try{const o=_.Selection.fromJSON(e.doc,{type:"nodeRange",anchor:s,head:r,depth:i});return o.ranges.length?o:_.TextSelection.near(e.doc.resolve(s))}catch{return _.TextSelection.near(e.doc.resolve(s))}},bi=(e,t)=>{const n=t.selection.jsonID;return{type:n,depth:n==="nodeRange"?t.selection.depth:void 0,anchor:wn(t.selection.anchor,e.type,e.mapping),head:wn(t.selection.head,e.type,e.mapping),absAnchor:t.selection.anchor,absHead:t.selection.head}};class Ph{constructor(t,n=new Map){this.type=t,this.prosemirrorView=null,this.mux=xh(),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=bi(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()?(ur&&this._domSelectionInView===null&&(Ar(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){const t=this.prosemirrorView._root.getSelection();if(t==null||t.anchorNode==null)return!1;const n=this.prosemirrorView._root.createRange();n.setStart(t.anchorNode,t.anchorOffset),n.setEnd(t.focusNode,t.focusOffset),n.getClientRects().length===0&&n.startContainer&&n.collapsed&&n.selectNodeContents(n.startContainer);const s=n.getBoundingClientRect(),r=Le.documentElement;return s.bottom>=0&&s.right>=0&&s.left<=(window.innerWidth||r.clientWidth||0)&&s.top<=(window.innerHeight||r.clientHeight||0)}renderSnapshot(t,n){n||(n=Fr(Br(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(B,{snapshot:t,prevSnapshot:n}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{const t=this.type.toArray().map(i=>Qe(i,this.prosemirrorView.state.schema,this)).filter(i=>i!==null),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new _.Slice(_.Fragment.from(t),0,0));n.setMeta(B,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(n)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{const t=this.beforeTransactionSelection!==null?null:this.prosemirrorView.state.selection,n=this.type.toArray().map(s=>Qe(s,this.prosemirrorView.state.schema,this)).filter(s=>s!==null),i=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new _.Slice(_.Fragment.from(n),0,0));if(t){const s=le(Lt(t.anchor,0),i.doc.content.size),r=le(Lt(t.head,0),i.doc.content.size);i.setSelection(_.TextSelection.create(i.doc,s,r))}this.prosemirrorView.dispatch(i.setMeta(B,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(t,n,i){let s=this.doc,r=this.type;if(t||(t=Zn(this.doc)),t instanceof Uint8Array||n instanceof Uint8Array)if((!(t instanceof Uint8Array)||!(n instanceof Uint8Array))&&it(),s=new Jt({gc:!1}),fi(s,n),n=Zn(s),fi(s,t),t=Zn(s),r._item===null){const o=Array.from(this.doc.share.keys()).find(l=>this.doc.share.get(l)===this.type);r=s.getXmlFragment(o)}else{const o=s.store.clients.get(r._item.id.client)??[],l=wt(o,r._item.id.clock);r=o[l].content.type}this.mapping.clear(),this.mux(()=>{s.transact(o=>{const l=i.permanentUserData;l&&l.dss.forEach(u=>{Pt(o,u,f=>{})});const c=(u,f)=>{const p=u==="added"?l.getUserByClientId(f.client):l.getUserByDeletedId(f);return{user:p,type:u,color:Rh(i.colorMapping,i.colors,p)}},a=Zr(r,new Vi(n.ds,t.sv)).map(u=>!u._item.deleted||xn(u._item,t)||xn(u._item,n)?Qe(u,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},t,n,c):null).filter(u=>u!==null),h=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new _.Slice(_.Fragment.from(a),0,0));this.prosemirrorView.dispatch(h.setMeta(B,{isChangeOrigin:!0}))},B)})}_typeChanged(t,n){if(this.prosemirrorView==null)return;const i=B.getState(this.prosemirrorView.state);if(t.length===0||i.snapshot!=null||i.prevSnapshot!=null){this.renderSnapshot(i.snapshot,i.prevSnapshot);return}this.mux(()=>{const s=(c,a)=>this.mapping.delete(a);Pt(n,n.deleteSet,c=>{if(c.constructor===O){const a=c.content.type;a&&this.mapping.delete(a)}}),n.changed.forEach(s),n.changedParentTypes.forEach(s),this.mapping.clear();const r=this.type.toArray().map(c=>mo(c,this.prosemirrorView.state.schema,this)).filter(c=>c!==null),o=this.prosemirrorView.state.doc;let l=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new _.Slice(_.Fragment.from(r),0,0));Nh(l,this.beforeTransactionSelection,this,o),l=l.setMeta(B,{isChangeOrigin:!0,isUndoRedoOperation:n.origin instanceof qr}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&l.scrollIntoView(),this.prosemirrorView.dispatch(l)})}_prosemirrorChanged(t){this.doc.transact(()=>{yi(this.doc,this.type,t,this),this.beforeTransactionSelection=bi(this,this.prosemirrorView.state)},B)}initView(t){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=t,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}}const mo=(e,t,n,i,s,r)=>{const o=n.mapping.get(e);if(o===void 0){if(e instanceof et)return Qe(e,t,n,i,s,r);throw ft()}return o},Qe=(e,t,n,i,s,r)=>{const o=[],l=c=>{var a,h;if(c instanceof et){const u=mo(c,t,n,i,s,r);u!==null&&o.push(u)}else{const u=(h=(a=c._item.right)==null?void 0:a.content)==null?void 0:h.type;u instanceof Ut&&!u._item.deleted&&u._item.id.client===u.doc.clientID&&(c.applyDelta([{retain:c.length},...u.toDelta()]),u.doc.transact(p=>{u._item.delete(p)}));const f=Uh(c,t,n,i,s,r);f!==null&&f.forEach(p=>{p!==null&&o.push(p)})}};i===void 0||s===void 0?e.toArray().forEach(l):Zr(e,new Vi(s.ds,i.sv)).forEach(l);try{const c=e.getAttributes(i);i!==void 0&&(xn(e._item,i)?xn(e._item,s)||(c.ychange=r?r("added",e._item.id):{type:"added"}):c.ychange=r?r("removed",e._item.id):{type:"removed"});const a=t.node(e.nodeName,c,o);return n.mapping.set(e,a),a}catch{return e.doc.transact(a=>{e._item.delete(a)},B),n.mapping.delete(e),null}},Uh=(e,t,n,i,s,r)=>{const o=[],l=e.toDelta(i,s,r);try{for(let c=0;c<l.length;c++){const a=l[c];o.push(t.text(a.insert,Kh(a.attributes,t)))}}catch{return e.doc.transact(a=>{e._item.delete(a)},B),null}return o},$h=(e,t)=>{const n=new ot,i=e.map(s=>({insert:s.text,attributes:wo(s.marks,t)}));return n.applyDelta(i),t.mapping.set(n,e),n},Fh=(e,t)=>{const n=new et(e.type.name);for(const i in e.attrs){const s=e.attrs[i];s!==null&&i!=="ychange"&&n.setAttribute(i,s)}return n.insert(0,Bn(e).map(i=>wi(i,t))),t.mapping.set(n,e),n},wi=(e,t)=>e instanceof Array?$h(e,t):Fh(e,t),Is=e=>typeof e=="object"&&e!==null,Gi=(e,t)=>{const n=Object.keys(e).filter(s=>e[s]!==null);let i=n.length===Object.keys(t).filter(s=>t[s]!==null).length;for(let s=0;s<n.length&&i;s++){const r=n[s],o=e[r],l=t[r];i=r==="ychange"||o===l||Is(o)&&Is(l)&&Gi(o,l)}return i},Bn=e=>{const t=e.content.content,n=[];for(let i=0;i<t.length;i++){const s=t[i];if(s.isText){const r=[];for(let o=t[i];i<t.length&&o.isText;o=t[++i])r.push(o);i--,n.push(r)}else n.push(s)}return n},xo=(e,t)=>{const n=e.toDelta();return n.length===t.length&&n.every((i,s)=>i.insert===t[s].text&&cr(i.attributes||{}).length===t[s].marks.length&&de(i.attributes,(r,o)=>{var h;const l=bo(o),c=t[s].marks;return c.find(u=>u.type.name===l)?Gi(r,(h=c.find(u=>u.type.name===l))==null?void 0:h.attrs):!1}))},je=(e,t)=>{if(e instanceof et&&!(t instanceof Array)&&vi(e,t)){const n=Bn(t);return e._length===n.length&&Gi(e.getAttributes(),t.attrs)&&e.toArray().every((i,s)=>je(i,n[s]))}return e instanceof ot&&t instanceof Array&&xo(e,t)},bn=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((n,i)=>t[i]===n),Ds=(e,t,n)=>{const i=e.toArray(),s=Bn(t),r=s.length,o=i.length,l=le(o,r);let c=0,a=0,h=!1;for(;c<l;c++){const u=i[c],f=s[c];if(bn(n.mapping.get(u),f))h=!0;else if(!je(u,f))break}for(;c+a<l;a++){const u=i[o-a-1],f=s[r-a-1];if(bn(n.mapping.get(u),f))h=!0;else if(!je(u,f))break}return{equalityFactor:c+a,foundMappedChild:h}},Vh=e=>{let t="",n=e._start;const i={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof yt?t+=n.content.str:n.content instanceof V&&(i[n.content.key]=null)),n=n.right;return{str:t,nAttrs:i}},Hh=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:i,str:s}=Vh(e),r=t.map(a=>({insert:a.text,attributes:Object.assign({},i,wo(a.marks,n))})),{insert:o,remove:l,index:c}=vh(s,r.map(a=>a.insert).join(""));e.delete(c,l),e.insert(c,o),e.applyDelta(r.map(a=>({retain:a.insert.length,attributes:a.attributes})))},zh=/(.*)(--[a-zA-Z0-9+/=]{8})$/,bo=e=>{var t;return((t=zh.exec(e))==null?void 0:t[1])??e},Kh=(e,t)=>{const n=[];for(const i in e)n.push(t.mark(bo(i),e[i]));return n},wo=(e,t)=>{const n={};return e.forEach(i=>{if(i.type.name!=="ychange"){const s=Ot(t.isOMark,i.type,()=>!i.type.excludes(i.type));n[s?`${i.type.name}--${Mh(i.toJSON())}`:i.type.name]=i.attrs}}),n},yi=(e,t,n,i)=>{if(t instanceof et&&t.nodeName!==n.type.name)throw new Error("node name mismatch!");if(i.mapping.set(t,n),t instanceof et){const u=t.getAttributes(),f=n.attrs;for(const p in f)f[p]!==null?u[p]!==f[p]&&p!=="ychange"&&t.setAttribute(p,f[p]):t.removeAttribute(p);for(const p in u)f[p]===void 0&&t.removeAttribute(p)}const s=Bn(n),r=s.length,o=t.toArray(),l=o.length,c=le(r,l);let a=0,h=0;for(;a<c;a++){const u=o[a],f=s[a];if(!bn(i.mapping.get(u),f))if(je(u,f))i.mapping.set(u,f);else break}for(;h+a+1<c;h++){const u=o[l-h-1],f=s[r-h-1];if(!bn(i.mapping.get(u),f))if(je(u,f))i.mapping.set(u,f);else break}e.transact(()=>{for(;l-a-h>0&&r-a-h>0;){const f=o[a],p=s[a],g=o[l-h-1],x=s[r-h-1];if(f instanceof ot&&p instanceof Array)xo(f,p)||Hh(f,p,i),a+=1;else{let w=f instanceof et&&vi(f,p),y=g instanceof et&&vi(g,x);if(w&&y){const S=Ds(f,p,i),k=Ds(g,x,i);S.foundMappedChild&&!k.foundMappedChild?y=!1:!S.foundMappedChild&&k.foundMappedChild||S.equalityFactor<k.equalityFactor?w=!1:y=!1}w?(yi(e,f,p,i),a+=1):y?(yi(e,g,x,i),h+=1):(i.mapping.delete(t.get(a)),t.delete(a,1),t.insert(a,[wi(p,i)]),a+=1)}}const u=l-a-h;if(l===1&&r===0&&o[0]instanceof ot?(i.mapping.delete(o[0]),o[0].delete(0,o[0].length)):u>0&&(t.slice(a,a+u).forEach(f=>i.mapping.delete(f)),t.delete(a,u)),a+h<r){const f=[];for(let p=a;p<r-h;p++)f.push(wi(s[p],i));t.insert(a,f)}},B)},vi=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,wn=(e,t,n)=>{if(e===0)return Xn(t,0,-1);let i=t._first===null?null:t._first.content.type;for(;i!==null&&t!==i;){if(i instanceof ot){if(i._length>=e)return Xn(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 hn(i._item===null?null:i._item.id,i._item===null?Ie(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 hn(i._item===null?null:i._item.id,i._item===null?Ie(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 it();if(e===0&&i.constructor!==ot&&i!==t)return Wh(i._item.parent,i._item)}return Xn(t,t._length,-1)},qh=(e,t,n)=>{if(n===null)return!1;const i=$r(t,e);return i!==null&&i.type instanceof ot&&t.item!==null&&n<=1},Wh=(e,t)=>{let n=null,i=null;return e._item===null?i=Ie(e):n=T(e._item.id.client,e._item.id.clock),new hn(n,i,t.id)},Vt=(e,t,n,i)=>{const s=$r(n,e);if(s===null||s.type!==t&&!De(t,s.type._item))return null;let r=s.type,o=0;if(r.constructor===ot)o=s.index;else if(r._item===null||!r._item.deleted){let c=r._first,a=0;for(;a<r._length&&a<s.index&&c!==null;){if(!c.deleted){const h=c.content.type;if(a++,h instanceof ot)o+=h._length;else{const u=i.get(h);if(u==null)return null;o+=u.nodeSize}}c=c.right}o+=1}for(;r!==t&&r._item!==null;){const c=r._item.parent;if(c._item===null||!c._item.deleted){o+=1;let a=c._first;for(;a!==null;){const h=a.content.type;if(h===r)break;if(!a.deleted)if(h instanceof ot)o+=h._length;else{const u=i.get(h);if(u==null)return null;o+=u.nodeSize}a=a.right}}r=c}const l=o-1;return qh(e,n,l)?null:l},Si=(e,t,n)=>{let i=0,s=0;for(;s<e.childCount;s++){const h=e.child(s);if(i+h.nodeSize>n)break;i+=h.nodeSize}if(s>=e.childCount)return null;const r=e.child(s),o=n-i;let l=0;for(let h=0;h<=s;h++){const u=e.child(h);u.type===r.type&&u.textContent===r.textContent&&l++}let c=0,a=0;for(let h=0;h<t.childCount;h++){const u=t.child(h);if(u.type===r.type&&u.textContent===r.textContent&&(c++,c===l)){const f=a+o,p=a+1,g=a+u.nodeSize-1;return Math.max(p,Math.min(f,g))}a+=u.nodeSize}return null},Ms=(e,t,n,i)=>{if(i===null)return!1;const s=e.resolve(n),r=t.resolve(i);if(!s.parent.isTextblock||!r.parent.isTextblock)return!1;if(s.parent.textContent!==r.parent.textContent||s.parentOffset!==0&&r.parentOffset===0)return!0;if(s.parentOffset===0&&r.parentOffset===0){const o=Si(e,t,n);return o!==null&&o!==i}return!1},Gh=e=>{const t=Mt.getState(e).undoManager;if(t!=null)return t.undo(),!0},Yh=e=>{const t=Mt.getState(e).undoManager;if(t!=null)return t.redo(),!0},Jh=new Set(["paragraph"]),Xh=(e,t)=>!(e instanceof O)||!(e.content instanceof vt)||!(e.content.type instanceof Ut||e.content.type instanceof et&&t.has(e.content.type.nodeName))||e.content.type._length===0,Zh=({protectedNodes:e=Jh,trackedOrigins:t=[],undoManager:n=null}={})=>new _.Plugin({key:Mt,state:{init:(i,s)=>{const r=B.getState(s);let o=n;if(!o){const l=r.doc,c=new Set(l?l._observers.get("destroy"):[]);o=new qr(r.type,{trackedOrigins:new Set([B].concat(t)),deleteFilter:h=>Xh(h,e),captureTransaction:h=>h.meta.get("addToHistory")!==!1});const a=l?l._observers.get("destroy"):new Set;o._yTiptapDocDestroyListeners=Array.from(a||[]).filter(h=>!c.has(h))}return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(i,s,r,o)=>{const l=B.getState(o).binding,c=s.undoManager,a=c.undoStack.length>0,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:bi(l,r),hasUndoOps:a,hasRedoOps:h}:a!==s.hasUndoOps||h!==s.hasRedoOps?Object.assign({},s,{hasUndoOps:c.undoStack.length>0,hasRedoOps:c.redoStack.length>0}):s}},view:i=>{const s=B.getState(i.state),r=Mt.getState(i.state).undoManager;return r.on("stack-item-added",({stackItem:o})=>{const l=s.binding;l&&o.meta.set(l,Mt.getState(i.state).prevSel)}),r.on("stack-item-popped",({stackItem:o})=>{const l=s.binding;l&&(l.beforeTransactionSelection=o.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{r.destroy();const o=r._yTiptapDocDestroyListeners;o&&r.doc&&(o.forEach(l=>r.doc.off("destroy",l)),r._yTiptapDocDestroyListeners=null)}}}});function yn(e){return!!e.getMeta(B)}function Qh(e,t){const n=B.getState(e);return Vt(n.doc,n.type,t,n.binding.mapping)||0}function yo(e,t){const n=B.getState(e);return wn(t,n.type,n.binding.mapping)}var tn=class vo extends _.MappablePosition{constructor(t,n){super(t),this.yRelativePosition=n}static fromJSON(t){return new vo(t.position,t.yRelativePosition)}toJSON(){return{position:this.position,yRelativePosition:this.yRelativePosition}}};function td(e,t){const n=yo(t,e);return new tn(e,n)}function ed(e,t,n){const i=e instanceof tn?e.yRelativePosition:null;if(yn(t)&&i){const o=Qh(n,i);return{position:new tn(o,i),mapResult:null}}const s=_.getUpdatedPosition(e,t),r=s.position.position;return{position:new tn(r,i??yo(n,r)),mapResult:s.mapResult}}_.Extension.create({name:"collaboration",priority:1e3,addOptions(){return{document:null,field:"default",fragment:null,provider:null}},addStorage(){return{isDisabled:!1}},onCreate(){this.editor.extensionManager.extensions.find(e=>e.name==="undoRedo")&&console.warn('[tiptap warn]: "@tiptap/extension-collaboration" comes with its own history support and is not compatible with "@tiptap/extension-undo-redo".')},onBeforeCreate(){this.editor.utils.getUpdatedPosition=(e,t)=>ed(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>td(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),Mt.getState(t).undoManager.undoStack.length===0?!1:n?Gh(t):!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),Mt.getState(t).undoManager.redoStack.length===0?!1:n?Yh(t):!0)}},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo()}},addProseMirrorPlugins(){const e=this.options.fragment?this.options.fragment:this.options.document.getXmlFragment(this.options.field),t=Zh(this.options.yUndoOptions),n=t.spec.view;t.spec.view=r=>{const{undoManager:o}=Mt.getState(r.state);o.restore&&(o.restore(),o.restore=()=>{});const l=n?n(r):void 0;return{destroy:()=>{const c=o.trackedOrigins.has(o),a=o._observers;o.restore=()=>{c&&o.trackedOrigins.add(o),o.doc.on("afterTransaction",o.afterTransactionHandler),o._observers=a},l!=null&&l.destroy&&l.destroy()}}};const i={...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender};return[jh(e,i),t,this.editor.options.enableContentCheck&&new K.Plugin({key:new K.PluginKey("filterInvalidContent"),filterTransaction:r=>{if(!yn(r))return!0;if(this.storage.isDisabled)return!1;if(!r.docChanged)return!0;try{return r.doc.check(),!0}catch(o){return this.storage.isDisabled=!0,this.editor.emit("contentError",{error:o,editor:this.editor,disableCollaboration:()=>{var l;(l=e.doc)==null||l.destroy()}}),!0}}})].filter(Boolean)}});function Os(e){if(!e.length)return $n.DecorationSet.empty;const t=[],n=e[0].$from.node(0);return e.forEach(i=>{const s=i.$from.pos,r=i.$from.nodeAfter;r&&t.push($n.Decoration.node(s,s+r.nodeSize,{class:"ProseMirror-selectednoderange"}))}),$n.DecorationSet.create(n,t)}function nd(e,t,n){const i=n.isText||n.isAtom?0:1;return{start:e+i,end:e+t-i}}function Ln(e,t,n,i={}){const s=[],r=e.node(0),{extendOnBoundaryOverlap:o=!0}=i;typeof n=="number"&&n>=0||(e.sameParent(t)?n=Math.max(0,e.sharedDepth(t.pos)-1):n=e.sharedDepth(t.pos));const l=new Uo.NodeRange(e,t,n),c=l.depth===0?0:r.resolve(l.start).posAtIndex(0);return l.parent.forEach((a,h)=>{const u=c+h,f=u+a.nodeSize,p=nd(u,a.nodeSize,a),g=o?t.pos>=p.start&&e.pos<=p.end:t.pos>p.start&&e.pos<p.end;if(u<l.start||u>=l.end||!g)return;const x=new K.SelectionRange(r.resolve(u),r.resolve(f));s.push(x)}),s}var id=class So{constructor(t,n,i){this.anchor=t,this.head=n,this.depth=i??0}map(t){return new So(t.map(this.anchor),t.map(this.head),this.depth)}resolve(t){const n=t.resolve(this.anchor),i=t.resolve(this.head);return new Ct(n,i,this.depth)}},Ct=class Nt extends K.Selection{constructor(t,n,i,s=1){const{doc:r}=t,o=t===n,l=t.pos===r.content.size&&n.pos===r.content.size,c=o&&!l?r.resolve(n.pos+(s>0?1:-1)):n,a=o&&l?r.resolve(t.pos-(s>0?1:-1)):t,h=Ln(a.min(c),a.max(c),i),u=c.pos>=t.pos?h[0].$from:h[h.length-1].$to,f=c.pos>=t.pos?h[h.length-1].$to:h[0].$from;super(u,f,h),this.depth=i}get $to(){return this.ranges[this.ranges.length-1].$to}eq(t){return t instanceof Nt&&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 Nt(i,s,this.depth)}toJSON(){return{type:"nodeRange",anchor:this.anchor,head:this.head,depth:this.depth}}get isForwards(){return this.head>=this.anchor}get isBackwards(){return!this.isForwards}extendBackwards(){const{doc:t}=this.$from;if(this.isForwards&&this.ranges.length>1){const s=this.ranges.slice(0,-1),r=s[0].$from,o=s[s.length-1].$to;return new Nt(r,o,this.depth)}const n=this.ranges[0],i=t.resolve(Math.max(0,n.$from.pos-1));return new Nt(this.$anchor,i,this.depth)}extendForwards(){const{doc:t}=this.$from;if(this.isBackwards&&this.ranges.length>1){const s=this.ranges.slice(1),r=s[0].$from,o=s[s.length-1].$to;return new Nt(o,r,this.depth)}const n=this.ranges[this.ranges.length-1],i=t.resolve(Math.min(t.content.size,n.$to.pos+1));return new Nt(this.$anchor,i,this.depth)}static fromJSON(t,n){return new Nt(t.resolve(n.anchor),t.resolve(n.head),n.depth)}static create(t,n,i,s,r=1){return new this(t.resolve(n),t.resolve(i),s,r)}getBookmark(){return new id(this.anchor,this.head,this.depth)}};Ct.prototype.visible=!1;try{K.Selection.jsonID("nodeRange",Ct)}catch{}function ve(e){return e instanceof Ct}_.Extension.create({name:"nodeRange",addOptions(){return{depth:void 0,key:"Mod"}},addKeyboardShortcuts(){return{"Shift-ArrowUp":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,selection:r,tr:o}=i,{anchor:l,head:c}=r;if(!ve(r)){const h=Ct.create(s,l,c,t,-1);return o.setSelection(h),n.dispatch(o),!0}const a=r.extendBackwards();return o.setSelection(a),n.dispatch(o),!0},"Shift-ArrowDown":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,selection:r,tr:o}=i,{anchor:l,head:c}=r;if(!ve(r)){const h=Ct.create(s,l,c,t);return o.setSelection(h),n.dispatch(o),!0}const a=r.extendForwards();return o.setSelection(a),n.dispatch(o),!0},"Mod-a":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,tr:r}=i,o=Ct.create(s,0,s.content.size,t);return r.setSelection(o),n.dispatch(r),!0}}},onSelectionUpdate(){const{selection:e}=this.editor.state;ve(e)&&this.editor.view.dom.classList.add("ProseMirror-noderangeselection")},addProseMirrorPlugins(){let e=!1,t=!1;return[new K.Plugin({key:new K.PluginKey("nodeRange"),props:{attributes:()=>e?{class:"ProseMirror-noderangeselection"}:{class:""},handleDOMEvents:{mousedown:(n,i)=>{const{key:s}=this.options,r=/Mac/.test(navigator.platform),o=!!i.shiftKey,l=!!i.ctrlKey,c=!!i.altKey,a=!!i.metaKey,h=r?a:l;return(s==null||s==="Shift"&&o||s==="Control"&&l||s==="Alt"&&c||s==="Meta"&&a||s==="Mod"&&h)&&(t=!0),t&&document.addEventListener("mouseup",()=>{t=!1;const{state:u}=n,{doc:f,selection:p,tr:g}=u,{$anchor:x,$head:w}=p;if(x.sameParent(w))return;const y=Ct.create(f,x.pos,w.pos,this.options.depth);g.setSelection(y),n.dispatch(g)},{once:!0}),!1}},decorations:n=>{const{selection:i}=n,s=ve(i);if(e=!1,!t)return s?(e=!0,Os(i.ranges)):null;const{$from:r,$to:o}=i;if(!s&&r.sameParent(o))return null;const l=Ln(r,o,this.options.depth);return l.length?(e=!0,Os(l)):null}}})]}});function sd(e,t){const n=getComputedStyle(e);if(t)return t.map(s=>s.trim()).filter(s=>s.length>0).map(s=>`${s}:${n.getPropertyValue(s)};`).join("");let i="";for(let s=0;s<n.length;s+=1)i+=`${n[s]}:${n.getPropertyValue(n[s])};`;return i}function rd(e,t){const n=e.cloneNode(!0),i=[e,...Array.from(e.getElementsByTagName("*"))],s=[n,...Array.from(n.getElementsByTagName("*"))];return i.forEach((r,o)=>{s[o].style.cssText=sd(r,t)}),n}var od={id:"listItemFirstChild",evaluate:({parent:e,isFirst:t})=>t&&e&&["listItem","taskItem"].includes(e.type.name)?1e3:0},ld={id:"listWrapperDeprioritize",evaluate:({node:e})=>{const t=["listItem","taskItem"],n=e.firstChild;return n&&t.includes(n.type.name)?1e3:0}},cd={id:"tableStructure",evaluate:({node:e,parent:t})=>["tableRow","tableCell","tableHeader"].includes(e.type.name)||t&&t.type.name==="tableHeader"?1e3:0},ad={id:"inlineContent",evaluate:({node:e})=>e.isInline||e.isText?1e3:0},ud=[od,ld,cd,ad],Rs={edges:["left","top"],threshold:12,strength:500};function ei(e){return e===void 0||e==="left"?{...Rs}:e==="right"?{edges:["right","top"],threshold:12,strength:500}:e==="both"?{edges:["left","right","top"],threshold:12,strength:500}:e==="none"?{edges:[],threshold:0,strength:0}:{...Rs,...e}}function hd(e,t,n){if(n.edges.length===0)return!1;const i=t.getBoundingClientRect(),{threshold:s,edges:r}=n;return r.some(o=>o==="left"?e.x-i.left<s:o==="right"?i.right-e.x<s:o==="top"?e.y-i.top<s:o==="bottom"?i.bottom-e.y<s:!1)}function dd(e,t,n,i){return!t||n.edges.length===0?0:hd(e,t,n)?n.strength*i:0}var fd=1e3;function js(e,t,n,i){let s=fd,r=!1;if(t.every(l=>{const c=l.evaluate(e);return s-=c,s<=0?(r=!0,!1):!0}),r)return-1;const o=e.view.nodeDOM(e.pos);return s-=dd(i,o,n,e.depth),s<=0?-1:s}function Ns(e,t,n){return Array.from({length:t},(s,r)=>t-1-r).some(s=>n.includes(e.node(s).type.name))}function pd(e,t,n){if(!Number.isFinite(t.x)||!Number.isFinite(t.y))return null;const i=e.posAtCoords({left:t.x,top:t.y});if(!i)return null;const{doc:s}=e.state,r=s.resolve(i.pos),o=[];n.defaultRules&&o.push(...ud),o.push(...n.rules);const c=Array.from({length:r.depth},(u,f)=>r.depth-f).map(u=>{const f=r.node(u),p=r.before(u);if(n.allowedContainers&&u>0&&!Ns(r,u,n.allowedContainers))return null;const g=u>0?r.node(u-1):null,x=u>0?r.index(u-1):0,w=g?g.childCount:1,y={node:f,pos:p,depth:u,parent:g,index:x,isFirst:x===0,isLast:x===w-1,$pos:r,view:e},S=js(y,o,n.edgeDetection,t);if(S<0)return null;const k=e.nodeDOM(p);return{node:f,pos:p,depth:u,score:S,dom:k}}).filter(u=>u!==null),a=r.nodeAfter;if(a&&a.isAtom&&!a.isInline){const u=i.pos,f=r.depth+1,p=r.parent,g=r.index(),x=p.childCount;let w=!0;if(n.allowedContainers&&(w=Ns(r,f,n.allowedContainers)),w){const y={node:a,pos:u,depth:f,parent:p,index:g,isFirst:g===0,isLast:g===x-1,$pos:r,view:e},S=js(y,o,n.edgeDetection,t);if(S>=0){const k=e.nodeDOM(u);k&&c.push({node:a,pos:u,depth:f,score:S,dom:k})}}}if(c.length===0)return null;c.sort((u,f)=>f.score!==u.score?f.score-u.score:f.depth-u.depth);const h=c[0];return h.dom?{node:h.node,pos:h.pos,dom:h.dom}:null}function gd(e,t){var n;let i=e;for(;i!=null&&i.parentElement&&i.parentElement!==t.dom;)i=i.parentElement;if((i==null?void 0:i.parentElement)===t.dom&&(n=i.pmViewDesc)!=null&&n.node)return i}function md(e){return Number.isFinite(e.top)&&Number.isFinite(e.bottom)&&Number.isFinite(e.left)&&Number.isFinite(e.right)&&e.width>0&&e.height>0}function Bs(e,t){let n=t==="first"?e.firstElementChild:e.lastElementChild;for(;n;){const i=n.getBoundingClientRect();if(md(i))return i;n=t==="first"?n.nextElementSibling:n.previousElementSibling}return null}function xd(e,t,n,i=5){if(!Number.isFinite(t)||!Number.isFinite(n))return null;const s=e.dom,r=Bs(s,"first"),o=Bs(s,"last");if(!r||!o)return null;const l=Math.min(Math.max(r.top+i,n),o.bottom-i),c=.5,a=Math.abs(r.left-o.left)<c,h=Math.abs(r.right-o.right)<c;let u=r;a&&h&&(u=r);const f=Math.min(Math.max(u.left+i,t),u.right-i);return!Number.isFinite(f)||!Number.isFinite(l)?null:{x:f,y:l}}var Co=e=>{const{x:t,y:n,editor:i,nestedOptions:s}=e,{view:r,state:o}=i,l=xd(r,t,n,5);if(!l)return{resultElement:null,resultNode:null,pos:null};const{x:c,y:a}=l;if(s!=null&&s.enabled){const g=pd(r,{x:c,y:a},s);return g?{resultElement:g.dom,resultNode:g.node,pos:g.pos}:{resultElement:null,resultNode:null,pos:null}}const h=r.root.elementsFromPoint(c,a);let u;if(Array.prototype.some.call(h,g=>{if(!r.dom.contains(g))return!1;const x=gd(g,r);return x?(u=x,!0):!1}),!u){const g=r.posAtCoords({left:c,top:a});if(g){const x=o.doc.resolve(g.pos),w=Math.min(x.depth,1),y=w>0?x.before(w):x.pos,S=o.doc.nodeAt(y);if(S){const k=r.nodeDOM(y);return{resultElement:k instanceof HTMLElement?k:null,resultNode:S,pos:y}}}return{resultElement:null,resultNode:null,pos:null}}let f;try{f=r.posAtDOM(u,0)}catch{return{resultElement:null,resultNode:null,pos:null}}const p=o.doc.nodeAt(f);if(!p){const g=o.doc.resolve(f),x=g.parent;return{resultElement:u,resultNode:x,pos:g.start()}}return{resultElement:u,resultNode:p,pos:f}};function ko(e,t){const n=e.nodeDOM(t);if(n instanceof Element&&n!==e.dom)return n;const{node:i,offset:s}=e.domAtPos(t),r=i.childNodes[s];return r instanceof Element?r:i instanceof Element?i:i.nodeType===Node.TEXT_NODE&&i.parentElement?i.parentElement:null}function bd(e,t){const n=ko(e,t);return(n?getComputedStyle(n).direction:getComputedStyle(e.dom).direction)||"ltr"}function Eo(e){var t;(t=e.parentNode)==null||t.removeChild(e)}function wd(e,t){return e==="rtl"?t:0}function yd(e){return e?!e.some(t=>{const n=t.trim().toLowerCase();return n==="margin"||n.startsWith("margin-")}):!0}function vd(e,t,n,i){const{doc:s}=t.view.state;if(n!=null&&n.enabled&&(i!=null&&i.node)&&i.pos>=0){const a=i.pos,h=i.pos+i.node.nodeSize;return[{$from:s.resolve(a),$to:s.resolve(h)}]}const r=Co({editor:t,x:e.clientX,y:e.clientY,nestedOptions:n});if(!r.resultNode||r.pos===null)return[];const o=r.resultNode.isText||r.resultNode.isAtom?0:-1,l=s.resolve(r.pos),c=s.resolve(r.pos+r.resultNode.nodeSize+o);return Ln(l,c,0,{extendOnBoundaryOverlap:!1})}function Sd(e,t,n,i,s){const{view:r}=t;if(!e.dataTransfer)return;const{empty:o,$from:l,$to:c}=r.state.selection,a=vd(e,t,n,i),h=Ln(l,c,0,{extendOnBoundaryOverlap:!1}),u=h.some(lt=>a.find(C=>C.$from===lt.$from&&C.$to===lt.$to)),f=o||!u?a:h;if(!f.length)return;const{tr:p}=r.state,g=document.createElement("div"),x=f[0].$from.pos,w=f[f.length-1].$to.pos,y=bd(r,x);g.setAttribute("dir",y);const S=(n==null?void 0:n.enabled)&&(i==null?void 0:i.node),k=f.length===1;let M,P;S&&k?(M=r.state.doc.slice(x,w),P=K.NodeSelection.create(r.state.doc,x)):(P=Ct.create(r.state.doc,x,w),M=P.content());const A=yd(s);f.forEach(lt=>{const C=ko(r,lt.$from.pos);if(!C)return;const v=rd(C,s);A&&(v.style.margin="0"),g.append(v)}),g.style.position="absolute",g.style.top="-10000px",document.body.append(g),e.dataTransfer.clearData();const E=g.getBoundingClientRect(),D=wd(y,E.width);e.dataTransfer.setDragImage(g,D,0);let Y=!1;const Q=()=>{Y||(Y=!0,Eo(g),document.removeEventListener("drop",Q),document.removeEventListener("dragend",Q))},ut=P instanceof K.NodeSelection?P:void 0;r.dragging={slice:M,move:!0,node:ut},p.setSelection(P),r.dispatch(p),document.addEventListener("drop",Q),document.addEventListener("dragend",Q)}var Ls=(e,t)=>{const n=e.resolve(t),{depth:i}=n;return i===0?t:n.pos-n.parentOffset-1},Ps=(e,t)=>{const n=e.nodeAt(t),i=e.resolve(t);let{depth:s}=i,r=n;for(;s>0;){const o=i.node(s);s-=1,s===0&&(r=o)}return r};function Cd(e,t,n){if(!t.docChanged)return e;if(n.isChangeOrigin&&e.relativeAnchorPos!=null){const s=n.getAbsolutePos(e.relativeAnchorPos);return!Number.isFinite(s)||s<=0?null:{...e,anchorPos:s}}const i=t.mapping.mapResult(e.anchorPos,1);return i.deleted?null:{...e,anchorPos:i.pos}}function Us(e,t,n){let i=0;for(let s=t;s<n;s+=1)i+=e.child(s).nodeSize;return i}function kd(e){var t;return ve(e)?{anchorPos:e.from,nodeCount:e.ranges.length,depth:(t=e.depth)!=null?t:0}:null}function Ed(e,t,n,i){const s=e.resolve(t),r=s.node(i);let o=s.index(i);o>=r.childCount&&(o=Math.max(0,r.childCount-n));const l=Math.min(n,r.childCount-o);if(l<=0)return null;const c=s.start(i)+Us(r,0,o),a=c+Us(r,o,o+l);return{anchor:c,head:a,count:l}}function _d(e,t,n,i){try{const s=Ed(e,t,n,i);if(!s)return null;const r=Ct.create(e,s.anchor,s.head,i);return r.ranges.length===n?r:null}catch{return null}}var Ke=(e,t)=>{const n=B.getState(e);return n?wn(t,n.type,n.binding.mapping):null},$s=(e,t)=>{const n=B.getState(e);return n?Vt(n.doc,n.type,t,n.binding.mapping)||0:-1},Fs=(e,t)=>{let n=t;for(;n!=null&&n.parentNode&&n.parentNode!==e.dom;)n=n.parentNode;return n},_o=new K.PluginKey("dragHandle"),To=({pluginKey:e=_o,element:t,editor:n,computePositionConfig:i,getReferencedVirtualElement:s,onNodeChange:r,onElementDragStart:o,onElementDragEnd:l,nestedOptions:c,dragImageProperties:a})=>{const h=document.createElement("div");let u=!1,f=null,p=-1,g,x=null,w=null,y=null,S=null;function k(){y=null,S=null}function M(C,v){S&&(S=Cd(S,C,{isChangeOrigin:yn(C),getAbsolutePos:N=>$s(v,N)}))}function P(C){if(!S)return null;const v=_d(C.doc,S.anchorPos,S.nodeCount,S.depth);return v?(k(),C.tr.setSelection(v)):(S=null,y=null,null)}function A(){t&&(t.style.visibility="hidden",t.style.pointerEvents="none")}function E(){if(t){if(!n.isEditable){A();return}t.style.visibility="",t.style.pointerEvents="auto"}}function D(C){const v=(s==null?void 0:s())||{getBoundingClientRect:()=>C.getBoundingClientRect()};z.computePosition(v,t,i).then(N=>{Object.assign(t.style,{position:N.strategy,left:`${N.x}px`,top:`${N.y}px`})})}function Y(C){o==null||o(C),Sd(C,n,c,{node:f,pos:p},a),y=kd(n.state.selection),t&&(t.dataset.dragging="true"),setTimeout(()=>{t&&(t.style.pointerEvents="none")},0)}function Q(C){l==null||l(C),y=null,A(),t&&(t.style.pointerEvents="auto",t.dataset.dragging="false")}function ut(C){if(!C.target||!n.view.dom.contains(C.target))return;if(_.isFirefox()){const J=n.view.dom;requestAnimationFrame(()=>{J.isContentEditable&&(J.contentEditable="false",J.contentEditable="true")})}if(!y||n.view.state.selection.empty)return;const v=n.state.selection.from,N=Ke(n.state,v);S={...y,anchorPos:v,relativeAnchorPos:N??void 0},n.view.dispatch(n.state.tr.setMeta("addToHistory",!1))}function lt(){t.removeEventListener("dragstart",Y),t.removeEventListener("dragend",Q),document.removeEventListener("drop",ut),x&&(cancelAnimationFrame(x),x=null,w=null),k()}return h.appendChild(t),{unbind(){lt()},plugin:new K.Plugin({key:typeof e=="string"?new K.PluginKey(e):e,state:{init(){return{locked:!1}},apply(C,v,N,J){M(C,J);const U=C.getMeta("lockDragHandle"),tt=C.getMeta("hideDragHandle");if(U!==void 0&&(u=U),tt)return A(),u=!1,f=null,p=-1,r==null||r({editor:n,node:null,pos:-1}),v;if(C.docChanged&&p!==-1&&t)if(yn(C)){const ct=$s(J,g);ct!==p&&(p=ct)}else{const ct=C.mapping.map(p);ct!==p&&(p=ct,g=Ke(J,p))}return v}},appendTransaction(C,v,N){return P(N)},view:C=>{var v;return t.draggable=!0,t.style.pointerEvents="auto",t.dataset.dragging="false",(v=n.view.dom.parentElement)==null||v.appendChild(h),h.style.pointerEvents="none",h.style.position="absolute",h.style.top="0",h.style.left="0",h.style.zIndex="10",t.addEventListener("dragstart",Y),t.addEventListener("dragend",Q),document.addEventListener("drop",ut),{update(N,J){if(!t)return;if(!n.isEditable){A();return}if(u?t.draggable=!1:t.draggable=!0,C.state.doc.eq(J.doc)||p===-1)return;let U=C.nodeDOM(p);if(U=Fs(C,U),U===C.dom||(U==null?void 0:U.nodeType)!==1)return;const tt=C.posAtDOM(U,0),ct=Ps(n.state.doc,tt),jt=Ls(n.state.doc,tt);f=ct,p=jt,g=Ke(C.state,p),r==null||r({editor:n,node:f,pos:p}),D(U)},destroy(){lt(),t&&Eo(h)}}},props:{handleDOMEvents:{keydown(C){return!t||u||C.hasFocus()&&(A(),f=null,p=-1,r==null||r({editor:n,node:null,pos:-1})),!1},mouseleave(C,v){return u||v.target&&!h.contains(v.relatedTarget)&&(A(),f=null,p=-1,r==null||r({editor:n,node:null,pos:-1})),!1},mousemove(C,v){return!t||u||(w={x:v.clientX,y:v.clientY},x)||(x=requestAnimationFrame(()=>{if(x=null,!w)return;const{x:N,y:J}=w;w=null;const U=Co({x:N,y:J,editor:n,nestedOptions:c});if(!U.resultElement)return;let tt=U.resultElement,ct=U.resultNode,jt=U.pos;if(!(c!=null&&c.enabled)){if(tt=Fs(C,tt),tt===C.dom||(tt==null?void 0:tt.nodeType)!==1)return;const Zt=C.posAtDOM(tt,0);ct=Ps(n.state.doc,Zt),jt=Ls(n.state.doc,Zt)}ct!==f&&(f=ct,p=jt??-1,g=Ke(C.state,p),r==null||r({editor:n,node:f,pos:p}),D(tt),E())})),!1}}}})}};function Ao(e){var t,n;return e===!1||e===void 0?{enabled:!1,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:ei("none")}:e===!0?{enabled:!0,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:ei("left")}:{enabled:!0,rules:(t=e.rules)!=null?t:[],defaultRules:(n=e.defaultRules)!=null?n:!0,allowedContainers:e.allowedContainers,edgeDetection:ei(e.edgeDetection)}}var Ci={placement:"left-start",strategy:"absolute"};_.Extension.create({name:"dragHandle",addOptions(){return{render(){const e=document.createElement("div");return e.classList.add("drag-handle"),e},computePositionConfig:{},locked:!1,onNodeChange:()=>null,onElementDragStart:void 0,onElementDragEnd:void 0,nested:!1,dragImageProperties:void 0}},addCommands(){return{lockDragHandle:()=>({editor:e})=>(this.options.locked=!0,e.commands.setMeta("lockDragHandle",this.options.locked)),unlockDragHandle:()=>({editor:e})=>(this.options.locked=!1,e.commands.setMeta("lockDragHandle",this.options.locked)),toggleDragHandle:()=>({editor:e})=>(this.options.locked=!this.options.locked,e.commands.setMeta("lockDragHandle",this.options.locked))}},addProseMirrorPlugins(){const e=this.options.render(),t=Ao(this.options.nested);return[To({computePositionConfig:{...Ci,...this.options.computePositionConfig},getReferencedVirtualElement:this.options.getReferencedVirtualElement,element:e,editor:this.editor,onNodeChange:this.options.onNodeChange,onElementDragStart:this.options.onElementDragStart,onElementDragEnd:this.options.onElementDragEnd,nestedOptions:t,dragImageProperties:this.options.dragImageProperties}).plugin]}});var Td=e=>{const{className:t="drag-handle",children:n,editor:i,pluginKey:s=_o,onNodeChange:r,onElementDragStart:o,onElementDragEnd:l,getReferencedVirtualElement:c,computePositionConfig:a=Ci,nested:h=!1}=e,u=b.useRef(null);u.current===null&&typeof document<"u"&&(u.current=document.createElement("div"));const f=b.useMemo(()=>Ao(h),[JSON.stringify(h)]);b.useEffect(()=>{const g=u.current;g&&(g.className=t)},[t]),b.useEffect(()=>{if(typeof document>"u"||i.isDestroyed)return;const g=u.current;if(!g)return;g.style.visibility="hidden",g.style.position="absolute",g.dataset.dragging="false";const{plugin:x,unbind:w}=To({editor:i,element:g,pluginKey:s,computePositionConfig:{...Ci,...a},onElementDragStart:o,onElementDragEnd:l,onNodeChange:r,getReferencedVirtualElement:c,nestedOptions:f});return i.registerPlugin(x),()=>{i.isDestroyed||i.unregisterPlugin(s),w()}},[i,r,c,s,a,o,l,f]);const p=u.current;return p?ki.createPortal(n,p):null},Ad=Td;function Id(){var A,E,D,Y,Q,ut,lt,C;const e=m.useEditorInstance(),t=m.useEditableEditor(),{t:n}=L.useLocale(),[i,s]=b.useState(null),[r,o]=b.useState(-1),[l,c]=b.useState(!1),a=(E=(A=e==null?void 0:e.extensionManager)==null?void 0:A.extensions)==null?void 0:E.some(v=>(v==null?void 0:v.name)===Ks.TextAlign.name),h=(Y=(D=e==null?void 0:e.extensionManager)==null?void 0:D.extensions)==null?void 0:Y.some(v=>(v==null?void 0:v.name)===be.Indent.name),u=(ut=(Q=e==null?void 0:e.extensionManager)==null?void 0:Q.extensions)==null?void 0:ut.some(v=>(v==null?void 0:v.name)===$o.Clear.name);function f(){const v=e.chain();v.setNodeSelection(r).unsetAllMarks(),(i==null?void 0:i.type.name)!=="paragraph"&&v.setParagraph(),v.run()}function p(){e.chain().focus().setNodeSelection(r).run(),document.execCommand("copy")}function g(){e.commands.setNodeSelection(r);const{$anchor:v}=e.state.selection,N=v.node(1)||e.state.selection.node;e.chain().setMeta("hideDragHandle",!0).insertContentAt(r+((i==null?void 0:i.nodeSize)||0),N.toJSON()).run()}function x(v){e.commands.setTextAlign(v)}function w(){const v=be.setNodeIndentMarkup(e.state.tr,r,1);v.setMeta("hideDragHandle",!0),e.view.dispatch&&e.view.dispatch(v)}function y(){const v=be.setNodeIndentMarkup(e.state.tr,r,-1);e.view.dispatch&&e.view.dispatch(v)}function S(){e.chain().setMeta("hideDragHandle",!0).setNodeSelection(r).deleteSelection().run()}const k=b.useCallback(v=>{v.node&&s(v.node),o(v.pos),requestAnimationFrame(()=>{v.editor.commands.focus()})},[]),M=v=>{var N;if(v.preventDefault(),r!==-1){const J=(i==null?void 0:i.nodeSize)||0,U=r+J,tt=(i==null?void 0:i.type.name)==="paragraph"&&((N=i==null?void 0:i.content)==null?void 0:N.size)===0,ct=tt?r+2:U+2;e.chain().command(({dispatch:jt,tr:Zt,state:Yi})=>jt?(tt?Zt.insertText("/",r,r+1):Zt.insert(U,Yi.schema.nodes.paragraph.create(null,[Yi.schema.text("/")])),jt(Zt)):!0).focus(ct).run()}};b.useEffect(()=>(l?e.commands.setMeta("lockDragHandle",!0):e.commands.setMeta("lockDragHandle",!1),()=>{e.commands.setMeta("lockDragHandle",!1)}),[l]);const P=v=>{t&&c(v)};return d.jsx(Ad,{className:"richtext-transition-all richtext-duration-200 richtext-ease-out",editor:e,onNodeChange:k,pluginKey:"RichTextBubbleMenuDragHandle",children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-0.5",children:[d.jsx(m.ActionButton,{action:M,disabled:!t,icon:"Plus",tooltip:n("editor.draghandle.insertBlock")}),d.jsx(m.ActionButton,{disabled:!t,icon:"Grip",tooltip:n("editor.draghandle.grip"),action:v=>{v.preventDefault(),v.stopPropagation(),P(!l)}}),d.jsxs($.DropdownMenu,{onOpenChange:P,open:l,children:[d.jsx($.DropdownMenuTrigger,{className:"richtext-pointer-events-none"}),d.jsxs($.DropdownMenuContent,{align:"start",className:"richtext-w-48",hideWhenDetached:!0,side:"bottom",sideOffset:0,children:[d.jsxs($.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:S,children:[d.jsx(m.IconComponent,{name:"Trash2"}),d.jsx("span",{children:n("editor.remove")})]}),u?d.jsxs($.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:f,children:[d.jsx(m.IconComponent,{name:"PaintRoller"}),d.jsx("span",{children:n("editor.clear.tooltip")})]}):null,d.jsxs($.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:p,children:[d.jsx(m.IconComponent,{name:"Clipboard"}),d.jsx("span",{children:n("editor.copyToClipboard")})]}),d.jsxs($.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:g,children:[d.jsx(m.IconComponent,{name:"Copy"}),d.jsx("span",{children:n("editor.copy")})]}),a||h?d.jsx($.DropdownMenuSeparator,{}):null,a?d.jsxs($.DropdownMenuSub,{children:[d.jsxs($.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[d.jsx(m.IconComponent,{name:"AlignCenter"}),d.jsx("span",{children:n("editor.textalign.tooltip")})]}),d.jsx($.DropdownMenuPortal,{children:d.jsxs($.DropdownMenuSubContent,{children:[d.jsxs($.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("left"),children:[d.jsx(m.IconComponent,{name:"AlignLeft"}),d.jsx("span",{children:n("editor.textalign.left.tooltip")})]}),d.jsxs($.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("center"),children:[d.jsx(m.IconComponent,{name:"AlignCenter"}),d.jsx("span",{children:n("editor.textalign.center.tooltip")})]}),d.jsxs($.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("right"),children:[d.jsx(m.IconComponent,{name:"AlignRight"}),d.jsx("span",{children:n("editor.textalign.right.tooltip")})]})]})})]}):null,h?d.jsxs($.DropdownMenuSub,{children:[d.jsxs($.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[d.jsx(m.IconComponent,{name:"IndentIncrease"}),d.jsx("span",{children:n("editor.indent")})]}),d.jsx($.DropdownMenuPortal,{children:d.jsxs($.DropdownMenuSubContent,{children:[d.jsxs($.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((lt=i==null?void 0:i.attrs)==null?void 0:lt.indent)>=be.IndentProps.max,onClick:w,children:[d.jsx(m.IconComponent,{name:"IndentIncrease"}),d.jsx("span",{children:n("editor.indent.tooltip")})]}),d.jsxs($.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((C=i==null?void 0:i.attrs)==null?void 0:C.indent)<=be.IndentProps.min,onClick:y,children:[d.jsx(m.IconComponent,{name:"IndentDecrease"}),d.jsx("span",{children:n("editor.outdent.tooltip")})]})]})})]}):null]})]})]})})}const Vs={plaintext:"Plain Text",js:"JavaScript",ts:"TypeScript",css:"CSS",html:"HTML",python:"Python",bash:"Bash"};function Dd({listLanguages:e}){const{t}=L.useLocale(),[n,i]=b.useState(!1),s=m.useEditorInstance(),r=b.useMemo(()=>{const{selection:l}=s.state,c=l.$from.parent;if(c.type.name==="codeBlock"){const a=c.attrs.language||"plaintext";return Vs[a]||a}},[s.state,e]),o=b.useMemo(()=>{let l=e||[];return e!=null&&e.includes("plaintext")||(l=["plaintext",...l]),l.map(c=>({label:Vs[c]||c,value:c}))},[e]);return d.jsxs(It.Popover,{modal:!0,onOpenChange:i,open:n,children:[d.jsx(It.PopoverTrigger,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:d.jsxs(m.ActionButton,{dataState:!!r,children:[r?d.jsx(d.Fragment,{children:r}):d.jsx(d.Fragment,{children:t("editor.paragraph.tooltip")}),d.jsx(m.IconComponent,{className:"richtext-ml-1 richtext-size-3 richtext-text-zinc-500",name:"MenuDown"})]})}),d.jsx(It.PopoverContent,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:o==null?void 0:o.map(l=>d.jsxs("div",{className:"richtext-flex richtext-w-full richtext-items-center richtext-gap-3 richtext-rounded-sm !richtext-border-none !richtext-bg-transparent richtext-px-2 richtext-py-1.5 richtext-text-left richtext-text-sm richtext-text-foreground !richtext-outline-none richtext-transition-colors hover:!richtext-bg-accent",onClick:c=>{c.preventDefault(),s.chain().focus().setCodeBlock({language:l.value}).run(),i(!1)},children:[d.jsx("div",{className:"!richtext-min-w-[20px]",children:r===l.value&&d.jsx(zt.Check,{size:16})}),d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:l.label})]},l.value))})]})}function Md(){const e=m.useEditableEditor(),t=m.useEditorInstance(),n=m.useExtension(Un.CodeBlock.name),i=b.useCallback(({editor:c})=>c.isActive(Un.CodeBlock.name),[]),s=b.useMemo(()=>{var c,a,h;return n?((h=(a=(c=n.options)==null?void 0:c.lowlight)==null?void 0:a.listLanguages)==null?void 0:h.call(a))||["plaintext","html","css","js","ts"]:[]},[n]),r=b.useCallback(()=>Yt(Un.CodeBlock.name,t),[t]),o=()=>{const{from:c}=t.state.selection,a=t.state.doc.resolve(c);for(let h=a.depth;h>=0;h--){const u=a.node(h);if(u.type.name==="codeBlock")return u.textContent}return""},l=()=>{const c=o();navigator.clipboard.writeText(c)};return e?d.jsx(st,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleCodeBlock",shouldShow:i,getReferencedVirtualElement:()=>{const{from:c}=t.state.selection,h=t.view.domAtPos(c).node.parentElement;return h?{getBoundingClientRect:()=>h.getBoundingClientRect()}:null},children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(Dd,{listLanguages:s}),d.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(m.ActionButton,{action:l,tooltip:"Copy",children:d.jsx(zt.Copy,{size:16})}),d.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(m.ActionButton,{action:r,tooltip:"Delete",children:d.jsx(zt.Trash2,{size:16})})]})}):d.jsx(d.Fragment,{})}exports.RichTextBubbleCallout=xl;exports.RichTextBubbleCodeBlock=Md;exports.RichTextBubbleColumns=bl;exports.RichTextBubbleDrawer=Nl;exports.RichTextBubbleExcalidraw=Ll;exports.RichTextBubbleIframe=Pl;exports.RichTextBubbleImage=ql;exports.RichTextBubbleImageGif=Wl;exports.RichTextBubbleKatex=$l;exports.RichTextBubbleLink=Vl;exports.RichTextBubbleMenuDragHandle=Id;exports.RichTextBubbleMermaid=Zl;exports.RichTextBubbleTable=Ql;exports.RichTextBubbleText=nc;exports.RichTextBubbleTwitter=ic;exports.RichTextBubbleVideo=Gl;