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