@richscripts/richtexteditor 2.4.1 → 2.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- "use strict";(()=>{var fr=Object.defineProperty,Ri=(e,t,r)=>t in e?fr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Fi=(e,t)=>{for(var r in t)fr(e,r,{get:t[r],enumerable:!0})},ue=(e,t,r)=>Ri(e,typeof t!="symbol"?t+"":t,r),dr={};Fi(dr,{BLOCK_TAGS:()=>ii,INLINE_MARK_TAGS:()=>si,LEAF_TAGS:()=>li,LOCAL_ORIGIN:()=>W,SUPPORTED_MARKS:()=>Xo,attachAwareness:()=>ga,attachCollab:()=>_a,attachCrdtBinding:()=>Ci,attachUndoManager:()=>fa,captureSelection:()=>di,classify:()=>Nt,htmlToYFragment:()=>ka,renderFragmentToHost:()=>ce,renderYNodeToDom:()=>Ze,restoreSelection:()=>gi});var W=Symbol.for("rte.crdt.local"),R=()=>new Map,fe=e=>{const t=R();return e.forEach((r,n)=>{t.set(n,r)}),t},et=(e,t,r)=>{let n=e.get(t);return n===void 0&&e.set(t,n=r()),n},Ui=(e,t)=>{const r=[];for(const[n,i]of e)r.push(t(i,n));return r},Bi=(e,t)=>{for(const[r,n]of e)if(t(n,r))return!0;return!1},rt=()=>new Set,de=e=>e[e.length-1],ji=(e,t)=>{for(let r=0;r<t.length;r++)e.push(t[r])},nt=Array.from,ge=(e,t)=>{for(let r=0;r<e.length;r++)if(!t(e[r],r,e))return!1;return!0},pe=(e,t)=>{for(let r=0;r<e.length;r++)if(t(e[r],r,e))return!0;return!1},Yi=(e,t)=>{const r=new Array(e);for(let n=0;n<e;n++)r[n]=t(n,r);return r},it=Array.isArray,gr=class{constructor(){this._observers=R()}on(e,t){return et(this._observers,e,rt).add(t),t}once(e,t){const r=(...n)=>{this.off(e,r),t(...n)};this.on(e,r)}off(e,t){const r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return nt((this._observers.get(e)||R()).values()).forEach(r=>r(...t))}destroy(){this._observers=R()}},Y=Math.floor,Dt=Math.abs,pr=(e,t)=>e<t?e:t,st=(e,t)=>e>t?e:t,Sa=Number.isNaN,Vi=e=>e!==0?e<0:1/e<0,vr=1,mr=2,ve=4,me=8,Pi=32,we=64,J=128,Hi=1<<17,Gi=1<<18,Xi=1<<19,zi=1<<20,Wi=1<<21,Ji=1<<22,Ki=1<<23,qi=1<<24,Zi=1<<25,Qi=1<<26,ts=1<<27,es=1<<28,rs=1<<29,ns=1<<30,Ea=1<<31,is=31,be=63,K=127,Ca=Hi-1,Ta=Gi-1,Aa=Xi-1,Ia=zi-1,Na=Wi-1,Da=Ji-1,Oa=Ki-1,xa=qi-1,La=Zi-1,Ma=Qi-1,$a=ts-1,Ra=es-1,Fa=rs-1,Ua=ns-1,ss=2147483647,Ot=Number.MAX_SAFE_INTEGER,wr=Number.MIN_SAFE_INTEGER,Ba=1<<31,ls=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&Y(e)===e),ja=Number.isNaN,Ya=Number.parseInt,br=String.fromCharCode,Va=String.fromCodePoint,Pa=br(65535),os=e=>e.toLowerCase(),as=/^\s*/g,cs=e=>e.replace(as,""),hs=/([A-Z])/g,_r=(e,t)=>cs(e.replace(hs,r=>`${t}${os(r)}`)),us=e=>{const t=unescape(encodeURIComponent(e)),r=t.length,n=new Uint8Array(r);for(let i=0;i<r;i++)n[i]=t.codePointAt(i);return n},vt=typeof TextEncoder<"u"?new TextEncoder:null,fs=e=>vt.encode(e),ds=vt?fs:us,mt=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});mt&&mt.decode(new Uint8Array).length===1&&(mt=null);var gs=(e,t)=>Yi(t,()=>e).join(""),wt=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},xt=()=>new wt,ps=e=>{let t=e.cpos;for(let r=0;r<e.bufs.length;r++)t+=e.bufs[r].length;return t},F=e=>{const t=new Uint8Array(ps(e));let r=0;for(let n=0;n<e.bufs.length;n++){const i=e.bufs[n];t.set(i,r),r+=i.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),r),t},vs=(e,t)=>{const r=e.cbuf.length;r-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(st(r,t)*2),e.cpos=0)},S=(e,t)=>{const r=e.cbuf.length;e.cpos===r&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(r*2),e.cpos=0),e.cbuf[e.cpos++]=t},bt=S,w=(e,t)=>{for(;t>K;)S(e,J|K&t),t=Y(t/128);S(e,K&t)},Lt=(e,t)=>{const r=Vi(t);for(r&&(t=-t),S(e,(t>be?J:0)|(r?we:0)|be&t),t=Y(t/64);t>0;)S(e,(t>K?J:0)|K&t),t=Y(t/128)},_e=new Uint8Array(3e4),ms=_e.length/3,ws=(e,t)=>{if(t.length<ms){const r=vt.encodeInto(t,_e).written||0;w(e,r);for(let n=0;n<r;n++)S(e,_e[n])}else x(e,ds(t))},bs=(e,t)=>{const r=unescape(encodeURIComponent(t)),n=r.length;w(e,n);for(let i=0;i<n;i++)S(e,r.codePointAt(i))},q=vt&&vt.encodeInto?ws:bs,ke=(e,t)=>{const r=e.cbuf.length,n=e.cpos,i=pr(r-n,t.length),s=t.length-i;e.cbuf.set(t.subarray(0,i),n),e.cpos+=i,s>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(st(r*2,s)),e.cbuf.set(t.subarray(i)),e.cpos=s)},x=(e,t)=>{w(e,t.byteLength),ke(e,t)},ye=(e,t)=>{vs(e,t);const r=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,r},_s=(e,t)=>ye(e,4).setFloat32(0,t,!1),ks=(e,t)=>ye(e,8).setFloat64(0,t,!1),ys=(e,t)=>ye(e,8).setBigInt64(0,t,!1),kr=new DataView(new ArrayBuffer(4)),Ss=e=>(kr.setFloat32(0,e),kr.getFloat32(0)===e),_t=(e,t)=>{switch(typeof t){case"string":S(e,119),q(e,t);break;case"number":ls(t)&&Dt(t)<=ss?(S(e,125),Lt(e,t)):Ss(t)?(S(e,124),_s(e,t)):(S(e,123),ks(e,t));break;case"bigint":S(e,122),ys(e,t);break;case"object":if(t===null)S(e,126);else if(it(t)){S(e,117),w(e,t.length);for(let r=0;r<t.length;r++)_t(e,t[r])}else if(t instanceof Uint8Array)S(e,116),x(e,t);else{S(e,118);const r=Object.keys(t);w(e,r.length);for(let n=0;n<r.length;n++){const i=r[n];q(e,i),_t(e,t[i])}}break;case"boolean":S(e,t?120:121);break;default:S(e,127)}},yr=class extends wt{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&w(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},Sr=e=>{e.count>0&&(Lt(e.encoder,e.count===1?e.s:-e.s),e.count>1&&w(e.encoder,e.count-2))},Mt=class{constructor(){this.encoder=new wt,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Sr(this),this.count=1,this.s=e)}toUint8Array(){return Sr(this),F(this.encoder)}},Er=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);Lt(e.encoder,t),e.count>1&&w(e.encoder,e.count-2)}},Se=class{constructor(){this.encoder=new wt,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Er(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Er(this),F(this.encoder)}},Es=class{constructor(){this.sarr=[],this.s="",this.lensE=new Mt}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new wt;return this.sarr.push(this.s),this.s="",q(e,this.sarr.join("")),ke(e,this.lensE.toUint8Array()),F(e)}},U=e=>new Error(e),L=()=>{throw U("Method unimplemented")},M=()=>{throw U("Unexpected case")},Cr=U("Unexpected end of array"),Tr=U("Integer out of Range"),Cs=class{constructor(e){this.arr=e,this.pos=0}},Ts=e=>new Cs(e),As=e=>e.pos!==e.arr.length,Is=(e,t)=>{const r=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,r},Ns=e=>Is(e,kt(e)),Ar=e=>e.arr[e.pos++],kt=e=>{let t=0,r=1;const n=e.arr.length;for(;e.pos<n;){const i=e.arr[e.pos++];if(t=t+(i&K)*r,r*=128,i<J)return t;if(t>Ot)throw Tr}throw Cr},Ds=e=>{let t=e.arr[e.pos++],r=t&be,n=64;const i=(t&we)>0?-1:1;if((t&J)===0)return i*r;const s=e.arr.length;for(;e.pos<s;){if(t=e.arr[e.pos++],r=r+(t&K)*n,n*=128,t<J)return i*r;if(r>Ot)throw Tr}throw Cr},Os=e=>{let t=kt(e);if(t===0)return"";{let r=String.fromCodePoint(Ar(e));if(--t<100)for(;t--;)r+=String.fromCodePoint(Ar(e));else for(;t>0;){const n=t<1e4?t:1e4,i=e.arr.subarray(e.pos,e.pos+n);e.pos+=n,r+=String.fromCodePoint.apply(null,i),t-=n}return decodeURIComponent(escape(r))}},xs=e=>mt.decode(Ns(e)),Ls=mt?xs:Os,Ha=crypto.subtle,Ms=crypto.getRandomValues.bind(crypto),Ir=()=>Ms(new Uint32Array(1))[0],$s="10000000-1000-4000-8000"+-1e11,Rs=()=>$s.replace(/[018]/g,e=>(e^Ir()&15>>e/4).toString(16)),Nr=Date.now,Dr=e=>new Promise(e),Ga=Promise.all.bind(Promise),Or=e=>e===void 0?null:e,Fs=class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},xr=new Fs,Us=!0;try{typeof localStorage<"u"&&localStorage&&(xr=localStorage,Us=!1)}catch{}var Bs=xr,yt=Symbol("Equality"),Lr=(e,t)=>{var r;return e===t||!!((r=e?.[yt])!=null&&r.call(e,t))||!1},js=e=>typeof e=="object",Ys=Object.assign,Vs=Object.keys,Ps=(e,t)=>{for(const r in e)t(e[r],r)},$t=e=>Vs(e).length,Hs=e=>{for(const t in e)return!1;return!0},St=(e,t)=>{for(const r in e)if(!t(e[r],r))return!1;return!0},Ee=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Gs=(e,t)=>e===t||$t(e)===$t(t)&&St(e,(r,n)=>(r!==void 0||Ee(t,n))&&Lr(t[n],r)),Xs=Object.freeze,Mr=e=>{for(const t in e){const r=e[t];(typeof r=="object"||typeof r=="function")&&Mr(e[t])}return Xs(e)},Ce=(e,t,r=0)=>{try{for(;r<e.length;r++)e[r](...t)}finally{r<e.length&&Ce(e,t,r+1)}},Rt=(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[yt]!=null)return e[yt](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 r=0;r<e.length;r++)if(e[r]!==t[r])return!1;break}case Set:{if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;break}case Map:{if(e.size!==t.size)return!1;for(const r of e.keys())if(!t.has(r)||!Rt(e.get(r),t.get(r)))return!1;break}case void 0:case Object:if($t(e)!==$t(t))return!1;for(const r in e)if(!Ee(e,r)||!Rt(e[r],t[r]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!Rt(e[r],t[r]))return!1;break;default:return!1}return!0},zs=(e,t)=>t.includes(e),Et=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",Xa=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,B,Ws=[],Js=()=>{if(B===void 0)if(Et){B=R();const e=process.argv;let t=null;for(let r=0;r<e.length;r++){const n=e[r];n[0]==="-"?(t!==null&&B.set(t,""),t=n):t!==null?(B.set(t,n),t=null):Ws.push(n)}t!==null&&B.set(t,"")}else typeof location=="object"?(B=R(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){const[t,r]=e.split("=");B.set(`--${_r(t,"-")}`,r),B.set(`-${_r(t,"-")}`,r)}})):B=R();return B},Te=e=>Js().has(e),Ft=e=>Or(Et?process.env[e.toUpperCase().replaceAll("-","_")]:Bs.getItem(e)),$r=e=>Te("--"+e)||Ft(e)!==null,Ks=$r("production"),qs=Et&&zs(process.env.FORCE_COLOR,["true","1","2"]),Zs=qs||!Te("--no-colors")&&!$r("no-color")&&(!Et||process.stdout.isTTY)&&(!Et||Te("--color")||Ft("COLORTERM")!==null||(Ft("TERM")||"").includes("color")),Qs=class{constructor(e,t){this.left=e,this.right=t}},V=(e,t)=>new Qs(e,t),Rr=e=>e.next()>=.5,Ae=(e,t,r)=>Y(e.next()*(r+1-t)+t),Fr=(e,t,r)=>Y(e.next()*(r+1-t)+t),Ie=(e,t,r)=>Fr(e,t,r),tl=e=>br(Ie(e,97,122)),el=(e,t=0,r=20)=>{const n=Ie(e,t,r);let i="";for(let s=0;s<n;s++)i+=tl(e);return i},Ne=(e,t)=>t[Ie(e,0,t.length-1)],rl=Symbol("0schema"),nl=class{constructor(){this._rerrs=[]}extend(e,t,r,n=null){this._rerrs.push({path:e,expected:t,has:r,message:n})}toString(){const e=[];for(let t=this._rerrs.length-1;t>0;t--){const r=this._rerrs[t];e.push(gs(" ",(this._rerrs.length-t)*2)+`${r.path!=null?`[${r.path}] `:""}${r.has} doesn't match ${r.expected}. ${r.message}`)}return e.join(`
2
- `)}},De=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[yt]?Lr(e,t):it(e)?ge(e,r=>pe(t,n=>De(r,n))):js(e)?St(e,(r,n)=>De(r,t[n])):!1,A=class{extends(e){let[t,r]=[this.shape,e.shape];return this.constructor._dilutes&&([r,t]=[t,r]),De(t,r)}equals(e){return this.constructor===e.constructor&&Rt(this.shape,e.shape)}[rl](){return!0}[yt](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){L()}get nullable(){return lt(this,Ht)}get optional(){return new jr(this)}cast(e){return en(e,this),e}expect(e){return en(e,this),e}};ue(A,"_dilutes",!1);var Oe=class extends A{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){const r=e?.constructor===this.shape&&(this._c==null||this._c(e));return!r&&t?.extend(null,this.shape.name,e?.constructor.name,e?.constructor!==this.shape?"Constructor match failed":"Check failed"),r}},y=(e,t=null)=>new Oe(e,t),za=y(Oe),xe=class extends A{constructor(e){super(),this.shape=e}check(e,t){const r=this.shape(e);return!r&&t?.extend(null,"custom prop",e?.constructor.name,"failed to check custom prop"),r}},E=e=>new xe(e),Wa=y(xe),Ut=class extends A{constructor(e){super(),this.shape=e}check(e,t){const r=this.shape.some(n=>n===e);return!r&&t?.extend(null,this.shape.join(" | "),e.toString()),r}},Bt=(...e)=>new Ut(e),Ur=y(Ut),il=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,t=>"\\"+t)),Br=e=>{if(at.check(e))return[il(e)];if(Ur.check(e))return e.shape.map(t=>t+"");if(Zr.check(e))return["[+-]?\\d+.?\\d*"];if(Qr.check(e))return[".*"];if(Yt.check(e))return e.shape.map(Br).flat(1);M()},sl=class extends A{constructor(e){super(),this.shape=e,this._r=new RegExp("^"+e.map(Br).map(t=>`(${t.join("|")})`).join("")+"$")}check(e,t){const r=this._r.exec(e)!=null;return!r&&t?.extend(null,this._r.toString(),e.toString(),"String doesn't match string template."),r}},Ja=y(sl),ll=Symbol("optional"),jr=class extends A{constructor(e){super(),this.shape=e}check(e,t){const r=e===void 0||this.shape.check(e);return!r&&t?.extend(null,"undefined (optional)","()"),r}get[ll](){return!0}},ol=y(jr),Yr=class extends A{check(e,t){return t?.extend(null,"never",typeof e),!1}},Ka=new Yr,qa=y(Yr),Vr=class Ni extends A{constructor(t,r=!1){super(),this.shape=t,this._isPartial=r}get partial(){return new Ni(this.shape,!0)}check(t,r){return t==null?(r?.extend(null,"object","null"),!1):St(this.shape,(n,i)=>{const s=this._isPartial&&!Ee(t,i)||n.check(t[i],r);return!s&&r?.extend(i.toString(),n.toString(),typeof t[i],"Object property does not match"),s})}};ue(Vr,"_dilutes",!0);var Pr=Vr,al=e=>new Pr(e),cl=y(Pr),hl=E(e=>e!=null&&(e.constructor===Object||e.constructor==null)),Hr=class extends A{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&St(e,(r,n)=>{const i=this.shape.keys.check(n,t);return!i&&t?.extend(n+"","Record",typeof e,i?"Key doesn't match schema":"Value doesn't match value"),i&&this.shape.values.check(r,t)})}},Gr=(e,t)=>new Hr(e,t),ul=y(Hr),Xr=class extends A{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&St(this.shape,(r,n)=>{const i=r.check(e[n],t);return!i&&t?.extend(n.toString(),"Tuple",typeof r),i})}},fl=(...e)=>new Xr(e),Za=y(Xr),zr=class extends A{constructor(e){super(),this.shape=e.length===1?e[0]:new jt(e)}check(e,t){const r=it(e)&&ge(e,n=>this.shape.check(n));return!r&&t?.extend(null,"Array",""),r}},Wr=(...e)=>new zr(e),dl=y(zr),gl=E(e=>it(e)),Jr=class extends A{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){const r=e instanceof this.shape&&(this._c==null||this._c(e));return!r&&t?.extend(null,this.shape.name,e?.constructor.name),r}},pl=(e,t=null)=>new Jr(e,t),Qa=y(Jr),vl=pl(A),ml=class extends A{constructor(e){super(),this.len=e.length-1,this.args=fl(...e.slice(-1)),this.res=e[this.len]}check(e,t){const r=e.constructor===Function&&e.length<=this.len;return!r&&t?.extend(null,"function",typeof e),r}},wl=y(ml),bl=E(e=>typeof e=="function"),_l=class extends A{constructor(e){super(),this.shape=e}check(e,t){const r=ge(this.shape,n=>n.check(e,t));return!r&&t?.extend(null,"Intersectinon",typeof e),r}},tc=y(_l,e=>e.shape.length>0),jt=class extends A{constructor(e){super(),this.shape=e}check(e,t){const r=pe(this.shape,n=>n.check(e,t));return t?.extend(null,"Union",typeof e),r}};ue(jt,"_dilutes",!0);var lt=(...e)=>e.findIndex(t=>Yt.check(t))>=0?lt(...e.map(t=>Ct(t)).map(t=>Yt.check(t)?t.shape:[t]).flat(1)):e.length===1?e[0]:new jt(e),Yt=y(jt),Kr=()=>!0,Vt=E(Kr),kl=y(xe,e=>e.shape===Kr),Le=E(e=>typeof e=="bigint"),yl=E(e=>e===Le),qr=E(e=>typeof e=="symbol"),ec=E(e=>e===qr),ot=E(e=>typeof e=="number"),Zr=E(e=>e===ot),at=E(e=>typeof e=="string"),Qr=E(e=>e===at),Pt=E(e=>typeof e=="boolean"),Sl=E(e=>e===Pt),tn=Bt(void 0),rc=y(Ut,e=>e.shape.length===1&&e.shape[0]===void 0),nc=Bt(void 0),Ht=Bt(null),El=y(Ut,e=>e.shape.length===1&&e.shape[0]===null),ic=y(Uint8Array),sc=y(Oe,e=>e.shape===Uint8Array),Cl=lt(ot,at,Ht,tn,Le,Pt,qr),lc=(()=>{const e=Wr(Vt),t=Gr(at,Vt),r=lt(ot,at,Ht,Pt,e,t);return e.shape=r,t.shape.values=r,r})(),Ct=e=>{if(vl.check(e))return e;if(hl.check(e)){const t={};for(const r in e)t[r]=Ct(e[r]);return al(t)}else{if(gl.check(e))return lt(...e.map(Ct));if(Cl.check(e))return Bt(e);if(bl.check(e))return y(e)}M()},en=Ks?()=>{}:(e,t)=>{const r=new nl;if(!t.check(e,r))throw U(`Expected value to be of type ${t.constructor.name}.
3
- ${r.toString()}`)},Tl=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:Ct(e),h:t}),this}else(e){return this.if(Vt,e)}done(){return((e,t)=>{for(let r=0;r<this.patterns.length;r++){const n=this.patterns[r];if(n.if.check(e))return n.h(e,t)}throw U("Unhandled pattern")})}},Al=e=>new Tl(e),rn=Al(Vt).if(Zr,(e,t)=>Ae(t,wr,Ot)).if(Qr,(e,t)=>el(t)).if(Sl,(e,t)=>Rr(t)).if(yl,(e,t)=>BigInt(Ae(t,wr,Ot))).if(Yt,(e,t)=>ct(t,Ne(t,e.shape))).if(cl,(e,t)=>{const r={};for(const n in e.shape){let i=e.shape[n];if(ol.check(i)){if(Rr(t))continue;i=i.shape}r[n]=rn(i,t)}return r}).if(dl,(e,t)=>{const r=[],n=Fr(t,0,42);for(let i=0;i<n;i++)r.push(ct(t,e.shape));return r}).if(Ur,(e,t)=>Ne(t,e.shape)).if(El,(e,t)=>null).if(wl,(e,t)=>{const r=ct(t,e.res);return()=>r}).if(kl,(e,t)=>ct(t,Ne(t,[ot,at,Ht,tn,Le,Pt,Wr(ot),Gr(lt("a","b","c"),ot)]))).if(ul,(e,t)=>{const r={},n=Ae(t,0,3);for(let i=0;i<n;i++){const s=ct(t,e.shape.keys),l=ct(t,e.shape.values);r[s]=l}return r}).done(),ct=(e,t)=>rn(Ct(t),e),Z=typeof document<"u"?document:{},oc=E(e=>e.nodeType===xl),ac=typeof DOMParser<"u"?new DOMParser:null,cc=E(e=>e.nodeType===Nl),hc=E(e=>e.nodeType===Dl),Il=e=>Ui(e,(t,r)=>`${r}:${t};`).join(""),Nl=Z.ELEMENT_NODE,Dl=Z.TEXT_NODE,uc=Z.CDATA_SECTION_NODE,fc=Z.COMMENT_NODE,Ol=Z.DOCUMENT_NODE,dc=Z.DOCUMENT_TYPE_NODE,xl=Z.DOCUMENT_FRAGMENT_NODE,gc=E(e=>e.nodeType===Ol),P=Symbol,nn=P(),sn=P(),Ll=P(),Ml=P(),$l=P(),ln=P(),Rl=P(),Me=P(),Fl=P(),Ul=e=>{var t;e.length===1&&((t=e[0])==null?void 0:t.constructor)===Function&&(e=e[0]());const r=[],n=[];let i=0;for(;i<e.length;i++){const s=e[i];if(s===void 0)break;if(s.constructor===String||s.constructor===Number)r.push(s);else if(s.constructor===Object)break}for(i>0&&n.push(r.join(""));i<e.length;i++){const s=e[i];s instanceof Symbol||n.push(s)}return n},pc=Nr(),Bl={[nn]:V("font-weight","bold"),[sn]:V("font-weight","normal"),[Ll]:V("color","blue"),[$l]:V("color","green"),[Ml]:V("color","grey"),[ln]:V("color","red"),[Rl]:V("color","purple"),[Me]:V("color","orange"),[Fl]:V("color","black")},jl=e=>{var t;e.length===1&&((t=e[0])==null?void 0:t.constructor)===Function&&(e=e[0]());const r=[],n=[],i=R();let s=[],l=0;for(;l<e.length;l++){const o=e[l],a=Bl[o];if(a!==void 0)i.set(a.left,a.right);else{if(o===void 0)break;if(o.constructor===String||o.constructor===Number){const c=Il(i);l>0||c.length>0?(r.push("%c"+o),n.push(c)):r.push(o)}else break}}for(l>0&&(s=n,s.unshift(r.join("")));l<e.length;l++){const o=e[l];o instanceof Symbol||s.push(o)}return s},on=Zs?jl:Ul,Yl=(...e)=>{console.log(...on(e)),cn.forEach(t=>t.print(e))},an=(...e)=>{console.warn(...on(e)),e.unshift(Me),cn.forEach(t=>t.print(e))},cn=rt(),hn=e=>({[Symbol.iterator](){return this},next:e}),Vl=(e,t)=>hn(()=>{let r;do r=e.next();while(!r.done&&!t(r.value));return r}),$e=(e,t)=>hn(()=>{const{done:r,value:n}=e.next();return{done:r,value:r?void 0:t(n)}}),un=class{constructor(e,t){this.clock=e,this.len=t}},Gt=class{constructor(){this.clients=new Map}},ht=(e,t,r)=>t.clients.forEach((n,i)=>{const s=e.doc.store.clients.get(i);if(s!=null){const l=s[s.length-1],o=l.id.clock+l.length;for(let a=0,c=n[a];a<n.length&&c.clock<o;c=n[++a])En(e,s,c.clock,c.len,r)}}),Pl=(e,t)=>{let r=0,n=e.length-1;for(;r<=n;){const i=Y((r+n)/2),s=e[i],l=s.clock;if(l<=t){if(t<l+s.len)return i;r=i+1}else n=i-1}return null},Tt=(e,t)=>{const r=e.clients.get(t.client);return r!==void 0&&Pl(r,t.clock)!==null},Re=e=>{e.clients.forEach(t=>{t.sort((i,s)=>i.clock-s.clock);let r,n;for(r=1,n=1;r<t.length;r++){const i=t[n-1],s=t[r];i.clock+i.len>=s.clock?t[n-1]=new un(i.clock,st(i.len,s.clock+s.len-i.clock)):(n<r&&(t[n]=s),n++)}t.length=n})},fn=e=>{const t=new Gt;for(let r=0;r<e.length;r++)e[r].clients.forEach((n,i)=>{if(!t.clients.has(i)){const s=n.slice();for(let l=r+1;l<e.length;l++)ji(s,e[l].clients.get(i)||[]);t.clients.set(i,s)}});return Re(t),t},Fe=(e,t,r,n)=>{et(e.clients,t,()=>[]).push(new un(r,n))},Hl=()=>new Gt,Gl=(e,t)=>{w(e.restEncoder,t.clients.size),nt(t.clients.entries()).sort((r,n)=>n[0]-r[0]).forEach(([r,n])=>{e.resetDsCurVal(),w(e.restEncoder,r);const i=n.length;w(e.restEncoder,i);for(let s=0;s<i;s++){const l=n[s];e.writeDsClock(l.clock),e.writeDsLen(l.len)}})},dn=Ir,Xt=class Di extends gr{constructor({guid:t=Rs(),collectionid:r=null,gc:n=!0,gcFilter:i=()=>!0,meta:s=null,autoLoad:l=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=i,this.clientID=dn(),this.guid=t,this.collectionid=r,this.share=new Map,this.store=new uo,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=l,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Dr(c=>{this.on("load",()=>{this.isLoaded=!0,c(this)})});const a=()=>Dr(c=>{const h=u=>{(u===void 0||u===!0)&&(this.off("sync",h),c())};this.on("sync",h)});this.on("sync",c=>{c===!1&&this.isSynced&&(this.whenSynced=a()),this.isSynced=c===void 0||c===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=a()}load(){const t=this._item;t!==null&&!this.shouldLoad&&_(t.parent.doc,r=>{r.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(nt(this.subdocs).map(t=>t.guid))}transact(t,r=null){return _(this,t,r)}get(t,r=C){const n=et(this.share,t,()=>{const s=new r;return s._integrate(this,null),s}),i=n.constructor;if(r!==C&&i!==r)if(i===C){const s=new r;s._map=n._map,n._map.forEach(l=>{for(;l!==null;l=l.left)l.parent=s}),s._start=n._start;for(let l=s._start;l!==null;l=l.right)l.parent=s;return s._length=n._length,this.share.set(t,s),s._integrate(this,null),s}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return n}getArray(t=""){return this.get(t,Io)}getText(t=""){return this.get(t,Jn)}getMap(t=""){return this.get(t,Do)}getXmlElement(t=""){return this.get(t,gt)}getXmlFragment(t=""){return this.get(t,se)}toJSON(){const t={};return this.share.forEach((r,n)=>{t[n]=r.toJSON()}),t}destroy(){this.isDestroyed=!0,nt(this.subdocs).forEach(r=>r.destroy());const t=this._item;if(t!==null){this._item=null;const r=t.content;r.doc=new Di({guid:this.guid,...r.opts,shouldLoad:!1}),r.doc._item=t,_(t.parent.doc,n=>{const i=r.doc;t.deleted||n.subdocsAdded.add(i),n.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}},Xl=class{constructor(){this.restEncoder=xt()}toUint8Array(){return F(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){w(this.restEncoder,e)}writeDsLen(e){w(this.restEncoder,e)}},zl=class extends Xl{writeLeftID(e){w(this.restEncoder,e.client),w(this.restEncoder,e.clock)}writeRightID(e){w(this.restEncoder,e.client),w(this.restEncoder,e.clock)}writeClient(e){w(this.restEncoder,e)}writeInfo(e){bt(this.restEncoder,e)}writeString(e){q(this.restEncoder,e)}writeParentInfo(e){w(this.restEncoder,e?1:0)}writeTypeRef(e){w(this.restEncoder,e)}writeLen(e){w(this.restEncoder,e)}writeAny(e){_t(this.restEncoder,e)}writeBuf(e){x(this.restEncoder,e)}writeJSON(e){q(this.restEncoder,JSON.stringify(e))}writeKey(e){q(this.restEncoder,e)}},Wl=class{constructor(){this.restEncoder=xt(),this.dsCurrVal=0}toUint8Array(){return F(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,w(this.restEncoder,t)}writeDsLen(e){e===0&&M(),w(this.restEncoder,e-1),this.dsCurrVal+=e}},Jl=class extends Wl{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Se,this.clientEncoder=new Mt,this.leftClockEncoder=new Se,this.rightClockEncoder=new Se,this.infoEncoder=new yr(bt),this.stringEncoder=new Es,this.parentInfoEncoder=new yr(bt),this.typeRefEncoder=new Mt,this.lenEncoder=new Mt}toUint8Array(){const e=xt();return w(e,0),x(e,this.keyClockEncoder.toUint8Array()),x(e,this.clientEncoder.toUint8Array()),x(e,this.leftClockEncoder.toUint8Array()),x(e,this.rightClockEncoder.toUint8Array()),x(e,F(this.infoEncoder)),x(e,this.stringEncoder.toUint8Array()),x(e,F(this.parentInfoEncoder)),x(e,this.typeRefEncoder.toUint8Array()),x(e,this.lenEncoder.toUint8Array()),ke(e,F(this.restEncoder)),F(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){_t(this.restEncoder,e)}writeBuf(e){x(this.restEncoder,e)}writeJSON(e){_t(this.restEncoder,e)}writeKey(e){const t=this.keyMap.get(e);t===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}},Kl=(e,t,r,n)=>{n=st(n,t[0].id.clock);const i=H(t,n);w(e.restEncoder,t.length-i),e.writeClient(r),w(e.restEncoder,n);const s=t[i];s.write(e,n-s.id.clock);for(let l=i+1;l<t.length;l++)t[l].write(e,0)},ql=(e,t,r)=>{const n=new Map;r.forEach((i,s)=>{T(t,s)>i&&n.set(s,i)}),Be(t).forEach((i,s)=>{r.has(s)||n.set(s,0)}),w(e.restEncoder,n.size),nt(n.entries()).sort((i,s)=>s[0]-i[0]).forEach(([i,s])=>{Kl(e,t.clients.get(i),i,s)})},Zl=(e,t)=>ql(e,t.doc.store,t.beforeState),Ql=class{constructor(){this.l=[]}},gn=()=>new Ql,pn=(e,t)=>e.l.push(t),vn=(e,t)=>{const r=e.l,n=r.length;e.l=r.filter(i=>t!==i),n===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},mn=(e,t,r)=>Ce(e.l,[t,r]),zt=class{constructor(e,t){this.client=e,this.clock=t}},Wt=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,b=(e,t)=>new zt(e,t),wn=(e,t)=>{w(e,t.client),w(e,t.clock)},bn=e=>b(kt(e),kt(e)),_n=e=>{for(const[t,r]of e.doc.share.entries())if(r===e)return t;throw M()},Jt=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},kn=class{constructor(e,t,r,n=0){this.type=e,this.tname=t,this.item=r,this.assoc=n}},to=class{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}},eo=(e,t,r=0)=>new to(e,t,r),Kt=(e,t,r)=>{let n=null,i=null;return e._item===null?i=_n(e):n=b(e._item.id.client,e._item.id.clock),new kn(n,i,t,r)},ro=(e,t,r=0)=>{let n=e._start;if(r<0){if(t===0)return Kt(e,null,r);t--}for(;n!==null;){if(!n.deleted&&n.countable){if(n.length>t)return Kt(e,b(n.id.client,n.id.clock+t),r);t-=n.length}if(n.right===null&&r<0)return Kt(e,n.lastId,r);n=n.right}return Kt(e,null,r)},no=(e,t)=>{const{type:r,tname:n,item:i,assoc:s}=t;if(i!==null)w(e,0),wn(e,i);else if(n!==null)bt(e,1),q(e,n);else if(r!==null)bt(e,2),wn(e,r);else throw M();return Lt(e,s),e},io=e=>{const t=xt();return no(t,e),F(t)},so=e=>{let t=null,r=null,n=null;switch(kt(e)){case 0:n=bn(e);break;case 1:r=Ls(e);break;case 2:t=bn(e)}const i=As(e)?Ds(e):0;return new kn(t,r,n,i)},lo=e=>so(Ts(e)),oo=(e,t)=>{const r=ft(e,t),n=t.clock-r.id.clock;return{item:r,diff:n}},ao=(e,t,r=!0)=>{const n=t.store,i=e.item,s=e.type,l=e.tname,o=e.assoc;let a=null,c=0;if(i!==null){if(T(n,i.client)<=i.clock)return null;const h=r?We(n,i):oo(n,i),u=h.item;if(!(u instanceof k))return null;if(a=u.parent,a._item===null||!a._item.deleted){c=u.deleted||!u.countable?0:h.diff+(o>=0?0:1);let f=u.left;for(;f!==null;)!f.deleted&&f.countable&&(c+=f.length),f=f.left}}else{if(l!==null)a=t.get(l);else if(s!==null){if(T(n,s.client)<=s.clock)return null;const{item:h}=r?We(n,s):{item:ft(n,s)};if(h instanceof k&&h.content instanceof Q)a=h.content.type;else return null}else throw M();o>=0?c=a._length:c=0}return eo(a,c,e.assoc)},co=class{constructor(e,t){this.ds=e,this.sv=t}},ho=(e,t)=>new co(e,t),vc=ho(Hl(),new Map),ut=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Tt(t.ds,e.id),Ue=(e,t)=>{const r=et(e.meta,Ue,rt),n=e.doc.store;r.has(t)||(t.sv.forEach((i,s)=>{i<T(n,s)&&O(e,b(s,i))}),ht(e,t.ds,i=>{}),r.add(t))},uo=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Be=e=>{const t=new Map;return e.clients.forEach((r,n)=>{const i=r[r.length-1];t.set(n,i.id.clock+i.length)}),t},T=(e,t)=>{const r=e.clients.get(t);if(r===void 0)return 0;const n=r[r.length-1];return n.id.clock+n.length},yn=(e,t)=>{let r=e.clients.get(t.id.client);if(r===void 0)r=[],e.clients.set(t.id.client,r);else{const n=r[r.length-1];if(n.id.clock+n.length!==t.id.clock)throw M()}r.push(t)},H=(e,t)=>{let r=0,n=e.length-1,i=e[n],s=i.id.clock;if(s===t)return n;let l=Y(t/(s+i.length-1)*n);for(;r<=n;){if(i=e[l],s=i.id.clock,s<=t){if(t<s+i.length)return l;r=l+1}else n=l-1;l=Y((r+n)/2)}throw M()},fo=(e,t)=>{const r=e.clients.get(t.client);return r[H(r,t.clock)]},ft=fo,je=(e,t,r)=>{const n=H(t,r),i=t[n];return i.id.clock<r&&i instanceof k?(t.splice(n+1,0,Qn(e,i,r-i.id.clock)),n+1):n},O=(e,t)=>{const r=e.doc.store.clients.get(t.client);return r[je(e,r,t.clock)]},Sn=(e,t,r)=>{const n=t.clients.get(r.client),i=H(n,r.clock),s=n[i];return r.clock!==s.id.clock+s.length-1&&s.constructor!==X&&n.splice(i+1,0,Qn(e,s,r.clock-s.id.clock+1)),s},go=(e,t,r)=>{const n=e.clients.get(t.id.client);n[H(n,t.id.clock)]=r},En=(e,t,r,n,i)=>{if(n===0)return;const s=r+n;let l=je(e,t,r),o;do o=t[l++],s<o.id.clock+o.length&&je(e,t,s),i(o);while(l<t.length&&t[l].id.clock<s)},po=class{constructor(e,t,r){this.doc=e,this.deleteSet=new Gt,this.beforeState=Be(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=r,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}},Cn=(e,t)=>t.deleteSet.clients.size===0&&!Bi(t.afterState,(r,n)=>t.beforeState.get(n)!==r)?!1:(Re(t.deleteSet),Zl(e,t),Gl(e,t.deleteSet),!0),Tn=(e,t,r)=>{const n=t._item;(n===null||n.id.clock<(e.beforeState.get(n.id.client)||0)&&!n.deleted)&&et(e.changed,t,rt).add(r)},qt=(e,t)=>{let r=e[t],n=e[t-1],i=t;for(;i>0;r=n,n=e[--i-1]){if(n.deleted===r.deleted&&n.constructor===r.constructor&&n.mergeWith(r)){r instanceof k&&r.parentSub!==null&&r.parent._map.get(r.parentSub)===r&&r.parent._map.set(r.parentSub,n);continue}break}const s=t-i;return s&&e.splice(t+1-s,s),s},vo=(e,t,r)=>{for(const[n,i]of e.clients.entries()){const s=t.clients.get(n);for(let l=i.length-1;l>=0;l--){const o=i[l],a=o.clock+o.len;for(let c=H(s,o.clock),h=s[c];c<s.length&&h.id.clock<a;h=s[++c]){const u=s[c];if(o.clock+o.len<=u.id.clock)break;u instanceof k&&u.deleted&&!u.keep&&r(u)&&u.gc(t,!1)}}}},mo=(e,t)=>{e.clients.forEach((r,n)=>{const i=t.clients.get(n);for(let s=r.length-1;s>=0;s--){const l=r[s],o=pr(i.length-1,1+H(i,l.clock+l.len-1));for(let a=o,c=i[a];a>0&&c.id.clock>=l.clock;c=i[a])a-=1+qt(i,a)}})},An=(e,t)=>{if(t<e.length){const r=e[t],n=r.doc,i=n.store,s=r.deleteSet,l=r._mergeStructs;try{Re(s),r.afterState=Be(r.doc.store),n.emit("beforeObserverCalls",[r,n]);const o=[];r.changed.forEach((a,c)=>o.push(()=>{(c._item===null||!c._item.deleted)&&c._callObserver(r,a)})),o.push(()=>{r.changedParentTypes.forEach((a,c)=>{c._dEH.l.length>0&&(c._item===null||!c._item.deleted)&&(a=a.filter(h=>h.target._item===null||!h.target._item.deleted),a.forEach(h=>{h.currentTarget=c,h._path=null}),a.sort((h,u)=>h.path.length-u.path.length),o.push(()=>{mn(c._dEH,a,r)}))}),o.push(()=>n.emit("afterTransaction",[r,n])),o.push(()=>{r._needFormattingCleanup&&Lo(r)})}),Ce(o,[])}finally{n.gc&&vo(s,i,n.gcFilter),mo(s,i),r.afterState.forEach((h,u)=>{const f=r.beforeState.get(u)||0;if(f!==h){const d=i.clients.get(u),g=st(H(d,f),1);for(let p=d.length-1;p>=g;)p-=1+qt(d,p)}});for(let h=l.length-1;h>=0;h--){const{client:u,clock:f}=l[h].id,d=i.clients.get(u),g=H(d,f);g+1<d.length&&qt(d,g+1)>1||g>0&&qt(d,g)}if(!r.local&&r.afterState.get(n.clientID)!==r.beforeState.get(n.clientID)&&(Yl(Me,nn,"[yjs] ",sn,ln,"Changed the client-id because another client seems to be using it."),n.clientID=dn()),n.emit("afterTransactionCleanup",[r,n]),n._observers.has("update")){const h=new zl;Cn(h,r)&&n.emit("update",[h.toUint8Array(),r.origin,n,r])}if(n._observers.has("updateV2")){const h=new Jl;Cn(h,r)&&n.emit("updateV2",[h.toUint8Array(),r.origin,n,r])}const{subdocsAdded:o,subdocsLoaded:a,subdocsRemoved:c}=r;(o.size>0||c.size>0||a.size>0)&&(o.forEach(h=>{h.clientID=n.clientID,h.collectionid==null&&(h.collectionid=n.collectionid),n.subdocs.add(h)}),c.forEach(h=>n.subdocs.delete(h)),n.emit("subdocs",[{loaded:a,added:o,removed:c},n,r]),c.forEach(h=>h.destroy())),e.length<=t+1?(n._transactionCleanups=[],n.emit("afterAllTransactions",[n,e])):An(e,t+1)}}},_=(e,t,r=null,n=!0)=>{const i=e._transactionCleanups;let s=!1,l=null;e._transaction===null&&(s=!0,e._transaction=new po(e,r,n),i.push(e._transaction),i.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{l=t(e._transaction)}finally{if(s){const o=e._transaction===i[0];e._transaction=null,o&&An(i,0)}}return l},wo=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},In=(e,t,r)=>{ht(e,r.deletions,n=>{n instanceof k&&t.scope.some(i=>i===e.doc||Jt(i,n))&&Je(n,!1)})},Nn=(e,t,r)=>{let n=null;const i=e.doc,s=e.scope;_(i,o=>{for(;t.length>0&&e.currStackItem===null;){const a=i.store,c=t.pop(),h=new Set,u=[];let f=!1;ht(o,c.insertions,d=>{if(d instanceof k){if(d.redone!==null){let{item:g,diff:p}=We(a,d.id);p>0&&(g=O(o,b(g.id.client,g.id.clock+p))),d=g}!d.deleted&&s.some(g=>g===o.doc||Jt(g,d))&&u.push(d)}}),ht(o,c.deletions,d=>{d instanceof k&&s.some(g=>g===o.doc||Jt(g,d))&&!Tt(c.insertions,d.id)&&h.add(d)}),h.forEach(d=>{f=ei(o,d,h,c.insertions,e.ignoreRemoteMapChanges,e)!==null||f});for(let d=u.length-1;d>=0;d--){const g=u[d];e.deleteFilter(g)&&(g.delete(o),f=!0)}e.currStackItem=f?c:null}o.changed.forEach((a,c)=>{a.has(null)&&c._searchMarker&&(c._searchMarker.length=0)}),n=o},e);const l=e.currStackItem;if(l!=null){const o=n.changedParentTypes;e.emit("stack-item-popped",[{stackItem:l,type:r,changedParentTypes:o,origin:e},e]),e.currStackItem=null}return l},bo=class extends gr{constructor(e,{captureTimeout:t=500,captureTransaction:r=o=>!0,deleteFilter:n=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:s=!1,doc:l=it(e)?e[0].doc:e instanceof Xt?e:e.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(e),this.deleteFilter=n,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=s,this.captureTimeout=t,this.afterTransactionHandler=o=>{if(!this.captureTransaction(o)||!this.scope.some(p=>o.changedParentTypes.has(p)||p===this.doc)||!this.trackedOrigins.has(o.origin)&&(!o.origin||!this.trackedOrigins.has(o.origin.constructor)))return;const a=this.undoing,c=this.redoing,h=a?this.redoStack:this.undoStack;a?this.stopCapturing():c||this.clear(!1,!0);const u=new Gt;o.afterState.forEach((p,m)=>{const v=o.beforeState.get(m)||0,j=p-v;j>0&&Fe(u,m,v,j)});const f=Nr();let d=!1;if(this.lastChange>0&&f-this.lastChange<this.captureTimeout&&h.length>0&&!a&&!c){const p=h[h.length-1];p.deletions=fn([p.deletions,o.deleteSet]),p.insertions=fn([p.insertions,u])}else h.push(new wo(o.deleteSet,u)),d=!0;!a&&!c&&(this.lastChange=f),ht(o,o.deleteSet,p=>{p instanceof k&&this.scope.some(m=>m===o.doc||Jt(m,p))&&Je(p,!0)});const g=[{stackItem:h[h.length-1],origin:o.origin,type:a?"redo":"undo",changedParentTypes:o.changedParentTypes},this];d?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(e){const t=new Set(this.scope);e=it(e)?e:[e],e.forEach(r=>{t.has(r)||(t.add(r),(r instanceof C?r.doc!==this.doc:r!==this.doc)&&an("[yjs#509] Not same Y.Doc"),this.scope.push(r))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(r=>{e&&(this.undoStack.forEach(n=>In(r,this,n)),this.undoStack=[]),t&&(this.redoStack.forEach(n=>In(r,this,n)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=Nn(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Nn(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}},Dn="You must not compute changes after the event-handler fired.",Zt=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=_o(this.currentTarget,this.target))}deletes(e){return Tt(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw U(Dn);const e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(n!==null){const i=t._map.get(n);let s,l;if(this.adds(i)){let o=i.left;for(;o!==null&&this.adds(o);)o=o.left;if(this.deletes(i))if(o!==null&&this.deletes(o))s="delete",l=de(o.content.getContent());else return;else o!==null&&this.deletes(o)?(s="update",l=de(o.content.getContent())):(s="add",l=void 0)}else if(this.deletes(i))s="delete",l=de(i.content.getContent());else return;e.set(n,{action:s,oldValue:l})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw U(Dn);const t=this.target,r=rt(),n=rt(),i=[];if(e={added:r,deleted:n,delta:i,keys:this.keys},this.transaction.changed.get(t).has(null)){let l=null;const o=()=>{l&&i.push(l)};for(let a=t._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((l===null||l.delete===void 0)&&(o(),l={delete:0}),l.delete+=a.length,n.add(a)):this.adds(a)?((l===null||l.insert===void 0)&&(o(),l={insert:[]}),l.insert=l.insert.concat(a.content.getContent()),r.add(a)):((l===null||l.retain===void 0)&&(o(),l={retain:0}),l.retain+=a.length);l!==null&&l.retain===void 0&&o()}this._changes=e}return e}},_o=(e,t)=>{const r=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)r.unshift(t._item.parentSub);else{let n=0,i=t._item.parent._start;for(;i!==t._item&&i!==null;)!i.deleted&&i.countable&&(n+=i.length),i=i.right;r.unshift(n)}t=t._item.parent}return r},I=()=>{an("Invalid access: Add Yjs type to a document before reading data.")},On=80,Ye=0,ko=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Ye++}},yo=e=>{e.timestamp=Ye++},xn=(e,t,r)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=r,e.timestamp=Ye++},So=(e,t,r)=>{if(e.length>=On){const n=e.reduce((i,s)=>i.timestamp<s.timestamp?i:s);return xn(n,t,r),n}else{const n=new ko(t,r);return e.push(n),n}},Qt=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;const r=e._searchMarker.length===0?null:e._searchMarker.reduce((s,l)=>Dt(t-s.index)<Dt(t-l.index)?s:l);let n=e._start,i=0;for(r!==null&&(n=r.p,i=r.index,yo(r));n.right!==null&&i<t;){if(!n.deleted&&n.countable){if(t<i+n.length)break;i+=n.length}n=n.right}for(;n.left!==null&&i>t;)n=n.left,!n.deleted&&n.countable&&(i-=n.length);for(;n.left!==null&&n.left.id.client===n.id.client&&n.left.id.clock+n.left.length===n.id.clock;)n=n.left,!n.deleted&&n.countable&&(i-=n.length);return r!==null&&Dt(r.index-i)<n.parent.length/On?(xn(r,n,i),r):So(e._searchMarker,n,i)},At=(e,t,r)=>{for(let n=e.length-1;n>=0;n--){const i=e[n];if(r>0){let s=i.p;for(s.marker=!1;s&&(s.deleted||!s.countable);)s=s.left,s&&!s.deleted&&s.countable&&(i.index-=s.length);if(s===null||s.marker===!0){e.splice(n,1);continue}i.p=s,s.marker=!0}(t<i.index||r>0&&t===i.index)&&(i.index=st(t,i.index+r))}},te=(e,t,r)=>{const n=e,i=t.changedParentTypes;for(;et(i,e,()=>[]).push(r),e._item!==null;)e=e._item.parent;mn(n._eH,r,t)},C=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=gn(),this._dEH=gn(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw L()}clone(){throw L()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){pn(this._eH,e)}observeDeep(e){pn(this._dEH,e)}unobserve(e){vn(this._eH,e)}unobserveDeep(e){vn(this._dEH,e)}toJSON(){}},Ln=(e,t,r)=>{var n;(n=e.doc)!=null||I(),t<0&&(t=e._length+t),r<0&&(r=e._length+r);let i=r-t;const s=[];let l=e._start;for(;l!==null&&i>0;){if(l.countable&&!l.deleted){const o=l.content.getContent();if(o.length<=t)t-=o.length;else{for(let a=t;a<o.length&&i>0;a++)s.push(o[a]),i--;t=0}}l=l.right}return s},Mn=e=>{var t;(t=e.doc)!=null||I();const r=[];let n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){const i=n.content.getContent();for(let s=0;s<i.length;s++)r.push(i[s])}n=n.right}return r},It=(e,t)=>{var r;let n=0,i=e._start;for((r=e.doc)!=null||I();i!==null;){if(i.countable&&!i.deleted){const s=i.content.getContent();for(let l=0;l<s.length;l++)t(s[l],n++,e)}i=i.right}},$n=(e,t)=>{const r=[];return It(e,(n,i)=>{r.push(t(n,i,e))}),r},Eo=e=>{let t=e._start,r=null,n=0;return{[Symbol.iterator](){return this},next:()=>{if(r===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};r=t.content.getContent(),n=0,t=t.right}const i=r[n++];return r.length<=n&&(r=null),{done:!1,value:i}}}},Rn=(e,t)=>{var r;(r=e.doc)!=null||I();const n=Qt(e,t);let i=e._start;for(n!==null&&(i=n.p,t-=n.index);i!==null;i=i.right)if(!i.deleted&&i.countable){if(t<i.length)return i.content.getContent()[t];t-=i.length}},ee=(e,t,r,n)=>{let i=r;const s=e.doc,l=s.clientID,o=s.store,a=r===null?t._start:r.right;let c=[];const h=()=>{c.length>0&&(i=new k(b(l,T(o,l)),i,i&&i.lastId,a,a&&a.id,t,null,new ze(c)),i.integrate(e,0),c=[])};n.forEach(u=>{if(u===null)c.push(u);else switch(u.constructor){case Number:case Object:case Boolean:case Array:case String:c.push(u);break;default:switch(h(),u.constructor){case Uint8Array:case ArrayBuffer:i=new k(b(l,T(o,l)),i,i&&i.lastId,a,a&&a.id,t,null,new qn(new Uint8Array(u))),i.integrate(e,0);break;case Xt:i=new k(b(l,T(o,l)),i,i&&i.lastId,a,a&&a.id,t,null,new Zn(u)),i.integrate(e,0);break;default:if(u instanceof C)i=new k(b(l,T(o,l)),i,i&&i.lastId,a,a&&a.id,t,null,new Q(u)),i.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},Fn=()=>U("Length exceeded!"),Un=(e,t,r,n)=>{if(r>t._length)throw Fn();if(r===0)return t._searchMarker&&At(t._searchMarker,r,n.length),ee(e,t,null,n);const i=r,s=Qt(t,r);let l=t._start;for(s!==null&&(l=s.p,r-=s.index,r===0&&(l=l.prev,r+=l&&l.countable&&!l.deleted?l.length:0));l!==null;l=l.right)if(!l.deleted&&l.countable){if(r<=l.length){r<l.length&&O(e,b(l.id.client,l.id.clock+r));break}r-=l.length}return t._searchMarker&&At(t._searchMarker,i,n.length),ee(e,t,l,n)},Co=(e,t,r)=>{let i=(t._searchMarker||[]).reduce((s,l)=>l.index>s.index?l:s,{index:0,p:t._start}).p;if(i)for(;i.right;)i=i.right;return ee(e,t,i,r)},Bn=(e,t,r,n)=>{if(n===0)return;const i=r,s=n,l=Qt(t,r);let o=t._start;for(l!==null&&(o=l.p,r-=l.index);o!==null&&r>0;o=o.right)!o.deleted&&o.countable&&(r<o.length&&O(e,b(o.id.client,o.id.clock+r)),r-=o.length);for(;n>0&&o!==null;)o.deleted||(n<o.length&&O(e,b(o.id.client,o.id.clock+n)),o.delete(e),n-=o.length),o=o.right;if(n>0)throw Fn();t._searchMarker&&At(t._searchMarker,i,-s+n)},re=(e,t,r)=>{const n=t._map.get(r);n!==void 0&&n.delete(e)},Ve=(e,t,r,n)=>{const i=t._map.get(r)||null,s=e.doc,l=s.clientID;let o;if(n==null)o=new ze([n]);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:o=new ze([n]);break;case Uint8Array:o=new qn(n);break;case Xt:o=new Zn(n);break;default:if(n instanceof C)o=new Q(n);else throw new Error("Unexpected content type")}new k(b(l,T(s.store,l)),i,i&&i.lastId,null,null,t,r,o).integrate(e,0)},Pe=(e,t)=>{var r;(r=e.doc)!=null||I();const n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},jn=e=>{var t;const r={};return(t=e.doc)!=null||I(),e._map.forEach((n,i)=>{n.deleted||(r[i]=n.content.getContent()[n.length-1])}),r},Yn=(e,t)=>{var r;(r=e.doc)!=null||I();const n=e._map.get(t);return n!==void 0&&!n.deleted},To=(e,t)=>{const r={};return e._map.forEach((n,i)=>{let s=n;for(;s!==null&&(!t.sv.has(s.id.client)||s.id.clock>=(t.sv.get(s.id.client)||0));)s=s.left;s!==null&&ut(s,t)&&(r[i]=s.content.getContent()[s.length-1])}),r},ne=e=>{var t;return(t=e.doc)!=null||I(),Vl(e._map.entries(),r=>!r[1].deleted)},Ao=class extends Zt{},Io=class he extends C{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const r=new he;return r.push(t),r}_integrate(t,r){super._integrate(t,r),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new he}clone(){const t=new he;return t.insert(0,this.toArray().map(r=>r instanceof C?r.clone():r)),t}get length(){var t;return(t=this.doc)!=null||I(),this._length}_callObserver(t,r){super._callObserver(t,r),te(this,t,new Ao(this,t))}insert(t,r){this.doc!==null?_(this.doc,n=>{Un(n,this,t,r)}):this._prelimContent.splice(t,0,...r)}push(t){this.doc!==null?_(this.doc,r=>{Co(r,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,r=1){this.doc!==null?_(this.doc,n=>{Bn(n,this,t,r)}):this._prelimContent.splice(t,r)}get(t){return Rn(this,t)}toArray(){return Mn(this)}slice(t=0,r=this.length){return Ln(this,t,r)}toJSON(){return this.map(t=>t instanceof C?t.toJSON():t)}map(t){return $n(this,t)}forEach(t){It(this,t)}[Symbol.iterator](){return Eo(this)}_write(t){t.writeTypeRef(jo)}},No=class extends Zt{constructor(e,t,r){super(e,t),this.keysChanged=r}},Do=class nr extends C{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,r){super._integrate(t,r),this._prelimContent.forEach((n,i)=>{this.set(i,n)}),this._prelimContent=null}_copy(){return new nr}clone(){const t=new nr;return this.forEach((r,n)=>{t.set(n,r instanceof C?r.clone():r)}),t}_callObserver(t,r){te(this,t,new No(this,t,r))}toJSON(){var t;(t=this.doc)!=null||I();const r={};return this._map.forEach((n,i)=>{if(!n.deleted){const s=n.content.getContent()[n.length-1];r[i]=s instanceof C?s.toJSON():s}}),r}get size(){return[...ne(this)].length}keys(){return $e(ne(this),t=>t[0])}values(){return $e(ne(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return $e(ne(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){var r;(r=this.doc)!=null||I(),this._map.forEach((n,i)=>{n.deleted||t(n.content.getContent()[n.length-1],i,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?_(this.doc,r=>{re(r,this,t)}):this._prelimContent.delete(t)}set(t,r){return this.doc!==null?_(this.doc,n=>{Ve(n,this,t,r)}):this._prelimContent.set(t,r),r}get(t){return Pe(this,t)}has(t){return Yn(this,t)}clear(){this.doc!==null?_(this.doc,t=>{this.forEach(function(r,n,i){re(t,i,n)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Yo)}},G=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&Gs(e,t),He=class{constructor(e,t,r,n){this.left=e,this.right=t,this.index=r,this.currentAttributes=n}forward(){this.right===null&&M(),this.right.content.constructor===N?this.right.deleted||dt(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}},Vn=(e,t,r)=>{for(;t.right!==null&&r>0;)t.right.content.constructor===N?t.right.deleted||dt(t.currentAttributes,t.right.content):t.right.deleted||(r<t.right.length&&O(e,b(t.right.id.client,t.right.id.clock+r)),t.index+=t.right.length,r-=t.right.length),t.left=t.right,t.right=t.right.right;return t},ie=(e,t,r,n)=>{const i=new Map,s=n?Qt(t,r):null;if(s){const l=new He(s.p.left,s.p,s.index,i);return Vn(e,l,r-s.index)}else{const l=new He(null,t._start,0,i);return Vn(e,l,r)}},Pn=(e,t,r,n)=>{for(;r.right!==null&&(r.right.deleted===!0||r.right.content.constructor===N&&G(n.get(r.right.content.key),r.right.content.value));)r.right.deleted||n.delete(r.right.content.key),r.forward();const i=e.doc,s=i.clientID;n.forEach((l,o)=>{const a=r.left,c=r.right,h=new k(b(s,T(i.store,s)),a,a&&a.lastId,c,c&&c.id,t,null,new N(o,l));h.integrate(e,0),r.right=h,r.forward()})},dt=(e,t)=>{const{key:r,value:n}=t;n===null?e.delete(r):e.set(r,n)},Hn=(e,t)=>{for(var r;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===N&&G((r=t[e.right.content.key])!=null?r:null,e.right.content.value)))break;e.forward()}},Gn=(e,t,r,n)=>{var i;const s=e.doc,l=s.clientID,o=new Map;for(const a in n){const c=n[a],h=(i=r.currentAttributes.get(a))!=null?i:null;if(!G(h,c)){o.set(a,h);const{left:u,right:f}=r;r.right=new k(b(l,T(s.store,l)),u,u&&u.lastId,f,f&&f.id,t,null,new N(a,c)),r.right.integrate(e,0),r.forward()}}return o},Ge=(e,t,r,n,i)=>{r.currentAttributes.forEach((f,d)=>{i[d]===void 0&&(i[d]=null)});const s=e.doc,l=s.clientID;Hn(r,i);const o=Gn(e,t,r,i),a=n.constructor===String?new pt(n):n instanceof C?new Q(n):new oe(n);let{left:c,right:h,index:u}=r;t._searchMarker&&At(t._searchMarker,r.index,a.getLength()),h=new k(b(l,T(s.store,l)),c,c&&c.lastId,h,h&&h.id,t,null,a),h.integrate(e,0),r.right=h,r.index=u,r.forward(),Pn(e,t,r,o)},Xn=(e,t,r,n,i)=>{const s=e.doc,l=s.clientID;Hn(r,i);const o=Gn(e,t,r,i);t:for(;r.right!==null&&(n>0||o.size>0&&(r.right.deleted||r.right.content.constructor===N));){if(!r.right.deleted)switch(r.right.content.constructor){case N:{const{key:a,value:c}=r.right.content,h=i[a];if(h!==void 0){if(G(h,c))o.delete(a);else{if(n===0)break t;o.set(a,c)}r.right.delete(e)}else r.currentAttributes.set(a,c);break}default:n<r.right.length&&O(e,b(r.right.id.client,r.right.id.clock+n)),n-=r.right.length;break}r.forward()}if(n>0){let a="";for(;n>0;n--)a+=`
4
- `;r.right=new k(b(l,T(s.store,l)),r.left,r.left&&r.left.lastId,r.right,r.right&&r.right.id,t,null,new pt(a)),r.right.integrate(e,0),r.forward()}Pn(e,t,r,o)},zn=(e,t,r,n,i)=>{var s,l;let o=t;const a=R();for(;o&&(!o.countable||o.deleted);){if(!o.deleted&&o.content.constructor===N){const u=o.content;a.set(u.key,u)}o=o.right}let c=0,h=!1;for(;t!==o;){if(r===t&&(h=!0),!t.deleted){const u=t.content;if(u.constructor===N){const{key:f,value:d}=u,g=(s=n.get(f))!=null?s:null;(a.get(f)!==u||g===d)&&(t.delete(e),c++,!h&&((l=i.get(f))!=null?l:null)===d&&g!==d&&(g===null?i.delete(f):i.set(f,g))),!h&&!t.deleted&&dt(i,u)}}t=t.right}return c},Oo=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const r=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===N){const n=t.content.key;r.has(n)?t.delete(e):r.add(n)}t=t.left}},xo=e=>{let t=0;return _(e.doc,r=>{let n=e._start,i=e._start,s=R();const l=fe(s);for(;i;)i.deleted===!1&&(i.content.constructor===N?dt(l,i.content):(t+=zn(r,n,i,s,l),s=fe(l),n=i)),i=i.right}),t},Lo=e=>{const t=new Set,r=e.doc;for(const[n,i]of e.afterState.entries()){const s=e.beforeState.get(n)||0;i!==s&&En(e,r.store.clients.get(n),s,i,l=>{!l.deleted&&l.content.constructor===N&&l.constructor!==X&&t.add(l.parent)})}_(r,n=>{ht(e,e.deleteSet,i=>{if(i instanceof X||!i.parent._hasFormatting||t.has(i.parent))return;const s=i.parent;i.content.constructor===N?t.add(s):Oo(n,i)});for(const i of t)xo(i)})},Wn=(e,t,r)=>{const n=r,i=fe(t.currentAttributes),s=t.right;for(;r>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Q:case oe:case pt:r<t.right.length&&O(e,b(t.right.id.client,t.right.id.clock+r)),r-=t.right.length,t.right.delete(e);break}t.forward()}s&&zn(e,s,t.right,i,t.currentAttributes);const l=(t.left||t.right).parent;return l._searchMarker&&At(l._searchMarker,t.index,-n+r),t},Mo=class extends Zt{constructor(e,t,r){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,r.forEach(n=>{n===null?this.childListChanged=!0:this.keysChanged.add(n)})}get changes(){if(this._changes===null){const e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){const e=this.target.doc,t=[];_(e,r=>{var n,i,s;const l=new Map,o=new Map;let a=this.target._start,c=null;const h={};let u="",f=0,d=0;const g=()=>{if(c!==null){let p=null;switch(c){case"delete":d>0&&(p={delete:d}),d=0;break;case"insert":(typeof u=="object"||u.length>0)&&(p={insert:u},l.size>0&&(p.attributes={},l.forEach((m,v)=>{m!==null&&(p.attributes[v]=m)}))),u="";break;case"retain":f>0&&(p={retain:f},Hs(h)||(p.attributes=Ys({},h))),f=0;break}p&&t.push(p),c=null}};for(;a!==null;){switch(a.content.constructor){case Q:case oe:this.adds(a)?this.deletes(a)||(g(),c="insert",u=a.content.getContent()[0],g()):this.deletes(a)?(c!=="delete"&&(g(),c="delete"),d+=1):a.deleted||(c!=="retain"&&(g(),c="retain"),f+=1);break;case pt:this.adds(a)?this.deletes(a)||(c!=="insert"&&(g(),c="insert"),u+=a.content.str):this.deletes(a)?(c!=="delete"&&(g(),c="delete"),d+=a.length):a.deleted||(c!=="retain"&&(g(),c="retain"),f+=a.length);break;case N:{const{key:p,value:m}=a.content;if(this.adds(a)){if(!this.deletes(a)){const v=(n=l.get(p))!=null?n:null;G(v,m)?m!==null&&a.delete(r):(c==="retain"&&g(),G(m,(i=o.get(p))!=null?i:null)?delete h[p]:h[p]=m)}}else if(this.deletes(a)){o.set(p,m);const v=(s=l.get(p))!=null?s:null;G(v,m)||(c==="retain"&&g(),h[p]=v)}else if(!a.deleted){o.set(p,m);const v=h[p];v!==void 0&&(G(v,m)?v!==null&&a.delete(r):(c==="retain"&&g(),m===null?delete h[p]:h[p]=m))}a.deleted||(c==="insert"&&g(),dt(l,a.content));break}}a=a.right}for(g();t.length>0;){const p=t[t.length-1];if(p.retain!==void 0&&p.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},Jn=class ir extends C{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){var t;return(t=this.doc)!=null||I(),this._length}_integrate(t,r){super._integrate(t,r);try{this._pending.forEach(n=>n())}catch(n){console.error(n)}this._pending=null}_copy(){return new ir}clone(){const t=new ir;return t.applyDelta(this.toDelta()),t}_callObserver(t,r){super._callObserver(t,r);const n=new Mo(this,t,r);te(this,t,n),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){var t;(t=this.doc)!=null||I();let r="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===pt&&(r+=n.content.str),n=n.right;return r}toJSON(){return this.toString()}applyDelta(t,{sanitize:r=!0}={}){this.doc!==null?_(this.doc,n=>{const i=new He(null,this._start,0,new Map);for(let s=0;s<t.length;s++){const l=t[s];if(l.insert!==void 0){const o=!r&&typeof l.insert=="string"&&s===t.length-1&&i.right===null&&l.insert.slice(-1)===`
5
- `?l.insert.slice(0,-1):l.insert;(typeof o!="string"||o.length>0)&&Ge(n,this,i,o,l.attributes||{})}else l.retain!==void 0?Xn(n,this,i,l.retain,l.attributes||{}):l.delete!==void 0&&Wn(n,i,l.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,r,n){var i;(i=this.doc)!=null||I();const s=[],l=new Map,o=this.doc;let a="",c=this._start;function h(){if(a.length>0){const f={};let d=!1;l.forEach((p,m)=>{d=!0,f[m]=p});const g={insert:a};d&&(g.attributes=f),s.push(g),a=""}}const u=()=>{for(;c!==null;){if(ut(c,t)||r!==void 0&&ut(c,r))switch(c.content.constructor){case pt:{const f=l.get("ychange");t!==void 0&&!ut(c,t)?(f===void 0||f.user!==c.id.client||f.type!=="removed")&&(h(),l.set("ychange",n?n("removed",c.id):{type:"removed"})):r!==void 0&&!ut(c,r)?(f===void 0||f.user!==c.id.client||f.type!=="added")&&(h(),l.set("ychange",n?n("added",c.id):{type:"added"})):f!==void 0&&(h(),l.delete("ychange")),a+=c.content.str;break}case Q:case oe:{h();const f={insert:c.content.getContent()[0]};if(l.size>0){const d={};f.attributes=d,l.forEach((g,p)=>{d[p]=g})}s.push(f);break}case N:ut(c,t)&&(h(),dt(l,c.content));break}c=c.right}h()};return t||r?_(o,f=>{t&&Ue(f,t),r&&Ue(f,r),u()},"cleanup"):u(),s}insert(t,r,n){if(r.length<=0)return;const i=this.doc;i!==null?_(i,s=>{const l=ie(s,this,t,!n);n||(n={},l.currentAttributes.forEach((o,a)=>{n[a]=o})),Ge(s,this,l,r,n)}):this._pending.push(()=>this.insert(t,r,n))}insertEmbed(t,r,n){const i=this.doc;i!==null?_(i,s=>{const l=ie(s,this,t,!n);Ge(s,this,l,r,n||{})}):this._pending.push(()=>this.insertEmbed(t,r,n||{}))}delete(t,r){if(r===0)return;const n=this.doc;n!==null?_(n,i=>{Wn(i,ie(i,this,t,!0),r)}):this._pending.push(()=>this.delete(t,r))}format(t,r,n){if(r===0)return;const i=this.doc;i!==null?_(i,s=>{const l=ie(s,this,t,!1);l.right!==null&&Xn(s,this,l,r,n)}):this._pending.push(()=>this.format(t,r,n))}removeAttribute(t){this.doc!==null?_(this.doc,r=>{re(r,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,r){this.doc!==null?_(this.doc,n=>{Ve(n,this,t,r)}):this._pending.push(()=>this.setAttribute(t,r))}getAttribute(t){return Pe(this,t)}getAttributes(){return jn(this)}_write(t){t.writeTypeRef(Vo)}},Xe=class{constructor(e,t=()=>!0){var r;this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,(r=e.doc)!=null||I()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===gt||t.constructor===se)&&t._start!==null)e=t._start;else for(;e!==null;){const r=e.next;if(r!==null){e=r;break}else e.parent===this._root?e=null:e=e.parent._item}while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},se=class sr extends C{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,r){super._integrate(t,r),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new sr}clone(){const t=new sr;return t.insert(0,this.toArray().map(r=>r instanceof C?r.clone():r)),t}get length(){var t;return(t=this.doc)!=null||I(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Xe(this,t)}querySelector(t){t=t.toUpperCase();const n=new Xe(this,i=>i.nodeName&&i.nodeName.toUpperCase()===t).next();return n.done?null:n.value}querySelectorAll(t){return t=t.toUpperCase(),nt(new Xe(this,r=>r.nodeName&&r.nodeName.toUpperCase()===t))}_callObserver(t,r){te(this,t,new $o(this,r,t))}toString(){return $n(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,r={},n){const i=t.createDocumentFragment();return n!==void 0&&n._createAssociation(i,this),It(this,s=>{i.insertBefore(s.toDOM(t,r,n),null)}),i}insert(t,r){this.doc!==null?_(this.doc,n=>{Un(n,this,t,r)}):this._prelimContent.splice(t,0,...r)}insertAfter(t,r){if(this.doc!==null)_(this.doc,n=>{const i=t&&t instanceof C?t._item:t;ee(n,this,i,r)});else{const n=this._prelimContent,i=t===null?0:n.findIndex(s=>s===t)+1;if(i===0&&t!==null)throw U("Reference item not found");n.splice(i,0,...r)}}delete(t,r=1){this.doc!==null?_(this.doc,n=>{Bn(n,this,t,r)}):this._prelimContent.splice(t,r)}toArray(){return Mn(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Rn(this,t)}slice(t=0,r=this.length){return Ln(this,t,r)}forEach(t){It(this,t)}_write(t){t.writeTypeRef(Ho)}},gt=class lr extends se{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,r){super._integrate(t,r),this._prelimAttrs.forEach((n,i)=>{this.setAttribute(i,n)}),this._prelimAttrs=null}_copy(){return new lr(this.nodeName)}clone(){const t=new lr(this.nodeName),r=this.getAttributes();return Ps(r,(n,i)=>{t.setAttribute(i,n)}),t.insert(0,this.toArray().map(n=>n instanceof C?n.clone():n)),t}toString(){const t=this.getAttributes(),r=[],n=[];for(const o in t)n.push(o);n.sort();const i=n.length;for(let o=0;o<i;o++){const a=n[o];r.push(a+'="'+t[a]+'"')}const s=this.nodeName.toLocaleLowerCase(),l=r.length>0?" "+r.join(" "):"";return`<${s}${l}>${super.toString()}</${s}>`}removeAttribute(t){this.doc!==null?_(this.doc,r=>{re(r,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,r){this.doc!==null?_(this.doc,n=>{Ve(n,this,t,r)}):this._prelimAttrs.set(t,r)}getAttribute(t){return Pe(this,t)}hasAttribute(t){return Yn(this,t)}getAttributes(t){return t?To(this,t):jn(this)}toDOM(t=document,r={},n){const i=t.createElement(this.nodeName),s=this.getAttributes();for(const l in s){const o=s[l];typeof o=="string"&&i.setAttribute(l,o)}return It(this,l=>{i.appendChild(l.toDOM(t,r,n))}),n!==void 0&&n._createAssociation(i,this),i}_write(t){t.writeTypeRef(Po),t.writeKey(this.nodeName)}},$o=class extends Zt{constructor(e,t,r){super(e,r),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(n=>{n===null?this.childListChanged=!0:this.attributesChanged.add(n)})}},le=class or extends Jn{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new or}clone(){const t=new or;return t.applyDelta(this.toDelta()),t}toDOM(t=document,r,n){const i=t.createTextNode(this.toString());return n!==void 0&&n._createAssociation(i,this),i}toString(){return this.toDelta().map(t=>{const r=[];for(const i in t.attributes){const s=[];for(const l in t.attributes[i])s.push({key:l,value:t.attributes[i][l]});s.sort((l,o)=>l.key<o.key?-1:1),r.push({nodeName:i,attrs:s})}r.sort((i,s)=>i.nodeName<s.nodeName?-1:1);let n="";for(let i=0;i<r.length;i++){const s=r[i];n+=`<${s.nodeName}`;for(let l=0;l<s.attrs.length;l++){const o=s.attrs[l];n+=` ${o.key}="${o.value}"`}n+=">"}n+=t.insert;for(let i=r.length-1;i>=0;i--)n+=`</${r[i].nodeName}>`;return n}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(Go)}},Kn=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw L()}mergeWith(e){return!1}write(e,t,r){throw L()}integrate(e,t){throw L()}},Ro=0,X=class extends Kn{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),yn(e.doc.store,this)}write(e,t){e.writeInfo(Ro),e.writeLen(this.length-t)}getMissing(e,t){return null}},qn=class Oi{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Oi(this.content)}splice(t){throw L()}mergeWith(t){return!1}integrate(t,r){}delete(t){}gc(t){}write(t,r){t.writeBuf(this.content)}getRef(){return 3}},Fo=class ar{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new ar(this.len)}splice(t){const r=new ar(this.len-t);return this.len=t,r}mergeWith(t){return this.len+=t.len,!0}integrate(t,r){Fe(t.deleteSet,r.id.client,r.id.clock,this.len),r.markDeleted()}delete(t){}gc(t){}write(t,r){t.writeLen(this.len-r)}getRef(){return 1}},Uo=(e,t)=>new Xt({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),Zn=class xi{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const r={};this.opts=r,t.gc||(r.gc=!1),t.autoLoad&&(r.autoLoad=!0),t.meta!==null&&(r.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new xi(Uo(this.doc.guid,this.opts))}splice(t){throw L()}mergeWith(t){return!1}integrate(t,r){this.doc._item=r,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,r){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}},oe=class Li{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Li(this.embed)}splice(t){throw L()}mergeWith(t){return!1}integrate(t,r){}delete(t){}gc(t){}write(t,r){t.writeJSON(this.embed)}getRef(){return 5}},N=class Mi{constructor(t,r){this.key=t,this.value=r}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new Mi(this.key,this.value)}splice(t){throw L()}mergeWith(t){return!1}integrate(t,r){const n=r.parent;n._searchMarker=null,n._hasFormatting=!0}delete(t){}gc(t){}write(t,r){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}},Bo=Ft("node_env")==="development",ze=class cr{constructor(t){this.arr=t,Bo&&Mr(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new cr(this.arr)}splice(t){const r=new cr(this.arr.slice(t));return this.arr=this.arr.slice(0,t),r}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,r){}delete(t){}gc(t){}write(t,r){const n=this.arr.length;t.writeLen(n-r);for(let i=r;i<n;i++){const s=this.arr[i];t.writeAny(s)}}getRef(){return 8}},pt=class hr{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new hr(this.str)}splice(t){const r=new hr(this.str.slice(t));this.str=this.str.slice(0,t);const n=this.str.charCodeAt(t-1);return n>=55296&&n<=56319&&(this.str=this.str.slice(0,t-1)+"\uFFFD",r.str="\uFFFD"+r.str.slice(1)),r}mergeWith(t){return this.str+=t.str,!0}integrate(t,r){}delete(t){}gc(t){}write(t,r){t.writeString(r===0?this.str:this.str.slice(r))}getRef(){return 4}},jo=0,Yo=1,Vo=2,Po=3,Ho=4,Go=6,Q=class $i{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new $i(this.type._copy())}splice(t){throw L()}mergeWith(t){return!1}integrate(t,r){this.type._integrate(t.doc,r)}delete(t){let r=this.type._start;for(;r!==null;)r.deleted?r.id.clock<(t.beforeState.get(r.id.client)||0)&&t._mergeStructs.push(r):r.delete(t),r=r.right;this.type._map.forEach(n=>{n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t)}),t.changed.delete(this.type)}gc(t){let r=this.type._start;for(;r!==null;)r.gc(t,!0),r=r.right;this.type._start=null,this.type._map.forEach(n=>{for(;n!==null;)n.gc(t,!0),n=n.left}),this.type._map=new Map}write(t,r){this.type._write(t)}getRef(){return 7}},We=(e,t)=>{let r=t,n=0,i;do n>0&&(r=b(r.client,r.clock+n)),i=ft(e,r),n=r.clock-i.id.clock,r=i.redone;while(r!==null&&i instanceof k);return{item:i,diff:n}},Je=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Qn=(e,t,r)=>{const{client:n,clock:i}=t.id,s=new k(b(n,i+r),t,b(n,i+r-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(r));return t.deleted&&s.markDeleted(),t.keep&&(s.keep=!0),t.redone!==null&&(s.redone=b(t.redone.client,t.redone.clock+r)),t.right=s,s.right!==null&&(s.right.left=s),e._mergeStructs.push(s),s.parentSub!==null&&s.right===null&&s.parent._map.set(s.parentSub,s),t.length=r,s},ti=(e,t)=>pe(e,r=>Tt(r.deletions,t)),ei=(e,t,r,n,i,s)=>{const l=e.doc,o=l.store,a=l.clientID,c=t.redone;if(c!==null)return O(e,c);let h=t.parent._item,u=null,f;if(h!==null&&h.deleted===!0){if(h.redone===null&&(!r.has(h)||ei(e,h,r,n,i,s)===null))return null;for(;h.redone!==null;)h=O(e,h.redone)}const d=h===null?t.parent:h.content.type;if(t.parentSub===null){for(u=t.left,f=t;u!==null;){let v=u;for(;v!==null&&v.parent._item!==h;)v=v.redone===null?null:O(e,v.redone);if(v!==null&&v.parent._item===h){u=v;break}u=u.left}for(;f!==null;){let v=f;for(;v!==null&&v.parent._item!==h;)v=v.redone===null?null:O(e,v.redone);if(v!==null&&v.parent._item===h){f=v;break}f=f.right}}else if(f=null,t.right&&!i){for(u=t;u!==null&&u.right!==null&&(u.right.redone||Tt(n,u.right.id)||ti(s.undoStack,u.right.id)||ti(s.redoStack,u.right.id));)for(u=u.right;u.redone;)u=O(e,u.redone);if(u&&u.right!==null)return null}else u=d._map.get(t.parentSub)||null;const g=T(o,a),p=b(a,g),m=new k(p,u,u&&u.lastId,f,f&&f.id,d,t.parentSub,t.content.copy());return t.redone=p,Je(m,!0),m.integrate(e,0),m},k=class ur extends Kn{constructor(t,r,n,i,s,l,o,a){super(t,a.getLength()),this.origin=n,this.left=r,this.right=i,this.rightOrigin=s,this.parent=l,this.parentSub=o,this.redone=null,this.content=a,this.info=this.content.isCountable()?mr:0}set marker(t){(this.info&me)>0!==t&&(this.info^=me)}get marker(){return(this.info&me)>0}get keep(){return(this.info&vr)>0}set keep(t){this.keep!==t&&(this.info^=vr)}get countable(){return(this.info&mr)>0}get deleted(){return(this.info&ve)>0}set deleted(t){this.deleted!==t&&(this.info^=ve)}markDeleted(){this.info|=ve}getMissing(t,r){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=T(r,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=T(r,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===zt&&this.id.client!==this.parent.client&&this.parent.clock>=T(r,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Sn(t,r,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=O(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===X||this.right&&this.right.constructor===X)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===ur?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===ur&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===zt){const n=ft(r,this.parent);n.constructor===X?this.parent=null:this.parent=n.content.type}return null}integrate(t,r){if(r>0&&(this.id.clock+=r,this.left=Sn(t,t.doc.store,b(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(r),this.length-=r),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let n=this.left,i;if(n!==null)i=n.right;else if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start;const s=new Set,l=new Set;for(;i!==null&&i!==this.right;){if(l.add(i),s.add(i),Wt(this.origin,i.origin)){if(i.id.client<this.id.client)n=i,s.clear();else if(Wt(this.rightOrigin,i.rightOrigin))break}else if(i.origin!==null&&l.has(ft(t.doc.store,i.origin)))s.has(ft(t.doc.store,i.origin))||(n=i,s.clear());else break;i=i.right}this.left=n}if(this.left!==null){const n=this.left.right;this.right=n,this.left.right=this}else{let n;if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start,this.parent._start=this;this.right=n}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),yn(t.doc.store,this),this.content.integrate(t,this),Tn(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new X(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:b(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Wt(t.origin,this.lastId)&&this.right===t&&Wt(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const r=this.parent._searchMarker;return r&&r.forEach(n=>{n.p===t&&(n.p=this,!this.deleted&&this.countable&&(n.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const r=this.parent;this.countable&&this.parentSub===null&&(r._length-=this.length),this.markDeleted(),Fe(t.deleteSet,this.id.client,this.id.clock,this.length),Tn(t,r,this.parentSub),this.content.delete(t)}}gc(t,r){if(!this.deleted)throw M();this.content.gc(t),r?go(t,this,new X(this.id,this.length)):this.content=new Fo(this.length)}write(t,r){const n=r>0?b(this.id.client,this.id.clock+r-1):this.origin,i=this.rightOrigin,s=this.parentSub,l=this.content.getRef()&is|(n===null?0:J)|(i===null?0:we)|(s===null?0:Pi);if(t.writeInfo(l),n!==null&&t.writeLeftID(n),i!==null&&t.writeRightID(i),n===null&&i===null){const o=this.parent;if(o._item!==void 0){const a=o._item;if(a===null){const c=_n(o);t.writeParentInfo(!0),t.writeString(c)}else t.writeParentInfo(!1),t.writeLeftID(a.id)}else o.constructor===String?(t.writeParentInfo(!0),t.writeString(o)):o.constructor===zt?(t.writeParentInfo(!1),t.writeLeftID(o)):M();s!==null&&t.writeString(s)}this.content.write(t,r)}},ri=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},ni="__ $YJS$ __";ri[ni]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),ri[ni]=!0;var ii=new Set(["p","div","section","article","header","footer","main","aside","h1","h2","h3","h4","h5","h6","ul","ol","li","blockquote","pre","table","thead","tbody","tfoot","tr","td","th","figure","figcaption"]),si=new Set(["strong","b","em","i","u","s","strike","del","ins","mark","small","sub","sup","code","kbd","samp","var","span","font","a"]),li=new Set(["br","hr","img","video","audio","source","iframe","embed","object"]);function Nt(e){const t=e.toLowerCase();return ii.has(t)?"block":li.has(t)?"leaf":si.has(t)?"mark":"unknown"}var Xo=["bold","italic","underline","strikethrough","subscript","superscript","color","backcolor","fontFamily","fontSize","link","code"],D="http://www.w3.org/1999/xhtml",Ke=null,qe=null;function oi(e){return e&&typeof e.XmlText=="function"&&typeof e.XmlElement=="function"?(Ke=e.XmlText,qe=e.XmlElement,!0):!1}function zo(e){e&&oi(e.Y)||typeof window<"u"&&oi(window.Y)||(Ke=le,qe=gt)}function ai(e){return new(Ke||le)(e)}function ci(e){return new(qe||gt)(e)}function ae(e){return!!e&&typeof e.nodeName=="string"&&typeof e.getAttributes=="function"}function hi(e){return!!e&&typeof e.toDelta=="function"&&typeof e.nodeName!="string"}function Wo(e){return e?e.textContent&&e.textContent.trim().length>0?!0:!!e.querySelector&&!!e.querySelector("img,table,hr,video,iframe,figure,ul,ol,blockquote,pre"):!1}function ce(e,t){for(;t.firstChild;)t.removeChild(t.firstChild);const r=t.ownerDocument;if(!r)throw new Error("renderFragmentToHost: editable host has no ownerDocument");for(let n=0;n<e.length;n++){const i=e.get(n),s=Ze(i,r);s&&t.appendChild(s)}t.childNodes.length===0&&t.appendChild(r.createElementNS(D,"p"))}function Ze(e,t){return hi(e)?Ko(e,t):ae(e)?Jo(e,t):null}function Jo(e,t){const r=e.nodeName.toLowerCase(),n=Nt(r);if(n==="unknown"){const s=t.createElementNS(D,"span");return s.setAttribute("data-rte-unknown",r),fi(e,s),ui(e,s,t),s}const i=t.createElementNS(D,r);return fi(e,i),n==="leaf"||ui(e,i,t),i}function ui(e,t,r){const n=e.length;for(let i=0;i<n;i++){const s=e.get(i),l=Ze(s,r);l&&t.appendChild(l)}}function fi(e,t){const r=e.getAttributes();for(const[n,i]of Object.entries(r))i!=null&&t.setAttribute(n,String(i))}function Ko(e,t){var r;const n=t.createDocumentFragment(),i=e.toDelta();for(const s of i){if(typeof s.insert!="string"||s.insert.length===0)continue;const l=Zo(s.attributes);let o=t.createTextNode(s.insert);for(let a=l.length-1;a>=0;a--){const c=Qo(l[a],(r=s.attributes)!=null?r:{},t);c.appendChild(o),o=c}n.appendChild(o)}return n}var qo=["link","color","backcolor","fontFamily","fontSize","code","underline","strikethrough","subscript","superscript","italic","bold"];function Zo(e){if(!e)return[];const t=[];for(const r of qo)r in e&&e[r]!=null&&e[r]!==!1&&t.push(r);return t}function Qo(e,t,r){switch(e){case"bold":return r.createElementNS(D,"strong");case"italic":return r.createElementNS(D,"em");case"underline":return r.createElementNS(D,"u");case"strikethrough":return r.createElementNS(D,"s");case"subscript":return r.createElementNS(D,"sub");case"superscript":return r.createElementNS(D,"sup");case"code":return r.createElementNS(D,"code");case"link":{const n=r.createElementNS(D,"a"),i=t.link;return typeof i=="string"&&n.setAttribute("href",i),n}case"color":{const n=r.createElementNS(D,"span");return n.setAttribute("style",`color:${t.color}`),n}case"backcolor":{const n=r.createElementNS(D,"span");return n.setAttribute("style",`background-color:${t.backcolor}`),n}case"fontFamily":{const n=r.createElementNS(D,"span");return n.setAttribute("style",`font-family:${t.fontFamily}`),n}case"fontSize":{const n=r.createElementNS(D,"span");return n.setAttribute("style",`font-size:${t.fontSize}`),n}default:return r.createElementNS(D,"span")}}function di(e){var t;const r=(t=e.ownerDocument)==null?void 0:t.defaultView,n=r?.getSelection(),i={insideHost:!1,anchorPath:[],anchorOffset:0,focusPath:[],focusOffset:0};if(!n||n.rangeCount===0)return i;const s=n.getRangeAt(0);return!e.contains(s.startContainer)||!e.contains(s.endContainer)?i:{insideHost:!0,anchorPath:pi(e,s.startContainer),anchorOffset:s.startOffset,focusPath:pi(e,s.endContainer),focusOffset:s.endOffset}}function gi(e,t){if(!t.insideHost)return;const r=e.ownerDocument,n=r?.defaultView;if(!r||!n)return;const i=n.getSelection();if(!i)return;const s=vi(e,t.anchorPath,t.anchorOffset),l=t.anchorPath===t.focusPath?s:vi(e,t.focusPath,t.focusOffset);try{const o=r.createRange();o.setStart(s.node,s.offset),o.setEnd(l.node,l.offset),i.removeAllRanges(),i.addRange(o)}catch{}}function pi(e,t){const r=[];let n=t;for(;n&&n!==e;){const i=n.parentNode;if(!i)break;let s=0,l=i.firstChild;for(;l&&l!==n;)s++,l=l.nextSibling;r.unshift(s),n=i}return r}function vi(e,t,r){let n=e;for(const s of t){const l=n.childNodes.item(s);if(!l)return{node:n,offset:0};n=l}const i=ta(n,r);return{node:n,offset:i}}function ta(e,t){if(e.nodeType===3){const n=e.data.length;return Math.max(0,Math.min(t,n))}const r=e.childNodes.length;return Math.max(0,Math.min(t,r))}function ea(e){var t,r;const n=(t=e.editable.ownerDocument)==null?void 0:t.defaultView;if(!n)return{disconnect:()=>{},drainPending:()=>{}};const i=(r=n.MutationObserver)!=null?r:globalThis.MutationObserver;if(!i)return{disconnect:()=>{},drainPending:()=>{}};const s=new i(l=>{var o;e.isApplyingRemote()||(o=e.fragment.doc)==null||o.transact(()=>{for(const a of l)ra(a,e)},W)});return s.observe(e.editable,{childList:!0,subtree:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0}),{disconnect:()=>s.disconnect(),drainPending:()=>{s.takeRecords()}}}function ra(e,t){switch(e.type){case"characterData":na(e,t);break;case"childList":ia(e,t);break;case"attributes":la(e,t);break}}function na(e,t){const r=e.target;if(r.nodeType!==3)return;const n=oa(r,t);if(!n)return;const i=r.data;n.toString()!==i&&(n.delete(0,n.length),n.insert(0,i))}function ia(e,t){if(e.target===t.editable){tr(t);return}e.target.nodeType===1&&sa(e.target,t)}function sa(e,t){const r=mi(e,t);if(!r){aa(t);return}r.delete(0,r.length);const n=ki(Array.from(e.childNodes));n.children.length>0&&(r.insert(0,n.children),er(n.marked))}function la(e,t){if(e.target.nodeType!==1)return;const r=e.target,n=mi(r,t);if(!n||e.attributeName===null)return;const i=r.getAttribute(e.attributeName);i===null?n.removeAttribute(e.attributeName):n.getAttribute(e.attributeName)!==i&&n.setAttribute(e.attributeName,i)}function oa(e,t){const r=wi(t.editable,e);if(r.length===0)return null;let n=t.fragment;for(let s=0;s<r.length-1;s++){const l=r[s],o=n.get(l);if(!ae(o))return null;n=o}const i=n.get(r[r.length-1]);return hi(i)?i:null}function mi(e,t){const r=wi(t.editable,e);if(r.length===0)return null;let n=t.fragment;for(const i of r){const s=n.get(i);if(!ae(s))return null;n=s}return ae(n)?n:null}function wi(e,t){const r=[];let n=t;for(;n&&n!==e;){const i=n.parentNode;if(!i)break;let s=0,l=i.firstChild;for(;l&&l!==n;)s++,l=l.nextSibling;r.unshift(s),n=i}return r}var Qe=new WeakSet;function aa(e){Qe.has(e.fragment)||(Qe.add(e.fragment),queueMicrotask(()=>{var t;Qe.delete(e.fragment),(t=e.fragment.doc)==null||t.transact(()=>tr(e),W)}))}function tr(e){e.fragment.delete(0,e.fragment.length);const t=bi(e.editable);t.children.length>0&&(e.fragment.insert(0,t.children),er(t.marked))}function bi(e){const t={children:[],marked:[]};for(let r=0;r<e.childNodes.length;r++){const n=e.childNodes.item(r),i=_i(n);if(i){i.node&&t.children.push(i.node);for(const s of i.marked)t.marked.push(s)}}return t}function _i(e){if(e.nodeType===3)return{node:ai(e.data),marked:[]};if(e.nodeType!==1)return null;const t=e,r=t.tagName.toLowerCase(),n=Nt(r);if(n==="mark")return null;const i=ci(r);for(const l of Array.from(t.attributes))i.setAttribute(l.name,l.value);if(n==="leaf")return{node:i,marked:[]};const s=ki(Array.from(t.childNodes));for(const l of s.children)i.insert(i.length,[l]);return{node:i,marked:s.marked}}function ca(){return{str:"",ranges:[]}}function ki(e){const t={marked:[],children:[]};let r=null;const n=()=>{if(r&&r.str.length>0){const s=ai(r.str);t.children.push(s),r.ranges.length>0&&t.marked.push({text:s,ranges:r.ranges})}r=null},i=()=>(r||(r=ca()),r);for(const s of e){if(s.nodeType===3){const c=s.data;if(c.length===0)continue;const h=i();h.str+=c;continue}if(s.nodeType!==1)continue;const l=s,o=l.tagName.toLowerCase(),a=Nt(o);if(a==="mark"){const c=i(),h=Ei(l);yi(l,c,h);continue}if(n(),a==="leaf"){const c=ci(o);for(const h of Array.from(l.attributes))c.setAttribute(h.name,h.value);t.children.push(c)}else{const c=_i(l);if(c&&c.node){t.children.push(c.node);for(const h of c.marked)t.marked.push(h)}}}return n(),t}function yi(e,t,r){for(const n of Array.from(e.childNodes)){if(n.nodeType===3){const l=n.data;if(l.length===0)continue;const o=t.str.length;t.str+=l;const a=t.str.length;Object.keys(r).length>0&&t.ranges.push({start:o,end:a,marks:r});continue}if(n.nodeType!==1)continue;const i=n;if(Nt(i.tagName.toLowerCase())==="mark"){const l={...r,...Ei(i)};yi(i,t,l)}}}function er(e){for(const t of e)for(const r of t.ranges){const n=r.end-r.start;n<=0||t.text.format(r.start,n,r.marks)}}var Si={buildYNodesFromDom:bi,applyDeferredMarks:er};function Ei(e){switch(e.tagName.toLowerCase()){case"strong":case"b":return{bold:!0};case"em":case"i":return{italic:!0};case"u":return{underline:!0};case"s":case"strike":case"del":return{strikethrough:!0};case"sub":return{subscript:!0};case"sup":return{superscript:!0};case"code":case"kbd":case"samp":return{code:!0};case"a":{const r=e.getAttribute("href");return r?{link:r}:{}}case"span":case"font":return ha(e);default:return{}}}function ha(e){var t;const r={},n=(t=e.getAttribute("style"))!=null?t:"";for(const i of n.split(";")){const[s,...l]=i.split(":");if(!s||l.length===0)continue;const o=s.trim().toLowerCase(),a=l.join(":").trim();if(a)switch(o){case"color":r.color=a;break;case"background-color":case"background":r.backcolor=a;break;case"font-family":r.fontFamily=a;break;case"font-size":r.fontSize=a;break}}if(e.tagName.toLowerCase()==="font"){const i=e.getAttribute("color");i&&(r.color=i);const s=e.getAttribute("face");s&&(r.fontFamily=s)}return r}function Ci(e){var t,r,n;zo(e);const i=(t=e.fragmentName)!=null?t:"default",s=e.ydoc.getXmlFragment(i),l=(n=e.awareness)!=null?n:(r=e.provider)==null?void 0:r.awareness;let o=!1;const a=ea({editable:e.editable,fragment:s,isApplyingRemote:()=>o}),c=Wo(e.editable);let h=!1,u=null;const f=()=>{if(!h){if(h=!0,u!=null){try{clearTimeout(u)}catch{}u=null}o=!0;try{if(s.length>0)ce(s,e.editable);else if(c&&e.seedFromHost!==!1){const $=s.doc;$&&$.transact(()=>tr({editable:e.editable,fragment:s}),W)}else ce(s,e.editable)}finally{a.drainPending(),o=!1}}};let d=()=>{};o=!0;const g=e.provider;if(g&&g.synced===!0)f();else if(g&&typeof g.on=="function"){const $=z=>{(z===void 0||z)&&f()};g.on("sync",$),g.on("synced",$),d=()=>{try{typeof g.off=="function"&&(g.off("sync",$),g.off("synced",$))}catch{}},typeof setTimeout=="function"?u=setTimeout(f,3e3):f()}else f();const p=($,z)=>{if(!h||z===W||z===W)return;const ya=di(e.editable);o=!0;try{ce(s,e.editable)}finally{a.drainPending(),o=!1}gi(e.editable,ya)};e.ydoc.on("update",p);const m=()=>{e.ydoc.off("update",p)},v=()=>a.disconnect(),j=ua(l,e.initialAwareness);let tt=[m,v,j,d];return{ydoc:e.ydoc,fragment:s,dispose(){for(const $ of tt)try{$()}catch(z){console.error("[crdt-engine] dispose cleanup error:",z)}tt=[]}}}function ua(e,t){return e?(t&&e.setLocalState(t),()=>e.setLocalState(null)):()=>{}}function fa(e){var t;const r=new Set([W]);if(e.extraTrackedOrigins)for(const n of e.extraTrackedOrigins)r.add(n);return new bo(e.fragment,{trackedOrigins:r,captureTimeout:(t=e.captureTimeoutMs)!=null?t:500})}var da=32;function ga(e){var t,r;const n=(t=e.editable.ownerDocument)==null?void 0:t.defaultView,i=e.editable.ownerDocument,s=(r=e.throttleMs)!=null?r:da;let l=null,o=null,a=null;const c=()=>{var f;if(!i)return;const d=n?.getSelection();if(!d||d.rangeCount===0){e.awareness.setLocalStateField("cursor",null);return}const g=d.getRangeAt(0);if(!e.editable.contains(g.startContainer)||!e.editable.contains(g.endContainer)){e.awareness.setLocalStateField("cursor",null);return}const p=Ti(e.fragment,e.editable,g.startContainer,g.startOffset),m=d.isCollapsed?p:Ti(e.fragment,e.editable,g.endContainer,g.endOffset);if(!p||!m){e.awareness.setLocalStateField("cursor",null);return}if(l&&o&&Ii(l,p)&&Ii(o,m))return;l=p,o=m;const v={...e.user?{user:e.user}:{},cursor:{anchor:{encoded:p},head:{encoded:m}}};e.awareness.setLocalState({...(f=e.awareness.getStates().get(e.awareness.clientID))!=null?f:{},...v,active:Date.now()})},h=()=>{a==null&&(a=setTimeout(()=>{a=null,c()},s))},u=()=>h();return i&&i.addEventListener("selectionchange",u),{dispose(){a!=null&&clearTimeout(a),i&&i.removeEventListener("selectionchange",u),e.awareness.setLocalStateField("cursor",null)},publishNow(){a!=null&&(clearTimeout(a),a=null),c()},snapshotPeers(){var f,d;const g=[];for(const[p,m]of e.awareness.getStates()){if(p===e.awareness.clientID)continue;const v=m;if(!v.cursor)continue;const j=Ai(e.fragment,e.editable,v.cursor.anchor.encoded),tt=v.cursor.head===v.cursor.anchor?j:Ai(e.fragment,e.editable,v.cursor.head.encoded);g.push({clientID:p,user:(f=v.user)!=null?f:{},anchor:j,head:tt,isCollapsed:j!==null&&tt!==null&&j.node===tt.node&&j.offset===tt.offset,activeAt:(d=v.active)!=null?d:0})}return g}}}function Ti(e,t,r,n){const i=pa(e,t,r,n);if(!i)return null;try{const s=ro(i.parent,i.index);return io(s)}catch{return null}}function Ai(e,t,r){if(!e.doc)return null;try{const n=lo(r),i=ao(n,e.doc);return i?va(t,i.type,i.index):null}catch{return null}}function pa(e,t,r,n){var i;const s=[];let l=n,o=r;if(o.nodeType===3)for(;o&&o!==t;){const u=o.parentNode;if(!u)break;let f=0,d=u.firstChild;for(;d&&d!==o;)f+=rr(d),d=d.nextSibling;if(l+=f,u===t||wa(u)){o=u;break}o=u}else if(o.nodeType===1){let u=0;for(let f=0;f<n&&f<o.childNodes.length;f++)u+=rr(o.childNodes.item(f));l=u}if(o===t){const u=(i=ba(t,r===t?t:r).at(0))!=null?i:0;return{parent:e,index:u}}let a=o;for(;a&&a!==t;){const u=a.parentNode;if(!u)return null;let f=0,d=u.firstChild;for(;d&&d!==a;)f++,d=d.nextSibling;s.unshift(f),a=u}let c=e;for(const u of s){const f=c.get(u);if(!(f instanceof gt))return null;c=f}const h=c.get(0);return h instanceof le?{parent:h,index:l}:{parent:c,index:0}}function va(e,t,r){const n=[];let i=t,s=!0;for(;i;){const a=i._item;if(!a)break;const c=a.parent;if(!c)break;let h=0,u=!1;if(c instanceof se||c instanceof gt){for(let f=0;f<c.length;f++)if(c.get(f)===i){h=f,u=!0;break}}if(!u)break;s&&t instanceof le||n.unshift(h),s=!1,i=c}let l=e;for(const a of n){const c=l.childNodes.item(a);if(!c)return null;l=c}return ma(l,r)}function ma(e,t){let r=t;const n=[];for(let i=e.childNodes.length-1;i>=0;i--)n.push(e.childNodes.item(i));for(;n.length>0;){const i=n.pop();if(i.nodeType===3){const s=i.data.length;if(r<=s)return{node:i,offset:r};r-=s;continue}if(i.nodeType===1)for(let s=i.childNodes.length-1;s>=0;s--)n.push(i.childNodes.item(s))}return{node:e,offset:e.childNodes.length}}function rr(e){if(e.nodeType===3)return e.data.length;let t=0;for(let r=0;r<e.childNodes.length;r++)t+=rr(e.childNodes.item(r));return t}function wa(e){if(e.nodeType!==1)return!1;const t=e.tagName.toLowerCase();return!["strong","b","em","i","u","s","strike","del","ins","mark","small","sub","sup","code","kbd","samp","var","span","font","a"].includes(t)}function ba(e,t){const r=[];let n=t;for(;n&&n!==e;){const i=n.parentNode;if(!i)break;let s=0,l=i.firstChild;for(;l&&l!==n;)s++,l=l.nextSibling;r.unshift(s),n=i}return r}function Ii(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}function _a(e){var t,r;const n=(t=e.textSync)!=null?t:!1;if(n==="crdt")return Ci(e);if(n===!0){if(!e.legacySnapshotAttach)throw new Error("[crdt-engine] textSync: true requires `legacySnapshotAttach` to be provided by the host. See M5.1 in the sprint README for the back-compat contract.");return e.legacySnapshotAttach(e)}const i=e.ydoc.getXmlFragment((r=e.fragmentName)!=null?r:"default");return{ydoc:e.ydoc,fragment:i,dispose(){}}}function ka(e){var t;const r=(t=e.fragmentName)!=null?t:"default",n=e.ydoc.getXmlFragment(r),i=e.parserDocument.createElement("div");i.innerHTML=e.html;let s=i;const l=i.querySelector("body");l&&(s=l);const o=Si.buildYNodesFromDom(s);return e.replace!==!1&&n.length>0&&n.delete(0,n.length),o.children.length>0&&(n.insert(n.length,o.children),Si.applyDeferredMarks(o.marked)),n}typeof window<"u"&&(window.RichTextEditorCrdt=dr)})();
1
+ "use strict";(()=>{var Us=Object.defineProperty;var qi=(e,t,n)=>t in e?Us(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Ds=(e,t)=>{for(var n in t)Us(e,n,{get:t[n],enumerable:!0})};var rn=(e,t,n)=>qi(e,typeof t!="symbol"?t+"":t,n);var Cs={};Ds(Cs,{BLOCK_TAGS:()=>xs,INLINE_MARK_TAGS:()=>bs,LEAF_TAGS:()=>ks,LOCAL_ORIGIN:()=>at,SUPPORTED_MARKS:()=>Ci,attachAwareness:()=>Pi,attachCollab:()=>Xi,attachCrdtBinding:()=>rr,attachUndoManager:()=>$i,captureSelection:()=>er,classify:()=>Tt,htmlToYFragment:()=>Gi,renderFragmentToHost:()=>nn,renderYNodeToDom:()=>tr,restoreSelection:()=>nr});var at=Symbol.for("rte.crdt.local");var Jt={};Ds(Jt,{AbsolutePosition:()=>Fn,AbstractConnector:()=>Xr,AbstractStruct:()=>ke,AbstractType:()=>_,Array:()=>Pt,ContentAny:()=>Ct,ContentBinary:()=>Gt,ContentDeleted:()=>Se,ContentDoc:()=>qt,ContentEmbed:()=>gt,ContentFormat:()=>C,ContentJSON:()=>tn,ContentString:()=>et,ContentType:()=>Q,Doc:()=>At,GC:()=>$,ID:()=>ht,Item:()=>S,Map:()=>Xt,PermanentUserData:()=>qr,RelativePosition:()=>xe,Skip:()=>R,Snapshot:()=>Ge,Text:()=>be,Transaction:()=>Yn,UndoManager:()=>qe,UpdateDecoderV1:()=>X,UpdateDecoderV2:()=>j,UpdateEncoderV1:()=>ct,UpdateEncoderV2:()=>J,XmlElement:()=>O,XmlFragment:()=>pt,XmlHook:()=>Qe,XmlText:()=>K,YArrayEvent:()=>Pn,YEvent:()=>Ht,YMapEvent:()=>Xn,YTextEvent:()=>Gn,YXmlEvent:()=>qn,applyUpdate:()=>Sl,applyUpdateV2:()=>Kn,cleanupYTextFormatting:()=>bi,compareIDs:()=>Bt,compareRelativePositions:()=>Ml,convertUpdateFormatV1ToV2:()=>na,convertUpdateFormatV2ToV1:()=>ri,createAbsolutePositionFromRelativePosition:()=>ds,createDeleteSet:()=>Jn,createDeleteSetFromStructStore:()=>ns,createDocFromSnapshot:()=>Yl,createID:()=>x,createRelativePositionFromJSON:()=>Il,createRelativePositionFromTypeIndex:()=>ls,createSnapshot:()=>hs,decodeRelativePosition:()=>us,decodeSnapshot:()=>Bl,decodeSnapshotV2:()=>Po,decodeStateVector:()=>os,decodeUpdate:()=>Jl,decodeUpdateV2:()=>Wo,diffUpdate:()=>Ql,diffUpdateV2:()=>fs,emptySnapshot:()=>Fl,encodeRelativePosition:()=>as,encodeSnapshot:()=>Vl,encodeSnapshotV2:()=>Ho,encodeStateAsUpdate:()=>Al,encodeStateAsUpdateV2:()=>$o,encodeStateVector:()=>Tl,encodeStateVectorFromUpdate:()=>Kl,encodeStateVectorFromUpdateV2:()=>Qo,equalDeleteSets:()=>Bo,equalSnapshots:()=>Rl,findIndexSS:()=>Z,findRootTypeKey:()=>cs,getItem:()=>Ft,getItemCleanEnd:()=>Kr,getItemCleanStart:()=>F,getState:()=>E,getTypeChildren:()=>ia,isDeleted:()=>zt,isParentOf:()=>Xe,iterateDeletedStructs:()=>$t,logType:()=>Ul,logUpdate:()=>zl,logUpdateV2:()=>Ko,mergeDeleteSets:()=>Yt,mergeUpdates:()=>Zo,mergeUpdatesV2:()=>Je,obfuscateUpdate:()=>ta,obfuscateUpdateV2:()=>ea,parseUpdateMeta:()=>Wl,parseUpdateMetaV2:()=>ti,readUpdate:()=>kl,readUpdateV2:()=>ss,relativePositionToJSON:()=>Dl,snapshot:()=>$l,snapshotContainsUpdate:()=>Hl,transact:()=>k,tryGc:()=>Gl,typeListToArraySnapshot:()=>ca,typeMapGetAllSnapshot:()=>gi,typeMapGetSnapshot:()=>ua});var A=()=>new Map,sn=e=>{let t=A();return e.forEach((n,r)=>{t.set(r,n)}),t},B=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},Is=(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 nt=()=>new Set;var on=e=>e[e.length-1];var vs=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},tt=Array.from,cn=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},_e=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1};var Os=(e,t)=>{let n=new Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n};var ut=Array.isArray;var Kt=class{constructor(){this._observers=A()}on(t,n){return B(this._observers,t,nt).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 tt((this._observers.get(t)||A()).values()).forEach(r=>r(...n))}destroy(){this._observers=A()}},ln=class{constructor(){this._observers=A()}on(t,n){B(this._observers,t,nt).add(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 tt((this._observers.get(t)||A()).values()).forEach(r=>r(...n))}destroy(){this._observers=A()}};var L=Math.floor;var Dt=Math.abs;var an=(e,t)=>e<t?e:t,dt=(e,t)=>e>t?e:t,fu=Number.isNaN;var un=e=>e!==0?e<0:1/e<0;var Zt=Number.MAX_SAFE_INTEGER,ir=Number.MIN_SAFE_INTEGER,pu=1<<31;var Ls=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&L(e)===e),gu=Number.isNaN,mu=Number.parseInt;var lr=String.fromCharCode,zi=String.fromCodePoint,wu=lr(65535),Ji=e=>e.toLowerCase(),Ki=/^\s*/g,Wi=e=>e.replace(Ki,""),Zi=/([A-Z])/g,ar=(e,t)=>Wi(e.replace(Zi,n=>`${t}${Ji(n)}`));var Qi=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},te=typeof TextEncoder!="undefined"?new TextEncoder:null,tc=e=>te.encode(e),Ms=te?tc:Qi;var Qt=typeof TextDecoder=="undefined"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Qt&&Qt.decode(new Uint8Array).length===1&&(Qt=null);var dn=(e,t)=>Os(t,()=>e).join("");var It=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},vt=()=>new It;var ec=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(ec(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},nc=(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(dt(n,t)*2),e.cpos=0)},I=(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 se=I;var m=(e,t)=>{for(;t>127;)I(e,128|127&t),t=L(t/128);I(e,127&t)},De=(e,t)=>{let n=un(t);for(n&&(t=-t),I(e,(t>63?128:0)|(n?64:0)|63&t),t=L(t/64);t>0;)I(e,(t>127?128:0)|127&t),t=L(t/128)},ur=new Uint8Array(3e4),rc=ur.length/3,sc=(e,t)=>{if(t.length<rc){let n=te.encodeInto(t,ur).written||0;m(e,n);for(let r=0;r<n;r++)I(e,ur[r])}else H(e,Ms(t))},oc=(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;m(e,r);for(let s=0;s<r;s++)I(e,n.codePointAt(s))},mt=te&&te.encodeInto?sc:oc;var $s=(e,t)=>oe(e,G(t)),oe=(e,t)=>{let n=e.cbuf.length,r=e.cpos,s=an(n-r,t.length),o=t.length-s;e.cbuf.set(t.subarray(0,s),r),e.cpos+=s,o>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(dt(n*2,o)),e.cbuf.set(t.subarray(s)),e.cpos=o)},H=(e,t)=>{m(e,t.byteLength),oe(e,t)},dr=(e,t)=>{nc(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},ic=(e,t)=>dr(e,4).setFloat32(0,t,!1),cc=(e,t)=>dr(e,8).setFloat64(0,t,!1),lc=(e,t)=>dr(e,8).setBigInt64(0,t,!1);var Vs=new DataView(new ArrayBuffer(4)),ac=e=>(Vs.setFloat32(0,e),Vs.getFloat32(0)===e),ne=(e,t)=>{switch(typeof t){case"string":I(e,119),mt(e,t);break;case"number":Ls(t)&&Dt(t)<=2147483647?(I(e,125),De(e,t)):ac(t)?(I(e,124),ic(e,t)):(I(e,123),cc(e,t));break;case"bigint":I(e,122),lc(e,t);break;case"object":if(t===null)I(e,126);else if(ut(t)){I(e,117),m(e,t.length);for(let n=0;n<t.length;n++)ne(e,t[n])}else if(t instanceof Uint8Array)I(e,116),H(e,t);else{I(e,118);let n=Object.keys(t);m(e,n.length);for(let r=0;r<n.length;r++){let s=n[r];mt(e,s),ne(e,t[s])}}break;case"boolean":I(e,t?120:121);break;default:I(e,127)}},Ue=class extends It{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&m(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}};var Bs=e=>{e.count>0&&(De(e.encoder,e.count===1?e.s:-e.s),e.count>1&&m(e.encoder,e.count-2))},Nt=class{constructor(){this.encoder=new It,this.s=0,this.count=0}write(t){this.s===t?this.count++:(Bs(this),this.count=1,this.s=t)}toUint8Array(){return Bs(this),G(this.encoder)}};var Fs=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);De(e.encoder,t),e.count>1&&m(e.encoder,e.count-2)}},re=class{constructor(){this.encoder=new It,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(Fs(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return Fs(this),G(this.encoder)}},hn=class{constructor(){this.sarr=[],this.s="",this.lensE=new Nt}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 It;return this.sarr.push(this.s),this.s="",mt(t,this.sarr.join("")),oe(t,this.lensE.toUint8Array()),G(t)}};var q=e=>new Error(e),z=()=>{throw q("Method unimplemented")},N=()=>{throw q("Unexpected case")};var Ys=q("Unexpected end of array"),js=q("Integer out of Range"),ie=class{constructor(t){this.arr=t,this.pos=0}},M=e=>new ie(e),fr=e=>e.pos!==e.arr.length;var dc=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},P=e=>dc(e,b(e));var Ot=e=>e.arr[e.pos++];var b=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>Zt)throw js}throw Ys},Ne=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 o=e.arr.length;for(;e.pos<o;){if(t=e.arr[e.pos++],n=n+(t&127)*r,r*=128,t<128)return s*n;if(n>Zt)throw js}throw Ys};var hc=e=>{let t=b(e);if(t===0)return"";{let n=String.fromCodePoint(Ot(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(Ot(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))}},fc=e=>Qt.decode(P(e)),yt=Qt?fc:hc;var pr=(e,t)=>{let n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},pc=e=>pr(e,4).getFloat32(0,!1),gc=e=>pr(e,8).getFloat64(0,!1),mc=e=>pr(e,8).getBigInt64(0,!1);var wc=[e=>{},e=>null,Ne,pc,gc,mc,e=>!1,e=>!0,yt,e=>{let t=b(e),n={};for(let r=0;r<t;r++){let s=yt(e);n[s]=ce(e)}return n},e=>{let t=b(e),n=[];for(let r=0;r<t;r++)n.push(ce(e));return n},P],ce=e=>wc[127-Ot(e)](e),Ie=class extends ie{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),fr(this)?this.count=b(this)+1:this.count=-1),this.count--,this.s}};var Lt=class extends ie{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Ne(this);let t=un(this.s);this.count=1,t&&(this.s=-this.s,this.count=b(this)+2)}return this.count--,this.s}};var le=class extends ie{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let t=Ne(this),n=t&1;this.diff=L(t/2),this.count=1,n&&(this.count=b(this)+2)}return this.s+=this.diff,this.count--,this.s}},fn=class{constructor(t){this.decoder=new Lt(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 bu=crypto.subtle,Hs=crypto.getRandomValues.bind(crypto);var gr=()=>Hs(new Uint32Array(1))[0];var xc="10000000-1000-4000-8000"+-1e11,Ps=()=>xc.replace(/[018]/g,e=>(e^gr()&15>>e/4).toString(16));var xt=Date.now;var wr=e=>new Promise(e);var Eu=Promise.all.bind(Promise);var yr=e=>e===void 0?null:e;var xr=class{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}},Xs=new xr,Ec=!0;try{typeof localStorage!="undefined"&&localStorage&&(Xs=localStorage,Ec=!1)}catch(e){}var Gs=Xs;var Mt=Symbol("Equality"),pn=(e,t)=>{var n;return e===t||!!((n=e==null?void 0:e[Mt])!=null&&n.call(e,t))||!1};var qs=e=>typeof e=="object",zs=Object.assign,_c=Object.keys;var Js=(e,t)=>{for(let n in e)t(e[n],n)};var ve=e=>_c(e).length;var Ks=e=>{for(let t in e)return!1;return!0},ae=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Oe=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),kr=(e,t)=>e===t||ve(e)===ve(t)&&ae(e,(n,r)=>(n!==void 0||Oe(t,r))&&pn(t[r],n)),Cc=Object.freeze,Sr=e=>{for(let t in e){let n=e[t];(typeof n=="object"||typeof n=="function")&&Sr(e[t])}return Cc(e)};var Le=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Le(e,t,n+1)}};var Ar=e=>e;var Rt=(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[Mt]!=null)return e[Mt](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)||!Rt(e.get(n),t.get(n)))return!1;break}case void 0:case Object:if(ve(e)!==ve(t))return!1;for(let n in e)if(!Oe(e,n)||!Rt(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(!Rt(e[n],t[n]))return!1;break;default:return!1}return!0},Ws=(e,t)=>t.includes(e);var Me=typeof process!="undefined"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process!="undefined"?process:0)==="[object process]";var Au=typeof navigator!="undefined"?/Mac/.test(navigator.platform):!1,rt,Tc=[],Uc=()=>{if(rt===void 0)if(Me){rt=A();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]==="-"?(t!==null&&rt.set(t,""),t=r):t!==null?(rt.set(t,r),t=null):Tc.push(r)}t!==null&&rt.set(t,"")}else typeof location=="object"?(rt=A(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){let[t,n]=e.split("=");rt.set(`--${ar(t,"-")}`,n),rt.set(`-${ar(t,"-")}`,n)}})):rt=A();return rt},_r=e=>Uc().has(e);var Re=e=>Me?yr(process.env[e.toUpperCase().replaceAll("-","_")]):yr(Gs.getItem(e));var Zs=e=>_r("--"+e)||Re(e)!==null,Qs=Zs("production"),Dc=Me&&Ws(process.env.FORCE_COLOR,["true","1","2"]),to=Dc||!_r("--no-colors")&&!Zs("no-color")&&(!Me||process.stdout.isTTY)&&(!Me||_r("--color")||Re("COLORTERM")!==null||(Re("TERM")||"").includes("color"));var Ic=e=>new Uint8Array(e);var eo=e=>{let t=Ic(e.byteLength);return t.set(e),t};var Tr=class{constructor(t,n){this.left=t,this.right=n}},st=(e,t)=>new Tr(e,t);var Ur=e=>e.next()>=.5,mn=(e,t,n)=>L(e.next()*(n+1-t)+t);var Dr=(e,t,n)=>L(e.next()*(n+1-t)+t);var Ir=(e,t,n)=>Dr(e,t,n);var Oc=e=>lr(Ir(e,97,122)),no=(e,t=0,n=20)=>{let r=Ir(e,t,n),s="";for(let o=0;o<r;o++)s+=Oc(e);return s};var wn=(e,t)=>t[Ir(e,0,t.length-1)];var Mc=Symbol("0schema"),Nr=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(dn(" ",(this._rerrs.length-n)*2)+`${r.path!=null?`[${r.path}] `:""}${r.has} doesn't match ${r.expected}. ${r.message}`)}return t.join(`
2
+ `)}},vr=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[Mt]?pn(e,t):ut(e)?cn(e,n=>_e(t,r=>vr(n,r))):qs(e)?ae(e,(n,r)=>vr(n,t[r])):!1,v=class{extends(t){let[n,r]=[this.shape,t.shape];return this.constructor._dilutes&&([r,n]=[n,r]),vr(n,r)}equals(t){return this.constructor===t.constructor&&Rt(this.shape,t.shape)}[Mc](){return!0}[Mt](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){z()}get nullable(){return ge(this,In)}get optional(){return new yn(this)}cast(t){return ro(t,this),t}expect(t){return ro(t,this),t}};rn(v,"_dilutes",!1);var Ve=class extends v{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n=void 0){let r=(t==null?void 0:t.constructor)===this.shape&&(this._c==null||this._c(t));return!r&&(n==null||n.extend(null,this.shape.name,t==null?void 0:t.constructor.name,(t==null?void 0:t.constructor)!==this.shape?"Constructor match failed":"Check failed")),r}},T=(e,t=null)=>new Ve(e,t),Cu=T(Ve),Be=class extends v{constructor(t){super(),this.shape=t}check(t,n){let r=this.shape(t);return!r&&(n==null||n.extend(null,"custom prop",t==null?void 0:t.constructor.name,"failed to check custom prop")),r}},D=e=>new Be(e),Tu=T(Be),fe=class extends v{constructor(t){super(),this.shape=t}check(t,n){let r=this.shape.some(s=>s===t);return!r&&(n==null||n.extend(null,this.shape.join(" | "),t.toString())),r}},Un=(...e)=>new fe(e),so=T(fe),Rc=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,t=>"\\"+t)),oo=e=>{if(pe.check(e))return[Rc(e)];if(so.check(e))return e.shape.map(t=>t+"");if(uo.check(e))return["[+-]?\\d+.?\\d*"];if(ho.check(e))return[".*"];if(_n.check(e))return e.shape.map(oo).flat(1);N()},Or=class extends v{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(oo).map(n=>`(${n.join("|")})`).join("")+"$")}check(t,n){let r=this._r.exec(t)!=null;return!r&&(n==null||n.extend(null,this._r.toString(),t.toString(),"String doesn't match string template.")),r}};var Uu=T(Or),Vc=Symbol("optional"),yn=class extends v{constructor(t){super(),this.shape=t}check(t,n){let r=t===void 0||this.shape.check(t);return!r&&(n==null||n.extend(null,"undefined (optional)","()")),r}get[Vc](){return!0}},Bc=T(yn),xn=class extends v{check(t,n){return n==null||n.extend(null,"never",typeof t),!1}},Du=new xn,Iu=T(xn),Tn=class Tn extends v{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}get partial(){return new Tn(this.shape,!0)}check(t,n){return t==null?(n==null||n.extend(null,"object","null"),!1):ae(this.shape,(r,s)=>{let o=this._isPartial&&!Oe(t,s)||r.check(t[s],n);return!o&&(n==null||n.extend(s.toString(),r.toString(),typeof t[s],"Object property does not match")),o})}};rn(Tn,"_dilutes",!0);var bn=Tn,Fc=e=>new bn(e),$c=T(bn),Yc=D(e=>e!=null&&(e.constructor===Object||e.constructor==null)),kn=class extends v{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return t!=null&&ae(t,(r,s)=>{let o=this.shape.keys.check(s,n);return!o&&(n==null||n.extend(s+"","Record",typeof t,o?"Key doesn't match schema":"Value doesn't match value")),o&&this.shape.values.check(r,n)})}},io=(e,t)=>new kn(e,t),jc=T(kn),Sn=class extends v{constructor(t){super(),this.shape=t}check(t,n){return t!=null&&ae(this.shape,(r,s)=>{let o=r.check(t[s],n);return!o&&(n==null||n.extend(s.toString(),"Tuple",typeof r)),o})}},Hc=(...e)=>new Sn(e),Nu=T(Sn),En=class extends v{constructor(t){super(),this.shape=t.length===1?t[0]:new de(t)}check(t,n){let r=ut(t)&&cn(t,s=>this.shape.check(s));return!r&&(n==null||n.extend(null,"Array","")),r}},co=(...e)=>new En(e),Pc=T(En),Xc=D(e=>ut(e)),An=class extends v{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==null||n.extend(null,this.shape.name,t==null?void 0:t.constructor.name)),r}},Gc=(e,t=null)=>new An(e,t),vu=T(An),qc=Gc(v),Lr=class extends v{constructor(t){super(),this.len=t.length-1,this.args=Hc(...t.slice(-1)),this.res=t[this.len]}check(t,n){let r=t.constructor===Function&&t.length<=this.len;return!r&&(n==null||n.extend(null,"function",typeof t)),r}};var zc=T(Lr),Jc=D(e=>typeof e=="function"),Mr=class extends v{constructor(t){super(),this.shape=t}check(t,n){let r=cn(this.shape,s=>s.check(t,n));return!r&&(n==null||n.extend(null,"Intersectinon",typeof t)),r}};var Ou=T(Mr,e=>e.shape.length>0),de=class extends v{constructor(t){super(),this.shape=t}check(t,n){let r=_e(this.shape,s=>s.check(t,n));return n==null||n.extend(null,"Union",typeof t),r}};rn(de,"_dilutes",!0);var ge=(...e)=>e.findIndex(t=>_n.check(t))>=0?ge(...e.map(t=>Fe(t)).map(t=>_n.check(t)?t.shape:[t]).flat(1)):e.length===1?e[0]:new de(e),_n=T(de),lo=()=>!0,Cn=D(lo),Kc=T(Be,e=>e.shape===lo),Vr=D(e=>typeof e=="bigint"),Wc=D(e=>e===Vr),ao=D(e=>typeof e=="symbol"),Lu=D(e=>e===ao),he=D(e=>typeof e=="number"),uo=D(e=>e===he),pe=D(e=>typeof e=="string"),ho=D(e=>e===pe),Dn=D(e=>typeof e=="boolean"),Zc=D(e=>e===Dn),fo=Un(void 0),Mu=T(fe,e=>e.shape.length===1&&e.shape[0]===void 0),Ru=Un(void 0);var In=Un(null),Qc=T(fe,e=>e.shape.length===1&&e.shape[0]===null),Vu=T(Uint8Array),Bu=T(Ve,e=>e.shape===Uint8Array),tl=ge(he,pe,In,fo,Vr,Dn,ao),Fu=(()=>{let e=co(Cn),t=io(pe,Cn),n=ge(he,pe,In,Dn,e,t);return e.shape=n,t.shape.values=n,n})(),Fe=e=>{if(qc.check(e))return e;if(Yc.check(e)){let t={};for(let n in e)t[n]=Fe(e[n]);return Fc(t)}else{if(Xc.check(e))return ge(...e.map(Fe));if(tl.check(e))return Un(e);if(Jc.check(e))return T(e)}N()},ro=Qs?()=>{}:(e,t)=>{let n=new Nr;if(!t.check(e,n))throw q(`Expected value to be of type ${t.constructor.name}.
3
+ ${n.toString()}`)},Rr=class{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:Fe(t),h:n}),this}else(t){return this.if(Cn,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 q("Unhandled pattern")}}},el=e=>new Rr(e),po=el(Cn).if(uo,(e,t)=>mn(t,ir,Zt)).if(ho,(e,t)=>no(t)).if(Zc,(e,t)=>Ur(t)).if(Wc,(e,t)=>BigInt(mn(t,ir,Zt))).if(_n,(e,t)=>ue(t,wn(t,e.shape))).if($c,(e,t)=>{let n={};for(let r in e.shape){let s=e.shape[r];if(Bc.check(s)){if(Ur(t))continue;s=s.shape}n[r]=po(s,t)}return n}).if(Pc,(e,t)=>{let n=[],r=Dr(t,0,42);for(let s=0;s<r;s++)n.push(ue(t,e.shape));return n}).if(so,(e,t)=>wn(t,e.shape)).if(Qc,(e,t)=>null).if(zc,(e,t)=>{let n=ue(t,e.res);return()=>n}).if(Kc,(e,t)=>ue(t,wn(t,[he,pe,In,fo,Vr,Dn,co(he),io(ge("a","b","c"),he)]))).if(jc,(e,t)=>{let n={},r=mn(t,0,3);for(let s=0;s<r;s++){let o=ue(t,e.shape.keys),i=ue(t,e.shape.values);n[o]=i}return n}).done(),ue=(e,t)=>po(Fe(t),e);var Vt=typeof document!="undefined"?document:{};var Yu=D(e=>e.nodeType===il);var ju=typeof DOMParser!="undefined"?new DOMParser:null;var Hu=D(e=>e.nodeType===rl);var Pu=D(e=>e.nodeType===sl);var go=e=>Is(e,(t,n)=>`${n}:${t};`).join("");var rl=Vt.ELEMENT_NODE,sl=Vt.TEXT_NODE,Xu=Vt.CDATA_SECTION_NODE,Gu=Vt.COMMENT_NODE,ol=Vt.DOCUMENT_NODE,qu=Vt.DOCUMENT_TYPE_NODE,il=Vt.DOCUMENT_FRAGMENT_NODE,zu=D(e=>e.nodeType===ol);var ot=Symbol;var $e=ot(),Ye=ot(),Br=ot(),Fr=ot(),$r=ot(),je=ot(),Yr=ot(),me=ot(),jr=ot(),mo=e=>{var s;e.length===1&&((s=e[0])==null?void 0:s.constructor)===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r<e.length;r++){let o=e[r];if(o===void 0)break;if(o.constructor===String||o.constructor===Number)t.push(o);else if(o.constructor===Object)break}for(r>0&&n.push(t.join(""));r<e.length;r++){let o=e[r];o instanceof Symbol||n.push(o)}return n};var Ju=xt();var ul={[$e]:st("font-weight","bold"),[Ye]:st("font-weight","normal"),[Br]:st("color","blue"),[$r]:st("color","green"),[Fr]:st("color","grey"),[je]:st("color","red"),[Yr]:st("color","purple"),[me]:st("color","orange"),[jr]:st("color","black")},dl=e=>{var i;e.length===1&&((i=e[0])==null?void 0:i.constructor)===Function&&(e=e[0]());let t=[],n=[],r=A(),s=[],o=0;for(;o<e.length;o++){let c=e[o],l=ul[c];if(l!==void 0)r.set(l.left,l.right);else{if(c===void 0)break;if(c.constructor===String||c.constructor===Number){let a=go(r);o>0||a.length>0?(t.push("%c"+c),n.push(a)):t.push(c)}else break}}for(o>0&&(s=n,s.unshift(t.join("")));o<e.length;o++){let c=e[o];c instanceof Symbol||s.push(c)}return s},wo=to?dl:mo,Nn=(...e)=>{console.log(...wo(e)),yo.forEach(t=>t.print(e))},Hr=(...e)=>{console.warn(...wo(e)),e.unshift(me),yo.forEach(t=>t.print(e))};var yo=nt();var xo=e=>({[Symbol.iterator](){return this},next:e}),bo=(e,t)=>xo(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),vn=(e,t)=>xo(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}});var Xr=class extends Kt{constructor(t,n){super(),this.doc=t,this.awareness=n}},we=class{constructor(t,n){this.clock=t,this.len=n}},Et=class{constructor(){this.clients=new Map}},$t=(e,t,n)=>t.clients.forEach((r,s)=>{let o=e.doc.store.clients.get(s);if(o!=null){let i=o[o.length-1],c=i.id.clock+i.length;for(let l=0,a=r[l];l<r.length&&a.clock<c;a=r[++l])Go(e,o,a.clock,a.len,n)}}),ml=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let s=L((n+r)/2),o=e[s],i=o.clock;if(i<=t){if(t<i+o.len)return s;n=s+1}else r=s-1}return null},zt=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&ml(n,t.clock)!==null},es=e=>{e.clients.forEach(t=>{t.sort((s,o)=>s.clock-o.clock);let n,r;for(n=1,r=1;n<t.length;n++){let s=t[r-1],o=t[n];s.clock+s.len>=o.clock?t[r-1]=new we(s.clock,dt(s.len,o.clock+o.len-s.clock)):(r<n&&(t[r]=o),r++)}t.length=r})},Yt=e=>{let t=new Et;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,s)=>{if(!t.clients.has(s)){let o=r.slice();for(let i=n+1;i<e.length;i++)vs(o,e[i].clients.get(s)||[]);t.clients.set(s,o)}});return es(t),t},Pe=(e,t,n,r)=>{B(e.clients,t,()=>[]).push(new we(n,r))},Jn=()=>new Et,ns=e=>{let t=Jn();return e.clients.forEach((n,r)=>{let s=[];for(let o=0;o<n.length;o++){let i=n[o];if(i.deleted){let c=i.id.clock,l=i.length;if(o+1<n.length)for(let a=n[o+1];o+1<n.length&&a.deleted;a=n[++o+1])l+=a.length;s.push(new we(c,l))}}s.length>0&&t.clients.set(r,s)}),t},it=(e,t)=>{m(e.restEncoder,t.clients.size),tt(t.clients.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{e.resetDsCurVal(),m(e.restEncoder,n);let s=r.length;m(e.restEncoder,s);for(let o=0;o<s;o++){let i=r[o];e.writeDsClock(i.clock),e.writeDsLen(i.len)}})},ft=e=>{let t=new Et,n=b(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();let s=b(e.restDecoder),o=b(e.restDecoder);if(o>0){let i=B(t.clients,s,()=>[]);for(let c=0;c<o;c++)i.push(new we(e.readDsClock(),e.readDsLen()))}}return t},Eo=(e,t,n)=>{let r=new Et,s=b(e.restDecoder);for(let o=0;o<s;o++){e.resetDsCurVal();let i=b(e.restDecoder),c=b(e.restDecoder),l=n.clients.get(i)||[],a=E(n,i);for(let u=0;u<c;u++){let d=e.readDsClock(),h=d+e.readDsLen();if(d<a){a<h&&Pe(r,i,a,h-a);let f=Z(l,d),p=l[f];for(!p.deleted&&p.id.clock<d&&(l.splice(f+1,0,zn(t,p,d-p.id.clock)),f++);f<l.length&&(p=l[f++],p.id.clock<h);)p.deleted||(h<p.id.clock+p.length&&l.splice(f,0,zn(t,p,h-p.id.clock)),p.delete(t))}else Pe(r,i,d,h-d)}}if(r.clients.size>0){let o=new J;return m(o.restEncoder,0),it(o,r),o.toUint8Array()}return null},Bo=(e,t)=>{if(e.clients.size!==t.clients.size)return!1;for(let[n,r]of e.clients.entries()){let s=t.clients.get(n);if(s===void 0||r.length!==s.length)return!1;for(let o=0;o<r.length;o++){let i=r[o],c=s[o];if(i.clock!==c.clock||i.len!==c.len)return!1}}return!0},Fo=gr,At=class e extends Kt{constructor({guid:t=Ps(),collectionid:n=null,gc:r=!0,gcFilter:s=()=>!0,meta:o=null,autoLoad:i=!1,shouldLoad:c=!0}={}){super(),this.gc=r,this.gcFilter=s,this.clientID=Fo(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new $n,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=i,this.meta=o,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=wr(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let l=()=>wr(a=>{let u=d=>{(d===void 0||d===!0)&&(this.off("sync",u),a())};this.on("sync",u)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=a===void 0||a===!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(tt(this.subdocs).map(t=>t.guid))}transact(t,n=null){return k(this,t,n)}get(t,n=_){let r=B(this.share,t,()=>{let o=new n;return o._integrate(this,null),o}),s=r.constructor;if(n!==_&&s!==n)if(s===_){let o=new n;o._map=r._map,r._map.forEach(i=>{for(;i!==null;i=i.left)i.parent=o}),o._start=r._start;for(let i=o._start;i!==null;i=i.right)i.parent=o;return o._length=r._length,this.share.set(t,o),o._integrate(this,null),o}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return r}getArray(t=""){return this.get(t,Pt)}getText(t=""){return this.get(t,be)}getMap(t=""){return this.get(t,Xt)}getXmlElement(t=""){return this.get(t,O)}getXmlFragment(t=""){return this.get(t,pt)}toJSON(){let t={};return this.share.forEach((n,r)=>{t[r]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,tt(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()}},jt=class{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return b(this.restDecoder)}readDsLen(){return b(this.restDecoder)}},X=class extends jt{readLeftID(){return x(b(this.restDecoder),b(this.restDecoder))}readRightID(){return x(b(this.restDecoder),b(this.restDecoder))}readClient(){return b(this.restDecoder)}readInfo(){return Ot(this.restDecoder)}readString(){return yt(this.restDecoder)}readParentInfo(){return b(this.restDecoder)===1}readTypeRef(){return b(this.restDecoder)}readLen(){return b(this.restDecoder)}readAny(){return ce(this.restDecoder)}readBuf(){return eo(P(this.restDecoder))}readJSON(){return JSON.parse(yt(this.restDecoder))}readKey(){return yt(this.restDecoder)}},Bn=class{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=b(this.restDecoder),this.dsCurrVal}readDsLen(){let t=b(this.restDecoder)+1;return this.dsCurrVal+=t,t}},j=class extends Bn{constructor(t){super(t),this.keys=[],b(t),this.keyClockDecoder=new le(P(t)),this.clientDecoder=new Lt(P(t)),this.leftClockDecoder=new le(P(t)),this.rightClockDecoder=new le(P(t)),this.infoDecoder=new Ie(P(t),Ot),this.stringDecoder=new fn(P(t)),this.parentInfoDecoder=new Ie(P(t),Ot),this.typeRefDecoder=new Lt(P(t)),this.lenDecoder=new Lt(P(t))}readLeftID(){return new ht(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new ht(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 ce(this.restDecoder)}readBuf(){return P(this.restDecoder)}readJSON(){return ce(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}}},_t=class{constructor(){this.restEncoder=vt()}toUint8Array(){return G(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){m(this.restEncoder,t)}writeDsLen(t){m(this.restEncoder,t)}},ct=class extends _t{writeLeftID(t){m(this.restEncoder,t.client),m(this.restEncoder,t.clock)}writeRightID(t){m(this.restEncoder,t.client),m(this.restEncoder,t.clock)}writeClient(t){m(this.restEncoder,t)}writeInfo(t){se(this.restEncoder,t)}writeString(t){mt(this.restEncoder,t)}writeParentInfo(t){m(this.restEncoder,t?1:0)}writeTypeRef(t){m(this.restEncoder,t)}writeLen(t){m(this.restEncoder,t)}writeAny(t){ne(this.restEncoder,t)}writeBuf(t){H(this.restEncoder,t)}writeJSON(t){mt(this.restEncoder,JSON.stringify(t))}writeKey(t){mt(this.restEncoder,t)}},ye=class{constructor(){this.restEncoder=vt(),this.dsCurrVal=0}toUint8Array(){return G(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){let n=t-this.dsCurrVal;this.dsCurrVal=t,m(this.restEncoder,n)}writeDsLen(t){t===0&&N(),m(this.restEncoder,t-1),this.dsCurrVal+=t}},J=class extends ye{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new re,this.clientEncoder=new Nt,this.leftClockEncoder=new re,this.rightClockEncoder=new re,this.infoEncoder=new Ue(se),this.stringEncoder=new hn,this.parentInfoEncoder=new Ue(se),this.typeRefEncoder=new Nt,this.lenEncoder=new Nt}toUint8Array(){let t=vt();return m(t,0),H(t,this.keyClockEncoder.toUint8Array()),H(t,this.clientEncoder.toUint8Array()),H(t,this.leftClockEncoder.toUint8Array()),H(t,this.rightClockEncoder.toUint8Array()),H(t,G(this.infoEncoder)),H(t,this.stringEncoder.toUint8Array()),H(t,G(this.parentInfoEncoder)),H(t,this.typeRefEncoder.toUint8Array()),H(t,this.lenEncoder.toUint8Array()),oe(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){ne(this.restEncoder,t)}writeBuf(t){H(this.restEncoder,t)}writeJSON(t){ne(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)}},wl=(e,t,n,r)=>{r=dt(r,t[0].id.clock);let s=Z(t,r);m(e.restEncoder,t.length-s),e.writeClient(n),m(e.restEncoder,r);let o=t[s];o.write(e,r-o.id.clock);for(let i=s+1;i<t.length;i++)t[i].write(e,0)},rs=(e,t,n)=>{let r=new Map;n.forEach((s,o)=>{E(t,o)>s&&r.set(o,s)}),en(t).forEach((s,o)=>{n.has(o)||r.set(o,0)}),m(e.restEncoder,r.size),tt(r.entries()).sort((s,o)=>o[0]-s[0]).forEach(([s,o])=>{wl(e,t.clients.get(s),s,o)})},yl=(e,t)=>{let n=A(),r=b(e.restDecoder);for(let s=0;s<r;s++){let o=b(e.restDecoder),i=new Array(o),c=e.readClient(),l=b(e.restDecoder);n.set(c,{i:0,refs:i});for(let a=0;a<o;a++){let u=e.readInfo();switch(31&u){case 0:{let d=e.readLen();i[a]=new $(x(c,l),d),l+=d;break}case 10:{let d=b(e.restDecoder);i[a]=new R(x(c,l),d),l+=d;break}default:{let d=(u&192)===0,h=new S(x(c,l),null,(u&128)===128?e.readLeftID():null,null,(u&64)===64?e.readRightID():null,d?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,d&&(u&32)===32?e.readString():null,Ei(e,u));i[a]=h,l+=h.length}}}}return n},xl=(e,t,n)=>{let r=[],s=tt(n.keys()).sort((f,p)=>f-p);if(s.length===0)return null;let o=()=>{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},i=o();if(i===null)return null;let c=new $n,l=new Map,a=(f,p)=>{let y=l.get(f);(y==null||y>p)&&l.set(f,p)},u=i.refs[i.i++],d=new Map,h=()=>{for(let f of r){let p=f.id.client,y=n.get(p);y?(y.i--,c.clients.set(p,y.refs.slice(y.i)),n.delete(p),y.i=0,y.refs=[]):c.clients.set(p,[f]),s=s.filter(g=>g!==p)}r.length=0};for(;;){if(u.constructor!==R){let p=B(d,u.id.client,()=>E(t,u.id.client))-u.id.clock;if(p<0)r.push(u),a(u.id.client,u.id.clock-1),h();else{let y=u.getMissing(e,t);if(y!==null){r.push(u);let g=n.get(y)||{refs:[],i:0};if(g.refs.length===g.i)a(y,E(t,y)),h();else{u=g.refs[g.i++];continue}}else(p===0||p<u.length)&&(u.integrate(e,p),d.set(u.id.client,u.id.clock+u.length))}}if(r.length>0)u=r.pop();else if(i!==null&&i.i<i.refs.length)u=i.refs[i.i++];else{if(i=o(),i===null)break;u=i.refs[i.i++]}}if(c.clients.size>0){let f=new J;return rs(f,c,new Map),m(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},bl=(e,t)=>rs(e,t.doc.store,t.beforeState),ss=(e,t,n,r=new j(e))=>k(t,s=>{s.local=!1;let o=!1,i=s.doc,c=i.store,l=yl(r,i),a=xl(s,c,l),u=c.pendingStructs;if(u){for(let[h,f]of u.missing)if(f<E(c,h)){o=!0;break}if(a){for(let[h,f]of a.missing){let p=u.missing.get(h);(p==null||p>f)&&u.missing.set(h,f)}u.update=Je([u.update,a.update])}}else c.pendingStructs=a;let d=Eo(r,s,c);if(c.pendingDs){let h=new j(M(c.pendingDs));b(h.restDecoder);let f=Eo(h,s,c);d&&f?c.pendingDs=Je([d,f]):c.pendingDs=d||f}else c.pendingDs=d;if(o){let h=c.pendingStructs.update;c.pendingStructs=null,Kn(s.doc,h)}},n,!1),kl=(e,t,n)=>ss(e,t,n,new X(e)),Kn=(e,t,n,r=j)=>{let s=M(t);ss(s,e,n,new r(s))},Sl=(e,t,n)=>Kn(e,t,n,X),El=(e,t,n=new Map)=>{rs(e,t.store,n),it(e,ns(t.store))},$o=(e,t=new Uint8Array([0]),n=new J)=>{let r=os(t);El(n,e,r);let s=[n.toUint8Array()];if(e.store.pendingDs&&s.push(e.store.pendingDs),e.store.pendingStructs&&s.push(fs(e.store.pendingStructs.update,t)),s.length>1){if(n.constructor===ct)return Zo(s.map((o,i)=>i===0?o:ri(o)));if(n.constructor===J)return Je(s)}return s[0]},Al=(e,t)=>$o(e,t,new ct),Yo=e=>{let t=new Map,n=b(e.restDecoder);for(let r=0;r<n;r++){let s=b(e.restDecoder),o=b(e.restDecoder);t.set(s,o)}return t},os=e=>Yo(new jt(M(e))),is=(e,t)=>(m(e.restEncoder,t.size),tt(t.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{m(e.restEncoder,n),m(e.restEncoder,r)}),e),_l=(e,t)=>is(e,en(t.store)),Cl=(e,t=new ye)=>(e instanceof Map?is(t,e):_l(t,e),t.toUint8Array()),Tl=e=>Cl(e,new _t),Gr=class{constructor(){this.l=[]}},Ao=()=>new Gr,_o=(e,t)=>e.l.push(t),Co=(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.")},jo=(e,t,n)=>Le(e.l,[t,n]),ht=class{constructor(t,n){this.client=t,this.clock=n}},Bt=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,x=(e,t)=>new ht(e,t),To=(e,t)=>{m(e,t.client),m(e,t.clock)},Uo=e=>x(b(e),b(e)),cs=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw N()},Xe=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},Ul=e=>{let t=[],n=e._start;for(;n;)t.push(n),n=n.right;console.log("Children: ",t),console.log("Children content: ",t.filter(r=>!r.deleted).map(r=>r.content))},qr=class{constructor(t,n=t.getMap("users")){let r=new Map;this.yusers=n,this.doc=t,this.clients=new Map,this.dss=r;let s=(o,i)=>{let c=o.get("ds"),l=o.get("ids"),a=u=>this.clients.set(u,i);c.observe(u=>{u.changes.added.forEach(d=>{d.content.getContent().forEach(h=>{h instanceof Uint8Array&&this.dss.set(i,Yt([this.dss.get(i)||Jn(),ft(new jt(M(h)))]))})})}),this.dss.set(i,Yt(c.map(u=>ft(new jt(M(u)))))),l.observe(u=>u.changes.added.forEach(d=>d.content.getContent().forEach(a))),l.forEach(a)};n.observe(o=>{o.keysChanged.forEach(i=>s(n.get(i),i))}),n.forEach(s)}setUserMapping(t,n,r,{filter:s=()=>!0}={}){let o=this.yusers,i=o.get(r);i||(i=new Xt,i.set("ids",new Pt),i.set("ds",new Pt),o.set(r,i)),i.get("ids").push([n]),o.observe(c=>{setTimeout(()=>{let l=o.get(r);if(l!==i){i=l,this.clients.forEach((d,h)=>{r===d&&i.get("ids").push([h])});let a=new _t,u=this.dss.get(r);u&&(it(a,u),i.get("ds").push([a.toUint8Array()]))}},0)}),t.on("afterTransaction",c=>{setTimeout(()=>{let l=i.get("ds"),a=c.deleteSet;if(c.local&&a.clients.size>0&&s(c,a)){let u=new _t;it(u,a),l.push([u.toUint8Array()])}})})}getUserByClientId(t){return this.clients.get(t)||null}getUserByDeletedId(t){for(let[n,r]of this.dss.entries())if(zt(r,t))return n;return null}},xe=class{constructor(t,n,r,s=0){this.type=t,this.tname=n,this.item=r,this.assoc=s}},Dl=e=>{let t={};return e.type&&(t.type=e.type),e.tname&&(t.tname=e.tname),e.item&&(t.item=e.item),e.assoc!=null&&(t.assoc=e.assoc),t},Il=e=>{var t;return new xe(e.type==null?null:x(e.type.client,e.type.clock),(t=e.tname)!=null?t:null,e.item==null?null:x(e.item.client,e.item.clock),e.assoc==null?0:e.assoc)},Fn=class{constructor(t,n,r=0){this.type=t,this.index=n,this.assoc=r}},Nl=(e,t,n=0)=>new Fn(e,t,n),On=(e,t,n)=>{let r=null,s=null;return e._item===null?s=cs(e):r=x(e._item.id.client,e._item.id.clock),new xe(r,s,t,n)},ls=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return On(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return On(e,x(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return On(e,r.lastId,n);r=r.right}return On(e,null,n)},vl=(e,t)=>{let{type:n,tname:r,item:s,assoc:o}=t;if(s!==null)m(e,0),To(e,s);else if(r!==null)se(e,1),mt(e,r);else if(n!==null)se(e,2),To(e,n);else throw N();return De(e,o),e},as=e=>{let t=vt();return vl(t,e),G(t)},Ol=e=>{let t=null,n=null,r=null;switch(b(e)){case 0:r=Uo(e);break;case 1:n=yt(e);break;case 2:t=Uo(e)}let s=fr(e)?Ne(e):0;return new xe(t,n,r,s)},us=e=>Ol(M(e)),Ll=(e,t)=>{let n=Ft(e,t),r=t.clock-n.id.clock;return{item:n,diff:r}},ds=(e,t,n=!0)=>{let r=t.store,s=e.item,o=e.type,i=e.tname,c=e.assoc,l=null,a=0;if(s!==null){if(E(r,s.client)<=s.clock)return null;let u=n?Qr(r,s):Ll(r,s),d=u.item;if(!(d instanceof S))return null;if(l=d.parent,l._item===null||!l._item.deleted){a=d.deleted||!d.countable?0:u.diff+(c>=0?0:1);let h=d.left;for(;h!==null;)!h.deleted&&h.countable&&(a+=h.length),h=h.left}}else{if(i!==null)l=t.get(i);else if(o!==null){if(E(r,o.client)<=o.clock)return null;let{item:u}=n?Qr(r,o):{item:Ft(r,o)};if(u instanceof S&&u.content instanceof Q)l=u.content.type;else return null}else throw N();c>=0?a=l._length:a=0}return Nl(l,a,e.assoc)},Ml=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&Bt(e.item,t.item)&&Bt(e.type,t.type)&&e.assoc===t.assoc,Ge=class{constructor(t,n){this.ds=t,this.sv=n}},Rl=(e,t)=>{let n=e.ds.clients,r=t.ds.clients,s=e.sv,o=t.sv;if(s.size!==o.size||n.size!==r.size)return!1;for(let[i,c]of s.entries())if(o.get(i)!==c)return!1;for(let[i,c]of n.entries()){let l=r.get(i)||[];if(c.length!==l.length)return!1;for(let a=0;a<c.length;a++){let u=c[a],d=l[a];if(u.clock!==d.clock||u.len!==d.len)return!1}}return!0},Ho=(e,t=new ye)=>(it(t,e.ds),is(t,e.sv),t.toUint8Array()),Vl=e=>Ho(e,new _t),Po=(e,t=new Bn(M(e)))=>new Ge(ft(t),Yo(t)),Bl=e=>Po(e,new jt(M(e))),hs=(e,t)=>new Ge(e,t),Fl=hs(Jn(),new Map),$l=e=>hs(ns(e.store),en(e.store)),bt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!zt(t.ds,e.id),zr=(e,t)=>{let n=B(e.meta,zr,nt),r=e.doc.store;n.has(t)||(t.sv.forEach((s,o)=>{s<E(r,o)&&F(e,x(o,s))}),$t(e,t.ds,s=>{}),n.add(t))},Yl=(e,t,n=new At)=>{if(e.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:s}=t,o=new J;return e.transact(i=>{let c=0;r.forEach(l=>{l>0&&c++}),m(o.restEncoder,c);for(let[l,a]of r){if(a===0)continue;a<E(e.store,l)&&F(i,x(l,a));let u=e.store.clients.get(l)||[],d=Z(u,a-1);m(o.restEncoder,d+1),o.writeClient(l),m(o.restEncoder,0);for(let h=0;h<=d;h++)u[h].write(o,0)}it(o,s)}),Kn(n,o.toUint8Array(),"snapshot"),n},jl=(e,t,n=j)=>{let r=new n(M(t)),s=new lt(r,!1);for(let i=s.curr;i!==null;i=s.next())if((e.sv.get(i.id.client)||0)<i.id.clock+i.length)return!1;let o=Yt([e.ds,ft(r)]);return Bo(e.ds,o)},Hl=(e,t)=>jl(e,t,X),$n=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},en=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},E=(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},Xo=(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 N()}n.push(t)},Z=(e,t)=>{let n=0,r=e.length-1,s=e[r],o=s.id.clock;if(o===t)return r;let i=L(t/(o+s.length-1)*r);for(;n<=r;){if(s=e[i],o=s.id.clock,o<=t){if(t<o+s.length)return i;n=i+1}else r=i-1;i=L((n+r)/2)}throw N()},Pl=(e,t)=>{let n=e.clients.get(t.client);return n[Z(n,t.clock)]},Ft=Pl,Jr=(e,t,n)=>{let r=Z(t,n),s=t[r];return s.id.clock<n&&s instanceof S?(t.splice(r+1,0,zn(e,s,n-s.id.clock)),r+1):r},F=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[Jr(e,n,t.clock)]},Kr=(e,t,n)=>{let r=t.clients.get(n.client),s=Z(r,n.clock),o=r[s];return n.clock!==o.id.clock+o.length-1&&o.constructor!==$&&r.splice(s+1,0,zn(e,o,n.clock-o.id.clock+1)),o},Xl=(e,t,n)=>{let r=e.clients.get(t.id.client);r[Z(r,t.id.clock)]=n},Go=(e,t,n,r,s)=>{if(r===0)return;let o=n+r,i=Jr(e,t,n),c;do c=t[i++],o<c.id.clock+c.length&&Jr(e,t,o),s(c);while(i<t.length&&t[i].id.clock<o)},Yn=class{constructor(t,n,r){this.doc=t,this.deleteSet=new Et,this.beforeState=en(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=r,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}},Do=(e,t)=>t.deleteSet.clients.size===0&&!Ns(t.afterState,(n,r)=>t.beforeState.get(r)!==n)?!1:(es(t.deleteSet),bl(e,t),it(e,t.deleteSet),!0),Io=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&B(e.changed,t,nt).add(n)},Rn=(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 S&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}let o=t-s;return o&&e.splice(t+1-o,o),o},qo=(e,t,n)=>{for(let[r,s]of e.clients.entries()){let o=t.clients.get(r);for(let i=s.length-1;i>=0;i--){let c=s[i],l=c.clock+c.len;for(let a=Z(o,c.clock),u=o[a];a<o.length&&u.id.clock<l;u=o[++a]){let d=o[a];if(c.clock+c.len<=d.id.clock)break;d instanceof S&&d.deleted&&!d.keep&&n(d)&&d.gc(t,!1)}}}},zo=(e,t)=>{e.clients.forEach((n,r)=>{let s=t.clients.get(r);for(let o=n.length-1;o>=0;o--){let i=n[o],c=an(s.length-1,1+Z(s,i.clock+i.len-1));for(let l=c,a=s[l];l>0&&a.id.clock>=i.clock;a=s[l])l-=1+Rn(s,l)}})},Gl=(e,t,n)=>{qo(e,t,n),zo(e,t)},Jo=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,s=r.store,o=n.deleteSet,i=n._mergeStructs;try{es(o),n.afterState=en(n.doc.store),r.emit("beforeObserverCalls",[n,r]);let c=[];n.changed.forEach((l,a)=>c.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(n,l)})),c.push(()=>{n.changedParentTypes.forEach((l,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(l=l.filter(u=>u.target._item===null||!u.target._item.deleted),l.forEach(u=>{u.currentTarget=a,u._path=null}),l.sort((u,d)=>u.path.length-d.path.length),c.push(()=>{jo(a._dEH,l,n)}))}),c.push(()=>r.emit("afterTransaction",[n,r])),c.push(()=>{n._needFormattingCleanup&&pa(n)})}),Le(c,[])}finally{r.gc&&qo(o,s,r.gcFilter),zo(o,s),n.afterState.forEach((u,d)=>{let h=n.beforeState.get(d)||0;if(h!==u){let f=s.clients.get(d),p=dt(Z(f,h),1);for(let y=f.length-1;y>=p;)y-=1+Rn(f,y)}});for(let u=i.length-1;u>=0;u--){let{client:d,clock:h}=i[u].id,f=s.clients.get(d),p=Z(f,h);p+1<f.length&&Rn(f,p+1)>1||p>0&&Rn(f,p)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(Nn(me,$e,"[yjs] ",Ye,je,"Changed the client-id because another client seems to be using it."),r.clientID=Fo()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){let u=new ct;Do(u,n)&&r.emit("update",[u.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){let u=new J;Do(u,n)&&r.emit("updateV2",[u.toUint8Array(),n.origin,r,n])}let{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:a}=n;(c.size>0||a.size>0||l.size>0)&&(c.forEach(u=>{u.clientID=r.clientID,u.collectionid==null&&(u.collectionid=r.collectionid),r.subdocs.add(u)}),a.forEach(u=>r.subdocs.delete(u)),r.emit("subdocs",[{loaded:l,added:c,removed:a},r,n]),a.forEach(u=>u.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,e])):Jo(e,t+1)}}},k=(e,t,n=null,r=!0)=>{let s=e._transactionCleanups,o=!1,i=null;e._transaction===null&&(o=!0,e._transaction=new Yn(e,n,r),s.push(e._transaction),s.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{i=t(e._transaction)}finally{if(o){let c=e._transaction===s[0];e._transaction=null,c&&Jo(s,0)}}return i},Wr=class{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}},No=(e,t,n)=>{$t(e,n.deletions,r=>{r instanceof S&&t.scope.some(s=>s===e.doc||Xe(s,r))&&ys(r,!1)})},vo=(e,t,n)=>{let r=null,s=e.doc,o=e.scope;k(s,c=>{for(;t.length>0&&e.currStackItem===null;){let l=s.store,a=t.pop(),u=new Set,d=[],h=!1;$t(c,a.insertions,f=>{if(f instanceof S){if(f.redone!==null){let{item:p,diff:y}=Qr(l,f.id);y>0&&(p=F(c,x(p.id.client,p.id.clock+y))),f=p}!f.deleted&&o.some(p=>p===c.doc||Xe(p,f))&&d.push(f)}}),$t(c,a.deletions,f=>{f instanceof S&&o.some(p=>p===c.doc||Xe(p,f))&&!zt(a.insertions,f.id)&&u.add(f)}),u.forEach(f=>{h=Si(c,f,u,a.insertions,e.ignoreRemoteMapChanges,e)!==null||h});for(let f=d.length-1;f>=0;f--){let p=d[f];e.deleteFilter(p)&&(p.delete(c),h=!0)}e.currStackItem=h?a:null}c.changed.forEach((l,a)=>{l.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),r=c},e);let i=e.currStackItem;if(i!=null){let c=r.changedParentTypes;e.emit("stack-item-popped",[{stackItem:i,type:n,changedParentTypes:c,origin:e},e]),e.currStackItem=null}return i},qe=class extends Kt{constructor(t,{captureTimeout:n=500,captureTransaction:r=l=>!0,deleteFilter:s=()=>!0,trackedOrigins:o=new Set([null]),ignoreRemoteMapChanges:i=!1,doc:c=ut(t)?t[0].doc:t instanceof At?t:t.doc}={}){super(),this.scope=[],this.doc=c,this.addToScope(t),this.deleteFilter=s,o.add(this),this.trackedOrigins=o,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=i,this.captureTimeout=n,this.afterTransactionHandler=l=>{if(!this.captureTransaction(l)||!this.scope.some(g=>l.changedParentTypes.has(g)||g===this.doc)||!this.trackedOrigins.has(l.origin)&&(!l.origin||!this.trackedOrigins.has(l.origin.constructor)))return;let a=this.undoing,u=this.redoing,d=a?this.redoStack:this.undoStack;a?this.stopCapturing():u||this.clear(!1,!0);let h=new Et;l.afterState.forEach((g,w)=>{let U=l.beforeState.get(w)||0,Ut=g-U;Ut>0&&Pe(h,w,U,Ut)});let f=xt(),p=!1;if(this.lastChange>0&&f-this.lastChange<this.captureTimeout&&d.length>0&&!a&&!u){let g=d[d.length-1];g.deletions=Yt([g.deletions,l.deleteSet]),g.insertions=Yt([g.insertions,h])}else d.push(new Wr(l.deleteSet,h)),p=!0;!a&&!u&&(this.lastChange=f),$t(l,l.deleteSet,g=>{g instanceof S&&this.scope.some(w=>w===l.doc||Xe(w,g))&&ys(g,!0)});let y=[{stackItem:d[d.length-1],origin:l.origin,type:a?"redo":"undo",changedParentTypes:l.changedParentTypes},this];p?this.emit("stack-item-added",y):this.emit("stack-item-updated",y)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){let n=new Set(this.scope);t=ut(t)?t:[t],t.forEach(r=>{n.has(r)||(n.add(r),(r instanceof _?r.doc!==this.doc:r!==this.doc)&&Hr("[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=>No(r,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>No(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=vo(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=vo(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*ql(e){let t=b(e.restDecoder);for(let n=0;n<t;n++){let r=b(e.restDecoder),s=e.readClient(),o=b(e.restDecoder);for(let i=0;i<r;i++){let c=e.readInfo();if(c===10){let l=b(e.restDecoder);yield new R(x(s,o),l),o+=l}else if((31&c)!==0){let l=(c&192)===0,a=new S(x(s,o),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,Ei(e,c));yield a,o+=a.length}else{let l=e.readLen();yield new $(x(s,o),l),o+=l}}}}var lt=class{constructor(t,n){this.gen=ql(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===R);return this.curr}},zl=e=>Ko(e,X),Ko=(e,t=j)=>{let n=[],r=new t(M(e)),s=new lt(r,!1);for(let i=s.curr;i!==null;i=s.next())n.push(i);Nn("Structs: ",n);let o=ft(r);Nn("DeleteSet: ",o)},Jl=e=>Wo(e,X),Wo=(e,t=j)=>{let n=[],r=new t(M(e)),s=new lt(r,!1);for(let o=s.curr;o!==null;o=s.next())n.push(o);return{structs:n,ds:ft(r)}},ze=class{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}},Zo=e=>Je(e,X,ct),Qo=(e,t=ye,n=j)=>{let r=new t,s=new lt(new n(M(e)),!1),o=s.curr;if(o!==null){let i=0,c=o.id.client,l=o.id.clock!==0,a=l?0:o.id.clock+o.length;for(;o!==null;o=s.next())c!==o.id.client&&(a!==0&&(i++,m(r.restEncoder,c),m(r.restEncoder,a)),c=o.id.client,a=0,l=o.id.clock!==0),o.constructor===R&&(l=!0),l||(a=o.id.clock+o.length);a!==0&&(i++,m(r.restEncoder,c),m(r.restEncoder,a));let u=vt();return m(u,i),$s(u,r.restEncoder),r.restEncoder=u,r.toUint8Array()}else return m(r.restEncoder,0),r.toUint8Array()},Kl=e=>Qo(e,_t,X),ti=(e,t=j)=>{let n=new Map,r=new Map,s=new lt(new t(M(e)),!1),o=s.curr;if(o!==null){let i=o.id.client,c=o.id.clock;for(n.set(i,c);o!==null;o=s.next())i!==o.id.client&&(r.set(i,c),n.set(o.id.client,o.id.clock),i=o.id.client),c=o.id.clock+o.length;r.set(i,c)}return{from:n,to:r}},Wl=e=>ti(e,X),Zl=(e,t)=>{if(e.constructor===$){let{client:n,clock:r}=e.id;return new $(x(n,r+t),e.length-t)}else if(e.constructor===R){let{client:n,clock:r}=e.id;return new R(x(n,r+t),e.length-t)}else{let n=e,{client:r,clock:s}=n.id;return new S(x(r,s+t),null,x(r,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Je=(e,t=j,n=J)=>{if(e.length===1)return e[0];let r=e.map(u=>new t(M(u))),s=r.map(u=>new lt(u,!0)),o=null,i=new n,c=new ze(i);for(;s=s.filter(h=>h.curr!==null),s.sort((h,f)=>{if(h.curr.id.client===f.curr.id.client){let p=h.curr.id.clock-f.curr.id.clock;return p===0?h.curr.constructor===f.curr.constructor?0:h.curr.constructor===R?1:-1:p}else return f.curr.id.client-h.curr.id.client}),s.length!==0;){let u=s[0],d=u.curr.id.client;if(o!==null){let h=u.curr,f=!1;for(;h!==null&&h.id.clock+h.length<=o.struct.id.clock+o.struct.length&&h.id.client>=o.struct.id.client;)h=u.next(),f=!0;if(h===null||h.id.client!==d||f&&h.id.clock>o.struct.id.clock+o.struct.length)continue;if(d!==o.struct.id.client)kt(c,o.struct,o.offset),o={struct:h,offset:0},u.next();else if(o.struct.id.clock+o.struct.length<h.id.clock)if(o.struct.constructor===R)o.struct.length=h.id.clock+h.length-o.struct.id.clock;else{kt(c,o.struct,o.offset);let p=h.id.clock-o.struct.id.clock-o.struct.length;o={struct:new R(x(d,o.struct.id.clock+o.struct.length),p),offset:0}}else{let p=o.struct.id.clock+o.struct.length-h.id.clock;p>0&&(o.struct.constructor===R?o.struct.length-=p:h=Zl(h,p)),o.struct.mergeWith(h)||(kt(c,o.struct,o.offset),o={struct:h,offset:0},u.next())}}else o={struct:u.curr,offset:0},u.next();for(let h=u.curr;h!==null&&h.id.client===d&&h.id.clock===o.struct.id.clock+o.struct.length&&h.constructor!==R;h=u.next())kt(c,o.struct,o.offset),o={struct:h,offset:0}}o!==null&&(kt(c,o.struct,o.offset),o=null),ps(c);let l=r.map(u=>ft(u)),a=Yt(l);return it(i,a),i.toUint8Array()},fs=(e,t,n=j,r=J)=>{let s=os(t),o=new r,i=new ze(o),c=new n(M(e)),l=new lt(c,!1);for(;l.curr;){let u=l.curr,d=u.id.client,h=s.get(d)||0;if(l.curr.constructor===R){l.next();continue}if(u.id.clock+u.length>h)for(kt(i,u,dt(h-u.id.clock,0)),l.next();l.curr&&l.curr.id.client===d;)kt(i,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===d&&l.curr.id.clock+l.curr.length<=h;)l.next()}ps(i);let a=ft(c);return it(o,a),o.toUint8Array()},Ql=(e,t)=>fs(e,t,X,ct),ei=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:G(e.encoder.restEncoder)}),e.encoder.restEncoder=vt(),e.written=0)},kt=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&ei(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),m(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},ps=e=>{ei(e);let t=e.encoder.restEncoder;m(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];m(t,r.written),oe(t,r.restEncoder)}},Wn=(e,t,n,r)=>{let s=new n(M(e)),o=new lt(s,!1),i=new r,c=new ze(i);for(let a=o.curr;a!==null;a=o.next())kt(c,t(a),0);ps(c);let l=ft(s);return it(i,l),i.toUint8Array()},ni=({formatting:e=!0,subdocs:t=!0,yxml:n=!0}={})=>{let r=0,s=A(),o=A(),i=A(),c=A();return c.set(null,null),l=>{switch(l.constructor){case $:case R:return l;case S:{let a=l,u=a.content;switch(u.constructor){case Se:break;case Q:{if(n){let d=u.type;d instanceof O&&(d.nodeName=B(o,d.nodeName,()=>"node-"+r)),d instanceof Qe&&(d.hookName=B(o,d.hookName,()=>"hook-"+r))}break}case Ct:{let d=u;d.arr=d.arr.map(()=>r);break}case Gt:{let d=u;d.content=new Uint8Array([r]);break}case qt:{let d=u;t&&(d.opts={},d.doc.guid=r+"");break}case gt:{let d=u;d.embed={};break}case C:{let d=u;e&&(d.key=B(i,d.key,()=>r+""),d.value=B(c,d.value,()=>({i:r})));break}case tn:{let d=u;d.arr=d.arr.map(()=>r);break}case et:{let d=u;d.str=dn(r%10+"",d.str.length);break}default:N()}return a.parentSub&&(a.parentSub=B(s,a.parentSub,()=>r+"")),r++,l}default:N()}}},ta=(e,t)=>Wn(e,ni(t),X,ct),ea=(e,t)=>Wn(e,ni(t),j,J),na=e=>Wn(e,Ar,X,J),ri=e=>Wn(e,Ar,j,ct),Oo="You must not compute changes after the event-handler fired.",Ht=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=ra(this.currentTarget,this.target))}deletes(t){return zt(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw q(Oo);let t=new Map,n=this.target;this.transaction.changed.get(n).forEach(s=>{if(s!==null){let o=n._map.get(s),i,c;if(this.adds(o)){let l=o.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(o))if(l!==null&&this.deletes(l))i="delete",c=on(l.content.getContent());else return;else l!==null&&this.deletes(l)?(i="update",c=on(l.content.getContent())):(i="add",c=void 0)}else if(this.deletes(o))i="delete",c=on(o.content.getContent());else return;t.set(s,{action:i,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 q(Oo);let n=this.target,r=nt(),s=nt(),o=[];if(t={added:r,deleted:s,delta:o,keys:this.keys},this.transaction.changed.get(n).has(null)){let c=null,l=()=>{c&&o.push(c)};for(let a=n._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((c===null||c.delete===void 0)&&(l(),c={delete:0}),c.delete+=a.length,s.add(a)):this.adds(a)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(a.content.getContent()),r.add(a)):((c===null||c.retain===void 0)&&(l(),c={retain:0}),c.retain+=a.length);c!==null&&c.retain===void 0&&l()}this._changes=t}return t}},ra=(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},V=()=>{Hr("Invalid access: Add Yjs type to a document before reading data.")},si=80,gs=0,Zr=class{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=gs++}},sa=e=>{e.timestamp=gs++},oi=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=gs++},oa=(e,t,n)=>{if(e.length>=si){let r=e.reduce((s,o)=>s.timestamp<o.timestamp?s:o);return oi(r,t,n),r}else{let r=new Zr(t,n);return e.push(r),r}},Zn=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((o,i)=>Dt(t-o.index)<Dt(t-i.index)?o:i),r=e._start,s=0;for(n!==null&&(r=n.p,s=n.index,sa(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&&Dt(n.index-s)<r.parent.length/si?(oi(n,r,s),n):oa(e._searchMarker,r,s)},Ke=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){let s=e[r];if(n>0){let o=s.p;for(o.marker=!1;o&&(o.deleted||!o.countable);)o=o.left,o&&!o.deleted&&o.countable&&(s.index-=o.length);if(o===null||o.marker===!0){e.splice(r,1);continue}s.p=o,o.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=dt(t,s.index+n))}},ia=e=>{var r;(r=e.doc)!=null||V();let t=e._start,n=[];for(;t;)n.push(t),t=t.right;return n},Qn=(e,t,n)=>{let r=e,s=t.changedParentTypes;for(;B(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;jo(r._eH,n,t)},_=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Ao(),this._dEH=Ao(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw z()}clone(){throw z()}_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){_o(this._eH,t)}observeDeep(t){_o(this._dEH,t)}unobserve(t){Co(this._eH,t)}unobserveDeep(t){Co(this._dEH,t)}toJSON(){}},ii=(e,t,n)=>{var i;(i=e.doc)!=null||V(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,s=[],o=e._start;for(;o!==null&&r>0;){if(o.countable&&!o.deleted){let c=o.content.getContent();if(c.length<=t)t-=c.length;else{for(let l=t;l<c.length&&r>0;l++)s.push(c[l]),r--;t=0}}o=o.right}return s},ci=e=>{var r;(r=e.doc)!=null||V();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let s=n.content.getContent();for(let o=0;o<s.length;o++)t.push(s[o])}n=n.right}return t},ca=(e,t)=>{let n=[],r=e._start;for(;r!==null;){if(r.countable&&bt(r,t)){let s=r.content.getContent();for(let o=0;o<s.length;o++)n.push(s[o])}r=r.right}return n},We=(e,t)=>{var s;let n=0,r=e._start;for((s=e.doc)!=null||V();r!==null;){if(r.countable&&!r.deleted){let o=r.content.getContent();for(let i=0;i<o.length;i++)t(o[i],n++,e)}r=r.right}},li=(e,t)=>{let n=[];return We(e,(r,s)=>{n.push(t(r,s,e))}),n},la=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}}}},ai=(e,t)=>{var s;(s=e.doc)!=null||V();let n=Zn(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}},jn=(e,t,n,r)=>{let s=n,o=e.doc,i=o.clientID,c=o.store,l=n===null?t._start:n.right,a=[],u=()=>{a.length>0&&(s=new S(x(i,E(c,i)),s,s&&s.lastId,l,l&&l.id,t,null,new Ct(a)),s.integrate(e,0),a=[])};r.forEach(d=>{if(d===null)a.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(d);break;default:switch(u(),d.constructor){case Uint8Array:case ArrayBuffer:s=new S(x(i,E(c,i)),s,s&&s.lastId,l,l&&l.id,t,null,new Gt(new Uint8Array(d))),s.integrate(e,0);break;case At:s=new S(x(i,E(c,i)),s,s&&s.lastId,l,l&&l.id,t,null,new qt(d)),s.integrate(e,0);break;default:if(d instanceof _)s=new S(x(i,E(c,i)),s,s&&s.lastId,l,l&&l.id,t,null,new Q(d)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),u()},ui=()=>q("Length exceeded!"),di=(e,t,n,r)=>{if(n>t._length)throw ui();if(n===0)return t._searchMarker&&Ke(t._searchMarker,n,r.length),jn(e,t,null,r);let s=n,o=Zn(t,n),i=t._start;for(o!==null&&(i=o.p,n-=o.index,n===0&&(i=i.prev,n+=i&&i.countable&&!i.deleted?i.length:0));i!==null;i=i.right)if(!i.deleted&&i.countable){if(n<=i.length){n<i.length&&F(e,x(i.id.client,i.id.clock+n));break}n-=i.length}return t._searchMarker&&Ke(t._searchMarker,s,r.length),jn(e,t,i,r)},aa=(e,t,n)=>{let s=(t._searchMarker||[]).reduce((o,i)=>i.index>o.index?i:o,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return jn(e,t,s,n)},hi=(e,t,n,r)=>{if(r===0)return;let s=n,o=r,i=Zn(t,n),c=t._start;for(i!==null&&(c=i.p,n-=i.index);c!==null&&n>0;c=c.right)!c.deleted&&c.countable&&(n<c.length&&F(e,x(c.id.client,c.id.clock+n)),n-=c.length);for(;r>0&&c!==null;)c.deleted||(r<c.length&&F(e,x(c.id.client,c.id.clock+r)),c.delete(e),r-=c.length),c=c.right;if(r>0)throw ui();t._searchMarker&&Ke(t._searchMarker,s,-o+r)},Hn=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},ms=(e,t,n,r)=>{let s=t._map.get(n)||null,o=e.doc,i=o.clientID,c;if(r==null)c=new Ct([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:c=new Ct([r]);break;case Uint8Array:c=new Gt(r);break;case At:c=new qt(r);break;default:if(r instanceof _)c=new Q(r);else throw new Error("Unexpected content type")}new S(x(i,E(o.store,i)),s,s&&s.lastId,null,null,t,n,c).integrate(e,0)},ws=(e,t)=>{var r;(r=e.doc)!=null||V();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},fi=e=>{var n;let t={};return(n=e.doc)!=null||V(),e._map.forEach((r,s)=>{r.deleted||(t[s]=r.content.getContent()[r.length-1])}),t},pi=(e,t)=>{var r;(r=e.doc)!=null||V();let n=e._map.get(t);return n!==void 0&&!n.deleted},ua=(e,t,n)=>{let r=e._map.get(t)||null;for(;r!==null&&(!n.sv.has(r.id.client)||r.id.clock>=(n.sv.get(r.id.client)||0));)r=r.left;return r!==null&&bt(r,n)?r.content.getContent()[r.length-1]:void 0},gi=(e,t)=>{let n={};return e._map.forEach((r,s)=>{let o=r;for(;o!==null&&(!t.sv.has(o.id.client)||o.id.clock>=(t.sv.get(o.id.client)||0));)o=o.left;o!==null&&bt(o,t)&&(n[s]=o.content.getContent()[o.length-1])}),n},Ln=e=>{var t;return(t=e.doc)!=null||V(),bo(e._map.entries(),n=>!n[1].deleted)},Pn=class extends Ht{},Pt=class e extends _{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 _?n.clone():n)),t}get length(){var t;return(t=this.doc)!=null||V(),this._length}_callObserver(t,n){super._callObserver(t,n),Qn(this,t,new Pn(this,t))}insert(t,n){this.doc!==null?k(this.doc,r=>{di(r,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?k(this.doc,n=>{aa(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?k(this.doc,r=>{hi(r,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return ai(this,t)}toArray(){return ci(this)}slice(t=0,n=this.length){return ii(this,t,n)}toJSON(){return this.map(t=>t instanceof _?t.toJSON():t)}map(t){return li(this,t)}forEach(t){We(this,t)}[Symbol.iterator](){return la(this)}_write(t){t.writeTypeRef(Na)}},da=e=>new Pt,Xn=class extends Ht{constructor(t,n,r){super(t,n),this.keysChanged=r}},Xt=class e extends _{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 _?n.clone():n)}),t}_callObserver(t,n){Qn(this,t,new Xn(this,t,n))}toJSON(){var n;(n=this.doc)!=null||V();let t={};return this._map.forEach((r,s)=>{if(!r.deleted){let o=r.content.getContent()[r.length-1];t[s]=o instanceof _?o.toJSON():o}}),t}get size(){return[...Ln(this)].length}keys(){return vn(Ln(this),t=>t[0])}values(){return vn(Ln(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return vn(Ln(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){var n;(n=this.doc)!=null||V(),this._map.forEach((r,s)=>{r.deleted||t(r.content.getContent()[r.length-1],s,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?k(this.doc,n=>{Hn(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?k(this.doc,r=>{ms(r,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return ws(this,t)}has(t){return pi(this,t)}clear(){this.doc!==null?k(this.doc,t=>{this.forEach(function(n,r,s){Hn(t,s,r)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(va)}},ha=e=>new Xt,St=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&kr(e,t),Ze=class{constructor(t,n,r,s){this.left=t,this.right=n,this.index=r,this.currentAttributes=s}forward(){this.right===null&&N(),this.right.content.constructor===C?this.right.deleted||Ee(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}},Lo=(e,t,n)=>{for(;t.right!==null&&n>0;)t.right.content.constructor===C?t.right.deleted||Ee(t.currentAttributes,t.right.content):t.right.deleted||(n<t.right.length&&F(e,x(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length),t.left=t.right,t.right=t.right.right;return t},Mn=(e,t,n,r)=>{let s=new Map,o=r?Zn(t,n):null;if(o){let i=new Ze(o.p.left,o.p,o.index,s);return Lo(e,i,n-o.index)}else{let i=new Ze(null,t._start,0,s);return Lo(e,i,n)}},mi=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===C&&St(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,o=s.clientID;r.forEach((i,c)=>{let l=n.left,a=n.right,u=new S(x(o,E(s.store,o)),l,l&&l.lastId,a,a&&a.id,t,null,new C(c,i));u.integrate(e,0),n.right=u,n.forward()})},Ee=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},wi=(e,t)=>{var n;for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===C&&St((n=t[e.right.content.key])!=null?n:null,e.right.content.value)))break;e.forward()}},yi=(e,t,n,r)=>{var c;let s=e.doc,o=s.clientID,i=new Map;for(let l in r){let a=r[l],u=(c=n.currentAttributes.get(l))!=null?c:null;if(!St(u,a)){i.set(l,u);let{left:d,right:h}=n;n.right=new S(x(o,E(s.store,o)),d,d&&d.lastId,h,h&&h.id,t,null,new C(l,a)),n.right.integrate(e,0),n.forward()}}return i},Pr=(e,t,n,r,s)=>{n.currentAttributes.forEach((h,f)=>{s[f]===void 0&&(s[f]=null)});let o=e.doc,i=o.clientID;wi(n,s);let c=yi(e,t,n,s),l=r.constructor===String?new et(r):r instanceof _?new Q(r):new gt(r),{left:a,right:u,index:d}=n;t._searchMarker&&Ke(t._searchMarker,n.index,l.getLength()),u=new S(x(i,E(o.store,i)),a,a&&a.lastId,u,u&&u.id,t,null,l),u.integrate(e,0),n.right=u,n.index=d,n.forward(),mi(e,t,n,c)},Mo=(e,t,n,r,s)=>{let o=e.doc,i=o.clientID;wi(n,s);let c=yi(e,t,n,s);t:for(;n.right!==null&&(r>0||c.size>0&&(n.right.deleted||n.right.content.constructor===C));){if(!n.right.deleted)switch(n.right.content.constructor){case C:{let{key:l,value:a}=n.right.content,u=s[l];if(u!==void 0){if(St(u,a))c.delete(l);else{if(r===0)break t;c.set(l,a)}n.right.delete(e)}else n.currentAttributes.set(l,a);break}default:r<n.right.length&&F(e,x(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+=`
4
+ `;n.right=new S(x(i,E(o.store,i)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new et(l)),n.right.integrate(e,0),n.forward()}mi(e,t,n,c)},xi=(e,t,n,r,s)=>{var a,u;let o=t,i=A();for(;o&&(!o.countable||o.deleted);){if(!o.deleted&&o.content.constructor===C){let d=o.content;i.set(d.key,d)}o=o.right}let c=0,l=!1;for(;t!==o;){if(n===t&&(l=!0),!t.deleted){let d=t.content;if(d.constructor===C){let{key:h,value:f}=d,p=(a=r.get(h))!=null?a:null;(i.get(h)!==d||p===f)&&(t.delete(e),c++,!l&&((u=s.get(h))!=null?u:null)===f&&p!==f&&(p===null?s.delete(h):s.set(h,p))),!l&&!t.deleted&&Ee(s,d)}}t=t.right}return c},fa=(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===C){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},bi=e=>{let t=0;return k(e.doc,n=>{let r=e._start,s=e._start,o=A(),i=sn(o);for(;s;)s.deleted===!1&&(s.content.constructor===C?Ee(i,s.content):(t+=xi(n,r,s,o,i),o=sn(i),r=s)),s=s.right}),t},pa=e=>{let t=new Set,n=e.doc;for(let[r,s]of e.afterState.entries()){let o=e.beforeState.get(r)||0;s!==o&&Go(e,n.store.clients.get(r),o,s,i=>{!i.deleted&&i.content.constructor===C&&i.constructor!==$&&t.add(i.parent)})}k(n,r=>{$t(e,e.deleteSet,s=>{if(s instanceof $||!s.parent._hasFormatting||t.has(s.parent))return;let o=s.parent;s.content.constructor===C?t.add(o):fa(r,s)});for(let s of t)bi(s)})},Ro=(e,t,n)=>{let r=n,s=sn(t.currentAttributes),o=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Q:case gt:case et:n<t.right.length&&F(e,x(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}o&&xi(e,o,t.right,s,t.currentAttributes);let i=(t.left||t.right).parent;return i._searchMarker&&Ke(i._searchMarker,t.index,-r+n),t},Gn=class extends Ht{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=>{var f,p,y;let s=new Map,o=new Map,i=this.target._start,c=null,l={},a="",u=0,d=0,h=()=>{if(c!==null){let g=null;switch(c){case"delete":d>0&&(g={delete:d}),d=0;break;case"insert":(typeof a=="object"||a.length>0)&&(g={insert:a},s.size>0&&(g.attributes={},s.forEach((w,U)=>{w!==null&&(g.attributes[U]=w)}))),a="";break;case"retain":u>0&&(g={retain:u},Ks(l)||(g.attributes=zs({},l))),u=0;break}g&&n.push(g),c=null}};for(;i!==null;){switch(i.content.constructor){case Q:case gt:this.adds(i)?this.deletes(i)||(h(),c="insert",a=i.content.getContent()[0],h()):this.deletes(i)?(c!=="delete"&&(h(),c="delete"),d+=1):i.deleted||(c!=="retain"&&(h(),c="retain"),u+=1);break;case et:this.adds(i)?this.deletes(i)||(c!=="insert"&&(h(),c="insert"),a+=i.content.str):this.deletes(i)?(c!=="delete"&&(h(),c="delete"),d+=i.length):i.deleted||(c!=="retain"&&(h(),c="retain"),u+=i.length);break;case C:{let{key:g,value:w}=i.content;if(this.adds(i)){if(!this.deletes(i)){let U=(f=s.get(g))!=null?f:null;St(U,w)?w!==null&&i.delete(r):(c==="retain"&&h(),St(w,(p=o.get(g))!=null?p:null)?delete l[g]:l[g]=w)}}else if(this.deletes(i)){o.set(g,w);let U=(y=s.get(g))!=null?y:null;St(U,w)||(c==="retain"&&h(),l[g]=U)}else if(!i.deleted){o.set(g,w);let U=l[g];U!==void 0&&(St(U,w)?U!==null&&i.delete(r):(c==="retain"&&h(),w===null?delete l[g]:l[g]=w))}i.deleted||(c==="insert"&&h(),Ee(s,i.content));break}}i=i.right}for(h();n.length>0;){let g=n[n.length-1];if(g.retain!==void 0&&g.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}},be=class e extends _{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){var t;return(t=this.doc)!=null||V(),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 Gn(this,t,n);Qn(this,t,r),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){var r;(r=this.doc)!=null||V();let t="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===et&&(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 Ze(null,this._start,0,new Map);for(let o=0;o<t.length;o++){let i=t[o];if(i.insert!==void 0){let c=!n&&typeof i.insert=="string"&&o===t.length-1&&s.right===null&&i.insert.slice(-1)===`
5
+ `?i.insert.slice(0,-1):i.insert;(typeof c!="string"||c.length>0)&&Pr(r,this,s,c,i.attributes||{})}else i.retain!==void 0?Mo(r,this,s,i.retain,i.attributes||{}):i.delete!==void 0&&Ro(r,s,i.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,r){var d;(d=this.doc)!=null||V();let s=[],o=new Map,i=this.doc,c="",l=this._start;function a(){if(c.length>0){let h={},f=!1;o.forEach((y,g)=>{f=!0,h[g]=y});let p={insert:c};f&&(p.attributes=h),s.push(p),c=""}}let u=()=>{for(;l!==null;){if(bt(l,t)||n!==void 0&&bt(l,n))switch(l.content.constructor){case et:{let h=o.get("ychange");t!==void 0&&!bt(l,t)?(h===void 0||h.user!==l.id.client||h.type!=="removed")&&(a(),o.set("ychange",r?r("removed",l.id):{type:"removed"})):n!==void 0&&!bt(l,n)?(h===void 0||h.user!==l.id.client||h.type!=="added")&&(a(),o.set("ychange",r?r("added",l.id):{type:"added"})):h!==void 0&&(a(),o.delete("ychange")),c+=l.content.str;break}case Q:case gt:{a();let h={insert:l.content.getContent()[0]};if(o.size>0){let f={};h.attributes=f,o.forEach((p,y)=>{f[y]=p})}s.push(h);break}case C:bt(l,t)&&(a(),Ee(o,l.content));break}l=l.right}a()};return t||n?k(i,h=>{t&&zr(h,t),n&&zr(h,n),u()},"cleanup"):u(),s}insert(t,n,r){if(n.length<=0)return;let s=this.doc;s!==null?k(s,o=>{let i=Mn(o,this,t,!r);r||(r={},i.currentAttributes.forEach((c,l)=>{r[l]=c})),Pr(o,this,i,n,r)}):this._pending.push(()=>this.insert(t,n,r))}insertEmbed(t,n,r){let s=this.doc;s!==null?k(s,o=>{let i=Mn(o,this,t,!r);Pr(o,this,i,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=>{Ro(s,Mn(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,o=>{let i=Mn(o,this,t,!1);i.right!==null&&Mo(o,this,i,n,r)}):this._pending.push(()=>this.format(t,n,r))}removeAttribute(t){this.doc!==null?k(this.doc,n=>{Hn(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?k(this.doc,r=>{ms(r,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return ws(this,t)}getAttributes(){return fi(this)}_write(t){t.writeTypeRef(Oa)}},ga=e=>new be,He=class{constructor(t,n=()=>!0){var r;this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,(r=t.doc)!=null||V()}[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===O||n.constructor===pt)&&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})}},pt=class e extends _{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 _?n.clone():n)),t}get length(){var t;return(t=this.doc)!=null||V(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new He(this,t)}querySelector(t){t=t.toUpperCase();let r=new He(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return r.done?null:r.value}querySelectorAll(t){return t=t.toUpperCase(),tt(new He(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){Qn(this,t,new qn(this,n,t))}toString(){return li(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),We(this,o=>{s.insertBefore(o.toDOM(t,n,r),null)}),s}insert(t,n){this.doc!==null?k(this.doc,r=>{di(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 _?t._item:t;jn(r,this,s,n)});else{let r=this._prelimContent,s=t===null?0:r.findIndex(o=>o===t)+1;if(s===0&&t!==null)throw q("Reference item not found");r.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?k(this.doc,r=>{hi(r,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return ci(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return ai(this,t)}slice(t=0,n=this.length){return ii(this,t,n)}forEach(t){We(this,t)}_write(t){t.writeTypeRef(Ma)}},ma=e=>new pt,O=class e extends pt{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 Js(n,(r,s)=>{t.setAttribute(s,r)}),t.insert(0,this.toArray().map(r=>r instanceof _?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 o=this.nodeName.toLocaleLowerCase(),i=n.length>0?" "+n.join(" "):"";return`<${o}${i}>${super.toString()}</${o}>`}removeAttribute(t){this.doc!==null?k(this.doc,n=>{Hn(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?k(this.doc,r=>{ms(r,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return ws(this,t)}hasAttribute(t){return pi(this,t)}getAttributes(t){return t?gi(this,t):fi(this)}toDOM(t=document,n={},r){let s=t.createElement(this.nodeName),o=this.getAttributes();for(let i in o){let c=o[i];typeof c=="string"&&s.setAttribute(i,c)}return We(this,i=>{s.appendChild(i.toDOM(t,n,r))}),r!==void 0&&r._createAssociation(s,this),s}_write(t){t.writeTypeRef(La),t.writeKey(this.nodeName)}},wa=e=>new O(e.readKey()),qn=class extends Ht{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)})}},Qe=class e extends Xt{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],o;return s!==void 0?o=s.createDom(this):o=document.createElement(this.hookName),o.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(o,this),o}_write(t){t.writeTypeRef(Ra),t.writeKey(this.hookName)}},ya=e=>new Qe(e.readKey()),K=class e extends be{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 o=[];for(let i in t.attributes[s])o.push({key:i,value:t.attributes[s][i]});o.sort((i,c)=>i.key<c.key?-1:1),n.push({nodeName:s,attrs:o})}n.sort((s,o)=>s.nodeName<o.nodeName?-1:1);let r="";for(let s=0;s<n.length;s++){let o=n[s];r+=`<${o.nodeName}`;for(let i=0;i<o.attrs.length;i++){let c=o.attrs[i];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(Va)}},xa=e=>new K,ke=class{constructor(t,n){this.id=t,this.length=n}get deleted(){throw z()}mergeWith(t){return!1}write(t,n,r){throw z()}integrate(t,n){throw z()}},ba=0,$=class extends ke{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),Xo(t.doc.store,this)}write(t,n){t.writeInfo(ba),t.writeLen(this.length-n)}getMissing(t,n){return null}},Gt=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 z()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}},ka=e=>new Gt(e.readBuf()),Se=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){Pe(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}},Sa=e=>new Se(e.readLen()),ki=(e,t)=>new At({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),qt=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(ki(this.doc.guid,this.opts))}splice(t){throw z()}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}},Ea=e=>new qt(ki(e.readString(),e.readAny())),gt=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 z()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}},Aa=e=>new gt(e.readJSON()),C=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 z()}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}},_a=e=>new C(e.readKey(),e.readJSON()),tn=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 o=this.arr[s];t.writeString(o===void 0?"undefined":JSON.stringify(o))}}getRef(){return 2}},Ca=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 tn(n)},Ta=Re("node_env")==="development",Ct=class e{constructor(t){this.arr=t,Ta&&Sr(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 o=this.arr[s];t.writeAny(o)}}getRef(){return 8}},Ua=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new Ct(n)},et=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}},Da=e=>new et(e.readString()),Ia=[da,ha,ga,wa,ma,ya,xa],Na=0,va=1,Oa=2,La=3,Ma=4,Ra=5,Va=6,Q=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 z()}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}},Ba=e=>new Q(Ia[e.readTypeRef()](e)),Qr=(e,t)=>{let n=t,r=0,s;do r>0&&(n=x(n.client,n.clock+r)),s=Ft(e,n),r=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof S);return{item:s,diff:r}},ys=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},zn=(e,t,n)=>{let{client:r,clock:s}=t.id,o=new S(x(r,s+n),t,x(r,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&o.markDeleted(),t.keep&&(o.keep=!0),t.redone!==null&&(o.redone=x(t.redone.client,t.redone.clock+n)),t.right=o,o.right!==null&&(o.right.left=o),e._mergeStructs.push(o),o.parentSub!==null&&o.right===null&&o.parent._map.set(o.parentSub,o),t.length=n,o},Vo=(e,t)=>_e(e,n=>zt(n.deletions,t)),Si=(e,t,n,r,s,o)=>{let i=e.doc,c=i.store,l=i.clientID,a=t.redone;if(a!==null)return F(e,a);let u=t.parent._item,d=null,h;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||Si(e,u,n,r,s,o)===null))return null;for(;u.redone!==null;)u=F(e,u.redone)}let f=u===null?t.parent:u.content.type;if(t.parentSub===null){for(d=t.left,h=t;d!==null;){let w=d;for(;w!==null&&w.parent._item!==u;)w=w.redone===null?null:F(e,w.redone);if(w!==null&&w.parent._item===u){d=w;break}d=d.left}for(;h!==null;){let w=h;for(;w!==null&&w.parent._item!==u;)w=w.redone===null?null:F(e,w.redone);if(w!==null&&w.parent._item===u){h=w;break}h=h.right}}else if(h=null,t.right&&!s){for(d=t;d!==null&&d.right!==null&&(d.right.redone||zt(r,d.right.id)||Vo(o.undoStack,d.right.id)||Vo(o.redoStack,d.right.id));)for(d=d.right;d.redone;)d=F(e,d.redone);if(d&&d.right!==null)return null}else d=f._map.get(t.parentSub)||null;let p=E(c,l),y=x(l,p),g=new S(y,d,d&&d.lastId,h,h&&h.id,f,t.parentSub,t.content.copy());return t.redone=y,ys(g,!0),g.integrate(e,0),g},S=class e extends ke{constructor(t,n,r,s,o,i,c,l){super(t,l.getLength()),this.origin=r,this.left=n,this.right=s,this.rightOrigin=o,this.parent=i,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>=E(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=E(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ht&&this.id.client!==this.parent.client&&this.parent.clock>=E(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Kr(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=F(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===$||this.right&&this.right.constructor===$)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===ht){let r=Ft(n,this.parent);r.constructor===$?this.parent=null:this.parent=r.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=Kr(t,t.doc.store,x(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 o=new Set,i=new Set;for(;s!==null&&s!==this.right;){if(i.add(s),o.add(s),Bt(this.origin,s.origin)){if(s.id.client<this.id.client)r=s,o.clear();else if(Bt(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&i.has(Ft(t.doc.store,s.origin)))o.has(Ft(t.doc.store,s.origin))||(r=s,o.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),Xo(t.doc.store,this),this.content.integrate(t,this),Io(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new $(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:x(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Bt(t.origin,this.lastId)&&this.right===t&&Bt(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(),Pe(t.deleteSet,this.id.client,this.id.clock,this.length),Io(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw N();this.content.gc(t),n?Xl(t,this,new $(this.id,this.length)):this.content=new Se(this.length)}write(t,n){let r=n>0?x(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,o=this.parentSub,i=this.content.getRef()&31|(r===null?0:128)|(s===null?0:64)|(o===null?0:32);if(t.writeInfo(i),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 a=cs(c);t.writeParentInfo(!0),t.writeString(a)}else t.writeParentInfo(!1),t.writeLeftID(l.id)}else c.constructor===String?(t.writeParentInfo(!0),t.writeString(c)):c.constructor===ht?(t.writeParentInfo(!1),t.writeLeftID(c)):N();o!==null&&t.writeString(o)}this.content.write(t,n)}},Ei=(e,t)=>Fa[t&31](e),Fa=[()=>{N()},Sa,Ca,ka,Da,Aa,_a,Ba,Ua,Ea,()=>{N()}],$a=10,R=class extends ke{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){N()}write(t,n){t.writeInfo($a),m(t.restEncoder,this.length-n)}getMissing(t,n){return null}},Ai=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:{},_i="__ $YJS$ __";Ai[_i]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Ai[_i]=!0;var xs=new Set(["p","div","section","article","header","footer","main","aside","h1","h2","h3","h4","h5","h6","ul","ol","li","blockquote","pre","table","thead","tbody","tfoot","tr","td","th","figure","figcaption"]),bs=new Set(["strong","b","em","i","u","s","strike","del","ins","mark","small","sub","sup","code","kbd","samp","var","span","font","a"]),ks=new Set(["br","hr","img","video","audio","source","iframe","embed","object"]);function Tt(e){let t=e.toLowerCase();return xs.has(t)?"block":ks.has(t)?"leaf":bs.has(t)?"mark":"unknown"}var Ci=["bold","italic","underline","strikethrough","subscript","superscript","color","backcolor","fontFamily","fontSize","link","code"];var Y="http://www.w3.org/1999/xhtml";function nn(e,t){for(;t.firstChild;)t.removeChild(t.firstChild);let n=t.ownerDocument;if(!n)throw new Error("renderFragmentToHost: editable host has no ownerDocument");for(let r=0;r<e.length;r++){let s=e.get(r),o=tr(s,n);o&&t.appendChild(o)}t.childNodes.length===0&&t.appendChild(n.createElementNS(Y,"p"))}function tr(e,t){return e instanceof K?ja(e,t):e instanceof O?Ya(e,t):null}function Ya(e,t){let n=e.nodeName.toLowerCase(),r=Tt(n);if(r==="unknown"){let o=t.createElementNS(Y,"span");return o.setAttribute("data-rte-unknown",n),Ui(e,o),Ti(e,o,t),o}let s=t.createElementNS(Y,n);return Ui(e,s),r==="leaf"||Ti(e,s,t),s}function Ti(e,t,n){let r=e.length;for(let s=0;s<r;s++){let o=e.get(s),i=tr(o,n);i&&t.appendChild(i)}}function Ui(e,t){let n=e.getAttributes();for(let[r,s]of Object.entries(n))s!=null&&t.setAttribute(r,String(s))}function ja(e,t){var s;let n=t.createDocumentFragment(),r=e.toDelta();for(let o of r){if(typeof o.insert!="string"||o.insert.length===0)continue;let i=Pa(o.attributes),c=t.createTextNode(o.insert);for(let l=i.length-1;l>=0;l--){let a=Xa(i[l],(s=o.attributes)!=null?s:{},t);a.appendChild(c),c=a}n.appendChild(c)}return n}var Ha=["link","color","backcolor","fontFamily","fontSize","code","underline","strikethrough","subscript","superscript","italic","bold"];function Pa(e){if(!e)return[];let t=[];for(let n of Ha)n in e&&e[n]!=null&&e[n]!==!1&&t.push(n);return t}function Xa(e,t,n){switch(e){case"bold":return n.createElementNS(Y,"strong");case"italic":return n.createElementNS(Y,"em");case"underline":return n.createElementNS(Y,"u");case"strikethrough":return n.createElementNS(Y,"s");case"subscript":return n.createElementNS(Y,"sub");case"superscript":return n.createElementNS(Y,"sup");case"code":return n.createElementNS(Y,"code");case"link":{let r=n.createElementNS(Y,"a"),s=t.link;return typeof s=="string"&&r.setAttribute("href",s),r}case"color":{let r=n.createElementNS(Y,"span");return r.setAttribute("style",`color:${t.color}`),r}case"backcolor":{let r=n.createElementNS(Y,"span");return r.setAttribute("style",`background-color:${t.backcolor}`),r}case"fontFamily":{let r=n.createElementNS(Y,"span");return r.setAttribute("style",`font-family:${t.fontFamily}`),r}case"fontSize":{let r=n.createElementNS(Y,"span");return r.setAttribute("style",`font-size:${t.fontSize}`),r}default:return n.createElementNS(Y,"span")}}function er(e){var o;let t=(o=e.ownerDocument)==null?void 0:o.defaultView,n=t==null?void 0:t.getSelection(),r={insideHost:!1,anchorPath:[],anchorOffset:0,focusPath:[],focusOffset:0};if(!n||n.rangeCount===0)return r;let s=n.getRangeAt(0);return!e.contains(s.startContainer)||!e.contains(s.endContainer)?r:{insideHost:!0,anchorPath:Di(e,s.startContainer),anchorOffset:s.startOffset,focusPath:Di(e,s.endContainer),focusOffset:s.endOffset}}function nr(e,t){if(!t.insideHost)return;let n=e.ownerDocument,r=n==null?void 0:n.defaultView;if(!n||!r)return;let s=r.getSelection();if(!s)return;let o=Ii(e,t.anchorPath,t.anchorOffset),i=t.anchorPath===t.focusPath?o:Ii(e,t.focusPath,t.focusOffset);try{let c=n.createRange();c.setStart(o.node,o.offset),c.setEnd(i.node,i.offset),s.removeAllRanges(),s.addRange(c)}catch(c){}}function Di(e,t){let n=[],r=t;for(;r&&r!==e;){let s=r.parentNode;if(!s)break;let o=0,i=s.firstChild;for(;i&&i!==r;)o++,i=i.nextSibling;n.unshift(o),r=s}return n}function Ii(e,t,n){let r=e;for(let o of t){let i=r.childNodes.item(o);if(!i)return{node:r,offset:0};r=i}let s=Ga(r,n);return{node:r,offset:s}}function Ga(e,t){if(e.nodeType===3){let r=e.data.length;return Math.max(0,Math.min(t,r))}let n=e.childNodes.length;return Math.max(0,Math.min(t,n))}function Ni(e){var s,o;let t=(s=e.editable.ownerDocument)==null?void 0:s.defaultView;if(!t)return{disconnect:()=>{},drainPending:()=>{}};let n=(o=t.MutationObserver)!=null?o:globalThis.MutationObserver;if(!n)return{disconnect:()=>{},drainPending:()=>{}};let r=new n(i=>{var c;e.isApplyingRemote()||(c=e.fragment.doc)==null||c.transact(()=>{for(let l of i)qa(l,e)},at)});return r.observe(e.editable,{childList:!0,subtree:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0}),{disconnect:()=>r.disconnect(),drainPending:()=>{r.takeRecords()}}}function qa(e,t){switch(e.type){case"characterData":za(e,t);break;case"childList":Ja(e,t);break;case"attributes":Wa(e,t);break}}function za(e,t){let n=e.target;if(n.nodeType!==3)return;let r=Za(n,t);if(!r)return;let s=n.data;r.toString()!==s&&(r.delete(0,r.length),r.insert(0,s))}function Ja(e,t){if(e.target===t.editable){Li(t);return}e.target.nodeType===1&&Ka(e.target,t)}function Ka(e,t){let n=vi(e,t);if(!n){Qa(t);return}n.delete(0,n.length);let r=Vi(Array.from(e.childNodes));r.children.length>0&&(n.insert(0,r.children),Es(r.marked))}function Wa(e,t){if(e.target.nodeType!==1)return;let n=e.target,r=vi(n,t);if(!r||e.attributeName===null)return;let s=n.getAttribute(e.attributeName);s===null?r.removeAttribute(e.attributeName):r.getAttribute(e.attributeName)!==s&&r.setAttribute(e.attributeName,s)}function Za(e,t){let n=Oi(t.editable,e);if(n.length===0)return null;let r=t.fragment;for(let o=0;o<n.length-1;o++){let i=n[o],c=r.get(i);if(!(c instanceof O))return null;r=c}let s=r.get(n[n.length-1]);return s instanceof K?s:null}function vi(e,t){let n=Oi(t.editable,e);if(n.length===0)return null;let r=t.fragment;for(let s of n){let o=r.get(s);if(!(o instanceof O))return null;r=o}return r instanceof O?r:null}function Oi(e,t){let n=[],r=t;for(;r&&r!==e;){let s=r.parentNode;if(!s)break;let o=0,i=s.firstChild;for(;i&&i!==r;)o++,i=i.nextSibling;n.unshift(o),r=s}return n}var Ss=new WeakSet;function Qa(e){Ss.has(e.fragment)||(Ss.add(e.fragment),queueMicrotask(()=>{var t;Ss.delete(e.fragment),(t=e.fragment.doc)==null||t.transact(()=>Li(e),at)}))}function Li(e){e.fragment.delete(0,e.fragment.length);let t=Mi(e.editable);t.children.length>0&&(e.fragment.insert(0,t.children),Es(t.marked))}function Mi(e){let t={children:[],marked:[]};for(let n=0;n<e.childNodes.length;n++){let r=e.childNodes.item(n),s=Ri(r);if(s){s.node&&t.children.push(s.node);for(let o of s.marked)t.marked.push(o)}}return t}function Ri(e){if(e.nodeType===3)return{node:new K(e.data),marked:[]};if(e.nodeType!==1)return null;let t=e,n=t.tagName.toLowerCase(),r=Tt(n);if(r==="mark")return null;let s=new O(n);for(let i of Array.from(t.attributes))s.setAttribute(i.name,i.value);if(r==="leaf")return{node:s,marked:[]};let o=Vi(Array.from(t.childNodes));for(let i of o.children)s.insert(s.length,[i]);return{node:s,marked:o.marked}}function tu(){return{str:"",ranges:[]}}function Vi(e){let t={marked:[],children:[]},n=null,r=()=>{if(n&&n.str.length>0){let o=new K(n.str);t.children.push(o),n.ranges.length>0&&t.marked.push({text:o,ranges:n.ranges})}n=null},s=()=>(n||(n=tu()),n);for(let o of e){if(o.nodeType===3){let a=o.data;if(a.length===0)continue;let u=s();u.str+=a;continue}if(o.nodeType!==1)continue;let i=o,c=i.tagName.toLowerCase(),l=Tt(c);if(l==="mark"){let a=s(),u=Fi(i);Bi(i,a,u);continue}if(r(),l==="leaf"){let a=new O(c);for(let u of Array.from(i.attributes))a.setAttribute(u.name,u.value);t.children.push(a)}else{let a=Ri(i);if(a&&a.node){t.children.push(a.node);for(let u of a.marked)t.marked.push(u)}}}return r(),t}function Bi(e,t,n){for(let r of Array.from(e.childNodes)){if(r.nodeType===3){let i=r.data;if(i.length===0)continue;let c=t.str.length;t.str+=i;let l=t.str.length;Object.keys(n).length>0&&t.ranges.push({start:c,end:l,marks:n});continue}if(r.nodeType!==1)continue;let s=r;if(Tt(s.tagName.toLowerCase())==="mark"){let i={...n,...Fi(s)};Bi(s,t,i)}}}function Es(e){for(let t of e)for(let n of t.ranges){let r=n.end-n.start;r<=0||t.text.format(n.start,r,n.marks)}}var As={buildYNodesFromDom:Mi,applyDeferredMarks:Es};function Fi(e){switch(e.tagName.toLowerCase()){case"strong":case"b":return{bold:!0};case"em":case"i":return{italic:!0};case"u":return{underline:!0};case"s":case"strike":case"del":return{strikethrough:!0};case"sub":return{subscript:!0};case"sup":return{superscript:!0};case"code":case"kbd":case"samp":return{code:!0};case"a":{let n=e.getAttribute("href");return n?{link:n}:{}}case"span":case"font":return eu(e);default:return{}}}function eu(e){var r;let t={},n=(r=e.getAttribute("style"))!=null?r:"";for(let s of n.split(";")){let[o,...i]=s.split(":");if(!o||i.length===0)continue;let c=o.trim().toLowerCase(),l=i.join(":").trim();if(l)switch(c){case"color":t.color=l;break;case"background-color":case"background":t.backcolor=l;break;case"font-family":t.fontFamily=l;break;case"font-size":t.fontSize=l;break}}if(e.tagName.toLowerCase()==="font"){let s=e.getAttribute("color");s&&(t.color=s);let o=e.getAttribute("face");o&&(t.fontFamily=o)}return t}function rr(e){var d,h,f;let t=(d=e.fragmentName)!=null?d:"default",n=e.ydoc.getXmlFragment(t),r=(f=e.awareness)!=null?f:(h=e.provider)==null?void 0:h.awareness,s=!1,o=Ni({editable:e.editable,fragment:n,isApplyingRemote:()=>s});s=!0;try{nn(n,e.editable)}finally{o.drainPending(),s=!1}let i=(p,y)=>{if(y===at)return;let g=er(e.editable);s=!0;try{nn(n,e.editable)}finally{o.drainPending(),s=!1}nr(e.editable,g)};e.ydoc.on("update",i);let c=()=>{e.ydoc.off("update",i)},l=()=>o.disconnect(),a=nu(r,e.initialAwareness),u=[c,l,a];return{ydoc:e.ydoc,fragment:n,dispose(){for(let p of u)try{p()}catch(y){console.error("[crdt-engine] dispose cleanup error:",y)}u=[]}}}function nu(e,t){return e?(t&&e.setLocalState(t),()=>e.setLocalState(null)):()=>{}}function $i(e){var n;let t=new Set([at]);if(e.extraTrackedOrigins)for(let r of e.extraTrackedOrigins)t.add(r);return new qe(e.fragment,{trackedOrigins:t,captureTimeout:(n=e.captureTimeoutMs)!=null?n:500})}var ru=32;function Pi(e){var u,d;let t=(u=e.editable.ownerDocument)==null?void 0:u.defaultView,n=e.editable.ownerDocument,r=(d=e.throttleMs)!=null?d:ru,s=null,o=null,i=null,c=()=>{var w;if(!n)return;let h=t==null?void 0:t.getSelection();if(!h||h.rangeCount===0){e.awareness.setLocalStateField("cursor",null);return}let f=h.getRangeAt(0);if(!e.editable.contains(f.startContainer)||!e.editable.contains(f.endContainer)){e.awareness.setLocalStateField("cursor",null);return}let p=Yi(e.fragment,e.editable,f.startContainer,f.startOffset),y=h.isCollapsed?p:Yi(e.fragment,e.editable,f.endContainer,f.endOffset);if(!p||!y){e.awareness.setLocalStateField("cursor",null);return}if(s&&o&&Hi(s,p)&&Hi(o,y))return;s=p,o=y;let g={...e.user?{user:e.user}:{},cursor:{anchor:{encoded:p},head:{encoded:y}}};e.awareness.setLocalState({...(w=e.awareness.getStates().get(e.awareness.clientID))!=null?w:{},...g,active:Date.now()})},l=()=>{i==null&&(i=setTimeout(()=>{i=null,c()},r))},a=()=>l();return n&&n.addEventListener("selectionchange",a),{dispose(){i!=null&&clearTimeout(i),n&&n.removeEventListener("selectionchange",a),e.awareness.setLocalStateField("cursor",null)},publishNow(){i!=null&&(clearTimeout(i),i=null),c()},snapshotPeers(){var f,p;let h=[];for(let[y,g]of e.awareness.getStates()){if(y===e.awareness.clientID)continue;let w=g;if(!w.cursor)continue;let U=ji(e.fragment,e.editable,w.cursor.anchor.encoded),Ut=w.cursor.head===w.cursor.anchor?U:ji(e.fragment,e.editable,w.cursor.head.encoded);h.push({clientID:y,user:(f=w.user)!=null?f:{},anchor:U,head:Ut,isCollapsed:U!==null&&Ut!==null&&U.node===Ut.node&&U.offset===Ut.offset,activeAt:(p=w.active)!=null?p:0})}return h}}}function Yi(e,t,n,r){let s=su(e,t,n,r);if(!s)return null;try{let o=ls(s.parent,s.index);return as(o)}catch(o){return null}}function ji(e,t,n){if(!e.doc)return null;try{let r=us(n),s=ds(r,e.doc);return s?ou(t,s.type,s.index):null}catch(r){return null}}function su(e,t,n,r){var u;let s=[],o=r,i=n;if(i.nodeType===3)for(;i&&i!==t;){let d=i.parentNode;if(!d)break;let h=0,f=d.firstChild;for(;f&&f!==i;)h+=_s(f),f=f.nextSibling;if(o+=h,d===t||cu(d)){i=d;break}i=d}else if(i.nodeType===1){let d=0;for(let h=0;h<r&&h<i.childNodes.length;h++)d+=_s(i.childNodes.item(h));o=d}if(i===t){let d=(u=lu(t,n===t?t:n).at(0))!=null?u:0;return{parent:e,index:d}}let c=i;for(;c&&c!==t;){let d=c.parentNode;if(!d)return null;let h=0,f=d.firstChild;for(;f&&f!==c;)h++,f=f.nextSibling;s.unshift(h),c=d}let l=e;for(let d of s){let h=l.get(d);if(!(h instanceof O))return null;l=h}let a=l.get(0);return a instanceof K?{parent:a,index:o}:{parent:l,index:0}}function ou(e,t,n){let r=[],s=t,o=!0;for(;s;){let l=s._item;if(!l)break;let a=l.parent;if(!a)break;let u=0,d=!1;if(a instanceof pt||a instanceof O){for(let h=0;h<a.length;h++)if(a.get(h)===s){u=h,d=!0;break}}if(!d)break;o&&t instanceof K||r.unshift(u),o=!1,s=a}let i=e;for(let l of r){let a=i.childNodes.item(l);if(!a)return null;i=a}return iu(i,n)}function iu(e,t){let n=t,r=[];for(let s=e.childNodes.length-1;s>=0;s--)r.push(e.childNodes.item(s));for(;r.length>0;){let s=r.pop();if(s.nodeType===3){let o=s.data.length;if(n<=o)return{node:s,offset:n};n-=o;continue}if(s.nodeType===1)for(let o=s.childNodes.length-1;o>=0;o--)r.push(s.childNodes.item(o))}return{node:e,offset:e.childNodes.length}}function _s(e){if(e.nodeType===3)return e.data.length;let t=0;for(let n=0;n<e.childNodes.length;n++)t+=_s(e.childNodes.item(n));return t}function cu(e){if(e.nodeType!==1)return!1;let t=e.tagName.toLowerCase();return!["strong","b","em","i","u","s","strike","del","ins","mark","small","sub","sup","code","kbd","samp","var","span","font","a"].includes(t)}function lu(e,t){let n=[],r=t;for(;r&&r!==e;){let s=r.parentNode;if(!s)break;let o=0,i=s.firstChild;for(;i&&i!==r;)o++,i=i.nextSibling;n.unshift(o),r=s}return n}function Hi(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Xi(e){var r,s;let t=(r=e.textSync)!=null?r:!1;if(t==="crdt")return rr(e);if(t===!0){if(!e.legacySnapshotAttach)throw new Error("[crdt-engine] textSync: true requires `legacySnapshotAttach` to be provided by the host. See M5.1 in the sprint README for the back-compat contract.");return e.legacySnapshotAttach(e)}let n=e.ydoc.getXmlFragment((s=e.fragmentName)!=null?s:"default");return{ydoc:e.ydoc,fragment:n,dispose(){}}}function Gi(e){var c;let t=(c=e.fragmentName)!=null?c:"default",n=e.ydoc.getXmlFragment(t),r=e.parserDocument.createElement("div");r.innerHTML=e.html;let s=r,o=r.querySelector("body");o&&(s=o);let i=As.buildYNodesFromDom(s);return e.replace!==!1&&n.length>0&&n.delete(0,n.length),i.children.length>0&&(n.insert(n.length,i.children),As.applyDeferredMarks(i.marked)),n}var Ts=3e4,sr=class extends ln{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let n=xt();this.getLocalState()!==null&&Ts/2<=n-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((s,o)=>{o!==this.clientID&&Ts<=n-s.lastUpdated&&this.states.has(o)&&r.push(o)}),r.length>0&&au(this,r,"timeout")},L(Ts/10)),t.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(t){let n=this.clientID,r=this.meta.get(n),s=r===void 0?0:r.clock+1,o=this.states.get(n);t===null?this.states.delete(n):this.states.set(n,t),this.meta.set(n,{clock:s,lastUpdated:xt()});let i=[],c=[],l=[],a=[];t===null?a.push(n):o==null?t!=null&&i.push(n):(c.push(n),Rt(o,t)||l.push(n)),(i.length>0||l.length>0||a.length>0)&&this.emit("change",[{added:i,updated:l,removed:a},"local"]),this.emit("update",[{added:i,updated:c,removed:a},"local"])}setLocalStateField(t,n){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[t]:n})}getStates(){return this.states}},au=(e,t,n)=>{let r=[];for(let s=0;s<t.length;s++){let o=t[s];if(e.states.has(o)){if(e.states.delete(o),o===e.clientID){let i=e.meta.get(o);e.meta.set(o,{clock:i.clock+1,lastUpdated:xt()})}r.push(o)}}r.length>0&&(e.emit("change",[{added:[],updated:[],removed:r},n]),e.emit("update",[{added:[],updated:[],removed:r},n]))};typeof window!="undefined"&&(window.RichTextEditorCrdt=Object.assign({},Cs,{Y:Jt,Awareness:sr}));})();