playhtml 2.0.17 → 2.0.18

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 Le=(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(Cn({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(Cn({id:e,type:"end",size:r,count:i}))};function Cn(n){return`${I}#${JSON.stringify(n)}`}const F=()=>new Map,Ie=n=>{const t=F();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,ve=n=>n[n.length-1],br=(n,t)=>{for(let e=0;e<t.length;e++)n.push(t[e])},Q=Array.from,kr=Array.isArray;class Zt{constructor(){this._observers=F()}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 Q((this._observers.get(t)||F()).values()).forEach(s=>s(...e))}destroy(){this._observers=F()}}const X=Math.floor,Qt=Math.abs,Me=(n,t)=>n<t?n:t,lt=(n,t)=>n>t?n:t,_r=Math.pow,An=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,Ln=(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 In=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 vn=new vr,xe=!0;try{typeof localStorage<"u"&&(vn=localStorage,xe=!1)}catch{}const Mn=vn,Mr=n=>xe||addEventListener("storage",n),xr=n=>xe||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},xn=(n,t)=>Object.prototype.hasOwnProperty.call(n,t),Fr=(n,t)=>n===t||te(n)===te(t)&&Nr(n,(e,s)=>(e!==void 0||xn(t,s))&&t[s]===e),Te=(n,t,e=0)=>{try{for(;e<n.length;e++)n[e](...t)}finally{e<n.length&&Te(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(!xn(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),Tn=typeof window<"u"&&typeof document<"u"&&!kt;let V;const jr=()=>{if(V===void 0)if(kt){V=F();const n=process.argv;let t=null;for(let e=0;e<n.length;e++){const s=n[e];s[0]==="-"?(t!==null&&V.set(t,""),t=s):t!==null&&(V.set(t,s),t=null)}t!==null&&V.set(t,"")}else typeof location=="object"?(V=F(),(location.search||"?").slice(1).split("&").forEach(n=>{if(n.length!==0){const[t,e]=n.split("=");V.set(`--${Ln(t,"-")}`,e),V.set(`-${Ln(t,"-")}`,e)}})):V=F();return V},Ue=n=>jr().has(n),Oe=n=>In(kt?process.env[n.toUpperCase()]:Mn.getItem(n));(n=>Ue("--"+n)||Oe(n)!==null)("production");const Un=kt&&$r(process.env.FORCE_COLOR,["true","1","2"]),Kr=!Ue("no-colors")&&(!kt||process.stdout.isTTY||Un)&&(!kt||Ue("color")||Un||Oe("COLORTERM")!==null||(Oe("TERM")||"").includes("color")),On=1,Rn=2,Re=4,Be=8,Rt=32,J=64,O=128,ee=31,Ne=63,ct=127,zr=2147483647,Bn=Number.MAX_SAFE_INTEGER,Yr=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&X(n)===n),W=n=>new Error(n),H=()=>{throw W("Method unimplemented")},$=()=>{throw W("Unexpected case")},Nn=W("Unexpected end of array"),Fn=W("Integer out of Range");class ne{constructor(t){this.arr=t,this.pos=0}}const tt=n=>new ne(n),Xr=n=>n.pos!==n.arr.length,Jr=(n,t)=>{const e=$e(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>Bn)throw Fn}throw Nn},Fe=n=>{let t=n.arr[n.pos++],e=t&Ne,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>Bn)throw Fn}throw Nn},et=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))}},Ve=(n,t)=>{const e=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,t);return n.pos+=t,e},Wr=[n=>{},n=>null,Fe,n=>Ve(n,4).getFloat32(0,!1),n=>Ve(n,8).getFloat64(0,!1),n=>Ve(n,8).getBigInt64(0,!1),n=>!1,n=>!0,et,n=>{const t=w(n),e={};for(let s=0;s<t;s++){const r=et(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 Vn 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=Fe(this);const t=An(this.s);this.count=1,t&&(this.s=-this.s,this.count=w(this)+2)}return this.count--,this.s}}class He extends ne{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=Fe(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=et(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 Hn=n=>new Uint8Array(n),$e=(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=Hn(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=Tn?qr:Zr,ni=Tn?Qr:ti,si=n=>{const t=Hn(n.byteLength);return t.set(n),t};class Nt{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const U=()=>new Nt,je=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(je(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($e(n.cbuf.buffer,0,n.cpos),e),t},ri=(n,t)=>{const e=n.cbuf.length;e-n.cpos<t&&(n.bufs.push($e(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},Ke=v,p=(n,t)=>{for(;t>ct;)v(n,O|ct&t),t=X(t/128);v(n,ct&t)},ze=(n,t)=>{const e=An(t);for(e&&(t=-t),v(n,(t>Ne?O:0)|(e?J:0)|Ne&t),t=X(t/64);t>0;)v(n,(t>ct?O:0)|ct&t),t=X(t/128)},Ye=new Uint8Array(3e4),ii=Ye.length/3,oi=(n,t)=>{if(t.length<ii){const e=Tt.encodeInto(t,Ye).written||0;p(n,e);for(let s=0;s<e;s++)v(n,Ye[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=Me(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)},Xe=(n,t)=>{ri(n,t);const e=new DataView(n.cbuf.buffer,n.cpos,t);return n.cpos+=t,e},ci=(n,t)=>Xe(n,4).setFloat32(0,t,!1),ai=(n,t)=>Xe(n,8).setFloat64(0,t,!1),hi=(n,t)=>Xe(n,8).setBigInt64(0,t,!1),$n=new DataView(new ArrayBuffer(4)),ui=n=>($n.setFloat32(0,n),$n.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),ze(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 jn 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 Kn=n=>{n.count>0&&(ze(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++:(Kn(this),this.count=1,this.s=t)}toUint8Array(){return Kn(this),D(this.encoder)}}const zn=n=>{if(n.count>0){const t=n.diff*2+(n.count===1?0:1);ze(n.encoder,t),n.count>1&&p(n.encoder,n.count-2)}};class Je{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++):(zn(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return zn(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),Yn=()=>fi(new Uint32Array(1))[0],gi=[1e7]+-1e3+-4e3+-8e3+-1e11,pi=()=>gi.replace(/[018]/g,n=>(n^Yn()&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,Xn=P(),Jn=P(),yi=P(),bi=P(),ki=P(),Wn=P(),_i=P(),Gn=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={[Xn]:G("font-weight","bold"),[Jn]:G("font-weight","normal"),[yi]:G("color","blue"),[ki]:G("color","green"),[bi]:G("color","grey"),[Wn]:G("color","red"),[_i]:G("color","purple"),[Gn]:G("color","orange"),[Si]:G("color","black")},Ci=Kr?n=>{const t=[],e=[],s=F();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(),Pn=n=>({[Symbol.iterator](){return this},next:n}),Ii=(n,t)=>Pn(()=>{let e;do e=n.next();while(!e.done&&!t(e.value));return e}),We=(n,t)=>Pn(()=>{const{done:e,value:s}=n.next();return{done:e,value:e?void 0:t(s)}});class Ge{constructor(t,e){this.clock=t,this.len=e}}class Vt{constructor(){this.clients=new Map}}const qn=(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];ws(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},Zn=(n,t)=>{const e=n.clients.get(t.client);return e!==void 0&&vi(e,t.clock)!==null},Pe=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 Pe(t),t},oe=(n,t,e,s)=>{Y(n.clients,t,()=>[]).push(new Ge(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 Ge(l,c))}}r.length>0&&t.clients.set(s,r)}),t},Dt=(n,t)=>{p(n.restEncoder,t.clients.size),Q(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)}})},qe=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 Ge(n.readDsClock(),n.readDsLen()))}}return t},Qn=(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=j(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},ts=Yn;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=ts(),this.guid=t,this.collectionid=e,this.share=new Map,this.store=new fs,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(Q(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(){Q(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 es{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return w(this.restDecoder)}readDsLen(){return w(this.restDecoder)}}class ns extends es{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 et(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(et(this.restDecoder))}readKey(){return et(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 He(T(t)),this.clientDecoder=new se(T(t)),this.leftClockDecoder=new He(T(t)),this.rightClockDecoder=new He(T(t)),this.infoDecoder=new Vn(T(t),_t),this.stringDecoder=new Gr(T(t)),this.parentInfoDecoder=new Vn(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 ss{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 ss{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){Ke(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 rs{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&&$(),p(this.restEncoder,t-1),this.dsCurrVal+=t}}class dt extends rs{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Je,this.clientEncoder=new ie,this.leftClockEncoder=new Je,this.rightClockEncoder=new Je,this.infoEncoder=new jn(Ke),this.stringEncoder=new di,this.parentInfoEncoder=new jn(Ke),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=j(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)},Ze=(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),Q(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=F(),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 B(b(l,c),d),c+=d;break}case 10:{const d=w(n.restDecoder);o[a]=new N(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,$s(n,h));o[a]=u,c+=u.length}}}}return e},Bi=(n,t,e)=>{const s=[];let r=Q(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 fs,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!==N){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 Ze(f,l,new Map),p(f.restEncoder,0),{missing:c,update:f.toUint8Array()}}return null},Ni=(n,t)=>Ze(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=Qn(s,r,l);if(l.pendingDs){const u=new Et(tt(l.pendingDs));w(u.restDecoder);const f=Qn(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,is(r.doc,u)}},e,!1),is=(n,t,e,s=Et)=>{const r=tt(t);Fi(r,n,e,new s(r))},os=(n,t,e)=>is(n,t,e,ns),Vi=(n,t,e=new Map)=>{Ze(n,t.store,e),Dt(n,Ti(t.store))},Hi=(n,t=new Uint8Array([0]),e=new dt)=>{const s=ls(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},ls=n=>$i(new es(tt(n))),cs=(n,t)=>(p(n.restEncoder,t.size),Q(t.entries()).sort((e,s)=>s[0]-e[0]).forEach(([e,s])=>{p(n.restEncoder,e),p(n.restEncoder,s)}),n),ji=(n,t)=>cs(n,ce(t.store)),Ki=(n,t=new rs)=>(n instanceof Map?cs(t,n):ji(t,n),t.toUint8Array()),zi=n=>Ki(n,new ss);class Yi{constructor(){this.l=[]}}const as=()=>new Yi,hs=(n,t)=>n.l.push(t),us=(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.")},ds=(n,t,e)=>Te(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 $()},$t=(n,t)=>t===void 0?!n.deleted:t.sv.has(n.id.client)&&(t.sv.get(n.id.client)||0)>n.id.clock&&!Zn(t.ds,n.id),tn=(n,t)=>{const e=Y(n.meta,tn,ot),s=n.doc.store;e.has(t)||(t.sv.forEach((r,i)=>{r<M(s,i)&&nt(n,b(i,r))}),qn(n,t.ds,r=>{}),e.add(t))};class fs{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},gs=(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 $()}e.push(t)},j=(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 $()},en=(n,t)=>{const e=n.clients.get(t.client);return e[j(e,t.clock)]},nn=(n,t,e)=>{const s=j(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},nt=(n,t)=>{const e=n.doc.store.clients.get(t.client);return e[nn(n,e,t.clock)]},ps=(n,t,e)=>{const s=t.clients.get(e.client),r=j(s,e.clock),i=s[r];return e.clock!==i.id.clock+i.length-1&&i.constructor!==B&&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[j(s,t.id.clock)]=e},ws=(n,t,e,s,r)=>{if(s===0)return;const i=e+s;let o=nn(n,t,e),l;do l=t[o++],i<l.id.clock+l.length&&nn(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 ms=(n,t)=>t.deleteSet.clients.size===0&&!yr(t.afterState,(e,s)=>t.beforeState.get(s)!==e)?!1:(Pe(t.deleteSet),Ni(n,t),Dt(n,t.deleteSet),!0),ys=(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=j(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=Me(r.length-1,1+j(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)}})},bs=(n,t)=>{if(t<n.length){const e=n[t],s=e.doc,r=s.store,i=e.deleteSet,o=e._mergeStructs;try{Pe(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),ds(a._dEH,c,e))})}),l.push(()=>s.emit("afterTransaction",[e,s])),Te(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(j(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=j(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(Gn,Xn,"[yjs] ",Jn,Wn,"Changed the client-id because another client seems to be using it."),s.clientID=ts()),s.emit("afterTransactionCleanup",[e,s]),s._observers.has("update")){const h=new Ht;ms(h,e)&&s.emit("update",[h.toUint8Array(),e.origin,s,e])}if(s._observers.has("updateV2")){const h=new dt;ms(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])):bs(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&&bs(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 N(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,$s(n,l));yield a,i+=a.length}else{const c=n.readLen();yield new B(b(r,i),c),i+=c}}}}class sn{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===N);return this.curr}}class rn{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const Zi=n=>he(n,ns,Ht),Qi=(n,t)=>{if(n.constructor===B){const{client:e,clock:s}=n.id;return new B(b(e,s+t),n.length-t)}else if(n.constructor===N){const{client:e,clock:s}=n.id;return new N(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(tt(h)));let r=s.map(h=>new sn(h,!0)),i=null;const o=new e,l=new rn(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===N?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)st(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===N)i.struct.length=u.id.clock+u.length-i.struct.id.clock;else{st(l,i.struct,i.offset);const g=u.id.clock-i.struct.id.clock-i.struct.length;i={struct:new N(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===N?i.struct.length-=g:u=Qi(u,g)),i.struct.mergeWith(u)||(st(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!==N;u=h.next())st(l,i.struct,i.offset),i={struct:u,offset:0}}i!==null&&(st(l,i.struct,i.offset),i=null),on(l);const c=s.map(h=>qe(h)),a=Mi(c);return Dt(o,a),o.toUint8Array()},to=(n,t,e=Et,s=dt)=>{const r=ls(t),i=new s,o=new rn(i),l=new e(tt(n)),c=new sn(l,!1);for(;c.curr;){const h=c.curr,d=h.id.client,u=r.get(d)||0;if(c.curr.constructor===N){c.next();continue}if(h.id.clock+h.length>u)for(st(o,h,lt(u-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===d;)st(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()}on(o);const a=qe(l);return Dt(i,a),i.toUint8Array()},ks=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:D(n.encoder.restEncoder)}),n.encoder.restEncoder=U(),n.written=0)},st=(n,t,e)=>{n.written>0&&n.currClient!==t.id.client&&ks(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++},on=n=>{ks(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(tt(n)),i=new sn(r,!1),o=new s,l=new rn(o);for(let a=i.curr;a!==null;a=i.next())st(l,t(a),0);on(l);const c=qe(r);return Dt(o,c),o.toUint8Array()},no=n=>eo(n,Vr,Et,Ht),_s="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 Zn(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw W(_s);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=ve(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=ve(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(i))o="delete",l=ve(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(_s);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},Ss=80;let ln=0;class ro{constructor(t,e){t.marker=!0,this.p=t,this.index=e,this.timestamp=ln++}}const io=n=>{n.timestamp=ln++},Ds=(n,t,e)=>{n.p.marker=!1,n.p=t,t.marker=!0,n.index=e,n.timestamp=ln++},oo=(n,t,e)=>{if(n.length>=Ss){const s=n.reduce((r,i)=>r.timestamp<i.timestamp?r:i);return Ds(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/Ss?(Ds(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;ds(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=as(),this._dEH=as(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,e){this.doc=t,this._item=e}_copy(){throw H()}clone(){throw H()}_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){hs(this._eH,t)}observeDeep(t){hs(this._dEH,t)}unobserve(t){us(this._eH,t)}unobserveDeep(t){us(this._dEH,t)}toJSON(){}}const Es=(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},Cs=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}},As=(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}}}},Ls=(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()},Is=()=>W("Length exceeded!"),vs=(n,t,e,s)=>{if(e>t._length)throw Is();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&&nt(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)},Ms=(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&&nt(n,b(l.id.client,l.id.clock+e)),e-=l.length);for(;s>0&&l!==null;)l.deleted||(s<l.length&&nt(n,b(l.id.client,l.id.clock+s)),l.delete(n),s-=l.length),l=l.right;if(s>0)throw Is();t._searchMarker&&jt(t._searchMarker,r,-i+s)},pe=(n,t,e)=>{const s=t._map.get(e);s!==void 0&&s.delete(n)},cn=(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)},an=(n,t)=>{const e=n._map.get(t);return e!==void 0&&!e.deleted?e.content.getContent()[e.length-1]:void 0},xs=n=>{const t={};return n._map.forEach((e,s)=>{e.deleted||(t[s]=e.content.getContent()[e.length-1])}),t},Ts=(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=>{vs(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=>{Ms(s,this,t,e)}):this._prelimContent.splice(t,e)}get(t){return Ls(this,t)}toArray(){return Cs(this)}slice(t=0,e=this.length){return Es(this,t,e)}toJSON(){return this.map(t=>t instanceof x?t.toJSON():t)}map(t){return As(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 We(we(this._map),t=>t[0])}values(){return We(we(this._map),t=>t[1].content.getContent()[t[1].length-1])}entries(){return We(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=>{cn(s,this,t,e)}):this._prelimContent.set(t,e),e}get(t){return an(this,t)}has(t){return Ts(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,rt=(n,t)=>n===t||typeof n=="object"&&typeof t=="object"&&n&&t&&Fr(n,t);class hn{constructor(t,e,s,r){this.left=t,this.right=e,this.index=s,this.currentAttributes=r}forward(){switch(this.right===null&&$(),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 Us=(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&&nt(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 hn(r.p.left,r.p,r.index,s);return Us(n,i,e-r.index)}else{const i=new hn(null,t._start,0,s);return Us(n,i,e)}},Os=(n,t,e,s)=>{for(;e.right!==null&&(e.right.deleted===!0||e.right.content.constructor===A&&rt(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)},Rs=(n,t)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===A&&rt(t[n.right.content.key]||null,n.right.content.value)))break;n.forward()}},Bs=(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(!rt(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},un=(n,t,e,s,r)=>{e.currentAttributes.forEach((u,f)=>{r[f]===void 0&&(r[f]=null)});const i=n.doc,o=i.clientID;Rs(e,r);const l=Bs(n,t,e,r),c=s.constructor===String?new K(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(),Os(n,t,e,l)},Ns=(n,t,e,s,r)=>{const i=n.doc,o=i.clientID;Rs(e,r);const l=Bs(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(rt(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&&nt(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 K(c)),e.right.integrate(n,0),e.forward()}Os(n,t,e,l)},Fs=(n,t,e,s,r)=>{let i=t;const o=F();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=F();const o=Ie(i);for(;r;){if(r.deleted===!1)switch(r.content.constructor){case A:Lt(o,r.content);break;default:t+=Fs(e,s,r,i,o),i=Ie(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&&ws(n,e.store.clients.get(s),i,r,o=>{!o.deleted&&o.content.constructor===A&&o.constructor!==B&&t.add(o.parent)})}_(e,s=>{qn(n,n.deleteSet,r=>{if(r instanceof B||!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)})},Vs=(n,t,e)=>{const s=e,r=Ie(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 K:e<t.right.length&&nt(n,b(t.right.id.client,t.right.id.clock+e)),e-=t.right.length,t.right.delete(n);break}t.forward()}i&&Fs(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 K: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;rt(m,g)?g!==null&&o.delete(s):(l==="retain"&&u(),rt(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;rt(m,g)||(l==="retain"&&u(),c[f]=m)}else if(!o.deleted){i.set(f,g);const m=c[f];m!==void 0&&(rt(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===K&&(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 hn(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)&&un(s,this,r,l,o.attributes||{})}else o.retain!==void 0?Ns(s,this,r,o.retain,o.attributes||{}):o.delete!==void 0&&Vs(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 K:{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&&tn(d,t),e&&tn(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})),un(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);un(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=>{Vs(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&&Ns(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=>{cn(s,this,t,e)}):this._pending.push(()=>this.setAttribute(t,e))}getAttribute(t){return an(this,t)}getAttributes(){return xs(this)}_write(t){t.writeTypeRef(Bo)}}const yo=n=>new It;class dn{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 dn(this,t)}querySelector(t){t=t.toUpperCase();const s=new dn(this,r=>r.nodeName&&r.nodeName.toUpperCase()===t).next();return s.done?null:s.value}querySelectorAll(t){return t=t.toUpperCase(),Q(new dn(this,e=>e.nodeName&&e.nodeName.toUpperCase()===t))}_callObserver(t,e){fe(this,t,new _o(this,e,t))}toString(){return As(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=>{vs(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=>{Ms(s,this,t,e)}):this._prelimContent.splice(t,e)}toArray(){return Cs(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Ls(this,t)}slice(t=0,e=this.length){return Es(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=>{cn(s,this,t,e)}):this._prelimAttrs.set(t,e)}getAttribute(t){return an(this,t)}hasAttribute(t){return Ts(this,t)}getAttributes(){return xs(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 fn{constructor(t,e){this.id=t,this.length=e}get deleted(){throw H()}mergeWith(t){return!1}write(t,e,s){throw H()}integrate(t,e){throw H()}}const Eo=0;class B extends fn{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),gs(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 H()}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()),Hs=(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(Hs(this.doc.guid,this.opts))}splice(t){throw H()}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(Hs(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 H()}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 H()}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 K{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new K(this.str)}splice(t){const e=new K(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 K(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 H()}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 fn{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()?Rn:0}set marker(t){(this.info&Be)>0!==t&&(this.info^=Be)}get marker(){return(this.info&Be)>0}get keep(){return(this.info&On)>0}set keep(t){this.keep!==t&&(this.info^=On)}get countable(){return(this.info&Rn)>0}get deleted(){return(this.info&Re)>0}set deleted(t){this.deleted!==t&&(this.info^=Re)}markDeleted(){this.info|=Re}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=ps(t,e,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=nt(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===B||this.right&&this.right.constructor===B)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=en(e,this.parent);s.constructor===B?this.parent=null:this.parent=s.content.type}return null}integrate(t,e){if(e>0&&(this.id.clock+=e,this.left=ps(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(en(t.doc.store,r.origin)))i.has(en(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),gs(t.doc.store,this),this.content.integrate(t,this),ys(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new B(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),ys(t,e,this.parentSub),this.content.delete(t)}}gc(t,e){if(!this.deleted)throw $();this.content.gc(t),e?Ji(t,this,new B(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)):$();i!==null&&t.writeString(i)}this.content.write(t,e)}}const $s=(n,t)=>jo[t&ee](n),jo=[()=>{$()},Ao,Mo,Co,To,Io,vo,$o,xo,Lo,()=>{$()}],Ko=10;class N extends fn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){$()}write(t,e){t.writeInfo(Ko),p(t.restEncoder,this.length-e)}getMissing(t,e){return null}}const js=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Ks="__ $YJS$ __";js[Ks]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),js[Ks]=!0;const zs=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){Mn.setItem(this.room,ei(Pr(t)))}close(){xr(this._onChange)}}const Yo=typeof BroadcastChannel>"u"?zo:BroadcastChannel,gn=n=>Y(zs,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)=>(gn(n).subs.add(t),t),Jo=(n,t)=>{const e=gn(n),s=e.subs.delete(t);return s&&e.subs.size===0&&(e.bc.close(),zs.delete(n)),s},vt=(n,t,e=null)=>{const s=gn(n);s.bc.postMessage(t),s.subs.forEach(r=>r(t,e))},Ys=0,pn=1,Xs=2,wn=(n,t)=>{p(n,Ys);const e=zi(t);C(n,e)},Js=(n,t,e)=>{p(n,pn),C(n,Qe(t,e))},Wo=(n,t,e)=>Js(t,e,T(n)),Ws=(n,t,e)=>{try{os(t,T(n),e)}catch(s){console.error("Caught error while handling a Yjs update",s)}},Go=(n,t)=>{p(n,Xs),C(n,t)},Po=Ws,qo=(n,t,e,s)=>{const r=w(n);switch(r){case Ys:Wo(n,t,e);break;case pn:Ws(n,e,s);break;case Xs: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,et(n))}},mn=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&&mn/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const s=[];this.meta.forEach((r,i)=>{i!==this.clientID&&mn<=e-r.lastUpdated&&this.states.has(i)&&s.push(i)}),s.length>0&&yn(this,s,"timeout")},X(mn/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 yn=(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=tt(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(et(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,Gs=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===pn&&!e.synced&&(e.synced=!0)},Gt[Gs]=(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 Ps=3e4;function ol(n,t){console.warn(`Permission denied to access ${n.url}.
4
- ${t}`)}function qs(n,t,e){const s=tt(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 Zs(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=qs(n,new Uint8Array(e.data),!0);je(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,yn(n.awareness,Array.from(n.awareness.getStates().keys()).filter(s=>s!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Zs,Me(_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),wn(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 bn(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),wn(u,s),this.ws.send(D(u))}},c)),this._bcSubscriber=(u,f)=>{if(f!==this){const g=qs(this,new Uint8Array(u),!1);je(g)>1&&vt(this.bcChannel,D(g),this)}},this._updateHandler=(u,f)=>{if(f!==this){const g=U();p(g,mt),Go(g,u),bn(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),Z=U();p(Z,Mt),C(Z,Wt(i,E)),bn(this,D(Z))},this._unloadHandler=()=>{yn(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&&Ps<ht()-this.wsLastMessageReceived&&(il(this.ws!==null,"ws must not be null"),this.ws.close())},Ps/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),wn(t,this.doc),vt(this.bcChannel,D(t),this);const e=U();p(e,mt),Js(e,this.doc),vt(this.bcChannel,D(e),this);const s=U();p(s,Gs),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)),bn(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&&(Zs(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 Qs(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={}){Qs(t,"host","string"),Qs(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 Le(this,bt)=="function"?Le(this,bt).call(this):Le(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))},tr=(n,t)=>yt(n.count(t)),gl=(n,t)=>yt(n.get(t)),er=(n,t)=>yt(n.delete(t)),pl=(n,t,e)=>yt(n.put(t,e)),kn=(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),_n="custom",nr="updates",sr=500,rr=(n,t=()=>{},e=()=>{})=>{const[s]=Pt(n.db,[nr]);return wl(s,Dl(n._dbref,!1)).then(r=>{n._destroyed||(t(s),_(n.doc,()=>{r.forEach(i=>os(n.doc,i))},n,!1),e(s))}).then(()=>yl(s).then(r=>{n._dbref=r+1})).then(()=>tr(s).then(r=>{n._dbsize=r})).then(()=>s)},El=(n,t=!0)=>rr(n).then(e=>{(t||n._dbsize>=sr)&&kn(e,Qe(n.doc)).then(()=>er(e,Sl(n._dbref,!0))).then(()=>tr(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,rr(this,o=>kn(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,[nr]);kn(i,s),++this._dbsize>=sr&&(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,[_n],"readonly");return gl(s,t)})}set(t,e){return this._db.then(s=>{const[r]=Pt(s,[_n]);return pl(r,e,t)})}del(t){return this._db.then(e=>{const[s]=Pt(e,[_n]);return er(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 ir=`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(_,k){typeof exports=="object"&&typeof module<"u"?k(exports):typeof define=="function"&&define.amd?define(["exports"],k):(_=typeof globalThis<"u"?globalThis:_||self,k(_.playhtml={}))})(this,function(_){var bt,wr;"use strict";var nl=Object.defineProperty;var sl=(_,k,L)=>k in _?nl(_,k,{enumerable:!0,configurable:!0,writable:!0,value:L}):_[k]=L;var y=(_,k,L)=>(sl(_,typeof k!="symbol"?k+"":k,L),L),mr=(_,k,L)=>{if(!k.has(_))throw TypeError("Cannot "+L)};var Me=(_,k,L)=>(mr(_,k,"read from private field"),L?L.call(_):k.get(_)),yr=(_,k,L)=>{if(k.has(_))throw TypeError("Cannot add the same private member more than once");k instanceof WeakSet?k.add(_):k.set(_,L)},br=(_,k,L,xt)=>(mr(_,k,"write to private field"),xt?xt.call(_,L):k.set(_,L),L);var k=1e6,L="y-pk-batch",xt=!1,kr=(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(In({id:e,type:"start",size:n.byteLength,count:s}));let r=0,i=0;for(let o=0;o<s;o++){const c=n.slice(k*o,k*(o+1));t(c),i+=1,r+=c.byteLength}t(In({id:e,type:"end",size:r,count:i}))};function In(n){return`${L}#${JSON.stringify(n)}`}const F=()=>new Map,ve=n=>{const t=F();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},Sr=(n,t)=>{const e=[];for(const[s,r]of n)e.push(t(r,s));return e},_r=(n,t)=>{for(const[e,s]of n)if(t(s,e))return!0;return!1},ot=()=>new Set,xe=n=>n[n.length-1],Dr=(n,t)=>{for(let e=0;e<t.length;e++)n.push(t[e])},Q=Array.from,Er=Array.isArray;class Qt{constructor(){this._observers=F()}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 Q((this._observers.get(t)||F()).values()).forEach(s=>s(...e))}destroy(){this._observers=F()}}const J=Math.floor,te=Math.abs,Ue=(n,t)=>n<t?n:t,ct=(n,t)=>n>t?n:t,Cr=Math.pow,Ln=n=>n!==0?n<0:1/n<0,Ar=String.fromCharCode,Ir=n=>n.toLowerCase(),Lr=/^\s*/g,Mr=n=>n.replace(Lr,""),vr=/([A-Z])/g,Mn=(n,t)=>Mr(n.replace(vr,e=>`${t}${Ir(e)}`)),xr=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},Ut=typeof TextEncoder<"u"?new TextEncoder:null,Ur=Ut?n=>Ut.encode(n):xr;let Tt=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Tt&&Tt.decode(new Uint8Array).length===1&&(Tt=null);const vn=n=>n===void 0?null:n;class Tr{constructor(){this.map=new Map}setItem(t,e){this.map.set(t,e)}getItem(t){return this.map.get(t)}}let xn=new Tr,Te=!0;try{typeof localStorage<"u"&&(xn=localStorage,Te=!1)}catch{}const Un=xn,Or=n=>Te||addEventListener("storage",n),Rr=n=>Te||removeEventListener("storage",n),Nr=Object.assign,Br=Object.keys,Fr=(n,t)=>{for(const e in n)t(n[e],e)},Hr=(n,t)=>{const e=[];for(const s in n)e.push(t(n[s],s));return e},ee=n=>Br(n).length,Vr=n=>{for(const t in n)return!1;return!0},$r=(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),jr=(n,t)=>n===t||ee(n)===ee(t)&&$r(n,(e,s)=>(e!==void 0||Tn(t,s))&&t[s]===e),Oe=(n,t,e=0)=>{try{for(;e<n.length;e++)n[e](...t)}finally{e<n.length&&Oe(n,t,e+1)}},Kr=n=>n,zr=(n,t)=>n===t,Ot=(n,t)=>{if(n==null||t==null)return zr(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(ee(n)!==ee(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},Yr=(n,t)=>t.includes(n),kt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name),On=typeof window<"u"&&typeof document<"u"&&!kt;let H;const Jr=()=>{if(H===void 0)if(kt){H=F();const n=process.argv;let t=null;for(let e=0;e<n.length;e++){const s=n[e];s[0]==="-"?(t!==null&&H.set(t,""),t=s):t!==null&&(H.set(t,s),t=null)}t!==null&&H.set(t,"")}else typeof location=="object"?(H=F(),(location.search||"?").slice(1).split("&").forEach(n=>{if(n.length!==0){const[t,e]=n.split("=");H.set(`--${Mn(t,"-")}`,e),H.set(`-${Mn(t,"-")}`,e)}})):H=F();return H},Re=n=>Jr().has(n),Ne=n=>vn(kt?process.env[n.toUpperCase()]:Un.getItem(n));(n=>Re("--"+n)||Ne(n)!==null)("production");const Rn=kt&&Yr(process.env.FORCE_COLOR,["true","1","2"]),Xr=!Re("no-colors")&&(!kt||process.stdout.isTTY||Rn)&&(!kt||Re("color")||Rn||Ne("COLORTERM")!==null||(Ne("TERM")||"").includes("color")),Nn=1,Bn=2,Be=4,Fe=8,Rt=32,X=64,O=128,ne=31,He=63,lt=127,Wr=2147483647,Fn=Number.MAX_SAFE_INTEGER,Gr=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&J(n)===n),W=n=>new Error(n),V=()=>{throw W("Method unimplemented")},$=()=>{throw W("Unexpected case")},Hn=W("Unexpected end of array"),Vn=W("Integer out of Range");class se{constructor(t){this.arr=t,this.pos=0}}const tt=n=>new se(n),Pr=n=>n.pos!==n.arr.length,qr=(n,t)=>{const e=Ke(n.arr.buffer,n.pos+n.arr.byteOffset,t);return n.pos+=t,e},U=n=>qr(n,w(n)),St=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&lt)*e,e*=128,r<O)return t;if(t>Fn)throw Vn}throw Hn},Ve=n=>{let t=n.arr[n.pos++],e=t&He,s=64;const r=(t&X)>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&lt)*s,s*=128,t<O)return r*e;if(e>Fn)throw Vn}throw Hn},et=Tt?n=>Tt.decode(U(n)):n=>{let t=w(n);if(t===0)return"";{let e=String.fromCodePoint(St(n));if(--t<100)for(;t--;)e+=String.fromCodePoint(St(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))}},$e=(n,t)=>{const e=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,t);return n.pos+=t,e},Zr=[n=>{},n=>null,Ve,n=>$e(n,4).getFloat32(0,!1),n=>$e(n,8).getFloat64(0,!1),n=>$e(n,8).getBigInt64(0,!1),n=>!1,n=>!0,et,n=>{const t=w(n),e={};for(let s=0;s<t;s++){const r=et(n);e[r]=Nt(n)}return e},n=>{const t=w(n),e=[];for(let s=0;s<t;s++)e.push(Nt(n));return e},U],Nt=n=>Zr[127-St(n)](n);class $n extends se{constructor(t,e){super(t),this.reader=e,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Pr(this)?this.count=w(this)+1:this.count=-1),this.count--,this.s}}class re extends se{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Ve(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 je extends se{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=Ve(this),e=t&1;this.diff=J(t/2),this.count=1,e&&(this.count=w(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Qr{constructor(t){this.decoder=new re(t),this.str=et(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 jn=n=>new Uint8Array(n),Ke=(n,t,e)=>new Uint8Array(n,t,e),ti=n=>new Uint8Array(n),ei=n=>{let t="";for(let e=0;e<n.byteLength;e++)t+=Ar(n[e]);return btoa(t)},ni=n=>Buffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),si=n=>{const t=atob(n),e=jn(t.length);for(let s=0;s<t.length;s++)e[s]=t.charCodeAt(s);return e},ri=n=>{const t=Buffer.from(n,"base64");return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)},ii=On?ei:ni,oi=On?si:ri,ci=n=>{const t=jn(n.byteLength);return t.set(n),t};class Bt{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const T=()=>new Bt,ze=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(ze(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(Ke(n.cbuf.buffer,0,n.cpos),e),t},li=(n,t)=>{const e=n.cbuf.length;e-n.cpos<t&&(n.bufs.push(Ke(n.cbuf.buffer,0,n.cpos)),n.cbuf=new Uint8Array(ct(e,t)*2),n.cpos=0)},M=(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},Ye=M,p=(n,t)=>{for(;t>lt;)M(n,O|lt&t),t=J(t/128);M(n,lt&t)},Je=(n,t)=>{const e=Ln(t);for(e&&(t=-t),M(n,(t>He?O:0)|(e?X:0)|He&t),t=J(t/64);t>0;)M(n,(t>lt?O:0)|lt&t),t=J(t/128)},Xe=new Uint8Array(3e4),ai=Xe.length/3,hi=(n,t)=>{if(t.length<ai){const e=Ut.encodeInto(t,Xe).written||0;p(n,e);for(let s=0;s<e;s++)M(n,Xe[s])}else C(n,Ur(t))},ui=(n,t)=>{const e=unescape(encodeURIComponent(t)),s=e.length;p(n,s);for(let r=0;r<s;r++)M(n,e.codePointAt(r))},at=Ut&&Ut.encodeInto?hi:ui,ie=(n,t)=>{const e=n.cbuf.length,s=n.cpos,r=Ue(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(ct(e*2,i)),n.cbuf.set(t.subarray(r)),n.cpos=i)},C=(n,t)=>{p(n,t.byteLength),ie(n,t)},We=(n,t)=>{li(n,t);const e=new DataView(n.cbuf.buffer,n.cpos,t);return n.cpos+=t,e},di=(n,t)=>We(n,4).setFloat32(0,t,!1),fi=(n,t)=>We(n,8).setFloat64(0,t,!1),gi=(n,t)=>We(n,8).setBigInt64(0,t,!1),Kn=new DataView(new ArrayBuffer(4)),pi=n=>(Kn.setFloat32(0,n),Kn.getFloat32(0)===n),Ft=(n,t)=>{switch(typeof t){case"string":M(n,119),at(n,t);break;case"number":Gr(t)&&te(t)<=Wr?(M(n,125),Je(n,t)):pi(t)?(M(n,124),di(n,t)):(M(n,123),fi(n,t));break;case"bigint":M(n,122),gi(n,t);break;case"object":if(t===null)M(n,126);else if(Er(t)){M(n,117),p(n,t.length);for(let e=0;e<t.length;e++)Ft(n,t[e])}else if(t instanceof Uint8Array)M(n,116),C(n,t);else{M(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":M(n,t?120:121);break;default:M(n,127)}};class zn extends Bt{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 Yn=n=>{n.count>0&&(Je(n.encoder,n.count===1?n.s:-n.s),n.count>1&&p(n.encoder,n.count-2))};class oe{constructor(){this.encoder=new Bt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(Yn(this),this.count=1,this.s=t)}toUint8Array(){return Yn(this),D(this.encoder)}}const Jn=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 Ge{constructor(){this.encoder=new Bt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(Jn(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return Jn(this),D(this.encoder)}}class wi{constructor(){this.sarr=[],this.s="",this.lensE=new oe}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 Bt;return this.sarr.push(this.s),this.s="",at(t,this.sarr.join("")),ie(t,this.lensE.toUint8Array()),D(t)}}const mi=crypto.getRandomValues.bind(crypto),Xn=()=>mi(new Uint32Array(1))[0],yi=[1e7]+-1e3+-4e3+-8e3+-1e11,bi=()=>yi.replace(/[018]/g,n=>(n^Xn()&15>>n/4).toString(16)),ht=Date.now,_t=n=>new Promise(n);Promise.all.bind(Promise);class ki{constructor(t,e){this.left=t,this.right=e}}const G=(n,t)=>new ki(n,t);typeof DOMParser<"u"&&new DOMParser;const Si=n=>Sr(n,(t,e)=>`${e}:${t};`).join(""),P=Symbol,Wn=P(),Gn=P(),_i=P(),Di=P(),Ei=P(),Pn=P(),Ci=P(),qn=P(),Ai=P(),Ii=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},Li={[Wn]:G("font-weight","bold"),[Gn]:G("font-weight","normal"),[_i]:G("color","blue"),[Ei]:G("color","green"),[Di]:G("color","grey"),[Pn]:G("color","red"),[Ci]:G("color","purple"),[qn]:G("color","orange"),[Ai]:G("color","black")},Mi=Xr?n=>{const t=[],e=[],s=F();let r=[],i=0;for(;i<n.length;i++){const o=n[i],c=Li[o];if(c!==void 0)s.set(c.left,c.right);else if(o.constructor===String||o.constructor===Number){const l=Si(s);i>0||l.length>0?(t.push("%c"+o),e.push(l)):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}:Ii,vi=(...n)=>{console.log(...Mi(n)),xi.forEach(t=>t.print(n))},xi=ot(),Zn=n=>({[Symbol.iterator](){return this},next:n}),Ui=(n,t)=>Zn(()=>{let e;do e=n.next();while(!e.done&&!t(e.value));return e}),Pe=(n,t)=>Zn(()=>{const{done:e,value:s}=n.next();return{done:e,value:e?void 0:t(s)}});class qe{constructor(t,e){this.clock=t,this.len=e}}class Ht{constructor(){this.clients=new Map}}const Qn=(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 c=s[o];ys(n,i,c.clock,c.len,e)}}),Ti=(n,t)=>{let e=0,s=n.length-1;for(;e<=s;){const r=J((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},ts=(n,t)=>{const e=n.clients.get(t.client);return e!==void 0&&Ti(e,t.clock)!==null},Ze=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=ct(r.len,i.clock+i.len-r.clock):(s<e&&(t[s]=i),s++)}t.length=s})},Oi=n=>{const t=new Ht;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++)Dr(i,n[o].clients.get(r)||[]);t.clients.set(r,i)}});return Ze(t),t},ce=(n,t,e,s)=>{Y(n.clients,t,()=>[]).push(new qe(e,s))},Ri=()=>new Ht,Ni=n=>{const t=Ri();return n.clients.forEach((e,s)=>{const r=[];for(let i=0;i<e.length;i++){const o=e[i];if(o.deleted){const c=o.id.clock;let l=o.length;if(i+1<e.length)for(let a=e[i+1];i+1<e.length&&a.deleted;a=e[++i+1])l+=a.length;r.push(new qe(c,l))}}r.length>0&&t.clients.set(s,r)}),t},Dt=(n,t)=>{p(n.restEncoder,t.clients.size),Q(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)}})},Qe=n=>{const t=new Ht,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 c=0;c<i;c++)o.push(new qe(n.readDsClock(),n.readDsLen()))}}return t},es=(n,t,e)=>{const s=new Ht,r=w(n.restDecoder);for(let i=0;i<r;i++){n.resetDsCurVal();const o=w(n.restDecoder),c=w(n.restDecoder),l=e.clients.get(o)||[],a=v(e,o);for(let h=0;h<c;h++){const d=n.readDsClock(),u=d+n.readDsLen();if(d<a){a<u&&ce(s,o,a,u-a);let f=j(l,d),g=l[f];for(!g.deleted&&g.id.clock<d&&(l.splice(f+1,0,_e(t,g,d-g.id.clock)),f++);f<l.length&&(g=l[f++],g.id.clock<u);)g.deleted||(u<g.id.clock+g.length&&l.splice(f,0,_e(t,g,u-g.id.clock)),g.delete(t))}else ce(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},ns=Xn;class ut extends Qt{constructor({guid:t=bi(),collectionid:e=null,gc:s=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:o=!1,shouldLoad:c=!0}={}){super(),this.gc=s,this.gcFilter=r,this.clientID=ns(),this.guid=t,this.collectionid=e,this.share=new Map,this.store=new ps,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=o,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.whenLoaded=_t(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const l=()=>_t(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=l()),this.isSynced=a===void 0||a===!0,this.isLoaded||this.emit("load",[])}),this.whenSynced=l()}load(){const t=this._item;t!==null&&!this.shouldLoad&&S(t.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Q(this.subdocs).map(t=>t.guid))}transact(t,e=null){return S(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,Lt)}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(){Q(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,S(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 ss{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return w(this.restDecoder)}readDsLen(){return w(this.restDecoder)}}class rs extends ss{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 St(this.restDecoder)}readString(){return et(this.restDecoder)}readParentInfo(){return w(this.restDecoder)===1}readTypeRef(){return w(this.restDecoder)}readLen(){return w(this.restDecoder)}readAny(){return Nt(this.restDecoder)}readBuf(){return ci(U(this.restDecoder))}readJSON(){return JSON.parse(et(this.restDecoder))}readKey(){return et(this.restDecoder)}}class Bi{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 Bi{constructor(t){super(t),this.keys=[],w(t),this.keyClockDecoder=new je(U(t)),this.clientDecoder=new re(U(t)),this.leftClockDecoder=new je(U(t)),this.rightClockDecoder=new je(U(t)),this.infoDecoder=new $n(U(t),St),this.stringDecoder=new Qr(U(t)),this.parentInfoDecoder=new $n(U(t),St),this.typeRefDecoder=new re(U(t)),this.lenDecoder=new re(U(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 Nt(this.restDecoder)}readBuf(){return U(this.restDecoder)}readJSON(){return Nt(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 is{constructor(){this.restEncoder=T()}toUint8Array(){return D(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){p(this.restEncoder,t)}writeDsLen(t){p(this.restEncoder,t)}}class Vt extends is{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){Ye(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 os{constructor(){this.restEncoder=T(),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&&$(),p(this.restEncoder,t-1),this.dsCurrVal+=t}}class dt extends os{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Ge,this.clientEncoder=new oe,this.leftClockEncoder=new Ge,this.rightClockEncoder=new Ge,this.infoEncoder=new zn(Ye),this.stringEncoder=new wi,this.parentInfoEncoder=new zn(Ye),this.typeRefEncoder=new oe,this.lenEncoder=new oe}toUint8Array(){const t=T();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()),ie(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 Fi=(n,t,e,s)=>{s=ct(s,t[0].id.clock);const r=j(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)},tn=(n,t,e)=>{const s=new Map;e.forEach((r,i)=>{v(t,i)>r&&s.set(i,r)}),ae(t).forEach((r,i)=>{e.has(i)||s.set(i,0)}),p(n.restEncoder,s.size),Q(s.entries()).sort((r,i)=>i[0]-r[0]).forEach(([r,i])=>{Fi(n,t.clients.get(r),r,i)})},Hi=(n,t)=>{const e=F(),s=w(n.restDecoder);for(let r=0;r<s;r++){const i=w(n.restDecoder),o=new Array(i),c=n.readClient();let l=w(n.restDecoder);e.set(c,{i:0,refs:o});for(let a=0;a<i;a++){const h=n.readInfo();switch(ne&h){case 0:{const d=n.readLen();o[a]=new N(b(c,l),d),l+=d;break}case 10:{const d=w(n.restDecoder);o[a]=new B(b(c,l),d),l+=d;break}default:{const d=(h&(X|O))===0,u=new I(b(c,l),null,(h&O)===O?n.readLeftID():null,null,(h&X)===X?n.readRightID():null,d?n.readParentInfo()?t.get(n.readString()):n.readLeftID():null,d&&(h&Rt)===Rt?n.readString():null,Ks(n,h));o[a]=u,l+=u.length}}}}return e},Vi=(n,t,e)=>{const s=[];let r=Q(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 c=new ps,l=new Map,a=(f,g)=>{const m=l.get(f);(m==null||m>g)&&l.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--,c.clients.set(g,m.refs.slice(m.i)),e.delete(g),m.i=0,m.refs=[]):c.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,()=>v(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,v(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(c.clients.size>0){const f=new dt;return tn(f,c,new Map),p(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},$i=(n,t)=>tn(n,t.doc.store,t.beforeState),ji=(n,t,e,s=new Et(n))=>S(t,r=>{r.local=!1;let i=!1;const o=r.doc,c=o.store,l=Hi(s,o),a=Vi(r,c,l),h=c.pendingStructs;if(h){for(const[u,f]of h.missing)if(f<v(c,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=ue([h.update,a.update])}}else c.pendingStructs=a;const d=es(s,r,c);if(c.pendingDs){const u=new Et(tt(c.pendingDs));w(u.restDecoder);const f=es(u,r,c);d&&f?c.pendingDs=ue([d,f]):c.pendingDs=d||f}else c.pendingDs=d;if(i){const u=c.pendingStructs.update;c.pendingStructs=null,cs(r.doc,u)}},e,!1),cs=(n,t,e,s=Et)=>{const r=tt(t);ji(r,n,e,new s(r))},ls=(n,t,e)=>cs(n,t,e,rs),Ki=(n,t,e=new Map)=>{tn(n,t.store,e),Dt(n,Ni(t.store))},zi=(n,t=new Uint8Array([0]),e=new dt)=>{const s=as(t);Ki(e,n,s);const r=[e.toUint8Array()];if(n.store.pendingDs&&r.push(n.store.pendingDs),n.store.pendingStructs&&r.push(ro(n.store.pendingStructs.update,t)),r.length>1){if(e.constructor===Vt)return no(r.map((i,o)=>o===0?i:oo(i)));if(e.constructor===dt)return ue(r)}return r[0]},en=(n,t)=>zi(n,t,new Vt),Yi=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},as=n=>Yi(new ss(tt(n))),hs=(n,t)=>(p(n.restEncoder,t.size),Q(t.entries()).sort((e,s)=>s[0]-e[0]).forEach(([e,s])=>{p(n.restEncoder,e),p(n.restEncoder,s)}),n),Ji=(n,t)=>hs(n,ae(t.store)),Xi=(n,t=new os)=>(n instanceof Map?hs(t,n):Ji(t,n),t.toUint8Array()),Wi=n=>Xi(n,new is);class Gi{constructor(){this.l=[]}}const us=()=>new Gi,ds=(n,t)=>n.l.push(t),fs=(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.")},gs=(n,t,e)=>Oe(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),Pi=n=>{for(const[t,e]of n.doc.share.entries())if(e===n)return t;throw $()},$t=(n,t)=>t===void 0?!n.deleted:t.sv.has(n.id.client)&&(t.sv.get(n.id.client)||0)>n.id.clock&&!ts(t.ds,n.id),nn=(n,t)=>{const e=Y(n.meta,nn,ot),s=n.doc.store;e.has(t)||(t.sv.forEach((r,i)=>{r<v(s,i)&&nt(n,b(i,r))}),Qn(n,t.ds,r=>{}),e.add(t))};class ps{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const ae=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},v=(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},ws=(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 $()}e.push(t)},j=(n,t)=>{let e=0,s=n.length-1,r=n[s],i=r.id.clock;if(i===t)return s;let o=J(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=J((e+s)/2)}throw $()},sn=(n,t)=>{const e=n.clients.get(t.client);return e[j(e,t.clock)]},rn=(n,t,e)=>{const s=j(t,e),r=t[s];return r.id.clock<e&&r instanceof I?(t.splice(s+1,0,_e(n,r,e-r.id.clock)),s+1):s},nt=(n,t)=>{const e=n.doc.store.clients.get(t.client);return e[rn(n,e,t.clock)]},ms=(n,t,e)=>{const s=t.clients.get(e.client),r=j(s,e.clock),i=s[r];return e.clock!==i.id.clock+i.length-1&&i.constructor!==N&&s.splice(r+1,0,_e(n,i,e.clock-i.id.clock+1)),i},qi=(n,t,e)=>{const s=n.clients.get(t.id.client);s[j(s,t.id.clock)]=e},ys=(n,t,e,s,r)=>{if(s===0)return;const i=e+s;let o=rn(n,t,e),c;do c=t[o++],i<c.id.clock+c.length&&rn(n,t,i),r(c);while(o<t.length&&t[o].id.clock<i)};class Zi{constructor(t,e,s){this.doc=t,this.deleteSet=new Ht,this.beforeState=ae(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 bs=(n,t)=>t.deleteSet.clients.size===0&&!_r(t.afterState,(e,s)=>t.beforeState.get(s)!==e)?!1:(Ze(t.deleteSet),$i(n,t),Dt(n,t.deleteSet),!0),ks=(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)},he=(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 I&&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},Qi=(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 c=r[o],l=c.clock+c.len;for(let a=j(i,c.clock),h=i[a];a<i.length&&h.id.clock<l;h=i[++a]){const d=i[a];if(c.clock+c.len<=d.id.clock)break;d instanceof I&&d.deleted&&!d.keep&&e(d)&&d.gc(t,!1)}}}},to=(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],c=Ue(r.length-1,1+j(r,o.clock+o.len-1));for(let l=c,a=r[l];l>0&&a.id.clock>=o.clock;a=r[l])l-=1+he(r,l)}})},Ss=(n,t)=>{if(t<n.length){const e=n[t],s=e.doc,r=s.store,i=e.deleteSet,o=e._mergeStructs;try{Ze(i),e.afterState=ae(e.doc.store),s.emit("beforeObserverCalls",[e,s]);const c=[];e.changed.forEach((l,a)=>c.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(e,l)})),c.push(()=>{e.changedParentTypes.forEach((l,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(l=l.filter(h=>h.target._item===null||!h.target._item.deleted),l.forEach(h=>{h.currentTarget=a,h._path=null}),l.sort((h,d)=>h.path.length-d.path.length),gs(a._dEH,l,e))})}),c.push(()=>s.emit("afterTransaction",[e,s])),Oe(c,[]),e._needFormattingCleanup&&ko(e)}finally{s.gc&&Qi(i,r,s.gcFilter),to(i,r),e.afterState.forEach((h,d)=>{const u=e.beforeState.get(d)||0;if(u!==h){const f=r.clients.get(d),g=ct(j(f,u),1);for(let m=f.length-1;m>=g;)m-=1+he(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=j(f,u);g+1<f.length&&he(f,g+1)>1||g>0&&he(f,g)}if(!e.local&&e.afterState.get(s.clientID)!==e.beforeState.get(s.clientID)&&(vi(qn,Wn,"[yjs] ",Gn,Pn,"Changed the client-id because another client seems to be using it."),s.clientID=ns()),s.emit("afterTransactionCleanup",[e,s]),s._observers.has("update")){const h=new Vt;bs(h,e)&&s.emit("update",[h.toUint8Array(),e.origin,s,e])}if(s._observers.has("updateV2")){const h=new dt;bs(h,e)&&s.emit("updateV2",[h.toUint8Array(),e.origin,s,e])}const{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:a}=e;(c.size>0||a.size>0||l.size>0)&&(c.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:l,added:c,removed:a},s,e]),a.forEach(h=>h.destroy())),n.length<=t+1?(s._transactionCleanups=[],s.emit("afterAllTransactions",[s,n])):Ss(n,t+1)}}},S=(n,t,e=null,s=!0)=>{const r=n._transactionCleanups;let i=!1,o=null;n._transaction===null&&(i=!0,n._transaction=new Zi(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 c=n._transaction===r[0];n._transaction=null,c&&Ss(r,0)}}return o};function*eo(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 c=n.readInfo();if(c===10){const l=w(n.restDecoder);yield new B(b(r,i),l),i+=l}else if(ne&c){const l=(c&(X|O))===0,a=new I(b(r,i),null,(c&O)===O?n.readLeftID():null,null,(c&X)===X?n.readRightID():null,l?n.readParentInfo()?n.readString():n.readLeftID():null,l&&(c&Rt)===Rt?n.readString():null,Ks(n,c));yield a,i+=a.length}else{const l=n.readLen();yield new N(b(r,i),l),i+=l}}}}class on{constructor(t,e){this.gen=eo(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 cn{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const no=n=>ue(n,rs,Vt),so=(n,t)=>{if(n.constructor===N){const{client:e,clock:s}=n.id;return new N(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 I(b(s,r+t),null,b(s,r+t-1),null,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t))}},ue=(n,t=Et,e=dt)=>{if(n.length===1)return n[0];const s=n.map(h=>new t(tt(h)));let r=s.map(h=>new on(h,!0)),i=null;const o=new e,c=new cn(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)st(c,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{st(c,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=so(u,g)),i.struct.mergeWith(u)||(st(c,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())st(c,i.struct,i.offset),i={struct:u,offset:0}}i!==null&&(st(c,i.struct,i.offset),i=null),ln(c);const l=s.map(h=>Qe(h)),a=Oi(l);return Dt(o,a),o.toUint8Array()},ro=(n,t,e=Et,s=dt)=>{const r=as(t),i=new s,o=new cn(i),c=new e(tt(n)),l=new on(c,!1);for(;l.curr;){const h=l.curr,d=h.id.client,u=r.get(d)||0;if(l.curr.constructor===B){l.next();continue}if(h.id.clock+h.length>u)for(st(o,h,ct(u-h.id.clock,0)),l.next();l.curr&&l.curr.id.client===d;)st(o,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===d&&l.curr.id.clock+l.curr.length<=u;)l.next()}ln(o);const a=Qe(c);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=T(),n.written=0)},st=(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++},ln=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),ie(t,s.restEncoder)}},io=(n,t,e,s)=>{const r=new e(tt(n)),i=new on(r,!1),o=new s,c=new cn(o);for(let a=i.curr;a!==null;a=i.next())st(c,t(a),0);ln(c);const l=Qe(r);return Dt(o,l),o.toUint8Array()},oo=n=>io(n,Kr,Et,Vt),Ds="You must not compute changes after the event-handler fired.";class de{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=co(this.currentTarget,this.target))}deletes(t){return ts(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw W(Ds);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,c;if(this.adds(i)){let l=i.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(i))if(l!==null&&this.deletes(l))o="delete",c=xe(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",c=xe(l.content.getContent())):(o="add",c=void 0)}else if(this.deletes(i))o="delete",c=xe(i.content.getContent());else return;t.set(r,{action:o,oldValue:c})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw W(Ds);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 c=null;const l=()=>{c&&i.push(c)};for(let a=e._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((c===null||c.delete===void 0)&&(l(),c={delete:0}),c.delete+=a.length,r.add(a)):this.adds(a)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(a.content.getContent()),s.add(a)):((c===null||c.retain===void 0)&&(l(),c={retain:0}),c.retain+=a.length);c!==null&&c.retain===void 0&&l()}this._changes=t}return t}}const co=(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},Es=80;let an=0;class lo{constructor(t,e){t.marker=!0,this.p=t,this.index=e,this.timestamp=an++}}const ao=n=>{n.timestamp=an++},Cs=(n,t,e)=>{n.p.marker=!1,n.p=t,t.marker=!0,n.index=e,n.timestamp=an++},ho=(n,t,e)=>{if(n.length>=Es){const s=n.reduce((r,i)=>r.timestamp<i.timestamp?r:i);return Cs(s,t,e),s}else{const s=new lo(t,e);return n.push(s),s}},fe=(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)=>te(t-i.index)<te(t-o.index)?i:o);let s=n._start,r=0;for(e!==null&&(s=e.p,r=e.index,ao(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&&te(e.index-r)<s.parent.length/Es?(Cs(e,s,r),e):ho(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=ct(t,r.index+e))}},ge=(n,t,e)=>{const s=n,r=t.changedParentTypes;for(;Y(r,n,()=>[]).push(e),n._item!==null;)n=n._item.parent;gs(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=us(),this._dEH=us(),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){ds(this._eH,t)}observeDeep(t){ds(this._dEH,t)}unobserve(t){fs(this._eH,t)}unobserveDeep(t){fs(this._dEH,t)}toJSON(){}}const As=(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 c=t;c<o.length&&s>0;c++)r.push(o[c]),s--;t=0}}i=i.right}return r},Is=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},uo=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}}}},Ms=(n,t)=>{const e=fe(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}},pe=(n,t,e,s)=>{let r=e;const i=n.doc,o=i.clientID,c=i.store,l=e===null?t._start:e.right;let a=[];const h=()=>{a.length>0&&(r=new I(b(o,v(c,o)),r,r&&r.lastId,l,l&&l.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 I(b(o,v(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new Yt(new Uint8Array(d))),r.integrate(n,0);break;case ut:r=new I(b(o,v(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new Xt(d)),r.integrate(n,0);break;default:if(d instanceof x)r=new I(b(o,v(c,o)),r,r&&r.lastId,l,l&&l.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!"),xs=(n,t,e,s)=>{if(e>t._length)throw vs();if(e===0)return t._searchMarker&&jt(t._searchMarker,e,s.length),pe(n,t,null,s);const r=e,i=fe(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&&nt(n,b(o.id.client,o.id.clock+e));break}e-=o.length}return t._searchMarker&&jt(t._searchMarker,r,s.length),pe(n,t,o,s)},fo=(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 pe(n,t,r,e)},Us=(n,t,e,s)=>{if(s===0)return;const r=e,i=s,o=fe(t,e);let c=t._start;for(o!==null&&(c=o.p,e-=o.index);c!==null&&e>0;c=c.right)!c.deleted&&c.countable&&(e<c.length&&nt(n,b(c.id.client,c.id.clock+e)),e-=c.length);for(;s>0&&c!==null;)c.deleted||(s<c.length&&nt(n,b(c.id.client,c.id.clock+s)),c.delete(n),s-=c.length),c=c.right;if(s>0)throw vs();t._searchMarker&&jt(t._searchMarker,r,-i+s)},we=(n,t,e)=>{const s=t._map.get(e);s!==void 0&&s.delete(n)},hn=(n,t,e,s)=>{const r=t._map.get(e)||null,i=n.doc,o=i.clientID;let c;if(s==null)c=new wt([s]);else switch(s.constructor){case Number:case Object:case Boolean:case Array:case String:c=new wt([s]);break;case Uint8Array:c=new Yt(s);break;case ut:c=new Xt(s);break;default:if(s instanceof x)c=new q(s);else throw new Error("Unexpected content type")}new I(b(o,v(i.store,o)),r,r&&r.lastId,null,null,t,e,c).integrate(n,0)},un=(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},Os=(n,t)=>{const e=n._map.get(t);return e!==void 0&&!e.deleted},me=n=>Ui(n.entries(),t=>!t[1].deleted);class go extends de{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),ge(this,t,new go(this,t))}insert(t,e){this.doc!==null?S(this.doc,s=>{xs(s,this,t,e)}):this._prelimContent.splice(t,0,...e)}push(t){this.doc!==null?S(this.doc,e=>{fo(e,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,e=1){this.doc!==null?S(this.doc,s=>{Us(s,this,t,e)}):this._prelimContent.splice(t,e)}get(t){return Ms(this,t)}toArray(){return Is(this)}slice(t=0,e=this.length){return As(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 uo(this)}_write(t){t.writeTypeRef(Fo)}}const po=n=>new At;class wo extends de{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){ge(this,t,new wo(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[...me(this._map)].length}keys(){return Pe(me(this._map),t=>t[0])}values(){return Pe(me(this._map),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Pe(me(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?S(this.doc,e=>{we(e,this,t)}):this._prelimContent.delete(t)}set(t,e){return this.doc!==null?S(this.doc,s=>{hn(s,this,t,e)}):this._prelimContent.set(t,e),e}get(t){return un(this,t)}has(t){return Os(this,t)}clear(){this.doc!==null?S(this.doc,t=>{this.forEach(function(e,s,r){we(t,r,s)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Ho)}}const mo=n=>new ft,rt=(n,t)=>n===t||typeof n=="object"&&typeof t=="object"&&n&&t&&jr(n,t);class dn{constructor(t,e,s,r){this.left=t,this.right=e,this.index=s,this.currentAttributes=r}forward(){switch(this.right===null&&$(),this.right.content.constructor){case A:this.right.deleted||It(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 Rs=(n,t,e)=>{for(;t.right!==null&&e>0;){switch(t.right.content.constructor){case A:t.right.deleted||It(t.currentAttributes,t.right.content);break;default:t.right.deleted||(e<t.right.length&&nt(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},ye=(n,t,e)=>{const s=new Map,r=fe(t,e);if(r){const i=new dn(r.p.left,r.p,r.index,s);return Rs(n,i,e-r.index)}else{const i=new dn(null,t._start,0,s);return Rs(n,i,e)}},Ns=(n,t,e,s)=>{for(;e.right!==null&&(e.right.deleted===!0||e.right.content.constructor===A&&rt(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,c)=>{const l=e.left,a=e.right,h=new I(b(i,v(r.store,i)),l,l&&l.lastId,a,a&&a.id,t,null,new A(c,o));h.integrate(n,0),e.right=h,e.forward()})},It=(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&&rt(t[n.right.content.key]||null,n.right.content.value)))break;n.forward()}},Fs=(n,t,e,s)=>{const r=n.doc,i=r.clientID,o=new Map;for(const c in s){const l=s[c],a=e.currentAttributes.get(c)||null;if(!rt(a,l)){o.set(c,a);const{left:h,right:d}=e;e.right=new I(b(i,v(r.store,i)),h,h&&h.lastId,d,d&&d.id,t,null,new A(c,l)),e.right.integrate(n,0),e.forward()}}return o},fn=(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 c=Fs(n,t,e,r),l=s.constructor===String?new K(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,l.getLength()),h=new I(b(o,v(i.store,o)),a,a&&a.lastId,h,h&&h.id,t,null,l),h.integrate(n,0),e.right=h,e.index=d,e.forward(),Ns(n,t,e,c)},Hs=(n,t,e,s,r)=>{const i=n.doc,o=i.clientID;Bs(e,r);const c=Fs(n,t,e,r);t:for(;e.right!==null&&(s>0||c.size>0&&(e.right.deleted||e.right.content.constructor===A));){if(!e.right.deleted)switch(e.right.content.constructor){case A:{const{key:l,value:a}=e.right.content,h=r[l];if(h!==void 0){if(rt(h,a))c.delete(l);else{if(s===0)break t;c.set(l,a)}e.right.delete(n)}else e.currentAttributes.set(l,a);break}default:s<e.right.length&&nt(n,b(e.right.id.client,e.right.id.clock+s)),s-=e.right.length;break}e.forward()}if(s>0){let l="";for(;s>0;s--)l+=`
2
+ `;e.right=new I(b(o,v(i.store,o)),e.left,e.left&&e.left.lastId,e.right,e.right&&e.right.id,t,null,new K(l)),e.right.integrate(n,0),e.forward()}Ns(n,t,e,c)},Vs=(n,t,e,s,r)=>{let i=t;const o=F();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 c=0,l=!1;for(;t!==i;){if(e===t&&(l=!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),c++,!l&&(r.get(h)||null)===d&&u!==d&&(u===null?r.delete(h):r.set(h,u))),!l&&!t.deleted&&It(r,a);break}}}t=t.right}return c},yo=(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}},bo=n=>{let t=0;return S(n.doc,e=>{let s=n._start,r=n._start,i=F();const o=ve(i);for(;r;){if(r.deleted===!1)switch(r.content.constructor){case A:It(o,r.content);break;default:t+=Vs(e,s,r,i,o),i=ve(o),s=r;break}r=r.right}}),t},ko=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&&ys(n,e.store.clients.get(s),i,r,o=>{!o.deleted&&o.content.constructor===A&&o.constructor!==N&&t.add(o.parent)})}S(e,s=>{Qn(n,n.deleteSet,r=>{if(r instanceof N||!r.parent._hasFormatting||t.has(r.parent))return;const i=r.parent;r.content.constructor===A?t.add(i):yo(s,r)});for(const r of t)bo(r)})},$s=(n,t,e)=>{const s=e,r=ve(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 K:e<t.right.length&&nt(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 So extends de{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=[];S(t,s=>{const r=new Map,i=new Map;let o=this.target._start,c=null;const l={};let a="",h=0,d=0;const u=()=>{if(c!==null){let f=null;switch(c){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},Vr(l)||(f.attributes=Nr({},l))),h=0;break}f&&e.push(f),c=null}};for(;o!==null;){switch(o.content.constructor){case q:case pt:this.adds(o)?this.deletes(o)||(u(),c="insert",a=o.content.getContent()[0],u()):this.deletes(o)?(c!=="delete"&&(u(),c="delete"),d+=1):o.deleted||(c!=="retain"&&(u(),c="retain"),h+=1);break;case K:this.adds(o)?this.deletes(o)||(c!=="insert"&&(u(),c="insert"),a+=o.content.str):this.deletes(o)?(c!=="delete"&&(u(),c="delete"),d+=o.length):o.deleted||(c!=="retain"&&(u(),c="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;rt(m,g)?g!==null&&o.delete(s):(c==="retain"&&u(),rt(g,i.get(f)||null)?delete l[f]:l[f]=g)}}else if(this.deletes(o)){i.set(f,g);const m=r.get(f)||null;rt(m,g)||(c==="retain"&&u(),l[f]=m)}else if(!o.deleted){i.set(f,g);const m=l[f];m!==void 0&&(rt(m,g)?m!==null&&o.delete(s):(c==="retain"&&u(),g===null?delete l[f]:l[f]=g))}o.deleted||(c==="insert"&&u(),It(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 Lt 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 Lt}clone(){const t=new Lt;return t.applyDelta(this.toDelta()),t}_callObserver(t,e){super._callObserver(t,e);const s=new So(this,t,e);ge(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===K&&(t+=e.content.str),e=e.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:e=!0}={}){this.doc!==null?S(this.doc,s=>{const r=new dn(null,this._start,0,new Map);for(let i=0;i<t.length;i++){const o=t[i];if(o.insert!==void 0){const c=!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 c!="string"||c.length>0)&&fn(s,this,r,c,o.attributes||{})}else o.retain!==void 0?Hs(s,this,r,o.retain,o.attributes||{}):o.delete!==void 0&&$s(s,r,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,e,s){const r=[],i=new Map,o=this.doc;let c="",l=this._start;function a(){if(c.length>0){const d={};let u=!1;i.forEach((g,m)=>{u=!0,d[m]=g});const f={insert:c};u&&(f.attributes=d),r.push(f),c=""}}const h=()=>{for(;l!==null;){if($t(l,t)||e!==void 0&&$t(l,e))switch(l.content.constructor){case K:{const d=i.get("ychange");t!==void 0&&!$t(l,t)?(d===void 0||d.user!==l.id.client||d.type!=="removed")&&(a(),i.set("ychange",s?s("removed",l.id):{type:"removed"})):e!==void 0&&!$t(l,e)?(d===void 0||d.user!==l.id.client||d.type!=="added")&&(a(),i.set("ychange",s?s("added",l.id):{type:"added"})):d!==void 0&&(a(),i.delete("ychange")),c+=l.content.str;break}case q:case pt:{a();const d={insert:l.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(l,t)&&(a(),It(i,l.content));break}l=l.right}a()};return t||e?S(o,d=>{t&&nn(d,t),e&&nn(d,e),h()},"cleanup"):h(),r}insert(t,e,s){if(e.length<=0)return;const r=this.doc;r!==null?S(r,i=>{const o=ye(i,this,t);s||(s={},o.currentAttributes.forEach((c,l)=>{s[l]=c})),fn(i,this,o,e,s)}):this._pending.push(()=>this.insert(t,e,s))}insertEmbed(t,e,s={}){const r=this.doc;r!==null?S(r,i=>{const o=ye(i,this,t);fn(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(s,r=>{$s(r,ye(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?S(r,i=>{const o=ye(i,this,t);o.right!==null&&Hs(i,this,o,e,s)}):this._pending.push(()=>this.format(t,e,s))}removeAttribute(t){this.doc!==null?S(this.doc,e=>{we(e,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,e){this.doc!==null?S(this.doc,s=>{hn(s,this,t,e)}):this._pending.push(()=>this.setAttribute(t,e))}getAttribute(t){return un(this,t)}getAttributes(){return Ts(this)}_write(t){t.writeTypeRef(Vo)}}const _o=n=>new Lt;class gn{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 gn(this,t)}querySelector(t){t=t.toUpperCase();const s=new gn(this,r=>r.nodeName&&r.nodeName.toUpperCase()===t).next();return s.done?null:s.value}querySelectorAll(t){return t=t.toUpperCase(),Q(new gn(this,e=>e.nodeName&&e.nodeName.toUpperCase()===t))}_callObserver(t,e){ge(this,t,new Co(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?S(this.doc,s=>{xs(s,this,t,e)}):this._prelimContent.splice(t,0,...e)}insertAfter(t,e){if(this.doc!==null)S(this.doc,s=>{const r=t&&t instanceof x?t._item:t;pe(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?S(this.doc,s=>{Us(s,this,t,e)}):this._prelimContent.splice(t,e)}toArray(){return Is(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Ms(this,t)}slice(t=0,e=this.length){return As(this,t,e)}forEach(t){Kt(this,t)}_write(t){t.writeTypeRef(jo)}}const Do=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 Fr(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 c in t)s.push(c);s.sort();const r=s.length;for(let c=0;c<r;c++){const l=s[c];e.push(l+'="'+t[l]+'"')}const i=this.nodeName.toLocaleLowerCase(),o=e.length>0?" "+e.join(" "):"";return`<${i}${o}>${super.toString()}</${i}>`}removeAttribute(t){this.doc!==null?S(this.doc,e=>{we(e,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,e){this.doc!==null?S(this.doc,s=>{hn(s,this,t,e)}):this._prelimAttrs.set(t,e)}getAttribute(t){return un(this,t)}hasAttribute(t){return Os(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 c=i[o];typeof c=="string"&&r.setAttribute(o,c)}return Kt(this,o=>{r.appendChild(o.toDOM(t,e,s))}),s!==void 0&&s._createAssociation(r,this),r}_write(t){t.writeTypeRef($o),t.writeKey(this.nodeName)}}const Eo=n=>new zt(n.readKey());class Co extends de{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 be extends ft{constructor(t){super(),this.hookName=t}_copy(){return new be(this.hookName)}clone(){const t=new be(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(Ko),t.writeKey(this.hookName)}}const Ao=n=>new be(n.readKey());class ke extends Lt{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 ke}clone(){const t=new ke;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,c)=>o.key<c.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 c=i.attrs[o];s+=` ${c.key}="${c.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(zo)}}const Io=n=>new ke;class pn{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 Lo=0;class N extends pn{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),ws(t.doc.store,this)}write(t,e){t.writeInfo(Lo),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 Mo=n=>new Yt(n.readBuf());class Jt{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Jt(this.len)}splice(t){const e=new Jt(this.len-t);return this.len=t,e}mergeWith(t){return this.len+=t.len,!0}integrate(t,e){ce(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 vo=n=>new Jt(n.readLen()),js=(n,t)=>new ut({guid:n,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Xt{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 Xt(js(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 xo=n=>new Xt(js(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 Uo=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 To=n=>new A(n.readKey(),n.readJSON());class Se{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Se(this.arr)}splice(t){const e=new Se(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 Oo=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 Se(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 Ro=n=>{const t=n.readLen(),e=[];for(let s=0;s<t;s++)e.push(n.readAny());return new wt(e)};class K{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new K(this.str)}splice(t){const e=new K(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 No=n=>new K(n.readString()),Bo=[po,mo,_o,Eo,Do,Ao,Io],Fo=0,Ho=1,Vo=2,$o=3,jo=4,Ko=5,zo=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 Yo=n=>new q(Bo[n.readTypeRef()](n)),_e=(n,t,e)=>{const{client:s,clock:r}=t.id,i=new I(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 I extends pn{constructor(t,e,s,r,i,o,c,l){super(t,l.getLength()),this.origin=s,this.left=e,this.right=r,this.rightOrigin=i,this.parent=o,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?Bn:0}set marker(t){(this.info&Fe)>0!==t&&(this.info^=Fe)}get marker(){return(this.info&Fe)>0}get keep(){return(this.info&Nn)>0}set keep(t){this.keep!==t&&(this.info^=Nn)}get countable(){return(this.info&Bn)>0}get deleted(){return(this.info&Be)>0}set deleted(t){this.deleted!==t&&(this.info^=Be)}markDeleted(){this.info|=Be}getMissing(t,e){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=v(e,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=v(e,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Ct&&this.id.client!==this.parent.client&&this.parent.clock>=v(e,this.parent.client))return this.parent.client;if(this.origin&&(this.left=ms(t,e,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=nt(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===N||this.right&&this.right.constructor===N)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===I&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===I&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Ct){const s=sn(e,this.parent);s.constructor===N?this.parent=null:this.parent=s.content.type}return null}integrate(t,e){if(e>0&&(this.id.clock+=e,this.left=ms(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(sn(t.doc.store,r.origin)))i.has(sn(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),ws(t.doc.store,this),this.content.integrate(t,this),ks(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new N(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(),ce(t.deleteSet,this.id.client,this.id.clock,this.length),ks(t,e,this.parentSub),this.content.delete(t)}}gc(t,e){if(!this.deleted)throw $();this.content.gc(t),e?qi(t,this,new N(this.id,this.length)):this.content=new Jt(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()&ne|(s===null?0:O)|(r===null?0:X)|(i===null?0:Rt);if(t.writeInfo(o),s!==null&&t.writeLeftID(s),r!==null&&t.writeRightID(r),s===null&&r===null){const c=this.parent;if(c._item!==void 0){const l=c._item;if(l===null){const a=Pi(c);t.writeParentInfo(!0),t.writeString(a)}else t.writeParentInfo(!1),t.writeLeftID(l.id)}else c.constructor===String?(t.writeParentInfo(!0),t.writeString(c)):c.constructor===Ct?(t.writeParentInfo(!1),t.writeLeftID(c)):$();i!==null&&t.writeString(i)}this.content.write(t,e)}}const Ks=(n,t)=>Jo[t&ne](n),Jo=[()=>{$()},vo,Oo,Mo,No,Uo,To,Yo,Ro,xo,()=>{$()}],Xo=10;class B extends pn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){$()}write(t,e){t.writeInfo(Xo),p(t.restEncoder,this.length-e)}getMissing(t,e){return null}}const zs=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Ys="__ $YJS$ __";zs[Ys]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),zs[Ys]=!0;const Js=new Map;class Wo{constructor(t){this.room=t,this.onmessage=null,this._onChange=e=>e.key===t&&this.onmessage!==null&&this.onmessage({data:oi(e.newValue||"")}),Or(this._onChange)}postMessage(t){Un.setItem(this.room,ii(ti(t)))}close(){Rr(this._onChange)}}const Go=typeof BroadcastChannel>"u"?Wo:BroadcastChannel,wn=n=>Y(Js,n,()=>{const t=ot(),e=new Go(n);return e.onmessage=s=>t.forEach(r=>r(s.data,"broadcastchannel")),{bc:e,subs:t}}),Po=(n,t)=>(wn(n).subs.add(t),t),qo=(n,t)=>{const e=wn(n),s=e.subs.delete(t);return s&&e.subs.size===0&&(e.bc.close(),Js.delete(n)),s},Mt=(n,t,e=null)=>{const s=wn(n);s.bc.postMessage(t),s.subs.forEach(r=>r(t,e))},Xs=0,mn=1,Ws=2,yn=(n,t)=>{p(n,Xs);const e=Wi(t);C(n,e)},Gs=(n,t,e)=>{p(n,mn),C(n,en(t,e))},Zo=(n,t,e)=>Gs(t,e,U(n)),Ps=(n,t,e)=>{try{ls(t,U(n),e)}catch(s){console.error("Caught error while handling a Yjs update",s)}},Qo=(n,t)=>{p(n,Ws),C(n,t)},tc=Ps,ec=(n,t,e,s)=>{const r=w(n);switch(r){case Xs:Zo(n,t,e);break;case mn:Ps(n,e,s);break;case Ws:tc(n,e,s);break;default:throw new Error("Unknown message type")}return r},nc=0,sc=(n,t,e)=>{switch(w(n)){case nc:e(t,et(n))}},bn=3e4;class rc extends Qt{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&&bn/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const s=[];this.meta.forEach((r,i)=>{i!==this.clientID&&bn<=e-r.lastUpdated&&this.states.has(i)&&s.push(i)}),s.length>0&&kn(this,s,"timeout")},J(bn/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=[],c=[],l=[],a=[];t===null?a.push(e):i==null?t!=null&&o.push(e):(c.push(e),Ot(i,t)||l.push(e)),(o.length>0||l.length>0||a.length>0)&&this.emit("change",[{added:o,updated:l,removed:a},"local"]),this.emit("update",[{added:o,updated:c,removed:a},"local"])}setLocalStateField(t,e){const s=this.getLocalState();s!==null&&this.setLocalState({...s,[t]:e})}getStates(){return this.states}}const kn=(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=T();p(r,s);for(let i=0;i<s;i++){const o=t[i],c=e.get(o)||null,l=n.meta.get(o).clock;p(r,o),p(r,l),at(r,JSON.stringify(c))}return D(r)},ic=(n,t,e)=>{const s=tt(t),r=ht(),i=[],o=[],c=[],l=[],a=w(s);for(let h=0;h<a;h++){const d=w(s);let u=w(s);const f=JSON.parse(et(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?l.push(d):f!==null&&(Ot(f,m)||c.push(d),o.push(d)))}(i.length>0||c.length>0||l.length>0)&&n.emit("change",[{added:i,updated:c,removed:l},e]),(i.length>0||o.length>0||l.length>0)&&n.emit("update",[{added:i,updated:o,removed:l},e])},oc=n=>Hr(n,(t,e)=>`${encodeURIComponent(e)}=${encodeURIComponent(t)}`).join("&");var mt=0,qs=3,vt=1,cc=2,lc=typeof window>"u";function ac(n,t){if(!n)throw new Error(t)}var Gt=[];Gt[mt]=(n,t,e,s,r)=>{p(n,mt);const i=ec(t,n,e.doc,e);s&&i===mn&&!e.synced&&(e.synced=!0)},Gt[qs]=(n,t,e,s,r)=>{p(n,vt),C(n,Wt(e.awareness,Array.from(e.awareness.getStates().keys())))},Gt[vt]=(n,t,e,s,r)=>{ic(e.awareness,U(t),e)},Gt[cc]=(n,t,e,s,r)=>{sc(t,e.doc,(i,o)=>hc(e,o))};var Zs=3e4;function hc(n,t){console.warn(`Permission denied to access ${n.url}.
4
+ ${t}`)}function Qs(n,t,e){const s=tt(t),r=T(),i=w(s),o=n.messageHandlers[i];return o?o(r,s,n,e,i):console.error("Unable to compute message"),r}function tr(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=Qs(n,new Uint8Array(e.data),!0);ze(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,kn(n.awareness,Array.from(n.awareness.getStates().keys()).filter(s=>s!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(tr,Ue(Cr(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=T();if(p(e,mt),yn(e,n.doc),t.send(D(e)),n.awareness.getLocalState()!==null){const s=T();p(s,vt),C(s,Wt(n.awareness,[n.doc.clientID])),t.send(D(s))}},n.emit("status",[{status:"connecting"}])}}function Sn(n,t){const e=n.ws;n.wsconnected&&e&&e.readyState===e.OPEN&&e.send(t),n.bcconnected&&Mt(n.bcChannel,t,n)}var uc=class extends Qt{constructor(t,e,s,{connect:r=!0,awareness:i=new rc(s),params:o={},WebSocketPolyfill:c=WebSocket,resyncInterval:l=-1,maxBackoffTime:a=2500,disableBc:h=lc}={}){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=oc(o);this.maxBackoffTime=a,this.bcChannel=t+"/"+e,this.url=t+"/"+e+(d.length===0?"":"?"+d),this.roomname=e,this.doc=s,this._WS=c,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,l>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const u=T();p(u,mt),yn(u,s),this.ws.send(D(u))}},l)),this._bcSubscriber=(u,f)=>{if(f!==this){const g=Qs(this,new Uint8Array(u),!1);ze(g)>1&&Mt(this.bcChannel,D(g),this)}},this._updateHandler=(u,f)=>{if(f!==this){const g=T();p(g,mt),Qo(g,u),Sn(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),Z=T();p(Z,vt),C(Z,Wt(i,E)),Sn(this,D(Z))},this._unloadHandler=()=>{kn(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&&Zs<ht()-this.wsLastMessageReceived&&(ac(this.ws!==null,"ws must not be null"),this.ws.close())},Zs/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||(Po(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const t=T();p(t,mt),yn(t,this.doc),Mt(this.bcChannel,D(t),this);const e=T();p(e,mt),Gs(e,this.doc),Mt(this.bcChannel,D(e),this);const s=T();p(s,qs),Mt(this.bcChannel,D(s),this);const r=T();p(r,vt),C(r,Wt(this.awareness,[this.doc.clientID])),Mt(this.bcChannel,D(r),this)}disconnectBc(){const t=T();p(t,vt),C(t,Wt(this.awareness,[this.doc.clientID],new Map)),Sn(this,D(t)),this.bcconnected&&(qo(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&&(tr(this),this.connectBc())}};function dc(){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 er(n,t,e){if(typeof n!==e)throw new Error(`Invalid "${t}" parameter provided to YPartyKitProvider. Expected: ${e}, received: ${n}`)}var fc=class extends WebSocket{send(n){typeof n!="string"&&kr(n,t=>super.send(t))}},gc=(wr=class extends uc{constructor(t,e,s,r={}){er(t,"host","string"),er(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??dc(),{params:c,connect:l=!0,...a}=r,h={...a,connect:!1,WebSocketPolyfill:fc};super(i,e,s??new ut,h);y(this,"id");yr(this,bt,void 0);this.id=o,br(this,bt,c),l&&this.connect()}connect(){Promise.resolve(typeof Me(this,bt)=="function"?Me(this,bt).call(this):Me(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,wr);const yt=n=>_t((t,e)=>{n.onerror=s=>e(new Error(s.target.error)),n.onsuccess=s=>t(s.target.result)}),pc=(n,t)=>_t((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)}}),wc=n=>yt(indexedDB.deleteDatabase(n)),mc=(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=>Cc(s,r))},nr=(n,t)=>yt(n.count(t)),yc=(n,t)=>yt(n.get(t)),sr=(n,t)=>yt(n.delete(t)),bc=(n,t,e)=>yt(n.put(t,e)),_n=(n,t)=>yt(n.add(t)),kc=(n,t,e)=>yt(n.getAll(t,e)),Sc=(n,t,e)=>{let s=null;return Ec(n,t,r=>(s=r,!1),e).then(()=>s)},_c=(n,t=null)=>Sc(n,t,"prev"),Dc=(n,t)=>_t((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()}}),Ec=(n,t,e,s="next")=>Dc(n.openKeyCursor(t,s),r=>e(r.key)),Cc=(n,t)=>n.objectStore(t),Ac=(n,t)=>IDBKeyRange.upperBound(n,t),Ic=(n,t)=>IDBKeyRange.lowerBound(n,t),Dn="custom",rr="updates",ir=500,or=(n,t=()=>{},e=()=>{})=>{const[s]=Pt(n.db,[rr]);return kc(s,Ic(n._dbref,!1)).then(r=>{n._destroyed||(t(s),S(n.doc,()=>{r.forEach(i=>ls(n.doc,i))},n,!1),e(s))}).then(()=>_c(s).then(r=>{n._dbref=r+1})).then(()=>nr(s).then(r=>{n._dbsize=r})).then(()=>s)},Lc=(n,t=!0)=>or(n).then(e=>{(t||n._dbsize>=ir)&&_n(e,en(n.doc)).then(()=>sr(e,Ac(n._dbref,!0))).then(()=>nr(e).then(s=>{n._dbsize=s}))});class Mc extends Qt{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=pc(t,s=>mc(s,[["updates",{autoIncrement:!0}],["custom"]])),this.whenSynced=_t(s=>this.on("synced",()=>s(this))),this._db.then(s=>{this.db=s,or(this,o=>_n(o,en(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,[rr]);_n(i,s),++this._dbsize>=ir&&(this._storeTimeoutId!==null&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout(()=>{Lc(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(()=>{wc(this.name)})}get(t){return this._db.then(e=>{const[s]=Pt(e,[Dn],"readonly");return yc(s,t)})}set(t,e){return this._db.then(s=>{const[r]=Pt(s,[Dn]);return bc(r,e,t)})}del(t){return this._db.then(e=>{const[s]=Pt(e,[Dn]);return sr(s,t)})}}const fl="",vc="can-duplicate-to";var De=(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.CanHover="can-hover",n.CanResize="can-resize",n.CanMirror="can-mirror",n))(De||{});function xc(n){return n.id}const cr=`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 or(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=ir}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:{on:!1},updateElement:({element:n,data:t})=>{const e=typeof t=="object"?t.on:t;n.classList.toggle("clicked",e)},onClick:(n,{data:t,setData:e})=>{const s=typeof t=="object"?t.on:t;e({on:!s})},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=ir,t.scale>=r.maxScale)return;i+=.1}s({...t,scale:i})},additionalSetup:n=>{n.getElement().addEventListener("mouseenter",t=>{or(t,n);const e=s=>or(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}}},lr=(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=lr(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=lr(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 Z;E.preventDefault(),(Z=this.onDrag)==null||Z.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 Z;E.preventDefault(),(Z=this.onDrag)==null||Z.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",Sn=new ut;function Ul(){return window.location.pathname+window.location.search}let it,z,R;const cr=new Map;let qt=Ml;function ar(){return[Se.CanPlay,...Object.keys(qt)]}let Ee=!1,Dn=!0;function Ol({room:n=Ul(),host:t=Tl,extraCapabilities:e}={}){if(!Dn){console.error("playhtml already set up!");return}const s=encodeURIComponent(window.location.hostname+"-"+n),r=t;if(console.log(`࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂
6
+ auto`,Uc=`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(),c=e();if(o.isHovering=!0,n.altKey){if(i.scale<=.5){c.style.cursor="not-allowed";return}c.style.cursor=Uc}else{if(i.scale>=i.maxScale){c.style.cursor="not-allowed";return}c.style.cursor=cr}r(o)}function Ee(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 Tc={["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}=Ee(n);t({startMouseX:e,startMouseY:s})},onDrag:(n,{data:t,localData:e,setData:s,setLocalData:r,element:i})=>{const{clientX:o,clientY:c}=Ee(n),{top:l,left:a,bottom:h,right:d}=i.getBoundingClientRect();d>window.outerWidth&&o>e.startMouseX||h>window.innerHeight&&c>e.startMouseY||a<0&&o<e.startMouseX||l<0&&c<e.startMouseY||(s({x:t.x+o-e.startMouseX,y:t.y+c-e.startMouseY}),r({startMouseX:o,startMouseY:c}))},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}=Ee(n);t({startMouseX:e})},onDrag:(n,{data:t,localData:e,setData:s,setLocalData:r})=>{const{clientX:i}=Ee(n);let o=Math.abs(i-e.startMouseX)*2,c=t.rotation;i>e.startMouseX?c+=o:i<e.startMouseX&&(c-=o),s({rotation:c}),r({startMouseX:i})},resetShortcut:"shiftKey"},["can-toggle"]:{defaultData:{on:!1},updateElement:({element:n,data:t})=>{const e=typeof t=="object"?t.on:t;n.classList.toggle("clicked",e)},onClick:(n,{data:t,setData:e})=>{const s=typeof t=="object"?t.on:t;console.log("clicked!",t,s),e({on:!s})},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=cr,t.scale>=r.maxScale)return;i+=.1}s({...t,scale:i})},onMount: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 h;const r=s.getAttribute("can-duplicate"),i=document.getElementById(r);let o=document.getElementById((h=t.slice(-1))==null?void 0:h[0])??null;if(!i){console.error(`Element with id ${r} not found. Cannot duplicate.`);return}const c=s.getAttribute(vc);function l(d){if(c){const u=document.getElementById(c)||document.querySelector(c);if(u){u.appendChild(d);return}}i.parentNode.insertBefore(d,(o||i).nextSibling)}const a=new Set(t);for(const d of n){if(a.has(d))continue;const u=i.cloneNode(!0);Object.assign(u,{...i}),u.id=d,l(u),t.push(d),window.playhtml.setupPlayElement(u),o=u}e(t)},onClick:(n,{data:t,element:e,setData:s})=>{const i=e.getAttribute("can-duplicate")+"-"+Math.random().toString(36).substr(2,9);s([...t,i])},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}},["can-mirror"]:{defaultData:n=>qt(n),onMount:({getElement:n,setData:t,getData:e})=>{const s=n();console.log("mirroring",s),Oc(s,r=>{const i=e();console.log("STATE UPDATING",i);const o=Nc(i,r);console.log("STATE UPDATED",o),t(o)})},updateElement:({element:n,data:t})=>{console.log("new data",t);const e=qt(n);Ce(e,t)||ar(n,t)}}};function Ce(n,t){if(n.tagName!==t.tagName||n.textContent!==t.textContent||Object.keys(n.attributes).length!==Object.keys(t.attributes).length)return!1;for(const[e,s]of Object.entries(n.attributes))if(t.attributes[e]!==s)return!1;if(n.children.length!==t.children.length)return!1;for(let e=0;e<n.children.length;e++)if(!Ce(n.children[e],t.children[e]))return!1;return!0}function Oc(n,t,e){const r={...{childList:!0,attributes:!0,subtree:!0,characterData:!0},...e},i=c=>{const l=c.filter(a=>{if(r.childList&&a.type==="childList")return!0;if(r.attributes&&a.type==="attributes")if(r.attributeFilter){if(r.attributeFilter.includes(a.attributeName||""))return!0}else return!0;return!!(r.characterData&&a.type==="characterData"||r.subtree&&a.type==="childList")});t(l)},o=new MutationObserver(i);return o.observe(n,r),o}function Rc(n){return JSON.parse(JSON.stringify(n))}function Nc(n,t){let e=Rc(n);return t.forEach(s=>{switch(s.type){case"attributes":Bc(e,s);break;case"childList":Fc(e,s);break;case"characterData":Hc(e,s);break}}),e}function Bc(n,t){if(t.target instanceof HTMLElement){const e=t.attributeName,s=t.target.getAttribute(e);s!==null?n.attributes[e]=s:delete n.attributes[e]}}function Fc(n,t){t.addedNodes.length&&t.addedNodes.forEach(e=>{if(!(e instanceof HTMLElement))return;const s=qt(e);n.children.find(r=>Ce(r,s))||n.children.push(s)}),t.removedNodes.length&&t.removedNodes.forEach(e=>{if(!(e instanceof HTMLElement))return;const s=qt(e),r=n.children.findIndex(i=>Ce(i,s));r!==-1&&n.children.splice(r,1)})}function Hc(n,t){t.target===n&&(n.textContent=t.target.textContent)}function qt(n){const t={tagName:n.tagName.toLowerCase(),attributes:{},children:[],textContent:n.textContent};for(const e of n.attributes)t.attributes[e.name]=e.value;return n.childNodes.forEach(e=>{e instanceof HTMLElement&&t.children.push(qt(e))}),console.log("initial state",t),t}function ar(n,t){Vc(n,t),t.children.length===0&&n.textContent!==t.textContent?n.textContent=t.textContent:t.children.length>0&&$c(n,t)}function Vc(n,t){if(t){for(const[e,s]of Object.entries(t.attributes))n.getAttribute(e)!==s&&n.setAttribute(e,s);Array.from(n.attributes).forEach(e=>{t.attributes[e.name]||n.removeAttribute(e.name)})}}function $c(n,t){const e=new Set;t.children.forEach(s=>{let r=Array.from(n.children).find(i=>i.tagName.toLowerCase()===s.tagName&&!e.has(i));r||(r=document.createElement(s.tagName),n.appendChild(r)),e.add(r),ar(r,s)}),Array.from(n.children).forEach(s=>{e.has(s)||n.removeChild(s)})}const jc={ctrlKey:"Control",altKey:"Alt",shiftKey:"Shift",metaKey:"Meta"},hr=(n,t=300)=>{let e;return function(...s){clearTimeout(e),e=setTimeout(()=>n.apply(this,s),t)}};class Kc{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:c,data:l,awareness:a,updateElement:h,updateElementAwareness:d,onMount: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=hr(this.onChange,f),this.onAwarenessChange=r,this.updateElement=h,this.updateElementAwareness=d;const m=l===void 0?this.defaultData:l;a!==void 0&&(this.__awareness=a);const E=c instanceof Function?c(e):c;E!==void 0&&this.setMyAwareness(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:c,onDragStart:l,resetShortcut:a,debounceMs:h,triggerAwarenessUpdate:d}){this.triggerAwarenessUpdate=d,this.onChange=e,this.debouncedOnChange=hr(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,c&&!this.onDrag&&(t.addEventListener("touchstart",u=>{var m;u.preventDefault(),(m=this.onDragStart)==null||m.call(this,u,this.getEventHandlerData());const f=E=>{var Z;E.preventDefault(),(Z=this.onDrag)==null||Z.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 Z;E.preventDefault(),(Z=this.onDrag)==null||Z.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=c,this.onDragStart=l,a&&!this.resetShortcut&&(t.title||(t.title=`Hold down the ${jc[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),setMyAwareness:t=>this.setMyAwareness(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),setMyAwareness:t=>this.setMyAwareness(t)}}setData(t){this.onChange(t)}setMyAwareness(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)}}async function zc(n,t){const e=new TextEncoder().encode(`${n}-${t.outerHTML}}`),s=await crypto.subtle.digest("SHA-1",e);return Array.from(new Uint8Array(s)).map(o=>o.toString(16).padStart(2,"0")).join("")}const Yc="playhtml.spencerc99.partykit.dev",En=new ut;function Jc(){return window.location.pathname+window.location.search}let it,z,R;const ur=new Map;let Zt=Tc;function dr(){return[De.CanPlay,...Object.keys(Zt)]}let Ae=!1,Cn=!0;function Xc({room:n=Jc(),host:t=Yc,extraCapabilities:e}={}){if(!Cn){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
- ࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂`),it=new hl(r,s,Sn),z=Sn.getMap("playhtml-global"),R=new Map,new Cl(s,Sn),Ce.globalData=z,Ce.elementHandlers=R,e)for(const[i,o]of Object.entries(e))qt[i]=o;return it.on("sync",i=>{i||console.error("Issue connecting to yjs..."),Ee=!0,console.log("[PLAYHTML]: Setting up elements... Time to have some fun 🛝"),ur()}),it}function Rl(n,t){const e=it.awareness.getLocalState();return((e==null?void 0:e[n])??{})[t]}function En(n){return n instanceof HTMLElement}function Bl(n,t,e,s){const r=z.get(t);return{...e,data:r.get(s)??e.defaultData,awareness:Rl(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=it.awareness.getLocalState())==null?void 0:c[t])||{};l[s]!==o&&(l[s]=o,it.awareness.setLocalStateField(t,l))},triggerAwarenessUpdate:()=>{hr()}}}function Nl(n){return n.defaultData!==void 0&&typeof n.defaultData=="object"&&n.updateElement!==void 0}function Fl(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 hr(){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)}it.awareness.getStates().forEach((e,s)=>{var r;for(const[i,o]of Object.entries(e)){const l=R.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=R.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 ur(){if(Ee){for(const n of ar()){const t=Array.from(document.querySelectorAll(`[${n}]`)).filter(En);if(t.length)for(let e=0;e<t.length;e++){const s=t[e];Ae(s,n)}}Dn&&(z.observe(n=>{n.changes.keys.forEach((t,e)=>{t.action==="add"&&z.set(e,z.get(e))})}),it.awareness.on("change",()=>hr()),Dn=!1)}}const Ce={init:Ol,setupPlayElements:ur,setupPlayElement:$l,removePlayElement:jl,setupPlayElementForTag:Ae,globalData:void 0,elementHandlers:void 0};window.playhtml=Ce;function Vl(n){if(R.has(n)||!Ee)return;R.has(n)||R.set(n,new Map),n!==Se.CanPlay&&qt[n],z.get(n)||z.set(n,new ft);const t=z.get(n);t.observe(e=>{e.changes.keys.forEach((s,r)=>{const i=R.get(n);if(s.action==="add"){const o=document.getElementById(r);if(!En(o)){console.log(`Element ${r} not an HTML element. Ignoring.`);return}Ae(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 Ae(n,t){var l;if(!Hl(n,t)||!Ee)return;if(!n.id){const c=n.getAttribute("selector-id");if(c){const a=cr.get(c)??0;n.id=btoa(`${t}-${c}-${a}`),cr.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=R.get(t),r=Fl(t,n);if(!Nl(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=z.get(t),o=Bl(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,{ignoreIfAlreadySetup:t}={}){if(!(t&&Object.keys(R||{}).some(e=>{var s;return(s=R.get(e))==null?void 0:s.has(n.id)}))){if(!En(n)){console.log(`Element ${n.id} not an HTML element. Ignoring.`);return}for(const e of ar())n.hasAttribute(e)&&Ae(n,e)}}function jl(n){if(!(!n||!n.id))for(const t of Object.keys(R)){const e=R.get(t);e.has(n.id)&&e.delete(n.id)}}S.playhtml=Ce,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
11
+ ࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂`),it=new gc(r,s,En),z=En.getMap("playhtml-global"),R=new Map,new Mc(s,En),Ie.globalData=z,Ie.elementHandlers=R,e)for(const[o,c]of Object.entries(e))Zt[o]=c;const i=document.createElement("link");return i.rel="stylesheet",i.href="https://unpkg.com/playhtml@latest/dist/style.css",document.head.appendChild(i),it.on("sync",o=>{o||console.error("Issue connecting to yjs..."),Ae=!0,console.log("[PLAYHTML]: Setting up elements... Time to have some fun 🛝"),pr()}),it}function Wc(n,t){const e=it.awareness.getLocalState();return((e==null?void 0:e[n])??{})[t]}function An(n){return n instanceof HTMLElement}function fr(n,t){if(n===t)return!0;if(n instanceof Object&&t instanceof Object){const e=Object.keys(n),s=Object.keys(t);if(e.length!==s.length)return!1;for(const r of e)if(!fr(n[r],t[r]))return!1;return!0}return!1}function Gc(n,t,e,s){const r=z.get(t);return{...e,data:r.get(s)??(e.defaultData instanceof Function?e.defaultData(n):e.defaultData),awareness:Wc(t,s)??e.myDefaultAwareness!==void 0?[e.myDefaultAwareness]:void 0,element:n,onChange:o=>{fr(r.get(s),o)||r.set(s,o)},onAwarenessChange:o=>{var l;const c=((l=it.awareness.getLocalState())==null?void 0:l[t])||{};c[s]!==o&&(c[s]=o,it.awareness.setLocalStateField(t,c))},triggerAwarenessUpdate:()=>{gr()}}}function Pc(n){return n.defaultData!==void 0&&(typeof n.defaultData=="object"||typeof n.defaultData=="function")&&n.updateElement!==void 0}function qc(n,t){if(n===De.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,onMount:e.onMount||e.additionalSetup,resetShortcut:e.resetShortcut,debounceMs:e.debounceMs,isValidElementForTag:e.isValidElementForTag}}return Zt[n]}function gr(){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)}it.awareness.getStates().forEach((e,s)=>{var r;for(const[i,o]of Object.entries(e)){const c=R.get(i);if(c)for(const[l,a]of c){if(!(l in o))continue;const h=o[l];t(i,l,s,h)}}for(const[i,o]of n){const c=R.get(i);if(c)for(const[l,a]of c){const h=(r=o.get(l))==null?void 0:r.values();if(!h)continue;let d=Array.from(h);a.__awareness=d}}})}function pr(){if(Ae){for(const n of dr()){const t=Array.from(document.querySelectorAll(`[${n}]`)).filter(An);t.length&&Promise.all(t.map(e=>Le(e,n)))}Cn&&(z.observe(n=>{n.changes.keys.forEach((t,e)=>{t.action==="add"&&z.set(e,z.get(e))})}),it.awareness.on("change",()=>gr()),Cn=!1)}}const Ie={init:Xc,setupPlayElements:pr,setupPlayElement:tl,removePlayElement:el,setupPlayElementForTag:Le,globalData:void 0,elementHandlers:void 0};window.playhtml=Ie;function Zc(n){if(R.has(n)||!Ae)return;R.has(n)||R.set(n,new Map),n!==De.CanPlay&&Zt[n],z.get(n)||z.set(n,new ft);const t=z.get(n);t.observe(e=>{e.changes.keys.forEach((s,r)=>{const i=R.get(n);if(s.action==="add"){const o=document.getElementById(r);if(!An(o)){console.log(`Element ${r} not an HTML element. Ignoring.`);return}Le(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 Qc(n,t){var e,s;return((s=(e=Zt[t])==null?void 0:e.isValidElementForTag)==null?void 0:s.call(e,n))??!0}async function Le(n,t){var c;if(!Qc(n,t)||!Ae)return;if(!n.id){const l=n.getAttribute("selector-id");if(l){const a=ur.get(l)??0;n.id=btoa(`${t}-${l}-${a}`),ur.set(l,a+1)}else n.id=await zc(t,n)}const e=xc(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}Zc(t);const s=R.get(t),r=qc(t,n);if(!Pc(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=z.get(t),o=Gc(n,t,r,e);if(s.has(e)){s.get(e).reinitializeElementData(o);return}else s.set(e,new Kc(o));i.get(e)===void 0&&r.defaultData!==void 0&&i.set(e,r.defaultData instanceof Function?r.defaultData(n):r.defaultData),(c=o.triggerAwarenessUpdate)==null||c.call(o),n.classList.add("__playhtml-element"),n.classList.add(`__playhtml-${t}`),n.style.setProperty("--jiggle-delay",`${Math.random()*1}s;}`)}function tl(n,{ignoreIfAlreadySetup:t}={}){if(!(t&&Object.keys(R||{}).some(e=>{var s;return(s=R.get(e))==null?void 0:s.has(n.id)}))){if(!An(n)){console.log(`Element ${n.id} not an HTML element. Ignoring.`);return}Promise.all(dr().filter(e=>n.hasAttribute(e)).map(e=>Le(n,e)))}}function el(n){if(!(!n||!n.id))for(const t of Object.keys(R)){const e=R.get(t);e.has(n.id)&&e.delete(n.id)}}_.playhtml=Ie,Object.defineProperty(_,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.17",
5
+ "version": "2.0.18",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "keywords": [
@@ -59,7 +59,7 @@
59
59
  "vite-plugin-dts": "^3.0.3"
60
60
  },
61
61
  "dependencies": {
62
- "@playhtml/common": "^0.0.5",
62
+ "@playhtml/common": "^0.0.6",
63
63
  "y-indexeddb": "^9.0.11",
64
64
  "y-partykit": "^0.0.10",
65
65
  "yjs": "^13.6.8"