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

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