"use strict";var meshagent=(()=>{var Oi=Object.create;var fe=Object.defineProperty;var Li=Object.getOwnPropertyDescriptor;var Mi=Object.getOwnPropertyNames;var Ri=Object.getPrototypeOf,Bi=Object.prototype.hasOwnProperty;var Fi=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),Yi=(n,t)=>{for(var e in t)fe(n,e,{get:t[e],enumerable:!0})},Kn=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Mi(t))!Bi.call(n,i)&&i!==e&&fe(n,i,{get:()=>t[i],enumerable:!(r=Li(t,i))||r.enumerable});return n};var Xi=(n,t,e)=>(e=n!=null?Oi(Ri(n)):{},Kn(t||!n||!n.__esModule?fe(e,"default",{value:n,enumerable:!0}):e,n)),ji=n=>Kn(fe({},"__esModule",{value:!0}),n);var Ni=Fi((Pe,ue)=>{(function(n){var t=typeof Pe=="object"&&Pe,e=typeof ue=="object"&&ue&&ue.exports==t&&ue,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,Vi=u.length-f;++p<Vi;)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})(Pe)});var ic={};Yi(ic,{ServerXmlDocument:()=>Bt,applyBackendChanges:()=>ec,applyChanges:()=>Zo,getState:()=>Qo,getStateVector:()=>tc,registerDocument:()=>nc,unregisterDocument:()=>rc});var v=()=>new Map,ge=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},Wn=(n,t)=>{let e=[];for(let[r,i]of n)e.push(t(i,r));return e},Zn=(n,t)=>{for(let[e,r]of n)if(t(r,e))return!0;return!1};var P=()=>new Set;var pe=n=>n[n.length-1];var Qn=(n,t)=>{for(let e=0;e<t.length;e++)n.push(t[e])},G=Array.from;var tr=(n,t)=>{for(let e=0;e<n.length;e++)if(t(n[e],e,n))return!0;return!1};var Yt=Array.isArray;var Xt=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 G((this._observers.get(t)||v()).values()).forEach(r=>r(...e))}destroy(){this._observers=v()}};var R=Math.floor;var kt=Math.abs;var me=(n,t)=>n<t?n:t,K=(n,t)=>n>t?n:t,cc=Number.isNaN;var we=n=>n!==0?n<0:1/n<0;var Ze=Number.MAX_SAFE_INTEGER,lc=Number.MIN_SAFE_INTEGER,ac=1<<31;var er=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&R(n)===n),hc=Number.isNaN,dc=Number.parseInt;var Gi=String.fromCharCode,uc=String.fromCodePoint,fc=Gi(65535),zi=n=>n.toLowerCase(),$i=/^\s*/g,Hi=n=>n.replace($i,""),Ji=/([A-Z])/g,Qe=(n,t)=>Hi(n.replace(Ji,e=>`${t}${zi(e)}`));var qi=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},St=typeof TextEncoder<"u"?new TextEncoder:null,Pi=n=>St.encode(n),rr=St?Pi:qi;var Et=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Et&&Et.decode(new Uint8Array).length===1&&(Et=null);var at=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},Gt=()=>new at;var Ki=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(Ki(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},Wi=(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 be=A;var y=(n,t)=>{for(;t>127;)A(n,128|127&t),t=R(t/128);A(n,127&t)},ke=(n,t)=>{let e=we(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)},en=new Uint8Array(3e4),Zi=en.length/3,Qi=(n,t)=>{if(t.length<Zi){let e=St.encodeInto(t,en).written||0;y(n,e);for(let r=0;r<e;r++)A(n,en[r])}else N(n,rr(t))},ts=(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=St&&St.encodeInto?Qi:ts;var zt=(n,t)=>{let e=n.cbuf.length,r=n.cpos,i=me(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)},nn=(n,t)=>{Wi(n,t);let e=new DataView(n.cbuf.buffer,n.cpos,t);return n.cpos+=t,e},es=(n,t)=>nn(n,4).setFloat32(0,t,!1),ns=(n,t)=>nn(n,8).setFloat64(0,t,!1),rs=(n,t)=>nn(n,8).setBigInt64(0,t,!1);var sr=new DataView(new ArrayBuffer(4)),is=n=>(sr.setFloat32(0,n),sr.getFloat32(0)===n),_t=(n,t)=>{switch(typeof t){case"string":A(n,119),ht(n,t);break;case"number":er(t)&&kt(t)<=2147483647?(A(n,125),ke(n,t)):is(t)?(A(n,124),es(n,t)):(A(n,123),ns(n,t));break;case"bigint":A(n,122),rs(n,t);break;case"object":if(t===null)A(n,126);else if(Yt(t)){A(n,117),y(n,t.length);for(let e=0;e<t.length;e++)_t(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),_t(n,t[i])}}break;case"boolean":A(n,t?120:121);break;default:A(n,127)}},jt=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 or=n=>{n.count>0&&(ke(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++:(or(this),this.count=1,this.s=t)}toUint8Array(){return or(this),F(this.encoder)}};var cr=n=>{if(n.count>0){let t=n.diff*2+(n.count===1?0:1);ke(n.encoder,t),n.count>1&&y(n.encoder,n.count-2)}},Ut=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++):(cr(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return cr(this),F(this.encoder)}},xe=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 z=n=>new Error(n),Y=()=>{throw z("Method unimplemented")},X=()=>{throw z("Unexpected case")};var ar=z("Unexpected end of array"),hr=z("Integer out of Range"),At=class{constructor(t){this.arr=t,this.pos=0}},pt=n=>new At(n),dr=n=>n.pos!==n.arr.length;var os=(n,t)=>{let e=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,t);return n.pos+=t,e},V=n=>os(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>Ze)throw hr}throw ar},Se=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>Ze)throw hr}throw ar};var cs=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))}},ls=n=>Et.decode(V(n)),ft=Et?ls:cs;var rn=(n,t)=>{let e=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,t);return n.pos+=t,e},as=n=>rn(n,4).getFloat32(0,!1),hs=n=>rn(n,8).getFloat64(0,!1),ds=n=>rn(n,8).getBigInt64(0,!1);var us=[n=>{},n=>null,Se,as,hs,ds,n=>!1,n=>!0,ft,n=>{let t=m(n),e={};for(let r=0;r<t;r++){let i=ft(n);e[i]=Dt(n)}return e},n=>{let t=m(n),e=[];for(let r=0;r<t;r++)e.push(Dt(n));return e},V],Dt=n=>us[127-ut(n)](n),$t=class extends At{constructor(t,e){super(t),this.reader=e,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),dr(this)?this.count=m(this)+1:this.count=-1),this.count--,this.s}};var gt=class extends At{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Se(this);let t=we(this.s);this.count=1,t&&(this.s=-this.s,this.count=m(this)+2)}return this.count--,this.s}};var Tt=class extends At{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let t=Se(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}},Ee=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 mc=crypto.subtle,ur=crypto.getRandomValues.bind(crypto);var sn=()=>ur(new Uint32Array(1))[0];var gs="10000000-1000-4000-8000"+-1e11,fr=()=>gs.replace(/[018]/g,n=>(n^sn()&15>>n/4).toString(16));var Ce=Date.now;var on=n=>new Promise(n);var xc=Promise.all.bind(Promise);var cn=n=>n===void 0?null:n;var ln=class{constructor(){this.map=new Map}setItem(t,e){this.map.set(t,e)}getItem(t){return this.map.get(t)}},pr=new ln,ys=!0;try{typeof localStorage<"u"&&localStorage&&(pr=localStorage,ys=!1)}catch{}var mr=pr;var yr=Object.assign,bs=Object.keys,xr=(n,t)=>{for(let e in n)t(n[e],e)};var wr=n=>bs(n).length;var br=n=>{for(let t in n)return!1;return!0},ks=(n,t)=>{for(let e in n)if(!t(n[e],e))return!1;return!0},Es=(n,t)=>Object.prototype.hasOwnProperty.call(n,t),kr=(n,t)=>n===t||wr(n)===wr(t)&&ks(n,(e,r)=>(e!==void 0||Es(t,r))&&t[r]===e),Ss=Object.freeze,an=n=>{for(let t in n){let e=n[t];(typeof e=="object"||typeof e=="function")&&an(n[t])}return Ss(n)};var Ht=(n,t,e=0)=>{try{for(;e<n.length;e++)n[e](...t)}finally{e<n.length&&Ht(n,t,e+1)}};var Er=n=>n;var Sr=(n,t)=>t.includes(n);var Jt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]";var bc=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,$,_s=[],Us=()=>{if($===void 0)if(Jt){$=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):_s.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(`--${Qe(t,"-")}`,e),$.set(`-${Qe(t,"-")}`,e)}})):$=v();return $},hn=n=>Us().has(n);var qt=n=>Jt?cn(Ur[n.toUpperCase().replaceAll("-","_")]):cn(mr.getItem(n));var _r=n=>hn("--"+n)||qt(n)!==null,Ur=_r("production"),As=Jt&&Sr(Ur.FORCE_COLOR,["true","1","2"]),Ar=As||!hn("--no-colors")&&!_r("no-color")&&(!Jt||process.stdout.isTTY)&&(!Jt||hn("--color")||qt("COLORTERM")!==null||(qt("TERM")||"").includes("color"));var Ds=n=>new Uint8Array(n);var Tr=n=>{let t=Ds(n.byteLength);return t.set(n),t};var dn=class{constructor(t,e){this.left=t,this.right=e}},H=(n,t)=>new dn(n,t);var mt=typeof document<"u"?document:{};var kc=typeof DOMParser<"u"?new DOMParser:null;var Ir=n=>Wn(n,(t,e)=>`${e}:${t};`).join("");var Ec=mt.ELEMENT_NODE,Sc=mt.TEXT_NODE,Cc=mt.CDATA_SECTION_NODE,_c=mt.COMMENT_NODE,Uc=mt.DOCUMENT_NODE,Ac=mt.DOCUMENT_TYPE_NODE,Dc=mt.DOCUMENT_FRAGMENT_NODE;var J=Symbol;var Pt=J(),Kt=J(),un=J(),fn=J(),gn=J(),Wt=J(),pn=J(),It=J(),mn=J(),vr=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 Tc=Ce();var Os={[Pt]:H("font-weight","bold"),[Kt]:H("font-weight","normal"),[un]:H("color","blue"),[gn]:H("color","green"),[fn]:H("color","grey"),[Wt]:H("color","red"),[pn]:H("color","purple"),[It]:H("color","orange"),[mn]:H("color","black")},Ls=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=Os[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=Ir(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},Nr=Ar?Ls:vr,Vr=(...n)=>{console.log(...Nr(n)),Or.forEach(t=>t.print(n))},wn=(...n)=>{console.warn(...Nr(n)),n.unshift(It),Or.forEach(t=>t.print(n))};var Or=P();var Lr=n=>({[Symbol.iterator](){return this},next:n}),Mr=(n,t)=>Lr(()=>{let e;do e=n.next();while(!e.done&&!t(e.value));return e}),_e=(n,t)=>Lr(()=>{let{done:e,value:r}=n.next();return{done:e,value:e?void 0:t(r)}});var Qt=class{constructor(t,e){this.clock=t,this.len=e}},st=class{constructor(){this.clients=new Map}},Nt=(n,t,e)=>t.clients.forEach((r,i)=>{let s=n.doc.store.clients.get(i);for(let o=0;o<r.length;o++){let c=r[o];ci(n,s,c.clock,c.len,e)}}),Ys=(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},de=(n,t)=>{let e=n.clients.get(t.client);return e!==void 0&&Ys(e,t.clock)!==null},Ln=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})},xn=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++)Qn(s,n[o].clients.get(i)||[]);t.clients.set(i,s)}});return Ln(t),t},te=(n,t,e,r)=>{j(n.clients,t,()=>[]).push(new Qt(e,r))},Qr=()=>new st,Xs=n=>{let t=Qr();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 Qt(c,l))}}i.length>0&&t.clients.set(r,i)}),t},Mt=(n,t)=>{y(n.restEncoder,t.clients.size),G(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)}})},Mn=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 Qt(n.readDsClock(),n.readDsLen()))}}return t},Fr=(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&&te(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 te(r,o,d,u-d)}}if(r.clients.size>0){let s=new W;return y(s.restEncoder,0),Mt(s,r),s.toUint8Array()}return null};var ti=sn,ot=class n extends Xt{constructor({guid:t=fr(),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=ti(),this.guid=t,this.collectionid=e,this.share=new Map,this.store=new Re,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=on(h=>{this.on("load",()=>{this.isLoaded=!0,h(this)})});let l=()=>on(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(G(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,je)}getText(t=""){return this.get(t,ce)}getMap(t=""){return this.get(t,se)}getXmlElement(t=""){return this.get(t,S)}getXmlFragment(t=""){return this.get(t,Ot)}toJSON(){let t={};return this.share.forEach((e,r)=>{t[r]=e.toJSON()}),t}destroy(){this.isDestroyed=!0,G(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()}},Ne=class{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return m(this.restDecoder)}readDsLen(){return m(this.restDecoder)}},Ve=class extends Ne{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 Dt(this.restDecoder)}readBuf(){return Tr(V(this.restDecoder))}readJSON(){return JSON.parse(ft(this.restDecoder))}readKey(){return ft(this.restDecoder)}},bn=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 bn{constructor(t){super(t),this.keys=[],m(t),this.keyClockDecoder=new Tt(V(t)),this.clientDecoder=new gt(V(t)),this.leftClockDecoder=new Tt(V(t)),this.rightClockDecoder=new Tt(V(t)),this.infoDecoder=new $t(V(t),ut),this.stringDecoder=new Ee(V(t)),this.parentInfoDecoder=new $t(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 Dt(this.restDecoder)}readBuf(){return V(this.restDecoder)}readJSON(){return Dt(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}}},Oe=class{constructor(){this.restEncoder=Gt()}toUint8Array(){return F(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){y(this.restEncoder,t)}writeDsLen(t){y(this.restEncoder,t)}},wt=class extends Oe{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){be(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){_t(this.restEncoder,t)}writeBuf(t){N(this.restEncoder,t)}writeJSON(t){ht(this.restEncoder,JSON.stringify(t))}writeKey(t){ht(this.restEncoder,t)}},Le=class{constructor(){this.restEncoder=Gt(),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 Le{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Ut,this.clientEncoder=new dt,this.leftClockEncoder=new Ut,this.rightClockEncoder=new Ut,this.infoEncoder=new jt(be),this.stringEncoder=new xe,this.parentInfoEncoder=new jt(be),this.typeRefEncoder=new dt,this.lenEncoder=new dt}toUint8Array(){let t=Gt();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){_t(this.restEncoder,t)}writeBuf(t){N(this.restEncoder,t)}writeJSON(t){_t(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)}},js=(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)},Rn=(n,t,e)=>{let r=new Map;e.forEach((i,s)=>{_(t,s)>i&&r.set(s,i)}),He(t).forEach((i,s)=>{e.has(s)||r.set(s,0)}),y(n.restEncoder,r.size),G(r.entries()).sort((i,s)=>s[0]-i[0]).forEach(([i,s])=>{js(n,t.clients.get(i),i,s)})},Gs=(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,Ai(n,a));o[h]=u,l+=u.length}}}}return e},zs=(n,t,e)=>{let r=[],i=G(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 Re,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 Rn(f,c,new Map),y(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},$s=(n,t)=>Rn(n,t.doc.store,t.beforeState),Hs=(n,t,e,r=new ct(n))=>k(t,i=>{i.local=!1;let s=!1,o=i.doc,c=o.store,l=Gs(r,o),h=zs(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=Fe([a.update,h.update])}}else c.pendingStructs=h;let d=Fr(r,i,c);if(c.pendingDs){let u=new ct(pt(c.pendingDs));m(u.restDecoder);let f=Fr(u,i,c);d&&f?c.pendingDs=Fe([d,f]):c.pendingDs=d||f}else c.pendingDs=d;if(s){let u=c.pendingStructs.update;c.pendingStructs=null,ei(i.doc,u)}},e,!1);var ei=(n,t,e,r=ct)=>{let i=pt(t);Hs(i,n,e,new r(i))},$e=(n,t,e)=>ei(n,t,e,Ve),Js=(n,t,e=new Map)=>{Rn(n,t.store,e),Mt(n,Xs(t.store))},qs=(n,t=new Uint8Array([0]),e=new W)=>{let r=ni(t);Js(e,n,r);let i=[e.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(co(n.store.pendingStructs.update,t)),i.length>1){if(e.constructor===wt)return so(i.map((s,o)=>o===0?s:ao(s)));if(e.constructor===W)return Fe(i)}return i[0]},Bn=(n,t)=>qs(n,t,new wt),Ps=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},ni=n=>Ps(new Ne(pt(n))),ri=(n,t)=>(y(n.restEncoder,t.size),G(t.entries()).sort((e,r)=>r[0]-e[0]).forEach(([e,r])=>{y(n.restEncoder,e),y(n.restEncoder,r)}),n),Ks=(n,t)=>ri(n,He(t.store)),Ws=(n,t=new Le)=>(n instanceof Map?ri(t,n):Ks(t,n),t.toUint8Array()),ii=n=>Ws(n,new Oe),kn=class{constructor(){this.l=[]}},Yr=()=>new kn,Xr=(n,t)=>n.l.push(t),jr=(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.")},si=(n,t,e)=>Ht(n.l,[t,e]),it=class{constructor(t,e){this.client=t,this.clock=e}},Ue=(n,t)=>n===t||n!==null&&t!==null&&n.client===t.client&&n.clock===t.clock,w=(n,t)=>new it(n,t);var Zs=n=>{for(let[t,e]of n.doc.share.entries())if(e===n)return t;throw X()},Me=(n,t)=>{for(;t!==null;){if(t.parent===n)return!0;t=t.parent._item}return!1};var En=class{constructor(t,e){this.ds=t,this.sv=e}};var Qs=(n,t)=>new En(n,t),Yc=Qs(Qr(),new Map);var vt=(n,t)=>t===void 0?!n.deleted:t.sv.has(n.id.client)&&(t.sv.get(n.id.client)||0)>n.id.clock&&!de(t.ds,n.id),Sn=(n,t)=>{let e=j(n.meta,Sn,P),r=n.doc.store;e.has(t)||(t.sv.forEach((i,s)=>{i<_(r,s)&&O(n,w(s,i))}),Nt(n,t.ds,i=>{}),e.add(t))};var Re=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},He=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},oi=(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()},to=(n,t)=>{let e=n.clients.get(t.client);return e[q(e,t.clock)]},Te=to,Cn=(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[Cn(n,e,t.clock)]},Gr=(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},eo=(n,t,e)=>{let r=n.clients.get(t.id.client);r[q(r,t.id.clock)]=e},ci=(n,t,e,r,i)=>{if(r===0)return;let s=e+r,o=Cn(n,t,e),c;do c=t[o++],s<c.id.clock+c.length&&Cn(n,t,s),i(c);while(o<t.length&&t[o].id.clock<s)},_n=class{constructor(t,e,r){this.doc=t,this.deleteSet=new st,this.beforeState=He(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}},zr=(n,t)=>t.deleteSet.clients.size===0&&!Zn(t.afterState,(e,r)=>t.beforeState.get(r)!==e)?!1:(Ln(t.deleteSet),$s(n,t),Mt(n,t.deleteSet),!0),$r=(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)},Ie=(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},no=(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)}}}},ro=(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=me(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+Ie(i,l)}})};var li=(n,t)=>{if(t<n.length){let e=n[t],r=e.doc,i=r.store,s=e.deleteSet,o=e._mergeStructs;try{Ln(s),e.afterState=He(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),si(h._dEH,l,e))})}),c.push(()=>r.emit("afterTransaction",[e,r])),Ht(c,[]),e._needFormattingCleanup&&ko(e)}finally{r.gc&&no(s,i,r.gcFilter),ro(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+Ie(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&&Ie(f,g+1)>1||g>0&&Ie(f,g)}if(!e.local&&e.afterState.get(r.clientID)!==e.beforeState.get(r.clientID)&&(Vr(It,Pt,"[yjs] ",Kt,Wt,"Changed the client-id because another client seems to be using it."),r.clientID=ti()),r.emit("afterTransactionCleanup",[e,r]),r._observers.has("update")){let a=new wt;zr(a,e)&&r.emit("update",[a.toUint8Array(),e.origin,r,e])}if(r._observers.has("updateV2")){let a=new W;zr(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])):li(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 _n(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&&li(i,0)}}return o},Un=class{constructor(t,e){this.insertions=e,this.deletions=t,this.meta=new Map}},Hr=(n,t,e)=>{Nt(n,e.deletions,r=>{r instanceof E&&t.scope.some(i=>i===n.doc||Me(i,r))&&Gn(r,!1)})},Jr=(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;Nt(c,h.insertions,f=>{if(f instanceof E){if(f.redone!==null){let{item:g,diff:p}=Ho(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||Me(g,f))&&d.push(f)}}),Nt(c,h.deletions,f=>{f instanceof E&&s.some(g=>g===c.doc||Me(g,f))&&!de(h.insertions,f.id)&&a.add(f)}),a.forEach(f=>{u=Ui(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},Be=class extends Xt{constructor(t,{captureTimeout:e=500,captureTransaction:r=l=>!0,deleteFilter:i=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:c=Yt(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&&te(u,b,tt,I)});let f=Ce(),g=!1;if(this.lastChange>0&&f-this.lastChange<this.captureTimeout&&d.length>0&&!h&&!a){let x=d[d.length-1];x.deletions=xn([x.deletions,l.deleteSet]),x.insertions=xn([x.insertions,u])}else d.push(new Un(l.deleteSet,u)),g=!0;!h&&!a&&(this.lastChange=f),Nt(l,l.deleteSet,x=>{x instanceof E&&this.scope.some(b=>b===l.doc||Me(b,x))&&Gn(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=Yt(t)?t:[t],t.forEach(r=>{e.has(r)||(e.add(r),(r instanceof C?r.doc!==this.doc:r!==this.doc)&&wn("[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=>Hr(r,this,i)),this.undoStack=[]),e&&(this.redoStack.forEach(i=>Hr(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=Jr(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=Jr(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*io(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,Ai(n,c));yield h,s+=h.length}else{let l=n.readLen();yield new L(w(i,s),l),s+=l}}}}var ee=class{constructor(t,e){this.gen=io(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 ne=class{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}},so=n=>Fe(n,Ve,wt);var oo=(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))}},Fe=(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 ee(a,!0)),s=null,o=new e,c=new ne(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=oo(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),Fn(c);let l=r.map(a=>Mn(a)),h=xn(l);return Mt(o,h),o.toUint8Array()},co=(n,t,e=ct,r=W)=>{let i=ni(t),s=new r,o=new ne(s),c=new e(pt(n)),l=new ee(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()}Fn(o);let h=Mn(c);return Mt(s,h),s.toUint8Array()};var ai=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:F(n.encoder.restEncoder)}),n.encoder.restEncoder=Gt(),n.written=0)},nt=(n,t,e)=>{n.written>0&&n.currClient!==t.id.client&&ai(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++},Fn=n=>{ai(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)}},lo=(n,t,e,r)=>{let i=new e(pt(n)),s=new ee(i,!1),o=new r,c=new ne(o);for(let h=s.curr;h!==null;h=s.next())nt(c,t(h),0);Fn(c);let l=Mn(i);return Mt(o,l),o.toUint8Array()};var ao=n=>lo(n,Er,ct,wt),qr="You must not compute changes after the event-handler fired.",Vt=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=ho(this.currentTarget,this.target))}deletes(t){return de(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw z(qr);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=pe(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",c=pe(l.content.getContent())):(o="add",c=void 0)}else if(this.deletes(s))o="delete",c=pe(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 z(qr);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}},ho=(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=()=>{wn("Invalid access: Add Yjs type to a document before reading data.")},hi=80,Yn=0,An=class{constructor(t,e){t.marker=!0,this.p=t,this.index=e,this.timestamp=Yn++}},uo=n=>{n.timestamp=Yn++},di=(n,t,e)=>{n.p.marker=!1,n.p=t,t.marker=!0,n.index=e,n.timestamp=Yn++},fo=(n,t,e)=>{if(n.length>=hi){let r=n.reduce((i,s)=>i.timestamp<s.timestamp?i:s);return di(r,t,e),r}else{let r=new An(t,e);return n.push(r),r}},Je=(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)=>kt(t-s.index)<kt(t-o.index)?s:o),r=n._start,i=0;for(e!==null&&(r=e.p,i=e.index,uo(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&&kt(e.index-i)<r.parent.length/hi?(di(e,r,i),e):fo(n._searchMarker,r,i)},re=(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 qe=(n,t,e)=>{let r=n,i=t.changedParentTypes;for(;j(i,n,()=>[]).push(e),n._item!==null;)n=n._item.parent;si(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=Yr(),this._dEH=Yr(),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){Xr(this._eH,t)}observeDeep(t){Xr(this._dEH,t)}unobserve(t){jr(this._eH,t)}unobserveDeep(t){jr(this._dEH,t)}toJSON(){}},ui=(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},fi=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 ie=(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}},gi=(n,t)=>{let e=[];return ie(n,(r,i)=>{e.push(t(r,i,n))}),e},go=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}}}},pi=(n,t)=>{n.doc??T();let e=Je(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}},Ye=(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 Lt(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 ae(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 he(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()},mi=()=>z("Length exceeded!"),wi=(n,t,e,r)=>{if(e>t._length)throw mi();if(e===0)return t._searchMarker&&re(t._searchMarker,e,r.length),Ye(n,t,null,r);let i=e,s=Je(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&&re(t._searchMarker,i,r.length),Ye(n,t,o,r)},po=(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 Ye(n,t,i,e)},yi=(n,t,e,r)=>{if(r===0)return;let i=e,s=r,o=Je(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 mi();t._searchMarker&&re(t._searchMarker,i,-s+r)},Xe=(n,t,e)=>{let r=t._map.get(e);r!==void 0&&r.delete(n)},Xn=(n,t,e,r)=>{let i=t._map.get(e)||null,s=n.doc,o=s.clientID,c;if(r==null)c=new Lt([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:c=new Lt([r]);break;case Uint8Array:c=new ae(r);break;case ot:c=new he(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)},jn=(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},xi=n=>{let t={};return n.doc??T(),n._map.forEach((e,r)=>{e.deleted||(t[r]=e.content.getContent()[e.length-1])}),t},bi=(n,t)=>{n.doc??T();let e=n._map.get(t);return e!==void 0&&!e.deleted};var mo=(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&&vt(s,t)&&(e[i]=s.content.getContent()[s.length-1])}),e},Ae=n=>(n.doc??T(),Mr(n._map.entries(),t=>!t[1].deleted)),Dn=class extends Vt{},je=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),qe(this,t,new Dn(this,t))}insert(t,e){this.doc!==null?k(this.doc,r=>{wi(r,this,t,e)}):this._prelimContent.splice(t,0,...e)}push(t){this.doc!==null?k(this.doc,e=>{po(e,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,e=1){this.doc!==null?k(this.doc,r=>{yi(r,this,t,e)}):this._prelimContent.splice(t,e)}get(t){return pi(this,t)}toArray(){return fi(this)}slice(t=0,e=this.length){return ui(this,t,e)}toJSON(){return this.map(t=>t instanceof C?t.toJSON():t)}map(t){return gi(this,t)}forEach(t){ie(this,t)}[Symbol.iterator](){return go(this)}_write(t){t.writeTypeRef(Bo)}},wo=n=>new je,Tn=class extends Vt{constructor(t,e,r){super(t,e),this.keysChanged=r}},se=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){qe(this,t,new Tn(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[...Ae(this)].length}keys(){return _e(Ae(this),t=>t[0])}values(){return _e(Ae(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return _e(Ae(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=>{Xe(e,this,t)}):this._prelimContent.delete(t)}set(t,e){return this.doc!==null?k(this.doc,r=>{Xn(r,this,t,e)}):this._prelimContent.set(t,e),e}get(t){return jn(this,t)}has(t){return bi(this,t)}clear(){this.doc!==null?k(this.doc,t=>{this.forEach(function(e,r,i){Xe(t,i,r)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Fo)}},yo=n=>new se,rt=(n,t)=>n===t||typeof n=="object"&&typeof t=="object"&&n&&t&&kr(n,t),oe=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||Rt(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}},Pr=(n,t,e)=>{for(;t.right!==null&&e>0;){switch(t.right.content.constructor){case U:t.right.deleted||Rt(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},De=(n,t,e,r)=>{let i=new Map,s=r?Je(t,e):null;if(s){let o=new oe(s.p.left,s.p,s.index,i);return Pr(n,o,e-s.index)}else{let o=new oe(null,t._start,0,i);return Pr(n,o,e)}},ki=(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()})},Rt=(n,t)=>{let{key:e,value:r}=t;r===null?n.delete(e):n.set(e,r)},Ei=(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()}},Si=(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},yn=(n,t,e,r,i)=>{e.currentAttributes.forEach((u,f)=>{i[f]===void 0&&(i[f]=null)});let s=n.doc,o=s.clientID;Ei(e,i);let c=Si(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&&re(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(),ki(n,t,e,c)},Kr=(n,t,e,r,i)=>{let s=n.doc,o=s.clientID;Ei(e,i);let c=Si(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()}ki(n,t,e,c)},Ci=(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&&Rt(i,h);break}}}t=t.right}return c},xo=(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}},bo=n=>{let t=0;return k(n.doc,e=>{let r=n._start,i=n._start,s=v(),o=ge(s);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case U:Rt(o,i.content);break;default:t+=Ci(e,r,i,s,o),s=ge(o),r=i;break}i=i.right}}),t},ko=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&&ci(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=>{Nt(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):xo(r,i)});for(let i of t)bo(i)})},Wr=(n,t,e)=>{let r=e,i=ge(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&&Ci(n,s,t.right,i,t.currentAttributes);let o=(t.left||t.right).parent;return o._searchMarker&&re(o._searchMarker,t.index,-r+e),t},In=class extends Vt{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},br(l)||(f.attributes=yr({},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(),Rt(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}},ce=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 In(this,t,e);qe(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 oe(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)&&yn(r,this,i,c,o.attributes||{})}else o.retain!==void 0?Kr(r,this,i,o.retain,o.attributes||{}):o.delete!==void 0&&Wr(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(vt(l,t)||e!==void 0&&vt(l,e))switch(l.content.constructor){case Z:{let d=s.get("ychange");t!==void 0&&!vt(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&&!vt(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:vt(l,t)&&(h(),Rt(s,l.content));break}l=l.right}h()};return t||e?k(o,d=>{t&&Sn(d,t),e&&Sn(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=De(s,this,t,!r);r||(r={},o.currentAttributes.forEach((c,l)=>{r[l]=c})),yn(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=De(s,this,t,!r);yn(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=>{Wr(i,De(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=De(s,this,t,!1);o.right!==null&&Kr(s,this,o,e,r)}):this._pending.push(()=>this.format(t,e,r))}removeAttribute(t){this.doc!==null?k(this.doc,e=>{Xe(e,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,e){this.doc!==null?k(this.doc,r=>{Xn(r,this,t,e)}):this._pending.push(()=>this.setAttribute(t,e))}getAttribute(t){return jn(this,t)}getAttributes(){return xi(this)}_write(t){t.writeTypeRef(Yo)}},Eo=n=>new ce,Zt=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===Ot)&&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})}},Ot=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 Zt(this,t)}querySelector(t){t=t.toUpperCase();let r=new Zt(this,i=>i.nodeName&&i.nodeName.toUpperCase()===t).next();return r.done?null:r.value}querySelectorAll(t){return t=t.toUpperCase(),G(new Zt(this,e=>e.nodeName&&e.nodeName.toUpperCase()===t))}_callObserver(t,e){qe(this,t,new vn(this,e,t))}toString(){return gi(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),ie(this,s=>{i.insertBefore(s.toDOM(t,e,r),null)}),i}insert(t,e){this.doc!==null?k(this.doc,r=>{wi(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;Ye(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 z("Reference item not found");r.splice(i,0,...e)}}delete(t,e=1){this.doc!==null?k(this.doc,r=>{yi(r,this,t,e)}):this._prelimContent.splice(t,e)}toArray(){return fi(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return pi(this,t)}slice(t=0,e=this.length){return ui(this,t,e)}forEach(t){ie(this,t)}_write(t){t.writeTypeRef(jo)}},So=n=>new Ot,S=class n extends Ot{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 xr(e,(r,i)=>{typeof r=="string"&&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=>{Xe(e,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,e){this.doc!==null?k(this.doc,r=>{Xn(r,this,t,e)}):this._prelimAttrs.set(t,e)}getAttribute(t){return jn(this,t)}hasAttribute(t){return bi(this,t)}getAttributes(t){return t?mo(this,t):xi(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 ie(this,o=>{i.appendChild(o.toDOM(t,e,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(t){t.writeTypeRef(Xo),t.writeKey(this.nodeName)}},Co=n=>new S(n.readKey()),vn=class extends Vt{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)})}},Nn=class n extends se{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(Go),t.writeKey(this.hookName)}},_o=n=>new Nn(n.readKey()),yt=class n extends ce{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(zo)}},Uo=n=>new yt,le=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()}},Ao=0,L=class extends le{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),oi(t.doc.store,this)}write(t,e){t.writeInfo(Ao),t.writeLen(this.length-e)}getMissing(t,e){return null}},ae=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}},Do=n=>new ae(n.readBuf()),Ge=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){te(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}},To=n=>new Ge(n.readLen()),_i=(n,t)=>new ot({guid:n,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),he=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(_i(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}},Io=n=>new he(_i(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}},No=n=>new U(n.readKey(),n.readJSON()),Vn=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}},Vo=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 Vn(e)},Oo=qt("node_env")==="development",Lt=class n{constructor(t){this.arr=t,Oo&&an(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}},Lo=n=>{let t=n.readLen(),e=[];for(let r=0;r<t;r++)e.push(n.readAny());return new Lt(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}},Mo=n=>new Z(n.readString()),Ro=[wo,yo,Eo,Co,So,_o,Uo],Bo=0,Fo=1,Yo=2,Xo=3,jo=4,Go=5,zo=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}},$o=n=>new Q(Ro[n.readTypeRef()](n)),Ho=(n,t)=>{let e=t,r=0,i;do r>0&&(e=w(e.client,e.clock+r)),i=Te(n,e),r=e.clock-i.id.clock,e=i.redone;while(e!==null&&i instanceof E);return{item:i,diff:r}},Gn=(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},Zr=(n,t)=>tr(n,e=>de(e.deletions,t)),Ui=(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)||Ui(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||de(r,d.right.id)||Zr(s.undoStack,d.right.id)||Zr(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,Gn(x,!0),x.integrate(n,0),x},E=class n extends le{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=Gr(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=Te(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=Gr(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),Ue(this.origin,i.origin)){if(i.id.client<this.id.client)r=i,s.clear();else if(Ue(this.rightOrigin,i.rightOrigin))break}else if(i.origin!==null&&o.has(Te(t.doc.store,i.origin)))s.has(Te(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),oi(t.doc.store,this),this.content.integrate(t,this),$r(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&&Ue(t.origin,this.lastId)&&this.right===t&&Ue(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(),te(t.deleteSet,this.id.client,this.id.clock,this.length),$r(t,e,this.parentSub),this.content.delete(t)}}gc(t,e){if(!this.deleted)throw X();this.content.gc(t),e?eo(t,this,new L(this.id,this.length)):this.content=new Ge(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=Zs(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)}},Ai=(n,t)=>Jo[t&31](n),Jo=[()=>{X()},To,Vo,Do,Mo,vo,No,$o,Lo,Io,()=>{X()}],qo=10,M=class extends le{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(qo),y(t.restEncoder,this.length-e)}getMissing(t,e){return null}},Di=typeof globalThis<"u"?globalThis:typeof window<"u"||typeof window<"u"?window:{},Ti="__ $YJS$ __";Di[Ti]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Di[Ti]=!0;var D=[];for(let n=0;n<256;++n)D.push((n+256).toString(16).slice(1));function vi(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 zn,Po=new Uint8Array(16);function $n(){if(!zn){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");zn=crypto.getRandomValues.bind(crypto)}return zn(Po)}var Ko=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Hn={randomUUID:Ko};function Wo(n,t,e){if(Hn.randomUUID&&!t&&!n)return Hn.randomUUID();n=n||{};let r=n.random??n.rng?.()??$n();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 vi(r)}var Jn=Wo;var Bt=class{constructor(t,e,r){this._y=t.get("xml",S),e?this._undoManager=new Be(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){$e(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??Jn()),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 bt=Xi(Ni()),qn=class{constructor(t){this.doc=new ot,this.doc.on("update",t)}update(t){$e(this.doc,t)}},Pn=new Map,lt=new Map;function Zo(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 Qo(n,t){let e=lt.get(n);if(!e)throw new Error("Document not registered: "+n);let r;if(t){let i=bt.default.decode(t),s=Uint8Array.from(i,o=>o.charCodeAt(0));r=Bn(e.doc,s)}else r=Bn(e.doc);return bt.default.encode(String.fromCharCode(...r))}function tc(n){let t=lt.get(n);if(!t)throw new Error("Document not registered: "+n);let e=ii(t.doc);return bt.default.encode(String.fromCharCode(...e))}function ec(n,t){let e=lt.get(n);if(!e)throw new Error("cannot apply changes, document was not registered "+n);let r=Uint8Array.from(bt.default.decode(t),s=>s.charCodeAt(0));e.applyBackendChanges(r);let i=Pn.get(n);if(i){let s=i.doc.get("xml",S)}}function nc(n,t,e=!1,r,i){if(lt.get(n))throw new Error("document is already registered "+n);let s=new qn(c=>{let l=String.fromCharCode(...c),h=JSON.stringify({documentID:n,data:bt.default.encode(l)}),a=r??onSendUpdateToBackend;a&&a(h)}),o=new Bt(s.doc,e,c=>{let l=JSON.stringify({documentID:n,data:c}),h=i??onSendUpdateToClient;h&&h(l)});if(t){let c=Uint8Array.from(bt.default.decode(t),l=>l.charCodeAt(0));o.applyBackendChanges(c)}lt.set(n,o),Pn.set(n,s)}function rc(n){if(!lt.has(n))throw new Error("document was not registered "+n);lt.delete(n),Pn.delete(n)}return ji(ic);})();
/*! Bundled license information:

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