playhtml 2.0.11 → 2.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
- (function(S,k){typeof exports=="object"&&typeof module<"u"?k(exports):typeof define=="function"&&define.amd?define(["exports"],k):(S=typeof globalThis<"u"?globalThis:S||self,k(S.playhtml={}))})(this,function(S){var bt,dr;"use strict";var Kl=Object.defineProperty;var zl=(S,k,I)=>k in S?Kl(S,k,{enumerable:!0,configurable:!0,writable:!0,value:I}):S[k]=I;var y=(S,k,I)=>(zl(S,typeof k!="symbol"?k+"":k,I),I),fr=(S,k,I)=>{if(!k.has(S))throw TypeError("Cannot "+I)};var Ce=(S,k,I)=>(fr(S,k,"read from private field"),I?I.call(S):k.get(S)),gr=(S,k,I)=>{if(k.has(S))throw TypeError("Cannot add the same private member more than once");k instanceof WeakSet?k.add(S):k.set(S,I)},pr=(S,k,I,xt)=>(fr(S,k,"write to private field"),xt?xt.call(S,I):k.set(S,I),I);var k=1e6,I="y-pk-batch",xt=!1,wr=(n,t)=>{if(n.byteLength<=k){t(n);return}xt||(console.warn("[y-partykit]","The Y.js update size exceeds 1MB, which is the maximum size for an individual update. The update will be split into chunks. This is an experimental feature.",`Message size: ${(n.byteLength/1e3/1e3).toFixed(1)}MB`),xt=!0);const e=(Date.now()+Math.random()).toString(36).substring(10),s=Math.ceil(n.byteLength/k);t(An({id:e,type:"start",size:n.byteLength,count:s}));let r=0,i=0;for(let o=0;o<s;o++){const l=n.slice(k*o,k*(o+1));t(l),i+=1,r+=l.byteLength}t(An({id:e,type:"end",size:r,count:i}))};function An(n){return`${I}#${JSON.stringify(n)}`}const N=()=>new Map,Ae=n=>{const t=N();return n.forEach((e,s)=>{t.set(s,e)}),t},Y=(n,t,e)=>{let s=n.get(t);return s===void 0&&n.set(t,s=e()),s},mr=(n,t)=>{const e=[];for(const[s,r]of n)e.push(t(r,s));return e},yr=(n,t)=>{for(const[e,s]of n)if(t(s,e))return!0;return!1},ot=()=>new Set,Le=n=>n[n.length-1],br=(n,t)=>{for(let e=0;e<t.length;e++)n.push(t[e])},tt=Array.from,kr=Array.isArray;class Zt{constructor(){this._observers=N()}on(t,e){Y(this._observers,t,ot).add(e)}once(t,e){const s=(...r)=>{this.off(t,s),e(...r)};this.on(t,s)}off(t,e){const s=this._observers.get(t);s!==void 0&&(s.delete(e),s.size===0&&this._observers.delete(t))}emit(t,e){return tt((this._observers.get(t)||N()).values()).forEach(s=>s(...e))}destroy(){this._observers=N()}}const X=Math.floor,Qt=Math.abs,Ie=(n,t)=>n<t?n:t,lt=(n,t)=>n>t?n:t,_r=Math.pow,Ln=n=>n!==0?n<0:1/n<0,Sr=String.fromCharCode,Dr=n=>n.toLowerCase(),Er=/^\s*/g,Cr=n=>n.replace(Er,""),Ar=/([A-Z])/g,In=(n,t)=>Cr(n.replace(Ar,e=>`${t}${Dr(e)}`)),Lr=n=>{const t=unescape(encodeURIComponent(n)),e=t.length,s=new Uint8Array(e);for(let r=0;r<e;r++)s[r]=t.codePointAt(r);return s},Tt=typeof TextEncoder<"u"?new TextEncoder:null,Ir=Tt?n=>Tt.encode(n):Lr;let Ut=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Ut&&Ut.decode(new Uint8Array).length===1&&(Ut=null);const vn=n=>n===void 0?null:n;class vr{constructor(){this.map=new Map}setItem(t,e){this.map.set(t,e)}getItem(t){return this.map.get(t)}}let Mn=new vr,ve=!0;try{typeof localStorage<"u"&&(Mn=localStorage,ve=!1)}catch{}const xn=Mn,Mr=n=>ve||addEventListener("storage",n),xr=n=>ve||removeEventListener("storage",n),Tr=Object.assign,Ur=Object.keys,Or=(n,t)=>{for(const e in n)t(n[e],e)},Rr=(n,t)=>{const e=[];for(const s in n)e.push(t(n[s],s));return e},te=n=>Ur(n).length,Br=n=>{for(const t in n)return!1;return!0},Nr=(n,t)=>{for(const e in n)if(!t(n[e],e))return!1;return!0},Tn=(n,t)=>Object.prototype.hasOwnProperty.call(n,t),Fr=(n,t)=>n===t||te(n)===te(t)&&Nr(n,(e,s)=>(e!==void 0||Tn(t,s))&&t[s]===e),Me=(n,t,e=0)=>{try{for(;e<n.length;e++)n[e](...t)}finally{e<n.length&&Me(n,t,e+1)}},Vr=n=>n,Hr=(n,t)=>n===t,Ot=(n,t)=>{if(n==null||t==null)return Hr(n,t);if(n.constructor!==t.constructor)return!1;if(n===t)return!0;switch(n.constructor){case ArrayBuffer:n=new Uint8Array(n),t=new Uint8Array(t);case Uint8Array:{if(n.byteLength!==t.byteLength)return!1;for(let e=0;e<n.length;e++)if(n[e]!==t[e])return!1;break}case Set:{if(n.size!==t.size)return!1;for(const e of n)if(!t.has(e))return!1;break}case Map:{if(n.size!==t.size)return!1;for(const e of n.keys())if(!t.has(e)||!Ot(n.get(e),t.get(e)))return!1;break}case Object:if(te(n)!==te(t))return!1;for(const e in n)if(!Tn(n,e)||!Ot(n[e],t[e]))return!1;break;case Array:if(n.length!==t.length)return!1;for(let e=0;e<n.length;e++)if(!Ot(n[e],t[e]))return!1;break;default:return!1}return!0},$r=(n,t)=>t.includes(n),kt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name),Un=typeof window<"u"&&typeof document<"u"&&!kt;let F;const jr=()=>{if(F===void 0)if(kt){F=N();const n=process.argv;let t=null;for(let e=0;e<n.length;e++){const s=n[e];s[0]==="-"?(t!==null&&F.set(t,""),t=s):t!==null&&(F.set(t,s),t=null)}t!==null&&F.set(t,"")}else typeof location=="object"?(F=N(),(location.search||"?").slice(1).split("&").forEach(n=>{if(n.length!==0){const[t,e]=n.split("=");F.set(`--${In(t,"-")}`,e),F.set(`-${In(t,"-")}`,e)}})):F=N();return F},xe=n=>jr().has(n),Te=n=>vn(kt?process.env[n.toUpperCase()]:xn.getItem(n));(n=>xe("--"+n)||Te(n)!==null)("production");const On=kt&&$r(process.env.FORCE_COLOR,["true","1","2"]),Kr=!xe("no-colors")&&(!kt||process.stdout.isTTY||On)&&(!kt||xe("color")||On||Te("COLORTERM")!==null||(Te("TERM")||"").includes("color")),Rn=1,Bn=2,Ue=4,Oe=8,Rt=32,J=64,O=128,ee=31,Re=63,ct=127,zr=2147483647,Nn=Number.MAX_SAFE_INTEGER,Yr=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&X(n)===n),W=n=>new Error(n),V=()=>{throw W("Method unimplemented")},H=()=>{throw W("Unexpected case")},Fn=W("Unexpected end of array"),Vn=W("Integer out of Range");class ne{constructor(t){this.arr=t,this.pos=0}}const et=n=>new ne(n),Xr=n=>n.pos!==n.arr.length,Jr=(n,t)=>{const e=Ve(n.arr.buffer,n.pos+n.arr.byteOffset,t);return n.pos+=t,e},T=n=>Jr(n,w(n)),_t=n=>n.arr[n.pos++],w=n=>{let t=0,e=1;const s=n.arr.length;for(;n.pos<s;){const r=n.arr[n.pos++];if(t=t+(r&ct)*e,e*=128,r<O)return t;if(t>Nn)throw Vn}throw Fn},Be=n=>{let t=n.arr[n.pos++],e=t&Re,s=64;const r=(t&J)>0?-1:1;if(!(t&O))return r*e;const i=n.arr.length;for(;n.pos<i;){if(t=n.arr[n.pos++],e=e+(t&ct)*s,s*=128,t<O)return r*e;if(e>Nn)throw Vn}throw Fn},nt=Ut?n=>Ut.decode(T(n)):n=>{let t=w(n);if(t===0)return"";{let e=String.fromCodePoint(_t(n));if(--t<100)for(;t--;)e+=String.fromCodePoint(_t(n));else for(;t>0;){const s=t<1e4?t:1e4,r=n.arr.subarray(n.pos,n.pos+s);n.pos+=s,e+=String.fromCodePoint.apply(null,r),t-=s}return decodeURIComponent(escape(e))}},Ne=(n,t)=>{const e=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,t);return n.pos+=t,e},Wr=[n=>{},n=>null,Be,n=>Ne(n,4).getFloat32(0,!1),n=>Ne(n,8).getFloat64(0,!1),n=>Ne(n,8).getBigInt64(0,!1),n=>!1,n=>!0,nt,n=>{const t=w(n),e={};for(let s=0;s<t;s++){const r=nt(n);e[r]=Bt(n)}return e},n=>{const t=w(n),e=[];for(let s=0;s<t;s++)e.push(Bt(n));return e},T],Bt=n=>Wr[127-_t(n)](n);class Hn extends ne{constructor(t,e){super(t),this.reader=e,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Xr(this)?this.count=w(this)+1:this.count=-1),this.count--,this.s}}class se extends ne{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Be(this);const t=Ln(this.s);this.count=1,t&&(this.s=-this.s,this.count=w(this)+2)}return this.count--,this.s}}class Fe extends ne{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=Be(this),e=t&1;this.diff=X(t/2),this.count=1,e&&(this.count=w(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Gr{constructor(t){this.decoder=new se(t),this.str=nt(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),e=this.str.slice(this.spos,t);return this.spos=t,e}}const $n=n=>new Uint8Array(n),Ve=(n,t,e)=>new Uint8Array(n,t,e),Pr=n=>new Uint8Array(n),qr=n=>{let t="";for(let e=0;e<n.byteLength;e++)t+=Sr(n[e]);return btoa(t)},Zr=n=>Buffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),Qr=n=>{const t=atob(n),e=$n(t.length);for(let s=0;s<t.length;s++)e[s]=t.charCodeAt(s);return e},ti=n=>{const t=Buffer.from(n,"base64");return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)},ei=Un?qr:Zr,ni=Un?Qr:ti,si=n=>{const t=$n(n.byteLength);return t.set(n),t};class Nt{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const U=()=>new Nt,He=n=>{let t=n.cpos;for(let e=0;e<n.bufs.length;e++)t+=n.bufs[e].length;return t},D=n=>{const t=new Uint8Array(He(n));let e=0;for(let s=0;s<n.bufs.length;s++){const r=n.bufs[s];t.set(r,e),e+=r.length}return t.set(Ve(n.cbuf.buffer,0,n.cpos),e),t},ri=(n,t)=>{const e=n.cbuf.length;e-n.cpos<t&&(n.bufs.push(Ve(n.cbuf.buffer,0,n.cpos)),n.cbuf=new Uint8Array(lt(e,t)*2),n.cpos=0)},v=(n,t)=>{const e=n.cbuf.length;n.cpos===e&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(e*2),n.cpos=0),n.cbuf[n.cpos++]=t},$e=v,p=(n,t)=>{for(;t>ct;)v(n,O|ct&t),t=X(t/128);v(n,ct&t)},je=(n,t)=>{const e=Ln(t);for(e&&(t=-t),v(n,(t>Re?O:0)|(e?J:0)|Re&t),t=X(t/64);t>0;)v(n,(t>ct?O:0)|ct&t),t=X(t/128)},Ke=new Uint8Array(3e4),ii=Ke.length/3,oi=(n,t)=>{if(t.length<ii){const e=Tt.encodeInto(t,Ke).written||0;p(n,e);for(let s=0;s<e;s++)v(n,Ke[s])}else C(n,Ir(t))},li=(n,t)=>{const e=unescape(encodeURIComponent(t)),s=e.length;p(n,s);for(let r=0;r<s;r++)v(n,e.codePointAt(r))},at=Tt&&Tt.encodeInto?oi:li,re=(n,t)=>{const e=n.cbuf.length,s=n.cpos,r=Ie(e-s,t.length),i=t.length-r;n.cbuf.set(t.subarray(0,r),s),n.cpos+=r,i>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(lt(e*2,i)),n.cbuf.set(t.subarray(r)),n.cpos=i)},C=(n,t)=>{p(n,t.byteLength),re(n,t)},ze=(n,t)=>{ri(n,t);const e=new DataView(n.cbuf.buffer,n.cpos,t);return n.cpos+=t,e},ci=(n,t)=>ze(n,4).setFloat32(0,t,!1),ai=(n,t)=>ze(n,8).setFloat64(0,t,!1),hi=(n,t)=>ze(n,8).setBigInt64(0,t,!1),jn=new DataView(new ArrayBuffer(4)),ui=n=>(jn.setFloat32(0,n),jn.getFloat32(0)===n),Ft=(n,t)=>{switch(typeof t){case"string":v(n,119),at(n,t);break;case"number":Yr(t)&&Qt(t)<=zr?(v(n,125),je(n,t)):ui(t)?(v(n,124),ci(n,t)):(v(n,123),ai(n,t));break;case"bigint":v(n,122),hi(n,t);break;case"object":if(t===null)v(n,126);else if(kr(t)){v(n,117),p(n,t.length);for(let e=0;e<t.length;e++)Ft(n,t[e])}else if(t instanceof Uint8Array)v(n,116),C(n,t);else{v(n,118);const e=Object.keys(t);p(n,e.length);for(let s=0;s<e.length;s++){const r=e[s];at(n,r),Ft(n,t[r])}}break;case"boolean":v(n,t?120:121);break;default:v(n,127)}};class Kn extends Nt{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&p(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const zn=n=>{n.count>0&&(je(n.encoder,n.count===1?n.s:-n.s),n.count>1&&p(n.encoder,n.count-2))};class ie{constructor(){this.encoder=new Nt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(zn(this),this.count=1,this.s=t)}toUint8Array(){return zn(this),D(this.encoder)}}const Yn=n=>{if(n.count>0){const t=n.diff*2+(n.count===1?0:1);je(n.encoder,t),n.count>1&&p(n.encoder,n.count-2)}};class Ye{constructor(){this.encoder=new Nt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(Yn(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return Yn(this),D(this.encoder)}}class di{constructor(){this.sarr=[],this.s="",this.lensE=new ie}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new Nt;return this.sarr.push(this.s),this.s="",at(t,this.sarr.join("")),re(t,this.lensE.toUint8Array()),D(t)}}const fi=crypto.getRandomValues.bind(crypto),Xn=()=>fi(new Uint32Array(1))[0],gi=[1e7]+-1e3+-4e3+-8e3+-1e11,pi=()=>gi.replace(/[018]/g,n=>(n^Xn()&15>>n/4).toString(16)),ht=Date.now,St=n=>new Promise(n);Promise.all.bind(Promise);class wi{constructor(t,e){this.left=t,this.right=e}}const G=(n,t)=>new wi(n,t);typeof DOMParser<"u"&&new DOMParser;const mi=n=>mr(n,(t,e)=>`${e}:${t};`).join(""),P=Symbol,Jn=P(),Wn=P(),yi=P(),bi=P(),ki=P(),Gn=P(),_i=P(),Pn=P(),Si=P(),Di=n=>{const t=[];let e=0;for(;e<n.length;e++){const s=n[e];s.constructor===String||s.constructor===Number||s.constructor===Object&&t.push(JSON.stringify(s))}return t},Ei={[Jn]:G("font-weight","bold"),[Wn]:G("font-weight","normal"),[yi]:G("color","blue"),[ki]:G("color","green"),[bi]:G("color","grey"),[Gn]:G("color","red"),[_i]:G("color","purple"),[Pn]:G("color","orange"),[Si]:G("color","black")},Ci=Kr?n=>{const t=[],e=[],s=N();let r=[],i=0;for(;i<n.length;i++){const o=n[i],l=Ei[o];if(l!==void 0)s.set(l.left,l.right);else if(o.constructor===String||o.constructor===Number){const c=mi(s);i>0||c.length>0?(t.push("%c"+o),e.push(c)):t.push(o)}else break}for(i>0&&(r=e,r.unshift(t.join("")));i<n.length;i++){const o=n[i];o instanceof Symbol||r.push(o)}return r}:Di,Ai=(...n)=>{console.log(...Ci(n)),Li.forEach(t=>t.print(n))},Li=ot(),qn=n=>({[Symbol.iterator](){return this},next:n}),Ii=(n,t)=>qn(()=>{let e;do e=n.next();while(!e.done&&!t(e.value));return e}),Xe=(n,t)=>qn(()=>{const{done:e,value:s}=n.next();return{done:e,value:e?void 0:t(s)}});class Je{constructor(t,e){this.clock=t,this.len=e}}class Vt{constructor(){this.clients=new Map}}const Zn=(n,t,e)=>t.clients.forEach((s,r)=>{const i=n.doc.store.clients.get(r);for(let o=0;o<s.length;o++){const l=s[o];ms(n,i,l.clock,l.len,e)}}),vi=(n,t)=>{let e=0,s=n.length-1;for(;e<=s;){const r=X((e+s)/2),i=n[r],o=i.clock;if(o<=t){if(t<o+i.len)return r;e=r+1}else s=r-1}return null},Qn=(n,t)=>{const e=n.clients.get(t.client);return e!==void 0&&vi(e,t.clock)!==null},We=n=>{n.clients.forEach(t=>{t.sort((r,i)=>r.clock-i.clock);let e,s;for(e=1,s=1;e<t.length;e++){const r=t[s-1],i=t[e];r.clock+r.len>=i.clock?r.len=lt(r.len,i.clock+i.len-r.clock):(s<e&&(t[s]=i),s++)}t.length=s})},Mi=n=>{const t=new Vt;for(let e=0;e<n.length;e++)n[e].clients.forEach((s,r)=>{if(!t.clients.has(r)){const i=s.slice();for(let o=e+1;o<n.length;o++)br(i,n[o].clients.get(r)||[]);t.clients.set(r,i)}});return We(t),t},oe=(n,t,e,s)=>{Y(n.clients,t,()=>[]).push(new Je(e,s))},xi=()=>new Vt,Ti=n=>{const t=xi();return n.clients.forEach((e,s)=>{const r=[];for(let i=0;i<e.length;i++){const o=e[i];if(o.deleted){const l=o.id.clock;let c=o.length;if(i+1<e.length)for(let a=e[i+1];i+1<e.length&&a.deleted;a=e[++i+1])c+=a.length;r.push(new Je(l,c))}}r.length>0&&t.clients.set(s,r)}),t},Dt=(n,t)=>{p(n.restEncoder,t.clients.size),tt(t.clients.entries()).sort((e,s)=>s[0]-e[0]).forEach(([e,s])=>{n.resetDsCurVal(),p(n.restEncoder,e);const r=s.length;p(n.restEncoder,r);for(let i=0;i<r;i++){const o=s[i];n.writeDsClock(o.clock),n.writeDsLen(o.len)}})},Ge=n=>{const t=new Vt,e=w(n.restDecoder);for(let s=0;s<e;s++){n.resetDsCurVal();const r=w(n.restDecoder),i=w(n.restDecoder);if(i>0){const o=Y(t.clients,r,()=>[]);for(let l=0;l<i;l++)o.push(new Je(n.readDsClock(),n.readDsLen()))}}return t},ts=(n,t,e)=>{const s=new Vt,r=w(n.restDecoder);for(let i=0;i<r;i++){n.resetDsCurVal();const o=w(n.restDecoder),l=w(n.restDecoder),c=e.clients.get(o)||[],a=M(e,o);for(let h=0;h<l;h++){const d=n.readDsClock(),u=d+n.readDsLen();if(d<a){a<u&&oe(s,o,a,u-a);let f=$(c,d),g=c[f];for(!g.deleted&&g.id.clock<d&&(c.splice(f+1,0,_e(t,g,d-g.id.clock)),f++);f<c.length&&(g=c[f++],g.id.clock<u);)g.deleted||(u<g.id.clock+g.length&&c.splice(f,0,_e(t,g,u-g.id.clock)),g.delete(t))}else oe(s,o,d,u-d)}}if(s.clients.size>0){const i=new dt;return p(i.restEncoder,0),Dt(i,s),i.toUint8Array()}return null},es=Xn;class ut extends Zt{constructor({guid:t=pi(),collectionid:e=null,gc:s=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:o=!1,shouldLoad:l=!0}={}){super(),this.gc=s,this.gcFilter=r,this.clientID=es(),this.guid=t,this.collectionid=e,this.share=new Map,this.store=new gs,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=o,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.whenLoaded=St(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const c=()=>St(a=>{const h=d=>{(d===void 0||d===!0)&&(this.off("sync",h),a())};this.on("sync",h)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=a===void 0||a===!0,this.isLoaded||this.emit("load",[])}),this.whenSynced=c()}load(){const t=this._item;t!==null&&!this.shouldLoad&&_(t.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(tt(this.subdocs).map(t=>t.guid))}transact(t,e=null){return _(this,t,e)}get(t,e=x){const s=Y(this.share,t,()=>{const i=new e;return i._integrate(this,null),i}),r=s.constructor;if(e!==x&&r!==e)if(r===x){const i=new e;i._map=s._map,s._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=i}),i._start=s._start;for(let o=i._start;o!==null;o=o.right)o.parent=i;return i._length=s._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 s}getArray(t=""){return this.get(t,At)}getText(t=""){return this.get(t,It)}getMap(t=""){return this.get(t,ft)}getXmlFragment(t=""){return this.get(t,gt)}toJSON(){const t={};return this.share.forEach((e,s)=>{t[s]=e.toJSON()}),t}destroy(){tt(this.subdocs).forEach(e=>e.destroy());const t=this._item;if(t!==null){this._item=null;const e=t.content;e.doc=new ut({guid:this.guid,...e.opts,shouldLoad:!1}),e.doc._item=t,_(t.parent.doc,s=>{const r=e.doc;t.deleted||s.subdocsAdded.add(r),s.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}on(t,e){super.on(t,e)}off(t,e){super.off(t,e)}}class ns{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return w(this.restDecoder)}readDsLen(){return w(this.restDecoder)}}class ss extends ns{readLeftID(){return b(w(this.restDecoder),w(this.restDecoder))}readRightID(){return b(w(this.restDecoder),w(this.restDecoder))}readClient(){return w(this.restDecoder)}readInfo(){return _t(this.restDecoder)}readString(){return nt(this.restDecoder)}readParentInfo(){return w(this.restDecoder)===1}readTypeRef(){return w(this.restDecoder)}readLen(){return w(this.restDecoder)}readAny(){return Bt(this.restDecoder)}readBuf(){return si(T(this.restDecoder))}readJSON(){return JSON.parse(nt(this.restDecoder))}readKey(){return nt(this.restDecoder)}}class Ui{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=w(this.restDecoder),this.dsCurrVal}readDsLen(){const t=w(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class Et extends Ui{constructor(t){super(t),this.keys=[],w(t),this.keyClockDecoder=new Fe(T(t)),this.clientDecoder=new se(T(t)),this.leftClockDecoder=new Fe(T(t)),this.rightClockDecoder=new Fe(T(t)),this.infoDecoder=new Hn(T(t),_t),this.stringDecoder=new Gr(T(t)),this.parentInfoDecoder=new Hn(T(t),_t),this.typeRefDecoder=new se(T(t)),this.lenDecoder=new se(T(t))}readLeftID(){return new Ct(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Ct(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 Bt(this.restDecoder)}readBuf(){return T(this.restDecoder)}readJSON(){return Bt(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{const e=this.stringDecoder.read();return this.keys.push(e),e}}}class rs{constructor(){this.restEncoder=U()}toUint8Array(){return D(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){p(this.restEncoder,t)}writeDsLen(t){p(this.restEncoder,t)}}class Ht extends rs{writeLeftID(t){p(this.restEncoder,t.client),p(this.restEncoder,t.clock)}writeRightID(t){p(this.restEncoder,t.client),p(this.restEncoder,t.clock)}writeClient(t){p(this.restEncoder,t)}writeInfo(t){$e(this.restEncoder,t)}writeString(t){at(this.restEncoder,t)}writeParentInfo(t){p(this.restEncoder,t?1:0)}writeTypeRef(t){p(this.restEncoder,t)}writeLen(t){p(this.restEncoder,t)}writeAny(t){Ft(this.restEncoder,t)}writeBuf(t){C(this.restEncoder,t)}writeJSON(t){at(this.restEncoder,JSON.stringify(t))}writeKey(t){at(this.restEncoder,t)}}class is{constructor(){this.restEncoder=U(),this.dsCurrVal=0}toUint8Array(){return D(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const e=t-this.dsCurrVal;this.dsCurrVal=t,p(this.restEncoder,e)}writeDsLen(t){t===0&&H(),p(this.restEncoder,t-1),this.dsCurrVal+=t}}class dt extends is{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Ye,this.clientEncoder=new ie,this.leftClockEncoder=new Ye,this.rightClockEncoder=new Ye,this.infoEncoder=new Kn($e),this.stringEncoder=new di,this.parentInfoEncoder=new Kn($e),this.typeRefEncoder=new ie,this.lenEncoder=new ie}toUint8Array(){const t=U();return p(t,0),C(t,this.keyClockEncoder.toUint8Array()),C(t,this.clientEncoder.toUint8Array()),C(t,this.leftClockEncoder.toUint8Array()),C(t,this.rightClockEncoder.toUint8Array()),C(t,D(this.infoEncoder)),C(t,this.stringEncoder.toUint8Array()),C(t,D(this.parentInfoEncoder)),C(t,this.typeRefEncoder.toUint8Array()),C(t,this.lenEncoder.toUint8Array()),re(t,D(this.restEncoder)),D(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){Ft(this.restEncoder,t)}writeBuf(t){C(this.restEncoder,t)}writeJSON(t){Ft(this.restEncoder,t)}writeKey(t){const e=this.keyMap.get(t);e===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(e)}}const Oi=(n,t,e,s)=>{s=lt(s,t[0].id.clock);const r=$(t,s);p(n.restEncoder,t.length-r),n.writeClient(e),p(n.restEncoder,s);const i=t[r];i.write(n,s-i.id.clock);for(let o=r+1;o<t.length;o++)t[o].write(n,0)},Pe=(n,t,e)=>{const s=new Map;e.forEach((r,i)=>{M(t,i)>r&&s.set(i,r)}),ce(t).forEach((r,i)=>{e.has(i)||s.set(i,0)}),p(n.restEncoder,s.size),tt(s.entries()).sort((r,i)=>i[0]-r[0]).forEach(([r,i])=>{Oi(n,t.clients.get(r),r,i)})},Ri=(n,t)=>{const e=N(),s=w(n.restDecoder);for(let r=0;r<s;r++){const i=w(n.restDecoder),o=new Array(i),l=n.readClient();let c=w(n.restDecoder);e.set(l,{i:0,refs:o});for(let a=0;a<i;a++){const h=n.readInfo();switch(ee&h){case 0:{const d=n.readLen();o[a]=new R(b(l,c),d),c+=d;break}case 10:{const d=w(n.restDecoder);o[a]=new B(b(l,c),d),c+=d;break}default:{const d=(h&(J|O))===0,u=new L(b(l,c),null,(h&O)===O?n.readLeftID():null,null,(h&J)===J?n.readRightID():null,d?n.readParentInfo()?t.get(n.readString()):n.readLeftID():null,d&&(h&Rt)===Rt?n.readString():null,js(n,h));o[a]=u,c+=u.length}}}}return e},Bi=(n,t,e)=>{const s=[];let r=tt(e.keys()).sort((f,g)=>f-g);if(r.length===0)return null;const i=()=>{if(r.length===0)return null;let f=e.get(r[r.length-1]);for(;f.refs.length===f.i;)if(r.pop(),r.length>0)f=e.get(r[r.length-1]);else return null;return f};let o=i();if(o===null&&s.length===0)return null;const l=new gs,c=new Map,a=(f,g)=>{const m=c.get(f);(m==null||m>g)&&c.set(f,g)};let h=o.refs[o.i++];const d=new Map,u=()=>{for(const f of s){const g=f.id.client,m=e.get(g);m?(m.i--,l.clients.set(g,m.refs.slice(m.i)),e.delete(g),m.i=0,m.refs=[]):l.clients.set(g,[f]),r=r.filter(E=>E!==g)}s.length=0};for(;;){if(h.constructor!==B){const g=Y(d,h.id.client,()=>M(t,h.id.client))-h.id.clock;if(g<0)s.push(h),a(h.id.client,h.id.clock-1),u();else{const m=h.getMissing(n,t);if(m!==null){s.push(h);const E=e.get(m)||{refs:[],i:0};if(E.refs.length===E.i)a(m,M(t,m)),u();else{h=E.refs[E.i++];continue}}else(g===0||g<h.length)&&(h.integrate(n,g),d.set(h.id.client,h.id.clock+h.length))}}if(s.length>0)h=s.pop();else if(o!==null&&o.i<o.refs.length)h=o.refs[o.i++];else{if(o=i(),o===null)break;h=o.refs[o.i++]}}if(l.clients.size>0){const f=new dt;return Pe(f,l,new Map),p(f.restEncoder,0),{missing:c,update:f.toUint8Array()}}return null},Ni=(n,t)=>Pe(n,t.doc.store,t.beforeState),Fi=(n,t,e,s=new Et(n))=>_(t,r=>{r.local=!1;let i=!1;const o=r.doc,l=o.store,c=Ri(s,o),a=Bi(r,l,c),h=l.pendingStructs;if(h){for(const[u,f]of h.missing)if(f<M(l,u)){i=!0;break}if(a){for(const[u,f]of a.missing){const g=h.missing.get(u);(g==null||g>f)&&h.missing.set(u,f)}h.update=he([h.update,a.update])}}else l.pendingStructs=a;const d=ts(s,r,l);if(l.pendingDs){const u=new Et(et(l.pendingDs));w(u.restDecoder);const f=ts(u,r,l);d&&f?l.pendingDs=he([d,f]):l.pendingDs=d||f}else l.pendingDs=d;if(i){const u=l.pendingStructs.update;l.pendingStructs=null,os(r.doc,u)}},e,!1),os=(n,t,e,s=Et)=>{const r=et(t);Fi(r,n,e,new s(r))},ls=(n,t,e)=>os(n,t,e,ss),Vi=(n,t,e=new Map)=>{Pe(n,t.store,e),Dt(n,Ti(t.store))},Hi=(n,t=new Uint8Array([0]),e=new dt)=>{const s=cs(t);Vi(e,n,s);const r=[e.toUint8Array()];if(n.store.pendingDs&&r.push(n.store.pendingDs),n.store.pendingStructs&&r.push(to(n.store.pendingStructs.update,t)),r.length>1){if(e.constructor===Ht)return Zi(r.map((i,o)=>o===0?i:no(i)));if(e.constructor===dt)return he(r)}return r[0]},qe=(n,t)=>Hi(n,t,new Ht),$i=n=>{const t=new Map,e=w(n.restDecoder);for(let s=0;s<e;s++){const r=w(n.restDecoder),i=w(n.restDecoder);t.set(r,i)}return t},cs=n=>$i(new ns(et(n))),as=(n,t)=>(p(n.restEncoder,t.size),tt(t.entries()).sort((e,s)=>s[0]-e[0]).forEach(([e,s])=>{p(n.restEncoder,e),p(n.restEncoder,s)}),n),ji=(n,t)=>as(n,ce(t.store)),Ki=(n,t=new is)=>(n instanceof Map?as(t,n):ji(t,n),t.toUint8Array()),zi=n=>Ki(n,new rs);class Yi{constructor(){this.l=[]}}const hs=()=>new Yi,us=(n,t)=>n.l.push(t),ds=(n,t)=>{const e=n.l,s=e.length;n.l=e.filter(r=>t!==r),s===n.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},fs=(n,t,e)=>Me(n.l,[t,e]);class Ct{constructor(t,e){this.client=t,this.clock=e}}const le=(n,t)=>n===t||n!==null&&t!==null&&n.client===t.client&&n.clock===t.clock,b=(n,t)=>new Ct(n,t),Xi=n=>{for(const[t,e]of n.doc.share.entries())if(e===n)return t;throw H()},$t=(n,t)=>t===void 0?!n.deleted:t.sv.has(n.id.client)&&(t.sv.get(n.id.client)||0)>n.id.clock&&!Qn(t.ds,n.id),Ze=(n,t)=>{const e=Y(n.meta,Ze,ot),s=n.doc.store;e.has(t)||(t.sv.forEach((r,i)=>{r<M(s,i)&&st(n,b(i,r))}),Zn(n,t.ds,r=>{}),e.add(t))};class gs{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const ce=n=>{const t=new Map;return n.clients.forEach((e,s)=>{const r=e[e.length-1];t.set(s,r.id.clock+r.length)}),t},M=(n,t)=>{const e=n.clients.get(t);if(e===void 0)return 0;const s=e[e.length-1];return s.id.clock+s.length},ps=(n,t)=>{let e=n.clients.get(t.id.client);if(e===void 0)e=[],n.clients.set(t.id.client,e);else{const s=e[e.length-1];if(s.id.clock+s.length!==t.id.clock)throw H()}e.push(t)},$=(n,t)=>{let e=0,s=n.length-1,r=n[s],i=r.id.clock;if(i===t)return s;let o=X(t/(i+r.length-1)*s);for(;e<=s;){if(r=n[o],i=r.id.clock,i<=t){if(t<i+r.length)return o;e=o+1}else s=o-1;o=X((e+s)/2)}throw H()},Qe=(n,t)=>{const e=n.clients.get(t.client);return e[$(e,t.clock)]},tn=(n,t,e)=>{const s=$(t,e),r=t[s];return r.id.clock<e&&r instanceof L?(t.splice(s+1,0,_e(n,r,e-r.id.clock)),s+1):s},st=(n,t)=>{const e=n.doc.store.clients.get(t.client);return e[tn(n,e,t.clock)]},ws=(n,t,e)=>{const s=t.clients.get(e.client),r=$(s,e.clock),i=s[r];return e.clock!==i.id.clock+i.length-1&&i.constructor!==R&&s.splice(r+1,0,_e(n,i,e.clock-i.id.clock+1)),i},Ji=(n,t,e)=>{const s=n.clients.get(t.id.client);s[$(s,t.id.clock)]=e},ms=(n,t,e,s,r)=>{if(s===0)return;const i=e+s;let o=tn(n,t,e),l;do l=t[o++],i<l.id.clock+l.length&&tn(n,t,i),r(l);while(o<t.length&&t[o].id.clock<i)};class Wi{constructor(t,e,s){this.doc=t,this.deleteSet=new Vt,this.beforeState=ce(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=e,this.meta=new Map,this.local=s,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const ys=(n,t)=>t.deleteSet.clients.size===0&&!yr(t.afterState,(e,s)=>t.beforeState.get(s)!==e)?!1:(We(t.deleteSet),Ni(n,t),Dt(n,t.deleteSet),!0),bs=(n,t,e)=>{const s=t._item;(s===null||s.id.clock<(n.beforeState.get(s.id.client)||0)&&!s.deleted)&&Y(n.changed,t,ot).add(e)},ae=(n,t)=>{let e=n[t],s=n[t-1],r=t;for(;r>0;e=s,s=n[--r-1]){if(s.deleted===e.deleted&&s.constructor===e.constructor&&s.mergeWith(e)){e instanceof L&&e.parentSub!==null&&e.parent._map.get(e.parentSub)===e&&e.parent._map.set(e.parentSub,s);continue}break}const i=t-r;return i&&n.splice(t+1-i,i),i},Gi=(n,t,e)=>{for(const[s,r]of n.clients.entries()){const i=t.clients.get(s);for(let o=r.length-1;o>=0;o--){const l=r[o],c=l.clock+l.len;for(let a=$(i,l.clock),h=i[a];a<i.length&&h.id.clock<c;h=i[++a]){const d=i[a];if(l.clock+l.len<=d.id.clock)break;d instanceof L&&d.deleted&&!d.keep&&e(d)&&d.gc(t,!1)}}}},Pi=(n,t)=>{n.clients.forEach((e,s)=>{const r=t.clients.get(s);for(let i=e.length-1;i>=0;i--){const o=e[i],l=Ie(r.length-1,1+$(r,o.clock+o.len-1));for(let c=l,a=r[c];c>0&&a.id.clock>=o.clock;a=r[c])c-=1+ae(r,c)}})},ks=(n,t)=>{if(t<n.length){const e=n[t],s=e.doc,r=s.store,i=e.deleteSet,o=e._mergeStructs;try{We(i),e.afterState=ce(e.doc.store),s.emit("beforeObserverCalls",[e,s]);const l=[];e.changed.forEach((c,a)=>l.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(e,c)})),l.push(()=>{e.changedParentTypes.forEach((c,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(c=c.filter(h=>h.target._item===null||!h.target._item.deleted),c.forEach(h=>{h.currentTarget=a,h._path=null}),c.sort((h,d)=>h.path.length-d.path.length),fs(a._dEH,c,e))})}),l.push(()=>s.emit("afterTransaction",[e,s])),Me(l,[]),e._needFormattingCleanup&&wo(e)}finally{s.gc&&Gi(i,r,s.gcFilter),Pi(i,r),e.afterState.forEach((h,d)=>{const u=e.beforeState.get(d)||0;if(u!==h){const f=r.clients.get(d),g=lt($(f,u),1);for(let m=f.length-1;m>=g;)m-=1+ae(f,m)}});for(let h=o.length-1;h>=0;h--){const{client:d,clock:u}=o[h].id,f=r.clients.get(d),g=$(f,u);g+1<f.length&&ae(f,g+1)>1||g>0&&ae(f,g)}if(!e.local&&e.afterState.get(s.clientID)!==e.beforeState.get(s.clientID)&&(Ai(Pn,Jn,"[yjs] ",Wn,Gn,"Changed the client-id because another client seems to be using it."),s.clientID=es()),s.emit("afterTransactionCleanup",[e,s]),s._observers.has("update")){const h=new Ht;ys(h,e)&&s.emit("update",[h.toUint8Array(),e.origin,s,e])}if(s._observers.has("updateV2")){const h=new dt;ys(h,e)&&s.emit("updateV2",[h.toUint8Array(),e.origin,s,e])}const{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=e;(l.size>0||a.size>0||c.size>0)&&(l.forEach(h=>{h.clientID=s.clientID,h.collectionid==null&&(h.collectionid=s.collectionid),s.subdocs.add(h)}),a.forEach(h=>s.subdocs.delete(h)),s.emit("subdocs",[{loaded:c,added:l,removed:a},s,e]),a.forEach(h=>h.destroy())),n.length<=t+1?(s._transactionCleanups=[],s.emit("afterAllTransactions",[s,n])):ks(n,t+1)}}},_=(n,t,e=null,s=!0)=>{const r=n._transactionCleanups;let i=!1,o=null;n._transaction===null&&(i=!0,n._transaction=new Wi(n,e,s),r.push(n._transaction),r.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{o=t(n._transaction)}finally{if(i){const l=n._transaction===r[0];n._transaction=null,l&&ks(r,0)}}return o};function*qi(n){const t=w(n.restDecoder);for(let e=0;e<t;e++){const s=w(n.restDecoder),r=n.readClient();let i=w(n.restDecoder);for(let o=0;o<s;o++){const l=n.readInfo();if(l===10){const c=w(n.restDecoder);yield new B(b(r,i),c),i+=c}else if(ee&l){const c=(l&(J|O))===0,a=new L(b(r,i),null,(l&O)===O?n.readLeftID():null,null,(l&J)===J?n.readRightID():null,c?n.readParentInfo()?n.readString():n.readLeftID():null,c&&(l&Rt)===Rt?n.readString():null,js(n,l));yield a,i+=a.length}else{const c=n.readLen();yield new R(b(r,i),c),i+=c}}}}class en{constructor(t,e){this.gen=qi(t),this.curr=null,this.done=!1,this.filterSkips=e,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===B);return this.curr}}class nn{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const Zi=n=>he(n,ss,Ht),Qi=(n,t)=>{if(n.constructor===R){const{client:e,clock:s}=n.id;return new R(b(e,s+t),n.length-t)}else if(n.constructor===B){const{client:e,clock:s}=n.id;return new B(b(e,s+t),n.length-t)}else{const e=n,{client:s,clock:r}=e.id;return new L(b(s,r+t),null,b(s,r+t-1),null,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t))}},he=(n,t=Et,e=dt)=>{if(n.length===1)return n[0];const s=n.map(h=>new t(et(h)));let r=s.map(h=>new en(h,!0)),i=null;const o=new e,l=new nn(o);for(;r=r.filter(u=>u.curr!==null),r.sort((u,f)=>{if(u.curr.id.client===f.curr.id.client){const g=u.curr.id.clock-f.curr.id.clock;return g===0?u.curr.constructor===f.curr.constructor?0:u.curr.constructor===B?1:-1:g}else return f.curr.id.client-u.curr.id.client}),r.length!==0;){const h=r[0],d=h.curr.id.client;if(i!==null){let u=h.curr,f=!1;for(;u!==null&&u.id.clock+u.length<=i.struct.id.clock+i.struct.length&&u.id.client>=i.struct.id.client;)u=h.next(),f=!0;if(u===null||u.id.client!==d||f&&u.id.clock>i.struct.id.clock+i.struct.length)continue;if(d!==i.struct.id.client)rt(l,i.struct,i.offset),i={struct:u,offset:0},h.next();else if(i.struct.id.clock+i.struct.length<u.id.clock)if(i.struct.constructor===B)i.struct.length=u.id.clock+u.length-i.struct.id.clock;else{rt(l,i.struct,i.offset);const g=u.id.clock-i.struct.id.clock-i.struct.length;i={struct:new B(b(d,i.struct.id.clock+i.struct.length),g),offset:0}}else{const g=i.struct.id.clock+i.struct.length-u.id.clock;g>0&&(i.struct.constructor===B?i.struct.length-=g:u=Qi(u,g)),i.struct.mergeWith(u)||(rt(l,i.struct,i.offset),i={struct:u,offset:0},h.next())}}else i={struct:h.curr,offset:0},h.next();for(let u=h.curr;u!==null&&u.id.client===d&&u.id.clock===i.struct.id.clock+i.struct.length&&u.constructor!==B;u=h.next())rt(l,i.struct,i.offset),i={struct:u,offset:0}}i!==null&&(rt(l,i.struct,i.offset),i=null),sn(l);const c=s.map(h=>Ge(h)),a=Mi(c);return Dt(o,a),o.toUint8Array()},to=(n,t,e=Et,s=dt)=>{const r=cs(t),i=new s,o=new nn(i),l=new e(et(n)),c=new en(l,!1);for(;c.curr;){const h=c.curr,d=h.id.client,u=r.get(d)||0;if(c.curr.constructor===B){c.next();continue}if(h.id.clock+h.length>u)for(rt(o,h,lt(u-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===d;)rt(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===d&&c.curr.id.clock+c.curr.length<=u;)c.next()}sn(o);const a=Ge(l);return Dt(i,a),i.toUint8Array()},_s=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:D(n.encoder.restEncoder)}),n.encoder.restEncoder=U(),n.written=0)},rt=(n,t,e)=>{n.written>0&&n.currClient!==t.id.client&&_s(n),n.written===0&&(n.currClient=t.id.client,n.encoder.writeClient(t.id.client),p(n.encoder.restEncoder,t.id.clock+e)),t.write(n.encoder,e),n.written++},sn=n=>{_s(n);const t=n.encoder.restEncoder;p(t,n.clientStructs.length);for(let e=0;e<n.clientStructs.length;e++){const s=n.clientStructs[e];p(t,s.written),re(t,s.restEncoder)}},eo=(n,t,e,s)=>{const r=new e(et(n)),i=new en(r,!1),o=new s,l=new nn(o);for(let a=i.curr;a!==null;a=i.next())rt(l,t(a),0);sn(l);const c=Ge(r);return Dt(o,c),o.toUint8Array()},no=n=>eo(n,Vr,Et,Ht),Ss="You must not compute changes after the event-handler fired.";class ue{constructor(t,e){this.target=t,this.currentTarget=t,this.transaction=e,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=so(this.currentTarget,this.target))}deletes(t){return Qn(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw W(Ss);const t=new Map,e=this.target;this.transaction.changed.get(e).forEach(r=>{if(r!==null){const i=e._map.get(r);let o,l;if(this.adds(i)){let c=i.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(i))if(c!==null&&this.deletes(c))o="delete",l=Le(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Le(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(i))o="delete",l=Le(i.content.getContent());else return;t.set(r,{action:o,oldValue:l})}}),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 W(Ss);const e=this.target,s=ot(),r=ot(),i=[];if(t={added:s,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(e).has(null)){let l=null;const c=()=>{l&&i.push(l)};for(let a=e._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((l===null||l.delete===void 0)&&(c(),l={delete:0}),l.delete+=a.length,r.add(a)):this.adds(a)?((l===null||l.insert===void 0)&&(c(),l={insert:[]}),l.insert=l.insert.concat(a.content.getContent()),s.add(a)):((l===null||l.retain===void 0)&&(c(),l={retain:0}),l.retain+=a.length);l!==null&&l.retain===void 0&&c()}this._changes=t}return t}}const so=(n,t)=>{const e=[];for(;t._item!==null&&t!==n;){if(t._item.parentSub!==null)e.unshift(t._item.parentSub);else{let s=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)r.deleted||s++,r=r.right;e.unshift(s)}t=t._item.parent}return e},Ds=80;let rn=0;class ro{constructor(t,e){t.marker=!0,this.p=t,this.index=e,this.timestamp=rn++}}const io=n=>{n.timestamp=rn++},Es=(n,t,e)=>{n.p.marker=!1,n.p=t,t.marker=!0,n.index=e,n.timestamp=rn++},oo=(n,t,e)=>{if(n.length>=Ds){const s=n.reduce((r,i)=>r.timestamp<i.timestamp?r:i);return Es(s,t,e),s}else{const s=new ro(t,e);return n.push(s),s}},de=(n,t)=>{if(n._start===null||t===0||n._searchMarker===null)return null;const e=n._searchMarker.length===0?null:n._searchMarker.reduce((i,o)=>Qt(t-i.index)<Qt(t-o.index)?i:o);let s=n._start,r=0;for(e!==null&&(s=e.p,r=e.index,io(e));s.right!==null&&r<t;){if(!s.deleted&&s.countable){if(t<r+s.length)break;r+=s.length}s=s.right}for(;s.left!==null&&r>t;)s=s.left,!s.deleted&&s.countable&&(r-=s.length);for(;s.left!==null&&s.left.id.client===s.id.client&&s.left.id.clock+s.left.length===s.id.clock;)s=s.left,!s.deleted&&s.countable&&(r-=s.length);return e!==null&&Qt(e.index-r)<s.parent.length/Ds?(Es(e,s,r),e):oo(n._searchMarker,s,r)},jt=(n,t,e)=>{for(let s=n.length-1;s>=0;s--){const r=n[s];if(e>0){let i=r.p;for(i.marker=!1;i&&(i.deleted||!i.countable);)i=i.left,i&&!i.deleted&&i.countable&&(r.index-=i.length);if(i===null||i.marker===!0){n.splice(s,1);continue}r.p=i,i.marker=!0}(t<r.index||e>0&&t===r.index)&&(r.index=lt(t,r.index+e))}},fe=(n,t,e)=>{const s=n,r=t.changedParentTypes;for(;Y(r,n,()=>[]).push(e),n._item!==null;)n=n._item.parent;fs(s._eH,e,t)};class x{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=hs(),this._dEH=hs(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,e){this.doc=t,this._item=e}_copy(){throw V()}clone(){throw V()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,e){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){us(this._eH,t)}observeDeep(t){us(this._dEH,t)}unobserve(t){ds(this._eH,t)}unobserveDeep(t){ds(this._dEH,t)}toJSON(){}}const Cs=(n,t,e)=>{t<0&&(t=n._length+t),e<0&&(e=n._length+e);let s=e-t;const r=[];let i=n._start;for(;i!==null&&s>0;){if(i.countable&&!i.deleted){const o=i.content.getContent();if(o.length<=t)t-=o.length;else{for(let l=t;l<o.length&&s>0;l++)r.push(o[l]),s--;t=0}}i=i.right}return r},As=n=>{const t=[];let e=n._start;for(;e!==null;){if(e.countable&&!e.deleted){const s=e.content.getContent();for(let r=0;r<s.length;r++)t.push(s[r])}e=e.right}return t},Kt=(n,t)=>{let e=0,s=n._start;for(;s!==null;){if(s.countable&&!s.deleted){const r=s.content.getContent();for(let i=0;i<r.length;i++)t(r[i],e++,n)}s=s.right}},Ls=(n,t)=>{const e=[];return Kt(n,(s,r)=>{e.push(t(s,r,n))}),e},lo=n=>{let t=n._start,e=null,s=0;return{[Symbol.iterator](){return this},next:()=>{if(e===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};e=t.content.getContent(),s=0,t=t.right}const r=e[s++];return e.length<=s&&(e=null),{done:!1,value:r}}}},Is=(n,t)=>{const e=de(n,t);let s=n._start;for(e!==null&&(s=e.p,t-=e.index);s!==null;s=s.right)if(!s.deleted&&s.countable){if(t<s.length)return s.content.getContent()[t];t-=s.length}},ge=(n,t,e,s)=>{let r=e;const i=n.doc,o=i.clientID,l=i.store,c=e===null?t._start:e.right;let a=[];const h=()=>{a.length>0&&(r=new L(b(o,M(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new wt(a)),r.integrate(n,0),a=[])};s.forEach(d=>{if(d===null)a.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(d);break;default:switch(h(),d.constructor){case Uint8Array:case ArrayBuffer:r=new L(b(o,M(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new Yt(new Uint8Array(d))),r.integrate(n,0);break;case ut:r=new L(b(o,M(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new Jt(d)),r.integrate(n,0);break;default:if(d instanceof x)r=new L(b(o,M(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new q(d)),r.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},vs=()=>W("Length exceeded!"),Ms=(n,t,e,s)=>{if(e>t._length)throw vs();if(e===0)return t._searchMarker&&jt(t._searchMarker,e,s.length),ge(n,t,null,s);const r=e,i=de(t,e);let o=t._start;for(i!==null&&(o=i.p,e-=i.index,e===0&&(o=o.prev,e+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(e<=o.length){e<o.length&&st(n,b(o.id.client,o.id.clock+e));break}e-=o.length}return t._searchMarker&&jt(t._searchMarker,r,s.length),ge(n,t,o,s)},co=(n,t,e)=>{let r=(t._searchMarker||[]).reduce((i,o)=>o.index>i.index?o:i,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return ge(n,t,r,e)},xs=(n,t,e,s)=>{if(s===0)return;const r=e,i=s,o=de(t,e);let l=t._start;for(o!==null&&(l=o.p,e-=o.index);l!==null&&e>0;l=l.right)!l.deleted&&l.countable&&(e<l.length&&st(n,b(l.id.client,l.id.clock+e)),e-=l.length);for(;s>0&&l!==null;)l.deleted||(s<l.length&&st(n,b(l.id.client,l.id.clock+s)),l.delete(n),s-=l.length),l=l.right;if(s>0)throw vs();t._searchMarker&&jt(t._searchMarker,r,-i+s)},pe=(n,t,e)=>{const s=t._map.get(e);s!==void 0&&s.delete(n)},on=(n,t,e,s)=>{const r=t._map.get(e)||null,i=n.doc,o=i.clientID;let l;if(s==null)l=new wt([s]);else switch(s.constructor){case Number:case Object:case Boolean:case Array:case String:l=new wt([s]);break;case Uint8Array:l=new Yt(s);break;case ut:l=new Jt(s);break;default:if(s instanceof x)l=new q(s);else throw new Error("Unexpected content type")}new L(b(o,M(i.store,o)),r,r&&r.lastId,null,null,t,e,l).integrate(n,0)},ln=(n,t)=>{const e=n._map.get(t);return e!==void 0&&!e.deleted?e.content.getContent()[e.length-1]:void 0},Ts=n=>{const t={};return n._map.forEach((e,s)=>{e.deleted||(t[s]=e.content.getContent()[e.length-1])}),t},Us=(n,t)=>{const e=n._map.get(t);return e!==void 0&&!e.deleted},we=n=>Ii(n.entries(),t=>!t[1].deleted);class ao extends ue{constructor(t,e){super(t,e),this._transaction=e}}class At extends x{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const e=new At;return e.push(t),e}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new At}clone(){const t=new At;return t.insert(0,this.toArray().map(e=>e instanceof x?e.clone():e)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}_callObserver(t,e){super._callObserver(t,e),fe(this,t,new ao(this,t))}insert(t,e){this.doc!==null?_(this.doc,s=>{Ms(s,this,t,e)}):this._prelimContent.splice(t,0,...e)}push(t){this.doc!==null?_(this.doc,e=>{co(e,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,e=1){this.doc!==null?_(this.doc,s=>{xs(s,this,t,e)}):this._prelimContent.splice(t,e)}get(t){return Is(this,t)}toArray(){return As(this)}slice(t=0,e=this.length){return Cs(this,t,e)}toJSON(){return this.map(t=>t instanceof x?t.toJSON():t)}map(t){return Ls(this,t)}forEach(t){Kt(this,t)}[Symbol.iterator](){return lo(this)}_write(t){t.writeTypeRef(Oo)}}const ho=n=>new At;class uo extends ue{constructor(t,e,s){super(t,e),this.keysChanged=s}}class ft extends x{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,e){super._integrate(t,e),this._prelimContent.forEach((s,r)=>{this.set(r,s)}),this._prelimContent=null}_copy(){return new ft}clone(){const t=new ft;return this.forEach((e,s)=>{t.set(s,e instanceof x?e.clone():e)}),t}_callObserver(t,e){fe(this,t,new uo(this,t,e))}toJSON(){const t={};return this._map.forEach((e,s)=>{if(!e.deleted){const r=e.content.getContent()[e.length-1];t[s]=r instanceof x?r.toJSON():r}}),t}get size(){return[...we(this._map)].length}keys(){return Xe(we(this._map),t=>t[0])}values(){return Xe(we(this._map),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Xe(we(this._map),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this._map.forEach((e,s)=>{e.deleted||t(e.content.getContent()[e.length-1],s,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?_(this.doc,e=>{pe(e,this,t)}):this._prelimContent.delete(t)}set(t,e){return this.doc!==null?_(this.doc,s=>{on(s,this,t,e)}):this._prelimContent.set(t,e),e}get(t){return ln(this,t)}has(t){return Us(this,t)}clear(){this.doc!==null?_(this.doc,t=>{this.forEach(function(e,s,r){pe(t,r,s)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Ro)}}const fo=n=>new ft,it=(n,t)=>n===t||typeof n=="object"&&typeof t=="object"&&n&&t&&Fr(n,t);class cn{constructor(t,e,s,r){this.left=t,this.right=e,this.index=s,this.currentAttributes=r}forward(){switch(this.right===null&&H(),this.right.content.constructor){case A:this.right.deleted||Lt(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}}const Os=(n,t,e)=>{for(;t.right!==null&&e>0;){switch(t.right.content.constructor){case A:t.right.deleted||Lt(t.currentAttributes,t.right.content);break;default:t.right.deleted||(e<t.right.length&&st(n,b(t.right.id.client,t.right.id.clock+e)),t.index+=t.right.length,e-=t.right.length);break}t.left=t.right,t.right=t.right.right}return t},me=(n,t,e)=>{const s=new Map,r=de(t,e);if(r){const i=new cn(r.p.left,r.p,r.index,s);return Os(n,i,e-r.index)}else{const i=new cn(null,t._start,0,s);return Os(n,i,e)}},Rs=(n,t,e,s)=>{for(;e.right!==null&&(e.right.deleted===!0||e.right.content.constructor===A&&it(s.get(e.right.content.key),e.right.content.value));)e.right.deleted||s.delete(e.right.content.key),e.forward();const r=n.doc,i=r.clientID;s.forEach((o,l)=>{const c=e.left,a=e.right,h=new L(b(i,M(r.store,i)),c,c&&c.lastId,a,a&&a.id,t,null,new A(l,o));h.integrate(n,0),e.right=h,e.forward()})},Lt=(n,t)=>{const{key:e,value:s}=t;s===null?n.delete(e):n.set(e,s)},Bs=(n,t)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===A&&it(t[n.right.content.key]||null,n.right.content.value)))break;n.forward()}},Ns=(n,t,e,s)=>{const r=n.doc,i=r.clientID,o=new Map;for(const l in s){const c=s[l],a=e.currentAttributes.get(l)||null;if(!it(a,c)){o.set(l,a);const{left:h,right:d}=e;e.right=new L(b(i,M(r.store,i)),h,h&&h.lastId,d,d&&d.id,t,null,new A(l,c)),e.right.integrate(n,0),e.forward()}}return o},an=(n,t,e,s,r)=>{e.currentAttributes.forEach((u,f)=>{r[f]===void 0&&(r[f]=null)});const i=n.doc,o=i.clientID;Bs(e,r);const l=Ns(n,t,e,r),c=s.constructor===String?new j(s):s instanceof x?new q(s):new pt(s);let{left:a,right:h,index:d}=e;t._searchMarker&&jt(t._searchMarker,e.index,c.getLength()),h=new L(b(o,M(i.store,o)),a,a&&a.lastId,h,h&&h.id,t,null,c),h.integrate(n,0),e.right=h,e.index=d,e.forward(),Rs(n,t,e,l)},Fs=(n,t,e,s,r)=>{const i=n.doc,o=i.clientID;Bs(e,r);const l=Ns(n,t,e,r);t:for(;e.right!==null&&(s>0||l.size>0&&(e.right.deleted||e.right.content.constructor===A));){if(!e.right.deleted)switch(e.right.content.constructor){case A:{const{key:c,value:a}=e.right.content,h=r[c];if(h!==void 0){if(it(h,a))l.delete(c);else{if(s===0)break t;l.set(c,a)}e.right.delete(n)}else e.currentAttributes.set(c,a);break}default:s<e.right.length&&st(n,b(e.right.id.client,e.right.id.clock+s)),s-=e.right.length;break}e.forward()}if(s>0){let c="";for(;s>0;s--)c+=`
2
- `;e.right=new L(b(o,M(i.store,o)),e.left,e.left&&e.left.lastId,e.right,e.right&&e.right.id,t,null,new j(c)),e.right.integrate(n,0),e.forward()}Rs(n,t,e,l)},Vs=(n,t,e,s,r)=>{let i=t;const o=N();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===A){const a=i.content;o.set(a.key,a)}i=i.right}let l=0,c=!1;for(;t!==i;){if(e===t&&(c=!0),!t.deleted){const a=t.content;switch(a.constructor){case A:{const{key:h,value:d}=a,u=s.get(h)||null;(o.get(h)!==a||u===d)&&(t.delete(n),l++,!c&&(r.get(h)||null)===d&&u!==d&&(u===null?r.delete(h):r.set(h,u))),!c&&!t.deleted&&Lt(r,a);break}}}t=t.right}return l},go=(n,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const e=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===A){const s=t.content.key;e.has(s)?t.delete(n):e.add(s)}t=t.left}},po=n=>{let t=0;return _(n.doc,e=>{let s=n._start,r=n._start,i=N();const o=Ae(i);for(;r;){if(r.deleted===!1)switch(r.content.constructor){case A:Lt(o,r.content);break;default:t+=Vs(e,s,r,i,o),i=Ae(o),s=r;break}r=r.right}}),t},wo=n=>{const t=new Set,e=n.doc;for(const[s,r]of n.afterState.entries()){const i=n.beforeState.get(s)||0;r!==i&&ms(n,e.store.clients.get(s),i,r,o=>{!o.deleted&&o.content.constructor===A&&o.constructor!==R&&t.add(o.parent)})}_(e,s=>{Zn(n,n.deleteSet,r=>{if(r instanceof R||!r.parent._hasFormatting||t.has(r.parent))return;const i=r.parent;r.content.constructor===A?t.add(i):go(s,r)});for(const r of t)po(r)})},Hs=(n,t,e)=>{const s=e,r=Ae(t.currentAttributes),i=t.right;for(;e>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case q:case pt:case j:e<t.right.length&&st(n,b(t.right.id.client,t.right.id.clock+e)),e-=t.right.length,t.right.delete(n);break}t.forward()}i&&Vs(n,i,t.right,r,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&jt(o._searchMarker,t.index,-s+e),t};class mo extends ue{constructor(t,e,s){super(t,e),this.childListChanged=!1,this.keysChanged=new Set,s.forEach(r=>{r===null?this.childListChanged=!0:this.keysChanged.add(r)})}get changes(){if(this._changes===null){const 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){const t=this.target.doc,e=[];_(t,s=>{const r=new Map,i=new Map;let o=this.target._start,l=null;const c={};let a="",h=0,d=0;const u=()=>{if(l!==null){let f=null;switch(l){case"delete":d>0&&(f={delete:d}),d=0;break;case"insert":(typeof a=="object"||a.length>0)&&(f={insert:a},r.size>0&&(f.attributes={},r.forEach((g,m)=>{g!==null&&(f.attributes[m]=g)}))),a="";break;case"retain":h>0&&(f={retain:h},Br(c)||(f.attributes=Tr({},c))),h=0;break}f&&e.push(f),l=null}};for(;o!==null;){switch(o.content.constructor){case q:case pt:this.adds(o)?this.deletes(o)||(u(),l="insert",a=o.content.getContent()[0],u()):this.deletes(o)?(l!=="delete"&&(u(),l="delete"),d+=1):o.deleted||(l!=="retain"&&(u(),l="retain"),h+=1);break;case j:this.adds(o)?this.deletes(o)||(l!=="insert"&&(u(),l="insert"),a+=o.content.str):this.deletes(o)?(l!=="delete"&&(u(),l="delete"),d+=o.length):o.deleted||(l!=="retain"&&(u(),l="retain"),h+=o.length);break;case A:{const{key:f,value:g}=o.content;if(this.adds(o)){if(!this.deletes(o)){const m=r.get(f)||null;it(m,g)?g!==null&&o.delete(s):(l==="retain"&&u(),it(g,i.get(f)||null)?delete c[f]:c[f]=g)}}else if(this.deletes(o)){i.set(f,g);const m=r.get(f)||null;it(m,g)||(l==="retain"&&u(),c[f]=m)}else if(!o.deleted){i.set(f,g);const m=c[f];m!==void 0&&(it(m,g)?m!==null&&o.delete(s):(l==="retain"&&u(),g===null?delete c[f]:c[f]=g))}o.deleted||(l==="insert"&&u(),Lt(r,o.content));break}}o=o.right}for(u();e.length>0;){const f=e[e.length-1];if(f.retain!==void 0&&f.attributes===void 0)e.pop();else break}}),this._delta=e}return this._delta}}class It extends x{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this._length}_integrate(t,e){super._integrate(t,e);try{this._pending.forEach(s=>s())}catch(s){console.error(s)}this._pending=null}_copy(){return new It}clone(){const t=new It;return t.applyDelta(this.toDelta()),t}_callObserver(t,e){super._callObserver(t,e);const s=new mo(this,t,e);fe(this,t,s),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){let t="",e=this._start;for(;e!==null;)!e.deleted&&e.countable&&e.content.constructor===j&&(t+=e.content.str),e=e.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:e=!0}={}){this.doc!==null?_(this.doc,s=>{const r=new cn(null,this._start,0,new Map);for(let i=0;i<t.length;i++){const o=t[i];if(o.insert!==void 0){const l=!e&&typeof o.insert=="string"&&i===t.length-1&&r.right===null&&o.insert.slice(-1)===`
3
- `?o.insert.slice(0,-1):o.insert;(typeof l!="string"||l.length>0)&&an(s,this,r,l,o.attributes||{})}else o.retain!==void 0?Fs(s,this,r,o.retain,o.attributes||{}):o.delete!==void 0&&Hs(s,r,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,e,s){const r=[],i=new Map,o=this.doc;let l="",c=this._start;function a(){if(l.length>0){const d={};let u=!1;i.forEach((g,m)=>{u=!0,d[m]=g});const f={insert:l};u&&(f.attributes=d),r.push(f),l=""}}const h=()=>{for(;c!==null;){if($t(c,t)||e!==void 0&&$t(c,e))switch(c.content.constructor){case j:{const d=i.get("ychange");t!==void 0&&!$t(c,t)?(d===void 0||d.user!==c.id.client||d.type!=="removed")&&(a(),i.set("ychange",s?s("removed",c.id):{type:"removed"})):e!==void 0&&!$t(c,e)?(d===void 0||d.user!==c.id.client||d.type!=="added")&&(a(),i.set("ychange",s?s("added",c.id):{type:"added"})):d!==void 0&&(a(),i.delete("ychange")),l+=c.content.str;break}case q:case pt:{a();const d={insert:c.content.getContent()[0]};if(i.size>0){const u={};d.attributes=u,i.forEach((f,g)=>{u[g]=f})}r.push(d);break}case A:$t(c,t)&&(a(),Lt(i,c.content));break}c=c.right}a()};return t||e?_(o,d=>{t&&Ze(d,t),e&&Ze(d,e),h()},"cleanup"):h(),r}insert(t,e,s){if(e.length<=0)return;const r=this.doc;r!==null?_(r,i=>{const o=me(i,this,t);s||(s={},o.currentAttributes.forEach((l,c)=>{s[c]=l})),an(i,this,o,e,s)}):this._pending.push(()=>this.insert(t,e,s))}insertEmbed(t,e,s={}){const r=this.doc;r!==null?_(r,i=>{const o=me(i,this,t);an(i,this,o,e,s)}):this._pending.push(()=>this.insertEmbed(t,e,s))}delete(t,e){if(e===0)return;const s=this.doc;s!==null?_(s,r=>{Hs(r,me(r,this,t),e)}):this._pending.push(()=>this.delete(t,e))}format(t,e,s){if(e===0)return;const r=this.doc;r!==null?_(r,i=>{const o=me(i,this,t);o.right!==null&&Fs(i,this,o,e,s)}):this._pending.push(()=>this.format(t,e,s))}removeAttribute(t){this.doc!==null?_(this.doc,e=>{pe(e,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,e){this.doc!==null?_(this.doc,s=>{on(s,this,t,e)}):this._pending.push(()=>this.setAttribute(t,e))}getAttribute(t){return ln(this,t)}getAttributes(){return Ts(this)}_write(t){t.writeTypeRef(Bo)}}const yo=n=>new It;class hn{constructor(t,e=()=>!0){this._filter=e,this._root=t,this._currentNode=t._start,this._firstCall=!0}[Symbol.iterator](){return this}next(){let t=this._currentNode,e=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(e)))do if(e=t.content.type,!t.deleted&&(e.constructor===zt||e.constructor===gt)&&e._start!==null)t=e._start;else for(;t!==null;)if(t.right!==null){t=t.right;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})}}class gt extends x{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new gt}clone(){const t=new gt;return t.insert(0,this.toArray().map(e=>e instanceof x?e.clone():e)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new hn(this,t)}querySelector(t){t=t.toUpperCase();const s=new hn(this,r=>r.nodeName&&r.nodeName.toUpperCase()===t).next();return s.done?null:s.value}querySelectorAll(t){return t=t.toUpperCase(),tt(new hn(this,e=>e.nodeName&&e.nodeName.toUpperCase()===t))}_callObserver(t,e){fe(this,t,new _o(this,e,t))}toString(){return Ls(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,e={},s){const r=t.createDocumentFragment();return s!==void 0&&s._createAssociation(r,this),Kt(this,i=>{r.insertBefore(i.toDOM(t,e,s),null)}),r}insert(t,e){this.doc!==null?_(this.doc,s=>{Ms(s,this,t,e)}):this._prelimContent.splice(t,0,...e)}insertAfter(t,e){if(this.doc!==null)_(this.doc,s=>{const r=t&&t instanceof x?t._item:t;ge(s,this,r,e)});else{const s=this._prelimContent,r=t===null?0:s.findIndex(i=>i===t)+1;if(r===0&&t!==null)throw W("Reference item not found");s.splice(r,0,...e)}}delete(t,e=1){this.doc!==null?_(this.doc,s=>{xs(s,this,t,e)}):this._prelimContent.splice(t,e)}toArray(){return As(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Is(this,t)}slice(t=0,e=this.length){return Cs(this,t,e)}forEach(t){Kt(this,t)}_write(t){t.writeTypeRef(Fo)}}const bo=n=>new gt;class zt extends gt{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,e){super._integrate(t,e),this._prelimAttrs.forEach((s,r)=>{this.setAttribute(r,s)}),this._prelimAttrs=null}_copy(){return new zt(this.nodeName)}clone(){const t=new zt(this.nodeName),e=this.getAttributes();return Or(e,(s,r)=>{typeof s=="string"&&t.setAttribute(r,s)}),t.insert(0,this.toArray().map(s=>s instanceof x?s.clone():s)),t}toString(){const t=this.getAttributes(),e=[],s=[];for(const l in t)s.push(l);s.sort();const r=s.length;for(let l=0;l<r;l++){const c=s[l];e.push(c+'="'+t[c]+'"')}const i=this.nodeName.toLocaleLowerCase(),o=e.length>0?" "+e.join(" "):"";return`<${i}${o}>${super.toString()}</${i}>`}removeAttribute(t){this.doc!==null?_(this.doc,e=>{pe(e,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,e){this.doc!==null?_(this.doc,s=>{on(s,this,t,e)}):this._prelimAttrs.set(t,e)}getAttribute(t){return ln(this,t)}hasAttribute(t){return Us(this,t)}getAttributes(){return Ts(this)}toDOM(t=document,e={},s){const r=t.createElement(this.nodeName),i=this.getAttributes();for(const o in i){const l=i[o];typeof l=="string"&&r.setAttribute(o,l)}return Kt(this,o=>{r.appendChild(o.toDOM(t,e,s))}),s!==void 0&&s._createAssociation(r,this),r}_write(t){t.writeTypeRef(No),t.writeKey(this.nodeName)}}const ko=n=>new zt(n.readKey());class _o extends ue{constructor(t,e,s){super(t,s),this.childListChanged=!1,this.attributesChanged=new Set,e.forEach(r=>{r===null?this.childListChanged=!0:this.attributesChanged.add(r)})}}class ye extends ft{constructor(t){super(),this.hookName=t}_copy(){return new ye(this.hookName)}clone(){const t=new ye(this.hookName);return this.forEach((e,s)=>{t.set(s,e)}),t}toDOM(t=document,e={},s){const r=e[this.hookName];let i;return r!==void 0?i=r.createDom(this):i=document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),s!==void 0&&s._createAssociation(i,this),i}_write(t){t.writeTypeRef(Vo),t.writeKey(this.hookName)}}const So=n=>new ye(n.readKey());class be extends It{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new be}clone(){const t=new be;return t.applyDelta(this.toDelta()),t}toDOM(t=document,e,s){const r=t.createTextNode(this.toString());return s!==void 0&&s._createAssociation(r,this),r}toString(){return this.toDelta().map(t=>{const e=[];for(const r in t.attributes){const i=[];for(const o in t.attributes[r])i.push({key:o,value:t.attributes[r][o]});i.sort((o,l)=>o.key<l.key?-1:1),e.push({nodeName:r,attrs:i})}e.sort((r,i)=>r.nodeName<i.nodeName?-1:1);let s="";for(let r=0;r<e.length;r++){const i=e[r];s+=`<${i.nodeName}`;for(let o=0;o<i.attrs.length;o++){const l=i.attrs[o];s+=` ${l.key}="${l.value}"`}s+=">"}s+=t.insert;for(let r=e.length-1;r>=0;r--)s+=`</${e[r].nodeName}>`;return s}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(Ho)}}const Do=n=>new be;class un{constructor(t,e){this.id=t,this.length=e}get deleted(){throw V()}mergeWith(t){return!1}write(t,e,s){throw V()}integrate(t,e){throw V()}}const Eo=0;class R extends un{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){e>0&&(this.id.clock+=e,this.length-=e),ps(t.doc.store,this)}write(t,e){t.writeInfo(Eo),t.writeLen(this.length-e)}getMissing(t,e){return null}}class Yt{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Yt(this.content)}splice(t){throw V()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeBuf(this.content)}getRef(){return 3}}const Co=n=>new Yt(n.readBuf());class Xt{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Xt(this.len)}splice(t){const e=new Xt(this.len-t);return this.len=t,e}mergeWith(t){return this.len+=t.len,!0}integrate(t,e){oe(t.deleteSet,e.id.client,e.id.clock,this.len),e.markDeleted()}delete(t){}gc(t){}write(t,e){t.writeLen(this.len-e)}getRef(){return 1}}const Ao=n=>new Xt(n.readLen()),$s=(n,t)=>new ut({guid:n,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Jt{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const e={};this.opts=e,t.gc||(e.gc=!1),t.autoLoad&&(e.autoLoad=!0),t.meta!==null&&(e.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Jt($s(this.doc.guid,this.opts))}splice(t){throw V()}mergeWith(t){return!1}integrate(t,e){this.doc._item=e,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,e){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}const Lo=n=>new Jt($s(n.readString(),n.readAny()));class pt{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new pt(this.embed)}splice(t){throw V()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeJSON(this.embed)}getRef(){return 5}}const Io=n=>new pt(n.readJSON());class A{constructor(t,e){this.key=t,this.value=e}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new A(this.key,this.value)}splice(t){throw V()}mergeWith(t){return!1}integrate(t,e){const s=e.parent;s._searchMarker=null,s._hasFormatting=!0}delete(t){}gc(t){}write(t,e){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}const vo=n=>new A(n.readKey(),n.readJSON());class ke{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ke(this.arr)}splice(t){const e=new ke(this.arr.slice(t));return this.arr=this.arr.slice(0,t),e}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){const s=this.arr.length;t.writeLen(s-e);for(let r=e;r<s;r++){const i=this.arr[r];t.writeString(i===void 0?"undefined":JSON.stringify(i))}}getRef(){return 2}}const Mo=n=>{const t=n.readLen(),e=[];for(let s=0;s<t;s++){const r=n.readString();r==="undefined"?e.push(void 0):e.push(JSON.parse(r))}return new ke(e)};class wt{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new wt(this.arr)}splice(t){const e=new wt(this.arr.slice(t));return this.arr=this.arr.slice(0,t),e}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){const s=this.arr.length;t.writeLen(s-e);for(let r=e;r<s;r++){const i=this.arr[r];t.writeAny(i)}}getRef(){return 8}}const xo=n=>{const t=n.readLen(),e=[];for(let s=0;s<t;s++)e.push(n.readAny());return new wt(e)};class j{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new j(this.str)}splice(t){const e=new j(this.str.slice(t));this.str=this.str.slice(0,t);const s=this.str.charCodeAt(t-1);return s>=55296&&s<=56319&&(this.str=this.str.slice(0,t-1)+"�",e.str="�"+e.str.slice(1)),e}mergeWith(t){return this.str+=t.str,!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeString(e===0?this.str:this.str.slice(e))}getRef(){return 4}}const To=n=>new j(n.readString()),Uo=[ho,fo,yo,ko,bo,So,Do],Oo=0,Ro=1,Bo=2,No=3,Fo=4,Vo=5,Ho=6;class q{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new q(this.type._copy())}splice(t){throw V()}mergeWith(t){return!1}integrate(t,e){this.type._integrate(t.doc,e)}delete(t){let e=this.type._start;for(;e!==null;)e.deleted?e.id.clock<(t.beforeState.get(e.id.client)||0)&&t._mergeStructs.push(e):e.delete(t),e=e.right;this.type._map.forEach(s=>{s.deleted?s.id.clock<(t.beforeState.get(s.id.client)||0)&&t._mergeStructs.push(s):s.delete(t)}),t.changed.delete(this.type)}gc(t){let e=this.type._start;for(;e!==null;)e.gc(t,!0),e=e.right;this.type._start=null,this.type._map.forEach(s=>{for(;s!==null;)s.gc(t,!0),s=s.left}),this.type._map=new Map}write(t,e){this.type._write(t)}getRef(){return 7}}const $o=n=>new q(Uo[n.readTypeRef()](n)),_e=(n,t,e)=>{const{client:s,clock:r}=t.id,i=new L(b(s,r+e),t,b(s,r+e-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(e));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),t.redone!==null&&(i.redone=b(t.redone.client,t.redone.clock+e)),t.right=i,i.right!==null&&(i.right.left=i),n._mergeStructs.push(i),i.parentSub!==null&&i.right===null&&i.parent._map.set(i.parentSub,i),t.length=e,i};class L extends un{constructor(t,e,s,r,i,o,l,c){super(t,c.getLength()),this.origin=s,this.left=e,this.right=r,this.rightOrigin=i,this.parent=o,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?Bn:0}set marker(t){(this.info&Oe)>0!==t&&(this.info^=Oe)}get marker(){return(this.info&Oe)>0}get keep(){return(this.info&Rn)>0}set keep(t){this.keep!==t&&(this.info^=Rn)}get countable(){return(this.info&Bn)>0}get deleted(){return(this.info&Ue)>0}set deleted(t){this.deleted!==t&&(this.info^=Ue)}markDeleted(){this.info|=Ue}getMissing(t,e){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=M(e,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=M(e,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Ct&&this.id.client!==this.parent.client&&this.parent.clock>=M(e,this.parent.client))return this.parent.client;if(this.origin&&(this.left=ws(t,e,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=st(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===L&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===L&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Ct){const s=Qe(e,this.parent);s.constructor===R?this.parent=null:this.parent=s.content.type}return null}integrate(t,e){if(e>0&&(this.id.clock+=e,this.left=ws(t,t.doc.store,b(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(e),this.length-=e),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let s=this.left,r;if(s!==null)r=s.right;else 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;const i=new Set,o=new Set;for(;r!==null&&r!==this.right;){if(o.add(r),i.add(r),le(this.origin,r.origin)){if(r.id.client<this.id.client)s=r,i.clear();else if(le(this.rightOrigin,r.rightOrigin))break}else if(r.origin!==null&&o.has(Qe(t.doc.store,r.origin)))i.has(Qe(t.doc.store,r.origin))||(s=r,i.clear());else break;r=r.right}this.left=s}if(this.left!==null){const s=this.left.right;this.right=s,this.left.right=this}else{let s;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,this.parent._start=this;this.right=s}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),ps(t.doc.store,this),this.content.integrate(t,this),bs(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:b(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&le(t.origin,this.lastId)&&this.right===t&&le(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const e=this.parent._searchMarker;return e&&e.forEach(s=>{s.p===t&&(s.p=this,!this.deleted&&this.countable&&(s.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const e=this.parent;this.countable&&this.parentSub===null&&(e._length-=this.length),this.markDeleted(),oe(t.deleteSet,this.id.client,this.id.clock,this.length),bs(t,e,this.parentSub),this.content.delete(t)}}gc(t,e){if(!this.deleted)throw H();this.content.gc(t),e?Ji(t,this,new R(this.id,this.length)):this.content=new Xt(this.length)}write(t,e){const s=e>0?b(this.id.client,this.id.clock+e-1):this.origin,r=this.rightOrigin,i=this.parentSub,o=this.content.getRef()&ee|(s===null?0:O)|(r===null?0:J)|(i===null?0:Rt);if(t.writeInfo(o),s!==null&&t.writeLeftID(s),r!==null&&t.writeRightID(r),s===null&&r===null){const l=this.parent;if(l._item!==void 0){const c=l._item;if(c===null){const a=Xi(l);t.writeParentInfo(!0),t.writeString(a)}else t.writeParentInfo(!1),t.writeLeftID(c.id)}else l.constructor===String?(t.writeParentInfo(!0),t.writeString(l)):l.constructor===Ct?(t.writeParentInfo(!1),t.writeLeftID(l)):H();i!==null&&t.writeString(i)}this.content.write(t,e)}}const js=(n,t)=>jo[t&ee](n),jo=[()=>{H()},Ao,Mo,Co,To,Io,vo,$o,xo,Lo,()=>{H()}],Ko=10;class B extends un{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){H()}write(t,e){t.writeInfo(Ko),p(t.restEncoder,this.length-e)}getMissing(t,e){return null}}const Ks=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},zs="__ $YJS$ __";Ks[zs]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),Ks[zs]=!0;const Ys=new Map;class zo{constructor(t){this.room=t,this.onmessage=null,this._onChange=e=>e.key===t&&this.onmessage!==null&&this.onmessage({data:ni(e.newValue||"")}),Mr(this._onChange)}postMessage(t){xn.setItem(this.room,ei(Pr(t)))}close(){xr(this._onChange)}}const Yo=typeof BroadcastChannel>"u"?zo:BroadcastChannel,dn=n=>Y(Ys,n,()=>{const t=ot(),e=new Yo(n);return e.onmessage=s=>t.forEach(r=>r(s.data,"broadcastchannel")),{bc:e,subs:t}}),Xo=(n,t)=>(dn(n).subs.add(t),t),Jo=(n,t)=>{const e=dn(n),s=e.subs.delete(t);return s&&e.subs.size===0&&(e.bc.close(),Ys.delete(n)),s},vt=(n,t,e=null)=>{const s=dn(n);s.bc.postMessage(t),s.subs.forEach(r=>r(t,e))},Xs=0,fn=1,Js=2,gn=(n,t)=>{p(n,Xs);const e=zi(t);C(n,e)},Ws=(n,t,e)=>{p(n,fn),C(n,qe(t,e))},Wo=(n,t,e)=>Ws(t,e,T(n)),Gs=(n,t,e)=>{try{ls(t,T(n),e)}catch(s){console.error("Caught error while handling a Yjs update",s)}},Go=(n,t)=>{p(n,Js),C(n,t)},Po=Gs,qo=(n,t,e,s)=>{const r=w(n);switch(r){case Xs:Wo(n,t,e);break;case fn:Gs(n,e,s);break;case Js:Po(n,e,s);break;default:throw new Error("Unknown message type")}return r},Zo=0,Qo=(n,t,e)=>{switch(w(n)){case Zo:e(t,nt(n))}},pn=3e4;class tl extends Zt{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const e=ht();this.getLocalState()!==null&&pn/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const s=[];this.meta.forEach((r,i)=>{i!==this.clientID&&pn<=e-r.lastUpdated&&this.states.has(i)&&s.push(i)}),s.length>0&&wn(this,s,"timeout")},X(pn/10)),t.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(t){const e=this.clientID,s=this.meta.get(e),r=s===void 0?0:s.clock+1,i=this.states.get(e);t===null?this.states.delete(e):this.states.set(e,t),this.meta.set(e,{clock:r,lastUpdated:ht()});const o=[],l=[],c=[],a=[];t===null?a.push(e):i==null?t!=null&&o.push(e):(l.push(e),Ot(i,t)||c.push(e)),(o.length>0||c.length>0||a.length>0)&&this.emit("change",[{added:o,updated:c,removed:a},"local"]),this.emit("update",[{added:o,updated:l,removed:a},"local"])}setLocalStateField(t,e){const s=this.getLocalState();s!==null&&this.setLocalState({...s,[t]:e})}getStates(){return this.states}}const wn=(n,t,e)=>{const s=[];for(let r=0;r<t.length;r++){const i=t[r];if(n.states.has(i)){if(n.states.delete(i),i===n.clientID){const o=n.meta.get(i);n.meta.set(i,{clock:o.clock+1,lastUpdated:ht()})}s.push(i)}}s.length>0&&(n.emit("change",[{added:[],updated:[],removed:s},e]),n.emit("update",[{added:[],updated:[],removed:s},e]))},Wt=(n,t,e=n.states)=>{const s=t.length,r=U();p(r,s);for(let i=0;i<s;i++){const o=t[i],l=e.get(o)||null,c=n.meta.get(o).clock;p(r,o),p(r,c),at(r,JSON.stringify(l))}return D(r)},el=(n,t,e)=>{const s=et(t),r=ht(),i=[],o=[],l=[],c=[],a=w(s);for(let h=0;h<a;h++){const d=w(s);let u=w(s);const f=JSON.parse(nt(s)),g=n.meta.get(d),m=n.states.get(d),E=g===void 0?0:g.clock;(E<u||E===u&&f===null&&n.states.has(d))&&(f===null?d===n.clientID&&n.getLocalState()!=null?u++:n.states.delete(d):n.states.set(d,f),n.meta.set(d,{clock:u,lastUpdated:r}),g===void 0&&f!==null?i.push(d):g!==void 0&&f===null?c.push(d):f!==null&&(Ot(f,m)||l.push(d),o.push(d)))}(i.length>0||l.length>0||c.length>0)&&n.emit("change",[{added:i,updated:l,removed:c},e]),(i.length>0||o.length>0||c.length>0)&&n.emit("update",[{added:i,updated:o,removed:c},e])},nl=n=>Rr(n,(t,e)=>`${encodeURIComponent(e)}=${encodeURIComponent(t)}`).join("&");var mt=0,Ps=3,Mt=1,sl=2,rl=typeof window>"u";function il(n,t){if(!n)throw new Error(t)}var Gt=[];Gt[mt]=(n,t,e,s,r)=>{p(n,mt);const i=qo(t,n,e.doc,e);s&&i===fn&&!e.synced&&(e.synced=!0)},Gt[Ps]=(n,t,e,s,r)=>{p(n,Mt),C(n,Wt(e.awareness,Array.from(e.awareness.getStates().keys())))},Gt[Mt]=(n,t,e,s,r)=>{el(e.awareness,T(t),e)},Gt[sl]=(n,t,e,s,r)=>{Qo(t,e.doc,(i,o)=>ol(e,o))};var qs=3e4;function ol(n,t){console.warn(`Permission denied to access ${n.url}.
4
- ${t}`)}function Zs(n,t,e){const s=et(t),r=U(),i=w(s),o=n.messageHandlers[i];return o?o(r,s,n,e,i):console.error("Unable to compute message"),r}function Qs(n){if(n.shouldConnect&&n.ws===null){const t=new n._WS(n.url);t.binaryType="arraybuffer",n.ws=t,n.wsconnecting=!0,n.wsconnected=!1,n.synced=!1,t.onmessage=e=>{if(typeof e.data=="string")return;n.wsLastMessageReceived=ht();const s=Zs(n,new Uint8Array(e.data),!0);He(s)>1&&t.send(D(s))},t.onerror=e=>{n.emit("connection-error",[e,n])},t.onclose=e=>{n.emit("connection-close",[e,n]),n.ws=null,n.wsconnecting=!1,n.wsconnected?(n.wsconnected=!1,n.synced=!1,wn(n.awareness,Array.from(n.awareness.getStates().keys()).filter(s=>s!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Qs,Ie(_r(2,n.wsUnsuccessfulReconnects)*100,n.maxBackoffTime),n)},t.onopen=()=>{n.wsLastMessageReceived=ht(),n.wsconnecting=!1,n.wsconnected=!0,n.wsUnsuccessfulReconnects=0,n.emit("status",[{status:"connected"}]);const e=U();if(p(e,mt),gn(e,n.doc),t.send(D(e)),n.awareness.getLocalState()!==null){const s=U();p(s,Mt),C(s,Wt(n.awareness,[n.doc.clientID])),t.send(D(s))}},n.emit("status",[{status:"connecting"}])}}function mn(n,t){const e=n.ws;n.wsconnected&&e&&e.readyState===e.OPEN&&e.send(t),n.bcconnected&&vt(n.bcChannel,t,n)}var ll=class extends Zt{constructor(t,e,s,{connect:r=!0,awareness:i=new tl(s),params:o={},WebSocketPolyfill:l=WebSocket,resyncInterval:c=-1,maxBackoffTime:a=2500,disableBc:h=rl}={}){super();y(this,"maxBackoffTime");y(this,"bcChannel");y(this,"url");y(this,"roomname");y(this,"doc");y(this,"_WS");y(this,"awareness");y(this,"wsconnected");y(this,"wsconnecting");y(this,"bcconnected");y(this,"disableBc");y(this,"wsUnsuccessfulReconnects");y(this,"messageHandlers");y(this,"_synced");y(this,"ws");y(this,"wsLastMessageReceived");y(this,"shouldConnect");y(this,"_resyncInterval");y(this,"_bcSubscriber");y(this,"_updateHandler");y(this,"_awarenessUpdateHandler");y(this,"_unloadHandler");y(this,"_checkInterval");for(;t[t.length-1]==="/";)t=t.slice(0,t.length-1);const d=nl(o);this.maxBackoffTime=a,this.bcChannel=t+"/"+e,this.url=t+"/"+e+(d.length===0?"":"?"+d),this.roomname=e,this.doc=s,this._WS=l,this.awareness=i,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=h,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Gt.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=r,this._resyncInterval=0,c>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const u=U();p(u,mt),gn(u,s),this.ws.send(D(u))}},c)),this._bcSubscriber=(u,f)=>{if(f!==this){const g=Zs(this,new Uint8Array(u),!1);He(g)>1&&vt(this.bcChannel,D(g),this)}},this._updateHandler=(u,f)=>{if(f!==this){const g=U();p(g,mt),Go(g,u),mn(this,D(g))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:u,updated:f,removed:g},m)=>{const E=u.concat(f).concat(g),Q=U();p(Q,Mt),C(Q,Wt(i,E)),mn(this,D(Q))},this._unloadHandler=()=>{wn(this.awareness,[s.clientID],"window unload")},typeof window<"u"?window.addEventListener("unload",this._unloadHandler):typeof process<"u"&&process.on("exit",this._unloadHandler),i.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&qs<ht()-this.wsLastMessageReceived&&(il(this.ws!==null,"ws must not be null"),this.ws.close())},qs/10),r&&this.connect()}get synced(){return this._synced}set synced(t){this._synced!==t&&(this._synced=t,this.emit("synced",[t]),this.emit("sync",[t]))}destroy(){this._resyncInterval!==0&&clearInterval(this._resyncInterval),clearInterval(this._checkInterval),this.disconnect(),typeof window<"u"?window.removeEventListener("unload",this._unloadHandler):typeof process<"u"&&process.off("exit",this._unloadHandler),this.awareness.off("update",this._awarenessUpdateHandler),this.doc.off("update",this._updateHandler),super.destroy()}connectBc(){if(this.disableBc)return;this.bcconnected||(Xo(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const t=U();p(t,mt),gn(t,this.doc),vt(this.bcChannel,D(t),this);const e=U();p(e,mt),Ws(e,this.doc),vt(this.bcChannel,D(e),this);const s=U();p(s,Ps),vt(this.bcChannel,D(s),this);const r=U();p(r,Mt),C(r,Wt(this.awareness,[this.doc.clientID])),vt(this.bcChannel,D(r),this)}disconnectBc(){const t=U();p(t,Mt),C(t,Wt(this.awareness,[this.doc.clientID],new Map)),mn(this,D(t)),this.bcconnected&&(Jo(this.bcChannel,this._bcSubscriber),this.bcconnected=!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&this.ws.close()}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(Qs(this),this.connectBc())}};function cl(){if(crypto.randomUUID)return crypto.randomUUID();let n=new Date().getTime(),t=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){let s=Math.random()*16;return n>0?(s=(n+s)%16|0,n=Math.floor(n/16)):(s=(t+s)%16|0,t=Math.floor(t/16)),(e==="x"?s:s&3|8).toString(16)})}function tr(n,t,e){if(typeof n!==e)throw new Error(`Invalid "${t}" parameter provided to YPartyKitProvider. Expected: ${e}, received: ${n}`)}var al=class extends WebSocket{send(n){typeof n!="string"&&wr(n,t=>super.send(t))}},hl=(dr=class extends ll{constructor(t,e,s,r={}){tr(t,"host","string"),tr(e,"room","string"),t=t.replace(/^(http|https|ws|wss):\/\//,""),t.endsWith("/")&&t.slice(0,-1);const i=`${t.startsWith("localhost:")||t.startsWith("127.0.0.1:")?"ws":"wss"}://${t}${r.party?`/parties/${r.party}`:"/party"}`,o=r.connectionId??cl(),{params:l,connect:c=!0,...a}=r,h={...a,connect:!1,WebSocketPolyfill:al};super(i,e,s??new ut,h);y(this,"id");gr(this,bt,void 0);this.id=o,pr(this,bt,l),c&&this.connect()}connect(){Promise.resolve(typeof Ce(this,bt)=="function"?Ce(this,bt).call(this):Ce(this,bt)).then(t=>{const e=new URLSearchParams([["_pk",this.id]]);if(t)for(const[r,i]of Object.entries(t))i!=null&&e.append(r,i);const s=new URL(this.url);s.search=e.toString(),this.url=s.toString(),super.connect()}).catch(t=>{throw console.error("Failed to open connecton to PartyKit",t),new Error(t)})}},bt=new WeakMap,dr);const yt=n=>St((t,e)=>{n.onerror=s=>e(new Error(s.target.error)),n.onsuccess=s=>t(s.target.result)}),ul=(n,t)=>St((e,s)=>{const r=indexedDB.open(n);r.onupgradeneeded=i=>t(i.target.result),r.onerror=i=>s(W(i.target.error)),r.onsuccess=i=>{const o=i.target.result;o.onversionchange=()=>{o.close()},typeof addEventListener<"u"&&addEventListener("unload",()=>o.close()),e(o)}}),dl=n=>yt(indexedDB.deleteDatabase(n)),fl=(n,t)=>t.forEach(e=>n.createObjectStore.apply(n,e)),Pt=(n,t,e="readwrite")=>{const s=n.transaction(t,e);return t.map(r=>_l(s,r))},er=(n,t)=>yt(n.count(t)),gl=(n,t)=>yt(n.get(t)),nr=(n,t)=>yt(n.delete(t)),pl=(n,t,e)=>yt(n.put(t,e)),yn=(n,t)=>yt(n.add(t)),wl=(n,t,e)=>yt(n.getAll(t,e)),ml=(n,t,e)=>{let s=null;return kl(n,t,r=>(s=r,!1),e).then(()=>s)},yl=(n,t=null)=>ml(n,t,"prev"),bl=(n,t)=>St((e,s)=>{n.onerror=s,n.onsuccess=async r=>{const i=r.target.result;if(i===null||await t(i)===!1)return e();i.continue()}}),kl=(n,t,e,s="next")=>bl(n.openKeyCursor(t,s),r=>e(r.key)),_l=(n,t)=>n.objectStore(t),Sl=(n,t)=>IDBKeyRange.upperBound(n,t),Dl=(n,t)=>IDBKeyRange.lowerBound(n,t),bn="custom",sr="updates",rr=500,ir=(n,t=()=>{},e=()=>{})=>{const[s]=Pt(n.db,[sr]);return wl(s,Dl(n._dbref,!1)).then(r=>{n._destroyed||(t(s),_(n.doc,()=>{r.forEach(i=>ls(n.doc,i))},n,!1),e(s))}).then(()=>yl(s).then(r=>{n._dbref=r+1})).then(()=>er(s).then(r=>{n._dbsize=r})).then(()=>s)},El=(n,t=!0)=>ir(n).then(e=>{(t||n._dbsize>=rr)&&yn(e,qe(n.doc)).then(()=>nr(e,Sl(n._dbref,!0))).then(()=>er(e).then(s=>{n._dbsize=s}))});class Cl extends Zt{constructor(t,e){super(),this.doc=e,this.name=t,this._dbref=0,this._dbsize=0,this._destroyed=!1,this.db=null,this.synced=!1,this._db=ul(t,s=>fl(s,[["updates",{autoIncrement:!0}],["custom"]])),this.whenSynced=St(s=>this.on("synced",()=>s(this))),this._db.then(s=>{this.db=s,ir(this,o=>yn(o,qe(e)),()=>{if(this._destroyed)return this;this.synced=!0,this.emit("synced",[this])})}),this._storeTimeout=1e3,this._storeTimeoutId=null,this._storeUpdate=(s,r)=>{if(this.db&&r!==this){const[i]=Pt(this.db,[sr]);yn(i,s),++this._dbsize>=rr&&(this._storeTimeoutId!==null&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout(()=>{El(this,!1),this._storeTimeoutId=null},this._storeTimeout))}},e.on("update",this._storeUpdate),this.destroy=this.destroy.bind(this),e.on("destroy",this.destroy)}destroy(){return this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this.doc.off("update",this._storeUpdate),this.doc.off("destroy",this.destroy),this._destroyed=!0,this._db.then(t=>{t.close()})}clearData(){return this.destroy().then(()=>{dl(this.name)})}get(t){return this._db.then(e=>{const[s]=Pt(e,[bn],"readonly");return gl(s,t)})}set(t,e){return this._db.then(s=>{const[r]=Pt(s,[bn]);return pl(r,e,t)})}del(t){return this._db.then(e=>{const[s]=Pt(e,[bn]);return nr(s,t)})}}const tc="",Al={ctrlKey:"Control",altKey:"Alt",shiftKey:"Shift",metaKey:"Meta"},Ll="can-duplicate-to";var kn=(n=>(n.CanPlay="can-play",n.CanMove="can-move",n.CanSpin="can-spin",n.CanGrow="can-grow",n.CanToggle="can-toggle",n.CanDuplicate="can-duplicate",n))(kn||{});function Il(n){return n.id}const or=`url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='44' height='53' viewport='0 0 100 100' style='fill:black;font-size:26px;'><text y='40%'>🚿</text></svg>")
1
+ (function(S,k){typeof exports=="object"&&typeof module<"u"?k(exports):typeof define=="function"&&define.amd?define(["exports"],k):(S=typeof globalThis<"u"?globalThis:S||self,k(S.playhtml={}))})(this,function(S){var bt,dr;"use strict";var Kl=Object.defineProperty;var zl=(S,k,I)=>k in S?Kl(S,k,{enumerable:!0,configurable:!0,writable:!0,value:I}):S[k]=I;var y=(S,k,I)=>(zl(S,typeof k!="symbol"?k+"":k,I),I),fr=(S,k,I)=>{if(!k.has(S))throw TypeError("Cannot "+I)};var Ae=(S,k,I)=>(fr(S,k,"read from private field"),I?I.call(S):k.get(S)),gr=(S,k,I)=>{if(k.has(S))throw TypeError("Cannot add the same private member more than once");k instanceof WeakSet?k.add(S):k.set(S,I)},pr=(S,k,I,xt)=>(fr(S,k,"write to private field"),xt?xt.call(S,I):k.set(S,I),I);var k=1e6,I="y-pk-batch",xt=!1,wr=(n,t)=>{if(n.byteLength<=k){t(n);return}xt||(console.warn("[y-partykit]","The Y.js update size exceeds 1MB, which is the maximum size for an individual update. The update will be split into chunks. This is an experimental feature.",`Message size: ${(n.byteLength/1e3/1e3).toFixed(1)}MB`),xt=!0);const e=(Date.now()+Math.random()).toString(36).substring(10),s=Math.ceil(n.byteLength/k);t(An({id:e,type:"start",size:n.byteLength,count:s}));let r=0,i=0;for(let o=0;o<s;o++){const l=n.slice(k*o,k*(o+1));t(l),i+=1,r+=l.byteLength}t(An({id:e,type:"end",size:r,count:i}))};function An(n){return`${I}#${JSON.stringify(n)}`}const N=()=>new Map,Le=n=>{const t=N();return n.forEach((e,s)=>{t.set(s,e)}),t},Y=(n,t,e)=>{let s=n.get(t);return s===void 0&&n.set(t,s=e()),s},mr=(n,t)=>{const e=[];for(const[s,r]of n)e.push(t(r,s));return e},yr=(n,t)=>{for(const[e,s]of n)if(t(s,e))return!0;return!1},ot=()=>new Set,Ie=n=>n[n.length-1],br=(n,t)=>{for(let e=0;e<t.length;e++)n.push(t[e])},tt=Array.from,kr=Array.isArray;class Zt{constructor(){this._observers=N()}on(t,e){Y(this._observers,t,ot).add(e)}once(t,e){const s=(...r)=>{this.off(t,s),e(...r)};this.on(t,s)}off(t,e){const s=this._observers.get(t);s!==void 0&&(s.delete(e),s.size===0&&this._observers.delete(t))}emit(t,e){return tt((this._observers.get(t)||N()).values()).forEach(s=>s(...e))}destroy(){this._observers=N()}}const X=Math.floor,Qt=Math.abs,ve=(n,t)=>n<t?n:t,lt=(n,t)=>n>t?n:t,_r=Math.pow,Ln=n=>n!==0?n<0:1/n<0,Sr=String.fromCharCode,Dr=n=>n.toLowerCase(),Er=/^\s*/g,Cr=n=>n.replace(Er,""),Ar=/([A-Z])/g,In=(n,t)=>Cr(n.replace(Ar,e=>`${t}${Dr(e)}`)),Lr=n=>{const t=unescape(encodeURIComponent(n)),e=t.length,s=new Uint8Array(e);for(let r=0;r<e;r++)s[r]=t.codePointAt(r);return s},Tt=typeof TextEncoder<"u"?new TextEncoder:null,Ir=Tt?n=>Tt.encode(n):Lr;let Ut=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Ut&&Ut.decode(new Uint8Array).length===1&&(Ut=null);const vn=n=>n===void 0?null:n;class vr{constructor(){this.map=new Map}setItem(t,e){this.map.set(t,e)}getItem(t){return this.map.get(t)}}let Mn=new vr,Me=!0;try{typeof localStorage<"u"&&(Mn=localStorage,Me=!1)}catch{}const xn=Mn,Mr=n=>Me||addEventListener("storage",n),xr=n=>Me||removeEventListener("storage",n),Tr=Object.assign,Ur=Object.keys,Or=(n,t)=>{for(const e in n)t(n[e],e)},Rr=(n,t)=>{const e=[];for(const s in n)e.push(t(n[s],s));return e},te=n=>Ur(n).length,Br=n=>{for(const t in n)return!1;return!0},Nr=(n,t)=>{for(const e in n)if(!t(n[e],e))return!1;return!0},Tn=(n,t)=>Object.prototype.hasOwnProperty.call(n,t),Fr=(n,t)=>n===t||te(n)===te(t)&&Nr(n,(e,s)=>(e!==void 0||Tn(t,s))&&t[s]===e),xe=(n,t,e=0)=>{try{for(;e<n.length;e++)n[e](...t)}finally{e<n.length&&xe(n,t,e+1)}},Vr=n=>n,Hr=(n,t)=>n===t,Ot=(n,t)=>{if(n==null||t==null)return Hr(n,t);if(n.constructor!==t.constructor)return!1;if(n===t)return!0;switch(n.constructor){case ArrayBuffer:n=new Uint8Array(n),t=new Uint8Array(t);case Uint8Array:{if(n.byteLength!==t.byteLength)return!1;for(let e=0;e<n.length;e++)if(n[e]!==t[e])return!1;break}case Set:{if(n.size!==t.size)return!1;for(const e of n)if(!t.has(e))return!1;break}case Map:{if(n.size!==t.size)return!1;for(const e of n.keys())if(!t.has(e)||!Ot(n.get(e),t.get(e)))return!1;break}case Object:if(te(n)!==te(t))return!1;for(const e in n)if(!Tn(n,e)||!Ot(n[e],t[e]))return!1;break;case Array:if(n.length!==t.length)return!1;for(let e=0;e<n.length;e++)if(!Ot(n[e],t[e]))return!1;break;default:return!1}return!0},$r=(n,t)=>t.includes(n),kt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name),Un=typeof window<"u"&&typeof document<"u"&&!kt;let F;const jr=()=>{if(F===void 0)if(kt){F=N();const n=process.argv;let t=null;for(let e=0;e<n.length;e++){const s=n[e];s[0]==="-"?(t!==null&&F.set(t,""),t=s):t!==null&&(F.set(t,s),t=null)}t!==null&&F.set(t,"")}else typeof location=="object"?(F=N(),(location.search||"?").slice(1).split("&").forEach(n=>{if(n.length!==0){const[t,e]=n.split("=");F.set(`--${In(t,"-")}`,e),F.set(`-${In(t,"-")}`,e)}})):F=N();return F},Te=n=>jr().has(n),Ue=n=>vn(kt?process.env[n.toUpperCase()]:xn.getItem(n));(n=>Te("--"+n)||Ue(n)!==null)("production");const On=kt&&$r(process.env.FORCE_COLOR,["true","1","2"]),Kr=!Te("no-colors")&&(!kt||process.stdout.isTTY||On)&&(!kt||Te("color")||On||Ue("COLORTERM")!==null||(Ue("TERM")||"").includes("color")),Rn=1,Bn=2,Oe=4,Re=8,Rt=32,J=64,O=128,ee=31,Be=63,ct=127,zr=2147483647,Nn=Number.MAX_SAFE_INTEGER,Yr=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&X(n)===n),W=n=>new Error(n),V=()=>{throw W("Method unimplemented")},H=()=>{throw W("Unexpected case")},Fn=W("Unexpected end of array"),Vn=W("Integer out of Range");class ne{constructor(t){this.arr=t,this.pos=0}}const et=n=>new ne(n),Xr=n=>n.pos!==n.arr.length,Jr=(n,t)=>{const e=He(n.arr.buffer,n.pos+n.arr.byteOffset,t);return n.pos+=t,e},T=n=>Jr(n,w(n)),_t=n=>n.arr[n.pos++],w=n=>{let t=0,e=1;const s=n.arr.length;for(;n.pos<s;){const r=n.arr[n.pos++];if(t=t+(r&ct)*e,e*=128,r<O)return t;if(t>Nn)throw Vn}throw Fn},Ne=n=>{let t=n.arr[n.pos++],e=t&Be,s=64;const r=(t&J)>0?-1:1;if(!(t&O))return r*e;const i=n.arr.length;for(;n.pos<i;){if(t=n.arr[n.pos++],e=e+(t&ct)*s,s*=128,t<O)return r*e;if(e>Nn)throw Vn}throw Fn},nt=Ut?n=>Ut.decode(T(n)):n=>{let t=w(n);if(t===0)return"";{let e=String.fromCodePoint(_t(n));if(--t<100)for(;t--;)e+=String.fromCodePoint(_t(n));else for(;t>0;){const s=t<1e4?t:1e4,r=n.arr.subarray(n.pos,n.pos+s);n.pos+=s,e+=String.fromCodePoint.apply(null,r),t-=s}return decodeURIComponent(escape(e))}},Fe=(n,t)=>{const e=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,t);return n.pos+=t,e},Wr=[n=>{},n=>null,Ne,n=>Fe(n,4).getFloat32(0,!1),n=>Fe(n,8).getFloat64(0,!1),n=>Fe(n,8).getBigInt64(0,!1),n=>!1,n=>!0,nt,n=>{const t=w(n),e={};for(let s=0;s<t;s++){const r=nt(n);e[r]=Bt(n)}return e},n=>{const t=w(n),e=[];for(let s=0;s<t;s++)e.push(Bt(n));return e},T],Bt=n=>Wr[127-_t(n)](n);class Hn extends ne{constructor(t,e){super(t),this.reader=e,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Xr(this)?this.count=w(this)+1:this.count=-1),this.count--,this.s}}class se extends ne{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Ne(this);const t=Ln(this.s);this.count=1,t&&(this.s=-this.s,this.count=w(this)+2)}return this.count--,this.s}}class Ve extends ne{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=Ne(this),e=t&1;this.diff=X(t/2),this.count=1,e&&(this.count=w(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Gr{constructor(t){this.decoder=new se(t),this.str=nt(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),e=this.str.slice(this.spos,t);return this.spos=t,e}}const $n=n=>new Uint8Array(n),He=(n,t,e)=>new Uint8Array(n,t,e),Pr=n=>new Uint8Array(n),qr=n=>{let t="";for(let e=0;e<n.byteLength;e++)t+=Sr(n[e]);return btoa(t)},Zr=n=>Buffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),Qr=n=>{const t=atob(n),e=$n(t.length);for(let s=0;s<t.length;s++)e[s]=t.charCodeAt(s);return e},ti=n=>{const t=Buffer.from(n,"base64");return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)},ei=Un?qr:Zr,ni=Un?Qr:ti,si=n=>{const t=$n(n.byteLength);return t.set(n),t};class Nt{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const U=()=>new Nt,$e=n=>{let t=n.cpos;for(let e=0;e<n.bufs.length;e++)t+=n.bufs[e].length;return t},D=n=>{const t=new Uint8Array($e(n));let e=0;for(let s=0;s<n.bufs.length;s++){const r=n.bufs[s];t.set(r,e),e+=r.length}return t.set(He(n.cbuf.buffer,0,n.cpos),e),t},ri=(n,t)=>{const e=n.cbuf.length;e-n.cpos<t&&(n.bufs.push(He(n.cbuf.buffer,0,n.cpos)),n.cbuf=new Uint8Array(lt(e,t)*2),n.cpos=0)},v=(n,t)=>{const e=n.cbuf.length;n.cpos===e&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(e*2),n.cpos=0),n.cbuf[n.cpos++]=t},je=v,p=(n,t)=>{for(;t>ct;)v(n,O|ct&t),t=X(t/128);v(n,ct&t)},Ke=(n,t)=>{const e=Ln(t);for(e&&(t=-t),v(n,(t>Be?O:0)|(e?J:0)|Be&t),t=X(t/64);t>0;)v(n,(t>ct?O:0)|ct&t),t=X(t/128)},ze=new Uint8Array(3e4),ii=ze.length/3,oi=(n,t)=>{if(t.length<ii){const e=Tt.encodeInto(t,ze).written||0;p(n,e);for(let s=0;s<e;s++)v(n,ze[s])}else C(n,Ir(t))},li=(n,t)=>{const e=unescape(encodeURIComponent(t)),s=e.length;p(n,s);for(let r=0;r<s;r++)v(n,e.codePointAt(r))},at=Tt&&Tt.encodeInto?oi:li,re=(n,t)=>{const e=n.cbuf.length,s=n.cpos,r=ve(e-s,t.length),i=t.length-r;n.cbuf.set(t.subarray(0,r),s),n.cpos+=r,i>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(lt(e*2,i)),n.cbuf.set(t.subarray(r)),n.cpos=i)},C=(n,t)=>{p(n,t.byteLength),re(n,t)},Ye=(n,t)=>{ri(n,t);const e=new DataView(n.cbuf.buffer,n.cpos,t);return n.cpos+=t,e},ci=(n,t)=>Ye(n,4).setFloat32(0,t,!1),ai=(n,t)=>Ye(n,8).setFloat64(0,t,!1),hi=(n,t)=>Ye(n,8).setBigInt64(0,t,!1),jn=new DataView(new ArrayBuffer(4)),ui=n=>(jn.setFloat32(0,n),jn.getFloat32(0)===n),Ft=(n,t)=>{switch(typeof t){case"string":v(n,119),at(n,t);break;case"number":Yr(t)&&Qt(t)<=zr?(v(n,125),Ke(n,t)):ui(t)?(v(n,124),ci(n,t)):(v(n,123),ai(n,t));break;case"bigint":v(n,122),hi(n,t);break;case"object":if(t===null)v(n,126);else if(kr(t)){v(n,117),p(n,t.length);for(let e=0;e<t.length;e++)Ft(n,t[e])}else if(t instanceof Uint8Array)v(n,116),C(n,t);else{v(n,118);const e=Object.keys(t);p(n,e.length);for(let s=0;s<e.length;s++){const r=e[s];at(n,r),Ft(n,t[r])}}break;case"boolean":v(n,t?120:121);break;default:v(n,127)}};class Kn extends Nt{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&p(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const zn=n=>{n.count>0&&(Ke(n.encoder,n.count===1?n.s:-n.s),n.count>1&&p(n.encoder,n.count-2))};class ie{constructor(){this.encoder=new Nt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(zn(this),this.count=1,this.s=t)}toUint8Array(){return zn(this),D(this.encoder)}}const Yn=n=>{if(n.count>0){const t=n.diff*2+(n.count===1?0:1);Ke(n.encoder,t),n.count>1&&p(n.encoder,n.count-2)}};class Xe{constructor(){this.encoder=new Nt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(Yn(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return Yn(this),D(this.encoder)}}class di{constructor(){this.sarr=[],this.s="",this.lensE=new ie}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new Nt;return this.sarr.push(this.s),this.s="",at(t,this.sarr.join("")),re(t,this.lensE.toUint8Array()),D(t)}}const fi=crypto.getRandomValues.bind(crypto),Xn=()=>fi(new Uint32Array(1))[0],gi=[1e7]+-1e3+-4e3+-8e3+-1e11,pi=()=>gi.replace(/[018]/g,n=>(n^Xn()&15>>n/4).toString(16)),ht=Date.now,St=n=>new Promise(n);Promise.all.bind(Promise);class wi{constructor(t,e){this.left=t,this.right=e}}const G=(n,t)=>new wi(n,t);typeof DOMParser<"u"&&new DOMParser;const mi=n=>mr(n,(t,e)=>`${e}:${t};`).join(""),P=Symbol,Jn=P(),Wn=P(),yi=P(),bi=P(),ki=P(),Gn=P(),_i=P(),Pn=P(),Si=P(),Di=n=>{const t=[];let e=0;for(;e<n.length;e++){const s=n[e];s.constructor===String||s.constructor===Number||s.constructor===Object&&t.push(JSON.stringify(s))}return t},Ei={[Jn]:G("font-weight","bold"),[Wn]:G("font-weight","normal"),[yi]:G("color","blue"),[ki]:G("color","green"),[bi]:G("color","grey"),[Gn]:G("color","red"),[_i]:G("color","purple"),[Pn]:G("color","orange"),[Si]:G("color","black")},Ci=Kr?n=>{const t=[],e=[],s=N();let r=[],i=0;for(;i<n.length;i++){const o=n[i],l=Ei[o];if(l!==void 0)s.set(l.left,l.right);else if(o.constructor===String||o.constructor===Number){const c=mi(s);i>0||c.length>0?(t.push("%c"+o),e.push(c)):t.push(o)}else break}for(i>0&&(r=e,r.unshift(t.join("")));i<n.length;i++){const o=n[i];o instanceof Symbol||r.push(o)}return r}:Di,Ai=(...n)=>{console.log(...Ci(n)),Li.forEach(t=>t.print(n))},Li=ot(),qn=n=>({[Symbol.iterator](){return this},next:n}),Ii=(n,t)=>qn(()=>{let e;do e=n.next();while(!e.done&&!t(e.value));return e}),Je=(n,t)=>qn(()=>{const{done:e,value:s}=n.next();return{done:e,value:e?void 0:t(s)}});class We{constructor(t,e){this.clock=t,this.len=e}}class Vt{constructor(){this.clients=new Map}}const Zn=(n,t,e)=>t.clients.forEach((s,r)=>{const i=n.doc.store.clients.get(r);for(let o=0;o<s.length;o++){const l=s[o];ms(n,i,l.clock,l.len,e)}}),vi=(n,t)=>{let e=0,s=n.length-1;for(;e<=s;){const r=X((e+s)/2),i=n[r],o=i.clock;if(o<=t){if(t<o+i.len)return r;e=r+1}else s=r-1}return null},Qn=(n,t)=>{const e=n.clients.get(t.client);return e!==void 0&&vi(e,t.clock)!==null},Ge=n=>{n.clients.forEach(t=>{t.sort((r,i)=>r.clock-i.clock);let e,s;for(e=1,s=1;e<t.length;e++){const r=t[s-1],i=t[e];r.clock+r.len>=i.clock?r.len=lt(r.len,i.clock+i.len-r.clock):(s<e&&(t[s]=i),s++)}t.length=s})},Mi=n=>{const t=new Vt;for(let e=0;e<n.length;e++)n[e].clients.forEach((s,r)=>{if(!t.clients.has(r)){const i=s.slice();for(let o=e+1;o<n.length;o++)br(i,n[o].clients.get(r)||[]);t.clients.set(r,i)}});return Ge(t),t},oe=(n,t,e,s)=>{Y(n.clients,t,()=>[]).push(new We(e,s))},xi=()=>new Vt,Ti=n=>{const t=xi();return n.clients.forEach((e,s)=>{const r=[];for(let i=0;i<e.length;i++){const o=e[i];if(o.deleted){const l=o.id.clock;let c=o.length;if(i+1<e.length)for(let a=e[i+1];i+1<e.length&&a.deleted;a=e[++i+1])c+=a.length;r.push(new We(l,c))}}r.length>0&&t.clients.set(s,r)}),t},Dt=(n,t)=>{p(n.restEncoder,t.clients.size),tt(t.clients.entries()).sort((e,s)=>s[0]-e[0]).forEach(([e,s])=>{n.resetDsCurVal(),p(n.restEncoder,e);const r=s.length;p(n.restEncoder,r);for(let i=0;i<r;i++){const o=s[i];n.writeDsClock(o.clock),n.writeDsLen(o.len)}})},Pe=n=>{const t=new Vt,e=w(n.restDecoder);for(let s=0;s<e;s++){n.resetDsCurVal();const r=w(n.restDecoder),i=w(n.restDecoder);if(i>0){const o=Y(t.clients,r,()=>[]);for(let l=0;l<i;l++)o.push(new We(n.readDsClock(),n.readDsLen()))}}return t},ts=(n,t,e)=>{const s=new Vt,r=w(n.restDecoder);for(let i=0;i<r;i++){n.resetDsCurVal();const o=w(n.restDecoder),l=w(n.restDecoder),c=e.clients.get(o)||[],a=M(e,o);for(let h=0;h<l;h++){const d=n.readDsClock(),u=d+n.readDsLen();if(d<a){a<u&&oe(s,o,a,u-a);let f=$(c,d),g=c[f];for(!g.deleted&&g.id.clock<d&&(c.splice(f+1,0,_e(t,g,d-g.id.clock)),f++);f<c.length&&(g=c[f++],g.id.clock<u);)g.deleted||(u<g.id.clock+g.length&&c.splice(f,0,_e(t,g,u-g.id.clock)),g.delete(t))}else oe(s,o,d,u-d)}}if(s.clients.size>0){const i=new dt;return p(i.restEncoder,0),Dt(i,s),i.toUint8Array()}return null},es=Xn;class ut extends Zt{constructor({guid:t=pi(),collectionid:e=null,gc:s=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:o=!1,shouldLoad:l=!0}={}){super(),this.gc=s,this.gcFilter=r,this.clientID=es(),this.guid=t,this.collectionid=e,this.share=new Map,this.store=new gs,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=o,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.whenLoaded=St(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const c=()=>St(a=>{const h=d=>{(d===void 0||d===!0)&&(this.off("sync",h),a())};this.on("sync",h)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=a===void 0||a===!0,this.isLoaded||this.emit("load",[])}),this.whenSynced=c()}load(){const t=this._item;t!==null&&!this.shouldLoad&&_(t.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(tt(this.subdocs).map(t=>t.guid))}transact(t,e=null){return _(this,t,e)}get(t,e=x){const s=Y(this.share,t,()=>{const i=new e;return i._integrate(this,null),i}),r=s.constructor;if(e!==x&&r!==e)if(r===x){const i=new e;i._map=s._map,s._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=i}),i._start=s._start;for(let o=i._start;o!==null;o=o.right)o.parent=i;return i._length=s._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 s}getArray(t=""){return this.get(t,At)}getText(t=""){return this.get(t,It)}getMap(t=""){return this.get(t,ft)}getXmlFragment(t=""){return this.get(t,gt)}toJSON(){const t={};return this.share.forEach((e,s)=>{t[s]=e.toJSON()}),t}destroy(){tt(this.subdocs).forEach(e=>e.destroy());const t=this._item;if(t!==null){this._item=null;const e=t.content;e.doc=new ut({guid:this.guid,...e.opts,shouldLoad:!1}),e.doc._item=t,_(t.parent.doc,s=>{const r=e.doc;t.deleted||s.subdocsAdded.add(r),s.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}on(t,e){super.on(t,e)}off(t,e){super.off(t,e)}}class ns{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return w(this.restDecoder)}readDsLen(){return w(this.restDecoder)}}class ss extends ns{readLeftID(){return b(w(this.restDecoder),w(this.restDecoder))}readRightID(){return b(w(this.restDecoder),w(this.restDecoder))}readClient(){return w(this.restDecoder)}readInfo(){return _t(this.restDecoder)}readString(){return nt(this.restDecoder)}readParentInfo(){return w(this.restDecoder)===1}readTypeRef(){return w(this.restDecoder)}readLen(){return w(this.restDecoder)}readAny(){return Bt(this.restDecoder)}readBuf(){return si(T(this.restDecoder))}readJSON(){return JSON.parse(nt(this.restDecoder))}readKey(){return nt(this.restDecoder)}}class Ui{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=w(this.restDecoder),this.dsCurrVal}readDsLen(){const t=w(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class Et extends Ui{constructor(t){super(t),this.keys=[],w(t),this.keyClockDecoder=new Ve(T(t)),this.clientDecoder=new se(T(t)),this.leftClockDecoder=new Ve(T(t)),this.rightClockDecoder=new Ve(T(t)),this.infoDecoder=new Hn(T(t),_t),this.stringDecoder=new Gr(T(t)),this.parentInfoDecoder=new Hn(T(t),_t),this.typeRefDecoder=new se(T(t)),this.lenDecoder=new se(T(t))}readLeftID(){return new Ct(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Ct(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 Bt(this.restDecoder)}readBuf(){return T(this.restDecoder)}readJSON(){return Bt(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{const e=this.stringDecoder.read();return this.keys.push(e),e}}}class rs{constructor(){this.restEncoder=U()}toUint8Array(){return D(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){p(this.restEncoder,t)}writeDsLen(t){p(this.restEncoder,t)}}class Ht extends rs{writeLeftID(t){p(this.restEncoder,t.client),p(this.restEncoder,t.clock)}writeRightID(t){p(this.restEncoder,t.client),p(this.restEncoder,t.clock)}writeClient(t){p(this.restEncoder,t)}writeInfo(t){je(this.restEncoder,t)}writeString(t){at(this.restEncoder,t)}writeParentInfo(t){p(this.restEncoder,t?1:0)}writeTypeRef(t){p(this.restEncoder,t)}writeLen(t){p(this.restEncoder,t)}writeAny(t){Ft(this.restEncoder,t)}writeBuf(t){C(this.restEncoder,t)}writeJSON(t){at(this.restEncoder,JSON.stringify(t))}writeKey(t){at(this.restEncoder,t)}}class is{constructor(){this.restEncoder=U(),this.dsCurrVal=0}toUint8Array(){return D(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const e=t-this.dsCurrVal;this.dsCurrVal=t,p(this.restEncoder,e)}writeDsLen(t){t===0&&H(),p(this.restEncoder,t-1),this.dsCurrVal+=t}}class dt extends is{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Xe,this.clientEncoder=new ie,this.leftClockEncoder=new Xe,this.rightClockEncoder=new Xe,this.infoEncoder=new Kn(je),this.stringEncoder=new di,this.parentInfoEncoder=new Kn(je),this.typeRefEncoder=new ie,this.lenEncoder=new ie}toUint8Array(){const t=U();return p(t,0),C(t,this.keyClockEncoder.toUint8Array()),C(t,this.clientEncoder.toUint8Array()),C(t,this.leftClockEncoder.toUint8Array()),C(t,this.rightClockEncoder.toUint8Array()),C(t,D(this.infoEncoder)),C(t,this.stringEncoder.toUint8Array()),C(t,D(this.parentInfoEncoder)),C(t,this.typeRefEncoder.toUint8Array()),C(t,this.lenEncoder.toUint8Array()),re(t,D(this.restEncoder)),D(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){Ft(this.restEncoder,t)}writeBuf(t){C(this.restEncoder,t)}writeJSON(t){Ft(this.restEncoder,t)}writeKey(t){const e=this.keyMap.get(t);e===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(e)}}const Oi=(n,t,e,s)=>{s=lt(s,t[0].id.clock);const r=$(t,s);p(n.restEncoder,t.length-r),n.writeClient(e),p(n.restEncoder,s);const i=t[r];i.write(n,s-i.id.clock);for(let o=r+1;o<t.length;o++)t[o].write(n,0)},qe=(n,t,e)=>{const s=new Map;e.forEach((r,i)=>{M(t,i)>r&&s.set(i,r)}),ce(t).forEach((r,i)=>{e.has(i)||s.set(i,0)}),p(n.restEncoder,s.size),tt(s.entries()).sort((r,i)=>i[0]-r[0]).forEach(([r,i])=>{Oi(n,t.clients.get(r),r,i)})},Ri=(n,t)=>{const e=N(),s=w(n.restDecoder);for(let r=0;r<s;r++){const i=w(n.restDecoder),o=new Array(i),l=n.readClient();let c=w(n.restDecoder);e.set(l,{i:0,refs:o});for(let a=0;a<i;a++){const h=n.readInfo();switch(ee&h){case 0:{const d=n.readLen();o[a]=new R(b(l,c),d),c+=d;break}case 10:{const d=w(n.restDecoder);o[a]=new B(b(l,c),d),c+=d;break}default:{const d=(h&(J|O))===0,u=new L(b(l,c),null,(h&O)===O?n.readLeftID():null,null,(h&J)===J?n.readRightID():null,d?n.readParentInfo()?t.get(n.readString()):n.readLeftID():null,d&&(h&Rt)===Rt?n.readString():null,js(n,h));o[a]=u,c+=u.length}}}}return e},Bi=(n,t,e)=>{const s=[];let r=tt(e.keys()).sort((f,g)=>f-g);if(r.length===0)return null;const i=()=>{if(r.length===0)return null;let f=e.get(r[r.length-1]);for(;f.refs.length===f.i;)if(r.pop(),r.length>0)f=e.get(r[r.length-1]);else return null;return f};let o=i();if(o===null&&s.length===0)return null;const l=new gs,c=new Map,a=(f,g)=>{const m=c.get(f);(m==null||m>g)&&c.set(f,g)};let h=o.refs[o.i++];const d=new Map,u=()=>{for(const f of s){const g=f.id.client,m=e.get(g);m?(m.i--,l.clients.set(g,m.refs.slice(m.i)),e.delete(g),m.i=0,m.refs=[]):l.clients.set(g,[f]),r=r.filter(E=>E!==g)}s.length=0};for(;;){if(h.constructor!==B){const g=Y(d,h.id.client,()=>M(t,h.id.client))-h.id.clock;if(g<0)s.push(h),a(h.id.client,h.id.clock-1),u();else{const m=h.getMissing(n,t);if(m!==null){s.push(h);const E=e.get(m)||{refs:[],i:0};if(E.refs.length===E.i)a(m,M(t,m)),u();else{h=E.refs[E.i++];continue}}else(g===0||g<h.length)&&(h.integrate(n,g),d.set(h.id.client,h.id.clock+h.length))}}if(s.length>0)h=s.pop();else if(o!==null&&o.i<o.refs.length)h=o.refs[o.i++];else{if(o=i(),o===null)break;h=o.refs[o.i++]}}if(l.clients.size>0){const f=new dt;return qe(f,l,new Map),p(f.restEncoder,0),{missing:c,update:f.toUint8Array()}}return null},Ni=(n,t)=>qe(n,t.doc.store,t.beforeState),Fi=(n,t,e,s=new Et(n))=>_(t,r=>{r.local=!1;let i=!1;const o=r.doc,l=o.store,c=Ri(s,o),a=Bi(r,l,c),h=l.pendingStructs;if(h){for(const[u,f]of h.missing)if(f<M(l,u)){i=!0;break}if(a){for(const[u,f]of a.missing){const g=h.missing.get(u);(g==null||g>f)&&h.missing.set(u,f)}h.update=he([h.update,a.update])}}else l.pendingStructs=a;const d=ts(s,r,l);if(l.pendingDs){const u=new Et(et(l.pendingDs));w(u.restDecoder);const f=ts(u,r,l);d&&f?l.pendingDs=he([d,f]):l.pendingDs=d||f}else l.pendingDs=d;if(i){const u=l.pendingStructs.update;l.pendingStructs=null,os(r.doc,u)}},e,!1),os=(n,t,e,s=Et)=>{const r=et(t);Fi(r,n,e,new s(r))},ls=(n,t,e)=>os(n,t,e,ss),Vi=(n,t,e=new Map)=>{qe(n,t.store,e),Dt(n,Ti(t.store))},Hi=(n,t=new Uint8Array([0]),e=new dt)=>{const s=cs(t);Vi(e,n,s);const r=[e.toUint8Array()];if(n.store.pendingDs&&r.push(n.store.pendingDs),n.store.pendingStructs&&r.push(to(n.store.pendingStructs.update,t)),r.length>1){if(e.constructor===Ht)return Zi(r.map((i,o)=>o===0?i:no(i)));if(e.constructor===dt)return he(r)}return r[0]},Ze=(n,t)=>Hi(n,t,new Ht),$i=n=>{const t=new Map,e=w(n.restDecoder);for(let s=0;s<e;s++){const r=w(n.restDecoder),i=w(n.restDecoder);t.set(r,i)}return t},cs=n=>$i(new ns(et(n))),as=(n,t)=>(p(n.restEncoder,t.size),tt(t.entries()).sort((e,s)=>s[0]-e[0]).forEach(([e,s])=>{p(n.restEncoder,e),p(n.restEncoder,s)}),n),ji=(n,t)=>as(n,ce(t.store)),Ki=(n,t=new is)=>(n instanceof Map?as(t,n):ji(t,n),t.toUint8Array()),zi=n=>Ki(n,new rs);class Yi{constructor(){this.l=[]}}const hs=()=>new Yi,us=(n,t)=>n.l.push(t),ds=(n,t)=>{const e=n.l,s=e.length;n.l=e.filter(r=>t!==r),s===n.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},fs=(n,t,e)=>xe(n.l,[t,e]);class Ct{constructor(t,e){this.client=t,this.clock=e}}const le=(n,t)=>n===t||n!==null&&t!==null&&n.client===t.client&&n.clock===t.clock,b=(n,t)=>new Ct(n,t),Xi=n=>{for(const[t,e]of n.doc.share.entries())if(e===n)return t;throw H()},$t=(n,t)=>t===void 0?!n.deleted:t.sv.has(n.id.client)&&(t.sv.get(n.id.client)||0)>n.id.clock&&!Qn(t.ds,n.id),Qe=(n,t)=>{const e=Y(n.meta,Qe,ot),s=n.doc.store;e.has(t)||(t.sv.forEach((r,i)=>{r<M(s,i)&&st(n,b(i,r))}),Zn(n,t.ds,r=>{}),e.add(t))};class gs{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const ce=n=>{const t=new Map;return n.clients.forEach((e,s)=>{const r=e[e.length-1];t.set(s,r.id.clock+r.length)}),t},M=(n,t)=>{const e=n.clients.get(t);if(e===void 0)return 0;const s=e[e.length-1];return s.id.clock+s.length},ps=(n,t)=>{let e=n.clients.get(t.id.client);if(e===void 0)e=[],n.clients.set(t.id.client,e);else{const s=e[e.length-1];if(s.id.clock+s.length!==t.id.clock)throw H()}e.push(t)},$=(n,t)=>{let e=0,s=n.length-1,r=n[s],i=r.id.clock;if(i===t)return s;let o=X(t/(i+r.length-1)*s);for(;e<=s;){if(r=n[o],i=r.id.clock,i<=t){if(t<i+r.length)return o;e=o+1}else s=o-1;o=X((e+s)/2)}throw H()},tn=(n,t)=>{const e=n.clients.get(t.client);return e[$(e,t.clock)]},en=(n,t,e)=>{const s=$(t,e),r=t[s];return r.id.clock<e&&r instanceof L?(t.splice(s+1,0,_e(n,r,e-r.id.clock)),s+1):s},st=(n,t)=>{const e=n.doc.store.clients.get(t.client);return e[en(n,e,t.clock)]},ws=(n,t,e)=>{const s=t.clients.get(e.client),r=$(s,e.clock),i=s[r];return e.clock!==i.id.clock+i.length-1&&i.constructor!==R&&s.splice(r+1,0,_e(n,i,e.clock-i.id.clock+1)),i},Ji=(n,t,e)=>{const s=n.clients.get(t.id.client);s[$(s,t.id.clock)]=e},ms=(n,t,e,s,r)=>{if(s===0)return;const i=e+s;let o=en(n,t,e),l;do l=t[o++],i<l.id.clock+l.length&&en(n,t,i),r(l);while(o<t.length&&t[o].id.clock<i)};class Wi{constructor(t,e,s){this.doc=t,this.deleteSet=new Vt,this.beforeState=ce(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=e,this.meta=new Map,this.local=s,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const ys=(n,t)=>t.deleteSet.clients.size===0&&!yr(t.afterState,(e,s)=>t.beforeState.get(s)!==e)?!1:(Ge(t.deleteSet),Ni(n,t),Dt(n,t.deleteSet),!0),bs=(n,t,e)=>{const s=t._item;(s===null||s.id.clock<(n.beforeState.get(s.id.client)||0)&&!s.deleted)&&Y(n.changed,t,ot).add(e)},ae=(n,t)=>{let e=n[t],s=n[t-1],r=t;for(;r>0;e=s,s=n[--r-1]){if(s.deleted===e.deleted&&s.constructor===e.constructor&&s.mergeWith(e)){e instanceof L&&e.parentSub!==null&&e.parent._map.get(e.parentSub)===e&&e.parent._map.set(e.parentSub,s);continue}break}const i=t-r;return i&&n.splice(t+1-i,i),i},Gi=(n,t,e)=>{for(const[s,r]of n.clients.entries()){const i=t.clients.get(s);for(let o=r.length-1;o>=0;o--){const l=r[o],c=l.clock+l.len;for(let a=$(i,l.clock),h=i[a];a<i.length&&h.id.clock<c;h=i[++a]){const d=i[a];if(l.clock+l.len<=d.id.clock)break;d instanceof L&&d.deleted&&!d.keep&&e(d)&&d.gc(t,!1)}}}},Pi=(n,t)=>{n.clients.forEach((e,s)=>{const r=t.clients.get(s);for(let i=e.length-1;i>=0;i--){const o=e[i],l=ve(r.length-1,1+$(r,o.clock+o.len-1));for(let c=l,a=r[c];c>0&&a.id.clock>=o.clock;a=r[c])c-=1+ae(r,c)}})},ks=(n,t)=>{if(t<n.length){const e=n[t],s=e.doc,r=s.store,i=e.deleteSet,o=e._mergeStructs;try{Ge(i),e.afterState=ce(e.doc.store),s.emit("beforeObserverCalls",[e,s]);const l=[];e.changed.forEach((c,a)=>l.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(e,c)})),l.push(()=>{e.changedParentTypes.forEach((c,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(c=c.filter(h=>h.target._item===null||!h.target._item.deleted),c.forEach(h=>{h.currentTarget=a,h._path=null}),c.sort((h,d)=>h.path.length-d.path.length),fs(a._dEH,c,e))})}),l.push(()=>s.emit("afterTransaction",[e,s])),xe(l,[]),e._needFormattingCleanup&&wo(e)}finally{s.gc&&Gi(i,r,s.gcFilter),Pi(i,r),e.afterState.forEach((h,d)=>{const u=e.beforeState.get(d)||0;if(u!==h){const f=r.clients.get(d),g=lt($(f,u),1);for(let m=f.length-1;m>=g;)m-=1+ae(f,m)}});for(let h=o.length-1;h>=0;h--){const{client:d,clock:u}=o[h].id,f=r.clients.get(d),g=$(f,u);g+1<f.length&&ae(f,g+1)>1||g>0&&ae(f,g)}if(!e.local&&e.afterState.get(s.clientID)!==e.beforeState.get(s.clientID)&&(Ai(Pn,Jn,"[yjs] ",Wn,Gn,"Changed the client-id because another client seems to be using it."),s.clientID=es()),s.emit("afterTransactionCleanup",[e,s]),s._observers.has("update")){const h=new Ht;ys(h,e)&&s.emit("update",[h.toUint8Array(),e.origin,s,e])}if(s._observers.has("updateV2")){const h=new dt;ys(h,e)&&s.emit("updateV2",[h.toUint8Array(),e.origin,s,e])}const{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=e;(l.size>0||a.size>0||c.size>0)&&(l.forEach(h=>{h.clientID=s.clientID,h.collectionid==null&&(h.collectionid=s.collectionid),s.subdocs.add(h)}),a.forEach(h=>s.subdocs.delete(h)),s.emit("subdocs",[{loaded:c,added:l,removed:a},s,e]),a.forEach(h=>h.destroy())),n.length<=t+1?(s._transactionCleanups=[],s.emit("afterAllTransactions",[s,n])):ks(n,t+1)}}},_=(n,t,e=null,s=!0)=>{const r=n._transactionCleanups;let i=!1,o=null;n._transaction===null&&(i=!0,n._transaction=new Wi(n,e,s),r.push(n._transaction),r.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{o=t(n._transaction)}finally{if(i){const l=n._transaction===r[0];n._transaction=null,l&&ks(r,0)}}return o};function*qi(n){const t=w(n.restDecoder);for(let e=0;e<t;e++){const s=w(n.restDecoder),r=n.readClient();let i=w(n.restDecoder);for(let o=0;o<s;o++){const l=n.readInfo();if(l===10){const c=w(n.restDecoder);yield new B(b(r,i),c),i+=c}else if(ee&l){const c=(l&(J|O))===0,a=new L(b(r,i),null,(l&O)===O?n.readLeftID():null,null,(l&J)===J?n.readRightID():null,c?n.readParentInfo()?n.readString():n.readLeftID():null,c&&(l&Rt)===Rt?n.readString():null,js(n,l));yield a,i+=a.length}else{const c=n.readLen();yield new R(b(r,i),c),i+=c}}}}class nn{constructor(t,e){this.gen=qi(t),this.curr=null,this.done=!1,this.filterSkips=e,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===B);return this.curr}}class sn{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const Zi=n=>he(n,ss,Ht),Qi=(n,t)=>{if(n.constructor===R){const{client:e,clock:s}=n.id;return new R(b(e,s+t),n.length-t)}else if(n.constructor===B){const{client:e,clock:s}=n.id;return new B(b(e,s+t),n.length-t)}else{const e=n,{client:s,clock:r}=e.id;return new L(b(s,r+t),null,b(s,r+t-1),null,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t))}},he=(n,t=Et,e=dt)=>{if(n.length===1)return n[0];const s=n.map(h=>new t(et(h)));let r=s.map(h=>new nn(h,!0)),i=null;const o=new e,l=new sn(o);for(;r=r.filter(u=>u.curr!==null),r.sort((u,f)=>{if(u.curr.id.client===f.curr.id.client){const g=u.curr.id.clock-f.curr.id.clock;return g===0?u.curr.constructor===f.curr.constructor?0:u.curr.constructor===B?1:-1:g}else return f.curr.id.client-u.curr.id.client}),r.length!==0;){const h=r[0],d=h.curr.id.client;if(i!==null){let u=h.curr,f=!1;for(;u!==null&&u.id.clock+u.length<=i.struct.id.clock+i.struct.length&&u.id.client>=i.struct.id.client;)u=h.next(),f=!0;if(u===null||u.id.client!==d||f&&u.id.clock>i.struct.id.clock+i.struct.length)continue;if(d!==i.struct.id.client)rt(l,i.struct,i.offset),i={struct:u,offset:0},h.next();else if(i.struct.id.clock+i.struct.length<u.id.clock)if(i.struct.constructor===B)i.struct.length=u.id.clock+u.length-i.struct.id.clock;else{rt(l,i.struct,i.offset);const g=u.id.clock-i.struct.id.clock-i.struct.length;i={struct:new B(b(d,i.struct.id.clock+i.struct.length),g),offset:0}}else{const g=i.struct.id.clock+i.struct.length-u.id.clock;g>0&&(i.struct.constructor===B?i.struct.length-=g:u=Qi(u,g)),i.struct.mergeWith(u)||(rt(l,i.struct,i.offset),i={struct:u,offset:0},h.next())}}else i={struct:h.curr,offset:0},h.next();for(let u=h.curr;u!==null&&u.id.client===d&&u.id.clock===i.struct.id.clock+i.struct.length&&u.constructor!==B;u=h.next())rt(l,i.struct,i.offset),i={struct:u,offset:0}}i!==null&&(rt(l,i.struct,i.offset),i=null),rn(l);const c=s.map(h=>Pe(h)),a=Mi(c);return Dt(o,a),o.toUint8Array()},to=(n,t,e=Et,s=dt)=>{const r=cs(t),i=new s,o=new sn(i),l=new e(et(n)),c=new nn(l,!1);for(;c.curr;){const h=c.curr,d=h.id.client,u=r.get(d)||0;if(c.curr.constructor===B){c.next();continue}if(h.id.clock+h.length>u)for(rt(o,h,lt(u-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===d;)rt(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===d&&c.curr.id.clock+c.curr.length<=u;)c.next()}rn(o);const a=Pe(l);return Dt(i,a),i.toUint8Array()},_s=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:D(n.encoder.restEncoder)}),n.encoder.restEncoder=U(),n.written=0)},rt=(n,t,e)=>{n.written>0&&n.currClient!==t.id.client&&_s(n),n.written===0&&(n.currClient=t.id.client,n.encoder.writeClient(t.id.client),p(n.encoder.restEncoder,t.id.clock+e)),t.write(n.encoder,e),n.written++},rn=n=>{_s(n);const t=n.encoder.restEncoder;p(t,n.clientStructs.length);for(let e=0;e<n.clientStructs.length;e++){const s=n.clientStructs[e];p(t,s.written),re(t,s.restEncoder)}},eo=(n,t,e,s)=>{const r=new e(et(n)),i=new nn(r,!1),o=new s,l=new sn(o);for(let a=i.curr;a!==null;a=i.next())rt(l,t(a),0);rn(l);const c=Pe(r);return Dt(o,c),o.toUint8Array()},no=n=>eo(n,Vr,Et,Ht),Ss="You must not compute changes after the event-handler fired.";class ue{constructor(t,e){this.target=t,this.currentTarget=t,this.transaction=e,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=so(this.currentTarget,this.target))}deletes(t){return Qn(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw W(Ss);const t=new Map,e=this.target;this.transaction.changed.get(e).forEach(r=>{if(r!==null){const i=e._map.get(r);let o,l;if(this.adds(i)){let c=i.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(i))if(c!==null&&this.deletes(c))o="delete",l=Ie(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Ie(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(i))o="delete",l=Ie(i.content.getContent());else return;t.set(r,{action:o,oldValue:l})}}),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 W(Ss);const e=this.target,s=ot(),r=ot(),i=[];if(t={added:s,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(e).has(null)){let l=null;const c=()=>{l&&i.push(l)};for(let a=e._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((l===null||l.delete===void 0)&&(c(),l={delete:0}),l.delete+=a.length,r.add(a)):this.adds(a)?((l===null||l.insert===void 0)&&(c(),l={insert:[]}),l.insert=l.insert.concat(a.content.getContent()),s.add(a)):((l===null||l.retain===void 0)&&(c(),l={retain:0}),l.retain+=a.length);l!==null&&l.retain===void 0&&c()}this._changes=t}return t}}const so=(n,t)=>{const e=[];for(;t._item!==null&&t!==n;){if(t._item.parentSub!==null)e.unshift(t._item.parentSub);else{let s=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)r.deleted||s++,r=r.right;e.unshift(s)}t=t._item.parent}return e},Ds=80;let on=0;class ro{constructor(t,e){t.marker=!0,this.p=t,this.index=e,this.timestamp=on++}}const io=n=>{n.timestamp=on++},Es=(n,t,e)=>{n.p.marker=!1,n.p=t,t.marker=!0,n.index=e,n.timestamp=on++},oo=(n,t,e)=>{if(n.length>=Ds){const s=n.reduce((r,i)=>r.timestamp<i.timestamp?r:i);return Es(s,t,e),s}else{const s=new ro(t,e);return n.push(s),s}},de=(n,t)=>{if(n._start===null||t===0||n._searchMarker===null)return null;const e=n._searchMarker.length===0?null:n._searchMarker.reduce((i,o)=>Qt(t-i.index)<Qt(t-o.index)?i:o);let s=n._start,r=0;for(e!==null&&(s=e.p,r=e.index,io(e));s.right!==null&&r<t;){if(!s.deleted&&s.countable){if(t<r+s.length)break;r+=s.length}s=s.right}for(;s.left!==null&&r>t;)s=s.left,!s.deleted&&s.countable&&(r-=s.length);for(;s.left!==null&&s.left.id.client===s.id.client&&s.left.id.clock+s.left.length===s.id.clock;)s=s.left,!s.deleted&&s.countable&&(r-=s.length);return e!==null&&Qt(e.index-r)<s.parent.length/Ds?(Es(e,s,r),e):oo(n._searchMarker,s,r)},jt=(n,t,e)=>{for(let s=n.length-1;s>=0;s--){const r=n[s];if(e>0){let i=r.p;for(i.marker=!1;i&&(i.deleted||!i.countable);)i=i.left,i&&!i.deleted&&i.countable&&(r.index-=i.length);if(i===null||i.marker===!0){n.splice(s,1);continue}r.p=i,i.marker=!0}(t<r.index||e>0&&t===r.index)&&(r.index=lt(t,r.index+e))}},fe=(n,t,e)=>{const s=n,r=t.changedParentTypes;for(;Y(r,n,()=>[]).push(e),n._item!==null;)n=n._item.parent;fs(s._eH,e,t)};class x{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=hs(),this._dEH=hs(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,e){this.doc=t,this._item=e}_copy(){throw V()}clone(){throw V()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,e){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){us(this._eH,t)}observeDeep(t){us(this._dEH,t)}unobserve(t){ds(this._eH,t)}unobserveDeep(t){ds(this._dEH,t)}toJSON(){}}const Cs=(n,t,e)=>{t<0&&(t=n._length+t),e<0&&(e=n._length+e);let s=e-t;const r=[];let i=n._start;for(;i!==null&&s>0;){if(i.countable&&!i.deleted){const o=i.content.getContent();if(o.length<=t)t-=o.length;else{for(let l=t;l<o.length&&s>0;l++)r.push(o[l]),s--;t=0}}i=i.right}return r},As=n=>{const t=[];let e=n._start;for(;e!==null;){if(e.countable&&!e.deleted){const s=e.content.getContent();for(let r=0;r<s.length;r++)t.push(s[r])}e=e.right}return t},Kt=(n,t)=>{let e=0,s=n._start;for(;s!==null;){if(s.countable&&!s.deleted){const r=s.content.getContent();for(let i=0;i<r.length;i++)t(r[i],e++,n)}s=s.right}},Ls=(n,t)=>{const e=[];return Kt(n,(s,r)=>{e.push(t(s,r,n))}),e},lo=n=>{let t=n._start,e=null,s=0;return{[Symbol.iterator](){return this},next:()=>{if(e===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};e=t.content.getContent(),s=0,t=t.right}const r=e[s++];return e.length<=s&&(e=null),{done:!1,value:r}}}},Is=(n,t)=>{const e=de(n,t);let s=n._start;for(e!==null&&(s=e.p,t-=e.index);s!==null;s=s.right)if(!s.deleted&&s.countable){if(t<s.length)return s.content.getContent()[t];t-=s.length}},ge=(n,t,e,s)=>{let r=e;const i=n.doc,o=i.clientID,l=i.store,c=e===null?t._start:e.right;let a=[];const h=()=>{a.length>0&&(r=new L(b(o,M(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new wt(a)),r.integrate(n,0),a=[])};s.forEach(d=>{if(d===null)a.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(d);break;default:switch(h(),d.constructor){case Uint8Array:case ArrayBuffer:r=new L(b(o,M(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new Yt(new Uint8Array(d))),r.integrate(n,0);break;case ut:r=new L(b(o,M(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new Jt(d)),r.integrate(n,0);break;default:if(d instanceof x)r=new L(b(o,M(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new q(d)),r.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},vs=()=>W("Length exceeded!"),Ms=(n,t,e,s)=>{if(e>t._length)throw vs();if(e===0)return t._searchMarker&&jt(t._searchMarker,e,s.length),ge(n,t,null,s);const r=e,i=de(t,e);let o=t._start;for(i!==null&&(o=i.p,e-=i.index,e===0&&(o=o.prev,e+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(e<=o.length){e<o.length&&st(n,b(o.id.client,o.id.clock+e));break}e-=o.length}return t._searchMarker&&jt(t._searchMarker,r,s.length),ge(n,t,o,s)},co=(n,t,e)=>{let r=(t._searchMarker||[]).reduce((i,o)=>o.index>i.index?o:i,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return ge(n,t,r,e)},xs=(n,t,e,s)=>{if(s===0)return;const r=e,i=s,o=de(t,e);let l=t._start;for(o!==null&&(l=o.p,e-=o.index);l!==null&&e>0;l=l.right)!l.deleted&&l.countable&&(e<l.length&&st(n,b(l.id.client,l.id.clock+e)),e-=l.length);for(;s>0&&l!==null;)l.deleted||(s<l.length&&st(n,b(l.id.client,l.id.clock+s)),l.delete(n),s-=l.length),l=l.right;if(s>0)throw vs();t._searchMarker&&jt(t._searchMarker,r,-i+s)},pe=(n,t,e)=>{const s=t._map.get(e);s!==void 0&&s.delete(n)},ln=(n,t,e,s)=>{const r=t._map.get(e)||null,i=n.doc,o=i.clientID;let l;if(s==null)l=new wt([s]);else switch(s.constructor){case Number:case Object:case Boolean:case Array:case String:l=new wt([s]);break;case Uint8Array:l=new Yt(s);break;case ut:l=new Jt(s);break;default:if(s instanceof x)l=new q(s);else throw new Error("Unexpected content type")}new L(b(o,M(i.store,o)),r,r&&r.lastId,null,null,t,e,l).integrate(n,0)},cn=(n,t)=>{const e=n._map.get(t);return e!==void 0&&!e.deleted?e.content.getContent()[e.length-1]:void 0},Ts=n=>{const t={};return n._map.forEach((e,s)=>{e.deleted||(t[s]=e.content.getContent()[e.length-1])}),t},Us=(n,t)=>{const e=n._map.get(t);return e!==void 0&&!e.deleted},we=n=>Ii(n.entries(),t=>!t[1].deleted);class ao extends ue{constructor(t,e){super(t,e),this._transaction=e}}class At extends x{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const e=new At;return e.push(t),e}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new At}clone(){const t=new At;return t.insert(0,this.toArray().map(e=>e instanceof x?e.clone():e)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}_callObserver(t,e){super._callObserver(t,e),fe(this,t,new ao(this,t))}insert(t,e){this.doc!==null?_(this.doc,s=>{Ms(s,this,t,e)}):this._prelimContent.splice(t,0,...e)}push(t){this.doc!==null?_(this.doc,e=>{co(e,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,e=1){this.doc!==null?_(this.doc,s=>{xs(s,this,t,e)}):this._prelimContent.splice(t,e)}get(t){return Is(this,t)}toArray(){return As(this)}slice(t=0,e=this.length){return Cs(this,t,e)}toJSON(){return this.map(t=>t instanceof x?t.toJSON():t)}map(t){return Ls(this,t)}forEach(t){Kt(this,t)}[Symbol.iterator](){return lo(this)}_write(t){t.writeTypeRef(Oo)}}const ho=n=>new At;class uo extends ue{constructor(t,e,s){super(t,e),this.keysChanged=s}}class ft extends x{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,e){super._integrate(t,e),this._prelimContent.forEach((s,r)=>{this.set(r,s)}),this._prelimContent=null}_copy(){return new ft}clone(){const t=new ft;return this.forEach((e,s)=>{t.set(s,e instanceof x?e.clone():e)}),t}_callObserver(t,e){fe(this,t,new uo(this,t,e))}toJSON(){const t={};return this._map.forEach((e,s)=>{if(!e.deleted){const r=e.content.getContent()[e.length-1];t[s]=r instanceof x?r.toJSON():r}}),t}get size(){return[...we(this._map)].length}keys(){return Je(we(this._map),t=>t[0])}values(){return Je(we(this._map),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Je(we(this._map),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this._map.forEach((e,s)=>{e.deleted||t(e.content.getContent()[e.length-1],s,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?_(this.doc,e=>{pe(e,this,t)}):this._prelimContent.delete(t)}set(t,e){return this.doc!==null?_(this.doc,s=>{ln(s,this,t,e)}):this._prelimContent.set(t,e),e}get(t){return cn(this,t)}has(t){return Us(this,t)}clear(){this.doc!==null?_(this.doc,t=>{this.forEach(function(e,s,r){pe(t,r,s)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Ro)}}const fo=n=>new ft,it=(n,t)=>n===t||typeof n=="object"&&typeof t=="object"&&n&&t&&Fr(n,t);class an{constructor(t,e,s,r){this.left=t,this.right=e,this.index=s,this.currentAttributes=r}forward(){switch(this.right===null&&H(),this.right.content.constructor){case A:this.right.deleted||Lt(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}}const Os=(n,t,e)=>{for(;t.right!==null&&e>0;){switch(t.right.content.constructor){case A:t.right.deleted||Lt(t.currentAttributes,t.right.content);break;default:t.right.deleted||(e<t.right.length&&st(n,b(t.right.id.client,t.right.id.clock+e)),t.index+=t.right.length,e-=t.right.length);break}t.left=t.right,t.right=t.right.right}return t},me=(n,t,e)=>{const s=new Map,r=de(t,e);if(r){const i=new an(r.p.left,r.p,r.index,s);return Os(n,i,e-r.index)}else{const i=new an(null,t._start,0,s);return Os(n,i,e)}},Rs=(n,t,e,s)=>{for(;e.right!==null&&(e.right.deleted===!0||e.right.content.constructor===A&&it(s.get(e.right.content.key),e.right.content.value));)e.right.deleted||s.delete(e.right.content.key),e.forward();const r=n.doc,i=r.clientID;s.forEach((o,l)=>{const c=e.left,a=e.right,h=new L(b(i,M(r.store,i)),c,c&&c.lastId,a,a&&a.id,t,null,new A(l,o));h.integrate(n,0),e.right=h,e.forward()})},Lt=(n,t)=>{const{key:e,value:s}=t;s===null?n.delete(e):n.set(e,s)},Bs=(n,t)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===A&&it(t[n.right.content.key]||null,n.right.content.value)))break;n.forward()}},Ns=(n,t,e,s)=>{const r=n.doc,i=r.clientID,o=new Map;for(const l in s){const c=s[l],a=e.currentAttributes.get(l)||null;if(!it(a,c)){o.set(l,a);const{left:h,right:d}=e;e.right=new L(b(i,M(r.store,i)),h,h&&h.lastId,d,d&&d.id,t,null,new A(l,c)),e.right.integrate(n,0),e.forward()}}return o},hn=(n,t,e,s,r)=>{e.currentAttributes.forEach((u,f)=>{r[f]===void 0&&(r[f]=null)});const i=n.doc,o=i.clientID;Bs(e,r);const l=Ns(n,t,e,r),c=s.constructor===String?new j(s):s instanceof x?new q(s):new pt(s);let{left:a,right:h,index:d}=e;t._searchMarker&&jt(t._searchMarker,e.index,c.getLength()),h=new L(b(o,M(i.store,o)),a,a&&a.lastId,h,h&&h.id,t,null,c),h.integrate(n,0),e.right=h,e.index=d,e.forward(),Rs(n,t,e,l)},Fs=(n,t,e,s,r)=>{const i=n.doc,o=i.clientID;Bs(e,r);const l=Ns(n,t,e,r);t:for(;e.right!==null&&(s>0||l.size>0&&(e.right.deleted||e.right.content.constructor===A));){if(!e.right.deleted)switch(e.right.content.constructor){case A:{const{key:c,value:a}=e.right.content,h=r[c];if(h!==void 0){if(it(h,a))l.delete(c);else{if(s===0)break t;l.set(c,a)}e.right.delete(n)}else e.currentAttributes.set(c,a);break}default:s<e.right.length&&st(n,b(e.right.id.client,e.right.id.clock+s)),s-=e.right.length;break}e.forward()}if(s>0){let c="";for(;s>0;s--)c+=`
2
+ `;e.right=new L(b(o,M(i.store,o)),e.left,e.left&&e.left.lastId,e.right,e.right&&e.right.id,t,null,new j(c)),e.right.integrate(n,0),e.forward()}Rs(n,t,e,l)},Vs=(n,t,e,s,r)=>{let i=t;const o=N();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===A){const a=i.content;o.set(a.key,a)}i=i.right}let l=0,c=!1;for(;t!==i;){if(e===t&&(c=!0),!t.deleted){const a=t.content;switch(a.constructor){case A:{const{key:h,value:d}=a,u=s.get(h)||null;(o.get(h)!==a||u===d)&&(t.delete(n),l++,!c&&(r.get(h)||null)===d&&u!==d&&(u===null?r.delete(h):r.set(h,u))),!c&&!t.deleted&&Lt(r,a);break}}}t=t.right}return l},go=(n,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const e=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===A){const s=t.content.key;e.has(s)?t.delete(n):e.add(s)}t=t.left}},po=n=>{let t=0;return _(n.doc,e=>{let s=n._start,r=n._start,i=N();const o=Le(i);for(;r;){if(r.deleted===!1)switch(r.content.constructor){case A:Lt(o,r.content);break;default:t+=Vs(e,s,r,i,o),i=Le(o),s=r;break}r=r.right}}),t},wo=n=>{const t=new Set,e=n.doc;for(const[s,r]of n.afterState.entries()){const i=n.beforeState.get(s)||0;r!==i&&ms(n,e.store.clients.get(s),i,r,o=>{!o.deleted&&o.content.constructor===A&&o.constructor!==R&&t.add(o.parent)})}_(e,s=>{Zn(n,n.deleteSet,r=>{if(r instanceof R||!r.parent._hasFormatting||t.has(r.parent))return;const i=r.parent;r.content.constructor===A?t.add(i):go(s,r)});for(const r of t)po(r)})},Hs=(n,t,e)=>{const s=e,r=Le(t.currentAttributes),i=t.right;for(;e>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case q:case pt:case j:e<t.right.length&&st(n,b(t.right.id.client,t.right.id.clock+e)),e-=t.right.length,t.right.delete(n);break}t.forward()}i&&Vs(n,i,t.right,r,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&jt(o._searchMarker,t.index,-s+e),t};class mo extends ue{constructor(t,e,s){super(t,e),this.childListChanged=!1,this.keysChanged=new Set,s.forEach(r=>{r===null?this.childListChanged=!0:this.keysChanged.add(r)})}get changes(){if(this._changes===null){const 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){const t=this.target.doc,e=[];_(t,s=>{const r=new Map,i=new Map;let o=this.target._start,l=null;const c={};let a="",h=0,d=0;const u=()=>{if(l!==null){let f=null;switch(l){case"delete":d>0&&(f={delete:d}),d=0;break;case"insert":(typeof a=="object"||a.length>0)&&(f={insert:a},r.size>0&&(f.attributes={},r.forEach((g,m)=>{g!==null&&(f.attributes[m]=g)}))),a="";break;case"retain":h>0&&(f={retain:h},Br(c)||(f.attributes=Tr({},c))),h=0;break}f&&e.push(f),l=null}};for(;o!==null;){switch(o.content.constructor){case q:case pt:this.adds(o)?this.deletes(o)||(u(),l="insert",a=o.content.getContent()[0],u()):this.deletes(o)?(l!=="delete"&&(u(),l="delete"),d+=1):o.deleted||(l!=="retain"&&(u(),l="retain"),h+=1);break;case j:this.adds(o)?this.deletes(o)||(l!=="insert"&&(u(),l="insert"),a+=o.content.str):this.deletes(o)?(l!=="delete"&&(u(),l="delete"),d+=o.length):o.deleted||(l!=="retain"&&(u(),l="retain"),h+=o.length);break;case A:{const{key:f,value:g}=o.content;if(this.adds(o)){if(!this.deletes(o)){const m=r.get(f)||null;it(m,g)?g!==null&&o.delete(s):(l==="retain"&&u(),it(g,i.get(f)||null)?delete c[f]:c[f]=g)}}else if(this.deletes(o)){i.set(f,g);const m=r.get(f)||null;it(m,g)||(l==="retain"&&u(),c[f]=m)}else if(!o.deleted){i.set(f,g);const m=c[f];m!==void 0&&(it(m,g)?m!==null&&o.delete(s):(l==="retain"&&u(),g===null?delete c[f]:c[f]=g))}o.deleted||(l==="insert"&&u(),Lt(r,o.content));break}}o=o.right}for(u();e.length>0;){const f=e[e.length-1];if(f.retain!==void 0&&f.attributes===void 0)e.pop();else break}}),this._delta=e}return this._delta}}class It extends x{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this._length}_integrate(t,e){super._integrate(t,e);try{this._pending.forEach(s=>s())}catch(s){console.error(s)}this._pending=null}_copy(){return new It}clone(){const t=new It;return t.applyDelta(this.toDelta()),t}_callObserver(t,e){super._callObserver(t,e);const s=new mo(this,t,e);fe(this,t,s),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){let t="",e=this._start;for(;e!==null;)!e.deleted&&e.countable&&e.content.constructor===j&&(t+=e.content.str),e=e.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:e=!0}={}){this.doc!==null?_(this.doc,s=>{const r=new an(null,this._start,0,new Map);for(let i=0;i<t.length;i++){const o=t[i];if(o.insert!==void 0){const l=!e&&typeof o.insert=="string"&&i===t.length-1&&r.right===null&&o.insert.slice(-1)===`
3
+ `?o.insert.slice(0,-1):o.insert;(typeof l!="string"||l.length>0)&&hn(s,this,r,l,o.attributes||{})}else o.retain!==void 0?Fs(s,this,r,o.retain,o.attributes||{}):o.delete!==void 0&&Hs(s,r,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,e,s){const r=[],i=new Map,o=this.doc;let l="",c=this._start;function a(){if(l.length>0){const d={};let u=!1;i.forEach((g,m)=>{u=!0,d[m]=g});const f={insert:l};u&&(f.attributes=d),r.push(f),l=""}}const h=()=>{for(;c!==null;){if($t(c,t)||e!==void 0&&$t(c,e))switch(c.content.constructor){case j:{const d=i.get("ychange");t!==void 0&&!$t(c,t)?(d===void 0||d.user!==c.id.client||d.type!=="removed")&&(a(),i.set("ychange",s?s("removed",c.id):{type:"removed"})):e!==void 0&&!$t(c,e)?(d===void 0||d.user!==c.id.client||d.type!=="added")&&(a(),i.set("ychange",s?s("added",c.id):{type:"added"})):d!==void 0&&(a(),i.delete("ychange")),l+=c.content.str;break}case q:case pt:{a();const d={insert:c.content.getContent()[0]};if(i.size>0){const u={};d.attributes=u,i.forEach((f,g)=>{u[g]=f})}r.push(d);break}case A:$t(c,t)&&(a(),Lt(i,c.content));break}c=c.right}a()};return t||e?_(o,d=>{t&&Qe(d,t),e&&Qe(d,e),h()},"cleanup"):h(),r}insert(t,e,s){if(e.length<=0)return;const r=this.doc;r!==null?_(r,i=>{const o=me(i,this,t);s||(s={},o.currentAttributes.forEach((l,c)=>{s[c]=l})),hn(i,this,o,e,s)}):this._pending.push(()=>this.insert(t,e,s))}insertEmbed(t,e,s={}){const r=this.doc;r!==null?_(r,i=>{const o=me(i,this,t);hn(i,this,o,e,s)}):this._pending.push(()=>this.insertEmbed(t,e,s))}delete(t,e){if(e===0)return;const s=this.doc;s!==null?_(s,r=>{Hs(r,me(r,this,t),e)}):this._pending.push(()=>this.delete(t,e))}format(t,e,s){if(e===0)return;const r=this.doc;r!==null?_(r,i=>{const o=me(i,this,t);o.right!==null&&Fs(i,this,o,e,s)}):this._pending.push(()=>this.format(t,e,s))}removeAttribute(t){this.doc!==null?_(this.doc,e=>{pe(e,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,e){this.doc!==null?_(this.doc,s=>{ln(s,this,t,e)}):this._pending.push(()=>this.setAttribute(t,e))}getAttribute(t){return cn(this,t)}getAttributes(){return Ts(this)}_write(t){t.writeTypeRef(Bo)}}const yo=n=>new It;class un{constructor(t,e=()=>!0){this._filter=e,this._root=t,this._currentNode=t._start,this._firstCall=!0}[Symbol.iterator](){return this}next(){let t=this._currentNode,e=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(e)))do if(e=t.content.type,!t.deleted&&(e.constructor===zt||e.constructor===gt)&&e._start!==null)t=e._start;else for(;t!==null;)if(t.right!==null){t=t.right;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})}}class gt extends x{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new gt}clone(){const t=new gt;return t.insert(0,this.toArray().map(e=>e instanceof x?e.clone():e)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new un(this,t)}querySelector(t){t=t.toUpperCase();const s=new un(this,r=>r.nodeName&&r.nodeName.toUpperCase()===t).next();return s.done?null:s.value}querySelectorAll(t){return t=t.toUpperCase(),tt(new un(this,e=>e.nodeName&&e.nodeName.toUpperCase()===t))}_callObserver(t,e){fe(this,t,new _o(this,e,t))}toString(){return Ls(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,e={},s){const r=t.createDocumentFragment();return s!==void 0&&s._createAssociation(r,this),Kt(this,i=>{r.insertBefore(i.toDOM(t,e,s),null)}),r}insert(t,e){this.doc!==null?_(this.doc,s=>{Ms(s,this,t,e)}):this._prelimContent.splice(t,0,...e)}insertAfter(t,e){if(this.doc!==null)_(this.doc,s=>{const r=t&&t instanceof x?t._item:t;ge(s,this,r,e)});else{const s=this._prelimContent,r=t===null?0:s.findIndex(i=>i===t)+1;if(r===0&&t!==null)throw W("Reference item not found");s.splice(r,0,...e)}}delete(t,e=1){this.doc!==null?_(this.doc,s=>{xs(s,this,t,e)}):this._prelimContent.splice(t,e)}toArray(){return As(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Is(this,t)}slice(t=0,e=this.length){return Cs(this,t,e)}forEach(t){Kt(this,t)}_write(t){t.writeTypeRef(Fo)}}const bo=n=>new gt;class zt extends gt{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,e){super._integrate(t,e),this._prelimAttrs.forEach((s,r)=>{this.setAttribute(r,s)}),this._prelimAttrs=null}_copy(){return new zt(this.nodeName)}clone(){const t=new zt(this.nodeName),e=this.getAttributes();return Or(e,(s,r)=>{typeof s=="string"&&t.setAttribute(r,s)}),t.insert(0,this.toArray().map(s=>s instanceof x?s.clone():s)),t}toString(){const t=this.getAttributes(),e=[],s=[];for(const l in t)s.push(l);s.sort();const r=s.length;for(let l=0;l<r;l++){const c=s[l];e.push(c+'="'+t[c]+'"')}const i=this.nodeName.toLocaleLowerCase(),o=e.length>0?" "+e.join(" "):"";return`<${i}${o}>${super.toString()}</${i}>`}removeAttribute(t){this.doc!==null?_(this.doc,e=>{pe(e,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,e){this.doc!==null?_(this.doc,s=>{ln(s,this,t,e)}):this._prelimAttrs.set(t,e)}getAttribute(t){return cn(this,t)}hasAttribute(t){return Us(this,t)}getAttributes(){return Ts(this)}toDOM(t=document,e={},s){const r=t.createElement(this.nodeName),i=this.getAttributes();for(const o in i){const l=i[o];typeof l=="string"&&r.setAttribute(o,l)}return Kt(this,o=>{r.appendChild(o.toDOM(t,e,s))}),s!==void 0&&s._createAssociation(r,this),r}_write(t){t.writeTypeRef(No),t.writeKey(this.nodeName)}}const ko=n=>new zt(n.readKey());class _o extends ue{constructor(t,e,s){super(t,s),this.childListChanged=!1,this.attributesChanged=new Set,e.forEach(r=>{r===null?this.childListChanged=!0:this.attributesChanged.add(r)})}}class ye extends ft{constructor(t){super(),this.hookName=t}_copy(){return new ye(this.hookName)}clone(){const t=new ye(this.hookName);return this.forEach((e,s)=>{t.set(s,e)}),t}toDOM(t=document,e={},s){const r=e[this.hookName];let i;return r!==void 0?i=r.createDom(this):i=document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),s!==void 0&&s._createAssociation(i,this),i}_write(t){t.writeTypeRef(Vo),t.writeKey(this.hookName)}}const So=n=>new ye(n.readKey());class be extends It{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new be}clone(){const t=new be;return t.applyDelta(this.toDelta()),t}toDOM(t=document,e,s){const r=t.createTextNode(this.toString());return s!==void 0&&s._createAssociation(r,this),r}toString(){return this.toDelta().map(t=>{const e=[];for(const r in t.attributes){const i=[];for(const o in t.attributes[r])i.push({key:o,value:t.attributes[r][o]});i.sort((o,l)=>o.key<l.key?-1:1),e.push({nodeName:r,attrs:i})}e.sort((r,i)=>r.nodeName<i.nodeName?-1:1);let s="";for(let r=0;r<e.length;r++){const i=e[r];s+=`<${i.nodeName}`;for(let o=0;o<i.attrs.length;o++){const l=i.attrs[o];s+=` ${l.key}="${l.value}"`}s+=">"}s+=t.insert;for(let r=e.length-1;r>=0;r--)s+=`</${e[r].nodeName}>`;return s}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(Ho)}}const Do=n=>new be;class dn{constructor(t,e){this.id=t,this.length=e}get deleted(){throw V()}mergeWith(t){return!1}write(t,e,s){throw V()}integrate(t,e){throw V()}}const Eo=0;class R extends dn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){e>0&&(this.id.clock+=e,this.length-=e),ps(t.doc.store,this)}write(t,e){t.writeInfo(Eo),t.writeLen(this.length-e)}getMissing(t,e){return null}}class Yt{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Yt(this.content)}splice(t){throw V()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeBuf(this.content)}getRef(){return 3}}const Co=n=>new Yt(n.readBuf());class Xt{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Xt(this.len)}splice(t){const e=new Xt(this.len-t);return this.len=t,e}mergeWith(t){return this.len+=t.len,!0}integrate(t,e){oe(t.deleteSet,e.id.client,e.id.clock,this.len),e.markDeleted()}delete(t){}gc(t){}write(t,e){t.writeLen(this.len-e)}getRef(){return 1}}const Ao=n=>new Xt(n.readLen()),$s=(n,t)=>new ut({guid:n,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Jt{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const e={};this.opts=e,t.gc||(e.gc=!1),t.autoLoad&&(e.autoLoad=!0),t.meta!==null&&(e.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Jt($s(this.doc.guid,this.opts))}splice(t){throw V()}mergeWith(t){return!1}integrate(t,e){this.doc._item=e,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,e){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}const Lo=n=>new Jt($s(n.readString(),n.readAny()));class pt{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new pt(this.embed)}splice(t){throw V()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeJSON(this.embed)}getRef(){return 5}}const Io=n=>new pt(n.readJSON());class A{constructor(t,e){this.key=t,this.value=e}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new A(this.key,this.value)}splice(t){throw V()}mergeWith(t){return!1}integrate(t,e){const s=e.parent;s._searchMarker=null,s._hasFormatting=!0}delete(t){}gc(t){}write(t,e){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}const vo=n=>new A(n.readKey(),n.readJSON());class ke{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ke(this.arr)}splice(t){const e=new ke(this.arr.slice(t));return this.arr=this.arr.slice(0,t),e}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){const s=this.arr.length;t.writeLen(s-e);for(let r=e;r<s;r++){const i=this.arr[r];t.writeString(i===void 0?"undefined":JSON.stringify(i))}}getRef(){return 2}}const Mo=n=>{const t=n.readLen(),e=[];for(let s=0;s<t;s++){const r=n.readString();r==="undefined"?e.push(void 0):e.push(JSON.parse(r))}return new ke(e)};class wt{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new wt(this.arr)}splice(t){const e=new wt(this.arr.slice(t));return this.arr=this.arr.slice(0,t),e}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){const s=this.arr.length;t.writeLen(s-e);for(let r=e;r<s;r++){const i=this.arr[r];t.writeAny(i)}}getRef(){return 8}}const xo=n=>{const t=n.readLen(),e=[];for(let s=0;s<t;s++)e.push(n.readAny());return new wt(e)};class j{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new j(this.str)}splice(t){const e=new j(this.str.slice(t));this.str=this.str.slice(0,t);const s=this.str.charCodeAt(t-1);return s>=55296&&s<=56319&&(this.str=this.str.slice(0,t-1)+"�",e.str="�"+e.str.slice(1)),e}mergeWith(t){return this.str+=t.str,!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeString(e===0?this.str:this.str.slice(e))}getRef(){return 4}}const To=n=>new j(n.readString()),Uo=[ho,fo,yo,ko,bo,So,Do],Oo=0,Ro=1,Bo=2,No=3,Fo=4,Vo=5,Ho=6;class q{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new q(this.type._copy())}splice(t){throw V()}mergeWith(t){return!1}integrate(t,e){this.type._integrate(t.doc,e)}delete(t){let e=this.type._start;for(;e!==null;)e.deleted?e.id.clock<(t.beforeState.get(e.id.client)||0)&&t._mergeStructs.push(e):e.delete(t),e=e.right;this.type._map.forEach(s=>{s.deleted?s.id.clock<(t.beforeState.get(s.id.client)||0)&&t._mergeStructs.push(s):s.delete(t)}),t.changed.delete(this.type)}gc(t){let e=this.type._start;for(;e!==null;)e.gc(t,!0),e=e.right;this.type._start=null,this.type._map.forEach(s=>{for(;s!==null;)s.gc(t,!0),s=s.left}),this.type._map=new Map}write(t,e){this.type._write(t)}getRef(){return 7}}const $o=n=>new q(Uo[n.readTypeRef()](n)),_e=(n,t,e)=>{const{client:s,clock:r}=t.id,i=new L(b(s,r+e),t,b(s,r+e-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(e));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),t.redone!==null&&(i.redone=b(t.redone.client,t.redone.clock+e)),t.right=i,i.right!==null&&(i.right.left=i),n._mergeStructs.push(i),i.parentSub!==null&&i.right===null&&i.parent._map.set(i.parentSub,i),t.length=e,i};class L extends dn{constructor(t,e,s,r,i,o,l,c){super(t,c.getLength()),this.origin=s,this.left=e,this.right=r,this.rightOrigin=i,this.parent=o,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?Bn:0}set marker(t){(this.info&Re)>0!==t&&(this.info^=Re)}get marker(){return(this.info&Re)>0}get keep(){return(this.info&Rn)>0}set keep(t){this.keep!==t&&(this.info^=Rn)}get countable(){return(this.info&Bn)>0}get deleted(){return(this.info&Oe)>0}set deleted(t){this.deleted!==t&&(this.info^=Oe)}markDeleted(){this.info|=Oe}getMissing(t,e){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=M(e,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=M(e,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Ct&&this.id.client!==this.parent.client&&this.parent.clock>=M(e,this.parent.client))return this.parent.client;if(this.origin&&(this.left=ws(t,e,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=st(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===L&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===L&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Ct){const s=tn(e,this.parent);s.constructor===R?this.parent=null:this.parent=s.content.type}return null}integrate(t,e){if(e>0&&(this.id.clock+=e,this.left=ws(t,t.doc.store,b(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(e),this.length-=e),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let s=this.left,r;if(s!==null)r=s.right;else 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;const i=new Set,o=new Set;for(;r!==null&&r!==this.right;){if(o.add(r),i.add(r),le(this.origin,r.origin)){if(r.id.client<this.id.client)s=r,i.clear();else if(le(this.rightOrigin,r.rightOrigin))break}else if(r.origin!==null&&o.has(tn(t.doc.store,r.origin)))i.has(tn(t.doc.store,r.origin))||(s=r,i.clear());else break;r=r.right}this.left=s}if(this.left!==null){const s=this.left.right;this.right=s,this.left.right=this}else{let s;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,this.parent._start=this;this.right=s}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),ps(t.doc.store,this),this.content.integrate(t,this),bs(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:b(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&le(t.origin,this.lastId)&&this.right===t&&le(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const e=this.parent._searchMarker;return e&&e.forEach(s=>{s.p===t&&(s.p=this,!this.deleted&&this.countable&&(s.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const e=this.parent;this.countable&&this.parentSub===null&&(e._length-=this.length),this.markDeleted(),oe(t.deleteSet,this.id.client,this.id.clock,this.length),bs(t,e,this.parentSub),this.content.delete(t)}}gc(t,e){if(!this.deleted)throw H();this.content.gc(t),e?Ji(t,this,new R(this.id,this.length)):this.content=new Xt(this.length)}write(t,e){const s=e>0?b(this.id.client,this.id.clock+e-1):this.origin,r=this.rightOrigin,i=this.parentSub,o=this.content.getRef()&ee|(s===null?0:O)|(r===null?0:J)|(i===null?0:Rt);if(t.writeInfo(o),s!==null&&t.writeLeftID(s),r!==null&&t.writeRightID(r),s===null&&r===null){const l=this.parent;if(l._item!==void 0){const c=l._item;if(c===null){const a=Xi(l);t.writeParentInfo(!0),t.writeString(a)}else t.writeParentInfo(!1),t.writeLeftID(c.id)}else l.constructor===String?(t.writeParentInfo(!0),t.writeString(l)):l.constructor===Ct?(t.writeParentInfo(!1),t.writeLeftID(l)):H();i!==null&&t.writeString(i)}this.content.write(t,e)}}const js=(n,t)=>jo[t&ee](n),jo=[()=>{H()},Ao,Mo,Co,To,Io,vo,$o,xo,Lo,()=>{H()}],Ko=10;class B extends dn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){H()}write(t,e){t.writeInfo(Ko),p(t.restEncoder,this.length-e)}getMissing(t,e){return null}}const Ks=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},zs="__ $YJS$ __";Ks[zs]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),Ks[zs]=!0;const Ys=new Map;class zo{constructor(t){this.room=t,this.onmessage=null,this._onChange=e=>e.key===t&&this.onmessage!==null&&this.onmessage({data:ni(e.newValue||"")}),Mr(this._onChange)}postMessage(t){xn.setItem(this.room,ei(Pr(t)))}close(){xr(this._onChange)}}const Yo=typeof BroadcastChannel>"u"?zo:BroadcastChannel,fn=n=>Y(Ys,n,()=>{const t=ot(),e=new Yo(n);return e.onmessage=s=>t.forEach(r=>r(s.data,"broadcastchannel")),{bc:e,subs:t}}),Xo=(n,t)=>(fn(n).subs.add(t),t),Jo=(n,t)=>{const e=fn(n),s=e.subs.delete(t);return s&&e.subs.size===0&&(e.bc.close(),Ys.delete(n)),s},vt=(n,t,e=null)=>{const s=fn(n);s.bc.postMessage(t),s.subs.forEach(r=>r(t,e))},Xs=0,gn=1,Js=2,pn=(n,t)=>{p(n,Xs);const e=zi(t);C(n,e)},Ws=(n,t,e)=>{p(n,gn),C(n,Ze(t,e))},Wo=(n,t,e)=>Ws(t,e,T(n)),Gs=(n,t,e)=>{try{ls(t,T(n),e)}catch(s){console.error("Caught error while handling a Yjs update",s)}},Go=(n,t)=>{p(n,Js),C(n,t)},Po=Gs,qo=(n,t,e,s)=>{const r=w(n);switch(r){case Xs:Wo(n,t,e);break;case gn:Gs(n,e,s);break;case Js:Po(n,e,s);break;default:throw new Error("Unknown message type")}return r},Zo=0,Qo=(n,t,e)=>{switch(w(n)){case Zo:e(t,nt(n))}},wn=3e4;class tl extends Zt{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const e=ht();this.getLocalState()!==null&&wn/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const s=[];this.meta.forEach((r,i)=>{i!==this.clientID&&wn<=e-r.lastUpdated&&this.states.has(i)&&s.push(i)}),s.length>0&&mn(this,s,"timeout")},X(wn/10)),t.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(t){const e=this.clientID,s=this.meta.get(e),r=s===void 0?0:s.clock+1,i=this.states.get(e);t===null?this.states.delete(e):this.states.set(e,t),this.meta.set(e,{clock:r,lastUpdated:ht()});const o=[],l=[],c=[],a=[];t===null?a.push(e):i==null?t!=null&&o.push(e):(l.push(e),Ot(i,t)||c.push(e)),(o.length>0||c.length>0||a.length>0)&&this.emit("change",[{added:o,updated:c,removed:a},"local"]),this.emit("update",[{added:o,updated:l,removed:a},"local"])}setLocalStateField(t,e){const s=this.getLocalState();s!==null&&this.setLocalState({...s,[t]:e})}getStates(){return this.states}}const mn=(n,t,e)=>{const s=[];for(let r=0;r<t.length;r++){const i=t[r];if(n.states.has(i)){if(n.states.delete(i),i===n.clientID){const o=n.meta.get(i);n.meta.set(i,{clock:o.clock+1,lastUpdated:ht()})}s.push(i)}}s.length>0&&(n.emit("change",[{added:[],updated:[],removed:s},e]),n.emit("update",[{added:[],updated:[],removed:s},e]))},Wt=(n,t,e=n.states)=>{const s=t.length,r=U();p(r,s);for(let i=0;i<s;i++){const o=t[i],l=e.get(o)||null,c=n.meta.get(o).clock;p(r,o),p(r,c),at(r,JSON.stringify(l))}return D(r)},el=(n,t,e)=>{const s=et(t),r=ht(),i=[],o=[],l=[],c=[],a=w(s);for(let h=0;h<a;h++){const d=w(s);let u=w(s);const f=JSON.parse(nt(s)),g=n.meta.get(d),m=n.states.get(d),E=g===void 0?0:g.clock;(E<u||E===u&&f===null&&n.states.has(d))&&(f===null?d===n.clientID&&n.getLocalState()!=null?u++:n.states.delete(d):n.states.set(d,f),n.meta.set(d,{clock:u,lastUpdated:r}),g===void 0&&f!==null?i.push(d):g!==void 0&&f===null?c.push(d):f!==null&&(Ot(f,m)||l.push(d),o.push(d)))}(i.length>0||l.length>0||c.length>0)&&n.emit("change",[{added:i,updated:l,removed:c},e]),(i.length>0||o.length>0||c.length>0)&&n.emit("update",[{added:i,updated:o,removed:c},e])},nl=n=>Rr(n,(t,e)=>`${encodeURIComponent(e)}=${encodeURIComponent(t)}`).join("&");var mt=0,Ps=3,Mt=1,sl=2,rl=typeof window>"u";function il(n,t){if(!n)throw new Error(t)}var Gt=[];Gt[mt]=(n,t,e,s,r)=>{p(n,mt);const i=qo(t,n,e.doc,e);s&&i===gn&&!e.synced&&(e.synced=!0)},Gt[Ps]=(n,t,e,s,r)=>{p(n,Mt),C(n,Wt(e.awareness,Array.from(e.awareness.getStates().keys())))},Gt[Mt]=(n,t,e,s,r)=>{el(e.awareness,T(t),e)},Gt[sl]=(n,t,e,s,r)=>{Qo(t,e.doc,(i,o)=>ol(e,o))};var qs=3e4;function ol(n,t){console.warn(`Permission denied to access ${n.url}.
4
+ ${t}`)}function Zs(n,t,e){const s=et(t),r=U(),i=w(s),o=n.messageHandlers[i];return o?o(r,s,n,e,i):console.error("Unable to compute message"),r}function Qs(n){if(n.shouldConnect&&n.ws===null){const t=new n._WS(n.url);t.binaryType="arraybuffer",n.ws=t,n.wsconnecting=!0,n.wsconnected=!1,n.synced=!1,t.onmessage=e=>{if(typeof e.data=="string")return;n.wsLastMessageReceived=ht();const s=Zs(n,new Uint8Array(e.data),!0);$e(s)>1&&t.send(D(s))},t.onerror=e=>{n.emit("connection-error",[e,n])},t.onclose=e=>{n.emit("connection-close",[e,n]),n.ws=null,n.wsconnecting=!1,n.wsconnected?(n.wsconnected=!1,n.synced=!1,mn(n.awareness,Array.from(n.awareness.getStates().keys()).filter(s=>s!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Qs,ve(_r(2,n.wsUnsuccessfulReconnects)*100,n.maxBackoffTime),n)},t.onopen=()=>{n.wsLastMessageReceived=ht(),n.wsconnecting=!1,n.wsconnected=!0,n.wsUnsuccessfulReconnects=0,n.emit("status",[{status:"connected"}]);const e=U();if(p(e,mt),pn(e,n.doc),t.send(D(e)),n.awareness.getLocalState()!==null){const s=U();p(s,Mt),C(s,Wt(n.awareness,[n.doc.clientID])),t.send(D(s))}},n.emit("status",[{status:"connecting"}])}}function yn(n,t){const e=n.ws;n.wsconnected&&e&&e.readyState===e.OPEN&&e.send(t),n.bcconnected&&vt(n.bcChannel,t,n)}var ll=class extends Zt{constructor(t,e,s,{connect:r=!0,awareness:i=new tl(s),params:o={},WebSocketPolyfill:l=WebSocket,resyncInterval:c=-1,maxBackoffTime:a=2500,disableBc:h=rl}={}){super();y(this,"maxBackoffTime");y(this,"bcChannel");y(this,"url");y(this,"roomname");y(this,"doc");y(this,"_WS");y(this,"awareness");y(this,"wsconnected");y(this,"wsconnecting");y(this,"bcconnected");y(this,"disableBc");y(this,"wsUnsuccessfulReconnects");y(this,"messageHandlers");y(this,"_synced");y(this,"ws");y(this,"wsLastMessageReceived");y(this,"shouldConnect");y(this,"_resyncInterval");y(this,"_bcSubscriber");y(this,"_updateHandler");y(this,"_awarenessUpdateHandler");y(this,"_unloadHandler");y(this,"_checkInterval");for(;t[t.length-1]==="/";)t=t.slice(0,t.length-1);const d=nl(o);this.maxBackoffTime=a,this.bcChannel=t+"/"+e,this.url=t+"/"+e+(d.length===0?"":"?"+d),this.roomname=e,this.doc=s,this._WS=l,this.awareness=i,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=h,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Gt.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=r,this._resyncInterval=0,c>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const u=U();p(u,mt),pn(u,s),this.ws.send(D(u))}},c)),this._bcSubscriber=(u,f)=>{if(f!==this){const g=Zs(this,new Uint8Array(u),!1);$e(g)>1&&vt(this.bcChannel,D(g),this)}},this._updateHandler=(u,f)=>{if(f!==this){const g=U();p(g,mt),Go(g,u),yn(this,D(g))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:u,updated:f,removed:g},m)=>{const E=u.concat(f).concat(g),Q=U();p(Q,Mt),C(Q,Wt(i,E)),yn(this,D(Q))},this._unloadHandler=()=>{mn(this.awareness,[s.clientID],"window unload")},typeof window<"u"?window.addEventListener("unload",this._unloadHandler):typeof process<"u"&&process.on("exit",this._unloadHandler),i.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&qs<ht()-this.wsLastMessageReceived&&(il(this.ws!==null,"ws must not be null"),this.ws.close())},qs/10),r&&this.connect()}get synced(){return this._synced}set synced(t){this._synced!==t&&(this._synced=t,this.emit("synced",[t]),this.emit("sync",[t]))}destroy(){this._resyncInterval!==0&&clearInterval(this._resyncInterval),clearInterval(this._checkInterval),this.disconnect(),typeof window<"u"?window.removeEventListener("unload",this._unloadHandler):typeof process<"u"&&process.off("exit",this._unloadHandler),this.awareness.off("update",this._awarenessUpdateHandler),this.doc.off("update",this._updateHandler),super.destroy()}connectBc(){if(this.disableBc)return;this.bcconnected||(Xo(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const t=U();p(t,mt),pn(t,this.doc),vt(this.bcChannel,D(t),this);const e=U();p(e,mt),Ws(e,this.doc),vt(this.bcChannel,D(e),this);const s=U();p(s,Ps),vt(this.bcChannel,D(s),this);const r=U();p(r,Mt),C(r,Wt(this.awareness,[this.doc.clientID])),vt(this.bcChannel,D(r),this)}disconnectBc(){const t=U();p(t,Mt),C(t,Wt(this.awareness,[this.doc.clientID],new Map)),yn(this,D(t)),this.bcconnected&&(Jo(this.bcChannel,this._bcSubscriber),this.bcconnected=!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&this.ws.close()}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(Qs(this),this.connectBc())}};function cl(){if(crypto.randomUUID)return crypto.randomUUID();let n=new Date().getTime(),t=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){let s=Math.random()*16;return n>0?(s=(n+s)%16|0,n=Math.floor(n/16)):(s=(t+s)%16|0,t=Math.floor(t/16)),(e==="x"?s:s&3|8).toString(16)})}function tr(n,t,e){if(typeof n!==e)throw new Error(`Invalid "${t}" parameter provided to YPartyKitProvider. Expected: ${e}, received: ${n}`)}var al=class extends WebSocket{send(n){typeof n!="string"&&wr(n,t=>super.send(t))}},hl=(dr=class extends ll{constructor(t,e,s,r={}){tr(t,"host","string"),tr(e,"room","string"),t=t.replace(/^(http|https|ws|wss):\/\//,""),t.endsWith("/")&&t.slice(0,-1);const i=`${t.startsWith("localhost:")||t.startsWith("127.0.0.1:")?"ws":"wss"}://${t}${r.party?`/parties/${r.party}`:"/party"}`,o=r.connectionId??cl(),{params:l,connect:c=!0,...a}=r,h={...a,connect:!1,WebSocketPolyfill:al};super(i,e,s??new ut,h);y(this,"id");gr(this,bt,void 0);this.id=o,pr(this,bt,l),c&&this.connect()}connect(){Promise.resolve(typeof Ae(this,bt)=="function"?Ae(this,bt).call(this):Ae(this,bt)).then(t=>{const e=new URLSearchParams([["_pk",this.id]]);if(t)for(const[r,i]of Object.entries(t))i!=null&&e.append(r,i);const s=new URL(this.url);s.search=e.toString(),this.url=s.toString(),super.connect()}).catch(t=>{throw console.error("Failed to open connecton to PartyKit",t),new Error(t)})}},bt=new WeakMap,dr);const yt=n=>St((t,e)=>{n.onerror=s=>e(new Error(s.target.error)),n.onsuccess=s=>t(s.target.result)}),ul=(n,t)=>St((e,s)=>{const r=indexedDB.open(n);r.onupgradeneeded=i=>t(i.target.result),r.onerror=i=>s(W(i.target.error)),r.onsuccess=i=>{const o=i.target.result;o.onversionchange=()=>{o.close()},typeof addEventListener<"u"&&addEventListener("unload",()=>o.close()),e(o)}}),dl=n=>yt(indexedDB.deleteDatabase(n)),fl=(n,t)=>t.forEach(e=>n.createObjectStore.apply(n,e)),Pt=(n,t,e="readwrite")=>{const s=n.transaction(t,e);return t.map(r=>_l(s,r))},er=(n,t)=>yt(n.count(t)),gl=(n,t)=>yt(n.get(t)),nr=(n,t)=>yt(n.delete(t)),pl=(n,t,e)=>yt(n.put(t,e)),bn=(n,t)=>yt(n.add(t)),wl=(n,t,e)=>yt(n.getAll(t,e)),ml=(n,t,e)=>{let s=null;return kl(n,t,r=>(s=r,!1),e).then(()=>s)},yl=(n,t=null)=>ml(n,t,"prev"),bl=(n,t)=>St((e,s)=>{n.onerror=s,n.onsuccess=async r=>{const i=r.target.result;if(i===null||await t(i)===!1)return e();i.continue()}}),kl=(n,t,e,s="next")=>bl(n.openKeyCursor(t,s),r=>e(r.key)),_l=(n,t)=>n.objectStore(t),Sl=(n,t)=>IDBKeyRange.upperBound(n,t),Dl=(n,t)=>IDBKeyRange.lowerBound(n,t),kn="custom",sr="updates",rr=500,ir=(n,t=()=>{},e=()=>{})=>{const[s]=Pt(n.db,[sr]);return wl(s,Dl(n._dbref,!1)).then(r=>{n._destroyed||(t(s),_(n.doc,()=>{r.forEach(i=>ls(n.doc,i))},n,!1),e(s))}).then(()=>yl(s).then(r=>{n._dbref=r+1})).then(()=>er(s).then(r=>{n._dbsize=r})).then(()=>s)},El=(n,t=!0)=>ir(n).then(e=>{(t||n._dbsize>=rr)&&bn(e,Ze(n.doc)).then(()=>nr(e,Sl(n._dbref,!0))).then(()=>er(e).then(s=>{n._dbsize=s}))});class Cl extends Zt{constructor(t,e){super(),this.doc=e,this.name=t,this._dbref=0,this._dbsize=0,this._destroyed=!1,this.db=null,this.synced=!1,this._db=ul(t,s=>fl(s,[["updates",{autoIncrement:!0}],["custom"]])),this.whenSynced=St(s=>this.on("synced",()=>s(this))),this._db.then(s=>{this.db=s,ir(this,o=>bn(o,Ze(e)),()=>{if(this._destroyed)return this;this.synced=!0,this.emit("synced",[this])})}),this._storeTimeout=1e3,this._storeTimeoutId=null,this._storeUpdate=(s,r)=>{if(this.db&&r!==this){const[i]=Pt(this.db,[sr]);bn(i,s),++this._dbsize>=rr&&(this._storeTimeoutId!==null&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout(()=>{El(this,!1),this._storeTimeoutId=null},this._storeTimeout))}},e.on("update",this._storeUpdate),this.destroy=this.destroy.bind(this),e.on("destroy",this.destroy)}destroy(){return this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this.doc.off("update",this._storeUpdate),this.doc.off("destroy",this.destroy),this._destroyed=!0,this._db.then(t=>{t.close()})}clearData(){return this.destroy().then(()=>{dl(this.name)})}get(t){return this._db.then(e=>{const[s]=Pt(e,[kn],"readonly");return gl(s,t)})}set(t,e){return this._db.then(s=>{const[r]=Pt(s,[kn]);return pl(r,e,t)})}del(t){return this._db.then(e=>{const[s]=Pt(e,[kn]);return nr(s,t)})}}const tc="",Al={ctrlKey:"Control",altKey:"Alt",shiftKey:"Shift",metaKey:"Meta"},Ll="can-duplicate-to";var Se=(n=>(n.CanPlay="can-play",n.CanMove="can-move",n.CanSpin="can-spin",n.CanGrow="can-grow",n.CanToggle="can-toggle",n.CanDuplicate="can-duplicate",n))(Se||{});function Il(n){return n.id}const or=`url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='44' height='53' viewport='0 0 100 100' style='fill:black;font-size:26px;'><text y='40%'>🚿</text></svg>")
5
5
  16 0,
6
- auto`,vl=`url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='40' height='48' viewport='0 0 100 100' style='fill:black;font-size:24px;'><text y='50%'>✂️</text></svg>") 16 0,auto`;function lr(n,{getData:t,getElement:e,getLocalData:s,setLocalData:r}){const i=t(),o=s(),l=e();if(o.isHovering=!0,n.altKey){if(i.scale<=.5){l.style.cursor="not-allowed";return}l.style.cursor=vl}else{if(i.scale>=i.maxScale){l.style.cursor="not-allowed";return}l.style.cursor=or}r(o)}function Se(n){if("touches"in n){const{clientX:t,clientY:e}=n.touches[0];return{clientX:t,clientY:e}}return{clientX:n.clientX,clientY:n.clientY}}const Ml={["can-move"]:{defaultData:{x:0,y:0},defaultLocalData:{startMouseX:0,startMouseY:0},updateElement:({element:n,data:t})=>{n.style.transform=`translate(${t.x}px, ${t.y}px)`},onDragStart:(n,{setLocalData:t})=>{const{clientX:e,clientY:s}=Se(n);t({startMouseX:e,startMouseY:s})},onDrag:(n,{data:t,localData:e,setData:s,setLocalData:r,element:i})=>{const{clientX:o,clientY:l}=Se(n),{top:c,left:a,bottom:h,right:d}=i.getBoundingClientRect();d>window.outerWidth&&o>e.startMouseX||h>window.innerHeight&&l>e.startMouseY||a<0&&o<e.startMouseX||c<0&&l<e.startMouseY||(s({x:t.x+o-e.startMouseX,y:t.y+l-e.startMouseY}),r({startMouseX:o,startMouseY:l}))},resetShortcut:"shiftKey"},["can-spin"]:{defaultData:{rotation:0},defaultLocalData:{startMouseX:0},updateElement:({element:n,data:t})=>{n.style.transform=`rotate(${t.rotation}deg)`},onDragStart:(n,{setLocalData:t})=>{const{clientX:e}=Se(n);t({startMouseX:e})},onDrag:(n,{data:t,localData:e,setData:s,setLocalData:r})=>{const{clientX:i}=Se(n);let o=Math.abs(i-e.startMouseX)*2,l=t.rotation;i>e.startMouseX?l+=o:i<e.startMouseX&&(l-=o),s({rotation:l}),r({startMouseX:i})},resetShortcut:"shiftKey"},["can-toggle"]:{defaultData:!1,updateElement:({element:n,data:t})=>{n.classList.toggle("clicked",t)},onClick:(n,{data:t,setData:e})=>{e(!t)},resetShortcut:"shiftKey"},["can-grow"]:{defaultData:{scale:1},defaultLocalData:{maxScale:2,isHovering:!1},updateElement:({element:n,data:t})=>{n.style.transform=`scale(${t.scale})`},onClick:(n,{data:t,element:e,setData:s,localData:r})=>{let{scale:i}=t;if(n.altKey){if(t.scale<=.5)return;i-=.1}else{if(e.style.cursor=or,t.scale>=r.maxScale)return;i+=.1}s({...t,scale:i})},additionalSetup:n=>{n.getElement().addEventListener("mouseenter",t=>{lr(t,n);const e=s=>lr(s,n);document.addEventListener("keydown",e),document.addEventListener("keyup",e),n.getElement().addEventListener("mouseleave",s=>{document.removeEventListener("keydown",e),document.removeEventListener("keyup",e)})})},resetShortcut:"shiftKey"},["can-duplicate"]:{defaultData:[],defaultLocalData:[],updateElement:({data:n,localData:t,setLocalData:e,element:s})=>{var r;const i=s.getAttribute("can-duplicate"),o=document.getElementById(i);let l=document.getElementById((r=t.slice(-1))==null?void 0:r[0])??null;if(!o){console.error(`Element with id ${i} not found. Cannot duplicate.`);return}const c=s.getAttribute(Ll);function a(d){if(c){const u=document.getElementById(c)||document.querySelector(c);if(u){u.appendChild(d);return}}o.parentNode.insertBefore(d,(l||o).nextSibling)}const h=new Set(t);for(const d of n){if(h.has(d))continue;const u=o.cloneNode(!0);Object.assign(u,{...o}),u.id=d,a(u),t.push(d),window.playhtml.setupPlayElement(u),l=u}e(t)},onClick:(n,{data:t,element:e,setData:s})=>{const r=e.getAttribute("can-duplicate")+"-"+Math.random().toString(36).substr(2,9);s([...t,r])},isValidElementForTag:n=>{const t=n.getAttribute("can-duplicate");return t?(document.getElementById(t)||console.warn(`can-duplicate element (${n.id}) duplicate element ("${t}") not found.`),!0):!1}}},cr=(n,t=300)=>{let e;return function(...s){clearTimeout(e),e=setTimeout(()=>n.apply(this,s),t)}};class xl{constructor(t){y(this,"defaultData");y(this,"localData");y(this,"awareness",[]);y(this,"selfAwareness");y(this,"element");y(this,"_data");y(this,"onChange");y(this,"onAwarenessChange");y(this,"debouncedOnChange");y(this,"resetShortcut");y(this,"updateElement");y(this,"updateElementAwareness");y(this,"triggerAwarenessUpdate");y(this,"onClick");y(this,"onDrag");y(this,"onDragStart");const{element:e,onChange:s,onAwarenessChange:r,defaultData:i,defaultLocalData:o,myDefaultAwareness:l,data:c,awareness:a,updateElement:h,updateElementAwareness:d,additionalSetup:u,debounceMs:f,triggerAwarenessUpdate:g}=t;this.element=e,this.defaultData=i instanceof Function?i(e):i,this.localData=o instanceof Function?o(e):o,this.triggerAwarenessUpdate=g,this.onChange=s,this.debouncedOnChange=cr(this.onChange,f),this.onAwarenessChange=r,this.updateElement=h,this.updateElementAwareness=d;const m=c===void 0?this.defaultData:c;a!==void 0&&(this.__awareness=a);const E=l instanceof Function?l(e):l;E!==void 0&&this.setLocalAwareness(E),this._data=m,this.__data=m,this.reinitializeElementData(t),u&&u(this.getSetupData())}reinitializeElementData({element:t,onChange:e,onAwarenessChange:s,updateElement:r,updateElementAwareness:i,onClick:o,onDrag:l,onDragStart:c,resetShortcut:a,debounceMs:h,triggerAwarenessUpdate:d}){this.triggerAwarenessUpdate=d,this.onChange=e,this.debouncedOnChange=cr(this.onChange,h),this.onAwarenessChange=s,this.updateElement=r,this.updateElementAwareness=i,o&&!this.onClick&&t.addEventListener("click",u=>{var f;(f=this.onClick)==null||f.call(this,u,this.getEventHandlerData())}),this.onClick=o,l&&!this.onDrag&&(t.addEventListener("touchstart",u=>{var m;u.preventDefault(),(m=this.onDragStart)==null||m.call(this,u,this.getEventHandlerData());const f=E=>{var Q;E.preventDefault(),(Q=this.onDrag)==null||Q.call(this,E,this.getEventHandlerData())},g=E=>{document.removeEventListener("touchmove",f),document.removeEventListener("touchend",g)};document.addEventListener("touchmove",f),document.addEventListener("touchend",g)}),t.addEventListener("mousedown",u=>{var m;(m=this.onDragStart)==null||m.call(this,u,this.getEventHandlerData());const f=E=>{var Q;E.preventDefault(),(Q=this.onDrag)==null||Q.call(this,E,this.getEventHandlerData())},g=E=>{document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",g)};document.addEventListener("mousemove",f),document.addEventListener("mouseup",g)})),this.onDrag=l,this.onDragStart=c,a&&!this.resetShortcut&&(t.title||(t.title=`Hold down the ${Al[a]} key while clicking to reset.`),t.reset=this.reset,t.addEventListener("click",u=>{switch(this.resetShortcut){case"ctrlKey":if(!u.ctrlKey)return;break;case"altKey":if(!u.altKey)return;break;case"shiftKey":if(!u.shiftKey)return;break;case"metaKey":if(!u.metaKey)return;break;default:return}this.reset(),u.preventDefault(),u.stopPropagation()})),this.resetShortcut=a}get data(){return this._data}setLocalData(t){this.localData=t}set __data(t){this._data=t,this.updateElement(this.getEventHandlerData())}set __awareness(t){this.updateElementAwareness&&(this.awareness=t,this.updateElementAwareness(this.getAwarenessEventHandlerData()))}getEventHandlerData(){return{element:this.element,data:this.data,localData:this.localData,awareness:this.awareness,setData:t=>this.setData(t),setLocalData:t=>this.setLocalData(t),setLocalAwareness:t=>this.setLocalAwareness(t)}}getAwarenessEventHandlerData(){return{...this.getEventHandlerData(),myAwareness:this.selfAwareness}}getSetupData(){return{getElement:()=>this.element,getData:()=>this.data,getLocalData:()=>this.localData,getAwareness:()=>this.awareness,setData:t=>this.setData(t),setLocalData:t=>this.setLocalData(t),setLocalAwareness:t=>this.setLocalAwareness(t)}}setData(t){this.onChange(t)}setLocalAwareness(t){var e;t!==this.selfAwareness&&(this.selfAwareness=t,this.onAwarenessChange(t),(e=this.triggerAwarenessUpdate)==null||e.call(this))}setDataDebounced(t){this.debouncedOnChange(t)}reset(){this.setData(this.defaultData)}}const Tl="playhtml.spencerc99.partykit.dev",_n=new ut;function Ul(){return window.location.pathname+window.location.search}let Z,K,z;const ar=new Map;let qt=Ml;function Sn(){return Object.keys(qt)}let Dn=!1,En=!0;function hr({room:n=Ul(),host:t=Tl,extraCapabilities:e}={}){if(!En){console.error("playhtml already set up!");return}const s=encodeURIComponent(window.location.hostname+"-"+n),r=t;if(console.log(`࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂
6
+ auto`,vl=`url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='40' height='48' viewport='0 0 100 100' style='fill:black;font-size:24px;'><text y='50%'>✂️</text></svg>") 16 0,auto`;function lr(n,{getData:t,getElement:e,getLocalData:s,setLocalData:r}){const i=t(),o=s(),l=e();if(o.isHovering=!0,n.altKey){if(i.scale<=.5){l.style.cursor="not-allowed";return}l.style.cursor=vl}else{if(i.scale>=i.maxScale){l.style.cursor="not-allowed";return}l.style.cursor=or}r(o)}function De(n){if("touches"in n){const{clientX:t,clientY:e}=n.touches[0];return{clientX:t,clientY:e}}return{clientX:n.clientX,clientY:n.clientY}}const Ml={["can-move"]:{defaultData:{x:0,y:0},defaultLocalData:{startMouseX:0,startMouseY:0},updateElement:({element:n,data:t})=>{n.style.transform=`translate(${t.x}px, ${t.y}px)`},onDragStart:(n,{setLocalData:t})=>{const{clientX:e,clientY:s}=De(n);t({startMouseX:e,startMouseY:s})},onDrag:(n,{data:t,localData:e,setData:s,setLocalData:r,element:i})=>{const{clientX:o,clientY:l}=De(n),{top:c,left:a,bottom:h,right:d}=i.getBoundingClientRect();d>window.outerWidth&&o>e.startMouseX||h>window.innerHeight&&l>e.startMouseY||a<0&&o<e.startMouseX||c<0&&l<e.startMouseY||(s({x:t.x+o-e.startMouseX,y:t.y+l-e.startMouseY}),r({startMouseX:o,startMouseY:l}))},resetShortcut:"shiftKey"},["can-spin"]:{defaultData:{rotation:0},defaultLocalData:{startMouseX:0},updateElement:({element:n,data:t})=>{n.style.transform=`rotate(${t.rotation}deg)`},onDragStart:(n,{setLocalData:t})=>{const{clientX:e}=De(n);t({startMouseX:e})},onDrag:(n,{data:t,localData:e,setData:s,setLocalData:r})=>{const{clientX:i}=De(n);let o=Math.abs(i-e.startMouseX)*2,l=t.rotation;i>e.startMouseX?l+=o:i<e.startMouseX&&(l-=o),s({rotation:l}),r({startMouseX:i})},resetShortcut:"shiftKey"},["can-toggle"]:{defaultData:!1,updateElement:({element:n,data:t})=>{n.classList.toggle("clicked",t)},onClick:(n,{data:t,setData:e})=>{e(!t)},resetShortcut:"shiftKey"},["can-grow"]:{defaultData:{scale:1},defaultLocalData:{maxScale:2,isHovering:!1},updateElement:({element:n,data:t})=>{n.style.transform=`scale(${t.scale})`},onClick:(n,{data:t,element:e,setData:s,localData:r})=>{let{scale:i}=t;if(n.altKey){if(t.scale<=.5)return;i-=.1}else{if(e.style.cursor=or,t.scale>=r.maxScale)return;i+=.1}s({...t,scale:i})},additionalSetup:n=>{n.getElement().addEventListener("mouseenter",t=>{lr(t,n);const e=s=>lr(s,n);document.addEventListener("keydown",e),document.addEventListener("keyup",e),n.getElement().addEventListener("mouseleave",s=>{document.removeEventListener("keydown",e),document.removeEventListener("keyup",e)})})},resetShortcut:"shiftKey"},["can-duplicate"]:{defaultData:[],defaultLocalData:[],updateElement:({data:n,localData:t,setLocalData:e,element:s})=>{var r;const i=s.getAttribute("can-duplicate"),o=document.getElementById(i);let l=document.getElementById((r=t.slice(-1))==null?void 0:r[0])??null;if(!o){console.error(`Element with id ${i} not found. Cannot duplicate.`);return}const c=s.getAttribute(Ll);function a(d){if(c){const u=document.getElementById(c)||document.querySelector(c);if(u){u.appendChild(d);return}}o.parentNode.insertBefore(d,(l||o).nextSibling)}const h=new Set(t);for(const d of n){if(h.has(d))continue;const u=o.cloneNode(!0);Object.assign(u,{...o}),u.id=d,a(u),t.push(d),window.playhtml.setupPlayElement(u),l=u}e(t)},onClick:(n,{data:t,element:e,setData:s})=>{const r=e.getAttribute("can-duplicate")+"-"+Math.random().toString(36).substr(2,9);s([...t,r])},isValidElementForTag:n=>{const t=n.getAttribute("can-duplicate");return t?(document.getElementById(t)||console.warn(`can-duplicate element (${n.id}) duplicate element ("${t}") not found.`),!0):!1}}},cr=(n,t=300)=>{let e;return function(...s){clearTimeout(e),e=setTimeout(()=>n.apply(this,s),t)}};class xl{constructor(t){y(this,"defaultData");y(this,"localData");y(this,"awareness",[]);y(this,"selfAwareness");y(this,"element");y(this,"_data");y(this,"onChange");y(this,"onAwarenessChange");y(this,"debouncedOnChange");y(this,"resetShortcut");y(this,"updateElement");y(this,"updateElementAwareness");y(this,"triggerAwarenessUpdate");y(this,"onClick");y(this,"onDrag");y(this,"onDragStart");const{element:e,onChange:s,onAwarenessChange:r,defaultData:i,defaultLocalData:o,myDefaultAwareness:l,data:c,awareness:a,updateElement:h,updateElementAwareness:d,additionalSetup:u,debounceMs:f,triggerAwarenessUpdate:g}=t;this.element=e,this.defaultData=i instanceof Function?i(e):i,this.localData=o instanceof Function?o(e):o,this.triggerAwarenessUpdate=g,this.onChange=s,this.debouncedOnChange=cr(this.onChange,f),this.onAwarenessChange=r,this.updateElement=h,this.updateElementAwareness=d;const m=c===void 0?this.defaultData:c;a!==void 0&&(this.__awareness=a);const E=l instanceof Function?l(e):l;E!==void 0&&this.setLocalAwareness(E),this._data=m,this.__data=m,this.reinitializeElementData(t),u&&u(this.getSetupData())}reinitializeElementData({element:t,onChange:e,onAwarenessChange:s,updateElement:r,updateElementAwareness:i,onClick:o,onDrag:l,onDragStart:c,resetShortcut:a,debounceMs:h,triggerAwarenessUpdate:d}){this.triggerAwarenessUpdate=d,this.onChange=e,this.debouncedOnChange=cr(this.onChange,h),this.onAwarenessChange=s,this.updateElement=r,this.updateElementAwareness=i,o&&!this.onClick&&t.addEventListener("click",u=>{var f;(f=this.onClick)==null||f.call(this,u,this.getEventHandlerData())}),this.onClick=o,l&&!this.onDrag&&(t.addEventListener("touchstart",u=>{var m;u.preventDefault(),(m=this.onDragStart)==null||m.call(this,u,this.getEventHandlerData());const f=E=>{var Q;E.preventDefault(),(Q=this.onDrag)==null||Q.call(this,E,this.getEventHandlerData())},g=E=>{document.removeEventListener("touchmove",f),document.removeEventListener("touchend",g)};document.addEventListener("touchmove",f),document.addEventListener("touchend",g)}),t.addEventListener("mousedown",u=>{var m;(m=this.onDragStart)==null||m.call(this,u,this.getEventHandlerData());const f=E=>{var Q;E.preventDefault(),(Q=this.onDrag)==null||Q.call(this,E,this.getEventHandlerData())},g=E=>{document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",g)};document.addEventListener("mousemove",f),document.addEventListener("mouseup",g)})),this.onDrag=l,this.onDragStart=c,a&&!this.resetShortcut&&(t.title||(t.title=`Hold down the ${Al[a]} key while clicking to reset.`),t.reset=this.reset,t.addEventListener("click",u=>{switch(this.resetShortcut){case"ctrlKey":if(!u.ctrlKey)return;break;case"altKey":if(!u.altKey)return;break;case"shiftKey":if(!u.shiftKey)return;break;case"metaKey":if(!u.metaKey)return;break;default:return}this.reset(),u.preventDefault(),u.stopPropagation()})),this.resetShortcut=a}get data(){return this._data}setLocalData(t){this.localData=t}set __data(t){this._data=t,this.updateElement(this.getEventHandlerData())}set __awareness(t){this.updateElementAwareness&&(this.awareness=t,this.updateElementAwareness(this.getAwarenessEventHandlerData()))}getEventHandlerData(){return{element:this.element,data:this.data,localData:this.localData,awareness:this.awareness,setData:t=>this.setData(t),setLocalData:t=>this.setLocalData(t),setLocalAwareness:t=>this.setLocalAwareness(t)}}getAwarenessEventHandlerData(){return{...this.getEventHandlerData(),myAwareness:this.selfAwareness}}getSetupData(){return{getElement:()=>this.element,getData:()=>this.data,getLocalData:()=>this.localData,getAwareness:()=>this.awareness,setData:t=>this.setData(t),setLocalData:t=>this.setLocalData(t),setLocalAwareness:t=>this.setLocalAwareness(t)}}setData(t){this.onChange(t)}setLocalAwareness(t){var e;t!==this.selfAwareness&&(this.selfAwareness=t,this.onAwarenessChange(t),(e=this.triggerAwarenessUpdate)==null||e.call(this))}setDataDebounced(t){this.debouncedOnChange(t)}reset(){this.setData(this.defaultData)}}const Tl="playhtml.spencerc99.partykit.dev",_n=new ut;function Ul(){return window.location.pathname+window.location.search}let Z,K,z;const ar=new Map;let qt=Ml;function Sn(){return[Se.CanPlay,...Object.keys(qt)]}let Dn=!1,En=!0;function hr({room:n=Ul(),host:t=Tl,extraCapabilities:e}={}){if(!En){console.error("playhtml already set up!");return}const s=encodeURIComponent(window.location.hostname+"-"+n),r=t;if(console.log(`࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂
7
7
  ࿂࿂࿂࿂ ࿂ ࿂ ࿂ ࿂ ࿂ ࿂࿂࿂࿂
8
8
  ࿂࿂࿂࿂ booting up playhtml... ࿂࿂࿂࿂
9
9
  ࿂࿂࿂࿂ https://playhtml.fun ࿂࿂࿂࿂
10
10
  ࿂࿂࿂࿂ ࿂ ࿂ ࿂ ࿂ ࿂࿂࿂࿂
11
- ࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂`),Z=new hl(r,s,_n),K=_n.getMap("playhtml-global"),z=new Map,new Cl(s,_n),De.globalData=K,De.elementHandlers=z,e)for(const[i,o]of Object.entries(e))qt[i]=o;return Z.on("sync",i=>{i||console.error("Issue connecting to yjs..."),Dn=!0,Fl()}),Z}setTimeout(()=>{Z||(console.error("You are using a deprecated version of playhtml. Please call `playhtml.init()` explicitly rather than just importing the library. Refer to https://github.com/spencerc99/playhtml#usage for reference."),hr())},3e3);function Ol(n,t){const e=Z.awareness.getLocalState();return((e==null?void 0:e[n])??{})[t]}function Cn(n){return n instanceof HTMLElement}function Rl(n,t,e,s){const r=K.get(t);return{...e,data:r.get(s)??e.defaultData,awareness:Ol(t,s)??e.myDefaultAwareness!==void 0?[e.myDefaultAwareness]:void 0,element:n,onChange:o=>{r.get(s)!==o&&r.set(s,o)},onAwarenessChange:o=>{var c;const l=((c=Z.awareness.getLocalState())==null?void 0:c[t])||{};l[s]!==o&&(l[s]=o,Z.awareness.setLocalStateField(t,l))},triggerAwarenessUpdate:()=>{ur()}}}function Bl(n){return n.defaultData!==void 0&&n.updateElement!==void 0}function Nl(n,t){if(n===kn.CanPlay){const e=t;return{defaultData:e.defaultData,defaultLocalData:e.defaultLocalData,myDefaultAwareness:e.myDefaultAwareness,updateElement:e.updateElement,updateElementAwareness:e.updateElementAwareness,onDrag:e.onDrag,onDragStart:e.onDragStart,onClick:e.onClick,additionalSetup:e.additionalSetup,resetShortcut:e.resetShortcut,debounceMs:e.debounceMs,isValidElementForTag:e.isValidElementForTag}}return qt[n]}function ur(){const n=new Map;function t(e,s,r,i){n.has(e)||n.set(e,new Map);const o=n.get(e);o.has(s)||o.set(s,new Map),o.get(s).set(r,i)}Z.awareness.getStates().forEach((e,s)=>{var r;for(const[i,o]of Object.entries(e)){const l=z.get(i);if(l)for(const[c,a]of l){if(!(c in o))continue;const h=o[c];t(i,c,s,h)}}for(const[i,o]of n){const l=z.get(i);if(l)for(const[c,a]of l){const h=(r=o.get(c))==null?void 0:r.values();if(!h)continue;let d=Array.from(h);a.__awareness=d}}})}function Fl(){console.log("[PLAYHTML]: Setting up elements... Time to have some fun 🛝"),console.log(Sn());for(const n of Sn()){const t=Array.from(document.querySelectorAll(`[${n}]`)).filter(Cn);if(t.length)for(let e=0;e<t.length;e++){const s=t[e];Ee(s,n)}}En&&(K.observe(n=>{n.changes.keys.forEach((t,e)=>{t.action==="add"&&K.set(e,K.get(e))})}),Z.awareness.on("change",()=>ur()),En=!1)}const De={init:hr,setupPlayElement:$l,removePlayElement:jl,setupPlayElementForTag:Ee,globalData:void 0,elementHandlers:void 0};window.playhtml=De;function Vl(n){if(z.has(n)||!Dn)return;z.set(n,new Map),n!==kn.CanPlay&&qt[n],K.get(n)||K.set(n,new ft);const t=K.get(n);t.observe(e=>{e.changes.keys.forEach((s,r)=>{const i=z.get(n);if(s.action==="add"){const o=document.getElementById(r);if(!Cn(o)){console.log(`Element ${r} not an HTML element. Ignoring.`);return}Ee(o,n)}else if(s.action==="update"){const o=i.get(r);o.__data=t.get(r)}else s.action==="delete"?i.delete(r):console.log(`Unhandled action: ${s.action}`)})})}function Hl(n,t){var e,s;return((s=(e=qt[t])==null?void 0:e.isValidElementForTag)==null?void 0:s.call(e,n))??!0}function Ee(n,t){var l;if(!Hl(n,t)||!Dn)return;if(!n.id){const c=n.getAttribute("selector-id");if(c){const a=ar.get(c)??0;n.id=btoa(`${t}-${c}-${a}`),ar.set(c,a+1)}else n.id=btoa(`${t}-${n.innerHTML}}`)}const e=Il(n);if(!e){console.error(`Element ${n} does not have an acceptable ID. Please add an ID to the element to register it as a playhtml element.`);return}Vl(t);const s=z.get(t),r=Nl(t,n);if(!Bl(r)){console.error(`Element ${e} does not have proper info to initial a playhtml element. Please refer to https://github.com/spencerc99/playhtml#can-play for troubleshooting help.`);return}const i=K.get(t),o=Rl(n,t,r,e);if(s.has(e)){s.get(e).reinitializeElementData(o);return}else s.set(e,new xl(o));i.get(e)===void 0&&r.defaultData!==void 0&&i.set(e,r.defaultData),(l=o.triggerAwarenessUpdate)==null||l.call(o),n.classList.add("__playhtml-element"),n.classList.add(`__playhtml-${t}`),n.style.setProperty("--jiggle-delay",`${Math.random()*1}s;}`)}function $l(n){if(!Cn(n)){console.log(`Element ${n.id} not an HTML element. Ignoring.`);return}for(const t of Sn())n.hasAttribute(t)&&Ee(n,t)}function jl(n){if(!(!n||!n.id))for(const t of Object.keys(z)){const e=z.get(t);e.has(n.id)&&e.delete(n.id)}}S.playhtml=De,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
11
+ ࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂`),Z=new hl(r,s,_n),K=_n.getMap("playhtml-global"),z=new Map,new Cl(s,_n),Ee.globalData=K,Ee.elementHandlers=z,e)for(const[i,o]of Object.entries(e))qt[i]=o;return Z.on("sync",i=>{i||console.error("Issue connecting to yjs..."),Dn=!0,Fl()}),Z}setTimeout(()=>{Z||(console.error("You are using a deprecated version of playhtml. Please call `playhtml.init()` explicitly rather than just importing the library. Refer to https://github.com/spencerc99/playhtml#usage for reference."),hr())},3e3);function Ol(n,t){const e=Z.awareness.getLocalState();return((e==null?void 0:e[n])??{})[t]}function Cn(n){return n instanceof HTMLElement}function Rl(n,t,e,s){const r=K.get(t);return{...e,data:r.get(s)??e.defaultData,awareness:Ol(t,s)??e.myDefaultAwareness!==void 0?[e.myDefaultAwareness]:void 0,element:n,onChange:o=>{r.get(s)!==o&&r.set(s,o)},onAwarenessChange:o=>{var c;const l=((c=Z.awareness.getLocalState())==null?void 0:c[t])||{};l[s]!==o&&(l[s]=o,Z.awareness.setLocalStateField(t,l))},triggerAwarenessUpdate:()=>{ur()}}}function Bl(n){return n.defaultData!==void 0&&n.updateElement!==void 0}function Nl(n,t){if(n===Se.CanPlay){const e=t;return{defaultData:e.defaultData,defaultLocalData:e.defaultLocalData,myDefaultAwareness:e.myDefaultAwareness,updateElement:e.updateElement,updateElementAwareness:e.updateElementAwareness,onDrag:e.onDrag,onDragStart:e.onDragStart,onClick:e.onClick,additionalSetup:e.additionalSetup,resetShortcut:e.resetShortcut,debounceMs:e.debounceMs,isValidElementForTag:e.isValidElementForTag}}return qt[n]}function ur(){const n=new Map;function t(e,s,r,i){n.has(e)||n.set(e,new Map);const o=n.get(e);o.has(s)||o.set(s,new Map),o.get(s).set(r,i)}Z.awareness.getStates().forEach((e,s)=>{var r;for(const[i,o]of Object.entries(e)){const l=z.get(i);if(l)for(const[c,a]of l){if(!(c in o))continue;const h=o[c];t(i,c,s,h)}}for(const[i,o]of n){const l=z.get(i);if(l)for(const[c,a]of l){const h=(r=o.get(c))==null?void 0:r.values();if(!h)continue;let d=Array.from(h);a.__awareness=d}}})}function Fl(){console.log("[PLAYHTML]: Setting up elements... Time to have some fun 🛝"),console.log(Sn());for(const n of Sn()){const t=Array.from(document.querySelectorAll(`[${n}]`)).filter(Cn);if(t.length)for(let e=0;e<t.length;e++){const s=t[e];Ce(s,n)}}En&&(K.observe(n=>{n.changes.keys.forEach((t,e)=>{t.action==="add"&&K.set(e,K.get(e))})}),Z.awareness.on("change",()=>ur()),En=!1)}const Ee={init:hr,setupPlayElement:$l,removePlayElement:jl,setupPlayElementForTag:Ce,globalData:void 0,elementHandlers:void 0};window.playhtml=Ee;function Vl(n){if(z.has(n)||!Dn)return;z.set(n,new Map),n!==Se.CanPlay&&qt[n],K.get(n)||K.set(n,new ft);const t=K.get(n);t.observe(e=>{e.changes.keys.forEach((s,r)=>{const i=z.get(n);if(s.action==="add"){const o=document.getElementById(r);if(!Cn(o)){console.log(`Element ${r} not an HTML element. Ignoring.`);return}Ce(o,n)}else if(s.action==="update"){const o=i.get(r);o.__data=t.get(r)}else s.action==="delete"?i.delete(r):console.log(`Unhandled action: ${s.action}`)})})}function Hl(n,t){var e,s;return((s=(e=qt[t])==null?void 0:e.isValidElementForTag)==null?void 0:s.call(e,n))??!0}function Ce(n,t){var l;if(!Hl(n,t)||!Dn)return;if(!n.id){const c=n.getAttribute("selector-id");if(c){const a=ar.get(c)??0;n.id=btoa(`${t}-${c}-${a}`),ar.set(c,a+1)}else n.id=btoa(`${t}-${n.innerHTML}}`)}const e=Il(n);if(!e){console.error(`Element ${n} does not have an acceptable ID. Please add an ID to the element to register it as a playhtml element.`);return}Vl(t);const s=z.get(t),r=Nl(t,n);if(!Bl(r)){console.error(`Element ${e} does not have proper info to initial a playhtml element. Please refer to https://github.com/spencerc99/playhtml#can-play for troubleshooting help.`);return}const i=K.get(t),o=Rl(n,t,r,e);if(s.has(e)){s.get(e).reinitializeElementData(o);return}else s.set(e,new xl(o));i.get(e)===void 0&&r.defaultData!==void 0&&i.set(e,r.defaultData),(l=o.triggerAwarenessUpdate)==null||l.call(o),n.classList.add("__playhtml-element"),n.classList.add(`__playhtml-${t}`),n.style.setProperty("--jiggle-delay",`${Math.random()*1}s;}`)}function $l(n){if(!Cn(n)){console.log(`Element ${n.id} not an HTML element. Ignoring.`);return}for(const t of Sn())n.hasAttribute(t)&&Ce(n,t)}function jl(n){if(!(!n||!n.id))for(const t of Object.keys(z)){const e=z.get(t);e.has(n.id)&&e.delete(n.id)}}S.playhtml=Ee,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "playhtml",
3
3
  "title": "playhtml",
4
4
  "description": "Create interactive, collaborative html elements with a single attribute",
5
- "version": "2.0.11",
5
+ "version": "2.0.12",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "keywords": [