From 86ef473710830e7e157d5d54393eb829ebbb3cac Mon Sep 17 00:00:00 2001 From: Rizky Date: Tue, 20 Feb 2024 15:03:09 +0700 Subject: [PATCH] wip fix --- app/srv/core/main.js | 2 +- app/srv/ws/sync/actions/code_edit.ts | 2 +- app/srv/ws/sync/actions/yjs_diff_local.ts | 2 +- app/web/src/nova/ed/logic/ed-global.ts | 5 +- pkgs/core/utils/diff.test.ts | 56 ------------- pkgs/core/utils/diff/diff.test.ts | 84 +++++++++++++++++++ pkgs/core/utils/{ => diff}/diff.ts | 29 +++++-- .../lib/fast-myers-diff.ts} | 10 ++- 8 files changed, 120 insertions(+), 70 deletions(-) delete mode 100644 pkgs/core/utils/diff.test.ts create mode 100644 pkgs/core/utils/diff/diff.test.ts rename pkgs/core/utils/{ => diff}/diff.ts (81%) rename pkgs/core/utils/{diff-internal.ts => diff/lib/fast-myers-diff.ts} (98%) diff --git a/app/srv/core/main.js b/app/srv/core/main.js index fbef0a6a..96157df9 100644 --- a/app/srv/core/main.js +++ b/app/srv/core/main.js @@ -35,7 +35,7 @@ ${d}`),B.pop(),`{${F}}`}case"number":return isFinite(g)?String(g):t?t(g):"null"; transform: translate(${-100+o.value*200}%); `)})}),r]})})]})};var st=null;var Ol=class extends Error{constructor(t){super(t),this.name="DecompressionError"}},Ti=0,Ll=null,OI=null;function Dh(e,t,A){let i;if(A){let r=t;i=e.malloc_u8(r);let o=new Uint8Array(e.memory.buffer,i,r);try{A(o)}catch(s){throw e.free_u8(i,r),s}return Ti=r,i}if(typeof t=="string"){let r=Ti=function(s){let I=0,a=0,c=0,u=s.length;for(;I>>0;st.free_u8(A,Ti);let n=st.buffer()>>>0;return new Uint8Array(st.memory.buffer,n,i)}function dt(e,t){kh(st);let A=Dh(st,e,t),i=st.gzip_decompress(A,Ti)>>>0;if(st.free_u8(A,Ti),i===4294967295){let r=st.error_message(),o=st.error_message_len(),s=new Uint8Array(st.memory.buffer,r,o),I=new TextDecoder().decode(s);throw new Ol(I)}let n=st.buffer()>>>0;return new Uint8Array(st.memory.buffer,n,i)}function kh(e){if(!e)throw new Error("WASM not initialized")}var It=()=>new Map,bI=e=>{let t=It();return e.forEach((A,i)=>{t.set(i,A)}),t},BA=(e,t,A)=>{let i=e.get(t);return i===void 0&&e.set(t,i=A()),i},Sh=(e,t)=>{let A=[];for(let[i,n]of e)A.push(t(n,i));return A},Uh=(e,t)=>{for(let[A,i]of e)if(t(i,A))return!0;return!1};var LA=()=>new Set;var YI=e=>e[e.length-1];var Nh=(e,t)=>{for(let A=0;A{this.off(t,i),A(...n)};this.on(t,i)}off(t,A){let i=this._observers.get(t);i!==void 0&&(i.delete(A),i.size===0&&this._observers.delete(t))}emit(t,A){return fA((this._observers.get(t)||It()).values()).forEach(i=>i(...A))}destroy(){this._observers=It()}};var Rt=Math.floor;var jn=Math.abs;var zI=(e,t)=>ee>t?e:t,hx=Number.isNaN;var PI=e=>e!==0?e<0:1/e<0;var zl=Number.MAX_SAFE_INTEGER,px=Number.MIN_SAFE_INTEGER,Ex=1<<31;var xh=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&Rt(e)===e),mx=Number.isNaN,yx=Number.parseInt;var sD=String.fromCharCode,wx=String.fromCodePoint,Fx=sD(65535),ID=e=>e.toLowerCase(),aD=/^\s*/g,cD=e=>e.replace(aD,""),gD=/([A-Z])/g,Pl=(e,t)=>cD(e.replace(gD,A=>`${t}${ID(A)}`));var lD=e=>{let t=unescape(encodeURIComponent(e)),A=t.length,i=new Uint8Array(A);for(let n=0;ner.encode(e),Hh=er?uD:lD;var $n=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});$n&&$n.decode(new Uint8Array).length===1&&($n=null);var Xi=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},Uo=()=>new Xi;var BD=e=>{let t=e.cpos;for(let A=0;A{let t=new Uint8Array(BD(e)),A=0;for(let i=0;i{let A=e.cbuf.length;A-e.cpos{let A=e.cbuf.length;e.cpos===A&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(A*2),e.cpos=0),e.cbuf[e.cpos++]=t};var XI=Re;var Z=(e,t)=>{for(;t>127;)Re(e,128|127&t),t=Rt(t/128);Re(e,127&t)},ZI=(e,t)=>{let A=PI(t);for(A&&(t=-t),Re(e,(t>63?128:0)|(A?64:0)|63&t),t=Rt(t/64);t>0;)Re(e,(t>127?128:0)|127&t),t=Rt(t/128)},Tl=new Uint8Array(3e4),dD=Tl.length/3,QD=(e,t)=>{if(t.length{let A=unescape(encodeURIComponent(t)),i=A.length;Z(e,i);for(let n=0;n{let A=e.cbuf.length,i=e.cpos,n=zI(A-i,t.length),r=t.length-n;e.cbuf.set(t.subarray(0,n),i),e.cpos+=n,r>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(OA(A*2,r)),e.cbuf.set(t.subarray(n)),e.cpos=r)},Qt=(e,t)=>{Z(e,t.byteLength),No(e,t)},Xl=(e,t)=>{fD(e,t);let A=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,A},hD=(e,t)=>Xl(e,4).setFloat32(0,t,!1),pD=(e,t)=>Xl(e,8).setFloat64(0,t,!1),ED=(e,t)=>Xl(e,8).setBigInt64(0,t,!1);var vh=new DataView(new ArrayBuffer(4)),mD=e=>(vh.setFloat32(0,e),vh.getFloat32(0)===e),Ar=(e,t)=>{switch(typeof t){case"string":Re(e,119),Zi(e,t);break;case"number":xh(t)&&jn(t)<=2147483647?(Re(e,125),ZI(e,t)):mD(t)?(Re(e,124),hD(e,t)):(Re(e,123),pD(e,t));break;case"bigint":Re(e,122),ED(e,t);break;case"object":if(t===null)Re(e,126);else if(Yl(t)){Re(e,117),Z(e,t.length);for(let A=0;A0&&Z(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}};var Jh=e=>{e.count>0&&(ZI(e.encoder,e.count===1?e.s:-e.s),e.count>1&&Z(e.encoder,e.count-2))},Wi=class{constructor(){this.encoder=new Xi,this.s=0,this.count=0}write(t){this.s===t?this.count++:(Jh(this),this.count=1,this.s=t)}toUint8Array(){return Jh(this),eA(this.encoder)}};var qh=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);ZI(e.encoder,t),e.count>1&&Z(e.encoder,e.count-2)}},ir=class{constructor(){this.encoder=new Xi,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(qh(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return qh(this),eA(this.encoder)}},TI=class{constructor(){this.sarr=[],this.s="",this.lensE=new Wi}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){let t=new Xi;return this.sarr.push(this.s),this.s="",Zi(t,this.sarr.join("")),No(t,this.lensE.toUint8Array()),eA(t)}};var dA=e=>new Error(e),tA=()=>{throw dA("Method unimplemented")},AA=()=>{throw dA("Unexpected case")};var Kh=dA("Unexpected end of array"),Lh=dA("Integer out of Range"),nr=class{constructor(t){this.arr=t,this.pos=0}},tn=e=>new nr(e),Oh=e=>e.pos!==e.arr.length;var wD=(e,t)=>{let A=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,A},Ct=e=>wD(e,T(e));var ji=e=>e.arr[e.pos++];var T=e=>{let t=0,A=1,i=e.arr.length;for(;e.poszl)throw Lh}throw Kh},jI=e=>{let t=e.arr[e.pos++],A=t&63,i=64,n=(t&64)>0?-1:1;if(!(t&128))return n*A;let r=e.arr.length;for(;e.poszl)throw Lh}throw Kh};var FD=e=>{let t=T(e);if(t===0)return"";{let A=String.fromCodePoint(ji(e));if(--t<100)for(;t--;)A+=String.fromCodePoint(ji(e));else for(;t>0;){let i=t<1e4?t:1e4,n=e.arr.subarray(e.pos,e.pos+i);e.pos+=i,A+=String.fromCodePoint.apply(null,n),t-=i}return decodeURIComponent(escape(A))}},DD=e=>$n.decode(Ct(e)),$i=$n?DD:FD;var Zl=(e,t)=>{let A=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,A},kD=e=>Zl(e,4).getFloat32(0,!1),SD=e=>Zl(e,8).getFloat64(0,!1),UD=e=>Zl(e,8).getBigInt64(0,!1);var ND=[e=>{},e=>null,jI,kD,SD,UD,e=>!1,e=>!0,$i,e=>{let t=T(e),A={};for(let i=0;i{let t=T(e),A=[];for(let i=0;iND[127-ji(e)](e),xo=class extends nr{constructor(t,A){super(t),this.reader=A,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Oh(this)?this.count=T(this)+1:this.count=-1),this.count--,this.s}};var en=class extends nr{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=jI(this);let t=PI(this.s);this.count=1,t&&(this.s=-this.s,this.count=T(this)+2)}return this.count--,this.s}};var or=class extends nr{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let t=jI(this),A=t&1;this.diff=Rt(t/2),this.count=1,A&&(this.count=T(this)+2)}return this.s+=this.diff,this.count--,this.s}},WI=class{constructor(t){this.decoder=new en(t),this.str=$i(this.decoder),this.spos=0}read(){let t=this.spos+this.decoder.read(),A=this.str.slice(this.spos,t);return this.spos=t,A}};var Sx=crypto.subtle,bh=crypto.getRandomValues.bind(crypto);var Wl=()=>bh(new Uint32Array(1))[0];var GD="10000000-1000-4000-8000"+-1e11,Yh=()=>GD.replace(/[018]/g,e=>(e^Wl()&15>>e/4).toString(16));var Vh=Date.now;var jl=e=>new Promise(e);var xx=Promise.all.bind(Promise);var $l=e=>e===void 0?null:e;var eu=class{constructor(){this.map=new Map}setItem(t,A){this.map.set(t,A)}getItem(t){return this.map.get(t)}},zh=new eu,qD=!0;try{typeof localStorage<"u"&&localStorage&&(zh=localStorage,qD=!1)}catch{}var Ph=zh;var Th=Object.assign,KD=Object.keys,Xh=(e,t)=>{for(let A in e)t(e[A],A)};var _h=e=>KD(e).length;var Zh=e=>{for(let t in e)return!1;return!0},LD=(e,t)=>{for(let A in e)if(!t(e[A],A))return!1;return!0},OD=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Wh=(e,t)=>e===t||_h(e)===_h(t)&&LD(e,(A,i)=>(A!==void 0||OD(t,i))&&t[i]===A);var Go=(e,t,A=0)=>{try{for(;Ae;var $h=(e,t)=>t.includes(e);var Ho=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]";var Gx=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,QA,YD=[],VD=()=>{if(QA===void 0)if(Ho){QA=It();let e=process.argv,t=null;for(let A=0;A{if(e.length!==0){let[t,A]=e.split("=");QA.set(`--${Pl(t,"-")}`,A),QA.set(`-${Pl(t,"-")}`,A)}})):QA=It();return QA},tu=e=>VD().has(e);var Au=e=>Ho?$l(process.env[e.toUpperCase()]):$l(Ph.getItem(e));var zD=e=>tu("--"+e)||Au(e)!==null,Hx=zD("production"),tp=Ho&&$h(process.env.FORCE_COLOR,["true","1","2"]),Ap=!tu("no-colors")&&(!Ho||process.stdout.isTTY||tp)&&(!Ho||tu("color")||tp||Au("COLORTERM")!==null||(Au("TERM")||"").includes("color"));var _D=e=>new Uint8Array(e);var ip=e=>{let t=_D(e.byteLength);return t.set(e),t};var iu=class{constructor(t,A){this.left=t,this.right=A}},CA=(e,t)=>new iu(e,t);var An=typeof document<"u"?document:{};var Mx=typeof DOMParser<"u"?new DOMParser:null;var np=e=>Sh(e,(t,A)=>`${A}:${t};`).join("");var vx=An.ELEMENT_NODE,Jx=An.TEXT_NODE,qx=An.CDATA_SECTION_NODE,Rx=An.COMMENT_NODE,Kx=An.DOCUMENT_NODE,Lx=An.DOCUMENT_TYPE_NODE,Ox=An.DOCUMENT_FRAGMENT_NODE;var hA=Symbol;var Mo=hA(),vo=hA(),nu=hA(),ru=hA(),ou=hA(),Jo=hA(),su=hA(),qo=hA(),Iu=hA(),rp=e=>{let t=[],A=[],i=0;for(;i{let t=[],A=[],i=It(),n=[],r=0;for(;r0||I.length>0?(t.push("%c"+o),A.push(I)):t.push(o)}else break}for(r>0&&(n=A,n.unshift(t.join("")));r{console.log(...tk(e)),Ak.forEach(t=>t.print(e))};var Ak=LA();var sp=e=>({[Symbol.iterator](){return this},next:e}),Ip=(e,t)=>sp(()=>{let A;do A=e.next();while(!A.done&&!t(A.value));return A}),$I=(e,t)=>sp(()=>{let{done:A,value:i}=e.next();return{done:A,value:A?void 0:t(i)}});var Ko=class{constructor(t,A){this.clock=t,this.len=A}},nn=class{constructor(){this.clients=new Map}},mp=(e,t,A)=>t.clients.forEach((i,n)=>{let r=e.doc.store.clients.get(n);for(let o=0;o{let A=0,i=e.length-1;for(;A<=i;){let n=Rt((A+i)/2),r=e[n],o=r.clock;if(o<=t){if(t{let A=e.clients.get(t.client);return A!==void 0&&sk(A,t.clock)!==null},Du=e=>{e.clients.forEach(t=>{t.sort((n,r)=>n.clock-r.clock);let A,i;for(A=1,i=1;A=r.clock?n.len=OA(n.len,r.clock+r.len-n.clock):(i{let t=new nn;for(let A=0;A{if(!t.clients.has(n)){let r=i.slice();for(let o=A+1;o{BA(e.clients,t,()=>[]).push(new Ko(A,i))},wp=()=>new nn,ak=e=>{let t=wp();return e.clients.forEach((A,i)=>{let n=[];for(let r=0;r0&&t.clients.set(i,n)}),t},gr=(e,t)=>{Z(e.restEncoder,t.clients.size),fA(t.clients.entries()).sort((A,i)=>i[0]-A[0]).forEach(([A,i])=>{e.resetDsCurVal(),Z(e.restEncoder,A);let n=i.length;Z(e.restEncoder,n);for(let r=0;r{let t=new nn,A=T(e.restDecoder);for(let i=0;i0){let o=BA(t.clients,n,()=>[]);for(let s=0;s{let i=new nn,n=T(e.restDecoder);for(let r=0;r0){let r=new bA;return Z(r.restEncoder,0),gr(r,i),r.toUint8Array()}return null};var Fp=Wl,Lo=class e extends VI{constructor({guid:t=Yh(),collectionid:A=null,gc:i=!0,gcFilter:n=()=>!0,meta:r=null,autoLoad:o=!1,shouldLoad:s=!0}={}){super(),this.gc=i,this.gcFilter=n,this.clientID=Fp(),this.guid=t,this.collectionid=A,this.share=new Map,this.store=new ca,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=s,this.autoLoad=o,this.meta=r,this.isLoaded=!1,this.isSynced=!1,this.whenLoaded=jl(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let I=()=>jl(a=>{let c=u=>{(u===void 0||u===!0)&&(this.off("sync",c),a())};this.on("sync",c)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=I()),this.isSynced=a===void 0||a===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[])}),this.whenSynced=I()}load(){let t=this._item;t!==null&&!this.shouldLoad&&Be(t.parent.doc,A=>{A.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(fA(this.subdocs).map(t=>t.guid))}transact(t,A=null){return Be(this,t,A)}get(t,A=He){let i=BA(this.share,t,()=>{let r=new A;return r._integrate(this,null),r}),n=i.constructor;if(A!==He&&n!==A)if(n===He){let r=new A;r._map=i._map,i._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=r}),r._start=i._start;for(let o=r._start;o!==null;o=o.right)o.parent=r;return r._length=i._length,this.share.set(t,r),r._integrate(this,null),r}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return i}getArray(t=""){return this.get(t,Ba)}getText(t=""){return this.get(t,_o)}getMap(t=""){return this.get(t,zo)}getXmlFragment(t=""){return this.get(t,ar)}toJSON(){let t={};return this.share.forEach((A,i)=>{t[i]=A.toJSON()}),t}destroy(){fA(this.subdocs).forEach(A=>A.destroy());let t=this._item;if(t!==null){this._item=null;let A=t.content;A.doc=new e({guid:this.guid,...A.opts,shouldLoad:!1}),A.doc._item=t,Be(t.parent.doc,i=>{let n=A.doc;t.deleted||i.subdocsAdded.add(n),i.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}on(t,A){super.on(t,A)}off(t,A){super.off(t,A)}},oa=class{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return T(this.restDecoder)}readDsLen(){return T(this.restDecoder)}},sa=class extends oa{readLeftID(){return ee(T(this.restDecoder),T(this.restDecoder))}readRightID(){return ee(T(this.restDecoder),T(this.restDecoder))}readClient(){return T(this.restDecoder)}readInfo(){return ji(this.restDecoder)}readString(){return $i(this.restDecoder)}readParentInfo(){return T(this.restDecoder)===1}readTypeRef(){return T(this.restDecoder)}readLen(){return T(this.restDecoder)}readAny(){return rr(this.restDecoder)}readBuf(){return ip(Ct(this.restDecoder))}readJSON(){return JSON.parse($i(this.restDecoder))}readKey(){return $i(this.restDecoder)}},gu=class{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=T(this.restDecoder),this.dsCurrVal}readDsLen(){let t=T(this.restDecoder)+1;return this.dsCurrVal+=t,t}},wi=class extends gu{constructor(t){super(t),this.keys=[],T(t),this.keyClockDecoder=new or(Ct(t)),this.clientDecoder=new en(Ct(t)),this.leftClockDecoder=new or(Ct(t)),this.rightClockDecoder=new or(Ct(t)),this.infoDecoder=new xo(Ct(t),ji),this.stringDecoder=new WI(Ct(t)),this.parentInfoDecoder=new xo(Ct(t),ji),this.typeRefDecoder=new en(Ct(t)),this.lenDecoder=new en(Ct(t))}readLeftID(){return new yi(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new yi(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 rr(this.restDecoder)}readBuf(){return Ct(this.restDecoder)}readJSON(){return rr(this.restDecoder)}readKey(){let t=this.keyClockDecoder.read();if(t{i=OA(i,t[0].id.clock);let n=pA(t,i);Z(e.restEncoder,t.length-n),e.writeClient(A),Z(e.restEncoder,i);let r=t[n];r.write(e,i-r.id.clock);for(let o=n+1;o{let i=new Map;A.forEach((n,r)=>{Ke(t,r)>n&&i.set(r,n)}),Ca(t).forEach((n,r)=>{A.has(r)||i.set(r,0)}),Z(e.restEncoder,i.size),fA(i.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{ck(e,t.clients.get(n),n,r)})},gk=(e,t)=>{let A=It(),i=T(e.restDecoder);for(let n=0;n{let i=[],n=fA(A.keys()).sort((g,B)=>g-B);if(n.length===0)return null;let r=()=>{if(n.length===0)return null;let g=A.get(n[n.length-1]);for(;g.refs.length===g.i;)if(n.pop(),n.length>0)g=A.get(n[n.length-1]);else return null;return g},o=r();if(o===null)return null;let s=new ca,I=new Map,a=(g,B)=>{let p=I.get(g);(p==null||p>B)&&I.set(g,B)},c=o.refs[o.i++],u=new Map,l=()=>{for(let g of i){let B=g.id.client,p=A.get(B);p?(p.i--,s.clients.set(B,p.refs.slice(p.i)),A.delete(B),p.i=0,p.refs=[]):s.clients.set(B,[g]),n=n.filter(U=>U!==B)}i.length=0};for(;;){if(c.constructor!==pt){let B=BA(u,c.id.client,()=>Ke(t,c.id.client))-c.id.clock;if(B<0)i.push(c),a(c.id.client,c.id.clock-1),l();else{let p=c.getMissing(e,t);if(p!==null){i.push(c);let U=A.get(p)||{refs:[],i:0};if(U.refs.length===U.i)a(p,Ke(t,p)),l();else{c=U.refs[U.i++];continue}}else(B===0||B0)c=i.pop();else if(o!==null&&o.i0){let g=new bA;return Su(g,s,new Map),Z(g.restEncoder,0),{missing:I,update:g.toUint8Array()}}return null},uk=(e,t)=>Su(e,t.doc.store,t.beforeState),Bk=(e,t,A,i=new wi(e))=>Be(t,n=>{n.local=!1;let r=!1,o=n.doc,s=o.store,I=gk(i,o),a=lk(n,s,I),c=s.pendingStructs;if(c){for(let[l,g]of c.missing)if(gg)&&c.missing.set(l,g)}c.update=ga([c.update,a.update])}}else s.pendingStructs=a;let u=gp(i,n,s);if(s.pendingDs){let l=new wi(tn(s.pendingDs));T(l.restDecoder);let g=gp(l,n,s);u&&g?s.pendingDs=ga([u,g]):s.pendingDs=u||g}else s.pendingDs=u;if(r){let l=s.pendingStructs.update;s.pendingStructs=null,Dp(n.doc,l)}},A,!1);var Dp=(e,t,A,i=wi)=>{let n=tn(t);Bk(n,e,A,new i(n))},kp=(e,t,A)=>Dp(e,t,A,sa),fk=(e,t,A=new Map)=>{Su(e,t.store,A),gr(e,ak(t.store))},dk=(e,t=new Uint8Array([0]),A=new bA)=>{let i=Up(t);fk(A,e,i);let n=[A.toUint8Array()];if(e.store.pendingDs&&n.push(e.store.pendingDs),e.store.pendingStructs&&n.push(Uk(e.store.pendingStructs.update,t)),n.length>1){if(A.constructor===rn)return kk(n.map((r,o)=>o===0?r:xk(r)));if(A.constructor===bA)return ga(n)}return n[0]},Sp=(e,t)=>dk(e,t,new rn),Qk=e=>{let t=new Map,A=T(e.restDecoder);for(let i=0;iQk(new oa(tn(e))),Np=(e,t)=>(Z(e.restEncoder,t.size),fA(t.entries()).sort((A,i)=>i[0]-A[0]).forEach(([A,i])=>{Z(e.restEncoder,A),Z(e.restEncoder,i)}),e),Ck=(e,t)=>Np(e,Ca(t.store)),hk=(e,t=new aa)=>(e instanceof Map?Np(t,e):Ck(t,e),t.toUint8Array()),xp=e=>hk(e,new Ia),lu=class{constructor(){this.l=[]}},lp=()=>new lu,up=(e,t)=>e.l.push(t),Bp=(e,t)=>{let A=e.l,i=A.length;e.l=A.filter(n=>t!==n),i===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Gp=(e,t,A)=>Go(e.l,[t,A]),yi=class{constructor(t,A){this.client=t,this.clock=A}},ea=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,ee=(e,t)=>new yi(e,t);var pk=e=>{for(let[t,A]of e.doc.share.entries())if(A===e)return t;throw AA()};var uu=class{constructor(t,A){this.ds=t,this.sv=A}};var Ek=(e,t)=>new uu(e,t),tG=Ek(wp(),new Map);var sr=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!yp(t.ds,e.id),Bu=(e,t)=>{let A=BA(e.meta,Bu,LA),i=e.doc.store;A.has(t)||(t.sv.forEach((n,r)=>{n{}),A.add(t))};var ca=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Ca=e=>{let t=new Map;return e.clients.forEach((A,i)=>{let n=A[A.length-1];t.set(i,n.id.clock+n.length)}),t},Ke=(e,t)=>{let A=e.clients.get(t);if(A===void 0)return 0;let i=A[A.length-1];return i.id.clock+i.length},Hp=(e,t)=>{let A=e.clients.get(t.id.client);if(A===void 0)A=[],e.clients.set(t.id.client,A);else{let i=A[A.length-1];if(i.id.clock+i.length!==t.id.clock)throw AA()}A.push(t)},pA=(e,t)=>{let A=0,i=e.length-1,n=e[i],r=n.id.clock;if(r===t)return i;let o=Rt(t/(r+n.length-1)*i);for(;A<=i;){if(n=e[o],r=n.id.clock,r<=t){if(t{let A=e.clients.get(t.client);return A[pA(A,t.clock)]},au=mk,fu=(e,t,A)=>{let i=pA(t,A),n=t[i];return n.id.clock{let A=e.doc.store.clients.get(t.client);return A[fu(e,A,t.clock)]},fp=(e,t,A)=>{let i=t.clients.get(A.client),n=pA(i,A.clock),r=i[n];return A.clock!==r.id.clock+r.length-1&&r.constructor!==ht&&i.splice(n+1,0,Qa(e,r,A.clock-r.id.clock+1)),r},yk=(e,t,A)=>{let i=e.clients.get(t.id.client);i[pA(i,t.id.clock)]=A},Mp=(e,t,A,i,n)=>{if(i===0)return;let r=A+i,o=fu(e,t,A),s;do s=t[o++],rt.deleteSet.clients.size===0&&!Uh(t.afterState,(A,i)=>t.beforeState.get(i)!==A)?!1:(Du(t.deleteSet),uk(e,t),gr(e,t.deleteSet),!0),Qp=(e,t,A)=>{let i=t._item;(i===null||i.id.clock<(e.beforeState.get(i.id.client)||0)&&!i.deleted)&&BA(e.changed,t,LA).add(A)},ia=(e,t)=>{let A=e[t],i=e[t-1],n=t;for(;n>0;A=i,i=e[--n-1]){if(i.deleted===A.deleted&&i.constructor===A.constructor&&i.mergeWith(A)){A instanceof Le&&A.parentSub!==null&&A.parent._map.get(A.parentSub)===A&&A.parent._map.set(A.parentSub,i);continue}break}let r=t-n;return r&&e.splice(t+1-r,r),r},wk=(e,t,A)=>{for(let[i,n]of e.clients.entries()){let r=t.clients.get(i);for(let o=n.length-1;o>=0;o--){let s=n[o],I=s.clock+s.len;for(let a=pA(r,s.clock),c=r[a];a{e.clients.forEach((A,i)=>{let n=t.clients.get(i);for(let r=A.length-1;r>=0;r--){let o=A[r],s=zI(n.length-1,1+pA(n,o.clock+o.len-1));for(let I=s,a=n[I];I>0&&a.id.clock>=o.clock;a=n[I])I-=1+ia(n,I)}})};var vp=(e,t)=>{if(ts.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(A,I)})),s.push(()=>{A.changedParentTypes.forEach((I,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(I=I.filter(c=>c.target._item===null||!c.target._item.deleted),I.forEach(c=>{c.currentTarget=a,c._path=null}),I.sort((c,u)=>c.path.length-u.path.length),Gp(a._dEH,I,A))})}),s.push(()=>i.emit("afterTransaction",[A,i])),Go(s,[]),A._needFormattingCleanup&&bk(A)}finally{i.gc&&wk(r,n,i.gcFilter),Fk(r,n),A.afterState.forEach((c,u)=>{let l=A.beforeState.get(u)||0;if(l!==c){let g=n.clients.get(u),B=OA(pA(g,l),1);for(let p=g.length-1;p>=B;)p-=1+ia(g,p)}});for(let c=o.length-1;c>=0;c--){let{client:u,clock:l}=o[c].id,g=n.clients.get(u),B=pA(g,l);B+11||B>0&&ia(g,B)}if(!A.local&&A.afterState.get(i.clientID)!==A.beforeState.get(i.clientID)&&(op(qo,Mo,"[yjs] ",vo,Jo,"Changed the client-id because another client seems to be using it."),i.clientID=Fp()),i.emit("afterTransactionCleanup",[A,i]),i._observers.has("update")){let c=new rn;dp(c,A)&&i.emit("update",[c.toUint8Array(),A.origin,i,A])}if(i._observers.has("updateV2")){let c=new bA;dp(c,A)&&i.emit("updateV2",[c.toUint8Array(),A.origin,i,A])}let{subdocsAdded:s,subdocsLoaded:I,subdocsRemoved:a}=A;(s.size>0||a.size>0||I.size>0)&&(s.forEach(c=>{c.clientID=i.clientID,c.collectionid==null&&(c.collectionid=i.collectionid),i.subdocs.add(c)}),a.forEach(c=>i.subdocs.delete(c)),i.emit("subdocs",[{loaded:I,added:s,removed:a},i,A]),a.forEach(c=>c.destroy())),e.length<=t+1?(i._transactionCleanups=[],i.emit("afterAllTransactions",[i,e])):vp(e,t+1)}}},Be=(e,t,A=null,i=!0)=>{let n=e._transactionCleanups,r=!1,o=null;e._transaction===null&&(r=!0,e._transaction=new du(e,A,i),n.push(e._transaction),n.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(r){let s=e._transaction===n[0];e._transaction=null,s&&vp(n,0)}}return o};function*Dk(e){let t=T(e.restDecoder);for(let A=0;Aga(e,sa,rn);var Sk=(e,t)=>{if(e.constructor===ht){let{client:A,clock:i}=e.id;return new ht(ee(A,i+t),e.length-t)}else if(e.constructor===pt){let{client:A,clock:i}=e.id;return new pt(ee(A,i+t),e.length-t)}else{let A=e,{client:i,clock:n}=A.id;return new Le(ee(i,n+t),null,ee(i,n+t-1),null,A.rightOrigin,A.parent,A.parentSub,A.content.splice(t))}},ga=(e,t=wi,A=bA)=>{if(e.length===1)return e[0];let i=e.map(c=>new t(tn(c))),n=i.map(c=>new Oo(c,!0)),r=null,o=new A,s=new bo(o);for(;n=n.filter(l=>l.curr!==null),n.sort((l,g)=>{if(l.curr.id.client===g.curr.id.client){let B=l.curr.id.clock-g.curr.id.clock;return B===0?l.curr.constructor===g.curr.constructor?0:l.curr.constructor===pt?1:-1:B}else return g.curr.id.client-l.curr.id.client}),n.length!==0;){let c=n[0],u=c.curr.id.client;if(r!==null){let l=c.curr,g=!1;for(;l!==null&&l.id.clock+l.length<=r.struct.id.clock+r.struct.length&&l.id.client>=r.struct.id.client;)l=c.next(),g=!0;if(l===null||l.id.client!==u||g&&l.id.clock>r.struct.id.clock+r.struct.length)continue;if(u!==r.struct.id.client)Ei(s,r.struct,r.offset),r={struct:l,offset:0},c.next();else if(r.struct.id.clock+r.struct.length0&&(r.struct.constructor===pt?r.struct.length-=B:l=Sk(l,B)),r.struct.mergeWith(l)||(Ei(s,r.struct,r.offset),r={struct:l,offset:0},c.next())}}else r={struct:c.curr,offset:0},c.next();for(let l=c.curr;l!==null&&l.id.client===u&&l.id.clock===r.struct.id.clock+r.struct.length&&l.constructor!==pt;l=c.next())Ei(s,r.struct,r.offset),r={struct:l,offset:0}}r!==null&&(Ei(s,r.struct,r.offset),r=null),Uu(s);let I=i.map(c=>ku(c)),a=Ik(I);return gr(o,a),o.toUint8Array()},Uk=(e,t,A=wi,i=bA)=>{let n=Up(t),r=new i,o=new bo(r),s=new A(tn(e)),I=new Oo(s,!1);for(;I.curr;){let c=I.curr,u=c.id.client,l=n.get(u)||0;if(I.curr.constructor===pt){I.next();continue}if(c.id.clock+c.length>l)for(Ei(o,c,OA(l-c.id.clock,0)),I.next();I.curr&&I.curr.id.client===u;)Ei(o,I.curr,0),I.next();else for(;I.curr&&I.curr.id.client===u&&I.curr.id.clock+I.curr.length<=l;)I.next()}Uu(o);let a=ku(s);return gr(r,a),r.toUint8Array()};var Jp=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:eA(e.encoder.restEncoder)}),e.encoder.restEncoder=Uo(),e.written=0)},Ei=(e,t,A)=>{e.written>0&&e.currClient!==t.id.client&&Jp(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),Z(e.encoder.restEncoder,t.id.clock+A)),t.write(e.encoder,A),e.written++},Uu=e=>{Jp(e);let t=e.encoder.restEncoder;Z(t,e.clientStructs.length);for(let A=0;A{let n=new A(tn(e)),r=new Oo(n,!1),o=new i,s=new bo(o);for(let a=r.curr;a!==null;a=r.next())Ei(s,t(a),0);Uu(s);let I=ku(n);return gr(o,I),o.toUint8Array()};var xk=e=>Nk(e,jh,wi,rn),Cp="You must not compute changes after the event-handler fired.",Ir=class{constructor(t,A){this.target=t,this.currentTarget=t,this.transaction=A,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Gk(this.currentTarget,this.target))}deletes(t){return yp(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw dA(Cp);let t=new Map,A=this.target;this.transaction.changed.get(A).forEach(n=>{if(n!==null){let r=A._map.get(n),o,s;if(this.adds(r)){let I=r.left;for(;I!==null&&this.adds(I);)I=I.left;if(this.deletes(r))if(I!==null&&this.deletes(I))o="delete",s=YI(I.content.getContent());else return;else I!==null&&this.deletes(I)?(o="update",s=YI(I.content.getContent())):(o="add",s=void 0)}else if(this.deletes(r))o="delete",s=YI(r.content.getContent());else return;t.set(n,{action:o,oldValue:s})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw dA(Cp);let A=this.target,i=LA(),n=LA(),r=[];if(t={added:i,deleted:n,delta:r,keys:this.keys},this.transaction.changed.get(A).has(null)){let s=null,I=()=>{s&&r.push(s)};for(let a=A._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((s===null||s.delete===void 0)&&(I(),s={delete:0}),s.delete+=a.length,n.add(a)):this.adds(a)?((s===null||s.insert===void 0)&&(I(),s={insert:[]}),s.insert=s.insert.concat(a.content.getContent()),i.add(a)):((s===null||s.retain===void 0)&&(I(),s={retain:0}),s.retain+=a.length);s!==null&&s.retain===void 0&&I()}this._changes=t}return t}},Gk=(e,t)=>{let A=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)A.unshift(t._item.parentSub);else{let i=0,n=t._item.parent._start;for(;n!==t._item&&n!==null;)n.deleted||i++,n=n.right;A.unshift(i)}t=t._item.parent}return A},qp=80,Nu=0,Qu=class{constructor(t,A){t.marker=!0,this.p=t,this.index=A,this.timestamp=Nu++}},Hk=e=>{e.timestamp=Nu++},Rp=(e,t,A)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=A,e.timestamp=Nu++},Mk=(e,t,A)=>{if(e.length>=qp){let i=e.reduce((n,r)=>n.timestamp{if(e._start===null||t===0||e._searchMarker===null)return null;let A=e._searchMarker.length===0?null:e._searchMarker.reduce((r,o)=>jn(t-r.index)t;)i=i.left,!i.deleted&&i.countable&&(n-=i.length);for(;i.left!==null&&i.left.id.client===i.id.client&&i.left.id.clock+i.left.length===i.id.clock;)i=i.left,!i.deleted&&i.countable&&(n-=i.length);return A!==null&&jn(A.index-n){for(let i=e.length-1;i>=0;i--){let n=e[i];if(A>0){let r=n.p;for(r.marker=!1;r&&(r.deleted||!r.countable);)r=r.left,r&&!r.deleted&&r.countable&&(n.index-=r.length);if(r===null||r.marker===!0){e.splice(i,1);continue}n.p=r,r.marker=!0}(t0&&t===n.index)&&(n.index=OA(t,n.index+A))}};var pa=(e,t,A)=>{let i=e,n=t.changedParentTypes;for(;BA(n,e,()=>[]).push(A),e._item!==null;)e=e._item.parent;Gp(i._eH,A,t)},He=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=lp(),this._dEH=lp(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,A){this.doc=t,this._item=A}_copy(){throw tA()}clone(){throw tA()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,A){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){up(this._eH,t)}observeDeep(t){up(this._dEH,t)}unobserve(t){Bp(this._eH,t)}unobserveDeep(t){Bp(this._dEH,t)}toJSON(){}},Kp=(e,t,A)=>{t<0&&(t=e._length+t),A<0&&(A=e._length+A);let i=A-t,n=[],r=e._start;for(;r!==null&&i>0;){if(r.countable&&!r.deleted){let o=r.content.getContent();if(o.length<=t)t-=o.length;else{for(let s=t;s0;s++)n.push(o[s]),i--;t=0}}r=r.right}return n},Lp=e=>{let t=[],A=e._start;for(;A!==null;){if(A.countable&&!A.deleted){let i=A.content.getContent();for(let n=0;n{let A=0,i=e._start;for(;i!==null;){if(i.countable&&!i.deleted){let n=i.content.getContent();for(let r=0;r{let A=[];return Vo(e,(i,n)=>{A.push(t(i,n,e))}),A},vk=e=>{let t=e._start,A=null,i=0;return{[Symbol.iterator](){return this},next:()=>{if(A===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};A=t.content.getContent(),i=0,t=t.right}let n=A[i++];return A.length<=i&&(A=null),{done:!1,value:n}}}},bp=(e,t)=>{let A=ha(e,t),i=e._start;for(A!==null&&(i=A.p,t-=A.index);i!==null;i=i.right)if(!i.deleted&&i.countable){if(t{let n=A,r=e.doc,o=r.clientID,s=r.store,I=A===null?t._start:A.right,a=[],c=()=>{a.length>0&&(n=new Le(ee(o,Ke(s,o)),n,n&&n.lastId,I,I&&I.id,t,null,new cr(a)),n.integrate(e,0),a=[])};i.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(c(),u.constructor){case Uint8Array:case ArrayBuffer:n=new Le(ee(o,Ke(s,o)),n,n&&n.lastId,I,I&&I.id,t,null,new Xo(new Uint8Array(u))),n.integrate(e,0);break;case Lo:n=new Le(ee(o,Ke(s,o)),n,n&&n.lastId,I,I&&I.id,t,null,new Zo(u)),n.integrate(e,0);break;default:if(u instanceof He)n=new Le(ee(o,Ke(s,o)),n,n&&n.lastId,I,I&&I.id,t,null,new VA(u)),n.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),c()},Yp=()=>dA("Length exceeded!"),Vp=(e,t,A,i)=>{if(A>t._length)throw Yp();if(A===0)return t._searchMarker&&Yo(t._searchMarker,A,i.length),la(e,t,null,i);let n=A,r=ha(t,A),o=t._start;for(r!==null&&(o=r.p,A-=r.index,A===0&&(o=o.prev,A+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(A<=o.length){A{let n=(t._searchMarker||[]).reduce((r,o)=>o.index>r.index?o:r,{index:0,p:t._start}).p;if(n)for(;n.right;)n=n.right;return la(e,t,n,A)},zp=(e,t,A,i)=>{if(i===0)return;let n=A,r=i,o=ha(t,A),s=t._start;for(o!==null&&(s=o.p,A-=o.index);s!==null&&A>0;s=s.right)!s.deleted&&s.countable&&(A0&&s!==null;)s.deleted||(i0)throw Yp();t._searchMarker&&Yo(t._searchMarker,n,-r+i)},ua=(e,t,A)=>{let i=t._map.get(A);i!==void 0&&i.delete(e)},xu=(e,t,A,i)=>{let n=t._map.get(A)||null,r=e.doc,o=r.clientID,s;if(i==null)s=new cr([i]);else switch(i.constructor){case Number:case Object:case Boolean:case Array:case String:s=new cr([i]);break;case Uint8Array:s=new Xo(i);break;case Lo:s=new Zo(i);break;default:if(i instanceof He)s=new VA(i);else throw new Error("Unexpected content type")}new Le(ee(o,Ke(r.store,o)),n,n&&n.lastId,null,null,t,A,s).integrate(e,0)},Gu=(e,t)=>{let A=e._map.get(t);return A!==void 0&&!A.deleted?A.content.getContent()[A.length-1]:void 0},Pp=e=>{let t={};return e._map.forEach((A,i)=>{A.deleted||(t[i]=A.content.getContent()[A.length-1])}),t},_p=(e,t)=>{let A=e._map.get(t);return A!==void 0&&!A.deleted};var qk=(e,t)=>{let A={};return e._map.forEach((i,n)=>{let r=i;for(;r!==null&&(!t.sv.has(r.id.client)||r.id.clock>=(t.sv.get(r.id.client)||0));)r=r.left;r!==null&&sr(r,t)&&(A[n]=r.content.getContent()[r.length-1])}),A},ta=e=>Ip(e.entries(),t=>!t[1].deleted),Cu=class extends Ir{constructor(t,A){super(t,A),this._transaction=A}},Ba=class e extends He{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let A=new e;return A.push(t),A}_integrate(t,A){super._integrate(t,A),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(A=>A instanceof He?A.clone():A)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}_callObserver(t,A){super._callObserver(t,A),pa(this,t,new Cu(this,t))}insert(t,A){this.doc!==null?Be(this.doc,i=>{Vp(i,this,t,A)}):this._prelimContent.splice(t,0,...A)}push(t){this.doc!==null?Be(this.doc,A=>{Jk(A,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,A=1){this.doc!==null?Be(this.doc,i=>{zp(i,this,t,A)}):this._prelimContent.splice(t,A)}get(t){return bp(this,t)}toArray(){return Lp(this)}slice(t=0,A=this.length){return Kp(this,t,A)}toJSON(){return this.map(t=>t instanceof He?t.toJSON():t)}map(t){return Op(this,t)}forEach(t){Vo(this,t)}[Symbol.iterator](){return vk(this)}_write(t){t.writeTypeRef(nS)}},Rk=e=>new Ba,hu=class extends Ir{constructor(t,A,i){super(t,A),this.keysChanged=i}},zo=class e extends He{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,A){super._integrate(t,A),this._prelimContent.forEach((i,n)=>{this.set(n,i)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((A,i)=>{t.set(i,A instanceof He?A.clone():A)}),t}_callObserver(t,A){pa(this,t,new hu(this,t,A))}toJSON(){let t={};return this._map.forEach((A,i)=>{if(!A.deleted){let n=A.content.getContent()[A.length-1];t[i]=n instanceof He?n.toJSON():n}}),t}get size(){return[...ta(this._map)].length}keys(){return $I(ta(this._map),t=>t[0])}values(){return $I(ta(this._map),t=>t[1].content.getContent()[t[1].length-1])}entries(){return $I(ta(this._map),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this._map.forEach((A,i)=>{A.deleted||t(A.content.getContent()[A.length-1],i,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?Be(this.doc,A=>{ua(A,this,t)}):this._prelimContent.delete(t)}set(t,A){return this.doc!==null?Be(this.doc,i=>{xu(i,this,t,A)}):this._prelimContent.set(t,A),A}get(t){return Gu(this,t)}has(t){return _p(this,t)}clear(){this.doc!==null?Be(this.doc,t=>{this.forEach(function(A,i,n){ua(t,n,i)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(rS)}},Kk=e=>new zo,mi=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&Wh(e,t),Po=class{constructor(t,A,i,n){this.left=t,this.right=A,this.index=i,this.currentAttributes=n}forward(){switch(this.right===null&&AA(),this.right.content.constructor){case Me:this.right.deleted||lr(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}},hp=(e,t,A)=>{for(;t.right!==null&&A>0;){switch(t.right.content.constructor){case Me:t.right.deleted||lr(t.currentAttributes,t.right.content);break;default:t.right.deleted||(A{let i=new Map,n=ha(t,A);if(n){let r=new Po(n.p.left,n.p,n.index,i);return hp(e,r,A-n.index)}else{let r=new Po(null,t._start,0,i);return hp(e,r,A)}},Tp=(e,t,A,i)=>{for(;A.right!==null&&(A.right.deleted===!0||A.right.content.constructor===Me&&mi(i.get(A.right.content.key),A.right.content.value));)A.right.deleted||i.delete(A.right.content.key),A.forward();let n=e.doc,r=n.clientID;i.forEach((o,s)=>{let I=A.left,a=A.right,c=new Le(ee(r,Ke(n.store,r)),I,I&&I.lastId,a,a&&a.id,t,null,new Me(s,o));c.integrate(e,0),A.right=c,A.forward()})},lr=(e,t)=>{let{key:A,value:i}=t;i===null?e.delete(A):e.set(A,i)},Xp=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===Me&&mi(t[e.right.content.key]||null,e.right.content.value)))break;e.forward()}},Zp=(e,t,A,i)=>{let n=e.doc,r=n.clientID,o=new Map;for(let s in i){let I=i[s],a=A.currentAttributes.get(s)||null;if(!mi(a,I)){o.set(s,a);let{left:c,right:u}=A;A.right=new Le(ee(r,Ke(n.store,r)),c,c&&c.lastId,u,u&&u.id,t,null,new Me(s,I)),A.right.integrate(e,0),A.forward()}}return o},cu=(e,t,A,i,n)=>{A.currentAttributes.forEach((l,g)=>{n[g]===void 0&&(n[g]=null)});let r=e.doc,o=r.clientID;Xp(A,n);let s=Zp(e,t,A,n),I=i.constructor===String?new YA(i):i instanceof He?new VA(i):new on(i),{left:a,right:c,index:u}=A;t._searchMarker&&Yo(t._searchMarker,A.index,I.getLength()),c=new Le(ee(o,Ke(r.store,o)),a,a&&a.lastId,c,c&&c.id,t,null,I),c.integrate(e,0),A.right=c,A.index=u,A.forward(),Tp(e,t,A,s)},pp=(e,t,A,i,n)=>{let r=e.doc,o=r.clientID;Xp(A,n);let s=Zp(e,t,A,n);e:for(;A.right!==null&&(i>0||s.size>0&&(A.right.deleted||A.right.content.constructor===Me));){if(!A.right.deleted)switch(A.right.content.constructor){case Me:{let{key:I,value:a}=A.right.content,c=n[I];if(c!==void 0){if(mi(c,a))s.delete(I);else{if(i===0)break e;s.set(I,a)}A.right.delete(e)}else A.currentAttributes.set(I,a);break}default:i0){let I="";for(;i>0;i--)I+=` `;A.right=new Le(ee(o,Ke(r.store,o)),A.left,A.left&&A.left.lastId,A.right,A.right&&A.right.id,t,null,new YA(I)),A.right.integrate(e,0),A.forward()}Tp(e,t,A,s)},Wp=(e,t,A,i,n)=>{let r=t,o=It();for(;r&&(!r.countable||r.deleted);){if(!r.deleted&&r.content.constructor===Me){let a=r.content;o.set(a.key,a)}r=r.right}let s=0,I=!1;for(;t!==r;){if(A===t&&(I=!0),!t.deleted){let a=t.content;switch(a.constructor){case Me:{let{key:c,value:u}=a,l=i.get(c)||null;(o.get(c)!==a||l===u)&&(t.delete(e),s++,!I&&(n.get(c)||null)===u&&l!==u&&(l===null?n.delete(c):n.set(c,l))),!I&&!t.deleted&&lr(n,a);break}}}t=t.right}return s},Lk=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let A=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===Me){let i=t.content.key;A.has(i)?t.delete(e):A.add(i)}t=t.left}},Ok=e=>{let t=0;return Be(e.doc,A=>{let i=e._start,n=e._start,r=It(),o=bI(r);for(;n;){if(n.deleted===!1)switch(n.content.constructor){case Me:lr(o,n.content);break;default:t+=Wp(A,i,n,r,o),r=bI(o),i=n;break}n=n.right}}),t},bk=e=>{let t=new Set,A=e.doc;for(let[i,n]of e.afterState.entries()){let r=e.beforeState.get(i)||0;n!==r&&Mp(e,A.store.clients.get(i),r,n,o=>{!o.deleted&&o.content.constructor===Me&&o.constructor!==ht&&t.add(o.parent)})}Be(A,i=>{mp(e,e.deleteSet,n=>{if(n instanceof ht||!n.parent._hasFormatting||t.has(n.parent))return;let r=n.parent;n.content.constructor===Me?t.add(r):Lk(i,n)});for(let n of t)Ok(n)})},Ep=(e,t,A)=>{let i=A,n=bI(t.currentAttributes),r=t.right;for(;A>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case VA:case on:case YA:A{n===null?this.childListChanged=!0:this.keysChanged.add(n)})}get changes(){if(this._changes===null){let 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){let t=this.target.doc,A=[];Be(t,i=>{let n=new Map,r=new Map,o=this.target._start,s=null,I={},a="",c=0,u=0,l=()=>{if(s!==null){let g=null;switch(s){case"delete":u>0&&(g={delete:u}),u=0;break;case"insert":(typeof a=="object"||a.length>0)&&(g={insert:a},n.size>0&&(g.attributes={},n.forEach((B,p)=>{B!==null&&(g.attributes[p]=B)}))),a="";break;case"retain":c>0&&(g={retain:c},Zh(I)||(g.attributes=Th({},I))),c=0;break}g&&A.push(g),s=null}};for(;o!==null;){switch(o.content.constructor){case VA:case on:this.adds(o)?this.deletes(o)||(l(),s="insert",a=o.content.getContent()[0],l()):this.deletes(o)?(s!=="delete"&&(l(),s="delete"),u+=1):o.deleted||(s!=="retain"&&(l(),s="retain"),c+=1);break;case YA:this.adds(o)?this.deletes(o)||(s!=="insert"&&(l(),s="insert"),a+=o.content.str):this.deletes(o)?(s!=="delete"&&(l(),s="delete"),u+=o.length):o.deleted||(s!=="retain"&&(l(),s="retain"),c+=o.length);break;case Me:{let{key:g,value:B}=o.content;if(this.adds(o)){if(!this.deletes(o)){let p=n.get(g)||null;mi(p,B)?B!==null&&o.delete(i):(s==="retain"&&l(),mi(B,r.get(g)||null)?delete I[g]:I[g]=B)}}else if(this.deletes(o)){r.set(g,B);let p=n.get(g)||null;mi(p,B)||(s==="retain"&&l(),I[g]=p)}else if(!o.deleted){r.set(g,B);let p=I[g];p!==void 0&&(mi(p,B)?p!==null&&o.delete(i):(s==="retain"&&l(),B===null?delete I[g]:I[g]=B))}o.deleted||(s==="insert"&&l(),lr(n,o.content));break}}o=o.right}for(l();A.length>0;){let g=A[A.length-1];if(g.retain!==void 0&&g.attributes===void 0)A.pop();else break}}),this._delta=A}return this._delta}},_o=class e extends He{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this._length}_integrate(t,A){super._integrate(t,A);try{this._pending.forEach(i=>i())}catch(i){console.error(i)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(t,A){super._callObserver(t,A);let i=new pu(this,t,A);pa(this,t,i),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){let t="",A=this._start;for(;A!==null;)!A.deleted&&A.countable&&A.content.constructor===YA&&(t+=A.content.str),A=A.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:A=!0}={}){this.doc!==null?Be(this.doc,i=>{let n=new Po(null,this._start,0,new Map);for(let r=0;r0)&&cu(i,this,n,s,o.attributes||{})}else o.retain!==void 0?pp(i,this,n,o.retain,o.attributes||{}):o.delete!==void 0&&Ep(i,n,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,A,i){let n=[],r=new Map,o=this.doc,s="",I=this._start;function a(){if(s.length>0){let u={},l=!1;r.forEach((B,p)=>{l=!0,u[p]=B});let g={insert:s};l&&(g.attributes=u),n.push(g),s=""}}let c=()=>{for(;I!==null;){if(sr(I,t)||A!==void 0&&sr(I,A))switch(I.content.constructor){case YA:{let u=r.get("ychange");t!==void 0&&!sr(I,t)?(u===void 0||u.user!==I.id.client||u.type!=="removed")&&(a(),r.set("ychange",i?i("removed",I.id):{type:"removed"})):A!==void 0&&!sr(I,A)?(u===void 0||u.user!==I.id.client||u.type!=="added")&&(a(),r.set("ychange",i?i("added",I.id):{type:"added"})):u!==void 0&&(a(),r.delete("ychange")),s+=I.content.str;break}case VA:case on:{a();let u={insert:I.content.getContent()[0]};if(r.size>0){let l={};u.attributes=l,r.forEach((g,B)=>{l[B]=g})}n.push(u);break}case Me:sr(I,t)&&(a(),lr(r,I.content));break}I=I.right}a()};return t||A?Be(o,u=>{t&&Bu(u,t),A&&Bu(u,A),c()},"cleanup"):c(),n}insert(t,A,i){if(A.length<=0)return;let n=this.doc;n!==null?Be(n,r=>{let o=Aa(r,this,t);i||(i={},o.currentAttributes.forEach((s,I)=>{i[I]=s})),cu(r,this,o,A,i)}):this._pending.push(()=>this.insert(t,A,i))}insertEmbed(t,A,i={}){let n=this.doc;n!==null?Be(n,r=>{let o=Aa(r,this,t);cu(r,this,o,A,i)}):this._pending.push(()=>this.insertEmbed(t,A,i))}delete(t,A){if(A===0)return;let i=this.doc;i!==null?Be(i,n=>{Ep(n,Aa(n,this,t),A)}):this._pending.push(()=>this.delete(t,A))}format(t,A,i){if(A===0)return;let n=this.doc;n!==null?Be(n,r=>{let o=Aa(r,this,t);o.right!==null&&pp(r,this,o,A,i)}):this._pending.push(()=>this.format(t,A,i))}removeAttribute(t){this.doc!==null?Be(this.doc,A=>{ua(A,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,A){this.doc!==null?Be(this.doc,i=>{xu(i,this,t,A)}):this._pending.push(()=>this.setAttribute(t,A))}getAttribute(t){return Gu(this,t)}getAttributes(){return Pp(this)}_write(t){t.writeTypeRef(oS)}},Yk=e=>new _o,Ro=class{constructor(t,A=()=>!0){this._filter=A,this._root=t,this._currentNode=t._start,this._firstCall=!0}[Symbol.iterator](){return this}next(){let t=this._currentNode,A=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(A)))do if(A=t.content.type,!t.deleted&&(A.constructor===fa||A.constructor===ar)&&A._start!==null)t=A._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})}},ar=class e extends He{constructor(){super(),this._prelimContent=[]}get firstChild(){let t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,A){super._integrate(t,A),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(A=>A instanceof He?A.clone():A)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Ro(this,t)}querySelector(t){t=t.toUpperCase();let i=new Ro(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t).next();return i.done?null:i.value}querySelectorAll(t){return t=t.toUpperCase(),fA(new Ro(this,A=>A.nodeName&&A.nodeName.toUpperCase()===t))}_callObserver(t,A){pa(this,t,new Eu(this,A,t))}toString(){return Op(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,A={},i){let n=t.createDocumentFragment();return i!==void 0&&i._createAssociation(n,this),Vo(this,r=>{n.insertBefore(r.toDOM(t,A,i),null)}),n}insert(t,A){this.doc!==null?Be(this.doc,i=>{Vp(i,this,t,A)}):this._prelimContent.splice(t,0,...A)}insertAfter(t,A){if(this.doc!==null)Be(this.doc,i=>{let n=t&&t instanceof He?t._item:t;la(i,this,n,A)});else{let i=this._prelimContent,n=t===null?0:i.findIndex(r=>r===t)+1;if(n===0&&t!==null)throw dA("Reference item not found");i.splice(n,0,...A)}}delete(t,A=1){this.doc!==null?Be(this.doc,i=>{zp(i,this,t,A)}):this._prelimContent.splice(t,A)}toArray(){return Lp(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return bp(this,t)}slice(t=0,A=this.length){return Kp(this,t,A)}forEach(t){Vo(this,t)}_write(t){t.writeTypeRef(IS)}},Vk=e=>new ar,fa=class e extends ar{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,A){super._integrate(t,A),this._prelimAttrs.forEach((i,n)=>{this.setAttribute(n,i)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName),A=this.getAttributes();return Xh(A,(i,n)=>{typeof i=="string"&&t.setAttribute(n,i)}),t.insert(0,this.toArray().map(i=>i instanceof He?i.clone():i)),t}toString(){let t=this.getAttributes(),A=[],i=[];for(let s in t)i.push(s);i.sort();let n=i.length;for(let s=0;s0?" "+A.join(" "):"";return`<${r}${o}>${super.toString()}`}removeAttribute(t){this.doc!==null?Be(this.doc,A=>{ua(A,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,A){this.doc!==null?Be(this.doc,i=>{xu(i,this,t,A)}):this._prelimAttrs.set(t,A)}getAttribute(t){return Gu(this,t)}hasAttribute(t){return _p(this,t)}getAttributes(t){return t?qk(this,t):Pp(this)}toDOM(t=document,A={},i){let n=t.createElement(this.nodeName),r=this.getAttributes();for(let o in r){let s=r[o];typeof s=="string"&&n.setAttribute(o,s)}return Vo(this,o=>{n.appendChild(o.toDOM(t,A,i))}),i!==void 0&&i._createAssociation(n,this),n}_write(t){t.writeTypeRef(sS),t.writeKey(this.nodeName)}},zk=e=>new fa(e.readKey()),Eu=class extends Ir{constructor(t,A,i){super(t,i),this.childListChanged=!1,this.attributesChanged=new Set,A.forEach(n=>{n===null?this.childListChanged=!0:this.attributesChanged.add(n)})}},mu=class e extends zo{constructor(t){super(),this.hookName=t}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((A,i)=>{t.set(i,A)}),t}toDOM(t=document,A={},i){let n=A[this.hookName],r;return n!==void 0?r=n.createDom(this):r=document.createElement(this.hookName),r.setAttribute("data-yjs-hook",this.hookName),i!==void 0&&i._createAssociation(r,this),r}_write(t){t.writeTypeRef(aS),t.writeKey(this.hookName)}},Pk=e=>new mu(e.readKey()),yu=class e extends _o{get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(t=document,A,i){let n=t.createTextNode(this.toString());return i!==void 0&&i._createAssociation(n,this),n}toString(){return this.toDelta().map(t=>{let A=[];for(let n in t.attributes){let r=[];for(let o in t.attributes[n])r.push({key:o,value:t.attributes[n][o]});r.sort((o,s)=>o.keyn.nodeName=0;n--)i+=``;return i}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(cS)}},_k=e=>new yu,To=class{constructor(t,A){this.id=t,this.length=A}get deleted(){throw tA()}mergeWith(t){return!1}write(t,A,i){throw tA()}integrate(t,A){throw tA()}},Tk=0,ht=class extends To{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,A){A>0&&(this.id.clock+=A,this.length-=A),Hp(t.doc.store,this)}write(t,A){t.writeInfo(Tk),t.writeLen(this.length-A)}getMissing(t,A){return null}},Xo=class e{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(t){throw tA()}mergeWith(t){return!1}integrate(t,A){}delete(t){}gc(t){}write(t,A){t.writeBuf(this.content)}getRef(){return 3}},Xk=e=>new Xo(e.readBuf()),da=class e{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let A=new e(this.len-t);return this.len=t,A}mergeWith(t){return this.len+=t.len,!0}integrate(t,A){ra(t.deleteSet,A.id.client,A.id.clock,this.len),A.markDeleted()}delete(t){}gc(t){}write(t,A){t.writeLen(this.len-A)}getRef(){return 1}},Zk=e=>new da(e.readLen()),jp=(e,t)=>new Lo({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),Zo=class e{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;let A={};this.opts=A,t.gc||(A.gc=!1),t.autoLoad&&(A.autoLoad=!0),t.meta!==null&&(A.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(jp(this.doc.guid,this.opts))}splice(t){throw tA()}mergeWith(t){return!1}integrate(t,A){this.doc._item=A,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,A){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}},Wk=e=>new Zo(jp(e.readString(),e.readAny())),on=class e{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(t){throw tA()}mergeWith(t){return!1}integrate(t,A){}delete(t){}gc(t){}write(t,A){t.writeJSON(this.embed)}getRef(){return 5}},jk=e=>new on(e.readJSON()),Me=class e{constructor(t,A){this.key=t,this.value=A}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(t){throw tA()}mergeWith(t){return!1}integrate(t,A){let i=A.parent;i._searchMarker=null,i._hasFormatting=!0}delete(t){}gc(t){}write(t,A){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}},$k=e=>new Me(e.readKey(),e.readJSON()),wu=class e{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let A=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),A}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,A){}delete(t){}gc(t){}write(t,A){let i=this.arr.length;t.writeLen(i-A);for(let n=A;n{let t=e.readLen(),A=[];for(let i=0;i{let t=e.readLen(),A=[];for(let i=0;i=55296&&i<=56319&&(this.str=this.str.slice(0,t-1)+"\uFFFD",A.str="\uFFFD"+A.str.slice(1)),A}mergeWith(t){return this.str+=t.str,!0}integrate(t,A){}delete(t){}gc(t){}write(t,A){t.writeString(A===0?this.str:this.str.slice(A))}getRef(){return 4}},AS=e=>new YA(e.readString()),iS=[Rk,Kk,Yk,zk,Vk,Pk,_k],nS=0,rS=1,oS=2,sS=3,IS=4,aS=5,cS=6,VA=class e{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(t){throw tA()}mergeWith(t){return!1}integrate(t,A){this.type._integrate(t.doc,A)}delete(t){let A=this.type._start;for(;A!==null;)A.deleted?A.id.clock<(t.beforeState.get(A.id.client)||0)&&t._mergeStructs.push(A):A.delete(t),A=A.right;this.type._map.forEach(i=>{i.deleted?i.id.clock<(t.beforeState.get(i.id.client)||0)&&t._mergeStructs.push(i):i.delete(t)}),t.changed.delete(this.type)}gc(t){let A=this.type._start;for(;A!==null;)A.gc(t,!0),A=A.right;this.type._start=null,this.type._map.forEach(i=>{for(;i!==null;)i.gc(t,!0),i=i.left}),this.type._map=new Map}write(t,A){this.type._write(t)}getRef(){return 7}},gS=e=>new VA(iS[e.readTypeRef()](e));var Qa=(e,t,A)=>{let{client:i,clock:n}=t.id,r=new Le(ee(i,n+A),t,ee(i,n+A-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(A));return t.deleted&&r.markDeleted(),t.keep&&(r.keep=!0),t.redone!==null&&(r.redone=ee(t.redone.client,t.redone.clock+A)),t.right=r,r.right!==null&&(r.right.left=r),e._mergeStructs.push(r),r.parentSub!==null&&r.right===null&&r.parent._map.set(r.parentSub,r),t.length=A,r};var Le=class e extends To{constructor(t,A,i,n,r,o,s,I){super(t,I.getLength()),this.origin=i,this.left=A,this.right=n,this.rightOrigin=r,this.parent=o,this.parentSub=s,this.redone=null,this.content=I,this.info=this.content.isCountable()?2:0}set marker(t){(this.info&8)>0!==t&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(t){this.keep!==t&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(t){this.deleted!==t&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,A){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=Ke(A,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=Ke(A,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===yi&&this.id.client!==this.parent.client&&this.parent.clock>=Ke(A,this.parent.client))return this.parent.client;if(this.origin&&(this.left=fp(t,A,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Fi(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===ht||this.right&&this.right.constructor===ht)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===yi){let i=au(A,this.parent);i.constructor===ht?this.parent=null:this.parent=i.content.type}return null}integrate(t,A){if(A>0&&(this.id.clock+=A,this.left=fp(t,t.doc.store,ee(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(A),this.length-=A),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let i=this.left,n;if(i!==null)n=i.right;else if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start;let r=new Set,o=new Set;for(;n!==null&&n!==this.right;){if(o.add(n),r.add(n),ea(this.origin,n.origin)){if(n.id.client{i.p===t&&(i.p=this,!this.deleted&&this.countable&&(i.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){let A=this.parent;this.countable&&this.parentSub===null&&(A._length-=this.length),this.markDeleted(),ra(t.deleteSet,this.id.client,this.id.clock,this.length),Qp(t,A,this.parentSub),this.content.delete(t)}}gc(t,A){if(!this.deleted)throw AA();this.content.gc(t),A?yk(t,this,new ht(this.id,this.length)):this.content=new da(this.length)}write(t,A){let i=A>0?ee(this.id.client,this.id.clock+A-1):this.origin,n=this.rightOrigin,r=this.parentSub,o=this.content.getRef()&31|(i===null?0:128)|(n===null?0:64)|(r===null?0:32);if(t.writeInfo(o),i!==null&&t.writeLeftID(i),n!==null&&t.writeRightID(n),i===null&&n===null){let s=this.parent;if(s._item!==void 0){let I=s._item;if(I===null){let a=pk(s);t.writeParentInfo(!0),t.writeString(a)}else t.writeParentInfo(!1),t.writeLeftID(I.id)}else s.constructor===String?(t.writeParentInfo(!0),t.writeString(s)):s.constructor===yi?(t.writeParentInfo(!1),t.writeLeftID(s)):AA();r!==null&&t.writeString(r)}this.content.write(t,A)}},$p=(e,t)=>lS[t&31](e),lS=[()=>{AA()},Zk,eS,Xk,AS,jk,$k,gS,tS,Wk,()=>{AA()}],uS=10,pt=class extends To{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,A){AA()}write(t,A){t.writeInfo(uS),Z(t.restEncoder,this.length-A)}getMissing(t,A){return null}},eE=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},tE="__ $YJS$ __";eE[tE]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");eE[tE]=!0;var Ea={proxies:new WeakMap,traps:new WeakMap},AE=(e,t,A)=>e.get(t)||e.set(t,new A).get(t),iE=e=>e.join(),nE=(e,t,A,i,n)=>{AE(AE(Ea.traps,e,WeakMap),t,Map).set(iE(A),i),Ea.proxies.set(i,n)},Hu=(e,t,A)=>{var i,n;return Ea.proxies.get((n=(i=Ea.traps.get(e))===null||i===void 0?void 0:i.get(t))===null||n===void 0?void 0:n.get(iE(A)))};var fS=Symbol("default"),dS=Object.keys(Object.getOwnPropertyDescriptors(Reflect)),QS=["get","has","set","defineProperty","deleteProperty","getOwnPropertyDescriptor"],CS=(e,t)=>{let A,i,n,r,o,s,I,a;switch(e){case"get":[A,i,r]=t;break;case"set":[A,i,n,r]=t;break;case"deleteProperty":case"defineProperty":[A,s]=t;break;case"has":case"getOwnPropertyDescriptor":[A,i]=t;break;case"apply":[A,I,o]=t;break;case"construct":[A,o]=t;break;case"setPrototypeOf":[A,a]=t;break;default:[A]=t}return{target:A,name:i,receiver:r,val:n,args:o,descriptor:s,thisValue:I,prototype:a}},hS=(e,t)=>{let{trapName:A,handler:i,traps:n,root:r,path:o}=e,{target:s,name:I,val:a,receiver:c,args:u,descriptor:l,thisValue:g,prototype:B}=CS(A,t),p=QS.includes(A)?I:void 0;return{parameters:t,target:s,name:I,val:a,args:u,descriptor:l,receiver:c,thisValue:g,prototype:B,trapName:A,traps:n,path:o,handler:i,key:p,newValue:A==="set"?a:void 0,root:r,get proxy(){return Hu(r,s,o)},get value(){return p&&s[p]},DEFAULT:fS,PROXY:rE.bind({root:r,handler:i,path:[...o,p]})}},pS=function(...e){let{trapName:t,handler:A}=this,i=hS(this,e),{PROXY:n,DEFAULT:r}=i,o=A(i);return o===n?n(i.value):o===r?Reflect[t](...e):o},ES=(e,t,A)=>dS.reduce((i,n)=>(i[n]=pS.bind({trapName:n,handler:e,traps:i,root:t,path:A}),i),{}),mS=e=>{if(e===null||typeof e!="object"&&typeof e!="function")throw new TypeError("Deep proxy could be applied to objects and functions only")},yS=({DEFAULT:e})=>e,rE=function(e,t,A,i){mS(e);let n=Object.assign({},this),r=t||n.handler||yS,o=A||n.path||[],s=n.root||i||e,I=Hu(s,e,o);if(I)return I;let a=ES(r,s,o),c=new Proxy(e,a);return nE(s,e,o,a,c),c},oE=class{constructor(e,t,A,i){return rE(e,t,A,i)}};function $o(e,t,A,i){function n(r){return r instanceof A?r:new A(function(o){o(r)})}return new(A||(A=Promise))(function(r,o){function s(c){try{a(i.next(c))}catch(u){o(u)}}function I(c){try{a(i.throw(c))}catch(u){o(u)}}function a(c){c.done?r(c.value):n(c.value).then(s,I)}a((i=i.apply(e,t||[])).next())})}var he=class{constructor(){this.mutex=Promise.resolve()}lock(){let t=()=>{};return this.mutex=this.mutex.then(()=>new Promise(t)),new Promise(A=>{t=A})}dispatch(t){return $o(this,void 0,void 0,function*(){let A=yield this.lock();try{return yield Promise.resolve(t())}finally{A()}})}},Mu;function wS(){return typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global}var qu=wS(),vu=(Mu=qu.Buffer)!==null&&Mu!==void 0?Mu:null,FS=qu.TextEncoder?new qu.TextEncoder:null;function uE(e,t){return(e&15)+(e>>6|e>>3&8)<<4|(t&15)+(t>>6|t>>3&8)}function DS(e,t){let A=t.length>>1;for(let i=0;i>>4;e[i++]=r>9?r+sE:r+IE,r=t[n]&15,e[i++]=r>9?r+sE:r+IE}return String.fromCharCode.apply(null,e)}var cE=vu!==null?e=>{if(typeof e=="string"){let t=vu.from(e,"utf8");return new Uint8Array(t.buffer,t.byteOffset,t.length)}if(vu.isBuffer(e))return new Uint8Array(e.buffer,e.byteOffset,e.length);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Invalid data type!")}:e=>{if(typeof e=="string")return FS.encode(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Invalid data type!")},gE="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",jo=new Uint8Array(256);for(let e=0;e>4,n+=1,i[n]=(s&15)<<4|I>>2,n+=1,i[n]=(I&3)<<6|a&63,n+=1}return i}var ma=16*1024,Wo=4,NS=new he,Ju=new Map;function xS(e,t){return $o(this,void 0,void 0,function*(){let A=null,i=null,n=!1;if(typeof WebAssembly>"u")throw new Error("WebAssembly is not supported in this environment!");let r=(w,D=0)=>{i.set(w,D)},o=()=>i,s=()=>A.exports,I=w=>{A.exports.Hash_SetMemorySize(w);let D=A.exports.Hash_GetBuffer(),S=A.exports.memory.buffer;i=new Uint8Array(S,D,w)},a=()=>new DataView(A.exports.memory.buffer).getUint32(A.exports.STATE_SIZE,!0),c=NS.dispatch(()=>$o(this,void 0,void 0,function*(){if(!Ju.has(e.name)){let D=US(e.data),S=WebAssembly.compile(D);Ju.set(e.name,S)}let w=yield Ju.get(e.name);A=yield WebAssembly.instantiate(w,{})})),u=()=>$o(this,void 0,void 0,function*(){A||(yield c);let w=A.exports.Hash_GetBuffer(),D=A.exports.memory.buffer;i=new Uint8Array(D,w,ma)}),l=(w=null)=>{n=!0,A.exports.Hash_Init(w)},g=w=>{let D=0;for(;D{if(!n)throw new Error("update() called before init()");let D=cE(w);g(D)},p=new Uint8Array(t*2),U=(w,D=null)=>{if(!n)throw new Error("digest() called before init()");return n=!1,A.exports.Hash_Final(D),w==="binary"?i.slice(0,t):aE(p,i,t)},d=()=>{if(!n)throw new Error("save() can only be called after init() and before digest()");let w=A.exports.Hash_GetState(),D=a(),S=A.exports.memory.buffer,K=new Uint8Array(S,w,D),q=new Uint8Array(Wo+D);return DS(q,e.hash),q.set(K,Wo),q},f=w=>{if(!(w instanceof Uint8Array))throw new Error("load() expects an Uint8Array generated by save()");let D=A.exports.Hash_GetState(),S=a(),K=Wo+S,q=A.exports.memory.buffer;if(w.length!==K)throw new Error(`Bad state length (expected ${K} bytes, got ${w.length})`);if(!kS(e.hash,w.subarray(0,Wo)))throw new Error("This state was written by an incompatible hash implementation");let X=w.subarray(Wo);new Uint8Array(q,D,S).set(X),n=!0},Q=w=>typeof w=="string"?w.length!0;break;case"blake2b":case"blake2s":y=(w,D)=>D<=512&&Q(w);break;case"blake3":y=(w,D)=>D===0&&Q(w);break;case"xxhash64":case"xxhash3":case"xxhash128":y=()=>!1;break}let F=(w,D=null,S=null)=>{if(!y(w,D))return l(D),B(w),U("hex",S);let K=cE(w);return i.set(K),A.exports.Hash_Calculate(K.length,D,S),aE(p,i,t)};return yield u(),{getMemory:o,writeMemory:r,getExports:s,setMemorySize:I,init:l,update:B,digest:U,save:d,load:f,calculate:F,hashLength:t}})}function GS(e,t,A){return $o(this,void 0,void 0,function*(){let i=yield e.lock(),n=yield xS(t,A);return i(),n})}var aG=new he;var cG=new he;var gG=new DataView(new ArrayBuffer(4));var lG=new he;var uG=new he;var BG=new he;var fG=new he;var dG=new he;var QG=new he;var CG=new he;var hG=new he;var pG=new he;var EG=new he;var mG=new he;var yG=new he;var wG=new he;var HS="xxhash32",MS="AGFzbQEAAAABEQRgAAF/YAF/AGAAAGACf38AAwcGAAEBAgADBQQBAQICBg4CfwFBsIkFC38AQYAICwdwCAZtZW1vcnkCAA5IYXNoX0dldEJ1ZmZlcgAACUhhc2hfSW5pdAABC0hhc2hfVXBkYXRlAAIKSGFzaF9GaW5hbAADDUhhc2hfR2V0U3RhdGUABA5IYXNoX0NhbGN1bGF0ZQAFClNUQVRFX1NJWkUDAQqxEAYFAEGACQtNAEEAQgA3A6iJAUEAIAA2AoiJAUEAIABBz4yijgZqNgKMiQFBACAAQfeUr694ajYChIkBQQAgAEGoiI2hAmo2AoCJAUEAQQA2AqCJAQu4CAEHfwJAIABFDQBBAEEAKQOoiQEgAK18NwOoiQECQEEAKAKgiQEiASAAakEPSw0AAkACQCAAQQNxIgINAEGACSEDIAAhBAwBCyAAQXxxIQRBgAkhAwNAQQBBACgCoIkBIgVBAWo2AqCJASAFQZCJAWogAy0AADoAACADQQFqIQMgAkF/aiICDQALCyAAQQRJDQEDQEEAQQAoAqCJASICQQFqNgKgiQEgAkGQiQFqIAMtAAA6AAAgA0EBai0AACECQQBBACgCoIkBIgVBAWo2AqCJASAFQZCJAWogAjoAACADQQJqLQAAIQJBAEEAKAKgiQEiBUEBajYCoIkBIAVBkIkBaiACOgAAIANBA2otAAAhAkEAQQAoAqCJASIFQQFqNgKgiQEgBUGQiQFqIAI6AAAgA0EEaiEDIARBfGoiBA0ADAILCyAAQfAIaiEGAkACQCABDQBBACgCjIkBIQJBACgCiIkBIQVBACgChIkBIQRBACgCgIkBIQFBgAkhAwwBC0GACSEDAkAgAUEPSw0AQYAJIQMCQAJAQQAgAWtBA3EiBA0AIAEhBQwBCyABIQIDQEEAIAJBAWoiBTYCoIkBIAJBkIkBaiADLQAAOgAAIANBAWohAyAFIQIgBEF/aiIEDQALCyABQXNqQQNJDQBBACEEA0AgAyAEaiIBLQAAIQdBACAFIARqIgJBAWo2AqCJASACQZCJAWogBzoAACABQQFqLQAAIQdBACACQQJqNgKgiQEgAkGRiQFqIAc6AAAgAUECai0AACEHQQAgAkEDajYCoIkBIAJBkokBaiAHOgAAIAFBA2otAAAhAUEAIAJBBGo2AqCJASACQZOJAWogAToAACAFIARBBGoiBGpBEEcNAAsgAyAEaiEDC0EAQQAoApCJAUH3lK+veGxBACgCgIkBakENd0Gx893xeWwiATYCgIkBQQBBACgClIkBQfeUr694bEEAKAKEiQFqQQ13QbHz3fF5bCIENgKEiQFBAEEAKAKYiQFB95Svr3hsQQAoAoiJAWpBDXdBsfPd8XlsIgU2AoiJAUEAQQAoApyJAUH3lK+veGxBACgCjIkBakENd0Gx893xeWwiAjYCjIkBCyAAQYAJaiEAAkAgAyAGSw0AA0AgAygCAEH3lK+veGwgAWpBDXdBsfPd8XlsIQEgA0EMaigCAEH3lK+veGwgAmpBDXdBsfPd8XlsIQIgA0EIaigCAEH3lK+veGwgBWpBDXdBsfPd8XlsIQUgA0EEaigCAEH3lK+veGwgBGpBDXdBsfPd8XlsIQQgA0EQaiIDIAZNDQALC0EAIAI2AoyJAUEAIAU2AoiJAUEAIAQ2AoSJAUEAIAE2AoCJAUEAIAAgA2s2AqCJASAAIANGDQBBACECA0AgAkGQiQFqIAMgAmotAAA6AAAgAkEBaiICQQAoAqCJAUkNAAsLC6QDAgF+Bn9BACkDqIkBIgCnIQECQAJAIABCEFQNAEEAKAKEiQFBB3dBACgCgIkBQQF3akEAKAKIiQFBDHdqQQAoAoyJAUESd2ohAgwBC0EAKAKIiQFBsc/ZsgFqIQILIAIgAWohAkGQiQEhAwJAQQAoAqCJASIEQZCJAWoiBUGUiQFJDQBBkIkBIQEDQCABKAIAQb3cypV8bCACakERd0Gv1tO+AmwhAiABQQhqIQYgAUEEaiIDIQEgBiAFTQ0ACwsCQCADIAVGDQAgBEGPiQFqIQYCQAJAIAQgA2tBAXENACADIQEMAQsgA0EBaiEBIAMtAABBsc/ZsgFsIAJqQQt3QbHz3fF5bCECCyAGIANGDQADQCABQQFqLQAAQbHP2bIBbCABLQAAQbHP2bIBbCACakELd0Gx893xeWxqQQt3QbHz3fF5bCECIAFBAmoiASAFRw0ACwtBACACQQ92IAJzQfeUr694bCIBQQ12IAFzQb3cypV8bCIBQRB2IAFzIgJBGHQgAkGA/gNxQQh0ciABQQh2QYD+A3EgAUEYdnJyrTcDgAkLBgBBgIkBC/MDAgF+BH9BAEIANwOoiQFBACABNgKIiQFBACABQc+Moo4GajYCjIkBQQAgAUH3lK+veGo2AoSJAUEAIAFBqIiNoQJqNgKAiQFBAEEANgKgiQEgABACQQApA6iJASICpyEBAkACQCACQhBUDQBBACgChIkBQQd3QQAoAoCJAUEBd2pBACgCiIkBQQx3akEAKAKMiQFBEndqIQAMAQtBACgCiIkBQbHP2bIBaiEACyAAIAFqIQBBkIkBIQMCQEEAKAKgiQEiBEGQiQFqIgVBlIkBSQ0AQZCJASEBA0AgASgCAEG93MqVfGwgAGpBEXdBr9bTvgJsIQAgAUEIaiEGIAFBBGoiAyEBIAYgBU0NAAsLAkAgAyAFRg0AIARBj4kBaiEGAkACQCAEIANrQQFxDQAgAyEBDAELIANBAWohASADLQAAQbHP2bIBbCAAakELd0Gx893xeWwhAAsgBiADRg0AA0AgAUEBai0AAEGxz9myAWwgAS0AAEGxz9myAWwgAGpBC3dBsfPd8XlsakELd0Gx893xeWwhACABQQJqIgEgBUcNAAsLQQAgAEEPdiAAc0H3lK+veGwiAUENdiABc0G93MqVfGwiAUEQdiABcyIAQRh0IABBgP4DcUEIdHIgAUEIdkGA/gNxIAFBGHZycq03A4AJCwsLAQBBgAgLBDAAAAA=",vS="9e3a00cd",JS={name:HS,data:MS,hash:vS},qS=new he,ya=null;function lE(e){return!Number.isInteger(e)||e<0||e>4294967295?new Error("Seed must be a valid 32-bit long unsigned integer."):null}function wa(e,t=0){if(lE(t))return Promise.reject(lE(t));if(ya===null)return GS(qS,JS,4).then(A=>(ya=A,ya.calculate(e,t)));try{let A=ya.calculate(e,t);return Promise.resolve(A)}catch(A){return Promise.reject(A)}}var FG=new he;var DG=new ArrayBuffer(8);var kG=new he;var SG=new ArrayBuffer(8);var UG=new he;var NG=new ArrayBuffer(8);var xG=new he;var GG=new he;var HG=new he;function Ku(e){return new Promise((t,A)=>{e.oncomplete=e.onsuccess=()=>t(e.result),e.onabort=e.onerror=()=>A(e.error)})}function sn(e,t){let A=indexedDB.open(e);A.onupgradeneeded=()=>A.result.createObjectStore(t);let i=Ku(A);return(n,r)=>i.then(o=>r(o.transaction(t,n).objectStore(t)))}var Ru;function BE(){return Ru||(Ru=sn("keyval-store","keyval")),Ru}function EA(e,t=BE()){return t("readonly",A=>Ku(A.get(e)))}function mA(e,t,A=BE()){return A("readwrite",i=>(i.put(t,e),Ku(i.transaction)))}var Ou;try{Ou=new TextDecoder}catch{}var G,Ot,C=0;var DE=[],bu=DE,Yu=0,Ee={},te,Di,Lt=0,yA=0,be,zA,Et=[],j,fE={useRecords:!1,mapsAsObjects:!0},es=class{},zu=new es;zu.name="MessagePack 0xC1";var ki=!1,kE=2,dE,QE,CE;try{new Function("")}catch{kE=1/0}var an=class e{constructor(t){t&&(t.useRecords===!1&&t.mapsAsObjects===void 0&&(t.mapsAsObjects=!0),t.sequential&&t.trusted!==!1&&(t.trusted=!0,!t.structures&&t.useRecords!=!1&&(t.structures=[],t.maxSharedStructures||(t.maxSharedStructures=0))),t.structures?t.structures.sharedLength=t.structures.length:t.getStructures&&((t.structures=[]).uninitialized=!0,t.structures.sharedLength=0),t.int64AsNumber&&(t.int64AsType="number")),Object.assign(this,t)}unpack(t,A){if(G)return xE(()=>(Da(),this?this.unpack(t,A):e.prototype.unpack.call(fE,t,A)));!t.buffer&&t.constructor===ArrayBuffer&&(t=typeof Buffer<"u"?Buffer.from(t):new Uint8Array(t)),typeof A=="object"?(Ot=A.end||t.length,C=A.start||0):(C=0,Ot=A>-1?A:t.length),Yu=0,yA=0,Di=null,bu=DE,be=null,G=t;try{j=t.dataView||(t.dataView=new DataView(t.buffer,t.byteOffset,t.byteLength))}catch(i){throw G=null,t instanceof Uint8Array?i:new Error("Source must be a Uint8Array or Buffer but was a "+(t&&typeof t=="object"?t.constructor.name:typeof t))}if(this instanceof e){if(Ee=this,this.structures)return te=this.structures,Fa(A);(!te||te.length>0)&&(te=[])}else Ee=fE,(!te||te.length>0)&&(te=[]);return Fa(A)}unpackMultiple(t,A){let i,n=0;try{ki=!0;let r=t.length,o=this?this.unpack(t,r):Sa.unpack(t,r);if(A){if(A(o,n,C)===!1)return;for(;Ci.slice(0)));for(let i=0,n=t.length;i=32&&(r.highByte=i-32>>5))}t.sharedLength=t.length;for(let i in A||[])if(i>=0){let n=t[i],r=A[i];r&&(n&&((t.restoreStructures||(t.restoreStructures=[]))[i]=n),t[i]=r)}return this.structures=t}decode(t,A){return this.unpack(t,A)}};function Fa(e){try{if(!Ee.trusted&&!ki){let A=te.sharedLength||0;A=32&&dE?(t=dE(G,C,Ot,Ee),G=null,!(e&&e.lazy)&&t&&(t=t.toJSON()),C=Ot):t=Se(),be&&(C=be.postBundlePosition,be=null),ki&&(te.restoreStructures=null),C==Ot)te&&te.restoreStructures&&hE(),te=null,G=null,zA&&(zA=null);else{if(C>Ot)throw new Error("Unexpected end of MessagePack data");if(!ki){let A;try{A=JSON.stringify(t,(i,n)=>typeof n=="bigint"?`${n}n`:n).slice(0,100)}catch(i){A="(JSON view not available "+i+")"}throw new Error("Data read, but end of buffer not reached "+A)}}return t}catch(t){throw te&&te.restoreStructures&&hE(),Da(),(t instanceof RangeError||t.message.startsWith("Unexpected end of buffer")||C>Ot)&&(t.incomplete=!0),t}}function hE(){for(let e in te.restoreStructures)te[e]=te.restoreStructures[e];te.restoreStructures=null}function Se(){let e=G[C++];if(e<160)if(e<128){if(e<64)return e;{let t=te[e&63]||Ee.getStructures&&SE()[e&63];return t?(t.read||(t.read=Pu(t,e&63)),t.read()):e}}else if(e<144)if(e-=128,Ee.mapsAsObjects){let t={};for(let A=0;A=C)return Di.slice(C-Lt,(C+=t)-Lt);if(yA==0&&Ot<140){let A=t<16?_u(t):UE(t);if(A!=null)return A}return Vu(t)}else{let t;switch(e){case 192:return null;case 193:return be?(t=Se(),t>0?be[1].slice(be.position1,be.position1+=t):be[0].slice(be.position0,be.position0-=t)):zu;case 194:return!1;case 195:return!0;case 196:if(t=G[C++],t===void 0)throw new Error("Unexpected end of buffer");return Lu(t);case 197:return t=j.getUint16(C),C+=2,Lu(t);case 198:return t=j.getUint32(C),C+=4,Lu(t);case 199:return In(G[C++]);case 200:return t=j.getUint16(C),C+=2,In(t);case 201:return t=j.getUint32(C),C+=4,In(t);case 202:if(t=j.getFloat32(C),Ee.useFloat32>2){let A=ka[(G[C]&127)<<1|G[C+1]>>7];return C+=4,(A*t+(t>0?.5:-.5)>>0)/A}return C+=4,t;case 203:return t=j.getFloat64(C),C+=8,t;case 204:return G[C++];case 205:return t=j.getUint16(C),C+=2,t;case 206:return t=j.getUint32(C),C+=4,t;case 207:return Ee.int64AsType==="number"?(t=j.getUint32(C)*4294967296,t+=j.getUint32(C+4)):Ee.int64AsType==="string"?t=j.getBigUint64(C).toString():Ee.int64AsType==="auto"?(t=j.getBigUint64(C),t<=BigInt(2)<=BigInt(-2)<=C?Di.slice(C-Lt,(C+=t)-Lt):KS(t);case 218:return t=j.getUint16(C),C+=2,yA>=C?Di.slice(C-Lt,(C+=t)-Lt):LS(t);case 219:return t=j.getUint32(C),C+=4,yA>=C?Di.slice(C-Lt,(C+=t)-Lt):OS(t);case 220:return t=j.getUint16(C),C+=2,EE(t);case 221:return t=j.getUint32(C),C+=4,EE(t);case 222:return t=j.getUint16(C),C+=2,mE(t);case 223:return t=j.getUint32(C),C+=4,mE(t);default:if(e>=224)return e-256;if(e===void 0){let A=new Error("Unexpected end of MessagePack data");throw A.incomplete=!0,A}throw new Error("Unknown MessagePack token "+e)}}}var RS=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function Pu(e,t){function A(){if(A.count++>kE){let n=e.read=new Function("r","return function(){return "+(Ee.freezeData?"Object.freeze":"")+"({"+e.map(r=>r==="__proto__"?"__proto_:r()":RS.test(r)?r+":r()":"["+JSON.stringify(r)+"]:r()").join(",")+"})}")(Se);return e.highByte===0&&(e.read=pE(t,e.read)),n()}let i={};for(let n=0,r=e.length;nfunction(){let A=G[C++];if(A===0)return t();let i=e<32?-(e+(A<<5)):e+(A<<5),n=te[i]||SE()[i];if(!n)throw new Error("Record id is not defined for "+i);return n.read||(n.read=Pu(n,e)),n.read()};function SE(){let e=xE(()=>(G=null,Ee.getStructures()));return te=Ee._mergeStructures(e,te)}var Vu=ts,KS=ts,LS=ts,OS=ts;function ts(e){let t;if(e<16&&(t=_u(e)))return t;if(e>64&&Ou)return Ou.decode(G.subarray(C,C+=e));let A=C+e,i=[];for(t="";C65535&&(I-=65536,i.push(I>>>10&1023|55296),I=56320|I&1023),i.push(I)}else i.push(n);i.length>=4096&&(t+=Oe.apply(String,i),i.length=0)}return i.length>0&&(t+=Oe.apply(String,i)),t}function EE(e){let t=new Array(e);for(let A=0;A0){C=t;return}A[i]=n}return Oe.apply(String,A)}function _u(e){if(e<4)if(e<2){if(e===0)return"";{let t=G[C++];if((t&128)>1){C-=1;return}return Oe(t)}}else{let t=G[C++],A=G[C++];if((t&128)>0||(A&128)>0){C-=2;return}if(e<3)return Oe(t,A);let i=G[C++];if((i&128)>0){C-=3;return}return Oe(t,A,i)}else{let t=G[C++],A=G[C++],i=G[C++],n=G[C++];if((t&128)>0||(A&128)>0||(i&128)>0||(n&128)>0){C-=4;return}if(e<6){if(e===4)return Oe(t,A,i,n);{let r=G[C++];if((r&128)>0){C-=5;return}return Oe(t,A,i,n,r)}}else if(e<8){let r=G[C++],o=G[C++];if((r&128)>0||(o&128)>0){C-=6;return}if(e<7)return Oe(t,A,i,n,r,o);let s=G[C++];if((s&128)>0){C-=7;return}return Oe(t,A,i,n,r,o,s)}else{let r=G[C++],o=G[C++],s=G[C++],I=G[C++];if((r&128)>0||(o&128)>0||(s&128)>0||(I&128)>0){C-=8;return}if(e<10){if(e===8)return Oe(t,A,i,n,r,o,s,I);{let a=G[C++];if((a&128)>0){C-=9;return}return Oe(t,A,i,n,r,o,s,I,a)}}else if(e<12){let a=G[C++],c=G[C++];if((a&128)>0||(c&128)>0){C-=10;return}if(e<11)return Oe(t,A,i,n,r,o,s,I,a,c);let u=G[C++];if((u&128)>0){C-=11;return}return Oe(t,A,i,n,r,o,s,I,a,c,u)}else{let a=G[C++],c=G[C++],u=G[C++],l=G[C++];if((a&128)>0||(c&128)>0||(u&128)>0||(l&128)>0){C-=12;return}if(e<14){if(e===12)return Oe(t,A,i,n,r,o,s,I,a,c,u,l);{let g=G[C++];if((g&128)>0){C-=13;return}return Oe(t,A,i,n,r,o,s,I,a,c,u,l,g)}}else{let g=G[C++],B=G[C++];if((g&128)>0||(B&128)>0){C-=14;return}if(e<15)return Oe(t,A,i,n,r,o,s,I,a,c,u,l,g,B);let p=G[C++];if((p&128)>0){C-=15;return}return Oe(t,A,i,n,r,o,s,I,a,c,u,l,g,B,p)}}}}}function yE(){let e=G[C++],t;if(e<192)t=e-160;else switch(e){case 217:t=G[C++];break;case 218:t=j.getUint16(C),C+=2;break;case 219:t=j.getUint32(C),C+=4;break;default:throw new Error("Expected string")}return ts(t)}function Lu(e){return Ee.copyBuffers?Uint8Array.prototype.slice.call(G,C,C+=e):G.subarray(C,C+=e)}function In(e){let t=G[C++];if(Et[t]){let A;return Et[t](G.subarray(C,A=C+=e),i=>{C=i;try{return Se()}finally{C=A}})}else throw new Error("Unknown extension type "+t)}var wE=new Array(4096);function NE(){let e=G[C++];if(e>=160&&e<192){if(e=e-160,yA>=C)return Di.slice(C-Lt,(C+=e)-Lt);if(!(yA==0&&Ot<180))return Vu(e)}else return C--,Se().toString();let t=(e<<5^(e>1?j.getUint16(C):e>0?G[C]:0))&4095,A=wE[t],i=C,n=C+e-3,r,o=0;if(A&&A.bytes==e){for(;i{let A=Se().map(r=>r.toString()),i=e;t!==void 0&&(e=e<32?-((t<<5)+e):(t<<5)+e,A.highByte=t);let n=te[e];return n&&(n.isShared||ki)&&((te.restoreStructures||(te.restoreStructures=[]))[e]=n),te[e]=A,A.read=Pu(A,i),A.read()};Et[0]=()=>{};Et[0].noBuffer=!0;Et[66]=e=>{let t=e.length,A=BigInt(e[0]&128?e[0]-256:e[0]);for(let i=1;i{let e=Se();return(bS[e[0]]||Error)(e[1])};Et[105]=e=>{let t=j.getUint32(C-4);zA||(zA=new Map);let A=G[C],i;A>=144&&A<160||A==220||A==221?i=[]:i={};let n={target:i};zA.set(t,n);let r=Se();return n.used?Object.assign(i,r):(n.target=r,r)};Et[112]=e=>{let t=j.getUint32(C-4),A=zA.get(t);return A.used=!0,A.target};Et[115]=()=>new Set(Se());var Tu=["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map(e=>e+"Array"),YS=typeof globalThis=="object"?globalThis:window;Et[116]=e=>{let t=e[0],A=Tu[t];if(!A)throw new Error("Could not find typed array for code "+t);return new YS[A](Uint8Array.prototype.slice.call(e,1).buffer)};Et[120]=()=>{let e=Se();return new RegExp(e[0],e[1])};var VS=[];Et[98]=e=>{let t=(e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3],A=C;return C+=t-e.length,be=VS,be=[yE(),yE()],be.position0=0,be.position1=0,be.postBundlePosition=C,C=A,Se()};Et[255]=e=>e.length==4?new Date((e[0]*16777216+(e[1]<<16)+(e[2]<<8)+e[3])*1e3):e.length==8?new Date(((e[0]<<22)+(e[1]<<14)+(e[2]<<6)+(e[3]>>2))/1e6+((e[3]&3)*4294967296+e[4]*16777216+(e[5]<<16)+(e[6]<<8)+e[7])*1e3):e.length==12?new Date(((e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3])/1e6+((e[4]&128?-281474976710656:0)+e[6]*1099511627776+e[7]*4294967296+e[8]*16777216+(e[9]<<16)+(e[10]<<8)+e[11])*1e3):new Date("invalid");function xE(e){CE&&CE();let t=Ot,A=C,i=Yu,n=Lt,r=yA,o=Di,s=bu,I=zA,a=be,c=new Uint8Array(G.slice(0,Ot)),u=te,l=te.slice(0,te.length),g=Ee,B=ki,p=e();return Ot=t,C=A,Yu=i,Lt=n,yA=r,Di=o,bu=s,zA=I,be=a,G=c,ki=B,te=u,te.splice(0,te.length,...l),Ee=g,j=new DataView(G.buffer,G.byteOffset,G.byteLength),p}function Da(){G=null,zA=null,te=null}var ka=new Array(147);for(let e=0;e<256;e++)ka[e]=+("1e"+Math.floor(45.15-e*.30103));var Sa=new an({useRecords:!1}),zS=Sa.unpack,PS=Sa.unpackMultiple,_S=Sa.unpack,Ua={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4},TS=new Float32Array(1),JG=new Uint8Array(TS.buffer,0,4);var xa;try{xa=new TextEncoder}catch{}var Xu,JE,Ga=typeof Buffer<"u",Na=Ga?function(e){return Buffer.allocUnsafeSlow(e)}:Uint8Array,qE=Ga?Buffer:Uint8Array,GE=Ga?4294967296:2144337920,E,As,ae,h=0,at,Fe=null,XS,ZS=21760,WS=/[\u0080-\uFFFF]/,ur=Symbol("record-id"),cn=class extends an{constructor(t){super(t),this.offset=0;let A,i,n,r,o,s=qE.prototype.utf8Write?function(m,J){return E.utf8Write(m,J,4294967295)}:xa&&xa.encodeInto?function(m,J){return xa.encodeInto(m,E.subarray(J)).written}:!1,I=this;t||(t={});let a=t&&t.sequential,c=t.structures||t.saveStructures,u=t.maxSharedStructures;if(u==null&&(u=c?32:0),u>8160)throw new Error("Maximum maxSharedStructure is 8160");t.structuredClone&&t.moreTypes==null&&(this.moreTypes=!0);let l=t.maxOwnStructures;l==null&&(l=c?32:64),!this.structures&&t.useRecords!=!1&&(this.structures=[]);let g=u>32||l+u>64,B=u+64,p=u+l+64;if(p>8256)throw new Error("Maximum maxSharedStructure + maxOwnStructure is 8192");let U=[],d=0,f=0;this.pack=this.encode=function(m,J){if(E||(E=new Na(8192),ae=E.dataView||(E.dataView=new DataView(E.buffer,0,8192)),h=0),at=E.length-10,at-h<2048?(E=new Na(E.length),ae=E.dataView||(E.dataView=new DataView(E.buffer,0,E.length)),at=E.length-10,h=0):h=h+7&2147483640,i=h,J&IU&&(h+=J&255),o=I.structuredClone?new Map:null,I.bundleStrings&&typeof m!="string"?(Fe=[],Fe.size=1/0):Fe=null,r=I.structures,r){r.uninitialized&&(r=I._mergeStructures(I.getStructures()));let k=r.sharedLength||0;if(k>u)throw new Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+r.sharedLength);if(!r.transitions){r.transitions=Object.create(null);for(let x=0;xre.offset>Ae.offset?1:-1),z=x.length,L=-1;for(;k&&z>0;){let re=x[--z].offset+i;rek.position+i?L>=0&&(L+=6):(L>=0&&(ae.setUint32(k.position+i,ae.getUint32(k.position+i)+L),L=-1),k=k.previous,z++)}L>=0&&k&&ae.setUint32(k.position+i,ae.getUint32(k.position+i)+L),h+=x.length*6,h>at&&q(h),I.offset=h;let O=$S(E.subarray(i,h),x);return o=null,O}return I.offset=h,J&KE?(E.start=i,E.end=h,E):E.subarray(i,h)}catch(k){throw H=k,k}finally{if(r&&(Q(),n&&I.saveStructures)){let k=r.sharedLength||0,x=E.subarray(i,h),z=eU(r,I);if(!H)return I.saveStructures(z,z.isCompatible)===!1?I.pack(m,J):(I.lastNamedStructuresLength=k,x)}J&sU&&(h=i)}};let Q=()=>{f<10&&f++;let m=r.sharedLength||0;if(r.length>m&&!a&&(r.length=m),d>1e4)r.transitions=null,f=0,d=0,U.length>0&&(U=[]);else if(U.length>0&&!a){for(let J=0,H=U.length;J{var J=m.length;J<16?E[h++]=144|J:J<65536?(E[h++]=220,E[h++]=J>>8,E[h++]=J&255):(E[h++]=221,ae.setUint32(h,J),h+=4);for(let H=0;H{h>at&&(E=q(h));var J=typeof m,H;if(J==="string"){let k=m.length;if(Fe&&k>=4&&k<4096){if((Fe.size+=k)>ZS){let O,re=(Fe[0]?Fe[0].length*3+Fe[1].length:0)+10;h+re>at&&(E=q(h+re));let Ae;Fe.position?(Ae=Fe,E[h]=200,h+=3,E[h++]=98,O=h-i,h+=4,vE(i,F,0),ae.setUint16(O+i-3,h-i-O)):(E[h++]=214,E[h++]=98,O=h-i,h+=4),Fe=["",""],Fe.previous=Ae,Fe.size=0,Fe.position=O}let L=WS.test(m);Fe[L?0:1]+=m,E[h++]=193,F(L?-k:k);return}let x;k<32?x=1:k<256?x=2:k<65536?x=3:x=5;let z=k*3;if(h+z>at&&(E=q(h+z)),k<64||!s){let L,O,re,Ae=h+x;for(L=0;L>6|192,E[Ae++]=O&63|128):(O&64512)===55296&&((re=m.charCodeAt(L+1))&64512)===56320?(O=65536+((O&1023)<<10)+(re&1023),L++,E[Ae++]=O>>18|240,E[Ae++]=O>>12&63|128,E[Ae++]=O>>6&63|128,E[Ae++]=O&63|128):(E[Ae++]=O>>12|224,E[Ae++]=O>>6&63|128,E[Ae++]=O&63|128);H=Ae-h-x}else H=s(m,h+x);H<32?E[h++]=160|H:H<256?(x<2&&E.copyWithin(h+2,h+1,h+1+H),E[h++]=217,E[h++]=H):H<65536?(x<3&&E.copyWithin(h+3,h+2,h+2+H),E[h++]=218,E[h++]=H>>8,E[h++]=H&255):(x<5&&E.copyWithin(h+5,h+3,h+3+H),E[h++]=219,ae.setUint32(h,H),h+=4),h+=H}else if(J==="number")if(m>>>0===m)m<32||m<128&&this.useRecords===!1||m<64&&!this.randomAccessStructure?E[h++]=m:m<256?(E[h++]=204,E[h++]=m):m<65536?(E[h++]=205,E[h++]=m>>8,E[h++]=m&255):(E[h++]=206,ae.setUint32(h,m),h+=4);else if(m>>0===m)m>=-32?E[h++]=256+m:m>=-128?(E[h++]=208,E[h++]=m+256):m>=-32768?(E[h++]=209,ae.setInt16(h,m),h+=2):(E[h++]=210,ae.setInt32(h,m),h+=4);else{let k;if((k=this.useFloat32)>0&&m<4294967296&&m>=-2147483648){E[h++]=202,ae.setFloat32(h,m);let x;if(k<4||(x=m*ka[(E[h]&127)<<1|E[h+1]>>7])>>0===x){h+=4;return}else h--}E[h++]=203,ae.setFloat64(h,m),h+=8}else if(J==="object"||J==="function")if(!m)E[h++]=192;else{if(o){let x=o.get(m);if(x){if(!x.id){let z=o.idsToInsert||(o.idsToInsert=[]);x.id=z.push(x)}E[h++]=214,E[h++]=112,ae.setUint32(h,x.id),h+=4;return}else o.set(m,{offset:h-i})}let k=m.constructor;if(k===Object)K(m,!0);else if(k===Array)y(m);else if(k===Map)if(this.mapAsEmptyObject)E[h++]=128;else{H=m.size,H<16?E[h++]=128|H:H<65536?(E[h++]=222,E[h++]=H>>8,E[h++]=H&255):(E[h++]=223,ae.setUint32(h,H),h+=4);for(let[x,z]of m)F(x),F(z)}else{for(let x=0,z=Xu.length;x(E=re,re=null,h+=Vt,h>at&&q(h),{target:E,targetView:ae,position:h-Vt}),F)}finally{re&&(E=re,ae=Ae,h=Te,at=E.length-10)}Yt&&(Yt.length+h>at&&q(Yt.length+h),h=jS(Yt,E,h,O.type));return}}if(Array.isArray(m))y(m);else{if(m.toJSON){let x=m.toJSON();if(x!==m)return F(x)}if(J==="function")return F(this.writeFunction&&this.writeFunction(m));K(m,!m.hasOwnProperty)}}}else if(J==="boolean")E[h++]=m?195:194;else if(J==="bigint"){if(m=-(BigInt(1)<0)E[h++]=207,ae.setBigUint64(h,m);else if(this.largeBigIntToFloat)E[h++]=203,ae.setFloat64(h,Number(m));else if(this.useBigIntExtension&&m<2n**1023n&&m>-(2n**1023n)){E[h++]=199,h++,E[h++]=66;let k=[],x;do{let z=m&0xffn;x=(z&0x80n)===(m<0n?0x80n:0n),k.push(z),m>>=8n}while(!((m===0n||m===-1n)&&x));E[h-2]=k.length;for(let z=k.length;z>0;)E[h++]=Number(k[--z]);return}else throw new RangeError(m+" was too large to fit in MessagePack 64-bit integer format, use useBigIntExtension or set largeBigIntToFloat to convert to float-64");h+=8}else if(J==="undefined")this.encodeUndefinedAsNil?E[h++]=192:(E[h++]=212,E[h++]=0,E[h++]=0);else throw new Error("Unknown type: "+J)},w=this.variableMapSize||this.coercibleKeyAsNumber?m=>{let J=Object.keys(m),H=J.length;H<16?E[h++]=128|H:H<65536?(E[h++]=222,E[h++]=H>>8,E[h++]=H&255):(E[h++]=223,ae.setUint32(h,H),h+=4);let k;if(this.coercibleKeyAsNumber)for(let x=0;x{E[h++]=222;let H=h-i;h+=2;let k=0;for(let x in m)(J||m.hasOwnProperty(x))&&(F(x),F(m[x]),k++);E[H+++i]=k>>8,E[H+i]=k&255},D=this.useRecords===!1?w:t.progressiveRecords&&!g?(m,J)=>{let H,k=r.transitions||(r.transitions=Object.create(null)),x=h++-i,z;for(let L in m)if(J||m.hasOwnProperty(L)){if(H=k[L],H)k=H;else{let O=Object.keys(m),re=k;k=r.transitions;let Ae=0;for(let Te=0,Yt=O.length;Te{let H,k=r.transitions||(r.transitions=Object.create(null)),x=0;for(let L in m)(J||m.hasOwnProperty(L))&&(H=k[L],H||(H=k[L]=Object.create(null),x++),k=H);let z=k[ur];z?z>=96&&g?(E[h++]=((z-=96)&31)+96,E[h++]=z>>5):E[h++]=z:X(k,k.__keys__||Object.keys(m),x);for(let L in m)(J||m.hasOwnProperty(L))&&F(m[L])},S=typeof this.useRecords=="function"&&this.useRecords,K=S?(m,J)=>{S(m)?D(m,J):w(m,J)}:D,q=m=>{let J;if(m>16777216){if(m-i>GE)throw new Error("Packed buffer would be larger than maximum buffer size");J=Math.min(GE,Math.round(Math.max((m-i)*(m>67108864?1.25:2),4194304)/4096)*4096)}else J=(Math.max(m-i<<2,E.length-1)>>12)+1<<12;let H=new Na(J);return ae=H.dataView||(H.dataView=new DataView(H.buffer,0,J)),m=Math.min(m,E.length),E.copy?E.copy(H,0,i,m):H.set(E.slice(i,m)),h-=i,i=0,at=H.length-10,E=H},X=(m,J,H)=>{let k=r.nextId;k||(k=64),k=p&&(k=B),r.nextId=k+1);let x=J.highByte=k>=96&&g?k-96>>5:-1;m[ur]=k,m.__keys__=J,r[k-64]=J,k=0?(E[h++]=(k&31)+96,E[h++]=x):E[h++]=k):(x>=0?(E[h++]=213,E[h++]=114,E[h++]=(k&31)+96,E[h++]=x):(E[h++]=212,E[h++]=114,E[h++]=k),H&&(d+=f*H),U.length>=l&&(U.shift()[ur]=0),U.push(m),F(J))},Ue=(m,J,H,k)=>{let x=E,z=h,L=at,O=i;E=As,h=0,i=0,E||(As=E=new Na(8192)),at=E.length-10,X(m,J,k),As=E;let re=h;if(E=x,h=z,at=L,i=O,re>1){let Ae=h+re-1;Ae>at&&q(Ae);let Te=H+i;E.copyWithin(Te+re,Te+1,h),E.set(As.slice(0,re),Te),h=Ae}else E[H+i]=As[0]},ct=(m,J)=>{let H=XS(m,E,i,h,r,q,(k,x,z)=>{if(z)return n=!0;h=x;let L=E;return F(k),Q(),L!==E?{position:h,targetView:ae,target:E}:h},this);if(H===0)return K(m,!0);h=H}}useBuffer(t){E=t,ae=new DataView(E.buffer,E.byteOffset,E.byteLength),h=0}clearSharedData(){this.structures&&(this.structures=[]),this.typedStructs&&(this.typedStructs=[])}};JE=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor,es];Xu=[{pack(e,t,A){let i=e.getTime()/1e3;if((this.useTimestamp32||e.getMilliseconds()===0)&&i>=0&&i<4294967296){let{target:n,targetView:r,position:o}=t(6);n[o++]=214,n[o++]=255,r.setUint32(o,i)}else if(i>0&&i<4294967296){let{target:n,targetView:r,position:o}=t(10);n[o++]=215,n[o++]=255,r.setUint32(o,e.getMilliseconds()*4e6+(i/1e3/4294967296>>0)),r.setUint32(o+4,i)}else if(isNaN(i)){if(this.onInvalidDate)return t(0),A(this.onInvalidDate());let{target:n,targetView:r,position:o}=t(3);n[o++]=212,n[o++]=255,n[o++]=255}else{let{target:n,targetView:r,position:o}=t(15);n[o++]=199,n[o++]=12,n[o++]=255,r.setUint32(o,e.getMilliseconds()*1e6),r.setBigInt64(o+4,BigInt(Math.floor(i)))}}},{pack(e,t,A){if(this.setAsEmptyObject)return t(0),A({});let i=Array.from(e),{target:n,position:r}=t(this.moreTypes?3:0);this.moreTypes&&(n[r++]=212,n[r++]=115,n[r++]=0),A(i)}},{pack(e,t,A){let{target:i,position:n}=t(this.moreTypes?3:0);this.moreTypes&&(i[n++]=212,i[n++]=101,i[n++]=0),A([e.name,e.message])}},{pack(e,t,A){let{target:i,position:n}=t(this.moreTypes?3:0);this.moreTypes&&(i[n++]=212,i[n++]=120,i[n++]=0),A([e.source,e.flags])}},{pack(e,t){this.moreTypes?HE(e,16,t):ME(Ga?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let A=e.constructor;A!==qE&&this.moreTypes?HE(e,Tu.indexOf(A.name),t):ME(e,t)}},{pack(e,t){let{target:A,position:i}=t(1);A[i]=193}}];function HE(e,t,A,i){let n=e.byteLength;if(n+1<256){var{target:r,position:o}=A(4+n);r[o++]=199,r[o++]=n+1}else if(n+1<65536){var{target:r,position:o}=A(5+n);r[o++]=200,r[o++]=n+1>>8,r[o++]=n+1&255}else{var{target:r,position:o,targetView:s}=A(7+n);r[o++]=201,s.setUint32(o,n+1),o+=4}r[o++]=116,r[o++]=t,r.set(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),o)}function ME(e,t){let A=e.byteLength;var i,n;if(A<256){var{target:i,position:n}=t(A+2);i[n++]=196,i[n++]=A}else if(A<65536){var{target:i,position:n}=t(A+3);i[n++]=197,i[n++]=A>>8,i[n++]=A&255}else{var{target:i,position:n,targetView:r}=t(A+5);i[n++]=198,r.setUint32(n,A),n+=4}i.set(e,n)}function jS(e,t,A,i){let n=e.length;switch(n){case 1:t[A++]=212;break;case 2:t[A++]=213;break;case 4:t[A++]=214;break;case 8:t[A++]=215;break;case 16:t[A++]=216;break;default:n<256?(t[A++]=199,t[A++]=n):n<65536?(t[A++]=200,t[A++]=n>>8,t[A++]=n&255):(t[A++]=201,t[A++]=n>>24,t[A++]=n>>16&255,t[A++]=n>>8&255,t[A++]=n&255)}return t[A++]=i,t.set(e,A),A+=n,A}function $S(e,t){let A,i=t.length*6,n=e.length-i;for(;A=t.pop();){let r=A.offset,o=A.id;e.copyWithin(r+i,r,n),i-=6;let s=r+i;e[s++]=214,e[s++]=105,e[s++]=o>>24,e[s++]=o>>16&255,e[s++]=o>>8&255,e[s++]=o&255,n=r}return e}function vE(e,t,A){if(Fe.length>0){ae.setUint32(Fe.position+e,h+A-Fe.position-e),Fe.stringsPosition=h-e;let i=Fe;Fe=null,t(i[0]),t(i[1])}}function eU(e,t){return e.isCompatible=A=>{let i=!A||(t.lastNamedStructuresLength||0)===A.length;return i||t._mergeStructures(A),i},e}var RE=new cn({useRecords:!1}),tU=RE.pack,AU=RE.pack;var{NEVER:iU,ALWAYS:nU,DECIMAL_ROUND:rU,DECIMAL_FIT:oU}=Ua,KE=512,sU=1024,IU=2048;var eB=R(VE(),1),iH=eB.default.configure,zE=eB.default;var PE={site:{list:"0",group:"1",load:"2",update:"3"},comp:{new:"4",list:"5",group:"6",load:"7"},page:{list:"8",load:"9",cache:"10"},yjs:{um:"11",sv_local:"12",diff_local:"13",sv_remote:"14"},client:{info:"15"},code:{load:"16",edit:"17",action:"18"}},_E={0:"site.list",1:"site.group",2:"site.load",3:"site.update",4:"comp.new",5:"comp.list",6:"comp.group",7:"comp.load",8:"page.list",9:"page.load",10:"page.cache",11:"yjs.um",12:"yjs.sv_local",13:"yjs.diff_local",14:"yjs.sv_remote",15:"client.info",16:"code.load",17:"code.edit",18:"code.action"};var fe=window;var TE=e=>sn(`prasi-user-${e}`,"default");var XE=new cn({structuredClone:!0}),is={debug:!!localStorage.getItem("prasi-ws-debug"),reconnectTimeout:1e3};fe.debug=new Proxy({},{get(e,t,A){if(t==="off")return is.debug=!1,localStorage.removeItem("prasi-ws-debug"),console.clear(),["WS DEBUG: Deactivated"];if(t==="on")return is.debug=!0,localStorage.setItem("prasi-ws-debug","1"),console.clear(),["WS DEBUG: Activated"]}});var wA={ws:null,client_id:"",idb:null,event:null},tB={action:{pending:{}}},ZE=(e,t)=>{let A=XE.pack(t);is.debug&&console.log("%c\u2B06","color:blue",jE(A.length,0),t),e.send(A)},WE=async e=>{let{user_id:t,site_id:A,page_id:i,events:n}=e;return wA.idb=TE(t),await BU({user_id:t,site_id:A,page_id:i},n),new oE(PE,({target:r,trapName:o,value:s,key:I,DEFAULT:a,PROXY:c})=>{if(o==="set")throw new TypeError("target is immutable");return typeof s=="string"?(...u)=>new Promise(l=>{CU({code:s,resolve:l,args:u})}):o==="get"&&typeof s=="object"&&s!==null?c:a})},BU=(e,t)=>{let{user_id:A,page_id:i,site_id:n}=e;return wA.event=t,fe.offline?new Promise(async r=>{r();let o="editor_start",s=await QU(o);t[o]&&t[o](s)}):new Promise((r,o)=>{if(!wA.ws){let s=0,I=()=>{let a=new URL(fe.basehost||location.href);a.pathname="/sync",a.protocol=a.protocol==="http:"?"ws:":"wss:";let c=new WebSocket(`${a.protocol}//${a.host}${a.pathname}`);c.onopen=()=>{ZE(c,{type:1,user_id:A,site_id:n,page_id:i}),wA.ws=c,t.opened()},c.onclose=async()=>{t.disconnected().reconnect?setTimeout(async()=>{s++,I()},s*is.reconnectTimeout):o()},c.onmessage=async u=>{let l=u.data,g=XE.unpack(Buffer.from(await l.arrayBuffer()));if(is.debug&&console.log("%c\u2B07","color:red",jE(l.size,0),g),g.type===0)wA.client_id=g.client_id,t.shakehand(g.client_id),r();else if(g.type===2){let B=g.event;t[B]&&(fU.includes(B)&&dU(B,g.data),t[B](g.data))}else if(g.type===4){let B=tB.action.pending[g.argid];if(B){B.resolve(g.val),delete tB.action.pending[g.argid];let p=wA.idb;p&&await mA(g.argid,g.val,p)}}}};I()}})},fU=["editor_start"],dU=async(e,t)=>{let A=wA.idb;if(A){let i=await wa(`ev-${e}`);await mA(i,t,A)}},QU=async e=>{let t=wA.idb;if(t){let A=await wa(`ev-${e}`);return await EA(A,t)}},CU=async e=>{let{args:t,code:A,resolve:i}=e,n=wA.ws,r=wA.idb;if(r){let o=zE(t),s=_E[A],I=await wa(`op-${s}-${o}`);if(n&&n.readyState===n.OPEN)tB.action.pending[I]={ts:Date.now(),resolve:i},ZE(n,{type:3,code:A,args:t,argid:I});else{let a=await EA(I,r);i(a)}}};function jE(e,t){if(e==0)return"0 Bytes";var A=1024,i=t||2,n=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],r=Math.floor(Math.log(e)/Math.log(A));return parseFloat((e/Math.pow(A,r)).toFixed(i))+" "+n[r]}var Br={NORMAL:0,WILDCARD:1,PLACEHOLDER:2};function fr(e={}){let t={options:e,rootNode:em(),staticRoutesMap:{}},A=i=>e.strictTrailingSlash?i:i.replace(/\/$/,"")||"/";if(e.routes)for(let i in e.routes)$E(t,A(i),e.routes[i]);return{ctx:t,lookup:i=>hU(t,A(i)),insert:(i,n)=>$E(t,A(i),n),remove:i=>pU(t,A(i))}}function hU(e,t){let A=e.staticRoutesMap[t];if(A)return A.data;let i=t.split("/"),n={},r=!1,o=null,s=e.rootNode,I=null;for(let a=0;a{},db:null,api:null,init_local_effect:{}},page:{history:{id:"",show:!1},root_id:"root",cur:mU,doc:null,list:{},building:!1,meta:{},entry:[],tree:[],render:()=>{}},comp:{doc:null,item:null,loaded:{},list:{},group:{}},code:{},global_prop:[],ui:{comp_editable:localStorage.getItem("prasi-comp-editable")==="yes",zoom:localStorage.zoom||"100%",side:{prop:!0},layout:{left:parseInt(localStorage.getItem("prasi-layout-left")||"250"),right:parseInt(localStorage.getItem("prasi-layout-right")||"250")},prevent_indent_hook:!1,syncing:!1,tree:{item_loading:[],search:"",search_ref:null,search_mode:{Name:!0,JS:!1,HTML:!1,CSS:!1},rename_id:"",open:{}},popup:{code:{init:!1,open:!1,name:"site",log:"",loading:!1,startup_status:"init",error:!1,show_log:!1,list:{}},page:{open:null,form:null},script:{open:!1,mode:"js",lastMode:"js",type:"item",prop_kind:"",prop_name:"",on_close:()=>{},typings:{status:"ok",err_msg:""},wb_render:()=>{}},site:null,site_form:null,comp:{preview_id:"",open:null,import:!1},comp_group:null,api:{open:!1}}}};var am=R(va());var cm=e=>{let{item:t,item_comp:A,ids:i}=e,n=uA(A);if(gm(n,i),t.id&&(n.id=t.id),n.component){if(n.component.props&&t.component)for(let r of Object.keys(n.component.props)){let o=t.component.props[r],s=n.component.props[r];o&&(s.value=o.value,s.valueBuilt=o.valueBuilt,s.jsxCalledBy=o.jsxCalledBy,s.content=o.content)}n.component.instances=t.component?.instances,n.component.style=t.component?.style}for(let r of Object.keys(t))delete t[r];for(let[r,o]of Object.entries(n))t[r]=o},gm=(e,t)=>{if(e.originalId=e.id,t[e.id]||(t[e.id]=(0,am.createId)()),e.id=t[e.id],e.childs)for(let A of e.childs)gm(A,t)};var lm=e=>{for(let[t,A]of Object.entries(e.item_comp.component?.props||{})){let i=uA(A),n=e.item.component?.props;n&&n[t]&&(i.value=n[t].value,i.valueBuilt=n[t].valueBuilt,n[t].content&&(i.content=n[t].content)),i&&e.each(t,i)}};var Ja=e=>{let t={};for(let[A,i]of Object.entries(e))if(A==="childs"){if(t.childs=[],i&&Array.isArray(i))for(let n of i)t.childs.push({id:n.id})}else t[A]=i;return t};var um=(e,t)=>{let{item:A}=t;if(A.type==="item"&&A.component?.id&&t.parent?.item.id){let i=e.comps[A.component.id];if(e.on?.visit_component&&e.on.visit_component(A,t.root||t.item),!i)return;if(i){let n;if(e.mode==="page"?(A.component.instances||(A.component.instances={}),n=A.component.instances):n=t.parent?.root_instances,n){let o=n[A.id];n[A.id]||(n[A.id]={},o=n[A.id]),cm({item:A,item_comp:i,ids:o})}let r={item:Ja(A),jsx_prop:t.jsx_prop,parent:{id:t.parent.item.id,comp_id:t.parent?.comp?.component?.id,instance_id:t.parent?.instance_id},instances:n};e.on?.visit&&e.on.visit(r,A,t.root||t.item),A.id&&e.set_meta!==!1&&(e.meta[A.id]=r),lm({item:A,item_comp:i,instance:n?n[A.id]:{},each(o,s){let I=A.component?.id;s.meta?.type==="content-element"&&I&&s.content&&(s.content.name=o,Nt({...e,mode:"comp"},{item:s.content,root:t.root||s.content,is_root:!1,jsx_prop:{is_root:!0,comp_id:I,name:o},parent:{item:r.item,instance_id:A.id,comp:i,root_instances:n}}))}});for(let o of Object.values(A.childs))o.name.startsWith("jsx:")||Nt({...e,mode:"comp"},{item:o,is_root:!1,root:t.root||t.item,parent:{item:A,instance_id:A.id,root_instances:n,comp:i}})}}};var Nt=(e,t)=>{let A=t.item;if(A.type==="item"&&A.component?.id&&t.ignore_first_component!==!0){um(e,t);return}let i={item:Ja(A),parent:{id:t.parent?.item.id||"root",instance_id:t.parent?.instance_id,comp_id:t.parent?.comp?.component?.id}};if(t.jsx_prop&&(i.jsx_prop=t.jsx_prop),e.on?.visit&&e.on.visit(i,A,t.root||t.item),A.id&&e.set_meta!==!1&&(e.meta[i.item.id]=i),A.childs){for(let[n,r]of Object.entries(A.childs))if(r.id){let o={item:r,is_root:!1,root:t.root||t.item,parent:{item:i.item,instance_id:t.parent?.instance_id,comp:t.parent?.comp,root_instances:t.parent?.root_instances}};t.jsx_prop&&(o.jsx_prop={...t.jsx_prop,is_root:!1}),Nt(e,o)}}};var qa=async(e,t,A,i)=>{let n=new Set,r={root:t};if(Nt({...e,on:{visit_component:({component:o})=>{if(o){let{id:s}=o;if(e.comps[s]||(!i||i&&!i.has(s))&&n.add(s),o?.props)for(let[I,a]of Object.entries(o.props))a.meta?.type==="content-element"&&a.content&&Nt({...e,on:{visit_component:({component:c})=>{if(c){let{id:u}=c;e.comps[u]||(!i||i&&!i.has(u))&&n.add(u)}},visit(c,u){A.visit&&A.visit(c,u,r)}},set_meta:!1,note:"init-load-comp-prop"},{item:a.content})}},visit(o,s){A.visit&&A.visit(o,s,r)}},set_meta:!1,note:"init-load-comp"},{item:t,ignore_first_component:!0}),A.done&&A.done(r),n.size>0){await A.load([...n]);let o=i;o||(o=new Set),n.forEach(s=>{o&&o.add(s)});for(let s of[...o]){let I=e.comps[s];I&&await qa(e,I,A,o)}}};var GU=sn("prasi-cache","prasi-cache-store"),un={timeout:null,store:GU},Ra=(e,t)=>{let A=[...Bm(t,"navigate(",")"),...Bm(t,"href = ",";")],i=e.page.cur.id;e.page.navs[i]||(e.page.navs[i]=new Set);for(let n of A)e.page.navs[i].add(n);clearTimeout(un.timeout),un.timeout=setTimeout(()=>{e.on_nav_loaded&&e.on_nav_loaded({urls:Array.from(e.page.navs[i])})},100)},Bm=(e,t,A)=>{let i=0,n=0,r=[];for(;;){let o=e.indexOf(t,i);if(n=i,o>=0){let s=e[o+t.length];if(s==='"'||s==="'"||s==="`"){let I=e.indexOf(`${s}${A}`,o+t.length+1),a=e.substring(o+t.length+1,I);i=I+2+A.length,r.push(a)}}if(n===i)break}return r};var dm=R(va());var Ka=()=>{let e=document.activeElement;return!!(e&&e.attributes.getNamedItem("contenteditable"))};var fm=R(va()),La=e=>{let{m:t,root:A,mitem:i,meta:n}=e;if(t.jsx_prop&&t.parent?.instance_id){let r=n[t.parent?.instance_id];if(r&&t.jsx_prop.is_root){let o=r.item.component?.props[t.jsx_prop.name];o&&(o.content=t.item)}}if(t.parent)if(t.parent.id==="root")t.item.id===A.id&&(t.mitem=i);else{let r=n[t.parent.id];if(r.mitem)if(t.jsx_prop?.is_root===!0){let o=r.mitem.get("component")?.get("props");if(o){let s=o.get(t.jsx_prop.name);if(s){let I=s.get("content");if(!I){let a=new Y.Map;syncronize(a,{id:(0,fm.createId)(),name:t.jsx_prop.name,type:"item",dim:{w:"full",h:"full"},childs:[],adv:{css:""}}),s.set("content",a)}I&&(t.mitem=I)}}}else r.mitem.get("childs")?.forEach(o=>{o&&o.get&&o.get("id")===t.item.id&&(t.mitem=o)});if(t.item.component?.props)for(let[o,s]of Object.entries(t.item.component.props)){let I=t.mitem?.get("component")?.get("props")?.get(o);if(!I){let a=t.mitem?.get("component")?.get("props");a&&e.new_prop_jsx(t,a,o,s)}if(s.content)if(I){let a=n[s.content.id];a&&(a.mitem=I.get("content"))}else{let a=t.mitem?.get("component")?.get("props");a&&e.new_prop_jsx(t,a,o,s)}}}};var Oa=(e,t,A,i)=>{if(t.parent?.id==="root")e.page.doc?.getMap("map").get("root")?.get("childs")?.forEach(n=>{n.get("id")===t.item.id&&(t.mitem=n)});else{let n=A[t.parent?.id||""];n&&n.mitem&&n.mitem.get("childs")?.forEach(r=>{r&&r.get&&r.get("id")===t.item.id&&(t.mitem=r)})}if(!t.item||!t.item.id)return console.warn("Emptry Tree Item ",t),null;if(i.find(n=>n.id===t.item.id))console.warn("Double Tree Item: ",t.item.id,t.item.name);else if(!t.parent?.comp_id)i.push({id:t.item.id,parent:t.parent?.id||"root",text:t.item.name,data:t});else if(t.jsx_prop)if(t.jsx_prop.is_root)t.jsx_prop.name!=="child"&&i.push({id:t.item.id,parent:t.parent?.instance_id||"root",text:t.jsx_prop.name,data:t});else{if(t.jsx_prop.name==="child"&&t.parent.instance_id){let n=A[t.parent.instance_id],r=n.item.component?.props.child.content?.id;r&&n.mitem&&A[r].item.childs.find(s=>t.item.id===s.id)&&i.push({id:t.item.id,parent:t.parent?.instance_id||"root",text:t.item.name,data:t})}t.parent.id!==t.parent.instance_id&&i.push({id:t.item.id,parent:t.parent?.id||"root",text:t.item.name,data:t})}};var Ya=async(e,t,A)=>{if(e.comp.list[t])return;let i=new Y.Doc;Y.applyUpdate(i,dt(A));let n=i.getMap("map").get("root");if(n){e.comp.loaded[t]=n.toJSON(),typeof e.comp.list[t]?.on_update=="function"&&i.off("update",e.comp.list[t].on_update);let r=await ba(e,i,t);if(r){let{meta:o,tree:s}=r;e.comp.list[t]?(e.comp.list[t].meta=o,e.comp.list[t].tree=s):(e.comp.list[t]={comp:{id:t,snapshot:A},doc:i,meta:o,tree:s,async on_update(I,a){if(a==="sv_remote"||a==="local")return;let c=await e.sync?.yjs.sv_local("comp",t,Buffer.from($t(I)));if(c){let u=Y.encodeStateAsUpdate(i,dt(c.sv));Y.applyUpdate(i,dt(c.diff),"local"),await e.sync?.yjs.diff_local("comp",t,Buffer.from($t(u)));let l=await ba(e,e.comp.list[t].doc,t);if(l&&(e.comp.list[t].meta=l.meta,e.comp.list[t].tree=l.tree),e.comp.loaded[t]=i.getMap("map").get("root")?.toJSON(),Ka())return;iA(e),e.render()}}},i.on("update",e.comp.list[t].on_update))}}},ba=async(e,t,A)=>{let i=t.getMap("map").get("root");if(!i)return;let n={},r=[],o=i.toJSON();return e.comp.loaded[A]=o,await qa({comps:e.comp.loaded,meta:n,set_meta:!1,mode:"comp"},o,{load:async s=>{let I=s.filter(c=>!e.comp.loaded[c]),a=await e.sync?.comp.load(I,!0);if(a){let c=Object.entries(a);for(let[u,l]of c)l&&l.snapshot&&!e.comp.list[u]&&await Ya(e,u,l.snapshot)}}}),Nt({comps:e.comp.loaded,meta:n,mode:"comp",on:{async visit(s){Oa(e,s,n,r),La({m:s,root:o,mitem:i,meta:n,new_prop_jsx(I,a,c,u){nB.list.push(()=>{let l=new Y.Map;u.content&&(u.content.id=(0,dm.createId)()),syncronize(l,u),a.set(c,l)})}})}},note:"load-comp-scan-meta"},{item:o,ignore_first_component:!0}),nB.list.length>0&&e.page.doc?.transact(()=>{for(let s of nB.list)s()}),e.comp.loaded[A]=o,{meta:n,tree:r,item:o}},nB={list:[]};var iA=async(e,t)=>{if(document.activeElement){let o=document.activeElement;if(o.tagName==="DIV"&&o.getAttribute("contenteditable")==="true")return}Ma.should_render_main=!0;let A=e.site.layout&&e.site.layout.id===e.page.cur.id&&t?.note==="load-layout page-init";for(let[o,s]of Object.entries(e.comp.list))if(!e.comp.loaded[o]){let a=s.doc.getMap("map").get("root")?.toJSON();a&&(e.comp.loaded[o]=a)}let i=e.page.doc?.getMap("map").get("root"),n=[];i?.get("childs")?.forEach(o=>n.push(o));let r={};e.page.tree=[];for(let o of n){let s=o.toJSON();s&&Nt({note:"tree-rebuild",comps:e.comp.loaded,meta:r,mode:"page",on:{async visit(I){A||((I.parent?.instance_id!==I.parent?.id||I.jsx_prop)&&Oa(e,I,r,e.page.tree),La({m:I,root:s,mitem:o,meta:r,new_prop_jsx(a,c,u,l){if(!c.get(u)){let g=new Y.Map;syncronize(g,l),c.set(u,g)}}}))}}},{item:s})}if(A)e.site.layout.meta=r;else{let o="root";if(e.site.layout&&e.site.layout.meta){for(let[s,I]of Object.entries(e.site.layout.meta))if(I.item.name==="content"){o=I.item.id;break}e.page.root_id=o}if(e.site.layout&&e.site.layout.id===e.page.cur.id)e.page.meta=r;else if(o!=="root"){for(let s of Object.values(r))s.parent?.id==="root"&&(s.parent.id=o);e.page.meta={...e.site.layout.meta,...r}}else e.page.meta=r}};BigInt.prototype.toJSON=function(){return"BigInt::"+this.toString()};var Bn=typeof window<"u"?window:null,dr=async(e,t,A)=>{let i={...A},n=t,r=!1,o=async I=>{if(Bn!==null){if(!(I instanceof Bn.FormData||I instanceof Bn.File))i["content-type"]="application/json";else if(I instanceof Bn.File){r=!0;let a=await new Promise(c=>{let u=new FileReader;u.addEventListener("load",l=>{c(l.target?.result)}),u.readAsArrayBuffer(I)});a&&(I=new File([a],I.name))}}return I};Array.isArray(t)?n=await Promise.all(t.map(I=>o(I))):n=await o(t),r||(n=JSON.stringify(n));let s=new URL(e);if(Bn!==null)if(new URL(location.href).host===s.host){let c=await(await fetch(s.pathname,t?{method:"POST",body:n,headers:i}:void 0)).text();try{return JSON.parse(c)}catch{return c}}else if(t instanceof File||Array.isArray(t)&&t[0]instanceof File){let a=new URL(e);if(A["content-type"]="multipart/form-data",t instanceof File){let c=new FormData;return c.append("file",t),await(await fetch(a.pathname,{body:c,method:"POST",headers:A})).text()}else{let c=new FormData,u=1;for(let g of t)c.append("file-"+u++,g);return await(await fetch(a.pathname,{body:c,method:"POST",headers:A})).text()}}else{let a=await fetch(`${Bn.basehost?Bn.basehost:""}/_proxy`,{method:"POST",body:JSON.stringify([{url:e,body:n,headers:i}]),headers:{"content-type":"application/json"}}),c="";try{return c=await a.text(),JSON.parse(c)}catch{let l=null;try{l=JSON.stringify(JSON.parse(n),null,2)}catch{}return console.warn(` +`?o.insert.slice(0,-1):o.insert;(typeof s!="string"||s.length>0)&&cu(i,this,n,s,o.attributes||{})}else o.retain!==void 0?pp(i,this,n,o.retain,o.attributes||{}):o.delete!==void 0&&Ep(i,n,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,A,i){let n=[],r=new Map,o=this.doc,s="",I=this._start;function a(){if(s.length>0){let u={},l=!1;r.forEach((B,p)=>{l=!0,u[p]=B});let g={insert:s};l&&(g.attributes=u),n.push(g),s=""}}let c=()=>{for(;I!==null;){if(sr(I,t)||A!==void 0&&sr(I,A))switch(I.content.constructor){case YA:{let u=r.get("ychange");t!==void 0&&!sr(I,t)?(u===void 0||u.user!==I.id.client||u.type!=="removed")&&(a(),r.set("ychange",i?i("removed",I.id):{type:"removed"})):A!==void 0&&!sr(I,A)?(u===void 0||u.user!==I.id.client||u.type!=="added")&&(a(),r.set("ychange",i?i("added",I.id):{type:"added"})):u!==void 0&&(a(),r.delete("ychange")),s+=I.content.str;break}case VA:case on:{a();let u={insert:I.content.getContent()[0]};if(r.size>0){let l={};u.attributes=l,r.forEach((g,B)=>{l[B]=g})}n.push(u);break}case Me:sr(I,t)&&(a(),lr(r,I.content));break}I=I.right}a()};return t||A?Be(o,u=>{t&&Bu(u,t),A&&Bu(u,A),c()},"cleanup"):c(),n}insert(t,A,i){if(A.length<=0)return;let n=this.doc;n!==null?Be(n,r=>{let o=Aa(r,this,t);i||(i={},o.currentAttributes.forEach((s,I)=>{i[I]=s})),cu(r,this,o,A,i)}):this._pending.push(()=>this.insert(t,A,i))}insertEmbed(t,A,i={}){let n=this.doc;n!==null?Be(n,r=>{let o=Aa(r,this,t);cu(r,this,o,A,i)}):this._pending.push(()=>this.insertEmbed(t,A,i))}delete(t,A){if(A===0)return;let i=this.doc;i!==null?Be(i,n=>{Ep(n,Aa(n,this,t),A)}):this._pending.push(()=>this.delete(t,A))}format(t,A,i){if(A===0)return;let n=this.doc;n!==null?Be(n,r=>{let o=Aa(r,this,t);o.right!==null&&pp(r,this,o,A,i)}):this._pending.push(()=>this.format(t,A,i))}removeAttribute(t){this.doc!==null?Be(this.doc,A=>{ua(A,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,A){this.doc!==null?Be(this.doc,i=>{xu(i,this,t,A)}):this._pending.push(()=>this.setAttribute(t,A))}getAttribute(t){return Gu(this,t)}getAttributes(){return Pp(this)}_write(t){t.writeTypeRef(oS)}},Yk=e=>new _o,Ro=class{constructor(t,A=()=>!0){this._filter=A,this._root=t,this._currentNode=t._start,this._firstCall=!0}[Symbol.iterator](){return this}next(){let t=this._currentNode,A=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(A)))do if(A=t.content.type,!t.deleted&&(A.constructor===fa||A.constructor===ar)&&A._start!==null)t=A._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})}},ar=class e extends He{constructor(){super(),this._prelimContent=[]}get firstChild(){let t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,A){super._integrate(t,A),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(A=>A instanceof He?A.clone():A)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Ro(this,t)}querySelector(t){t=t.toUpperCase();let i=new Ro(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t).next();return i.done?null:i.value}querySelectorAll(t){return t=t.toUpperCase(),fA(new Ro(this,A=>A.nodeName&&A.nodeName.toUpperCase()===t))}_callObserver(t,A){pa(this,t,new Eu(this,A,t))}toString(){return Op(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,A={},i){let n=t.createDocumentFragment();return i!==void 0&&i._createAssociation(n,this),Vo(this,r=>{n.insertBefore(r.toDOM(t,A,i),null)}),n}insert(t,A){this.doc!==null?Be(this.doc,i=>{Vp(i,this,t,A)}):this._prelimContent.splice(t,0,...A)}insertAfter(t,A){if(this.doc!==null)Be(this.doc,i=>{let n=t&&t instanceof He?t._item:t;la(i,this,n,A)});else{let i=this._prelimContent,n=t===null?0:i.findIndex(r=>r===t)+1;if(n===0&&t!==null)throw dA("Reference item not found");i.splice(n,0,...A)}}delete(t,A=1){this.doc!==null?Be(this.doc,i=>{zp(i,this,t,A)}):this._prelimContent.splice(t,A)}toArray(){return Lp(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return bp(this,t)}slice(t=0,A=this.length){return Kp(this,t,A)}forEach(t){Vo(this,t)}_write(t){t.writeTypeRef(IS)}},Vk=e=>new ar,fa=class e extends ar{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,A){super._integrate(t,A),this._prelimAttrs.forEach((i,n)=>{this.setAttribute(n,i)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName),A=this.getAttributes();return Xh(A,(i,n)=>{typeof i=="string"&&t.setAttribute(n,i)}),t.insert(0,this.toArray().map(i=>i instanceof He?i.clone():i)),t}toString(){let t=this.getAttributes(),A=[],i=[];for(let s in t)i.push(s);i.sort();let n=i.length;for(let s=0;s0?" "+A.join(" "):"";return`<${r}${o}>${super.toString()}`}removeAttribute(t){this.doc!==null?Be(this.doc,A=>{ua(A,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,A){this.doc!==null?Be(this.doc,i=>{xu(i,this,t,A)}):this._prelimAttrs.set(t,A)}getAttribute(t){return Gu(this,t)}hasAttribute(t){return _p(this,t)}getAttributes(t){return t?qk(this,t):Pp(this)}toDOM(t=document,A={},i){let n=t.createElement(this.nodeName),r=this.getAttributes();for(let o in r){let s=r[o];typeof s=="string"&&n.setAttribute(o,s)}return Vo(this,o=>{n.appendChild(o.toDOM(t,A,i))}),i!==void 0&&i._createAssociation(n,this),n}_write(t){t.writeTypeRef(sS),t.writeKey(this.nodeName)}},zk=e=>new fa(e.readKey()),Eu=class extends Ir{constructor(t,A,i){super(t,i),this.childListChanged=!1,this.attributesChanged=new Set,A.forEach(n=>{n===null?this.childListChanged=!0:this.attributesChanged.add(n)})}},mu=class e extends zo{constructor(t){super(),this.hookName=t}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((A,i)=>{t.set(i,A)}),t}toDOM(t=document,A={},i){let n=A[this.hookName],r;return n!==void 0?r=n.createDom(this):r=document.createElement(this.hookName),r.setAttribute("data-yjs-hook",this.hookName),i!==void 0&&i._createAssociation(r,this),r}_write(t){t.writeTypeRef(aS),t.writeKey(this.hookName)}},Pk=e=>new mu(e.readKey()),yu=class e extends _o{get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(t=document,A,i){let n=t.createTextNode(this.toString());return i!==void 0&&i._createAssociation(n,this),n}toString(){return this.toDelta().map(t=>{let A=[];for(let n in t.attributes){let r=[];for(let o in t.attributes[n])r.push({key:o,value:t.attributes[n][o]});r.sort((o,s)=>o.keyn.nodeName=0;n--)i+=``;return i}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(cS)}},_k=e=>new yu,To=class{constructor(t,A){this.id=t,this.length=A}get deleted(){throw tA()}mergeWith(t){return!1}write(t,A,i){throw tA()}integrate(t,A){throw tA()}},Tk=0,ht=class extends To{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,A){A>0&&(this.id.clock+=A,this.length-=A),Hp(t.doc.store,this)}write(t,A){t.writeInfo(Tk),t.writeLen(this.length-A)}getMissing(t,A){return null}},Xo=class e{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(t){throw tA()}mergeWith(t){return!1}integrate(t,A){}delete(t){}gc(t){}write(t,A){t.writeBuf(this.content)}getRef(){return 3}},Xk=e=>new Xo(e.readBuf()),da=class e{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let A=new e(this.len-t);return this.len=t,A}mergeWith(t){return this.len+=t.len,!0}integrate(t,A){ra(t.deleteSet,A.id.client,A.id.clock,this.len),A.markDeleted()}delete(t){}gc(t){}write(t,A){t.writeLen(this.len-A)}getRef(){return 1}},Zk=e=>new da(e.readLen()),jp=(e,t)=>new Lo({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),Zo=class e{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;let A={};this.opts=A,t.gc||(A.gc=!1),t.autoLoad&&(A.autoLoad=!0),t.meta!==null&&(A.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(jp(this.doc.guid,this.opts))}splice(t){throw tA()}mergeWith(t){return!1}integrate(t,A){this.doc._item=A,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,A){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}},Wk=e=>new Zo(jp(e.readString(),e.readAny())),on=class e{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(t){throw tA()}mergeWith(t){return!1}integrate(t,A){}delete(t){}gc(t){}write(t,A){t.writeJSON(this.embed)}getRef(){return 5}},jk=e=>new on(e.readJSON()),Me=class e{constructor(t,A){this.key=t,this.value=A}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(t){throw tA()}mergeWith(t){return!1}integrate(t,A){let i=A.parent;i._searchMarker=null,i._hasFormatting=!0}delete(t){}gc(t){}write(t,A){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}},$k=e=>new Me(e.readKey(),e.readJSON()),wu=class e{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let A=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),A}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,A){}delete(t){}gc(t){}write(t,A){let i=this.arr.length;t.writeLen(i-A);for(let n=A;n{let t=e.readLen(),A=[];for(let i=0;i{let t=e.readLen(),A=[];for(let i=0;i=55296&&i<=56319&&(this.str=this.str.slice(0,t-1)+"\uFFFD",A.str="\uFFFD"+A.str.slice(1)),A}mergeWith(t){return this.str+=t.str,!0}integrate(t,A){}delete(t){}gc(t){}write(t,A){t.writeString(A===0?this.str:this.str.slice(A))}getRef(){return 4}},AS=e=>new YA(e.readString()),iS=[Rk,Kk,Yk,zk,Vk,Pk,_k],nS=0,rS=1,oS=2,sS=3,IS=4,aS=5,cS=6,VA=class e{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(t){throw tA()}mergeWith(t){return!1}integrate(t,A){this.type._integrate(t.doc,A)}delete(t){let A=this.type._start;for(;A!==null;)A.deleted?A.id.clock<(t.beforeState.get(A.id.client)||0)&&t._mergeStructs.push(A):A.delete(t),A=A.right;this.type._map.forEach(i=>{i.deleted?i.id.clock<(t.beforeState.get(i.id.client)||0)&&t._mergeStructs.push(i):i.delete(t)}),t.changed.delete(this.type)}gc(t){let A=this.type._start;for(;A!==null;)A.gc(t,!0),A=A.right;this.type._start=null,this.type._map.forEach(i=>{for(;i!==null;)i.gc(t,!0),i=i.left}),this.type._map=new Map}write(t,A){this.type._write(t)}getRef(){return 7}},gS=e=>new VA(iS[e.readTypeRef()](e));var Qa=(e,t,A)=>{let{client:i,clock:n}=t.id,r=new Le(ee(i,n+A),t,ee(i,n+A-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(A));return t.deleted&&r.markDeleted(),t.keep&&(r.keep=!0),t.redone!==null&&(r.redone=ee(t.redone.client,t.redone.clock+A)),t.right=r,r.right!==null&&(r.right.left=r),e._mergeStructs.push(r),r.parentSub!==null&&r.right===null&&r.parent._map.set(r.parentSub,r),t.length=A,r};var Le=class e extends To{constructor(t,A,i,n,r,o,s,I){super(t,I.getLength()),this.origin=i,this.left=A,this.right=n,this.rightOrigin=r,this.parent=o,this.parentSub=s,this.redone=null,this.content=I,this.info=this.content.isCountable()?2:0}set marker(t){(this.info&8)>0!==t&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(t){this.keep!==t&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(t){this.deleted!==t&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,A){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=Ke(A,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=Ke(A,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===yi&&this.id.client!==this.parent.client&&this.parent.clock>=Ke(A,this.parent.client))return this.parent.client;if(this.origin&&(this.left=fp(t,A,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Fi(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===ht||this.right&&this.right.constructor===ht)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===yi){let i=au(A,this.parent);i.constructor===ht?this.parent=null:this.parent=i.content.type}return null}integrate(t,A){if(A>0&&(this.id.clock+=A,this.left=fp(t,t.doc.store,ee(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(A),this.length-=A),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let i=this.left,n;if(i!==null)n=i.right;else if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start;let r=new Set,o=new Set;for(;n!==null&&n!==this.right;){if(o.add(n),r.add(n),ea(this.origin,n.origin)){if(n.id.client{i.p===t&&(i.p=this,!this.deleted&&this.countable&&(i.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){let A=this.parent;this.countable&&this.parentSub===null&&(A._length-=this.length),this.markDeleted(),ra(t.deleteSet,this.id.client,this.id.clock,this.length),Qp(t,A,this.parentSub),this.content.delete(t)}}gc(t,A){if(!this.deleted)throw AA();this.content.gc(t),A?yk(t,this,new ht(this.id,this.length)):this.content=new da(this.length)}write(t,A){let i=A>0?ee(this.id.client,this.id.clock+A-1):this.origin,n=this.rightOrigin,r=this.parentSub,o=this.content.getRef()&31|(i===null?0:128)|(n===null?0:64)|(r===null?0:32);if(t.writeInfo(o),i!==null&&t.writeLeftID(i),n!==null&&t.writeRightID(n),i===null&&n===null){let s=this.parent;if(s._item!==void 0){let I=s._item;if(I===null){let a=pk(s);t.writeParentInfo(!0),t.writeString(a)}else t.writeParentInfo(!1),t.writeLeftID(I.id)}else s.constructor===String?(t.writeParentInfo(!0),t.writeString(s)):s.constructor===yi?(t.writeParentInfo(!1),t.writeLeftID(s)):AA();r!==null&&t.writeString(r)}this.content.write(t,A)}},$p=(e,t)=>lS[t&31](e),lS=[()=>{AA()},Zk,eS,Xk,AS,jk,$k,gS,tS,Wk,()=>{AA()}],uS=10,pt=class extends To{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,A){AA()}write(t,A){t.writeInfo(uS),Z(t.restEncoder,this.length-A)}getMissing(t,A){return null}},eE=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},tE="__ $YJS$ __";eE[tE]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");eE[tE]=!0;var Ea={proxies:new WeakMap,traps:new WeakMap},AE=(e,t,A)=>e.get(t)||e.set(t,new A).get(t),iE=e=>e.join(),nE=(e,t,A,i,n)=>{AE(AE(Ea.traps,e,WeakMap),t,Map).set(iE(A),i),Ea.proxies.set(i,n)},Hu=(e,t,A)=>{var i,n;return Ea.proxies.get((n=(i=Ea.traps.get(e))===null||i===void 0?void 0:i.get(t))===null||n===void 0?void 0:n.get(iE(A)))};var fS=Symbol("default"),dS=Object.keys(Object.getOwnPropertyDescriptors(Reflect)),QS=["get","has","set","defineProperty","deleteProperty","getOwnPropertyDescriptor"],CS=(e,t)=>{let A,i,n,r,o,s,I,a;switch(e){case"get":[A,i,r]=t;break;case"set":[A,i,n,r]=t;break;case"deleteProperty":case"defineProperty":[A,s]=t;break;case"has":case"getOwnPropertyDescriptor":[A,i]=t;break;case"apply":[A,I,o]=t;break;case"construct":[A,o]=t;break;case"setPrototypeOf":[A,a]=t;break;default:[A]=t}return{target:A,name:i,receiver:r,val:n,args:o,descriptor:s,thisValue:I,prototype:a}},hS=(e,t)=>{let{trapName:A,handler:i,traps:n,root:r,path:o}=e,{target:s,name:I,val:a,receiver:c,args:u,descriptor:l,thisValue:g,prototype:B}=CS(A,t),p=QS.includes(A)?I:void 0;return{parameters:t,target:s,name:I,val:a,args:u,descriptor:l,receiver:c,thisValue:g,prototype:B,trapName:A,traps:n,path:o,handler:i,key:p,newValue:A==="set"?a:void 0,root:r,get proxy(){return Hu(r,s,o)},get value(){return p&&s[p]},DEFAULT:fS,PROXY:rE.bind({root:r,handler:i,path:[...o,p]})}},pS=function(...e){let{trapName:t,handler:A}=this,i=hS(this,e),{PROXY:n,DEFAULT:r}=i,o=A(i);return o===n?n(i.value):o===r?Reflect[t](...e):o},ES=(e,t,A)=>dS.reduce((i,n)=>(i[n]=pS.bind({trapName:n,handler:e,traps:i,root:t,path:A}),i),{}),mS=e=>{if(e===null||typeof e!="object"&&typeof e!="function")throw new TypeError("Deep proxy could be applied to objects and functions only")},yS=({DEFAULT:e})=>e,rE=function(e,t,A,i){mS(e);let n=Object.assign({},this),r=t||n.handler||yS,o=A||n.path||[],s=n.root||i||e,I=Hu(s,e,o);if(I)return I;let a=ES(r,s,o),c=new Proxy(e,a);return nE(s,e,o,a,c),c},oE=class{constructor(e,t,A,i){return rE(e,t,A,i)}};function $o(e,t,A,i){function n(r){return r instanceof A?r:new A(function(o){o(r)})}return new(A||(A=Promise))(function(r,o){function s(c){try{a(i.next(c))}catch(u){o(u)}}function I(c){try{a(i.throw(c))}catch(u){o(u)}}function a(c){c.done?r(c.value):n(c.value).then(s,I)}a((i=i.apply(e,t||[])).next())})}var he=class{constructor(){this.mutex=Promise.resolve()}lock(){let t=()=>{};return this.mutex=this.mutex.then(()=>new Promise(t)),new Promise(A=>{t=A})}dispatch(t){return $o(this,void 0,void 0,function*(){let A=yield this.lock();try{return yield Promise.resolve(t())}finally{A()}})}},Mu;function wS(){return typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global}var qu=wS(),vu=(Mu=qu.Buffer)!==null&&Mu!==void 0?Mu:null,FS=qu.TextEncoder?new qu.TextEncoder:null;function uE(e,t){return(e&15)+(e>>6|e>>3&8)<<4|(t&15)+(t>>6|t>>3&8)}function DS(e,t){let A=t.length>>1;for(let i=0;i>>4;e[i++]=r>9?r+sE:r+IE,r=t[n]&15,e[i++]=r>9?r+sE:r+IE}return String.fromCharCode.apply(null,e)}var cE=vu!==null?e=>{if(typeof e=="string"){let t=vu.from(e,"utf8");return new Uint8Array(t.buffer,t.byteOffset,t.length)}if(vu.isBuffer(e))return new Uint8Array(e.buffer,e.byteOffset,e.length);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Invalid data type!")}:e=>{if(typeof e=="string")return FS.encode(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Invalid data type!")},gE="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",jo=new Uint8Array(256);for(let e=0;e>4,n+=1,i[n]=(s&15)<<4|I>>2,n+=1,i[n]=(I&3)<<6|a&63,n+=1}return i}var ma=16*1024,Wo=4,NS=new he,Ju=new Map;function xS(e,t){return $o(this,void 0,void 0,function*(){let A=null,i=null,n=!1;if(typeof WebAssembly>"u")throw new Error("WebAssembly is not supported in this environment!");let r=(w,D=0)=>{i.set(w,D)},o=()=>i,s=()=>A.exports,I=w=>{A.exports.Hash_SetMemorySize(w);let D=A.exports.Hash_GetBuffer(),S=A.exports.memory.buffer;i=new Uint8Array(S,D,w)},a=()=>new DataView(A.exports.memory.buffer).getUint32(A.exports.STATE_SIZE,!0),c=NS.dispatch(()=>$o(this,void 0,void 0,function*(){if(!Ju.has(e.name)){let D=US(e.data),S=WebAssembly.compile(D);Ju.set(e.name,S)}let w=yield Ju.get(e.name);A=yield WebAssembly.instantiate(w,{})})),u=()=>$o(this,void 0,void 0,function*(){A||(yield c);let w=A.exports.Hash_GetBuffer(),D=A.exports.memory.buffer;i=new Uint8Array(D,w,ma)}),l=(w=null)=>{n=!0,A.exports.Hash_Init(w)},g=w=>{let D=0;for(;D{if(!n)throw new Error("update() called before init()");let D=cE(w);g(D)},p=new Uint8Array(t*2),U=(w,D=null)=>{if(!n)throw new Error("digest() called before init()");return n=!1,A.exports.Hash_Final(D),w==="binary"?i.slice(0,t):aE(p,i,t)},d=()=>{if(!n)throw new Error("save() can only be called after init() and before digest()");let w=A.exports.Hash_GetState(),D=a(),S=A.exports.memory.buffer,K=new Uint8Array(S,w,D),q=new Uint8Array(Wo+D);return DS(q,e.hash),q.set(K,Wo),q},f=w=>{if(!(w instanceof Uint8Array))throw new Error("load() expects an Uint8Array generated by save()");let D=A.exports.Hash_GetState(),S=a(),K=Wo+S,q=A.exports.memory.buffer;if(w.length!==K)throw new Error(`Bad state length (expected ${K} bytes, got ${w.length})`);if(!kS(e.hash,w.subarray(0,Wo)))throw new Error("This state was written by an incompatible hash implementation");let X=w.subarray(Wo);new Uint8Array(q,D,S).set(X),n=!0},Q=w=>typeof w=="string"?w.length!0;break;case"blake2b":case"blake2s":y=(w,D)=>D<=512&&Q(w);break;case"blake3":y=(w,D)=>D===0&&Q(w);break;case"xxhash64":case"xxhash3":case"xxhash128":y=()=>!1;break}let F=(w,D=null,S=null)=>{if(!y(w,D))return l(D),B(w),U("hex",S);let K=cE(w);return i.set(K),A.exports.Hash_Calculate(K.length,D,S),aE(p,i,t)};return yield u(),{getMemory:o,writeMemory:r,getExports:s,setMemorySize:I,init:l,update:B,digest:U,save:d,load:f,calculate:F,hashLength:t}})}function GS(e,t,A){return $o(this,void 0,void 0,function*(){let i=yield e.lock(),n=yield xS(t,A);return i(),n})}var aG=new he;var cG=new he;var gG=new DataView(new ArrayBuffer(4));var lG=new he;var uG=new he;var BG=new he;var fG=new he;var dG=new he;var QG=new he;var CG=new he;var hG=new he;var pG=new he;var EG=new he;var mG=new he;var yG=new he;var wG=new he;var HS="xxhash32",MS="AGFzbQEAAAABEQRgAAF/YAF/AGAAAGACf38AAwcGAAEBAgADBQQBAQICBg4CfwFBsIkFC38AQYAICwdwCAZtZW1vcnkCAA5IYXNoX0dldEJ1ZmZlcgAACUhhc2hfSW5pdAABC0hhc2hfVXBkYXRlAAIKSGFzaF9GaW5hbAADDUhhc2hfR2V0U3RhdGUABA5IYXNoX0NhbGN1bGF0ZQAFClNUQVRFX1NJWkUDAQqxEAYFAEGACQtNAEEAQgA3A6iJAUEAIAA2AoiJAUEAIABBz4yijgZqNgKMiQFBACAAQfeUr694ajYChIkBQQAgAEGoiI2hAmo2AoCJAUEAQQA2AqCJAQu4CAEHfwJAIABFDQBBAEEAKQOoiQEgAK18NwOoiQECQEEAKAKgiQEiASAAakEPSw0AAkACQCAAQQNxIgINAEGACSEDIAAhBAwBCyAAQXxxIQRBgAkhAwNAQQBBACgCoIkBIgVBAWo2AqCJASAFQZCJAWogAy0AADoAACADQQFqIQMgAkF/aiICDQALCyAAQQRJDQEDQEEAQQAoAqCJASICQQFqNgKgiQEgAkGQiQFqIAMtAAA6AAAgA0EBai0AACECQQBBACgCoIkBIgVBAWo2AqCJASAFQZCJAWogAjoAACADQQJqLQAAIQJBAEEAKAKgiQEiBUEBajYCoIkBIAVBkIkBaiACOgAAIANBA2otAAAhAkEAQQAoAqCJASIFQQFqNgKgiQEgBUGQiQFqIAI6AAAgA0EEaiEDIARBfGoiBA0ADAILCyAAQfAIaiEGAkACQCABDQBBACgCjIkBIQJBACgCiIkBIQVBACgChIkBIQRBACgCgIkBIQFBgAkhAwwBC0GACSEDAkAgAUEPSw0AQYAJIQMCQAJAQQAgAWtBA3EiBA0AIAEhBQwBCyABIQIDQEEAIAJBAWoiBTYCoIkBIAJBkIkBaiADLQAAOgAAIANBAWohAyAFIQIgBEF/aiIEDQALCyABQXNqQQNJDQBBACEEA0AgAyAEaiIBLQAAIQdBACAFIARqIgJBAWo2AqCJASACQZCJAWogBzoAACABQQFqLQAAIQdBACACQQJqNgKgiQEgAkGRiQFqIAc6AAAgAUECai0AACEHQQAgAkEDajYCoIkBIAJBkokBaiAHOgAAIAFBA2otAAAhAUEAIAJBBGo2AqCJASACQZOJAWogAToAACAFIARBBGoiBGpBEEcNAAsgAyAEaiEDC0EAQQAoApCJAUH3lK+veGxBACgCgIkBakENd0Gx893xeWwiATYCgIkBQQBBACgClIkBQfeUr694bEEAKAKEiQFqQQ13QbHz3fF5bCIENgKEiQFBAEEAKAKYiQFB95Svr3hsQQAoAoiJAWpBDXdBsfPd8XlsIgU2AoiJAUEAQQAoApyJAUH3lK+veGxBACgCjIkBakENd0Gx893xeWwiAjYCjIkBCyAAQYAJaiEAAkAgAyAGSw0AA0AgAygCAEH3lK+veGwgAWpBDXdBsfPd8XlsIQEgA0EMaigCAEH3lK+veGwgAmpBDXdBsfPd8XlsIQIgA0EIaigCAEH3lK+veGwgBWpBDXdBsfPd8XlsIQUgA0EEaigCAEH3lK+veGwgBGpBDXdBsfPd8XlsIQQgA0EQaiIDIAZNDQALC0EAIAI2AoyJAUEAIAU2AoiJAUEAIAQ2AoSJAUEAIAE2AoCJAUEAIAAgA2s2AqCJASAAIANGDQBBACECA0AgAkGQiQFqIAMgAmotAAA6AAAgAkEBaiICQQAoAqCJAUkNAAsLC6QDAgF+Bn9BACkDqIkBIgCnIQECQAJAIABCEFQNAEEAKAKEiQFBB3dBACgCgIkBQQF3akEAKAKIiQFBDHdqQQAoAoyJAUESd2ohAgwBC0EAKAKIiQFBsc/ZsgFqIQILIAIgAWohAkGQiQEhAwJAQQAoAqCJASIEQZCJAWoiBUGUiQFJDQBBkIkBIQEDQCABKAIAQb3cypV8bCACakERd0Gv1tO+AmwhAiABQQhqIQYgAUEEaiIDIQEgBiAFTQ0ACwsCQCADIAVGDQAgBEGPiQFqIQYCQAJAIAQgA2tBAXENACADIQEMAQsgA0EBaiEBIAMtAABBsc/ZsgFsIAJqQQt3QbHz3fF5bCECCyAGIANGDQADQCABQQFqLQAAQbHP2bIBbCABLQAAQbHP2bIBbCACakELd0Gx893xeWxqQQt3QbHz3fF5bCECIAFBAmoiASAFRw0ACwtBACACQQ92IAJzQfeUr694bCIBQQ12IAFzQb3cypV8bCIBQRB2IAFzIgJBGHQgAkGA/gNxQQh0ciABQQh2QYD+A3EgAUEYdnJyrTcDgAkLBgBBgIkBC/MDAgF+BH9BAEIANwOoiQFBACABNgKIiQFBACABQc+Moo4GajYCjIkBQQAgAUH3lK+veGo2AoSJAUEAIAFBqIiNoQJqNgKAiQFBAEEANgKgiQEgABACQQApA6iJASICpyEBAkACQCACQhBUDQBBACgChIkBQQd3QQAoAoCJAUEBd2pBACgCiIkBQQx3akEAKAKMiQFBEndqIQAMAQtBACgCiIkBQbHP2bIBaiEACyAAIAFqIQBBkIkBIQMCQEEAKAKgiQEiBEGQiQFqIgVBlIkBSQ0AQZCJASEBA0AgASgCAEG93MqVfGwgAGpBEXdBr9bTvgJsIQAgAUEIaiEGIAFBBGoiAyEBIAYgBU0NAAsLAkAgAyAFRg0AIARBj4kBaiEGAkACQCAEIANrQQFxDQAgAyEBDAELIANBAWohASADLQAAQbHP2bIBbCAAakELd0Gx893xeWwhAAsgBiADRg0AA0AgAUEBai0AAEGxz9myAWwgAS0AAEGxz9myAWwgAGpBC3dBsfPd8XlsakELd0Gx893xeWwhACABQQJqIgEgBUcNAAsLQQAgAEEPdiAAc0H3lK+veGwiAUENdiABc0G93MqVfGwiAUEQdiABcyIAQRh0IABBgP4DcUEIdHIgAUEIdkGA/gNxIAFBGHZycq03A4AJCwsLAQBBgAgLBDAAAAA=",vS="9e3a00cd",JS={name:HS,data:MS,hash:vS},qS=new he,ya=null;function lE(e){return!Number.isInteger(e)||e<0||e>4294967295?new Error("Seed must be a valid 32-bit long unsigned integer."):null}function wa(e,t=0){if(lE(t))return Promise.reject(lE(t));if(ya===null)return GS(qS,JS,4).then(A=>(ya=A,ya.calculate(e,t)));try{let A=ya.calculate(e,t);return Promise.resolve(A)}catch(A){return Promise.reject(A)}}var FG=new he;var DG=new ArrayBuffer(8);var kG=new he;var SG=new ArrayBuffer(8);var UG=new he;var NG=new ArrayBuffer(8);var xG=new he;var GG=new he;var HG=new he;function Ku(e){return new Promise((t,A)=>{e.oncomplete=e.onsuccess=()=>t(e.result),e.onabort=e.onerror=()=>A(e.error)})}function sn(e,t){let A=indexedDB.open(e);A.onupgradeneeded=()=>A.result.createObjectStore(t);let i=Ku(A);return(n,r)=>i.then(o=>r(o.transaction(t,n).objectStore(t)))}var Ru;function BE(){return Ru||(Ru=sn("keyval-store","keyval")),Ru}function EA(e,t=BE()){return t("readonly",A=>Ku(A.get(e)))}function mA(e,t,A=BE()){return A("readwrite",i=>(i.put(t,e),Ku(i.transaction)))}var Ou;try{Ou=new TextDecoder}catch{}var G,Ot,C=0;var DE=[],bu=DE,Yu=0,Ee={},te,Di,Lt=0,yA=0,be,zA,Et=[],j,fE={useRecords:!1,mapsAsObjects:!0},es=class{},zu=new es;zu.name="MessagePack 0xC1";var ki=!1,kE=2,dE,QE,CE;try{new Function("")}catch{kE=1/0}var an=class e{constructor(t){t&&(t.useRecords===!1&&t.mapsAsObjects===void 0&&(t.mapsAsObjects=!0),t.sequential&&t.trusted!==!1&&(t.trusted=!0,!t.structures&&t.useRecords!=!1&&(t.structures=[],t.maxSharedStructures||(t.maxSharedStructures=0))),t.structures?t.structures.sharedLength=t.structures.length:t.getStructures&&((t.structures=[]).uninitialized=!0,t.structures.sharedLength=0),t.int64AsNumber&&(t.int64AsType="number")),Object.assign(this,t)}unpack(t,A){if(G)return xE(()=>(Da(),this?this.unpack(t,A):e.prototype.unpack.call(fE,t,A)));!t.buffer&&t.constructor===ArrayBuffer&&(t=typeof Buffer<"u"?Buffer.from(t):new Uint8Array(t)),typeof A=="object"?(Ot=A.end||t.length,C=A.start||0):(C=0,Ot=A>-1?A:t.length),Yu=0,yA=0,Di=null,bu=DE,be=null,G=t;try{j=t.dataView||(t.dataView=new DataView(t.buffer,t.byteOffset,t.byteLength))}catch(i){throw G=null,t instanceof Uint8Array?i:new Error("Source must be a Uint8Array or Buffer but was a "+(t&&typeof t=="object"?t.constructor.name:typeof t))}if(this instanceof e){if(Ee=this,this.structures)return te=this.structures,Fa(A);(!te||te.length>0)&&(te=[])}else Ee=fE,(!te||te.length>0)&&(te=[]);return Fa(A)}unpackMultiple(t,A){let i,n=0;try{ki=!0;let r=t.length,o=this?this.unpack(t,r):Sa.unpack(t,r);if(A){if(A(o,n,C)===!1)return;for(;Ci.slice(0)));for(let i=0,n=t.length;i=32&&(r.highByte=i-32>>5))}t.sharedLength=t.length;for(let i in A||[])if(i>=0){let n=t[i],r=A[i];r&&(n&&((t.restoreStructures||(t.restoreStructures=[]))[i]=n),t[i]=r)}return this.structures=t}decode(t,A){return this.unpack(t,A)}};function Fa(e){try{if(!Ee.trusted&&!ki){let A=te.sharedLength||0;A=32&&dE?(t=dE(G,C,Ot,Ee),G=null,!(e&&e.lazy)&&t&&(t=t.toJSON()),C=Ot):t=Se(),be&&(C=be.postBundlePosition,be=null),ki&&(te.restoreStructures=null),C==Ot)te&&te.restoreStructures&&hE(),te=null,G=null,zA&&(zA=null);else{if(C>Ot)throw new Error("Unexpected end of MessagePack data");if(!ki){let A;try{A=JSON.stringify(t,(i,n)=>typeof n=="bigint"?`${n}n`:n).slice(0,100)}catch(i){A="(JSON view not available "+i+")"}throw new Error("Data read, but end of buffer not reached "+A)}}return t}catch(t){throw te&&te.restoreStructures&&hE(),Da(),(t instanceof RangeError||t.message.startsWith("Unexpected end of buffer")||C>Ot)&&(t.incomplete=!0),t}}function hE(){for(let e in te.restoreStructures)te[e]=te.restoreStructures[e];te.restoreStructures=null}function Se(){let e=G[C++];if(e<160)if(e<128){if(e<64)return e;{let t=te[e&63]||Ee.getStructures&&SE()[e&63];return t?(t.read||(t.read=Pu(t,e&63)),t.read()):e}}else if(e<144)if(e-=128,Ee.mapsAsObjects){let t={};for(let A=0;A=C)return Di.slice(C-Lt,(C+=t)-Lt);if(yA==0&&Ot<140){let A=t<16?_u(t):UE(t);if(A!=null)return A}return Vu(t)}else{let t;switch(e){case 192:return null;case 193:return be?(t=Se(),t>0?be[1].slice(be.position1,be.position1+=t):be[0].slice(be.position0,be.position0-=t)):zu;case 194:return!1;case 195:return!0;case 196:if(t=G[C++],t===void 0)throw new Error("Unexpected end of buffer");return Lu(t);case 197:return t=j.getUint16(C),C+=2,Lu(t);case 198:return t=j.getUint32(C),C+=4,Lu(t);case 199:return In(G[C++]);case 200:return t=j.getUint16(C),C+=2,In(t);case 201:return t=j.getUint32(C),C+=4,In(t);case 202:if(t=j.getFloat32(C),Ee.useFloat32>2){let A=ka[(G[C]&127)<<1|G[C+1]>>7];return C+=4,(A*t+(t>0?.5:-.5)>>0)/A}return C+=4,t;case 203:return t=j.getFloat64(C),C+=8,t;case 204:return G[C++];case 205:return t=j.getUint16(C),C+=2,t;case 206:return t=j.getUint32(C),C+=4,t;case 207:return Ee.int64AsType==="number"?(t=j.getUint32(C)*4294967296,t+=j.getUint32(C+4)):Ee.int64AsType==="string"?t=j.getBigUint64(C).toString():Ee.int64AsType==="auto"?(t=j.getBigUint64(C),t<=BigInt(2)<=BigInt(-2)<=C?Di.slice(C-Lt,(C+=t)-Lt):KS(t);case 218:return t=j.getUint16(C),C+=2,yA>=C?Di.slice(C-Lt,(C+=t)-Lt):LS(t);case 219:return t=j.getUint32(C),C+=4,yA>=C?Di.slice(C-Lt,(C+=t)-Lt):OS(t);case 220:return t=j.getUint16(C),C+=2,EE(t);case 221:return t=j.getUint32(C),C+=4,EE(t);case 222:return t=j.getUint16(C),C+=2,mE(t);case 223:return t=j.getUint32(C),C+=4,mE(t);default:if(e>=224)return e-256;if(e===void 0){let A=new Error("Unexpected end of MessagePack data");throw A.incomplete=!0,A}throw new Error("Unknown MessagePack token "+e)}}}var RS=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function Pu(e,t){function A(){if(A.count++>kE){let n=e.read=new Function("r","return function(){return "+(Ee.freezeData?"Object.freeze":"")+"({"+e.map(r=>r==="__proto__"?"__proto_:r()":RS.test(r)?r+":r()":"["+JSON.stringify(r)+"]:r()").join(",")+"})}")(Se);return e.highByte===0&&(e.read=pE(t,e.read)),n()}let i={};for(let n=0,r=e.length;nfunction(){let A=G[C++];if(A===0)return t();let i=e<32?-(e+(A<<5)):e+(A<<5),n=te[i]||SE()[i];if(!n)throw new Error("Record id is not defined for "+i);return n.read||(n.read=Pu(n,e)),n.read()};function SE(){let e=xE(()=>(G=null,Ee.getStructures()));return te=Ee._mergeStructures(e,te)}var Vu=ts,KS=ts,LS=ts,OS=ts;function ts(e){let t;if(e<16&&(t=_u(e)))return t;if(e>64&&Ou)return Ou.decode(G.subarray(C,C+=e));let A=C+e,i=[];for(t="";C65535&&(I-=65536,i.push(I>>>10&1023|55296),I=56320|I&1023),i.push(I)}else i.push(n);i.length>=4096&&(t+=Oe.apply(String,i),i.length=0)}return i.length>0&&(t+=Oe.apply(String,i)),t}function EE(e){let t=new Array(e);for(let A=0;A0){C=t;return}A[i]=n}return Oe.apply(String,A)}function _u(e){if(e<4)if(e<2){if(e===0)return"";{let t=G[C++];if((t&128)>1){C-=1;return}return Oe(t)}}else{let t=G[C++],A=G[C++];if((t&128)>0||(A&128)>0){C-=2;return}if(e<3)return Oe(t,A);let i=G[C++];if((i&128)>0){C-=3;return}return Oe(t,A,i)}else{let t=G[C++],A=G[C++],i=G[C++],n=G[C++];if((t&128)>0||(A&128)>0||(i&128)>0||(n&128)>0){C-=4;return}if(e<6){if(e===4)return Oe(t,A,i,n);{let r=G[C++];if((r&128)>0){C-=5;return}return Oe(t,A,i,n,r)}}else if(e<8){let r=G[C++],o=G[C++];if((r&128)>0||(o&128)>0){C-=6;return}if(e<7)return Oe(t,A,i,n,r,o);let s=G[C++];if((s&128)>0){C-=7;return}return Oe(t,A,i,n,r,o,s)}else{let r=G[C++],o=G[C++],s=G[C++],I=G[C++];if((r&128)>0||(o&128)>0||(s&128)>0||(I&128)>0){C-=8;return}if(e<10){if(e===8)return Oe(t,A,i,n,r,o,s,I);{let a=G[C++];if((a&128)>0){C-=9;return}return Oe(t,A,i,n,r,o,s,I,a)}}else if(e<12){let a=G[C++],c=G[C++];if((a&128)>0||(c&128)>0){C-=10;return}if(e<11)return Oe(t,A,i,n,r,o,s,I,a,c);let u=G[C++];if((u&128)>0){C-=11;return}return Oe(t,A,i,n,r,o,s,I,a,c,u)}else{let a=G[C++],c=G[C++],u=G[C++],l=G[C++];if((a&128)>0||(c&128)>0||(u&128)>0||(l&128)>0){C-=12;return}if(e<14){if(e===12)return Oe(t,A,i,n,r,o,s,I,a,c,u,l);{let g=G[C++];if((g&128)>0){C-=13;return}return Oe(t,A,i,n,r,o,s,I,a,c,u,l,g)}}else{let g=G[C++],B=G[C++];if((g&128)>0||(B&128)>0){C-=14;return}if(e<15)return Oe(t,A,i,n,r,o,s,I,a,c,u,l,g,B);let p=G[C++];if((p&128)>0){C-=15;return}return Oe(t,A,i,n,r,o,s,I,a,c,u,l,g,B,p)}}}}}function yE(){let e=G[C++],t;if(e<192)t=e-160;else switch(e){case 217:t=G[C++];break;case 218:t=j.getUint16(C),C+=2;break;case 219:t=j.getUint32(C),C+=4;break;default:throw new Error("Expected string")}return ts(t)}function Lu(e){return Ee.copyBuffers?Uint8Array.prototype.slice.call(G,C,C+=e):G.subarray(C,C+=e)}function In(e){let t=G[C++];if(Et[t]){let A;return Et[t](G.subarray(C,A=C+=e),i=>{C=i;try{return Se()}finally{C=A}})}else throw new Error("Unknown extension type "+t)}var wE=new Array(4096);function NE(){let e=G[C++];if(e>=160&&e<192){if(e=e-160,yA>=C)return Di.slice(C-Lt,(C+=e)-Lt);if(!(yA==0&&Ot<180))return Vu(e)}else return C--,Se().toString();let t=(e<<5^(e>1?j.getUint16(C):e>0?G[C]:0))&4095,A=wE[t],i=C,n=C+e-3,r,o=0;if(A&&A.bytes==e){for(;i{let A=Se().map(r=>r.toString()),i=e;t!==void 0&&(e=e<32?-((t<<5)+e):(t<<5)+e,A.highByte=t);let n=te[e];return n&&(n.isShared||ki)&&((te.restoreStructures||(te.restoreStructures=[]))[e]=n),te[e]=A,A.read=Pu(A,i),A.read()};Et[0]=()=>{};Et[0].noBuffer=!0;Et[66]=e=>{let t=e.length,A=BigInt(e[0]&128?e[0]-256:e[0]);for(let i=1;i{let e=Se();return(bS[e[0]]||Error)(e[1])};Et[105]=e=>{let t=j.getUint32(C-4);zA||(zA=new Map);let A=G[C],i;A>=144&&A<160||A==220||A==221?i=[]:i={};let n={target:i};zA.set(t,n);let r=Se();return n.used?Object.assign(i,r):(n.target=r,r)};Et[112]=e=>{let t=j.getUint32(C-4),A=zA.get(t);return A.used=!0,A.target};Et[115]=()=>new Set(Se());var Tu=["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map(e=>e+"Array"),YS=typeof globalThis=="object"?globalThis:window;Et[116]=e=>{let t=e[0],A=Tu[t];if(!A)throw new Error("Could not find typed array for code "+t);return new YS[A](Uint8Array.prototype.slice.call(e,1).buffer)};Et[120]=()=>{let e=Se();return new RegExp(e[0],e[1])};var VS=[];Et[98]=e=>{let t=(e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3],A=C;return C+=t-e.length,be=VS,be=[yE(),yE()],be.position0=0,be.position1=0,be.postBundlePosition=C,C=A,Se()};Et[255]=e=>e.length==4?new Date((e[0]*16777216+(e[1]<<16)+(e[2]<<8)+e[3])*1e3):e.length==8?new Date(((e[0]<<22)+(e[1]<<14)+(e[2]<<6)+(e[3]>>2))/1e6+((e[3]&3)*4294967296+e[4]*16777216+(e[5]<<16)+(e[6]<<8)+e[7])*1e3):e.length==12?new Date(((e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3])/1e6+((e[4]&128?-281474976710656:0)+e[6]*1099511627776+e[7]*4294967296+e[8]*16777216+(e[9]<<16)+(e[10]<<8)+e[11])*1e3):new Date("invalid");function xE(e){CE&&CE();let t=Ot,A=C,i=Yu,n=Lt,r=yA,o=Di,s=bu,I=zA,a=be,c=new Uint8Array(G.slice(0,Ot)),u=te,l=te.slice(0,te.length),g=Ee,B=ki,p=e();return Ot=t,C=A,Yu=i,Lt=n,yA=r,Di=o,bu=s,zA=I,be=a,G=c,ki=B,te=u,te.splice(0,te.length,...l),Ee=g,j=new DataView(G.buffer,G.byteOffset,G.byteLength),p}function Da(){G=null,zA=null,te=null}var ka=new Array(147);for(let e=0;e<256;e++)ka[e]=+("1e"+Math.floor(45.15-e*.30103));var Sa=new an({useRecords:!1}),zS=Sa.unpack,PS=Sa.unpackMultiple,_S=Sa.unpack,Ua={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4},TS=new Float32Array(1),JG=new Uint8Array(TS.buffer,0,4);var xa;try{xa=new TextEncoder}catch{}var Xu,JE,Ga=typeof Buffer<"u",Na=Ga?function(e){return Buffer.allocUnsafeSlow(e)}:Uint8Array,qE=Ga?Buffer:Uint8Array,GE=Ga?4294967296:2144337920,E,As,ae,h=0,at,Fe=null,XS,ZS=21760,WS=/[\u0080-\uFFFF]/,ur=Symbol("record-id"),cn=class extends an{constructor(t){super(t),this.offset=0;let A,i,n,r,o,s=qE.prototype.utf8Write?function(m,J){return E.utf8Write(m,J,4294967295)}:xa&&xa.encodeInto?function(m,J){return xa.encodeInto(m,E.subarray(J)).written}:!1,I=this;t||(t={});let a=t&&t.sequential,c=t.structures||t.saveStructures,u=t.maxSharedStructures;if(u==null&&(u=c?32:0),u>8160)throw new Error("Maximum maxSharedStructure is 8160");t.structuredClone&&t.moreTypes==null&&(this.moreTypes=!0);let l=t.maxOwnStructures;l==null&&(l=c?32:64),!this.structures&&t.useRecords!=!1&&(this.structures=[]);let g=u>32||l+u>64,B=u+64,p=u+l+64;if(p>8256)throw new Error("Maximum maxSharedStructure + maxOwnStructure is 8192");let U=[],d=0,f=0;this.pack=this.encode=function(m,J){if(E||(E=new Na(8192),ae=E.dataView||(E.dataView=new DataView(E.buffer,0,8192)),h=0),at=E.length-10,at-h<2048?(E=new Na(E.length),ae=E.dataView||(E.dataView=new DataView(E.buffer,0,E.length)),at=E.length-10,h=0):h=h+7&2147483640,i=h,J&IU&&(h+=J&255),o=I.structuredClone?new Map:null,I.bundleStrings&&typeof m!="string"?(Fe=[],Fe.size=1/0):Fe=null,r=I.structures,r){r.uninitialized&&(r=I._mergeStructures(I.getStructures()));let k=r.sharedLength||0;if(k>u)throw new Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+r.sharedLength);if(!r.transitions){r.transitions=Object.create(null);for(let x=0;xre.offset>Ae.offset?1:-1),z=x.length,L=-1;for(;k&&z>0;){let re=x[--z].offset+i;rek.position+i?L>=0&&(L+=6):(L>=0&&(ae.setUint32(k.position+i,ae.getUint32(k.position+i)+L),L=-1),k=k.previous,z++)}L>=0&&k&&ae.setUint32(k.position+i,ae.getUint32(k.position+i)+L),h+=x.length*6,h>at&&q(h),I.offset=h;let O=$S(E.subarray(i,h),x);return o=null,O}return I.offset=h,J&KE?(E.start=i,E.end=h,E):E.subarray(i,h)}catch(k){throw H=k,k}finally{if(r&&(Q(),n&&I.saveStructures)){let k=r.sharedLength||0,x=E.subarray(i,h),z=eU(r,I);if(!H)return I.saveStructures(z,z.isCompatible)===!1?I.pack(m,J):(I.lastNamedStructuresLength=k,x)}J&sU&&(h=i)}};let Q=()=>{f<10&&f++;let m=r.sharedLength||0;if(r.length>m&&!a&&(r.length=m),d>1e4)r.transitions=null,f=0,d=0,U.length>0&&(U=[]);else if(U.length>0&&!a){for(let J=0,H=U.length;J{var J=m.length;J<16?E[h++]=144|J:J<65536?(E[h++]=220,E[h++]=J>>8,E[h++]=J&255):(E[h++]=221,ae.setUint32(h,J),h+=4);for(let H=0;H{h>at&&(E=q(h));var J=typeof m,H;if(J==="string"){let k=m.length;if(Fe&&k>=4&&k<4096){if((Fe.size+=k)>ZS){let O,re=(Fe[0]?Fe[0].length*3+Fe[1].length:0)+10;h+re>at&&(E=q(h+re));let Ae;Fe.position?(Ae=Fe,E[h]=200,h+=3,E[h++]=98,O=h-i,h+=4,vE(i,F,0),ae.setUint16(O+i-3,h-i-O)):(E[h++]=214,E[h++]=98,O=h-i,h+=4),Fe=["",""],Fe.previous=Ae,Fe.size=0,Fe.position=O}let L=WS.test(m);Fe[L?0:1]+=m,E[h++]=193,F(L?-k:k);return}let x;k<32?x=1:k<256?x=2:k<65536?x=3:x=5;let z=k*3;if(h+z>at&&(E=q(h+z)),k<64||!s){let L,O,re,Ae=h+x;for(L=0;L>6|192,E[Ae++]=O&63|128):(O&64512)===55296&&((re=m.charCodeAt(L+1))&64512)===56320?(O=65536+((O&1023)<<10)+(re&1023),L++,E[Ae++]=O>>18|240,E[Ae++]=O>>12&63|128,E[Ae++]=O>>6&63|128,E[Ae++]=O&63|128):(E[Ae++]=O>>12|224,E[Ae++]=O>>6&63|128,E[Ae++]=O&63|128);H=Ae-h-x}else H=s(m,h+x);H<32?E[h++]=160|H:H<256?(x<2&&E.copyWithin(h+2,h+1,h+1+H),E[h++]=217,E[h++]=H):H<65536?(x<3&&E.copyWithin(h+3,h+2,h+2+H),E[h++]=218,E[h++]=H>>8,E[h++]=H&255):(x<5&&E.copyWithin(h+5,h+3,h+3+H),E[h++]=219,ae.setUint32(h,H),h+=4),h+=H}else if(J==="number")if(m>>>0===m)m<32||m<128&&this.useRecords===!1||m<64&&!this.randomAccessStructure?E[h++]=m:m<256?(E[h++]=204,E[h++]=m):m<65536?(E[h++]=205,E[h++]=m>>8,E[h++]=m&255):(E[h++]=206,ae.setUint32(h,m),h+=4);else if(m>>0===m)m>=-32?E[h++]=256+m:m>=-128?(E[h++]=208,E[h++]=m+256):m>=-32768?(E[h++]=209,ae.setInt16(h,m),h+=2):(E[h++]=210,ae.setInt32(h,m),h+=4);else{let k;if((k=this.useFloat32)>0&&m<4294967296&&m>=-2147483648){E[h++]=202,ae.setFloat32(h,m);let x;if(k<4||(x=m*ka[(E[h]&127)<<1|E[h+1]>>7])>>0===x){h+=4;return}else h--}E[h++]=203,ae.setFloat64(h,m),h+=8}else if(J==="object"||J==="function")if(!m)E[h++]=192;else{if(o){let x=o.get(m);if(x){if(!x.id){let z=o.idsToInsert||(o.idsToInsert=[]);x.id=z.push(x)}E[h++]=214,E[h++]=112,ae.setUint32(h,x.id),h+=4;return}else o.set(m,{offset:h-i})}let k=m.constructor;if(k===Object)K(m,!0);else if(k===Array)y(m);else if(k===Map)if(this.mapAsEmptyObject)E[h++]=128;else{H=m.size,H<16?E[h++]=128|H:H<65536?(E[h++]=222,E[h++]=H>>8,E[h++]=H&255):(E[h++]=223,ae.setUint32(h,H),h+=4);for(let[x,z]of m)F(x),F(z)}else{for(let x=0,z=Xu.length;x(E=re,re=null,h+=Vt,h>at&&q(h),{target:E,targetView:ae,position:h-Vt}),F)}finally{re&&(E=re,ae=Ae,h=Te,at=E.length-10)}Yt&&(Yt.length+h>at&&q(Yt.length+h),h=jS(Yt,E,h,O.type));return}}if(Array.isArray(m))y(m);else{if(m.toJSON){let x=m.toJSON();if(x!==m)return F(x)}if(J==="function")return F(this.writeFunction&&this.writeFunction(m));K(m,!m.hasOwnProperty)}}}else if(J==="boolean")E[h++]=m?195:194;else if(J==="bigint"){if(m=-(BigInt(1)<0)E[h++]=207,ae.setBigUint64(h,m);else if(this.largeBigIntToFloat)E[h++]=203,ae.setFloat64(h,Number(m));else if(this.useBigIntExtension&&m<2n**1023n&&m>-(2n**1023n)){E[h++]=199,h++,E[h++]=66;let k=[],x;do{let z=m&0xffn;x=(z&0x80n)===(m<0n?0x80n:0n),k.push(z),m>>=8n}while(!((m===0n||m===-1n)&&x));E[h-2]=k.length;for(let z=k.length;z>0;)E[h++]=Number(k[--z]);return}else throw new RangeError(m+" was too large to fit in MessagePack 64-bit integer format, use useBigIntExtension or set largeBigIntToFloat to convert to float-64");h+=8}else if(J==="undefined")this.encodeUndefinedAsNil?E[h++]=192:(E[h++]=212,E[h++]=0,E[h++]=0);else throw new Error("Unknown type: "+J)},w=this.variableMapSize||this.coercibleKeyAsNumber?m=>{let J=Object.keys(m),H=J.length;H<16?E[h++]=128|H:H<65536?(E[h++]=222,E[h++]=H>>8,E[h++]=H&255):(E[h++]=223,ae.setUint32(h,H),h+=4);let k;if(this.coercibleKeyAsNumber)for(let x=0;x{E[h++]=222;let H=h-i;h+=2;let k=0;for(let x in m)(J||m.hasOwnProperty(x))&&(F(x),F(m[x]),k++);E[H+++i]=k>>8,E[H+i]=k&255},D=this.useRecords===!1?w:t.progressiveRecords&&!g?(m,J)=>{let H,k=r.transitions||(r.transitions=Object.create(null)),x=h++-i,z;for(let L in m)if(J||m.hasOwnProperty(L)){if(H=k[L],H)k=H;else{let O=Object.keys(m),re=k;k=r.transitions;let Ae=0;for(let Te=0,Yt=O.length;Te{let H,k=r.transitions||(r.transitions=Object.create(null)),x=0;for(let L in m)(J||m.hasOwnProperty(L))&&(H=k[L],H||(H=k[L]=Object.create(null),x++),k=H);let z=k[ur];z?z>=96&&g?(E[h++]=((z-=96)&31)+96,E[h++]=z>>5):E[h++]=z:X(k,k.__keys__||Object.keys(m),x);for(let L in m)(J||m.hasOwnProperty(L))&&F(m[L])},S=typeof this.useRecords=="function"&&this.useRecords,K=S?(m,J)=>{S(m)?D(m,J):w(m,J)}:D,q=m=>{let J;if(m>16777216){if(m-i>GE)throw new Error("Packed buffer would be larger than maximum buffer size");J=Math.min(GE,Math.round(Math.max((m-i)*(m>67108864?1.25:2),4194304)/4096)*4096)}else J=(Math.max(m-i<<2,E.length-1)>>12)+1<<12;let H=new Na(J);return ae=H.dataView||(H.dataView=new DataView(H.buffer,0,J)),m=Math.min(m,E.length),E.copy?E.copy(H,0,i,m):H.set(E.slice(i,m)),h-=i,i=0,at=H.length-10,E=H},X=(m,J,H)=>{let k=r.nextId;k||(k=64),k=p&&(k=B),r.nextId=k+1);let x=J.highByte=k>=96&&g?k-96>>5:-1;m[ur]=k,m.__keys__=J,r[k-64]=J,k=0?(E[h++]=(k&31)+96,E[h++]=x):E[h++]=k):(x>=0?(E[h++]=213,E[h++]=114,E[h++]=(k&31)+96,E[h++]=x):(E[h++]=212,E[h++]=114,E[h++]=k),H&&(d+=f*H),U.length>=l&&(U.shift()[ur]=0),U.push(m),F(J))},Ue=(m,J,H,k)=>{let x=E,z=h,L=at,O=i;E=As,h=0,i=0,E||(As=E=new Na(8192)),at=E.length-10,X(m,J,k),As=E;let re=h;if(E=x,h=z,at=L,i=O,re>1){let Ae=h+re-1;Ae>at&&q(Ae);let Te=H+i;E.copyWithin(Te+re,Te+1,h),E.set(As.slice(0,re),Te),h=Ae}else E[H+i]=As[0]},ct=(m,J)=>{let H=XS(m,E,i,h,r,q,(k,x,z)=>{if(z)return n=!0;h=x;let L=E;return F(k),Q(),L!==E?{position:h,targetView:ae,target:E}:h},this);if(H===0)return K(m,!0);h=H}}useBuffer(t){E=t,ae=new DataView(E.buffer,E.byteOffset,E.byteLength),h=0}clearSharedData(){this.structures&&(this.structures=[]),this.typedStructs&&(this.typedStructs=[])}};JE=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor,es];Xu=[{pack(e,t,A){let i=e.getTime()/1e3;if((this.useTimestamp32||e.getMilliseconds()===0)&&i>=0&&i<4294967296){let{target:n,targetView:r,position:o}=t(6);n[o++]=214,n[o++]=255,r.setUint32(o,i)}else if(i>0&&i<4294967296){let{target:n,targetView:r,position:o}=t(10);n[o++]=215,n[o++]=255,r.setUint32(o,e.getMilliseconds()*4e6+(i/1e3/4294967296>>0)),r.setUint32(o+4,i)}else if(isNaN(i)){if(this.onInvalidDate)return t(0),A(this.onInvalidDate());let{target:n,targetView:r,position:o}=t(3);n[o++]=212,n[o++]=255,n[o++]=255}else{let{target:n,targetView:r,position:o}=t(15);n[o++]=199,n[o++]=12,n[o++]=255,r.setUint32(o,e.getMilliseconds()*1e6),r.setBigInt64(o+4,BigInt(Math.floor(i)))}}},{pack(e,t,A){if(this.setAsEmptyObject)return t(0),A({});let i=Array.from(e),{target:n,position:r}=t(this.moreTypes?3:0);this.moreTypes&&(n[r++]=212,n[r++]=115,n[r++]=0),A(i)}},{pack(e,t,A){let{target:i,position:n}=t(this.moreTypes?3:0);this.moreTypes&&(i[n++]=212,i[n++]=101,i[n++]=0),A([e.name,e.message])}},{pack(e,t,A){let{target:i,position:n}=t(this.moreTypes?3:0);this.moreTypes&&(i[n++]=212,i[n++]=120,i[n++]=0),A([e.source,e.flags])}},{pack(e,t){this.moreTypes?HE(e,16,t):ME(Ga?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let A=e.constructor;A!==qE&&this.moreTypes?HE(e,Tu.indexOf(A.name),t):ME(e,t)}},{pack(e,t){let{target:A,position:i}=t(1);A[i]=193}}];function HE(e,t,A,i){let n=e.byteLength;if(n+1<256){var{target:r,position:o}=A(4+n);r[o++]=199,r[o++]=n+1}else if(n+1<65536){var{target:r,position:o}=A(5+n);r[o++]=200,r[o++]=n+1>>8,r[o++]=n+1&255}else{var{target:r,position:o,targetView:s}=A(7+n);r[o++]=201,s.setUint32(o,n+1),o+=4}r[o++]=116,r[o++]=t,r.set(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),o)}function ME(e,t){let A=e.byteLength;var i,n;if(A<256){var{target:i,position:n}=t(A+2);i[n++]=196,i[n++]=A}else if(A<65536){var{target:i,position:n}=t(A+3);i[n++]=197,i[n++]=A>>8,i[n++]=A&255}else{var{target:i,position:n,targetView:r}=t(A+5);i[n++]=198,r.setUint32(n,A),n+=4}i.set(e,n)}function jS(e,t,A,i){let n=e.length;switch(n){case 1:t[A++]=212;break;case 2:t[A++]=213;break;case 4:t[A++]=214;break;case 8:t[A++]=215;break;case 16:t[A++]=216;break;default:n<256?(t[A++]=199,t[A++]=n):n<65536?(t[A++]=200,t[A++]=n>>8,t[A++]=n&255):(t[A++]=201,t[A++]=n>>24,t[A++]=n>>16&255,t[A++]=n>>8&255,t[A++]=n&255)}return t[A++]=i,t.set(e,A),A+=n,A}function $S(e,t){let A,i=t.length*6,n=e.length-i;for(;A=t.pop();){let r=A.offset,o=A.id;e.copyWithin(r+i,r,n),i-=6;let s=r+i;e[s++]=214,e[s++]=105,e[s++]=o>>24,e[s++]=o>>16&255,e[s++]=o>>8&255,e[s++]=o&255,n=r}return e}function vE(e,t,A){if(Fe.length>0){ae.setUint32(Fe.position+e,h+A-Fe.position-e),Fe.stringsPosition=h-e;let i=Fe;Fe=null,t(i[0]),t(i[1])}}function eU(e,t){return e.isCompatible=A=>{let i=!A||(t.lastNamedStructuresLength||0)===A.length;return i||t._mergeStructures(A),i},e}var RE=new cn({useRecords:!1}),tU=RE.pack,AU=RE.pack;var{NEVER:iU,ALWAYS:nU,DECIMAL_ROUND:rU,DECIMAL_FIT:oU}=Ua,KE=512,sU=1024,IU=2048;var eB=R(VE(),1),iH=eB.default.configure,zE=eB.default;var PE={site:{list:"0",group:"1",load:"2",update:"3"},comp:{new:"4",list:"5",group:"6",load:"7"},page:{list:"8",load:"9",cache:"10"},yjs:{um:"11",sv_local:"12",diff_local:"13",sv_remote:"14"},client:{info:"15"},code:{load:"16",edit:"17",action:"18"}},_E={0:"site.list",1:"site.group",2:"site.load",3:"site.update",4:"comp.new",5:"comp.list",6:"comp.group",7:"comp.load",8:"page.list",9:"page.load",10:"page.cache",11:"yjs.um",12:"yjs.sv_local",13:"yjs.diff_local",14:"yjs.sv_remote",15:"client.info",16:"code.load",17:"code.edit",18:"code.action"};var fe=window;var TE=e=>sn(`prasi-user-${e}`,"default");var XE=new cn({structuredClone:!0}),is={debug:!!localStorage.getItem("prasi-ws-debug"),reconnectTimeout:1e3};fe.debug=new Proxy({},{get(e,t,A){if(t==="off")return is.debug=!1,localStorage.removeItem("prasi-ws-debug"),console.clear(),["WS DEBUG: Deactivated"];if(t==="on")return is.debug=!0,localStorage.setItem("prasi-ws-debug","1"),console.clear(),["WS DEBUG: Activated"]}});var wA={ws:null,client_id:"",idb:null,event:null},tB={action:{pending:{}}},ZE=(e,t)=>{let A=XE.pack(t);is.debug&&console.log("%c\u2B06","color:blue",jE(A.length,0),t),e.send(A)},WE=async e=>{let{user_id:t,site_id:A,page_id:i,events:n}=e;return wA.idb=TE(t),await BU({user_id:t,site_id:A,page_id:i},n),new oE(PE,({target:r,trapName:o,value:s,key:I,DEFAULT:a,PROXY:c})=>{if(o==="set")throw new TypeError("target is immutable");return typeof s=="string"?(...u)=>new Promise(l=>{CU({code:s,resolve:l,args:u})}):o==="get"&&typeof s=="object"&&s!==null?c:a})},BU=(e,t)=>{let{user_id:A,page_id:i,site_id:n}=e;return wA.event=t,fe.offline?new Promise(async r=>{r();let o="editor_start",s=await QU(o);t[o]&&t[o](s)}):new Promise((r,o)=>{if(!wA.ws){let s=0,I=()=>{let a=new URL(fe.basehost||location.href);a.pathname="/sync",a.protocol=a.protocol==="http:"?"ws:":"wss:";let c=new WebSocket(`${a.protocol}//${a.host}${a.pathname}`);c.onopen=()=>{ZE(c,{type:1,user_id:A,site_id:n,page_id:i}),wA.ws=c,t.opened()},c.onclose=async()=>{t.disconnected().reconnect?setTimeout(async()=>{s++,I()},s*is.reconnectTimeout):o()},c.onmessage=async u=>{let l=u.data,g=XE.unpack(Buffer.from(await l.arrayBuffer()));if(is.debug&&console.log("%c\u2B07","color:red",jE(l.size,0),g),g.type===0)wA.client_id=g.client_id,t.shakehand(g.client_id),r();else if(g.type===2){let B=g.event;t[B]&&(fU.includes(B)&&dU(B,g.data),t[B](g.data))}else if(g.type===4){let B=tB.action.pending[g.argid];if(B){B.resolve(g.val),delete tB.action.pending[g.argid];let p=wA.idb;p&&await mA(g.argid,g.val,p)}}}};I()}})},fU=["editor_start"],dU=async(e,t)=>{let A=wA.idb;if(A){let i=await wa(`ev-${e}`);await mA(i,t,A)}},QU=async e=>{let t=wA.idb;if(t){let A=await wa(`ev-${e}`);return await EA(A,t)}},CU=async e=>{let{args:t,code:A,resolve:i}=e,n=wA.ws,r=wA.idb;if(r){let o=zE(t),s=_E[A],I=await wa(`op-${s}-${o}`);if(n&&n.readyState===n.OPEN)tB.action.pending[I]={ts:Date.now(),resolve:i},ZE(n,{type:3,code:A,args:t,argid:I});else{let a=await EA(I,r);i(a)}}};function jE(e,t){if(e==0)return"0 Bytes";var A=1024,i=t||2,n=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],r=Math.floor(Math.log(e)/Math.log(A));return parseFloat((e/Math.pow(A,r)).toFixed(i))+" "+n[r]}var Br={NORMAL:0,WILDCARD:1,PLACEHOLDER:2};function fr(e={}){let t={options:e,rootNode:em(),staticRoutesMap:{}},A=i=>e.strictTrailingSlash?i:i.replace(/\/$/,"")||"/";if(e.routes)for(let i in e.routes)$E(t,A(i),e.routes[i]);return{ctx:t,lookup:i=>hU(t,A(i)),insert:(i,n)=>$E(t,A(i),n),remove:i=>pU(t,A(i))}}function hU(e,t){let A=e.staticRoutesMap[t];if(A)return A.data;let i=t.split("/"),n={},r=!1,o=null,s=e.rootNode,I=null;for(let a=0;a{},db:null,api:null,init_local_effect:{}},page:{history:{id:"",show:!1},root_id:"root",cur:mU,doc:null,list:{},building:!1,meta:{},entry:[],tree:[],render:()=>{}},comp:{doc:null,item:null,loaded:{},list:{},group:{}},code:{},global_prop:[],ui:{comp_editable:localStorage.getItem("prasi-comp-editable")==="yes",zoom:localStorage.zoom||"100%",side:{prop:!0},layout:{left:parseInt(localStorage.getItem("prasi-layout-left")||"250"),right:parseInt(localStorage.getItem("prasi-layout-right")||"250")},prevent_indent_hook:!1,syncing:!1,tree:{item_loading:[],search:"",search_ref:null,search_mode:{Name:!0,JS:!1,HTML:!1,CSS:!1},rename_id:"",open:{}},popup:{file:{enabled:!1},code:{init:!1,open:!1,name:"site",log:"",loading:!1,startup_status:"init",error:!1,show_log:!1,list:{}},page:{open:null,form:null},script:{open:!1,mode:"js",lastMode:"js",type:"item",prop_kind:"",prop_name:"",on_close:()=>{},typings:{status:"ok",err_msg:""},wb_render:()=>{}},site:null,site_form:null,comp:{preview_id:"",open:null,import:!1},comp_group:null,api:{open:!1}}}};var am=R(va());var cm=e=>{let{item:t,item_comp:A,ids:i}=e,n=uA(A);if(gm(n,i),t.id&&(n.id=t.id),n.component){if(n.component.props&&t.component)for(let r of Object.keys(n.component.props)){let o=t.component.props[r],s=n.component.props[r];o&&(s.value=o.value,s.valueBuilt=o.valueBuilt,s.jsxCalledBy=o.jsxCalledBy,s.content=o.content)}n.component.instances=t.component?.instances,n.component.style=t.component?.style}for(let r of Object.keys(t))delete t[r];for(let[r,o]of Object.entries(n))t[r]=o},gm=(e,t)=>{if(e.originalId=e.id,t[e.id]||(t[e.id]=(0,am.createId)()),e.id=t[e.id],e.childs)for(let A of e.childs)gm(A,t)};var lm=e=>{for(let[t,A]of Object.entries(e.item_comp.component?.props||{})){let i=uA(A),n=e.item.component?.props;n&&n[t]&&(i.value=n[t].value,i.valueBuilt=n[t].valueBuilt,n[t].content&&(i.content=n[t].content)),i&&e.each(t,i)}};var Ja=e=>{let t={};for(let[A,i]of Object.entries(e))if(A==="childs"){if(t.childs=[],i&&Array.isArray(i))for(let n of i)t.childs.push({id:n.id})}else t[A]=i;return t};var um=(e,t)=>{let{item:A}=t;if(A.type==="item"&&A.component?.id&&t.parent?.item.id){let i=e.comps[A.component.id];if(e.on?.visit_component&&e.on.visit_component(A,t.root||t.item),!i)return;if(i){let n;if(e.mode==="page"?(A.component.instances||(A.component.instances={}),n=A.component.instances):n=t.parent?.root_instances,n){let o=n[A.id];n[A.id]||(n[A.id]={},o=n[A.id]),cm({item:A,item_comp:i,ids:o})}let r={item:Ja(A),jsx_prop:t.jsx_prop,parent:{id:t.parent.item.id,comp_id:t.parent?.comp?.component?.id,instance_id:t.parent?.instance_id},instances:n};e.on?.visit&&e.on.visit(r,A,t.root||t.item),A.id&&e.set_meta!==!1&&(e.meta[A.id]=r),lm({item:A,item_comp:i,instance:n?n[A.id]:{},each(o,s){let I=A.component?.id;s.meta?.type==="content-element"&&I&&s.content&&(s.content.name=o,Nt({...e,mode:"comp"},{item:s.content,root:t.root||s.content,is_root:!1,jsx_prop:{is_root:!0,comp_id:I,name:o},parent:{item:r.item,instance_id:A.id,comp:i,root_instances:n}}))}});for(let o of Object.values(A.childs))o.name.startsWith("jsx:")||Nt({...e,mode:"comp"},{item:o,is_root:!1,root:t.root||t.item,parent:{item:A,instance_id:A.id,root_instances:n,comp:i}})}}};var Nt=(e,t)=>{let A=t.item;if(A.type==="item"&&A.component?.id&&t.ignore_first_component!==!0){um(e,t);return}let i={item:Ja(A),parent:{id:t.parent?.item.id||"root",instance_id:t.parent?.instance_id,comp_id:t.parent?.comp?.component?.id}};if(t.jsx_prop&&(i.jsx_prop=t.jsx_prop),e.on?.visit&&e.on.visit(i,A,t.root||t.item),A.id&&e.set_meta!==!1&&(e.meta[i.item.id]=i),A.childs){for(let[n,r]of Object.entries(A.childs))if(r.id){let o={item:r,is_root:!1,root:t.root||t.item,parent:{item:i.item,instance_id:t.parent?.instance_id,comp:t.parent?.comp,root_instances:t.parent?.root_instances}};t.jsx_prop&&(o.jsx_prop={...t.jsx_prop,is_root:!1}),Nt(e,o)}}};var qa=async(e,t,A,i)=>{let n=new Set,r={root:t};if(Nt({...e,on:{visit_component:({component:o})=>{if(o){let{id:s}=o;if(e.comps[s]||(!i||i&&!i.has(s))&&n.add(s),o?.props)for(let[I,a]of Object.entries(o.props))a.meta?.type==="content-element"&&a.content&&Nt({...e,on:{visit_component:({component:c})=>{if(c){let{id:u}=c;e.comps[u]||(!i||i&&!i.has(u))&&n.add(u)}},visit(c,u){A.visit&&A.visit(c,u,r)}},set_meta:!1,note:"init-load-comp-prop"},{item:a.content})}},visit(o,s){A.visit&&A.visit(o,s,r)}},set_meta:!1,note:"init-load-comp"},{item:t,ignore_first_component:!0}),A.done&&A.done(r),n.size>0){await A.load([...n]);let o=i;o||(o=new Set),n.forEach(s=>{o&&o.add(s)});for(let s of[...o]){let I=e.comps[s];I&&await qa(e,I,A,o)}}};var GU=sn("prasi-cache","prasi-cache-store"),un={timeout:null,store:GU},Ra=(e,t)=>{let A=[...Bm(t,"navigate(",")"),...Bm(t,"href = ",";")],i=e.page.cur.id;e.page.navs[i]||(e.page.navs[i]=new Set);for(let n of A)e.page.navs[i].add(n);clearTimeout(un.timeout),un.timeout=setTimeout(()=>{e.on_nav_loaded&&e.on_nav_loaded({urls:Array.from(e.page.navs[i])})},100)},Bm=(e,t,A)=>{let i=0,n=0,r=[];for(;;){let o=e.indexOf(t,i);if(n=i,o>=0){let s=e[o+t.length];if(s==='"'||s==="'"||s==="`"){let I=e.indexOf(`${s}${A}`,o+t.length+1),a=e.substring(o+t.length+1,I);i=I+2+A.length,r.push(a)}}if(n===i)break}return r};var dm=R(va());var Ka=()=>{let e=document.activeElement;return!!(e&&e.attributes.getNamedItem("contenteditable"))};var fm=R(va()),La=e=>{let{m:t,root:A,mitem:i,meta:n}=e;if(t.jsx_prop&&t.parent?.instance_id){let r=n[t.parent?.instance_id];if(r&&t.jsx_prop.is_root){let o=r.item.component?.props[t.jsx_prop.name];o&&(o.content=t.item)}}if(t.parent)if(t.parent.id==="root")t.item.id===A.id&&(t.mitem=i);else{let r=n[t.parent.id];if(r.mitem)if(t.jsx_prop?.is_root===!0){let o=r.mitem.get("component")?.get("props");if(o){let s=o.get(t.jsx_prop.name);if(s){let I=s.get("content");if(!I){let a=new Y.Map;syncronize(a,{id:(0,fm.createId)(),name:t.jsx_prop.name,type:"item",dim:{w:"full",h:"full"},childs:[],adv:{css:""}}),s.set("content",a)}I&&(t.mitem=I)}}}else r.mitem.get("childs")?.forEach(o=>{o&&o.get&&o.get("id")===t.item.id&&(t.mitem=o)});if(t.item.component?.props)for(let[o,s]of Object.entries(t.item.component.props)){let I=t.mitem?.get("component")?.get("props")?.get(o);if(!I){let a=t.mitem?.get("component")?.get("props");a&&e.new_prop_jsx(t,a,o,s)}if(s.content)if(I){let a=n[s.content.id];a&&(a.mitem=I.get("content"))}else{let a=t.mitem?.get("component")?.get("props");a&&e.new_prop_jsx(t,a,o,s)}}}};var Oa=(e,t,A,i)=>{if(t.parent?.id==="root")e.page.doc?.getMap("map").get("root")?.get("childs")?.forEach(n=>{n.get("id")===t.item.id&&(t.mitem=n)});else{let n=A[t.parent?.id||""];n&&n.mitem&&n.mitem.get("childs")?.forEach(r=>{r&&r.get&&r.get("id")===t.item.id&&(t.mitem=r)})}if(!t.item||!t.item.id)return console.warn("Emptry Tree Item ",t),null;if(i.find(n=>n.id===t.item.id))console.warn("Double Tree Item: ",t.item.id,t.item.name);else if(!t.parent?.comp_id)i.push({id:t.item.id,parent:t.parent?.id||"root",text:t.item.name,data:t});else if(t.jsx_prop)if(t.jsx_prop.is_root)t.jsx_prop.name!=="child"&&i.push({id:t.item.id,parent:t.parent?.instance_id||"root",text:t.jsx_prop.name,data:t});else{if(t.jsx_prop.name==="child"&&t.parent.instance_id){let n=A[t.parent.instance_id],r=n.item.component?.props.child.content?.id;r&&n.mitem&&A[r].item.childs.find(s=>t.item.id===s.id)&&i.push({id:t.item.id,parent:t.parent?.instance_id||"root",text:t.item.name,data:t})}t.parent.id!==t.parent.instance_id&&i.push({id:t.item.id,parent:t.parent?.id||"root",text:t.item.name,data:t})}};var Ya=async(e,t,A)=>{if(e.comp.list[t])return;let i=new Y.Doc;Y.applyUpdate(i,dt(A));let n=i.getMap("map").get("root");if(n){e.comp.loaded[t]=n.toJSON(),typeof e.comp.list[t]?.on_update=="function"&&i.off("update",e.comp.list[t].on_update);let r=await ba(e,i,t);if(r){let{meta:o,tree:s}=r;e.comp.list[t]?(e.comp.list[t].meta=o,e.comp.list[t].tree=s):(e.comp.list[t]={comp:{id:t,snapshot:A},doc:i,meta:o,tree:s,async on_update(I,a){if(a==="sv_remote"||a==="local")return;let c=await e.sync?.yjs.sv_local("comp",t,Buffer.from($t(I)));if(c){let u=Y.encodeStateAsUpdate(i,dt(c.sv));Y.applyUpdate(i,dt(c.diff),"local"),await e.sync?.yjs.diff_local("comp",t,Buffer.from($t(u)));let l=await ba(e,e.comp.list[t].doc,t);if(l&&(e.comp.list[t].meta=l.meta,e.comp.list[t].tree=l.tree),e.comp.loaded[t]=i.getMap("map").get("root")?.toJSON(),Ka())return;iA(e),e.render()}}},i.on("update",e.comp.list[t].on_update))}}},ba=async(e,t,A)=>{let i=t.getMap("map").get("root");if(!i)return;let n={},r=[],o=i.toJSON();return e.comp.loaded[A]=o,await qa({comps:e.comp.loaded,meta:n,set_meta:!1,mode:"comp"},o,{load:async s=>{let I=s.filter(c=>!e.comp.loaded[c]),a=await e.sync?.comp.load(I,!0);if(a){let c=Object.entries(a);for(let[u,l]of c)l&&l.snapshot&&!e.comp.list[u]&&await Ya(e,u,l.snapshot)}}}),Nt({comps:e.comp.loaded,meta:n,mode:"comp",on:{async visit(s){Oa(e,s,n,r),La({m:s,root:o,mitem:i,meta:n,new_prop_jsx(I,a,c,u){nB.list.push(()=>{let l=new Y.Map;u.content&&(u.content.id=(0,dm.createId)()),syncronize(l,u),a.set(c,l)})}})}},note:"load-comp-scan-meta"},{item:o,ignore_first_component:!0}),nB.list.length>0&&e.page.doc?.transact(()=>{for(let s of nB.list)s()}),e.comp.loaded[A]=o,{meta:n,tree:r,item:o}},nB={list:[]};var iA=async(e,t)=>{if(document.activeElement){let o=document.activeElement;if(o.tagName==="DIV"&&o.getAttribute("contenteditable")==="true")return}Ma.should_render_main=!0;let A=e.site.layout&&e.site.layout.id===e.page.cur.id&&t?.note==="load-layout page-init";for(let[o,s]of Object.entries(e.comp.list))if(!e.comp.loaded[o]){let a=s.doc.getMap("map").get("root")?.toJSON();a&&(e.comp.loaded[o]=a)}let i=e.page.doc?.getMap("map").get("root"),n=[];i?.get("childs")?.forEach(o=>n.push(o));let r={};e.page.tree=[];for(let o of n){let s=o.toJSON();s&&Nt({note:"tree-rebuild",comps:e.comp.loaded,meta:r,mode:"page",on:{async visit(I){A||((I.parent?.instance_id!==I.parent?.id||I.jsx_prop)&&Oa(e,I,r,e.page.tree),La({m:I,root:s,mitem:o,meta:r,new_prop_jsx(a,c,u,l){if(!c.get(u)){let g=new Y.Map;syncronize(g,l),c.set(u,g)}}}))}}},{item:s})}if(A)e.site.layout.meta=r;else{let o="root";if(e.site.layout&&e.site.layout.meta){for(let[s,I]of Object.entries(e.site.layout.meta))if(I.item.name==="content"){o=I.item.id;break}e.page.root_id=o}if(e.site.layout&&e.site.layout.id===e.page.cur.id)e.page.meta=r;else if(o!=="root"){for(let s of Object.values(r))s.parent?.id==="root"&&(s.parent.id=o);e.page.meta={...e.site.layout.meta,...r}}else e.page.meta=r}};BigInt.prototype.toJSON=function(){return"BigInt::"+this.toString()};var Bn=typeof window<"u"?window:null,dr=async(e,t,A)=>{let i={...A},n=t,r=!1,o=async I=>{if(Bn!==null){if(!(I instanceof Bn.FormData||I instanceof Bn.File))i["content-type"]="application/json";else if(I instanceof Bn.File){r=!0;let a=await new Promise(c=>{let u=new FileReader;u.addEventListener("load",l=>{c(l.target?.result)}),u.readAsArrayBuffer(I)});a&&(I=new File([a],I.name))}}return I};Array.isArray(t)?n=await Promise.all(t.map(I=>o(I))):n=await o(t),r||(n=JSON.stringify(n));let s=new URL(e);if(Bn!==null)if(new URL(location.href).host===s.host){let c=await(await fetch(s.pathname,t?{method:"POST",body:n,headers:i}:void 0)).text();try{return JSON.parse(c)}catch{return c}}else if(t instanceof File||Array.isArray(t)&&t[0]instanceof File){let a=new URL(e);if(A["content-type"]="multipart/form-data",t instanceof File){let c=new FormData;return c.append("file",t),await(await fetch(a.pathname,{body:c,method:"POST",headers:A})).text()}else{let c=new FormData,u=1;for(let g of t)c.append("file-"+u++,g);return await(await fetch(a.pathname,{body:c,method:"POST",headers:A})).text()}}else{let a=await fetch(`${Bn.basehost?Bn.basehost:""}/_proxy`,{method:"POST",body:JSON.stringify([{url:e,body:n,headers:i}]),headers:{"content-type":"application/json"}}),c="";try{return c=await a.text(),JSON.parse(c)}catch{let l=null;try{l=JSON.stringify(JSON.parse(n),null,2)}catch{}return console.warn(` \u26A1 Failed to JSON.parse fetch result of ${e}: diff --git a/app/srv/ws/sync/actions/code_edit.ts b/app/srv/ws/sync/actions/code_edit.ts index 0d86019b..46f03020 100644 --- a/app/srv/ws/sync/actions/code_edit.ts +++ b/app/srv/ws/sync/actions/code_edit.ts @@ -11,7 +11,7 @@ import { SyncConnection } from "../type"; import { parseJs } from "../editor/parser/parse-js"; import { snapshot } from "../entity/snapshot"; import { validate } from "uuid"; -import { gzipAsync } from "utils/diff"; +import { gzipAsync } from "utils/diff/diff"; const decoder = new TextDecoder(); const timeout = { diff --git a/app/srv/ws/sync/actions/yjs_diff_local.ts b/app/srv/ws/sync/actions/yjs_diff_local.ts index c9e43d3f..00f00df1 100644 --- a/app/srv/ws/sync/actions/yjs_diff_local.ts +++ b/app/srv/ws/sync/actions/yjs_diff_local.ts @@ -3,7 +3,7 @@ import { SAction } from "../actions"; import { docs } from "../entity/docs"; import { gunzipAsync } from "../entity/zlib"; import { SyncConnection } from "../type"; -import { gzipAsync } from "utils/diff"; +import { gzipAsync } from "utils/diff/diff"; const history = {} as Record; diff --git a/app/web/src/nova/ed/logic/ed-global.ts b/app/web/src/nova/ed/logic/ed-global.ts index b4b6d0d9..eea7f652 100644 --- a/app/web/src/nova/ed/logic/ed-global.ts +++ b/app/web/src/nova/ed/logic/ed-global.ts @@ -170,7 +170,7 @@ export const EDGlobal = { page: { history: { id: "", - show: false + show: false, }, root_id: "root", cur: EmptyPage, @@ -231,6 +231,7 @@ export const EDGlobal = { open: {} as Record, }, popup: { + file: { enabled: false }, code: { init: false, open: false, @@ -273,7 +274,7 @@ export const EDGlobal = { comp: { preview_id: "", open: null as null | ((comp_id: string) => void | Promise), - import: false + import: false, }, comp_group: null as null | { mouse_event: React.MouseEvent; diff --git a/pkgs/core/utils/diff.test.ts b/pkgs/core/utils/diff.test.ts deleted file mode 100644 index d2949a8d..00000000 --- a/pkgs/core/utils/diff.test.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { describe } from "bun:test"; -import { readAsync } from "fs-jetpack"; -import { Diff, gunzipAsync } from "./diff"; - -import { Packr } from "msgpackr"; - -const MAX_HISTORY = 10; - -const packr = new Packr({}); - -describe("simple diff", async () => { - const server = await Diff.server(await readAsync("tsconfig.json")); - const patch = await server.getPatch("new"); - - console.log("init", hmn(patch.length)); - const client = await Diff.client(patch); - - console.log("\npatch1"); - await server.update("rako12"); - const patch1 = await server.getPatch(client.ts); - await client.applyPatch(patch1); - console.log( - hmn(patch1.length), - `|| client: ${hmn((await client.data).length)}` - ); - - console.log("\npatch2"); - const bin = await readAsync("data/prod/main.js", "utf8"); - await server.update(bin); - const patch2 = await server.getPatch(client.ts); - await client.applyPatch(patch2); - console.log( - hmn(patch2.length), - `|| client: ${hmn((await client.data).length)}` - ); - - console.log("\npatch3"); - const ubin = "mantappu" + bin?.substring(0,100000); - await server.update(ubin); - const patch3 = await server.getPatch(client.ts); - await client.applyPatch(patch3); - console.log( - hmn(patch3.length), - `|| client: ${hmn((await client.data).length)}` - ); -}); - -function hmn(bytes: number): string { - const sizes = ["bytes", "KB", "MB", "GB", "TB"]; - if (bytes === 0) return "0 bytes"; - - const i = Math.floor(Math.log(bytes) / Math.log(1024)); - const size = i === 0 ? bytes : (bytes / Math.pow(1024, i)).toFixed(2); - - return `${size} ${sizes[i]}`; -} diff --git a/pkgs/core/utils/diff/diff.test.ts b/pkgs/core/utils/diff/diff.test.ts new file mode 100644 index 00000000..57bed14c --- /dev/null +++ b/pkgs/core/utils/diff/diff.test.ts @@ -0,0 +1,84 @@ +import { describe } from "bun:test"; +import { readAsync } from "fs-jetpack"; +import { Diff, gunzipAsync } from "./diff"; + +import { Packr } from "msgpackr"; + +const MAX_HISTORY = 10; + +const packr = new Packr({}); + +describe("simple diff", async () => { + const json = await readAsync("data/1MB.json", "json") as any[]; + const server = await Diff.server(json); + const patch = await server.getPatch("new"); + + console.log("init"); + const client = await Diff.client(patch); + console.log( + hmn(patch.length), + `|| client: ${hmn(JSON.stringify(await client.data).length)}` + ); + + console.log("\npatch1"); + json.shift(); + json.shift(); + json.shift(); + await server.update(json); + const patch1 = await server.getPatch(client.ts); + await client.applyPatch(patch1); + console.log( + hmn(patch1.length), + `|| client: ${hmn(JSON.stringify(await client.data).length)}` + ); + + // console.log("\npatch15"); + // await server.update({ moka: { rako: "1231" } }); + // const patch15 = await server.getPatch(client.ts); + // await client.applyPatch(patch15); + // console.log( + // hmn(patch15.length), + // `|| client: ${JSON.stringify(await client.data)}` + // ); + + // console.log("\npatch2"); + // const bin = await readAsync("data/prod/main.js", "utf8"); + // await server.update(bin); + // const patch2 = await server.getPatch(client.ts); + // await client.applyPatch(patch2); + // console.log( + // hmn(patch2.length), + // `|| client: ${hmn((await client.data).length)}` + // ); + + // if (bin) { + // console.log("\npatch2.5"); + // await server.update(bin.substring(0, 10) + "1" + bin.substring(10)); + // const patch25 = await server.getPatch(client.ts); + // await client.applyPatch(patch25); + // console.log( + // hmn(patch25.length), + // `|| client: ${hmn((await client.data).length)}` + // ); + // } + + // console.log("\npatch3"); + // const ubin = "mantappu" + bin?.substring(0, 100000); + // await server.update(ubin); + // const patch3 = await server.getPatch(client.ts); + // await client.applyPatch(patch3); + // console.log( + // hmn(patch3.length), + // `|| client: ${hmn((await client.data).length)}` + // ); +}); + +function hmn(bytes: number): string { + const sizes = ["bytes", "KB", "MB", "GB", "TB"]; + if (bytes === 0) return "0 bytes"; + + const i = Math.floor(Math.log(bytes) / Math.log(1024)); + const size = i === 0 ? bytes : (bytes / Math.pow(1024, i)).toFixed(2); + + return `${size} ${sizes[i]}`; +} diff --git a/pkgs/core/utils/diff.ts b/pkgs/core/utils/diff/diff.ts similarity index 81% rename from pkgs/core/utils/diff.ts rename to pkgs/core/utils/diff/diff.ts index d889cd21..f1b43fe2 100644 --- a/pkgs/core/utils/diff.ts +++ b/pkgs/core/utils/diff/diff.ts @@ -1,9 +1,9 @@ -import { applyPatch, calcPatch } from "./diff-internal"; import { Packr } from "msgpackr"; import { gunzip, gzip } from "zlib"; +import { applyPatch, calcPatch } from "./lib/fast-myers-diff"; const MAX_HISTORY = 25; // max history item -const MAX_DIFF_TIMEOUT = 50; // in ms +const MAX_FMD_TIMEOUT = 100; // in ms const packr = new Packr({}); @@ -12,9 +12,14 @@ type PATCH_RESULT = mode: "new"; ts: string; data: number[]; + } + | { + mode: "patch-fmd"; + ts: string; + diff: any; } | { - mode: "patch"; + mode: "patch-fd"; ts: string; diff: any; }; @@ -74,12 +79,13 @@ export class Diff { return old_data[key1] === this._data[key2]; }, () => { - return performance.now() - now > MAX_DIFF_TIMEOUT; + return performance.now() - now > MAX_FMD_TIMEOUT; } ), ]; - if (performance.now() - now <= MAX_DIFF_TIMEOUT) { + if (performance.now() - now <= MAX_FMD_TIMEOUT) { + console.log(Math.round(performance.now() - now) + "ms"); done( new Uint8Array( packr.pack({ diff: result_diff, mode: "patch", ts: this.ts }) @@ -100,6 +106,7 @@ export class Diff { async applyPatch(_patch: Uint8Array) { const patch = packr.unpack(_patch) as PATCH_RESULT; + console.log(patch.mode, `size: ${hmn(_patch.length)}`); if (patch.mode === "new") { this.ts = patch.ts; if (patch.data) this._data = patch.data; @@ -113,7 +120,7 @@ export class Diff { } } else { num_array.push(num); - } + } } this._data = num_array; } @@ -156,3 +163,13 @@ export const gunzipAsync = (bin: Uint8Array) => { }); }); }; + +function hmn(bytes: number): string { + const sizes = ["bytes", "KB", "MB", "GB", "TB"]; + if (bytes === 0) return "0 bytes"; + + const i = Math.floor(Math.log(bytes) / Math.log(1024)); + const size = i === 0 ? bytes : (bytes / Math.pow(1024, i)).toFixed(2); + + return `${size} ${sizes[i]}`; +} diff --git a/pkgs/core/utils/diff-internal.ts b/pkgs/core/utils/diff/lib/fast-myers-diff.ts similarity index 98% rename from pkgs/core/utils/diff-internal.ts rename to pkgs/core/utils/diff/lib/fast-myers-diff.ts index e6a57e21..23a6b5c2 100644 --- a/pkgs/core/utils/diff-internal.ts +++ b/pkgs/core/utils/diff/lib/fast-myers-diff.ts @@ -250,9 +250,13 @@ export function diff_core( ): IterableIterator { const Z = (Math.min(N, M) + 1) * 2; const L = N + M; - const b = new (L < 256 ? Uint8Array : L < 65536 ? Uint16Array : Uint32Array)( - 2 * Z - ); + + let constructor: any = Float64Array; + if (L < 256) constructor = Uint8Array; + else if (L < 65536) constructor = Uint16Array; + else if (L < 4294967297) constructor = Uint32Array; + + const b = new constructor(2 * Z); return new DiffGen({ i,