@tryghost/koenig-lexical 0.0.64 → 0.0.65
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.
|
@@ -1109,8 +1109,8 @@ b`.split(/\n/).length!=3?function(c){for(var f=0,v=[],_=c.length;f<=_;){var E=c.
|
|
|
1109
1109
|
`]},VCt={link:"URL for the link:",image:"URL of the image:"},XCt={bold:"**",code:"```",italic:"*"};function Et(t){t=t||{},t.parent=this;var e=!0;if(t.autoDownloadFontAwesome===!1&&(e=!1),t.autoDownloadFontAwesome!==!0)for(var n=document.styleSheets,i=0;i<n.length;i++)n[i].href&&n[i].href.indexOf("//maxcdn.bootstrapcdn.com/font-awesome/")>-1&&(e=!1);if(e){var r=document.createElement("link");r.rel="stylesheet",r.href="https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css",document.getElementsByTagName("head")[0].appendChild(r)}if(t.element)this.element=t.element;else if(t.element===null){console.log("SimpleMDE: Error. No element was found.");return}if(t.toolbar===void 0){t.toolbar=[];for(var s in kS)kS.hasOwnProperty(s)&&(s.indexOf("separator-")!=-1&&t.toolbar.push("|"),(kS[s].default===!0||t.showIcons&&t.showIcons.constructor===Array&&t.showIcons.indexOf(s)!=-1)&&t.toolbar.push(s))}t.hasOwnProperty("status")||(t.status=["autosave","lines","words","cursor"]),t.previewRender||(t.previewRender=function(o){return this.parent.markdown(o)}),t.parsingConfig=cw({highlightFormatting:!0},t.parsingConfig||{}),t.insertTexts=cw({},HCt,t.insertTexts||{}),t.promptTexts=VCt,t.blockStyles=cw({},XCt,t.blockStyles||{}),t.shortcuts=cw({},UCt,t.shortcuts||{}),t.autosave!=null&&t.autosave.unique_id!=null&&t.autosave.unique_id!=""&&(t.autosave.uniqueId=t.autosave.unique_id),this.options=t,this.render(),t.initialValue&&(!this.options.autosave||this.options.autosave.foundSavedValue!==!0)&&this.value(t.initialValue)}Et.prototype.markdown=function(t){};Et.prototype.render=function(t){if(t||(t=this.element||document.getElementsByTagName("textarea")[0]),!(this._rendered&&this._rendered===t)){this.element=t;var e=this.options,n=this,i={};for(var r in e.shortcuts)e.shortcuts[r]!==null&&fk[r]!==null&&function(u){i[Ece(e.shortcuts[u])]=function(){fk[u](n)}}(r);i.Enter="newlineAndIndentContinueMarkdownList",i.Tab="tabAndIndentMarkdownList",i["Shift-Tab"]="shiftTabAndUnindentMarkdownList",i.Esc=function(u){u.getOption("fullScreen")&&km(n)},BCt&&(i.Home="goLineLeftSmart",i.End="goLineRight"),document.addEventListener("keydown",function(u){u=u||window.event,u.keyCode==27&&n.codemirror.getOption("fullScreen")&&km(n)},!1);var s,o;if(e.spellChecker!==!1?(s="spell-checker",o=e.parsingConfig,o.name="gfm",o.gitHubSpice=!1,PCt({codeMirrorInstance:hK})):(s=e.parsingConfig,s.name="gfm",s.gitHubSpice=!1),this.codemirror=hK.fromTextArea(t,{mode:s,backdrop:o,theme:"paper",tabSize:e.tabSize!=null?e.tabSize:2,indentUnit:e.tabSize!=null?e.tabSize:2,indentWithTabs:e.indentWithTabs!==!1,lineNumbers:!1,autofocus:e.autofocus===!0,extraKeys:i,lineWrapping:e.lineWrapping!==!1,allowDropFileTypes:["text/plain"],placeholder:e.placeholder||t.getAttribute("placeholder")||"",styleSelectedText:e.styleSelectedText!=null?e.styleSelectedText:!0}),e.forceSync===!0){var a=this.codemirror;a.on("change",function(){a.save()})}this.gui={},e.toolbar!==!1&&(this.gui.toolbar=this.createToolbar()),e.status!==!1&&(this.gui.statusbar=this.createStatusbar()),e.autosave!=null&&e.autosave.enabled===!0&&this.autosave(),this.gui.sideBySide=this.createSideBySide(),this._rendered=this.element;var l=this.codemirror;setTimeout(function(){l.refresh()}.bind(l),0)}};function Oce(){if(typeof localStorage=="object")try{localStorage.setItem("smde_localStorage",1),localStorage.removeItem("smde_localStorage")}catch{return!1}else return!1;return!0}Et.prototype.autosave=function(){if(Oce()){var t=this;if(this.options.autosave.uniqueId==null||this.options.autosave.uniqueId==""){console.log("SimpleMDE: You must set a uniqueId to use the autosave feature");return}t.element.form!=null&&t.element.form!=null&&t.element.form.addEventListener("submit",function(){localStorage.removeItem("smde_"+t.options.autosave.uniqueId)}),this.options.autosave.loaded!==!0&&(typeof localStorage.getItem("smde_"+this.options.autosave.uniqueId)=="string"&&localStorage.getItem("smde_"+this.options.autosave.uniqueId)!=""&&(this.codemirror.setValue(localStorage.getItem("smde_"+this.options.autosave.uniqueId)),this.options.autosave.foundSavedValue=!0),this.options.autosave.loaded=!0),localStorage.setItem("smde_"+this.options.autosave.uniqueId,t.value());var e=document.getElementById("autosaved");if(e!=null&&e!=null&&e!=""){var n=new Date,i=n.getHours(),r=n.getMinutes(),s="am",o=i;o>=12&&(o=i-12,s="pm"),o==0&&(o=12),r=r<10?"0"+r:r,e.innerHTML="Autosaved: "+o+":"+r+" "+s}this.autosaveTimeoutId=setTimeout(function(){t.autosave()},this.options.autosave.delay||1e4)}else console.log("SimpleMDE: localStorage not available, cannot autosave")};Et.prototype.clearAutosavedValue=function(){if(Oce()){if(this.options.autosave==null||this.options.autosave.uniqueId==null||this.options.autosave.uniqueId==""){console.log("SimpleMDE: You must set a uniqueId to clear the autosave value");return}localStorage.removeItem("smde_"+this.options.autosave.uniqueId)}else console.log("SimpleMDE: localStorage not available, cannot autosave")};Et.prototype.createSideBySide=function(){var t=this.codemirror,e=t.getWrapperElement(),n=e.nextSibling;(!n||!/editor-preview-side/.test(n.className))&&(n=document.createElement("div"),n.className="editor-preview-side",e.parentNode.insertBefore(n,e.nextSibling));var i=!1,r=!1;return t.on("scroll",function(s){if(i){i=!1;return}r=!0;var o=s.getScrollInfo().height-s.getScrollInfo().clientHeight,a=parseFloat(s.getScrollInfo().top)/o,l=(n.scrollHeight-n.clientHeight)*a;n.scrollTop=l}),n.onscroll=function(){if(r){r=!1;return}i=!0;var s=n.scrollHeight-n.clientHeight,o=parseFloat(n.scrollTop)/s,a=(t.getScrollInfo().height-t.getScrollInfo().clientHeight)*o;t.scrollTo(0,a)},n};Et.prototype.createToolbar=function(t){if(t=t||this.options.toolbar,!(!t||t.length===0)){var e;for(e=0;e<t.length;e++)kS[t[e]]!=null&&(t[e]=kS[t[e]]);var n=document.createElement("div");n.className="editor-toolbar";var i=this,r={};for(i.toolbar=t,e=0;e<t.length;e++)if(!(t[e].name=="guide"&&i.options.toolbarGuideIcon===!1)&&!(i.options.hideIcons&&i.options.hideIcons.indexOf(t[e].name)!=-1)&&!((t[e].name=="fullscreen"||t[e].name=="side-by-side")&&QCt())){if(t[e]==="|"){for(var s=!1,o=e+1;o<t.length;o++)t[o]!=="|"&&(!i.options.hideIcons||i.options.hideIcons.indexOf(t[o].name)==-1)&&(s=!0);if(!s)continue}(function(u){var d;u==="|"?d=YCt():d=qCt(u,i.options.toolbarTips,i.options.shortcuts),u.action&&(typeof u.action=="function"?d.onclick=function(p){p.preventDefault(),u.action(i)}:typeof u.action=="string"&&(d.href=u.action,d.target="_blank")),r[u.name||u]=d,n.appendChild(d)})(t[e])}i.toolbarElements=r;var a=this.codemirror;a.on("cursorActivity",function(){var u=Lp(a);for(var d in r)(function(p){var h=r[p];u[p]?h.className+=" active":p!="fullscreen"&&p!="side-by-side"&&p!="spellcheck"&&p!="hemmingway"&&(h.className=h.className.replace(/\s*active\s*/g,""))})(d)});var l=a.getWrapperElement();return l.parentNode.insertBefore(n,l),n}};Et.prototype.createStatusbar=function(t){t=t||this.options.status;var e=this.options,n=this.codemirror;if(!(!t||t.length===0)){var i=[],r,s,o;for(r=0;r<t.length;r++)if(s=void 0,o=void 0,typeof t[r]=="object")i.push({className:t[r].className,defaultValue:t[r].defaultValue,onUpdate:t[r].onUpdate});else{var a=t[r];a==="words"?(o=function(h){h.innerHTML=gK(n.getValue())},s=function(h){h.innerHTML=gK(n.getValue())}):a==="lines"?(o=function(h){h.innerHTML=n.lineCount()},s=function(h){h.innerHTML=n.lineCount()}):a==="cursor"?(o=function(h){h.innerHTML="0:0"},s=function(h){var g=n.getCursor();h.innerHTML=g.line+":"+g.ch}):a==="autosave"&&(o=function(h){e.autosave!=null&&e.autosave.enabled===!0&&h.setAttribute("id","autosaved")}),i.push({className:a,defaultValue:o,onUpdate:s})}var l=document.createElement("div");for(l.className="editor-statusbar",r=0;r<i.length;r++){var u=i[r],d=document.createElement("span");d.className=u.className,typeof u.defaultValue=="function"&&u.defaultValue(d),typeof u.onUpdate=="function"&&this.codemirror.on("update",function(h,g){return function(){g.onUpdate(h)}}(d,u)),l.appendChild(d)}var p=this.codemirror.getWrapperElement();return p.parentNode.insertBefore(l,p.nextSibling),l}};Et.prototype.value=function(t){return t===void 0?this.codemirror.getValue():(this.codemirror.getDoc().setValue(t),this)};Et.toggleBold=Jx;Et.toggleItalic=eR;Et.toggleStrikethrough=tR;Et.toggleBlockquote=iR;Et.toggleHeadingSmaller=Dy;Et.toggleHeadingBigger=rR;Et.toggleHeading1=sR;Et.toggleHeading2=oR;Et.toggleHeading3=aR;Et.toggleCodeBlock=nR;Et.toggleUnorderedList=lR;Et.toggleOrderedList=cR;Et.cleanBlock=uR;Et.drawLink=dR;Et.drawImage=fR;Et.drawTable=pR;Et.drawHorizontalRule=hR;Et.undo=mR;Et.redo=gR;Et.togglePreview=_R;Et.toggleSideBySide=Uv;Et.toggleFullScreen=km;Et.prototype.toggleBold=function(){Jx(this)};Et.prototype.toggleItalic=function(){eR(this)};Et.prototype.toggleStrikethrough=function(){tR(this)};Et.prototype.toggleBlockquote=function(){iR(this)};Et.prototype.toggleHeadingSmaller=function(){Dy(this)};Et.prototype.toggleHeadingBigger=function(){rR(this)};Et.prototype.toggleHeading1=function(){sR(this)};Et.prototype.toggleHeading2=function(){oR(this)};Et.prototype.toggleHeading3=function(){aR(this)};Et.prototype.toggleCodeBlock=function(){nR(this)};Et.prototype.toggleUnorderedList=function(){lR(this)};Et.prototype.toggleOrderedList=function(){cR(this)};Et.prototype.cleanBlock=function(){uR(this)};Et.prototype.drawLink=function(){dR(this)};Et.prototype.drawImage=function(){fR(this)};Et.prototype.drawTable=function(){pR(this)};Et.prototype.drawHorizontalRule=function(){hR(this)};Et.prototype.undo=function(){mR(this)};Et.prototype.redo=function(){gR(this)};Et.prototype.togglePreview=function(){_R(this)};Et.prototype.toggleSideBySide=function(){Uv(this)};Et.prototype.toggleFullScreen=function(){km(this)};Et.prototype.isPreviewActive=function(){var t=this.codemirror,e=t.getWrapperElement(),n=e.lastChild;return/editor-preview-active/.test(n.className)};Et.prototype.isSideBySideActive=function(){var t=this.codemirror,e=t.getWrapperElement(),n=e.nextSibling;return/editor-preview-active-side/.test(n.className)};Et.prototype.isFullscreenActive=function(){var t=this.codemirror;return t.getOption("fullScreen")};Et.prototype.getState=function(){var t=this.codemirror;return Lp(t)};Et.prototype.toTextArea=function(){var t=this.codemirror,e=t.getWrapperElement();e.parentNode&&(this.gui.toolbar&&e.parentNode.removeChild(this.gui.toolbar),this.gui.statusbar&&e.parentNode.removeChild(this.gui.statusbar),this.gui.sideBySide&&e.parentNode.removeChild(this.gui.sideBySide)),t.toTextArea(),this.autosaveTimeoutId&&(clearTimeout(this.autosaveTimeoutId),this.autosaveTimeoutId=void 0,this.clearAutosavedValue())};var KCt=Et;const jCt=t=>U.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",...t},U.createElement("title",null,"download"),U.createElement("path",{d:"M20 5.5l-8 8-8-8m-3.5 13h23",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeMiterlimit:10,fill:"none"})),ZCt=t=>U.createElement("svg",{viewBox:"0 0 32 32",...t},U.createElement("title",null,"unsplash-heart"),U.createElement("path",{d:"M17.4 29c-.8.8-2 .8-2.8 0L2.3 16.2C-.8 13.1-.8 8 2.3 4.8c3.1-3.1 8.2-3.1 11.3 0L16 7.6l2.3-2.8c3.1-3.1 8.2-3.1 11.3 0 3.1 3.1 3.1 8.2 0 11.4L17.4 29z"})),JCt={heart:ZCt,download:jCt};function LL({icon:t,label:e,...n}){const i=JCt[t];return Ee("a",{className:"flex h-8 shrink-0 cursor-pointer items-center rounded-md bg-white py-2 px-3 font-sans text-sm font-medium leading-6 text-grey-700 opacity-90 transition-all ease-in-out first-of-type:mr-3 hover:opacity-100",type:"button",onClick:r=>r.stopPropagation(),...n,children:[t&&I(i,{className:`h-4 w-4 fill-red stroke-[3px] ${e&&"mr-1"}`}),e&&I("span",{children:e})]})}function wce({payload:t,srcUrl:e,links:n,likes:i,user:r,alt:s,urls:o,height:a,width:l,zoomed:u,insertImage:d,selectImg:p}){return Ee("div",{className:`relative mb-6 block bg-grey-100 ${u?"h-full w-[max-content] cursor-zoom-out":"w-full cursor-zoom-in"}`,"data-kg-unsplash-gallery-item":!0,onClick:h=>{h.stopPropagation(),p(u?null:t)},children:[I("img",{alt:s,className:`${u?"h-full w-auto object-contain":""}`,height:a,loading:"lazy",src:e,width:l,"data-kg-unsplash-gallery-img":!0}),Ee("div",{className:"absolute inset-0 flex flex-col justify-between bg-gradient-to-b from-black/5 via-black/5 to-black/30 p-5 opacity-0 transition-all ease-in-out hover:opacity-100",children:[Ee("div",{className:"flex items-center justify-end",children:[I(LL,{"data-kg-button":"unsplash-like",href:`${n.html}/?utm_source=ghost&utm_medium=referral&utm_campaign=api-credit`,icon:"heart",label:i,rel:"noopener noreferrer",target:"_blank"}),I(LL,{"data-kg-button":"unsplash-download",href:`${n.download}/?utm_source=ghost&utm_medium=referral&utm_campaign=api-credit&force=true`,icon:"download"})]}),Ee("div",{className:"flex items-center justify-between",children:[Ee("div",{className:"flex items-center",children:[I("img",{alt:"author",className:"mr-2 h-8 w-8 rounded-full",src:r.profile_image.small}),I("div",{className:"mr-2 truncate font-sans text-sm font-medium text-white",children:r.name})]}),I(LL,{label:"Insert image","data-kg-unsplash-insert-button":!0,onClick:h=>{h.stopPropagation(),d({src:o.regular.replace(/&w=1080/,"&w=2000"),caption:`Photo by ${r.name} on Unsplash`,height:a,width:l,alt:s,links:n})}})]})]})]})}function Tce({payload:t,insertImage:e,selectImg:n,zoomed:i}){return I("div",{className:"flex h-full grow basis-0 justify-center","data-kg-unsplash-zoomed":!0,onClick:()=>n(null),children:I(wce,{alt:t.alt_description,height:t.height,insertImage:e,likes:t.likes,links:t.links,payload:t,selectImg:n,srcUrl:t.urls.regular,urls:t.urls,user:t.user,width:t.width,zoomed:i})})}Tce.propTypes={payload:et.object,insertImage:et.func,selectImg:et.func,zoomed:et.object||et.bool,srcUrl:et.string,alt:et.string,links:et.object,likes:et.number,user:et.object,urls:et.object,height:et.number,width:et.number};function ekt(){return I("div",{className:"absolute inset-y-0 left-0 flex w-full items-center justify-center overflow-hidden pb-[8vh]","data-kg-loader":!0,children:I("div",{className:"relative inline-block h-[50px] w-[50px] animate-spin rounded-full border border-black/10 before:z-10 before:mt-[7px] before:block before:h-[7px] before:w-[7px] before:rounded-full before:bg-grey-800"})})}function tkt(t){return I("div",{className:"mr-6 flex grow basis-0 flex-col justify-start last-of-type:mr-0",children:t.children})}function nkt(t){return t!=null&&t.columns?t==null?void 0:t.columns.map((e,n)=>I(tkt,{children:e.map(i=>I(wce,{alt:i.alt_description,height:i.height,insertImage:t==null?void 0:t.insertImage,likes:i.likes,links:i.links,payload:i,selectImg:t==null?void 0:t.selectImg,srcUrl:i.urls.regular,urls:i.urls,user:i.user,width:i.width,zoomed:t==null?void 0:t.zoomed},i.id))},n)):null}function PL(t){return I("div",{className:"relative h-full overflow-hidden","data-kg-unsplash-gallery":!0,children:Ee("div",{ref:t.galleryRef,className:`flex h-full w-full justify-center overflow-auto px-20 ${t!=null&&t.zoomed?"pb-10":""}`,"data-kg-unsplash-gallery-scrollref":!0,children:[t.children,(t==null?void 0:t.isLoading)&&I(ekt,{})]})})}function ikt({zoomed:t,error:e,galleryRef:n,isLoading:i,dataset:r,selectImg:s,insertImage:o}){return t?I(PL,{galleryRef:n,zoomed:t,children:I(Tce,{insertImage:o,payload:t,selectImg:s,zoomed:t})}):e?I(PL,{galleryRef:n,zoomed:t,children:Ee("div",{className:"flex h-full flex-col items-center justify-center",children:[I("h1",{className:"mb-4 text-2xl font-bold",children:"Error"}),I("p",{className:"text-lg font-medium",children:e})]})}):I(PL,{dataset:r,galleryRef:n,isLoading:i,zoomed:t,children:I(nkt,{columns:r,insertImage:o,selectImg:s,zoomed:t})})}const rkt=t=>U.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",strokeWidth:1.5,viewBox:"0 0 24 24",...t},U.createElement("title",null,"kg-search"),U.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",d:"M1.472 13.357a9.063 9.063 0 1 0 16.682-7.09 9.063 9.063 0 1 0-16.682 7.09Zm14.749 2.863 7.029 7.03"}));function Cce({closeModal:t,handleSearch:e,children:n,galleryRef:i}){return Ee(qn,{children:[I("div",{className:"fixed inset-0 z-40 h-[100vh] bg-black opacity-60"}),Ee("div",{ref:i,className:"not-kg-prose fixed inset-8 z-50 overflow-hidden rounded bg-white shadow-xl","data-kg-modal":"unsplash",children:[I("button",{className:"absolute top-6 right-6 cursor-pointer",type:"button",children:I(H6,{className:"h-4 w-4 stroke-2 text-grey-400","data-kg-modal-close-button":!0,onClick:()=>t()})}),Ee("div",{className:"flex h-full flex-col",children:[Ee("header",{className:"flex shrink-0 items-center justify-between py-10 px-20",children:[Ee("h1",{className:"flex items-center gap-2 font-sans text-3xl font-bold text-black",children:[I(h6,{className:"mb-1"}),"Unsplash"]}),Ee("div",{className:"relative w-full max-w-sm",children:[I(rkt,{className:"absolute top-1/2 left-4 h-4 w-4 -translate-y-2 text-grey-700"}),I("input",{className:"h-10 w-full rounded-full border border-grey-300 pr-8 pl-10 font-sans text-md font-normal text-black focus:border-grey-400 focus-visible:outline-none",placeholder:"Search free high-resolution photos",autoFocus:!0,"data-kg-unsplash-search":!0,onChange:e})]})]}),n]})]})]})}Cce.propTypes={closeModal:et.func,handleSearch:et.func};class skt{constructor(e){this.columnCount=e||3,this.columns=null,this.columnHeights=null}reset(){let e=[],n=[];for(let i=0;i<this.columnCount;i+=1)e[i]=[],n[i]=0;this.columns=e,this.columnHeights=n}addColumns(){for(let e=0;e<this.columnCount;e++)this.columns.push([]),this.columnHeights.push(0)}addPhotoToColumns(e){this.columns||this.reset();let n=Math.min(...this.columnHeights),i=this.columnHeights.indexOf(n);this.columnHeights[i]+=300*e.ratio,this.columns[i].push(e)}getColumns(){return this.columns}changeColumnCount(e){e!==this.columnCount&&(this.columnCount=e,this.reset())}}const $L=new skt(3);class okt{constructor({API_URL:e,HEADERS:n}){this.API_URL=e||"https://api.unsplash.com",this.HEADERS=n,this.photos=[],this._pagination=[],this.page=1,this.error=null,this.search_is_running=!1,this.request_is_running=!1,this.search_term="",this._lastRequestUrl="",this.isLoading=!1}extractPagination(e){e=e||e.results;let n={},i=new RegExp('<(.*)>; rel="(.*)"'),r=[];for(let s of e.headers.entries())s[0]==="link"&&r.push(s[1]);return r&&r.toString().split(",").forEach(s=>{if(s){let o=i.exec(s);n[o[2]]=o[1]}}),this._pagination=n,e}async checkStatus(e){if(e.status>=200&&e.status<300)return e;let n="",i;return e.headers.map["content-type"]==="application/json"?i=e.json().then(r=>r.errors[0]):e.headers.map["content-type"]==="text/xml"&&(i=e.text()),i.then(r=>{e.status===403&&e.headers.map["x-ratelimit-remaining"]==="0"&&(n="Unsplash API rate limit reached, please try again later."),n=n||r||`Error ${e.status}: Uh-oh! Trouble reaching the Unsplash API`,this.error=n;let s=new Error(n);throw s.response=e,s})}async makeRequest(e){if(this.request_is_running)return;this._lastRequestUrl=e;const n={method:"GET",headers:this.HEADERS};return this.request_is_running=!0,this.isLoading=!0,await fetch(e,n).then(i=>this.checkStatus(i)).then(i=>this.extractPagination(i)).then(i=>(this.request_is_running=!1,i.json())).catch(i=>this.error=i)}async loadNew(){this.reset();const e=`${this.API_URL}/photos?per_page=30`,n=await this.makeRequest(e);await this.addPhotosFromResponse(n)}async addPhotosFromResponse(e){(e.results||e).forEach(i=>{this.addPhoto(i)})}async addPhoto(e){e.ratio=e.width/e.height,this.photos.push(e),$L.addPhotoToColumns(e)}async loadNextPage(){if(!this.request_is_running&&!this.search_is_running&&this.photos.length!==0&&this._pagination.next){const e=`${this._pagination.next}`,n=await this.makeRequest(e);this.addPhotosFromResponse(n)}}async updateSearch(e){e!==this.search_term&&(this.request_is_running||(this.reset(),this.search_term=e,e?await this.search(e):await this.loadNew()))}async search(e){if(this.search_is_running!==!0){this.search_is_running=!0;const n=`${this.API_URL}/search/photos?query=${e}&per_page=30`,i=await this.makeRequest(n);i&&(this.addPhotosFromResponse(i),this.search_is_running=!1)}}triggerDownload(e){e.links.download_location&&this.makeRequest(e.links.download_location)}getPhotos(){return this.photos}clearPhotos(){this.photos=[]}getColumns(){return $L.getColumns()}reset(){this.clearPhotos(),$L.reset(),this.pagination=[]}setSearchTerm(e){this.search_term=e}}const akt="https://api.unsplash.com",kce=({onClose:t,onImageInsert:e,unsplashConf:n})=>{const i=U.useMemo(()=>new okt({API_URL:akt,HEADERS:n.defaultHeaders}),[n.defaultHeaders]),r=ue.useRef(null),[s,o]=ue.useState(0),[a,l]=ue.useState(0),[u,d]=ue.useState(i.search_is_running||!0),p=ue.useRef(!1),[h,g]=ue.useState(""),[y,O]=ue.useState(null),[b,w]=ue.useState(i.getColumns()||[]);ue.useEffect(()=>{y===null&&a!==0&&(r.current.scrollTop=a,l(0))},[y,s,a]),ue.useEffect(()=>{const q=r.current;if(!y)return q&&q.addEventListener("scroll",()=>{o(q.scrollTop)}),()=>{q&&q.removeEventListener("scroll",()=>{o(q.scrollTop)})}},[r,y]);const T=ue.useCallback(async()=>{if(p.current===!1||h.length===0){w([]),await i.clearPhotos(),await i.loadNew();const q=i.getColumns();w(q),r.current.scrollTop!==0&&(r.current.scrollTop=0),d(!1)}},[i,h]),x=async q=>{const H=q.target.value;H.length>2&&(O(null),g(H)),H.length===0&&(g(""),p.current=!1,await T())},R=ue.useCallback(async()=>{if(h){d(!0),i.clearPhotos(),await i.updateSearch(h);const q=i.getColumns();w(q),r.current.scrollTop!==0&&(r.current.scrollTop=0),d(!1)}},[h,i]);ue.useEffect(()=>{const q=setTimeout(async()=>{h.length>2?await R():await T()},300);return()=>{p.current=!0,clearTimeout(q)}},[h,R,T]);const A=ue.useCallback(async()=>{d(!0),await i.loadNextPage();const q=i.getColumns();w(q),d(!1)},[i]);ue.useEffect(()=>{const q=r.current;if(q){const H=async()=>{y===null&&q.scrollTop+q.clientHeight>=q.scrollHeight-1e3&&await A()};return q.addEventListener("scroll",H),()=>{q.removeEventListener("scroll",H)}}},[r,A,y]);const L=q=>{q&&(O(q),l(s)),q===null&&(r.current.scrollTop=a,O(null))};async function F(q){q.src&&(i.triggerDownload(q),e(q))}return I(pE,{children:I(Cce,{closeModal:t,handleSearch:x,children:I(ikt,{dataset:b,error:i.error,galleryRef:r,insertImage:F,isLoading:u,selectImg:L,zoomed:y})})})},FL=navigator.userAgent.indexOf("Mac")!==-1?"Cmd":"Ctrl";function lkt(t,e){const n=U.useRef(null),{progress:i,upload:r,errors:s,isLoading:o,filesNumber:a}=e("image"),l=async h=>{const g=h.target.files,y=await r(g);p(y)};function u(){n.current.click()}function d({src:h,alt:g,caption:y}){let O={alt:g,url:h,credit:`<small>${y}</small>`};p([O])}function p(h=[]){const g=t.current.codemirror;let O=h.map(b=>{if(typeof b=="string"){let w=b.split("/").pop(),T=w;return w.lastIndexOf(".")>0&&(T=w.slice(0,w.lastIndexOf("."))),``}else{let w=``;return b.credit&&(w+=`
|
|
1110
1110
|
${b.credit}`),w}}).join(`
|
|
1111
1111
|
|
|
1112
|
-
`);t.current.codemirror.focus(),g.replaceSelection(O,"end")}return{openImageUploadDialog:u,uploadImages:l,insertUnsplashImage:d,imageInputRef:n,progress:i,errors:s,isLoading:o,filesNumber:a}}function ckt({markdown:t,updateMarkdown:e,imageUploader:n,unsplashConf:i,autofocus:r=!0,placeholder:s=""}){const o=U.useRef(null),a=U.useRef(null),[l,u]=U.useState(!1),[d,p]=U.useState(!1),{openImageUploadDialog:h,uploadImages:g,insertUnsplashImage:y,imageInputRef:O,progress:b,errors:w,isLoading:T,filesNumber:x}=lkt(a,n),R={openImageDialog:`${FL}-Alt-I`,toggleSpellcheck:`${FL}-Alt-S`,openUnsplashDialog:`${FL}-Alt-U`};U.useLayoutEffect(()=>{a.current=new KCt({element:o.current,autofocus:r,indentWithTabs:!1,placeholder:s,tabSize:4,shortcuts:{toggleFullScreen:null,togglePreview:null,toggleSideBySide:null,drawImage:null},hideIcons:Z(),status:[],toolbar:["bold","italic","heading","|","quote","unordered-list","ordered-list","|","link",{name:"image",action:h,className:"fa fa-picture-o",title:`Upload Image(s) (${R.openImageDialog})`},{name:"unsplash",action:Y,className:"fa fa-camera",title:`Add Image from Unsplash (${R.openUnsplashDialog})`},"|",{name:"spellcheck",action:L,className:"fa fa-check active",title:`Spellcheck (${R.toggleSpellcheck})`},{name:"guide",action:q,className:"fa fa-question-circle",title:"Markdown Guide"}]});const V=a.current;return V.value(t??""),V.codemirror.on("change",(z,X)=>{X.origin!=="setValue"&&e(a.current.value())}),V.codemirror.setOption("specialChars",/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff\xa0]/g),r&&V.codemirror.execCommand("goDocEnd"),V.codemirror.on("mousedown",(z,X)=>{X.stopPropagation()}),A(),()=>{a.current.toTextArea()}},[]);function A(){const V=a.current.codemirror,z=V.getOption("extraKeys");z[R.toggleSpellcheck]=L,z[R.openImageDialog]=h,i&&(z[R.openUnsplashDialog]=Y),V.setOption("extraKeys",z)}function L(){let V=a.current.codemirror;V.getOption("mode")==="spell-checker"?V.setOption("mode","gfm"):V.setOption("mode","spell-checker"),F()}function F(){let V=a.current.toolbarElements.spellcheck;V&&(a.current.codemirror.getOption("mode")==="spell-checker"?V.classList.add("active"):V.classList.remove("active"))}function q(){u(!0)}function H(){u(!1)}function Z(){let V=[];return i||V.push("unsplash"),V}function Y(){p(!0)}function G(){a.current.codemirror.focus(),p(!1)}function ie(V){y(V),p(!1)}return Ee("div",{className:"not-kg-prose",children:[I("textarea",{ref:o}),I(TCt,{isOpen:l,onClose:H}),I(xCt,{errors:w,filesNumber:x,inputRef:O,loading:T,progress:b,onChange:g}),d&&I(kce,{unsplashConf:i,onClose:G,onImageInsert:ie})]})}function xce({markdown:t="",updateMarkdown:e,isEditing:n,imageUploader:i,unsplashConf:r}){return I(qn,{children:n?I("div",{className:"markdown-editor",children:I(ckt,{imageUploader:i,markdown:t,unsplashConf:r,updateMarkdown:e})}):I(ukt,{markdown:t})})}function ukt({markdown:t}){const e=bee.render(t),n=mce(e,{replaceJS:!0});return I("div",{dangerouslySetInnerHTML:{__html:n},className:"whitespace-normal"})}xce.propTypes={markdown:et.string};const dkt=t=>U.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",...t},U.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",d:"M2 14V6l4 4 4-4v8m6-7.93v7.916M13.5 11.5l2.48 2.525L18.5 11.5"}));function fkt({nodeKey:t,markdown:e}){const[n]=Qt.useLexicalComposerContext(),i=ue.useContext(qa),{fileUploader:r,cardConfig:s}=ue.useContext(Io),o=a=>{n.update(()=>{J.$getNodeByKey(t).setMarkdown(a)})};return I(xce,{imageUploader:r.useFileUpload,isEditing:i.isEditing,markdown:e,nodeKey:t,unsplashConf:s.unsplash,updateMarkdown:o})}class vR extends jlt{static getType(){return"markdown"}getIcon(){return A3}decorate(){return I(Id,{IndicatorIcon:dkt,nodeKey:this.getKey(),width:this.__cardWidth,wrapperStyle:"wide",children:I(fkt,{markdown:this.__markdown,nodeKey:this.getKey()})})}}He(vR,"kgMenu",{label:"Markdown",desc:"Insert a Markdown editor card",Icon:A3,insertCommand:wee,matches:["markdown","md"]});function pkt(t){return new vR(t)}var Rce={},hkt=Qt,mkt=U;Rce.AutoFocusPlugin=function({defaultSelection:t}){let[e]=hkt.useLexicalComposerContext();return mkt.useEffect(()=>{e.focus(()=>{let n=document.activeElement,i=e.getRootElement();i===null||n!==null&&i.contains(n)||i.focus({preventScroll:!0})},{defaultSelection:t})},[t,e]),null};const gkt=Rce;var _kt=gkt;const vkt=({text:t="Type here",className:e=""})=>I("div",{className:`not-kg-prose pointer-events-none absolute top-0 left-0 min-w-full cursor-text ${e}`,children:t}),_K=({text:t,setText:e,placeholderText:n,textClassName:i,placeholderClassName:r,readOnly:s,autoFocus:o=!1,singleParagraph:a=!1})=>I(Gv,{nodes:Fce,children:Ee(yp,{className:i,isDragEnabled:!1,markdownTransformers:wle,placeholder:I(vkt,{className:r,text:n}),readOnly:s,children:[a&&I(TE,{paragraphs:1}),o&&I(_kt.AutoFocusPlugin,{}),I(yR,{html:t,setHtml:e})]})}),Skt=t=>U.createElement("svg",{id:"Regular",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",...t},U.createElement("defs",null,U.createElement("style",null,".cls-1{fill:none;stroke:currentColor;stroke-linecap:round;stroke-linejoin:round;fill-rule:evenodd;}")),U.createElement("title",null,"arrow-down-1"),U.createElement("path",{className:"cls-1",d:"M23.25,7.311,12.53,18.03a.749.749,0,0,1-1.06,0L.75,7.311"}));function l9({content:t,contentPlaceholder:e,focusOnContent:n,focusOnHeader:i,header:r,headerPlaceholder:s,isContentFocused:o,isContentVisible:a,isEditing:l,isHeaderFocused:u,setContent:d,setHeader:p,toggleContent:h,toggleRef:g}){return Ee("div",{className:"rounded border border-grey/40 py-4 px-6 dark:border-grey/30",children:[Ee("div",{className:"flex cursor-text items-start justify-between",children:[I("div",{className:"mr-2 w-full",onClick:i,onKeyDown:n,children:I(_K,{autoFocus:u,placeholderClassName:"kg-toggle-header-placeholder",placeholderText:s,readOnly:!l,setText:p,singleParagraph:!0,text:r,textClassName:"kg-toggle-header-text"})}),I("div",{ref:g,className:"ml-auto mt-[-1px] flex h-8 w-8 shrink-0 items-center justify-center",onClick:h,children:I(Skt,{className:`h-4 w-4 stroke-2 text-grey-400 dark:text-grey/30 ${a?"rotate-180":"rotate-0"}`})})]}),I("div",{className:`mt-2 w-full ${a?"visible":"hidden"}`,children:I(_K,{autoFocus:o,placeholderClassName:"kg-toggle-content-placeholder",placeholderText:e,readOnly:!l,setText:d,text:t,textClassName:"kg-toggle-content-text"})})]})}l9.propTypes={content:et.string,contentPlaceholder:et.string,focusOnContent:et.func,focusOnHeader:et.func,header:et.string,headerPlaceholder:et.string,isContentFocused:et.bool,isContentVisible:et.bool,isEditing:et.bool,isHeaderFocused:et.bool,setContent:et.func,setHeader:et.func,toggleContent:et.func,toggleRef:et.object};l9.defaultProps={content:"",contentPlaceholder:"Collapsible content",header:"",headerPlaceholder:"Toggle Header",isContentFocused:!1,isContentVisible:!1,isEditing:!1,isHeaderFocused:!0};function ykt({nodeKey:t,content:e,header:n}){const[i]=Qt.useLexicalComposerContext(),r=ue.useContext(qa),{isEditing:s}=r,[o,a]=U.useState(!1),[l,u]=U.useState(!1),[d,p]=U.useState(!0),h=U.useRef(null);return U.useEffect(()=>{h&&h.current&&h.current.click()},[]),I(l9,{content:e,contentPlaceholder:"Collapsible content",focusOnContent:T=>{T.key==="Enter"&&(p(!1),u(!0),!o&&h&&h.current&&h.current.click())},focusOnHeader:T=>{u(!1),p(!0)},header:n,headerPlaceholder:"Toggle header",isContentFocused:l,isContentVisible:o,isEditing:s,isHeaderFocused:d,setContent:T=>{i.update(()=>{J.$getNodeByKey(t).setContent(T)})},setHeader:T=>{i.update(()=>{J.$getNodeByKey(t).setHeader(T)})},toggleContent:()=>{a(!o)},toggleRef:h})}class SR extends Tct{getIcon(){return I3}createDOM(){return document.createElement("div")}decorate(){return I(Id,{nodeKey:this.getKey(),width:this.__cardWidth,children:I(ykt,{content:this.__content,header:this.__header,nodeKey:this.getKey()})})}}He(SR,"kgMenu",[{label:"Toggle",desc:"Add collapsible content",Icon:I3,insertCommand:xee,matches:["toggle","collapse"]}]);const Ekt=t=>new SR(t);function bkt(t){return new Promise((e,n)=>{const i=t.type;let r,s,o;const a=document.createElement("video");a.preload="metadata",a.muted=!0,a.playsInline=!0,a.onerror=n,a.onloadedmetadata=function(){r=a.duration,s=a.videoWidth,o=a.videoHeight,setTimeout(()=>{a.currentTime=.5},200)},a.onseeked=function(){const l=document.createElement("canvas");l.width=s,l.height=o;const u=l.getContext("2d");u.drawImage(a,0,0,s,o),window.URL.revokeObjectURL(a.src),u.canvas.toBlob(d=>{e({duration:r,width:s,height:o,mimeType:i,thumbnailBlob:d})},"image/jpeg",.75)},a.src=URL.createObjectURL(t)})}function Okt({thumbnail:t,customThumbnail:e,onCustomThumbnailChange:n,videoUploader:i={},customThumbnailUploader:r={},onRemoveCustomThumbnail:s,totalDuration:o,cardWidth:a,isLoopChecked:l,onLoopChange:u,onCardWidthChange:d,isEditing:p,thumbnailMimeTypes:h,thumbnailDragHandler:g={}}){var b;const y={width:`${(b=i.progress)==null?void 0:b.toFixed(0)}%`},O=[{label:"Regular",name:"regular",Icon:f6},{label:"Wide",name:"wide",Icon:p6},{label:"Full",name:"full",Icon:d6}];return Ee(qn,{children:[Ee("div",{className:"not-kg-prose relative","data-testid":"video-card-populated",children:[Ee("div",{children:[I("img",{alt:"Video thumbnail",className:"mx-auto",src:t}),e&&I("img",{alt:"Video custom thumbnail",className:"absolute inset-0 h-full w-full bg-white object-cover",src:e})]}),I("div",{className:"absolute inset-0 flex items-center justify-center bg-gradient-to-t from-black/0 via-black/5 to-black/30",children:i.isLoading||I("button",{className:"flex h-20 w-20 items-center justify-center rounded-full bg-black/50",type:"button",children:I(Lle,{className:"h-auto w-5 fill-white"})})}),I("div",{className:`absolute bottom-0 flex h-20 w-full justify-end bg-gradient-to-b from-black/0 to-black/50 ${a==="full"?"px-7 py-4":"px-4"}`,children:I(t9,{duration:o,theme:"light"})})]}),i.isLoading&&I("div",{className:"absolute inset-0 flex min-w-full items-center justify-center overflow-hidden bg-white/50","data-testid":"video-progress",children:I(Lm,{bgStyle:"transparent",style:y})}),!!t&&!i.isLoading&&p&&Ee(uce,{children:[I(LTt,{buttons:O,label:"Video width",selectedName:a,onClick:d}),I(dce,{dataTestID:"loop-video",description:"Autoplay your video on a loop without sound.",isChecked:l,label:"Loop",onChange:u}),!l&&I($Tt,{alt:"Custom thumbnail",dataTestID:"custom-thumbnail-replace",errors:r.errors,icon:"file",isDraggedOver:g.isDraggedOver,isLoading:r.isLoading,label:"Custom thumbnail",mimeTypes:h,placeholderRef:g.setRef,progress:r.progress,size:"xsmall",src:e,onFileChange:n,onRemoveCustomThumbnail:s})]})]})}function wkt({onFileChange:t,fileInputRef:e,errors:n,videoMimeTypes:i=[],videoDragHandler:r={}}){return Ee(qn,{children:[I(aE,{desc:"Click to select a video",errors:n,filePicker:()=>fa({fileInputRef:e}),icon:"video",isDraggedOver:r.isDraggedOver,placeholderRef:r.setRef}),I("form",{onChange:t,children:I("input",{ref:e,accept:i.join(","),hidden:!0,name:"image-input",type:"file"})})]})}const Tkt=({fileInputRef:t,onVideoFileChange:e,videoDragHandler:n,videoUploader:i={},videoUploadErrors:r,videoMimeTypes:s,...o})=>o.customThumbnail||o.thumbnail||i.isLoading?I(Okt,{...o,videoUploader:i}):I(wkt,{errors:r,fileInputRef:t,videoDragHandler:n,videoMimeTypes:s,onFileChange:e});function Nce({caption:t,onCaptionChange:e,isSelected:n,isEditing:i,...r}){return I(qn,{children:Ee("figure",{children:[I(Tkt,{...r,isEditing:i}),I(W6,{caption:t||"",captionPlaceholder:"Type caption for video (optional)",dataTestId:"video-card-caption",isSelected:n,readOnly:!i,setCaption:e})]})})}Nce.propTypes={caption:et.string};function Ckt({nodeKey:t,thumbnail:e,customThumbnail:n,caption:i,totalDuration:r,cardWidth:s,triggerFileDialog:o,isLoopChecked:a,initialFile:l}){var ae;const[u]=Qt.useLexicalComposerContext(),{fileUploader:d}=ue.useContext(Io),p=ue.useContext(qa),h=ue.useRef(),[g,y]=U.useState(""),O=d.useFileUpload("video"),b=d.useFileUpload("mediaThumbnail"),w=d.useFileUpload("image"),T=HS({handleDrop:G}),x=HS({handleDrop:ie}),[R,A]=U.useState([]),L=((ae=d.fileTypes.video)==null?void 0:ae.mimeTypes)||["video/*"];ue.useEffect(()=>{(async be=>{be&&!O.isLoading&&await F([be])})(l)},[]);const F=async pe=>{var Nt,nt;const be=pe[0];if(!be)return;let K,$,_e,Ce;try{({thumbnailBlob:K,duration:$,width:_e,height:Ce}=await bkt(be))}catch{A([{name:be.name,message:`The file type you uploaded is not supported. Please use .${L.join(", .").toUpperCase()}`}])}y(URL.createObjectURL(K));const ke=await O.upload([be]),Ye=(Nt=ke==null?void 0:ke[0])==null?void 0:Nt.url;if(!Ye){y("");return}Ye&&u.update(()=>{const At=J.$getNodeByKey(t);At.setSrc(Ye),At.setDuration($),At.setVideoWidth(_e),At.setVideoHeight(Ce)});const Rt=new File([K],`${be.name}.jpg`,{type:"image/jpeg"}),ct=await b.upload([Rt],{formData:{url:Ye}}),Ct=(nt=ct==null?void 0:ct[0])==null?void 0:nt.url;Ct&&u.update(()=>{J.$getNodeByKey(t).setThumbnailSrc(Ct)}),y("")},q=async pe=>{pe.target.files[0]&&await F(pe.target.files)},H=pe=>{u.update(()=>{J.$getNodeByKey(t).setCaption(pe)})},Z=async pe=>{var $;const be=await w.upload(pe),K=($=be==null?void 0:be[0])==null?void 0:$.url;K&&u.update(()=>{J.$getNodeByKey(t).setCustomThumbnailSrc(K)})},Y=async pe=>{await Z(pe.target.files)};async function G(pe){await F(pe)}async function ie(pe){await Z(pe)}const V=()=>{u.update(()=>{J.$getNodeByKey(t).setCustomThumbnailSrc("")})},z=pe=>{u.update(()=>{J.$getNodeByKey(t).setLoop(pe.target.checked)})},X=pe=>{u.update(()=>{J.$getNodeByKey(t).setCardWidth(pe),p.setCardWidth(pe)})},ne=pe=>{pe.preventDefault(),pe.stopPropagation(),p.setEditing(!0)};ue.useEffect(()=>{if(!o)return;const pe=setTimeout(()=>{fa({fileInputRef:h}),u.update(()=>{J.$getNodeByKey(t).setTriggerFileDialog(!1)})});return()=>{clearTimeout(pe)}});const se=n||e;return Ee(qn,{children:[I(Nce,{caption:i,cardWidth:s,customThumbnail:n,customThumbnailUploader:w,fileInputRef:h,isEditing:p.isEditing,isLoopChecked:a,isSelected:p.isSelected,thumbnail:g||e,thumbnailDragHandler:x,thumbnailMimeTypes:d.fileTypes.image.mimeTypes,totalDuration:r,videoDragHandler:T,videoMimeTypes:L,videoUploader:O,videoUploadErrors:[...b.errors,...R,...O.errors],onCaptionChange:H,onCardWidthChange:X,onCustomThumbnailChange:Y,onLoopChange:z,onRemoveCustomThumbnail:V,onVideoFileChange:q}),I(VS,{"data-kg-card-toolbar":"video",isVisible:se&&p.isSelected&&!p.isEditing,children:Ee(lE,{children:[I(Kr,{dataTestId:"edit-video-card",icon:"edit",isActive:!1,label:"Edit",onClick:ne}),I(V_,{}),I(Kr,{icon:"snippet",isActive:!1,label:"Snippet"})]})})]})}class My extends rct{constructor(n={},i){super(n,i);He(this,"__triggerFileDialog",!1);He(this,"__initialFile",null);const{triggerFileDialog:r,initialFile:s}=n;this.__triggerFileDialog=!n.src&&r,this.__initialFile=s||null}getIcon(){return D3}setTriggerFileDialog(n){const i=this.getWritable();return i.__triggerFileDialog=n}decorate(){return I(Id,{nodeKey:this.getKey(),width:this.getCardWidth(),children:I(Ckt,{caption:this.getCaption(),cardWidth:this.getCardWidth(),customThumbnail:this.getCustomThumbnailSrc(),initialFile:this.__initialFile,isLoopChecked:this.getLoop(),nodeKey:this.getKey(),thumbnail:this.getThumbnailSrc(),totalDuration:this.getFormattedDuration(),triggerFileDialog:this.__triggerFileDialog})})}}He(My,"kgMenu",[{label:"Video",desc:"Upload and play a video file",Icon:D3,insertCommand:q3,insertParams:{triggerFileDialog:!0},matches:["video"]}]),He(My,"uploadType","video");const kkt=t=>new My(t),xkt=[$a.HeadingNode,bo.ListNode,bo.ListItemNode,$a.QuoteNode,Kie,Ov.LinkNode,zx,bE,vm,vR,Iy,My,jx,Zx,SR],Rkt={paragraph:void 0,heading:{h1:void 0,h2:void 0,h3:void 0,h4:void 0,h5:void 0,h6:void 0},quote:void 0,aside:void 0,list:{nested:{listitem:"!list-none"},ol:void 0,ul:void 0,listitem:void 0},link:void 0,text:{bold:void 0,italic:"italic",overflowed:void 0,hashtag:void 0,underline:void 0,strikethrough:void 0,underlinestrikethrough:void 0,code:void 0},code:void 0};var Ace={},vK=Qt,W0=J,pk=U;let Ice=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";var Nkt=Ice?pk.useLayoutEffect:pk.useEffect;let uw={tag:"history-merge"};function Akt(t,e){if(e!==null){if(e===void 0)t.update(()=>{var n=W0.$getRoot();if(n.isEmpty()){let i=W0.$createParagraphNode();n.append(i),n=Ice?document.activeElement:null,(W0.$getSelection()!==null||n!==null&&n===t.getRootElement())&&i.select()}},uw);else if(e!==null)switch(typeof e){case"string":let n=t.parseEditorState(e);t.setEditorState(n,uw);break;case"object":t.setEditorState(e,uw);break;case"function":t.update(()=>{W0.$getRoot().isEmpty()&&e(t)},uw)}}}Ace.LexicalComposer=function({initialConfig:t,children:e}){let n=pk.useMemo(()=>{const{theme:i,namespace:r,editor__DEPRECATED:s,nodes:o,onError:a,editorState:l}=t,u=vK.createLexicalComposerContext(null,i);let d=s||null;if(d===null){const p=W0.createEditor({editable:!1,namespace:r,nodes:o,onError:h=>a(h,p),theme:i});Akt(p,l),d=p}return[d,u]},[]);return Nkt(()=>{let i=t.editable,[r]=n;r.setEditable(i!==void 0?i:!0)},[]),pk.createElement(vK.LexicalComposerContext.Provider,{value:n},e)};const Ikt=Ace;var Dkt=Ikt;function Mkt(t){console.error(t)}const Lkt={namespace:"KoenigEditor",theme:Rkt},Gv=({initialEditorState:t,nodes:e=[...xkt],onError:n=Mkt,fileUploader:i={},cardConfig:r={},darkMode:s=!1,children:o})=>{const[a,l]=ue.useState(null),[u,d]=ue.useState(!1),p=ue.useMemo(()=>Object.assign({},Lkt,{nodes:e,editorState:t,onError:n}),[t,e,n]),h=ue.useRef(null);return i.useFileUpload||(i.useFileUpload=function(){console.error("<KoenigComposer> requires a `fileUploader` prop object to be passed containing a `useFileUpload` custom hook")}),I(Dkt.LexicalComposer,{initialConfig:p,children:I(Io.Provider,{value:{fileUploader:i,editorContainerRef:h,cardConfig:r,darkMode:s,selectedCardKey:a,setSelectedCardKey:l,isEditingCard:u,setIsEditingCard:d},children:o})})},Pkt=()=>{const[t]=Qt.useLexicalComposerContext();return U.useEffect(()=>{if(!t.hasNodes([])){console.error("HorizontalRulePlugin: HorizontalRuleNode not registered");return}return t.registerCommand(Cee,()=>{const e=J.$getSelection();if(!J.$isRangeSelection(e))return!1;if(e.focus.getNode()!==null){const i=Uae(),r=e.focus.getNode();J.$isParagraphNode(r)&&r.getTextContent()!==""&&e.insertParagraph(),e.focus.getNode().getTopLevelElementOrThrow().insertBefore(i)}return!0},J.COMMAND_PRIORITY_EDITOR)},[t]),null},$kt=()=>{const[t]=Qt.useLexicalComposerContext();return ue.useEffect(()=>{if(!t.hasNodes([Zx])){console.error("HtmlPlugin: HtmlNode not registered");return}return Fn.mergeRegister(t.registerCommand(kee,async e=>{const n=wCt(e);return t.dispatchCommand(xp,{cardNode:n,openInEditMode:!0}),!0},J.COMMAND_PRIORITY_LOW))},[t]),null},Fkt=({nodeKey:t,handleModalClose:e})=>{const{cardConfig:n}=ue.useContext(Io),[i]=Qt.useLexicalComposerContext(),r=()=>{t&&i.update(()=>{J.$getNodeByKey(t).remove()}),e(!1)},s=async o=>{i.update(()=>{const a=J.$getNodeByKey(t);a.setSrc(o.src),a.setImgHeight(o.height),a.setImgWidth(o.width),a.setCaption(o.caption),a.setAltText(o.alt);const l=J.$createNodeSelection();l.add(a.getKey()),J.$setSelection(l)}),e(!1)};return I(kce,{unsplashConf:n.unsplash,onClose:r,onImageInsert:s})},Bkt=()=>{const[t]=Qt.useLexicalComposerContext(),{fileUploader:e}=ue.useContext(Io),[n,i]=ue.useState(null),[r,s]=ue.useState(null),[o,a]=ue.useState(!1),l=e.useFileUpload("image"),u=ue.useCallback(async(d,p)=>{if((d==null?void 0:d.length)>0)return await ww(d,p,t,l.upload)},[l.upload,t]);return ue.useEffect(()=>{if(!t.hasNodes([vm])){console.error("ImagePlugin: ImageNode not registered");return}return Fn.mergeRegister(t.registerCommand(UT,async d=>{const p=V6(d);return(d==null?void 0:d.triggerFileSelector)==="unsplash"&&(s(p.getKey()),a(!0),i("unsplash")),t.dispatchCommand(xp,{cardNode:p}),!0},J.COMMAND_PRIORITY_LOW),t.registerCommand(Lk,async d=>d.type==="image"?(t.dispatchCommand(UT,{initialFile:d.file}),!0):!1,J.COMMAND_PRIORITY_HIGH))},[t,e,u]),o&&n?I(Fkt,{handleModalClose:a,nodeKey:r}):null},Ukt=()=>{const[t]=Qt.useLexicalComposerContext();return ue.useEffect(()=>{if(!t.hasNodes([vR])){console.error("MarkdownPlugin: MarkdownNode not registered");return}return Fn.mergeRegister(t.registerCommand(wee,async e=>{const n=pkt(e);return t.dispatchCommand(xp,{cardNode:n,openInEditMode:!0}),!0},J.COMMAND_PRIORITY_HIGH))},[t]),null},Gkt=()=>{const[t]=Qt.useLexicalComposerContext();return ue.useEffect(()=>{if(!t.hasNodes([Iy])){console.error("AudioPlugin: AudioNode not registered");return}return Fn.mergeRegister(t.registerCommand(Y3,async e=>{const n=Nwt(e);return t.dispatchCommand(xp,{cardNode:n}),!0},J.COMMAND_PRIORITY_LOW),t.registerCommand(Lk,async e=>e.type==="audio"?(t.dispatchCommand(Y3,{initialFile:e.file}),!0):!1,J.COMMAND_PRIORITY_HIGH))},[t]),null},Qkt=()=>{const[t]=Qt.useLexicalComposerContext();return ue.useEffect(()=>{if(!t.hasNodes([jx])){console.error("CalloutPlugin: CalloutNode not registered");return}return Fn.mergeRegister(t.registerCommand(Tee,async e=>{const n=GTt(e);return t.dispatchCommand(xp,{cardNode:n}),!0},J.COMMAND_PRIORITY_LOW))}),null},qkt=({label:t,children:e,...n})=>Ee("li",{className:"flex shrink-0 flex-col justify-center text-[1.1rem] font-semibold uppercase tracking-wide text-grey",role:"separator",...n,children:[I("span",{className:"mb-2 block px-4 pt-3",style:{minWidth:"calc(100% - 3.2rem)"},children:t}),I("ul",{role:"menu",children:e})]}),Ykt=({label:t,desc:e,isSelected:n,onClick:i,Icon:r,...s})=>I("li",{role:"presentation",children:Ee("button",{className:`flex w-full cursor-pointer flex-row items-center border border-transparent px-4 py-[1rem] text-left text-grey-800 hover:bg-grey-100 ${n?"bg-grey-100":""}`,"data-kg-card-menu-item":t,"data-kg-cardmenu-selected":n,role:"menuitem",type:"button",onClick:i,onMouseDown:a=>{a.preventDefault()},...s,children:[I("div",{className:"flex items-center",children:I(r,{className:"h-7 w-7"})}),Ee("div",{className:"flex flex-col",children:[I("div",{className:"m-0 ml-4 truncate text-[1.3rem] font-medium leading-[1.6rem] tracking-[.02rem] text-grey-900",children:t}),I("div",{className:"m-0 ml-4 truncate text-xs font-normal leading-[1.6rem] tracking-[.02rem] text-grey",children:e})]})]})}),zkt=({label:t,isSelected:e,Icon:n,...i})=>I("li",{role:"presentation",children:Ee("button",{className:`flex w-full cursor-pointer flex-row items-center border border-transparent px-4 py-[1rem] text-grey-800 hover:bg-grey-100 ${e?"bg-grey-100":""}`,"data-kg-cardmenu-selected":e,role:"menuitem",type:"button",...i,children:[I("div",{className:"flex items-center",children:I(n,{className:"h-7 w-7"})}),I("div",{className:"flex flex-col",children:I("div",{className:"m-0 ml-4 truncate text-[1.3rem] font-medium leading-[1.6rem] tracking-[.02rem] text-grey-900",children:t})})]})}),Dce=({menu:t=new Map,insert:e=()=>{},selectedItemIndex:n})=>{const i=[];let r=0;for(const[s,o]of t){const a=[];o.forEach(l=>{const u=r===n,d=p=>{p.preventDefault(),p.stopPropagation(),e==null||e(l.insertCommand,{insertParams:l.insertParams,queryParams:l.queryParams})};!l.type||l.type==="card"?a.push(I(Ykt,{"data-kg-cardmenu-idx":r,desc:l.desc,Icon:l.Icon,isSelected:u,label:l.label,onClick:d},r)):l.type==="snippet"&&a.push(I(zkt,{"data-kg-cardmenu-idx":r,Icon:l.Icon,isSelected:u,label:l.label,onClick:d},r)),r=r+1}),i.push(I(qkt,{label:s,children:a},s))}return I("ul",{className:"not-kg-prose z-[9999999] m-0 mb-3 max-h-[376px] w-[312px] flex-col overflow-y-auto rounded-md bg-white bg-clip-padding p-0 font-sans text-sm shadow-md after:block after:pb-4",role:"menu",children:i})};function Wkt({onClick:t}){return I("div",{className:"absolute top-[-2px] left-[-66px]","data-kg-plus-button":!0,children:I("button",{"aria-label":"Add a card",className:"group relative flex h-7 w-7 cursor-pointer items-center justify-center rounded-full border border-grey transition-all ease-linear hover:border-grey-900 dark:border-grey-800 dark:hover:border-grey-100 md:h-9 md:w-9",type:"button",onClick:t,children:I(wJ,{className:"h-4 w-4 stroke-grey-800 stroke-2 group-hover:stroke-grey-500 dark:stroke-grey-500 dark:group-hover:stroke-grey-100"})})})}function Hkt({children:t}){return I("div",{className:"absolute left-[-16px]","data-kg-plus-menu":!0,children:t})}function Mce(t,{query:e}={}){const n=new Map;e=e==null?void 0:e.toLowerCase();let i=-1;function r(s){if(e&&(!s.matches||!s.matches.find(a=>a.startsWith(e))))return;const o=s.section||"Primary";n.has(o)?n.get(o).push(s):n.set(o,[s]),i=i+1}for(const[s,o]of t)Array.isArray(o.kgMenu)?o.kgMenu.forEach(a=>r({nodeType:s,...a})):r({nodeType:s,...o.kgMenu});return{menu:n,maxItemIndex:i}}function Vkt(t){var Z;const[e,n]=ue.useState(!1),[i,r]=ue.useState(!1),[s,o]=ue.useState(0),[a,l]=ue.useState(null),[u,d]=ue.useState({}),p=ue.useRef(null);function h(Y){const G=Y.getBoundingClientRect(),ie=Y.parentNode.getBoundingClientRect();return G.top-ie.top}function g(Y){const G=new Range;return G.setStart(Y,0),G.setEnd(Y,0),G}const y=ue.useCallback(()=>{a&&(document.getSelection().removeAllRanges(),document.getSelection().addRange(a))},[a]),O=ue.useCallback(Y=>{const G=g(Y);l(G),n(!0)},[n,l]),b=ue.useCallback(()=>{n(!1),r(!1),l(null)},[n,r,l]),w=ue.useCallback(Y=>{Y==null||Y.preventDefault(),t.update(()=>{J.$setSelection(null)},{discrete:!0}),y(),r(!0)},[t,y,r]),T=ue.useCallback(({resetCursor:Y=!1}={})=>{Y&&y(),r(!1)},[y,r]),x=ue.useCallback(()=>{t.getEditorState().read(()=>{if(t.isComposing())return;const Y=J.$getSelection();if(!J.$isRangeSelection(Y)||!Y.type==="text"||!Y.isCollapsed()){b();return}const G=bC(Y);if(!J.$isParagraphNode(G)||G.getTextContent()!==""){b();return}const V=window.getSelection().anchorNode,z=t.getRootElement();if((V==null?void 0:V.tagName)!=="P"||!z.contains(V)){b();return}o(h(V)),O(V)})},[t,O,b]),R=ue.useCallback((Y,{insertParams:G={}}={})=>{const ie={...G};t.dispatchCommand(Y,ie),T()},[t,T]);ue.useEffect(()=>t.registerUpdateListener(()=>{x()},[t,x]));const A=ue.useCallback(()=>{var Y;if(e){const G=window.getSelection();if(i&&((Y=p.current)!=null&&Y.contains(G.anchorNode)))return;t.getRootElement().contains(G.anchorNode)||b()}},[t,e,i,b]);ue.useEffect(()=>(document.addEventListener("selectionchange",A),()=>{document.removeEventListener("selectionchange",A)}),[A]);const L=ue.useCallback(Y=>{if(i)return;const G=t.getRootElement();let{pageX:ie,pageY:V}=Y,z=G.getBoundingClientRect();ie<z.left&&(ie=ie+40);const X=document.elementFromPoint(ie,V);G.contains(X)&&((X==null?void 0:X.tagName)==="P"&&X.textContent===""?(o(h(X)),O(X)):x())},[t,i,o,O,x]);ue.useEffect(()=>(window.addEventListener("mousemove",L),()=>{window.removeEventListener("mousemove",L)}),[L]);const F=ue.useCallback(Y=>{var G;if(i&&!((G=p.current)!=null&&G.contains(Y.target)))return T()},[i,T]);ue.useEffect(()=>(window.addEventListener("mousedown",F),()=>{window.removeEventListener("mousedown",F)}),[F]);const q=ue.useCallback(Y=>{if(i){if(Y.key==="Escape"){T({resetCursor:!0});return}["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(Y.key)&&T()}},[i,T]);ue.useEffect(()=>(window.addEventListener("keydown",q),()=>{window.removeEventListener("keydown",q)})),ue.useEffect(()=>{const Y=S6(t);d(Mce(Y))},[t,d]);const H={top:`${s}px`};return((Z=u.menu)==null?void 0:Z.size)===0?null:e?Ee("div",{ref:p,className:"absolute",style:H,"data-kg-plus-container":!0,children:[e&&I(Wkt,{onClick:w}),i&&I(Hkt,{children:I(Dce,{insert:R,menu:u.menu})})]}):null}function Xkt(){const[t]=Qt.useLexicalComposerContext();return Vkt(t)}function Kkt({children:t}){return I("div",{"data-kg-slash-menu":!0,children:t})}function jkt(t){var R;const[e,n]=ue.useState(!1),[i,r]=ue.useState(0),[s,o]=ue.useState(""),[a,l]=ue.useState([]),[u,d]=ue.useState({}),[p,h]=ue.useState(0),g=ue.useRef(null),y=ue.useRef(null);function O(A){const L=A.getBoundingClientRect(),F=A.parentNode.getBoundingClientRect();return L.bottom-F.top}function b(){g.current&&(document.getSelection().removeAllRanges(),document.getSelection().addRange(g.current))}const w=ue.useCallback(()=>{n(!0)},[n]),T=ue.useCallback(({resetCursor:A=!1}={})=>{A&&b(),n(!1),o(""),l([]),g.current=null},[n]),x=ue.useCallback((A,{insertParams:L={},queryParams:F={}}={})=>{const q={...L};for(let H=0;H<F.length;H++)if(a[H]){const Z=F[H],Y=a[H];q[Z]=Y}t.update(()=>{const H=J.$getSelection();H.modify("extend",!0,"lineboundary"),H.deleteCharacter(!0),t.dispatchCommand(A,q)}),T()},[t,a,T]);return ue.useEffect(()=>t.registerUpdateListener(()=>{t.getEditorState().read(()=>{if(t.isComposing())return;const A=J.$getSelection();if(!J.$isRangeSelection(A)||!A.type==="text"||!A.isCollapsed()){T();return}const L=bC(A).getTopLevelElement();if(!L||!J.$isParagraphNode(L)||!L.getTextContent().startsWith("/")){T();return}const F=window.getSelection(),q=F.anchorNode,H=t.getRootElement();if((q==null?void 0:q.nodeType)!==Node.TEXT_NODE||!H.contains(q)){T();return}g.current=F.getRangeAt(0);const Z=L.getTextContent().slice(1),[Y,...G]=Z.split(" ");o(Y),l(G)})}),[t,T,o,l]),ue.useEffect(()=>{if(e)return;const A=L=>{const{key:F,isComposing:q,ctrlKey:H,metaKey:Z}=L;F!=="/"||q||H||Z||!t.getRootElement().matches(":focus")||t.getEditorState().read(()=>{const G=J.$getSelection(),ie=bC(G).getTopLevelElement();if(!ie||!J.$isParagraphNode(ie))return;const V=ie.getTextContentSize(),z=G.isCollapsed()&&ie.getTextContent()==="",X=!G.isCollapsed()&&(G.anchor.offset===0&&G.focus.offset===V||G.anchor.offset===V&&G.focus.offset===0);if(z||X){const ne=window.getSelection();let se;ne.anchorNode.nodeType===Node.TEXT_NODE?se=ne.anchorNode.parentNode.closest("p"):se=ne.anchorNode,r(O(se)),w()}})};return window.addEventListener("keypress",A),()=>{window.removeEventListener("keypress",A)}},[t,e,r,w]),ue.useEffect(()=>{if(!e)return;const A=L=>{if(L.key==="Escape"){T({resetCursor:!0});return}};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[e,T]),ue.useEffect(()=>{if(!e)return;const A=L=>{var F;(F=y.current)!=null&&F.contains(L.target)||T()};return window.addEventListener("mousedown",A),()=>{window.removeEventListener("mousedown",A)}},[e,T]),ue.useEffect(()=>{if(!e)return;const A=q=>(h(p===0?u.maxItemIndex:p-1),q.preventDefault(),!0),L=q=>(p===u.maxItemIndex?h(0):h(p+1),q.preventDefault(),!0),F=q=>{var H;return(H=document.querySelector(`[data-kg-slash-menu] [data-kg-cardmenu-idx="${p}"]`))==null||H.click(),q.preventDefault(),!0};return Fn.mergeRegister(t.registerCommand(J.KEY_ARROW_DOWN_COMMAND,L,J.COMMAND_PRIORITY_HIGH),t.registerCommand(J.KEY_ARROW_UP_COMMAND,A,J.COMMAND_PRIORITY_HIGH),t.registerCommand(J.KEY_ARROW_RIGHT_COMMAND,L,J.COMMAND_PRIORITY_HIGH),t.registerCommand(J.KEY_ARROW_LEFT_COMMAND,A,J.COMMAND_PRIORITY_HIGH),t.registerCommand(J.KEY_ENTER_COMMAND,F,J.COMMAND_PRIORITY_HIGH))},[t,e,u,p]),ue.useEffect(()=>{const A=S6(t);d(Mce(A,{insert:x,query:s})),h(0)},[t,s,x,d,h]),((R=u.menu)==null?void 0:R.size)===0?null:e?I("div",{ref:y,className:"absolute -left-2 mt-2",style:{top:`${i}px`},"data-kg-slash-container":!0,children:I(Kkt,{children:I(Dce,{insert:x,menu:u.menu,selectedItemIndex:p})})}):null}function Zkt(){const[t]=Qt.useLexicalComposerContext();return jkt(t)}const Jkt=()=>Ee(qn,{children:[I(Xkt,{}),I(Zkt,{})]});var Lce={},Ju=bo,ext=Qt,Pce=U,txt=Fn,k0=J;function nxt(t){Pce.useEffect(()=>txt.mergeRegister(t.registerCommand(Ju.INSERT_ORDERED_LIST_COMMAND,()=>(Ju.insertList(t,"number"),!0),k0.COMMAND_PRIORITY_LOW),t.registerCommand(Ju.INSERT_UNORDERED_LIST_COMMAND,()=>(Ju.insertList(t,"bullet"),!0),k0.COMMAND_PRIORITY_LOW),t.registerCommand(Ju.REMOVE_LIST_COMMAND,()=>(Ju.removeList(t),!0),k0.COMMAND_PRIORITY_LOW),t.registerCommand(k0.INSERT_PARAGRAPH_COMMAND,()=>!!Ju.$handleListInsertParagraph(),k0.COMMAND_PRIORITY_LOW)),[t])}Lce.ListPlugin=function(){let[t]=ext.useLexicalComposerContext();return Pce.useEffect(()=>{if(!t.hasNodes([Ju.ListNode,Ju.ListItemNode]))throw Error("ListPlugin: ListNode and/or ListItemNode not registered on editor")},[t]),nxt(t),null};const ixt=Lce;var rxt=ixt,$ce={},sxt=Qt,Xg=J,oxt=U;$ce.TabIndentationPlugin=function(){let[t]=sxt.useLexicalComposerContext();return oxt.useEffect(()=>t.registerCommand(Xg.KEY_TAB_COMMAND,e=>{let n=Xg.$getSelection();return Xg.$isRangeSelection(n)?(e.preventDefault(),t.dispatchCommand(e.shiftKey?Xg.OUTDENT_CONTENT_COMMAND:Xg.INDENT_CONTENT_COMMAND,void 0)):!1},Xg.COMMAND_PRIORITY_EDITOR)),null};const axt=$ce;var lxt=axt;const cxt=()=>{const[t]=Qt.useLexicalComposerContext();return ue.useEffect(()=>{if(!t.hasNodes([SR])){console.error("TogglePlugin: ToggleNode not registered");return}return Fn.mergeRegister(t.registerCommand(xee,async e=>{const n=Ekt(e);return t.dispatchCommand(xp,{cardNode:n,openInEditMode:!0}),!0},J.COMMAND_PRIORITY_LOW))},[t]),null},uxt=()=>{const[t]=Qt.useLexicalComposerContext();return ue.useEffect(()=>{if(!t.hasNodes([My])){console.error("VideoPlugin: VideoNode not registered");return}return Fn.mergeRegister(t.registerCommand(q3,async e=>{const n=kkt(e);return t.dispatchCommand(xp,{cardNode:n}),!0},J.COMMAND_PRIORITY_LOW),t.registerCommand(Lk,async e=>e.type==="video"?(t.dispatchCommand(q3,{initialFile:e.file}),!0):!1,J.COMMAND_PRIORITY_HIGH))},[t]),null},dxt=()=>Ee(qn,{children:[I(rxt.ListPlugin,{})," ",I(lxt.TabIndentationPlugin,{})," ",I(Jkt,{}),I(Gkt,{}),I(Bkt,{}),I(uxt,{}),I(Ukt,{}),I(Pkt,{}),I(Qkt,{}),I($kt,{}),I(cxt,{})]}),fxt=({children:t,...e})=>Ee(yp,{...e,children:[I(dxt,{}),t]}),yR=({html:t="",setHtml:e})=>{const[n]=Qt.useLexicalComposerContext(),i=ue.useRef(!0);ue.useLayoutEffect(()=>{i.current&&(i.current=!1,t&&n.update(()=>{const o=new DOMParser().parseFromString(t,"text/html"),a=M3.$generateNodesFromDOM(n,o);let l=!0;if(a.forEach(u=>{u.getTextContent().trim()&&(l=!1)}),J.$getRoot().select(),l){J.$getRoot().clear();return}J.$insertNodes(a)}))},[]);const r=ue.useCallback(()=>{n.update(()=>{const s=M3.$generateHtmlFromNodes(n,null);e==null||e(s)})},[n,e]);return I(s6.OnChangePlugin,{onChange:r})},TE=({paragraphs:t})=>{const[e]=Qt.useLexicalComposerContext();return ue.useEffect(()=>Fn.mergeRegister(e.registerNodeTransform(J.RootNode,n=>{const i=J.$getSelection();if(!J.$isRangeSelection(i)||!i.isCollapsed())return;const r=n.getChildren();if(!(r.length<=t&&r.every(J.$isParagraphNode))){let o=r.filter(a=>!J.$isDecoratorNode(a));o=o.slice(0,t),o=o.map(a=>{if(bo.$isListNode(a)){const l=a.getChildren()[0];return J.$createParagraphNode().append(...l.getChildren())}else return J.$isParagraphNode(a)?a:J.$createParagraphNode().append(...a.getChildren())}),r.forEach(a=>a.remove()),o.forEach(a=>n.append(a)),n.selectEnd()}})),[e,t]),null},Fce=[bo.ListNode,bo.ListItemNode,Ov.LinkNode],c9=[Ov.LinkNode];var Bce={},u9={},Uce=U;let SK=[["Cat","rgb(125, 50, 0)"],["Dog","rgb(100, 0, 0)"],["Rabbit","rgb(150, 0, 0)"],["Frog","rgb(200, 0, 0)"],["Fox","rgb(200, 75, 0)"],["Hedgehog","rgb(0, 75, 0)"],["Pigeon","rgb(0, 125, 0)"],["Squirrel","rgb(75, 100, 0)"],["Bear","rgb(125, 100, 0)"],["Tiger","rgb(0, 0, 150)"],["Leopard","rgb(0, 0, 200)"],["Zebra","rgb(0, 0, 250)"],["Wolf","rgb(0, 100, 150)"],["Owl","rgb(0, 100, 100)"],["Gull","rgb(100, 0, 100)"],["Squid","rgb(150, 0, 150)"]],yK=SK[Math.floor(Math.random()*SK.length)],Gce=Uce.createContext({clientID:0,color:yK[1],isCollabActive:!1,name:yK[0],yjsDocMap:new Map});u9.CollaborationContext=Gce;u9.useCollaborationContext=function(t,e){let n=Uce.useContext(Gce);return t!=null&&(n.name=t),e!=null&&(n.color=e),n};const pxt=u9;var hxt=pxt,gu={};const Bl=()=>new Map,_$=t=>{const e=Bl();return t.forEach((n,i)=>{e.set(i,n)}),e},Md=(t,e,n)=>{let i=t.get(e);return i===void 0&&t.set(e,i=n()),i},mxt=(t,e)=>{const n=[];for(const[i,r]of t)n.push(e(r,i));return n},gxt=(t,e)=>{for(const[n,i]of t)if(e(i,n))return!0;return!1},xm=()=>new Set,BL=t=>t[t.length-1],_xt=(t,e)=>{for(let n=0;n<e.length;n++)t.push(e[n])},Ep=Array.from,EK=Array.isArray;class CE{constructor(){this._observers=Bl()}on(e,n){Md(this._observers,e,xm).add(n)}once(e,n){const i=(...r)=>{this.off(e,i),n(...r)};this.on(e,i)}off(e,n){const i=this._observers.get(e);i!==void 0&&(i.delete(n),i.size===0&&this._observers.delete(e))}emit(e,n){return Ep((this._observers.get(e)||Bl()).values()).forEach(i=>i(...n))}destroy(){this._observers=Bl()}}class vxt extends CE{constructor(e,n){super(),this.doc=e,this.awareness=n}}const Cd=Math.floor,dT=Math.abs,d9=(t,e)=>t<e?t:e,Um=(t,e)=>t>e?t:e,Sxt=Math.pow,Qce=t=>t!==0?t<0:1/t<0,yxt=String.fromCharCode,Ext=t=>t.toLowerCase(),bxt=/^\s*/g,Oxt=t=>t.replace(bxt,""),wxt=/([A-Z])/g,bK=(t,e)=>Oxt(t.replace(wxt,n=>`${e}${Ext(n)}`)),Txt=t=>{const e=unescape(encodeURIComponent(t)),n=e.length,i=new Uint8Array(n);for(let r=0;r<n;r++)i[r]=e.codePointAt(r);return i},Ly=typeof TextEncoder<"u"?new TextEncoder:null,Cxt=t=>Ly.encode(t),kxt=Ly?Cxt:Txt;let xS=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});xS&&xS.decode(new Uint8Array).length===1&&(xS=null);const OK=t=>t===void 0?null:t;class xxt{constructor(){this.map=new Map}setItem(e,n){this.map.set(e,n)}getItem(e){return this.map.get(e)}}let qce=new xxt,Yce=!0;try{typeof localStorage<"u"&&(qce=localStorage,Yce=!1)}catch{}const zce=qce,Rxt=t=>Yce||addEventListener("storage",t),Nxt=Object.keys,Axt=(t,e)=>{const n=[];for(const i in t)n.push(e(t[i],i));return n},hk=t=>Nxt(t).length,Ixt=(t,e)=>{for(const n in t)if(!e(t[n],n))return!1;return!0},Wce=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Dxt=(t,e)=>t===e||hk(t)===hk(e)&&Ixt(t,(n,i)=>(n!==void 0||Wce(e,i))&&e[i]===n),f9=(t,e,n=0)=>{try{for(;n<t.length;n++)t[n](...e)}finally{n<t.length&&f9(t,e,n+1)}},Mxt=(t,e)=>t===e,RS=(t,e)=>{if(t==null||e==null)return Mxt(t,e);if(t.constructor!==e.constructor)return!1;if(t===e)return!0;switch(t.constructor){case ArrayBuffer:t=new Uint8Array(t),e=new Uint8Array(e);case Uint8Array:{if(t.byteLength!==e.byteLength)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;break}case Set:{if(t.size!==e.size)return!1;for(const n of t)if(!e.has(n))return!1;break}case Map:{if(t.size!==e.size)return!1;for(const n of t.keys())if(!e.has(n)||!RS(t.get(n),e.get(n)))return!1;break}case Object:if(hk(t)!==hk(e))return!1;for(const n in t)if(!Wce(t,n)||!RS(t[n],e[n]))return!1;break;case Array:if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!RS(t[n],e[n]))return!1;break;default:return!1}return!0},Lxt=(t,e)=>e.includes(t),Rm=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name),Hce=typeof window<"u"&&typeof document<"u"&&!Rm;let kc;const Pxt=()=>{if(kc===void 0)if(Rm){kc=Bl();const t=process.argv;let e=null;for(let n=0;n<t.length;n++){const i=t[n];i[0]==="-"?(e!==null&&kc.set(e,""),e=i):e!==null&&(kc.set(e,i),e=null)}e!==null&&kc.set(e,"")}else typeof location=="object"?(kc=Bl(),(location.search||"?").slice(1).split("&").forEach(t=>{if(t.length!==0){const[e,n]=t.split("=");kc.set(`--${bK(e,"-")}`,n),kc.set(`-${bK(e,"-")}`,n)}})):kc=Bl();return kc},v$=t=>Pxt().has(t),S$=t=>OK(Rm?process.env[t.toUpperCase()]:zce.getItem(t)),$xt=t=>v$("--"+t)||S$(t)!==null;$xt("production");const wK=Rm&&Lxt({}.FORCE_COLOR,["true","1","2"]),Fxt=!v$("no-colors")&&(!Rm||process.stdout.isTTY||wK)&&(!Rm||v$("color")||wK||S$("COLORTERM")!==null||(S$("TERM")||"").includes("color")),TK=1,CK=2,UL=4,GL=8,Py=32,hd=64,ca=128,ER=31,y$=63,cm=127,Bxt=2147483647,Vce=Number.MAX_SAFE_INTEGER,Uxt=Number.isInteger||(t=>typeof t=="number"&&isFinite(t)&&Cd(t)===t),Qv=t=>new Error(t),Jc=()=>{throw Qv("Method unimplemented")},Ka=()=>{throw Qv("Unexpected case")},Xce=Qv("Unexpected end of array"),Kce=Qv("Integer out of Range");class bR{constructor(e){this.arr=e,this.pos=0}}const ls=t=>new bR(t),jce=t=>t.pos!==t.arr.length,Gxt=(t,e)=>{const n=h9(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,n},gs=t=>Gxt(t,Gt(t)),_v=t=>t.arr[t.pos++],Gt=t=>{let e=0,n=1;const i=t.arr.length;for(;t.pos<i;){const r=t.arr[t.pos++];if(e=e+(r&cm)*n,n*=128,r<ca)return e;if(e>Vce)throw Kce}throw Xce},OR=t=>{let e=t.arr[t.pos++],n=e&y$,i=64;const r=(e&hd)>0?-1:1;if(!(e&ca))return r*n;const s=t.arr.length;for(;t.pos<s;){if(e=t.arr[t.pos++],n=n+(e&cm)*i,i*=128,e<ca)return r*n;if(n>Vce)throw Kce}throw Xce},Qxt=t=>{let e=Gt(t);if(e===0)return"";{let n=String.fromCodePoint(_v(t));if(--e<100)for(;e--;)n+=String.fromCodePoint(_v(t));else for(;e>0;){const i=e<1e4?e:1e4,r=t.arr.subarray(t.pos,t.pos+i);t.pos+=i,n+=String.fromCodePoint.apply(null,r),e-=i}return decodeURIComponent(escape(n))}},qxt=t=>xS.decode(gs(t)),md=xS?qxt:Qxt,p9=(t,e)=>{const n=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,e);return t.pos+=e,n},Yxt=t=>p9(t,4).getFloat32(0,!1),zxt=t=>p9(t,8).getFloat64(0,!1),Wxt=t=>p9(t,8).getBigInt64(0,!1),Hxt=[t=>{},t=>null,OR,Yxt,zxt,Wxt,t=>!1,t=>!0,md,t=>{const e=Gt(t),n={};for(let i=0;i<e;i++){const r=md(t);n[r]=$y(t)}return n},t=>{const e=Gt(t),n=[];for(let i=0;i<e;i++)n.push($y(t));return n},gs],$y=t=>Hxt[127-_v(t)](t);class kK extends bR{constructor(e,n){super(e),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),jce(this)?this.count=Gt(this)+1:this.count=-1),this.count--,this.s}}class fT extends bR{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=OR(this);const e=Qce(this.s);this.count=1,e&&(this.s=-this.s,this.count=Gt(this)+2)}return this.count--,this.s}}class QL extends bR{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const e=OR(this),n=e&1;this.diff=Cd(e/2),this.count=1,n&&(this.count=Gt(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Vxt{constructor(e){this.decoder=new fT(e),this.str=md(this.decoder),this.spos=0}read(){const e=this.spos+this.decoder.read(),n=this.str.slice(this.spos,e);return this.spos=e,n}}const Zce=t=>new Uint8Array(t),h9=(t,e,n)=>new Uint8Array(t,e,n),Xxt=t=>new Uint8Array(t),Kxt=t=>{let e="";for(let n=0;n<t.byteLength;n++)e+=yxt(t[n]);return btoa(e)},jxt=t=>Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("base64"),Zxt=t=>{const e=atob(t),n=Zce(e.length);for(let i=0;i<e.length;i++)n[i]=e.charCodeAt(i);return n},Jxt=t=>{const e=Buffer.from(t,"base64");return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)},eRt=Hce?Kxt:jxt,tRt=Hce?Zxt:Jxt,nRt=t=>{const e=Zce(t.byteLength);return e.set(t),e};class kE{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Dr=()=>new kE,m9=t=>{let e=t.cpos;for(let n=0;n<t.bufs.length;n++)e+=t.bufs[n].length;return e},fi=t=>{const e=new Uint8Array(m9(t));let n=0;for(let i=0;i<t.bufs.length;i++){const r=t.bufs[i];e.set(r,n),n+=r.length}return e.set(h9(t.cbuf.buffer,0,t.cpos),n),e},iRt=(t,e)=>{const n=t.cbuf.length;n-t.cpos<e&&(t.bufs.push(h9(t.cbuf.buffer,0,t.cpos)),t.cbuf=new Uint8Array(Um(n,e)*2),t.cpos=0)},Nr=(t,e)=>{const n=t.cbuf.length;t.cpos===n&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(n*2),t.cpos=0),t.cbuf[t.cpos++]=e},Fy=Nr,lt=(t,e)=>{for(;e>cm;)Nr(t,ca|cm&e),e=Cd(e/128);Nr(t,cm&e)},wR=(t,e)=>{const n=Qce(e);for(n&&(e=-e),Nr(t,(e>y$?ca:0)|(n?hd:0)|y$&e),e=Cd(e/64);e>0;)Nr(t,(e>cm?ca:0)|cm&e),e=Cd(e/128)},E$=new Uint8Array(3e4),rRt=E$.length/3,sRt=(t,e)=>{if(e.length<rRt){const n=Ly.encodeInto(e,E$).written||0;lt(t,n);for(let i=0;i<n;i++)Nr(t,E$[i])}else Ji(t,kxt(e))},oRt=(t,e)=>{const n=unescape(encodeURIComponent(e)),i=n.length;lt(t,i);for(let r=0;r<i;r++)Nr(t,n.codePointAt(r))},lp=Ly&&Ly.encodeInto?sRt:oRt,aRt=(t,e)=>xE(t,fi(e)),xE=(t,e)=>{const n=t.cbuf.length,i=t.cpos,r=d9(n-i,e.length),s=e.length-r;t.cbuf.set(e.subarray(0,r),i),t.cpos+=r,s>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(Um(n*2,s)),t.cbuf.set(e.subarray(r)),t.cpos=s)},Ji=(t,e)=>{lt(t,e.byteLength),xE(t,e)},g9=(t,e)=>{iRt(t,e);const n=new DataView(t.cbuf.buffer,t.cpos,e);return t.cpos+=e,n},lRt=(t,e)=>g9(t,4).setFloat32(0,e,!1),cRt=(t,e)=>g9(t,8).setFloat64(0,e,!1),uRt=(t,e)=>g9(t,8).setBigInt64(0,e,!1),xK=new DataView(new ArrayBuffer(4)),dRt=t=>(xK.setFloat32(0,t),xK.getFloat32(0)===t),By=(t,e)=>{switch(typeof e){case"string":Nr(t,119),lp(t,e);break;case"number":Uxt(e)&&dT(e)<=Bxt?(Nr(t,125),wR(t,e)):dRt(e)?(Nr(t,124),lRt(t,e)):(Nr(t,123),cRt(t,e));break;case"bigint":Nr(t,122),uRt(t,e);break;case"object":if(e===null)Nr(t,126);else if(e instanceof Array){Nr(t,117),lt(t,e.length);for(let n=0;n<e.length;n++)By(t,e[n])}else if(e instanceof Uint8Array)Nr(t,116),Ji(t,e);else{Nr(t,118);const n=Object.keys(e);lt(t,n.length);for(let i=0;i<n.length;i++){const r=n[i];lp(t,r),By(t,e[r])}}break;case"boolean":Nr(t,e?120:121);break;default:Nr(t,127)}};class RK extends kE{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&<(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const NK=t=>{t.count>0&&(wR(t.encoder,t.count===1?t.s:-t.s),t.count>1&<(t.encoder,t.count-2))};class pT{constructor(){this.encoder=new kE,this.s=0,this.count=0}write(e){this.s===e?this.count++:(NK(this),this.count=1,this.s=e)}toUint8Array(){return NK(this),fi(this.encoder)}}const AK=t=>{if(t.count>0){const e=t.diff*2+(t.count===1?0:1);wR(t.encoder,e),t.count>1&<(t.encoder,t.count-2)}};class qL{constructor(){this.encoder=new kE,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(AK(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return AK(this),fi(this.encoder)}}class fRt{constructor(){this.sarr=[],this.s="",this.lensE=new pT}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new kE;return this.sarr.push(this.s),this.s="",lp(e,this.sarr.join("")),xE(e,this.lensE.toUint8Array()),fi(e)}}class _9{constructor(e,n){this.clock=e,this.len=n}}class qv{constructor(){this.clients=new Map}}const bp=(t,e,n)=>e.clients.forEach((i,r)=>{const s=t.doc.store.clients.get(r);for(let o=0;o<i.length;o++){const a=i[o];pue(t,s,a.clock,a.len,n)}}),pRt=(t,e)=>{let n=0,i=t.length-1;for(;n<=i;){const r=Cd((n+i)/2),s=t[r],o=s.clock;if(o<=e){if(e<o+s.len)return r;n=r+1}else i=r-1}return null},Yv=(t,e)=>{const n=t.clients.get(e.client);return n!==void 0&&pRt(n,e.clock)!==null},v9=t=>{t.clients.forEach(e=>{e.sort((r,s)=>r.clock-s.clock);let n,i;for(n=1,i=1;n<e.length;n++){const r=e[i-1],s=e[n];r.clock+r.len>=s.clock?r.len=Um(r.len,s.clock+s.len-r.clock):(i<n&&(e[i]=s),i++)}e.length=i})},Uy=t=>{const e=new qv;for(let n=0;n<t.length;n++)t[n].clients.forEach((i,r)=>{if(!e.clients.has(r)){const s=i.slice();for(let o=n+1;o<t.length;o++)_xt(s,t[o].clients.get(r)||[]);e.clients.set(r,s)}});return v9(e),e},Gy=(t,e,n,i)=>{Md(t.clients,e,()=>[]).push(new _9(n,i))},TR=()=>new qv,S9=t=>{const e=TR();return t.clients.forEach((n,i)=>{const r=[];for(let s=0;s<n.length;s++){const o=n[s];if(o.deleted){const a=o.id.clock;let l=o.length;if(s+1<n.length)for(let u=n[s+1];s+1<n.length&&u.deleted;u=n[++s+1])l+=u.length;r.push(new _9(a,l))}}r.length>0&&e.clients.set(i,r)}),e},nu=(t,e)=>{lt(t.restEncoder,e.clients.size),Ep(e.clients.entries()).sort((n,i)=>i[0]-n[0]).forEach(([n,i])=>{t.resetDsCurVal(),lt(t.restEncoder,n);const r=i.length;lt(t.restEncoder,r);for(let s=0;s<r;s++){const o=i[s];t.writeDsClock(o.clock),t.writeDsLen(o.len)}})},Op=t=>{const e=new qv,n=Gt(t.restDecoder);for(let i=0;i<n;i++){t.resetDsCurVal();const r=Gt(t.restDecoder),s=Gt(t.restDecoder);if(s>0){const o=Md(e.clients,r,()=>[]);for(let a=0;a<s;a++)o.push(new _9(t.readDsClock(),t.readDsLen()))}}return e},IK=(t,e,n)=>{const i=new qv,r=Gt(t.restDecoder);for(let s=0;s<r;s++){t.resetDsCurVal();const o=Gt(t.restDecoder),a=Gt(t.restDecoder),l=n.clients.get(o)||[],u=Pi(n,o);for(let d=0;d<a;d++){const p=t.readDsClock(),h=p+t.readDsLen();if(p<u){u<h&&Gy(i,o,u,h-u);let g=ja(l,p),y=l[g];for(!y.deleted&&y.id.clock<p&&(l.splice(g+1,0,_k(e,y,p-y.id.clock)),g++);g<l.length&&(y=l[g++],y.id.clock<h);)y.deleted||(h<y.id.clock+y.length&&l.splice(g,0,_k(e,y,h-y.id.clock)),y.delete(e))}else Gy(i,o,p,h-p)}}if(i.clients.size>0){const s=new kd;return lt(s.restEncoder,0),nu(s,i),s.toUint8Array()}return null},DK=typeof crypto>"u"?null:crypto,hRt=DK!==null?t=>{const e=new ArrayBuffer(t),n=new Uint8Array(e);return DK.getRandomValues(n),e}:t=>{const e=new ArrayBuffer(t),n=new Uint8Array(e);for(let i=0;i<t;i++)n[i]=Math.ceil(Math.random()*4294967295>>>0);return e},Jce=()=>new Uint32Array(hRt(4))[0],mRt=[1e7]+-1e3+-4e3+-8e3+-1e11,gRt=()=>mRt.replace(/[018]/g,t=>(t^Jce()&15>>t/4).toString(16)),wp=Date.now,MK=t=>new Promise(t),eue=Jce;class Pp extends CE{constructor({guid:e=gRt(),collectionid:n=null,gc:i=!0,gcFilter:r=()=>!0,meta:s=null,autoLoad:o=!1,shouldLoad:a=!0}={}){super(),this.gc=i,this.gcFilter=r,this.clientID=eue(),this.guid=e,this.collectionid=n,this.share=new Map,this.store=new due,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=a,this.autoLoad=o,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.whenLoaded=MK(u=>{this.on("load",()=>{this.isLoaded=!0,u(this)})});const l=()=>MK(u=>{const d=p=>{(p===void 0||p===!0)&&(this.off("sync",d),u())};this.on("sync",d)});this.on("sync",u=>{u===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=u===void 0||u===!0,this.isLoaded||this.emit("load",[])}),this.whenSynced=l()}load(){const e=this._item;e!==null&&!this.shouldLoad&&Wn(e.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Ep(this.subdocs).map(e=>e.guid))}transact(e,n=null){return Wn(this,e,n)}get(e,n=Fr){const i=Md(this.share,e,()=>{const s=new n;return s._integrate(this,null),s}),r=i.constructor;if(n!==Fr&&r!==n)if(r===Fr){const s=new n;s._map=i._map,i._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=s}),s._start=i._start;for(let o=s._start;o!==null;o=o.right)o.parent=s;return s._length=i._length,this.share.set(e,s),s._integrate(this,null),s}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return i}getArray(e=""){return this.get(e,gd)}getText(e=""){return this.get(e,Nm)}getMap(e=""){return this.get(e,Tp)}getXmlFragment(e=""){return this.get(e,Cp)}toJSON(){const e={};return this.share.forEach((n,i)=>{e[i]=n.toJSON()}),e}destroy(){Ep(this.subdocs).forEach(n=>n.destroy());const e=this._item;if(e!==null){this._item=null;const n=e.content;n.doc=new Pp({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=e,Wn(e.parent.doc,i=>{const r=n.doc;e.deleted||i.subdocsAdded.add(r),i.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}on(e,n){super.on(e,n)}off(e,n){super.off(e,n)}}class Qy{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return Gt(this.restDecoder)}readDsLen(){return Gt(this.restDecoder)}}class Ld extends Qy{readLeftID(){return Yt(Gt(this.restDecoder),Gt(this.restDecoder))}readRightID(){return Yt(Gt(this.restDecoder),Gt(this.restDecoder))}readClient(){return Gt(this.restDecoder)}readInfo(){return _v(this.restDecoder)}readString(){return md(this.restDecoder)}readParentInfo(){return Gt(this.restDecoder)===1}readTypeRef(){return Gt(this.restDecoder)}readLen(){return Gt(this.restDecoder)}readAny(){return $y(this.restDecoder)}readBuf(){return nRt(gs(this.restDecoder))}readJSON(){return JSON.parse(md(this.restDecoder))}readKey(){return md(this.restDecoder)}}class tue{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=Gt(this.restDecoder),this.dsCurrVal}readDsLen(){const e=Gt(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class iu extends tue{constructor(e){super(e),this.keys=[],Gt(e),this.keyClockDecoder=new QL(gs(e)),this.clientDecoder=new fT(gs(e)),this.leftClockDecoder=new QL(gs(e)),this.rightClockDecoder=new QL(gs(e)),this.infoDecoder=new kK(gs(e),_v),this.stringDecoder=new Vxt(gs(e)),this.parentInfoDecoder=new kK(gs(e),_v),this.typeRefDecoder=new fT(gs(e)),this.lenDecoder=new fT(gs(e))}readLeftID(){return new um(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new um(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 $y(this.restDecoder)}readBuf(){return gs(this.restDecoder)}readJSON(){return $y(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{const n=this.stringDecoder.read();return this.keys.push(n),n}}}class vv{constructor(){this.restEncoder=Dr()}toUint8Array(){return fi(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){lt(this.restEncoder,e)}writeDsLen(e){lt(this.restEncoder,e)}}class Gm extends vv{writeLeftID(e){lt(this.restEncoder,e.client),lt(this.restEncoder,e.clock)}writeRightID(e){lt(this.restEncoder,e.client),lt(this.restEncoder,e.clock)}writeClient(e){lt(this.restEncoder,e)}writeInfo(e){Fy(this.restEncoder,e)}writeString(e){lp(this.restEncoder,e)}writeParentInfo(e){lt(this.restEncoder,e?1:0)}writeTypeRef(e){lt(this.restEncoder,e)}writeLen(e){lt(this.restEncoder,e)}writeAny(e){By(this.restEncoder,e)}writeBuf(e){Ji(this.restEncoder,e)}writeJSON(e){lp(this.restEncoder,JSON.stringify(e))}writeKey(e){lp(this.restEncoder,e)}}class CR{constructor(){this.restEncoder=Dr(),this.dsCurrVal=0}toUint8Array(){return fi(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const n=e-this.dsCurrVal;this.dsCurrVal=e,lt(this.restEncoder,n)}writeDsLen(e){e===0&&Ka(),lt(this.restEncoder,e-1),this.dsCurrVal+=e}}class kd extends CR{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new qL,this.clientEncoder=new pT,this.leftClockEncoder=new qL,this.rightClockEncoder=new qL,this.infoEncoder=new RK(Fy),this.stringEncoder=new fRt,this.parentInfoEncoder=new RK(Fy),this.typeRefEncoder=new pT,this.lenEncoder=new pT}toUint8Array(){const e=Dr();return lt(e,0),Ji(e,this.keyClockEncoder.toUint8Array()),Ji(e,this.clientEncoder.toUint8Array()),Ji(e,this.leftClockEncoder.toUint8Array()),Ji(e,this.rightClockEncoder.toUint8Array()),Ji(e,fi(this.infoEncoder)),Ji(e,this.stringEncoder.toUint8Array()),Ji(e,fi(this.parentInfoEncoder)),Ji(e,this.typeRefEncoder.toUint8Array()),Ji(e,this.lenEncoder.toUint8Array()),xE(e,fi(this.restEncoder)),fi(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){By(this.restEncoder,e)}writeBuf(e){Ji(this.restEncoder,e)}writeJSON(e){By(this.restEncoder,e)}writeKey(e){const n=this.keyMap.get(e);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(n)}}const _Rt=(t,e,n,i)=>{i=Um(i,e[0].id.clock);const r=ja(e,i);lt(t.restEncoder,e.length-r),t.writeClient(n),lt(t.restEncoder,i);const s=e[r];s.write(t,i-s.id.clock);for(let o=r+1;o<e.length;o++)e[o].write(t,0)},y9=(t,e,n)=>{const i=new Map;n.forEach((r,s)=>{Pi(e,s)>r&&i.set(s,r)}),RE(e).forEach((r,s)=>{n.has(s)||i.set(s,0)}),lt(t.restEncoder,i.size),Ep(i.entries()).sort((r,s)=>s[0]-r[0]).forEach(([r,s])=>{_Rt(t,e.clients.get(r),r,s)})},vRt=(t,e)=>{const n=Bl(),i=Gt(t.restDecoder);for(let r=0;r<i;r++){const s=Gt(t.restDecoder),o=new Array(s),a=t.readClient();let l=Gt(t.restDecoder);n.set(a,{i:0,refs:o});for(let u=0;u<s;u++){const d=t.readInfo();switch(ER&d){case 0:{const p=t.readLen();o[u]=new na(Yt(a,l),p),l+=p;break}case 10:{const p=Gt(t.restDecoder);o[u]=new ia(Yt(a,l),p),l+=p;break}default:{const p=(d&(hd|ca))===0,h=new Hn(Yt(a,l),null,(d&ca)===ca?t.readLeftID():null,null,(d&hd)===hd?t.readRightID():null,p?t.readParentInfo()?e.get(t.readString()):t.readLeftID():null,p&&(d&Py)===Py?t.readString():null,tde(t,d));o[u]=h,l+=h.length}}}}return n},SRt=(t,e,n)=>{const i=[];let r=Ep(n.keys()).sort((g,y)=>g-y);if(r.length===0)return null;const s=()=>{if(r.length===0)return null;let g=n.get(r[r.length-1]);for(;g.refs.length===g.i;)if(r.pop(),r.length>0)g=n.get(r[r.length-1]);else return null;return g};let o=s();if(o===null&&i.length===0)return null;const a=new due,l=new Map,u=(g,y)=>{const O=l.get(g);(O==null||O>y)&&l.set(g,y)};let d=o.refs[o.i++];const p=new Map,h=()=>{for(const g of i){const y=g.id.client,O=n.get(y);O?(O.i--,a.clients.set(y,O.refs.slice(O.i)),n.delete(y),O.i=0,O.refs=[]):a.clients.set(y,[g]),r=r.filter(b=>b!==y)}i.length=0};for(;;){if(d.constructor!==ia){const y=Md(p,d.id.client,()=>Pi(e,d.id.client))-d.id.clock;if(y<0)i.push(d),u(d.id.client,d.id.clock-1),h();else{const O=d.getMissing(t,e);if(O!==null){i.push(d);const b=n.get(O)||{refs:[],i:0};if(b.refs.length===b.i)u(O,Pi(e,O)),h();else{d=b.refs[b.i++];continue}}else(y===0||y<d.length)&&(d.integrate(t,y),p.set(d.id.client,d.id.clock+d.length))}}if(i.length>0)d=i.pop();else if(o!==null&&o.i<o.refs.length)d=o.refs[o.i++];else{if(o=s(),o===null)break;d=o.refs[o.i++]}}if(a.clients.size>0){const g=new kd;return y9(g,a,new Map),lt(g.restEncoder,0),{missing:l,update:g.toUint8Array()}}return null},yRt=(t,e)=>y9(t,e.doc.store,e.beforeState),E9=(t,e,n,i=new iu(t))=>Wn(e,r=>{r.local=!1;let s=!1;const o=r.doc,a=o.store,l=vRt(i,o),u=SRt(r,a,l),d=a.pendingStructs;if(d){for(const[h,g]of d.missing)if(g<Pi(a,h)){s=!0;break}if(u){for(const[h,g]of u.missing){const y=d.missing.get(h);(y==null||y>g)&&d.missing.set(h,g)}d.update=Yy([d.update,u.update])}}else a.pendingStructs=u;const p=IK(i,r,a);if(a.pendingDs){const h=new iu(ls(a.pendingDs));Gt(h.restDecoder);const g=IK(h,r,a);p&&g?a.pendingDs=Yy([p,g]):a.pendingDs=p||g}else a.pendingDs=p;if(s){const h=a.pendingStructs.update;a.pendingStructs=null,kR(r.doc,h)}},n,!1),ERt=(t,e,n)=>E9(t,e,n,new Ld(t)),kR=(t,e,n,i=iu)=>{const r=ls(e);E9(r,t,n,new i(r))},nue=(t,e,n)=>kR(t,e,n,Ld),bRt=(t,e,n=new Map)=>{y9(t,e.store,n),nu(t,S9(e.store))},iue=(t,e=new Uint8Array([0]),n=new kd)=>{const i=b9(e);bRt(n,t,i);const r=[n.toUint8Array()];if(t.store.pendingDs&&r.push(t.store.pendingDs),t.store.pendingStructs&&r.push(I9(t.store.pendingStructs.update,e)),r.length>1){if(n.constructor===Gm)return Cue(r.map((s,o)=>o===0?s:Aue(s)));if(n.constructor===kd)return Yy(r)}return r[0]},rue=(t,e)=>iue(t,e,new Gm),sue=t=>{const e=new Map,n=Gt(t.restDecoder);for(let i=0;i<n;i++){const r=Gt(t.restDecoder),s=Gt(t.restDecoder);e.set(r,s)}return e},b9=t=>sue(new Qy(ls(t))),O9=(t,e)=>(lt(t.restEncoder,e.size),Ep(e.entries()).sort((n,i)=>i[0]-n[0]).forEach(([n,i])=>{lt(t.restEncoder,n),lt(t.restEncoder,i)}),t),ORt=(t,e)=>O9(t,RE(e.store)),wRt=(t,e=new CR)=>(t instanceof Map?O9(e,t):ORt(e,t),e.toUint8Array()),oue=t=>wRt(t,new vv);class TRt{constructor(){this.l=[]}}const LK=()=>new TRt,PK=(t,e)=>t.l.push(e),$K=(t,e)=>{const n=t.l,i=n.length;t.l=n.filter(r=>e!==r),i===t.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},aue=(t,e,n)=>f9(t.l,[e,n]);class um{constructor(e,n){this.client=e,this.clock=n}}const Zh=(t,e)=>t===e||t!==null&&e!==null&&t.client===e.client&&t.clock===e.clock,Yt=(t,e)=>new um(t,e),FK=(t,e)=>{lt(t,e.client),lt(t,e.clock)},BK=t=>Yt(Gt(t),Gt(t)),w9=t=>{for(const[e,n]of t.doc.share.entries())if(n===t)return e;throw Ka()},qy=(t,e)=>{for(;e!==null;){if(e.parent===t)return!0;e=e.parent._item}return!1},CRt=t=>{const e=[];let n=t._start;for(;n;)e.push(n),n=n.right;console.log("Children: ",e),console.log("Children content: ",e.filter(i=>!i.deleted).map(i=>i.content))};class kRt{constructor(e,n=e.getMap("users")){const i=new Map;this.yusers=n,this.doc=e,this.clients=new Map,this.dss=i;const r=(s,o)=>{const a=s.get("ds"),l=s.get("ids"),u=d=>this.clients.set(d,o);a.observe(d=>{d.changes.added.forEach(p=>{p.content.getContent().forEach(h=>{h instanceof Uint8Array&&this.dss.set(o,Uy([this.dss.get(o)||TR(),Op(new Qy(ls(h)))]))})})}),this.dss.set(o,Uy(a.map(d=>Op(new Qy(ls(d)))))),l.observe(d=>d.changes.added.forEach(p=>p.content.getContent().forEach(u))),l.forEach(u)};n.observe(s=>{s.keysChanged.forEach(o=>r(n.get(o),o))}),n.forEach(r)}setUserMapping(e,n,i,{filter:r=()=>!0}={}){const s=this.yusers;let o=s.get(i);o||(o=new Tp,o.set("ids",new gd),o.set("ds",new gd),s.set(i,o)),o.get("ids").push([n]),s.observe(a=>{setTimeout(()=>{const l=s.get(i);if(l!==o){o=l,this.clients.forEach((p,h)=>{i===p&&o.get("ids").push([h])});const u=new vv,d=this.dss.get(i);d&&(nu(u,d),o.get("ds").push([u.toUint8Array()]))}},0)}),e.on("afterTransaction",a=>{setTimeout(()=>{const l=o.get("ds"),u=a.deleteSet;if(a.local&&u.clients.size>0&&r(a,u)){const d=new vv;nu(d,u),l.push([d.toUint8Array()])}})})}getUserByClientId(e){return this.clients.get(e)||null}getUserByDeletedId(e){for(const[n,i]of this.dss.entries())if(Yv(i,e))return n;return null}}class xR{constructor(e,n,i,r=0){this.type=e,this.tname=n,this.item=i,this.assoc=r}}const xRt=t=>{const e={};return t.type&&(e.type=t.type),t.tname&&(e.tname=t.tname),t.item&&(e.item=t.item),t.assoc!=null&&(e.assoc=t.assoc),e},RRt=t=>new xR(t.type==null?null:Yt(t.type.client,t.type.clock),t.tname||null,t.item==null?null:Yt(t.item.client,t.item.clock),t.assoc==null?0:t.assoc);class lue{constructor(e,n,i=0){this.type=e,this.index=n,this.assoc=i}}const NRt=(t,e,n=0)=>new lue(t,e,n),dw=(t,e,n)=>{let i=null,r=null;return t._item===null?r=w9(t):i=Yt(t._item.id.client,t._item.id.clock),new xR(i,r,e,n)},ARt=(t,e,n=0)=>{let i=t._start;if(n<0){if(e===0)return dw(t,null,n);e--}for(;i!==null;){if(!i.deleted&&i.countable){if(i.length>e)return dw(t,Yt(i.id.client,i.id.clock+e),n);e-=i.length}if(i.right===null&&n<0)return dw(t,i.lastId,n);i=i.right}return dw(t,null,n)},IRt=(t,e)=>{const{type:n,tname:i,item:r,assoc:s}=e;if(r!==null)lt(t,0),FK(t,r);else if(i!==null)Fy(t,1),lp(t,i);else if(n!==null)Fy(t,2),FK(t,n);else throw Ka();return wR(t,s),t},DRt=t=>{const e=Dr();return IRt(e,t),fi(e)},MRt=t=>{let e=null,n=null,i=null;switch(Gt(t)){case 0:i=BK(t);break;case 1:n=md(t);break;case 2:e=BK(t)}const r=jce(t)?OR(t):0;return new xR(e,n,i,r)},LRt=t=>MRt(ls(t)),PRt=(t,e)=>{const n=e.store,i=t.item,r=t.type,s=t.tname,o=t.assoc;let a=null,l=0;if(i!==null){if(Pi(n,i.client)<=i.clock)return null;const u=C$(n,i),d=u.item;if(!(d instanceof Hn))return null;if(a=d.parent,a._item===null||!a._item.deleted){l=d.deleted||!d.countable?0:u.diff+(o>=0?0:1);let p=d.left;for(;p!==null;)!p.deleted&&p.countable&&(l+=p.length),p=p.left}}else{if(s!==null)a=e.get(s);else if(r!==null){if(Pi(n,r.client)<=r.clock)return null;const{item:u}=C$(n,r);if(u instanceof Hn&&u.content instanceof Xl)a=u.content.type;else return null}else throw Ka();o>=0?l=a._length:l=0}return NRt(a,l,t.assoc)},$Rt=(t,e)=>t===e||t!==null&&e!==null&&t.tname===e.tname&&Zh(t.item,e.item)&&Zh(t.type,e.type)&&t.assoc===e.assoc;class T9{constructor(e,n){this.ds=e,this.sv=n}}const FRt=(t,e)=>{const n=t.ds.clients,i=e.ds.clients,r=t.sv,s=e.sv;if(r.size!==s.size||n.size!==i.size)return!1;for(const[o,a]of r.entries())if(s.get(o)!==a)return!1;for(const[o,a]of n.entries()){const l=i.get(o)||[];if(a.length!==l.length)return!1;for(let u=0;u<a.length;u++){const d=a[u],p=l[u];if(d.clock!==p.clock||d.len!==p.len)return!1}}return!0},cue=(t,e=new CR)=>(nu(e,t.ds),O9(e,t.sv),e.toUint8Array()),BRt=t=>cue(t,new vv),uue=(t,e=new tue(ls(t)))=>new T9(Op(e),sue(e)),URt=t=>uue(t,new Qy(ls(t))),C9=(t,e)=>new T9(t,e),GRt=C9(TR(),new Map),QRt=t=>C9(S9(t.store),RE(t.store)),Uh=(t,e)=>e===void 0?!t.deleted:e.sv.has(t.id.client)&&(e.sv.get(t.id.client)||0)>t.id.clock&&!Yv(e.ds,t.id),b$=(t,e)=>{const n=Md(t.meta,b$,xm),i=t.doc.store;n.has(e)||(e.sv.forEach((r,s)=>{r<Pi(i,s)&&Gs(t,Yt(s,r))}),bp(t,e.ds,r=>{}),n.add(e))},qRt=(t,e,n=new Pp)=>{if(t.gc)throw new Error("originDoc must not be garbage collected");const{sv:i,ds:r}=e,s=new kd;return t.transact(o=>{let a=0;i.forEach(l=>{l>0&&a++}),lt(s.restEncoder,a);for(const[l,u]of i){if(u===0)continue;u<Pi(t.store,l)&&Gs(o,Yt(l,u));const d=t.store.clients.get(l)||[],p=ja(d,u-1);lt(s.restEncoder,p+1),s.writeClient(l),lt(s.restEncoder,0);for(let h=0;h<=p;h++)d[h].write(s,0)}nu(s,r)}),kR(n,s.toUint8Array(),"snapshot"),n};class due{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const RE=t=>{const e=new Map;return t.clients.forEach((n,i)=>{const r=n[n.length-1];e.set(i,r.id.clock+r.length)}),e},Pi=(t,e)=>{const n=t.clients.get(e);if(n===void 0)return 0;const i=n[n.length-1];return i.id.clock+i.length},fue=(t,e)=>{let n=t.clients.get(e.id.client);if(n===void 0)n=[],t.clients.set(e.id.client,n);else{const i=n[n.length-1];if(i.id.clock+i.length!==e.id.clock)throw Ka()}n.push(e)},ja=(t,e)=>{let n=0,i=t.length-1,r=t[i],s=r.id.clock;if(s===e)return i;let o=Cd(e/(s+r.length-1)*i);for(;n<=i;){if(r=t[o],s=r.id.clock,s<=e){if(e<s+r.length)return o;n=o+1}else i=o-1;o=Cd((n+i)/2)}throw Ka()},YRt=(t,e)=>{const n=t.clients.get(e.client);return n[ja(n,e.clock)]},NS=YRt,O$=(t,e,n)=>{const i=ja(e,n),r=e[i];return r.id.clock<n&&r instanceof Hn?(e.splice(i+1,0,_k(t,r,n-r.id.clock)),i+1):i},Gs=(t,e)=>{const n=t.doc.store.clients.get(e.client);return n[O$(t,n,e.clock)]},UK=(t,e,n)=>{const i=e.clients.get(n.client),r=ja(i,n.clock),s=i[r];return n.clock!==s.id.clock+s.length-1&&s.constructor!==na&&i.splice(r+1,0,_k(t,s,n.clock-s.id.clock+1)),s},zRt=(t,e,n)=>{const i=t.clients.get(e.id.client);i[ja(i,e.id.clock)]=n},pue=(t,e,n,i,r)=>{if(i===0)return;const s=n+i;let o=O$(t,e,n),a;do a=e[o++],s<a.id.clock+a.length&&O$(t,e,s),r(a);while(o<e.length&&e[o].id.clock<s)},Pd=Symbol;class WRt{constructor(e,n){this.left=e,this.right=n}}const Xu=(t,e)=>new WRt(t,e);typeof DOMParser<"u"&&new DOMParser;const HRt=t=>mxt(t,(e,n)=>`${n}:${e};`).join(""),k9=Pd(),x9=Pd(),hue=Pd(),mue=Pd(),gue=Pd(),R9=Pd(),_ue=Pd(),N9=Pd(),vue=Pd(),VRt={[k9]:Xu("font-weight","bold"),[x9]:Xu("font-weight","normal"),[hue]:Xu("color","blue"),[gue]:Xu("color","green"),[mue]:Xu("color","grey"),[R9]:Xu("color","red"),[_ue]:Xu("color","purple"),[N9]:Xu("color","orange"),[vue]:Xu("color","black")},Sue={[k9]:"\x1B[1m",[x9]:"\x1B[2m",[hue]:"\x1B[34m",[gue]:"\x1B[32m",[mue]:"\x1B[37m",[R9]:"\x1B[31m",[_ue]:"\x1B[35m",[N9]:"\x1B[38;5;208m",[vue]:"\x1B[0m"},XRt=t=>{const e=[],n=[],i=Bl();let r=[],s=0;for(;s<t.length;s++){const o=t[s],a=VRt[o];if(a!==void 0)i.set(a.left,a.right);else if(o.constructor===String||o.constructor===Number){const l=HRt(i);s>0||l.length>0?(e.push("%c"+o),n.push(l)):e.push(o)}else break}for(s>0&&(r=n,r.unshift(e.join("")));s<t.length;s++){const o=t[s];o instanceof Symbol||r.push(o)}return r},KRt=t=>{const e=[],n=[];let i=0;for(;i<t.length;i++){const r=t[i];if(Sue[r]===void 0)if(r.constructor===String||r.constructor===Number)e.push(r);else break}for(i>0&&n.push(e.join(""));i<t.length;i++){const r=t[i];r instanceof Symbol||(r.constructor===Object?n.push(JSON.stringify(r)):n.push(r))}return n},jRt=t=>{const e=[],n=[];let i=0;for(;i<t.length;i++){const r=t[i],s=Sue[r];if(s!==void 0)e.push(s);else if(r.constructor===String||r.constructor===Number)e.push(r);else break}for(i>0&&(e.push("\x1B[0m"),n.push(e.join("")));i<t.length;i++){const r=t[i];r instanceof Symbol||n.push(r)}return n},ZRt=Fxt?Rm?jRt:XRt:KRt,w$=(...t)=>{console.log(...ZRt(t)),JRt.forEach(e=>e.print(t))},JRt=xm();class yue{constructor(e,n,i){this.doc=e,this.deleteSet=new qv,this.beforeState=RE(e.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}}const GK=(t,e)=>e.deleteSet.clients.size===0&&!gxt(e.afterState,(n,i)=>e.beforeState.get(i)!==n)?!1:(v9(e.deleteSet),yRt(t,e),nu(t,e.deleteSet),!0),QK=(t,e,n)=>{const i=e._item;(i===null||i.id.clock<(t.beforeState.get(i.id.client)||0)&&!i.deleted)&&Md(t.changed,e,xm).add(n)},hT=(t,e)=>{const n=t[e-1],i=t[e];n.deleted===i.deleted&&n.constructor===i.constructor&&n.mergeWith(i)&&(t.splice(e,1),i instanceof Hn&&i.parentSub!==null&&i.parent._map.get(i.parentSub)===i&&i.parent._map.set(i.parentSub,n))},Eue=(t,e,n)=>{for(const[i,r]of t.clients.entries()){const s=e.clients.get(i);for(let o=r.length-1;o>=0;o--){const a=r[o],l=a.clock+a.len;for(let u=ja(s,a.clock),d=s[u];u<s.length&&d.id.clock<l;d=s[++u]){const p=s[u];if(a.clock+a.len<=p.id.clock)break;p instanceof Hn&&p.deleted&&!p.keep&&n(p)&&p.gc(e,!1)}}}},bue=(t,e)=>{t.clients.forEach((n,i)=>{const r=e.clients.get(i);for(let s=n.length-1;s>=0;s--){const o=n[s],a=d9(r.length-1,1+ja(r,o.clock+o.len-1));for(let l=a,u=r[l];l>0&&u.id.clock>=o.clock;u=r[--l])hT(r,l)}})},eNt=(t,e,n)=>{Eue(t,e,n),bue(t,e)},Oue=(t,e)=>{if(e<t.length){const n=t[e],i=n.doc,r=i.store,s=n.deleteSet,o=n._mergeStructs;try{v9(s),n.afterState=RE(n.doc.store),i.emit("beforeObserverCalls",[n,i]);const a=[];n.changed.forEach((l,u)=>a.push(()=>{(u._item===null||!u._item.deleted)&&u._callObserver(n,l)})),a.push(()=>{n.changedParentTypes.forEach((l,u)=>a.push(()=>{(u._item===null||!u._item.deleted)&&(l=l.filter(d=>d.target._item===null||!d.target._item.deleted),l.forEach(d=>{d.currentTarget=u}),l.sort((d,p)=>d.path.length-p.path.length),aue(u._dEH,l,n))})),a.push(()=>i.emit("afterTransaction",[n,i]))}),f9(a,[])}finally{i.gc&&Eue(s,r,i.gcFilter),bue(s,r),n.afterState.forEach((d,p)=>{const h=n.beforeState.get(p)||0;if(h!==d){const g=r.clients.get(p),y=Um(ja(g,h),1);for(let O=g.length-1;O>=y;O--)hT(g,O)}});for(let d=0;d<o.length;d++){const{client:p,clock:h}=o[d].id,g=r.clients.get(p),y=ja(g,h);y+1<g.length&&hT(g,y+1),y>0&&hT(g,y)}if(!n.local&&n.afterState.get(i.clientID)!==n.beforeState.get(i.clientID)&&(w$(N9,k9,"[yjs] ",x9,R9,"Changed the client-id because another client seems to be using it."),i.clientID=eue()),i.emit("afterTransactionCleanup",[n,i]),i._observers.has("update")){const d=new Gm;GK(d,n)&&i.emit("update",[d.toUint8Array(),n.origin,i,n])}if(i._observers.has("updateV2")){const d=new kd;GK(d,n)&&i.emit("updateV2",[d.toUint8Array(),n.origin,i,n])}const{subdocsAdded:a,subdocsLoaded:l,subdocsRemoved:u}=n;(a.size>0||u.size>0||l.size>0)&&(a.forEach(d=>{d.clientID=i.clientID,d.collectionid==null&&(d.collectionid=i.collectionid),i.subdocs.add(d)}),u.forEach(d=>i.subdocs.delete(d)),i.emit("subdocs",[{loaded:l,added:a,removed:u},i,n]),u.forEach(d=>d.destroy())),t.length<=e+1?(i._transactionCleanups=[],i.emit("afterAllTransactions",[i,t])):Oue(t,e+1)}}},Wn=(t,e,n=null,i=!0)=>{const r=t._transactionCleanups;let s=!1,o=null;t._transaction===null&&(s=!0,t._transaction=new yue(t,n,i),r.push(t._transaction),r.length===1&&t.emit("beforeAllTransactions",[t]),t.emit("beforeTransaction",[t._transaction,t]));try{o=e(t._transaction)}finally{if(s){const a=t._transaction===r[0];t._transaction=null,a&&Oue(r,0)}}return o};class tNt{constructor(e,n){this.insertions=n,this.deletions=e,this.meta=new Map}}const qK=(t,e,n)=>{bp(t,n.deletions,i=>{i instanceof Hn&&e.scope.some(r=>qy(r,i))&&$9(i,!1)})},YK=(t,e,n)=>{let i=null,r=null;const s=t.doc,o=t.scope;if(Wn(s,a=>{for(;e.length>0&&i===null;){const l=s.store,u=e.pop(),d=new Set,p=[];let h=!1;bp(a,u.insertions,g=>{if(g instanceof Hn){if(g.redone!==null){let{item:y,diff:O}=C$(l,g.id);O>0&&(y=Gs(a,Yt(y.id.client,y.id.clock+O))),g=y}!g.deleted&&o.some(y=>qy(y,g))&&p.push(g)}}),bp(a,u.deletions,g=>{g instanceof Hn&&o.some(y=>qy(y,g))&&!Yv(u.insertions,g.id)&&d.add(g)}),d.forEach(g=>{h=ede(a,g,d,u.insertions,t.ignoreRemoteMapChanges)!==null||h});for(let g=p.length-1;g>=0;g--){const y=p[g];t.deleteFilter(y)&&(y.delete(a),h=!0)}i=h?u:null}a.changed.forEach((l,u)=>{l.has(null)&&u._searchMarker&&(u._searchMarker.length=0)}),r=a},t),i!=null){const a=r.changedParentTypes;t.emit("stack-item-popped",[{stackItem:i,type:n,changedParentTypes:a},t])}return i};class nNt extends CE{constructor(e,{captureTimeout:n=500,captureTransaction:i=l=>!0,deleteFilter:r=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:a=EK(e)?e[0].doc:e.doc}={}){super(),this.scope=[],this.addToScope(e),this.deleteFilter=r,s.add(this),this.trackedOrigins=s,this.captureTransaction=i,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.doc=a,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=n,this.afterTransactionHandler=l=>{if(!this.captureTransaction(l)||!this.scope.some(b=>l.changedParentTypes.has(b))||!this.trackedOrigins.has(l.origin)&&(!l.origin||!this.trackedOrigins.has(l.origin.constructor)))return;const u=this.undoing,d=this.redoing,p=u?this.redoStack:this.undoStack;u?this.stopCapturing():d||this.clear(!1,!0);const h=new qv;l.afterState.forEach((b,w)=>{const T=l.beforeState.get(w)||0,x=b-T;x>0&&Gy(h,w,T,x)});const g=wp();let y=!1;if(this.lastChange>0&&g-this.lastChange<this.captureTimeout&&p.length>0&&!u&&!d){const b=p[p.length-1];b.deletions=Uy([b.deletions,l.deleteSet]),b.insertions=Uy([b.insertions,h])}else p.push(new tNt(l.deleteSet,h)),y=!0;!u&&!d&&(this.lastChange=g),bp(l,l.deleteSet,b=>{b instanceof Hn&&this.scope.some(w=>qy(w,b))&&$9(b,!0)});const O=[{stackItem:p[p.length-1],origin:l.origin,type:u?"redo":"undo",changedParentTypes:l.changedParentTypes},this];y?this.emit("stack-item-added",O):this.emit("stack-item-updated",O)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(e){e=EK(e)?e:[e],e.forEach(n=>{this.scope.every(i=>i!==n)&&this.scope.push(n)})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,n=!0){(e&&this.canUndo()||n&&this.canRedo())&&this.doc.transact(i=>{e&&(this.undoStack.forEach(r=>qK(i,this,r)),this.undoStack=[]),n&&(this.redoStack.forEach(r=>qK(i,this,r)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=YK(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=YK(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}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*iNt(t){const e=Gt(t.restDecoder);for(let n=0;n<e;n++){const i=Gt(t.restDecoder),r=t.readClient();let s=Gt(t.restDecoder);for(let o=0;o<i;o++){const a=t.readInfo();if(a===10){const l=Gt(t.restDecoder);yield new ia(Yt(r,s),l),s+=l}else if(ER&a){const l=(a&(hd|ca))===0,u=new Hn(Yt(r,s),null,(a&ca)===ca?t.readLeftID():null,null,(a&hd)===hd?t.readRightID():null,l?t.readParentInfo()?t.readString():t.readLeftID():null,l&&(a&Py)===Py?t.readString():null,tde(t,a));yield u,s+=u.length}else{const l=t.readLen();yield new na(Yt(r,s),l),s+=l}}}}class Qm{constructor(e,n){this.gen=iNt(e),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===ia);return this.curr}}const rNt=t=>wue(t,Ld),wue=(t,e=iu)=>{const n=[],i=new e(ls(t)),r=new Qm(i,!1);for(let o=r.curr;o!==null;o=r.next())n.push(o);w$("Structs: ",n);const s=Op(i);w$("DeleteSet: ",s)},sNt=t=>Tue(t,Ld),Tue=(t,e=iu)=>{const n=[],i=new e(ls(t)),r=new Qm(i,!1);for(let s=r.curr;s!==null;s=r.next())n.push(s);return{structs:n,ds:Op(i)}};class A9{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}}const Cue=t=>Yy(t,Ld,Gm),kue=(t,e=CR,n=iu)=>{const i=new e,r=new Qm(new n(ls(t)),!1);let s=r.curr;if(s!==null){let o=0,a=s.id.client,l=s.id.clock!==0,u=l?0:s.id.clock+s.length;for(;s!==null;s=r.next())a!==s.id.client&&(u!==0&&(o++,lt(i.restEncoder,a),lt(i.restEncoder,u)),a=s.id.client,u=0,l=s.id.clock!==0),s.constructor===ia&&(l=!0),l||(u=s.id.clock+s.length);u!==0&&(o++,lt(i.restEncoder,a),lt(i.restEncoder,u));const d=Dr();return lt(d,o),aRt(d,i.restEncoder),i.restEncoder=d,i.toUint8Array()}else return lt(i.restEncoder,0),i.toUint8Array()},oNt=t=>kue(t,vv,Ld),xue=(t,e=iu)=>{const n=new Map,i=new Map,r=new Qm(new e(ls(t)),!1);let s=r.curr;if(s!==null){let o=s.id.client,a=s.id.clock;for(n.set(o,a);s!==null;s=r.next())o!==s.id.client&&(i.set(o,a),n.set(s.id.client,s.id.clock),o=s.id.client),a=s.id.clock+s.length;i.set(o,a)}return{from:n,to:i}},aNt=t=>xue(t,Ld),lNt=(t,e)=>{if(t.constructor===na){const{client:n,clock:i}=t.id;return new na(Yt(n,i+e),t.length-e)}else if(t.constructor===ia){const{client:n,clock:i}=t.id;return new ia(Yt(n,i+e),t.length-e)}else{const n=t,{client:i,clock:r}=n.id;return new Hn(Yt(i,r+e),null,Yt(i,r+e-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(e))}},Yy=(t,e=iu,n=kd)=>{if(t.length===1)return t[0];const i=t.map(d=>new e(ls(d)));let r=i.map(d=>new Qm(d,!0)),s=null;const o=new n,a=new A9(o);for(;r=r.filter(h=>h.curr!==null),r.sort((h,g)=>{if(h.curr.id.client===g.curr.id.client){const y=h.curr.id.clock-g.curr.id.clock;return y===0?h.curr.constructor===g.curr.constructor?0:h.curr.constructor===ia?1:-1:y}else return g.curr.id.client-h.curr.id.client}),r.length!==0;){const d=r[0],p=d.curr.id.client;if(s!==null){let h=d.curr,g=!1;for(;h!==null&&h.id.clock+h.length<=s.struct.id.clock+s.struct.length&&h.id.client>=s.struct.id.client;)h=d.next(),g=!0;if(h===null||h.id.client!==p||g&&h.id.clock>s.struct.id.clock+s.struct.length)continue;if(p!==s.struct.id.client)Mf(a,s.struct,s.offset),s={struct:h,offset:0},d.next();else if(s.struct.id.clock+s.struct.length<h.id.clock)if(s.struct.constructor===ia)s.struct.length=h.id.clock+h.length-s.struct.id.clock;else{Mf(a,s.struct,s.offset);const y=h.id.clock-s.struct.id.clock-s.struct.length;s={struct:new ia(Yt(p,s.struct.id.clock+s.struct.length),y),offset:0}}else{const y=s.struct.id.clock+s.struct.length-h.id.clock;y>0&&(s.struct.constructor===ia?s.struct.length-=y:h=lNt(h,y)),s.struct.mergeWith(h)||(Mf(a,s.struct,s.offset),s={struct:h,offset:0},d.next())}}else s={struct:d.curr,offset:0},d.next();for(let h=d.curr;h!==null&&h.id.client===p&&h.id.clock===s.struct.id.clock+s.struct.length&&h.constructor!==ia;h=d.next())Mf(a,s.struct,s.offset),s={struct:h,offset:0}}s!==null&&(Mf(a,s.struct,s.offset),s=null),D9(a);const l=i.map(d=>Op(d)),u=Uy(l);return nu(o,u),o.toUint8Array()},I9=(t,e,n=iu,i=kd)=>{const r=b9(e),s=new i,o=new A9(s),a=new n(ls(t)),l=new Qm(a,!1);for(;l.curr;){const d=l.curr,p=d.id.client,h=r.get(p)||0;if(l.curr.constructor===ia){l.next();continue}if(d.id.clock+d.length>h)for(Mf(o,d,Um(h-d.id.clock,0)),l.next();l.curr&&l.curr.id.client===p;)Mf(o,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===p&&l.curr.id.clock+l.curr.length<=h;)l.next()}D9(o);const u=Op(a);return nu(s,u),s.toUint8Array()},cNt=(t,e)=>I9(t,e,Ld,Gm),Rue=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:fi(t.encoder.restEncoder)}),t.encoder.restEncoder=Dr(),t.written=0)},Mf=(t,e,n)=>{t.written>0&&t.currClient!==e.id.client&&Rue(t),t.written===0&&(t.currClient=e.id.client,t.encoder.writeClient(e.id.client),lt(t.encoder.restEncoder,e.id.clock+n)),e.write(t.encoder,n),t.written++},D9=t=>{Rue(t);const e=t.encoder.restEncoder;lt(e,t.clientStructs.length);for(let n=0;n<t.clientStructs.length;n++){const i=t.clientStructs[n];lt(e,i.written),xE(e,i.restEncoder)}},Nue=(t,e,n)=>{const i=new e(ls(t)),r=new Qm(i,!1),s=new n,o=new A9(s);for(let l=r.curr;l!==null;l=r.next())Mf(o,l,0);D9(o);const a=Op(i);return nu(s,a),s.toUint8Array()},uNt=t=>Nue(t,Ld,kd),Aue=t=>Nue(t,iu,Gm);class NE{constructor(e,n){this.target=e,this.currentTarget=e,this.transaction=n,this._changes=null,this._keys=null,this._delta=null}get path(){return dNt(this.currentTarget,this.target)}deletes(e){return Yv(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){const e=new Map,n=this.target;this.transaction.changed.get(n).forEach(r=>{if(r!==null){const s=n._map.get(r);let o,a;if(this.adds(s)){let l=s.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(s))if(l!==null&&this.deletes(l))o="delete",a=BL(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",a=BL(l.content.getContent())):(o="add",a=void 0)}else if(this.deletes(s))o="delete",a=BL(s.content.getContent());else return;e.set(r,{action:o,oldValue:a})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){const n=this.target,i=xm(),r=xm(),s=[];if(e={added:i,deleted:r,delta:s,keys:this.keys},this.transaction.changed.get(n).has(null)){let a=null;const l=()=>{a&&s.push(a)};for(let u=n._start;u!==null;u=u.right)u.deleted?this.deletes(u)&&!this.adds(u)&&((a===null||a.delete===void 0)&&(l(),a={delete:0}),a.delete+=u.length,r.add(u)):this.adds(u)?((a===null||a.insert===void 0)&&(l(),a={insert:[]}),a.insert=a.insert.concat(u.content.getContent()),i.add(u)):((a===null||a.retain===void 0)&&(l(),a={retain:0}),a.retain+=u.length);a!==null&&a.retain===void 0&&l()}this._changes=e}return e}}const dNt=(t,e)=>{const n=[];for(;e._item!==null&&e!==t;){if(e._item.parentSub!==null)n.unshift(e._item.parentSub);else{let i=0,r=e._item.parent._start;for(;r!==e._item&&r!==null;)r.deleted||i++,r=r.right;n.unshift(i)}e=e._item.parent}return n},Iue=t=>({[Symbol.iterator](){return this},next:t}),fNt=(t,e)=>Iue(()=>{let n;do n=t.next();while(!n.done&&!e(n.value));return n}),YL=(t,e)=>Iue(()=>{const{done:n,value:i}=t.next();return{done:n,value:n?void 0:e(i)}}),Due=80;let M9=0;class pNt{constructor(e,n){e.marker=!0,this.p=e,this.index=n,this.timestamp=M9++}}const hNt=t=>{t.timestamp=M9++},Mue=(t,e,n)=>{t.p.marker=!1,t.p=e,e.marker=!0,t.index=n,t.timestamp=M9++},mNt=(t,e,n)=>{if(t.length>=Due){const i=t.reduce((r,s)=>r.timestamp<s.timestamp?r:s);return Mue(i,e,n),i}else{const i=new pNt(e,n);return t.push(i),i}},RR=(t,e)=>{if(t._start===null||e===0||t._searchMarker===null)return null;const n=t._searchMarker.length===0?null:t._searchMarker.reduce((s,o)=>dT(e-s.index)<dT(e-o.index)?s:o);let i=t._start,r=0;for(n!==null&&(i=n.p,r=n.index,hNt(n));i.right!==null&&r<e;){if(!i.deleted&&i.countable){if(e<r+i.length)break;r+=i.length}i=i.right}for(;i.left!==null&&r>e;)i=i.left,!i.deleted&&i.countable&&(r-=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&&(r-=i.length);return n!==null&&dT(n.index-r)<i.parent.length/Due?(Mue(n,i,r),n):mNt(t._searchMarker,i,r)},zy=(t,e,n)=>{for(let i=t.length-1;i>=0;i--){const r=t[i];if(n>0){let s=r.p;for(s.marker=!1;s&&(s.deleted||!s.countable);)s=s.left,s&&!s.deleted&&s.countable&&(r.index-=s.length);if(s===null||s.marker===!0){t.splice(i,1);continue}r.p=s,s.marker=!0}(e<r.index||n>0&&e===r.index)&&(r.index=Um(e,r.index+n))}},gNt=t=>{let e=t._start;const n=[];for(;e;)n.push(e),e=e.right;return n},NR=(t,e,n)=>{const i=t,r=e.changedParentTypes;for(;Md(r,t,()=>[]).push(n),t._item!==null;)t=t._item.parent;aue(i._eH,n,e)};class Fr{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=LK(),this._dEH=LK(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,n){this.doc=e,this._item=n}_copy(){throw Jc()}clone(){throw Jc()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,n){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){PK(this._eH,e)}observeDeep(e){PK(this._dEH,e)}unobserve(e){$K(this._eH,e)}unobserveDeep(e){$K(this._dEH,e)}toJSON(){}}const Lue=(t,e,n)=>{e<0&&(e=t._length+e),n<0&&(n=t._length+n);let i=n-e;const r=[];let s=t._start;for(;s!==null&&i>0;){if(s.countable&&!s.deleted){const o=s.content.getContent();if(o.length<=e)e-=o.length;else{for(let a=e;a<o.length&&i>0;a++)r.push(o[a]),i--;e=0}}s=s.right}return r},Pue=t=>{const e=[];let n=t._start;for(;n!==null;){if(n.countable&&!n.deleted){const i=n.content.getContent();for(let r=0;r<i.length;r++)e.push(i[r])}n=n.right}return e},_Nt=(t,e)=>{const n=[];let i=t._start;for(;i!==null;){if(i.countable&&Uh(i,e)){const r=i.content.getContent();for(let s=0;s<r.length;s++)n.push(r[s])}i=i.right}return n},Wy=(t,e)=>{let n=0,i=t._start;for(;i!==null;){if(i.countable&&!i.deleted){const r=i.content.getContent();for(let s=0;s<r.length;s++)e(r[s],n++,t)}i=i.right}},$ue=(t,e)=>{const n=[];return Wy(t,(i,r)=>{n.push(e(i,r,t))}),n},vNt=t=>{let e=t._start,n=null,i=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};n=e.content.getContent(),i=0,e=e.right}const r=n[i++];return n.length<=i&&(n=null),{done:!1,value:r}}}},Fue=(t,e)=>{const n=RR(t,e);let i=t._start;for(n!==null&&(i=n.p,e-=n.index);i!==null;i=i.right)if(!i.deleted&&i.countable){if(e<i.length)return i.content.getContent()[e];e-=i.length}},mk=(t,e,n,i)=>{let r=n;const s=t.doc,o=s.clientID,a=s.store,l=n===null?e._start:n.right;let u=[];const d=()=>{u.length>0&&(r=new Hn(Yt(o,Pi(a,o)),r,r&&r.lastId,l,l&&l.id,e,null,new kp(u)),r.integrate(t,0),u=[])};i.forEach(p=>{if(p===null)u.push(p);else switch(p.constructor){case Number:case Object:case Boolean:case Array:case String:u.push(p);break;default:switch(d(),p.constructor){case Uint8Array:case ArrayBuffer:r=new Hn(Yt(o,Pi(a,o)),r,r&&r.lastId,l,l&&l.id,e,null,new Wv(new Uint8Array(p))),r.integrate(t,0);break;case Pp:r=new Hn(Yt(o,Pi(a,o)),r,r&&r.lastId,l,l&&l.id,e,null,new AE(p)),r.integrate(t,0);break;default:if(p instanceof Fr)r=new Hn(Yt(o,Pi(a,o)),r,r&&r.lastId,l,l&&l.id,e,null,new Xl(p)),r.integrate(t,0);else throw new Error("Unexpected content type in insert operation")}}}),d()},Bue=Qv("Length exceeded!"),Uue=(t,e,n,i)=>{if(n>e._length)throw Bue;if(n===0)return e._searchMarker&&zy(e._searchMarker,n,i.length),mk(t,e,null,i);const r=n,s=RR(e,n);let o=e._start;for(s!==null&&(o=s.p,n-=s.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&Gs(t,Yt(o.id.client,o.id.clock+n));break}n-=o.length}return e._searchMarker&&zy(e._searchMarker,r,i.length),mk(t,e,o,i)},SNt=(t,e,n)=>{let r=(e._searchMarker||[]).reduce((s,o)=>o.index>s.index?o:s,{index:0,p:e._start}).p;if(r)for(;r.right;)r=r.right;return mk(t,e,r,n)},Gue=(t,e,n,i)=>{if(i===0)return;const r=n,s=i,o=RR(e,n);let a=e._start;for(o!==null&&(a=o.p,n-=o.index);a!==null&&n>0;a=a.right)!a.deleted&&a.countable&&(n<a.length&&Gs(t,Yt(a.id.client,a.id.clock+n)),n-=a.length);for(;i>0&&a!==null;)a.deleted||(i<a.length&&Gs(t,Yt(a.id.client,a.id.clock+i)),a.delete(t),i-=a.length),a=a.right;if(i>0)throw Bue;e._searchMarker&&zy(e._searchMarker,r,-s+i)},gk=(t,e,n)=>{const i=e._map.get(n);i!==void 0&&i.delete(t)},L9=(t,e,n,i)=>{const r=e._map.get(n)||null,s=t.doc,o=s.clientID;let a;if(i==null)a=new kp([i]);else switch(i.constructor){case Number:case Object:case Boolean:case Array:case String:a=new kp([i]);break;case Uint8Array:a=new Wv(i);break;case Pp:a=new AE(i);break;default:if(i instanceof Fr)a=new Xl(i);else throw new Error("Unexpected content type")}new Hn(Yt(o,Pi(s.store,o)),r,r&&r.lastId,null,null,e,n,a).integrate(t,0)},P9=(t,e)=>{const n=t._map.get(e);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Que=t=>{const e={};return t._map.forEach((n,i)=>{n.deleted||(e[i]=n.content.getContent()[n.length-1])}),e},que=(t,e)=>{const n=t._map.get(e);return n!==void 0&&!n.deleted},yNt=(t,e,n)=>{let i=t._map.get(e)||null;for(;i!==null&&(!n.sv.has(i.id.client)||i.id.clock>=(n.sv.get(i.id.client)||0));)i=i.left;return i!==null&&Uh(i,n)?i.content.getContent()[i.length-1]:void 0},fw=t=>fNt(t.entries(),e=>!e[1].deleted);class Yue extends NE{constructor(e,n){super(e,n),this._transaction=n}}class gd extends Fr{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const n=new gd;return n.push(e),n}_integrate(e,n){super._integrate(e,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new gd}clone(){const e=new gd;return e.insert(0,this.toArray().map(n=>n instanceof Fr?n.clone():n)),e}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}_callObserver(e,n){super._callObserver(e,n),NR(this,e,new Yue(this,e))}insert(e,n){this.doc!==null?Wn(this.doc,i=>{Uue(i,this,e,n)}):this._prelimContent.splice(e,0,...n)}push(e){this.doc!==null?Wn(this.doc,n=>{SNt(n,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,n=1){this.doc!==null?Wn(this.doc,i=>{Gue(i,this,e,n)}):this._prelimContent.splice(e,n)}get(e){return Fue(this,e)}toArray(){return Pue(this)}slice(e=0,n=this.length){return Lue(this,e,n)}toJSON(){return this.map(e=>e instanceof Fr?e.toJSON():e)}map(e){return $ue(this,e)}forEach(e){Wy(this,e)}[Symbol.iterator](){return vNt(this)}_write(e){e.writeTypeRef(BNt)}}const ENt=t=>new gd;class zue extends NE{constructor(e,n,i){super(e,n),this.keysChanged=i}}class Tp extends Fr{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,n){super._integrate(e,n),this._prelimContent.forEach((i,r)=>{this.set(r,i)}),this._prelimContent=null}_copy(){return new Tp}clone(){const e=new Tp;return this.forEach((n,i)=>{e.set(i,n instanceof Fr?n.clone():n)}),e}_callObserver(e,n){NR(this,e,new zue(this,e,n))}toJSON(){const e={};return this._map.forEach((n,i)=>{if(!n.deleted){const r=n.content.getContent()[n.length-1];e[i]=r instanceof Fr?r.toJSON():r}}),e}get size(){return[...fw(this._map)].length}keys(){return YL(fw(this._map),e=>e[0])}values(){return YL(fw(this._map),e=>e[1].content.getContent()[e[1].length-1])}entries(){return YL(fw(this._map),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this._map.forEach((n,i)=>{n.deleted||e(n.content.getContent()[n.length-1],i,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?Wn(this.doc,n=>{gk(n,this,e)}):this._prelimContent.delete(e)}set(e,n){return this.doc!==null?Wn(this.doc,i=>{L9(i,this,e,n)}):this._prelimContent.set(e,n),n}get(e){return P9(this,e)}has(e){return que(this,e)}clear(){this.doc!==null?Wn(this.doc,e=>{this.forEach(function(n,i,r){gk(e,r,i)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(UNt)}}const bNt=t=>new Tp,Vf=(t,e)=>t===e||typeof t=="object"&&typeof e=="object"&&t&&e&&Dxt(t,e);class T${constructor(e,n,i,r){this.left=e,this.right=n,this.index=i,this.currentAttributes=r}forward(){switch(this.right===null&&Ka(),this.right.content.constructor){case ur:this.right.deleted||zv(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 zK=(t,e,n)=>{for(;e.right!==null&&n>0;){switch(e.right.content.constructor){case ur:e.right.deleted||zv(e.currentAttributes,e.right.content);break;default:e.right.deleted||(n<e.right.length&&Gs(t,Yt(e.right.id.client,e.right.id.clock+n)),e.index+=e.right.length,n-=e.right.length);break}e.left=e.right,e.right=e.right.right}return e},pw=(t,e,n)=>{const i=new Map,r=RR(e,n);if(r){const s=new T$(r.p.left,r.p,r.index,i);return zK(t,s,n-r.index)}else{const s=new T$(null,e._start,0,i);return zK(t,s,n)}},Wue=(t,e,n,i)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===ur&&Vf(i.get(n.right.content.key),n.right.content.value));)n.right.deleted||i.delete(n.right.content.key),n.forward();const r=t.doc,s=r.clientID;i.forEach((o,a)=>{const l=n.left,u=n.right,d=new Hn(Yt(s,Pi(r.store,s)),l,l&&l.lastId,u,u&&u.id,e,null,new ur(a,o));d.integrate(t,0),n.right=d,n.forward()})},zv=(t,e)=>{const{key:n,value:i}=e;i===null?t.delete(n):t.set(n,i)},Hue=(t,e)=>{for(;t.right!==null;){if(!(t.right.deleted||t.right.content.constructor===ur&&Vf(e[t.right.content.key]||null,t.right.content.value)))break;t.forward()}},Vue=(t,e,n,i)=>{const r=t.doc,s=r.clientID,o=new Map;for(const a in i){const l=i[a],u=n.currentAttributes.get(a)||null;if(!Vf(u,l)){o.set(a,u);const{left:d,right:p}=n;n.right=new Hn(Yt(s,Pi(r.store,s)),d,d&&d.lastId,p,p&&p.id,e,null,new ur(a,l)),n.right.integrate(t,0),n.forward()}}return o},zL=(t,e,n,i,r)=>{n.currentAttributes.forEach((h,g)=>{r[g]===void 0&&(r[g]=null)});const s=t.doc,o=s.clientID;Hue(n,r);const a=Vue(t,e,n,r),l=i.constructor===String?new Ql(i):i instanceof Fr?new Xl(i):new $p(i);let{left:u,right:d,index:p}=n;e._searchMarker&&zy(e._searchMarker,n.index,l.getLength()),d=new Hn(Yt(o,Pi(s.store,o)),u,u&&u.lastId,d,d&&d.id,e,null,l),d.integrate(t,0),n.right=d,n.index=p,n.forward(),Wue(t,e,n,a)},WK=(t,e,n,i,r)=>{const s=t.doc,o=s.clientID;Hue(n,r);const a=Vue(t,e,n,r);e:for(;n.right!==null&&(i>0||a.size>0&&(n.right.deleted||n.right.content.constructor===ur));){if(!n.right.deleted)switch(n.right.content.constructor){case ur:{const{key:l,value:u}=n.right.content,d=r[l];if(d!==void 0){if(Vf(d,u))a.delete(l);else{if(i===0)break e;a.set(l,u)}n.right.delete(t)}else n.currentAttributes.set(l,u);break}default:i<n.right.length&&Gs(t,Yt(n.right.id.client,n.right.id.clock+i)),i-=n.right.length;break}n.forward()}if(i>0){let l="";for(;i>0;i--)l+=`
|
|
1112
|
+
`);t.current.codemirror.focus(),g.replaceSelection(O,"end")}return{openImageUploadDialog:u,uploadImages:l,insertUnsplashImage:d,imageInputRef:n,progress:i,errors:s,isLoading:o,filesNumber:a}}function ckt({markdown:t,updateMarkdown:e,imageUploader:n,unsplashConf:i,autofocus:r=!0,placeholder:s=""}){const o=U.useRef(null),a=U.useRef(null),[l,u]=U.useState(!1),[d,p]=U.useState(!1),{openImageUploadDialog:h,uploadImages:g,insertUnsplashImage:y,imageInputRef:O,progress:b,errors:w,isLoading:T,filesNumber:x}=lkt(a,n),R={openImageDialog:`${FL}-Alt-I`,toggleSpellcheck:`${FL}-Alt-S`,openUnsplashDialog:`${FL}-Alt-U`};U.useLayoutEffect(()=>{a.current=new KCt({element:o.current,autofocus:r,indentWithTabs:!1,placeholder:s,tabSize:4,shortcuts:{toggleFullScreen:null,togglePreview:null,toggleSideBySide:null,drawImage:null},hideIcons:Z(),status:[],toolbar:["bold","italic","heading","|","quote","unordered-list","ordered-list","|","link",{name:"image",action:h,className:"fa fa-picture-o",title:`Upload Image(s) (${R.openImageDialog})`},{name:"unsplash",action:Y,className:"fa fa-camera",title:`Add Image from Unsplash (${R.openUnsplashDialog})`},"|",{name:"spellcheck",action:L,className:"fa fa-check active",title:`Spellcheck (${R.toggleSpellcheck})`},{name:"guide",action:q,className:"fa fa-question-circle",title:"Markdown Guide"}]});const V=a.current;return V.value(t??""),V.codemirror.on("change",(z,X)=>{X.origin!=="setValue"&&e(a.current.value())}),V.codemirror.setOption("specialChars",/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff\xa0]/g),r&&V.codemirror.execCommand("goDocEnd"),V.codemirror.on("mousedown",(z,X)=>{X.stopPropagation()}),A(),()=>{a.current.toTextArea()}},[]);function A(){const V=a.current.codemirror,z=V.getOption("extraKeys");z[R.toggleSpellcheck]=L,z[R.openImageDialog]=h,i&&(z[R.openUnsplashDialog]=Y),V.setOption("extraKeys",z)}function L(){let V=a.current.codemirror;V.getOption("mode")==="spell-checker"?V.setOption("mode","gfm"):V.setOption("mode","spell-checker"),F()}function F(){let V=a.current.toolbarElements.spellcheck;V&&(a.current.codemirror.getOption("mode")==="spell-checker"?V.classList.add("active"):V.classList.remove("active"))}function q(){u(!0)}function H(){u(!1)}function Z(){let V=[];return i||V.push("unsplash"),V}function Y(){p(!0)}function G(){a.current.codemirror.focus(),p(!1)}function ie(V){y(V),p(!1)}return Ee("div",{className:"not-kg-prose",children:[I("textarea",{ref:o}),I(TCt,{isOpen:l,onClose:H}),I(xCt,{errors:w,filesNumber:x,inputRef:O,loading:T,progress:b,onChange:g}),d&&I(kce,{unsplashConf:i,onClose:G,onImageInsert:ie})]})}function xce({markdown:t="",updateMarkdown:e,isEditing:n,imageUploader:i,unsplashConf:r}){return I(qn,{children:n?I("div",{className:"markdown-editor",children:I(ckt,{imageUploader:i,markdown:t,unsplashConf:r,updateMarkdown:e})}):I(ukt,{markdown:t})})}function ukt({markdown:t}){const e=bee.render(t),n=mce(e,{replaceJS:!0});return I("div",{dangerouslySetInnerHTML:{__html:n},className:"whitespace-normal"})}xce.propTypes={markdown:et.string};const dkt=t=>U.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",...t},U.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",d:"M2 14V6l4 4 4-4v8m6-7.93v7.916M13.5 11.5l2.48 2.525L18.5 11.5"}));function fkt({nodeKey:t,markdown:e}){const[n]=Qt.useLexicalComposerContext(),i=ue.useContext(qa),{fileUploader:r,cardConfig:s}=ue.useContext(Io),o=a=>{n.update(()=>{J.$getNodeByKey(t).setMarkdown(a)})};return I(xce,{imageUploader:r.useFileUpload,isEditing:i.isEditing,markdown:e,nodeKey:t,unsplashConf:s.unsplash,updateMarkdown:o})}class vR extends jlt{static getType(){return"markdown"}getIcon(){return A3}decorate(){return I(Id,{IndicatorIcon:dkt,nodeKey:this.getKey(),width:this.__cardWidth,wrapperStyle:"wide",children:I(fkt,{markdown:this.__markdown,nodeKey:this.getKey()})})}}He(vR,"kgMenu",{label:"Markdown",desc:"Insert a Markdown editor card",Icon:A3,insertCommand:wee,matches:["markdown","md"]});function pkt(t){return new vR(t)}var Rce={},hkt=Qt,mkt=U;Rce.AutoFocusPlugin=function({defaultSelection:t}){let[e]=hkt.useLexicalComposerContext();return mkt.useEffect(()=>{e.focus(()=>{let n=document.activeElement,i=e.getRootElement();i===null||n!==null&&i.contains(n)||i.focus({preventScroll:!0})},{defaultSelection:t})},[t,e]),null};const gkt=Rce;var _kt=gkt;const vkt=({text:t="Type here",className:e=""})=>I("div",{className:`not-kg-prose pointer-events-none absolute top-0 left-0 min-w-full cursor-text ${e}`,children:t}),_K=({text:t,setText:e,placeholderText:n,textClassName:i,placeholderClassName:r,readOnly:s,autoFocus:o=!1,singleParagraph:a=!1})=>I(Gv,{nodes:Fce,children:Ee(yp,{className:i,isDragEnabled:!1,markdownTransformers:wle,placeholder:I(vkt,{className:r,text:n}),readOnly:s,children:[a&&I(TE,{paragraphs:1}),o&&I(_kt.AutoFocusPlugin,{}),I(yR,{html:t,setHtml:e})]})}),Skt=t=>U.createElement("svg",{id:"Regular",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",...t},U.createElement("defs",null,U.createElement("style",null,".cls-1{fill:none;stroke:currentColor;stroke-linecap:round;stroke-linejoin:round;fill-rule:evenodd;}")),U.createElement("title",null,"arrow-down-1"),U.createElement("path",{className:"cls-1",d:"M23.25,7.311,12.53,18.03a.749.749,0,0,1-1.06,0L.75,7.311"}));function l9({content:t,contentPlaceholder:e,focusOnContent:n,focusOnHeader:i,header:r,headerPlaceholder:s,isContentFocused:o,isContentVisible:a,isEditing:l,isHeaderFocused:u,setContent:d,setHeader:p,toggleContent:h,toggleRef:g}){return Ee("div",{className:"rounded border border-grey/40 py-4 px-6 dark:border-grey/30",children:[Ee("div",{className:"flex cursor-text items-start justify-between",children:[I("div",{className:"mr-2 w-full",onClick:i,onKeyDown:n,children:I(_K,{autoFocus:u,placeholderClassName:"kg-toggle-header-placeholder",placeholderText:s,readOnly:!l,setText:p,singleParagraph:!0,text:r,textClassName:"kg-toggle-header-text"})}),I("div",{ref:g,className:"ml-auto mt-[-1px] flex h-8 w-8 shrink-0 items-center justify-center",onClick:h,children:I(Skt,{className:`h-4 w-4 stroke-2 text-grey-400 dark:text-grey/30 ${a?"rotate-180":"rotate-0"}`})})]}),I("div",{className:`mt-2 w-full ${a?"visible":"hidden"}`,children:I(_K,{autoFocus:o,placeholderClassName:"kg-toggle-content-placeholder",placeholderText:e,readOnly:!l,setText:d,text:t,textClassName:"kg-toggle-content-text"})})]})}l9.propTypes={content:et.string,contentPlaceholder:et.string,focusOnContent:et.func,focusOnHeader:et.func,header:et.string,headerPlaceholder:et.string,isContentFocused:et.bool,isContentVisible:et.bool,isEditing:et.bool,isHeaderFocused:et.bool,setContent:et.func,setHeader:et.func,toggleContent:et.func,toggleRef:et.object};l9.defaultProps={content:"",contentPlaceholder:"Collapsible content",header:"",headerPlaceholder:"Toggle header",isContentFocused:!1,isContentVisible:!1,isEditing:!1,isHeaderFocused:!0};function ykt({nodeKey:t,content:e,header:n}){const[i]=Qt.useLexicalComposerContext(),r=ue.useContext(qa),{isEditing:s}=r,[o,a]=U.useState(!1),[l,u]=U.useState(!1),[d,p]=U.useState(!0),h=U.useRef(null);return U.useEffect(()=>{h&&h.current&&h.current.click()},[]),I(l9,{content:e,contentPlaceholder:"Collapsible content",focusOnContent:T=>{T.key==="Enter"&&(p(!1),u(!0),!o&&h&&h.current&&h.current.click())},focusOnHeader:T=>{u(!1),p(!0)},header:n,headerPlaceholder:"Toggle header",isContentFocused:l,isContentVisible:o,isEditing:s,isHeaderFocused:d,setContent:T=>{i.update(()=>{J.$getNodeByKey(t).setContent(T)})},setHeader:T=>{i.update(()=>{J.$getNodeByKey(t).setHeader(T)})},toggleContent:()=>{a(!o)},toggleRef:h})}class SR extends Tct{getIcon(){return I3}createDOM(){return document.createElement("div")}decorate(){return I(Id,{nodeKey:this.getKey(),width:this.__cardWidth,children:I(ykt,{content:this.__content,header:this.__header,nodeKey:this.getKey()})})}}He(SR,"kgMenu",[{label:"Toggle",desc:"Add collapsible content",Icon:I3,insertCommand:xee,matches:["toggle","collapse"]}]);const Ekt=t=>new SR(t);function bkt(t){return new Promise((e,n)=>{const i=t.type;let r,s,o;const a=document.createElement("video");a.preload="metadata",a.muted=!0,a.playsInline=!0,a.onerror=n,a.onloadedmetadata=function(){r=a.duration,s=a.videoWidth,o=a.videoHeight,setTimeout(()=>{a.currentTime=.5},200)},a.onseeked=function(){const l=document.createElement("canvas");l.width=s,l.height=o;const u=l.getContext("2d");u.drawImage(a,0,0,s,o),window.URL.revokeObjectURL(a.src),u.canvas.toBlob(d=>{e({duration:r,width:s,height:o,mimeType:i,thumbnailBlob:d})},"image/jpeg",.75)},a.src=URL.createObjectURL(t)})}function Okt({thumbnail:t,customThumbnail:e,onCustomThumbnailChange:n,videoUploader:i={},customThumbnailUploader:r={},onRemoveCustomThumbnail:s,totalDuration:o,cardWidth:a,isLoopChecked:l,onLoopChange:u,onCardWidthChange:d,isEditing:p,thumbnailMimeTypes:h,thumbnailDragHandler:g={}}){var b;const y={width:`${(b=i.progress)==null?void 0:b.toFixed(0)}%`},O=[{label:"Regular",name:"regular",Icon:f6},{label:"Wide",name:"wide",Icon:p6},{label:"Full",name:"full",Icon:d6}];return Ee(qn,{children:[Ee("div",{className:"not-kg-prose relative","data-testid":"video-card-populated",children:[Ee("div",{children:[I("img",{alt:"Video thumbnail",className:"mx-auto",src:t}),e&&I("img",{alt:"Video custom thumbnail",className:"absolute inset-0 h-full w-full bg-white object-cover",src:e})]}),I("div",{className:"absolute inset-0 flex items-center justify-center bg-gradient-to-t from-black/0 via-black/5 to-black/30",children:i.isLoading||I("button",{className:"flex h-20 w-20 items-center justify-center rounded-full bg-black/50",type:"button",children:I(Lle,{className:"h-auto w-5 fill-white"})})}),I("div",{className:`absolute bottom-0 flex h-20 w-full justify-end bg-gradient-to-b from-black/0 to-black/50 ${a==="full"?"px-7 py-4":"px-4"}`,children:I(t9,{duration:o,theme:"light"})})]}),i.isLoading&&I("div",{className:"absolute inset-0 flex min-w-full items-center justify-center overflow-hidden bg-white/50","data-testid":"video-progress",children:I(Lm,{bgStyle:"transparent",style:y})}),!!t&&!i.isLoading&&p&&Ee(uce,{children:[I(LTt,{buttons:O,label:"Video width",selectedName:a,onClick:d}),I(dce,{dataTestID:"loop-video",description:"Autoplay your video on a loop without sound.",isChecked:l,label:"Loop",onChange:u}),!l&&I($Tt,{alt:"Custom thumbnail",dataTestID:"custom-thumbnail-replace",errors:r.errors,icon:"file",isDraggedOver:g.isDraggedOver,isLoading:r.isLoading,label:"Custom thumbnail",mimeTypes:h,placeholderRef:g.setRef,progress:r.progress,size:"xsmall",src:e,onFileChange:n,onRemoveCustomThumbnail:s})]})]})}function wkt({onFileChange:t,fileInputRef:e,errors:n,videoMimeTypes:i=[],videoDragHandler:r={}}){return Ee(qn,{children:[I(aE,{desc:"Click to select a video",errors:n,filePicker:()=>fa({fileInputRef:e}),icon:"video",isDraggedOver:r.isDraggedOver,placeholderRef:r.setRef}),I("form",{onChange:t,children:I("input",{ref:e,accept:i.join(","),hidden:!0,name:"image-input",type:"file"})})]})}const Tkt=({fileInputRef:t,onVideoFileChange:e,videoDragHandler:n,videoUploader:i={},videoUploadErrors:r,videoMimeTypes:s,...o})=>o.customThumbnail||o.thumbnail||i.isLoading?I(Okt,{...o,videoUploader:i}):I(wkt,{errors:r,fileInputRef:t,videoDragHandler:n,videoMimeTypes:s,onFileChange:e});function Nce({caption:t,onCaptionChange:e,isSelected:n,isEditing:i,...r}){return I(qn,{children:Ee("figure",{children:[I(Tkt,{...r,isEditing:i}),I(W6,{caption:t||"",captionPlaceholder:"Type caption for video (optional)",dataTestId:"video-card-caption",isSelected:n,readOnly:!i,setCaption:e})]})})}Nce.propTypes={caption:et.string};function Ckt({nodeKey:t,thumbnail:e,customThumbnail:n,caption:i,totalDuration:r,cardWidth:s,triggerFileDialog:o,isLoopChecked:a,initialFile:l}){var ae;const[u]=Qt.useLexicalComposerContext(),{fileUploader:d}=ue.useContext(Io),p=ue.useContext(qa),h=ue.useRef(),[g,y]=U.useState(""),O=d.useFileUpload("video"),b=d.useFileUpload("mediaThumbnail"),w=d.useFileUpload("image"),T=HS({handleDrop:G}),x=HS({handleDrop:ie}),[R,A]=U.useState([]),L=((ae=d.fileTypes.video)==null?void 0:ae.mimeTypes)||["video/*"];ue.useEffect(()=>{(async be=>{be&&!O.isLoading&&await F([be])})(l)},[]);const F=async pe=>{var Nt,nt;const be=pe[0];if(!be)return;let K,$,_e,Ce;try{({thumbnailBlob:K,duration:$,width:_e,height:Ce}=await bkt(be))}catch{A([{name:be.name,message:`The file type you uploaded is not supported. Please use .${L.join(", .").toUpperCase()}`}])}y(URL.createObjectURL(K));const ke=await O.upload([be]),Ye=(Nt=ke==null?void 0:ke[0])==null?void 0:Nt.url;if(!Ye){y("");return}Ye&&u.update(()=>{const At=J.$getNodeByKey(t);At.setSrc(Ye),At.setDuration($),At.setVideoWidth(_e),At.setVideoHeight(Ce)});const Rt=new File([K],`${be.name}.jpg`,{type:"image/jpeg"}),ct=await b.upload([Rt],{formData:{url:Ye}}),Ct=(nt=ct==null?void 0:ct[0])==null?void 0:nt.url;Ct&&u.update(()=>{J.$getNodeByKey(t).setThumbnailSrc(Ct)}),y("")},q=async pe=>{pe.target.files[0]&&await F(pe.target.files)},H=pe=>{u.update(()=>{J.$getNodeByKey(t).setCaption(pe)})},Z=async pe=>{var $;const be=await w.upload(pe),K=($=be==null?void 0:be[0])==null?void 0:$.url;K&&u.update(()=>{J.$getNodeByKey(t).setCustomThumbnailSrc(K)})},Y=async pe=>{await Z(pe.target.files)};async function G(pe){await F(pe)}async function ie(pe){await Z(pe)}const V=()=>{u.update(()=>{J.$getNodeByKey(t).setCustomThumbnailSrc("")})},z=pe=>{u.update(()=>{J.$getNodeByKey(t).setLoop(pe.target.checked)})},X=pe=>{u.update(()=>{J.$getNodeByKey(t).setCardWidth(pe),p.setCardWidth(pe)})},ne=pe=>{pe.preventDefault(),pe.stopPropagation(),p.setEditing(!0)};ue.useEffect(()=>{if(!o)return;const pe=setTimeout(()=>{fa({fileInputRef:h}),u.update(()=>{J.$getNodeByKey(t).setTriggerFileDialog(!1)})});return()=>{clearTimeout(pe)}});const se=n||e;return Ee(qn,{children:[I(Nce,{caption:i,cardWidth:s,customThumbnail:n,customThumbnailUploader:w,fileInputRef:h,isEditing:p.isEditing,isLoopChecked:a,isSelected:p.isSelected,thumbnail:g||e,thumbnailDragHandler:x,thumbnailMimeTypes:d.fileTypes.image.mimeTypes,totalDuration:r,videoDragHandler:T,videoMimeTypes:L,videoUploader:O,videoUploadErrors:[...b.errors,...R,...O.errors],onCaptionChange:H,onCardWidthChange:X,onCustomThumbnailChange:Y,onLoopChange:z,onRemoveCustomThumbnail:V,onVideoFileChange:q}),I(VS,{"data-kg-card-toolbar":"video",isVisible:se&&p.isSelected&&!p.isEditing,children:Ee(lE,{children:[I(Kr,{dataTestId:"edit-video-card",icon:"edit",isActive:!1,label:"Edit",onClick:ne}),I(V_,{}),I(Kr,{icon:"snippet",isActive:!1,label:"Snippet"})]})})]})}class My extends rct{constructor(n={},i){super(n,i);He(this,"__triggerFileDialog",!1);He(this,"__initialFile",null);const{triggerFileDialog:r,initialFile:s}=n;this.__triggerFileDialog=!n.src&&r,this.__initialFile=s||null}getIcon(){return D3}setTriggerFileDialog(n){const i=this.getWritable();return i.__triggerFileDialog=n}decorate(){return I(Id,{nodeKey:this.getKey(),width:this.getCardWidth(),children:I(Ckt,{caption:this.getCaption(),cardWidth:this.getCardWidth(),customThumbnail:this.getCustomThumbnailSrc(),initialFile:this.__initialFile,isLoopChecked:this.getLoop(),nodeKey:this.getKey(),thumbnail:this.getThumbnailSrc(),totalDuration:this.getFormattedDuration(),triggerFileDialog:this.__triggerFileDialog})})}}He(My,"kgMenu",[{label:"Video",desc:"Upload and play a video file",Icon:D3,insertCommand:q3,insertParams:{triggerFileDialog:!0},matches:["video"]}]),He(My,"uploadType","video");const kkt=t=>new My(t),xkt=[$a.HeadingNode,bo.ListNode,bo.ListItemNode,$a.QuoteNode,Kie,Ov.LinkNode,zx,bE,vm,vR,Iy,My,jx,Zx,SR],Rkt={paragraph:void 0,heading:{h1:void 0,h2:void 0,h3:void 0,h4:void 0,h5:void 0,h6:void 0},quote:void 0,aside:void 0,list:{nested:{listitem:"!list-none"},ol:void 0,ul:void 0,listitem:void 0},link:void 0,text:{bold:void 0,italic:"italic",overflowed:void 0,hashtag:void 0,underline:void 0,strikethrough:void 0,underlinestrikethrough:void 0,code:void 0},code:void 0};var Ace={},vK=Qt,W0=J,pk=U;let Ice=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";var Nkt=Ice?pk.useLayoutEffect:pk.useEffect;let uw={tag:"history-merge"};function Akt(t,e){if(e!==null){if(e===void 0)t.update(()=>{var n=W0.$getRoot();if(n.isEmpty()){let i=W0.$createParagraphNode();n.append(i),n=Ice?document.activeElement:null,(W0.$getSelection()!==null||n!==null&&n===t.getRootElement())&&i.select()}},uw);else if(e!==null)switch(typeof e){case"string":let n=t.parseEditorState(e);t.setEditorState(n,uw);break;case"object":t.setEditorState(e,uw);break;case"function":t.update(()=>{W0.$getRoot().isEmpty()&&e(t)},uw)}}}Ace.LexicalComposer=function({initialConfig:t,children:e}){let n=pk.useMemo(()=>{const{theme:i,namespace:r,editor__DEPRECATED:s,nodes:o,onError:a,editorState:l}=t,u=vK.createLexicalComposerContext(null,i);let d=s||null;if(d===null){const p=W0.createEditor({editable:!1,namespace:r,nodes:o,onError:h=>a(h,p),theme:i});Akt(p,l),d=p}return[d,u]},[]);return Nkt(()=>{let i=t.editable,[r]=n;r.setEditable(i!==void 0?i:!0)},[]),pk.createElement(vK.LexicalComposerContext.Provider,{value:n},e)};const Ikt=Ace;var Dkt=Ikt;function Mkt(t){console.error(t)}const Lkt={namespace:"KoenigEditor",theme:Rkt},Gv=({initialEditorState:t,nodes:e=[...xkt],onError:n=Mkt,fileUploader:i={},cardConfig:r={},darkMode:s=!1,children:o})=>{const[a,l]=ue.useState(null),[u,d]=ue.useState(!1),p=ue.useMemo(()=>Object.assign({},Lkt,{nodes:e,editorState:t,onError:n}),[t,e,n]),h=ue.useRef(null);return i.useFileUpload||(i.useFileUpload=function(){console.error("<KoenigComposer> requires a `fileUploader` prop object to be passed containing a `useFileUpload` custom hook")}),I(Dkt.LexicalComposer,{initialConfig:p,children:I(Io.Provider,{value:{fileUploader:i,editorContainerRef:h,cardConfig:r,darkMode:s,selectedCardKey:a,setSelectedCardKey:l,isEditingCard:u,setIsEditingCard:d},children:o})})},Pkt=()=>{const[t]=Qt.useLexicalComposerContext();return U.useEffect(()=>{if(!t.hasNodes([])){console.error("HorizontalRulePlugin: HorizontalRuleNode not registered");return}return t.registerCommand(Cee,()=>{const e=J.$getSelection();if(!J.$isRangeSelection(e))return!1;if(e.focus.getNode()!==null){const i=Uae(),r=e.focus.getNode();J.$isParagraphNode(r)&&r.getTextContent()!==""&&e.insertParagraph(),e.focus.getNode().getTopLevelElementOrThrow().insertBefore(i)}return!0},J.COMMAND_PRIORITY_EDITOR)},[t]),null},$kt=()=>{const[t]=Qt.useLexicalComposerContext();return ue.useEffect(()=>{if(!t.hasNodes([Zx])){console.error("HtmlPlugin: HtmlNode not registered");return}return Fn.mergeRegister(t.registerCommand(kee,async e=>{const n=wCt(e);return t.dispatchCommand(xp,{cardNode:n,openInEditMode:!0}),!0},J.COMMAND_PRIORITY_LOW))},[t]),null},Fkt=({nodeKey:t,handleModalClose:e})=>{const{cardConfig:n}=ue.useContext(Io),[i]=Qt.useLexicalComposerContext(),r=()=>{t&&i.update(()=>{J.$getNodeByKey(t).remove()}),e(!1)},s=async o=>{i.update(()=>{const a=J.$getNodeByKey(t);a.setSrc(o.src),a.setImgHeight(o.height),a.setImgWidth(o.width),a.setCaption(o.caption),a.setAltText(o.alt);const l=J.$createNodeSelection();l.add(a.getKey()),J.$setSelection(l)}),e(!1)};return I(kce,{unsplashConf:n.unsplash,onClose:r,onImageInsert:s})},Bkt=()=>{const[t]=Qt.useLexicalComposerContext(),{fileUploader:e}=ue.useContext(Io),[n,i]=ue.useState(null),[r,s]=ue.useState(null),[o,a]=ue.useState(!1),l=e.useFileUpload("image"),u=ue.useCallback(async(d,p)=>{if((d==null?void 0:d.length)>0)return await ww(d,p,t,l.upload)},[l.upload,t]);return ue.useEffect(()=>{if(!t.hasNodes([vm])){console.error("ImagePlugin: ImageNode not registered");return}return Fn.mergeRegister(t.registerCommand(UT,async d=>{const p=V6(d);return(d==null?void 0:d.triggerFileSelector)==="unsplash"&&(s(p.getKey()),a(!0),i("unsplash")),t.dispatchCommand(xp,{cardNode:p}),!0},J.COMMAND_PRIORITY_LOW),t.registerCommand(Lk,async d=>d.type==="image"?(t.dispatchCommand(UT,{initialFile:d.file}),!0):!1,J.COMMAND_PRIORITY_HIGH))},[t,e,u]),o&&n?I(Fkt,{handleModalClose:a,nodeKey:r}):null},Ukt=()=>{const[t]=Qt.useLexicalComposerContext();return ue.useEffect(()=>{if(!t.hasNodes([vR])){console.error("MarkdownPlugin: MarkdownNode not registered");return}return Fn.mergeRegister(t.registerCommand(wee,async e=>{const n=pkt(e);return t.dispatchCommand(xp,{cardNode:n,openInEditMode:!0}),!0},J.COMMAND_PRIORITY_HIGH))},[t]),null},Gkt=()=>{const[t]=Qt.useLexicalComposerContext();return ue.useEffect(()=>{if(!t.hasNodes([Iy])){console.error("AudioPlugin: AudioNode not registered");return}return Fn.mergeRegister(t.registerCommand(Y3,async e=>{const n=Nwt(e);return t.dispatchCommand(xp,{cardNode:n}),!0},J.COMMAND_PRIORITY_LOW),t.registerCommand(Lk,async e=>e.type==="audio"?(t.dispatchCommand(Y3,{initialFile:e.file}),!0):!1,J.COMMAND_PRIORITY_HIGH))},[t]),null},Qkt=()=>{const[t]=Qt.useLexicalComposerContext();return ue.useEffect(()=>{if(!t.hasNodes([jx])){console.error("CalloutPlugin: CalloutNode not registered");return}return Fn.mergeRegister(t.registerCommand(Tee,async e=>{const n=GTt(e);return t.dispatchCommand(xp,{cardNode:n}),!0},J.COMMAND_PRIORITY_LOW))}),null},qkt=({label:t,children:e,...n})=>Ee("li",{className:"flex shrink-0 flex-col justify-center text-[1.1rem] font-semibold uppercase tracking-wide text-grey",role:"separator",...n,children:[I("span",{className:"mb-2 block px-4 pt-3",style:{minWidth:"calc(100% - 3.2rem)"},children:t}),I("ul",{role:"menu",children:e})]}),Ykt=({label:t,desc:e,isSelected:n,onClick:i,Icon:r,...s})=>I("li",{role:"presentation",children:Ee("button",{className:`flex w-full cursor-pointer flex-row items-center border border-transparent px-4 py-[1rem] text-left text-grey-800 hover:bg-grey-100 ${n?"bg-grey-100":""}`,"data-kg-card-menu-item":t,"data-kg-cardmenu-selected":n,role:"menuitem",type:"button",onClick:i,onMouseDown:a=>{a.preventDefault()},...s,children:[I("div",{className:"flex items-center",children:I(r,{className:"h-7 w-7"})}),Ee("div",{className:"flex flex-col",children:[I("div",{className:"m-0 ml-4 truncate text-[1.3rem] font-medium leading-[1.6rem] tracking-[.02rem] text-grey-900",children:t}),I("div",{className:"m-0 ml-4 truncate text-xs font-normal leading-[1.6rem] tracking-[.02rem] text-grey",children:e})]})]})}),zkt=({label:t,isSelected:e,Icon:n,...i})=>I("li",{role:"presentation",children:Ee("button",{className:`flex w-full cursor-pointer flex-row items-center border border-transparent px-4 py-[1rem] text-grey-800 hover:bg-grey-100 ${e?"bg-grey-100":""}`,"data-kg-cardmenu-selected":e,role:"menuitem",type:"button",...i,children:[I("div",{className:"flex items-center",children:I(n,{className:"h-7 w-7"})}),I("div",{className:"flex flex-col",children:I("div",{className:"m-0 ml-4 truncate text-[1.3rem] font-medium leading-[1.6rem] tracking-[.02rem] text-grey-900",children:t})})]})}),Dce=({menu:t=new Map,insert:e=()=>{},selectedItemIndex:n})=>{const i=[];let r=0;for(const[s,o]of t){const a=[];o.forEach(l=>{const u=r===n,d=p=>{p.preventDefault(),p.stopPropagation(),e==null||e(l.insertCommand,{insertParams:l.insertParams,queryParams:l.queryParams})};!l.type||l.type==="card"?a.push(I(Ykt,{"data-kg-cardmenu-idx":r,desc:l.desc,Icon:l.Icon,isSelected:u,label:l.label,onClick:d},r)):l.type==="snippet"&&a.push(I(zkt,{"data-kg-cardmenu-idx":r,Icon:l.Icon,isSelected:u,label:l.label,onClick:d},r)),r=r+1}),i.push(I(qkt,{label:s,children:a},s))}return I("ul",{className:"not-kg-prose z-[9999999] m-0 mb-3 max-h-[376px] w-[312px] flex-col overflow-y-auto rounded-md bg-white bg-clip-padding p-0 font-sans text-sm shadow-md after:block after:pb-4",role:"menu",children:i})};function Wkt({onClick:t}){return I("div",{className:"absolute top-[-2px] left-[-66px]","data-kg-plus-button":!0,children:I("button",{"aria-label":"Add a card",className:"group relative flex h-7 w-7 cursor-pointer items-center justify-center rounded-full border border-grey transition-all ease-linear hover:border-grey-900 dark:border-grey-800 dark:hover:border-grey-100 md:h-9 md:w-9",type:"button",onClick:t,children:I(wJ,{className:"h-4 w-4 stroke-grey-800 stroke-2 group-hover:stroke-grey-500 dark:stroke-grey-500 dark:group-hover:stroke-grey-100"})})})}function Hkt({children:t}){return I("div",{className:"absolute left-[-16px]","data-kg-plus-menu":!0,children:t})}function Mce(t,{query:e}={}){const n=new Map;e=e==null?void 0:e.toLowerCase();let i=-1;function r(s){if(e&&(!s.matches||!s.matches.find(a=>a.startsWith(e))))return;const o=s.section||"Primary";n.has(o)?n.get(o).push(s):n.set(o,[s]),i=i+1}for(const[s,o]of t)Array.isArray(o.kgMenu)?o.kgMenu.forEach(a=>r({nodeType:s,...a})):r({nodeType:s,...o.kgMenu});return{menu:n,maxItemIndex:i}}function Vkt(t){var Z;const[e,n]=ue.useState(!1),[i,r]=ue.useState(!1),[s,o]=ue.useState(0),[a,l]=ue.useState(null),[u,d]=ue.useState({}),p=ue.useRef(null);function h(Y){const G=Y.getBoundingClientRect(),ie=Y.parentNode.getBoundingClientRect();return G.top-ie.top}function g(Y){const G=new Range;return G.setStart(Y,0),G.setEnd(Y,0),G}const y=ue.useCallback(()=>{a&&(document.getSelection().removeAllRanges(),document.getSelection().addRange(a))},[a]),O=ue.useCallback(Y=>{const G=g(Y);l(G),n(!0)},[n,l]),b=ue.useCallback(()=>{n(!1),r(!1),l(null)},[n,r,l]),w=ue.useCallback(Y=>{Y==null||Y.preventDefault(),t.update(()=>{J.$setSelection(null)},{discrete:!0}),y(),r(!0)},[t,y,r]),T=ue.useCallback(({resetCursor:Y=!1}={})=>{Y&&y(),r(!1)},[y,r]),x=ue.useCallback(()=>{t.getEditorState().read(()=>{if(t.isComposing())return;const Y=J.$getSelection();if(!J.$isRangeSelection(Y)||!Y.type==="text"||!Y.isCollapsed()){b();return}const G=bC(Y);if(!J.$isParagraphNode(G)||G.getTextContent()!==""){b();return}const V=window.getSelection().anchorNode,z=t.getRootElement();if((V==null?void 0:V.tagName)!=="P"||!z.contains(V)){b();return}o(h(V)),O(V)})},[t,O,b]),R=ue.useCallback((Y,{insertParams:G={}}={})=>{const ie={...G};t.dispatchCommand(Y,ie),T()},[t,T]);ue.useEffect(()=>t.registerUpdateListener(()=>{x()},[t,x]));const A=ue.useCallback(()=>{var Y;if(e){const G=window.getSelection();if(i&&((Y=p.current)!=null&&Y.contains(G.anchorNode)))return;t.getRootElement().contains(G.anchorNode)||b()}},[t,e,i,b]);ue.useEffect(()=>(document.addEventListener("selectionchange",A),()=>{document.removeEventListener("selectionchange",A)}),[A]);const L=ue.useCallback(Y=>{if(i)return;const G=t.getRootElement();let{pageX:ie,pageY:V}=Y,z=G.getBoundingClientRect();ie<z.left&&(ie=ie+40);const X=document.elementFromPoint(ie,V);G.contains(X)&&((X==null?void 0:X.tagName)==="P"&&X.textContent===""?(o(h(X)),O(X)):x())},[t,i,o,O,x]);ue.useEffect(()=>(window.addEventListener("mousemove",L),()=>{window.removeEventListener("mousemove",L)}),[L]);const F=ue.useCallback(Y=>{var G;if(i&&!((G=p.current)!=null&&G.contains(Y.target)))return T()},[i,T]);ue.useEffect(()=>(window.addEventListener("mousedown",F),()=>{window.removeEventListener("mousedown",F)}),[F]);const q=ue.useCallback(Y=>{if(i){if(Y.key==="Escape"){T({resetCursor:!0});return}["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(Y.key)&&T()}},[i,T]);ue.useEffect(()=>(window.addEventListener("keydown",q),()=>{window.removeEventListener("keydown",q)})),ue.useEffect(()=>{const Y=S6(t);d(Mce(Y))},[t,d]);const H={top:`${s}px`};return((Z=u.menu)==null?void 0:Z.size)===0?null:e?Ee("div",{ref:p,className:"absolute",style:H,"data-kg-plus-container":!0,children:[e&&I(Wkt,{onClick:w}),i&&I(Hkt,{children:I(Dce,{insert:R,menu:u.menu})})]}):null}function Xkt(){const[t]=Qt.useLexicalComposerContext();return Vkt(t)}function Kkt({children:t}){return I("div",{"data-kg-slash-menu":!0,children:t})}function jkt(t){var R;const[e,n]=ue.useState(!1),[i,r]=ue.useState(0),[s,o]=ue.useState(""),[a,l]=ue.useState([]),[u,d]=ue.useState({}),[p,h]=ue.useState(0),g=ue.useRef(null),y=ue.useRef(null);function O(A){const L=A.getBoundingClientRect(),F=A.parentNode.getBoundingClientRect();return L.bottom-F.top}function b(){g.current&&(document.getSelection().removeAllRanges(),document.getSelection().addRange(g.current))}const w=ue.useCallback(()=>{n(!0)},[n]),T=ue.useCallback(({resetCursor:A=!1}={})=>{A&&b(),n(!1),o(""),l([]),g.current=null},[n]),x=ue.useCallback((A,{insertParams:L={},queryParams:F={}}={})=>{const q={...L};for(let H=0;H<F.length;H++)if(a[H]){const Z=F[H],Y=a[H];q[Z]=Y}t.update(()=>{const H=J.$getSelection();H.modify("extend",!0,"lineboundary"),H.deleteCharacter(!0),t.dispatchCommand(A,q)}),T()},[t,a,T]);return ue.useEffect(()=>t.registerUpdateListener(()=>{t.getEditorState().read(()=>{if(t.isComposing())return;const A=J.$getSelection();if(!J.$isRangeSelection(A)||!A.type==="text"||!A.isCollapsed()){T();return}const L=bC(A).getTopLevelElement();if(!L||!J.$isParagraphNode(L)||!L.getTextContent().startsWith("/")){T();return}const F=window.getSelection(),q=F.anchorNode,H=t.getRootElement();if((q==null?void 0:q.nodeType)!==Node.TEXT_NODE||!H.contains(q)){T();return}g.current=F.getRangeAt(0);const Z=L.getTextContent().slice(1),[Y,...G]=Z.split(" ");o(Y),l(G)})}),[t,T,o,l]),ue.useEffect(()=>{if(e)return;const A=L=>{const{key:F,isComposing:q,ctrlKey:H,metaKey:Z}=L;F!=="/"||q||H||Z||!t.getRootElement().matches(":focus")||t.getEditorState().read(()=>{const G=J.$getSelection(),ie=bC(G).getTopLevelElement();if(!ie||!J.$isParagraphNode(ie))return;const V=ie.getTextContentSize(),z=G.isCollapsed()&&ie.getTextContent()==="",X=!G.isCollapsed()&&(G.anchor.offset===0&&G.focus.offset===V||G.anchor.offset===V&&G.focus.offset===0);if(z||X){const ne=window.getSelection();let se;ne.anchorNode.nodeType===Node.TEXT_NODE?se=ne.anchorNode.parentNode.closest("p"):se=ne.anchorNode,r(O(se)),w()}})};return window.addEventListener("keypress",A),()=>{window.removeEventListener("keypress",A)}},[t,e,r,w]),ue.useEffect(()=>{if(!e)return;const A=L=>{if(L.key==="Escape"){T({resetCursor:!0});return}};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[e,T]),ue.useEffect(()=>{if(!e)return;const A=L=>{var F;(F=y.current)!=null&&F.contains(L.target)||T()};return window.addEventListener("mousedown",A),()=>{window.removeEventListener("mousedown",A)}},[e,T]),ue.useEffect(()=>{if(!e)return;const A=q=>(h(p===0?u.maxItemIndex:p-1),q.preventDefault(),!0),L=q=>(p===u.maxItemIndex?h(0):h(p+1),q.preventDefault(),!0),F=q=>{var H;return(H=document.querySelector(`[data-kg-slash-menu] [data-kg-cardmenu-idx="${p}"]`))==null||H.click(),q.preventDefault(),!0};return Fn.mergeRegister(t.registerCommand(J.KEY_ARROW_DOWN_COMMAND,L,J.COMMAND_PRIORITY_HIGH),t.registerCommand(J.KEY_ARROW_UP_COMMAND,A,J.COMMAND_PRIORITY_HIGH),t.registerCommand(J.KEY_ARROW_RIGHT_COMMAND,L,J.COMMAND_PRIORITY_HIGH),t.registerCommand(J.KEY_ARROW_LEFT_COMMAND,A,J.COMMAND_PRIORITY_HIGH),t.registerCommand(J.KEY_ENTER_COMMAND,F,J.COMMAND_PRIORITY_HIGH))},[t,e,u,p]),ue.useEffect(()=>{const A=S6(t);d(Mce(A,{insert:x,query:s})),h(0)},[t,s,x,d,h]),((R=u.menu)==null?void 0:R.size)===0?null:e?I("div",{ref:y,className:"absolute -left-2 mt-2",style:{top:`${i}px`},"data-kg-slash-container":!0,children:I(Kkt,{children:I(Dce,{insert:x,menu:u.menu,selectedItemIndex:p})})}):null}function Zkt(){const[t]=Qt.useLexicalComposerContext();return jkt(t)}const Jkt=()=>Ee(qn,{children:[I(Xkt,{}),I(Zkt,{})]});var Lce={},Ju=bo,ext=Qt,Pce=U,txt=Fn,k0=J;function nxt(t){Pce.useEffect(()=>txt.mergeRegister(t.registerCommand(Ju.INSERT_ORDERED_LIST_COMMAND,()=>(Ju.insertList(t,"number"),!0),k0.COMMAND_PRIORITY_LOW),t.registerCommand(Ju.INSERT_UNORDERED_LIST_COMMAND,()=>(Ju.insertList(t,"bullet"),!0),k0.COMMAND_PRIORITY_LOW),t.registerCommand(Ju.REMOVE_LIST_COMMAND,()=>(Ju.removeList(t),!0),k0.COMMAND_PRIORITY_LOW),t.registerCommand(k0.INSERT_PARAGRAPH_COMMAND,()=>!!Ju.$handleListInsertParagraph(),k0.COMMAND_PRIORITY_LOW)),[t])}Lce.ListPlugin=function(){let[t]=ext.useLexicalComposerContext();return Pce.useEffect(()=>{if(!t.hasNodes([Ju.ListNode,Ju.ListItemNode]))throw Error("ListPlugin: ListNode and/or ListItemNode not registered on editor")},[t]),nxt(t),null};const ixt=Lce;var rxt=ixt,$ce={},sxt=Qt,Xg=J,oxt=U;$ce.TabIndentationPlugin=function(){let[t]=sxt.useLexicalComposerContext();return oxt.useEffect(()=>t.registerCommand(Xg.KEY_TAB_COMMAND,e=>{let n=Xg.$getSelection();return Xg.$isRangeSelection(n)?(e.preventDefault(),t.dispatchCommand(e.shiftKey?Xg.OUTDENT_CONTENT_COMMAND:Xg.INDENT_CONTENT_COMMAND,void 0)):!1},Xg.COMMAND_PRIORITY_EDITOR)),null};const axt=$ce;var lxt=axt;const cxt=()=>{const[t]=Qt.useLexicalComposerContext();return ue.useEffect(()=>{if(!t.hasNodes([SR])){console.error("TogglePlugin: ToggleNode not registered");return}return Fn.mergeRegister(t.registerCommand(xee,async e=>{const n=Ekt(e);return t.dispatchCommand(xp,{cardNode:n,openInEditMode:!0}),!0},J.COMMAND_PRIORITY_LOW))},[t]),null},uxt=()=>{const[t]=Qt.useLexicalComposerContext();return ue.useEffect(()=>{if(!t.hasNodes([My])){console.error("VideoPlugin: VideoNode not registered");return}return Fn.mergeRegister(t.registerCommand(q3,async e=>{const n=kkt(e);return t.dispatchCommand(xp,{cardNode:n}),!0},J.COMMAND_PRIORITY_LOW),t.registerCommand(Lk,async e=>e.type==="video"?(t.dispatchCommand(q3,{initialFile:e.file}),!0):!1,J.COMMAND_PRIORITY_HIGH))},[t]),null},dxt=()=>Ee(qn,{children:[I(rxt.ListPlugin,{})," ",I(lxt.TabIndentationPlugin,{})," ",I(Jkt,{}),I(Gkt,{}),I(Bkt,{}),I(uxt,{}),I(Ukt,{}),I(Pkt,{}),I(Qkt,{}),I($kt,{}),I(cxt,{})]}),fxt=({children:t,...e})=>Ee(yp,{...e,children:[I(dxt,{}),t]}),yR=({html:t="",setHtml:e})=>{const[n]=Qt.useLexicalComposerContext(),i=ue.useRef(!0);ue.useLayoutEffect(()=>{i.current&&(i.current=!1,t&&n.update(()=>{const o=new DOMParser().parseFromString(t,"text/html"),a=M3.$generateNodesFromDOM(n,o);let l=!0;if(a.forEach(u=>{u.getTextContent().trim()&&(l=!1)}),J.$getRoot().select(),l){J.$getRoot().clear();return}J.$insertNodes(a)}))},[]);const r=ue.useCallback(()=>{n.update(()=>{const s=M3.$generateHtmlFromNodes(n,null);e==null||e(s)})},[n,e]);return I(s6.OnChangePlugin,{onChange:r})},TE=({paragraphs:t})=>{const[e]=Qt.useLexicalComposerContext();return ue.useEffect(()=>Fn.mergeRegister(e.registerNodeTransform(J.RootNode,n=>{const i=J.$getSelection();if(!J.$isRangeSelection(i)||!i.isCollapsed())return;const r=n.getChildren();if(!(r.length<=t&&r.every(J.$isParagraphNode))){let o=r.filter(a=>!J.$isDecoratorNode(a));o=o.slice(0,t),o=o.map(a=>{if(bo.$isListNode(a)){const l=a.getChildren()[0];return J.$createParagraphNode().append(...l.getChildren())}else return J.$isParagraphNode(a)?a:J.$createParagraphNode().append(...a.getChildren())}),r.forEach(a=>a.remove()),o.forEach(a=>n.append(a)),n.selectEnd()}})),[e,t]),null},Fce=[bo.ListNode,bo.ListItemNode,Ov.LinkNode],c9=[Ov.LinkNode];var Bce={},u9={},Uce=U;let SK=[["Cat","rgb(125, 50, 0)"],["Dog","rgb(100, 0, 0)"],["Rabbit","rgb(150, 0, 0)"],["Frog","rgb(200, 0, 0)"],["Fox","rgb(200, 75, 0)"],["Hedgehog","rgb(0, 75, 0)"],["Pigeon","rgb(0, 125, 0)"],["Squirrel","rgb(75, 100, 0)"],["Bear","rgb(125, 100, 0)"],["Tiger","rgb(0, 0, 150)"],["Leopard","rgb(0, 0, 200)"],["Zebra","rgb(0, 0, 250)"],["Wolf","rgb(0, 100, 150)"],["Owl","rgb(0, 100, 100)"],["Gull","rgb(100, 0, 100)"],["Squid","rgb(150, 0, 150)"]],yK=SK[Math.floor(Math.random()*SK.length)],Gce=Uce.createContext({clientID:0,color:yK[1],isCollabActive:!1,name:yK[0],yjsDocMap:new Map});u9.CollaborationContext=Gce;u9.useCollaborationContext=function(t,e){let n=Uce.useContext(Gce);return t!=null&&(n.name=t),e!=null&&(n.color=e),n};const pxt=u9;var hxt=pxt,gu={};const Bl=()=>new Map,_$=t=>{const e=Bl();return t.forEach((n,i)=>{e.set(i,n)}),e},Md=(t,e,n)=>{let i=t.get(e);return i===void 0&&t.set(e,i=n()),i},mxt=(t,e)=>{const n=[];for(const[i,r]of t)n.push(e(r,i));return n},gxt=(t,e)=>{for(const[n,i]of t)if(e(i,n))return!0;return!1},xm=()=>new Set,BL=t=>t[t.length-1],_xt=(t,e)=>{for(let n=0;n<e.length;n++)t.push(e[n])},Ep=Array.from,EK=Array.isArray;class CE{constructor(){this._observers=Bl()}on(e,n){Md(this._observers,e,xm).add(n)}once(e,n){const i=(...r)=>{this.off(e,i),n(...r)};this.on(e,i)}off(e,n){const i=this._observers.get(e);i!==void 0&&(i.delete(n),i.size===0&&this._observers.delete(e))}emit(e,n){return Ep((this._observers.get(e)||Bl()).values()).forEach(i=>i(...n))}destroy(){this._observers=Bl()}}class vxt extends CE{constructor(e,n){super(),this.doc=e,this.awareness=n}}const Cd=Math.floor,dT=Math.abs,d9=(t,e)=>t<e?t:e,Um=(t,e)=>t>e?t:e,Sxt=Math.pow,Qce=t=>t!==0?t<0:1/t<0,yxt=String.fromCharCode,Ext=t=>t.toLowerCase(),bxt=/^\s*/g,Oxt=t=>t.replace(bxt,""),wxt=/([A-Z])/g,bK=(t,e)=>Oxt(t.replace(wxt,n=>`${e}${Ext(n)}`)),Txt=t=>{const e=unescape(encodeURIComponent(t)),n=e.length,i=new Uint8Array(n);for(let r=0;r<n;r++)i[r]=e.codePointAt(r);return i},Ly=typeof TextEncoder<"u"?new TextEncoder:null,Cxt=t=>Ly.encode(t),kxt=Ly?Cxt:Txt;let xS=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});xS&&xS.decode(new Uint8Array).length===1&&(xS=null);const OK=t=>t===void 0?null:t;class xxt{constructor(){this.map=new Map}setItem(e,n){this.map.set(e,n)}getItem(e){return this.map.get(e)}}let qce=new xxt,Yce=!0;try{typeof localStorage<"u"&&(qce=localStorage,Yce=!1)}catch{}const zce=qce,Rxt=t=>Yce||addEventListener("storage",t),Nxt=Object.keys,Axt=(t,e)=>{const n=[];for(const i in t)n.push(e(t[i],i));return n},hk=t=>Nxt(t).length,Ixt=(t,e)=>{for(const n in t)if(!e(t[n],n))return!1;return!0},Wce=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Dxt=(t,e)=>t===e||hk(t)===hk(e)&&Ixt(t,(n,i)=>(n!==void 0||Wce(e,i))&&e[i]===n),f9=(t,e,n=0)=>{try{for(;n<t.length;n++)t[n](...e)}finally{n<t.length&&f9(t,e,n+1)}},Mxt=(t,e)=>t===e,RS=(t,e)=>{if(t==null||e==null)return Mxt(t,e);if(t.constructor!==e.constructor)return!1;if(t===e)return!0;switch(t.constructor){case ArrayBuffer:t=new Uint8Array(t),e=new Uint8Array(e);case Uint8Array:{if(t.byteLength!==e.byteLength)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;break}case Set:{if(t.size!==e.size)return!1;for(const n of t)if(!e.has(n))return!1;break}case Map:{if(t.size!==e.size)return!1;for(const n of t.keys())if(!e.has(n)||!RS(t.get(n),e.get(n)))return!1;break}case Object:if(hk(t)!==hk(e))return!1;for(const n in t)if(!Wce(t,n)||!RS(t[n],e[n]))return!1;break;case Array:if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!RS(t[n],e[n]))return!1;break;default:return!1}return!0},Lxt=(t,e)=>e.includes(t),Rm=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name),Hce=typeof window<"u"&&typeof document<"u"&&!Rm;let kc;const Pxt=()=>{if(kc===void 0)if(Rm){kc=Bl();const t=process.argv;let e=null;for(let n=0;n<t.length;n++){const i=t[n];i[0]==="-"?(e!==null&&kc.set(e,""),e=i):e!==null&&(kc.set(e,i),e=null)}e!==null&&kc.set(e,"")}else typeof location=="object"?(kc=Bl(),(location.search||"?").slice(1).split("&").forEach(t=>{if(t.length!==0){const[e,n]=t.split("=");kc.set(`--${bK(e,"-")}`,n),kc.set(`-${bK(e,"-")}`,n)}})):kc=Bl();return kc},v$=t=>Pxt().has(t),S$=t=>OK(Rm?process.env[t.toUpperCase()]:zce.getItem(t)),$xt=t=>v$("--"+t)||S$(t)!==null;$xt("production");const wK=Rm&&Lxt({}.FORCE_COLOR,["true","1","2"]),Fxt=!v$("no-colors")&&(!Rm||process.stdout.isTTY||wK)&&(!Rm||v$("color")||wK||S$("COLORTERM")!==null||(S$("TERM")||"").includes("color")),TK=1,CK=2,UL=4,GL=8,Py=32,hd=64,ca=128,ER=31,y$=63,cm=127,Bxt=2147483647,Vce=Number.MAX_SAFE_INTEGER,Uxt=Number.isInteger||(t=>typeof t=="number"&&isFinite(t)&&Cd(t)===t),Qv=t=>new Error(t),Jc=()=>{throw Qv("Method unimplemented")},Ka=()=>{throw Qv("Unexpected case")},Xce=Qv("Unexpected end of array"),Kce=Qv("Integer out of Range");class bR{constructor(e){this.arr=e,this.pos=0}}const ls=t=>new bR(t),jce=t=>t.pos!==t.arr.length,Gxt=(t,e)=>{const n=h9(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,n},gs=t=>Gxt(t,Gt(t)),_v=t=>t.arr[t.pos++],Gt=t=>{let e=0,n=1;const i=t.arr.length;for(;t.pos<i;){const r=t.arr[t.pos++];if(e=e+(r&cm)*n,n*=128,r<ca)return e;if(e>Vce)throw Kce}throw Xce},OR=t=>{let e=t.arr[t.pos++],n=e&y$,i=64;const r=(e&hd)>0?-1:1;if(!(e&ca))return r*n;const s=t.arr.length;for(;t.pos<s;){if(e=t.arr[t.pos++],n=n+(e&cm)*i,i*=128,e<ca)return r*n;if(n>Vce)throw Kce}throw Xce},Qxt=t=>{let e=Gt(t);if(e===0)return"";{let n=String.fromCodePoint(_v(t));if(--e<100)for(;e--;)n+=String.fromCodePoint(_v(t));else for(;e>0;){const i=e<1e4?e:1e4,r=t.arr.subarray(t.pos,t.pos+i);t.pos+=i,n+=String.fromCodePoint.apply(null,r),e-=i}return decodeURIComponent(escape(n))}},qxt=t=>xS.decode(gs(t)),md=xS?qxt:Qxt,p9=(t,e)=>{const n=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,e);return t.pos+=e,n},Yxt=t=>p9(t,4).getFloat32(0,!1),zxt=t=>p9(t,8).getFloat64(0,!1),Wxt=t=>p9(t,8).getBigInt64(0,!1),Hxt=[t=>{},t=>null,OR,Yxt,zxt,Wxt,t=>!1,t=>!0,md,t=>{const e=Gt(t),n={};for(let i=0;i<e;i++){const r=md(t);n[r]=$y(t)}return n},t=>{const e=Gt(t),n=[];for(let i=0;i<e;i++)n.push($y(t));return n},gs],$y=t=>Hxt[127-_v(t)](t);class kK extends bR{constructor(e,n){super(e),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),jce(this)?this.count=Gt(this)+1:this.count=-1),this.count--,this.s}}class fT extends bR{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=OR(this);const e=Qce(this.s);this.count=1,e&&(this.s=-this.s,this.count=Gt(this)+2)}return this.count--,this.s}}class QL extends bR{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const e=OR(this),n=e&1;this.diff=Cd(e/2),this.count=1,n&&(this.count=Gt(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Vxt{constructor(e){this.decoder=new fT(e),this.str=md(this.decoder),this.spos=0}read(){const e=this.spos+this.decoder.read(),n=this.str.slice(this.spos,e);return this.spos=e,n}}const Zce=t=>new Uint8Array(t),h9=(t,e,n)=>new Uint8Array(t,e,n),Xxt=t=>new Uint8Array(t),Kxt=t=>{let e="";for(let n=0;n<t.byteLength;n++)e+=yxt(t[n]);return btoa(e)},jxt=t=>Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("base64"),Zxt=t=>{const e=atob(t),n=Zce(e.length);for(let i=0;i<e.length;i++)n[i]=e.charCodeAt(i);return n},Jxt=t=>{const e=Buffer.from(t,"base64");return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)},eRt=Hce?Kxt:jxt,tRt=Hce?Zxt:Jxt,nRt=t=>{const e=Zce(t.byteLength);return e.set(t),e};class kE{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Dr=()=>new kE,m9=t=>{let e=t.cpos;for(let n=0;n<t.bufs.length;n++)e+=t.bufs[n].length;return e},fi=t=>{const e=new Uint8Array(m9(t));let n=0;for(let i=0;i<t.bufs.length;i++){const r=t.bufs[i];e.set(r,n),n+=r.length}return e.set(h9(t.cbuf.buffer,0,t.cpos),n),e},iRt=(t,e)=>{const n=t.cbuf.length;n-t.cpos<e&&(t.bufs.push(h9(t.cbuf.buffer,0,t.cpos)),t.cbuf=new Uint8Array(Um(n,e)*2),t.cpos=0)},Nr=(t,e)=>{const n=t.cbuf.length;t.cpos===n&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(n*2),t.cpos=0),t.cbuf[t.cpos++]=e},Fy=Nr,lt=(t,e)=>{for(;e>cm;)Nr(t,ca|cm&e),e=Cd(e/128);Nr(t,cm&e)},wR=(t,e)=>{const n=Qce(e);for(n&&(e=-e),Nr(t,(e>y$?ca:0)|(n?hd:0)|y$&e),e=Cd(e/64);e>0;)Nr(t,(e>cm?ca:0)|cm&e),e=Cd(e/128)},E$=new Uint8Array(3e4),rRt=E$.length/3,sRt=(t,e)=>{if(e.length<rRt){const n=Ly.encodeInto(e,E$).written||0;lt(t,n);for(let i=0;i<n;i++)Nr(t,E$[i])}else Ji(t,kxt(e))},oRt=(t,e)=>{const n=unescape(encodeURIComponent(e)),i=n.length;lt(t,i);for(let r=0;r<i;r++)Nr(t,n.codePointAt(r))},lp=Ly&&Ly.encodeInto?sRt:oRt,aRt=(t,e)=>xE(t,fi(e)),xE=(t,e)=>{const n=t.cbuf.length,i=t.cpos,r=d9(n-i,e.length),s=e.length-r;t.cbuf.set(e.subarray(0,r),i),t.cpos+=r,s>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(Um(n*2,s)),t.cbuf.set(e.subarray(r)),t.cpos=s)},Ji=(t,e)=>{lt(t,e.byteLength),xE(t,e)},g9=(t,e)=>{iRt(t,e);const n=new DataView(t.cbuf.buffer,t.cpos,e);return t.cpos+=e,n},lRt=(t,e)=>g9(t,4).setFloat32(0,e,!1),cRt=(t,e)=>g9(t,8).setFloat64(0,e,!1),uRt=(t,e)=>g9(t,8).setBigInt64(0,e,!1),xK=new DataView(new ArrayBuffer(4)),dRt=t=>(xK.setFloat32(0,t),xK.getFloat32(0)===t),By=(t,e)=>{switch(typeof e){case"string":Nr(t,119),lp(t,e);break;case"number":Uxt(e)&&dT(e)<=Bxt?(Nr(t,125),wR(t,e)):dRt(e)?(Nr(t,124),lRt(t,e)):(Nr(t,123),cRt(t,e));break;case"bigint":Nr(t,122),uRt(t,e);break;case"object":if(e===null)Nr(t,126);else if(e instanceof Array){Nr(t,117),lt(t,e.length);for(let n=0;n<e.length;n++)By(t,e[n])}else if(e instanceof Uint8Array)Nr(t,116),Ji(t,e);else{Nr(t,118);const n=Object.keys(e);lt(t,n.length);for(let i=0;i<n.length;i++){const r=n[i];lp(t,r),By(t,e[r])}}break;case"boolean":Nr(t,e?120:121);break;default:Nr(t,127)}};class RK extends kE{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&<(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const NK=t=>{t.count>0&&(wR(t.encoder,t.count===1?t.s:-t.s),t.count>1&<(t.encoder,t.count-2))};class pT{constructor(){this.encoder=new kE,this.s=0,this.count=0}write(e){this.s===e?this.count++:(NK(this),this.count=1,this.s=e)}toUint8Array(){return NK(this),fi(this.encoder)}}const AK=t=>{if(t.count>0){const e=t.diff*2+(t.count===1?0:1);wR(t.encoder,e),t.count>1&<(t.encoder,t.count-2)}};class qL{constructor(){this.encoder=new kE,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(AK(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return AK(this),fi(this.encoder)}}class fRt{constructor(){this.sarr=[],this.s="",this.lensE=new pT}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new kE;return this.sarr.push(this.s),this.s="",lp(e,this.sarr.join("")),xE(e,this.lensE.toUint8Array()),fi(e)}}class _9{constructor(e,n){this.clock=e,this.len=n}}class qv{constructor(){this.clients=new Map}}const bp=(t,e,n)=>e.clients.forEach((i,r)=>{const s=t.doc.store.clients.get(r);for(let o=0;o<i.length;o++){const a=i[o];pue(t,s,a.clock,a.len,n)}}),pRt=(t,e)=>{let n=0,i=t.length-1;for(;n<=i;){const r=Cd((n+i)/2),s=t[r],o=s.clock;if(o<=e){if(e<o+s.len)return r;n=r+1}else i=r-1}return null},Yv=(t,e)=>{const n=t.clients.get(e.client);return n!==void 0&&pRt(n,e.clock)!==null},v9=t=>{t.clients.forEach(e=>{e.sort((r,s)=>r.clock-s.clock);let n,i;for(n=1,i=1;n<e.length;n++){const r=e[i-1],s=e[n];r.clock+r.len>=s.clock?r.len=Um(r.len,s.clock+s.len-r.clock):(i<n&&(e[i]=s),i++)}e.length=i})},Uy=t=>{const e=new qv;for(let n=0;n<t.length;n++)t[n].clients.forEach((i,r)=>{if(!e.clients.has(r)){const s=i.slice();for(let o=n+1;o<t.length;o++)_xt(s,t[o].clients.get(r)||[]);e.clients.set(r,s)}});return v9(e),e},Gy=(t,e,n,i)=>{Md(t.clients,e,()=>[]).push(new _9(n,i))},TR=()=>new qv,S9=t=>{const e=TR();return t.clients.forEach((n,i)=>{const r=[];for(let s=0;s<n.length;s++){const o=n[s];if(o.deleted){const a=o.id.clock;let l=o.length;if(s+1<n.length)for(let u=n[s+1];s+1<n.length&&u.deleted;u=n[++s+1])l+=u.length;r.push(new _9(a,l))}}r.length>0&&e.clients.set(i,r)}),e},nu=(t,e)=>{lt(t.restEncoder,e.clients.size),Ep(e.clients.entries()).sort((n,i)=>i[0]-n[0]).forEach(([n,i])=>{t.resetDsCurVal(),lt(t.restEncoder,n);const r=i.length;lt(t.restEncoder,r);for(let s=0;s<r;s++){const o=i[s];t.writeDsClock(o.clock),t.writeDsLen(o.len)}})},Op=t=>{const e=new qv,n=Gt(t.restDecoder);for(let i=0;i<n;i++){t.resetDsCurVal();const r=Gt(t.restDecoder),s=Gt(t.restDecoder);if(s>0){const o=Md(e.clients,r,()=>[]);for(let a=0;a<s;a++)o.push(new _9(t.readDsClock(),t.readDsLen()))}}return e},IK=(t,e,n)=>{const i=new qv,r=Gt(t.restDecoder);for(let s=0;s<r;s++){t.resetDsCurVal();const o=Gt(t.restDecoder),a=Gt(t.restDecoder),l=n.clients.get(o)||[],u=Pi(n,o);for(let d=0;d<a;d++){const p=t.readDsClock(),h=p+t.readDsLen();if(p<u){u<h&&Gy(i,o,u,h-u);let g=ja(l,p),y=l[g];for(!y.deleted&&y.id.clock<p&&(l.splice(g+1,0,_k(e,y,p-y.id.clock)),g++);g<l.length&&(y=l[g++],y.id.clock<h);)y.deleted||(h<y.id.clock+y.length&&l.splice(g,0,_k(e,y,h-y.id.clock)),y.delete(e))}else Gy(i,o,p,h-p)}}if(i.clients.size>0){const s=new kd;return lt(s.restEncoder,0),nu(s,i),s.toUint8Array()}return null},DK=typeof crypto>"u"?null:crypto,hRt=DK!==null?t=>{const e=new ArrayBuffer(t),n=new Uint8Array(e);return DK.getRandomValues(n),e}:t=>{const e=new ArrayBuffer(t),n=new Uint8Array(e);for(let i=0;i<t;i++)n[i]=Math.ceil(Math.random()*4294967295>>>0);return e},Jce=()=>new Uint32Array(hRt(4))[0],mRt=[1e7]+-1e3+-4e3+-8e3+-1e11,gRt=()=>mRt.replace(/[018]/g,t=>(t^Jce()&15>>t/4).toString(16)),wp=Date.now,MK=t=>new Promise(t),eue=Jce;class Pp extends CE{constructor({guid:e=gRt(),collectionid:n=null,gc:i=!0,gcFilter:r=()=>!0,meta:s=null,autoLoad:o=!1,shouldLoad:a=!0}={}){super(),this.gc=i,this.gcFilter=r,this.clientID=eue(),this.guid=e,this.collectionid=n,this.share=new Map,this.store=new due,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=a,this.autoLoad=o,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.whenLoaded=MK(u=>{this.on("load",()=>{this.isLoaded=!0,u(this)})});const l=()=>MK(u=>{const d=p=>{(p===void 0||p===!0)&&(this.off("sync",d),u())};this.on("sync",d)});this.on("sync",u=>{u===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=u===void 0||u===!0,this.isLoaded||this.emit("load",[])}),this.whenSynced=l()}load(){const e=this._item;e!==null&&!this.shouldLoad&&Wn(e.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Ep(this.subdocs).map(e=>e.guid))}transact(e,n=null){return Wn(this,e,n)}get(e,n=Fr){const i=Md(this.share,e,()=>{const s=new n;return s._integrate(this,null),s}),r=i.constructor;if(n!==Fr&&r!==n)if(r===Fr){const s=new n;s._map=i._map,i._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=s}),s._start=i._start;for(let o=s._start;o!==null;o=o.right)o.parent=s;return s._length=i._length,this.share.set(e,s),s._integrate(this,null),s}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return i}getArray(e=""){return this.get(e,gd)}getText(e=""){return this.get(e,Nm)}getMap(e=""){return this.get(e,Tp)}getXmlFragment(e=""){return this.get(e,Cp)}toJSON(){const e={};return this.share.forEach((n,i)=>{e[i]=n.toJSON()}),e}destroy(){Ep(this.subdocs).forEach(n=>n.destroy());const e=this._item;if(e!==null){this._item=null;const n=e.content;n.doc=new Pp({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=e,Wn(e.parent.doc,i=>{const r=n.doc;e.deleted||i.subdocsAdded.add(r),i.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}on(e,n){super.on(e,n)}off(e,n){super.off(e,n)}}class Qy{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return Gt(this.restDecoder)}readDsLen(){return Gt(this.restDecoder)}}class Ld extends Qy{readLeftID(){return Yt(Gt(this.restDecoder),Gt(this.restDecoder))}readRightID(){return Yt(Gt(this.restDecoder),Gt(this.restDecoder))}readClient(){return Gt(this.restDecoder)}readInfo(){return _v(this.restDecoder)}readString(){return md(this.restDecoder)}readParentInfo(){return Gt(this.restDecoder)===1}readTypeRef(){return Gt(this.restDecoder)}readLen(){return Gt(this.restDecoder)}readAny(){return $y(this.restDecoder)}readBuf(){return nRt(gs(this.restDecoder))}readJSON(){return JSON.parse(md(this.restDecoder))}readKey(){return md(this.restDecoder)}}class tue{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=Gt(this.restDecoder),this.dsCurrVal}readDsLen(){const e=Gt(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class iu extends tue{constructor(e){super(e),this.keys=[],Gt(e),this.keyClockDecoder=new QL(gs(e)),this.clientDecoder=new fT(gs(e)),this.leftClockDecoder=new QL(gs(e)),this.rightClockDecoder=new QL(gs(e)),this.infoDecoder=new kK(gs(e),_v),this.stringDecoder=new Vxt(gs(e)),this.parentInfoDecoder=new kK(gs(e),_v),this.typeRefDecoder=new fT(gs(e)),this.lenDecoder=new fT(gs(e))}readLeftID(){return new um(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new um(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 $y(this.restDecoder)}readBuf(){return gs(this.restDecoder)}readJSON(){return $y(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{const n=this.stringDecoder.read();return this.keys.push(n),n}}}class vv{constructor(){this.restEncoder=Dr()}toUint8Array(){return fi(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){lt(this.restEncoder,e)}writeDsLen(e){lt(this.restEncoder,e)}}class Gm extends vv{writeLeftID(e){lt(this.restEncoder,e.client),lt(this.restEncoder,e.clock)}writeRightID(e){lt(this.restEncoder,e.client),lt(this.restEncoder,e.clock)}writeClient(e){lt(this.restEncoder,e)}writeInfo(e){Fy(this.restEncoder,e)}writeString(e){lp(this.restEncoder,e)}writeParentInfo(e){lt(this.restEncoder,e?1:0)}writeTypeRef(e){lt(this.restEncoder,e)}writeLen(e){lt(this.restEncoder,e)}writeAny(e){By(this.restEncoder,e)}writeBuf(e){Ji(this.restEncoder,e)}writeJSON(e){lp(this.restEncoder,JSON.stringify(e))}writeKey(e){lp(this.restEncoder,e)}}class CR{constructor(){this.restEncoder=Dr(),this.dsCurrVal=0}toUint8Array(){return fi(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const n=e-this.dsCurrVal;this.dsCurrVal=e,lt(this.restEncoder,n)}writeDsLen(e){e===0&&Ka(),lt(this.restEncoder,e-1),this.dsCurrVal+=e}}class kd extends CR{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new qL,this.clientEncoder=new pT,this.leftClockEncoder=new qL,this.rightClockEncoder=new qL,this.infoEncoder=new RK(Fy),this.stringEncoder=new fRt,this.parentInfoEncoder=new RK(Fy),this.typeRefEncoder=new pT,this.lenEncoder=new pT}toUint8Array(){const e=Dr();return lt(e,0),Ji(e,this.keyClockEncoder.toUint8Array()),Ji(e,this.clientEncoder.toUint8Array()),Ji(e,this.leftClockEncoder.toUint8Array()),Ji(e,this.rightClockEncoder.toUint8Array()),Ji(e,fi(this.infoEncoder)),Ji(e,this.stringEncoder.toUint8Array()),Ji(e,fi(this.parentInfoEncoder)),Ji(e,this.typeRefEncoder.toUint8Array()),Ji(e,this.lenEncoder.toUint8Array()),xE(e,fi(this.restEncoder)),fi(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){By(this.restEncoder,e)}writeBuf(e){Ji(this.restEncoder,e)}writeJSON(e){By(this.restEncoder,e)}writeKey(e){const n=this.keyMap.get(e);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(n)}}const _Rt=(t,e,n,i)=>{i=Um(i,e[0].id.clock);const r=ja(e,i);lt(t.restEncoder,e.length-r),t.writeClient(n),lt(t.restEncoder,i);const s=e[r];s.write(t,i-s.id.clock);for(let o=r+1;o<e.length;o++)e[o].write(t,0)},y9=(t,e,n)=>{const i=new Map;n.forEach((r,s)=>{Pi(e,s)>r&&i.set(s,r)}),RE(e).forEach((r,s)=>{n.has(s)||i.set(s,0)}),lt(t.restEncoder,i.size),Ep(i.entries()).sort((r,s)=>s[0]-r[0]).forEach(([r,s])=>{_Rt(t,e.clients.get(r),r,s)})},vRt=(t,e)=>{const n=Bl(),i=Gt(t.restDecoder);for(let r=0;r<i;r++){const s=Gt(t.restDecoder),o=new Array(s),a=t.readClient();let l=Gt(t.restDecoder);n.set(a,{i:0,refs:o});for(let u=0;u<s;u++){const d=t.readInfo();switch(ER&d){case 0:{const p=t.readLen();o[u]=new na(Yt(a,l),p),l+=p;break}case 10:{const p=Gt(t.restDecoder);o[u]=new ia(Yt(a,l),p),l+=p;break}default:{const p=(d&(hd|ca))===0,h=new Hn(Yt(a,l),null,(d&ca)===ca?t.readLeftID():null,null,(d&hd)===hd?t.readRightID():null,p?t.readParentInfo()?e.get(t.readString()):t.readLeftID():null,p&&(d&Py)===Py?t.readString():null,tde(t,d));o[u]=h,l+=h.length}}}}return n},SRt=(t,e,n)=>{const i=[];let r=Ep(n.keys()).sort((g,y)=>g-y);if(r.length===0)return null;const s=()=>{if(r.length===0)return null;let g=n.get(r[r.length-1]);for(;g.refs.length===g.i;)if(r.pop(),r.length>0)g=n.get(r[r.length-1]);else return null;return g};let o=s();if(o===null&&i.length===0)return null;const a=new due,l=new Map,u=(g,y)=>{const O=l.get(g);(O==null||O>y)&&l.set(g,y)};let d=o.refs[o.i++];const p=new Map,h=()=>{for(const g of i){const y=g.id.client,O=n.get(y);O?(O.i--,a.clients.set(y,O.refs.slice(O.i)),n.delete(y),O.i=0,O.refs=[]):a.clients.set(y,[g]),r=r.filter(b=>b!==y)}i.length=0};for(;;){if(d.constructor!==ia){const y=Md(p,d.id.client,()=>Pi(e,d.id.client))-d.id.clock;if(y<0)i.push(d),u(d.id.client,d.id.clock-1),h();else{const O=d.getMissing(t,e);if(O!==null){i.push(d);const b=n.get(O)||{refs:[],i:0};if(b.refs.length===b.i)u(O,Pi(e,O)),h();else{d=b.refs[b.i++];continue}}else(y===0||y<d.length)&&(d.integrate(t,y),p.set(d.id.client,d.id.clock+d.length))}}if(i.length>0)d=i.pop();else if(o!==null&&o.i<o.refs.length)d=o.refs[o.i++];else{if(o=s(),o===null)break;d=o.refs[o.i++]}}if(a.clients.size>0){const g=new kd;return y9(g,a,new Map),lt(g.restEncoder,0),{missing:l,update:g.toUint8Array()}}return null},yRt=(t,e)=>y9(t,e.doc.store,e.beforeState),E9=(t,e,n,i=new iu(t))=>Wn(e,r=>{r.local=!1;let s=!1;const o=r.doc,a=o.store,l=vRt(i,o),u=SRt(r,a,l),d=a.pendingStructs;if(d){for(const[h,g]of d.missing)if(g<Pi(a,h)){s=!0;break}if(u){for(const[h,g]of u.missing){const y=d.missing.get(h);(y==null||y>g)&&d.missing.set(h,g)}d.update=Yy([d.update,u.update])}}else a.pendingStructs=u;const p=IK(i,r,a);if(a.pendingDs){const h=new iu(ls(a.pendingDs));Gt(h.restDecoder);const g=IK(h,r,a);p&&g?a.pendingDs=Yy([p,g]):a.pendingDs=p||g}else a.pendingDs=p;if(s){const h=a.pendingStructs.update;a.pendingStructs=null,kR(r.doc,h)}},n,!1),ERt=(t,e,n)=>E9(t,e,n,new Ld(t)),kR=(t,e,n,i=iu)=>{const r=ls(e);E9(r,t,n,new i(r))},nue=(t,e,n)=>kR(t,e,n,Ld),bRt=(t,e,n=new Map)=>{y9(t,e.store,n),nu(t,S9(e.store))},iue=(t,e=new Uint8Array([0]),n=new kd)=>{const i=b9(e);bRt(n,t,i);const r=[n.toUint8Array()];if(t.store.pendingDs&&r.push(t.store.pendingDs),t.store.pendingStructs&&r.push(I9(t.store.pendingStructs.update,e)),r.length>1){if(n.constructor===Gm)return Cue(r.map((s,o)=>o===0?s:Aue(s)));if(n.constructor===kd)return Yy(r)}return r[0]},rue=(t,e)=>iue(t,e,new Gm),sue=t=>{const e=new Map,n=Gt(t.restDecoder);for(let i=0;i<n;i++){const r=Gt(t.restDecoder),s=Gt(t.restDecoder);e.set(r,s)}return e},b9=t=>sue(new Qy(ls(t))),O9=(t,e)=>(lt(t.restEncoder,e.size),Ep(e.entries()).sort((n,i)=>i[0]-n[0]).forEach(([n,i])=>{lt(t.restEncoder,n),lt(t.restEncoder,i)}),t),ORt=(t,e)=>O9(t,RE(e.store)),wRt=(t,e=new CR)=>(t instanceof Map?O9(e,t):ORt(e,t),e.toUint8Array()),oue=t=>wRt(t,new vv);class TRt{constructor(){this.l=[]}}const LK=()=>new TRt,PK=(t,e)=>t.l.push(e),$K=(t,e)=>{const n=t.l,i=n.length;t.l=n.filter(r=>e!==r),i===t.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},aue=(t,e,n)=>f9(t.l,[e,n]);class um{constructor(e,n){this.client=e,this.clock=n}}const Zh=(t,e)=>t===e||t!==null&&e!==null&&t.client===e.client&&t.clock===e.clock,Yt=(t,e)=>new um(t,e),FK=(t,e)=>{lt(t,e.client),lt(t,e.clock)},BK=t=>Yt(Gt(t),Gt(t)),w9=t=>{for(const[e,n]of t.doc.share.entries())if(n===t)return e;throw Ka()},qy=(t,e)=>{for(;e!==null;){if(e.parent===t)return!0;e=e.parent._item}return!1},CRt=t=>{const e=[];let n=t._start;for(;n;)e.push(n),n=n.right;console.log("Children: ",e),console.log("Children content: ",e.filter(i=>!i.deleted).map(i=>i.content))};class kRt{constructor(e,n=e.getMap("users")){const i=new Map;this.yusers=n,this.doc=e,this.clients=new Map,this.dss=i;const r=(s,o)=>{const a=s.get("ds"),l=s.get("ids"),u=d=>this.clients.set(d,o);a.observe(d=>{d.changes.added.forEach(p=>{p.content.getContent().forEach(h=>{h instanceof Uint8Array&&this.dss.set(o,Uy([this.dss.get(o)||TR(),Op(new Qy(ls(h)))]))})})}),this.dss.set(o,Uy(a.map(d=>Op(new Qy(ls(d)))))),l.observe(d=>d.changes.added.forEach(p=>p.content.getContent().forEach(u))),l.forEach(u)};n.observe(s=>{s.keysChanged.forEach(o=>r(n.get(o),o))}),n.forEach(r)}setUserMapping(e,n,i,{filter:r=()=>!0}={}){const s=this.yusers;let o=s.get(i);o||(o=new Tp,o.set("ids",new gd),o.set("ds",new gd),s.set(i,o)),o.get("ids").push([n]),s.observe(a=>{setTimeout(()=>{const l=s.get(i);if(l!==o){o=l,this.clients.forEach((p,h)=>{i===p&&o.get("ids").push([h])});const u=new vv,d=this.dss.get(i);d&&(nu(u,d),o.get("ds").push([u.toUint8Array()]))}},0)}),e.on("afterTransaction",a=>{setTimeout(()=>{const l=o.get("ds"),u=a.deleteSet;if(a.local&&u.clients.size>0&&r(a,u)){const d=new vv;nu(d,u),l.push([d.toUint8Array()])}})})}getUserByClientId(e){return this.clients.get(e)||null}getUserByDeletedId(e){for(const[n,i]of this.dss.entries())if(Yv(i,e))return n;return null}}class xR{constructor(e,n,i,r=0){this.type=e,this.tname=n,this.item=i,this.assoc=r}}const xRt=t=>{const e={};return t.type&&(e.type=t.type),t.tname&&(e.tname=t.tname),t.item&&(e.item=t.item),t.assoc!=null&&(e.assoc=t.assoc),e},RRt=t=>new xR(t.type==null?null:Yt(t.type.client,t.type.clock),t.tname||null,t.item==null?null:Yt(t.item.client,t.item.clock),t.assoc==null?0:t.assoc);class lue{constructor(e,n,i=0){this.type=e,this.index=n,this.assoc=i}}const NRt=(t,e,n=0)=>new lue(t,e,n),dw=(t,e,n)=>{let i=null,r=null;return t._item===null?r=w9(t):i=Yt(t._item.id.client,t._item.id.clock),new xR(i,r,e,n)},ARt=(t,e,n=0)=>{let i=t._start;if(n<0){if(e===0)return dw(t,null,n);e--}for(;i!==null;){if(!i.deleted&&i.countable){if(i.length>e)return dw(t,Yt(i.id.client,i.id.clock+e),n);e-=i.length}if(i.right===null&&n<0)return dw(t,i.lastId,n);i=i.right}return dw(t,null,n)},IRt=(t,e)=>{const{type:n,tname:i,item:r,assoc:s}=e;if(r!==null)lt(t,0),FK(t,r);else if(i!==null)Fy(t,1),lp(t,i);else if(n!==null)Fy(t,2),FK(t,n);else throw Ka();return wR(t,s),t},DRt=t=>{const e=Dr();return IRt(e,t),fi(e)},MRt=t=>{let e=null,n=null,i=null;switch(Gt(t)){case 0:i=BK(t);break;case 1:n=md(t);break;case 2:e=BK(t)}const r=jce(t)?OR(t):0;return new xR(e,n,i,r)},LRt=t=>MRt(ls(t)),PRt=(t,e)=>{const n=e.store,i=t.item,r=t.type,s=t.tname,o=t.assoc;let a=null,l=0;if(i!==null){if(Pi(n,i.client)<=i.clock)return null;const u=C$(n,i),d=u.item;if(!(d instanceof Hn))return null;if(a=d.parent,a._item===null||!a._item.deleted){l=d.deleted||!d.countable?0:u.diff+(o>=0?0:1);let p=d.left;for(;p!==null;)!p.deleted&&p.countable&&(l+=p.length),p=p.left}}else{if(s!==null)a=e.get(s);else if(r!==null){if(Pi(n,r.client)<=r.clock)return null;const{item:u}=C$(n,r);if(u instanceof Hn&&u.content instanceof Xl)a=u.content.type;else return null}else throw Ka();o>=0?l=a._length:l=0}return NRt(a,l,t.assoc)},$Rt=(t,e)=>t===e||t!==null&&e!==null&&t.tname===e.tname&&Zh(t.item,e.item)&&Zh(t.type,e.type)&&t.assoc===e.assoc;class T9{constructor(e,n){this.ds=e,this.sv=n}}const FRt=(t,e)=>{const n=t.ds.clients,i=e.ds.clients,r=t.sv,s=e.sv;if(r.size!==s.size||n.size!==i.size)return!1;for(const[o,a]of r.entries())if(s.get(o)!==a)return!1;for(const[o,a]of n.entries()){const l=i.get(o)||[];if(a.length!==l.length)return!1;for(let u=0;u<a.length;u++){const d=a[u],p=l[u];if(d.clock!==p.clock||d.len!==p.len)return!1}}return!0},cue=(t,e=new CR)=>(nu(e,t.ds),O9(e,t.sv),e.toUint8Array()),BRt=t=>cue(t,new vv),uue=(t,e=new tue(ls(t)))=>new T9(Op(e),sue(e)),URt=t=>uue(t,new Qy(ls(t))),C9=(t,e)=>new T9(t,e),GRt=C9(TR(),new Map),QRt=t=>C9(S9(t.store),RE(t.store)),Uh=(t,e)=>e===void 0?!t.deleted:e.sv.has(t.id.client)&&(e.sv.get(t.id.client)||0)>t.id.clock&&!Yv(e.ds,t.id),b$=(t,e)=>{const n=Md(t.meta,b$,xm),i=t.doc.store;n.has(e)||(e.sv.forEach((r,s)=>{r<Pi(i,s)&&Gs(t,Yt(s,r))}),bp(t,e.ds,r=>{}),n.add(e))},qRt=(t,e,n=new Pp)=>{if(t.gc)throw new Error("originDoc must not be garbage collected");const{sv:i,ds:r}=e,s=new kd;return t.transact(o=>{let a=0;i.forEach(l=>{l>0&&a++}),lt(s.restEncoder,a);for(const[l,u]of i){if(u===0)continue;u<Pi(t.store,l)&&Gs(o,Yt(l,u));const d=t.store.clients.get(l)||[],p=ja(d,u-1);lt(s.restEncoder,p+1),s.writeClient(l),lt(s.restEncoder,0);for(let h=0;h<=p;h++)d[h].write(s,0)}nu(s,r)}),kR(n,s.toUint8Array(),"snapshot"),n};class due{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const RE=t=>{const e=new Map;return t.clients.forEach((n,i)=>{const r=n[n.length-1];e.set(i,r.id.clock+r.length)}),e},Pi=(t,e)=>{const n=t.clients.get(e);if(n===void 0)return 0;const i=n[n.length-1];return i.id.clock+i.length},fue=(t,e)=>{let n=t.clients.get(e.id.client);if(n===void 0)n=[],t.clients.set(e.id.client,n);else{const i=n[n.length-1];if(i.id.clock+i.length!==e.id.clock)throw Ka()}n.push(e)},ja=(t,e)=>{let n=0,i=t.length-1,r=t[i],s=r.id.clock;if(s===e)return i;let o=Cd(e/(s+r.length-1)*i);for(;n<=i;){if(r=t[o],s=r.id.clock,s<=e){if(e<s+r.length)return o;n=o+1}else i=o-1;o=Cd((n+i)/2)}throw Ka()},YRt=(t,e)=>{const n=t.clients.get(e.client);return n[ja(n,e.clock)]},NS=YRt,O$=(t,e,n)=>{const i=ja(e,n),r=e[i];return r.id.clock<n&&r instanceof Hn?(e.splice(i+1,0,_k(t,r,n-r.id.clock)),i+1):i},Gs=(t,e)=>{const n=t.doc.store.clients.get(e.client);return n[O$(t,n,e.clock)]},UK=(t,e,n)=>{const i=e.clients.get(n.client),r=ja(i,n.clock),s=i[r];return n.clock!==s.id.clock+s.length-1&&s.constructor!==na&&i.splice(r+1,0,_k(t,s,n.clock-s.id.clock+1)),s},zRt=(t,e,n)=>{const i=t.clients.get(e.id.client);i[ja(i,e.id.clock)]=n},pue=(t,e,n,i,r)=>{if(i===0)return;const s=n+i;let o=O$(t,e,n),a;do a=e[o++],s<a.id.clock+a.length&&O$(t,e,s),r(a);while(o<e.length&&e[o].id.clock<s)},Pd=Symbol;class WRt{constructor(e,n){this.left=e,this.right=n}}const Xu=(t,e)=>new WRt(t,e);typeof DOMParser<"u"&&new DOMParser;const HRt=t=>mxt(t,(e,n)=>`${n}:${e};`).join(""),k9=Pd(),x9=Pd(),hue=Pd(),mue=Pd(),gue=Pd(),R9=Pd(),_ue=Pd(),N9=Pd(),vue=Pd(),VRt={[k9]:Xu("font-weight","bold"),[x9]:Xu("font-weight","normal"),[hue]:Xu("color","blue"),[gue]:Xu("color","green"),[mue]:Xu("color","grey"),[R9]:Xu("color","red"),[_ue]:Xu("color","purple"),[N9]:Xu("color","orange"),[vue]:Xu("color","black")},Sue={[k9]:"\x1B[1m",[x9]:"\x1B[2m",[hue]:"\x1B[34m",[gue]:"\x1B[32m",[mue]:"\x1B[37m",[R9]:"\x1B[31m",[_ue]:"\x1B[35m",[N9]:"\x1B[38;5;208m",[vue]:"\x1B[0m"},XRt=t=>{const e=[],n=[],i=Bl();let r=[],s=0;for(;s<t.length;s++){const o=t[s],a=VRt[o];if(a!==void 0)i.set(a.left,a.right);else if(o.constructor===String||o.constructor===Number){const l=HRt(i);s>0||l.length>0?(e.push("%c"+o),n.push(l)):e.push(o)}else break}for(s>0&&(r=n,r.unshift(e.join("")));s<t.length;s++){const o=t[s];o instanceof Symbol||r.push(o)}return r},KRt=t=>{const e=[],n=[];let i=0;for(;i<t.length;i++){const r=t[i];if(Sue[r]===void 0)if(r.constructor===String||r.constructor===Number)e.push(r);else break}for(i>0&&n.push(e.join(""));i<t.length;i++){const r=t[i];r instanceof Symbol||(r.constructor===Object?n.push(JSON.stringify(r)):n.push(r))}return n},jRt=t=>{const e=[],n=[];let i=0;for(;i<t.length;i++){const r=t[i],s=Sue[r];if(s!==void 0)e.push(s);else if(r.constructor===String||r.constructor===Number)e.push(r);else break}for(i>0&&(e.push("\x1B[0m"),n.push(e.join("")));i<t.length;i++){const r=t[i];r instanceof Symbol||n.push(r)}return n},ZRt=Fxt?Rm?jRt:XRt:KRt,w$=(...t)=>{console.log(...ZRt(t)),JRt.forEach(e=>e.print(t))},JRt=xm();class yue{constructor(e,n,i){this.doc=e,this.deleteSet=new qv,this.beforeState=RE(e.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}}const GK=(t,e)=>e.deleteSet.clients.size===0&&!gxt(e.afterState,(n,i)=>e.beforeState.get(i)!==n)?!1:(v9(e.deleteSet),yRt(t,e),nu(t,e.deleteSet),!0),QK=(t,e,n)=>{const i=e._item;(i===null||i.id.clock<(t.beforeState.get(i.id.client)||0)&&!i.deleted)&&Md(t.changed,e,xm).add(n)},hT=(t,e)=>{const n=t[e-1],i=t[e];n.deleted===i.deleted&&n.constructor===i.constructor&&n.mergeWith(i)&&(t.splice(e,1),i instanceof Hn&&i.parentSub!==null&&i.parent._map.get(i.parentSub)===i&&i.parent._map.set(i.parentSub,n))},Eue=(t,e,n)=>{for(const[i,r]of t.clients.entries()){const s=e.clients.get(i);for(let o=r.length-1;o>=0;o--){const a=r[o],l=a.clock+a.len;for(let u=ja(s,a.clock),d=s[u];u<s.length&&d.id.clock<l;d=s[++u]){const p=s[u];if(a.clock+a.len<=p.id.clock)break;p instanceof Hn&&p.deleted&&!p.keep&&n(p)&&p.gc(e,!1)}}}},bue=(t,e)=>{t.clients.forEach((n,i)=>{const r=e.clients.get(i);for(let s=n.length-1;s>=0;s--){const o=n[s],a=d9(r.length-1,1+ja(r,o.clock+o.len-1));for(let l=a,u=r[l];l>0&&u.id.clock>=o.clock;u=r[--l])hT(r,l)}})},eNt=(t,e,n)=>{Eue(t,e,n),bue(t,e)},Oue=(t,e)=>{if(e<t.length){const n=t[e],i=n.doc,r=i.store,s=n.deleteSet,o=n._mergeStructs;try{v9(s),n.afterState=RE(n.doc.store),i.emit("beforeObserverCalls",[n,i]);const a=[];n.changed.forEach((l,u)=>a.push(()=>{(u._item===null||!u._item.deleted)&&u._callObserver(n,l)})),a.push(()=>{n.changedParentTypes.forEach((l,u)=>a.push(()=>{(u._item===null||!u._item.deleted)&&(l=l.filter(d=>d.target._item===null||!d.target._item.deleted),l.forEach(d=>{d.currentTarget=u}),l.sort((d,p)=>d.path.length-p.path.length),aue(u._dEH,l,n))})),a.push(()=>i.emit("afterTransaction",[n,i]))}),f9(a,[])}finally{i.gc&&Eue(s,r,i.gcFilter),bue(s,r),n.afterState.forEach((d,p)=>{const h=n.beforeState.get(p)||0;if(h!==d){const g=r.clients.get(p),y=Um(ja(g,h),1);for(let O=g.length-1;O>=y;O--)hT(g,O)}});for(let d=0;d<o.length;d++){const{client:p,clock:h}=o[d].id,g=r.clients.get(p),y=ja(g,h);y+1<g.length&&hT(g,y+1),y>0&&hT(g,y)}if(!n.local&&n.afterState.get(i.clientID)!==n.beforeState.get(i.clientID)&&(w$(N9,k9,"[yjs] ",x9,R9,"Changed the client-id because another client seems to be using it."),i.clientID=eue()),i.emit("afterTransactionCleanup",[n,i]),i._observers.has("update")){const d=new Gm;GK(d,n)&&i.emit("update",[d.toUint8Array(),n.origin,i,n])}if(i._observers.has("updateV2")){const d=new kd;GK(d,n)&&i.emit("updateV2",[d.toUint8Array(),n.origin,i,n])}const{subdocsAdded:a,subdocsLoaded:l,subdocsRemoved:u}=n;(a.size>0||u.size>0||l.size>0)&&(a.forEach(d=>{d.clientID=i.clientID,d.collectionid==null&&(d.collectionid=i.collectionid),i.subdocs.add(d)}),u.forEach(d=>i.subdocs.delete(d)),i.emit("subdocs",[{loaded:l,added:a,removed:u},i,n]),u.forEach(d=>d.destroy())),t.length<=e+1?(i._transactionCleanups=[],i.emit("afterAllTransactions",[i,t])):Oue(t,e+1)}}},Wn=(t,e,n=null,i=!0)=>{const r=t._transactionCleanups;let s=!1,o=null;t._transaction===null&&(s=!0,t._transaction=new yue(t,n,i),r.push(t._transaction),r.length===1&&t.emit("beforeAllTransactions",[t]),t.emit("beforeTransaction",[t._transaction,t]));try{o=e(t._transaction)}finally{if(s){const a=t._transaction===r[0];t._transaction=null,a&&Oue(r,0)}}return o};class tNt{constructor(e,n){this.insertions=n,this.deletions=e,this.meta=new Map}}const qK=(t,e,n)=>{bp(t,n.deletions,i=>{i instanceof Hn&&e.scope.some(r=>qy(r,i))&&$9(i,!1)})},YK=(t,e,n)=>{let i=null,r=null;const s=t.doc,o=t.scope;if(Wn(s,a=>{for(;e.length>0&&i===null;){const l=s.store,u=e.pop(),d=new Set,p=[];let h=!1;bp(a,u.insertions,g=>{if(g instanceof Hn){if(g.redone!==null){let{item:y,diff:O}=C$(l,g.id);O>0&&(y=Gs(a,Yt(y.id.client,y.id.clock+O))),g=y}!g.deleted&&o.some(y=>qy(y,g))&&p.push(g)}}),bp(a,u.deletions,g=>{g instanceof Hn&&o.some(y=>qy(y,g))&&!Yv(u.insertions,g.id)&&d.add(g)}),d.forEach(g=>{h=ede(a,g,d,u.insertions,t.ignoreRemoteMapChanges)!==null||h});for(let g=p.length-1;g>=0;g--){const y=p[g];t.deleteFilter(y)&&(y.delete(a),h=!0)}i=h?u:null}a.changed.forEach((l,u)=>{l.has(null)&&u._searchMarker&&(u._searchMarker.length=0)}),r=a},t),i!=null){const a=r.changedParentTypes;t.emit("stack-item-popped",[{stackItem:i,type:n,changedParentTypes:a},t])}return i};class nNt extends CE{constructor(e,{captureTimeout:n=500,captureTransaction:i=l=>!0,deleteFilter:r=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:a=EK(e)?e[0].doc:e.doc}={}){super(),this.scope=[],this.addToScope(e),this.deleteFilter=r,s.add(this),this.trackedOrigins=s,this.captureTransaction=i,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.doc=a,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=n,this.afterTransactionHandler=l=>{if(!this.captureTransaction(l)||!this.scope.some(b=>l.changedParentTypes.has(b))||!this.trackedOrigins.has(l.origin)&&(!l.origin||!this.trackedOrigins.has(l.origin.constructor)))return;const u=this.undoing,d=this.redoing,p=u?this.redoStack:this.undoStack;u?this.stopCapturing():d||this.clear(!1,!0);const h=new qv;l.afterState.forEach((b,w)=>{const T=l.beforeState.get(w)||0,x=b-T;x>0&&Gy(h,w,T,x)});const g=wp();let y=!1;if(this.lastChange>0&&g-this.lastChange<this.captureTimeout&&p.length>0&&!u&&!d){const b=p[p.length-1];b.deletions=Uy([b.deletions,l.deleteSet]),b.insertions=Uy([b.insertions,h])}else p.push(new tNt(l.deleteSet,h)),y=!0;!u&&!d&&(this.lastChange=g),bp(l,l.deleteSet,b=>{b instanceof Hn&&this.scope.some(w=>qy(w,b))&&$9(b,!0)});const O=[{stackItem:p[p.length-1],origin:l.origin,type:u?"redo":"undo",changedParentTypes:l.changedParentTypes},this];y?this.emit("stack-item-added",O):this.emit("stack-item-updated",O)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(e){e=EK(e)?e:[e],e.forEach(n=>{this.scope.every(i=>i!==n)&&this.scope.push(n)})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,n=!0){(e&&this.canUndo()||n&&this.canRedo())&&this.doc.transact(i=>{e&&(this.undoStack.forEach(r=>qK(i,this,r)),this.undoStack=[]),n&&(this.redoStack.forEach(r=>qK(i,this,r)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=YK(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=YK(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}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*iNt(t){const e=Gt(t.restDecoder);for(let n=0;n<e;n++){const i=Gt(t.restDecoder),r=t.readClient();let s=Gt(t.restDecoder);for(let o=0;o<i;o++){const a=t.readInfo();if(a===10){const l=Gt(t.restDecoder);yield new ia(Yt(r,s),l),s+=l}else if(ER&a){const l=(a&(hd|ca))===0,u=new Hn(Yt(r,s),null,(a&ca)===ca?t.readLeftID():null,null,(a&hd)===hd?t.readRightID():null,l?t.readParentInfo()?t.readString():t.readLeftID():null,l&&(a&Py)===Py?t.readString():null,tde(t,a));yield u,s+=u.length}else{const l=t.readLen();yield new na(Yt(r,s),l),s+=l}}}}class Qm{constructor(e,n){this.gen=iNt(e),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===ia);return this.curr}}const rNt=t=>wue(t,Ld),wue=(t,e=iu)=>{const n=[],i=new e(ls(t)),r=new Qm(i,!1);for(let o=r.curr;o!==null;o=r.next())n.push(o);w$("Structs: ",n);const s=Op(i);w$("DeleteSet: ",s)},sNt=t=>Tue(t,Ld),Tue=(t,e=iu)=>{const n=[],i=new e(ls(t)),r=new Qm(i,!1);for(let s=r.curr;s!==null;s=r.next())n.push(s);return{structs:n,ds:Op(i)}};class A9{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}}const Cue=t=>Yy(t,Ld,Gm),kue=(t,e=CR,n=iu)=>{const i=new e,r=new Qm(new n(ls(t)),!1);let s=r.curr;if(s!==null){let o=0,a=s.id.client,l=s.id.clock!==0,u=l?0:s.id.clock+s.length;for(;s!==null;s=r.next())a!==s.id.client&&(u!==0&&(o++,lt(i.restEncoder,a),lt(i.restEncoder,u)),a=s.id.client,u=0,l=s.id.clock!==0),s.constructor===ia&&(l=!0),l||(u=s.id.clock+s.length);u!==0&&(o++,lt(i.restEncoder,a),lt(i.restEncoder,u));const d=Dr();return lt(d,o),aRt(d,i.restEncoder),i.restEncoder=d,i.toUint8Array()}else return lt(i.restEncoder,0),i.toUint8Array()},oNt=t=>kue(t,vv,Ld),xue=(t,e=iu)=>{const n=new Map,i=new Map,r=new Qm(new e(ls(t)),!1);let s=r.curr;if(s!==null){let o=s.id.client,a=s.id.clock;for(n.set(o,a);s!==null;s=r.next())o!==s.id.client&&(i.set(o,a),n.set(s.id.client,s.id.clock),o=s.id.client),a=s.id.clock+s.length;i.set(o,a)}return{from:n,to:i}},aNt=t=>xue(t,Ld),lNt=(t,e)=>{if(t.constructor===na){const{client:n,clock:i}=t.id;return new na(Yt(n,i+e),t.length-e)}else if(t.constructor===ia){const{client:n,clock:i}=t.id;return new ia(Yt(n,i+e),t.length-e)}else{const n=t,{client:i,clock:r}=n.id;return new Hn(Yt(i,r+e),null,Yt(i,r+e-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(e))}},Yy=(t,e=iu,n=kd)=>{if(t.length===1)return t[0];const i=t.map(d=>new e(ls(d)));let r=i.map(d=>new Qm(d,!0)),s=null;const o=new n,a=new A9(o);for(;r=r.filter(h=>h.curr!==null),r.sort((h,g)=>{if(h.curr.id.client===g.curr.id.client){const y=h.curr.id.clock-g.curr.id.clock;return y===0?h.curr.constructor===g.curr.constructor?0:h.curr.constructor===ia?1:-1:y}else return g.curr.id.client-h.curr.id.client}),r.length!==0;){const d=r[0],p=d.curr.id.client;if(s!==null){let h=d.curr,g=!1;for(;h!==null&&h.id.clock+h.length<=s.struct.id.clock+s.struct.length&&h.id.client>=s.struct.id.client;)h=d.next(),g=!0;if(h===null||h.id.client!==p||g&&h.id.clock>s.struct.id.clock+s.struct.length)continue;if(p!==s.struct.id.client)Mf(a,s.struct,s.offset),s={struct:h,offset:0},d.next();else if(s.struct.id.clock+s.struct.length<h.id.clock)if(s.struct.constructor===ia)s.struct.length=h.id.clock+h.length-s.struct.id.clock;else{Mf(a,s.struct,s.offset);const y=h.id.clock-s.struct.id.clock-s.struct.length;s={struct:new ia(Yt(p,s.struct.id.clock+s.struct.length),y),offset:0}}else{const y=s.struct.id.clock+s.struct.length-h.id.clock;y>0&&(s.struct.constructor===ia?s.struct.length-=y:h=lNt(h,y)),s.struct.mergeWith(h)||(Mf(a,s.struct,s.offset),s={struct:h,offset:0},d.next())}}else s={struct:d.curr,offset:0},d.next();for(let h=d.curr;h!==null&&h.id.client===p&&h.id.clock===s.struct.id.clock+s.struct.length&&h.constructor!==ia;h=d.next())Mf(a,s.struct,s.offset),s={struct:h,offset:0}}s!==null&&(Mf(a,s.struct,s.offset),s=null),D9(a);const l=i.map(d=>Op(d)),u=Uy(l);return nu(o,u),o.toUint8Array()},I9=(t,e,n=iu,i=kd)=>{const r=b9(e),s=new i,o=new A9(s),a=new n(ls(t)),l=new Qm(a,!1);for(;l.curr;){const d=l.curr,p=d.id.client,h=r.get(p)||0;if(l.curr.constructor===ia){l.next();continue}if(d.id.clock+d.length>h)for(Mf(o,d,Um(h-d.id.clock,0)),l.next();l.curr&&l.curr.id.client===p;)Mf(o,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===p&&l.curr.id.clock+l.curr.length<=h;)l.next()}D9(o);const u=Op(a);return nu(s,u),s.toUint8Array()},cNt=(t,e)=>I9(t,e,Ld,Gm),Rue=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:fi(t.encoder.restEncoder)}),t.encoder.restEncoder=Dr(),t.written=0)},Mf=(t,e,n)=>{t.written>0&&t.currClient!==e.id.client&&Rue(t),t.written===0&&(t.currClient=e.id.client,t.encoder.writeClient(e.id.client),lt(t.encoder.restEncoder,e.id.clock+n)),e.write(t.encoder,n),t.written++},D9=t=>{Rue(t);const e=t.encoder.restEncoder;lt(e,t.clientStructs.length);for(let n=0;n<t.clientStructs.length;n++){const i=t.clientStructs[n];lt(e,i.written),xE(e,i.restEncoder)}},Nue=(t,e,n)=>{const i=new e(ls(t)),r=new Qm(i,!1),s=new n,o=new A9(s);for(let l=r.curr;l!==null;l=r.next())Mf(o,l,0);D9(o);const a=Op(i);return nu(s,a),s.toUint8Array()},uNt=t=>Nue(t,Ld,kd),Aue=t=>Nue(t,iu,Gm);class NE{constructor(e,n){this.target=e,this.currentTarget=e,this.transaction=n,this._changes=null,this._keys=null,this._delta=null}get path(){return dNt(this.currentTarget,this.target)}deletes(e){return Yv(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){const e=new Map,n=this.target;this.transaction.changed.get(n).forEach(r=>{if(r!==null){const s=n._map.get(r);let o,a;if(this.adds(s)){let l=s.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(s))if(l!==null&&this.deletes(l))o="delete",a=BL(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",a=BL(l.content.getContent())):(o="add",a=void 0)}else if(this.deletes(s))o="delete",a=BL(s.content.getContent());else return;e.set(r,{action:o,oldValue:a})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){const n=this.target,i=xm(),r=xm(),s=[];if(e={added:i,deleted:r,delta:s,keys:this.keys},this.transaction.changed.get(n).has(null)){let a=null;const l=()=>{a&&s.push(a)};for(let u=n._start;u!==null;u=u.right)u.deleted?this.deletes(u)&&!this.adds(u)&&((a===null||a.delete===void 0)&&(l(),a={delete:0}),a.delete+=u.length,r.add(u)):this.adds(u)?((a===null||a.insert===void 0)&&(l(),a={insert:[]}),a.insert=a.insert.concat(u.content.getContent()),i.add(u)):((a===null||a.retain===void 0)&&(l(),a={retain:0}),a.retain+=u.length);a!==null&&a.retain===void 0&&l()}this._changes=e}return e}}const dNt=(t,e)=>{const n=[];for(;e._item!==null&&e!==t;){if(e._item.parentSub!==null)n.unshift(e._item.parentSub);else{let i=0,r=e._item.parent._start;for(;r!==e._item&&r!==null;)r.deleted||i++,r=r.right;n.unshift(i)}e=e._item.parent}return n},Iue=t=>({[Symbol.iterator](){return this},next:t}),fNt=(t,e)=>Iue(()=>{let n;do n=t.next();while(!n.done&&!e(n.value));return n}),YL=(t,e)=>Iue(()=>{const{done:n,value:i}=t.next();return{done:n,value:n?void 0:e(i)}}),Due=80;let M9=0;class pNt{constructor(e,n){e.marker=!0,this.p=e,this.index=n,this.timestamp=M9++}}const hNt=t=>{t.timestamp=M9++},Mue=(t,e,n)=>{t.p.marker=!1,t.p=e,e.marker=!0,t.index=n,t.timestamp=M9++},mNt=(t,e,n)=>{if(t.length>=Due){const i=t.reduce((r,s)=>r.timestamp<s.timestamp?r:s);return Mue(i,e,n),i}else{const i=new pNt(e,n);return t.push(i),i}},RR=(t,e)=>{if(t._start===null||e===0||t._searchMarker===null)return null;const n=t._searchMarker.length===0?null:t._searchMarker.reduce((s,o)=>dT(e-s.index)<dT(e-o.index)?s:o);let i=t._start,r=0;for(n!==null&&(i=n.p,r=n.index,hNt(n));i.right!==null&&r<e;){if(!i.deleted&&i.countable){if(e<r+i.length)break;r+=i.length}i=i.right}for(;i.left!==null&&r>e;)i=i.left,!i.deleted&&i.countable&&(r-=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&&(r-=i.length);return n!==null&&dT(n.index-r)<i.parent.length/Due?(Mue(n,i,r),n):mNt(t._searchMarker,i,r)},zy=(t,e,n)=>{for(let i=t.length-1;i>=0;i--){const r=t[i];if(n>0){let s=r.p;for(s.marker=!1;s&&(s.deleted||!s.countable);)s=s.left,s&&!s.deleted&&s.countable&&(r.index-=s.length);if(s===null||s.marker===!0){t.splice(i,1);continue}r.p=s,s.marker=!0}(e<r.index||n>0&&e===r.index)&&(r.index=Um(e,r.index+n))}},gNt=t=>{let e=t._start;const n=[];for(;e;)n.push(e),e=e.right;return n},NR=(t,e,n)=>{const i=t,r=e.changedParentTypes;for(;Md(r,t,()=>[]).push(n),t._item!==null;)t=t._item.parent;aue(i._eH,n,e)};class Fr{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=LK(),this._dEH=LK(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,n){this.doc=e,this._item=n}_copy(){throw Jc()}clone(){throw Jc()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,n){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){PK(this._eH,e)}observeDeep(e){PK(this._dEH,e)}unobserve(e){$K(this._eH,e)}unobserveDeep(e){$K(this._dEH,e)}toJSON(){}}const Lue=(t,e,n)=>{e<0&&(e=t._length+e),n<0&&(n=t._length+n);let i=n-e;const r=[];let s=t._start;for(;s!==null&&i>0;){if(s.countable&&!s.deleted){const o=s.content.getContent();if(o.length<=e)e-=o.length;else{for(let a=e;a<o.length&&i>0;a++)r.push(o[a]),i--;e=0}}s=s.right}return r},Pue=t=>{const e=[];let n=t._start;for(;n!==null;){if(n.countable&&!n.deleted){const i=n.content.getContent();for(let r=0;r<i.length;r++)e.push(i[r])}n=n.right}return e},_Nt=(t,e)=>{const n=[];let i=t._start;for(;i!==null;){if(i.countable&&Uh(i,e)){const r=i.content.getContent();for(let s=0;s<r.length;s++)n.push(r[s])}i=i.right}return n},Wy=(t,e)=>{let n=0,i=t._start;for(;i!==null;){if(i.countable&&!i.deleted){const r=i.content.getContent();for(let s=0;s<r.length;s++)e(r[s],n++,t)}i=i.right}},$ue=(t,e)=>{const n=[];return Wy(t,(i,r)=>{n.push(e(i,r,t))}),n},vNt=t=>{let e=t._start,n=null,i=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};n=e.content.getContent(),i=0,e=e.right}const r=n[i++];return n.length<=i&&(n=null),{done:!1,value:r}}}},Fue=(t,e)=>{const n=RR(t,e);let i=t._start;for(n!==null&&(i=n.p,e-=n.index);i!==null;i=i.right)if(!i.deleted&&i.countable){if(e<i.length)return i.content.getContent()[e];e-=i.length}},mk=(t,e,n,i)=>{let r=n;const s=t.doc,o=s.clientID,a=s.store,l=n===null?e._start:n.right;let u=[];const d=()=>{u.length>0&&(r=new Hn(Yt(o,Pi(a,o)),r,r&&r.lastId,l,l&&l.id,e,null,new kp(u)),r.integrate(t,0),u=[])};i.forEach(p=>{if(p===null)u.push(p);else switch(p.constructor){case Number:case Object:case Boolean:case Array:case String:u.push(p);break;default:switch(d(),p.constructor){case Uint8Array:case ArrayBuffer:r=new Hn(Yt(o,Pi(a,o)),r,r&&r.lastId,l,l&&l.id,e,null,new Wv(new Uint8Array(p))),r.integrate(t,0);break;case Pp:r=new Hn(Yt(o,Pi(a,o)),r,r&&r.lastId,l,l&&l.id,e,null,new AE(p)),r.integrate(t,0);break;default:if(p instanceof Fr)r=new Hn(Yt(o,Pi(a,o)),r,r&&r.lastId,l,l&&l.id,e,null,new Xl(p)),r.integrate(t,0);else throw new Error("Unexpected content type in insert operation")}}}),d()},Bue=Qv("Length exceeded!"),Uue=(t,e,n,i)=>{if(n>e._length)throw Bue;if(n===0)return e._searchMarker&&zy(e._searchMarker,n,i.length),mk(t,e,null,i);const r=n,s=RR(e,n);let o=e._start;for(s!==null&&(o=s.p,n-=s.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&Gs(t,Yt(o.id.client,o.id.clock+n));break}n-=o.length}return e._searchMarker&&zy(e._searchMarker,r,i.length),mk(t,e,o,i)},SNt=(t,e,n)=>{let r=(e._searchMarker||[]).reduce((s,o)=>o.index>s.index?o:s,{index:0,p:e._start}).p;if(r)for(;r.right;)r=r.right;return mk(t,e,r,n)},Gue=(t,e,n,i)=>{if(i===0)return;const r=n,s=i,o=RR(e,n);let a=e._start;for(o!==null&&(a=o.p,n-=o.index);a!==null&&n>0;a=a.right)!a.deleted&&a.countable&&(n<a.length&&Gs(t,Yt(a.id.client,a.id.clock+n)),n-=a.length);for(;i>0&&a!==null;)a.deleted||(i<a.length&&Gs(t,Yt(a.id.client,a.id.clock+i)),a.delete(t),i-=a.length),a=a.right;if(i>0)throw Bue;e._searchMarker&&zy(e._searchMarker,r,-s+i)},gk=(t,e,n)=>{const i=e._map.get(n);i!==void 0&&i.delete(t)},L9=(t,e,n,i)=>{const r=e._map.get(n)||null,s=t.doc,o=s.clientID;let a;if(i==null)a=new kp([i]);else switch(i.constructor){case Number:case Object:case Boolean:case Array:case String:a=new kp([i]);break;case Uint8Array:a=new Wv(i);break;case Pp:a=new AE(i);break;default:if(i instanceof Fr)a=new Xl(i);else throw new Error("Unexpected content type")}new Hn(Yt(o,Pi(s.store,o)),r,r&&r.lastId,null,null,e,n,a).integrate(t,0)},P9=(t,e)=>{const n=t._map.get(e);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Que=t=>{const e={};return t._map.forEach((n,i)=>{n.deleted||(e[i]=n.content.getContent()[n.length-1])}),e},que=(t,e)=>{const n=t._map.get(e);return n!==void 0&&!n.deleted},yNt=(t,e,n)=>{let i=t._map.get(e)||null;for(;i!==null&&(!n.sv.has(i.id.client)||i.id.clock>=(n.sv.get(i.id.client)||0));)i=i.left;return i!==null&&Uh(i,n)?i.content.getContent()[i.length-1]:void 0},fw=t=>fNt(t.entries(),e=>!e[1].deleted);class Yue extends NE{constructor(e,n){super(e,n),this._transaction=n}}class gd extends Fr{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const n=new gd;return n.push(e),n}_integrate(e,n){super._integrate(e,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new gd}clone(){const e=new gd;return e.insert(0,this.toArray().map(n=>n instanceof Fr?n.clone():n)),e}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}_callObserver(e,n){super._callObserver(e,n),NR(this,e,new Yue(this,e))}insert(e,n){this.doc!==null?Wn(this.doc,i=>{Uue(i,this,e,n)}):this._prelimContent.splice(e,0,...n)}push(e){this.doc!==null?Wn(this.doc,n=>{SNt(n,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,n=1){this.doc!==null?Wn(this.doc,i=>{Gue(i,this,e,n)}):this._prelimContent.splice(e,n)}get(e){return Fue(this,e)}toArray(){return Pue(this)}slice(e=0,n=this.length){return Lue(this,e,n)}toJSON(){return this.map(e=>e instanceof Fr?e.toJSON():e)}map(e){return $ue(this,e)}forEach(e){Wy(this,e)}[Symbol.iterator](){return vNt(this)}_write(e){e.writeTypeRef(BNt)}}const ENt=t=>new gd;class zue extends NE{constructor(e,n,i){super(e,n),this.keysChanged=i}}class Tp extends Fr{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,n){super._integrate(e,n),this._prelimContent.forEach((i,r)=>{this.set(r,i)}),this._prelimContent=null}_copy(){return new Tp}clone(){const e=new Tp;return this.forEach((n,i)=>{e.set(i,n instanceof Fr?n.clone():n)}),e}_callObserver(e,n){NR(this,e,new zue(this,e,n))}toJSON(){const e={};return this._map.forEach((n,i)=>{if(!n.deleted){const r=n.content.getContent()[n.length-1];e[i]=r instanceof Fr?r.toJSON():r}}),e}get size(){return[...fw(this._map)].length}keys(){return YL(fw(this._map),e=>e[0])}values(){return YL(fw(this._map),e=>e[1].content.getContent()[e[1].length-1])}entries(){return YL(fw(this._map),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this._map.forEach((n,i)=>{n.deleted||e(n.content.getContent()[n.length-1],i,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?Wn(this.doc,n=>{gk(n,this,e)}):this._prelimContent.delete(e)}set(e,n){return this.doc!==null?Wn(this.doc,i=>{L9(i,this,e,n)}):this._prelimContent.set(e,n),n}get(e){return P9(this,e)}has(e){return que(this,e)}clear(){this.doc!==null?Wn(this.doc,e=>{this.forEach(function(n,i,r){gk(e,r,i)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(UNt)}}const bNt=t=>new Tp,Vf=(t,e)=>t===e||typeof t=="object"&&typeof e=="object"&&t&&e&&Dxt(t,e);class T${constructor(e,n,i,r){this.left=e,this.right=n,this.index=i,this.currentAttributes=r}forward(){switch(this.right===null&&Ka(),this.right.content.constructor){case ur:this.right.deleted||zv(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 zK=(t,e,n)=>{for(;e.right!==null&&n>0;){switch(e.right.content.constructor){case ur:e.right.deleted||zv(e.currentAttributes,e.right.content);break;default:e.right.deleted||(n<e.right.length&&Gs(t,Yt(e.right.id.client,e.right.id.clock+n)),e.index+=e.right.length,n-=e.right.length);break}e.left=e.right,e.right=e.right.right}return e},pw=(t,e,n)=>{const i=new Map,r=RR(e,n);if(r){const s=new T$(r.p.left,r.p,r.index,i);return zK(t,s,n-r.index)}else{const s=new T$(null,e._start,0,i);return zK(t,s,n)}},Wue=(t,e,n,i)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===ur&&Vf(i.get(n.right.content.key),n.right.content.value));)n.right.deleted||i.delete(n.right.content.key),n.forward();const r=t.doc,s=r.clientID;i.forEach((o,a)=>{const l=n.left,u=n.right,d=new Hn(Yt(s,Pi(r.store,s)),l,l&&l.lastId,u,u&&u.id,e,null,new ur(a,o));d.integrate(t,0),n.right=d,n.forward()})},zv=(t,e)=>{const{key:n,value:i}=e;i===null?t.delete(n):t.set(n,i)},Hue=(t,e)=>{for(;t.right!==null;){if(!(t.right.deleted||t.right.content.constructor===ur&&Vf(e[t.right.content.key]||null,t.right.content.value)))break;t.forward()}},Vue=(t,e,n,i)=>{const r=t.doc,s=r.clientID,o=new Map;for(const a in i){const l=i[a],u=n.currentAttributes.get(a)||null;if(!Vf(u,l)){o.set(a,u);const{left:d,right:p}=n;n.right=new Hn(Yt(s,Pi(r.store,s)),d,d&&d.lastId,p,p&&p.id,e,null,new ur(a,l)),n.right.integrate(t,0),n.forward()}}return o},zL=(t,e,n,i,r)=>{n.currentAttributes.forEach((h,g)=>{r[g]===void 0&&(r[g]=null)});const s=t.doc,o=s.clientID;Hue(n,r);const a=Vue(t,e,n,r),l=i.constructor===String?new Ql(i):i instanceof Fr?new Xl(i):new $p(i);let{left:u,right:d,index:p}=n;e._searchMarker&&zy(e._searchMarker,n.index,l.getLength()),d=new Hn(Yt(o,Pi(s.store,o)),u,u&&u.lastId,d,d&&d.id,e,null,l),d.integrate(t,0),n.right=d,n.index=p,n.forward(),Wue(t,e,n,a)},WK=(t,e,n,i,r)=>{const s=t.doc,o=s.clientID;Hue(n,r);const a=Vue(t,e,n,r);e:for(;n.right!==null&&(i>0||a.size>0&&(n.right.deleted||n.right.content.constructor===ur));){if(!n.right.deleted)switch(n.right.content.constructor){case ur:{const{key:l,value:u}=n.right.content,d=r[l];if(d!==void 0){if(Vf(d,u))a.delete(l);else{if(i===0)break e;a.set(l,u)}n.right.delete(t)}else n.currentAttributes.set(l,u);break}default:i<n.right.length&&Gs(t,Yt(n.right.id.client,n.right.id.clock+i)),i-=n.right.length;break}n.forward()}if(i>0){let l="";for(;i>0;i--)l+=`
|
|
1113
1113
|
`;n.right=new Hn(Yt(o,Pi(s.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,e,null,new Ql(l)),n.right.integrate(t,0),n.forward()}Wue(t,e,n,a)},Xue=(t,e,n,i,r)=>{let s=e;const o=Bl();for(;s&&(!s.countable||s.deleted);){if(!s.deleted&&s.content.constructor===ur){const u=s.content;o.set(u.key,u)}s=s.right}let a=0,l=!1;for(;e!==s;){if(n===e&&(l=!0),!e.deleted){const u=e.content;switch(u.constructor){case ur:{const{key:d,value:p}=u,h=i.get(d)||null;(o.get(d)!==u||h===p)&&(e.delete(t),a++,!l&&(r.get(d)||null)===p&&h!==p&&(h===null?r.delete(d):r.set(d,h))),!l&&!e.deleted&&zv(r,u);break}}}e=e.right}return a},ONt=(t,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;const n=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===ur){const i=e.content.key;n.has(i)?e.delete(t):n.add(i)}e=e.left}},Kue=t=>{let e=0;return Wn(t.doc,n=>{let i=t._start,r=t._start,s=Bl();const o=_$(s);for(;r;){if(r.deleted===!1)switch(r.content.constructor){case ur:zv(o,r.content);break;default:e+=Xue(n,i,r,s,o),s=_$(o),i=r;break}r=r.right}}),e},HK=(t,e,n)=>{const i=n,r=_$(e.currentAttributes),s=e.right;for(;n>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case Xl:case $p:case Ql:n<e.right.length&&Gs(t,Yt(e.right.id.client,e.right.id.clock+n)),n-=e.right.length,e.right.delete(t);break}e.forward()}s&&Xue(t,s,e.right,r,e.currentAttributes);const o=(e.left||e.right).parent;return o._searchMarker&&zy(o._searchMarker,e.index,-i+n),e};class jue extends NE{constructor(e,n,i){super(e,n),this.childListChanged=!1,this.keysChanged=new Set,i.forEach(r=>{r===null?this.childListChanged=!0:this.keysChanged.add(r)})}get changes(){if(this._changes===null){const e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){const e=this.target.doc,n=[];Wn(e,i=>{const r=new Map,s=new Map;let o=this.target._start,a=null;const l={};let u="",d=0,p=0;const h=()=>{if(a!==null){let g;switch(a){case"delete":g={delete:p},p=0;break;case"insert":g={insert:u},r.size>0&&(g.attributes={},r.forEach((y,O)=>{y!==null&&(g.attributes[O]=y)})),u="";break;case"retain":if(g={retain:d},Object.keys(l).length>0){g.attributes={};for(const y in l)g.attributes[y]=l[y]}d=0;break}n.push(g),a=null}};for(;o!==null;){switch(o.content.constructor){case Xl:case $p:this.adds(o)?this.deletes(o)||(h(),a="insert",u=o.content.getContent()[0],h()):this.deletes(o)?(a!=="delete"&&(h(),a="delete"),p+=1):o.deleted||(a!=="retain"&&(h(),a="retain"),d+=1);break;case Ql:this.adds(o)?this.deletes(o)||(a!=="insert"&&(h(),a="insert"),u+=o.content.str):this.deletes(o)?(a!=="delete"&&(h(),a="delete"),p+=o.length):o.deleted||(a!=="retain"&&(h(),a="retain"),d+=o.length);break;case ur:{const{key:g,value:y}=o.content;if(this.adds(o)){if(!this.deletes(o)){const O=r.get(g)||null;Vf(O,y)?y!==null&&o.delete(i):(a==="retain"&&h(),Vf(y,s.get(g)||null)?delete l[g]:l[g]=y)}}else if(this.deletes(o)){s.set(g,y);const O=r.get(g)||null;Vf(O,y)||(a==="retain"&&h(),l[g]=O)}else if(!o.deleted){s.set(g,y);const O=l[g];O!==void 0&&(Vf(O,y)?O!==null&&o.delete(i):(a==="retain"&&h(),y===null?delete l[g]:l[g]=y))}o.deleted||(a==="insert"&&h(),zv(r,o.content));break}}o=o.right}for(h();n.length>0;){const g=n[n.length-1];if(g.retain!==void 0&&g.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class Nm extends Fr{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[]}get length(){return this._length}_integrate(e,n){super._integrate(e,n);try{this._pending.forEach(i=>i())}catch(i){console.error(i)}this._pending=null}_copy(){return new Nm}clone(){const e=new Nm;return e.applyDelta(this.toDelta()),e}_callObserver(e,n){super._callObserver(e,n);const i=new jue(this,e,n),r=e.doc;if(NR(this,e,i),!e.local){let s=!1;for(const[o,a]of e.afterState.entries()){const l=e.beforeState.get(o)||0;if(a!==l&&(pue(e,r.store.clients.get(o),l,a,u=>{!u.deleted&&u.content.constructor===ur&&(s=!0)}),s))break}s||bp(e,e.deleteSet,o=>{o instanceof na||s||o.parent===this&&o.content.constructor===ur&&(s=!0)}),Wn(r,o=>{s?Kue(this):bp(o,o.deleteSet,a=>{a instanceof na||a.parent===this&&ONt(o,a)})})}}toString(){let e="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===Ql&&(e+=n.content.str),n=n.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:n=!0}={}){this.doc!==null?Wn(this.doc,i=>{const r=new T$(null,this._start,0,new Map);for(let s=0;s<e.length;s++){const o=e[s];if(o.insert!==void 0){const a=!n&&typeof o.insert=="string"&&s===e.length-1&&r.right===null&&o.insert.slice(-1)===`
|
|
1114
1114
|
`?o.insert.slice(0,-1):o.insert;(typeof a!="string"||a.length>0)&&zL(i,this,r,a,o.attributes||{})}else o.retain!==void 0?WK(i,this,r,o.retain,o.attributes||{}):o.delete!==void 0&&HK(i,r,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,n,i){const r=[],s=new Map,o=this.doc;let a="",l=this._start;function u(){if(a.length>0){const p={};let h=!1;s.forEach((y,O)=>{h=!0,p[O]=y});const g={insert:a};h&&(g.attributes=p),r.push(g),a=""}}const d=()=>{for(;l!==null;){if(Uh(l,e)||n!==void 0&&Uh(l,n))switch(l.content.constructor){case Ql:{const p=s.get("ychange");e!==void 0&&!Uh(l,e)?(p===void 0||p.user!==l.id.client||p.type!=="removed")&&(u(),s.set("ychange",i?i("removed",l.id):{type:"removed"})):n!==void 0&&!Uh(l,n)?(p===void 0||p.user!==l.id.client||p.type!=="added")&&(u(),s.set("ychange",i?i("added",l.id):{type:"added"})):p!==void 0&&(u(),s.delete("ychange")),a+=l.content.str;break}case Xl:case $p:{u();const p={insert:l.content.getContent()[0]};if(s.size>0){const h={};p.attributes=h,s.forEach((g,y)=>{h[y]=g})}r.push(p);break}case ur:Uh(l,e)&&(u(),zv(s,l.content));break}l=l.right}u()};return e||n?Wn(o,p=>{e&&b$(p,e),n&&b$(p,n),d()},"cleanup"):d(),r}insert(e,n,i){if(n.length<=0)return;const r=this.doc;r!==null?Wn(r,s=>{const o=pw(s,this,e);i||(i={},o.currentAttributes.forEach((a,l)=>{i[l]=a})),zL(s,this,o,n,i)}):this._pending.push(()=>this.insert(e,n,i))}insertEmbed(e,n,i={}){const r=this.doc;r!==null?Wn(r,s=>{const o=pw(s,this,e);zL(s,this,o,n,i)}):this._pending.push(()=>this.insertEmbed(e,n,i))}delete(e,n){if(n===0)return;const i=this.doc;i!==null?Wn(i,r=>{HK(r,pw(r,this,e),n)}):this._pending.push(()=>this.delete(e,n))}format(e,n,i){if(n===0)return;const r=this.doc;r!==null?Wn(r,s=>{const o=pw(s,this,e);o.right!==null&&WK(s,this,o,n,i)}):this._pending.push(()=>this.format(e,n,i))}removeAttribute(e){this.doc!==null?Wn(this.doc,n=>{gk(n,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,n){this.doc!==null?Wn(this.doc,i=>{L9(i,this,e,n)}):this._pending.push(()=>this.setAttribute(e,n))}getAttribute(e){return P9(this,e)}getAttributes(){return Que(this)}_write(e){e.writeTypeRef(GNt)}}const wNt=t=>new Nm;class WL{constructor(e,n=()=>!0){this._filter=n,this._root=e,this._currentNode=e._start,this._firstCall=!0}[Symbol.iterator](){return this}next(){let e=this._currentNode,n=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(n)))do if(n=e.content.type,!e.deleted&&(n.constructor===Sv||n.constructor===Cp)&&n._start!==null)e=n._start;else for(;e!==null;)if(e.right!==null){e=e.right;break}else e.parent===this._root?e=null:e=e.parent._item;while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}}class Cp extends Fr{constructor(){super(),this._prelimContent=[]}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,n){super._integrate(e,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Cp}clone(){const e=new Cp;return e.insert(0,this.toArray().map(n=>n instanceof Fr?n.clone():n)),e}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new WL(this,e)}querySelector(e){e=e.toUpperCase();const i=new WL(this,r=>r.nodeName&&r.nodeName.toUpperCase()===e).next();return i.done?null:i.value}querySelectorAll(e){return e=e.toUpperCase(),Ep(new WL(this,n=>n.nodeName&&n.nodeName.toUpperCase()===e))}_callObserver(e,n){NR(this,e,new Zue(this,n,e))}toString(){return $ue(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,n={},i){const r=e.createDocumentFragment();return i!==void 0&&i._createAssociation(r,this),Wy(this,s=>{r.insertBefore(s.toDOM(e,n,i),null)}),r}insert(e,n){this.doc!==null?Wn(this.doc,i=>{Uue(i,this,e,n)}):this._prelimContent.splice(e,0,...n)}insertAfter(e,n){if(this.doc!==null)Wn(this.doc,i=>{const r=e&&e instanceof Fr?e._item:e;mk(i,this,r,n)});else{const i=this._prelimContent,r=e===null?0:i.findIndex(s=>s===e)+1;if(r===0&&e!==null)throw Qv("Reference item not found");i.splice(r,0,...n)}}delete(e,n=1){this.doc!==null?Wn(this.doc,i=>{Gue(i,this,e,n)}):this._prelimContent.splice(e,n)}toArray(){return Pue(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return Fue(this,e)}slice(e=0,n=this.length){return Lue(this,e,n)}forEach(e){Wy(this,e)}_write(e){e.writeTypeRef(qNt)}}const TNt=t=>new Cp;class Sv extends Cp{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,n){super._integrate(e,n),this._prelimAttrs.forEach((i,r)=>{this.setAttribute(r,i)}),this._prelimAttrs=null}_copy(){return new Sv(this.nodeName)}clone(){const e=new Sv(this.nodeName),n=this.getAttributes();for(const i in n)e.setAttribute(i,n[i]);return e.insert(0,this.toArray().map(i=>i instanceof Fr?i.clone():i)),e}toString(){const e=this.getAttributes(),n=[],i=[];for(const a in e)i.push(a);i.sort();const r=i.length;for(let a=0;a<r;a++){const l=i[a];n.push(l+'="'+e[l]+'"')}const s=this.nodeName.toLocaleLowerCase(),o=n.length>0?" "+n.join(" "):"";return`<${s}${o}>${super.toString()}</${s}>`}removeAttribute(e){this.doc!==null?Wn(this.doc,n=>{gk(n,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,n){this.doc!==null?Wn(this.doc,i=>{L9(i,this,e,n)}):this._prelimAttrs.set(e,n)}getAttribute(e){return P9(this,e)}hasAttribute(e){return que(this,e)}getAttributes(){return Que(this)}toDOM(e=document,n={},i){const r=e.createElement(this.nodeName),s=this.getAttributes();for(const o in s)r.setAttribute(o,s[o]);return Wy(this,o=>{r.appendChild(o.toDOM(e,n,i))}),i!==void 0&&i._createAssociation(r,this),r}_write(e){e.writeTypeRef(QNt),e.writeKey(this.nodeName)}}const CNt=t=>new Sv(t.readKey());class Zue extends NE{constructor(e,n,i){super(e,i),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(r=>{r===null?this.childListChanged=!0:this.attributesChanged.add(r)})}}class Hy extends Tp{constructor(e){super(),this.hookName=e}_copy(){return new Hy(this.hookName)}clone(){const e=new Hy(this.hookName);return this.forEach((n,i)=>{e.set(i,n)}),e}toDOM(e=document,n={},i){const r=n[this.hookName];let s;return r!==void 0?s=r.createDom(this):s=document.createElement(this.hookName),s.setAttribute("data-yjs-hook",this.hookName),i!==void 0&&i._createAssociation(s,this),s}_write(e){e.writeTypeRef(YNt),e.writeKey(this.hookName)}}const kNt=t=>new Hy(t.readKey());class Vy extends Nm{get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new Vy}clone(){const e=new Vy;return e.applyDelta(this.toDelta()),e}toDOM(e=document,n,i){const r=e.createTextNode(this.toString());return i!==void 0&&i._createAssociation(r,this),r}toString(){return this.toDelta().map(e=>{const n=[];for(const r in e.attributes){const s=[];for(const o in e.attributes[r])s.push({key:o,value:e.attributes[r][o]});s.sort((o,a)=>o.key<a.key?-1:1),n.push({nodeName:r,attrs:s})}n.sort((r,s)=>r.nodeName<s.nodeName?-1:1);let i="";for(let r=0;r<n.length;r++){const s=n[r];i+=`<${s.nodeName}`;for(let o=0;o<s.attrs.length;o++){const a=s.attrs[o];i+=` ${a.key}="${a.value}"`}i+=">"}i+=e.insert;for(let r=n.length-1;r>=0;r--)i+=`</${n[r].nodeName}>`;return i}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(zNt)}}const xNt=t=>new Vy;class AR{constructor(e,n){this.id=e,this.length=n}get deleted(){throw Jc()}mergeWith(e){return!1}write(e,n,i){throw Jc()}integrate(e,n){throw Jc()}}const RNt=0;class na extends AR{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,n){n>0&&(this.id.clock+=n,this.length-=n),fue(e.doc.store,this)}write(e,n){e.writeInfo(RNt),e.writeLen(this.length-n)}getMissing(e,n){return null}}class Wv{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Wv(this.content)}splice(e){throw Jc()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeBuf(this.content)}getRef(){return 3}}const NNt=t=>new Wv(t.readBuf());class yv{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new yv(this.len)}splice(e){const n=new yv(this.len-e);return this.len=e,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,n){Gy(e.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(e){}gc(e){}write(e,n){e.writeLen(this.len-n)}getRef(){return 1}}const ANt=t=>new yv(t.readLen()),Jue=(t,e)=>new Pp({guid:t,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class AE{constructor(e){e._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=e;const n={};this.opts=n,e.gc||(n.gc=!1),e.autoLoad&&(n.autoLoad=!0),e.meta!==null&&(n.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new AE(Jue(this.doc.guid,this.opts))}splice(e){throw Jc()}mergeWith(e){return!1}integrate(e,n){this.doc._item=n,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,n){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}}const INt=t=>new AE(Jue(t.readString(),t.readAny()));class $p{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new $p(this.embed)}splice(e){throw Jc()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeJSON(this.embed)}getRef(){return 5}}const DNt=t=>new $p(t.readJSON());class ur{constructor(e,n){this.key=e,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new ur(this.key,this.value)}splice(e){throw Jc()}mergeWith(e){return!1}integrate(e,n){n.parent._searchMarker=null}delete(e){}gc(e){}write(e,n){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}const MNt=t=>new ur(t.readKey(),t.readJSON());class Xy{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Xy(this.arr)}splice(e){const n=new Xy(this.arr.slice(e));return this.arr=this.arr.slice(0,e),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,n){}delete(e){}gc(e){}write(e,n){const i=this.arr.length;e.writeLen(i-n);for(let r=n;r<i;r++){const s=this.arr[r];e.writeString(s===void 0?"undefined":JSON.stringify(s))}}getRef(){return 2}}const LNt=t=>{const e=t.readLen(),n=[];for(let i=0;i<e;i++){const r=t.readString();r==="undefined"?n.push(void 0):n.push(JSON.parse(r))}return new Xy(n)};class kp{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new kp(this.arr)}splice(e){const n=new kp(this.arr.slice(e));return this.arr=this.arr.slice(0,e),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,n){}delete(e){}gc(e){}write(e,n){const i=this.arr.length;e.writeLen(i-n);for(let r=n;r<i;r++){const s=this.arr[r];e.writeAny(s)}}getRef(){return 8}}const PNt=t=>{const e=t.readLen(),n=[];for(let i=0;i<e;i++)n.push(t.readAny());return new kp(n)};class Ql{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new Ql(this.str)}splice(e){const n=new Ql(this.str.slice(e));this.str=this.str.slice(0,e);const i=this.str.charCodeAt(e-1);return i>=55296&&i<=56319&&(this.str=this.str.slice(0,e-1)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}}const $Nt=t=>new Ql(t.readString()),FNt=[ENt,bNt,wNt,CNt,TNt,kNt,xNt],BNt=0,UNt=1,GNt=2,QNt=3,qNt=4,YNt=5,zNt=6;class Xl{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new Xl(this.type._copy())}splice(e){throw Jc()}mergeWith(e){return!1}integrate(e,n){this.type._integrate(e.doc,n)}delete(e){let n=this.type._start;for(;n!==null;)n.deleted?e._mergeStructs.push(n):n.delete(e),n=n.right;this.type._map.forEach(i=>{i.deleted?e._mergeStructs.push(i):i.delete(e)}),e.changed.delete(this.type)}gc(e){let n=this.type._start;for(;n!==null;)n.gc(e,!0),n=n.right;this.type._start=null,this.type._map.forEach(i=>{for(;i!==null;)i.gc(e,!0),i=i.left}),this.type._map=new Map}write(e,n){this.type._write(e)}getRef(){return 7}}const WNt=t=>new Xl(FNt[t.readTypeRef()](t)),C$=(t,e)=>{let n=e,i=0,r;do i>0&&(n=Yt(n.client,n.clock+i)),r=NS(t,n),i=n.clock-r.id.clock,n=r.redone;while(n!==null&&r instanceof Hn);return{item:r,diff:i}},$9=(t,e)=>{for(;t!==null&&t.keep!==e;)t.keep=e,t=t.parent._item},_k=(t,e,n)=>{const{client:i,clock:r}=e.id,s=new Hn(Yt(i,r+n),e,Yt(i,r+n-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(n));return e.deleted&&s.markDeleted(),e.keep&&(s.keep=!0),e.redone!==null&&(s.redone=Yt(e.redone.client,e.redone.clock+n)),e.right=s,s.right!==null&&(s.right.left=s),t._mergeStructs.push(s),s.parentSub!==null&&s.right===null&&s.parent._map.set(s.parentSub,s),e.length=n,s},ede=(t,e,n,i,r)=>{const s=t.doc,o=s.store,a=s.clientID,l=e.redone;if(l!==null)return Gs(t,l);let u=e.parent._item,d=null,p;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||ede(t,u,n,i,r)===null))return null;for(;u.redone!==null;)u=Gs(t,u.redone)}const h=u===null?e.parent:u.content.type;if(e.parentSub===null){for(d=e.left,p=e;d!==null;){let b=d;for(;b!==null&&b.parent._item!==u;)b=b.redone===null?null:Gs(t,b.redone);if(b!==null&&b.parent._item===u){d=b;break}d=d.left}for(;p!==null;){let b=p;for(;b!==null&&b.parent._item!==u;)b=b.redone===null?null:Gs(t,b.redone);if(b!==null&&b.parent._item===u){p=b;break}p=p.right}}else if(p=null,e.right&&!r){for(d=e;d!==null&&d.right!==null&&Yv(i,d.right.id);)d=d.right;for(;d!==null&&d.redone!==null;)d=Gs(t,d.redone);if(d&&d.right!==null)return null}else d=h._map.get(e.parentSub)||null;const g=Pi(o,a),y=Yt(a,g),O=new Hn(y,d,d&&d.lastId,p,p&&p.id,h,e.parentSub,e.content.copy());return e.redone=y,$9(O,!0),O.integrate(t,0),O};class Hn extends AR{constructor(e,n,i,r,s,o,a,l){super(e,l.getLength()),this.origin=i,this.left=n,this.right=r,this.rightOrigin=s,this.parent=o,this.parentSub=a,this.redone=null,this.content=l,this.info=this.content.isCountable()?CK:0}set marker(e){(this.info&GL)>0!==e&&(this.info^=GL)}get marker(){return(this.info&GL)>0}get keep(){return(this.info&TK)>0}set keep(e){this.keep!==e&&(this.info^=TK)}get countable(){return(this.info&CK)>0}get deleted(){return(this.info&UL)>0}set deleted(e){this.deleted!==e&&(this.info^=UL)}markDeleted(){this.info|=UL}getMissing(e,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=Pi(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=Pi(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===um&&this.id.client!==this.parent.client&&this.parent.clock>=Pi(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=UK(e,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Gs(e,this.rightOrigin),this.rightOrigin=this.right.id),(this.left&&this.left.constructor===na||this.right&&this.right.constructor===na)&&(this.parent=null),!this.parent)this.left&&this.left.constructor===Hn&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===Hn&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===um){const i=NS(n,this.parent);i.constructor===na?this.parent=null:this.parent=i.content.type}return null}integrate(e,n){if(n>0&&(this.id.clock+=n,this.left=UK(e,e.doc.store,Yt(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,r;if(i!==null)r=i.right;else if(this.parentSub!==null)for(r=this.parent._map.get(this.parentSub)||null;r!==null&&r.left!==null;)r=r.left;else r=this.parent._start;const s=new Set,o=new Set;for(;r!==null&&r!==this.right;){if(o.add(r),s.add(r),Zh(this.origin,r.origin)){if(r.id.client<this.id.client)i=r,s.clear();else if(Zh(this.rightOrigin,r.rightOrigin))break}else if(r.origin!==null&&o.has(NS(e.doc.store,r.origin)))s.has(NS(e.doc.store,r.origin))||(i=r,s.clear());else break;r=r.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(e)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),fue(e.doc.store,this),this.content.integrate(e,this),QK(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new na(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;e!==null&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;e!==null&&e.deleted;)e=e.left;return e}get lastId(){return this.length===1?this.id:Yt(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&Zh(e.origin,this.lastId)&&this.right===e&&Zh(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&this.redone===null&&e.redone===null&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){const n=this.parent._searchMarker;return n&&n.forEach(i=>{i.p===e&&(i.p=this,!this.deleted&&this.countable&&(i.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){const n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),Gy(e.deleteSet,this.id.client,this.id.clock,this.length),QK(e,n,this.parentSub),this.content.delete(e)}}gc(e,n){if(!this.deleted)throw Ka();this.content.gc(e),n?zRt(e,this,new na(this.id,this.length)):this.content=new yv(this.length)}write(e,n){const i=n>0?Yt(this.id.client,this.id.clock+n-1):this.origin,r=this.rightOrigin,s=this.parentSub,o=this.content.getRef()&ER|(i===null?0:ca)|(r===null?0:hd)|(s===null?0:Py);if(e.writeInfo(o),i!==null&&e.writeLeftID(i),r!==null&&e.writeRightID(r),i===null&&r===null){const a=this.parent;if(a._item!==void 0){const l=a._item;if(l===null){const u=w9(a);e.writeParentInfo(!0),e.writeString(u)}else e.writeParentInfo(!1),e.writeLeftID(l.id)}else a.constructor===String?(e.writeParentInfo(!0),e.writeString(a)):a.constructor===um?(e.writeParentInfo(!1),e.writeLeftID(a)):Ka();s!==null&&e.writeString(s)}this.content.write(e,n)}}const tde=(t,e)=>HNt[e&ER](t),HNt=[()=>{Ka()},ANt,LNt,NNt,$Nt,DNt,MNt,WNt,PNt,INt,()=>{Ka()}],VNt=10;class ia extends AR{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,n){Ka()}write(e,n){e.writeInfo(VNt),lt(e.restEncoder,this.length-n)}getMissing(e,n){return null}}const nde=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},ide="__ $YJS$ __";nde[ide]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");nde[ide]=!0;const XNt=Object.freeze(Object.defineProperty({__proto__:null,AbsolutePosition:lue,AbstractConnector:vxt,AbstractStruct:AR,AbstractType:Fr,Array:gd,ContentAny:kp,ContentBinary:Wv,ContentDeleted:yv,ContentEmbed:$p,ContentFormat:ur,ContentJSON:Xy,ContentString:Ql,ContentType:Xl,Doc:Pp,GC:na,ID:um,Item:Hn,Map:Tp,PermanentUserData:kRt,RelativePosition:xR,Snapshot:T9,Text:Nm,Transaction:yue,UndoManager:nNt,UpdateEncoderV1:Gm,XmlElement:Sv,XmlFragment:Cp,XmlHook:Hy,XmlText:Vy,YArrayEvent:Yue,YEvent:NE,YMapEvent:zue,YTextEvent:jue,YXmlEvent:Zue,applyUpdate:nue,applyUpdateV2:kR,cleanupYTextFormatting:Kue,compareIDs:Zh,compareRelativePositions:$Rt,convertUpdateFormatV1ToV2:uNt,convertUpdateFormatV2ToV1:Aue,createAbsolutePositionFromRelativePosition:PRt,createDeleteSet:TR,createDeleteSetFromStructStore:S9,createDocFromSnapshot:qRt,createID:Yt,createRelativePositionFromJSON:RRt,createRelativePositionFromTypeIndex:ARt,createSnapshot:C9,decodeRelativePosition:LRt,decodeSnapshot:URt,decodeSnapshotV2:uue,decodeStateVector:b9,decodeUpdate:sNt,decodeUpdateV2:Tue,diffUpdate:cNt,diffUpdateV2:I9,emptySnapshot:GRt,encodeRelativePosition:DRt,encodeSnapshot:BRt,encodeSnapshotV2:cue,encodeStateAsUpdate:rue,encodeStateAsUpdateV2:iue,encodeStateVector:oue,encodeStateVectorFromUpdate:oNt,encodeStateVectorFromUpdateV2:kue,equalSnapshots:FRt,findIndexSS:ja,findRootTypeKey:w9,getItem:NS,getState:Pi,getTypeChildren:gNt,isDeleted:Yv,isParentOf:qy,iterateDeletedStructs:bp,logType:CRt,logUpdate:rNt,logUpdateV2:wue,mergeUpdates:Cue,mergeUpdatesV2:Yy,parseUpdateMeta:aNt,parseUpdateMetaV2:xue,readUpdate:ERt,readUpdateV2:E9,relativePositionToJSON:xRt,snapshot:QRt,transact:Wn,tryGc:eNt,typeListToArraySnapshot:_Nt,typeMapGetSnapshot:yNt},Symbol.toStringTag,{value:"Module"})),rde=N$(XNt);var IR={},Jh=J;function sde(t){throw Error(`Minified Lexical error #${t}; visit https://lexical.dev/docs/error?code=${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}let ode=class{constructor(e,n,i=1){this._offsetMap=e,this._firstNode=n,this._blockOffsetSize=i}createSelectionFromOffsets(e,n,i){var r=this._firstNode;if(r===null)return null;var s=H0(r,e,this._blockOffsetSize);let o=H0(r,n,this._blockOffsetSize);if(i!==void 0&&(e=VK(e,s,i,this,this._blockOffsetSize),s=H0(r,e,this._blockOffsetSize),n=VK(n,o,i,this,this._blockOffsetSize),o=H0(r,n,this._blockOffsetSize)),s===null||o===null)return null;i=s.key,r=o.key;let a=Jh.$getNodeByKey(i),l=Jh.$getNodeByKey(r);if(a===null||l===null)return null;let u=0,d=0,p="element",h="element";return s.type==="text"?(u=e-s.start,p="text",s=a.getNextSibling(),e!==n&&u===a.getTextContentSize()&&Jh.$isTextNode(s)&&(u=0,i=s.__key)):s.type==="inline"&&(i=a.getParentOrThrow().getKey(),u=n>s.start?s.end:s.start),o.type==="text"?(d=n-o.start,h="text"):o.type==="inline"&&(r=l.getParentOrThrow().getKey(),d=n>o.start?o.end:o.start),e=Jh.$createRangeSelection(),e===null?null:(e.anchor.set(i,u,p),e.focus.set(r,d,h),e)}getOffsetsFromSelection(e){var n=e.anchor,i=e.focus,r=this._offsetMap;let s=n.offset;var o=i.offset;let a=e=-1;if(n.type==="text")n=r.get(n.key),n!==void 0&&(e=n.start+s);else if(n=n.getNode().getDescendantByIndex(s),n!==null){let l=r.get(n.getKey());l!==void 0&&(e=n.getIndexWithinParent()!==s?l.end:l.start)}return i.type==="text"?(o=r.get(i.key),o!==void 0&&(a=o.start+i.offset)):(i=i.getNode().getDescendantByIndex(o),i!==null&&(r=r.get(i.getKey()),r!==void 0&&(a=i.getIndexWithinParent()!==o?r.end:r.start))),[e,a]}};function VK(t,e,n,i,r){let s=n._offsetMap;i=i._offsetMap;let o=new Set,a=t;for(;e!==null;){var l=e.key,u=s.get(l),d=e.end-e.start;if(o.add(l),u===void 0?a+=d:(l=u.end-u.start,l!==d&&(a+=d-l)),d=e.prev,d!==null)e=d;else{for(e=e.parent;e!==null;)u=e.prev,u!==null&&(d=u.key,l=s.get(d),u=u.end-u.start,o.add(d),l===void 0?a+=u:(d=l.end-l.start,d!==u&&(a+=u-d))),e=e.parent;break}}if(n=n._firstNode,n!==null){for(e=H0(n,t,r),t=!1;e!==null;){if(!o.has(e.key)){t=!0;break}e=e.parent}if(!t)for(;e!==null;)t=e.key,o.has(t)||(r=i.get(t),t=e.end-e.start,r===void 0?a-=t:(r=r.end-r.start,t!==r&&(a+=r-t))),e=e.prev}return a}function H0(t,e,n){for(;t!==null;){if(e<t.end+(t.type!=="element"||n===0?1:0)){let i=t.child;if(i!==null){t=i;continue}return t}if(t=t.next,t===null)break}return null}function ade(t,e,n,i,r,s){let o=null,a=null,l=e.length;for(let b=0;b<l;b++){{var u=t,d=e[b],p=n,h=i,g=r,y=s,O=h.get(d);O===void 0&&sde(3);let w=u.offset;if(Jh.$isElementNode(O)){let T=F9(O,h);h=(O=T.length===0)?null:ade(u,T,null,h,g,y),(!u.prevIsBlock||O)&&(u.prevIsBlock=!0,u.offset+=y),p={child:h,end:w,key:d,next:null,parent:p,prev:null,start:w,type:"element"},h!==null&&(h.parent=p),p.end=u.offset,g.set(d,p),d=p}else u.prevIsBlock=!1,y=Jh.$isTextNode(O),u={child:null,end:u.offset+=y?O.__text.length:1,key:d,next:null,parent:p,prev:null,start:w,type:y?"text":"inline"},g.set(d,u),d=u}a===null?o=d:(d.prev=a,a.next=d),a=d}return o}function F9(t,e){let n=[];for(t=t.__first;t!==null;){let i=e===null?Jh.$getNodeByKey(t):e.get(t);i!=null||sde(101),n.push(t),t=i.__next}return n}IR.$createOffsetView=function(t,e=1,n){n=(n||t._pendingEditorState||t._editorState)._nodeMap;let i=n.get("root");return t=new Map,n=ade({offset:0,prevIsBlock:!1},F9(i,n),null,n,t,e),new ode(t,n,e)};IR.OffsetView=ode;IR.createChildrenArray=F9;const KNt=IR;var jNt=KNt,Ft=J,_i=rde,XK=La,KK=jNt;function Xr(t){throw Error(`Minified Lexical error #${t}; visit https://lexical.dev/docs/error?code=${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class V0{constructor(e,n){this._key="",this._map=e,this._parent=n,this._type="linebreak"}getNode(){let e=Ft.$getNodeByKey(this._key);return Ft.$isLineBreakNode(e)?e:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(e){e.collabNodeMap.delete(this._key)}}function lde(t,e){return e=new V0(t,e),t._collabNode=e}class vo{constructor(e,n,i,r){this._key="",this._map=e,this._parent=i,this._text=n,this._type=r,this._normalized=!1}getPrevNode(e){return e===null?null:(e=e.get(this._key),Ft.$isTextNode(e)?e:null)}getNode(){let e=Ft.$getNodeByKey(this._key);return Ft.$isTextNode(e)?e:null}getSharedType(){return this._map}getType(){return this._type}getKey(){return this._key}getSize(){return this._text.length+(this._normalized?0:1)}getOffset(){return this._parent.getChildOffset(this)}spliceText(e,n,i){let r=this._parent._xmlText;e=this.getOffset()+1+e,n!==0&&r.delete(e,n),i!==""&&r.insert(e,i)}syncPropertiesAndTextFromLexical(e,n,i){var r=this.getPrevNode(i);if(i=n.__text,G9(e,this._map,r,n),r!==null&&(e=r.__text,e!==i)){r=n.__key,n=e;var s=Ft.$getSelection();e=i.length,Ft.$isRangeSelection(s)&&s.isCollapsed()&&(s=s.anchor,s.key===r&&(e=s.offset)),r=n.length;let o=i.length,a=s=0;for(;s<r&&s<o&&n[s]===i[s]&&s<e;)s++;for(;a+s<r&&a+s<o&&n[r-a-1]===i[o-a-1];)a++;for(;a+s<r&&a+s<o&&n[s]===i[s];)s++;n=s,e=i.slice(s,o-a),r=r-s-a,this.spliceText(n,r,e),this._text=i}}syncPropertiesAndTextFromYjs(e,n){let i=this.getNode();i===null&&Xr(84),U9(e,this._map,i,n),e=this._text,i.__text!==e&&(i.getWritable().__text=e)}destroy(e){e.collabNodeMap.delete(this._key)}}function cde(t,e,n,i){return e=new vo(t,e,n,i),t._collabNode=e}let ude=new Set("__key __parent __cachedText __text __size __next __prev __first __last".split(" "));function x0(t){return t=Ft.$getNodeByKey(t),t===null&&Xr(85),t}function jK(t,e,n){let i=e.__type;if(Ft.$isElementNode(e)){var r=new _i.XmlText;r=Q9(r,n,i),r.syncPropertiesFromLexical(t,e,null),r.syncChildrenFromLexical(t,e,null,null,null)}else Ft.$isTextNode(e)?(r=new _i.Map,r=cde(r,e.__text,n,i),r.syncPropertiesAndTextFromLexical(t,e,null)):Ft.$isLineBreakNode(e)?(t=new _i.Map,t.set("__type","linebreak"),r=lde(t,n)):Ft.$isDecoratorNode(e)?(r=new _i.XmlElement,r=dde(r,n,i),r.syncPropertiesFromLexical(t,e,null)):Xr(86);return r._key=e.__key,r}function B9(t,e,n){let i=e._collabNode;if(i===void 0){var r=t.editor._nodes;let s=e instanceof _i.Map?e.get("__type"):e.getAttribute("__type");if(s==null&&Xr(87),r.get(s)===void 0&&Xr(88),r=e.parent,t=n===void 0&&r!==null?B9(t,r):n||null,t instanceof Ma||Xr(89),e instanceof _i.XmlText)return Q9(e,t,s);if(e instanceof _i.Map)return s==="linebreak"?lde(e,t):cde(e,"",t,s);if(e instanceof _i.XmlElement)return dde(e,t,s)}return i}function U9(t,e,n,i){i=i===null?e instanceof _i.Map?Array.from(e.keys()):Object.keys(e.getAttributes()):Array.from(i);let r;for(let o=0;o<i.length;o++){let a=i[o];if(ude.has(a))continue;var s=n[a];let l=e instanceof _i.Map?e.get(a):e.getAttribute(a);if(s!==l){if(l instanceof _i.Doc){let u=t.docMap;s instanceof _i.Doc&&u.delete(s.guid),s=Ft.createEditor();let d=l.guid;s._key=d,u.set(d,l),l=s}r===void 0&&(r=n.getWritable()),r[a]=l}}}function G9(t,e,n,i){var r=i.__type,s=t.nodeProperties;let o=s.get(r);for(o===void 0&&(o=Object.keys(i).filter(l=>!ude.has(l)),s.set(r,o)),r=t.editor.constructor,s=0;s<o.length;s++){let l=o[s];var a=n===null?void 0:n[l];let u=i[l];if(a!==u){if(u instanceof r){let d=t.docMap,p;a instanceof r&&(a=a._key,p=d.get(a),d.delete(a)),a=p||new _i.Doc;let h=a.guid;u._key=h,d.set(h,a),u=a,t.editor.update(()=>{i.markDirty()})}e instanceof _i.Map?e.set(l,u):e.setAttribute(l,u)}}}function mT(t,e,n){let i=0,r=0,s=t._children,o=s.length;for(;r<o;r++){t=s[r];let a=i,l=t.getSize();if(i+=l,(n?i>=e:i>e)&&t instanceof vo)return n=e-a-1,0>n&&(n=0),{length:i-e,node:t,nodeIndex:r,offset:n};if(i>e)return{length:0,node:t,nodeIndex:r,offset:a};if(r===o-1)return{length:0,node:null,nodeIndex:r+1,offset:a+1}}return{length:0,node:null,nodeIndex:0,offset:0}}function ZK(t){let e=t.anchor;t=t.focus;let n=!1;try{let i=e.getNode(),r=t.getNode();(!i.isAttached()||!r.isAttached()||Ft.$isTextNode(i)&&e.offset>i.getTextContentSize()||Ft.$isTextNode(r)&&t.offset>r.getTextContentSize())&&(n=!0)}catch{n=!0}return n}function ZNt(t,e){t.doc.transact(e,t)}function HL(t,e){let n=[];for(t=t.__first;t!==null;){let i=e===null?Ft.$getNodeByKey(t):e.get(t);i!=null||Xr(101),n.push(t),t=i.__next}return n}function JK(t){var e=t.getParent();if(e!==null){let r=t.getWritable();e=e.getWritable();var n=t.getPreviousSibling();if(t=t.getNextSibling(),n===null)if(t!==null){var i=t.getWritable();e.__first=t.__key,i.__prev=null}else e.__first=null;else{if(i=n.getWritable(),t!==null){let s=t.getWritable();s.__prev=i.__key,i.__next=s.__key}else i.__next=null;r.__prev=null}t===null?n!==null?(t=n.getWritable(),e.__last=n.__key,t.__next=null):e.__last=null:(t=t.getWritable(),n!==null?(n=n.getWritable(),n.__next=t.__key,t.__prev=n.__key):t.__prev=null,r.__next=null),e.__size--,r.__parent=null}}let Nf=class{constructor(e,n,i){this._key="",this._xmlElem=e,this._parent=n,this._type=i,this._unobservers=new Set}getPrevNode(e){return e===null?null:(e=e.get(this._key),Ft.$isDecoratorNode(e)?e:null)}getNode(){let e=Ft.$getNodeByKey(this._key);return Ft.$isDecoratorNode(e)?e:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}syncPropertiesFromLexical(e,n,i){i=this.getPrevNode(i),G9(e,this._xmlElem,i,n)}syncPropertiesFromYjs(e,n){let i=this.getNode();i===null&&Xr(83),U9(e,this._xmlElem,i,n)}destroy(e){e.collabNodeMap.delete(this._key),this._unobservers.forEach(n=>n()),this._unobservers.clear()}};function dde(t,e,n){return e=new Nf(t,e,n),t._collabNode=e}class Ma{constructor(e,n,i){this._key="",this._children=[],this._xmlText=e,this._type=i,this._parent=n}getPrevNode(e){return e===null?null:(e=e.get(this._key),Ft.$isElementNode(e)?e:null)}getNode(){let e=Ft.$getNodeByKey(this._key);return Ft.$isElementNode(e)?e:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return this._children.length===0}getSize(){return 1}getOffset(){let e=this._parent;return e===null&&Xr(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,n){let i=this.getNode();i===null&&Xr(91),U9(e,this._xmlText,i,n)}applyChildrenYjsDelta(e,n){let i=this._children,r=0;for(let p=0;p<n.length;p++){var s=n[p],o=s.insert,a=s.delete;if(s.retain!=null)r+=s.retain;else if(typeof a=="number")for(o=a;0<o;){let{node:h,nodeIndex:g,offset:y,length:O}=mT(this,r,!1);if(h instanceof Ma||h instanceof V0||h instanceof Nf)i.splice(g,1),--o;else if(h instanceof vo){s=Math.min(o,O),a=g!==0?i[g-1]:null;var l=h.getSize();if(y===0&&s===1&&0<g&&a instanceof vo&&O===l&&Array.from(h._map.keys()).length===0)a._text+=h._text,i.splice(g,1);else if(y===0&&s===l)i.splice(g,1);else{a=h,l=h._text;var u=y,d=s;l=l.slice(0,u)+""+l.slice(u+d),a._text=l}o-=s}else break}else if(o!=null)if(typeof o=="string"){let{node:h,offset:g}=mT(this,r,!0);h instanceof vo?(s=h,a=h._text,l=g,u=o,a=a.slice(0,l)+u+a.slice(l+0),s._text=a):this._xmlText.delete(g,o.length),r+=o.length}else s=o,{nodeIndex:o}=mT(this,r,!1),s=B9(e,s,this),i.splice(o,0,s),r+=1;else throw Error("Unexpected delta format")}}syncChildrenFromYjs(e){var n=this.getNode();n===null&&Xr(92);var i=n.__key;let r=HL(n,null),s=r.length;var o=this._children;let a=o.length,l=e.collabNodeMap,u=new Set,d,p=0;var h=null;a!==s&&n.getWritable();for(let x=0;x<a;x++){var g=r[p],y=o[x],O=y.getNode(),b=y._key;if(O!==null&&g===b)h=Ft.$isTextNode(O),u.add(g),h&&(y._key=g,y instanceof Ma?(h=y._xmlText,y.syncPropertiesFromYjs(e,null),y.applyChildrenYjsDelta(e,h.toDelta()),y.syncChildrenFromYjs(e)):y instanceof vo?y.syncPropertiesAndTextFromYjs(e,null):y instanceof Nf?y.syncPropertiesFromYjs(e,null):y instanceof V0||Xr(93)),h=O,p++;else{if(d===void 0)for(d=new Set,b=0;b<a;b++){var w=o[b]._key;w!==""&&d.add(w)}if(O===null||g===void 0||d.has(g)){O=n.getWritable(),g=e,b=y,w=i;var T=b.getType();T=g.editor._nodes.get(T),T===void 0&&Xr(88),T=new T.klass,T.__parent=w,b._key=T.__key,b instanceof Ma?(w=b._xmlText,b.syncPropertiesFromYjs(g,null),b.applyChildrenYjsDelta(g,w.toDelta()),b.syncChildrenFromYjs(g)):b instanceof vo?b.syncPropertiesAndTextFromYjs(g,null):b instanceof Nf&&b.syncPropertiesFromYjs(g,null),g.collabNodeMap.set(T.__key,b),g=T,b=g.__key,l.set(b,y),h===null?(h=O.getFirstChild(),O.__first=b,h!==null&&(h=h.getWritable(),h.__prev=b,g.__next=h.__key)):(y=h.getWritable(),w=h.getNextSibling(),y.__next=b,g.__prev=h.__key,w!==null&&(h=w.getWritable(),h.__prev=b,g.__next=h.__key)),x===a-1&&(O.__last=b),O.__size++,h=g}else y=x0(g),JK(y),x--,p++}}for(n=0;n<s;n++)o=r[n],u.has(o)||(i=x0(o),o=e.collabNodeMap.get(o),o!==void 0&&o.destroy(e),JK(i))}syncPropertiesFromLexical(e,n,i){G9(e,this._xmlText,this.getPrevNode(i),n)}_syncChildFromLexical(e,n,i,r,s,o){n=this._children[n],i=x0(i),n instanceof Ma&&Ft.$isElementNode(i)?(n.syncPropertiesFromLexical(e,i,r),n.syncChildrenFromLexical(e,i,r,s,o)):n instanceof vo&&Ft.$isTextNode(i)?n.syncPropertiesAndTextFromLexical(e,i,r):n instanceof Nf&&Ft.$isDecoratorNode(i)&&n.syncPropertiesFromLexical(e,i,r)}syncChildrenFromLexical(e,n,i,r,s){var o=this.getPrevNode(i);let a=o===null?[]:HL(o,i);o=HL(n,null);let l=a.length-1,u=o.length-1,d=e.collabNodeMap,p,h,g=0;for(n=0;g<=l&&n<=u;){var y=a[g];let b=o[n];if(y===b)this._syncChildFromLexical(e,n,b,i,r,s),g++,n++;else{p===void 0&&(p=new Set(a)),h===void 0&&(h=new Set(o));var O=h.has(y);y=p.has(b),O?(O=x0(b),O=jK(e,O,this),d.set(b,O),y?(this.splice(e,n,1,O),g++):this.splice(e,n,0,O),n++):(this.splice(e,n,1),g++)}}if(i=g>l,r=n>u,i&&!r)for(;n<=u;++n)i=o[n],r=x0(i),r=jK(e,r,this),this.append(r),d.set(i,r);else if(r&&!i)for(o=this._children.length-1;o>=n;o--)this.splice(e,o,1)}append(e){let n=this._xmlText;var i=this._children;if(i=i[i.length-1],i=i!==void 0?i.getOffset()+i.getSize():0,e instanceof Ma)n.insertEmbed(i,e._xmlText);else if(e instanceof vo){let r=e._map;r.parent===null&&n.insertEmbed(i,r),n.insert(i+1,e._text)}else e instanceof V0?n.insertEmbed(i,e._map):e instanceof Nf&&n.insertEmbed(i,e._xmlElem);this._children.push(e)}splice(e,n,i,r){let s=this._children;var o=s[n];if(o===void 0)r===void 0&&Xr(94),this.append(r);else{var a=o.getOffset();a===-1&&Xr(95);var l=this._xmlText;if(i!==0&&l.delete(a,o.getSize()),r instanceof Ma?l.insertEmbed(a,r._xmlText):r instanceof vo?(o=r._map,o.parent===null&&l.insertEmbed(a,o),l.insert(a+1,r._text)):r instanceof V0?l.insertEmbed(a,r._map):r instanceof Nf&&l.insertEmbed(a,r._xmlElem),i!==0)for(a=s.slice(n,n+i),l=0;l<a.length;l++)a[l].destroy(e);r!==void 0?s.splice(n,i,r):s.splice(n,i)}}getChildOffset(e){let n=0,i=this._children;for(let r=0;r<i.length;r++){let s=i[r];if(s===e)return n;n+=s.getSize()}return-1}destroy(e){let n=e.collabNodeMap,i=this._children;for(let r=0;r<i.length;r++)i[r].destroy(e);n.delete(this._key)}}function Q9(t,e,n){return e=new Ma(t,e,n),t._collabNode=e}function ej(t,e){var n=e.collabNodeMap.get(t.key);if(n===void 0)return null;e=t.offset;let i=n.getSharedType();if(n instanceof vo){if(i=n._parent._xmlText,t=n.getOffset(),t===-1)return null;e=t+1+e}else if(n instanceof Ma&&t.type==="element"){let r=n=0;for(t=t.getNode().getFirstChild();t!==null&&r++<e;)Ft.$isTextNode(t)?n+=t.getTextContentSize()+1:n++,t=t.getNextSibling();e=n}return _i.createRelativePositionFromTypeIndex(i,e)}function tj(t,e){if(t==null){if(e!=null)return!0}else if(e==null||!_i.compareRelativePositions(t,e))return!0;return!1}function nj(t,e){if(t=t.cursorsContainer,t!==null){e=e.selections;let n=e.length;for(let i=0;i<n;i++)t.removeChild(e[i])}}function ij(t,e){var n=e.awareness.getLocalState();if(n!==null&&(e=n.anchorPos,n=n.focusPos,e!==null&&n!==null&&(e=_i.createAbsolutePositionFromRelativePosition(e,t.doc),t=_i.createAbsolutePositionFromRelativePosition(n,t.doc),e!==null&&t!==null))){let[i,r]=vk(e.type,e.index),[s,o]=vk(t.type,t.index);if(i!==null&&s!==null){e=i.getKey(),n=s.getKey();let a=Ft.$getSelection();Ft.$isRangeSelection(a)&&(t=a.focus,rj(a.anchor,e,r),rj(t,n,o))}}}function rj(t,e,n){if(t.key!==e||t.offset!==n){let i=Ft.$getNodeByKey(e);if(i!==null&&!Ft.$isElementNode(i)&&!Ft.$isTextNode(i)){let r=i.getParentOrThrow();e=r.getKey(),n=i.getIndexWithinParent(),i=r}t.set(e,n,Ft.$isElementNode(i)?"element":"text")}}function vk(t,e){if(t=t._collabNode,t===void 0)return[null,0];if(t instanceof Ma){let{node:n,offset:i}=mT(t,e,!0);return n===null?[t,0]:[n,i]}return[null,0]}function fde(t,e){var n=Array.from(e.awareness.getStates()),i=t.clientID;e=t.cursors;var r=t.editor._editorState._nodeMap;let s=new Set;for(var o=0;o<n.length;o++){let[x,R]=n[o];if(x!==i){s.add(x);let{anchorPos:A,focusPos:L,name:F,color:q,focusing:H}=R;var a=null,l=e.get(x);if(l===void 0&&(l={color:q,name:F,selection:null},e.set(x,l)),A!==null&&L!==null&&H){var u=_i.createAbsolutePositionFromRelativePosition(A,t.doc),d=_i.createAbsolutePositionFromRelativePosition(L,t.doc);if(u!==null&&d!==null){let[Z,Y]=vk(u.type,u.index),[G,ie]=vk(d.type,d.index);if(Z!==null&&G!==null){u=Z.getKey();var p=G.getKey();if(a=l.selection,a===null){a=l,d=Y;var h=ie,g=a.color,y=document.createElement("span");y.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${g};z-index:10;`;var O=document.createElement("span");O.textContent=a.name,O.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:${g};color:#fff;line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`,y.appendChild(O),a={anchor:{key:u,offset:d},caret:y,color:g,focus:{key:p,offset:h},name:O,selections:[]}}else d=a.anchor,h=a.focus,d.key=u,d.offset=Y,h.key=p,h.offset=ie}}}e:if(u=t,d=l,y=a,g=r,h=u.editor,a=h.getRootElement(),l=u.cursorsContainer,l!==null&&a!==null&&(a=l.offsetParent,a!==null))if(a=a.getBoundingClientRect(),p=d.selection,y===null)p!==null&&(d.selection=null,nj(u,p));else{d.selection=y,d=y.caret,p=y.color,u=y.selections,O=y.anchor,y=y.focus;var b=O.key,w=y.key,T=g.get(b);if(g=g.get(w),T!=null&&g!=null){if(T===g&&Ft.$isLineBreakNode(T))g=[h.getElementByKey(b).getBoundingClientRect()];else{if(g=XK.createDOMRange(h,T,O.offset,g,y.offset),g===null)break e;g=XK.createRectsFromDOMRange(h,g)}for(y=u.length,h=g.length,O=0;O<h;O++)T=g[O],b=u[O],b===void 0&&(b=document.createElement("span"),u[O]=b,w=document.createElement("span"),b.appendChild(w),l.appendChild(b)),T=`position:absolute;top:${T.top-a.top}px;left:${T.left-a.left}px;height:${T.height}px;width:${T.width}px;pointer-events:none;z-index:5;`,b.style.cssText=T,b.firstChild.style.cssText=`${T}left:0;top:0;background-color:${p};opacity:0.3;`,O===h-1&&d.parentNode!==b&&b.appendChild(d);for(a=y-1;a>=h;a--)l.removeChild(u[a]),u.pop()}}}}for(n=Array.from(e.keys()),i=0;i<n.length;i++)r=n[i],s.has(r)||(o=e.get(r),o!==void 0&&(o=o.selection,o!==null&&nj(t,o),e.delete(r)))}function pde(t,e,n,i){e=e.awareness;var r=e.getLocalState();if(r!==null){var{anchorPos:s,focusPos:o,name:a,color:l,focusing:u}=r,d=r=null;(i!==null&&(s===null||i.is(n))||n!==null)&&(Ft.$isRangeSelection(i)&&(r=ej(i.anchor,t),d=ej(i.focus,t)),(tj(s,r)||tj(o,d))&&e.setLocalState({anchorPos:r,color:l,focusPos:d,focusing:u,name:a}))}}let JNt=Ft.createCommand("CONNECTED_COMMAND"),e2t=Ft.createCommand("TOGGLE_CONNECT_COMMAND");gu.CONNECTED_COMMAND=JNt;gu.TOGGLE_CONNECT_COMMAND=e2t;gu.createBinding=function(t,e,n,i,r){return i!=null||Xr(81),e=i.get("root",_i.XmlText),e=Q9(e,null,"root"),e._key="root",{clientID:i.clientID,collabNodeMap:new Map,cursors:new Map,cursorsContainer:null,doc:i,docMap:r,editor:t,id:n,nodeProperties:new Map,root:e}};gu.createUndoManager=function(t,e){return new _i.UndoManager(e,{trackedOrigins:new Set([t,null])})};gu.initLocalState=function(t,e,n,i){t.awareness.setLocalState({anchorPos:null,color:n,focusPos:null,focusing:i,name:e})};gu.setLocalStateFocus=function(t,e,n,i){({awareness:t}=t);let r=t.getLocalState();r===null&&(r={anchorPos:null,color:n,focusPos:null,focusing:i,name:e}),r.focusing=i,t.setLocalState(r)};gu.syncCursorPositions=fde;gu.syncLexicalUpdateToYjs=function(t,e,n,i,r,s,o,a){ZNt(t,()=>{i.read(()=>{if(a.has("collaboration")||a.has("historic")){if(0<o.size){var l=Array.from(o),u=t.collabNodeMap,d=[];for(let y=0;y<l.length;y++){var p=l[y],h=Ft.$getNodeByKey(p),g=u.get(p);if(g instanceof vo)if(Ft.$isTextNode(h))d.push([g,h.__text]);else{if(h=g.getOffset(),h===-1)continue;let O=g._parent;g._normalized=!0,O._xmlText.delete(h,1),u.delete(p),p=O._children,g=p.indexOf(g),p.splice(g,1)}}for(l=0;l<d.length;l++){let[y,O]=d[l];y instanceof vo&&typeof O=="string"&&(y._text=O)}}}else r.has("root")&&(d=n._nodeMap,l=Ft.$getRoot(),u=t.root,u.syncPropertiesFromLexical(t,l,d),u.syncChildrenFromLexical(t,l,d,r,s)),d=Ft.$getSelection(),pde(t,e,n._selection,d)})})};gu.syncYjsChangesToLexical=function(t,e,n,i){let r=t.editor,s=r._editorState;r.update(()=>{for(var o=r._pendingEditorState,a=0;a<n.length;a++){var l=t,u=n[a],{target:d}=u;if(d=B9(l,d),d instanceof Ma&&u instanceof _i.YTextEvent){let{keysChanged:p,childListChanged:h,delta:g}=u;0<p.size&&d.syncPropertiesFromYjs(l,p),h&&(d.applyChildrenYjsDelta(l,g),d.syncChildrenFromYjs(l))}else d instanceof vo&&u instanceof _i.YMapEvent?({keysChanged:u}=u,0<u.size&&d.syncPropertiesAndTextFromYjs(l,u)):d instanceof Nf&&u instanceof _i.YXmlEvent?({attributesChanged:u}=u,0<u.size&&d.syncPropertiesFromYjs(l,u)):Xr(82)}if(a=Ft.$getSelection(),Ft.$isRangeSelection(a))if(ZK(a)){if(l=s._selection,Ft.$isRangeSelection(l)){d=KK.$createOffsetView(r,0,s),o=KK.$createOffsetView(r,0,o);let[p,h]=d.getOffsetsFromSelection(l);o=o.createSelectionFromOffsets(p,h,d),o!==null?Ft.$setSelection(o):(ij(t,e),ZK(a)&&(o=Ft.$getRoot(),o.getChildrenSize()===0&&o.append(Ft.$createParagraphNode()),Ft.$getRoot().selectEnd()))}pde(t,e,l,Ft.$getSelection())}else ij(t,e)},{onUpdate:()=>{fde(t,e)},skipTransforms:!0,tag:i?"historic":"collaboration"})};const t2t=gu;var n2t=t2t,i2t=hxt,r2t=Qt,$s=U,hde=Fn,Pc=n2t,Co=J,s2t=K_,o2t=rde;function a2t(t,e,n,i,r,s,o,a,l){let u=$s.useRef(!1),[d,p]=$s.useState(i.get(e)),h=$s.useMemo(()=>Pc.createBinding(t,n,e,d,i),[t,n,e,i,d]),g=$s.useCallback(()=>{n.connect()},[n]),y=$s.useCallback(()=>{try{n.disconnect()}catch{}},[n]);$s.useEffect(()=>{let{root:b}=h,{awareness:w}=n,T=({status:q})=>{t.dispatchCommand(Pc.CONNECTED_COMMAND,q==="connected")},x=q=>{o&&q&&b.isEmpty()&&b._xmlText._length===0&&u.current===!1&&u2t(t,l),u.current=!1},R=()=>{Pc.syncCursorPositions(h,n)},A=(q,H)=>{H=H.origin,H!==h&&Pc.syncYjsChangesToLexical(h,n,q,H instanceof o2t.UndoManager)};Pc.initLocalState(n,r,s,document.activeElement===t.getRootElement());let L=q=>{d2t(t,h),p(q),i.set(e,q),u.current=!0};n.on("reload",L),n.on("status",T),n.on("sync",x),w.on("update",R),b.getSharedType().observeDeep(A);let F=t.registerUpdateListener(({prevEditorState:q,editorState:H,dirtyLeaves:Z,dirtyElements:Y,normalizedNodes:G,tags:ie})=>{ie.has("skip-collab")===!1&&Pc.syncLexicalUpdateToYjs(h,n,q,H,Y,Z,G,ie)});return g(),()=>{u.current===!1&&y(),n.off("sync",x),n.off("status",T),n.off("reload",L),w.off("update",R),b.getSharedType().unobserveDeep(A),i.delete(e),F()}},[h,s,g,y,i,t,e,l,r,n,o]);let O=$s.useMemo(()=>s2t.createPortal($s.createElement("div",{ref:b=>{h.cursorsContainer=b}}),a&&a.current||document.body),[h,a]);return $s.useEffect(()=>t.registerCommand(Pc.TOGGLE_CONNECT_COMMAND,b=>(g!==void 0&&y!==void 0&&(b?(console.log("Collaboration connected!"),g()):(console.log("Collaboration disconnected!"),y())),!0),Co.COMMAND_PRIORITY_EDITOR),[g,y,t]),[O,h]}function l2t(t,e,n,i){$s.useEffect(()=>hde.mergeRegister(t.registerCommand(Co.FOCUS_COMMAND,()=>(Pc.setLocalStateFocus(e,n,i,!0),!1),Co.COMMAND_PRIORITY_EDITOR),t.registerCommand(Co.BLUR_COMMAND,()=>(Pc.setLocalStateFocus(e,n,i,!1),!1),Co.COMMAND_PRIORITY_EDITOR)),[i,t,n,e])}function c2t(t,e){let n=$s.useMemo(()=>Pc.createUndoManager(e,e.root.getSharedType()),[e]);return $s.useEffect(()=>hde.mergeRegister(t.registerCommand(Co.UNDO_COMMAND,()=>(n.undo(),!0),Co.COMMAND_PRIORITY_EDITOR),t.registerCommand(Co.REDO_COMMAND,()=>(n.redo(),!0),Co.COMMAND_PRIORITY_EDITOR))),$s.useCallback(()=>{n.clear()},[n])}function u2t(t,e){t.update(()=>{var n=Co.$getRoot();if(n.isEmpty())if(e)switch(typeof e){case"string":var i=t.parseEditorState(e);t.setEditorState(i,{tag:"history-merge"});break;case"object":t.setEditorState(e,{tag:"history-merge"});break;case"function":t.update(()=>{Co.$getRoot().isEmpty()&&e(t)},{tag:"history-merge"})}else i=Co.$createParagraphNode(),n.append(i),{activeElement:n}=document,(Co.$getSelection()!==null||n!==null&&n===t.getRootElement())&&i.select()},{tag:"history-merge"})}function d2t(t,e){if(t.update(()=>{let i=Co.$getRoot();i.clear(),i.select()},{tag:"skip-collab"}),e.cursors!=null&&(t=e.cursors,t!=null&&(e=e.cursorsContainer,e!=null))){t=Array.from(t.values());for(let i=0;i<t.length;i++){var n=t[i].selection;if(n&&n.selections!=null){n=n.selections;for(let r=0;r<n.length;r++)e.removeChild(n[i])}}}}Bce.CollaborationPlugin=function({id:t,providerFactory:e,shouldBootstrap:n,username:i,cursorColor:r,cursorsContainerRef:s,initialEditorState:o}){let a=i2t.useCollaborationContext(i,r),{yjsDocMap:l,name:u,color:d}=a,[p]=r2t.useLexicalComposerContext();$s.useEffect(()=>(a.isCollabActive=!0,()=>{p._parentEditor==null&&(a.isCollabActive=!1)}),[a,p]),i=$s.useMemo(()=>e(t,l),[t,e,l]);let[h,g]=a2t(p,t,i,l,u,d,n,s,o);return a.clientID=g.clientID,c2t(p,g),l2t(p,i,u,d),h};const f2t=Bce;var p2t=f2t;const mde=new Map;class h2t{constructor(e){this.room=e,this.onmessage=null,Rxt(n=>n.key===e&&this.onmessage!==null&&this.onmessage({data:tRt(n.newValue||"")}))}postMessage(e){zce.setItem(this.room,eRt(Xxt(e)))}}const m2t=typeof BroadcastChannel>"u"?h2t:BroadcastChannel,q9=t=>Md(mde,t,()=>{const e=xm(),n=new m2t(t);return n.onmessage=i=>e.forEach(r=>r(i.data,"broadcastchannel")),{bc:n,subs:e}}),g2t=(t,e)=>(q9(t).subs.add(e),e),_2t=(t,e)=>{const n=q9(t),i=n.subs.delete(e);return i&&n.subs.size===0&&(n.bc.close(),mde.delete(t)),i},n_=(t,e,n=null)=>{const i=q9(t);i.bc.postMessage(e),i.subs.forEach(r=>r(e,n))},gde=0,Y9=1,_de=2,k$=(t,e)=>{lt(t,gde);const n=oue(e);Ji(t,n)},vde=(t,e,n)=>{lt(t,Y9),Ji(t,rue(e,n))},v2t=(t,e,n)=>vde(e,n,gs(t)),Sde=(t,e,n)=>{try{nue(e,gs(t),n)}catch(i){console.error("Caught error while handling a Yjs update",i)}},S2t=(t,e)=>{lt(t,_de),Ji(t,e)},y2t=Sde,E2t=(t,e,n,i)=>{const r=Gt(t);switch(r){case gde:v2t(t,e,n);break;case Y9:Sde(t,n,i);break;case _de:y2t(t,n,i);break;default:throw new Error("Unknown message type")}return r},b2t=0,O2t=(t,e,n)=>{switch(Gt(t)){case b2t:n(e,md(t))}},VL=3e4;class w2t extends CE{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const n=wp();this.getLocalState()!==null&&VL/2<=n-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const i=[];this.meta.forEach((r,s)=>{s!==this.clientID&&VL<=n-r.lastUpdated&&this.states.has(s)&&i.push(s)}),i.length>0&&z9(this,i,"timeout")},Cd(VL/10)),e.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){const n=this.clientID,i=this.meta.get(n),r=i===void 0?0:i.clock+1,s=this.states.get(n);e===null?this.states.delete(n):this.states.set(n,e),this.meta.set(n,{clock:r,lastUpdated:wp()});const o=[],a=[],l=[],u=[];e===null?u.push(n):s==null?e!=null&&o.push(n):(a.push(n),RS(s,e)||l.push(n)),(o.length>0||l.length>0||u.length>0)&&this.emit("change",[{added:o,updated:l,removed:u},"local"]),this.emit("update",[{added:o,updated:a,removed:u},"local"])}setLocalStateField(e,n){const i=this.getLocalState();i!==null&&this.setLocalState({...i,[e]:n})}getStates(){return this.states}}const z9=(t,e,n)=>{const i=[];for(let r=0;r<e.length;r++){const s=e[r];if(t.states.has(s)){if(t.states.delete(s),s===t.clientID){const o=t.meta.get(s);t.meta.set(s,{clock:o.clock+1,lastUpdated:wp()})}i.push(s)}}i.length>0&&(t.emit("change",[{added:[],updated:[],removed:i},n]),t.emit("update",[{added:[],updated:[],removed:i},n]))},AS=(t,e,n=t.states)=>{const i=e.length,r=Dr();lt(r,i);for(let s=0;s<i;s++){const o=e[s],a=n.get(o)||null,l=t.meta.get(o).clock;lt(r,o),lt(r,l),lp(r,JSON.stringify(a))}return fi(r)},T2t=(t,e,n)=>{const i=ls(e),r=wp(),s=[],o=[],a=[],l=[],u=Gt(i);for(let d=0;d<u;d++){const p=Gt(i);let h=Gt(i);const g=JSON.parse(md(i)),y=t.meta.get(p),O=t.states.get(p),b=y===void 0?0:y.clock;(b<h||b===h&&g===null&&t.states.has(p))&&(g===null?p===t.clientID&&t.getLocalState()!=null?h++:t.states.delete(p):t.states.set(p,g),t.meta.set(p,{clock:h,lastUpdated:r}),y===void 0&&g!==null?s.push(p):y!==void 0&&g===null?l.push(p):g!==null&&(RS(g,O)||a.push(p),o.push(p)))}(s.length>0||a.length>0||l.length>0)&&t.emit("change",[{added:s,updated:a,removed:l},n]),(s.length>0||o.length>0||l.length>0)&&t.emit("update",[{added:s,updated:o,removed:l},n])},C2t=t=>Axt(t,(e,n)=>`${encodeURIComponent(n)}=${encodeURIComponent(e)}`).join("&"),em=0,yde=3,W_=1,k2t=2,IE=[];IE[em]=(t,e,n,i,r)=>{lt(t,em);const s=E2t(e,t,n.doc,n);i&&s===Y9&&!n.synced&&(n.synced=!0)};IE[yde]=(t,e,n,i,r)=>{lt(t,W_),Ji(t,AS(n.awareness,Array.from(n.awareness.getStates().keys())))};IE[W_]=(t,e,n,i,r)=>{T2t(n.awareness,gs(e),n)};IE[k2t]=(t,e,n,i,r)=>{O2t(e,n.doc,(s,o)=>x2t(n,o))};const sj=3e4,x2t=(t,e)=>console.warn(`Permission denied to access ${t.url}.
|
|
1115
1115
|
${e}`),Ede=(t,e,n)=>{const i=ls(e),r=Dr(),s=Gt(i),o=t.messageHandlers[s];return o?o(r,i,t,n,s):console.error("Unable to compute message"),r},bde=t=>{if(t.shouldConnect&&t.ws===null){const e=new t._WS(t.url);e.binaryType="arraybuffer",t.ws=e,t.wsconnecting=!0,t.wsconnected=!1,t.synced=!1,e.onmessage=n=>{t.wsLastMessageReceived=wp();const i=Ede(t,new Uint8Array(n.data),!0);m9(i)>1&&e.send(fi(i))},e.onerror=n=>{t.emit("connection-error",[n,t])},e.onclose=n=>{t.emit("connection-close",[n,t]),t.ws=null,t.wsconnecting=!1,t.wsconnected?(t.wsconnected=!1,t.synced=!1,z9(t.awareness,Array.from(t.awareness.getStates().keys()).filter(i=>i!==t.doc.clientID),t),t.emit("status",[{status:"disconnected"}])):t.wsUnsuccessfulReconnects++,setTimeout(bde,d9(Sxt(2,t.wsUnsuccessfulReconnects)*100,t.maxBackoffTime),t)},e.onopen=()=>{t.wsLastMessageReceived=wp(),t.wsconnecting=!1,t.wsconnected=!0,t.wsUnsuccessfulReconnects=0,t.emit("status",[{status:"connected"}]);const n=Dr();if(lt(n,em),k$(n,t.doc),e.send(fi(n)),t.awareness.getLocalState()!==null){const i=Dr();lt(i,W_),Ji(i,AS(t.awareness,[t.doc.clientID])),e.send(fi(i))}},t.emit("status",[{status:"connecting"}])}},XL=(t,e)=>{const n=t.ws;t.wsconnected&&n&&n.readyState===n.OPEN&&n.send(e),t.bcconnected&&n_(t.bcChannel,e,t)};class R2t extends CE{constructor(e,n,i,{connect:r=!0,awareness:s=new w2t(i),params:o={},WebSocketPolyfill:a=WebSocket,resyncInterval:l=-1,maxBackoffTime:u=2500,disableBc:d=!1}={}){for(super();e[e.length-1]==="/";)e=e.slice(0,e.length-1);const p=C2t(o);this.maxBackoffTime=u,this.bcChannel=e+"/"+n,this.url=e+"/"+n+(p.length===0?"":"?"+p),this.roomname=n,this.doc=i,this._WS=a,this.awareness=s,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=d,this.wsUnsuccessfulReconnects=0,this.messageHandlers=IE.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=r,this._resyncInterval=0,l>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const h=Dr();lt(h,em),k$(h,i),this.ws.send(fi(h))}},l)),this._bcSubscriber=(h,g)=>{if(g!==this){const y=Ede(this,new Uint8Array(h),!1);m9(y)>1&&n_(this.bcChannel,fi(y),this)}},this._updateHandler=(h,g)=>{if(g!==this){const y=Dr();lt(y,em),S2t(y,h),XL(this,fi(y))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:h,updated:g,removed:y},O)=>{const b=h.concat(g).concat(y),w=Dr();lt(w,W_),Ji(w,AS(s,b)),XL(this,fi(w))},this._unloadHandler=()=>{z9(this.awareness,[i.clientID],"window unload")},typeof window<"u"?window.addEventListener("unload",this._unloadHandler):typeof process<"u"&&process.on("exit",this._unloadHandler),s.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&sj<wp()-this.wsLastMessageReceived&&this.ws.close()},sj/10),r&&this.connect()}get synced(){return this._synced}set synced(e){this._synced!==e&&(this._synced=e,this.emit("synced",[e]),this.emit("sync",[e]))}destroy(){this._resyncInterval!==0&&clearInterval(this._resyncInterval),clearInterval(this._checkInterval),this.disconnect(),typeof window<"u"?window.removeEventListener("unload",this._unloadHandler):typeof process<"u"&&process.off("exit",this._unloadHandler),this.awareness.off("update",this._awarenessUpdateHandler),this.doc.off("update",this._updateHandler),super.destroy()}connectBc(){if(this.disableBc)return;this.bcconnected||(g2t(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const e=Dr();lt(e,em),k$(e,this.doc),n_(this.bcChannel,fi(e),this);const n=Dr();lt(n,em),vde(n,this.doc),n_(this.bcChannel,fi(n),this);const i=Dr();lt(i,yde),n_(this.bcChannel,fi(i),this);const r=Dr();lt(r,W_),Ji(r,AS(this.awareness,[this.doc.clientID])),n_(this.bcChannel,fi(r),this)}disconnectBc(){const e=Dr();lt(e,W_),Ji(e,AS(this.awareness,[this.doc.clientID],new Map)),XL(this,fi(e)),this.bcconnected&&(_2t(this.bcChannel,this._bcSubscriber),this.bcconnected=!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&this.ws.close()}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(bde(this),this.connectBc())}}const N2t=new URL(window.location.href),Ode=new URLSearchParams(N2t.search),A2t=Ode.get("multiplayerEndpoint")||"ws://localhost:1234",I2t="demo",D2t=Ode.get("multiplayerId")||"0";function M2t(t,e){let n=e.get(t);n===void 0?(n=new Pp,e.set(t,n)):n.load();const i=new R2t(A2t,I2t+"/"+D2t+"/"+t,n,{connect:!1});return i.on("status",r=>{console.log(r.status)}),i}const L2t="v1",P2t="8672af113b0a8573edae3aa3713886265d9bb741d707f6c01a486cde8c278980",W9={Authorization:`Client-ID ${P2t}`,"Accept-Version":L2t,"Content-Type":"application/json","App-Pragma":"no-cache","X-Unsplash-Cache":!0},DR={image:{mimeTypes:["image/gif","image/jpg","image/jpeg","image/png","image/svg+xml","image/webp"],extensions:["gif","jpg","jpeg","png","svg","svgz","webp"]},video:{mimeTypes:["video/mp4","video/webm","video/ogg"],extensions:["mp4","webm","ogv"]},audio:{mimeTypes:["audio/mp3","audio/mpeg","audio/ogg","audio/wav","audio/vnd.wav","audio/wave","audio/x-wav","audio/mp4","audio/x-m4a"],extensions:["mp3","wav","ogg","m4a"]},mediaThumbnail:{mimeTypes:["image/gif","image/jpg","image/jpeg","image/png","image/webp"],extensions:["gif","jpg","jpeg","png","webp"]}};function H9({isMultiplayer:t=!1}={}){return function(n=""){const[i,r]=U.useState(100),[s,o]=U.useState(!1),[a,l]=U.useState([]),[u,d]=U.useState(0);function p(y){let O=DR[n].extensions,[,b]=/(?:\.([^.]+))?$/.exec(y.name);return O?(Array.isArray(O)||(O=O.split(",")),!b||O.indexOf(b.toLowerCase())===-1?`The file type you uploaded is not supported. Please use ${`.${O.join(", .").toUpperCase()}`}`:!0):!0}function h(y=[]){const O=[];for(let b=0;b<y.length;b+=1){let w=y[b],T=p(w);T!==!0&&O.push({fileName:w.name,message:T})}return O}async function g(y=[],O={}){d(y.length),o(!0);const b=h(y);if(b.length)return l(b),o(!1),r(100),null;let w=200;w=0,r(30),await KL(w),r(60),await KL(w),r(90),await KL(w);const T=Array.from(y).filter(R=>{var A;return(A=R.name)==null?void 0:A.includes("fail")});if(T.length)return l(T.map(R=>({fileName:R.name,message:"Upload failed"}))),o(!1),r(100),null;let x=[];if(t)for(const R of Array.from(y)){const A=new FileReader,L=await new Promise(F=>{A.addEventListener("load",()=>{F(A.result)},!1),A.readAsDataURL(R)});x.push({url:L,fileName:R.name})}else x=Array.from(y).map(R=>({url:URL.createObjectURL(R),fileName:R.name}));return r(100),o(!1),l([]),x}return{progress:i,isLoading:s,upload:g,errors:a,filesNumber:u}}}function KL(t){return new Promise(e=>{setTimeout(e,t)})}const $2t=window.parent!==null&&window.parent.frames.right===window,F2t={unsplash:{defaultHeaders:W9}};function B2t({editorType:t}){return t==="basic"?rEe:t==="minimal"?lEe:oEe}function U2t({editorType:t}){if(t==="basic")return Fce;if(t==="minimal")return c9}function G2t({editorType:t,isMultiplayer:e,registerAPI:n,cursorDidExitAtTop:i,darkMode:r}){return t==="basic"?I(yp,{cursorDidExitAtTop:i,markdownTransformers:wle,registerAPI:n}):t==="minimal"?I(yp,{cursorDidExitAtTop:i,markdownTransformers:K5,registerAPI:n,children:I(TE,{paragraphs:1})}):I(fxt,{cursorDidExitAtTop:i,darkMode:r,registerAPI:n,children:e?I(p2t.CollaborationPlugin,{id:"main",providerFactory:M2t,shouldBootstrap:!$2t}):null})}function hw({editorType:t,isMultiplayer:e}){const[n,i]=tEe(),[r,s]=U.useState(!1),[o,a]=U.useState("json"),l=n.get("darkMode")==="true",u=n.get("content")==="false",d=ue.useMemo(()=>JSON.stringify(B2t({editorType:t})),[t]),p=ue.useMemo(()=>u?void 0:d,[u,d]),[h,g]=U.useState(p?"Meet the Koenig editor.":""),[y,O]=U.useState(null),b=ue.useRef(null),w=ue.useRef(null);function T(q="json"){if(r&&o===q)return s(!1);a(q),s(!0)}function x(){var q;(q=b.current)==null||q.focus()}function R(q){const H=q.target.closest("[data-lexical-decorator]")!==null||q.target.hasAttribute("data-lexical-decorator"),Z=q.target.closest("[data-kg-slash-menu]")!==null||q.target.hasAttribute("data-kg-slash-menu");if(y&&!H&&!Z){let Y=y.editorInstance,{bottom:G}=Y._rootElement.getBoundingClientRect();if(q.pageY>G&&q.clientY>G){q.preventDefault();let ie=!1;Y.getEditorState().read(()=>{const V=J.$getRoot().getChildren().at(-1);J.$isDecoratorNode(V)&&(ie=!0)}),ie&&y.insertParagraphAtBottom(),y.focusEditor({position:"bottom"}),w.current.scrollTop=w.current.scrollHeight}}}function A(){l?n.delete("darkMode"):n.set("darkMode","true"),i(n)}ue.useEffect(()=>{const q=Z=>{Z.preventDefault()},H=Z=>{Z.dataTransfer.files.length>0&&(Z.preventDefault(),y==null||y.insertFiles(Array.from(Z.dataTransfer.files)))};return window.addEventListener("dragover",q),window.addEventListener("drop",H),()=>{window.removeEventListener("dragover",q),window.removeEventListener("drop",H)}},[y]);const L=!e&&!["basic","minimal"].includes(t),F=Mm();return I("div",{className:"koenig-lexical top",children:Ee(Gv,{cardConfig:F2t,darkMode:l,fileUploader:{useFileUpload:H9({isMultiplayer:e}),fileTypes:DR},initialEditorState:e?null:p,nodes:U2t({editorType:t}),children:[Ee("div",{className:`relative h-full grow ${l?"dark":""}`,children:[!e&&n!=="false"?I(qge,{defaultContent:d,searchParams:n,setSearchParams:i,setTitle:g}):null,I(Kme,{darkMode:l,toggleDarkMode:A}),I("div",{ref:w,className:"h-full overflow-auto",onClick:R,children:Ee("div",{className:"mx-auto max-w-[740px] py-[15vmin] px-6 lg:px-0",children:[L?I(lJ,{ref:b,editorAPI:y,setTitle:g,title:h}):null,I(G2t,{cursorDidExitAtTop:x,darkMode:l,editorType:t,isMultiplayer:e,registerAPI:O})]})})]}),I(u6,{editorType:t||"full"}),Ee("div",{className:"absolute z-20 flex h-full flex-col items-end sm:relative",children:[I(l6,{isOpen:r,view:o}),I(L$,{isOpen:r,onClick:T})]})]})},F.key)}const Q2t={unsplash:{defaultHeaders:W9}};function q2t(){const[t,e]=U.useState(!1),[n,i]=U.useState('<p><span>check</span> <a href="https://ghost.org/changelog/markdown/" dir="ltr"><span data-lexical-text="true">ghost.org/changelog/markdown/</span></a></p>'),[r,s]=U.useState("json"),[o]=U.useState(void 0),[a,l]=U.useState(null),u=ue.useRef(null),d=ue.useRef(null);function p(y="json"){if(t&&r===y)return e(!1);s(y),e(!0)}function h(){var y;(y=u.current)==null||y.focus()}function g(y){const O=y.target.closest("[data-lexical-decorator]")!==null||y.target.hasAttribute("data-lexical-decorator"),b=y.target.closest("[data-kg-slash-menu]")!==null||y.target.hasAttribute("data-kg-slash-menu");if(a&&!O&&!b){let w=a.editorInstance,{bottom:T}=w._rootElement.getBoundingClientRect();if(y.pageY>T&&y.clientY>T){y.preventDefault();let x=!1;w.getEditorState().read(()=>{const R=J.$getRoot().getChildren().at(-1);J.$isDecoratorNode(R)&&(x=!0)}),x&&a.insertParagraphAtBottom(),a.focusEditor({position:"bottom"}),d.current.scrollTop=d.current.scrollHeight}}}return Ee(qn,{children:[I("div",{"data-testid":"html-output",hidden:!0,children:n}),I("div",{className:"koenig-lexical top",children:Ee(Gv,{cardConfig:Q2t,fileUploader:{useFileUpload:H9,fileTypes:DR},initialEditorState:o,children:[I("div",{className:"relative h-full grow",children:I("div",{ref:d,className:"h-full overflow-auto",onClick:g,children:I("div",{className:"mx-auto max-w-[740px] py-[15vmin] px-6 lg:px-0",children:I(yp,{cursorDidExitAtTop:h,registerAPI:l,children:I(yR,{html:n,setHtml:i})})})})}),I(u6,{}),Ee("div",{className:"absolute z-20 flex h-full flex-col items-end sm:relative",children:[I(l6,{isOpen:t,view:r}),I(L$,{isOpen:t,onClick:p})]})]})})]})}var x$={},oj=K_;x$.createRoot=oj.createRoot,x$.hydrateRoot=oj.hydrateRoot;const Y2t={unsplash:{defaultHeaders:W9}};function z2t(){const{search:t}=Mm();return ue.useMemo(()=>new URLSearchParams(t),[t])}function W2t(){let t=z2t();const[e,n]=U.useState(!1),[i,r]=U.useState("json"),[s]=U.useState(void 0),[o,a]=U.useState(null),l=ue.useRef(null),u=ue.useRef(null),d=t.get("paragraphs")||1;function p(y="json"){if(e&&i===y)return n(!1);r(y),n(!0)}function h(){var y;(y=l.current)==null||y.focus()}function g(y){const O=y.target.closest("[data-lexical-decorator]")!==null||y.target.hasAttribute("data-lexical-decorator"),b=y.target.closest("[data-kg-slash-menu]")!==null||y.target.hasAttribute("data-kg-slash-menu");if(o&&!O&&!b){let w=o.editorInstance,{bottom:T}=w._rootElement.getBoundingClientRect();if(y.pageY>T&&y.clientY>T){y.preventDefault();let x=!1;w.getEditorState().read(()=>{const R=J.$getRoot().getChildren().at(-1);J.$isDecoratorNode(R)&&(x=!0)}),x&&o.insertParagraphAtBottom(),o.focusEditor({position:"bottom"}),u.current.scrollTop=u.current.scrollHeight}}}return I("div",{className:"koenig-lexical top",children:Ee(Gv,{cardConfig:Y2t,fileUploader:{useFileUpload:H9,fileTypes:DR},initialEditorState:s,children:[I("div",{className:"relative h-full grow",children:I("div",{ref:u,className:"h-full overflow-auto",onClick:g,children:I("div",{className:"mx-auto max-w-[740px] py-[15vmin] px-6 lg:px-0",children:I(yp,{cursorDidExitAtTop:h,registerAPI:a,children:I(TE,{paragraphs:d})})})})}),I(u6,{}),Ee("div",{className:"absolute z-20 flex h-full flex-col items-end sm:relative",children:[I(l6,{isOpen:e,view:i}),I(L$,{isOpen:e,onClick:p})]})]})})}x$.createRoot(document.getElementById("root")).render(I(ue.StrictMode,{children:I(Kye,{children:Ee(Yye,{children:[I(Ef,{element:I(xEe,{}),path:"/designsandbox"}),I(Ef,{element:I(W2t,{paragraphs:1}),path:"/contentrestricted"}),I(Ef,{element:I(q2t,{}),path:"/html-output"}),I(Ef,{element:I(hw,{introContent:!0}),path:"/"}),I(Ef,{element:I(hw,{editorType:"basic",introContent:!0}),path:"/basic"}),I(Ef,{element:I(hw,{editorType:"minimal",introContent:!0}),path:"/minimal"}),I(Ef,{element:I(hw,{introContent:!0,isMultiplayer:!0}),path:"/multiplayer"})]})})}));
|
|
1116
|
-
//# sourceMappingURL=main-
|
|
1116
|
+
//# sourceMappingURL=main-a7ddd9d1.js.map
|