playhtml 0.1.3 → 0.1.5

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,6 +1,6 @@
1
- (function(U,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(U=typeof globalThis<"u"?globalThis:U||self,_(U.playhtml={}))})(this,function(U){"use strict";var Ro=Object.defineProperty;var No=(U,_,$)=>_ in U?Ro(U,_,{enumerable:!0,configurable:!0,writable:!0,value:$}):U[_]=$;var m=(U,_,$)=>(No(U,typeof _!="symbol"?_+"":_,$),$);const _=()=>new Map,$=n=>{const t=_();return n.forEach((e,s)=>{t.set(s,e)}),t},j=(n,t,e)=>{let s=n.get(t);return s===void 0&&n.set(t,s=e()),s},Bs=(n,t)=>{const e=[];for(const[s,i]of n)e.push(t(i,s));return e},Fs=(n,t)=>{for(const[e,s]of n)if(t(s,e))return!0;return!1},tt=()=>new Set,de=n=>n[n.length-1],$s=(n,t)=>{for(let e=0;e<t.length;e++)n.push(t[e])},W=Array.from,js=Array.isArray,Ks=String.fromCharCode,Ys=n=>n.toLowerCase(),Xs=/^\s*/g,Js=n=>n.replace(Xs,""),Gs=/([A-Z])/g,on=(n,t)=>Js(n.replace(Gs,e=>`${t}${Ys(e)}`)),Ws=n=>{const t=unescape(encodeURIComponent(n)),e=t.length,s=new Uint8Array(e);for(let i=0;i<e;i++)s[i]=t.codePointAt(i);return s},Dt=typeof TextEncoder<"u"?new TextEncoder:null,zs=Dt?n=>Dt.encode(n):Ws;let Et=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Et&&Et.decode(new Uint8Array).length===1&&(Et=null);const ln=n=>n===void 0?null:n;class qs{constructor(){this.map=new Map}setItem(t,e){this.map.set(t,e)}getItem(t){return this.map.get(t)}}let cn=new qs,fe=!0;try{typeof localStorage<"u"&&(cn=localStorage,fe=!1)}catch{}const hn=cn,Qs=n=>fe||addEventListener("storage",n),Zs=n=>fe||removeEventListener("storage",n),Ps=Object.assign,ti=Object.keys,ei=(n,t)=>{for(const e in n)t(n[e],e)},ni=(n,t)=>{const e=[];for(const s in n)e.push(t(n[s],s));return e},jt=n=>ti(n).length,si=n=>{for(const t in n)return!1;return!0},ii=(n,t)=>{for(const e in n)if(!t(n[e],e))return!1;return!0},an=(n,t)=>Object.prototype.hasOwnProperty.call(n,t),ri=(n,t)=>n===t||jt(n)===jt(t)&&ii(n,(e,s)=>(e!==void 0||an(t,s))&&t[s]===e),ge=(n,t,e=0)=>{try{for(;e<n.length;e++)n[e](...t)}finally{e<n.length&&ge(n,t,e+1)}},oi=n=>n,li=(n,t)=>n===t,At=(n,t)=>{if(n==null||t==null)return li(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)||!At(n.get(e),t.get(e)))return!1;break}case Object:if(jt(n)!==jt(t))return!1;for(const e in n)if(!an(n,e)||!At(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(!At(n[e],t[e]))return!1;break;default:return!1}return!0},ci=(n,t)=>t.includes(n),ut=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name),un=typeof window<"u"&&typeof document<"u"&&!ut;let N;const hi=()=>{if(N===void 0)if(ut){N=_();const n=process.argv;let t=null;for(let e=0;e<n.length;e++){const s=n[e];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=_(),(location.search||"?").slice(1).split("&").forEach(n=>{if(n.length!==0){const[t,e]=n.split("=");N.set(`--${on(t,"-")}`,e),N.set(`-${on(t,"-")}`,e)}})):N=_();return N},pe=n=>hi().has(n),we=n=>ln(ut?process.env[n.toUpperCase()]:hn.getItem(n));(n=>pe("--"+n)||we(n)!==null)("production");const dn=ut&&ci(process.env.FORCE_COLOR,["true","1","2"]),ai=!pe("no-colors")&&(!ut||process.stdout.isTTY||dn)&&(!ut||pe("color")||dn||we("COLORTERM")!==null||(we("TERM")||"").includes("color")),K=Math.floor,Kt=Math.abs,me=(n,t)=>n<t?n:t,et=(n,t)=>n>t?n:t,ui=Math.pow,fn=n=>n!==0?n<0:1/n<0,gn=1,pn=2,ye=4,ke=8,It=32,Y=64,v=128,Yt=31,be=63,nt=127,di=2147483647,wn=Number.MAX_SAFE_INTEGER,fi=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&K(n)===n);class Lt{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const x=()=>new Lt,_e=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(_e(n));let e=0;for(let s=0;s<n.bufs.length;s++){const i=n.bufs[s];t.set(i,e),e+=i.length}return t.set(Me(n.cbuf.buffer,0,n.cpos),e),t},gi=(n,t)=>{const e=n.cbuf.length;e-n.cpos<t&&(n.bufs.push(Me(n.cbuf.buffer,0,n.cpos)),n.cbuf=new Uint8Array(et(e,t)*2),n.cpos=0)},A=(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},Se=A,p=(n,t)=>{for(;t>nt;)A(n,v|nt&t),t=K(t/128);A(n,nt&t)},Ce=(n,t)=>{const e=fn(t);for(e&&(t=-t),A(n,(t>be?v:0)|(e?Y:0)|be&t),t=K(t/64);t>0;)A(n,(t>nt?v:0)|nt&t),t=K(t/128)},De=new Uint8Array(3e4),pi=De.length/3,wi=(n,t)=>{if(t.length<pi){const e=Dt.encodeInto(t,De).written||0;p(n,e);for(let s=0;s<e;s++)A(n,De[s])}else C(n,zs(t))},mi=(n,t)=>{const e=unescape(encodeURIComponent(t)),s=e.length;p(n,s);for(let i=0;i<s;i++)A(n,e.codePointAt(i))},st=Dt&&Dt.encodeInto?wi:mi,Xt=(n,t)=>{const e=n.cbuf.length,s=n.cpos,i=me(e-s,t.length),r=t.length-i;n.cbuf.set(t.subarray(0,i),s),n.cpos+=i,r>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(et(e*2,r)),n.cbuf.set(t.subarray(i)),n.cpos=r)},C=(n,t)=>{p(n,t.byteLength),Xt(n,t)},Ee=(n,t)=>{gi(n,t);const e=new DataView(n.cbuf.buffer,n.cpos,t);return n.cpos+=t,e},yi=(n,t)=>Ee(n,4).setFloat32(0,t,!1),ki=(n,t)=>Ee(n,8).setFloat64(0,t,!1),bi=(n,t)=>Ee(n,8).setBigInt64(0,t,!1),mn=new DataView(new ArrayBuffer(4)),_i=n=>(mn.setFloat32(0,n),mn.getFloat32(0)===n),xt=(n,t)=>{switch(typeof t){case"string":A(n,119),st(n,t);break;case"number":fi(t)&&Kt(t)<=di?(A(n,125),Ce(n,t)):_i(t)?(A(n,124),yi(n,t)):(A(n,123),ki(n,t));break;case"bigint":A(n,122),bi(n,t);break;case"object":if(t===null)A(n,126);else if(js(t)){A(n,117),p(n,t.length);for(let e=0;e<t.length;e++)xt(n,t[e])}else if(t instanceof Uint8Array)A(n,116),C(n,t);else{A(n,118);const e=Object.keys(t);p(n,e.length);for(let s=0;s<e.length;s++){const i=e[s];st(n,i),xt(n,t[i])}}break;case"boolean":A(n,t?120:121);break;default:A(n,127)}};class yn extends Lt{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&p(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const kn=n=>{n.count>0&&(Ce(n.encoder,n.count===1?n.s:-n.s),n.count>1&&p(n.encoder,n.count-2))};class Jt{constructor(){this.encoder=new Lt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(kn(this),this.count=1,this.s=t)}toUint8Array(){return kn(this),S(this.encoder)}}const bn=n=>{if(n.count>0){const t=n.diff*2+(n.count===1?0:1);Ce(n.encoder,t),n.count>1&&p(n.encoder,n.count-2)}};class Ae{constructor(){this.encoder=new Lt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(bn(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return bn(this),S(this.encoder)}}class Si{constructor(){this.sarr=[],this.s="",this.lensE=new Jt}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 Lt;return this.sarr.push(this.s),this.s="",st(t,this.sarr.join("")),Xt(t,this.lensE.toUint8Array()),S(t)}}const dt=n=>new Error(n),V=()=>{throw dt("Method unimplemented")},H=()=>{throw dt("Unexpected case")},_n=dt("Unexpected end of array"),Sn=dt("Integer out of Range");class Gt{constructor(t){this.arr=t,this.pos=0}}const z=n=>new Gt(n),Ci=n=>n.pos!==n.arr.length,Di=(n,t)=>{const e=Me(n.arr.buffer,n.pos+n.arr.byteOffset,t);return n.pos+=t,e},M=n=>Di(n,w(n)),ft=n=>n.arr[n.pos++],w=n=>{let t=0,e=1;const s=n.arr.length;for(;n.pos<s;){const i=n.arr[n.pos++];if(t=t+(i&nt)*e,e*=128,i<v)return t;if(t>wn)throw Sn}throw _n},Ie=n=>{let t=n.arr[n.pos++],e=t&be,s=64;const i=(t&Y)>0?-1:1;if(!(t&v))return i*e;const r=n.arr.length;for(;n.pos<r;){if(t=n.arr[n.pos++],e=e+(t&nt)*s,s*=128,t<v)return i*e;if(e>wn)throw Sn}throw _n},q=Et?n=>Et.decode(M(n)):n=>{let t=w(n);if(t===0)return"";{let e=String.fromCodePoint(ft(n));if(--t<100)for(;t--;)e+=String.fromCodePoint(ft(n));else for(;t>0;){const s=t<1e4?t:1e4,i=n.arr.subarray(n.pos,n.pos+s);n.pos+=s,e+=String.fromCodePoint.apply(null,i),t-=s}return decodeURIComponent(escape(e))}},Le=(n,t)=>{const e=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,t);return n.pos+=t,e},Ei=[n=>{},n=>null,Ie,n=>Le(n,4).getFloat32(0,!1),n=>Le(n,8).getFloat64(0,!1),n=>Le(n,8).getBigInt64(0,!1),n=>!1,n=>!0,q,n=>{const t=w(n),e={};for(let s=0;s<t;s++){const i=q(n);e[i]=Mt(n)}return e},n=>{const t=w(n),e=[];for(let s=0;s<t;s++)e.push(Mt(n));return e},M],Mt=n=>Ei[127-ft(n)](n);class Cn extends Gt{constructor(t,e){super(t),this.reader=e,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Ci(this)?this.count=w(this)+1:this.count=-1),this.count--,this.s}}class Wt extends Gt{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Ie(this);const t=fn(this.s);this.count=1,t&&(this.s=-this.s,this.count=w(this)+2)}return this.count--,this.s}}class xe extends Gt{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=Ie(this),e=t&1;this.diff=K(t/2),this.count=1,e&&(this.count=w(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Ai{constructor(t){this.decoder=new Wt(t),this.str=q(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 Dn=n=>new Uint8Array(n),Me=(n,t,e)=>new Uint8Array(n,t,e),Ii=n=>new Uint8Array(n),Li=n=>{let t="";for(let e=0;e<n.byteLength;e++)t+=Ks(n[e]);return btoa(t)},xi=n=>Buffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),Mi=n=>{const t=atob(n),e=Dn(t.length);for(let s=0;s<t.length;s++)e[s]=t.charCodeAt(s);return e},Ui=n=>{const t=Buffer.from(n,"base64");return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)},vi=un?Li:xi,Oi=un?Mi:Ui,Ti=n=>{const t=Dn(n.byteLength);return t.set(n),t},En=new Map;class Ri{constructor(t){this.room=t,this.onmessage=null,this._onChange=e=>e.key===t&&this.onmessage!==null&&this.onmessage({data:Oi(e.newValue||"")}),Qs(this._onChange)}postMessage(t){hn.setItem(this.room,vi(Ii(t)))}close(){Zs(this._onChange)}}const Ni=typeof BroadcastChannel>"u"?Ri:BroadcastChannel,Ue=n=>j(En,n,()=>{const t=tt(),e=new Ni(n);return e.onmessage=s=>t.forEach(i=>i(s.data,"broadcastchannel")),{bc:e,subs:t}}),Vi=(n,t)=>(Ue(n).subs.add(t),t),Hi=(n,t)=>{const e=Ue(n),s=e.subs.delete(t);return s&&e.subs.size===0&&(e.bc.close(),En.delete(n)),s},gt=(n,t,e=null)=>{const s=Ue(n);s.bc.postMessage(t),s.subs.forEach(i=>i(t,e))},it=Date.now;class ve{constructor(){this._observers=_()}on(t,e){j(this._observers,t,tt).add(e)}once(t,e){const s=(...i)=>{this.off(t,s),e(...i)};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 W((this._observers.get(t)||_()).values()).forEach(s=>s(...e))}destroy(){this._observers=_()}}const Bi=crypto.getRandomValues.bind(crypto),An=()=>Bi(new Uint32Array(1))[0],Fi=[1e7]+-1e3+-4e3+-8e3+-1e11,$i=()=>Fi.replace(/[018]/g,n=>(n^An()&15>>n/4).toString(16)),In=n=>new Promise(n);Promise.all.bind(Promise);class ji{constructor(t,e){this.left=t,this.right=e}}const X=(n,t)=>new ji(n,t);typeof DOMParser<"u"&&new DOMParser;const Ki=n=>Bs(n,(t,e)=>`${e}:${t};`).join(""),J=Symbol,Ln=J(),xn=J(),Yi=J(),Xi=J(),Ji=J(),Mn=J(),Gi=J(),Un=J(),Wi=J(),zi=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},qi={[Ln]:X("font-weight","bold"),[xn]:X("font-weight","normal"),[Yi]:X("color","blue"),[Ji]:X("color","green"),[Xi]:X("color","grey"),[Mn]:X("color","red"),[Gi]:X("color","purple"),[Un]:X("color","orange"),[Wi]:X("color","black")},Qi=ai?n=>{const t=[],e=[],s=_();let i=[],r=0;for(;r<n.length;r++){const o=n[r],l=qi[o];if(l!==void 0)s.set(l.left,l.right);else if(o.constructor===String||o.constructor===Number){const c=Ki(s);r>0||c.length>0?(t.push("%c"+o),e.push(c)):t.push(o)}else break}for(r>0&&(i=e,i.unshift(t.join("")));r<n.length;r++){const o=n[r];o instanceof Symbol||i.push(o)}return i}:zi,Zi=(...n)=>{console.log(...Qi(n)),Pi.forEach(t=>t.print(n))},Pi=tt(),vn=n=>({[Symbol.iterator](){return this},next:n}),tr=(n,t)=>vn(()=>{let e;do e=n.next();while(!e.done&&!t(e.value));return e}),Oe=(n,t)=>vn(()=>{const{done:e,value:s}=n.next();return{done:e,value:e?void 0:t(s)}});class Te{constructor(t,e){this.clock=t,this.len=e}}class Ut{constructor(){this.clients=new Map}}const On=(n,t,e)=>t.clients.forEach((s,i)=>{const r=n.doc.store.clients.get(i);for(let o=0;o<s.length;o++){const l=s[o];Qn(n,r,l.clock,l.len,e)}}),er=(n,t)=>{let e=0,s=n.length-1;for(;e<=s;){const i=K((e+s)/2),r=n[i],o=r.clock;if(o<=t){if(t<o+r.len)return i;e=i+1}else s=i-1}return null},Tn=(n,t)=>{const e=n.clients.get(t.client);return e!==void 0&&er(e,t.clock)!==null},Re=n=>{n.clients.forEach(t=>{t.sort((i,r)=>i.clock-r.clock);let e,s;for(e=1,s=1;e<t.length;e++){const i=t[s-1],r=t[e];i.clock+i.len>=r.clock?i.len=et(i.len,r.clock+r.len-i.clock):(s<e&&(t[s]=r),s++)}t.length=s})},nr=n=>{const t=new Ut;for(let e=0;e<n.length;e++)n[e].clients.forEach((s,i)=>{if(!t.clients.has(i)){const r=s.slice();for(let o=e+1;o<n.length;o++)$s(r,n[o].clients.get(i)||[]);t.clients.set(i,r)}});return Re(t),t},zt=(n,t,e,s)=>{j(n.clients,t,()=>[]).push(new Te(e,s))},sr=()=>new Ut,ir=n=>{const t=sr();return n.clients.forEach((e,s)=>{const i=[];for(let r=0;r<e.length;r++){const o=e[r];if(o.deleted){const l=o.id.clock;let c=o.length;if(r+1<e.length)for(let a=e[r+1];r+1<e.length&&a.deleted;a=e[++r+1])c+=a.length;i.push(new Te(l,c))}}i.length>0&&t.clients.set(s,i)}),t},pt=(n,t)=>{p(n.restEncoder,t.clients.size),W(t.clients.entries()).sort((e,s)=>s[0]-e[0]).forEach(([e,s])=>{n.resetDsCurVal(),p(n.restEncoder,e);const i=s.length;p(n.restEncoder,i);for(let r=0;r<i;r++){const o=s[r];n.writeDsClock(o.clock),n.writeDsLen(o.len)}})},Ne=n=>{const t=new Ut,e=w(n.restDecoder);for(let s=0;s<e;s++){n.resetDsCurVal();const i=w(n.restDecoder),r=w(n.restDecoder);if(r>0){const o=j(t.clients,i,()=>[]);for(let l=0;l<r;l++)o.push(new Te(n.readDsClock(),n.readDsLen()))}}return t},Rn=(n,t,e)=>{const s=new Ut,i=w(n.restDecoder);for(let r=0;r<i;r++){n.resetDsCurVal();const o=w(n.restDecoder),l=w(n.restDecoder),c=e.clients.get(o)||[],a=I(e,o);for(let h=0;h<l;h++){const u=n.readDsClock(),d=u+n.readDsLen();if(u<a){a<d&&zt(s,o,a,d-a);let f=B(c,u),g=c[f];for(!g.deleted&&g.id.clock<u&&(c.splice(f+1,0,ae(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,ae(t,g,d-g.id.clock)),g.delete(t))}else zt(s,o,u,d-u)}}if(s.clients.size>0){const r=new rt;return p(r.restEncoder,0),pt(r,s),r.toUint8Array()}return null},Nn=An;class wt extends ve{constructor({guid:t=$i(),collectionid:e=null,gc:s=!0,gcFilter:i=()=>!0,meta:r=null,autoLoad:o=!1,shouldLoad:l=!0}={}){super(),this.gc=s,this.gcFilter=i,this.clientID=Nn(),this.guid=t,this.collectionid=e,this.share=new Map,this.store=new Wn,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=o,this.meta=r,this.isLoaded=!1,this.isSynced=!1,this.whenLoaded=In(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const c=()=>In(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&&b(t.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(W(this.subdocs).map(t=>t.guid))}transact(t,e=null){return b(this,t,e)}get(t,e=L){const s=j(this.share,t,()=>{const r=new e;return r._integrate(this,null),r}),i=s.constructor;if(e!==L&&i!==e)if(i===L){const r=new e;r._map=s._map,s._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=r}),r._start=s._start;for(let o=r._start;o!==null;o=o.right)o.parent=r;return r._length=s._length,this.share.set(t,r),r._integrate(this,null),r}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,kt)}getText(t=""){return this.get(t,St)}getMap(t=""){return this.get(t,bt)}getXmlFragment(t=""){return this.get(t,ot)}toJSON(){const t={};return this.share.forEach((e,s)=>{t[s]=e.toJSON()}),t}destroy(){W(this.subdocs).forEach(e=>e.destroy());const t=this._item;if(t!==null){this._item=null;const e=t.content;e.doc=new wt({guid:this.guid,...e.opts,shouldLoad:!1}),e.doc._item=t,b(t.parent.doc,s=>{const i=e.doc;t.deleted||s.subdocsAdded.add(i),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 Vn{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return w(this.restDecoder)}readDsLen(){return w(this.restDecoder)}}class Hn extends Vn{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 ft(this.restDecoder)}readString(){return q(this.restDecoder)}readParentInfo(){return w(this.restDecoder)===1}readTypeRef(){return w(this.restDecoder)}readLen(){return w(this.restDecoder)}readAny(){return Mt(this.restDecoder)}readBuf(){return Ti(M(this.restDecoder))}readJSON(){return JSON.parse(q(this.restDecoder))}readKey(){return q(this.restDecoder)}}class rr{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 mt extends rr{constructor(t){super(t),this.keys=[],w(t),this.keyClockDecoder=new xe(M(t)),this.clientDecoder=new Wt(M(t)),this.leftClockDecoder=new xe(M(t)),this.rightClockDecoder=new xe(M(t)),this.infoDecoder=new Cn(M(t),ft),this.stringDecoder=new Ai(M(t)),this.parentInfoDecoder=new Cn(M(t),ft),this.typeRefDecoder=new Wt(M(t)),this.lenDecoder=new Wt(M(t))}readLeftID(){return new yt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new yt(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 Mt(this.restDecoder)}readBuf(){return M(this.restDecoder)}readJSON(){return Mt(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 Bn{constructor(){this.restEncoder=x()}toUint8Array(){return S(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){p(this.restEncoder,t)}writeDsLen(t){p(this.restEncoder,t)}}class vt extends Bn{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){Se(this.restEncoder,t)}writeString(t){st(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){xt(this.restEncoder,t)}writeBuf(t){C(this.restEncoder,t)}writeJSON(t){st(this.restEncoder,JSON.stringify(t))}writeKey(t){st(this.restEncoder,t)}}class Fn{constructor(){this.restEncoder=x(),this.dsCurrVal=0}toUint8Array(){return S(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const e=t-this.dsCurrVal;this.dsCurrVal=t,p(this.restEncoder,e)}writeDsLen(t){t===0&&H(),p(this.restEncoder,t-1),this.dsCurrVal+=t}}class rt extends Fn{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Ae,this.clientEncoder=new Jt,this.leftClockEncoder=new Ae,this.rightClockEncoder=new Ae,this.infoEncoder=new yn(Se),this.stringEncoder=new Si,this.parentInfoEncoder=new yn(Se),this.typeRefEncoder=new Jt,this.lenEncoder=new Jt}toUint8Array(){const t=x();return p(t,0),C(t,this.keyClockEncoder.toUint8Array()),C(t,this.clientEncoder.toUint8Array()),C(t,this.leftClockEncoder.toUint8Array()),C(t,this.rightClockEncoder.toUint8Array()),C(t,S(this.infoEncoder)),C(t,this.stringEncoder.toUint8Array()),C(t,S(this.parentInfoEncoder)),C(t,this.typeRefEncoder.toUint8Array()),C(t,this.lenEncoder.toUint8Array()),Xt(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){xt(this.restEncoder,t)}writeBuf(t){C(this.restEncoder,t)}writeJSON(t){xt(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 or=(n,t,e,s)=>{s=et(s,t[0].id.clock);const i=B(t,s);p(n.restEncoder,t.length-i),n.writeClient(e),p(n.restEncoder,s);const r=t[i];r.write(n,s-r.id.clock);for(let o=i+1;o<t.length;o++)t[o].write(n,0)},Ve=(n,t,e)=>{const s=new Map;e.forEach((i,r)=>{I(t,r)>i&&s.set(r,i)}),Qt(t).forEach((i,r)=>{e.has(r)||s.set(r,0)}),p(n.restEncoder,s.size),W(s.entries()).sort((i,r)=>r[0]-i[0]).forEach(([i,r])=>{or(n,t.clients.get(i),i,r)})},lr=(n,t)=>{const e=_(),s=w(n.restDecoder);for(let i=0;i<s;i++){const r=w(n.restDecoder),o=new Array(r),l=n.readClient();let c=w(n.restDecoder);e.set(l,{i:0,refs:o});for(let a=0;a<r;a++){const h=n.readInfo();switch(Yt&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 T(y(l,c),u),c+=u;break}default:{const u=(h&(Y|v))===0,d=new E(y(l,c),null,(h&v)===v?n.readLeftID():null,null,(h&Y)===Y?n.readRightID():null,u?n.readParentInfo()?t.get(n.readString()):n.readLeftID():null,u&&(h&It)===It?n.readString():null,_s(n,h));o[a]=d,c+=d.length}}}}return e},cr=(n,t,e)=>{const s=[];let i=W(e.keys()).sort((f,g)=>f-g);if(i.length===0)return null;const r=()=>{if(i.length===0)return null;let f=e.get(i[i.length-1]);for(;f.refs.length===f.i;)if(i.pop(),i.length>0)f=e.get(i[i.length-1]);else return null;return f};let o=r();if(o===null&&s.length===0)return null;const l=new Wn,c=new Map,a=(f,g)=>{const k=c.get(f);(k==null||k>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,k=e.get(g);k?(k.i--,l.clients.set(g,k.refs.slice(k.i)),e.delete(g),k.i=0,k.refs=[]):l.clients.set(g,[f]),i=i.filter(R=>R!==g)}s.length=0};for(;;){if(h.constructor!==T){const g=j(u,h.id.client,()=>I(t,h.id.client))-h.id.clock;if(g<0)s.push(h),a(h.id.client,h.id.clock-1),d();else{const k=h.getMissing(n,t);if(k!==null){s.push(h);const R=e.get(k)||{refs:[],i:0};if(R.refs.length===R.i)a(k,I(t,k)),d();else{h=R.refs[R.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=r(),o===null)break;h=o.refs[o.i++]}}if(l.clients.size>0){const f=new rt;return Ve(f,l,new Map),p(f.restEncoder,0),{missing:c,update:f.toUint8Array()}}return null},hr=(n,t)=>Ve(n,t.doc.store,t.beforeState),ar=(n,t,e,s=new mt(n))=>b(t,i=>{i.local=!1;let r=!1;const o=i.doc,l=o.store,c=lr(s,o),a=cr(i,l,c),h=l.pendingStructs;if(h){for(const[d,f]of h.missing)if(f<I(l,d)){r=!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=Pt([h.update,a.update])}}else l.pendingStructs=a;const u=Rn(s,i,l);if(l.pendingDs){const d=new mt(z(l.pendingDs));w(d.restDecoder);const f=Rn(d,i,l);u&&f?l.pendingDs=Pt([u,f]):l.pendingDs=u||f}else l.pendingDs=u;if(r){const d=l.pendingStructs.update;l.pendingStructs=null,$n(i.doc,d)}},e,!1),$n=(n,t,e,s=mt)=>{const i=z(t);ar(i,n,e,new s(i))},ur=(n,t,e)=>$n(n,t,e,Hn),dr=(n,t,e=new Map)=>{Ve(n,t.store,e),pt(n,ir(t.store))},fr=(n,t=new Uint8Array([0]),e=new rt)=>{const s=jn(t);dr(e,n,s);const i=[e.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(Lr(n.store.pendingStructs.update,t)),i.length>1){if(e.constructor===vt)return Ar(i.map((r,o)=>o===0?r:Mr(r)));if(e.constructor===rt)return Pt(i)}return i[0]},gr=(n,t)=>fr(n,t,new vt),pr=n=>{const t=new Map,e=w(n.restDecoder);for(let s=0;s<e;s++){const i=w(n.restDecoder),r=w(n.restDecoder);t.set(i,r)}return t},jn=n=>pr(new Vn(z(n))),Kn=(n,t)=>(p(n.restEncoder,t.size),W(t.entries()).sort((e,s)=>s[0]-e[0]).forEach(([e,s])=>{p(n.restEncoder,e),p(n.restEncoder,s)}),n),wr=(n,t)=>Kn(n,Qt(t.store)),mr=(n,t=new Fn)=>(n instanceof Map?Kn(t,n):wr(t,n),t.toUint8Array()),yr=n=>mr(n,new Bn);class kr{constructor(){this.l=[]}}const Yn=()=>new kr,Xn=(n,t)=>n.l.push(t),Jn=(n,t)=>{const e=n.l,s=e.length;n.l=e.filter(i=>t!==i),s===n.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Gn=(n,t,e)=>ge(n.l,[t,e]);class yt{constructor(t,e){this.client=t,this.clock=e}}const qt=(n,t)=>n===t||n!==null&&t!==null&&n.client===t.client&&n.clock===t.clock,y=(n,t)=>new yt(n,t),br=n=>{for(const[t,e]of n.doc.share.entries())if(e===n)return t;throw H()},Ot=(n,t)=>t===void 0?!n.deleted:t.sv.has(n.id.client)&&(t.sv.get(n.id.client)||0)>n.id.clock&&!Tn(t.ds,n.id),He=(n,t)=>{const e=j(n.meta,He,tt),s=n.doc.store;e.has(t)||(t.sv.forEach((i,r)=>{i<I(s,r)&&Q(n,y(r,i))}),On(n,t.ds,i=>{}),e.add(t))};class Wn{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Qt=n=>{const t=new Map;return n.clients.forEach((e,s)=>{const i=e[e.length-1];t.set(s,i.id.clock+i.length)}),t},I=(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},zn=(n,t)=>{let e=n.clients.get(t.id.client);if(e===void 0)e=[],n.clients.set(t.id.client,e);else{const s=e[e.length-1];if(s.id.clock+s.length!==t.id.clock)throw H()}e.push(t)},B=(n,t)=>{let e=0,s=n.length-1,i=n[s],r=i.id.clock;if(r===t)return s;let o=K(t/(r+i.length-1)*s);for(;e<=s;){if(i=n[o],r=i.id.clock,r<=t){if(t<r+i.length)return o;e=o+1}else s=o-1;o=K((e+s)/2)}throw H()},Be=(n,t)=>{const e=n.clients.get(t.client);return e[B(e,t.clock)]},Fe=(n,t,e)=>{const s=B(t,e),i=t[s];return i.id.clock<e&&i instanceof E?(t.splice(s+1,0,ae(n,i,e-i.id.clock)),s+1):s},Q=(n,t)=>{const e=n.doc.store.clients.get(t.client);return e[Fe(n,e,t.clock)]},qn=(n,t,e)=>{const s=t.clients.get(e.client),i=B(s,e.clock),r=s[i];return e.clock!==r.id.clock+r.length-1&&r.constructor!==O&&s.splice(i+1,0,ae(n,r,e.clock-r.id.clock+1)),r},_r=(n,t,e)=>{const s=n.clients.get(t.id.client);s[B(s,t.id.clock)]=e},Qn=(n,t,e,s,i)=>{if(s===0)return;const r=e+s;let o=Fe(n,t,e),l;do l=t[o++],r<l.id.clock+l.length&&Fe(n,t,r),i(l);while(o<t.length&&t[o].id.clock<r)};class Sr{constructor(t,e,s){this.doc=t,this.deleteSet=new Ut,this.beforeState=Qt(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 Zn=(n,t)=>t.deleteSet.clients.size===0&&!Fs(t.afterState,(e,s)=>t.beforeState.get(s)!==e)?!1:(Re(t.deleteSet),hr(n,t),pt(n,t.deleteSet),!0),Pn=(n,t,e)=>{const s=t._item;(s===null||s.id.clock<(n.beforeState.get(s.id.client)||0)&&!s.deleted)&&j(n.changed,t,tt).add(e)},Zt=(n,t)=>{const e=n[t-1],s=n[t];e.deleted===s.deleted&&e.constructor===s.constructor&&e.mergeWith(s)&&(n.splice(t,1),s instanceof E&&s.parentSub!==null&&s.parent._map.get(s.parentSub)===s&&s.parent._map.set(s.parentSub,e))},Cr=(n,t,e)=>{for(const[s,i]of n.clients.entries()){const r=t.clients.get(s);for(let o=i.length-1;o>=0;o--){const l=i[o],c=l.clock+l.len;for(let a=B(r,l.clock),h=r[a];a<r.length&&h.id.clock<c;h=r[++a]){const u=r[a];if(l.clock+l.len<=u.id.clock)break;u instanceof E&&u.deleted&&!u.keep&&e(u)&&u.gc(t,!1)}}}},Dr=(n,t)=>{n.clients.forEach((e,s)=>{const i=t.clients.get(s);for(let r=e.length-1;r>=0;r--){const o=e[r],l=me(i.length-1,1+B(i,o.clock+o.len-1));for(let c=l,a=i[c];c>0&&a.id.clock>=o.clock;a=i[--c])Zt(i,c)}})},ts=(n,t)=>{if(t<n.length){const e=n[t],s=e.doc,i=s.store,r=e.deleteSet,o=e._mergeStructs;try{Re(r),e.afterState=Qt(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),Gn(a._dEH,c,e))})}),l.push(()=>s.emit("afterTransaction",[e,s])),ge(l,[]),e._needFormattingCleanup&&Kr(e)}finally{s.gc&&Cr(r,i,s.gcFilter),Dr(r,i),e.afterState.forEach((h,u)=>{const d=e.beforeState.get(u)||0;if(d!==h){const f=i.clients.get(u),g=et(B(f,d),1);for(let k=f.length-1;k>=g;k--)Zt(f,k)}});for(let h=0;h<o.length;h++){const{client:u,clock:d}=o[h].id,f=i.clients.get(u),g=B(f,d);g+1<f.length&&Zt(f,g+1),g>0&&Zt(f,g)}if(!e.local&&e.afterState.get(s.clientID)!==e.beforeState.get(s.clientID)&&(Zi(Un,Ln,"[yjs] ",xn,Mn,"Changed the client-id because another client seems to be using it."),s.clientID=Nn()),s.emit("afterTransactionCleanup",[e,s]),s._observers.has("update")){const h=new vt;Zn(h,e)&&s.emit("update",[h.toUint8Array(),e.origin,s,e])}if(s._observers.has("updateV2")){const h=new rt;Zn(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])):ts(n,t+1)}}},b=(n,t,e=null,s=!0)=>{const i=n._transactionCleanups;let r=!1,o=null;n._transaction===null&&(r=!0,n._transaction=new Sr(n,e,s),i.push(n._transaction),i.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{o=t(n._transaction)}finally{if(r){const l=n._transaction===i[0];n._transaction=null,l&&ts(i,0)}}return o};function*Er(n){const t=w(n.restDecoder);for(let e=0;e<t;e++){const s=w(n.restDecoder),i=n.readClient();let r=w(n.restDecoder);for(let o=0;o<s;o++){const l=n.readInfo();if(l===10){const c=w(n.restDecoder);yield new T(y(i,r),c),r+=c}else if(Yt&l){const c=(l&(Y|v))===0,a=new E(y(i,r),null,(l&v)===v?n.readLeftID():null,null,(l&Y)===Y?n.readRightID():null,c?n.readParentInfo()?n.readString():n.readLeftID():null,c&&(l&It)===It?n.readString():null,_s(n,l));yield a,r+=a.length}else{const c=n.readLen();yield new O(y(i,r),c),r+=c}}}}class $e{constructor(t,e){this.gen=Er(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===T);return this.curr}}class je{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const Ar=n=>Pt(n,Hn,vt),Ir=(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===T){const{client:e,clock:s}=n.id;return new T(y(e,s+t),n.length-t)}else{const e=n,{client:s,clock:i}=e.id;return new E(y(s,i+t),null,y(s,i+t-1),null,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t))}},Pt=(n,t=mt,e=rt)=>{if(n.length===1)return n[0];const s=n.map(h=>new t(z(h)));let i=s.map(h=>new $e(h,!0)),r=null;const o=new e,l=new je(o);for(;i=i.filter(d=>d.curr!==null),i.sort((d,f)=>{if(d.curr.id.client===f.curr.id.client){const g=d.curr.id.clock-f.curr.id.clock;return g===0?d.curr.constructor===f.curr.constructor?0:d.curr.constructor===T?1:-1:g}else return f.curr.id.client-d.curr.id.client}),i.length!==0;){const h=i[0],u=h.curr.id.client;if(r!==null){let d=h.curr,f=!1;for(;d!==null&&d.id.clock+d.length<=r.struct.id.clock+r.struct.length&&d.id.client>=r.struct.id.client;)d=h.next(),f=!0;if(d===null||d.id.client!==u||f&&d.id.clock>r.struct.id.clock+r.struct.length)continue;if(u!==r.struct.id.client)Z(l,r.struct,r.offset),r={struct:d,offset:0},h.next();else if(r.struct.id.clock+r.struct.length<d.id.clock)if(r.struct.constructor===T)r.struct.length=d.id.clock+d.length-r.struct.id.clock;else{Z(l,r.struct,r.offset);const g=d.id.clock-r.struct.id.clock-r.struct.length;r={struct:new T(y(u,r.struct.id.clock+r.struct.length),g),offset:0}}else{const g=r.struct.id.clock+r.struct.length-d.id.clock;g>0&&(r.struct.constructor===T?r.struct.length-=g:d=Ir(d,g)),r.struct.mergeWith(d)||(Z(l,r.struct,r.offset),r={struct:d,offset:0},h.next())}}else r={struct:h.curr,offset:0},h.next();for(let d=h.curr;d!==null&&d.id.client===u&&d.id.clock===r.struct.id.clock+r.struct.length&&d.constructor!==T;d=h.next())Z(l,r.struct,r.offset),r={struct:d,offset:0}}r!==null&&(Z(l,r.struct,r.offset),r=null),Ke(l);const c=s.map(h=>Ne(h)),a=nr(c);return pt(o,a),o.toUint8Array()},Lr=(n,t,e=mt,s=rt)=>{const i=jn(t),r=new s,o=new je(r),l=new e(z(n)),c=new $e(l,!1);for(;c.curr;){const h=c.curr,u=h.id.client,d=i.get(u)||0;if(c.curr.constructor===T){c.next();continue}if(h.id.clock+h.length>d)for(Z(o,h,et(d-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===u;)Z(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()}Ke(o);const a=Ne(l);return pt(r,a),r.toUint8Array()},es=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:S(n.encoder.restEncoder)}),n.encoder.restEncoder=x(),n.written=0)},Z=(n,t,e)=>{n.written>0&&n.currClient!==t.id.client&&es(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++},Ke=n=>{es(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),Xt(t,s.restEncoder)}},xr=(n,t,e,s)=>{const i=new e(z(n)),r=new $e(i,!1),o=new s,l=new je(o);for(let a=r.curr;a!==null;a=r.next())Z(l,t(a),0);Ke(l);const c=Ne(i);return pt(o,c),o.toUint8Array()},Mr=n=>xr(n,oi,mt,vt);class te{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=Ur(this.currentTarget,this.target))}deletes(t){return Tn(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){const t=new Map,e=this.target;this.transaction.changed.get(e).forEach(i=>{if(i!==null){const r=e._map.get(i);let o,l;if(this.adds(r)){let c=r.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(r))if(c!==null&&this.deletes(c))o="delete",l=de(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=de(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(r))o="delete",l=de(r.content.getContent());else return;t.set(i,{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){const e=this.target,s=tt(),i=tt(),r=[];if(t={added:s,deleted:i,delta:r,keys:this.keys},this.transaction.changed.get(e).has(null)){let l=null;const c=()=>{l&&r.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,i.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 Ur=(n,t)=>{const e=[];for(;t._item!==null&&t!==n;){if(t._item.parentSub!==null)e.unshift(t._item.parentSub);else{let s=0,i=t._item.parent._start;for(;i!==t._item&&i!==null;)i.deleted||s++,i=i.right;e.unshift(s)}t=t._item.parent}return e},ns=80;let Ye=0;class vr{constructor(t,e){t.marker=!0,this.p=t,this.index=e,this.timestamp=Ye++}}const Or=n=>{n.timestamp=Ye++},ss=(n,t,e)=>{n.p.marker=!1,n.p=t,t.marker=!0,n.index=e,n.timestamp=Ye++},Tr=(n,t,e)=>{if(n.length>=ns){const s=n.reduce((i,r)=>i.timestamp<r.timestamp?i:r);return ss(s,t,e),s}else{const s=new vr(t,e);return n.push(s),s}},ee=(n,t)=>{if(n._start===null||t===0||n._searchMarker===null)return null;const e=n._searchMarker.length===0?null:n._searchMarker.reduce((r,o)=>Kt(t-r.index)<Kt(t-o.index)?r:o);let s=n._start,i=0;for(e!==null&&(s=e.p,i=e.index,Or(e));s.right!==null&&i<t;){if(!s.deleted&&s.countable){if(t<i+s.length)break;i+=s.length}s=s.right}for(;s.left!==null&&i>t;)s=s.left,!s.deleted&&s.countable&&(i-=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&&(i-=s.length);return e!==null&&Kt(e.index-i)<s.parent.length/ns?(ss(e,s,i),e):Tr(n._searchMarker,s,i)},Tt=(n,t,e)=>{for(let s=n.length-1;s>=0;s--){const i=n[s];if(e>0){let r=i.p;for(r.marker=!1;r&&(r.deleted||!r.countable);)r=r.left,r&&!r.deleted&&r.countable&&(i.index-=r.length);if(r===null||r.marker===!0){n.splice(s,1);continue}i.p=r,r.marker=!0}(t<i.index||e>0&&t===i.index)&&(i.index=et(t,i.index+e))}},ne=(n,t,e)=>{const s=n,i=t.changedParentTypes;for(;j(i,n,()=>[]).push(e),n._item!==null;)n=n._item.parent;Gn(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=Yn(),this._dEH=Yn(),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){Xn(this._eH,t)}observeDeep(t){Xn(this._dEH,t)}unobserve(t){Jn(this._eH,t)}unobserveDeep(t){Jn(this._dEH,t)}toJSON(){}}const is=(n,t,e)=>{t<0&&(t=n._length+t),e<0&&(e=n._length+e);let s=e-t;const i=[];let r=n._start;for(;r!==null&&s>0;){if(r.countable&&!r.deleted){const o=r.content.getContent();if(o.length<=t)t-=o.length;else{for(let l=t;l<o.length&&s>0;l++)i.push(o[l]),s--;t=0}}r=r.right}return i},rs=n=>{const t=[];let e=n._start;for(;e!==null;){if(e.countable&&!e.deleted){const s=e.content.getContent();for(let i=0;i<s.length;i++)t.push(s[i])}e=e.right}return t},Rt=(n,t)=>{let e=0,s=n._start;for(;s!==null;){if(s.countable&&!s.deleted){const i=s.content.getContent();for(let r=0;r<i.length;r++)t(i[r],e++,n)}s=s.right}},os=(n,t)=>{const e=[];return Rt(n,(s,i)=>{e.push(t(s,i,n))}),e},Rr=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 i=e[s++];return e.length<=s&&(e=null),{done:!1,value:i}}}},ls=(n,t)=>{const e=ee(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}},se=(n,t,e,s)=>{let i=e;const r=n.doc,o=r.clientID,l=r.store,c=e===null?t._start:e.right;let a=[];const h=()=>{a.length>0&&(i=new E(y(o,I(l,o)),i,i&&i.lastId,c,c&&c.id,t,null,new ct(a)),i.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:i=new E(y(o,I(l,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Vt(new Uint8Array(u))),i.integrate(n,0);break;case wt:i=new E(y(o,I(l,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Bt(u)),i.integrate(n,0);break;default:if(u instanceof L)i=new E(y(o,I(l,o)),i,i&&i.lastId,c,c&&c.id,t,null,new G(u)),i.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},cs=dt("Length exceeded!"),hs=(n,t,e,s)=>{if(e>t._length)throw cs;if(e===0)return t._searchMarker&&Tt(t._searchMarker,e,s.length),se(n,t,null,s);const i=e,r=ee(t,e);let o=t._start;for(r!==null&&(o=r.p,e-=r.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&&Q(n,y(o.id.client,o.id.clock+e));break}e-=o.length}return t._searchMarker&&Tt(t._searchMarker,i,s.length),se(n,t,o,s)},Nr=(n,t,e)=>{let i=(t._searchMarker||[]).reduce((r,o)=>o.index>r.index?o:r,{index:0,p:t._start}).p;if(i)for(;i.right;)i=i.right;return se(n,t,i,e)},as=(n,t,e,s)=>{if(s===0)return;const i=e,r=s,o=ee(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&&Q(n,y(l.id.client,l.id.clock+e)),e-=l.length);for(;s>0&&l!==null;)l.deleted||(s<l.length&&Q(n,y(l.id.client,l.id.clock+s)),l.delete(n),s-=l.length),l=l.right;if(s>0)throw cs;t._searchMarker&&Tt(t._searchMarker,i,-r+s)},ie=(n,t,e)=>{const s=t._map.get(e);s!==void 0&&s.delete(n)},Xe=(n,t,e,s)=>{const i=t._map.get(e)||null,r=n.doc,o=r.clientID;let l;if(s==null)l=new ct([s]);else switch(s.constructor){case Number:case Object:case Boolean:case Array:case String:l=new ct([s]);break;case Uint8Array:l=new Vt(s);break;case wt:l=new Bt(s);break;default:if(s instanceof L)l=new G(s);else throw new Error("Unexpected content type")}new E(y(o,I(r.store,o)),i,i&&i.lastId,null,null,t,e,l).integrate(n,0)},Je=(n,t)=>{const e=n._map.get(t);return e!==void 0&&!e.deleted?e.content.getContent()[e.length-1]:void 0},us=n=>{const t={};return n._map.forEach((e,s)=>{e.deleted||(t[s]=e.content.getContent()[e.length-1])}),t},ds=(n,t)=>{const e=n._map.get(t);return e!==void 0&&!e.deleted},re=n=>tr(n.entries(),t=>!t[1].deleted);class Vr extends te{constructor(t,e){super(t,e),this._transaction=e}}class kt extends L{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const e=new kt;return e.push(t),e}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new kt}clone(){const t=new kt;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),ne(this,t,new Vr(this,t))}insert(t,e){this.doc!==null?b(this.doc,s=>{hs(s,this,t,e)}):this._prelimContent.splice(t,0,...e)}push(t){this.doc!==null?b(this.doc,e=>{Nr(e,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,e=1){this.doc!==null?b(this.doc,s=>{as(s,this,t,e)}):this._prelimContent.splice(t,e)}get(t){return ls(this,t)}toArray(){return rs(this)}slice(t=0,e=this.length){return is(this,t,e)}toJSON(){return this.map(t=>t instanceof L?t.toJSON():t)}map(t){return os(this,t)}forEach(t){Rt(this,t)}[Symbol.iterator](){return Rr(this)}_write(t){t.writeTypeRef(lo)}}const Hr=n=>new kt;class Br extends te{constructor(t,e,s){super(t,e),this.keysChanged=s}}class bt 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,i)=>{this.set(i,s)}),this._prelimContent=null}_copy(){return new bt}clone(){const t=new bt;return this.forEach((e,s)=>{t.set(s,e instanceof L?e.clone():e)}),t}_callObserver(t,e){ne(this,t,new Br(this,t,e))}toJSON(){const t={};return this._map.forEach((e,s)=>{if(!e.deleted){const i=e.content.getContent()[e.length-1];t[s]=i instanceof L?i.toJSON():i}}),t}get size(){return[...re(this._map)].length}keys(){return Oe(re(this._map),t=>t[0])}values(){return Oe(re(this._map),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Oe(re(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?b(this.doc,e=>{ie(e,this,t)}):this._prelimContent.delete(t)}set(t,e){return this.doc!==null?b(this.doc,s=>{Xe(s,this,t,e)}):this._prelimContent.set(t,e),e}get(t){return Je(this,t)}has(t){return ds(this,t)}clear(){this.doc!==null?b(this.doc,t=>{this.forEach(function(e,s,i){ie(t,i,s)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(co)}}const Fr=n=>new bt,P=(n,t)=>n===t||typeof n=="object"&&typeof t=="object"&&n&&t&&ri(n,t);class Ge{constructor(t,e,s,i){this.left=t,this.right=e,this.index=s,this.currentAttributes=i}forward(){switch(this.right===null&&H(),this.right.content.constructor){case D:this.right.deleted||_t(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 fs=(n,t,e)=>{for(;t.right!==null&&e>0;){switch(t.right.content.constructor){case D:t.right.deleted||_t(t.currentAttributes,t.right.content);break;default:t.right.deleted||(e<t.right.length&&Q(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},oe=(n,t,e)=>{const s=new Map,i=ee(t,e);if(i){const r=new Ge(i.p.left,i.p,i.index,s);return fs(n,r,e-i.index)}else{const r=new Ge(null,t._start,0,s);return fs(n,r,e)}},gs=(n,t,e,s)=>{for(;e.right!==null&&(e.right.deleted===!0||e.right.content.constructor===D&&P(s.get(e.right.content.key),e.right.content.value));)e.right.deleted||s.delete(e.right.content.key),e.forward();const i=n.doc,r=i.clientID;s.forEach((o,l)=>{const c=e.left,a=e.right,h=new E(y(r,I(i.store,r)),c,c&&c.lastId,a,a&&a.id,t,null,new D(l,o));h.integrate(n,0),e.right=h,e.forward()})},_t=(n,t)=>{const{key:e,value:s}=t;s===null?n.delete(e):n.set(e,s)},ps=(n,t)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===D&&P(t[n.right.content.key]||null,n.right.content.value)))break;n.forward()}},ws=(n,t,e,s)=>{const i=n.doc,r=i.clientID,o=new Map;for(const l in s){const c=s[l],a=e.currentAttributes.get(l)||null;if(!P(a,c)){o.set(l,a);const{left:h,right:u}=e;e.right=new E(y(r,I(i.store,r)),h,h&&h.lastId,u,u&&u.id,t,null,new D(l,c)),e.right.integrate(n,0),e.forward()}}return o},We=(n,t,e,s,i)=>{e.currentAttributes.forEach((d,f)=>{i[f]===void 0&&(i[f]=null)});const r=n.doc,o=r.clientID;ps(e,i);const l=ws(n,t,e,i),c=s.constructor===String?new F(s):s instanceof L?new G(s):new lt(s);let{left:a,right:h,index:u}=e;t._searchMarker&&Tt(t._searchMarker,e.index,c.getLength()),h=new E(y(o,I(r.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(),gs(n,t,e,l)},ms=(n,t,e,s,i)=>{const r=n.doc,o=r.clientID;ps(e,i);const l=ws(n,t,e,i);t:for(;e.right!==null&&(s>0||l.size>0&&(e.right.deleted||e.right.content.constructor===D));){if(!e.right.deleted)switch(e.right.content.constructor){case D:{const{key:c,value:a}=e.right.content,h=i[c];if(h!==void 0){if(P(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&&Q(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,I(r.store,o)),e.left,e.left&&e.left.lastId,e.right,e.right&&e.right.id,t,null,new F(c)),e.right.integrate(n,0),e.forward()}gs(n,t,e,l)},ys=(n,t,e,s,i)=>{let r=t;const o=_();for(;r&&(!r.countable||r.deleted);){if(!r.deleted&&r.content.constructor===D){const a=r.content;o.set(a.key,a)}r=r.right}let l=0,c=!1;for(;t!==r;){if(e===t&&(c=!0),!t.deleted){const a=t.content;switch(a.constructor){case D:{const{key:h,value:u}=a,d=s.get(h)||null;(o.get(h)!==a||d===u)&&(t.delete(n),l++,!c&&(i.get(h)||null)===u&&d!==u&&(d===null?i.delete(h):i.set(h,d))),!c&&!t.deleted&&_t(i,a);break}}}t=t.right}return l},$r=(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===D){const s=t.content.key;e.has(s)?t.delete(n):e.add(s)}t=t.left}},jr=n=>{let t=0;return b(n.doc,e=>{let s=n._start,i=n._start,r=_();const o=$(r);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case D:_t(o,i.content);break;default:t+=ys(e,s,i,r,o),r=$(o),s=i;break}i=i.right}}),t},Kr=n=>{const t=new Set,e=n.doc;for(const[s,i]of n.afterState.entries()){const r=n.beforeState.get(s)||0;i!==r&&Qn(n,e.store.clients.get(s),r,i,o=>{!o.deleted&&o.content.constructor===D&&o.constructor!==O&&t.add(o.parent)})}b(e,s=>{On(n,n.deleteSet,i=>{if(i instanceof O||!i.parent._hasFormatting||t.has(i.parent))return;const r=i.parent;i.content.constructor===D?t.add(r):$r(s,i)});for(const i of t)jr(i)})},ks=(n,t,e)=>{const s=e,i=$(t.currentAttributes),r=t.right;for(;e>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case G:case lt:case F:e<t.right.length&&Q(n,y(t.right.id.client,t.right.id.clock+e)),e-=t.right.length,t.right.delete(n);break}t.forward()}r&&ys(n,r,t.right,i,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&Tt(o._searchMarker,t.index,-s+e),t};class Yr extends te{constructor(t,e,s){super(t,e),this.childListChanged=!1,this.keysChanged=new Set,s.forEach(i=>{i===null?this.childListChanged=!0:this.keysChanged.add(i)})}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=[];b(t,s=>{const i=new Map,r=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},i.size>0&&(f.attributes={},i.forEach((g,k)=>{g!==null&&(f.attributes[k]=g)}))),a="";break;case"retain":h>0&&(f={retain:h},si(c)||(f.attributes=Ps({},c))),h=0;break}f&&e.push(f),l=null}};for(;o!==null;){switch(o.content.constructor){case G:case lt: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 F: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 D:{const{key:f,value:g}=o.content;if(this.adds(o)){if(!this.deletes(o)){const k=i.get(f)||null;P(k,g)?g!==null&&o.delete(s):(l==="retain"&&d(),P(g,r.get(f)||null)?delete c[f]:c[f]=g)}}else if(this.deletes(o)){r.set(f,g);const k=i.get(f)||null;P(k,g)||(l==="retain"&&d(),c[f]=k)}else if(!o.deleted){r.set(f,g);const k=c[f];k!==void 0&&(P(k,g)?k!==null&&o.delete(s):(l==="retain"&&d(),g===null?delete c[f]:c[f]=g))}o.deleted||(l==="insert"&&d(),_t(i,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 St 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 St}clone(){const t=new St;return t.applyDelta(this.toDelta()),t}_callObserver(t,e){super._callObserver(t,e);const s=new Yr(this,t,e);ne(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===F&&(t+=e.content.str),e=e.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:e=!0}={}){this.doc!==null?b(this.doc,s=>{const i=new Ge(null,this._start,0,new Map);for(let r=0;r<t.length;r++){const o=t[r];if(o.insert!==void 0){const l=!e&&typeof o.insert=="string"&&r===t.length-1&&i.right===null&&o.insert.slice(-1)===`
3
- `?o.insert.slice(0,-1):o.insert;(typeof l!="string"||l.length>0)&&We(s,this,i,l,o.attributes||{})}else o.retain!==void 0?ms(s,this,i,o.retain,o.attributes||{}):o.delete!==void 0&&ks(s,i,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,e,s){const i=[],r=new Map,o=this.doc;let l="",c=this._start;function a(){if(l.length>0){const u={};let d=!1;r.forEach((g,k)=>{d=!0,u[k]=g});const f={insert:l};d&&(f.attributes=u),i.push(f),l=""}}const h=()=>{for(;c!==null;){if(Ot(c,t)||e!==void 0&&Ot(c,e))switch(c.content.constructor){case F:{const u=r.get("ychange");t!==void 0&&!Ot(c,t)?(u===void 0||u.user!==c.id.client||u.type!=="removed")&&(a(),r.set("ychange",s?s("removed",c.id):{type:"removed"})):e!==void 0&&!Ot(c,e)?(u===void 0||u.user!==c.id.client||u.type!=="added")&&(a(),r.set("ychange",s?s("added",c.id):{type:"added"})):u!==void 0&&(a(),r.delete("ychange")),l+=c.content.str;break}case G:case lt:{a();const u={insert:c.content.getContent()[0]};if(r.size>0){const d={};u.attributes=d,r.forEach((f,g)=>{d[g]=f})}i.push(u);break}case D:Ot(c,t)&&(a(),_t(r,c.content));break}c=c.right}a()};return t||e?b(o,u=>{t&&He(u,t),e&&He(u,e),h()},"cleanup"):h(),i}insert(t,e,s){if(e.length<=0)return;const i=this.doc;i!==null?b(i,r=>{const o=oe(r,this,t);s||(s={},o.currentAttributes.forEach((l,c)=>{s[c]=l})),We(r,this,o,e,s)}):this._pending.push(()=>this.insert(t,e,s))}insertEmbed(t,e,s={}){const i=this.doc;i!==null?b(i,r=>{const o=oe(r,this,t);We(r,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?b(s,i=>{ks(i,oe(i,this,t),e)}):this._pending.push(()=>this.delete(t,e))}format(t,e,s){if(e===0)return;const i=this.doc;i!==null?b(i,r=>{const o=oe(r,this,t);o.right!==null&&ms(r,this,o,e,s)}):this._pending.push(()=>this.format(t,e,s))}removeAttribute(t){this.doc!==null?b(this.doc,e=>{ie(e,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,e){this.doc!==null?b(this.doc,s=>{Xe(s,this,t,e)}):this._pending.push(()=>this.setAttribute(t,e))}getAttribute(t){return Je(this,t)}getAttributes(){return us(this)}_write(t){t.writeTypeRef(ho)}}const Xr=n=>new St;class ze{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===Nt||e.constructor===ot)&&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 ot 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 ot}clone(){const t=new ot;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 ze(this,t)}querySelector(t){t=t.toUpperCase();const s=new ze(this,i=>i.nodeName&&i.nodeName.toUpperCase()===t).next();return s.done?null:s.value}querySelectorAll(t){return t=t.toUpperCase(),W(new ze(this,e=>e.nodeName&&e.nodeName.toUpperCase()===t))}_callObserver(t,e){ne(this,t,new Wr(this,e,t))}toString(){return os(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,e={},s){const i=t.createDocumentFragment();return s!==void 0&&s._createAssociation(i,this),Rt(this,r=>{i.insertBefore(r.toDOM(t,e,s),null)}),i}insert(t,e){this.doc!==null?b(this.doc,s=>{hs(s,this,t,e)}):this._prelimContent.splice(t,0,...e)}insertAfter(t,e){if(this.doc!==null)b(this.doc,s=>{const i=t&&t instanceof L?t._item:t;se(s,this,i,e)});else{const s=this._prelimContent,i=t===null?0:s.findIndex(r=>r===t)+1;if(i===0&&t!==null)throw dt("Reference item not found");s.splice(i,0,...e)}}delete(t,e=1){this.doc!==null?b(this.doc,s=>{as(s,this,t,e)}):this._prelimContent.splice(t,e)}toArray(){return rs(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return ls(this,t)}slice(t=0,e=this.length){return is(this,t,e)}forEach(t){Rt(this,t)}_write(t){t.writeTypeRef(uo)}}const Jr=n=>new ot;class Nt extends ot{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,i)=>{this.setAttribute(i,s)}),this._prelimAttrs=null}_copy(){return new Nt(this.nodeName)}clone(){const t=new Nt(this.nodeName),e=this.getAttributes();return ei(e,(s,i)=>{typeof s=="string"&&t.setAttribute(i,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 i=s.length;for(let l=0;l<i;l++){const c=s[l];e.push(c+'="'+t[c]+'"')}const r=this.nodeName.toLocaleLowerCase(),o=e.length>0?" "+e.join(" "):"";return`<${r}${o}>${super.toString()}</${r}>`}removeAttribute(t){this.doc!==null?b(this.doc,e=>{ie(e,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,e){this.doc!==null?b(this.doc,s=>{Xe(s,this,t,e)}):this._prelimAttrs.set(t,e)}getAttribute(t){return Je(this,t)}hasAttribute(t){return ds(this,t)}getAttributes(){return us(this)}toDOM(t=document,e={},s){const i=t.createElement(this.nodeName),r=this.getAttributes();for(const o in r){const l=r[o];typeof l=="string"&&i.setAttribute(o,l)}return Rt(this,o=>{i.appendChild(o.toDOM(t,e,s))}),s!==void 0&&s._createAssociation(i,this),i}_write(t){t.writeTypeRef(ao),t.writeKey(this.nodeName)}}const Gr=n=>new Nt(n.readKey());class Wr extends te{constructor(t,e,s){super(t,s),this.childListChanged=!1,this.attributesChanged=new Set,e.forEach(i=>{i===null?this.childListChanged=!0:this.attributesChanged.add(i)})}}class le extends bt{constructor(t){super(),this.hookName=t}_copy(){return new le(this.hookName)}clone(){const t=new le(this.hookName);return this.forEach((e,s)=>{t.set(s,e)}),t}toDOM(t=document,e={},s){const i=e[this.hookName];let r;return i!==void 0?r=i.createDom(this):r=document.createElement(this.hookName),r.setAttribute("data-yjs-hook",this.hookName),s!==void 0&&s._createAssociation(r,this),r}_write(t){t.writeTypeRef(fo),t.writeKey(this.hookName)}}const zr=n=>new le(n.readKey());class ce extends St{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 ce}clone(){const t=new ce;return t.applyDelta(this.toDelta()),t}toDOM(t=document,e,s){const i=t.createTextNode(this.toString());return s!==void 0&&s._createAssociation(i,this),i}toString(){return this.toDelta().map(t=>{const e=[];for(const i in t.attributes){const r=[];for(const o in t.attributes[i])r.push({key:o,value:t.attributes[i][o]});r.sort((o,l)=>o.key<l.key?-1:1),e.push({nodeName:i,attrs:r})}e.sort((i,r)=>i.nodeName<r.nodeName?-1:1);let s="";for(let i=0;i<e.length;i++){const r=e[i];s+=`<${r.nodeName}`;for(let o=0;o<r.attrs.length;o++){const l=r.attrs[o];s+=` ${l.key}="${l.value}"`}s+=">"}s+=t.insert;for(let i=e.length-1;i>=0;i--)s+=`</${e[i].nodeName}>`;return s}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(go)}}const qr=n=>new ce;class qe{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 Qr=0;class O extends qe{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),zn(t.doc.store,this)}write(t,e){t.writeInfo(Qr),t.writeLen(this.length-e)}getMissing(t,e){return null}}class Vt{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Vt(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 Zr=n=>new Vt(n.readBuf());class Ht{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Ht(this.len)}splice(t){const e=new Ht(this.len-t);return this.len=t,e}mergeWith(t){return this.len+=t.len,!0}integrate(t,e){zt(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 Pr=n=>new Ht(n.readLen()),bs=(n,t)=>new wt({guid:n,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Bt{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 Bt(bs(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 to=n=>new Bt(bs(n.readString(),n.readAny()));class lt{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new lt(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 eo=n=>new lt(n.readJSON());class D{constructor(t,e){this.key=t,this.value=e}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new D(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 no=n=>new D(n.readKey(),n.readJSON());class he{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new he(this.arr)}splice(t){const e=new he(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 i=e;i<s;i++){const r=this.arr[i];t.writeString(r===void 0?"undefined":JSON.stringify(r))}}getRef(){return 2}}const so=n=>{const t=n.readLen(),e=[];for(let s=0;s<t;s++){const i=n.readString();i==="undefined"?e.push(void 0):e.push(JSON.parse(i))}return new he(e)};class ct{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ct(this.arr)}splice(t){const e=new ct(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 i=e;i<s;i++){const r=this.arr[i];t.writeAny(r)}}getRef(){return 8}}const io=n=>{const t=n.readLen(),e=[];for(let s=0;s<t;s++)e.push(n.readAny());return new ct(e)};class F{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new F(this.str)}splice(t){const e=new F(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 ro=n=>new F(n.readString()),oo=[Hr,Fr,Xr,Gr,Jr,zr,qr],lo=0,co=1,ho=2,ao=3,uo=4,fo=5,go=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 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?t._mergeStructs.push(e):e.delete(t),e=e.right;this.type._map.forEach(s=>{s.deleted?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 po=n=>new G(oo[n.readTypeRef()](n)),ae=(n,t,e)=>{const{client:s,clock:i}=t.id,r=new E(y(s,i+e),t,y(s,i+e-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(e));return t.deleted&&r.markDeleted(),t.keep&&(r.keep=!0),t.redone!==null&&(r.redone=y(t.redone.client,t.redone.clock+e)),t.right=r,r.right!==null&&(r.right.left=r),n._mergeStructs.push(r),r.parentSub!==null&&r.right===null&&r.parent._map.set(r.parentSub,r),t.length=e,r};class E extends qe{constructor(t,e,s,i,r,o,l,c){super(t,c.getLength()),this.origin=s,this.left=e,this.right=i,this.rightOrigin=r,this.parent=o,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?pn:0}set marker(t){(this.info&ke)>0!==t&&(this.info^=ke)}get marker(){return(this.info&ke)>0}get keep(){return(this.info&gn)>0}set keep(t){this.keep!==t&&(this.info^=gn)}get countable(){return(this.info&pn)>0}get deleted(){return(this.info&ye)>0}set deleted(t){this.deleted!==t&&(this.info^=ye)}markDeleted(){this.info|=ye}getMissing(t,e){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=I(e,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=I(e,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===yt&&this.id.client!==this.parent.client&&this.parent.clock>=I(e,this.parent.client))return this.parent.client;if(this.origin&&(this.left=qn(t,e,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Q(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===yt){const s=Be(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=qn(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,i;if(s!==null)i=s.right;else if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start;const r=new Set,o=new Set;for(;i!==null&&i!==this.right;){if(o.add(i),r.add(i),qt(this.origin,i.origin)){if(i.id.client<this.id.client)s=i,r.clear();else if(qt(this.rightOrigin,i.rightOrigin))break}else if(i.origin!==null&&o.has(Be(t.doc.store,i.origin)))r.has(Be(t.doc.store,i.origin))||(s=i,r.clear());else break;i=i.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),zn(t.doc.store,this),this.content.integrate(t,this),Pn(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&&qt(t.origin,this.lastId)&&this.right===t&&qt(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(),zt(t.deleteSet,this.id.client,this.id.clock,this.length),Pn(t,e,this.parentSub),this.content.delete(t)}}gc(t,e){if(!this.deleted)throw H();this.content.gc(t),e?_r(t,this,new O(this.id,this.length)):this.content=new Ht(this.length)}write(t,e){const s=e>0?y(this.id.client,this.id.clock+e-1):this.origin,i=this.rightOrigin,r=this.parentSub,o=this.content.getRef()&Yt|(s===null?0:v)|(i===null?0:Y)|(r===null?0:It);if(t.writeInfo(o),s!==null&&t.writeLeftID(s),i!==null&&t.writeRightID(i),s===null&&i===null){const l=this.parent;if(l._item!==void 0){const c=l._item;if(c===null){const a=br(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===yt?(t.writeParentInfo(!1),t.writeLeftID(l)):H();r!==null&&t.writeString(r)}this.content.write(t,e)}}const _s=(n,t)=>wo[t&Yt](n),wo=[()=>{H()},Pr,so,Zr,ro,eo,no,po,io,to,()=>{H()}],mo=10;class T extends qe{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){H()}write(t,e){t.writeInfo(mo),p(t.restEncoder,this.length-e)}getMissing(t,e){return null}}const Ss=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Cs="__ $YJS$ __";Ss[Cs]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),Ss[Cs]=!0;const Ds=0,Qe=1,Es=2,Ze=(n,t)=>{p(n,Ds);const e=yr(t);C(n,e)},As=(n,t,e)=>{p(n,Qe),C(n,gr(t,e))},yo=(n,t,e)=>As(t,e,M(n)),Is=(n,t,e)=>{try{ur(t,M(n),e)}catch(s){console.error("Caught error while handling a Yjs update",s)}},ko=(n,t)=>{p(n,Es),C(n,t)},bo=Is,_o=(n,t,e,s)=>{const i=w(n);switch(i){case Ds:yo(n,t,e);break;case Qe:Is(n,e,s);break;case Es:bo(n,e,s);break;default:throw new Error("Unknown message type")}return i},So=0,Co=(n,t,e)=>{switch(w(n)){case So:e(t,q(n))}},Pe=3e4;class Do extends ve{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const e=it();this.getLocalState()!==null&&Pe/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const s=[];this.meta.forEach((i,r)=>{r!==this.clientID&&Pe<=e-i.lastUpdated&&this.states.has(r)&&s.push(r)}),s.length>0&&tn(this,s,"timeout")},K(Pe/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),i=s===void 0?0:s.clock+1,r=this.states.get(e);t===null?this.states.delete(e):this.states.set(e,t),this.meta.set(e,{clock:i,lastUpdated:it()});const o=[],l=[],c=[],a=[];t===null?a.push(e):r==null?t!=null&&o.push(e):(l.push(e),At(r,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 tn=(n,t,e)=>{const s=[];for(let i=0;i<t.length;i++){const r=t[i];if(n.states.has(r)){if(n.states.delete(r),r===n.clientID){const o=n.meta.get(r);n.meta.set(r,{clock:o.clock+1,lastUpdated:it()})}s.push(r)}}s.length>0&&(n.emit("change",[{added:[],updated:[],removed:s},e]),n.emit("update",[{added:[],updated:[],removed:s},e]))},Ft=(n,t,e=n.states)=>{const s=t.length,i=x();p(i,s);for(let r=0;r<s;r++){const o=t[r],l=e.get(o)||null,c=n.meta.get(o).clock;p(i,o),p(i,c),st(i,JSON.stringify(l))}return S(i)},Eo=(n,t,e)=>{const s=z(t),i=it(),r=[],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(q(s)),g=n.meta.get(u),k=n.states.get(u),R=g===void 0?0:g.clock;(R<d||R===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:i}),g===void 0&&f!==null?r.push(u):g!==void 0&&f===null?c.push(u):f!==null&&(At(f,k)||l.push(u),o.push(u)))}(r.length>0||l.length>0||c.length>0)&&n.emit("change",[{added:r,updated:l,removed:c},e]),(r.length>0||o.length>0||c.length>0)&&n.emit("update",[{added:r,updated:o,removed:c},e])},Ao=n=>ni(n,(t,e)=>`${encodeURIComponent(e)}=${encodeURIComponent(t)}`).join("&");var ht=0,Ls=3,Ct=1,Io=2;function Lo(n,t){if(!n)throw new Error(t)}var $t=[];$t[ht]=(n,t,e,s,i)=>{p(n,ht);const r=_o(t,n,e.doc,e);s&&r===Qe&&!e.synced&&(e.synced=!0)},$t[Ls]=(n,t,e,s,i)=>{p(n,Ct),C(n,Ft(e.awareness,Array.from(e.awareness.getStates().keys())))},$t[Ct]=(n,t,e,s,i)=>{Eo(e.awareness,M(t),e)},$t[Io]=(n,t,e,s,i)=>{Co(t,e.doc,(r,o)=>xo(e,o))};var xs=3e4;function xo(n,t){console.warn(`Permission denied to access ${n.url}.
4
- ${t}`)}function Ms(n,t,e){const s=z(t),i=x(),r=w(s),o=n.messageHandlers[r];return o?o(i,s,n,e,r):console.error("Unable to compute message"),i}function Us(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=it();const s=Ms(n,new Uint8Array(e.data),!0);_e(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,tn(n.awareness,Array.from(n.awareness.getStates().keys()).filter(s=>s!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Us,me(ui(2,n.wsUnsuccessfulReconnects)*100,n.maxBackoffTime),n)},t.onopen=()=>{n.wsLastMessageReceived=it(),n.wsconnecting=!1,n.wsconnected=!0,n.wsUnsuccessfulReconnects=0,n.emit("status",[{status:"connected"}]);const e=x();if(p(e,ht),Ze(e,n.doc),t.send(S(e)),n.awareness.getLocalState()!==null){const s=x();p(s,Ct),C(s,Ft(n.awareness,[n.doc.clientID])),t.send(S(s))}},n.emit("status",[{status:"connecting"}])}}function en(n,t){const e=n.ws;n.wsconnected&&e&&e.readyState===e.OPEN&&e.send(t),n.bcconnected&&gt(n.bcChannel,t,n)}var Mo=class extends ve{constructor(t,e,s,{connect:i=!0,awareness:r=new Do(s),params:o={},WebSocketPolyfill:l=WebSocket,resyncInterval:c=-1,maxBackoffTime:a=2500,disableBc:h=!1}={}){super();m(this,"maxBackoffTime");m(this,"bcChannel");m(this,"url");m(this,"roomname");m(this,"doc");m(this,"_WS");m(this,"awareness");m(this,"wsconnected");m(this,"wsconnecting");m(this,"bcconnected");m(this,"disableBc");m(this,"wsUnsuccessfulReconnects");m(this,"messageHandlers");m(this,"_synced");m(this,"ws");m(this,"wsLastMessageReceived");m(this,"shouldConnect");m(this,"_resyncInterval");m(this,"_bcSubscriber");m(this,"_updateHandler");m(this,"_awarenessUpdateHandler");m(this,"_unloadHandler");m(this,"_checkInterval");for(;t[t.length-1]==="/";)t=t.slice(0,t.length-1);const u=Ao(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=r,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=h,this.wsUnsuccessfulReconnects=0,this.messageHandlers=$t.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=i,this._resyncInterval=0,c>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const d=x();p(d,ht),Ze(d,s),this.ws.send(S(d))}},c)),this._bcSubscriber=(d,f)=>{if(f!==this){const g=Ms(this,new Uint8Array(d),!1);_e(g)>1&&gt(this.bcChannel,S(g),this)}},this._updateHandler=(d,f)=>{if(f!==this){const g=x();p(g,ht),ko(g,d),en(this,S(g))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:d,updated:f,removed:g},k)=>{const R=d.concat(f).concat(g),rn=x();p(rn,Ct),C(rn,Ft(r,R)),en(this,S(rn))},this._unloadHandler=()=>{tn(this.awareness,[s.clientID],"window unload")},typeof window<"u"?window.addEventListener("unload",this._unloadHandler):typeof process<"u"&&process.on("exit",this._unloadHandler),r.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&xs<it()-this.wsLastMessageReceived&&(Lo(this.ws!==null,"ws must not be null"),this.ws.close())},xs/10),i&&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||(Vi(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const t=x();p(t,ht),Ze(t,this.doc),gt(this.bcChannel,S(t),this);const e=x();p(e,ht),As(e,this.doc),gt(this.bcChannel,S(e),this);const s=x();p(s,Ls),gt(this.bcChannel,S(s),this);const i=x();p(i,Ct),C(i,Ft(this.awareness,[this.doc.clientID])),gt(this.bcChannel,S(i),this)}disconnectBc(){const t=x();p(t,Ct),C(t,Ft(this.awareness,[this.doc.clientID],new Map)),en(this,S(t)),this.bcconnected&&(Hi(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&&(Us(this),this.connectBc())}};function vs(){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 Uo=class extends Mo{constructor(n,t,e,s={}){const i=`${n.startsWith("localhost:")||n.startsWith("127.0.0.1:")?"ws":"wss"}://${n}/party`;s.params===void 0?s.params={_pk:vs()}:s.params._pk=vs(),super(i,t,e,s)}};const Jo="";var at=(n=>(n.CanMove="can-move",n.CanSpin="can-spin",n.CanGrow="can-grow",n))(at||{});const vo={ctrlKey:"Control",altKey:"Alt",shiftKey:"Shift",metaKey:"Meta"};class nn{constructor(t,e,s,i){m(this,"element");m(this,"_data");m(this,"onChange");m(this,"debouncedOnChange");m(this,"resetShortcut");this.element=t,this.onChange=s,this.resetShortcut=i,this.debouncedOnChange=this.onChange,this._data=e,this.data=e,i&&(t.title||(t.title=`Hold down the ${vo[i]} key while clicking to reset.`),t.addEventListener("click",r=>{switch(i){case"ctrlKey":if(!r.ctrlKey)return;break;case"altKey":if(!r.altKey)return;break;case"shiftKey":if(!r.shiftKey)return;break;case"metaKey":if(!r.metaKey)return;break;default:return}this.reset()}))}get data(){return this._data}set data(t){this._data=t,this.updateElement(t),this.debouncedOnChange(t)}reset(){this.data=this.initialData}}class Os extends nn{constructor(e,s=0,i){super(e,s,i,"shiftKey");m(this,"isDown");m(this,"startX");m(this,"initialData",0);this.isDown=!1,this.startX=0,this.element.addEventListener("mousedown",r=>this.mouseDownHandler(r)),document.addEventListener("mousemove",r=>this.mouseMoveHandler(r)),document.addEventListener("mouseup",r=>this.mouseUpHandler(r))}updateElement(e){this.element.style.transform=`rotate(${e}deg)`}mouseDownHandler(e){this.isDown=!0,this.startX=e.pageX}mouseMoveHandler(e){if(!this.isDown)return;e.preventDefault();let s=Math.abs(e.pageX-this.startX)*2;e.pageX>this.startX?this.data+=s:e.pageX<this.startX&&(this.data-=s),this.startX=e.pageX}mouseUpHandler(e){this.isDown=!1}}class Ts extends nn{constructor(e,s={x:0,y:0},i){super(e,s,i,"shiftKey");m(this,"initialData",{x:0,y:0});m(this,"isDown");m(this,"startMouseX");m(this,"startMouseY");this.isDown=!1,this.startMouseX=0,this.startMouseY=0,this.updateDisplay(),this.element.addEventListener("mousedown",r=>this.mouseDownHandler(r)),document.addEventListener("mousemove",r=>this.mouseMoveHandler(r)),document.addEventListener("mouseup",r=>this.mouseUpHandler(r))}updateDisplay(){this.element.style.display==="inline"&&(this.element.style.display="inline-block")}updateElement({x:e,y:s}){this.element.style.transform=`translate(${e}px, ${s}px)`}mouseDownHandler(e){this.isDown=!0,this.startMouseX=e.clientX,this.startMouseY=e.clientY}mouseMoveHandler(e){this.isDown&&(e.preventDefault(),this.data={x:this.data.x+e.clientX-this.startMouseX,y:this.data.y+e.clientY-this.startMouseY},this.startMouseX=e.clientX,this.startMouseY=e.clientY)}mouseUpHandler(e){this.isDown=!1}}class Rs extends nn{constructor(e,s=1,i,r=2){super(e,s,i,"shiftKey");m(this,"initialData",1);m(this,"maxScale");m(this,"originalCursor",`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(T,S){typeof exports=="object"&&typeof module<"u"?S(exports):typeof define=="function"&&define.amd?define(["exports"],S):(T=typeof globalThis<"u"?globalThis:T||self,S(T.playhtml={}))})(this,function(T){"use strict";var dc=Object.defineProperty;var fc=(T,S,$)=>S in T?dc(T,S,{enumerable:!0,configurable:!0,writable:!0,value:$}):T[S]=$;var _=(T,S,$)=>(fc(T,typeof S!="symbol"?S+"":S,$),$);const S=()=>new Map,$=e=>{const t=S();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},et=()=>new Set,ye=e=>e[e.length-1],nr=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},W=Array.from,sr=Array.isArray,rr=String.fromCharCode,ir=e=>e.toLowerCase(),or=/^\s*/g,cr=e=>e.replace(or,""),lr=/([A-Z])/g,gn=(e,t)=>cr(e.replace(lr,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},xt=typeof TextEncoder<"u"?new TextEncoder:null,hr=xt?e=>xt.encode(e):ar;let Mt=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Mt&&Mt.decode(new Uint8Array).length===1&&(Mt=null);const pn=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 wn=new ur,_e=!0;try{typeof localStorage<"u"&&(wn=localStorage,_e=!1)}catch{}const mn=wn,dr=e=>_e||addEventListener("storage",e),fr=e=>_e||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},Gt=e=>pr(e).length,yr=e=>{for(const t in e)return!1;return!0},_r=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},yn=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),br=(e,t)=>e===t||Gt(e)===Gt(t)&&_r(e,(n,s)=>(n!==void 0||yn(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,Ut=(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)||!Ut(e.get(n),t.get(n)))return!1;break}case Object:if(Gt(e)!==Gt(t))return!1;for(const n in e)if(!yn(e,n)||!Ut(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(!Ut(e[n],t[n]))return!1;break;default:return!1}return!0},Dr=(e,t)=>t.includes(e),gt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name),_n=typeof window<"u"&&typeof document<"u"&&!gt;let N;const Cr=()=>{if(N===void 0)if(gt){N=S();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=S(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){const[t,n]=e.split("=");N.set(`--${gn(t,"-")}`,n),N.set(`-${gn(t,"-")}`,n)}})):N=S();return N},ke=e=>Cr().has(e),Se=e=>pn(gt?process.env[e.toUpperCase()]:mn.getItem(e));(e=>ke("--"+e)||Se(e)!==null)("production");const bn=gt&&Dr(process.env.FORCE_COLOR,["true","1","2"]),Er=!ke("no-colors")&&(!gt||process.stdout.isTTY||bn)&&(!gt||ke("color")||bn||Se("COLORTERM")!==null||(Se("TERM")||"").includes("color")),K=Math.floor,Wt=Math.abs,De=(e,t)=>e<t?e:t,nt=(e,t)=>e>t?e:t,Ir=Math.pow,kn=e=>e!==0?e<0:1/e<0,Sn=1,Dn=2,Ce=4,Ee=8,Tt=32,J=64,v=128,qt=31,Ie=63,st=127,Ar=2147483647,Cn=Number.MAX_SAFE_INTEGER,Lr=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&K(e)===e);class vt{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const M=()=>new vt,Ae=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},D=e=>{const t=new Uint8Array(Ae(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(Ne(e.cbuf.buffer,0,e.cpos),n),t},xr=(e,t)=>{const n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(Ne(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(nt(n,t)*2),e.cpos=0)},A=(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},Le=A,p=(e,t)=>{for(;t>st;)A(e,v|st&t),t=K(t/128);A(e,st&t)},xe=(e,t)=>{const n=kn(t);for(n&&(t=-t),A(e,(t>Ie?v:0)|(n?J:0)|Ie&t),t=K(t/64);t>0;)A(e,(t>st?v:0)|st&t),t=K(t/128)},Me=new Uint8Array(3e4),Mr=Me.length/3,Ur=(e,t)=>{if(t.length<Mr){const n=xt.encodeInto(t,Me).written||0;p(e,n);for(let s=0;s<n;s++)A(e,Me[s])}else C(e,hr(t))},Tr=(e,t)=>{const n=unescape(encodeURIComponent(t)),s=n.length;p(e,s);for(let r=0;r<s;r++)A(e,n.codePointAt(r))},rt=xt&&xt.encodeInto?Ur:Tr,Qt=(e,t)=>{const n=e.cbuf.length,s=e.cpos,r=De(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(nt(n*2,i)),e.cbuf.set(t.subarray(r)),e.cpos=i)},C=(e,t)=>{p(e,t.byteLength),Qt(e,t)},Ue=(e,t)=>{xr(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},vr=(e,t)=>Ue(e,4).setFloat32(0,t,!1),Or=(e,t)=>Ue(e,8).setFloat64(0,t,!1),Rr=(e,t)=>Ue(e,8).setBigInt64(0,t,!1),En=new DataView(new ArrayBuffer(4)),Nr=e=>(En.setFloat32(0,e),En.getFloat32(0)===e),Ot=(e,t)=>{switch(typeof t){case"string":A(e,119),rt(e,t);break;case"number":Lr(t)&&Wt(t)<=Ar?(A(e,125),xe(e,t)):Nr(t)?(A(e,124),vr(e,t)):(A(e,123),Or(e,t));break;case"bigint":A(e,122),Rr(e,t);break;case"object":if(t===null)A(e,126);else if(sr(t)){A(e,117),p(e,t.length);for(let n=0;n<t.length;n++)Ot(e,t[n])}else if(t instanceof Uint8Array)A(e,116),C(e,t);else{A(e,118);const n=Object.keys(t);p(e,n.length);for(let s=0;s<n.length;s++){const r=n[s];rt(e,r),Ot(e,t[r])}}break;case"boolean":A(e,t?120:121);break;default:A(e,127)}};class In extends vt{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 An=e=>{e.count>0&&(xe(e.encoder,e.count===1?e.s:-e.s),e.count>1&&p(e.encoder,e.count-2))};class Zt{constructor(){this.encoder=new vt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(An(this),this.count=1,this.s=t)}toUint8Array(){return An(this),D(this.encoder)}}const Ln=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);xe(e.encoder,t),e.count>1&&p(e.encoder,e.count-2)}};class Te{constructor(){this.encoder=new vt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(Ln(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return Ln(this),D(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 vt;return this.sarr.push(this.s),this.s="",rt(t,this.sarr.join("")),Qt(t,this.lensE.toUint8Array()),D(t)}}const it=e=>new Error(e),B=()=>{throw it("Method unimplemented")},V=()=>{throw it("Unexpected case")},xn=it("Unexpected end of array"),Mn=it("Integer out of Range");class Pt{constructor(t){this.arr=t,this.pos=0}}const q=e=>new Pt(e),Vr=e=>e.pos!==e.arr.length,Fr=(e,t)=>{const n=Ne(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},U=e=>Fr(e,m(e)),pt=e=>e.arr[e.pos++],m=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&st)*n,n*=128,r<v)return t;if(t>Cn)throw Mn}throw xn},ve=e=>{let t=e.arr[e.pos++],n=t&Ie,s=64;const r=(t&J)>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&st)*s,s*=128,t<v)return r*n;if(n>Cn)throw Mn}throw xn},Q=Mt?e=>Mt.decode(U(e)):e=>{let t=m(e);if(t===0)return"";{let n=String.fromCodePoint(pt(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(pt(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))}},Oe=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},Hr=[e=>{},e=>null,ve,e=>Oe(e,4).getFloat32(0,!1),e=>Oe(e,8).getFloat64(0,!1),e=>Oe(e,8).getBigInt64(0,!1),e=>!1,e=>!0,Q,e=>{const t=m(e),n={};for(let s=0;s<t;s++){const r=Q(e);n[r]=Rt(e)}return n},e=>{const t=m(e),n=[];for(let s=0;s<t;s++)n.push(Rt(e));return n},U],Rt=e=>Hr[127-pt(e)](e);class Un extends Pt{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=m(this)+1:this.count=-1),this.count--,this.s}}class te extends Pt{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=ve(this);const t=kn(this.s);this.count=1,t&&(this.s=-this.s,this.count=m(this)+2)}return this.count--,this.s}}class Re extends Pt{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=ve(this),n=t&1;this.diff=K(t/2),this.count=1,n&&(this.count=m(this)+2)}return this.s+=this.diff,this.count--,this.s}}class $r{constructor(t){this.decoder=new te(t),this.str=Q(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 Tn=e=>new Uint8Array(e),Ne=(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)},Jr=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),Xr=e=>{const t=atob(e),n=Tn(t.length);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return n},Yr=e=>{const t=Buffer.from(e,"base64");return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)},zr=_n?Kr:Jr,Gr=_n?Xr:Yr,Wr=e=>{const t=Tn(e.byteLength);return t.set(e),t},vn=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){mn.setItem(this.room,zr(jr(t)))}close(){fr(this._onChange)}}const Qr=typeof BroadcastChannel>"u"?qr:BroadcastChannel,Be=e=>j(vn,e,()=>{const t=et(),n=new Qr(e);return n.onmessage=s=>t.forEach(r=>r(s.data,"broadcastchannel")),{bc:n,subs:t}}),Zr=(e,t)=>(Be(e).subs.add(t),t),Pr=(e,t)=>{const n=Be(e),s=n.subs.delete(t);return s&&n.subs.size===0&&(n.bc.close(),vn.delete(e)),s},wt=(e,t,n=null)=>{const s=Be(e);s.bc.postMessage(t),s.subs.forEach(r=>r(t,n))},ot=Date.now;class ee{constructor(){this._observers=S()}on(t,n){j(this._observers,t,et).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 W((this._observers.get(t)||S()).values()).forEach(s=>s(...n))}destroy(){this._observers=S()}}const ti=crypto.getRandomValues.bind(crypto),On=()=>ti(new Uint32Array(1))[0],ei=[1e7]+-1e3+-4e3+-8e3+-1e11,ni=()=>ei.replace(/[018]/g,e=>(e^On()&15>>e/4).toString(16)),mt=e=>new Promise(e);Promise.all.bind(Promise);class si{constructor(t,n){this.left=t,this.right=n}}const X=(e,t)=>new si(e,t);typeof DOMParser<"u"&&new DOMParser;const ri=e=>tr(e,(t,n)=>`${n}:${t};`).join(""),Y=Symbol,Rn=Y(),Nn=Y(),ii=Y(),oi=Y(),ci=Y(),Bn=Y(),li=Y(),Vn=Y(),ai=Y(),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={[Rn]:X("font-weight","bold"),[Nn]:X("font-weight","normal"),[ii]:X("color","blue"),[ci]:X("color","green"),[oi]:X("color","grey"),[Bn]:X("color","red"),[li]:X("color","purple"),[Vn]:X("color","orange"),[ai]:X("color","black")},di=Er?e=>{const t=[],n=[],s=S();let r=[],i=0;for(;i<e.length;i++){const o=e[i],c=ui[o];if(c!==void 0)s.set(c.left,c.right);else if(o.constructor===String||o.constructor===Number){const l=ri(s);i>0||l.length>0?(t.push("%c"+o),n.push(l)):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=et(),Fn=e=>({[Symbol.iterator](){return this},next:e}),pi=(e,t)=>Fn(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),Ve=(e,t)=>Fn(()=>{const{done:n,value:s}=e.next();return{done:n,value:n?void 0:t(s)}});class Fe{constructor(t,n){this.clock=t,this.len=n}}class Nt{constructor(){this.clients=new Map}}const Hn=(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 c=s[o];is(e,i,c.clock,c.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},$n=(e,t)=>{const n=e.clients.get(t.client);return n!==void 0&&wi(n,t.clock)!==null},He=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=nt(r.len,i.clock+i.len-r.clock):(s<n&&(t[s]=i),s++)}t.length=s})},mi=e=>{const t=new Nt;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 He(t),t},ne=(e,t,n,s)=>{j(e.clients,t,()=>[]).push(new Fe(n,s))},yi=()=>new Nt,_i=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 c=o.id.clock;let l=o.length;if(i+1<n.length)for(let a=n[i+1];i+1<n.length&&a.deleted;a=n[++i+1])l+=a.length;r.push(new Fe(c,l))}}r.length>0&&t.clients.set(s,r)}),t},yt=(e,t)=>{p(e.restEncoder,t.clients.size),W(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)}})},$e=e=>{const t=new Nt,n=m(e.restDecoder);for(let s=0;s<n;s++){e.resetDsCurVal();const r=m(e.restDecoder),i=m(e.restDecoder);if(i>0){const o=j(t.clients,r,()=>[]);for(let c=0;c<i;c++)o.push(new Fe(e.readDsClock(),e.readDsLen()))}}return t},jn=(e,t,n)=>{const s=new Nt,r=m(e.restDecoder);for(let i=0;i<r;i++){e.resetDsCurVal();const o=m(e.restDecoder),c=m(e.restDecoder),l=n.clients.get(o)||[],a=L(n,o);for(let h=0;h<c;h++){const u=e.readDsClock(),d=u+e.readDsLen();if(u<a){a<d&&ne(s,o,a,d-a);let f=F(l,u),g=l[f];for(!g.deleted&&g.id.clock<u&&(l.splice(f+1,0,me(t,g,u-g.id.clock)),f++);f<l.length&&(g=l[f++],g.id.clock<d);)g.deleted||(d<g.id.clock+g.length&&l.splice(f,0,me(t,g,d-g.id.clock)),g.delete(t))}else ne(s,o,u,d-u)}}if(s.clients.size>0){const i=new ct;return p(i.restEncoder,0),yt(i,s),i.toUint8Array()}return null},Kn=On;class _t extends ee{constructor({guid:t=ni(),collectionid:n=null,gc:s=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:o=!1,shouldLoad:c=!0}={}){super(),this.gc=s,this.gcFilter=r,this.clientID=Kn(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new ns,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=o,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.whenLoaded=mt(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const l=()=>mt(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=l()),this.isSynced=a===void 0||a===!0,this.isLoaded||this.emit("load",[])}),this.whenSynced=l()}load(){const t=this._item;t!==null&&!this.shouldLoad&&b(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(W(this.subdocs).map(t=>t.guid))}transact(t,n=null){return b(this,t,n)}get(t,n=x){const s=j(this.share,t,()=>{const i=new n;return i._integrate(this,null),i}),r=s.constructor;if(n!==x&&r!==n)if(r===x){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,St)}getText(t=""){return this.get(t,Ct)}getMap(t=""){return this.get(t,lt)}getXmlFragment(t=""){return this.get(t,at)}toJSON(){const t={};return this.share.forEach((n,s)=>{t[s]=n.toJSON()}),t}destroy(){W(this.subdocs).forEach(n=>n.destroy());const t=this._item;if(t!==null){this._item=null;const n=t.content;n.doc=new _t({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,b(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 m(this.restDecoder)}readDsLen(){return m(this.restDecoder)}}class Xn extends Jn{readLeftID(){return y(m(this.restDecoder),m(this.restDecoder))}readRightID(){return y(m(this.restDecoder),m(this.restDecoder))}readClient(){return m(this.restDecoder)}readInfo(){return pt(this.restDecoder)}readString(){return Q(this.restDecoder)}readParentInfo(){return m(this.restDecoder)===1}readTypeRef(){return m(this.restDecoder)}readLen(){return m(this.restDecoder)}readAny(){return Rt(this.restDecoder)}readBuf(){return Wr(U(this.restDecoder))}readJSON(){return JSON.parse(Q(this.restDecoder))}readKey(){return Q(this.restDecoder)}}class bi{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=m(this.restDecoder),this.dsCurrVal}readDsLen(){const t=m(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class bt extends bi{constructor(t){super(t),this.keys=[],m(t),this.keyClockDecoder=new Re(U(t)),this.clientDecoder=new te(U(t)),this.leftClockDecoder=new Re(U(t)),this.rightClockDecoder=new Re(U(t)),this.infoDecoder=new Un(U(t),pt),this.stringDecoder=new $r(U(t)),this.parentInfoDecoder=new Un(U(t),pt),this.typeRefDecoder=new te(U(t)),this.lenDecoder=new te(U(t))}readLeftID(){return new kt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new kt(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 Rt(this.restDecoder)}readBuf(){return U(this.restDecoder)}readJSON(){return Rt(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=M()}toUint8Array(){return D(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){p(this.restEncoder,t)}writeDsLen(t){p(this.restEncoder,t)}}class Bt 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){Le(this.restEncoder,t)}writeString(t){rt(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){Ot(this.restEncoder,t)}writeBuf(t){C(this.restEncoder,t)}writeJSON(t){rt(this.restEncoder,JSON.stringify(t))}writeKey(t){rt(this.restEncoder,t)}}class zn{constructor(){this.restEncoder=M(),this.dsCurrVal=0}toUint8Array(){return D(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 Te,this.clientEncoder=new Zt,this.leftClockEncoder=new Te,this.rightClockEncoder=new Te,this.infoEncoder=new In(Le),this.stringEncoder=new Br,this.parentInfoEncoder=new In(Le),this.typeRefEncoder=new Zt,this.lenEncoder=new Zt}toUint8Array(){const t=M();return p(t,0),C(t,this.keyClockEncoder.toUint8Array()),C(t,this.clientEncoder.toUint8Array()),C(t,this.leftClockEncoder.toUint8Array()),C(t,this.rightClockEncoder.toUint8Array()),C(t,D(this.infoEncoder)),C(t,this.stringEncoder.toUint8Array()),C(t,D(this.parentInfoEncoder)),C(t,this.typeRefEncoder.toUint8Array()),C(t,this.lenEncoder.toUint8Array()),Qt(t,D(this.restEncoder)),D(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){Ot(this.restEncoder,t)}writeBuf(t){C(this.restEncoder,t)}writeJSON(t){Ot(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=nt(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)},je=(e,t,n)=>{const s=new Map;n.forEach((r,i)=>{L(t,i)>r&&s.set(i,r)}),re(t).forEach((r,i)=>{n.has(i)||s.set(i,0)}),p(e.restEncoder,s.size),W(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=S(),s=m(e.restDecoder);for(let r=0;r<s;r++){const i=m(e.restDecoder),o=new Array(i),c=e.readClient();let l=m(e.restDecoder);n.set(c,{i:0,refs:o});for(let a=0;a<i;a++){const h=e.readInfo();switch(qt&h){case 0:{const u=e.readLen();o[a]=new O(y(c,l),u),l+=u;break}case 10:{const u=m(e.restDecoder);o[a]=new R(y(c,l),u),l+=u;break}default:{const u=(h&(J|v))===0,d=new I(y(c,l),null,(h&v)===v?e.readLeftID():null,null,(h&J)===J?e.readRightID():null,u?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,u&&(h&Tt)===Tt?e.readString():null,xs(e,h));o[a]=d,l+=d.length}}}}return n},Di=(e,t,n)=>{const s=[];let r=W(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 c=new ns,l=new Map,a=(f,g)=>{const w=l.get(f);(w==null||w>g)&&l.set(f,g)};let h=o.refs[o.i++];const u=new Map,d=()=>{for(const f of s){const g=f.id.client,w=n.get(g);w?(w.i--,c.clients.set(g,w.refs.slice(w.i)),n.delete(g),w.i=0,w.refs=[]):c.clients.set(g,[f]),r=r.filter(k=>k!==g)}s.length=0};for(;;){if(h.constructor!==R){const g=j(u,h.id.client,()=>L(t,h.id.client))-h.id.clock;if(g<0)s.push(h),a(h.id.client,h.id.clock-1),d();else{const w=h.getMissing(e,t);if(w!==null){s.push(h);const k=n.get(w)||{refs:[],i:0};if(k.refs.length===k.i)a(w,L(t,w)),d();else{h=k.refs[k.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(c.clients.size>0){const f=new ct;return je(f,c,new Map),p(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},Ci=(e,t)=>je(e,t.doc.store,t.beforeState),Ei=(e,t,n,s=new bt(e))=>b(t,r=>{r.local=!1;let i=!1;const o=r.doc,c=o.store,l=Si(s,o),a=Di(r,c,l),h=c.pendingStructs;if(h){for(const[d,f]of h.missing)if(f<L(c,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=oe([h.update,a.update])}}else c.pendingStructs=a;const u=jn(s,r,c);if(c.pendingDs){const d=new bt(q(c.pendingDs));m(d.restDecoder);const f=jn(d,r,c);u&&f?c.pendingDs=oe([u,f]):c.pendingDs=u||f}else c.pendingDs=u;if(i){const d=c.pendingStructs.update;c.pendingStructs=null,Gn(r.doc,d)}},n,!1),Gn=(e,t,n,s=bt)=>{const r=q(t);Ei(r,e,n,new s(r))},Wn=(e,t,n)=>Gn(e,t,n,Xn),Ii=(e,t,n=new Map)=>{je(e,t.store,n),yt(e,_i(t.store))},Ai=(e,t=new Uint8Array([0]),n=new ct)=>{const s=qn(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===Bt)return Fi(r.map((i,o)=>o===0?i:Ki(i)));if(n.constructor===ct)return oe(r)}return r[0]},Ke=(e,t)=>Ai(e,t,new Bt),Li=e=>{const t=new Map,n=m(e.restDecoder);for(let s=0;s<n;s++){const r=m(e.restDecoder),i=m(e.restDecoder);t.set(r,i)}return t},qn=e=>Li(new Jn(q(e))),Qn=(e,t)=>(p(e.restEncoder,t.size),W(t.entries()).sort((n,s)=>s[0]-n[0]).forEach(([n,s])=>{p(e.restEncoder,n),p(e.restEncoder,s)}),e),xi=(e,t)=>Qn(e,re(t.store)),Mi=(e,t=new zn)=>(e instanceof Map?Qn(t,e):xi(t,e),t.toUint8Array()),Ui=e=>Mi(e,new Yn);class Ti{constructor(){this.l=[]}}const Zn=()=>new Ti,Pn=(e,t)=>e.l.push(t),ts=(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.")},es=(e,t,n)=>be(e.l,[t,n]);class kt{constructor(t,n){this.client=t,this.clock=n}}const se=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,y=(e,t)=>new kt(e,t),vi=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw V()},Vt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!$n(t.ds,e.id),Je=(e,t)=>{const n=j(e.meta,Je,et),s=e.doc.store;n.has(t)||(t.sv.forEach((r,i)=>{r<L(s,i)&&Z(e,y(i,r))}),Hn(e,t.ds,r=>{}),n.add(t))};class ns{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const re=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},L=(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},ss=(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()},Xe=(e,t)=>{const n=e.clients.get(t.client);return n[F(n,t.clock)]},Ye=(e,t,n)=>{const s=F(t,n),r=t[s];return r.id.clock<n&&r instanceof I?(t.splice(s+1,0,me(e,r,n-r.id.clock)),s+1):s},Z=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[Ye(e,n,t.clock)]},rs=(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,me(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},is=(e,t,n,s,r)=>{if(s===0)return;const i=n+s;let o=Ye(e,t,n),c;do c=t[o++],i<c.id.clock+c.length&&Ye(e,t,i),r(c);while(o<t.length&&t[o].id.clock<i)};class Ri{constructor(t,n,s){this.doc=t,this.deleteSet=new Nt,this.beforeState=re(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 os=(e,t)=>t.deleteSet.clients.size===0&&!er(t.afterState,(n,s)=>t.beforeState.get(s)!==n)?!1:(He(t.deleteSet),Ci(e,t),yt(e,t.deleteSet),!0),cs=(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,et).add(n)},ie=(e,t)=>{const n=e[t-1],s=e[t];n.deleted===s.deleted&&n.constructor===s.constructor&&n.mergeWith(s)&&(e.splice(t,1),s instanceof I&&s.parentSub!==null&&s.parent._map.get(s.parentSub)===s&&s.parent._map.set(s.parentSub,n))},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 c=r[o],l=c.clock+c.len;for(let a=F(i,c.clock),h=i[a];a<i.length&&h.id.clock<l;h=i[++a]){const u=i[a];if(c.clock+c.len<=u.id.clock)break;u instanceof I&&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],c=De(r.length-1,1+F(r,o.clock+o.len-1));for(let l=c,a=r[l];l>0&&a.id.clock>=o.clock;a=r[--l])ie(r,l)}})},ls=(e,t)=>{if(t<e.length){const n=e[t],s=n.doc,r=s.store,i=n.deleteSet,o=n._mergeStructs;try{He(i),n.afterState=re(n.doc.store),s.emit("beforeObserverCalls",[n,s]);const c=[];n.changed.forEach((l,a)=>c.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(n,l)})),c.push(()=>{n.changedParentTypes.forEach((l,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(l=l.filter(h=>h.target._item===null||!h.target._item.deleted),l.forEach(h=>{h.currentTarget=a,h._path=null}),l.sort((h,u)=>h.path.length-u.path.length),es(a._dEH,l,n))})}),c.push(()=>s.emit("afterTransaction",[n,s])),be(c,[]),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=nt(F(f,d),1);for(let w=f.length-1;w>=g;w--)ie(f,w)}});for(let h=0;h<o.length;h++){const{client:u,clock:d}=o[h].id,f=r.clients.get(u),g=F(f,d);g+1<f.length&&ie(f,g+1),g>0&&ie(f,g)}if(!n.local&&n.afterState.get(s.clientID)!==n.beforeState.get(s.clientID)&&(fi(Vn,Rn,"[yjs] ",Nn,Bn,"Changed the client-id because another client seems to be using it."),s.clientID=Kn()),s.emit("afterTransactionCleanup",[n,s]),s._observers.has("update")){const h=new Bt;os(h,n)&&s.emit("update",[h.toUint8Array(),n.origin,s,n])}if(s._observers.has("updateV2")){const h=new ct;os(h,n)&&s.emit("updateV2",[h.toUint8Array(),n.origin,s,n])}const{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:a}=n;(c.size>0||a.size>0||l.size>0)&&(c.forEach(h=>{h.clientID=s.clientID,h.collectionid==null&&(h.collectionid=s.collectionid),s.subdocs.add(h)}),a.forEach(h=>s.subdocs.delete(h)),s.emit("subdocs",[{loaded:l,added:c,removed:a},s,n]),a.forEach(h=>h.destroy())),e.length<=t+1?(s._transactionCleanups=[],s.emit("afterAllTransactions",[s,e])):ls(e,t+1)}}},b=(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 c=e._transaction===r[0];e._transaction=null,c&&ls(r,0)}}return o};function*Vi(e){const t=m(e.restDecoder);for(let n=0;n<t;n++){const s=m(e.restDecoder),r=e.readClient();let i=m(e.restDecoder);for(let o=0;o<s;o++){const c=e.readInfo();if(c===10){const l=m(e.restDecoder);yield new R(y(r,i),l),i+=l}else if(qt&c){const l=(c&(J|v))===0,a=new I(y(r,i),null,(c&v)===v?e.readLeftID():null,null,(c&J)===J?e.readRightID():null,l?e.readParentInfo()?e.readString():e.readLeftID():null,l&&(c&Tt)===Tt?e.readString():null,xs(e,c));yield a,i+=a.length}else{const l=e.readLen();yield new O(y(r,i),l),i+=l}}}}class ze{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 Ge{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const Fi=e=>oe(e,Xn,Bt),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 I(y(s,r+t),null,y(s,r+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},oe=(e,t=bt,n=ct)=>{if(e.length===1)return e[0];const s=e.map(h=>new t(q(h)));let r=s.map(h=>new ze(h,!0)),i=null;const o=new n,c=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)P(c,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{P(c,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)||(P(c,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())P(c,i.struct,i.offset),i={struct:d,offset:0}}i!==null&&(P(c,i.struct,i.offset),i=null),We(c);const l=s.map(h=>$e(h)),a=mi(l);return yt(o,a),o.toUint8Array()},$i=(e,t,n=bt,s=ct)=>{const r=qn(t),i=new s,o=new Ge(i),c=new n(q(e)),l=new ze(c,!1);for(;l.curr;){const h=l.curr,u=h.id.client,d=r.get(u)||0;if(l.curr.constructor===R){l.next();continue}if(h.id.clock+h.length>d)for(P(o,h,nt(d-h.id.clock,0)),l.next();l.curr&&l.curr.id.client===u;)P(o,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===u&&l.curr.id.clock+l.curr.length<=d;)l.next()}We(o);const a=$e(c);return yt(i,a),i.toUint8Array()},as=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:D(e.encoder.restEncoder)}),e.encoder.restEncoder=M(),e.written=0)},P=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&as(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++},We=e=>{as(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 ze(r,!1),o=new s,c=new Ge(o);for(let a=i.curr;a!==null;a=i.next())P(c,t(a),0);We(c);const l=$e(r);return yt(o,l),o.toUint8Array()},Ki=e=>ji(e,kr,bt,Bt);class ce{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=Ji(this.currentTarget,this.target))}deletes(t){return $n(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){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,c;if(this.adds(i)){let l=i.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(i))if(l!==null&&this.deletes(l))o="delete",c=ye(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",c=ye(l.content.getContent())):(o="add",c=void 0)}else if(this.deletes(i))o="delete",c=ye(i.content.getContent());else return;t.set(r,{action:o,oldValue:c})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){const n=this.target,s=et(),r=et(),i=[];if(t={added:s,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(n).has(null)){let c=null;const l=()=>{c&&i.push(c)};for(let a=n._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((c===null||c.delete===void 0)&&(l(),c={delete:0}),c.delete+=a.length,r.add(a)):this.adds(a)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(a.content.getContent()),s.add(a)):((c===null||c.retain===void 0)&&(l(),c={retain:0}),c.retain+=a.length);c!==null&&c.retain===void 0&&l()}this._changes=t}return t}}const Ji=(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},hs=80;let qe=0;class Xi{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=qe++}}const Yi=e=>{e.timestamp=qe++},us=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=qe++},zi=(e,t,n)=>{if(e.length>=hs){const s=e.reduce((r,i)=>r.timestamp<i.timestamp?r:i);return us(s,t,n),s}else{const s=new Xi(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)=>Wt(t-i.index)<Wt(t-o.index)?i:o);let s=e._start,r=0;for(n!==null&&(s=n.p,r=n.index,Yi(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&&Wt(n.index-r)<s.parent.length/hs?(us(n,s,r),n):zi(e._searchMarker,s,r)},Ft=(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=nt(t,r.index+n))}},ae=(e,t,n)=>{const s=e,r=t.changedParentTypes;for(;j(r,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;es(s._eH,n,t)};class x{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,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){Pn(this._eH,t)}observeDeep(t){Pn(this._dEH,t)}unobserve(t){ts(this._eH,t)}unobserveDeep(t){ts(this._dEH,t)}toJSON(){}}const ds=(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 c=t;c<o.length&&s>0;c++)r.push(o[c]),s--;t=0}}i=i.right}return r},fs=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},Ht=(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}},gs=(e,t)=>{const n=[];return Ht(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}}}},ps=(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}},he=(e,t,n,s)=>{let r=n;const i=e.doc,o=i.clientID,c=i.store,l=n===null?t._start:n.right;let a=[];const h=()=>{a.length>0&&(r=new I(y(o,L(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new ut(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 I(y(o,L(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new jt(new Uint8Array(u))),r.integrate(e,0);break;case _t:r=new I(y(o,L(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new Jt(u)),r.integrate(e,0);break;default:if(u instanceof x)r=new I(y(o,L(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new z(u)),r.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},ws=it("Length exceeded!"),ms=(e,t,n,s)=>{if(n>t._length)throw ws;if(n===0)return t._searchMarker&&Ft(t._searchMarker,n,s.length),he(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&&Z(e,y(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&Ft(t._searchMarker,r,s.length),he(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 he(e,t,r,n)},ys=(e,t,n,s)=>{if(s===0)return;const r=n,i=s,o=le(t,n);let c=t._start;for(o!==null&&(c=o.p,n-=o.index);c!==null&&n>0;c=c.right)!c.deleted&&c.countable&&(n<c.length&&Z(e,y(c.id.client,c.id.clock+n)),n-=c.length);for(;s>0&&c!==null;)c.deleted||(s<c.length&&Z(e,y(c.id.client,c.id.clock+s)),c.delete(e),s-=c.length),c=c.right;if(s>0)throw ws;t._searchMarker&&Ft(t._searchMarker,r,-i+s)},ue=(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 c;if(s==null)c=new ut([s]);else switch(s.constructor){case Number:case Object:case Boolean:case Array:case String:c=new ut([s]);break;case Uint8Array:c=new jt(s);break;case _t:c=new Jt(s);break;default:if(s instanceof x)c=new z(s);else throw new Error("Unexpected content type")}new I(y(o,L(i.store,o)),r,r&&r.lastId,null,null,t,n,c).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},_s=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},de=e=>pi(e.entries(),t=>!t[1].deleted);class qi extends ce{constructor(t,n){super(t,n),this._transaction=n}}class St extends x{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new St;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new St}clone(){const t=new St;return t.insert(0,this.toArray().map(n=>n instanceof x?n.clone():n)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}_callObserver(t,n){super._callObserver(t,n),ae(this,t,new qi(this,t))}insert(t,n){this.doc!==null?b(this.doc,s=>{ms(s,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?b(this.doc,n=>{Wi(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?b(this.doc,s=>{ys(s,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return ps(this,t)}toArray(){return fs(this)}slice(t=0,n=this.length){return ds(this,t,n)}toJSON(){return this.map(t=>t instanceof x?t.toJSON():t)}map(t){return gs(this,t)}forEach(t){Ht(this,t)}[Symbol.iterator](){return Gi(this)}_write(t){t.writeTypeRef(ko)}}const Qi=e=>new St;class Zi extends ce{constructor(t,n,s){super(t,n),this.keysChanged=s}}class lt extends x{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 lt}clone(){const t=new lt;return this.forEach((n,s)=>{t.set(s,n instanceof x?n.clone():n)}),t}_callObserver(t,n){ae(this,t,new Zi(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 x?r.toJSON():r}}),t}get size(){return[...de(this._map)].length}keys(){return Ve(de(this._map),t=>t[0])}values(){return Ve(de(this._map),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Ve(de(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?b(this.doc,n=>{ue(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?b(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?b(this.doc,t=>{this.forEach(function(n,s,r){ue(t,r,s)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(So)}}const Pi=e=>new lt,tt=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&br(e,t);class Pe{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 E:this.right.deleted||Dt(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=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case E:t.right.deleted||Dt(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&Z(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},fe=(e,t,n)=>{const s=new Map,r=le(t,n);if(r){const i=new Pe(r.p.left,r.p,r.index,s);return ks(e,i,n-r.index)}else{const i=new Pe(null,t._start,0,s);return ks(e,i,n)}},Ss=(e,t,n,s)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===E&&tt(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,c)=>{const l=n.left,a=n.right,h=new I(y(i,L(r.store,i)),l,l&&l.lastId,a,a&&a.id,t,null,new E(c,o));h.integrate(e,0),n.right=h,n.forward()})},Dt=(e,t)=>{const{key:n,value:s}=t;s===null?e.delete(n):e.set(n,s)},Ds=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===E&&tt(t[e.right.content.key]||null,e.right.content.value)))break;e.forward()}},Cs=(e,t,n,s)=>{const r=e.doc,i=r.clientID,o=new Map;for(const c in s){const l=s[c],a=n.currentAttributes.get(c)||null;if(!tt(a,l)){o.set(c,a);const{left:h,right:u}=n;n.right=new I(y(i,L(r.store,i)),h,h&&h.lastId,u,u&&u.id,t,null,new E(c,l)),n.right.integrate(e,0),n.forward()}}return o},tn=(e,t,n,s,r)=>{n.currentAttributes.forEach((d,f)=>{r[f]===void 0&&(r[f]=null)});const i=e.doc,o=i.clientID;Ds(n,r);const c=Cs(e,t,n,r),l=s.constructor===String?new H(s):s instanceof x?new z(s):new ht(s);let{left:a,right:h,index:u}=n;t._searchMarker&&Ft(t._searchMarker,n.index,l.getLength()),h=new I(y(o,L(i.store,o)),a,a&&a.lastId,h,h&&h.id,t,null,l),h.integrate(e,0),n.right=h,n.index=u,n.forward(),Ss(e,t,n,c)},Es=(e,t,n,s,r)=>{const i=e.doc,o=i.clientID;Ds(n,r);const c=Cs(e,t,n,r);t:for(;n.right!==null&&(s>0||c.size>0&&(n.right.deleted||n.right.content.constructor===E));){if(!n.right.deleted)switch(n.right.content.constructor){case E:{const{key:l,value:a}=n.right.content,h=r[l];if(h!==void 0){if(tt(h,a))c.delete(l);else{if(s===0)break t;c.set(l,a)}n.right.delete(e)}else n.currentAttributes.set(l,a);break}default:s<n.right.length&&Z(e,y(n.right.id.client,n.right.id.clock+s)),s-=n.right.length;break}n.forward()}if(s>0){let l="";for(;s>0;s--)l+=`
2
+ `;n.right=new I(y(o,L(i.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new H(l)),n.right.integrate(e,0),n.forward()}Ss(e,t,n,c)},Is=(e,t,n,s,r)=>{let i=t;const o=S();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===E){const a=i.content;o.set(a.key,a)}i=i.right}let c=0,l=!1;for(;t!==i;){if(n===t&&(l=!0),!t.deleted){const a=t.content;switch(a.constructor){case E:{const{key:h,value:u}=a,d=s.get(h)||null;(o.get(h)!==a||d===u)&&(t.delete(e),c++,!l&&(r.get(h)||null)===u&&d!==u&&(d===null?r.delete(h):r.set(h,d))),!l&&!t.deleted&&Dt(r,a);break}}}t=t.right}return c},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===E){const s=t.content.key;n.has(s)?t.delete(e):n.add(s)}t=t.left}},eo=e=>{let t=0;return b(e.doc,n=>{let s=e._start,r=e._start,i=S();const o=$(i);for(;r;){if(r.deleted===!1)switch(r.content.constructor){case E:Dt(o,r.content);break;default:t+=Is(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&&is(e,n.store.clients.get(s),i,r,o=>{!o.deleted&&o.content.constructor===E&&o.constructor!==O&&t.add(o.parent)})}b(n,s=>{Hn(e,e.deleteSet,r=>{if(r instanceof O||!r.parent._hasFormatting||t.has(r.parent))return;const i=r.parent;r.content.constructor===E?t.add(i):to(s,r)});for(const r of t)eo(r)})},As=(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 z:case ht:case H:n<t.right.length&&Z(e,y(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}i&&Is(e,i,t.right,r,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&Ft(o._searchMarker,t.index,-s+n),t};class so extends ce{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=[];b(t,s=>{const r=new Map,i=new Map;let o=this.target._start,c=null;const l={};let a="",h=0,u=0;const d=()=>{if(c!==null){let f=null;switch(c){case"delete":u>0&&(f={delete:u}),u=0;break;case"insert":(typeof a=="object"||a.length>0)&&(f={insert:a},r.size>0&&(f.attributes={},r.forEach((g,w)=>{g!==null&&(f.attributes[w]=g)}))),a="";break;case"retain":h>0&&(f={retain:h},yr(l)||(f.attributes=gr({},l))),h=0;break}f&&n.push(f),c=null}};for(;o!==null;){switch(o.content.constructor){case z:case ht:this.adds(o)?this.deletes(o)||(d(),c="insert",a=o.content.getContent()[0],d()):this.deletes(o)?(c!=="delete"&&(d(),c="delete"),u+=1):o.deleted||(c!=="retain"&&(d(),c="retain"),h+=1);break;case H:this.adds(o)?this.deletes(o)||(c!=="insert"&&(d(),c="insert"),a+=o.content.str):this.deletes(o)?(c!=="delete"&&(d(),c="delete"),u+=o.length):o.deleted||(c!=="retain"&&(d(),c="retain"),h+=o.length);break;case E:{const{key:f,value:g}=o.content;if(this.adds(o)){if(!this.deletes(o)){const w=r.get(f)||null;tt(w,g)?g!==null&&o.delete(s):(c==="retain"&&d(),tt(g,i.get(f)||null)?delete l[f]:l[f]=g)}}else if(this.deletes(o)){i.set(f,g);const w=r.get(f)||null;tt(w,g)||(c==="retain"&&d(),l[f]=w)}else if(!o.deleted){i.set(f,g);const w=l[f];w!==void 0&&(tt(w,g)?w!==null&&o.delete(s):(c==="retain"&&d(),g===null?delete l[f]:l[f]=g))}o.deleted||(c==="insert"&&d(),Dt(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 Ct extends x{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach(s=>s())}catch(s){console.error(s)}this._pending=null}_copy(){return new Ct}clone(){const t=new Ct;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const s=new so(this,t,n);ae(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?b(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 c=!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 c!="string"||c.length>0)&&tn(s,this,r,c,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,n,s){const r=[],i=new Map,o=this.doc;let c="",l=this._start;function a(){if(c.length>0){const u={};let d=!1;i.forEach((g,w)=>{d=!0,u[w]=g});const f={insert:c};d&&(f.attributes=u),r.push(f),c=""}}const h=()=>{for(;l!==null;){if(Vt(l,t)||n!==void 0&&Vt(l,n))switch(l.content.constructor){case H:{const u=i.get("ychange");t!==void 0&&!Vt(l,t)?(u===void 0||u.user!==l.id.client||u.type!=="removed")&&(a(),i.set("ychange",s?s("removed",l.id):{type:"removed"})):n!==void 0&&!Vt(l,n)?(u===void 0||u.user!==l.id.client||u.type!=="added")&&(a(),i.set("ychange",s?s("added",l.id):{type:"added"})):u!==void 0&&(a(),i.delete("ychange")),c+=l.content.str;break}case z:case ht:{a();const u={insert:l.content.getContent()[0]};if(i.size>0){const d={};u.attributes=d,i.forEach((f,g)=>{d[g]=f})}r.push(u);break}case E:Vt(l,t)&&(a(),Dt(i,l.content));break}l=l.right}a()};return t||n?b(o,u=>{t&&Je(u,t),n&&Je(u,n),h()},"cleanup"):h(),r}insert(t,n,s){if(n.length<=0)return;const r=this.doc;r!==null?b(r,i=>{const o=fe(i,this,t);s||(s={},o.currentAttributes.forEach((c,l)=>{s[l]=c})),tn(i,this,o,n,s)}):this._pending.push(()=>this.insert(t,n,s))}insertEmbed(t,n,s={}){const r=this.doc;r!==null?b(r,i=>{const o=fe(i,this,t);tn(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?b(s,r=>{As(r,fe(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?b(r,i=>{const o=fe(i,this,t);o.right!==null&&Es(i,this,o,n,s)}):this._pending.push(()=>this.format(t,n,s))}removeAttribute(t){this.doc!==null?b(this.doc,n=>{ue(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?b(this.doc,s=>{Qe(s,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return Ze(this,t)}getAttributes(){return _s(this)}_write(t){t.writeTypeRef(Do)}}const ro=e=>new Ct;class en{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===$t||n.constructor===at)&&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 at extends x{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 at}clone(){const t=new at;return t.insert(0,this.toArray().map(n=>n instanceof x?n.clone():n)),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(),W(new en(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){ae(this,t,new co(this,n,t))}toString(){return gs(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),Ht(this,i=>{r.insertBefore(i.toDOM(t,n,s),null)}),r}insert(t,n){this.doc!==null?b(this.doc,s=>{ms(s,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)b(this.doc,s=>{const r=t&&t instanceof x?t._item:t;he(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 it("Reference item not found");s.splice(r,0,...n)}}delete(t,n=1){this.doc!==null?b(this.doc,s=>{ys(s,this,t,n)}):this._prelimContent.splice(t,n)}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,n=this.length){return ds(this,t,n)}forEach(t){Ht(this,t)}_write(t){t.writeTypeRef(Eo)}}const io=e=>new at;class $t extends at{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 $t(this.nodeName)}clone(){const t=new $t(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 x?s.clone():s)),t}toString(){const t=this.getAttributes(),n=[],s=[];for(const c in t)s.push(c);s.sort();const r=s.length;for(let c=0;c<r;c++){const l=s[c];n.push(l+'="'+t[l]+'"')}const i=this.nodeName.toLocaleLowerCase(),o=n.length>0?" "+n.join(" "):"";return`<${i}${o}>${super.toString()}</${i}>`}removeAttribute(t){this.doc!==null?b(this.doc,n=>{ue(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?b(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 _s(this)}toDOM(t=document,n={},s){const r=t.createElement(this.nodeName),i=this.getAttributes();for(const o in i){const c=i[o];typeof c=="string"&&r.setAttribute(o,c)}return Ht(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 $t(e.readKey());class co extends ce{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 ge extends lt{constructor(t){super(),this.hookName=t}_copy(){return new ge(this.hookName)}clone(){const t=new ge(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 lo=e=>new ge(e.readKey());class pe extends Ct{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 pe}clone(){const t=new pe;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,c)=>o.key<c.key?-1:1),n.push({nodeName:r,attrs:i})}n.sort((r,i)=>r.nodeName<i.nodeName?-1:1);let s="";for(let r=0;r<n.length;r++){const i=n[r];s+=`<${i.nodeName}`;for(let o=0;o<i.attrs.length;o++){const c=i.attrs[o];s+=` ${c.key}="${c.value}"`}s+=">"}s+=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 pe;class nn{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 nn{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),ss(t.doc.store,this)}write(t,n){t.writeInfo(ho),t.writeLen(this.length-n)}getMissing(t,n){return null}}class jt{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new jt(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 jt(e.readBuf());class Kt{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Kt(this.len)}splice(t){const n=new Kt(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){ne(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 Kt(e.readLen()),Ls=(e,t)=>new _t({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Jt{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const 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 Jt(Ls(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 Jt(Ls(e.readString(),e.readAny()));class ht{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new ht(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 ht(e.readJSON());class E{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new E(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 E(e.readKey(),e.readJSON());class we{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new we(this.arr)}splice(t){const n=new we(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 we(n)};class ut{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ut(this.arr)}splice(t){const n=new ut(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 ut(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 _o=e=>new H(e.readString()),bo=[Qi,Pi,ro,oo,io,lo,ao],ko=0,So=1,Do=2,Co=3,Eo=4,Io=5,Ao=6;class z{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new z(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?t._mergeStructs.push(n):n.delete(t),n=n.right;this.type._map.forEach(s=>{s.deleted?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 z(bo[e.readTypeRef()](e)),me=(e,t,n)=>{const{client:s,clock:r}=t.id,i=new I(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 I extends nn{constructor(t,n,s,r,i,o,c,l){super(t,l.getLength()),this.origin=s,this.left=n,this.right=r,this.rightOrigin=i,this.parent=o,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?Dn:0}set marker(t){(this.info&Ee)>0!==t&&(this.info^=Ee)}get marker(){return(this.info&Ee)>0}get keep(){return(this.info&Sn)>0}set keep(t){this.keep!==t&&(this.info^=Sn)}get countable(){return(this.info&Dn)>0}get deleted(){return(this.info&Ce)>0}set deleted(t){this.deleted!==t&&(this.info^=Ce)}markDeleted(){this.info|=Ce}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=L(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=L(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===kt&&this.id.client!==this.parent.client&&this.parent.clock>=L(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=rs(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Z(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===I&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===I&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===kt){const s=Xe(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=rs(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),se(this.origin,r.origin)){if(r.id.client<this.id.client)s=r,i.clear();else if(se(this.rightOrigin,r.rightOrigin))break}else if(r.origin!==null&&o.has(Xe(t.doc.store,r.origin)))i.has(Xe(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),ss(t.doc.store,this),this.content.integrate(t,this),cs(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&&se(t.origin,this.lastId)&&this.right===t&&se(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(),ne(t.deleteSet,this.id.client,this.id.clock,this.length),cs(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 Kt(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()&qt|(s===null?0:v)|(r===null?0:J)|(i===null?0:Tt);if(t.writeInfo(o),s!==null&&t.writeLeftID(s),r!==null&&t.writeRightID(r),s===null&&r===null){const c=this.parent;if(c._item!==void 0){const l=c._item;if(l===null){const a=vi(c);t.writeParentInfo(!0),t.writeString(a)}else t.writeParentInfo(!1),t.writeLeftID(l.id)}else c.constructor===String?(t.writeParentInfo(!0),t.writeString(c)):c.constructor===kt?(t.writeParentInfo(!1),t.writeLeftID(c)):V();i!==null&&t.writeString(i)}this.content.write(t,n)}}const xs=(e,t)=>xo[t&qt](e),xo=[()=>{V()},fo,mo,uo,_o,po,wo,Lo,yo,go,()=>{V()}],Mo=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,n){V()}write(t,n){t.writeInfo(Mo),p(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const Ms=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Us="__ $YJS$ __";Ms[Us]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),Ms[Us]=!0;const Ts=0,sn=1,vs=2,rn=(e,t)=>{p(e,Ts);const n=Ui(t);C(e,n)},Os=(e,t,n)=>{p(e,sn),C(e,Ke(t,n))},Uo=(e,t,n)=>Os(t,n,U(e)),Rs=(e,t,n)=>{try{Wn(t,U(e),n)}catch(s){console.error("Caught error while handling a Yjs update",s)}},To=(e,t)=>{p(e,vs),C(e,t)},vo=Rs,Oo=(e,t,n,s)=>{const r=m(e);switch(r){case Ts:Uo(e,t,n);break;case sn:Rs(e,n,s);break;case vs:vo(e,n,s);break;default:throw new Error("Unknown message type")}return r},Ro=0,No=(e,t,n)=>{switch(m(e)){case Ro:n(t,Q(e))}},on=3e4;class Bo extends ee{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const n=ot();this.getLocalState()!==null&&on/2<=n-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const s=[];this.meta.forEach((r,i)=>{i!==this.clientID&&on<=n-r.lastUpdated&&this.states.has(i)&&s.push(i)}),s.length>0&&cn(this,s,"timeout")},K(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 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:ot()});const o=[],c=[],l=[],a=[];t===null?a.push(n):i==null?t!=null&&o.push(n):(c.push(n),Ut(i,t)||l.push(n)),(o.length>0||l.length>0||a.length>0)&&this.emit("change",[{added:o,updated:l,removed:a},"local"]),this.emit("update",[{added:o,updated:c,removed:a},"local"])}setLocalStateField(t,n){const s=this.getLocalState();s!==null&&this.setLocalState({...s,[t]:n})}getStates(){return this.states}}const cn=(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:ot()})}s.push(i)}}s.length>0&&(e.emit("change",[{added:[],updated:[],removed:s},n]),e.emit("update",[{added:[],updated:[],removed:s},n]))},Xt=(e,t,n=e.states)=>{const s=t.length,r=M();p(r,s);for(let i=0;i<s;i++){const o=t[i],c=n.get(o)||null,l=e.meta.get(o).clock;p(r,o),p(r,l),rt(r,JSON.stringify(c))}return D(r)},Vo=(e,t,n)=>{const s=q(t),r=ot(),i=[],o=[],c=[],l=[],a=m(s);for(let h=0;h<a;h++){const u=m(s);let d=m(s);const f=JSON.parse(Q(s)),g=e.meta.get(u),w=e.states.get(u),k=g===void 0?0:g.clock;(k<d||k===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?l.push(u):f!==null&&(Ut(f,w)||c.push(u),o.push(u)))}(i.length>0||c.length>0||l.length>0)&&e.emit("change",[{added:i,updated:c,removed:l},n]),(i.length>0||o.length>0||l.length>0)&&e.emit("update",[{added:i,updated:o,removed:l},n])},Fo=e=>mr(e,(t,n)=>`${encodeURIComponent(n)}=${encodeURIComponent(t)}`).join("&");var dt=0,Ns=3,Et=1,Ho=2;function $o(e,t){if(!e)throw new Error(t)}var Yt=[];Yt[dt]=(e,t,n,s,r)=>{p(e,dt);const i=Oo(t,e,n.doc,n);s&&i===sn&&!n.synced&&(n.synced=!0)},Yt[Ns]=(e,t,n,s,r)=>{p(e,Et),C(e,Xt(n.awareness,Array.from(n.awareness.getStates().keys())))},Yt[Et]=(e,t,n,s,r)=>{Vo(n.awareness,U(t),n)},Yt[Ho]=(e,t,n,s,r)=>{No(t,n.doc,(i,o)=>jo(n,o))};var Bs=3e4;function jo(e,t){console.warn(`Permission denied to access ${e.url}.
4
+ ${t}`)}function Vs(e,t,n){const s=q(t),r=M(),i=m(s),o=e.messageHandlers[i];return o?o(r,s,e,n,i):console.error("Unable to compute message"),r}function Fs(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=ot();const s=Vs(e,new Uint8Array(n.data),!0);Ae(s)>1&&t.send(D(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,cn(e.awareness,Array.from(e.awareness.getStates().keys()).filter(s=>s!==e.doc.clientID),e),e.emit("status",[{status:"disconnected"}])):e.wsUnsuccessfulReconnects++,setTimeout(Fs,De(Ir(2,e.wsUnsuccessfulReconnects)*100,e.maxBackoffTime),e)},t.onopen=()=>{e.wsLastMessageReceived=ot(),e.wsconnecting=!1,e.wsconnected=!0,e.wsUnsuccessfulReconnects=0,e.emit("status",[{status:"connected"}]);const n=M();if(p(n,dt),rn(n,e.doc),t.send(D(n)),e.awareness.getLocalState()!==null){const s=M();p(s,Et),C(s,Xt(e.awareness,[e.doc.clientID])),t.send(D(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&&wt(e.bcChannel,t,e)}var Ko=class extends ee{constructor(t,n,s,{connect:r=!0,awareness:i=new Bo(s),params:o={},WebSocketPolyfill:c=WebSocket,resyncInterval:l=-1,maxBackoffTime:a=2500,disableBc:h=!1}={}){super();_(this,"maxBackoffTime");_(this,"bcChannel");_(this,"url");_(this,"roomname");_(this,"doc");_(this,"_WS");_(this,"awareness");_(this,"wsconnected");_(this,"wsconnecting");_(this,"bcconnected");_(this,"disableBc");_(this,"wsUnsuccessfulReconnects");_(this,"messageHandlers");_(this,"_synced");_(this,"ws");_(this,"wsLastMessageReceived");_(this,"shouldConnect");_(this,"_resyncInterval");_(this,"_bcSubscriber");_(this,"_updateHandler");_(this,"_awarenessUpdateHandler");_(this,"_unloadHandler");_(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=c,this.awareness=i,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=h,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Yt.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=r,this._resyncInterval=0,l>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const d=M();p(d,dt),rn(d,s),this.ws.send(D(d))}},l)),this._bcSubscriber=(d,f)=>{if(f!==this){const g=Vs(this,new Uint8Array(d),!1);Ae(g)>1&&wt(this.bcChannel,D(g),this)}},this._updateHandler=(d,f)=>{if(f!==this){const g=M();p(g,dt),To(g,d),ln(this,D(g))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:d,updated:f,removed:g},w)=>{const k=d.concat(f).concat(g),At=M();p(At,Et),C(At,Xt(i,k)),ln(this,D(At))},this._unloadHandler=()=>{cn(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<ot()-this.wsLastMessageReceived&&($o(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||(Zr(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const t=M();p(t,dt),rn(t,this.doc),wt(this.bcChannel,D(t),this);const n=M();p(n,dt),Os(n,this.doc),wt(this.bcChannel,D(n),this);const s=M();p(s,Ns),wt(this.bcChannel,D(s),this);const r=M();p(r,Et),C(r,Xt(this.awareness,[this.doc.clientID])),wt(this.bcChannel,D(r),this)}disconnectBc(){const t=M();p(t,Et),C(t,Xt(this.awareness,[this.doc.clientID],new Map)),ln(this,D(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&&(Fs(this),this.connectBc())}};function Hs(){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 Jo=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:Hs()}:s.params._pk=Hs(),super(r,t,n,s)}};const ft=e=>mt((t,n)=>{e.onerror=s=>n(new Error(s.target.error)),e.onsuccess=s=>t(s.target.result)}),Xo=(e,t)=>mt((n,s)=>{const r=indexedDB.open(e);r.onupgradeneeded=i=>t(i.target.result),r.onerror=i=>s(it(i.target.error)),r.onsuccess=i=>{const o=i.target.result;o.onversionchange=()=>{o.close()},typeof addEventListener<"u"&&addEventListener("unload",()=>o.close()),n(o)}}),Yo=e=>ft(indexedDB.deleteDatabase(e)),zo=(e,t)=>t.forEach(n=>e.createObjectStore.apply(e,n)),zt=(e,t,n="readwrite")=>{const s=e.transaction(t,n);return t.map(r=>ec(s,r))},$s=(e,t)=>ft(e.count(t)),Go=(e,t)=>ft(e.get(t)),js=(e,t)=>ft(e.delete(t)),Wo=(e,t,n)=>ft(e.put(t,n)),an=(e,t)=>ft(e.add(t)),qo=(e,t,n)=>ft(e.getAll(t,n)),Qo=(e,t,n)=>{let s=null;return tc(e,t,r=>(s=r,!1),n).then(()=>s)},Zo=(e,t=null)=>Qo(e,t,"prev"),Po=(e,t)=>mt((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()}}),tc=(e,t,n,s="next")=>Po(e.openKeyCursor(t,s),r=>n(r.key)),ec=(e,t)=>e.objectStore(t),nc=(e,t)=>IDBKeyRange.upperBound(e,t),sc=(e,t)=>IDBKeyRange.lowerBound(e,t),hn="custom",Ks="updates",Js=500,Xs=(e,t=()=>{},n=()=>{})=>{const[s]=zt(e.db,[Ks]);return qo(s,sc(e._dbref,!1)).then(r=>{e._destroyed||(t(s),b(e.doc,()=>{r.forEach(i=>Wn(e.doc,i))},e,!1),n(s))}).then(()=>Zo(s).then(r=>{e._dbref=r+1})).then(()=>$s(s).then(r=>{e._dbsize=r})).then(()=>s)},rc=(e,t=!0)=>Xs(e).then(n=>{(t||e._dbsize>=Js)&&an(n,Ke(e.doc)).then(()=>js(n,nc(e._dbref,!0))).then(()=>$s(n).then(s=>{e._dbsize=s}))});class ic extends ee{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=Xo(t,s=>zo(s,[["updates",{autoIncrement:!0}],["custom"]])),this.whenSynced=mt(s=>this.on("synced",()=>s(this))),this._db.then(s=>{this.db=s,Xs(this,o=>an(o,Ke(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]=zt(this.db,[Ks]);an(i,s),++this._dbsize>=Js&&(this._storeTimeoutId!==null&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout(()=>{rc(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(()=>{Yo(this.name)})}get(t){return this._db.then(n=>{const[s]=zt(n,[hn],"readonly");return Go(s,t)})}set(t,n){return this._db.then(s=>{const[r]=zt(s,[hn]);return Wo(r,n,t)})}del(t){return this._db.then(n=>{const[s]=zt(n,[hn]);return js(s,t)})}}const Dc="";var It=(e=>(e.CanMove="can-move",e.CanSpin="can-spin",e.CanGrow="can-grow",e.CanToggle="can-toggle",e))(It||{});const oc=(e,t=300)=>{let n;return function(...s){clearTimeout(n),n=setTimeout(()=>e.apply(this,s),t)}},cc={ctrlKey:"Control",altKey:"Alt",shiftKey:"Shift",metaKey:"Meta"},Ys=`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`);m(this,"cutCursor",`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`);m(this,"isHovering",!1);this.maxScale=r,e.addEventListener("mouseenter",o=>this.mouseOverHandler(o)),e.addEventListener("mouseout",o=>{this.isHovering=!1}),e.addEventListener("click",o=>this.clickHandler(o)),document.addEventListener("keydown",o=>{this.isHovering&&this.mouseOverHandler(o)}),document.addEventListener("keyup",o=>{this.isHovering&&this.mouseOverHandler(o)})}updateElement(e){this.element.style.transform=`scale(${e})`}mouseOverHandler(e){if(this.isHovering=!0,e.altKey){if(this.data<=.5){this.element.style.cursor="not-allowed";return}this.element.style.cursor=this.cutCursor}else{if(this.data>=this.maxScale){this.element.style.cursor="not-allowed";return}this.element.style.cursor=this.originalCursor}}clickHandler(e){if(e.altKey){if(this.data<=.5)return;this.data-=.1}else{if(this.element.style.cursor=this.originalCursor,this.data>=this.maxScale)return;this.data+=.1}}}const Oo=typeof PARTYKIT_HOST>"u"?"localhost:1999":PARTYKIT_HOST,ue=new wt,Ns=new Uo(Oo,window.location.href,ue,{connect:!1});Ns.connect();function sn(n){return n.id}const Vs={[at.CanMove]:n=>{const t=ue.getMap(at.CanMove),e=new Map;function s(i,r){const o=t.get(i)||{x:0,y:0};o.x===r.x&&o.y===r.y||t.set(i,r)}for(const i of n){const r=sn(i),o=t.get(r);e.set(r,new Ts(i,o,l=>s(r,l)))}t.observe(i=>{i.changes.keys.forEach((r,o)=>{if(r.action==="add")e.set(o,new Ts(n[0],t.get(o),l=>s(o,l)));else if(r.action==="update"){const l=e.get(o);l.data=t.get(o)}})})},[at.CanSpin]:n=>{const t=ue.getMap(at.CanSpin),e=new Map;function s(i,r){t.get(i)!==r&&t.set(i,r)}for(const i of n){const r=sn(i),o=t.get(r)||0;e.set(r,new Os(i,o,l=>s(r,l)))}t.observe(i=>{i.changes.keys.forEach((r,o)=>{if(r.action==="add")e.set(o,new Os(n[0],t.get(o),l=>s(o,l)));else if(r.action==="update"){const l=e.get(o);l.data=t.get(o)}})})},[at.CanGrow]:n=>{const t=ue.getMap(at.CanGrow),e=new Map;function s(i,r){t.get(i)!==r&&t.set(i,r)}for(const i of n){const r=sn(i),o=t.get(r);e.set(r,new Rs(i,o,l=>s(r,l)))}t.observe(i=>{i.changes.keys.forEach((r,o)=>{if(r.action==="add")e.set(o,new Rs(n[0],t.get(o),l=>s(o,l)));else if(r.action==="update"){const l=e.get(o);l.data=t.get(o)}})})}};Ns.on("sync",n=>{n||console.error("Issue connecting to yjs..."),Hs()});function To(n){return n instanceof HTMLElement}function Hs(){for(const[n,t]of Object.entries(Vs)){const e=Array.from(document.querySelectorAll(`[${n}]`)).filter(To);t(e),e.forEach(s=>{s.classList.add("__playhtml-element"),s.classList.add(`__playhtml-${n}`)})}}U.TagData=Vs,U.setupElements=Hs,Object.defineProperty(U,Symbol.toStringTag,{value:"Module"})});
6
+ auto`,lc=`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 un(e,t,n){if(t.isHovering=!0,e.altKey){if(t.scale<=.5){n.style.cursor="not-allowed";return}n.style.cursor=lc}else{if(t.scale>=t.maxScale){n.style.cursor="not-allowed";return}n.style.cursor=Ys}return{...t}}const zs={[It.CanMove]:{defaultData:{x:0,y:0,startMouseX:0,startMouseY:0},updateElement:(e,t)=>{e.style.transform=`translate(${t.x}px, ${t.y}px)`},onDragStart:(e,t)=>({...t,startMouseX:e.clientX,startMouseY:e.clientY}),onDrag:(e,t)=>({x:t.x+e.clientX-t.startMouseX,y:t.y+e.clientY-t.startMouseY,startMouseX:e.clientX,startMouseY:e.clientY}),resetShortcut:"shiftKey"},[It.CanSpin]:{defaultData:{rotation:0,startMouseX:0},updateElement:(e,t)=>{e.style.transform=`rotate(${t.rotation}deg)`},onDragStart:(e,t)=>({...t,startMouseX:e.clientX}),onDrag:(e,t)=>{let n=Math.abs(e.pageX-t.startMouseX)*2,s=t.rotation;return e.pageX>t.startMouseX?s+=n:e.pageX<t.startMouseX&&(s-=n),{rotation:s,startMouseX:e.pageX}},resetShortcut:"shiftKey"},[It.CanToggle]:{defaultData:!1,updateElement:(e,t)=>{e.classList.toggle("clicked",t)},onClick:(e,t)=>!t,resetShortcut:"shiftKey"},[It.CanGrow]:{defaultData:{scale:1,maxScale:2,isHovering:!1},updateElement:(e,t)=>{e.style.transform=`scale(${t.scale})`},onClick:(e,t,n)=>{if(e.altKey){if(t.scale<=.5)return;t.scale-=.1}else{if(n.style.cursor=Ys,t.scale>=t.maxScale)return;t.scale+=.1}return{...t}},onMouseEnter:un,onKeyDown:un,onKeyUp:un}};class ac{constructor({element:t,onChange:n,defaultData:s,data:r,updateElement:i,onClick:o,onDrag:c,onDragStart:l,onMouseEnter:a,onKeyDown:h,onKeyUp:u,resetShortcut:d,debounceMs:f}){_(this,"defaultData");_(this,"element");_(this,"_data");_(this,"onChange");_(this,"debouncedOnChange");_(this,"resetShortcut");_(this,"updateElement");this.element=t,this.defaultData=s,this.onChange=n,this.resetShortcut=d,this.debouncedOnChange=oc(this.onChange,f),this.updateElement=i;const g=r===void 0?s:r;this._data=g,this.__data=g,o&&t.addEventListener("click",w=>{const k=o(w,this.data,this.element);k!==void 0&&(this.data=k)}),c&&t.addEventListener("mousedown",w=>{if(l){const Lt=l(w,this.data,this.element);Lt!==void 0&&(this.data=Lt)}const k=Lt=>{Lt.preventDefault();const Ps=c(Lt,this.data,this.element);Ps!==void 0&&(this.data=Ps)},At=Lt=>{document.removeEventListener("mousemove",k),document.removeEventListener("mouseup",At)};document.addEventListener("mousemove",k),document.addEventListener("mouseup",At)}),a&&t.addEventListener("mouseenter",w=>{const k=a(w,this.data,this.element);k!==void 0&&(this.data=k)}),h&&t.addEventListener("keydown",w=>{const k=h(w,this.data,this.element);k!==void 0&&(this.data=k)}),u&&t.addEventListener("keyup",w=>{const k=u(w,this.data,this.element);k!==void 0&&(this.data=k)}),d&&(t.title||(t.title=`Hold down the ${cc[d]} key while clicking to reset.`),t.addEventListener("click",w=>{switch(d){case"ctrlKey":if(!w.ctrlKey)return;break;case"altKey":if(!w.altKey)return;break;case"shiftKey":if(!w.shiftKey)return;break;case"metaKey":if(!w.metaKey)return;break;default:return}this.reset(),w.preventDefault(),w.stopPropagation()}))}get data(){return this._data}set __data(t){this._data=t,this.updateElement(this.element,t)}set data(t){this.onChange(t)}setDataDebounced(t){this.debouncedOnChange(t)}reset(){this.data=this.defaultData}}const hc=process!==void 0&&process.env.NODE_ENV==="development"?"localhost:1999":"playhtml.spencerc99.partykit.dev",dn=new _t,Gs=window.location.href,Ws=new Jo(hc,Gs,dn,{connect:!1});new ic(Gs,dn),Ws.connect();const G=dn.getMap("playhtml-global");function fn(e){return e.id}function uc(e){return document.getElementById(e)}Ws.on("sync",e=>{e||console.error("Issue connecting to yjs..."),Zs()});function qs(e){return e instanceof HTMLElement}function Qs(e,t){const n=zs[t],s=G.get(t),r=fn(e),i={...n,data:s.get(r)||n.defaultData,element:e,onChange:o=>{s.get(r)!==o&&s.set(r,o)}};return new ac(i)}function Zs(){const e=new Map;console.log("EXISTING DATA",G.toJSON());for(const t of Object.values(It)){const n=Array.from(document.querySelectorAll(`[${t}]`)).filter(qs);if(!n.length)continue;const s=zs[t];if(console.log(s),!s)continue;console.log(`initializing ${t}`),G.get(t)||G.set(t,new lt);const r=G.get(t);for(const i of n){const o=Qs(i,t);e.set(fn(i),o),i.classList.add("__playhtml-element"),i.classList.add(`__playhtml-${t}`)}r.observe(i=>{i.changes.keys.forEach((o,c)=>{if(o.action==="add"){const l=uc(c);if(!qs(l)){console.log(`Element ${c} not an HTML element. Ignoring.`);return}const a=Qs(l,t);e.set(fn(l),a)}else if(o.action==="update"){const l=e.get(c);l.__data=r.get(c)}else o.action==="delete"?e.delete(c):console.log(`Unhandled action: ${o.action}`)})})}G.observe(t=>{t.changes.keys.forEach((n,s)=>{n.action==="add"&&G.set(s,G.get(s))})})}T.globalData=G,T.setupElements=Zs,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
package/dist/style.css CHANGED
@@ -1 +1 @@
1
- .__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}
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}
package/dist/types.d.ts CHANGED
@@ -1,15 +1,21 @@
1
- import { GrowElement, MoveElement, SpinElement } from "./elements";
2
- export type Position = {
1
+ export type MoveData = {
3
2
  x: number;
4
3
  y: number;
4
+ startMouseX: number;
5
+ startMouseY: number;
6
+ };
7
+ export type SpinData = {
8
+ rotation: number;
9
+ startMouseX: number;
10
+ };
11
+ export type GrowData = {
12
+ scale: number;
13
+ maxScale: number;
14
+ isHovering: boolean;
5
15
  };
6
- export interface TagTypeToElement {
7
- [TagType.CanMove]: MoveElement;
8
- [TagType.CanSpin]: SpinElement;
9
- [TagType.CanGrow]: GrowElement;
10
- }
11
16
  export declare enum TagType {
12
17
  "CanMove" = "can-move",
13
18
  "CanSpin" = "can-spin",
14
- "CanGrow" = "can-grow"
19
+ "CanGrow" = "can-grow",
20
+ "CanToggle" = "can-toggle"
15
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playhtml",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/playhtml.umd.js",
@@ -18,6 +18,7 @@
18
18
  "scripts": {
19
19
  "dev": "vite",
20
20
  "build": "tsc && vite build",
21
+ "build-site": "vite build --config vite.config.site.ts",
21
22
  "preview": "vite preview",
22
23
  "publish-npm": "yarn run build && yarn publish"
23
24
  },
@@ -32,6 +33,7 @@
32
33
  "dependencies": {
33
34
  "partykit": "^0.0.0-e7aa4cd",
34
35
  "partysocket": "^0.0.0-e7aa4cd",
36
+ "y-indexeddb": "^9.0.11",
35
37
  "y-partykit": "^0.0.0-e7aa4cd",
36
38
  "yjs": "^13.6.6"
37
39
  }