playhtml 1.0.0 → 1.1.0

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