playhtml 1.3.1 → 2.0.0

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,12 +1,12 @@
1
- (function(v,k){typeof exports=="object"&&typeof module<"u"?k(exports):typeof define=="function"&&define.amd?define(["exports"],k):(v=typeof globalThis<"u"?globalThis:v||self,k(v.playhtml={}))})(this,function(v){"use strict";var xl=Object.defineProperty;var Ul=(v,k,K)=>k in v?xl(v,k,{enumerable:!0,configurable:!0,writable:!0,value:K}):v[k]=K;var y=(v,k,K)=>(Ul(v,typeof k!="symbol"?k+"":k,K),K);const k=()=>new Map,K=n=>{const t=k();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},dr=(n,t)=>{const e=[];for(const[s,r]of n)e.push(t(r,s));return e},fr=(n,t)=>{for(const[e,s]of n)if(t(s,e))return!0;return!1},rt=()=>new Set,Ce=n=>n[n.length-1],gr=(n,t)=>{for(let e=0;e<t.length;e++)n.push(t[e])},Q=Array.from,pr=Array.isArray,wr=String.fromCharCode,mr=n=>n.toLowerCase(),yr=/^\s*/g,br=n=>n.replace(yr,""),_r=/([A-Z])/g,Dn=(n,t)=>br(n.replace(_r,e=>`${t}${mr(e)}`)),kr=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},xt=typeof TextEncoder<"u"?new TextEncoder:null,Sr=xt?n=>xt.encode(n):kr;let Ut=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Ut&&Ut.decode(new Uint8Array).length===1&&(Ut=null);const En=n=>n===void 0?null:n;class Dr{constructor(){this.map=new Map}setItem(t,e){this.map.set(t,e)}getItem(t){return this.map.get(t)}}let Cn=new Dr,Ae=!0;try{typeof localStorage<"u"&&(Cn=localStorage,Ae=!1)}catch{}const An=Cn,Er=n=>Ae||addEventListener("storage",n),Cr=n=>Ae||removeEventListener("storage",n),Ar=Object.assign,Ir=Object.keys,Lr=(n,t)=>{for(const e in n)t(n[e],e)},Mr=(n,t)=>{const e=[];for(const s in n)e.push(t(n[s],s));return e},Zt=n=>Ir(n).length,vr=n=>{for(const t in n)return!1;return!0},xr=(n,t)=>{for(const e in n)if(!t(n[e],e))return!1;return!0},In=(n,t)=>Object.prototype.hasOwnProperty.call(n,t),Ur=(n,t)=>n===t||Zt(n)===Zt(t)&&xr(n,(e,s)=>(e!==void 0||In(t,s))&&t[s]===e),Ie=(n,t,e=0)=>{try{for(;e<n.length;e++)n[e](...t)}finally{e<n.length&&Ie(n,t,e+1)}},Tr=n=>n,Or=(n,t)=>n===t,Tt=(n,t)=>{if(n==null||t==null)return Or(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)||!Tt(n.get(e),t.get(e)))return!1;break}case Object:if(Zt(n)!==Zt(t))return!1;for(const e in n)if(!In(n,e)||!Tt(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(!Tt(n[e],t[e]))return!1;break;default:return!1}return!0},Rr=(n,t)=>t.includes(n),yt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name),Ln=typeof window<"u"&&typeof document<"u"&&!yt;let F;const Nr=()=>{if(F===void 0)if(yt){F=k();const n=process.argv;let t=null;for(let e=0;e<n.length;e++){const s=n[e];s[0]==="-"?(t!==null&&F.set(t,""),t=s):t!==null&&(F.set(t,s),t=null)}t!==null&&F.set(t,"")}else typeof location=="object"?(F=k(),(location.search||"?").slice(1).split("&").forEach(n=>{if(n.length!==0){const[t,e]=n.split("=");F.set(`--${Dn(t,"-")}`,e),F.set(`-${Dn(t,"-")}`,e)}})):F=k();return F},Le=n=>Nr().has(n),Me=n=>En(yt?process.env[n.toUpperCase()]:An.getItem(n));(n=>Le("--"+n)||Me(n)!==null)("production");const Mn=yt&&Rr(process.env.FORCE_COLOR,["true","1","2"]),Br=!Le("no-colors")&&(!yt||process.stdout.isTTY||Mn)&&(!yt||Le("color")||Mn||Me("COLORTERM")!==null||(Me("TERM")||"").includes("color")),X=Math.floor,te=Math.abs,ve=(n,t)=>n<t?n:t,it=(n,t)=>n>t?n:t,Fr=Math.pow,vn=n=>n!==0?n<0:1/n<0,xn=1,Un=2,xe=4,Ue=8,Ot=32,z=64,T=128,ee=31,Te=63,ot=127,Vr=2147483647,Tn=Number.MAX_SAFE_INTEGER,Hr=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&X(n)===n);class Rt{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const x=()=>new Rt,Oe=n=>{let t=n.cpos;for(let e=0;e<n.bufs.length;e++)t+=n.bufs[e].length;return t},S=n=>{const t=new Uint8Array(Oe(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},$r=(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(it(e,t)*2),n.cpos=0)},I=(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},Re=I,p=(n,t)=>{for(;t>ot;)I(n,T|ot&t),t=X(t/128);I(n,ot&t)},Ne=(n,t)=>{const e=vn(t);for(e&&(t=-t),I(n,(t>Te?T:0)|(e?z:0)|Te&t),t=X(t/64);t>0;)I(n,(t>ot?T:0)|ot&t),t=X(t/128)},Be=new Uint8Array(3e4),jr=Be.length/3,Kr=(n,t)=>{if(t.length<jr){const e=xt.encodeInto(t,Be).written||0;p(n,e);for(let s=0;s<e;s++)I(n,Be[s])}else D(n,Sr(t))},Yr=(n,t)=>{const e=unescape(encodeURIComponent(t)),s=e.length;p(n,s);for(let r=0;r<s;r++)I(n,e.codePointAt(r))},lt=xt&&xt.encodeInto?Kr:Yr,ne=(n,t)=>{const e=n.cbuf.length,s=n.cpos,r=ve(e-s,t.length),i=t.length-r;n.cbuf.set(t.subarray(0,r),s),n.cpos+=r,i>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(it(e*2,i)),n.cbuf.set(t.subarray(r)),n.cpos=i)},D=(n,t)=>{p(n,t.byteLength),ne(n,t)},Fe=(n,t)=>{$r(n,t);const e=new DataView(n.cbuf.buffer,n.cpos,t);return n.cpos+=t,e},Xr=(n,t)=>Fe(n,4).setFloat32(0,t,!1),zr=(n,t)=>Fe(n,8).setFloat64(0,t,!1),Jr=(n,t)=>Fe(n,8).setBigInt64(0,t,!1),On=new DataView(new ArrayBuffer(4)),Gr=n=>(On.setFloat32(0,n),On.getFloat32(0)===n),Nt=(n,t)=>{switch(typeof t){case"string":I(n,119),lt(n,t);break;case"number":Hr(t)&&te(t)<=Vr?(I(n,125),Ne(n,t)):Gr(t)?(I(n,124),Xr(n,t)):(I(n,123),zr(n,t));break;case"bigint":I(n,122),Jr(n,t);break;case"object":if(t===null)I(n,126);else if(pr(t)){I(n,117),p(n,t.length);for(let e=0;e<t.length;e++)Nt(n,t[e])}else if(t instanceof Uint8Array)I(n,116),D(n,t);else{I(n,118);const e=Object.keys(t);p(n,e.length);for(let s=0;s<e.length;s++){const r=e[s];lt(n,r),Nt(n,t[r])}}break;case"boolean":I(n,t?120:121);break;default:I(n,127)}};class Rn extends Rt{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 Nn=n=>{n.count>0&&(Ne(n.encoder,n.count===1?n.s:-n.s),n.count>1&&p(n.encoder,n.count-2))};class se{constructor(){this.encoder=new Rt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(Nn(this),this.count=1,this.s=t)}toUint8Array(){return Nn(this),S(this.encoder)}}const Bn=n=>{if(n.count>0){const t=n.diff*2+(n.count===1?0:1);Ne(n.encoder,t),n.count>1&&p(n.encoder,n.count-2)}};class Ve{constructor(){this.encoder=new Rt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(Bn(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return Bn(this),S(this.encoder)}}class Wr{constructor(){this.sarr=[],this.s="",this.lensE=new se}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 Rt;return this.sarr.push(this.s),this.s="",lt(t,this.sarr.join("")),ne(t,this.lensE.toUint8Array()),S(t)}}const J=n=>new Error(n),V=()=>{throw J("Method unimplemented")},H=()=>{throw J("Unexpected case")},Fn=J("Unexpected end of array"),Vn=J("Integer out of Range");class re{constructor(t){this.arr=t,this.pos=0}}const Z=n=>new re(n),qr=n=>n.pos!==n.arr.length,Pr=(n,t)=>{const e=Ke(n.arr.buffer,n.pos+n.arr.byteOffset,t);return n.pos+=t,e},U=n=>Pr(n,w(n)),bt=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&ot)*e,e*=128,r<T)return t;if(t>Tn)throw Vn}throw Fn},He=n=>{let t=n.arr[n.pos++],e=t&Te,s=64;const r=(t&z)>0?-1:1;if(!(t&T))return r*e;const i=n.arr.length;for(;n.pos<i;){if(t=n.arr[n.pos++],e=e+(t&ot)*s,s*=128,t<T)return r*e;if(e>Tn)throw Vn}throw Fn},tt=Ut?n=>Ut.decode(U(n)):n=>{let t=w(n);if(t===0)return"";{let e=String.fromCodePoint(bt(n));if(--t<100)for(;t--;)e+=String.fromCodePoint(bt(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},Qr=[n=>{},n=>null,He,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,tt,n=>{const t=w(n),e={};for(let s=0;s<t;s++){const r=tt(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},U],Bt=n=>Qr[127-bt(n)](n);class Hn extends re{constructor(t,e){super(t),this.reader=e,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),qr(this)?this.count=w(this)+1:this.count=-1),this.count--,this.s}}class ie extends re{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=He(this);const t=vn(this.s);this.count=1,t&&(this.s=-this.s,this.count=w(this)+2)}return this.count--,this.s}}class je extends re{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=He(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 Zr{constructor(t){this.decoder=new ie(t),this.str=tt(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),e=this.str.slice(this.spos,t);return this.spos=t,e}}const $n=n=>new Uint8Array(n),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+=wr(n[e]);return btoa(t)},ni=n=>Buffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),si=n=>{const t=atob(n),e=$n(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=Ln?ei:ni,oi=Ln?si:ri,li=n=>{const t=$n(n.byteLength);return t.set(n),t},jn=new Map;class ci{constructor(t){this.room=t,this.onmessage=null,this._onChange=e=>e.key===t&&this.onmessage!==null&&this.onmessage({data:oi(e.newValue||"")}),Er(this._onChange)}postMessage(t){An.setItem(this.room,ii(ti(t)))}close(){Cr(this._onChange)}}const ai=typeof BroadcastChannel>"u"?ci:BroadcastChannel,Ye=n=>Y(jn,n,()=>{const t=rt(),e=new ai(n);return e.onmessage=s=>t.forEach(r=>r(s.data,"broadcastchannel")),{bc:e,subs:t}}),hi=(n,t)=>(Ye(n).subs.add(t),t),ui=(n,t)=>{const e=Ye(n),s=e.subs.delete(t);return s&&e.subs.size===0&&(e.bc.close(),jn.delete(n)),s},_t=(n,t,e=null)=>{const s=Ye(n);s.bc.postMessage(t),s.subs.forEach(r=>r(t,e))},ct=Date.now;class oe{constructor(){this._observers=k()}on(t,e){Y(this._observers,t,rt).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)||k()).values()).forEach(s=>s(...e))}destroy(){this._observers=k()}}const di=crypto.getRandomValues.bind(crypto),Kn=()=>di(new Uint32Array(1))[0],fi=[1e7]+-1e3+-4e3+-8e3+-1e11,gi=()=>fi.replace(/[018]/g,n=>(n^Kn()&15>>n/4).toString(16)),kt=n=>new Promise(n);Promise.all.bind(Promise);class pi{constructor(t,e){this.left=t,this.right=e}}const G=(n,t)=>new pi(n,t);typeof DOMParser<"u"&&new DOMParser;const wi=n=>dr(n,(t,e)=>`${e}:${t};`).join(""),W=Symbol,Yn=W(),Xn=W(),mi=W(),yi=W(),bi=W(),zn=W(),_i=W(),Jn=W(),ki=W(),Si=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},Di={[Yn]:G("font-weight","bold"),[Xn]:G("font-weight","normal"),[mi]:G("color","blue"),[bi]:G("color","green"),[yi]:G("color","grey"),[zn]:G("color","red"),[_i]:G("color","purple"),[Jn]:G("color","orange"),[ki]:G("color","black")},Ei=Br?n=>{const t=[],e=[],s=k();let r=[],i=0;for(;i<n.length;i++){const o=n[i],l=Di[o];if(l!==void 0)s.set(l.left,l.right);else if(o.constructor===String||o.constructor===Number){const c=wi(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}:Si,Ci=(...n)=>{console.log(...Ei(n)),Ai.forEach(t=>t.print(n))},Ai=rt(),Gn=n=>({[Symbol.iterator](){return this},next:n}),Ii=(n,t)=>Gn(()=>{let e;do e=n.next();while(!e.done&&!t(e.value));return e}),Xe=(n,t)=>Gn(()=>{const{done:e,value:s}=n.next();return{done:e,value:e?void 0:t(s)}});class ze{constructor(t,e){this.clock=t,this.len=e}}class Ft{constructor(){this.clients=new Map}}const Wn=(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];gs(n,i,l.clock,l.len,e)}}),Li=(n,t)=>{let e=0,s=n.length-1;for(;e<=s;){const r=X((e+s)/2),i=n[r],o=i.clock;if(o<=t){if(t<o+i.len)return r;e=r+1}else s=r-1}return null},qn=(n,t)=>{const e=n.clients.get(t.client);return e!==void 0&&Li(e,t.clock)!==null},Je=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=it(r.len,i.clock+i.len-r.clock):(s<e&&(t[s]=i),s++)}t.length=s})},Mi=n=>{const t=new Ft;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++)gr(i,n[o].clients.get(r)||[]);t.clients.set(r,i)}});return Je(t),t},le=(n,t,e,s)=>{Y(n.clients,t,()=>[]).push(new ze(e,s))},vi=()=>new Ft,xi=n=>{const t=vi();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 ze(l,c))}}r.length>0&&t.clients.set(s,r)}),t},St=(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)}})},Ge=n=>{const t=new Ft,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 ze(n.readDsClock(),n.readDsLen()))}}return t},Pn=(n,t,e)=>{const s=new Ft,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=L(e,o);for(let h=0;h<l;h++){const u=n.readDsClock(),d=u+n.readDsLen();if(u<a){a<d&&le(s,o,a,d-a);let f=$(c,u),g=c[f];for(!g.deleted&&g.id.clock<u&&(c.splice(f+1,0,Se(t,g,u-g.id.clock)),f++);f<c.length&&(g=c[f++],g.id.clock<d);)g.deleted||(d<g.id.clock+g.length&&c.splice(f,0,Se(t,g,d-g.id.clock)),g.delete(t))}else le(s,o,u,d-u)}}if(s.clients.size>0){const i=new at;return p(i.restEncoder,0),St(i,s),i.toUint8Array()}return null},Qn=Kn;class Dt extends oe{constructor({guid:t=gi(),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=Qn(),this.guid=t,this.collectionid=e,this.share=new Map,this.store=new us,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=kt(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const c=()=>kt(a=>{const h=u=>{(u===void 0||u===!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=M){const s=Y(this.share,t,()=>{const i=new e;return i._integrate(this,null),i}),r=s.constructor;if(e!==M&&r!==e)if(r===M){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,ht)}getXmlFragment(t=""){return this.get(t,ut)}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 Dt({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 Zn{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return w(this.restDecoder)}readDsLen(){return w(this.restDecoder)}}class ts extends Zn{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 bt(this.restDecoder)}readString(){return tt(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 li(U(this.restDecoder))}readJSON(){return JSON.parse(tt(this.restDecoder))}readKey(){return tt(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 je(U(t)),this.clientDecoder=new ie(U(t)),this.leftClockDecoder=new je(U(t)),this.rightClockDecoder=new je(U(t)),this.infoDecoder=new Hn(U(t),bt),this.stringDecoder=new Zr(U(t)),this.parentInfoDecoder=new Hn(U(t),bt),this.typeRefDecoder=new ie(U(t)),this.lenDecoder=new ie(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 Bt(this.restDecoder)}readBuf(){return U(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 es{constructor(){this.restEncoder=x()}toUint8Array(){return S(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){p(this.restEncoder,t)}writeDsLen(t){p(this.restEncoder,t)}}class Vt extends es{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){Re(this.restEncoder,t)}writeString(t){lt(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){Nt(this.restEncoder,t)}writeBuf(t){D(this.restEncoder,t)}writeJSON(t){lt(this.restEncoder,JSON.stringify(t))}writeKey(t){lt(this.restEncoder,t)}}class ns{constructor(){this.restEncoder=x(),this.dsCurrVal=0}toUint8Array(){return S(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const e=t-this.dsCurrVal;this.dsCurrVal=t,p(this.restEncoder,e)}writeDsLen(t){t===0&&H(),p(this.restEncoder,t-1),this.dsCurrVal+=t}}class at extends ns{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Ve,this.clientEncoder=new se,this.leftClockEncoder=new Ve,this.rightClockEncoder=new Ve,this.infoEncoder=new Rn(Re),this.stringEncoder=new Wr,this.parentInfoEncoder=new Rn(Re),this.typeRefEncoder=new se,this.lenEncoder=new se}toUint8Array(){const t=x();return p(t,0),D(t,this.keyClockEncoder.toUint8Array()),D(t,this.clientEncoder.toUint8Array()),D(t,this.leftClockEncoder.toUint8Array()),D(t,this.rightClockEncoder.toUint8Array()),D(t,S(this.infoEncoder)),D(t,this.stringEncoder.toUint8Array()),D(t,S(this.parentInfoEncoder)),D(t,this.typeRefEncoder.toUint8Array()),D(t,this.lenEncoder.toUint8Array()),ne(t,S(this.restEncoder)),S(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){Nt(this.restEncoder,t)}writeBuf(t){D(this.restEncoder,t)}writeJSON(t){Nt(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 Ti=(n,t,e,s)=>{s=it(s,t[0].id.clock);const r=$(t,s);p(n.restEncoder,t.length-r),n.writeClient(e),p(n.restEncoder,s);const i=t[r];i.write(n,s-i.id.clock);for(let o=r+1;o<t.length;o++)t[o].write(n,0)},We=(n,t,e)=>{const s=new Map;e.forEach((r,i)=>{L(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])=>{Ti(n,t.clients.get(r),r,i)})},Oi=(n,t)=>{const e=k(),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 u=n.readLen();o[a]=new N(b(l,c),u),c+=u;break}case 10:{const u=w(n.restDecoder);o[a]=new B(b(l,c),u),c+=u;break}default:{const u=(h&(z|T))===0,d=new A(b(l,c),null,(h&T)===T?n.readLeftID():null,null,(h&z)===z?n.readRightID():null,u?n.readParentInfo()?t.get(n.readString()):n.readLeftID():null,u&&(h&Ot)===Ot?n.readString():null,Vs(n,h));o[a]=d,c+=d.length}}}}return e},Ri=(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 us,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 u=new Map,d=()=>{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(O=>O!==g)}s.length=0};for(;;){if(h.constructor!==B){const g=Y(u,h.id.client,()=>L(t,h.id.client))-h.id.clock;if(g<0)s.push(h),a(h.id.client,h.id.clock-1),d();else{const m=h.getMissing(n,t);if(m!==null){s.push(h);const O=e.get(m)||{refs:[],i:0};if(O.refs.length===O.i)a(m,L(t,m)),d();else{h=O.refs[O.i++];continue}}else(g===0||g<h.length)&&(h.integrate(n,g),u.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 at;return We(f,l,new Map),p(f.restEncoder,0),{missing:c,update:f.toUint8Array()}}return null},Ni=(n,t)=>We(n,t.doc.store,t.beforeState),Bi=(n,t,e,s=new Et(n))=>_(t,r=>{r.local=!1;let i=!1;const o=r.doc,l=o.store,c=Oi(s,o),a=Ri(r,l,c),h=l.pendingStructs;if(h){for(const[d,f]of h.missing)if(f<L(l,d)){i=!0;break}if(a){for(const[d,f]of a.missing){const g=h.missing.get(d);(g==null||g>f)&&h.missing.set(d,f)}h.update=ue([h.update,a.update])}}else l.pendingStructs=a;const u=Pn(s,r,l);if(l.pendingDs){const d=new Et(Z(l.pendingDs));w(d.restDecoder);const f=Pn(d,r,l);u&&f?l.pendingDs=ue([u,f]):l.pendingDs=u||f}else l.pendingDs=u;if(i){const d=l.pendingStructs.update;l.pendingStructs=null,ss(r.doc,d)}},e,!1),ss=(n,t,e,s=Et)=>{const r=Z(t);Bi(r,n,e,new s(r))},rs=(n,t,e)=>ss(n,t,e,ts),Fi=(n,t,e=new Map)=>{We(n,t.store,e),St(n,xi(t.store))},Vi=(n,t=new Uint8Array([0]),e=new at)=>{const s=is(t);Fi(e,n,s);const r=[e.toUint8Array()];if(n.store.pendingDs&&r.push(n.store.pendingDs),n.store.pendingStructs&&r.push(Zi(n.store.pendingStructs.update,t)),r.length>1){if(e.constructor===Vt)return Pi(r.map((i,o)=>o===0?i:eo(i)));if(e.constructor===at)return ue(r)}return r[0]},qe=(n,t)=>Vi(n,t,new Vt),Hi=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},is=n=>Hi(new Zn(Z(n))),os=(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),$i=(n,t)=>os(n,ae(t.store)),ji=(n,t=new ns)=>(n instanceof Map?os(t,n):$i(t,n),t.toUint8Array()),Ki=n=>ji(n,new es);class Yi{constructor(){this.l=[]}}const ls=()=>new Yi,cs=(n,t)=>n.l.push(t),as=(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.")},hs=(n,t,e)=>Ie(n.l,[t,e]);class Ct{constructor(t,e){this.client=t,this.clock=e}}const ce=(n,t)=>n===t||n!==null&&t!==null&&n.client===t.client&&n.clock===t.clock,b=(n,t)=>new Ct(n,t),Xi=n=>{for(const[t,e]of n.doc.share.entries())if(e===n)return t;throw H()},Ht=(n,t)=>t===void 0?!n.deleted:t.sv.has(n.id.client)&&(t.sv.get(n.id.client)||0)>n.id.clock&&!qn(t.ds,n.id),Pe=(n,t)=>{const e=Y(n.meta,Pe,rt),s=n.doc.store;e.has(t)||(t.sv.forEach((r,i)=>{r<L(s,i)&&et(n,b(i,r))}),Wn(n,t.ds,r=>{}),e.add(t))};class us{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},L=(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},ds=(n,t)=>{let e=n.clients.get(t.id.client);if(e===void 0)e=[],n.clients.set(t.id.client,e);else{const s=e[e.length-1];if(s.id.clock+s.length!==t.id.clock)throw H()}e.push(t)},$=(n,t)=>{let e=0,s=n.length-1,r=n[s],i=r.id.clock;if(i===t)return s;let o=X(t/(i+r.length-1)*s);for(;e<=s;){if(r=n[o],i=r.id.clock,i<=t){if(t<i+r.length)return o;e=o+1}else s=o-1;o=X((e+s)/2)}throw H()},Qe=(n,t)=>{const e=n.clients.get(t.client);return e[$(e,t.clock)]},Ze=(n,t,e)=>{const s=$(t,e),r=t[s];return r.id.clock<e&&r instanceof A?(t.splice(s+1,0,Se(n,r,e-r.id.clock)),s+1):s},et=(n,t)=>{const e=n.doc.store.clients.get(t.client);return e[Ze(n,e,t.clock)]},fs=(n,t,e)=>{const s=t.clients.get(e.client),r=$(s,e.clock),i=s[r];return e.clock!==i.id.clock+i.length-1&&i.constructor!==N&&s.splice(r+1,0,Se(n,i,e.clock-i.id.clock+1)),i},zi=(n,t,e)=>{const s=n.clients.get(t.id.client);s[$(s,t.id.clock)]=e},gs=(n,t,e,s,r)=>{if(s===0)return;const i=e+s;let o=Ze(n,t,e),l;do l=t[o++],i<l.id.clock+l.length&&Ze(n,t,i),r(l);while(o<t.length&&t[o].id.clock<i)};class Ji{constructor(t,e,s){this.doc=t,this.deleteSet=new Ft,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 ps=(n,t)=>t.deleteSet.clients.size===0&&!fr(t.afterState,(e,s)=>t.beforeState.get(s)!==e)?!1:(Je(t.deleteSet),Ni(n,t),St(n,t.deleteSet),!0),ws=(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,rt).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 A&&e.parentSub!==null&&e.parent._map.get(e.parentSub)===e&&e.parent._map.set(e.parentSub,s);continue}break}const i=t-r;return i&&n.splice(t+1-i,i),i},Gi=(n,t,e)=>{for(const[s,r]of n.clients.entries()){const i=t.clients.get(s);for(let o=r.length-1;o>=0;o--){const l=r[o],c=l.clock+l.len;for(let a=$(i,l.clock),h=i[a];a<i.length&&h.id.clock<c;h=i[++a]){const u=i[a];if(l.clock+l.len<=u.id.clock)break;u instanceof A&&u.deleted&&!u.keep&&e(u)&&u.gc(t,!1)}}}},Wi=(n,t)=>{n.clients.forEach((e,s)=>{const r=t.clients.get(s);for(let i=e.length-1;i>=0;i--){const o=e[i],l=ve(r.length-1,1+$(r,o.clock+o.len-1));for(let c=l,a=r[c];c>0&&a.id.clock>=o.clock;a=r[c])c-=1+he(r,c)}})},ms=(n,t)=>{if(t<n.length){const e=n[t],s=e.doc,r=s.store,i=e.deleteSet,o=e._mergeStructs;try{Je(i),e.afterState=ae(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,u)=>h.path.length-u.path.length),hs(a._dEH,c,e))})}),l.push(()=>s.emit("afterTransaction",[e,s])),Ie(l,[]),e._needFormattingCleanup&&po(e)}finally{s.gc&&Gi(i,r,s.gcFilter),Wi(i,r),e.afterState.forEach((h,u)=>{const d=e.beforeState.get(u)||0;if(d!==h){const f=r.clients.get(u),g=it($(f,d),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:u,clock:d}=o[h].id,f=r.clients.get(u),g=$(f,d);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)&&(Ci(Jn,Yn,"[yjs] ",Xn,zn,"Changed the client-id because another client seems to be using it."),s.clientID=Qn()),s.emit("afterTransactionCleanup",[e,s]),s._observers.has("update")){const h=new Vt;ps(h,e)&&s.emit("update",[h.toUint8Array(),e.origin,s,e])}if(s._observers.has("updateV2")){const h=new at;ps(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])):ms(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 Ji(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&&ms(r,0)}}return o};function*qi(n){const t=w(n.restDecoder);for(let e=0;e<t;e++){const s=w(n.restDecoder),r=n.readClient();let i=w(n.restDecoder);for(let o=0;o<s;o++){const l=n.readInfo();if(l===10){const c=w(n.restDecoder);yield new B(b(r,i),c),i+=c}else if(ee&l){const c=(l&(z|T))===0,a=new A(b(r,i),null,(l&T)===T?n.readLeftID():null,null,(l&z)===z?n.readRightID():null,c?n.readParentInfo()?n.readString():n.readLeftID():null,c&&(l&Ot)===Ot?n.readString():null,Vs(n,l));yield a,i+=a.length}else{const c=n.readLen();yield new N(b(r,i),c),i+=c}}}}class tn{constructor(t,e){this.gen=qi(t),this.curr=null,this.done=!1,this.filterSkips=e,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===B);return this.curr}}class en{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const Pi=n=>ue(n,ts,Vt),Qi=(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 A(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=at)=>{if(n.length===1)return n[0];const s=n.map(h=>new t(Z(h)));let r=s.map(h=>new tn(h,!0)),i=null;const o=new e,l=new en(o);for(;r=r.filter(d=>d.curr!==null),r.sort((d,f)=>{if(d.curr.id.client===f.curr.id.client){const g=d.curr.id.clock-f.curr.id.clock;return g===0?d.curr.constructor===f.curr.constructor?0:d.curr.constructor===B?1:-1:g}else return f.curr.id.client-d.curr.id.client}),r.length!==0;){const h=r[0],u=h.curr.id.client;if(i!==null){let d=h.curr,f=!1;for(;d!==null&&d.id.clock+d.length<=i.struct.id.clock+i.struct.length&&d.id.client>=i.struct.id.client;)d=h.next(),f=!0;if(d===null||d.id.client!==u||f&&d.id.clock>i.struct.id.clock+i.struct.length)continue;if(u!==i.struct.id.client)nt(l,i.struct,i.offset),i={struct:d,offset:0},h.next();else if(i.struct.id.clock+i.struct.length<d.id.clock)if(i.struct.constructor===B)i.struct.length=d.id.clock+d.length-i.struct.id.clock;else{nt(l,i.struct,i.offset);const g=d.id.clock-i.struct.id.clock-i.struct.length;i={struct:new B(b(u,i.struct.id.clock+i.struct.length),g),offset:0}}else{const g=i.struct.id.clock+i.struct.length-d.id.clock;g>0&&(i.struct.constructor===B?i.struct.length-=g:d=Qi(d,g)),i.struct.mergeWith(d)||(nt(l,i.struct,i.offset),i={struct:d,offset:0},h.next())}}else i={struct:h.curr,offset:0},h.next();for(let d=h.curr;d!==null&&d.id.client===u&&d.id.clock===i.struct.id.clock+i.struct.length&&d.constructor!==B;d=h.next())nt(l,i.struct,i.offset),i={struct:d,offset:0}}i!==null&&(nt(l,i.struct,i.offset),i=null),nn(l);const c=s.map(h=>Ge(h)),a=Mi(c);return St(o,a),o.toUint8Array()},Zi=(n,t,e=Et,s=at)=>{const r=is(t),i=new s,o=new en(i),l=new e(Z(n)),c=new tn(l,!1);for(;c.curr;){const h=c.curr,u=h.id.client,d=r.get(u)||0;if(c.curr.constructor===B){c.next();continue}if(h.id.clock+h.length>d)for(nt(o,h,it(d-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===u;)nt(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===u&&c.curr.id.clock+c.curr.length<=d;)c.next()}nn(o);const a=Ge(l);return St(i,a),i.toUint8Array()},ys=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:S(n.encoder.restEncoder)}),n.encoder.restEncoder=x(),n.written=0)},nt=(n,t,e)=>{n.written>0&&n.currClient!==t.id.client&&ys(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++},nn=n=>{ys(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),ne(t,s.restEncoder)}},to=(n,t,e,s)=>{const r=new e(Z(n)),i=new tn(r,!1),o=new s,l=new en(o);for(let a=i.curr;a!==null;a=i.next())nt(l,t(a),0);nn(l);const c=Ge(r);return St(o,c),o.toUint8Array()},eo=n=>to(n,Tr,Et,Vt),bs="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=no(this.currentTarget,this.target))}deletes(t){return qn(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw J(bs);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=Ce(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Ce(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(i))o="delete",l=Ce(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 J(bs);const e=this.target,s=rt(),r=rt(),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 no=(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},_s=80;let sn=0;class so{constructor(t,e){t.marker=!0,this.p=t,this.index=e,this.timestamp=sn++}}const ro=n=>{n.timestamp=sn++},ks=(n,t,e)=>{n.p.marker=!1,n.p=t,t.marker=!0,n.index=e,n.timestamp=sn++},io=(n,t,e)=>{if(n.length>=_s){const s=n.reduce((r,i)=>r.timestamp<i.timestamp?r:i);return ks(s,t,e),s}else{const s=new so(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,ro(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/_s?(ks(e,s,r),e):io(n._searchMarker,s,r)},$t=(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=it(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;hs(s._eH,e,t)};class M{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ls(),this._dEH=ls(),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){cs(this._eH,t)}observeDeep(t){cs(this._dEH,t)}unobserve(t){as(this._eH,t)}unobserveDeep(t){as(this._dEH,t)}toJSON(){}}const Ss=(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},Ds=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},jt=(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}},Es=(n,t)=>{const e=[];return jt(n,(s,r)=>{e.push(t(s,r,n))}),e},oo=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}}}},Cs=(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,l=i.store,c=e===null?t._start:e.right;let a=[];const h=()=>{a.length>0&&(r=new A(b(o,L(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new ft(a)),r.integrate(n,0),a=[])};s.forEach(u=>{if(u===null)a.push(u);else switch(u.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(u);break;default:switch(h(),u.constructor){case Uint8Array:case ArrayBuffer:r=new A(b(o,L(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new Yt(new Uint8Array(u))),r.integrate(n,0);break;case Dt:r=new A(b(o,L(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new zt(u)),r.integrate(n,0);break;default:if(u instanceof M)r=new A(b(o,L(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new q(u)),r.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},As=J("Length exceeded!"),Is=(n,t,e,s)=>{if(e>t._length)throw As;if(e===0)return t._searchMarker&&$t(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&&et(n,b(o.id.client,o.id.clock+e));break}e-=o.length}return t._searchMarker&&$t(t._searchMarker,r,s.length),pe(n,t,o,s)},lo=(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)},Ls=(n,t,e,s)=>{if(s===0)return;const r=e,i=s,o=fe(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&&et(n,b(l.id.client,l.id.clock+e)),e-=l.length);for(;s>0&&l!==null;)l.deleted||(s<l.length&&et(n,b(l.id.client,l.id.clock+s)),l.delete(n),s-=l.length),l=l.right;if(s>0)throw As;t._searchMarker&&$t(t._searchMarker,r,-i+s)},we=(n,t,e)=>{const s=t._map.get(e);s!==void 0&&s.delete(n)},rn=(n,t,e,s)=>{const r=t._map.get(e)||null,i=n.doc,o=i.clientID;let l;if(s==null)l=new ft([s]);else switch(s.constructor){case Number:case Object:case Boolean:case Array:case String:l=new ft([s]);break;case Uint8Array:l=new Yt(s);break;case Dt:l=new zt(s);break;default:if(s instanceof M)l=new q(s);else throw new Error("Unexpected content type")}new A(b(o,L(i.store,o)),r,r&&r.lastId,null,null,t,e,l).integrate(n,0)},on=(n,t)=>{const e=n._map.get(t);return e!==void 0&&!e.deleted?e.content.getContent()[e.length-1]:void 0},Ms=n=>{const t={};return n._map.forEach((e,s)=>{e.deleted||(t[s]=e.content.getContent()[e.length-1])}),t},vs=(n,t)=>{const e=n._map.get(t);return e!==void 0&&!e.deleted},me=n=>Ii(n.entries(),t=>!t[1].deleted);class co extends de{constructor(t,e){super(t,e),this._transaction=e}}class At extends M{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 M?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 co(this,t))}insert(t,e){this.doc!==null?_(this.doc,s=>{Is(s,this,t,e)}):this._prelimContent.splice(t,0,...e)}push(t){this.doc!==null?_(this.doc,e=>{lo(e,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,e=1){this.doc!==null?_(this.doc,s=>{Ls(s,this,t,e)}):this._prelimContent.splice(t,e)}get(t){return Cs(this,t)}toArray(){return Ds(this)}slice(t=0,e=this.length){return Ss(this,t,e)}toJSON(){return this.map(t=>t instanceof M?t.toJSON():t)}map(t){return Es(this,t)}forEach(t){jt(this,t)}[Symbol.iterator](){return oo(this)}_write(t){t.writeTypeRef(To)}}const ao=n=>new At;class ho extends de{constructor(t,e,s){super(t,e),this.keysChanged=s}}class ht extends M{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 ht}clone(){const t=new ht;return this.forEach((e,s)=>{t.set(s,e instanceof M?e.clone():e)}),t}_callObserver(t,e){ge(this,t,new ho(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 M?r.toJSON():r}}),t}get size(){return[...me(this._map)].length}keys(){return Xe(me(this._map),t=>t[0])}values(){return Xe(me(this._map),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Xe(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?_(this.doc,e=>{we(e,this,t)}):this._prelimContent.delete(t)}set(t,e){return this.doc!==null?_(this.doc,s=>{rn(s,this,t,e)}):this._prelimContent.set(t,e),e}get(t){return on(this,t)}has(t){return vs(this,t)}clear(){this.doc!==null?_(this.doc,t=>{this.forEach(function(e,s,r){we(t,r,s)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Oo)}}const uo=n=>new ht,st=(n,t)=>n===t||typeof n=="object"&&typeof t=="object"&&n&&t&&Ur(n,t);class ln{constructor(t,e,s,r){this.left=t,this.right=e,this.index=s,this.currentAttributes=r}forward(){switch(this.right===null&&H(),this.right.content.constructor){case C: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 xs=(n,t,e)=>{for(;t.right!==null&&e>0;){switch(t.right.content.constructor){case C:t.right.deleted||It(t.currentAttributes,t.right.content);break;default:t.right.deleted||(e<t.right.length&&et(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 ln(r.p.left,r.p,r.index,s);return xs(n,i,e-r.index)}else{const i=new ln(null,t._start,0,s);return xs(n,i,e)}},Us=(n,t,e,s)=>{for(;e.right!==null&&(e.right.deleted===!0||e.right.content.constructor===C&&st(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 A(b(i,L(r.store,i)),c,c&&c.lastId,a,a&&a.id,t,null,new C(l,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)},Ts=(n,t)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===C&&st(t[n.right.content.key]||null,n.right.content.value)))break;n.forward()}},Os=(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(!st(a,c)){o.set(l,a);const{left:h,right:u}=e;e.right=new A(b(i,L(r.store,i)),h,h&&h.lastId,u,u&&u.id,t,null,new C(l,c)),e.right.integrate(n,0),e.forward()}}return o},cn=(n,t,e,s,r)=>{e.currentAttributes.forEach((d,f)=>{r[f]===void 0&&(r[f]=null)});const i=n.doc,o=i.clientID;Ts(e,r);const l=Os(n,t,e,r),c=s.constructor===String?new j(s):s instanceof M?new q(s):new dt(s);let{left:a,right:h,index:u}=e;t._searchMarker&&$t(t._searchMarker,e.index,c.getLength()),h=new A(b(o,L(i.store,o)),a,a&&a.lastId,h,h&&h.id,t,null,c),h.integrate(n,0),e.right=h,e.index=u,e.forward(),Us(n,t,e,l)},Rs=(n,t,e,s,r)=>{const i=n.doc,o=i.clientID;Ts(e,r);const l=Os(n,t,e,r);t:for(;e.right!==null&&(s>0||l.size>0&&(e.right.deleted||e.right.content.constructor===C));){if(!e.right.deleted)switch(e.right.content.constructor){case C:{const{key:c,value:a}=e.right.content,h=r[c];if(h!==void 0){if(st(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&&et(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 A(b(o,L(i.store,o)),e.left,e.left&&e.left.lastId,e.right,e.right&&e.right.id,t,null,new j(c)),e.right.integrate(n,0),e.forward()}Us(n,t,e,l)},Ns=(n,t,e,s,r)=>{let i=t;const o=k();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===C){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 C:{const{key:h,value:u}=a,d=s.get(h)||null;(o.get(h)!==a||d===u)&&(t.delete(n),l++,!c&&(r.get(h)||null)===u&&d!==u&&(d===null?r.delete(h):r.set(h,d))),!c&&!t.deleted&&It(r,a);break}}}t=t.right}return l},fo=(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===C){const s=t.content.key;e.has(s)?t.delete(n):e.add(s)}t=t.left}},go=n=>{let t=0;return _(n.doc,e=>{let s=n._start,r=n._start,i=k();const o=K(i);for(;r;){if(r.deleted===!1)switch(r.content.constructor){case C:It(o,r.content);break;default:t+=Ns(e,s,r,i,o),i=K(o),s=r;break}r=r.right}}),t},po=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&&gs(n,e.store.clients.get(s),i,r,o=>{!o.deleted&&o.content.constructor===C&&o.constructor!==N&&t.add(o.parent)})}_(e,s=>{Wn(n,n.deleteSet,r=>{if(r instanceof N||!r.parent._hasFormatting||t.has(r.parent))return;const i=r.parent;r.content.constructor===C?t.add(i):fo(s,r)});for(const r of t)go(r)})},Bs=(n,t,e)=>{const s=e,r=K(t.currentAttributes),i=t.right;for(;e>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case q:case dt:case j:e<t.right.length&&et(n,b(t.right.id.client,t.right.id.clock+e)),e-=t.right.length,t.right.delete(n);break}t.forward()}i&&Ns(n,i,t.right,r,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&$t(o._searchMarker,t.index,-s+e),t};class wo 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=[];_(t,s=>{const r=new Map,i=new Map;let o=this.target._start,l=null;const c={};let a="",h=0,u=0;const d=()=>{if(l!==null){let f=null;switch(l){case"delete":u>0&&(f={delete:u}),u=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(c)||(f.attributes=Ar({},c))),h=0;break}f&&e.push(f),l=null}};for(;o!==null;){switch(o.content.constructor){case q:case dt:this.adds(o)?this.deletes(o)||(d(),l="insert",a=o.content.getContent()[0],d()):this.deletes(o)?(l!=="delete"&&(d(),l="delete"),u+=1):o.deleted||(l!=="retain"&&(d(),l="retain"),h+=1);break;case j:this.adds(o)?this.deletes(o)||(l!=="insert"&&(d(),l="insert"),a+=o.content.str):this.deletes(o)?(l!=="delete"&&(d(),l="delete"),u+=o.length):o.deleted||(l!=="retain"&&(d(),l="retain"),h+=o.length);break;case C:{const{key:f,value:g}=o.content;if(this.adds(o)){if(!this.deletes(o)){const m=r.get(f)||null;st(m,g)?g!==null&&o.delete(s):(l==="retain"&&d(),st(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;st(m,g)||(l==="retain"&&d(),c[f]=m)}else if(!o.deleted){i.set(f,g);const m=c[f];m!==void 0&&(st(m,g)?m!==null&&o.delete(s):(l==="retain"&&d(),g===null?delete c[f]:c[f]=g))}o.deleted||(l==="insert"&&d(),It(r,o.content));break}}o=o.right}for(d();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 M{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 wo(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===j&&(t+=e.content.str),e=e.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:e=!0}={}){this.doc!==null?_(this.doc,s=>{const r=new ln(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)&&cn(s,this,r,l,o.attributes||{})}else o.retain!==void 0?Rs(s,this,r,o.retain,o.attributes||{}):o.delete!==void 0&&Bs(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 u={};let d=!1;i.forEach((g,m)=>{d=!0,u[m]=g});const f={insert:l};d&&(f.attributes=u),r.push(f),l=""}}const h=()=>{for(;c!==null;){if(Ht(c,t)||e!==void 0&&Ht(c,e))switch(c.content.constructor){case j:{const u=i.get("ychange");t!==void 0&&!Ht(c,t)?(u===void 0||u.user!==c.id.client||u.type!=="removed")&&(a(),i.set("ychange",s?s("removed",c.id):{type:"removed"})):e!==void 0&&!Ht(c,e)?(u===void 0||u.user!==c.id.client||u.type!=="added")&&(a(),i.set("ychange",s?s("added",c.id):{type:"added"})):u!==void 0&&(a(),i.delete("ychange")),l+=c.content.str;break}case q:case dt:{a();const u={insert:c.content.getContent()[0]};if(i.size>0){const d={};u.attributes=d,i.forEach((f,g)=>{d[g]=f})}r.push(u);break}case C:Ht(c,t)&&(a(),It(i,c.content));break}c=c.right}a()};return t||e?_(o,u=>{t&&Pe(u,t),e&&Pe(u,e),h()},"cleanup"):h(),r}insert(t,e,s){if(e.length<=0)return;const r=this.doc;r!==null?_(r,i=>{const o=ye(i,this,t);s||(s={},o.currentAttributes.forEach((l,c)=>{s[c]=l})),cn(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=ye(i,this,t);cn(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=>{Bs(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?_(r,i=>{const o=ye(i,this,t);o.right!==null&&Rs(i,this,o,e,s)}):this._pending.push(()=>this.format(t,e,s))}removeAttribute(t){this.doc!==null?_(this.doc,e=>{we(e,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,e){this.doc!==null?_(this.doc,s=>{rn(s,this,t,e)}):this._pending.push(()=>this.setAttribute(t,e))}getAttribute(t){return on(this,t)}getAttributes(){return Ms(this)}_write(t){t.writeTypeRef(Ro)}}const mo=n=>new Lt;class an{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===Kt||e.constructor===ut)&&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 ut extends M{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 ut}clone(){const t=new ut;return t.insert(0,this.toArray().map(e=>e instanceof M?e.clone():e)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new an(this,t)}querySelector(t){t=t.toUpperCase();const s=new an(this,r=>r.nodeName&&r.nodeName.toUpperCase()===t).next();return s.done?null:s.value}querySelectorAll(t){return t=t.toUpperCase(),Q(new an(this,e=>e.nodeName&&e.nodeName.toUpperCase()===t))}_callObserver(t,e){ge(this,t,new _o(this,e,t))}toString(){return Es(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),jt(this,i=>{r.insertBefore(i.toDOM(t,e,s),null)}),r}insert(t,e){this.doc!==null?_(this.doc,s=>{Is(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 M?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 J("Reference item not found");s.splice(r,0,...e)}}delete(t,e=1){this.doc!==null?_(this.doc,s=>{Ls(s,this,t,e)}):this._prelimContent.splice(t,e)}toArray(){return Ds(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Cs(this,t)}slice(t=0,e=this.length){return Ss(this,t,e)}forEach(t){jt(this,t)}_write(t){t.writeTypeRef(Bo)}}const yo=n=>new ut;class Kt extends ut{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 Kt(this.nodeName)}clone(){const t=new Kt(this.nodeName),e=this.getAttributes();return Lr(e,(s,r)=>{typeof s=="string"&&t.setAttribute(r,s)}),t.insert(0,this.toArray().map(s=>s instanceof M?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=>{we(e,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,e){this.doc!==null?_(this.doc,s=>{rn(s,this,t,e)}):this._prelimAttrs.set(t,e)}getAttribute(t){return on(this,t)}hasAttribute(t){return vs(this,t)}getAttributes(){return Ms(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 jt(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 bo=n=>new Kt(n.readKey());class _o 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 ht{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(Fo),t.writeKey(this.hookName)}}const ko=n=>new be(n.readKey());class _e 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 _e}clone(){const t=new _e;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(Vo)}}const So=n=>new _e;class hn{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 Do=0;class N extends hn{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),ds(t.doc.store,this)}write(t,e){t.writeInfo(Do),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 Eo=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){le(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 Co=n=>new Xt(n.readLen()),Fs=(n,t)=>new Dt({guid:n,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class zt{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 zt(Fs(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 Ao=n=>new zt(Fs(n.readString(),n.readAny()));class dt{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new dt(this.embed)}splice(t){throw V()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeJSON(this.embed)}getRef(){return 5}}const Io=n=>new dt(n.readJSON());class C{constructor(t,e){this.key=t,this.value=e}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new C(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 Lo=n=>new C(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 ft{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ft(this.arr)}splice(t){const e=new ft(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 vo=n=>{const t=n.readLen(),e=[];for(let s=0;s<t;s++)e.push(n.readAny());return new ft(e)};class j{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new j(this.str)}splice(t){const e=new j(this.str.slice(t));this.str=this.str.slice(0,t);const s=this.str.charCodeAt(t-1);return s>=55296&&s<=56319&&(this.str=this.str.slice(0,t-1)+"�",e.str="�"+e.str.slice(1)),e}mergeWith(t){return this.str+=t.str,!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeString(e===0?this.str:this.str.slice(e))}getRef(){return 4}}const xo=n=>new j(n.readString()),Uo=[ao,uo,mo,bo,yo,ko,So],To=0,Oo=1,Ro=2,No=3,Bo=4,Fo=5,Vo=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 Ho=n=>new q(Uo[n.readTypeRef()](n)),Se=(n,t,e)=>{const{client:s,clock:r}=t.id,i=new A(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 A extends hn{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()?Un:0}set marker(t){(this.info&Ue)>0!==t&&(this.info^=Ue)}get marker(){return(this.info&Ue)>0}get keep(){return(this.info&xn)>0}set keep(t){this.keep!==t&&(this.info^=xn)}get countable(){return(this.info&Un)>0}get deleted(){return(this.info&xe)>0}set deleted(t){this.deleted!==t&&(this.info^=xe)}markDeleted(){this.info|=xe}getMissing(t,e){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=L(e,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=L(e,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Ct&&this.id.client!==this.parent.client&&this.parent.clock>=L(e,this.parent.client))return this.parent.client;if(this.origin&&(this.left=fs(t,e,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=et(t,this.rightOrigin),this.rightOrigin=this.right.id),(this.left&&this.left.constructor===N||this.right&&this.right.constructor===N)&&(this.parent=null),!this.parent)this.left&&this.left.constructor===A&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===A&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Ct){const s=Qe(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=fs(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),ce(this.origin,r.origin)){if(r.id.client<this.id.client)s=r,i.clear();else if(ce(this.rightOrigin,r.rightOrigin))break}else if(r.origin!==null&&o.has(Qe(t.doc.store,r.origin)))i.has(Qe(t.doc.store,r.origin))||(s=r,i.clear());else break;r=r.right}this.left=s}if(this.left!==null){const s=this.left.right;this.right=s,this.left.right=this}else{let s;if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start,this.parent._start=this;this.right=s}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),ds(t.doc.store,this),this.content.integrate(t,this),ws(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&&ce(t.origin,this.lastId)&&this.right===t&&ce(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(),le(t.deleteSet,this.id.client,this.id.clock,this.length),ws(t,e,this.parentSub),this.content.delete(t)}}gc(t,e){if(!this.deleted)throw H();this.content.gc(t),e?zi(t,this,new N(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:T)|(r===null?0:z)|(i===null?0:Ot);if(t.writeInfo(o),s!==null&&t.writeLeftID(s),r!==null&&t.writeRightID(r),s===null&&r===null){const l=this.parent;if(l._item!==void 0){const c=l._item;if(c===null){const a=Xi(l);t.writeParentInfo(!0),t.writeString(a)}else t.writeParentInfo(!1),t.writeLeftID(c.id)}else l.constructor===String?(t.writeParentInfo(!0),t.writeString(l)):l.constructor===Ct?(t.writeParentInfo(!1),t.writeLeftID(l)):H();i!==null&&t.writeString(i)}this.content.write(t,e)}}const Vs=(n,t)=>$o[t&ee](n),$o=[()=>{H()},Co,Mo,Eo,xo,Io,Lo,Ho,vo,Ao,()=>{H()}],jo=10;class B extends hn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){H()}write(t,e){t.writeInfo(jo),p(t.restEncoder,this.length-e)}getMissing(t,e){return null}}const Hs=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},$s="__ $YJS$ __";Hs[$s]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),Hs[$s]=!0;const js=0,un=1,Ks=2,dn=(n,t)=>{p(n,js);const e=Ki(t);D(n,e)},Ys=(n,t,e)=>{p(n,un),D(n,qe(t,e))},Ko=(n,t,e)=>Ys(t,e,U(n)),Xs=(n,t,e)=>{try{rs(t,U(n),e)}catch(s){console.error("Caught error while handling a Yjs update",s)}},Yo=(n,t)=>{p(n,Ks),D(n,t)},Xo=Xs,zo=(n,t,e,s)=>{const r=w(n);switch(r){case js:Ko(n,t,e);break;case un:Xs(n,e,s);break;case Ks:Xo(n,e,s);break;default:throw new Error("Unknown message type")}return r},Jo=0,Go=(n,t,e)=>{switch(w(n)){case Jo:e(t,tt(n))}},fn=3e4;class Wo extends oe{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const e=ct();this.getLocalState()!==null&&fn/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const s=[];this.meta.forEach((r,i)=>{i!==this.clientID&&fn<=e-r.lastUpdated&&this.states.has(i)&&s.push(i)}),s.length>0&&gn(this,s,"timeout")},X(fn/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:ct()});const o=[],l=[],c=[],a=[];t===null?a.push(e):i==null?t!=null&&o.push(e):(l.push(e),Tt(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 gn=(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:ct()})}s.push(i)}}s.length>0&&(n.emit("change",[{added:[],updated:[],removed:s},e]),n.emit("update",[{added:[],updated:[],removed:s},e]))},Jt=(n,t,e=n.states)=>{const s=t.length,r=x();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),lt(r,JSON.stringify(l))}return S(r)},qo=(n,t,e)=>{const s=Z(t),r=ct(),i=[],o=[],l=[],c=[],a=w(s);for(let h=0;h<a;h++){const u=w(s);let d=w(s);const f=JSON.parse(tt(s)),g=n.meta.get(u),m=n.states.get(u),O=g===void 0?0:g.clock;(O<d||O===d&&f===null&&n.states.has(u))&&(f===null?u===n.clientID&&n.getLocalState()!=null?d++:n.states.delete(u):n.states.set(u,f),n.meta.set(u,{clock:d,lastUpdated:r}),g===void 0&&f!==null?i.push(u):g!==void 0&&f===null?c.push(u):f!==null&&(Tt(f,m)||l.push(u),o.push(u)))}(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])},Po=n=>Mr(n,(t,e)=>`${encodeURIComponent(e)}=${encodeURIComponent(t)}`).join("&");var gt=0,zs=3,Mt=1,Qo=2;function Zo(n,t){if(!n)throw new Error(t)}var Gt=[];Gt[gt]=(n,t,e,s,r)=>{p(n,gt);const i=zo(t,n,e.doc,e);s&&i===un&&!e.synced&&(e.synced=!0)},Gt[zs]=(n,t,e,s,r)=>{p(n,Mt),D(n,Jt(e.awareness,Array.from(e.awareness.getStates().keys())))},Gt[Mt]=(n,t,e,s,r)=>{qo(e.awareness,U(t),e)},Gt[Qo]=(n,t,e,s,r)=>{Go(t,e.doc,(i,o)=>tl(e,o))};var Js=3e4;function tl(n,t){console.warn(`Permission denied to access ${n.url}.
4
- ${t}`)}function Gs(n,t,e){const s=Z(t),r=x(),i=w(s),o=n.messageHandlers[i];return o?o(r,s,n,e,i):console.error("Unable to compute message"),r}function Ws(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(e.data==="ping"){t.send("pong");return}n.wsLastMessageReceived=ct();const s=Gs(n,new Uint8Array(e.data),!0);Oe(s)>1&&t.send(S(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,gn(n.awareness,Array.from(n.awareness.getStates().keys()).filter(s=>s!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Ws,ve(Fr(2,n.wsUnsuccessfulReconnects)*100,n.maxBackoffTime),n)},t.onopen=()=>{n.wsLastMessageReceived=ct(),n.wsconnecting=!1,n.wsconnected=!0,n.wsUnsuccessfulReconnects=0,n.emit("status",[{status:"connected"}]);const e=x();if(p(e,gt),dn(e,n.doc),t.send(S(e)),n.awareness.getLocalState()!==null){const s=x();p(s,Mt),D(s,Jt(n.awareness,[n.doc.clientID])),t.send(S(s))}},n.emit("status",[{status:"connecting"}])}}function pn(n,t){const e=n.ws;n.wsconnected&&e&&e.readyState===e.OPEN&&e.send(t),n.bcconnected&&_t(n.bcChannel,t,n)}var el=class extends oe{constructor(t,e,s,{connect:r=!0,awareness:i=new Wo(s),params:o={},WebSocketPolyfill:l=WebSocket,resyncInterval:c=-1,maxBackoffTime:a=2500,disableBc:h=!1}={}){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 u=Po(o);this.maxBackoffTime=a,this.bcChannel=t+"/"+e,this.url=t+"/"+e+(u.length===0?"":"?"+u),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 d=x();p(d,gt),dn(d,s),this.ws.send(S(d))}},c)),this._bcSubscriber=(d,f)=>{if(f!==this){const g=Gs(this,new Uint8Array(d),!1);Oe(g)>1&&_t(this.bcChannel,S(g),this)}},this._updateHandler=(d,f)=>{if(f!==this){const g=x();p(g,gt),Yo(g,d),pn(this,S(g))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:d,updated:f,removed:g},m)=>{const O=d.concat(f).concat(g),qt=x();p(qt,Mt),D(qt,Jt(i,O)),pn(this,S(qt))},this._unloadHandler=()=>{gn(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&&Js<ct()-this.wsLastMessageReceived&&(Zo(this.ws!==null,"ws must not be null"),this.ws.close())},Js/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||(hi(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const t=x();p(t,gt),dn(t,this.doc),_t(this.bcChannel,S(t),this);const e=x();p(e,gt),Ys(e,this.doc),_t(this.bcChannel,S(e),this);const s=x();p(s,zs),_t(this.bcChannel,S(s),this);const r=x();p(r,Mt),D(r,Jt(this.awareness,[this.doc.clientID])),_t(this.bcChannel,S(r),this)}disconnectBc(){const t=x();p(t,Mt),D(t,Jt(this.awareness,[this.doc.clientID],new Map)),pn(this,S(t)),this.bcconnected&&(ui(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&&(Ws(this),this.connectBc())}};function qs(){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)})}var nl=class extends el{constructor(n,t,e,s={}){const r=`${n.startsWith("localhost:")||n.startsWith("127.0.0.1:")?"ws":"wss"}://${n}/party`;s.params===void 0?s.params={_pk:qs()}:s.params._pk=qs(),super(r,t,e,s)}};const pt=n=>kt((t,e)=>{n.onerror=s=>e(new Error(s.target.error)),n.onsuccess=s=>t(s.target.result)}),sl=(n,t)=>kt((e,s)=>{const r=indexedDB.open(n);r.onupgradeneeded=i=>t(i.target.result),r.onerror=i=>s(J(i.target.error)),r.onsuccess=i=>{const o=i.target.result;o.onversionchange=()=>{o.close()},typeof addEventListener<"u"&&addEventListener("unload",()=>o.close()),e(o)}}),rl=n=>pt(indexedDB.deleteDatabase(n)),il=(n,t)=>t.forEach(e=>n.createObjectStore.apply(n,e)),Wt=(n,t,e="readwrite")=>{const s=n.transaction(t,e);return t.map(r=>fl(s,r))},Ps=(n,t)=>pt(n.count(t)),ol=(n,t)=>pt(n.get(t)),Qs=(n,t)=>pt(n.delete(t)),ll=(n,t,e)=>pt(n.put(t,e)),wn=(n,t)=>pt(n.add(t)),cl=(n,t,e)=>pt(n.getAll(t,e)),al=(n,t,e)=>{let s=null;return dl(n,t,r=>(s=r,!1),e).then(()=>s)},hl=(n,t=null)=>al(n,t,"prev"),ul=(n,t)=>kt((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()}}),dl=(n,t,e,s="next")=>ul(n.openKeyCursor(t,s),r=>e(r.key)),fl=(n,t)=>n.objectStore(t),gl=(n,t)=>IDBKeyRange.upperBound(n,t),pl=(n,t)=>IDBKeyRange.lowerBound(n,t),mn="custom",Zs="updates",tr=500,er=(n,t=()=>{},e=()=>{})=>{const[s]=Wt(n.db,[Zs]);return cl(s,pl(n._dbref,!1)).then(r=>{n._destroyed||(t(s),_(n.doc,()=>{r.forEach(i=>rs(n.doc,i))},n,!1),e(s))}).then(()=>hl(s).then(r=>{n._dbref=r+1})).then(()=>Ps(s).then(r=>{n._dbsize=r})).then(()=>s)},wl=(n,t=!0)=>er(n).then(e=>{(t||n._dbsize>=tr)&&wn(e,qe(n.doc)).then(()=>Qs(e,gl(n._dbref,!0))).then(()=>Ps(e).then(s=>{n._dbsize=s}))});class ml extends oe{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=sl(t,s=>il(s,[["updates",{autoIncrement:!0}],["custom"]])),this.whenSynced=kt(s=>this.on("synced",()=>s(this))),this._db.then(s=>{this.db=s,er(this,o=>wn(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]=Wt(this.db,[Zs]);wn(i,s),++this._dbsize>=tr&&(this._storeTimeoutId!==null&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout(()=>{wl(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(()=>{rl(this.name)})}get(t){return this._db.then(e=>{const[s]=Wt(e,[mn],"readonly");return ol(s,t)})}set(t,e){return this._db.then(s=>{const[r]=Wt(s,[mn]);return ll(r,e,t)})}del(t){return this._db.then(e=>{const[s]=Wt(e,[mn]);return Qs(s,t)})}}const jl="",yl={ctrlKey:"Control",altKey:"Alt",shiftKey:"Shift",metaKey:"Meta"},bl="can-duplicate-to";var E=(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.CanPost="can-post",n))(E||{});const _l=(n,t=300)=>{let e;return function(...s){clearTimeout(e),e=setTimeout(()=>n.apply(this,s),t)}},nr=`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(L,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(L=typeof globalThis<"u"?globalThis:L||self,_(L.playhtml={}))})(this,function(L){"use strict";var zc=Object.defineProperty;var Oc=(L,_,q)=>_ in L?zc(L,_,{enumerable:!0,configurable:!0,writable:!0,value:q}):L[_]=q;var b=(L,_,q)=>(Oc(L,typeof _!="symbol"?_+"":_,q),q);const _=()=>new Map,q=s=>{const e=_();return s.forEach((t,n)=>{e.set(n,t)}),e},K=(s,e,t)=>{let n=s.get(e);return n===void 0&&s.set(e,n=t()),n},di=(s,e)=>{const t=[];for(const[n,i]of s)t.push(e(i,n));return t},fi=(s,e)=>{for(const[t,n]of s)if(e(n,t))return!0;return!1},re=()=>new Set,vt=s=>s[s.length-1],gi=(s,e)=>{for(let t=0;t<e.length;t++)s.push(e[t])},Q=Array.from,pi=Array.isArray,ki=String.fromCharCode,mi=s=>s.toLowerCase(),bi=/^\s*/g,wi=s=>s.replace(bi,""),yi=/([A-Z])/g,Ss=(s,e)=>wi(s.replace(yi,t=>`${e}${mi(t)}`)),_i=s=>{const e=unescape(encodeURIComponent(s)),t=e.length,n=new Uint8Array(t);for(let i=0;i<t;i++)n[i]=e.codePointAt(i);return n},je=typeof TextEncoder<"u"?new TextEncoder:null,Si=je?s=>je.encode(s):_i;let Me=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Me&&Me.decode(new Uint8Array).length===1&&(Me=null);const Ds=s=>s===void 0?null:s;class Di{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}}let Es=new Di,At=!0;try{typeof localStorage<"u"&&(Es=localStorage,At=!1)}catch{}const Cs=Es,Ei=s=>At||addEventListener("storage",s),Ci=s=>At||removeEventListener("storage",s),vi=Object.assign,Ai=Object.keys,xi=(s,e)=>{for(const t in s)e(s[t],t)},Ii=(s,e)=>{const t=[];for(const n in s)t.push(e(s[n],n));return t},Ze=s=>Ai(s).length,Li=s=>{for(const e in s)return!1;return!0},ji=(s,e)=>{for(const t in s)if(!e(s[t],t))return!1;return!0},vs=(s,e)=>Object.prototype.hasOwnProperty.call(s,e),Mi=(s,e)=>s===e||Ze(s)===Ze(e)&&ji(s,(t,n)=>(t!==void 0||vs(e,n))&&e[n]===t),xt=(s,e,t=0)=>{try{for(;t<s.length;t++)s[t](...e)}finally{t<s.length&&xt(s,e,t+1)}},Ti=s=>s,Ui=(s,e)=>s===e,Te=(s,e)=>{if(s==null||e==null)return Ui(s,e);if(s.constructor!==e.constructor)return!1;if(s===e)return!0;switch(s.constructor){case ArrayBuffer:s=new Uint8Array(s),e=new Uint8Array(e);case Uint8Array:{if(s.byteLength!==e.byteLength)return!1;for(let t=0;t<s.length;t++)if(s[t]!==e[t])return!1;break}case Set:{if(s.size!==e.size)return!1;for(const t of s)if(!e.has(t))return!1;break}case Map:{if(s.size!==e.size)return!1;for(const t of s.keys())if(!e.has(t)||!Te(s.get(t),e.get(t)))return!1;break}case Object:if(Ze(s)!==Ze(e))return!1;for(const t in s)if(!vs(s,t)||!Te(s[t],e[t]))return!1;break;case Array:if(s.length!==e.length)return!1;for(let t=0;t<s.length;t++)if(!Te(s[t],e[t]))return!1;break;default:return!1}return!0},zi=(s,e)=>e.includes(s),we=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name),As=typeof window<"u"&&typeof document<"u"&&!we;let N;const Oi=()=>{if(N===void 0)if(we){N=_();const s=process.argv;let e=null;for(let t=0;t<s.length;t++){const n=s[t];n[0]==="-"?(e!==null&&N.set(e,""),e=n):e!==null&&(N.set(e,n),e=null)}e!==null&&N.set(e,"")}else typeof location=="object"?(N=_(),(location.search||"?").slice(1).split("&").forEach(s=>{if(s.length!==0){const[e,t]=s.split("=");N.set(`--${Ss(e,"-")}`,t),N.set(`-${Ss(e,"-")}`,t)}})):N=_();return N},It=s=>Oi().has(s),Lt=s=>Ds(we?process.env[s.toUpperCase()]:Cs.getItem(s));(s=>It("--"+s)||Lt(s)!==null)("production");const xs=we&&zi(process.env.FORCE_COLOR,["true","1","2"]),Ri=!It("no-colors")&&(!we||process.stdout.isTTY||xs)&&(!we||It("color")||xs||Lt("COLORTERM")!==null||(Lt("TERM")||"").includes("color")),Y=Math.floor,et=Math.abs,jt=(s,e)=>s<e?s:e,oe=(s,e)=>s>e?s:e,Ni=Math.pow,Is=s=>s!==0?s<0:1/s<0,Ls=1,js=2,Mt=4,Tt=8,Ue=32,J=64,T=128,tt=31,Ut=63,ce=127,Bi=2147483647,Ms=Number.MAX_SAFE_INTEGER,Fi=Number.isInteger||(s=>typeof s=="number"&&isFinite(s)&&Y(s)===s);class ze{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const j=()=>new ze,zt=s=>{let e=s.cpos;for(let t=0;t<s.bufs.length;t++)e+=s.bufs[t].length;return e},S=s=>{const e=new Uint8Array(zt(s));let t=0;for(let n=0;n<s.bufs.length;n++){const i=s.bufs[n];e.set(i,t),t+=i.length}return e.set(qt(s.cbuf.buffer,0,s.cpos),t),e},Vi=(s,e)=>{const t=s.cbuf.length;t-s.cpos<e&&(s.bufs.push(qt(s.cbuf.buffer,0,s.cpos)),s.cbuf=new Uint8Array(oe(t,e)*2),s.cpos=0)},A=(s,e)=>{const t=s.cbuf.length;s.cpos===t&&(s.bufs.push(s.cbuf),s.cbuf=new Uint8Array(t*2),s.cpos=0),s.cbuf[s.cpos++]=e},Ot=A,p=(s,e)=>{for(;e>ce;)A(s,T|ce&e),e=Y(e/128);A(s,ce&e)},Rt=(s,e)=>{const t=Is(e);for(t&&(e=-e),A(s,(e>Ut?T:0)|(t?J:0)|Ut&e),e=Y(e/64);e>0;)A(s,(e>ce?T:0)|ce&e),e=Y(e/128)},Nt=new Uint8Array(3e4),Hi=Nt.length/3,$i=(s,e)=>{if(e.length<Hi){const t=je.encodeInto(e,Nt).written||0;p(s,t);for(let n=0;n<t;n++)A(s,Nt[n])}else D(s,Si(e))},qi=(s,e)=>{const t=unescape(encodeURIComponent(e)),n=t.length;p(s,n);for(let i=0;i<n;i++)A(s,t.codePointAt(i))},ae=je&&je.encodeInto?$i:qi,st=(s,e)=>{const t=s.cbuf.length,n=s.cpos,i=jt(t-n,e.length),r=e.length-i;s.cbuf.set(e.subarray(0,i),n),s.cpos+=i,r>0&&(s.bufs.push(s.cbuf),s.cbuf=new Uint8Array(oe(t*2,r)),s.cbuf.set(e.subarray(i)),s.cpos=r)},D=(s,e)=>{p(s,e.byteLength),st(s,e)},Bt=(s,e)=>{Vi(s,e);const t=new DataView(s.cbuf.buffer,s.cpos,e);return s.cpos+=e,t},Ki=(s,e)=>Bt(s,4).setFloat32(0,e,!1),Yi=(s,e)=>Bt(s,8).setFloat64(0,e,!1),Ji=(s,e)=>Bt(s,8).setBigInt64(0,e,!1),Ts=new DataView(new ArrayBuffer(4)),Xi=s=>(Ts.setFloat32(0,s),Ts.getFloat32(0)===s),Oe=(s,e)=>{switch(typeof e){case"string":A(s,119),ae(s,e);break;case"number":Fi(e)&&et(e)<=Bi?(A(s,125),Rt(s,e)):Xi(e)?(A(s,124),Ki(s,e)):(A(s,123),Yi(s,e));break;case"bigint":A(s,122),Ji(s,e);break;case"object":if(e===null)A(s,126);else if(pi(e)){A(s,117),p(s,e.length);for(let t=0;t<e.length;t++)Oe(s,e[t])}else if(e instanceof Uint8Array)A(s,116),D(s,e);else{A(s,118);const t=Object.keys(e);p(s,t.length);for(let n=0;n<t.length;n++){const i=t[n];ae(s,i),Oe(s,e[i])}}break;case"boolean":A(s,e?120:121);break;default:A(s,127)}};class Us extends ze{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&p(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const zs=s=>{s.count>0&&(Rt(s.encoder,s.count===1?s.s:-s.s),s.count>1&&p(s.encoder,s.count-2))};class nt{constructor(){this.encoder=new ze,this.s=0,this.count=0}write(e){this.s===e?this.count++:(zs(this),this.count=1,this.s=e)}toUint8Array(){return zs(this),S(this.encoder)}}const Os=s=>{if(s.count>0){const e=s.diff*2+(s.count===1?0:1);Rt(s.encoder,e),s.count>1&&p(s.encoder,s.count-2)}};class Ft{constructor(){this.encoder=new ze,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Os(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Os(this),S(this.encoder)}}class Gi{constructor(){this.sarr=[],this.s="",this.lensE=new nt}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new ze;return this.sarr.push(this.s),this.s="",ae(e,this.sarr.join("")),st(e,this.lensE.toUint8Array()),S(e)}}const X=s=>new Error(s),B=()=>{throw X("Method unimplemented")},F=()=>{throw X("Unexpected case")},Rs=X("Unexpected end of array"),Ns=X("Integer out of Range");class it{constructor(e){this.arr=e,this.pos=0}}const Z=s=>new it(s),Wi=s=>s.pos!==s.arr.length,Pi=(s,e)=>{const t=qt(s.arr.buffer,s.pos+s.arr.byteOffset,e);return s.pos+=e,t},M=s=>Pi(s,k(s)),ye=s=>s.arr[s.pos++],k=s=>{let e=0,t=1;const n=s.arr.length;for(;s.pos<n;){const i=s.arr[s.pos++];if(e=e+(i&ce)*t,t*=128,i<T)return e;if(e>Ms)throw Ns}throw Rs},Vt=s=>{let e=s.arr[s.pos++],t=e&Ut,n=64;const i=(e&J)>0?-1:1;if(!(e&T))return i*t;const r=s.arr.length;for(;s.pos<r;){if(e=s.arr[s.pos++],t=t+(e&ce)*n,n*=128,e<T)return i*t;if(t>Ms)throw Ns}throw Rs},ee=Me?s=>Me.decode(M(s)):s=>{let e=k(s);if(e===0)return"";{let t=String.fromCodePoint(ye(s));if(--e<100)for(;e--;)t+=String.fromCodePoint(ye(s));else for(;e>0;){const n=e<1e4?e:1e4,i=s.arr.subarray(s.pos,s.pos+n);s.pos+=n,t+=String.fromCodePoint.apply(null,i),e-=n}return decodeURIComponent(escape(t))}},Ht=(s,e)=>{const t=new DataView(s.arr.buffer,s.arr.byteOffset+s.pos,e);return s.pos+=e,t},Qi=[s=>{},s=>null,Vt,s=>Ht(s,4).getFloat32(0,!1),s=>Ht(s,8).getFloat64(0,!1),s=>Ht(s,8).getBigInt64(0,!1),s=>!1,s=>!0,ee,s=>{const e=k(s),t={};for(let n=0;n<e;n++){const i=ee(s);t[i]=Re(s)}return t},s=>{const e=k(s),t=[];for(let n=0;n<e;n++)t.push(Re(s));return t},M],Re=s=>Qi[127-ye(s)](s);class Bs extends it{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Wi(this)?this.count=k(this)+1:this.count=-1),this.count--,this.s}}class rt extends it{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=Vt(this);const e=Is(this.s);this.count=1,e&&(this.s=-this.s,this.count=k(this)+2)}return this.count--,this.s}}class $t extends it{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const e=Vt(this),t=e&1;this.diff=Y(e/2),this.count=1,t&&(this.count=k(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Zi{constructor(e){this.decoder=new rt(e),this.str=ee(this.decoder),this.spos=0}read(){const e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}}const Fs=s=>new Uint8Array(s),qt=(s,e,t)=>new Uint8Array(s,e,t),er=s=>new Uint8Array(s),tr=s=>{let e="";for(let t=0;t<s.byteLength;t++)e+=ki(s[t]);return btoa(e)},sr=s=>Buffer.from(s.buffer,s.byteOffset,s.byteLength).toString("base64"),nr=s=>{const e=atob(s),t=Fs(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return t},ir=s=>{const e=Buffer.from(s,"base64");return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)},rr=As?tr:sr,or=As?nr:ir,cr=s=>{const e=Fs(s.byteLength);return e.set(s),e},Vs=new Map;class ar{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:or(t.newValue||"")}),Ei(this._onChange)}postMessage(e){Cs.setItem(this.room,rr(er(e)))}close(){Ci(this._onChange)}}const lr=typeof BroadcastChannel>"u"?ar:BroadcastChannel,Kt=s=>K(Vs,s,()=>{const e=re(),t=new lr(s);return t.onmessage=n=>e.forEach(i=>i(n.data,"broadcastchannel")),{bc:t,subs:e}}),hr=(s,e)=>(Kt(s).subs.add(e),e),ur=(s,e)=>{const t=Kt(s),n=t.subs.delete(e);return n&&t.subs.size===0&&(t.bc.close(),Vs.delete(s)),n},_e=(s,e,t=null)=>{const n=Kt(s);n.bc.postMessage(e),n.subs.forEach(i=>i(e,t))},le=Date.now;class ot{constructor(){this._observers=_()}on(e,t){K(this._observers,e,re).add(t)}once(e,t){const n=(...i)=>{this.off(e,n),t(...i)};this.on(e,n)}off(e,t){const n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return Q((this._observers.get(e)||_()).values()).forEach(n=>n(...t))}destroy(){this._observers=_()}}const dr=crypto.getRandomValues.bind(crypto),Hs=()=>dr(new Uint32Array(1))[0],fr=[1e7]+-1e3+-4e3+-8e3+-1e11,gr=()=>fr.replace(/[018]/g,s=>(s^Hs()&15>>s/4).toString(16)),Se=s=>new Promise(s);Promise.all.bind(Promise);class pr{constructor(e,t){this.left=e,this.right=t}}const G=(s,e)=>new pr(s,e);typeof DOMParser<"u"&&new DOMParser;const kr=s=>di(s,(e,t)=>`${t}:${e};`).join(""),W=Symbol,$s=W(),qs=W(),mr=W(),br=W(),wr=W(),Ks=W(),yr=W(),Ys=W(),_r=W(),Sr=s=>{const e=[];let t=0;for(;t<s.length;t++){const n=s[t];n.constructor===String||n.constructor===Number||n.constructor===Object&&e.push(JSON.stringify(n))}return e},Dr={[$s]:G("font-weight","bold"),[qs]:G("font-weight","normal"),[mr]:G("color","blue"),[wr]:G("color","green"),[br]:G("color","grey"),[Ks]:G("color","red"),[yr]:G("color","purple"),[Ys]:G("color","orange"),[_r]:G("color","black")},Er=Ri?s=>{const e=[],t=[],n=_();let i=[],r=0;for(;r<s.length;r++){const o=s[r],c=Dr[o];if(c!==void 0)n.set(c.left,c.right);else if(o.constructor===String||o.constructor===Number){const a=kr(n);r>0||a.length>0?(e.push("%c"+o),t.push(a)):e.push(o)}else break}for(r>0&&(i=t,i.unshift(e.join("")));r<s.length;r++){const o=s[r];o instanceof Symbol||i.push(o)}return i}:Sr,Cr=(...s)=>{console.log(...Er(s)),vr.forEach(e=>e.print(s))},vr=re(),Js=s=>({[Symbol.iterator](){return this},next:s}),Ar=(s,e)=>Js(()=>{let t;do t=s.next();while(!t.done&&!e(t.value));return t}),Yt=(s,e)=>Js(()=>{const{done:t,value:n}=s.next();return{done:t,value:t?void 0:e(n)}});class Jt{constructor(e,t){this.clock=e,this.len=t}}class Ne{constructor(){this.clients=new Map}}const Xs=(s,e,t)=>e.clients.forEach((n,i)=>{const r=s.doc.store.clients.get(i);for(let o=0;o<n.length;o++){const c=n[o];gn(s,r,c.clock,c.len,t)}}),xr=(s,e)=>{let t=0,n=s.length-1;for(;t<=n;){const i=Y((t+n)/2),r=s[i],o=r.clock;if(o<=e){if(e<o+r.len)return i;t=i+1}else n=i-1}return null},Gs=(s,e)=>{const t=s.clients.get(e.client);return t!==void 0&&xr(t,e.clock)!==null},Xt=s=>{s.clients.forEach(e=>{e.sort((i,r)=>i.clock-r.clock);let t,n;for(t=1,n=1;t<e.length;t++){const i=e[n-1],r=e[t];i.clock+i.len>=r.clock?i.len=oe(i.len,r.clock+r.len-i.clock):(n<t&&(e[n]=r),n++)}e.length=n})},Ir=s=>{const e=new Ne;for(let t=0;t<s.length;t++)s[t].clients.forEach((n,i)=>{if(!e.clients.has(i)){const r=n.slice();for(let o=t+1;o<s.length;o++)gi(r,s[o].clients.get(i)||[]);e.clients.set(i,r)}});return Xt(e),e},ct=(s,e,t,n)=>{K(s.clients,e,()=>[]).push(new Jt(t,n))},Lr=()=>new Ne,jr=s=>{const e=Lr();return s.clients.forEach((t,n)=>{const i=[];for(let r=0;r<t.length;r++){const o=t[r];if(o.deleted){const c=o.id.clock;let a=o.length;if(r+1<t.length)for(let l=t[r+1];r+1<t.length&&l.deleted;l=t[++r+1])a+=l.length;i.push(new Jt(c,a))}}i.length>0&&e.clients.set(n,i)}),e},De=(s,e)=>{p(s.restEncoder,e.clients.size),Q(e.clients.entries()).sort((t,n)=>n[0]-t[0]).forEach(([t,n])=>{s.resetDsCurVal(),p(s.restEncoder,t);const i=n.length;p(s.restEncoder,i);for(let r=0;r<i;r++){const o=n[r];s.writeDsClock(o.clock),s.writeDsLen(o.len)}})},Gt=s=>{const e=new Ne,t=k(s.restDecoder);for(let n=0;n<t;n++){s.resetDsCurVal();const i=k(s.restDecoder),r=k(s.restDecoder);if(r>0){const o=K(e.clients,i,()=>[]);for(let c=0;c<r;c++)o.push(new Jt(s.readDsClock(),s.readDsLen()))}}return e},Ws=(s,e,t)=>{const n=new Ne,i=k(s.restDecoder);for(let r=0;r<i;r++){s.resetDsCurVal();const o=k(s.restDecoder),c=k(s.restDecoder),a=t.clients.get(o)||[],l=x(t,o);for(let h=0;h<c;h++){const u=s.readDsClock(),d=u+s.readDsLen();if(u<l){l<d&&ct(n,o,l,d-l);let f=V(a,u),g=a[f];for(!g.deleted&&g.id.clock<u&&(a.splice(f+1,0,St(e,g,u-g.id.clock)),f++);f<a.length&&(g=a[f++],g.id.clock<d);)g.deleted||(d<g.id.clock+g.length&&a.splice(f,0,St(e,g,d-g.id.clock)),g.delete(e))}else ct(n,o,u,d-u)}}if(n.clients.size>0){const r=new he;return p(r.restEncoder,0),De(r,n),r.toUint8Array()}return null},Ps=Hs;class Ee extends ot{constructor({guid:e=gr(),collectionid:t=null,gc:n=!0,gcFilter:i=()=>!0,meta:r=null,autoLoad:o=!1,shouldLoad:c=!0}={}){super(),this.gc=n,this.gcFilter=i,this.clientID=Ps(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new un,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=o,this.meta=r,this.isLoaded=!1,this.isSynced=!1,this.whenLoaded=Se(l=>{this.on("load",()=>{this.isLoaded=!0,l(this)})});const a=()=>Se(l=>{const h=u=>{(u===void 0||u===!0)&&(this.off("sync",h),l())};this.on("sync",h)});this.on("sync",l=>{l===!1&&this.isSynced&&(this.whenSynced=a()),this.isSynced=l===void 0||l===!0,this.isLoaded||this.emit("load",[])}),this.whenSynced=a()}load(){const e=this._item;e!==null&&!this.shouldLoad&&y(e.parent.doc,t=>{t.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Q(this.subdocs).map(e=>e.guid))}transact(e,t=null){return y(this,e,t)}get(e,t=I){const n=K(this.share,e,()=>{const r=new t;return r._integrate(this,null),r}),i=n.constructor;if(t!==I&&i!==t)if(i===I){const r=new t;r._map=n._map,n._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=r}),r._start=n._start;for(let o=r._start;o!==null;o=o.right)o.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return n}getArray(e=""){return this.get(e,Ae)}getText(e=""){return this.get(e,Ie)}getMap(e=""){return this.get(e,ue)}getXmlFragment(e=""){return this.get(e,de)}toJSON(){const e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){Q(this.subdocs).forEach(t=>t.destroy());const e=this._item;if(e!==null){this._item=null;const t=e.content;t.doc=new Ee({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,y(e.parent.doc,n=>{const i=t.doc;e.deleted||n.subdocsAdded.add(i),n.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}on(e,t){super.on(e,t)}off(e,t){super.off(e,t)}}class Qs{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return k(this.restDecoder)}readDsLen(){return k(this.restDecoder)}}class Zs extends Qs{readLeftID(){return w(k(this.restDecoder),k(this.restDecoder))}readRightID(){return w(k(this.restDecoder),k(this.restDecoder))}readClient(){return k(this.restDecoder)}readInfo(){return ye(this.restDecoder)}readString(){return ee(this.restDecoder)}readParentInfo(){return k(this.restDecoder)===1}readTypeRef(){return k(this.restDecoder)}readLen(){return k(this.restDecoder)}readAny(){return Re(this.restDecoder)}readBuf(){return cr(M(this.restDecoder))}readJSON(){return JSON.parse(ee(this.restDecoder))}readKey(){return ee(this.restDecoder)}}class Mr{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=k(this.restDecoder),this.dsCurrVal}readDsLen(){const e=k(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class Ce extends Mr{constructor(e){super(e),this.keys=[],k(e),this.keyClockDecoder=new $t(M(e)),this.clientDecoder=new rt(M(e)),this.leftClockDecoder=new $t(M(e)),this.rightClockDecoder=new $t(M(e)),this.infoDecoder=new Bs(M(e),ye),this.stringDecoder=new Zi(M(e)),this.parentInfoDecoder=new Bs(M(e),ye),this.typeRefDecoder=new rt(M(e)),this.lenDecoder=new rt(M(e))}readLeftID(){return new ve(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new ve(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 Re(this.restDecoder)}readBuf(){return M(this.restDecoder)}readJSON(){return Re(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{const t=this.stringDecoder.read();return this.keys.push(t),t}}}class en{constructor(){this.restEncoder=j()}toUint8Array(){return S(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){p(this.restEncoder,e)}writeDsLen(e){p(this.restEncoder,e)}}class Be extends en{writeLeftID(e){p(this.restEncoder,e.client),p(this.restEncoder,e.clock)}writeRightID(e){p(this.restEncoder,e.client),p(this.restEncoder,e.clock)}writeClient(e){p(this.restEncoder,e)}writeInfo(e){Ot(this.restEncoder,e)}writeString(e){ae(this.restEncoder,e)}writeParentInfo(e){p(this.restEncoder,e?1:0)}writeTypeRef(e){p(this.restEncoder,e)}writeLen(e){p(this.restEncoder,e)}writeAny(e){Oe(this.restEncoder,e)}writeBuf(e){D(this.restEncoder,e)}writeJSON(e){ae(this.restEncoder,JSON.stringify(e))}writeKey(e){ae(this.restEncoder,e)}}class tn{constructor(){this.restEncoder=j(),this.dsCurrVal=0}toUint8Array(){return S(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,p(this.restEncoder,t)}writeDsLen(e){e===0&&F(),p(this.restEncoder,e-1),this.dsCurrVal+=e}}class he extends tn{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Ft,this.clientEncoder=new nt,this.leftClockEncoder=new Ft,this.rightClockEncoder=new Ft,this.infoEncoder=new Us(Ot),this.stringEncoder=new Gi,this.parentInfoEncoder=new Us(Ot),this.typeRefEncoder=new nt,this.lenEncoder=new nt}toUint8Array(){const e=j();return p(e,0),D(e,this.keyClockEncoder.toUint8Array()),D(e,this.clientEncoder.toUint8Array()),D(e,this.leftClockEncoder.toUint8Array()),D(e,this.rightClockEncoder.toUint8Array()),D(e,S(this.infoEncoder)),D(e,this.stringEncoder.toUint8Array()),D(e,S(this.parentInfoEncoder)),D(e,this.typeRefEncoder.toUint8Array()),D(e,this.lenEncoder.toUint8Array()),st(e,S(this.restEncoder)),S(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){Oe(this.restEncoder,e)}writeBuf(e){D(this.restEncoder,e)}writeJSON(e){Oe(this.restEncoder,e)}writeKey(e){const t=this.keyMap.get(e);t===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}}const Tr=(s,e,t,n)=>{n=oe(n,e[0].id.clock);const i=V(e,n);p(s.restEncoder,e.length-i),s.writeClient(t),p(s.restEncoder,n);const r=e[i];r.write(s,n-r.id.clock);for(let o=i+1;o<e.length;o++)e[o].write(s,0)},Wt=(s,e,t)=>{const n=new Map;t.forEach((i,r)=>{x(e,r)>i&&n.set(r,i)}),lt(e).forEach((i,r)=>{t.has(r)||n.set(r,0)}),p(s.restEncoder,n.size),Q(n.entries()).sort((i,r)=>r[0]-i[0]).forEach(([i,r])=>{Tr(s,e.clients.get(i),i,r)})},Ur=(s,e)=>{const t=_(),n=k(s.restDecoder);for(let i=0;i<n;i++){const r=k(s.restDecoder),o=new Array(r),c=s.readClient();let a=k(s.restDecoder);t.set(c,{i:0,refs:o});for(let l=0;l<r;l++){const h=s.readInfo();switch(tt&h){case 0:{const u=s.readLen();o[l]=new O(w(c,a),u),a+=u;break}case 10:{const u=k(s.restDecoder);o[l]=new R(w(c,a),u),a+=u;break}default:{const u=(h&(J|T))===0,d=new v(w(c,a),null,(h&T)===T?s.readLeftID():null,null,(h&J)===J?s.readRightID():null,u?s.readParentInfo()?e.get(s.readString()):s.readLeftID():null,u&&(h&Ue)===Ue?s.readString():null,Bn(s,h));o[l]=d,a+=d.length}}}}return t},zr=(s,e,t)=>{const n=[];let i=Q(t.keys()).sort((f,g)=>f-g);if(i.length===0)return null;const r=()=>{if(i.length===0)return null;let f=t.get(i[i.length-1]);for(;f.refs.length===f.i;)if(i.pop(),i.length>0)f=t.get(i[i.length-1]);else return null;return f};let o=r();if(o===null&&n.length===0)return null;const c=new un,a=new Map,l=(f,g)=>{const m=a.get(f);(m==null||m>g)&&a.set(f,g)};let h=o.refs[o.i++];const u=new Map,d=()=>{for(const f of n){const g=f.id.client,m=t.get(g);m?(m.i--,c.clients.set(g,m.refs.slice(m.i)),t.delete(g),m.i=0,m.refs=[]):c.clients.set(g,[f]),i=i.filter(U=>U!==g)}n.length=0};for(;;){if(h.constructor!==R){const g=K(u,h.id.client,()=>x(e,h.id.client))-h.id.clock;if(g<0)n.push(h),l(h.id.client,h.id.clock-1),d();else{const m=h.getMissing(s,e);if(m!==null){n.push(h);const U=t.get(m)||{refs:[],i:0};if(U.refs.length===U.i)l(m,x(e,m)),d();else{h=U.refs[U.i++];continue}}else(g===0||g<h.length)&&(h.integrate(s,g),u.set(h.id.client,h.id.clock+h.length))}}if(n.length>0)h=n.pop();else if(o!==null&&o.i<o.refs.length)h=o.refs[o.i++];else{if(o=r(),o===null)break;h=o.refs[o.i++]}}if(c.clients.size>0){const f=new he;return Wt(f,c,new Map),p(f.restEncoder,0),{missing:a,update:f.toUint8Array()}}return null},Or=(s,e)=>Wt(s,e.doc.store,e.beforeState),Rr=(s,e,t,n=new Ce(s))=>y(e,i=>{i.local=!1;let r=!1;const o=i.doc,c=o.store,a=Ur(n,o),l=zr(i,c,a),h=c.pendingStructs;if(h){for(const[d,f]of h.missing)if(f<x(c,d)){r=!0;break}if(l){for(const[d,f]of l.missing){const g=h.missing.get(d);(g==null||g>f)&&h.missing.set(d,f)}h.update=ut([h.update,l.update])}}else c.pendingStructs=l;const u=Ws(n,i,c);if(c.pendingDs){const d=new Ce(Z(c.pendingDs));k(d.restDecoder);const f=Ws(d,i,c);u&&f?c.pendingDs=ut([u,f]):c.pendingDs=u||f}else c.pendingDs=u;if(r){const d=c.pendingStructs.update;c.pendingStructs=null,sn(i.doc,d)}},t,!1),sn=(s,e,t,n=Ce)=>{const i=Z(e);Rr(i,s,t,new n(i))},nn=(s,e,t)=>sn(s,e,t,Zs),Nr=(s,e,t=new Map)=>{Wt(s,e.store,t),De(s,jr(e.store))},Br=(s,e=new Uint8Array([0]),t=new he)=>{const n=rn(e);Nr(t,s,n);const i=[t.toUint8Array()];if(s.store.pendingDs&&i.push(s.store.pendingDs),s.store.pendingStructs&&i.push(Zr(s.store.pendingStructs.update,e)),i.length>1){if(t.constructor===Be)return Pr(i.map((r,o)=>o===0?r:to(r)));if(t.constructor===he)return ut(i)}return i[0]},Pt=(s,e)=>Br(s,e,new Be),Fr=s=>{const e=new Map,t=k(s.restDecoder);for(let n=0;n<t;n++){const i=k(s.restDecoder),r=k(s.restDecoder);e.set(i,r)}return e},rn=s=>Fr(new Qs(Z(s))),on=(s,e)=>(p(s.restEncoder,e.size),Q(e.entries()).sort((t,n)=>n[0]-t[0]).forEach(([t,n])=>{p(s.restEncoder,t),p(s.restEncoder,n)}),s),Vr=(s,e)=>on(s,lt(e.store)),Hr=(s,e=new tn)=>(s instanceof Map?on(e,s):Vr(e,s),e.toUint8Array()),$r=s=>Hr(s,new en);class qr{constructor(){this.l=[]}}const cn=()=>new qr,an=(s,e)=>s.l.push(e),ln=(s,e)=>{const t=s.l,n=t.length;s.l=t.filter(i=>e!==i),n===s.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},hn=(s,e,t)=>xt(s.l,[e,t]);class ve{constructor(e,t){this.client=e,this.clock=t}}const at=(s,e)=>s===e||s!==null&&e!==null&&s.client===e.client&&s.clock===e.clock,w=(s,e)=>new ve(s,e),Kr=s=>{for(const[e,t]of s.doc.share.entries())if(t===s)return e;throw F()},Fe=(s,e)=>e===void 0?!s.deleted:e.sv.has(s.id.client)&&(e.sv.get(s.id.client)||0)>s.id.clock&&!Gs(e.ds,s.id),Qt=(s,e)=>{const t=K(s.meta,Qt,re),n=s.doc.store;t.has(e)||(e.sv.forEach((i,r)=>{i<x(n,r)&&te(s,w(r,i))}),Xs(s,e.ds,i=>{}),t.add(e))};class un{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const lt=s=>{const e=new Map;return s.clients.forEach((t,n)=>{const i=t[t.length-1];e.set(n,i.id.clock+i.length)}),e},x=(s,e)=>{const t=s.clients.get(e);if(t===void 0)return 0;const n=t[t.length-1];return n.id.clock+n.length},dn=(s,e)=>{let t=s.clients.get(e.id.client);if(t===void 0)t=[],s.clients.set(e.id.client,t);else{const n=t[t.length-1];if(n.id.clock+n.length!==e.id.clock)throw F()}t.push(e)},V=(s,e)=>{let t=0,n=s.length-1,i=s[n],r=i.id.clock;if(r===e)return n;let o=Y(e/(r+i.length-1)*n);for(;t<=n;){if(i=s[o],r=i.id.clock,r<=e){if(e<r+i.length)return o;t=o+1}else n=o-1;o=Y((t+n)/2)}throw F()},Zt=(s,e)=>{const t=s.clients.get(e.client);return t[V(t,e.clock)]},es=(s,e,t)=>{const n=V(e,t),i=e[n];return i.id.clock<t&&i instanceof v?(e.splice(n+1,0,St(s,i,t-i.id.clock)),n+1):n},te=(s,e)=>{const t=s.doc.store.clients.get(e.client);return t[es(s,t,e.clock)]},fn=(s,e,t)=>{const n=e.clients.get(t.client),i=V(n,t.clock),r=n[i];return t.clock!==r.id.clock+r.length-1&&r.constructor!==O&&n.splice(i+1,0,St(s,r,t.clock-r.id.clock+1)),r},Yr=(s,e,t)=>{const n=s.clients.get(e.id.client);n[V(n,e.id.clock)]=t},gn=(s,e,t,n,i)=>{if(n===0)return;const r=t+n;let o=es(s,e,t),c;do c=e[o++],r<c.id.clock+c.length&&es(s,e,r),i(c);while(o<e.length&&e[o].id.clock<r)};class Jr{constructor(e,t,n){this.doc=e,this.deleteSet=new Ne,this.beforeState=lt(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const pn=(s,e)=>e.deleteSet.clients.size===0&&!fi(e.afterState,(t,n)=>e.beforeState.get(n)!==t)?!1:(Xt(e.deleteSet),Or(s,e),De(s,e.deleteSet),!0),kn=(s,e,t)=>{const n=e._item;(n===null||n.id.clock<(s.beforeState.get(n.id.client)||0)&&!n.deleted)&&K(s.changed,e,re).add(t)},ht=(s,e)=>{let t=s[e],n=s[e-1],i=e;for(;i>0;t=n,n=s[--i-1]){if(n.deleted===t.deleted&&n.constructor===t.constructor&&n.mergeWith(t)){t instanceof v&&t.parentSub!==null&&t.parent._map.get(t.parentSub)===t&&t.parent._map.set(t.parentSub,n);continue}break}const r=e-i;return r&&s.splice(e+1-r,r),r},Xr=(s,e,t)=>{for(const[n,i]of s.clients.entries()){const r=e.clients.get(n);for(let o=i.length-1;o>=0;o--){const c=i[o],a=c.clock+c.len;for(let l=V(r,c.clock),h=r[l];l<r.length&&h.id.clock<a;h=r[++l]){const u=r[l];if(c.clock+c.len<=u.id.clock)break;u instanceof v&&u.deleted&&!u.keep&&t(u)&&u.gc(e,!1)}}}},Gr=(s,e)=>{s.clients.forEach((t,n)=>{const i=e.clients.get(n);for(let r=t.length-1;r>=0;r--){const o=t[r],c=jt(i.length-1,1+V(i,o.clock+o.len-1));for(let a=c,l=i[a];a>0&&l.id.clock>=o.clock;l=i[a])a-=1+ht(i,a)}})},mn=(s,e)=>{if(e<s.length){const t=s[e],n=t.doc,i=n.store,r=t.deleteSet,o=t._mergeStructs;try{Xt(r),t.afterState=lt(t.doc.store),n.emit("beforeObserverCalls",[t,n]);const c=[];t.changed.forEach((a,l)=>c.push(()=>{(l._item===null||!l._item.deleted)&&l._callObserver(t,a)})),c.push(()=>{t.changedParentTypes.forEach((a,l)=>{l._dEH.l.length>0&&(l._item===null||!l._item.deleted)&&(a=a.filter(h=>h.target._item===null||!h.target._item.deleted),a.forEach(h=>{h.currentTarget=l,h._path=null}),a.sort((h,u)=>h.path.length-u.path.length),hn(l._dEH,a,t))})}),c.push(()=>n.emit("afterTransaction",[t,n])),xt(c,[]),t._needFormattingCleanup&&po(t)}finally{n.gc&&Xr(r,i,n.gcFilter),Gr(r,i),t.afterState.forEach((h,u)=>{const d=t.beforeState.get(u)||0;if(d!==h){const f=i.clients.get(u),g=oe(V(f,d),1);for(let m=f.length-1;m>=g;)m-=1+ht(f,m)}});for(let h=o.length-1;h>=0;h--){const{client:u,clock:d}=o[h].id,f=i.clients.get(u),g=V(f,d);g+1<f.length&&ht(f,g+1)>1||g>0&&ht(f,g)}if(!t.local&&t.afterState.get(n.clientID)!==t.beforeState.get(n.clientID)&&(Cr(Ys,$s,"[yjs] ",qs,Ks,"Changed the client-id because another client seems to be using it."),n.clientID=Ps()),n.emit("afterTransactionCleanup",[t,n]),n._observers.has("update")){const h=new Be;pn(h,t)&&n.emit("update",[h.toUint8Array(),t.origin,n,t])}if(n._observers.has("updateV2")){const h=new he;pn(h,t)&&n.emit("updateV2",[h.toUint8Array(),t.origin,n,t])}const{subdocsAdded:c,subdocsLoaded:a,subdocsRemoved:l}=t;(c.size>0||l.size>0||a.size>0)&&(c.forEach(h=>{h.clientID=n.clientID,h.collectionid==null&&(h.collectionid=n.collectionid),n.subdocs.add(h)}),l.forEach(h=>n.subdocs.delete(h)),n.emit("subdocs",[{loaded:a,added:c,removed:l},n,t]),l.forEach(h=>h.destroy())),s.length<=e+1?(n._transactionCleanups=[],n.emit("afterAllTransactions",[n,s])):mn(s,e+1)}}},y=(s,e,t=null,n=!0)=>{const i=s._transactionCleanups;let r=!1,o=null;s._transaction===null&&(r=!0,s._transaction=new Jr(s,t,n),i.push(s._transaction),i.length===1&&s.emit("beforeAllTransactions",[s]),s.emit("beforeTransaction",[s._transaction,s]));try{o=e(s._transaction)}finally{if(r){const c=s._transaction===i[0];s._transaction=null,c&&mn(i,0)}}return o};function*Wr(s){const e=k(s.restDecoder);for(let t=0;t<e;t++){const n=k(s.restDecoder),i=s.readClient();let r=k(s.restDecoder);for(let o=0;o<n;o++){const c=s.readInfo();if(c===10){const a=k(s.restDecoder);yield new R(w(i,r),a),r+=a}else if(tt&c){const a=(c&(J|T))===0,l=new v(w(i,r),null,(c&T)===T?s.readLeftID():null,null,(c&J)===J?s.readRightID():null,a?s.readParentInfo()?s.readString():s.readLeftID():null,a&&(c&Ue)===Ue?s.readString():null,Bn(s,c));yield l,r+=l.length}else{const a=s.readLen();yield new O(w(i,r),a),r+=a}}}}class ts{constructor(e,t){this.gen=Wr(e),this.curr=null,this.done=!1,this.filterSkips=t,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===R);return this.curr}}class ss{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}}const Pr=s=>ut(s,Zs,Be),Qr=(s,e)=>{if(s.constructor===O){const{client:t,clock:n}=s.id;return new O(w(t,n+e),s.length-e)}else if(s.constructor===R){const{client:t,clock:n}=s.id;return new R(w(t,n+e),s.length-e)}else{const t=s,{client:n,clock:i}=t.id;return new v(w(n,i+e),null,w(n,i+e-1),null,t.rightOrigin,t.parent,t.parentSub,t.content.splice(e))}},ut=(s,e=Ce,t=he)=>{if(s.length===1)return s[0];const n=s.map(h=>new e(Z(h)));let i=n.map(h=>new ts(h,!0)),r=null;const o=new t,c=new ss(o);for(;i=i.filter(d=>d.curr!==null),i.sort((d,f)=>{if(d.curr.id.client===f.curr.id.client){const g=d.curr.id.clock-f.curr.id.clock;return g===0?d.curr.constructor===f.curr.constructor?0:d.curr.constructor===R?1:-1:g}else return f.curr.id.client-d.curr.id.client}),i.length!==0;){const h=i[0],u=h.curr.id.client;if(r!==null){let d=h.curr,f=!1;for(;d!==null&&d.id.clock+d.length<=r.struct.id.clock+r.struct.length&&d.id.client>=r.struct.id.client;)d=h.next(),f=!0;if(d===null||d.id.client!==u||f&&d.id.clock>r.struct.id.clock+r.struct.length)continue;if(u!==r.struct.id.client)se(c,r.struct,r.offset),r={struct:d,offset:0},h.next();else if(r.struct.id.clock+r.struct.length<d.id.clock)if(r.struct.constructor===R)r.struct.length=d.id.clock+d.length-r.struct.id.clock;else{se(c,r.struct,r.offset);const g=d.id.clock-r.struct.id.clock-r.struct.length;r={struct:new R(w(u,r.struct.id.clock+r.struct.length),g),offset:0}}else{const g=r.struct.id.clock+r.struct.length-d.id.clock;g>0&&(r.struct.constructor===R?r.struct.length-=g:d=Qr(d,g)),r.struct.mergeWith(d)||(se(c,r.struct,r.offset),r={struct:d,offset:0},h.next())}}else r={struct:h.curr,offset:0},h.next();for(let d=h.curr;d!==null&&d.id.client===u&&d.id.clock===r.struct.id.clock+r.struct.length&&d.constructor!==R;d=h.next())se(c,r.struct,r.offset),r={struct:d,offset:0}}r!==null&&(se(c,r.struct,r.offset),r=null),ns(c);const a=n.map(h=>Gt(h)),l=Ir(a);return De(o,l),o.toUint8Array()},Zr=(s,e,t=Ce,n=he)=>{const i=rn(e),r=new n,o=new ss(r),c=new t(Z(s)),a=new ts(c,!1);for(;a.curr;){const h=a.curr,u=h.id.client,d=i.get(u)||0;if(a.curr.constructor===R){a.next();continue}if(h.id.clock+h.length>d)for(se(o,h,oe(d-h.id.clock,0)),a.next();a.curr&&a.curr.id.client===u;)se(o,a.curr,0),a.next();else for(;a.curr&&a.curr.id.client===u&&a.curr.id.clock+a.curr.length<=d;)a.next()}ns(o);const l=Gt(c);return De(r,l),r.toUint8Array()},bn=s=>{s.written>0&&(s.clientStructs.push({written:s.written,restEncoder:S(s.encoder.restEncoder)}),s.encoder.restEncoder=j(),s.written=0)},se=(s,e,t)=>{s.written>0&&s.currClient!==e.id.client&&bn(s),s.written===0&&(s.currClient=e.id.client,s.encoder.writeClient(e.id.client),p(s.encoder.restEncoder,e.id.clock+t)),e.write(s.encoder,t),s.written++},ns=s=>{bn(s);const e=s.encoder.restEncoder;p(e,s.clientStructs.length);for(let t=0;t<s.clientStructs.length;t++){const n=s.clientStructs[t];p(e,n.written),st(e,n.restEncoder)}},eo=(s,e,t,n)=>{const i=new t(Z(s)),r=new ts(i,!1),o=new n,c=new ss(o);for(let l=r.curr;l!==null;l=r.next())se(c,e(l),0);ns(c);const a=Gt(i);return De(o,a),o.toUint8Array()},to=s=>eo(s,Ti,Ce,Be),wn="You must not compute changes after the event-handler fired.";class dt{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=so(this.currentTarget,this.target))}deletes(e){return Gs(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw X(wn);const e=new Map,t=this.target;this.transaction.changed.get(t).forEach(i=>{if(i!==null){const r=t._map.get(i);let o,c;if(this.adds(r)){let a=r.left;for(;a!==null&&this.adds(a);)a=a.left;if(this.deletes(r))if(a!==null&&this.deletes(a))o="delete",c=vt(a.content.getContent());else return;else a!==null&&this.deletes(a)?(o="update",c=vt(a.content.getContent())):(o="add",c=void 0)}else if(this.deletes(r))o="delete",c=vt(r.content.getContent());else return;e.set(i,{action:o,oldValue:c})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw X(wn);const t=this.target,n=re(),i=re(),r=[];if(e={added:n,deleted:i,delta:r,keys:this.keys},this.transaction.changed.get(t).has(null)){let c=null;const a=()=>{c&&r.push(c)};for(let l=t._start;l!==null;l=l.right)l.deleted?this.deletes(l)&&!this.adds(l)&&((c===null||c.delete===void 0)&&(a(),c={delete:0}),c.delete+=l.length,i.add(l)):this.adds(l)?((c===null||c.insert===void 0)&&(a(),c={insert:[]}),c.insert=c.insert.concat(l.content.getContent()),n.add(l)):((c===null||c.retain===void 0)&&(a(),c={retain:0}),c.retain+=l.length);c!==null&&c.retain===void 0&&a()}this._changes=e}return e}}const so=(s,e)=>{const t=[];for(;e._item!==null&&e!==s;){if(e._item.parentSub!==null)t.unshift(e._item.parentSub);else{let n=0,i=e._item.parent._start;for(;i!==e._item&&i!==null;)i.deleted||n++,i=i.right;t.unshift(n)}e=e._item.parent}return t},yn=80;let is=0;class no{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=is++}}const io=s=>{s.timestamp=is++},_n=(s,e,t)=>{s.p.marker=!1,s.p=e,e.marker=!0,s.index=t,s.timestamp=is++},ro=(s,e,t)=>{if(s.length>=yn){const n=s.reduce((i,r)=>i.timestamp<r.timestamp?i:r);return _n(n,e,t),n}else{const n=new no(e,t);return s.push(n),n}},ft=(s,e)=>{if(s._start===null||e===0||s._searchMarker===null)return null;const t=s._searchMarker.length===0?null:s._searchMarker.reduce((r,o)=>et(e-r.index)<et(e-o.index)?r:o);let n=s._start,i=0;for(t!==null&&(n=t.p,i=t.index,io(t));n.right!==null&&i<e;){if(!n.deleted&&n.countable){if(e<i+n.length)break;i+=n.length}n=n.right}for(;n.left!==null&&i>e;)n=n.left,!n.deleted&&n.countable&&(i-=n.length);for(;n.left!==null&&n.left.id.client===n.id.client&&n.left.id.clock+n.left.length===n.id.clock;)n=n.left,!n.deleted&&n.countable&&(i-=n.length);return t!==null&&et(t.index-i)<n.parent.length/yn?(_n(t,n,i),t):ro(s._searchMarker,n,i)},Ve=(s,e,t)=>{for(let n=s.length-1;n>=0;n--){const i=s[n];if(t>0){let r=i.p;for(r.marker=!1;r&&(r.deleted||!r.countable);)r=r.left,r&&!r.deleted&&r.countable&&(i.index-=r.length);if(r===null||r.marker===!0){s.splice(n,1);continue}i.p=r,r.marker=!0}(e<i.index||t>0&&e===i.index)&&(i.index=oe(e,i.index+t))}},gt=(s,e,t)=>{const n=s,i=e.changedParentTypes;for(;K(i,s,()=>[]).push(t),s._item!==null;)s=s._item.parent;hn(n._eH,t,e)};class I{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=cn(),this._dEH=cn(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw B()}clone(){throw B()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){an(this._eH,e)}observeDeep(e){an(this._dEH,e)}unobserve(e){ln(this._eH,e)}unobserveDeep(e){ln(this._dEH,e)}toJSON(){}}const Sn=(s,e,t)=>{e<0&&(e=s._length+e),t<0&&(t=s._length+t);let n=t-e;const i=[];let r=s._start;for(;r!==null&&n>0;){if(r.countable&&!r.deleted){const o=r.content.getContent();if(o.length<=e)e-=o.length;else{for(let c=e;c<o.length&&n>0;c++)i.push(o[c]),n--;e=0}}r=r.right}return i},Dn=s=>{const e=[];let t=s._start;for(;t!==null;){if(t.countable&&!t.deleted){const n=t.content.getContent();for(let i=0;i<n.length;i++)e.push(n[i])}t=t.right}return e},He=(s,e)=>{let t=0,n=s._start;for(;n!==null;){if(n.countable&&!n.deleted){const i=n.content.getContent();for(let r=0;r<i.length;r++)e(i[r],t++,s)}n=n.right}},En=(s,e)=>{const t=[];return He(s,(n,i)=>{t.push(e(n,i,s))}),t},oo=s=>{let e=s._start,t=null,n=0;return{[Symbol.iterator](){return this},next:()=>{if(t===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};t=e.content.getContent(),n=0,e=e.right}const i=t[n++];return t.length<=n&&(t=null),{done:!1,value:i}}}},Cn=(s,e)=>{const t=ft(s,e);let n=s._start;for(t!==null&&(n=t.p,e-=t.index);n!==null;n=n.right)if(!n.deleted&&n.countable){if(e<n.length)return n.content.getContent()[e];e-=n.length}},pt=(s,e,t,n)=>{let i=t;const r=s.doc,o=r.clientID,c=r.store,a=t===null?e._start:t.right;let l=[];const h=()=>{l.length>0&&(i=new v(w(o,x(c,o)),i,i&&i.lastId,a,a&&a.id,e,null,new ge(l)),i.integrate(s,0),l=[])};n.forEach(u=>{if(u===null)l.push(u);else switch(u.constructor){case Number:case Object:case Boolean:case Array:case String:l.push(u);break;default:switch(h(),u.constructor){case Uint8Array:case ArrayBuffer:i=new v(w(o,x(c,o)),i,i&&i.lastId,a,a&&a.id,e,null,new qe(new Uint8Array(u))),i.integrate(s,0);break;case Ee:i=new v(w(o,x(c,o)),i,i&&i.lastId,a,a&&a.id,e,null,new Ye(u)),i.integrate(s,0);break;default:if(u instanceof I)i=new v(w(o,x(c,o)),i,i&&i.lastId,a,a&&a.id,e,null,new P(u)),i.integrate(s,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},vn=X("Length exceeded!"),An=(s,e,t,n)=>{if(t>e._length)throw vn;if(t===0)return e._searchMarker&&Ve(e._searchMarker,t,n.length),pt(s,e,null,n);const i=t,r=ft(e,t);let o=e._start;for(r!==null&&(o=r.p,t-=r.index,t===0&&(o=o.prev,t+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(t<=o.length){t<o.length&&te(s,w(o.id.client,o.id.clock+t));break}t-=o.length}return e._searchMarker&&Ve(e._searchMarker,i,n.length),pt(s,e,o,n)},co=(s,e,t)=>{let i=(e._searchMarker||[]).reduce((r,o)=>o.index>r.index?o:r,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return pt(s,e,i,t)},xn=(s,e,t,n)=>{if(n===0)return;const i=t,r=n,o=ft(e,t);let c=e._start;for(o!==null&&(c=o.p,t-=o.index);c!==null&&t>0;c=c.right)!c.deleted&&c.countable&&(t<c.length&&te(s,w(c.id.client,c.id.clock+t)),t-=c.length);for(;n>0&&c!==null;)c.deleted||(n<c.length&&te(s,w(c.id.client,c.id.clock+n)),c.delete(s),n-=c.length),c=c.right;if(n>0)throw vn;e._searchMarker&&Ve(e._searchMarker,i,-r+n)},kt=(s,e,t)=>{const n=e._map.get(t);n!==void 0&&n.delete(s)},rs=(s,e,t,n)=>{const i=e._map.get(t)||null,r=s.doc,o=r.clientID;let c;if(n==null)c=new ge([n]);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:c=new ge([n]);break;case Uint8Array:c=new qe(n);break;case Ee:c=new Ye(n);break;default:if(n instanceof I)c=new P(n);else throw new Error("Unexpected content type")}new v(w(o,x(r.store,o)),i,i&&i.lastId,null,null,e,t,c).integrate(s,0)},os=(s,e)=>{const t=s._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},In=s=>{const e={};return s._map.forEach((t,n)=>{t.deleted||(e[n]=t.content.getContent()[t.length-1])}),e},Ln=(s,e)=>{const t=s._map.get(e);return t!==void 0&&!t.deleted},mt=s=>Ar(s.entries(),e=>!e[1].deleted);class ao extends dt{constructor(e,t){super(e,t),this._transaction=t}}class Ae extends I{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const t=new Ae;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Ae}clone(){const e=new Ae;return e.insert(0,this.toArray().map(t=>t instanceof I?t.clone():t)),e}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}_callObserver(e,t){super._callObserver(e,t),gt(this,e,new ao(this,e))}insert(e,t){this.doc!==null?y(this.doc,n=>{An(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?y(this.doc,t=>{co(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?y(this.doc,n=>{xn(n,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return Cn(this,e)}toArray(){return Dn(this)}slice(e=0,t=this.length){return Sn(this,e,t)}toJSON(){return this.map(e=>e instanceof I?e.toJSON():e)}map(e){return En(this,e)}forEach(e){He(this,e)}[Symbol.iterator](){return oo(this)}_write(e){e.writeTypeRef(To)}}const lo=s=>new Ae;class ho extends dt{constructor(e,t,n){super(e,t),this.keysChanged=n}}class ue extends I{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((n,i)=>{this.set(i,n)}),this._prelimContent=null}_copy(){return new ue}clone(){const e=new ue;return this.forEach((t,n)=>{e.set(n,t instanceof I?t.clone():t)}),e}_callObserver(e,t){gt(this,e,new ho(this,e,t))}toJSON(){const e={};return this._map.forEach((t,n)=>{if(!t.deleted){const i=t.content.getContent()[t.length-1];e[n]=i instanceof I?i.toJSON():i}}),e}get size(){return[...mt(this._map)].length}keys(){return Yt(mt(this._map),e=>e[0])}values(){return Yt(mt(this._map),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Yt(mt(this._map),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?y(this.doc,t=>{kt(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?y(this.doc,n=>{rs(n,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return os(this,e)}has(e){return Ln(this,e)}clear(){this.doc!==null?y(this.doc,e=>{this.forEach(function(t,n,i){kt(e,i,n)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(Uo)}}const uo=s=>new ue,ne=(s,e)=>s===e||typeof s=="object"&&typeof e=="object"&&s&&e&&Mi(s,e);class cs{constructor(e,t,n,i){this.left=e,this.right=t,this.index=n,this.currentAttributes=i}forward(){switch(this.right===null&&F(),this.right.content.constructor){case C:this.right.deleted||xe(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 jn=(s,e,t)=>{for(;e.right!==null&&t>0;){switch(e.right.content.constructor){case C:e.right.deleted||xe(e.currentAttributes,e.right.content);break;default:e.right.deleted||(t<e.right.length&&te(s,w(e.right.id.client,e.right.id.clock+t)),e.index+=e.right.length,t-=e.right.length);break}e.left=e.right,e.right=e.right.right}return e},bt=(s,e,t)=>{const n=new Map,i=ft(e,t);if(i){const r=new cs(i.p.left,i.p,i.index,n);return jn(s,r,t-i.index)}else{const r=new cs(null,e._start,0,n);return jn(s,r,t)}},Mn=(s,e,t,n)=>{for(;t.right!==null&&(t.right.deleted===!0||t.right.content.constructor===C&&ne(n.get(t.right.content.key),t.right.content.value));)t.right.deleted||n.delete(t.right.content.key),t.forward();const i=s.doc,r=i.clientID;n.forEach((o,c)=>{const a=t.left,l=t.right,h=new v(w(r,x(i.store,r)),a,a&&a.lastId,l,l&&l.id,e,null,new C(c,o));h.integrate(s,0),t.right=h,t.forward()})},xe=(s,e)=>{const{key:t,value:n}=e;n===null?s.delete(t):s.set(t,n)},Tn=(s,e)=>{for(;s.right!==null;){if(!(s.right.deleted||s.right.content.constructor===C&&ne(e[s.right.content.key]||null,s.right.content.value)))break;s.forward()}},Un=(s,e,t,n)=>{const i=s.doc,r=i.clientID,o=new Map;for(const c in n){const a=n[c],l=t.currentAttributes.get(c)||null;if(!ne(l,a)){o.set(c,l);const{left:h,right:u}=t;t.right=new v(w(r,x(i.store,r)),h,h&&h.lastId,u,u&&u.id,e,null,new C(c,a)),t.right.integrate(s,0),t.forward()}}return o},as=(s,e,t,n,i)=>{t.currentAttributes.forEach((d,f)=>{i[f]===void 0&&(i[f]=null)});const r=s.doc,o=r.clientID;Tn(t,i);const c=Un(s,e,t,i),a=n.constructor===String?new H(n):n instanceof I?new P(n):new fe(n);let{left:l,right:h,index:u}=t;e._searchMarker&&Ve(e._searchMarker,t.index,a.getLength()),h=new v(w(o,x(r.store,o)),l,l&&l.lastId,h,h&&h.id,e,null,a),h.integrate(s,0),t.right=h,t.index=u,t.forward(),Mn(s,e,t,c)},zn=(s,e,t,n,i)=>{const r=s.doc,o=r.clientID;Tn(t,i);const c=Un(s,e,t,i);e:for(;t.right!==null&&(n>0||c.size>0&&(t.right.deleted||t.right.content.constructor===C));){if(!t.right.deleted)switch(t.right.content.constructor){case C:{const{key:a,value:l}=t.right.content,h=i[a];if(h!==void 0){if(ne(h,l))c.delete(a);else{if(n===0)break e;c.set(a,l)}t.right.delete(s)}else t.currentAttributes.set(a,l);break}default:n<t.right.length&&te(s,w(t.right.id.client,t.right.id.clock+n)),n-=t.right.length;break}t.forward()}if(n>0){let a="";for(;n>0;n--)a+=`
2
+ `;t.right=new v(w(o,x(r.store,o)),t.left,t.left&&t.left.lastId,t.right,t.right&&t.right.id,e,null,new H(a)),t.right.integrate(s,0),t.forward()}Mn(s,e,t,c)},On=(s,e,t,n,i)=>{let r=e;const o=_();for(;r&&(!r.countable||r.deleted);){if(!r.deleted&&r.content.constructor===C){const l=r.content;o.set(l.key,l)}r=r.right}let c=0,a=!1;for(;e!==r;){if(t===e&&(a=!0),!e.deleted){const l=e.content;switch(l.constructor){case C:{const{key:h,value:u}=l,d=n.get(h)||null;(o.get(h)!==l||d===u)&&(e.delete(s),c++,!a&&(i.get(h)||null)===u&&d!==u&&(d===null?i.delete(h):i.set(h,d))),!a&&!e.deleted&&xe(i,l);break}}}e=e.right}return c},fo=(s,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;const t=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===C){const n=e.content.key;t.has(n)?e.delete(s):t.add(n)}e=e.left}},go=s=>{let e=0;return y(s.doc,t=>{let n=s._start,i=s._start,r=_();const o=q(r);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case C:xe(o,i.content);break;default:e+=On(t,n,i,r,o),r=q(o),n=i;break}i=i.right}}),e},po=s=>{const e=new Set,t=s.doc;for(const[n,i]of s.afterState.entries()){const r=s.beforeState.get(n)||0;i!==r&&gn(s,t.store.clients.get(n),r,i,o=>{!o.deleted&&o.content.constructor===C&&o.constructor!==O&&e.add(o.parent)})}y(t,n=>{Xs(s,s.deleteSet,i=>{if(i instanceof O||!i.parent._hasFormatting||e.has(i.parent))return;const r=i.parent;i.content.constructor===C?e.add(r):fo(n,i)});for(const i of e)go(i)})},Rn=(s,e,t)=>{const n=t,i=q(e.currentAttributes),r=e.right;for(;t>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case P:case fe:case H:t<e.right.length&&te(s,w(e.right.id.client,e.right.id.clock+t)),t-=e.right.length,e.right.delete(s);break}e.forward()}r&&On(s,r,e.right,i,e.currentAttributes);const o=(e.left||e.right).parent;return o._searchMarker&&Ve(o._searchMarker,e.index,-n+t),e};class ko extends dt{constructor(e,t,n){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,n.forEach(i=>{i===null?this.childListChanged=!0:this.keysChanged.add(i)})}get changes(){if(this._changes===null){const e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){const e=this.target.doc,t=[];y(e,n=>{const i=new Map,r=new Map;let o=this.target._start,c=null;const a={};let l="",h=0,u=0;const d=()=>{if(c!==null){let f=null;switch(c){case"delete":u>0&&(f={delete:u}),u=0;break;case"insert":(typeof l=="object"||l.length>0)&&(f={insert:l},i.size>0&&(f.attributes={},i.forEach((g,m)=>{g!==null&&(f.attributes[m]=g)}))),l="";break;case"retain":h>0&&(f={retain:h},Li(a)||(f.attributes=vi({},a))),h=0;break}f&&t.push(f),c=null}};for(;o!==null;){switch(o.content.constructor){case P:case fe:this.adds(o)?this.deletes(o)||(d(),c="insert",l=o.content.getContent()[0],d()):this.deletes(o)?(c!=="delete"&&(d(),c="delete"),u+=1):o.deleted||(c!=="retain"&&(d(),c="retain"),h+=1);break;case H:this.adds(o)?this.deletes(o)||(c!=="insert"&&(d(),c="insert"),l+=o.content.str):this.deletes(o)?(c!=="delete"&&(d(),c="delete"),u+=o.length):o.deleted||(c!=="retain"&&(d(),c="retain"),h+=o.length);break;case C:{const{key:f,value:g}=o.content;if(this.adds(o)){if(!this.deletes(o)){const m=i.get(f)||null;ne(m,g)?g!==null&&o.delete(n):(c==="retain"&&d(),ne(g,r.get(f)||null)?delete a[f]:a[f]=g)}}else if(this.deletes(o)){r.set(f,g);const m=i.get(f)||null;ne(m,g)||(c==="retain"&&d(),a[f]=m)}else if(!o.deleted){r.set(f,g);const m=a[f];m!==void 0&&(ne(m,g)?m!==null&&o.delete(n):(c==="retain"&&d(),g===null?delete a[f]:a[f]=g))}o.deleted||(c==="insert"&&d(),xe(i,o.content));break}}o=o.right}for(d();t.length>0;){const f=t[t.length-1];if(f.retain!==void 0&&f.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}}class Ie extends I{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(n=>n())}catch(n){console.error(n)}this._pending=null}_copy(){return new Ie}clone(){const e=new Ie;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);const n=new ko(this,e,t);gt(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){let e="",t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===H&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc!==null?y(this.doc,n=>{const i=new cs(null,this._start,0,new Map);for(let r=0;r<e.length;r++){const o=e[r];if(o.insert!==void 0){const c=!t&&typeof o.insert=="string"&&r===e.length-1&&i.right===null&&o.insert.slice(-1)===`
3
+ `?o.insert.slice(0,-1):o.insert;(typeof c!="string"||c.length>0)&&as(n,this,i,c,o.attributes||{})}else o.retain!==void 0?zn(n,this,i,o.retain,o.attributes||{}):o.delete!==void 0&&Rn(n,i,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,n){const i=[],r=new Map,o=this.doc;let c="",a=this._start;function l(){if(c.length>0){const u={};let d=!1;r.forEach((g,m)=>{d=!0,u[m]=g});const f={insert:c};d&&(f.attributes=u),i.push(f),c=""}}const h=()=>{for(;a!==null;){if(Fe(a,e)||t!==void 0&&Fe(a,t))switch(a.content.constructor){case H:{const u=r.get("ychange");e!==void 0&&!Fe(a,e)?(u===void 0||u.user!==a.id.client||u.type!=="removed")&&(l(),r.set("ychange",n?n("removed",a.id):{type:"removed"})):t!==void 0&&!Fe(a,t)?(u===void 0||u.user!==a.id.client||u.type!=="added")&&(l(),r.set("ychange",n?n("added",a.id):{type:"added"})):u!==void 0&&(l(),r.delete("ychange")),c+=a.content.str;break}case P:case fe:{l();const u={insert:a.content.getContent()[0]};if(r.size>0){const d={};u.attributes=d,r.forEach((f,g)=>{d[g]=f})}i.push(u);break}case C:Fe(a,e)&&(l(),xe(r,a.content));break}a=a.right}l()};return e||t?y(o,u=>{e&&Qt(u,e),t&&Qt(u,t),h()},"cleanup"):h(),i}insert(e,t,n){if(t.length<=0)return;const i=this.doc;i!==null?y(i,r=>{const o=bt(r,this,e);n||(n={},o.currentAttributes.forEach((c,a)=>{n[a]=c})),as(r,this,o,t,n)}):this._pending.push(()=>this.insert(e,t,n))}insertEmbed(e,t,n={}){const i=this.doc;i!==null?y(i,r=>{const o=bt(r,this,e);as(r,this,o,t,n)}):this._pending.push(()=>this.insertEmbed(e,t,n))}delete(e,t){if(t===0)return;const n=this.doc;n!==null?y(n,i=>{Rn(i,bt(i,this,e),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,n){if(t===0)return;const i=this.doc;i!==null?y(i,r=>{const o=bt(r,this,e);o.right!==null&&zn(r,this,o,t,n)}):this._pending.push(()=>this.format(e,t,n))}removeAttribute(e){this.doc!==null?y(this.doc,t=>{kt(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?y(this.doc,n=>{rs(n,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return os(this,e)}getAttributes(){return In(this)}_write(e){e.writeTypeRef(zo)}}const mo=s=>new Ie;class ls{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===$e||t.constructor===de)&&t._start!==null)e=t._start;else for(;e!==null;)if(e.right!==null){e=e.right;break}else e.parent===this._root?e=null:e=e.parent._item;while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}}class de extends I{constructor(){super(),this._prelimContent=[]}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new de}clone(){const e=new de;return e.insert(0,this.toArray().map(t=>t instanceof I?t.clone():t)),e}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new ls(this,e)}querySelector(e){e=e.toUpperCase();const n=new ls(this,i=>i.nodeName&&i.nodeName.toUpperCase()===e).next();return n.done?null:n.value}querySelectorAll(e){return e=e.toUpperCase(),Q(new ls(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){gt(this,e,new yo(this,t,e))}toString(){return En(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},n){const i=e.createDocumentFragment();return n!==void 0&&n._createAssociation(i,this),He(this,r=>{i.insertBefore(r.toDOM(e,t,n),null)}),i}insert(e,t){this.doc!==null?y(this.doc,n=>{An(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(this.doc!==null)y(this.doc,n=>{const i=e&&e instanceof I?e._item:e;pt(n,this,i,t)});else{const n=this._prelimContent,i=e===null?0:n.findIndex(r=>r===e)+1;if(i===0&&e!==null)throw X("Reference item not found");n.splice(i,0,...t)}}delete(e,t=1){this.doc!==null?y(this.doc,n=>{xn(n,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return Dn(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return Cn(this,e)}slice(e=0,t=this.length){return Sn(this,e,t)}forEach(e){He(this,e)}_write(e){e.writeTypeRef(Ro)}}const bo=s=>new de;class $e extends de{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((n,i)=>{this.setAttribute(i,n)}),this._prelimAttrs=null}_copy(){return new $e(this.nodeName)}clone(){const e=new $e(this.nodeName),t=this.getAttributes();return xi(t,(n,i)=>{typeof n=="string"&&e.setAttribute(i,n)}),e.insert(0,this.toArray().map(n=>n instanceof I?n.clone():n)),e}toString(){const e=this.getAttributes(),t=[],n=[];for(const c in e)n.push(c);n.sort();const i=n.length;for(let c=0;c<i;c++){const a=n[c];t.push(a+'="'+e[a]+'"')}const r=this.nodeName.toLocaleLowerCase(),o=t.length>0?" "+t.join(" "):"";return`<${r}${o}>${super.toString()}</${r}>`}removeAttribute(e){this.doc!==null?y(this.doc,t=>{kt(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?y(this.doc,n=>{rs(n,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return os(this,e)}hasAttribute(e){return Ln(this,e)}getAttributes(){return In(this)}toDOM(e=document,t={},n){const i=e.createElement(this.nodeName),r=this.getAttributes();for(const o in r){const c=r[o];typeof c=="string"&&i.setAttribute(o,c)}return He(this,o=>{i.appendChild(o.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(i,this),i}_write(e){e.writeTypeRef(Oo),e.writeKey(this.nodeName)}}const wo=s=>new $e(s.readKey());class yo extends dt{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(i=>{i===null?this.childListChanged=!0:this.attributesChanged.add(i)})}}class wt extends ue{constructor(e){super(),this.hookName=e}_copy(){return new wt(this.hookName)}clone(){const e=new wt(this.hookName);return this.forEach((t,n)=>{e.set(n,t)}),e}toDOM(e=document,t={},n){const i=t[this.hookName];let r;return i!==void 0?r=i.createDom(this):r=document.createElement(this.hookName),r.setAttribute("data-yjs-hook",this.hookName),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(No),e.writeKey(this.hookName)}}const _o=s=>new wt(s.readKey());class yt extends Ie{get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new yt}clone(){const e=new yt;return e.applyDelta(this.toDelta()),e}toDOM(e=document,t,n){const i=e.createTextNode(this.toString());return n!==void 0&&n._createAssociation(i,this),i}toString(){return this.toDelta().map(e=>{const t=[];for(const i in e.attributes){const r=[];for(const o in e.attributes[i])r.push({key:o,value:e.attributes[i][o]});r.sort((o,c)=>o.key<c.key?-1:1),t.push({nodeName:i,attrs:r})}t.sort((i,r)=>i.nodeName<r.nodeName?-1:1);let n="";for(let i=0;i<t.length;i++){const r=t[i];n+=`<${r.nodeName}`;for(let o=0;o<r.attrs.length;o++){const c=r.attrs[o];n+=` ${c.key}="${c.value}"`}n+=">"}n+=e.insert;for(let i=t.length-1;i>=0;i--)n+=`</${t[i].nodeName}>`;return n}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(Bo)}}const So=s=>new yt;class hs{constructor(e,t){this.id=e,this.length=t}get deleted(){throw B()}mergeWith(e){return!1}write(e,t,n){throw B()}integrate(e,t){throw B()}}const Do=0;class O extends hs{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),dn(e.doc.store,this)}write(e,t){e.writeInfo(Do),e.writeLen(this.length-t)}getMissing(e,t){return null}}class qe{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new qe(this.content)}splice(e){throw B()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}}const Eo=s=>new qe(s.readBuf());class Ke{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Ke(this.len)}splice(e){const t=new Ke(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){ct(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}}const Co=s=>new Ke(s.readLen()),Nn=(s,e)=>new Ee({guid:s,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class Ye{constructor(e){e._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=e;const t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Ye(Nn(this.doc.guid,this.opts))}splice(e){throw B()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}}const vo=s=>new Ye(Nn(s.readString(),s.readAny()));class fe{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new fe(this.embed)}splice(e){throw B()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}}const Ao=s=>new fe(s.readJSON());class C{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new C(this.key,this.value)}splice(e){throw B()}mergeWith(e){return!1}integrate(e,t){const n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}const xo=s=>new C(s.readKey(),s.readJSON());class _t{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new _t(this.arr)}splice(e){const t=new _t(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){const n=this.arr.length;e.writeLen(n-t);for(let i=t;i<n;i++){const r=this.arr[i];e.writeString(r===void 0?"undefined":JSON.stringify(r))}}getRef(){return 2}}const Io=s=>{const e=s.readLen(),t=[];for(let n=0;n<e;n++){const i=s.readString();i==="undefined"?t.push(void 0):t.push(JSON.parse(i))}return new _t(t)};class ge{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ge(this.arr)}splice(e){const t=new ge(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){const n=this.arr.length;e.writeLen(n-t);for(let i=t;i<n;i++){const r=this.arr[i];e.writeAny(r)}}getRef(){return 8}}const Lo=s=>{const e=s.readLen(),t=[];for(let n=0;n<e;n++)t.push(s.readAny());return new ge(t)};class H{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new H(this.str)}splice(e){const t=new H(this.str.slice(e));this.str=this.str.slice(0,e);const n=this.str.charCodeAt(e-1);return n>=55296&&n<=56319&&(this.str=this.str.slice(0,e-1)+"�",t.str="�"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}}const jo=s=>new H(s.readString()),Mo=[lo,uo,mo,wo,bo,_o,So],To=0,Uo=1,zo=2,Oo=3,Ro=4,No=5,Bo=6;class P{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new P(this.type._copy())}splice(e){throw B()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(n=>{n.deleted?n.id.clock<(e.beforeState.get(n.id.client)||0)&&e._mergeStructs.push(n):n.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(n=>{for(;n!==null;)n.gc(e,!0),n=n.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}}const Fo=s=>new P(Mo[s.readTypeRef()](s)),St=(s,e,t)=>{const{client:n,clock:i}=e.id,r=new v(w(n,i+t),e,w(n,i+t-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t));return e.deleted&&r.markDeleted(),e.keep&&(r.keep=!0),e.redone!==null&&(r.redone=w(e.redone.client,e.redone.clock+t)),e.right=r,r.right!==null&&(r.right.left=r),s._mergeStructs.push(r),r.parentSub!==null&&r.right===null&&r.parent._map.set(r.parentSub,r),e.length=t,r};class v extends hs{constructor(e,t,n,i,r,o,c,a){super(e,a.getLength()),this.origin=n,this.left=t,this.right=i,this.rightOrigin=r,this.parent=o,this.parentSub=c,this.redone=null,this.content=a,this.info=this.content.isCountable()?js:0}set marker(e){(this.info&Tt)>0!==e&&(this.info^=Tt)}get marker(){return(this.info&Tt)>0}get keep(){return(this.info&Ls)>0}set keep(e){this.keep!==e&&(this.info^=Ls)}get countable(){return(this.info&js)>0}get deleted(){return(this.info&Mt)>0}set deleted(e){this.deleted!==e&&(this.info^=Mt)}markDeleted(){this.info|=Mt}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=x(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=x(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ve&&this.id.client!==this.parent.client&&this.parent.clock>=x(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=fn(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=te(e,this.rightOrigin),this.rightOrigin=this.right.id),(this.left&&this.left.constructor===O||this.right&&this.right.constructor===O)&&(this.parent=null),!this.parent)this.left&&this.left.constructor===v&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===v&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===ve){const n=Zt(t,this.parent);n.constructor===O?this.parent=null:this.parent=n.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=fn(e,e.doc.store,w(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let n=this.left,i;if(n!==null)i=n.right;else if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start;const r=new Set,o=new Set;for(;i!==null&&i!==this.right;){if(o.add(i),r.add(i),at(this.origin,i.origin)){if(i.id.client<this.id.client)n=i,r.clear();else if(at(this.rightOrigin,i.rightOrigin))break}else if(i.origin!==null&&o.has(Zt(e.doc.store,i.origin)))r.has(Zt(e.doc.store,i.origin))||(n=i,r.clear());else break;i=i.right}this.left=n}if(this.left!==null){const n=this.left.right;this.right=n,this.left.right=this}else{let n;if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start,this.parent._start=this;this.right=n}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),dn(e.doc.store,this),this.content.integrate(e,this),kn(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new O(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;e!==null&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;e!==null&&e.deleted;)e=e.left;return e}get lastId(){return this.length===1?this.id:w(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&at(e.origin,this.lastId)&&this.right===e&&at(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&this.redone===null&&e.redone===null&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){const t=this.parent._searchMarker;return t&&t.forEach(n=>{n.p===e&&(n.p=this,!this.deleted&&this.countable&&(n.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){const t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),ct(e.deleteSet,this.id.client,this.id.clock,this.length),kn(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw F();this.content.gc(e),t?Yr(e,this,new O(this.id,this.length)):this.content=new Ke(this.length)}write(e,t){const n=t>0?w(this.id.client,this.id.clock+t-1):this.origin,i=this.rightOrigin,r=this.parentSub,o=this.content.getRef()&tt|(n===null?0:T)|(i===null?0:J)|(r===null?0:Ue);if(e.writeInfo(o),n!==null&&e.writeLeftID(n),i!==null&&e.writeRightID(i),n===null&&i===null){const c=this.parent;if(c._item!==void 0){const a=c._item;if(a===null){const l=Kr(c);e.writeParentInfo(!0),e.writeString(l)}else e.writeParentInfo(!1),e.writeLeftID(a.id)}else c.constructor===String?(e.writeParentInfo(!0),e.writeString(c)):c.constructor===ve?(e.writeParentInfo(!1),e.writeLeftID(c)):F();r!==null&&e.writeString(r)}this.content.write(e,t)}}const Bn=(s,e)=>Vo[e&tt](s),Vo=[()=>{F()},Co,Io,Eo,jo,Ao,xo,Fo,Lo,vo,()=>{F()}],Ho=10;class R extends hs{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){F()}write(e,t){e.writeInfo(Ho),p(e.restEncoder,this.length-t)}getMissing(e,t){return null}}const Fn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Vn="__ $YJS$ __";Fn[Vn]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),Fn[Vn]=!0;const Hn=0,us=1,$n=2,ds=(s,e)=>{p(s,Hn);const t=$r(e);D(s,t)},qn=(s,e,t)=>{p(s,us),D(s,Pt(e,t))},$o=(s,e,t)=>qn(e,t,M(s)),Kn=(s,e,t)=>{try{nn(e,M(s),t)}catch(n){console.error("Caught error while handling a Yjs update",n)}},qo=(s,e)=>{p(s,$n),D(s,e)},Ko=Kn,Yo=(s,e,t,n)=>{const i=k(s);switch(i){case Hn:$o(s,e,t);break;case us:Kn(s,t,n);break;case $n:Ko(s,t,n);break;default:throw new Error("Unknown message type")}return i},Jo=0,Xo=(s,e,t)=>{switch(k(s)){case Jo:t(e,ee(s))}},fs=3e4;class Go extends ot{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const t=le();this.getLocalState()!==null&&fs/2<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const n=[];this.meta.forEach((i,r)=>{r!==this.clientID&&fs<=t-i.lastUpdated&&this.states.has(r)&&n.push(r)}),n.length>0&&gs(this,n,"timeout")},Y(fs/10)),e.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(e){const t=this.clientID,n=this.meta.get(t),i=n===void 0?0:n.clock+1,r=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:i,lastUpdated:le()});const o=[],c=[],a=[],l=[];e===null?l.push(t):r==null?e!=null&&o.push(t):(c.push(t),Te(r,e)||a.push(t)),(o.length>0||a.length>0||l.length>0)&&this.emit("change",[{added:o,updated:a,removed:l},"local"]),this.emit("update",[{added:o,updated:c,removed:l},"local"])}setLocalStateField(e,t){const n=this.getLocalState();n!==null&&this.setLocalState({...n,[e]:t})}getStates(){return this.states}}const gs=(s,e,t)=>{const n=[];for(let i=0;i<e.length;i++){const r=e[i];if(s.states.has(r)){if(s.states.delete(r),r===s.clientID){const o=s.meta.get(r);s.meta.set(r,{clock:o.clock+1,lastUpdated:le()})}n.push(r)}}n.length>0&&(s.emit("change",[{added:[],updated:[],removed:n},t]),s.emit("update",[{added:[],updated:[],removed:n},t]))},Je=(s,e,t=s.states)=>{const n=e.length,i=j();p(i,n);for(let r=0;r<n;r++){const o=e[r],c=t.get(o)||null,a=s.meta.get(o).clock;p(i,o),p(i,a),ae(i,JSON.stringify(c))}return S(i)},Wo=(s,e,t)=>{const n=Z(e),i=le(),r=[],o=[],c=[],a=[],l=k(n);for(let h=0;h<l;h++){const u=k(n);let d=k(n);const f=JSON.parse(ee(n)),g=s.meta.get(u),m=s.states.get(u),U=g===void 0?0:g.clock;(U<d||U===d&&f===null&&s.states.has(u))&&(f===null?u===s.clientID&&s.getLocalState()!=null?d++:s.states.delete(u):s.states.set(u,f),s.meta.set(u,{clock:d,lastUpdated:i}),g===void 0&&f!==null?r.push(u):g!==void 0&&f===null?a.push(u):f!==null&&(Te(f,m)||c.push(u),o.push(u)))}(r.length>0||c.length>0||a.length>0)&&s.emit("change",[{added:r,updated:c,removed:a},t]),(r.length>0||o.length>0||a.length>0)&&s.emit("update",[{added:r,updated:o,removed:a},t])},Po=s=>Ii(s,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join("&");var pe=0,Yn=3,Le=1,Qo=2;function Zo(s,e){if(!s)throw new Error(e)}var Xe=[];Xe[pe]=(s,e,t,n,i)=>{p(s,pe);const r=Yo(e,s,t.doc,t);n&&r===us&&!t.synced&&(t.synced=!0)},Xe[Yn]=(s,e,t,n,i)=>{p(s,Le),D(s,Je(t.awareness,Array.from(t.awareness.getStates().keys())))},Xe[Le]=(s,e,t,n,i)=>{Wo(t.awareness,M(e),t)},Xe[Qo]=(s,e,t,n,i)=>{Xo(e,t.doc,(r,o)=>ec(t,o))};var Jn=3e4;function ec(s,e){console.warn(`Permission denied to access ${s.url}.
4
+ ${e}`)}function Xn(s,e,t){const n=Z(e),i=j(),r=k(n),o=s.messageHandlers[r];return o?o(i,n,s,t,r):console.error("Unable to compute message"),i}function Gn(s){if(s.shouldConnect&&s.ws===null){const e=new s._WS(s.url);e.binaryType="arraybuffer",s.ws=e,s.wsconnecting=!0,s.wsconnected=!1,s.synced=!1,e.onmessage=t=>{if(t.data==="ping"){e.send("pong");return}s.wsLastMessageReceived=le();const n=Xn(s,new Uint8Array(t.data),!0);zt(n)>1&&e.send(S(n))},e.onerror=t=>{s.emit("connection-error",[t,s])},e.onclose=t=>{s.emit("connection-close",[t,s]),s.ws=null,s.wsconnecting=!1,s.wsconnected?(s.wsconnected=!1,s.synced=!1,gs(s.awareness,Array.from(s.awareness.getStates().keys()).filter(n=>n!==s.doc.clientID),s),s.emit("status",[{status:"disconnected"}])):s.wsUnsuccessfulReconnects++,setTimeout(Gn,jt(Ni(2,s.wsUnsuccessfulReconnects)*100,s.maxBackoffTime),s)},e.onopen=()=>{s.wsLastMessageReceived=le(),s.wsconnecting=!1,s.wsconnected=!0,s.wsUnsuccessfulReconnects=0,s.emit("status",[{status:"connected"}]);const t=j();if(p(t,pe),ds(t,s.doc),e.send(S(t)),s.awareness.getLocalState()!==null){const n=j();p(n,Le),D(n,Je(s.awareness,[s.doc.clientID])),e.send(S(n))}},s.emit("status",[{status:"connecting"}])}}function ps(s,e){const t=s.ws;s.wsconnected&&t&&t.readyState===t.OPEN&&t.send(e),s.bcconnected&&_e(s.bcChannel,e,s)}var tc=class extends ot{constructor(e,t,n,{connect:i=!0,awareness:r=new Go(n),params:o={},WebSocketPolyfill:c=WebSocket,resyncInterval:a=-1,maxBackoffTime:l=2500,disableBc:h=!1}={}){super();b(this,"maxBackoffTime");b(this,"bcChannel");b(this,"url");b(this,"roomname");b(this,"doc");b(this,"_WS");b(this,"awareness");b(this,"wsconnected");b(this,"wsconnecting");b(this,"bcconnected");b(this,"disableBc");b(this,"wsUnsuccessfulReconnects");b(this,"messageHandlers");b(this,"_synced");b(this,"ws");b(this,"wsLastMessageReceived");b(this,"shouldConnect");b(this,"_resyncInterval");b(this,"_bcSubscriber");b(this,"_updateHandler");b(this,"_awarenessUpdateHandler");b(this,"_unloadHandler");b(this,"_checkInterval");for(;e[e.length-1]==="/";)e=e.slice(0,e.length-1);const u=Po(o);this.maxBackoffTime=l,this.bcChannel=e+"/"+t,this.url=e+"/"+t+(u.length===0?"":"?"+u),this.roomname=t,this.doc=n,this._WS=c,this.awareness=r,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=h,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Xe.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=i,this._resyncInterval=0,a>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const d=j();p(d,pe),ds(d,n),this.ws.send(S(d))}},a)),this._bcSubscriber=(d,f)=>{if(f!==this){const g=Xn(this,new Uint8Array(d),!1);zt(g)>1&&_e(this.bcChannel,S(g),this)}},this._updateHandler=(d,f)=>{if(f!==this){const g=j();p(g,pe),qo(g,d),ps(this,S(g))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:d,updated:f,removed:g},m)=>{const U=d.concat(f).concat(g),We=j();p(We,Le),D(We,Je(r,U)),ps(this,S(We))},this._unloadHandler=()=>{gs(this.awareness,[n.clientID],"window unload")},typeof window<"u"?window.addEventListener("unload",this._unloadHandler):typeof process<"u"&&process.on("exit",this._unloadHandler),r.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Jn<le()-this.wsLastMessageReceived&&(Zo(this.ws!==null,"ws must not be null"),this.ws.close())},Jn/10),i&&this.connect()}get synced(){return this._synced}set synced(e){this._synced!==e&&(this._synced=e,this.emit("synced",[e]),this.emit("sync",[e]))}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||(hr(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const e=j();p(e,pe),ds(e,this.doc),_e(this.bcChannel,S(e),this);const t=j();p(t,pe),qn(t,this.doc),_e(this.bcChannel,S(t),this);const n=j();p(n,Yn),_e(this.bcChannel,S(n),this);const i=j();p(i,Le),D(i,Je(this.awareness,[this.doc.clientID])),_e(this.bcChannel,S(i),this)}disconnectBc(){const e=j();p(e,Le),D(e,Je(this.awareness,[this.doc.clientID],new Map)),ps(this,S(e)),this.bcconnected&&(ur(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&&(Gn(this),this.connectBc())}};function Wn(){if(crypto.randomUUID)return crypto.randomUUID();let s=new Date().getTime(),e=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){let n=Math.random()*16;return s>0?(n=(s+n)%16|0,s=Math.floor(s/16)):(n=(e+n)%16|0,e=Math.floor(e/16)),(t==="x"?n:n&3|8).toString(16)})}var sc=class extends tc{constructor(s,e,t,n={}){const i=`${s.startsWith("localhost:")||s.startsWith("127.0.0.1:")?"ws":"wss"}://${s}/party`;n.params===void 0?n.params={_pk:Wn()}:n.params._pk=Wn(),super(i,e,t,n)}};const ke=s=>Se((e,t)=>{s.onerror=n=>t(new Error(n.target.error)),s.onsuccess=n=>e(n.target.result)}),nc=(s,e)=>Se((t,n)=>{const i=indexedDB.open(s);i.onupgradeneeded=r=>e(r.target.result),i.onerror=r=>n(X(r.target.error)),i.onsuccess=r=>{const o=r.target.result;o.onversionchange=()=>{o.close()},typeof addEventListener<"u"&&addEventListener("unload",()=>o.close()),t(o)}}),ic=s=>ke(indexedDB.deleteDatabase(s)),rc=(s,e)=>e.forEach(t=>s.createObjectStore.apply(s,t)),Ge=(s,e,t="readwrite")=>{const n=s.transaction(e,t);return e.map(i=>fc(n,i))},Pn=(s,e)=>ke(s.count(e)),oc=(s,e)=>ke(s.get(e)),Qn=(s,e)=>ke(s.delete(e)),cc=(s,e,t)=>ke(s.put(e,t)),ks=(s,e)=>ke(s.add(e)),ac=(s,e,t)=>ke(s.getAll(e,t)),lc=(s,e,t)=>{let n=null;return dc(s,e,i=>(n=i,!1),t).then(()=>n)},hc=(s,e=null)=>lc(s,e,"prev"),uc=(s,e)=>Se((t,n)=>{s.onerror=n,s.onsuccess=async i=>{const r=i.target.result;if(r===null||await e(r)===!1)return t();r.continue()}}),dc=(s,e,t,n="next")=>uc(s.openKeyCursor(e,n),i=>t(i.key)),fc=(s,e)=>s.objectStore(e),gc=(s,e)=>IDBKeyRange.upperBound(s,e),pc=(s,e)=>IDBKeyRange.lowerBound(s,e),ms="custom",Zn="updates",ei=500,ti=(s,e=()=>{},t=()=>{})=>{const[n]=Ge(s.db,[Zn]);return ac(n,pc(s._dbref,!1)).then(i=>{s._destroyed||(e(n),y(s.doc,()=>{i.forEach(r=>nn(s.doc,r))},s,!1),t(n))}).then(()=>hc(n).then(i=>{s._dbref=i+1})).then(()=>Pn(n).then(i=>{s._dbsize=i})).then(()=>n)},kc=(s,e=!0)=>ti(s).then(t=>{(e||s._dbsize>=ei)&&ks(t,Pt(s.doc)).then(()=>Qn(t,gc(s._dbref,!0))).then(()=>Pn(t).then(n=>{s._dbsize=n}))});class mc extends ot{constructor(e,t){super(),this.doc=t,this.name=e,this._dbref=0,this._dbsize=0,this._destroyed=!1,this.db=null,this.synced=!1,this._db=nc(e,n=>rc(n,[["updates",{autoIncrement:!0}],["custom"]])),this.whenSynced=Se(n=>this.on("synced",()=>n(this))),this._db.then(n=>{this.db=n,ti(this,o=>ks(o,Pt(t)),()=>{if(this._destroyed)return this;this.synced=!0,this.emit("synced",[this])})}),this._storeTimeout=1e3,this._storeTimeoutId=null,this._storeUpdate=(n,i)=>{if(this.db&&i!==this){const[r]=Ge(this.db,[Zn]);ks(r,n),++this._dbsize>=ei&&(this._storeTimeoutId!==null&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout(()=>{kc(this,!1),this._storeTimeoutId=null},this._storeTimeout))}},t.on("update",this._storeUpdate),this.destroy=this.destroy.bind(this),t.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(e=>{e.close()})}clearData(){return this.destroy().then(()=>{ic(this.name)})}get(e){return this._db.then(t=>{const[n]=Ge(t,[ms],"readonly");return oc(n,e)})}set(e,t){return this._db.then(n=>{const[i]=Ge(n,[ms]);return cc(i,t,e)})}del(e){return this._db.then(t=>{const[n]=Ge(t,[ms]);return Qn(n,e)})}}const Yc="",bc={ctrlKey:"Control",altKey:"Alt",shiftKey:"Shift",metaKey:"Meta"},wc="can-duplicate-to";var E=(s=>(s.CanPlay="can-play",s.CanMove="can-move",s.CanSpin="can-spin",s.CanGrow="can-grow",s.CanToggle="can-toggle",s.CanDuplicate="can-duplicate",s.CanPost="can-post",s))(E||{});function yc(s){return s.id}function si(s){return document.getElementById(s)}function _c(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}var Sc=["2 girls 1 cup","2g1c","4r5e","5h1t","5hit","5ht","666","@$$","a s s","a s shole","a55","a55hole","a_s_s","abbo","abeed","abuse","acrotomophilia","aeolus","africoon","ahole","alabama hot pocket","alaskan pipeline","alligator bait","alligatorbait","amcik","anal","analannie","analprobe","analsex","andskota","anilingus","anus","apeshit","ar5e","arabush","arabushs","areola","areole","argie","armo","armos","aroused","arrse","arschloch","arse","arsehole","aryan","ash0le","ash0les","asholes","ass monkey","ass","ass-fucker","ass-hat","ass-pirate","assbag","assbagger","assbandit","assbang","assbanged","assbanger","assbangs","assbite","assblaster","assclown","asscock","asscowboy","asscracker","asses","assface","assfuck","assfucker","assfukka","assgoblin","assh0le","assh0lez","asshat","asshead","assho1e","asshole","assholes","assholz","asshopper","asshore","assjacker","assjockey","asskiss","asskisser","assklown","asslick","asslicker","asslover","assman","assmaster","assmonkey","assmunch","assmuncher","assnigger","asspacker","asspirate","asspuppies","assrammer","assranger","assshit","assshole","asssucker","asswad","asswhole","asswhore","asswipe","asswipes","auto erotic","autoerotic","ayir","azazel","azz","azzhole","b a s t a r d","b i t c h","b o o b","b!+ch","b!tch","b!tchin","b*tch","b00b","b00bies","b00biez","b00bs","b00bz","b17ch","b1tch","b7ch","babeland","babes","baby batter","baby juice","backdoor","backdoorman","badfuck","bagging","ball gag","ball gravy","ball kicking","ball licking","ball sack","ball sucking","ballbag","balllicker","ballsack","bampot","bangbro","bangbros","bangbus","banger","banging","bareback","barely legal","barelylegal","barenaked","barf","barface","barfface","bassterd","bassterds","bastard","bastardo","bastards","bastardz","basterds","basterdz","bastinado","bawdy","bazongas","bazooms","bbw","bdsm","beaner","beaners","beaney","beaneys","beardedclam","beastality","beastial","beastiality","beastility","beatch","beatoff","beatyourmeat","beaver cleaver","beaver lips","beef curtains","beeyotch","bellend","beotch","bestial","bestiality","bi curious","bi+ch","bi7ch","biatch","bicurious","big black","big breasts","big knockers","big tits","bigass","bigbastard","bigbreasts","bigbutt","bigtits","bimbo","bimbos","bint","birdlock","bitch","bitchass","bitched","bitcher","bitchers","bitches","bitchez","bitchin","bitching","bitchslap","bitchtit","bitchy","biteme","bitties","black cock","blackcock","blackman","blackout","blacks","blonde action","blonde on blonde action","blonde on blonde","bloodclaat","bloody","blow j","blow job","blow your l","blow your load","blowjob","blowjobs","blue waffle","bluegum","bluegums","blumpkin","bo ob","bo obs","boang","boche","boches","bodily","boffing","bogan","bohunk","boink","boiolas","bollick","bollock","bollocks","bollok","bollox","bombers","bombing","bomd","bondage","boned","boner","boners","bong","bookie","boong","boonga","boongas","boongs","boonie","boonies","booobs","boooobs","booooobs","booooooobs","bootee","bootlip","bootlips","boozer","boozy","bosch","bosche","bosches","boschs","bosomy","bounty bar","bounty bars","bountybar","brea5t","breastjob","breastlover","breastman","brown shower","brown showers","brunette action","btch","buceta","buddhahead","buddhaheads","buffies","bugger","buggered","buggery","bukake","bukkake","bullcrap","bulldike","bulldyke","bullet vibe","bullshit","bullshits","bullshitted","bullturds","bumblefuck","bumfuck","bung hole","bung","bunga","bungas","bunghole","bunny fucker","burr head","burr heads","burrhead","burrheads","butchbabes","butchdike","butchdyke","butt plug","butt-pirate","buttbang","buttcheeks","buttface","buttfuck","buttfucker","buttfuckers","butthead","butthole","buttman","buttmuch","buttmunch","buttmuncher","buttpirate","buttplug","buttstain","buttwipe","byatch","c u n t","c-0-c-k","c-o-c-k","c-u-n-t","c.0.c.k","c.o.c.k.","c.u.n.t","c0ck","c0cks","c0cksucker","c0k","cabron","caca","cacker","cahone","camel jockey","camel jockeys","camel toe","cameljockey","cameltoe","camgirl","camslut","camwhore","carpet muncher","carpetmuncher","carruth","cawk","cawks","cazzo","cervix","chav","cheese eating surrender monkey","cheese eating surrender monkies","cheeseeating surrender monkey","cheeseeating surrender monkies","cheesehead","cheeseheads","cherrypopper","chickslick","china swede","china swedes","chinaman","chinamen","chinaswede","chinaswedes","chinc","chincs","ching chong","ching chongs","chinga","chingchong","chingchongs","chink","chinks","chinky","choad","chocolate rosebuds","chode","chodes","chonkies","chonky","chonkys","chraa","christ killer","christ killers","chug","chugs","chuj","chunger","chungers","chunkies","chunkys","chute","cipa","circlejerk","cl1t","clamdigger","clamdiver","clamps","clansman","clansmen","clanswoman","clanswomen","cleveland steamer","clit","clitface","clitfuck","clitoris","clitorus","clits","clitty","clogwog","clover clamps","clusterfuck","cnts","cntz","cnut","cocain","cocaine","cock","cock-head","cock-sucker","cockbite","cockblock","cockblocker","cockburger","cockcowboy","cockface","cockfight","cockfucker","cockhead","cockholster","cockjockey","cockknob","cockknocker","cockknoker","cocklicker","cocklover","cockmaster","cockmongler","cockmongruel","cockmonkey","cockmunch","cockmuncher","cocknob","cocknose","cocknugget","cockqueen","cockrider","cocks","cockshit","cocksman","cocksmith","cocksmoker","cocksucer","cocksuck","cocksucked","cocksucker","cocksucking","cocksucks","cocksuka","cocksukka","cocktease","cocky","cohee","coital","coitus","cok","cokmuncher","coksucka","commie","condom","coochie","coochy","coolie","coolies","cooly","coon ass","coon asses","coonass","coonasses","coondog","coons","cooter","coprolagnia","coprophilia","copulate","corksucker","cornhole","cra5h","crabs","crackcocain","cracker","crackpipe","crackwhore","crap","crapola","crapper","crappy","creampie","crotch","crotchjockey","crotchmonkey","crotchrot","cuck","cum face","cum licker","cum","cumbubble","cumdumpster","cumfest","cumguzzler","cuming","cumjockey","cumlickr","cumm","cummer","cummin","cumming","cumquat","cumqueen","cums","cumshot","cumshots","cumslut","cumstain","cumsucker","cumtart","cunilingus","cunillingus","cunn","cunnie","cunnilingus","cunntt","cunny","cunt","cunteyed","cuntface","cuntfuck","cuntfucker","cunthole","cunthunter","cuntlick","cuntlicker","cuntlicking","cuntrag","cunts","cuntslut","cuntsucker","cuntz","curry muncher","curry munchers","currymuncher","currymunchers","cushi","cushis","cyalis","cyberfuc","cyberfuck","cyberfucked","cyberfucker","cyberfuckers","cyberfucking","cybersex","cyberslimer","d0ng","d0uch3","d0uche","d1ck","d1ld0","d1ldo","d4mn","dago","dagos","dahmer","damm","dammit","damn","damnation","damned","damnit","darkey","darkeys","darkie","darkies","darky","date rape","daterape","datnigga","dawgie style","dawgie-style","daygo","deapthroat","deep throat","deep throating","deepaction","deepthroat","deepthroating","defecate","deggo","dego","degos","demon","dendrophilia","destroyyourpussy","deth","diaper daddy","diaper head","diaper heads","diaperdaddy","diaperhead","diaperheads","dick pic","dick","dick-ish","dickbag","dickbeater","dickbeaters","dickbrain","dickdipper","dickface","dickflipper","dickforbrains","dickfuck","dickhead","dickheads","dickhole","dickish","dickjuice","dickless","dicklick","dicklicker","dickman","dickmilk","dickmonger","dickpic","dickripper","dicks","dicksipper","dickslap","dickslicker","dicksucker","dickwad","dickweasel","dickweed","dickwhipper","dickwod","dickzipper","diddle","dike","dild0","dild0s","dildo","dildos","dilf","diligaf","dilld0","dilld0s","dillweed","dimwit","dingle","dingleberries","dingleberry","dink","dinks","dipship","dipshit","dipstick","dirsa","dirty pillows","dirty sanchez","dix","dixiedike","dixiedyke","dlck","dog style","dog-fucker","doggie style","doggie","doggie-style","doggiestyle","doggin","dogging","doggy style","doggy-style","doggystyle","dolcett","domination","dominatricks","dominatrics","dominatrix","dommes","dong","donkey punch","donkeypunch","donkeyribber","doochbag","doodoo","doofus","dookie","doosh","dot head","dot heads","dothead","dotheads","double dong","double penetration","doubledong","doublepenetration","douch3","douche bag","douche","douche-fag","douchebag","douchebags","douchewaffle","douchey","dp action","dp","dpaction","dragqueen","dragqween","dripdick","dry hump","dryhump","duche","dudette","dumass","dumb ass","dumbass","dumbasses","dumbbitch","dumbfuck","dumbshit","dumshit","dune coon","dune coons","dupa","dvda","dyefly","dyke","dykes","dziwka","earotics","easyslut","eat my ass","eat my","eatadick","eatballs","eathairpie","eatme","eatmyass","eatpussy","ecchi","ejackulate","ejakulate","ekrem","ekto","enculer","enema","enlargement","erect","erection","ero","erotic","erotism","escort","esqua","essohbee","ethical slut","evl","excrement","exkwew","extacy","extasy","f u c k e r","f u c k e","f u c k","f u k","f*ck","f-u-c-k","f.u.c.k","f4nny","f_u_c_k","facefucker","fack","faeces","faen","fag","fag1t","fagbag","faget","fagfucker","fagg","fagg1t","fagged","fagging","faggit","faggitt","faggot","faggotcock","faggs","fagit","fagot","fagots","fags","fagt","fagtard","fagz","faig","faigs","faigt","fanculo","fannybandit","fannyflaps","fannyfucker","fanyy","fartknocker","fastfuck","fatah","fatfuck","fatfucker","fatso","fck","fckcum","fckd","fcuk","fcuker","fcuking","fecal","feck","fecker","feg","felatio","felch","felcher","felching","fellate","fellatio","feltch","feltcher","feltching","female squirting","femalesquirtin","femalesquirting","femdom","fetish","ficken","figging","fingerbang","fingerfood","fingerfuck","fingerfucked","fingerfucker","fingerfuckers","fingerfucking","fingerfucks","fingering","fisted","fister","fistfuck","fistfucked","fistfucker","fistfuckers","fistfucking","fistfuckings","fistfucks","fisting","fisty","fitt","flamer","flange","flasher","flikker","flipping the bird","flogthelog","floo","floozy","flydie","flydye","foad","fok","fondle","foobar","fook","fooker","foot fetish","footaction","footfetish","footfuck","footfucker","footjob","footlicker","footstar","foreskin","forni","fornicate","fotze","foursome","fourtwenty","freakfuck","freakyfucker","freefuck","freex","frigg","frigga","frigger","frotting","fucck","fuck","fuck-tard","fucka","fuckable","fuckass","fuckbag","fuckbitch","fuckbook","fuckboy","fuckbrain","fuckbuddy","fuckbutt","fuckd","fucked","fuckedup","fucker","fuckers","fuckersucker","fuckface","fuckfest","fuckfreak","fuckfriend","fuckhead","fuckheads","fuckher","fuckhole","fuckin","fuckina","fucking","fuckingbitch","fuckings","fuckingshitmotherfucker","fuckinnuts","fuckinright","fuckit","fuckknob","fuckme","fuckmeat","fuckmehard","fuckmonkey","fuckn","fucknugget","fucknut","fucknuts","fucknutt","fucknutz","fuckoff","fuckpig","fuckpuppet","fuckr","fucks","fuckstick","fucktard","fucktards","fucktoy","fucktrophy","fuckup","fuckwad","fuckwhit","fuckwhore","fuckwit","fuckwitt","fuckyomama","fuckyou","fudge packer","fudgepacker","fugly","fuk","fukah","fuken","fuker","fukin","fuking","fukk","fukkah","fukken","fukker","fukkin","fukking","fuks","fuktard","fuktards","fukwhit","fukwit","funfuck","fungus","futanari","futanary","futkretzn","fuuck","fux","fux0r","fuxor","fvck","fvk","fxck","g-spot","g00k","gae","gai","gang bang","gangbang","gangbanged","gangbanger","gangbangs","gangsta","ganja","gassyass","gator bait","gatorbait","gay sex","gayass","gaybob","gayboy","gaydo","gaygirl","gaylord","gaymuthafuckinwhore","gays","gaysex","gaytard","gaywad","gayz","geezer","geni","genital","genitals","getiton","gey","gfy","ghay","ghey","giant cock","gigolo","ginzo","ginzos","gipp","gippo","gippos","gipps","girl on top","girl on","girls gone wild","givehead","glans","glazeddonut","goatcx","goatse","gob","god dammit","god damn","god damnit","god-dam","god-damned","godam","godammit","godamn","godamnit","goddam","goddamit","goddamm","goddammit","goddamn","goddamned","goddamnes","goddamnit","goddamnmuthafucker","godsdamn","gokkun","golden shower","goldenshower","golliwog","golliwogs","gonad","gonads","gonorrehea","gonzagas","goo girl","gooch","goodpoop","gook eye","gook eyes","gook","gookeye","gookeyes","gookies","gooks","gooky","gora","goras","goregasm","gotohell","goy","goyim","greaseball","greaseballs","groe","groid","groids","grope","grostulation","group sex","gspot","gstring","gtfo","gub","gubba","gubbas","gubs","guido","guiena","guineas","guizi","gummer","guro","gwailo","gwailos","gweilo","gweilos","gyopo","gyopos","gyp","gyped","gypo","gypos","gypp","gypped","gyppie","gyppies","gyppo","gyppos","gyppy","gyppys","gypsys","h e l l","h o m","h00r","h0ar","h0m0","h0mo","h0r","h0re","h4x0r","hadji","hadjis","hairyback","hairybacks","haji","hajis","hajji","hajjis","half breed","half caste","halfbreed","halfcaste","hamas","hamflap","hand job","handjob","haole","haoles","hapa","hard core","hardcore","hardcoresex","hardon","harem","he11","headfuck","hebe","hebes","heeb","heebs","hell","hells","helvete","hentai","heroin","herp","herpes","herpy","heshe","hijacker","hijacking","hillbillies","hillbilly","hindoo","hiscock","hitler","hitlerism","hitlerist","hoar","hoare","hobag","hodgie","hoe","hoer","hoes","holestuffer","hom0","homey","homo","homobangers","homodumbshit","homoey","honger","honkers","honkey","honkeys","honkie","honkies","honky","hooch","hooker","hookers","hoor","hoore","hootch","hooter","hooters","hore","hori","horis","hork","horndawg","horndog","horney","horniest","horny","horseshit","hosejob","hoser","hot carl","hot chick","hotcarl","hotdamn","hotpussy","hotsex","hottotrot","how to kill","how to murder","howtokill","howtomurdep","huevon","huge fat","hugefat","hui","hummer","humped","humper","humpher","humphim","humpin","humping","hussy","hustler","hymen","hymie","hymies","iblowu","ike","ikes","ikey","ikeymo","ikeymos","ikwe","illegal","illegals","inbred","incest","indon","indons","injun","injuns","insest","intercourse","interracial","intheass","inthebuff","israels","j3rk0ff","jack off","jack-off","jackass","jackhole","jackoff","jackshit","jacktheripper","jail bait","jailbait","jap","japcrap","japie","japies","japs","jebus","jelly donut","jerk off","jerk","jerk-off","jerk0ff","jerked","jerkoff","jerries","jerry","jewboy","jewed","jewess","jiga","jigaboo","jigaboos","jigarooni","jigaroonis","jigg","jigga","jiggabo","jiggaboo","jiggabos","jiggas","jigger","jiggerboo","jiggers","jiggs","jiggy","jigs","jihad","jijjiboo","jijjiboos","jimfish","jisim","jism","jiss","jiz","jizim","jizin","jizjuice","jizm","jizn","jizz","jizzd","jizzed","jizzim","jizzin","jizzn","jizzum","jugg","juggs","jugs","jungle bunnies","jungle bunny","junglebunny","junkie","junky","kacap","kacapas","kacaps","kaffer","kaffir","kaffre","kafir","kanake","kanker","katsap","katsaps","kawk","khokhol","khokhols","kicking","kigger","kike","kikes","kimchis","kinbaku","kink","kinkster","kinky","kinkyJesus","kissass","kiunt","kkk","klan","klansman","klansmen","klanswoman","klanswomen","klootzak","knobbing","knobead","knobed","knobend","knobhead","knobjocky","knobjokey","knobz","knockers","knulle","kock","kondum","kondums","kooch","kooches","koon","kootch","krap","krappy","kraut","krauts","kuffar","kuk","kuksuger","kum","kumbubble","kumbullbe","kumer","kummer","kumming","kumquat","kums","kunilingus","kunnilingus","kunt","kunts","kuntz","kurac","kurwa","kushi","kushis","kusi","kwa","kwai lo","kwai los","kwif","kyke","kykes","kyopo","kyopos","kyrpa","l3i+ch","l3i\\+ch","l3itch","labia","lapdance","leather restraint","leather straight","leatherrestraint","lebos","lech","lemon party","lemonparty","leper","lesbain","lesbayn","lesbin","lesbo","lesbos","lez","lezbe","lezbefriends","lezbian","lezbians","lezbo","lezbos","lezz","lezzian","lezzie","lezzies","lezzo","lezzy","libido","licker","licking","lickme","lilniglet","limey","limpdick","limy","lingerie","lipshits","lipshitz","livesex","loadedgun","loin","loins","lolita","lovebone","lovegoo","lovegun","lovejuice","lovemaking","lovemuscle","lovepistol","loverocket","lowlife","lsd","lubejob","lubra","lucifer","luckycammeltoe","lugan","lugans","lust","lusting","lusty","lynch","m-fucking","m0f0","m0fo","m45terbate","ma5terb8","ma5terbate","mabuno","mabunos","macaca","macacas","mafugly","magicwand","mahbuno","mahbunos","make me come","makemecome","makemecum","male squirting","mamhoon","mams","manhater","manpaste","maricon","maricón","marijuana","masochist","masokist","massa","massterbait","masstrbait","masstrbate","mastabate","mastabater","master-bate","masterb8","masterbaiter","masterbat","masterbat3","masterbate","masterbates","masterbating","masterbation","masterbations","masterblaster","mastrabator","masturbat","masturbate","masturbating","masturbation","mattressprincess","mau mau","mau maus","maumau","maumaus","mcfagget","meatbeatter","meatrack","menage","merd","mgger","mggor","mibun","mick","mickeyfinn","mideast","mierda","milf","minge","minger","mo-fo","mockey","mockie","mocky","mof0","mofo","moky","molest","molestation","molester","molestor","moneyshot","mong","monkleigh","moolie","moon cricket","moon crickets","mooncricket","mooncrickets","mormon","moron","moskal","moskals","moslem","mosshead","motha fucker","motha fuker","motha fukkah","motha fukker","mothafuck","mothafucka","mothafuckas","mothafuckaz","mothafucked","mothafucker","mothafuckers","mothafuckin","mothafucking","mothafuckings","mothafucks","mother fucker","mother fukah","mother fuker","mother fukkah","mother fukker","mother-fucker","motherfuck","motherfucka","motherfucked","motherfucker","motherfuckers","motherfuckin","motherfucking","motherfuckings","motherfuckka","motherfucks","motherfvcker","motherlovebone","mothrfucker","mouliewop","mound of venus","moundofvenus","mr hands","mrhands","mtherfucker","mthrfuck","mthrfucker","mthrfucking","mtrfck","mtrfuck","mtrfucker","muff diver","muff","muffdive","muffdiver","muffdiving","muffindiver","mufflikcer","muffpuff","muie","mulatto","mulkku","muncher","mung","munging","munt","munter","muschi","mutha fucker","mutha fukah","mutha fuker","mutha fukkah","mutha fukker","muthafecker","muthafuckaz","muthafucker","muthafuckker","muther","mutherfucker","mutherfucking","muthrfucking","mzungu","mzungus","n1gga","n1gger","n1gr","nad","nads","naked","nambla","nappy","nastt","nasty","nastybitch","nastyho","nastyslut","nastywhore","nawashi","nazi","nazis","nazism","necked","necro","needthedick","negres","negress","negro","negroes","negroid","negros","neonazi","nepesaurio","nig nog","nig","niga","nigar","nigars","nigas","nigers","nigette","nigettes","nigg","nigg3r","nigg4h","nigga","niggah","niggahs","niggar","niggaracci","niggard","niggarded","niggarding","niggardliness","niggardlinesss","niggardly","niggards","niggars","niggas","niggaz","nigger","niggerhead","niggerhole","niggers","niggle","niggled","niggles","niggling","nigglings","niggor","niggress","niggresses","nigguh","nigguhs","niggur","niggurs","niglet","nignog","nigor","nigors","nigr","nigra","nigras","nigre","nigres","nigress","nigs","nigur","niiger","niigr","nimphomania","nimrod","ninny","nip","nipple","nipplering","nipples","nips","nittit","nlgger","nlggor","nob jokey","nob","nobhead","nobjocky","nobjokey","nofuckingway","nog","nookey","nookie","nooky","noonan","nooner","nsfw images","nsfw","nudger","nudie","nudies","numbnuts","nut sack","nutbutter","nutfucker","nutsack","nutten","nymph","nympho","nymphomania","o c k","octopussy","omorashi","one cup two girls","one guy one jar","one guy","one jar","ontherag","orafis","orally","orga","orgasim","orgasim;","orgasims","orgasm","orgasmic","orgasms","orgasum","orgies","orgy","oriface","orifice","orifiss","orospu","osama","ovum","ovums","p e n i s","p i s","p u s s y","p.u.s.s.y.","p0rn","packi","packie","packy","paddy","paedophile","paki","pakie","pakis","paky","palesimian","pancake face","pancake faces","panooch","pansies","pansy","panti","pantie","panties","panty","paska","pastie","pasty","payo","pcp","pearlnecklace","pecker","peckerhead","peckerwood","pedo","pedobear","pedophile","pedophilia","pedophiliac","peeenus","peeenusss","peehole","peenus","peepee","peepshow","peepshpw","pegging","peinus","pen1s","penas","pendejo","pendy","penetrate","penetration","peni5","penial","penile","penis","penis-breath","penises","penisfucker","penisland","penislick","penislicker","penispuffer","penthouse","penus","penuus","perse","perv","perversion","peyote","phalli","phallic","phone sex","phonesex","phuc","phuck","phuk","phuked","phuker","phuking","phukked","phukker","phukking","phuks","phungky","phuq","pi55","picaninny","piccaninny","picka","pickaninnies","pickaninny","piece of shit","pieceofshit","piefke","piefkes","pierdol","pigfucker","piker","pikey","piky","pillowbiter","pillu","pimmel","pimp","pimped","pimper","pimpis","pimpjuic","pimpjuice","pimpsimp","pindick","pinko","pis","pises","pisin","pising","pisof","piss pig","piss","piss-off","pissed","pisser","pissers","pisses","pissflap","pissflaps","pisshead","pissin","pissing","pissoff","pisspig","pistol","pizda","playboy","playgirl","pleasure chest","pleasurechest","pocha","pochas","pocho","pochos","pocketpool","pohm","pohms","polac","polack","polacks","polak","pole smoker","polesmoker","pollock","pollocks","pommie grant","pommie grants","pommy","ponyplay","poof","poon","poonani","poonany","poontang","poontsee","poop chute","poopchute","pooper","pooperscooper","pooping","poorwhitetrash","popimp","porch monkey","porch monkies","porchmonkey","porn","pornflick","pornking","porno","pornography","pornos","pornprincess","pound town","poundtown","pplicker","pr0n","pr1c","pr1ck","pr1k","prairie nigger","prairie niggers","premature","preteen","pric","prickhead","pricks","prig","prince albert piercing","pron","prostitute","pthc","pu55i","pu55y","pube","pubes","pubic","pubiclice","pubis","pud","pudboy","pudd","puddboy","puke","pula","pule","punani","punanny","punany","punkass","punky","punta","puntang","purinapricness","pusies","puss","pusse","pussee","pussi","pussie","pussies","pussy","pussycat","pussydestroyer","pussyeater","pussyfart","pussyfucker","pussylicker","pussylicking","pussylips","pussylover","pussypalace","pussypounder","pussys","pusy","puta","puto","puuke","puuker","qahbeh","quashie","queaf","queef","queerhole","queero","queers","queerz","quickie","quicky","quiff","quim","qweers","qweerz","qweir","r-tard","r-tards","r5e","ra8s","raghead","ragheads","rape","raped","raper","raping","rapist","rautenberg","rearend","rearentry","recktum","rectal","rectum","rectus","redleg","redlegs","redlight","redneck","rednecks","redskin","redskins","reefer","reestie","reetard","reich","renob","rentafuck","rere","retard","retarded","retards","retardz","reverse cowgirl","reversecowgirl","rigger","rimjaw","rimjob","rimming","ritard","rosebuds","rosy palm and her 5 sisters","rosy palm","rosypalm","rosypalmandher5sisters","rosypalmandherefivesisters","round eyes","roundeye","rtard","rtards","rumprammer","ruski","russki","russkie","rusty trombone","rustytrombone","s h i t","s hit","s&m","s-h-1-t","s-h-i-t","s-o-b","s.h.i.t.","s.o.b.","s0b","s_h_i_t","sac","sadis","sadism","sadist","sadom","sambo","sambos","samckdaddy","sanchez","sand nigger","sand niggers","sandm","sandnigger","santorum","sausagequeen","scag","scallywag","scank","scantily","scat","schaffer","scheiss","schizo","schlampe","schlong","schmuck","schvartse","schvartsen","schwartze","schwartzen","scissoring","screwed","screwing","screwyou","scroat","scrog","scrote","scrotum","scrud","seduce","semen","seppo","seppos","septics","sex","sexcam","sexed","sexfarm","sexhound","sexhouse","sexi","sexing","sexkitten","sexo","sexpot","sexslave","sextogo","sextoy","sextoys","sexual","sexually","sexwhore","sexx","sexxi","sexxx","sexxxi","sexxxy","sexxy","sexy","sexymoma","sexyslim","sh!+","sh!t","sh1t","sh1ter","sh1ts","sh1tter","sh1tz","shag","shagger","shaggin","shagging","shamedame","sharmuta","sharmute","shat","shav","shaved beaver","shaved pussy","shavedbeaver","shavedpussy","shawtypimp","sheeney","shemale","shhit","shi+","shibari","shibary","shinola","shipal","shit ass","shit","shit-ass","shit-bag","shit-bagger","shit-brain","shit-breath","shit-cunt","shit-dick","shit-eating","shit-face","shit-faced","shit-fit","shit-head","shit-heel","shit-hole","shit-house","shit-load","shit-pot","shit-spitter","shit-stain","shitass","shitbag","shitbagger","shitblimp","shitbrain","shitbreath","shitcan","shitcunt","shitdick","shite","shiteater","shiteating","shited","shitey","shitface","shitfaced","shitfit","shitforbrains","shitfuck","shitfucker","shitfull","shithapens","shithappens","shithead","shitheel","shithole","shithouse","shiting","shitings","shitlist","shitload","shitola","shitoutofluck","shitpot","shits","shitspitter","shitstain","shitt","shitted","shitter","shitters","shittiest","shitting","shittings","shitty","shity","shitz","shiz","shiznit","shortfuck","shota","shrimping","shylock","shylocks","shyt","shyte","shytty","shyty","simp","sissy","sixsixsix","sixtynine","sixtyniner","skag","skanck","skank","skankbitch","skankee","skankey","skankfuck","skanks","skankwhore","skanky","skankybitch","skankywhore","skeet","skinflute","skribz","skullfuck","skum","skumbag","skurwysyn","skwa","skwe","slag","slanteye","slanty","slapper","sleezeball","slideitin","slimeball","slimebucket","slopehead","slopeheads","sloper","slopers","slopes","slopey","slopeys","slopies","slopy","slut","slutbag","slutbucket","slutdumper","slutkiss","sluts","slutt","slutting","slutty","slutwear","slutwhore","slutz","smack","smackthemonkey","smeg","smegma","smoker","smut","smutty","snatchpatch","snigger","sniggered","sniggering","sniggers","snowback","snowballing","snownigger","snuff","socksucker","sodom","sodomise","sodomite","sodomize","sodomy","son of a bitch","son of a whore","son-of-a-bitch","son-of-a-whore","sonofabitch","sonofbitch","sooties","sooty","souse","soused","soyboy","spac","spade","spades","spaghettibender","spaghettinigger","spank","spankthemonkey","spastic","spearchucker","spearchuckers","sperm","spermacide","spermbag","spermhearder","spermherder","sphencter","spic","spick","spicks","spics","spierdalaj","spig","spigotty","spik","spiks","spitter","splittail","splooge","spludge","spooge","spread legs","spreadeagle","spunk","spunky","sqeh","squa","squarehead","squareheads","squaw","squinty","squirting","stagg","steamy","stfu","stiffy","stoned","stoner","strap on","strapon","strappado","stringer","strip club","stripclub","stroke","stroking","stuinties","stupidfuck","stupidfucker","style doggy","suckdick","sucked","sucker","sucking","suckme","suckmyass","suckmydick","suckmytit","suckoff","sucks","suicide girl","suicide girls","suicidegirl","suicidegirls","suka","sultrywoman","sultrywomen","sumofabiatch","swallower","swalow","swamp guinea","swamp guineas","swastika","syphilis","t i t","t i ts","t1t","t1tt1e5","t1tties","taboo","tacohead","tacoheads","taff","take off your","tar babies","tar baby","tarbaby","tard","taste my","tastemy","tawdry","tea bagging","teabagging","teat","teets","teez","terd","terror","terrorist","teste","testee","testes","testical","testicle","testicles","testis","thicklip","thicklips","thirdeye","thirdleg","threesome","threeway","throating","thumbzilla","thundercunt","tied up","tig ol bitties","tig old bitties","tight white","timber nigger","timber niggers","timbernigger","tinkle","tit","titbitnipply","titfuck","titfucker","titfuckin","titi","titjob","titlicker","titlover","tits","titt","tittie","tittie5","tittiefucker","titties","tittis","titty","tittyfuck","tittyfucker","tittys","tittywank","titwank","tity","to murder","toke","tongethruster","tongue in a","tongueina","tonguethrust","tonguetramp","toots","topless","tortur","torture","tosser","towel head","towel heads","towelhead","trailertrash","tramp","trannie","tranny","transsexual","transvestite","trashy","tribadism","triplex","trisexual","trois","trojan","trots","tub girl","tubgirl","tuckahoe","tunneloflove","turd burgler","turnon","tush","tushy","tw4t","twat","twathead","twatlips","twats","twatty","twatwaffle","twink","twinkie","two girls one cup","twobitwhore","twunt","twunter","udge packer","ukrop","unclefucker","undressing","unfuckable","upskirt","uptheass","upthebutt","urethra play","urethraplay","urophilia","usama","ussys","uzi","v a g i n a","v14gra","v1gra","v4gra","va-j-j","va1jina","vag","vag1na","vagiina","vaj1na","vajina","valium","venus mound","vgra","vibr","vibrater","vibrator","vigra","violet wand","virgin","virginbreaker","vittu","vixen","vjayjay","vodka","vomit","vorarephilia","voyeurweb","voyuer","vullva","vulva","w00se","w0p","wab","wad","wang","wank","wanker","wanking","wanky","waysted","wazoo","weenie","weewee","weiner","welcher","wench","wet dream","wetb","wetback","wetbacks","wetdream","wetspot","wh00r","wh0re","wh0reface","whacker","whash","whigger","whiggers","whiskeydick","whiskydick","whit","white power","white trash","whitenigger","whitepower","whites","whitetrash","whitey","whiteys","whities","whoar","whop","whoralicious","whore","whorealicious","whorebag","whored","whoreface","whorefucker","whorehopper","whorehouse","whores","whoring","wichser","wigga","wiggas","wigger","wiggers","willie","willies","williewanker","willy","wn","wog","wogs","woose","wop","worldsex","wrapping men","wrinkled starfish","wtf","wuss","wuzzie","x-rated","x-rated2g1c","xkwe","xrated","xtc","xx","xxx","xxxxxx","yank","yaoi","yarpie","yarpies","yeasty","yed","yellow showers","yellowman","yellowshowers","yid","yids","yiffy","yobbo","yourboobs","yourpenis","yourtits","yury","zabourah","zigabo","zigabos","zipperhead","zipperheads","zoophile","zoophilia","🖕"];const Dc=_c(Sc),Ec=(s,e=300)=>{let t;return function(...n){clearTimeout(t),t=setTimeout(()=>s.apply(this,n),e)}},ni=`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`,kl=`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 sr(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=kl}else{if(i.scale>=i.maxScale){l.style.cursor="not-allowed";return}l.style.cursor=nr}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 rr={[E.CanMove]:{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:u}=i.getBoundingClientRect();u>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"},[E.CanSpin]:{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"},[E.CanToggle]:{defaultData:!1,updateElement:({element:n,data:t})=>{n.classList.toggle("clicked",t)},onClick:(n,{data:t,setData:e})=>{e(!t)},resetShortcut:"shiftKey"},[E.CanGrow]:{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=nr,t.scale>=r.maxScale)return;i+=.1}s({...t,scale:i})},additionalSetup:n=>{n.getElement().addEventListener("mouseenter",t=>{sr(t,n);const e=s=>sr(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"},[E.CanPost]:{defaultData:[],defaultLocalData:{addedEntries:new Set},updateElement:({data:n,localData:{addedEntries:t},setLocalData:e})=>{const s=n.filter(i=>!t.has(i.id)),r=bn("guestbookMessages");s.forEach(i=>{const o=document.createElement("div");o.classList.add("guestbook-entry");const l=new Date(i.timestamp),c=l.toTimeString().split(" ")[0],a=l.toDateString()===new Date().toDateString(),h=(()=>a?"Today ":new Date().getDate()-l.getDate()===1?"Yesterday ":new Date().getDate()-l.getDate()<7?"This week ":"Sometime before ")();o.innerHTML=`
7
- <span class="guestbook-entry-timestamp">${h}${c}</span><span class="guestbook-entry-name">${i.name}</span> <span class="guestbook-entry-message">${i.message}</span>`,r.prepend(o),t.add(i.id)}),e({addedEntries:t})},additionalSetup:({getElement:n,getData:t,setData:e})=>{n().addEventListener("submit",r=>{r.preventDefault(),r.stopImmediatePropagation();const i=t(),o=new FormData(r.target),l=Object.fromEntries(o.entries()),c=Date.now(),a={name:"someone",message:"something",...l,timestamp:c,id:`${c}-${l.name}`};return e([...i,a]),!1})}},[E.CanDuplicate]:{defaultData:[],defaultLocalData:[],updateElement:({data:n,localData:t,setLocalData:e,element:s})=>{var h;const r=s.getAttribute(E.CanDuplicate),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 l=s.getAttribute(bl);function c(u){if(l){const d=document.getElementById(l)||document.querySelector(l);if(d){d.appendChild(u);return}}i.parentNode.insertBefore(u,(o||i).nextSibling)}const a=new Set(t);for(const u of n){if(a.has(u))continue;const d=i.cloneNode(!0);Object.assign(d,{...i}),d.id=u,c(d),t.push(u),Sn.setupPlayElement(d),o=d}e(t)},onClick:(n,{data:t,element:e,setData:s})=>{const i=e.getAttribute(E.CanDuplicate)+"-"+Math.random().toString(36).substr(2,9);s([...t,i])}}};class Sl{constructor({element:t,onChange:e,onAwarenessChange:s,defaultData:r,defaultLocalData:i,myDefaultAwareness:o,data:l,awareness:c,updateElement:a,updateElementAwareness:h,onClick:u,onDrag:d,onDragStart:f,additionalSetup:g,resetShortcut:m,debounceMs:O,triggerAwarenessUpdate:qt}){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");this.element=t,this.defaultData=r instanceof Function?r(t):r,this.localData=i instanceof Function?i(t):i,this.triggerAwarenessUpdate=qt,this.onChange=e,this.resetShortcut=m,this.debouncedOnChange=_l(this.onChange,O),this.onAwarenessChange=s,this.updateElement=a,this.updateElementAwareness=h;const hr=l===void 0?this.defaultData:l;c!==void 0&&(this.__awareness=c);const ur=o instanceof Function?o(t):o;ur!==void 0&&this.setLocalAwareness(ur),this._data=hr,this.__data=hr,u&&t.addEventListener("click",R=>{u(R,this.getEventHandlerData())}),d&&(t.addEventListener("touchstart",R=>{R.preventDefault(),f&&f(R,this.getEventHandlerData());const Pt=mt=>{mt.preventDefault(),d(mt,this.getEventHandlerData())},Qt=mt=>{document.removeEventListener("touchmove",Pt),document.removeEventListener("touchend",Qt)};document.addEventListener("touchmove",Pt),document.addEventListener("touchend",Qt)}),t.addEventListener("mousedown",R=>{f&&f(R,this.getEventHandlerData());const Pt=mt=>{mt.preventDefault(),d(mt,this.getEventHandlerData())},Qt=mt=>{document.removeEventListener("mousemove",Pt),document.removeEventListener("mouseup",Qt)};document.addEventListener("mousemove",Pt),document.addEventListener("mouseup",Qt)})),g&&g(this.getSetupData()),m&&(t.title||(t.title=`Hold down the ${yl[m]} key while clicking to reset.`),t.reset=this.reset,t.addEventListener("click",R=>{switch(m){case"ctrlKey":if(!R.ctrlKey)return;break;case"altKey":if(!R.altKey)return;break;case"shiftKey":if(!R.shiftKey)return;break;case"metaKey":if(!R.metaKey)return;break;default:return}this.reset(),R.preventDefault(),R.stopPropagation()}))}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 Dl="playhtml.spencerc99.partykit.dev",yn=new Dt,ir=window.location.href,vt=new nl(Dl,ir,yn);new ml(ir,yn);const P=yn.getMap("playhtml-global"),wt=new Map,or=new Map;let lr=!0;function El(n){return n.id}function bn(n){return document.getElementById(n)}function Cl(n,t){const e=vt.awareness.getLocalState();return((e==null?void 0:e[n])??{})[t]}vt.on("sync",n=>{n||console.error("Issue connecting to yjs..."),kn()});function _n(n){return n instanceof HTMLElement}function Al(n,t,e,s){const r=P.get(t),i={...e,data:r.get(s)??e.defaultData,awareness:Cl(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=vt.awareness.getLocalState())==null?void 0:c[t])||{};l[s]!==o&&(l[s]=o,vt.awareness.setLocalStateField(t,l))},triggerAwarenessUpdate:()=>{cr()}};return new Sl(i)}function Il(n){return n.defaultData!==void 0&&n.updateElement!==void 0}function Ll(n,t){if(n===E.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}}return rr[n]}function cr(){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)}vt.awareness.getStates().forEach((e,s)=>{var r;for(const[i,o]of Object.entries(e)){const l=wt.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=wt.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 u=Array.from(h);a.__awareness=u}}})}function kn(){console.log(`࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂
6
+ auto`,Cc=`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 ii(s,{getData:e,getElement:t,getLocalData:n,setLocalData:i}){const r=e(),o=n(),c=t();if(o.isHovering=!0,s.altKey){if(r.scale<=.5){c.style.cursor="not-allowed";return}c.style.cursor=Cc}else{if(r.scale>=r.maxScale){c.style.cursor="not-allowed";return}c.style.cursor=ni}i(o)}function Dt(s){if("touches"in s){const{clientX:e,clientY:t}=s.touches[0];return{clientX:e,clientY:t}}return{clientX:s.clientX,clientY:s.clientY}}const ri={[E.CanMove]:{defaultData:{x:0,y:0},defaultLocalData:{startMouseX:0,startMouseY:0},updateElement:({element:s,data:e})=>{s.style.transform=`translate(${e.x}px, ${e.y}px)`},onDragStart:(s,{setLocalData:e})=>{const{clientX:t,clientY:n}=Dt(s);e({startMouseX:t,startMouseY:n})},onDrag:(s,{data:e,localData:t,setData:n,setLocalData:i,element:r})=>{const{clientX:o,clientY:c}=Dt(s),{top:a,left:l,bottom:h,right:u}=r.getBoundingClientRect();u>window.outerWidth&&o>t.startMouseX||h>window.innerHeight&&c>t.startMouseY||l<0&&o<t.startMouseX||a<0&&c<t.startMouseY||(n({x:e.x+o-t.startMouseX,y:e.y+c-t.startMouseY}),i({startMouseX:o,startMouseY:c}))},resetShortcut:"shiftKey"},[E.CanSpin]:{defaultData:{rotation:0},defaultLocalData:{startMouseX:0},updateElement:({element:s,data:e})=>{s.style.transform=`rotate(${e.rotation}deg)`},onDragStart:(s,{setLocalData:e})=>{const{clientX:t}=Dt(s);e({startMouseX:t})},onDrag:(s,{data:e,localData:t,setData:n,setLocalData:i})=>{const{clientX:r}=Dt(s);let o=Math.abs(r-t.startMouseX)*2,c=e.rotation;r>t.startMouseX?c+=o:r<t.startMouseX&&(c-=o),n({rotation:c}),i({startMouseX:r})},resetShortcut:"shiftKey"},[E.CanToggle]:{defaultData:!1,updateElement:({element:s,data:e})=>{s.classList.toggle("clicked",e)},onClick:(s,{data:e,setData:t})=>{t(!e)},resetShortcut:"shiftKey"},[E.CanGrow]:{defaultData:{scale:1},defaultLocalData:{maxScale:2,isHovering:!1},updateElement:({element:s,data:e})=>{s.style.transform=`scale(${e.scale})`},onClick:(s,{data:e,element:t,setData:n,localData:i})=>{let{scale:r}=e;if(s.altKey){if(e.scale<=.5)return;r-=.1}else{if(t.style.cursor=ni,e.scale>=i.maxScale)return;r+=.1}n({...e,scale:r})},additionalSetup:s=>{s.getElement().addEventListener("mouseenter",e=>{ii(e,s);const t=n=>ii(n,s);document.addEventListener("keydown",t),document.addEventListener("keyup",t),s.getElement().addEventListener("mouseleave",n=>{document.removeEventListener("keydown",t),document.removeEventListener("keyup",t)})})},resetShortcut:"shiftKey"},[E.CanPost]:{defaultData:[],defaultLocalData:{addedEntries:new Set},updateElement:({data:s,localData:{addedEntries:e},setLocalData:t})=>{const n=s.filter(r=>!e.has(r.id)),i=si("guestbookMessages");n.forEach(r=>{const o=document.createElement("div");o.classList.add("guestbook-entry");const c=new Date(r.timestamp),a=c.toTimeString().split(" ")[0],l=c.toDateString()===new Date().toDateString(),h=(()=>{const u=new Date;return u.getFullYear()!==c.getFullYear()||u.getMonth()!==c.getMonth()?"Sometime before":l?"Today":u.getDate()-c.getDate()===1?"Yesterday":u.getDate()-c.getDate()<7?"This week":"Sometime before"})();o.innerHTML=`
7
+ <span class="guestbook-entry-timestamp">${h} at ${a}</span><span class="guestbook-entry-name"></span> <span class="guestbook-entry-message"></span>`,i.prepend(o),o.querySelector(".guestbook-entry-name")&&(o.querySelector(".guestbook-entry-name").innerText=r.name),o.querySelector(".guestbook-entry-message")&&(o.querySelector(".guestbook-entry-message").innerText=r.message),e.add(r.id)}),t({addedEntries:e})},additionalSetup:({getElement:s,getData:e,setData:t})=>{const n=s();n.addEventListener("submit",i=>{i.preventDefault(),i.stopImmediatePropagation();const r=e(),o=new FormData(i.target);function c(){const u=n.querySelector('input[name="message"]');u&&(u.value="")}const a=Object.fromEntries(o.entries());if(!a.name)return c(),!1;if(Dc.some(u=>{const d=new RegExp(`\\b${u}\\b`,"gi");return d.test(a.message)||d.test(a.name)}))return alert("now why would you try to do something like that?"),c(),!1;const l=Date.now(),h={name:"someone",message:"something",...a,timestamp:l,id:`${l}-${a.name}`};return t([...r,h]),c(),!1})}},[E.CanDuplicate]:{defaultData:[],defaultLocalData:[],updateElement:({data:s,localData:e,setLocalData:t,element:n})=>{var h;const i=n.getAttribute(E.CanDuplicate),r=document.getElementById(i);let o=document.getElementById((h=e.slice(-1))==null?void 0:h[0])??null;if(!r){console.error(`Element with id ${i} not found. Cannot duplicate.`);return}const c=n.getAttribute(wc);function a(u){if(c){const d=document.getElementById(c)||document.querySelector(c);if(d){d.appendChild(u);return}}r.parentNode.insertBefore(u,(o||r).nextSibling)}const l=new Set(e);for(const u of s){if(l.has(u))continue;const d=r.cloneNode(!0);Object.assign(d,{...r}),d.id=u,a(d),e.push(u),window.playhtml.setupPlayElement(d),o=d}t(e)},onClick:(s,{data:e,element:t,setData:n})=>{const r=t.getAttribute(E.CanDuplicate)+"-"+Math.random().toString(36).substr(2,9);n([...e,r])}}};class vc{constructor({element:e,onChange:t,onAwarenessChange:n,defaultData:i,defaultLocalData:r,myDefaultAwareness:o,data:c,awareness:a,updateElement:l,updateElementAwareness:h,onClick:u,onDrag:d,onDragStart:f,additionalSetup:g,resetShortcut:m,debounceMs:U,triggerAwarenessUpdate:We}){b(this,"defaultData");b(this,"localData");b(this,"awareness",[]);b(this,"selfAwareness");b(this,"element");b(this,"_data");b(this,"onChange");b(this,"onAwarenessChange");b(this,"debouncedOnChange");b(this,"resetShortcut");b(this,"updateElement");b(this,"updateElementAwareness");b(this,"triggerAwarenessUpdate");this.element=e,this.defaultData=i instanceof Function?i(e):i,this.localData=r instanceof Function?r(e):r,this.triggerAwarenessUpdate=We,this.onChange=t,this.resetShortcut=m,this.debouncedOnChange=Ec(this.onChange,U),this.onAwarenessChange=n,this.updateElement=l,this.updateElementAwareness=h;const hi=c===void 0?this.defaultData:c;a!==void 0&&(this.__awareness=a);const ui=o instanceof Function?o(e):o;ui!==void 0&&this.setLocalAwareness(ui),this._data=hi,this.__data=hi,u&&e.addEventListener("click",z=>{u(z,this.getEventHandlerData())}),d&&(e.addEventListener("touchstart",z=>{z.preventDefault(),f&&f(z,this.getEventHandlerData());const Pe=be=>{be.preventDefault(),d(be,this.getEventHandlerData())},Qe=be=>{document.removeEventListener("touchmove",Pe),document.removeEventListener("touchend",Qe)};document.addEventListener("touchmove",Pe),document.addEventListener("touchend",Qe)}),e.addEventListener("mousedown",z=>{f&&f(z,this.getEventHandlerData());const Pe=be=>{be.preventDefault(),d(be,this.getEventHandlerData())},Qe=be=>{document.removeEventListener("mousemove",Pe),document.removeEventListener("mouseup",Qe)};document.addEventListener("mousemove",Pe),document.addEventListener("mouseup",Qe)})),g&&g(this.getSetupData()),m&&(e.title||(e.title=`Hold down the ${bc[m]} key while clicking to reset.`),e.reset=this.reset,e.addEventListener("click",z=>{switch(m){case"ctrlKey":if(!z.ctrlKey)return;break;case"altKey":if(!z.altKey)return;break;case"shiftKey":if(!z.shiftKey)return;break;case"metaKey":if(!z.metaKey)return;break;default:return}this.reset(),z.preventDefault(),z.stopPropagation()}))}get data(){return this._data}setLocalData(e){this.localData=e}set __data(e){this._data=e,this.updateElement(this.getEventHandlerData())}set __awareness(e){this.updateElementAwareness&&(this.awareness=e,this.updateElementAwareness(this.getAwarenessEventHandlerData()))}getEventHandlerData(){return{element:this.element,data:this.data,localData:this.localData,awareness:this.awareness,setData:e=>this.setData(e),setLocalData:e=>this.setLocalData(e),setLocalAwareness:e=>this.setLocalAwareness(e)}}getAwarenessEventHandlerData(){return{...this.getEventHandlerData(),myAwareness:this.selfAwareness}}getSetupData(){return{getElement:()=>this.element,getData:()=>this.data,getLocalData:()=>this.localData,getAwareness:()=>this.awareness,setData:e=>this.setData(e),setLocalData:e=>this.setLocalData(e),setLocalAwareness:e=>this.setLocalAwareness(e)}}setData(e){this.onChange(e)}setLocalAwareness(e){var t;e!==this.selfAwareness&&(this.selfAwareness=e,this.onAwarenessChange(e),(t=this.triggerAwarenessUpdate)==null||t.call(this))}setDataDebounced(e){this.debouncedOnChange(e)}reset(){this.setData(this.defaultData)}}const Ac="playhtml.spencerc99.partykit.dev",bs=new Ee,xc=window.location.href;let me,$,ie;const oi=new Map;let ws=!0;function ci({room:s=xc,host:e=Ac}={}){if(!ws){console.error("playhtml already set up!");return}const t=e;console.log(`࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂
8
8
  ࿂࿂࿂࿂ ࿂ ࿂ ࿂ ࿂ ࿂ ࿂࿂࿂࿂
9
9
  ࿂࿂࿂࿂ booting up playhtml... ࿂࿂࿂࿂
10
10
  ࿂࿂࿂࿂ https://playhtml.fun ࿂࿂࿂࿂
11
11
  ࿂࿂࿂࿂ ࿂ ࿂ ࿂ ࿂ ࿂࿂࿂࿂
12
- ࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂`);for(const n of Object.values(E)){const t=Array.from(document.querySelectorAll(`[${n}]`)).filter(_n);if(t.length)for(let e=0;e<t.length;e++){const s=t[e];Ee(s,n)}}lr&&(P.observe(n=>{n.changes.keys.forEach((t,e)=>{t.action==="add"&&P.set(e,P.get(e))})}),vt.awareness.on("change",()=>cr()),lr=!1)}const Sn={setupElements:kn,globalData:P,elementHandlers:wt,setupPlayElement:ar};window.playhtml=Sn;function Ml(n){if(wt.has(n))return;wt.set(n,new Map),n!==E.CanPlay&&rr[n],P.get(n)||P.set(n,new ht);const t=P.get(n);t.observe(e=>{e.changes.keys.forEach((s,r)=>{const i=wt.get(n);if(s.action==="add"){const o=bn(r);if(!_n(o)){console.log(`Element ${r} not an HTML element. Ignoring.`);return}Ee(o,n)}else if(s.action==="update"){const o=i.get(r);o.__data=t.get(r)}else s.action==="delete"?i.delete(r):console.log(`Unhandled action: ${s.action}`)})})}function vl(n,t){const e=n.getAttribute(t);switch(t){case E.CanPlay:case E.CanMove:case E.CanSpin:case E.CanGrow:case E.CanToggle:case E.CanPost:return!0;case E.CanDuplicate:return e?(document.getElementById(e)||console.warn(`${E.CanDuplicate} element (${n.id}) duplicate element ("${e}") not found.`),!0):!1;default:return console.error(`Unhandled tag found in validation: ${t}`),!1}}function Ee(n,t){var l;if(!vl(n,t))return;if(!n.id){const c=n.getAttribute("selector-id");if(c){const a=or.get(c)??0;n.id=btoa(`${t}-${c}-${a}`),or.set(c,a+1)}else n.id=btoa(`${t}-${n.innerHTML}}`)}const e=El(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}Ml(t);const s=wt.get(t);if(s.has(e))return;const r=Ll(t,n);if(!Il(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=P.get(t),o=Al(n,t,r,e);s.set(e,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 ar(n){if(!_n(n)){console.log(`Element ${n.id} not an HTML element. Ignoring.`);return}for(const t of Object.values(E))n.hasAttribute(t)&&Ee(n,t)}v.getElementFromId=bn,v.playhtml=Sn,v.setupElements=kn,v.setupPlayElement=ar,v.setupPlayElementForTag=Ee,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
12
+ ࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂`),me=new sc(t,s,bs),$=bs.getMap("playhtml-global"),ie=new Map,new mc(s,bs),Et.globalData=$,Et.elementHandlers=ie,me.on("sync",n=>{n||console.error("Issue connecting to yjs..."),_s()})}function Ic(s,e){const t=me.awareness.getLocalState();return((t==null?void 0:t[s])??{})[e]}function ys(s){return s instanceof HTMLElement}function Lc(s,e,t,n){const i=$.get(e),r={...t,data:i.get(n)??t.defaultData,awareness:Ic(e,n)??t.myDefaultAwareness!==void 0?[t.myDefaultAwareness]:void 0,element:s,onChange:o=>{i.get(n)!==o&&i.set(n,o)},onAwarenessChange:o=>{var a;const c=((a=me.awareness.getLocalState())==null?void 0:a[e])||{};c[n]!==o&&(c[n]=o,me.awareness.setLocalStateField(e,c))},triggerAwarenessUpdate:()=>{ai()}};return new vc(r)}function jc(s){return s.defaultData!==void 0&&s.updateElement!==void 0}function Mc(s,e){if(s===E.CanPlay){const t=e;return{defaultData:t.defaultData,defaultLocalData:t.defaultLocalData,myDefaultAwareness:t.myDefaultAwareness,updateElement:t.updateElement,updateElementAwareness:t.updateElementAwareness,onDrag:t.onDrag,onDragStart:t.onDragStart,onClick:t.onClick,additionalSetup:t.additionalSetup,resetShortcut:t.resetShortcut,debounceMs:t.debounceMs}}return ri[s]}function ai(){const s=new Map;function e(t,n,i,r){s.has(t)||s.set(t,new Map);const o=s.get(t);o.has(n)||o.set(n,new Map),o.get(n).set(i,r)}me.awareness.getStates().forEach((t,n)=>{var i;for(const[r,o]of Object.entries(t)){const c=ie.get(r);if(c)for(const[a,l]of c){if(!(a in o))continue;const h=o[a];e(r,a,n,h)}}for(const[r,o]of s){const c=ie.get(r);if(c)for(const[a,l]of c){const h=(i=o.get(a))==null?void 0:i.values();if(!h)continue;let u=Array.from(h);l.__awareness=u}}})}function _s(){console.log("[PLAYHTML]: Setting up elements... Time to have some fun 🛝");for(const s of Object.values(E)){const e=Array.from(document.querySelectorAll(`[${s}]`)).filter(ys);if(e.length)for(let t=0;t<e.length;t++){const n=e[t];Ct(n,s)}}ws&&($.observe(s=>{s.changes.keys.forEach((e,t)=>{e.action==="add"&&$.set(t,$.get(t))})}),me.awareness.on("change",()=>ai()),ws=!1)}const Et={init:ci,setupElements:_s,setupPlayElement:li,globalData:void 0,elementHandlers:void 0};window.playhtml=Et;function Tc(s){if(ie.has(s))return;ie.set(s,new Map),s!==E.CanPlay&&ri[s],$.get(s)||$.set(s,new ue);const e=$.get(s);e.observe(t=>{t.changes.keys.forEach((n,i)=>{const r=ie.get(s);if(n.action==="add"){const o=si(i);if(!ys(o)){console.log(`Element ${i} not an HTML element. Ignoring.`);return}Ct(o,s)}else if(n.action==="update"){const o=r.get(i);o.__data=e.get(i)}else n.action==="delete"?r.delete(i):console.log(`Unhandled action: ${n.action}`)})})}function Uc(s,e){const t=s.getAttribute(e);switch(e){case E.CanPlay:case E.CanMove:case E.CanSpin:case E.CanGrow:case E.CanToggle:case E.CanPost:return!0;case E.CanDuplicate:return t?(document.getElementById(t)||console.warn(`${E.CanDuplicate} element (${s.id}) duplicate element ("${t}") not found.`),!0):!1;default:return console.error(`Unhandled tag found in validation: ${e}`),!1}}function Ct(s,e){var c;if(!Uc(s,e))return;if(!s.id){const a=s.getAttribute("selector-id");if(a){const l=oi.get(a)??0;s.id=btoa(`${e}-${a}-${l}`),oi.set(a,l+1)}else s.id=btoa(`${e}-${s.innerHTML}}`)}const t=yc(s);if(!t){console.error(`Element ${s} does not have an acceptable ID. Please add an ID to the element to register it as a playhtml element.`);return}Tc(e);const n=ie.get(e);if(n.has(t))return;const i=Mc(e,s);if(!jc(i)){console.error(`Element ${t} 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 r=$.get(e),o=Lc(s,e,i,t);n.set(t,o),r.get(t)===void 0&&i.defaultData!==void 0&&r.set(t,i.defaultData),(c=o.triggerAwarenessUpdate)==null||c.call(o),s.classList.add("__playhtml-element"),s.classList.add(`__playhtml-${e}`),s.style.setProperty("--jiggle-delay",`${Math.random()*1}s;}`)}function li(s){if(!ys(s)){console.log(`Element ${s.id} not an HTML element. Ignoring.`);return}for(const e of Object.values(E))s.hasAttribute(e)&&Ct(s,e)}L.initPlayHTML=ci,L.playhtml=Et,L.setupElements=_s,L.setupPlayElement=li,L.setupPlayElementForTag=Ct,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})});