playhtml 2.1.0 → 2.1.1
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 +4 -0
- package/README.md +2 -2
- package/dist/init.es.js +2 -0
- package/dist/playhtml.es.js +6499 -1676
- package/package.json +2 -2
- package/dist/playhtml.umd.js +0 -37
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.1.
|
|
5
|
+
"version": "2.1.1",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"keywords": [
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"vite-plugin-dts": "^3.0.3"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@playhtml/common": "^0.0.
|
|
62
|
+
"@playhtml/common": "^0.0.9",
|
|
63
63
|
"partysocket": "^0.0.25",
|
|
64
64
|
"y-indexeddb": "^9.0.11",
|
|
65
65
|
"y-partykit": "^0.0.10",
|
package/dist/playhtml.umd.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
(function(S,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(S=typeof globalThis<"u"?globalThis:S||self,b(S.playhtml={}))})(this,function(S){var kt,vr,xr;"use strict";var Ll=Object.defineProperty;var vl=(S,b,v)=>b in S?Ll(S,b,{enumerable:!0,configurable:!0,writable:!0,value:v}):S[b]=v;var p=(S,b,v)=>(vl(S,typeof b!="symbol"?b+"":b,v),v),Ir=(S,b,v)=>{if(!b.has(S))throw TypeError("Cannot "+v)};var Me=(S,b,v)=>(Ir(S,b,"read from private field"),v?v.call(S):b.get(S)),Tr=(S,b,v)=>{if(b.has(S))throw TypeError("Cannot add the same private member more than once");b instanceof WeakSet?b.add(S):b.set(S,v)},Mr=(S,b,v,Ot)=>(Ir(S,b,"write to private field"),Ot?Ot.call(S,v):b.set(S,v),v);var b=1e6,v="y-pk-batch",Ot=!1,Ur=(n,t)=>{if(n.byteLength<=b){t(n);return}Ot||(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`),Ot=!0);const e=(Date.now()+Math.random()).toString(36).substring(10),s=Math.ceil(n.byteLength/b);t(Mn({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(b*o,b*(o+1));t(c),i+=1,r+=c.byteLength}t(Mn({id:e,type:"end",size:r,count:i}))};function Mn(n){return`${v}#${JSON.stringify(n)}`}const F=()=>new Map,Ue=n=>{const t=F();return n.forEach((e,s)=>{t.set(s,e)}),t},K=(n,t,e)=>{let s=n.get(t);return s===void 0&&n.set(t,s=e()),s},Or=(n,t)=>{const e=[];for(const[s,r]of n)e.push(t(r,s));return e},Nr=(n,t)=>{for(const[e,s]of n)if(t(s,e))return!0;return!1},ot=()=>new Set,Oe=n=>n[n.length-1],Rr=(n,t)=>{for(let e=0;e<t.length;e++)n.push(t[e])},Z=Array.from,Br=Array.isArray;class ne{constructor(){this._observers=F()}on(t,e){K(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 Z((this._observers.get(t)||F()).values()).forEach(s=>s(...e))}destroy(){this._observers=F()}}const z=Math.floor,se=Math.abs,Ne=(n,t)=>n<t?n:t,ct=(n,t)=>n>t?n:t,Fr=Math.pow,Un=n=>n!==0?n<0:1/n<0,Hr=String.fromCharCode,Vr=n=>n.toLowerCase(),$r=/^\s*/g,jr=n=>n.replace($r,""),Wr=/([A-Z])/g,On=(n,t)=>jr(n.replace(Wr,e=>`${t}${Vr(e)}`)),Kr=n=>{const t=unescape(encodeURIComponent(n)),e=t.length,s=new Uint8Array(e);for(let r=0;r<e;r++)s[r]=t.codePointAt(r);return s},Nt=typeof TextEncoder<"u"?new TextEncoder:null,zr=Nt?n=>Nt.encode(n):Kr;let Rt=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Rt&&Rt.decode(new Uint8Array).length===1&&(Rt=null);const Nn=n=>n===void 0?null:n;class Pr{constructor(){this.map=new Map}setItem(t,e){this.map.set(t,e)}getItem(t){return this.map.get(t)}}let Rn=new Pr,Re=!0;try{typeof localStorage<"u"&&(Rn=localStorage,Re=!1)}catch{}const Bn=Rn,Yr=n=>Re||addEventListener("storage",n),Jr=n=>Re||removeEventListener("storage",n),Xr=Object.assign,Gr=Object.keys,qr=(n,t)=>{for(const e in n)t(n[e],e)},Qr=(n,t)=>{const e=[];for(const s in n)e.push(t(n[s],s));return e},re=n=>Gr(n).length,Zr=n=>{for(const t in n)return!1;return!0},ti=(n,t)=>{for(const e in n)if(!t(n[e],e))return!1;return!0},Fn=(n,t)=>Object.prototype.hasOwnProperty.call(n,t),ei=(n,t)=>n===t||re(n)===re(t)&&ti(n,(e,s)=>(e!==void 0||Fn(t,s))&&t[s]===e),Be=(n,t,e=0)=>{try{for(;e<n.length;e++)n[e](...t)}finally{e<n.length&&Be(n,t,e+1)}},ni=n=>n,si=(n,t)=>n===t,Bt=(n,t)=>{if(n==null||t==null)return si(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)||!Bt(n.get(e),t.get(e)))return!1;break}case Object:if(re(n)!==re(t))return!1;for(const e in n)if(!Fn(n,e)||!Bt(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(!Bt(n[e],t[e]))return!1;break;default:return!1}return!0},ri=(n,t)=>t.includes(n),Et=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name),Hn=typeof window<"u"&&typeof document<"u"&&!Et;let H;const ii=()=>{if(H===void 0)if(Et){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(`--${On(t,"-")}`,e),H.set(`-${On(t,"-")}`,e)}})):H=F();return H},Fe=n=>ii().has(n),He=n=>Nn(Et?process.env[n.toUpperCase()]:Bn.getItem(n));(n=>Fe("--"+n)||He(n)!==null)("production");const Vn=Et&&ri(process.env.FORCE_COLOR,["true","1","2"]),oi=!Fe("no-colors")&&(!Et||process.stdout.isTTY||Vn)&&(!Et||Fe("color")||Vn||He("COLORTERM")!==null||(He("TERM")||"").includes("color")),$n=1,jn=2,Ve=4,$e=8,Ft=32,P=64,O=128,ie=31,je=63,lt=127,ci=2147483647,Wn=Number.MAX_SAFE_INTEGER,li=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&z(n)===n),Y=n=>new Error(n),V=()=>{throw Y("Method unimplemented")},$=()=>{throw Y("Unexpected case")},Kn=Y("Unexpected end of array"),zn=Y("Integer out of Range");class oe{constructor(t){this.arr=t,this.pos=0}}const tt=n=>new oe(n),ai=n=>n.pos!==n.arr.length,hi=(n,t)=>{const e=Pe(n.arr.buffer,n.pos+n.arr.byteOffset,t);return n.pos+=t,e},M=n=>hi(n,y(n)),Dt=n=>n.arr[n.pos++],y=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>Wn)throw zn}throw Kn},We=n=>{let t=n.arr[n.pos++],e=t&je,s=64;const r=(t&P)>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>Wn)throw zn}throw Kn},et=Rt?n=>Rt.decode(M(n)):n=>{let t=y(n);if(t===0)return"";{let e=String.fromCodePoint(Dt(n));if(--t<100)for(;t--;)e+=String.fromCodePoint(Dt(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))}},Ke=(n,t)=>{const e=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,t);return n.pos+=t,e},ui=[n=>{},n=>null,We,n=>Ke(n,4).getFloat32(0,!1),n=>Ke(n,8).getFloat64(0,!1),n=>Ke(n,8).getBigInt64(0,!1),n=>!1,n=>!0,et,n=>{const t=y(n),e={};for(let s=0;s<t;s++){const r=et(n);e[r]=Ht(n)}return e},n=>{const t=y(n),e=[];for(let s=0;s<t;s++)e.push(Ht(n));return e},M],Ht=n=>ui[127-Dt(n)](n);class Pn extends oe{constructor(t,e){super(t),this.reader=e,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),ai(this)?this.count=y(this)+1:this.count=-1),this.count--,this.s}}class ce extends oe{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=We(this);const t=Un(this.s);this.count=1,t&&(this.s=-this.s,this.count=y(this)+2)}return this.count--,this.s}}class ze extends oe{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=We(this),e=t&1;this.diff=z(t/2),this.count=1,e&&(this.count=y(this)+2)}return this.s+=this.diff,this.count--,this.s}}class di{constructor(t){this.decoder=new ce(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 Yn=n=>new Uint8Array(n),Pe=(n,t,e)=>new Uint8Array(n,t,e),fi=n=>new Uint8Array(n),gi=n=>{let t="";for(let e=0;e<n.byteLength;e++)t+=Hr(n[e]);return btoa(t)},pi=n=>Buffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),wi=n=>{const t=atob(n),e=Yn(t.length);for(let s=0;s<t.length;s++)e[s]=t.charCodeAt(s);return e},mi=n=>{const t=Buffer.from(n,"base64");return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)},yi=Hn?gi:pi,_i=Hn?wi:mi,bi=n=>{const t=Yn(n.byteLength);return t.set(n),t};class Vt{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const U=()=>new Vt,Ye=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(Ye(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(Pe(n.cbuf.buffer,0,n.cpos),e),t},ki=(n,t)=>{const e=n.cbuf.length;e-n.cpos<t&&(n.bufs.push(Pe(n.cbuf.buffer,0,n.cpos)),n.cbuf=new Uint8Array(ct(e,t)*2),n.cpos=0)},x=(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=x,w=(n,t)=>{for(;t>lt;)x(n,O|lt&t),t=z(t/128);x(n,lt&t)},Xe=(n,t)=>{const e=Un(t);for(e&&(t=-t),x(n,(t>je?O:0)|(e?P:0)|je&t),t=z(t/64);t>0;)x(n,(t>lt?O:0)|lt&t),t=z(t/128)},Ge=new Uint8Array(3e4),Si=Ge.length/3,Ei=(n,t)=>{if(t.length<Si){const e=Nt.encodeInto(t,Ge).written||0;w(n,e);for(let s=0;s<e;s++)x(n,Ge[s])}else C(n,zr(t))},Di=(n,t)=>{const e=unescape(encodeURIComponent(t)),s=e.length;w(n,s);for(let r=0;r<s;r++)x(n,e.codePointAt(r))},at=Nt&&Nt.encodeInto?Ei:Di,le=(n,t)=>{const e=n.cbuf.length,s=n.cpos,r=Ne(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)=>{w(n,t.byteLength),le(n,t)},qe=(n,t)=>{ki(n,t);const e=new DataView(n.cbuf.buffer,n.cpos,t);return n.cpos+=t,e},Ci=(n,t)=>qe(n,4).setFloat32(0,t,!1),Ai=(n,t)=>qe(n,8).setFloat64(0,t,!1),Li=(n,t)=>qe(n,8).setBigInt64(0,t,!1),Jn=new DataView(new ArrayBuffer(4)),vi=n=>(Jn.setFloat32(0,n),Jn.getFloat32(0)===n),$t=(n,t)=>{switch(typeof t){case"string":x(n,119),at(n,t);break;case"number":li(t)&&se(t)<=ci?(x(n,125),Xe(n,t)):vi(t)?(x(n,124),Ci(n,t)):(x(n,123),Ai(n,t));break;case"bigint":x(n,122),Li(n,t);break;case"object":if(t===null)x(n,126);else if(Br(t)){x(n,117),w(n,t.length);for(let e=0;e<t.length;e++)$t(n,t[e])}else if(t instanceof Uint8Array)x(n,116),C(n,t);else{x(n,118);const e=Object.keys(t);w(n,e.length);for(let s=0;s<e.length;s++){const r=e[s];at(n,r),$t(n,t[r])}}break;case"boolean":x(n,t?120:121);break;default:x(n,127)}};class Xn extends Vt{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&w(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const Gn=n=>{n.count>0&&(Xe(n.encoder,n.count===1?n.s:-n.s),n.count>1&&w(n.encoder,n.count-2))};class ae{constructor(){this.encoder=new Vt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(Gn(this),this.count=1,this.s=t)}toUint8Array(){return Gn(this),D(this.encoder)}}const qn=n=>{if(n.count>0){const t=n.diff*2+(n.count===1?0:1);Xe(n.encoder,t),n.count>1&&w(n.encoder,n.count-2)}};class Qe{constructor(){this.encoder=new Vt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(qn(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return qn(this),D(this.encoder)}}class xi{constructor(){this.sarr=[],this.s="",this.lensE=new ae}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new Vt;return this.sarr.push(this.s),this.s="",at(t,this.sarr.join("")),le(t,this.lensE.toUint8Array()),D(t)}}const Ii=crypto.getRandomValues.bind(crypto),Qn=()=>Ii(new Uint32Array(1))[0],Ti=[1e7]+-1e3+-4e3+-8e3+-1e11,Mi=()=>Ti.replace(/[018]/g,n=>(n^Qn()&15>>n/4).toString(16)),ht=Date.now,Ct=n=>new Promise(n);Promise.all.bind(Promise);class Ui{constructor(t,e){this.left=t,this.right=e}}const J=(n,t)=>new Ui(n,t);typeof DOMParser<"u"&&new DOMParser;const Oi=n=>Or(n,(t,e)=>`${e}:${t};`).join(""),X=Symbol,Zn=X(),ts=X(),Ni=X(),Ri=X(),Bi=X(),es=X(),Fi=X(),ns=X(),Hi=X(),Vi=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},$i={[Zn]:J("font-weight","bold"),[ts]:J("font-weight","normal"),[Ni]:J("color","blue"),[Bi]:J("color","green"),[Ri]:J("color","grey"),[es]:J("color","red"),[Fi]:J("color","purple"),[ns]:J("color","orange"),[Hi]:J("color","black")},ji=oi?n=>{const t=[],e=[],s=F();let r=[],i=0;for(;i<n.length;i++){const o=n[i],c=$i[o];if(c!==void 0)s.set(c.left,c.right);else if(o.constructor===String||o.constructor===Number){const l=Oi(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}:Vi,Wi=(...n)=>{console.log(...ji(n)),Ki.forEach(t=>t.print(n))},Ki=ot(),ss=n=>({[Symbol.iterator](){return this},next:n}),zi=(n,t)=>ss(()=>{let e;do e=n.next();while(!e.done&&!t(e.value));return e}),Ze=(n,t)=>ss(()=>{const{done:e,value:s}=n.next();return{done:e,value:e?void 0:t(s)}});class tn{constructor(t,e){this.clock=t,this.len=e}}class jt{constructor(){this.clients=new Map}}const rs=(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];Es(n,i,c.clock,c.len,e)}}),Pi=(n,t)=>{let e=0,s=n.length-1;for(;e<=s;){const r=z((e+s)/2),i=n[r],o=i.clock;if(o<=t){if(t<o+i.len)return r;e=r+1}else s=r-1}return null},is=(n,t)=>{const e=n.clients.get(t.client);return e!==void 0&&Pi(e,t.clock)!==null},en=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})},Yi=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++)Rr(i,n[o].clients.get(r)||[]);t.clients.set(r,i)}});return en(t),t},he=(n,t,e,s)=>{K(n.clients,t,()=>[]).push(new tn(e,s))},Ji=()=>new jt,Xi=n=>{const t=Ji();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 tn(c,l))}}r.length>0&&t.clients.set(s,r)}),t},At=(n,t)=>{w(n.restEncoder,t.clients.size),Z(t.clients.entries()).sort((e,s)=>s[0]-e[0]).forEach(([e,s])=>{n.resetDsCurVal(),w(n.restEncoder,e);const r=s.length;w(n.restEncoder,r);for(let i=0;i<r;i++){const o=s[i];n.writeDsClock(o.clock),n.writeDsLen(o.len)}})},nn=n=>{const t=new jt,e=y(n.restDecoder);for(let s=0;s<e;s++){n.resetDsCurVal();const r=y(n.restDecoder),i=y(n.restDecoder);if(i>0){const o=K(t.clients,r,()=>[]);for(let c=0;c<i;c++)o.push(new tn(n.readDsClock(),n.readDsLen()))}}return t},os=(n,t,e)=>{const s=new jt,r=y(n.restDecoder);for(let i=0;i<r;i++){n.resetDsCurVal();const o=y(n.restDecoder),c=y(n.restDecoder),l=e.clients.get(o)||[],a=I(e,o);for(let h=0;h<c;h++){const u=n.readDsClock(),d=u+n.readDsLen();if(u<a){a<d&&he(s,o,a,d-a);let f=j(l,u),g=l[f];for(!g.deleted&&g.id.clock<u&&(l.splice(f+1,0,Ce(t,g,u-g.id.clock)),f++);f<l.length&&(g=l[f++],g.id.clock<d);)g.deleted||(d<g.id.clock+g.length&&l.splice(f,0,Ce(t,g,d-g.id.clock)),g.delete(t))}else he(s,o,u,d-u)}}if(s.clients.size>0){const i=new dt;return w(i.restEncoder,0),At(i,s),i.toUint8Array()}return null},cs=Qn;class ut extends ne{constructor({guid:t=Mi(),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=cs(),this.guid=t,this.collectionid=e,this.share=new Map,this.store=new bs,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=Ct(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const l=()=>Ct(a=>{const h=u=>{(u===void 0||u===!0)&&(this.off("sync",h),a())};this.on("sync",h)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=a===void 0||a===!0,this.isLoaded||this.emit("load",[])}),this.whenSynced=l()}load(){const t=this._item;t!==null&&!this.shouldLoad&&k(t.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Z(this.subdocs).map(t=>t.guid))}transact(t,e=null){return k(this,t,e)}get(t,e=T){const s=K(this.share,t,()=>{const i=new e;return i._integrate(this,null),i}),r=s.constructor;if(e!==T&&r!==e)if(r===T){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,xt)}getText(t=""){return this.get(t,Tt)}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(){Z(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,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 ls{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return y(this.restDecoder)}readDsLen(){return y(this.restDecoder)}}class as extends ls{readLeftID(){return _(y(this.restDecoder),y(this.restDecoder))}readRightID(){return _(y(this.restDecoder),y(this.restDecoder))}readClient(){return y(this.restDecoder)}readInfo(){return Dt(this.restDecoder)}readString(){return et(this.restDecoder)}readParentInfo(){return y(this.restDecoder)===1}readTypeRef(){return y(this.restDecoder)}readLen(){return y(this.restDecoder)}readAny(){return Ht(this.restDecoder)}readBuf(){return bi(M(this.restDecoder))}readJSON(){return JSON.parse(et(this.restDecoder))}readKey(){return et(this.restDecoder)}}class Gi{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=y(this.restDecoder),this.dsCurrVal}readDsLen(){const t=y(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class Lt extends Gi{constructor(t){super(t),this.keys=[],y(t),this.keyClockDecoder=new ze(M(t)),this.clientDecoder=new ce(M(t)),this.leftClockDecoder=new ze(M(t)),this.rightClockDecoder=new ze(M(t)),this.infoDecoder=new Pn(M(t),Dt),this.stringDecoder=new di(M(t)),this.parentInfoDecoder=new Pn(M(t),Dt),this.typeRefDecoder=new ce(M(t)),this.lenDecoder=new ce(M(t))}readLeftID(){return new vt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new vt(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 Ht(this.restDecoder)}readBuf(){return M(this.restDecoder)}readJSON(){return Ht(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 hs{constructor(){this.restEncoder=U()}toUint8Array(){return D(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){w(this.restEncoder,t)}writeDsLen(t){w(this.restEncoder,t)}}class Wt extends hs{writeLeftID(t){w(this.restEncoder,t.client),w(this.restEncoder,t.clock)}writeRightID(t){w(this.restEncoder,t.client),w(this.restEncoder,t.clock)}writeClient(t){w(this.restEncoder,t)}writeInfo(t){Je(this.restEncoder,t)}writeString(t){at(this.restEncoder,t)}writeParentInfo(t){w(this.restEncoder,t?1:0)}writeTypeRef(t){w(this.restEncoder,t)}writeLen(t){w(this.restEncoder,t)}writeAny(t){$t(this.restEncoder,t)}writeBuf(t){C(this.restEncoder,t)}writeJSON(t){at(this.restEncoder,JSON.stringify(t))}writeKey(t){at(this.restEncoder,t)}}class us{constructor(){this.restEncoder=U(),this.dsCurrVal=0}toUint8Array(){return D(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const e=t-this.dsCurrVal;this.dsCurrVal=t,w(this.restEncoder,e)}writeDsLen(t){t===0&&$(),w(this.restEncoder,t-1),this.dsCurrVal+=t}}class dt extends us{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Qe,this.clientEncoder=new ae,this.leftClockEncoder=new Qe,this.rightClockEncoder=new Qe,this.infoEncoder=new Xn(Je),this.stringEncoder=new xi,this.parentInfoEncoder=new Xn(Je),this.typeRefEncoder=new ae,this.lenEncoder=new ae}toUint8Array(){const t=U();return w(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()),le(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){$t(this.restEncoder,t)}writeBuf(t){C(this.restEncoder,t)}writeJSON(t){$t(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 qi=(n,t,e,s)=>{s=ct(s,t[0].id.clock);const r=j(t,s);w(n.restEncoder,t.length-r),n.writeClient(e),w(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)},sn=(n,t,e)=>{const s=new Map;e.forEach((r,i)=>{I(t,i)>r&&s.set(i,r)}),de(t).forEach((r,i)=>{e.has(i)||s.set(i,0)}),w(n.restEncoder,s.size),Z(s.entries()).sort((r,i)=>i[0]-r[0]).forEach(([r,i])=>{qi(n,t.clients.get(r),r,i)})},Qi=(n,t)=>{const e=F(),s=y(n.restDecoder);for(let r=0;r<s;r++){const i=y(n.restDecoder),o=new Array(i),c=n.readClient();let l=y(n.restDecoder);e.set(c,{i:0,refs:o});for(let a=0;a<i;a++){const h=n.readInfo();switch(ie&h){case 0:{const u=n.readLen();o[a]=new N(_(c,l),u),l+=u;break}case 10:{const u=y(n.restDecoder);o[a]=new R(_(c,l),u),l+=u;break}default:{const u=(h&(P|O))===0,d=new L(_(c,l),null,(h&O)===O?n.readLeftID():null,null,(h&P)===P?n.readRightID():null,u?n.readParentInfo()?t.get(n.readString()):n.readLeftID():null,u&&(h&Ft)===Ft?n.readString():null,Js(n,h));o[a]=d,l+=d.length}}}}return e},Zi=(n,t,e)=>{const s=[];let r=Z(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 bs,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 u=new Map,d=()=>{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!==R){const g=K(u,h.id.client,()=>I(t,h.id.client))-h.id.clock;if(g<0)s.push(h),a(h.id.client,h.id.clock-1),d();else{const 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,I(t,m)),d();else{h=E.refs[E.i++];continue}}else(g===0||g<h.length)&&(h.integrate(n,g),u.set(h.id.client,h.id.clock+h.length))}}if(s.length>0)h=s.pop();else if(o!==null&&o.i<o.refs.length)h=o.refs[o.i++];else{if(o=i(),o===null)break;h=o.refs[o.i++]}}if(c.clients.size>0){const f=new dt;return sn(f,c,new Map),w(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},to=(n,t)=>sn(n,t.doc.store,t.beforeState),eo=(n,t,e,s=new Lt(n))=>k(t,r=>{r.local=!1;let i=!1;const o=r.doc,c=o.store,l=Qi(s,o),a=Zi(r,c,l),h=c.pendingStructs;if(h){for(const[d,f]of h.missing)if(f<I(c,d)){i=!0;break}if(a){for(const[d,f]of a.missing){const g=h.missing.get(d);(g==null||g>f)&&h.missing.set(d,f)}h.update=ge([h.update,a.update])}}else c.pendingStructs=a;const u=os(s,r,c);if(c.pendingDs){const d=new Lt(tt(c.pendingDs));y(d.restDecoder);const f=os(d,r,c);u&&f?c.pendingDs=ge([u,f]):c.pendingDs=u||f}else c.pendingDs=u;if(i){const d=c.pendingStructs.update;c.pendingStructs=null,ds(r.doc,d)}},e,!1),ds=(n,t,e,s=Lt)=>{const r=tt(t);eo(r,n,e,new s(r))},fs=(n,t,e)=>ds(n,t,e,as),no=(n,t,e=new Map)=>{sn(n,t.store,e),At(n,Xi(t.store))},so=(n,t=new Uint8Array([0]),e=new dt)=>{const s=gs(t);no(e,n,s);const r=[e.toUint8Array()];if(n.store.pendingDs&&r.push(n.store.pendingDs),n.store.pendingStructs&&r.push(yo(n.store.pendingStructs.update,t)),r.length>1){if(e.constructor===Wt)return wo(r.map((i,o)=>o===0?i:bo(i)));if(e.constructor===dt)return ge(r)}return r[0]},rn=(n,t)=>so(n,t,new Wt),ro=n=>{const t=new Map,e=y(n.restDecoder);for(let s=0;s<e;s++){const r=y(n.restDecoder),i=y(n.restDecoder);t.set(r,i)}return t},gs=n=>ro(new ls(tt(n))),ps=(n,t)=>(w(n.restEncoder,t.size),Z(t.entries()).sort((e,s)=>s[0]-e[0]).forEach(([e,s])=>{w(n.restEncoder,e),w(n.restEncoder,s)}),n),io=(n,t)=>ps(n,de(t.store)),oo=(n,t=new us)=>(n instanceof Map?ps(t,n):io(t,n),t.toUint8Array()),co=n=>oo(n,new hs);class lo{constructor(){this.l=[]}}const ws=()=>new lo,ms=(n,t)=>n.l.push(t),ys=(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.")},_s=(n,t,e)=>Be(n.l,[t,e]);class vt{constructor(t,e){this.client=t,this.clock=e}}const ue=(n,t)=>n===t||n!==null&&t!==null&&n.client===t.client&&n.clock===t.clock,_=(n,t)=>new vt(n,t),ao=n=>{for(const[t,e]of n.doc.share.entries())if(e===n)return t;throw $()},Kt=(n,t)=>t===void 0?!n.deleted:t.sv.has(n.id.client)&&(t.sv.get(n.id.client)||0)>n.id.clock&&!is(t.ds,n.id),on=(n,t)=>{const e=K(n.meta,on,ot),s=n.doc.store;e.has(t)||(t.sv.forEach((r,i)=>{r<I(s,i)&&nt(n,_(i,r))}),rs(n,t.ds,r=>{}),e.add(t))};class bs{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const de=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},I=(n,t)=>{const e=n.clients.get(t);if(e===void 0)return 0;const s=e[e.length-1];return s.id.clock+s.length},ks=(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=z(t/(i+r.length-1)*s);for(;e<=s;){if(r=n[o],i=r.id.clock,i<=t){if(t<i+r.length)return o;e=o+1}else s=o-1;o=z((e+s)/2)}throw $()},cn=(n,t)=>{const e=n.clients.get(t.client);return e[j(e,t.clock)]},ln=(n,t,e)=>{const s=j(t,e),r=t[s];return r.id.clock<e&&r instanceof L?(t.splice(s+1,0,Ce(n,r,e-r.id.clock)),s+1):s},nt=(n,t)=>{const e=n.doc.store.clients.get(t.client);return e[ln(n,e,t.clock)]},Ss=(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,Ce(n,i,e.clock-i.id.clock+1)),i},ho=(n,t,e)=>{const s=n.clients.get(t.id.client);s[j(s,t.id.clock)]=e},Es=(n,t,e,s,r)=>{if(s===0)return;const i=e+s;let o=ln(n,t,e),c;do c=t[o++],i<c.id.clock+c.length&&ln(n,t,i),r(c);while(o<t.length&&t[o].id.clock<i)};class uo{constructor(t,e,s){this.doc=t,this.deleteSet=new jt,this.beforeState=de(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 Ds=(n,t)=>t.deleteSet.clients.size===0&&!Nr(t.afterState,(e,s)=>t.beforeState.get(s)!==e)?!1:(en(t.deleteSet),to(n,t),At(n,t.deleteSet),!0),Cs=(n,t,e)=>{const s=t._item;(s===null||s.id.clock<(n.beforeState.get(s.id.client)||0)&&!s.deleted)&&K(n.changed,t,ot).add(e)},fe=(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 L&&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},fo=(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 u=i[a];if(c.clock+c.len<=u.id.clock)break;u instanceof L&&u.deleted&&!u.keep&&e(u)&&u.gc(t,!1)}}}},go=(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=Ne(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+fe(r,l)}})},As=(n,t)=>{if(t<n.length){const e=n[t],s=e.doc,r=s.store,i=e.deleteSet,o=e._mergeStructs;try{en(i),e.afterState=de(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,u)=>h.path.length-u.path.length),_s(a._dEH,l,e))})}),c.push(()=>s.emit("afterTransaction",[e,s])),Be(c,[]),e._needFormattingCleanup&&Uo(e)}finally{s.gc&&fo(i,r,s.gcFilter),go(i,r),e.afterState.forEach((h,u)=>{const d=e.beforeState.get(u)||0;if(d!==h){const f=r.clients.get(u),g=ct(j(f,d),1);for(let m=f.length-1;m>=g;)m-=1+fe(f,m)}});for(let h=o.length-1;h>=0;h--){const{client:u,clock:d}=o[h].id,f=r.clients.get(u),g=j(f,d);g+1<f.length&&fe(f,g+1)>1||g>0&&fe(f,g)}if(!e.local&&e.afterState.get(s.clientID)!==e.beforeState.get(s.clientID)&&(Wi(ns,Zn,"[yjs] ",ts,es,"Changed the client-id because another client seems to be using it."),s.clientID=cs()),s.emit("afterTransactionCleanup",[e,s]),s._observers.has("update")){const h=new Wt;Ds(h,e)&&s.emit("update",[h.toUint8Array(),e.origin,s,e])}if(s._observers.has("updateV2")){const h=new dt;Ds(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])):As(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 uo(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&&As(r,0)}}return o};function*po(n){const t=y(n.restDecoder);for(let e=0;e<t;e++){const s=y(n.restDecoder),r=n.readClient();let i=y(n.restDecoder);for(let o=0;o<s;o++){const c=n.readInfo();if(c===10){const l=y(n.restDecoder);yield new R(_(r,i),l),i+=l}else if(ie&c){const l=(c&(P|O))===0,a=new L(_(r,i),null,(c&O)===O?n.readLeftID():null,null,(c&P)===P?n.readRightID():null,l?n.readParentInfo()?n.readString():n.readLeftID():null,l&&(c&Ft)===Ft?n.readString():null,Js(n,c));yield a,i+=a.length}else{const l=n.readLen();yield new N(_(r,i),l),i+=l}}}}class an{constructor(t,e){this.gen=po(t),this.curr=null,this.done=!1,this.filterSkips=e,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===R);return this.curr}}class hn{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const wo=n=>ge(n,as,Wt),mo=(n,t)=>{if(n.constructor===N){const{client:e,clock:s}=n.id;return new N(_(e,s+t),n.length-t)}else if(n.constructor===R){const{client:e,clock:s}=n.id;return new R(_(e,s+t),n.length-t)}else{const e=n,{client:s,clock:r}=e.id;return new L(_(s,r+t),null,_(s,r+t-1),null,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t))}},ge=(n,t=Lt,e=dt)=>{if(n.length===1)return n[0];const s=n.map(h=>new t(tt(h)));let r=s.map(h=>new an(h,!0)),i=null;const o=new e,c=new hn(o);for(;r=r.filter(d=>d.curr!==null),r.sort((d,f)=>{if(d.curr.id.client===f.curr.id.client){const g=d.curr.id.clock-f.curr.id.clock;return g===0?d.curr.constructor===f.curr.constructor?0:d.curr.constructor===R?1:-1:g}else return f.curr.id.client-d.curr.id.client}),r.length!==0;){const h=r[0],u=h.curr.id.client;if(i!==null){let d=h.curr,f=!1;for(;d!==null&&d.id.clock+d.length<=i.struct.id.clock+i.struct.length&&d.id.client>=i.struct.id.client;)d=h.next(),f=!0;if(d===null||d.id.client!==u||f&&d.id.clock>i.struct.id.clock+i.struct.length)continue;if(u!==i.struct.id.client)st(c,i.struct,i.offset),i={struct:d,offset:0},h.next();else if(i.struct.id.clock+i.struct.length<d.id.clock)if(i.struct.constructor===R)i.struct.length=d.id.clock+d.length-i.struct.id.clock;else{st(c,i.struct,i.offset);const g=d.id.clock-i.struct.id.clock-i.struct.length;i={struct:new R(_(u,i.struct.id.clock+i.struct.length),g),offset:0}}else{const g=i.struct.id.clock+i.struct.length-d.id.clock;g>0&&(i.struct.constructor===R?i.struct.length-=g:d=mo(d,g)),i.struct.mergeWith(d)||(st(c,i.struct,i.offset),i={struct:d,offset:0},h.next())}}else i={struct:h.curr,offset:0},h.next();for(let d=h.curr;d!==null&&d.id.client===u&&d.id.clock===i.struct.id.clock+i.struct.length&&d.constructor!==R;d=h.next())st(c,i.struct,i.offset),i={struct:d,offset:0}}i!==null&&(st(c,i.struct,i.offset),i=null),un(c);const l=s.map(h=>nn(h)),a=Yi(l);return At(o,a),o.toUint8Array()},yo=(n,t,e=Lt,s=dt)=>{const r=gs(t),i=new s,o=new hn(i),c=new e(tt(n)),l=new an(c,!1);for(;l.curr;){const h=l.curr,u=h.id.client,d=r.get(u)||0;if(l.curr.constructor===R){l.next();continue}if(h.id.clock+h.length>d)for(st(o,h,ct(d-h.id.clock,0)),l.next();l.curr&&l.curr.id.client===u;)st(o,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===u&&l.curr.id.clock+l.curr.length<=d;)l.next()}un(o);const a=nn(c);return At(i,a),i.toUint8Array()},Ls=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:D(n.encoder.restEncoder)}),n.encoder.restEncoder=U(),n.written=0)},st=(n,t,e)=>{n.written>0&&n.currClient!==t.id.client&&Ls(n),n.written===0&&(n.currClient=t.id.client,n.encoder.writeClient(t.id.client),w(n.encoder.restEncoder,t.id.clock+e)),t.write(n.encoder,e),n.written++},un=n=>{Ls(n);const t=n.encoder.restEncoder;w(t,n.clientStructs.length);for(let e=0;e<n.clientStructs.length;e++){const s=n.clientStructs[e];w(t,s.written),le(t,s.restEncoder)}},_o=(n,t,e,s)=>{const r=new e(tt(n)),i=new an(r,!1),o=new s,c=new hn(o);for(let a=i.curr;a!==null;a=i.next())st(c,t(a),0);un(c);const l=nn(r);return At(o,l),o.toUint8Array()},bo=n=>_o(n,ni,Lt,Wt),vs="You must not compute changes after the event-handler fired.";class pe{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=ko(this.currentTarget,this.target))}deletes(t){return is(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Y(vs);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=Oe(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",c=Oe(l.content.getContent())):(o="add",c=void 0)}else if(this.deletes(i))o="delete",c=Oe(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 Y(vs);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 ko=(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},xs=80;let dn=0;class So{constructor(t,e){t.marker=!0,this.p=t,this.index=e,this.timestamp=dn++}}const Eo=n=>{n.timestamp=dn++},Is=(n,t,e)=>{n.p.marker=!1,n.p=t,t.marker=!0,n.index=e,n.timestamp=dn++},Do=(n,t,e)=>{if(n.length>=xs){const s=n.reduce((r,i)=>r.timestamp<i.timestamp?r:i);return Is(s,t,e),s}else{const s=new So(t,e);return n.push(s),s}},we=(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)=>se(t-i.index)<se(t-o.index)?i:o);let s=n._start,r=0;for(e!==null&&(s=e.p,r=e.index,Eo(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&&se(e.index-r)<s.parent.length/xs?(Is(e,s,r),e):Do(n._searchMarker,s,r)},zt=(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))}},me=(n,t,e)=>{const s=n,r=t.changedParentTypes;for(;K(r,n,()=>[]).push(e),n._item!==null;)n=n._item.parent;_s(s._eH,e,t)};class T{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ws(),this._dEH=ws(),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){ms(this._eH,t)}observeDeep(t){ms(this._dEH,t)}unobserve(t){ys(this._eH,t)}unobserveDeep(t){ys(this._dEH,t)}toJSON(){}}const Ts=(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},Ms=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},Pt=(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}},Us=(n,t)=>{const e=[];return Pt(n,(s,r)=>{e.push(t(s,r,n))}),e},Co=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}}}},Os=(n,t)=>{const e=we(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}},ye=(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 L(_(o,I(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new wt(a)),r.integrate(n,0),a=[])};s.forEach(u=>{if(u===null)a.push(u);else switch(u.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(u);break;default:switch(h(),u.constructor){case Uint8Array:case ArrayBuffer:r=new L(_(o,I(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new Jt(new Uint8Array(u))),r.integrate(n,0);break;case ut:r=new L(_(o,I(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new Gt(u)),r.integrate(n,0);break;default:if(u instanceof T)r=new L(_(o,I(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new G(u)),r.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},Ns=()=>Y("Length exceeded!"),Rs=(n,t,e,s)=>{if(e>t._length)throw Ns();if(e===0)return t._searchMarker&&zt(t._searchMarker,e,s.length),ye(n,t,null,s);const r=e,i=we(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,_(o.id.client,o.id.clock+e));break}e-=o.length}return t._searchMarker&&zt(t._searchMarker,r,s.length),ye(n,t,o,s)},Ao=(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 ye(n,t,r,e)},Bs=(n,t,e,s)=>{if(s===0)return;const r=e,i=s,o=we(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,_(c.id.client,c.id.clock+e)),e-=c.length);for(;s>0&&c!==null;)c.deleted||(s<c.length&&nt(n,_(c.id.client,c.id.clock+s)),c.delete(n),s-=c.length),c=c.right;if(s>0)throw Ns();t._searchMarker&&zt(t._searchMarker,r,-i+s)},_e=(n,t,e)=>{const s=t._map.get(e);s!==void 0&&s.delete(n)},fn=(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 Jt(s);break;case ut:c=new Gt(s);break;default:if(s instanceof T)c=new G(s);else throw new Error("Unexpected content type")}new L(_(o,I(i.store,o)),r,r&&r.lastId,null,null,t,e,c).integrate(n,0)},gn=(n,t)=>{const e=n._map.get(t);return e!==void 0&&!e.deleted?e.content.getContent()[e.length-1]:void 0},Fs=n=>{const t={};return n._map.forEach((e,s)=>{e.deleted||(t[s]=e.content.getContent()[e.length-1])}),t},Hs=(n,t)=>{const e=n._map.get(t);return e!==void 0&&!e.deleted},be=n=>zi(n.entries(),t=>!t[1].deleted);class Lo extends pe{constructor(t,e){super(t,e),this._transaction=e}}class xt extends T{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const e=new xt;return e.push(t),e}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new xt}clone(){const t=new xt;return t.insert(0,this.toArray().map(e=>e instanceof T?e.clone():e)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}_callObserver(t,e){super._callObserver(t,e),me(this,t,new Lo(this,t))}insert(t,e){this.doc!==null?k(this.doc,s=>{Rs(s,this,t,e)}):this._prelimContent.splice(t,0,...e)}push(t){this.doc!==null?k(this.doc,e=>{Ao(e,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,e=1){this.doc!==null?k(this.doc,s=>{Bs(s,this,t,e)}):this._prelimContent.splice(t,e)}get(t){return Os(this,t)}toArray(){return Ms(this)}slice(t=0,e=this.length){return Ts(this,t,e)}toJSON(){return this.map(t=>t instanceof T?t.toJSON():t)}map(t){return Us(this,t)}forEach(t){Pt(this,t)}[Symbol.iterator](){return Co(this)}_write(t){t.writeTypeRef(qo)}}const vo=n=>new xt;class xo extends pe{constructor(t,e,s){super(t,e),this.keysChanged=s}}class ft extends T{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 T?e.clone():e)}),t}_callObserver(t,e){me(this,t,new xo(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 T?r.toJSON():r}}),t}get size(){return[...be(this._map)].length}keys(){return Ze(be(this._map),t=>t[0])}values(){return Ze(be(this._map),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Ze(be(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=>{_e(e,this,t)}):this._prelimContent.delete(t)}set(t,e){return this.doc!==null?k(this.doc,s=>{fn(s,this,t,e)}):this._prelimContent.set(t,e),e}get(t){return gn(this,t)}has(t){return Hs(this,t)}clear(){this.doc!==null?k(this.doc,t=>{this.forEach(function(e,s,r){_e(t,r,s)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Qo)}}const Io=n=>new ft,rt=(n,t)=>n===t||typeof n=="object"&&typeof t=="object"&&n&&t&&ei(n,t);class pn{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 Vs=(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,_(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},ke=(n,t,e)=>{const s=new Map,r=we(t,e);if(r){const i=new pn(r.p.left,r.p,r.index,s);return Vs(n,i,e-r.index)}else{const i=new pn(null,t._start,0,s);return Vs(n,i,e)}},$s=(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 L(_(i,I(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)},js=(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()}},Ws=(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:u}=e;e.right=new L(_(i,I(r.store,i)),h,h&&h.lastId,u,u&&u.id,t,null,new A(c,l)),e.right.integrate(n,0),e.forward()}}return o},wn=(n,t,e,s,r)=>{e.currentAttributes.forEach((d,f)=>{r[f]===void 0&&(r[f]=null)});const i=n.doc,o=i.clientID;js(e,r);const c=Ws(n,t,e,r),l=s.constructor===String?new W(s):s instanceof T?new G(s):new pt(s);let{left:a,right:h,index:u}=e;t._searchMarker&&zt(t._searchMarker,e.index,l.getLength()),h=new L(_(o,I(i.store,o)),a,a&&a.lastId,h,h&&h.id,t,null,l),h.integrate(n,0),e.right=h,e.index=u,e.forward(),$s(n,t,e,c)},Ks=(n,t,e,s,r)=>{const i=n.doc,o=i.clientID;js(e,r);const c=Ws(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,_(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 L(_(o,I(i.store,o)),e.left,e.left&&e.left.lastId,e.right,e.right&&e.right.id,t,null,new W(l)),e.right.integrate(n,0),e.forward()}$s(n,t,e,c)},zs=(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:u}=a,d=s.get(h)||null;(o.get(h)!==a||d===u)&&(t.delete(n),c++,!l&&(r.get(h)||null)===u&&d!==u&&(d===null?r.delete(h):r.set(h,d))),!l&&!t.deleted&&It(r,a);break}}}t=t.right}return c},To=(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}},Mo=n=>{let t=0;return k(n.doc,e=>{let s=n._start,r=n._start,i=F();const o=Ue(i);for(;r;){if(r.deleted===!1)switch(r.content.constructor){case A:It(o,r.content);break;default:t+=zs(e,s,r,i,o),i=Ue(o),s=r;break}r=r.right}}),t},Uo=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&&Es(n,e.store.clients.get(s),i,r,o=>{!o.deleted&&o.content.constructor===A&&o.constructor!==N&&t.add(o.parent)})}k(e,s=>{rs(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):To(s,r)});for(const r of t)Mo(r)})},Ps=(n,t,e)=>{const s=e,r=Ue(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 W:e<t.right.length&&nt(n,_(t.right.id.client,t.right.id.clock+e)),e-=t.right.length,t.right.delete(n);break}t.forward()}i&&zs(n,i,t.right,r,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&zt(o._searchMarker,t.index,-s+e),t};class Oo extends pe{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,c=null;const l={};let a="",h=0,u=0;const d=()=>{if(c!==null){let f=null;switch(c){case"delete":u>0&&(f={delete:u}),u=0;break;case"insert":(typeof a=="object"||a.length>0)&&(f={insert:a},r.size>0&&(f.attributes={},r.forEach((g,m)=>{g!==null&&(f.attributes[m]=g)}))),a="";break;case"retain":h>0&&(f={retain:h},Zr(l)||(f.attributes=Xr({},l))),h=0;break}f&&e.push(f),c=null}};for(;o!==null;){switch(o.content.constructor){case G:case pt:this.adds(o)?this.deletes(o)||(d(),c="insert",a=o.content.getContent()[0],d()):this.deletes(o)?(c!=="delete"&&(d(),c="delete"),u+=1):o.deleted||(c!=="retain"&&(d(),c="retain"),h+=1);break;case W:this.adds(o)?this.deletes(o)||(c!=="insert"&&(d(),c="insert"),a+=o.content.str):this.deletes(o)?(c!=="delete"&&(d(),c="delete"),u+=o.length):o.deleted||(c!=="retain"&&(d(),c="retain"),h+=o.length);break;case 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"&&d(),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"&&d(),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"&&d(),g===null?delete l[f]:l[f]=g))}o.deleted||(c==="insert"&&d(),It(r,o.content));break}}o=o.right}for(d();e.length>0;){const f=e[e.length-1];if(f.retain!==void 0&&f.attributes===void 0)e.pop();else break}}),this._delta=e}return this._delta}}class Tt extends T{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 Tt}clone(){const t=new Tt;return t.applyDelta(this.toDelta()),t}_callObserver(t,e){super._callObserver(t,e);const s=new Oo(this,t,e);me(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===W&&(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 pn(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)&&wn(s,this,r,c,o.attributes||{})}else o.retain!==void 0?Ks(s,this,r,o.retain,o.attributes||{}):o.delete!==void 0&&Ps(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 u={};let d=!1;i.forEach((g,m)=>{d=!0,u[m]=g});const f={insert:c};d&&(f.attributes=u),r.push(f),c=""}}const h=()=>{for(;l!==null;){if(Kt(l,t)||e!==void 0&&Kt(l,e))switch(l.content.constructor){case W:{const u=i.get("ychange");t!==void 0&&!Kt(l,t)?(u===void 0||u.user!==l.id.client||u.type!=="removed")&&(a(),i.set("ychange",s?s("removed",l.id):{type:"removed"})):e!==void 0&&!Kt(l,e)?(u===void 0||u.user!==l.id.client||u.type!=="added")&&(a(),i.set("ychange",s?s("added",l.id):{type:"added"})):u!==void 0&&(a(),i.delete("ychange")),c+=l.content.str;break}case G:case pt:{a();const u={insert:l.content.getContent()[0]};if(i.size>0){const d={};u.attributes=d,i.forEach((f,g)=>{d[g]=f})}r.push(u);break}case A:Kt(l,t)&&(a(),It(i,l.content));break}l=l.right}a()};return t||e?k(o,u=>{t&&on(u,t),e&&on(u,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=ke(i,this,t);s||(s={},o.currentAttributes.forEach((c,l)=>{s[l]=c})),wn(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=ke(i,this,t);wn(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=>{Ps(r,ke(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=ke(i,this,t);o.right!==null&&Ks(i,this,o,e,s)}):this._pending.push(()=>this.format(t,e,s))}removeAttribute(t){this.doc!==null?k(this.doc,e=>{_e(e,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,e){this.doc!==null?k(this.doc,s=>{fn(s,this,t,e)}):this._pending.push(()=>this.setAttribute(t,e))}getAttribute(t){return gn(this,t)}getAttributes(){return Fs(this)}_write(t){t.writeTypeRef(Zo)}}const No=n=>new Tt;class mn{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===Yt||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 T{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 T?e.clone():e)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new mn(this,t)}querySelector(t){t=t.toUpperCase();const s=new mn(this,r=>r.nodeName&&r.nodeName.toUpperCase()===t).next();return s.done?null:s.value}querySelectorAll(t){return t=t.toUpperCase(),Z(new mn(this,e=>e.nodeName&&e.nodeName.toUpperCase()===t))}_callObserver(t,e){me(this,t,new Fo(this,e,t))}toString(){return Us(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),Pt(this,i=>{r.insertBefore(i.toDOM(t,e,s),null)}),r}insert(t,e){this.doc!==null?k(this.doc,s=>{Rs(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 T?t._item:t;ye(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 Y("Reference item not found");s.splice(r,0,...e)}}delete(t,e=1){this.doc!==null?k(this.doc,s=>{Bs(s,this,t,e)}):this._prelimContent.splice(t,e)}toArray(){return Ms(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Os(this,t)}slice(t=0,e=this.length){return Ts(this,t,e)}forEach(t){Pt(this,t)}_write(t){t.writeTypeRef(ec)}}const Ro=n=>new gt;class Yt 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 Yt(this.nodeName)}clone(){const t=new Yt(this.nodeName),e=this.getAttributes();return qr(e,(s,r)=>{typeof s=="string"&&t.setAttribute(r,s)}),t.insert(0,this.toArray().map(s=>s instanceof T?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?k(this.doc,e=>{_e(e,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,e){this.doc!==null?k(this.doc,s=>{fn(s,this,t,e)}):this._prelimAttrs.set(t,e)}getAttribute(t){return gn(this,t)}hasAttribute(t){return Hs(this,t)}getAttributes(){return Fs(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 Pt(this,o=>{r.appendChild(o.toDOM(t,e,s))}),s!==void 0&&s._createAssociation(r,this),r}_write(t){t.writeTypeRef(tc),t.writeKey(this.nodeName)}}const Bo=n=>new Yt(n.readKey());class Fo extends pe{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 Se extends ft{constructor(t){super(),this.hookName=t}_copy(){return new Se(this.hookName)}clone(){const t=new Se(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(nc),t.writeKey(this.hookName)}}const Ho=n=>new Se(n.readKey());class Ee extends Tt{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 Ee}clone(){const t=new Ee;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(sc)}}const Vo=n=>new Ee;class yn{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 $o=0;class N extends yn{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),ks(t.doc.store,this)}write(t,e){t.writeInfo($o),t.writeLen(this.length-e)}getMissing(t,e){return null}}class Jt{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Jt(this.content)}splice(t){throw V()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeBuf(this.content)}getRef(){return 3}}const jo=n=>new Jt(n.readBuf());class Xt{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Xt(this.len)}splice(t){const e=new Xt(this.len-t);return this.len=t,e}mergeWith(t){return this.len+=t.len,!0}integrate(t,e){he(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 Wo=n=>new Xt(n.readLen()),Ys=(n,t)=>new ut({guid:n,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Gt{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 Gt(Ys(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 Ko=n=>new Gt(Ys(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 zo=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 Po=n=>new A(n.readKey(),n.readJSON());class De{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new De(this.arr)}splice(t){const e=new De(this.arr.slice(t));return this.arr=this.arr.slice(0,t),e}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){const s=this.arr.length;t.writeLen(s-e);for(let r=e;r<s;r++){const i=this.arr[r];t.writeString(i===void 0?"undefined":JSON.stringify(i))}}getRef(){return 2}}const Yo=n=>{const t=n.readLen(),e=[];for(let s=0;s<t;s++){const r=n.readString();r==="undefined"?e.push(void 0):e.push(JSON.parse(r))}return new De(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 Jo=n=>{const t=n.readLen(),e=[];for(let s=0;s<t;s++)e.push(n.readAny());return new wt(e)};class W{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new W(this.str)}splice(t){const e=new W(this.str.slice(t));this.str=this.str.slice(0,t);const s=this.str.charCodeAt(t-1);return s>=55296&&s<=56319&&(this.str=this.str.slice(0,t-1)+"�",e.str="�"+e.str.slice(1)),e}mergeWith(t){return this.str+=t.str,!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeString(e===0?this.str:this.str.slice(e))}getRef(){return 4}}const Xo=n=>new W(n.readString()),Go=[vo,Io,No,Bo,Ro,Ho,Vo],qo=0,Qo=1,Zo=2,tc=3,ec=4,nc=5,sc=6;class G{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new G(this.type._copy())}splice(t){throw V()}mergeWith(t){return!1}integrate(t,e){this.type._integrate(t.doc,e)}delete(t){let e=this.type._start;for(;e!==null;)e.deleted?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 rc=n=>new G(Go[n.readTypeRef()](n)),Ce=(n,t,e)=>{const{client:s,clock:r}=t.id,i=new L(_(s,r+e),t,_(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=_(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 L extends yn{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()?jn:0}set marker(t){(this.info&$e)>0!==t&&(this.info^=$e)}get marker(){return(this.info&$e)>0}get keep(){return(this.info&$n)>0}set keep(t){this.keep!==t&&(this.info^=$n)}get countable(){return(this.info&jn)>0}get deleted(){return(this.info&Ve)>0}set deleted(t){this.deleted!==t&&(this.info^=Ve)}markDeleted(){this.info|=Ve}getMissing(t,e){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=I(e,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=I(e,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===vt&&this.id.client!==this.parent.client&&this.parent.clock>=I(e,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Ss(t,e,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=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===L&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===L&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===vt){const s=cn(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=Ss(t,t.doc.store,_(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),ue(this.origin,r.origin)){if(r.id.client<this.id.client)s=r,i.clear();else if(ue(this.rightOrigin,r.rightOrigin))break}else if(r.origin!==null&&o.has(cn(t.doc.store,r.origin)))i.has(cn(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),ks(t.doc.store,this),this.content.integrate(t,this),Cs(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new 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:_(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&ue(t.origin,this.lastId)&&this.right===t&&ue(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(),he(t.deleteSet,this.id.client,this.id.clock,this.length),Cs(t,e,this.parentSub),this.content.delete(t)}}gc(t,e){if(!this.deleted)throw $();this.content.gc(t),e?ho(t,this,new N(this.id,this.length)):this.content=new Xt(this.length)}write(t,e){const s=e>0?_(this.id.client,this.id.clock+e-1):this.origin,r=this.rightOrigin,i=this.parentSub,o=this.content.getRef()&ie|(s===null?0:O)|(r===null?0:P)|(i===null?0:Ft);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=ao(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===vt?(t.writeParentInfo(!1),t.writeLeftID(c)):$();i!==null&&t.writeString(i)}this.content.write(t,e)}}const Js=(n,t)=>ic[t&ie](n),ic=[()=>{$()},Wo,Yo,jo,Xo,zo,Po,rc,Jo,Ko,()=>{$()}],oc=10;class R extends yn{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(oc),w(t.restEncoder,this.length-e)}getMissing(t,e){return null}}const Xs=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Gs="__ $YJS$ __";Xs[Gs]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),Xs[Gs]=!0;const qs=new Map;class cc{constructor(t){this.room=t,this.onmessage=null,this._onChange=e=>e.key===t&&this.onmessage!==null&&this.onmessage({data:_i(e.newValue||"")}),Yr(this._onChange)}postMessage(t){Bn.setItem(this.room,yi(fi(t)))}close(){Jr(this._onChange)}}const lc=typeof BroadcastChannel>"u"?cc:BroadcastChannel,_n=n=>K(qs,n,()=>{const t=ot(),e=new lc(n);return e.onmessage=s=>t.forEach(r=>r(s.data,"broadcastchannel")),{bc:e,subs:t}}),ac=(n,t)=>(_n(n).subs.add(t),t),hc=(n,t)=>{const e=_n(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=_n(n);s.bc.postMessage(t),s.subs.forEach(r=>r(t,e))},Qs=0,bn=1,Zs=2,kn=(n,t)=>{w(n,Qs);const e=co(t);C(n,e)},tr=(n,t,e)=>{w(n,bn),C(n,rn(t,e))},uc=(n,t,e)=>tr(t,e,M(n)),er=(n,t,e)=>{try{fs(t,M(n),e)}catch(s){console.error("Caught error while handling a Yjs update",s)}},dc=(n,t)=>{w(n,Zs),C(n,t)},fc=er,gc=(n,t,e,s)=>{const r=y(n);switch(r){case Qs:uc(n,t,e);break;case bn:er(n,e,s);break;case Zs:fc(n,e,s);break;default:throw new Error("Unknown message type")}return r},pc=0,wc=(n,t,e)=>{switch(y(n)){case pc:e(t,et(n))}},Sn=3e4;class mc extends ne{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&&Sn/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const s=[];this.meta.forEach((r,i)=>{i!==this.clientID&&Sn<=e-r.lastUpdated&&this.states.has(i)&&s.push(i)}),s.length>0&&En(this,s,"timeout")},z(Sn/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),Bt(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 En=(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]))},qt=(n,t,e=n.states)=>{const s=t.length,r=U();w(r,s);for(let i=0;i<s;i++){const o=t[i],c=e.get(o)||null,l=n.meta.get(o).clock;w(r,o),w(r,l),at(r,JSON.stringify(c))}return D(r)},yc=(n,t,e)=>{const s=tt(t),r=ht(),i=[],o=[],c=[],l=[],a=y(s);for(let h=0;h<a;h++){const u=y(s);let d=y(s);const f=JSON.parse(et(s)),g=n.meta.get(u),m=n.states.get(u),E=g===void 0?0:g.clock;(E<d||E===d&&f===null&&n.states.has(u))&&(f===null?u===n.clientID&&n.getLocalState()!=null?d++:n.states.delete(u):n.states.set(u,f),n.meta.set(u,{clock:d,lastUpdated:r}),g===void 0&&f!==null?i.push(u):g!==void 0&&f===null?l.push(u):f!==null&&(Bt(f,m)||c.push(u),o.push(u)))}(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])},_c=n=>Qr(n,(t,e)=>`${encodeURIComponent(e)}=${encodeURIComponent(t)}`).join("&");var mt=0,nr=3,Ut=1,bc=2,kc=typeof window>"u";function Sc(n,t){if(!n)throw new Error(t)}var Qt=[];Qt[mt]=(n,t,e,s,r)=>{w(n,mt);const i=gc(t,n,e.doc,e);s&&i===bn&&!e.synced&&(e.synced=!0)},Qt[nr]=(n,t,e,s,r)=>{w(n,Ut),C(n,qt(e.awareness,Array.from(e.awareness.getStates().keys())))},Qt[Ut]=(n,t,e,s,r)=>{yc(e.awareness,M(t),e)},Qt[bc]=(n,t,e,s,r)=>{wc(t,e.doc,(i,o)=>Ec(e,o))};var sr=3e4;function Ec(n,t){console.warn(`Permission denied to access ${n.url}.
|
|
4
|
-
${t}`)}function rr(n,t,e){const s=tt(t),r=U(),i=y(s),o=n.messageHandlers[i];return o?o(r,s,n,e,i):console.error("Unable to compute message"),r}function ir(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=rr(n,new Uint8Array(e.data),!0);Ye(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,En(n.awareness,Array.from(n.awareness.getStates().keys()).filter(s=>s!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(ir,Ne(Fr(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=U();if(w(e,mt),kn(e,n.doc),t.send(D(e)),n.awareness.getLocalState()!==null){const s=U();w(s,Ut),C(s,qt(n.awareness,[n.doc.clientID])),t.send(D(s))}},n.emit("status",[{status:"connecting"}])}}function Dn(n,t){const e=n.ws;n.wsconnected&&e&&e.readyState===e.OPEN&&e.send(t),n.bcconnected&&Mt(n.bcChannel,t,n)}var Dc=class extends ne{constructor(t,e,s,{connect:r=!0,awareness:i=new mc(s),params:o={},WebSocketPolyfill:c=WebSocket,resyncInterval:l=-1,maxBackoffTime:a=2500,disableBc:h=kc}={}){super();p(this,"maxBackoffTime");p(this,"bcChannel");p(this,"url");p(this,"roomname");p(this,"doc");p(this,"_WS");p(this,"awareness");p(this,"wsconnected");p(this,"wsconnecting");p(this,"bcconnected");p(this,"disableBc");p(this,"wsUnsuccessfulReconnects");p(this,"messageHandlers");p(this,"_synced");p(this,"ws");p(this,"wsLastMessageReceived");p(this,"shouldConnect");p(this,"_resyncInterval");p(this,"_bcSubscriber");p(this,"_updateHandler");p(this,"_awarenessUpdateHandler");p(this,"_unloadHandler");p(this,"_checkInterval");for(;t[t.length-1]==="/";)t=t.slice(0,t.length-1);const u=_c(o);this.maxBackoffTime=a,this.bcChannel=t+"/"+e,this.url=t+"/"+e+(u.length===0?"":"?"+u),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=Qt.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=r,this._resyncInterval=0,l>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const d=U();w(d,mt),kn(d,s),this.ws.send(D(d))}},l)),this._bcSubscriber=(d,f)=>{if(f!==this){const g=rr(this,new Uint8Array(d),!1);Ye(g)>1&&Mt(this.bcChannel,D(g),this)}},this._updateHandler=(d,f)=>{if(f!==this){const g=U();w(g,mt),dc(g,d),Dn(this,D(g))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:d,updated:f,removed:g},m)=>{const E=d.concat(f).concat(g),Q=U();w(Q,Ut),C(Q,qt(i,E)),Dn(this,D(Q))},this._unloadHandler=()=>{En(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&&sr<ht()-this.wsLastMessageReceived&&(Sc(this.ws!==null,"ws must not be null"),this.ws.close())},sr/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||(ac(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const t=U();w(t,mt),kn(t,this.doc),Mt(this.bcChannel,D(t),this);const e=U();w(e,mt),tr(e,this.doc),Mt(this.bcChannel,D(e),this);const s=U();w(s,nr),Mt(this.bcChannel,D(s),this);const r=U();w(r,Ut),C(r,qt(this.awareness,[this.doc.clientID])),Mt(this.bcChannel,D(r),this)}disconnectBc(){const t=U();w(t,Ut),C(t,qt(this.awareness,[this.doc.clientID],new Map)),Dn(this,D(t)),this.bcconnected&&(hc(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&&(ir(this),this.connectBc())}};function Cc(){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 or(n,t,e){if(typeof n!==e)throw new Error(`Invalid "${t}" parameter provided to YPartyKitProvider. Expected: ${e}, received: ${n}`)}var Ac=class extends WebSocket{send(n){typeof n!="string"&&Ur(n,t=>super.send(t))}},Lc=(vr=class extends Dc{constructor(t,e,s,r={}){or(t,"host","string"),or(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??Cc(),{params:c,connect:l=!0,...a}=r,h={...a,connect:!1,WebSocketPolyfill:Ac};super(i,e,s??new ut,h);p(this,"id");Tr(this,kt,void 0);this.id=o,Mr(this,kt,c),l&&this.connect()}connect(){Promise.resolve(typeof Me(this,kt)=="function"?Me(this,kt).call(this):Me(this,kt)).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)})}},kt=new WeakMap,vr);const yt=n=>Ct((t,e)=>{n.onerror=s=>e(new Error(s.target.error)),n.onsuccess=s=>t(s.target.result)}),vc=(n,t)=>Ct((e,s)=>{const r=indexedDB.open(n);r.onupgradeneeded=i=>t(i.target.result),r.onerror=i=>s(Y(i.target.error)),r.onsuccess=i=>{const o=i.target.result;o.onversionchange=()=>{o.close()},typeof addEventListener<"u"&&addEventListener("unload",()=>o.close()),e(o)}}),xc=n=>yt(indexedDB.deleteDatabase(n)),Ic=(n,t)=>t.forEach(e=>n.createObjectStore.apply(n,e)),Zt=(n,t,e="readwrite")=>{const s=n.transaction(t,e);return t.map(r=>Fc(s,r))},cr=(n,t)=>yt(n.count(t)),Tc=(n,t)=>yt(n.get(t)),lr=(n,t)=>yt(n.delete(t)),Mc=(n,t,e)=>yt(n.put(t,e)),Cn=(n,t)=>yt(n.add(t)),Uc=(n,t,e)=>yt(n.getAll(t,e)),Oc=(n,t,e)=>{let s=null;return Bc(n,t,r=>(s=r,!1),e).then(()=>s)},Nc=(n,t=null)=>Oc(n,t,"prev"),Rc=(n,t)=>Ct((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()}}),Bc=(n,t,e,s="next")=>Rc(n.openKeyCursor(t,s),r=>e(r.key)),Fc=(n,t)=>n.objectStore(t),Hc=(n,t)=>IDBKeyRange.upperBound(n,t),Vc=(n,t)=>IDBKeyRange.lowerBound(n,t),An="custom",ar="updates",hr=500,ur=(n,t=()=>{},e=()=>{})=>{const[s]=Zt(n.db,[ar]);return Uc(s,Vc(n._dbref,!1)).then(r=>{n._destroyed||(t(s),k(n.doc,()=>{r.forEach(i=>fs(n.doc,i))},n,!1),e(s))}).then(()=>Nc(s).then(r=>{n._dbref=r+1})).then(()=>cr(s).then(r=>{n._dbsize=r})).then(()=>s)},$c=(n,t=!0)=>ur(n).then(e=>{(t||n._dbsize>=hr)&&Cn(e,rn(n.doc)).then(()=>lr(e,Hc(n._dbref,!0))).then(()=>cr(e).then(s=>{n._dbsize=s}))});class jc extends ne{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=vc(t,s=>Ic(s,[["updates",{autoIncrement:!0}],["custom"]])),this.whenSynced=Ct(s=>this.on("synced",()=>s(this))),this._db.then(s=>{this.db=s,ur(this,o=>Cn(o,rn(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]=Zt(this.db,[ar]);Cn(i,s),++this._dbsize>=hr&&(this._storeTimeoutId!==null&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout(()=>{$c(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(()=>{xc(this.name)})}get(t){return this._db.then(e=>{const[s]=Zt(e,[An],"readonly");return Tc(s,t)})}set(t,e){return this._db.then(s=>{const[r]=Zt(s,[An]);return Mc(r,e,t)})}del(t){return this._db.then(e=>{const[s]=Zt(e,[An]);return lr(s,t)})}}(!globalThis.EventTarget||!globalThis.Event)&&console.error(`
|
|
5
|
-
PartySocket requires a global 'EventTarget' class to be available!
|
|
6
|
-
You can polyfill this global by adding this to your code before any partysocket imports:
|
|
7
|
-
|
|
8
|
-
\`\`\`
|
|
9
|
-
import 'partysocket/event-target-polyfill';
|
|
10
|
-
\`\`\`
|
|
11
|
-
Please file an issue at https://github.com/partykit/partykit if you're still having trouble.
|
|
12
|
-
`);var dr=class extends Event{constructor(t,e){super("error",e);p(this,"message");p(this,"error");this.message=t.message,this.error=t}},fr=class extends Event{constructor(t=1e3,e="",s){super("close",s);p(this,"code");p(this,"reason");p(this,"wasClean",!0);this.code=t,this.reason=e}},Ln={Event,ErrorEvent:dr,CloseEvent:fr};function Wc(n,t){if(!n)throw new Error(t)}function Kc(n){return new n.constructor(n.type,n)}function zc(n){return"data"in n?new MessageEvent(n.type,n):"code"in n||"reason"in n?new fr(n.code||1999,n.reason||"unknown reason",n):"error"in n?new dr(n.error,n):new Event(n.type,n)}var Pc=typeof process<"u"&&typeof((xr=process.versions)==null?void 0:xr.node)<"u"&&typeof document>"u",Ae=Pc?zc:Kc,_t={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+Math.random()*4e3,minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0,startClosed:!1,debug:!1},gr=!1,Yc=class St extends EventTarget{constructor(e,s,r={}){super();p(this,"_ws");p(this,"_retryCount",-1);p(this,"_uptimeTimeout");p(this,"_connectTimeout");p(this,"_shouldReconnect",!0);p(this,"_connectLock",!1);p(this,"_binaryType","blob");p(this,"_closeCalled",!1);p(this,"_messageQueue",[]);p(this,"_debugLogger",console.log.bind(console));p(this,"_url");p(this,"_protocols");p(this,"_options");p(this,"onclose",null);p(this,"onerror",null);p(this,"onmessage",null);p(this,"onopen",null);p(this,"_handleOpen",e=>{this._debug("open event");const{minUptime:s=_t.minUptime}=this._options;clearTimeout(this._connectTimeout),this._uptimeTimeout=setTimeout(()=>this._acceptOpen(),s),Wc(this._ws,"WebSocket is not defined"),this._ws.binaryType=this._binaryType,this._messageQueue.forEach(r=>{var i;return(i=this._ws)==null?void 0:i.send(r)}),this._messageQueue=[],this.onopen&&this.onopen(e),this.dispatchEvent(Ae(e))});p(this,"_handleMessage",e=>{this._debug("message event"),this.onmessage&&this.onmessage(e),this.dispatchEvent(Ae(e))});p(this,"_handleError",e=>{this._debug("error event",e.message),this._disconnect(void 0,e.message==="TIMEOUT"?"timeout":void 0),this.onerror&&this.onerror(e),this._debug("exec error listeners"),this.dispatchEvent(Ae(e)),this._connect()});p(this,"_handleClose",e=>{this._debug("close event"),this._clearTimeouts(),this._shouldReconnect&&this._connect(),this.onclose&&this.onclose(e),this.dispatchEvent(Ae(e))});this._url=e,this._protocols=s,this._options=r,this._options.startClosed&&(this._shouldReconnect=!1),this._options.debugLogger&&(this._debugLogger=this._options.debugLogger),this._connect()}static get CONNECTING(){return 0}static get OPEN(){return 1}static get CLOSING(){return 2}static get CLOSED(){return 3}get CONNECTING(){return St.CONNECTING}get OPEN(){return St.OPEN}get CLOSING(){return St.CLOSING}get CLOSED(){return St.CLOSED}get binaryType(){return this._ws?this._ws.binaryType:this._binaryType}set binaryType(e){this._binaryType=e,this._ws&&(this._ws.binaryType=e)}get retryCount(){return Math.max(this._retryCount,0)}get bufferedAmount(){return this._messageQueue.reduce((s,r)=>(typeof r=="string"?s+=r.length:r instanceof Blob?s+=r.size:s+=r.byteLength,s),0)+(this._ws?this._ws.bufferedAmount:0)}get extensions(){return this._ws?this._ws.extensions:""}get protocol(){return this._ws?this._ws.protocol:""}get readyState(){return this._ws?this._ws.readyState:this._options.startClosed?St.CLOSED:St.CONNECTING}get url(){return this._ws?this._ws.url:""}get shouldReconnect(){return this._shouldReconnect}close(e=1e3,s){if(this._closeCalled=!0,this._shouldReconnect=!1,this._clearTimeouts(),!this._ws){this._debug("close enqueued: no ws instance");return}if(this._ws.readyState===this.CLOSED){this._debug("close: already closed");return}this._ws.close(e,s)}reconnect(e,s){this._shouldReconnect=!0,this._closeCalled=!1,this._retryCount=-1,!this._ws||this._ws.readyState===this.CLOSED?this._connect():(this._disconnect(e,s),this._connect())}send(e){if(this._ws&&this._ws.readyState===this.OPEN)this._debug("send",e),this._ws.send(e);else{const{maxEnqueuedMessages:s=_t.maxEnqueuedMessages}=this._options;this._messageQueue.length<s&&(this._debug("enqueue",e),this._messageQueue.push(e))}}_debug(...e){this._options.debug&&this._debugLogger("RWS>",...e)}_getNextDelay(){const{reconnectionDelayGrowFactor:e=_t.reconnectionDelayGrowFactor,minReconnectionDelay:s=_t.minReconnectionDelay,maxReconnectionDelay:r=_t.maxReconnectionDelay}=this._options;let i=0;return this._retryCount>0&&(i=s*Math.pow(e,this._retryCount-1),i>r&&(i=r)),this._debug("next delay",i),i}_wait(){return new Promise(e=>{setTimeout(e,this._getNextDelay())})}_getNextProtocols(e){if(!e)return Promise.resolve(null);if(typeof e=="string"||Array.isArray(e))return Promise.resolve(e);if(typeof e=="function"){const s=e();if(!s)return Promise.resolve(null);if(typeof s=="string"||Array.isArray(s))return Promise.resolve(s);if(s.then)return s}throw Error("Invalid protocols")}_getNextUrl(e){if(typeof e=="string")return Promise.resolve(e);if(typeof e=="function"){const s=e();if(typeof s=="string")return Promise.resolve(s);if(s.then)return s}throw Error("Invalid URL")}_connect(){if(this._connectLock||!this._shouldReconnect)return;this._connectLock=!0;const{maxRetries:e=_t.maxRetries,connectionTimeout:s=_t.connectionTimeout}=this._options;if(this._retryCount>=e){this._debug("max retries reached",this._retryCount,">=",e);return}this._retryCount++,this._debug("connect",this._retryCount),this._removeListeners(),this._wait().then(()=>Promise.all([this._getNextUrl(this._url),this._getNextProtocols(this._protocols||null)])).then(([r,i])=>{if(this._closeCalled){this._connectLock=!1;return}!this._options.WebSocket&&typeof WebSocket>"u"&&!gr&&(console.error(`‼️ No WebSocket implementation available. You should define options.WebSocket.
|
|
13
|
-
|
|
14
|
-
For example, if you're using node.js, run \`npm install ws\`, and then in your code:
|
|
15
|
-
|
|
16
|
-
import PartySocket from 'partysocket';
|
|
17
|
-
import WS from 'ws';
|
|
18
|
-
|
|
19
|
-
const partysocket = new PartySocket({
|
|
20
|
-
host: "127.0.0.1:1999",
|
|
21
|
-
room: "test-room",
|
|
22
|
-
WebSocket: WS
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
`),gr=!0);const o=this._options.WebSocket||WebSocket;this._debug("connect",{url:r,protocols:i}),this._ws=i?new o(r,i):new o(r),this._ws.binaryType=this._binaryType,this._connectLock=!1,this._addListeners(),this._connectTimeout=setTimeout(()=>this._handleTimeout(),s)}).catch(r=>{this._connectLock=!1,this._handleError(new Ln.ErrorEvent(Error(r.message),this))})}_handleTimeout(){this._debug("timeout event"),this._handleError(new Ln.ErrorEvent(Error("TIMEOUT"),this))}_disconnect(e=1e3,s){if(this._clearTimeouts(),!!this._ws){this._removeListeners();try{this._ws.close(e,s),this._handleClose(new Ln.CloseEvent(e,s,this))}catch{}}}_acceptOpen(){this._debug("accept open"),this._retryCount=0}_removeListeners(){this._ws&&(this._debug("removeListeners"),this._ws.removeEventListener("open",this._handleOpen),this._ws.removeEventListener("close",this._handleClose),this._ws.removeEventListener("message",this._handleMessage),this._ws.removeEventListener("error",this._handleError))}_addListeners(){this._ws&&(this._debug("addListeners"),this._ws.addEventListener("open",this._handleOpen),this._ws.addEventListener("close",this._handleClose),this._ws.addEventListener("message",this._handleMessage),this._ws.addEventListener("error",this._handleError))}_clearTimeouts(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)}};/*!
|
|
26
|
-
* Reconnecting WebSocket
|
|
27
|
-
* by Pedro Ladaria <pedro.ladaria@gmail.com>
|
|
28
|
-
* https://github.com/pladaria/reconnecting-websocket
|
|
29
|
-
* License MIT
|
|
30
|
-
*/var Jc=n=>n[1]!==null&&n[1]!==void 0;function Xc(){if(typeof crypto<"u"&&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 pr(n,t,e={}){const{host:s,path:r,protocol:i,room:o,party:c,query:l}=n;let a=s.replace(/^(http|https|ws|wss):\/\//,"");if(a.endsWith("/")&&(a=a.slice(0,-1)),r&&r.startsWith("/"))throw new Error("path must not start with a slash");const h=c??"main",u=r?`/${r}`:"",d=i||(a.startsWith("localhost:")||a.startsWith("127.0.0.1:")||a.startsWith("192.168.")||a.startsWith("10.")||a.startsWith("172.")&&a.split(".")[1]>="16"&&a.split(".")[1]<="31"||a.startsWith("[::ffff:7f00:1]:")?t:t+"s"),f=`${d}://${a}/${c?`parties/${c}`:"party"}/${o}${u}`,g=(E={})=>`${f}?${new URLSearchParams([...Object.entries(e),...Object.entries(E).filter(Jc)])}`,m=typeof l=="function"?async()=>g(await l()):g(l);return{host:a,path:u,room:o,name:h,protocol:d,partyUrl:f,urlProvider:m}}var Gc=class extends Yc{constructor(t){const e=wr(t);super(e.urlProvider,e.protocols,e.socketOptions);p(this,"_pk");p(this,"_pkurl");p(this,"name");p(this,"room");p(this,"host");p(this,"path");this.partySocketOptions=t,this.setWSProperties(e)}updateProperties(t){const e=wr({...this.partySocketOptions,...t,host:t.host??this.host,room:t.room??this.room,path:t.path??this.path});this._url=e.urlProvider,this._protocols=e.protocols,this._options=e.socketOptions,this.setWSProperties(e)}setWSProperties(t){const{_pk:e,_pkurl:s,name:r,room:i,host:o,path:c}=t;this._pk=e,this._pkurl=s,this.name=r,this.room=i,this.host=o,this.path=c}reconnect(t,e){if(!this.room||!this.host)throw new Error("The room and host must be set before connecting, use `updateProperties` method to set them or pass them to the constructor.");super.reconnect(t,e)}get id(){return this._pk}get roomUrl(){return this._pkurl}static async fetch(t,e){const s=pr(t,"http"),r=typeof s.urlProvider=="string"?s.urlProvider:await s.urlProvider();return(t.fetch??fetch)(r,e)}};function wr(n){const{id:t,host:e,path:s,party:r,room:i,protocol:o,query:c,protocols:l,...a}=n,h=t||Xc(),u=pr(n,"ws",{_pk:h});return{_pk:h,_pkurl:u.partyUrl,name:u.name,room:u.room,host:u.host,path:u.path,protocols:l,socketOptions:a,urlProvider:u.urlProvider}}const Fl="",qc={ctrlKey:"Control",altKey:"Alt",shiftKey:"Shift",metaKey:"Meta"},Qc="can-duplicate-to";var Le=(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))(Le||{});function Zc(n){return n.id}const mr=`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>")
|
|
31
|
-
16 0,
|
|
32
|
-
auto`,tl=`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 yr(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=tl}else{if(i.scale>=i.maxScale){c.style.cursor="not-allowed";return}c.style.cursor=mr}r(o)}function ve(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 el={["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}=ve(n);t({startMouseX:e,startMouseY:s})},onDrag:(n,{data:t,localData:e,setData:s,setLocalData:r,element:i})=>{const{clientX:o,clientY:c}=ve(n),{top:l,left:a,bottom:h,right:u}=i.getBoundingClientRect();u>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}=ve(n);t({startMouseX:e})},onDrag:(n,{data:t,localData:e,setData:s,setLocalData:r})=>{const{clientX:i}=ve(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;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=mr,t.scale>=r.maxScale)return;i+=.1}s({...t,scale:i})},onMount:n=>{n.getElement().addEventListener("mouseenter",t=>{yr(t,n);const e=s=>yr(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 c=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 l=s.getAttribute(Qc);function a(u){if(l){const d=document.getElementById(l)||document.querySelector(l);if(d){d.appendChild(u);return}}o.parentNode.insertBefore(u,(c||o).nextSibling)}const h=new Set(t);for(const u of n){if(h.has(u))continue;const d=o.cloneNode(!0);Object.assign(d,{...o}),d.id=u,a(d),t.push(u),window.playhtml.setupPlayElement(d),c=d}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}},["can-mirror"]:{defaultData:n=>te(n),onMount:({getElement:n,setData:t,getData:e})=>{const s=n();nl(s,r=>{const i=e(),o=rl(i,r);t(o)})},updateElement:({element:n,data:t})=>{const e=te(n);xe(e,t)||_r(n,t)}}};function xe(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(!xe(n.children[e],t.children[e]))return!1;return!0}function nl(n,t,e){const s={childList:!0,attributes:!0,subtree:!0,characterData:!0,...e},r=o=>{const c=o.filter(l=>{if(s.childList&&l.type==="childList")return!0;if(s.attributes&&l.type==="attributes")if(s.attributeFilter){if(s.attributeFilter.includes(l.attributeName||""))return!0}else return!0;return!!(s.characterData&&l.type==="characterData"||s.subtree&&l.type==="childList")});t(c)},i=new MutationObserver(r);return i.observe(n,s),i}function sl(n){return JSON.parse(JSON.stringify(n))}function rl(n,t){let e=sl(n);return t.forEach(s=>{switch(s.type){case"attributes":il(e,s);break;case"childList":ol(e,s);break;case"characterData":cl(e,s);break}}),e}function il(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 ol(n,t){t.addedNodes.length&&t.addedNodes.forEach(e=>{if(!(e instanceof HTMLElement))return;const s=te(e);n.children.find(r=>xe(r,s))||n.children.push(s)}),t.removedNodes.length&&t.removedNodes.forEach(e=>{if(!(e instanceof HTMLElement))return;const s=te(e),r=n.children.findIndex(i=>xe(i,s));r!==-1&&n.children.splice(r,1)})}function cl(n,t){t.target===n&&(n.textContent=t.target.textContent)}function te(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(te(e))}),t}function _r(n,t){ll(n,t),t.children.length===0&&n.textContent!==t.textContent?n.textContent=t.textContent:t.children.length>0&&al(n,t)}function ll(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 al(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),_r(r,s)}),Array.from(n.children).forEach(s=>{e.has(s)||n.removeChild(s)})}const br=(n,t=300)=>{let e;return function(...s){clearTimeout(e),e=setTimeout(()=>n.apply(this,s),t)}};class hl{constructor(t){p(this,"defaultData");p(this,"localData");p(this,"awareness",[]);p(this,"selfAwareness");p(this,"element");p(this,"_data");p(this,"onChange");p(this,"onAwarenessChange");p(this,"debouncedOnChange");p(this,"resetShortcut");p(this,"updateElement");p(this,"updateElementAwareness");p(this,"triggerAwarenessUpdate");p(this,"onClick");p(this,"onDrag");p(this,"onDragStart");const{element:e,onChange:s,onAwarenessChange:r,defaultData:i,defaultLocalData:o,myDefaultAwareness:c,data:l,awareness:a,updateElement:h,updateElementAwareness:u,onMount:d,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=br(this.onChange,f),this.onAwarenessChange=r,this.updateElement=h,this.updateElementAwareness=u;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),d&&d(this.getSetupData())}reinitializeElementData({element:t,onChange:e,onAwarenessChange:s,updateElement:r,updateElementAwareness:i,onClick:o,onDrag:c,onDragStart:l,resetShortcut:a,debounceMs:h,triggerAwarenessUpdate:u}){this.triggerAwarenessUpdate=u,this.onChange=e,this.debouncedOnChange=br(this.onChange,h),this.onAwarenessChange=s,this.updateElement=r,this.updateElementAwareness=i,o&&!this.onClick&&t.addEventListener("click",d=>{var f;(f=this.onClick)==null||f.call(this,d,this.getEventHandlerData())}),this.onClick=o,c&&!this.onDrag&&(t.addEventListener("touchstart",d=>{var m;d.preventDefault(),(m=this.onDragStart)==null||m.call(this,d,this.getEventHandlerData());const f=E=>{var Q;E.preventDefault(),(Q=this.onDrag)==null||Q.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",d=>{var m;(m=this.onDragStart)==null||m.call(this,d,this.getEventHandlerData());const f=E=>{var Q;E.preventDefault(),(Q=this.onDrag)==null||Q.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 ${qc[a]} key while clicking to reset.`),t.reset=this.reset,t.addEventListener("click",d=>{switch(this.resetShortcut){case"ctrlKey":if(!d.ctrlKey)return;break;case"altKey":if(!d.altKey)return;break;case"shiftKey":if(!d.shiftKey)return;break;case"metaKey":if(!d.metaKey)return;break;default:return}this.reset(),d.preventDefault(),d.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 ul(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 dl="playhtml.spencerc99.partykit.dev",vn=new ut;function fl(){return window.location.pathname+window.location.search}let it,xn,q=vn.getMap("playhtml-global"),B=new Map,bt=new Map;const kr=new Map;let gl=0,ee=el;function Sr(){return[Le.CanPlay,...Object.keys(ee)]}function pl(n){xn.send(JSON.stringify(n))}let Ie=!1,In=!0;function wl({room:n=fl(),host:t=dl,extraCapabilities:e,events:s}={}){if(!In){console.error("playhtml already set up!");return}const r=encodeURIComponent(window.location.hostname+"-"+n),i=t;if(console.log(`࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂
|
|
33
|
-
࿂࿂࿂࿂ ࿂ ࿂ ࿂ ࿂ ࿂ ࿂࿂࿂࿂
|
|
34
|
-
࿂࿂࿂࿂ booting up playhtml... ࿂࿂࿂࿂
|
|
35
|
-
࿂࿂࿂࿂ https://playhtml.fun ࿂࿂࿂࿂
|
|
36
|
-
࿂࿂࿂࿂ ࿂ ࿂ ࿂ ࿂ ࿂࿂࿂࿂
|
|
37
|
-
࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂`),it=new Lc(i,r,vn),xn=new Gc({host:i,room:r}),new jc(r,vn),e)for(const[c,l]of Object.entries(e))ee[c]=l;if(s)for(const[c,l]of Object.entries(s))Lr(c,l);xn.onmessage=c=>{if(c.data instanceof Blob)return;let l;try{l=JSON.parse(c.data)}catch{return}const{type:a,eventPayload:h}=l,u=bt.get(a);if(u)for(const d of u)d.onEvent(h)};const o=document.createElement("link");return o.rel="stylesheet",o.href="https://unpkg.com/playhtml@latest/dist/style.css",document.head.appendChild(o),it.on("sync",c=>{c||console.error("Issue connecting to yjs..."),Ie=!0,console.log("[PLAYHTML]: Setting up elements... Time to have some fun 🛝"),Cr()}),it}function ml(n,t){const e=it.awareness.getLocalState();return((e==null?void 0:e[n])??{})[t]}function Tn(n){return n instanceof HTMLElement}function Er(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(!Er(n[r],t[r]))return!1;return!0}return!1}function yl(n,t,e,s){const r=q.get(t);return{...e,data:r.get(s)??(e.defaultData instanceof Function?e.defaultData(n):e.defaultData),awareness:ml(t,s)??e.myDefaultAwareness!==void 0?[e.myDefaultAwareness]:void 0,element:n,onChange:o=>{Er(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:()=>{Dr()}}}function _l(n){return n.defaultData!==void 0&&(typeof n.defaultData=="object"||typeof n.defaultData=="function")&&n.updateElement!==void 0}function bl(n,t){if(n===Le.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 ee[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)}it.awareness.getStates().forEach((e,s)=>{var r;for(const[i,o]of Object.entries(e)){const c=B.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=B.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 u=Array.from(h);a.__awareness=u}}})}function Cr(){if(Ie){for(const n of Sr()){const t=Array.from(document.querySelectorAll(`[${n}]`)).filter(Tn);t.length&&Promise.all(t.map(e=>Te(e,n)))}In&&(q.observe(n=>{n.changes.keys.forEach((t,e)=>{t.action==="add"&&q.set(e,q.get(e))})}),it.awareness.on("change",()=>Dr()),In=!1)}}const Ar={init:wl,setupPlayElements:Cr,setupPlayElement:El,removePlayElement:Dl,setupPlayElementForTag:Te,globalData:q,elementHandlers:B,eventHandlers:bt,dispatchPlayEvent:Cl,registerPlayEventListener:Lr,removePlayEventListener:Al};window.playhtml=Ar;function kl(n){if(B.has(n)||!Ie)return;B.has(n)||B.set(n,new Map),n!==Le.CanPlay&&ee[n],q.get(n)||q.set(n,new ft);const t=q.get(n);t.observe(e=>{e.changes.keys.forEach((s,r)=>{const i=B.get(n);if(s.action==="add"){const o=document.getElementById(r);if(!Tn(o)){console.log(`Element ${r} not an HTML element. Ignoring.`);return}Te(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 Sl(n,t){var e,s;return((s=(e=ee[t])==null?void 0:e.isValidElementForTag)==null?void 0:s.call(e,n))??!0}async function Te(n,t){var c;if(!Sl(n,t)||!Ie)return;if(!n.id){const l=n.getAttribute("selector-id");if(l){const a=kr.get(l)??0;n.id=btoa(`${t}-${l}-${a}`),kr.set(l,a+1)}else n.id=await ul(t,n)}const e=Zc(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}kl(t);const s=B.get(t),r=bl(t,n);if(!_l(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=q.get(t),o=yl(n,t,r,e);if(s.has(e)){s.get(e).reinitializeElementData(o);return}else s.set(e,new hl(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 El(n,{ignoreIfAlreadySetup:t}={}){if(!(t&&Object.keys(B||{}).some(e=>{var s;return(s=B.get(e))==null?void 0:s.has(n.id)}))){if(!Tn(n)){console.log(`Element ${n.id} not an HTML element. Ignoring.`);return}Promise.all(Sr().filter(e=>n.hasAttribute(e)).map(e=>Te(n,e)))}}function Dl(n){if(!(!n||!n.id))for(const t of Object.keys(B)){const e=B.get(t);e.has(n.id)&&e.delete(n.id)}}function Cl(n){const{type:t}=n;if(!bt.has(t)){console.error(`[playhtml] event "${t}" not registered.`);return}pl(n)}function Lr(n,t){const e=String(gl++);return bt.set(n,[...bt.get(n)??[],{type:n,...t,id:e}]),e}function Al(n,t){const e=bt.get(n);if(!e)return;const s=e.findIndex(r=>r.id===t);s!==-1&&(e.splice(s,1),e.length===0&&bt.delete(n))}S.playhtml=Ar,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
|