"use strict";var meshagent=(()=>{var Ri=Object.create;var ue=Object.defineProperty;var Bi=Object.getOwnPropertyDescriptor;var Fi=Object.getOwnPropertyNames;var Yi=Object.getPrototypeOf,Xi=Object.prototype.hasOwnProperty;var ji=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),zi=(n,t)=>{for(var e in t)ue(n,e,{get:t[e],enumerable:!0})},Qn=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Fi(t))!Xi.call(n,i)&&i!==e&&ue(n,i,{get:()=>t[i],enumerable:!(r=Bi(t,i))||r.enumerable});return n};var tr=(n,t,e)=>(e=n!=null?Ri(Yi(n)):{},Qn(t||!n||!n.__esModule?ue(e,"default",{value:n,enumerable:!0}):e,n)),Gi=n=>Qn(ue({},"__esModule",{value:!0}),n);var Kn=ji((qe,de)=>{(function(n){var t=typeof qe=="object"&&qe,e=typeof de=="object"&&de&&de.exports==t&&de,r=typeof window=="object"&&window;(r.global===r||r.window===r)&&(n=r);var i=function(u){this.message=u};i.prototype=new Error,i.prototype.name="InvalidCharacterError";var s=function(u){throw new i(u)},o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",c=/[\t\n\f\r ]/g,l=function(u){u=String(u).replace(c,"");var f=u.length;f%4==0&&(u=u.replace(/==?$/,""),f=u.length),(f%4==1||/[^+a-zA-Z0-9/]/.test(u))&&s("Invalid character: the string to be decoded is not correctly encoded.");for(var g=0,p,x,b="",tt=-1;++tt<f;)x=o.indexOf(u.charAt(tt)),p=g%4?p*64+x:x,g++%4&&(b+=String.fromCharCode(255&p>>(-2*g&6)));return b},h=function(u){u=String(u),/[^\0-\xFF]/.test(u)&&s("The string to be encoded contains characters outside of the Latin1 range.");for(var f=u.length%3,g="",p=-1,x,b,tt,I,Mi=u.length-f;++p<Mi;)x=u.charCodeAt(p)<<16,b=u.charCodeAt(++p)<<8,tt=u.charCodeAt(++p),I=x+b+tt,g+=o.charAt(I>>18&63)+o.charAt(I>>12&63)+o.charAt(I>>6&63)+o.charAt(I&63);return f==2?(x=u.charCodeAt(p)<<8,b=u.charCodeAt(++p),I=x+b,g+=o.charAt(I>>10)+o.charAt(I>>4&63)+o.charAt(I<<2&63)+"="):f==1&&(I=u.charCodeAt(p),g+=o.charAt(I>>2)+o.charAt(I<<4&63)+"=="),g},a={encode:h,decode:l,version:"1.0.0"};if(typeof define=="function"&&typeof define.amd=="object"&&define.amd)define(function(){return a});else if(t&&!t.nodeType)if(e)e.exports=a;else for(var d in a)a.hasOwnProperty(d)&&(t[d]=a[d]);else n.base64=a})(qe)});var cc={};zi(cc,{ServerXmlDocument:()=>Rt,applyBackendChanges:()=>ic,applyChanges:()=>ec,base64ToUint8Array:()=>tc,getState:()=>nc,getStateVector:()=>rc,registerDocument:()=>sc,uint8ArrayToBase64:()=>We,unregisterDocument:()=>oc});var v=()=>new Map,fe=n=>{let t=v();return n.forEach((e,r)=>{t.set(r,e)}),t},j=(n,t,e)=>{let r=n.get(t);return r===void 0&&n.set(t,r=e()),r},er=(n,t)=>{let e=[];for(let[r,i]of n)e.push(t(i,r));return e},nr=(n,t)=>{for(let[e,r]of n)if(t(r,e))return!0;return!1};var P=()=>new Set;var ge=n=>n[n.length-1];var rr=(n,t)=>{for(let e=0;e<t.length;e++)n.push(t[e])},z=Array.from;var ir=(n,t)=>{for(let e=0;e<n.length;e++)if(t(n[e],e,n))return!0;return!1};var Ft=Array.isArray;var Yt=class{constructor(){this._observers=v()}on(t,e){return j(this._observers,t,P).add(e),e}once(t,e){let r=(...i)=>{this.off(t,r),e(...i)};this.on(t,r)}off(t,e){let r=this._observers.get(t);r!==void 0&&(r.delete(e),r.size===0&&this._observers.delete(t))}emit(t,e){return z((this._observers.get(t)||v()).values()).forEach(r=>r(...e))}destroy(){this._observers=v()}};var R=Math.floor;var bt=Math.abs;var pe=(n,t)=>n<t?n:t,K=(n,t)=>n>t?n:t,hc=Number.isNaN;var me=n=>n!==0?n<0:1/n<0;var tn=Number.MAX_SAFE_INTEGER,dc=Number.MIN_SAFE_INTEGER,uc=1<<31;var sr=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&R(n)===n),fc=Number.isNaN,gc=Number.parseInt;var $i=String.fromCharCode,pc=String.fromCodePoint,mc=$i(65535),Hi=n=>n.toLowerCase(),Ji=/^\s*/g,qi=n=>n.replace(Ji,""),Pi=/([A-Z])/g,en=(n,t)=>qi(n.replace(Pi,e=>`${t}${Hi(e)}`));var Ki=n=>{let t=unescape(encodeURIComponent(n)),e=t.length,r=new Uint8Array(e);for(let i=0;i<e;i++)r[i]=t.codePointAt(i);return r},Et=typeof TextEncoder<"u"?new TextEncoder:null,Wi=n=>Et.encode(n),cr=Et?Wi:Ki;var kt=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});kt&&kt.decode(new Uint8Array).length===1&&(kt=null);var at=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},jt=()=>new at;var Zi=n=>{let t=n.cpos;for(let e=0;e<n.bufs.length;e++)t+=n.bufs[e].length;return t};var F=n=>{let t=new Uint8Array(Zi(n)),e=0;for(let r=0;r<n.bufs.length;r++){let i=n.bufs[r];t.set(i,e),e+=i.length}return t.set(new Uint8Array(n.cbuf.buffer,0,n.cpos),e),t},Qi=(n,t)=>{let e=n.cbuf.length;e-n.cpos<t&&(n.bufs.push(new Uint8Array(n.cbuf.buffer,0,n.cpos)),n.cbuf=new Uint8Array(K(e,t)*2),n.cpos=0)},A=(n,t)=>{let e=n.cbuf.length;n.cpos===e&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(e*2),n.cpos=0),n.cbuf[n.cpos++]=t};var xe=A;var y=(n,t)=>{for(;t>127;)A(n,128|127&t),t=R(t/128);A(n,127&t)},be=(n,t)=>{let e=me(t);for(e&&(t=-t),A(n,(t>63?128:0)|(e?64:0)|63&t),t=R(t/64);t>0;)A(n,(t>127?128:0)|127&t),t=R(t/128)},rn=new Uint8Array(3e4),ts=rn.length/3,es=(n,t)=>{if(t.length<ts){let e=Et.encodeInto(t,rn).written||0;y(n,e);for(let r=0;r<e;r++)A(n,rn[r])}else N(n,cr(t))},ns=(n,t)=>{let e=unescape(encodeURIComponent(t)),r=e.length;y(n,r);for(let i=0;i<r;i++)A(n,e.codePointAt(i))},ht=Et&&Et.encodeInto?es:ns;var zt=(n,t)=>{let e=n.cbuf.length,r=n.cpos,i=pe(e-r,t.length),s=t.length-i;n.cbuf.set(t.subarray(0,i),r),n.cpos+=i,s>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(K(e*2,s)),n.cbuf.set(t.subarray(i)),n.cpos=s)},N=(n,t)=>{y(n,t.byteLength),zt(n,t)},sn=(n,t)=>{Qi(n,t);let e=new DataView(n.cbuf.buffer,n.cpos,t);return n.cpos+=t,e},rs=(n,t)=>sn(n,4).setFloat32(0,t,!1),is=(n,t)=>sn(n,8).setFloat64(0,t,!1),ss=(n,t)=>sn(n,8).setBigInt64(0,t,!1);var ar=new DataView(new ArrayBuffer(4)),os=n=>(ar.setFloat32(0,n),ar.getFloat32(0)===n),Ct=(n,t)=>{switch(typeof t){case"string":A(n,119),ht(n,t);break;case"number":sr(t)&&bt(t)<=2147483647?(A(n,125),be(n,t)):os(t)?(A(n,124),rs(n,t)):(A(n,123),is(n,t));break;case"bigint":A(n,122),ss(n,t);break;case"object":if(t===null)A(n,126);else if(Ft(t)){A(n,117),y(n,t.length);for(let e=0;e<t.length;e++)Ct(n,t[e])}else if(t instanceof Uint8Array)A(n,116),N(n,t);else{A(n,118);let e=Object.keys(t);y(n,e.length);for(let r=0;r<e.length;r++){let i=e[r];ht(n,i),Ct(n,t[i])}}break;case"boolean":A(n,t?120:121);break;default:A(n,127)}},Xt=class extends at{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&y(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}};var hr=n=>{n.count>0&&(be(n.encoder,n.count===1?n.s:-n.s),n.count>1&&y(n.encoder,n.count-2))},dt=class{constructor(){this.encoder=new at,this.s=0,this.count=0}write(t){this.s===t?this.count++:(hr(this),this.count=1,this.s=t)}toUint8Array(){return hr(this),F(this.encoder)}};var dr=n=>{if(n.count>0){let t=n.diff*2+(n.count===1?0:1);be(n.encoder,t),n.count>1&&y(n.encoder,n.count-2)}},_t=class{constructor(){this.encoder=new at,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(dr(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return dr(this),F(this.encoder)}},ye=class{constructor(){this.sarr=[],this.s="",this.lensE=new dt}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){let t=new at;return this.sarr.push(this.s),this.s="",ht(t,this.sarr.join("")),zt(t,this.lensE.toUint8Array()),F(t)}};var G=n=>new Error(n),Y=()=>{throw G("Method unimplemented")},X=()=>{throw G("Unexpected case")};var fr=G("Unexpected end of array"),gr=G("Integer out of Range"),Ut=class{constructor(t){this.arr=t,this.pos=0}},pt=n=>new Ut(n),pr=n=>n.pos!==n.arr.length;var ls=(n,t)=>{let e=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,t);return n.pos+=t,e},V=n=>ls(n,m(n));var ut=n=>n.arr[n.pos++];var m=n=>{let t=0,e=1,r=n.arr.length;for(;n.pos<r;){let i=n.arr[n.pos++];if(t=t+(i&127)*e,e*=128,i<128)return t;if(t>tn)throw gr}throw fr},Ee=n=>{let t=n.arr[n.pos++],e=t&63,r=64,i=(t&64)>0?-1:1;if((t&128)===0)return i*e;let s=n.arr.length;for(;n.pos<s;){if(t=n.arr[n.pos++],e=e+(t&127)*r,r*=128,t<128)return i*e;if(e>tn)throw gr}throw fr};var as=n=>{let t=m(n);if(t===0)return"";{let e=String.fromCodePoint(ut(n));if(--t<100)for(;t--;)e+=String.fromCodePoint(ut(n));else for(;t>0;){let r=t<1e4?t:1e4,i=n.arr.subarray(n.pos,n.pos+r);n.pos+=r,e+=String.fromCodePoint.apply(null,i),t-=r}return decodeURIComponent(escape(e))}},hs=n=>kt.decode(V(n)),ft=kt?hs:as;var on=(n,t)=>{let e=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,t);return n.pos+=t,e},ds=n=>on(n,4).getFloat32(0,!1),us=n=>on(n,8).getFloat64(0,!1),fs=n=>on(n,8).getBigInt64(0,!1);var gs=[n=>{},n=>null,Ee,ds,us,fs,n=>!1,n=>!0,ft,n=>{let t=m(n),e={};for(let r=0;r<t;r++){let i=ft(n);e[i]=At(n)}return e},n=>{let t=m(n),e=[];for(let r=0;r<t;r++)e.push(At(n));return e},V],At=n=>gs[127-ut(n)](n),Gt=class extends Ut{constructor(t,e){super(t),this.reader=e,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),pr(this)?this.count=m(this)+1:this.count=-1),this.count--,this.s}};var gt=class extends Ut{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Ee(this);let t=me(this.s);this.count=1,t&&(this.s=-this.s,this.count=m(this)+2)}return this.count--,this.s}};var Dt=class extends Ut{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let t=Ee(this),e=t&1;this.diff=R(t/2),this.count=1,e&&(this.count=m(this)+2)}return this.s+=this.diff,this.count--,this.s}},ke=class{constructor(t){this.decoder=new gt(t),this.str=ft(this.decoder),this.spos=0}read(){let t=this.spos+this.decoder.read(),e=this.str.slice(this.spos,t);return this.spos=t,e}};var xc=crypto.subtle,mr=crypto.getRandomValues.bind(crypto);var cn=()=>mr(new Uint32Array(1))[0];var ms="10000000-1000-4000-8000"+-1e11,wr=()=>ms.replace(/[018]/g,n=>(n^cn()&15>>n/4).toString(16));var Se=Date.now;var ln=n=>new Promise(n);var Ec=Promise.all.bind(Promise);var an=n=>n===void 0?null:n;var hn=class{constructor(){this.map=new Map}setItem(t,e){this.map.set(t,e)}getItem(t){return this.map.get(t)}},xr=new hn,bs=!0;try{typeof localStorage<"u"&&localStorage&&(xr=localStorage,bs=!1)}catch{}var br=xr;var Er=Object.assign,Es=Object.keys,Sr=(n,t)=>{for(let e in n)t(n[e],e)};var kr=n=>Es(n).length;var Cr=n=>{for(let t in n)return!1;return!0},Ss=(n,t)=>{for(let e in n)if(!t(n[e],e))return!1;return!0},Cs=(n,t)=>Object.prototype.hasOwnProperty.call(n,t),_r=(n,t)=>n===t||kr(n)===kr(t)&&Ss(n,(e,r)=>(e!==void 0||Cs(t,r))&&t[r]===e),_s=Object.freeze,dn=n=>{for(let t in n){let e=n[t];(typeof e=="object"||typeof e=="function")&&dn(n[t])}return _s(n)};var $t=(n,t,e=0)=>{try{for(;e<n.length;e++)n[e](...t)}finally{e<n.length&&$t(n,t,e+1)}};var Ur=n=>n;var Ar=(n,t)=>t.includes(n);var Ht=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]";var Sc=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,$,As=[],Ds=()=>{if($===void 0)if(Ht){$=v();let n=process.argv,t=null;for(let e=0;e<n.length;e++){let r=n[e];r[0]==="-"?(t!==null&&$.set(t,""),t=r):t!==null?($.set(t,r),t=null):As.push(r)}t!==null&&$.set(t,"")}else typeof location=="object"?($=v(),(location.search||"?").slice(1).split("&").forEach(n=>{if(n.length!==0){let[t,e]=n.split("=");$.set(`--${en(t,"-")}`,e),$.set(`-${en(t,"-")}`,e)}})):$=v();return $},un=n=>Ds().has(n);var Jt=n=>Ht?an(Ir[n.toUpperCase().replaceAll("-","_")]):an(br.getItem(n));var Tr=n=>un("--"+n)||Jt(n)!==null,Ir=Tr("production"),Ts=Ht&&Ar(Ir.FORCE_COLOR,["true","1","2"]),vr=Ts||!un("--no-colors")&&!Tr("no-color")&&(!Ht||process.stdout.isTTY)&&(!Ht||un("--color")||Jt("COLORTERM")!==null||(Jt("TERM")||"").includes("color"));var Is=n=>new Uint8Array(n);var Vr=n=>{let t=Is(n.byteLength);return t.set(n),t};var fn=class{constructor(t,e){this.left=t,this.right=e}},H=(n,t)=>new fn(n,t);var mt=typeof document<"u"?document:{};var Cc=typeof DOMParser<"u"?new DOMParser:null;var Or=n=>er(n,(t,e)=>`${e}:${t};`).join("");var _c=mt.ELEMENT_NODE,Uc=mt.TEXT_NODE,Ac=mt.CDATA_SECTION_NODE,Dc=mt.COMMENT_NODE,Tc=mt.DOCUMENT_NODE,Ic=mt.DOCUMENT_TYPE_NODE,vc=mt.DOCUMENT_FRAGMENT_NODE;var J=Symbol;var qt=J(),Pt=J(),gn=J(),pn=J(),mn=J(),Kt=J(),wn=J(),Tt=J(),yn=J(),Lr=n=>{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let t=[],e=[],r=0;for(;r<n.length;r++){let i=n[r];if(i===void 0)break;if(i.constructor===String||i.constructor===Number)t.push(i);else if(i.constructor===Object)break}for(r>0&&e.push(t.join(""));r<n.length;r++){let i=n[r];i instanceof Symbol||e.push(i)}return e};var Nc=Se();var Ms={[qt]:H("font-weight","bold"),[Pt]:H("font-weight","normal"),[gn]:H("color","blue"),[mn]:H("color","green"),[pn]:H("color","grey"),[Kt]:H("color","red"),[wn]:H("color","purple"),[Tt]:H("color","orange"),[yn]:H("color","black")},Rs=n=>{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let t=[],e=[],r=v(),i=[],s=0;for(;s<n.length;s++){let o=n[s],c=Ms[o];if(c!==void 0)r.set(c.left,c.right);else{if(o===void 0)break;if(o.constructor===String||o.constructor===Number){let l=Or(r);s>0||l.length>0?(t.push("%c"+o),e.push(l)):t.push(o)}else break}}for(s>0&&(i=e,i.unshift(t.join("")));s<n.length;s++){let o=n[s];o instanceof Symbol||i.push(o)}return i},Mr=vr?Rs:Lr,Rr=(...n)=>{console.log(...Mr(n)),Br.forEach(t=>t.print(n))},xn=(...n)=>{console.warn(...Mr(n)),n.unshift(Tt),Br.forEach(t=>t.print(n))};var Br=P();var Fr=n=>({[Symbol.iterator](){return this},next:n}),Yr=(n,t)=>Fr(()=>{let e;do e=n.next();while(!e.done&&!t(e.value));return e}),Ce=(n,t)=>Fr(()=>{let{done:e,value:r}=n.next();return{done:e,value:e?void 0:t(r)}});var Zt=class{constructor(t,e){this.clock=t,this.len=e}},st=class{constructor(){this.clients=new Map}},vt=(n,t,e)=>t.clients.forEach((r,i)=>{let s=n.doc.store.clients.get(i);if(s!=null){let o=s[s.length-1],c=o.id.clock+o.length;for(let l=0,h=r[l];l<r.length&&h.clock<c;h=r[++l])di(n,s,h.clock,h.len,e)}}),js=(n,t)=>{let e=0,r=n.length-1;for(;e<=r;){let i=R((e+r)/2),s=n[i],o=s.clock;if(o<=t){if(t<o+s.len)return i;e=i+1}else r=i-1}return null},he=(n,t)=>{let e=n.clients.get(t.client);return e!==void 0&&js(e,t.clock)!==null},Rn=n=>{n.clients.forEach(t=>{t.sort((i,s)=>i.clock-s.clock);let e,r;for(e=1,r=1;e<t.length;e++){let i=t[r-1],s=t[e];i.clock+i.len>=s.clock?i.len=K(i.len,s.clock+s.len-i.clock):(r<e&&(t[r]=s),r++)}t.length=r})},kn=n=>{let t=new st;for(let e=0;e<n.length;e++)n[e].clients.forEach((r,i)=>{if(!t.clients.has(i)){let s=r.slice();for(let o=e+1;o<n.length;o++)rr(s,n[o].clients.get(i)||[]);t.clients.set(i,s)}});return Rn(t),t},Qt=(n,t,e,r)=>{j(n.clients,t,()=>[]).push(new Zt(e,r))},ri=()=>new st,zs=n=>{let t=ri();return n.clients.forEach((e,r)=>{let i=[];for(let s=0;s<e.length;s++){let o=e[s];if(o.deleted){let c=o.id.clock,l=o.length;if(s+1<e.length)for(let h=e[s+1];s+1<e.length&&h.deleted;h=e[++s+1])l+=h.length;i.push(new Zt(c,l))}}i.length>0&&t.clients.set(r,i)}),t},Lt=(n,t)=>{y(n.restEncoder,t.clients.size),z(t.clients.entries()).sort((e,r)=>r[0]-e[0]).forEach(([e,r])=>{n.resetDsCurVal(),y(n.restEncoder,e);let i=r.length;y(n.restEncoder,i);for(let s=0;s<i;s++){let o=r[s];n.writeDsClock(o.clock),n.writeDsLen(o.len)}})},Bn=n=>{let t=new st,e=m(n.restDecoder);for(let r=0;r<e;r++){n.resetDsCurVal();let i=m(n.restDecoder),s=m(n.restDecoder);if(s>0){let o=j(t.clients,i,()=>[]);for(let c=0;c<s;c++)o.push(new Zt(n.readDsClock(),n.readDsLen()))}}return t},zr=(n,t,e)=>{let r=new st,i=m(n.restDecoder);for(let s=0;s<i;s++){n.resetDsCurVal();let o=m(n.restDecoder),c=m(n.restDecoder),l=e.clients.get(o)||[],h=_(e,o);for(let a=0;a<c;a++){let d=n.readDsClock(),u=d+n.readDsLen();if(d<h){h<u&&Qt(r,o,h,u-h);let f=q(l,d),g=l[f];for(!g.deleted&&g.id.clock<d&&(l.splice(f+1,0,ze(t,g,d-g.id.clock)),f++);f<l.length&&(g=l[f++],g.id.clock<u);)g.deleted||(u<g.id.clock+g.length&&l.splice(f,0,ze(t,g,u-g.id.clock)),g.delete(t))}else Qt(r,o,d,u-d)}}if(r.clients.size>0){let s=new W;return y(s.restEncoder,0),Lt(s,r),s.toUint8Array()}return null};var ii=cn,ot=class n extends Yt{constructor({guid:t=wr(),collectionid:e=null,gc:r=!0,gcFilter:i=()=>!0,meta:s=null,autoLoad:o=!1,shouldLoad:c=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=ii(),this.guid=t,this.collectionid=e,this.share=new Map,this.store=new Me,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=o,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=ln(h=>{this.on("load",()=>{this.isLoaded=!0,h(this)})});let l=()=>ln(h=>{let a=d=>{(d===void 0||d===!0)&&(this.off("sync",a),h())};this.on("sync",a)});this.on("sync",h=>{h===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=h===void 0||h===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){let t=this._item;t!==null&&!this.shouldLoad&&k(t.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(z(this.subdocs).map(t=>t.guid))}transact(t,e=null){return k(this,t,e)}get(t,e=C){let r=j(this.share,t,()=>{let s=new e;return s._integrate(this,null),s}),i=r.constructor;if(e!==C&&i!==e)if(i===C){let s=new e;s._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=s}),s._start=r._start;for(let o=s._start;o!==null;o=o.right)o.parent=s;return s._length=r._length,this.share.set(t,s),s._integrate(this,null),s}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return r}getArray(t=""){return this.get(t,Xe)}getText(t=""){return this.get(t,oe)}getMap(t=""){return this.get(t,ie)}getXmlElement(t=""){return this.get(t,S)}getXmlFragment(t=""){return this.get(t,Vt)}toJSON(){let t={};return this.share.forEach((e,r)=>{t[r]=e.toJSON()}),t}destroy(){this.isDestroyed=!0,z(this.subdocs).forEach(e=>e.destroy());let t=this._item;if(t!==null){this._item=null;let e=t.content;e.doc=new n({guid:this.guid,...e.opts,shouldLoad:!1}),e.doc._item=t,k(t.parent.doc,r=>{let i=e.doc;t.deleted||r.subdocsAdded.add(i),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}},ve=class{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return m(this.restDecoder)}readDsLen(){return m(this.restDecoder)}},Ne=class extends ve{readLeftID(){return w(m(this.restDecoder),m(this.restDecoder))}readRightID(){return w(m(this.restDecoder),m(this.restDecoder))}readClient(){return m(this.restDecoder)}readInfo(){return ut(this.restDecoder)}readString(){return ft(this.restDecoder)}readParentInfo(){return m(this.restDecoder)===1}readTypeRef(){return m(this.restDecoder)}readLen(){return m(this.restDecoder)}readAny(){return At(this.restDecoder)}readBuf(){return Vr(V(this.restDecoder))}readJSON(){return JSON.parse(ft(this.restDecoder))}readKey(){return ft(this.restDecoder)}},En=class{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=m(this.restDecoder),this.dsCurrVal}readDsLen(){let t=m(this.restDecoder)+1;return this.dsCurrVal+=t,t}},ct=class extends En{constructor(t){super(t),this.keys=[],m(t),this.keyClockDecoder=new Dt(V(t)),this.clientDecoder=new gt(V(t)),this.leftClockDecoder=new Dt(V(t)),this.rightClockDecoder=new Dt(V(t)),this.infoDecoder=new Gt(V(t),ut),this.stringDecoder=new ke(V(t)),this.parentInfoDecoder=new Gt(V(t),ut),this.typeRefDecoder=new gt(V(t)),this.lenDecoder=new gt(V(t))}readLeftID(){return new it(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new it(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 At(this.restDecoder)}readBuf(){return V(this.restDecoder)}readJSON(){return At(this.restDecoder)}readKey(){let t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{let e=this.stringDecoder.read();return this.keys.push(e),e}}},Ve=class{constructor(){this.restEncoder=jt()}toUint8Array(){return F(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){y(this.restEncoder,t)}writeDsLen(t){y(this.restEncoder,t)}},wt=class extends Ve{writeLeftID(t){y(this.restEncoder,t.client),y(this.restEncoder,t.clock)}writeRightID(t){y(this.restEncoder,t.client),y(this.restEncoder,t.clock)}writeClient(t){y(this.restEncoder,t)}writeInfo(t){xe(this.restEncoder,t)}writeString(t){ht(this.restEncoder,t)}writeParentInfo(t){y(this.restEncoder,t?1:0)}writeTypeRef(t){y(this.restEncoder,t)}writeLen(t){y(this.restEncoder,t)}writeAny(t){Ct(this.restEncoder,t)}writeBuf(t){N(this.restEncoder,t)}writeJSON(t){ht(this.restEncoder,JSON.stringify(t))}writeKey(t){ht(this.restEncoder,t)}},Oe=class{constructor(){this.restEncoder=jt(),this.dsCurrVal=0}toUint8Array(){return F(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){let e=t-this.dsCurrVal;this.dsCurrVal=t,y(this.restEncoder,e)}writeDsLen(t){t===0&&X(),y(this.restEncoder,t-1),this.dsCurrVal+=t}},W=class extends Oe{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new _t,this.clientEncoder=new dt,this.leftClockEncoder=new _t,this.rightClockEncoder=new _t,this.infoEncoder=new Xt(xe),this.stringEncoder=new ye,this.parentInfoEncoder=new Xt(xe),this.typeRefEncoder=new dt,this.lenEncoder=new dt}toUint8Array(){let t=jt();return y(t,0),N(t,this.keyClockEncoder.toUint8Array()),N(t,this.clientEncoder.toUint8Array()),N(t,this.leftClockEncoder.toUint8Array()),N(t,this.rightClockEncoder.toUint8Array()),N(t,F(this.infoEncoder)),N(t,this.stringEncoder.toUint8Array()),N(t,F(this.parentInfoEncoder)),N(t,this.typeRefEncoder.toUint8Array()),N(t,this.lenEncoder.toUint8Array()),zt(t,F(this.restEncoder)),F(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){Ct(this.restEncoder,t)}writeBuf(t){N(this.restEncoder,t)}writeJSON(t){Ct(this.restEncoder,t)}writeKey(t){let e=this.keyMap.get(t);e===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(e)}},Gs=(n,t,e,r)=>{r=K(r,t[0].id.clock);let i=q(t,r);y(n.restEncoder,t.length-i),n.writeClient(e),y(n.restEncoder,r);let s=t[i];s.write(n,r-s.id.clock);for(let o=i+1;o<t.length;o++)t[o].write(n,0)},Fn=(n,t,e)=>{let r=new Map;e.forEach((i,s)=>{_(t,s)>i&&r.set(s,i)}),$e(t).forEach((i,s)=>{e.has(s)||r.set(s,0)}),y(n.restEncoder,r.size),z(r.entries()).sort((i,s)=>s[0]-i[0]).forEach(([i,s])=>{Gs(n,t.clients.get(i),i,s)})},$s=(n,t)=>{let e=v(),r=m(n.restDecoder);for(let i=0;i<r;i++){let s=m(n.restDecoder),o=new Array(s),c=n.readClient(),l=m(n.restDecoder);e.set(c,{i:0,refs:o});for(let h=0;h<s;h++){let a=n.readInfo();switch(31&a){case 0:{let d=n.readLen();o[h]=new L(w(c,l),d),l+=d;break}case 10:{let d=m(n.restDecoder);o[h]=new M(w(c,l),d),l+=d;break}default:{let d=(a&192)===0,u=new E(w(c,l),null,(a&128)===128?n.readLeftID():null,null,(a&64)===64?n.readRightID():null,d?n.readParentInfo()?t.get(n.readString()):n.readLeftID():null,d&&(a&32)===32?n.readString():null,vi(n,a));o[h]=u,l+=u.length}}}}return e},Hs=(n,t,e)=>{let r=[],i=z(e.keys()).sort((f,g)=>f-g);if(i.length===0)return null;let s=()=>{if(i.length===0)return null;let f=e.get(i[i.length-1]);for(;f.refs.length===f.i;)if(i.pop(),i.length>0)f=e.get(i[i.length-1]);else return null;return f},o=s();if(o===null)return null;let c=new Me,l=new Map,h=(f,g)=>{let p=l.get(f);(p==null||p>g)&&l.set(f,g)},a=o.refs[o.i++],d=new Map,u=()=>{for(let f of r){let g=f.id.client,p=e.get(g);p?(p.i--,c.clients.set(g,p.refs.slice(p.i)),e.delete(g),p.i=0,p.refs=[]):c.clients.set(g,[f]),i=i.filter(x=>x!==g)}r.length=0};for(;;){if(a.constructor!==M){let g=j(d,a.id.client,()=>_(t,a.id.client))-a.id.clock;if(g<0)r.push(a),h(a.id.client,a.id.clock-1),u();else{let p=a.getMissing(n,t);if(p!==null){r.push(a);let x=e.get(p)||{refs:[],i:0};if(x.refs.length===x.i)h(p,_(t,p)),u();else{a=x.refs[x.i++];continue}}else(g===0||g<a.length)&&(a.integrate(n,g),d.set(a.id.client,a.id.clock+a.length))}}if(r.length>0)a=r.pop();else if(o!==null&&o.i<o.refs.length)a=o.refs[o.i++];else{if(o=s(),o===null)break;a=o.refs[o.i++]}}if(c.clients.size>0){let f=new W;return Fn(f,c,new Map),y(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},Js=(n,t)=>Fn(n,t.doc.store,t.beforeState),qs=(n,t,e,r=new ct(n))=>k(t,i=>{i.local=!1;let s=!1,o=i.doc,c=o.store,l=$s(r,o),h=Hs(i,c,l),a=c.pendingStructs;if(a){for(let[u,f]of a.missing)if(f<_(c,u)){s=!0;break}if(h){for(let[u,f]of h.missing){let g=a.missing.get(u);(g==null||g>f)&&a.missing.set(u,f)}a.update=Be([a.update,h.update])}}else c.pendingStructs=h;let d=zr(r,i,c);if(c.pendingDs){let u=new ct(pt(c.pendingDs));m(u.restDecoder);let f=zr(u,i,c);d&&f?c.pendingDs=Be([d,f]):c.pendingDs=d||f}else c.pendingDs=d;if(s){let u=c.pendingStructs.update;c.pendingStructs=null,si(i.doc,u)}},e,!1);var si=(n,t,e,r=ct)=>{let i=pt(t);qs(i,n,e,new r(i))},Ge=(n,t,e)=>si(n,t,e,Ne),Ps=(n,t,e=new Map)=>{Fn(n,t.store,e),Lt(n,zs(t.store))},Ks=(n,t=new Uint8Array([0]),e=new W)=>{let r=oi(t);Ps(e,n,r);let i=[e.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(ao(n.store.pendingStructs.update,t)),i.length>1){if(e.constructor===wt)return co(i.map((s,o)=>o===0?s:uo(s)));if(e.constructor===W)return Be(i)}return i[0]},Yn=(n,t)=>Ks(n,t,new wt),Ws=n=>{let t=new Map,e=m(n.restDecoder);for(let r=0;r<e;r++){let i=m(n.restDecoder),s=m(n.restDecoder);t.set(i,s)}return t},oi=n=>Ws(new ve(pt(n))),ci=(n,t)=>(y(n.restEncoder,t.size),z(t.entries()).sort((e,r)=>r[0]-e[0]).forEach(([e,r])=>{y(n.restEncoder,e),y(n.restEncoder,r)}),n),Zs=(n,t)=>ci(n,$e(t.store)),Qs=(n,t=new Oe)=>(n instanceof Map?ci(t,n):Zs(t,n),t.toUint8Array()),li=n=>Qs(n,new Ve),Sn=class{constructor(){this.l=[]}},Gr=()=>new Sn,$r=(n,t)=>n.l.push(t),Hr=(n,t)=>{let e=n.l,r=e.length;n.l=e.filter(i=>t!==i),r===n.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},ai=(n,t,e)=>$t(n.l,[t,e]),it=class{constructor(t,e){this.client=t,this.clock=e}},_e=(n,t)=>n===t||n!==null&&t!==null&&n.client===t.client&&n.clock===t.clock,w=(n,t)=>new it(n,t);var to=n=>{for(let[t,e]of n.doc.share.entries())if(e===n)return t;throw X()},Le=(n,t)=>{for(;t!==null;){if(t.parent===n)return!0;t=t.parent._item}return!1};var Cn=class{constructor(t,e){this.ds=t,this.sv=e}};var eo=(n,t)=>new Cn(n,t),zc=eo(ri(),new Map);var It=(n,t)=>t===void 0?!n.deleted:t.sv.has(n.id.client)&&(t.sv.get(n.id.client)||0)>n.id.clock&&!he(t.ds,n.id),_n=(n,t)=>{let e=j(n.meta,_n,P),r=n.doc.store;e.has(t)||(t.sv.forEach((i,s)=>{i<_(r,s)&&O(n,w(s,i))}),vt(n,t.ds,i=>{}),e.add(t))};var Me=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},$e=n=>{let t=new Map;return n.clients.forEach((e,r)=>{let i=e[e.length-1];t.set(r,i.id.clock+i.length)}),t},_=(n,t)=>{let e=n.clients.get(t);if(e===void 0)return 0;let r=e[e.length-1];return r.id.clock+r.length},hi=(n,t)=>{let e=n.clients.get(t.id.client);if(e===void 0)e=[],n.clients.set(t.id.client,e);else{let r=e[e.length-1];if(r.id.clock+r.length!==t.id.clock)throw X()}e.push(t)},q=(n,t)=>{let e=0,r=n.length-1,i=n[r],s=i.id.clock;if(s===t)return r;let o=R(t/(s+i.length-1)*r);for(;e<=r;){if(i=n[o],s=i.id.clock,s<=t){if(t<s+i.length)return o;e=o+1}else r=o-1;o=R((e+r)/2)}throw X()},no=(n,t)=>{let e=n.clients.get(t.client);return e[q(e,t.clock)]},De=no,Un=(n,t,e)=>{let r=q(t,e),i=t[r];return i.id.clock<e&&i instanceof E?(t.splice(r+1,0,ze(n,i,e-i.id.clock)),r+1):r},O=(n,t)=>{let e=n.doc.store.clients.get(t.client);return e[Un(n,e,t.clock)]},Jr=(n,t,e)=>{let r=t.clients.get(e.client),i=q(r,e.clock),s=r[i];return e.clock!==s.id.clock+s.length-1&&s.constructor!==L&&r.splice(i+1,0,ze(n,s,e.clock-s.id.clock+1)),s},ro=(n,t,e)=>{let r=n.clients.get(t.id.client);r[q(r,t.id.clock)]=e},di=(n,t,e,r,i)=>{if(r===0)return;let s=e+r,o=Un(n,t,e),c;do c=t[o++],s<c.id.clock+c.length&&Un(n,t,s),i(c);while(o<t.length&&t[o].id.clock<s)},An=class{constructor(t,e,r){this.doc=t,this.deleteSet=new st,this.beforeState=$e(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=e,this.meta=new Map,this.local=r,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}},qr=(n,t)=>t.deleteSet.clients.size===0&&!nr(t.afterState,(e,r)=>t.beforeState.get(r)!==e)?!1:(Rn(t.deleteSet),Js(n,t),Lt(n,t.deleteSet),!0),Pr=(n,t,e)=>{let r=t._item;(r===null||r.id.clock<(n.beforeState.get(r.id.client)||0)&&!r.deleted)&&j(n.changed,t,P).add(e)},Te=(n,t)=>{let e=n[t],r=n[t-1],i=t;for(;i>0;e=r,r=n[--i-1]){if(r.deleted===e.deleted&&r.constructor===e.constructor&&r.mergeWith(e)){e instanceof E&&e.parentSub!==null&&e.parent._map.get(e.parentSub)===e&&e.parent._map.set(e.parentSub,r);continue}break}let s=t-i;return s&&n.splice(t+1-s,s),s},io=(n,t,e)=>{for(let[r,i]of n.clients.entries()){let s=t.clients.get(r);for(let o=i.length-1;o>=0;o--){let c=i[o],l=c.clock+c.len;for(let h=q(s,c.clock),a=s[h];h<s.length&&a.id.clock<l;a=s[++h]){let d=s[h];if(c.clock+c.len<=d.id.clock)break;d instanceof E&&d.deleted&&!d.keep&&e(d)&&d.gc(t,!1)}}}},so=(n,t)=>{n.clients.forEach((e,r)=>{let i=t.clients.get(r);for(let s=e.length-1;s>=0;s--){let o=e[s],c=pe(i.length-1,1+q(i,o.clock+o.len-1));for(let l=c,h=i[l];l>0&&h.id.clock>=o.clock;h=i[l])l-=1+Te(i,l)}})};var ui=(n,t)=>{if(t<n.length){let e=n[t],r=e.doc,i=r.store,s=e.deleteSet,o=e._mergeStructs;try{Rn(s),e.afterState=$e(e.doc.store),r.emit("beforeObserverCalls",[e,r]);let c=[];e.changed.forEach((l,h)=>c.push(()=>{(h._item===null||!h._item.deleted)&&h._callObserver(e,l)})),c.push(()=>{e.changedParentTypes.forEach((l,h)=>{h._dEH.l.length>0&&(h._item===null||!h._item.deleted)&&(l=l.filter(a=>a.target._item===null||!a.target._item.deleted),l.forEach(a=>{a.currentTarget=h,a._path=null}),l.sort((a,d)=>a.path.length-d.path.length),c.push(()=>{ai(h._dEH,l,e)}))}),c.push(()=>r.emit("afterTransaction",[e,r])),c.push(()=>{e._needFormattingCleanup&&So(e)})}),$t(c,[])}finally{r.gc&&io(s,i,r.gcFilter),so(s,i),e.afterState.forEach((a,d)=>{let u=e.beforeState.get(d)||0;if(u!==a){let f=i.clients.get(d),g=K(q(f,u),1);for(let p=f.length-1;p>=g;)p-=1+Te(f,p)}});for(let a=o.length-1;a>=0;a--){let{client:d,clock:u}=o[a].id,f=i.clients.get(d),g=q(f,u);g+1<f.length&&Te(f,g+1)>1||g>0&&Te(f,g)}if(!e.local&&e.afterState.get(r.clientID)!==e.beforeState.get(r.clientID)&&(Rr(Tt,qt,"[yjs] ",Pt,Kt,"Changed the client-id because another client seems to be using it."),r.clientID=ii()),r.emit("afterTransactionCleanup",[e,r]),r._observers.has("update")){let a=new wt;qr(a,e)&&r.emit("update",[a.toUint8Array(),e.origin,r,e])}if(r._observers.has("updateV2")){let a=new W;qr(a,e)&&r.emit("updateV2",[a.toUint8Array(),e.origin,r,e])}let{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:h}=e;(c.size>0||h.size>0||l.size>0)&&(c.forEach(a=>{a.clientID=r.clientID,a.collectionid==null&&(a.collectionid=r.collectionid),r.subdocs.add(a)}),h.forEach(a=>r.subdocs.delete(a)),r.emit("subdocs",[{loaded:l,added:c,removed:h},r,e]),h.forEach(a=>a.destroy())),n.length<=t+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,n])):ui(n,t+1)}}},k=(n,t,e=null,r=!0)=>{let i=n._transactionCleanups,s=!1,o=null;n._transaction===null&&(s=!0,n._transaction=new An(n,e,r),i.push(n._transaction),i.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{o=t(n._transaction)}finally{if(s){let c=n._transaction===i[0];n._transaction=null,c&&ui(i,0)}}return o},Dn=class{constructor(t,e){this.insertions=e,this.deletions=t,this.meta=new Map}},Kr=(n,t,e)=>{vt(n,e.deletions,r=>{r instanceof E&&t.scope.some(i=>i===n.doc||Le(i,r))&&$n(r,!1)})},Wr=(n,t,e)=>{let r=null,i=n.doc,s=n.scope;k(i,c=>{for(;t.length>0&&n.currStackItem===null;){let l=i.store,h=t.pop(),a=new Set,d=[],u=!1;vt(c,h.insertions,f=>{if(f instanceof E){if(f.redone!==null){let{item:g,diff:p}=qo(l,f.id);p>0&&(g=O(c,w(g.id.client,g.id.clock+p))),f=g}!f.deleted&&s.some(g=>g===c.doc||Le(g,f))&&d.push(f)}}),vt(c,h.deletions,f=>{f instanceof E&&s.some(g=>g===c.doc||Le(g,f))&&!he(h.insertions,f.id)&&a.add(f)}),a.forEach(f=>{u=Ii(c,f,a,h.insertions,n.ignoreRemoteMapChanges,n)!==null||u});for(let f=d.length-1;f>=0;f--){let g=d[f];n.deleteFilter(g)&&(g.delete(c),u=!0)}n.currStackItem=u?h:null}c.changed.forEach((l,h)=>{l.has(null)&&h._searchMarker&&(h._searchMarker.length=0)}),r=c},n);let o=n.currStackItem;if(o!=null){let c=r.changedParentTypes;n.emit("stack-item-popped",[{stackItem:o,type:e,changedParentTypes:c,origin:n},n]),n.currStackItem=null}return o},Re=class extends Yt{constructor(t,{captureTimeout:e=500,captureTransaction:r=l=>!0,deleteFilter:i=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:c=Ft(t)?t[0].doc:t instanceof ot?t:t.doc}={}){super(),this.scope=[],this.doc=c,this.addToScope(t),this.deleteFilter=i,s.add(this),this.trackedOrigins=s,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=e,this.afterTransactionHandler=l=>{if(!this.captureTransaction(l)||!this.scope.some(x=>l.changedParentTypes.has(x)||x===this.doc)||!this.trackedOrigins.has(l.origin)&&(!l.origin||!this.trackedOrigins.has(l.origin.constructor)))return;let h=this.undoing,a=this.redoing,d=h?this.redoStack:this.undoStack;h?this.stopCapturing():a||this.clear(!1,!0);let u=new st;l.afterState.forEach((x,b)=>{let tt=l.beforeState.get(b)||0,I=x-tt;I>0&&Qt(u,b,tt,I)});let f=Se(),g=!1;if(this.lastChange>0&&f-this.lastChange<this.captureTimeout&&d.length>0&&!h&&!a){let x=d[d.length-1];x.deletions=kn([x.deletions,l.deleteSet]),x.insertions=kn([x.insertions,u])}else d.push(new Dn(l.deleteSet,u)),g=!0;!h&&!a&&(this.lastChange=f),vt(l,l.deleteSet,x=>{x instanceof E&&this.scope.some(b=>b===l.doc||Le(b,x))&&$n(x,!0)});let p=[{stackItem:d[d.length-1],origin:l.origin,type:h?"redo":"undo",changedParentTypes:l.changedParentTypes},this];g?this.emit("stack-item-added",p):this.emit("stack-item-updated",p)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){let e=new Set(this.scope);t=Ft(t)?t:[t],t.forEach(r=>{e.has(r)||(e.add(r),(r instanceof C?r.doc!==this.doc:r!==this.doc)&&xn("[yjs#509] Not same Y.Doc"),this.scope.push(r))})}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,e=!0){(t&&this.canUndo()||e&&this.canRedo())&&this.doc.transact(r=>{t&&(this.undoStack.forEach(i=>Kr(r,this,i)),this.undoStack=[]),e&&(this.redoStack.forEach(i=>Kr(r,this,i)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:e}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let t;try{t=Wr(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=Wr(this,this.redoStack,"redo")}finally{this.redoing=!1}return t}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}};function*oo(n){let t=m(n.restDecoder);for(let e=0;e<t;e++){let r=m(n.restDecoder),i=n.readClient(),s=m(n.restDecoder);for(let o=0;o<r;o++){let c=n.readInfo();if(c===10){let l=m(n.restDecoder);yield new M(w(i,s),l),s+=l}else if((31&c)!==0){let l=(c&192)===0,h=new E(w(i,s),null,(c&128)===128?n.readLeftID():null,null,(c&64)===64?n.readRightID():null,l?n.readParentInfo()?n.readString():n.readLeftID():null,l&&(c&32)===32?n.readString():null,vi(n,c));yield h,s+=h.length}else{let l=n.readLen();yield new L(w(i,s),l),s+=l}}}}var te=class{constructor(t,e){this.gen=oo(t),this.curr=null,this.done=!1,this.filterSkips=e,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===M);return this.curr}};var ee=class{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}},co=n=>Be(n,Ne,wt);var lo=(n,t)=>{if(n.constructor===L){let{client:e,clock:r}=n.id;return new L(w(e,r+t),n.length-t)}else if(n.constructor===M){let{client:e,clock:r}=n.id;return new M(w(e,r+t),n.length-t)}else{let e=n,{client:r,clock:i}=e.id;return new E(w(r,i+t),null,w(r,i+t-1),null,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t))}},Be=(n,t=ct,e=W)=>{if(n.length===1)return n[0];let r=n.map(a=>new t(pt(a))),i=r.map(a=>new te(a,!0)),s=null,o=new e,c=new ee(o);for(;i=i.filter(u=>u.curr!==null),i.sort((u,f)=>{if(u.curr.id.client===f.curr.id.client){let g=u.curr.id.clock-f.curr.id.clock;return g===0?u.curr.constructor===f.curr.constructor?0:u.curr.constructor===M?1:-1:g}else return f.curr.id.client-u.curr.id.client}),i.length!==0;){let a=i[0],d=a.curr.id.client;if(s!==null){let u=a.curr,f=!1;for(;u!==null&&u.id.clock+u.length<=s.struct.id.clock+s.struct.length&&u.id.client>=s.struct.id.client;)u=a.next(),f=!0;if(u===null||u.id.client!==d||f&&u.id.clock>s.struct.id.clock+s.struct.length)continue;if(d!==s.struct.id.client)nt(c,s.struct,s.offset),s={struct:u,offset:0},a.next();else if(s.struct.id.clock+s.struct.length<u.id.clock)if(s.struct.constructor===M)s.struct.length=u.id.clock+u.length-s.struct.id.clock;else{nt(c,s.struct,s.offset);let g=u.id.clock-s.struct.id.clock-s.struct.length;s={struct:new M(w(d,s.struct.id.clock+s.struct.length),g),offset:0}}else{let g=s.struct.id.clock+s.struct.length-u.id.clock;g>0&&(s.struct.constructor===M?s.struct.length-=g:u=lo(u,g)),s.struct.mergeWith(u)||(nt(c,s.struct,s.offset),s={struct:u,offset:0},a.next())}}else s={struct:a.curr,offset:0},a.next();for(let u=a.curr;u!==null&&u.id.client===d&&u.id.clock===s.struct.id.clock+s.struct.length&&u.constructor!==M;u=a.next())nt(c,s.struct,s.offset),s={struct:u,offset:0}}s!==null&&(nt(c,s.struct,s.offset),s=null),Xn(c);let l=r.map(a=>Bn(a)),h=kn(l);return Lt(o,h),o.toUint8Array()},ao=(n,t,e=ct,r=W)=>{let i=oi(t),s=new r,o=new ee(s),c=new e(pt(n)),l=new te(c,!1);for(;l.curr;){let a=l.curr,d=a.id.client,u=i.get(d)||0;if(l.curr.constructor===M){l.next();continue}if(a.id.clock+a.length>u)for(nt(o,a,K(u-a.id.clock,0)),l.next();l.curr&&l.curr.id.client===d;)nt(o,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===d&&l.curr.id.clock+l.curr.length<=u;)l.next()}Xn(o);let h=Bn(c);return Lt(s,h),s.toUint8Array()};var fi=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:F(n.encoder.restEncoder)}),n.encoder.restEncoder=jt(),n.written=0)},nt=(n,t,e)=>{n.written>0&&n.currClient!==t.id.client&&fi(n),n.written===0&&(n.currClient=t.id.client,n.encoder.writeClient(t.id.client),y(n.encoder.restEncoder,t.id.clock+e)),t.write(n.encoder,e),n.written++},Xn=n=>{fi(n);let t=n.encoder.restEncoder;y(t,n.clientStructs.length);for(let e=0;e<n.clientStructs.length;e++){let r=n.clientStructs[e];y(t,r.written),zt(t,r.restEncoder)}},ho=(n,t,e,r)=>{let i=new e(pt(n)),s=new te(i,!1),o=new r,c=new ee(o);for(let h=s.curr;h!==null;h=s.next())nt(c,t(h),0);Xn(c);let l=Bn(i);return Lt(o,l),o.toUint8Array()};var uo=n=>ho(n,Ur,ct,wt),Zr="You must not compute changes after the event-handler fired.",Nt=class{constructor(t,e){this.target=t,this.currentTarget=t,this.transaction=e,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=fo(this.currentTarget,this.target))}deletes(t){return he(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw G(Zr);let t=new Map,e=this.target;this.transaction.changed.get(e).forEach(i=>{if(i!==null){let s=e._map.get(i),o,c;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",c=ge(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",c=ge(l.content.getContent())):(o="add",c=void 0)}else if(this.deletes(s))o="delete",c=ge(s.content.getContent());else return;t.set(i,{action:o,oldValue:c})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw G(Zr);let e=this.target,r=P(),i=P(),s=[];if(t={added:r,deleted:i,delta:s,keys:this.keys},this.transaction.changed.get(e).has(null)){let c=null,l=()=>{c&&s.push(c)};for(let h=e._start;h!==null;h=h.right)h.deleted?this.deletes(h)&&!this.adds(h)&&((c===null||c.delete===void 0)&&(l(),c={delete:0}),c.delete+=h.length,i.add(h)):this.adds(h)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(h.content.getContent()),r.add(h)):((c===null||c.retain===void 0)&&(l(),c={retain:0}),c.retain+=h.length);c!==null&&c.retain===void 0&&l()}this._changes=t}return t}},fo=(n,t)=>{let e=[];for(;t._item!==null&&t!==n;){if(t._item.parentSub!==null)e.unshift(t._item.parentSub);else{let r=0,i=t._item.parent._start;for(;i!==t._item&&i!==null;)!i.deleted&&i.countable&&(r+=i.length),i=i.right;e.unshift(r)}t=t._item.parent}return e},T=()=>{xn("Invalid access: Add Yjs type to a document before reading data.")},gi=80,jn=0,Tn=class{constructor(t,e){t.marker=!0,this.p=t,this.index=e,this.timestamp=jn++}},go=n=>{n.timestamp=jn++},pi=(n,t,e)=>{n.p.marker=!1,n.p=t,t.marker=!0,n.index=e,n.timestamp=jn++},po=(n,t,e)=>{if(n.length>=gi){let r=n.reduce((i,s)=>i.timestamp<s.timestamp?i:s);return pi(r,t,e),r}else{let r=new Tn(t,e);return n.push(r),r}},He=(n,t)=>{if(n._start===null||t===0||n._searchMarker===null)return null;let e=n._searchMarker.length===0?null:n._searchMarker.reduce((s,o)=>bt(t-s.index)<bt(t-o.index)?s:o),r=n._start,i=0;for(e!==null&&(r=e.p,i=e.index,go(e));r.right!==null&&i<t;){if(!r.deleted&&r.countable){if(t<i+r.length)break;i+=r.length}r=r.right}for(;r.left!==null&&i>t;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return e!==null&&bt(e.index-i)<r.parent.length/gi?(pi(e,r,i),e):po(n._searchMarker,r,i)},ne=(n,t,e)=>{for(let r=n.length-1;r>=0;r--){let i=n[r];if(e>0){let s=i.p;for(s.marker=!1;s&&(s.deleted||!s.countable);)s=s.left,s&&!s.deleted&&s.countable&&(i.index-=s.length);if(s===null||s.marker===!0){n.splice(r,1);continue}i.p=s,s.marker=!0}(t<i.index||e>0&&t===i.index)&&(i.index=K(t,i.index+e))}};var Je=(n,t,e)=>{let r=n,i=t.changedParentTypes;for(;j(i,n,()=>[]).push(e),n._item!==null;)n=n._item.parent;ai(r._eH,e,t)},C=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Gr(),this._dEH=Gr(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,e){this.doc=t,this._item=e}_copy(){throw Y()}clone(){throw Y()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,e){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){$r(this._eH,t)}observeDeep(t){$r(this._dEH,t)}unobserve(t){Hr(this._eH,t)}unobserveDeep(t){Hr(this._dEH,t)}toJSON(){}},mi=(n,t,e)=>{n.doc??T(),t<0&&(t=n._length+t),e<0&&(e=n._length+e);let r=e-t,i=[],s=n._start;for(;s!==null&&r>0;){if(s.countable&&!s.deleted){let o=s.content.getContent();if(o.length<=t)t-=o.length;else{for(let c=t;c<o.length&&r>0;c++)i.push(o[c]),r--;t=0}}s=s.right}return i},wi=n=>{n.doc??T();let t=[],e=n._start;for(;e!==null;){if(e.countable&&!e.deleted){let r=e.content.getContent();for(let i=0;i<r.length;i++)t.push(r[i])}e=e.right}return t};var re=(n,t)=>{let e=0,r=n._start;for(n.doc??T();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let s=0;s<i.length;s++)t(i[s],e++,n)}r=r.right}},yi=(n,t)=>{let e=[];return re(n,(r,i)=>{e.push(t(r,i,n))}),e},mo=n=>{let t=n._start,e=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(e===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};e=t.content.getContent(),r=0,t=t.right}let i=e[r++];return e.length<=r&&(e=null),{done:!1,value:i}}}},xi=(n,t)=>{n.doc??T();let e=He(n,t),r=n._start;for(e!==null&&(r=e.p,t-=e.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},Fe=(n,t,e,r)=>{let i=e,s=n.doc,o=s.clientID,c=s.store,l=e===null?t._start:e.right,h=[],a=()=>{h.length>0&&(i=new E(w(o,_(c,o)),i,i&&i.lastId,l,l&&l.id,t,null,new Ot(h)),i.integrate(n,0),h=[])};r.forEach(d=>{if(d===null)h.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:h.push(d);break;default:switch(a(),d.constructor){case Uint8Array:case ArrayBuffer:i=new E(w(o,_(c,o)),i,i&&i.lastId,l,l&&l.id,t,null,new le(new Uint8Array(d))),i.integrate(n,0);break;case ot:i=new E(w(o,_(c,o)),i,i&&i.lastId,l,l&&l.id,t,null,new ae(d)),i.integrate(n,0);break;default:if(d instanceof C)i=new E(w(o,_(c,o)),i,i&&i.lastId,l,l&&l.id,t,null,new Q(d)),i.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),a()},bi=()=>G("Length exceeded!"),ki=(n,t,e,r)=>{if(e>t._length)throw bi();if(e===0)return t._searchMarker&&ne(t._searchMarker,e,r.length),Fe(n,t,null,r);let i=e,s=He(t,e),o=t._start;for(s!==null&&(o=s.p,e-=s.index,e===0&&(o=o.prev,e+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(e<=o.length){e<o.length&&O(n,w(o.id.client,o.id.clock+e));break}e-=o.length}return t._searchMarker&&ne(t._searchMarker,i,r.length),Fe(n,t,o,r)},wo=(n,t,e)=>{let i=(t._searchMarker||[]).reduce((s,o)=>o.index>s.index?o:s,{index:0,p:t._start}).p;if(i)for(;i.right;)i=i.right;return Fe(n,t,i,e)},Ei=(n,t,e,r)=>{if(r===0)return;let i=e,s=r,o=He(t,e),c=t._start;for(o!==null&&(c=o.p,e-=o.index);c!==null&&e>0;c=c.right)!c.deleted&&c.countable&&(e<c.length&&O(n,w(c.id.client,c.id.clock+e)),e-=c.length);for(;r>0&&c!==null;)c.deleted||(r<c.length&&O(n,w(c.id.client,c.id.clock+r)),c.delete(n),r-=c.length),c=c.right;if(r>0)throw bi();t._searchMarker&&ne(t._searchMarker,i,-s+r)},Ye=(n,t,e)=>{let r=t._map.get(e);r!==void 0&&r.delete(n)},zn=(n,t,e,r)=>{let i=t._map.get(e)||null,s=n.doc,o=s.clientID,c;if(r==null)c=new Ot([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:c=new Ot([r]);break;case Uint8Array:c=new le(r);break;case ot:c=new ae(r);break;default:if(r instanceof C)c=new Q(r);else throw new Error("Unexpected content type")}new E(w(o,_(s.store,o)),i,i&&i.lastId,null,null,t,e,c).integrate(n,0)},Gn=(n,t)=>{n.doc??T();let e=n._map.get(t);return e!==void 0&&!e.deleted?e.content.getContent()[e.length-1]:void 0},Si=n=>{let t={};return n.doc??T(),n._map.forEach((e,r)=>{e.deleted||(t[r]=e.content.getContent()[e.length-1])}),t},Ci=(n,t)=>{n.doc??T();let e=n._map.get(t);return e!==void 0&&!e.deleted};var yo=(n,t)=>{let e={};return n._map.forEach((r,i)=>{let s=r;for(;s!==null&&(!t.sv.has(s.id.client)||s.id.clock>=(t.sv.get(s.id.client)||0));)s=s.left;s!==null&&It(s,t)&&(e[i]=s.content.getContent()[s.length-1])}),e},Ue=n=>(n.doc??T(),Yr(n._map.entries(),t=>!t[1].deleted)),In=class extends Nt{},Xe=class n extends C{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let e=new n;return e.push(t),e}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let t=new n;return t.insert(0,this.toArray().map(e=>e instanceof C?e.clone():e)),t}get length(){return this.doc??T(),this._length}_callObserver(t,e){super._callObserver(t,e),Je(this,t,new In(this,t))}insert(t,e){this.doc!==null?k(this.doc,r=>{ki(r,this,t,e)}):this._prelimContent.splice(t,0,...e)}push(t){this.doc!==null?k(this.doc,e=>{wo(e,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,e=1){this.doc!==null?k(this.doc,r=>{Ei(r,this,t,e)}):this._prelimContent.splice(t,e)}get(t){return xi(this,t)}toArray(){return wi(this)}slice(t=0,e=this.length){return mi(this,t,e)}toJSON(){return this.map(t=>t instanceof C?t.toJSON():t)}map(t){return yi(this,t)}forEach(t){re(this,t)}[Symbol.iterator](){return mo(this)}_write(t){t.writeTypeRef(Yo)}},xo=n=>new Xe,vn=class extends Nt{constructor(t,e,r){super(t,e),this.keysChanged=r}},ie=class n extends C{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,e){super._integrate(t,e),this._prelimContent.forEach((r,i)=>{this.set(i,r)}),this._prelimContent=null}_copy(){return new n}clone(){let t=new n;return this.forEach((e,r)=>{t.set(r,e instanceof C?e.clone():e)}),t}_callObserver(t,e){Je(this,t,new vn(this,t,e))}toJSON(){this.doc??T();let t={};return this._map.forEach((e,r)=>{if(!e.deleted){let i=e.content.getContent()[e.length-1];t[r]=i instanceof C?i.toJSON():i}}),t}get size(){return[...Ue(this)].length}keys(){return Ce(Ue(this),t=>t[0])}values(){return Ce(Ue(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Ce(Ue(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??T(),this._map.forEach((e,r)=>{e.deleted||t(e.content.getContent()[e.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?k(this.doc,e=>{Ye(e,this,t)}):this._prelimContent.delete(t)}set(t,e){return this.doc!==null?k(this.doc,r=>{zn(r,this,t,e)}):this._prelimContent.set(t,e),e}get(t){return Gn(this,t)}has(t){return Ci(this,t)}clear(){this.doc!==null?k(this.doc,t=>{this.forEach(function(e,r,i){Ye(t,i,r)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Xo)}},bo=n=>new ie,rt=(n,t)=>n===t||typeof n=="object"&&typeof t=="object"&&n&&t&&_r(n,t),se=class{constructor(t,e,r,i){this.left=t,this.right=e,this.index=r,this.currentAttributes=i}forward(){switch(this.right===null&&X(),this.right.content.constructor){case U:this.right.deleted||Mt(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}},Qr=(n,t,e)=>{for(;t.right!==null&&e>0;){switch(t.right.content.constructor){case U:t.right.deleted||Mt(t.currentAttributes,t.right.content);break;default:t.right.deleted||(e<t.right.length&&O(n,w(t.right.id.client,t.right.id.clock+e)),t.index+=t.right.length,e-=t.right.length);break}t.left=t.right,t.right=t.right.right}return t},Ae=(n,t,e,r)=>{let i=new Map,s=r?He(t,e):null;if(s){let o=new se(s.p.left,s.p,s.index,i);return Qr(n,o,e-s.index)}else{let o=new se(null,t._start,0,i);return Qr(n,o,e)}},_i=(n,t,e,r)=>{for(;e.right!==null&&(e.right.deleted===!0||e.right.content.constructor===U&&rt(r.get(e.right.content.key),e.right.content.value));)e.right.deleted||r.delete(e.right.content.key),e.forward();let i=n.doc,s=i.clientID;r.forEach((o,c)=>{let l=e.left,h=e.right,a=new E(w(s,_(i.store,s)),l,l&&l.lastId,h,h&&h.id,t,null,new U(c,o));a.integrate(n,0),e.right=a,e.forward()})},Mt=(n,t)=>{let{key:e,value:r}=t;r===null?n.delete(e):n.set(e,r)},Ui=(n,t)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===U&&rt(t[n.right.content.key]??null,n.right.content.value)))break;n.forward()}},Ai=(n,t,e,r)=>{let i=n.doc,s=i.clientID,o=new Map;for(let c in r){let l=r[c],h=e.currentAttributes.get(c)??null;if(!rt(h,l)){o.set(c,h);let{left:a,right:d}=e;e.right=new E(w(s,_(i.store,s)),a,a&&a.lastId,d,d&&d.id,t,null,new U(c,l)),e.right.integrate(n,0),e.forward()}}return o},bn=(n,t,e,r,i)=>{e.currentAttributes.forEach((u,f)=>{i[f]===void 0&&(i[f]=null)});let s=n.doc,o=s.clientID;Ui(e,i);let c=Ai(n,t,e,i),l=r.constructor===String?new Z(r):r instanceof C?new Q(r):new xt(r),{left:h,right:a,index:d}=e;t._searchMarker&&ne(t._searchMarker,e.index,l.getLength()),a=new E(w(o,_(s.store,o)),h,h&&h.lastId,a,a&&a.id,t,null,l),a.integrate(n,0),e.right=a,e.index=d,e.forward(),_i(n,t,e,c)},ti=(n,t,e,r,i)=>{let s=n.doc,o=s.clientID;Ui(e,i);let c=Ai(n,t,e,i);t:for(;e.right!==null&&(r>0||c.size>0&&(e.right.deleted||e.right.content.constructor===U));){if(!e.right.deleted)switch(e.right.content.constructor){case U:{let{key:l,value:h}=e.right.content,a=i[l];if(a!==void 0){if(rt(a,h))c.delete(l);else{if(r===0)break t;c.set(l,h)}e.right.delete(n)}else e.currentAttributes.set(l,h);break}default:r<e.right.length&&O(n,w(e.right.id.client,e.right.id.clock+r)),r-=e.right.length;break}e.forward()}if(r>0){let l="";for(;r>0;r--)l+=`
`;e.right=new E(w(o,_(s.store,o)),e.left,e.left&&e.left.lastId,e.right,e.right&&e.right.id,t,null,new Z(l)),e.right.integrate(n,0),e.forward()}_i(n,t,e,c)},Di=(n,t,e,r,i)=>{let s=t,o=v();for(;s&&(!s.countable||s.deleted);){if(!s.deleted&&s.content.constructor===U){let h=s.content;o.set(h.key,h)}s=s.right}let c=0,l=!1;for(;t!==s;){if(e===t&&(l=!0),!t.deleted){let h=t.content;switch(h.constructor){case U:{let{key:a,value:d}=h,u=r.get(a)??null;(o.get(a)!==h||u===d)&&(t.delete(n),c++,!l&&(i.get(a)??null)===d&&u!==d&&(u===null?i.delete(a):i.set(a,u))),!l&&!t.deleted&&Mt(i,h);break}}}t=t.right}return c},ko=(n,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let e=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===U){let r=t.content.key;e.has(r)?t.delete(n):e.add(r)}t=t.left}},Eo=n=>{let t=0;return k(n.doc,e=>{let r=n._start,i=n._start,s=v(),o=fe(s);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case U:Mt(o,i.content);break;default:t+=Di(e,r,i,s,o),s=fe(o),r=i;break}i=i.right}}),t},So=n=>{let t=new Set,e=n.doc;for(let[r,i]of n.afterState.entries()){let s=n.beforeState.get(r)||0;i!==s&&di(n,e.store.clients.get(r),s,i,o=>{!o.deleted&&o.content.constructor===U&&o.constructor!==L&&t.add(o.parent)})}k(e,r=>{vt(n,n.deleteSet,i=>{if(i instanceof L||!i.parent._hasFormatting||t.has(i.parent))return;let s=i.parent;i.content.constructor===U?t.add(s):ko(r,i)});for(let i of t)Eo(i)})},ei=(n,t,e)=>{let r=e,i=fe(t.currentAttributes),s=t.right;for(;e>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Q:case xt:case Z:e<t.right.length&&O(n,w(t.right.id.client,t.right.id.clock+e)),e-=t.right.length,t.right.delete(n);break}t.forward()}s&&Di(n,s,t.right,i,t.currentAttributes);let o=(t.left||t.right).parent;return o._searchMarker&&ne(o._searchMarker,t.index,-r+e),t},Nn=class extends Nt{constructor(t,e,r){super(t,e),this.childListChanged=!1,this.keysChanged=new Set,r.forEach(i=>{i===null?this.childListChanged=!0:this.keysChanged.add(i)})}get changes(){if(this._changes===null){let t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){let t=this.target.doc,e=[];k(t,r=>{let i=new Map,s=new Map,o=this.target._start,c=null,l={},h="",a=0,d=0,u=()=>{if(c!==null){let f=null;switch(c){case"delete":d>0&&(f={delete:d}),d=0;break;case"insert":(typeof h=="object"||h.length>0)&&(f={insert:h},i.size>0&&(f.attributes={},i.forEach((g,p)=>{g!==null&&(f.attributes[p]=g)}))),h="";break;case"retain":a>0&&(f={retain:a},Cr(l)||(f.attributes=Er({},l))),a=0;break}f&&e.push(f),c=null}};for(;o!==null;){switch(o.content.constructor){case Q:case xt:this.adds(o)?this.deletes(o)||(u(),c="insert",h=o.content.getContent()[0],u()):this.deletes(o)?(c!=="delete"&&(u(),c="delete"),d+=1):o.deleted||(c!=="retain"&&(u(),c="retain"),a+=1);break;case Z:this.adds(o)?this.deletes(o)||(c!=="insert"&&(u(),c="insert"),h+=o.content.str):this.deletes(o)?(c!=="delete"&&(u(),c="delete"),d+=o.length):o.deleted||(c!=="retain"&&(u(),c="retain"),a+=o.length);break;case U:{let{key:f,value:g}=o.content;if(this.adds(o)){if(!this.deletes(o)){let p=i.get(f)??null;rt(p,g)?g!==null&&o.delete(r):(c==="retain"&&u(),rt(g,s.get(f)??null)?delete l[f]:l[f]=g)}}else if(this.deletes(o)){s.set(f,g);let p=i.get(f)??null;rt(p,g)||(c==="retain"&&u(),l[f]=p)}else if(!o.deleted){s.set(f,g);let p=l[f];p!==void 0&&(rt(p,g)?p!==null&&o.delete(r):(c==="retain"&&u(),g===null?delete l[f]:l[f]=g))}o.deleted||(c==="insert"&&u(),Mt(i,o.content));break}}o=o.right}for(u();e.length>0;){let f=e[e.length-1];if(f.retain!==void 0&&f.attributes===void 0)e.pop();else break}}),this._delta=e}return this._delta}},oe=class n extends C{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??T(),this._length}_integrate(t,e){super._integrate(t,e);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new n}clone(){let t=new n;return t.applyDelta(this.toDelta()),t}_callObserver(t,e){super._callObserver(t,e);let r=new Nn(this,t,e);Je(this,t,r),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??T();let t="",e=this._start;for(;e!==null;)!e.deleted&&e.countable&&e.content.constructor===Z&&(t+=e.content.str),e=e.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:e=!0}={}){this.doc!==null?k(this.doc,r=>{let i=new se(null,this._start,0,new Map);for(let s=0;s<t.length;s++){let o=t[s];if(o.insert!==void 0){let c=!e&&typeof o.insert=="string"&&s===t.length-1&&i.right===null&&o.insert.slice(-1)===`
`?o.insert.slice(0,-1):o.insert;(typeof c!="string"||c.length>0)&&bn(r,this,i,c,o.attributes||{})}else o.retain!==void 0?ti(r,this,i,o.retain,o.attributes||{}):o.delete!==void 0&&ei(r,i,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,e,r){this.doc??T();let i=[],s=new Map,o=this.doc,c="",l=this._start;function h(){if(c.length>0){let d={},u=!1;s.forEach((g,p)=>{u=!0,d[p]=g});let f={insert:c};u&&(f.attributes=d),i.push(f),c=""}}let a=()=>{for(;l!==null;){if(It(l,t)||e!==void 0&&It(l,e))switch(l.content.constructor){case Z:{let d=s.get("ychange");t!==void 0&&!It(l,t)?(d===void 0||d.user!==l.id.client||d.type!=="removed")&&(h(),s.set("ychange",r?r("removed",l.id):{type:"removed"})):e!==void 0&&!It(l,e)?(d===void 0||d.user!==l.id.client||d.type!=="added")&&(h(),s.set("ychange",r?r("added",l.id):{type:"added"})):d!==void 0&&(h(),s.delete("ychange")),c+=l.content.str;break}case Q:case xt:{h();let d={insert:l.content.getContent()[0]};if(s.size>0){let u={};d.attributes=u,s.forEach((f,g)=>{u[g]=f})}i.push(d);break}case U:It(l,t)&&(h(),Mt(s,l.content));break}l=l.right}h()};return t||e?k(o,d=>{t&&_n(d,t),e&&_n(d,e),a()},"cleanup"):a(),i}insert(t,e,r){if(e.length<=0)return;let i=this.doc;i!==null?k(i,s=>{let o=Ae(s,this,t,!r);r||(r={},o.currentAttributes.forEach((c,l)=>{r[l]=c})),bn(s,this,o,e,r)}):this._pending.push(()=>this.insert(t,e,r))}insertEmbed(t,e,r){let i=this.doc;i!==null?k(i,s=>{let o=Ae(s,this,t,!r);bn(s,this,o,e,r||{})}):this._pending.push(()=>this.insertEmbed(t,e,r||{}))}delete(t,e){if(e===0)return;let r=this.doc;r!==null?k(r,i=>{ei(i,Ae(i,this,t,!0),e)}):this._pending.push(()=>this.delete(t,e))}format(t,e,r){if(e===0)return;let i=this.doc;i!==null?k(i,s=>{let o=Ae(s,this,t,!1);o.right!==null&&ti(s,this,o,e,r)}):this._pending.push(()=>this.format(t,e,r))}removeAttribute(t){this.doc!==null?k(this.doc,e=>{Ye(e,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,e){this.doc!==null?k(this.doc,r=>{zn(r,this,t,e)}):this._pending.push(()=>this.setAttribute(t,e))}getAttribute(t){return Gn(this,t)}getAttributes(){return Si(this)}_write(t){t.writeTypeRef(jo)}},Co=n=>new oe,Wt=class{constructor(t,e=()=>!0){this._filter=e,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??T()}[Symbol.iterator](){return this}next(){let t=this._currentNode,e=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(e)))do if(e=t.content.type,!t.deleted&&(e.constructor===S||e.constructor===Vt)&&e._start!==null)t=e._start;else for(;t!==null;){let r=t.next;if(r!==null){t=r;break}else t.parent===this._root?t=null:t=t.parent._item}while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}},Vt=class n extends C{constructor(){super(),this._prelimContent=[]}get firstChild(){let t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let t=new n;return t.insert(0,this.toArray().map(e=>e instanceof C?e.clone():e)),t}get length(){return this.doc??T(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Wt(this,t)}querySelector(t){t=t.toUpperCase();let r=new Wt(this,i=>i.nodeName&&i.nodeName.toUpperCase()===t).next();return r.done?null:r.value}querySelectorAll(t){return t=t.toUpperCase(),z(new Wt(this,e=>e.nodeName&&e.nodeName.toUpperCase()===t))}_callObserver(t,e){Je(this,t,new Vn(this,e,t))}toString(){return yi(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,e={},r){let i=t.createDocumentFragment();return r!==void 0&&r._createAssociation(i,this),re(this,s=>{i.insertBefore(s.toDOM(t,e,r),null)}),i}insert(t,e){this.doc!==null?k(this.doc,r=>{ki(r,this,t,e)}):this._prelimContent.splice(t,0,...e)}insertAfter(t,e){if(this.doc!==null)k(this.doc,r=>{let i=t&&t instanceof C?t._item:t;Fe(r,this,i,e)});else{let r=this._prelimContent,i=t===null?0:r.findIndex(s=>s===t)+1;if(i===0&&t!==null)throw G("Reference item not found");r.splice(i,0,...e)}}delete(t,e=1){this.doc!==null?k(this.doc,r=>{Ei(r,this,t,e)}):this._prelimContent.splice(t,e)}toArray(){return wi(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return xi(this,t)}slice(t=0,e=this.length){return mi(this,t,e)}forEach(t){re(this,t)}_write(t){t.writeTypeRef(Go)}},_o=n=>new Vt,S=class n extends Vt{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,e){super._integrate(t,e),this._prelimAttrs.forEach((r,i)=>{this.setAttribute(i,r)}),this._prelimAttrs=null}_copy(){return new n(this.nodeName)}clone(){let t=new n(this.nodeName),e=this.getAttributes();return Sr(e,(r,i)=>{t.setAttribute(i,r)}),t.insert(0,this.toArray().map(r=>r instanceof C?r.clone():r)),t}toString(){let t=this.getAttributes(),e=[],r=[];for(let c in t)r.push(c);r.sort();let i=r.length;for(let c=0;c<i;c++){let l=r[c];e.push(l+'="'+t[l]+'"')}let s=this.nodeName.toLocaleLowerCase(),o=e.length>0?" "+e.join(" "):"";return`<${s}${o}>${super.toString()}</${s}>`}removeAttribute(t){this.doc!==null?k(this.doc,e=>{Ye(e,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,e){this.doc!==null?k(this.doc,r=>{zn(r,this,t,e)}):this._prelimAttrs.set(t,e)}getAttribute(t){return Gn(this,t)}hasAttribute(t){return Ci(this,t)}getAttributes(t){return t?yo(this,t):Si(this)}toDOM(t=document,e={},r){let i=t.createElement(this.nodeName),s=this.getAttributes();for(let o in s){let c=s[o];typeof c=="string"&&i.setAttribute(o,c)}return re(this,o=>{i.appendChild(o.toDOM(t,e,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(t){t.writeTypeRef(zo),t.writeKey(this.nodeName)}},Uo=n=>new S(n.readKey()),Vn=class extends Nt{constructor(t,e,r){super(t,r),this.childListChanged=!1,this.attributesChanged=new Set,e.forEach(i=>{i===null?this.childListChanged=!0:this.attributesChanged.add(i)})}},On=class n extends ie{constructor(t){super(),this.hookName=t}_copy(){return new n(this.hookName)}clone(){let t=new n(this.hookName);return this.forEach((e,r)=>{t.set(r,e)}),t}toDOM(t=document,e={},r){let i=e[this.hookName],s;return i!==void 0?s=i.createDom(this):s=document.createElement(this.hookName),s.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(s,this),s}_write(t){t.writeTypeRef($o),t.writeKey(this.hookName)}},Ao=n=>new On(n.readKey()),yt=class n extends oe{get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new n}clone(){let t=new n;return t.applyDelta(this.toDelta()),t}toDOM(t=document,e,r){let i=t.createTextNode(this.toString());return r!==void 0&&r._createAssociation(i,this),i}toString(){return this.toDelta().map(t=>{let e=[];for(let i in t.attributes){let s=[];for(let o in t.attributes[i])s.push({key:o,value:t.attributes[i][o]});s.sort((o,c)=>o.key<c.key?-1:1),e.push({nodeName:i,attrs:s})}e.sort((i,s)=>i.nodeName<s.nodeName?-1:1);let r="";for(let i=0;i<e.length;i++){let s=e[i];r+=`<${s.nodeName}`;for(let o=0;o<s.attrs.length;o++){let c=s.attrs[o];r+=` ${c.key}="${c.value}"`}r+=">"}r+=t.insert;for(let i=e.length-1;i>=0;i--)r+=`</${e[i].nodeName}>`;return r}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(Ho)}},Do=n=>new yt,ce=class{constructor(t,e){this.id=t,this.length=e}get deleted(){throw Y()}mergeWith(t){return!1}write(t,e,r){throw Y()}integrate(t,e){throw Y()}},To=0,L=class extends ce{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){e>0&&(this.id.clock+=e,this.length-=e),hi(t.doc.store,this)}write(t,e){t.writeInfo(To),t.writeLen(this.length-e)}getMissing(t,e){return null}},le=class n{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new n(this.content)}splice(t){throw Y()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeBuf(this.content)}getRef(){return 3}},Io=n=>new le(n.readBuf()),je=class n{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.len)}splice(t){let e=new n(this.len-t);return this.len=t,e}mergeWith(t){return this.len+=t.len,!0}integrate(t,e){Qt(t.deleteSet,e.id.client,e.id.clock,this.len),e.markDeleted()}delete(t){}gc(t){}write(t,e){t.writeLen(this.len-e)}getRef(){return 1}},vo=n=>new je(n.readLen()),Ti=(n,t)=>new ot({guid:n,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),ae=class n{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;let e={};this.opts=e,t.gc||(e.gc=!1),t.autoLoad&&(e.autoLoad=!0),t.meta!==null&&(e.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new n(Ti(this.doc.guid,this.opts))}splice(t){throw Y()}mergeWith(t){return!1}integrate(t,e){this.doc._item=e,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,e){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}},No=n=>new ae(Ti(n.readString(),n.readAny())),xt=class n{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new n(this.embed)}splice(t){throw Y()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeJSON(this.embed)}getRef(){return 5}},Vo=n=>new xt(n.readJSON()),U=class n{constructor(t,e){this.key=t,this.value=e}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.key,this.value)}splice(t){throw Y()}mergeWith(t){return!1}integrate(t,e){let r=e.parent;r._searchMarker=null,r._hasFormatting=!0}delete(t){}gc(t){}write(t,e){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}},Oo=n=>new U(n.readKey(),n.readJSON()),Ln=class n{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new n(this.arr)}splice(t){let e=new n(this.arr.slice(t));return this.arr=this.arr.slice(0,t),e}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){let r=this.arr.length;t.writeLen(r-e);for(let i=e;i<r;i++){let s=this.arr[i];t.writeString(s===void 0?"undefined":JSON.stringify(s))}}getRef(){return 2}},Lo=n=>{let t=n.readLen(),e=[];for(let r=0;r<t;r++){let i=n.readString();i==="undefined"?e.push(void 0):e.push(JSON.parse(i))}return new Ln(e)},Mo=Jt("node_env")==="development",Ot=class n{constructor(t){this.arr=t,Mo&&dn(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new n(this.arr)}splice(t){let e=new n(this.arr.slice(t));return this.arr=this.arr.slice(0,t),e}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){let r=this.arr.length;t.writeLen(r-e);for(let i=e;i<r;i++){let s=this.arr[i];t.writeAny(s)}}getRef(){return 8}},Ro=n=>{let t=n.readLen(),e=[];for(let r=0;r<t;r++)e.push(n.readAny());return new Ot(e)},Z=class n{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new n(this.str)}splice(t){let e=new n(this.str.slice(t));this.str=this.str.slice(0,t);let r=this.str.charCodeAt(t-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+"\uFFFD",e.str="\uFFFD"+e.str.slice(1)),e}mergeWith(t){return this.str+=t.str,!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeString(e===0?this.str:this.str.slice(e))}getRef(){return 4}},Bo=n=>new Z(n.readString()),Fo=[xo,bo,Co,Uo,_o,Ao,Do],Yo=0,Xo=1,jo=2,zo=3,Go=4,$o=5,Ho=6,Q=class n{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new n(this.type._copy())}splice(t){throw Y()}mergeWith(t){return!1}integrate(t,e){this.type._integrate(t.doc,e)}delete(t){let e=this.type._start;for(;e!==null;)e.deleted?e.id.clock<(t.beforeState.get(e.id.client)||0)&&t._mergeStructs.push(e):e.delete(t),e=e.right;this.type._map.forEach(r=>{r.deleted?r.id.clock<(t.beforeState.get(r.id.client)||0)&&t._mergeStructs.push(r):r.delete(t)}),t.changed.delete(this.type)}gc(t){let e=this.type._start;for(;e!==null;)e.gc(t,!0),e=e.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(t,!0),r=r.left}),this.type._map=new Map}write(t,e){this.type._write(t)}getRef(){return 7}},Jo=n=>new Q(Fo[n.readTypeRef()](n)),qo=(n,t)=>{let e=t,r=0,i;do r>0&&(e=w(e.client,e.clock+r)),i=De(n,e),r=e.clock-i.id.clock,e=i.redone;while(e!==null&&i instanceof E);return{item:i,diff:r}},$n=(n,t)=>{for(;n!==null&&n.keep!==t;)n.keep=t,n=n.parent._item},ze=(n,t,e)=>{let{client:r,clock:i}=t.id,s=new E(w(r,i+e),t,w(r,i+e-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(e));return t.deleted&&s.markDeleted(),t.keep&&(s.keep=!0),t.redone!==null&&(s.redone=w(t.redone.client,t.redone.clock+e)),t.right=s,s.right!==null&&(s.right.left=s),n._mergeStructs.push(s),s.parentSub!==null&&s.right===null&&s.parent._map.set(s.parentSub,s),t.length=e,s},ni=(n,t)=>ir(n,e=>he(e.deletions,t)),Ii=(n,t,e,r,i,s)=>{let o=n.doc,c=o.store,l=o.clientID,h=t.redone;if(h!==null)return O(n,h);let a=t.parent._item,d=null,u;if(a!==null&&a.deleted===!0){if(a.redone===null&&(!e.has(a)||Ii(n,a,e,r,i,s)===null))return null;for(;a.redone!==null;)a=O(n,a.redone)}let f=a===null?t.parent:a.content.type;if(t.parentSub===null){for(d=t.left,u=t;d!==null;){let b=d;for(;b!==null&&b.parent._item!==a;)b=b.redone===null?null:O(n,b.redone);if(b!==null&&b.parent._item===a){d=b;break}d=d.left}for(;u!==null;){let b=u;for(;b!==null&&b.parent._item!==a;)b=b.redone===null?null:O(n,b.redone);if(b!==null&&b.parent._item===a){u=b;break}u=u.right}}else if(u=null,t.right&&!i){for(d=t;d!==null&&d.right!==null&&(d.right.redone||he(r,d.right.id)||ni(s.undoStack,d.right.id)||ni(s.redoStack,d.right.id));)for(d=d.right;d.redone;)d=O(n,d.redone);if(d&&d.right!==null)return null}else d=f._map.get(t.parentSub)||null;let g=_(c,l),p=w(l,g),x=new E(p,d,d&&d.lastId,u,u&&u.id,f,t.parentSub,t.content.copy());return t.redone=p,$n(x,!0),x.integrate(n,0),x},E=class n extends ce{constructor(t,e,r,i,s,o,c,l){super(t,l.getLength()),this.origin=r,this.left=e,this.right=i,this.rightOrigin=s,this.parent=o,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?2:0}set marker(t){(this.info&8)>0!==t&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(t){this.keep!==t&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(t){this.deleted!==t&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,e){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=_(e,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=_(e,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===it&&this.id.client!==this.parent.client&&this.parent.clock>=_(e,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Jr(t,e,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=O(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===L||this.right&&this.right.constructor===L)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===n?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===n&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===it){let r=De(e,this.parent);r.constructor===L?this.parent=null:this.parent=r.content.type}return null}integrate(t,e){if(e>0&&(this.id.clock+=e,this.left=Jr(t,t.doc.store,w(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(e),this.length-=e),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,i;if(r!==null)i=r.right;else 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;let s=new Set,o=new Set;for(;i!==null&&i!==this.right;){if(o.add(i),s.add(i),_e(this.origin,i.origin)){if(i.id.client<this.id.client)r=i,s.clear();else if(_e(this.rightOrigin,i.rightOrigin))break}else if(i.origin!==null&&o.has(De(t.doc.store,i.origin)))s.has(De(t.doc.store,i.origin))||(r=i,s.clear());else break;i=i.right}this.left=r}if(this.left!==null){let r=this.left.right;this.right=r,this.left.right=this}else{let r;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,this.parent._start=this;this.right=r}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),hi(t.doc.store,this),this.content.integrate(t,this),Pr(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new L(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;t!==null&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;t!==null&&t.deleted;)t=t.left;return t}get lastId(){return this.length===1?this.id:w(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&_e(t.origin,this.lastId)&&this.right===t&&_e(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){let e=this.parent._searchMarker;return e&&e.forEach(r=>{r.p===t&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){let e=this.parent;this.countable&&this.parentSub===null&&(e._length-=this.length),this.markDeleted(),Qt(t.deleteSet,this.id.client,this.id.clock,this.length),Pr(t,e,this.parentSub),this.content.delete(t)}}gc(t,e){if(!this.deleted)throw X();this.content.gc(t),e?ro(t,this,new L(this.id,this.length)):this.content=new je(this.length)}write(t,e){let r=e>0?w(this.id.client,this.id.clock+e-1):this.origin,i=this.rightOrigin,s=this.parentSub,o=this.content.getRef()&31|(r===null?0:128)|(i===null?0:64)|(s===null?0:32);if(t.writeInfo(o),r!==null&&t.writeLeftID(r),i!==null&&t.writeRightID(i),r===null&&i===null){let c=this.parent;if(c._item!==void 0){let l=c._item;if(l===null){let h=to(c);t.writeParentInfo(!0),t.writeString(h)}else t.writeParentInfo(!1),t.writeLeftID(l.id)}else c.constructor===String?(t.writeParentInfo(!0),t.writeString(c)):c.constructor===it?(t.writeParentInfo(!1),t.writeLeftID(c)):X();s!==null&&t.writeString(s)}this.content.write(t,e)}},vi=(n,t)=>Po[t&31](n),Po=[()=>{X()},vo,Lo,Io,Bo,Vo,Oo,Jo,Ro,No,()=>{X()}],Ko=10,M=class extends ce{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){X()}write(t,e){t.writeInfo(Ko),y(t.restEncoder,this.length-e)}getMissing(t,e){return null}},Ni=typeof globalThis<"u"?globalThis:typeof window<"u"||typeof window<"u"?window:{},Vi="__ $YJS$ __";Ni[Vi]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Ni[Vi]=!0;var D=[];for(let n=0;n<256;++n)D.push((n+256).toString(16).slice(1));function Li(n,t=0){return(D[n[t+0]]+D[n[t+1]]+D[n[t+2]]+D[n[t+3]]+"-"+D[n[t+4]]+D[n[t+5]]+"-"+D[n[t+6]]+D[n[t+7]]+"-"+D[n[t+8]]+D[n[t+9]]+"-"+D[n[t+10]]+D[n[t+11]]+D[n[t+12]]+D[n[t+13]]+D[n[t+14]]+D[n[t+15]]).toLowerCase()}var Hn,Wo=new Uint8Array(16);function Jn(){if(!Hn){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Hn=crypto.getRandomValues.bind(crypto)}return Hn(Wo)}var Zo=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),qn={randomUUID:Zo};function Qo(n,t,e){if(qn.randomUUID&&!t&&!n)return qn.randomUUID();n=n||{};let r=n.random??n.rng?.()??Jn();if(r.length<16)throw new Error("Random bytes length must be >= 16");if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){if(e=e||0,e<0||e+16>t.length)throw new RangeError(`UUID byte range ${e}:${e+15} is out of buffer bounds`);for(let i=0;i<16;++i)t[e+i]=r[i];return t}return Li(r)}var Pn=Qo;var Rt=class{constructor(t,e,r){this._y=t.get("xml",S),e?this._undoManager=new Re(this._y):this._undoManager=null,this.doc=t,this._y.observeDeep(i=>{for(let s of i){let o=s.target;if(o instanceof S){let c=o.getAttribute("$id"),l={root:o===this._y,target:c,elements:[],attributes:{set:[],delete:[]},text:[]};for(let h of s.changes.delta)h.insert?l.elements.push({retain:h.retain,insert:(h.insert instanceof Array?h.insert:[h.insert]).map(a=>this.serialize(a))}):h.delete?l.elements.push({retain:h.retain,delete:h.delete}):h.retain&&l.elements.push({retain:h.retain});s.changes.keys.forEach((h,a)=>{h.action==="add"||h.action==="update"?l.attributes.set.push({name:a,value:o.getAttribute(a)}):h.action==="delete"&&l.attributes.delete.push(a)}),r(l)}else if(o instanceof yt){let h={root:!1,target:o.parent?.getAttribute("$id")??void 0,elements:[],attributes:{set:[],delete:[]},text:[]};for(let a of s.changes.delta){let d;a.hasOwnProperty("attributes")&&(d=a.attributes),a.insert?h.text.push({retain:a.retain,insert:a.insert}):a.delete?h.text.push({retain:a.retain,delete:a.delete}):a.retain&&h.text.push({retain:a.retain,attributes:d})}r(h)}else throw new Error("Unexpected target type")}})}applyBackendChanges(t){Ge(this.doc,t)}doUndo(){this._undoManager?.undo()}doRedo(){this._undoManager?.redo()}serialize(t){if(t instanceof S){let e=[],r=t.firstChild;for(;r;){let i=this.serialize(r);i&&e.push(i),r=r.nextSibling}return{element:{tagName:t.nodeName,attributes:t.getAttributes(),children:e}}}else{if(t instanceof yt)return{text:{delta:t.toDelta()}};throw new Error("Unexpected node type "+t)}}doDelete(t){if(t.parent instanceof S){let e=0,r=t.parent.firstChild;for(;r;){if(r===t){t.parent.delete(e,1);return}e++,r=r.nextSibling}throw new Error("Element was not found among parent's children.")}else throw new Error("Cannot delete top-level element.")}createNodes(t){let e=[];for(let r of t)if(r.text){let i=new yt;r.text.delta&&i.applyDelta(r.text.delta),e.push(i)}else if(r.element){let i=new S(r.element.name);if(i.setAttribute("$id",r.element.attributes?.id??Pn()),r.element.attributes)for(let s of Object.keys(r.element.attributes))i.setAttribute(s,r.element.attributes[s]);r.element.children&&i.insert(0,this.createNodes(r.element.children)),e.push(i)}else throw new Error("Unexpected XML data item (not text or element).");return e}doInsertChildren(t,{after:e,index:r,children:i}){let s=null;if(e){for(let o=t.firstChild;o!=null;o=o.nextSibling)if(o instanceof S&&o.getAttribute("$id")===e){s=o;break}if(!s)throw new Error("Unable to find child element to insert after: "+e)}s?t.insertAfter(s,this.createNodes(i)):r!=null?t.insert(r,this.createNodes(i)):t.push(this.createNodes(i))}doDeleteChildren(t,{after:e,index:r,length:i}){if(e){let s=null,o=0;for(let c=t.firstChild;c!=null;c=c.nextSibling){if(c instanceof S&&c.getAttribute("$id")===e){s=c;break}o++}if(!s)throw new Error("Unable to find child element to insert after: "+e);t.delete(o,i)}else{if(r==null)throw new Error("No 'index' specified for deleteChildren.");t.delete(r,i)}}doRemoveAttributes(t,e){for(let r of e)t.removeAttribute(r)}doSetAttributes(t,e){for(let r of Object.keys(e))t.setAttribute(r,e[r])}findNode(t,e=this._y){if(!t)return e;if(e instanceof S){if(e.getAttribute("$id")===t)return e;for(let r=e.firstChild;r!=null;r=r.nextSibling){let i=this.findNode(t,r);if(i)return i}}return null}doInsertText(t,{index:e,text:r,attributes:i}){if(t.nodeName!=="text")throw new Error("Can only insert text in a text node.");t.firstChild.insert(e,r,i)}doFormatText(t,{from:e,length:r,attributes:i}){if(t.nodeName!=="text")throw new Error("Can only format text in a text node.");t.firstChild.format(e,r,i||{})}doDeleteText(t,{index:e,length:r}){if(t.nodeName!=="text")throw new Error("Can only delete text in a text node.");t.firstChild.delete(e,r)}applyChanges(t){for(let e of t){let r=e.nodeID?this.findNode(e.nodeID):this._y;if(r==null)throw new Error("Element was not found for nodeID "+e.nodeID);if(e.delete&&this.doDelete(r),e.insertChildren){if(!(r instanceof S))throw new Error("Cannot insert children into a text node.");this.doInsertChildren(r,e.insertChildren)}if(e.deleteChildren){if(!(r instanceof S))throw new Error("Cannot delete children of a text node.");this.doDeleteChildren(r,e.deleteChildren)}if(e.removeAttributes){if(!(r instanceof S))throw new Error("Cannot remove attributes from a text node.");this.doRemoveAttributes(r,e.removeAttributes)}if(e.setAttributes){if(!(r instanceof S))throw new Error("Cannot set attributes on a text node.");this.doSetAttributes(r,e.setAttributes)}if(e.insertText){if(!(r instanceof S))throw new Error("Node is not a text element.");this.doInsertText(r,e.insertText)}if(e.formatText){if(!(r instanceof S))throw new Error("Node is not a text element.");this.doFormatText(r,e.formatText)}if(e.deleteText){if(!(r instanceof S))throw new Error("Node is not a text element.");this.doDeleteText(r,e.deleteText)}e.undo&&this.doUndo(),e.redo&&this.doRedo()}}};var Pe=tr(Kn()),Ke=tr(Kn());function We(n){let t="";for(let r=0;r<n.length;r+=32768)t+=String.fromCharCode(...n.subarray(r,r+32768));return(0,Ke.encode)(t)}function tc(n){let t=(0,Ke.decode)(n),e=t.length,r=new Uint8Array(e);for(let i=0;i<e;i++)r[i]=t.charCodeAt(i);return r}var Wn=class{constructor(t){this.doc=new ot,this.doc.on("update",t)}update(t){Ge(this.doc,t)}},Zn=new Map,lt=new Map;function ec(n){let t=lt.get(n.documentID);if(!t)throw new Error("cannot apply changes, document was not registered "+n.documentID);t.applyChanges(n.changes)}function nc(n,t){let e=lt.get(n);if(!e)throw new Error("Document not registered: "+n);let r;if(t){let i=Pe.default.decode(t),s=Uint8Array.from(i,o=>o.charCodeAt(0));r=Yn(e.doc,s)}else r=Yn(e.doc);return We(r)}function rc(n){let t=lt.get(n);if(!t)throw new Error("Document not registered: "+n);let e=li(t.doc);return We(e)}function ic(n,t){let e=lt.get(n);if(!e)throw new Error("cannot apply changes, document was not registered "+n);let r=Uint8Array.from(Pe.default.decode(t),s=>s.charCodeAt(0));e.applyBackendChanges(r);let i=Zn.get(n);if(i){let s=i.doc.get("xml",S)}}function sc(n,t,e=!1,r,i){if(lt.get(n))throw new Error("document is already registered "+n);let s=new Wn(c=>{let l=JSON.stringify({documentID:n,data:We(c)}),h=r??onSendUpdateToBackend;h&&h(l)}),o=new Rt(s.doc,e,c=>{let l=JSON.stringify({documentID:n,data:c}),h=i??onSendUpdateToClient;h&&h(l)});if(t){let c=Uint8Array.from(Pe.default.decode(t),l=>l.charCodeAt(0));o.applyBackendChanges(c)}lt.set(n,o),Zn.set(n,s)}function oc(n){if(!lt.has(n))throw new Error("document was not registered "+n);lt.delete(n),Zn.delete(n)}return Gi(cc);})();
/*! Bundled license information:

base-64/base64.js:
  (*! https://mths.be/base64 v1.0.0 by @mathias | MIT license *)
*/
