reactjs-tiptap-editor 1.0.20 → 1.0.22

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 (138) hide show
  1. package/lib/{ActionMenuButton-CMXWxvWu.js → ActionMenuButton-B1067mIC.js} +1 -1
  2. package/lib/{ActionMenuButton-BPgqKDXT.cjs → ActionMenuButton-BBDqKvKg.cjs} +1 -1
  3. package/lib/Attachment.cjs +1 -1
  4. package/lib/Attachment.js +24 -24
  5. package/lib/Blockquote.cjs +1 -1
  6. package/lib/Blockquote.js +1 -1
  7. package/lib/Bold.cjs +1 -1
  8. package/lib/Bold.js +1 -1
  9. package/lib/BulletList.cjs +1 -1
  10. package/lib/BulletList.js +1 -1
  11. package/lib/Callout-V2mO6s2Y.js +340 -0
  12. package/lib/Callout-lBlBlK_w.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 +1 -1
  17. package/lib/Code.cjs +1 -1
  18. package/lib/Code.js +1 -1
  19. package/lib/CodeBlock.cjs +1 -1
  20. package/lib/CodeBlock.js +1 -1
  21. package/lib/CodeView.cjs +1 -1
  22. package/lib/CodeView.js +1 -1
  23. package/lib/Color.cjs +1 -1
  24. package/lib/Color.js +2 -2
  25. package/lib/Column.cjs +1 -1
  26. package/lib/Column.js +1 -1
  27. package/lib/{Drawer-BivLAzMN.cjs → Drawer-BeYo9jAG.cjs} +1 -1
  28. package/lib/{Drawer-BmVmgJsc.js → Drawer-Cyv27orn.js} +19 -19
  29. package/lib/Drawer.cjs +1 -1
  30. package/lib/Drawer.js +2 -2
  31. package/lib/Emoji.cjs +1 -1
  32. package/lib/Emoji.js +9 -9
  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 +1 -1
  37. package/lib/ExportWord.cjs +1 -1
  38. package/lib/ExportWord.js +1 -1
  39. package/lib/FontFamily.cjs +1 -1
  40. package/lib/FontFamily.js +4 -4
  41. package/lib/FontSize.cjs +1 -1
  42. package/lib/FontSize.js +4 -4
  43. package/lib/Heading.cjs +1 -1
  44. package/lib/Heading.js +9 -9
  45. package/lib/Highlight.cjs +1 -1
  46. package/lib/Highlight.js +2 -2
  47. package/lib/History.cjs +1 -1
  48. package/lib/History.js +1 -1
  49. package/lib/HorizontalRule.cjs +1 -1
  50. package/lib/HorizontalRule.js +1 -1
  51. package/lib/{Iframe-hwg9FxhU.cjs → Iframe-Bx-VDxSB.cjs} +1 -1
  52. package/lib/{Iframe-CAUrccA0.js → Iframe-D9JVKzO0.js} +5 -5
  53. package/lib/Iframe.cjs +1 -1
  54. package/lib/Iframe.js +1 -1
  55. package/lib/Image.cjs +1 -1
  56. package/lib/Image.js +4 -4
  57. package/lib/ImageGif.cjs +1 -1
  58. package/lib/ImageGif.js +36 -36
  59. package/lib/ImportWord.cjs +1 -1
  60. package/lib/ImportWord.js +13 -13
  61. package/lib/{Indent-3MoIatX1.js → Indent-B5tQ5Wfg.js} +1 -1
  62. package/lib/{Indent-MuSU0kXz.cjs → Indent-CCLO0KpG.cjs} +1 -1
  63. package/lib/Indent.cjs +1 -1
  64. package/lib/Indent.js +1 -1
  65. package/lib/Italic.cjs +1 -1
  66. package/lib/Italic.js +1 -1
  67. package/lib/Katex-rtfVV2pl.cjs +4 -0
  68. package/lib/{Katex-xS-XZKQc.js → Katex-w_c6vAMd.js} +5 -4
  69. package/lib/Katex.cjs +1 -1
  70. package/lib/Katex.js +1 -1
  71. package/lib/LineHeight.cjs +1 -1
  72. package/lib/LineHeight.js +3 -3
  73. package/lib/Link.cjs +1 -1
  74. package/lib/Link.js +1 -1
  75. package/lib/{LinkEditBlock-Dhvz7DCA.js → LinkEditBlock-CTlU8YnO.js} +25 -25
  76. package/lib/{LinkEditBlock-DLDY-8Ax.cjs → LinkEditBlock-_41zgSyl.cjs} +1 -1
  77. package/lib/Mermaid.cjs +2 -2
  78. package/lib/Mermaid.js +44 -43
  79. package/lib/MoreMark.cjs +1 -1
  80. package/lib/MoreMark.js +4 -4
  81. package/lib/OrderedList.cjs +1 -1
  82. package/lib/OrderedList.js +1 -1
  83. package/lib/SearchAndReplace.cjs +1 -1
  84. package/lib/SearchAndReplace.js +7 -7
  85. package/lib/SlashCommand.cjs +1 -1
  86. package/lib/SlashCommand.js +3 -3
  87. package/lib/{SlashCommandNodeView-CavaOSwo.cjs → SlashCommandNodeView-CVKjpS6r.cjs} +1 -1
  88. package/lib/{SlashCommandNodeView-RnDRm4Z1.js → SlashCommandNodeView-DNkpJuM3.js} +6 -6
  89. package/lib/Strike.cjs +1 -1
  90. package/lib/Strike.js +1 -1
  91. package/lib/{Table-m32ZhtxF.cjs → Table-BFiU40iW.cjs} +1 -1
  92. package/lib/{Table-DN4TuDz1.js → Table-yZtD5Qo1.js} +3 -3
  93. package/lib/Table.cjs +1 -1
  94. package/lib/Table.js +1 -1
  95. package/lib/TaskList.cjs +1 -1
  96. package/lib/TaskList.js +1 -1
  97. package/lib/TextAlign.cjs +1 -1
  98. package/lib/TextAlign.js +2 -2
  99. package/lib/TextDirection.cjs +1 -1
  100. package/lib/TextDirection.js +2 -2
  101. package/lib/TextUnderline.cjs +1 -1
  102. package/lib/TextUnderline.js +1 -1
  103. package/lib/{Twitter-CJhQLKYS.cjs → Twitter-BJjt8vv_.cjs} +1 -1
  104. package/lib/{Twitter-B2FDarxE.js → Twitter-CKm0M53B.js} +7 -7
  105. package/lib/Twitter.cjs +1 -1
  106. package/lib/Twitter.js +1 -1
  107. package/lib/Video.cjs +1 -1
  108. package/lib/Video.js +4 -4
  109. package/lib/bubble.cjs +6 -6
  110. package/lib/bubble.js +678 -643
  111. package/lib/{dropdown-menu-CWd8VVRO.js → dropdown-menu-AhMKS9PQ.js} +1 -1
  112. package/lib/{dropdown-menu-C0VlKIZC.cjs → dropdown-menu-Dre693DD.cjs} +1 -1
  113. package/lib/index-83hp1lZH.cjs +1 -0
  114. package/lib/{index-B2a7NqnN.js → index-BfHAqkoX.js} +1020 -1149
  115. package/lib/index-C4aGVY2E.cjs +1 -0
  116. package/lib/{index-BlXGgvT-.js → index-DtVRewGA.js} +26 -14
  117. package/lib/index.cjs +1 -1
  118. package/lib/index.js +12 -12
  119. package/lib/locale-bundle.cjs +1 -1
  120. package/lib/locale-bundle.js +1 -1
  121. package/lib/locales/en.d.ts +2 -0
  122. package/lib/locales/fi.d.ts +2 -0
  123. package/lib/locales/hu.d.ts +2 -0
  124. package/lib/locales/index.d.ts +12 -0
  125. package/lib/locales/pt-br.d.ts +2 -0
  126. package/lib/locales/vi.d.ts +2 -0
  127. package/lib/locales/zh-cn.d.ts +2 -0
  128. package/lib/{popover-BrSDMb_n.js → popover-B1ptDngu.js} +1 -1
  129. package/lib/{popover-UUKfPWue.cjs → popover-D7w_FVSV.cjs} +1 -1
  130. package/lib/{separator-fpWkZkoh.js → separator-CDoF4Z4Z.js} +14 -14
  131. package/lib/{separator-LH5EzF0T.cjs → separator-C_7KkuoG.cjs} +1 -1
  132. package/lib/style.css +1 -1
  133. package/lib/textarea-CEtXap1b.cjs +1 -0
  134. package/lib/textarea-CNzZnjjW.js +20 -0
  135. package/package.json +1 -1
  136. package/lib/Katex-BPQ7_A3w.cjs +0 -4
  137. package/lib/index-BqL4vAWE.cjs +0 -1
  138. package/lib/index-czmcFIW7.cjs +0 -1
package/lib/bubble.cjs CHANGED
@@ -1,6 +1,6 @@
1
- "use strict";var yo=Object.create;var jn=Object.defineProperty;var vo=Object.getOwnPropertyDescriptor;var So=Object.getOwnPropertyNames;var Co=Object.getPrototypeOf,ko=Object.prototype.hasOwnProperty;var Eo=(e,t,n)=>t in e?jn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var _o=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of So(t))!ko.call(e,s)&&s!==n&&jn(e,s,{get:()=>t[s],enumerable:!(i=vo(t,s))||i.enumerable});return e};var To=(e,t,n)=>(n=e!=null?yo(Co(e)):{},_o(t||!e||!e.__esModule?jn(n,"default",{value:e,enumerable:!0}):n,e));var Re=(e,t,n)=>Eo(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),T=require("./index-C4WLt4NA.cjs"),H=require("./index-TcJ2UKnv.cjs"),W=require("@tiptap/pm/state"),Ns=require("./Table-m32ZhtxF.cjs"),Bs=require("./clsx-DSAWW32g.cjs"),b=require("react"),Ls=require("react-dom"),m=require("./index-czmcFIW7.cjs"),Ne=require("./Callout.cjs"),ut=require("./Katex-BPQ7_A3w.cjs"),B=require("./index-BqL4vAWE.cjs"),Zt=require("lucide-react"),St=require("./popover-UUKfPWue.cjs"),Ct=require("./separator-LH5EzF0T.cjs"),Rn=require("./CodeBlock.cjs"),qi=require("./Column.cjs");require("./theme.cjs");const Fe=require("./Drawer-BivLAzMN.cjs"),Wi=require("easydrawer"),Je=require("./shortId-Bfj8TyNr.cjs"),he=require("./Excalidraw.cjs"),Kt=require("./Iframe-hwg9FxhU.cjs"),Ao=require("./ImageGif.cjs"),Io=require("katex"),Ve=require("./LinkEditBlock-DLDY-8Ax.cjs"),Nn=require("@tiptap/pm/view"),Do=require("@tiptap/pm/model"),U=require("./dropdown-menu-C0VlKIZC.cjs"),Mo=require("./Clear.cjs"),ue=require("./Indent-MuSU0kXz.cjs"),Us=require("./TextAlign.cjs"),Zn=require("./Mermaid.cjs"),Oo=require("./Bold.cjs"),jo=require("./Code.cjs");require("./index-DlxZt4_j.cjs");const Ro=require("./Color.cjs"),No=require("./Highlight.cjs"),Bo=require("./Italic.cjs"),Lo=require("./SlashCommandNodeView-CavaOSwo.cjs"),Uo=require("./Strike.cjs"),Po=require("./TextUnderline.cjs"),Bn=require("./Twitter-CJhQLKYS.cjs");function $o(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 Fo=class{constructor({editor:e,element:t,view:n,pluginKey:i="bubbleMenu",updateDelay:s=250,resizeDelay:r=60,shouldShow:o,appendTo:l,getReferencedVirtualElement:c,options:a}){this.preventHide=!1,this.isVisible=!1,this.scrollTarget=window,this.floatingUIOptions={strategy:"absolute",placement:"top",offset:8,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1,onShow:void 0,onHide:void 0,onUpdate:void 0,onDestroy:void 0},this.shouldShow=({view:h,state:f,from:p,to:g})=>{const{doc:x,selection:w}=f,{empty:y}=w,C=!x.textBetween(p,g).length&&T.isTextSelection(f.selection),k=this.element.contains(document.activeElement);return!(!(h.hasFocus()||k)||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.updatePosition(),this.show()},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)};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(H.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(H.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(H.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(H.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(H.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(H.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(H.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(H.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}get virtualElement(){var e,t,n;const{selection:i}=this.editor.state,s=(e=this.getReferencedVirtualElement)==null?void 0:e.call(this);if(s)return s;if(!((n=(t=this.view)==null?void 0:t.dom)!=null&&n.parentNode))return;const r=T.posToDOMRect(this.view,i.from,i.to);let o={getBoundingClientRect:()=>r,getClientRects:()=>[r]};if(i instanceof W.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 Ns.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():$o(h.getBoundingClientRect(),f.getBoundingClientRect());o={getBoundingClientRect:()=>p,getClientRects:()=>[p]}}return o}updatePosition(){const e=this.virtualElement;e&&H.computePosition(e,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:t,y:n,strategy:i,middlewareData:s})=>{var r,o;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()}},Ps=e=>new W.Plugin({key:typeof e.pluginKey=="string"?new W.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Fo({view:t,...e})});T.Extension.create({name:"bubbleMenu",addOptions(){return{element:null,pluginKey:"bubbleMenu",updateDelay:void 0,appendTo:void 0,shouldShow:null}},addProseMirrorPlugins(){return this.options.element?[Ps({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,updateDelay:this.options.updateDelay,options:this.options.options,appendTo:this.options.appendTo,getReferencedVirtualElement:this.options.getReferencedVirtualElement,shouldShow:this.options.shouldShow})]:[]}});var Vo=class{constructor({editor:e,element:t,view:n,pluginKey:i="floatingMenu",updateDelay:s=250,resizeDelay:r=60,options:o,appendTo:l,shouldShow:c}){this.preventHide=!1,this.isVisible=!1,this.scrollTarget=window,this.shouldShow=({view:u,state:h})=>{const{selection:f}=h,{$anchor:p,empty:g}=f,x=p.depth===1,w=p.parent.isTextblock&&!p.parent.type.spec.code&&!p.parent.textContent&&p.parent.childCount===0&&!this.getTextContent(p.parent);return!(!u.hasFocus()||!g||!x||!w||!this.editor.isEditable)},this.floatingUIOptions={strategy:"absolute",placement:"right",offset:8,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1},this.updateHandler=(u,h,f,p)=>{const{composing:g}=u;if(g||!h&&!f)return;if(!this.getShouldShow(p)){this.hide();return}this.updatePosition(),this.show()},this.mousedownHandler=()=>{this.preventHide=!0},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:u})=>{var h;if(this.preventHide){this.preventHide=!1;return}u!=null&&u.relatedTarget&&((h=this.element.parentNode)!=null&&h.contains(u.relatedTarget))||(u==null?void 0:u.relatedTarget)!==this.editor.view.dom&&this.hide()},this.transactionHandler=({transaction:u})=>{const h=u.getMeta(this.pluginKey);h==="updatePosition"?this.updatePosition():h&&typeof h=="object"&&h.type==="updateOptions"&&this.updateOptions(h.options)},this.resizeHandler=()=>{this.resizeDebounceTimer&&clearTimeout(this.resizeDebounceTimer),this.resizeDebounceTimer=window.setTimeout(()=>{this.updatePosition()},this.resizeDelay)};var a;this.editor=e,this.element=t,this.view=n,this.pluginKey=i,this.updateDelay=s,this.resizeDelay=r,this.appendTo=l,this.scrollTarget=(a=o==null?void 0:o.scrollTarget)!=null?a:window,this.floatingUIOptions={...this.floatingUIOptions,...o},this.element.tabIndex=0,c&&(this.shouldShow=c),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.editor.on("transaction",this.transactionHandler),window.addEventListener("resize",this.resizeHandler),this.scrollTarget.addEventListener("scroll",this.resizeHandler),this.update(n,n.state),this.getShouldShow()&&(this.show(),this.updatePosition())}getTextContent(e){return T.getText(e,{textSerializers:T.getTextSerializersFromSchema(this.editor.schema)})}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(H.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(H.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(H.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(H.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(H.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(H.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(H.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(H.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}getShouldShow(e){var t;const{state:n}=this.view,{selection:i}=n,{ranges:s}=i,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(){const{selection:e}=this.editor.state,t=T.posToDOMRect(this.view,e.from,e.to),n={getBoundingClientRect:()=>t,getClientRects:()=>[t]};H.computePosition(n,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:i,y:s,strategy:r,middlewareData:o})=>{var l,c;if((l=o.hide)!=null&&l.referenceHidden||(c=o.hide)!=null&&c.escaped){this.element.style.visibility="hidden";return}this.element.style.visibility="visible",this.element.style.width="max-content",this.element.style.position=r,this.element.style.left=`${i}px`,this.element.style.top=`${s}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()})}update(e,t){const n=!(t!=null&&t.selection.eq(e.state.selection)),i=!(t!=null&&t.doc.eq(e.state.doc));this.updateHandler(e,n,i,t)}show(){var e;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const t=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(e=t??this.view.dom.parentElement)==null||e.appendChild(this.element),this.floatingUIOptions.onShow&&this.floatingUIOptions.onShow(),this.isVisible=!0}hide(){this.isVisible&&(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.remove(),this.floatingUIOptions.onHide&&this.floatingUIOptions.onHide(),this.isVisible=!1)}destroy(){this.hide(),this.element.removeEventListener("mousedown",this.mousedownHandler,{capture:!0}),window.removeEventListener("resize",this.resizeHandler),this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.editor.off("transaction",this.transactionHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},$s=e=>new W.Plugin({key:typeof e.pluginKey=="string"?new W.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Vo({view:t,...e})});T.Extension.create({name:"floatingMenu",addOptions(){return{element:null,options:{},pluginKey:"floatingMenu",updateDelay:void 0,resizeDelay:void 0,appendTo:void 0,shouldShow:null}},addCommands(){return{updateFloatingMenuPosition:()=>({tr:e,dispatch:t})=>(t&&e.setMeta(this.options.pluginKey,"updatePosition"),!0)}},addProseMirrorPlugins(){return this.options.element?[$s({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 Fs(e,t){return e??new W.PluginKey(t)}var Ho=typeof window<"u"?b.useLayoutEffect:b.useEffect,Vs=new Set(["left","opacity","position","top","visibility","width"]),zo=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"]),Ko=new Set(["children","className","style"]),qo=new Set(["tabIndex"]),Wo=new Set(["accessKey","autoCapitalize","contentEditable","contextMenu","dir","draggable","enterKeyHint","hidden","id","lang","nonce","role","slot","spellCheck","tabIndex","title","translate"]),Go={Blur:"focusout",DoubleClick:"dblclick",Focus:"focusin",MouseEnter:"mouseenter",MouseLeave:"mouseleave"};function Qn(e,t){return/^on[A-Z]/.test(e)&&typeof t=="function"}function Yo(e){return e.startsWith("aria-")||e.startsWith("data-"),e}function Jo(e){return e.startsWith("aria-")||e.startsWith("data-")||Wo.has(e)}function Hs(e){return e.startsWith("--")?e:e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}function Xo(e){var t;const n=e.endsWith("Capture"),s=(n?e.slice(0,-7):e).slice(2);return{eventName:(t=Go[s])!=null?t:s.toLowerCase(),options:n?{capture:!0}:void 0}}function Zo(e,t){let n=t.defaultPrevented,i=!1;const s=Object.create(t);return Object.defineProperties(s,{nativeEvent:{value:t},currentTarget:{value:e},target:{value:t.target},persist:{value:()=>{}},isDefaultPrevented:{value:()=>n},isPropagationStopped:{value:()=>i},preventDefault:{value:()=>{n=!0,t.preventDefault()}},stopPropagation:{value:()=>{i=!0,t.stopPropagation()}}}),s}function Ln(e){return qo.has(e)}function Gi(e,t,n){if(t==="tabIndex"){e.tabIndex=Number(n);return}e[t]=n}function Qo(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 tl(e,t){return typeof t!="number"||t===0||e.startsWith("--")||zo.has(e)?String(t):`${t}px`}function el(e,t){Vs.has(t)||e.style.removeProperty(Hs(t))}function nl(e,t,n){Vs.has(t)||e.style.setProperty(Hs(t),tl(t,n))}function il(e,t,n){new Set([...Object.keys(t),...Object.keys(n)]).forEach(s=>{if(Ko.has(s)||!Jo(s)||Qn(s,t[s])||Qn(s,n[s]))return;const r=t[s],o=n[s];if(r===o)return;const l=Yo(s);if(o==null||o===!1){Ln(s)&&Qo(e,s),e.removeAttribute(l);return}if(o===!0){Ln(s)&&Gi(e,s,!0),e.setAttribute(l,"");return}if(Ln(s)){Gi(e,s,o);return}e.setAttribute(l,String(o))})}function sl(e,t,n){if(t!==n){if(n){e.className=n;return}e.removeAttribute("class")}}function rl(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){el(e,o);return}nl(e,o,c)}})}function ol(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(!Qn(s,r))return;const{eventName:o,options:l}=Xo(s),c=a=>{r(Zo(e,a))};e.addEventListener(o,c,l),i.push({eventName:o,listener:c,options:l})}),i}function zs(e,t){const n=b.useRef({}),i=b.useRef([]);Ho(()=>{const s=n.current;return sl(e,s.className,t.className),rl(e,s.style,t.style),il(e,s,t),i.current=ol(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 et=b.forwardRef(({pluginKey:e,editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:r=null,getReferencedVirtualElement:o,options:l,children:c,...a},u)=>{const h=b.useRef(document.createElement("div")),f=b.useRef(Fs(e,"bubbleMenu")).current;zs(h.current,a),typeof u=="function"?u(h.current):u&&(u.current=h.current);const{editor:p}=Bs.useCurrentEditor(),g=t||p,x={updateDelay:n,resizeDelay:i,appendTo:s,pluginKey:f,shouldShow:r,getReferencedVirtualElement:o,options:l},w=b.useRef(x);w.current=x;const[y,C]=b.useState(!1),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 D=h.current;D.style.visibility="hidden",D.style.position="absolute";const L=Ps({...w.current,editor:g,element:D});g.registerPlugin(L);const v=w.current.pluginKey;return k.current=!0,C(!0),()=>{C(!1),g.unregisterPlugin(v),window.requestAnimationFrame(()=>{D.parentNode&&D.parentNode.removeChild(D)})}},[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]),Ls.createPortal(c,h.current)});b.forwardRef(({pluginKey:e,editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:r=null,options:o,children:l,...c},a)=>{const u=b.useRef(document.createElement("div")),h=b.useRef(Fs(e,"floatingMenu")).current;zs(u.current,c),typeof a=="function"?a(u.current):a&&(a.current=u.current);const{editor:f}=Bs.useCurrentEditor(),p=t||f,g={updateDelay:n,resizeDelay:i,appendTo:s,pluginKey:h,shouldShow:r,options:o},x=b.useRef(g);x.current=g;const[w,y]=b.useState(!1),C=b.useRef(!0);return b.useEffect(()=>{if(p!=null&&p.isDestroyed)return;if(!p){console.warn("FloatingMenu component is not rendered inside of an editor component or does not have editor prop.");return}const k=u.current;k.style.visibility="hidden",k.style.position="absolute";const D=$s({...x.current,editor:p,element:k});p.registerPlugin(D);const L=x.current.pluginKey;return C.current=!0,y(!0),()=>{y(!1),p.unregisterPlugin(L),window.requestAnimationFrame(()=>{k.parentNode&&k.parentNode.removeChild(k)})}},[p]),b.useEffect(()=>{if(!(!w||!p||p.isDestroyed)){if(C.current){C.current=!1;return}p.view.dispatch(p.state.tr.setMeta(h,{type:"updateOptions",options:x.current}))}},[w,p,n,i,r,o,s,h]),Ls.createPortal(l,u.current)});function Ft(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 ll=[{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 cl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=B.useLocale(),{type:i,title:s,body:r}=ut.useAttributes(t,Ne.Callout.name,{type:"note",title:"",body:""}),[o,l]=b.useState(!1),[c,a]=b.useState("note"),[u,h]=b.useState(""),[f,p]=b.useState("");b.useEffect(()=>{o&&(a(i||"note"),h(s||""),p(r||""))},[o,i,s,r]);const g=b.useCallback(()=>{t&&(t.chain().updateAttributes(Ne.Callout.name,{type:c,title:u,body:f}).focus().run(),l(!1))},[t,c,u,f]),x=b.useCallback(()=>{l(!1)},[]),w=b.useCallback(()=>{Ft(Ne.Callout.name,t)},[t]),y=b.useCallback(()=>t.isActive(Ne.Callout.name),[t]);return e?d.jsx(et,{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:ll.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:w,icon:"Trash2",tooltip:n("editor.delete")})]})}):d.jsx(d.Fragment,{})}function al(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=B.useLocale(),i=b.useCallback(()=>t.isActive(qi.MultipleColumnNode.name),[t]),s=b.useCallback(()=>Ft(qi.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(et,{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 hl(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,r)=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[r],action:()=>e.commands.updateImage({width:B.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:B.IMAGE_SIZE[s]})}}))}function ul(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,r)=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[r],action:()=>e.commands.updateImageGif({width:B.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:B.IMAGE_SIZE[s]})}}))}function dl(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 fl(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 pl(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImageMermaid)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function gl(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImageDrawer)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function ml(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 xl(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,r)=>({type:`video-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[r],action:()=>e.commands.updateVideo({width:B.VIDEO_SIZE[s]}),isActive:()=>e.isActive("video",{width:B.VIDEO_SIZE[s]})}}))}function bl(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()}}},...hl(e,t),...dl(e,t),{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;T.deleteSelection(n,i)}}}]}function wl(e,t){return[...ul(e,t),...fl(e,t),{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;T.deleteSelection(n,i)}}}]}function yl(e,t){return[...pl(e,t),{type:"edit",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;T.deleteSelection(n,i)}}}]}function vl(e,t){return[...gl(e,t),{type:"edit",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;T.deleteSelection(n,i)}}}]}function Sl(e,t){return[...xl(e,t),...ml(e),{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;T.deleteSelection(n,i)}}}]}let de=!1;function Cl({editor:e,attrs:t,extension:n}){const[i,s]=b.useState(!1),r=b.useRef(null),o=b.useRef(null),{alt:l,align:c}=t,a=n==null?void 0:n.options.upload,u=()=>{(async()=>{const S=document.querySelector("#easydrawer");S&&(r.current=new Wi.Editor(S,{wheelEventsEnabled:!1,disableZoom:!0}),o.current=Wi.makeDropdownToolbar(r.current),o.current.addDefaultToolWidgets(),r.current.loadFromSVG(decodeURIComponent(l)))})()};b.useEffect(()=>{i&&setTimeout(()=>{u()},200)},[i]);const h=async()=>{if(r.current){const v=r.current.toSVG(),S=v.outerHTML,A=`drawer-${Je.shortId()}.svg`;let z=Je.i(v.outerHTML);if(a){const N=m.dataURLtoFile(z,A);z=await a(N)}e==null||e.chain().focus().setDrawer({type:"drawer",src:z,alt:encodeURIComponent(S),width:426,height:212},!!S).run(),e==null||e.commands.setAlignImageDrawer(c)}s(!1)},f=v=>{const S=r.current.toolController.getPrimaryTools()[2],A=o.current.getWidgetById("pen-1");S&&A&&(S.setColor(v),A.serializeState())},p=v=>{const S=r.current.toolController.getPrimaryTools()[2],A=o.current.getWidgetById("pen-1");S&&A&&(S.setThickness(v),A.serializeState())},g=v=>{const S=r.current.toolController.getPrimaryTools()[3],A=o.current.getWidgetById("pen-2");S&&A&&(S.setColor(v),A.serializeState())},x=v=>{const S=o.current.getWidgetById("shape");S&&S.setShapeType(v)},w=v=>{const S=r.current.toolController.getPrimaryTools()[5],A=o.current.getWidgetById("shape");S&&A&&(S.setColor(v),A.serializeState())},y=v=>{const S=r.current.toolController.getPrimaryTools()[5],A=o.current.getWidgetById("shape");S&&A&&(S.setThickness(v),A.serializeState())},C=v=>{const S=r.current.toolController.getPrimaryTools()[5],A=o.current.getWidgetById("shape");S&&A&&(S.setBorderColor(v),A.serializeState())},k=()=>{if(de){for(;r.current.history.redoStackSize>0;)r.current.history.redo();de=!1;return}r.current.history.undo()},D=()=>{de||r.current.history.redo()},L=()=>{if(!de){for(;r.current.history.undoStackSize>0;)k();de=!0}};return d.jsxs(m.Dialog,{onOpenChange:s,open:i,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{action:()=>s(!0),icon:"Pencil",tooltip:"Edit Drawer"})}),d.jsxs(m.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[d.jsx(m.DialogTitle,{children:"Edit Drawer"}),d.jsxs("div",{style:{height:"100%",borderWidth:1,background:"white",position:"relative"},children:[d.jsx("div",{className:"richtext-size-full",id:"easydrawer"}),d.jsx(Fe.ControlDrawer,{changeBorderColorShape:C,changeColorShape:w,changeShape:x,onClear:L,onRedo:D,onThicknessChange:y,onUndo:k,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 kl({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?d.jsx(b.Fragment,{children:e.type==="divider"?d.jsx(Ct.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 El(){const{lang:e,t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=ut.useAttributes(i,Fe.Drawer.name),r=m.useExtension(Fe.Drawer.name),o=({editor:c})=>{const{selection:a}=c.view.state,{$from:u,to:h}=a;let f=!1;return c.view.state.doc.nodesBetween(u.pos,h,p=>{if(p.type.name===Fe.Drawer.name)return f=!0,!1}),f},l=b.useMemo(()=>vl(i,t),[i,e,t]);return n?d.jsx(et,{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(Cl,{attrs:s,editor:i,extension:r},`bubbleMenu-drawer-${a}`):d.jsx(kl,{editor:i,item:c},`bubbleMenu-drawer-${a}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}const Ks=({width:e,maxWidth:t,height:n,onOk:i,children:s})=>{const{t:r}=B.useLocale(),[o,l]=b.useState({width:"",height:"",maxWidth:""});b.useEffect(()=>{l({width:e,height:n,maxWidth:t})},[n,t,e]);function c(a){a.preventDefault(),a.stopPropagation(),i(o)}return d.jsxs(St.Popover,{modal:!0,children:[d.jsx(St.PopoverTrigger,{asChild:!0,children:s}),d.jsx(St.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")})]})})]})},Rt=new Map;function _l(e){const t=e.options.element;Rt.has("width")||Rt.set("width",t.clientWidth),Rt.has("width")&&Rt.get("width")<=0&&Rt.set("width",t.clientWidth);const n={attributes:!0,childList:!0,subtree:!0},i=function(){Rt.set("width",t.clientWidth)},s=new MutationObserver(i);return s.observe(t,n),e.on("destroy",()=>{s.disconnect()}),{width:Rt.get("width")}}function Tl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=B.useLocale(),{width:i}=_l(t),s=ut.useAttributes(t,he.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(he.Excalidraw.name,p).setNodeSelection(t.state.selection.from).focus().run()},[t]),u=b.useCallback(()=>{const p=m.EVENTS.EXCALIDRAW(t.id);m.emit(p,s)},[t,s]),h=b.useCallback(()=>t.isActive(he.Excalidraw.name),[t]),f=b.useCallback(()=>Ft(he.Excalidraw.name,t),[t]);return b.useEffect(()=>{r&&(u(),t.chain().updateAttributes(he.Excalidraw.name,{defaultShowPicker:!1}).focus().run())},[o,r,t,u]),e?d.jsx(et,{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(Ks,{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 Al(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=B.useLocale(),{width:i,height:s,src:r}=ut.useAttributes(t,Kt.Iframe.name,{width:0,height:0,src:"",defaultShowPicker:!1}),[o,l]=b.useState(!1),[c,a]=b.useState(""),u=b.useCallback(w=>{var y;(y=w==null?void 0:w.preventDefault)==null||y.call(w),l(!1)},[l]);b.useEffect(()=>{o&&a(r)},[o,r]);const h=b.useCallback(w=>{var C;(C=w==null?void 0:w.preventDefault)==null||C.call(w);const y=Kt.getServiceSrc(c);t.chain().updateAttributes(Kt.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(Kt.Iframe.name,w).setNodeSelection(t.state.selection.from).focus().run()},[t]),g=b.useCallback(()=>t.isActive(Kt.Iframe.name)&&!r,[t,r]),x=b.useCallback(()=>Ft(Kt.Iframe.name,t),[t]);return e?d.jsx(d.Fragment,{children:d.jsx(et,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleIframe",shouldShow:g,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{action:f,icon:"Eye",tooltip:"Visit Link"}),d.jsxs(m.Dialog,{onOpenChange:l,open:o,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{icon:"Pencil",tooltip:"Open Edit Link"})}),d.jsxs(m.DialogContent,{children:[d.jsx(m.DialogHeader,{children:d.jsx(m.DialogTitle,{children:"Edit Link Iframe"})}),d.jsx(m.Input,{autoFocus:!0,onInput:w=>a(w.target.value),placeholder:"Enter link",type:"url",value:c}),d.jsxs(m.DialogFooter,{children:[d.jsx(m.Button,{onClick:u,type:"button",children:"Cancel"}),d.jsx(m.Button,{onClick:h,type:"button",children:"OK"})]})]})]}),d.jsx(Ks,{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 Il({children:e,visible:t,toggleVisible:n}){const{t:i}=B.useLocale(),s=m.useEditorInstance(),r=ut.useAttributes(s,ut.Katex.name,{text:"",macros:""}),{text:o,macros:l}=r,[c,a]=b.useState(decodeURIComponent(o||"")),[u,h]=b.useState(decodeURIComponent(l||""));b.useEffect(()=>{t&&(a(decodeURIComponent(o||"")),h(decodeURIComponent(l||"")))},[t]);const f=b.useCallback(()=>{s.chain().focus().setKatex({text:encodeURIComponent(c),macros:encodeURIComponent(u)}).run(),a(""),h(""),n(!1)},[s,c,u,n]),p=b.useMemo(()=>{try{return Io.renderToString(c,{macros:ut.safeJSONParse(u||"")})}catch{return c}},[c,u]),g=b.useMemo(()=>`${c}`.trim()?p:null,[c,p]);return d.jsxs(m.Dialog,{onOpenChange:n,open:t,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:e}),d.jsxs(m.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[d.jsx(m.DialogTitle,{children:i("editor.formula.dialog.text")}),d.jsx("div",{style:{height:"100%",border:"1px solid hsl(var(--border))"},children:d.jsxs("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[d.jsxs("div",{className:"richtext-flex-1",children:[d.jsx(m.Label,{className:"mb-[6px]",children:"Expression"}),d.jsx(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 Dl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),[n,i]=b.useState(!1),s=b.useCallback(()=>t.isActive(ut.Katex.name),[t]),r=b.useCallback(()=>Ft(ut.Katex.name,t),[t]);return e?d.jsx(et,{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(Il,{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 Ml(e){const{t}=B.useLocale();return d.jsxs("div",{className:"richtext-flex richtext-flex-nowrap",children:[d.jsx(m.ActionButton,{disabled:!(e!=null&&e.link),icon:"ExternalLink",tooltip:t("editor.link.open.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{window.open(e==null?void 0:e.link,"_blank")}}),d.jsx(m.ActionButton,{icon:"Pencil",tooltip:t("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onEdit()}}),d.jsx(m.ActionButton,{icon:"Unlink",tooltip:t("editor.link.unlink.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onClear()}})]})}function Ol(){const e=m.useEditableEditor(),t=m.useEditorInstance(),[n,i]=b.useState(!1),s=ut.useAttributes(t,Ve.Link.name),r=s==null?void 0:s.href,o=b.useCallback(({editor:u})=>u.isActive(Ve.Link.name),[]),l=(u,h,f)=>{const p=t.state.selection,{from:g}=p,x=(h==null?void 0:h.length)??0,w=g+x;t.chain().extendMarkRange("link").insertContent({type:"text",text:h,marks:[{type:"link",attrs:{href:u,target:f?"_blank":""}}]}).setLink({href:u}).setTextSelection({from:g,to:w}).focus().run(),i(!1)},c=b.useCallback(()=>{t.chain().extendMarkRange("link").unsetLink().focus().run(),i(!1)},[t]),a=()=>{i(!1)};return e?d.jsx(et,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleLink",shouldShow:o,children:d.jsx(d.Fragment,{children:n?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-4 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(Ve.LinkEditBlock,{editor:t,onClose:a,onSetLink:l})}):d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(Ml,{editor:t,link:r,onClear:c,onEdit:()=>{i(!0)}})})})}):d.jsx(d.Fragment,{})}function bi({item:e,disabled:t,editor:n}){const i=e.component;return i?d.jsx(b.Fragment,{children:e.type==="divider"?d.jsx(Ct.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 jl(e){return e.type.name===m.Image.name}function Rl(e){return e.type.name===Ao.ImageGif.name}function Nl(e){return e.type.name===m.Video.name}function Bl(){const{lang:e,t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:o})=>{const{selection:l}=o.view.state,{$from:c,to:a}=l;let u=!1;return o.view.state.doc.nodesBetween(c.pos,a,h=>{if(jl(h))return u=!0,!1}),u},r=b.useMemo(()=>bl(i,t),[i,e,t]);return n?d.jsx(et,{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(bi,{editor:i,item:o},`bubbleMenu-image-${l}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function Ll(){const{lang:e,t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:o})=>{const{selection:l}=o.view.state,{$from:c,to:a}=l;let u=!1;return o.view.state.doc.nodesBetween(c.pos,a,h=>{if(Rl(h))return u=!0,!1}),u},r=b.useMemo(()=>wl(i,t),[i,t,e]);return n?d.jsx(et,{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(bi,{editor:i,item:o},`bubbleMenu-image-gif-${l}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function Ul(){const{t:e}=B.useLocale(),t=m.useEditableEditor(),n=m.useEditorInstance(),i=({editor:r})=>{const{selection:o}=r.view.state,{$from:l,to:c}=o;let a=!1;return r.view.state.doc.nodesBetween(l.pos,c,u=>{if(Nl(u))return a=!0,!1}),a},s=b.useMemo(()=>Sl(n,e),[n,e]);return t?d.jsx(et,{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(bi,{editor:n,item:r},`bubbleMenu-video-${o}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}const Yi=`graph TB
2
- a-->b`,Pl=({editor:e,attrs:t,extension:n})=>{const{alt:i,align:s}=t,[r,o]=b.useState(decodeURIComponent(i??Yi)),[l,c]=b.useState(""),[a,u]=b.useState(!1),h=b.useRef(null),[f,p]=b.useState(null),g=n==null?void 0:n.options.upload,x=b.useCallback(k=>{k&&import("mermaid").then(D=>{p(D.default)})},[]),w=async k=>{try{const{svg:D}=await f.render("mermaid-svg",k);c(D)}catch{c("")}},y=()=>{f.initialize({darkMode:!1,startOnLoad:!1,fontSize:12,theme:"base"}),w(r)};b.useEffect(()=>{f&&a&&y()},[f,a]),b.useEffect(()=>{f&&a&&w(r)},[f,r]);const C=async()=>{if(r!==""){if(r){const k=h.current.querySelector("svg"),{width:D,height:L}=k.getBoundingClientRect(),v=`mermaid-${Je.shortId()}.svg`;let S=Je.i(k.outerHTML);if(g){const A=m.dataURLtoFile(S,v);S=await g(A)}e==null||e.chain().focus().setMermaid({type:"mermaid",src:S,alt:encodeURIComponent(r),width:D,height:L},!!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:Yi,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: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 $l({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?d.jsx(b.Fragment,{children:e.type==="divider"?d.jsx(Ct.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 Fl(e){return e.type.name===Zn.Mermaid.name}function Vl(){const{lang:e,t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=ut.useAttributes(i,Zn.Mermaid.name),r=m.useExtension(Zn.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(Fl(p))return f=!0,!1}),f},l=b.useMemo(()=>yl(i,t),[i,e,t]);return n?d.jsx(et,{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(Pl,{attrs:s,editor:i,extension:r},`bubbleMenu-mermaid-${a}`):d.jsx($l,{editor:i,item:c},`bubbleMenu-mermaid-${a}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function Hl({hiddenActions:e=[]}){var x,w,y,C,k,D,L,v,S,A,z,N,$,Y,st,E,yt,je;const{t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:zt})=>T.isActive(zt.view.state,Ns.Table.name),r=zt=>e.includes(zt);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(et,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTable",shouldShow:s,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[!r("addColumnBefore")&&d.jsx(m.ActionButton,{action:o,disabled:!((w=(x=i==null?void 0:i.can())==null?void 0:x.addColumnBefore)!=null&&w.call(x)),icon:"BetweenHorizonalEnd",tooltip:t("editor.table.menu.insertColumnBefore"),tooltipOptions:{sideOffset:15}}),!r("addColumnAfter")&&d.jsx(m.ActionButton,{action:l,disabled:!((C=(y=i==null?void 0:i.can())==null?void 0:y.addColumnAfter)!=null&&C.call(y)),icon:"BetweenHorizonalStart",tooltip:t("editor.table.menu.insertColumnAfter"),tooltipOptions:{sideOffset:15}}),!r("deleteColumn")&&d.jsx(m.ActionButton,{action:c,disabled:!((D=i==null?void 0:(k=i.can()).deleteColumn)!=null&&D.call(k)),icon:"DeleteColumn",tooltip:t("editor.table.menu.deleteColumn"),tooltipOptions:{sideOffset:15}}),d.jsx(Ct.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!r("addRowAbove")&&d.jsx(m.ActionButton,{action:a,disabled:!((v=i==null?void 0:(L=i.can()).addRowBefore)!=null&&v.call(L)),icon:"BetweenVerticalEnd",tooltip:t("editor.table.menu.insertRowAbove"),tooltipOptions:{sideOffset:15}}),!r("addRowBelow")&&d.jsx(m.ActionButton,{action:u,disabled:!((A=(S=i==null?void 0:i.can())==null?void 0:S.addRowAfter)!=null&&A.call(S)),icon:"BetweenVerticalStart",tooltip:t("editor.table.menu.insertRowBelow"),tooltipOptions:{sideOffset:15}}),!r("deleteRow")&&d.jsx(m.ActionButton,{action:h,disabled:!((N=(z=i==null?void 0:i.can())==null?void 0:z.deleteRow)!=null&&N.call(z)),icon:"DeleteRow",tooltip:t("editor.table.menu.deleteRow"),tooltipOptions:{sideOffset:15}}),d.jsx(Ct.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!r("mergeCells")&&d.jsx(m.ActionButton,{action:f,disabled:!((Y=($=i==null?void 0:i.can())==null?void 0:$.mergeCells)!=null&&Y.call($)),icon:"TableCellsMerge",tooltip:t("editor.table.menu.mergeCells"),tooltipOptions:{sideOffset:15}}),!r("splitCells")&&d.jsx(m.ActionButton,{action:p,disabled:!((E=(st=i==null?void 0:i.can())==null?void 0:st.splitCell)!=null&&E.call(st)),icon:"TableCellsSplit",tooltip:t("editor.table.menu.splitCells"),tooltipOptions:{sideOffset:15}}),d.jsx(Ct.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!r("deleteTable")&&d.jsx(m.ActionButton,{action:g,disabled:!((je=(yt=i==null?void 0:i.can())==null?void 0:yt.deleteTable)!=null&&je.call(yt)),icon:"Trash2",tooltip:t("editor.table.menu.deleteTable"),tooltipOptions:{sideOffset:15}})]})}):d.jsx(d.Fragment,{})}function zl(){const{t:e}=B.useLocale(),[t,n]=b.useState(!1),i=m.useEditorInstance(),s=b.useMemo(()=>{var o,l;return(l=(o=Lo.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(St.Popover,{modal:!0,onOpenChange:n,open:t,children:[d.jsx(St.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(St.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 Kl(){return d.jsxs(d.Fragment,{children:[d.jsx(zl,{}),d.jsx(Ct.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(Oo.RichTextBold,{}),d.jsx(Bo.RichTextItalic,{}),d.jsx(Po.RichTextUnderline,{}),d.jsx(Uo.RichTextStrike,{}),d.jsx(jo.RichTextCode,{}),d.jsx(Ve.RichTextLink,{}),d.jsx(Ct.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(Ro.RichTextColor,{}),d.jsx(No.RichTextHighlight,{}),d.jsx(Us.RichTextAlign,{})]})}function ql({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 W.TextSelection};return n?d.jsx(et,{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(Kl,{})})}):d.jsx(d.Fragment,{})}function Wl(){const{t:e}=B.useLocale(),t=m.useEditableEditor(),n=m.useEditorInstance(),[i,s]=b.useState(!1),r=b.useCallback(({editor:c})=>c.isActive(Bn.Twitter.name),[]),o=c=>{n.commands.updateTweet({src:c}),s(!1)},l=b.useCallback(()=>Ft(Bn.Twitter.name,n),[n]);return t?d.jsx(et,{editor:n,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTwitter",shouldShow:r,children:d.jsx(d.Fragment,{children:i?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-4 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(Bn.FormEditLinkTwitter,{editor:n,onSetLink:o})}):d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{icon:"Pencil",tooltip:e("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{s(!0)}}),d.jsx(m.ActionButton,{action:l,icon:"Trash",tooltip:e("editor.delete"),tooltipOptions:{sideOffset:15}})]})})}):d.jsx(d.Fragment,{})}const dt=()=>new Map,ti=e=>{const t=dt();return e.forEach((n,i)=>{t.set(i,n)}),t},_t=(e,t,n)=>{let i=e.get(t);return i===void 0&&e.set(t,i=n()),i},Gl=(e,t)=>{const n=[];for(const[i,s]of e)n.push(t(s,i));return n},Yl=(e,t)=>{for(const[n,i]of e)if(t(i,n))return!0;return!1},Lt=()=>new Set,Un=e=>e[e.length-1],Jl=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},Ut=Array.from,wi=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},yi=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},Xl=(e,t)=>{const n=new Array(e);for(let i=0;i<e;i++)n[i]=t(i,n);return n},Qt=Array.isArray;class qs{constructor(){this._observers=dt()}on(t,n){return _t(this._observers,t,Lt).add(n),n}once(t,n){const i=(...s)=>{this.off(t,i),n(...s)};this.on(t,i)}off(t,n){const i=this._observers.get(t);i!==void 0&&(i.delete(n),i.size===0&&this._observers.delete(t))}emit(t,n){return Ut((this._observers.get(t)||dt()).values()).forEach(i=>i(...n))}destroy(){this._observers=dt()}}const ft=Math.floor,He=Math.abs,te=(e,t)=>e<t?e:t,Mt=(e,t)=>e>t?e:t,Ws=e=>e!==0?e<0:1/e<0,Ji=1,Xi=2,Pn=4,$n=8,me=32,kt=64,tt=128,Zl=1<<29,mn=31,ei=63,Bt=127,Ql=2147483647,Xe=Number.MAX_SAFE_INTEGER,Zi=Number.MIN_SAFE_INTEGER,tc=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&ft(e)===e),Gs=String.fromCharCode,ec=e=>e.toLowerCase(),nc=/^\s*/g,ic=e=>e.replace(nc,""),sc=/([A-Z])/g,Qi=(e,t)=>ic(e.replace(sc,n=>`${t}${ec(n)}`)),rc=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},xe=typeof TextEncoder<"u"?new TextEncoder:null,oc=e=>xe.encode(e),lc=xe?oc:rc;let pe=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});pe&&pe.decode(new Uint8Array).length===1&&(pe=null);const cc=(e,t)=>Xl(t,()=>e).join("");class Ae{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Ie=()=>new Ae,ac=e=>{const t=Ie();return e(t),ht(t)},hc=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},ht=e=>{const t=new Uint8Array(hc(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},uc=(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(Mt(n,t)*2),e.cpos=0)},K=(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},ni=K,I=(e,t)=>{for(;t>Bt;)K(e,tt|Bt&t),t=ft(t/128);K(e,Bt&t)},vi=(e,t)=>{const n=Ws(t);for(n&&(t=-t),K(e,(t>ei?tt:0)|(n?kt:0)|ei&t),t=ft(t/64);t>0;)K(e,(t>Bt?tt:0)|Bt&t),t=ft(t/128)},ii=new Uint8Array(3e4),dc=ii.length/3,fc=(e,t)=>{if(t.length<dc){const n=xe.encodeInto(t,ii).written||0;I(e,n);for(let i=0;i<n;i++)K(e,ii[i])}else rt(e,lc(t))},pc=(e,t)=>{const n=unescape(encodeURIComponent(t)),i=n.length;I(e,i);for(let s=0;s<i;s++)K(e,n.codePointAt(s))},Wt=xe&&xe.encodeInto?fc:pc,xn=(e,t)=>{const n=e.cbuf.length,i=e.cpos,s=te(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(Mt(n*2,r)),e.cbuf.set(t.subarray(s)),e.cpos=r)},rt=(e,t)=>{I(e,t.byteLength),xn(e,t)},Si=(e,t)=>{uc(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},gc=(e,t)=>Si(e,4).setFloat32(0,t,!1),mc=(e,t)=>Si(e,8).setFloat64(0,t,!1),xc=(e,t)=>Si(e,8).setBigInt64(0,t,!1),ts=new DataView(new ArrayBuffer(4)),bc=e=>(ts.setFloat32(0,e),ts.getFloat32(0)===e),ee=(e,t)=>{switch(typeof t){case"string":K(e,119),Wt(e,t);break;case"number":tc(t)&&He(t)<=Ql?(K(e,125),vi(e,t)):bc(t)?(K(e,124),gc(e,t)):(K(e,123),mc(e,t));break;case"bigint":K(e,122),xc(e,t);break;case"object":if(t===null)K(e,126);else if(Qt(t)){K(e,117),I(e,t.length);for(let n=0;n<t.length;n++)ee(e,t[n])}else if(t instanceof Uint8Array)K(e,116),rt(e,t);else{K(e,118);const n=Object.keys(t);I(e,n.length);for(let i=0;i<n.length;i++){const s=n[i];Wt(e,s),ee(e,t[s])}}break;case"boolean":K(e,t?120:121);break;default:K(e,127)}};class es extends Ae{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&I(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const ns=e=>{e.count>0&&(vi(e.encoder,e.count===1?e.s:-e.s),e.count>1&&I(e.encoder,e.count-2))};class ze{constructor(){this.encoder=new Ae,this.s=0,this.count=0}write(t){this.s===t?this.count++:(ns(this),this.count=1,this.s=t)}toUint8Array(){return ns(this),ht(this.encoder)}}const is=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);vi(e.encoder,t),e.count>1&&I(e.encoder,e.count-2)}};class Fn{constructor(){this.encoder=new Ae,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(is(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return is(this),ht(this.encoder)}}class wc{constructor(){this.sarr=[],this.s="",this.lensE=new ze}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new Ae;return this.sarr.push(this.s),this.s="",Wt(t,this.sarr.join("")),xn(t,this.lensE.toUint8Array()),ht(t)}}const wt=e=>new Error(e),ct=()=>{throw wt("Method unimplemented")},Z=()=>{throw wt("Unexpected case")},Ys=wt("Unexpected end of array"),Js=wt("Integer out of Range");class bn{constructor(t){this.arr=t,this.pos=0}}const Ci=e=>new bn(e),yc=e=>e.pos!==e.arr.length,vc=(e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},ot=e=>vc(e,j(e)),be=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&Bt)*n,n*=128,s<tt)return t;if(t>Xe)throw Js}throw Ys},ki=e=>{let t=e.arr[e.pos++],n=t&ei,i=64;const s=(t&kt)>0?-1:1;if((t&tt)===0)return s*n;const r=e.arr.length;for(;e.pos<r;){if(t=e.arr[e.pos++],n=n+(t&Bt)*i,i*=128,t<tt)return s*n;if(n>Xe)throw Js}throw Ys},Sc=e=>{let t=j(e);if(t===0)return"";{let n=String.fromCodePoint(be(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(be(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))}},Cc=e=>pe.decode(ot(e)),si=pe?Cc:Sc,Ei=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},kc=e=>Ei(e,4).getFloat32(0,!1),Ec=e=>Ei(e,8).getFloat64(0,!1),_c=e=>Ei(e,8).getBigInt64(0,!1),Tc=[e=>{},e=>null,ki,kc,Ec,_c,e=>!1,e=>!0,si,e=>{const t=j(e),n={};for(let i=0;i<t;i++){const s=si(e);n[s]=Ze(e)}return n},e=>{const t=j(e),n=[];for(let i=0;i<t;i++)n.push(Ze(e));return n},ot],Ze=e=>Tc[127-be(e)](e);class ss extends bn{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),yc(this)?this.count=j(this)+1:this.count=-1),this.count--,this.s}}class Ke extends bn{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=ki(this);const t=Ws(this.s);this.count=1,t&&(this.s=-this.s,this.count=j(this)+2)}return this.count--,this.s}}class Vn extends bn{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=ki(this),n=t&1;this.diff=ft(t/2),this.count=1,n&&(this.count=j(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Ac{constructor(t){this.decoder=new Ke(t),this.str=si(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 Ic=crypto.getRandomValues.bind(crypto),Dc=Math.random,Xs=()=>Ic(new Uint32Array(1))[0],Mc=e=>e[ft(Dc()*e.length)],Oc="10000000-1000-4000-8000"+-1e11,jc=()=>Oc.replace(/[018]/g,e=>(e^Xs()&15>>e/4).toString(16)),Rc=Date.now,rs=e=>new Promise(e);Promise.all.bind(Promise);const os=e=>e===void 0?null:e;class Nc{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}}let Zs=new Nc,Bc=!0;try{typeof localStorage<"u"&&localStorage&&(Zs=localStorage,Bc=!1)}catch{}const Lc=Zs,we=Symbol("Equality"),Qs=(e,t)=>{var n;return e===t||!!((n=e==null?void 0:e[we])!=null&&n.call(e,t))||!1},Uc=e=>typeof e=="object",Pc=Object.assign,tr=Object.keys,$c=(e,t)=>{for(const n in e)t(e[n],n)},Qe=e=>tr(e).length,Fc=e=>{for(const t in e)return!1;return!0},re=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},_i=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Vc=(e,t)=>e===t||Qe(e)===Qe(t)&&re(e,(n,i)=>(n!==void 0||_i(t,i))&&Qs(t[i],n)),Hc=Object.freeze,er=e=>{for(const t in e){const n=e[t];(typeof n=="object"||typeof n=="function")&&er(e[t])}return Hc(e)},Ti=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Ti(e,t,n+1)}},qe=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[we]!=null)return e[we](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:{if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break}case Set:{if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;break}case Map:{if(e.size!==t.size)return!1;for(const n of e.keys())if(!t.has(n)||!qe(e.get(n),t.get(n)))return!1;break}case void 0:case Object:if(Qe(e)!==Qe(t))return!1;for(const n in e)if(!_i(e,n)||!qe(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!qe(e[n],t[n]))return!1;break;default:return!1}return!0},zc=(e,t)=>t.includes(e),ne=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",nr=typeof window<"u"&&typeof document<"u"&&!ne;let xt;const Kc=()=>{if(xt===void 0)if(ne){xt=dt();const e=process.argv;let t=null;for(let n=0;n<e.length;n++){const i=e[n];i[0]==="-"?(t!==null&&xt.set(t,""),t=i):t!==null&&(xt.set(t,i),t=null)}t!==null&&xt.set(t,"")}else typeof location=="object"?(xt=dt(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){const[t,n]=e.split("=");xt.set(`--${Qi(t,"-")}`,n),xt.set(`-${Qi(t,"-")}`,n)}})):xt=dt();return xt},ri=e=>Kc().has(e),tn=e=>os(ne?process.env[e.toUpperCase().replaceAll("-","_")]:Lc.getItem(e)),ir=e=>ri("--"+e)||tn(e)!==null,qc=ir("production"),Wc=ne&&zc(process.env.FORCE_COLOR,["true","1","2"]),Gc=Wc||!ri("--no-colors")&&!ir("no-color")&&(!ne||process.stdout.isTTY)&&(!ne||ri("--color")||tn("COLORTERM")!==null||(tn("TERM")||"").includes("color")),Yc=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=Gs(e[n]);return btoa(t)},Jc=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),Xc=nr?Yc:Jc,Zc=e=>ac(t=>ee(t,e));class Qc{constructor(t,n){this.left=t,this.right=n}}const vt=(e,t)=>new Qc(e,t),ls=e=>e.next()>=.5,Hn=(e,t,n)=>ft(e.next()*(n+1-t)+t),sr=(e,t,n)=>ft(e.next()*(n+1-t)+t),Ai=(e,t,n)=>sr(e,t,n),ta=e=>Gs(Ai(e,97,122)),ea=(e,t=0,n=20)=>{const i=Ai(e,t,n);let s="";for(let r=0;r<i;r++)s+=ta(e);return s},zn=(e,t)=>t[Ai(e,0,t.length-1)],na=Symbol("0schema");class ia{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(cc(" ",(this._rerrs.length-n)*2)+`${i.path!=null?`[${i.path}] `:""}${i.has} doesn't match ${i.expected}. ${i.message}`)}return t.join(`
3
- `)}}const oi=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[we]?Qs(e,t):Qt(e)?wi(e,n=>yi(t,i=>oi(n,i))):Uc(e)?re(e,(n,i)=>oi(n,t[i])):!1;class Q{extends(t){let[n,i]=[this.shape,t.shape];return this.constructor._dilutes&&([i,n]=[n,i]),oi(n,i)}equals(t){return this.constructor===t.constructor&&qe(this.shape,t.shape)}[na](){return!0}[we](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){ct()}get nullable(){return oe(this,Cn)}get optional(){return new lr(this)}cast(t){return cs(t,this),t}expect(t){return cs(t,this),t}}Re(Q,"_dilutes",!1);class Ii extends Q{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n=void 0){const i=(t==null?void 0:t.constructor)===this.shape&&(this._c==null||this._c(t));return!i&&(n==null||n.extend(null,this.shape.name,t==null?void 0:t.constructor.name,(t==null?void 0:t.constructor)!==this.shape?"Constructor match failed":"Check failed")),i}}const V=(e,t=null)=>new Ii(e,t);V(Ii);class Di extends Q{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 Di(e);V(Di);class wn extends Q{constructor(t){super(),this.shape=t}check(t,n){const i=this.shape.some(s=>s===t);return!i&&(n==null||n.extend(null,this.shape.join(" | "),t.toString())),i}}const yn=(...e)=>new wn(e),rr=V(wn),sa=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,t=>"\\"+t)),or=e=>{if(ie.check(e))return[sa(e)];if(rr.check(e))return e.shape.map(t=>t+"");if(mr.check(e))return["[+-]?\\d+.?\\d*"];if(xr.check(e))return[".*"];if(nn.check(e))return e.shape.map(or).flat(1);Z()};class ra extends Q{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(or).map(n=>`(${n.join("|")})`).join("")+"$")}check(t,n){const i=this._r.exec(t)!=null;return!i&&(n==null||n.extend(null,this._r.toString(),t.toString(),"String doesn't match string template.")),i}}V(ra);const oa=Symbol("optional");class lr extends Q{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[oa](){return!0}}const la=V(lr);class ca extends Q{check(t,n){return n==null||n.extend(null,"never",typeof t),!1}}V(ca);const gn=class gn extends Q{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}get partial(){return new gn(this.shape,!0)}check(t,n){return t==null?(n==null||n.extend(null,"object","null"),!1):re(this.shape,(i,s)=>{const r=this._isPartial&&!_i(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})}};Re(gn,"_dilutes",!0);let en=gn;const aa=e=>new en(e),ha=V(en),ua=G(e=>e!=null&&(e.constructor===Object||e.constructor==null));class cr extends Q{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return t!=null&&re(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 ar=(e,t)=>new cr(e,t),da=V(cr);class hr extends Q{constructor(t){super(),this.shape=t}check(t,n){return t!=null&&re(this.shape,(i,s)=>{const r=i.check(t[s],n);return!r&&(n==null||n.extend(s.toString(),"Tuple",typeof i)),r})}}const fa=(...e)=>new hr(e);V(hr);class ur extends Q{constructor(t){super(),this.shape=t.length===1?t[0]:new vn(t)}check(t,n){const i=Qt(t)&&wi(t,s=>this.shape.check(s));return!i&&(n==null||n.extend(null,"Array","")),i}}const dr=(...e)=>new ur(e),pa=V(ur),ga=G(e=>Qt(e));class fr extends Q{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 ma=(e,t=null)=>new fr(e,t);V(fr);const xa=ma(Q);class ba extends Q{constructor(t){super(),this.len=t.length-1,this.args=fa(...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 wa=V(ba),ya=G(e=>typeof e=="function");class va extends Q{constructor(t){super(),this.shape=t}check(t,n){const i=wi(this.shape,s=>s.check(t,n));return!i&&(n==null||n.extend(null,"Intersectinon",typeof t)),i}}V(va,e=>e.shape.length>0);class vn extends Q{constructor(t){super(),this.shape=t}check(t,n){const i=yi(this.shape,s=>s.check(t,n));return n==null||n.extend(null,"Union",typeof t),i}}Re(vn,"_dilutes",!0);const oe=(...e)=>e.findIndex(t=>nn.check(t))>=0?oe(...e.map(t=>ye(t)).map(t=>nn.check(t)?t.shape:[t]).flat(1)):e.length===1?e[0]:new vn(e),nn=V(vn),pr=()=>!0,sn=G(pr),Sa=V(Di,e=>e.shape===pr),Mi=G(e=>typeof e=="bigint"),Ca=G(e=>e===Mi),gr=G(e=>typeof e=="symbol");G(e=>e===gr);const Gt=G(e=>typeof e=="number"),mr=G(e=>e===Gt),ie=G(e=>typeof e=="string"),xr=G(e=>e===ie),Sn=G(e=>typeof e=="boolean"),ka=G(e=>e===Sn),br=yn(void 0);V(wn,e=>e.shape.length===1&&e.shape[0]===void 0);yn(void 0);const Cn=yn(null),Ea=V(wn,e=>e.shape.length===1&&e.shape[0]===null);V(Uint8Array);V(Ii,e=>e.shape===Uint8Array);const _a=oe(Gt,ie,Cn,br,Mi,Sn,gr);(()=>{const e=dr(sn),t=ar(ie,sn),n=oe(Gt,ie,Cn,Sn,e,t);return e.shape=n,t.shape.values=n,n})();const ye=e=>{if(xa.check(e))return e;if(ua.check(e)){const t={};for(const n in e)t[n]=ye(e[n]);return aa(t)}else{if(ga.check(e))return oe(...e.map(ye));if(_a.check(e))return yn(e);if(ya.check(e))return V(e)}Z()},cs=qc?()=>{}:(e,t)=>{const n=new ia;if(!t.check(e,n))throw wt(`Expected value to be of type ${t.constructor.name}.
4
- ${n.toString()}`)};class Ta{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:ye(t),h:n}),this}else(t){return this.if(sn,t)}done(){return(t,n)=>{for(let i=0;i<this.patterns.length;i++){const s=this.patterns[i];if(s.if.check(t))return s.h(t,n)}throw wt("Unhandled pattern")}}}const Aa=e=>new Ta(e),wr=Aa(sn).if(mr,(e,t)=>Hn(t,Zi,Xe)).if(xr,(e,t)=>ea(t)).if(ka,(e,t)=>ls(t)).if(Ca,(e,t)=>BigInt(Hn(t,Zi,Xe))).if(nn,(e,t)=>qt(t,zn(t,e.shape))).if(ha,(e,t)=>{const n={};for(const i in e.shape){let s=e.shape[i];if(la.check(s)){if(ls(t))continue;s=s.shape}n[i]=wr(s,t)}return n}).if(pa,(e,t)=>{const n=[],i=sr(t,0,42);for(let s=0;s<i;s++)n.push(qt(t,e.shape));return n}).if(rr,(e,t)=>zn(t,e.shape)).if(Ea,(e,t)=>null).if(wa,(e,t)=>{const n=qt(t,e.res);return()=>n}).if(Sa,(e,t)=>qt(t,zn(t,[Gt,ie,Cn,br,Mi,Sn,dr(Gt),ar(oe("a","b","c"),Gt)]))).if(da,(e,t)=>{const n={},i=Hn(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)=>wr(ye(t),e),De=typeof document<"u"?document:{};G(e=>e.nodeType===ja);typeof DOMParser<"u"&&new DOMParser;G(e=>e.nodeType===Da);G(e=>e.nodeType===Ma);const Ia=e=>Gl(e,(t,n)=>`${n}:${t};`).join(""),Da=De.ELEMENT_NODE,Ma=De.TEXT_NODE,Oa=De.DOCUMENT_NODE,ja=De.DOCUMENT_FRAGMENT_NODE;G(e=>e.nodeType===Oa);const Ra=e=>class{constructor(n){this._=n}destroy(){e(this._)}},Na=Ra(clearTimeout),yr=(e,t)=>new Na(setTimeout(t,e)),Tt=Symbol,vr=Tt(),Sr=Tt(),Ba=Tt(),La=Tt(),Ua=Tt(),Cr=Tt(),Pa=Tt(),Oi=Tt(),$a=Tt(),Fa=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},Va={[vr]:vt("font-weight","bold"),[Sr]:vt("font-weight","normal"),[Ba]:vt("color","blue"),[Ua]:vt("color","green"),[La]:vt("color","grey"),[Cr]:vt("color","red"),[Pa]:vt("color","purple"),[Oi]:vt("color","orange"),[$a]:vt("color","black")},Ha=e=>{var o;e.length===1&&((o=e[0])==null?void 0:o.constructor)===Function&&(e=e[0]());const t=[],n=[],i=dt();let s=[],r=0;for(;r<e.length;r++){const l=e[r],c=Va[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=Ia(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},kr=Gc?Ha:Fa,za=(...e)=>{console.log(...kr(e)),_r.forEach(t=>t.print(e))},Er=(...e)=>{console.warn(...kr(e)),e.unshift(Oi),_r.forEach(t=>t.print(e))},_r=Lt(),Tr=e=>({[Symbol.iterator](){return this},next:e}),Ka=(e,t)=>Tr(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),Kn=(e,t)=>Tr(()=>{const{done:n,value:i}=e.next();return{done:n,value:n?void 0:t(i)}});class kn{constructor(t,n){this.clock=t,this.len=n}}class le{constructor(){this.clients=new Map}}const Ot=(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])Nr(e,r,a.clock,a.len,n)}}),qa=(e,t)=>{let n=0,i=e.length-1;for(;n<=i;){const s=ft((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},ce=(e,t)=>{const n=e.clients.get(t.client);return n!==void 0&&qa(n,t.clock)!==null},ji=e=>{e.clients.forEach(t=>{t.sort((s,r)=>s.clock-r.clock);let n,i;for(n=1,i=1;n<t.length;n++){const s=t[i-1],r=t[n];s.clock+s.len>=r.clock?t[i-1]=new kn(s.clock,Mt(s.len,r.clock+r.len-s.clock)):(i<n&&(t[i]=r),i++)}t.length=i})},li=e=>{const t=new le;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++)Jl(r,e[o].clients.get(s)||[]);t.clients.set(s,r)}});return ji(t),t},ve=(e,t,n,i)=>{_t(e.clients,t,()=>[]).push(new kn(n,i))},Ar=()=>new le,Wa=e=>{const t=Ar();return e.clients.forEach((n,i)=>{const s=[];for(let r=0;r<n.length;r++){const o=n[r];if(o.deleted){const l=o.id.clock;let c=o.length;if(r+1<n.length)for(let a=n[r+1];r+1<n.length&&a.deleted;a=n[++r+1])c+=a.length;s.push(new kn(l,c))}}s.length>0&&t.clients.set(i,s)}),t},Ri=(e,t)=>{I(e.restEncoder,t.clients.size),Ut(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)}})},Ga=e=>{const t=new le,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=_t(t.clients,s,()=>[]);for(let l=0;l<r;l++)o.push(new kn(e.readDsClock(),e.readDsLen()))}}return t},as=(e,t,n)=>{const i=new le,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=P(n,o);for(let u=0;u<l;u++){const h=e.readDsClock(),f=h+e.readDsLen();if(h<a){a<f&&ve(i,o,a,f-a);let p=pt(c,h),g=c[p];for(!g.deleted&&g.id.clock<h&&(c.splice(p+1,0,un(t,g,h-g.id.clock)),p++);p<c.length&&(g=c[p++],g.id.clock<f);)g.deleted||(f<g.id.clock+g.length&&c.splice(p,0,un(t,g,f-g.id.clock)),g.delete(t))}else ve(i,o,h,f-h)}}if(i.clients.size>0){const r=new En;return I(r.restEncoder,0),Ri(r,i),r.toUint8Array()}return null},Ir=Xs;class Vt extends qs{constructor({guid:t=jc(),collectionid:n=null,gc:i=!0,gcFilter:s=()=>!0,meta:r=null,autoLoad:o=!1,shouldLoad:l=!0}={}){super(),this.gc=i,this.gcFilter=s,this.clientID=Ir(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new jr,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=rs(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const c=()=>rs(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&&O(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Ut(this.subdocs).map(t=>t.guid))}transact(t,n=null){return O(this,t,n)}get(t,n=q){const i=_t(this.share,t,()=>{const r=new n;return r._integrate(this,null),r}),s=i.constructor;if(n!==q&&s!==n)if(s===q){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,Xt)}getText(t=""){return this.get(t,jt)}getMap(t=""){return this.get(t,se)}getXmlElement(t=""){return this.get(t,J)}getXmlFragment(t=""){return this.get(t,Pt)}toJSON(){const t={};return this.share.forEach((n,i)=>{t[i]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,Ut(this.subdocs).forEach(n=>n.destroy());const t=this._item;if(t!==null){this._item=null;const n=t.content;n.doc=new Vt({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,O(t.parent.doc,i=>{const s=n.doc;t.deleted||i.subdocsAdded.add(s),i.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class Ya{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 rn extends Ya{constructor(t){super(t),this.keys=[],j(t),this.keyClockDecoder=new Vn(ot(t)),this.clientDecoder=new Ke(ot(t)),this.leftClockDecoder=new Vn(ot(t)),this.rightClockDecoder=new Vn(ot(t)),this.infoDecoder=new ss(ot(t),be),this.stringDecoder=new Ac(ot(t)),this.parentInfoDecoder=new ss(ot(t),be),this.typeRefDecoder=new Ke(ot(t)),this.lenDecoder=new Ke(ot(t))}readLeftID(){return new Yt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Yt(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Ze(this.restDecoder)}readBuf(){return ot(this.restDecoder)}readJSON(){return Ze(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{const n=this.stringDecoder.read();return this.keys.push(n),n}}}class Ja{constructor(){this.restEncoder=Ie()}toUint8Array(){return ht(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){I(this.restEncoder,t)}writeDsLen(t){I(this.restEncoder,t)}}class Xa extends Ja{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){ni(this.restEncoder,t)}writeString(t){Wt(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){ee(this.restEncoder,t)}writeBuf(t){rt(this.restEncoder,t)}writeJSON(t){Wt(this.restEncoder,JSON.stringify(t))}writeKey(t){Wt(this.restEncoder,t)}}class Za{constructor(){this.restEncoder=Ie(),this.dsCurrVal=0}toUint8Array(){return ht(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,I(this.restEncoder,n)}writeDsLen(t){t===0&&Z(),I(this.restEncoder,t-1),this.dsCurrVal+=t}}class En extends Za{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Fn,this.clientEncoder=new ze,this.leftClockEncoder=new Fn,this.rightClockEncoder=new Fn,this.infoEncoder=new es(ni),this.stringEncoder=new wc,this.parentInfoEncoder=new es(ni),this.typeRefEncoder=new ze,this.lenEncoder=new ze}toUint8Array(){const t=Ie();return I(t,0),rt(t,this.keyClockEncoder.toUint8Array()),rt(t,this.clientEncoder.toUint8Array()),rt(t,this.leftClockEncoder.toUint8Array()),rt(t,this.rightClockEncoder.toUint8Array()),rt(t,ht(this.infoEncoder)),rt(t,this.stringEncoder.toUint8Array()),rt(t,ht(this.parentInfoEncoder)),rt(t,this.typeRefEncoder.toUint8Array()),rt(t,this.lenEncoder.toUint8Array()),xn(t,ht(this.restEncoder)),ht(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){ee(this.restEncoder,t)}writeBuf(t){rt(this.restEncoder,t)}writeJSON(t){ee(this.restEncoder,t)}writeKey(t){const n=this.keyMap.get(t);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}}const Qa=(e,t,n,i)=>{i=Mt(i,t[0].id.clock);const s=pt(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)},Dr=(e,t,n)=>{const i=new Map;n.forEach((s,r)=>{P(t,r)>s&&i.set(r,s)}),_n(t).forEach((s,r)=>{n.has(r)||i.set(r,0)}),I(e.restEncoder,i.size),Ut(i.entries()).sort((s,r)=>r[0]-s[0]).forEach(([s,r])=>{Qa(e,t.clients.get(s),s,r)})},th=(e,t)=>{const n=dt(),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 u=e.readInfo();switch(mn&u){case 0:{const h=e.readLen();o[a]=new lt(_(l,c),h),c+=h;break}case 10:{const h=j(e.restDecoder);o[a]=new at(_(l,c),h),c+=h;break}default:{const h=(u&(kt|tt))===0,f=new M(_(l,c),null,(u&tt)===tt?e.readLeftID():null,null,(u&kt)===kt?e.readRightID():null,h?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,h&&(u&me)===me?e.readString():null,io(e,u));o[a]=f,c+=f.length}}}}return n},eh=(e,t,n)=>{const i=[];let s=Ut(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 jr,c=new Map,a=(p,g)=>{const x=c.get(p);(x==null||x>g)&&c.set(p,g)};let u=o.refs[o.i++];const h=new Map,f=()=>{for(const p of i){const g=p.id.client,x=n.get(g);x?(x.i--,l.clients.set(g,x.refs.slice(x.i)),n.delete(g),x.i=0,x.refs=[]):l.clients.set(g,[p]),s=s.filter(w=>w!==g)}i.length=0};for(;;){if(u.constructor!==at){const g=_t(h,u.id.client,()=>P(t,u.id.client))-u.id.clock;if(g<0)i.push(u),a(u.id.client,u.id.clock-1),f();else{const x=u.getMissing(e,t);if(x!==null){i.push(u);const w=n.get(x)||{refs:[],i:0};if(w.refs.length===w.i)a(x,P(t,x)),f();else{u=w.refs[w.i++];continue}}else(g===0||g<u.length)&&(u.integrate(e,g),h.set(u.id.client,u.id.clock+u.length))}}if(i.length>0)u=i.pop();else if(o!==null&&o.i<o.refs.length)u=o.refs[o.i++];else{if(o=r(),o===null)break;u=o.refs[o.i++]}}if(l.clients.size>0){const p=new En;return Dr(p,l,new Map),I(p.restEncoder,0),{missing:c,update:p.toUint8Array()}}return null},nh=(e,t)=>Dr(e,t.doc.store,t.beforeState),ih=(e,t,n,i=new rn(e))=>O(t,s=>{s.local=!1;let r=!1;const o=s.doc,l=o.store,c=th(i,o),a=eh(s,l,c),u=l.pendingStructs;if(u){for(const[f,p]of u.missing)if(p<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=bs([u.update,a.update])}}else l.pendingStructs=a;const h=as(i,s,l);if(l.pendingDs){const f=new rn(Ci(l.pendingDs));j(f.restDecoder);const p=as(f,s,l);h&&p?l.pendingDs=bs([h,p]):l.pendingDs=h||p}else l.pendingDs=h;if(r){const f=l.pendingStructs.update;l.pendingStructs=null,ci(s.doc,f)}},n,!1),ci=(e,t,n,i=rn)=>{const s=Ci(t);ih(s,e,n,new i(s))};class sh{constructor(){this.l=[]}}const hs=()=>new sh,us=(e,t)=>e.l.push(t),ds=(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.")},Mr=(e,t,n)=>Ti(e.l,[t,n]);class Yt{constructor(t,n){this.client=t,this.clock=n}}const Be=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,_=(e,t)=>new Yt(e,t),Se=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw Z()},Ce=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1};class on{constructor(t,n,i,s=0){this.type=t,this.tname=n,this.item=i,this.assoc=s}}class rh{constructor(t,n,i=0){this.type=t,this.index=n,this.assoc=i}}const oh=(e,t,n=0)=>new rh(e,t,n),Le=(e,t,n)=>{let i=null,s=null;return e._item===null?s=Se(e):i=_(e._item.id.client,e._item.id.clock),new on(i,s,t,n)},qn=(e,t,n=0)=>{let i=e._start;if(n<0){if(t===0)return Le(e,null,n);t--}for(;i!==null;){if(!i.deleted&&i.countable){if(i.length>t)return Le(e,_(i.id.client,i.id.clock+t),n);t-=i.length}if(i.right===null&&n<0)return Le(e,i.lastId,n);i=i.right}return Le(e,null,n)},lh=(e,t)=>{const n=Jt(e,t),i=t.clock-n.id.clock;return{item:n,diff:i}},ch=(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(P(i,s.client)<=s.clock)return null;const u=n?di(i,s):lh(i,s),h=u.item;if(!(h instanceof M))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(P(i,r.client)<=r.clock)return null;const{item:u}=n?di(i,r):{item:Jt(i,r)};if(u instanceof M&&u.content instanceof mt)c=u.content.type;else return null}else throw Z();l>=0?a=c._length:a=0}return oh(c,a,e.assoc)};class Ni{constructor(t,n){this.ds=t,this.sv=n}}const Or=(e,t)=>new Ni(e,t),Wn=e=>Or(Wa(e.store),_n(e.store)),Nt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!ce(t.ds,e.id),ai=(e,t)=>{const n=_t(e.meta,ai,Lt),i=e.doc.store;n.has(t)||(t.sv.forEach((s,r)=>{s<P(i,r)&&nt(e,_(r,s))}),Ot(e,t.ds,s=>{}),n.add(t))};class jr{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const _n=e=>{const t=new Map;return e.clients.forEach((n,i)=>{const s=n[n.length-1];t.set(i,s.id.clock+s.length)}),t},P=(e,t)=>{const n=e.clients.get(t);if(n===void 0)return 0;const i=n[n.length-1];return i.id.clock+i.length},Rr=(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 Z()}n.push(t)},pt=(e,t)=>{let n=0,i=e.length-1,s=e[i],r=s.id.clock;if(r===t)return i;let o=ft(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=ft((n+i)/2)}throw Z()},ah=(e,t)=>{const n=e.clients.get(t.client);return n[pt(n,t.clock)]},Jt=ah,hi=(e,t,n)=>{const i=pt(t,n),s=t[i];return s.id.clock<n&&s instanceof M?(t.splice(i+1,0,un(e,s,n-s.id.clock)),i+1):i},nt=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[hi(e,n,t.clock)]},fs=(e,t,n)=>{const i=t.clients.get(n.client),s=pt(i,n.clock),r=i[s];return n.clock!==r.id.clock+r.length-1&&r.constructor!==lt&&i.splice(s+1,0,un(e,r,n.clock-r.id.clock+1)),r},hh=(e,t,n)=>{const i=e.clients.get(t.id.client);i[pt(i,t.id.clock)]=n},Nr=(e,t,n,i,s)=>{if(i===0)return;const r=n+i;let o=hi(e,t,n),l;do l=t[o++],r<l.id.clock+l.length&&hi(e,t,r),s(l);while(o<t.length&&t[o].id.clock<r)};class uh{constructor(t,n,i){this.doc=t,this.deleteSet=new le,this.beforeState=_n(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=i,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const ps=(e,t)=>t.deleteSet.clients.size===0&&!Yl(t.afterState,(n,i)=>t.beforeState.get(i)!==n)?!1:(ji(t.deleteSet),nh(e,t),Ri(e,t.deleteSet),!0),gs=(e,t,n)=>{const i=t._item;(i===null||i.id.clock<(e.beforeState.get(i.id.client)||0)&&!i.deleted)&&_t(e.changed,t,Lt).add(n)},We=(e,t)=>{let n=e[t],i=e[t-1],s=t;for(;s>0;n=i,i=e[--s-1]){if(i.deleted===n.deleted&&i.constructor===n.constructor&&i.mergeWith(n)){n instanceof M&&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},dh=(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=pt(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 M&&h.deleted&&!h.keep&&n(h)&&h.gc(t,!1)}}}},fh=(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=te(s.length-1,1+pt(s,o.clock+o.len-1));for(let c=l,a=s[c];c>0&&a.id.clock>=o.clock;a=s[c])c-=1+We(s,c)}})},Br=(e,t)=>{if(t<e.length){const n=e[t],i=n.doc,s=i.store,r=n.deleteSet,o=n._mergeStructs;try{ji(r),n.afterState=_n(n.doc.store),i.emit("beforeObserverCalls",[n,i]);const l=[];n.changed.forEach((c,a)=>l.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(n,c)})),l.push(()=>{n.changedParentTypes.forEach((c,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(c=c.filter(u=>u.target._item===null||!u.target._item.deleted),c.forEach(u=>{u.currentTarget=a,u._path=null}),c.sort((u,h)=>u.path.length-h.path.length),l.push(()=>{Mr(a._dEH,c,n)}))}),l.push(()=>i.emit("afterTransaction",[n,i])),l.push(()=>{n._needFormattingCleanup&&jh(n)})}),Ti(l,[])}finally{i.gc&&dh(r,s,i.gcFilter),fh(r,s),n.afterState.forEach((u,h)=>{const f=n.beforeState.get(h)||0;if(f!==u){const p=s.clients.get(h),g=Mt(pt(p,f),1);for(let x=p.length-1;x>=g;)x-=1+We(p,x)}});for(let u=o.length-1;u>=0;u--){const{client:h,clock:f}=o[u].id,p=s.clients.get(h),g=pt(p,f);g+1<p.length&&We(p,g+1)>1||g>0&&We(p,g)}if(!n.local&&n.afterState.get(i.clientID)!==n.beforeState.get(i.clientID)&&(za(Oi,vr,"[yjs] ",Sr,Cr,"Changed the client-id because another client seems to be using it."),i.clientID=Ir()),i.emit("afterTransactionCleanup",[n,i]),i._observers.has("update")){const u=new Xa;ps(u,n)&&i.emit("update",[u.toUint8Array(),n.origin,i,n])}if(i._observers.has("updateV2")){const u=new En;ps(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])):Br(e,t+1)}}},O=(e,t,n=null,i=!0)=>{const s=e._transactionCleanups;let r=!1,o=null;e._transaction===null&&(r=!0,e._transaction=new uh(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&&Br(s,0)}}return o};class ph{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const ms=(e,t,n)=>{Ot(e,n.deletions,i=>{i instanceof M&&t.scope.some(s=>s===e.doc||Ce(s,i))&&$i(i,!1)})},xs=(e,t,n)=>{let i=null;const s=e.doc,r=e.scope;O(s,l=>{for(;t.length>0&&e.currStackItem===null;){const c=s.store,a=t.pop(),u=new Set,h=[];let f=!1;Ot(l,a.insertions,p=>{if(p instanceof M){if(p.redone!==null){let{item:g,diff:x}=di(c,p.id);x>0&&(g=nt(l,_(g.id.client,g.id.clock+x))),p=g}!p.deleted&&r.some(g=>g===l.doc||Ce(g,p))&&h.push(p)}}),Ot(l,a.deletions,p=>{p instanceof M&&r.some(g=>g===l.doc||Ce(g,p))&&!ce(a.insertions,p.id)&&u.add(p)}),u.forEach(p=>{f=no(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 Lr extends qs{constructor(t,{captureTimeout:n=500,captureTransaction:i=c=>!0,deleteFilter:s=()=>!0,trackedOrigins:r=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:l=Qt(t)?t[0].doc:t instanceof Vt?t:t.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(t),this.deleteFilter=s,r.add(this),this.trackedOrigins=r,this.captureTransaction=i,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=n,this.afterTransactionHandler=c=>{if(!this.captureTransaction(c)||!this.scope.some(w=>c.changedParentTypes.has(w)||w===this.doc)||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;const a=this.undoing,u=this.redoing,h=a?this.redoStack:this.undoStack;a?this.stopCapturing():u||this.clear(!1,!0);const f=new le;c.afterState.forEach((w,y)=>{const C=c.beforeState.get(y)||0,k=w-C;k>0&&ve(f,y,C,k)});const p=Rc();let g=!1;if(this.lastChange>0&&p-this.lastChange<this.captureTimeout&&h.length>0&&!a&&!u){const w=h[h.length-1];w.deletions=li([w.deletions,c.deleteSet]),w.insertions=li([w.insertions,f])}else h.push(new ph(c.deleteSet,f)),g=!0;!a&&!u&&(this.lastChange=p),Ot(c,c.deleteSet,w=>{w instanceof M&&this.scope.some(y=>y===c.doc||Ce(y,w))&&$i(w,!0)});const x=[{stackItem:h[h.length-1],origin:c.origin,type:a?"redo":"undo",changedParentTypes:c.changedParentTypes},this];g?this.emit("stack-item-added",x):this.emit("stack-item-updated",x)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){const n=new Set(this.scope);t=Qt(t)?t:[t],t.forEach(i=>{n.has(i)||(n.add(i),(i instanceof q?i.doc!==this.doc:i!==this.doc)&&Er("[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=>ms(i,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>ms(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=xs(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=xs(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*gh(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 at(_(s,r),c),r+=c}else if((mn&l)!==0){const c=(l&(kt|tt))===0,a=new M(_(s,r),null,(l&tt)===tt?e.readLeftID():null,null,(l&kt)===kt?e.readRightID():null,c?e.readParentInfo()?e.readString():e.readLeftID():null,c&&(l&me)===me?e.readString():null,io(e,l));yield a,r+=a.length}else{const c=e.readLen();yield new lt(_(s,r),c),r+=c}}}}class mh{constructor(t,n){this.gen=gh(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===at);return this.curr}}class xh{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const bh=(e,t)=>{if(e.constructor===lt){const{client:n,clock:i}=e.id;return new lt(_(n,i+t),e.length-t)}else if(e.constructor===at){const{client:n,clock:i}=e.id;return new at(_(n,i+t),e.length-t)}else{const n=e,{client:i,clock:s}=n.id;return new M(_(i,s+t),null,_(i,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},bs=(e,t=rn,n=En)=>{if(e.length===1)return e[0];const i=e.map(u=>new t(Ci(u)));let s=i.map(u=>new mh(u,!0)),r=null;const o=new n,l=new xh(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===at?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)fe(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===at)r.struct.length=f.id.clock+f.length-r.struct.id.clock;else{fe(l,r.struct,r.offset);const g=f.id.clock-r.struct.id.clock-r.struct.length;r={struct:new at(_(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===at?r.struct.length-=g:f=bh(f,g)),r.struct.mergeWith(f)||(fe(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!==at;f=u.next())fe(l,r.struct,r.offset),r={struct:f,offset:0}}r!==null&&(fe(l,r.struct,r.offset),r=null),wh(l);const c=i.map(u=>Ga(u)),a=li(c);return Ri(o,a),o.toUint8Array()},Ur=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:ht(e.encoder.restEncoder)}),e.encoder.restEncoder=Ie(),e.written=0)},fe=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Ur(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),I(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},wh=e=>{Ur(e);const t=e.encoder.restEncoder;I(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const i=e.clientStructs[n];I(t,i.written),xn(t,i.restEncoder)}},ws="You must not compute changes after the event-handler fired.";class Tn{constructor(t,n){this.target=t,this.currentTarget=t,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=yh(this.currentTarget,this.target))}deletes(t){return ce(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw wt(ws);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=Un(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Un(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(r))o="delete",l=Un(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 wt(ws);const n=this.target,i=Lt(),s=Lt(),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 yh=(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=()=>{Er("Invalid access: Add Yjs type to a document before reading data.")},Pr=80;let Bi=0;class vh{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=Bi++}}const Sh=e=>{e.timestamp=Bi++},$r=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Bi++},Ch=(e,t,n)=>{if(e.length>=Pr){const i=e.reduce((s,r)=>s.timestamp<r.timestamp?s:r);return $r(i,t,n),i}else{const i=new vh(t,n);return e.push(i),i}},An=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;const n=e._searchMarker.length===0?null:e._searchMarker.reduce((r,o)=>He(t-r.index)<He(t-o.index)?r:o);let i=e._start,s=0;for(n!==null&&(i=n.p,s=n.index,Sh(n));i.right!==null&&s<t;){if(!i.deleted&&i.countable){if(t<s+i.length)break;s+=i.length}i=i.right}for(;i.left!==null&&s>t;)i=i.left,!i.deleted&&i.countable&&(s-=i.length);for(;i.left!==null&&i.left.id.client===i.id.client&&i.left.id.clock+i.left.length===i.id.clock;)i=i.left,!i.deleted&&i.countable&&(s-=i.length);return n!==null&&He(n.index-s)<i.parent.length/Pr?($r(n,i,s),n):Ch(e._searchMarker,i,s)},ke=(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=Mt(t,s.index+n))}},In=(e,t,n)=>{const i=e,s=t.changedParentTypes;for(;_t(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Mr(i._eH,n,t)};class q{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=hs(),this._dEH=hs(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw ct()}clone(){throw ct()}_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){us(this._eH,t)}observeDeep(t){us(this._dEH,t)}unobserve(t){ds(this._eH,t)}unobserveDeep(t){ds(this._dEH,t)}toJSON(){}}const Fr=(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},Vr=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},Hr=(e,t)=>{const n=[];let i=e._start;for(;i!==null;){if(i.countable&&Nt(i,t)){const s=i.content.getContent();for(let r=0;r<s.length;r++)n.push(s[r])}i=i.right}return n},Ee=(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}},zr=(e,t)=>{const n=[];return Ee(e,(i,s)=>{n.push(t(i,s,e))}),n},kh=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}}}},Kr=(e,t)=>{e.doc??X();const n=An(e,t);let i=e._start;for(n!==null&&(i=n.p,t-=n.index);i!==null;i=i.right)if(!i.deleted&&i.countable){if(t<i.length)return i.content.getContent()[t];t-=i.length}},ln=(e,t,n,i)=>{let s=n;const r=e.doc,o=r.clientID,l=r.store,c=n===null?t._start:n.right;let a=[];const u=()=>{a.length>0&&(s=new M(_(o,P(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new $t(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 M(_(o,P(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new Me(new Uint8Array(h))),s.integrate(e,0);break;case Vt:s=new M(_(o,P(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new Oe(h)),s.integrate(e,0);break;default:if(h instanceof q)s=new M(_(o,P(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new mt(h)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),u()},qr=()=>wt("Length exceeded!"),Wr=(e,t,n,i)=>{if(n>t._length)throw qr();if(n===0)return t._searchMarker&&ke(t._searchMarker,n,i.length),ln(e,t,null,i);const s=n,r=An(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&&nt(e,_(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&ke(t._searchMarker,s,i.length),ln(e,t,o,i)},Eh=(e,t,n)=>{let s=(t._searchMarker||[]).reduce((r,o)=>o.index>r.index?o:r,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return ln(e,t,s,n)},Gr=(e,t,n,i)=>{if(i===0)return;const s=n,r=i,o=An(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&&nt(e,_(l.id.client,l.id.clock+n)),n-=l.length);for(;i>0&&l!==null;)l.deleted||(i<l.length&&nt(e,_(l.id.client,l.id.clock+i)),l.delete(e),i-=l.length),l=l.right;if(i>0)throw qr();t._searchMarker&&ke(t._searchMarker,s,-r+i)},cn=(e,t,n)=>{const i=t._map.get(n);i!==void 0&&i.delete(e)},Li=(e,t,n,i)=>{const s=t._map.get(n)||null,r=e.doc,o=r.clientID;let l;if(i==null)l=new $t([i]);else switch(i.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new $t([i]);break;case Uint8Array:l=new Me(i);break;case Vt:l=new Oe(i);break;default:if(i instanceof q)l=new mt(i);else throw new Error("Unexpected content type")}new M(_(o,P(r.store,o)),s,s&&s.lastId,null,null,t,n,l).integrate(e,0)},Ui=(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},Yr=e=>{const t={};return e.doc??X(),e._map.forEach((n,i)=>{n.deleted||(t[i]=n.content.getContent()[n.length-1])}),t},Jr=(e,t)=>{e.doc??X();const n=e._map.get(t);return n!==void 0&&!n.deleted},_h=(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&&Nt(r,t)&&(n[s]=r.content.getContent()[r.length-1])}),n},Ue=e=>(e.doc??X(),Ka(e._map.entries(),t=>!t[1].deleted));class Th extends Tn{}class Xt extends q{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new Xt;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Xt}clone(){const t=new Xt;return t.insert(0,this.toArray().map(n=>n instanceof q?n.clone():n)),t}get length(){return this.doc??X(),this._length}_callObserver(t,n){super._callObserver(t,n),In(this,t,new Th(this,t))}insert(t,n){this.doc!==null?O(this.doc,i=>{Wr(i,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?O(this.doc,n=>{Eh(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?O(this.doc,i=>{Gr(i,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return Kr(this,t)}toArray(){return Vr(this)}slice(t=0,n=this.length){return Fr(this,t,n)}toJSON(){return this.map(t=>t instanceof q?t.toJSON():t)}map(t){return zr(this,t)}forEach(t){Ee(this,t)}[Symbol.iterator](){return kh(this)}_write(t){t.writeTypeRef(Zh)}}const Ah=e=>new Xt;class Ih extends Tn{constructor(t,n,i){super(t,n),this.keysChanged=i}}class se extends q{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach((i,s)=>{this.set(s,i)}),this._prelimContent=null}_copy(){return new se}clone(){const t=new se;return this.forEach((n,i)=>{t.set(i,n instanceof q?n.clone():n)}),t}_callObserver(t,n){In(this,t,new Ih(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 q?s.toJSON():s}}),t}get size(){return[...Ue(this)].length}keys(){return Kn(Ue(this),t=>t[0])}values(){return Kn(Ue(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Kn(Ue(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?O(this.doc,n=>{cn(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?O(this.doc,i=>{Li(i,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return Ui(this,t)}has(t){return Jr(this,t)}clear(){this.doc!==null?O(this.doc,t=>{this.forEach(function(n,i,s){cn(t,s,i)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Qh)}}const Dh=e=>new se,It=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&Vc(e,t);class ui{constructor(t,n,i,s){this.left=t,this.right=n,this.index=i,this.currentAttributes=s}forward(){switch(this.right===null&&Z(),this.right.content.constructor){case F:this.right.deleted||ae(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 ys=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case F:t.right.deleted||ae(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&nt(e,_(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length);break}t.left=t.right,t.right=t.right.right}return t},Pe=(e,t,n,i)=>{const s=new Map,r=i?An(t,n):null;if(r){const o=new ui(r.p.left,r.p,r.index,s);return ys(e,o,n-r.index)}else{const o=new ui(null,t._start,0,s);return ys(e,o,n)}},Xr=(e,t,n,i)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===F&&It(i.get(n.right.content.key),n.right.content.value));)n.right.deleted||i.delete(n.right.content.key),n.forward();const s=e.doc,r=s.clientID;i.forEach((o,l)=>{const c=n.left,a=n.right,u=new M(_(r,P(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()})},ae=(e,t)=>{const{key:n,value:i}=t;i===null?e.delete(n):e.set(n,i)},Zr=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===F&&It(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},Qr=(e,t,n,i)=>{const s=e.doc,r=s.clientID,o=new Map;for(const l in i){const c=i[l],a=n.currentAttributes.get(l)??null;if(!It(a,c)){o.set(l,a);const{left:u,right:h}=n;n.right=new M(_(r,P(s.store,r)),u,u&&u.lastId,h,h&&h.id,t,null,new F(l,c)),n.right.integrate(e,0),n.forward()}}return o},Gn=(e,t,n,i,s)=>{n.currentAttributes.forEach((f,p)=>{s[p]===void 0&&(s[p]=null)});const r=e.doc,o=r.clientID;Zr(n,s);const l=Qr(e,t,n,s),c=i.constructor===String?new gt(i):i instanceof q?new mt(i):new Ht(i);let{left:a,right:u,index:h}=n;t._searchMarker&&ke(t._searchMarker,n.index,c.getLength()),u=new M(_(o,P(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(),Xr(e,t,n,l)},vs=(e,t,n,i,s)=>{const r=e.doc,o=r.clientID;Zr(n,s);const l=Qr(e,t,n,s);t:for(;n.right!==null&&(i>0||l.size>0&&(n.right.deleted||n.right.content.constructor===F));){if(!n.right.deleted)switch(n.right.content.constructor){case F:{const{key:c,value:a}=n.right.content,u=s[c];if(u!==void 0){if(It(u,a))l.delete(c);else{if(i===0)break t;l.set(c,a)}n.right.delete(e)}else n.currentAttributes.set(c,a);break}default:i<n.right.length&&nt(e,_(n.right.id.client,n.right.id.clock+i)),i-=n.right.length;break}n.forward()}if(i>0){let c="";for(;i>0;i--)c+=`
5
- `;n.right=new M(_(o,P(r.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new gt(c)),n.right.integrate(e,0),n.forward()}Xr(e,t,n,l)},to=(e,t,n,i,s)=>{let r=t;const o=dt();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&&ae(s,a);break}}}t=t.right}return l},Mh=(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}},Oh=e=>{let t=0;return O(e.doc,n=>{let i=e._start,s=e._start,r=dt();const o=ti(r);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case F:ae(o,s.content);break;default:t+=to(n,i,s,r,o),r=ti(o),i=s;break}s=s.right}}),t},jh=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&&Nr(e,n.store.clients.get(i),r,s,o=>{!o.deleted&&o.content.constructor===F&&o.constructor!==lt&&t.add(o.parent)})}O(n,i=>{Ot(e,e.deleteSet,s=>{if(s instanceof lt||!s.parent._hasFormatting||t.has(s.parent))return;const r=s.parent;s.content.constructor===F?t.add(r):Mh(i,s)});for(const s of t)Oh(s)})},Ss=(e,t,n)=>{const i=n,s=ti(t.currentAttributes),r=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case mt:case Ht:case gt:n<t.right.length&&nt(e,_(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}r&&to(e,r,t.right,s,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&ke(o._searchMarker,t.index,-i+n),t};class Rh extends Tn{constructor(t,n,i){super(t,n),this.childListChanged=!1,this.keysChanged=new Set,i.forEach(s=>{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}get changes(){if(this._changes===null){const t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){const t=this.target.doc,n=[];O(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},Fc(c)||(p.attributes=Pc({},c))),u=0;break}p&&n.push(p),l=null}};for(;o!==null;){switch(o.content.constructor){case mt:case Ht: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 gt:this.adds(o)?this.deletes(o)||(l!=="insert"&&(f(),l="insert"),a+=o.content.str):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),h+=o.length):o.deleted||(l!=="retain"&&(f(),l="retain"),u+=o.length);break;case F:{const{key:p,value:g}=o.content;if(this.adds(o)){if(!this.deletes(o)){const x=s.get(p)??null;It(x,g)?g!==null&&o.delete(i):(l==="retain"&&f(),It(g,r.get(p)??null)?delete c[p]:c[p]=g)}}else if(this.deletes(o)){r.set(p,g);const x=s.get(p)??null;It(x,g)||(l==="retain"&&f(),c[p]=x)}else if(!o.deleted){r.set(p,g);const x=c[p];x!==void 0&&(It(x,g)?x!==null&&o.delete(i):(l==="retain"&&f(),g===null?delete c[p]:c[p]=g))}o.deleted||(l==="insert"&&f(),ae(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 jt extends q{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 jt}clone(){const t=new jt;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const i=new Rh(this,t,n);In(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===gt&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){this.doc!==null?O(this.doc,i=>{const s=new ui(null,this._start,0,new Map);for(let r=0;r<t.length;r++){const o=t[r];if(o.insert!==void 0){const l=!n&&typeof o.insert=="string"&&r===t.length-1&&s.right===null&&o.insert.slice(-1)===`
6
- `?o.insert.slice(0,-1):o.insert;(typeof l!="string"||l.length>0)&&Gn(i,this,s,l,o.attributes||{})}else o.retain!==void 0?vs(i,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&Ss(i,s,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,i){this.doc??X();const s=[],r=new Map,o=this.doc;let l="",c=this._start;function a(){if(l.length>0){const h={};let f=!1;r.forEach((g,x)=>{f=!0,h[x]=g});const p={insert:l};f&&(p.attributes=h),s.push(p),l=""}}const u=()=>{for(;c!==null;){if(Nt(c,t)||n!==void 0&&Nt(c,n))switch(c.content.constructor){case gt:{const h=r.get("ychange");t!==void 0&&!Nt(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&&!Nt(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 mt:case Ht:{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:Nt(c,t)&&(a(),ae(r,c.content));break}c=c.right}a()};return t||n?O(o,h=>{t&&ai(h,t),n&&ai(h,n),u()},"cleanup"):u(),s}insert(t,n,i){if(n.length<=0)return;const s=this.doc;s!==null?O(s,r=>{const o=Pe(r,this,t,!i);i||(i={},o.currentAttributes.forEach((l,c)=>{i[c]=l})),Gn(r,this,o,n,i)}):this._pending.push(()=>this.insert(t,n,i))}insertEmbed(t,n,i){const s=this.doc;s!==null?O(s,r=>{const o=Pe(r,this,t,!i);Gn(r,this,o,n,i||{})}):this._pending.push(()=>this.insertEmbed(t,n,i||{}))}delete(t,n){if(n===0)return;const i=this.doc;i!==null?O(i,s=>{Ss(s,Pe(s,this,t,!0),n)}):this._pending.push(()=>this.delete(t,n))}format(t,n,i){if(n===0)return;const s=this.doc;s!==null?O(s,r=>{const o=Pe(r,this,t,!1);o.right!==null&&vs(r,this,o,n,i)}):this._pending.push(()=>this.format(t,n,i))}removeAttribute(t){this.doc!==null?O(this.doc,n=>{cn(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?O(this.doc,i=>{Li(i,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return Ui(this,t)}getAttributes(){return Yr(this)}_write(t){t.writeTypeRef(tu)}}const Nh=e=>new jt;class Yn{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??X()}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(n)))do if(n=t.content.type,!t.deleted&&(n.constructor===J||n.constructor===Pt)&&n._start!==null)t=n._start;else for(;t!==null;){const i=t.next;if(i!==null){t=i;break}else t.parent===this._root?t=null:t=t.parent._item}while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class Pt extends q{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Pt}clone(){const t=new Pt;return t.insert(0,this.toArray().map(n=>n instanceof q?n.clone():n)),t}get length(){return this.doc??X(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Yn(this,t)}querySelector(t){t=t.toUpperCase();const i=new Yn(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return i.done?null:i.value}querySelectorAll(t){return t=t.toUpperCase(),Ut(new Yn(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){In(this,t,new Uh(this,n,t))}toString(){return zr(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),Ee(this,r=>{s.insertBefore(r.toDOM(t,n,i),null)}),s}insert(t,n){this.doc!==null?O(this.doc,i=>{Wr(i,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)O(this.doc,i=>{const s=t&&t instanceof q?t._item:t;ln(i,this,s,n)});else{const i=this._prelimContent,s=t===null?0:i.findIndex(r=>r===t)+1;if(s===0&&t!==null)throw wt("Reference item not found");i.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?O(this.doc,i=>{Gr(i,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return Vr(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Kr(this,t)}slice(t=0,n=this.length){return Fr(this,t,n)}forEach(t){Ee(this,t)}_write(t){t.writeTypeRef(nu)}}const Bh=e=>new Pt;class J extends Pt{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach((i,s)=>{this.setAttribute(s,i)}),this._prelimAttrs=null}_copy(){return new J(this.nodeName)}clone(){const t=new J(this.nodeName),n=this.getAttributes();return $c(n,(i,s)=>{t.setAttribute(s,i)}),t.insert(0,this.toArray().map(i=>i instanceof q?i.clone():i)),t}toString(){const t=this.getAttributes(),n=[],i=[];for(const l in t)i.push(l);i.sort();const s=i.length;for(let l=0;l<s;l++){const c=i[l];n.push(c+'="'+t[c]+'"')}const r=this.nodeName.toLocaleLowerCase(),o=n.length>0?" "+n.join(" "):"";return`<${r}${o}>${super.toString()}</${r}>`}removeAttribute(t){this.doc!==null?O(this.doc,n=>{cn(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?O(this.doc,i=>{Li(i,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return Ui(this,t)}hasAttribute(t){return Jr(this,t)}getAttributes(t){return t?_h(this,t):Yr(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 Ee(this,o=>{s.appendChild(o.toDOM(t,n,i))}),i!==void 0&&i._createAssociation(s,this),s}_write(t){t.writeTypeRef(eu),t.writeKey(this.nodeName)}}const Lh=e=>new J(e.readKey());class Uh extends Tn{constructor(t,n,i){super(t,i),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}}class an extends se{constructor(t){super(),this.hookName=t}_copy(){return new an(this.hookName)}clone(){const t=new an(this.hookName);return this.forEach((n,i)=>{t.set(i,n)}),t}toDOM(t=document,n={},i){const s=n[this.hookName];let r;return s!==void 0?r=s.createDom(this):r=document.createElement(this.hookName),r.setAttribute("data-yjs-hook",this.hookName),i!==void 0&&i._createAssociation(r,this),r}_write(t){t.writeTypeRef(iu),t.writeKey(this.hookName)}}const Ph=e=>new an(e.readKey());class it extends jt{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 it}clone(){const t=new it;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(su)}}const $h=e=>new it;class Pi{constructor(t,n){this.id=t,this.length=n}get deleted(){throw ct()}mergeWith(t){return!1}write(t,n,i){throw ct()}integrate(t,n){throw ct()}}const Fh=0;class lt extends Pi{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),Rr(t.doc.store,this)}write(t,n){t.writeInfo(Fh),t.writeLen(this.length-n)}getMissing(t,n){return null}}class Me{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Me(this.content)}splice(t){throw ct()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}const Vh=e=>new Me(e.readBuf());class _e{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new _e(this.len)}splice(t){const n=new _e(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){ve(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 Hh=e=>new _e(e.readLen()),eo=(e,t)=>new Vt({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Oe{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 Oe(eo(this.doc.guid,this.opts))}splice(t){throw ct()}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 zh=e=>new Oe(eo(e.readString(),e.readAny()));class Ht{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Ht(this.embed)}splice(t){throw ct()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}const Kh=e=>new Ht(e.readJSON());class F{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new F(this.key,this.value)}splice(t){throw ct()}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 qh=e=>new F(e.readKey(),e.readJSON());class hn{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new hn(this.arr)}splice(t){const n=new hn(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const i=this.arr.length;t.writeLen(i-n);for(let s=n;s<i;s++){const r=this.arr[s];t.writeString(r===void 0?"undefined":JSON.stringify(r))}}getRef(){return 2}}const Wh=e=>{const t=e.readLen(),n=[];for(let i=0;i<t;i++){const s=e.readString();s==="undefined"?n.push(void 0):n.push(JSON.parse(s))}return new hn(n)},Gh=tn("node_env")==="development";class $t{constructor(t){this.arr=t,Gh&&er(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new $t(this.arr)}splice(t){const n=new $t(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 Yh=e=>{const t=e.readLen(),n=[];for(let i=0;i<t;i++)n.push(e.readAny());return new $t(n)};class gt{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new gt(this.str)}splice(t){const n=new gt(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 Jh=e=>new gt(e.readString()),Xh=[Ah,Dh,Nh,Lh,Bh,Ph,$h],Zh=0,Qh=1,tu=2,eu=3,nu=4,iu=5,su=6;class mt{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new mt(this.type._copy())}splice(t){throw ct()}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 ru=e=>new mt(Xh[e.readTypeRef()](e)),di=(e,t)=>{let n=t,i=0,s;do i>0&&(n=_(n.client,n.clock+i)),s=Jt(e,n),i=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof M);return{item:s,diff:i}},$i=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},un=(e,t,n)=>{const{client:i,clock:s}=t.id,r=new M(_(i,s+n),t,_(i,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&r.markDeleted(),t.keep&&(r.keep=!0),t.redone!==null&&(r.redone=_(t.redone.client,t.redone.clock+n)),t.right=r,r.right!==null&&(r.right.left=r),e._mergeStructs.push(r),r.parentSub!==null&&r.right===null&&r.parent._map.set(r.parentSub,r),t.length=n,r},Cs=(e,t)=>yi(e,n=>ce(n.deletions,t)),no=(e,t,n,i,s,r)=>{const o=e.doc,l=o.store,c=o.clientID,a=t.redone;if(a!==null)return nt(e,a);let u=t.parent._item,h=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||no(e,u,n,i,s,r)===null))return null;for(;u.redone!==null;)u=nt(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:nt(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:nt(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||ce(i,h.right.id)||Cs(r.undoStack,h.right.id)||Cs(r.redoStack,h.right.id));)for(h=h.right;h.redone;)h=nt(e,h.redone);if(h&&h.right!==null)return null}else h=p._map.get(t.parentSub)||null;const g=P(l,c),x=_(c,g),w=new M(x,h,h&&h.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=x,$i(w,!0),w.integrate(e,0),w};class M extends Pi{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()?Xi:0}set marker(t){(this.info&$n)>0!==t&&(this.info^=$n)}get marker(){return(this.info&$n)>0}get keep(){return(this.info&Ji)>0}set keep(t){this.keep!==t&&(this.info^=Ji)}get countable(){return(this.info&Xi)>0}get deleted(){return(this.info&Pn)>0}set deleted(t){this.deleted!==t&&(this.info^=Pn)}markDeleted(){this.info|=Pn}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=P(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=P(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Yt&&this.id.client!==this.parent.client&&this.parent.clock>=P(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=fs(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=nt(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===lt||this.right&&this.right.constructor===lt)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===M?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===M&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Yt){const i=Jt(n,this.parent);i.constructor===lt?this.parent=null:this.parent=i.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=fs(t,t.doc.store,_(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let i=this.left,s;if(i!==null)s=i.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;const r=new Set,o=new Set;for(;s!==null&&s!==this.right;){if(o.add(s),r.add(s),Be(this.origin,s.origin)){if(s.id.client<this.id.client)i=s,r.clear();else if(Be(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&o.has(Jt(t.doc.store,s.origin)))r.has(Jt(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),Rr(t.doc.store,this),this.content.integrate(t,this),gs(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new lt(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;t!==null&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;t!==null&&t.deleted;)t=t.left;return t}get lastId(){return this.length===1?this.id:_(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Be(t.origin,this.lastId)&&this.right===t&&Be(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const n=this.parent._searchMarker;return n&&n.forEach(i=>{i.p===t&&(i.p=this,!this.deleted&&this.countable&&(i.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),ve(t.deleteSet,this.id.client,this.id.clock,this.length),gs(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw Z();this.content.gc(t),n?hh(t,this,new lt(this.id,this.length)):this.content=new _e(this.length)}write(t,n){const i=n>0?_(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,r=this.parentSub,o=this.content.getRef()&mn|(i===null?0:tt)|(s===null?0:kt)|(r===null?0:me);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=Se(l);t.writeParentInfo(!0),t.writeString(a)}else t.writeParentInfo(!1),t.writeLeftID(c.id)}else l.constructor===String?(t.writeParentInfo(!0),t.writeString(l)):l.constructor===Yt?(t.writeParentInfo(!1),t.writeLeftID(l)):Z();r!==null&&t.writeString(r)}this.content.write(t,n)}}const io=(e,t)=>ou[t&mn](e),ou=[()=>{Z()},Hh,Wh,Vh,Jh,Kh,qh,ru,Yh,zh,()=>{Z()}],lu=10;class at extends Pi{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){Z()}write(t,n){t.writeInfo(lu),I(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const so=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},ro="__ $YJS$ __";so[ro]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");so[ro]=!0;const cu=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},au=/[\uD800-\uDBFF]/,hu=/[\uDC00-\uDFFF]/,uu=(e,t)=>{let n=0,i=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&au.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&&hu.test(e[e.length-i])&&i--,{index:n,remove:e.length-n-i,insert:t.slice(n,t.length-i)}},du=uu,bt=(e,t)=>e>>>t|e<<32-t,fu=e=>bt(e,2)^bt(e,13)^bt(e,22),pu=e=>bt(e,6)^bt(e,11)^bt(e,25),gu=e=>bt(e,7)^bt(e,18)^e>>>3,mu=e=>bt(e,17)^bt(e,19)^e>>>10,xu=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]),bu=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class wu{constructor(){const t=new ArrayBuffer(320);this._H=new Uint32Array(t,0,8),this._H.set(bu),this._W=new Uint32Array(t,64,64)}_updateHash(){const t=this._H,n=this._W;for(let h=16;h<64;h++)n[h]=mu(n[h-2])+n[h-7]+gu(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+pu(l)+(l&c^~l&a)+xu[h]+n[h]>>>0,p=fu(i)+(i&s^i&r^s&r)>>>0,u=a,a=c,c=l,l=o+f>>>0,o=r,r=s,s=i,i=f+p>>>0;t[0]+=i,t[1]+=s,t[2]+=r,t[3]+=o,t[4]+=l,t[5]+=c,t[6]+=a,t[7]+=u}digest(t){let n=0;for(;n+56<=t.length;){let o=0;for(;o<16&&n+3<t.length;o++)this._W[o]=t[n++]<<24|t[n++]<<16|t[n++]<<8|t[n++];if(n%64!==0){for(this._W.fill(0,o,16);n<t.length;)this._W[o]|=t[n]<<(3-n%4)*8,n++;this._W[o]|=tt<<(3-n%4)*8}this._updateHash()}const i=n%64!==0;this._W.fill(0,0,16);let s=0;for(;n<t.length;s++)for(let o=3;o>=0&&n<t.length;o--)this._W[s]|=t[n++]<<o*8;i||(this._W[s-(n%4===0?0:1)]|=tt<<(3-n%4)*8),this._W[14]=t.byteLength/Zl,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 yu=e=>new wu().digest(e),R=new T.PluginKey("y-sync"),Et=new T.PluginKey("y-undo");new T.PluginKey("yjs-cursor");const vu=e=>{for(let n=6;n<e.length;n++)e[n%6]=e[n%6]^e[n];return e.slice(0,6)},Su=e=>Xc(vu(yu(Zc(e)))),dn=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!ce(t.ds,e.id),Cu=[{light:"#ecd44433",dark:"#ecd444"}],ku=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){const i=Lt();e.forEach(s=>i.add(s)),t=t.filter(s=>!i.has(s))}e.set(n,Mc(t))}return e.get(n)},Eu=(e,{colors:t=Cu,colorMapping:n=new Map,permanentUserData:i=null,onFirstRender:s=()=>{},mapping:r}={})=>{let o=!1;const l=new Au(e,r),c=new T.Plugin({props:{editable:a=>{const u=R.getState(a);return u.snapshot==null&&u.prevSnapshot==null}},key:R,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(R);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)&&yr(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=Et.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)},R)})}},destroy:()=>{l.destroy()}})});return c},_u=(e,t,n)=>{if(t!==null&&t.anchor!==null&&t.head!==null)if(t.type==="all")e.setSelection(new T.AllSelection(e.doc));else if(t.type==="node"){const i=ge(n.doc,n.type,t.anchor,n.mapping);e.setSelection(Tu(e,i))}else{const i=ge(n.doc,n.type,t.anchor,n.mapping),s=ge(n.doc,n.type,t.head,n.mapping);i!==null&&s!==null&&e.setSelection(T.TextSelection.between(e.doc.resolve(i),e.doc.resolve(s)))}},Tu=(e,t)=>{const n=e.doc.resolve(t);return n.nodeAfter?T.NodeSelection.create(e.doc,t):T.TextSelection.near(n)},fi=(e,t)=>({type:t.selection.jsonID,anchor:pn(t.selection.anchor,e.type,e.mapping),head:pn(t.selection.head,e.type,e.mapping)});class Au{constructor(t,n=new Map){this.type=t,this.prosemirrorView=null,this.mux=cu(),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=fi(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()?(nr&&this._domSelectionInView===null&&(yr(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=De.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=Or(Ar(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(R,{snapshot:t,prevSnapshot:n}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{const t=this.type.toArray().map(i=>Ge(i,this.prosemirrorView.state.schema,this)).filter(i=>i!==null),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new T.Slice(T.Fragment.from(t),0,0));n.setMeta(R,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(n)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{const t=this.beforeTransactionSelection!==null?null:this.prosemirrorView.state.selection,n=this.type.toArray().map(s=>Ge(s,this.prosemirrorView.state.schema,this)).filter(s=>s!==null),i=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new T.Slice(T.Fragment.from(n),0,0));if(t){const s=te(Mt(t.anchor,0),i.doc.content.size),r=te(Mt(t.head,0),i.doc.content.size);i.setSelection(T.TextSelection.create(i.doc,s,r))}this.prosemirrorView.dispatch(i.setMeta(R,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(t,n,i){let s=this.doc,r=this.type;if(t||(t=Wn(this.doc)),t instanceof Uint8Array||n instanceof Uint8Array)if((!(t instanceof Uint8Array)||!(n instanceof Uint8Array))&&Z(),s=new Vt({gc:!1}),ci(s,n),n=Wn(s),ci(s,t),t=Wn(s),r._item===null){const o=Array.from(this.doc.share.keys()).find(l=>this.doc.share.get(l)===this.type);r=s.getXmlFragment(o)}else{const o=s.store.clients.get(r._item.id.client)??[],l=pt(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=>{Ot(o,h,f=>{})});const c=(h,f)=>{const p=h==="added"?l.getUserByClientId(f.client):l.getUserByDeletedId(f);return{user:p,type:h,color:ku(i.colorMapping,i.colors,p)}},a=Hr(r,new Ni(n.ds,t.sv)).map(h=>!h._item.deleted||dn(h._item,t)||dn(h._item,n)?Ge(h,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},t,n,c):null).filter(h=>h!==null),u=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new T.Slice(T.Fragment.from(a),0,0));this.prosemirrorView.dispatch(u.setMeta(R,{isChangeOrigin:!0}))},R)})}_typeChanged(t,n){if(this.prosemirrorView==null)return;const i=R.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);Ot(n,n.deleteSet,l=>{if(l.constructor===M){const c=l.content.type;c&&this.mapping.delete(c)}}),n.changed.forEach(s),n.changedParentTypes.forEach(s);const r=this.type.toArray().map(l=>oo(l,this.prosemirrorView.state.schema,this)).filter(l=>l!==null);let o=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new T.Slice(T.Fragment.from(r),0,0));_u(o,this.beforeTransactionSelection,this),o=o.setMeta(R,{isChangeOrigin:!0,isUndoRedoOperation:n.origin instanceof Lr}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)})}_prosemirrorChanged(t){this.doc.transact(()=>{gi(this.doc,this.type,t,this),this.beforeTransactionSelection=fi(this,this.prosemirrorView.state)},R)}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 oo=(e,t,n,i,s,r)=>{const o=n.mapping.get(e);if(o===void 0){if(e instanceof J)return Ge(e,t,n,i,s,r);throw ct()}return o},Ge=(e,t,n,i,s,r)=>{const o=[],l=c=>{var a,u;if(c instanceof J){const h=oo(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 jt&&!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=Iu(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):Hr(e,new Ni(s.ds,i.sv)).forEach(l);try{const c=e.getAttributes(i);i!==void 0&&(dn(e._item,i)?dn(e._item,s)||(c.ychange=r?r("added",e._item.id):{type:"added"}):c.ychange=r?r("removed",e._item.id):{type:"removed"});const a=t.node(e.nodeName,c,o);return n.mapping.set(e,a),a}catch{return e.doc.transact(a=>{e._item.delete(a)},R),n.mapping.delete(e),null}},Iu=(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,Nu(a.attributes,t)))}}catch{return e.doc.transact(a=>{e._item.delete(a)},R),null}return o},Du=(e,t)=>{const n=new it,i=e.map(s=>({insert:s.text,attributes:co(s.marks,t)}));return n.applyDelta(i),t.mapping.set(n,e),n},Mu=(e,t)=>{const n=new J(e.type.name);for(const i in e.attrs){const s=e.attrs[i];s!==null&&i!=="ychange"&&n.setAttribute(i,s)}return n.insert(0,Dn(e).map(i=>pi(i,t))),t.mapping.set(n,e),n},pi=(e,t)=>e instanceof Array?Du(e,t):Mu(e,t),ks=e=>typeof e=="object"&&e!==null,Fi=(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||ks(o)&&ks(l)&&Fi(o,l)}return i},Dn=e=>{const t=e.content.content,n=[];for(let i=0;i<t.length;i++){const s=t[i];if(s.isText){const 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},lo=(e,t)=>{const n=e.toDelta();return n.length===t.length&&n.every((i,s)=>i.insert===t[s].text&&tr(i.attributes||{}).length===t[s].marks.length&&re(i.attributes,(r,o)=>{var u;const l=Vi(o),c=t[s].marks;return c.find(h=>h.type.name===l)?Fi(r,(u=c.find(h=>h.type.name===l))==null?void 0:u.attrs):!1}))},Te=(e,t)=>{if(e instanceof J&&!(t instanceof Array)&&mi(e,t)){const n=Dn(t);return e._length===n.length&&Fi(e.getAttributes(),t.attrs)&&e.toArray().every((i,s)=>Te(i,n[s]))}return e instanceof it&&t instanceof Array&&lo(e,t)},fn=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((n,i)=>t[i]===n),Es=(e,t,n)=>{const i=e.toArray(),s=Dn(t),r=s.length,o=i.length,l=te(o,r);let c=0,a=0,u=!1;for(;c<l;c++){const h=i[c],f=s[c];if(fn(n.mapping.get(h),f))u=!0;else if(!Te(h,f))break}for(;c+a<l;a++){const h=i[o-a-1],f=s[r-a-1];if(fn(n.mapping.get(h),f))u=!0;else if(!Te(h,f))break}return{equalityFactor:c+a,foundMappedChild:u}},Ou=e=>{let t="",n=e._start;const i={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof gt?t+=n.content.str:n.content instanceof F&&(i[n.content.key]=null)),n=n.right;return{str:t,nAttrs:i}},ju=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:i,str:s}=Ou(e),r=t.map(a=>({insert:a.text,attributes:Object.assign({},i,co(a.marks,n))})),{insert:o,remove:l,index:c}=du(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})))},Ru=/(.*)(--[a-zA-Z0-9+/=]{8})$/,Vi=e=>{var t;return((t=Ru.exec(e))==null?void 0:t[1])??e},Nu=(e,t)=>{const n=[];for(const i in e)n.push(t.mark(Vi(i),e[i]));return n},co=(e,t)=>{const n={};return e.forEach(i=>{if(i.type.name!=="ychange"){const s=_t(t.isOMark,i.type,()=>!i.type.excludes(i.type));n[s?`${i.type.name}--${Su(i.toJSON())}`:i.type.name]=i.attrs}}),n},gi=(e,t,n,i)=>{if(t instanceof J&&t.nodeName!==n.type.name)throw new Error("node name mismatch!");if(i.mapping.set(t,n),t instanceof J){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=Dn(n),r=s.length,o=t.toArray(),l=o.length,c=te(r,l);let a=0,u=0;for(;a<c;a++){const h=o[a],f=s[a];if(!fn(i.mapping.get(h),f))if(Te(h,f))i.mapping.set(h,f);else break}for(;u+a+1<c;u++){const h=o[l-u-1],f=s[r-u-1];if(!fn(i.mapping.get(h),f))if(Te(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 it&&p instanceof Array)lo(f,p)||ju(f,p,i),a+=1;else{let w=f instanceof J&&mi(f,p),y=g instanceof J&&mi(g,x);if(w&&y){const C=Es(f,p,i),k=Es(g,x,i);C.foundMappedChild&&!k.foundMappedChild?y=!1:!C.foundMappedChild&&k.foundMappedChild||C.equalityFactor<k.equalityFactor?w=!1:y=!1}w?(gi(e,f,p,i),a+=1):y?(gi(e,g,x,i),u+=1):(i.mapping.delete(t.get(a)),t.delete(a,1),t.insert(a,[pi(p,i)]),a+=1)}}const h=l-a-u;if(l===1&&r===0&&o[0]instanceof it?(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(pi(s[p],i));t.insert(a,f)}},R)},mi=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,pn=(e,t,n)=>{if(e===0)return qn(t,0,-1);let i=t._first===null?null:t._first.content.type;for(;i!==null&&t!==i;){if(i instanceof it){if(i._length>=e)return qn(i,e,-1);if(e-=i._length,i._item!==null&&i._item.next!==null)i=i._item.next.content.type;else{do i=i._item===null?null:i._item.parent,e--;while(i!==t&&i!==null&&i._item!==null&&i._item.next===null);i!==null&&i!==t&&(i=i._item===null?null:i._item.next.content.type)}}else{const s=(n.get(i)||{nodeSize:0}).nodeSize;if(i._first!==null&&e<s)i=i._first.content.type,e--;else{if(e===1&&i._length===0&&s>1)return new on(i._item===null?null:i._item.id,i._item===null?Se(i):null,null);if(e-=s,i._item!==null&&i._item.next!==null)i=i._item.next.content.type;else{if(e===0)return i=i._item===null?i:i._item.parent,new on(i._item===null?null:i._item.id,i._item===null?Se(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 Z();if(e===0&&i.constructor!==it&&i!==t)return Bu(i._item.parent,i._item)}return qn(t,t._length,-1)},Bu=(e,t)=>{let n=null,i=null;return e._item===null?i=Se(e):n=_(e._item.id.client,e._item.id.clock),new on(n,i,t.id)},ge=(e,t,n,i)=>{const s=ch(n,e);if(s===null||s.type!==t&&!Ce(t,s.type._item))return null;let r=s.type,o=0;if(r.constructor===it)o=s.index;else if(r._item===null||!r._item.deleted){let l=r._first,c=0;for(;c<r._length&&c<s.index&&l!==null;){if(!l.deleted){const a=l.content.type;c++,a instanceof it?o+=a._length:o+=i.get(a).nodeSize}l=l.right}o+=1}for(;r!==t&&r._item!==null;){const l=r._item.parent;if(l._item===null||!l._item.deleted){o+=1;let c=l._first;for(;c!==null;){const a=c.content.type;if(a===r)break;c.deleted||(a instanceof it?o+=a._length:o+=i.get(a).nodeSize),c=c.right}}r=l}return o-1};function Lu(e){const t=e.toArray(),n=i=>{let s;if(i instanceof it)s=i.toDelta().map(o=>{const l={type:"text",text:o.insert};return o.attributes&&(l.marks=Object.keys(o.attributes).map(c=>{const a=o.attributes[c],h={type:Vi(c)};return Object.keys(a)&&(h.attrs=a),h})),l});else if(i instanceof J){s={type:i.nodeName};const r=i.getAttributes();Object.keys(r).length&&(s.attrs=r);const o=i.toArray();o.length&&(s.content=o.map(n).flat())}else Z();return s};return{type:"doc",content:t.map(n)}}const Uu=e=>{const t=Et.getState(e).undoManager;if(t!=null)return t.undo(),!0},Pu=e=>{const t=Et.getState(e).undoManager;if(t!=null)return t.redo(),!0},$u=new Set(["paragraph"]),Fu=(e,t)=>!(e instanceof M)||!(e.content instanceof mt)||!(e.content.type instanceof jt||e.content.type instanceof J&&t.has(e.content.type.nodeName))||e.content.type._length===0,Vu=({protectedNodes:e=$u,trackedOrigins:t=[],undoManager:n=null}={})=>new T.Plugin({key:Et,state:{init:(i,s)=>{const r=R.getState(s),o=n||new Lr(r.type,{trackedOrigins:new Set([R].concat(t)),deleteFilter:l=>Fu(l,e),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(i,s,r,o)=>{const l=R.getState(o).binding,c=s.undoManager,a=c.undoStack.length>0,u=c.redoStack.length>0;return l?{undoManager:c,prevSel:fi(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=R.getState(i.state),r=Et.getState(i.state).undoManager;return r.on("stack-item-added",({stackItem:o})=>{const l=s.binding;l&&o.meta.set(l,Et.getState(i.state).prevSel)}),r.on("stack-item-popped",({stackItem:o})=>{const l=s.binding;l&&(l.beforeTransactionSelection=o.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{r.destroy()}}}});function ao(e){return!!e.getMeta(R)}function Hu(e,t){const n=R.getState(e);return ge(n.doc,n.type,t,n.binding.mapping)||0}function ho(e,t){const n=R.getState(e);return pn(t,n.type,n.binding.mapping)}var Ye=class uo extends T.MappablePosition{constructor(t,n){super(t),this.yRelativePosition=n}static fromJSON(t){return new uo(t.position,t.yRelativePosition)}toJSON(){return{position:this.position,yRelativePosition:this.yRelativePosition}}};function zu(e,t){const n=ho(t,e);return new Ye(e,n)}function Ku(e,t,n){const i=e instanceof Ye?e.yRelativePosition:null;if(ao(t)&&i){const o=Hu(n,i);return{position:new Ye(o,i),mapResult:null}}const s=T.getUpdatedPosition(e,t),r=s.position.position;return{position:new Ye(r,i??ho(n,r)),mapResult:s.mapResult}}T.Extension.create({name:"collaboration",priority:1e3,addOptions(){return{document:null,field:"default",fragment:null,provider:null}},addStorage(){return{isDisabled:!1}},onCreate(){this.editor.extensionManager.extensions.find(e=>e.name==="undoRedo")&&console.warn('[tiptap warn]: "@tiptap/extension-collaboration" comes with its own history support and is not compatible with "@tiptap/extension-undo-redo".')},onBeforeCreate(){this.editor.utils.getUpdatedPosition=(e,t)=>Ku(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>zu(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),Et.getState(t).undoManager.undoStack.length===0?!1:n?Uu(t):!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),Et.getState(t).undoManager.redoStack.length===0?!1:n?Pu(t):!0)}},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo()}},addProseMirrorPlugins(){var e;const t=this.options.fragment?this.options.fragment:this.options.document.getXmlFragment(this.options.field),n=Vu(this.options.yUndoOptions),i=n.spec.view;n.spec.view=o=>{const{undoManager:l}=Et.getState(o.state);l.restore&&(l.restore(),l.restore=()=>{});const c=i?i(o):void 0;return{destroy:()=>{const a=l.trackedOrigins.has(l),u=l._observers;l.restore=()=>{a&&l.trackedOrigins.add(l),l.doc.on("afterTransaction",l.afterTransactionHandler),l._observers=u},c!=null&&c.destroy&&c.destroy()}}};const s={...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender},r=Eu(t,s);return this.editor.options.enableContentCheck&&((e=t.doc)==null||e.on("beforeTransaction",()=>{try{const o=Lu(t);if(o.content.length===0)return;this.editor.schema.nodeFromJSON(o).check()}catch(o){return this.editor.emit("contentError",{error:o,editor:this.editor,disableCollaboration:()=>{var l;(l=t.doc)==null||l.destroy(),this.storage.isDisabled=!0}}),!1}})),[r,n,this.editor.options.enableContentCheck&&new W.Plugin({key:new W.PluginKey("filterInvalidContent"),filterTransaction:()=>{var o;return this.storage.isDisabled!==!1&&((o=t.doc)==null||o.destroy()),!0}})].filter(Boolean)}});function _s(e){if(!e.length)return Nn.DecorationSet.empty;const t=[],n=e[0].$from.node(0);return e.forEach(i=>{const s=i.$from.pos,r=i.$from.nodeAfter;r&&t.push(Nn.Decoration.node(s,s+r.nodeSize,{class:"ProseMirror-selectednoderange"}))}),Nn.DecorationSet.create(n,t)}function Mn(e,t,n){const i=[],s=e.node(0);typeof n=="number"&&n>=0||(e.sameParent(t)?n=Math.max(0,e.sharedDepth(t.pos)-1):n=e.sharedDepth(t.pos));const r=new Do.NodeRange(e,t,n),o=r.depth===0?0:s.resolve(r.start).posAtIndex(0);return r.parent.forEach((l,c)=>{const a=o+c,u=a+l.nodeSize;if(a<r.start||a>=r.end)return;const h=new W.SelectionRange(s.resolve(a),s.resolve(u));i.push(h)}),i}var qu=class fo{constructor(t,n){this.anchor=t,this.head=n}map(t){return new fo(t.map(this.anchor),t.map(this.head))}resolve(t){const n=t.resolve(this.anchor),i=t.resolve(this.head);return new Dt(n,i)}},Dt=class At extends W.Selection{constructor(t,n,i,s=1){const{doc:r}=t,o=t===n,l=t.pos===r.content.size&&n.pos===r.content.size,c=o&&!l?r.resolve(n.pos+(s>0?1:-1)):n,a=o&&l?r.resolve(t.pos-(s>0?1:-1)):t,u=Mn(a.min(c),a.max(c),i),h=c.pos>=t.pos?u[0].$from:u[u.length-1].$to,f=c.pos>=t.pos?u[u.length-1].$to:u[0].$from;super(h,f,u),this.depth=i}get $to(){return this.ranges[this.ranges.length-1].$to}eq(t){return t instanceof At&&t.$from.pos===this.$from.pos&&t.$to.pos===this.$to.pos}map(t,n){const i=t.resolve(n.map(this.anchor)),s=t.resolve(n.map(this.head));return new At(i,s)}toJSON(){return{type:"nodeRange",anchor:this.anchor,head:this.head}}get isForwards(){return this.head>=this.anchor}get isBackwards(){return!this.isForwards}extendBackwards(){const{doc:t}=this.$from;if(this.isForwards&&this.ranges.length>1){const s=this.ranges.slice(0,-1),r=s[0].$from,o=s[s.length-1].$to;return new At(r,o,this.depth)}const n=this.ranges[0],i=t.resolve(Math.max(0,n.$from.pos-1));return new At(this.$anchor,i,this.depth)}extendForwards(){const{doc:t}=this.$from;if(this.isBackwards&&this.ranges.length>1){const s=this.ranges.slice(1),r=s[0].$from,o=s[s.length-1].$to;return new At(o,r,this.depth)}const n=this.ranges[this.ranges.length-1],i=t.resolve(Math.min(t.content.size,n.$to.pos+1));return new At(this.$anchor,i,this.depth)}static fromJSON(t,n){return new At(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,i,s,r=1){return new this(t.resolve(n),t.resolve(i),s,r)}getBookmark(){return new qu(this.anchor,this.head)}};Dt.prototype.visible=!1;function $e(e){return e instanceof Dt}T.Extension.create({name:"nodeRange",addOptions(){return{depth:void 0,key:"Mod"}},addKeyboardShortcuts(){return{"Shift-ArrowUp":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,selection:r,tr:o}=i,{anchor:l,head:c}=r;if(!$e(r)){const u=Dt.create(s,l,c,t,-1);return o.setSelection(u),n.dispatch(o),!0}const a=r.extendBackwards();return o.setSelection(a),n.dispatch(o),!0},"Shift-ArrowDown":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,selection:r,tr:o}=i,{anchor:l,head:c}=r;if(!$e(r)){const u=Dt.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=Dt.create(s,0,s.content.size,t);return r.setSelection(o),n.dispatch(r),!0}}},onSelectionUpdate(){const{selection:e}=this.editor.state;$e(e)&&this.editor.view.dom.classList.add("ProseMirror-noderangeselection")},addProseMirrorPlugins(){let e=!1,t=!1;return[new W.Plugin({key:new W.PluginKey("nodeRange"),props:{attributes:()=>e?{class:"ProseMirror-noderangeselection"}:{class:""},handleDOMEvents:{mousedown:(n,i)=>{const{key:s}=this.options,r=/Mac/.test(navigator.platform),o=!!i.shiftKey,l=!!i.ctrlKey,c=!!i.altKey,a=!!i.metaKey,u=r?a:l;return(s==null||s==="Shift"&&o||s==="Control"&&l||s==="Alt"&&c||s==="Meta"&&a||s==="Mod"&&u)&&(t=!0),t&&document.addEventListener("mouseup",()=>{t=!1;const{state:h}=n,{doc:f,selection:p,tr:g}=h,{$anchor:x,$head:w}=p;if(x.sameParent(w))return;const y=Dt.create(f,x.pos,w.pos,this.options.depth);g.setSelection(y),n.dispatch(g)},{once:!0}),!1}},decorations:n=>{const{selection:i}=n,s=$e(i);if(e=!1,!t)return s?(e=!0,_s(i.ranges)):null;const{$from:r,$to:o}=i;if(!s&&r.sameParent(o))return null;const l=Mn(r,o,this.options.depth);return l.length?(e=!0,_s(l)):null}}})]}});function Wu(e){let t="";const n=getComputedStyle(e);for(let i=0;i<n.length;i+=1)t+=`${n[i]}:${n.getPropertyValue(n[i])};`;return t}function Gu(e){const t=e.cloneNode(!0),n=[e,...Array.from(e.getElementsByTagName("*"))],i=[t,...Array.from(t.getElementsByTagName("*"))];return n.forEach((s,r)=>{i[r].style.cssText=Wu(s)}),t}var Yu={id:"listItemFirstChild",evaluate:({parent:e,isFirst:t})=>t&&e&&["listItem","taskItem"].includes(e.type.name)?1e3:0},Ju={id:"listWrapperDeprioritize",evaluate:({node:e})=>{const t=["listItem","taskItem"],n=e.firstChild;return n&&t.includes(n.type.name)?1e3:0}},Xu={id:"tableStructure",evaluate:({node:e,parent:t})=>["tableRow","tableCell","tableHeader"].includes(e.type.name)||t&&t.type.name==="tableHeader"?1e3:0},Zu={id:"inlineContent",evaluate:({node:e})=>e.isInline||e.isText?1e3:0},Qu=[Yu,Ju,Xu,Zu],Ts={edges:["left","top"],threshold:12,strength:500};function Jn(e){return e===void 0||e==="left"?{...Ts}: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}:{...Ts,...e}}function td(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 ed(e,t,n,i){return!t||n.edges.length===0?0:td(e,t,n)?n.strength*i:0}var nd=1e3;function As(e,t,n,i){let s=nd,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-=ed(i,o,n,e.depth),s<=0?-1:s}function Is(e,t,n){return Array.from({length:t},(s,r)=>t-1-r).some(s=>n.includes(e.node(s).type.name))}function id(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(...Qu),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&&!Is(r,h,n.allowedContainers))return null;const g=h>0?r.node(h-1):null,x=h>0?r.index(h-1):0,w=g?g.childCount:1,y={node:f,pos:p,depth:h,parent:g,index:x,isFirst:x===0,isLast:x===w-1,$pos:r,view:e},C=As(y,o,n.edgeDetection,t);if(C<0)return null;const k=e.nodeDOM(p);return{node:f,pos:p,depth:h,score:C,dom:k}}).filter(h=>h!==null),a=r.nodeAfter;if(a&&a.isAtom&&!a.isInline){const h=i.pos,f=r.depth+1,p=r.parent,g=r.index(),x=p.childCount;let w=!0;if(n.allowedContainers&&(w=Is(r,f,n.allowedContainers)),w){const y={node:a,pos:h,depth:f,parent:p,index:g,isFirst:g===0,isLast:g===x-1,$pos:r,view:e},C=As(y,o,n.edgeDetection,t);if(C>=0){const k=e.nodeDOM(h);k&&c.push({node:a,pos:h,depth:f,score:C,dom:k})}}}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 sd(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 Ds(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 rd(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(!Ds(l)||!Ds(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 po=e=>{const{x:t,y:n,editor:i,nestedOptions:s}=e,{view:r,state:o}=i,l=rd(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=id(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=sd(g,r);return x?(h=x,!0):!1}),!h)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 go(e){var t;(t=e.parentNode)==null||t.removeChild(e)}function od(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=po({editor:t,x:e.clientX,y:e.clientY,nestedOptions:n});if(!r.resultNode||r.pos===null)return[];const o=r.resultNode.isText||r.resultNode.isAtom?0:-1,l=s.resolve(r.pos),c=s.resolve(r.pos+r.resultNode.nodeSize+o);return Mn(l,c,0)}function ld(e,t,n,i){const{view:s}=t;if(!e.dataTransfer)return;const{empty:r,$from:o,$to:l}=s.state.selection,c=od(e,t,n,i),a=Mn(o,l,0),u=a.some(D=>c.find(L=>L.$from===D.$from&&L.$to===D.$to)),h=r||!u?c:a;if(!h.length)return;const{tr:f}=s.state,p=document.createElement("div"),g=h[0].$from.pos,x=h[h.length-1].$to.pos,w=(n==null?void 0:n.enabled)&&(i==null?void 0:i.node);let y,C;w?(y=s.state.doc.slice(g,x),C=W.NodeSelection.create(s.state.doc,g)):(C=Dt.create(s.state.doc,g,x),y=C.content()),h.forEach(D=>{const L=s.nodeDOM(D.$from.pos),v=Gu(L);p.append(v)}),p.style.position="absolute",p.style.top="-10000px",document.body.append(p),e.dataTransfer.clearData(),e.dataTransfer.setDragImage(p,0,0);const k=C instanceof W.NodeSelection?C:void 0;s.dragging={slice:y,move:!0,node:k},f.setSelection(C),s.dispatch(f),document.addEventListener("drop",()=>go(p),{once:!0})}var Ms=(e,t)=>{const n=e.resolve(t),{depth:i}=n;return i===0?t:n.pos-n.parentOffset-1},Os=(e,t)=>{const n=e.nodeAt(t),i=e.resolve(t);let{depth:s}=i,r=n;for(;s>0;){const o=i.node(s);s-=1,s===0&&(r=o)}return r},Xn=(e,t)=>{const n=R.getState(e);return n?pn(t,n.type,n.binding.mapping):null},cd=(e,t)=>{const n=R.getState(e);return n?ge(n.doc,n.type,t,n.binding.mapping)||0:-1},js=(e,t)=>{let n=t;for(;n!=null&&n.parentNode&&n.parentNode!==e.dom;)n=n.parentNode;return n},mo=new W.PluginKey("dragHandle"),xo=({pluginKey:e=mo,element:t,editor:n,computePositionConfig:i,getReferencedVirtualElement:s,onNodeChange:r,onElementDragStart:o,onElementDragEnd:l,nestedOptions:c})=>{const a=document.createElement("div");let u=!1,h=null,f=-1,p,g=null,x=null;function w(){t&&(t.style.visibility="hidden",t.style.pointerEvents="none")}function y(){if(t){if(!n.isEditable){w();return}t.style.visibility="",t.style.pointerEvents="auto"}}function C(v){const S=(s==null?void 0:s())||{getBoundingClientRect:()=>v.getBoundingClientRect()};H.computePosition(S,t,i).then(A=>{Object.assign(t.style,{position:A.strategy,left:`${A.x}px`,top:`${A.y}px`})})}function k(v){o==null||o(v),ld(v,n,c,{node:h,pos:f}),t&&(t.dataset.dragging="true"),setTimeout(()=>{t&&(t.style.pointerEvents="none")},0)}function D(v){l==null||l(v),w(),t&&(t.style.pointerEvents="auto",t.dataset.dragging="false")}function L(){if(T.isFirefox()){const v=n.view.dom;requestAnimationFrame(()=>{v.isContentEditable&&(v.contentEditable="false",v.contentEditable="true")})}}return a.appendChild(t),{unbind(){t.removeEventListener("dragstart",k),t.removeEventListener("dragend",D),document.removeEventListener("drop",L),g&&(cancelAnimationFrame(g),g=null,x=null)},plugin:new W.Plugin({key:typeof e=="string"?new W.PluginKey(e):e,state:{init(){return{locked:!1}},apply(v,S,A,z){const N=v.getMeta("lockDragHandle"),$=v.getMeta("hideDragHandle");if(N!==void 0&&(u=N),$)return w(),u=!1,h=null,f=-1,r==null||r({editor:n,node:null,pos:-1}),S;if(v.docChanged&&f!==-1&&t)if(ao(v)){const Y=cd(z,p);Y!==f&&(f=Y)}else{const Y=v.mapping.map(f);Y!==f&&(f=Y,p=Xn(z,f))}return S}},view:v=>{var S;return t.draggable=!0,t.style.pointerEvents="auto",t.dataset.dragging="false",(S=n.view.dom.parentElement)==null||S.appendChild(a),a.style.pointerEvents="none",a.style.position="absolute",a.style.top="0",a.style.left="0",t.addEventListener("dragstart",k),t.addEventListener("dragend",D),document.addEventListener("drop",L),{update(A,z){if(!t)return;if(!n.isEditable){w();return}if(u?t.draggable=!1:t.draggable=!0,v.state.doc.eq(z.doc)||f===-1)return;let N=v.nodeDOM(f);if(N=js(v,N),N===v.dom||(N==null?void 0:N.nodeType)!==1)return;const $=v.posAtDOM(N,0),Y=Os(n.state.doc,$),st=Ms(n.state.doc,$);h=Y,f=st,p=Xn(v.state,f),r==null||r({editor:n,node:h,pos:f}),C(N)},destroy(){t.removeEventListener("dragstart",k),t.removeEventListener("dragend",D),document.removeEventListener("drop",L),g&&(cancelAnimationFrame(g),g=null,x=null),t&&go(a)}}},props:{handleDOMEvents:{keydown(v){return!t||u||v.hasFocus()&&(w(),h=null,f=-1,r==null||r({editor:n,node:null,pos:-1})),!1},mouseleave(v,S){return u||S.target&&!a.contains(S.relatedTarget)&&(w(),h=null,f=-1,r==null||r({editor:n,node:null,pos:-1})),!1},mousemove(v,S){return!t||u||(x={x:S.clientX,y:S.clientY},g)||(g=requestAnimationFrame(()=>{if(g=null,!x)return;const{x:A,y:z}=x;x=null;const N=po({x:A,y:z,editor:n,nestedOptions:c});if(!N.resultElement)return;let $=N.resultElement,Y=N.resultNode,st=N.pos;if(!(c!=null&&c.enabled)){if($=js(v,$),$===v.dom||($==null?void 0:$.nodeType)!==1)return;const E=v.posAtDOM($,0);Y=Os(n.state.doc,E),st=Ms(n.state.doc,E)}Y!==h&&(h=Y,f=st??-1,p=Xn(v.state,f),r==null||r({editor:n,node:h,pos:f}),C($),y())})),!1}}}})}};function bo(e){var t,n;return e===!1||e===void 0?{enabled:!1,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Jn("none")}:e===!0?{enabled:!0,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Jn("left")}:{enabled:!0,rules:(t=e.rules)!=null?t:[],defaultRules:(n=e.defaultRules)!=null?n:!0,allowedContainers:e.allowedContainers,edgeDetection:Jn(e.edgeDetection)}}var xi={placement:"left-start",strategy:"absolute"};T.Extension.create({name:"dragHandle",addOptions(){return{render(){const e=document.createElement("div");return e.classList.add("drag-handle"),e},computePositionConfig:{},locked:!1,onNodeChange:()=>null,onElementDragStart:void 0,onElementDragEnd:void 0,nested:!1}},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=bo(this.options.nested);return[xo({computePositionConfig:{...xi,...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}).plugin]}});var ad=e=>{const{className:t="drag-handle",children:n,editor:i,pluginKey:s=mo,onNodeChange:r,onElementDragStart:o,onElementDragEnd:l,computePositionConfig:c=xi,nested:a=!1}=e,[u,h]=b.useState(null),f=b.useRef(null),p=b.useMemo(()=>bo(a),[JSON.stringify(a)]);return b.useEffect(()=>{let g=null;return u?i.isDestroyed?()=>{f.current=null}:(f.current||(g=xo({editor:i,element:u,pluginKey:s,computePositionConfig:{...xi,...c},onElementDragStart:o,onElementDragEnd:l,onNodeChange:r,nestedOptions:p}),f.current=g.plugin,i.registerPlugin(f.current)),()=>{i.unregisterPlugin(s),f.current=null,g&&(g.unbind(),g=null)}):()=>{f.current=null}},[u,i,r,s,c,o,l,p]),d.jsx("div",{className:t,style:{visibility:"hidden",position:"absolute"},"data-dragging":"false",ref:h,children:n})},hd=ad;function ud(){var v,S,A,z,N,$,Y,st;const e=m.useEditorInstance(),t=m.useEditableEditor(),{t:n}=B.useLocale(),[i,s]=b.useState(null),[r,o]=b.useState(-1),[l,c]=b.useState(!1),a=(S=(v=e==null?void 0:e.extensionManager)==null?void 0:v.extensions)==null?void 0:S.some(E=>(E==null?void 0:E.name)===Us.TextAlign.name),u=(z=(A=e==null?void 0:e.extensionManager)==null?void 0:A.extensions)==null?void 0:z.some(E=>(E==null?void 0:E.name)===ue.Indent.name),h=($=(N=e==null?void 0:e.extensionManager)==null?void 0:N.extensions)==null?void 0:$.some(E=>(E==null?void 0:E.name)===Mo.Clear.name);function f(){const E=e.chain();E.setNodeSelection(r).unsetAllMarks(),(i==null?void 0:i.type.name)!=="paragraph"&&E.setParagraph(),E.run()}function p(){e.chain().focus().setNodeSelection(r).run(),document.execCommand("copy")}function g(){e.commands.setNodeSelection(r);const{$anchor:E}=e.state.selection,yt=E.node(1)||e.state.selection.node;e.chain().setMeta("hideDragHandle",!0).insertContentAt(r+((i==null?void 0:i.nodeSize)||0),yt.toJSON()).run()}function x(E){e.commands.setTextAlign(E)}function w(){const E=ue.setNodeIndentMarkup(e.state.tr,r,1);E.setMeta("hideDragHandle",!0),e.view.dispatch&&e.view.dispatch(E)}function y(){const E=ue.setNodeIndentMarkup(e.state.tr,r,-1);e.view.dispatch&&e.view.dispatch(E)}function C(){e.chain().setMeta("hideDragHandle",!0).setNodeSelection(r).deleteSelection().run()}const k=b.useCallback(E=>{E.node&&s(E.node),o(E.pos),requestAnimationFrame(()=>{E.editor.commands.focus()})},[]),D=E=>{var yt;if(E.preventDefault(),r!==-1){const je=(i==null?void 0:i.nodeSize)||0,zt=r+je,Hi=(i==null?void 0:i.type.name)==="paragraph"&&((yt=i==null?void 0:i.content)==null?void 0:yt.size)===0,wo=Hi?r+2:zt+2;e.chain().command(({dispatch:zi,tr:On,state:Ki})=>zi?(Hi?On.insertText("/",r,r+1):On.insert(zt,Ki.schema.nodes.paragraph.create(null,[Ki.schema.text("/")])),zi(On)):!0).focus(wo).run()}};b.useEffect(()=>(l?e.commands.setMeta("lockDragHandle",!0):e.commands.setMeta("lockDragHandle",!1),()=>{e.commands.setMeta("lockDragHandle",!1)}),[l]);const L=E=>{t&&c(E)};return d.jsx(hd,{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:D,disabled:!t,icon:"Plus",tooltip:"Insert block"}),d.jsx(m.ActionButton,{disabled:!t,icon:"Grip",tooltip:"Click for options, Hold for drag",action:E=>{E.preventDefault(),E.stopPropagation(),L(!l)}}),d.jsxs(U.DropdownMenu,{onOpenChange:L,open:l,children:[d.jsx(U.DropdownMenuTrigger,{className:"richtext-pointer-events-none"}),d.jsxs(U.DropdownMenuContent,{align:"start",className:"richtext-w-48",hideWhenDetached:!0,side:"bottom",sideOffset:0,children:[d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3 richtext-bg-opacity-10 hover:richtext-bg-red-400 hover:richtext-bg-opacity-20 focus:richtext-bg-red-400 focus:richtext-bg-opacity-30 focus:richtext-text-red-500 dark:hover:richtext-bg-opacity-20 dark:hover:richtext-text-red-500",onClick:C,children:[d.jsx(m.IconComponent,{name:"Trash2"}),d.jsx("span",{children:n("editor.remove")})]}),h?d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:f,children:[d.jsx(m.IconComponent,{name:"PaintRoller"}),d.jsx("span",{children:n("editor.clear.tooltip")})]}):null,d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:p,children:[d.jsx(m.IconComponent,{name:"Clipboard"}),d.jsx("span",{children:n("editor.copyToClipboard")})]}),d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:g,children:[d.jsx(m.IconComponent,{name:"Copy"}),d.jsx("span",{children:n("editor.copy")})]}),a||u?d.jsx(U.DropdownMenuSeparator,{}):null,a?d.jsxs(U.DropdownMenuSub,{children:[d.jsxs(U.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[d.jsx(m.IconComponent,{name:"AlignCenter"}),d.jsx("span",{children:n("editor.textalign.tooltip")})]}),d.jsx(U.DropdownMenuPortal,{children:d.jsxs(U.DropdownMenuSubContent,{children:[d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("left"),children:[d.jsx(m.IconComponent,{name:"AlignLeft"}),d.jsx("span",{children:n("editor.textalign.left.tooltip")})]}),d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("center"),children:[d.jsx(m.IconComponent,{name:"AlignCenter"}),d.jsx("span",{children:n("editor.textalign.center.tooltip")})]}),d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("right"),children:[d.jsx(m.IconComponent,{name:"AlignRight"}),d.jsx("span",{children:n("editor.textalign.right.tooltip")})]})]})})]}):null,u?d.jsxs(U.DropdownMenuSub,{children:[d.jsxs(U.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[d.jsx(m.IconComponent,{name:"IndentIncrease"}),d.jsx("span",{children:n("editor.indent")})]}),d.jsx(U.DropdownMenuPortal,{children:d.jsxs(U.DropdownMenuSubContent,{children:[d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((Y=i==null?void 0:i.attrs)==null?void 0:Y.indent)>=ue.IndentProps.max,onClick:w,children:[d.jsx(m.IconComponent,{name:"IndentIncrease"}),d.jsx("span",{children:n("editor.indent.tooltip")})]}),d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((st=i==null?void 0:i.attrs)==null?void 0:st.indent)<=ue.IndentProps.min,onClick:y,children:[d.jsx(m.IconComponent,{name:"IndentDecrease"}),d.jsx("span",{children:n("editor.outdent.tooltip")})]})]})})]}):null]})]})]})})}const Rs={plaintext:"Plain Text",js:"JavaScript",ts:"TypeScript",css:"CSS",html:"HTML",python:"Python"};function dd({listLanguages:e}){const{t}=B.useLocale(),[n,i]=b.useState(!1),s=m.useEditorInstance(),r=b.useMemo(()=>{const{selection:l}=s.state,c=l.$from.parent;if(c.type.name==="codeBlock"){const a=c.attrs.language||"plaintext";return Rs[a]||a}},[s.state,e]),o=b.useMemo(()=>{let l=e||[];return e!=null&&e.includes("plaintext")||(l=["plaintext",...l]),l.map(c=>({label:Rs[c]||c,value:c}))},[e]);return d.jsxs(St.Popover,{modal:!0,onOpenChange:i,open:n,children:[d.jsx(St.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(St.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 fd(){const e=m.useEditableEditor(),t=m.useEditorInstance(),n=m.useExtension(Rn.CodeBlock.name),i=b.useCallback(({editor:o})=>o.isActive(Rn.CodeBlock.name),[]),s=b.useMemo(()=>{var o,l,c;return n?((c=(l=(o=n.options)==null?void 0:o.lowlight)==null?void 0:l.listLanguages)==null?void 0:c.call(l))||["plaintext","html","css","js","ts"]:[]},[n]),r=b.useCallback(()=>Ft(Rn.CodeBlock.name,t),[t]);return e?d.jsx(et,{editor:t,options:{placement:"top-start",strategy:"fixed",offset:25,flip:!0},pluginKey:"RichTextBubbleCodeBlock",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(dd,{listLanguages:s}),d.jsx(Ct.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=cl;exports.RichTextBubbleCodeBlock=fd;exports.RichTextBubbleColumns=al;exports.RichTextBubbleDrawer=El;exports.RichTextBubbleExcalidraw=Tl;exports.RichTextBubbleIframe=Al;exports.RichTextBubbleImage=Bl;exports.RichTextBubbleImageGif=Ll;exports.RichTextBubbleKatex=Dl;exports.RichTextBubbleLink=Ol;exports.RichTextBubbleMenuDragHandle=ud;exports.RichTextBubbleMermaid=Vl;exports.RichTextBubbleTable=Hl;exports.RichTextBubbleText=ql;exports.RichTextBubbleTwitter=Wl;exports.RichTextBubbleVideo=Ul;
1
+ "use strict";var vo=Object.create;var jn=Object.defineProperty;var So=Object.getOwnPropertyDescriptor;var Co=Object.getOwnPropertyNames;var ko=Object.getPrototypeOf,Eo=Object.prototype.hasOwnProperty;var _o=(e,t,n)=>t in e?jn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var To=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Co(t))!Eo.call(e,s)&&s!==n&&jn(e,s,{get:()=>t[s],enumerable:!(i=So(t,s))||i.enumerable});return e};var Ao=(e,t,n)=>(n=e!=null?vo(ko(e)):{},To(t||!e||!e.__esModule?jn(n,"default",{value:e,enumerable:!0}):n,e));var Ne=(e,t,n)=>_o(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),T=require("./index-C4WLt4NA.cjs"),H=require("./index-TcJ2UKnv.cjs"),W=require("@tiptap/pm/state"),Bs=require("./Table-BFiU40iW.cjs"),Ls=require("./clsx-DSAWW32g.cjs"),b=require("react"),Us=require("react-dom"),m=require("./index-83hp1lZH.cjs"),St=require("./Callout-lBlBlK_w.cjs"),ut=require("./Katex-rtfVV2pl.cjs"),B=require("./index-C4aGVY2E.cjs"),Ut=require("lucide-react"),Rn=require("./CodeBlock.cjs"),bt=require("./separator-C_7KkuoG.cjs"),kt=require("./popover-D7w_FVSV.cjs"),Wi=require("./Column.cjs");require("./theme.cjs");const Fe=require("./Drawer-BeYo9jAG.cjs"),Gi=require("easydrawer"),Je=require("./shortId-Bfj8TyNr.cjs"),ue=require("./Excalidraw.cjs"),Wt=require("./Iframe-Bx-VDxSB.cjs"),Io=require("./ImageGif.cjs"),Do=require("katex"),Zn=require("./textarea-CEtXap1b.cjs"),Ve=require("./LinkEditBlock-_41zgSyl.cjs"),Nn=require("@tiptap/pm/view"),Mo=require("@tiptap/pm/model"),Oo=require("./Clear.cjs"),de=require("./Indent-CCLO0KpG.cjs"),Ps=require("./TextAlign.cjs"),U=require("./dropdown-menu-Dre693DD.cjs"),Qn=require("./Mermaid.cjs"),jo=require("./Bold.cjs"),Ro=require("./Code.cjs");require("./index-DlxZt4_j.cjs");const No=require("./Color.cjs"),Bo=require("./Highlight.cjs"),Lo=require("./Italic.cjs"),Uo=require("./SlashCommandNodeView-CVKjpS6r.cjs"),Po=require("./Strike.cjs"),$o=require("./TextUnderline.cjs"),Bn=require("./Twitter-BJjt8vv_.cjs");function Fo(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 Vo=class{constructor({editor:e,element:t,view:n,pluginKey:i="bubbleMenu",updateDelay:s=250,resizeDelay:r=60,shouldShow:o,appendTo:l,getReferencedVirtualElement:c,options:a}){this.preventHide=!1,this.isVisible=!1,this.scrollTarget=window,this.floatingUIOptions={strategy:"absolute",placement:"top",offset:8,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1,onShow:void 0,onHide:void 0,onUpdate:void 0,onDestroy:void 0},this.shouldShow=({view:h,state:f,from:p,to:g})=>{const{doc:x,selection:w}=f,{empty:y}=w,C=!x.textBetween(p,g).length&&T.isTextSelection(f.selection),k=this.element.contains(document.activeElement);return!(!(h.hasFocus()||k)||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.updatePosition(),this.show()},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)};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(H.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(H.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(H.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(H.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(H.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(H.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(H.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(H.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}get virtualElement(){var e,t,n;const{selection:i}=this.editor.state,s=(e=this.getReferencedVirtualElement)==null?void 0:e.call(this);if(s)return s;if(!((n=(t=this.view)==null?void 0:t.dom)!=null&&n.parentNode))return;const r=T.posToDOMRect(this.view,i.from,i.to);let o={getBoundingClientRect:()=>r,getClientRects:()=>[r]};if(i instanceof W.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 Bs.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():Fo(h.getBoundingClientRect(),f.getBoundingClientRect());o={getBoundingClientRect:()=>p,getClientRects:()=>[p]}}return o}updatePosition(){const e=this.virtualElement;e&&H.computePosition(e,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:t,y:n,strategy:i,middlewareData:s})=>{var r,o;if((r=s.hide)!=null&&r.referenceHidden||(o=s.hide)!=null&&o.escaped){this.element.style.visibility="hidden";return}this.element.style.visibility="visible",this.element.style.width="max-content",this.element.style.position=i,this.element.style.left=`${t}px`,this.element.style.top=`${n}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()})}update(e,t){const{state:n}=e,i=n.selection.from!==n.selection.to;if(this.updateDelay>0&&i){this.handleDebouncedUpdate(e,t);return}const s=!(t!=null&&t.selection.eq(e.state.selection)),r=!(t!=null&&t.doc.eq(e.state.doc));this.updateHandler(e,s,r,t)}getShouldShow(e){var t;const{state:n}=this.view,{selection:i}=n,{ranges:s}=i,r=Math.min(...s.map(c=>c.$from.pos)),o=Math.max(...s.map(c=>c.$to.pos));return((t=this.shouldShow)==null?void 0:t.call(this,{editor:this.editor,element:this.element,view:this.view,state:n,oldState:e,from:r,to:o}))||!1}show(){var e;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const t=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(e=t??this.view.dom.parentElement)==null||e.appendChild(this.element),this.floatingUIOptions.onShow&&this.floatingUIOptions.onShow(),this.isVisible=!0}hide(){this.isVisible&&(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.remove(),this.floatingUIOptions.onHide&&this.floatingUIOptions.onHide(),this.isVisible=!1)}updateOptions(e){var t;if(e.updateDelay!==void 0&&(this.updateDelay=e.updateDelay),e.resizeDelay!==void 0&&(this.resizeDelay=e.resizeDelay),e.appendTo!==void 0&&(this.appendTo=e.appendTo),e.getReferencedVirtualElement!==void 0&&(this.getReferencedVirtualElement=e.getReferencedVirtualElement),e.shouldShow!==void 0&&e.shouldShow&&(this.shouldShow=e.shouldShow),e.options!==void 0){const n=(t=e.options.scrollTarget)!=null?t:window;n!==this.scrollTarget&&(this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.scrollTarget=n,this.scrollTarget.addEventListener("scroll",this.resizeHandler)),this.floatingUIOptions={...this.floatingUIOptions,...e.options}}}destroy(){this.hide(),this.element.removeEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.view.dom.removeEventListener("dragstart",this.dragstartHandler),window.removeEventListener("resize",this.resizeHandler),this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.editor.off("transaction",this.transactionHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},$s=e=>new W.Plugin({key:typeof e.pluginKey=="string"?new W.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Vo({view:t,...e})});T.Extension.create({name:"bubbleMenu",addOptions(){return{element:null,pluginKey:"bubbleMenu",updateDelay:void 0,appendTo:void 0,shouldShow:null}},addProseMirrorPlugins(){return this.options.element?[$s({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,updateDelay:this.options.updateDelay,options:this.options.options,appendTo:this.options.appendTo,getReferencedVirtualElement:this.options.getReferencedVirtualElement,shouldShow:this.options.shouldShow})]:[]}});var Ho=class{constructor({editor:e,element:t,view:n,pluginKey:i="floatingMenu",updateDelay:s=250,resizeDelay:r=60,options:o,appendTo:l,shouldShow:c}){this.preventHide=!1,this.isVisible=!1,this.scrollTarget=window,this.shouldShow=({view:u,state:h})=>{const{selection:f}=h,{$anchor:p,empty:g}=f,x=p.depth===1,w=p.parent.isTextblock&&!p.parent.type.spec.code&&!p.parent.textContent&&p.parent.childCount===0&&!this.getTextContent(p.parent);return!(!u.hasFocus()||!g||!x||!w||!this.editor.isEditable)},this.floatingUIOptions={strategy:"absolute",placement:"right",offset:8,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1},this.updateHandler=(u,h,f,p)=>{const{composing:g}=u;if(g||!h&&!f)return;if(!this.getShouldShow(p)){this.hide();return}this.updatePosition(),this.show()},this.mousedownHandler=()=>{this.preventHide=!0},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:u})=>{var h;if(this.preventHide){this.preventHide=!1;return}u!=null&&u.relatedTarget&&((h=this.element.parentNode)!=null&&h.contains(u.relatedTarget))||(u==null?void 0:u.relatedTarget)!==this.editor.view.dom&&this.hide()},this.transactionHandler=({transaction:u})=>{const h=u.getMeta(this.pluginKey);h==="updatePosition"?this.updatePosition():h&&typeof h=="object"&&h.type==="updateOptions"&&this.updateOptions(h.options)},this.resizeHandler=()=>{this.resizeDebounceTimer&&clearTimeout(this.resizeDebounceTimer),this.resizeDebounceTimer=window.setTimeout(()=>{this.updatePosition()},this.resizeDelay)};var a;this.editor=e,this.element=t,this.view=n,this.pluginKey=i,this.updateDelay=s,this.resizeDelay=r,this.appendTo=l,this.scrollTarget=(a=o==null?void 0:o.scrollTarget)!=null?a:window,this.floatingUIOptions={...this.floatingUIOptions,...o},this.element.tabIndex=0,c&&(this.shouldShow=c),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.editor.on("transaction",this.transactionHandler),window.addEventListener("resize",this.resizeHandler),this.scrollTarget.addEventListener("scroll",this.resizeHandler),this.update(n,n.state),this.getShouldShow()&&(this.show(),this.updatePosition())}getTextContent(e){return T.getText(e,{textSerializers:T.getTextSerializersFromSchema(this.editor.schema)})}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(H.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(H.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(H.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(H.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(H.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(H.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(H.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(H.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}getShouldShow(e){var t;const{state:n}=this.view,{selection:i}=n,{ranges:s}=i,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(){const{selection:e}=this.editor.state,t=T.posToDOMRect(this.view,e.from,e.to),n={getBoundingClientRect:()=>t,getClientRects:()=>[t]};H.computePosition(n,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:i,y:s,strategy:r,middlewareData:o})=>{var l,c;if((l=o.hide)!=null&&l.referenceHidden||(c=o.hide)!=null&&c.escaped){this.element.style.visibility="hidden";return}this.element.style.visibility="visible",this.element.style.width="max-content",this.element.style.position=r,this.element.style.left=`${i}px`,this.element.style.top=`${s}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()})}update(e,t){const n=!(t!=null&&t.selection.eq(e.state.selection)),i=!(t!=null&&t.doc.eq(e.state.doc));this.updateHandler(e,n,i,t)}show(){var e;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const t=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(e=t??this.view.dom.parentElement)==null||e.appendChild(this.element),this.floatingUIOptions.onShow&&this.floatingUIOptions.onShow(),this.isVisible=!0}hide(){this.isVisible&&(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.remove(),this.floatingUIOptions.onHide&&this.floatingUIOptions.onHide(),this.isVisible=!1)}destroy(){this.hide(),this.element.removeEventListener("mousedown",this.mousedownHandler,{capture:!0}),window.removeEventListener("resize",this.resizeHandler),this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.editor.off("transaction",this.transactionHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},Fs=e=>new W.Plugin({key:typeof e.pluginKey=="string"?new W.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Ho({view:t,...e})});T.Extension.create({name:"floatingMenu",addOptions(){return{element:null,options:{},pluginKey:"floatingMenu",updateDelay:void 0,resizeDelay:void 0,appendTo:void 0,shouldShow:null}},addCommands(){return{updateFloatingMenuPosition:()=>({tr:e,dispatch:t})=>(t&&e.setMeta(this.options.pluginKey,"updatePosition"),!0)}},addProseMirrorPlugins(){return this.options.element?[Fs({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,updateDelay:this.options.updateDelay,resizeDelay:this.options.resizeDelay,options:this.options.options,appendTo:this.options.appendTo,shouldShow:this.options.shouldShow})]:[]}});function Vs(e,t){return e??new W.PluginKey(t)}var zo=typeof window<"u"?b.useLayoutEffect:b.useEffect,Hs=new Set(["left","opacity","position","top","visibility","width"]),Ko=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"]),qo=new Set(["children","className","style"]),Wo=new Set(["tabIndex"]),Go=new Set(["accessKey","autoCapitalize","contentEditable","contextMenu","dir","draggable","enterKeyHint","hidden","id","lang","nonce","role","slot","spellCheck","tabIndex","title","translate"]),Yo={Blur:"focusout",DoubleClick:"dblclick",Focus:"focusin",MouseEnter:"mouseenter",MouseLeave:"mouseleave"};function ti(e,t){return/^on[A-Z]/.test(e)&&typeof t=="function"}function Jo(e){return e.startsWith("aria-")||e.startsWith("data-"),e}function Xo(e){return e.startsWith("aria-")||e.startsWith("data-")||Go.has(e)}function zs(e){return e.startsWith("--")?e:e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}function Zo(e){var t;const n=e.endsWith("Capture"),s=(n?e.slice(0,-7):e).slice(2);return{eventName:(t=Yo[s])!=null?t:s.toLowerCase(),options:n?{capture:!0}:void 0}}function Qo(e,t){let n=t.defaultPrevented,i=!1;const s=Object.create(t);return Object.defineProperties(s,{nativeEvent:{value:t},currentTarget:{value:e},target:{value:t.target},persist:{value:()=>{}},isDefaultPrevented:{value:()=>n},isPropagationStopped:{value:()=>i},preventDefault:{value:()=>{n=!0,t.preventDefault()}},stopPropagation:{value:()=>{i=!0,t.stopPropagation()}}}),s}function Ln(e){return Wo.has(e)}function Yi(e,t,n){if(t==="tabIndex"){e.tabIndex=Number(n);return}e[t]=n}function tl(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 el(e,t){return typeof t!="number"||t===0||e.startsWith("--")||Ko.has(e)?String(t):`${t}px`}function nl(e,t){Hs.has(t)||e.style.removeProperty(zs(t))}function il(e,t,n){Hs.has(t)||e.style.setProperty(zs(t),el(t,n))}function sl(e,t,n){new Set([...Object.keys(t),...Object.keys(n)]).forEach(s=>{if(qo.has(s)||!Xo(s)||ti(s,t[s])||ti(s,n[s]))return;const r=t[s],o=n[s];if(r===o)return;const l=Jo(s);if(o==null||o===!1){Ln(s)&&tl(e,s),e.removeAttribute(l);return}if(o===!0){Ln(s)&&Yi(e,s,!0),e.setAttribute(l,"");return}if(Ln(s)){Yi(e,s,o);return}e.setAttribute(l,String(o))})}function rl(e,t,n){if(t!==n){if(n){e.className=n;return}e.removeAttribute("class")}}function ol(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){nl(e,o);return}il(e,o,c)}})}function ll(e,t,n){t.forEach(({eventName:s,listener:r,options:o})=>{e.removeEventListener(s,r,o)});const i=[];return Object.entries(n).forEach(([s,r])=>{if(!ti(s,r))return;const{eventName:o,options:l}=Zo(s),c=a=>{r(Qo(e,a))};e.addEventListener(o,c,l),i.push({eventName:o,listener:c,options:l})}),i}function Ks(e,t){const n=b.useRef({}),i=b.useRef([]);zo(()=>{const s=n.current;return rl(e,s.className,t.className),ol(e,s.style,t.style),sl(e,s,t),i.current=ll(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 et=b.forwardRef(({pluginKey:e,editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:r=null,getReferencedVirtualElement:o,options:l,children:c,...a},u)=>{const h=b.useRef(document.createElement("div")),f=b.useRef(Vs(e,"bubbleMenu")).current;Ks(h.current,a),typeof u=="function"?u(h.current):u&&(u.current=h.current);const{editor:p}=Ls.useCurrentEditor(),g=t||p,x={updateDelay:n,resizeDelay:i,appendTo:s,pluginKey:f,shouldShow:r,getReferencedVirtualElement:o,options:l},w=b.useRef(x);w.current=x;const[y,C]=b.useState(!1),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 D=h.current;D.style.visibility="hidden",D.style.position="absolute";const L=$s({...w.current,editor:g,element:D});g.registerPlugin(L);const v=w.current.pluginKey;return k.current=!0,C(!0),()=>{C(!1),g.unregisterPlugin(v),window.requestAnimationFrame(()=>{D.parentNode&&D.parentNode.removeChild(D)})}},[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]),Us.createPortal(c,h.current)});b.forwardRef(({pluginKey:e,editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:r=null,options:o,children:l,...c},a)=>{const u=b.useRef(document.createElement("div")),h=b.useRef(Vs(e,"floatingMenu")).current;Ks(u.current,c),typeof a=="function"?a(u.current):a&&(a.current=u.current);const{editor:f}=Ls.useCurrentEditor(),p=t||f,g={updateDelay:n,resizeDelay:i,appendTo:s,pluginKey:h,shouldShow:r,options:o},x=b.useRef(g);x.current=g;const[w,y]=b.useState(!1),C=b.useRef(!0);return b.useEffect(()=>{if(p!=null&&p.isDestroyed)return;if(!p){console.warn("FloatingMenu component is not rendered inside of an editor component or does not have editor prop.");return}const k=u.current;k.style.visibility="hidden",k.style.position="absolute";const D=Fs({...x.current,editor:p,element:k});p.registerPlugin(D);const L=x.current.pluginKey;return C.current=!0,y(!0),()=>{y(!1),p.unregisterPlugin(L),window.requestAnimationFrame(()=>{k.parentNode&&k.parentNode.removeChild(k)})}},[p]),b.useEffect(()=>{if(!(!w||!p||p.isDestroyed)){if(C.current){C.current=!1;return}p.view.dispatch(p.state.tr.setMeta(h,{type:"updateOptions",options:x.current}))}},[w,p,n,i,r,o,s,h]),Us.createPortal(l,u.current)});function Ht(e,t){const{state:n}=t,i=n.selection.$anchor;let s=!1;if(i.depth)for(let r=i.depth;r>0;r--)i.node(r).type.name===e&&(t.dispatchTransaction&&t.dispatchTransaction(n.tr.delete(i.before(r),i.after(r)).scrollIntoView()),s=!0);else{const r=n.selection.node;r&&r.type.name===e&&(t.chain().deleteSelection().run(),s=!0)}if(!s){const r=i.pos;if(r){const o=n.tr.doc.nodeAt(r);o&&o.type.name===e&&(t.dispatchTransaction&&t.dispatchTransaction(n.tr.delete(r,r+o.nodeSize)),s=!0)}}return s}const cl=[{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 al(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=B.useLocale(),{type:i,title:s,body:r}=ut.useAttributes(t,St.Callout.name,{type:"note",title:"",body:""}),[o,l]=b.useState(!1),[c,a]=b.useState("note"),[u,h]=b.useState(""),[f,p]=b.useState("");b.useEffect(()=>{o&&(a(i||"note"),h(s||""),p(r||""))},[o,i,s,r]);const g=b.useCallback(()=>{t&&(t.chain().updateAttributes(St.Callout.name,{type:c,title:u,body:f}).focus().run(),l(!1))},[t,c,u,f]),x=b.useCallback(()=>{l(!1)},[]),w=b.useCallback(()=>{Ht(St.Callout.name,t)},[t]),y=b.useCallback(()=>t.isActive(St.Callout.name),[t]);return e?d.jsx(et,{editor:t,options:{placement:"top",offset:8,flip:!0},pluginKey:"RichTextBubbleCallout",shouldShow:y,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsxs(m.Dialog,{onOpenChange:l,open:o,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{icon:"Pencil",tooltip:n("editor.callout.edit.title")})}),d.jsxs(m.DialogContent,{children:[d.jsx(m.DialogTitle,{children:n("editor.callout.edit.title")}),d.jsxs("div",{className:"richtext-space-y-4 richtext-py-4",children:[d.jsxs("div",{className:"richtext-space-y-2",children:[d.jsx(m.Label,{children:n("editor.callout.dialog.type")}),d.jsxs(St.Select,{onValueChange:a,value:c,children:[d.jsx(St.SelectTrigger,{children:d.jsx(St.SelectValue,{className:"richtext-text-accent",placeholder:n("editor.callout.dialog.type.placeholder")})}),d.jsx(St.SelectContent,{children:cl.map(C=>d.jsx(St.SelectItem,{value:C.value,children:n(`editor.callout.type.${C.value}`)},C.value))})]})]}),d.jsxs("div",{className:"richtext-space-y-2",children:[d.jsx(m.Label,{children:n("editor.callout.dialog.title.label")}),d.jsx(m.Input,{onChange:C=>h(C.target.value),placeholder:n("editor.callout.dialog.title.placeholder"),type:"text",value:u})]}),d.jsxs("div",{className:"richtext-space-y-2",children:[d.jsx(m.Label,{children:n("editor.callout.dialog.body.label")}),d.jsx(m.Input,{onChange:C=>p(C.target.value),placeholder:n("editor.callout.dialog.body.placeholder"),type:"text",value:f})]})]}),d.jsxs(m.DialogFooter,{children:[d.jsx(m.Button,{onClick:x,variant:"outline",children:n("editor.callout.dialog.button.cancel")}),d.jsx(m.Button,{onClick:g,children:n("editor.callout.dialog.button.apply")})]})]})]}),d.jsx(m.ActionButton,{action:w,icon:"Trash2",tooltip:n("editor.delete")})]})}):d.jsx(d.Fragment,{})}function hl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=B.useLocale(),i=b.useCallback(()=>t.isActive(Wi.MultipleColumnNode.name),[t]),s=b.useCallback(()=>Ht(Wi.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(et,{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 ul(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,r)=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[r],action:()=>e.commands.updateImage({width:B.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:B.IMAGE_SIZE[s]})}}))}function dl(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,r)=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[r],action:()=>e.commands.updateImageGif({width:B.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:B.IMAGE_SIZE[s]})}}))}function fl(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 pl(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImageGif)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function gl(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImageMermaid)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function ml(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var r,o;return(o=(r=e.commands)==null?void 0:r.setAlignImageDrawer)==null?void 0:o.call(r,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function xl(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 bl(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,r)=>({type:`video-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[r],action:()=>e.commands.updateVideo({width:B.VIDEO_SIZE[s]}),isActive:()=>e.isActive("video",{width:B.VIDEO_SIZE[s]})}}))}function wl(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()}}},...ul(e,t),...fl(e,t),{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;T.deleteSelection(n,i)}}}]}function yl(e,t){return[...dl(e,t),...pl(e,t),{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;T.deleteSelection(n,i)}}}]}function vl(e,t){return[...gl(e,t),{type:"edit",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;T.deleteSelection(n,i)}}}]}function Sl(e,t){return[...ml(e,t),{type:"edit",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;T.deleteSelection(n,i)}}}]}function Cl(e,t){return[...bl(e,t),...xl(e),{type:"remove",component:m.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;T.deleteSelection(n,i)}}}]}let fe=!1;function kl({editor:e,attrs:t,extension:n}){const[i,s]=b.useState(!1),r=b.useRef(null),o=b.useRef(null),{alt:l,align:c}=t,a=n==null?void 0:n.options.upload,u=()=>{(async()=>{const S=document.querySelector("#easydrawer");S&&(r.current=new Gi.Editor(S,{wheelEventsEnabled:!1,disableZoom:!0}),o.current=Gi.makeDropdownToolbar(r.current),o.current.addDefaultToolWidgets(),r.current.loadFromSVG(decodeURIComponent(l)))})()};b.useEffect(()=>{i&&setTimeout(()=>{u()},200)},[i]);const h=async()=>{if(r.current){const v=r.current.toSVG(),S=v.outerHTML,A=`drawer-${Je.shortId()}.svg`;let z=Je.i(v.outerHTML);if(a){const N=m.dataURLtoFile(z,A);z=await a(N)}e==null||e.chain().focus().setDrawer({type:"drawer",src:z,alt:encodeURIComponent(S),width:426,height:212},!!S).run(),e==null||e.commands.setAlignImageDrawer(c)}s(!1)},f=v=>{const S=r.current.toolController.getPrimaryTools()[2],A=o.current.getWidgetById("pen-1");S&&A&&(S.setColor(v),A.serializeState())},p=v=>{const S=r.current.toolController.getPrimaryTools()[2],A=o.current.getWidgetById("pen-1");S&&A&&(S.setThickness(v),A.serializeState())},g=v=>{const S=r.current.toolController.getPrimaryTools()[3],A=o.current.getWidgetById("pen-2");S&&A&&(S.setColor(v),A.serializeState())},x=v=>{const S=o.current.getWidgetById("shape");S&&S.setShapeType(v)},w=v=>{const S=r.current.toolController.getPrimaryTools()[5],A=o.current.getWidgetById("shape");S&&A&&(S.setColor(v),A.serializeState())},y=v=>{const S=r.current.toolController.getPrimaryTools()[5],A=o.current.getWidgetById("shape");S&&A&&(S.setThickness(v),A.serializeState())},C=v=>{const S=r.current.toolController.getPrimaryTools()[5],A=o.current.getWidgetById("shape");S&&A&&(S.setBorderColor(v),A.serializeState())},k=()=>{if(fe){for(;r.current.history.redoStackSize>0;)r.current.history.redo();fe=!1;return}r.current.history.undo()},D=()=>{fe||r.current.history.redo()},L=()=>{if(!fe){for(;r.current.history.undoStackSize>0;)k();fe=!0}};return d.jsxs(m.Dialog,{onOpenChange:s,open:i,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{action:()=>s(!0),icon:"Pencil",tooltip:"Edit Drawer"})}),d.jsxs(m.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[d.jsx(m.DialogTitle,{children:"Edit Drawer"}),d.jsxs("div",{style:{height:"100%",borderWidth:1,background:"white",position:"relative"},children:[d.jsx("div",{className:"richtext-size-full",id:"easydrawer"}),d.jsx(Fe.ControlDrawer,{changeBorderColorShape:C,changeColorShape:w,changeShape:x,onClear:L,onRedo:D,onThicknessChange:y,onUndo:k,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 El({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?d.jsx(b.Fragment,{children:e.type==="divider"?d.jsx(bt.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 _l(){const{lang:e,t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=ut.useAttributes(i,Fe.Drawer.name),r=m.useExtension(Fe.Drawer.name),o=({editor:c})=>{const{selection:a}=c.view.state,{$from:u,to:h}=a;let f=!1;return c.view.state.doc.nodesBetween(u.pos,h,p=>{if(p.type.name===Fe.Drawer.name)return f=!0,!1}),f},l=b.useMemo(()=>Sl(i,t),[i,e,t]);return n?d.jsx(et,{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(kl,{attrs:s,editor:i,extension:r},`bubbleMenu-drawer-${a}`):d.jsx(El,{editor:i,item:c},`bubbleMenu-drawer-${a}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}const qs=({width:e,maxWidth:t,height:n,onOk:i,children:s})=>{const{t:r}=B.useLocale(),[o,l]=b.useState({width:"",height:"",maxWidth:""});b.useEffect(()=>{l({width:e,height:n,maxWidth:t})},[n,t,e]);function c(a){a.preventDefault(),a.stopPropagation(),i(o)}return d.jsxs(kt.Popover,{modal:!0,children:[d.jsx(kt.PopoverTrigger,{asChild:!0,children:s}),d.jsx(kt.PopoverContent,{children:d.jsxs("form",{className:"richtext-flex richtext-flex-col richtext-gap-2",onSubmit:c,children:[d.jsx(m.Label,{className:"mb-[6px]",children:"Width"}),d.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:d.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:d.jsx(m.Input,{onChange:a=>l({...o,width:a.target.value}),required:!0,type:"number",value:o.width})})}),d.jsx(m.Label,{className:"mb-[6px]",children:"Max Width"}),d.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:d.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:d.jsx(m.Input,{onChange:a=>l({...o,maxWidth:a.target.value}),required:!0,type:"number",value:o.maxWidth})})}),d.jsx(m.Label,{className:"mb-[6px]",children:"Height"}),d.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:d.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:d.jsx(m.Input,{onChange:a=>l({...o,height:a.target.value}),required:!0,type:"number",value:o.height})})}),d.jsx(m.Button,{className:"richtext-mt-2 richtext-self-end",type:"submit",children:r("editor.link.dialog.button.apply")})]})})]})},Nt=new Map;function Tl(e){const t=e.options.element;Nt.has("width")||Nt.set("width",t.clientWidth),Nt.has("width")&&Nt.get("width")<=0&&Nt.set("width",t.clientWidth);const n={attributes:!0,childList:!0,subtree:!0},i=function(){Nt.set("width",t.clientWidth)},s=new MutationObserver(i);return s.observe(t,n),e.on("destroy",()=>{s.disconnect()}),{width:Nt.get("width")}}function Al(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=B.useLocale(),{width:i}=Tl(t),s=ut.useAttributes(t,ue.Excalidraw.name,{defaultShowPicker:!1,createUser:"",width:0,height:0}),{defaultShowPicker:r,createUser:o,width:l,height:c}=s,a=b.useCallback(p=>{t.chain().updateAttributes(ue.Excalidraw.name,p).setNodeSelection(t.state.selection.from).focus().run()},[t]),u=b.useCallback(()=>{const p=m.EVENTS.EXCALIDRAW(t.id);m.emit(p,s)},[t,s]),h=b.useCallback(()=>t.isActive(ue.Excalidraw.name),[t]),f=b.useCallback(()=>Ht(ue.Excalidraw.name,t),[t]);return b.useEffect(()=>{r&&(u(),t.chain().updateAttributes(ue.Excalidraw.name,{defaultShowPicker:!1}).focus().run())},[o,r,t,u]),e?d.jsx(et,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleExcalidraw",shouldShow:h,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{action:u,icon:"Pencil",tooltip:n("editor.edit")}),d.jsx(qs,{height:c,maxWidth:i,onOk:a,width:l,children:d.jsx(m.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),d.jsx(m.ActionButton,{action:f,icon:"Trash2",tooltip:n("editor.delete")})]})}):d.jsx(d.Fragment,{})}function Il(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=B.useLocale(),{width:i,height:s,src:r}=ut.useAttributes(t,Wt.Iframe.name,{width:0,height:0,src:"",defaultShowPicker:!1}),[o,l]=b.useState(!1),[c,a]=b.useState(""),u=b.useCallback(w=>{var y;(y=w==null?void 0:w.preventDefault)==null||y.call(w),l(!1)},[l]);b.useEffect(()=>{o&&a(r)},[o,r]);const h=b.useCallback(w=>{var C;(C=w==null?void 0:w.preventDefault)==null||C.call(w);const y=Wt.getServiceSrc(c);t.chain().updateAttributes(Wt.Iframe.name,{src:(y==null?void 0:y.src)||c}).setNodeSelection(t.state.selection.from).focus().run(),l(!1)},[t,c,l]),f=b.useCallback(()=>{window.open(r,"_blank")},[r]),p=b.useCallback(w=>{t.chain().updateAttributes(Wt.Iframe.name,w).setNodeSelection(t.state.selection.from).focus().run()},[t]),g=b.useCallback(()=>t.isActive(Wt.Iframe.name)&&!r,[t,r]),x=b.useCallback(()=>Ht(Wt.Iframe.name,t),[t]);return e?d.jsx(d.Fragment,{children:d.jsx(et,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleIframe",shouldShow:g,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{action:f,icon:"Eye",tooltip:"Visit Link"}),d.jsxs(m.Dialog,{onOpenChange:l,open:o,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{icon:"Pencil",tooltip:"Open Edit Link"})}),d.jsxs(m.DialogContent,{children:[d.jsx(m.DialogHeader,{children:d.jsx(m.DialogTitle,{children:"Edit Link Iframe"})}),d.jsx(m.Input,{autoFocus:!0,onInput:w=>a(w.target.value),placeholder:"Enter link",type:"url",value:c}),d.jsxs(m.DialogFooter,{children:[d.jsx(m.Button,{onClick:u,type:"button",children:"Cancel"}),d.jsx(m.Button,{onClick:h,type:"button",children:"OK"})]})]})]}),d.jsx(qs,{height:s,onOk:p,width:i,children:d.jsx(m.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),d.jsx(m.ActionButton,{action:x,icon:"Trash2",tooltip:n("editor.delete")})]})})}):d.jsx(d.Fragment,{})}function Dl({children:e,visible:t,toggleVisible:n}){const{t:i}=B.useLocale(),s=m.useEditorInstance(),r=ut.useAttributes(s,ut.Katex.name,{text:"",macros:""}),{text:o,macros:l}=r,[c,a]=b.useState(decodeURIComponent(o||"")),[u,h]=b.useState(decodeURIComponent(l||""));b.useEffect(()=>{t&&(a(decodeURIComponent(o||"")),h(decodeURIComponent(l||"")))},[t]);const f=b.useCallback(()=>{s.chain().focus().setKatex({text:encodeURIComponent(c),macros:encodeURIComponent(u)}).run(),a(""),h(""),n(!1)},[s,c,u,n]),p=b.useMemo(()=>{try{return Do.renderToString(c,{macros:ut.safeJSONParse(u||"")})}catch{return c}},[c,u]),g=b.useMemo(()=>`${c}`.trim()?p:null,[c,p]);return d.jsxs(m.Dialog,{onOpenChange:n,open:t,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:e}),d.jsxs(m.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[d.jsx(m.DialogTitle,{children:i("editor.formula.dialog.text")}),d.jsx("div",{style:{height:"100%",border:"1px solid hsl(var(--border))"},children:d.jsxs("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[d.jsxs("div",{className:"richtext-flex-1",children:[d.jsx(m.Label,{className:"mb-[6px]",children:"Expression"}),d.jsx(Zn.Textarea,{autoFocus:!0,className:"richtext-mb-[10px]",onChange:x=>a(x.target.value),placeholder:"Text",required:!0,rows:10,value:c,style:{color:"hsl(var(--foreground))"}}),d.jsx(m.Label,{className:"mb-[6px]",children:"Macros"}),d.jsx(Zn.Textarea,{onChange:x=>h(x.target.value),placeholder:"Macros",rows:10,value:u,style:{color:"hsl(var(--foreground))"}})]}),d.jsx("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:g||""},style:{height:"100%",borderWidth:1,minHeight:500,background:"#fff"}})]})}),d.jsx(m.DialogFooter,{children:d.jsx(m.Button,{onClick:f,type:"button",children:"Save changes"})})]})]})}function Ml(){const e=m.useEditableEditor(),t=m.useEditorInstance(),[n,i]=b.useState(!1),s=b.useCallback(()=>t.isActive(ut.Katex.name),[t]),r=b.useCallback(()=>Ht(ut.Katex.name,t),[t]);return e?d.jsx(et,{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(Dl,{toggleVisible:i,visible:n,children:d.jsx(m.ActionButton,{action:()=>i(!n),tooltip:"Edit",children:d.jsx(Ut.Pencil,{size:16})})}),d.jsx(m.ActionButton,{action:r,tooltip:"Delete",children:d.jsx(Ut.Trash2,{size:16})})]})}):d.jsx(d.Fragment,{})}function Ol(e){const{t}=B.useLocale();return d.jsxs("div",{className:"richtext-flex richtext-flex-nowrap",children:[d.jsx(m.ActionButton,{disabled:!(e!=null&&e.link),icon:"ExternalLink",tooltip:t("editor.link.open.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{window.open(e==null?void 0:e.link,"_blank")}}),d.jsx(m.ActionButton,{icon:"Pencil",tooltip:t("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onEdit()}}),d.jsx(m.ActionButton,{icon:"Unlink",tooltip:t("editor.link.unlink.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onClear()}})]})}function jl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),[n,i]=b.useState(!1),s=ut.useAttributes(t,Ve.Link.name),r=s==null?void 0:s.href,o=b.useCallback(({editor:u})=>u.isActive(Ve.Link.name),[]),l=(u,h,f)=>{const p=t.state.selection,{from:g}=p,x=(h==null?void 0:h.length)??0,w=g+x;t.chain().extendMarkRange("link").insertContent({type:"text",text:h,marks:[{type:"link",attrs:{href:u,target:f?"_blank":""}}]}).setLink({href:u}).setTextSelection({from:g,to:w}).focus().run(),i(!1)},c=b.useCallback(()=>{t.chain().extendMarkRange("link").unsetLink().focus().run(),i(!1)},[t]),a=()=>{i(!1)};return e?d.jsx(et,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleLink",shouldShow:o,children:d.jsx(d.Fragment,{children:n?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-4 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(Ve.LinkEditBlock,{editor:t,onClose:a,onSetLink:l})}):d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(Ol,{editor:t,link:r,onClear:c,onEdit:()=>{i(!0)}})})})}):d.jsx(d.Fragment,{})}function wi({item:e,disabled:t,editor:n}){const i=e.component;return i?d.jsx(b.Fragment,{children:e.type==="divider"?d.jsx(bt.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 Rl(e){return e.type.name===m.Image.name}function Nl(e){return e.type.name===Io.ImageGif.name}function Bl(e){return e.type.name===m.Video.name}function Ll(){const{lang:e,t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:o})=>{const{selection:l}=o.view.state,{$from:c,to:a}=l;let u=!1;return o.view.state.doc.nodesBetween(c.pos,a,h=>{if(Rl(h))return u=!0,!1}),u},r=b.useMemo(()=>wl(i,t),[i,e,t]);return n?d.jsx(et,{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(wi,{editor:i,item:o},`bubbleMenu-image-${l}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function Ul(){const{lang:e,t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:o})=>{const{selection:l}=o.view.state,{$from:c,to:a}=l;let u=!1;return o.view.state.doc.nodesBetween(c.pos,a,h=>{if(Nl(h))return u=!0,!1}),u},r=b.useMemo(()=>yl(i,t),[i,t,e]);return n?d.jsx(et,{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(wi,{editor:i,item:o},`bubbleMenu-image-gif-${l}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function Pl(){const{t:e}=B.useLocale(),t=m.useEditableEditor(),n=m.useEditorInstance(),i=({editor:r})=>{const{selection:o}=r.view.state,{$from:l,to:c}=o;let a=!1;return r.view.state.doc.nodesBetween(l.pos,c,u=>{if(Bl(u))return a=!0,!1}),a},s=b.useMemo(()=>Cl(n,e),[n,e]);return t?d.jsx(et,{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(wi,{editor:n,item:r},`bubbleMenu-video-${o}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}const Ji=`graph TB
2
+ a-->b`,$l=({editor:e,attrs:t,extension:n})=>{const{alt:i,align:s}=t,[r,o]=b.useState(decodeURIComponent(i??Ji)),[l,c]=b.useState(""),[a,u]=b.useState(!1),h=b.useRef(null),[f,p]=b.useState(null),g=n==null?void 0:n.options.upload,x=b.useCallback(k=>{k&&import("mermaid").then(D=>{p(D.default)})},[]),w=async k=>{try{const{svg:D}=await f.render("mermaid-svg",k);c(D)}catch{c("")}},y=()=>{f.initialize({darkMode:!1,startOnLoad:!1,fontSize:12,theme:"base"}),w(r)};b.useEffect(()=>{f&&a&&y()},[f,a]),b.useEffect(()=>{f&&a&&w(r)},[f,r]);const C=async()=>{if(r!==""){if(r){const k=h.current.querySelector("svg"),{width:D,height:L}=k.getBoundingClientRect(),v=`mermaid-${Je.shortId()}.svg`;let S=Je.i(k.outerHTML);if(g){const A=m.dataURLtoFile(S,v);S=await g(A)}e==null||e.chain().focus().setMermaid({type:"mermaid",src:S,alt:encodeURIComponent(r),width:D,height:L},!!r).run(),e==null||e.commands.setAlignImageMermaid(s)}u(!1)}};return d.jsxs(m.Dialog,{onOpenChange:u,open:a,children:[d.jsx(m.DialogTrigger,{asChild:!0,children:d.jsx(m.ActionButton,{action:()=>u(!0),icon:"Pencil",tooltip:"Edit Mermaid"})}),d.jsxs(m.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[d.jsx(m.DialogTitle,{children:"Edit Mermaid"}),d.jsx("div",{ref:x,style:{height:"100%",border:"1px solid hsl(var(--border))"},children:d.jsxs("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[d.jsx(Zn.Textarea,{autoFocus:!0,className:"richtext-flex-1",defaultValue:Ji,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: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 Fl({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?d.jsx(b.Fragment,{children:e.type==="divider"?d.jsx(bt.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 Vl(e){return e.type.name===Qn.Mermaid.name}function Hl(){const{lang:e,t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=ut.useAttributes(i,Qn.Mermaid.name),r=m.useExtension(Qn.Mermaid.name),o=({editor:c})=>{const{selection:a}=c.view.state,{$from:u,to:h}=a;let f=!1;return c.view.state.doc.nodesBetween(u.pos,h,p=>{if(Vl(p))return f=!0,!1}),f},l=b.useMemo(()=>vl(i,t),[i,e,t]);return n?d.jsx(et,{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($l,{attrs:s,editor:i,extension:r},`bubbleMenu-mermaid-${a}`):d.jsx(Fl,{editor:i,item:c},`bubbleMenu-mermaid-${a}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function zl({hiddenActions:e=[]}){var x,w,y,C,k,D,L,v,S,A,z,N,$,Y,st,E,vt,Re;const{t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:qt})=>T.isActive(qt.view.state,Bs.Table.name),r=qt=>e.includes(qt);function o(){i.chain().focus().addColumnBefore().run()}function l(){i.chain().focus().addColumnAfter().run()}function c(){i.chain().focus().deleteColumn().run()}function a(){i.chain().focus().addRowBefore().run()}function u(){i.chain().focus().addRowAfter().run()}function h(){i.chain().focus().deleteRow().run()}function f(){i.chain().focus().mergeCells().run()}function p(){i==null||i.chain().focus().splitCell().run()}function g(){i.chain().focus().deleteTable().run()}return n?d.jsx(et,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTable",shouldShow:s,children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[!r("addColumnBefore")&&d.jsx(m.ActionButton,{action:o,disabled:!((w=(x=i==null?void 0:i.can())==null?void 0:x.addColumnBefore)!=null&&w.call(x)),icon:"BetweenHorizonalEnd",tooltip:t("editor.table.menu.insertColumnBefore"),tooltipOptions:{sideOffset:15}}),!r("addColumnAfter")&&d.jsx(m.ActionButton,{action:l,disabled:!((C=(y=i==null?void 0:i.can())==null?void 0:y.addColumnAfter)!=null&&C.call(y)),icon:"BetweenHorizonalStart",tooltip:t("editor.table.menu.insertColumnAfter"),tooltipOptions:{sideOffset:15}}),!r("deleteColumn")&&d.jsx(m.ActionButton,{action:c,disabled:!((D=i==null?void 0:(k=i.can()).deleteColumn)!=null&&D.call(k)),icon:"DeleteColumn",tooltip:t("editor.table.menu.deleteColumn"),tooltipOptions:{sideOffset:15}}),d.jsx(bt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!r("addRowAbove")&&d.jsx(m.ActionButton,{action:a,disabled:!((v=i==null?void 0:(L=i.can()).addRowBefore)!=null&&v.call(L)),icon:"BetweenVerticalEnd",tooltip:t("editor.table.menu.insertRowAbove"),tooltipOptions:{sideOffset:15}}),!r("addRowBelow")&&d.jsx(m.ActionButton,{action:u,disabled:!((A=(S=i==null?void 0:i.can())==null?void 0:S.addRowAfter)!=null&&A.call(S)),icon:"BetweenVerticalStart",tooltip:t("editor.table.menu.insertRowBelow"),tooltipOptions:{sideOffset:15}}),!r("deleteRow")&&d.jsx(m.ActionButton,{action:h,disabled:!((N=(z=i==null?void 0:i.can())==null?void 0:z.deleteRow)!=null&&N.call(z)),icon:"DeleteRow",tooltip:t("editor.table.menu.deleteRow"),tooltipOptions:{sideOffset:15}}),d.jsx(bt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!r("mergeCells")&&d.jsx(m.ActionButton,{action:f,disabled:!((Y=($=i==null?void 0:i.can())==null?void 0:$.mergeCells)!=null&&Y.call($)),icon:"TableCellsMerge",tooltip:t("editor.table.menu.mergeCells"),tooltipOptions:{sideOffset:15}}),!r("splitCells")&&d.jsx(m.ActionButton,{action:p,disabled:!((E=(st=i==null?void 0:i.can())==null?void 0:st.splitCell)!=null&&E.call(st)),icon:"TableCellsSplit",tooltip:t("editor.table.menu.splitCells"),tooltipOptions:{sideOffset:15}}),d.jsx(bt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!r("deleteTable")&&d.jsx(m.ActionButton,{action:g,disabled:!((Re=(vt=i==null?void 0:i.can())==null?void 0:vt.deleteTable)!=null&&Re.call(vt)),icon:"Trash2",tooltip:t("editor.table.menu.deleteTable"),tooltipOptions:{sideOffset:15}})]})}):d.jsx(d.Fragment,{})}function Kl(){const{t:e}=B.useLocale(),[t,n]=b.useState(!1),i=m.useEditorInstance(),s=b.useMemo(()=>{var o,l;return(l=(o=Uo.renderCommandListDefault({t:e}))==null?void 0:o[0])==null?void 0:l.commands},[e]),r=b.useMemo(()=>{var l;return(l=s==null?void 0:s.find(c=>{var a;return(a=c==null?void 0:c.isActive)==null?void 0:a.call(c,i)}))==null?void 0:l.label},[i.state.selection.ranges,t,i,s,e]);return d.jsxs(kt.Popover,{modal:!0,onOpenChange:n,open:t,children:[d.jsx(kt.PopoverTrigger,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:d.jsxs(m.ActionButton,{dataState:!!r,children:[r?d.jsx(d.Fragment,{children:r}):d.jsx(d.Fragment,{children:e("editor.paragraph.tooltip")}),d.jsx(m.IconComponent,{className:"richtext-ml-1 richtext-size-3 richtext-text-zinc-500",name:"MenuDown"})]})}),d.jsx(kt.PopoverContent,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:s==null?void 0:s.map(o=>{var c;const l=(c=o==null?void 0:o.isActive)==null?void 0:c.call(o,i);return d.jsxs("div",{className:"richtext-flex richtext-w-full richtext-items-center richtext-gap-3 richtext-rounded-sm !richtext-border-none !richtext-bg-transparent richtext-px-2 richtext-py-1.5 richtext-text-left richtext-text-sm richtext-text-foreground !richtext-outline-none richtext-transition-colors hover:!richtext-bg-accent",onClick:a=>{a.preventDefault(),o.action({editor:i,range:i.state.selection.ranges}),n(!1)},children:[d.jsxs("div",{className:"!richtext-min-w-[20px]",children:[l&&d.jsx(Ut.Check,{size:16}),!r&&o.label===e("editor.paragraph.tooltip")&&!l&&d.jsx(Ut.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 ql(){return d.jsxs(d.Fragment,{children:[d.jsx(Kl,{}),d.jsx(bt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(jo.RichTextBold,{}),d.jsx(Lo.RichTextItalic,{}),d.jsx($o.RichTextUnderline,{}),d.jsx(Po.RichTextStrike,{}),d.jsx(Ro.RichTextCode,{}),d.jsx(Ve.RichTextLink,{}),d.jsx(bt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(No.RichTextColor,{}),d.jsx(Bo.RichTextHighlight,{}),d.jsx(Ps.RichTextAlign,{})]})}function Wl({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 W.TextSelection};return n?d.jsx(et,{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(ql,{})})}):d.jsx(d.Fragment,{})}function Gl(){const{t:e}=B.useLocale(),t=m.useEditableEditor(),n=m.useEditorInstance(),[i,s]=b.useState(!1),r=b.useCallback(({editor:c})=>c.isActive(Bn.Twitter.name),[]),o=c=>{n.commands.updateTweet({src:c}),s(!1)},l=b.useCallback(()=>Ht(Bn.Twitter.name,n),[n]);return t?d.jsx(et,{editor:n,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTwitter",shouldShow:r,children:d.jsx(d.Fragment,{children:i?d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-4 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:d.jsx(Bn.FormEditLinkTwitter,{editor:n,onSetLink:o})}):d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[d.jsx(m.ActionButton,{icon:"Pencil",tooltip:e("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{s(!0)}}),d.jsx(m.ActionButton,{action:l,icon:"Trash",tooltip:e("editor.delete"),tooltipOptions:{sideOffset:15}})]})})}):d.jsx(d.Fragment,{})}const dt=()=>new Map,ei=e=>{const t=dt();return e.forEach((n,i)=>{t.set(i,n)}),t},Tt=(e,t,n)=>{let i=e.get(t);return i===void 0&&e.set(t,i=n()),i},Yl=(e,t)=>{const n=[];for(const[i,s]of e)n.push(t(s,i));return n},Jl=(e,t)=>{for(const[n,i]of e)if(t(i,n))return!0;return!1},Pt=()=>new Set,Un=e=>e[e.length-1],Xl=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},$t=Array.from,yi=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},vi=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},Zl=(e,t)=>{const n=new Array(e);for(let i=0;i<e;i++)n[i]=t(i,n);return n},te=Array.isArray;class Ws{constructor(){this._observers=dt()}on(t,n){return Tt(this._observers,t,Pt).add(n),n}once(t,n){const i=(...s)=>{this.off(t,i),n(...s)};this.on(t,i)}off(t,n){const i=this._observers.get(t);i!==void 0&&(i.delete(n),i.size===0&&this._observers.delete(t))}emit(t,n){return $t((this._observers.get(t)||dt()).values()).forEach(i=>i(...n))}destroy(){this._observers=dt()}}const ft=Math.floor,He=Math.abs,ee=(e,t)=>e<t?e:t,Ot=(e,t)=>e>t?e:t,Gs=e=>e!==0?e<0:1/e<0,Xi=1,Zi=2,Pn=4,$n=8,xe=32,Et=64,tt=128,Ql=1<<29,mn=31,ni=63,Lt=127,tc=2147483647,Xe=Number.MAX_SAFE_INTEGER,Qi=Number.MIN_SAFE_INTEGER,ec=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&ft(e)===e),Ys=String.fromCharCode,nc=e=>e.toLowerCase(),ic=/^\s*/g,sc=e=>e.replace(ic,""),rc=/([A-Z])/g,ts=(e,t)=>sc(e.replace(rc,n=>`${t}${nc(n)}`)),oc=e=>{const t=unescape(encodeURIComponent(e)),n=t.length,i=new Uint8Array(n);for(let s=0;s<n;s++)i[s]=t.codePointAt(s);return i},be=typeof TextEncoder<"u"?new TextEncoder:null,lc=e=>be.encode(e),cc=be?lc:oc;let ge=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});ge&&ge.decode(new Uint8Array).length===1&&(ge=null);const ac=(e,t)=>Zl(t,()=>e).join("");class Ie{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const De=()=>new Ie,hc=e=>{const t=De();return e(t),ht(t)},uc=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},ht=e=>{const t=new Uint8Array(uc(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},dc=(e,t)=>{const n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(Ot(n,t)*2),e.cpos=0)},K=(e,t)=>{const n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},ii=K,I=(e,t)=>{for(;t>Lt;)K(e,tt|Lt&t),t=ft(t/128);K(e,Lt&t)},Si=(e,t)=>{const n=Gs(t);for(n&&(t=-t),K(e,(t>ni?tt:0)|(n?Et:0)|ni&t),t=ft(t/64);t>0;)K(e,(t>Lt?tt:0)|Lt&t),t=ft(t/128)},si=new Uint8Array(3e4),fc=si.length/3,pc=(e,t)=>{if(t.length<fc){const n=be.encodeInto(t,si).written||0;I(e,n);for(let i=0;i<n;i++)K(e,si[i])}else rt(e,cc(t))},gc=(e,t)=>{const n=unescape(encodeURIComponent(t)),i=n.length;I(e,i);for(let s=0;s<i;s++)K(e,n.codePointAt(s))},Yt=be&&be.encodeInto?pc:gc,xn=(e,t)=>{const n=e.cbuf.length,i=e.cpos,s=ee(n-i,t.length),r=t.length-s;e.cbuf.set(t.subarray(0,s),i),e.cpos+=s,r>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(Ot(n*2,r)),e.cbuf.set(t.subarray(s)),e.cpos=r)},rt=(e,t)=>{I(e,t.byteLength),xn(e,t)},Ci=(e,t)=>{dc(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},mc=(e,t)=>Ci(e,4).setFloat32(0,t,!1),xc=(e,t)=>Ci(e,8).setFloat64(0,t,!1),bc=(e,t)=>Ci(e,8).setBigInt64(0,t,!1),es=new DataView(new ArrayBuffer(4)),wc=e=>(es.setFloat32(0,e),es.getFloat32(0)===e),ne=(e,t)=>{switch(typeof t){case"string":K(e,119),Yt(e,t);break;case"number":ec(t)&&He(t)<=tc?(K(e,125),Si(e,t)):wc(t)?(K(e,124),mc(e,t)):(K(e,123),xc(e,t));break;case"bigint":K(e,122),bc(e,t);break;case"object":if(t===null)K(e,126);else if(te(t)){K(e,117),I(e,t.length);for(let n=0;n<t.length;n++)ne(e,t[n])}else if(t instanceof Uint8Array)K(e,116),rt(e,t);else{K(e,118);const n=Object.keys(t);I(e,n.length);for(let i=0;i<n.length;i++){const s=n[i];Yt(e,s),ne(e,t[s])}}break;case"boolean":K(e,t?120:121);break;default:K(e,127)}};class ns extends Ie{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 is=e=>{e.count>0&&(Si(e.encoder,e.count===1?e.s:-e.s),e.count>1&&I(e.encoder,e.count-2))};class ze{constructor(){this.encoder=new Ie,this.s=0,this.count=0}write(t){this.s===t?this.count++:(is(this),this.count=1,this.s=t)}toUint8Array(){return is(this),ht(this.encoder)}}const ss=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);Si(e.encoder,t),e.count>1&&I(e.encoder,e.count-2)}};class Fn{constructor(){this.encoder=new Ie,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(ss(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return ss(this),ht(this.encoder)}}class yc{constructor(){this.sarr=[],this.s="",this.lensE=new ze}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new Ie;return this.sarr.push(this.s),this.s="",Yt(t,this.sarr.join("")),xn(t,this.lensE.toUint8Array()),ht(t)}}const yt=e=>new Error(e),ct=()=>{throw yt("Method unimplemented")},Z=()=>{throw yt("Unexpected case")},Js=yt("Unexpected end of array"),Xs=yt("Integer out of Range");class bn{constructor(t){this.arr=t,this.pos=0}}const ki=e=>new bn(e),vc=e=>e.pos!==e.arr.length,Sc=(e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},ot=e=>Sc(e,j(e)),we=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&Lt)*n,n*=128,s<tt)return t;if(t>Xe)throw Xs}throw Js},Ei=e=>{let t=e.arr[e.pos++],n=t&ni,i=64;const s=(t&Et)>0?-1:1;if((t&tt)===0)return s*n;const r=e.arr.length;for(;e.pos<r;){if(t=e.arr[e.pos++],n=n+(t&Lt)*i,i*=128,t<tt)return s*n;if(n>Xe)throw Xs}throw Js},Cc=e=>{let t=j(e);if(t===0)return"";{let n=String.fromCodePoint(we(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(we(e));else for(;t>0;){const i=t<1e4?t:1e4,s=e.arr.subarray(e.pos,e.pos+i);e.pos+=i,n+=String.fromCodePoint.apply(null,s),t-=i}return decodeURIComponent(escape(n))}},kc=e=>ge.decode(ot(e)),ri=ge?kc:Cc,_i=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},Ec=e=>_i(e,4).getFloat32(0,!1),_c=e=>_i(e,8).getFloat64(0,!1),Tc=e=>_i(e,8).getBigInt64(0,!1),Ac=[e=>{},e=>null,Ei,Ec,_c,Tc,e=>!1,e=>!0,ri,e=>{const t=j(e),n={};for(let i=0;i<t;i++){const s=ri(e);n[s]=Ze(e)}return n},e=>{const t=j(e),n=[];for(let i=0;i<t;i++)n.push(Ze(e));return n},ot],Ze=e=>Ac[127-we(e)](e);class rs extends bn{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),vc(this)?this.count=j(this)+1:this.count=-1),this.count--,this.s}}class Ke extends bn{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Ei(this);const t=Gs(this.s);this.count=1,t&&(this.s=-this.s,this.count=j(this)+2)}return this.count--,this.s}}class Vn extends bn{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=Ei(this),n=t&1;this.diff=ft(t/2),this.count=1,n&&(this.count=j(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Ic{constructor(t){this.decoder=new Ke(t),this.str=ri(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}}const Dc=crypto.getRandomValues.bind(crypto),Mc=Math.random,Zs=()=>Dc(new Uint32Array(1))[0],Oc=e=>e[ft(Mc()*e.length)],jc="10000000-1000-4000-8000"+-1e11,Rc=()=>jc.replace(/[018]/g,e=>(e^Zs()&15>>e/4).toString(16)),Nc=Date.now,os=e=>new Promise(e);Promise.all.bind(Promise);const ls=e=>e===void 0?null:e;class Bc{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}}let Qs=new Bc,Lc=!0;try{typeof localStorage<"u"&&localStorage&&(Qs=localStorage,Lc=!1)}catch{}const Uc=Qs,ye=Symbol("Equality"),tr=(e,t)=>{var n;return e===t||!!((n=e==null?void 0:e[ye])!=null&&n.call(e,t))||!1},Pc=e=>typeof e=="object",$c=Object.assign,er=Object.keys,Fc=(e,t)=>{for(const n in e)t(e[n],n)},Qe=e=>er(e).length,Vc=e=>{for(const t in e)return!1;return!0},oe=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},Ti=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Hc=(e,t)=>e===t||Qe(e)===Qe(t)&&oe(e,(n,i)=>(n!==void 0||Ti(t,i))&&tr(t[i],n)),zc=Object.freeze,nr=e=>{for(const t in e){const n=e[t];(typeof n=="object"||typeof n=="function")&&nr(e[t])}return zc(e)},Ai=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Ai(e,t,n+1)}},qe=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[ye]!=null)return e[ye](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:{if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break}case Set:{if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;break}case Map:{if(e.size!==t.size)return!1;for(const n of e.keys())if(!t.has(n)||!qe(e.get(n),t.get(n)))return!1;break}case void 0:case Object:if(Qe(e)!==Qe(t))return!1;for(const n in e)if(!Ti(e,n)||!qe(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!qe(e[n],t[n]))return!1;break;default:return!1}return!0},Kc=(e,t)=>t.includes(e),ie=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",ir=typeof window<"u"&&typeof document<"u"&&!ie;let xt;const qc=()=>{if(xt===void 0)if(ie){xt=dt();const e=process.argv;let t=null;for(let n=0;n<e.length;n++){const i=e[n];i[0]==="-"?(t!==null&&xt.set(t,""),t=i):t!==null&&(xt.set(t,i),t=null)}t!==null&&xt.set(t,"")}else typeof location=="object"?(xt=dt(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){const[t,n]=e.split("=");xt.set(`--${ts(t,"-")}`,n),xt.set(`-${ts(t,"-")}`,n)}})):xt=dt();return xt},oi=e=>qc().has(e),tn=e=>ls(ie?process.env[e.toUpperCase().replaceAll("-","_")]:Uc.getItem(e)),sr=e=>oi("--"+e)||tn(e)!==null,Wc=sr("production"),Gc=ie&&Kc(process.env.FORCE_COLOR,["true","1","2"]),Yc=Gc||!oi("--no-colors")&&!sr("no-color")&&(!ie||process.stdout.isTTY)&&(!ie||oi("--color")||tn("COLORTERM")!==null||(tn("TERM")||"").includes("color")),Jc=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=Ys(e[n]);return btoa(t)},Xc=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),Zc=ir?Jc:Xc,Qc=e=>hc(t=>ne(t,e));class ta{constructor(t,n){this.left=t,this.right=n}}const Ct=(e,t)=>new ta(e,t),cs=e=>e.next()>=.5,Hn=(e,t,n)=>ft(e.next()*(n+1-t)+t),rr=(e,t,n)=>ft(e.next()*(n+1-t)+t),Ii=(e,t,n)=>rr(e,t,n),ea=e=>Ys(Ii(e,97,122)),na=(e,t=0,n=20)=>{const i=Ii(e,t,n);let s="";for(let r=0;r<i;r++)s+=ea(e);return s},zn=(e,t)=>t[Ii(e,0,t.length-1)],ia=Symbol("0schema");class sa{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(ac(" ",(this._rerrs.length-n)*2)+`${i.path!=null?`[${i.path}] `:""}${i.has} doesn't match ${i.expected}. ${i.message}`)}return t.join(`
3
+ `)}}const li=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[ye]?tr(e,t):te(e)?yi(e,n=>vi(t,i=>li(n,i))):Pc(e)?oe(e,(n,i)=>li(n,t[i])):!1;class Q{extends(t){let[n,i]=[this.shape,t.shape];return this.constructor._dilutes&&([i,n]=[n,i]),li(n,i)}equals(t){return this.constructor===t.constructor&&qe(this.shape,t.shape)}[ia](){return!0}[ye](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){ct()}get nullable(){return le(this,Cn)}get optional(){return new cr(this)}cast(t){return as(t,this),t}expect(t){return as(t,this),t}}Ne(Q,"_dilutes",!1);class Di extends Q{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n=void 0){const i=(t==null?void 0:t.constructor)===this.shape&&(this._c==null||this._c(t));return!i&&(n==null||n.extend(null,this.shape.name,t==null?void 0:t.constructor.name,(t==null?void 0:t.constructor)!==this.shape?"Constructor match failed":"Check failed")),i}}const V=(e,t=null)=>new Di(e,t);V(Di);class Mi extends Q{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 Mi(e);V(Mi);class wn extends Q{constructor(t){super(),this.shape=t}check(t,n){const i=this.shape.some(s=>s===t);return!i&&(n==null||n.extend(null,this.shape.join(" | "),t.toString())),i}}const yn=(...e)=>new wn(e),or=V(wn),ra=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,t=>"\\"+t)),lr=e=>{if(se.check(e))return[ra(e)];if(or.check(e))return e.shape.map(t=>t+"");if(xr.check(e))return["[+-]?\\d+.?\\d*"];if(br.check(e))return[".*"];if(nn.check(e))return e.shape.map(lr).flat(1);Z()};class oa extends Q{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(lr).map(n=>`(${n.join("|")})`).join("")+"$")}check(t,n){const i=this._r.exec(t)!=null;return!i&&(n==null||n.extend(null,this._r.toString(),t.toString(),"String doesn't match string template.")),i}}V(oa);const la=Symbol("optional");class cr extends Q{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[la](){return!0}}const ca=V(cr);class aa extends Q{check(t,n){return n==null||n.extend(null,"never",typeof t),!1}}V(aa);const gn=class gn extends Q{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}get partial(){return new gn(this.shape,!0)}check(t,n){return t==null?(n==null||n.extend(null,"object","null"),!1):oe(this.shape,(i,s)=>{const r=this._isPartial&&!Ti(t,s)||i.check(t[s],n);return!r&&(n==null||n.extend(s.toString(),i.toString(),typeof t[s],"Object property does not match")),r})}};Ne(gn,"_dilutes",!0);let en=gn;const ha=e=>new en(e),ua=V(en),da=G(e=>e!=null&&(e.constructor===Object||e.constructor==null));class ar extends Q{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return t!=null&&oe(t,(i,s)=>{const r=this.shape.keys.check(s,n);return!r&&(n==null||n.extend(s+"","Record",typeof t,r?"Key doesn't match schema":"Value doesn't match value")),r&&this.shape.values.check(i,n)})}}const hr=(e,t)=>new ar(e,t),fa=V(ar);class ur extends Q{constructor(t){super(),this.shape=t}check(t,n){return t!=null&&oe(this.shape,(i,s)=>{const r=i.check(t[s],n);return!r&&(n==null||n.extend(s.toString(),"Tuple",typeof i)),r})}}const pa=(...e)=>new ur(e);V(ur);class dr extends Q{constructor(t){super(),this.shape=t.length===1?t[0]:new vn(t)}check(t,n){const i=te(t)&&yi(t,s=>this.shape.check(s));return!i&&(n==null||n.extend(null,"Array","")),i}}const fr=(...e)=>new dr(e),ga=V(dr),ma=G(e=>te(e));class pr extends Q{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 xa=(e,t=null)=>new pr(e,t);V(pr);const ba=xa(Q);class wa extends Q{constructor(t){super(),this.len=t.length-1,this.args=pa(...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 ya=V(wa),va=G(e=>typeof e=="function");class Sa extends Q{constructor(t){super(),this.shape=t}check(t,n){const i=yi(this.shape,s=>s.check(t,n));return!i&&(n==null||n.extend(null,"Intersectinon",typeof t)),i}}V(Sa,e=>e.shape.length>0);class vn extends Q{constructor(t){super(),this.shape=t}check(t,n){const i=vi(this.shape,s=>s.check(t,n));return n==null||n.extend(null,"Union",typeof t),i}}Ne(vn,"_dilutes",!0);const le=(...e)=>e.findIndex(t=>nn.check(t))>=0?le(...e.map(t=>ve(t)).map(t=>nn.check(t)?t.shape:[t]).flat(1)):e.length===1?e[0]:new vn(e),nn=V(vn),gr=()=>!0,sn=G(gr),Ca=V(Mi,e=>e.shape===gr),Oi=G(e=>typeof e=="bigint"),ka=G(e=>e===Oi),mr=G(e=>typeof e=="symbol");G(e=>e===mr);const Jt=G(e=>typeof e=="number"),xr=G(e=>e===Jt),se=G(e=>typeof e=="string"),br=G(e=>e===se),Sn=G(e=>typeof e=="boolean"),Ea=G(e=>e===Sn),wr=yn(void 0);V(wn,e=>e.shape.length===1&&e.shape[0]===void 0);yn(void 0);const Cn=yn(null),_a=V(wn,e=>e.shape.length===1&&e.shape[0]===null);V(Uint8Array);V(Di,e=>e.shape===Uint8Array);const Ta=le(Jt,se,Cn,wr,Oi,Sn,mr);(()=>{const e=fr(sn),t=hr(se,sn),n=le(Jt,se,Cn,Sn,e,t);return e.shape=n,t.shape.values=n,n})();const ve=e=>{if(ba.check(e))return e;if(da.check(e)){const t={};for(const n in e)t[n]=ve(e[n]);return ha(t)}else{if(ma.check(e))return le(...e.map(ve));if(Ta.check(e))return yn(e);if(va.check(e))return V(e)}Z()},as=Wc?()=>{}:(e,t)=>{const n=new sa;if(!t.check(e,n))throw yt(`Expected value to be of type ${t.constructor.name}.
4
+ ${n.toString()}`)};class Aa{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:ve(t),h:n}),this}else(t){return this.if(sn,t)}done(){return(t,n)=>{for(let i=0;i<this.patterns.length;i++){const s=this.patterns[i];if(s.if.check(t))return s.h(t,n)}throw yt("Unhandled pattern")}}}const Ia=e=>new Aa(e),yr=Ia(sn).if(xr,(e,t)=>Hn(t,Qi,Xe)).if(br,(e,t)=>na(t)).if(Ea,(e,t)=>cs(t)).if(ka,(e,t)=>BigInt(Hn(t,Qi,Xe))).if(nn,(e,t)=>Gt(t,zn(t,e.shape))).if(ua,(e,t)=>{const n={};for(const i in e.shape){let s=e.shape[i];if(ca.check(s)){if(cs(t))continue;s=s.shape}n[i]=yr(s,t)}return n}).if(ga,(e,t)=>{const n=[],i=rr(t,0,42);for(let s=0;s<i;s++)n.push(Gt(t,e.shape));return n}).if(or,(e,t)=>zn(t,e.shape)).if(_a,(e,t)=>null).if(ya,(e,t)=>{const n=Gt(t,e.res);return()=>n}).if(Ca,(e,t)=>Gt(t,zn(t,[Jt,se,Cn,wr,Oi,Sn,fr(Jt),hr(le("a","b","c"),Jt)]))).if(fa,(e,t)=>{const n={},i=Hn(t,0,3);for(let s=0;s<i;s++){const r=Gt(t,e.shape.keys),o=Gt(t,e.shape.values);n[r]=o}return n}).done(),Gt=(e,t)=>yr(ve(t),e),Me=typeof document<"u"?document:{};G(e=>e.nodeType===Ra);typeof DOMParser<"u"&&new DOMParser;G(e=>e.nodeType===Ma);G(e=>e.nodeType===Oa);const Da=e=>Yl(e,(t,n)=>`${n}:${t};`).join(""),Ma=Me.ELEMENT_NODE,Oa=Me.TEXT_NODE,ja=Me.DOCUMENT_NODE,Ra=Me.DOCUMENT_FRAGMENT_NODE;G(e=>e.nodeType===ja);const Na=e=>class{constructor(n){this._=n}destroy(){e(this._)}},Ba=Na(clearTimeout),vr=(e,t)=>new Ba(setTimeout(t,e)),At=Symbol,Sr=At(),Cr=At(),La=At(),Ua=At(),Pa=At(),kr=At(),$a=At(),ji=At(),Fa=At(),Va=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},Ha={[Sr]:Ct("font-weight","bold"),[Cr]:Ct("font-weight","normal"),[La]:Ct("color","blue"),[Pa]:Ct("color","green"),[Ua]:Ct("color","grey"),[kr]:Ct("color","red"),[$a]:Ct("color","purple"),[ji]:Ct("color","orange"),[Fa]:Ct("color","black")},za=e=>{var o;e.length===1&&((o=e[0])==null?void 0:o.constructor)===Function&&(e=e[0]());const t=[],n=[],i=dt();let s=[],r=0;for(;r<e.length;r++){const l=e[r],c=Ha[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=Da(i);r>0||a.length>0?(t.push("%c"+l),n.push(a)):t.push(l)}else break}}for(r>0&&(s=n,s.unshift(t.join("")));r<e.length;r++){const l=e[r];l instanceof Symbol||s.push(l)}return s},Er=Yc?za:Va,Ka=(...e)=>{console.log(...Er(e)),Tr.forEach(t=>t.print(e))},_r=(...e)=>{console.warn(...Er(e)),e.unshift(ji),Tr.forEach(t=>t.print(e))},Tr=Pt(),Ar=e=>({[Symbol.iterator](){return this},next:e}),qa=(e,t)=>Ar(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),Kn=(e,t)=>Ar(()=>{const{done:n,value:i}=e.next();return{done:n,value:n?void 0:t(i)}});class kn{constructor(t,n){this.clock=t,this.len=n}}class ce{constructor(){this.clients=new Map}}const jt=(e,t,n)=>t.clients.forEach((i,s)=>{const r=e.doc.store.clients.get(s);if(r!=null){const o=r[r.length-1],l=o.id.clock+o.length;for(let c=0,a=i[c];c<i.length&&a.clock<l;a=i[++c])Br(e,r,a.clock,a.len,n)}}),Wa=(e,t)=>{let n=0,i=e.length-1;for(;n<=i;){const s=ft((n+i)/2),r=e[s],o=r.clock;if(o<=t){if(t<o+r.len)return s;n=s+1}else i=s-1}return null},ae=(e,t)=>{const n=e.clients.get(t.client);return n!==void 0&&Wa(n,t.clock)!==null},Ri=e=>{e.clients.forEach(t=>{t.sort((s,r)=>s.clock-r.clock);let n,i;for(n=1,i=1;n<t.length;n++){const s=t[i-1],r=t[n];s.clock+s.len>=r.clock?t[i-1]=new kn(s.clock,Ot(s.len,r.clock+r.len-s.clock)):(i<n&&(t[i]=r),i++)}t.length=i})},ci=e=>{const t=new ce;for(let n=0;n<e.length;n++)e[n].clients.forEach((i,s)=>{if(!t.clients.has(s)){const r=i.slice();for(let o=n+1;o<e.length;o++)Xl(r,e[o].clients.get(s)||[]);t.clients.set(s,r)}});return Ri(t),t},Se=(e,t,n,i)=>{Tt(e.clients,t,()=>[]).push(new kn(n,i))},Ir=()=>new ce,Ga=e=>{const t=Ir();return e.clients.forEach((n,i)=>{const s=[];for(let r=0;r<n.length;r++){const o=n[r];if(o.deleted){const l=o.id.clock;let c=o.length;if(r+1<n.length)for(let a=n[r+1];r+1<n.length&&a.deleted;a=n[++r+1])c+=a.length;s.push(new kn(l,c))}}s.length>0&&t.clients.set(i,s)}),t},Ni=(e,t)=>{I(e.restEncoder,t.clients.size),$t(t.clients.entries()).sort((n,i)=>i[0]-n[0]).forEach(([n,i])=>{e.resetDsCurVal(),I(e.restEncoder,n);const s=i.length;I(e.restEncoder,s);for(let r=0;r<s;r++){const o=i[r];e.writeDsClock(o.clock),e.writeDsLen(o.len)}})},Ya=e=>{const t=new ce,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=Tt(t.clients,s,()=>[]);for(let l=0;l<r;l++)o.push(new kn(e.readDsClock(),e.readDsLen()))}}return t},hs=(e,t,n)=>{const i=new ce,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=P(n,o);for(let u=0;u<l;u++){const h=e.readDsClock(),f=h+e.readDsLen();if(h<a){a<f&&Se(i,o,a,f-a);let p=pt(c,h),g=c[p];for(!g.deleted&&g.id.clock<h&&(c.splice(p+1,0,un(t,g,h-g.id.clock)),p++);p<c.length&&(g=c[p++],g.id.clock<f);)g.deleted||(f<g.id.clock+g.length&&c.splice(p,0,un(t,g,f-g.id.clock)),g.delete(t))}else Se(i,o,h,f-h)}}if(i.clients.size>0){const r=new En;return I(r.restEncoder,0),Ni(r,i),r.toUint8Array()}return null},Dr=Zs;class zt extends Ws{constructor({guid:t=Rc(),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=Dr(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new Rr,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=o,this.meta=r,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=os(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const c=()=>os(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&&O(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set($t(this.subdocs).map(t=>t.guid))}transact(t,n=null){return O(this,t,n)}get(t,n=q){const i=Tt(this.share,t,()=>{const r=new n;return r._integrate(this,null),r}),s=i.constructor;if(n!==q&&s!==n)if(s===q){const r=new n;r._map=i._map,i._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=r}),r._start=i._start;for(let o=r._start;o!==null;o=o.right)o.parent=r;return r._length=i._length,this.share.set(t,r),r._integrate(this,null),r}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return i}getArray(t=""){return this.get(t,Qt)}getText(t=""){return this.get(t,Rt)}getMap(t=""){return this.get(t,re)}getXmlElement(t=""){return this.get(t,J)}getXmlFragment(t=""){return this.get(t,Ft)}toJSON(){const t={};return this.share.forEach((n,i)=>{t[i]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,$t(this.subdocs).forEach(n=>n.destroy());const t=this._item;if(t!==null){this._item=null;const n=t.content;n.doc=new zt({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,O(t.parent.doc,i=>{const s=n.doc;t.deleted||i.subdocsAdded.add(s),i.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class Ja{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 rn extends Ja{constructor(t){super(t),this.keys=[],j(t),this.keyClockDecoder=new Vn(ot(t)),this.clientDecoder=new Ke(ot(t)),this.leftClockDecoder=new Vn(ot(t)),this.rightClockDecoder=new Vn(ot(t)),this.infoDecoder=new rs(ot(t),we),this.stringDecoder=new Ic(ot(t)),this.parentInfoDecoder=new rs(ot(t),we),this.typeRefDecoder=new Ke(ot(t)),this.lenDecoder=new Ke(ot(t))}readLeftID(){return new Xt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Xt(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Ze(this.restDecoder)}readBuf(){return ot(this.restDecoder)}readJSON(){return Ze(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{const n=this.stringDecoder.read();return this.keys.push(n),n}}}class Xa{constructor(){this.restEncoder=De()}toUint8Array(){return ht(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){I(this.restEncoder,t)}writeDsLen(t){I(this.restEncoder,t)}}class Za extends Xa{writeLeftID(t){I(this.restEncoder,t.client),I(this.restEncoder,t.clock)}writeRightID(t){I(this.restEncoder,t.client),I(this.restEncoder,t.clock)}writeClient(t){I(this.restEncoder,t)}writeInfo(t){ii(this.restEncoder,t)}writeString(t){Yt(this.restEncoder,t)}writeParentInfo(t){I(this.restEncoder,t?1:0)}writeTypeRef(t){I(this.restEncoder,t)}writeLen(t){I(this.restEncoder,t)}writeAny(t){ne(this.restEncoder,t)}writeBuf(t){rt(this.restEncoder,t)}writeJSON(t){Yt(this.restEncoder,JSON.stringify(t))}writeKey(t){Yt(this.restEncoder,t)}}class Qa{constructor(){this.restEncoder=De(),this.dsCurrVal=0}toUint8Array(){return ht(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,I(this.restEncoder,n)}writeDsLen(t){t===0&&Z(),I(this.restEncoder,t-1),this.dsCurrVal+=t}}class En extends Qa{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Fn,this.clientEncoder=new ze,this.leftClockEncoder=new Fn,this.rightClockEncoder=new Fn,this.infoEncoder=new ns(ii),this.stringEncoder=new yc,this.parentInfoEncoder=new ns(ii),this.typeRefEncoder=new ze,this.lenEncoder=new ze}toUint8Array(){const t=De();return I(t,0),rt(t,this.keyClockEncoder.toUint8Array()),rt(t,this.clientEncoder.toUint8Array()),rt(t,this.leftClockEncoder.toUint8Array()),rt(t,this.rightClockEncoder.toUint8Array()),rt(t,ht(this.infoEncoder)),rt(t,this.stringEncoder.toUint8Array()),rt(t,ht(this.parentInfoEncoder)),rt(t,this.typeRefEncoder.toUint8Array()),rt(t,this.lenEncoder.toUint8Array()),xn(t,ht(this.restEncoder)),ht(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){ne(this.restEncoder,t)}writeBuf(t){rt(this.restEncoder,t)}writeJSON(t){ne(this.restEncoder,t)}writeKey(t){const n=this.keyMap.get(t);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}}const th=(e,t,n,i)=>{i=Ot(i,t[0].id.clock);const s=pt(t,i);I(e.restEncoder,t.length-s),e.writeClient(n),I(e.restEncoder,i);const r=t[s];r.write(e,i-r.id.clock);for(let o=s+1;o<t.length;o++)t[o].write(e,0)},Mr=(e,t,n)=>{const i=new Map;n.forEach((s,r)=>{P(t,r)>s&&i.set(r,s)}),_n(t).forEach((s,r)=>{n.has(r)||i.set(r,0)}),I(e.restEncoder,i.size),$t(i.entries()).sort((s,r)=>r[0]-s[0]).forEach(([s,r])=>{th(e,t.clients.get(s),s,r)})},eh=(e,t)=>{const n=dt(),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 u=e.readInfo();switch(mn&u){case 0:{const h=e.readLen();o[a]=new lt(_(l,c),h),c+=h;break}case 10:{const h=j(e.restDecoder);o[a]=new at(_(l,c),h),c+=h;break}default:{const h=(u&(Et|tt))===0,f=new M(_(l,c),null,(u&tt)===tt?e.readLeftID():null,null,(u&Et)===Et?e.readRightID():null,h?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,h&&(u&xe)===xe?e.readString():null,so(e,u));o[a]=f,c+=f.length}}}}return n},nh=(e,t,n)=>{const i=[];let s=$t(n.keys()).sort((p,g)=>p-g);if(s.length===0)return null;const r=()=>{if(s.length===0)return null;let p=n.get(s[s.length-1]);for(;p.refs.length===p.i;)if(s.pop(),s.length>0)p=n.get(s[s.length-1]);else return null;return p};let o=r();if(o===null)return null;const l=new Rr,c=new Map,a=(p,g)=>{const x=c.get(p);(x==null||x>g)&&c.set(p,g)};let u=o.refs[o.i++];const h=new Map,f=()=>{for(const p of i){const g=p.id.client,x=n.get(g);x?(x.i--,l.clients.set(g,x.refs.slice(x.i)),n.delete(g),x.i=0,x.refs=[]):l.clients.set(g,[p]),s=s.filter(w=>w!==g)}i.length=0};for(;;){if(u.constructor!==at){const g=Tt(h,u.id.client,()=>P(t,u.id.client))-u.id.clock;if(g<0)i.push(u),a(u.id.client,u.id.clock-1),f();else{const x=u.getMissing(e,t);if(x!==null){i.push(u);const w=n.get(x)||{refs:[],i:0};if(w.refs.length===w.i)a(x,P(t,x)),f();else{u=w.refs[w.i++];continue}}else(g===0||g<u.length)&&(u.integrate(e,g),h.set(u.id.client,u.id.clock+u.length))}}if(i.length>0)u=i.pop();else if(o!==null&&o.i<o.refs.length)u=o.refs[o.i++];else{if(o=r(),o===null)break;u=o.refs[o.i++]}}if(l.clients.size>0){const p=new En;return Mr(p,l,new Map),I(p.restEncoder,0),{missing:c,update:p.toUint8Array()}}return null},ih=(e,t)=>Mr(e,t.doc.store,t.beforeState),sh=(e,t,n,i=new rn(e))=>O(t,s=>{s.local=!1;let r=!1;const o=s.doc,l=o.store,c=eh(i,o),a=nh(s,l,c),u=l.pendingStructs;if(u){for(const[f,p]of u.missing)if(p<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=ws([u.update,a.update])}}else l.pendingStructs=a;const h=hs(i,s,l);if(l.pendingDs){const f=new rn(ki(l.pendingDs));j(f.restDecoder);const p=hs(f,s,l);h&&p?l.pendingDs=ws([h,p]):l.pendingDs=h||p}else l.pendingDs=h;if(r){const f=l.pendingStructs.update;l.pendingStructs=null,ai(s.doc,f)}},n,!1),ai=(e,t,n,i=rn)=>{const s=ki(t);sh(s,e,n,new i(s))};class rh{constructor(){this.l=[]}}const us=()=>new rh,ds=(e,t)=>e.l.push(t),fs=(e,t)=>{const n=e.l,i=n.length;e.l=n.filter(s=>t!==s),i===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Or=(e,t,n)=>Ai(e.l,[t,n]);class Xt{constructor(t,n){this.client=t,this.clock=n}}const Be=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,_=(e,t)=>new Xt(e,t),Ce=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw Z()},ke=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1};class on{constructor(t,n,i,s=0){this.type=t,this.tname=n,this.item=i,this.assoc=s}}class oh{constructor(t,n,i=0){this.type=t,this.index=n,this.assoc=i}}const lh=(e,t,n=0)=>new oh(e,t,n),Le=(e,t,n)=>{let i=null,s=null;return e._item===null?s=Ce(e):i=_(e._item.id.client,e._item.id.clock),new on(i,s,t,n)},qn=(e,t,n=0)=>{let i=e._start;if(n<0){if(t===0)return Le(e,null,n);t--}for(;i!==null;){if(!i.deleted&&i.countable){if(i.length>t)return Le(e,_(i.id.client,i.id.clock+t),n);t-=i.length}if(i.right===null&&n<0)return Le(e,i.lastId,n);i=i.right}return Le(e,null,n)},ch=(e,t)=>{const n=Zt(e,t),i=t.clock-n.id.clock;return{item:n,diff:i}},ah=(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(P(i,s.client)<=s.clock)return null;const u=n?fi(i,s):ch(i,s),h=u.item;if(!(h instanceof M))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(P(i,r.client)<=r.clock)return null;const{item:u}=n?fi(i,r):{item:Zt(i,r)};if(u instanceof M&&u.content instanceof mt)c=u.content.type;else return null}else throw Z();l>=0?a=c._length:a=0}return lh(c,a,e.assoc)};class Bi{constructor(t,n){this.ds=t,this.sv=n}}const jr=(e,t)=>new Bi(e,t),Wn=e=>jr(Ga(e.store),_n(e.store)),Bt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!ae(t.ds,e.id),hi=(e,t)=>{const n=Tt(e.meta,hi,Pt),i=e.doc.store;n.has(t)||(t.sv.forEach((s,r)=>{s<P(i,r)&&nt(e,_(r,s))}),jt(e,t.ds,s=>{}),n.add(t))};class Rr{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const _n=e=>{const t=new Map;return e.clients.forEach((n,i)=>{const s=n[n.length-1];t.set(i,s.id.clock+s.length)}),t},P=(e,t)=>{const n=e.clients.get(t);if(n===void 0)return 0;const i=n[n.length-1];return i.id.clock+i.length},Nr=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{const i=n[n.length-1];if(i.id.clock+i.length!==t.id.clock)throw Z()}n.push(t)},pt=(e,t)=>{let n=0,i=e.length-1,s=e[i],r=s.id.clock;if(r===t)return i;let o=ft(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=ft((n+i)/2)}throw Z()},hh=(e,t)=>{const n=e.clients.get(t.client);return n[pt(n,t.clock)]},Zt=hh,ui=(e,t,n)=>{const i=pt(t,n),s=t[i];return s.id.clock<n&&s instanceof M?(t.splice(i+1,0,un(e,s,n-s.id.clock)),i+1):i},nt=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[ui(e,n,t.clock)]},ps=(e,t,n)=>{const i=t.clients.get(n.client),s=pt(i,n.clock),r=i[s];return n.clock!==r.id.clock+r.length-1&&r.constructor!==lt&&i.splice(s+1,0,un(e,r,n.clock-r.id.clock+1)),r},uh=(e,t,n)=>{const i=e.clients.get(t.id.client);i[pt(i,t.id.clock)]=n},Br=(e,t,n,i,s)=>{if(i===0)return;const r=n+i;let o=ui(e,t,n),l;do l=t[o++],r<l.id.clock+l.length&&ui(e,t,r),s(l);while(o<t.length&&t[o].id.clock<r)};class dh{constructor(t,n,i){this.doc=t,this.deleteSet=new ce,this.beforeState=_n(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=i,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const gs=(e,t)=>t.deleteSet.clients.size===0&&!Jl(t.afterState,(n,i)=>t.beforeState.get(i)!==n)?!1:(Ri(t.deleteSet),ih(e,t),Ni(e,t.deleteSet),!0),ms=(e,t,n)=>{const i=t._item;(i===null||i.id.clock<(e.beforeState.get(i.id.client)||0)&&!i.deleted)&&Tt(e.changed,t,Pt).add(n)},We=(e,t)=>{let n=e[t],i=e[t-1],s=t;for(;s>0;n=i,i=e[--s-1]){if(i.deleted===n.deleted&&i.constructor===n.constructor&&i.mergeWith(n)){n instanceof M&&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},fh=(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=pt(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 M&&h.deleted&&!h.keep&&n(h)&&h.gc(t,!1)}}}},ph=(e,t)=>{e.clients.forEach((n,i)=>{const s=t.clients.get(i);for(let r=n.length-1;r>=0;r--){const o=n[r],l=ee(s.length-1,1+pt(s,o.clock+o.len-1));for(let c=l,a=s[c];c>0&&a.id.clock>=o.clock;a=s[c])c-=1+We(s,c)}})},Lr=(e,t)=>{if(t<e.length){const n=e[t],i=n.doc,s=i.store,r=n.deleteSet,o=n._mergeStructs;try{Ri(r),n.afterState=_n(n.doc.store),i.emit("beforeObserverCalls",[n,i]);const l=[];n.changed.forEach((c,a)=>l.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(n,c)})),l.push(()=>{n.changedParentTypes.forEach((c,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(c=c.filter(u=>u.target._item===null||!u.target._item.deleted),c.forEach(u=>{u.currentTarget=a,u._path=null}),c.sort((u,h)=>u.path.length-h.path.length),l.push(()=>{Or(a._dEH,c,n)}))}),l.push(()=>i.emit("afterTransaction",[n,i])),l.push(()=>{n._needFormattingCleanup&&Rh(n)})}),Ai(l,[])}finally{i.gc&&fh(r,s,i.gcFilter),ph(r,s),n.afterState.forEach((u,h)=>{const f=n.beforeState.get(h)||0;if(f!==u){const p=s.clients.get(h),g=Ot(pt(p,f),1);for(let x=p.length-1;x>=g;)x-=1+We(p,x)}});for(let u=o.length-1;u>=0;u--){const{client:h,clock:f}=o[u].id,p=s.clients.get(h),g=pt(p,f);g+1<p.length&&We(p,g+1)>1||g>0&&We(p,g)}if(!n.local&&n.afterState.get(i.clientID)!==n.beforeState.get(i.clientID)&&(Ka(ji,Sr,"[yjs] ",Cr,kr,"Changed the client-id because another client seems to be using it."),i.clientID=Dr()),i.emit("afterTransactionCleanup",[n,i]),i._observers.has("update")){const u=new Za;gs(u,n)&&i.emit("update",[u.toUint8Array(),n.origin,i,n])}if(i._observers.has("updateV2")){const u=new En;gs(u,n)&&i.emit("updateV2",[u.toUint8Array(),n.origin,i,n])}const{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=n;(l.size>0||a.size>0||c.size>0)&&(l.forEach(u=>{u.clientID=i.clientID,u.collectionid==null&&(u.collectionid=i.collectionid),i.subdocs.add(u)}),a.forEach(u=>i.subdocs.delete(u)),i.emit("subdocs",[{loaded:c,added:l,removed:a},i,n]),a.forEach(u=>u.destroy())),e.length<=t+1?(i._transactionCleanups=[],i.emit("afterAllTransactions",[i,e])):Lr(e,t+1)}}},O=(e,t,n=null,i=!0)=>{const s=e._transactionCleanups;let r=!1,o=null;e._transaction===null&&(r=!0,e._transaction=new dh(e,n,i),s.push(e._transaction),s.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(r){const l=e._transaction===s[0];e._transaction=null,l&&Lr(s,0)}}return o};class gh{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const xs=(e,t,n)=>{jt(e,n.deletions,i=>{i instanceof M&&t.scope.some(s=>s===e.doc||ke(s,i))&&Fi(i,!1)})},bs=(e,t,n)=>{let i=null;const s=e.doc,r=e.scope;O(s,l=>{for(;t.length>0&&e.currStackItem===null;){const c=s.store,a=t.pop(),u=new Set,h=[];let f=!1;jt(l,a.insertions,p=>{if(p instanceof M){if(p.redone!==null){let{item:g,diff:x}=fi(c,p.id);x>0&&(g=nt(l,_(g.id.client,g.id.clock+x))),p=g}!p.deleted&&r.some(g=>g===l.doc||ke(g,p))&&h.push(p)}}),jt(l,a.deletions,p=>{p instanceof M&&r.some(g=>g===l.doc||ke(g,p))&&!ae(a.insertions,p.id)&&u.add(p)}),u.forEach(p=>{f=io(l,p,u,a.insertions,e.ignoreRemoteMapChanges,e)!==null||f});for(let p=h.length-1;p>=0;p--){const g=h[p];e.deleteFilter(g)&&(g.delete(l),f=!0)}e.currStackItem=f?a:null}l.changed.forEach((c,a)=>{c.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),i=l},e);const o=e.currStackItem;if(o!=null){const l=i.changedParentTypes;e.emit("stack-item-popped",[{stackItem:o,type:n,changedParentTypes:l,origin:e},e]),e.currStackItem=null}return o};class Ur extends Ws{constructor(t,{captureTimeout:n=500,captureTransaction:i=c=>!0,deleteFilter:s=()=>!0,trackedOrigins:r=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:l=te(t)?t[0].doc:t instanceof zt?t:t.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(t),this.deleteFilter=s,r.add(this),this.trackedOrigins=r,this.captureTransaction=i,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=n,this.afterTransactionHandler=c=>{if(!this.captureTransaction(c)||!this.scope.some(w=>c.changedParentTypes.has(w)||w===this.doc)||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;const a=this.undoing,u=this.redoing,h=a?this.redoStack:this.undoStack;a?this.stopCapturing():u||this.clear(!1,!0);const f=new ce;c.afterState.forEach((w,y)=>{const C=c.beforeState.get(y)||0,k=w-C;k>0&&Se(f,y,C,k)});const p=Nc();let g=!1;if(this.lastChange>0&&p-this.lastChange<this.captureTimeout&&h.length>0&&!a&&!u){const w=h[h.length-1];w.deletions=ci([w.deletions,c.deleteSet]),w.insertions=ci([w.insertions,f])}else h.push(new gh(c.deleteSet,f)),g=!0;!a&&!u&&(this.lastChange=p),jt(c,c.deleteSet,w=>{w instanceof M&&this.scope.some(y=>y===c.doc||ke(y,w))&&Fi(w,!0)});const x=[{stackItem:h[h.length-1],origin:c.origin,type:a?"redo":"undo",changedParentTypes:c.changedParentTypes},this];g?this.emit("stack-item-added",x):this.emit("stack-item-updated",x)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){const n=new Set(this.scope);t=te(t)?t:[t],t.forEach(i=>{n.has(i)||(n.add(i),(i instanceof q?i.doc!==this.doc:i!==this.doc)&&_r("[yjs#509] Not same Y.Doc"),this.scope.push(i))})}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,n=!0){(t&&this.canUndo()||n&&this.canRedo())&&this.doc.transact(i=>{t&&(this.undoStack.forEach(s=>xs(i,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>xs(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=bs(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=bs(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*mh(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 at(_(s,r),c),r+=c}else if((mn&l)!==0){const c=(l&(Et|tt))===0,a=new M(_(s,r),null,(l&tt)===tt?e.readLeftID():null,null,(l&Et)===Et?e.readRightID():null,c?e.readParentInfo()?e.readString():e.readLeftID():null,c&&(l&xe)===xe?e.readString():null,so(e,l));yield a,r+=a.length}else{const c=e.readLen();yield new lt(_(s,r),c),r+=c}}}}class xh{constructor(t,n){this.gen=mh(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===at);return this.curr}}class bh{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const wh=(e,t)=>{if(e.constructor===lt){const{client:n,clock:i}=e.id;return new lt(_(n,i+t),e.length-t)}else if(e.constructor===at){const{client:n,clock:i}=e.id;return new at(_(n,i+t),e.length-t)}else{const n=e,{client:i,clock:s}=n.id;return new M(_(i,s+t),null,_(i,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},ws=(e,t=rn,n=En)=>{if(e.length===1)return e[0];const i=e.map(u=>new t(ki(u)));let s=i.map(u=>new xh(u,!0)),r=null;const o=new n,l=new bh(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===at?1:-1:g}else return p.curr.id.client-f.curr.id.client}),s.length!==0;){const u=s[0],h=u.curr.id.client;if(r!==null){let f=u.curr,p=!1;for(;f!==null&&f.id.clock+f.length<=r.struct.id.clock+r.struct.length&&f.id.client>=r.struct.id.client;)f=u.next(),p=!0;if(f===null||f.id.client!==h||p&&f.id.clock>r.struct.id.clock+r.struct.length)continue;if(h!==r.struct.id.client)pe(l,r.struct,r.offset),r={struct:f,offset:0},u.next();else if(r.struct.id.clock+r.struct.length<f.id.clock)if(r.struct.constructor===at)r.struct.length=f.id.clock+f.length-r.struct.id.clock;else{pe(l,r.struct,r.offset);const g=f.id.clock-r.struct.id.clock-r.struct.length;r={struct:new at(_(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===at?r.struct.length-=g:f=wh(f,g)),r.struct.mergeWith(f)||(pe(l,r.struct,r.offset),r={struct:f,offset:0},u.next())}}else r={struct:u.curr,offset:0},u.next();for(let f=u.curr;f!==null&&f.id.client===h&&f.id.clock===r.struct.id.clock+r.struct.length&&f.constructor!==at;f=u.next())pe(l,r.struct,r.offset),r={struct:f,offset:0}}r!==null&&(pe(l,r.struct,r.offset),r=null),yh(l);const c=i.map(u=>Ya(u)),a=ci(c);return Ni(o,a),o.toUint8Array()},Pr=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:ht(e.encoder.restEncoder)}),e.encoder.restEncoder=De(),e.written=0)},pe=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Pr(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++},yh=e=>{Pr(e);const t=e.encoder.restEncoder;I(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const i=e.clientStructs[n];I(t,i.written),xn(t,i.restEncoder)}},ys="You must not compute changes after the event-handler fired.";class Tn{constructor(t,n){this.target=t,this.currentTarget=t,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=vh(this.currentTarget,this.target))}deletes(t){return ae(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw yt(ys);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=Un(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Un(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(r))o="delete",l=Un(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 yt(ys);const n=this.target,i=Pt(),s=Pt(),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 vh=(e,t)=>{const n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let i=0,s=t._item.parent._start;for(;s!==t._item&&s!==null;)!s.deleted&&s.countable&&(i+=s.length),s=s.right;n.unshift(i)}t=t._item.parent}return n},X=()=>{_r("Invalid access: Add Yjs type to a document before reading data.")},$r=80;let Li=0;class Sh{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=Li++}}const Ch=e=>{e.timestamp=Li++},Fr=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Li++},kh=(e,t,n)=>{if(e.length>=$r){const i=e.reduce((s,r)=>s.timestamp<r.timestamp?s:r);return Fr(i,t,n),i}else{const i=new Sh(t,n);return e.push(i),i}},An=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;const n=e._searchMarker.length===0?null:e._searchMarker.reduce((r,o)=>He(t-r.index)<He(t-o.index)?r:o);let i=e._start,s=0;for(n!==null&&(i=n.p,s=n.index,Ch(n));i.right!==null&&s<t;){if(!i.deleted&&i.countable){if(t<s+i.length)break;s+=i.length}i=i.right}for(;i.left!==null&&s>t;)i=i.left,!i.deleted&&i.countable&&(s-=i.length);for(;i.left!==null&&i.left.id.client===i.id.client&&i.left.id.clock+i.left.length===i.id.clock;)i=i.left,!i.deleted&&i.countable&&(s-=i.length);return n!==null&&He(n.index-s)<i.parent.length/$r?(Fr(n,i,s),n):kh(e._searchMarker,i,s)},Ee=(e,t,n)=>{for(let i=e.length-1;i>=0;i--){const s=e[i];if(n>0){let r=s.p;for(r.marker=!1;r&&(r.deleted||!r.countable);)r=r.left,r&&!r.deleted&&r.countable&&(s.index-=r.length);if(r===null||r.marker===!0){e.splice(i,1);continue}s.p=r,r.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=Ot(t,s.index+n))}},In=(e,t,n)=>{const i=e,s=t.changedParentTypes;for(;Tt(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Or(i._eH,n,t)};class q{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=us(),this._dEH=us(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw ct()}clone(){throw ct()}_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){ds(this._eH,t)}observeDeep(t){ds(this._dEH,t)}unobserve(t){fs(this._eH,t)}unobserveDeep(t){fs(this._dEH,t)}toJSON(){}}const Vr=(e,t,n)=>{e.doc??X(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let i=n-t;const s=[];let r=e._start;for(;r!==null&&i>0;){if(r.countable&&!r.deleted){const o=r.content.getContent();if(o.length<=t)t-=o.length;else{for(let l=t;l<o.length&&i>0;l++)s.push(o[l]),i--;t=0}}r=r.right}return s},Hr=e=>{e.doc??X();const t=[];let n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){const i=n.content.getContent();for(let s=0;s<i.length;s++)t.push(i[s])}n=n.right}return t},zr=(e,t)=>{const n=[];let i=e._start;for(;i!==null;){if(i.countable&&Bt(i,t)){const s=i.content.getContent();for(let r=0;r<s.length;r++)n.push(s[r])}i=i.right}return n},_e=(e,t)=>{let n=0,i=e._start;for(e.doc??X();i!==null;){if(i.countable&&!i.deleted){const s=i.content.getContent();for(let r=0;r<s.length;r++)t(s[r],n++,e)}i=i.right}},Kr=(e,t)=>{const n=[];return _e(e,(i,s)=>{n.push(t(i,s,e))}),n},Eh=e=>{let t=e._start,n=null,i=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),i=0,t=t.right}const s=n[i++];return n.length<=i&&(n=null),{done:!1,value:s}}}},qr=(e,t)=>{e.doc??X();const n=An(e,t);let i=e._start;for(n!==null&&(i=n.p,t-=n.index);i!==null;i=i.right)if(!i.deleted&&i.countable){if(t<i.length)return i.content.getContent()[t];t-=i.length}},ln=(e,t,n,i)=>{let s=n;const r=e.doc,o=r.clientID,l=r.store,c=n===null?t._start:n.right;let a=[];const u=()=>{a.length>0&&(s=new M(_(o,P(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new Vt(a)),s.integrate(e,0),a=[])};i.forEach(h=>{if(h===null)a.push(h);else switch(h.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(h);break;default:switch(u(),h.constructor){case Uint8Array:case ArrayBuffer:s=new M(_(o,P(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new Oe(new Uint8Array(h))),s.integrate(e,0);break;case zt:s=new M(_(o,P(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new je(h)),s.integrate(e,0);break;default:if(h instanceof q)s=new M(_(o,P(l,o)),s,s&&s.lastId,c,c&&c.id,t,null,new mt(h)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),u()},Wr=()=>yt("Length exceeded!"),Gr=(e,t,n,i)=>{if(n>t._length)throw Wr();if(n===0)return t._searchMarker&&Ee(t._searchMarker,n,i.length),ln(e,t,null,i);const s=n,r=An(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&&nt(e,_(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&Ee(t._searchMarker,s,i.length),ln(e,t,o,i)},_h=(e,t,n)=>{let s=(t._searchMarker||[]).reduce((r,o)=>o.index>r.index?o:r,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return ln(e,t,s,n)},Yr=(e,t,n,i)=>{if(i===0)return;const s=n,r=i,o=An(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&&nt(e,_(l.id.client,l.id.clock+n)),n-=l.length);for(;i>0&&l!==null;)l.deleted||(i<l.length&&nt(e,_(l.id.client,l.id.clock+i)),l.delete(e),i-=l.length),l=l.right;if(i>0)throw Wr();t._searchMarker&&Ee(t._searchMarker,s,-r+i)},cn=(e,t,n)=>{const i=t._map.get(n);i!==void 0&&i.delete(e)},Ui=(e,t,n,i)=>{const s=t._map.get(n)||null,r=e.doc,o=r.clientID;let l;if(i==null)l=new Vt([i]);else switch(i.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new Vt([i]);break;case Uint8Array:l=new Oe(i);break;case zt:l=new je(i);break;default:if(i instanceof q)l=new mt(i);else throw new Error("Unexpected content type")}new M(_(o,P(r.store,o)),s,s&&s.lastId,null,null,t,n,l).integrate(e,0)},Pi=(e,t)=>{e.doc??X();const n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Jr=e=>{const t={};return e.doc??X(),e._map.forEach((n,i)=>{n.deleted||(t[i]=n.content.getContent()[n.length-1])}),t},Xr=(e,t)=>{e.doc??X();const n=e._map.get(t);return n!==void 0&&!n.deleted},Th=(e,t)=>{const n={};return e._map.forEach((i,s)=>{let r=i;for(;r!==null&&(!t.sv.has(r.id.client)||r.id.clock>=(t.sv.get(r.id.client)||0));)r=r.left;r!==null&&Bt(r,t)&&(n[s]=r.content.getContent()[r.length-1])}),n},Ue=e=>(e.doc??X(),qa(e._map.entries(),t=>!t[1].deleted));class Ah extends Tn{}class Qt extends q{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new Qt;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Qt}clone(){const t=new Qt;return t.insert(0,this.toArray().map(n=>n instanceof q?n.clone():n)),t}get length(){return this.doc??X(),this._length}_callObserver(t,n){super._callObserver(t,n),In(this,t,new Ah(this,t))}insert(t,n){this.doc!==null?O(this.doc,i=>{Gr(i,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?O(this.doc,n=>{_h(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?O(this.doc,i=>{Yr(i,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return qr(this,t)}toArray(){return Hr(this)}slice(t=0,n=this.length){return Vr(this,t,n)}toJSON(){return this.map(t=>t instanceof q?t.toJSON():t)}map(t){return Kr(this,t)}forEach(t){_e(this,t)}[Symbol.iterator](){return Eh(this)}_write(t){t.writeTypeRef(Qh)}}const Ih=e=>new Qt;class Dh extends Tn{constructor(t,n,i){super(t,n),this.keysChanged=i}}class re extends q{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach((i,s)=>{this.set(s,i)}),this._prelimContent=null}_copy(){return new re}clone(){const t=new re;return this.forEach((n,i)=>{t.set(i,n instanceof q?n.clone():n)}),t}_callObserver(t,n){In(this,t,new Dh(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 q?s.toJSON():s}}),t}get size(){return[...Ue(this)].length}keys(){return Kn(Ue(this),t=>t[0])}values(){return Kn(Ue(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Kn(Ue(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?O(this.doc,n=>{cn(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?O(this.doc,i=>{Ui(i,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return Pi(this,t)}has(t){return Xr(this,t)}clear(){this.doc!==null?O(this.doc,t=>{this.forEach(function(n,i,s){cn(t,s,i)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(tu)}}const Mh=e=>new re,Dt=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&Hc(e,t);class di{constructor(t,n,i,s){this.left=t,this.right=n,this.index=i,this.currentAttributes=s}forward(){switch(this.right===null&&Z(),this.right.content.constructor){case F:this.right.deleted||he(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}}const vs=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case F:t.right.deleted||he(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&nt(e,_(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length);break}t.left=t.right,t.right=t.right.right}return t},Pe=(e,t,n,i)=>{const s=new Map,r=i?An(t,n):null;if(r){const o=new di(r.p.left,r.p,r.index,s);return vs(e,o,n-r.index)}else{const o=new di(null,t._start,0,s);return vs(e,o,n)}},Zr=(e,t,n,i)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===F&&Dt(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 M(_(r,P(s.store,r)),c,c&&c.lastId,a,a&&a.id,t,null,new F(l,o));u.integrate(e,0),n.right=u,n.forward()})},he=(e,t)=>{const{key:n,value:i}=t;i===null?e.delete(n):e.set(n,i)},Qr=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===F&&Dt(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},to=(e,t,n,i)=>{const s=e.doc,r=s.clientID,o=new Map;for(const l in i){const c=i[l],a=n.currentAttributes.get(l)??null;if(!Dt(a,c)){o.set(l,a);const{left:u,right:h}=n;n.right=new M(_(r,P(s.store,r)),u,u&&u.lastId,h,h&&h.id,t,null,new F(l,c)),n.right.integrate(e,0),n.forward()}}return o},Gn=(e,t,n,i,s)=>{n.currentAttributes.forEach((f,p)=>{s[p]===void 0&&(s[p]=null)});const r=e.doc,o=r.clientID;Qr(n,s);const l=to(e,t,n,s),c=i.constructor===String?new gt(i):i instanceof q?new mt(i):new Kt(i);let{left:a,right:u,index:h}=n;t._searchMarker&&Ee(t._searchMarker,n.index,c.getLength()),u=new M(_(o,P(r.store,o)),a,a&&a.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=h,n.forward(),Zr(e,t,n,l)},Ss=(e,t,n,i,s)=>{const r=e.doc,o=r.clientID;Qr(n,s);const l=to(e,t,n,s);t:for(;n.right!==null&&(i>0||l.size>0&&(n.right.deleted||n.right.content.constructor===F));){if(!n.right.deleted)switch(n.right.content.constructor){case F:{const{key:c,value:a}=n.right.content,u=s[c];if(u!==void 0){if(Dt(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&&nt(e,_(n.right.id.client,n.right.id.clock+i)),i-=n.right.length;break}n.forward()}if(i>0){let c="";for(;i>0;i--)c+=`
5
+ `;n.right=new M(_(o,P(r.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new gt(c)),n.right.integrate(e,0),n.forward()}Zr(e,t,n,l)},eo=(e,t,n,i,s)=>{let r=t;const o=dt();for(;r&&(!r.countable||r.deleted);){if(!r.deleted&&r.content.constructor===F){const a=r.content;o.set(a.key,a)}r=r.right}let l=0,c=!1;for(;t!==r;){if(n===t&&(c=!0),!t.deleted){const a=t.content;switch(a.constructor){case F:{const{key:u,value:h}=a,f=i.get(u)??null;(o.get(u)!==a||f===h)&&(t.delete(e),l++,!c&&(s.get(u)??null)===h&&f!==h&&(f===null?s.delete(u):s.set(u,f))),!c&&!t.deleted&&he(s,a);break}}}t=t.right}return l},Oh=(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}},jh=e=>{let t=0;return O(e.doc,n=>{let i=e._start,s=e._start,r=dt();const o=ei(r);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case F:he(o,s.content);break;default:t+=eo(n,i,s,r,o),r=ei(o),i=s;break}s=s.right}}),t},Rh=e=>{const t=new Set,n=e.doc;for(const[i,s]of e.afterState.entries()){const r=e.beforeState.get(i)||0;s!==r&&Br(e,n.store.clients.get(i),r,s,o=>{!o.deleted&&o.content.constructor===F&&o.constructor!==lt&&t.add(o.parent)})}O(n,i=>{jt(e,e.deleteSet,s=>{if(s instanceof lt||!s.parent._hasFormatting||t.has(s.parent))return;const r=s.parent;s.content.constructor===F?t.add(r):Oh(i,s)});for(const s of t)jh(s)})},Cs=(e,t,n)=>{const i=n,s=ei(t.currentAttributes),r=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case mt:case Kt:case gt:n<t.right.length&&nt(e,_(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}r&&eo(e,r,t.right,s,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&Ee(o._searchMarker,t.index,-i+n),t};class Nh extends Tn{constructor(t,n,i){super(t,n),this.childListChanged=!1,this.keysChanged=new Set,i.forEach(s=>{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}get changes(){if(this._changes===null){const t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){const t=this.target.doc,n=[];O(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},Vc(c)||(p.attributes=$c({},c))),u=0;break}p&&n.push(p),l=null}};for(;o!==null;){switch(o.content.constructor){case mt:case Kt:this.adds(o)?this.deletes(o)||(f(),l="insert",a=o.content.getContent()[0],f()):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),h+=1):o.deleted||(l!=="retain"&&(f(),l="retain"),u+=1);break;case gt: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;Dt(x,g)?g!==null&&o.delete(i):(l==="retain"&&f(),Dt(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;Dt(x,g)||(l==="retain"&&f(),c[p]=x)}else if(!o.deleted){r.set(p,g);const x=c[p];x!==void 0&&(Dt(x,g)?x!==null&&o.delete(i):(l==="retain"&&f(),g===null?delete c[p]:c[p]=g))}o.deleted||(l==="insert"&&f(),he(s,o.content));break}}o=o.right}for(f();n.length>0;){const p=n[n.length-1];if(p.retain!==void 0&&p.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class Rt extends q{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??X(),this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach(i=>i())}catch(i){console.error(i)}this._pending=null}_copy(){return new Rt}clone(){const t=new Rt;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const i=new Nh(this,t,n);In(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===gt&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){this.doc!==null?O(this.doc,i=>{const s=new di(null,this._start,0,new Map);for(let r=0;r<t.length;r++){const o=t[r];if(o.insert!==void 0){const l=!n&&typeof o.insert=="string"&&r===t.length-1&&s.right===null&&o.insert.slice(-1)===`
6
+ `?o.insert.slice(0,-1):o.insert;(typeof l!="string"||l.length>0)&&Gn(i,this,s,l,o.attributes||{})}else o.retain!==void 0?Ss(i,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&Cs(i,s,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,i){this.doc??X();const s=[],r=new Map,o=this.doc;let l="",c=this._start;function a(){if(l.length>0){const h={};let f=!1;r.forEach((g,x)=>{f=!0,h[x]=g});const p={insert:l};f&&(p.attributes=h),s.push(p),l=""}}const u=()=>{for(;c!==null;){if(Bt(c,t)||n!==void 0&&Bt(c,n))switch(c.content.constructor){case gt:{const h=r.get("ychange");t!==void 0&&!Bt(c,t)?(h===void 0||h.user!==c.id.client||h.type!=="removed")&&(a(),r.set("ychange",i?i("removed",c.id):{type:"removed"})):n!==void 0&&!Bt(c,n)?(h===void 0||h.user!==c.id.client||h.type!=="added")&&(a(),r.set("ychange",i?i("added",c.id):{type:"added"})):h!==void 0&&(a(),r.delete("ychange")),l+=c.content.str;break}case mt:case Kt:{a();const h={insert:c.content.getContent()[0]};if(r.size>0){const f={};h.attributes=f,r.forEach((p,g)=>{f[g]=p})}s.push(h);break}case F:Bt(c,t)&&(a(),he(r,c.content));break}c=c.right}a()};return t||n?O(o,h=>{t&&hi(h,t),n&&hi(h,n),u()},"cleanup"):u(),s}insert(t,n,i){if(n.length<=0)return;const s=this.doc;s!==null?O(s,r=>{const o=Pe(r,this,t,!i);i||(i={},o.currentAttributes.forEach((l,c)=>{i[c]=l})),Gn(r,this,o,n,i)}):this._pending.push(()=>this.insert(t,n,i))}insertEmbed(t,n,i){const s=this.doc;s!==null?O(s,r=>{const o=Pe(r,this,t,!i);Gn(r,this,o,n,i||{})}):this._pending.push(()=>this.insertEmbed(t,n,i||{}))}delete(t,n){if(n===0)return;const i=this.doc;i!==null?O(i,s=>{Cs(s,Pe(s,this,t,!0),n)}):this._pending.push(()=>this.delete(t,n))}format(t,n,i){if(n===0)return;const s=this.doc;s!==null?O(s,r=>{const o=Pe(r,this,t,!1);o.right!==null&&Ss(r,this,o,n,i)}):this._pending.push(()=>this.format(t,n,i))}removeAttribute(t){this.doc!==null?O(this.doc,n=>{cn(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?O(this.doc,i=>{Ui(i,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return Pi(this,t)}getAttributes(){return Jr(this)}_write(t){t.writeTypeRef(eu)}}const Bh=e=>new Rt;class Yn{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??X()}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(n)))do if(n=t.content.type,!t.deleted&&(n.constructor===J||n.constructor===Ft)&&n._start!==null)t=n._start;else for(;t!==null;){const i=t.next;if(i!==null){t=i;break}else t.parent===this._root?t=null:t=t.parent._item}while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class Ft extends q{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Ft}clone(){const t=new Ft;return t.insert(0,this.toArray().map(n=>n instanceof q?n.clone():n)),t}get length(){return this.doc??X(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Yn(this,t)}querySelector(t){t=t.toUpperCase();const i=new Yn(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return i.done?null:i.value}querySelectorAll(t){return t=t.toUpperCase(),$t(new Yn(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){In(this,t,new Ph(this,n,t))}toString(){return Kr(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},i){const s=t.createDocumentFragment();return i!==void 0&&i._createAssociation(s,this),_e(this,r=>{s.insertBefore(r.toDOM(t,n,i),null)}),s}insert(t,n){this.doc!==null?O(this.doc,i=>{Gr(i,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)O(this.doc,i=>{const s=t&&t instanceof q?t._item:t;ln(i,this,s,n)});else{const i=this._prelimContent,s=t===null?0:i.findIndex(r=>r===t)+1;if(s===0&&t!==null)throw yt("Reference item not found");i.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?O(this.doc,i=>{Yr(i,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return Hr(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return qr(this,t)}slice(t=0,n=this.length){return Vr(this,t,n)}forEach(t){_e(this,t)}_write(t){t.writeTypeRef(iu)}}const Lh=e=>new Ft;class J extends Ft{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach((i,s)=>{this.setAttribute(s,i)}),this._prelimAttrs=null}_copy(){return new J(this.nodeName)}clone(){const t=new J(this.nodeName),n=this.getAttributes();return Fc(n,(i,s)=>{t.setAttribute(s,i)}),t.insert(0,this.toArray().map(i=>i instanceof q?i.clone():i)),t}toString(){const t=this.getAttributes(),n=[],i=[];for(const l in t)i.push(l);i.sort();const s=i.length;for(let l=0;l<s;l++){const c=i[l];n.push(c+'="'+t[c]+'"')}const r=this.nodeName.toLocaleLowerCase(),o=n.length>0?" "+n.join(" "):"";return`<${r}${o}>${super.toString()}</${r}>`}removeAttribute(t){this.doc!==null?O(this.doc,n=>{cn(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?O(this.doc,i=>{Ui(i,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return Pi(this,t)}hasAttribute(t){return Xr(this,t)}getAttributes(t){return t?Th(this,t):Jr(this)}toDOM(t=document,n={},i){const s=t.createElement(this.nodeName),r=this.getAttributes();for(const o in r){const l=r[o];typeof l=="string"&&s.setAttribute(o,l)}return _e(this,o=>{s.appendChild(o.toDOM(t,n,i))}),i!==void 0&&i._createAssociation(s,this),s}_write(t){t.writeTypeRef(nu),t.writeKey(this.nodeName)}}const Uh=e=>new J(e.readKey());class Ph extends Tn{constructor(t,n,i){super(t,i),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}}class an extends re{constructor(t){super(),this.hookName=t}_copy(){return new an(this.hookName)}clone(){const t=new an(this.hookName);return this.forEach((n,i)=>{t.set(i,n)}),t}toDOM(t=document,n={},i){const s=n[this.hookName];let r;return s!==void 0?r=s.createDom(this):r=document.createElement(this.hookName),r.setAttribute("data-yjs-hook",this.hookName),i!==void 0&&i._createAssociation(r,this),r}_write(t){t.writeTypeRef(su),t.writeKey(this.hookName)}}const $h=e=>new an(e.readKey());class it extends Rt{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new it}clone(){const t=new it;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(ru)}}const Fh=e=>new it;class $i{constructor(t,n){this.id=t,this.length=n}get deleted(){throw ct()}mergeWith(t){return!1}write(t,n,i){throw ct()}integrate(t,n){throw ct()}}const Vh=0;class lt extends $i{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){n>0&&(this.id.clock+=n,this.length-=n),Nr(t.doc.store,this)}write(t,n){t.writeInfo(Vh),t.writeLen(this.length-n)}getMissing(t,n){return null}}class Oe{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Oe(this.content)}splice(t){throw ct()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}const Hh=e=>new Oe(e.readBuf());class Te{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Te(this.len)}splice(t){const n=new Te(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){Se(t.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(t){}gc(t){}write(t,n){t.writeLen(this.len-n)}getRef(){return 1}}const zh=e=>new Te(e.readLen()),no=(e,t)=>new zt({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class je{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const n={};this.opts=n,t.gc||(n.gc=!1),t.autoLoad&&(n.autoLoad=!0),t.meta!==null&&(n.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new je(no(this.doc.guid,this.opts))}splice(t){throw ct()}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 Kh=e=>new je(no(e.readString(),e.readAny()));class Kt{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Kt(this.embed)}splice(t){throw ct()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}const qh=e=>new Kt(e.readJSON());class F{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new F(this.key,this.value)}splice(t){throw ct()}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 Wh=e=>new F(e.readKey(),e.readJSON());class hn{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new hn(this.arr)}splice(t){const n=new hn(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const i=this.arr.length;t.writeLen(i-n);for(let s=n;s<i;s++){const r=this.arr[s];t.writeString(r===void 0?"undefined":JSON.stringify(r))}}getRef(){return 2}}const Gh=e=>{const t=e.readLen(),n=[];for(let i=0;i<t;i++){const s=e.readString();s==="undefined"?n.push(void 0):n.push(JSON.parse(s))}return new hn(n)},Yh=tn("node_env")==="development";class Vt{constructor(t){this.arr=t,Yh&&nr(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Vt(this.arr)}splice(t){const n=new Vt(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const i=this.arr.length;t.writeLen(i-n);for(let s=n;s<i;s++){const r=this.arr[s];t.writeAny(r)}}getRef(){return 8}}const Jh=e=>{const t=e.readLen(),n=[];for(let i=0;i<t;i++)n.push(e.readAny());return new Vt(n)};class gt{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new gt(this.str)}splice(t){const n=new gt(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 Xh=e=>new gt(e.readString()),Zh=[Ih,Mh,Bh,Uh,Lh,$h,Fh],Qh=0,tu=1,eu=2,nu=3,iu=4,su=5,ru=6;class mt{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new mt(this.type._copy())}splice(t){throw ct()}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 ou=e=>new mt(Zh[e.readTypeRef()](e)),fi=(e,t)=>{let n=t,i=0,s;do i>0&&(n=_(n.client,n.clock+i)),s=Zt(e,n),i=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof M);return{item:s,diff:i}},Fi=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},un=(e,t,n)=>{const{client:i,clock:s}=t.id,r=new M(_(i,s+n),t,_(i,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&r.markDeleted(),t.keep&&(r.keep=!0),t.redone!==null&&(r.redone=_(t.redone.client,t.redone.clock+n)),t.right=r,r.right!==null&&(r.right.left=r),e._mergeStructs.push(r),r.parentSub!==null&&r.right===null&&r.parent._map.set(r.parentSub,r),t.length=n,r},ks=(e,t)=>vi(e,n=>ae(n.deletions,t)),io=(e,t,n,i,s,r)=>{const o=e.doc,l=o.store,c=o.clientID,a=t.redone;if(a!==null)return nt(e,a);let u=t.parent._item,h=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||io(e,u,n,i,s,r)===null))return null;for(;u.redone!==null;)u=nt(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:nt(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:nt(e,y.redone);if(y!==null&&y.parent._item===u){f=y;break}f=f.right}}else if(f=null,t.right&&!s){for(h=t;h!==null&&h.right!==null&&(h.right.redone||ae(i,h.right.id)||ks(r.undoStack,h.right.id)||ks(r.redoStack,h.right.id));)for(h=h.right;h.redone;)h=nt(e,h.redone);if(h&&h.right!==null)return null}else h=p._map.get(t.parentSub)||null;const g=P(l,c),x=_(c,g),w=new M(x,h,h&&h.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=x,Fi(w,!0),w.integrate(e,0),w};class M extends $i{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()?Zi:0}set marker(t){(this.info&$n)>0!==t&&(this.info^=$n)}get marker(){return(this.info&$n)>0}get keep(){return(this.info&Xi)>0}set keep(t){this.keep!==t&&(this.info^=Xi)}get countable(){return(this.info&Zi)>0}get deleted(){return(this.info&Pn)>0}set deleted(t){this.deleted!==t&&(this.info^=Pn)}markDeleted(){this.info|=Pn}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=P(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=P(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Xt&&this.id.client!==this.parent.client&&this.parent.clock>=P(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=ps(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=nt(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===lt||this.right&&this.right.constructor===lt)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===M?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===M&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Xt){const i=Zt(n,this.parent);i.constructor===lt?this.parent=null:this.parent=i.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=ps(t,t.doc.store,_(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let i=this.left,s;if(i!==null)s=i.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;const r=new Set,o=new Set;for(;s!==null&&s!==this.right;){if(o.add(s),r.add(s),Be(this.origin,s.origin)){if(s.id.client<this.id.client)i=s,r.clear();else if(Be(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&o.has(Zt(t.doc.store,s.origin)))r.has(Zt(t.doc.store,s.origin))||(i=s,r.clear());else break;s=s.right}this.left=i}if(this.left!==null){const i=this.left.right;this.right=i,this.left.right=this}else{let i;if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start,this.parent._start=this;this.right=i}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Nr(t.doc.store,this),this.content.integrate(t,this),ms(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new lt(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;t!==null&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;t!==null&&t.deleted;)t=t.left;return t}get lastId(){return this.length===1?this.id:_(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Be(t.origin,this.lastId)&&this.right===t&&Be(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const n=this.parent._searchMarker;return n&&n.forEach(i=>{i.p===t&&(i.p=this,!this.deleted&&this.countable&&(i.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),Se(t.deleteSet,this.id.client,this.id.clock,this.length),ms(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw Z();this.content.gc(t),n?uh(t,this,new lt(this.id,this.length)):this.content=new Te(this.length)}write(t,n){const i=n>0?_(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,r=this.parentSub,o=this.content.getRef()&mn|(i===null?0:tt)|(s===null?0:Et)|(r===null?0:xe);if(t.writeInfo(o),i!==null&&t.writeLeftID(i),s!==null&&t.writeRightID(s),i===null&&s===null){const l=this.parent;if(l._item!==void 0){const c=l._item;if(c===null){const a=Ce(l);t.writeParentInfo(!0),t.writeString(a)}else t.writeParentInfo(!1),t.writeLeftID(c.id)}else l.constructor===String?(t.writeParentInfo(!0),t.writeString(l)):l.constructor===Xt?(t.writeParentInfo(!1),t.writeLeftID(l)):Z();r!==null&&t.writeString(r)}this.content.write(t,n)}}const so=(e,t)=>lu[t&mn](e),lu=[()=>{Z()},zh,Gh,Hh,Xh,qh,Wh,ou,Jh,Kh,()=>{Z()}],cu=10;class at extends $i{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){Z()}write(t,n){t.writeInfo(cu),I(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const ro=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},oo="__ $YJS$ __";ro[oo]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");ro[oo]=!0;const au=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},hu=/[\uD800-\uDBFF]/,uu=/[\uDC00-\uDFFF]/,du=(e,t)=>{let n=0,i=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&hu.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&&uu.test(e[e.length-i])&&i--,{index:n,remove:e.length-n-i,insert:t.slice(n,t.length-i)}},fu=du,wt=(e,t)=>e>>>t|e<<32-t,pu=e=>wt(e,2)^wt(e,13)^wt(e,22),gu=e=>wt(e,6)^wt(e,11)^wt(e,25),mu=e=>wt(e,7)^wt(e,18)^e>>>3,xu=e=>wt(e,17)^wt(e,19)^e>>>10,bu=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]),wu=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class yu{constructor(){const t=new ArrayBuffer(320);this._H=new Uint32Array(t,0,8),this._H.set(wu),this._W=new Uint32Array(t,64,64)}_updateHash(){const t=this._H,n=this._W;for(let h=16;h<64;h++)n[h]=xu(n[h-2])+n[h-7]+mu(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+gu(l)+(l&c^~l&a)+bu[h]+n[h]>>>0,p=pu(i)+(i&s^i&r^s&r)>>>0,u=a,a=c,c=l,l=o+f>>>0,o=r,r=s,s=i,i=f+p>>>0;t[0]+=i,t[1]+=s,t[2]+=r,t[3]+=o,t[4]+=l,t[5]+=c,t[6]+=a,t[7]+=u}digest(t){let n=0;for(;n+56<=t.length;){let o=0;for(;o<16&&n+3<t.length;o++)this._W[o]=t[n++]<<24|t[n++]<<16|t[n++]<<8|t[n++];if(n%64!==0){for(this._W.fill(0,o,16);n<t.length;)this._W[o]|=t[n]<<(3-n%4)*8,n++;this._W[o]|=tt<<(3-n%4)*8}this._updateHash()}const i=n%64!==0;this._W.fill(0,0,16);let s=0;for(;n<t.length;s++)for(let o=3;o>=0&&n<t.length;o--)this._W[s]|=t[n++]<<o*8;i||(this._W[s-(n%4===0?0:1)]|=tt<<(3-n%4)*8),this._W[14]=t.byteLength/Ql,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 vu=e=>new yu().digest(e),R=new T.PluginKey("y-sync"),_t=new T.PluginKey("y-undo");new T.PluginKey("yjs-cursor");const Su=e=>{for(let n=6;n<e.length;n++)e[n%6]=e[n%6]^e[n];return e.slice(0,6)},Cu=e=>Zc(Su(vu(Qc(e)))),dn=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!ae(t.ds,e.id),ku=[{light:"#ecd44433",dark:"#ecd444"}],Eu=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){const i=Pt();e.forEach(s=>i.add(s)),t=t.filter(s=>!i.has(s))}e.set(n,Oc(t))}return e.get(n)},_u=(e,{colors:t=ku,colorMapping:n=new Map,permanentUserData:i=null,onFirstRender:s=()=>{},mapping:r}={})=>{let o=!1;const l=new Iu(e,r),c=new T.Plugin({props:{editable:a=>{const u=R.getState(a);return u.snapshot==null&&u.prevSnapshot==null}},key:R,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(R);if(h!==void 0){u=Object.assign({},u);for(const f in h)u[f]=h[f]}return u.addToHistory=a.getMeta("addToHistory")!==!1,u.isChangeOrigin=h!==void 0&&!!h.isChangeOrigin,u.isUndoRedoOperation=h!==void 0&&!!h.isChangeOrigin&&!!h.isUndoRedoOperation,l.prosemirrorView!==null&&h!==void 0&&(h.snapshot!=null||h.prevSnapshot!=null)&&vr(0,()=>{l.prosemirrorView!=null&&(h.restore==null?l._renderSnapshot(h.snapshot,h.prevSnapshot,u):(l._renderSnapshot(h.snapshot,h.snapshot,u),delete u.restore,delete u.snapshot,delete u.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),u}},view:a=>(l.initView(a),r==null&&l._forceRerender(),s(),{update:()=>{const u=c.getState(a.state);if(u.snapshot==null&&u.prevSnapshot==null&&(o||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(o=!0,u.addToHistory===!1&&!u.isChangeOrigin){const h=_t.getState(a.state),f=h&&h.undoManager;f&&f.stopCapturing()}l.mux(()=>{u.doc.transact(h=>{h.meta.set("addToHistory",u.addToHistory),l._prosemirrorChanged(a.state.doc)},R)})}},destroy:()=>{l.destroy()}})});return c},Tu=(e,t,n)=>{if(t!==null&&t.anchor!==null&&t.head!==null)if(t.type==="all")e.setSelection(new T.AllSelection(e.doc));else if(t.type==="node"){const i=me(n.doc,n.type,t.anchor,n.mapping);e.setSelection(Au(e,i))}else{const i=me(n.doc,n.type,t.anchor,n.mapping),s=me(n.doc,n.type,t.head,n.mapping);i!==null&&s!==null&&e.setSelection(T.TextSelection.between(e.doc.resolve(i),e.doc.resolve(s)))}},Au=(e,t)=>{const n=e.doc.resolve(t);return n.nodeAfter?T.NodeSelection.create(e.doc,t):T.TextSelection.near(n)},pi=(e,t)=>({type:t.selection.jsonID,anchor:pn(t.selection.anchor,e.type,e.mapping),head:pn(t.selection.head,e.type,e.mapping)});class Iu{constructor(t,n=new Map){this.type=t,this.prosemirrorView=null,this.mux=au(),this.mapping=n,this.isOMark=new Map,this._observeFunction=this._typeChanged.bind(this),this.doc=t.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=pi(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return this.prosemirrorView.hasFocus()?(ir&&this._domSelectionInView===null&&(vr(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){const t=this.prosemirrorView._root.getSelection();if(t==null||t.anchorNode==null)return!1;const n=this.prosemirrorView._root.createRange();n.setStart(t.anchorNode,t.anchorOffset),n.setEnd(t.focusNode,t.focusOffset),n.getClientRects().length===0&&n.startContainer&&n.collapsed&&n.selectNodeContents(n.startContainer);const s=n.getBoundingClientRect(),r=Me.documentElement;return s.bottom>=0&&s.right>=0&&s.left<=(window.innerWidth||r.clientWidth||0)&&s.top<=(window.innerHeight||r.clientHeight||0)}renderSnapshot(t,n){n||(n=jr(Ir(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(R,{snapshot:t,prevSnapshot:n}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{const t=this.type.toArray().map(i=>Ge(i,this.prosemirrorView.state.schema,this)).filter(i=>i!==null),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new T.Slice(T.Fragment.from(t),0,0));n.setMeta(R,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(n)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{const t=this.beforeTransactionSelection!==null?null:this.prosemirrorView.state.selection,n=this.type.toArray().map(s=>Ge(s,this.prosemirrorView.state.schema,this)).filter(s=>s!==null),i=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new T.Slice(T.Fragment.from(n),0,0));if(t){const s=ee(Ot(t.anchor,0),i.doc.content.size),r=ee(Ot(t.head,0),i.doc.content.size);i.setSelection(T.TextSelection.create(i.doc,s,r))}this.prosemirrorView.dispatch(i.setMeta(R,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(t,n,i){let s=this.doc,r=this.type;if(t||(t=Wn(this.doc)),t instanceof Uint8Array||n instanceof Uint8Array)if((!(t instanceof Uint8Array)||!(n instanceof Uint8Array))&&Z(),s=new zt({gc:!1}),ai(s,n),n=Wn(s),ai(s,t),t=Wn(s),r._item===null){const o=Array.from(this.doc.share.keys()).find(l=>this.doc.share.get(l)===this.type);r=s.getXmlFragment(o)}else{const o=s.store.clients.get(r._item.id.client)??[],l=pt(o,r._item.id.clock);r=o[l].content.type}this.mapping.clear(),this.mux(()=>{s.transact(o=>{const l=i.permanentUserData;l&&l.dss.forEach(h=>{jt(o,h,f=>{})});const c=(h,f)=>{const p=h==="added"?l.getUserByClientId(f.client):l.getUserByDeletedId(f);return{user:p,type:h,color:Eu(i.colorMapping,i.colors,p)}},a=zr(r,new Bi(n.ds,t.sv)).map(h=>!h._item.deleted||dn(h._item,t)||dn(h._item,n)?Ge(h,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},t,n,c):null).filter(h=>h!==null),u=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new T.Slice(T.Fragment.from(a),0,0));this.prosemirrorView.dispatch(u.setMeta(R,{isChangeOrigin:!0}))},R)})}_typeChanged(t,n){if(this.prosemirrorView==null)return;const i=R.getState(this.prosemirrorView.state);if(t.length===0||i.snapshot!=null||i.prevSnapshot!=null){this.renderSnapshot(i.snapshot,i.prevSnapshot);return}this.mux(()=>{const s=(l,c)=>this.mapping.delete(c);jt(n,n.deleteSet,l=>{if(l.constructor===M){const c=l.content.type;c&&this.mapping.delete(c)}}),n.changed.forEach(s),n.changedParentTypes.forEach(s);const r=this.type.toArray().map(l=>lo(l,this.prosemirrorView.state.schema,this)).filter(l=>l!==null);let o=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new T.Slice(T.Fragment.from(r),0,0));Tu(o,this.beforeTransactionSelection,this),o=o.setMeta(R,{isChangeOrigin:!0,isUndoRedoOperation:n.origin instanceof Ur}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)})}_prosemirrorChanged(t){this.doc.transact(()=>{mi(this.doc,this.type,t,this),this.beforeTransactionSelection=pi(this,this.prosemirrorView.state)},R)}initView(t){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=t,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}}const lo=(e,t,n,i,s,r)=>{const o=n.mapping.get(e);if(o===void 0){if(e instanceof J)return Ge(e,t,n,i,s,r);throw ct()}return o},Ge=(e,t,n,i,s,r)=>{const o=[],l=c=>{var a,u;if(c instanceof J){const h=lo(c,t,n,i,s,r);h!==null&&o.push(h)}else{const h=(u=(a=c._item.right)==null?void 0:a.content)==null?void 0:u.type;h instanceof Rt&&!h._item.deleted&&h._item.id.client===h.doc.clientID&&(c.applyDelta([{retain:c.length},...h.toDelta()]),h.doc.transact(p=>{h._item.delete(p)}));const f=Du(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 Bi(s.ds,i.sv)).forEach(l);try{const c=e.getAttributes(i);i!==void 0&&(dn(e._item,i)?dn(e._item,s)||(c.ychange=r?r("added",e._item.id):{type:"added"}):c.ychange=r?r("removed",e._item.id):{type:"removed"});const a=t.node(e.nodeName,c,o);return n.mapping.set(e,a),a}catch{return e.doc.transact(a=>{e._item.delete(a)},R),n.mapping.delete(e),null}},Du=(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,Bu(a.attributes,t)))}}catch{return e.doc.transact(a=>{e._item.delete(a)},R),null}return o},Mu=(e,t)=>{const n=new it,i=e.map(s=>({insert:s.text,attributes:ao(s.marks,t)}));return n.applyDelta(i),t.mapping.set(n,e),n},Ou=(e,t)=>{const n=new J(e.type.name);for(const i in e.attrs){const s=e.attrs[i];s!==null&&i!=="ychange"&&n.setAttribute(i,s)}return n.insert(0,Dn(e).map(i=>gi(i,t))),t.mapping.set(n,e),n},gi=(e,t)=>e instanceof Array?Mu(e,t):Ou(e,t),Es=e=>typeof e=="object"&&e!==null,Vi=(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||Es(o)&&Es(l)&&Vi(o,l)}return i},Dn=e=>{const t=e.content.content,n=[];for(let i=0;i<t.length;i++){const s=t[i];if(s.isText){const r=[];for(let o=t[i];i<t.length&&o.isText;o=t[++i])r.push(o);i--,n.push(r)}else n.push(s)}return n},co=(e,t)=>{const n=e.toDelta();return n.length===t.length&&n.every((i,s)=>i.insert===t[s].text&&er(i.attributes||{}).length===t[s].marks.length&&oe(i.attributes,(r,o)=>{var u;const l=Hi(o),c=t[s].marks;return c.find(h=>h.type.name===l)?Vi(r,(u=c.find(h=>h.type.name===l))==null?void 0:u.attrs):!1}))},Ae=(e,t)=>{if(e instanceof J&&!(t instanceof Array)&&xi(e,t)){const n=Dn(t);return e._length===n.length&&Vi(e.getAttributes(),t.attrs)&&e.toArray().every((i,s)=>Ae(i,n[s]))}return e instanceof it&&t instanceof Array&&co(e,t)},fn=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((n,i)=>t[i]===n),_s=(e,t,n)=>{const i=e.toArray(),s=Dn(t),r=s.length,o=i.length,l=ee(o,r);let c=0,a=0,u=!1;for(;c<l;c++){const h=i[c],f=s[c];if(fn(n.mapping.get(h),f))u=!0;else if(!Ae(h,f))break}for(;c+a<l;a++){const h=i[o-a-1],f=s[r-a-1];if(fn(n.mapping.get(h),f))u=!0;else if(!Ae(h,f))break}return{equalityFactor:c+a,foundMappedChild:u}},ju=e=>{let t="",n=e._start;const i={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof gt?t+=n.content.str:n.content instanceof F&&(i[n.content.key]=null)),n=n.right;return{str:t,nAttrs:i}},Ru=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:i,str:s}=ju(e),r=t.map(a=>({insert:a.text,attributes:Object.assign({},i,ao(a.marks,n))})),{insert:o,remove:l,index:c}=fu(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})))},Nu=/(.*)(--[a-zA-Z0-9+/=]{8})$/,Hi=e=>{var t;return((t=Nu.exec(e))==null?void 0:t[1])??e},Bu=(e,t)=>{const n=[];for(const i in e)n.push(t.mark(Hi(i),e[i]));return n},ao=(e,t)=>{const n={};return e.forEach(i=>{if(i.type.name!=="ychange"){const s=Tt(t.isOMark,i.type,()=>!i.type.excludes(i.type));n[s?`${i.type.name}--${Cu(i.toJSON())}`:i.type.name]=i.attrs}}),n},mi=(e,t,n,i)=>{if(t instanceof J&&t.nodeName!==n.type.name)throw new Error("node name mismatch!");if(i.mapping.set(t,n),t instanceof J){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=Dn(n),r=s.length,o=t.toArray(),l=o.length,c=ee(r,l);let a=0,u=0;for(;a<c;a++){const h=o[a],f=s[a];if(!fn(i.mapping.get(h),f))if(Ae(h,f))i.mapping.set(h,f);else break}for(;u+a+1<c;u++){const h=o[l-u-1],f=s[r-u-1];if(!fn(i.mapping.get(h),f))if(Ae(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 it&&p instanceof Array)co(f,p)||Ru(f,p,i),a+=1;else{let w=f instanceof J&&xi(f,p),y=g instanceof J&&xi(g,x);if(w&&y){const C=_s(f,p,i),k=_s(g,x,i);C.foundMappedChild&&!k.foundMappedChild?y=!1:!C.foundMappedChild&&k.foundMappedChild||C.equalityFactor<k.equalityFactor?w=!1:y=!1}w?(mi(e,f,p,i),a+=1):y?(mi(e,g,x,i),u+=1):(i.mapping.delete(t.get(a)),t.delete(a,1),t.insert(a,[gi(p,i)]),a+=1)}}const h=l-a-u;if(l===1&&r===0&&o[0]instanceof it?(i.mapping.delete(o[0]),o[0].delete(0,o[0].length)):h>0&&(t.slice(a,a+h).forEach(f=>i.mapping.delete(f)),t.delete(a,h)),a+u<r){const f=[];for(let p=a;p<r-u;p++)f.push(gi(s[p],i));t.insert(a,f)}},R)},xi=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,pn=(e,t,n)=>{if(e===0)return qn(t,0,-1);let i=t._first===null?null:t._first.content.type;for(;i!==null&&t!==i;){if(i instanceof it){if(i._length>=e)return qn(i,e,-1);if(e-=i._length,i._item!==null&&i._item.next!==null)i=i._item.next.content.type;else{do i=i._item===null?null:i._item.parent,e--;while(i!==t&&i!==null&&i._item!==null&&i._item.next===null);i!==null&&i!==t&&(i=i._item===null?null:i._item.next.content.type)}}else{const s=(n.get(i)||{nodeSize:0}).nodeSize;if(i._first!==null&&e<s)i=i._first.content.type,e--;else{if(e===1&&i._length===0&&s>1)return new on(i._item===null?null:i._item.id,i._item===null?Ce(i):null,null);if(e-=s,i._item!==null&&i._item.next!==null)i=i._item.next.content.type;else{if(e===0)return i=i._item===null?i:i._item.parent,new on(i._item===null?null:i._item.id,i._item===null?Ce(i):null,null);do i=i._item.parent,e--;while(i!==t&&i._item.next===null);i!==t&&(i=i._item.next.content.type)}}}if(i===null)throw Z();if(e===0&&i.constructor!==it&&i!==t)return Lu(i._item.parent,i._item)}return qn(t,t._length,-1)},Lu=(e,t)=>{let n=null,i=null;return e._item===null?i=Ce(e):n=_(e._item.id.client,e._item.id.clock),new on(n,i,t.id)},me=(e,t,n,i)=>{const s=ah(n,e);if(s===null||s.type!==t&&!ke(t,s.type._item))return null;let r=s.type,o=0;if(r.constructor===it)o=s.index;else if(r._item===null||!r._item.deleted){let l=r._first,c=0;for(;c<r._length&&c<s.index&&l!==null;){if(!l.deleted){const a=l.content.type;c++,a instanceof it?o+=a._length:o+=i.get(a).nodeSize}l=l.right}o+=1}for(;r!==t&&r._item!==null;){const l=r._item.parent;if(l._item===null||!l._item.deleted){o+=1;let c=l._first;for(;c!==null;){const a=c.content.type;if(a===r)break;c.deleted||(a instanceof it?o+=a._length:o+=i.get(a).nodeSize),c=c.right}}r=l}return o-1};function Uu(e){const t=e.toArray(),n=i=>{let s;if(i instanceof it)s=i.toDelta().map(o=>{const l={type:"text",text:o.insert};return o.attributes&&(l.marks=Object.keys(o.attributes).map(c=>{const a=o.attributes[c],h={type:Hi(c)};return Object.keys(a)&&(h.attrs=a),h})),l});else if(i instanceof J){s={type:i.nodeName};const r=i.getAttributes();Object.keys(r).length&&(s.attrs=r);const o=i.toArray();o.length&&(s.content=o.map(n).flat())}else Z();return s};return{type:"doc",content:t.map(n)}}const Pu=e=>{const t=_t.getState(e).undoManager;if(t!=null)return t.undo(),!0},$u=e=>{const t=_t.getState(e).undoManager;if(t!=null)return t.redo(),!0},Fu=new Set(["paragraph"]),Vu=(e,t)=>!(e instanceof M)||!(e.content instanceof mt)||!(e.content.type instanceof Rt||e.content.type instanceof J&&t.has(e.content.type.nodeName))||e.content.type._length===0,Hu=({protectedNodes:e=Fu,trackedOrigins:t=[],undoManager:n=null}={})=>new T.Plugin({key:_t,state:{init:(i,s)=>{const r=R.getState(s),o=n||new Ur(r.type,{trackedOrigins:new Set([R].concat(t)),deleteFilter:l=>Vu(l,e),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(i,s,r,o)=>{const l=R.getState(o).binding,c=s.undoManager,a=c.undoStack.length>0,u=c.redoStack.length>0;return l?{undoManager:c,prevSel:pi(l,r),hasUndoOps:a,hasRedoOps:u}:a!==s.hasUndoOps||u!==s.hasRedoOps?Object.assign({},s,{hasUndoOps:c.undoStack.length>0,hasRedoOps:c.redoStack.length>0}):s}},view:i=>{const s=R.getState(i.state),r=_t.getState(i.state).undoManager;return r.on("stack-item-added",({stackItem:o})=>{const l=s.binding;l&&o.meta.set(l,_t.getState(i.state).prevSel)}),r.on("stack-item-popped",({stackItem:o})=>{const l=s.binding;l&&(l.beforeTransactionSelection=o.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{r.destroy()}}}});function ho(e){return!!e.getMeta(R)}function zu(e,t){const n=R.getState(e);return me(n.doc,n.type,t,n.binding.mapping)||0}function uo(e,t){const n=R.getState(e);return pn(t,n.type,n.binding.mapping)}var Ye=class fo extends T.MappablePosition{constructor(t,n){super(t),this.yRelativePosition=n}static fromJSON(t){return new fo(t.position,t.yRelativePosition)}toJSON(){return{position:this.position,yRelativePosition:this.yRelativePosition}}};function Ku(e,t){const n=uo(t,e);return new Ye(e,n)}function qu(e,t,n){const i=e instanceof Ye?e.yRelativePosition:null;if(ho(t)&&i){const o=zu(n,i);return{position:new Ye(o,i),mapResult:null}}const s=T.getUpdatedPosition(e,t),r=s.position.position;return{position:new Ye(r,i??uo(n,r)),mapResult:s.mapResult}}T.Extension.create({name:"collaboration",priority:1e3,addOptions(){return{document:null,field:"default",fragment:null,provider:null}},addStorage(){return{isDisabled:!1}},onCreate(){this.editor.extensionManager.extensions.find(e=>e.name==="undoRedo")&&console.warn('[tiptap warn]: "@tiptap/extension-collaboration" comes with its own history support and is not compatible with "@tiptap/extension-undo-redo".')},onBeforeCreate(){this.editor.utils.getUpdatedPosition=(e,t)=>qu(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>Ku(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),_t.getState(t).undoManager.undoStack.length===0?!1:n?Pu(t):!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),_t.getState(t).undoManager.redoStack.length===0?!1:n?$u(t):!0)}},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo()}},addProseMirrorPlugins(){var e;const t=this.options.fragment?this.options.fragment:this.options.document.getXmlFragment(this.options.field),n=Hu(this.options.yUndoOptions),i=n.spec.view;n.spec.view=o=>{const{undoManager:l}=_t.getState(o.state);l.restore&&(l.restore(),l.restore=()=>{});const c=i?i(o):void 0;return{destroy:()=>{const a=l.trackedOrigins.has(l),u=l._observers;l.restore=()=>{a&&l.trackedOrigins.add(l),l.doc.on("afterTransaction",l.afterTransactionHandler),l._observers=u},c!=null&&c.destroy&&c.destroy()}}};const s={...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender},r=_u(t,s);return this.editor.options.enableContentCheck&&((e=t.doc)==null||e.on("beforeTransaction",()=>{try{const o=Uu(t);if(o.content.length===0)return;this.editor.schema.nodeFromJSON(o).check()}catch(o){return this.editor.emit("contentError",{error:o,editor:this.editor,disableCollaboration:()=>{var l;(l=t.doc)==null||l.destroy(),this.storage.isDisabled=!0}}),!1}})),[r,n,this.editor.options.enableContentCheck&&new W.Plugin({key:new W.PluginKey("filterInvalidContent"),filterTransaction:()=>{var o;return this.storage.isDisabled!==!1&&((o=t.doc)==null||o.destroy()),!0}})].filter(Boolean)}});function Ts(e){if(!e.length)return Nn.DecorationSet.empty;const t=[],n=e[0].$from.node(0);return e.forEach(i=>{const s=i.$from.pos,r=i.$from.nodeAfter;r&&t.push(Nn.Decoration.node(s,s+r.nodeSize,{class:"ProseMirror-selectednoderange"}))}),Nn.DecorationSet.create(n,t)}function Mn(e,t,n){const i=[],s=e.node(0);typeof n=="number"&&n>=0||(e.sameParent(t)?n=Math.max(0,e.sharedDepth(t.pos)-1):n=e.sharedDepth(t.pos));const r=new Mo.NodeRange(e,t,n),o=r.depth===0?0:s.resolve(r.start).posAtIndex(0);return r.parent.forEach((l,c)=>{const a=o+c,u=a+l.nodeSize;if(a<r.start||a>=r.end)return;const h=new W.SelectionRange(s.resolve(a),s.resolve(u));i.push(h)}),i}var Wu=class po{constructor(t,n){this.anchor=t,this.head=n}map(t){return new po(t.map(this.anchor),t.map(this.head))}resolve(t){const n=t.resolve(this.anchor),i=t.resolve(this.head);return new Mt(n,i)}},Mt=class It extends W.Selection{constructor(t,n,i,s=1){const{doc:r}=t,o=t===n,l=t.pos===r.content.size&&n.pos===r.content.size,c=o&&!l?r.resolve(n.pos+(s>0?1:-1)):n,a=o&&l?r.resolve(t.pos-(s>0?1:-1)):t,u=Mn(a.min(c),a.max(c),i),h=c.pos>=t.pos?u[0].$from:u[u.length-1].$to,f=c.pos>=t.pos?u[u.length-1].$to:u[0].$from;super(h,f,u),this.depth=i}get $to(){return this.ranges[this.ranges.length-1].$to}eq(t){return t instanceof It&&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 It(i,s)}toJSON(){return{type:"nodeRange",anchor:this.anchor,head:this.head}}get isForwards(){return this.head>=this.anchor}get isBackwards(){return!this.isForwards}extendBackwards(){const{doc:t}=this.$from;if(this.isForwards&&this.ranges.length>1){const s=this.ranges.slice(0,-1),r=s[0].$from,o=s[s.length-1].$to;return new It(r,o,this.depth)}const n=this.ranges[0],i=t.resolve(Math.max(0,n.$from.pos-1));return new It(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 It(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 It(this.$anchor,i,this.depth)}static fromJSON(t,n){return new It(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,i,s,r=1){return new this(t.resolve(n),t.resolve(i),s,r)}getBookmark(){return new Wu(this.anchor,this.head)}};Mt.prototype.visible=!1;function $e(e){return e instanceof Mt}T.Extension.create({name:"nodeRange",addOptions(){return{depth:void 0,key:"Mod"}},addKeyboardShortcuts(){return{"Shift-ArrowUp":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,selection:r,tr:o}=i,{anchor:l,head:c}=r;if(!$e(r)){const u=Mt.create(s,l,c,t,-1);return o.setSelection(u),n.dispatch(o),!0}const a=r.extendBackwards();return o.setSelection(a),n.dispatch(o),!0},"Shift-ArrowDown":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,selection:r,tr:o}=i,{anchor:l,head:c}=r;if(!$e(r)){const u=Mt.create(s,l,c,t);return o.setSelection(u),n.dispatch(o),!0}const a=r.extendForwards();return o.setSelection(a),n.dispatch(o),!0},"Mod-a":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,tr:r}=i,o=Mt.create(s,0,s.content.size,t);return r.setSelection(o),n.dispatch(r),!0}}},onSelectionUpdate(){const{selection:e}=this.editor.state;$e(e)&&this.editor.view.dom.classList.add("ProseMirror-noderangeselection")},addProseMirrorPlugins(){let e=!1,t=!1;return[new W.Plugin({key:new W.PluginKey("nodeRange"),props:{attributes:()=>e?{class:"ProseMirror-noderangeselection"}:{class:""},handleDOMEvents:{mousedown:(n,i)=>{const{key:s}=this.options,r=/Mac/.test(navigator.platform),o=!!i.shiftKey,l=!!i.ctrlKey,c=!!i.altKey,a=!!i.metaKey,u=r?a:l;return(s==null||s==="Shift"&&o||s==="Control"&&l||s==="Alt"&&c||s==="Meta"&&a||s==="Mod"&&u)&&(t=!0),t&&document.addEventListener("mouseup",()=>{t=!1;const{state:h}=n,{doc:f,selection:p,tr:g}=h,{$anchor:x,$head:w}=p;if(x.sameParent(w))return;const y=Mt.create(f,x.pos,w.pos,this.options.depth);g.setSelection(y),n.dispatch(g)},{once:!0}),!1}},decorations:n=>{const{selection:i}=n,s=$e(i);if(e=!1,!t)return s?(e=!0,Ts(i.ranges)):null;const{$from:r,$to:o}=i;if(!s&&r.sameParent(o))return null;const l=Mn(r,o,this.options.depth);return l.length?(e=!0,Ts(l)):null}}})]}});function Gu(e){let t="";const n=getComputedStyle(e);for(let i=0;i<n.length;i+=1)t+=`${n[i]}:${n.getPropertyValue(n[i])};`;return t}function Yu(e){const t=e.cloneNode(!0),n=[e,...Array.from(e.getElementsByTagName("*"))],i=[t,...Array.from(t.getElementsByTagName("*"))];return n.forEach((s,r)=>{i[r].style.cssText=Gu(s)}),t}var Ju={id:"listItemFirstChild",evaluate:({parent:e,isFirst:t})=>t&&e&&["listItem","taskItem"].includes(e.type.name)?1e3:0},Xu={id:"listWrapperDeprioritize",evaluate:({node:e})=>{const t=["listItem","taskItem"],n=e.firstChild;return n&&t.includes(n.type.name)?1e3:0}},Zu={id:"tableStructure",evaluate:({node:e,parent:t})=>["tableRow","tableCell","tableHeader"].includes(e.type.name)||t&&t.type.name==="tableHeader"?1e3:0},Qu={id:"inlineContent",evaluate:({node:e})=>e.isInline||e.isText?1e3:0},td=[Ju,Xu,Zu,Qu],As={edges:["left","top"],threshold:12,strength:500};function Jn(e){return e===void 0||e==="left"?{...As}:e==="right"?{edges:["right","top"],threshold:12,strength:500}:e==="both"?{edges:["left","right","top"],threshold:12,strength:500}:e==="none"?{edges:[],threshold:0,strength:0}:{...As,...e}}function ed(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 nd(e,t,n,i){return!t||n.edges.length===0?0:ed(e,t,n)?n.strength*i:0}var id=1e3;function Is(e,t,n,i){let s=id,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-=nd(i,o,n,e.depth),s<=0?-1:s}function Ds(e,t,n){return Array.from({length:t},(s,r)=>t-1-r).some(s=>n.includes(e.node(s).type.name))}function sd(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(...td),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&&!Ds(r,h,n.allowedContainers))return null;const g=h>0?r.node(h-1):null,x=h>0?r.index(h-1):0,w=g?g.childCount:1,y={node:f,pos:p,depth:h,parent:g,index:x,isFirst:x===0,isLast:x===w-1,$pos:r,view:e},C=Is(y,o,n.edgeDetection,t);if(C<0)return null;const k=e.nodeDOM(p);return{node:f,pos:p,depth:h,score:C,dom:k}}).filter(h=>h!==null),a=r.nodeAfter;if(a&&a.isAtom&&!a.isInline){const h=i.pos,f=r.depth+1,p=r.parent,g=r.index(),x=p.childCount;let w=!0;if(n.allowedContainers&&(w=Ds(r,f,n.allowedContainers)),w){const y={node:a,pos:h,depth:f,parent:p,index:g,isFirst:g===0,isLast:g===x-1,$pos:r,view:e},C=Is(y,o,n.edgeDetection,t);if(C>=0){const k=e.nodeDOM(h);k&&c.push({node:a,pos:h,depth:f,score:C,dom:k})}}}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 rd(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 Ms(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 od(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(!Ms(l)||!Ms(c))return null;const a=Math.min(Math.max(l.top+i,n),c.bottom-i),u=.5,h=Math.abs(l.left-c.left)<u,f=Math.abs(l.right-c.right)<u;let p=l;h&&f&&(p=l);const g=Math.min(Math.max(p.left+i,t),p.right-i);return!Number.isFinite(g)||!Number.isFinite(a)?null:{x:g,y:a}}var go=e=>{const{x:t,y:n,editor:i,nestedOptions:s}=e,{view:r,state:o}=i,l=od(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=sd(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=rd(g,r);return x?(h=x,!0):!1}),!h)return{resultElement:null,resultNode:null,pos:null};let f;try{f=r.posAtDOM(h,0)}catch{return{resultElement:null,resultNode:null,pos:null}}const p=o.doc.nodeAt(f);if(!p){const g=o.doc.resolve(f),x=g.parent;return{resultElement:h,resultNode:x,pos:g.start()}}return{resultElement:h,resultNode:p,pos:f}};function mo(e){var t;(t=e.parentNode)==null||t.removeChild(e)}function ld(e,t,n,i){const{doc:s}=t.view.state;if(n!=null&&n.enabled&&(i!=null&&i.node)&&i.pos>=0){const a=i.pos,u=i.pos+i.node.nodeSize;return[{$from:s.resolve(a),$to:s.resolve(u)}]}const r=go({editor:t,x:e.clientX,y:e.clientY,nestedOptions:n});if(!r.resultNode||r.pos===null)return[];const o=r.resultNode.isText||r.resultNode.isAtom?0:-1,l=s.resolve(r.pos),c=s.resolve(r.pos+r.resultNode.nodeSize+o);return Mn(l,c,0)}function cd(e,t,n,i){const{view:s}=t;if(!e.dataTransfer)return;const{empty:r,$from:o,$to:l}=s.state.selection,c=ld(e,t,n,i),a=Mn(o,l,0),u=a.some(D=>c.find(L=>L.$from===D.$from&&L.$to===D.$to)),h=r||!u?c:a;if(!h.length)return;const{tr:f}=s.state,p=document.createElement("div"),g=h[0].$from.pos,x=h[h.length-1].$to.pos,w=(n==null?void 0:n.enabled)&&(i==null?void 0:i.node);let y,C;w?(y=s.state.doc.slice(g,x),C=W.NodeSelection.create(s.state.doc,g)):(C=Mt.create(s.state.doc,g,x),y=C.content()),h.forEach(D=>{const L=s.nodeDOM(D.$from.pos),v=Yu(L);p.append(v)}),p.style.position="absolute",p.style.top="-10000px",document.body.append(p),e.dataTransfer.clearData(),e.dataTransfer.setDragImage(p,0,0);const k=C instanceof W.NodeSelection?C:void 0;s.dragging={slice:y,move:!0,node:k},f.setSelection(C),s.dispatch(f),document.addEventListener("drop",()=>mo(p),{once:!0})}var Os=(e,t)=>{const n=e.resolve(t),{depth:i}=n;return i===0?t:n.pos-n.parentOffset-1},js=(e,t)=>{const n=e.nodeAt(t),i=e.resolve(t);let{depth:s}=i,r=n;for(;s>0;){const o=i.node(s);s-=1,s===0&&(r=o)}return r},Xn=(e,t)=>{const n=R.getState(e);return n?pn(t,n.type,n.binding.mapping):null},ad=(e,t)=>{const n=R.getState(e);return n?me(n.doc,n.type,t,n.binding.mapping)||0:-1},Rs=(e,t)=>{let n=t;for(;n!=null&&n.parentNode&&n.parentNode!==e.dom;)n=n.parentNode;return n},xo=new W.PluginKey("dragHandle"),bo=({pluginKey:e=xo,element:t,editor:n,computePositionConfig:i,getReferencedVirtualElement:s,onNodeChange:r,onElementDragStart:o,onElementDragEnd:l,nestedOptions:c})=>{const a=document.createElement("div");let u=!1,h=null,f=-1,p,g=null,x=null;function w(){t&&(t.style.visibility="hidden",t.style.pointerEvents="none")}function y(){if(t){if(!n.isEditable){w();return}t.style.visibility="",t.style.pointerEvents="auto"}}function C(v){const S=(s==null?void 0:s())||{getBoundingClientRect:()=>v.getBoundingClientRect()};H.computePosition(S,t,i).then(A=>{Object.assign(t.style,{position:A.strategy,left:`${A.x}px`,top:`${A.y}px`})})}function k(v){o==null||o(v),cd(v,n,c,{node:h,pos:f}),t&&(t.dataset.dragging="true"),setTimeout(()=>{t&&(t.style.pointerEvents="none")},0)}function D(v){l==null||l(v),w(),t&&(t.style.pointerEvents="auto",t.dataset.dragging="false")}function L(){if(T.isFirefox()){const v=n.view.dom;requestAnimationFrame(()=>{v.isContentEditable&&(v.contentEditable="false",v.contentEditable="true")})}}return a.appendChild(t),{unbind(){t.removeEventListener("dragstart",k),t.removeEventListener("dragend",D),document.removeEventListener("drop",L),g&&(cancelAnimationFrame(g),g=null,x=null)},plugin:new W.Plugin({key:typeof e=="string"?new W.PluginKey(e):e,state:{init(){return{locked:!1}},apply(v,S,A,z){const N=v.getMeta("lockDragHandle"),$=v.getMeta("hideDragHandle");if(N!==void 0&&(u=N),$)return w(),u=!1,h=null,f=-1,r==null||r({editor:n,node:null,pos:-1}),S;if(v.docChanged&&f!==-1&&t)if(ho(v)){const Y=ad(z,p);Y!==f&&(f=Y)}else{const Y=v.mapping.map(f);Y!==f&&(f=Y,p=Xn(z,f))}return S}},view:v=>{var S;return t.draggable=!0,t.style.pointerEvents="auto",t.dataset.dragging="false",(S=n.view.dom.parentElement)==null||S.appendChild(a),a.style.pointerEvents="none",a.style.position="absolute",a.style.top="0",a.style.left="0",t.addEventListener("dragstart",k),t.addEventListener("dragend",D),document.addEventListener("drop",L),{update(A,z){if(!t)return;if(!n.isEditable){w();return}if(u?t.draggable=!1:t.draggable=!0,v.state.doc.eq(z.doc)||f===-1)return;let N=v.nodeDOM(f);if(N=Rs(v,N),N===v.dom||(N==null?void 0:N.nodeType)!==1)return;const $=v.posAtDOM(N,0),Y=js(n.state.doc,$),st=Os(n.state.doc,$);h=Y,f=st,p=Xn(v.state,f),r==null||r({editor:n,node:h,pos:f}),C(N)},destroy(){t.removeEventListener("dragstart",k),t.removeEventListener("dragend",D),document.removeEventListener("drop",L),g&&(cancelAnimationFrame(g),g=null,x=null),t&&mo(a)}}},props:{handleDOMEvents:{keydown(v){return!t||u||v.hasFocus()&&(w(),h=null,f=-1,r==null||r({editor:n,node:null,pos:-1})),!1},mouseleave(v,S){return u||S.target&&!a.contains(S.relatedTarget)&&(w(),h=null,f=-1,r==null||r({editor:n,node:null,pos:-1})),!1},mousemove(v,S){return!t||u||(x={x:S.clientX,y:S.clientY},g)||(g=requestAnimationFrame(()=>{if(g=null,!x)return;const{x:A,y:z}=x;x=null;const N=go({x:A,y:z,editor:n,nestedOptions:c});if(!N.resultElement)return;let $=N.resultElement,Y=N.resultNode,st=N.pos;if(!(c!=null&&c.enabled)){if($=Rs(v,$),$===v.dom||($==null?void 0:$.nodeType)!==1)return;const E=v.posAtDOM($,0);Y=js(n.state.doc,E),st=Os(n.state.doc,E)}Y!==h&&(h=Y,f=st??-1,p=Xn(v.state,f),r==null||r({editor:n,node:h,pos:f}),C($),y())})),!1}}}})}};function wo(e){var t,n;return e===!1||e===void 0?{enabled:!1,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Jn("none")}:e===!0?{enabled:!0,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Jn("left")}:{enabled:!0,rules:(t=e.rules)!=null?t:[],defaultRules:(n=e.defaultRules)!=null?n:!0,allowedContainers:e.allowedContainers,edgeDetection:Jn(e.edgeDetection)}}var bi={placement:"left-start",strategy:"absolute"};T.Extension.create({name:"dragHandle",addOptions(){return{render(){const e=document.createElement("div");return e.classList.add("drag-handle"),e},computePositionConfig:{},locked:!1,onNodeChange:()=>null,onElementDragStart:void 0,onElementDragEnd:void 0,nested:!1}},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=wo(this.options.nested);return[bo({computePositionConfig:{...bi,...this.options.computePositionConfig},getReferencedVirtualElement:this.options.getReferencedVirtualElement,element:e,editor:this.editor,onNodeChange:this.options.onNodeChange,onElementDragStart:this.options.onElementDragStart,onElementDragEnd:this.options.onElementDragEnd,nestedOptions:t}).plugin]}});var hd=e=>{const{className:t="drag-handle",children:n,editor:i,pluginKey:s=xo,onNodeChange:r,onElementDragStart:o,onElementDragEnd:l,computePositionConfig:c=bi,nested:a=!1}=e,[u,h]=b.useState(null),f=b.useRef(null),p=b.useMemo(()=>wo(a),[JSON.stringify(a)]);return b.useEffect(()=>{let g=null;return u?i.isDestroyed?()=>{f.current=null}:(f.current||(g=bo({editor:i,element:u,pluginKey:s,computePositionConfig:{...bi,...c},onElementDragStart:o,onElementDragEnd:l,onNodeChange:r,nestedOptions:p}),f.current=g.plugin,i.registerPlugin(f.current)),()=>{i.unregisterPlugin(s),f.current=null,g&&(g.unbind(),g=null)}):()=>{f.current=null}},[u,i,r,s,c,o,l,p]),d.jsx("div",{className:t,style:{visibility:"hidden",position:"absolute"},"data-dragging":"false",ref:h,children:n})},ud=hd;function dd(){var v,S,A,z,N,$,Y,st;const e=m.useEditorInstance(),t=m.useEditableEditor(),{t:n}=B.useLocale(),[i,s]=b.useState(null),[r,o]=b.useState(-1),[l,c]=b.useState(!1),a=(S=(v=e==null?void 0:e.extensionManager)==null?void 0:v.extensions)==null?void 0:S.some(E=>(E==null?void 0:E.name)===Ps.TextAlign.name),u=(z=(A=e==null?void 0:e.extensionManager)==null?void 0:A.extensions)==null?void 0:z.some(E=>(E==null?void 0:E.name)===de.Indent.name),h=($=(N=e==null?void 0:e.extensionManager)==null?void 0:N.extensions)==null?void 0:$.some(E=>(E==null?void 0:E.name)===Oo.Clear.name);function f(){const E=e.chain();E.setNodeSelection(r).unsetAllMarks(),(i==null?void 0:i.type.name)!=="paragraph"&&E.setParagraph(),E.run()}function p(){e.chain().focus().setNodeSelection(r).run(),document.execCommand("copy")}function g(){e.commands.setNodeSelection(r);const{$anchor:E}=e.state.selection,vt=E.node(1)||e.state.selection.node;e.chain().setMeta("hideDragHandle",!0).insertContentAt(r+((i==null?void 0:i.nodeSize)||0),vt.toJSON()).run()}function x(E){e.commands.setTextAlign(E)}function w(){const E=de.setNodeIndentMarkup(e.state.tr,r,1);E.setMeta("hideDragHandle",!0),e.view.dispatch&&e.view.dispatch(E)}function y(){const E=de.setNodeIndentMarkup(e.state.tr,r,-1);e.view.dispatch&&e.view.dispatch(E)}function C(){e.chain().setMeta("hideDragHandle",!0).setNodeSelection(r).deleteSelection().run()}const k=b.useCallback(E=>{E.node&&s(E.node),o(E.pos),requestAnimationFrame(()=>{E.editor.commands.focus()})},[]),D=E=>{var vt;if(E.preventDefault(),r!==-1){const Re=(i==null?void 0:i.nodeSize)||0,qt=r+Re,zi=(i==null?void 0:i.type.name)==="paragraph"&&((vt=i==null?void 0:i.content)==null?void 0:vt.size)===0,yo=zi?r+2:qt+2;e.chain().command(({dispatch:Ki,tr:On,state:qi})=>Ki?(zi?On.insertText("/",r,r+1):On.insert(qt,qi.schema.nodes.paragraph.create(null,[qi.schema.text("/")])),Ki(On)):!0).focus(yo).run()}};b.useEffect(()=>(l?e.commands.setMeta("lockDragHandle",!0):e.commands.setMeta("lockDragHandle",!1),()=>{e.commands.setMeta("lockDragHandle",!1)}),[l]);const L=E=>{t&&c(E)};return d.jsx(ud,{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:D,disabled:!t,icon:"Plus",tooltip:n("editor.draghandle.insertBlock")}),d.jsx(m.ActionButton,{disabled:!t,icon:"Grip",tooltip:n("editor.draghandle.grip"),action:E=>{E.preventDefault(),E.stopPropagation(),L(!l)}}),d.jsxs(U.DropdownMenu,{onOpenChange:L,open:l,children:[d.jsx(U.DropdownMenuTrigger,{className:"richtext-pointer-events-none"}),d.jsxs(U.DropdownMenuContent,{align:"start",className:"richtext-w-48",hideWhenDetached:!0,side:"bottom",sideOffset:0,children:[d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3 richtext-bg-opacity-10 hover:richtext-bg-red-400 hover:richtext-bg-opacity-20 focus:richtext-bg-red-400 focus:richtext-bg-opacity-30 focus:richtext-text-red-500 dark:hover:richtext-bg-opacity-20 dark:hover:richtext-text-red-500",onClick:C,children:[d.jsx(m.IconComponent,{name:"Trash2"}),d.jsx("span",{children:n("editor.remove")})]}),h?d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:f,children:[d.jsx(m.IconComponent,{name:"PaintRoller"}),d.jsx("span",{children:n("editor.clear.tooltip")})]}):null,d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:p,children:[d.jsx(m.IconComponent,{name:"Clipboard"}),d.jsx("span",{children:n("editor.copyToClipboard")})]}),d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:g,children:[d.jsx(m.IconComponent,{name:"Copy"}),d.jsx("span",{children:n("editor.copy")})]}),a||u?d.jsx(U.DropdownMenuSeparator,{}):null,a?d.jsxs(U.DropdownMenuSub,{children:[d.jsxs(U.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[d.jsx(m.IconComponent,{name:"AlignCenter"}),d.jsx("span",{children:n("editor.textalign.tooltip")})]}),d.jsx(U.DropdownMenuPortal,{children:d.jsxs(U.DropdownMenuSubContent,{children:[d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("left"),children:[d.jsx(m.IconComponent,{name:"AlignLeft"}),d.jsx("span",{children:n("editor.textalign.left.tooltip")})]}),d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("center"),children:[d.jsx(m.IconComponent,{name:"AlignCenter"}),d.jsx("span",{children:n("editor.textalign.center.tooltip")})]}),d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("right"),children:[d.jsx(m.IconComponent,{name:"AlignRight"}),d.jsx("span",{children:n("editor.textalign.right.tooltip")})]})]})})]}):null,u?d.jsxs(U.DropdownMenuSub,{children:[d.jsxs(U.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[d.jsx(m.IconComponent,{name:"IndentIncrease"}),d.jsx("span",{children:n("editor.indent")})]}),d.jsx(U.DropdownMenuPortal,{children:d.jsxs(U.DropdownMenuSubContent,{children:[d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((Y=i==null?void 0:i.attrs)==null?void 0:Y.indent)>=de.IndentProps.max,onClick:w,children:[d.jsx(m.IconComponent,{name:"IndentIncrease"}),d.jsx("span",{children:n("editor.indent.tooltip")})]}),d.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((st=i==null?void 0:i.attrs)==null?void 0:st.indent)<=de.IndentProps.min,onClick:y,children:[d.jsx(m.IconComponent,{name:"IndentDecrease"}),d.jsx("span",{children:n("editor.outdent.tooltip")})]})]})})]}):null]})]})]})})}const Ns={plaintext:"Plain Text",js:"JavaScript",ts:"TypeScript",css:"CSS",html:"HTML",python:"Python",bash:"Bash"};function fd({listLanguages:e}){const{t}=B.useLocale(),[n,i]=b.useState(!1),s=m.useEditorInstance(),r=b.useMemo(()=>{const{selection:l}=s.state,c=l.$from.parent;if(c.type.name==="codeBlock"){const a=c.attrs.language||"plaintext";return Ns[a]||a}},[s.state,e]),o=b.useMemo(()=>{let l=e||[];return e!=null&&e.includes("plaintext")||(l=["plaintext",...l]),l.map(c=>({label:Ns[c]||c,value:c}))},[e]);return d.jsxs(kt.Popover,{modal:!0,onOpenChange:i,open:n,children:[d.jsx(kt.PopoverTrigger,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:d.jsxs(m.ActionButton,{dataState:!!r,children:[r?d.jsx(d.Fragment,{children:r}):d.jsx(d.Fragment,{children:t("editor.paragraph.tooltip")}),d.jsx(m.IconComponent,{className:"richtext-ml-1 richtext-size-3 richtext-text-zinc-500",name:"MenuDown"})]})}),d.jsx(kt.PopoverContent,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:o==null?void 0:o.map(l=>d.jsxs("div",{className:"richtext-flex richtext-w-full richtext-items-center richtext-gap-3 richtext-rounded-sm !richtext-border-none !richtext-bg-transparent richtext-px-2 richtext-py-1.5 richtext-text-left richtext-text-sm richtext-text-foreground !richtext-outline-none richtext-transition-colors hover:!richtext-bg-accent",onClick:c=>{c.preventDefault(),s.chain().focus().setCodeBlock({language:l.value}).run(),i(!1)},children:[d.jsx("div",{className:"!richtext-min-w-[20px]",children:r===l.value&&d.jsx(Ut.Check,{size:16})}),d.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:l.label})]},l.value))})]})}function pd(){const e=m.useEditableEditor(),t=m.useEditorInstance(),n=m.useExtension(Rn.CodeBlock.name),i=b.useCallback(({editor:c})=>c.isActive(Rn.CodeBlock.name),[]),s=b.useMemo(()=>{var c,a,u;return n?((u=(a=(c=n.options)==null?void 0:c.lowlight)==null?void 0:a.listLanguages)==null?void 0:u.call(a))||["plaintext","html","css","js","ts"]:[]},[n]),r=b.useCallback(()=>Ht(Rn.CodeBlock.name,t),[t]),o=()=>{const{from:c}=t.state.selection,a=t.state.doc.resolve(c);for(let u=a.depth;u>=0;u--){const h=a.node(u);if(h.type.name==="codeBlock")return h.textContent}return""},l=()=>{const c=o();navigator.clipboard.writeText(c)};return e?d.jsx(et,{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(fd,{listLanguages:s}),d.jsx(bt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(m.ActionButton,{action:l,tooltip:"Copy",children:d.jsx(Ut.Copy,{size:16})}),d.jsx(bt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(m.ActionButton,{action:r,tooltip:"Delete",children:d.jsx(Ut.Trash2,{size:16})})]})}):d.jsx(d.Fragment,{})}exports.RichTextBubbleCallout=al;exports.RichTextBubbleCodeBlock=pd;exports.RichTextBubbleColumns=hl;exports.RichTextBubbleDrawer=_l;exports.RichTextBubbleExcalidraw=Al;exports.RichTextBubbleIframe=Il;exports.RichTextBubbleImage=Ll;exports.RichTextBubbleImageGif=Ul;exports.RichTextBubbleKatex=Ml;exports.RichTextBubbleLink=jl;exports.RichTextBubbleMenuDragHandle=dd;exports.RichTextBubbleMermaid=Hl;exports.RichTextBubbleTable=zl;exports.RichTextBubbleText=Wl;exports.RichTextBubbleTwitter=Gl;exports.RichTextBubbleVideo=Pl;