PageSourceSearch

https://wewere.online/assets/index-B8a2M02w.js

js wewere.online collected 2026-10-08 09:22:18 UTC 216,303 bytes, 41 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/cursor-client-BWUq_OlJ.js","assets/preload-helper-BlTxHScW.js","assets/development-Dr8fEiSP.js"])))=>i.map(i=>d[i]);
2import{_ as _c}from"./preload-helper-BlTxHScW.js";const Yi=1,Ji=2,Bs=4,Vs=8,Bt=32,ve=64,ee=128,bs=31,ur=63,Ke=127,Eu=2147483647,he=Math.floor,Nn=Math.abs,Br=(t,e)=>t<e?t:e,nt=(t,e)=>t>e?t:e,vu=Math.pow,Ec=t=>t!==0?t<0:1/t<0,Kn=Number.MAX_SAFE_INTEGER,qi=Number.MIN_SAFE_INTEGER,Su=Number.isInteger||(t=>typeof t=="number"&&isFinite(t)&&he(t)===t),Re=()=>new Set,Ws=t=>t[t.length-1],Au=(t,e)=>{for(let n=0;n<e.length;n++)t.push(e[n])},Se=Array.from,Vr=(t,e)=>{for(let n=0;n<t.length;n++)if(!e(t[n],n,t))return!1;return!0},vc=(t,e)=>{for(let n=0;n<t.length;n++)if(e(t[n],n,t))return!0;return!1},Cu=(t,e)=>{const n=new Array(t);for(let s=0;s<t;s++)n[s]=e(s,n);return n},_s=Array.isArray,Sc=String.fromCharCode,ku=t=>t.toLowerCase(),Du=/^\s*/g,Lu=t=>t.replace(Du,""),Ou=/([A-Z])/g,Gi=(t,e)=>Lu(t.replace(Ou,n=>`${e}${ku(n)}`)),Iu=t=>{const e=unescape(encodeURIComponent(t)),n=e.length,s=new Uint8Array(n);for(let r=0;r<n;r++)s[r]=e.codePointAt(r);return s},Vt=typeof TextEncoder<"u"?new TextEncoder:null,Pu=t=>Vt.encode(t),Tu=Vt?Pu:Iu;let Rt=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Rt&&Rt.decode(new Uint8Array).length===1&&(Rt=null);const xu=(t,e)=>Cu(e,()=>t).join(""),ye=t=>new Error(t),le=()=>{throw ye("Method unimplemented")},ie=()=>{throw ye("Unexpected case")};class dn{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const W=()=>new dn,Wr=t=>{let e=t.cpos;for(let n=0;n<t.bufs.length;n++)e+=t.bufs[n].length;return e},A=t=>{const e=new Uint8Array(Wr(t));let n=0;for(let s=0;s<t.bufs.length;s++){const r=t.bufs[s];e.set(r,n),n+=r.length}return e.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),n),e},Mu=(t,e)=>{const n=t.cbuf.length;n-t.cpos<e&&(t.bufs.push(new Uint8Array(t.cbuf.buffer,0,t.cpos)),t.cbuf=new Uint8Array(nt(n,e)*2),t.cpos=0)},M=(t,e)=>{const n=t.cbuf.length;t.cpos===n&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(n*2),t.cpos=0),t.cbuf[t.cpos++]=e},hr=M,m=(t,e)=>{for(;e>Ke;)M(t,ee|Ke&e),e=he(e/128);M(t,Ke&e)},zr=(t,e)=>{const n=Ec(e);for(n&&(e=-e),M(t,(e>ur?ee:0)|(n?ve:0)|ur&e),e=he(e/64);e>0;)M(t,(e>Ke?ee:0)|Ke&e),e=he(e/128)},dr=new Uint8Array(3e4),$u=dr.length/3,Ru=(t,e)=>{if(e.length<$u){const n=Vt.encodeInto(e,dr).written||0;m(t,n);for(let s=0;s<n;s++)M(t,dr[s])}else L(t,Tu(e))},Nu=(t,e)=>{const n=unescape(encodeURIComponent(e)),s=n.length;m(t,s);for(let r=0;r<s;r++)M(t,n.codePointAt(r))},Ye=Vt&&Vt.encodeInto?Ru:Nu,Es=(t,e)=>{const n=t.cbuf.length,s=t.cpos,r=Br(n-s,e.length),i=e.length-r;t.cbuf.set(e.subarray(0,r),s),t.cpos+=r,i>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(nt(n*2,i)),t.cbuf.set(e.subarray(r)),t.cpos=i)},L=(t,e)=>{m(t,e.byteLength),Es(t,e)},Kr=(t,e)=>{Mu(t,e);const n=new DataView(t.cbuf.buffer,t.cpos,e);return t.cpos+=e,n},Uu=(t,e)=>Kr(t,4).setFloat32(0,e,!1),ju=(t,e)=>Kr(t,8).setFloat64(0,e,!1),Hu=(t,e)=>Kr(t,8).setBigInt64(0,e,!1),Xi=new DataView(new ArrayBuffer(4)),Fu=t=>(Xi.setFloat32(0,t),Xi.getFloat32(0)===t),Wt=(t,e)=>{switch(typeof e){case"string":M(t,119),Ye(t,e);break;case"number":Su(e)&&Nn(e)<=Eu?(M(t,125),zr(t,e)):Fu(e)?(M(t,124),Uu(t,e)):(M(t,123),ju(t,e));break;case"bigint":M(t,122),Hu(t,e);break;case"object":if(e===null)M(t,126);else if(_s(e)){M(t,117),m(t,e.length);for(let n=0;n<e.length;n++)Wt(t,e[n])}else if(e instanceof Uint8Array)M(t,116),L(t,e);else{M(t,118);const n=Object.keys(e);m(t,n.length);for(let s=0;s<n.length;s++){const r=n[s];Ye(t,r),Wt(t,e[r])}}break;case"boolean":M(t,e?120:121);break;default:M(t,127)}};class Qi extends dn{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&m(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const Zi=t=>{t.count>0&&(zr(t.encoder,t.count===1?t.s:-t.s),t.count>1&&m(t.encoder,t.count-2))};class Un{constructor(){this.encoder=new dn,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Zi(this),this.count=1,this.s=e)}toUint8Array(){return Zi(this),A(this.encoder)}}const eo=t=>{if(t.count>0){const e=t.diff*2+(t.count===1?0:1);zr(t.encoder,e),t.count>1&&m(t.encoder,t.count-2)}};class zs{constructor(){this.encoder=new dn,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(eo(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return eo(this),A(this.encoder)}}class Bu{constructor(){this.sarr=[],this.s="",this.lensE=new Un}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 dn;return this.sarr.push(this.s),this.s="",Ye(e,this.sarr.join("")),Es(e,this.lensE.toUint8Array()),A(e)}}const Ac=ye("Unexpected end of array"),Cc=ye("Integer out of Range");class vs{constructor(e){this.arr=e,this.pos=0}}const je=t=>new vs(t),Vu=t=>t.pos!==t.arr.length,Wu=(t,e)=>{const n=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,n},V=t=>Wu(t,w(t)),yt=t=>t.arr[t.pos++],w=t=>{let e=0,n=1;const s=t.arr.length;for(;t.pos<s;){const r=t.arr[t.pos++];if(e=e+(r&Ke)*n,n*=128,r<ee)return e;if(e>Kn)throw Cc}throw Ac},Yr=t=>{let e=t.arr[t.pos++],n=e&ur,s=64;const r=(e&ve)>0?-1:1;if((e&ee)===0)return r*n;const i=t.arr.length;for(;t.pos<i;){if(e=t.arr[t.pos++],n=n+(e&Ke)*s,s*=128,e<ee)return r*n;if(n>Kn)throw Cc}throw Ac},zu=t=>{let e=w(t);if(e===0)return"";{let n=String.fromCodePoint(yt(t));if(--e<100)for(;e--;)n+=String.fromCodePoint(yt(t));else for(;e>0;){const s=e<1e4?e:1e4,r=t.arr.subarray(t.pos,t.pos+s);t.pos+=s,n+=String.fromCodePoint.apply(null,r),e-=s}return decodeURIComponent(escape(n))}},Ku=t=>Rt.decode(V(t)),Me=Rt?Ku:zu,Jr=(t,e)=>{const n=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,e);return t.pos+=e,n},Yu=t=>Jr(t,4).getFloat32(0,!1),Ju=t=>Jr(t,8).getFloat64(0,!1),qu=t=>Jr(t,8).getBigInt64(0,!1),Gu=[t=>{},t=>null,Yr,Yu,Ju,qu,t=>!1,t=>!0,Me,t=>{const e=w(t),n={};for(let s=0;s<e;s++){const r=Me(t);n[r]=zt(t)}return n},t=>{const e=w(t),n=[];for(let s=0;s<e;s++)n.push(zt(t));return n},V],zt=t=>Gu[127-yt(t)](t);class to extends vs{constructor(e,n){super(e),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Vu(this)?this.count=w(this)+1:this.count=-1),this.count--,this.s}}class jn extends vs{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=Yr(this);const e=Ec(this.s);this.count=1,e&&(this.s=-this.s,this.count=w(this)+2)}return this.count--,this.s}}class Ks extends vs{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const e=Yr(this),n=e&1;this.diff=he(e/2),this.count=1,n&&(this.count=w(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Xu{constructor(e){this.decoder=new jn(e),this.str=Me(this.decoder),this.spos=0}read(){const e=this.spos+this.decoder.read(),n=this.str.slice(this.spos,e);return this.spos=e,n}}
2const mt=Date.now,X=()=>new Map,fr=t=>{const e=X();return t.forEach((n,s)=>{e.set(s,n)}),e},_e=(t,e,n)=>{let s=t.get(e);return s===void 0&&t.set(e,s=n()),s},Qu=(t,e)=>{const n=[];for(const[s,r]of t)n.push(e(r,s));return n},Zu=(t,e)=>{for(const[n,s]of t)if(e(s,n))return!0;return!1};class eh{constructor(){this._observers=X()}on(e,n){return _e(this._observers,e,Re).add(n),n}once(e,n){const s=(...r)=>{this.off(e,s),n(...r)};this.on(e,s)}off(e,n){const s=this._observers.get(e);s!==void 0&&(s.delete(n),s.size===0&&this._observers.delete(e))}emit(e,n){return Se((this._observers.get(e)||X()).values()).forEach(s=>s(...n))}destroy(){this._observers=X()}}class kc{constructor(){this._observers=X()}on(e,n){_e(this._observers,e,Re).add(n)}once(e,n){const s=(...r)=>{this.off(e,s),n(...r)};this.on(e,s)}off(e,n){const s=this._observers.get(e);s!==void 0&&(s.delete(n),s.size===0&&this._observers.delete(e))}emit(e,n){return Se((this._observers.get(e)||X()).values()).forEach(s=>s(...n))}destroy(){this._observers=X()}}const Kt=Symbol("Equality"),Dc=(t,e)=>t===e||!!t?.[Kt]?.(e)||!1,th=t=>typeof t=="object",nh=Object.assign,sh=Object.keys,rh=(t,e)=>{for(const n in t)e(t[n],n)},ih=(t,e)=>{const n=[];for(const s in t)n.push(e(t[s],s));return n},Yn=t=>sh(t).length,oh=t=>{for(const e in t)return!1;return!0},fn=(t,e)=>{for(const n in t)if(!e(t[n],n))return!1;return!0},qr=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),ch=(t,e)=>t===e||Yn(t)===Yn(e)&&fn(t,(n,s)=>(n!==void 0||qr(e,s))&&Dc(e[s],n)),Gr=(t,e,n=0)=>{try{for(;n<t.length;n++)t[n](...e)}finally{n<t.length&&Gr(t,e,n+1)}},lh=t=>t,ht=(t,e)=>{if(t===e)return!0;if(t==null||e==null||t.constructor!==e.constructor&&(t.constructor||Object)!==(e.constructor||Object))return!1;if(t[Kt]!=null)return t[Kt](e);switch(t.constructor){case ArrayBuffer:t=new Uint8Array(t),e=new Uint8Array(e);case Uint8Array:{if(t.byteLength!==e.byteLength)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;break}case Set:{if(t.size!==e.size)return!1;for(const n of t)if(!e.has(n))return!1;break}case Map:{if(t.size!==e.size)return!1;for(const n of t.keys())if(!e.has(n)||!ht(t.get(n),e.get(n)))return!1;break}case void 0:case Object:if(Yn(t)!==Yn(e))return!1;for(const n in t)if(!qr(t,n)||!ht(t[n],e[n]))return!1;break;case Array:if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!ht(t[n],e[n]))return!1;break;default:return!1}return!0},ah=(t,e)=>e.includes(t),uh=crypto.getRandomValues.bind(crypto),Lc=()=>uh(new Uint32Array(1))[0],hh="10000000-1000-4000-8000"+-1e11,dh=()=>hh.replace(/[018]/g,t=>(t^Lc()&15>>t/4).toString(16)),no=t=>new Promise(t);Promise.all.bind(Promise);const so=t=>t===void 0?null:t;class fh{constructor(){this.map=new Map}setItem(e,n){this.map.set(e,n)}getItem(e){return this.map.get(e)}}let Oc=new fh,Xr=!0;try{typeof localStorage<"u"&&localStorage&&(Oc=localStorage,Xr=!1)}catch{}const Ic=Oc,ph=t=>Xr||addEventListener("storage",t),gh=t=>Xr||removeEventListener("storage",t);var Pc={};const wt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",Tc=typeof window<"u"&&typeof document<"u"&&!wt;let pe;const yh=()=>{if(pe===void 0)if(wt){pe=X();const t=process.argv;let e=null;for(let n=0;n<t.length;n++){const s=t[n];s[0]==="-"?(e!==null&&pe.set(e,""),e=s):e!==null&&(pe.set(e,s),e=null)}e!==null&&pe.set(e,"")}else typeof location=="object"?(pe=X(),(location.search||"?").slice(1).split("&").forEach(t=>{if(t.length!==0){const[e,n]=t.split("=");pe.set(`--${Gi(e,"-")}`,n),pe.set(`-${Gi(e,"-")}`,n)}})):pe=X();return pe},pr=t=>yh().has(t),gr=t=>so(wt?Pc[t.toUpperCase().replaceAll("-","_")]:Ic.getItem(t)),xc=t=>pr("--"+t)||gr(t)!==null,mh=xc("production"),wh=wt&&ah(Pc.FORCE_COLOR,["true","1","2"]),bh=wh||!pr("--no-colors")&&!xc("no-color")&&(!wt||process.stdout.isTTY)&&(!wt||pr("--color")||gr("COLORTERM")!==null||(gr("TERM")||"").includes("color")),Mc=t=>new Uint8Array(t),_h=(t,e,n)=>new Uint8Array(t,e,n),Eh=t=>new Uint8Array(t),vh=t=>{let e="";for(let n=0;n<t.byteLength;n++)e+=Sc(t[n]);return btoa(e)},Sh=t=>Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("base64"),Ah=t=>{const e=atob(t),n=Mc(e.length);for(let s=0;s<e.length;s++)n[s]=e.charCodeAt(s);return n},Ch=t=>{const e=Buffer.from(t,"base64");return _h(e.buffer,e.byteOffset,e.byteLength)},kh=Tc?vh:Sh,Dh=Tc?Ah:Ch,Lh=t=>{const e=Mc(t.byteLength);return e.set(t),e};class Oh{constructor(e,n){this.left=e,this.right=n}}const Ee=(t,e)=>new Oh(t,e),ro=t=>t.next()>=.5,Ys=(t,e,n)=>he(t.next()*(n+1-e)+e),$c=(t,e,n)=>he(t.next()*(n+1-e)+e),Qr=(t,e,n)=>$c(t,e,n),Ih=t=>Sc(Qr(t,97,122)),Ph=(t,e=0,n=20)=>{const s=Qr(t,e,n);let r="";for(let i=0;i<s;i++)r+=Ih(t);return r},Js=(t,e)=>e[Qr(t,0,e.length-1)],Th=Symbol("0schema");class xh{constructor(){this._rerrs=[]}extend(e,n,s,r=null){this._rerrs.push({path:e,expected:n,has:s,message:r})}toString(){const e=[];for(let n=this._rerrs.length-1;n>0;n--){const s=this._rerrs[n];e.push(xu(" ",(this._rerrs.length-n)*2)+`${s.path!=null?`[${s.path}] `:""}${s.has} doesn't match ${s.expected}. ${s.message}`)}return e.join(`
3`)}}const yr=(t,e)=>t===e?!0:t==null||e==null||t.constructor!==e.constructor?!1:t[Kt]?Dc(t,e):_s(t)?Vr(t,n=>vc(e,s=>yr(n,s))):th(t)?fn(t,(n,s)=>yr(n,e[s])):!1;class G{static _dilutes=!1;extends(e){let[n,s]=[this.shape,e.shape];return this.constructor._dilutes&&([s,n]=[n,s]),yr(n,s)}equals(e){return this.constructor===e.constructor&&ht(this.shape,e.shape)}[Th](){return!0}[Kt](e){return this.equals(e)}validate(e){return this.check(e)}check(e,n){le()}get nullable(){return Dt(this,Ds)}get optional(){return new Uc(this)}cast(e){return io(e,this),e}expect(e){return io(e,this),e}}class Zr extends G{constructor(e,n){super(),this.shape=e,this._c=n}check(e,n=void 0){const s=e?.constructor===this.shape&&(this._c==null||this._c(e));
3return!s&&n?.extend(null,this.shape.name,e?.constructor.name,e?.constructor!==this.shape?"Constructor match failed":"Check failed"),s}}const I=(t,e=null)=>new Zr(t,e);I(Zr);class ei extends G{constructor(e){super(),this.shape=e}check(e,n){const s=this.shape(e);return!s&&n?.extend(null,"custom prop",e?.constructor.name,"failed to check custom prop"),s}}const U=t=>new ei(t);I(ei);class Ss extends G{constructor(e){super(),this.shape=e}check(e,n){const s=this.shape.some(r=>r===e);return!s&&n?.extend(null,this.shape.join(" | "),e.toString()),s}}const As=(...t)=>new Ss(t),Rc=I(Ss),Mh=RegExp.escape||(t=>t.replace(/[().|&,$^[\]]/g,e=>"\\"+e)),Nc=t=>{if(bt.check(t))return[Mh(t)];if(Rc.check(t))return t.shape.map(e=>e+"");if(Yc.check(t))return["[+-]?\\d+.?\\d*"];if(Jc.check(t))return[".*"];if(Jn.check(t))return t.shape.map(Nc).flat(1);ie()};class $h extends G{constructor(e){super(),this.shape=e,this._r=new RegExp("^"+e.map(Nc).map(n=>`(${n.join("|")})`).join("")+"$")}check(e,n){const s=this._r.exec(e)!=null;return!s&&n?.extend(null,this._r.toString(),e.toString(),"String doesn't match string template."),s}}I($h);const Rh=Symbol("optional");class Uc extends G{constructor(e){super(),this.shape=e}check(e,n){const s=e===void 0||this.shape.check(e);return!s&&n?.extend(null,"undefined (optional)","()"),s}get[Rh](){return!0}}const Nh=I(Uc);class Uh extends G{check(e,n){return n?.extend(null,"never",typeof e),!1}}I(Uh);class Cs extends G{constructor(e,n=!1){super(),this.shape=e,this._isPartial=n}static _dilutes=!0;get partial(){return new Cs(this.shape,!0)}check(e,n){return e==null?(n?.extend(null,"object","null"),!1):fn(this.shape,(s,r)=>{const i=this._isPartial&&!qr(e,r)||s.check(e[r],n);return!i&&n?.extend(r.toString(),s.toString(),typeof e[r],"Object property does not match"),i})}}const jh=t=>new Cs(t),Hh=I(Cs),Fh=U(t=>t!=null&&(t.constructor===Object||t.constructor==null));class jc extends G{constructor(e,n){super(),this.shape={keys:e,values:n}}check(e,n){return e!=null&&fn(e,(s,r)=>{const i=this.shape.keys.check(r,n);return!i&&n?.extend(r+"","Record",typeof e,i?"Key doesn't match schema":"Value doesn't match value"),i&&this.shape.values.check(s,n)})}}const Hc=(t,e)=>new jc(t,e),Bh=I(jc);class Fc extends G{constructor(e){super(),this.shape=e}check(e,n){return e!=null&&fn(this.shape,(s,r)=>{const i=s.check(e[r],n);return!i&&n?.extend(r.toString(),"Tuple",typeof s),i})}}const Vh=(...t)=>new Fc(t);I(Fc);class Bc extends G{constructor(e){super(),this.shape=e.length===1?e[0]:new ti(e)}check(e,n){const s=_s(e)&&Vr(e,r=>this.shape.check(r));return!s&&n?.extend(null,"Array",""),s}}const Vc=(...t)=>new Bc(t),Wh=I(Bc),zh=U(t=>_s(t));class Wc extends G{constructor(e,n){super(),this.shape=e,this._c=n}check(e,n){const s=e instanceof this.shape&&(this._c==null||this._c(e));return!s&&n?.extend(null,this.shape.name,e?.constructor.name),s}}const Kh=(t,e=null)=>new Wc(t,e);I(Wc);const Yh=Kh(G);class Jh extends G{constructor(e){super(),this.len=e.length-1,this.args=Vh(...e.slice(-1)),this.res=e[this.len]}check(e,n){const s=e.constructor===Function&&e.length<=this.len;return!s&&n?.extend(null,"function",typeof e),s}}const qh=I(Jh),Gh=U(t=>typeof t=="function");class Xh extends G{constructor(e){super(),this.shape=e}check(e,n){const s=Vr(this.shape,r=>r.check(e,n));return!s&&n?.extend(null,"Intersectinon",typeof e),s}}I(Xh,t=>t.shape.length>0);class ti extends G{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,n){const s=vc(this.shape,r=>r.check(e,n));return n?.extend(null,"Union",typeof e),s}}const Dt=(...t)=>t.findIndex(e=>Jn.check(e))>=0?Dt(...t.map(e=>Yt(e)).map(e=>Jn.check(e)?e.shape:[e]).flat(1)):t.length===1?t[0]:new ti(t),Jn=I(ti),zc=()=>!0,qn=U(zc),Qh=I(ei,t=>t.shape===zc),ni=U(t=>typeof t=="bigint"),Zh=U(t=>t===ni),Kc=U(t=>typeof t=="symbol");U(t=>t===Kc);const dt=U(t=>typeof t=="number"),Yc=U(t=>t===dt),bt=U(t=>typeof t=="string"),Jc=U(t=>t===bt),ks=U(t=>typeof t=="boolean"),ed=U(t=>t===ks),qc=As(void 0);I(Ss,t=>t.shape.length===1&&t.shape[0]===void 0);As(void 0);const Ds=As(null),td=I(Ss,t=>t.shape.length===1&&t.shape[0]===null);I(Uint8Array);I(Zr,t=>t.shape===Uint8Array);const nd=Dt(dt,bt,Ds,qc,ni,ks,Kc);(()=>{const t=Vc(qn),e=Hc(bt,qn),n=Dt(dt,bt,Ds,ks,t,e);return t.shape=n,e.shape.values=n,n})();const Yt=t=>{if(Yh.check(t))return t;if(Fh.check(t)){const e={};for(const n in t)e[n]=Yt(t[n]);return jh(e)}else{if(zh.check(t))return Dt(...t.map(Yt));if(nd.check(t))return As(t);if(Gh.check(t))return I(t)}ie()},io=mh?()=>{}:(t,e)=>{const n=new xh;if(!e.check(t,n))throw ye(`Expected value to be of type ${e.constructor.name}.
4${n.toString()}`)};class sd{constructor(e){this.patterns=[],this.$state=e}if(e,n){return this.patterns.push({if:Yt(e),h:n}),this}else(e){return this.if(qn,e)}
4done(){return(e,n)=>{for(let s=0;s<this.patterns.length;s++){const r=this.patterns[s];if(r.if.check(e))return r.h(e,n)}throw ye("Unhandled pattern")}}}const rd=t=>new sd(t),Gc=rd(qn).if(Yc,(t,e)=>Ys(e,qi,Kn)).if(Jc,(t,e)=>Ph(e)).if(ed,(t,e)=>ro(e)).if(Zh,(t,e)=>BigInt(Ys(e,qi,Kn))).if(Jn,(t,e)=>rt(e,Js(e,t.shape))).if(Hh,(t,e)=>{const n={};for(const s in t.shape){let r=t.shape[s];if(Nh.check(r)){if(ro(e))continue;r=r.shape}n[s]=Gc(r,e)}return n}).if(Wh,(t,e)=>{const n=[],s=$c(e,0,42);for(let r=0;r<s;r++)n.push(rt(e,t.shape));return n}).if(Rc,(t,e)=>Js(e,t.shape)).if(td,(t,e)=>null).if(qh,(t,e)=>{const n=rt(e,t.res);return()=>n}).if(Qh,(t,e)=>rt(e,Js(e,[dt,bt,Ds,qc,ni,ks,Vc(dt),Hc(Dt("a","b","c"),dt)]))).if(Bh,(t,e)=>{const n={},s=Ys(e,0,3);for(let r=0;r<s;r++){const i=rt(e,t.shape.keys),o=rt(e,t.shape.values);n[i]=o}return n}).done(),rt=(t,e)=>Gc(Yt(e),t),Ls=typeof document<"u"?document:{};U(t=>t.nodeType===ad);typeof DOMParser<"u"&&new DOMParser;U(t=>t.nodeType===od);U(t=>t.nodeType===cd);const id=t=>Qu(t,(e,n)=>`${n}:${e};`).join(""),od=Ls.ELEMENT_NODE,cd=Ls.TEXT_NODE,ld=Ls.DOCUMENT_NODE,ad=Ls.DOCUMENT_FRAGMENT_NODE;U(t=>t.nodeType===ld);const De=Symbol,Xc=De(),Qc=De(),ud=De(),hd=De(),dd=De(),Zc=De(),fd=De(),el=De(),pd=De(),gd=t=>{t.length===1&&t[0]?.constructor===Function&&(t=t[0]());const e=[],n=[];let s=0;for(;s<t.length;s++){const r=t[s];if(r===void 0)break;if(r.constructor===String||r.constructor===Number)e.push(r);else if(r.constructor===Object)break}for(s>0&&n.push(e.join(""));s<t.length;s++){const r=t[s];r instanceof Symbol||n.push(r)}return n},yd={[Xc]:Ee("font-weight","bold"),[Qc]:Ee("font-weight","normal"),[ud]:Ee("color","blue"),[dd]:Ee("color","green"),[hd]:Ee("color","grey"),[Zc]:Ee("color","red"),[fd]:Ee("color","purple"),[el]:Ee("color","orange"),[pd]:Ee("color","black")},md=t=>{t.length===1&&t[0]?.constructor===Function&&(t=t[0]());const e=[],n=[],s=X();let r=[],i=0;for(;i<t.length;i++){const o=t[i],c=yd[o];if(c!==void 0)s.set(c.left,c.right);else{if(o===void 0)break;if(o.constructor===String||o.constructor===Number){const l=id(s);i>0||l.length>
40?(e.push("%c"+o),n.push(l)):e.push(o)}else break}}for(i>0&&(r=n,r.unshift(e.join("")));i<t.length;i++){const o=t[i];o instanceof Symbol||r.push(o)}return r},wd=bh?md:gd,bd=(...t)=>{console.log(...wd(t)),_d.forEach(e=>e.print(t))},_d=Re(),tl=t=>({[Symbol.iterator](){return this},next:t}),Ed=(t,e)=>tl(()=>{let n;do n=t.next();while(!n.done&&!e(n.value));return n}),qs=(t,e)=>tl(()=>{const{done:n,value:s}=t.next();return{done:n,value:n?void 0:e(s)}});class si{constructor(e,n){this.clock=e,this.len=n}}class pn{constructor(){this.clients=new Map}}const nl=(t,e,n)=>e.clients.forEach((s,r)=>{const i=t.doc.store.clients.get(r);for(let o=0;o<s.length;o++){const c=s[o];gl(t,i,c.clock,c.len,n)}}),vd=(t,e)=>{let n=0,s=t.length-1;for(;n<=s;){const r=he((n+s)/2),i=t[r],o=i.clock;if(o<=e){if(e<o+i.len)return r;n=r+1}else s=r-1}return null},sl=(t,e)=>{const n=t.clients.get(e.client);return n!==void 0&&vd(n,e.clock)!==null},ri=t=>{t.clients.forEach(e=>{e.sort((r,i)=>r.clock-i.clock);let n,s;for(n=1,s=1;n<e.length;n++){const r=e[s-1],i=e[n];r.clock+r.len>=i.clock?r.len=nt(r.len,i.clock+i.len-r.clock):(s<n&&(e[s]=i),s++)}e.length=s})},Sd=t=>{const e=new pn;for(let n=0;n<t.length;n++)t[n].clients.forEach((s,r)=>{if(!e.clients.has(r)){const i=s.slice();for(let o=n+1;o<t.length;o++)Au(i,t[o].clients.get(r)||[]);e.clients.set(r,i)}});return ri(e),e},Gn=(t,e,n,s)=>{_e(t.clients,e,()=>[]).push(new si(n,s))},Ad=()=>new pn,Cd=t=>{const e=Ad();return t.clients.forEach((n,s)=>{const r=[];for(let i=0;i<n.length;i++){const o=n[i];if(o.deleted){const c=o.id.clock;let l=o.length;if(i+1<n.length)for(let a=n[i+1];i+1<n.length&&a.deleted;a=n[++i+1])l+=a.length;r.push(new si(c,l))}}r.length>0&&e.clients.set(s,r)}),e},Lt=(t,e)=>{m(t.restEncoder,e.clients.size),Se(e.clients.entries()).sort((n,s)=>s[0]-n[0]).forEach(([n,s])=>{t.resetDsCurVal(),m(t.restEncoder,n);const r=s.length;m(t.restEncoder,r);for(let i=0;i<r;i++){const o=s[i];t.writeDsClock(o.clock),t.writeDsLen(o.len)}})},ii=t=>{const e=new pn,n=w(t.restDecoder);for(let s=0;s<n;s++){t.resetDsCurVal();const r=w(t.restDecoder),i=w(t.restDecoder);if(i>0){const o=_e(e.clients,r,()=>[]);for(let c=0;c<i;c++)o.push(new si(t.readDsClock(),t.readDsLen()))}}return e},oo=(t,e,n)=>{const s=new pn,r=w(t.restDecoder);for(let i=0;i<r;i++){t.resetDsCurVal();const o=w(t.restDecoder),c=w(t.restDecoder),l=n.clients.get(o)||[],a=R(n,o);for(let u=0;u<c;u++){const h=t.readDsClock(),d=h+t.readDsLen();if(h<a){a<d&&Gn(s,o,a,d-a);let f=de(l,h),p=l[f];for(!p.deleted&&p.id.clock<h&&(l.splice(f+1,0,ts(e,p,h-p.id.clock)),f++);f<l.length&&(p=l[f++],p.id.clock<d);)p.deleted||(d<p.id.clock+p.length&&l.splice(f,0,ts(e,p,d-p.id.clock)),p.delete(e))}else Gn(s,o,h,d-h)}}if(s.clients.size>0){const i=new Ge;return m(i.restEncoder,0),Lt(i,s),i.toUint8Array()}return null},rl=Lc;class Le extends eh{constructor({guid:e=dh(),collectionid:n=null,gc:s=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:o=!1,shouldLoad:c=!0}={}){super(),this.gc=s,this.gcFilter=r,this.clientID=rl(),this.guid=e,this.collectionid=n,this.share=new Map,this.store=new fl,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=o,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.whenLoaded=no(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const l=()=>no(a=>{const u=h=>{(h===void 0||h===!0)&&(this.off("sync",u),a())};this.on("sync",u)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=a===void 0||a===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){const e=this._item;e!==null&&!this.shouldLoad&&E(e.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Se(this.subdocs).map(e=>e.guid))}transact(e,n=null){return E(this,e,n)}get(e,n=k){const s=_e(this.share,e,()=>{const i=new n;return i._integrate(this,null),i}),r=s.constructor;if(n!==k&&r!==n)if(r===k){const i=new n;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(e,i),i._integrate(this,null),i}else throw new Error(`Type with the name ${e}
4 has already been defined with a different constructor`);return s}getArray(e=""){return this.get(e,ge)}getText(e=""){return this.get(e,Ae)}getMap(e=""){return this.get(e,me)}getXmlElement(e=""){return this.get(e,Ce)}getXmlFragment(e=""){return this.get(e,we)}toJSON(){const e={};return this.share.forEach((n,s)=>{e[s]=n.toJSON()}),e}destroy(){Se(this.subdocs).forEach(n=>n.destroy());const e=this._item;if(e!==null){this._item=null;const n=e.content;n.doc=new Le({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=e,E(e.parent.doc,s=>{const r=n.doc;e.deleted||s.subdocsAdded.add(r),s.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class il{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return w(this.restDecoder)}readDsLen(){return w(this.restDecoder)}}class ol extends il{readLeftID(){return _(w(this.restDecoder),w(this.restDecoder))}readRightID(){return _(w(this.restDecoder),w(this.restDecoder))}readClient(){return w(this.restDecoder)}readInfo(){return yt(this.restDecoder)}readString(){return Me(this.restDecoder)}readParentInfo(){return w(this.restDecoder)===1}readTypeRef(){return w(this.restDecoder)}readLen(){return w(this.restDecoder)}readAny(){return zt(this.restDecoder)}readBuf(){return Lh(V(this.restDecoder))}readJSON(){return JSON.parse(Me(this.restDecoder))}readKey(){return Me(this.restDecoder)}}class kd{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=w(this.restDecoder),this.dsCurrVal}readDsLen(){const e=w(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class _t extends kd{constructor(e){super(e),this.keys=[],w(e),this.keyClockDecoder=new Ks(V(e)),this.clientDecoder=new jn(V(e)),this.leftClockDecoder=new Ks(V(e)),this.rightClockDecoder=new Ks(V(e)),this.infoDecoder=new to(V(e),yt),this.stringDecoder=new Xu(V(e)),this.parentInfoDecoder=new to(V(e),yt),this.typeRefDecoder=new jn(V(e)),this.lenDecoder=new jn(V(e))}readLeftID(){return new ft(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new ft(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 zt(this.restDecoder)}readBuf(){return V(this.restDecoder)}readJSON(){return zt(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{const n=this.stringDecoder.read();return this.keys.push(n),n}}}class cl{constructor(){this.restEncoder=W()}toUint8Array(){return A(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){m(this.restEncoder,e)}writeDsLen(e){m(this.restEncoder,e)}}class gn extends cl{writeLeftID(e){m(this.restEncoder,e.client),m(this.restEncoder,e.clock)}writeRightID(e){m(this.restEncoder,e.client),m(this.restEncoder,e.clock)}writeClient(e){m(this.restEncoder,e)}writeInfo(e){hr(this.restEncoder,e)}writeString(e){Ye(this.restEncoder,e)}writeParentInfo(e){m(this.restEncoder,e?1:0)}writeTypeRef(e){m(this.restEncoder,e)}writeLen(e){m(this.restEncoder,e)}writeAny(e){Wt(this.restEncoder,e)}writeBuf(e){L(this.restEncoder,e)}writeJSON(e){Ye(this.restEncoder,JSON.stringify(e))}writeKey(e){Ye(this.restEncoder,e)}}class ll{constructor(){this.restEncoder=W(),this.dsCurrVal=0}toUint8Array(){return A(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const n=e-this.dsCurrVal;this.dsCurrVal=e,m(this.restEncoder,n)}writeDsLen(e){e===0&&ie(),m(this.restEncoder,e-1),this.dsCurrVal+=e}}class Ge extends ll{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new zs,this.clientEncoder=new Un,this.leftClockEncoder=new zs,this.rightClockEncoder=new zs,this.infoEncoder=new Qi(hr),this.stringEncoder=new Bu,this.parentInfoEncoder=new Qi(hr),this.typeRefEncoder=new Un,this.lenEncoder=new Un}toUint8Array(){const e=W();return m(e,0),L(e,this.keyClockEncoder.toUint8Array()),L(e,this.clientEncoder.toUint8Array()),L(e,this.leftClockEncoder.toUint8Array()),L(e,this.rightClockEncoder.toUint8Array()),L(e,A(this.infoEncoder)),L(e,this.stringEncoder.toUint8Array()),L(e,A(this.parentInfoEncoder)),L(e,this.typeRefEncoder.toUint8Array()),L(e,this.lenEncoder.toUint8Array()),Es(e,A(this.restEncoder)),A(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){Wt(this.restEncoder,e)}writeBuf(e){L(this.restEncoder,e)}writeJSON(e){Wt(this.restEncoder,e)}writeKey(e){const n=this.keyMap.get(e);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(n)}}const Dd=(t,e,n,s)=>{s=nt(s,e[0].id.clock);const r=de(e,s);m(t.restEncoder,e.length-r),t.writeClient(n),m(t.restEncoder,s);const i=e[r];i.write(t,s-i.id.clock);for(let o=r+1;o<e.length;o++)e[o].write(t,0)},oi=(t,e,n)=>{const s=new Map;
4n.forEach((r,i)=>{R(e,i)>r&&s.set(i,r)}),Os(e).forEach((r,i)=>{n.has(i)||s.set(i,0)}),m(t.restEncoder,s.size),Se(s.entries()).sort((r,i)=>i[0]-r[0]).forEach(([r,i])=>{Dd(t,e.clients.get(r),r,i)})},Ld=(t,e)=>{const n=X(),s=w(t.restDecoder);for(let r=0;r<s;r++){const i=w(t.restDecoder),o=new Array(i),c=t.readClient();let l=w(t.restDecoder);n.set(c,{i:0,refs:o});for(let a=0;a<i;a++){const u=t.readInfo();switch(bs&u){case 0:{const h=t.readLen();o[a]=new Z(_(c,l),h),l+=h;break}case 10:{const h=w(t.restDecoder);o[a]=new se(_(c,l),h),l+=h;break}default:{const h=(u&(ve|ee))===0,d=new P(_(c,l),null,(u&ee)===ee?t.readLeftID():null,null,(u&ve)===ve?t.readRightID():null,h?t.readParentInfo()?e.get(t.readString()):t.readLeftID():null,h&&(u&Bt)===Bt?t.readString():null,$l(t,u));o[a]=d,l+=d.length}}}}return n},Od=(t,e,n)=>{const s=[];let r=Se(n.keys()).sort((f,p)=>f-p);if(r.length===0)return null;const i=()=>{if(r.length===0)return null;let f=n.get(r[r.length-1]);for(;f.refs.length===f.i;)if(r.pop(),r.length>0)f=n.get(r[r.length-1]);else return null;return f};let o=i();if(o===null)return null;const c=new fl,l=new Map,a=(f,p)=>{const y=l.get(f);(y==null||y>p)&&l.set(f,p)};let u=o.refs[o.i++];const h=new Map,d=()=>{for(const f of s){const p=f.id.client,y=n.get(p);y?(y.i--,c.clients.set(p,y.refs.slice(y.i)),n.delete(p),y.i=0,y.refs=[]):c.clients.set(p,[f]),r=r.filter(g=>g!==p)}s.length=0};for(;;){if(u.constructor!==se){const p=_e(h,u.id.client,()=>R(e,u.id.client))-u.id.clock;if(p<0)s.push(u),a(u.id.client,u.id.clock-1),d();else{const y=u.getMissing(t,e);if(y!==null){s.push(u);const g=n.get(y)||{refs:[],i:0};if(g.refs.length===g.i)a(y,R(e,y)),d();else{u=g.refs[g.i++];continue}}else(p===0||p<u.length)&&(u.integrate(t,p),h.set(u.id.client,u.id.clock+u.length))}}if(s.length>0)u=s.pop();else if(o!==null&&o.i<o.refs.length)u=o.refs[o.i++];else{if(o=i(),o===null)break;u=o.refs[o.i++]}}if(c.clients.size>0){const f=new Ge;return oi(f,c,new Map),m(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},Id=(t,e)=>oi(t,e.doc.store,e.beforeState),Pd=(t,e,n,s=new _t(t))=>E(e,r=>{r.local=!1;let i=!1;const o=r.doc,c=o.store,l=Ld(s,o),a=Od(r,c,l),u=c.pendingStructs;if(u){for(const[d,f]of u.missing)if(f<R(c,d)){i=!0;break}if(a){for(const[d,f]of a.missing){const p=u.missing.get(d);(p==null||p>f)&&u.missing.set(d,f)}u.update=Xn([u.update,a.update])}}else c.pendingStructs=a;const h=oo(s,r,c);if(c.pendingDs){const d=new _t(je(c.pendingDs));w(d.restDecoder);const f=oo(d,r,c);h&&f?c.pendingDs=Xn([h,f]):c.pendingDs=h||f}else c.pendingDs=h;if(i){const d=c.pendingStructs.update;c.pendingStructs=null,al(r.doc,d)}},n,!1),al=(t,e,n,s=_t)=>{const r=je(e);Pd(r,t,n,new s(r))},Td=(t,e,n)=>al(t,e,n,ol),xd=(t,e,n=new Map)=>{oi(t,e.store,n),Lt(t,Cd(e.store))},Md=(t,e=new Uint8Array([0]),n=new Ge)=>{const s=ul(e);xd(n,t,s);const r=[n.toUint8Array()];if(t.store.pendingDs&&r.push(t.store.pendingDs),t.store.pendingStructs&&r.push(qd(t.store.pendingStructs.update,e)),r.length>1){if(n.constructor===gn)return ml(r.map((i,o)=>o===0?i:Xd(i)));if(n.constructor===Ge)return Xn(r)}return r[0]},$d=(t,e)=>Md(t,e,new gn),Rd=t=>{const e=new Map,n=w(t.restDecoder);for(let s=0;s<n;s++){const r=w(t.restDecoder),i=w(t.restDecoder);e.set(r,i)}return e},ul=t=>Rd(new il(je(t))),hl=(t,e)=>(m(t.restEncoder,e.size),Se(e.entries()).sort((n,s)=>s[0]-n[0]).forEach(([n,s])=>{m(t.restEncoder,n),m(t.restEncoder,s)}),t),Nd=(t,e)=>hl(t,Os(e.store)),Ud=(t,e=new ll)=>(t instanceof Map?hl(e,t):Nd(e,t),e.toUint8Array()),jd=t=>Ud(t,new cl);class Hd{constructor(){this.l=[]}}const co=()=>new Hd,lo=(t,e)=>t.l.push(e),ao=(t,e)=>{const n=t.l,s=n.length;t.l=n.filter(r=>e!==r),s===t.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},dl=(t,e,n)=>Gr(t.l,[e,n]);class ft{constructor(e,n){this.client=e,this.clock=n}}const Cn=(t,e)=>t===e||t!==null&&e!==null&&t.client===e.client&&t.clock===e.clock,_=(t,e)=>new ft(t,e),Fd=t=>{for(const[e,n]of t.doc.share.entries())if(n===t)return e;throw ie()},ct=(t,e)=>e===void 0?!t.deleted:e.sv.has(t.id.client)&&(e.sv.get(t.id.client)||0)>t.id.clock&&!sl(e.ds,t.id),mr=(t,e)=>{const n=_e(t.meta,mr,Re),s=t.doc.store;n.has(e)||(e.sv.forEach((r,i)=>{r<R(s,i)&&Ne(t,_(i,r))}),nl(t,e.ds,r=>{}),n.add(e))};class fl{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Os=t=>{const e=new Map;
4return t.clients.forEach((n,s)=>{const r=n[n.length-1];e.set(s,r.id.clock+r.length)}),e},R=(t,e)=>{const n=t.clients.get(e);if(n===void 0)return 0;const s=n[n.length-1];return s.id.clock+s.length},pl=(t,e)=>{let n=t.clients.get(e.id.client);if(n===void 0)n=[],t.clients.set(e.id.client,n);else{const s=n[n.length-1];if(s.id.clock+s.length!==e.id.clock)throw ie()}n.push(e)},de=(t,e)=>{let n=0,s=t.length-1,r=t[s],i=r.id.clock;if(i===e)return s;let o=he(e/(i+r.length-1)*s);for(;n<=s;){if(r=t[o],i=r.id.clock,i<=e){if(e<i+r.length)return o;n=o+1}else s=o-1;o=he((n+s)/2)}throw ie()},Bd=(t,e)=>{const n=t.clients.get(e.client);return n[de(n,e.clock)]},Gs=Bd,wr=(t,e,n)=>{const s=de(e,n),r=e[s];return r.id.clock<n&&r instanceof P?(e.splice(s+1,0,ts(t,r,n-r.id.clock)),s+1):s},Ne=(t,e)=>{const n=t.doc.store.clients.get(e.client);return n[wr(t,n,e.clock)]},uo=(t,e,n)=>{const s=e.clients.get(n.client),r=de(s,n.clock),i=s[r];return n.clock!==i.id.clock+i.length-1&&i.constructor!==Z&&s.splice(r+1,0,ts(t,i,n.clock-i.id.clock+1)),i},Vd=(t,e,n)=>{const s=t.clients.get(e.id.client);s[de(s,e.id.clock)]=n},gl=(t,e,n,s,r)=>{if(s===0)return;const i=n+s;let o=wr(t,e,n),c;do c=e[o++],i<c.id.clock+c.length&&wr(t,e,i),r(c);while(o<e.length&&e[o].id.clock<i)};class Wd{constructor(e,n,s){this.doc=e,this.deleteSet=new pn,this.beforeState=Os(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=s,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const ho=(t,e)=>e.deleteSet.clients.size===0&&!Zu(e.afterState,(n,s)=>e.beforeState.get(s)!==n)?!1:(ri(e.deleteSet),Id(t,e),Lt(t,e.deleteSet),!0),fo=(t,e,n)=>{const s=e._item;(s===null||s.id.clock<(t.beforeState.get(s.id.client)||0)&&!s.deleted)&&_e(t.changed,e,Re).add(n)},Hn=(t,e)=>{let n=t[e],s=t[e-1],r=e;for(;r>0;n=s,s=t[--r-1]){if(s.deleted===n.deleted&&s.constructor===n.constructor&&s.mergeWith(n)){n instanceof P&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,s);continue}break}const i=e-r;return i&&t.splice(e+1-i,i),i},zd=(t,e,n)=>{for(const[s,r]of t.clients.entries()){const i=e.clients.get(s);for(let o=r.length-1;o>=0;o--){const c=r[o],l=c.clock+c.len;for(let a=de(i,c.clock),u=i[a];a<i.length&&u.id.clock<l;u=i[++a]){const h=i[a];if(c.clock+c.len<=h.id.clock)break;h instanceof P&&h.deleted&&!h.keep&&n(h)&&h.gc(e,!1)}}}},Kd=(t,e)=>{t.clients.forEach((n,s)=>{const r=e.clients.get(s);for(let i=n.length-1;i>=0;i--){const o=n[i],c=Br(r.length-1,1+de(r,o.clock+o.len-1));for(let l=c,a=r[l];l>0&&a.id.clock>=o.clock;a=r[l])l-=1+Hn(r,l)}})},yl=(t,e)=>{if(e<t.length){const n=t[e],s=n.doc,r=s.store,i=n.deleteSet,o=n._mergeStructs;try{ri(i),n.afterState=Os(n.doc.store),s.emit("beforeObserverCalls",[n,s]);const c=[];n.changed.forEach((l,a)=>c.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(n,l)})),c.push(()=>{n.changedParentTypes.forEach((l,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(l=l.filter(u=>u.target._item===null||!u.target._item.deleted),l.forEach(u=>{u.currentTarget=a,u._path=null}),l.sort((u,h)=>u.path.length-h.path.length),dl(a._dEH,l,n))})}),c.push(()=>s.emit("afterTransaction",[n,s])),Gr(c,[]),n._needFormattingCleanup&&df(n)}finally{s.gc&&zd(i,r,s.gcFilter),Kd(i,r),n.afterState.forEach((u,h)=>{const d=n.beforeState.get(h)||0;if(d!==u){const f=r.clients.get(h),p=nt(de(f,d),1);for(let y=f.length-1;y>=p;)y-=1+Hn(f,y)}});for(let u=o.length-1;u>=0;u--){const{client:h,clock:d}=o[u].id,f=r.clients.get(h),p=de(f,d);p+1<f.length&&Hn(f,p+1)>1||p>0&&Hn(f,p)}if(!n.local&&n.afterState.get(s.clientID)!==n.beforeState.get(s.clientID)&&(bd(el,Xc,"[yjs] ",Qc,Zc,"Changed the client-id because another client seems to be using it."),s.clientID=rl()),s.emit("afterTransactionCleanup",[n,s]),s._observers.has("update")){const u=new gn;ho(u,n)&&s.emit("update",[u.toUint8Array(),n.origin,s,n])}if(s._observers.has("updateV2")){const u=new Ge;ho(u,n)&&s.emit("updateV2",[u.toUint8Array(),n.origin,s,n])}const{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:a}=n;(c.size>0||a.size>0||l.size>0)&&(c.forEach(u=>{u.clientID=s.clientID,u.collectionid==null&&(u.collectionid=s.collectionid),s.subdocs.add(u)}),a.forEach(u=>s.subdocs.delete(u)),s.emit("subdocs",[{loaded:l,added:c,removed:a},s,n]),a.forEach(u=>u.destroy())),t.length<=e+1?(s._transactionCleanups=[],s.emit("afterAllTransactions",[s,t])):yl(t,e+1)}}}
4,E=(t,e,n=null,s=!0)=>{const r=t._transactionCleanups;let i=!1,o=null;t._transaction===null&&(i=!0,t._transaction=new Wd(t,n,s),r.push(t._transaction),r.length===1&&t.emit("beforeAllTransactions",[t]),t.emit("beforeTransaction",[t._transaction,t]));try{o=e(t._transaction)}finally{if(i){const c=t._transaction===r[0];t._transaction=null,c&&yl(r,0)}}return o};function*Yd(t){const e=w(t.restDecoder);for(let n=0;n<e;n++){const s=w(t.restDecoder),r=t.readClient();let i=w(t.restDecoder);for(let o=0;o<s;o++){const c=t.readInfo();if(c===10){const l=w(t.restDecoder);yield new se(_(r,i),l),i+=l}else if((bs&c)!==0){const l=(c&(ve|ee))===0,a=new P(_(r,i),null,(c&ee)===ee?t.readLeftID():null,null,(c&ve)===ve?t.readRightID():null,l?t.readParentInfo()?t.readString():t.readLeftID():null,l&&(c&Bt)===Bt?t.readString():null,$l(t,c));yield a,i+=a.length}else{const l=t.readLen();yield new Z(_(r,i),l),i+=l}}}}class ci{constructor(e,n){this.gen=Yd(e),this.curr=null,this.done=!1,this.filterSkips=n,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===se);return this.curr}}class li{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}}const ml=t=>Xn(t,ol,gn),Jd=(t,e)=>{if(t.constructor===Z){const{client:n,clock:s}=t.id;return new Z(_(n,s+e),t.length-e)}else if(t.constructor===se){const{client:n,clock:s}=t.id;return new se(_(n,s+e),t.length-e)}else{const n=t,{client:s,clock:r}=n.id;return new P(_(s,r+e),null,_(s,r+e-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(e))}},Xn=(t,e=_t,n=Ge)=>{if(t.length===1)return t[0];const s=t.map(u=>new e(je(u)));let r=s.map(u=>new ci(u,!0)),i=null;const o=new n,c=new li(o);for(;r=r.filter(d=>d.curr!==null),r.sort((d,f)=>{if(d.curr.id.client===f.curr.id.client){const p=d.curr.id.clock-f.curr.id.clock;return p===0?d.curr.constructor===f.curr.constructor?0:d.curr.constructor===se?1:-1:p}else return f.curr.id.client-d.curr.id.client}),r.length!==0;){const u=r[0],h=u.curr.id.client;if(i!==null){let d=u.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=u.next(),f=!0;if(d===null||d.id.client!==h||f&&d.id.clock>i.struct.id.clock+i.struct.length)continue;if(h!==i.struct.id.client)Pe(c,i.struct,i.offset),i={struct:d,offset:0},u.next();else if(i.struct.id.clock+i.struct.length<d.id.clock)if(i.struct.constructor===se)i.struct.length=d.id.clock+d.length-i.struct.id.clock;else{Pe(c,i.struct,i.offset);const p=d.id.clock-i.struct.id.clock-i.struct.length;i={struct:new se(_(h,i.struct.id.clock+i.struct.length),p),offset:0}}else{const p=i.struct.id.clock+i.struct.length-d.id.clock;p>0&&(i.struct.constructor===se?i.struct.length-=p:d=Jd(d,p)),i.struct.mergeWith(d)||(Pe(c,i.struct,i.offset),i={struct:d,offset:0},u.next())}}else i={struct:u.curr,offset:0},u.next();for(let d=u.curr;d!==null&&d.id.client===h&&d.id.clock===i.struct.id.clock+i.struct.length&&d.constructor!==se;d=u.next())Pe(c,i.struct,i.offset),i={struct:d,offset:0}}i!==null&&(Pe(c,i.struct,i.offset),i=null),ai(c);const l=s.map(u=>ii(u)),a=Sd(l);return Lt(o,a),o.toUint8Array()},qd=(t,e,n=_t,s=Ge)=>{const r=ul(e),i=new s,o=new li(i),c=new n(je(t)),l=new ci(c,!1);for(;l.curr;){const u=l.curr,h=u.id.client,d=r.get(h)||0;if(l.curr.constructor===se){l.next();continue}if(u.id.clock+u.length>d)for(Pe(o,u,nt(d-u.id.clock,0)),l.next();l.curr&&l.curr.id.client===h;)Pe(o,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===h&&l.curr.id.clock+l.curr.length<=d;)l.next()}ai(o);const a=ii(c);return Lt(i,a),i.toUint8Array()},wl=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:A(t.encoder.restEncoder)}),t.encoder.restEncoder=W(),t.written=0)},Pe=(t,e,n)=>{t.written>0&&t.currClient!==e.id.client&&wl(t),t.written===0&&(t.currClient=e.id.client,t.encoder.writeClient(e.id.client),m(t.encoder.restEncoder,e.id.clock+n)),e.write(t.encoder,n),t.written++},ai=t=>{wl(t);const e=t.encoder.restEncoder;m(e,t.clientStructs.length);for(let n=0;n<t.clientStructs.length;n++){const s=t.clientStructs[n];m(e,s.written),Es(e,s.restEncoder)}},Gd=(t,e,n,s)=>{const r=new n(je(t)),i=new ci(r,!1),o=new s,c=new li(o);for(let a=i.curr;a!==null;a=i.next())Pe(c,e(a),0);ai(c);const l=ii(r);return Lt(o,l),o.toUint8Array()},Xd=t=>Gd(t,lh,_t,gn),po="You must not compute changes after the event-handler fired.";class Is{constructor(e,n){this.target=e,this.currentTarget=e,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Qd(this.currentTarget,this.target))}deletes(e){return sl(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw ye(po);const e=new Map,n=this.target;
4this.transaction.changed.get(n).forEach(r=>{if(r!==null){const i=n._map.get(r);let o,c;if(this.adds(i)){let l=i.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(i))if(l!==null&&this.deletes(l))o="delete",c=Ws(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",c=Ws(l.content.getContent())):(o="add",c=void 0)}else if(this.deletes(i))o="delete",c=Ws(i.content.getContent());else return;e.set(r,{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 ye(po);const n=this.target,s=Re(),r=Re(),i=[];if(e={added:s,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(n).has(null)){let c=null;const l=()=>{c&&i.push(c)};for(let a=n._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((c===null||c.delete===void 0)&&(l(),c={delete:0}),c.delete+=a.length,r.add(a)):this.adds(a)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(a.content.getContent()),s.add(a)):((c===null||c.retain===void 0)&&(l(),c={retain:0}),c.retain+=a.length);c!==null&&c.retain===void 0&&l()}this._changes=e}return e}}const Qd=(t,e)=>{const n=[];for(;e._item!==null&&e!==t;){if(e._item.parentSub!==null)n.unshift(e._item.parentSub);else{let s=0,r=e._item.parent._start;for(;r!==e._item&&r!==null;)!r.deleted&&r.countable&&(s+=r.length),r=r.right;n.unshift(s)}e=e._item.parent}return n},bl=80;let ui=0;class Zd{constructor(e,n){e.marker=!0,this.p=e,this.index=n,this.timestamp=ui++}}const ef=t=>{t.timestamp=ui++},_l=(t,e,n)=>{t.p.marker=!1,t.p=e,e.marker=!0,t.index=n,t.timestamp=ui++},tf=(t,e,n)=>{if(t.length>=bl){const s=t.reduce((r,i)=>r.timestamp<i.timestamp?r:i);return _l(s,e,n),s}else{const s=new Zd(e,n);return t.push(s),s}},Ps=(t,e)=>{if(t._start===null||e===0||t._searchMarker===null)return null;const n=t._searchMarker.length===0?null:t._searchMarker.reduce((i,o)=>Nn(e-i.index)<Nn(e-o.index)?i:o);let s=t._start,r=0;for(n!==null&&(s=n.p,r=n.index,ef(n));s.right!==null&&r<e;){if(!s.deleted&&s.countable){if(e<r+s.length)break;r+=s.length}s=s.right}for(;s.left!==null&&r>e;)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 n!==null&&Nn(n.index-r)<s.parent.length/bl?(_l(n,s,r),n):tf(t._searchMarker,s,r)},Jt=(t,e,n)=>{for(let s=t.length-1;s>=0;s--){const r=t[s];if(n>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){t.splice(s,1);continue}r.p=i,i.marker=!0}(e<r.index||n>0&&e===r.index)&&(r.index=nt(e,r.index+n))}},Ts=(t,e,n)=>{const s=t,r=e.changedParentTypes;for(;_e(r,t,()=>[]).push(n),t._item!==null;)t=t._item.parent;dl(s._eH,n,e)};class k{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=co(),this._dEH=co(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,n){this.doc=e,this._item=n}_copy(){throw le()}clone(){throw le()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,n){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){lo(this._eH,e)}observeDeep(e){lo(this._dEH,e)}unobserve(e){ao(this._eH,e)}unobserveDeep(e){ao(this._dEH,e)}toJSON(){}}const El=(t,e,n)=>{e<0&&(e=t._length+e),n<0&&(n=t._length+n);let s=n-e;const r=[];let i=t._start;for(;i!==null&&s>0;){if(i.countable&&!i.deleted){const o=i.content.getContent();if(o.length<=e)e-=o.length;else{for(let c=e;c<o.length&&s>0;c++)r.push(o[c]),s--;e=0}}i=i.right}return r},vl=t=>{const e=[];let n=t._start;for(;n!==null;){if(n.countable&&!n.deleted){const s=n.content.getContent();for(let r=0;r<s.length;r++)e.push(s[r])}n=n.right}return e},qt=(t,e)=>{let n=0,s=t._start;for(;s!==null;){if(s.countable&&!s.deleted){const r=s.content.getContent();for(let i=0;i<r.length;i++)e(r[i],n++,t)}s=s.right}},Sl=(t,e)=>{const n=[];return qt(t,(s,r)=>
4{n.push(e(s,r,t))}),n},nf=t=>{let e=t._start,n=null,s=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};n=e.content.getContent(),s=0,e=e.right}const r=n[s++];return n.length<=s&&(n=null),{done:!1,value:r}}}},Al=(t,e)=>{const n=Ps(t,e);let s=t._start;for(n!==null&&(s=n.p,e-=n.index);s!==null;s=s.right)if(!s.deleted&&s.countable){if(e<s.length)return s.content.getContent()[e];e-=s.length}},Qn=(t,e,n,s)=>{let r=n;const i=t.doc,o=i.clientID,c=i.store,l=n===null?e._start:n.right;let a=[];const u=()=>{a.length>0&&(r=new P(_(o,R(c,o)),r,r&&r.lastId,l,l&&l.id,e,null,new Qe(a)),r.integrate(t,0),a=[])};s.forEach(h=>{if(h===null)a.push(h);else switch(h.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(h);break;default:switch(u(),h.constructor){case Uint8Array:case ArrayBuffer:r=new P(_(o,R(c,o)),r,r&&r.lastId,l,l&&l.id,e,null,new yn(new Uint8Array(h))),r.integrate(t,0);break;case Le:r=new P(_(o,R(c,o)),r,r&&r.lastId,l,l&&l.id,e,null,new mn(h)),r.integrate(t,0);break;default:if(h instanceof k)r=new P(_(o,R(c,o)),r,r&&r.lastId,l,l&&l.id,e,null,new Oe(h)),r.integrate(t,0);else throw new Error("Unexpected content type in insert operation")}}}),u()},Cl=()=>ye("Length exceeded!"),kl=(t,e,n,s)=>{if(n>e._length)throw Cl();if(n===0)return e._searchMarker&&Jt(e._searchMarker,n,s.length),Qn(t,e,null,s);const r=n,i=Ps(e,n);let o=e._start;for(i!==null&&(o=i.p,n-=i.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&Ne(t,_(o.id.client,o.id.clock+n));break}n-=o.length}return e._searchMarker&&Jt(e._searchMarker,r,s.length),Qn(t,e,o,s)},sf=(t,e,n)=>{let r=(e._searchMarker||[]).reduce((i,o)=>o.index>i.index?o:i,{index:0,p:e._start}).p;if(r)for(;r.right;)r=r.right;return Qn(t,e,r,n)},Dl=(t,e,n,s)=>{if(s===0)return;const r=n,i=s,o=Ps(e,n);let c=e._start;for(o!==null&&(c=o.p,n-=o.index);c!==null&&n>0;c=c.right)!c.deleted&&c.countable&&(n<c.length&&Ne(t,_(c.id.client,c.id.clock+n)),n-=c.length);for(;s>0&&c!==null;)c.deleted||(s<c.length&&Ne(t,_(c.id.client,c.id.clock+s)),c.delete(t),s-=c.length),c=c.right;if(s>0)throw Cl();e._searchMarker&&Jt(e._searchMarker,r,-i+s)},Zn=(t,e,n)=>{const s=e._map.get(n);s!==void 0&&s.delete(t)},hi=(t,e,n,s)=>{const r=e._map.get(n)||null,i=t.doc,o=i.clientID;let c;if(s==null)c=new Qe([s]);else switch(s.constructor){case Number:case Object:case Boolean:case Array:case String:c=new Qe([s]);break;case Uint8Array:c=new yn(s);break;case Le:c=new mn(s);break;default:if(s instanceof k)c=new Oe(s);else throw new Error("Unexpected content type")}new P(_(o,R(i.store,o)),r,r&&r.lastId,null,null,e,n,c).integrate(t,0)},di=(t,e)=>{const n=t._map.get(e);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Ll=t=>{const e={};return t._map.forEach((n,s)=>{n.deleted||(e[s]=n.content.getContent()[n.length-1])}),e},Ol=(t,e)=>{const n=t._map.get(e);return n!==void 0&&!n.deleted},rf=(t,e)=>{const n={};return t._map.forEach((s,r)=>{let i=s;for(;i!==null&&(!e.sv.has(i.id.client)||i.id.clock>=(e.sv.get(i.id.client)||0));)i=i.left;i!==null&&ct(i,e)&&(n[r]=i.content.getContent()[i.length-1])}),n},kn=t=>Ed(t.entries(),e=>!e[1].deleted);class of extends Is{}class ge extends k{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const n=new ge;return n.push(e),n}_integrate(e,n){super._integrate(e,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new ge}clone(){const e=new ge;return e.insert(0,this.toArray().map(n=>n instanceof k?n.clone():n)),e}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}_callObserver(e,n){super._callObserver(e,n),Ts(this,e,new of(this,e))}insert(e,n){this.doc!==null?E(this.doc,s=>{kl(s,this,e,n)}):this._prelimContent.splice(e,0,...n)}push(e){this.doc!==null?E(this.doc,n=>{sf(n,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,n=1){this.doc!==null?E(this.doc,s=>{Dl(s,this,e,n)}):this._prelimContent.splice(e,n)}get(e){return Al(this,e)}toArray(){return vl(this)}slice(e=0,n=this.length){return El(this,e,n)}toJSON(){return this.map(e=>e instanceof k?e.toJSON():e)}map(e){return Sl(this,e)}forEach(e){qt(this,e)}[Symbol.iterator](){return nf(this)}_write(e){e.writeTypeRef(If)}}const cf=t=>new ge;class lf extends Is{constructor(e,n,s){super(e,n),this.keysChanged=s}}class me extends k{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,n){super._integrate(e,n),this._prelimContent.forEach((s,r)=>{this.set(r,s)}),this._prelimContent=null}_copy(){return new me}clone(){const e=new me;return this.forEach((n,s)=>{e.set(s,n instanceof k?n.clone():n)}),e}_callObserver(e,n){Ts(this,e,new lf(this,e,n))}toJSON(){const e={};
4return this._map.forEach((n,s)=>{if(!n.deleted){const r=n.content.getContent()[n.length-1];e[s]=r instanceof k?r.toJSON():r}}),e}get size(){return[...kn(this._map)].length}keys(){return qs(kn(this._map),e=>e[0])}values(){return qs(kn(this._map),e=>e[1].content.getContent()[e[1].length-1])}entries(){return qs(kn(this._map),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this._map.forEach((n,s)=>{n.deleted||e(n.content.getContent()[n.length-1],s,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?E(this.doc,n=>{Zn(n,this,e)}):this._prelimContent.delete(e)}set(e,n){return this.doc!==null?E(this.doc,s=>{hi(s,this,e,n)}):this._prelimContent.set(e,n),n}get(e){return di(this,e)}has(e){return Ol(this,e)}clear(){this.doc!==null?E(this.doc,e=>{this.forEach(function(n,s,r){Zn(e,r,s)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(Pf)}}const af=t=>new me,xe=(t,e)=>t===e||typeof t=="object"&&typeof e=="object"&&t&&e&&ch(t,e);class br{constructor(e,n,s,r){this.left=e,this.right=n,this.index=s,this.currentAttributes=r}forward(){switch(this.right===null&&ie(),this.right.content.constructor){case x:this.right.deleted||Ot(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 go=(t,e,n)=>{for(;e.right!==null&&n>0;){switch(e.right.content.constructor){case x:e.right.deleted||Ot(e.currentAttributes,e.right.content);break;default:e.right.deleted||(n<e.right.length&&Ne(t,_(e.right.id.client,e.right.id.clock+n)),e.index+=e.right.length,n-=e.right.length);break}e.left=e.right,e.right=e.right.right}return e},Dn=(t,e,n,s)=>{const r=new Map,i=s?Ps(e,n):null;if(i){const o=new br(i.p.left,i.p,i.index,r);return go(t,o,n-i.index)}else{const o=new br(null,e._start,0,r);return go(t,o,n)}},Il=(t,e,n,s)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===x&&xe(s.get(n.right.content.key),n.right.content.value));)n.right.deleted||s.delete(n.right.content.key),n.forward();const r=t.doc,i=r.clientID;s.forEach((o,c)=>{const l=n.left,a=n.right,u=new P(_(i,R(r.store,i)),l,l&&l.lastId,a,a&&a.id,e,null,new x(c,o));u.integrate(t,0),n.right=u,n.forward()})},Ot=(t,e)=>{const{key:n,value:s}=e;s===null?t.delete(n):t.set(n,s)},Pl=(t,e)=>{for(;t.right!==null;){if(!(t.right.deleted||t.right.content.constructor===x&&xe(e[t.right.content.key]??null,t.right.content.value)))break;t.forward()}},Tl=(t,e,n,s)=>{const r=t.doc,i=r.clientID,o=new Map;for(const c in s){const l=s[c],a=n.currentAttributes.get(c)??null;if(!xe(a,l)){o.set(c,a);const{left:u,right:h}=n;n.right=new P(_(i,R(r.store,i)),u,u&&u.lastId,h,h&&h.id,e,null,new x(c,l)),n.right.integrate(t,0),n.forward()}}return o},Xs=(t,e,n,s,r)=>{n.currentAttributes.forEach((d,f)=>{r[f]===void 0&&(r[f]=null)});const i=t.doc,o=i.clientID;Pl(n,r);const c=Tl(t,e,n,r),l=s.constructor===String?new be(s):s instanceof k?new Oe(s):new st(s);let{left:a,right:u,index:h}=n;e._searchMarker&&Jt(e._searchMarker,n.index,l.getLength()),u=new P(_(o,R(i.store,o)),a,a&&a.lastId,u,u&&u.id,e,null,l),u.integrate(t,0),n.right=u,n.index=h,n.forward(),Il(t,e,n,c)},yo=(t,e,n,s,r)=>{const i=t.doc,o=i.clientID;Pl(n,r);const c=Tl(t,e,n,r);e:for(;n.right!==null&&(s>0||c.size>0&&(n.right.deleted||n.right.content.constructor===x));){if(!n.right.deleted)switch(n.right.content.constructor){case x:{const{key:l,value:a}=n.right.content,u=r[l];if(u!==void 0){if(xe(u,a))c.delete(l);else{if(s===0)break e;c.set(l,a)}n.right.delete(t)}else n.currentAttributes.set(l,a);break}default:s<n.right.length&&Ne(t,_(n.right.id.client,n.right.id.clock+s)),s-=n.right.length;break}n.forward()}if(s>0){let l="";for(;s>0;s--)l+=`
5`;n.right=new P(_(o,R(i.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,e,null,new be(l)),n.right.integrate(t,0),n.forward()}Il(t,e,n,c)},xl=(t,e,n,s,r)=>{let i=e;const o=X();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===x){const a=i.content;o.set(a.key,a)}i=i.right}let c=0,l=!1;for(;e!==i;){if(n===e&&(l=!0),!e.deleted){const a=e.content;switch(a.constructor){case x:{const{key:u,value:h}=a,d=s.get(u)??null;
5(o.get(u)!==a||d===h)&&(e.delete(t),c++,!l&&(r.get(u)??null)===h&&d!==h&&(d===null?r.delete(u):r.set(u,d))),!l&&!e.deleted&&Ot(r,a);break}}}e=e.right}return c},uf=(t,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;const n=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===x){const s=e.content.key;n.has(s)?e.delete(t):n.add(s)}e=e.left}},hf=t=>{let e=0;return E(t.doc,n=>{let s=t._start,r=t._start,i=X();const o=fr(i);for(;r;){if(r.deleted===!1)switch(r.content.constructor){case x:Ot(o,r.content);break;default:e+=xl(n,s,r,i,o),i=fr(o),s=r;break}r=r.right}}),e},df=t=>{const e=new Set,n=t.doc;for(const[s,r]of t.afterState.entries()){const i=t.beforeState.get(s)||0;r!==i&&gl(t,n.store.clients.get(s),i,r,o=>{!o.deleted&&o.content.constructor===x&&o.constructor!==Z&&e.add(o.parent)})}E(n,s=>{nl(t,t.deleteSet,r=>{if(r instanceof Z||!r.parent._hasFormatting||e.has(r.parent))return;const i=r.parent;r.content.constructor===x?e.add(i):uf(s,r)});for(const r of e)hf(r)})},mo=(t,e,n)=>{const s=n,r=fr(e.currentAttributes),i=e.right;for(;n>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case Oe:case st:case be:n<e.right.length&&Ne(t,_(e.right.id.client,e.right.id.clock+n)),n-=e.right.length,e.right.delete(t);break}e.forward()}i&&xl(t,i,e.right,r,e.currentAttributes);const o=(e.left||e.right).parent;return o._searchMarker&&Jt(o._searchMarker,e.index,-s+n),e};class ff extends Is{constructor(e,n,s){super(e,n),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 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,n=[];E(e,s=>{const r=new Map,i=new Map;let o=this.target._start,c=null;const l={};let a="",u=0,h=0;const d=()=>{if(c!==null){let f=null;switch(c){case"delete":h>0&&(f={delete:h}),h=0;break;case"insert":(typeof a=="object"||a.length>0)&&(f={insert:a},r.size>0&&(f.attributes={},r.forEach((p,y)=>{p!==null&&(f.attributes[y]=p)}))),a="";break;case"retain":u>0&&(f={retain:u},oh(l)||(f.attributes=nh({},l))),u=0;break}f&&n.push(f),c=null}};for(;o!==null;){switch(o.content.constructor){case Oe:case st:this.adds(o)?this.deletes(o)||(d(),c="insert",a=o.content.getContent()[0],d()):this.deletes(o)?(c!=="delete"&&(d(),c="delete"),h+=1):o.deleted||(c!=="retain"&&(d(),c="retain"),u+=1);break;case be:this.adds(o)?this.deletes(o)||(c!=="insert"&&(d(),c="insert"),a+=o.content.str):this.deletes(o)?(c!=="delete"&&(d(),c="delete"),h+=o.length):o.deleted||(c!=="retain"&&(d(),c="retain"),u+=o.length);break;case x:{const{key:f,value:p}=o.content;if(this.adds(o)){if(!this.deletes(o)){const y=r.get(f)??null;xe(y,p)?p!==null&&o.delete(s):(c==="retain"&&d(),xe(p,i.get(f)??null)?delete l[f]:l[f]=p)}}else if(this.deletes(o)){i.set(f,p);const y=r.get(f)??null;xe(y,p)||(c==="retain"&&d(),l[f]=y)}else if(!o.deleted){i.set(f,p);const y=l[f];y!==void 0&&(xe(y,p)?y!==null&&o.delete(s):(c==="retain"&&d(),p===null?delete l[f]:l[f]=p))}o.deleted||(c==="insert"&&d(),Ot(r,o.content));break}}o=o.right}for(d();n.length>0;){const f=n[n.length-1];if(f.retain!==void 0&&f.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class Ae extends k{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this._length}_integrate(e,n){super._integrate(e,n);try{this._pending.forEach(s=>s())}catch(s){console.error(s)}this._pending=null}_copy(){return new Ae}clone(){const e=new Ae;return e.applyDelta(this.toDelta()),e}_callObserver(e,n){super._callObserver(e,n);const s=new ff(this,e,n);Ts(this,e,s),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){let e="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===be&&(e+=n.content.str),n=n.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:n=!0}={}){this.doc!==null?E(this.doc,s=>{const r=new br(null,this._start,0,new Map);for(let i=0;i<e.length;i++){const o=e[i];
5if(o.insert!==void 0){const c=!n&&typeof o.insert=="string"&&i===e.length-1&&r.right===null&&o.insert.slice(-1)===`
6`?o.insert.slice(0,-1):o.insert;(typeof c!="string"||c.length>0)&&Xs(s,this,r,c,o.attributes||{})}else o.retain!==void 0?yo(s,this,r,o.retain,o.attributes||{}):o.delete!==void 0&&mo(s,r,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,n,s){const r=[],i=new Map,o=this.doc;let c="",l=this._start;function a(){if(c.length>0){const h={};let d=!1;i.forEach((p,y)=>{d=!0,h[y]=p});const f={insert:c};d&&(f.attributes=h),r.push(f),c=""}}const u=()=>{for(;l!==null;){if(ct(l,e)||n!==void 0&&ct(l,n))switch(l.content.constructor){case be:{const h=i.get("ychange");e!==void 0&&!ct(l,e)?(h===void 0||h.user!==l.id.client||h.type!=="removed")&&(a(),i.set("ychange",s?s("removed",l.id):{type:"removed"})):n!==void 0&&!ct(l,n)?(h===void 0||h.user!==l.id.client||h.type!=="added")&&(a(),i.set("ychange",s?s("added",l.id):{type:"added"})):h!==void 0&&(a(),i.delete("ychange")),c+=l.content.str;break}case Oe:case st:{a();const h={insert:l.content.getContent()[0]};if(i.size>0){const d={};h.attributes=d,i.forEach((f,p)=>{d[p]=f})}r.push(h);break}case x:ct(l,e)&&(a(),Ot(i,l.content));break}l=l.right}a()};return e||n?E(o,h=>{e&&mr(h,e),n&&mr(h,n),u()},"cleanup"):u(),r}insert(e,n,s){if(n.length<=0)return;const r=this.doc;r!==null?E(r,i=>{const o=Dn(i,this,e,!s);s||(s={},o.currentAttributes.forEach((c,l)=>{s[l]=c})),Xs(i,this,o,n,s)}):this._pending.push(()=>this.insert(e,n,s))}insertEmbed(e,n,s){const r=this.doc;r!==null?E(r,i=>{const o=Dn(i,this,e,!s);Xs(i,this,o,n,s||{})}):this._pending.push(()=>this.insertEmbed(e,n,s||{}))}delete(e,n){if(n===0)return;const s=this.doc;s!==null?E(s,r=>{mo(r,Dn(r,this,e,!0),n)}):this._pending.push(()=>this.delete(e,n))}format(e,n,s){if(n===0)return;const r=this.doc;r!==null?E(r,i=>{const o=Dn(i,this,e,!1);o.right!==null&&yo(i,this,o,n,s)}):this._pending.push(()=>this.format(e,n,s))}removeAttribute(e){this.doc!==null?E(this.doc,n=>{Zn(n,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,n){this.doc!==null?E(this.doc,s=>{hi(s,this,e,n)}):this._pending.push(()=>this.setAttribute(e,n))}getAttribute(e){return di(this,e)}getAttributes(){return Ll(this)}_write(e){e.writeTypeRef(Tf)}}const pf=t=>new Ae;class Qs{constructor(e,n=()=>!0){this._filter=n,this._root=e,this._currentNode=e._start,this._firstCall=!0}[Symbol.iterator](){return this}next(){let e=this._currentNode,n=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(n)))do if(n=e.content.type,!e.deleted&&(n.constructor===Ce||n.constructor===we)&&n._start!==null)e=n._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 we extends k{constructor(){super(),this._prelimContent=[]}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,n){super._integrate(e,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new we}clone(){const e=new we;return e.insert(0,this.toArray().map(n=>n instanceof k?n.clone():n)),e}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new Qs(this,e)}querySelector(e){e=e.toUpperCase();const s=new Qs(this,r=>r.nodeName&&r.nodeName.toUpperCase()===e).next();return s.done?null:s.value}querySelectorAll(e){return e=e.toUpperCase(),Se(new Qs(this,n=>n.nodeName&&n.nodeName.toUpperCase()===e))}_callObserver(e,n){Ts(this,e,new mf(this,n,e))}toString(){return Sl(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,n={},s){const r=e.createDocumentFragment();return s!==void 0&&s._createAssociation(r,this),qt(this,i=>{r.insertBefore(i.toDOM(e,n,s),null)}),r}insert(e,n){this.doc!==null?E(this.doc,s=>{kl(s,this,e,n)}):this._prelimContent.splice(e,0,...n)}insertAfter(e,n){if(this.doc!==null)E(this.doc,s=>{const r=e&&e instanceof k?e._item:e;Qn(s,this,r,n)});else{const s=this._prelimContent,r=e===null?0:s.findIndex(i=>i===e)+1;if(r===0&&e!==null)throw ye("Reference item not found");s.splice(r,0,...n)}}delete(e,n=1){this.doc!==null?E(this.doc,s=>{Dl(s,this,e,n)}):this._prelimContent.splice(e,n)}toArray(){return vl(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return Al(this,e)}slice(e=0,n=this.length){return El(this,e,n)}forEach(e){qt(this,e)}_write(e){e.writeTypeRef(Mf)}}const gf=t=>new we;class Ce extends we{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}
6_integrate(e,n){super._integrate(e,n),this._prelimAttrs.forEach((s,r)=>{this.setAttribute(r,s)}),this._prelimAttrs=null}_copy(){return new Ce(this.nodeName)}clone(){const e=new Ce(this.nodeName),n=this.getAttributes();return rh(n,(s,r)=>{typeof s=="string"&&e.setAttribute(r,s)}),e.insert(0,this.toArray().map(s=>s instanceof k?s.clone():s)),e}toString(){const e=this.getAttributes(),n=[],s=[];for(const c in e)s.push(c);s.sort();const r=s.length;for(let c=0;c<r;c++){const l=s[c];n.push(l+'="'+e[l]+'"')}const i=this.nodeName.toLocaleLowerCase(),o=n.length>0?" "+n.join(" "):"";return`<${i}${o}>${super.toString()}</${i}>`}removeAttribute(e){this.doc!==null?E(this.doc,n=>{Zn(n,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,n){this.doc!==null?E(this.doc,s=>{hi(s,this,e,n)}):this._prelimAttrs.set(e,n)}getAttribute(e){return di(this,e)}hasAttribute(e){return Ol(this,e)}getAttributes(e){return e?rf(this,e):Ll(this)}toDOM(e=document,n={},s){const r=e.createElement(this.nodeName),i=this.getAttributes();for(const o in i){const c=i[o];typeof c=="string"&&r.setAttribute(o,c)}return qt(this,o=>{r.appendChild(o.toDOM(e,n,s))}),s!==void 0&&s._createAssociation(r,this),r}_write(e){e.writeTypeRef(xf),e.writeKey(this.nodeName)}}const yf=t=>new Ce(t.readKey());class mf extends Is{constructor(e,n,s){super(e,s),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(r=>{r===null?this.childListChanged=!0:this.attributesChanged.add(r)})}}class Et extends me{constructor(e){super(),this.hookName=e}_copy(){return new Et(this.hookName)}clone(){const e=new Et(this.hookName);return this.forEach((n,s)=>{e.set(s,n)}),e}toDOM(e=document,n={},s){const r=n[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(e){e.writeTypeRef($f),e.writeKey(this.hookName)}}const wf=t=>new Et(t.readKey());class Xe extends Ae{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 Xe}clone(){const e=new Xe;return e.applyDelta(this.toDelta()),e}toDOM(e=document,n,s){const r=e.createTextNode(this.toString());return s!==void 0&&s._createAssociation(r,this),r}toString(){return this.toDelta().map(e=>{const n=[];for(const r in e.attributes){const i=[];for(const o in e.attributes[r])i.push({key:o,value:e.attributes[r][o]});i.sort((o,c)=>o.key<c.key?-1:1),n.push({nodeName:r,attrs:i})}n.sort((r,i)=>r.nodeName<i.nodeName?-1:1);let s="";for(let r=0;r<n.length;r++){const i=n[r];s+=`<${i.nodeName}`;for(let o=0;o<i.attrs.length;o++){const c=i.attrs[o];s+=` ${c.key}="${c.value}"`}s+=">"}s+=e.insert;for(let r=n.length-1;r>=0;r--)s+=`</${n[r].nodeName}>`;return s}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(Rf)}}const bf=t=>new Xe;class fi{constructor(e,n){this.id=e,this.length=n}get deleted(){throw le()}mergeWith(e){return!1}write(e,n,s){throw le()}integrate(e,n){throw le()}}const _f=0;class Z extends fi{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,n){n>0&&(this.id.clock+=n,this.length-=n),pl(e.doc.store,this)}write(e,n){e.writeInfo(_f),e.writeLen(this.length-n)}getMissing(e,n){return null}}class yn{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new yn(this.content)}splice(e){throw le()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeBuf(this.content)}getRef(){return 3}}const Ef=t=>new yn(t.readBuf());class Gt{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Gt(this.len)}splice(e){const n=new Gt(this.len-e);return this.len=e,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,n){Gn(e.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(e){}gc(e){}write(e,n){e.writeLen(this.len-n)}getRef(){return 1}}const vf=t=>new Gt(t.readLen()),Ml=(t,e)=>new Le({guid:t,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class mn{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 n={};this.opts=n,e.gc||(n.gc=!1),e.autoLoad&&(n.autoLoad=!0),e.meta!==null&&(n.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new mn(Ml(this.doc.guid,this.opts))}splice(e){throw le()}mergeWith(e){return!1}integrate(e,n){this.doc._item=n,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,n){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}}const Sf=t=>new mn(Ml(t.readString(),t.readAny()));class st{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new st(this.embed)}splice(e){throw le()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeJSON(this.embed)}getRef(){return 5}}const Af=t=>new st(t.readJSON());class x{constructor(e,n){this.key=e,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new x(this.key,this.value)}splice(e){throw le()}mergeWith(e){return!1}integrate(e,n){const s=n.parent;s._searchMarker=null,s._hasFormatting=!0}delete(e){}gc(e){}write(e,n){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}const Cf=t=>new x(t.readKey(),t.readJSON());class es{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new es(this.arr)}splice(e){const n=new es(this.arr.slice(e));return this.arr=this.arr.slice(0,e),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,n){}delete(e){}gc(e){}write(e,n){const s=this.arr.length;e.writeLen(s-n);for(let r=n;r<s;r++){const i=this.arr[r];e.writeString(i===void 0?"undefined":JSON.stringify(i))}}getRef(){return 2}}const kf=t=>{const e=t.readLen(),n=[];for(let s=0;s<e;s++){const r=t.readString();r==="undefined"?n.push(void 0):n.push(JSON.parse(r))}return new es(n)};class Qe{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Qe(this.arr)}splice(e){const n=new Qe(this.arr.slice(e));return this.arr=this.arr.slice(0,e),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,n){}delete(e){}gc(e){}write(e,n){const s=this.arr.length;e.writeLen(s-n);for(let r=n;r<s;r++){const i=this.arr[r];e.writeAny(i)}}getRef(){return 8}}const Df=t=>{const e=t.readLen(),n=[];for(let s=0;s<e;s++)n.push(t.readAny());return new Qe(n)};class be{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new be(this.str)}splice(e){const n=new be(this.str.slice(e));this.str=this.str.slice(0,e);const s=this.str.charCodeAt(e-1);return s>=55296&&s<=56319&&(this.str=this.str.slice(0,e-1)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}}const Lf=t=>new be(t.readString()),Of=[cf,af,pf,yf,gf,wf,bf],If=0,Pf=1,Tf=2,xf=3,Mf=4,$f=5,Rf=6;class Oe{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}
6copy(){return new Oe(this.type._copy())}splice(e){throw le()}mergeWith(e){return!1}integrate(e,n){this.type._integrate(e.doc,n)}delete(e){let n=this.type._start;for(;n!==null;)n.deleted?n.id.clock<(e.beforeState.get(n.id.client)||0)&&e._mergeStructs.push(n):n.delete(e),n=n.right;this.type._map.forEach(s=>{s.deleted?s.id.clock<(e.beforeState.get(s.id.client)||0)&&e._mergeStructs.push(s):s.delete(e)}),e.changed.delete(this.type)}gc(e){let n=this.type._start;for(;n!==null;)n.gc(e,!0),n=n.right;this.type._start=null,this.type._map.forEach(s=>{for(;s!==null;)s.gc(e,!0),s=s.left}),this.type._map=new Map}write(e,n){this.type._write(e)}getRef(){return 7}}const Nf=t=>new Oe(Of[t.readTypeRef()](t)),ts=(t,e,n)=>{const{client:s,clock:r}=e.id,i=new P(_(s,r+n),e,_(s,r+n-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(n));return e.deleted&&i.markDeleted(),e.keep&&(i.keep=!0),e.redone!==null&&(i.redone=_(e.redone.client,e.redone.clock+n)),e.right=i,i.right!==null&&(i.right.left=i),t._mergeStructs.push(i),i.parentSub!==null&&i.right===null&&i.parent._map.set(i.parentSub,i),e.length=n,i};class P extends fi{constructor(e,n,s,r,i,o,c,l){super(e,l.getLength()),this.origin=s,this.left=n,this.right=r,this.rightOrigin=i,this.parent=o,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?Ji:0}set marker(e){(this.info&Vs)>0!==e&&(this.info^=Vs)}get marker(){return(this.info&Vs)>0}get keep(){return(this.info&Yi)>0}set keep(e){this.keep!==e&&(this.info^=Yi)}get countable(){return(this.info&Ji)>0}get deleted(){return(this.info&Bs)>0}set deleted(e){this.deleted!==e&&(this.info^=Bs)}markDeleted(){this.info|=Bs}getMissing(e,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=R(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=R(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ft&&this.id.client!==this.parent.client&&this.parent.clock>=R(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=uo(e,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Ne(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===Z||this.right&&this.right.constructor===Z)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===P&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===P&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===ft){const s=Gs(n,this.parent);s.constructor===Z?this.parent=null:this.parent=s.content.type}return null}integrate(e,n){if(n>0&&(this.id.clock+=n,this.left=uo(e,e.doc.store,_(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let 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),Cn(this.origin,r.origin)){if(r.id.client<this.id.client)s=r,i.clear();else if(Cn(this.rightOrigin,r.rightOrigin))break}else if(r.origin!==null&&o.has(Gs(e.doc.store,r.origin)))i.has(Gs(e.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(e)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),pl(e.doc.store,this),this.content.integrate(e,this),fo(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new Z(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:_(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&Cn(e.origin,this.lastId)&&this.right===e&&Cn(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 n=this.parent._searchMarker;
6return n&&n.forEach(s=>{s.p===e&&(s.p=this,!this.deleted&&this.countable&&(s.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 n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),Gn(e.deleteSet,this.id.client,this.id.clock,this.length),fo(e,n,this.parentSub),this.content.delete(e)}}gc(e,n){if(!this.deleted)throw ie();this.content.gc(e),n?Vd(e,this,new Z(this.id,this.length)):this.content=new Gt(this.length)}write(e,n){const s=n>0?_(this.id.client,this.id.clock+n-1):this.origin,r=this.rightOrigin,i=this.parentSub,o=this.content.getRef()&bs|(s===null?0:ee)|(r===null?0:ve)|(i===null?0:Bt);if(e.writeInfo(o),s!==null&&e.writeLeftID(s),r!==null&&e.writeRightID(r),s===null&&r===null){const c=this.parent;if(c._item!==void 0){const l=c._item;if(l===null){const a=Fd(c);e.writeParentInfo(!0),e.writeString(a)}else e.writeParentInfo(!1),e.writeLeftID(l.id)}else c.constructor===String?(e.writeParentInfo(!0),e.writeString(c)):c.constructor===ft?(e.writeParentInfo(!1),e.writeLeftID(c)):ie();i!==null&&e.writeString(i)}this.content.write(e,n)}}const $l=(t,e)=>Uf[e&bs](t),Uf=[()=>{ie()},vf,kf,Ef,Lf,Af,Cf,Nf,Df,Sf,()=>{ie()}],jf=10;class se extends fi{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,n){ie()}write(e,n){e.writeInfo(jf),m(e.restEncoder,this.length-n)}getMissing(e,n){return null}}const Rl=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Nl="__ $YJS$ __";Rl[Nl]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Rl[Nl]=!0;const Zs=3e4;class Hf extends kc{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const n=mt();this.getLocalState()!==null&&Zs/2<=n-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const s=[];this.meta.forEach((r,i)=>{i!==this.clientID&&Zs<=n-r.lastUpdated&&this.states.has(i)&&s.push(i)}),s.length>0&&pi(this,s,"timeout")},he(Zs/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 n=this.clientID,s=this.meta.get(n),r=s===void 0?0:s.clock+1,i=this.states.get(n);e===null?this.states.delete(n):this.states.set(n,e),this.meta.set(n,{clock:r,lastUpdated:mt()});const o=[],c=[],l=[],a=[];e===null?a.push(n):i==null?e!=null&&o.push(n):(c.push(n),ht(i,e)||l.push(n)),(o.length>0||l.length>0||a.length>0)&&this.emit("change",[{added:o,updated:l,removed:a},"local"]),this.emit("update",[{added:o,updated:c,removed:a},"local"])}setLocalStateField(e,n){const s=this.getLocalState();s!==null&&this.setLocalState({...s,[e]:n})}getStates(){return this.states}}const pi=(t,e,n)=>{const s=[];for(let r=0;r<e.length;r++){const i=e[r];if(t.states.has(i)){if(t.states.delete(i),i===t.clientID){const o=t.meta.get(i);t.meta.set(i,{clock:o.clock+1,lastUpdated:mt()})}s.push(i)}}s.length>0&&(t.emit("change",[{added:[],updated:[],removed:s},n]),t.emit("update",[{added:[],updated:[],removed:s},n]))},Nt=(t,e,n=t.states)=>{const s=e.length,r=W();m(r,s);for(let i=0;i<s;i++){const o=e[i],c=n.get(o)||null,l=t.meta.get(o).clock;m(r,o),m(r,l),Ye(r,JSON.stringify(c))}return A(r)},Ff=(t,e,n)=>{const s=je(e),r=mt(),i=[],o=[],c=[],l=[],a=w(s);for(let u=0;u<a;u++){const h=w(s);let d=w(s);const f=JSON.parse(Me(s)),p=t.meta.get(h),y=t.states.get(h),g=p===void 0?0:p.clock;(g<d||g===d&&f===null&&t.states.has(h))&&(f===null?h===t.clientID&&t.getLocalState()!=null?d++:t.states.delete(h):t.states.set(h,f),t.meta.set(h,{clock:d,lastUpdated:r}),p===void 0&&f!==null?i.push(h):p!==void 0&&f===null?l.push(h):f!==null&&(ht(f,y)||c.push(h),o.push(h)))}(i.length>0||c.length>0||l.length>0)&&t.emit("change",[{added:i,updated:c,removed:l},n]),(i.length>0||o.length>0||l.length>0)&&t.emit("update",[{added:i,updated:o,removed:l},n])},Ul=0,gi=1,jl=2,_r=(t,e)=>{m(t,Ul);const n=jd(e);L(t,n)},Hl=(t,e,n)=>{m(t,gi),L(t,$d(e,n))},Bf=(t,e,n)=>Hl(e,n,V(t)),Fl=(t,e,n,s)=>{try{Td(e,V(t),n)}catch(r){s?.(r),console.error("Caught error while handling a Yjs update",r)}},Vf=(t,e)=>{m(t,jl),L(t,e)},Wf=Fl,zf=(t,e,n,s,r)=>{const i=w(t);switch(i){case Ul:Bf(t,e,n);break;case gi:Fl(t,n,s,r);break;case jl:Wf(t,n,s,r);break;default:throw new Error("Unknown message type")}return i},Bl=new Map;class Kf{constructor(e){this.room=e,this.onmessage=null,this._onChange=n=>n.key===e&&this.onmessage!==null&&this.onmessage({data:Dh(n.newValue||"")}),ph(this._onChange)}postMessage(e){Ic.setItem(this.room,kh(Eh(e)))}close(){gh(this._onChange)}}const Yf=typeof BroadcastChannel>"u"?Kf:BroadcastChannel,yi=t=>_e(Bl,t,()=>{const e=Re(),n=new Yf(t);return n.onmessage=s=>e.forEach(r=>r(s.data,"broadcastchannel")),{bc:n,subs:e}}),Jf=(t,e)=>(yi(t).subs.add(e),e),qf=(t,e)=>{const n=yi(t),s=n.subs.delete(e);return s&&n.subs.size===0&&(n.bc.close(),Bl.delete(t)),s},lt=(t,e,n=null)=>{const s=yi(t);
6s.bc.postMessage(e),s.subs.forEach(r=>r(e,n))},Gf=t=>ih(t,(e,n)=>`${encodeURIComponent(n)}=${encodeURIComponent(e)}`).join("&");let Xf="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",Qf=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=Xf[n[t]&63];return e};const Zf=0,ep=(t,e,n)=>{switch(w(t)){case Zf:n(e,Me(t))}},tp=typeof window>"u",wn=[];wn[0]=(t,e,n,s,r)=>{m(t,0);const i=zf(e,t,n.doc,n);s&&i===gi&&!n.synced&&(n.synced=!0)};wn[3]=(t,e,n,s,r)=>{m(t,1),L(t,Nt(n.awareness,Array.from(n.awareness.getStates().keys())))};wn[1]=(t,e,n,s,r)=>{Ff(n.awareness,V(e),n)};wn[2]=(t,e,n,s,r)=>{ep(e,n.doc,(i,o)=>np(n,o))};function np(t,e){console.warn(`Permission denied to access ${t.url}.
7${e}`)}function Vl(t,e,n){const s=je(e),r=W(),i=w(s),o=t.messageHandlers[i];return o?o(r,s,t,n,i):console.error("Unable to compute message"),r}function wo(t){if(t.shouldConnect&&t.ws===null){if(!t._WS)throw new Error("No WebSocket implementation available, did you forget to pass options.WebSocketPolyfill?");const e=new t._WS(t.url);e.binaryType="arraybuffer",t.ws=e,t.wsconnecting=!0,t.wsconnected=!1,t.synced=!1,e.addEventListener("message",n=>
7{if(typeof n.data=="string"){if(n.data.startsWith("__YPS:")){const r=n.data.slice(6);t.emit("custom-message",[r])}return}t.wsLastMessageReceived=mt();const s=Vl(t,new Uint8Array(n.data),!0);Wr(s)>1&&e.send(A(s))}),e.addEventListener("error",n=>{t.emit("connection-error",[n,t])}),e.addEventListener("close",n=>{if(t.emit("connection-close",[n,t]),t.ws=null,t.wsconnecting=!1,t.wsconnected){t.wsconnected=!1,t.synced=!1;const s=Array.from(t.awareness.getStates().keys()).filter(r=>r!==t.doc.clientID);pi(t.awareness,s,t);for(const r of s)t.awareness.meta.delete(r);t.emit("status",[{status:"disconnected"}])}else t.wsUnsuccessfulReconnects++;setTimeout(()=>{t.shouldConnect&&Promise.resolve(t._reconnectWS()).catch(s=>{console.error("Reconnection failed",s)})},Br(vu(2,t.wsUnsuccessfulReconnects)*100,t.maxBackoffTime))}),e.addEventListener("open",()=>{t.wsLastMessageReceived=mt(),t.wsconnecting=!1,t.wsconnected=!0,t.wsUnsuccessfulReconnects=0,t.emit("status",[{status:"connected"}]);const n=W();if(m(n,0),_r(n,t.doc),e.send(A(n)),t.awareness.getL
7ocalState()!==null){t.awareness.setLocalState(t.awareness.getLocalState());const s=W();m(s,1),L(s,Nt(t.awareness,[t.doc.clientID])),e.send(A(s))}}),t.emit("status",[{status:"connecting"}])}}function er(t,e){const n=t.ws;t.wsconnected&&n&&n.readyState===n.OPEN&&n.send(e),t.bcconnected&&lt(t.bcChannel,e,t)}const sp=typeof WebSocket>"u"?null:WebSocket;var rp=class extends kc{maxBackoffTime;bcChannel;url;roomname;doc;_WS;awareness;wsconnected;wsconnecting;bcconnected;disableBc;wsUnsuccessfulReconnects;messageHandlers;_synced;ws;wsLastMessageReceived;shouldConnect;_resyncInterval;_bcSubscriber;_updateHandler;_awarenessUpdateHandler;_unloadHandler;constructor(t,e,n,{connect:s=!0,awareness:r=new Hf(n),params:i={},isPrefixedUrl:o=!1,WebSocketPolyfill:c=sp,resyncInterval:l=-1,maxBackoffTime:a=2500,disableBc:u=tp}={}){for(super();t[t.length-1]==="/";)t=t.slice(0,t.length-1);const h=Gf(i);this.maxBackoffTime=a,this.bcChannel=`${t}/${e}`,this.url=o?t:`${t}/${e}${h.length===0?"":`?${h}`}`,this.roomname=e,this.doc=n,this._WS=c,this.awareness=r,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=u,this.wsUnsuccessfulReconnects=0,this.messageHandlers=wn.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=s,this._resyncInterval=0,l>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const d=W();m(d,0),_r(d,n),this.ws.send(A(d))}},l)),this._bcSubscriber=(d,f)=>{if(f!==this){const p=Vl(this,new Uint8Array(d),!1);Wr(p)>1&&lt(this.bcChannel,A(p),this)}},this._updateHandler=(d,f)=>{if(f!==this){const p=W();m(p,0),Vf(p,d),er(this,A(p))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:d,updated:f,removed:p},y)=>{const g=d.concat(f).concat(p),b=W();m(b,1),L(b,Nt(r,g)),er(this,A(b))},this._unloadHandler=()=>{pi(this.awareness,[n.clientID],"window unload")},typeof window<"u"?window.addEventListener("unload",this._unloadHandler):typeof process<"u"&&typeof process.on=="function"&&process.on("exit",this._unloadHandler),r.on("change",this._awarenessUpdateHandler),clearInterval(r._checkInterval),s&&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),this.disconnect(),typeof window<"u"?window.removeEventListener("unload",this._unloadHandler):typeof process<"u"&&typeof process.off=="function"&&process.off("exit",this._unloadHandler),this.awareness.off("change",this._awarenessUpdateHandler),this.doc.off("update",this._updateHandler),super.destroy()}connectBc(){if(this.disableBc)return;this.bcconnected||(Jf(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const t=W();m(t,0),_r(t,this.doc),lt(this.bcChannel,A(t),this);const e=W();m(e,0),Hl(e,this.doc),lt(this.bcChannel,A(e),this);const n=W();m(n,3),lt(this.bcChannel,A(n),this);const s=W();m(s,1),L(s,Nt(this.awareness,[this.doc.clientID])),lt(this.bcChannel,A(s),this)}disconnectBc(){const t=W();m(t,1),L(t,Nt(this.awareness,[this.doc.clientID],new Map)),er(this,A(t)),this.bcconnected&&(qf(this.bcChannel,this._bcSubscriber),this.bcconnected=!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&this.ws.close()}_reconnectWS(){wo(this)}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(wo(this),this.connectBc())}};function bo(t,e,n){if(typeof t!==n)throw new Error(`Invalid "${e}" parameter provided to YProvider. Expected: ${n}, received: ${t}`)}var ip=class extends rp{id;#e;constructor(t,e,n,s={}){bo(t,"host","string"),bo(e,"room","string"),t=t.replace(/^(http|https|ws|wss):\/\//,""),t.endsWith("/")&&(t=t.slice(0,-1));const r=`${s.protocol||(t.startsWith("localhost:")||t.startsWith("127.0.0.1:")||t.startsWith("192.168.")||t.startsWith("10.")||t.startsWith("172.")&&t.split(".")[1]>="16"&&t.split(".")[1]<="31"?"ws":"wss")}://${t}${s.prefix||`/parties/${s.party||"main"}`}`,i=s.connectionId??Qf(10),{params:o,connect:c=!0,...l}=s,a={...l,isPrefixedUrl:!!s.prefix,connect:!1};super(r,e,n??new Le,a),this.id=i,this.#e=o,c&&this.connect()}async#t(){const t=typeof this.#e=="function"?await this.#e():this.#e,e=ne
7w URLSearchParams([["_pk",this.id]]);if(t)for(const[s,r]of Object.entries(t))r!=null&&e.append(s,r);const n=new URL(this.url);n.search=e.toString(),this.url=n.toString()}async connect(){try{await this.#t(),super.connect()}catch(t){throw console.error("Failed to open connecton to PartyServer",t),t}}async _reconnectWS(){try{await this.#t()}catch(t){console.error("Failed to refresh params, reconnecting with stale params",t)}super._reconnectWS()}sendMessage(t){this.ws?.send(`__YPS:${t}`)}};const op=50;function cp(t){const e=t._updateHandler;if(typeof e!="function")throw new Error("Provider has no _updateHandler to coalesce");const n=[];let s=null,r=-1/0;const i=()=>{if(s!==null&&(clearTimeout(s),s=null),n.length===0)return;const c=n.length===1?n[0]:ml(n);n.length=0,r=Date.now(),e(c,null)},o=(c,l)=>{if(l===t||(n.push(c),s!==null))return;const a=r+op-Date.now();if(a<=0){i();return}s=setTimeout(i,a)};return t.doc.off("update",e),t._updateHandler=o,t.doc.on("update",o),{flush:i}}const Wl=["data-playhtml-hover","data-playhtml-focus"],lp=["__playhtml-element","ph-flash","ph-inspect-highlight","ph-inspect-highlight-hover","ph-inspect-selected","playhtml-loading"],ap={"aria-busy":"true","aria-live":"polite"},_o={childList:!0,attributes:!0,subtree:!1,characterData:!0},up={defaultData:t=>Ut(t),myDefaultAwareness:{hover:!1,focus:!1},onMount:({getElement:t,setData:e,setMyAwareness:n})=>{const s=t(),r=e,i=wi(s,l=>{const a=l.filter(u=>u.type!=="attributes"||!Wl.includes(u.attributeName||""));a.length!==0&&r(u=>{hp(u,a)})},_o);s.__playhtml_observer=i,s.addEventListener("mouseenter",()=>{n({hover:!0,focus:s.hasAttribute("data-playhtml-focus")}),s.setAttribute("data-playhtml-hover","")}),s.addEventListener("mouseleave",()=>{n({hover:!1,focus:s.hasAttribute("data-playhtml-focus")}),s.removeAttribute("data-playhtml-hover")}),s.addEventListener("focusin",()=>{n({hover:s.hasAttribute("data-playhtml-hover"),focus:!0}),s.setAttribute("data-playhtml-focus","")}),s.addEventListener("focusout",()=>{n({hover:s.hasAttribute("data-playhtml-hover"),focus:!1}),s.removeAttribute("data-playhtml-focus")});const o=(l,a)=>{if(l.formState&&(a.formState=l.formState),l.children&&a.children)for(let u=0;u<l.children.length;u++){const h=l.children[u];h.nodeType==="HTMLElement"&&a.children[u]&&o(h,a.children[u])}},c=()=>{r(l=>{const a=Ut(s);o(a,l),a.children&&l.children.splice(0,l.children.length,...a.children)})};s.addEventListener("input",c),s.addEventListener("change",c)},updateElement:({element:t,data:e})=>{const n=Ut(t);if(mi(n,e))return;const s=t.__playhtml_observer;s&&(s.takeRecords(),s.disconnect()),Fn(t,e),s&&s.observe(t,_o)},updateElementAwareness:({element:t,awareness:e})=>{const n=e.some(r=>r?.hover),s=e.some(r=>r?.focus);n?t.setAttribute("data-playhtml-hover",""):t.removeAttribute("data-playhtml-hover"),s?t.setAttribute("data-playhtml-focus",""):t.removeAttribute("data-playhtml-focus")}};function Eo(t){return t.nodeType==="HTMLElement"}function mi(t,e){if(t.nodeType!==e.nodeType)return!1;
7if(t.nodeType==="Text"&&e.nodeType==="Text")return t.textContent===e.textContent;if(Eo(t)&&Eo(e)){if(t.tagName!==e.tagName)return!1;const n=Er(t.attributes),s=Er(e.attributes);if(Object.keys(n).length!==Object.keys(s).length)return!1;for(const[l,a]of Object.entries(n))if(s[l]!==a)return!1;const r=t.formState,i=e.formState;if((r||i)&&(!r||!i||r.checked!==i.checked||r.value!==i.value||r.selectedIndex!==i.selectedIndex))return!1;const o=ns(t.children),c=ns(e.children);if(o.length!==c.length)return!1;for(let l=0;l<o.length;l++)if(!mi(o[l],c[l]))return!1}return!0}function wi(t,e,n){const s=new MutationObserver(e);return s.observe(t,n),s}function hp(t,e){e.forEach(n=>{switch(n.type){case"attributes":dp(t,n);break;case"childList":fp(t,n);break;case"characterData":pp(t,n);break}})}function dp(t,e){if(t.nodeType!=="Text"&&e.target instanceof HTMLElement){const n=e.attributeName,s=e.target.getAttribute(n),r=Ei(e.target);if(s!==null){const i=vi(n,s,r);i===null?n in t.attributes&&delete t.attributes[n]:t.attributes[n]!==i&&(t.attributes[n]=i)}else n in t.attributes&&delete t.attributes[n]}}function fp(t,e){if(t.nodeType==="Text"||!(e.target instanceof HTMLElement))return;const n=[];e.target.childNodes.forEach(r=>{bi(r)&&n.push(Ut(r))});const s=ns(t.children);s.length===t.children.length&&mp(s,n)||t.children.splice(0,t.children.length,...n)}function pp(t,e){const n=e.target;switch(t.nodeType){case"Text":if(n instanceof Text)return t.textContent=n.textContent||"",!0;break}return!1}function gp(t){return t instanceof HTMLElement||t instanceof Text}function zl(t){return t instanceof HTMLElement&&t.classList.contains("ph-inspect-label")}function bi(t){return gp(t)&&!zl(t)}function _i(t,e){return!!t?.split(/\s+/).includes(e)}function yp(t){return t.nodeType==="HTMLElement"&&_i(t.attributes.class,"ph-inspect-label")}function ns(t){return t.filter(e=>!yp(e))}function mp(t,e){return t.length!==e.length?!1:t.every((n,s)=>mi(n,e[s]))}function Kl(t,e){const n=new Set(lp);return e&&_i(t,"playhtml-loading")&&n.add(e),n}function Ei(t){const e=t.getAttribute("class")||void 0;return{classValue:e,localClassNames:Kl(e,t.getAttribute("loading-class"))}}function wp(t){return{classValue:t.class,localClassNames:Kl(t.class,t["loading-class"])}}function Yl(t,e,n){return Wl.includes(t)?!0:_i(n.classValue,"playhtml-loading")&&ap[t]===e}function vi(t,e,n){return Yl(t,e,n)?null:t==="class"?bp(e,n.localClassNames)||null:e}function Er(t){const e={},n=wp(t);for(const[s,r]of Object.entries(t)){const i=vi(s,r,n);i!==null&&(e[s]=i)}return e}function bp(t,e){return t.split(/\s+/).filter(n=>n&&!e.has(n)).join(" ")}function Jl(t,e){return t.split(/\s+/).filter(n=>e.has(n)).join(" ")}function _p(t,e,n){const s=[...t.split(/\s+/).filter(Boolean),...Jl(e,n).split(/\s+/).filter(Boolean)];return Array.from(new Set(s)).join(" ")}function Ep(t){if(t instanceof HTMLInputElement){const e={};return t.type==="checkbox"||t.type==="radio"?e.checked=t.checked:e.value=t.value,e}if(t instanceof HTMLTextAreaElement)return{value:t.value};if(t instanceof HTMLSelectElement)return{selectedIndex:t.selectedIndex,value:t.value}}function Ut(t){if(t instanceof Text)return{nodeType:"Text",textContent:t.textContent||""};const e={nodeType:"HTMLElement",tagName:t.tagName.toLowerCase(),attributes:{},children:[]},n=Ei(t);for(const r of t.attributes){const i=vi(r.name,r.value,n);i!==null&&(e.attributes[r.name]=i)}const s=Ep(t);return s&&(e.formState=s),t.childNodes.forEach(r=>{bi(r)&&e.children.push(Ut(r))}),e}function vp(t,e){e&&(t instanceof HTMLInputElement?(t.type==="checkbox"||t.type==="radio")&&e.checked!==void 0?t.checked=e.checked:e.value!==void 0&&(t.value=e.value):t instanceof HTMLTextAreaElement&&e.value!==void 0?t.value=e.value:t instanceof HTMLSelectElement&&e.selectedIndex!==void 0&&(t.selectedIndex=e.selectedIndex))}function Fn(t,e){Sp(t,e),e.nodeType==="HTMLElement"&&(Ap(t,e),vp(t,e.formState),kp(t,e))}function Sp(t,e){e&&e.nodeType==="Text"&&t.textContent!==e.textContent&&(t.textContent=e.textContent||"")}function Ap(t,e){if(!e)return;const n=e.attributes&&typeof e.attributes=="object"?Er(e.attributes):{},s=Ei(t);for(const[r,i]of Object.entries(n)){const o=r==="class"?_p(i,t.getAttribute("class")||"",s.localClassNames):i;t.getAttribute(r)!==o&&t.setAttribute(r,o)}
7Array.from(t.attributes).forEach(r=>{if(!Yl(r.name,r.value,s)){if(r.name==="class"){const i=Jl(r.value,s.localClassNames);if(!("class"in n)&&i){t.setAttribute("class",i);return}}r.name in n||t.removeAttribute(r.name)}})}function vo(t){return t.nodeType==="Text"?document.createTextNode(t.textContent):document.createElement(t.tagName)}function Cp(t,e){return e.nodeType==="Text"?t instanceof Text:t instanceof HTMLElement&&t.tagName.toLowerCase()===e.tagName}function kp(t,e){const n=Array.from(t.childNodes).filter(bi),s=ns(e.children),r=Math.min(n.length,s.length);for(let i=0;i<r;i++){const o=n[i],c=s[i];if(Cp(o,c))Fn(o,c);else{const l=vo(c);t.replaceChild(l,o),Fn(l,c)}}for(let i=r;i<s.length;i++){const o=s[i],c=vo(o),l=Array.from(t.childNodes).find(zl);t.insertBefore(c,l??null),Fn(c,o)}for(let i=n.length-1;i>=r;i--)t.removeChild(n[i])}const vr=16,Ve=512,ql=/[\u0000-\u001f\u007f]/,Im=150;function Dp(){return`hsl(${Math.floor(Math.random()*360)}, 70%, 60%)`}function So(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function Gl(t){if(!So(t)||!Ao(t.publicKey))return null;const e=So(t.playerStyle)?t.playerStyle:{},n=Array.isArray(e.colorPalette)?e.colorPalette.filter(Ao).slice(0,vr):[],s={publicKey:t.publicKey,playerStyle:{colorPalette:n}},r=Co(t.name);r!==void 0&&(s.name=r);const i=Co(e.cursorStyle);return i!==void 0&&(s.playerStyle.cursorStyle=i),Number.isFinite(t.createdAt)&&(s.createdAt=Number(t.createdAt)),s}function Ao(t){return typeof t=="string"&&t.length>0&&t.length<=Ve&&!ql.test(t)}function Co(t){if(typeof t=="string"&&!ql.test(t))return t.slice(0,Ve)}function Lp(){const t=crypto.getRandomValues(new Uint8Array(16)).reduce((s,r)=>s+r.toString(16).padStart(2,"0"),""),e=Math.floor(Math.random()*360),n=[`hsl(${e}, 70%, 60%)`,`hsl(${(e+120)%360}, 70%, 60%)`,`hsl(${(e+240)%360}, 70%, 60%)`];return{publicKey:t,playerStyle:{colorPalette:n},createdAt:Date.now()}}function Op(t){const e=t.playerStyle?.colorPalette?.[0];return typeof e=="string"&&e.length>0}function Sr(t){try{localStorage.setItem(Xl,JSON.stringify(t))}catch(e){console.warn("Failed to save player identity to localStorage:",e)}}function Ip(t){return Op(t)?!1:(t.playerStyle||(t.playerStyle={colorPalette:[]}),Array.isArray(t.playerStyle.colorPalette)||(t.playerStyle.colorPalette=[]),t.playerStyle.colorPalette[0]=Dp(),!0)}const Xl="playhtml_player_identity";let Ln=null;function Pp(){if(Ln)return Ln;const t=localStorage.getItem(Xl);if(t)try{const n=JSON.parse(t),s=Gl(n);if(s)return(Ip(s)||JSON.stringify(s)!==JSON.stringify(n))&&Sr(s),Ln=s,s}catch{console.warn("Failed to parse stored player identity, generating new one")}const e=Lp();return Sr(e),Ln=e,e}const Si=512,ss=4096;function tr(t){if(!N(t))throw new Error("Presence message must be an object");switch(t.type){case"presence-join":return Tp(t),t;case"presence-update":return Do(t.channel),xp(t.channel,t.value),t;case"presence-clear":return Do(t.channel),t;default:throw new Error("Unsupported presence message type")}}function Tp(t){ta(t),rs(t.page,"page",Si),t.identity!==void 0&&Ql(t.identity)}function xp(t,e){if(e===void 0)throw new Error("Presence value must not be undefined");ta(e),t==="cursor"&&Mp(e),t==="identity"&&Ql(e)}function Mp(t){if(!N(t))throw new Error("cursor presence value must be an object");if(!("cursor"in t))throw new Error("cursor presence value must include cursor");if(t.cursor!==null&&$p(t.cursor),t.zone!==void 0&&t.zone!==null&&Rp(t.zone),rs(t.page,"page",Si),t.at!==void 0&&!Number.isFinite(t.at))throw new Error("cursor at must be a finite number")}function Pm(t){try{return Zl(t),!0}catch{return!1}}function Ql(t){Zl(t)}function Zl(t){if(!N(t))throw new Error("identity must be an object");if(ko(t,["publicKey","name","playerStyle","createdAt"],"identity"),nr(t.publicKey,"identity.publicKey",Ve),!N(t.playerStyle))throw new Error("identity.playerStyle must be an object");ko(t.playerStyle,["colorPalette","cursorStyle"],"identity.playerStyle");const e=t.playerStyle.colorPalette;if(!Array.isArray(e))throw new Error("identity.playerStyle.colorPalette must be an array");if(e.length>vr)throw new Error(`identity.playerStyle.colorPalette must have ${vr} colors or less`);nr(e[0],"identity.playerStyle.colorPalette[0]",Ve);for(let n=1;n<e.length;n++)nr(e[n],`identity.playerStyle.colorPalette[${n}]`,Ve);if(rs(t.name,"identity.name",Ve),rs(t.playerStyle.cursorStyle,"identity.playerStyle.cursorStyle",Ve),t.createdAt!==void 0&&!Number.isFinite(t.createdAt))throw new Error("identity.createdAt must be a finite number")}function ko(t,e,n){for(const s of Object.keys(t))if(!e.includes(s))throw new Error(`${n} must only include public presence fields`)}function Tm(t){try{return ea(t),!0}catch{return!1}}function $p(t){ea(t)}function ea(t){if(!N(t))throw new Error("cursor must be an object");
7if(!Number.isFinite(t.x))throw new Error("cursor.x must be a finite number");if(!Number.isFinite(t.y))throw new Error("cursor.y must be a finite number");if(typeof t.pointer!="string"||t.pointer.length===0)throw new Error("cursor.pointer must be a non-empty string")}function Rp(t){if(!N(t))throw new Error("cursor zone must be an object");if(typeof t.zoneId!="string"||t.zoneId.length===0)throw new Error("cursor zoneId must be a non-empty string");if(!Number.isFinite(t.relX))throw new Error("cursor zone relX must be a finite number");if(!Number.isFinite(t.relY))throw new Error("cursor zone relY must be a finite number")}function Do(t){if(typeof t!="string"||t.length===0)throw new Error("Presence channel must be a non-empty string");Ai(t,"Presence channel",128)}function nr(t,e,n){if(typeof t!="string"||t.length===0)throw new Error(`${e} must be a non-empty string`);Ai(t,e,n)}function rs(t,e,n){if(t!==void 0){if(typeof t!="string")throw new Error(`${e} must be a string`);Ai(t,e,n)}}function Ai(t,e,n){if(t.length>n)throw new Error(`${e} must be ${n} characters or less`);if(/[\u0000-\u001f\u007f]/.test(t))throw new Error(`${e} must not contain control characters`)}function ta(t){try{if(JSON.stringify(t)===void 0)throw new Error("Presence value must be JSON-serializable")}catch{throw new Error("Presence value must be JSON-serializable")}}function N(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function ce(t){return t!==null&&typeof t=="object"&&Object.getPrototypeOf(t)===Object.prototype}function pt(t,e){if(Object.is(t,e))return!0;if(Array.isArray(t)&&Array.isArray(e))return t.length===e.length&&t.every((n,s)=>pt(n,e[s]));if(ce(t)&&ce(e)){const n=Object.keys(t),s=Object.keys(e);return n.length===s.length&&s.every(r=>Object.prototype.hasOwnProperty.call(t,r)&&pt(t[r],e[r]))}return!1}function Xt(t,e){if(e!=null){if(Array.isArray(e)){Up(t,e);return}if(ce(e)){for(const n of Object.keys(t))n in e||delete t[n];for(const[n,s]of Object.entries(e))Array.isArray(s)?(Array.isArray(t[n])||(t[n]=[]),Xt(t[n],s)):ce(s)?(ce(t[n])||(t[n]={}),Xt(t[n],s)):Object.is(t[n],s)||(t[n]=s);return}t=e}}function Np(t,e){const n=ce(t)&&"id"in t,s=ce(e)&&"id"in e;return n||s?n&&s&&pt(t.id,e.id):!0}function Up(t,e){let n=0;const s=Math.min(t.length,e.length);for(;n<s&&pt(t[n],e[n]);)n+=1;if(n===t.length&&n===e.length)return;let r=t.length,i=e.length;for(;r>n&&i>n&&pt(t[r-1],e[i-1]);)r-=1,i-=1;if(r-n!==i-n){t.splice(n,r-n,...e.slice(n,i));return}const o=[];for(let l=n;l<i;l+=1)pt(t[l],e[l])||o.push(l);const c=o.length===1;for(const l of o){const a=t[l],u=e[l],h=Array.isArray(a)&&Array.isArray(u)||ce(a)&&ce(u),f=ce(a)&&"id"in a||ce(u)&&"id"in u?Np(a,u):c;h&&f?Xt(a,u):t.splice(l,1,u)}}function ke(t){try{if(typeof structuredClone=="function")return structuredClone(t)}catch{}return t==null?t:typeof t=="object"?JSON.parse(JSON.stringify(t)):t}function na(t){const[e,n]=t.split("#");if(!e||!n)throw new Error("Invalid data-source attribute value");const s=e.indexOf("/"),r=s===-1?e:e.slice(0,s),i=s===-1?"/":e.slice(s);return{domain:r,path:i,elementId:n}}const jp="LOCAL";function Hp(t){return t?t.replace(/^www\./i,""):jp}function Lo(t){if(!t)return"/";const e=t.replace(/\.[^/.]+$/,"");return e.startsWith("/")?e:`/${e}`}function is(t){return Math.round(t*10)/10+0}function $t(t){const e=t?.trim();if(!e)return null;const n=e.startsWith("#")?e.slice(1):e;return document.getElementById(n)??document.querySelector(e)}function Oo(t){return $t(t.getAttribute(Kp))}const Io=1,Po=60;function Fp(t){const e=t.getAttribute(Yp);if(e==null)return Io;const n=parseFloat(e);return Number.isFinite(n)?Math.max(0,Math.min(1,n)):Io}function Bp(t){const e=t.getAttribute(Jp);if(e==null)return Po;const n=parseFloat(e);return!Number.isFinite(n)||n<0?Po:n}function To(t,e,n){return Math.min(t,Math.max(t*e,n))}function Ar(t,e,n){const s=t.getBoundingClientRect(),r=e.getBoundingClientRect();return{x:s.left-r.left-e.clientLeft-n.x,y:s.top-r.top-e.clientTop-n.y}}function Vp(t,e,n,s,r=Ar(t,e,n)){const i=Fp(t),o=Bp(t),c=t.offsetWidth,l=t.offsetHeight,a=To(c,i,o),u=To(l,i,o),h=a-c-r.x,d=e.clientWidth-a-r.x,f=u-l-r.y,p=e.clientHeight-u-r.y;return{x:d<h?0:Math.min(d,Math.max(h,s.x)),y:p<f?0:Math.min(p,Math.max(f,s.y))}}function Wp(t){return{x:is(t.x),y:is(t.y)}}
7const zp="can-duplicate-to",Kp="can-move-bounds",Yp="can-move-bounds-min-visible",Jp="can-move-bounds-min-visible-px";var Y=(t=>(t.CanPlay="can-play",t.CanMove="can-move",t.CanSpin="can-spin",t.CanGrow="can-grow",t.CanToggle="can-toggle",t.CanDuplicate="can-duplicate",t.CanHover="can-hover",t.CanMirror="can-mirror",t))(Y||{});function It(t){return t.getAttribute("data-source")?qp(t):t.id}function qp(t){const e=t.getAttribute("data-source");if(!e)throw new Error("Element has no data-source attribute");const[n,s]=e.split("#");if(!n||!s)throw new Error("Invalid data-source attribute");return s}const sa=`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>")
8      16 0,
9    auto`,Gp=`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 xo(t,{getData:e,getElement:n,getLocalData:s,setLocalData:r}){const i=e(),o=s(),c=n();if(o.isHovering=!0,t.altKey){if(i.scale<=.5){c.style.cursor="not-allowed";return}c.style.cursor=Gp}else{if(i.scale>=i.maxScale){c.style.cursor="not-allowed";return}c.style.cursor=sa}r(o)}function On(t){if("touches"in t){const{clientX:e,clientY:n}=t.touches[0];return{clientX:e,clientY:n}}return{clientX:t.clientX,clientY:t.clientY}}const ra={"can-move":{defaultData:{x:0,y:0},defaultLocalData:{startMouseX:0,startMouseY:0},updateElement:({element:t,data:e})=>{t.style.transform=`translate(${e.x}px, ${e.y}px)`},onDragStart:(t,{data:e,element:n,setLocalData:s})=>{const{clientX:r,clientY:i}=On(t),o=Oo(n),c=o?Ar(n,o,e):void 0;s({startMouseX:r,startMouseY:i,dragX:e.x,dragY:e.y,boundsBaseX:c?.x,boundsBaseY:c?.y})},onDrag:(t,{data:e,localData:n,setData:s,setLocalData:r,element:i})=>{const{clientX:o,clientY:c}=On(t),l=e.x+o-n.startMouseX,a=e.y+c-n.startMouseY,u=Oo(i);if(u){const b={x:n.dragX??e.x,y:n.dragY??e.y},S=b.x+o-n.startMouseX,j=b.y+c-n.startMouseY,B=n.boundsBaseX!==void 0&&n.boundsBaseY!==void 0?{x:n.boundsBaseX,y:n.boundsBaseY}:Ar(i,u,b),O=Vp(i,u,b,{x:S,y:j},B),Q=Wp(O);s(Q);const An=O.x-b.x,_u=O.y-b.y;r({startMouseX:n.startMouseX+An,startMouseY:n.startMouseY+_u,dragX:Q.x,dragY:Q.y,boundsBaseX:B.x,boundsBaseY:B.y});return}const{top:h,left:d,bottom:f,right:p}=i.getBoundingClientRect(),y=window.visualViewport?.width??window.innerWidth,g=window.visualViewport?.height??window.innerHeight;p>y&&o>n.startMouseX||f>g&&c>n.startMouseY||d<0&&o<n.startMouseX||h<0&&c<n.startMouseY||(s({x:is(l),y:is(a)}),r({startMouseX:o,startMouseY:c}))},resetShortcut:"shiftKey"},"can-spin":{defaultData:{rotation:0},defaultLocalData:{startMouseX:0},updateElement:({element:t,data:e})=>{t.style.transform=`rotate(${e.rotation}deg)`},onDragStart:(t,{setLocalData:e})=>{const{clientX:n}=On(t);e({startMouseX:n})},onDrag:(t,{data:e,localData:n,setData:s,setLocalData:r})=>{const{clientX:i}=On(t);let o=Math.abs(i-n.startMouseX)*2,c=e.rotation;i>n.startMouseX?c+=o:i<n.startMouseX&&(c-=o),s({rotation:c}),r({startMouseX:i})},resetShortcut:"shiftKey"},"can-toggle":{defaultData:{on:!1},updateElement:({element:t,data:e})=>{const n=typeof e=="object"?e.on:e;t.classList.toggle("toggled",n),t.classList.toggle("clicked",n)},onClick:(t,{data:e,setData:n})=>{const s=typeof e=="object"?e.on:e;n({on:!s})},resetShortcut:"shiftKey"},"can-grow":{defaultData:{scale:1},defaultLocalData:{maxScale:2,isHovering:!1},updateElement:({element:t,data:e})=>{t.style.transform=`scale(${e.scale})`},onClick:(t,{data:e,element:n,setData:s,localData:r})=>{let{scale:i}=e;if(t.altKey){if(e.scale<=.5)return;i-=.1}else{if(n.style.cursor=sa,e.scale>=r.maxScale)return;i+=.1}s({...e,scale:i})},onMount:t=>{const e=t.getElement();let n=!1;const s=o=>xo(o,t),r=o=>{xo(o,t),!n&&(n=!0,document.addEventListener("keydown",s),document.addEventListener("keyup",s))},i=()=>{n&&(n=!1,document.removeEventListener("keydown",s),document.removeEventListener("keyup",s))};return e.addEventListener("mouseenter",r),e.addEventListener("mouseleave",i),()=>{e.removeEventListener("mouseenter",r),e.removeEventListener("mouseleave",i),document.removeEventListener("keydown",s),document.removeEventListener("keyup",s)}},resetShortcut:"shiftKey"},"can-duplicate":{defaultData:[],defaultLocalData:[],updateElement:({data:t,localData:e,setLocalData:n,element:s})=>{const r=s.getAttribute("can-duplicate"),i=$t(r);let o=document.getElementById(e.slice(-1)?.[0])??null;if(!i){console.error(`Element ${r} not found. Cannot duplicate.`);return}const c=$t(s.getAttribute(zp));function l(u){if(c){c.appendChild(u);return}i.parentNode.insertBefore(u,(o||i).nextSibling)}const a=new Set(e);for(const u of t){if(a.has(u))continue;const h=i.cloneNode(!0);Object.assign(h,{...i}),h.id=u,l(h),e.push(u),window.playhtml.setupPlayElement(h),o=h}n(e)},onClick:(t,{data:e,element:n,setData:s})=>{const r=$t(n.getAttribute("can-duplicate"));if(!r)return;const i=r.id+"-"+Math.random().toString(36).substr(2,9);s(o=>{o.push(i)})},isValidElementForTag:t=>{const e=t.getAttribute("can-duplicate");return e?($t(e)||console.warn(`can-duplicate element (${t.id}) duplicate element ("${e}") not found.`),!0):!1}},"can-hover":{defaultData:{},myDefaultAwareness:{hover:!1},onMount:({getElement:t,setMyAwareness:e})=>{const n=t();n.addEventListener("mouseenter",()=>{e({hover:!0}),n.setAttribute("data-playhtml-hover","")}),n.addEventListener("mouseleave",()=>{e({hover:!1}),n.removeAttribute("data-playhtml-hover")})},updateElement:()=>{},updateElementAwareness:({element:t,awareness:e})=>{e.some(s=>s?.hover)?t.setAttribute("data-playhtml-hover",""):t.removeAttribute("data-playhtml-hover")}},"can-mirror":up};function Xp(){const t=[];
9if(document.querySelectorAll("[shared]").forEach(e=>{const n=e,s=n.id;if(!s)return;const r=`${window.location.host}${Lo(window.location.pathname)}#${s}`;t.push({type:"source",elementId:s,dataSource:r,normalized:r,permissions:n.getAttribute("shared")?.includes("read-only")?"read-only":"read-write",element:n})}),document.querySelectorAll("[data-source]").forEach(e=>{const n=e,s=n.getAttribute("data-source")||"",[r,i]=s.split("#");if(!r||!i)return;const o=r.indexOf("/"),c=o===-1?r:r.slice(0,o),l=o===-1?"/":r.slice(o),a=`${c}${Lo(l)}#${i}`;t.push({type:"consumer",elementId:i,dataSource:s,normalized:a,element:n})}),t.length>0)try{console.table(t.map(e=>({type:e.type,elementId:e.elementId,dataSource:e.dataSource,normalized:e.normalized,permissions:e.permissions||""})))}catch{}return t}function Qp(t){let e=!1,n=!1,s=!1;async function r(){if(!s){if(e){n=!0;return}e=!0;try{await t()}finally{e=!1,n&&!s&&(n=!1,await r())}}}return{trigger:r,destroy(){s=!0,n=!1}}}function Zp(t){const e=()=>{t.trigger()},n=()=>{t.trigger()};window.addEventListener("popstate",e);const s=window.navigation;return s&&typeof s.addEventListener=="function"&&s.addEventListener("currententrychange",n),()=>{window.removeEventListener("popstate",e),s&&typeof s.removeEventListener=="function"&&s.removeEventListener("currententrychange",n)}}function ia(t){document.dispatchEvent(new CustomEvent("playhtml:navigated",{detail:{room:t}}))}function Qt(){return Qt=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},Qt.apply(this,arguments)}function eg(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,Cr(t,e)}function Cr(t,e){return Cr=Object.setPrototypeOf||function(s,r){return s.__proto__=r,s},Cr(t,e)}function tg(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}var oa=(function(){function t(n){this.trigger=n,this.observing=new Map}var e=t.prototype;return e.registerConnection=function(s){var r=this.observing.get(s.observable);r||(r={byKey:new Set,iterate:!1},this.observing.set(s.observable,r)),s.type==="iterate"?r.iterate=!0:r.byKey.add(s.key)},e.removeObservers=function(){var s=this;this.observing.forEach(function(r,i){r.iterate&&i[T].connections.iterate.delete(s),r.byKey.forEach(function(o){i[T].connections.byKey.get(o).delete(s)})}),this.observing.clear()},t})(),Je=[],xs=(function(t){eg(e,t);function e(s,r,i){var o;if(o=t.call(this,function(){return o._trigger()})||this,o.func=s,o.options=r,o.effect=i,o.isInitial=!0,o.reaction=function(){Je.push(tg(o));try{o.func()}finally{Je.pop()}o.effect&&(!o.isInitial||o.options.fireImmediately)&&o.effect(),o.isInitial=!1},!i&&!o.options.fireImmediately)throw new Error("if no effect function passed, should always fireImmediately");return o.reaction(),o}var n=e.prototype;return n._trigger=function(){if(Je.includes(this))throw new Error("already running reaction");this.removeObservers(),this.reaction()},e})(oa);function ca(){return!!Je.length}function la(){return Je.length?Je[Je.length-1]:void 0}function ng(t,e,n){var s=Qt({name:"unnamed",fireImmediately:!0},n),r=new xs(t,s,e);return r}var Bn=0;function aa(){return Bn>0}function kr(t){Bn++;try{return t()}finally{Bn--,Bn===0&&rg()}}var Dr=!1;function ua(){return Dr}function ha(t){Dr=!0;try{t()}finally{Dr=!1}}function sg(t){return function(){return ha(t)}}var Lr=[];function rg(){var t=[].concat(Lr);Lr=[],da(t)}function da(t){var e=new Set;t.forEach(function(n){var s;(n.type==="add"||n.type==="delete")&&n.observable[T].connections.iterate.forEach(function(r){e.add(r)}),(s=n.observable[T].connections.byKey.get(n.key))==null||s.forEach(function(r){e.add(r)})}),e.forEach(function(n){n.trigger()})}function In(t){if(aa()){Lr.push(t);return}da([t])}function Mo(t,e){if(t.type==="iterate")t.observable[T].connections.iterate.add(e);else{var n=t.observable[T].connections.byKey.get(t.key);n||(n=new Set,t.observable[T].connections.byKey.set(t.key,n)),n.add(e)}}function Pn(t,e){if(!ua()){var n=la();n&&(Mo(t,n),n.registerConnection(t)),e&&(Mo(t,e),e.registerConnection(t))}}var Ci=Symbol("$skipreactive"),T=Symbol("$reactive"),oe=Symbol("$reactiveproxy");function bn(t,e){return!!(t&&t[oe]&&t[oe].implicitObserver===e)}function ki(t){return t[Ci]=!0,t}function fa(t){return!!(t&&!bn(t)&&t[T])}function Or(t,e,n){if(n===void 0&&(n=!1),t[Ci]||bn(t,e))return t;var s=ig(t,n);if(!e)return s;var r=s[T].proxiesWithImplicitObserver.get(e);if(!r){var i={implicitObserver:e};Object.setPrototypeOf(i,pa),r=new Proxy(s[T].raw,i),s[T].proxiesWithImplicitObserver.set(e,r)}return r}var Zt=Or;function ig(t,e){if(e===void 0&&(e=!1),bn(t))return t;if(fa(t))return t[T].proxy;if(t[T]||t[oe])throw new Error("unexpected");var n={connections:{iterate:new Set,byKey:new Map},proxy:{},raw:t,proxiesWithImplicitObserver:new Map,shallow:e};Object.defineProperty(t,T,{enumerable:!1,writable:!0,configurable:!0,value:n});var s=new Proxy(t,pa);return n.proxy=s,s}var pa={has:function(e,n){var s=Reflect.has(e,n);return typeof n=="symbol"||Pn({observable:e,key:n,type:"has"}
9,this.implicitObserver),s},get:function(e,n,s){if(n===oe)return{implicitObserver:this.implicitObserver};var r=Reflect.get(e,n,s);if(typeof n=="symbol")return n.toString()==="Symbol($reactiveproxy)"&&console.error("warning, Symbol($reactiveproxy) passed, but does not match $reactiveproxy. Multiple Reactive libraries loaded?"),r;if(n==="length"&&Array.isArray(e)?Pn({observable:e,type:"iterate"},this.implicitObserver):Pn({observable:e,key:n,type:"get"},this.implicitObserver),fa(r))return Or(r,this.implicitObserver);if(e[T].shallow)return r;if(typeof r=="object"&&r!==null&&!bn(r,this.implicitObserver)&&!Object.isFrozen(r)){var i=Reflect.getOwnPropertyDescriptor(e,n);if((!i||!(i.writable===!1&&i.configurable===!1))&&(ca()||this.implicitObserver))return Or(r,this.implicitObserver)}return r},ownKeys:function(e){return Pn({observable:e,type:"iterate"},this.implicitObserver),Reflect.ownKeys(e)},set:function(e,n,s,r){return kr(function(){if(typeof n=="symbol")return Reflect.set(e,n,s,r);var i=Object.hasOwnProperty.call(e,n),o=Reflect.get(e,n,r),c=Reflect.set(e,n,s,r);if(!i)In({observable:e,key:n,value:s,type:"add"});else if(s!==o)if(n==="length"&&Array.isArray(e)){if(!(o<s))for(var l=s+1;l<=o;l++)In({observable:e,key:""+(l-1),oldValue:void 0,type:"delete"})}else In({observable:e,key:n,value:s,oldValue:o,type:"update"});return c})},deleteProperty:function(e,n){return kr(function(){if(typeof n=="symbol")return Reflect.deleteProperty(e,n);var s=Object.hasOwnProperty.call(e,n),r=Reflect.get(e,n),i=Reflect.deleteProperty(e,n);return s&&In({observable:e,key:n,oldValue:r,type:"delete"}),i})},preventExtensions:function(e){throw new Error("Dynamic observable objects cannot be frozen")}};function og(t,e){var n=Qt({name:"unnamed",fireImmediately:!0},e),s=new xs(t,n);return s}function cg(t,e,n){var s=Qt({name:"unnamed",fireImmediately:!0},n),r=new xs(function(){t(e)},s);return e=Zt(e,r),s.fireImmediately&&r.trigger(),r}var ga=(function(){function t(){this._observable=Zt({_key:1})}var e=t.prototype;return e.reportObserved=function(s){return Zt(this._observable,s)._key},e.reportChanged=function(){this._observable._key++},t})();function lg(t,e,n){return new ga}const ag=Object.freeze(Object.defineProperty({__proto__:null,$reactive:T,$reactiveproxy:oe,$skipreactive:Ci,Atom:ga,Observer:oa,Reaction:xs,autorun:og,autorunAsync:cg,createAtom:lg,hasRunningReaction:ca,isActionRunning:aa,isReactive:bn,isTrackingDisabled:ua,markRaw:ki,reaction:ng,reactive:Zt,runInAction:kr,runningReaction:la,untracked:ha,untrackedCB:sg},Symbol.toStringTag,{value:"Module"}));let Ir,Pr,ug=t=>t();function hg(t,e){if(Pr)return Pr(t,e);ug(t)}function Ze(t,e,n){if(Ir)return Ir.apply(null,arguments);throw new Error("observable implementation not provided. Call enableReactiveBindings, enableVueBindings or enableMobxBindings.")}function dg(t){Ir=function(e,n,s){const r=t.createAtom(e);return n&&n(),r},Pr=(e,n)=>t.reaction(e,n,{fireImmediately:!1})}const $o=new WeakSet;function fg(t){if($o.has(t))return t;$o.add(t);let e;const n=new Map;function s(){if(!e){const h=d=>{(d.changes.added.size||d.changes.deleted.size||d.changes.keys.size||d.changes.delta.length)&&e.reportChanged()};e=Ze("map",()=>{t.observe(h)},()=>{t.unobserve(h)})}e.reportObserved(t._implicitObserver)}function r(h){let d=n.get(h);if(!d){const f=p=>{d.reportChanged()};d=Ze(h+"",()=>{t.observe(f)},()=>{t.unobserve(f)}),n.set(h,d)}d.reportObserved(t._implicitObserver)}const i=t.get;t.get=function(h){if(typeof h!="number")throw new Error("unexpected");return r(h),Reflect.apply(i,this,arguments)};function o(h){const d=t[h];t[h]=function(){return s(),Reflect.apply(d,this,arguments)}}function c(h){let d=t,f=Object.getOwnPropertyDescriptor(d,h);if(f||(d=Object.getPrototypeOf(d),f=Object.getOwnPropertyDescriptor(d,h)),f||(d=Object.getPrototypeOf(d),f=Object.getOwnPropertyDescriptor(d,h)),!f)throw new Error("property not found");const p=f.get;f.get=function(){return this._disableTracking||s(),Reflect.apply(p,this,arguments)},Object.defineProperty(t,h,f)}function l(h,d){let f=t,p=Object.getOwnPropertyDescriptor(f,h);if(p||(f=Object.getPrototypeOf(f),p=Object.getOwnPropertyDescriptor(f,h)),p||(f=Object.getPrototypeOf(f),p=Object.getOwnPropertyDescriptor(f,h)),!p)throw new Error("property not found");Object.defineProperty(t,d,p)}
9o("forEach"),o("toJSON"),o("toArray"),o("slice"),o("map"),l("length","lengthUntracked"),c("length");const a=t.push;t.push=function(h){this._disableTracking=!0;const d=a.call(this,h);return this._disableTracking=!1,d};const u=t.slice;return t.slice=function(h,d){this._disableTracking=!0;const f=u.call(this,h,d);return this._disableTracking=!1,f},t}const Ro=new WeakSet;function pg(t){if(Ro.has(t))return t;Ro.add(t);let e;function n(){if(!e){let i=Array.from(t.share.keys());const o=c=>{const l=Array.from(t.share.keys());JSON.stringify(i)!==JSON.stringify(l)&&(i=l,e.reportChanged())};e=Ze("map",()=>{t.on("beforeObserverCalls",o)},()=>{t.off("beforeObserverCalls",o)})}e.reportObserved(t._implicitObserver)}const s=t.get;t.get=function(i){if(typeof i!="string")throw new Error("unexpected");const o=Reflect.apply(s,this,arguments);return Ms(o),o};function r(i){const o=t[i];let c;t[i]=function(){let l,a=arguments;return n(),c&&c.removeObservers(),c=hg(()=>(l=Reflect.apply(o,t,a),l),()=>e.reportChanged()),l}}return r("toJSON"),Object.defineProperty(t,"keys",{get:()=>(n(),Object.keys(t.share))}),t}const No=new WeakSet;function gg(t){if(No.has(t))return t;No.add(t);let e;const n=new Map;function s(){if(!e){const c=l=>{(l.changes.added.size||l.changes.deleted.size||l.changes.keys.size||l.changes.delta.length)&&e.reportChanged()};e=Ze("map",()=>{t.observe(c)},()=>{t.unobserve(c)})}e.reportObserved(t._implicitObserver)}function r(c){let l=n.get(c);if(!l){const a=u=>{u.keysChanged.has(c)&&(u.changes.added.size||u.changes.deleted.size||u.changes.keys.size||u.changes.delta.length)&&l.reportChanged()};l=Ze(c,()=>{t.observe(a)},()=>{t.unobserve(a)}),n.set(c,l)}l.reportObserved(t._implicitObserver)}const i=t.get;t.get=function(c){if(typeof c!="string")throw new Error("unexpected");return r(c),Reflect.apply(i,this,arguments)};function o(c){const l=t[c];t[c]=function(){return s(),Reflect.apply(l,this,arguments)}}return o("values"),o("entries"),o("keys"),o("forEach"),o("toJSON"),t}const Uo=new WeakSet;function jo(t){if(Uo.has(t))return t;Uo.add(t);let e;const n=r=>{e.reportChanged()};e=Ze("text",()=>{t.observe(n)},()=>{t.unobserve(n)});function s(r){const i=t[r];t[r]=function(){return e.reportObserved(this._implicitObserver),Reflect.apply(i,this,arguments)}}return s("toString"),s("toJSON"),t}const Ho=new WeakSet;function Fo(t){if(Ho.has(t))return t;Ho.add(t);let e;const n=i=>{(i.changes.added.size||i.changes.deleted.size||i.changes.keys.size||i.changes.delta.length)&&e.reportChanged()};e=Ze("xml",()=>{t.observe(n)},()=>{t.unobserve(n)});function s(i){const o=t[i];t[i]=function(){return e.reportObserved(this._implicitObserver),Reflect.apply(o,this,arguments)}}function r(i){let o=t,c=Object.getOwnPropertyDescriptor(o,i);if(c||(o=Object.getPrototypeOf(o),c=Object.getOwnPropertyDescriptor(o,i)),c||(o=Object.getPrototypeOf(o),c=Object.getOwnPropertyDescriptor(o,i)),!c)throw new Error("property not found");const l=c.get;c.get=function(){return e.reportObserved(this._implicitObserver),Reflect.apply(l,this,arguments)},Object.defineProperty(t,i,c)}return s("toString"),s("toDOM"),s("toArray"),s("getAttribute"),r("firstChild"),t}function Ms(t){return t instanceof Xe||t instanceof Ae?jo(t):t instanceof ge?fg(t):t instanceof me?gg(t):t instanceof Le||Object.prototype.hasOwnProperty.call(t,"autoLoad")?pg(t):t instanceof we||t instanceof Ce?Fo(t):t}function Bo(t){t.share.forEach(e=>{e.constructor!==k&&Ms(e)})}function Vo(t,e){for(let s=t.length-1;s>=e;s--){let r=t[s];if(!r.deleted){var n;if(r instanceof Z)continue;(n=r.content)==null||n.getContent().forEach(i=>{i instanceof k&&Ms(i)})}}}const Wo=new WeakSet;function yg(t){Wo.has(t)||(Wo.add(t),Ms(t),t.store.clients.forEach(e=>{e&&Vo(e,0)}),Bo(t),t.on("beforeObserverCalls",e=>{Bo(t),e.afterState.forEach((n,s)=>{const r=e.beforeState.get(s)||0;if(r!==n){const i=e.doc.store.clients.get(s);if(!i)return;const o=de(i,r);Vo(i,o)}})}))}class en{constructor(e){this.value=void 0,this.value=e}}function mg(t){return ArrayBuffer.isView(t)?new en(t):new en(Object.freeze(t))}function wg(t){const e=function(){var c;let l=(c=this[oe])==null?void 0:c.implicitObserver;
9return t._implicitObserver=l,t.slice.bind(t).apply(t,arguments).map(u=>{const h=$s(u,l);return l&&typeof h=="object"?Zt(h,l):h})},n=function(c){return c.map(l=>{const a=Di(l);let u=J(a)||a;if(u instanceof en&&(u=u.value),u instanceof k&&u.parent)throw new Error("Not supported: reassigning object that already occurs in the tree.");return u})},s=function(){return[].findIndex.apply(e.apply(this),arguments)},r={slice:e,unshift:(...o)=>(t.unshift(n(o)),t.lengthUntracked),push:(...o)=>(t.push(n(o)),t.lengthUntracked),insert:t.insert.bind(t),toJSON:t.toJSON.bind(t),forEach:function(){return[].forEach.apply(e.apply(this),arguments)},every:function(){return[].every.apply(e.apply(this),arguments)},filter:function(){return[].filter.apply(e.apply(this),arguments)},find:function(){return[].find.apply(e.apply(this),arguments)},findIndex:s,some:function(){return[].some.apply(e.apply(this),arguments)},includes:function(){return[].includes.apply(e.apply(this),arguments)},map:function(){return[].map.apply(e.apply(this),arguments)},indexOf:function(){const o=arguments[0];return s.call(this,c=>vg(c,o))},splice:function(){let o=arguments[0]<0?t.length-Math.abs(arguments[0]):arguments[0],c=arguments[1],l=Array.from(Array.from(arguments).slice(2)),a=e.apply(this,[o,Number.isInteger(c)?o+c:void 0]);return t.doc?t.doc.transact(()=>{t.delete(o,c),t.insert(o,n(l))}):(t.delete(o,c),t.insert(o,n(l))),a}},i=[];for(let o in r)i[o]=r[o];return i}function Pt(t){if(typeof t=="string"&&t.trim().length){const e=Number(t);if(Number.isInteger(e))return e}return t}function zo(t,e=new ge){if(e[T])throw new Error("unexpected");const n=wg(e),s=new Proxy(n,{set:(r,i,o)=>{throw typeof Pt(i)!="number"?new Error:new Error("array assignment is not implemented / supported")},get:(r,i,o)=>{const c=Pt(i);if(c===Rs)return e;if(typeof c=="number"){let u;if(o&&o[oe]){var l;u=(l=o[oe])==null?void 0:l.implicitObserver,e._implicitObserver=u}let h=e.get(c);return h=$s(h,u),h}if(c===Symbol.toStringTag)return"Array";if(c===Symbol.iterator){const u=e.slice();return Reflect.get(u,c)}return c==="length"?e.length:Reflect.get(r,c,o)},deleteProperty:(r,i)=>{const o=Pt(i);if(typeof o!="number")throw new Error;return o<e.lengthUntracked&&o>=0?(e.delete(o),!0):!1},has:(r,i)=>{const o=Pt(i);return typeof o!="number"?Reflect.has(r,o):o<e.lengthUntracked&&o>=0},getOwnPropertyDescriptor(r,i){const o=Pt(i);if(o==="length")return{enumerable:!1,configurable:!1,writable:!0};if(typeof o=="number"&&o>=0&&o<e.lengthUntracked)return{enumerable:!0,configurable:!0,writable:!0}},ownKeys:r=>{const i=[];for(let o=0;o<e.length;o++)i.push(o+"");return i.push("length"),i}});return n.push.apply(s,t),s}function Ko(t,e=new me){if(e[T])throw new Error("unexpected");const n=new Proxy({},{set:(s,r,i)=>{if(typeof r!="string")throw new Error;const o=Di(i);let c=J(o)||o;if(c instanceof en&&(c=c.value),c instanceof k&&c.parent)throw new Error("Not supported: reassigning object that already occurs in the tree.");return e.set(r,c),!0},get:(s,r,i)=>{if(r===Rs)return e;if(typeof r!="string")return Reflect.get(s,r);let o;if(i&&i[oe]){var c;o=(c=i[oe])==null?void 0:c.implicitObserver,e._implicitObserver=o}let l=e.get(r);return l=$s(l,o),l},deleteProperty:(s,r)=>{if(typeof r!="string")throw new Error;return e.has(r)?(e.delete(r),!0):!1},has:(s,r)=>!!(typeof r=="string"&&e.has(r)),getOwnPropertyDescriptor(s,r){if(typeof r=="string"&&e.has(r))return{enumerable:!0,configurable:!0}},ownKeys:s=>Array.from(e.keys())});jt.set(e,n);for(let s in t)n[s]=t[s];return n}function bg(t){return t instanceof k}const jt=new WeakMap;function $s(t,e){if(bg(t)){if(t._implicitObserver=e,t instanceof ge||t instanceof me){if(!jt.has(t)){const n=Di(t);jt.set(t,n)}t=jt.get(t)}else if(t instanceof Ce||t instanceof we||t instanceof Xe||t instanceof Et||t instanceof Ae)ki(t),t.__v_skip=!0;else throw new Error("unknown YType");return t}else{if(t===null)return null;if(typeof t=="object")return mg(t)}return t}function Di(t){if(t==null)return t;if(t=J(t)||t,t instanceof ge)return zo([],t);if(t instanceof me)return Ko({},t);if(typeof t=="string")return t;if(Array.isArray(t))return zo(t);if(t instanceof Ce||t instanceof we||t instanceof Xe||t instanceof Et)return t;if(t instanceof Ae)return t;if(typeof t=="object")return t instanceof en?t:Ko(t);if(typeof t=="number"||typeof t=="boolean")return t;throw new Error("invalid")}function _g(t){for(let[e,n]of Object.entries(t))if(Array.isArray(n)){if(n.length!==0)throw new Error("Root Array initializer must always be empty array")}else if(n&&typeof n=="object"){if(Object.keys(n).length!==0||Object.getPrototypeOf(n)!==Object.prototype)throw new Error("Root Object initializer must always be {}")}else if(n!=="xml"&&n!=="text")throw new Error("unknown Root initializer")}function Yo(t,e,n){let s=e[n];
9if(!s){n!=="__v_raw"&&n!=="__v_isRef"&&n!=="__v_isReadonly"&&console.warn("property not found on root doc",n);return}return s==="xml"?t.getXmlFragment(n):s==="text"?t.getText(n):Array.isArray(s)?t.getArray(n):t.getMap(n)}function Eg(t,e){if(t[T])throw new Error("unexpected");_g(e);const n=new Proxy({},{set:(s,r,i)=>{throw typeof r!="string"?new Error:new Error("cannot set new elements on root doc")},get:(s,r,i)=>{if(r===Rs)return t;if(typeof r!="string")return Reflect.get(s,r);let o;if(i&&i[oe]){var c;o=(c=i[oe])==null?void 0:c.implicitObserver,t._implicitObserver=o}if(r==="toJSON"){for(let u of Object.keys(e))Yo(t,e,u);return Reflect.get(t,r)}let l=Yo(t,e,r);return l=$s(l,o),l},deleteProperty:(s,r)=>{throw new Error("deleteProperty not available for doc")},has:(s,r)=>!!(typeof r=="string"&&t.share.has(r)),getOwnPropertyDescriptor(s,r){if(typeof r=="string"&&t.share.has(r)||r==="toJSON")return{enumerable:!0,configurable:!0}},ownKeys:s=>Array.from(t.share.keys())});return jt.set(t,n),n}dg(ag);const Rs=Symbol("INTERNAL_SYMBOL");function ya(t){const e=J(t);if(!(e instanceof Le))throw new Error("store is not a valid syncedStore that maps to a Y.Doc");return e}function J(t){if(typeof t!="object"||t===null)return;const e=t[Rs];return e&&(ki(e),e.__v_skip=!0),e}function vg(t,e){if(t===e)return!0;if(typeof t=="object"&&typeof e=="object"){const n=J(t),s=J(e);return!n||!s?!1:n===s}return!1}function ma(t,e=new Le){return yg(e),Eg(e,t)}/**
10 * @license
11 * Copyright 2017 Google LLC
12 * SPDX-License-Identifier: BSD-3-Clause
13 */const Li=globalThis,Jo=t=>t,os=Li.trustedTypes,qo=os?os.createPolicy("lit-html",{createHTML:t=>t}):void 0,wa="$lit$",Te=`lit$${Math.random().toFixed(9).slice(2)}$`,ba="?"+Te,Sg=`<${ba}>`,et=document,tn=()=>et.createComment(""),nn=t=>t===null||typeof t!="object"&&typeof t!="function",Oi=Array.isArray,Ag=t=>Oi(t)||typeof t?.[Symbol.iterator]=="function",sr=`[ 	
14\f\r]`,Tt=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Go=/-->
14/g,Xo=/>/g,He=RegExp(`>|${sr}(?:([^\\s"'>=/]+)(${sr}*=${sr}*(?:[^ 	
15\f\r"'\`<>=]|("|')|))|$)`,"g"),Qo=/'/g,Zo=/"/g,_a=/^(?:script|style|textarea|title)$/i,sn=Symbol.for("lit-noChange"),$=Symbol.for("lit-nothing"),ec=new WeakMap,We=et.createTreeWalker(et,129);function Ea(t,e){if(!Oi(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return qo!==void 0?qo.createHTML(e):e}const Cg=(t,e)=>{const n=t.length-1,s=[];let r,i=e===2?"<svg>":e===3?"<math>":"",o=Tt;for(let c=0;c<n;c++){const l=t[c];let a,u,h=-1,d=0;for(;d<l.length&&(o.lastIndex=d,u=o.exec(l),u!==null);)d=o.lastIndex,o===Tt?u[1]==="!--"?o=Go:u[1]!==void 0?o=Xo:u[2]!==void 0?(_a.test(u[2])&&(r=RegExp("</"+u[2],"g")),o=He):u[3]!==void 0&&(o=He):o===He?u[0]===">"?(o=r??Tt,h=-1):u[1]===void 0?h=-2:(h=o.lastIndex-u[2].length,a=u[1],o=u[3]===void 0?He:u[3]==='"'?Zo:Qo):o===Zo||o===Qo?o=He:o===Go||o===Xo?o=Tt:(o=He,r=void 0);const f=o===He&&t[c+1].startsWith("/>")?" ":"";i+=o===Tt?l+Sg:h>=0?(s.push(a),l.slice(0,h)+wa+l.slice(h)+Te+f):l+Te+(h===-2?c:f)}return[Ea(t,i+(t[n]||"<?>")+(e===2?"</svg>":e===3?"</math>":"")),s]};class rn{constructor({strings:e,_$litType$:n},s){let r;this.parts=[];let i=0,o=0;const c=e.length-1,l=this.parts,[a,u]=Cg(e,n);if(this.el=rn.createElement(a,s),We.currentNode=this.el.content,n===2||n===3){const h=this.el.content.firstChild;h.replaceWith(...h.childNodes)}for(;(r=We.nextNode())!==null&&l.length<c;){if(r.nodeType===1){if(r.hasAttributes())for(const h of r.getAttributeNames())if(h.endsWith(wa)){const d=u[o++],f=r.getAttribute(h).split(Te),p=/([.?@])?(.*)/.exec(d);l.push({type:1,index:i,name:p[2],strings:f,ctor:p[1]==="."?Dg:p[1]==="?"?Lg:p[1]==="@"?Og:Ns}),r.removeAttribute(h)}else h.startsWith(Te)&&(l.push({type:6,index:i}),r.removeAttribute(h));if(_a.test(r.tagName)){const h=r.textContent.split(Te),d=h.length-1;if(d>0){r.textContent=os?os.emptyScript:"";for(let f=0;f<d;f++)r.append(h[f],tn()),We.nextNode(),l.push({type:2,index:++i});r.append(h[d],tn())}}}else if(r.nodeType===8)if(r.data===ba)l.push({type:2,index:i});else{let h=-1;for(;(h=r.data.indexOf(Te,h+1))!==-1;)l.push({type:7,index:i}),h+=Te.length-1}i++}}static createElement(e,n){const s=et.createElement("template");return s.innerHTML=e,s}}function vt(t,e,n=t,s){if(e===sn)return e;let r=s!==void 0?n._$Co?.[s]:n._$Cl;const i=nn(e)?void 0:e._$litDirective$;return r?.constructor!==i&&(r?._$AO?.(!1),i===void 0?r=void 0:(r=new i(t),r._$AT(t,n,s)),s!==void 0?(n._$Co??=[])[s]=r:n._$Cl=r),r!==void 0&&(e=vt(t,r._$AS(t,e.values),r,s)),e}class kg{constructor(e,n){this._$AV=[],this._$AN=void 0,this._$AD=e,this._$AM=n}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(e){const{el:{content:n},parts:s}=this._$AD,r=(e?.creationScope??et).importNode(n,!0);We.currentNode=r;let i=We.nextNode(),o=0,c=0,l=s[0];for(;l!==void 0;){if(o===l.index){let a;l.type===2?a=new _n(i,i.nextSibling,this,e):l.type===1?a=new l.ctor(i,l.name,l.strings,this,e):l.type===6&&(a=new Ig(i,this,e)),this._$AV.push(a),l=s[++c]}o!==l?.index&&(i=We.nextNode(),o++)}return We.currentNode=et,r}p(e){let n=0;for(const s of this._$AV)s!==void 0&&(s.strings!==void 0?(s._$AI(e,s,n),n+=s.strings.length-2):s._$AI(e[n])),n++}}class _n{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(e,n,s,r){this.type=2,this._$AH=$,this._$AN=void 0,this._$AA=e,this._$AB=n,this._$AM=s,this.options=r,this._$Cv=r?.isConnected??!0}get parentNode(){let e=this._$AA.parentNode;const n=this._$AM;return n!==void 0&&e?.nodeType===11&&(e=n.parentNode),e}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(e,n=this){e=vt(this,e,n),nn(e)?e===$||e==null||e===""?(this._$AH!==$&&this._$AR(),this._$AH=$):e!==this._$AH&&e!==sn&&this._(e):e._$litType$!==void 0?this.$(e):e.nodeType!==void 0?this.T(e):Ag(e)?this.k(e):this._(e)}O(e){return this._$AA.parentNode.insertBefore(e,this._$AB)}T(e){this._$AH!==e&&(this._$AR(),this._$AH=this.O(e))}_(e){this._$AH!==$&&nn(this._$AH)?this._$AA.nextSibling.data=e:this.T(et.createTextNode(e)),this._$AH=e}$(e){const{values:n,_$litType$:s}=e,r=typeof s=="number"?this._$AC(e):(s.el===void 0&&(s.el=rn.createElement(Ea(s.h,s.h[0]),this.options)),s);if(this._$AH?._$AD===r)this._$AH.p(n);else{const i=new kg(r,this),o=i.u(this.options);i.p(n),this.T(o),this._$AH=i}}_$AC(e){let n=ec.get(e.strings);return n===void 0&&ec.set(e.strings,n=new rn(e)),n}k(e){Oi(this._$AH)||(this._$AH=[],this._$AR());const n=this._$AH;let s,r=0;for(const i of e)r===n.length?n.push(s=new _n(this.O(tn()),this.O(tn()),this,this.options)):s=n[r],s._$AI(i),r++;r<n.length&&(this._$AR(s&&s._$AB.nextSibling,r),n.length=r)}_$AR(e=this._$AA.nextSibling,n){for(this._$AP?.(!1,!0,n);e!==this._$AB;){const s=Jo(e).nextSibling;Jo(e).remove(),e=s}}setConnected(e){this._$AM===void 0&&(this._$Cv=e,this._$AP?.(e))}}class Ns{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(e,n,s,r,i){this.type=1,this._$AH=$,this._$AN=void 0,this.element=e,this.name=n,this._$AM=r,this.options=i,s.length>2||s[0]!==""||s[1]!==""?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=$}_$AI(e,n=this,s,r){const i=this.strings;let o=!1;if(i===void 0)e=vt(this,e,n,0),o=!nn(e)||e!==this._$AH&&e!==sn,o&&(this._$AH=e);else{const c=e;let l,a;for(e=i[0],l=0;l<i.length-1;l++)a=vt(this,c[s+l],n,l),a===sn&&(a=this._$AH[l]),o||=!nn(a)||a!==this._$AH[l],a===$?e=$:e!==$&&(e+=(a??"")+i[l+1]),this._$AH[l]=a}o&&!r&&this.j(e)}j(e){e===$?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,e??"")}}class Dg extends Ns{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===$?void 0:e}}class Lg extends Ns{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==$)}}class Og extends Ns{constructor(e,n,s,r,i){super(e,n,s,r,i),this.type=5}_$AI(e,n=this){if((e=vt(this,e,n,0)??$)===sn)return;const s=this._$AH,r=e===$&&s!==$||e.capture!==s.capture||e.once!==s.once||e.passive!==s.passive,i=e!==$&&(s===$||r);r&&this.element.removeEventListener(this.name,this,s),i&&this.element.addEventListener(this.name,this,e),this._$AH=e}handleEvent(e){typeof this._$AH=="function"?this._$AH.call(this.options?.host??this.element,e):this._$AH.handleEvent(e)}}class Ig{constructor(e,n,s){this.element=e,this.type=6,this._$AN=void 0,this._$AM=n,this.options=s}get _$AU(){return this._$AM._$AU}_$AI(e){vt(this,e)}}const Pg=Li.litHtmlPolyfillSupport;Pg?.(rn,_n),(Li.litHtmlVersions??=[]).push("3.3.3");const Tg=(t,e,n)=>{const s=e;let r=s._$litPart$;return r===void 0&&(s._$litPart$=r=new _n(e.insertBefore(tn(),null),null,void 0,{})),r._$AI(t),r},tc=(t,e=300)=>{let n;return function(...s){clearTimeout(n),n=setTimeout(()=>t.apply(this,s),e)}};class xg{defaultData;localData;awareness=[];awarenessByStableId=new Map;selfAwareness;element;_data;onChange;onAwarenessChange;debouncedOnChange;resetShortcut;update;view;updateElementAwareness;triggerAwarenessUpdate;devMode;isRendering=!1;onUnmount;onAfterRender;descendantObserver;dataUpdateListeners=new Set;scheduleSetupDataWrite;getUsers;clickListener;touchStartListener;mouseDownListener;resetShortcutListener;activeDragCleanup;onClick;onDrag;onDragStart;constructor(e,n={}){const{element:s,onChange:r,onAwarenessChange:i,defaultData:o,defaultLocalData:c,live:l,myDefaultAwareness:a,data:u,awareness:h,update:d,updateElement:f,view:p,updateElementAwareness:y,onMount:g,debounceMs:b,triggerAwarenessUpdate:S,devMode:j}=e;this.scheduleSetupDataWrite=n.scheduleSetupDataWrite,this.getUsers=n.getUsers??(()=>[]),this.element=s,this.view=p,this.devMode=j,this.defaultData=o instanceof Function?o(s):o,this.localData=c instanceof Function?c(s):c,this.triggerAwarenessUpdate=S,this.onChange=r,this.debouncedOnChange=tc(this.onChange,b),this.onAwarenessChange=i,this.update=d??f,this.updateElementAwareness=y;const B=u===void 0?this.defaultData:u;h!==void 0&&(this.awareness=h);const O=l!==void 0?l:a,Q=O instanceof Function?O(s):O;if(Q!==void 0&&this.setLive(Q),this._data=B,this.__data=B,this.reinitializeElementData(e),g){const An=g(this.getSetupData());typeof An=="function"&&(this.onUnmount=An)}}destroy(){this.descendantObserver?.disconnect(),this.descendantObserver=void 0,this.clickListener&&(this.element.removeEventListener("click",this.clickListener),this.clickListener=void 0),this.touchStartListener&&(this.element.removeEventListener("touchstart",this.touchStartListener),this.touchStartListener=void 0),this.mouseDownListener&&(this.element.removeEventListener("mousedown",this.mouseDownListener),this.mouseDownListener=void 0),this.resetShortcutListener&&(this.element.removeEventListener("click",this.resetShortcutListener),this.resetShortcutListener=void 0),this.removeActiveDragListeners(),this.onClick=void 0,this.onDrag=void 0,this.onDragStart=void 0,this.resetShortcut=void 0;const e=this.onUnmount;if(this.onUnmount=void 0,e)try{e()}catch(n){console.error(`[playhtml] onMount cleanup for "${this.element.i
15d}" threw`,n)}}reinitializeElementData({element:e,onChange:n,onAwarenessChange:s,update:r,updateElement:i,view:o,updateElementAwareness:c,onClick:l,onDrag:a,onDragStart:u,resetShortcut:h,debounceMs:d,triggerAwarenessUpdate:f,devMode:p}){this.triggerAwarenessUpdate=f,this.onChange=n,this.debouncedOnChange=tc(this.onChange,d),this.onAwarenessChange=s,this.update=r??i,this.view=o,this.devMode=p,o&&this.update&&(console.error(`[playhtml] "${e.id}" provides both \`view\` and an imperative update renderer. They are mutually exclusive. \`view\` is used and the imperative renderer is ignored.`),this.update=void 0),o&&(l||a||u)&&(console.error(`[playhtml] "${e.id}" provides a \`view\` alongside onClick/onDrag/onDragStart. In view mode these are ignored — attach events inside the template (e.g. @click). `),l=void 0,a=void 0,u=void 0),this.setEventHandlers({onClick:l,onDrag:a,onDragStart:u}),h&&!this.resetShortcutListener&&(e.reset=this.reset,this.resetShortcutListener=y=>{switch(this.resetShortcut){case"ctrlKey":if(!y.ctrlKey)return;break;case"altKey":if(!y.altKey)return;break;case"shiftKey":if(!y.shiftKey)return;break;case"metaKey":if(!y.metaKey)return;break;default:return}this.reset(),y.preventDefault(),y.stopPropagation()},e.addEventListener("click",this.resetShortcutListener)),this.resetShortcut=h}setEventHandlers({onClick:e,onDrag:n,onDragStart:s}){const r=this.element,i=!!(this.onDrag||this.onDragStart);if(this.view){i&&this.removeActiveDragListeners(),this.onClick=void 0,this.onDrag=void 0,this.onDragStart=void 0;return}const o=!!(n||s);i&&!o&&this.removeActiveDragListeners(),e&&!this.clickListener&&(this.clickListener=c=>{this.onClick?.(c,this.getEventHandlerData())},r.addEventListener("click",this.clickListener)),o&&!this.touchStartListener&&(this.touchStartListener=c=>{if(!this.onDrag&&!this.onDragStart)return;c.preventDefault(),this.removeActiveDragListeners(),r.classList.add("cursordown"),this.onDragStart?.(c,this.getEventHandlerData());const l=u=>{u.preventDefault(),this.onDrag?.(u,this.getEventHandlerData())},a=()=>{r.classList.remove("cursordown"),document.removeEventListener("touchmove",l),document.removeEventListener("touchend",a),this.activeDragCleanup===a&&(this.activeDragCleanup=void 0)};this.activeDragCleanup=a,document.addEventListener("touchmove",l),document.addEventListener("touchend",a)},r.addEventListener("touchstart",this.touchStartListener)),o&&!this.mouseDownListener&&(this.mouseDownListener=c=>{if(!this.onDrag&&!this.onDragStart)return;c.preventDefault(),this.removeActiveDragListeners(),this.onDragStart?.(c,this.getEventHandlerData()),r.classList.add("cursordown");const l=u=>{u.preventDefault(),this.onDrag?.(u,this.getEventHandlerData())},a=()=>{r.classList.remove("cursordown"),document.removeEventListener("mousemove",l),document.removeEventListener("mouseup",a),this.activeDragCleanup===a&&(this.activeDragCleanup=void 0)};this.activeDragCleanup=a,document.addEventListener("mousemove",l),document.addEventListener("mouseup",a)},r.addEventListener("mousedown",this.mouseDownListener)),this.onClick=e,this.onDrag=n,this.onDragStart=s}removeActiveDragListeners(){this.activeDragCleanup?.(),this.activeDragCleanup=void 0,this.element.classList.remove("cursordown")}get data(){return this._data}onDataUpdate(e){return this.dataUpdateListeners.add(e),()=>{this.dataUpdateListeners.delete(e)}}setLocalData(e){this.rejectWriteDuringRender("setLocalData")||(typeof e=="function"?e(this.localData):this.localData=e,this.view&&this.render())}set __data(e){this._data=e,this.render();for(const n of this.dataUpdateListeners)n()}render(){if(this.view){this.isRendering=!0;try{Tg(this.view(this.getEventHandlerData()),this.element)}finally{this.isRendering=!1}return}this.update?.(this.getEventHandlerData())}observeDescendants(){!this.onAfterRender||this.descendantObserver||(this.onAfterRender(this.element),typeof MutationObserver<"u"&&(this.descendantObserver=wi(this.element,()=>{this.onAfterRender?.(this.element)},{childList:!0,subtree:!0})))}requestUpdate(){!this.view||this.isRendering||this.render()}rejectWriteDuringRender(e){return this.isRendering?(console.error(`[playhtml] ${e}
15() was called during a view render for "${this.element.id}". Views must be pure — drive writes from @event handlers (e.g. @click) instead. Ignoring this write.`),!0):!1}updateAwareness(e,n){this.awareness=e,this.awarenessByStableId=n;try{this.updateElementAwareness?.(this.getAwarenessEventHandlerData())}catch(s){console.error("[playhtml] updateElementAwareness callback threw:",s)}this.render()}getEventHandlerData(){return{element:this.element,data:this.data,localData:this.localData,live:this.selfAwareness,users:this.getUsers(this.awarenessByStableId,this.selfAwareness),awareness:this.awareness,awarenessByStableId:this.awarenessByStableId,myAwareness:this.selfAwareness,setData:e=>this.setData(e),setLocalData:e=>this.setLocalData(e),setLive:e=>this.setLive(e),setMyAwareness:e=>this.setLive(e),requestUpdate:()=>this.requestUpdate()}}getAwarenessEventHandlerData(){return{...this.getEventHandlerData()}}getSetupData(){return{getElement:()=>this.element,getData:()=>this.data,getLocalData:()=>this.localData,getLive:()=>this.selfAwareness,getUsers:()=>this.getUsers(this.awarenessByStableId,this.selfAwareness),getAwareness:()=>this.awareness,setData:e=>this.setSetupData(e),setLocalData:e=>this.setLocalData(e),setLive:e=>this.setLive(e),setMyAwareness:e=>this.setLive(e),requestUpdate:()=>this.requestUpdate()}}setSetupData(e){if(!this.scheduleSetupDataWrite){this.setData(e);return}this.rejectWriteDuringRender("setData")||this.scheduleSetupDataWrite(()=>{this.onChange(e)})}setData(e){this.rejectWriteDuringRender("setData")||this.onChange(e)}setLive(e){this.rejectWriteDuringRender("setLive")||e!==this.selfAwareness&&(this.selfAwareness=e,this.onAwarenessChange(e),this.triggerAwarenessUpdate?.())}setMyAwareness(e){this.setLive(e)}setDataDebounced(e){this.debouncedOnChange(e)}reset(){this.defaultData!==void 0&&this.setData(this.defaultData)}}async function Mg(t,e){const n=new TextEncoder().encode(`${t}-${e.outerHTML}}`),s=await crypto.subtle.digest("SHA-1",n);return Array.from(new Uint8Array(s)).map(o=>o.toString(16).padStart(2,"0")).join("")}function on(){const t=window.location.pathname;return t.length<=Si?t:void 0}function Ii(t){const e=t.playerStyle?.colorPalette?.[0];if(e==null||e==="")throw new Error("[playhtml] Player identity must have playerStyle.colorPalette[0] (primary color).");return e}function nc(t){if(!t.publicKey)throw new Error("[playhtml] Player identity must have publicKey.");Ii(t)}function Tn(t,e){return{pid:t.publicKey,name:t.name,color:Ii(t),isMe:e}}function $g(t,e){let n=t;nc(n);const s=new Set,r=new Set;let i=null,o=null,c=null;function l(g,b,S){for(const j of g)try{j(b)}catch(B){console.error(`[playhtml] ${S} subscriber threw:`,B)}}function a(){l(s,n,"users self-change")}function u(g,b){return g.length===b.length&&g.every((S,j)=>S.pid===b[j].pid&&S.name===b[j].name&&S.color===b[j].color&&S.isMe===b[j].isMe)}function h(g=!1){if(r.size===0)return;const b=f();!g&&c&&u(c,b)||(c=b,l(r,b,"users change"))}function d(){if(i??=e.onIdentityPeersChange(h),!o&&e.onCursorPresencesChange){const g=e.onCursorPresencesChange(()=>{h()});g&&(o=g)}}function f(){const g=new Map,b=n.publicKey,S=e.getIdentityPeers();for(const B of Array.from(S.keys()).sort()){const Q=S.get(B).identity;if(!(!Q||Q.publicKey===b))try{g.set(Q.publicKey,Tn(Q,!1))}catch{}}g.set(b,Tn(n,!0));const j=e.getCursorPresences?.();if(j)for(const[B,O]of j){if(!O.playerIdentity)continue;const Q=B===b;try{g.set(B,Q?Tn(n,!0):Tn(O.playerIdentity,!1))}catch{}}return Array.from(g.values())}function p(g){g(),Sr(n),a(),h(!0)}return{me:{get pid(){return n.publicKey},get name(){return n.name},set name(g){n.name!==g&&p(()=>{n.name=g})},get color(){return Ii(n)},set color(g){if(g==null||g==="")throw new Error("[playhtml] users.me.color cannot be set to empty; player identity must have a primary color.");n.playerStyle.colorPalette[0]!==g&&p(()=>{n.playerStyle.colorPalette[0]=g})}},getAll(){return d(),f()},onChange(g){d(),h(),r.add(g);const b=f();return c=b,g(b),()=>{r.delete(g)}},onSelfChange(g){return s.add(g),()=>{s.delete(g)}},adoptIdentity(g){nc(g),n!==g&&p(()=>{n=g})},getIdentity(){return n},destroy(){s.clear(),r.clear(),o?.(),o=null,i?.(),i=null}}}function Rg(){return Pp()}function xm(t){return Array.from(new Set(t.map(e=>e.color)))}const va=new Map;function Sa(t,e){va.set(t,e)}function Ng(){const t=[];
15return document.querySelectorAll("[shared]").forEach(e=>{if(!e.id)return;let n="read-write";const s=e.getAttribute("shared");if(s&&s!==""){const r=s.toLowerCase();(r.includes("read-only")||r==="ro")&&(n="read-only")}t.push({elementId:e.id,permissions:n,path:window.location.pathname})}),t}function Ug(){const t=[];return document.querySelectorAll("[data-source]").forEach(e=>{const n=e.getAttribute("data-source");if(n)try{const{domain:s,path:r,elementId:i}=na(n);t.push({domain:s,path:r,elementId:i})}catch{}}),t}function jg(t,e){if(t.hasAttribute("data-source")&&t.hasAttribute("data-source-read-only"))return!0;const r=e??It(t);return r?va.get(r)==="read-only":!1}const v="__page__";function Aa(t){return`${v}:${t}`}function sc(t,e){if(typeof t!="function")return t;if(e!==null&&typeof e=="object"){const n=t(e);return n===null?n:e}return t(e)}function Pi(t,e,n){const s=e.getStorePlay()[v]?.[t];if(s===void 0)return;const r=ke(s);for(const i of n)i(r)}function cs(t,e){const n=Aa(t),s=Hg(e,n);s&&(s.mode==="deep"&&s.target?.unobserveDeep(s),s.mode==="shallow"&&s.target?.unobserve(s),s.parentTarget?.unobserve(s.parentObserver),e.yObserverByKey.delete(n))}function Hg(t,e){return t.yObserverByKey.get(e)}function cn(t,e,n){const{getStorePlay:s,yObserverByKey:r}=e,i=Aa(t);if(r.has(i))return;const o=s()[v]?.[t],c=J(o);let l=!1;const a=()=>{l||(l=!0,queueMicrotask(()=>{l=!1,Pi(t,e,n)}))};if(c&&typeof c.observeDeep=="function"){const d=a,f=J(s()[v]),p=(y=>{y.keysChanged?.has(t)&&(a(),cs(t,e),cn(t,e,n))});d.target=c,d.mode="deep",d.parentTarget=f,d.parentObserver=p,c.observeDeep(d),f.observe(p),r.set(i,d);return}const u=J(s()[v]);if(!u||typeof u.observe!="function")return;const h=(d=>{if(!d.keysChanged?.has(t))return;a();const f=s()[v]?.[t],p=J(f);p&&typeof p.observeDeep=="function"&&(cs(t,e),cn(t,e,n))});h.target=u,h.mode="shallow",u.observe(h),r.set(i,h)}function Fg(t){for(const[e,n]of t.channelListeners)cs(e,t),t.proxyByTagAndId.get(v)?.delete(e),cn(e,t,n),Pi(e,t,n)}function Ca(t){const{channelListeners:e,getStorePlay:n}=t;for(const[s,r]of e)n()[v]?.[s]!==void 0&&(cn(s,t,r),Pi(s,t,r))}function Bg(t,e,n){const{ensureProxy:s,getDoc:r,getStorePlay:i,proxyByTagAndId:o,channelRefCounts:c,channelListeners:l}=n,a=()=>i(),u=()=>r();a()[v]??={},s(v,t,e),l.has(t)||l.set(t,new Set);const h=l.get(t),d=new Set;function f(){cn(t,n,h)}const p=(c.get(t)??0)+1;c.set(t,p),f();let y=!1;return{getData(){if(y)throw new Error(`PageDataChannel "${t}" has been destroyed`);const g=a()[v]?.[t];return ke(g===void 0?e:g)},setData(g){if(y)throw new Error(`PageDataChannel "${t}" has been destroyed`);let b=a()[v]?.[t];b===void 0?(b=s(v,t,e),f()):o.get(v)?.set(t,b);const S=b,j=S!==null&&typeof S=="object",B=j?S:a()[v]?.[t];let O=B;if(typeof g=="function"&&j){if(u().transact(()=>{O=sc(g,S)}),O===S)return}else O=sc(g,B);if(j&&O!==null&&typeof O=="object"&&Array.isArray(S)===Array.isArray(O)){u().transact(()=>{Xt(S,O)});return}u().transact(()=>{a()[v]??={},a()[v][t]=ke(O),o.get(v)?.set(t,a()[v][t])})},onUpdate(g){if(y)throw new Error(`PageDataChannel "${t}" has been destroyed`);return h.add(g),d.add(g),()=>{h.delete(g),d.delete(g)}},destroy(){if(y)return;y=!0;for(const b of d)h.delete(b);d.clear();const g=(c.get(t)??1)-1;if(c.set(t,g),g<=0){c.delete(t),l.delete(t),cs(t,n);const b=o.get(v);b&&b.delete(t)}}}}const Vg="playhtml.syncedStore is read-only.",Wg=new Set(["copyWithin","fill","pop","push","reverse","shift","sort","splice","unshift"]);function it(){throw new Error(Vg)}function zg(t){return Array.isArray(t)?[]:{}}function rc(t,e){!Array.isArray(t)||!Array.isArray(e)||(e.length=t.length)}function ka(t){const e=new WeakMap;function n(s){if(s===null||typeof s!="object")return s;const r=e.get(s);if(r)return r;const i=s,o=zg(i),c=new Proxy(o,{get(l,a){return Array.isArray(i)&&Wg.has(a)?it:n(Reflect.get(i,a,i))},getOwnPropertyDescriptor(l,a){if(rc(i,o),Array.isArray(i)&&a==="length")return Reflect.getOwnPropertyDescriptor(o,a);const u=Reflect.getOwnPropertyDescriptor(i,a);return u&&("value"in u?{...u,configurable:!0,value:n(u.value),writable:!1}:{configurable:!0,enumerable:u.enumerable,value:n(Reflect.get(i,a,i)),writable:!1})},has(l,a){return a in i},ownKeys(){return rc(i,o),Reflect.ownKeys(i)},getPrototypeOf(){return Reflect.getPrototypeOf(i)},set:it,deleteProperty:it,defineProperty:it,setPrototypeOf:it,preventExtensions:it});return e.set(s,c),c}return n(t)}(!globalThis.EventTarget||!globalThis.Event)&&console.error(`
16  PartySocket requires a global 'EventTarget' class to be available!
17  You can polyfill this global by adding this to your code before any partysocket imports: 
18  
19  \`\`\`
20  import 'partysocket/event-target-polyfill';
21  \`\`\`
22  Please file an issue at https://github.com/partykit/partykit if you're still having trouble.
23`);
vendor: 9,243 bytes, lines 23-36
23var Da=class extends Event{message;error;constructor(t,e){super("error",e),this.message=t.message,this.error=t}},La=class extends Event{code;reason;wasClean=!0;constructor(t=1e3,e="",n){super("close",n),this.code=t,this.reason=e}};const rr={Event,ErrorEvent:Da,CloseEvent:La};function Kg(t,e){if(!t)throw new Error(e)}function Yg(t){return new t.constructor(t.type,t)}function Jg(t){return"data"in t?new MessageEvent(t.type,t):"code"in t||"reason"in t?new La(t.code||1999,t.reason||"unknown reason",t):"error"in t?new Da(t.error,t):new Event(t.type,t)}const qg=typeof process<"u"&&typeof process.versions?.node<"u",Gg=typeof navigator<"u"&&navigator.product==="ReactNative",xn=qg||Gg?Jg:Yg,Fe={maxReconnectionDelay:1e4,minReconnectionDelay:3e3,minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:Number.POSITIVE_INFINITY,maxEnqueuedMessages:Number.POSITIVE_INFINITY};let ic=!1;function Xg(){}var Qg=class Ie extends EventTarget{_ws;_retryCount=-1;_uptimeTimeout;_connectTimeout;_shouldReconnect=!0;_connectLock=!1;_binaryType="blob";_closeCalled=!1;_didWarnAboutClosedSend=!1;_messageQueue=[];_debugLogger=console.log.bind(console);_url;_protocols;_options;constructor(e,n,s={}){super(),this._url=e,this._protocols=n,this._options=s,this._options.startClosed&&(this._shouldReconnect=!1),this._options.debugLogger&&(this._debugLogger=this._options.debugLogger),this._connect()}static get CONNECTING(){return 0}static get OPEN(){return 1}static get CLOSING(){return 2}static get CLOSED(){return 3}get CONNECTING(){return Ie.CONNECTING}get OPEN(){return Ie.OPEN}get CLOSING(){return Ie.CLOSING}get CLOSED(){return Ie.CLOSED}get binaryType(){return this._ws?this._ws.binaryType:this._binaryType}set binaryType(e){this._binaryType=e,this._ws&&(this._ws.binaryType=e)}get retryCount(){return Math.max(this._retryCount,0)}get bufferedAmount(){return this._messageQueue.reduce((e,n)=>(typeof n=="string"?e+=n.length:n instanceof Blob?e+=n.size:e+=n.byteLength,e),0)+(this._ws?this._ws.bufferedAmount:0)}get extensions(){return this._ws?this._ws.extensions:""}get protocol(){return this._ws?this._ws.protocol:""}get readyState(){return this._closeCalled?Ie.CLOSED:this._ws?this._ws.readyState:this._options.startClosed?Ie.CLOSED:Ie.CONNECTING}get url(){return this._ws?this._ws.url:""}get shouldReconnect(){return this._shouldReconnect}onclose=null;onerror=null;onmessage=null;onopen=null;close(e=1e3,n){if(this._closeCalled=!0,this._shouldReconnect=!1,this._clearTimeouts(),!this._ws){this._debug("close enqueued: no ws instance");return}if(this._ws.readyState===this.CLOSED||this._ws.readyState===this.CLOSING){this._debug("close: already closing or closed");return}this._disconnect(e,n)}reconnect(e,n){this._shouldReconnect=!0,this._closeCalled=!1,this._didWarnAboutClosedSend=!1,this._retryCount=-1,!this._ws||this._ws.readyState===this.CLOSED||this._ws.readyState===this.CLOSING?this._connect():(this._disconnect(e,n),this._connect())}send(e){if(this._ws&&this._ws.readyState===this.OPEN)return this._debug("send",e),this._ws.send(e),!0;this._closeCalled&&!this._didWarnAboutClosedSend&&(this._didWarnAboutClosedSend=!0,console.warn("ReconnectingWebSocket: send() was called after close(). The message has been buffered, but it will only be delivered if reconnect() is called on this socket. If this socket has been discarded, the message is lost — this usually means a stale socket reference is being used."));const{maxEnqueuedMessages:n=Fe.maxEnqueuedMessages}=this._options;return this._messageQueue.length<n&&(this._debug("enqueue",e),this._messageQueue.push(e)),!1}drainQueuedMessages(){const e=this._messageQueue;return this._messageQueue=[],e}_debug(...e){this._options.debug&&this._debugLogger("RWS>",...e)}_getNextDelay(){const{reconnectionDelayGrowFactor:e=Fe.reconnectionDelayGrowFactor,minReconnectionDelay:n=Fe.minReconnectionDelay,maxReconnectionDelay:s=Fe.maxReconnectionDelay}=this._options;let r=0;return this._retryCount>0&&(r=n*e**(this._retryCount-1),r>s&&(r=s)),this._debug("next delay",r),r}_wait(){return new Promise(e=>{setTimeout(e,this._getNextDelay())})}_getNextProtocols(e){if(!e)return Promise.resolve(null);if(typeof e=="string"||Array.isArray(e))return Promise.resolve(e);if(typeof e=="function"){const n=e();if(!n)return Promise.resolve(null);if(typeof n=="string"||Array.isArray(n))return Promise.resolve(n);if(n.then)return n}throw Error("Invalid protocols")}_getNextUrl(e){if(typeof e=="string")return Promise.resolve(e);if(typeof e=="function"){const n=e();if(typeof n=="string")return Promise.resolve(n);if(n.then)return n}throw Error("Invalid URL")}_connect(){if(this._connectLock||!this._shouldReconnect)return;this._connectLock=!0;const{maxRetries:e=Fe.maxRetries,connectionTimeout:n=Fe.connectionTimeout}=this._options;if(this._retryCount>=e){this._debug("max retries reached",this._retryCount,">=",e),this._connectLock=!1;return}this._retryCount++,this._debug("connect",this._retryCount),this._removeListeners(),this._wait().then(()=>Promise.all([this._getNextUrl(this._url),this._getNextProtocols(this._protocols||null)])).then(([s,r])=>{if(this._closeCalled){this._connectLock=!1;return}!this._options.WebSocket&&typeof WebSocket>"u"&&!ic&&(console.error(`‼️ No WebSocket implementation available. You should define options.WebSocket. 
24
25For example, if you're using node.js, run \`npm install ws\`, and then in your code:
26
27import PartySocket from 'partysocket';
28import WS from 'ws';
29
30const partysocket = new PartySocket({
31  host: "127.0.0.1:1999",
32  room: "test-room",
33  WebSocket: WS
34});
35
36`),ic=!0);const i=this._options.WebSocket||WebSocket;this._debug("connect",{url:s,protocols:r}),this._ws=r?new i(s,r):new i(s),this._ws.binaryType=this._binaryType,this._connectLock=!1,this._addListeners(),this._connectTimeout=setTimeout(()=>this._handleTimeout(),n)}).catch(s=>{this._connectLock=!1,this._handleError(new rr.ErrorEvent(Error(s.message),this))})}_handleTimeout(){this._debug("timeout event"),this._handleError(new rr.ErrorEvent(Error("TIMEOUT"),this))}_disconnect(e=1e3,n){if(this._clearTimeouts(),!!this._ws){this._removeListeners();try{(this._ws.readyState===this.OPEN||this._ws.readyState===this.CONNECTING)&&this._ws.close(e,n),this._handleClose(new rr.CloseEvent(e,n,this))}catch{}}}_acceptOpen(){this._debug("accept open"),this._retryCount=0}_handleOpen=e=>{this._debug("open event");const{minUptime:n=Fe.minUptime}=this._options;clearTimeout(this._connectTimeout),this._uptimeTimeout=setTimeout(()=>this._acceptOpen(),n),Kg(this._ws,"WebSocket is not defined"),this._ws.binaryType=this._binaryType,this._messageQueue.forEach(s=>{this._ws?.send(s)}),this._messageQueue=[],this.onopen&&this.onopen(e),this.dispatchEvent(xn(e))};_handleMessage=e=>{this._debug("message event"),this.onmessage&&this.onmessage(e),this.dispatchEvent(xn(e))};_handleError=e=>{this._debug("error event",e.message),this._disconnect(void 0,e.message==="TIMEOUT"?"timeout":void 0),this.onerror&&this.onerror(e),this._debug("exec error listeners"),this.dispatchEvent(xn(e)),this._connect()};_handleClose=e=>{this._debug("close event"),this._clearTimeouts(),this._shouldReconnect&&this._connect(),this.onclose&&this.onclose(e),this.dispatchEvent(xn(e))};_removeListeners(){this._ws&&(this._debug("removeListeners"),this._ws.removeEventListener("open",this._handleOpen),this._ws.removeEventListener("close",this._handleClose),this._ws.removeEventListener("message",this._handleMessage),this._ws.removeEventListener("error",this._handleError),this._ws.addEventListener("error",Xg))}_addListeners(){this._ws&&(this._debug("addListeners"),this._ws.addEventListener("open",this._handleOpen),this._ws.addEventListener("close",this._handleClose),this._ws.addEventListener("message",this._handleMessage),this._ws.addEventListener("error",this._handleError))}_clearTimeouts(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)}};const Zg=t=>t[1]!==null&&t[1]!==void 0;function ey(){if(crypto?.randomUUID)return crypto.randomUUID();let t=Date.now(),e=performance?.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(n){let s=Math.random()*16;return t>0?(s=(t+s)%16|0,t=Math.floor(t/16)):(s=(e+s)%16|0,e=Math.floor(e/16)),(n==="x"?s:s&3|8).toString(16)})}function Oa(t,e,n={}){const{host:s,path:r,protocol:i,room:o,party:c,basePath:l,prefix:a,query:u}=t;let h=s.replace(/^(http|https|ws|wss):\/\//,"");if(h.endsWith("/")&&(h=h.slice(0,-1)),r?.startsWith("/"))throw new Error("path must not start with a slash");const d=c??"main",f=r?`/${r}`:"",p=i||(h.startsWith("localhost:")||h.startsWith("127.0.0.1:")||h.startsWith("192.168.")||h.startsWith("10.")||h.startsWith("172.")&&h.split(".")[1]>="16"&&h.split(".")[1]<="31"||h.startsWith("[::ffff:7f00:1]:")?e:`${e}s`),y=`${p}://${h}/${l||`${a||"parties"}/${d}/${o}`}${f}`,g=(S={})=>`${y}?${new URLSearchParams([...Object.entries(n),...Object.entries(S).filter(Zg)])}`,b=typeof u=="function"?async()=>g(await u()):g(u);return{host:h,path:f,room:o,name:d,protocol:p,partyUrl:y,urlProvider:b}}var ty=class extends Qg{_pk;_pkurl;name;room;host;path;basePath;constructor(t){const e=oc(t);if(super(e.urlProvider,e.protocols,e.socketOptions),this.partySocketOptions=t,this.setWSProperties(e),
36!t.startClosed&&!this.room&&!this.basePath)throw this.close(),new Error("Either room or basePath must be provided to connect. Use startClosed: true to create a socket and set them via updateProperties before calling reconnect().");t.disableNameValidation||(t.party?.includes("/")&&console.warn(`PartySocket: party name "${t.party}" contains forward slash which may cause routing issues. Consider using a name without forward slashes or set disableNameValidation: true to bypass this warning.`),t.room?.includes("/")&&console.warn(`PartySocket: room name "${t.room}" contains forward slash which may cause routing issues. Consider using a name without forward slashes or set disableNameValidation: true to bypass this warning.`))}updateProperties(t){const e=oc({...this.partySocketOptions,...t,host:t.host??this.host,room:t.room??this.room,path:t.path??this.path,basePath:t.basePath??this.basePath});this._url=e.urlProvider,this._protocols=e.protocols,this._options=e.socketOptions,this.setWSProperties(e)}setWSProperties(t){const{_pk:e,_pkurl:n,name:s,room:r,host:i,path:o,basePath:c}=t;this._pk=e,this._pkurl=n,this.name=s,this.room=r,this.host=i,this.path=o,this.basePath=c}reconnect(t,e){if(!this.host)throw new Error("The host must be set before connecting, use `updateProperties` method to set it or pass it to the constructor.");if(!this.room&&!this.basePath)throw new Error("The room (or basePath) must be set before connecting, use `updateProperties` method to set it or pass it to the constructor.");super.reconnect(t,e)}get id(){return this._pk}get roomUrl(){return this._pkurl}static async fetch(t,e){const n=Oa(t,"http"),s=typeof n.urlProvider=="string"?n.urlProvider:await n.urlProvider();return(t.fetch??fetch)(s,e)}};function oc(t){const{id:e,host:n,path:s,party:r,room:i,protocol:o,query:c,protocols:l,...a}=t,u=e||ey(),h=Oa(t,"ws",{_pk:u});return{_pk:u,_pkurl:h.partyUrl,name:h.name,room:h.room,host:h.host,path:h.path,basePath:t.basePath,protocols:l,socketOptions:a,urlProvider:h.urlProvider}}const Ia="identity",Ti="element:",xi="presence:",ny=new Set(["playerIdentity","cursor","isMe"]);function ir(t){return ny.has(t)}function Pa(t){return t.startsWith(Ti)}function Ta(t){return t.startsWith(xi)}function or(t){return`${xi}${t}`}function sy(t){return t.slice(xi.length)}const Mi=3e4,ry=1e4;function iy(t,e,n=Mi){return Number.isFinite(t)?e-Number(t)<=n:!0}function oy(t,e,n=Mi){return!N(t)||!("at"in t)?!0:iy(t.at,e,n)}function xa(t,e=ry){const n=setInterval(()=>{t()},e);return()=>clearInterval(n)}function cy(t,e=Date.now()){return{at:e,value:t}}function cc(t){return N(t)&&"value"in t&&"at"in t?t.value:t}function Ma(t){try{const e=JSON.stringify(t);return e===void 0?1/0:new TextEncoder().encode(e).byteLength}catch{return 1/0}}function Tr(t){const e=t[Ia];return N(e)&&typeof e.publicKey=="string"?e.publicKey:void 0}function $a(t,e,n,s){if(Ma(n)>ss)return console.warn(`[playhtml] Failed to publish ${s}:`,new Error(`Presence value must be ${ss} bytes or less`)),!1;try{return t.update(e,n),!0}catch(r){return console.warn(`[playhtml] Failed to publish ${s}:`,r),!1}}function ls(t,e,n){try{t.clear(e)}catch(s){console.warn(`[playhtml] Failed to clear ${n}:`,s)}}function te(t,e){try{return t(),!0}catch(n){return console.error(`[playhtml] ${e} callback threw:`,n),!1}}function Mm(t){return N(t)&&"cursor"in t}function lc(t){return N(t)?Object.values(t).every(N):!1}function ly(t){return N(t)?Object.values(t).every(e=>Array.isArray(e)&&e.every(n=>typeof n=="string")):!1}function $m(t){return t==null?null:typeof t=="string"?t:null}function Rm(t){return typeof t=="string"?t:void 0}const ay=1e3,uy=5e3;function ot(t){return t===Ia?"identity":Pa(t)?"element":Ta(t)?"presence":"cursor"}class hy{constructor(e,n,s={}){this.localConnectionId=n,this.syncGraceMs=s.syncGraceMs??uy,this.unsubscribe=e.subscribe(r=>this.handleMessage(r)),this.sweepTimer=setInterval(()=>{this.sweepExpired(Date.now())},ay)}peers=new Map;listeners={cursor:new Set,element:new Set,presence:new Set,identity:new Set};unsubscribe;sweepTimer=null;syncGraceMs;absentPeerDeadlines=new Map;absentPeerTimer=null;getPeers(){return this.peers}subscribe(e,n){return this.listeners[e].add(n),te(n,"peer store namespace"),()=>{this.listeners[e].delete(n)}}destroy(){this.sweepTimer!==null&&(clearInterval(this.sweepTimer),this.sweepTimer=null),this.clearAbsentPeerTimer(),this.absentPeerDeadlines.clear(),this.unsubscribe();for(const e of Object.values(this.listeners))e.clear()}handleMessage(e){if(e.type==="presence-sync"){this.applySync(e.peers),this.pruneExpired(Date.now()),this.notify(new Set(["cursor","element","presence","identity"]));return}if(e.type==="presence-changes"){const n=this.applyChanges(e);this.pruneExpired(Date.now(),n),n.size>0&&this.notify(n)}}applySync(e){const n=Date.now();for(const s of this.peers.keys())s in e||this.absentPeerDeadlines.has(s)||this.absentPeerDeadlines.set(s,n+this.syncGraceMs);for(const[s,r]of Object.entries(e))s!==this.localConnectionId&&(this.peers.set(s,{...r}),this.absentPeerDeadlines.delete(s));this.scheduleAbsentPeerExpiry()}scheduleAbsentPeerExpiry(){if(this.clearAbsentPeerTimer(),this.absentPeerDeadlines.size===0)return;const e=Math.min(...this.absentPeerDeadlines.values());this.absentPeerTimer=setTimeout(()=>{this.absentPeerTimer=null,this.expireAbsentPeers(Date.now())},Math.max(0,e-Date.now()))}clearAbsentPeerTimer(){this.absentPeerTimer!==null&&(clearTimeout(this.absentPeerTimer),this.absentPeerTimer=null)}expireAbsentPeers(e){const n=new Set;for(const[s,r]of this.absentPeerDeadlines){if(r>e)continue;this.absentPeerDeadlines.delete(s);const i=this.peers.get(s);if(i){this.peers.delete(s);for(const o of Object.keys(i))n.add(ot(o))}}this.scheduleAbsentPeerExpiry(),n.size>0&&this.notify(n)}applyChanges(e){const n=new Set;for(const[s,r]of Object.entries(e.updates)){if(s===this.localConnectionId){for(const o of Object.keys(r))n.add(ot(o));continue}const i=this.peers.get(s)??{};this.peers.set(s,i),this.absentPeerDeadlines.delete(s);for(const[o,c]of Object.entries(r))i[o]=c,n.add(ot(o))}for(const[s,r]of Object.entries(e.removes)){if(s===this.localConnectionId){for(const o of r)n.add(ot(o));continue}const i=this.peers.get(s);if(i){for(const o of r)o in i&&(delete i[o],n.add(ot(o)));Object.keys(i).length===0&&(this.peers.delete(s),this.absentPeerDeadlines.delete(s))}}return n}notify(e){const n=new Set;for(const s of e)for(const r of this.listeners[s])n.has(r)||(n.add(r),te(r,"peer store namespace"))}sweepExpired(e){const n=new Set;this.pruneExpired(e,n),n.size>0&&this.notify(n)}pruneExpired(e,n=new Set){for(const[s,r]of this.peers){for(const[i,o]of Object.entries(r))oy(o,e,Mi)||(delete r[i],n.add(ot(i)));Object.keys(r).length===0&&(this.peers.delete(s),this.absentPeerDeadlines.delete(s))}return n}}const dy=1,fy=3,py=15e3,gy=5e3,yy=500,my=2500;function wy(t=Math.random){return yy+t()*my}class Ra{socket;room;listeners=new Set;latestJoin=null;channelValues=new Map;peers;_connectionState="connecting";hasEverOpened=!1;failedReconnects=0;unreachableLogged=!1;unreachableTimer=null;
36lastControlLogAt=new Map;usesHandlerProperties=!1;onMessage=e=>{const n=by(e.data);if(n){this.handleControlMessage(n);for(const s of this.listeners)te(()=>s(n),"presence transport listener")}};onOpen=()=>{this._connectionState="open",this.hasEverOpened=!0,this.failedReconnects=0,this.unreachableLogged=!1,this.unreachableTimer!==null&&(clearTimeout(this.unreachableTimer),this.unreachableTimer=null),this.flushCurrentState()};onCloseOrError=()=>{this._connectionState!=="open"&&(this.failedReconnects+=1),this._connectionState!=="unreachable"&&(this._connectionState="connecting"),this.failedReconnects>=fy&&this.markUnreachable()};constructor(e){this.room=e.room;const n=e.socketFactory??(s=>new ty(s));this.socket=n({host:e.host,room:e.room,party:"presence",maxEnqueuedMessages:0,minReconnectionDelay:wy()}),ac(this.socket)?(this.socket.onmessage=this.onMessage,this.socket.onopen=this.onOpen,this.socket.onclose=this.onCloseOrError,this.socket.onerror=this.onCloseOrError,this.usesHandlerProperties=!0):(this.socket.addEventListener("message",this.onMessage),this.socket.addEventListener("open",this.onOpen),this.socket.addEventListener("close",this.onCloseOrError),this.socket.addEventListener("error",this.onCloseOrError)),this.unreachableTimer=setTimeout(()=>{this.unreachableTimer=null,this.hasEverOpened||this.markUnreachable()},py),this.peers=new hy(this,this.socket.id)}get connectionState(){return this._connectionState}markUnreachable(){this.unreachableLogged||(this.unreachableLogged=!0,this._connectionState="unreachable",console.error(`[playhtml] presence transport unreachable — realtime presence degraded (room ${this.room}). Cursors, element awareness, and custom presence will not sync until the connection recovers.`))}handleControlMessage(e){e.type==="presence-error"?this.logControl("presence-error",()=>console.warn(`[playhtml] presence server rejected a message (room ${this.room}):`,e.message)):e.type==="presence-rate"&&this.logControl("presence-rate",()=>console.warn(`[playhtml] presence channel "${e.channel}" is rate-limited to ${e.hz}Hz (room ${this.room}).`))}logControl(e,n){const s=Date.now(),r=this.lastControlLogAt.get(e)??0;s-r<gy||(this.lastControlLogAt.set(e,s),n())}join(e){const n=ke(e),s={type:"presence-join",identity:n.identity,page:n.page};tr(s),this.latestJoin=n,this.sendIfOpen(s)}update(e,n){const s=ke(n),r={type:"presence-update",channel:e,value:s};tr(r),this.channelValues.set(e,s),this.sendIfOpen(r)}clear(e){this.channelValues.delete(e),this.sendIfOpen({type:"presence-clear",channel:e})}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}destroy(){this.unreachableTimer!==null&&(clearTimeout(this.unreachableTimer),this.unreachableTimer=null),this.peers.destroy(),this.usesHandlerProperties&&ac(this.socket)?(this.socket.onmessage===this.onMessage&&(this.socket.onmessage=null),this.socket.onopen===this.onOpen&&(this.socket.onopen=null),this.socket.onclose===this.onCloseOrError&&(this.socket.onclose=null),this.socket.onerror===this.onCloseOrError&&(this.socket.onerror=null)):(this.socket.removeEventListener("message",this.onMessage),this.socket.removeEventListener("open",this.onOpen),this.socket.removeEventListener("close",this.onCloseOrError),this.socket.removeEventListener("error",this.onCloseOrError)),this.socket.close(),this.listeners.clear()}flushCurrentState(){this.latestJoin&&this.sendIfOpen({type:"presence-join",identity:this.latestJoin.identity,page:this.latestJoin.page});for(const[e,n]of this.channelValues)this.sendIfOpen({type:"presence-update",channel:e,value:n})}sendIfOpen(e){tr(e),this.isSocketOpen()&&this.socket.send(JSON.stringify(e))}isSocketOpen(){return this.socket.readyState===void 0||this.socket.readyState===dy}}function ac(t){return"onmessage"in t&&"onopen"in t&&"onclose"in t&&"onerror"in t}function by(t){if(typeof t!="string")return null;let e;try{e=JSON.parse(t)}catch{return null}if(!N(e))return null;switch(e.type){case"presence-sync":return lc(e.peers)?e:null;case"presence-changes":return lc(e.updates)&&ly(e.removes)?e:null;case"presence-rate":return typeof e.channel=="string"&&typeof e.hz=="number"?e:null;case"presence-error":return typeof e.message=="string"?e:null;default:return null}}const uc=`${Ti}shard:`,Na=1,xt=8,_y=1100;class Ey{transport;getIdentity;getPage;onAwareness;onAwarenessChange;localTags=new Map;currentAwareness=new Map;publishedChannels=new Set;pendingClears=new Set;unsubscribe;stopKeepalive;publishScheduled=!1;republishTimer=null;destroyed=!1;lastAwarenessFingerprint="";localStableId;constructor(e){this.transport=e.transport,this.getIdentity=e.getIdentity,this.getPage=e.getPage,this.onAwareness=e.onAwareness,this.onAwarenessChange=e.onAwarenessChange,this.localStableId=this.getIdentity().publicKey;const n=()=>
36this.emit(),s=this.transport.peers.subscribe("element",n),r=this.transport.peers.subscribe("identity",n);this.unsubscribe=()=>{s(),r()},this.stopKeepalive=xa(()=>{this.destroyed||this.localTags.size===0||this.publishLocalAwareness()}),this.join()}setLocalAwareness(e,n,s){this.stageLocalAwareness(e,n,s)&&(this.schedulePublish(),this.emitLocalAwareness(e,n))}setLocalAwarenessBatch(e){const n=[];for(const[s,r,i]of e)this.stageLocalAwareness(s,r,i)&&n.push([s,r]);if(n.length!==0){this.schedulePublish();for(const[s,r]of n)this.emitLocalAwareness(s,r)}}stageLocalAwareness(e,n,s){const r=this.localTags.get(e);return r?r[n]===s?!1:(r[n]=s,!0):(this.localTags.set(e,{[n]:s}),!0)}removeLocalAwareness(e,n){const s=this.localTags.get(e);!s||!(n in s)||(delete s[n],Object.keys(s).length===0&&this.localTags.delete(e),this.schedulePublish(),this.emitLocalAwareness(e,n))}getLocalAwareness(e,n){return this.localTags.get(e)?.[n]}getAwareness(e,n){return this.currentAwareness.get(`${e}:${n}`)}refresh(){this.emit()}destroy(){this.destroyed=!0,this.republishTimer!==null&&(clearTimeout(this.republishTimer),this.republishTimer=null),this.stopKeepalive(),this.unsubscribe()}schedulePublish(){this.publishScheduled||this.destroyed||(this.publishScheduled=!0,queueMicrotask(()=>{this.publishScheduled=!1,!this.destroyed&&(this.onAwarenessChange&&(this.lastAwarenessFingerprint=this.fingerprintCurrentAwareness(this.currentAwareness)),this.publishLocalAwareness(),this.scheduleRepublish())}))}scheduleRepublish(){this.destroyed||(this.republishTimer!==null&&clearTimeout(this.republishTimer),this.republishTimer=setTimeout(()=>{if(this.republishTimer=null,!this.destroyed){for(const e of this.pendingClears)ls(this.transport,e,"element awareness");this.pendingClears.clear(),this.publishLocalAwareness()}},_y))}join(){try{this.transport.join({identity:this.getIdentity(),page:this.getPage()})}catch(e){console.warn("[playhtml] Failed to join element awareness room:",e)}}publishLocalAwareness(){const e=new Set,n=Sy(this.localTags),s=n.slice(0,xt);if(n.length>xt){const r=Cy(n.slice(xt));console.error(`[playhtml] Element awareness exceeded ${xt} shards (~${xt*ss} bytes); dropping overflow so under-budget elements keep syncing. Affected tags: ${r.join(", ")}.`)}for(let r=0;r<s.length;r+=1){const i=`${uc}${r}`;$a(this.transport,i,s[r],"element awareness")&&e.add(i),this.pendingClears.delete(i)}for(const r of this.publishedChannels)e.has(r)||(this.pendingClears.add(r),ls(this.transport,r,"element awareness"));this.publishedChannels=e}emit(){const e=this.buildElementAwareness(),n=this.fingerprintCurrentAwareness(e);n!==this.lastAwarenessFingerprint&&(this.lastAwarenessFingerprint=n,this.currentAwareness=e,this.onAwareness(e))}fingerprintCurrentAwareness(e){const n=vy(e),s=new Set;for(const c of e.values())for(const l of c.byStableId.keys())s.add(l);const r=[],i=this.getIdentity();s.has(i.publicKey)&&r.push(`${i.publicKey}:${JSON.stringify(i)}`);const o=this.transport.peers.getPeers();for(const c of Array.from(o.keys()).sort()){const l=o.get(c);if(!l)continue;const a=Tr(l)??c;s.has(a)&&r.push(`${a}:${JSON.stringify(l.identity??null)}`)}return`${n}|${r.sort().join("|")}`}emitLocalAwareness(e,n){if(!this.onAwarenessChange){this.emit();return}const s=`${e}:${n}`,r=this.currentAwareness.get(s),i=this.getIdentity().publicKey;if(i!==this.localStableId){this.localStableId=i,this.emit();return}const o=new Map,c=this.localTags.get(e);c&&n in c&&o.set(i,c[n]);for(const[a,u]of r?.byStableId??[])a===this.localStableId||a===i||o.set(a,u);if(o.size===0){this.currentAwareness.delete(s),this.onAwarenessChange(s,void 0);return}const l={array:Array.from(o.values()),byStableId:o};this.currentAwareness.set(s,l),this.onAwarenessChange(s,l)}buildElementAwareness(){const e=new Map,n=this.getIdentity().publicKey;for(const[r,i]of this.localTags)for(const[o,c]of Object.entries(i))xr(e,r,o,c,n);const s=this.transport.peers.getPeers();for(const r of Array.from(s.keys()).sort()){const i=s.get(r),o=Tr(i);if(o===n)continue;const c=o??r;for(const[l,a]of Object.entries(i))if(Pa(l)){if(l.startsWith(uc))ky(e,a,c);else if(N(a)){const u=l.slice(Ti.length);for(const[h,d]of Object.entries(a))xr(e,u,h,d,c)}}}return e}}function vy(t){const e=[];for(const n of Array.from(t.keys()).sort()){const s=t.get(n);for(const r of Array.from(s.byStableId.keys()).sort()){let i;try{i=JSON.stringify(s.byStableId.get(r))??"null"}catch{i="null"}e.push(`${n}:${r}:${i}`)}}return e.join("|")}function xr(t,e,n,s,r){const i=`${e}:${n}`;let o=t.get(i);o||(o={array:[],byStableId:new Map},t.set(i,o)),o.array.push(s),o.byStableId.set(r,s)}function Sy(t){const e=[];let n=[];for(const s of Ay(t)){const r=[...n,s];n.length>0&&Ma(cr(r))>ss?(e.push(cr(n)),n=[s]):n=r}return n.length>0&&e.push(cr(n)),e}function Ay(t){const e=[];for(const n of Array.from(t.keys()).sort()){const s=t.get(n);for(const r of Object.keys(s).sort())e.push([n,r,s[r]])}return e}
36function cr(t){return{v:Na,at:Date.now(),entries:t}}function Cy(t){const e=new Set;for(const n of t)for(const[s]of n.entries)e.add(s);return Array.from(e).sort()}function ky(t,e,n){if(Dy(e))for(const s of e.entries){const[r,i,o]=s;xr(t,r,i,o,n)}}function Dy(t){return!N(t)||t.v!==Na||!Array.isArray(t.entries)?!1:t.entries.every(e=>Array.isArray(e)&&e.length===3&&typeof e[0]=="string"&&typeof e[1]=="string")}const Ly=1100;class Ua{transport;getIdentity;getPage;getCursorPresences;onCursorPresencesChange;localChannels=new Map;pendingClears=new Set;listeners=new Map;nextListenerId=0;unsubscribe;stopKeepalive;republishTimer=null;destroyed=!1;constructor(e){this.transport=e.transport,this.getIdentity=e.getIdentity,this.getPage=e.getPage,this.getCursorPresences=e.getCursorPresences,this.onCursorPresencesChange=e.onCursorPresencesChange;const n=()=>this.emit(),s=this.transport.peers.subscribe("presence",n),r=this.transport.peers.subscribe("identity",n);this.unsubscribe=()=>{s(),r()},this.stopKeepalive=xa(()=>{this.destroyed||this.localChannels.size===0||this.republishLiveChannels()}),this.join()}setMyPresence(e,n){if(ir(e))throw new Error(`[playhtml] "${e}" is a reserved presence field and cannot be used as a channel name. playerIdentity, cursor, and isMe are populated by playhtml; choose a different channel name.`);const s=or(e);if(n==null){if(!this.localChannels.has(e)&&this.pendingClears.has(s))return;this.localChannels.delete(e),this.pendingClears.add(s),ls(this.transport,s,"presence")}else this.localChannels.set(e,n),this.pendingClears.delete(s),this.publishChannel(e,n);this.scheduleRepublish(),this.emit()}publishChannel(e,n){$a(this.transport,or(e),cy(n),"presence")}getPresences(){return this.buildPresences()}onPresenceChange(e,n){if(e==="cursor"&&this.onCursorPresencesChange){const r=this.onCursorPresencesChange(()=>{n(this.buildPresences())});return te(()=>n(this.buildPresences()),"presence subscriber"),r??(()=>{})}const s=String(this.nextListenerId++);return this.listeners.set(s,{channel:e,callback:n,lastFingerprint:this.channelFingerprint(e)}),te(()=>n(this.buildPresences()),"presence subscriber"),()=>{this.listeners.delete(s)}}getMyIdentity(){return this.getIdentity()}destroy(){this.destroyed=!0,this.republishTimer!==null&&(clearTimeout(this.republishTimer),this.republishTimer=null),this.stopKeepalive(),this.unsubscribe()}scheduleRepublish(){this.destroyed||(this.republishTimer!==null&&clearTimeout(this.republishTimer),this.republishTimer=setTimeout(()=>{if(this.republishTimer=null,!this.destroyed){this.republishLiveChannels();for(const e of this.pendingClears)ls(this.transport,e,"presence");this.pendingClears.clear()}},Ly))}republishLiveChannels(){for(const[e,n]of this.localChannels)this.publishChannel(e,n)}join(){try{this.transport.join({identity:this.getIdentity(),page:this.getPage()})}catch(e){console.warn("[playhtml] Failed to join presence room:",e)}}get peers(){return this.transport.peers.getPeers()}emit(){if(this.listeners.size===0)return;let e=null;const n=()=>(e||(e=this.buildPresences()),e);for(const s of this.listeners.values()){const r=this.channelFingerprint(s.channel);if(r===s.lastFingerprint)continue;te(()=>s.callback(n()),"presence subscriber")&&(s.lastFingerprint=r)}}channelFingerprint(e){const n=[`self-identity:${Mn(this.getIdentity())}`];this.localChannels.has(e)&&n.push(`self:${Mn(this.localChannels.get(e))}`);const s=or(e);for(const r of Array.from(this.peers.keys()).sort()){const i=this.peers.get(r),o=i[s];o!==void 0&&n.push(`${r}:${Mn(i.identity)}:${Mn(cc(o))}`)}return n.join("|")}buildPresences(){const e=new Map,n=this.getIdentity().publicKey;e.set(n,this.buildSelfView());for(const s of Array.from(this.peers.keys()).sort()){const r=this.peers.get(s),i=r.identity,o=Tr(r);if(o===n)continue;const c=o??s,l=e.get(c)??{playerIdentity:N(i)?i:void 0,cursor:null,isMe:!1};!l.playerIdentity&&N(i)&&(l.playerIdentity=i);for(const[a,u]of Object.entries(r)){if(!Ta(a))continue;const h=sy(a);ir(h)||(l[h]=cc(u))}e.set(c,l)}return this.mergeCursorPresences(e,n),e}buildSelfView(){const e={playerIdentity:this.getIdentity(),cursor:null,isMe:!0};for(const[n,s]of this.localChannels)ir(n)||(e[n]=s);return e}mergeCursorPresences(e,n){const s=this.getCursorPresences?.();if(s)for(const[r,i]of s){const o=e.get(r);e.set(r,{...o,playerIdentity:i.playerIdentity??o?.playerIdentity,cursor:i.cursor??null,isMe:r===n})}}}function Mn(t){try{return JSON.stringify(t??null)}catch{return"null"}}class Oy{inner;subscriptions=new Map;nextSubscriptionId=0;constructor(e){this.inner=e}setInner(e){if(e!==this.inner){this.inner=e;for(const n of this.subscriptions.values()){try{n.innerUnsub()}catch{}let s=()=>{};te(()=>{s=e.onPresenceChange(n.channel,n.callback)},"presence facade re-attach"),n.innerUnsub=s}}}setMyPresence(e,n){this.inner.setMyPresence(e,n)}getPresences(){return this.inner.getPresences()}onPresenceChange(e,n){const s=this.nextSubscriptionId++,r=this.inner.onPresenceChange(e,n);return this.subscriptions.set(s,{channel:e,callback:n,innerUnsub:r}),()=>{const i=this.subscriptions.get(s);if(i){this.subscriptions.delete(s);try{i.innerUnsub()}catch{}}}}getMyIdentity(){return this.inner.getMyIdentity()}}class Iy{pendingChanges=[];cancelFlush=null;getDoc;constructor(e){this.getDoc=e}queue(e){this.pendingChanges.push({targetDoc:this.getDoc(),apply:e}),this.requestFlush()}clear(){this.cancelFlush&&(this.cancelFlush(),this.cancelFlush=null),this.pendingChanges=[]}flush(){this.cancelFlush=null;const e=this.pendingChanges;if(this.pendingChanges=[],!e.length)return;const n=new Map;for(const s of e){const r=n.get(s.targetDoc)??[];r.push(s.apply),n.set(s.targetDoc,r)}for(const[s,r]of n)s.transact(()=>{for(const i of r)i()})}requestFlush(){if(this.cancelFlush)return;const e=()=>this.flush();if(typeof window.requestAnimationFrame=="function"){const s=window.requestAnimationFrame(e);this.cancelFlush=()=>window.cancelAnimationFrame(s);return}const n=window.setTimeout(e,0);this.cancelFlush=()=>window.clearTimeout(n)}}function Py(t,e){if(t.host||t.protocol!=="about:")return t.host;try{return new URL(e).host}catch{return t.host}}const Ty="api.playhtml.fun",xy="api-staging.playhtml.fun";function My(t){if(t)return t;const e=window.location.hostname;return e.includes("staging")||e.includes("ngrok-free")?xy:Ty}let K=ma({play:{}}),Ue=ya(K),ja=ka(K.play),hc=null;function Ha({includeSearch:t}){const e=window.location.pathname.replace(/\.[^/.]+$/,"");return t?e+window.location.search:e}function $n(t){return t.replace(/\.[^/.]+$/,"")}function Fa(t){const e={domain:St(),pathname:window.location.pathname,search:window.location.search};if(typeof t=="function"){const n=t(e);return n&&n.startsWith("/")?$n(n):n}switch(t){case"page":return $n(e.pathname);case"domain":return"";
36case"section":return`/${$n(e.pathname).split("/").filter(Boolean)[0]||""}`;default:return $n(e.pathname)}}function ln(t,e){const n=Hp(t),s=e===""?n:`${n}-${e}`;return encodeURIComponent(s)}function St(){return Py(window.location,document.referrer)}let z,Ht=null,dc=!1,ae=null,Mr=null;async function $i(){Mr??=await _c(()=>import("./cursor-client-BWUq_OlJ.js"),__vite__mapDeps([0,1]))}let at="",as=null,F=null,$r=null;const At={subscribers:new Set,feedUnsub:null,getPresences(){return ae?.getCursorPresences()??new Map},subscribe(t){return this.subscribers.add(t),()=>{this.subscribers.delete(t)}},notify(t){for(const e of this.subscribers)te(()=>e(t),"cursor presence subscriber")},connect(t){this.feedUnsub?.(),this.feedUnsub=t.onCursorPresencesChange(e=>{this.notify(e)})},disconnect(){this.feedUnsub?.(),this.feedUnsub=null}};function tt(){return F?.getIdentity()??Rg()}const ue=new Map,Ct=new Map,$y=new Map,Ry=new Map,us=new Set,qe=new Map,Rr=new Set;function Ny(t){const e=t.getAttribute("data-source");if(!e)return;let n,s,r;try{({domain:n,path:s,elementId:r}=na(e))}catch{return}const i=`${n}${s}#${r}`;if(!Rr.has(i)&&(Rr.add(i),z?.wsconnected))try{const o={domain:n,path:s,elementId:r};z.sendMessage(JSON.stringify({type:"add-shared-reference",reference:o})),z.sendMessage(JSON.stringify({type:"export-permissions",elementIds:[r]}))}catch(o){console.warn("[PLAYHTML] Failed to notify server of new shared reference:",o)}}function Uy(t){if(!t.id)return;const e=t.id,n=t.getAttribute("shared");let s="read-write";if(n&&n!==""){const r=n.toLowerCase();(r.includes("read-only")||r==="ro")&&(s="read-only")}if(Sa(e,s),z?.wsconnected)try{const r={elementId:e,permissions:s,path:window.location.pathname};z.sendMessage(JSON.stringify({type:"register-shared-element",element:r}))}catch(r){console.warn("[PLAYHTML] Failed to notify server of new shared element:",r)}}function Ba(t,e,n){ue.has(t)||ue.set(t,new Map);const s=ue.get(t);if(!s.has(e)){K.play[t]??={};const r=K.play[t];if(r[e]===void 0){const i=ke(n);r[e]=i}s.set(e,r[e])}return s.get(e)}const D=new Map,fc=new WeakMap;let kt=new Map;const pc=new Set,Va=new Iy(()=>Ue),gc=new Map;let jy=0,Us=ra;const re=new Map;let hs=null;function Wa(){hs||re.size===0||typeof MutationObserver>"u"||(hs=wi(document.documentElement,t=>{for(const e of t)for(const n of e.addedNodes)fe(n)&&(n.id&&re.has(n.id)&&hn(n),n.querySelectorAll("[id]").forEach(s=>{re.has(s.id)&&hn(s)}))},{childList:!0,subtree:!0}))}function Hy(){hs?.disconnect(),hs=null}function js(){return[Y.CanPlay,...Object.keys(Us)]}function Fy(t){z.sendMessage(JSON.stringify(t))}function Ri(t){let e;try{e=JSON.parse(t)}catch{return}if(e.type==="room-reset"){const i=Number(e.resetEpoch);
36if(!Number.isFinite(i)){console.error("[PLAYHTML] Received room-reset without a resetEpoch"),window.location.reload();return}em(i);return}if(e.type==="reset-epoch"){const i=Number(e.resetEpoch);if(!Number.isFinite(i)){console.error("[PLAYHTML] Received reset-epoch without a resetEpoch");return}tu(H,i);return}const{type:n,eventPayload:s}=e,r=kt.get(n);if(!r){if(e.permissions)try{const i=e.permissions;Object.entries(i).forEach(([o,c])=>{if(Sa(o,c),c==="read-only"){const l=document.querySelector(`[data-source$="#${CSS.escape(o)}"]`);l&&l.setAttribute("data-source-read-only","")}})}catch{}return}for(const i of r)i.onEvent(s)}let q=!1,ds=!0,Ni=!0,Rn=!1,za=()=>{},Nr=()=>{};function By(){const t=new Promise((e,n)=>{za=e,Nr=n});return t.catch(()=>{}),t}let ut=By();function Vy(t){return typeof t=="object"&&t!==null&&"then"in t&&typeof t.then=="function"}let an=new Set,H="",$e="",fs=null,lr=null;function Ka(){const t=C?.room;return typeof t=="function"?t():t}const ps=new Map;let Vn=null,ne=null,gt=null,Ft=null,Wn=null,zn=null;const gs={store:null,storeUnsubscribe:null,subscribers:new Set,getPeers(){return this.store?.getPeers()??new Map},subscribe(t){return this.subscribers.add(t),()=>this.subscribers.delete(t)},connect(t){this.storeUnsubscribe?.(),this.store=t,this.storeUnsubscribe=t.subscribe("identity",()=>{for(const e of this.subscribers)te(e,"users identity subscriber")})},disconnect(){this.storeUnsubscribe?.(),this.storeUnsubscribe=null,this.store=null}};function Hs(t){const e=ps.get(t);if(e)return e.refCount++,e.transport;const n=new Ra({host:$e,room:t}),s=F?.onSelfChange(()=>{try{n.join({identity:tt(),page:on()}),t===gt&&ne?.refresh()}catch(r){console.warn("[playhtml] Failed to republish identity on change:",r)}})??null;return ps.set(t,{transport:n,refCount:1,selfChangeUnsub:s}),n}function Ya(t){const e=Hs(t);zn=t,gs.connect(e.peers)}function Wy(){gs.disconnect(),zn!==null&&(En(zn),zn=null)}function En(t){const e=ps.get(t);if(e&&(e.refCount--,!(e.refCount>0))){ps.delete(t);try{e.selfChangeUnsub?.()}catch{}try{e.transport.destroy()}catch{}}}let ar=null,ze=null;const zy=5e3,ys=new Set;let C=null,Ja=!1;function un(t){if(typeof t!="function"){if(Array.isArray(t)){const e=t.map(un);return e.length===0?void 0:e}if(t&&typeof t=="object"){const e={};for(const n of Object.keys(t).sort()){const s=un(t[n]);s!==void 0&&(e[n]=s)}return Object.keys(e).length===0?void 0:e}return t}}function Ur(t){return typeof t=="function"?!0:Array.isArray(t)?t.some(Ur):t&&typeof t=="object"?Object.values(t).some(Ur):!1}function Ky(t,e){for(const r of Object.keys(e)){const i=typeof e[r]=="function",o=typeof t[r]=="function",c=t[r]!==void 0;if(i&&c&&!o||o&&e[r]!==void 0&&!i)return!0}const n=un(t)??{},s=un(e)??{};for(const r of Object.keys(s))if(r in n&&JSON.stringify(s[r])!==JSON.stringify(n[r]))return!0;return!1}function Yy(t){return un(t)===void 0&&!Ur(t)}function jr(t){if(C){Ky(C,t)&&console.warn("[playhtml] Ignoring conflicting config passed after playhtml was already configured. Config is locked to the first declaration. Declare it once up front with playhtml.configure(...) (or matching options at every call site).");return}if(!Yy(t)){if(Ja){console.warn("[playhtml] Ignoring config passed after playhtml already connected. Declare it before init() — e.g. with playhtml.configure(...) in a script that runs before any component mounts.");return}if(t.extraCapabilities)for(const[e,n]of Object.entries(t.extraCapabilities))wu(e,n);if(C={...t,...t.defaultRoomOptions?{defaultRoomOptions:{...t.defaultRoomOptions}}:{},...t.cursors?{cursors:{...t.cursors}}:{}},t.extraCapabilities)for(const[e,n]of Object.entries(t.extraCapabilities))mu(e,n);if(t.events)for(const[e,n]of Object.entries(t.events))bu(e,n)}}function Jy(){Ja=!0}function Ui(t){const{room:e,partykitHost:n,onError:s,onMessage:r}=t,i=Ng(),o=Ug();o.forEach(l=>{const a=`${l.domain}${l.path}#${l.elementId}`;Rr.add(a)});const c=()=>{const l=Qy(e);return{sharedElements:JSON.stringify(i),sharedReferences:JSON.stringify(o),clientResetEpoch:l!==null?String(l):null}};return z=new ip(n,e,Ue,{params:c}),Ht=cp(z),!dc&&typeof window<"u"&&(dc=!0,window.addEventListener("pagehide",()=>Ht?.flush()),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&Ht?.flush()})),z.on("error",()=>{s?.()}),z.on("sync",Zy),z.on("custom-message",r),{sharedReferences:o}}function qa(){At.disconnect();try{ae?.destroy?.()}catch{}ae=null,Vn!==null&&(En(Vn),Vn=null)}function Ga(){try{Ht?.flush()}catch{}Ht=null;try{z?.disconnect?.()}catch{}try{z?.destroy?.()}catch{}}function Xa(){Va.clear();const t=Ue;K=ma({play:{}}
36),Ue=ya(K),ja=ka(K.play),ue.clear(),Ct.clear();try{t.destroy()}catch{}}function Qa(){const t=Hs(H),e=H;gt=e;try{ne=new Ey({transport:t,getIdentity:tt,getPage:on,onAwareness:au,onAwarenessChange:gm})}catch(n){gt=null,En(e),console.error("[playhtml] Failed to build element awareness client:",n);return}}function qy(){if(ne){try{ne.destroy()}catch{}ne=null,gt!==null&&(En(gt),gt=null)}}function Gy(){if(!ne)return;const t=[];for(const[e,n]of D)for(const[s,r]of n)r.selfAwareness!==void 0&&t.push([e,s,r.selfAwareness]);t.length!==0&&ne.setLocalAwarenessBatch(t)}function Za(){const t=Hs(H);return Wn=H,Ft=new Ua({transport:t,getIdentity:tt,getPage:on,getCursorPresences:()=>At.getPresences(),onCursorPresencesChange:n=>At.subscribe(n)}),Ft}function Xy(){if(Ft){try{Ft.destroy()}catch{}Ft=null,Wn!==null&&(En(Wn),Wn=null)}}function ji(t){const{cursors:e,mainRoom:n}=t;if(!e.enabled){at="";return}if(!F)throw new Error("[playhtml] buildCursors requires the users module to exist first.");const s={...e};if(s.room){const i=Fa(s.room);at=ln(St(),i)}else at=n;if(Mr===null)throw new Error("[playhtml] buildCursors requires the cursor client to be loaded first.");const r=Hs(at);Vn=at,ae=new Mr.CursorClientAwareness(s,r,F),At.connect(ae)}const ms=new Map;function eu(t){return`playhtml_resetEpoch_${t}`}function Qy(t){const e=ms.get(t);if(e!==void 0)return e;let n=null;try{n=localStorage.getItem(eu(t))}catch(r){console.warn("[PLAYHTML] Could not read the stored room reset epoch",r)}const s=n===null?NaN:Number(n);return Number.isFinite(s)?(ms.set(t,s),s):null}function tu(t,e){const n=ms.get(t);if(!(n!==void 0&&n>=e)){ms.set(t,e);try{localStorage.setItem(eu(t),String(e))}catch(s){console.warn("[PLAYHTML] Could not store the room reset epoch",s)}}}function Hi(t){return new Promise((e,n)=>{if(q){e();return}let s=!1,r=null;const i=o=>{s||(s=!0,r!==null&&clearTimeout(r),ys.delete(i),o?n(o):e())};ys.add(i),t!==void 0&&(r=setTimeout(()=>{i(new Error("Timed out waiting for playhtml room reset sync"))},t))})}function Zy(t){if(t||console.error("Issue connecting to yjs..."),q)return;q=!0;const e=[...ys];ys.clear(),e.forEach(n=>n())}function em(t){if(tu(H,t),ar){ze=Math.max(ze??0,t);return}ar=tm(t).catch(e=>{console.error("[PLAYHTML] Failed to reconnect after room-reset:",e),window.location.reload()}).finally(()=>{ar=null,ze=null})}async function tm(t){let e=t;for(;;){const n=e;if(ze=null,await nm(),ze===null||ze<=n)return;e=ze}}async function nm(){if(!H||!$e)throw new Error("playhtml cannot reset before init()");if(C?.cursors?.enabled&&(await $i(),!H||!$e))return;Ga(),qa(),q=!1,an.clear(),Xa(),Ui({room:H,partykitHost:$e,onError:C?.onError,onMessage:Ri});const t=C?.cursors;t?.enabled&&ji({cursors:t,mainRoom:H}),F?.getAll(),Fi(),await Hi(zy),Ca(Fs()),uu(),Bi(),ae?.refreshContainer?.(),ae?.refreshCursorStyles?.(),ia(H)}function sm(){lr||(lr=(t=>{const e=Gl(t.detail?.playerIdentity);if(!e?.playerStyle.colorPalette[0]||!F)return;const n=tt(),s={...e,...typeof n.name=="string"?{name:n.name}:{}};F.adoptIdentity(s),console.log("[playhtml] Merged extension identity via CustomEvent")}),document.addEventListener("playhtml:configure-identity",lr),document.dispatchEvent(new CustomEvent("playhtml:ready")))}async function rm(){if(ds||C?.cursors?.enabled&&(await $i(),ds))return;const t=Ka()??Ha(C?.defaultRoomOptions??{includeSearch:!1}),e=ln(St(),t),n=e!==H,s=C?.cursors,r=!!s?.enabled,o=r!==(ae!==null);let c=!1;if(s?.enabled)if(s.room){const l=Fa(s.room);c=ln(St(),l)!==at}else c=n;for(const[l,a]of D)for(const[u,h]of[...a.entries()]){const d=h.element;(!d||!d.isConnected)&&(h.destroy?.(),a.delete(u),ne?.removeLocalAwareness(l,u))}n&&(Ga(),qy(),Xy(),Wy(),q=!1,au(new Map),Xa(),Ui({room:e,partykitHost:$e,onError:C?.onError,onMessage:Ri}),H=e,Ya(e),Qa(),Gy()),(o||c&&s)&&(qa(),r&&s&&ji({cursors:s,mainRoom:e})),n&&as?.setInner(Za()),(n||o||c)&&F?.getAll(),Fi(),n&&(await Hi(),Ca(Fs())),n?uu():Wi(),Bi(),ae?.refreshContainer?.(),ae?.refreshCursorStyles?.(),ia(H)}function im(t={}){jr(t)}function om(t={}){if(Rn)return jr(t),ut;const e=window.playhtml;if(e){if(Vy(e.ready))return ut=e.ready,ut.then(()=>{Ni=!1},()=>{}),Rn=!0,ut;
36const s=new Error("playhtml is already set up by an incompatible instance. Make sure @playhtml/react and playhtml use matching versions.");return Nr(s),Rn=!0,ut}Rn=!0,jr(t);const n=cm();return n.catch(s=>{Nr(s)}),n}async function cm(){Jy();const t=C?.host,e=C?.cursors??{},n=e.enabled?$i():null,s=Ka()??Ha(C?.defaultRoomOptions??{includeSearch:!1}),r=C?.onError;window.playhtml=mc,document.documentElement.dataset.playhtml="true";const i=ln(St(),s),o=My(t);H=i,$e=o,console.log(`࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂
37࿂࿂࿂࿂  ࿂    ࿂    ࿂    ࿂    ࿂  ࿂࿂࿂࿂
38࿂࿂࿂࿂ booting up playhtml... ࿂࿂࿂࿂
39࿂࿂࿂࿂  https://playhtml.fun  ࿂࿂࿂࿂
40࿂࿂࿂࿂   ࿂     ࿂     ࿂     ࿂   ࿂࿂࿂࿂
41࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂`);const{sharedReferences:c}=Ui({room:i,partykitHost:o,onError:r,onMessage:Ri});if(n&&(await n,H!==i))return z;const l=e.playerIdentity??C?.playerIdentity??tt();F=$g(l,{getIdentityPeers:()=>gs.getPeers(),onIdentityPeersChange:u=>gs.subscribe(u),getCursorPresences:()=>At.getPresences(),onCursorPresencesChange:u=>At.subscribe(u)}),Ya(i),$r=null,F.onChange(dm),ji({cursors:e,mainRoom:i}),F.getAll(),Qa(),sm(),as=new Oy(Za());const a=document.createElement("link");if(a.rel="stylesheet",a.href="https://unpkg.com/playhtml@latest/dist/style.css",document.head.appendChild(a),C?.developmentMode&&(hc=await _c(()=>import("./development-Dr8fEiSP.js"),__vite__mapDeps([2,1])),hc.setupDevUI(mc,D)),Fi(),await Hi(),console.log("[PLAYHTML]: Setting up elements... Time to have some fun 🛝"),Wi(),Bi(),Ni=!1,za(),c.length>0)try{const u=c.map(h=>h.elementId);z.sendMessage(JSON.stringify({type:"export-permissions",elementIds:u}))}catch(u){console.error("[PLAYHTML] Error during post-sync setup:",u)}return z}function lm(t,e){return ne?.getLocalAwareness(t,e)}function fe(t){return t instanceof HTMLElement}function nu(t){return t.hasAttribute("can-play")?"none":"animate"}function su(t){if((t.getAttribute("loading-behavior")||nu(t))==="none")return;t.classList.add("playhtml-loading");const n=t.getAttribute("loading-class");n&&t.classList.add(n),t.setAttribute("aria-busy","true"),t.setAttribute("aria-live","polite")}function ru(t){if((t.getAttribute("loading-behavior")||nu(t))==="none")return;t.classList.remove("playhtml-loading");const n=t.getAttribute("loading-class");n&&t.classList.remove(n),t.removeAttribute("aria-busy"),t.removeAttribute("aria-live")}function iu(){const t=js(),e=new Map(t.map(s=>[s,[]])),n=t.map(s=>`[${s}]`).join(",");for(const s of document.querySelectorAll(n))if(fe(s))for(const r of t)s.hasAttribute(r)&&e.get(r).push(s);return e}function ou(){const t=new Set;for(const e of iu().values())for(const n of e)t.add(n);for(const e of re.keys()){const n=document.getElementById(e);n&&fe(n)&&t.add(n)}return t}function Fi(){ou().forEach(su)}function Bi(){ou().forEach(ru)}function am(t,e,n){if(typeof n=="function"){const s=n(e);C?.developmentMode&&s!==void 0&&typeof s=="object"&&console.warn(`[playhtml] A setData() mutator for "${t}" returned an object. Mutators must mutate the draft in place (e.g. \`d => { d.count++ }\`); the return value is ignored. To replace the whole snapshot, pass a value instead of a function.`);return}Xt(e,n)}function cu(t){const e=It(t);return!jg(t,e)}function um(t,e,n,s){const r=n.defaultData instanceof Function?n.defaultData(t):n.defaultData,i=n.defaultData===void 0?void 0:Ba(e,s,r),o=lm(e,s),c=n.live!==void 0?n.live:n.myDefaultAwareness,l=o??(c instanceof Function?c(t):c);return{...n,live:l,devMode:C?.developmentMode??!1,data:ke(i),awareness:l!==void 0?[l]:void 0,element:t,onChange:u=>{if(i===void 0){console.error(`[playhtml] setData() was called for "${s}", but its initializer does not define \`defaultData\`.`);return}if(!cu(t))return;const h=ue.get(e)?.get(s)??i;Ue.transact(()=>{am(s,h,u)})},onAwarenessChange:u=>{ne?.setLocalAwareness(e,s,u)},triggerAwarenessUpdate:()=>{}}}function hm(t,e){if(!F)return[];const n=new Map(t);e!==void 0&&n.set(F.me.pid,e);const s=[];for(const r of F.getAll()){const i=n.get(r.pid);i!==void 0&&s.push({user:r,live:i})}return s}function dm(t){const e=JSON.stringify([...t].sort((n,s)=>n.pid.localeCompare(s.pid)));if(e!==$r){$r=e;for(const n of D.values())for(const s of n.values())s.selfAwareness===void 0&&s.awarenessByStableId.size===0||te(()=>s.render(),"element users render")}}function fm(t){return Vi(t).length===0}function Vi(t){if(t==null)return["initializer"];const e=[],n=t.defaultData!==void 0,s=n&&t.defaultData!==null&&(typeof t.defaultData=="object"||typeof t.defaultData=="function"),r=typeof t.update=="function",i=typeof t.updateElement=="function",o=typeof t.view=="function",c=r||i||o,l=t.live!==void 0,a=t.myDefaultAwareness!==void 0,u=typeof t.updateElementAwareness=="function",h=c||u;return r&&i&&e.push("update and updateElement are mutually exclusive"),l&&a&&e.push("live and myDefaultAwareness are mutually exclusive"),n&&!s&&e.push("defaultData must be an object or function"),n&&!c?e.push("defaultData requires update, updateElement, or view"):!n&&!l&&!a&&c&&e.push("update, updateElement, or view requires defaultData or live"),l&&!c&&e.push("live requires update, updateElement, or view"),a&&!c&&!u&&e.push("myDefaultAwareness requires update, updateElement, view, or updateElementAwareness"),e.length===0&&!h&&e.push("update, updateElement, view, or updateElementAwareness"),e}function yc(t){const e=t,n={},s=["defaultData","defaultLocalData","live","myDefaultAwareness","update","updateElement","view","updateElementAwareness","onDrag","onDragStart","onClick","onMount","resetShortcut","debounceMs","isValidElementForTag"];for(const r of s)e[r]!==void 0&&(n[r]=e[r]);return n}function lu(t,e){return t===Y.CanPlay||!e.hasAttribute(Y.CanPlay)}function pm(t,e){if(t===Y.CanPlay){const r=re.get(e.id);return r||yc(e)}const n=Us[t];if(!n)return;if(!lu(t,e))return n;const s=yc(e);return{...n,...s}}function au(t){t.forEach(({array:e,byStableId:n},s)=>{te(()=>
41Hr(s,e,n),"element awareness handler")});for(const e of an)t.has(e)||te(()=>Hr(e,[],new Map),"element awareness handler");an=new Set(t.keys())}function gm(t,e){te(()=>Hr(t,e?.array??[],e?.byStableId??new Map),"element awareness handler"),e?an.add(t):an.delete(t)}function Hr(t,e,n){const s=t.indexOf(":"),r=t.slice(0,s),i=t.slice(s+1),o=D.get(r);if(!o)return;const c=o.get(i);c&&c.updateAwareness(e,n)}function Wi(){hu(!1)}function uu(){hu(!0)}function hu(t){if(q){Wa();for(const[e,n]of iu()){const s=new Set(n);if(e===Y.CanPlay)for(const r of re.keys()){const i=document.getElementById(r);i&&fe(i)&&s.add(i)}s.size!==0&&Promise.all(Array.from(s).map(r=>{const i=It(r),o=i?D.get(e)?.get(i):void 0;if(!(!t&&o?.element===r))return vn(r,e)}))}ds&&(ne?.refresh(),fs=Qp(async()=>{await rm()}),Zp(fs),ds=!1)}}function Fs(){return{ensureProxy:Ba,getDoc:()=>Ue,getStorePlay:()=>K.play,proxyByTagAndId:ue,yObserverByKey:Ct,channelRefCounts:$y,channelListeners:Ry}}function ym(t,e){if(!q)throw new Error("playhtml.createPageData is not available before init()");return du(),Bg(t,e,Fs())}function mm(t){if(!q)throw new Error("playhtml.createPresenceRoom is not available before init()");const e=ln(St(),t),n=new Ra({host:$e,room:e}),s=F?.onSelfChange(()=>{n.join({identity:tt(),page:on()})})??null,r=new Ua({transport:n,getIdentity:tt,getPage:on});let i=!1;return{presence:r,destroy:()=>{i||(i=!0,s?.(),r.destroy(),n.destroy())}}}const mc={init:om,configure:im,get isLoading(){return Ni},get ready(){return ut},handleNavigation:async function(){fs&&await fs.trigger()},setupPlayElements:Wi,setupPlayElement:hn,removePlayElement:Sn,deleteElementData:km,setupPlayElementForTag:vn,register:Sm,define:Am,getHandle:yu,get syncedStore(){return ja},elementHandlers:D,dispatchPlayEvent:Dm,registerPlayEventListener:bu,removePlayEventListener:Lm,get cursorClient(){return ae},get presence(){if(!as)throw new Error("playhtml.presence is not available before init()");return as},get users(){if(!F)throw new Error("playhtml.users is not available before init()");return F},get roomId(){return H},get host(){return $e},createPageData:ym,createPresenceRoom:mm,listSharedElements:Xp};function wm(t){if(t===v)throw new Error(`"${v}" is a reserved tag name for page-level data`);D.has(t)||q&&(D.has(t)||D.set(t,new Map),K.play[t]??={})}function bm(t,e){const n=e===Y.CanPlay?re.get(t.id)?.isValidElementForTag:void 0;if(n)return n(t);const s=lu(e,t)?t.isValidElementForTag:void 0;return typeof s=="function"?s(t):Us[e]?.isValidElementForTag?.(t)??!0}function wc(t){const e=t.tagName.toLowerCase(),n=t.id?`#${t.id}`:"",s=Array.from(t.classList).map(r=>`.${r}`).join("");return`<${e}${n}${s}>`}function _m(t,e,n,s){console.error(`[playhtml] Duplicate element id "${e}" for ${t}. Element IDs must be unique per capability tag because playhtml stores shared data by tag and ID. Keeping ${wc(n)} and ignoring ${wc(s)}.`,{existingElement:n,duplicateElement:s})}function Em(t,e,n){const s=D.get(t)?.get(e);!s||s.element===n||s.element.isConnected||Sn(s.element)}async function vn(t,e){if(!bm(t,e)||!q)return;if(!t.id){const l=t.getAttribute("selector-id");if(l){const a=gc.get(l)??0;t.id=btoa(`${e}-${l}-${a}`),gc.set(l,a+1)}else t.id=await Mg(e,t)}const n=It(t);if(!n){console.error(`Element ${t} does not have an acceptable ID. Please add an ID to the element to register it as a playhtml element.`);return}wm(e);const s=D.get(e);Em(e,n,t);const r=pm(e,t);if(!fm(r)){const l=Vi(r);console.error(`Element ${n} does not have proper info to initialize a playhtml element. Missing or invalid initializer properties: ${l.join(", ")}. Please refer to https://github.com/spencerc99/playhtml#can-play for troubleshooting help.`);return}const i=um(t,e,r,n),o=s.get(n);if(o){if(o.element!==t){_m(e,n,o.element,t);return}o.reinitializeElementData(i),zi(e,n,o),Fr(e,n);return}else{const l=new xg(i,{getUsers:hm,...e===Y.CanMirror?{scheduleSetupDataWrite:a=>Va.queue(a)}:{}});s.set(n,l),r.view&&(l.onAfterRender=Cm,l.observeDescendants()),e===Y.CanMirror&&pu(t)}const c=ne?.getAwareness(e,n);c?s.get(n)?.updateAwareness(c.array,c.byStableId):i.triggerAwarenessUpdate?.(),t.classList.add("__playhtml-element"),t.style.setProperty("--jiggle-delay",`${Math.random()*1}s;}`),Fr(e,n)}function zi(t,e,n){const s=K.play[t]?.[e];if(s===void 0)return!1;const r=`${t}:${e}`;pc.add(r);try{n.__data=ke(s),t===Y.CanMirror&&pu(n.element)}finally{pc.delete(r)}return!0}function Ki(t){const e=Ct.get(t);e&&(e.target?.unobserveDeep?.(e),Ct.delete(t))}const ws=new WeakSet;function vm(t){du();const e=J(K.play[t]);e&&!ws.has(e)&&(ws.add(e),e.observe(n=>{if(J(K.play[t])===e)for(const s of n.keysChanged)fu(t,s)}))}function du(){const t=J(K.play);!t||ws.has(t)||(ws.add(t),t.observe(e=>{for(const n of e.keysChanged){if(n===v){Fg(Fs());continue}const s=D.get(n);if(s)for(const r of s.keys())fu(n,r,{restoreMissing:!0})}}))}function fu(t,e,{restoreMissing:n=!1}={}){const s=D.get(t)?.get(e);if(!s)return;const r=K.play[t];n&&r!==void 0&&r[e]===void 0&&s.data!==void 0&&cu(s.element)&&Ue.transact(()=>{r[e]=ke(s.data)});const i=r?.[e];
41if(i===void 0)return;const o=`${t}:${e}`;Ct.get(o)?.target!==J(i)&&(ue.has(t)||ue.set(t,new Map),ue.get(t).set(e,i),Fr(t,e),zi(t,e,s))}function Fr(t,e){const n=`${t}:${e}`,s=D.get(t);if(!s)return;const r=s.get(e);if(!r)return;vm(t);const i=J(K.play[t]?.[e]);if(!i||typeof i.observeDeep!="function")return;Ki(n);let o=!1;const c=()=>{o||(o=!0,queueMicrotask(()=>{o=!1,zi(t,e,r)&&us.add(n)}))};if(c.target=i,i.observeDeep(c),Ct.set(n,c),C?.developmentMode){const l=r.element;if(l&&l.hasAttribute&&l.hasAttribute("data-source")&&!qe.has(n)){const a=window.setTimeout(()=>{us.has(n)||console.warn(`[playhtml] Shared reference ${t}:${e} has not received data. Check data-source and source availability.`),qe.delete(n)},3e3);qe.set(n,a)}}}function hn(t,{ignoreIfAlreadySetup:e}={}){if(t.hasAttribute?.("data-source")&&t.hasAttribute?.("shared")){const s=t.id||"<no-id>";console.error(`[playhtml] Element ${s} has both 'data-source' and 'shared'. Ignoring. A single element cannot be both a consumer and a source.`);return}if(e&&Array.from(D.values()).some(s=>s.has(t.id)))return;if(!fe(t)){console.log(`Element ${t.id} not an HTML element. Ignoring.`);return}t.hasAttribute("data-source")&&Ny(t),t.hasAttribute("shared")&&Uy(t);const n=new Set(js().filter(s=>t.hasAttribute(s)));t.id&&re.has(t.id)&&n.add(Y.CanPlay),n.size>0&&(q?ru(t):su(t)),Promise.all(Array.from(n).map(s=>vn(t,s)))}function pu(t){const e=new Set,n=new Map;for(const r of js())t.querySelectorAll(`[${r}]`).forEach(i=>{if(fe(i)){e.add(i);const o=It(i);o&&n.set(`${r}:${o}`,i)}});fc.get(t)?.forEach((r,i)=>{n.get(i)!==r&&Sn(r)}),e.forEach(r=>{hn(r)}),fc.set(t,n)}function Sn(t){if(!t||!t.id)return;const e=It(t);if(e)for(const[n,s]of D){const r=s.get(e);if(!r||r.element!==t)continue;const i=`${n}:${e}`;Ki(i),us.delete(i);const o=qe.get(i);o!==void 0&&(clearTimeout(o),qe.delete(i)),r.destroy?.(),ne?.removeLocalAwareness(n,e),s.delete(e)}}function gu(t,e){if(e.update&&e.updateElement)throw new Error(`[playhtml] "${t}" defines both \`update\` and \`updateElement\`. Pick one imperative renderer.`);if(e.live!==void 0&&e.myDefaultAwareness!==void 0)throw new Error(`[playhtml] "${t}" defines both \`live\` and \`myDefaultAwareness\`. Pick one element live default.`);if(e.view&&(e.update||e.updateElement))throw new Error(`[playhtml] "${t}" defines both \`view\` and an imperative update renderer. They are mutually exclusive. Pick one.`);if(e.view&&(e.onClick||e.onDrag||e.onDragStart))throw new Error(`[playhtml] "${t}" defines \`view\` alongside an element event handler (onClick/onDrag/onDragStart). In view mode, attach events inside the template (e.g. \`@click=\${...}\`) instead.`);if(e.defaultData!==void 0&&typeof e.defaultData!="function"&&(typeof e.defaultData!="object"||e.defaultData===null))throw new Error(`[playhtml] "${t}" has a non-object \`defaultData\`. Use an object (e.g. \`{ count: 0 }\`) so the shape can grow without a data migration.`);const n=Vi(e);if(n.length>0)throw new Error(`[playhtml] "${t}" has an invalid initializer: ${n.join(", ")}.`)}function Be(t,e){if(e!==void 0)return D.get(e)?.get(t);const n=D.get(Y.CanPlay)?.get(t);if(n)return n;for(const[,s]of D){const r=s.get(t);if(r)return r}}function Mt(t,e){C?.developmentMode&&console.warn(`[playhtml] ${t}("${e}") — no bound element with that id yet; the write was dropped. Register/add the element first, or check the id.`)}function yu(t,e){return{id:t,getElement:()=>document.getElementById(t),getData:()=>Be(t,e)?.data,setData:n=>{const s=Be(t,e);if(!s)return Mt("setData",t);s.setData(n)},setLocalData:n=>{const s=Be(t,e);if(!s)return Mt("setLocalData",t);s.setLocalData(n)},setLive:n=>{const s=Be(t,e);if(!s)return Mt("setLive",t);s.setLive(n)},setMyAwareness:n=>{const s=Be(t,e);if(!s)return Mt("setMyAwareness",t);s.setLive(n)},requestUpdate:()=>{const n=Be(t,e);if(!n)return Mt("requestUpdate",t);n.requestUpdate()},unregister:()=>{const n=Be(t,e)?.element;re.delete(t),re.size===0&&Hy();const s=n??document.getElementById(t);s&&Sn(s)}}}function Sm(t,e){let n,s;if(typeof t=="string")s=t,n=document.getElementById(s);else{if(!fe(t))throw new Error("[playhtml] register(element, initializer) requires an HTML element.");if(!t.id)throw new Error("[playhtml] register(element, initializer) requires an element with a non-empty id.");n=t,s=n.id}return gu(s,e),re.set(s,e),q&&Wa(),n&&fe(n)&&hn(n),C?.developmentMode&&q&&!n&&console.warn(`[playhtml] register("${s}") — no element with that id is in the DOM yet. It will bind automatically when the element appears.`),yu(s,Y.CanPlay)}function Am(t,e){mu(t,e)}function mu(t,e){if(wu(t,e),Us[t]=e,q){const n=Array.from(document.querySelectorAll(`[${t}]`)).filter(fe);Promise.all(n.map(s=>vn(s,t)))}}function wu(t,e){if(t===v)throw new Error(`"${v}" is a reserved tag name for page-level data`);if(t===Y.CanPlay)throw new Error(`[playhtml] "${Y.CanPlay}" is reserved — use register(elementOrId, init) for single elements.`);if(Object.prototype.hasOwnProperty.call(ra,t))throw new Error(`[playhtml] "${t}" is a built-in capability and cannot be redefined.`);gu(t,e)}const bc=new WeakMap;function Cm(t){const e=new Map;
41for(const s of re.keys()){if(s===t.id)continue;const r=document.getElementById(s);r&&t.contains(r)&&fe(r)&&e.set(`${Y.CanPlay}:${s}`,r)}for(const s of js()){const r=Array.from(t.querySelectorAll(`[${s}]`)).filter(fe);for(const i of r)if(i!==t){if(!i.id){C?.developmentMode&&console.warn(`[playhtml] a view rendered a "${s}" element with no id; it won't bind. Give capability children a stable, unique id (key keyed lists by it).`);continue}e.set(`${s}:${i.id}`,i)}}for(const[s,r]of e){const i=s.slice(0,s.indexOf(":"));D.get(i)?.get(r.id)?.element!==r&&vn(r,i)}const n=bc.get(t);if(n)for(const[s,r]of n)e.has(s)||Sn(r);bc.set(t,e)}function km(t,e){if(!q){console.warn(`[PLAYHTML] Cannot remove element data before sync: ${t}:${e}`);return}const n=`${t}:${e}`;try{Ki(n)}catch(c){console.warn(`[PLAYHTML] Failed to remove observer for ${n}:`,c)}const s=K.play[t];if(s&&e in s)try{Ue.transact(()=>{delete s[e]})}catch(c){console.warn(`[PLAYHTML] Failed to remove SyncedStore data for ${n}:`,c)}const r=ue.get(t);r&&(r.delete(e),r.size===0&&ue.delete(t));const i=D.get(t);i&&i.delete(e),us.delete(n);const o=qe.get(n);o!==void 0&&(clearTimeout(o),qe.delete(n))}function Dm(t){const{type:e}=t;if(!kt.has(e)){console.error(`[playhtml] event "${e}" not registered.`);return}Fy(t)}function bu(t,e){const n=String(jy++);return kt.set(t,[...kt.get(t)??[],{type:t,...e,id:n}]),n}function Lm(t,e){const n=kt.get(t);if(!n)return;const s=n.findIndex(r=>
41r.id===e);s!==-1&&(n.splice(s,1),n.length===0&&kt.delete(t))}export{Mi as P,Y as T,Pm as a,Rm as b,Mm as c,Tm as d,D as e,$m as f,It as g,Im as h,N as i,on as j,Xp as l,mc as p,xm as s,Gl as t};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.