@thebase/ui
Version:
CDN-installable Owl and Bootstrap 5 UI component library.
6 lines • 94.3 kB
JavaScript
import{e as Je}from"./chunk-23NN352E.js";var _=()=>new Map,Xe=e=>{let t=_();return e.forEach((n,r)=>{t.set(r,n)}),t},L=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},Wr=(e,t)=>{let n=[];for(let[r,s]of e)n.push(t(s,r));return n},Zr=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1};var W=()=>new Set;var Pe=e=>e[e.length-1];var Qr=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},P=Array.from,Ke=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},ge=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1};var ts=(e,t)=>{let n=new Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n};var st=Array.isArray;var Ot=class{constructor(){this._observers=_()}on(t,n){return L(this._observers,t,W).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 P((this._observers.get(t)||_()).values()).forEach(r=>r(...n))}destroy(){this._observers=_()}},es=class{constructor(){this._observers=_()}on(t,n){L(this._observers,t,W).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 P((this._observers.get(t)||_()).values()).forEach(r=>r(...n))}destroy(){this._observers=_()}};var O=Math.floor;var bt=Math.abs;var $l=Math.log10;var Ye=(e,t)=>e<t?e:t,it=(e,t)=>e>t?e:t,Fl=Number.isNaN,jl=Math.pow;var We=e=>e!==0?e<0:1/e<0;var Nt=Number.MAX_SAFE_INTEGER,Hn=Number.MIN_SAFE_INTEGER,ql=1<<31;var ns=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&O(e)===e),Gl=Number.isNaN,zl=Number.parseInt;var we=String.fromCharCode,to=String.fromCodePoint,Hl=we(65535),eo=e=>e.toLowerCase(),no=/^\s*/g,ro=e=>e.replace(no,""),so=/([A-Z])/g,Xn=(e,t)=>ro(e.replace(so,n=>`${t}${eo(n)}`));var io=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},Bt=typeof TextEncoder<"u"?new TextEncoder:null,oo=e=>Bt.encode(e),rs=Bt?oo:io;var Lt=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Lt&&Lt.decode(new Uint8Array).length===1&&(Lt=null);var Ze=(e,t)=>ts(t,()=>e).join("");var kt=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},ut=()=>new kt,ls=e=>{let t=ut();return e(t),$(t)},co=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t};var $=e=>{let t=new Uint8Array(co(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},lo=(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(it(n,t)*2),e.cpos=0)},T=(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 Ft=T;var g=(e,t)=>{for(;t>127;)T(e,128|127&t),t=O(t/128);T(e,127&t)},xe=(e,t)=>{let n=We(t);for(n&&(t=-t),T(e,(t>63?128:0)|(n?64:0)|63&t),t=O(t/64);t>0;)T(e,(t>127?128:0)|127&t),t=O(t/128)},Pn=new Uint8Array(3e4),ao=Pn.length/3,ho=(e,t)=>{if(t.length<ao){let n=Bt.encodeInto(t,Pn).written||0;g(e,n);for(let r=0;r<n;r++)T(e,Pn[r])}else F(e,rs(t))},uo=(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;g(e,r);for(let s=0;s<r;s++)T(e,n.codePointAt(s))},lt=Bt&&Bt.encodeInto?ho:uo;var as=(e,t)=>jt(e,$(t)),jt=(e,t)=>{let n=e.cbuf.length,r=e.cpos,s=Ye(n-r,t.length),i=t.length-s;e.cbuf.set(t.subarray(0,s),r),e.cpos+=s,i>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(it(n*2,i)),e.cbuf.set(t.subarray(s)),e.cpos=i)},F=(e,t)=>{g(e,t.byteLength),jt(e,t)},Kn=(e,t)=>{lo(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},fo=(e,t)=>Kn(e,4).setFloat32(0,t,!1),po=(e,t)=>Kn(e,8).setFloat64(0,t,!1),go=(e,t)=>Kn(e,8).setBigInt64(0,t,!1);var is=new DataView(new ArrayBuffer(4)),mo=e=>(is.setFloat32(0,e),is.getFloat32(0)===e),at=(e,t)=>{switch(typeof t){case"string":T(e,119),lt(e,t);break;case"number":ns(t)&&bt(t)<=2147483647?(T(e,125),xe(e,t)):mo(t)?(T(e,124),fo(e,t)):(T(e,123),po(e,t));break;case"bigint":T(e,122),go(e,t);break;case"object":if(t===null)T(e,126);else if(st(t)){T(e,117),g(e,t.length);for(let n=0;n<t.length;n++)at(e,t[n])}else if(t instanceof Uint8Array)T(e,116),F(e,t);else{T(e,118);let n=Object.keys(t);g(e,n.length);for(let r=0;r<n.length;r++){let s=n[r];lt(e,s),at(e,t[s])}}break;case"boolean":T(e,t?120:121);break;default:T(e,127)}},ye=class extends kt{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&g(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}};var os=e=>{e.count>0&&(xe(e.encoder,e.count===1?e.s:-e.s),e.count>1&&g(e.encoder,e.count-2))},St=class{constructor(){this.encoder=new kt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(os(this),this.count=1,this.s=t)}toUint8Array(){return os(this),$(this.encoder)}};var cs=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);xe(e.encoder,t),e.count>1&&g(e.encoder,e.count-2)}},$t=class{constructor(){this.encoder=new kt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(cs(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return cs(this),$(this.encoder)}},Qe=class{constructor(){this.sarr=[],this.s="",this.lensE=new St}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 kt;return this.sarr.push(this.s),this.s="",lt(t,this.sarr.join("")),jt(t,this.lensE.toUint8Array()),$(t)}};var G=e=>new Error(e),z=()=>{throw G("Method unimplemented")},D=()=>{throw G("Unexpected case")};var us=G("Unexpected end of array"),ds=G("Integer out of Range"),qt=class{constructor(t){this.arr=t,this.pos=0}},V=e=>new qt(e),Wn=e=>e.pos!==e.arr.length;var wo=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},j=e=>wo(e,w(e));var _t=e=>e.arr[e.pos++];var w=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>Nt)throw ds}throw us},ke=e=>{let t=e.arr[e.pos++],n=t&63,r=64,s=(t&64)>0?-1:1;if((t&128)===0)return s*n;let i=e.arr.length;for(;e.pos<i;){if(t=e.arr[e.pos++],n=n+(t&127)*r,r*=128,t<128)return s*n;if(n>Nt)throw ds}throw us};var yo=e=>{let t=w(e);if(t===0)return"";{let n=String.fromCodePoint(_t(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(_t(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))}},xo=e=>Lt.decode(j(e)),dt=Lt?xo:yo;var Zn=(e,t)=>{let n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},bo=e=>Zn(e,4).getFloat32(0,!1),ko=e=>Zn(e,8).getFloat64(0,!1),So=e=>Zn(e,8).getBigInt64(0,!1);var _o=[e=>{},e=>null,ke,bo,ko,So,e=>!1,e=>!0,dt,e=>{let t=w(e),n={};for(let r=0;r<t;r++){let s=dt(e);n[s]=Gt(e)}return n},e=>{let t=w(e),n=[];for(let r=0;r<t;r++)n.push(Gt(e));return n},j],Gt=e=>_o[127-_t(e)](e),be=class extends qt{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Wn(this)?this.count=w(this)+1:this.count=-1),this.count--,this.s}};var Et=class extends qt{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=ke(this);let t=We(this.s);this.count=1,t&&(this.s=-this.s,this.count=w(this)+2)}return this.count--,this.s}};var zt=class extends qt{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let t=ke(this),n=t&1;this.diff=O(t/2),this.count=1,n&&(this.count=w(this)+2)}return this.s+=this.diff,this.count--,this.s}},tn=class{constructor(t){this.decoder=new Et(t),this.str=dt(this.decoder),this.spos=0}read(){let t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}};var Pl=crypto.subtle,fs=crypto.getRandomValues.bind(crypto);var Uo=Math.random,Qn=()=>fs(new Uint32Array(1))[0];var Wl=e=>e[O(Uo()*e.length)],Co="10000000-1000-4000-8000"+-1e11,ps=()=>Co.replace(/[018]/g,e=>(e^Qn()&15>>e/4).toString(16));var Se=Date.now;var tr=e=>new Promise(e);var Zl=Promise.all.bind(Promise),Ql=e=>Promise.reject(e),ta=e=>Promise.resolve(e);var er=e=>e===void 0?null:e;var nr=class{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}},ms=new nr,rr=!0;try{typeof localStorage<"u"&&localStorage&&(ms=localStorage,rr=!1)}catch{}var ws=ms,ea=e=>rr||addEventListener("storage",e),na=e=>rr||removeEventListener("storage",e);var Ut=Symbol("Equality"),en=(e,t)=>e===t||!!e?.[Ut]?.(t)||!1;var ys=e=>typeof e=="object",xs=Object.assign,vo=Object.keys;var bs=(e,t)=>{for(let n in e)t(e[n],n)},ra=(e,t)=>{let n=[];for(let r in e)n.push(t(e[r],r));return n};var _e=e=>vo(e).length;var ks=e=>{for(let t in e)return!1;return!0},Ht=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Ee=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),ir=(e,t)=>e===t||_e(e)===_e(t)&&Ht(e,(n,r)=>(n!==void 0||Ee(t,r))&&en(t[r],n)),Oo=Object.freeze,or=e=>{for(let t in e){let n=e[t];(typeof n=="object"||typeof n=="function")&&or(e[t])}return Oo(e)};var Ce=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Ce(e,t,n+1)}},Ss=()=>{};var lr=e=>e;var Ue=(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[Ut]!=null)return e[Ut](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)||!Ue(e.get(n),t.get(n)))return!1;break}case void 0:case Object:if(_e(e)!==_e(t))return!1;for(let n in e)if(!Ee(e,n)||!Ue(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(!Ue(e[n],t[n]))return!1;break;default:return!1}return!0},_s=(e,t)=>t.includes(e);var Jt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",rn=typeof window<"u"&&typeof document<"u"&&!Jt,sa=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,Z,Vo=[],No=()=>{if(Z===void 0)if(Jt){Z=_();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]==="-"?(t!==null&&Z.set(t,""),t=r):t!==null?(Z.set(t,r),t=null):Vo.push(r)}t!==null&&Z.set(t,"")}else typeof location=="object"?(Z=_(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){let[t,n]=e.split("=");Z.set(`--${Xn(t,"-")}`,n),Z.set(`-${Xn(t,"-")}`,n)}})):Z=_();return Z},ar=e=>No().has(e);var Ct=e=>Jt?er(process.env[e.toUpperCase().replaceAll("-","_")]):er(ws.getItem(e));var Es=e=>ar("--"+e)||Ct(e)!==null,Us=Es("production"),Lo=Jt&&_s(process.env.FORCE_COLOR,["true","1","2"]),Cs=Lo||!ar("--no-colors")&&!Es("no-color")&&(!Jt||process.stdout.isTTY)&&(!Jt||ar("--color")||Ct("COLORTERM")!==null||(Ct("TERM")||"").includes("color"));var As=e=>new Uint8Array(e),Bo=(e,t,n)=>new Uint8Array(e,t,n),ia=e=>new Uint8Array(e),Mo=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=we(e[n]);return btoa(t)},Ro=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),$o=e=>{let t=atob(e),n=As(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n},Fo=e=>{let t=Buffer.from(e,"base64");return Bo(t.buffer,t.byteOffset,t.byteLength)},oa=rn?Mo:Ro,ca=rn?$o:Fo;var Is=e=>{let t=As(e.byteLength);return t.set(e),t},la=e=>ls(t=>at(t,e));var hr=class{constructor(t,n){this.left=t,this.right=n}},Q=(e,t)=>new hr(e,t);var ur=e=>e.next()>=.5,sn=(e,t,n)=>O(e.next()*(n+1-t)+t);var dr=(e,t,n)=>O(e.next()*(n+1-t)+t);var fr=(e,t,n)=>dr(e,t,n);var Go=e=>we(fr(e,97,122)),Ts=(e,t=0,n=20)=>{let r=fr(e,t,n),s="";for(let i=0;i<r;i++)s+=Go(e);return s};var on=(e,t)=>t[fr(e,0,t.length-1)];var Ho=Symbol("0schema"),pr=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(Ze(" ",(this._rerrs.length-n)*2)+`${r.path!=null?`[${r.path}] `:""}${r.has} doesn't match ${r.expected}. ${r.message}`)}return t.join(`
`)}},gr=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[Ut]?en(e,t):st(e)?Ke(e,n=>ge(t,r=>gr(n,r))):ys(e)?Ht(e,(n,r)=>gr(n,t[r])):!1,v=class{extends(t){let[n,r]=[this.shape,t.shape];return this.constructor._dilutes&&([r,n]=[n,r]),gr(n,r)}equals(t){return this.constructor===t.constructor&&Ue(this.shape,t.shape)}[Ho](){return!0}[Ut](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){z()}get nullable(){return Zt(this,xn)}get optional(){return new cn(this)}cast(t){return Ds(t,this),t}expect(t){return Ds(t,this),t}};Je(v,"_dilutes",!1);var Ie=class extends v{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n=void 0){let r=t?.constructor===this.shape&&(this._c==null||this._c(t));return!r&&n?.extend(null,this.shape.name,t?.constructor.name,t?.constructor!==this.shape?"Constructor match failed":"Check failed"),r}},U=(e,t=null)=>new Ie(e,t),ha=U(Ie),Te=class extends v{constructor(t){super(),this.shape=t}check(t,n){let r=this.shape(t);return!r&&n?.extend(null,"custom prop",t?.constructor.name,"failed to check custom prop"),r}},I=e=>new Te(e),ua=U(Te),Yt=class extends v{constructor(t){super(),this.shape=t}check(t,n){let r=this.shape.some(s=>s===t);return!r&&n?.extend(null,this.shape.join(" | "),t.toString()),r}},wn=(...e)=>new Yt(e),vs=U(Yt),Jo=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,t=>"\\"+t)),Os=e=>{if(Wt.check(e))return[Jo(e)];if(vs.check(e))return e.shape.map(t=>t+"");if(Ms.check(e))return["[+-]?\\d+.?\\d*"];if(Rs.check(e))return[".*"];if(pn.check(e))return e.shape.map(Os).flat(1);D()},mr=class extends v{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(Os).map(n=>`(${n.join("|")})`).join("")+"$")}check(t,n){let r=this._r.exec(t)!=null;return!r&&n?.extend(null,this._r.toString(),t.toString(),"String doesn't match string template."),r}};var da=U(mr),Xo=Symbol("optional"),cn=class extends v{constructor(t){super(),this.shape=t}check(t,n){let r=t===void 0||this.shape.check(t);return!r&&n?.extend(null,"undefined (optional)","()"),r}get[Xo](){return!0}},Po=U(cn),ln=class extends v{check(t,n){return n?.extend(null,"never",typeof t),!1}},fa=new ln,pa=U(ln),mn=class mn extends v{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}get partial(){return new mn(this.shape,!0)}check(t,n){return t==null?(n?.extend(null,"object","null"),!1):Ht(this.shape,(r,s)=>{let i=this._isPartial&&!Ee(t,s)||r.check(t[s],n);return!i&&n?.extend(s.toString(),r.toString(),typeof t[s],"Object property does not match"),i})}};Je(mn,"_dilutes",!0);var an=mn,Ko=e=>new an(e),Yo=U(an),Wo=I(e=>e!=null&&(e.constructor===Object||e.constructor==null)),hn=class extends v{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return t!=null&&Ht(t,(r,s)=>{let i=this.shape.keys.check(s,n);return!i&&n?.extend(s+"","Record",typeof t,i?"Key doesn't match schema":"Value doesn't match value"),i&&this.shape.values.check(r,n)})}},Vs=(e,t)=>new hn(e,t),Zo=U(hn),un=class extends v{constructor(t){super(),this.shape=t}check(t,n){return t!=null&&Ht(this.shape,(r,s)=>{let i=r.check(t[s],n);return!i&&n?.extend(s.toString(),"Tuple",typeof r),i})}},Qo=(...e)=>new un(e),ga=U(un),dn=class extends v{constructor(t){super(),this.shape=t.length===1?t[0]:new Pt(t)}check(t,n){let r=st(t)&&Ke(t,s=>this.shape.check(s));return!r&&n?.extend(null,"Array",""),r}},Ns=(...e)=>new dn(e),tc=U(dn),ec=I(e=>st(e)),fn=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?.extend(null,this.shape.name,t?.constructor.name),r}},nc=(e,t=null)=>new fn(e,t),ma=U(fn),rc=nc(v),wr=class extends v{constructor(t){super(),this.len=t.length-1,this.args=Qo(...t.slice(-1)),this.res=t[this.len]}check(t,n){let r=t.constructor===Function&&t.length<=this.len;return!r&&n?.extend(null,"function",typeof t),r}};var sc=U(wr),ic=I(e=>typeof e=="function"),yr=class extends v{constructor(t){super(),this.shape=t}check(t,n){let r=Ke(this.shape,s=>s.check(t,n));return!r&&n?.extend(null,"Intersectinon",typeof t),r}};var wa=U(yr,e=>e.shape.length>0),Pt=class extends v{constructor(t){super(),this.shape=t}check(t,n){let r=ge(this.shape,s=>s.check(t,n));return n?.extend(null,"Union",typeof t),r}};Je(Pt,"_dilutes",!0);var Zt=(...e)=>e.findIndex(t=>pn.check(t))>=0?Zt(...e.map(t=>De(t)).map(t=>pn.check(t)?t.shape:[t]).flat(1)):e.length===1?e[0]:new Pt(e),pn=U(Pt),Ls=()=>!0,gn=I(Ls),oc=U(Te,e=>e.shape===Ls),br=I(e=>typeof e=="bigint"),cc=I(e=>e===br),Bs=I(e=>typeof e=="symbol"),ya=I(e=>e===Bs),Kt=I(e=>typeof e=="number"),Ms=I(e=>e===Kt),Wt=I(e=>typeof e=="string"),Rs=I(e=>e===Wt),yn=I(e=>typeof e=="boolean"),lc=I(e=>e===yn),$s=wn(void 0),xa=U(Yt,e=>e.shape.length===1&&e.shape[0]===void 0),ba=wn(void 0);var xn=wn(null),ac=U(Yt,e=>e.shape.length===1&&e.shape[0]===null),ka=U(Uint8Array),Sa=U(Ie,e=>e.shape===Uint8Array),hc=Zt(Kt,Wt,xn,$s,br,yn,Bs),_a=(()=>{let e=Ns(gn),t=Vs(Wt,gn),n=Zt(Kt,Wt,xn,yn,e,t);return e.shape=n,t.shape.values=n,n})(),De=e=>{if(rc.check(e))return e;if(Wo.check(e)){let t={};for(let n in e)t[n]=De(e[n]);return Ko(t)}else{if(ec.check(e))return Zt(...e.map(De));if(hc.check(e))return wn(e);if(ic.check(e))return U(e)}D()},Ds=Us?()=>{}:(e,t)=>{let n=new pr;if(!t.check(e,n))throw G(`Expected value to be of type ${t.constructor.name}.
${n.toString()}`)},xr=class{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:De(t),h:n}),this}else(t){return this.if(gn,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 G("Unhandled pattern")}}},uc=e=>new xr(e),Fs=uc(gn).if(Ms,(e,t)=>sn(t,Hn,Nt)).if(Rs,(e,t)=>Ts(t)).if(lc,(e,t)=>ur(t)).if(cc,(e,t)=>BigInt(sn(t,Hn,Nt))).if(pn,(e,t)=>Xt(t,on(t,e.shape))).if(Yo,(e,t)=>{let n={};for(let r in e.shape){let s=e.shape[r];if(Po.check(s)){if(ur(t))continue;s=s.shape}n[r]=Fs(s,t)}return n}).if(tc,(e,t)=>{let n=[],r=dr(t,0,42);for(let s=0;s<r;s++)n.push(Xt(t,e.shape));return n}).if(vs,(e,t)=>on(t,e.shape)).if(ac,(e,t)=>null).if(sc,(e,t)=>{let n=Xt(t,e.res);return()=>n}).if(oc,(e,t)=>Xt(t,on(t,[Kt,Wt,xn,$s,br,yn,Ns(Kt),Vs(Zt("a","b","c"),Kt)]))).if(Zo,(e,t)=>{let n={},r=sn(t,0,3);for(let s=0;s<r;s++){let i=Xt(t,e.shape.keys),o=Xt(t,e.shape.values);n[i]=o}return n}).done(),Xt=(e,t)=>Fs(De(t),e);var At=typeof document<"u"?document:{};var Ua=I(e=>e.nodeType===mc);var Ca=typeof DOMParser<"u"?new DOMParser:null;var Aa=I(e=>e.nodeType===fc);var Ia=I(e=>e.nodeType===pc);var js=e=>Wr(e,(t,n)=>`${n}:${t};`).join("");var fc=At.ELEMENT_NODE,pc=At.TEXT_NODE,Ta=At.CDATA_SECTION_NODE,Da=At.COMMENT_NODE,gc=At.DOCUMENT_NODE,va=At.DOCUMENT_TYPE_NODE,mc=At.DOCUMENT_FRAGMENT_NODE,Oa=I(e=>e.nodeType===gc);var qs=JSON.stringify;var bn=e=>class{constructor(n){this._=n}destroy(){e(this._)}},xc=bn(clearTimeout),Na=(e,t)=>new xc(setTimeout(t,e)),La=bn(clearInterval);var Ba=bn(e=>typeof requestAnimationFrame<"u"&&cancelAnimationFrame(e));var Ma=bn(e=>typeof cancelIdleCallback<"u"&&cancelIdleCallback(e));var tt=Symbol;var ve=tt(),Oe=tt(),kn=tt(),Sr=tt(),Sn=tt(),Ve=tt(),_n=tt(),It=tt(),En=tt(),Hs=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r<e.length;r++){let s=e[r];if(s===void 0)break;if(s.constructor===String||s.constructor===Number)t.push(s);else if(s.constructor===Object)break}for(r>0&&n.push(t.join(""));r<e.length;r++){let s=e[r];s instanceof Symbol||n.push(s)}return n},Gs=[Sn,_n,It,kn],kr=0,zs=Se(),Js=(e,t)=>{let n=Gs[kr],r=Ct("log"),s=r!==null&&(r==="*"||r==="true"||new RegExp(r,"gi").test(t));return kr=(kr+1)%Gs.length,t+=": ",s?(...i)=>{i.length===1&&i[0]?.constructor===Function&&(i=i[0]());let o=Se(),c=o-zs;zs=o,e(n,t,En,...i.map(l=>{switch(l!=null&&l.constructor===Uint8Array&&(l=Array.from(l)),typeof l){case"string":case"symbol":return l;default:return qs(l)}}),n," +"+c+"ms")}:Ss};var Sc={[ve]:Q("font-weight","bold"),[Oe]:Q("font-weight","normal"),[kn]:Q("color","blue"),[Sn]:Q("color","green"),[Sr]:Q("color","grey"),[Ve]:Q("color","red"),[_n]:Q("color","purple"),[It]:Q("color","orange"),[En]:Q("color","black")},_c=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=_(),s=[],i=0;for(;i<e.length;i++){let o=e[i],c=Sc[o];if(c!==void 0)r.set(c.left,c.right);else{if(o===void 0)break;if(o.constructor===String||o.constructor===Number){let l=js(r);i>0||l.length>0?(t.push("%c"+o),n.push(l)):t.push(o)}else break}}for(i>0&&(s=n,s.unshift(t.join("")));i<e.length;i++){let o=e[i];o instanceof Symbol||s.push(o)}return s},Xs=Cs?_c:Hs,Ne=(...e)=>{console.log(...Xs(e)),Ps.forEach(t=>t.print(e))},_r=(...e)=>{console.warn(...Xs(e)),e.unshift(It),Ps.forEach(t=>t.print(e))};var Ps=W();var Ga=e=>Js(Ne,e);var Ks=e=>({[Symbol.iterator](){return this},next:e}),Ys=(e,t)=>Ks(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),Un=(e,t)=>Ks(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}});var Qs=class extends Ot{constructor(t,n){super(),this.doc=t,this.awareness=n}},ee=class{constructor(t,n){this.clock=t,this.len=n}},wt=class{constructor(){this.clients=new Map}},ne=(e,t,n)=>t.clients.forEach((r,s)=>{let i=e.doc.store.clients.get(s);if(i!=null){let o=i[i.length-1],c=o.id.clock+o.length;for(let l=0,h=r[l];l<r.length&&h.clock<c;h=r[++l])Ai(e,i,h.clock,h.len,n)}}),Ic=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let s=O((n+r)/2),i=e[s],o=i.clock;if(o<=t){if(t<o+i.len)return s;n=s+1}else r=s-1}return null},de=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&Ic(n,t.clock)!==null},$r=e=>{e.clients.forEach(t=>{t.sort((s,i)=>s.clock-i.clock);let n,r;for(n=1,r=1;n<t.length;n++){let s=t[r-1],i=t[n];s.clock+s.len>=i.clock?t[r-1]=new ee(s.clock,it(s.len,i.clock+i.len-s.clock)):(r<n&&(t[r]=i),r++)}t.length=r})},re=e=>{let t=new wt;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,s)=>{if(!t.clients.has(s)){let i=r.slice();for(let o=n+1;o<e.length;o++)Qr(i,e[o].clients.get(s)||[]);t.clients.set(s,i)}});return $r(t),t},Be=(e,t,n,r)=>{L(e.clients,t,()=>[]).push(new ee(n,r))},Fr=()=>new wt,yi=e=>{let t=Fr();return e.clients.forEach((n,r)=>{let s=[];for(let i=0;i<n.length;i++){let o=n[i];if(o.deleted){let c=o.id.clock,l=o.length;if(i+1<n.length)for(let h=n[i+1];i+1<n.length&&h.deleted;h=n[++i+1])l+=h.length;s.push(new ee(c,l))}}s.length>0&&t.clients.set(r,s)}),t},et=(e,t)=>{g(e.restEncoder,t.clients.size),P(t.clients.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{e.resetDsCurVal(),g(e.restEncoder,n);let s=r.length;g(e.restEncoder,s);for(let i=0;i<s;i++){let o=r[i];e.writeDsClock(o.clock),e.writeDsLen(o.len)}})},ot=e=>{let t=new wt,n=w(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();let s=w(e.restDecoder),i=w(e.restDecoder);if(i>0){let o=L(t.clients,s,()=>[]);for(let c=0;c<i;c++)o.push(new ee(e.readDsClock(),e.readDsLen()))}}return t},ti=(e,t,n)=>{let r=new wt,s=w(e.restDecoder);for(let i=0;i<s;i++){e.resetDsCurVal();let o=w(e.restDecoder),c=w(e.restDecoder),l=n.clients.get(o)||[],h=E(n,o);for(let a=0;a<c;a++){let u=e.readDsClock(),d=u+e.readDsLen();if(u<h){h<d&&Be(r,o,h,d-h);let f=K(l,u),p=l[f];for(!p.deleted&&p.id.clock<u&&(l.splice(f+1,0,Fn(t,p,u-p.id.clock)),f++);f<l.length&&(p=l[f++],p.id.clock<d);)p.deleted||(d<p.id.clock+p.length&&l.splice(f,0,Fn(t,p,d-p.id.clock)),p.delete(t))}else Be(r,o,u,d-u)}}if(r.clients.size>0){let i=new X;return g(i.restEncoder,0),et(i,r),i.toUint8Array()}return null},Tc=(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 i=0;i<r.length;i++){let o=r[i],c=s[i];if(o.clock!==c.clock||o.len!==c.len)return!1}}return!0},xi=Qn,Tt=class e extends Ot{constructor({guid:t=ps(),collectionid:n=null,gc:r=!0,gcFilter:s=()=>!0,meta:i=null,autoLoad:o=!1,shouldLoad:c=!0}={}){super(),this.gc=r,this.gcFilter=s,this.clientID=xi(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new Nn,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=o,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=tr(h=>{this.on("load",()=>{this.isLoaded=!0,h(this)})});let l=()=>tr(h=>{let a=u=>{(u===void 0||u===!0)&&(this.off("sync",a),h())};this.on("sync",a)});this.on("sync",h=>{h===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=h===void 0||h===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){let t=this._item;t!==null&&!this.shouldLoad&&x(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(P(this.subdocs).map(t=>t.guid))}transact(t,n=null){return x(this,t,n)}get(t,n=C){let r=L(this.share,t,()=>{let i=new n;return i._integrate(this,null),i}),s=r.constructor;if(n!==C&&s!==n)if(s===C){let i=new n;i._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=i}),i._start=r._start;for(let o=i._start;o!==null;o=o.right)o.parent=i;return i._length=r._length,this.share.set(t,i),i._integrate(this,null),i}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return r}getArray(t=""){return this.get(t,oe)}getText(t=""){return this.get(t,qe)}getMap(t=""){return this.get(t,ce)}getXmlElement(t=""){return this.get(t,ae)}getXmlFragment(t=""){return this.get(t,le)}toJSON(){let t={};return this.share.forEach((n,r)=>{t[r]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,P(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,x(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()}},Dt=class{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return w(this.restDecoder)}readDsLen(){return w(this.restDecoder)}},H=class extends Dt{readLeftID(){return m(w(this.restDecoder),w(this.restDecoder))}readRightID(){return m(w(this.restDecoder),w(this.restDecoder))}readClient(){return w(this.restDecoder)}readInfo(){return _t(this.restDecoder)}readString(){return dt(this.restDecoder)}readParentInfo(){return w(this.restDecoder)===1}readTypeRef(){return w(this.restDecoder)}readLen(){return w(this.restDecoder)}readAny(){return Gt(this.restDecoder)}readBuf(){return Is(j(this.restDecoder))}readJSON(){return JSON.parse(dt(this.restDecoder))}readKey(){return dt(this.restDecoder)}},vn=class{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=w(this.restDecoder),this.dsCurrVal}readDsLen(){let t=w(this.restDecoder)+1;return this.dsCurrVal+=t,t}},q=class extends vn{constructor(t){super(t),this.keys=[],w(t),this.keyClockDecoder=new zt(j(t)),this.clientDecoder=new Et(j(t)),this.leftClockDecoder=new zt(j(t)),this.rightClockDecoder=new zt(j(t)),this.infoDecoder=new be(j(t),_t),this.stringDecoder=new tn(j(t)),this.parentInfoDecoder=new be(j(t),_t),this.typeRefDecoder=new Et(j(t)),this.lenDecoder=new Et(j(t))}readLeftID(){return new mt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new mt(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 Gt(this.restDecoder)}readBuf(){return j(this.restDecoder)}readJSON(){return Gt(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}}},yt=class{constructor(){this.restEncoder=ut()}toUint8Array(){return $(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){g(this.restEncoder,t)}writeDsLen(t){g(this.restEncoder,t)}},ct=class extends yt{writeLeftID(t){g(this.restEncoder,t.client),g(this.restEncoder,t.clock)}writeRightID(t){g(this.restEncoder,t.client),g(this.restEncoder,t.clock)}writeClient(t){g(this.restEncoder,t)}writeInfo(t){Ft(this.restEncoder,t)}writeString(t){lt(this.restEncoder,t)}writeParentInfo(t){g(this.restEncoder,t?1:0)}writeTypeRef(t){g(this.restEncoder,t)}writeLen(t){g(this.restEncoder,t)}writeAny(t){at(this.restEncoder,t)}writeBuf(t){F(this.restEncoder,t)}writeJSON(t){lt(this.restEncoder,JSON.stringify(t))}writeKey(t){lt(this.restEncoder,t)}},se=class{constructor(){this.restEncoder=ut(),this.dsCurrVal=0}toUint8Array(){return $(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){let n=t-this.dsCurrVal;this.dsCurrVal=t,g(this.restEncoder,n)}writeDsLen(t){t===0&&D(),g(this.restEncoder,t-1),this.dsCurrVal+=t}},X=class extends se{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new $t,this.clientEncoder=new St,this.leftClockEncoder=new $t,this.rightClockEncoder=new $t,this.infoEncoder=new ye(Ft),this.stringEncoder=new Qe,this.parentInfoEncoder=new ye(Ft),this.typeRefEncoder=new St,this.lenEncoder=new St}toUint8Array(){let t=ut();return g(t,0),F(t,this.keyClockEncoder.toUint8Array()),F(t,this.clientEncoder.toUint8Array()),F(t,this.leftClockEncoder.toUint8Array()),F(t,this.rightClockEncoder.toUint8Array()),F(t,$(this.infoEncoder)),F(t,this.stringEncoder.toUint8Array()),F(t,$(this.parentInfoEncoder)),F(t,this.typeRefEncoder.toUint8Array()),F(t,this.lenEncoder.toUint8Array()),jt(t,$(this.restEncoder)),$(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){at(this.restEncoder,t)}writeBuf(t){F(this.restEncoder,t)}writeJSON(t){at(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)}},Dc=(e,t,n,r)=>{r=it(r,t[0].id.clock);let s=K(t,r);g(e.restEncoder,t.length-s),e.writeClient(n),g(e.restEncoder,r);let i=t[s];i.write(e,r-i.id.clock);for(let o=s+1;o<t.length;o++)t[o].write(e,0)},jr=(e,t,n)=>{let r=new Map;n.forEach((s,i)=>{E(t,i)>s&&r.set(i,s)}),He(t).forEach((s,i)=>{n.has(i)||r.set(i,0)}),g(e.restEncoder,r.size),P(r.entries()).sort((s,i)=>i[0]-s[0]).forEach(([s,i])=>{Dc(e,t.clients.get(s),s,i)})},vc=(e,t)=>{let n=_(),r=w(e.restDecoder);for(let s=0;s<r;s++){let i=w(e.restDecoder),o=new Array(i),c=e.readClient(),l=w(e.restDecoder);n.set(c,{i:0,refs:o});for(let h=0;h<i;h++){let a=e.readInfo();switch(31&a){case 0:{let u=e.readLen();o[h]=new R(m(c,l),u),l+=u;break}case 10:{let u=w(e.restDecoder);o[h]=new B(m(c,l),u),l+=u;break}default:{let u=(a&192)===0,d=new b(m(c,l),null,(a&128)===128?e.readLeftID():null,null,(a&64)===64?e.readRightID():null,u?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,u&&(a&32)===32?e.readString():null,Wi(e,a));o[h]=d,l+=d.length}}}}return n},Oc=(e,t,n)=>{let r=[],s=P(n.keys()).sort((f,p)=>f-p);if(s.length===0)return null;let i=()=>{if(s.length===0)return null;let f=n.get(s[s.length-1]);for(;f.refs.length===f.i;)if(s.pop(),s.length>0)f=n.get(s[s.length-1]);else return null;return f},o=i();if(o===null)return null;let c=new Nn,l=new Map,h=(f,p)=>{let y=l.get(f);(y==null||y>p)&&l.set(f,p)},a=o.refs[o.i++],u=new Map,d=()=>{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(k=>k!==p)}r.length=0};for(;;){if(a.constructor!==B){let p=L(u,a.id.client,()=>E(t,a.id.client))-a.id.clock;if(p<0)r.push(a),h(a.id.client,a.id.clock-1),d();else{let y=a.getMissing(e,t);if(y!==null){r.push(a);let k=n.get(y)||{refs:[],i:0};if(k.refs.length===k.i)h(y,E(t,y)),d();else{a=k.refs[k.i++];continue}}else(p===0||p<a.length)&&(a.integrate(e,p),u.set(a.id.client,a.id.clock+a.length))}}if(r.length>0)a=r.pop();else if(o!==null&&o.i<o.refs.length)a=o.refs[o.i++];else{if(o=i(),o===null)break;a=o.refs[o.i++]}}if(c.clients.size>0){let f=new X;return jr(f,c,new Map),g(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},Vc=(e,t)=>jr(e,t.doc.store,t.beforeState),bi=(e,t,n,r=new q(e))=>x(t,s=>{s.local=!1;let i=!1,o=s.doc,c=o.store,l=vc(r,o),h=Oc(s,c,l),a=c.pendingStructs;if(a){for(let[d,f]of a.missing)if(f<E(c,d)){i=!0;break}if(h){for(let[d,f]of h.missing){let p=a.missing.get(d);(p==null||p>f)&&a.missing.set(d,f)}a.update=Ln([a.update,h.update])}}else c.pendingStructs=h;let u=ti(r,s,c);if(c.pendingDs){let d=new q(V(c.pendingDs));w(d.restDecoder);let f=ti(d,s,c);u&&f?c.pendingDs=Ln([u,f]):c.pendingDs=u||f}else c.pendingDs=u;if(i){let d=c.pendingStructs.update;c.pendingStructs=null,qr(s.doc,d)}},n,!1),Xa=(e,t,n)=>bi(e,t,n,new H(e)),qr=(e,t,n,r=q)=>{let s=V(t);bi(s,e,n,new r(s))},Pa=(e,t,n)=>qr(e,t,n,H),Nc=(e,t,n=new Map)=>{jr(e,t.store,n),et(e,yi(t.store))},Lc=(e,t=new Uint8Array([0]),n=new X)=>{let r=Si(t);Nc(n,e,r);let s=[n.toUint8Array()];if(e.store.pendingDs&&s.push(e.store.pendingDs),e.store.pendingStructs&&s.push(vi(e.store.pendingStructs.update,t)),s.length>1){if(n.constructor===ct)return Yc(s.map((i,o)=>o===0?i:tl(i)));if(n.constructor===X)return Ln(s)}return s[0]},Ka=(e,t)=>Lc(e,t,new ct),ki=e=>{let t=new Map,n=w(e.restDecoder);for(let r=0;r<n;r++){let s=w(e.restDecoder),i=w(e.restDecoder);t.set(s,i)}return t},Si=e=>ki(new Dt(V(e))),Gr=(e,t)=>(g(e.restEncoder,t.size),P(t.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{g(e.restEncoder,n),g(e.restEncoder,r)}),e),Bc=(e,t)=>Gr(e,He(t.store)),Mc=(e,t=new se)=>(e instanceof Map?Gr(t,e):Bc(t,e),t.toUint8Array()),Ya=e=>Mc(e,new yt),Ur=class{constructor(){this.l=[]}},ei=()=>new Ur,ni=(e,t)=>e.l.push(t),ri=(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.")},_i=(e,t,n)=>Ce(e.l,[t,n]),mt=class{constructor(t,n){this.client=t,this.clock=n}},Qt=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,m=(e,t)=>new mt(e,t),si=(e,t)=>{g(e,t.client),g(e,t.clock)},ii=e=>m(w(e),w(e)),Ei=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw D()},On=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},Wa=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))},oi=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=(i,o)=>{let c=i.get("ds"),l=i.get("ids"),h=a=>this.clients.set(a,o);c.observe(a=>{a.changes.added.forEach(u=>{u.content.getContent().forEach(d=>{d instanceof Uint8Array&&this.dss.set(o,re([this.dss.get(o)||Fr(),ot(new Dt(V(d)))]))})})}),this.dss.set(o,re(c.map(a=>ot(new Dt(V(a)))))),l.observe(a=>a.changes.added.forEach(u=>u.content.getContent().forEach(h))),l.forEach(h)};n.observe(i=>{i.keysChanged.forEach(o=>s(n.get(o),o))}),n.forEach(s)}setUserMapping(t,n,r,{filter:s=()=>!0}={}){let i=this.yusers,o=i.get(r);o||(o=new ce,o.set("ids",new oe),o.set("ds",new oe),i.set(r,o)),o.get("ids").push([n]),i.observe(c=>{setTimeout(()=>{let l=i.get(r);if(l!==o){o=l,this.clients.forEach((u,d)=>{r===u&&o.get("ids").push([d])});let h=new yt,a=this.dss.get(r);a&&(et(h,a),o.get("ds").push([h.toUint8Array()]))}},0)}),t.on("afterTransaction",c=>{setTimeout(()=>{let l=o.get("ds"),h=c.deleteSet;if(c.local&&h.clients.size>0&&s(c,h)){let a=new yt;et(a,h),l.push([a.toUint8Array()])}})})}getUserByClientId(t){return this.clients.get(t)||null}getUserByDeletedId(t){for(let[n,r]of this.dss.entries())if(de(r,t))return n;return null}},Me=class{constructor(t,n,r,s=0){this.type=t,this.tname=n,this.item=r,this.assoc=s}},Za=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},Qa=e=>new Me(e.type==null?null:m(e.type.client,e.type.clock),e.tname??null,e.item==null?null:m(e.item.client,e.item.clock),e.assoc==null?0:e.assoc),Cr=class{constructor(t,n,r=0){this.type=t,this.index=n,this.assoc=r}},Rc=(e,t,n=0)=>new Cr(e,t,n),Cn=(e,t,n)=>{let r=null,s=null;return e._item===null?s=Ei(e):r=m(e._item.id.client,e._item.id.clock),new Me(r,s,t,n)},th=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return Cn(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return Cn(e,m(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return Cn(e,r.lastId,n);r=r.right}return Cn(e,null,n)},$c=(e,t)=>{let{type:n,tname:r,item:s,assoc:i}=t;if(s!==null)g(e,0),si(e,s);else if(r!==null)Ft(e,1),lt(e,r);else if(n!==null)Ft(e,2),si(e,n);else throw D();return xe(e,i),e},eh=e=>{let t=ut();return $c(t,e),$(t)},Fc=e=>{let t=null,n=null,r=null;switch(w(e)){case 0:r=ii(e);break;case 1:n=dt(e);break;case 2:t=ii(e)}let s=Wn(e)?ke(e):0;return new Me(t,n,r,s)},nh=e=>Fc(V(e)),jc=(e,t)=>{let n=te(e,t),r=t.clock-n.id.clock;return{item:n,diff:r}},rh=(e,t,n=!0)=>{let r=t.store,s=e.item,i=e.type,o=e.tname,c=e.assoc,l=null,h=0;if(s!==null){if(E(r,s.client)<=s.clock)return null;let a=n?Mr(r,s):jc(r,s),u=a.item;if(!(u instanceof b))return null;if(l=u.parent,l._item===null||!l._item.deleted){h=u.deleted||!u.countable?0:a.diff+(c>=0?0:1);let d=u.left;for(;d!==null;)!d.deleted&&d.countable&&(h+=d.length),d=d.left}}else{if(o!==null)l=t.get(o);else if(i!==null){if(E(r,i.client)<=i.clock)return null;let{item:a}=n?Mr(r,i):{item:te(r,i)};if(a instanceof b&&a.content instanceof Y)l=a.content.type;else return null}else throw D();c>=0?h=l._length:h=0}return Rc(l,h,e.assoc)},sh=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&Qt(e.item,t.item)&&Qt(e.type,t.type)&&e.assoc===t.assoc,Vn=class{constructor(t,n){this.ds=t,this.sv=n}},ih=(e,t)=>{let n=e.ds.clients,r=t.ds.clients,s=e.sv,i=t.sv;if(s.size!==i.size||n.size!==r.size)return!1;for(let[o,c]of s.entries())if(i.get(o)!==c)return!1;for(let[o,c]of n.entries()){let l=r.get(o)||[];if(c.length!==l.length)return!1;for(let h=0;h<c.length;h++){let a=c[h],u=l[h];if(a.clock!==u.clock||a.len!==u.len)return!1}}return!0},qc=(e,t=new se)=>(et(t,e.ds),Gr(t,e.sv),t.toUint8Array()),oh=e=>qc(e,new yt),Gc=(e,t=new vn(V(e)))=>new Vn(ot(t),ki(t)),ch=e=>Gc(e,new Dt(V(e))),Ui=(e,t)=>new Vn(e,t),lh=Ui(Fr(),new Map),ah=e=>Ui(yi(e.store),He(e.store)),ft=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!de(t.ds,e.id),Ar=(e,t)=>{let n=L(e.meta,Ar,W),r=e.doc.store;n.has(t)||(t.sv.forEach((s,i)=>{s<E(r,i)&&M(e,m(i,s))}),ne(e,t.ds,s=>{}),n.add(t))},hh=(e,t,n=new Tt)=>{if(e.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:s}=t,i=new X;return e.transact(o=>{let c=0;r.forEach(l=>{l>0&&c++}),g(i.restEncoder,c);for(let[l,h]of r){if(h===0)continue;h<E(e.store,l)&&M(o,m(l,h));let a=e.store.clients.get(l)||[],u=K(a,h-1);g(i.restEncoder,u+1),i.writeClient(l),g(i.restEncoder,0);for(let d=0;d<=u;d++)a[d].write(i,0)}et(i,s)}),qr(n,i.toUint8Array(),"snapshot"),n},zc=(e,t,n=q)=>{let r=new n(V(t)),s=new nt(r,!1);for(let o=s.curr;o!==null;o=s.next())if((e.sv.get(o.id.client)||0)<o.id.clock+o.length)return!1;let i=re([e.ds,ot(r)]);return Tc(e.ds,i)},uh=(e,t)=>zc(e,t,H),Nn=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},He=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},Ci=(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 D()}n.push(t)},K=(e,t)=>{let n=0,r=e.length-1,s=e[r],i=s.id.clock;if(i===t)return r;let o=O(t/(i+s.length-1)*r);for(;n<=r;){if(s=e[o],i=s.id.clock,i<=t){if(t<i+s.length)return o;n=o+1}else r=o-1;o=O((n+r)/2)}throw D()},Hc=(e,t)=>{let n=e.clients.get(t.client);return n[K(n,t.clock)]},te=Hc,Ir=(e,t,n)=>{let r=K(t,n),s=t[r];return s.id.clock<n&&s instanceof b?(t.splice(r+1,0,Fn(e,s,n-s.id.clock)),r+1):r},M=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[Ir(e,n,t.clock)]},ci=(e,t,n)=>{let r=t.clients.get(n.client),s=K(r,n.clock),i=r[s];return n.clock!==i.id.clock+i.length-1&&i.constructor!==R&&r.splice(s+1,0,Fn(e,i,n.clock-i.id.clock+1)),i},Jc=(e,t,n)=>{let r=e.clients.get(t.id.client);r[K(r,t.id.clock)]=n},Ai=(e,t,n,r,s)=>{if(r===0)return;let i=n+r,o=Ir(e,t,n),c;do c=t[o++],i<c.id.clock+c.length&&Ir(e,t,i),s(c);while(o<t.length&&t[o].id.clock<i)},Tr=class{constructor(t,n,r){this.doc=t,this.deleteSet=new wt,this.beforeState=He(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}},li=(e,t)=>t.deleteSet.clients.size===0&&!Zr(t.afterState,(n,r)=>t.beforeState.get(r)!==n)?!1:($r(t.deleteSet),Vc(e,t),et(e,t.deleteSet),!0),ai=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&L(e.changed,t,W).add(n)},Tn=(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 b&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}let i=t-s;return i&&e.splice(t+1-i,i),i},Ii=(e,t,n)=>{for(let[r,s]of e.clients.entries()){let i=t.clients.get(r);for(let o=s.length-1;o>=0;o--){let c=s[o],l=c.clock+c.len;for(let h=K(i,c.clock),a=i[h];h<i.length&&a.id.clock<l;a=i[++h]){let u=i[h];if(c.clock+c.len<=u.id.clock)break;u instanceof b&&u.deleted&&!u.keep&&n(u)&&u.gc(t,!1)}}}},Ti=(e,t)=>{e.clients.forEach((n,r)=>{let s=t.clients.get(r);for(let i=n.length-1;i>=0;i--){let o=n[i],c=Ye(s.length-1,1+K(s,o.clock+o.len-1));for(let l=c,h=s[l];l>0&&h.id.clock>=o.clock;h=s[l])l-=1+Tn(s,l)}})},dh=(e,t,n)=>{Ii(e,t,n),Ti(e,t)},Di=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,s=r.store,i=n.deleteSet,o=n._mergeStructs;try{$r(i),n.afterState=He(n.doc.store),r.emit("beforeObserverCalls",[n,r]);let c=[];n.changed.forEach((l,h)=>c.push(()=>{(h._item===null||!h._item.deleted)&&h._callObserver(n,l)})),c.push(()=>{n.changedParentTypes.forEach((l,h)=>{h._dEH.l.length>0&&(h._item===null||!h._item.deleted)&&(l=l.filter(a=>a.target._item===null||!a.target._item.deleted),l.forEach(a=>{a.currentTarget=h,a._path=null}),l.sort((a,u)=>a.path.length-u.path.length),c.push(()=>{_i(h._dEH,l,n)}))}),c.push(()=>r.emit("afterTransaction",[n,r])),c.push(()=>{n._needFormattingCleanup&&ul(n)})}),Ce(c,[])}finally{r.gc&&Ii(i,s,r.gcFilter),Ti(i,s),n.afterState.forEach((a,u)=>{let d=n.beforeState.get(u)||0;if(d!==a){let f=s.clients.get(u),p=it(K(f,d),1);for(let y=f.length-1;y>=p;)y-=1+Tn(f,y)}});for(let a=o.length-1;a>=0;a--){let{client:u,clock:d}=o[a].id,f=s.clients.get(u),p=K(f,d);p+1<f.length&&Tn(f,p+1)>1||p>0&&Tn(f,p)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(Ne(It,ve,"[yjs] ",Oe,Ve,"Changed the client-id because another client seems to be using it."),r.clientID=xi()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){let a=new ct;li(a,n)&&r.emit("update",[a.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){let a=new X;li(a,n)&&r.emit("updateV2",[a.toUint8Array(),n.origin,r,n])}let{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:h}=n;(c.size>0||h.size>0||l.size>0)&&(c.forEach(a=>{a.clientID=r.clientID,a.collectionid==null&&(a.collectionid=r.collectionid),r.subdocs.add(a)}),h.forEach(a=>r.subdocs.delete(a)),r.emit("subdocs",[{loaded:l,added:c,removed:h},r,n]),h.forEach(a=>a.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,e])):Di(e,t+1)}}},x=(e,t,n=null,r=!0)=>{let s=e._transactionCleanups,i=!1,o=null;e._transaction===null&&(i=!0,e._transaction=new Tr(e,n,r),s.push(e._transaction),s.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(i){let c=e._transaction===s[0];e._transaction=null,c&&Di(s,0)}}return o},Dr=class{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}},hi=(e,t,n)=>{ne(e,n.deletions,r=>{r instanceof b&&t.scope.some(s=>s===e.doc||On(s,r))&&Pr(r,!1)})},ui=(e,t,n)=>{let r=null,s=e.doc,i=e.scope;x(s,c=>{for(;t.length>0&&e.currStackItem===null;){let l=s.store,h=t.pop(),a=new Set,u=[],d=!1;ne(c,h.insertions,f=>{if(f instanceof b){if(f.redone!==null){let{item:p,diff:y}=Mr(l,f.id);y>0&&(p=M(c,m(p.id.client,p.id.clock+y))),f=p}!f.deleted&&i.some(p=>p===c.doc||On(p,f))&&u.push(f)}}),ne(c,h.deletions,f=>{f instanceof b&&i.some(p=>p===c.doc||On(p,f))&&!de(h.insertions,f.id)&&a.add(f)}),a.forEach(f=>{d=Yi(c,f,a,h.insertions,e.ignoreRemoteMapChanges,e)!==null||d});for(let f=u.length-1;f>=0;f--){let p=u[f];e.deleteFilter(p)&&(p.delete(c),d=!0)}e.currStackItem=d?h:null}c.changed.forEach((l,h)=>{l.has(null)&&h._searchMarker&&(h._searchMarker.length=0)}),r=c},e);let o=e.currStackItem;if(o!=null){let c=r.changedParentTypes;e.emit("stack-item-popped",[{stackItem:o,type:n,changedParentTypes:c,origin:e},e]),e.currStackItem=null}return o},di=class extends Ot{constructor(t,{captureTimeout:n=500,captureTransaction:r=l=>!0,deleteFilter:s=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:c=st(t)?t[0].doc:t instanceof Tt?t:t.doc}={}){super(),this.scope=[],this.doc=c,this.addToScope(t),this.deleteFilter=s,i.add(this),this.trackedOrigins=i,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=n,this.afterTransactionHandler=l=>{if(!this.captureTransaction(l)||!this.scope.some(k=>l.changedParentTypes.has(k)||k===this.doc)||!this.trackedOrigins.has(l.origin)&&(!l.origin||!this.trackedOrigins.has(l.origin.constructor)))return;let h=this.undoing,a=this.redoing,u=h?this.redoStack:this.undoStack;h?this.stopCapturing():a||this.clear(!1,!0);let d=new wt;l.afterState.forEach((k,S)=>{let Kr=l.beforeState.get(S)||0,Yr=k-Kr;Yr>0&&Be(d,S,Kr,Yr)});let f=Se(),p=!1;if(this.lastChange>0&&f-this.lastChange<this.captureTimeout&&u.length>0&&!h&&!a){let k=u[u.length-1];k.deletions=re([k.deletions,l.deleteSet]),k.insertions=re([k.insertions,d])}else u.push(new Dr(l.deleteSet,d)),p=!0;!h&&!a&&(this.lastChange=f),ne(l,l.deleteSet,k=>{k instanceof b&&this.scope.some(S=>S===l.doc||On(S,k))&&Pr(k,!0)});let y=[{stackItem:u[u.length-1],origin:l.origin,type:h?"redo":"undo",changedParentTypes:l.changedParentTypes},this];p?this.emit("stack-item-added",y):this.emit("stack-item-updated",y)},this.destroy=this.destroy.bind(this),this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",this.destroy)}addToScope(t){let n=new Set(this.scope);t=st(t)?t:[t],t.forEach(r=>{n.has(r)||(n.add(r),(r instanceof C?r.doc!==this.doc:r!==this.doc)&&_r("[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=>hi(r,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>hi(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=ui(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=ui(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),this.doc.off("destroy",this.destroy),super.destroy()}};function*Xc(e){let t=w(e.restDecoder);for(let n=0;n<t;n++){let r=w(e.restDecoder),s=e.readClient(),i=w(e.restDecoder);for(let o=0;o<r;o++){let c=e.readInfo();if(c===10){let l=w(e.restDecoder);yield new B(m(s,i),l),i+=l}else if((31&c)!==0){let l=(c&192)===0,h=new b(m(s,i),null,(c&128)===128?e.readLeftID():null,null,(c&64)===64?e.readRightID():null,l?e.readParentInfo()?e.readString():e.readLeftID():null,l&&(c&32)===32?e.readString():null,Wi(e,c));yield h,i+=h.length}else{let l=e.readLen();yield new R(m(s,i),l),i+=l}}}}var nt=class{constructor(t,n){this.gen=Xc(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===B);return this.curr}},fh=e=>Pc(e,H),Pc=(e,t=q)=>{let n=[],r=new t(V(e)),s=new nt(r,!1);for(let o=s.curr;o!==null;o=s.next())n.push(o);Ne("Structs: ",n);let i=ot(r);Ne("DeleteSet: ",i)},ph=e=>Kc(e,H),Kc=(e,t=q)=>{let n=[],r=new t(V(e)),s=new nt(r,!1);for(let i=s.curr;i!==null;i=s.next())n.push(i);return{structs:n,ds:ot(r)}},Re=class{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}},Yc=e=>Ln(e,H,ct),Wc=(e,t=se,n=q)=>{let r=new t,s=new nt(new n(V(e)),!1),i=s.curr;if(i!==null){let o=0,c=i.id.client,l=i.id.clock!==0,h=l?0:i.id.clock+i.length;for(;i!==null;i=s.next())c!==i.id.client&&(h!==0&&(o++,g(r.restEncoder,c),g(r.restEncoder,h)),c=i.id.client,h=0,l=i.id.clock!==0),i.constructor===B&&(l=!0),l||(h=i.id.clock+i.length);h!==0&&(o++,g(r.restEncoder,c),g(r.restEncoder,h));let a=ut();return g(a,o),as(a,r.restEncoder),r.restEncoder=a,r.toUint8Array()}else return g(r.restEncoder,0),r.toUint8Array()},gh=e=>Wc(e,yt,H),Zc=(e,t=q)=>{let n=new Map,r=new Map,s=new nt(new t(V(e)),!1),i=s.curr;if(i!==null){let o=i.id.client,c=i.id.clock;for(n.set(o,c);i!==null;i=s.next())o!==i.id.client&&(r.set(o,c),n.set(i.id.client,i.id.clock),o=i.id.client),c=i.id.clock+i.length;r.set(o,c)}return{from:n,to:r}},mh=e=>Zc(e,H),Qc=(e,t)=>{if(e.constructor===R){let{client:n,clock:r}=e.id;return new R(m(n,r+t),e.length-t)}else if(e.constructor===B){let{client:n,clock:r}=e.id;return new B(m(n,r+t),e.length-t)}else{let n=e,{client:r,clock:s}=n.id;return new b(m(r,s+t),null,m(r,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Ln=(e,t=q,n=X)=>{if(e.length===1)return e[0];let r=e.map(a=>new t(V(a))),s=r.map(a=>new nt(a,!0)),i=null,o=new n,c=new Re(o);for(;s=s.filter(d=>d.curr!==null),s.sort((d,f)=>{if(d.curr.id.client===f.curr.id.client){let p=d.curr.id.clock-f.curr.id.clock;return p===0?d.curr.constructor===f.curr.constructor?0:d.curr.constructor===B?1:-1:p}else return f.curr.id.client-d.curr.id.client}),s.length!==0;){let a=s[0],u=a.curr.id.client;if(i!==null){let d=a.curr,f=!1;for(;d!==null&&d.id.clock+d.length<=i.struct.id.clock+i.struct.length&&d.id.client>=i.struct.id.client;)d=a.next(),f=!0;if(d===null||d.id.client!==u||f&&d.id.clock>i.struct.id.clock+i.struct.length)continue;if(u!==i.struct.id.client)pt(c,i.struct,i.offset),i={struct:d,offset:0},a.next();else if(i.struct.id.clock+i.struct.length<d.id.clock)if(i.struct.constructor===B)i.struct.length=d.id.clock+d.length-i.struct.id.clock;else{pt(c,i.struct,i.offset);let p=d.id.clock-i.struct.id.clock-i.struct.length;i={struct:new B(m(u,i.struct.id.clock+i.struct.length),p),offset:0}}else{let p=i.struct.id.clock+i.struct.length-d.id.clock;p>0&&(i.struct.constructor===B?i.struct.length-=p:d=Qc(d,p)),i.struct.mergeWith(d)||(pt(c,i.struct,i.offset),i={struct:d,offset:0},a.next())}}else i={struct:a.curr,offset:0},a.next();for(let d=a.curr;d!==null&&d.id.client===u&&d.id.clock===i.struct.id.clock+i.struct.length&&d.constructor!==B;d=a.next())pt(c,i.struct,i.offset),i={struct:d,offset:0}}i!==null&&(pt(c,i.struct,i.offset),i=null),zr(c);let l=r.map(a=>ot(a)),h=re(l);return et(o,h),o.toUint8Array()},vi=(e,t,n=q,r=X)=>{let s=Si(t),i=new r,o=new Re(i),c=new n(V(e)),l=new nt(c,!1);for(;l.curr;){let a=l.curr,u=a.id.client,d=s.get(u)||0;if(l.curr.constructor===B){l.next();continue}if(a.id.clock+a.length>d)for(pt(o,a,it(d-a.id.clock,0)),l.next();l.curr&&l.curr.id.client===u;)pt(o,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===u&&l.curr.id.clock+l.curr.length<=d;)l.next()}zr(o);let h=ot(c);return et(i,h),i.toUint8Array()},wh=(e,t)=>vi(e,t,H,ct),Oi=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:$(e.encoder.restEncoder)}),e.encoder.restEncoder=ut(),e.written=0)},pt=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Oi(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),g(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},zr=e=>{Oi(e);let t=e.encoder.restEncoder;g(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];g(t,r.written),jt(t,r.restEncoder)}},jn=(e,t,n,r)=>{let s=new n(V(e)),i=new nt(s,!1),o=new r,c=new Re(o);for(let h=i.curr;h!==null;h=i.next())pt(c,t(h),0);zr(c);let l=ot(s);return et(o,l),o.toUint8Array()},Vi=({formatting:e=!0,subdocs:t=!0,yxml:n=!0}={})=>{let r=0,s=_(),i=_(),o=_(),c=_();return c.set(null,null),l=>{switch(l.constructor){case R:case B:return l;case b:{let h=l,a=h.content;switch(a.constructor){case ze:break;case Y:{if(n){let u=a.type;u instanceof ae&&(u.nodeName=L(i,u.nodeName,()=>"node-"+r)),u instanceof Rn&&(u.hookName=L(i,u.hookName,()=>"hook-"+r))}break}case vt:{let u=a;u.arr=u.arr.map(()=>r);break}case he:{let u=a;u.content=new Uint8Array([r]);break}case ue:{let u=a;t&&(u.opts={},u.doc.guid=r+"");break}case xt:{let u=a;u.embed={};break}case A:{let u=a;e&&(u.key=L(o,u.key,()=>r+""),u.value=L(c,u.value,()=>({i:r})));break}case $n:{let u=a;u.arr=u.arr.map(()=>r);break}case rt:{let u=a;u.str=Ze(r%10+"",u.str.length);break}default:D()}return h.parentSub&&(h.parentSub=L(s,h.parentSub,()=>r+"")),r++,l}default:D()}}},yh=(e,t)=>jn(e,Vi(t),H,ct),xh=(e,t)=>jn(e,Vi(t),q,X),bh=e=>jn(e,lr,H,X),tl=e=>jn(e,lr,q,ct),fi="You must not compute changes after the event-handler fired.",ie=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=el(this.currentTarget,this.target))}deletes(t){return de(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw G(fi);let t=new Map,n=this.target;this.transaction.changed.get(n).forEach(s=>{if(s!==null){let i=n._map.get(s),o,c;if(this.adds(i)){let l=i.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(i))if(l!==null&&this.deletes(l))o="delete",c=Pe(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",c=Pe(l.content.getContent())):(o="add",c=void 0)}else if(this.deletes(i))o="delete",c=Pe(i.content.getContent());else return;t.set(s,{action:o,oldValue:c})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw G(fi);let n=this.target,r=W(),s=W(),i=[];if(t={added:r,deleted:s,delta:i,keys:this.keys},this.transaction.changed.get(n).has(null)){let c=null,l=()=>{c&&i.push(c)};for(let h=n._start;h!==null;h=h.right)h.deleted?this.deletes(h)&&!this.adds(h)&&((c===null||c.delete===void 0)&&(l(),c={delete:0}),c.delete+=h.length,s.add(h)):this.adds(h)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(h.content.getContent()),r.add(h)):((c===null||c.retain===void 0)&&(l(),c={retain:0}),c.retain+=h.length);c!==null&&c.retain===void 0&&l()}this._changes=t}return t}},el=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let r=0,s=t._item.parent._start;for(;s!==t._item&&s!==null;)!s.deleted&&s.countable&&(r+=s.length),s=s.right;n.unshift(r)}t=t._item.parent}return n},N=()=>{_r("Invalid access: Add Yjs type to a document before reading data.")},Ni=80,Hr=0,vr=class{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=Hr++}},nl=e=>{e.timestamp=Hr++},Li=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Hr++},rl=(e,t,n)=>{if(e.length>=Ni){let r=e.reduce((s,i)=>s.timestamp<i.timestamp?s:i);return Li(r,t,n),r}else{let r=new vr(t,n);return e.push(r),r}},qn=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((i,o)=>bt(t-i.index)<bt(t-o.index)?i:o),r=e._start,s=0;for(n!==null&&(r=n.p,s=n.index,nl(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&&bt(n.index-s)<r.parent.length/Ni?(Li(n,r,s),n):rl(e._searchMarker,r,s)},$e=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){let s=e[r];if(n>0){let i=s.p;for(i.marker=!1;i&&(i.deleted||!i.countable);)i=i.left,i&&!i.deleted&&i.countable&&(s.index-=i.length);if(i===null||i.marker===!0){e.splice(r,1);continue}s.p=i,i.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=it(t,s.index+n))}},kh=e=>{e.doc??N();let t=e._start,n=[];for(;t;)n.push(t),t=t.right;return n},Gn=(e,t,n)=>{let r=e,s=t.changedParentTypes;for(;L(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;_i(r._eH,n,t)},C=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ei(),this._dEH=ei(),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){ni(this._eH,t)}observeDeep(t){ni(this._dEH,t)}unobserve(t){ri(this._eH,t)}unobserveDeep(t){ri(this._dEH,t)}toJSON(){}},Bi=(e,t,n)=>{e.doc??N(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,s=[],i=e._start;for(;i!==null&&r>0;){if(i.countable&&!i.deleted){let o=i.content.getContent();if(o.length<=t)t-=o.length;else{for(let c=t;c<o.length&&r>0;c++)s.push(o[c]),r--;t=0}}i=i.right}return s},Mi=e=>{e.doc??N();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let r=n.content.getContent();for(let s=0;s<r.length;s++)t.push(r[s])}n=n.right}return t},Sh=(e,t)=>{let n=[],r=e._start;for(;r!==null;){if(r.countable&&ft(r,t)){let s=r.content.getContent();for(let i=0;i<s.length;i++)n.push(s[i])}r=r.right}return n},Fe=(e,t)=>{let n=0,r=e._start;for(e.doc??N();r!==null;){if(r.countable&&!r.deleted){let s=r.content.getContent();for(let i=0;i<s.length;i++)t(s[i],n++,e)}r=r.right}},Ri=(e,t)=>{let n=[];return Fe(e,(r,s)=>{n.push(t(r,s,e))}),n},sl=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}}}},$i=(e,t)=>{e.doc??N();let n=qn(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}},Bn=(e,t,n,r)=>{let s=n,i=e.doc,o=i.clientID,c=i.store,l=n===null?t._start:n.right,h=[],a=()=>{h.length>0&&(s=new b(m(o,E(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new vt(h)),s.integrate(e,0),h=[])};r.forEach(u=>{if(u===null)h.push(u);else switch(u.constructor){case Number:case Object:case Boolean:case Array:case String:h.push(u);break;default:switch(a(),u.constructor){case Uint8Array:case ArrayBuffer:s=new b(m(o,E(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new he(new Uint8Array(u))),s.integrate(e,0);break;case Tt:s=new b(m(o,E(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new ue(u)),s.integrate(e,0);break;default:if(u instanceof C)s=new b(m(o,E(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new Y(u)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),a()},Fi=()=>G("Length exceeded!"),ji=(e,t,n,r)=>{if(n>t._length)throw Fi();if(n===0)return t._searchMarker&&$e(t._searchMarker,n,r.length),Bn(e,t,null,r);let s=n,i=qn(t,n),o=t._start;for(i!==null&&(o=i.p,n-=i.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&M(e,m(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&$e(t._searchMarker,s,r.length),Bn(e,t,o,r)},il=(e,t,n)=>{let s=(t._searchMarker||[]).reduce((i,o)=>o.index>i.index?o:i,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return Bn(e,t,s,n)},qi=(e,t,n,r)=>{if(r===0)return;let s=n,i=r,o=qn(t,n),c=t._start;for(o!==null&&(c=o.p,n-=o.index);c!==null&&n>0;c=c.right)!c.deleted&&c.countable&&(n<c.length&&M(e,m(c.id.client,c.id.clock+n)),n-=c.length);for(;r>0&&c!==null;)c.deleted||(r<c.length&&M(e,m(c.id.client,c.id.clock+r)),c.delete(e),r-=c.length),c=c.right;if(r>0)throw Fi();t._searchMarker&&$e(t._searchMarker,s,-i+r)},Mn=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},Jr=(e,t,n,r)=>{let s=t._map.get(n)||null,i=e.doc,o=i.clientID,c;if(r==null)c=new vt([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:c=new vt([r]);break;case Uint8Array:c=new he(r);break;case Tt:c=new ue(r);break;default:if(r instanceof C)c=new Y(r);else throw new Error("Unexpected content type")}new b(m(o,E(i.store,o)),s,s&&s.lastId,null,null,t,n,c).integrate(e,0)},Xr=(e,t)=>{e.doc??N();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Gi=e=>{let t={};return e.doc??N(),e._map.forEach((n,r)=>{n.deleted||(t[r]=n.content.getContent()[n.length-1])}),t},zi=(e,t)=>{e.doc??N();let n=e._map.get(t);return n!==void 0&&!n.deleted},_h=(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&&ft(r,n)?r.content.getContent()[r.length-1]:void 0},ol=(e,t)=>{let n={};return e._map.forEach((r,s)=>{let i=r;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&ft(i,t)&&(n[s]=i.content.getContent()[i.length-1])}),n},An=e=>(e.doc??N(),Ys(e._map.entries(),t=>!t[1].deleted)),Or=class extends ie{},oe=class e extends C{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(n=>n instanceof C?n.clone():n)),t}get length(){return this.doc??N(),this._length}_callObserver(t,n){super._callObserver(t,n),Gn(this,t,new Or(this,t))}insert(t,n){this.doc!==null?x(this.doc,r=>{ji(r,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?x(this.doc,n=>{il(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?x(this.doc,r=>{qi(r,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return $i(this,t)}toArray(){return Mi(this)}slice(t=0,n=this.length){return Bi(this,t,n)}toJSON(){return this.map(t=>t instanceof C?t.toJSON():t)}map(t){return Ri(this,t)}forEach(t){Fe(this,t)}[Symbol.iterator](){return sl(this)}_write(t){t.writeTypeRef(Il)}},cl=e=>new oe,Vr=class extends ie{constructor(t,n,r){super(t,n),this.keysChanged=r}},ce=class e extends C{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach((r,s)=>{this.set(s,r)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((n,r)=>{t.set(r,n instanceof C?n.clone():n)}),t}_callObserver(t,n){Gn(this,t,new Vr(this,t,n))}toJSON(){this.doc??N();let t={};return this._map.forEach((n,r)=>{if(!n.deleted){let s=n.content.getContent()[n.length-1];t[r]=s instanceof C?s.toJSON():s}}),t}get size(){return[...An(this)].length}keys(){return Un(An(this),t=>t[0])}values(){return Un(An(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Un(An(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??N(),this._map.forEach((n,r)=>{n.deleted||t(n.content.getContent()[n.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?x(this.doc,n=>{Mn(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?x(this.doc,r=>{Jr(r,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return Xr(this,t)}has(t){return zi(this,t)}clear(){this.doc!==null?x(this.doc,t=>{this.forEach(function(n,r,s){Mn(t,s,r)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Tl)}},ll=e=>new ce,gt=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&ir(e,t),je=class{constructor(t,n,r,s){this.left=t,this.right=n,this.index=r,this.currentAttributes=s}forward(){this.right===null&&D(),this.right.content.constructor===A?this.right.deleted||fe(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}},pi=(e,t,n)=>{for(;t.right!==null&&n>0;)t.right.content.constructor===A?t.right.deleted||fe(t.currentAttributes,t.right.content):t.right.deleted||(n<t.right.length&&M(e,m(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},In=(e,t,n,r)=>{let s=new Map,i=r?qn(t,n):null;if(i){let o=new je(i.p.left,i.p,i.index,s);return pi(e,o,n-i.index)}else{let o=new je(null,t._start,0,s);return pi(e,o,n)}},Hi=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===A&>(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let s=e.doc,i=s.clientID;r.forEach((o,c)=>{let l=n.left,h=n.right,a=new b(m(i,E(s.store,i)),l,l&&l.lastId,h,h&&h.id,t,null,new A(c,o));a.integrate(e,0),n.right=a,n.forward()})},fe=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},Ji=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===A&>(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},Xi=(e,t,n,r)=>{let s=e.doc,i=s.clientID,o=new Map;for(let c in r){let l=r[c],h=n.currentAttributes.get(c)??null;if(!gt(h,l)){o.set(c,h);let{left:a,right:u}=n;n.right=new b(m(i,E(s.store,i)),a,a&&a.lastId,u,u&&u.id,t,null,new A(c,l)),n.right.integrate(e,0),n.forward()}}return o},Er=(e,t,n,r,s)=>{n.currentAttributes.forEach((d,f)=>{s[f]===void 0&&(s[f]=null)});let i=e.doc,o=i.clientID;Ji(n,s);let c=Xi(e,t,n,s),l=r.constructor===String?new rt(r):r instanceof C?new Y(r):new xt(r),{left:h,right:a,index:u}=n;t._searchMarker&&$e(t._searchMarker,n.index,l.getLength()),a=new b(m(o,E(i.store,o)),h,h&&h.lastId,a,a&&a.id,t,null,l),a.integrate(e,0),n.right=a,n.index=u,n.forward(),Hi(e,t,n,c)},gi=(e,t,n,r,s)=>{let i=e.doc,o=i.clientID;Ji(n,s);let c=Xi(e,t,n,s);t:for(;n.right!==null&&(r>0||c.size>0&&(n.right.deleted||n.right.content.constructor===A));){if(!n.right.deleted)switch(n.right.content.constructor){case A:{let{key:l,value:h}=n.right.content,a=s[l];if(a!==void 0){if(gt(a,h))c.delete(l);else{if(r===0)break t;c.set(l,h)}n.right.delete(e)}else n.currentAttributes.set(l,h);break}default:r<n.right.length&&M(e,m(n.right.id.client,n.right.id.clock+r)),r-=n.right.length;break}n.forward()}if(r>0){let l="";for(;r>0;r--)l+=`
`;n.right=new b(m(o,E(i.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new rt(l)),n.right.integrate(e,0),n.forward()}Hi(e,t,n,c)},Pi=(e,t,n,r,s)=>{let i=t,o=_();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===A){let h=i.content;o.set(h.key,h)}i=i.right}let c=0,l=!1;for(;t!==i;){if(n===t&&(l=!0),!t.deleted){let h=t.content;if(h.constructor===A){let{key:a,value:u}=h,d=r.get(a)??null;(o.get(a)!==h||d===u)&&(t.delete(e),c++,!l&&(s.get(a)??null)===u&&d!==u&&(d===null?s.delete(a):s.set(a,d))),!l&&!t.deleted&&fe(s,h)}}t=t.right}return c},al=(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===A){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},hl=e=>{let t=0;return x(e.doc,n=>{let r=e._start,s=e._start,i=_(),o=Xe(i);for(;s;)s.deleted===!1&&(s.content.constructor===A?fe(o,s.content):(t+=Pi(n,r,s,i,o),i=Xe(o),r=s)),s=s.right}),t},ul=e=>{let t=new Set,n=e.doc;for(let[r,s]of e.afterState.entries()){let i=e.beforeState.get(r)||0;s!==i&&Ai(e,n.store.clients.get(r),i,s,o=>{!o.deleted&&o.content.constructor===A&&o.constructor!==R&&t.add(o.parent)})}x(n,r=>{ne(e,e.deleteSet,s=>{if(s instanceof R||!s.parent._hasFormatting||t.has(s.parent))return;let i=s.parent;s.content.constructor===A?t.add(i):al(r,s)});for(let s of t)hl(s)})},mi=(e,t,n)=>{let r=n,s=Xe(t.currentAttributes),i=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Y:case xt:case rt:n<t.right.length&&M(e,m(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}i&&Pi(e,i,t.right,s,t.currentAttributes);let o=(t.left||t.right).parent;return o._searchMarker&&$e(o._searchMarker,t.index,-r+n),t},Nr=class extends ie{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=[];x(t,r=>{let s=new Map,i=new Map,o=this.target._start,c=null,l={},h="",a=0,u=0,d=()=>{if(c!==null){let f=null;switch(c){case"delete":u>0&&(f={delete:u}),u=0;break;case"insert":(typeof h=="object"||h.length>0)&&(f={insert:h},s.size>0&&(f.attributes={},s.forEach((p,y)=>{p!==null&&(f.attributes[y]=p)}))),h="";break;case"retain":a>0&&(f={retain:a},ks(l)||(f.attributes=xs({},l))),a=0;break}f&&n.push(f),c=null}};for(;o!==null;){switch(o.content.constructor){case Y:case xt:this.adds(o)?this.deletes(o)||(d(),c="insert",h=o.content.getContent()[0],d()):this.deletes(o)?(c!=="delete"&&(d(),c="delete"),u+=1):o.deleted||(c!=="retain"&&(d(),c="retain"),a+=1);break;case rt:this.adds(o)?this.deletes(o)||(c!=="insert"&&(d(),c="insert"),h+=o.content.str):this.deletes(o)?(c!=="delete"&&(d(),c="delete"),u+=o.length):o.deleted||(c!=="retain"&&(d(),c="retain"),a+=o.length);break;case A:{let{key:f,value:p}=o.content;if(this.adds(o)){if(!this.deletes(o)){let y=s.get(f)??null;gt(y,p)?p!==null&&o.delete(r):(c==="retain"&&d(),gt(p,i.get(f)??null)?delete l[f]:l[f]=p)}}else if(this.deletes(o)){i.set(f,p);let y=s.get(f)??null;gt(y,p)||(c==="retain"&&d(),l[f]=y)}else if(!o.deleted){i.set(f,p);let y=l[f];y!==void 0&&(gt(y,p)?y!==null&&o.delete(r):(c==="retain"&&d(),p===null?delete l[f]:l[f]=p))}o.deleted||(c==="insert"&&d(),fe(s,o.content));break}}o=o.right}for(d();n.length>0;){let f=n[n.length-1];if(f.retain!==void 0&&f.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}},qe=class e extends C{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??N(),this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);let r=new Nr(this,t,n);Gn(this,t,r),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??N();let t="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===rt&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){this.doc!==null?x(this.doc,r=>{let s=new je(null,this._start,0,new Map);for(let i=0;i<t.length;i++){let o=t[i];if(o.insert!==void 0){let c=!n&&typeof o.insert=="string"&&i===t.length-1&&s.right===null&&o.insert.slice(-1)===`
`?o.insert.slice(0,-1):o.insert;(typeof c!="string"||c.length>0)&&Er(r,this,s,c,o.attributes||{})}else o.retain!==void 0?gi(r,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&mi(r,s,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,r){this.doc??N();let s=[],i=new Map,o=this.doc,c="",l=this._start;function h(){if(c.length>0){let u={},d=!1;i.forEach((p,y)=>{d=!0,u[y]=p});let f={insert:c};d&&(f.attributes=u),s.push(f),c=""}}let a=()=>{for(;l!==null;){if(ft(l,t)||n!==void 0&&ft(l,n))switch(l.content.constructor){case rt:{let u=i.get("ychange");t!==void 0&&!ft(l,t)?(u===void 0||u.user!==l.id.client||u.type!=="removed")&&(h(),i.set("ychange",r?r("removed",l.id):{type:"removed"})):n!==void 0&&!ft(l,n)?(u===void 0||u.user!==l.id.client||u.type!=="added")&&(h(),i.set("ychange",r?r("added",l.id):{type:"added"})):u!==void 0&&(h(),i.delete("ychange")),c+=l.content.str;break}case Y:case xt:{h();let u={insert:l.content.getContent()[0]};if(i.size>0){let d={};u.attributes=d,i.forEach((f,p)=>{d[p]=f})}s.push(u);break}case A:ft(l,t)&&(h(),fe(i,l.content));break}l=l.right}h()};return t||n?x(o,u=>{t&&Ar(u,t),n&&Ar(u,n),a()},"cleanup"):a(),s}insert(t,n,r){if(n.length<=0)return;let s=this.doc;s!==null?x(s,i=>{let o=In(i,this,t,!r);r||(r={},o.currentAttributes.forEach((c,l)=>{r[l]=c})),Er(i,this,o,n,r)}):this._pending.push(()=>this.insert(t,n,r))}insertEmbed(t,n,r){let s=this.doc;s!==null?x(s,i=>{let o=In(i,this,t,!r);Er(i,this,o,n,r||{})}):this._pending.push(()=>this.insertEmbed(t,n,r||{}))}delete(t,n){if(n===0)return;let r=this.doc;r!==null?x(r,s=>{mi(s,In(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?x(s,i=>{let o=In(i,this,t,!1);o.right!==null&&gi(i,this,o,n,r)}):this._pending.push(()=>this.format(t,n,r))}removeAttribute(t){this.doc!==null?x(this.doc,n=>{Mn(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?x(this.doc,r=>{Jr(r,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return Xr(this,t)}getAttributes(){return Gi(this)}_write(t){t.writeTypeRef(Dl)}},dl=e=>new qe,Le=class{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??N()}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(n)))do if(n=t.content.type,!t.deleted&&(n.constructor===ae||n.constructor===le)&&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})}},le=class e extends C{constructor(){super(),this._prelimContent=[]}get firstChild(){let t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(n=>n instanceof C?n.clone():n)),t}get length(){return this.doc??N(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Le(this,t)}querySelector(t){t=t.toUpperCase();let r=new Le(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return r.done?null:r.value}querySelectorAll(t){return t=t.toUpperCase(),P(new Le(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){Gn(this,t,new Lr(this,n,t))}toString(){return Ri(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),Fe(this,i=>{s.insertBefore(i.toDOM(t,n,r),null)}),s}insert(t,n){this.doc!==null?x(this.doc,r=>{ji(r,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)x(this.doc,r=>{let s=t&&t instanceof C?t._item:t;Bn(r,this,s,n)});else{let r=this._prelimContent,s=t===null?0:r.findIndex(i=>i===t)+1;if(s===0&&t!==null)throw G("Reference item not found");r.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?x(this.doc,r=>{qi(r,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return Mi(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return $i(this,t)}slice(t=0,n=this.length){return Bi(this,t,n)}forEach(t){Fe(this,t)}_write(t){t.writeTypeRef(Ol)}},fl=e=>new le,ae=class e extends le{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 bs(n,(r,s)=>{t.setAttribute(s,r)}),t.insert(0,this.toArray().map(r=>r instanceof C?r.clone():r)),t}toString(){let t=this.getAttributes(),n=[],r=[];for(let c in t)r.push(c);r.sort();let s=r.length;for(let c=0;c<s;c++){let l=r[c];n.push(l+'="'+t[l]+'"')}let i=this.nodeName.toLocaleLowerCase(),o=n.length>0?" "+n.join(" "):"";return`<${i}${o}>${super.toString()}</${i}>`}removeAttribute(t){this.doc!==null?x(this.doc,n=>{Mn(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?x(this.doc,r=>{Jr(r,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return Xr(this,t)}hasAttribute(t){return zi(this,t)}getAttributes(t){return t?ol(this,t):Gi(this)}toDOM(t=document,n={},r){let s=t.createElement(this.nodeName),i=this.getAttributes();for(let o in i){let c=i[o];typeof c=="string"&&s.setAttribute(o,c)}return Fe(this,o=>{s.appendChild(o.toDOM(t,n,r))}),r!==void 0&&r._createAssociation(s,this),s}_write(t){t.writeTypeRef(vl),t.writeKey(this.nodeName)}},pl=e=>new ae(e.readKey()),Lr=class extends ie{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)})}},Rn=class e extends ce{constructor(t){super(),this.hookName=t}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((n,r)=>{t.set(r,n)}),t}toDOM(t=document,n={},r){let s=n[this.hookName],i;return s!==void 0?i=s.createDom(this):i=document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(i,this),i}_write(t){t.writeTypeRef(Vl),t.writeKey(this.hookName)}},gl=e=>new Rn(e.readKey()),Br=class e extends qe{get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,r){let s=t.createTextNode(this.toString());return r!==void 0&&r._createAssociation(s,this),s}toString(){return this.toDelta().map(t=>{let n=[];for(let s in t.attributes){let i=[];for(let o in t.attributes[s])i.push({key:o,value:t.attributes[s][o]});i.sort((o,c)=>o.key<c.key?-1:1),n.push({nodeName:s,attrs:i})}n.sort((s,i)=>s.nodeName<i.nodeName?-1:1);let r="";for(let s=0;s<n.length;s++){let i=n[s];r+=`<${i.nodeName}`;for(let o=0;o<i.attrs.length;o++){let c=i.attrs[o];r+=` ${c.key}="${c.value}"`}r+=">"}r+=t.insert;for(let s=n.length-1;s>=0;s--)r+=`</${n[s].nodeName}>`;return r}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(Nl)}},ml=e=>new Br,Ge=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()}},wl=0,R=class extends Ge{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),Ci(t.doc.store,this)}write(t,n){t.writeInfo(wl),t.writeLen(this.length-n)}getMissing(t,n){return null}},he=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}},yl=e=>new he(e.readBuf()),ze=class e{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){Be(t.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(t){}gc(t){}write(t,n){t.writeLen(this.len-n)}getRef(){return 1}},xl=e=>new ze(e.readLen()),Ki=(e,t)=>new Tt({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),ue=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}},bl=e=>new ue(Ki(e.readString(),e.readAny())),xt=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}},kl=e=>new xt(e.readJSON()),A=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}},Sl=e=>new A(e.readKey(),e.readJSON()),$n=class e{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){let r=this.arr.length;t.writeLen(r-n);for(let s=n;s<r;s++){let i=this.arr[s];t.writeString(i===void 0?"undefined":JSON.stringify(i))}}getRef(){return 2}},_l=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 $n(n)},El=Ct("node_env")==="development",vt=class e{constructor(t){this.arr=t,El&&or(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){let r=this.arr.length;t.writeLen(r-n);for(let s=n;s<r;s++){let i=this.arr[s];t.writeAny(i)}}getRef(){return 8}},Ul=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new vt(n)},rt=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}},Cl=e=>new rt(e.readString()),Al=[cl,ll,dl,pl,fl,gl,ml],Il=0,Tl=1,Dl=2,vl=3,Ol=4,Vl=5,Nl=6,Y=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}},Ll=e=>new Y(Al[e.readTypeRef()](e)),Mr=(e,t)=>{let n=t,r=0,s;do r>0&&(n=m(n.client,n.clock+r)),s=te(e,n),r=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof b);return{item:s,diff:r}},Pr=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Fn=(e,t,n)=>{let{client:r,clock:s}=t.id,i=new b(m(r,s+n),t,m(r,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),t.redone!==null&&(i.redone=m(t.redone.client,t.redone.clock+n)),t.right=i,i.right!==null&&(i.right.left=i),e._mergeStructs.push(i),i.parentSub!==null&&i.right===null&&i.parent._map.set(i.parentSub,i),t.length=n,i},wi=(e,t)=>ge(e,n=>de(n.deletions,t)),Yi=(e,t,n,r,s,i)=>{let o=e.doc,c=o.store,l=o.clientID,h=t.redone;if(h!==null)return M(e,h);let a=t.parent._item,u=null,d;if(a!==null&&a.deleted===!0){if(a.redone===null&&(!n.has(a)||Yi(e,a,n,r,s,i)===null))return null;for(;a.redone!==null;)a=M(e,a.redone)}let f=a===null?t.parent:a.content.type;if(t.parentSub===null){for(u=t.left,d=t;u!==null;){let S=u;for(;S!==null&&S.parent._item!==a;)S=S.redone===null?null:M(e,S.redone);if(S!==null&&S.parent._item===a){u=S;break}u=u.left}for(;d!==null;){let S=d;for(;S!==null&&S.parent._item!==a;)S=S.redone===null?null:M(e,S.redone);if(S!==null&&S.parent._item===a){d=S;break}d=d.right}}else{if(d=null,t.right&&!s){for(u=t;u!==null&&u.right!==null&&(u.right.redone||de(r,u.right.id)||wi(i.undoStack,u.right.id)||wi(i.redoStack,u.right.id));)for(u=u.right;u.redone;)u=M(e,u.redone);if(u&&u.right!==null)return null}else u=f._map.get(t.parentSub)||null;u!==null&&u.parent._item!==a&&(u=f._map.get(t.parentSub)||null)}let p=E(c,l),y=m(l,p),k=new b(y,u,u&&u.lastId,d,d&&d.id,f,t.parentSub,t.content.copy());return t.redone=y,Pr(k,!0),k.integrate(e,0),k},b=class e extends Ge{constructor(t,n,r,s,i,o,c,l){super(t,l.getLength()),this.origin=r,this.left=n,this.right=s,this.rightOrigin=i,this.parent=o,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?2:0}set marker(t){(this.info&8)>0!==t&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(t){this.keep!==t&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(t){this.deleted!==t&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=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===mt&&this.id.client!==this.parent.client&&this.parent.clock>=E(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=ci(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=M(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===R||this.right&&this.right.constructor===R)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===mt){let r=te(n,this.parent);r.constructor===R?this.parent=null:this.parent=r.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=ci(t,t.doc.store,m(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,s;if(r!==null)s=r.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;let i=new Set,o=new Set;for(;s!==null&&s!==this.right;){if(o.add(s),i.add(s),Qt(this.origin,s.origin)){if(s.id.client<this.id.client)r=s,i.clear();else if(Qt(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&o.has(te(t.doc.store,s.origin)))i.has(te(t.doc.store,s.origin))||(r=s,i.clear());else break;s=s.right}this.left=r}if(this.left!==null){let r=this.left.right;this.right=r,this.left.right=this}else{let r;if(this.parentSub!==null)for(r=this.parent._map.get(this.parentSub)||null;r!==null&&r.left!==null;)r=r.left;else r=this.parent._start,this.parent._start=this;this.right=r}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Ci(t.doc.store,this),this.content.integrate(t,this),ai(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new R(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:m(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Qt(t.origin,this.lastId)&&this.right===t&&Qt(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){let n=this.parent._searchMarker;return n&&n.forEach(r=>{r.p===t&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){let n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),Be(t.deleteSet,this.id.client,this.id.clock,this.length),ai(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw D();this.content.gc(t),n?Jc(t,this,new R(this.id,this.length)):this.content=new ze(this.length)}write(t,n){let r=n>0?m(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,i=this.parentSub,o=this.content.getRef()&31|(r===null?0:128)|(s===null?0:64)|(i===null?0:32);if(t.writeInfo(o),r!==null&&t.writeLeftID(r),s!==null&&t.writeRightID(s),r===null&&s===null){let c=this.parent;if(c._item!==void 0){let l=c._item;if(l===null){let h=Ei(c);t.writeParentInfo(!0),t.writeString(h)}else t.writeParentInfo(!1),t.writeLeftID(l.id)}else c.constructor===String?(t.writeParentInfo(!0),t.writeString(c)):c.constructor===mt?(t.writeParentInfo(!1),t.writeLeftID(c)):D();i!==null&&t.writeString(i)}this.content.write(t,n)}},Wi=(e,t)=>Bl[t&31](e),Bl=[()=>{D()},xl,_l,yl,Cl,kl,Sl,Ll,Ul,bl,()=>{D()}],Ml=10,B=class extends Ge{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){D()}write(t,n){t.writeInfo(Ml),g(t.restEncoder,this.length-n)}getMissing(t,n){return null}},Zi=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Qi="__ $YJS$ __";Zi[Qi]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Zi[Qi]=!0;export{_ as a,L as b,W as c,Ot as d,es as e,O as f,$l as g,Ye as h,it as i,jl as j,rs as k,ut as l,co as m,$ as n,Ft as o,g as p,lt as q,F as r,at as s,G as t,z as u,D as v,V as w,j as x,_t as y,w as z,dt as A,Gt as B,Uo as C,Wl as D,ps as E,Se as F,Ql as G,ta as H,ws as I,ea as J,na as K,vo as L,ra as M,Ht as N,Ue as O,Jt as P,rn as Q,ia as R,oa as S,ca as T,la as U,At as V,Na as W,ve as X,Oe as Y,Sr as Z,En as _,Ga as $,Qs as aa,ne as ba,de as ca,re as da,Fr as ea,yi as fa,Tc as ga,Tt as ha,H as ia,q as ja,ct as ka,X as la,bi as ma,Xa as na,qr as oa,Pa as pa,Lc as qa,Ka as ra,Si as sa,Ya as ta,mt as ua,Qt as va,m as wa,Ei as xa,On as ya,Wa as za,oi as Aa,Me as Ba,Za as Ca,Qa as Da,Cr as Ea,th as Fa,eh as Ga,nh as Ha,rh as Ia,sh as Ja,Vn as Ka,ih as La,qc as Ma,oh as Na,Gc as Oa,ch as Pa,Ui as Qa,lh as Ra,ah as Sa,hh as Ta,uh as Ua,E as Va,K as Wa,te as Xa,M as Ya,ci as Za,Tr as _a,dh as $a,x as ab,di as bb,fh as cb,Pc as db,ph as eb,Kc as fb,Yc as gb,Wc as hb,gh as ib,Zc as jb,mh as kb,Ln as lb,vi as mb,wh as nb,yh as ob,xh as pb,bh as qb,tl as rb,ie as sb,kh as tb,C as ub,Sh as vb,_h as wb,ol as xb,Or as yb,oe as zb,Vr as Ab,ce as Bb,hl as Cb,Nr as Db,qe as Eb,le as Fb,ae as Gb,Lr as Hb,Rn as Ib,Br as Jb,Ge as Kb,R as Lb,he as Mb,ze as Nb,ue as Ob,xt as Pb,A as Qb,$n as Rb,vt as Sb,rt as Tb,Y as Ub,b as Vb,B as Wb};