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