yjs-bundle
Version:
bundles several yjs packages in a single module in order to avoid "Yjs was already imported" problems
1 lines • 217 kB
JavaScript
const e=()=>new Map,t=t=>{const n=e();return t.forEach(((e,t)=>{n.set(t,e)})),n},n=(e,t,n)=>{let r=e.get(t);return void 0===r&&e.set(t,r=n()),r},r=()=>new Set,s=e=>e[e.length-1],i=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},o=Array.from,a=Array.isArray;class c{constructor(){this._observers=e()}on(e,t){return n(this._observers,e,r).add(t),t}once(e,t){const n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){const n=this._observers.get(e);void 0!==n&&(n.delete(t),0===n.size&&this._observers.delete(e))}emit(t,n){return o((this._observers.get(t)||e()).values()).forEach((e=>e(...n)))}destroy(){this._observers=e()}}class l{constructor(){this._observers=e()}on(e,t){n(this._observers,e,r).add(t)}once(e,t){const n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){const n=this._observers.get(e);void 0!==n&&(n.delete(t),0===n.size&&this._observers.delete(e))}emit(t,n){return o((this._observers.get(t)||e()).values()).forEach((e=>e(...n)))}destroy(){this._observers=e()}}const h=Math.floor,u=Math.abs,d=Math.log10,f=(e,t)=>e<t?e:t,p=(e,t)=>e>t?e:t,g=Math.pow,y=e=>0!==e?e<0:1/e<0,m=64,w=128,b=127,_=Number.MAX_SAFE_INTEGER,v=Number.isInteger||(e=>"number"==typeof e&&isFinite(e)&&h(e)===e),E=String.fromCharCode,k=/^\s*/g,C=/([A-Z])/g,S=(e,t)=>(e=>e.replace(k,""))(e.replace(C,(e=>`${t}${(e=>e.toLowerCase())(e)}`))),T="undefined"!=typeof TextEncoder?new TextEncoder:null,A=T?e=>T.encode(e):e=>{const t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.codePointAt(e);return r};let R="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});R&&1===R.decode(new Uint8Array).length&&(R=null);const D=(e,t)=>((e,t)=>{const n=new Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n})(t,(()=>e)).join("");class I{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const L=()=>new I,x=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},M=e=>{const t=new Uint8Array(x(e));let n=0;for(let r=0;r<e.bufs.length;r++){const s=e.bufs[r];t.set(s,n),n+=s.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},O=(e,t)=>{const n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(2*n),e.cpos=0),e.cbuf[e.cpos++]=t},N=O,U=(e,t)=>{for(;t>b;)O(e,w|b&t),t=h(t/128);O(e,b&t)},P=(e,t)=>{const n=y(t);for(n&&(t=-t),O(e,(t>63?w:0)|(n?m:0)|63&t),t=h(t/64);t>0;)O(e,(t>b?w:0)|b&t),t=h(t/128)},j=new Uint8Array(3e4),B=j.length/3,F=T&&T.encodeInto?(e,t)=>{if(t.length<B){const n=T.encodeInto(t,j).written||0;U(e,n);for(let t=0;t<n;t++)O(e,j[t])}else V(e,A(t))}:(e,t)=>{const n=unescape(encodeURIComponent(t)),r=n.length;U(e,r);for(let t=0;t<r;t++)O(e,n.codePointAt(t))},W=(e,t)=>{const n=e.cbuf.length,r=e.cpos,s=f(n-r,t.length),i=t.length-s;e.cbuf.set(t.subarray(0,s),r),e.cpos+=s,i>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(p(2*n,i)),e.cbuf.set(t.subarray(s)),e.cpos=i)},V=(e,t)=>{U(e,t.byteLength),W(e,t)},H=(e,t)=>{((e,t)=>{const n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(2*p(n,t)),e.cpos=0)})(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},q=new DataView(new ArrayBuffer(4)),z=(e,t)=>{switch(typeof t){case"string":O(e,119),F(e,t);break;case"number":v(t)&&u(t)<=2147483647?(O(e,125),P(e,t)):(n=t,q.setFloat32(0,n),q.getFloat32(0)===n?(O(e,124),((e,t)=>{H(e,4).setFloat32(0,t,!1)})(e,t)):(O(e,123),((e,t)=>{H(e,8).setFloat64(0,t,!1)})(e,t)));break;case"bigint":O(e,122),((e,t)=>{H(e,8).setBigInt64(0,t,!1)})(e,t);break;case"object":if(null===t)O(e,126);else if(a(t)){O(e,117),U(e,t.length);for(let n=0;n<t.length;n++)z(e,t[n])}else if(t instanceof Uint8Array)O(e,116),V(e,t);else{O(e,118);const n=Object.keys(t);U(e,n.length);for(let r=0;r<n.length;r++){const s=n[r];F(e,s),z(e,t[s])}}break;case"boolean":O(e,t?120:121);break;default:O(e,127)}var n};class K extends I{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&U(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const J=e=>{e.count>0&&(P(e.encoder,1===e.count?e.s:-e.s),e.count>1&&U(e.encoder,e.count-2))};class Y{constructor(){this.encoder=new I,this.s=0,this.count=0}write(e){this.s===e?this.count++:(J(this),this.count=1,this.s=e)}toUint8Array(){return J(this),M(this.encoder)}}const $=e=>{if(e.count>0){const t=2*e.diff+(1===e.count?0:1);P(e.encoder,t),e.count>1&&U(e.encoder,e.count-2)}};class G{constructor(){this.encoder=new I,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):($(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return $(this),M(this.encoder)}}class X{constructor(){this.sarr=[],this.s="",this.lensE=new Y}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new I;return this.sarr.push(this.s),this.s="",F(e,this.sarr.join("")),W(e,this.lensE.toUint8Array()),M(e)}}const Z=e=>new Error(e),Q=()=>{throw Z("Method unimplemented")},ee=()=>{throw Z("Unexpected case")},te=Z("Unexpected end of array"),ne=Z("Integer out of Range");class re{constructor(e){this.arr=e,this.pos=0}}const se=e=>new re(e),ie=e=>e.pos!==e.arr.length,oe=e=>((e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n})(e,ce(e)),ae=e=>e.arr[e.pos++],ce=e=>{let t=0,n=1;const r=e.arr.length;for(;e.pos<r;){const r=e.arr[e.pos++];if(t+=(r&b)*n,n*=128,r<w)return t;if(t>_)throw ne}throw te},le=e=>{let t=e.arr[e.pos++],n=63&t,r=64;const s=(t&m)>0?-1:1;if(!(t&w))return s*n;const i=e.arr.length;for(;e.pos<i;){if(t=e.arr[e.pos++],n+=(t&b)*r,r*=128,t<w)return s*n;if(n>_)throw ne}throw te},he=R?e=>R.decode(oe(e)):e=>{let t=ce(e);if(0===t)return"";{let n=String.fromCodePoint(ae(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(ae(e));else for(;t>0;){const r=t<1e4?t:1e4,s=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,s),t-=r}return decodeURIComponent(escape(n))}},ue=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},de=[e=>{},e=>null,le,e=>ue(e,4).getFloat32(0,!1),e=>ue(e,8).getFloat64(0,!1),e=>ue(e,8).getBigInt64(0,!1),e=>!1,e=>!0,he,e=>{const t=ce(e),n={};for(let r=0;r<t;r++){n[he(e)]=fe(e)}return n},e=>{const t=ce(e),n=[];for(let r=0;r<t;r++)n.push(fe(e));return n},oe],fe=e=>de[127-ae(e)](e);class pe extends re{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return 0===this.count&&(this.s=this.reader(this),ie(this)?this.count=ce(this)+1:this.count=-1),this.count--,this.s}}class ge extends re{constructor(e){super(e),this.s=0,this.count=0}read(){if(0===this.count){this.s=le(this);const e=y(this.s);this.count=1,e&&(this.s=-this.s,this.count=ce(this)+2)}return this.count--,this.s}}class ye extends re{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(0===this.count){const e=le(this),t=1&e;this.diff=h(e/2),this.count=1,t&&(this.count=ce(this)+2)}return this.s+=this.diff,this.count--,this.s}}class me{constructor(e){this.decoder=new ge(e),this.str=he(this.decoder),this.spos=0}read(){const e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}}const we=crypto.getRandomValues.bind(crypto),be=Math.random,_e=()=>we(new Uint32Array(1))[0],ve=[1e7]+-1e3+-4e3+-8e3+-1e11,Ee=()=>ve.replace(/[018]/g,(e=>(e^_e()&15>>e/4).toString(16))),ke=Date.now,Ce=e=>new Promise(e);Promise.all.bind(Promise);const Se=e=>Promise.resolve(e),Te=e=>void 0===e?null:e;let Ae=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},Re=!0;try{"undefined"!=typeof localStorage&&localStorage&&(Ae=localStorage,Re=!1)}catch(e){}const De=Ae,Ie=Object.assign,Le=Object.keys,xe=e=>Le(e).length,Me=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Oe=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Oe(e,t,n+1)}},Ne=()=>{},Ue=e=>e,Pe=(e,t)=>{if(null==e||null==t)return((e,t)=>e===t)(e,t);if(e.constructor!==t.constructor)return!1;if(e===t)return!0;switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break;case Set:if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;break;case Map:if(e.size!==t.size)return!1;for(const n of e.keys())if(!t.has(n)||!Pe(e.get(n),t.get(n)))return!1;break;case Object:if(xe(e)!==xe(t))return!1;for(const n in e)if(!Me(e,n)||!Pe(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Pe(e[n],t[n]))return!1;break;default:return!1}return!0},je="undefined"!=typeof process&&process.release&&/node|io\.js/.test(process.release.name)&&"[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),Be="undefined"!=typeof window&&"undefined"!=typeof document&&!je;let Fe;"undefined"!=typeof navigator&&/Mac/.test(navigator.platform);const We=t=>(()=>{if(void 0===Fe)if(je){Fe=e();const t=process.argv;let n=null;for(let e=0;e<t.length;e++){const r=t[e];"-"===r[0]?(null!==n&&Fe.set(n,""),n=r):null!==n&&(Fe.set(n,r),n=null)}null!==n&&Fe.set(n,"")}else"object"==typeof location?(Fe=e(),(location.search||"?").slice(1).split("&").forEach((e=>{if(0!==e.length){const[t,n]=e.split("=");Fe.set(`--${S(t,"-")}`,n),Fe.set(`-${S(t,"-")}`,n)}}))):Fe=e();return Fe})().has(t),Ve=e=>Te(je?process.env[e.toUpperCase().replaceAll("-","_")]:De.getItem(e));var He;We("--"+(He="production"))||Ve(He);const qe=je&&(ze=process.env.FORCE_COLOR,["true","1","2"].includes(ze));var ze;const Ke=!We("no-colors")&&(!je||process.stdout.isTTY||qe)&&(!je||We("color")||qe||null!==Ve("COLORTERM")||(Ve("TERM")||"").includes("color")),Je=e=>new Uint8Array(e),Ye=Be?e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=E(e[n]);return btoa(t)}:e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),$e=Be?e=>{const t=atob(e),n=Je(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}:e=>{const t=Buffer.from(e,"base64");return((e,t,n)=>new Uint8Array(e,t,n))(t.buffer,t.byteOffset,t.byteLength)};class Ge{constructor(e,t){this.left=e,this.right=t}}const Xe=(e,t)=>new Ge(e,t),Ze="undefined"!=typeof document?document:{};"undefined"!=typeof DOMParser&&new DOMParser;Ze.ELEMENT_NODE,Ze.TEXT_NODE,Ze.CDATA_SECTION_NODE,Ze.COMMENT_NODE,Ze.DOCUMENT_NODE,Ze.DOCUMENT_TYPE_NODE,Ze.DOCUMENT_FRAGMENT_NODE;const Qe=JSON.stringify,et=Symbol,tt=et(),nt=et(),rt=et(),st=et(),it=et(),ot=et(),at=et(),ct=et(),lt=et(),ht=[it,at,ct,rt];let ut=0,dt=ke();const ft={[tt]:Xe("font-weight","bold"),[nt]:Xe("font-weight","normal"),[rt]:Xe("color","blue"),[it]:Xe("color","green"),[st]:Xe("color","grey"),[ot]:Xe("color","red"),[at]:Xe("color","purple"),[ct]:Xe("color","orange"),[lt]:Xe("color","black")},pt=Ke?t=>{1===t.length&&t[0]?.constructor===Function&&(t=t[0]());const n=[],r=[],s=e();let i=[],o=0;for(;o<t.length;o++){const e=t[o],i=ft[e];if(void 0!==i)s.set(i.left,i.right);else{if(void 0===e)break;if(e.constructor!==String&&e.constructor!==Number)break;{const t=((e,t)=>{const n=[];for(const[r,s]of e)n.push(t(s,r));return n})(s,((e,t)=>`${t}:${e};`)).join("");o>0||t.length>0?(n.push("%c"+e),r.push(t)):n.push(e)}}}for(o>0&&(i=r,i.unshift(n.join("")));o<t.length;o++){const e=t[o];e instanceof Symbol||i.push(e)}return i}:e=>{1===e.length&&e[0]?.constructor===Function&&(e=e[0]());const t=[];let n=0;for(;n<e.length;n++){const r=e[n];void 0===r||r.constructor===String||r.constructor===Number||r.constructor===Object&&t.push(JSON.stringify(r))}return t},gt=(...e)=>{console.log(...pt(e)),yt.forEach((t=>t.print(e)))},yt=r(),mt=e=>({[Symbol.iterator](){return this},next:e}),wt=(e,t)=>mt((()=>{const{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}));class bt extends c{constructor(e,t){super(),this.doc=e,this.awareness=t}}class _t{constructor(e,t){this.clock=e,this.len=t}}class vt{constructor(){this.clients=new Map}}const Et=(e,t,n)=>t.clients.forEach(((t,r)=>{const s=e.doc.store.clients.get(r);for(let r=0;r<t.length;r++){const i=t[r];Yn(e,s,i.clock,i.len,n)}})),kt=(e,t)=>{const n=e.clients.get(t.client);return void 0!==n&&null!==((e,t)=>{let n=0,r=e.length-1;for(;n<=r;){const s=h((n+r)/2),i=e[s],o=i.clock;if(o<=t){if(t<o+i.len)return s;n=s+1}else r=s-1}return null})(n,t.clock)},Ct=e=>{e.clients.forEach((e=>{let t,n;for(e.sort(((e,t)=>e.clock-t.clock)),t=1,n=1;t<e.length;t++){const r=e[n-1],s=e[t];r.clock+r.len>=s.clock?r.len=p(r.len,s.clock+s.len-r.clock):(n<t&&(e[n]=s),n++)}e.length=n}))},St=e=>{const t=new vt;for(let n=0;n<e.length;n++)e[n].clients.forEach(((r,s)=>{if(!t.clients.has(s)){const o=r.slice();for(let t=n+1;t<e.length;t++)i(o,e[t].clients.get(s)||[]);t.clients.set(s,o)}}));return Ct(t),t},Tt=(e,t,r,s)=>{n(e.clients,t,(()=>[])).push(new _t(r,s))},At=()=>new vt,Rt=e=>{const t=At();return e.clients.forEach(((e,n)=>{const r=[];for(let t=0;t<e.length;t++){const n=e[t];if(n.deleted){const s=n.id.clock;let i=n.length;if(t+1<e.length)for(let n=e[t+1];t+1<e.length&&n.deleted;n=e[1+ ++t])i+=n.length;r.push(new _t(s,i))}}r.length>0&&t.clients.set(n,r)})),t},Dt=(e,t)=>{U(e.restEncoder,t.clients.size),o(t.clients.entries()).sort(((e,t)=>t[0]-e[0])).forEach((([t,n])=>{e.resetDsCurVal(),U(e.restEncoder,t);const r=n.length;U(e.restEncoder,r);for(let t=0;t<r;t++){const r=n[t];e.writeDsClock(r.clock),e.writeDsLen(r.len)}}))},It=e=>{const t=new vt,r=ce(e.restDecoder);for(let s=0;s<r;s++){e.resetDsCurVal();const r=ce(e.restDecoder),s=ce(e.restDecoder);if(s>0){const i=n(t.clients,r,(()=>[]));for(let t=0;t<s;t++)i.push(new _t(e.readDsClock(),e.readDsLen()))}}return t},Lt=(e,t,n)=>{const r=new vt,s=ce(e.restDecoder);for(let i=0;i<s;i++){e.resetDsCurVal();const s=ce(e.restDecoder),i=ce(e.restDecoder),o=n.clients.get(s)||[],a=Wn(n,s);for(let n=0;n<i;n++){const n=e.readDsClock(),i=n+e.readDsLen();if(n<a){a<i&&Tt(r,s,a,i-a);let e=Hn(o,n),c=o[e];for(!c.deleted&&c.id.clock<n&&(o.splice(e+1,0,ni(t,c,n-c.id.clock)),e++);e<o.length&&(c=o[e++],c.id.clock<i);)c.deleted||(i<c.id.clock+c.length&&o.splice(e,0,ni(t,c,i-c.id.clock)),c.delete(t))}else Tt(r,s,n,i-n)}}if(r.clients.size>0){const e=new Vt;return U(e.restEncoder,0),Dt(e,r),e.toUint8Array()}return null},xt=(e,t)=>{if(e.clients.size!==t.clients.size)return!1;for(const[n,r]of e.clients.entries()){const e=t.clients.get(n);if(void 0===e||r.length!==e.length)return!1;for(let t=0;t<r.length;t++){const n=r[t],s=e[t];if(n.clock!==s.clock||n.len!==s.len)return!1}}return!0},Mt=_e;class Ot extends c{constructor({guid:e=Ee(),collectionid:t=null,gc:n=!0,gcFilter:r=(()=>!0),meta:s=null,autoLoad:i=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=r,this.clientID=Mt(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Bn,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=i,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.whenLoaded=Ce((e=>{this.on("load",(()=>{this.isLoaded=!0,e(this)}))}));const a=()=>Ce((e=>{const t=n=>{void 0!==n&&!0!==n||(this.off("sync",t),e())};this.on("sync",t)}));this.on("sync",(e=>{!1===e&&this.isSynced&&(this.whenSynced=a()),this.isSynced=void 0===e||!0===e,this.isSynced&&!this.isLoaded&&this.emit("load",[this])})),this.whenSynced=a()}load(){const e=this._item;null===e||this.shouldLoad||rr(e.parent.doc,(e=>{e.subdocsLoaded.add(this)}),null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(o(this.subdocs).map((e=>e.guid)))}transact(e,t=null){return rr(this,e,t)}get(e,t=Vr){const r=n(this.share,e,(()=>{const e=new t;return e._integrate(this,null),e})),s=r.constructor;if(t!==Vr&&s!==t){if(s===Vr){const n=new t;n._map=r._map,r._map.forEach((e=>{for(;null!==e;e=e.left)e.parent=n})),n._start=r._start;for(let e=n._start;null!==e;e=e.right)e.parent=n;return n._length=r._length,this.share.set(e,n),n._integrate(this,null),n}throw new Error(`Type with the name ${e} has already been defined with a different constructor`)}return r}getArray(e=""){return this.get(e,ls)}getText(e=""){return this.get(e,As)}getMap(e=""){return this.get(e,us)}getXmlElement(e=""){return this.get(e,Is)}getXmlFragment(e=""){return this.get(e,Ds)}toJSON(){const e={};return this.share.forEach(((t,n)=>{e[n]=t.toJSON()})),e}destroy(){o(this.subdocs).forEach((e=>e.destroy()));const e=this._item;if(null!==e){this._item=null;const t=e.content;t.doc=new Ot({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,rr(e.parent.doc,(n=>{const r=t.doc;e.deleted||n.subdocsAdded.add(r),n.subdocsRemoved.add(this)}),null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class Nt{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return ce(this.restDecoder)}readDsLen(){return ce(this.restDecoder)}}class Ut extends Nt{readLeftID(){return ln(ce(this.restDecoder),ce(this.restDecoder))}readRightID(){return ln(ce(this.restDecoder),ce(this.restDecoder))}readClient(){return ce(this.restDecoder)}readInfo(){return ae(this.restDecoder)}readString(){return he(this.restDecoder)}readParentInfo(){return 1===ce(this.restDecoder)}readTypeRef(){return ce(this.restDecoder)}readLen(){return ce(this.restDecoder)}readAny(){return fe(this.restDecoder)}readBuf(){return(e=>{const t=Je(e.byteLength);return t.set(e),t})(oe(this.restDecoder))}readJSON(){return JSON.parse(he(this.restDecoder))}readKey(){return he(this.restDecoder)}}class Pt{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=ce(this.restDecoder),this.dsCurrVal}readDsLen(){const e=ce(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class jt extends Pt{constructor(e){super(e),this.keys=[],ce(e),this.keyClockDecoder=new ye(oe(e)),this.clientDecoder=new ge(oe(e)),this.leftClockDecoder=new ye(oe(e)),this.rightClockDecoder=new ye(oe(e)),this.infoDecoder=new pe(oe(e),ae),this.stringDecoder=new me(oe(e)),this.parentInfoDecoder=new pe(oe(e),ae),this.typeRefDecoder=new ge(oe(e)),this.lenDecoder=new ge(oe(e))}readLeftID(){return new an(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new an(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return 1===this.parentInfoDecoder.read()}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return fe(this.restDecoder)}readBuf(){return oe(this.restDecoder)}readJSON(){return fe(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{const e=this.stringDecoder.read();return this.keys.push(e),e}}}class Bt{constructor(){this.restEncoder=L()}toUint8Array(){return M(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){U(this.restEncoder,e)}writeDsLen(e){U(this.restEncoder,e)}}class Ft extends Bt{writeLeftID(e){U(this.restEncoder,e.client),U(this.restEncoder,e.clock)}writeRightID(e){U(this.restEncoder,e.client),U(this.restEncoder,e.clock)}writeClient(e){U(this.restEncoder,e)}writeInfo(e){N(this.restEncoder,e)}writeString(e){F(this.restEncoder,e)}writeParentInfo(e){U(this.restEncoder,e?1:0)}writeTypeRef(e){U(this.restEncoder,e)}writeLen(e){U(this.restEncoder,e)}writeAny(e){z(this.restEncoder,e)}writeBuf(e){V(this.restEncoder,e)}writeJSON(e){F(this.restEncoder,JSON.stringify(e))}writeKey(e){F(this.restEncoder,e)}}class Wt{constructor(){this.restEncoder=L(),this.dsCurrVal=0}toUint8Array(){return M(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,U(this.restEncoder,t)}writeDsLen(e){0===e&&ee(),U(this.restEncoder,e-1),this.dsCurrVal+=e}}class Vt extends Wt{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new G,this.clientEncoder=new Y,this.leftClockEncoder=new G,this.rightClockEncoder=new G,this.infoEncoder=new K(N),this.stringEncoder=new X,this.parentInfoEncoder=new K(N),this.typeRefEncoder=new Y,this.lenEncoder=new Y}toUint8Array(){const e=L();return U(e,0),V(e,this.keyClockEncoder.toUint8Array()),V(e,this.clientEncoder.toUint8Array()),V(e,this.leftClockEncoder.toUint8Array()),V(e,this.rightClockEncoder.toUint8Array()),V(e,M(this.infoEncoder)),V(e,this.stringEncoder.toUint8Array()),V(e,M(this.parentInfoEncoder)),V(e,this.typeRefEncoder.toUint8Array()),V(e,this.lenEncoder.toUint8Array()),W(e,M(this.restEncoder)),M(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){z(this.restEncoder,e)}writeBuf(e){V(this.restEncoder,e)}writeJSON(e){z(this.restEncoder,e)}writeKey(e){const t=this.keyMap.get(e);void 0===t?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}}const Ht=(e,t,n)=>{const r=new Map;n.forEach(((e,n)=>{Wn(t,n)>e&&r.set(n,e)})),Fn(t).forEach(((e,t)=>{n.has(t)||r.set(t,0)})),U(e.restEncoder,r.size),o(r.entries()).sort(((e,t)=>t[0]-e[0])).forEach((([n,r])=>{((e,t,n,r)=>{r=p(r,t[0].id.clock);const s=Hn(t,r);U(e.restEncoder,t.length-s),e.writeClient(n),U(e.restEncoder,r);const i=t[s];i.write(e,r-i.id.clock);for(let n=s+1;n<t.length;n++)t[n].write(e,0)})(e,t.clients.get(n),n,r)}))},qt=(t,r,s,i=new jt(t))=>rr(r,(t=>{t.local=!1;let r=!1;const s=t.doc,a=s.store,c=((t,n)=>{const r=e(),s=ce(t.restDecoder);for(let e=0;e<s;e++){const e=ce(t.restDecoder),s=new Array(e),i=t.readClient();let o=ce(t.restDecoder);r.set(i,{i:0,refs:s});for(let r=0;r<e;r++){const e=t.readInfo();switch(31&e){case 0:{const e=t.readLen();s[r]=new Ns(ln(i,o),e),o+=e;break}case 10:{const e=ce(t.restDecoder);s[r]=new ci(ln(i,o),e),o+=e;break}default:{const a=!(192&e),c=new ii(ln(i,o),null,(e&w)===w?t.readLeftID():null,null,(e&m)===m?t.readRightID():null,a?t.readParentInfo()?n.get(t.readString()):t.readLeftID():null,!a||32&~e?null:t.readString(),oi(t,e));s[r]=c,o+=c.length}}}}return r})(i,s),l=((e,t,r)=>{const s=[];let i=o(r.keys()).sort(((e,t)=>e-t));if(0===i.length)return null;const a=()=>{if(0===i.length)return null;let e=r.get(i[i.length-1]);for(;e.refs.length===e.i;){if(i.pop(),!(i.length>0))return null;e=r.get(i[i.length-1])}return e};let c=a();if(null===c)return null;const l=new Bn,h=new Map,u=(e,t)=>{const n=h.get(e);(null==n||n>t)&&h.set(e,t)};let d=c.refs[c.i++];const f=new Map,p=()=>{for(const e of s){const t=e.id.client,n=r.get(t);n?(n.i--,l.clients.set(t,n.refs.slice(n.i)),r.delete(t),n.i=0,n.refs=[]):l.clients.set(t,[e]),i=i.filter((e=>e!==t))}s.length=0};for(;;){if(d.constructor!==ci){const i=n(f,d.id.client,(()=>Wn(t,d.id.client)))-d.id.clock;if(i<0)s.push(d),u(d.id.client,d.id.clock-1),p();else{const n=d.getMissing(e,t);if(null!==n){s.push(d);const e=r.get(n)||{refs:[],i:0};if(e.refs.length!==e.i){d=e.refs[e.i++];continue}u(n,Wn(t,n)),p()}else(0===i||i<d.length)&&(d.integrate(e,i),f.set(d.id.client,d.id.clock+d.length))}}if(s.length>0)d=s.pop();else if(null!==c&&c.i<c.refs.length)d=c.refs[c.i++];else{if(c=a(),null===c)break;d=c.refs[c.i++]}}if(l.clients.size>0){const e=new Vt;return Ht(e,l,new Map),U(e.restEncoder,0),{missing:h,update:e.toUint8Array()}}return null})(t,a,c),h=a.pendingStructs;if(h){for(const[e,t]of h.missing)if(t<Wn(a,e)){r=!0;break}if(l){for(const[e,t]of l.missing){const n=h.missing.get(e);(null==n||n>t)&&h.missing.set(e,t)}h.update=_r([h.update,l.update])}}else a.pendingStructs=l;const u=Lt(i,t,a);if(a.pendingDs){const e=new jt(se(a.pendingDs));ce(e.restDecoder);const n=Lt(e,t,a);a.pendingDs=u&&n?_r([u,n]):u||n}else a.pendingDs=u;if(r){const e=a.pendingStructs.update;a.pendingStructs=null,Kt(t.doc,e)}}),s,!1),zt=(e,t,n)=>qt(e,t,n,new Ut(e)),Kt=(e,t,n,r=jt)=>{const s=se(t);qt(s,e,n,new r(s))},Jt=(e,t,n)=>Kt(e,t,n,Ut),Yt=(e,t=new Uint8Array([0]),n=new Vt)=>{((e,t,n=new Map)=>{Ht(e,t.store,n),Dt(e,Rt(t.store))})(n,e,Xt(t));const r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(vr(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===Ft)return pr(r.map(((e,t)=>0===t?e:Lr(e))));if(n.constructor===Vt)return _r(r)}return r[0]},$t=(e,t)=>Yt(e,t,new Ft),Gt=e=>{const t=new Map,n=ce(e.restDecoder);for(let r=0;r<n;r++){const n=ce(e.restDecoder),r=ce(e.restDecoder);t.set(n,r)}return t},Xt=e=>Gt(new Nt(se(e))),Zt=(e,t)=>(U(e.restEncoder,t.size),o(t.entries()).sort(((e,t)=>t[0]-e[0])).forEach((([t,n])=>{U(e.restEncoder,t),U(e.restEncoder,n)})),e),Qt=(e,t=new Wt)=>(e instanceof Map?Zt(t,e):((e,t)=>{Zt(e,Fn(t.store))})(t,e),t.toUint8Array()),en=e=>Qt(e,new Bt);class tn{constructor(){this.l=[]}}const nn=()=>new tn,rn=(e,t)=>e.l.push(t),sn=(e,t)=>{const n=e.l,r=n.length;e.l=n.filter((e=>t!==e)),r===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},on=(e,t,n)=>Oe(e.l,[t,n]);class an{constructor(e,t){this.client=e,this.clock=t}}const cn=(e,t)=>e===t||null!==e&&null!==t&&e.client===t.client&&e.clock===t.clock,ln=(e,t)=>new an(e,t),hn=(e,t)=>{U(e,t.client),U(e,t.clock)},un=e=>ln(ce(e),ce(e)),dn=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw ee()},fn=(e,t)=>{for(;null!==t;){if(t.parent===e)return!0;t=t.parent._item}return!1},pn=e=>{const t=[];let n=e._start;for(;n;)t.push(n),n=n.right;console.log("Children: ",t),console.log("Children content: ",t.filter((e=>!e.deleted)).map((e=>e.content)))};class gn{constructor(e,t=e.getMap("users")){const n=new Map;this.yusers=t,this.doc=e,this.clients=new Map,this.dss=n;const r=(e,t)=>{const n=e.get("ds"),r=e.get("ids"),s=e=>this.clients.set(e,t);n.observe((e=>{e.changes.added.forEach((e=>{e.content.getContent().forEach((e=>{e instanceof Uint8Array&&this.dss.set(t,St([this.dss.get(t)||At(),It(new Nt(se(e)))]))}))}))})),this.dss.set(t,St(n.map((e=>It(new Nt(se(e))))))),r.observe((e=>e.changes.added.forEach((e=>e.content.getContent().forEach(s))))),r.forEach(s)};t.observe((e=>{e.keysChanged.forEach((e=>r(t.get(e),e)))})),t.forEach(r)}setUserMapping(e,t,n,{filter:r=(()=>!0)}={}){const s=this.yusers;let i=s.get(n);i||(i=new us,i.set("ids",new ls),i.set("ds",new ls),s.set(n,i)),i.get("ids").push([t]),s.observe((e=>{setTimeout((()=>{const e=s.get(n);if(e!==i){i=e,this.clients.forEach(((e,t)=>{n===e&&i.get("ids").push([t])}));const t=new Bt,r=this.dss.get(n);r&&(Dt(t,r),i.get("ds").push([t.toUint8Array()]))}}),0)})),e.on("afterTransaction",(e=>{setTimeout((()=>{const t=i.get("ds"),n=e.deleteSet;if(e.local&&n.clients.size>0&&r(e,n)){const e=new Bt;Dt(e,n),t.push([e.toUint8Array()])}}))}))}getUserByClientId(e){return this.clients.get(e)||null}getUserByDeletedId(e){for(const[t,n]of this.dss.entries())if(kt(n,e))return t;return null}}class yn{constructor(e,t,n,r=0){this.type=e,this.tname=t,this.item=n,this.assoc=r}}const mn=e=>{const t={};return e.type&&(t.type=e.type),e.tname&&(t.tname=e.tname),e.item&&(t.item=e.item),null!=e.assoc&&(t.assoc=e.assoc),t},wn=e=>new yn(null==e.type?null:ln(e.type.client,e.type.clock),e.tname||null,null==e.item?null:ln(e.item.client,e.item.clock),null==e.assoc?0:e.assoc);class bn{constructor(e,t,n=0){this.type=e,this.index=t,this.assoc=n}}const _n=(e,t,n)=>{let r=null,s=null;return null===e._item?s=dn(e):r=ln(e._item.id.client,e._item.id.clock),new yn(r,s,t,n)},vn=(e,t,n=0)=>{let r=e._start;if(n<0){if(0===t)return _n(e,null,n);t--}for(;null!==r;){if(!r.deleted&&r.countable){if(r.length>t)return _n(e,ln(r.id.client,r.id.clock+t),n);t-=r.length}if(null===r.right&&n<0)return _n(e,r.lastId,n);r=r.right}return _n(e,null,n)},En=e=>{const t=L();return((e,t)=>{const{type:n,tname:r,item:s,assoc:i}=t;if(null!==s)U(e,0),hn(e,s);else if(null!==r)N(e,1),F(e,r);else{if(null===n)throw ee();N(e,2),hn(e,n)}P(e,i)})(t,e),M(t)},kn=e=>(e=>{let t=null,n=null,r=null;switch(ce(e)){case 0:r=un(e);break;case 1:n=he(e);break;case 2:t=un(e)}const s=ie(e)?le(e):0;return new yn(t,n,r,s)})(se(e)),Cn=(e,t)=>{const n=t.store,r=e.item,s=e.type,i=e.tname,o=e.assoc;let a=null,c=0;if(null!==r){if(Wn(n,r.client)<=r.clock)return null;const e=ei(n,r),t=e.item;if(!(t instanceof ii))return null;if(a=t.parent,null===a._item||!a._item.deleted){c=t.deleted||!t.countable?0:e.diff+(o>=0?0:1);let n=t.left;for(;null!==n;)!n.deleted&&n.countable&&(c+=n.length),n=n.left}}else{if(null!==i)a=t.get(i);else{if(null===s)throw ee();{if(Wn(n,s.client)<=s.clock)return null;const{item:e}=ei(n,s);if(!(e instanceof ii&&e.content instanceof Qs))return null;a=e.content.type}}c=o>=0?a._length:0}return((e,t,n=0)=>new bn(e,t,n))(a,c,e.assoc)},Sn=(e,t)=>e===t||null!==e&&null!==t&&e.tname===t.tname&&cn(e.item,t.item)&&cn(e.type,t.type)&&e.assoc===t.assoc;class Tn{constructor(e,t){this.ds=e,this.sv=t}}const An=(e,t)=>{const n=e.ds.clients,r=t.ds.clients,s=e.sv,i=t.sv;if(s.size!==i.size||n.size!==r.size)return!1;for(const[e,t]of s.entries())if(i.get(e)!==t)return!1;for(const[e,t]of n.entries()){const n=r.get(e)||[];if(t.length!==n.length)return!1;for(let e=0;e<t.length;e++){const r=t[e],s=n[e];if(r.clock!==s.clock||r.len!==s.len)return!1}}return!0},Rn=(e,t=new Wt)=>(Dt(t,e.ds),Zt(t,e.sv),t.toUint8Array()),Dn=e=>Rn(e,new Bt),In=(e,t=new Pt(se(e)))=>new Tn(It(t),Gt(t)),Ln=e=>In(e,new Nt(se(e))),xn=(e,t)=>new Tn(e,t),Mn=xn(At(),new Map),On=e=>xn(Rt(e.store),Fn(e.store)),Nn=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!kt(t.ds,e.id),Un=(e,t)=>{const s=n(e.meta,Un,r),i=e.doc.store;s.has(t)||(t.sv.forEach(((t,n)=>{t<Wn(i,n)&&Kn(e,ln(n,t))})),Et(e,t.ds,(e=>{})),s.add(t))},Pn=(e,t,n=new Ot)=>{if(e.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");const{sv:r,ds:s}=t,i=new Vt;return e.transact((t=>{let n=0;r.forEach((e=>{e>0&&n++})),U(i.restEncoder,n);for(const[n,s]of r){if(0===s)continue;s<Wn(e.store,n)&&Kn(t,ln(n,s));const r=e.store.clients.get(n)||[],o=Hn(r,s-1);U(i.restEncoder,o+1),i.writeClient(n),U(i.restEncoder,0);for(let e=0;e<=o;e++)r[e].write(i,0)}Dt(i,s)})),Kt(n,i.toUint8Array(),"snapshot"),n},jn=(e,t)=>((e,t,n=jt)=>{const r=new n(se(t)),s=new cr(r,!1);for(let t=s.curr;null!==t;t=s.next())if((e.sv.get(t.id.client)||0)<t.id.clock+t.length)return!1;const i=St([e.ds,It(r)]);return xt(e.ds,i)})(e,t,Ut);class Bn{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Fn=e=>{const t=new Map;return e.clients.forEach(((e,n)=>{const r=e[e.length-1];t.set(n,r.id.clock+r.length)})),t},Wn=(e,t)=>{const n=e.clients.get(t);if(void 0===n)return 0;const r=n[n.length-1];return r.id.clock+r.length},Vn=(e,t)=>{let n=e.clients.get(t.id.client);if(void 0===n)n=[],e.clients.set(t.id.client,n);else{const e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw ee()}n.push(t)},Hn=(e,t)=>{let n=0,r=e.length-1,s=e[r],i=s.id.clock;if(i===t)return r;let o=h(t/(i+s.length-1)*r);for(;n<=r;){if(s=e[o],i=s.id.clock,i<=t){if(t<i+s.length)return o;n=o+1}else r=o-1;o=h((n+r)/2)}throw ee()},qn=(e,t)=>{const n=e.clients.get(t.client);return n[Hn(n,t.clock)]},zn=(e,t,n)=>{const r=Hn(t,n),s=t[r];return s.id.clock<n&&s instanceof ii?(t.splice(r+1,0,ni(e,s,n-s.id.clock)),r+1):r},Kn=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[zn(e,n,t.clock)]},Jn=(e,t,n)=>{const r=t.clients.get(n.client),s=Hn(r,n.clock),i=r[s];return n.clock!==i.id.clock+i.length-1&&i.constructor!==Ns&&r.splice(s+1,0,ni(e,i,n.clock-i.id.clock+1)),i},Yn=(e,t,n,r,s)=>{if(0===r)return;const i=n+r;let o,a=zn(e,t,n);do{o=t[a++],i<o.id.clock+o.length&&zn(e,t,i),s(o)}while(a<t.length&&t[a].id.clock<i)};class $n{constructor(e,t,n){this.doc=e,this.deleteSet=new vt,this.beforeState=Fn(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const Gn=(e,t)=>!(0===t.deleteSet.clients.size&&!((e,t)=>{for(const[n,r]of e)if(t(r,n))return!0;return!1})(t.afterState,((e,n)=>t.beforeState.get(n)!==e)))&&(Ct(t.deleteSet),((e,t)=>{Ht(e,t.doc.store,t.beforeState)})(e,t),Dt(e,t.deleteSet),!0),Xn=(e,t,s)=>{const i=t._item;(null===i||i.id.clock<(e.beforeState.get(i.id.client)||0)&&!i.deleted)&&n(e.changed,t,r).add(s)},Zn=(e,t)=>{let n=e[t],r=e[t-1],s=t;for(;s>0&&(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n));n=r,r=e[--s-1])n instanceof ii&&null!==n.parentSub&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);const i=t-s;return i&&e.splice(t+1-i,i),i},Qn=(e,t,n)=>{for(const[r,s]of e.clients.entries()){const e=t.clients.get(r);for(let r=s.length-1;r>=0;r--){const i=s[r],o=i.clock+i.len;for(let r=Hn(e,i.clock),s=e[r];r<e.length&&s.id.clock<o;s=e[++r]){const s=e[r];if(i.clock+i.len<=s.id.clock)break;s instanceof ii&&s.deleted&&!s.keep&&n(s)&&s.gc(t,!1)}}}},er=(e,t)=>{e.clients.forEach(((e,n)=>{const r=t.clients.get(n);for(let t=e.length-1;t>=0;t--){const n=e[t];for(let e=f(r.length-1,1+Hn(r,n.clock+n.len-1)),t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+Zn(r,e)}}))},tr=(e,t,n)=>{Qn(e,t,n),er(e,t)},nr=(e,t)=>{if(t<e.length){const n=e[t],r=n.doc,s=r.store,i=n.deleteSet,o=n._mergeStructs;try{Ct(i),n.afterState=Fn(n.doc.store),r.emit("beforeObserverCalls",[n,r]);const e=[];n.changed.forEach(((t,r)=>e.push((()=>{null!==r._item&&r._item.deleted||r._callObserver(n,t)})))),e.push((()=>{n.changedParentTypes.forEach(((e,t)=>{t._dEH.l.length>0&&(null===t._item||!t._item.deleted)&&((e=e.filter((e=>null===e.target._item||!e.target._item.deleted))).forEach((e=>{e.currentTarget=t,e._path=null})),e.sort(((e,t)=>e.path.length-t.path.length)),on(t._dEH,e,n))}))})),e.push((()=>r.emit("afterTransaction",[n,r]))),Oe(e,[]),n._needFormattingCleanup&&Cs(n)}finally{r.gc&&Qn(i,s,r.gcFilter),er(i,s),n.afterState.forEach(((e,t)=>{const r=n.beforeState.get(t)||0;if(r!==e){const e=s.clients.get(t),n=p(Hn(e,r),1);for(let t=e.length-1;t>=n;)t-=1+Zn(e,t)}}));for(let e=o.length-1;e>=0;e--){const{client:t,clock:n}=o[e].id,r=s.clients.get(t),i=Hn(r,n);i+1<r.length&&Zn(r,i+1)>1||i>0&&Zn(r,i)}if(n.local||n.afterState.get(r.clientID)===n.beforeState.get(r.clientID)||(gt(ct,tt,"[yjs] ",nt,ot,"Changed the client-id because another client seems to be using it."),r.clientID=Mt()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){const e=new Ft;Gn(e,n)&&r.emit("update",[e.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){const e=new Vt;Gn(e,n)&&r.emit("updateV2",[e.toUint8Array(),n.origin,r,n])}const{subdocsAdded:a,subdocsLoaded:c,subdocsRemoved:l}=n;(a.size>0||l.size>0||c.size>0)&&(a.forEach((e=>{e.clientID=r.clientID,null==e.collectionid&&(e.collectionid=r.collectionid),r.subdocs.add(e)})),l.forEach((e=>r.subdocs.delete(e))),r.emit("subdocs",[{loaded:c,added:a,removed:l},r,n]),l.forEach((e=>e.destroy()))),e.length<=t+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,e])):nr(e,t+1)}}},rr=(e,t,n=null,r=!0)=>{const s=e._transactionCleanups;let i=!1,o=null;null===e._transaction&&(i=!0,e._transaction=new $n(e,n,r),s.push(e._transaction),1===s.length&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(i){const t=e._transaction===s[0];e._transaction=null,t&&nr(s,0)}}return o};class sr{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}}const ir=(e,t,n)=>{Et(e,n.deletions,(e=>{e instanceof ii&&t.scope.some((t=>fn(t,e)))&&ti(e,!1)}))},or=(e,t,n)=>{let r=null;const s=e.doc,i=e.scope;if(rr(s,(n=>{for(;t.length>0&&null===e.currStackItem;){const r=s.store,o=t.pop(),a=new Set,c=[];let l=!1;Et(n,o.insertions,(e=>{if(e instanceof ii){if(null!==e.redone){let{item:t,diff:s}=ei(r,e.id);s>0&&(t=Kn(n,ln(t.id.client,t.id.clock+s))),e=t}!e.deleted&&i.some((t=>fn(t,e)))&&c.push(e)}})),Et(n,o.deletions,(e=>{e instanceof ii&&i.some((t=>fn(t,e)))&&!kt(o.insertions,e.id)&&a.add(e)})),a.forEach((t=>{l=null!==si(n,t,a,o.insertions,e.ignoreRemoteMapChanges,e)||l}));for(let t=c.length-1;t>=0;t--){const r=c[t];e.deleteFilter(r)&&(r.delete(n),l=!0)}e.currStackItem=l?o:null}n.changed.forEach(((e,t)=>{e.has(null)&&t._searchMarker&&(t._searchMarker.length=0)})),r=n}),e),null!=e.currStackItem){const t=r.changedParentTypes;e.emit("stack-item-popped",[{stackItem:e.currStackItem,type:n,changedParentTypes:t,origin:e},e]),e.currStackItem=null}return e.currStackItem};class ar extends c{constructor(e,{captureTimeout:t=500,captureTransaction:n=(e=>!0),deleteFilter:r=(()=>!0),trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:i=!1,doc:o=(a(e)?e[0].doc:e.doc)}={}){super(),this.scope=[],this.doc=o,this.addToScope(e),this.deleteFilter=r,s.add(this),this.trackedOrigins=s,this.captureTransaction=n,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=i,this.captureTimeout=t,this.afterTransactionHandler=e=>{if(!(this.captureTransaction(e)&&this.scope.some((t=>e.changedParentTypes.has(t)))&&(this.trackedOrigins.has(e.origin)||e.origin&&this.trackedOrigins.has(e.origin.constructor))))return;const t=this.undoing,n=this.redoing,r=t?this.redoStack:this.undoStack;t?this.stopCapturing():n||this.clear(!1,!0);const s=new vt;e.afterState.forEach(((t,n)=>{const r=e.beforeState.get(n)||0,i=t-r;i>0&&Tt(s,n,r,i)}));const i=ke();let o=!1;if(this.lastChange>0&&i-this.lastChange<this.captureTimeout&&r.length>0&&!t&&!n){const t=r[r.length-1];t.deletions=St([t.deletions,e.deleteSet]),t.insertions=St([t.insertions,s])}else r.push(new sr(e.deleteSet,s)),o=!0;t||n||(this.lastChange=i),Et(e,e.deleteSet,(e=>{e instanceof ii&&this.scope.some((t=>fn(t,e)))&&ti(e,!0)}));const a=[{stackItem:r[r.length-1],origin:e.origin,type:t?"redo":"undo",changedParentTypes:e.changedParentTypes},this];o?this.emit("stack-item-added",a):this.emit("stack-item-updated",a)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",(()=>{this.destroy()}))}addToScope(e){(e=a(e)?e:[e]).forEach((e=>{this.scope.every((t=>t!==e))&&(e.doc!==this.doc&&((...e)=>{console.warn(...pt(e)),e.unshift(ct),yt.forEach((t=>t.print(e)))})("[yjs#509] Not same Y.Doc"),this.scope.push(e))}))}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact((n=>{e&&(this.undoStack.forEach((e=>ir(n,this,e))),this.undoStack=[]),t&&(this.redoStack.forEach((e=>ir(n,this,e))),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:t}])}))}stopCapturing(){this.lastChange=0}undo(){let e;this.undoing=!0;try{e=or(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){let e;this.redoing=!0;try{e=or(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}}class cr{constructor(e,t){this.gen=function*(e){const t=ce(e.restDecoder);for(let n=0;n<t;n++){const t=ce(e.restDecoder),n=e.readClient();let r=ce(e.restDecoder);for(let s=0;s<t;s++){const t=e.readInfo();if(10===t){const t=ce(e.restDecoder);yield new ci(ln(n,r),t),r+=t}else if(31&t){const s=!(192&t),i=new ii(ln(n,r),null,(t&w)===w?e.readLeftID():null,null,(t&m)===m?e.readRightID():null,s?e.readParentInfo()?e.readString():e.readLeftID():null,!s||32&~t?null:e.readString(),oi(e,t));yield i,r+=i.length}else{const t=e.readLen();yield new Ns(ln(n,r),t),r+=t}}}}(e),this.curr=null,this.done=!1,this.filterSkips=t,this.next()}next(){do{this.curr=this.gen.next().value||null}while(this.filterSkips&&null!==this.curr&&this.curr.constructor===ci);return this.curr}}const lr=e=>hr(e,Ut),hr=(e,t=jt)=>{const n=[],r=new t(se(e)),s=new cr(r,!1);for(let e=s.curr;null!==e;e=s.next())n.push(e);gt("Structs: ",n);const i=It(r);gt("DeleteSet: ",i)},ur=e=>dr(e,Ut),dr=(e,t=jt)=>{const n=[],r=new t(se(e)),s=new cr(r,!1);for(let e=s.curr;null!==e;e=s.next())n.push(e);return{structs:n,ds:It(r)}};class fr{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}}const pr=e=>_r(e,Ut,Ft),gr=(e,t=Wt,n=jt)=>{const r=new t,s=new cr(new n(se(e)),!1);let i=s.curr;if(null!==i){let e=0,t=i.id.client,n=0!==i.id.clock,o=n?0:i.id.clock+i.length;for(;null!==i;i=s.next())t!==i.id.client&&(0!==o&&(e++,U(r.restEncoder,t),U(r.restEncoder,o)),t=i.id.client,o=0,n=0!==i.id.clock),i.constructor===ci&&(n=!0),n||(o=i.id.clock+i.length);0!==o&&(e++,U(r.restEncoder,t),U(r.restEncoder,o));const a=L();return U(a,e),((e,t)=>{W(e,M(t))})(a,r.restEncoder),r.restEncoder=a,r.toUint8Array()}return U(r.restEncoder,0),r.toUint8Array()},yr=e=>gr(e,Bt,Ut),mr=(e,t=jt)=>{const n=new Map,r=new Map,s=new cr(new t(se(e)),!1);let i=s.curr;if(null!==i){let e=i.id.client,t=i.id.clock;for(n.set(e,t);null!==i;i=s.next())e!==i.id.client&&(r.set(e,t),n.set(i.id.client,i.id.clock),e=i.id.client),t=i.id.clock+i.length;r.set(e,t)}return{from:n,to:r}},wr=e=>mr(e,Ut),br=(e,t)=>{if(e.constructor===Ns){const{client:n,clock:r}=e.id;return new Ns(ln(n,r+t),e.length-t)}if(e.constructor===ci){const{client:n,clock:r}=e.id;return new ci(ln(n,r+t),e.length-t)}{const n=e,{client:r,clock:s}=n.id;return new ii(ln(r,s+t),null,ln(r,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},_r=(e,t=jt,n=Vt)=>{if(1===e.length)return e[0];const r=e.map((e=>new t(se(e))));let s=r.map((e=>new cr(e,!0))),i=null;const o=new n,a=new fr(o);for(;s=s.filter((e=>null!==e.curr)),s.sort(((e,t)=>{if(e.curr.id.client===t.curr.id.client){const n=e.curr.id.clock-t.curr.id.clock;return 0===n?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===ci?1:-1:n}return t.curr.id.client-e.curr.id.client})),0!==s.length;){const e=s[0],t=e.curr.id.client;if(null!==i){let n=e.curr,r=!1;for(;null!==n&&n.id.clock+n.length<=i.struct.id.clock+i.struct.length&&n.id.client>=i.struct.id.client;)n=e.next(),r=!0;if(null===n||n.id.client!==t||r&&n.id.clock>i.struct.id.clock+i.struct.length)continue;if(t!==i.struct.id.client)Cr(a,i.struct,i.offset),i={struct:n,offset:0},e.next();else if(i.struct.id.clock+i.struct.length<n.id.clock)if(i.struct.constructor===ci)i.struct.length=n.id.clock+n.length-i.struct.id.clock;else{Cr(a,i.struct,i.offset);const e=n.id.clock-i.struct.id.clock-i.struct.length;i={struct:new ci(ln(t,i.struct.id.clock+i.struct.length),e),offset:0}}else{const t=i.struct.id.clock+i.struct.length-n.id.clock;t>0&&(i.struct.constructor===ci?i.struct.length-=t:n=br(n,t)),i.struct.mergeWith(n)||(Cr(a,i.struct,i.offset),i={struct:n,offset:0},e.next())}}else i={struct:e.curr,offset:0},e.next();for(let n=e.curr;null!==n&&n.id.client===t&&n.id.clock===i.struct.id.clock+i.struct.length&&n.constructor!==ci;n=e.next())Cr(a,i.struct,i.offset),i={struct:n,offset:0}}null!==i&&(Cr(a,i.struct,i.offset),i=null),Sr(a);const c=r.map((e=>It(e))),l=St(c);return Dt(o,l),o.toUint8Array()},vr=(e,t,n=jt,r=Vt)=>{const s=Xt(t),i=new r,o=new fr(i),a=new n(se(e)),c=new cr(a,!1);for(;c.curr;){const e=c.curr,t=e.id.client,n=s.get(t)||0;if(c.curr.constructor!==ci)if(e.id.clock+e.length>n)for(Cr(o,e,p(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)Cr(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===t&&c.curr.id.clock+c.curr.length<=n;)c.next();else c.next()}Sr(o);const l=It(a);return Dt(i,l),i.toUint8Array()},Er=(e,t)=>vr(e,t,Ut,Ft),kr=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:M(e.encoder.restEncoder)}),e.encoder.restEncoder=L(),e.written=0)},Cr=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&kr(e),0===e.written&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),U(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Sr=e=>{kr(e);const t=e.encoder.restEncoder;U(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const r=e.clientStructs[n];U(t,r.written),W(t,r.restEncoder)}},Tr=(e,t,n,r)=>{const s=new n(se(e)),i=new cr(s,!1),o=new r,a=new fr(o);for(let e=i.curr;null!==e;e=i.next())Cr(a,t(e),0);Sr(a);const c=It(s);return Dt(o,c),o.toUint8Array()},Ar=({formatting:t=!0,subdocs:r=!0,yxml:s=!0}={})=>{let i=0;const o=e(),a=e(),c=e(),l=e();return l.set(null,null),e=>{switch(e.constructor){case Ns:case ci:return e;case ii:{const h=e,u=h.content;switch(u.constructor){case Ps:break;case Qs:if(s){const e=u.type;e instanceof Is&&(e.nodeName=n(a,e.nodeName,(()=>"node-"+i))),e instanceof xs&&(e.hookName=n(a,e.hookName,(()=>"hook-"+i)))}break;case Hs:{const e=u;e.arr=e.arr.map((()=>i));break}case Us:u.content=new Uint8Array([i]);break;case Bs:{const e=u;r&&(e.opts={},e.doc.guid=i+"");break}case Fs:u.embed={};break;case Ws:{const e=u;t&&(e.key=n(c,e.key,(()=>i+"")),e.value=n(l,e.value,(()=>({i:i}))));break}case Vs:{const e=u;e.arr=e.arr.map((()=>i));break}case qs:{const e=u;e.str=D(i%10+"",e.str.length);break}default:ee()}return h.parentSub&&(h.parentSub=n(o,h.parentSub,(()=>i+""))),i++,e}default:ee()}}},Rr=(e,t)=>Tr(e,Ar(t),Ut,Ft),Dr=(e,t)=>Tr(e,Ar(t),jt,Vt),Ir=e=>Tr(e,Ue,Ut,Vt),Lr=e=>Tr(e,Ue,jt,Ft),xr="You must not compute changes after the event-handler fired.";class Mr{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Or(this.currentTarget,this.target))}deletes(e){return kt(this.transaction.deleteSet,e.id)}get keys(){if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw Z(xr);const e=new Map,t=this.target;this.transaction.changed.get(t).forEach((n=>{if(null!==n){const r=t._map.get(n);let i,o;if(this.adds(r)){let e=r.left;for(;null!==e&&this.adds(e);)e=e.left;if(this.deletes(r)){if(null===e||!this.deletes(e))return;i="delete",o=s(e.content.getContent())}else null!==e&&this.deletes(e)?(i="update",o=s(e.content.getContent())):(i="add",o=void 0)}else{if(!this.deletes(r))return;i="delete",o=s(r.content.getContent())}e.set(n,{action:i,oldValue:o})}})),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(null===e){if(0===this.transaction.doc._transactionCleanups.length)throw Z(xr);const t=this.target,n=r(),s=r(),i=[];e={added:n,deleted:s,delta:i,keys:this.keys};if(this.transaction.changed.get(t).has(null)){let e=null;const r=()=>{e&&i.push(e)};for(let i=t._start;null!==i;i=i.right)i.deleted?this.deletes(i)&&!this.adds(i)&&(null!==e&&void 0!==e.delete||(r(),e={delete:0}),e.delete+=i.length,s.add(i)):this.adds(i)?(null!==e&&void 0!==e.insert||(r(),e={insert:[]}),e.insert=e.insert.concat(i.content.getContent()),n.add(i)):(null!==e&&void 0!==e.retain||(r(),e={retain:0}),e.retain+=i.length);null!==e&&void 0===e.retain&&r()}this._changes=e}return e}}const Or=(e,t)=>{const n=[];for(;null!==t._item&&t!==e;){if(null!==t._item.parentSub)n.unshift(t._item.parentSub);else{let e=0,r=t._item.parent._start;for(;r!==t._item&&null!==r;)r.deleted||e++,r=r.right;n.unshift(e)}t=t._item.parent}return n};let Nr=0;class Ur{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Nr++}}const Pr=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Nr++},jr=(e,t)=>{if(null===e._start||0===t||null===e._searchMarker)return null;const n=0===e._searchMarker.length?null:e._searchMarker.reduce(((e,n)=>u(t-e.index)<u(t-n.index)?e:n));let r=e._start,s=0;for(null!==n&&(r=n.p,s=n.index,(e=>{e.timestamp=Nr++})(n));null!==r.right&&s<t;){if(!r.deleted&&r.countable){if(t<s+r.length)break;s+=r.length}r=r.right}for(;null!==r.left&&s>t;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);for(;null!==r.left&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);return null!==n&&u(n.index-s)<r.parent.length/80?(Pr(n,r,s),n):((e,t,n)=>{if(e.length>=80){const r=e.reduce(((e,t)=>e.timestamp<t.timestamp?e:t));return Pr(r,t,n),r}{const r=new Ur(t,n);return e.push(r),r}})(e._searchMarker,r,s)},Br=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){const s=e[r];if(n>0){let t=s.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(s.index-=t.length);if(null===t||!0===t.marker){e.splice(r,1);continue}s.p=t,t.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=p(t,s.index+n))}},Fr=e=>{let t=e._start;const n=[];for(;t;)n.push(t),t=t.right;return n},Wr=(e,t,r)=>{const s=e,i=t.changedParentTypes;for(;n(i,e,(()=>[])).push(r),null!==e._item;)e=e._item.parent;on(s._eH,r,t)};class Vr{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=nn(),this._dEH=nn(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw Q()}clone(){throw Q()}_write(e){}get _first(){let e=this._start;for(;null!==e&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){rn(this._eH,e)}observeDeep(e){rn(this._dEH,e)}unobserve(e){sn(this._eH,e)}unobserveDeep(e){sn(this._dEH,e)}toJSON(){}}const Hr=(e,t,n)=>{t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t;const s=[];let i=e._start;for(;null!==i&&r>0;){if(i.countable&&!i.deleted){const e=i.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n<e.length&&r>0;n++)s.push(e[n]),r--;t=0}}i=i.right}return s},qr=e=>{const t=[];let n=e._start;for(;null!==n;){if(n.countable&&!n.deleted){const e=n.content.getContent();for(let n=0;n<e.length;n++)t.push(e[n])}n=n.right}return t},zr=(e,t)=>{const n=[];let r=e._start;for(;null!==r;){if(r.countable&&Nn(r,t)){const e=r.content.getContent();for(let t=0;t<e.length;t++)n.push(e[t])}r=r.right}return n},Kr=(e,t)=>{let n=0,r=e._start;for(;null!==r;){if(r.countable&&!r.deleted){const s=r.content.getCo