reactjs-tiptap-editor 1.0.17 → 1.0.18
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.
- package/lib/{ActionMenuButton-lsIBc9sU.js → ActionMenuButton-BOjCHFTA.js} +6 -6
- package/lib/ActionMenuButton-Df077oOH.cjs +1 -0
- package/lib/Attachment.cjs +2 -2
- package/lib/Attachment.js +40 -78
- package/lib/Blockquote.cjs +1 -1
- package/lib/Blockquote.js +2 -3
- package/lib/Bold.cjs +1 -1
- package/lib/Bold.js +2 -3
- package/lib/BulletList.cjs +1 -1
- package/lib/BulletList.js +2 -3
- package/lib/Callout.cjs +1 -1
- package/lib/Callout.js +105 -99
- package/lib/Clear.cjs +1 -1
- package/lib/Clear.js +2 -3
- package/lib/Code.cjs +1 -1
- package/lib/Code.js +2 -3
- package/lib/CodeBlock.cjs +38 -38
- package/lib/CodeBlock.js +1561 -1605
- package/lib/CodeView.cjs +1 -1
- package/lib/CodeView.js +2 -2
- package/lib/Color.cjs +1 -1
- package/lib/Color.js +46 -63
- package/lib/Column.cjs +1 -1
- package/lib/Column.js +24 -10
- package/lib/Drawer-DwrlY_lY.cjs +1 -0
- package/lib/Drawer-DxOoRiGQ.js +1099 -0
- package/lib/Drawer.cjs +1 -1
- package/lib/Drawer.js +6 -5
- package/lib/Emoji.cjs +1 -1
- package/lib/Emoji.js +69 -93
- package/lib/Excalidraw.cjs +1 -1
- package/lib/Excalidraw.js +99 -110
- package/lib/ExportPdf.cjs +4 -4
- package/lib/ExportPdf.js +4 -13
- package/lib/ExportWord.cjs +1 -1
- package/lib/ExportWord.js +9 -7
- package/lib/FontFamily.cjs +1 -1
- package/lib/FontFamily.js +12 -34
- package/lib/FontSize.cjs +1 -1
- package/lib/FontSize.js +12 -27
- package/lib/Heading.cjs +1 -1
- package/lib/Heading.js +34 -47
- package/lib/Highlight.cjs +1 -1
- package/lib/Highlight.js +39 -52
- package/lib/History.cjs +1 -1
- package/lib/History.js +318 -313
- package/lib/HorizontalRule.cjs +1 -1
- package/lib/HorizontalRule.js +2 -3
- package/lib/{Iframe-CTajPyzs.js → Iframe-AhNV5WH5.js} +25 -34
- package/lib/Iframe-C6pBw-AF.cjs +1 -0
- package/lib/Iframe.cjs +1 -1
- package/lib/Iframe.js +5 -4
- package/lib/Image.cjs +1 -1
- package/lib/Image.js +5 -4
- package/lib/ImageGif.cjs +1 -1
- package/lib/ImageGif.js +63 -91
- package/lib/ImportWord.cjs +1 -1
- package/lib/ImportWord.js +7 -11
- package/lib/{Indent-BGEHlRx_.js → Indent-DZ5PcJA4.js} +3 -7
- package/lib/Indent-Do-X0AsY.cjs +1 -0
- package/lib/Indent.cjs +1 -1
- package/lib/Indent.js +2 -2
- package/lib/Italic.cjs +1 -1
- package/lib/Italic.js +2 -3
- package/lib/Katex-CIC9ygbL.cjs +4 -0
- package/lib/{Katex-tMh4bfBb.js → Katex-bIgoenn_.js} +241 -255
- package/lib/Katex.cjs +1 -1
- package/lib/Katex.js +5 -4
- package/lib/LineHeight.cjs +1 -1
- package/lib/LineHeight.js +13 -21
- package/lib/Link.cjs +1 -1
- package/lib/Link.js +2 -2
- package/lib/LinkEditBlock-B0ZaACZO.cjs +5 -0
- package/lib/{LinkEditBlock-CA5NhP-m.js → LinkEditBlock-D_cF9fnc.js} +320 -370
- package/lib/MarkdownPaste.cjs +58 -0
- package/lib/MarkdownPaste.js +1656 -0
- package/lib/Mention.cjs +1 -1
- package/lib/Mention.js +22 -17
- package/lib/Mermaid.cjs +2 -2
- package/lib/Mermaid.js +118 -142
- package/lib/MoreMark.cjs +1 -1
- package/lib/MoreMark.js +10 -18
- package/lib/OrderedList.cjs +1 -1
- package/lib/OrderedList.js +2 -3
- package/lib/SearchAndReplace.cjs +1 -1
- package/lib/SearchAndReplace.js +68 -133
- package/lib/SlashCommand.cjs +1 -1
- package/lib/SlashCommand.js +15 -14
- package/lib/{SlashCommandNodeView-CZoM3ZlS.cjs → SlashCommandNodeView-Ba03hlVZ.cjs} +1 -1
- package/lib/{SlashCommandNodeView-DLuqbX2o.js → SlashCommandNodeView-cg0x3NRF.js} +15 -17
- package/lib/Strike.cjs +1 -1
- package/lib/Strike.js +2 -3
- package/lib/{Table-BC4Lbqzn.js → Table-KqLiT5wG.js} +95 -133
- package/lib/Table-ddU2LSc6.cjs +9 -0
- package/lib/Table.cjs +1 -1
- package/lib/Table.js +1 -1
- package/lib/TaskList.cjs +1 -1
- package/lib/TaskList.js +2 -3
- package/lib/TextAlign.cjs +1 -1
- package/lib/TextAlign.js +51 -60
- package/lib/TextDirection.cjs +1 -1
- package/lib/TextDirection.js +47 -69
- package/lib/TextUnderline.cjs +1 -1
- package/lib/TextUnderline.js +2 -3
- package/lib/Twitter-BIiR78Jh.cjs +1 -0
- package/lib/{Twitter-D8Cbgl7g.js → Twitter-C1Lzqc7u.js} +567 -593
- package/lib/Twitter.cjs +1 -1
- package/lib/Twitter.js +4 -3
- package/lib/Video.cjs +1 -1
- package/lib/Video.js +3 -3
- package/lib/bubble.cjs +6 -4
- package/lib/bubble.js +3712 -3023
- package/lib/clsx-BWE7vnna.cjs +33 -0
- package/lib/clsx-eGVyq7ot.js +1062 -0
- package/lib/components/ActionButton.d.ts +2 -2
- package/lib/components/ActionMenuButton.d.ts +1 -1
- package/lib/components/Bubble/formatBubble.d.ts +5 -5
- package/lib/components/ui/checkbox.d.ts +1 -1
- package/lib/components/ui/dialog.d.ts +1 -1
- package/lib/components/ui/dropdown-menu.d.ts +1 -1
- package/lib/components/ui/emoji-picker.d.ts +1 -1
- package/lib/components/ui/label.d.ts +1 -1
- package/lib/components/ui/popover.d.ts +1 -1
- package/lib/components/ui/select.d.ts +1 -1
- package/lib/components/ui/separator.d.ts +1 -1
- package/lib/components/ui/switch.d.ts +1 -1
- package/lib/components/ui/tabs.d.ts +1 -1
- package/lib/components/ui/toast.d.ts +1 -1
- package/lib/components/ui/toggle.d.ts +1 -1
- package/lib/components/ui/tooltip.d.ts +1 -1
- package/lib/{delete-node-IyVmiRbI.js → delete-node-eQHsyyhR.js} +3 -1
- package/lib/{dropdown-menu-q6RL_fkA.js → dropdown-menu-CexIkt_V.js} +8 -8
- package/lib/{dropdown-menu-C_F7LEy5.cjs → dropdown-menu-oSKIntXM.cjs} +1 -1
- package/lib/extensions/Blockquote/Blockquote.d.ts +1 -1
- package/lib/extensions/Bold/Bold.d.ts +1 -1
- package/lib/extensions/Code/Code.d.ts +1 -1
- package/lib/extensions/CodeView/CodeView.d.ts +2 -2
- package/lib/extensions/Heading/Heading.d.ts +1 -1
- package/lib/extensions/Highlight/Highlight.d.ts +1 -1
- package/lib/extensions/HorizontalRule/HorizontalRule.d.ts +1 -1
- package/lib/extensions/ImportWord/ImportWord.d.ts +2 -2
- package/lib/extensions/Italic/Italic.d.ts +1 -1
- package/lib/extensions/Link/Link.d.ts +1 -1
- package/lib/extensions/MarkdownPaste/MarkdownPaste.d.ts +5 -0
- package/lib/extensions/MarkdownPaste/index.d.ts +1 -0
- package/lib/extensions/Mermaid/Mermaid.d.ts +1 -1
- package/lib/extensions/MoreMark/MoreMark.d.ts +1 -1
- package/lib/extensions/Strike/Strike.d.ts +1 -1
- package/lib/extensions/Table/Table.d.ts +1 -1
- package/lib/extensions/TextAlign/TextAlign.d.ts +1 -1
- package/lib/extensions/TextUnderline/TextUnderline.d.ts +1 -1
- package/lib/index-BUTn2LY6.cjs +1 -0
- package/lib/{index-C07N8gA1.js → index-BlXGgvT-.js} +21 -18
- package/lib/{index-DqruLhsu.js → index-BnW6t8z6.js} +23 -23
- package/lib/{index-BsFvo9PG.cjs → index-BqL4vAWE.cjs} +1 -1
- package/lib/index-BtxvYLJ1.cjs +12 -0
- package/lib/{index-Do_dsOGB.js → index-C6xmkxrQ.js} +232 -217
- package/lib/index-CJ9pyCM4.cjs +1 -0
- package/lib/{index-neeeY2o7.cjs → index-D0lc95kr.cjs} +3 -3
- package/lib/{index-RcSPeQHn.js → index-DHUN85fV.js} +571 -657
- package/lib/index-DUpSE1Gb.cjs +1 -0
- package/lib/index-D_8P0LE5.js +1362 -0
- package/lib/{index-BDYJ8Ph2.js → index-RIXs7STX.js} +1 -1
- package/lib/index-mfGK4pFo.js +6469 -0
- package/lib/index-zig3Dj7A.cjs +22 -0
- package/lib/index.cjs +1 -1
- package/lib/index.js +26 -34
- package/lib/locale-bundle.cjs +1 -1
- package/lib/locale-bundle.js +1 -1
- package/lib/plugins/image-upload.d.ts +1 -1
- package/lib/popover-BYSZ3zBi.js +24 -0
- package/lib/popover-BcHDZqBt.cjs +1 -0
- package/lib/{renderNodeView-BEkECnnY.js → renderNodeView-BrM5kUj_.js} +2 -2
- package/lib/{renderNodeView-DfLmGrgA.cjs → renderNodeView-D1zydtli.cjs} +1 -1
- package/lib/{select-CmV5uTXr.js → select-C5SHDLFj.js} +8 -5
- package/lib/{select-CYyIeImH.cjs → select-DHjzKkcu.cjs} +1 -1
- package/lib/{separator-BLp6xpSY.cjs → separator-BmixLrnJ.cjs} +1 -1
- package/lib/separator-CFKVxAea.js +293 -0
- package/lib/store/editor.d.ts +1 -1
- package/lib/store/store.d.ts +1 -1
- package/lib/style.css +1 -1
- package/lib/{textarea-Cn75Cm2n.cjs → textarea-CasDcv3u.cjs} +1 -1
- package/lib/{textarea-CkVKMPqK.js → textarea-DNLrJoRl.js} +1 -1
- package/lib/theme.js +1 -1
- package/lib/types.d.ts +3 -3
- package/lib/updatePosition-CBRjbQMH.js +16 -0
- package/lib/updatePosition-CfmY5Trk.cjs +1 -0
- package/lib/utils/columns.d.ts +1 -1
- package/lib/utils/pdf.d.ts +1 -1
- package/lib/utils/utils.d.ts +1 -1
- package/package.json +262 -247
- package/lib/ActionMenuButton-B_E2mbAW.cjs +0 -1
- package/lib/Drawer-DQ4CxBwG.js +0 -1373
- package/lib/Drawer-FUeUKshi.cjs +0 -1
- package/lib/Iframe-EVWXCqe4.cjs +0 -1
- package/lib/Indent-q9cEWAa_.cjs +0 -1
- package/lib/Katex-ClqcEnN_.cjs +0 -4
- package/lib/LinkEditBlock-DZXk4ln_.cjs +0 -5
- package/lib/Table-BmDopO43.cjs +0 -9
- package/lib/Twitter-BbMD3Ybp.cjs +0 -1
- package/lib/clsx-CXbNJWDD.cjs +0 -54
- package/lib/clsx-DaPvp9ji.js +0 -7391
- package/lib/index-BCzvbrf5.cjs +0 -12
- package/lib/index-BnVcq33n.cjs +0 -1
- package/lib/index-CjhjjJsN.cjs +0 -1
- package/lib/index-Cs6cp0Y6.cjs +0 -1
- package/lib/index-Qcl3BG94.js +0 -1351
- package/lib/popover-CtinPbiy.js +0 -24
- package/lib/popover-DIMT3pae.cjs +0 -1
- package/lib/separator-C7luvaG8.js +0 -327
- package/lib/updatePosition-Cjuj2E26.cjs +0 -1
- package/lib/updatePosition-DRmKQBGm.js +0 -16
package/lib/bubble.cjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
"use strict";var co=Object.create;var hi=Object.defineProperty;var ao=Object.getOwnPropertyDescriptor;var ho=Object.getOwnPropertyNames;var uo=Object.getPrototypeOf,fo=Object.prototype.hasOwnProperty;var go=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ho(t))!fo.call(e,s)&&s!==n&&hi(e,s,{get:()=>t[s],enumerable:!(i=ao(t,s))||i.enumerable});return e};var po=(e,t,n)=>(n=e!=null?co(uo(e)):{},go(t||!e||!e.__esModule?hi(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-runtime"),w=require("react"),E=require("./clsx-CXbNJWDD.cjs"),F=require("./index-Cs6cp0Y6.cjs"),Y=require("@tiptap/pm/state"),Ki=require("./Table-BmDopO43.cjs"),Wi=require("react-dom"),p=require("./index-BnVcq33n.cjs"),te=require("./select-CYyIeImH.cjs"),Ce=require("./Callout.cjs"),ot=require("./Katex-ClqcEnN_.cjs"),L=require("./index-BsFvo9PG.cjs"),Jt=require("./delete-node-CosiBes5.cjs"),di=require("./Column.cjs");require("./theme.cjs");const Ae=require("./Drawer-FUeUKshi.cjs"),ui=require("easydrawer"),Le=require("./shortId-Bfj8TyNr.cjs"),kt=require("./separator-BLp6xpSY.cjs"),Ft=require("./popover-DIMT3pae.cjs"),ee=require("./Excalidraw.cjs"),Vt=require("./Iframe-EVWXCqe4.cjs"),mo=require("katex"),Ue=require("lucide-react"),Cn=require("./textarea-Cn75Cm2n.cjs"),De=require("./LinkEditBlock-DZXk4ln_.cjs"),xo=require("./ImageGif.cjs"),kn=require("./Mermaid.cjs"),wo=require("./Bold.cjs"),bo=require("./Code.cjs");require("./index-CjhjjJsN.cjs");const yo=require("./Color.cjs"),So=require("./Highlight.cjs"),Co=require("./Italic.cjs"),ko=require("./SlashCommandNodeView-CZoM3ZlS.cjs"),vo=require("./Strike.cjs"),Yi=require("./TextAlign.cjs"),_o=require("./TextUnderline.cjs"),an=require("./Twitter-BbMD3Ybp.cjs"),hn=require("@tiptap/pm/view"),Eo=require("@tiptap/pm/model"),Io=require("./Clear.cjs"),ne=require("./Indent-q9cEWAa_.cjs"),U=require("./dropdown-menu-C_F7LEy5.cjs");function To(e,t){const n=Math.min(e.top,t.top),i=Math.max(e.bottom,t.bottom),s=Math.min(e.left,t.left),r=Math.max(e.right,t.right)-s,l=i-n,c=s,a=n;return new DOMRect(c,a,r,l)}var Ao=class{constructor({editor:e,element:t,view:n,updateDelay:i=250,resizeDelay:s=60,shouldShow:o,appendTo:r,getReferencedVirtualElement:l,options:c}){this.preventHide=!1,this.isVisible=!1,this.scrollTarget=window,this.floatingUIOptions={strategy:"absolute",placement:"top",offset:8,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1,onShow:void 0,onHide:void 0,onUpdate:void 0,onDestroy:void 0},this.shouldShow=({view:h,state:d,from:f,to:g})=>{const{doc:m,selection:x}=d,{empty:b}=x,y=!m.textBetween(f,g).length&&E.isTextSelection(d.selection),I=this.element.contains(document.activeElement);return!(!(h.hasFocus()||I)||b||y||!this.editor.isEditable)},this.mousedownHandler=()=>{this.preventHide=!0},this.dragstartHandler=()=>{this.hide()},this.resizeHandler=()=>{this.resizeDebounceTimer&&clearTimeout(this.resizeDebounceTimer),this.resizeDebounceTimer=window.setTimeout(()=>{this.updatePosition()},this.resizeDelay)},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:h})=>{var d;if(this.editor.isDestroyed){this.destroy();return}if(this.preventHide){this.preventHide=!1;return}h!=null&&h.relatedTarget&&((d=this.element.parentNode)!=null&&d.contains(h.relatedTarget))||(h==null?void 0:h.relatedTarget)!==this.editor.view.dom&&this.hide()},this.handleDebouncedUpdate=(h,d)=>{const f=!(d!=null&&d.selection.eq(h.state.selection)),g=!(d!=null&&d.doc.eq(h.state.doc));!f&&!g||(this.updateDebounceTimer&&clearTimeout(this.updateDebounceTimer),this.updateDebounceTimer=window.setTimeout(()=>{this.updateHandler(h,f,g,d)},this.updateDelay))},this.updateHandler=(h,d,f,g)=>{const{composing:m}=h;if(m||!d&&!f)return;if(!this.getShouldShow(g)){this.hide();return}this.updatePosition(),this.show()},this.transactionHandler=({transaction:h})=>{h.getMeta("bubbleMenu")==="updatePosition"&&this.updatePosition()};var a;this.editor=e,this.element=t,this.view=n,this.updateDelay=i,this.resizeDelay=s,this.appendTo=r,this.scrollTarget=(a=c==null?void 0:c.scrollTarget)!=null?a:window,this.getReferencedVirtualElement=l,this.floatingUIOptions={...this.floatingUIOptions,...c},this.element.tabIndex=0,o&&(this.shouldShow=o),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.view.dom.addEventListener("dragstart",this.dragstartHandler),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.editor.on("transaction",this.transactionHandler),window.addEventListener("resize",this.resizeHandler),this.scrollTarget.addEventListener("scroll",this.resizeHandler),this.update(n,n.state),this.getShouldShow()&&(this.show(),this.updatePosition())}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(F.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(F.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(F.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(F.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(F.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(F.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(F.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(F.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}get virtualElement(){var e;const{selection:t}=this.editor.state,n=(e=this.getReferencedVirtualElement)==null?void 0:e.call(this);if(n)return n;const i=E.posToDOMRect(this.view,t.from,t.to);let s={getBoundingClientRect:()=>i,getClientRects:()=>[i]};if(t instanceof Y.NodeSelection){let o=this.view.nodeDOM(t.from);const r=o.dataset.nodeViewWrapper?o:o.querySelector("[data-node-view-wrapper]");r&&(o=r),o&&(s={getBoundingClientRect:()=>o.getBoundingClientRect(),getClientRects:()=>[o.getBoundingClientRect()]})}if(t instanceof Ki.CellSelection){const{$anchorCell:o,$headCell:r}=t,l=o?o.pos:r.pos,c=r?r.pos:o.pos,a=this.view.nodeDOM(l),h=this.view.nodeDOM(c);if(!a||!h)return;const d=a===h?a.getBoundingClientRect():To(a.getBoundingClientRect(),h.getBoundingClientRect());s={getBoundingClientRect:()=>d,getClientRects:()=>[d]}}return s}updatePosition(){const e=this.virtualElement;e&&F.computePosition(e,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:t,y:n,strategy:i})=>{this.element.style.width="max-content",this.element.style.position=i,this.element.style.left=`${t}px`,this.element.style.top=`${n}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()})}update(e,t){const{state:n}=e,i=n.selection.from!==n.selection.to;if(this.updateDelay>0&&i){this.handleDebouncedUpdate(e,t);return}const s=!(t!=null&&t.selection.eq(e.state.selection)),o=!(t!=null&&t.doc.eq(e.state.doc));this.updateHandler(e,s,o,t)}getShouldShow(e){var t;const{state:n}=this.view,{selection:i}=n,{ranges:s}=i,o=Math.min(...s.map(c=>c.$from.pos)),r=Math.max(...s.map(c=>c.$to.pos));return((t=this.shouldShow)==null?void 0:t.call(this,{editor:this.editor,element:this.element,view:this.view,state:n,oldState:e,from:o,to:r}))||!1}show(){var e;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const t=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(e=t??this.view.dom.parentElement)==null||e.appendChild(this.element),this.floatingUIOptions.onShow&&this.floatingUIOptions.onShow(),this.isVisible=!0}hide(){this.isVisible&&(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.remove(),this.floatingUIOptions.onHide&&this.floatingUIOptions.onHide(),this.isVisible=!1)}destroy(){this.hide(),this.element.removeEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.view.dom.removeEventListener("dragstart",this.dragstartHandler),window.removeEventListener("resize",this.resizeHandler),this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.editor.off("transaction",this.transactionHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},Gi=e=>new Y.Plugin({key:typeof e.pluginKey=="string"?new Y.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Ao({view:t,...e})});E.Extension.create({name:"bubbleMenu",addOptions(){return{element:null,pluginKey:"bubbleMenu",updateDelay:void 0,appendTo:void 0,shouldShow:null}},addProseMirrorPlugins(){return this.options.element?[Gi({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 Do=class{constructor({editor:e,element:t,view:n,options:i,appendTo:s,shouldShow:o}){this.preventHide=!1,this.isVisible=!1,this.shouldShow=({view:r,state:l})=>{const{selection:c}=l,{$anchor:a,empty:h}=c,d=a.depth===1,f=a.parent.isTextblock&&!a.parent.type.spec.code&&!a.parent.textContent&&a.parent.childCount===0&&!this.getTextContent(a.parent);return!(!r.hasFocus()||!h||!d||!f||!this.editor.isEditable)},this.floatingUIOptions={strategy:"absolute",placement:"right",offset:8,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1},this.updateHandler=(r,l,c,a)=>{const{composing:h}=r;if(h||!l&&!c)return;if(!this.getShouldShow(a)){this.hide();return}this.updatePosition(),this.show()},this.mousedownHandler=()=>{this.preventHide=!0},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:r})=>{var l;if(this.preventHide){this.preventHide=!1;return}r!=null&&r.relatedTarget&&((l=this.element.parentNode)!=null&&l.contains(r.relatedTarget))||(r==null?void 0:r.relatedTarget)!==this.editor.view.dom&&this.hide()},this.editor=e,this.element=t,this.view=n,this.appendTo=s,this.floatingUIOptions={...this.floatingUIOptions,...i},this.element.tabIndex=0,o&&(this.shouldShow=o),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.update(n,n.state),this.getShouldShow()&&(this.show(),this.updatePosition())}getTextContent(e){return E.getText(e,{textSerializers:E.getTextSerializersFromSchema(this.editor.schema)})}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(F.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(F.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(F.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(F.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(F.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(F.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(F.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(F.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}getShouldShow(e){var t;const{state:n}=this.view,{selection:i}=n,{ranges:s}=i,o=Math.min(...s.map(c=>c.$from.pos)),r=Math.max(...s.map(c=>c.$to.pos));return(t=this.shouldShow)==null?void 0:t.call(this,{editor:this.editor,view:this.view,state:n,oldState:e,from:o,to:r})}updatePosition(){const{selection:e}=this.editor.state,t=E.posToDOMRect(this.view,e.from,e.to),n={getBoundingClientRect:()=>t,getClientRects:()=>[t]};F.computePosition(n,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:i,y:s,strategy:o})=>{this.element.style.width="max-content",this.element.style.position=o,this.element.style.left=`${i}px`,this.element.style.top=`${s}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()})}update(e,t){const n=!(t!=null&&t.selection.eq(e.state.selection)),i=!(t!=null&&t.doc.eq(e.state.doc));this.updateHandler(e,n,i,t)}show(){var e;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const t=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(e=t??this.view.dom.parentElement)==null||e.appendChild(this.element),this.floatingUIOptions.onShow&&this.floatingUIOptions.onShow(),this.isVisible=!0}hide(){this.isVisible&&(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.remove(),this.floatingUIOptions.onHide&&this.floatingUIOptions.onHide(),this.isVisible=!1)}destroy(){this.hide(),this.element.removeEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},Ji=e=>new Y.Plugin({key:typeof e.pluginKey=="string"?new Y.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Do({view:t,...e})});E.Extension.create({name:"floatingMenu",addOptions(){return{element:null,options:{},pluginKey:"floatingMenu",appendTo:void 0,shouldShow:null}},addProseMirrorPlugins(){return this.options.element?[Ji({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,options:this.options.options,appendTo:this.options.appendTo,shouldShow:this.options.shouldShow})]:[]}});var Z=w.forwardRef(({pluginKey:e="bubbleMenu",editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:o=null,getReferencedVirtualElement:r,options:l,children:c,...a},h)=>{const d=w.useRef(document.createElement("div"));typeof h=="function"?h(d.current):h&&(h.current=d.current);const{editor:f}=E.useCurrentEditor(),g=t||f,m={updateDelay:n,resizeDelay:i,appendTo:s,pluginKey:e,shouldShow:o,getReferencedVirtualElement:r,options:l},x=w.useRef(m);return x.current=m,w.useEffect(()=>{if(g!=null&&g.isDestroyed)return;if(!g){console.warn("BubbleMenu component is not rendered inside of an editor component or does not have editor prop.");return}const b=d.current;b.style.visibility="hidden",b.style.position="absolute";const y=Gi({...x.current,editor:g,element:b});g.registerPlugin(y);const I=x.current.pluginKey;return()=>{g.unregisterPlugin(I),window.requestAnimationFrame(()=>{b.parentNode&&b.parentNode.removeChild(b)})}},[g]),Wi.createPortal(u.jsx("div",{...a,children:c}),d.current)});w.forwardRef(({pluginKey:e="floatingMenu",editor:t,appendTo:n,shouldShow:i=null,options:s,children:o,...r},l)=>{const c=w.useRef(document.createElement("div"));typeof l=="function"?l(c.current):l&&(l.current=c.current);const{editor:a}=E.useCurrentEditor();return w.useEffect(()=>{const h=c.current;if(h.style.visibility="hidden",h.style.position="absolute",t!=null&&t.isDestroyed||a!=null&&a.isDestroyed)return;const d=t||a;if(!d){console.warn("FloatingMenu component is not rendered inside of an editor component or does not have editor prop.");return}const f=Ji({editor:d,element:h,pluginKey:e,appendTo:n,shouldShow:i,options:s});return d.registerPlugin(f),()=>{d.unregisterPlugin(e),window.requestAnimationFrame(()=>{h.parentNode&&h.parentNode.removeChild(h)})}},[t,a,n,e,i,s]),Wi.createPortal(u.jsx("div",{...r,children:o}),c.current)});const Mo=[{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 jo(){const e=p.useEditableEditor(),t=p.useEditorInstance(),{t:n}=L.useLocale(),{type:i,title:s,body:o}=ot.useAttributes(t,Ce.Callout.name,{type:"note",title:"",body:""}),[r,l]=w.useState(!1),[c,a]=w.useState("note"),[h,d]=w.useState(""),[f,g]=w.useState("");w.useEffect(()=>{r&&(a(i||"note"),d(s||""),g(o||""))},[r,i,s,o]);const m=w.useCallback(()=>{t&&(t.chain().updateAttributes(Ce.Callout.name,{type:c,title:h,body:f}).focus().run(),l(!1))},[t,c,h,f]),x=w.useCallback(()=>{l(!1)},[]),b=w.useCallback(()=>{Jt.deleteNode(Ce.Callout.name,t)},[t]),y=w.useCallback(()=>t.isActive(Ce.Callout.name),[t]);return e?u.jsx(Z,{editor:t,options:{placement:"top",offset:8,flip:!0},pluginKey:"RichTextBubbleCallout",shouldShow:y,children:u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[u.jsxs(p.Dialog,{onOpenChange:l,open:r,children:[u.jsx(p.DialogTrigger,{asChild:!0,children:u.jsx(p.ActionButton,{icon:"Pencil",tooltip:n("editor.callout.edit.title")})}),u.jsxs(p.DialogContent,{children:[u.jsx(p.DialogTitle,{children:n("editor.callout.edit.title")}),u.jsxs("div",{className:"richtext-space-y-4 richtext-py-4",children:[u.jsxs("div",{className:"richtext-space-y-2",children:[u.jsx(p.Label,{children:n("editor.callout.dialog.type")}),u.jsxs(te.Select,{onValueChange:a,value:c,children:[u.jsx(te.SelectTrigger,{children:u.jsx(te.SelectValue,{className:"richtext-text-accent",placeholder:n("editor.callout.dialog.type.placeholder")})}),u.jsx(te.SelectContent,{children:Mo.map(I=>u.jsx(te.SelectItem,{value:I.value,children:n(`editor.callout.type.${I.value}`)},I.value))})]})]}),u.jsxs("div",{className:"richtext-space-y-2",children:[u.jsx(p.Label,{children:n("editor.callout.dialog.title.label")}),u.jsx(p.Input,{onChange:I=>d(I.target.value),placeholder:n("editor.callout.dialog.title.placeholder"),type:"text",value:h})]}),u.jsxs("div",{className:"richtext-space-y-2",children:[u.jsx(p.Label,{children:n("editor.callout.dialog.body.label")}),u.jsx(p.Input,{onChange:I=>g(I.target.value),placeholder:n("editor.callout.dialog.body.placeholder"),type:"text",value:f})]})]}),u.jsxs(p.DialogFooter,{children:[u.jsx(p.Button,{onClick:x,variant:"outline",children:n("editor.callout.dialog.button.cancel")}),u.jsx(p.Button,{onClick:m,children:n("editor.callout.dialog.button.apply")})]})]})]}),u.jsx(p.ActionButton,{action:b,icon:"Trash2",tooltip:n("editor.delete")})]})}):u.jsx(u.Fragment,{})}function Oo(){const e=p.useEditableEditor(),t=p.useEditorInstance(),{t:n}=L.useLocale(),i=w.useCallback(()=>t.isActive(di.MultipleColumnNode.name),[t]),s=w.useCallback(()=>Jt.deleteNode(di.MultipleColumnNode.name,t),[t]),o=w.useCallback(()=>t.chain().focus().addColBefore().run(),[t]),r=w.useCallback(()=>t.chain().focus().addColAfter().run(),[t]),l=w.useCallback(()=>t.chain().focus().deleteCol().run(),[t]);return e?u.jsx(Z,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleColumns",shouldShow:i,children:u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[u.jsx(p.ActionButton,{action:o,icon:"ColumnAddLeft",tooltip:n("editor.table.menu.insertColumnBefore")}),u.jsx(p.ActionButton,{action:r,icon:"ColumnAddRight",tooltip:n("editor.table.menu.insertColumnAfter")}),u.jsx(p.ActionButton,{action:l,icon:"DeleteColumn",tooltip:n("editor.table.menu.deleteColumn")}),u.jsx(p.ActionButton,{action:s,icon:"Trash2",tooltip:n("editor.table.menu.delete_column")})]})}):u.jsx(u.Fragment,{})}function Ro(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,o)=>({type:`image-${s}`,component:p.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[o],action:()=>e.commands.updateImage({width:L.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:L.IMAGE_SIZE[s]})}}))}function No(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,o)=>({type:`image-${s}`,component:p.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[o],action:()=>e.commands.updateImageGif({width:L.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:L.IMAGE_SIZE[s]})}}))}function Bo(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:p.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImage)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function Lo(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:p.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImageGif)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function Uo(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:p.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImageMermaid)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function Po(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:p.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImageDrawer)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function Vo(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:p.ActionButton,componentProps:{tooltip:n.tooltip,icon:n.icon,action:()=>e.commands.updateVideo({align:n.type}),isActive:()=>e.getAttributes("video").align===n.type}}))}function Fo(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,o)=>({type:`video-${s}`,component:p.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[o],action:()=>e.commands.updateVideo({width:L.VIDEO_SIZE[s]}),isActive:()=>e.isActive("video",{width:L.VIDEO_SIZE[s]})}}))}function Ho(e,t){return[{type:"flipX",component:p.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:p.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()}}},...Ro(e,t),...Bo(e,t),{type:"remove",component:p.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}function $o(e,t){return[...No(e,t),...Lo(e,t),{type:"remove",component:p.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}function zo(e,t){return[...Uo(e,t),{type:"edit",component:p.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:p.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}function qo(e,t){return[...Po(e,t),{type:"edit",component:p.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:p.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}function Ko(e,t){return[...Fo(e,t),...Vo(e),{type:"remove",component:p.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}let ie=!1;function Wo({editor:e,attrs:t,extension:n}){const[i,s]=w.useState(!1),o=w.useRef(null),r=w.useRef(null),{alt:l,align:c}=t,a=n==null?void 0:n.options.upload,h=()=>{(async()=>{const S=document.querySelector("#easydrawer");S&&(o.current=new ui.Editor(S,{wheelEventsEnabled:!1,disableZoom:!0}),r.current=ui.makeDropdownToolbar(o.current),r.current.addDefaultToolWidgets(),o.current.loadFromSVG(decodeURIComponent(l)))})()};w.useEffect(()=>{i&&setTimeout(()=>{h()},200)},[i]);const d=async()=>{if(o.current){const T=o.current.toSVG(),S=T.outerHTML,C=`drawer-${Le.shortId()}.svg`;let R=Le.i(T.outerHTML);if(a){const H=p.dataURLtoFile(R,C);R=await a(H)}e==null||e.chain().focus().setDrawer({type:"drawer",src:R,alt:encodeURIComponent(S),width:426,height:212},!!S).run(),e==null||e.commands.setAlignImageDrawer(c)}s(!1)},f=T=>{const S=o.current.toolController.getPrimaryTools()[2],C=r.current.getWidgetById("pen-1");S&&C&&(S.setColor(T),C.serializeState())},g=T=>{const S=o.current.toolController.getPrimaryTools()[2],C=r.current.getWidgetById("pen-1");S&&C&&(S.setThickness(T),C.serializeState())},m=T=>{const S=o.current.toolController.getPrimaryTools()[3],C=r.current.getWidgetById("pen-2");S&&C&&(S.setColor(T),C.serializeState())},x=T=>{const S=r.current.getWidgetById("shape");S&&S.setShapeType(T)},b=T=>{const S=o.current.toolController.getPrimaryTools()[5],C=r.current.getWidgetById("shape");S&&C&&(S.setColor(T),C.serializeState())},y=T=>{const S=o.current.toolController.getPrimaryTools()[5],C=r.current.getWidgetById("shape");S&&C&&(S.setThickness(T),C.serializeState())},I=T=>{const S=o.current.toolController.getPrimaryTools()[5],C=r.current.getWidgetById("shape");S&&C&&(S.setBorderColor(T),C.serializeState())},M=()=>{if(ie){for(;o.current.history.redoStackSize>0;)o.current.history.redo();ie=!1;return}o.current.history.undo()},k=()=>{ie||o.current.history.redo()},B=()=>{if(!ie){for(;o.current.history.undoStackSize>0;)M();ie=!0}};return u.jsxs(p.Dialog,{onOpenChange:s,open:i,children:[u.jsx(p.DialogTrigger,{asChild:!0,children:u.jsx(p.ActionButton,{action:()=>s(!0),icon:"Pencil",tooltip:"Edit Drawer"})}),u.jsxs(p.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[u.jsx(p.DialogTitle,{children:"Edit Drawer"}),u.jsxs("div",{style:{height:"100%",borderWidth:1,background:"white",position:"relative"},children:[u.jsx("div",{className:"richtext-size-full",id:"easydrawer"}),u.jsx(Ae.ControlDrawer,{changeBorderColorShape:I,changeColorShape:b,changeShape:x,onClear:B,onRedo:k,onThicknessChange:y,onUndo:M,refEditor:o,setColorHighlight:m,setColorPen:f,setThicknessPen:g})]}),u.jsx(p.DialogFooter,{children:u.jsx(p.Button,{onClick:d,type:"button",children:"Save changes"})})]})]})}function Yo({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?u.jsx(w.Fragment,{children:e.type==="divider"?u.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):u.jsx(i,{...e.componentProps,disabled:t||((s=e==null?void 0:e.componentProps)==null?void 0:s.disabled),editor:n})}):u.jsx(u.Fragment,{})}function Go(){const{lang:e,t}=L.useLocale(),n=p.useEditableEditor(),i=p.useEditorInstance(),s=ot.useAttributes(i,Ae.Drawer.name),o=p.useExtension(Ae.Drawer.name),r=({editor:c})=>{const{selection:a}=c.view.state,{$from:h,to:d}=a;let f=!1;return c.view.state.doc.nodesBetween(h.pos,d,g=>{if(g.type.name===Ae.Drawer.name)return f=!0,!1}),f},l=w.useMemo(()=>qo(i,t),[i,e,t]);return n?u.jsx(Z,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleDrawer",shouldShow:r,children:l!=null&&l.length?u.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:l==null?void 0:l.map((c,a)=>c.type==="edit"&&(s!=null&&s.src)?u.jsx(Wo,{attrs:s,editor:i,extension:o},`bubbleMenu-drawer-${a}`):u.jsx(Yo,{editor:i,item:c},`bubbleMenu-drawer-${a}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}const Xi=({width:e,maxWidth:t,height:n,onOk:i,children:s})=>{const{t:o}=L.useLocale(),[r,l]=w.useState({width:"",height:"",maxWidth:""});w.useEffect(()=>{l({width:e,height:n,maxWidth:t})},[n,t,e]);function c(a){a.preventDefault(),a.stopPropagation(),i(r)}return u.jsxs(Ft.Popover,{modal:!0,children:[u.jsx(Ft.PopoverTrigger,{asChild:!0,children:s}),u.jsx(Ft.PopoverContent,{children:u.jsxs("form",{className:"richtext-flex richtext-flex-col richtext-gap-2",onSubmit:c,children:[u.jsx(p.Label,{className:"mb-[6px]",children:"Width"}),u.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:u.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:u.jsx(p.Input,{onChange:a=>l({...r,width:a.target.value}),required:!0,type:"number",value:r.width})})}),u.jsx(p.Label,{className:"mb-[6px]",children:"Max Width"}),u.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:u.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:u.jsx(p.Input,{onChange:a=>l({...r,maxWidth:a.target.value}),required:!0,type:"number",value:r.maxWidth})})}),u.jsx(p.Label,{className:"mb-[6px]",children:"Height"}),u.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:u.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:u.jsx(p.Input,{onChange:a=>l({...r,height:a.target.value}),required:!0,type:"number",value:r.height})})}),u.jsx(p.Button,{className:"richtext-mt-2 richtext-self-end",type:"submit",children:o("editor.link.dialog.button.apply")})]})})]})},Dt=new Map;function Jo(e){const t=e.options.element;Dt.has("width")||Dt.set("width",t.clientWidth),Dt.has("width")&&Dt.get("width")<=0&&Dt.set("width",t.clientWidth);const n={attributes:!0,childList:!0,subtree:!0},i=function(){Dt.set("width",t.clientWidth)},s=new MutationObserver(i);return s.observe(t,n),e.on("destroy",()=>{s.disconnect()}),{width:Dt.get("width")}}function Xo(){const e=p.useEditableEditor(),t=p.useEditorInstance(),{t:n}=L.useLocale(),{width:i}=Jo(t),s=ot.useAttributes(t,ee.Excalidraw.name,{defaultShowPicker:!1,createUser:"",width:0,height:0}),{defaultShowPicker:o,createUser:r,width:l,height:c}=s,a=w.useCallback(g=>{t.chain().updateAttributes(ee.Excalidraw.name,g).setNodeSelection(t.state.selection.from).focus().run()},[t]),h=w.useCallback(()=>{const g=p.EVENTS.EXCALIDRAW(t.id);p.emit(g,s)},[t,s]),d=w.useCallback(()=>t.isActive(ee.Excalidraw.name),[t]),f=w.useCallback(()=>Jt.deleteNode(ee.Excalidraw.name,t),[t]);return w.useEffect(()=>{o&&(h(),t.chain().updateAttributes(ee.Excalidraw.name,{defaultShowPicker:!1}).focus().run())},[r,o,t,h]),e?u.jsx(Z,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleExcalidraw",shouldShow:d,children:u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[u.jsx(p.ActionButton,{action:h,icon:"Pencil",tooltip:n("editor.edit")}),u.jsx(Xi,{height:c,maxWidth:i,onOk:a,width:l,children:u.jsx(p.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),u.jsx(p.ActionButton,{action:f,icon:"Trash2",tooltip:n("editor.delete")})]})}):u.jsx(u.Fragment,{})}function Zo(){const e=p.useEditableEditor(),t=p.useEditorInstance(),{t:n}=L.useLocale(),{width:i,height:s,src:o}=ot.useAttributes(t,Vt.Iframe.name,{width:0,height:0,src:"",defaultShowPicker:!1}),[r,l]=w.useState(!1),[c,a]=w.useState(""),h=w.useCallback(b=>{var y;(y=b==null?void 0:b.preventDefault)==null||y.call(b),l(!1)},[l]);w.useEffect(()=>{r&&a(o)},[r,o]);const d=w.useCallback(b=>{var I;(I=b==null?void 0:b.preventDefault)==null||I.call(b);const y=Vt.getServiceSrc(c);t.chain().updateAttributes(Vt.Iframe.name,{src:(y==null?void 0:y.src)||c}).setNodeSelection(t.state.selection.from).focus().run(),l(!1)},[t,c,l]),f=w.useCallback(()=>{window.open(o,"_blank")},[o]),g=w.useCallback(b=>{t.chain().updateAttributes(Vt.Iframe.name,b).setNodeSelection(t.state.selection.from).focus().run()},[t]),m=w.useCallback(()=>t.isActive(Vt.Iframe.name)&&!o,[t,o]),x=w.useCallback(()=>Jt.deleteNode(Vt.Iframe.name,t),[t]);return e?u.jsx(u.Fragment,{children:u.jsx(Z,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleIframe",shouldShow:m,children:u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[u.jsx(p.ActionButton,{action:f,icon:"Eye",tooltip:"Visit Link"}),u.jsxs(p.Dialog,{onOpenChange:l,open:r,children:[u.jsx(p.DialogTrigger,{asChild:!0,children:u.jsx(p.ActionButton,{icon:"Pencil",tooltip:"Open Edit Link"})}),u.jsxs(p.DialogContent,{children:[u.jsx(p.DialogHeader,{children:u.jsx(p.DialogTitle,{children:"Edit Link Iframe"})}),u.jsx(p.Input,{autoFocus:!0,onInput:b=>a(b.target.value),placeholder:"Enter link",type:"url",value:c}),u.jsxs(p.DialogFooter,{children:[u.jsx(p.Button,{onClick:h,type:"button",children:"Cancel"}),u.jsx(p.Button,{onClick:d,type:"button",children:"OK"})]})]})]}),u.jsx(Xi,{height:s,onOk:g,width:i,children:u.jsx(p.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),u.jsx(p.ActionButton,{action:x,icon:"Trash2",tooltip:n("editor.delete")})]})})}):u.jsx(u.Fragment,{})}function Qo({children:e,visible:t,toggleVisible:n}){const{t:i}=L.useLocale(),s=p.useEditorInstance(),o=ot.useAttributes(s,ot.Katex.name,{text:"",macros:""}),{text:r,macros:l}=o,[c,a]=w.useState(decodeURIComponent(r||"")),[h,d]=w.useState(decodeURIComponent(l||""));w.useEffect(()=>{t&&(a(decodeURIComponent(r||"")),d(decodeURIComponent(l||"")))},[t]);const f=w.useCallback(()=>{s.chain().focus().setKatex({text:encodeURIComponent(c),macros:encodeURIComponent(h)}).run(),a(""),d(""),n(!1)},[s,c,h,n]),g=w.useMemo(()=>{try{return mo.renderToString(c,{macros:ot.safeJSONParse(h||"")})}catch{return c}},[c,h]),m=w.useMemo(()=>`${c}`.trim()?g:null,[c,g]);return u.jsxs(p.Dialog,{onOpenChange:n,open:t,children:[u.jsx(p.DialogTrigger,{asChild:!0,children:e}),u.jsxs(p.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[u.jsx(p.DialogTitle,{children:i("editor.formula.dialog.text")}),u.jsx("div",{style:{height:"100%",border:"1px solid hsl(var(--border))"},children:u.jsxs("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[u.jsxs("div",{className:"richtext-flex-1",children:[u.jsx(p.Label,{className:"mb-[6px]",children:"Expression"}),u.jsx(Cn.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))"}}),u.jsx(p.Label,{className:"mb-[6px]",children:"Macros"}),u.jsx(Cn.Textarea,{onChange:x=>d(x.target.value),placeholder:"Macros",rows:10,value:h,style:{color:"hsl(var(--foreground))"}})]}),u.jsx("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:m||""},style:{height:"100%",borderWidth:1,minHeight:500,background:"#fff"}})]})}),u.jsx(p.DialogFooter,{children:u.jsx(p.Button,{onClick:f,type:"button",children:"Save changes"})})]})]})}function tr(){const e=p.useEditableEditor(),t=p.useEditorInstance(),[n,i]=w.useState(!1),s=w.useCallback(()=>t.isActive(ot.Katex.name),[t]),o=w.useCallback(()=>Jt.deleteNode(ot.Katex.name,t),[t]);return e?u.jsx(Z,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleKatex",shouldShow:s,children:u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[u.jsx(Qo,{toggleVisible:i,visible:n,children:u.jsx(p.ActionButton,{action:()=>i(!n),tooltip:"Edit",children:u.jsx(Ue.Pencil,{size:16})})}),u.jsx(p.ActionButton,{action:o,tooltip:"Delete",children:u.jsx(Ue.Trash2,{size:16})})]})}):u.jsx(u.Fragment,{})}function er(e){const{t}=L.useLocale();return u.jsxs("div",{className:"richtext-flex richtext-flex-nowrap",children:[u.jsx(p.ActionButton,{disabled:!(e!=null&&e.link),icon:"ExternalLink",tooltip:t("editor.link.open.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{window.open(e==null?void 0:e.link,"_blank")}}),u.jsx(p.ActionButton,{icon:"Pencil",tooltip:t("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onEdit()}}),u.jsx(p.ActionButton,{icon:"Unlink",tooltip:t("editor.link.unlink.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onClear()}})]})}function nr(){const e=p.useEditableEditor(),t=p.useEditorInstance(),[n,i]=w.useState(!1),s=ot.useAttributes(t,De.Link.name),o=s==null?void 0:s.href,r=w.useCallback(({editor:h})=>h.isActive(De.Link.name),[]),l=(h,d,f)=>{const g=t.state.selection,{from:m}=g,x=(d==null?void 0:d.length)??0,b=m+x;t.chain().extendMarkRange("link").insertContent({type:"text",text:d,marks:[{type:"link",attrs:{href:h,target:f?"_blank":""}}]}).setLink({href:h}).setTextSelection({from:m,to:b}).focus().run(),i(!1)},c=w.useCallback(()=>{t.chain().extendMarkRange("link").unsetLink().focus().run(),i(!1)},[t]),a=()=>{i(!1)};return e?u.jsx(Z,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleLink",shouldShow:r,children:u.jsx(u.Fragment,{children:n?u.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-4 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:u.jsx(De.LinkEditBlock,{editor:t,onClose:a,onSetLink:l})}):u.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:u.jsx(er,{editor:t,link:o,onClear:c,onEdit:()=>{i(!0)}})})})}):u.jsx(u.Fragment,{})}function Hn({item:e,disabled:t,editor:n}){const i=e.component;return i?u.jsx(w.Fragment,{children:e.type==="divider"?u.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):u.jsx(i,{...e.componentProps,disabled:t||(e==null?void 0:e.componentdisabled),editor:n})}):u.jsx(u.Fragment,{})}function ir(e){return e.type.name===p.Image.name}function sr(e){return e.type.name===xo.ImageGif.name}function or(e){return e.type.name===p.Video.name}function rr(){const{lang:e,t}=L.useLocale(),n=p.useEditableEditor(),i=p.useEditorInstance(),s=({editor:r})=>{const{selection:l}=r.view.state,{$from:c,to:a}=l;let h=!1;return r.view.state.doc.nodesBetween(c.pos,a,d=>{if(ir(d))return h=!0,!1}),h},o=w.useMemo(()=>Ho(i,t),[i,e,t]);return n?u.jsx(Z,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImage",shouldShow:s,children:o!=null&&o.length?u.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:o==null?void 0:o.map((r,l)=>u.jsx(Hn,{editor:i,item:r},`bubbleMenu-image-${l}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}function lr(){const{lang:e,t}=L.useLocale(),n=p.useEditableEditor(),i=p.useEditorInstance(),s=({editor:r})=>{const{selection:l}=r.view.state,{$from:c,to:a}=l;let h=!1;return r.view.state.doc.nodesBetween(c.pos,a,d=>{if(sr(d))return h=!0,!1}),h},o=w.useMemo(()=>$o(i,t),[i,t,e]);return n?u.jsx(Z,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImageGif",shouldShow:s,children:o!=null&&o.length?u.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:o==null?void 0:o.map((r,l)=>u.jsx(Hn,{editor:i,item:r},`bubbleMenu-image-gif-${l}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}function cr(){const{t:e}=L.useLocale(),t=p.useEditableEditor(),n=p.useEditorInstance(),i=({editor:o})=>{const{selection:r}=o.view.state,{$from:l,to:c}=r;let a=!1;return o.view.state.doc.nodesBetween(l.pos,c,h=>{if(or(h))return a=!0,!1}),a},s=w.useMemo(()=>Ko(n,e),[n,e]);return t?u.jsx(Z,{editor:n,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleVideo",shouldShow:i,children:s!=null&&s.length?u.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:s==null?void 0:s.map((o,r)=>u.jsx(Hn,{editor:n,item:o},`bubbleMenu-video-${r}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}const fi=`graph TB
|
|
2
|
-
a-->b`,ar=({editor:e,attrs:t,extension:n})=>{const{alt:i,align:s}=t,[o,r]=w.useState(decodeURIComponent(i??fi)),[l,c]=w.useState(""),[a,h]=w.useState(!1),d=w.useRef(null),[f,g]=w.useState(null),m=n==null?void 0:n.options.upload,x=w.useCallback(M=>{M&&import("mermaid").then(k=>{g(k.default)})},[]),b=async M=>{try{const{svg:k}=await f.render("mermaid-svg",M);c(k)}catch{c("")}},y=()=>{f.initialize({darkMode:!1,startOnLoad:!1,fontSize:12,theme:"base"}),b(o)};w.useEffect(()=>{f&&a&&y()},[f,a]),w.useEffect(()=>{f&&a&&b(o)},[f,o]);const I=async()=>{if(o!==""){if(o){const M=d.current.querySelector("svg"),{width:k,height:B}=M.getBoundingClientRect(),T=`mermaid-${Le.shortId()}.svg`;let S=Le.i(M.outerHTML);if(m){const C=p.dataURLtoFile(S,T);S=await m(C)}e==null||e.chain().focus().setMermaid({type:"mermaid",src:S,alt:encodeURIComponent(o),width:k,height:B},!!o).run(),e==null||e.commands.setAlignImageMermaid(s)}h(!1)}};return u.jsxs(p.Dialog,{onOpenChange:h,open:a,children:[u.jsx(p.DialogTrigger,{asChild:!0,children:u.jsx(p.ActionButton,{action:()=>h(!0),icon:"Pencil",tooltip:"Edit Mermaid"})}),u.jsxs(p.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[u.jsx(p.DialogTitle,{children:"Edit Mermaid"}),u.jsx("div",{ref:x,style:{height:"100%",border:"1px solid hsl(var(--border))"},children:u.jsxs("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[u.jsx(Cn.Textarea,{autoFocus:!0,className:"richtext-flex-1",defaultValue:fi,onChange:M=>r(M.target.value),placeholder:"Text",required:!0,rows:10,value:o,style:{color:"hsl(var(--foreground))"}}),u.jsx("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:l},ref:d,style:{height:"100%",border:"1px solid hsl(var(--border))",minHeight:500}})]})}),u.jsx(p.DialogFooter,{children:u.jsx(p.Button,{onClick:I,type:"button",children:"Save changes"})})]})]})};function hr({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?u.jsx(w.Fragment,{children:e.type==="divider"?u.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):u.jsx(i,{...e.componentProps,disabled:t||((s=e==null?void 0:e.componentProps)==null?void 0:s.disabled),editor:n})}):u.jsx(u.Fragment,{})}function dr(e){return e.type.name===kn.Mermaid.name}function ur(){const{lang:e,t}=L.useLocale(),n=p.useEditableEditor(),i=p.useEditorInstance(),s=ot.useAttributes(i,kn.Mermaid.name),o=p.useExtension(kn.Mermaid.name),r=({editor:c})=>{const{selection:a}=c.view.state,{$from:h,to:d}=a;let f=!1;return c.view.state.doc.nodesBetween(h.pos,d,g=>{if(dr(g))return f=!0,!1}),f},l=w.useMemo(()=>zo(i,t),[i,e,t]);return n?u.jsx(Z,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleMermaid",shouldShow:r,children:l!=null&&l.length?u.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:l==null?void 0:l.map((c,a)=>c.type==="edit"&&(s!=null&&s.src)?u.jsx(ar,{attrs:s,editor:i,extension:o},`bubbleMenu-mermaid-${a}`):u.jsx(hr,{editor:i,item:c},`bubbleMenu-mermaid-${a}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}function fr({hiddenActions:e=[]}){var x,b,y,I,M,k,B,T,S,C,R,H,tt,Tt,At,v,ft,Se;const{t}=L.useLocale(),n=p.useEditableEditor(),i=p.useEditorInstance(),s=({editor:Pt})=>E.isActive(Pt.view.state,Ki.Table.name),o=Pt=>e.includes(Pt);function r(){i.chain().focus().addColumnBefore().run()}function l(){i.chain().focus().addColumnAfter().run()}function c(){i.chain().focus().deleteColumn().run()}function a(){i.chain().focus().addRowBefore().run()}function h(){i.chain().focus().addRowAfter().run()}function d(){i.chain().focus().deleteRow().run()}function f(){i.chain().focus().mergeCells().run()}function g(){i==null||i.chain().focus().splitCell().run()}function m(){i.chain().focus().deleteTable().run()}return n?u.jsx(Z,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTable",shouldShow:s,children:u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[!o("addColumnBefore")&&u.jsx(p.ActionButton,{action:r,disabled:!((b=(x=i==null?void 0:i.can())==null?void 0:x.addColumnBefore)!=null&&b.call(x)),icon:"BetweenHorizonalEnd",tooltip:t("editor.table.menu.insertColumnBefore"),tooltipOptions:{sideOffset:15}}),!o("addColumnAfter")&&u.jsx(p.ActionButton,{action:l,disabled:!((I=(y=i==null?void 0:i.can())==null?void 0:y.addColumnAfter)!=null&&I.call(y)),icon:"BetweenHorizonalStart",tooltip:t("editor.table.menu.insertColumnAfter"),tooltipOptions:{sideOffset:15}}),!o("deleteColumn")&&u.jsx(p.ActionButton,{action:c,disabled:!((k=i==null?void 0:(M=i.can()).deleteColumn)!=null&&k.call(M)),icon:"DeleteColumn",tooltip:t("editor.table.menu.deleteColumn"),tooltipOptions:{sideOffset:15}}),u.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!o("addRowAbove")&&u.jsx(p.ActionButton,{action:a,disabled:!((T=i==null?void 0:(B=i.can()).addRowBefore)!=null&&T.call(B)),icon:"BetweenVerticalEnd",tooltip:t("editor.table.menu.insertRowAbove"),tooltipOptions:{sideOffset:15}}),!o("addRowBelow")&&u.jsx(p.ActionButton,{action:h,disabled:!((C=(S=i==null?void 0:i.can())==null?void 0:S.addRowAfter)!=null&&C.call(S)),icon:"BetweenVerticalStart",tooltip:t("editor.table.menu.insertRowBelow"),tooltipOptions:{sideOffset:15}}),!o("deleteRow")&&u.jsx(p.ActionButton,{action:d,disabled:!((H=(R=i==null?void 0:i.can())==null?void 0:R.deleteRow)!=null&&H.call(R)),icon:"DeleteRow",tooltip:t("editor.table.menu.deleteRow"),tooltipOptions:{sideOffset:15}}),u.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!o("mergeCells")&&u.jsx(p.ActionButton,{action:f,disabled:!((Tt=(tt=i==null?void 0:i.can())==null?void 0:tt.mergeCells)!=null&&Tt.call(tt)),icon:"TableCellsMerge",tooltip:t("editor.table.menu.mergeCells"),tooltipOptions:{sideOffset:15}}),!o("splitCells")&&u.jsx(p.ActionButton,{action:g,disabled:!((v=(At=i==null?void 0:i.can())==null?void 0:At.splitCell)!=null&&v.call(At)),icon:"TableCellsSplit",tooltip:t("editor.table.menu.splitCells"),tooltipOptions:{sideOffset:15}}),u.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!o("deleteTable")&&u.jsx(p.ActionButton,{action:m,disabled:!((Se=(ft=i==null?void 0:i.can())==null?void 0:ft.deleteTable)!=null&&Se.call(ft)),icon:"Trash2",tooltip:t("editor.table.menu.deleteTable"),tooltipOptions:{sideOffset:15}})]})}):u.jsx(u.Fragment,{})}function gr(){const{t:e}=L.useLocale(),[t,n]=w.useState(!1),i=p.useEditorInstance(),s=w.useMemo(()=>{var r,l;return(l=(r=ko.renderCommandListDefault({t:e}))==null?void 0:r[0])==null?void 0:l.commands},[e]),o=w.useMemo(()=>{var l;return(l=s==null?void 0:s.find(c=>{var a;return(a=c==null?void 0:c.isActive)==null?void 0:a.call(c,i)}))==null?void 0:l.label},[i.state.selection.ranges,t,i,s,e]);return u.jsxs(Ft.Popover,{modal:!0,onOpenChange:n,open:t,children:[u.jsx(Ft.PopoverTrigger,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:u.jsxs(p.ActionButton,{dataState:!!o,children:[o?u.jsx(u.Fragment,{children:o}):u.jsx(u.Fragment,{children:e("editor.paragraph.tooltip")}),u.jsx(p.IconComponent,{className:"richtext-ml-1 richtext-size-3 richtext-text-zinc-500",name:"MenuDown"})]})}),u.jsx(Ft.PopoverContent,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:s==null?void 0:s.map(r=>{var c;const l=(c=r==null?void 0:r.isActive)==null?void 0:c.call(r,i);return u.jsxs("div",{className:"richtext-flex richtext-w-full richtext-items-center richtext-gap-3 richtext-rounded-sm !richtext-border-none !richtext-bg-transparent richtext-px-2 richtext-py-1.5 richtext-text-left richtext-text-sm richtext-text-foreground !richtext-outline-none richtext-transition-colors hover:!richtext-bg-accent",onClick:a=>{a.preventDefault(),r.action({editor:i,range:i.state.selection.ranges}),n(!1)},children:[u.jsxs("div",{className:"!richtext-min-w-[20px]",children:[l&&u.jsx(Ue.Check,{size:16}),!o&&r.label===e("editor.paragraph.tooltip")&&!l&&u.jsx(Ue.Check,{size:16})]}),u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:[r.iconName&&u.jsx(p.IconComponent,{className:"!richtext-mr-1 !richtext-text-lg",name:r.iconName}),r.label]})]},r.name)})})]})}function pr(){return u.jsxs(u.Fragment,{children:[u.jsx(gr,{}),u.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),u.jsx(wo.RichTextBold,{}),u.jsx(Co.RichTextItalic,{}),u.jsx(_o.RichTextUnderline,{}),u.jsx(vo.RichTextStrike,{}),u.jsx(bo.RichTextCode,{}),u.jsx(De.RichTextLink,{}),u.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),u.jsx(yo.RichTextColor,{}),u.jsx(So.RichTextHighlight,{}),u.jsx(Yi.RichTextAlign,{})]})}function mr({buttonBubble:e}){const t=p.useEditorInstance(),n=p.useEditableEditor(),i=({editor:s})=>{const{selection:o}=s.view.state,{$from:r,to:l}=o;return r.pos===l?!1:o instanceof Y.TextSelection};return n?u.jsx(Z,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleText",shouldShow:i,children:e?u.jsx(u.Fragment,{children:e}):u.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:u.jsx(pr,{})})}):u.jsx(u.Fragment,{})}function xr(){const{t:e}=L.useLocale(),t=p.useEditableEditor(),n=p.useEditorInstance(),[i,s]=w.useState(!1),o=w.useCallback(({editor:c})=>c.isActive(an.Twitter.name),[]),r=c=>{n.commands.updateTweet({src:c}),s(!1)},l=w.useCallback(()=>Jt.deleteNode(an.Twitter.name,n),[n]);return t?u.jsx(Z,{editor:n,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTwitter",shouldShow:o,children:u.jsx(u.Fragment,{children:i?u.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-4 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:u.jsx(an.FormEditLinkTwitter,{editor:n,onSetLink:r})}):u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[u.jsx(p.ActionButton,{icon:"Pencil",tooltip:e("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{s(!0)}}),u.jsx(p.ActionButton,{action:l,icon:"Trash",tooltip:e("editor.delete"),tooltipOptions:{sideOffset:15}})]})})}):u.jsx(u.Fragment,{})}const rt=()=>new Map,vn=e=>{const t=rt();return e.forEach((n,i)=>{t.set(i,n)}),t},wt=(e,t,n)=>{let i=e.get(t);return i===void 0&&e.set(t,i=n()),i},wr=(e,t)=>{const n=[];for(const[i,s]of e)n.push(t(s,i));return n},br=(e,t)=>{for(const[n,i]of e)if(t(i,n))return!0;return!1},Ot=()=>new Set,dn=e=>e[e.length-1],yr=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},Rt=Array.from,Sr=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},_n=Array.isArray;class Zi{constructor(){this._observers=rt()}on(t,n){return wt(this._observers,t,Ot).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 Rt((this._observers.get(t)||rt()).values()).forEach(i=>i(...n))}destroy(){this._observers=rt()}}const xt=Math.floor,Me=Math.abs,Kt=(e,t)=>e<t?e:t,vt=(e,t)=>e>t?e:t,Qi=e=>e!==0?e<0:1/e<0,gi=1,pi=2,un=4,fn=8,le=32,pt=64,W=128,Cr=1<<29,Xe=31,En=63,jt=127,kr=2147483647,ts=Number.MAX_SAFE_INTEGER,vr=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&xt(e)===e),_r=String.fromCharCode,Er=e=>e.toLowerCase(),Ir=/^\s*/g,Tr=e=>e.replace(Ir,""),Ar=/([A-Z])/g,mi=(e,t)=>Tr(e.replace(Ar,n=>`${t}${Er(n)}`)),Dr=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},ce=typeof TextEncoder<"u"?new TextEncoder:null,Mr=e=>ce.encode(e),jr=ce?Mr:Dr;let oe=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});oe&&oe.decode(new Uint8Array).length===1&&(oe=null);class xe{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const we=()=>new xe,Or=e=>{const t=we();return e(t),st(t)},Rr=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},st=e=>{const t=new Uint8Array(Rr(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},Nr=(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(vt(n,t)*2),e.cpos=0)},$=(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},In=$,A=(e,t)=>{for(;t>jt;)$(e,W|jt&t),t=xt(t/128);$(e,jt&t)},$n=(e,t)=>{const n=Qi(t);for(n&&(t=-t),$(e,(t>En?W:0)|(n?pt:0)|En&t),t=xt(t/64);t>0;)$(e,(t>jt?W:0)|jt&t),t=xt(t/128)},Tn=new Uint8Array(3e4),Br=Tn.length/3,Lr=(e,t)=>{if(t.length<Br){const n=ce.encodeInto(t,Tn).written||0;A(e,n);for(let i=0;i<n;i++)$(e,Tn[i])}else Q(e,jr(t))},Ur=(e,t)=>{const n=unescape(encodeURIComponent(t)),i=n.length;A(e,i);for(let s=0;s<i;s++)$(e,n.codePointAt(s))},Ht=ce&&ce.encodeInto?Lr:Ur,Ze=(e,t)=>{const n=e.cbuf.length,i=e.cpos,s=Kt(n-i,t.length),o=t.length-s;e.cbuf.set(t.subarray(0,s),i),e.cpos+=s,o>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(vt(n*2,o)),e.cbuf.set(t.subarray(s)),e.cpos=o)},Q=(e,t)=>{A(e,t.byteLength),Ze(e,t)},zn=(e,t)=>{Nr(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Pr=(e,t)=>zn(e,4).setFloat32(0,t,!1),Vr=(e,t)=>zn(e,8).setFloat64(0,t,!1),Fr=(e,t)=>zn(e,8).setBigInt64(0,t,!1),xi=new DataView(new ArrayBuffer(4)),Hr=e=>(xi.setFloat32(0,e),xi.getFloat32(0)===e),Wt=(e,t)=>{switch(typeof t){case"string":$(e,119),Ht(e,t);break;case"number":vr(t)&&Me(t)<=kr?($(e,125),$n(e,t)):Hr(t)?($(e,124),Pr(e,t)):($(e,123),Vr(e,t));break;case"bigint":$(e,122),Fr(e,t);break;case"object":if(t===null)$(e,126);else if(_n(t)){$(e,117),A(e,t.length);for(let n=0;n<t.length;n++)Wt(e,t[n])}else if(t instanceof Uint8Array)$(e,116),Q(e,t);else{$(e,118);const n=Object.keys(t);A(e,n.length);for(let i=0;i<n.length;i++){const s=n[i];Ht(e,s),Wt(e,t[s])}}break;case"boolean":$(e,t?120:121);break;default:$(e,127)}};class wi extends xe{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&A(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const bi=e=>{e.count>0&&($n(e.encoder,e.count===1?e.s:-e.s),e.count>1&&A(e.encoder,e.count-2))};class je{constructor(){this.encoder=new xe,this.s=0,this.count=0}write(t){this.s===t?this.count++:(bi(this),this.count=1,this.s=t)}toUint8Array(){return bi(this),st(this.encoder)}}const yi=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);$n(e.encoder,t),e.count>1&&A(e.encoder,e.count-2)}};class gn{constructor(){this.encoder=new xe,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(yi(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return yi(this),st(this.encoder)}}class $r{constructor(){this.sarr=[],this.s="",this.lensE=new je}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new xe;return this.sarr.push(this.s),this.s="",Ht(t,this.sarr.join("")),Ze(t,this.lensE.toUint8Array()),st(t)}}const _t=e=>new Error(e),lt=()=>{throw _t("Method unimplemented")},X=()=>{throw _t("Unexpected case")},es=_t("Unexpected end of array"),ns=_t("Integer out of Range");class Qe{constructor(t){this.arr=t,this.pos=0}}const qn=e=>new Qe(e),zr=e=>e.pos!==e.arr.length,qr=(e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},et=e=>qr(e,O(e)),ae=e=>e.arr[e.pos++],O=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&jt)*n,n*=128,s<W)return t;if(t>ts)throw ns}throw es},Kn=e=>{let t=e.arr[e.pos++],n=t&En,i=64;const s=(t&pt)>0?-1:1;if((t&W)===0)return s*n;const o=e.arr.length;for(;e.pos<o;){if(t=e.arr[e.pos++],n=n+(t&jt)*i,i*=128,t<W)return s*n;if(n>ts)throw ns}throw es},Kr=e=>{let t=O(e);if(t===0)return"";{let n=String.fromCodePoint(ae(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(ae(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))}},Wr=e=>oe.decode(et(e)),An=oe?Wr:Kr,Wn=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},Yr=e=>Wn(e,4).getFloat32(0,!1),Gr=e=>Wn(e,8).getFloat64(0,!1),Jr=e=>Wn(e,8).getBigInt64(0,!1),Xr=[e=>{},e=>null,Kn,Yr,Gr,Jr,e=>!1,e=>!0,An,e=>{const t=O(e),n={};for(let i=0;i<t;i++){const s=An(e);n[s]=Pe(e)}return n},e=>{const t=O(e),n=[];for(let i=0;i<t;i++)n.push(Pe(e));return n},et],Pe=e=>Xr[127-ae(e)](e);class Si extends Qe{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),zr(this)?this.count=O(this)+1:this.count=-1),this.count--,this.s}}class Oe extends Qe{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Kn(this);const t=Qi(this.s);this.count=1,t&&(this.s=-this.s,this.count=O(this)+2)}return this.count--,this.s}}class pn extends Qe{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=Kn(this),n=t&1;this.diff=xt(t/2),this.count=1,n&&(this.count=O(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Zr{constructor(t){this.decoder=new Oe(t),this.str=An(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 Qr=crypto.getRandomValues.bind(crypto),tl=Math.random,is=()=>Qr(new Uint32Array(1))[0],el=e=>e[xt(tl()*e.length)],nl="10000000-1000-4000-8000"+-1e11,il=()=>nl.replace(/[018]/g,e=>(e^is()&15>>e/4).toString(16)),sl=Date.now,Ci=e=>new Promise(e);Promise.all.bind(Promise);const ki=e=>e===void 0?null:e;class ol{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}}let ss=new ol,rl=!0;try{typeof localStorage<"u"&&localStorage&&(ss=localStorage,rl=!1)}catch{}const ll=ss,cl=Object.assign,os=Object.keys,al=(e,t)=>{for(const n in e)t(e[n],n)},vi=e=>os(e).length,hl=e=>{for(const t in e)return!1;return!0},rs=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},dl=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),ul=(e,t)=>e===t||vi(e)===vi(t)&&rs(e,(n,i)=>(n!==void 0||dl(t,i))&&t[i]===n),fl=Object.freeze,ls=e=>{for(const t in e){const n=e[t];(typeof n=="object"||typeof n=="function")&&ls(e[t])}return fl(e)},Yn=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Yn(e,t,n+1)}},gl=(e,t)=>t.includes(e),Yt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",cs=typeof window<"u"&&typeof document<"u"&&!Yt;let dt;const pl=()=>{if(dt===void 0)if(Yt){dt=rt();const e=process.argv;let t=null;for(let n=0;n<e.length;n++){const i=e[n];i[0]==="-"?(t!==null&&dt.set(t,""),t=i):t!==null&&(dt.set(t,i),t=null)}t!==null&&dt.set(t,"")}else typeof location=="object"?(dt=rt(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){const[t,n]=e.split("=");dt.set(`--${mi(t,"-")}`,n),dt.set(`-${mi(t,"-")}`,n)}})):dt=rt();return dt},Dn=e=>pl().has(e),Ve=e=>ki(Yt?process.env[e.toUpperCase().replaceAll("-","_")]:ll.getItem(e)),as=e=>Dn("--"+e)||Ve(e)!==null;as("production");const ml=Yt&&gl(process.env.FORCE_COLOR,["true","1","2"]),xl=ml||!Dn("--no-colors")&&!as("no-color")&&(!Yt||process.stdout.isTTY)&&(!Yt||Dn("--color")||Ve("COLORTERM")!==null||(Ve("TERM")||"").includes("color")),wl=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=_r(e[n]);return btoa(t)},bl=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),yl=cs?wl:bl,Sl=e=>Or(t=>Wt(t,e));class Cl{constructor(t,n){this.left=t,this.right=n}}const gt=(e,t)=>new Cl(e,t),kl=typeof document<"u"?document:{};typeof DOMParser<"u"&&new DOMParser;const vl=e=>wr(e,(t,n)=>`${n}:${t};`).join(""),_l=e=>class{constructor(n){this._=n}destroy(){e(this._)}},El=_l(clearTimeout),hs=(e,t)=>new El(setTimeout(t,e)),bt=Symbol,ds=bt(),us=bt(),Il=bt(),Tl=bt(),Al=bt(),fs=bt(),Dl=bt(),Gn=bt(),Ml=bt(),jl=e=>{var s;e.length===1&&((s=e[0])==null?void 0:s.constructor)===Function&&(e=e[0]());const t=[],n=[];let i=0;for(;i<e.length;i++){const o=e[i];if(o===void 0)break;if(o.constructor===String||o.constructor===Number)t.push(o);else if(o.constructor===Object)break}for(i>0&&n.push(t.join(""));i<e.length;i++){const o=e[i];o instanceof Symbol||n.push(o)}return n},Ol={[ds]:gt("font-weight","bold"),[us]:gt("font-weight","normal"),[Il]:gt("color","blue"),[Al]:gt("color","green"),[Tl]:gt("color","grey"),[fs]:gt("color","red"),[Dl]:gt("color","purple"),[Gn]:gt("color","orange"),[Ml]:gt("color","black")},Rl=e=>{var r;e.length===1&&((r=e[0])==null?void 0:r.constructor)===Function&&(e=e[0]());const t=[],n=[],i=rt();let s=[],o=0;for(;o<e.length;o++){const l=e[o],c=Ol[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=vl(i);o>0||a.length>0?(t.push("%c"+l),n.push(a)):t.push(l)}else break}}for(o>0&&(s=n,s.unshift(t.join("")));o<e.length;o++){const l=e[o];l instanceof Symbol||s.push(l)}return s},gs=xl?Rl:jl,Nl=(...e)=>{console.log(...gs(e)),ms.forEach(t=>t.print(e))},ps=(...e)=>{console.warn(...gs(e)),e.unshift(Gn),ms.forEach(t=>t.print(e))},ms=Ot(),xs=e=>({[Symbol.iterator](){return this},next:e}),Bl=(e,t)=>xs(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),mn=(e,t)=>xs(()=>{const{done:n,value:i}=e.next();return{done:n,value:n?void 0:t(i)}});class Jn{constructor(t,n){this.clock=t,this.len=n}}class Xt{constructor(){this.clients=new Map}}const Et=(e,t,n)=>t.clients.forEach((i,s)=>{const o=e.doc.store.clients.get(s);if(o!=null){const r=o[o.length-1],l=r.id.clock+r.length;for(let c=0,a=i[c];c<i.length&&a.clock<l;a=i[++c])_s(e,o,a.clock,a.len,n)}}),Ll=(e,t)=>{let n=0,i=e.length-1;for(;n<=i;){const s=xt((n+i)/2),o=e[s],r=o.clock;if(r<=t){if(t<r+o.len)return s;n=s+1}else i=s-1}return null},Zt=(e,t)=>{const n=e.clients.get(t.client);return n!==void 0&&Ll(n,t.clock)!==null},Xn=e=>{e.clients.forEach(t=>{t.sort((s,o)=>s.clock-o.clock);let n,i;for(n=1,i=1;n<t.length;n++){const s=t[i-1],o=t[n];s.clock+s.len>=o.clock?s.len=vt(s.len,o.clock+o.len-s.clock):(i<n&&(t[i]=o),i++)}t.length=i})},Mn=e=>{const t=new Xt;for(let n=0;n<e.length;n++)e[n].clients.forEach((i,s)=>{if(!t.clients.has(s)){const o=i.slice();for(let r=n+1;r<e.length;r++)yr(o,e[r].clients.get(s)||[]);t.clients.set(s,o)}});return Xn(t),t},he=(e,t,n,i)=>{wt(e.clients,t,()=>[]).push(new Jn(n,i))},ws=()=>new Xt,Ul=e=>{const t=ws();return e.clients.forEach((n,i)=>{const s=[];for(let o=0;o<n.length;o++){const r=n[o];if(r.deleted){const l=r.id.clock;let c=r.length;if(o+1<n.length)for(let a=n[o+1];o+1<n.length&&a.deleted;a=n[++o+1])c+=a.length;s.push(new Jn(l,c))}}s.length>0&&t.clients.set(i,s)}),t},Zn=(e,t)=>{A(e.restEncoder,t.clients.size),Rt(t.clients.entries()).sort((n,i)=>i[0]-n[0]).forEach(([n,i])=>{e.resetDsCurVal(),A(e.restEncoder,n);const s=i.length;A(e.restEncoder,s);for(let o=0;o<s;o++){const r=i[o];e.writeDsClock(r.clock),e.writeDsLen(r.len)}})},Pl=e=>{const t=new Xt,n=O(e.restDecoder);for(let i=0;i<n;i++){e.resetDsCurVal();const s=O(e.restDecoder),o=O(e.restDecoder);if(o>0){const r=wt(t.clients,s,()=>[]);for(let l=0;l<o;l++)r.push(new Jn(e.readDsClock(),e.readDsLen()))}}return t},_i=(e,t,n)=>{const i=new Xt,s=O(e.restDecoder);for(let o=0;o<s;o++){e.resetDsCurVal();const r=O(e.restDecoder),l=O(e.restDecoder),c=n.clients.get(r)||[],a=P(n,r);for(let h=0;h<l;h++){const d=e.readDsClock(),f=d+e.readDsLen();if(d<a){a<f&&he(i,r,a,f-a);let g=ct(c,d),m=c[g];for(!m.deleted&&m.id.clock<d&&(c.splice(g+1,0,We(t,m,d-m.id.clock)),g++);g<c.length&&(m=c[g++],m.id.clock<f);)m.deleted||(f<m.id.clock+m.length&&c.splice(g,0,We(t,m,f-m.id.clock)),m.delete(t))}else he(i,r,d,f-d)}}if(i.clients.size>0){const o=new tn;return A(o.restEncoder,0),Zn(o,i),o.toUint8Array()}return null},bs=is;class Lt extends Zi{constructor({guid:t=il(),collectionid:n=null,gc:i=!0,gcFilter:s=()=>!0,meta:o=null,autoLoad:r=!1,shouldLoad:l=!0}={}){super(),this.gc=i,this.gcFilter=s,this.clientID=bs(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new ks,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=r,this.meta=o,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Ci(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const c=()=>Ci(a=>{const h=d=>{(d===void 0||d===!0)&&(this.off("sync",h),a())};this.on("sync",h)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=a===void 0||a===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=c()}load(){const t=this._item;t!==null&&!this.shouldLoad&&j(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Rt(this.subdocs).map(t=>t.guid))}transact(t,n=null){return j(this,t,n)}get(t,n=z){const i=wt(this.share,t,()=>{const o=new n;return o._integrate(this,null),o}),s=i.constructor;if(n!==z&&s!==n)if(s===z){const o=new n;o._map=i._map,i._map.forEach(r=>{for(;r!==null;r=r.left)r.parent=o}),o._start=i._start;for(let r=o._start;r!==null;r=r.right)r.parent=o;return o._length=i._length,this.share.set(t,o),o._integrate(this,null),o}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return i}getArray(t=""){return this.get(t,qt)}getText(t=""){return this.get(t,It)}getMap(t=""){return this.get(t,Gt)}getXmlElement(t=""){return this.get(t,q)}getXmlFragment(t=""){return this.get(t,Nt)}toJSON(){const t={};return this.share.forEach((n,i)=>{t[i]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,Rt(this.subdocs).forEach(n=>n.destroy());const t=this._item;if(t!==null){this._item=null;const n=t.content;n.doc=new Lt({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,j(t.parent.doc,i=>{const s=n.doc;t.deleted||i.subdocsAdded.add(s),i.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class Vl{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=O(this.restDecoder),this.dsCurrVal}readDsLen(){const t=O(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class Fe extends Vl{constructor(t){super(t),this.keys=[],O(t),this.keyClockDecoder=new pn(et(t)),this.clientDecoder=new Oe(et(t)),this.leftClockDecoder=new pn(et(t)),this.rightClockDecoder=new pn(et(t)),this.infoDecoder=new Si(et(t),ae),this.stringDecoder=new Zr(et(t)),this.parentInfoDecoder=new Si(et(t),ae),this.typeRefDecoder=new Oe(et(t)),this.lenDecoder=new Oe(et(t))}readLeftID(){return new $t(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new $t(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 Pe(this.restDecoder)}readBuf(){return et(this.restDecoder)}readJSON(){return Pe(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 Fl{constructor(){this.restEncoder=we()}toUint8Array(){return st(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){A(this.restEncoder,t)}writeDsLen(t){A(this.restEncoder,t)}}class Hl extends Fl{writeLeftID(t){A(this.restEncoder,t.client),A(this.restEncoder,t.clock)}writeRightID(t){A(this.restEncoder,t.client),A(this.restEncoder,t.clock)}writeClient(t){A(this.restEncoder,t)}writeInfo(t){In(this.restEncoder,t)}writeString(t){Ht(this.restEncoder,t)}writeParentInfo(t){A(this.restEncoder,t?1:0)}writeTypeRef(t){A(this.restEncoder,t)}writeLen(t){A(this.restEncoder,t)}writeAny(t){Wt(this.restEncoder,t)}writeBuf(t){Q(this.restEncoder,t)}writeJSON(t){Ht(this.restEncoder,JSON.stringify(t))}writeKey(t){Ht(this.restEncoder,t)}}class $l{constructor(){this.restEncoder=we(),this.dsCurrVal=0}toUint8Array(){return st(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,A(this.restEncoder,n)}writeDsLen(t){t===0&&X(),A(this.restEncoder,t-1),this.dsCurrVal+=t}}class tn extends $l{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new gn,this.clientEncoder=new je,this.leftClockEncoder=new gn,this.rightClockEncoder=new gn,this.infoEncoder=new wi(In),this.stringEncoder=new $r,this.parentInfoEncoder=new wi(In),this.typeRefEncoder=new je,this.lenEncoder=new je}toUint8Array(){const t=we();return A(t,0),Q(t,this.keyClockEncoder.toUint8Array()),Q(t,this.clientEncoder.toUint8Array()),Q(t,this.leftClockEncoder.toUint8Array()),Q(t,this.rightClockEncoder.toUint8Array()),Q(t,st(this.infoEncoder)),Q(t,this.stringEncoder.toUint8Array()),Q(t,st(this.parentInfoEncoder)),Q(t,this.typeRefEncoder.toUint8Array()),Q(t,this.lenEncoder.toUint8Array()),Ze(t,st(this.restEncoder)),st(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){Wt(this.restEncoder,t)}writeBuf(t){Q(this.restEncoder,t)}writeJSON(t){Wt(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 zl=(e,t,n,i)=>{i=vt(i,t[0].id.clock);const s=ct(t,i);A(e.restEncoder,t.length-s),e.writeClient(n),A(e.restEncoder,i);const o=t[s];o.write(e,i-o.id.clock);for(let r=s+1;r<t.length;r++)t[r].write(e,0)},ys=(e,t,n)=>{const i=new Map;n.forEach((s,o)=>{P(t,o)>s&&i.set(o,s)}),en(t).forEach((s,o)=>{n.has(o)||i.set(o,0)}),A(e.restEncoder,i.size),Rt(i.entries()).sort((s,o)=>o[0]-s[0]).forEach(([s,o])=>{zl(e,t.clients.get(s),s,o)})},ql=(e,t)=>{const n=rt(),i=O(e.restDecoder);for(let s=0;s<i;s++){const o=O(e.restDecoder),r=new Array(o),l=e.readClient();let c=O(e.restDecoder);n.set(l,{i:0,refs:r});for(let a=0;a<o;a++){const h=e.readInfo();switch(Xe&h){case 0:{const d=e.readLen();r[a]=new nt(_(l,c),d),c+=d;break}case 10:{const d=O(e.restDecoder);r[a]=new it(_(l,c),d),c+=d;break}default:{const d=(h&(pt|W))===0,f=new D(_(l,c),null,(h&W)===W?e.readLeftID():null,null,(h&pt)===pt?e.readRightID():null,d?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,d&&(h&le)===le?e.readString():null,Ws(e,h));r[a]=f,c+=f.length}}}}return n},Kl=(e,t,n)=>{const i=[];let s=Rt(n.keys()).sort((g,m)=>g-m);if(s.length===0)return null;const o=()=>{if(s.length===0)return null;let g=n.get(s[s.length-1]);for(;g.refs.length===g.i;)if(s.pop(),s.length>0)g=n.get(s[s.length-1]);else return null;return g};let r=o();if(r===null)return null;const l=new ks,c=new Map,a=(g,m)=>{const x=c.get(g);(x==null||x>m)&&c.set(g,m)};let h=r.refs[r.i++];const d=new Map,f=()=>{for(const g of i){const m=g.id.client,x=n.get(m);x?(x.i--,l.clients.set(m,x.refs.slice(x.i)),n.delete(m),x.i=0,x.refs=[]):l.clients.set(m,[g]),s=s.filter(b=>b!==m)}i.length=0};for(;;){if(h.constructor!==it){const m=wt(d,h.id.client,()=>P(t,h.id.client))-h.id.clock;if(m<0)i.push(h),a(h.id.client,h.id.clock-1),f();else{const x=h.getMissing(e,t);if(x!==null){i.push(h);const b=n.get(x)||{refs:[],i:0};if(b.refs.length===b.i)a(x,P(t,x)),f();else{h=b.refs[b.i++];continue}}else(m===0||m<h.length)&&(h.integrate(e,m),d.set(h.id.client,h.id.clock+h.length))}}if(i.length>0)h=i.pop();else if(r!==null&&r.i<r.refs.length)h=r.refs[r.i++];else{if(r=o(),r===null)break;h=r.refs[r.i++]}}if(l.clients.size>0){const g=new tn;return ys(g,l,new Map),A(g.restEncoder,0),{missing:c,update:g.toUint8Array()}}return null},Wl=(e,t)=>ys(e,t.doc.store,t.beforeState),Yl=(e,t,n,i=new Fe(e))=>j(t,s=>{s.local=!1;let o=!1;const r=s.doc,l=r.store,c=ql(i,r),a=Kl(s,l,c),h=l.pendingStructs;if(h){for(const[f,g]of h.missing)if(g<P(l,f)){o=!0;break}if(a){for(const[f,g]of a.missing){const m=h.missing.get(f);(m==null||m>g)&&h.missing.set(f,g)}h.update=Ri([h.update,a.update])}}else l.pendingStructs=a;const d=_i(i,s,l);if(l.pendingDs){const f=new Fe(qn(l.pendingDs));O(f.restDecoder);const g=_i(f,s,l);d&&g?l.pendingDs=Ri([d,g]):l.pendingDs=d||g}else l.pendingDs=d;if(o){const f=l.pendingStructs.update;l.pendingStructs=null,jn(s.doc,f)}},n,!1),jn=(e,t,n,i=Fe)=>{const s=qn(t);Yl(s,e,n,new i(s))};class Gl{constructor(){this.l=[]}}const Ei=()=>new Gl,Ii=(e,t)=>e.l.push(t),Ti=(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.")},Ss=(e,t,n)=>Yn(e.l,[t,n]);class $t{constructor(t,n){this.client=t,this.clock=n}}const ke=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,_=(e,t)=>new $t(e,t),de=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw X()},ue=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1};class He{constructor(t,n,i,s=0){this.type=t,this.tname=n,this.item=i,this.assoc=s}}class Jl{constructor(t,n,i=0){this.type=t,this.index=n,this.assoc=i}}const Xl=(e,t,n=0)=>new Jl(e,t,n),ve=(e,t,n)=>{let i=null,s=null;return e._item===null?s=de(e):i=_(e._item.id.client,e._item.id.clock),new He(i,s,t,n)},xn=(e,t,n=0)=>{let i=e._start;if(n<0){if(t===0)return ve(e,null,n);t--}for(;i!==null;){if(!i.deleted&&i.countable){if(i.length>t)return ve(e,_(i.id.client,i.id.clock+t),n);t-=i.length}if(i.right===null&&n<0)return ve(e,i.lastId,n);i=i.right}return ve(e,null,n)},Zl=(e,t)=>{const n=zt(e,t),i=t.clock-n.id.clock;return{item:n,diff:i}},Ql=(e,t,n=!0)=>{const i=t.store,s=e.item,o=e.type,r=e.tname,l=e.assoc;let c=null,a=0;if(s!==null){if(P(i,s.client)<=s.clock)return null;const h=n?Bn(i,s):Zl(i,s),d=h.item;if(!(d instanceof D))return null;if(c=d.parent,c._item===null||!c._item.deleted){a=d.deleted||!d.countable?0:h.diff+(l>=0?0:1);let f=d.left;for(;f!==null;)!f.deleted&&f.countable&&(a+=f.length),f=f.left}}else{if(r!==null)c=t.get(r);else if(o!==null){if(P(i,o.client)<=o.clock)return null;const{item:h}=n?Bn(i,o):{item:zt(i,o)};if(h instanceof D&&h.content instanceof ht)c=h.content.type;else return null}else throw X();l>=0?a=c._length:a=0}return Xl(c,a,e.assoc)};class Qn{constructor(t,n){this.ds=t,this.sv=n}}const Cs=(e,t)=>new Qn(e,t),wn=e=>Cs(Ul(e.store),en(e.store)),Mt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Zt(t.ds,e.id),On=(e,t)=>{const n=wt(e.meta,On,Ot),i=e.doc.store;n.has(t)||(t.sv.forEach((s,o)=>{s<P(i,o)&&G(e,_(o,s))}),Et(e,t.ds,s=>{}),n.add(t))};class ks{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const en=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},vs=(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 X()}n.push(t)},ct=(e,t)=>{let n=0,i=e.length-1,s=e[i],o=s.id.clock;if(o===t)return i;let r=xt(t/(o+s.length-1)*i);for(;n<=i;){if(s=e[r],o=s.id.clock,o<=t){if(t<o+s.length)return r;n=r+1}else i=r-1;r=xt((n+i)/2)}throw X()},tc=(e,t)=>{const n=e.clients.get(t.client);return n[ct(n,t.clock)]},zt=tc,Rn=(e,t,n)=>{const i=ct(t,n),s=t[i];return s.id.clock<n&&s instanceof D?(t.splice(i+1,0,We(e,s,n-s.id.clock)),i+1):i},G=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[Rn(e,n,t.clock)]},Ai=(e,t,n)=>{const i=t.clients.get(n.client),s=ct(i,n.clock),o=i[s];return n.clock!==o.id.clock+o.length-1&&o.constructor!==nt&&i.splice(s+1,0,We(e,o,n.clock-o.id.clock+1)),o},ec=(e,t,n)=>{const i=e.clients.get(t.id.client);i[ct(i,t.id.clock)]=n},_s=(e,t,n,i,s)=>{if(i===0)return;const o=n+i;let r=Rn(e,t,n),l;do l=t[r++],o<l.id.clock+l.length&&Rn(e,t,o),s(l);while(r<t.length&&t[r].id.clock<o)};class nc{constructor(t,n,i){this.doc=t,this.deleteSet=new Xt,this.beforeState=en(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 Di=(e,t)=>t.deleteSet.clients.size===0&&!br(t.afterState,(n,i)=>t.beforeState.get(i)!==n)?!1:(Xn(t.deleteSet),Wl(e,t),Zn(e,t.deleteSet),!0),Mi=(e,t,n)=>{const i=t._item;(i===null||i.id.clock<(e.beforeState.get(i.id.client)||0)&&!i.deleted)&&wt(e.changed,t,Ot).add(n)},Re=(e,t)=>{let n=e[t],i=e[t-1],s=t;for(;s>0;n=i,i=e[--s-1]){if(i.deleted===n.deleted&&i.constructor===n.constructor&&i.mergeWith(n)){n instanceof D&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,i);continue}break}const o=t-s;return o&&e.splice(t+1-o,o),o},ic=(e,t,n)=>{for(const[i,s]of e.clients.entries()){const o=t.clients.get(i);for(let r=s.length-1;r>=0;r--){const l=s[r],c=l.clock+l.len;for(let a=ct(o,l.clock),h=o[a];a<o.length&&h.id.clock<c;h=o[++a]){const d=o[a];if(l.clock+l.len<=d.id.clock)break;d instanceof D&&d.deleted&&!d.keep&&n(d)&&d.gc(t,!1)}}}},sc=(e,t)=>{e.clients.forEach((n,i)=>{const s=t.clients.get(i);for(let o=n.length-1;o>=0;o--){const r=n[o],l=Kt(s.length-1,1+ct(s,r.clock+r.len-1));for(let c=l,a=s[c];c>0&&a.id.clock>=r.clock;a=s[c])c-=1+Re(s,c)}})},Es=(e,t)=>{if(t<e.length){const n=e[t],i=n.doc,s=i.store,o=n.deleteSet,r=n._mergeStructs;try{Xn(o),n.afterState=en(n.doc.store),i.emit("beforeObserverCalls",[n,i]);const l=[];n.changed.forEach((c,a)=>l.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(n,c)})),l.push(()=>{n.changedParentTypes.forEach((c,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(c=c.filter(h=>h.target._item===null||!h.target._item.deleted),c.forEach(h=>{h.currentTarget=a,h._path=null}),c.sort((h,d)=>h.path.length-d.path.length),Ss(a._dEH,c,n))})}),l.push(()=>i.emit("afterTransaction",[n,i])),Yn(l,[]),n._needFormattingCleanup&&vc(n)}finally{i.gc&&ic(o,s,i.gcFilter),sc(o,s),n.afterState.forEach((h,d)=>{const f=n.beforeState.get(d)||0;if(f!==h){const g=s.clients.get(d),m=vt(ct(g,f),1);for(let x=g.length-1;x>=m;)x-=1+Re(g,x)}});for(let h=r.length-1;h>=0;h--){const{client:d,clock:f}=r[h].id,g=s.clients.get(d),m=ct(g,f);m+1<g.length&&Re(g,m+1)>1||m>0&&Re(g,m)}if(!n.local&&n.afterState.get(i.clientID)!==n.beforeState.get(i.clientID)&&(Nl(Gn,ds,"[yjs] ",us,fs,"Changed the client-id because another client seems to be using it."),i.clientID=bs()),i.emit("afterTransactionCleanup",[n,i]),i._observers.has("update")){const h=new Hl;Di(h,n)&&i.emit("update",[h.toUint8Array(),n.origin,i,n])}if(i._observers.has("updateV2")){const h=new tn;Di(h,n)&&i.emit("updateV2",[h.toUint8Array(),n.origin,i,n])}const{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=n;(l.size>0||a.size>0||c.size>0)&&(l.forEach(h=>{h.clientID=i.clientID,h.collectionid==null&&(h.collectionid=i.collectionid),i.subdocs.add(h)}),a.forEach(h=>i.subdocs.delete(h)),i.emit("subdocs",[{loaded:c,added:l,removed:a},i,n]),a.forEach(h=>h.destroy())),e.length<=t+1?(i._transactionCleanups=[],i.emit("afterAllTransactions",[i,e])):Es(e,t+1)}}},j=(e,t,n=null,i=!0)=>{const s=e._transactionCleanups;let o=!1,r=null;e._transaction===null&&(o=!0,e._transaction=new nc(e,n,i),s.push(e._transaction),s.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{r=t(e._transaction)}finally{if(o){const l=e._transaction===s[0];e._transaction=null,l&&Es(s,0)}}return r};class oc{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const ji=(e,t,n)=>{Et(e,n.deletions,i=>{i instanceof D&&t.scope.some(s=>s===e.doc||ue(s,i))&&si(i,!1)})},Oi=(e,t,n)=>{let i=null;const s=e.doc,o=e.scope;j(s,l=>{for(;t.length>0&&e.currStackItem===null;){const c=s.store,a=t.pop(),h=new Set,d=[];let f=!1;Et(l,a.insertions,g=>{if(g instanceof D){if(g.redone!==null){let{item:m,diff:x}=Bn(c,g.id);x>0&&(m=G(l,_(m.id.client,m.id.clock+x))),g=m}!g.deleted&&o.some(m=>m===l.doc||ue(m,g))&&d.push(g)}}),Et(l,a.deletions,g=>{g instanceof D&&o.some(m=>m===l.doc||ue(m,g))&&!Zt(a.insertions,g.id)&&h.add(g)}),h.forEach(g=>{f=Ks(l,g,h,a.insertions,e.ignoreRemoteMapChanges,e)!==null||f});for(let g=d.length-1;g>=0;g--){const m=d[g];e.deleteFilter(m)&&(m.delete(l),f=!0)}e.currStackItem=f?a:null}l.changed.forEach((c,a)=>{c.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),i=l},e);const r=e.currStackItem;if(r!=null){const l=i.changedParentTypes;e.emit("stack-item-popped",[{stackItem:r,type:n,changedParentTypes:l,origin:e},e]),e.currStackItem=null}return r};class Is extends Zi{constructor(t,{captureTimeout:n=500,captureTransaction:i=c=>!0,deleteFilter:s=()=>!0,trackedOrigins:o=new Set([null]),ignoreRemoteMapChanges:r=!1,doc:l=_n(t)?t[0].doc:t instanceof Lt?t:t.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(t),this.deleteFilter=s,o.add(this),this.trackedOrigins=o,this.captureTransaction=i,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=r,this.captureTimeout=n,this.afterTransactionHandler=c=>{if(!this.captureTransaction(c)||!this.scope.some(b=>c.changedParentTypes.has(b)||b===this.doc)||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;const a=this.undoing,h=this.redoing,d=a?this.redoStack:this.undoStack;a?this.stopCapturing():h||this.clear(!1,!0);const f=new Xt;c.afterState.forEach((b,y)=>{const I=c.beforeState.get(y)||0,M=b-I;M>0&&he(f,y,I,M)});const g=sl();let m=!1;if(this.lastChange>0&&g-this.lastChange<this.captureTimeout&&d.length>0&&!a&&!h){const b=d[d.length-1];b.deletions=Mn([b.deletions,c.deleteSet]),b.insertions=Mn([b.insertions,f])}else d.push(new oc(c.deleteSet,f)),m=!0;!a&&!h&&(this.lastChange=g),Et(c,c.deleteSet,b=>{b instanceof D&&this.scope.some(y=>y===c.doc||ue(y,b))&&si(b,!0)});const x=[{stackItem:d[d.length-1],origin:c.origin,type:a?"redo":"undo",changedParentTypes:c.changedParentTypes},this];m?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=_n(t)?t:[t],t.forEach(i=>{n.has(i)||(n.add(i),(i instanceof z?i.doc!==this.doc:i!==this.doc)&&ps("[yjs#509] Not same Y.Doc"),this.scope.push(i))})}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,n=!0){(t&&this.canUndo()||n&&this.canRedo())&&this.doc.transact(i=>{t&&(this.undoStack.forEach(s=>ji(i,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>ji(i,this,s)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let t;try{t=Oi(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=Oi(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*rc(e){const t=O(e.restDecoder);for(let n=0;n<t;n++){const i=O(e.restDecoder),s=e.readClient();let o=O(e.restDecoder);for(let r=0;r<i;r++){const l=e.readInfo();if(l===10){const c=O(e.restDecoder);yield new it(_(s,o),c),o+=c}else if((Xe&l)!==0){const c=(l&(pt|W))===0,a=new D(_(s,o),null,(l&W)===W?e.readLeftID():null,null,(l&pt)===pt?e.readRightID():null,c?e.readParentInfo()?e.readString():e.readLeftID():null,c&&(l&le)===le?e.readString():null,Ws(e,l));yield a,o+=a.length}else{const c=e.readLen();yield new nt(_(s,o),c),o+=c}}}}class lc{constructor(t,n){this.gen=rc(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===it);return this.curr}}class cc{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const ac=(e,t)=>{if(e.constructor===nt){const{client:n,clock:i}=e.id;return new nt(_(n,i+t),e.length-t)}else if(e.constructor===it){const{client:n,clock:i}=e.id;return new it(_(n,i+t),e.length-t)}else{const n=e,{client:i,clock:s}=n.id;return new D(_(i,s+t),null,_(i,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Ri=(e,t=Fe,n=tn)=>{if(e.length===1)return e[0];const i=e.map(h=>new t(qn(h)));let s=i.map(h=>new lc(h,!0)),o=null;const r=new n,l=new cc(r);for(;s=s.filter(f=>f.curr!==null),s.sort((f,g)=>{if(f.curr.id.client===g.curr.id.client){const m=f.curr.id.clock-g.curr.id.clock;return m===0?f.curr.constructor===g.curr.constructor?0:f.curr.constructor===it?1:-1:m}else return g.curr.id.client-f.curr.id.client}),s.length!==0;){const h=s[0],d=h.curr.id.client;if(o!==null){let f=h.curr,g=!1;for(;f!==null&&f.id.clock+f.length<=o.struct.id.clock+o.struct.length&&f.id.client>=o.struct.id.client;)f=h.next(),g=!0;if(f===null||f.id.client!==d||g&&f.id.clock>o.struct.id.clock+o.struct.length)continue;if(d!==o.struct.id.client)se(l,o.struct,o.offset),o={struct:f,offset:0},h.next();else if(o.struct.id.clock+o.struct.length<f.id.clock)if(o.struct.constructor===it)o.struct.length=f.id.clock+f.length-o.struct.id.clock;else{se(l,o.struct,o.offset);const m=f.id.clock-o.struct.id.clock-o.struct.length;o={struct:new it(_(d,o.struct.id.clock+o.struct.length),m),offset:0}}else{const m=o.struct.id.clock+o.struct.length-f.id.clock;m>0&&(o.struct.constructor===it?o.struct.length-=m:f=ac(f,m)),o.struct.mergeWith(f)||(se(l,o.struct,o.offset),o={struct:f,offset:0},h.next())}}else o={struct:h.curr,offset:0},h.next();for(let f=h.curr;f!==null&&f.id.client===d&&f.id.clock===o.struct.id.clock+o.struct.length&&f.constructor!==it;f=h.next())se(l,o.struct,o.offset),o={struct:f,offset:0}}o!==null&&(se(l,o.struct,o.offset),o=null),hc(l);const c=i.map(h=>Pl(h)),a=Mn(c);return Zn(r,a),r.toUint8Array()},Ts=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:st(e.encoder.restEncoder)}),e.encoder.restEncoder=we(),e.written=0)},se=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Ts(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),A(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},hc=e=>{Ts(e);const t=e.encoder.restEncoder;A(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const i=e.clientStructs[n];A(t,i.written),Ze(t,i.restEncoder)}},Ni="You must not compute changes after the event-handler fired.";class nn{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=dc(this.currentTarget,this.target))}deletes(t){return Zt(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw _t(Ni);const t=new Map,n=this.target;this.transaction.changed.get(n).forEach(s=>{if(s!==null){const o=n._map.get(s);let r,l;if(this.adds(o)){let c=o.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(o))if(c!==null&&this.deletes(c))r="delete",l=dn(c.content.getContent());else return;else c!==null&&this.deletes(c)?(r="update",l=dn(c.content.getContent())):(r="add",l=void 0)}else if(this.deletes(o))r="delete",l=dn(o.content.getContent());else return;t.set(s,{action:r,oldValue:l})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw _t(Ni);const n=this.target,i=Ot(),s=Ot(),o=[];if(t={added:i,deleted:s,delta:o,keys:this.keys},this.transaction.changed.get(n).has(null)){let l=null;const c=()=>{l&&o.push(l)};for(let a=n._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((l===null||l.delete===void 0)&&(c(),l={delete:0}),l.delete+=a.length,s.add(a)):this.adds(a)?((l===null||l.insert===void 0)&&(c(),l={insert:[]}),l.insert=l.insert.concat(a.content.getContent()),i.add(a)):((l===null||l.retain===void 0)&&(c(),l={retain:0}),l.retain+=a.length);l!==null&&l.retain===void 0&&c()}this._changes=t}return t}}const dc=(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},K=()=>{ps("Invalid access: Add Yjs type to a document before reading data.")},As=80;let ti=0;class uc{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=ti++}}const fc=e=>{e.timestamp=ti++},Ds=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=ti++},gc=(e,t,n)=>{if(e.length>=As){const i=e.reduce((s,o)=>s.timestamp<o.timestamp?s:o);return Ds(i,t,n),i}else{const i=new uc(t,n);return e.push(i),i}},sn=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;const n=e._searchMarker.length===0?null:e._searchMarker.reduce((o,r)=>Me(t-o.index)<Me(t-r.index)?o:r);let i=e._start,s=0;for(n!==null&&(i=n.p,s=n.index,fc(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&&Me(n.index-s)<i.parent.length/As?(Ds(n,i,s),n):gc(e._searchMarker,i,s)},fe=(e,t,n)=>{for(let i=e.length-1;i>=0;i--){const s=e[i];if(n>0){let o=s.p;for(o.marker=!1;o&&(o.deleted||!o.countable);)o=o.left,o&&!o.deleted&&o.countable&&(s.index-=o.length);if(o===null||o.marker===!0){e.splice(i,1);continue}s.p=o,o.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=vt(t,s.index+n))}},on=(e,t,n)=>{const i=e,s=t.changedParentTypes;for(;wt(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Ss(i._eH,n,t)};class z{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Ei(),this._dEH=Ei(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw lt()}clone(){throw lt()}_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){Ii(this._eH,t)}observeDeep(t){Ii(this._dEH,t)}unobserve(t){Ti(this._eH,t)}unobserveDeep(t){Ti(this._dEH,t)}toJSON(){}}const Ms=(e,t,n)=>{e.doc??K(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let i=n-t;const s=[];let o=e._start;for(;o!==null&&i>0;){if(o.countable&&!o.deleted){const r=o.content.getContent();if(r.length<=t)t-=r.length;else{for(let l=t;l<r.length&&i>0;l++)s.push(r[l]),i--;t=0}}o=o.right}return s},js=e=>{e.doc??K();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},Os=(e,t)=>{const n=[];let i=e._start;for(;i!==null;){if(i.countable&&Mt(i,t)){const s=i.content.getContent();for(let o=0;o<s.length;o++)n.push(s[o])}i=i.right}return n},ge=(e,t)=>{let n=0,i=e._start;for(e.doc??K();i!==null;){if(i.countable&&!i.deleted){const s=i.content.getContent();for(let o=0;o<s.length;o++)t(s[o],n++,e)}i=i.right}},Rs=(e,t)=>{const n=[];return ge(e,(i,s)=>{n.push(t(i,s,e))}),n},pc=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}}}},Ns=(e,t)=>{e.doc??K();const n=sn(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}},$e=(e,t,n,i)=>{let s=n;const o=e.doc,r=o.clientID,l=o.store,c=n===null?t._start:n.right;let a=[];const h=()=>{a.length>0&&(s=new D(_(r,P(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new Bt(a)),s.integrate(e,0),a=[])};i.forEach(d=>{if(d===null)a.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(d);break;default:switch(h(),d.constructor){case Uint8Array:case ArrayBuffer:s=new D(_(r,P(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new be(new Uint8Array(d))),s.integrate(e,0);break;case Lt:s=new D(_(r,P(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new ye(d)),s.integrate(e,0);break;default:if(d instanceof z)s=new D(_(r,P(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new ht(d)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},Bs=()=>_t("Length exceeded!"),Ls=(e,t,n,i)=>{if(n>t._length)throw Bs();if(n===0)return t._searchMarker&&fe(t._searchMarker,n,i.length),$e(e,t,null,i);const s=n,o=sn(t,n);let r=t._start;for(o!==null&&(r=o.p,n-=o.index,n===0&&(r=r.prev,n+=r&&r.countable&&!r.deleted?r.length:0));r!==null;r=r.right)if(!r.deleted&&r.countable){if(n<=r.length){n<r.length&&G(e,_(r.id.client,r.id.clock+n));break}n-=r.length}return t._searchMarker&&fe(t._searchMarker,s,i.length),$e(e,t,r,i)},mc=(e,t,n)=>{let s=(t._searchMarker||[]).reduce((o,r)=>r.index>o.index?r:o,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return $e(e,t,s,n)},Us=(e,t,n,i)=>{if(i===0)return;const s=n,o=i,r=sn(t,n);let l=t._start;for(r!==null&&(l=r.p,n-=r.index);l!==null&&n>0;l=l.right)!l.deleted&&l.countable&&(n<l.length&&G(e,_(l.id.client,l.id.clock+n)),n-=l.length);for(;i>0&&l!==null;)l.deleted||(i<l.length&&G(e,_(l.id.client,l.id.clock+i)),l.delete(e),i-=l.length),l=l.right;if(i>0)throw Bs();t._searchMarker&&fe(t._searchMarker,s,-o+i)},ze=(e,t,n)=>{const i=t._map.get(n);i!==void 0&&i.delete(e)},ei=(e,t,n,i)=>{const s=t._map.get(n)||null,o=e.doc,r=o.clientID;let l;if(i==null)l=new Bt([i]);else switch(i.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new Bt([i]);break;case Uint8Array:l=new be(i);break;case Lt:l=new ye(i);break;default:if(i instanceof z)l=new ht(i);else throw new Error("Unexpected content type")}new D(_(r,P(o.store,r)),s,s&&s.lastId,null,null,t,n,l).integrate(e,0)},ni=(e,t)=>{e.doc??K();const n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Ps=e=>{const t={};return e.doc??K(),e._map.forEach((n,i)=>{n.deleted||(t[i]=n.content.getContent()[n.length-1])}),t},Vs=(e,t)=>{e.doc??K();const n=e._map.get(t);return n!==void 0&&!n.deleted},xc=(e,t)=>{const n={};return e._map.forEach((i,s)=>{let o=i;for(;o!==null&&(!t.sv.has(o.id.client)||o.id.clock>=(t.sv.get(o.id.client)||0));)o=o.left;o!==null&&Mt(o,t)&&(n[s]=o.content.getContent()[o.length-1])}),n},_e=e=>(e.doc??K(),Bl(e._map.entries(),t=>!t[1].deleted));class wc extends nn{}class qt extends z{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 z?n.clone():n)),t}get length(){return this.doc??K(),this._length}_callObserver(t,n){super._callObserver(t,n),on(this,t,new wc(this,t))}insert(t,n){this.doc!==null?j(this.doc,i=>{Ls(i,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?j(this.doc,n=>{mc(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?j(this.doc,i=>{Us(i,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return Ns(this,t)}toArray(){return js(this)}slice(t=0,n=this.length){return Ms(this,t,n)}toJSON(){return this.map(t=>t instanceof z?t.toJSON():t)}map(t){return Rs(this,t)}forEach(t){ge(this,t)}[Symbol.iterator](){return pc(this)}_write(t){t.writeTypeRef($c)}}const bc=e=>new qt;class yc extends nn{constructor(t,n,i){super(t,n),this.keysChanged=i}}class Gt extends z{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 Gt}clone(){const t=new Gt;return this.forEach((n,i)=>{t.set(i,n instanceof z?n.clone():n)}),t}_callObserver(t,n){on(this,t,new yc(this,t,n))}toJSON(){this.doc??K();const t={};return this._map.forEach((n,i)=>{if(!n.deleted){const s=n.content.getContent()[n.length-1];t[i]=s instanceof z?s.toJSON():s}}),t}get size(){return[..._e(this)].length}keys(){return mn(_e(this),t=>t[0])}values(){return mn(_e(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return mn(_e(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??K(),this._map.forEach((n,i)=>{n.deleted||t(n.content.getContent()[n.length-1],i,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?j(this.doc,n=>{ze(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?j(this.doc,i=>{ei(i,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return ni(this,t)}has(t){return Vs(this,t)}clear(){this.doc!==null?j(this.doc,t=>{this.forEach(function(n,i,s){ze(t,s,i)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(zc)}}const Sc=e=>new Gt,St=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&ul(e,t);class Nn{constructor(t,n,i,s){this.left=t,this.right=n,this.index=i,this.currentAttributes=s}forward(){switch(this.right===null&&X(),this.right.content.constructor){case V:this.right.deleted||Qt(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 Bi=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case V:t.right.deleted||Qt(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&G(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},Ee=(e,t,n,i)=>{const s=new Map,o=i?sn(t,n):null;if(o){const r=new Nn(o.p.left,o.p,o.index,s);return Bi(e,r,n-o.index)}else{const r=new Nn(null,t._start,0,s);return Bi(e,r,n)}},Fs=(e,t,n,i)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===V&&St(i.get(n.right.content.key),n.right.content.value));)n.right.deleted||i.delete(n.right.content.key),n.forward();const s=e.doc,o=s.clientID;i.forEach((r,l)=>{const c=n.left,a=n.right,h=new D(_(o,P(s.store,o)),c,c&&c.lastId,a,a&&a.id,t,null,new V(l,r));h.integrate(e,0),n.right=h,n.forward()})},Qt=(e,t)=>{const{key:n,value:i}=t;i===null?e.delete(n):e.set(n,i)},Hs=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===V&&St(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},$s=(e,t,n,i)=>{const s=e.doc,o=s.clientID,r=new Map;for(const l in i){const c=i[l],a=n.currentAttributes.get(l)??null;if(!St(a,c)){r.set(l,a);const{left:h,right:d}=n;n.right=new D(_(o,P(s.store,o)),h,h&&h.lastId,d,d&&d.id,t,null,new V(l,c)),n.right.integrate(e,0),n.forward()}}return r},bn=(e,t,n,i,s)=>{n.currentAttributes.forEach((f,g)=>{s[g]===void 0&&(s[g]=null)});const o=e.doc,r=o.clientID;Hs(n,s);const l=$s(e,t,n,s),c=i.constructor===String?new at(i):i instanceof z?new ht(i):new Ut(i);let{left:a,right:h,index:d}=n;t._searchMarker&&fe(t._searchMarker,n.index,c.getLength()),h=new D(_(r,P(o.store,r)),a,a&&a.lastId,h,h&&h.id,t,null,c),h.integrate(e,0),n.right=h,n.index=d,n.forward(),Fs(e,t,n,l)},Li=(e,t,n,i,s)=>{const o=e.doc,r=o.clientID;Hs(n,s);const l=$s(e,t,n,s);t:for(;n.right!==null&&(i>0||l.size>0&&(n.right.deleted||n.right.content.constructor===V));){if(!n.right.deleted)switch(n.right.content.constructor){case V:{const{key:c,value:a}=n.right.content,h=s[c];if(h!==void 0){if(St(h,a))l.delete(c);else{if(i===0)break t;l.set(c,a)}n.right.delete(e)}else n.currentAttributes.set(c,a);break}default:i<n.right.length&&G(e,_(n.right.id.client,n.right.id.clock+i)),i-=n.right.length;break}n.forward()}if(i>0){let c="";for(;i>0;i--)c+=`
|
|
3
|
-
|
|
4
|
-
`?r.insert.slice(0,-1):r.insert;(typeof l!="string"||l.length>0)&&bn(i,this,s,l,r.attributes||{})}else r.retain!==void 0?Li(i,this,s,r.retain,r.attributes||{}):r.delete!==void 0&&Ui(i,s,r.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,i){this.doc??K();const s=[],o=new Map,r=this.doc;let l="",c=this._start;function a(){if(l.length>0){const d={};let f=!1;o.forEach((m,x)=>{f=!0,d[x]=m});const g={insert:l};f&&(g.attributes=d),s.push(g),l=""}}const h=()=>{for(;c!==null;){if(Mt(c,t)||n!==void 0&&Mt(c,n))switch(c.content.constructor){case at:{const d=o.get("ychange");t!==void 0&&!Mt(c,t)?(d===void 0||d.user!==c.id.client||d.type!=="removed")&&(a(),o.set("ychange",i?i("removed",c.id):{type:"removed"})):n!==void 0&&!Mt(c,n)?(d===void 0||d.user!==c.id.client||d.type!=="added")&&(a(),o.set("ychange",i?i("added",c.id):{type:"added"})):d!==void 0&&(a(),o.delete("ychange")),l+=c.content.str;break}case ht:case Ut:{a();const d={insert:c.content.getContent()[0]};if(o.size>0){const f={};d.attributes=f,o.forEach((g,m)=>{f[m]=g})}s.push(d);break}case V:Mt(c,t)&&(a(),Qt(o,c.content));break}c=c.right}a()};return t||n?j(r,d=>{t&&On(d,t),n&&On(d,n),h()},"cleanup"):h(),s}insert(t,n,i){if(n.length<=0)return;const s=this.doc;s!==null?j(s,o=>{const r=Ee(o,this,t,!i);i||(i={},r.currentAttributes.forEach((l,c)=>{i[c]=l})),bn(o,this,r,n,i)}):this._pending.push(()=>this.insert(t,n,i))}insertEmbed(t,n,i){const s=this.doc;s!==null?j(s,o=>{const r=Ee(o,this,t,!i);bn(o,this,r,n,i||{})}):this._pending.push(()=>this.insertEmbed(t,n,i||{}))}delete(t,n){if(n===0)return;const i=this.doc;i!==null?j(i,s=>{Ui(s,Ee(s,this,t,!0),n)}):this._pending.push(()=>this.delete(t,n))}format(t,n,i){if(n===0)return;const s=this.doc;s!==null?j(s,o=>{const r=Ee(o,this,t,!1);r.right!==null&&Li(o,this,r,n,i)}):this._pending.push(()=>this.format(t,n,i))}removeAttribute(t){this.doc!==null?j(this.doc,n=>{ze(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?j(this.doc,i=>{ei(i,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return ni(this,t)}getAttributes(){return Ps(this)}_write(t){t.writeTypeRef(qc)}}const Ec=e=>new It;class yn{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??K()}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(n)))do if(n=t.content.type,!t.deleted&&(n.constructor===q||n.constructor===Nt)&&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 Nt extends z{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 Nt}clone(){const t=new Nt;return t.insert(0,this.toArray().map(n=>n instanceof z?n.clone():n)),t}get length(){return this.doc??K(),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(),Rt(new yn(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){on(this,t,new Ac(this,n,t))}toString(){return Rs(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),ge(this,o=>{s.insertBefore(o.toDOM(t,n,i),null)}),s}insert(t,n){this.doc!==null?j(this.doc,i=>{Ls(i,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)j(this.doc,i=>{const s=t&&t instanceof z?t._item:t;$e(i,this,s,n)});else{const i=this._prelimContent,s=t===null?0:i.findIndex(o=>o===t)+1;if(s===0&&t!==null)throw _t("Reference item not found");i.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?j(this.doc,i=>{Us(i,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return js(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Ns(this,t)}slice(t=0,n=this.length){return Ms(this,t,n)}forEach(t){ge(this,t)}_write(t){t.writeTypeRef(Wc)}}const Ic=e=>new Nt;class q extends Nt{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach((i,s)=>{this.setAttribute(s,i)}),this._prelimAttrs=null}_copy(){return new q(this.nodeName)}clone(){const t=new q(this.nodeName),n=this.getAttributes();return al(n,(i,s)=>{t.setAttribute(s,i)}),t.insert(0,this.toArray().map(i=>i instanceof z?i.clone():i)),t}toString(){const t=this.getAttributes(),n=[],i=[];for(const l in t)i.push(l);i.sort();const s=i.length;for(let l=0;l<s;l++){const c=i[l];n.push(c+'="'+t[c]+'"')}const o=this.nodeName.toLocaleLowerCase(),r=n.length>0?" "+n.join(" "):"";return`<${o}${r}>${super.toString()}</${o}>`}removeAttribute(t){this.doc!==null?j(this.doc,n=>{ze(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?j(this.doc,i=>{ei(i,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return ni(this,t)}hasAttribute(t){return Vs(this,t)}getAttributes(t){return t?xc(this,t):Ps(this)}toDOM(t=document,n={},i){const s=t.createElement(this.nodeName),o=this.getAttributes();for(const r in o){const l=o[r];typeof l=="string"&&s.setAttribute(r,l)}return ge(this,r=>{s.appendChild(r.toDOM(t,n,i))}),i!==void 0&&i._createAssociation(s,this),s}_write(t){t.writeTypeRef(Kc),t.writeKey(this.nodeName)}}const Tc=e=>new q(e.readKey());class Ac extends nn{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 qe extends Gt{constructor(t){super(),this.hookName=t}_copy(){return new qe(this.hookName)}clone(){const t=new qe(this.hookName);return this.forEach((n,i)=>{t.set(i,n)}),t}toDOM(t=document,n={},i){const s=n[this.hookName];let o;return s!==void 0?o=s.createDom(this):o=document.createElement(this.hookName),o.setAttribute("data-yjs-hook",this.hookName),i!==void 0&&i._createAssociation(o,this),o}_write(t){t.writeTypeRef(Yc),t.writeKey(this.hookName)}}const Dc=e=>new qe(e.readKey());class J extends It{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 J}clone(){const t=new J;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,i){const s=t.createTextNode(this.toString());return i!==void 0&&i._createAssociation(s,this),s}toString(){return this.toDelta().map(t=>{const n=[];for(const s in t.attributes){const o=[];for(const r in t.attributes[s])o.push({key:r,value:t.attributes[s][r]});o.sort((r,l)=>r.key<l.key?-1:1),n.push({nodeName:s,attrs:o})}n.sort((s,o)=>s.nodeName<o.nodeName?-1:1);let i="";for(let s=0;s<n.length;s++){const o=n[s];i+=`<${o.nodeName}`;for(let r=0;r<o.attrs.length;r++){const l=o.attrs[r];i+=` ${l.key}="${l.value}"`}i+=">"}i+=t.insert;for(let s=n.length-1;s>=0;s--)i+=`</${n[s].nodeName}>`;return i}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(Gc)}}const Mc=e=>new J;class ii{constructor(t,n){this.id=t,this.length=n}get deleted(){throw lt()}mergeWith(t){return!1}write(t,n,i){throw lt()}integrate(t,n){throw lt()}}const jc=0;class nt extends ii{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),vs(t.doc.store,this)}write(t,n){t.writeInfo(jc),t.writeLen(this.length-n)}getMissing(t,n){return null}}class be{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new be(this.content)}splice(t){throw lt()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}const Oc=e=>new be(e.readBuf());class pe{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new pe(this.len)}splice(t){const n=new pe(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){he(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 Rc=e=>new pe(e.readLen()),qs=(e,t)=>new Lt({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class ye{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 ye(qs(this.doc.guid,this.opts))}splice(t){throw lt()}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 Nc=e=>new ye(qs(e.readString(),e.readAny()));class Ut{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Ut(this.embed)}splice(t){throw lt()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}const Bc=e=>new Ut(e.readJSON());class V{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new V(this.key,this.value)}splice(t){throw lt()}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 Lc=e=>new V(e.readKey(),e.readJSON());class Ke{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Ke(this.arr)}splice(t){const n=new Ke(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const i=this.arr.length;t.writeLen(i-n);for(let s=n;s<i;s++){const o=this.arr[s];t.writeString(o===void 0?"undefined":JSON.stringify(o))}}getRef(){return 2}}const Uc=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 Ke(n)},Pc=Ve("node_env")==="development";class Bt{constructor(t){this.arr=t,Pc&&ls(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Bt(this.arr)}splice(t){const n=new Bt(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const i=this.arr.length;t.writeLen(i-n);for(let s=n;s<i;s++){const o=this.arr[s];t.writeAny(o)}}getRef(){return 8}}const Vc=e=>{const t=e.readLen(),n=[];for(let i=0;i<t;i++)n.push(e.readAny());return new Bt(n)};class at{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new at(this.str)}splice(t){const n=new at(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 Fc=e=>new at(e.readString()),Hc=[bc,Sc,Ec,Tc,Ic,Dc,Mc],$c=0,zc=1,qc=2,Kc=3,Wc=4,Yc=5,Gc=6;class ht{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new ht(this.type._copy())}splice(t){throw lt()}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 Jc=e=>new ht(Hc[e.readTypeRef()](e)),Bn=(e,t)=>{let n=t,i=0,s;do i>0&&(n=_(n.client,n.clock+i)),s=zt(e,n),i=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof D);return{item:s,diff:i}},si=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},We=(e,t,n)=>{const{client:i,clock:s}=t.id,o=new D(_(i,s+n),t,_(i,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&o.markDeleted(),t.keep&&(o.keep=!0),t.redone!==null&&(o.redone=_(t.redone.client,t.redone.clock+n)),t.right=o,o.right!==null&&(o.right.left=o),e._mergeStructs.push(o),o.parentSub!==null&&o.right===null&&o.parent._map.set(o.parentSub,o),t.length=n,o},Pi=(e,t)=>Sr(e,n=>Zt(n.deletions,t)),Ks=(e,t,n,i,s,o)=>{const r=e.doc,l=r.store,c=r.clientID,a=t.redone;if(a!==null)return G(e,a);let h=t.parent._item,d=null,f;if(h!==null&&h.deleted===!0){if(h.redone===null&&(!n.has(h)||Ks(e,h,n,i,s,o)===null))return null;for(;h.redone!==null;)h=G(e,h.redone)}const g=h===null?t.parent:h.content.type;if(t.parentSub===null){for(d=t.left,f=t;d!==null;){let y=d;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:G(e,y.redone);if(y!==null&&y.parent._item===h){d=y;break}d=d.left}for(;f!==null;){let y=f;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:G(e,y.redone);if(y!==null&&y.parent._item===h){f=y;break}f=f.right}}else if(f=null,t.right&&!s){for(d=t;d!==null&&d.right!==null&&(d.right.redone||Zt(i,d.right.id)||Pi(o.undoStack,d.right.id)||Pi(o.redoStack,d.right.id));)for(d=d.right;d.redone;)d=G(e,d.redone);if(d&&d.right!==null)return null}else d=g._map.get(t.parentSub)||null;const m=P(l,c),x=_(c,m),b=new D(x,d,d&&d.lastId,f,f&&f.id,g,t.parentSub,t.content.copy());return t.redone=x,si(b,!0),b.integrate(e,0),b};class D extends ii{constructor(t,n,i,s,o,r,l,c){super(t,c.getLength()),this.origin=i,this.left=n,this.right=s,this.rightOrigin=o,this.parent=r,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?pi:0}set marker(t){(this.info&fn)>0!==t&&(this.info^=fn)}get marker(){return(this.info&fn)>0}get keep(){return(this.info&gi)>0}set keep(t){this.keep!==t&&(this.info^=gi)}get countable(){return(this.info&pi)>0}get deleted(){return(this.info&un)>0}set deleted(t){this.deleted!==t&&(this.info^=un)}markDeleted(){this.info|=un}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=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===$t&&this.id.client!==this.parent.client&&this.parent.clock>=P(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Ai(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=G(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===nt||this.right&&this.right.constructor===nt)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===D?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===D&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===$t){const i=zt(n,this.parent);i.constructor===nt?this.parent=null:this.parent=i.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=Ai(t,t.doc.store,_(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let i=this.left,s;if(i!==null)s=i.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;const o=new Set,r=new Set;for(;s!==null&&s!==this.right;){if(r.add(s),o.add(s),ke(this.origin,s.origin)){if(s.id.client<this.id.client)i=s,o.clear();else if(ke(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&r.has(zt(t.doc.store,s.origin)))o.has(zt(t.doc.store,s.origin))||(i=s,o.clear());else break;s=s.right}this.left=i}if(this.left!==null){const i=this.left.right;this.right=i,this.left.right=this}else{let i;if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start,this.parent._start=this;this.right=i}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),vs(t.doc.store,this),this.content.integrate(t,this),Mi(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new nt(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&&ke(t.origin,this.lastId)&&this.right===t&&ke(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(),he(t.deleteSet,this.id.client,this.id.clock,this.length),Mi(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw X();this.content.gc(t),n?ec(t,this,new nt(this.id,this.length)):this.content=new pe(this.length)}write(t,n){const i=n>0?_(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,o=this.parentSub,r=this.content.getRef()&Xe|(i===null?0:W)|(s===null?0:pt)|(o===null?0:le);if(t.writeInfo(r),i!==null&&t.writeLeftID(i),s!==null&&t.writeRightID(s),i===null&&s===null){const l=this.parent;if(l._item!==void 0){const c=l._item;if(c===null){const a=de(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===$t?(t.writeParentInfo(!1),t.writeLeftID(l)):X();o!==null&&t.writeString(o)}this.content.write(t,n)}}const Ws=(e,t)=>Xc[t&Xe](e),Xc=[()=>{X()},Rc,Uc,Oc,Fc,Bc,Lc,Jc,Vc,Nc,()=>{X()}],Zc=10;class it extends ii{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){X()}write(t,n){t.writeInfo(Zc),A(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const Ys=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Gs="__ $YJS$ __";Ys[Gs]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Ys[Gs]=!0;const Qc=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},ta=/[\uD800-\uDBFF]/,ea=/[\uDC00-\uDFFF]/,na=(e,t)=>{let n=0,i=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&ta.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&&ea.test(e[e.length-i])&&i--,{index:n,remove:e.length-n-i,insert:t.slice(n,t.length-i)}},ia=na,ut=(e,t)=>e>>>t|e<<32-t,sa=e=>ut(e,2)^ut(e,13)^ut(e,22),oa=e=>ut(e,6)^ut(e,11)^ut(e,25),ra=e=>ut(e,7)^ut(e,18)^e>>>3,la=e=>ut(e,17)^ut(e,19)^e>>>10,ca=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]),aa=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class ha{constructor(){const t=new ArrayBuffer(320);this._H=new Uint32Array(t,0,8),this._H.set(aa),this._W=new Uint32Array(t,64,64)}_updateHash(){const t=this._H,n=this._W;for(let d=16;d<64;d++)n[d]=la(n[d-2])+n[d-7]+ra(n[d-15])+n[d-16];let i=t[0],s=t[1],o=t[2],r=t[3],l=t[4],c=t[5],a=t[6],h=t[7];for(let d=0,f,g;d<64;d++)f=h+oa(l)+(l&c^~l&a)+ca[d]+n[d]>>>0,g=sa(i)+(i&s^i&o^s&o)>>>0,h=a,a=c,c=l,l=r+f>>>0,r=o,o=s,s=i,i=f+g>>>0;t[0]+=i,t[1]+=s,t[2]+=o,t[3]+=r,t[4]+=l,t[5]+=c,t[6]+=a,t[7]+=h}digest(t){let n=0;for(;n+56<=t.length;){let r=0;for(;r<16&&n+3<t.length;r++)this._W[r]=t[n++]<<24|t[n++]<<16|t[n++]<<8|t[n++];if(n%64!==0){for(this._W.fill(0,r,16);n<t.length;)this._W[r]|=t[n]<<(3-n%4)*8,n++;this._W[r]|=W<<(3-n%4)*8}this._updateHash()}const i=n%64!==0;this._W.fill(0,0,16);let s=0;for(;n<t.length;s++)for(let r=3;r>=0&&n<t.length;r--)this._W[s]|=t[n++]<<r*8;i||(this._W[s-(n%4===0?0:1)]|=W<<(3-n%4)*8),this._W[14]=t.byteLength/Cr,this._W[15]=t.byteLength*8,this._updateHash();const o=new Uint8Array(32);for(let r=0;r<this._H.length;r++)for(let l=0;l<4;l++)o[r*4+l]=this._H[r]>>>(3-l)*8;return o}}const da=e=>new ha().digest(e),N=new E.PluginKey("y-sync"),mt=new E.PluginKey("y-undo");new E.PluginKey("yjs-cursor");const ua=e=>{for(let n=6;n<e.length;n++)e[n%6]=e[n%6]^e[n];return e.slice(0,6)},fa=e=>yl(ua(da(Sl(e)))),Ye=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!Zt(t.ds,e.id),ga=[{light:"#ecd44433",dark:"#ecd444"}],pa=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){const i=Ot();e.forEach(s=>i.add(s)),t=t.filter(s=>!i.has(s))}e.set(n,el(t))}return e.get(n)},ma=(e,{colors:t=ga,colorMapping:n=new Map,permanentUserData:i=null,onFirstRender:s=()=>{},mapping:o}={})=>{let r=!1;const l=new ba(e,o),c=new E.Plugin({props:{editable:a=>{const h=N.getState(a);return h.snapshot==null&&h.prevSnapshot==null}},key:N,state:{init:(a,h)=>({type:e,doc:e.doc,binding:l,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:t,colorMapping:n,permanentUserData:i}),apply:(a,h)=>{const d=a.getMeta(N);if(d!==void 0){h=Object.assign({},h);for(const f in d)h[f]=d[f]}return h.addToHistory=a.getMeta("addToHistory")!==!1,h.isChangeOrigin=d!==void 0&&!!d.isChangeOrigin,h.isUndoRedoOperation=d!==void 0&&!!d.isChangeOrigin&&!!d.isUndoRedoOperation,l.prosemirrorView!==null&&d!==void 0&&(d.snapshot!=null||d.prevSnapshot!=null)&&hs(0,()=>{l.prosemirrorView!=null&&(d.restore==null?l._renderSnapshot(d.snapshot,d.prevSnapshot,h):(l._renderSnapshot(d.snapshot,d.snapshot,h),delete h.restore,delete h.snapshot,delete h.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),h}},view:a=>(l.initView(a),o==null&&l._forceRerender(),s(),{update:()=>{const h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(r||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(r=!0,h.addToHistory===!1&&!h.isChangeOrigin){const d=mt.getState(a.state),f=d&&d.undoManager;f&&f.stopCapturing()}l.mux(()=>{h.doc.transact(d=>{d.meta.set("addToHistory",h.addToHistory),l._prosemirrorChanged(a.state.doc)},N)})}},destroy:()=>{l.destroy()}})});return c},xa=(e,t,n)=>{if(t!==null&&t.anchor!==null&&t.head!==null)if(t.type==="all")e.setSelection(new E.AllSelection(e.doc));else if(t.type==="node"){const i=re(n.doc,n.type,t.anchor,n.mapping);e.setSelection(wa(e,i))}else{const i=re(n.doc,n.type,t.anchor,n.mapping),s=re(n.doc,n.type,t.head,n.mapping);i!==null&&s!==null&&e.setSelection(E.TextSelection.between(e.doc.resolve(i),e.doc.resolve(s)))}},wa=(e,t)=>{const n=e.doc.resolve(t);return n.nodeAfter?E.NodeSelection.create(e.doc,t):E.TextSelection.near(n)},Ln=(e,t)=>({type:t.selection.jsonID,anchor:Je(t.selection.anchor,e.type,e.mapping),head:Je(t.selection.head,e.type,e.mapping)});class ba{constructor(t,n=new Map){this.type=t,this.prosemirrorView=null,this.mux=Qc(),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=Ln(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()?(cs&&this._domSelectionInView===null&&(hs(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){const t=this.prosemirrorView._root.getSelection();if(t==null||t.anchorNode==null)return!1;const n=this.prosemirrorView._root.createRange();n.setStart(t.anchorNode,t.anchorOffset),n.setEnd(t.focusNode,t.focusOffset),n.getClientRects().length===0&&n.startContainer&&n.collapsed&&n.selectNodeContents(n.startContainer);const s=n.getBoundingClientRect(),o=kl.documentElement;return s.bottom>=0&&s.right>=0&&s.left<=(window.innerWidth||o.clientWidth||0)&&s.top<=(window.innerHeight||o.clientHeight||0)}renderSnapshot(t,n){n||(n=Cs(ws(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(N,{snapshot:t,prevSnapshot:n}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{const t=this.type.toArray().map(i=>Ne(i,this.prosemirrorView.state.schema,this)).filter(i=>i!==null),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new E.Slice(E.Fragment.from(t),0,0));n.setMeta(N,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(n)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{const t=this.beforeTransactionSelection!==null?null:this.prosemirrorView.state.selection,n=this.type.toArray().map(s=>Ne(s,this.prosemirrorView.state.schema,this)).filter(s=>s!==null),i=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new E.Slice(E.Fragment.from(n),0,0));if(t){const s=Kt(vt(t.anchor,0),i.doc.content.size),o=Kt(vt(t.head,0),i.doc.content.size);i.setSelection(E.TextSelection.create(i.doc,s,o))}this.prosemirrorView.dispatch(i.setMeta(N,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(t,n,i){let s=this.doc,o=this.type;if(t||(t=wn(this.doc)),t instanceof Uint8Array||n instanceof Uint8Array)if((!(t instanceof Uint8Array)||!(n instanceof Uint8Array))&&X(),s=new Lt({gc:!1}),jn(s,n),n=wn(s),jn(s,t),t=wn(s),o._item===null){const r=Array.from(this.doc.share.keys()).find(l=>this.doc.share.get(l)===this.type);o=s.getXmlFragment(r)}else{const r=s.store.clients.get(o._item.id.client)??[],l=ct(r,o._item.id.clock);o=r[l].content.type}this.mapping.clear(),this.mux(()=>{s.transact(r=>{const l=i.permanentUserData;l&&l.dss.forEach(d=>{Et(r,d,f=>{})});const c=(d,f)=>{const g=d==="added"?l.getUserByClientId(f.client):l.getUserByDeletedId(f);return{user:g,type:d,color:pa(i.colorMapping,i.colors,g)}},a=Os(o,new Qn(n.ds,t.sv)).map(d=>!d._item.deleted||Ye(d._item,t)||Ye(d._item,n)?Ne(d,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},t,n,c):null).filter(d=>d!==null),h=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new E.Slice(E.Fragment.from(a),0,0));this.prosemirrorView.dispatch(h.setMeta(N,{isChangeOrigin:!0}))},N)})}_typeChanged(t,n){if(this.prosemirrorView==null)return;const i=N.getState(this.prosemirrorView.state);if(t.length===0||i.snapshot!=null||i.prevSnapshot!=null){this.renderSnapshot(i.snapshot,i.prevSnapshot);return}this.mux(()=>{const s=(l,c)=>this.mapping.delete(c);Et(n,n.deleteSet,l=>{if(l.constructor===D){const c=l.content.type;c&&this.mapping.delete(c)}}),n.changed.forEach(s),n.changedParentTypes.forEach(s);const o=this.type.toArray().map(l=>Js(l,this.prosemirrorView.state.schema,this)).filter(l=>l!==null);let r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new E.Slice(E.Fragment.from(o),0,0));xa(r,this.beforeTransactionSelection,this),r=r.setMeta(N,{isChangeOrigin:!0,isUndoRedoOperation:n.origin instanceof Is}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&r.scrollIntoView(),this.prosemirrorView.dispatch(r)})}_prosemirrorChanged(t){this.doc.transact(()=>{Pn(this.doc,this.type,t,this),this.beforeTransactionSelection=Ln(this,this.prosemirrorView.state)},N)}initView(t){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=t,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}}const Js=(e,t,n,i,s,o)=>{const r=n.mapping.get(e);if(r===void 0){if(e instanceof q)return Ne(e,t,n,i,s,o);throw lt()}return r},Ne=(e,t,n,i,s,o)=>{const r=[],l=c=>{var a,h;if(c instanceof q){const d=Js(c,t,n,i,s,o);d!==null&&r.push(d)}else{const d=(h=(a=c._item.right)==null?void 0:a.content)==null?void 0:h.type;d instanceof It&&!d._item.deleted&&d._item.id.client===d.doc.clientID&&(c.applyDelta([{retain:c.length},...d.toDelta()]),d.doc.transact(g=>{d._item.delete(g)}));const f=ya(c,t,n,i,s,o);f!==null&&f.forEach(g=>{g!==null&&r.push(g)})}};i===void 0||s===void 0?e.toArray().forEach(l):Os(e,new Qn(s.ds,i.sv)).forEach(l);try{const c=e.getAttributes(i);i!==void 0&&(Ye(e._item,i)?Ye(e._item,s)||(c.ychange=o?o("added",e._item.id):{type:"added"}):c.ychange=o?o("removed",e._item.id):{type:"removed"});const a=t.node(e.nodeName,c,r);return n.mapping.set(e,a),a}catch{return e.doc.transact(a=>{e._item.delete(a)},N),n.mapping.delete(e),null}},ya=(e,t,n,i,s,o)=>{const r=[],l=e.toDelta(i,s,o);try{for(let c=0;c<l.length;c++){const a=l[c];r.push(t.text(a.insert,Ea(a.attributes,t)))}}catch{return e.doc.transact(a=>{e._item.delete(a)},N),null}return r},Sa=(e,t)=>{const n=new J,i=e.map(s=>({insert:s.text,attributes:Zs(s.marks,t)}));return n.applyDelta(i),t.mapping.set(n,e),n},Ca=(e,t)=>{const n=new q(e.type.name);for(const i in e.attrs){const s=e.attrs[i];s!==null&&i!=="ychange"&&n.setAttribute(i,s)}return n.insert(0,rn(e).map(i=>Un(i,t))),t.mapping.set(n,e),n},Un=(e,t)=>e instanceof Array?Sa(e,t):Ca(e,t),Vi=e=>typeof e=="object"&&e!==null,oi=(e,t)=>{const n=Object.keys(e).filter(s=>e[s]!==null);let i=n.length===Object.keys(t).filter(s=>t[s]!==null).length;for(let s=0;s<n.length&&i;s++){const o=n[s],r=e[o],l=t[o];i=o==="ychange"||r===l||Vi(r)&&Vi(l)&&oi(r,l)}return i},rn=e=>{const t=e.content.content,n=[];for(let i=0;i<t.length;i++){const s=t[i];if(s.isText){const o=[];for(let r=t[i];i<t.length&&r.isText;r=t[++i])o.push(r);i--,n.push(o)}else n.push(s)}return n},Xs=(e,t)=>{const n=e.toDelta();return n.length===t.length&&n.every((i,s)=>i.insert===t[s].text&&os(i.attributes||{}).length===t[s].marks.length&&rs(i.attributes,(o,r)=>{var h;const l=ri(r),c=t[s].marks;return c.find(d=>d.type.name===l)?oi(o,(h=c.find(d=>d.type.name===l))==null?void 0:h.attrs):!1}))},me=(e,t)=>{if(e instanceof q&&!(t instanceof Array)&&Vn(e,t)){const n=rn(t);return e._length===n.length&&oi(e.getAttributes(),t.attrs)&&e.toArray().every((i,s)=>me(i,n[s]))}return e instanceof J&&t instanceof Array&&Xs(e,t)},Ge=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((n,i)=>t[i]===n),Fi=(e,t,n)=>{const i=e.toArray(),s=rn(t),o=s.length,r=i.length,l=Kt(r,o);let c=0,a=0,h=!1;for(;c<l;c++){const d=i[c],f=s[c];if(Ge(n.mapping.get(d),f))h=!0;else if(!me(d,f))break}for(;c+a<l;a++){const d=i[r-a-1],f=s[o-a-1];if(Ge(n.mapping.get(d),f))h=!0;else if(!me(d,f))break}return{equalityFactor:c+a,foundMappedChild:h}},ka=e=>{let t="",n=e._start;const i={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof at?t+=n.content.str:n.content instanceof V&&(i[n.content.key]=null)),n=n.right;return{str:t,nAttrs:i}},va=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:i,str:s}=ka(e),o=t.map(a=>({insert:a.text,attributes:Object.assign({},i,Zs(a.marks,n))})),{insert:r,remove:l,index:c}=ia(s,o.map(a=>a.insert).join(""));e.delete(c,l),e.insert(c,r),e.applyDelta(o.map(a=>({retain:a.insert.length,attributes:a.attributes})))},_a=/(.*)(--[a-zA-Z0-9+/=]{8})$/,ri=e=>{var t;return((t=_a.exec(e))==null?void 0:t[1])??e},Ea=(e,t)=>{const n=[];for(const i in e)n.push(t.mark(ri(i),e[i]));return n},Zs=(e,t)=>{const n={};return e.forEach(i=>{if(i.type.name!=="ychange"){const s=wt(t.isOMark,i.type,()=>!i.type.excludes(i.type));n[s?`${i.type.name}--${fa(i.toJSON())}`:i.type.name]=i.attrs}}),n},Pn=(e,t,n,i)=>{if(t instanceof q&&t.nodeName!==n.type.name)throw new Error("node name mismatch!");if(i.mapping.set(t,n),t instanceof q){const d=t.getAttributes(),f=n.attrs;for(const g in f)f[g]!==null?d[g]!==f[g]&&g!=="ychange"&&t.setAttribute(g,f[g]):t.removeAttribute(g);for(const g in d)f[g]===void 0&&t.removeAttribute(g)}const s=rn(n),o=s.length,r=t.toArray(),l=r.length,c=Kt(o,l);let a=0,h=0;for(;a<c;a++){const d=r[a],f=s[a];if(!Ge(i.mapping.get(d),f))if(me(d,f))i.mapping.set(d,f);else break}for(;h+a+1<c;h++){const d=r[l-h-1],f=s[o-h-1];if(!Ge(i.mapping.get(d),f))if(me(d,f))i.mapping.set(d,f);else break}e.transact(()=>{for(;l-a-h>0&&o-a-h>0;){const f=r[a],g=s[a],m=r[l-h-1],x=s[o-h-1];if(f instanceof J&&g instanceof Array)Xs(f,g)||va(f,g,i),a+=1;else{let b=f instanceof q&&Vn(f,g),y=m instanceof q&&Vn(m,x);if(b&&y){const I=Fi(f,g,i),M=Fi(m,x,i);I.foundMappedChild&&!M.foundMappedChild?y=!1:!I.foundMappedChild&&M.foundMappedChild||I.equalityFactor<M.equalityFactor?b=!1:y=!1}b?(Pn(e,f,g,i),a+=1):y?(Pn(e,m,x,i),h+=1):(i.mapping.delete(t.get(a)),t.delete(a,1),t.insert(a,[Un(g,i)]),a+=1)}}const d=l-a-h;if(l===1&&o===0&&r[0]instanceof J?(i.mapping.delete(r[0]),r[0].delete(0,r[0].length)):d>0&&(t.slice(a,a+d).forEach(f=>i.mapping.delete(f)),t.delete(a,d)),a+h<o){const f=[];for(let g=a;g<o-h;g++)f.push(Un(s[g],i));t.insert(a,f)}},N)},Vn=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,Je=(e,t,n)=>{if(e===0)return xn(t,0,-1);let i=t._first===null?null:t._first.content.type;for(;i!==null&&t!==i;){if(i instanceof J){if(i._length>=e)return xn(i,e,-1);if(e-=i._length,i._item!==null&&i._item.next!==null)i=i._item.next.content.type;else{do i=i._item===null?null:i._item.parent,e--;while(i!==t&&i!==null&&i._item!==null&&i._item.next===null);i!==null&&i!==t&&(i=i._item===null?null:i._item.next.content.type)}}else{const s=(n.get(i)||{nodeSize:0}).nodeSize;if(i._first!==null&&e<s)i=i._first.content.type,e--;else{if(e===1&&i._length===0&&s>1)return new He(i._item===null?null:i._item.id,i._item===null?de(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 He(i._item===null?null:i._item.id,i._item===null?de(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 X();if(e===0&&i.constructor!==J&&i!==t)return Ia(i._item.parent,i._item)}return xn(t,t._length,-1)},Ia=(e,t)=>{let n=null,i=null;return e._item===null?i=de(e):n=_(e._item.id.client,e._item.id.clock),new He(n,i,t.id)},re=(e,t,n,i)=>{const s=Ql(n,e);if(s===null||s.type!==t&&!ue(t,s.type._item))return null;let o=s.type,r=0;if(o.constructor===J)r=s.index;else if(o._item===null||!o._item.deleted){let l=o._first,c=0;for(;c<o._length&&c<s.index&&l!==null;){if(!l.deleted){const a=l.content.type;c++,a instanceof J?r+=a._length:r+=i.get(a).nodeSize}l=l.right}r+=1}for(;o!==t&&o._item!==null;){const l=o._item.parent;if(l._item===null||!l._item.deleted){r+=1;let c=l._first;for(;c!==null;){const a=c.content.type;if(a===o)break;c.deleted||(a instanceof J?r+=a._length:r+=i.get(a).nodeSize),c=c.right}}o=l}return r-1};function Ta(e){const t=e.toArray(),n=i=>{let s;if(i instanceof J)s=i.toDelta().map(r=>{const l={type:"text",text:r.insert};return r.attributes&&(l.marks=Object.keys(r.attributes).map(c=>{const a=r.attributes[c],d={type:ri(c)};return Object.keys(a)&&(d.attrs=a),d})),l});else if(i instanceof q){s={type:i.nodeName};const o=i.getAttributes();Object.keys(o).length&&(s.attrs=o);const r=i.toArray();r.length&&(s.content=r.map(n).flat())}else X();return s};return{type:"doc",content:t.map(n)}}const Aa=e=>{const t=mt.getState(e).undoManager;if(t!=null)return t.undo(),!0},Da=e=>{const t=mt.getState(e).undoManager;if(t!=null)return t.redo(),!0},Ma=new Set(["paragraph"]),ja=(e,t)=>!(e instanceof D)||!(e.content instanceof ht)||!(e.content.type instanceof It||e.content.type instanceof q&&t.has(e.content.type.nodeName))||e.content.type._length===0,Oa=({protectedNodes:e=Ma,trackedOrigins:t=[],undoManager:n=null}={})=>new E.Plugin({key:mt,state:{init:(i,s)=>{const o=N.getState(s),r=n||new Is(o.type,{trackedOrigins:new Set([N].concat(t)),deleteFilter:l=>ja(l,e),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:r,prevSel:null,hasUndoOps:r.undoStack.length>0,hasRedoOps:r.redoStack.length>0}},apply:(i,s,o,r)=>{const l=N.getState(r).binding,c=s.undoManager,a=c.undoStack.length>0,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:Ln(l,o),hasUndoOps:a,hasRedoOps:h}:a!==s.hasUndoOps||h!==s.hasRedoOps?Object.assign({},s,{hasUndoOps:c.undoStack.length>0,hasRedoOps:c.redoStack.length>0}):s}},view:i=>{const s=N.getState(i.state),o=mt.getState(i.state).undoManager;return o.on("stack-item-added",({stackItem:r})=>{const l=s.binding;l&&r.meta.set(l,mt.getState(i.state).prevSel)}),o.on("stack-item-popped",({stackItem:r})=>{const l=s.binding;l&&(l.beforeTransactionSelection=r.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{o.destroy()}}}});function Qs(e){return!!e.getMeta(N)}function Ra(e,t){const n=N.getState(e);return re(n.doc,n.type,t,n.binding.mapping)||0}function to(e,t){const n=N.getState(e);return Je(t,n.type,n.binding.mapping)}var Be=class eo extends E.MappablePosition{constructor(t,n){super(t),this.yRelativePosition=n}static fromJSON(t){return new eo(t.position,t.yRelativePosition)}toJSON(){return{position:this.position,yRelativePosition:this.yRelativePosition}}};function Na(e,t){const n=to(t,e);return new Be(e,n)}function Ba(e,t,n){const i=e instanceof Be?e.yRelativePosition:null;if(Qs(t)&&i){const r=Ra(n,i);return{position:new Be(r,i),mapResult:null}}const s=E.getUpdatedPosition(e,t),o=s.position.position;return{position:new Be(o,i??to(n,o)),mapResult:s.mapResult}}E.Extension.create({name:"collaboration",priority:1e3,addOptions(){return{document:null,field:"default",fragment:null,provider:null}},addStorage(){return{isDisabled:!1}},onCreate(){this.editor.extensionManager.extensions.find(e=>e.name==="undoRedo")&&console.warn('[tiptap warn]: "@tiptap/extension-collaboration" comes with its own history support and is not compatible with "@tiptap/extension-undo-redo".')},onBeforeCreate(){this.editor.utils.getUpdatedPosition=(e,t)=>Ba(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>Na(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),mt.getState(t).undoManager.undoStack.length===0?!1:n?Aa(t):!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),mt.getState(t).undoManager.redoStack.length===0?!1:n?Da(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=Oa(this.options.yUndoOptions),i=n.spec.view;n.spec.view=r=>{const{undoManager:l}=mt.getState(r.state);l.restore&&(l.restore(),l.restore=()=>{});const c=i?i(r):void 0;return{destroy:()=>{const a=l.trackedOrigins.has(l),h=l._observers;l.restore=()=>{a&&l.trackedOrigins.add(l),l.doc.on("afterTransaction",l.afterTransactionHandler),l._observers=h},c!=null&&c.destroy&&c.destroy()}}};const s={...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender},o=ma(t,s);return this.editor.options.enableContentCheck&&((e=t.doc)==null||e.on("beforeTransaction",()=>{try{const r=Ta(t);if(r.content.length===0)return;this.editor.schema.nodeFromJSON(r).check()}catch(r){return this.editor.emit("contentError",{error:r,editor:this.editor,disableCollaboration:()=>{var l;(l=t.doc)==null||l.destroy(),this.storage.isDisabled=!0}}),!1}})),[o,n,this.editor.options.enableContentCheck&&new Y.Plugin({key:new Y.PluginKey("filterInvalidContent"),filterTransaction:()=>{var r;return this.storage.isDisabled!==!1&&((r=t.doc)==null||r.destroy()),!0}})].filter(Boolean)}});function Hi(e){if(!e.length)return hn.DecorationSet.empty;const t=[],n=e[0].$from.node(0);return e.forEach(i=>{const s=i.$from.pos,o=i.$from.nodeAfter;o&&t.push(hn.Decoration.node(s,s+o.nodeSize,{class:"ProseMirror-selectednoderange"}))}),hn.DecorationSet.create(n,t)}function ln(e,t,n){const i=[],s=e.node(0);typeof n=="number"&&n>=0||(e.sameParent(t)?n=Math.max(0,e.sharedDepth(t.pos)-1):n=e.sharedDepth(t.pos));const o=new Eo.NodeRange(e,t,n),r=o.depth===0?0:s.resolve(o.start).posAtIndex(0);return o.parent.forEach((l,c)=>{const a=r+c,h=a+l.nodeSize;if(a<o.start||a>=o.end)return;const d=new Y.SelectionRange(s.resolve(a),s.resolve(h));i.push(d)}),i}var La=class no{constructor(t,n){this.anchor=t,this.head=n}map(t){return new no(t.map(this.anchor),t.map(this.head))}resolve(t){const n=t.resolve(this.anchor),i=t.resolve(this.head);return new Ct(n,i)}},Ct=class yt extends Y.Selection{constructor(t,n,i,s=1){const{doc:o}=t,r=t===n,l=t.pos===o.content.size&&n.pos===o.content.size,c=r&&!l?o.resolve(n.pos+(s>0?1:-1)):n,a=r&&l?o.resolve(t.pos-(s>0?1:-1)):t,h=ln(a.min(c),a.max(c),i),d=c.pos>=t.pos?h[0].$from:h[h.length-1].$to,f=c.pos>=t.pos?h[h.length-1].$to:h[0].$from;super(d,f,h),this.depth=i}get $to(){return this.ranges[this.ranges.length-1].$to}eq(t){return t instanceof yt&&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 yt(i,s)}toJSON(){return{type:"nodeRange",anchor:this.anchor,head:this.head}}get isForwards(){return this.head>=this.anchor}get isBackwards(){return!this.isForwards}extendBackwards(){const{doc:t}=this.$from;if(this.isForwards&&this.ranges.length>1){const s=this.ranges.slice(0,-1),o=s[0].$from,r=s[s.length-1].$to;return new yt(o,r,this.depth)}const n=this.ranges[0],i=t.resolve(Math.max(0,n.$from.pos-1));return new yt(this.$anchor,i,this.depth)}extendForwards(){const{doc:t}=this.$from;if(this.isBackwards&&this.ranges.length>1){const s=this.ranges.slice(1),o=s[0].$from,r=s[s.length-1].$to;return new yt(r,o,this.depth)}const n=this.ranges[this.ranges.length-1],i=t.resolve(Math.min(t.content.size,n.$to.pos+1));return new yt(this.$anchor,i,this.depth)}static fromJSON(t,n){return new yt(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,i,s,o=1){return new this(t.resolve(n),t.resolve(i),s,o)}getBookmark(){return new La(this.anchor,this.head)}};Ct.prototype.visible=!1;function Ie(e){return e instanceof Ct}E.Extension.create({name:"nodeRange",addOptions(){return{depth:void 0,key:"Mod"}},addKeyboardShortcuts(){return{"Shift-ArrowUp":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,selection:o,tr:r}=i,{anchor:l,head:c}=o;if(!Ie(o)){const h=Ct.create(s,l,c,t,-1);return r.setSelection(h),n.dispatch(r),!0}const a=o.extendBackwards();return r.setSelection(a),n.dispatch(r),!0},"Shift-ArrowDown":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,selection:o,tr:r}=i,{anchor:l,head:c}=o;if(!Ie(o)){const h=Ct.create(s,l,c,t);return r.setSelection(h),n.dispatch(r),!0}const a=o.extendForwards();return r.setSelection(a),n.dispatch(r),!0},"Mod-a":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,tr:o}=i,r=Ct.create(s,0,s.content.size,t);return o.setSelection(r),n.dispatch(o),!0}}},onSelectionUpdate(){const{selection:e}=this.editor.state;Ie(e)&&this.editor.view.dom.classList.add("ProseMirror-noderangeselection")},addProseMirrorPlugins(){let e=!1,t=!1;return[new Y.Plugin({key:new Y.PluginKey("nodeRange"),props:{attributes:()=>e?{class:"ProseMirror-noderangeselection"}:{class:""},handleDOMEvents:{mousedown:(n,i)=>{const{key:s}=this.options,o=/Mac/.test(navigator.platform),r=!!i.shiftKey,l=!!i.ctrlKey,c=!!i.altKey,a=!!i.metaKey,h=o?a:l;return(s==null||s==="Shift"&&r||s==="Control"&&l||s==="Alt"&&c||s==="Meta"&&a||s==="Mod"&&h)&&(t=!0),t&&document.addEventListener("mouseup",()=>{t=!1;const{state:d}=n,{doc:f,selection:g,tr:m}=d,{$anchor:x,$head:b}=g;if(x.sameParent(b))return;const y=Ct.create(f,x.pos,b.pos,this.options.depth);m.setSelection(y),n.dispatch(m)},{once:!0}),!1}},decorations:n=>{const{selection:i}=n,s=Ie(i);if(e=!1,!t)return s?(e=!0,Hi(i.ranges)):null;const{$from:o,$to:r}=i;if(!s&&o.sameParent(r))return null;const l=ln(o,r,this.options.depth);return l.length?(e=!0,Hi(l)):null}}})]}});function Ua(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 Pa(e){const t=e.cloneNode(!0),n=[e,...Array.from(e.getElementsByTagName("*"))],i=[t,...Array.from(t.getElementsByTagName("*"))];return n.forEach((s,o)=>{i[o].style.cssText=Ua(s)}),t}function Va(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 Fa(e,t,n,i=5){const s=e.dom,o=s.firstElementChild,r=s.lastElementChild;if(!o||!r)return{x:t,y:n};const l=o.getBoundingClientRect(),c=r.getBoundingClientRect(),a=Math.min(Math.max(l.top+i,n),c.bottom-i),h=.5,d=Math.abs(l.left-c.left)<h,f=Math.abs(l.right-c.right)<h;let g=l;return d&&f&&(g=l),{x:Math.min(Math.max(g.left+i,t),g.right-i),y:a}}var io=e=>{const{x:t,y:n,editor:i}=e,{view:s,state:o}=i,{x:r,y:l}=Fa(s,t,n,5),c=s.root.elementsFromPoint(r,l);let a;if(Array.prototype.some.call(c,f=>{if(!s.dom.contains(f))return!1;const g=Va(f,s);return g?(a=g,!0):!1}),!a)return{resultElement:null,resultNode:null,pos:null};let h;try{h=s.posAtDOM(a,0)}catch{return{resultElement:null,resultNode:null,pos:null}}const d=o.doc.nodeAt(h);if(!d){const f=o.doc.resolve(h),g=f.parent;return{resultElement:a,resultNode:g,pos:f.start()}}return{resultElement:a,resultNode:d,pos:h}};function Te(e,t){return window.getComputedStyle(e)[t]}function Ha(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function $a(e,t,n){const i=parseInt(Te(e.dom,"paddingLeft"),10),s=parseInt(Te(e.dom,"paddingRight"),10),o=parseInt(Te(e.dom,"borderLeftWidth"),10),r=parseInt(Te(e.dom,"borderLeftWidth"),10),l=e.dom.getBoundingClientRect();return{left:Ha(t,l.left+i+o,l.right-s-r),top:n}}function so(e){var t;(t=e.parentNode)==null||t.removeChild(e)}function za(e,t){const{doc:n}=t.view.state,i=io({editor:t,x:e.clientX,y:e.clientY});if(!i.resultNode||i.pos===null)return[];const s=e.clientX,o=$a(t.view,s,e.clientY),r=t.view.posAtCoords(o);if(!r)return[];const{pos:l}=r;if(!n.resolve(l).parent)return[];const a=n.resolve(i.pos),h=n.resolve(i.pos+1);return ln(a,h,0)}function qa(e,t){const{view:n}=t;if(!e.dataTransfer)return;const{empty:i,$from:s,$to:o}=n.state.selection,r=za(e,t),l=ln(s,o,0),c=l.some(b=>r.find(y=>y.$from===b.$from&&y.$to===b.$to)),a=i||!c?r:l;if(!a.length)return;const{tr:h}=n.state,d=document.createElement("div"),f=a[0].$from.pos,g=a[a.length-1].$to.pos,m=Ct.create(n.state.doc,f,g),x=m.content();a.forEach(b=>{const y=n.nodeDOM(b.$from.pos),I=Pa(y);d.append(I)}),d.style.position="absolute",d.style.top="-10000px",document.body.append(d),e.dataTransfer.clearData(),e.dataTransfer.setDragImage(d,0,0),n.dragging={slice:x,move:!0},h.setSelection(m),n.dispatch(h),document.addEventListener("drop",()=>so(d),{once:!0})}var $i=(e,t)=>{const n=e.resolve(t),{depth:i}=n;return i===0?t:n.pos-n.parentOffset-1},zi=(e,t)=>{const n=e.nodeAt(t),i=e.resolve(t);let{depth:s}=i,o=n;for(;s>0;){const r=i.node(s);s-=1,s===0&&(o=r)}return o},Sn=(e,t)=>{const n=N.getState(e);return n?Je(t,n.type,n.binding.mapping):null},Ka=(e,t)=>{const n=N.getState(e);return n?re(n.doc,n.type,t,n.binding.mapping)||0:-1},qi=(e,t)=>{let n=t;for(;n!=null&&n.parentNode&&n.parentNode!==e.dom;)n=n.parentNode;return n},oo=new Y.PluginKey("dragHandle"),ro=({pluginKey:e=oo,element:t,editor:n,computePositionConfig:i,getReferencedVirtualElement:s,onNodeChange:o,onElementDragStart:r,onElementDragEnd:l})=>{const c=document.createElement("div");let a=!1,h=null,d=-1,f,g=null,m=null;function x(){t&&(t.style.visibility="hidden",t.style.pointerEvents="none")}function b(){if(t){if(!n.isEditable){x();return}t.style.visibility="",t.style.pointerEvents="auto"}}function y(k){const B=(s==null?void 0:s())||{getBoundingClientRect:()=>k.getBoundingClientRect()};F.computePosition(B,t,i).then(T=>{Object.assign(t.style,{position:T.strategy,left:`${T.x}px`,top:`${T.y}px`})})}function I(k){r==null||r(k),qa(k,n),t&&(t.dataset.dragging="true"),setTimeout(()=>{t&&(t.style.pointerEvents="none")},0)}function M(k){l==null||l(k),x(),t&&(t.style.pointerEvents="auto",t.dataset.dragging="false")}return t.addEventListener("dragstart",I),t.addEventListener("dragend",M),c.appendChild(t),{unbind(){t.removeEventListener("dragstart",I),t.removeEventListener("dragend",M),g&&(cancelAnimationFrame(g),g=null,m=null)},plugin:new Y.Plugin({key:typeof e=="string"?new Y.PluginKey(e):e,state:{init(){return{locked:!1}},apply(k,B,T,S){const C=k.getMeta("lockDragHandle"),R=k.getMeta("hideDragHandle");if(C!==void 0&&(a=C),R)return x(),a=!1,h=null,d=-1,o==null||o({editor:n,node:null,pos:-1}),B;if(k.docChanged&&d!==-1&&t)if(Qs(k)){const H=Ka(S,f);H!==d&&(d=H)}else{const H=k.mapping.map(d);H!==d&&(d=H,f=Sn(S,d))}return B}},view:k=>{var B;return t.draggable=!0,t.style.pointerEvents="auto",t.dataset.dragging="false",(B=n.view.dom.parentElement)==null||B.appendChild(c),c.style.pointerEvents="none",c.style.position="absolute",c.style.top="0",c.style.left="0",{update(T,S){if(!t)return;if(!n.isEditable){x();return}if(a?t.draggable=!1:t.draggable=!0,k.state.doc.eq(S.doc)||d===-1)return;let C=k.nodeDOM(d);if(C=qi(k,C),C===k.dom||(C==null?void 0:C.nodeType)!==1)return;const R=k.posAtDOM(C,0),H=zi(n.state.doc,R),tt=$i(n.state.doc,R);h=H,d=tt,f=Sn(k.state,d),o==null||o({editor:n,node:h,pos:d}),y(C)},destroy(){g&&(cancelAnimationFrame(g),g=null,m=null),t&&so(c)}}},props:{handleDOMEvents:{keydown(k){return!t||a||k.hasFocus()&&(x(),h=null,d=-1,o==null||o({editor:n,node:null,pos:-1})),!1},mouseleave(k,B){return a||B.target&&!c.contains(B.relatedTarget)&&(x(),h=null,d=-1,o==null||o({editor:n,node:null,pos:-1})),!1},mousemove(k,B){return!t||a||(m={x:B.clientX,y:B.clientY},g)||(g=requestAnimationFrame(()=>{if(g=null,!m)return;const{x:T,y:S}=m;m=null;const C=io({x:T,y:S,editor:n});if(!C.resultElement)return;let R=C.resultElement;if(R=qi(k,R),R===k.dom||(R==null?void 0:R.nodeType)!==1)return;const H=k.posAtDOM(R,0),tt=zi(n.state.doc,H);if(tt!==h){const Tt=$i(n.state.doc,H);h=tt,d=Tt,f=Sn(k.state,d),o==null||o({editor:n,node:h,pos:d}),y(R),b()}})),!1}}}})}},Fn={placement:"left-start",strategy:"absolute"};E.Extension.create({name:"dragHandle",addOptions(){return{render(){const e=document.createElement("div");return e.classList.add("drag-handle"),e},computePositionConfig:{},locked:!1,onNodeChange:()=>null,onElementDragStart:void 0,onElementDragEnd:void 0}},addCommands(){return{lockDragHandle:()=>({editor:e})=>(this.options.locked=!0,e.commands.setMeta("lockDragHandle",this.options.locked)),unlockDragHandle:()=>({editor:e})=>(this.options.locked=!1,e.commands.setMeta("lockDragHandle",this.options.locked)),toggleDragHandle:()=>({editor:e})=>(this.options.locked=!this.options.locked,e.commands.setMeta("lockDragHandle",this.options.locked))}},addProseMirrorPlugins(){const e=this.options.render();return[ro({computePositionConfig:{...Fn,...this.options.computePositionConfig},getReferencedVirtualElement:this.options.getReferencedVirtualElement,element:e,editor:this.editor,onNodeChange:this.options.onNodeChange,onElementDragStart:this.options.onElementDragStart,onElementDragEnd:this.options.onElementDragEnd}).plugin]}});var Wa=e=>{const{className:t="drag-handle",children:n,editor:i,pluginKey:s=oo,onNodeChange:o,onElementDragStart:r,onElementDragEnd:l,computePositionConfig:c=Fn}=e,[a,h]=w.useState(null),d=w.useRef(null);return w.useEffect(()=>{let f=null;return a?i.isDestroyed?()=>{d.current=null}:(d.current||(f=ro({editor:i,element:a,pluginKey:s,computePositionConfig:{...Fn,...c},onElementDragStart:r,onElementDragEnd:l,onNodeChange:o}),d.current=f.plugin,i.registerPlugin(d.current)),()=>{i.unregisterPlugin(s),d.current=null,f&&(f.unbind(),f=null)}):()=>{d.current=null}},[a,i,o,s,c,r,l]),u.jsx("div",{className:t,style:{visibility:"hidden",position:"absolute"},"data-dragging":"false",ref:h,children:n})},Ya=Wa;function Ga(){var T,S,C,R,H,tt,Tt,At;const e=p.useEditorInstance(),t=p.useEditableEditor(),{t:n}=L.useLocale(),[i,s]=w.useState(null),[o,r]=w.useState(-1),[l,c]=w.useState(!1),a=(S=(T=e==null?void 0:e.extensionManager)==null?void 0:T.extensions)==null?void 0:S.some(v=>(v==null?void 0:v.name)===Yi.TextAlign.name),h=(R=(C=e==null?void 0:e.extensionManager)==null?void 0:C.extensions)==null?void 0:R.some(v=>(v==null?void 0:v.name)===ne.Indent.name),d=(tt=(H=e==null?void 0:e.extensionManager)==null?void 0:H.extensions)==null?void 0:tt.some(v=>(v==null?void 0:v.name)===Io.Clear.name);function f(){const v=e.chain();v.setNodeSelection(o).unsetAllMarks(),(i==null?void 0:i.type.name)!=="paragraph"&&v.setParagraph(),v.run()}function g(){e.chain().focus().setNodeSelection(o).run(),document.execCommand("copy")}function m(){e.commands.setNodeSelection(o);const{$anchor:v}=e.state.selection,ft=v.node(1)||e.state.selection.node;e.chain().setMeta("hideDragHandle",!0).insertContentAt(o+((i==null?void 0:i.nodeSize)||0),ft.toJSON()).run()}function x(v){e.commands.setTextAlign(v)}function b(){const v=ne.setNodeIndentMarkup(e.state.tr,o,1);v.setMeta("hideDragHandle",!0),e.view.dispatch&&e.view.dispatch(v)}function y(){const v=ne.setNodeIndentMarkup(e.state.tr,o,-1);e.view.dispatch&&e.view.dispatch(v)}function I(){e.chain().setMeta("hideDragHandle",!0).setNodeSelection(o).deleteSelection().run()}const M=w.useCallback(v=>{v.node&&s(v.node),r(v.pos),requestAnimationFrame(()=>{v.editor.commands.focus()})},[]),k=v=>{var ft;if(v.preventDefault(),o!==-1){const Se=(i==null?void 0:i.nodeSize)||0,Pt=o+Se,li=(i==null?void 0:i.type.name)==="paragraph"&&((ft=i==null?void 0:i.content)==null?void 0:ft.size)===0,lo=li?o+2:Pt+2;e.chain().command(({dispatch:ci,tr:cn,state:ai})=>ci?(li?cn.insertText("/",o,o+1):cn.insert(Pt,ai.schema.nodes.paragraph.create(null,[ai.schema.text("/")])),ci(cn)):!0).focus(lo).run()}};w.useEffect(()=>(l?e.commands.setMeta("lockDragHandle",!0):e.commands.setMeta("lockDragHandle",!1),()=>{e.commands.setMeta("lockDragHandle",!1)}),[l]);const B=v=>{t&&c(v)};return u.jsx(Ya,{className:"richtext-transition-all richtext-duration-200 richtext-ease-out",editor:e,onNodeChange:M,pluginKey:"RichTextBubbleMenuDragHandle",children:u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-0.5",children:[u.jsx(p.ActionButton,{action:k,disabled:!t,icon:"Plus",tooltip:"Insert block"}),u.jsx(p.ActionButton,{disabled:!t,icon:"Grip",tooltip:"Click for options, Hold for drag",action:v=>{v.preventDefault(),v.stopPropagation(),B(!l)}}),u.jsxs(U.DropdownMenu,{onOpenChange:B,open:l,children:[u.jsx(U.DropdownMenuTrigger,{className:"richtext-pointer-events-none"}),u.jsxs(U.DropdownMenuContent,{align:"start",className:"richtext-w-48",hideWhenDetached:!0,side:"bottom",sideOffset:0,children:[u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3 richtext-bg-opacity-10 hover:richtext-bg-red-400 hover:richtext-bg-opacity-20 focus:richtext-bg-red-400 focus:richtext-bg-opacity-30 focus:richtext-text-red-500 dark:hover:richtext-bg-opacity-20 dark:hover:richtext-text-red-500",onClick:I,children:[u.jsx(p.IconComponent,{name:"Trash2"}),u.jsx("span",{children:n("editor.remove")})]}),d?u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:f,children:[u.jsx(p.IconComponent,{name:"PaintRoller"}),u.jsx("span",{children:n("editor.clear.tooltip")})]}):null,u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:g,children:[u.jsx(p.IconComponent,{name:"Clipboard"}),u.jsx("span",{children:n("editor.copyToClipboard")})]}),u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:m,children:[u.jsx(p.IconComponent,{name:"Copy"}),u.jsx("span",{children:n("editor.copy")})]}),a||h?u.jsx(U.DropdownMenuSeparator,{}):null,a?u.jsxs(U.DropdownMenuSub,{children:[u.jsxs(U.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[u.jsx(p.IconComponent,{name:"AlignCenter"}),u.jsx("span",{children:n("editor.textalign.tooltip")})]}),u.jsx(U.DropdownMenuPortal,{children:u.jsxs(U.DropdownMenuSubContent,{children:[u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("left"),children:[u.jsx(p.IconComponent,{name:"AlignLeft"}),u.jsx("span",{children:n("editor.textalign.left.tooltip")})]}),u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("center"),children:[u.jsx(p.IconComponent,{name:"AlignCenter"}),u.jsx("span",{children:n("editor.textalign.center.tooltip")})]}),u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",onClick:()=>x("right"),children:[u.jsx(p.IconComponent,{name:"AlignRight"}),u.jsx("span",{children:n("editor.textalign.right.tooltip")})]})]})})]}):null,h?u.jsxs(U.DropdownMenuSub,{children:[u.jsxs(U.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[u.jsx(p.IconComponent,{name:"IndentIncrease"}),u.jsx("span",{children:n("editor.indent")})]}),u.jsx(U.DropdownMenuPortal,{children:u.jsxs(U.DropdownMenuSubContent,{children:[u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((Tt=i==null?void 0:i.attrs)==null?void 0:Tt.indent)>=ne.IndentProps.max,onClick:b,children:[u.jsx(p.IconComponent,{name:"IndentIncrease"}),u.jsx("span",{children:n("editor.indent.tooltip")})]}),u.jsxs(U.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((At=i==null?void 0:i.attrs)==null?void 0:At.indent)<=ne.IndentProps.min,onClick:y,children:[u.jsx(p.IconComponent,{name:"IndentDecrease"}),u.jsx("span",{children:n("editor.outdent.tooltip")})]})]})})]}):null]})]})]})})}exports.RichTextBubbleCallout=jo;exports.RichTextBubbleColumns=Oo;exports.RichTextBubbleDrawer=Go;exports.RichTextBubbleExcalidraw=Xo;exports.RichTextBubbleIframe=Zo;exports.RichTextBubbleImage=rr;exports.RichTextBubbleImageGif=lr;exports.RichTextBubbleKatex=tr;exports.RichTextBubbleLink=nr;exports.RichTextBubbleMenuDragHandle=Ga;exports.RichTextBubbleMermaid=ur;exports.RichTextBubbleTable=fr;exports.RichTextBubbleText=mr;exports.RichTextBubbleTwitter=xr;exports.RichTextBubbleVideo=cr;
|
|
1
|
+
"use strict";var fr=Object.create;var jn=Object.defineProperty;var pr=Object.getOwnPropertyDescriptor;var gr=Object.getOwnPropertyNames;var mr=Object.getPrototypeOf,xr=Object.prototype.hasOwnProperty;var br=(e,t,n)=>t in e?jn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var wr=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of gr(t))!xr.call(e,s)&&s!==n&&jn(e,s,{get:()=>t[s],enumerable:!(i=pr(t,s))||i.enumerable});return e};var yr=(e,t,n)=>(n=e!=null?fr(mr(e)):{},wr(t||!e||!e.__esModule?jn(n,"default",{value:e,enumerable:!0}):n,e));var Re=(e,t,n)=>br(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),T=require("./index-zig3Dj7A.cjs"),H=require("./index-DUpSE1Gb.cjs"),Y=require("@tiptap/pm/state"),Os=require("./Table-ddU2LSc6.cjs"),js=require("./clsx-BWE7vnna.cjs"),b=require("react"),Rs=require("react-dom"),m=require("./index-BUTn2LY6.cjs"),ae=require("./select-DHjzKkcu.cjs"),Ne=require("./Callout.cjs"),ut=require("./Katex-CIC9ygbL.cjs"),B=require("./index-BqL4vAWE.cjs"),ie=require("./delete-node-CosiBes5.cjs"),qi=require("./Column.cjs");require("./theme.cjs");const Fe=require("./Drawer-DwrlY_lY.cjs"),Ki=require("easydrawer"),Je=require("./shortId-Bfj8TyNr.cjs"),It=require("./separator-BmixLrnJ.cjs"),qt=require("./popover-BcHDZqBt.cjs"),he=require("./Excalidraw.cjs"),Ht=require("./Iframe-C6pBw-AF.cjs"),Sr=require("./ImageGif.cjs"),vr=require("katex"),Xe=require("lucide-react"),Jn=require("./textarea-CasDcv3u.cjs"),Ve=require("./LinkEditBlock-B0ZaACZO.cjs"),Rn=require("@tiptap/pm/view"),kr=require("@tiptap/pm/model"),Cr=require("./Clear.cjs"),ue=require("./Indent-Do-X0AsY.cjs"),Ns=require("./TextAlign.cjs"),L=require("./dropdown-menu-oSKIntXM.cjs"),Xn=require("./Mermaid.cjs"),Er=require("./Bold.cjs"),_r=require("./Code.cjs");require("./index-CJ9pyCM4.cjs");const Tr=require("./Color.cjs"),Dr=require("./Highlight.cjs"),Ir=require("./Italic.cjs"),Ar=require("./SlashCommandNodeView-Ba03hlVZ.cjs"),Mr=require("./Strike.cjs"),Or=require("./TextUnderline.cjs"),Nn=require("./Twitter-BIiR78Jh.cjs");function jr(e,t){const n=Math.min(e.top,t.top),i=Math.max(e.bottom,t.bottom),s=Math.min(e.left,t.left),r=Math.max(e.right,t.right)-s,l=i-n,c=s,a=n;return new DOMRect(c,a,r,l)}var Rr=class{constructor({editor:e,element:t,view:n,pluginKey:i="bubbleMenu",updateDelay:s=250,resizeDelay:o=60,shouldShow:r,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,v=!x.textBetween(p,g).length&&T.isTextSelection(f.selection),C=this.element.contains(document.activeElement);return!(!(h.hasFocus()||C)||y||v||!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=o,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,r&&(this.shouldShow=r),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 o=T.posToDOMRect(this.view,i.from,i.to);let r={getBoundingClientRect:()=>o,getClientRects:()=>[o]};if(i instanceof Y.NodeSelection){let l=this.view.nodeDOM(i.from);const c=l.dataset.nodeViewWrapper?l:l.querySelector("[data-node-view-wrapper]");c&&(l=c),l&&(r={getBoundingClientRect:()=>l.getBoundingClientRect(),getClientRects:()=>[l.getBoundingClientRect()]})}if(i instanceof Os.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():jr(h.getBoundingClientRect(),f.getBoundingClientRect());r={getBoundingClientRect:()=>p,getClientRects:()=>[p]}}return r}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 o,r;if((o=s.hide)!=null&&o.referenceHidden||(r=s.hide)!=null&&r.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)),o=!(t!=null&&t.doc.eq(e.state.doc));this.updateHandler(e,s,o,t)}getShouldShow(e){var t;const{state:n}=this.view,{selection:i}=n,{ranges:s}=i,o=Math.min(...s.map(c=>c.$from.pos)),r=Math.max(...s.map(c=>c.$to.pos));return((t=this.shouldShow)==null?void 0:t.call(this,{editor:this.editor,element:this.element,view:this.view,state:n,oldState:e,from:o,to:r}))||!1}show(){var e;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const t=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(e=t??this.view.dom.parentElement)==null||e.appendChild(this.element),this.floatingUIOptions.onShow&&this.floatingUIOptions.onShow(),this.isVisible=!0}hide(){this.isVisible&&(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.remove(),this.floatingUIOptions.onHide&&this.floatingUIOptions.onHide(),this.isVisible=!1)}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()}},Bs=e=>new Y.Plugin({key:typeof e.pluginKey=="string"?new Y.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Rr({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?[Bs({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 Nr=class{constructor({editor:e,element:t,view:n,pluginKey:i="floatingMenu",updateDelay:s=250,resizeDelay:o=60,options:r,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=o,this.appendTo=l,this.scrollTarget=(a=r==null?void 0:r.scrollTarget)!=null?a:window,this.floatingUIOptions={...this.floatingUIOptions,...r},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,o=Math.min(...s.map(c=>c.$from.pos)),r=Math.max(...s.map(c=>c.$to.pos));return(t=this.shouldShow)==null?void 0:t.call(this,{editor:this.editor,view:this.view,state:n,oldState:e,from:o,to:r})}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:o,middlewareData:r})=>{var l,c;if((l=r.hide)!=null&&l.referenceHidden||(c=r.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=o,this.element.style.left=`${i}px`,this.element.style.top=`${s}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()})}update(e,t){const n=!(t!=null&&t.selection.eq(e.state.selection)),i=!(t!=null&&t.doc.eq(e.state.doc));this.updateHandler(e,n,i,t)}show(){var e;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const t=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(e=t??this.view.dom.parentElement)==null||e.appendChild(this.element),this.floatingUIOptions.onShow&&this.floatingUIOptions.onShow(),this.isVisible=!0}hide(){this.isVisible&&(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.remove(),this.floatingUIOptions.onHide&&this.floatingUIOptions.onHide(),this.isVisible=!1)}destroy(){this.hide(),this.element.removeEventListener("mousedown",this.mousedownHandler,{capture:!0}),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()}},Ls=e=>new Y.Plugin({key:typeof e.pluginKey=="string"?new Y.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Nr({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?[Ls({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})]:[]}});var it=b.forwardRef(({pluginKey:e="bubbleMenu",editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:o=null,getReferencedVirtualElement:r,options:l,children:c,...a},u)=>{const h=b.useRef(document.createElement("div"));typeof u=="function"?u(h.current):u&&(u.current=h.current);const{editor:f}=js.useCurrentEditor(),p=t||f,g={updateDelay:n,resizeDelay:i,appendTo:s,pluginKey:e,shouldShow:o,getReferencedVirtualElement:r,options:l},x=b.useRef(g);x.current=g;const[w,y]=b.useState(!1),v=b.useRef(!0);return b.useEffect(()=>{if(p!=null&&p.isDestroyed)return;if(!p){console.warn("BubbleMenu component is not rendered inside of an editor component or does not have editor prop.");return}const C=h.current;C.style.visibility="hidden",C.style.position="absolute";const M=Bs({...x.current,editor:p,element:C});p.registerPlugin(M);const P=x.current.pluginKey;return v.current=!0,y(!0),()=>{y(!1),p.unregisterPlugin(P),window.requestAnimationFrame(()=>{C.parentNode&&C.parentNode.removeChild(C)})}},[p]),b.useEffect(()=>{if(!(!w||!p||p.isDestroyed)){if(v.current){v.current=!1;return}p.view.dispatch(p.state.tr.setMeta(e,{type:"updateOptions",options:x.current}))}},[w,p,n,i,o,l,s,r]),Rs.createPortal(d.jsx("div",{...a,children:c}),h.current)});b.forwardRef(({pluginKey:e="floatingMenu",editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:o=null,options:r,children:l,...c},a)=>{const u=b.useRef(document.createElement("div"));typeof a=="function"?a(u.current):a&&(a.current=u.current);const{editor:h}=js.useCurrentEditor(),f=t||h,p={updateDelay:n,resizeDelay:i,appendTo:s,pluginKey:e,shouldShow:o,options:r},g=b.useRef(p);g.current=p;const[x,w]=b.useState(!1),y=b.useRef(!0);return b.useEffect(()=>{if(f!=null&&f.isDestroyed)return;if(!f){console.warn("FloatingMenu component is not rendered inside of an editor component or does not have editor prop.");return}const v=u.current;v.style.visibility="hidden",v.style.position="absolute";const C=Ls({...g.current,editor:f,element:v});f.registerPlugin(C);const M=g.current.pluginKey;return y.current=!0,w(!0),()=>{w(!1),f.unregisterPlugin(M),window.requestAnimationFrame(()=>{v.parentNode&&v.parentNode.removeChild(v)})}},[f]),b.useEffect(()=>{if(!(!x||!f||f.isDestroyed)){if(y.current){y.current=!1;return}f.view.dispatch(f.state.tr.setMeta(e,{type:"updateOptions",options:g.current}))}},[x,f,n,i,o,r,s]),Rs.createPortal(d.jsx("div",{...c,children:l}),u.current)});const Br=[{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 Lr(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=B.useLocale(),{type:i,title:s,body:o}=ut.useAttributes(t,Ne.Callout.name,{type:"note",title:"",body:""}),[r,l]=b.useState(!1),[c,a]=b.useState("note"),[u,h]=b.useState(""),[f,p]=b.useState("");b.useEffect(()=>{r&&(a(i||"note"),h(s||""),p(o||""))},[r,i,s,o]);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(()=>{ie.deleteNode(Ne.Callout.name,t)},[t]),y=b.useCallback(()=>t.isActive(Ne.Callout.name),[t]);return e?d.jsx(it,{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:r,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(ae.Select,{onValueChange:a,value:c,children:[d.jsx(ae.SelectTrigger,{children:d.jsx(ae.SelectValue,{className:"richtext-text-accent",placeholder:n("editor.callout.dialog.type.placeholder")})}),d.jsx(ae.SelectContent,{children:Br.map(v=>d.jsx(ae.SelectItem,{value:v.value,children:n(`editor.callout.type.${v.value}`)},v.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:v=>h(v.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:v=>p(v.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 Ur(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=B.useLocale(),i=b.useCallback(()=>t.isActive(qi.MultipleColumnNode.name),[t]),s=b.useCallback(()=>ie.deleteNode(qi.MultipleColumnNode.name,t),[t]),o=b.useCallback(()=>t.chain().focus().addColBefore().run(),[t]),r=b.useCallback(()=>t.chain().focus().addColAfter().run(),[t]),l=b.useCallback(()=>t.chain().focus().deleteCol().run(),[t]);return e?d.jsx(it,{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:o,icon:"ColumnAddLeft",tooltip:n("editor.table.menu.insertColumnBefore")}),d.jsx(m.ActionButton,{action:r,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 Pr(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,o)=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[o],action:()=>e.commands.updateImage({width:B.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:B.IMAGE_SIZE[s]})}}))}function $r(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,o)=>({type:`image-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[o],action:()=>e.commands.updateImageGif({width:B.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:B.IMAGE_SIZE[s]})}}))}function Fr(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 o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImage)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function Vr(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 o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImageGif)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function Hr(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 o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImageMermaid)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function zr(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 o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImageDrawer)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function qr(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 Kr(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,o)=>({type:`video-${s}`,component:m.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[o],action:()=>e.commands.updateVideo({width:B.VIDEO_SIZE[s]}),isActive:()=>e.isActive("video",{width:B.VIDEO_SIZE[s]})}}))}function Wr(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()}}},...Pr(e,t),...Fr(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 Gr(e,t){return[...$r(e,t),...Vr(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 Yr(e,t){return[...Hr(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 Jr(e,t){return[...zr(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 Xr(e,t){return[...Kr(e,t),...qr(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 Zr({editor:e,attrs:t,extension:n}){const[i,s]=b.useState(!1),o=b.useRef(null),r=b.useRef(null),{alt:l,align:c}=t,a=n==null?void 0:n.options.upload,u=()=>{(async()=>{const k=document.querySelector("#easydrawer");k&&(o.current=new Ki.Editor(k,{wheelEventsEnabled:!1,disableZoom:!0}),r.current=Ki.makeDropdownToolbar(o.current),r.current.addDefaultToolWidgets(),o.current.loadFromSVG(decodeURIComponent(l)))})()};b.useEffect(()=>{i&&setTimeout(()=>{u()},200)},[i]);const h=async()=>{if(o.current){const S=o.current.toSVG(),k=S.outerHTML,D=`drawer-${Je.shortId()}.svg`;let z=Je.i(S.outerHTML);if(a){const N=m.dataURLtoFile(z,D);z=await a(N)}e==null||e.chain().focus().setDrawer({type:"drawer",src:z,alt:encodeURIComponent(k),width:426,height:212},!!k).run(),e==null||e.commands.setAlignImageDrawer(c)}s(!1)},f=S=>{const k=o.current.toolController.getPrimaryTools()[2],D=r.current.getWidgetById("pen-1");k&&D&&(k.setColor(S),D.serializeState())},p=S=>{const k=o.current.toolController.getPrimaryTools()[2],D=r.current.getWidgetById("pen-1");k&&D&&(k.setThickness(S),D.serializeState())},g=S=>{const k=o.current.toolController.getPrimaryTools()[3],D=r.current.getWidgetById("pen-2");k&&D&&(k.setColor(S),D.serializeState())},x=S=>{const k=r.current.getWidgetById("shape");k&&k.setShapeType(S)},w=S=>{const k=o.current.toolController.getPrimaryTools()[5],D=r.current.getWidgetById("shape");k&&D&&(k.setColor(S),D.serializeState())},y=S=>{const k=o.current.toolController.getPrimaryTools()[5],D=r.current.getWidgetById("shape");k&&D&&(k.setThickness(S),D.serializeState())},v=S=>{const k=o.current.toolController.getPrimaryTools()[5],D=r.current.getWidgetById("shape");k&&D&&(k.setBorderColor(S),D.serializeState())},C=()=>{if(de){for(;o.current.history.redoStackSize>0;)o.current.history.redo();de=!1;return}o.current.history.undo()},M=()=>{de||o.current.history.redo()},P=()=>{if(!de){for(;o.current.history.undoStackSize>0;)C();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:v,changeColorShape:w,changeShape:x,onClear:P,onRedo:M,onThicknessChange:y,onUndo:C,refEditor:o,setColorHighlight:g,setColorPen:f,setThicknessPen:p})]}),d.jsx(m.DialogFooter,{children:d.jsx(m.Button,{onClick:h,type:"button",children:"Save changes"})})]})]})}function Qr({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?d.jsx(b.Fragment,{children:e.type==="divider"?d.jsx(It.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):d.jsx(i,{...e.componentProps,disabled:t||((s=e==null?void 0:e.componentProps)==null?void 0:s.disabled),editor:n})}):d.jsx(d.Fragment,{})}function tl(){const{lang:e,t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=ut.useAttributes(i,Fe.Drawer.name),o=m.useExtension(Fe.Drawer.name),r=({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(()=>Jr(i,t),[i,e,t]);return n?d.jsx(it,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleDrawer",shouldShow:r,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(Zr,{attrs:s,editor:i,extension:o},`bubbleMenu-drawer-${a}`):d.jsx(Qr,{editor:i,item:c},`bubbleMenu-drawer-${a}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}const Us=({width:e,maxWidth:t,height:n,onOk:i,children:s})=>{const{t:o}=B.useLocale(),[r,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(r)}return d.jsxs(qt.Popover,{modal:!0,children:[d.jsx(qt.PopoverTrigger,{asChild:!0,children:s}),d.jsx(qt.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({...r,width:a.target.value}),required:!0,type:"number",value:r.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({...r,maxWidth:a.target.value}),required:!0,type:"number",value:r.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({...r,height:a.target.value}),required:!0,type:"number",value:r.height})})}),d.jsx(m.Button,{className:"richtext-mt-2 richtext-self-end",type:"submit",children:o("editor.link.dialog.button.apply")})]})})]})},jt=new Map;function el(e){const t=e.options.element;jt.has("width")||jt.set("width",t.clientWidth),jt.has("width")&&jt.get("width")<=0&&jt.set("width",t.clientWidth);const n={attributes:!0,childList:!0,subtree:!0},i=function(){jt.set("width",t.clientWidth)},s=new MutationObserver(i);return s.observe(t,n),e.on("destroy",()=>{s.disconnect()}),{width:jt.get("width")}}function nl(){const e=m.useEditableEditor(),t=m.useEditorInstance(),{t:n}=B.useLocale(),{width:i}=el(t),s=ut.useAttributes(t,he.Excalidraw.name,{defaultShowPicker:!1,createUser:"",width:0,height:0}),{defaultShowPicker:o,createUser:r,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(()=>ie.deleteNode(he.Excalidraw.name,t),[t]);return b.useEffect(()=>{o&&(u(),t.chain().updateAttributes(he.Excalidraw.name,{defaultShowPicker:!1}).focus().run())},[r,o,t,u]),e?d.jsx(it,{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(Us,{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:o}=ut.useAttributes(t,Ht.Iframe.name,{width:0,height:0,src:"",defaultShowPicker:!1}),[r,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(()=>{r&&a(o)},[r,o]);const h=b.useCallback(w=>{var v;(v=w==null?void 0:w.preventDefault)==null||v.call(w);const y=Ht.getServiceSrc(c);t.chain().updateAttributes(Ht.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(o,"_blank")},[o]),p=b.useCallback(w=>{t.chain().updateAttributes(Ht.Iframe.name,w).setNodeSelection(t.state.selection.from).focus().run()},[t]),g=b.useCallback(()=>t.isActive(Ht.Iframe.name)&&!o,[t,o]),x=b.useCallback(()=>ie.deleteNode(Ht.Iframe.name,t),[t]);return e?d.jsx(d.Fragment,{children:d.jsx(it,{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:r,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(Us,{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 sl({children:e,visible:t,toggleVisible:n}){const{t:i}=B.useLocale(),s=m.useEditorInstance(),o=ut.useAttributes(s,ut.Katex.name,{text:"",macros:""}),{text:r,macros:l}=o,[c,a]=b.useState(decodeURIComponent(r||"")),[u,h]=b.useState(decodeURIComponent(l||""));b.useEffect(()=>{t&&(a(decodeURIComponent(r||"")),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 vr.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(Jn.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(Jn.Textarea,{onChange:x=>h(x.target.value),placeholder:"Macros",rows:10,value:u,style:{color:"hsl(var(--foreground))"}})]}),d.jsx("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:g||""},style:{height:"100%",borderWidth:1,minHeight:500,background:"#fff"}})]})}),d.jsx(m.DialogFooter,{children:d.jsx(m.Button,{onClick:f,type:"button",children:"Save changes"})})]})]})}function ol(){const e=m.useEditableEditor(),t=m.useEditorInstance(),[n,i]=b.useState(!1),s=b.useCallback(()=>t.isActive(ut.Katex.name),[t]),o=b.useCallback(()=>ie.deleteNode(ut.Katex.name,t),[t]);return e?d.jsx(it,{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(sl,{toggleVisible:i,visible:n,children:d.jsx(m.ActionButton,{action:()=>i(!n),tooltip:"Edit",children:d.jsx(Xe.Pencil,{size:16})})}),d.jsx(m.ActionButton,{action:o,tooltip:"Delete",children:d.jsx(Xe.Trash2,{size:16})})]})}):d.jsx(d.Fragment,{})}function rl(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 ll(){const e=m.useEditableEditor(),t=m.useEditorInstance(),[n,i]=b.useState(!1),s=ut.useAttributes(t,Ve.Link.name),o=s==null?void 0:s.href,r=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(it,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleLink",shouldShow:r,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(rl,{editor:t,link:o,onClear:c,onEdit:()=>{i(!0)}})})})}):d.jsx(d.Fragment,{})}function mi({item:e,disabled:t,editor:n}){const i=e.component;return i?d.jsx(b.Fragment,{children:e.type==="divider"?d.jsx(It.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 cl(e){return e.type.name===m.Image.name}function al(e){return e.type.name===Sr.ImageGif.name}function hl(e){return e.type.name===m.Video.name}function ul(){const{lang:e,t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:r})=>{const{selection:l}=r.view.state,{$from:c,to:a}=l;let u=!1;return r.view.state.doc.nodesBetween(c.pos,a,h=>{if(cl(h))return u=!0,!1}),u},o=b.useMemo(()=>Wr(i,t),[i,e,t]);return n?d.jsx(it,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImage",shouldShow:s,children:o!=null&&o.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:o==null?void 0:o.map((r,l)=>d.jsx(mi,{editor:i,item:r},`bubbleMenu-image-${l}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function dl(){const{lang:e,t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:r})=>{const{selection:l}=r.view.state,{$from:c,to:a}=l;let u=!1;return r.view.state.doc.nodesBetween(c.pos,a,h=>{if(al(h))return u=!0,!1}),u},o=b.useMemo(()=>Gr(i,t),[i,t,e]);return n?d.jsx(it,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImageGif",shouldShow:s,children:o!=null&&o.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:o==null?void 0:o.map((r,l)=>d.jsx(mi,{editor:i,item:r},`bubbleMenu-image-gif-${l}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function fl(){const{t:e}=B.useLocale(),t=m.useEditableEditor(),n=m.useEditorInstance(),i=({editor:o})=>{const{selection:r}=o.view.state,{$from:l,to:c}=r;let a=!1;return o.view.state.doc.nodesBetween(l.pos,c,u=>{if(hl(u))return a=!0,!1}),a},s=b.useMemo(()=>Xr(n,e),[n,e]);return t?d.jsx(it,{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((o,r)=>d.jsx(mi,{editor:n,item:o},`bubbleMenu-video-${r}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}const Wi=`graph TB
|
|
2
|
+
a-->b`,pl=({editor:e,attrs:t,extension:n})=>{const{alt:i,align:s}=t,[o,r]=b.useState(decodeURIComponent(i??Wi)),[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(C=>{C&&import("mermaid").then(M=>{p(M.default)})},[]),w=async C=>{try{const{svg:M}=await f.render("mermaid-svg",C);c(M)}catch{c("")}},y=()=>{f.initialize({darkMode:!1,startOnLoad:!1,fontSize:12,theme:"base"}),w(o)};b.useEffect(()=>{f&&a&&y()},[f,a]),b.useEffect(()=>{f&&a&&w(o)},[f,o]);const v=async()=>{if(o!==""){if(o){const C=h.current.querySelector("svg"),{width:M,height:P}=C.getBoundingClientRect(),S=`mermaid-${Je.shortId()}.svg`;let k=Je.i(C.outerHTML);if(g){const D=m.dataURLtoFile(k,S);k=await g(D)}e==null||e.chain().focus().setMermaid({type:"mermaid",src:k,alt:encodeURIComponent(o),width:M,height:P},!!o).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(Jn.Textarea,{autoFocus:!0,className:"richtext-flex-1",defaultValue:Wi,onChange:C=>r(C.target.value),placeholder:"Text",required:!0,rows:10,value:o,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:v,type:"button",children:"Save changes"})})]})]})};function gl({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?d.jsx(b.Fragment,{children:e.type==="divider"?d.jsx(It.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 ml(e){return e.type.name===Xn.Mermaid.name}function xl(){const{lang:e,t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=ut.useAttributes(i,Xn.Mermaid.name),o=m.useExtension(Xn.Mermaid.name),r=({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(ml(p))return f=!0,!1}),f},l=b.useMemo(()=>Yr(i,t),[i,e,t]);return n?d.jsx(it,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleMermaid",shouldShow:r,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:o},`bubbleMenu-mermaid-${a}`):d.jsx(gl,{editor:i,item:c},`bubbleMenu-mermaid-${a}`))}):d.jsx(d.Fragment,{})}):d.jsx(d.Fragment,{})}function bl({hiddenActions:e=[]}){var x,w,y,v,C,M,P,S,k,D,z,N,$,G,st,E,yt,je;const{t}=B.useLocale(),n=m.useEditableEditor(),i=m.useEditorInstance(),s=({editor:Vt})=>T.isActive(Vt.view.state,Os.Table.name),o=Vt=>e.includes(Vt);function r(){i.chain().focus().addColumnBefore().run()}function l(){i.chain().focus().addColumnAfter().run()}function c(){i.chain().focus().deleteColumn().run()}function a(){i.chain().focus().addRowBefore().run()}function 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(it,{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:[!o("addColumnBefore")&&d.jsx(m.ActionButton,{action:r,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}}),!o("addColumnAfter")&&d.jsx(m.ActionButton,{action:l,disabled:!((v=(y=i==null?void 0:i.can())==null?void 0:y.addColumnAfter)!=null&&v.call(y)),icon:"BetweenHorizonalStart",tooltip:t("editor.table.menu.insertColumnAfter"),tooltipOptions:{sideOffset:15}}),!o("deleteColumn")&&d.jsx(m.ActionButton,{action:c,disabled:!((M=i==null?void 0:(C=i.can()).deleteColumn)!=null&&M.call(C)),icon:"DeleteColumn",tooltip:t("editor.table.menu.deleteColumn"),tooltipOptions:{sideOffset:15}}),d.jsx(It.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!o("addRowAbove")&&d.jsx(m.ActionButton,{action:a,disabled:!((S=i==null?void 0:(P=i.can()).addRowBefore)!=null&&S.call(P)),icon:"BetweenVerticalEnd",tooltip:t("editor.table.menu.insertRowAbove"),tooltipOptions:{sideOffset:15}}),!o("addRowBelow")&&d.jsx(m.ActionButton,{action:u,disabled:!((D=(k=i==null?void 0:i.can())==null?void 0:k.addRowAfter)!=null&&D.call(k)),icon:"BetweenVerticalStart",tooltip:t("editor.table.menu.insertRowBelow"),tooltipOptions:{sideOffset:15}}),!o("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(It.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!o("mergeCells")&&d.jsx(m.ActionButton,{action:f,disabled:!((G=($=i==null?void 0:i.can())==null?void 0:$.mergeCells)!=null&&G.call($)),icon:"TableCellsMerge",tooltip:t("editor.table.menu.mergeCells"),tooltipOptions:{sideOffset:15}}),!o("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(It.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!o("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 wl(){const{t:e}=B.useLocale(),[t,n]=b.useState(!1),i=m.useEditorInstance(),s=b.useMemo(()=>{var r,l;return(l=(r=Ar.renderCommandListDefault({t:e}))==null?void 0:r[0])==null?void 0:l.commands},[e]),o=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(qt.Popover,{modal:!0,onOpenChange:n,open:t,children:[d.jsx(qt.PopoverTrigger,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:d.jsxs(m.ActionButton,{dataState:!!o,children:[o?d.jsx(d.Fragment,{children:o}):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(qt.PopoverContent,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:s==null?void 0:s.map(r=>{var c;const l=(c=r==null?void 0:r.isActive)==null?void 0:c.call(r,i);return 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(),r.action({editor:i,range:i.state.selection.ranges}),n(!1)},children:[d.jsxs("div",{className:"!richtext-min-w-[20px]",children:[l&&d.jsx(Xe.Check,{size:16}),!o&&r.label===e("editor.paragraph.tooltip")&&!l&&d.jsx(Xe.Check,{size:16})]}),d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:[r.iconName&&d.jsx(m.IconComponent,{className:"!richtext-mr-1 !richtext-text-lg",name:r.iconName}),r.label]})]},r.name)})})]})}function yl(){return d.jsxs(d.Fragment,{children:[d.jsx(wl,{}),d.jsx(It.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(Er.RichTextBold,{}),d.jsx(Ir.RichTextItalic,{}),d.jsx(Or.RichTextUnderline,{}),d.jsx(Mr.RichTextStrike,{}),d.jsx(_r.RichTextCode,{}),d.jsx(Ve.RichTextLink,{}),d.jsx(It.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),d.jsx(Tr.RichTextColor,{}),d.jsx(Dr.RichTextHighlight,{}),d.jsx(Ns.RichTextAlign,{})]})}function Sl({buttonBubble:e}){const t=m.useEditorInstance(),n=m.useEditableEditor(),i=({editor:s})=>{const{selection:o}=s.view.state,{$from:r,to:l}=o;return r.pos===l?!1:o instanceof Y.TextSelection};return n?d.jsx(it,{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(yl,{})})}):d.jsx(d.Fragment,{})}function vl(){const{t:e}=B.useLocale(),t=m.useEditableEditor(),n=m.useEditorInstance(),[i,s]=b.useState(!1),o=b.useCallback(({editor:c})=>c.isActive(Nn.Twitter.name),[]),r=c=>{n.commands.updateTweet({src:c}),s(!1)},l=b.useCallback(()=>ie.deleteNode(Nn.Twitter.name,n),[n]);return t?d.jsx(it,{editor:n,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTwitter",shouldShow:o,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(Nn.FormEditLinkTwitter,{editor:n,onSetLink:r})}):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,Zn=e=>{const t=dt();return e.forEach((n,i)=>{t.set(i,n)}),t},Ct=(e,t,n)=>{let i=e.get(t);return i===void 0&&e.set(t,i=n()),i},kl=(e,t)=>{const n=[];for(const[i,s]of e)n.push(t(s,i));return n},Cl=(e,t)=>{for(const[n,i]of e)if(t(i,n))return!0;return!1},Bt=()=>new Set,Bn=e=>e[e.length-1],El=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},Lt=Array.from,xi=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},bi=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},_l=(e,t)=>{const n=new Array(e);for(let i=0;i<e;i++)n[i]=t(i,n);return n},Xt=Array.isArray;class Ps{constructor(){this._observers=dt()}on(t,n){return Ct(this._observers,t,Bt).add(n),n}once(t,n){const i=(...s)=>{this.off(t,i),n(...s)};this.on(t,i)}off(t,n){const i=this._observers.get(t);i!==void 0&&(i.delete(n),i.size===0&&this._observers.delete(t))}emit(t,n){return Lt((this._observers.get(t)||dt()).values()).forEach(i=>i(...n))}destroy(){this._observers=dt()}}const ft=Math.floor,He=Math.abs,Zt=(e,t)=>e<t?e:t,At=(e,t)=>e>t?e:t,$s=e=>e!==0?e<0:1/e<0,Gi=1,Yi=2,Ln=4,Un=8,me=32,vt=64,tt=128,Tl=1<<29,xn=31,Qn=63,Nt=127,Dl=2147483647,Ze=Number.MAX_SAFE_INTEGER,Ji=Number.MIN_SAFE_INTEGER,Il=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&ft(e)===e),Fs=String.fromCharCode,Al=e=>e.toLowerCase(),Ml=/^\s*/g,Ol=e=>e.replace(Ml,""),jl=/([A-Z])/g,Xi=(e,t)=>Ol(e.replace(jl,n=>`${t}${Al(n)}`)),Rl=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,Nl=e=>xe.encode(e),Bl=xe?Nl:Rl;let pe=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});pe&&pe.decode(new Uint8Array).length===1&&(pe=null);const Ll=(e,t)=>_l(t,()=>e).join("");class De{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Ie=()=>new De,Ul=e=>{const t=Ie();return e(t),ht(t)},Pl=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(Pl(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},$l=(e,t)=>{const n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(At(n,t)*2),e.cpos=0)},q=(e,t)=>{const n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},ti=q,I=(e,t)=>{for(;t>Nt;)q(e,tt|Nt&t),t=ft(t/128);q(e,Nt&t)},wi=(e,t)=>{const n=$s(t);for(n&&(t=-t),q(e,(t>Qn?tt:0)|(n?vt:0)|Qn&t),t=ft(t/64);t>0;)q(e,(t>Nt?tt:0)|Nt&t),t=ft(t/128)},ei=new Uint8Array(3e4),Fl=ei.length/3,Vl=(e,t)=>{if(t.length<Fl){const n=xe.encodeInto(t,ei).written||0;I(e,n);for(let i=0;i<n;i++)q(e,ei[i])}else ot(e,Bl(t))},Hl=(e,t)=>{const n=unescape(encodeURIComponent(t)),i=n.length;I(e,i);for(let s=0;s<i;s++)q(e,n.codePointAt(s))},Kt=xe&&xe.encodeInto?Vl:Hl,bn=(e,t)=>{const n=e.cbuf.length,i=e.cpos,s=Zt(n-i,t.length),o=t.length-s;e.cbuf.set(t.subarray(0,s),i),e.cpos+=s,o>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(At(n*2,o)),e.cbuf.set(t.subarray(s)),e.cpos=o)},ot=(e,t)=>{I(e,t.byteLength),bn(e,t)},yi=(e,t)=>{$l(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},zl=(e,t)=>yi(e,4).setFloat32(0,t,!1),ql=(e,t)=>yi(e,8).setFloat64(0,t,!1),Kl=(e,t)=>yi(e,8).setBigInt64(0,t,!1),Zi=new DataView(new ArrayBuffer(4)),Wl=e=>(Zi.setFloat32(0,e),Zi.getFloat32(0)===e),Qt=(e,t)=>{switch(typeof t){case"string":q(e,119),Kt(e,t);break;case"number":Il(t)&&He(t)<=Dl?(q(e,125),wi(e,t)):Wl(t)?(q(e,124),zl(e,t)):(q(e,123),ql(e,t));break;case"bigint":q(e,122),Kl(e,t);break;case"object":if(t===null)q(e,126);else if(Xt(t)){q(e,117),I(e,t.length);for(let n=0;n<t.length;n++)Qt(e,t[n])}else if(t instanceof Uint8Array)q(e,116),ot(e,t);else{q(e,118);const n=Object.keys(t);I(e,n.length);for(let i=0;i<n.length;i++){const s=n[i];Kt(e,s),Qt(e,t[s])}}break;case"boolean":q(e,t?120:121);break;default:q(e,127)}};class Qi extends De{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 ts=e=>{e.count>0&&(wi(e.encoder,e.count===1?e.s:-e.s),e.count>1&&I(e.encoder,e.count-2))};class ze{constructor(){this.encoder=new De,this.s=0,this.count=0}write(t){this.s===t?this.count++:(ts(this),this.count=1,this.s=t)}toUint8Array(){return ts(this),ht(this.encoder)}}const es=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);wi(e.encoder,t),e.count>1&&I(e.encoder,e.count-2)}};class Pn{constructor(){this.encoder=new De,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(es(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return es(this),ht(this.encoder)}}class Gl{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 De;return this.sarr.push(this.s),this.s="",Kt(t,this.sarr.join("")),bn(t,this.lensE.toUint8Array()),ht(t)}}const wt=e=>new Error(e),ct=()=>{throw wt("Method unimplemented")},Z=()=>{throw wt("Unexpected case")},Vs=wt("Unexpected end of array"),Hs=wt("Integer out of Range");class wn{constructor(t){this.arr=t,this.pos=0}}const Si=e=>new wn(e),Yl=e=>e.pos!==e.arr.length,Jl=(e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},rt=e=>Jl(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&Nt)*n,n*=128,s<tt)return t;if(t>Ze)throw Hs}throw Vs},vi=e=>{let t=e.arr[e.pos++],n=t&Qn,i=64;const s=(t&vt)>0?-1:1;if((t&tt)===0)return s*n;const o=e.arr.length;for(;e.pos<o;){if(t=e.arr[e.pos++],n=n+(t&Nt)*i,i*=128,t<tt)return s*n;if(n>Ze)throw Hs}throw Vs},Xl=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))}},Zl=e=>pe.decode(rt(e)),ni=pe?Zl:Xl,ki=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},Ql=e=>ki(e,4).getFloat32(0,!1),tc=e=>ki(e,8).getFloat64(0,!1),ec=e=>ki(e,8).getBigInt64(0,!1),nc=[e=>{},e=>null,vi,Ql,tc,ec,e=>!1,e=>!0,ni,e=>{const t=j(e),n={};for(let i=0;i<t;i++){const s=ni(e);n[s]=Qe(e)}return n},e=>{const t=j(e),n=[];for(let i=0;i<t;i++)n.push(Qe(e));return n},rt],Qe=e=>nc[127-be(e)](e);class ns extends wn{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Yl(this)?this.count=j(this)+1:this.count=-1),this.count--,this.s}}class qe extends wn{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=vi(this);const t=$s(this.s);this.count=1,t&&(this.s=-this.s,this.count=j(this)+2)}return this.count--,this.s}}class $n extends wn{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=vi(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 qe(t),this.str=ni(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 sc=crypto.getRandomValues.bind(crypto),oc=Math.random,zs=()=>sc(new Uint32Array(1))[0],rc=e=>e[ft(oc()*e.length)],lc="10000000-1000-4000-8000"+-1e11,cc=()=>lc.replace(/[018]/g,e=>(e^zs()&15>>e/4).toString(16)),ac=Date.now,is=e=>new Promise(e);Promise.all.bind(Promise);const ss=e=>e===void 0?null:e;class hc{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}}let qs=new hc,uc=!0;try{typeof localStorage<"u"&&localStorage&&(qs=localStorage,uc=!1)}catch{}const dc=qs,we=Symbol("Equality"),Ks=(e,t)=>{var n;return e===t||!!((n=e==null?void 0:e[we])!=null&&n.call(e,t))||!1},fc=e=>typeof e=="object",pc=Object.assign,Ws=Object.keys,gc=(e,t)=>{for(const n in e)t(e[n],n)},tn=e=>Ws(e).length,mc=e=>{for(const t in e)return!1;return!0},se=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},Ci=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),xc=(e,t)=>e===t||tn(e)===tn(t)&&se(e,(n,i)=>(n!==void 0||Ci(t,i))&&Ks(t[i],n)),bc=Object.freeze,Gs=e=>{for(const t in e){const n=e[t];(typeof n=="object"||typeof n=="function")&&Gs(e[t])}return bc(e)},Ei=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Ei(e,t,n+1)}},Ke=(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)||!Ke(e.get(n),t.get(n)))return!1;break}case void 0:case Object:if(tn(e)!==tn(t))return!1;for(const n in e)if(!Ci(e,n)||!Ke(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(!Ke(e[n],t[n]))return!1;break;default:return!1}return!0},wc=(e,t)=>t.includes(e),te=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",Ys=typeof window<"u"&&typeof document<"u"&&!te;let xt;const yc=()=>{if(xt===void 0)if(te){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(`--${Xi(t,"-")}`,n),xt.set(`-${Xi(t,"-")}`,n)}})):xt=dt();return xt},ii=e=>yc().has(e),en=e=>ss(te?process.env[e.toUpperCase().replaceAll("-","_")]:dc.getItem(e)),Js=e=>ii("--"+e)||en(e)!==null,Sc=Js("production"),vc=te&&wc(process.env.FORCE_COLOR,["true","1","2"]),kc=vc||!ii("--no-colors")&&!Js("no-color")&&(!te||process.stdout.isTTY)&&(!te||ii("--color")||en("COLORTERM")!==null||(en("TERM")||"").includes("color")),Cc=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=Fs(e[n]);return btoa(t)},Ec=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),_c=Ys?Cc:Ec,Tc=e=>Ul(t=>Qt(t,e));class Dc{constructor(t,n){this.left=t,this.right=n}}const St=(e,t)=>new Dc(e,t),os=e=>e.next()>=.5,Fn=(e,t,n)=>ft(e.next()*(n+1-t)+t),Xs=(e,t,n)=>ft(e.next()*(n+1-t)+t),_i=(e,t,n)=>Xs(e,t,n),Ic=e=>Fs(_i(e,97,122)),Ac=(e,t=0,n=20)=>{const i=_i(e,t,n);let s="";for(let o=0;o<i;o++)s+=Ic(e);return s},Vn=(e,t)=>t[_i(e,0,t.length-1)],Mc=Symbol("0schema");class Oc{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(Ll(" ",(this._rerrs.length-n)*2)+`${i.path!=null?`[${i.path}] `:""}${i.has} doesn't match ${i.expected}. ${i.message}`)}return t.join(`
|
|
3
|
+
`)}}const si=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[we]?Ks(e,t):Xt(e)?xi(e,n=>bi(t,i=>si(n,i))):fc(e)?se(e,(n,i)=>si(n,t[i])):!1;class Q{extends(t){let[n,i]=[this.shape,t.shape];return this.constructor._dilutes&&([i,n]=[n,i]),si(n,i)}equals(t){return this.constructor===t.constructor&&Ke(this.shape,t.shape)}[Mc](){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 to(this)}cast(t){return rs(t,this),t}expect(t){return rs(t,this),t}}Re(Q,"_dilutes",!1);class Ti 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 Ti(e,t);V(Ti);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 W=e=>new Di(e);V(Di);class yn 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 Sn=(...e)=>new yn(e),Zs=V(yn),jc=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,t=>"\\"+t)),Qs=e=>{if(ee.check(e))return[jc(e)];if(Zs.check(e))return e.shape.map(t=>t+"");if(ao.check(e))return["[+-]?\\d+.?\\d*"];if(ho.check(e))return[".*"];if(sn.check(e))return e.shape.map(Qs).flat(1);Z()};class Rc extends Q{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(Qs).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(Rc);const Nc=Symbol("optional");class to 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[Nc](){return!0}}const Bc=V(to);class Lc extends Q{check(t,n){return n==null||n.extend(null,"never",typeof t),!1}}V(Lc);const mn=class mn extends Q{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}get partial(){return new mn(this.shape,!0)}check(t,n){return t==null?(n==null||n.extend(null,"object","null"),!1):se(this.shape,(i,s)=>{const o=this._isPartial&&!Ci(t,s)||i.check(t[s],n);return!o&&(n==null||n.extend(s.toString(),i.toString(),typeof t[s],"Object property does not match")),o})}};Re(mn,"_dilutes",!0);let nn=mn;const Uc=e=>new nn(e),Pc=V(nn),$c=W(e=>e!=null&&(e.constructor===Object||e.constructor==null));class eo extends Q{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return t!=null&&se(t,(i,s)=>{const o=this.shape.keys.check(s,n);return!o&&(n==null||n.extend(s+"","Record",typeof t,o?"Key doesn't match schema":"Value doesn't match value")),o&&this.shape.values.check(i,n)})}}const no=(e,t)=>new eo(e,t),Fc=V(eo);class io extends Q{constructor(t){super(),this.shape=t}check(t,n){return t!=null&&se(this.shape,(i,s)=>{const o=i.check(t[s],n);return!o&&(n==null||n.extend(s.toString(),"Tuple",typeof i)),o})}}const Vc=(...e)=>new io(e);V(io);class so extends Q{constructor(t){super(),this.shape=t.length===1?t[0]:new vn(t)}check(t,n){const i=Xt(t)&&xi(t,s=>this.shape.check(s));return!i&&(n==null||n.extend(null,"Array","")),i}}const oo=(...e)=>new so(e),Hc=V(so),zc=W(e=>Xt(e));class ro 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 qc=(e,t=null)=>new ro(e,t);V(ro);const Kc=qc(Q);class Wc extends Q{constructor(t){super(),this.len=t.length-1,this.args=Vc(...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 Gc=V(Wc),Yc=W(e=>typeof e=="function");class Jc extends Q{constructor(t){super(),this.shape=t}check(t,n){const i=xi(this.shape,s=>s.check(t,n));return!i&&(n==null||n.extend(null,"Intersectinon",typeof t)),i}}V(Jc,e=>e.shape.length>0);class vn extends Q{constructor(t){super(),this.shape=t}check(t,n){const i=bi(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=>sn.check(t))>=0?oe(...e.map(t=>ye(t)).map(t=>sn.check(t)?t.shape:[t]).flat(1)):e.length===1?e[0]:new vn(e),sn=V(vn),lo=()=>!0,on=W(lo),Xc=V(Di,e=>e.shape===lo),Ii=W(e=>typeof e=="bigint"),Zc=W(e=>e===Ii),co=W(e=>typeof e=="symbol");W(e=>e===co);const Wt=W(e=>typeof e=="number"),ao=W(e=>e===Wt),ee=W(e=>typeof e=="string"),ho=W(e=>e===ee),kn=W(e=>typeof e=="boolean"),Qc=W(e=>e===kn),uo=Sn(void 0);V(yn,e=>e.shape.length===1&&e.shape[0]===void 0);Sn(void 0);const Cn=Sn(null),ta=V(yn,e=>e.shape.length===1&&e.shape[0]===null);V(Uint8Array);V(Ti,e=>e.shape===Uint8Array);const ea=oe(Wt,ee,Cn,uo,Ii,kn,co);(()=>{const e=oo(on),t=no(ee,on),n=oe(Wt,ee,Cn,kn,e,t);return e.shape=n,t.shape.values=n,n})();const ye=e=>{if(Kc.check(e))return e;if($c.check(e)){const t={};for(const n in e)t[n]=ye(e[n]);return Uc(t)}else{if(zc.check(e))return oe(...e.map(ye));if(ea.check(e))return Sn(e);if(Yc.check(e))return V(e)}Z()},rs=Sc?()=>{}:(e,t)=>{const n=new Oc;if(!t.check(e,n))throw wt(`Expected value to be of type ${t.constructor.name}.
|
|
4
|
+
${n.toString()}`)};class na{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(on,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 ia=e=>new na(e),fo=ia(on).if(ao,(e,t)=>Fn(t,Ji,Ze)).if(ho,(e,t)=>Ac(t)).if(Qc,(e,t)=>os(t)).if(Zc,(e,t)=>BigInt(Fn(t,Ji,Ze))).if(sn,(e,t)=>zt(t,Vn(t,e.shape))).if(Pc,(e,t)=>{const n={};for(const i in e.shape){let s=e.shape[i];if(Bc.check(s)){if(os(t))continue;s=s.shape}n[i]=fo(s,t)}return n}).if(Hc,(e,t)=>{const n=[],i=Xs(t,0,42);for(let s=0;s<i;s++)n.push(zt(t,e.shape));return n}).if(Zs,(e,t)=>Vn(t,e.shape)).if(ta,(e,t)=>null).if(Gc,(e,t)=>{const n=zt(t,e.res);return()=>n}).if(Xc,(e,t)=>zt(t,Vn(t,[Wt,ee,Cn,uo,Ii,kn,oo(Wt),no(oe("a","b","c"),Wt)]))).if(Fc,(e,t)=>{const n={},i=Fn(t,0,3);for(let s=0;s<i;s++){const o=zt(t,e.shape.keys),r=zt(t,e.shape.values);n[o]=r}return n}).done(),zt=(e,t)=>fo(ye(t),e),Ae=typeof document<"u"?document:{};W(e=>e.nodeType===ca);typeof DOMParser<"u"&&new DOMParser;W(e=>e.nodeType===oa);W(e=>e.nodeType===ra);const sa=e=>kl(e,(t,n)=>`${n}:${t};`).join(""),oa=Ae.ELEMENT_NODE,ra=Ae.TEXT_NODE,la=Ae.DOCUMENT_NODE,ca=Ae.DOCUMENT_FRAGMENT_NODE;W(e=>e.nodeType===la);const aa=e=>class{constructor(n){this._=n}destroy(){e(this._)}},ha=aa(clearTimeout),po=(e,t)=>new ha(setTimeout(t,e)),Et=Symbol,go=Et(),mo=Et(),ua=Et(),da=Et(),fa=Et(),xo=Et(),pa=Et(),Ai=Et(),ga=Et(),ma=e=>{var s;e.length===1&&((s=e[0])==null?void 0:s.constructor)===Function&&(e=e[0]());const t=[],n=[];let i=0;for(;i<e.length;i++){const o=e[i];if(o===void 0)break;if(o.constructor===String||o.constructor===Number)t.push(o);else if(o.constructor===Object)break}for(i>0&&n.push(t.join(""));i<e.length;i++){const o=e[i];o instanceof Symbol||n.push(o)}return n},xa={[go]:St("font-weight","bold"),[mo]:St("font-weight","normal"),[ua]:St("color","blue"),[fa]:St("color","green"),[da]:St("color","grey"),[xo]:St("color","red"),[pa]:St("color","purple"),[Ai]:St("color","orange"),[ga]:St("color","black")},ba=e=>{var r;e.length===1&&((r=e[0])==null?void 0:r.constructor)===Function&&(e=e[0]());const t=[],n=[],i=dt();let s=[],o=0;for(;o<e.length;o++){const l=e[o],c=xa[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=sa(i);o>0||a.length>0?(t.push("%c"+l),n.push(a)):t.push(l)}else break}}for(o>0&&(s=n,s.unshift(t.join("")));o<e.length;o++){const l=e[o];l instanceof Symbol||s.push(l)}return s},bo=kc?ba:ma,wa=(...e)=>{console.log(...bo(e)),yo.forEach(t=>t.print(e))},wo=(...e)=>{console.warn(...bo(e)),e.unshift(Ai),yo.forEach(t=>t.print(e))},yo=Bt(),So=e=>({[Symbol.iterator](){return this},next:e}),ya=(e,t)=>So(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),Hn=(e,t)=>So(()=>{const{done:n,value:i}=e.next();return{done:n,value:n?void 0:t(i)}});class Mi{constructor(t,n){this.clock=t,this.len=n}}class re{constructor(){this.clients=new Map}}const Mt=(e,t,n)=>t.clients.forEach((i,s)=>{const o=e.doc.store.clients.get(s);if(o!=null){const r=o[o.length-1],l=r.id.clock+r.length;for(let c=0,a=i[c];c<i.length&&a.clock<l;a=i[++c])Io(e,o,a.clock,a.len,n)}}),Sa=(e,t)=>{let n=0,i=e.length-1;for(;n<=i;){const s=ft((n+i)/2),o=e[s],r=o.clock;if(r<=t){if(t<r+o.len)return s;n=s+1}else i=s-1}return null},le=(e,t)=>{const n=e.clients.get(t.client);return n!==void 0&&Sa(n,t.clock)!==null},Oi=e=>{e.clients.forEach(t=>{t.sort((s,o)=>s.clock-o.clock);let n,i;for(n=1,i=1;n<t.length;n++){const s=t[i-1],o=t[n];s.clock+s.len>=o.clock?s.len=At(s.len,o.clock+o.len-s.clock):(i<n&&(t[i]=o),i++)}t.length=i})},oi=e=>{const t=new re;for(let n=0;n<e.length;n++)e[n].clients.forEach((i,s)=>{if(!t.clients.has(s)){const o=i.slice();for(let r=n+1;r<e.length;r++)El(o,e[r].clients.get(s)||[]);t.clients.set(s,o)}});return Oi(t),t},Se=(e,t,n,i)=>{Ct(e.clients,t,()=>[]).push(new Mi(n,i))},vo=()=>new re,va=e=>{const t=vo();return e.clients.forEach((n,i)=>{const s=[];for(let o=0;o<n.length;o++){const r=n[o];if(r.deleted){const l=r.id.clock;let c=r.length;if(o+1<n.length)for(let a=n[o+1];o+1<n.length&&a.deleted;a=n[++o+1])c+=a.length;s.push(new Mi(l,c))}}s.length>0&&t.clients.set(i,s)}),t},ji=(e,t)=>{I(e.restEncoder,t.clients.size),Lt(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 o=0;o<s;o++){const r=i[o];e.writeDsClock(r.clock),e.writeDsLen(r.len)}})},ka=e=>{const t=new re,n=j(e.restDecoder);for(let i=0;i<n;i++){e.resetDsCurVal();const s=j(e.restDecoder),o=j(e.restDecoder);if(o>0){const r=Ct(t.clients,s,()=>[]);for(let l=0;l<o;l++)r.push(new Mi(e.readDsClock(),e.readDsLen()))}}return t},ls=(e,t,n)=>{const i=new re,s=j(e.restDecoder);for(let o=0;o<s;o++){e.resetDsCurVal();const r=j(e.restDecoder),l=j(e.restDecoder),c=n.clients.get(r)||[],a=U(n,r);for(let u=0;u<l;u++){const h=e.readDsClock(),f=h+e.readDsLen();if(h<a){a<f&&Se(i,r,a,f-a);let p=pt(c,h),g=c[p];for(!g.deleted&&g.id.clock<h&&(c.splice(p+1,0,dn(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,dn(t,g,f-g.id.clock)),g.delete(t))}else Se(i,r,h,f-h)}}if(i.clients.size>0){const o=new En;return I(o.restEncoder,0),ji(o,i),o.toUint8Array()}return null},ko=zs;class $t extends Ps{constructor({guid:t=cc(),collectionid:n=null,gc:i=!0,gcFilter:s=()=>!0,meta:o=null,autoLoad:r=!1,shouldLoad:l=!0}={}){super(),this.gc=i,this.gcFilter=s,this.clientID=ko(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new To,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=r,this.meta=o,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=is(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const c=()=>is(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(Lt(this.subdocs).map(t=>t.guid))}transact(t,n=null){return O(this,t,n)}get(t,n=K){const i=Ct(this.share,t,()=>{const o=new n;return o._integrate(this,null),o}),s=i.constructor;if(n!==K&&s!==n)if(s===K){const o=new n;o._map=i._map,i._map.forEach(r=>{for(;r!==null;r=r.left)r.parent=o}),o._start=i._start;for(let r=o._start;r!==null;r=r.right)r.parent=o;return o._length=i._length,this.share.set(t,o),o._integrate(this,null),o}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return i}getArray(t=""){return this.get(t,Jt)}getText(t=""){return this.get(t,Ot)}getMap(t=""){return this.get(t,ne)}getXmlElement(t=""){return this.get(t,J)}getXmlFragment(t=""){return this.get(t,Ut)}toJSON(){const t={};return this.share.forEach((n,i)=>{t[i]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,Lt(this.subdocs).forEach(n=>n.destroy());const t=this._item;if(t!==null){this._item=null;const n=t.content;n.doc=new $t({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 Ca{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 Ca{constructor(t){super(t),this.keys=[],j(t),this.keyClockDecoder=new $n(rt(t)),this.clientDecoder=new qe(rt(t)),this.leftClockDecoder=new $n(rt(t)),this.rightClockDecoder=new $n(rt(t)),this.infoDecoder=new ns(rt(t),be),this.stringDecoder=new ic(rt(t)),this.parentInfoDecoder=new ns(rt(t),be),this.typeRefDecoder=new qe(rt(t)),this.lenDecoder=new qe(rt(t))}readLeftID(){return new Gt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Gt(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 Qe(this.restDecoder)}readBuf(){return rt(this.restDecoder)}readJSON(){return Qe(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 Ea{constructor(){this.restEncoder=Ie()}toUint8Array(){return ht(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){I(this.restEncoder,t)}writeDsLen(t){I(this.restEncoder,t)}}class _a extends Ea{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){ti(this.restEncoder,t)}writeString(t){Kt(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){Qt(this.restEncoder,t)}writeBuf(t){ot(this.restEncoder,t)}writeJSON(t){Kt(this.restEncoder,JSON.stringify(t))}writeKey(t){Kt(this.restEncoder,t)}}class Ta{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 Ta{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Pn,this.clientEncoder=new ze,this.leftClockEncoder=new Pn,this.rightClockEncoder=new Pn,this.infoEncoder=new Qi(ti),this.stringEncoder=new Gl,this.parentInfoEncoder=new Qi(ti),this.typeRefEncoder=new ze,this.lenEncoder=new ze}toUint8Array(){const t=Ie();return I(t,0),ot(t,this.keyClockEncoder.toUint8Array()),ot(t,this.clientEncoder.toUint8Array()),ot(t,this.leftClockEncoder.toUint8Array()),ot(t,this.rightClockEncoder.toUint8Array()),ot(t,ht(this.infoEncoder)),ot(t,this.stringEncoder.toUint8Array()),ot(t,ht(this.parentInfoEncoder)),ot(t,this.typeRefEncoder.toUint8Array()),ot(t,this.lenEncoder.toUint8Array()),bn(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){Qt(this.restEncoder,t)}writeBuf(t){ot(this.restEncoder,t)}writeJSON(t){Qt(this.restEncoder,t)}writeKey(t){const n=this.keyMap.get(t);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}}const Da=(e,t,n,i)=>{i=At(i,t[0].id.clock);const s=pt(t,i);I(e.restEncoder,t.length-s),e.writeClient(n),I(e.restEncoder,i);const o=t[s];o.write(e,i-o.id.clock);for(let r=s+1;r<t.length;r++)t[r].write(e,0)},Co=(e,t,n)=>{const i=new Map;n.forEach((s,o)=>{U(t,o)>s&&i.set(o,s)}),_n(t).forEach((s,o)=>{n.has(o)||i.set(o,0)}),I(e.restEncoder,i.size),Lt(i.entries()).sort((s,o)=>o[0]-s[0]).forEach(([s,o])=>{Da(e,t.clients.get(s),s,o)})},Ia=(e,t)=>{const n=dt(),i=j(e.restDecoder);for(let s=0;s<i;s++){const o=j(e.restDecoder),r=new Array(o),l=e.readClient();let c=j(e.restDecoder);n.set(l,{i:0,refs:r});for(let a=0;a<o;a++){const u=e.readInfo();switch(xn&u){case 0:{const h=e.readLen();r[a]=new lt(_(l,c),h),c+=h;break}case 10:{const h=j(e.restDecoder);r[a]=new at(_(l,c),h),c+=h;break}default:{const h=(u&(vt|tt))===0,f=new A(_(l,c),null,(u&tt)===tt?e.readLeftID():null,null,(u&vt)===vt?e.readRightID():null,h?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,h&&(u&me)===me?e.readString():null,Xo(e,u));r[a]=f,c+=f.length}}}}return n},Aa=(e,t,n)=>{const i=[];let s=Lt(n.keys()).sort((p,g)=>p-g);if(s.length===0)return null;const o=()=>{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 r=o();if(r===null)return null;const l=new To,c=new Map,a=(p,g)=>{const x=c.get(p);(x==null||x>g)&&c.set(p,g)};let u=r.refs[r.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=Ct(h,u.id.client,()=>U(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,U(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(r!==null&&r.i<r.refs.length)u=r.refs[r.i++];else{if(r=o(),r===null)break;u=r.refs[r.i++]}}if(l.clients.size>0){const p=new En;return Co(p,l,new Map),I(p.restEncoder,0),{missing:c,update:p.toUint8Array()}}return null},Ma=(e,t)=>Co(e,t.doc.store,t.beforeState),Oa=(e,t,n,i=new rn(e))=>O(t,s=>{s.local=!1;let o=!1;const r=s.doc,l=r.store,c=Ia(i,r),a=Aa(s,l,c),u=l.pendingStructs;if(u){for(const[f,p]of u.missing)if(p<U(l,f)){o=!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=ms([u.update,a.update])}}else l.pendingStructs=a;const h=ls(i,s,l);if(l.pendingDs){const f=new rn(Si(l.pendingDs));j(f.restDecoder);const p=ls(f,s,l);h&&p?l.pendingDs=ms([h,p]):l.pendingDs=h||p}else l.pendingDs=h;if(o){const f=l.pendingStructs.update;l.pendingStructs=null,ri(s.doc,f)}},n,!1),ri=(e,t,n,i=rn)=>{const s=Si(t);Oa(s,e,n,new i(s))};class ja{constructor(){this.l=[]}}const cs=()=>new ja,as=(e,t)=>e.l.push(t),hs=(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.")},Eo=(e,t,n)=>Ei(e.l,[t,n]);class Gt{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 Gt(e,t),ve=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 ln{constructor(t,n,i,s=0){this.type=t,this.tname=n,this.item=i,this.assoc=s}}class Ra{constructor(t,n,i=0){this.type=t,this.index=n,this.assoc=i}}const Na=(e,t,n=0)=>new Ra(e,t,n),Le=(e,t,n)=>{let i=null,s=null;return e._item===null?s=ve(e):i=_(e._item.id.client,e._item.id.clock),new ln(i,s,t,n)},zn=(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)},Ba=(e,t)=>{const n=Yt(e,t),i=t.clock-n.id.clock;return{item:n,diff:i}},La=(e,t,n=!0)=>{const i=t.store,s=e.item,o=e.type,r=e.tname,l=e.assoc;let c=null,a=0;if(s!==null){if(U(i,s.client)<=s.clock)return null;const u=n?hi(i,s):Ba(i,s),h=u.item;if(!(h instanceof A))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(r!==null)c=t.get(r);else if(o!==null){if(U(i,o.client)<=o.clock)return null;const{item:u}=n?hi(i,o):{item:Yt(i,o)};if(u instanceof A&&u.content instanceof mt)c=u.content.type;else return null}else throw Z();l>=0?a=c._length:a=0}return Na(c,a,e.assoc)};class Ri{constructor(t,n){this.ds=t,this.sv=n}}const _o=(e,t)=>new Ri(e,t),qn=e=>_o(va(e.store),_n(e.store)),Rt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!le(t.ds,e.id),li=(e,t)=>{const n=Ct(e.meta,li,Bt),i=e.doc.store;n.has(t)||(t.sv.forEach((s,o)=>{s<U(i,o)&&et(e,_(o,s))}),Mt(e,t.ds,s=>{}),n.add(t))};class To{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},U=(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},Do=(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],o=s.id.clock;if(o===t)return i;let r=ft(t/(o+s.length-1)*i);for(;n<=i;){if(s=e[r],o=s.id.clock,o<=t){if(t<o+s.length)return r;n=r+1}else i=r-1;r=ft((n+i)/2)}throw Z()},Ua=(e,t)=>{const n=e.clients.get(t.client);return n[pt(n,t.clock)]},Yt=Ua,ci=(e,t,n)=>{const i=pt(t,n),s=t[i];return s.id.clock<n&&s instanceof A?(t.splice(i+1,0,dn(e,s,n-s.id.clock)),i+1):i},et=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[ci(e,n,t.clock)]},us=(e,t,n)=>{const i=t.clients.get(n.client),s=pt(i,n.clock),o=i[s];return n.clock!==o.id.clock+o.length-1&&o.constructor!==lt&&i.splice(s+1,0,dn(e,o,n.clock-o.id.clock+1)),o},Pa=(e,t,n)=>{const i=e.clients.get(t.id.client);i[pt(i,t.id.clock)]=n},Io=(e,t,n,i,s)=>{if(i===0)return;const o=n+i;let r=ci(e,t,n),l;do l=t[r++],o<l.id.clock+l.length&&ci(e,t,o),s(l);while(r<t.length&&t[r].id.clock<o)};class $a{constructor(t,n,i){this.doc=t,this.deleteSet=new re,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 ds=(e,t)=>t.deleteSet.clients.size===0&&!Cl(t.afterState,(n,i)=>t.beforeState.get(i)!==n)?!1:(Oi(t.deleteSet),Ma(e,t),ji(e,t.deleteSet),!0),fs=(e,t,n)=>{const i=t._item;(i===null||i.id.clock<(e.beforeState.get(i.id.client)||0)&&!i.deleted)&&Ct(e.changed,t,Bt).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 A&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,i);continue}break}const o=t-s;return o&&e.splice(t+1-o,o),o},Fa=(e,t,n)=>{for(const[i,s]of e.clients.entries()){const o=t.clients.get(i);for(let r=s.length-1;r>=0;r--){const l=s[r],c=l.clock+l.len;for(let a=pt(o,l.clock),u=o[a];a<o.length&&u.id.clock<c;u=o[++a]){const h=o[a];if(l.clock+l.len<=h.id.clock)break;h instanceof A&&h.deleted&&!h.keep&&n(h)&&h.gc(t,!1)}}}},Va=(e,t)=>{e.clients.forEach((n,i)=>{const s=t.clients.get(i);for(let o=n.length-1;o>=0;o--){const r=n[o],l=Zt(s.length-1,1+pt(s,r.clock+r.len-1));for(let c=l,a=s[c];c>0&&a.id.clock>=r.clock;a=s[c])c-=1+We(s,c)}})},Ao=(e,t)=>{if(t<e.length){const n=e[t],i=n.doc,s=i.store,o=n.deleteSet,r=n._mergeStructs;try{Oi(o),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(()=>{Eo(a._dEH,c,n)}))}),l.push(()=>i.emit("afterTransaction",[n,i])),l.push(()=>{n._needFormattingCleanup&&ch(n)})}),Ei(l,[])}finally{i.gc&&Fa(o,s,i.gcFilter),Va(o,s),n.afterState.forEach((u,h)=>{const f=n.beforeState.get(h)||0;if(f!==u){const p=s.clients.get(h),g=At(pt(p,f),1);for(let x=p.length-1;x>=g;)x-=1+We(p,x)}});for(let u=r.length-1;u>=0;u--){const{client:h,clock:f}=r[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)&&(wa(Ai,go,"[yjs] ",mo,xo,"Changed the client-id because another client seems to be using it."),i.clientID=ko()),i.emit("afterTransactionCleanup",[n,i]),i._observers.has("update")){const u=new _a;ds(u,n)&&i.emit("update",[u.toUint8Array(),n.origin,i,n])}if(i._observers.has("updateV2")){const u=new En;ds(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])):Ao(e,t+1)}}},O=(e,t,n=null,i=!0)=>{const s=e._transactionCleanups;let o=!1,r=null;e._transaction===null&&(o=!0,e._transaction=new $a(e,n,i),s.push(e._transaction),s.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{r=t(e._transaction)}finally{if(o){const l=e._transaction===s[0];e._transaction=null,l&&Ao(s,0)}}return r};class Ha{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const ps=(e,t,n)=>{Mt(e,n.deletions,i=>{i instanceof A&&t.scope.some(s=>s===e.doc||ke(s,i))&&Pi(i,!1)})},gs=(e,t,n)=>{let i=null;const s=e.doc,o=e.scope;O(s,l=>{for(;t.length>0&&e.currStackItem===null;){const c=s.store,a=t.pop(),u=new Set,h=[];let f=!1;Mt(l,a.insertions,p=>{if(p instanceof A){if(p.redone!==null){let{item:g,diff:x}=hi(c,p.id);x>0&&(g=et(l,_(g.id.client,g.id.clock+x))),p=g}!p.deleted&&o.some(g=>g===l.doc||ke(g,p))&&h.push(p)}}),Mt(l,a.deletions,p=>{p instanceof A&&o.some(g=>g===l.doc||ke(g,p))&&!le(a.insertions,p.id)&&u.add(p)}),u.forEach(p=>{f=Jo(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 r=e.currStackItem;if(r!=null){const l=i.changedParentTypes;e.emit("stack-item-popped",[{stackItem:r,type:n,changedParentTypes:l,origin:e},e]),e.currStackItem=null}return r};class Mo extends Ps{constructor(t,{captureTimeout:n=500,captureTransaction:i=c=>!0,deleteFilter:s=()=>!0,trackedOrigins:o=new Set([null]),ignoreRemoteMapChanges:r=!1,doc:l=Xt(t)?t[0].doc:t instanceof $t?t:t.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(t),this.deleteFilter=s,o.add(this),this.trackedOrigins=o,this.captureTransaction=i,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=r,this.captureTimeout=n,this.afterTransactionHandler=c=>{if(!this.captureTransaction(c)||!this.scope.some(w=>c.changedParentTypes.has(w)||w===this.doc)||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;const a=this.undoing,u=this.redoing,h=a?this.redoStack:this.undoStack;a?this.stopCapturing():u||this.clear(!1,!0);const f=new re;c.afterState.forEach((w,y)=>{const v=c.beforeState.get(y)||0,C=w-v;C>0&&Se(f,y,v,C)});const p=ac();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=oi([w.deletions,c.deleteSet]),w.insertions=oi([w.insertions,f])}else h.push(new Ha(c.deleteSet,f)),g=!0;!a&&!u&&(this.lastChange=p),Mt(c,c.deleteSet,w=>{w instanceof A&&this.scope.some(y=>y===c.doc||ke(y,w))&&Pi(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=Xt(t)?t:[t],t.forEach(i=>{n.has(i)||(n.add(i),(i instanceof K?i.doc!==this.doc:i!==this.doc)&&wo("[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=>ps(i,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>ps(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=gs(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=gs(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*za(e){const t=j(e.restDecoder);for(let n=0;n<t;n++){const i=j(e.restDecoder),s=e.readClient();let o=j(e.restDecoder);for(let r=0;r<i;r++){const l=e.readInfo();if(l===10){const c=j(e.restDecoder);yield new at(_(s,o),c),o+=c}else if((xn&l)!==0){const c=(l&(vt|tt))===0,a=new A(_(s,o),null,(l&tt)===tt?e.readLeftID():null,null,(l&vt)===vt?e.readRightID():null,c?e.readParentInfo()?e.readString():e.readLeftID():null,c&&(l&me)===me?e.readString():null,Xo(e,l));yield a,o+=a.length}else{const c=e.readLen();yield new lt(_(s,o),c),o+=c}}}}class qa{constructor(t,n){this.gen=za(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 Ka{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const Wa=(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 A(_(i,s+t),null,_(i,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},ms=(e,t=rn,n=En)=>{if(e.length===1)return e[0];const i=e.map(u=>new t(Si(u)));let s=i.map(u=>new qa(u,!0)),o=null;const r=new n,l=new Ka(r);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(o!==null){let f=u.curr,p=!1;for(;f!==null&&f.id.clock+f.length<=o.struct.id.clock+o.struct.length&&f.id.client>=o.struct.id.client;)f=u.next(),p=!0;if(f===null||f.id.client!==h||p&&f.id.clock>o.struct.id.clock+o.struct.length)continue;if(h!==o.struct.id.client)fe(l,o.struct,o.offset),o={struct:f,offset:0},u.next();else if(o.struct.id.clock+o.struct.length<f.id.clock)if(o.struct.constructor===at)o.struct.length=f.id.clock+f.length-o.struct.id.clock;else{fe(l,o.struct,o.offset);const g=f.id.clock-o.struct.id.clock-o.struct.length;o={struct:new at(_(h,o.struct.id.clock+o.struct.length),g),offset:0}}else{const g=o.struct.id.clock+o.struct.length-f.id.clock;g>0&&(o.struct.constructor===at?o.struct.length-=g:f=Wa(f,g)),o.struct.mergeWith(f)||(fe(l,o.struct,o.offset),o={struct:f,offset:0},u.next())}}else o={struct:u.curr,offset:0},u.next();for(let f=u.curr;f!==null&&f.id.client===h&&f.id.clock===o.struct.id.clock+o.struct.length&&f.constructor!==at;f=u.next())fe(l,o.struct,o.offset),o={struct:f,offset:0}}o!==null&&(fe(l,o.struct,o.offset),o=null),Ga(l);const c=i.map(u=>ka(u)),a=oi(c);return ji(r,a),r.toUint8Array()},Oo=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&&Oo(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++},Ga=e=>{Oo(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),bn(t,i.restEncoder)}},xs="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=Ya(this.currentTarget,this.target))}deletes(t){return le(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw wt(xs);const t=new Map,n=this.target;this.transaction.changed.get(n).forEach(s=>{if(s!==null){const o=n._map.get(s);let r,l;if(this.adds(o)){let c=o.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(o))if(c!==null&&this.deletes(c))r="delete",l=Bn(c.content.getContent());else return;else c!==null&&this.deletes(c)?(r="update",l=Bn(c.content.getContent())):(r="add",l=void 0)}else if(this.deletes(o))r="delete",l=Bn(o.content.getContent());else return;t.set(s,{action:r,oldValue:l})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw wt(xs);const n=this.target,i=Bt(),s=Bt(),o=[];if(t={added:i,deleted:s,delta:o,keys:this.keys},this.transaction.changed.get(n).has(null)){let l=null;const c=()=>{l&&o.push(l)};for(let a=n._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((l===null||l.delete===void 0)&&(c(),l={delete:0}),l.delete+=a.length,s.add(a)):this.adds(a)?((l===null||l.insert===void 0)&&(c(),l={insert:[]}),l.insert=l.insert.concat(a.content.getContent()),i.add(a)):((l===null||l.retain===void 0)&&(c(),l={retain:0}),l.retain+=a.length);l!==null&&l.retain===void 0&&c()}this._changes=t}return t}}const Ya=(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=()=>{wo("Invalid access: Add Yjs type to a document before reading data.")},jo=80;let Ni=0;class Ja{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=Ni++}}const Xa=e=>{e.timestamp=Ni++},Ro=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Ni++},Za=(e,t,n)=>{if(e.length>=jo){const i=e.reduce((s,o)=>s.timestamp<o.timestamp?s:o);return Ro(i,t,n),i}else{const i=new Ja(t,n);return e.push(i),i}},Dn=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;const n=e._searchMarker.length===0?null:e._searchMarker.reduce((o,r)=>He(t-o.index)<He(t-r.index)?o:r);let i=e._start,s=0;for(n!==null&&(i=n.p,s=n.index,Xa(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/jo?(Ro(n,i,s),n):Za(e._searchMarker,i,s)},Ce=(e,t,n)=>{for(let i=e.length-1;i>=0;i--){const s=e[i];if(n>0){let o=s.p;for(o.marker=!1;o&&(o.deleted||!o.countable);)o=o.left,o&&!o.deleted&&o.countable&&(s.index-=o.length);if(o===null||o.marker===!0){e.splice(i,1);continue}s.p=o,o.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=At(t,s.index+n))}},In=(e,t,n)=>{const i=e,s=t.changedParentTypes;for(;Ct(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Eo(i._eH,n,t)};class K{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=cs(),this._dEH=cs(),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){as(this._eH,t)}observeDeep(t){as(this._dEH,t)}unobserve(t){hs(this._eH,t)}unobserveDeep(t){hs(this._dEH,t)}toJSON(){}}const No=(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 o=e._start;for(;o!==null&&i>0;){if(o.countable&&!o.deleted){const r=o.content.getContent();if(r.length<=t)t-=r.length;else{for(let l=t;l<r.length&&i>0;l++)s.push(r[l]),i--;t=0}}o=o.right}return s},Bo=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},Lo=(e,t)=>{const n=[];let i=e._start;for(;i!==null;){if(i.countable&&Rt(i,t)){const s=i.content.getContent();for(let o=0;o<s.length;o++)n.push(s[o])}i=i.right}return n},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 o=0;o<s.length;o++)t(s[o],n++,e)}i=i.right}},Uo=(e,t)=>{const n=[];return Ee(e,(i,s)=>{n.push(t(i,s,e))}),n},Qa=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}}}},Po=(e,t)=>{e.doc??X();const n=Dn(e,t);let i=e._start;for(n!==null&&(i=n.p,t-=n.index);i!==null;i=i.right)if(!i.deleted&&i.countable){if(t<i.length)return i.content.getContent()[t];t-=i.length}},cn=(e,t,n,i)=>{let s=n;const o=e.doc,r=o.clientID,l=o.store,c=n===null?t._start:n.right;let a=[];const u=()=>{a.length>0&&(s=new A(_(r,U(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new Pt(a)),s.integrate(e,0),a=[])};i.forEach(h=>{if(h===null)a.push(h);else switch(h.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(h);break;default:switch(u(),h.constructor){case Uint8Array:case ArrayBuffer:s=new A(_(r,U(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new Me(new Uint8Array(h))),s.integrate(e,0);break;case $t:s=new A(_(r,U(l,r)),s,s&&s.lastId,c,c&&c.id,t,null,new Oe(h)),s.integrate(e,0);break;default:if(h instanceof K)s=new A(_(r,U(l,r)),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()},$o=()=>wt("Length exceeded!"),Fo=(e,t,n,i)=>{if(n>t._length)throw $o();if(n===0)return t._searchMarker&&Ce(t._searchMarker,n,i.length),cn(e,t,null,i);const s=n,o=Dn(t,n);let r=t._start;for(o!==null&&(r=o.p,n-=o.index,n===0&&(r=r.prev,n+=r&&r.countable&&!r.deleted?r.length:0));r!==null;r=r.right)if(!r.deleted&&r.countable){if(n<=r.length){n<r.length&&et(e,_(r.id.client,r.id.clock+n));break}n-=r.length}return t._searchMarker&&Ce(t._searchMarker,s,i.length),cn(e,t,r,i)},th=(e,t,n)=>{let s=(t._searchMarker||[]).reduce((o,r)=>r.index>o.index?r:o,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return cn(e,t,s,n)},Vo=(e,t,n,i)=>{if(i===0)return;const s=n,o=i,r=Dn(t,n);let l=t._start;for(r!==null&&(l=r.p,n-=r.index);l!==null&&n>0;l=l.right)!l.deleted&&l.countable&&(n<l.length&&et(e,_(l.id.client,l.id.clock+n)),n-=l.length);for(;i>0&&l!==null;)l.deleted||(i<l.length&&et(e,_(l.id.client,l.id.clock+i)),l.delete(e),i-=l.length),l=l.right;if(i>0)throw $o();t._searchMarker&&Ce(t._searchMarker,s,-o+i)},an=(e,t,n)=>{const i=t._map.get(n);i!==void 0&&i.delete(e)},Bi=(e,t,n,i)=>{const s=t._map.get(n)||null,o=e.doc,r=o.clientID;let l;if(i==null)l=new Pt([i]);else switch(i.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new Pt([i]);break;case Uint8Array:l=new Me(i);break;case $t:l=new Oe(i);break;default:if(i instanceof K)l=new mt(i);else throw new Error("Unexpected content type")}new A(_(r,U(o.store,r)),s,s&&s.lastId,null,null,t,n,l).integrate(e,0)},Li=(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},Ho=e=>{const t={};return e.doc??X(),e._map.forEach((n,i)=>{n.deleted||(t[i]=n.content.getContent()[n.length-1])}),t},zo=(e,t)=>{e.doc??X();const n=e._map.get(t);return n!==void 0&&!n.deleted},eh=(e,t)=>{const n={};return e._map.forEach((i,s)=>{let o=i;for(;o!==null&&(!t.sv.has(o.id.client)||o.id.clock>=(t.sv.get(o.id.client)||0));)o=o.left;o!==null&&Rt(o,t)&&(n[s]=o.content.getContent()[o.length-1])}),n},Ue=e=>(e.doc??X(),ya(e._map.entries(),t=>!t[1].deleted));class nh extends Tn{}class Jt extends K{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new Jt;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Jt}clone(){const t=new Jt;return t.insert(0,this.toArray().map(n=>n instanceof K?n.clone():n)),t}get length(){return this.doc??X(),this._length}_callObserver(t,n){super._callObserver(t,n),In(this,t,new nh(this,t))}insert(t,n){this.doc!==null?O(this.doc,i=>{Fo(i,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?O(this.doc,n=>{th(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?O(this.doc,i=>{Vo(i,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return Po(this,t)}toArray(){return Bo(this)}slice(t=0,n=this.length){return No(this,t,n)}toJSON(){return this.map(t=>t instanceof K?t.toJSON():t)}map(t){return Uo(this,t)}forEach(t){Ee(this,t)}[Symbol.iterator](){return Qa(this)}_write(t){t.writeTypeRef(Th)}}const ih=e=>new Jt;class sh extends Tn{constructor(t,n,i){super(t,n),this.keysChanged=i}}class ne extends K{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach((i,s)=>{this.set(s,i)}),this._prelimContent=null}_copy(){return new ne}clone(){const t=new ne;return this.forEach((n,i)=>{t.set(i,n instanceof K?n.clone():n)}),t}_callObserver(t,n){In(this,t,new sh(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 K?s.toJSON():s}}),t}get size(){return[...Ue(this)].length}keys(){return Hn(Ue(this),t=>t[0])}values(){return Hn(Ue(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Hn(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=>{an(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?O(this.doc,i=>{Bi(i,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return Li(this,t)}has(t){return zo(this,t)}clear(){this.doc!==null?O(this.doc,t=>{this.forEach(function(n,i,s){an(t,s,i)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Dh)}}const oh=e=>new ne,Tt=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&xc(e,t);class ai{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||ce(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 bs=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case F:t.right.deleted||ce(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&et(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,o=i?Dn(t,n):null;if(o){const r=new ai(o.p.left,o.p,o.index,s);return bs(e,r,n-o.index)}else{const r=new ai(null,t._start,0,s);return bs(e,r,n)}},qo=(e,t,n,i)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===F&&Tt(i.get(n.right.content.key),n.right.content.value));)n.right.deleted||i.delete(n.right.content.key),n.forward();const s=e.doc,o=s.clientID;i.forEach((r,l)=>{const c=n.left,a=n.right,u=new A(_(o,U(s.store,o)),c,c&&c.lastId,a,a&&a.id,t,null,new F(l,r));u.integrate(e,0),n.right=u,n.forward()})},ce=(e,t)=>{const{key:n,value:i}=t;i===null?e.delete(n):e.set(n,i)},Ko=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===F&&Tt(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},Wo=(e,t,n,i)=>{const s=e.doc,o=s.clientID,r=new Map;for(const l in i){const c=i[l],a=n.currentAttributes.get(l)??null;if(!Tt(a,c)){r.set(l,a);const{left:u,right:h}=n;n.right=new A(_(o,U(s.store,o)),u,u&&u.lastId,h,h&&h.id,t,null,new F(l,c)),n.right.integrate(e,0),n.forward()}}return r},Kn=(e,t,n,i,s)=>{n.currentAttributes.forEach((f,p)=>{s[p]===void 0&&(s[p]=null)});const o=e.doc,r=o.clientID;Ko(n,s);const l=Wo(e,t,n,s),c=i.constructor===String?new gt(i):i instanceof K?new mt(i):new Ft(i);let{left:a,right:u,index:h}=n;t._searchMarker&&Ce(t._searchMarker,n.index,c.getLength()),u=new A(_(r,U(o.store,r)),a,a&&a.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=h,n.forward(),qo(e,t,n,l)},ws=(e,t,n,i,s)=>{const o=e.doc,r=o.clientID;Ko(n,s);const l=Wo(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(Tt(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&&et(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 A(_(r,U(o.store,r)),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()}qo(e,t,n,l)},Go=(e,t,n,i,s)=>{let o=t;const r=dt();for(;o&&(!o.countable||o.deleted);){if(!o.deleted&&o.content.constructor===F){const a=o.content;r.set(a.key,a)}o=o.right}let l=0,c=!1;for(;t!==o;){if(n===t&&(c=!0),!t.deleted){const a=t.content;switch(a.constructor){case F:{const{key:u,value:h}=a,f=i.get(u)??null;(r.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&&ce(s,a);break}}}t=t.right}return l},rh=(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}},lh=e=>{let t=0;return O(e.doc,n=>{let i=e._start,s=e._start,o=dt();const r=Zn(o);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case F:ce(r,s.content);break;default:t+=Go(n,i,s,o,r),o=Zn(r),i=s;break}s=s.right}}),t},ch=e=>{const t=new Set,n=e.doc;for(const[i,s]of e.afterState.entries()){const o=e.beforeState.get(i)||0;s!==o&&Io(e,n.store.clients.get(i),o,s,r=>{!r.deleted&&r.content.constructor===F&&r.constructor!==lt&&t.add(r.parent)})}O(n,i=>{Mt(e,e.deleteSet,s=>{if(s instanceof lt||!s.parent._hasFormatting||t.has(s.parent))return;const o=s.parent;s.content.constructor===F?t.add(o):rh(i,s)});for(const s of t)lh(s)})},ys=(e,t,n)=>{const i=n,s=Zn(t.currentAttributes),o=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case mt:case Ft:case gt:n<t.right.length&&et(e,_(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}o&&Go(e,o,t.right,s,t.currentAttributes);const r=(t.left||t.right).parent;return r._searchMarker&&Ce(r._searchMarker,t.index,-i+n),t};class ah 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,o=new Map;let r=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},mc(c)||(p.attributes=pc({},c))),u=0;break}p&&n.push(p),l=null}};for(;r!==null;){switch(r.content.constructor){case mt:case Ft:this.adds(r)?this.deletes(r)||(f(),l="insert",a=r.content.getContent()[0],f()):this.deletes(r)?(l!=="delete"&&(f(),l="delete"),h+=1):r.deleted||(l!=="retain"&&(f(),l="retain"),u+=1);break;case gt:this.adds(r)?this.deletes(r)||(l!=="insert"&&(f(),l="insert"),a+=r.content.str):this.deletes(r)?(l!=="delete"&&(f(),l="delete"),h+=r.length):r.deleted||(l!=="retain"&&(f(),l="retain"),u+=r.length);break;case F:{const{key:p,value:g}=r.content;if(this.adds(r)){if(!this.deletes(r)){const x=s.get(p)??null;Tt(x,g)?g!==null&&r.delete(i):(l==="retain"&&f(),Tt(g,o.get(p)??null)?delete c[p]:c[p]=g)}}else if(this.deletes(r)){o.set(p,g);const x=s.get(p)??null;Tt(x,g)||(l==="retain"&&f(),c[p]=x)}else if(!r.deleted){o.set(p,g);const x=c[p];x!==void 0&&(Tt(x,g)?x!==null&&r.delete(i):(l==="retain"&&f(),g===null?delete c[p]:c[p]=g))}r.deleted||(l==="insert"&&f(),ce(s,r.content));break}}r=r.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 Ot extends K{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??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 Ot}clone(){const t=new Ot;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const i=new ah(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 ai(null,this._start,0,new Map);for(let o=0;o<t.length;o++){const r=t[o];if(r.insert!==void 0){const l=!n&&typeof r.insert=="string"&&o===t.length-1&&s.right===null&&r.insert.slice(-1)===`
|
|
6
|
+
`?r.insert.slice(0,-1):r.insert;(typeof l!="string"||l.length>0)&&Kn(i,this,s,l,r.attributes||{})}else r.retain!==void 0?ws(i,this,s,r.retain,r.attributes||{}):r.delete!==void 0&&ys(i,s,r.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,i){this.doc??X();const s=[],o=new Map,r=this.doc;let l="",c=this._start;function a(){if(l.length>0){const h={};let f=!1;o.forEach((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(Rt(c,t)||n!==void 0&&Rt(c,n))switch(c.content.constructor){case gt:{const h=o.get("ychange");t!==void 0&&!Rt(c,t)?(h===void 0||h.user!==c.id.client||h.type!=="removed")&&(a(),o.set("ychange",i?i("removed",c.id):{type:"removed"})):n!==void 0&&!Rt(c,n)?(h===void 0||h.user!==c.id.client||h.type!=="added")&&(a(),o.set("ychange",i?i("added",c.id):{type:"added"})):h!==void 0&&(a(),o.delete("ychange")),l+=c.content.str;break}case mt:case Ft:{a();const h={insert:c.content.getContent()[0]};if(o.size>0){const f={};h.attributes=f,o.forEach((p,g)=>{f[g]=p})}s.push(h);break}case F:Rt(c,t)&&(a(),ce(o,c.content));break}c=c.right}a()};return t||n?O(r,h=>{t&&li(h,t),n&&li(h,n),u()},"cleanup"):u(),s}insert(t,n,i){if(n.length<=0)return;const s=this.doc;s!==null?O(s,o=>{const r=Pe(o,this,t,!i);i||(i={},r.currentAttributes.forEach((l,c)=>{i[c]=l})),Kn(o,this,r,n,i)}):this._pending.push(()=>this.insert(t,n,i))}insertEmbed(t,n,i){const s=this.doc;s!==null?O(s,o=>{const r=Pe(o,this,t,!i);Kn(o,this,r,n,i||{})}):this._pending.push(()=>this.insertEmbed(t,n,i||{}))}delete(t,n){if(n===0)return;const i=this.doc;i!==null?O(i,s=>{ys(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,o=>{const r=Pe(o,this,t,!1);r.right!==null&&ws(o,this,r,n,i)}):this._pending.push(()=>this.format(t,n,i))}removeAttribute(t){this.doc!==null?O(this.doc,n=>{an(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?O(this.doc,i=>{Bi(i,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return Li(this,t)}getAttributes(){return Ho(this)}_write(t){t.writeTypeRef(Ih)}}const hh=e=>new Ot;class Wn{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===Ut)&&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 Ut extends K{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Ut}clone(){const t=new Ut;return t.insert(0,this.toArray().map(n=>n instanceof K?n.clone():n)),t}get length(){return this.doc??X(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Wn(this,t)}querySelector(t){t=t.toUpperCase();const i=new Wn(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return i.done?null:i.value}querySelectorAll(t){return t=t.toUpperCase(),Lt(new Wn(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){In(this,t,new fh(this,n,t))}toString(){return Uo(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,o=>{s.insertBefore(o.toDOM(t,n,i),null)}),s}insert(t,n){this.doc!==null?O(this.doc,i=>{Fo(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 K?t._item:t;cn(i,this,s,n)});else{const i=this._prelimContent,s=t===null?0:i.findIndex(o=>o===t)+1;if(s===0&&t!==null)throw wt("Reference item not found");i.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?O(this.doc,i=>{Vo(i,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return Bo(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Po(this,t)}slice(t=0,n=this.length){return No(this,t,n)}forEach(t){Ee(this,t)}_write(t){t.writeTypeRef(Mh)}}const uh=e=>new Ut;class J extends Ut{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 gc(n,(i,s)=>{t.setAttribute(s,i)}),t.insert(0,this.toArray().map(i=>i instanceof K?i.clone():i)),t}toString(){const t=this.getAttributes(),n=[],i=[];for(const l in t)i.push(l);i.sort();const s=i.length;for(let l=0;l<s;l++){const c=i[l];n.push(c+'="'+t[c]+'"')}const o=this.nodeName.toLocaleLowerCase(),r=n.length>0?" "+n.join(" "):"";return`<${o}${r}>${super.toString()}</${o}>`}removeAttribute(t){this.doc!==null?O(this.doc,n=>{an(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?O(this.doc,i=>{Bi(i,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return Li(this,t)}hasAttribute(t){return zo(this,t)}getAttributes(t){return t?eh(this,t):Ho(this)}toDOM(t=document,n={},i){const s=t.createElement(this.nodeName),o=this.getAttributes();for(const r in o){const l=o[r];typeof l=="string"&&s.setAttribute(r,l)}return Ee(this,r=>{s.appendChild(r.toDOM(t,n,i))}),i!==void 0&&i._createAssociation(s,this),s}_write(t){t.writeTypeRef(Ah),t.writeKey(this.nodeName)}}const dh=e=>new J(e.readKey());class fh 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 hn extends ne{constructor(t){super(),this.hookName=t}_copy(){return new hn(this.hookName)}clone(){const t=new hn(this.hookName);return this.forEach((n,i)=>{t.set(i,n)}),t}toDOM(t=document,n={},i){const s=n[this.hookName];let o;return s!==void 0?o=s.createDom(this):o=document.createElement(this.hookName),o.setAttribute("data-yjs-hook",this.hookName),i!==void 0&&i._createAssociation(o,this),o}_write(t){t.writeTypeRef(Oh),t.writeKey(this.hookName)}}const ph=e=>new hn(e.readKey());class nt extends Ot{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new nt}clone(){const t=new nt;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,i){const s=t.createTextNode(this.toString());return i!==void 0&&i._createAssociation(s,this),s}toString(){return this.toDelta().map(t=>{const n=[];for(const s in t.attributes){const o=[];for(const r in t.attributes[s])o.push({key:r,value:t.attributes[s][r]});o.sort((r,l)=>r.key<l.key?-1:1),n.push({nodeName:s,attrs:o})}n.sort((s,o)=>s.nodeName<o.nodeName?-1:1);let i="";for(let s=0;s<n.length;s++){const o=n[s];i+=`<${o.nodeName}`;for(let r=0;r<o.attrs.length;r++){const l=o.attrs[r];i+=` ${l.key}="${l.value}"`}i+=">"}i+=t.insert;for(let s=n.length-1;s>=0;s--)i+=`</${n[s].nodeName}>`;return i}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(jh)}}const gh=e=>new nt;class Ui{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 mh=0;class lt extends Ui{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),Do(t.doc.store,this)}write(t,n){t.writeInfo(mh),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 xh=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){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 bh=e=>new _e(e.readLen()),Yo=(e,t)=>new $t({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(Yo(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 wh=e=>new Oe(Yo(e.readString(),e.readAny()));class Ft{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Ft(this.embed)}splice(t){throw ct()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}const yh=e=>new Ft(e.readJSON());class F{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new F(this.key,this.value)}splice(t){throw 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 Sh=e=>new F(e.readKey(),e.readJSON());class un{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new un(this.arr)}splice(t){const n=new un(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const i=this.arr.length;t.writeLen(i-n);for(let s=n;s<i;s++){const o=this.arr[s];t.writeString(o===void 0?"undefined":JSON.stringify(o))}}getRef(){return 2}}const vh=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 un(n)},kh=en("node_env")==="development";class Pt{constructor(t){this.arr=t,kh&&Gs(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Pt(this.arr)}splice(t){const n=new Pt(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const i=this.arr.length;t.writeLen(i-n);for(let s=n;s<i;s++){const o=this.arr[s];t.writeAny(o)}}getRef(){return 8}}const Ch=e=>{const t=e.readLen(),n=[];for(let i=0;i<t;i++)n.push(e.readAny());return new Pt(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 Eh=e=>new gt(e.readString()),_h=[ih,oh,hh,dh,uh,ph,gh],Th=0,Dh=1,Ih=2,Ah=3,Mh=4,Oh=5,jh=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 Rh=e=>new mt(_h[e.readTypeRef()](e)),hi=(e,t)=>{let n=t,i=0,s;do i>0&&(n=_(n.client,n.clock+i)),s=Yt(e,n),i=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof A);return{item:s,diff:i}},Pi=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},dn=(e,t,n)=>{const{client:i,clock:s}=t.id,o=new A(_(i,s+n),t,_(i,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&o.markDeleted(),t.keep&&(o.keep=!0),t.redone!==null&&(o.redone=_(t.redone.client,t.redone.clock+n)),t.right=o,o.right!==null&&(o.right.left=o),e._mergeStructs.push(o),o.parentSub!==null&&o.right===null&&o.parent._map.set(o.parentSub,o),t.length=n,o},Ss=(e,t)=>bi(e,n=>le(n.deletions,t)),Jo=(e,t,n,i,s,o)=>{const r=e.doc,l=r.store,c=r.clientID,a=t.redone;if(a!==null)return et(e,a);let u=t.parent._item,h=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||Jo(e,u,n,i,s,o)===null))return null;for(;u.redone!==null;)u=et(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:et(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:et(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||le(i,h.right.id)||Ss(o.undoStack,h.right.id)||Ss(o.redoStack,h.right.id));)for(h=h.right;h.redone;)h=et(e,h.redone);if(h&&h.right!==null)return null}else h=p._map.get(t.parentSub)||null;const g=U(l,c),x=_(c,g),w=new A(x,h,h&&h.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=x,Pi(w,!0),w.integrate(e,0),w};class A extends Ui{constructor(t,n,i,s,o,r,l,c){super(t,c.getLength()),this.origin=i,this.left=n,this.right=s,this.rightOrigin=o,this.parent=r,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?Yi:0}set marker(t){(this.info&Un)>0!==t&&(this.info^=Un)}get marker(){return(this.info&Un)>0}get keep(){return(this.info&Gi)>0}set keep(t){this.keep!==t&&(this.info^=Gi)}get countable(){return(this.info&Yi)>0}get deleted(){return(this.info&Ln)>0}set deleted(t){this.deleted!==t&&(this.info^=Ln)}markDeleted(){this.info|=Ln}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=U(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=U(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Gt&&this.id.client!==this.parent.client&&this.parent.clock>=U(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=us(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=et(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===A?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===A&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Gt){const i=Yt(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=us(t,t.doc.store,_(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let i=this.left,s;if(i!==null)s=i.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;const o=new Set,r=new Set;for(;s!==null&&s!==this.right;){if(r.add(s),o.add(s),Be(this.origin,s.origin)){if(s.id.client<this.id.client)i=s,o.clear();else if(Be(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&r.has(Yt(t.doc.store,s.origin)))o.has(Yt(t.doc.store,s.origin))||(i=s,o.clear());else break;s=s.right}this.left=i}if(this.left!==null){const i=this.left.right;this.right=i,this.left.right=this}else{let i;if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start,this.parent._start=this;this.right=i}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Do(t.doc.store,this),this.content.integrate(t,this),fs(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),fs(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw Z();this.content.gc(t),n?Pa(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,o=this.parentSub,r=this.content.getRef()&xn|(i===null?0:tt)|(s===null?0:vt)|(o===null?0:me);if(t.writeInfo(r),i!==null&&t.writeLeftID(i),s!==null&&t.writeRightID(s),i===null&&s===null){const l=this.parent;if(l._item!==void 0){const c=l._item;if(c===null){const a=ve(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===Gt?(t.writeParentInfo(!1),t.writeLeftID(l)):Z();o!==null&&t.writeString(o)}this.content.write(t,n)}}const Xo=(e,t)=>Nh[t&xn](e),Nh=[()=>{Z()},bh,vh,xh,Eh,yh,Sh,Rh,Ch,wh,()=>{Z()}],Bh=10;class at extends Ui{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(Bh),I(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const Zo=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Qo="__ $YJS$ __";Zo[Qo]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Zo[Qo]=!0;const Lh=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},Uh=/[\uD800-\uDBFF]/,Ph=/[\uDC00-\uDFFF]/,$h=(e,t)=>{let n=0,i=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&Uh.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&&Ph.test(e[e.length-i])&&i--,{index:n,remove:e.length-n-i,insert:t.slice(n,t.length-i)}},Fh=$h,bt=(e,t)=>e>>>t|e<<32-t,Vh=e=>bt(e,2)^bt(e,13)^bt(e,22),Hh=e=>bt(e,6)^bt(e,11)^bt(e,25),zh=e=>bt(e,7)^bt(e,18)^e>>>3,qh=e=>bt(e,17)^bt(e,19)^e>>>10,Kh=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]),Wh=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class Gh{constructor(){const t=new ArrayBuffer(320);this._H=new Uint32Array(t,0,8),this._H.set(Wh),this._W=new Uint32Array(t,64,64)}_updateHash(){const t=this._H,n=this._W;for(let h=16;h<64;h++)n[h]=qh(n[h-2])+n[h-7]+zh(n[h-15])+n[h-16];let i=t[0],s=t[1],o=t[2],r=t[3],l=t[4],c=t[5],a=t[6],u=t[7];for(let h=0,f,p;h<64;h++)f=u+Hh(l)+(l&c^~l&a)+Kh[h]+n[h]>>>0,p=Vh(i)+(i&s^i&o^s&o)>>>0,u=a,a=c,c=l,l=r+f>>>0,r=o,o=s,s=i,i=f+p>>>0;t[0]+=i,t[1]+=s,t[2]+=o,t[3]+=r,t[4]+=l,t[5]+=c,t[6]+=a,t[7]+=u}digest(t){let n=0;for(;n+56<=t.length;){let r=0;for(;r<16&&n+3<t.length;r++)this._W[r]=t[n++]<<24|t[n++]<<16|t[n++]<<8|t[n++];if(n%64!==0){for(this._W.fill(0,r,16);n<t.length;)this._W[r]|=t[n]<<(3-n%4)*8,n++;this._W[r]|=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 r=3;r>=0&&n<t.length;r--)this._W[s]|=t[n++]<<r*8;i||(this._W[s-(n%4===0?0:1)]|=tt<<(3-n%4)*8),this._W[14]=t.byteLength/Tl,this._W[15]=t.byteLength*8,this._updateHash();const o=new Uint8Array(32);for(let r=0;r<this._H.length;r++)for(let l=0;l<4;l++)o[r*4+l]=this._H[r]>>>(3-l)*8;return o}}const Yh=e=>new Gh().digest(e),R=new T.PluginKey("y-sync"),kt=new T.PluginKey("y-undo");new T.PluginKey("yjs-cursor");const Jh=e=>{for(let n=6;n<e.length;n++)e[n%6]=e[n%6]^e[n];return e.slice(0,6)},Xh=e=>_c(Jh(Yh(Tc(e)))),fn=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!le(t.ds,e.id),Zh=[{light:"#ecd44433",dark:"#ecd444"}],Qh=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){const i=Bt();e.forEach(s=>i.add(s)),t=t.filter(s=>!i.has(s))}e.set(n,rc(t))}return e.get(n)},tu=(e,{colors:t=Zh,colorMapping:n=new Map,permanentUserData:i=null,onFirstRender:s=()=>{},mapping:o}={})=>{let r=!1;const l=new iu(e,o),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)&&po(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),o==null&&l._forceRerender(),s(),{update:()=>{const u=c.getState(a.state);if(u.snapshot==null&&u.prevSnapshot==null&&(r||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(r=!0,u.addToHistory===!1&&!u.isChangeOrigin){const h=kt.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},eu=(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(nu(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)))}},nu=(e,t)=>{const n=e.doc.resolve(t);return n.nodeAfter?T.NodeSelection.create(e.doc,t):T.TextSelection.near(n)},ui=(e,t)=>({type:t.selection.jsonID,anchor:gn(t.selection.anchor,e.type,e.mapping),head:gn(t.selection.head,e.type,e.mapping)});class iu{constructor(t,n=new Map){this.type=t,this.prosemirrorView=null,this.mux=Lh(),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=ui(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()?(Ys&&this._domSelectionInView===null&&(po(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){const t=this.prosemirrorView._root.getSelection();if(t==null||t.anchorNode==null)return!1;const n=this.prosemirrorView._root.createRange();n.setStart(t.anchorNode,t.anchorOffset),n.setEnd(t.focusNode,t.focusOffset),n.getClientRects().length===0&&n.startContainer&&n.collapsed&&n.selectNodeContents(n.startContainer);const s=n.getBoundingClientRect(),o=Ae.documentElement;return s.bottom>=0&&s.right>=0&&s.left<=(window.innerWidth||o.clientWidth||0)&&s.top<=(window.innerHeight||o.clientHeight||0)}renderSnapshot(t,n){n||(n=_o(vo(),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=Zt(At(t.anchor,0),i.doc.content.size),o=Zt(At(t.head,0),i.doc.content.size);i.setSelection(T.TextSelection.create(i.doc,s,o))}this.prosemirrorView.dispatch(i.setMeta(R,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(t,n,i){let s=this.doc,o=this.type;if(t||(t=qn(this.doc)),t instanceof Uint8Array||n instanceof Uint8Array)if((!(t instanceof Uint8Array)||!(n instanceof Uint8Array))&&Z(),s=new $t({gc:!1}),ri(s,n),n=qn(s),ri(s,t),t=qn(s),o._item===null){const r=Array.from(this.doc.share.keys()).find(l=>this.doc.share.get(l)===this.type);o=s.getXmlFragment(r)}else{const r=s.store.clients.get(o._item.id.client)??[],l=pt(r,o._item.id.clock);o=r[l].content.type}this.mapping.clear(),this.mux(()=>{s.transact(r=>{const l=i.permanentUserData;l&&l.dss.forEach(h=>{Mt(r,h,f=>{})});const c=(h,f)=>{const p=h==="added"?l.getUserByClientId(f.client):l.getUserByDeletedId(f);return{user:p,type:h,color:Qh(i.colorMapping,i.colors,p)}},a=Lo(o,new Ri(n.ds,t.sv)).map(h=>!h._item.deleted||fn(h._item,t)||fn(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);Mt(n,n.deleteSet,l=>{if(l.constructor===A){const c=l.content.type;c&&this.mapping.delete(c)}}),n.changed.forEach(s),n.changedParentTypes.forEach(s);const o=this.type.toArray().map(l=>tr(l,this.prosemirrorView.state.schema,this)).filter(l=>l!==null);let r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new T.Slice(T.Fragment.from(o),0,0));eu(r,this.beforeTransactionSelection,this),r=r.setMeta(R,{isChangeOrigin:!0,isUndoRedoOperation:n.origin instanceof Mo}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&r.scrollIntoView(),this.prosemirrorView.dispatch(r)})}_prosemirrorChanged(t){this.doc.transact(()=>{fi(this.doc,this.type,t,this),this.beforeTransactionSelection=ui(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 tr=(e,t,n,i,s,o)=>{const r=n.mapping.get(e);if(r===void 0){if(e instanceof J)return Ge(e,t,n,i,s,o);throw ct()}return r},Ge=(e,t,n,i,s,o)=>{const r=[],l=c=>{var a,u;if(c instanceof J){const h=tr(c,t,n,i,s,o);h!==null&&r.push(h)}else{const h=(u=(a=c._item.right)==null?void 0:a.content)==null?void 0:u.type;h instanceof Ot&&!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=su(c,t,n,i,s,o);f!==null&&f.forEach(p=>{p!==null&&r.push(p)})}};i===void 0||s===void 0?e.toArray().forEach(l):Lo(e,new Ri(s.ds,i.sv)).forEach(l);try{const c=e.getAttributes(i);i!==void 0&&(fn(e._item,i)?fn(e._item,s)||(c.ychange=o?o("added",e._item.id):{type:"added"}):c.ychange=o?o("removed",e._item.id):{type:"removed"});const a=t.node(e.nodeName,c,r);return n.mapping.set(e,a),a}catch{return e.doc.transact(a=>{e._item.delete(a)},R),n.mapping.delete(e),null}},su=(e,t,n,i,s,o)=>{const r=[],l=e.toDelta(i,s,o);try{for(let c=0;c<l.length;c++){const a=l[c];r.push(t.text(a.insert,hu(a.attributes,t)))}}catch{return e.doc.transact(a=>{e._item.delete(a)},R),null}return r},ou=(e,t)=>{const n=new nt,i=e.map(s=>({insert:s.text,attributes:nr(s.marks,t)}));return n.applyDelta(i),t.mapping.set(n,e),n},ru=(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,An(e).map(i=>di(i,t))),t.mapping.set(n,e),n},di=(e,t)=>e instanceof Array?ou(e,t):ru(e,t),vs=e=>typeof e=="object"&&e!==null,$i=(e,t)=>{const n=Object.keys(e).filter(s=>e[s]!==null);let i=n.length===Object.keys(t).filter(s=>t[s]!==null).length;for(let s=0;s<n.length&&i;s++){const o=n[s],r=e[o],l=t[o];i=o==="ychange"||r===l||vs(r)&&vs(l)&&$i(r,l)}return i},An=e=>{const t=e.content.content,n=[];for(let i=0;i<t.length;i++){const s=t[i];if(s.isText){const o=[];for(let r=t[i];i<t.length&&r.isText;r=t[++i])o.push(r);i--,n.push(o)}else n.push(s)}return n},er=(e,t)=>{const n=e.toDelta();return n.length===t.length&&n.every((i,s)=>i.insert===t[s].text&&Ws(i.attributes||{}).length===t[s].marks.length&&se(i.attributes,(o,r)=>{var u;const l=Fi(r),c=t[s].marks;return c.find(h=>h.type.name===l)?$i(o,(u=c.find(h=>h.type.name===l))==null?void 0:u.attrs):!1}))},Te=(e,t)=>{if(e instanceof J&&!(t instanceof Array)&&pi(e,t)){const n=An(t);return e._length===n.length&&$i(e.getAttributes(),t.attrs)&&e.toArray().every((i,s)=>Te(i,n[s]))}return e instanceof nt&&t instanceof Array&&er(e,t)},pn=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((n,i)=>t[i]===n),ks=(e,t,n)=>{const i=e.toArray(),s=An(t),o=s.length,r=i.length,l=Zt(r,o);let c=0,a=0,u=!1;for(;c<l;c++){const h=i[c],f=s[c];if(pn(n.mapping.get(h),f))u=!0;else if(!Te(h,f))break}for(;c+a<l;a++){const h=i[r-a-1],f=s[o-a-1];if(pn(n.mapping.get(h),f))u=!0;else if(!Te(h,f))break}return{equalityFactor:c+a,foundMappedChild:u}},lu=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}},cu=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:i,str:s}=lu(e),o=t.map(a=>({insert:a.text,attributes:Object.assign({},i,nr(a.marks,n))})),{insert:r,remove:l,index:c}=Fh(s,o.map(a=>a.insert).join(""));e.delete(c,l),e.insert(c,r),e.applyDelta(o.map(a=>({retain:a.insert.length,attributes:a.attributes})))},au=/(.*)(--[a-zA-Z0-9+/=]{8})$/,Fi=e=>{var t;return((t=au.exec(e))==null?void 0:t[1])??e},hu=(e,t)=>{const n=[];for(const i in e)n.push(t.mark(Fi(i),e[i]));return n},nr=(e,t)=>{const n={};return e.forEach(i=>{if(i.type.name!=="ychange"){const s=Ct(t.isOMark,i.type,()=>!i.type.excludes(i.type));n[s?`${i.type.name}--${Xh(i.toJSON())}`:i.type.name]=i.attrs}}),n},fi=(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=An(n),o=s.length,r=t.toArray(),l=r.length,c=Zt(o,l);let a=0,u=0;for(;a<c;a++){const h=r[a],f=s[a];if(!pn(i.mapping.get(h),f))if(Te(h,f))i.mapping.set(h,f);else break}for(;u+a+1<c;u++){const h=r[l-u-1],f=s[o-u-1];if(!pn(i.mapping.get(h),f))if(Te(h,f))i.mapping.set(h,f);else break}e.transact(()=>{for(;l-a-u>0&&o-a-u>0;){const f=r[a],p=s[a],g=r[l-u-1],x=s[o-u-1];if(f instanceof nt&&p instanceof Array)er(f,p)||cu(f,p,i),a+=1;else{let w=f instanceof J&&pi(f,p),y=g instanceof J&&pi(g,x);if(w&&y){const v=ks(f,p,i),C=ks(g,x,i);v.foundMappedChild&&!C.foundMappedChild?y=!1:!v.foundMappedChild&&C.foundMappedChild||v.equalityFactor<C.equalityFactor?w=!1:y=!1}w?(fi(e,f,p,i),a+=1):y?(fi(e,g,x,i),u+=1):(i.mapping.delete(t.get(a)),t.delete(a,1),t.insert(a,[di(p,i)]),a+=1)}}const h=l-a-u;if(l===1&&o===0&&r[0]instanceof nt?(i.mapping.delete(r[0]),r[0].delete(0,r[0].length)):h>0&&(t.slice(a,a+h).forEach(f=>i.mapping.delete(f)),t.delete(a,h)),a+u<o){const f=[];for(let p=a;p<o-u;p++)f.push(di(s[p],i));t.insert(a,f)}},R)},pi=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,gn=(e,t,n)=>{if(e===0)return zn(t,0,-1);let i=t._first===null?null:t._first.content.type;for(;i!==null&&t!==i;){if(i instanceof nt){if(i._length>=e)return zn(i,e,-1);if(e-=i._length,i._item!==null&&i._item.next!==null)i=i._item.next.content.type;else{do i=i._item===null?null:i._item.parent,e--;while(i!==t&&i!==null&&i._item!==null&&i._item.next===null);i!==null&&i!==t&&(i=i._item===null?null:i._item.next.content.type)}}else{const s=(n.get(i)||{nodeSize:0}).nodeSize;if(i._first!==null&&e<s)i=i._first.content.type,e--;else{if(e===1&&i._length===0&&s>1)return new ln(i._item===null?null:i._item.id,i._item===null?ve(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 ln(i._item===null?null:i._item.id,i._item===null?ve(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!==nt&&i!==t)return uu(i._item.parent,i._item)}return zn(t,t._length,-1)},uu=(e,t)=>{let n=null,i=null;return e._item===null?i=ve(e):n=_(e._item.id.client,e._item.id.clock),new ln(n,i,t.id)},ge=(e,t,n,i)=>{const s=La(n,e);if(s===null||s.type!==t&&!ke(t,s.type._item))return null;let o=s.type,r=0;if(o.constructor===nt)r=s.index;else if(o._item===null||!o._item.deleted){let l=o._first,c=0;for(;c<o._length&&c<s.index&&l!==null;){if(!l.deleted){const a=l.content.type;c++,a instanceof nt?r+=a._length:r+=i.get(a).nodeSize}l=l.right}r+=1}for(;o!==t&&o._item!==null;){const l=o._item.parent;if(l._item===null||!l._item.deleted){r+=1;let c=l._first;for(;c!==null;){const a=c.content.type;if(a===o)break;c.deleted||(a instanceof nt?r+=a._length:r+=i.get(a).nodeSize),c=c.right}}o=l}return r-1};function du(e){const t=e.toArray(),n=i=>{let s;if(i instanceof nt)s=i.toDelta().map(r=>{const l={type:"text",text:r.insert};return r.attributes&&(l.marks=Object.keys(r.attributes).map(c=>{const a=r.attributes[c],h={type:Fi(c)};return Object.keys(a)&&(h.attrs=a),h})),l});else if(i instanceof J){s={type:i.nodeName};const o=i.getAttributes();Object.keys(o).length&&(s.attrs=o);const r=i.toArray();r.length&&(s.content=r.map(n).flat())}else Z();return s};return{type:"doc",content:t.map(n)}}const fu=e=>{const t=kt.getState(e).undoManager;if(t!=null)return t.undo(),!0},pu=e=>{const t=kt.getState(e).undoManager;if(t!=null)return t.redo(),!0},gu=new Set(["paragraph"]),mu=(e,t)=>!(e instanceof A)||!(e.content instanceof mt)||!(e.content.type instanceof Ot||e.content.type instanceof J&&t.has(e.content.type.nodeName))||e.content.type._length===0,xu=({protectedNodes:e=gu,trackedOrigins:t=[],undoManager:n=null}={})=>new T.Plugin({key:kt,state:{init:(i,s)=>{const o=R.getState(s),r=n||new Mo(o.type,{trackedOrigins:new Set([R].concat(t)),deleteFilter:l=>mu(l,e),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:r,prevSel:null,hasUndoOps:r.undoStack.length>0,hasRedoOps:r.redoStack.length>0}},apply:(i,s,o,r)=>{const l=R.getState(r).binding,c=s.undoManager,a=c.undoStack.length>0,u=c.redoStack.length>0;return l?{undoManager:c,prevSel:ui(l,o),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),o=kt.getState(i.state).undoManager;return o.on("stack-item-added",({stackItem:r})=>{const l=s.binding;l&&r.meta.set(l,kt.getState(i.state).prevSel)}),o.on("stack-item-popped",({stackItem:r})=>{const l=s.binding;l&&(l.beforeTransactionSelection=r.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{o.destroy()}}}});function ir(e){return!!e.getMeta(R)}function bu(e,t){const n=R.getState(e);return ge(n.doc,n.type,t,n.binding.mapping)||0}function sr(e,t){const n=R.getState(e);return gn(t,n.type,n.binding.mapping)}var Ye=class or extends T.MappablePosition{constructor(t,n){super(t),this.yRelativePosition=n}static fromJSON(t){return new or(t.position,t.yRelativePosition)}toJSON(){return{position:this.position,yRelativePosition:this.yRelativePosition}}};function wu(e,t){const n=sr(t,e);return new Ye(e,n)}function yu(e,t,n){const i=e instanceof Ye?e.yRelativePosition:null;if(ir(t)&&i){const r=bu(n,i);return{position:new Ye(r,i),mapResult:null}}const s=T.getUpdatedPosition(e,t),o=s.position.position;return{position:new Ye(o,i??sr(n,o)),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)=>yu(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>wu(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),kt.getState(t).undoManager.undoStack.length===0?!1:n?fu(t):!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),kt.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=xu(this.options.yUndoOptions),i=n.spec.view;n.spec.view=r=>{const{undoManager:l}=kt.getState(r.state);l.restore&&(l.restore(),l.restore=()=>{});const c=i?i(r):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},o=tu(t,s);return this.editor.options.enableContentCheck&&((e=t.doc)==null||e.on("beforeTransaction",()=>{try{const r=du(t);if(r.content.length===0)return;this.editor.schema.nodeFromJSON(r).check()}catch(r){return this.editor.emit("contentError",{error:r,editor:this.editor,disableCollaboration:()=>{var l;(l=t.doc)==null||l.destroy(),this.storage.isDisabled=!0}}),!1}})),[o,n,this.editor.options.enableContentCheck&&new Y.Plugin({key:new Y.PluginKey("filterInvalidContent"),filterTransaction:()=>{var r;return this.storage.isDisabled!==!1&&((r=t.doc)==null||r.destroy()),!0}})].filter(Boolean)}});function Cs(e){if(!e.length)return Rn.DecorationSet.empty;const t=[],n=e[0].$from.node(0);return e.forEach(i=>{const s=i.$from.pos,o=i.$from.nodeAfter;o&&t.push(Rn.Decoration.node(s,s+o.nodeSize,{class:"ProseMirror-selectednoderange"}))}),Rn.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 o=new kr.NodeRange(e,t,n),r=o.depth===0?0:s.resolve(o.start).posAtIndex(0);return o.parent.forEach((l,c)=>{const a=r+c,u=a+l.nodeSize;if(a<o.start||a>=o.end)return;const h=new Y.SelectionRange(s.resolve(a),s.resolve(u));i.push(h)}),i}var Su=class rr{constructor(t,n){this.anchor=t,this.head=n}map(t){return new rr(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 _t extends Y.Selection{constructor(t,n,i,s=1){const{doc:o}=t,r=t===n,l=t.pos===o.content.size&&n.pos===o.content.size,c=r&&!l?o.resolve(n.pos+(s>0?1:-1)):n,a=r&&l?o.resolve(t.pos-(s>0?1:-1)):t,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 _t&&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 _t(i,s)}toJSON(){return{type:"nodeRange",anchor:this.anchor,head:this.head}}get isForwards(){return this.head>=this.anchor}get isBackwards(){return!this.isForwards}extendBackwards(){const{doc:t}=this.$from;if(this.isForwards&&this.ranges.length>1){const s=this.ranges.slice(0,-1),o=s[0].$from,r=s[s.length-1].$to;return new _t(o,r,this.depth)}const n=this.ranges[0],i=t.resolve(Math.max(0,n.$from.pos-1));return new _t(this.$anchor,i,this.depth)}extendForwards(){const{doc:t}=this.$from;if(this.isBackwards&&this.ranges.length>1){const s=this.ranges.slice(1),o=s[0].$from,r=s[s.length-1].$to;return new _t(r,o,this.depth)}const n=this.ranges[this.ranges.length-1],i=t.resolve(Math.min(t.content.size,n.$to.pos+1));return new _t(this.$anchor,i,this.depth)}static fromJSON(t,n){return new _t(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,i,s,o=1){return new this(t.resolve(n),t.resolve(i),s,o)}getBookmark(){return new Su(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:o,tr:r}=i,{anchor:l,head:c}=o;if(!$e(o)){const u=Dt.create(s,l,c,t,-1);return r.setSelection(u),n.dispatch(r),!0}const a=o.extendBackwards();return r.setSelection(a),n.dispatch(r),!0},"Shift-ArrowDown":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,selection:o,tr:r}=i,{anchor:l,head:c}=o;if(!$e(o)){const u=Dt.create(s,l,c,t);return r.setSelection(u),n.dispatch(r),!0}const a=o.extendForwards();return r.setSelection(a),n.dispatch(r),!0},"Mod-a":({editor:e})=>{const{depth:t}=this.options,{view:n,state:i}=e,{doc:s,tr:o}=i,r=Dt.create(s,0,s.content.size,t);return o.setSelection(r),n.dispatch(o),!0}}},onSelectionUpdate(){const{selection:e}=this.editor.state;$e(e)&&this.editor.view.dom.classList.add("ProseMirror-noderangeselection")},addProseMirrorPlugins(){let e=!1,t=!1;return[new Y.Plugin({key:new Y.PluginKey("nodeRange"),props:{attributes:()=>e?{class:"ProseMirror-noderangeselection"}:{class:""},handleDOMEvents:{mousedown:(n,i)=>{const{key:s}=this.options,o=/Mac/.test(navigator.platform),r=!!i.shiftKey,l=!!i.ctrlKey,c=!!i.altKey,a=!!i.metaKey,u=o?a:l;return(s==null||s==="Shift"&&r||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,Cs(i.ranges)):null;const{$from:o,$to:r}=i;if(!s&&o.sameParent(r))return null;const l=Mn(o,r,this.options.depth);return l.length?(e=!0,Cs(l)):null}}})]}});function vu(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 ku(e){const t=e.cloneNode(!0),n=[e,...Array.from(e.getElementsByTagName("*"))],i=[t,...Array.from(t.getElementsByTagName("*"))];return n.forEach((s,o)=>{i[o].style.cssText=vu(s)}),t}var Cu={id:"listItemFirstChild",evaluate:({parent:e,isFirst:t})=>t&&e&&["listItem","taskItem"].includes(e.type.name)?1e3:0},Eu={id:"listWrapperDeprioritize",evaluate:({node:e})=>{const t=["listItem","taskItem"],n=e.firstChild;return n&&t.includes(n.type.name)?1e3:0}},_u={id:"tableStructure",evaluate:({node:e,parent:t})=>["tableRow","tableCell","tableHeader"].includes(e.type.name)||t&&t.type.name==="tableHeader"?1e3:0},Tu={id:"inlineContent",evaluate:({node:e})=>e.isInline||e.isText?1e3:0},Du=[Cu,Eu,_u,Tu],Es={edges:["left","top"],threshold:12,strength:500};function Gn(e){return e===void 0||e==="left"?{...Es}: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}:{...Es,...e}}function Iu(e,t,n){if(n.edges.length===0)return!1;const i=t.getBoundingClientRect(),{threshold:s,edges:o}=n;return o.some(r=>r==="left"?e.x-i.left<s:r==="right"?i.right-e.x<s:r==="top"?e.y-i.top<s:r==="bottom"?i.bottom-e.y<s:!1)}function Au(e,t,n,i){return!t||n.edges.length===0?0:Iu(e,t,n)?n.strength*i:0}var Mu=1e3;function _s(e,t,n,i){let s=Mu,o=!1;if(t.every(l=>{const c=l.evaluate(e);return s-=c,s<=0?(o=!0,!1):!0}),o)return-1;const r=e.view.nodeDOM(e.pos);return s-=Au(i,r,n,e.depth),s<=0?-1:s}function Ts(e,t,n){return Array.from({length:t},(s,o)=>t-1-o).some(s=>n.includes(e.node(s).type.name))}function Ou(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,o=s.resolve(i.pos),r=[];n.defaultRules&&r.push(...Du),r.push(...n.rules);const c=Array.from({length:o.depth},(h,f)=>o.depth-f).map(h=>{const f=o.node(h),p=o.before(h);if(n.allowedContainers&&h>0&&!Ts(o,h,n.allowedContainers))return null;const g=h>0?o.node(h-1):null,x=h>0?o.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:o,view:e},v=_s(y,r,n.edgeDetection,t);if(v<0)return null;const C=e.nodeDOM(p);return{node:f,pos:p,depth:h,score:v,dom:C}}).filter(h=>h!==null),a=o.nodeAfter;if(a&&a.isAtom&&!a.isInline){const h=i.pos,f=o.depth+1,p=o.parent,g=o.index(),x=p.childCount;let w=!0;if(n.allowedContainers&&(w=Ts(o,f,n.allowedContainers)),w){const y={node:a,pos:h,depth:f,parent:p,index:g,isFirst:g===0,isLast:g===x-1,$pos:o,view:e},v=_s(y,r,n.edgeDetection,t);if(v>=0){const C=e.nodeDOM(h);C&&c.push({node:a,pos:h,depth:f,score:v,dom:C})}}}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 ju(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 Ru(e,t,n,i=5){if(!Number.isFinite(t)||!Number.isFinite(n))return null;const s=e.dom,o=s.firstElementChild,r=s.lastElementChild;if(!o||!r)return null;const l=o.getBoundingClientRect(),c=r.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 lr=e=>{const{x:t,y:n,editor:i,nestedOptions:s}=e,{view:o,state:r}=i,l=Ru(o,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=Ou(o,{x:c,y:a},s);return g?{resultElement:g.dom,resultNode:g.node,pos:g.pos}:{resultElement:null,resultNode:null,pos:null}}const u=o.root.elementsFromPoint(c,a);let h;if(Array.prototype.some.call(u,g=>{if(!o.dom.contains(g))return!1;const x=ju(g,o);return x?(h=x,!0):!1}),!h)return{resultElement:null,resultNode:null,pos:null};let f;try{f=o.posAtDOM(h,0)}catch{return{resultElement:null,resultNode:null,pos:null}}const p=r.doc.nodeAt(f);if(!p){const g=r.doc.resolve(f),x=g.parent;return{resultElement:h,resultNode:x,pos:g.start()}}return{resultElement:h,resultNode:p,pos:f}};function cr(e){var t;(t=e.parentNode)==null||t.removeChild(e)}function Nu(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 o=lr({editor:t,x:e.clientX,y:e.clientY,nestedOptions:n});if(!o.resultNode||o.pos===null)return[];const r=o.resultNode.isText||o.resultNode.isAtom?0:-1,l=s.resolve(o.pos),c=s.resolve(o.pos+o.resultNode.nodeSize+r);return Mn(l,c,0)}function Bu(e,t,n,i){const{view:s}=t;if(!e.dataTransfer)return;const{empty:o,$from:r,$to:l}=s.state.selection,c=Nu(e,t,n,i),a=Mn(r,l,0),u=a.some(M=>c.find(P=>P.$from===M.$from&&P.$to===M.$to)),h=o||!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,v;w?(y=s.state.doc.slice(g,x),v=Y.NodeSelection.create(s.state.doc,g)):(v=Dt.create(s.state.doc,g,x),y=v.content()),h.forEach(M=>{const P=s.nodeDOM(M.$from.pos),S=ku(P);p.append(S)}),p.style.position="absolute",p.style.top="-10000px",document.body.append(p),e.dataTransfer.clearData(),e.dataTransfer.setDragImage(p,0,0);const C=v instanceof Y.NodeSelection?v:void 0;s.dragging={slice:y,move:!0,node:C},f.setSelection(v),s.dispatch(f),document.addEventListener("drop",()=>cr(p),{once:!0})}var Is=(e,t)=>{const n=e.resolve(t),{depth:i}=n;return i===0?t:n.pos-n.parentOffset-1},As=(e,t)=>{const n=e.nodeAt(t),i=e.resolve(t);let{depth:s}=i,o=n;for(;s>0;){const r=i.node(s);s-=1,s===0&&(o=r)}return o},Yn=(e,t)=>{const n=R.getState(e);return n?gn(t,n.type,n.binding.mapping):null},Lu=(e,t)=>{const n=R.getState(e);return n?ge(n.doc,n.type,t,n.binding.mapping)||0:-1},Ms=(e,t)=>{let n=t;for(;n!=null&&n.parentNode&&n.parentNode!==e.dom;)n=n.parentNode;return n},ar=new Y.PluginKey("dragHandle"),hr=({pluginKey:e=ar,element:t,editor:n,computePositionConfig:i,getReferencedVirtualElement:s,onNodeChange:o,onElementDragStart:r,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 v(S){const k=(s==null?void 0:s())||{getBoundingClientRect:()=>S.getBoundingClientRect()};H.computePosition(k,t,i).then(D=>{Object.assign(t.style,{position:D.strategy,left:`${D.x}px`,top:`${D.y}px`})})}function C(S){r==null||r(S),Bu(S,n,c,{node:h,pos:f}),t&&(t.dataset.dragging="true"),setTimeout(()=>{t&&(t.style.pointerEvents="none")},0)}function M(S){l==null||l(S),w(),t&&(t.style.pointerEvents="auto",t.dataset.dragging="false")}function P(){if(T.isFirefox()){const S=n.view.dom;requestAnimationFrame(()=>{S.isContentEditable&&(S.contentEditable="false",S.contentEditable="true")})}}return a.appendChild(t),{unbind(){t.removeEventListener("dragstart",C),t.removeEventListener("dragend",M),document.removeEventListener("drop",P),g&&(cancelAnimationFrame(g),g=null,x=null)},plugin:new Y.Plugin({key:typeof e=="string"?new Y.PluginKey(e):e,state:{init(){return{locked:!1}},apply(S,k,D,z){const N=S.getMeta("lockDragHandle"),$=S.getMeta("hideDragHandle");if(N!==void 0&&(u=N),$)return w(),u=!1,h=null,f=-1,o==null||o({editor:n,node:null,pos:-1}),k;if(S.docChanged&&f!==-1&&t)if(ir(S)){const G=Lu(z,p);G!==f&&(f=G)}else{const G=S.mapping.map(f);G!==f&&(f=G,p=Yn(z,f))}return k}},view:S=>{var k;return t.draggable=!0,t.style.pointerEvents="auto",t.dataset.dragging="false",(k=n.view.dom.parentElement)==null||k.appendChild(a),a.style.pointerEvents="none",a.style.position="absolute",a.style.top="0",a.style.left="0",t.addEventListener("dragstart",C),t.addEventListener("dragend",M),document.addEventListener("drop",P),{update(D,z){if(!t)return;if(!n.isEditable){w();return}if(u?t.draggable=!1:t.draggable=!0,S.state.doc.eq(z.doc)||f===-1)return;let N=S.nodeDOM(f);if(N=Ms(S,N),N===S.dom||(N==null?void 0:N.nodeType)!==1)return;const $=S.posAtDOM(N,0),G=As(n.state.doc,$),st=Is(n.state.doc,$);h=G,f=st,p=Yn(S.state,f),o==null||o({editor:n,node:h,pos:f}),v(N)},destroy(){t.removeEventListener("dragstart",C),t.removeEventListener("dragend",M),document.removeEventListener("drop",P),g&&(cancelAnimationFrame(g),g=null,x=null),t&&cr(a)}}},props:{handleDOMEvents:{keydown(S){return!t||u||S.hasFocus()&&(w(),h=null,f=-1,o==null||o({editor:n,node:null,pos:-1})),!1},mouseleave(S,k){return u||k.target&&!a.contains(k.relatedTarget)&&(w(),h=null,f=-1,o==null||o({editor:n,node:null,pos:-1})),!1},mousemove(S,k){return!t||u||(x={x:k.clientX,y:k.clientY},g)||(g=requestAnimationFrame(()=>{if(g=null,!x)return;const{x:D,y:z}=x;x=null;const N=lr({x:D,y:z,editor:n,nestedOptions:c});if(!N.resultElement)return;let $=N.resultElement,G=N.resultNode,st=N.pos;if(!(c!=null&&c.enabled)){if($=Ms(S,$),$===S.dom||($==null?void 0:$.nodeType)!==1)return;const E=S.posAtDOM($,0);G=As(n.state.doc,E),st=Is(n.state.doc,E)}G!==h&&(h=G,f=st??-1,p=Yn(S.state,f),o==null||o({editor:n,node:h,pos:f}),v($),y())})),!1}}}})}};function ur(e){var t,n;return e===!1||e===void 0?{enabled:!1,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Gn("none")}:e===!0?{enabled:!0,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Gn("left")}:{enabled:!0,rules:(t=e.rules)!=null?t:[],defaultRules:(n=e.defaultRules)!=null?n:!0,allowedContainers:e.allowedContainers,edgeDetection:Gn(e.edgeDetection)}}var gi={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=ur(this.options.nested);return[hr({computePositionConfig:{...gi,...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 Uu=e=>{const{className:t="drag-handle",children:n,editor:i,pluginKey:s=ar,onNodeChange:o,onElementDragStart:r,onElementDragEnd:l,computePositionConfig:c=gi,nested:a=!1}=e,[u,h]=b.useState(null),f=b.useRef(null),p=b.useMemo(()=>ur(a),[JSON.stringify(a)]);return b.useEffect(()=>{let g=null;return u?i.isDestroyed?()=>{f.current=null}:(f.current||(g=hr({editor:i,element:u,pluginKey:s,computePositionConfig:{...gi,...c},onElementDragStart:r,onElementDragEnd:l,onNodeChange:o,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,o,s,c,r,l,p]),d.jsx("div",{className:t,style:{visibility:"hidden",position:"absolute"},"data-dragging":"false",ref:h,children:n})},Pu=Uu;function $u(){var S,k,D,z,N,$,G,st;const e=m.useEditorInstance(),t=m.useEditableEditor(),{t:n}=B.useLocale(),[i,s]=b.useState(null),[o,r]=b.useState(-1),[l,c]=b.useState(!1),a=(k=(S=e==null?void 0:e.extensionManager)==null?void 0:S.extensions)==null?void 0:k.some(E=>(E==null?void 0:E.name)===Ns.TextAlign.name),u=(z=(D=e==null?void 0:e.extensionManager)==null?void 0:D.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)===Cr.Clear.name);function f(){const E=e.chain();E.setNodeSelection(o).unsetAllMarks(),(i==null?void 0:i.type.name)!=="paragraph"&&E.setParagraph(),E.run()}function p(){e.chain().focus().setNodeSelection(o).run(),document.execCommand("copy")}function g(){e.commands.setNodeSelection(o);const{$anchor:E}=e.state.selection,yt=E.node(1)||e.state.selection.node;e.chain().setMeta("hideDragHandle",!0).insertContentAt(o+((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,o,1);E.setMeta("hideDragHandle",!0),e.view.dispatch&&e.view.dispatch(E)}function y(){const E=ue.setNodeIndentMarkup(e.state.tr,o,-1);e.view.dispatch&&e.view.dispatch(E)}function v(){e.chain().setMeta("hideDragHandle",!0).setNodeSelection(o).deleteSelection().run()}const C=b.useCallback(E=>{E.node&&s(E.node),r(E.pos),requestAnimationFrame(()=>{E.editor.commands.focus()})},[]),M=E=>{var yt;if(E.preventDefault(),o!==-1){const je=(i==null?void 0:i.nodeSize)||0,Vt=o+je,Vi=(i==null?void 0:i.type.name)==="paragraph"&&((yt=i==null?void 0:i.content)==null?void 0:yt.size)===0,dr=Vi?o+2:Vt+2;e.chain().command(({dispatch:Hi,tr:On,state:zi})=>Hi?(Vi?On.insertText("/",o,o+1):On.insert(Vt,zi.schema.nodes.paragraph.create(null,[zi.schema.text("/")])),Hi(On)):!0).focus(dr).run()}};b.useEffect(()=>(l?e.commands.setMeta("lockDragHandle",!0):e.commands.setMeta("lockDragHandle",!1),()=>{e.commands.setMeta("lockDragHandle",!1)}),[l]);const P=E=>{t&&c(E)};return d.jsx(Pu,{className:"richtext-transition-all richtext-duration-200 richtext-ease-out",editor:e,onNodeChange:C,pluginKey:"RichTextBubbleMenuDragHandle",children:d.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-0.5",children:[d.jsx(m.ActionButton,{action:M,disabled:!t,icon:"Plus",tooltip:"Insert block"}),d.jsx(m.ActionButton,{disabled:!t,icon:"Grip",tooltip:"Click for options, Hold for drag",action:E=>{E.preventDefault(),E.stopPropagation(),P(!l)}}),d.jsxs(L.DropdownMenu,{onOpenChange:P,open:l,children:[d.jsx(L.DropdownMenuTrigger,{className:"richtext-pointer-events-none"}),d.jsxs(L.DropdownMenuContent,{align:"start",className:"richtext-w-48",hideWhenDetached:!0,side:"bottom",sideOffset:0,children:[d.jsxs(L.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:v,children:[d.jsx(m.IconComponent,{name:"Trash2"}),d.jsx("span",{children:n("editor.remove")})]}),h?d.jsxs(L.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(L.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(L.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(L.DropdownMenuSeparator,{}):null,a?d.jsxs(L.DropdownMenuSub,{children:[d.jsxs(L.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[d.jsx(m.IconComponent,{name:"AlignCenter"}),d.jsx("span",{children:n("editor.textalign.tooltip")})]}),d.jsx(L.DropdownMenuPortal,{children:d.jsxs(L.DropdownMenuSubContent,{children:[d.jsxs(L.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(L.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(L.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(L.DropdownMenuSub,{children:[d.jsxs(L.DropdownMenuSubTrigger,{className:"richtext-flex richtext-gap-3",children:[d.jsx(m.IconComponent,{name:"IndentIncrease"}),d.jsx("span",{children:n("editor.indent")})]}),d.jsx(L.DropdownMenuPortal,{children:d.jsxs(L.DropdownMenuSubContent,{children:[d.jsxs(L.DropdownMenuItem,{className:"richtext-flex richtext-gap-3",disabled:((G=i==null?void 0:i.attrs)==null?void 0:G.indent)>=ue.IndentProps.max,onClick:w,children:[d.jsx(m.IconComponent,{name:"IndentIncrease"}),d.jsx("span",{children:n("editor.indent.tooltip")})]}),d.jsxs(L.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]})]})]})})}exports.RichTextBubbleCallout=Lr;exports.RichTextBubbleColumns=Ur;exports.RichTextBubbleDrawer=tl;exports.RichTextBubbleExcalidraw=nl;exports.RichTextBubbleIframe=il;exports.RichTextBubbleImage=ul;exports.RichTextBubbleImageGif=dl;exports.RichTextBubbleKatex=ol;exports.RichTextBubbleLink=ll;exports.RichTextBubbleMenuDragHandle=$u;exports.RichTextBubbleMermaid=xl;exports.RichTextBubbleTable=bl;exports.RichTextBubbleText=Sl;exports.RichTextBubbleTwitter=vl;exports.RichTextBubbleVideo=fl;
|