@editora/plugins 1.0.19 → 1.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/{CodePlugin.native-Bwf25lLX.js → CodePlugin.native-CKJo7IFG.js} +8 -8
  2. package/dist/{CodePlugin.native-Cpp4u3Jl.mjs → CodePlugin.native-D8gGxB8i.mjs} +59 -60
  3. package/dist/a11y-checker.cjs.js +1 -1
  4. package/dist/a11y-checker.esm.js +18 -18
  5. package/dist/anchor.cjs.js +6 -6
  6. package/dist/anchor.esm.js +57 -57
  7. package/dist/blockquote.cjs.js +1 -1
  8. package/dist/blockquote.esm.js +31 -31
  9. package/dist/capitalization.cjs.js +1 -1
  10. package/dist/capitalization.esm.js +25 -25
  11. package/dist/checklist.cjs.js +1 -1
  12. package/dist/checklist.esm.js +30 -30
  13. package/dist/code.cjs.js +1 -1
  14. package/dist/code.esm.js +1 -1
  15. package/dist/collaboration.cjs.js +8 -8
  16. package/dist/collaboration.esm.js +1279 -1169
  17. package/dist/comments.cjs.js +1 -1
  18. package/dist/comments.esm.js +1 -1
  19. package/dist/direction.cjs.js +1 -1
  20. package/dist/direction.esm.js +26 -26
  21. package/dist/document-manager.cjs.js +1 -1
  22. package/dist/document-manager.esm.js +1 -1
  23. package/dist/{documentManager-yjRBab4v.mjs → documentManager-BL98a7YZ.mjs} +402 -404
  24. package/dist/{documentManager-BDz6tovy.js → documentManager-r8t7yZEd.js} +9 -9
  25. package/dist/enterprise.cjs.js +1 -1
  26. package/dist/enterprise.esm.js +1 -1
  27. package/dist/font-family.cjs.js +1 -1
  28. package/dist/font-family.esm.js +26 -26
  29. package/dist/{index-Bm1eqYHh.mjs → index-B-VitI3v.mjs} +23 -22
  30. package/dist/{index-CoflqYuK.js → index-D5xugkYA.js} +2 -2
  31. package/dist/index.cjs.js +1 -1
  32. package/dist/index.esm.js +2 -2
  33. package/dist/preview.cjs.js +3 -3
  34. package/dist/preview.esm.js +48 -51
  35. package/dist/purify.es-B6PsRpEV.js +3 -0
  36. package/dist/purify.es-DmCsrgBd.mjs +1480 -0
  37. package/dist/sanitizeHtml-CDoBlNTk.js +1 -0
  38. package/dist/sanitizeHtml-CtLy8um-.mjs +16 -0
  39. package/dist/spell-check.cjs.js +2 -2
  40. package/dist/spell-check.esm.js +19 -19
  41. package/dist/table.cjs.js +14 -14
  42. package/dist/table.esm.js +158 -150
  43. package/dist/template.cjs.js +20 -21
  44. package/dist/template.esm.js +176 -724
  45. package/package.json +6 -4
@@ -1,9 +1,9 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const R=()=>new Map,tn=e=>{const t=R();return e.forEach((n,s)=>{t.set(s,n)}),t},K=(e,t,n)=>{let s=e.get(t);return s===void 0&&e.set(t,s=n()),s},si=(e,t)=>{const n=[];for(const[s,r]of e)n.push(t(r,s));return n},ri=(e,t)=>{for(const[n,s]of e)if(t(s,n))return!0;return!1},rt=()=>new Set,je=e=>e[e.length-1],ii=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},P=Array.from,gn=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},pn=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},oi=(e,t)=>{const n=new Array(e);for(let s=0;s<e;s++)n[s]=t(s,n);return n},It=Array.isArray;class wn{constructor(){this._observers=R()}on(t,n){return K(this._observers,t,rt).add(n),n}once(t,n){const s=(...r)=>{this.off(t,s),n(...r)};this.on(t,s)}off(t,n){const s=this._observers.get(t);s!==void 0&&(s.delete(n),s.size===0&&this._observers.delete(t))}emit(t,n){return P((this._observers.get(t)||R()).values()).forEach(s=>s(...n))}destroy(){this._observers=R()}}class ci{constructor(){this._observers=R()}on(t,n){K(this._observers,t,rt).add(n)}once(t,n){const s=(...r)=>{this.off(t,s),n(...r)};this.on(t,s)}off(t,n){const s=this._observers.get(t);s!==void 0&&(s.delete(n),s.size===0&&this._observers.delete(t))}emit(t,n){return P((this._observers.get(t)||R()).values()).forEach(s=>s(...n))}destroy(){this._observers=R()}}const H=Math.floor,ce=Math.abs,mn=(e,t)=>e<t?e:t,wt=(e,t)=>e>t?e:t,li=Math.pow,Ts=e=>e!==0?e<0:1/e<0,Pn=1,qn=2,He=4,Ye=8,jt=32,X=64,$=128,Ae=31,en=63,ht=127,hi=2147483647,fe=Number.MAX_SAFE_INTEGER,Qn=Number.MIN_SAFE_INTEGER,ai=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&H(e)===e),Ls=String.fromCharCode,ui=e=>e.toLowerCase(),di=/^\s*/g,fi=e=>e.replace(di,""),gi=/([A-Z])/g,Zn=(e,t)=>fi(e.replace(gi,n=>`${t}${ui(n)}`)),pi=e=>{const t=unescape(encodeURIComponent(e)),n=t.length,s=new Uint8Array(n);for(let r=0;r<n;r++)s[r]=t.codePointAt(r);return s},Ht=typeof TextEncoder<"u"?new TextEncoder:null,wi=e=>Ht.encode(e),mi=Ht?wi:pi;let Vt=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Vt&&Vt.decode(new Uint8Array).length===1&&(Vt=null);const yi=(e,t)=>oi(t,()=>e).join("");class qt{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const N=()=>new qt,yn=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},C=e=>{const t=new Uint8Array(yn(e));let n=0;for(let s=0;s<e.bufs.length;s++){const r=e.bufs[s];t.set(r,n),n+=r.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},bi=(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(wt(n,t)*2),e.cpos=0)},I=(e,t)=>{const n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},nn=I,p=(e,t)=>{for(;t>ht;)I(e,$|ht&t),t=H(t/128);I(e,ht&t)},bn=(e,t)=>{const n=Ts(t);for(n&&(t=-t),I(e,(t>en?$:0)|(n?X:0)|en&t),t=H(t/64);t>0;)I(e,(t>ht?$:0)|ht&t),t=H(t/128)},sn=new Uint8Array(3e4),ki=sn.length/3,_i=(e,t)=>{if(t.length<ki){const n=Ht.encodeInto(t,sn).written||0;p(e,n);for(let s=0;s<n;s++)I(e,sn[s])}else E(e,mi(t))},Si=(e,t)=>{const n=unescape(encodeURIComponent(t)),s=n.length;p(e,s);for(let r=0;r<s;r++)I(e,n.codePointAt(r))},at=Ht&&Ht.encodeInto?_i:Si,xe=(e,t)=>{const n=e.cbuf.length,s=e.cpos,r=mn(n-s,t.length),i=t.length-r;e.cbuf.set(t.subarray(0,r),s),e.cpos+=r,i>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(wt(n*2,i)),e.cbuf.set(t.subarray(r)),e.cpos=i)},E=(e,t)=>{p(e,t.byteLength),xe(e,t)},kn=(e,t)=>{bi(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Ci=(e,t)=>kn(e,4).setFloat32(0,t,!1),Ei=(e,t)=>kn(e,8).setFloat64(0,t,!1),Di=(e,t)=>kn(e,8).setBigInt64(0,t,!1),ts=new DataView(new ArrayBuffer(4)),Ai=e=>(ts.setFloat32(0,e),ts.getFloat32(0)===e),Yt=(e,t)=>{switch(typeof t){case"string":I(e,119),at(e,t);break;case"number":ai(t)&&ce(t)<=hi?(I(e,125),bn(e,t)):Ai(t)?(I(e,124),Ci(e,t)):(I(e,123),Ei(e,t));break;case"bigint":I(e,122),Di(e,t);break;case"object":if(t===null)I(e,126);else if(It(t)){I(e,117),p(e,t.length);for(let n=0;n<t.length;n++)Yt(e,t[n])}else if(t instanceof Uint8Array)I(e,116),E(e,t);else{I(e,118);const n=Object.keys(t);p(e,n.length);for(let s=0;s<n.length;s++){const r=n[s];at(e,r),Yt(e,t[r])}}break;case"boolean":I(e,t?120:121);break;default:I(e,127)}};class es extends qt{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&p(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const ns=e=>{e.count>0&&(bn(e.encoder,e.count===1?e.s:-e.s),e.count>1&&p(e.encoder,e.count-2))};class le{constructor(){this.encoder=new qt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(ns(this),this.count=1,this.s=t)}toUint8Array(){return ns(this),C(this.encoder)}}const ss=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);bn(e.encoder,t),e.count>1&&p(e.encoder,e.count-2)}};class ze{constructor(){this.encoder=new qt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(ss(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return ss(this),C(this.encoder)}}class xi{constructor(){this.sarr=[],this.s="",this.lensE=new le}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new qt;return this.sarr.push(this.s),this.s="",at(t,this.sarr.join("")),xe(t,this.lensE.toUint8Array()),C(t)}}const z=e=>new Error(e),j=()=>{throw z("Method unimplemented")},F=()=>{throw z("Unexpected case")},Ie=z("Unexpected end of array"),Os=z("Integer out of Range"),Ii=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw Ie;return new Uint8Array(e.buffer,e.byteOffset+t,n)},Ti=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw Ie;return new DataView(e.buffer,e.byteOffset+t,n)};class Te{constructor(t){this.arr=t,this.pos=0}}const ct=e=>new Te(e),Li=e=>e.pos!==e.arr.length,Oi=(e,t)=>{const n=Ii(e.arr,e.pos,t);return e.pos+=t,n},O=e=>Oi(e,m(e)),Tt=e=>e.arr[e.pos++],m=e=>{let t=0,n=1;const s=e.arr.length;for(;e.pos<s;){const r=e.arr[e.pos++];if(t=t+(r&ht)*n,n*=128,r<$)return t;if(t>fe)throw Os}throw Ie},_n=e=>{let t=e.arr[e.pos++],n=t&en,s=64;const r=(t&X)>0?-1:1;if((t&$)===0)return r*n;const i=e.arr.length;for(;e.pos<i;){if(t=e.arr[e.pos++],n=n+(t&ht)*s,s*=128,t<$)return r*n;if(n>fe)throw Os}throw Ie},Ni=e=>{let t=m(e);if(t===0)return"";{let n=String.fromCodePoint(Tt(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(Tt(e));else for(;t>0;){const s=t<1e4?t:1e4,r=e.arr.subarray(e.pos,e.pos+s);e.pos+=s,n+=String.fromCodePoint.apply(null,r),t-=s}return decodeURIComponent(escape(n))}},Mi=e=>Vt.decode(O(e)),st=Vt?Mi:Ni,Sn=(e,t)=>{const n=Ti(e.arr,e.pos,t);return e.pos+=t,n},Ui=e=>Sn(e,4).getFloat32(0,!1),vi=e=>Sn(e,8).getFloat64(0,!1),Ri=e=>Sn(e,8).getBigInt64(0,!1),$i=[e=>{},e=>null,_n,Ui,vi,Ri,e=>!1,e=>!0,st,e=>{const t=m(e),n={};for(let s=0;s<t;s++){const r=st(e);n[r]=zt(e)}return n},e=>{const t=m(e),n=[];for(let s=0;s<t;s++)n.push(zt(e));return n},O],zt=e=>$i[127-Tt(e)](e);class rs extends Te{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Li(this)?this.count=m(this)+1:this.count=-1),this.count--,this.s}}class he extends Te{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=_n(this);const t=Ts(this.s);this.count=1,t&&(this.s=-this.s,this.count=m(this)+2)}return this.count--,this.s}}class Je extends Te{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=_n(this),n=t&1;this.diff=H(t/2),this.count=1,n&&(this.count=m(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Bi{constructor(t){this.decoder=new he(t),this.str=st(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}}const Vi=crypto.getRandomValues.bind(crypto),Ns=()=>Vi(new Uint32Array(1))[0],Fi="10000000-1000-4000-8000"+-1e11,ji=()=>Fi.replace(/[018]/g,e=>(e^Ns()&15>>e/4).toString(16)),it=Date.now,is=e=>new Promise(e);Promise.all.bind(Promise);const os=e=>e===void 0?null:e;class Hi{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}}let Ms=new Hi,Cn=!0;try{typeof localStorage<"u"&&localStorage&&(Ms=localStorage,Cn=!1)}catch{}const Us=Ms,Yi=e=>Cn||addEventListener("storage",e),zi=e=>Cn||removeEventListener("storage",e),Jt=Symbol("Equality"),vs=(e,t)=>e===t||!!e?.[Jt]?.(t)||!1,Ji=e=>typeof e=="object",Gi=Object.assign,Ki=Object.keys,Wi=(e,t)=>{for(const n in e)t(e[n],n)},Xi=(e,t)=>{const n=[];for(const s in e)n.push(t(e[s],s));return n},ge=e=>Ki(e).length,Pi=e=>{for(const t in e)return!1;return!0},Qt=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},En=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),qi=(e,t)=>e===t||ge(e)===ge(t)&&Qt(e,(n,s)=>(n!==void 0||En(t,s))&&vs(t[s],n)),Qi=Object.freeze,Rs=e=>{for(const t in e){const n=e[t];(typeof n=="object"||typeof n=="function")&&Rs(e[t])}return Qi(e)},Dn=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Dn(e,t,n+1)}},Zi=e=>e,Ct=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[Jt]!=null)return e[Jt](t);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)||!Ct(e.get(n),t.get(n)))return!1;break}case void 0:case Object:if(ge(e)!==ge(t))return!1;for(const n in e)if(!En(e,n)||!Ct(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(!Ct(e[n],t[n]))return!1;break;default:return!1}return!0},to=(e,t)=>t.includes(e),ot=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",$s=typeof window<"u"&&typeof document<"u"&&!ot;let Y;const eo=()=>{if(Y===void 0)if(ot){Y=R();const e=process.argv;let t=null;for(let n=0;n<e.length;n++){const s=e[n];s[0]==="-"?(t!==null&&Y.set(t,""),t=s):t!==null&&(Y.set(t,s),t=null)}t!==null&&Y.set(t,"")}else typeof location=="object"?(Y=R(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){const[t,n]=e.split("=");Y.set(`--${Zn(t,"-")}`,n),Y.set(`-${Zn(t,"-")}`,n)}})):Y=R();return Y},rn=e=>eo().has(e),pe=e=>os(ot?process.env[e.toUpperCase().replaceAll("-","_")]:Us.getItem(e)),Bs=e=>rn("--"+e)||pe(e)!==null,no=Bs("production"),so=ot&&to(process.env.FORCE_COLOR,["true","1","2"]),ro=so||!rn("--no-colors")&&!Bs("no-color")&&(!ot||process.stdout.isTTY)&&(!ot||rn("--color")||pe("COLORTERM")!==null||(pe("TERM")||"").includes("color")),Vs=e=>new Uint8Array(e),io=e=>new Uint8Array(e),oo=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=Ls(e[n]);return btoa(t)},co=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),lo=e=>{const t=atob(e),n=Vs(t.length);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return n},ho=e=>new Uint8Array(Buffer.from(e,"base64")),ao=$s?oo:co,uo=$s?lo:ho,fo=e=>{const t=Vs(e.byteLength);return t.set(e),t};class go{constructor(t,n){this.left=t,this.right=n}}const W=(e,t)=>new go(e,t),cs=e=>e.next()>=.5,Ge=(e,t,n)=>H(e.next()*(n+1-t)+t),Fs=(e,t,n)=>H(e.next()*(n+1-t)+t),An=(e,t,n)=>Fs(e,t,n),po=e=>Ls(An(e,97,122)),wo=(e,t=0,n=20)=>{const s=An(e,t,n);let r="";for(let i=0;i<s;i++)r+=po(e);return r},Ke=(e,t)=>t[An(e,0,t.length-1)],mo=Symbol("0schema");class yo{constructor(){this._rerrs=[]}extend(t,n,s,r=null){this._rerrs.push({path:t,expected:n,has:s,message:r})}toString(){const t=[];for(let n=this._rerrs.length-1;n>0;n--){const s=this._rerrs[n];t.push(yi(" ",(this._rerrs.length-n)*2)+`${s.path!=null?`[${s.path}] `:""}${s.has} doesn't match ${s.expected}. ${s.message}`)}return t.join(`
2
- `)}}const on=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[Jt]?vs(e,t):It(e)?gn(e,n=>pn(t,s=>on(n,s))):Ji(e)?Qt(e,(n,s)=>on(n,t[s])):!1;class U{static _dilutes=!1;extends(t){let[n,s]=[this.shape,t.shape];return this.constructor._dilutes&&([s,n]=[n,s]),on(n,s)}equals(t){return this.constructor===t.constructor&&Ct(this.shape,t.shape)}[mo](){return!0}[Jt](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){j()}get nullable(){return vt(this,Ue)}get optional(){return new Ys(this)}cast(t){return ls(t,this),t}expect(t){return ls(t,this),t}}class xn extends U{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n=void 0){const s=t?.constructor===this.shape&&(this._c==null||this._c(t));return!s&&n?.extend(null,this.shape.name,t?.constructor.name,t?.constructor!==this.shape?"Constructor match failed":"Check failed"),s}}const D=(e,t=null)=>new xn(e,t);D(xn);class In extends U{constructor(t){super(),this.shape=t}check(t,n){const s=this.shape(t);return!s&&n?.extend(null,"custom prop",t?.constructor.name,"failed to check custom prop"),s}}const L=e=>new In(e);D(In);class Le extends U{constructor(t){super(),this.shape=t}check(t,n){const s=this.shape.some(r=>r===t);return!s&&n?.extend(null,this.shape.join(" | "),t.toString()),s}}const Oe=(...e)=>new Le(e),js=D(Le),bo=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,t=>"\\"+t)),Hs=e=>{if(Lt.check(e))return[bo(e)];if(js.check(e))return e.shape.map(t=>t+"");if(Qs.check(e))return["[+-]?\\d+.?\\d*"];if(Zs.check(e))return[".*"];if(we.check(e))return e.shape.map(Hs).flat(1);F()};class ko extends U{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(Hs).map(n=>`(${n.join("|")})`).join("")+"$")}check(t,n){const s=this._r.exec(t)!=null;return!s&&n?.extend(null,this._r.toString(),t.toString(),"String doesn't match string template."),s}}D(ko);const _o=Symbol("optional");class Ys extends U{constructor(t){super(),this.shape=t}check(t,n){const s=t===void 0||this.shape.check(t);return!s&&n?.extend(null,"undefined (optional)","()"),s}get[_o](){return!0}}const So=D(Ys);class Co extends U{check(t,n){return n?.extend(null,"never",typeof t),!1}}D(Co);class Ne extends U{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}static _dilutes=!0;get partial(){return new Ne(this.shape,!0)}check(t,n){return t==null?(n?.extend(null,"object","null"),!1):Qt(this.shape,(s,r)=>{const i=this._isPartial&&!En(t,r)||s.check(t[r],n);return!i&&n?.extend(r.toString(),s.toString(),typeof t[r],"Object property does not match"),i})}}const Eo=e=>new Ne(e),Do=D(Ne),Ao=L(e=>e!=null&&(e.constructor===Object||e.constructor==null));class zs extends U{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return t!=null&&Qt(t,(s,r)=>{const i=this.shape.keys.check(r,n);return!i&&n?.extend(r+"","Record",typeof t,i?"Key doesn't match schema":"Value doesn't match value"),i&&this.shape.values.check(s,n)})}}const Js=(e,t)=>new zs(e,t),xo=D(zs);class Gs extends U{constructor(t){super(),this.shape=t}check(t,n){return t!=null&&Qt(this.shape,(s,r)=>{const i=s.check(t[r],n);return!i&&n?.extend(r.toString(),"Tuple",typeof s),i})}}const Io=(...e)=>new Gs(e);D(Gs);class Ks extends U{constructor(t){super(),this.shape=t.length===1?t[0]:new Tn(t)}check(t,n){const s=It(t)&&gn(t,r=>this.shape.check(r));return!s&&n?.extend(null,"Array",""),s}}const Ws=(...e)=>new Ks(e),To=D(Ks),Lo=L(e=>It(e));class Xs extends U{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n){const s=t instanceof this.shape&&(this._c==null||this._c(t));return!s&&n?.extend(null,this.shape.name,t?.constructor.name),s}}const Oo=(e,t=null)=>new Xs(e,t);D(Xs);const No=Oo(U);class Mo extends U{constructor(t){super(),this.len=t.length-1,this.args=Io(...t.slice(-1)),this.res=t[this.len]}check(t,n){const s=t.constructor===Function&&t.length<=this.len;return!s&&n?.extend(null,"function",typeof t),s}}const Uo=D(Mo),vo=L(e=>typeof e=="function");class Ro extends U{constructor(t){super(),this.shape=t}check(t,n){const s=gn(this.shape,r=>r.check(t,n));return!s&&n?.extend(null,"Intersectinon",typeof t),s}}D(Ro,e=>e.shape.length>0);class Tn extends U{static _dilutes=!0;constructor(t){super(),this.shape=t}check(t,n){const s=pn(this.shape,r=>r.check(t,n));return n?.extend(null,"Union",typeof t),s}}const vt=(...e)=>e.findIndex(t=>we.check(t))>=0?vt(...e.map(t=>Gt(t)).map(t=>we.check(t)?t.shape:[t]).flat(1)):e.length===1?e[0]:new Tn(e),we=D(Tn),Ps=()=>!0,me=L(Ps),$o=D(In,e=>e.shape===Ps),Ln=L(e=>typeof e=="bigint"),Bo=L(e=>e===Ln),qs=L(e=>typeof e=="symbol");L(e=>e===qs);const Et=L(e=>typeof e=="number"),Qs=L(e=>e===Et),Lt=L(e=>typeof e=="string"),Zs=L(e=>e===Lt),Me=L(e=>typeof e=="boolean"),Vo=L(e=>e===Me),tr=Oe(void 0);D(Le,e=>e.shape.length===1&&e.shape[0]===void 0);Oe(void 0);const Ue=Oe(null),Fo=D(Le,e=>e.shape.length===1&&e.shape[0]===null);D(Uint8Array);D(xn,e=>e.shape===Uint8Array);const jo=vt(Et,Lt,Ue,tr,Ln,Me,qs);(()=>{const e=Ws(me),t=Js(Lt,me),n=vt(Et,Lt,Ue,Me,e,t);return e.shape=n,t.shape.values=n,n})();const Gt=e=>{if(No.check(e))return e;if(Ao.check(e)){const t={};for(const n in e)t[n]=Gt(e[n]);return Eo(t)}else{if(Lo.check(e))return vt(...e.map(Gt));if(jo.check(e))return Oe(e);if(vo.check(e))return D(e)}F()},ls=no?()=>{}:(e,t)=>{const n=new yo;if(!t.check(e,n))throw z(`Expected value to be of type ${t.constructor.name}.
3
- ${n.toString()}`)};class Ho{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:Gt(t),h:n}),this}else(t){return this.if(me,t)}done(){return(t,n)=>{for(let s=0;s<this.patterns.length;s++){const r=this.patterns[s];if(r.if.check(t))return r.h(t,n)}throw z("Unhandled pattern")}}}const Yo=e=>new Ho(e),er=Yo(me).if(Qs,(e,t)=>Ge(t,Qn,fe)).if(Zs,(e,t)=>wo(t)).if(Vo,(e,t)=>cs(t)).if(Bo,(e,t)=>BigInt(Ge(t,Qn,fe))).if(we,(e,t)=>bt(t,Ke(t,e.shape))).if(Do,(e,t)=>{const n={};for(const s in e.shape){let r=e.shape[s];if(So.check(r)){if(cs(t))continue;r=r.shape}n[s]=er(r,t)}return n}).if(To,(e,t)=>{const n=[],s=Fs(t,0,42);for(let r=0;r<s;r++)n.push(bt(t,e.shape));return n}).if(js,(e,t)=>Ke(t,e.shape)).if(Fo,(e,t)=>null).if(Uo,(e,t)=>{const n=bt(t,e.res);return()=>n}).if($o,(e,t)=>bt(t,Ke(t,[Et,Lt,Ue,tr,Ln,Me,Ws(Et),Js(vt("a","b","c"),Et)]))).if(xo,(e,t)=>{const n={},s=Ge(t,0,3);for(let r=0;r<s;r++){const i=bt(t,e.shape.keys),o=bt(t,e.shape.values);n[i]=o}return n}).done(),bt=(e,t)=>er(Gt(t),e),ve=typeof document<"u"?document:{};L(e=>e.nodeType===Wo);typeof DOMParser<"u"&&new DOMParser;L(e=>e.nodeType===Jo);L(e=>e.nodeType===Go);const zo=e=>si(e,(t,n)=>`${n}:${t};`).join(""),Jo=ve.ELEMENT_NODE,Go=ve.TEXT_NODE,Ko=ve.DOCUMENT_NODE,Wo=ve.DOCUMENT_FRAGMENT_NODE;L(e=>e.nodeType===Ko);const Z=Symbol,nr=Z(),sr=Z(),Xo=Z(),Po=Z(),qo=Z(),rr=Z(),Qo=Z(),On=Z(),Zo=Z(),tc=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());const t=[],n=[];let s=0;for(;s<e.length;s++){const r=e[s];if(r===void 0)break;if(r.constructor===String||r.constructor===Number)t.push(r);else if(r.constructor===Object)break}for(s>0&&n.push(t.join(""));s<e.length;s++){const r=e[s];r instanceof Symbol||n.push(r)}return n},ec={[nr]:W("font-weight","bold"),[sr]:W("font-weight","normal"),[Xo]:W("color","blue"),[qo]:W("color","green"),[Po]:W("color","grey"),[rr]:W("color","red"),[Qo]:W("color","purple"),[On]:W("color","orange"),[Zo]:W("color","black")},nc=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());const t=[],n=[],s=R();let r=[],i=0;for(;i<e.length;i++){const o=e[i],c=ec[o];if(c!==void 0)s.set(c.left,c.right);else{if(o===void 0)break;if(o.constructor===String||o.constructor===Number){const l=zo(s);i>0||l.length>0?(t.push("%c"+o),n.push(l)):t.push(o)}else break}}for(i>0&&(r=n,r.unshift(t.join("")));i<e.length;i++){const o=e[i];o instanceof Symbol||r.push(o)}return r},ir=ro?nc:tc,sc=(...e)=>{console.log(...ir(e)),cr.forEach(t=>t.print(e))},or=(...e)=>{console.warn(...ir(e)),e.unshift(On),cr.forEach(t=>t.print(e))},cr=rt(),lr=e=>({[Symbol.iterator](){return this},next:e}),rc=(e,t)=>lr(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),We=(e,t)=>lr(()=>{const{done:n,value:s}=e.next();return{done:n,value:n?void 0:t(s)}});class Re{constructor(t,n){this.clock=t,this.len=n}}class Rt{constructor(){this.clients=new Map}}const Ot=(e,t,n)=>t.clients.forEach((s,r)=>{const i=e.doc.store.clients.get(r);if(i!=null){const o=i[i.length-1],c=o.id.clock+o.length;for(let l=0,h=s[l];l<s.length&&h.clock<c;h=s[++l])kr(e,i,h.clock,h.len,n)}}),ic=(e,t)=>{let n=0,s=e.length-1;for(;n<=s;){const r=H((n+s)/2),i=e[r],o=i.clock;if(o<=t){if(t<o+i.len)return r;n=r+1}else s=r-1}return null},Zt=(e,t)=>{const n=e.clients.get(t.client);return n!==void 0&&ic(n,t.clock)!==null},Nn=e=>{e.clients.forEach(t=>{t.sort((r,i)=>r.clock-i.clock);let n,s;for(n=1,s=1;n<t.length;n++){const r=t[s-1],i=t[n];r.clock+r.len>=i.clock?t[s-1]=new Re(r.clock,wt(r.len,i.clock+i.len-r.clock)):(s<n&&(t[s]=i),s++)}t.length=s})},cn=e=>{const t=new Rt;for(let n=0;n<e.length;n++)e[n].clients.forEach((s,r)=>{if(!t.clients.has(r)){const i=s.slice();for(let o=n+1;o<e.length;o++)ii(i,e[o].clients.get(r)||[]);t.clients.set(r,i)}});return Nn(t),t},Kt=(e,t,n,s)=>{K(e.clients,t,()=>[]).push(new Re(n,s))},oc=()=>new Rt,cc=e=>{const t=oc();return e.clients.forEach((n,s)=>{const r=[];for(let i=0;i<n.length;i++){const o=n[i];if(o.deleted){const c=o.id.clock;let l=o.length;if(i+1<n.length)for(let h=n[i+1];i+1<n.length&&h.deleted;h=n[++i+1])l+=h.length;r.push(new Re(c,l))}}r.length>0&&t.clients.set(s,r)}),t},$t=(e,t)=>{p(e.restEncoder,t.clients.size),P(t.clients.entries()).sort((n,s)=>s[0]-n[0]).forEach(([n,s])=>{e.resetDsCurVal(),p(e.restEncoder,n);const r=s.length;p(e.restEncoder,r);for(let i=0;i<r;i++){const o=s[i];e.writeDsClock(o.clock),e.writeDsLen(o.len)}})},Mn=e=>{const t=new Rt,n=m(e.restDecoder);for(let s=0;s<n;s++){e.resetDsCurVal();const r=m(e.restDecoder),i=m(e.restDecoder);if(i>0){const o=K(t.clients,r,()=>[]);for(let c=0;c<i;c++)o.push(new Re(e.readDsClock(),e.readDsLen()))}}return t},hs=(e,t,n)=>{const s=new Rt,r=m(e.restDecoder);for(let i=0;i<r;i++){e.resetDsCurVal();const o=m(e.restDecoder),c=m(e.restDecoder),l=n.clients.get(o)||[],h=A(n,o);for(let a=0;a<c;a++){const u=e.readDsClock(),d=u+e.readDsLen();if(u<h){h<d&&Kt(s,o,h,d-h);let f=J(l,u),g=l[f];for(!g.deleted&&g.id.clock<u&&(l.splice(f+1,0,Ee(t,g,u-g.id.clock)),f++);f<l.length&&(g=l[f++],g.id.clock<d);)g.deleted||(d<g.id.clock+g.length&&l.splice(f,0,Ee(t,g,d-g.id.clock)),g.delete(t))}else Kt(s,o,u,d-u)}}if(s.clients.size>0){const i=new ut;return p(i.restEncoder,0),$t(i,s),i.toUint8Array()}return null},hr=Ns;class mt extends wn{constructor({guid:t=ji(),collectionid:n=null,gc:s=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:o=!1,shouldLoad:c=!0}={}){super(),this.gc=s,this.gcFilter=r,this.clientID=hr(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new yr,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=o,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=is(h=>{this.on("load",()=>{this.isLoaded=!0,h(this)})});const l=()=>is(h=>{const a=u=>{(u===void 0||u===!0)&&(this.off("sync",a),h())};this.on("sync",a)});this.on("sync",h=>{h===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=h===void 0||h===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){const t=this._item;t!==null&&!this.shouldLoad&&_(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(P(this.subdocs).map(t=>t.guid))}transact(t,n=null){return _(this,t,n)}get(t,n=T){const s=K(this.share,t,()=>{const i=new n;return i._integrate(this,null),i}),r=s.constructor;if(n!==T&&r!==n)if(r===T){const i=new n;i._map=s._map,s._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=i}),i._start=s._start;for(let o=i._start;o!==null;o=o.right)o.parent=i;return i._length=s._length,this.share.set(t,i),i._integrate(this,null),i}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return s}getArray(t=""){return this.get(t,At)}getText(t=""){return this.get(t,Ut)}getMap(t=""){return this.get(t,Mt)}getXmlElement(t=""){return this.get(t,q)}getXmlFragment(t=""){return this.get(t,dt)}toJSON(){const t={};return this.share.forEach((n,s)=>{t[s]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,P(this.subdocs).forEach(n=>n.destroy());const t=this._item;if(t!==null){this._item=null;const n=t.content;n.doc=new mt({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,_(t.parent.doc,s=>{const r=n.doc;t.deleted||s.subdocsAdded.add(r),s.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class ar{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return m(this.restDecoder)}readDsLen(){return m(this.restDecoder)}}class ur extends ar{readLeftID(){return y(m(this.restDecoder),m(this.restDecoder))}readRightID(){return y(m(this.restDecoder),m(this.restDecoder))}readClient(){return m(this.restDecoder)}readInfo(){return Tt(this.restDecoder)}readString(){return st(this.restDecoder)}readParentInfo(){return m(this.restDecoder)===1}readTypeRef(){return m(this.restDecoder)}readLen(){return m(this.restDecoder)}readAny(){return zt(this.restDecoder)}readBuf(){return fo(O(this.restDecoder))}readJSON(){return JSON.parse(st(this.restDecoder))}readKey(){return st(this.restDecoder)}}class lc{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=m(this.restDecoder),this.dsCurrVal}readDsLen(){const t=m(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class Nt extends lc{constructor(t){super(t),this.keys=[],m(t),this.keyClockDecoder=new Je(O(t)),this.clientDecoder=new he(O(t)),this.leftClockDecoder=new Je(O(t)),this.rightClockDecoder=new Je(O(t)),this.infoDecoder=new rs(O(t),Tt),this.stringDecoder=new Bi(O(t)),this.parentInfoDecoder=new rs(O(t),Tt),this.typeRefDecoder=new he(O(t)),this.lenDecoder=new he(O(t))}readLeftID(){return new Dt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Dt(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return zt(this.restDecoder)}readBuf(){return O(this.restDecoder)}readJSON(){return zt(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{const n=this.stringDecoder.read();return this.keys.push(n),n}}}class dr{constructor(){this.restEncoder=N()}toUint8Array(){return C(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){p(this.restEncoder,t)}writeDsLen(t){p(this.restEncoder,t)}}class te extends dr{writeLeftID(t){p(this.restEncoder,t.client),p(this.restEncoder,t.clock)}writeRightID(t){p(this.restEncoder,t.client),p(this.restEncoder,t.clock)}writeClient(t){p(this.restEncoder,t)}writeInfo(t){nn(this.restEncoder,t)}writeString(t){at(this.restEncoder,t)}writeParentInfo(t){p(this.restEncoder,t?1:0)}writeTypeRef(t){p(this.restEncoder,t)}writeLen(t){p(this.restEncoder,t)}writeAny(t){Yt(this.restEncoder,t)}writeBuf(t){E(this.restEncoder,t)}writeJSON(t){at(this.restEncoder,JSON.stringify(t))}writeKey(t){at(this.restEncoder,t)}}class fr{constructor(){this.restEncoder=N(),this.dsCurrVal=0}toUint8Array(){return C(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,p(this.restEncoder,n)}writeDsLen(t){t===0&&F(),p(this.restEncoder,t-1),this.dsCurrVal+=t}}class ut extends fr{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new ze,this.clientEncoder=new le,this.leftClockEncoder=new ze,this.rightClockEncoder=new ze,this.infoEncoder=new es(nn),this.stringEncoder=new xi,this.parentInfoEncoder=new es(nn),this.typeRefEncoder=new le,this.lenEncoder=new le}toUint8Array(){const t=N();return p(t,0),E(t,this.keyClockEncoder.toUint8Array()),E(t,this.clientEncoder.toUint8Array()),E(t,this.leftClockEncoder.toUint8Array()),E(t,this.rightClockEncoder.toUint8Array()),E(t,C(this.infoEncoder)),E(t,this.stringEncoder.toUint8Array()),E(t,C(this.parentInfoEncoder)),E(t,this.typeRefEncoder.toUint8Array()),E(t,this.lenEncoder.toUint8Array()),xe(t,C(this.restEncoder)),C(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){Yt(this.restEncoder,t)}writeBuf(t){E(this.restEncoder,t)}writeJSON(t){Yt(this.restEncoder,t)}writeKey(t){const n=this.keyMap.get(t);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}}const hc=(e,t,n,s)=>{s=wt(s,t[0].id.clock);const r=J(t,s);p(e.restEncoder,t.length-r),e.writeClient(n),p(e.restEncoder,s);const i=t[r];i.write(e,s-i.id.clock);for(let o=r+1;o<t.length;o++)t[o].write(e,0)},Un=(e,t,n)=>{const s=new Map;n.forEach((r,i)=>{A(t,i)>r&&s.set(i,r)}),$e(t).forEach((r,i)=>{n.has(i)||s.set(i,0)}),p(e.restEncoder,s.size),P(s.entries()).sort((r,i)=>i[0]-r[0]).forEach(([r,i])=>{hc(e,t.clients.get(r),r,i)})},ac=(e,t)=>{const n=R(),s=m(e.restDecoder);for(let r=0;r<s;r++){const i=m(e.restDecoder),o=new Array(i),c=e.readClient();let l=m(e.restDecoder);n.set(c,{i:0,refs:o});for(let h=0;h<i;h++){const a=e.readInfo();switch(Ae&a){case 0:{const u=e.readLen();o[h]=new B(y(c,l),u),l+=u;break}case 10:{const u=m(e.restDecoder);o[h]=new V(y(c,l),u),l+=u;break}default:{const u=(a&(X|$))===0,d=new S(y(c,l),null,(a&$)===$?e.readLeftID():null,null,(a&X)===X?e.readRightID():null,u?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,u&&(a&jt)===jt?e.readString():null,Fr(e,a));o[h]=d,l+=d.length}}}}return n},uc=(e,t,n)=>{const s=[];let r=P(n.keys()).sort((f,g)=>f-g);if(r.length===0)return null;const i=()=>{if(r.length===0)return null;let f=n.get(r[r.length-1]);for(;f.refs.length===f.i;)if(r.pop(),r.length>0)f=n.get(r[r.length-1]);else return null;return f};let o=i();if(o===null)return null;const c=new yr,l=new Map,h=(f,g)=>{const w=l.get(f);(w==null||w>g)&&l.set(f,g)};let a=o.refs[o.i++];const u=new Map,d=()=>{for(const f of s){const g=f.id.client,w=n.get(g);w?(w.i--,c.clients.set(g,w.refs.slice(w.i)),n.delete(g),w.i=0,w.refs=[]):c.clients.set(g,[f]),r=r.filter(b=>b!==g)}s.length=0};for(;;){if(a.constructor!==V){const g=K(u,a.id.client,()=>A(t,a.id.client))-a.id.clock;if(g<0)s.push(a),h(a.id.client,a.id.clock-1),d();else{const w=a.getMissing(e,t);if(w!==null){s.push(a);const b=n.get(w)||{refs:[],i:0};if(b.refs.length===b.i)h(w,A(t,w)),d();else{a=b.refs[b.i++];continue}}else(g===0||g<a.length)&&(a.integrate(e,g),u.set(a.id.client,a.id.clock+a.length))}}if(s.length>0)a=s.pop();else if(o!==null&&o.i<o.refs.length)a=o.refs[o.i++];else{if(o=i(),o===null)break;a=o.refs[o.i++]}}if(c.clients.size>0){const f=new ut;return Un(f,c,new Map),p(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},dc=(e,t)=>Un(e,t.doc.store,t.beforeState),fc=(e,t,n,s=new Nt(e))=>_(t,r=>{r.local=!1;let i=!1;const o=r.doc,c=o.store,l=ac(s,o),h=uc(r,c,l),a=c.pendingStructs;if(a){for(const[d,f]of a.missing)if(f<A(c,d)){i=!0;break}if(h){for(const[d,f]of h.missing){const g=a.missing.get(d);(g==null||g>f)&&a.missing.set(d,f)}a.update=be([a.update,h.update])}}else c.pendingStructs=h;const u=hs(s,r,c);if(c.pendingDs){const d=new Nt(ct(c.pendingDs));m(d.restDecoder);const f=hs(d,r,c);u&&f?c.pendingDs=be([u,f]):c.pendingDs=u||f}else c.pendingDs=u;if(i){const d=c.pendingStructs.update;c.pendingStructs=null,gr(r.doc,d)}},n,!1),gr=(e,t,n,s=Nt)=>{const r=ct(t);fc(r,e,n,new s(r))},gc=(e,t,n)=>gr(e,t,n,ur),pc=(e,t,n=new Map)=>{Un(e,t.store,n),$t(e,cc(t.store))},wc=(e,t=new Uint8Array([0]),n=new ut)=>{const s=pr(t);pc(n,e,s);const r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(Uc(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===te)return Nc(r.map((i,o)=>o===0?i:Rc(i)));if(n.constructor===ut)return be(r)}return r[0]},mc=(e,t)=>wc(e,t,new te),yc=e=>{const t=new Map,n=m(e.restDecoder);for(let s=0;s<n;s++){const r=m(e.restDecoder),i=m(e.restDecoder);t.set(r,i)}return t},pr=e=>yc(new ar(ct(e))),wr=(e,t)=>(p(e.restEncoder,t.size),P(t.entries()).sort((n,s)=>s[0]-n[0]).forEach(([n,s])=>{p(e.restEncoder,n),p(e.restEncoder,s)}),e),bc=(e,t)=>wr(e,$e(t.store)),kc=(e,t=new fr)=>(e instanceof Map?wr(t,e):bc(t,e),t.toUint8Array()),_c=e=>kc(e,new dr);class Sc{constructor(){this.l=[]}}const as=()=>new Sc,us=(e,t)=>e.l.push(t),ds=(e,t)=>{const n=e.l,s=n.length;e.l=n.filter(r=>t!==r),s===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},mr=(e,t,n)=>Dn(e.l,[t,n]);class Dt{constructor(t,n){this.client=t,this.clock=n}}const re=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,y=(e,t)=>new Dt(e,t),Cc=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw F()},ye=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},kt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Zt(t.ds,e.id),ln=(e,t)=>{const n=K(e.meta,ln,rt),s=e.doc.store;n.has(t)||(t.sv.forEach((r,i)=>{r<A(s,i)&&v(e,y(i,r))}),Ot(e,t.ds,r=>{}),n.add(t))};class yr{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const $e=e=>{const t=new Map;return e.clients.forEach((n,s)=>{const r=n[n.length-1];t.set(s,r.id.clock+r.length)}),t},A=(e,t)=>{const n=e.clients.get(t);if(n===void 0)return 0;const s=n[n.length-1];return s.id.clock+s.length},br=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{const s=n[n.length-1];if(s.id.clock+s.length!==t.id.clock)throw F()}n.push(t)},J=(e,t)=>{let n=0,s=e.length-1,r=e[s],i=r.id.clock;if(i===t)return s;let o=H(t/(i+r.length-1)*s);for(;n<=s;){if(r=e[o],i=r.id.clock,i<=t){if(t<i+r.length)return o;n=o+1}else s=o-1;o=H((n+s)/2)}throw F()},Ec=(e,t)=>{const n=e.clients.get(t.client);return n[J(n,t.clock)]},ae=Ec,hn=(e,t,n)=>{const s=J(t,n),r=t[s];return r.id.clock<n&&r instanceof S?(t.splice(s+1,0,Ee(e,r,n-r.id.clock)),s+1):s},v=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[hn(e,n,t.clock)]},fs=(e,t,n)=>{const s=t.clients.get(n.client),r=J(s,n.clock),i=s[r];return n.clock!==i.id.clock+i.length-1&&i.constructor!==B&&s.splice(r+1,0,Ee(e,i,n.clock-i.id.clock+1)),i},Dc=(e,t,n)=>{const s=e.clients.get(t.id.client);s[J(s,t.id.clock)]=n},kr=(e,t,n,s,r)=>{if(s===0)return;const i=n+s;let o=hn(e,t,n),c;do c=t[o++],i<c.id.clock+c.length&&hn(e,t,i),r(c);while(o<t.length&&t[o].id.clock<i)};class Ac{constructor(t,n,s){this.doc=t,this.deleteSet=new Rt,this.beforeState=$e(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=s,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const gs=(e,t)=>t.deleteSet.clients.size===0&&!ri(t.afterState,(n,s)=>t.beforeState.get(s)!==n)?!1:(Nn(t.deleteSet),dc(e,t),$t(e,t.deleteSet),!0),ps=(e,t,n)=>{const s=t._item;(s===null||s.id.clock<(e.beforeState.get(s.id.client)||0)&&!s.deleted)&&K(e.changed,t,rt).add(n)},ue=(e,t)=>{let n=e[t],s=e[t-1],r=t;for(;r>0;n=s,s=e[--r-1]){if(s.deleted===n.deleted&&s.constructor===n.constructor&&s.mergeWith(n)){n instanceof S&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,s);continue}break}const i=t-r;return i&&e.splice(t+1-i,i),i},xc=(e,t,n)=>{for(const[s,r]of e.clients.entries()){const i=t.clients.get(s);for(let o=r.length-1;o>=0;o--){const c=r[o],l=c.clock+c.len;for(let h=J(i,c.clock),a=i[h];h<i.length&&a.id.clock<l;a=i[++h]){const u=i[h];if(c.clock+c.len<=u.id.clock)break;u instanceof S&&u.deleted&&!u.keep&&n(u)&&u.gc(t,!1)}}}},Ic=(e,t)=>{e.clients.forEach((n,s)=>{const r=t.clients.get(s);for(let i=n.length-1;i>=0;i--){const o=n[i],c=mn(r.length-1,1+J(r,o.clock+o.len-1));for(let l=c,h=r[l];l>0&&h.id.clock>=o.clock;h=r[l])l-=1+ue(r,l)}})},_r=(e,t)=>{if(t<e.length){const n=e[t],s=n.doc,r=s.store,i=n.deleteSet,o=n._mergeStructs;try{Nn(i),n.afterState=$e(n.doc.store),s.emit("beforeObserverCalls",[n,s]);const c=[];n.changed.forEach((l,h)=>c.push(()=>{(h._item===null||!h._item.deleted)&&h._callObserver(n,l)})),c.push(()=>{n.changedParentTypes.forEach((l,h)=>{h._dEH.l.length>0&&(h._item===null||!h._item.deleted)&&c.push(()=>{l=l.filter(a=>a.target._item===null||!a.target._item.deleted),l.forEach(a=>{a.currentTarget=h,a._path=null}),l.sort((a,u)=>a.path.length-u.path.length),mr(h._dEH,l,n)})}),c.push(()=>s.emit("afterTransaction",[n,s])),c.push(()=>{n._needFormattingCleanup&&Pc(n)})}),Dn(c,[])}finally{s.gc&&xc(i,r,s.gcFilter),Ic(i,r),n.afterState.forEach((a,u)=>{const d=n.beforeState.get(u)||0;if(d!==a){const f=r.clients.get(u),g=wt(J(f,d),1);for(let w=f.length-1;w>=g;)w-=1+ue(f,w)}});for(let a=o.length-1;a>=0;a--){const{client:u,clock:d}=o[a].id,f=r.clients.get(u),g=J(f,d);g+1<f.length&&ue(f,g+1)>1||g>0&&ue(f,g)}if(!n.local&&n.afterState.get(s.clientID)!==n.beforeState.get(s.clientID)&&(sc(On,nr,"[yjs] ",sr,rr,"Changed the client-id because another client seems to be using it."),s.clientID=hr()),s.emit("afterTransactionCleanup",[n,s]),s._observers.has("update")){const a=new te;gs(a,n)&&s.emit("update",[a.toUint8Array(),n.origin,s,n])}if(s._observers.has("updateV2")){const a=new ut;gs(a,n)&&s.emit("updateV2",[a.toUint8Array(),n.origin,s,n])}const{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:h}=n;(c.size>0||h.size>0||l.size>0)&&(c.forEach(a=>{a.clientID=s.clientID,a.collectionid==null&&(a.collectionid=s.collectionid),s.subdocs.add(a)}),h.forEach(a=>s.subdocs.delete(a)),s.emit("subdocs",[{loaded:l,added:c,removed:h},s,n]),h.forEach(a=>a.destroy())),e.length<=t+1?(s._transactionCleanups=[],s.emit("afterAllTransactions",[s,e])):_r(e,t+1)}}},_=(e,t,n=null,s=!0)=>{const r=e._transactionCleanups;let i=!1,o=null;e._transaction===null&&(i=!0,e._transaction=new Ac(e,n,s),r.push(e._transaction),r.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(i){const c=e._transaction===r[0];e._transaction=null,c&&_r(r,0)}}return o};class Tc{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const ws=(e,t,n)=>{Ot(e,n.deletions,s=>{s instanceof S&&t.scope.some(r=>r===e.doc||ye(r,s))&&Hn(s,!1)})},ms=(e,t,n)=>{let s=null;const r=e.doc,i=e.scope;_(r,c=>{for(;t.length>0&&e.currStackItem===null;){const l=r.store,h=t.pop(),a=new Set,u=[];let d=!1;Ot(c,h.insertions,f=>{if(f instanceof S){if(f.redone!==null){let{item:g,diff:w}=Cl(l,f.id);w>0&&(g=v(c,y(g.id.client,g.id.clock+w))),f=g}!f.deleted&&i.some(g=>g===c.doc||ye(g,f))&&u.push(f)}}),Ot(c,h.deletions,f=>{f instanceof S&&i.some(g=>g===c.doc||ye(g,f))&&!Zt(h.insertions,f.id)&&a.add(f)}),a.forEach(f=>{d=Vr(c,f,a,h.insertions,e.ignoreRemoteMapChanges,e)!==null||d});for(let f=u.length-1;f>=0;f--){const g=u[f];e.deleteFilter(g)&&(g.delete(c),d=!0)}e.currStackItem=d?h:null}c.changed.forEach((l,h)=>{l.has(null)&&h._searchMarker&&(h._searchMarker.length=0)}),s=c},e);const o=e.currStackItem;if(o!=null){const c=s.changedParentTypes;e.emit("stack-item-popped",[{stackItem:o,type:n,changedParentTypes:c,origin:e},e]),e.currStackItem=null}return o};class Lc extends wn{constructor(t,{captureTimeout:n=500,captureTransaction:s=l=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:c=It(t)?t[0].doc:t instanceof mt?t:t.doc}={}){super(),this.scope=[],this.doc=c,this.addToScope(t),this.deleteFilter=r,i.add(this),this.trackedOrigins=i,this.captureTransaction=s,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=n,this.afterTransactionHandler=l=>{if(!this.captureTransaction(l)||!this.scope.some(b=>l.changedParentTypes.has(b)||b===this.doc)||!this.trackedOrigins.has(l.origin)&&(!l.origin||!this.trackedOrigins.has(l.origin.constructor)))return;const h=this.undoing,a=this.redoing,u=h?this.redoStack:this.undoStack;h?this.stopCapturing():a||this.clear(!1,!0);const d=new Rt;l.afterState.forEach((b,k)=>{const Wn=l.beforeState.get(k)||0,Xn=b-Wn;Xn>0&&Kt(d,k,Wn,Xn)});const f=it();let g=!1;if(this.lastChange>0&&f-this.lastChange<this.captureTimeout&&u.length>0&&!h&&!a){const b=u[u.length-1];b.deletions=cn([b.deletions,l.deleteSet]),b.insertions=cn([b.insertions,d])}else u.push(new Tc(l.deleteSet,d)),g=!0;!h&&!a&&(this.lastChange=f),Ot(l,l.deleteSet,b=>{b instanceof S&&this.scope.some(k=>k===l.doc||ye(k,b))&&Hn(b,!0)});const w=[{stackItem:u[u.length-1],origin:l.origin,type:h?"redo":"undo",changedParentTypes:l.changedParentTypes},this];g?this.emit("stack-item-added",w):this.emit("stack-item-updated",w)},this.destroy=this.destroy.bind(this),this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",this.destroy)}addToScope(t){const n=new Set(this.scope);t=It(t)?t:[t],t.forEach(s=>{n.has(s)||(n.add(s),(s instanceof T?s.doc!==this.doc:s!==this.doc)&&or("[yjs#509] Not same Y.Doc"),this.scope.push(s))})}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,n=!0){(t&&this.canUndo()||n&&this.canRedo())&&this.doc.transact(s=>{t&&(this.undoStack.forEach(r=>ws(s,this,r)),this.undoStack=[]),n&&(this.redoStack.forEach(r=>ws(s,this,r)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let t;try{t=ms(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=ms(this,this.redoStack,"redo")}finally{this.redoing=!1}return t}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),this.doc.off("destroy",this.destroy),super.destroy()}}function*Oc(e){const t=m(e.restDecoder);for(let n=0;n<t;n++){const s=m(e.restDecoder),r=e.readClient();let i=m(e.restDecoder);for(let o=0;o<s;o++){const c=e.readInfo();if(c===10){const l=m(e.restDecoder);yield new V(y(r,i),l),i+=l}else if((Ae&c)!==0){const l=(c&(X|$))===0,h=new S(y(r,i),null,(c&$)===$?e.readLeftID():null,null,(c&X)===X?e.readRightID():null,l?e.readParentInfo()?e.readString():e.readLeftID():null,l&&(c&jt)===jt?e.readString():null,Fr(e,c));yield h,i+=h.length}else{const l=e.readLen();yield new B(y(r,i),l),i+=l}}}}class vn{constructor(t,n){this.gen=Oc(t),this.curr=null,this.done=!1,this.filterSkips=n,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===V);return this.curr}}class Rn{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const Nc=e=>be(e,ur,te),Mc=(e,t)=>{if(e.constructor===B){const{client:n,clock:s}=e.id;return new B(y(n,s+t),e.length-t)}else if(e.constructor===V){const{client:n,clock:s}=e.id;return new V(y(n,s+t),e.length-t)}else{const n=e,{client:s,clock:r}=n.id;return new S(y(s,r+t),null,y(s,r+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},be=(e,t=Nt,n=ut)=>{if(e.length===1)return e[0];const s=e.map(a=>new t(ct(a)));let r=s.map(a=>new vn(a,!0)),i=null;const o=new n,c=new Rn(o);for(;r=r.filter(d=>d.curr!==null),r.sort((d,f)=>{if(d.curr.id.client===f.curr.id.client){const g=d.curr.id.clock-f.curr.id.clock;return g===0?d.curr.constructor===f.curr.constructor?0:d.curr.constructor===V?1:-1:g}else return f.curr.id.client-d.curr.id.client}),r.length!==0;){const a=r[0],u=a.curr.id.client;if(i!==null){let d=a.curr,f=!1;for(;d!==null&&d.id.clock+d.length<=i.struct.id.clock+i.struct.length&&d.id.client>=i.struct.id.client;)d=a.next(),f=!0;if(d===null||d.id.client!==u||f&&d.id.clock>i.struct.id.clock+i.struct.length)continue;if(u!==i.struct.id.client)et(c,i.struct,i.offset),i={struct:d,offset:0},a.next();else if(i.struct.id.clock+i.struct.length<d.id.clock)if(i.struct.constructor===V)i.struct.length=d.id.clock+d.length-i.struct.id.clock;else{et(c,i.struct,i.offset);const g=d.id.clock-i.struct.id.clock-i.struct.length;i={struct:new V(y(u,i.struct.id.clock+i.struct.length),g),offset:0}}else{const g=i.struct.id.clock+i.struct.length-d.id.clock;g>0&&(i.struct.constructor===V?i.struct.length-=g:d=Mc(d,g)),i.struct.mergeWith(d)||(et(c,i.struct,i.offset),i={struct:d,offset:0},a.next())}}else i={struct:a.curr,offset:0},a.next();for(let d=a.curr;d!==null&&d.id.client===u&&d.id.clock===i.struct.id.clock+i.struct.length&&d.constructor!==V;d=a.next())et(c,i.struct,i.offset),i={struct:d,offset:0}}i!==null&&(et(c,i.struct,i.offset),i=null),$n(c);const l=s.map(a=>Mn(a)),h=cn(l);return $t(o,h),o.toUint8Array()},Uc=(e,t,n=Nt,s=ut)=>{const r=pr(t),i=new s,o=new Rn(i),c=new n(ct(e)),l=new vn(c,!1);for(;l.curr;){const a=l.curr,u=a.id.client,d=r.get(u)||0;if(l.curr.constructor===V){l.next();continue}if(a.id.clock+a.length>d)for(et(o,a,wt(d-a.id.clock,0)),l.next();l.curr&&l.curr.id.client===u;)et(o,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===u&&l.curr.id.clock+l.curr.length<=d;)l.next()}$n(o);const h=Mn(c);return $t(i,h),i.toUint8Array()},Sr=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:C(e.encoder.restEncoder)}),e.encoder.restEncoder=N(),e.written=0)},et=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Sr(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),p(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},$n=e=>{Sr(e);const t=e.encoder.restEncoder;p(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const s=e.clientStructs[n];p(t,s.written),xe(t,s.restEncoder)}},vc=(e,t,n,s)=>{const r=new n(ct(e)),i=new vn(r,!1),o=new s,c=new Rn(o);for(let h=i.curr;h!==null;h=i.next())et(c,t(h),0);$n(c);const l=Mn(r);return $t(o,l),o.toUint8Array()},Rc=e=>vc(e,Zi,Nt,te),ys="You must not compute changes after the event-handler fired.";class Be{constructor(t,n){this.target=t,this.currentTarget=t,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=$c(this.currentTarget,this.target))}deletes(t){return Zt(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw z(ys);const t=new Map,n=this.target;this.transaction.changed.get(n).forEach(r=>{if(r!==null){const i=n._map.get(r);let o,c;if(this.adds(i)){let l=i.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(i))if(l!==null&&this.deletes(l))o="delete",c=je(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",c=je(l.content.getContent())):(o="add",c=void 0)}else if(this.deletes(i))o="delete",c=je(i.content.getContent());else return;t.set(r,{action:o,oldValue:c})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw z(ys);const n=this.target,s=rt(),r=rt(),i=[];if(t={added:s,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(n).has(null)){let c=null;const l=()=>{c&&i.push(c)};for(let h=n._start;h!==null;h=h.right)h.deleted?this.deletes(h)&&!this.adds(h)&&((c===null||c.delete===void 0)&&(l(),c={delete:0}),c.delete+=h.length,r.add(h)):this.adds(h)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(h.content.getContent()),s.add(h)):((c===null||c.retain===void 0)&&(l(),c={retain:0}),c.retain+=h.length);c!==null&&c.retain===void 0&&l()}this._changes=t}return t}}const $c=(e,t)=>{const n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let s=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)!r.deleted&&r.countable&&(s+=r.length),r=r.right;n.unshift(s)}t=t._item.parent}return n},M=()=>{or("Invalid access: Add Yjs type to a document before reading data.")},Cr=80;let Bn=0;class Bc{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=Bn++}}const Vc=e=>{e.timestamp=Bn++},Er=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Bn++},Fc=(e,t,n)=>{if(e.length>=Cr){const s=e.reduce((r,i)=>r.timestamp<i.timestamp?r:i);return Er(s,t,n),s}else{const s=new Bc(t,n);return e.push(s),s}},Ve=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;const n=e._searchMarker.length===0?null:e._searchMarker.reduce((i,o)=>ce(t-i.index)<ce(t-o.index)?i:o);let s=e._start,r=0;for(n!==null&&(s=n.p,r=n.index,Vc(n));s.right!==null&&r<t;){if(!s.deleted&&s.countable){if(t<r+s.length)break;r+=s.length}s=s.right}for(;s.left!==null&&r>t;)s=s.left,!s.deleted&&s.countable&&(r-=s.length);for(;s.left!==null&&s.left.id.client===s.id.client&&s.left.id.clock+s.left.length===s.id.clock;)s=s.left,!s.deleted&&s.countable&&(r-=s.length);return n!==null&&ce(n.index-r)<s.parent.length/Cr?(Er(n,s,r),n):Fc(e._searchMarker,s,r)},Wt=(e,t,n)=>{for(let s=e.length-1;s>=0;s--){const r=e[s];if(n>0){let i=r.p;for(i.marker=!1;i&&(i.deleted||!i.countable);)i=i.left,i&&!i.deleted&&i.countable&&(r.index-=i.length);if(i===null||i.marker===!0){e.splice(s,1);continue}r.p=i,i.marker=!0}(t<r.index||n>0&&t===r.index)&&(r.index=wt(t,r.index+n))}},Fe=(e,t,n)=>{const s=e,r=t.changedParentTypes;for(;K(r,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;mr(s._eH,n,t)};class T{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=as(),this._dEH=as(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw j()}clone(){throw j()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,n){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){us(this._eH,t)}observeDeep(t){us(this._dEH,t)}unobserve(t){ds(this._eH,t)}unobserveDeep(t){ds(this._dEH,t)}toJSON(){}}const Dr=(e,t,n)=>{e.doc??M(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let s=n-t;const r=[];let i=e._start;for(;i!==null&&s>0;){if(i.countable&&!i.deleted){const o=i.content.getContent();if(o.length<=t)t-=o.length;else{for(let c=t;c<o.length&&s>0;c++)r.push(o[c]),s--;t=0}}i=i.right}return r},Ar=e=>{e.doc??M();const t=[];let n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){const s=n.content.getContent();for(let r=0;r<s.length;r++)t.push(s[r])}n=n.right}return t},Xt=(e,t)=>{let n=0,s=e._start;for(e.doc??M();s!==null;){if(s.countable&&!s.deleted){const r=s.content.getContent();for(let i=0;i<r.length;i++)t(r[i],n++,e)}s=s.right}},xr=(e,t)=>{const n=[];return Xt(e,(s,r)=>{n.push(t(s,r,e))}),n},jc=e=>{let t=e._start,n=null,s=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),s=0,t=t.right}const r=n[s++];return n.length<=s&&(n=null),{done:!1,value:r}}}},Ir=(e,t)=>{e.doc??M();const n=Ve(e,t);let s=e._start;for(n!==null&&(s=n.p,t-=n.index);s!==null;s=s.right)if(!s.deleted&&s.countable){if(t<s.length)return s.content.getContent()[t];t-=s.length}},ke=(e,t,n,s)=>{let r=n;const i=e.doc,o=i.clientID,c=i.store,l=n===null?t._start:n.right;let h=[];const a=()=>{h.length>0&&(r=new S(y(o,A(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new ft(h)),r.integrate(e,0),h=[])};s.forEach(u=>{if(u===null)h.push(u);else switch(u.constructor){case Number:case Object:case Boolean:case Array:case String:h.push(u);break;default:switch(a(),u.constructor){case Uint8Array:case ArrayBuffer:r=new S(y(o,A(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new ee(new Uint8Array(u))),r.integrate(e,0);break;case mt:r=new S(y(o,A(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new ne(u)),r.integrate(e,0);break;default:if(u instanceof T)r=new S(y(o,A(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new tt(u)),r.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),a()},Tr=()=>z("Length exceeded!"),Lr=(e,t,n,s)=>{if(n>t._length)throw Tr();if(n===0)return t._searchMarker&&Wt(t._searchMarker,n,s.length),ke(e,t,null,s);const r=n,i=Ve(t,n);let o=t._start;for(i!==null&&(o=i.p,n-=i.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&v(e,y(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&Wt(t._searchMarker,r,s.length),ke(e,t,o,s)},Hc=(e,t,n)=>{let r=(t._searchMarker||[]).reduce((i,o)=>o.index>i.index?o:i,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return ke(e,t,r,n)},Or=(e,t,n,s)=>{if(s===0)return;const r=n,i=s,o=Ve(t,n);let c=t._start;for(o!==null&&(c=o.p,n-=o.index);c!==null&&n>0;c=c.right)!c.deleted&&c.countable&&(n<c.length&&v(e,y(c.id.client,c.id.clock+n)),n-=c.length);for(;s>0&&c!==null;)c.deleted||(s<c.length&&v(e,y(c.id.client,c.id.clock+s)),c.delete(e),s-=c.length),c=c.right;if(s>0)throw Tr();t._searchMarker&&Wt(t._searchMarker,r,-i+s)},_e=(e,t,n)=>{const s=t._map.get(n);s!==void 0&&s.delete(e)},Vn=(e,t,n,s)=>{const r=t._map.get(n)||null,i=e.doc,o=i.clientID;let c;if(s==null)c=new ft([s]);else switch(s.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:c=new ft([s]);break;case Uint8Array:c=new ee(s);break;case mt:c=new ne(s);break;default:if(s instanceof T)c=new tt(s);else throw new Error("Unexpected content type")}new S(y(o,A(i.store,o)),r,r&&r.lastId,null,null,t,n,c).integrate(e,0)},Fn=(e,t)=>{e.doc??M();const n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Nr=e=>{const t={};return e.doc??M(),e._map.forEach((n,s)=>{n.deleted||(t[s]=n.content.getContent()[n.length-1])}),t},Mr=(e,t)=>{e.doc??M();const n=e._map.get(t);return n!==void 0&&!n.deleted},Yc=(e,t)=>{const n={};return e._map.forEach((s,r)=>{let i=s;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&kt(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},ie=e=>(e.doc??M(),rc(e._map.entries(),t=>!t[1].deleted));class zc extends Be{}class At extends T{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new At;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new At}clone(){const t=new At;return t.insert(0,this.toArray().map(n=>n instanceof T?n.clone():n)),t}get length(){return this.doc??M(),this._length}_callObserver(t,n){super._callObserver(t,n),Fe(this,t,new zc(this,t))}insert(t,n){this.doc!==null?_(this.doc,s=>{Lr(s,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?_(this.doc,n=>{Hc(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?_(this.doc,s=>{Or(s,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return Ir(this,t)}toArray(){return Ar(this)}slice(t=0,n=this.length){return Dr(this,t,n)}toJSON(){return this.map(t=>t instanceof T?t.toJSON():t)}map(t){return xr(this,t)}forEach(t){Xt(this,t)}[Symbol.iterator](){return jc(this)}_write(t){t.writeTypeRef(pl)}}const Jc=e=>new At;class Gc extends Be{constructor(t,n,s){super(t,n),this.keysChanged=s}}class Mt extends T{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach((s,r)=>{this.set(r,s)}),this._prelimContent=null}_copy(){return new Mt}clone(){const t=new Mt;return this.forEach((n,s)=>{t.set(s,n instanceof T?n.clone():n)}),t}_callObserver(t,n){Fe(this,t,new Gc(this,t,n))}toJSON(){this.doc??M();const t={};return this._map.forEach((n,s)=>{if(!n.deleted){const r=n.content.getContent()[n.length-1];t[s]=r instanceof T?r.toJSON():r}}),t}get size(){return[...ie(this)].length}keys(){return We(ie(this),t=>t[0])}values(){return We(ie(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return We(ie(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??M(),this._map.forEach((n,s)=>{n.deleted||t(n.content.getContent()[n.length-1],s,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?_(this.doc,n=>{_e(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?_(this.doc,s=>{Vn(s,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return Fn(this,t)}has(t){return Mr(this,t)}clear(){this.doc!==null?_(this.doc,t=>{this.forEach(function(n,s,r){_e(t,r,s)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(wl)}}const Kc=e=>new Mt,nt=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&qi(e,t);class an{constructor(t,n,s,r){this.left=t,this.right=n,this.index=s,this.currentAttributes=r}forward(){this.right===null&&F(),this.right.content.constructor===x?this.right.deleted||Bt(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}}const bs=(e,t,n)=>{for(;t.right!==null&&n>0;)t.right.content.constructor===x?t.right.deleted||Bt(t.currentAttributes,t.right.content):t.right.deleted||(n<t.right.length&&v(e,y(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length),t.left=t.right,t.right=t.right.right;return t},oe=(e,t,n,s)=>{const r=new Map,i=s?Ve(t,n):null;if(i){const o=new an(i.p.left,i.p,i.index,r);return bs(e,o,n-i.index)}else{const o=new an(null,t._start,0,r);return bs(e,o,n)}},Ur=(e,t,n,s)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===x&&nt(s.get(n.right.content.key),n.right.content.value));)n.right.deleted||s.delete(n.right.content.key),n.forward();const r=e.doc,i=r.clientID;s.forEach((o,c)=>{const l=n.left,h=n.right,a=new S(y(i,A(r.store,i)),l,l&&l.lastId,h,h&&h.id,t,null,new x(c,o));a.integrate(e,0),n.right=a,n.forward()})},Bt=(e,t)=>{const{key:n,value:s}=t;s===null?e.delete(n):e.set(n,s)},vr=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===x&&nt(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},Rr=(e,t,n,s)=>{const r=e.doc,i=r.clientID,o=new Map;for(const c in s){const l=s[c],h=n.currentAttributes.get(c)??null;if(!nt(h,l)){o.set(c,h);const{left:a,right:u}=n;n.right=new S(y(i,A(r.store,i)),a,a&&a.lastId,u,u&&u.id,t,null,new x(c,l)),n.right.integrate(e,0),n.forward()}}return o},Xe=(e,t,n,s,r)=>{n.currentAttributes.forEach((d,f)=>{r[f]===void 0&&(r[f]=null)});const i=e.doc,o=i.clientID;vr(n,r);const c=Rr(e,t,n,r),l=s.constructor===String?new G(s):s instanceof T?new tt(s):new yt(s);let{left:h,right:a,index:u}=n;t._searchMarker&&Wt(t._searchMarker,n.index,l.getLength()),a=new S(y(o,A(i.store,o)),h,h&&h.lastId,a,a&&a.id,t,null,l),a.integrate(e,0),n.right=a,n.index=u,n.forward(),Ur(e,t,n,c)},ks=(e,t,n,s,r)=>{const i=e.doc,o=i.clientID;vr(n,r);const c=Rr(e,t,n,r);t:for(;n.right!==null&&(s>0||c.size>0&&(n.right.deleted||n.right.content.constructor===x));){if(!n.right.deleted)switch(n.right.content.constructor){case x:{const{key:l,value:h}=n.right.content,a=r[l];if(a!==void 0){if(nt(a,h))c.delete(l);else{if(s===0)break t;c.set(l,h)}n.right.delete(e)}else n.currentAttributes.set(l,h);break}default:s<n.right.length&&v(e,y(n.right.id.client,n.right.id.clock+s)),s-=n.right.length;break}n.forward()}if(s>0){let l="";for(;s>0;s--)l+=`
4
- `;n.right=new S(y(o,A(i.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new G(l)),n.right.integrate(e,0),n.forward()}Ur(e,t,n,c)},$r=(e,t,n,s,r)=>{let i=t;const o=R();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===x){const h=i.content;o.set(h.key,h)}i=i.right}let c=0,l=!1;for(;t!==i;){if(n===t&&(l=!0),!t.deleted){const h=t.content;if(h.constructor===x){const{key:a,value:u}=h,d=s.get(a)??null;(o.get(a)!==h||d===u)&&(t.delete(e),c++,!l&&(r.get(a)??null)===u&&d!==u&&(d===null?r.delete(a):r.set(a,d))),!l&&!t.deleted&&Bt(r,h)}}t=t.right}return c},Wc=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===x){const s=t.content.key;n.has(s)?t.delete(e):n.add(s)}t=t.left}},Xc=e=>{let t=0;return _(e.doc,n=>{let s=e._start,r=e._start,i=R();const o=tn(i);for(;r;)r.deleted===!1&&(r.content.constructor===x?Bt(o,r.content):(t+=$r(n,s,r,i,o),i=tn(o),s=r)),r=r.right}),t},Pc=e=>{const t=new Set,n=e.doc;for(const[s,r]of e.afterState.entries()){const i=e.beforeState.get(s)||0;r!==i&&kr(e,n.store.clients.get(s),i,r,o=>{!o.deleted&&o.content.constructor===x&&o.constructor!==B&&t.add(o.parent)})}_(n,s=>{Ot(e,e.deleteSet,r=>{if(r instanceof B||!r.parent._hasFormatting||t.has(r.parent))return;const i=r.parent;r.content.constructor===x?t.add(i):Wc(s,r)});for(const r of t)Xc(r)})},_s=(e,t,n)=>{const s=n,r=tn(t.currentAttributes),i=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case tt:case yt:case G:n<t.right.length&&v(e,y(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}i&&$r(e,i,t.right,r,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&Wt(o._searchMarker,t.index,-s+n),t};class qc extends Be{constructor(t,n,s){super(t,n),this.childListChanged=!1,this.keysChanged=new Set,s.forEach(r=>{r===null?this.childListChanged=!0:this.keysChanged.add(r)})}get changes(){if(this._changes===null){const t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){const t=this.target.doc,n=[];_(t,s=>{const r=new Map,i=new Map;let o=this.target._start,c=null;const l={};let h="",a=0,u=0;const d=()=>{if(c!==null){let f=null;switch(c){case"delete":u>0&&(f={delete:u}),u=0;break;case"insert":(typeof h=="object"||h.length>0)&&(f={insert:h},r.size>0&&(f.attributes={},r.forEach((g,w)=>{g!==null&&(f.attributes[w]=g)}))),h="";break;case"retain":a>0&&(f={retain:a},Pi(l)||(f.attributes=Gi({},l))),a=0;break}f&&n.push(f),c=null}};for(;o!==null;){switch(o.content.constructor){case tt:case yt:this.adds(o)?this.deletes(o)||(d(),c="insert",h=o.content.getContent()[0],d()):this.deletes(o)?(c!=="delete"&&(d(),c="delete"),u+=1):o.deleted||(c!=="retain"&&(d(),c="retain"),a+=1);break;case G:this.adds(o)?this.deletes(o)||(c!=="insert"&&(d(),c="insert"),h+=o.content.str):this.deletes(o)?(c!=="delete"&&(d(),c="delete"),u+=o.length):o.deleted||(c!=="retain"&&(d(),c="retain"),a+=o.length);break;case x:{const{key:f,value:g}=o.content;if(this.adds(o)){if(!this.deletes(o)){const w=r.get(f)??null;nt(w,g)?g!==null&&o.delete(s):(c==="retain"&&d(),nt(g,i.get(f)??null)?delete l[f]:l[f]=g)}}else if(this.deletes(o)){i.set(f,g);const w=r.get(f)??null;nt(w,g)||(c==="retain"&&d(),l[f]=w)}else if(!o.deleted){i.set(f,g);const w=l[f];w!==void 0&&(nt(w,g)?w!==null&&o.delete(s):(c==="retain"&&d(),g===null?delete l[f]:l[f]=g))}o.deleted||(c==="insert"&&d(),Bt(r,o.content));break}}o=o.right}for(d();n.length>0;){const f=n[n.length-1];if(f.retain!==void 0&&f.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class Ut extends T{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??M(),this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach(s=>s())}catch(s){console.error(s)}this._pending=null}_copy(){return new Ut}clone(){const t=new Ut;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const s=new qc(this,t,n);Fe(this,t,s),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??M();let t="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===G&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){this.doc!==null?_(this.doc,s=>{const r=new an(null,this._start,0,new Map);for(let i=0;i<t.length;i++){const o=t[i];if(o.insert!==void 0){const c=!n&&typeof o.insert=="string"&&i===t.length-1&&r.right===null&&o.insert.slice(-1)===`
5
- `?o.insert.slice(0,-1):o.insert;(typeof c!="string"||c.length>0)&&Xe(s,this,r,c,o.attributes||{})}else o.retain!==void 0?ks(s,this,r,o.retain,o.attributes||{}):o.delete!==void 0&&_s(s,r,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,s){this.doc??M();const r=[],i=new Map,o=this.doc;let c="",l=this._start;function h(){if(c.length>0){const u={};let d=!1;i.forEach((g,w)=>{d=!0,u[w]=g});const f={insert:c};d&&(f.attributes=u),r.push(f),c=""}}const a=()=>{for(;l!==null;){if(kt(l,t)||n!==void 0&&kt(l,n))switch(l.content.constructor){case G:{const u=i.get("ychange");t!==void 0&&!kt(l,t)?(u===void 0||u.user!==l.id.client||u.type!=="removed")&&(h(),i.set("ychange",s?s("removed",l.id):{type:"removed"})):n!==void 0&&!kt(l,n)?(u===void 0||u.user!==l.id.client||u.type!=="added")&&(h(),i.set("ychange",s?s("added",l.id):{type:"added"})):u!==void 0&&(h(),i.delete("ychange")),c+=l.content.str;break}case tt:case yt:{h();const u={insert:l.content.getContent()[0]};if(i.size>0){const d={};u.attributes=d,i.forEach((f,g)=>{d[g]=f})}r.push(u);break}case x:kt(l,t)&&(h(),Bt(i,l.content));break}l=l.right}h()};return t||n?_(o,u=>{t&&ln(u,t),n&&ln(u,n),a()},"cleanup"):a(),r}insert(t,n,s){if(n.length<=0)return;const r=this.doc;r!==null?_(r,i=>{const o=oe(i,this,t,!s);s||(s={},o.currentAttributes.forEach((c,l)=>{s[l]=c})),Xe(i,this,o,n,s)}):this._pending.push(()=>this.insert(t,n,s))}insertEmbed(t,n,s){const r=this.doc;r!==null?_(r,i=>{const o=oe(i,this,t,!s);Xe(i,this,o,n,s||{})}):this._pending.push(()=>this.insertEmbed(t,n,s||{}))}delete(t,n){if(n===0)return;const s=this.doc;s!==null?_(s,r=>{_s(r,oe(r,this,t,!0),n)}):this._pending.push(()=>this.delete(t,n))}format(t,n,s){if(n===0)return;const r=this.doc;r!==null?_(r,i=>{const o=oe(i,this,t,!1);o.right!==null&&ks(i,this,o,n,s)}):this._pending.push(()=>this.format(t,n,s))}removeAttribute(t){this.doc!==null?_(this.doc,n=>{_e(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?_(this.doc,s=>{Vn(s,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return Fn(this,t)}getAttributes(){return Nr(this)}_write(t){t.writeTypeRef(ml)}}const Qc=e=>new Ut;class Pe{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??M()}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(n)))do if(n=t.content.type,!t.deleted&&(n.constructor===q||n.constructor===dt)&&n._start!==null)t=n._start;else for(;t!==null;){const s=t.next;if(s!==null){t=s;break}else t.parent===this._root?t=null:t=t.parent._item}while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class dt extends T{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new dt}clone(){const t=new dt;return t.insert(0,this.toArray().map(n=>n instanceof T?n.clone():n)),t}get length(){return this.doc??M(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Pe(this,t)}querySelector(t){t=t.toUpperCase();const s=new Pe(this,r=>r.nodeName&&r.nodeName.toUpperCase()===t).next();return s.done?null:s.value}querySelectorAll(t){return t=t.toUpperCase(),P(new Pe(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){Fe(this,t,new el(this,n,t))}toString(){return xr(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},s){const r=t.createDocumentFragment();return s!==void 0&&s._createAssociation(r,this),Xt(this,i=>{r.insertBefore(i.toDOM(t,n,s),null)}),r}insert(t,n){this.doc!==null?_(this.doc,s=>{Lr(s,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)_(this.doc,s=>{const r=t&&t instanceof T?t._item:t;ke(s,this,r,n)});else{const s=this._prelimContent,r=t===null?0:s.findIndex(i=>i===t)+1;if(r===0&&t!==null)throw z("Reference item not found");s.splice(r,0,...n)}}delete(t,n=1){this.doc!==null?_(this.doc,s=>{Or(s,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return Ar(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Ir(this,t)}slice(t=0,n=this.length){return Dr(this,t,n)}forEach(t){Xt(this,t)}_write(t){t.writeTypeRef(bl)}}const Zc=e=>new dt;class q extends dt{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach((s,r)=>{this.setAttribute(r,s)}),this._prelimAttrs=null}_copy(){return new q(this.nodeName)}clone(){const t=new q(this.nodeName),n=this.getAttributes();return Wi(n,(s,r)=>{t.setAttribute(r,s)}),t.insert(0,this.toArray().map(s=>s instanceof T?s.clone():s)),t}toString(){const t=this.getAttributes(),n=[],s=[];for(const c in t)s.push(c);s.sort();const r=s.length;for(let c=0;c<r;c++){const l=s[c];n.push(l+'="'+t[l]+'"')}const i=this.nodeName.toLocaleLowerCase(),o=n.length>0?" "+n.join(" "):"";return`<${i}${o}>${super.toString()}</${i}>`}removeAttribute(t){this.doc!==null?_(this.doc,n=>{_e(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?_(this.doc,s=>{Vn(s,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return Fn(this,t)}hasAttribute(t){return Mr(this,t)}getAttributes(t){return t?Yc(this,t):Nr(this)}toDOM(t=document,n={},s){const r=t.createElement(this.nodeName),i=this.getAttributes();for(const o in i){const c=i[o];typeof c=="string"&&r.setAttribute(o,c)}return Xt(this,o=>{r.appendChild(o.toDOM(t,n,s))}),s!==void 0&&s._createAssociation(r,this),r}_write(t){t.writeTypeRef(yl),t.writeKey(this.nodeName)}}const tl=e=>new q(e.readKey());class el extends Be{constructor(t,n,s){super(t,s),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(r=>{r===null?this.childListChanged=!0:this.attributesChanged.add(r)})}}class Se extends Mt{constructor(t){super(),this.hookName=t}_copy(){return new Se(this.hookName)}clone(){const t=new Se(this.hookName);return this.forEach((n,s)=>{t.set(s,n)}),t}toDOM(t=document,n={},s){const r=n[this.hookName];let i;return r!==void 0?i=r.createDom(this):i=document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),s!==void 0&&s._createAssociation(i,this),i}_write(t){t.writeTypeRef(kl),t.writeKey(this.hookName)}}const nl=e=>new Se(e.readKey());class Q extends Ut{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new Q}clone(){const t=new Q;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,s){const r=t.createTextNode(this.toString());return s!==void 0&&s._createAssociation(r,this),r}toString(){return this.toDelta().map(t=>{const n=[];for(const r in t.attributes){const i=[];for(const o in t.attributes[r])i.push({key:o,value:t.attributes[r][o]});i.sort((o,c)=>o.key<c.key?-1:1),n.push({nodeName:r,attrs:i})}n.sort((r,i)=>r.nodeName<i.nodeName?-1:1);let s="";for(let r=0;r<n.length;r++){const i=n[r];s+=`<${i.nodeName}`;for(let o=0;o<i.attrs.length;o++){const c=i.attrs[o];s+=` ${c.key}="${c.value}"`}s+=">"}s+=t.insert;for(let r=n.length-1;r>=0;r--)s+=`</${n[r].nodeName}>`;return s}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(_l)}}const sl=e=>new Q;class jn{constructor(t,n){this.id=t,this.length=n}get deleted(){throw j()}mergeWith(t){return!1}write(t,n,s){throw j()}integrate(t,n){throw j()}}const rl=0;class B extends jn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){n>0&&(this.id.clock+=n,this.length-=n),br(t.doc.store,this)}write(t,n){t.writeInfo(rl),t.writeLen(this.length-n)}getMissing(t,n){return null}}class ee{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new ee(this.content)}splice(t){throw j()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}const il=e=>new ee(e.readBuf());class Pt{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Pt(this.len)}splice(t){const n=new Pt(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){Kt(t.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(t){}gc(t){}write(t,n){t.writeLen(this.len-n)}getRef(){return 1}}const ol=e=>new Pt(e.readLen()),Br=(e,t)=>new mt({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class ne{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const n={};this.opts=n,t.gc||(n.gc=!1),t.autoLoad&&(n.autoLoad=!0),t.meta!==null&&(n.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new ne(Br(this.doc.guid,this.opts))}splice(t){throw j()}mergeWith(t){return!1}integrate(t,n){this.doc._item=n,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,n){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}const cl=e=>new ne(Br(e.readString(),e.readAny()));class yt{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new yt(this.embed)}splice(t){throw j()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}const ll=e=>new yt(e.readJSON());class x{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new x(this.key,this.value)}splice(t){throw j()}mergeWith(t){return!1}integrate(t,n){const s=n.parent;s._searchMarker=null,s._hasFormatting=!0}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}const hl=e=>new x(e.readKey(),e.readJSON());class Ce{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Ce(this.arr)}splice(t){const n=new Ce(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const s=this.arr.length;t.writeLen(s-n);for(let r=n;r<s;r++){const i=this.arr[r];t.writeString(i===void 0?"undefined":JSON.stringify(i))}}getRef(){return 2}}const al=e=>{const t=e.readLen(),n=[];for(let s=0;s<t;s++){const r=e.readString();r==="undefined"?n.push(void 0):n.push(JSON.parse(r))}return new Ce(n)},ul=pe("node_env")==="development";class ft{constructor(t){this.arr=t,ul&&Rs(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ft(this.arr)}splice(t){const n=new ft(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const s=this.arr.length;t.writeLen(s-n);for(let r=n;r<s;r++){const i=this.arr[r];t.writeAny(i)}}getRef(){return 8}}const dl=e=>{const t=e.readLen(),n=[];for(let s=0;s<t;s++)n.push(e.readAny());return new ft(n)};class G{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new G(this.str)}splice(t){const n=new G(this.str.slice(t));this.str=this.str.slice(0,t);const s=this.str.charCodeAt(t-1);return s>=55296&&s<=56319&&(this.str=this.str.slice(0,t-1)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(t){return this.str+=t.str,!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}}const fl=e=>new G(e.readString()),gl=[Jc,Kc,Qc,tl,Zc,nl,sl],pl=0,wl=1,ml=2,yl=3,bl=4,kl=5,_l=6;class tt{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new tt(this.type._copy())}splice(t){throw j()}mergeWith(t){return!1}integrate(t,n){this.type._integrate(t.doc,n)}delete(t){let n=this.type._start;for(;n!==null;)n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t),n=n.right;this.type._map.forEach(s=>{s.deleted?s.id.clock<(t.beforeState.get(s.id.client)||0)&&t._mergeStructs.push(s):s.delete(t)}),t.changed.delete(this.type)}gc(t){let n=this.type._start;for(;n!==null;)n.gc(t,!0),n=n.right;this.type._start=null,this.type._map.forEach(s=>{for(;s!==null;)s.gc(t,!0),s=s.left}),this.type._map=new Map}write(t,n){this.type._write(t)}getRef(){return 7}}const Sl=e=>new tt(gl[e.readTypeRef()](e)),Cl=(e,t)=>{let n=t,s=0,r;do s>0&&(n=y(n.client,n.clock+s)),r=ae(e,n),s=n.clock-r.id.clock,n=r.redone;while(n!==null&&r instanceof S);return{item:r,diff:s}},Hn=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Ee=(e,t,n)=>{const{client:s,clock:r}=t.id,i=new S(y(s,r+n),t,y(s,r+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),t.redone!==null&&(i.redone=y(t.redone.client,t.redone.clock+n)),t.right=i,i.right!==null&&(i.right.left=i),e._mergeStructs.push(i),i.parentSub!==null&&i.right===null&&i.parent._map.set(i.parentSub,i),t.length=n,i},Ss=(e,t)=>pn(e,n=>Zt(n.deletions,t)),Vr=(e,t,n,s,r,i)=>{const o=e.doc,c=o.store,l=o.clientID,h=t.redone;if(h!==null)return v(e,h);let a=t.parent._item,u=null,d;if(a!==null&&a.deleted===!0){if(a.redone===null&&(!n.has(a)||Vr(e,a,n,s,r,i)===null))return null;for(;a.redone!==null;)a=v(e,a.redone)}const f=a===null?t.parent:a.content.type;if(t.parentSub===null){for(u=t.left,d=t;u!==null;){let k=u;for(;k!==null&&k.parent._item!==a;)k=k.redone===null?null:v(e,k.redone);if(k!==null&&k.parent._item===a){u=k;break}u=u.left}for(;d!==null;){let k=d;for(;k!==null&&k.parent._item!==a;)k=k.redone===null?null:v(e,k.redone);if(k!==null&&k.parent._item===a){d=k;break}d=d.right}}else{if(d=null,t.right&&!r){for(u=t;u!==null&&u.right!==null&&(u.right.redone||Zt(s,u.right.id)||Ss(i.undoStack,u.right.id)||Ss(i.redoStack,u.right.id));)for(u=u.right;u.redone;)u=v(e,u.redone);if(u&&u.right!==null)return null}else u=f._map.get(t.parentSub)||null;u!==null&&u.parent._item!==a&&(u=f._map.get(t.parentSub)||null)}const g=A(c,l),w=y(l,g),b=new S(w,u,u&&u.lastId,d,d&&d.id,f,t.parentSub,t.content.copy());return t.redone=w,Hn(b,!0),b.integrate(e,0),b};class S extends jn{constructor(t,n,s,r,i,o,c,l){super(t,l.getLength()),this.origin=s,this.left=n,this.right=r,this.rightOrigin=i,this.parent=o,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?qn:0}set marker(t){(this.info&Ye)>0!==t&&(this.info^=Ye)}get marker(){return(this.info&Ye)>0}get keep(){return(this.info&Pn)>0}set keep(t){this.keep!==t&&(this.info^=Pn)}get countable(){return(this.info&qn)>0}get deleted(){return(this.info&He)>0}set deleted(t){this.deleted!==t&&(this.info^=He)}markDeleted(){this.info|=He}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=A(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=A(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Dt&&this.id.client!==this.parent.client&&this.parent.clock>=A(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=fs(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=v(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===B||this.right&&this.right.constructor===B)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===S?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===S&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Dt){const s=ae(n,this.parent);s.constructor===B?this.parent=null:this.parent=s.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=fs(t,t.doc.store,y(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let s=this.left,r;if(s!==null)r=s.right;else if(this.parentSub!==null)for(r=this.parent._map.get(this.parentSub)||null;r!==null&&r.left!==null;)r=r.left;else r=this.parent._start;const i=new Set,o=new Set;for(;r!==null&&r!==this.right;){if(o.add(r),i.add(r),re(this.origin,r.origin)){if(r.id.client<this.id.client)s=r,i.clear();else if(re(this.rightOrigin,r.rightOrigin))break}else if(r.origin!==null&&o.has(ae(t.doc.store,r.origin)))i.has(ae(t.doc.store,r.origin))||(s=r,i.clear());else break;r=r.right}this.left=s}if(this.left!==null){const s=this.left.right;this.right=s,this.left.right=this}else{let s;if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start,this.parent._start=this;this.right=s}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),br(t.doc.store,this),this.content.integrate(t,this),ps(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new B(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;t!==null&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;t!==null&&t.deleted;)t=t.left;return t}get lastId(){return this.length===1?this.id:y(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&re(t.origin,this.lastId)&&this.right===t&&re(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const n=this.parent._searchMarker;return n&&n.forEach(s=>{s.p===t&&(s.p=this,!this.deleted&&this.countable&&(s.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),Kt(t.deleteSet,this.id.client,this.id.clock,this.length),ps(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw F();this.content.gc(t),n?Dc(t,this,new B(this.id,this.length)):this.content=new Pt(this.length)}write(t,n){const s=n>0?y(this.id.client,this.id.clock+n-1):this.origin,r=this.rightOrigin,i=this.parentSub,o=this.content.getRef()&Ae|(s===null?0:$)|(r===null?0:X)|(i===null?0:jt);if(t.writeInfo(o),s!==null&&t.writeLeftID(s),r!==null&&t.writeRightID(r),s===null&&r===null){const c=this.parent;if(c._item!==void 0){const l=c._item;if(l===null){const h=Cc(c);t.writeParentInfo(!0),t.writeString(h)}else t.writeParentInfo(!1),t.writeLeftID(l.id)}else c.constructor===String?(t.writeParentInfo(!0),t.writeString(c)):c.constructor===Dt?(t.writeParentInfo(!1),t.writeLeftID(c)):F();i!==null&&t.writeString(i)}this.content.write(t,n)}}const Fr=(e,t)=>El[t&Ae](e),El=[()=>{F()},ol,al,il,fl,ll,hl,Sl,dl,cl,()=>{F()}],Dl=10;class V extends jn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){F()}write(t,n){t.writeInfo(Dl),p(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const jr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Hr="__ $YJS$ __";jr[Hr]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");jr[Hr]=!0;const Yr=new Map;class Al{constructor(t){this.room=t,this.onmessage=null,this._onChange=n=>n.key===t&&this.onmessage!==null&&this.onmessage({data:uo(n.newValue||"")}),Yi(this._onChange)}postMessage(t){Us.setItem(this.room,ao(io(t)))}close(){zi(this._onChange)}}const xl=typeof BroadcastChannel>"u"?Al:BroadcastChannel,Yn=e=>K(Yr,e,()=>{const t=rt(),n=new xl(e);return n.onmessage=s=>t.forEach(r=>r(s.data,"broadcastchannel")),{bc:n,subs:t}}),Il=(e,t)=>(Yn(e).subs.add(t),t),Tl=(e,t)=>{const n=Yn(e),s=n.subs.delete(t);return s&&n.subs.size===0&&(n.bc.close(),Yr.delete(e)),s},_t=(e,t,n=null)=>{const s=Yn(e);s.bc.postMessage(t),s.subs.forEach(r=>r(t,n))},zr=0,zn=1,Jr=2,un=(e,t)=>{p(e,zr);const n=_c(t);E(e,n)},Gr=(e,t,n)=>{p(e,zn),E(e,mc(t,n))},Ll=(e,t,n)=>Gr(t,n,O(e)),Kr=(e,t,n,s)=>{try{gc(t,O(e),n)}catch(r){s?.(r),console.error("Caught error while handling a Yjs update",r)}},Ol=(e,t)=>{p(e,Jr),E(e,t)},Nl=Kr,Ml=(e,t,n,s,r)=>{const i=m(e);switch(i){case zr:Ll(e,t,n);break;case zn:Kr(e,n,s,r);break;case Jr:Nl(e,n,s,r);break;default:throw new Error("Unknown message type")}return i},Ul=0,vl=(e,t,n)=>{m(e)===Ul&&n(t,st(e))},qe=3e4;class Rl extends ci{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const n=it();this.getLocalState()!==null&&qe/2<=n-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const s=[];this.meta.forEach((r,i)=>{i!==this.clientID&&qe<=n-r.lastUpdated&&this.states.has(i)&&s.push(i)}),s.length>0&&Jn(this,s,"timeout")},H(qe/10)),t.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(t){const n=this.clientID,s=this.meta.get(n),r=s===void 0?0:s.clock+1,i=this.states.get(n);t===null?this.states.delete(n):this.states.set(n,t),this.meta.set(n,{clock:r,lastUpdated:it()});const o=[],c=[],l=[],h=[];t===null?h.push(n):i==null?t!=null&&o.push(n):(c.push(n),Ct(i,t)||l.push(n)),(o.length>0||l.length>0||h.length>0)&&this.emit("change",[{added:o,updated:l,removed:h},"local"]),this.emit("update",[{added:o,updated:c,removed:h},"local"])}setLocalStateField(t,n){const s=this.getLocalState();s!==null&&this.setLocalState({...s,[t]:n})}getStates(){return this.states}}const Jn=(e,t,n)=>{const s=[];for(let r=0;r<t.length;r++){const i=t[r];if(e.states.has(i)){if(e.states.delete(i),i===e.clientID){const o=e.meta.get(i);e.meta.set(i,{clock:o.clock+1,lastUpdated:it()})}s.push(i)}}s.length>0&&(e.emit("change",[{added:[],updated:[],removed:s},n]),e.emit("update",[{added:[],updated:[],removed:s},n]))},Ft=(e,t,n=e.states)=>{const s=t.length,r=N();p(r,s);for(let i=0;i<s;i++){const o=t[i],c=n.get(o)||null,l=e.meta.get(o).clock;p(r,o),p(r,l),at(r,JSON.stringify(c))}return C(r)},$l=(e,t,n)=>{const s=ct(t),r=it(),i=[],o=[],c=[],l=[],h=m(s);for(let a=0;a<h;a++){const u=m(s);let d=m(s);const f=JSON.parse(st(s)),g=e.meta.get(u),w=e.states.get(u),b=g===void 0?0:g.clock;(b<d||b===d&&f===null&&e.states.has(u))&&(f===null?u===e.clientID&&e.getLocalState()!=null?d++:e.states.delete(u):e.states.set(u,f),e.meta.set(u,{clock:d,lastUpdated:r}),g===void 0&&f!==null?i.push(u):g!==void 0&&f===null?l.push(u):f!==null&&(Ct(f,w)||c.push(u),o.push(u)))}(i.length>0||c.length>0||l.length>0)&&e.emit("change",[{added:i,updated:c,removed:l},n]),(i.length>0||o.length>0||l.length>0)&&e.emit("update",[{added:i,updated:o,removed:l},n])},Bl=e=>Xi(e,(t,n)=>`${encodeURIComponent(n)}=${encodeURIComponent(t)}`).join("&"),lt=0,Wr=3,xt=1,Vl=2,se=[];se[lt]=(e,t,n,s,r)=>{p(e,lt);const i=Ml(t,e,n.doc,n);s&&i===zn&&!n.synced&&(n.synced=!0)};se[Wr]=(e,t,n,s,r)=>{p(e,xt),E(e,Ft(n.awareness,Array.from(n.awareness.getStates().keys())))};se[xt]=(e,t,n,s,r)=>{$l(n.awareness,O(t),n)};se[Vl]=(e,t,n,s,r)=>{vl(t,n.doc,(i,o)=>Fl(n,o))};const Cs=3e4,Fl=(e,t)=>console.warn(`Permission denied to access ${e.url}.
6
- ${t}`),Xr=(e,t,n)=>{const s=ct(t),r=N(),i=m(s),o=e.messageHandlers[i];return o?o(r,s,e,n,i):console.error("Unable to compute message"),r},dn=(e,t,n)=>{t===e.ws&&(e.emit("connection-close",[n,e]),e.ws=null,t.close(),e.wsconnecting=!1,e.wsconnected?(e.wsconnected=!1,e.synced=!1,Jn(e.awareness,Array.from(e.awareness.getStates().keys()).filter(s=>s!==e.doc.clientID),e),e.emit("status",[{status:"disconnected"}])):e.wsUnsuccessfulReconnects++,setTimeout(Pr,mn(li(2,e.wsUnsuccessfulReconnects)*100,e.maxBackoffTime),e))},Pr=e=>{if(e.shouldConnect&&e.ws===null){const t=new e._WS(e.url,e.protocols);t.binaryType="arraybuffer",e.ws=t,e.wsconnecting=!0,e.wsconnected=!1,e.synced=!1,t.onmessage=n=>{e.wsLastMessageReceived=it();const s=Xr(e,new Uint8Array(n.data),!0);yn(s)>1&&t.send(C(s))},t.onerror=n=>{e.emit("connection-error",[n,e])},t.onclose=n=>{dn(e,t,n)},t.onopen=()=>{e.wsLastMessageReceived=it(),e.wsconnecting=!1,e.wsconnected=!0,e.wsUnsuccessfulReconnects=0,e.emit("status",[{status:"connected"}]);const n=N();if(p(n,lt),un(n,e.doc),t.send(C(n)),e.awareness.getLocalState()!==null){const s=N();p(s,xt),E(s,Ft(e.awareness,[e.doc.clientID])),t.send(C(s))}},e.emit("status",[{status:"connecting"}])}},Qe=(e,t)=>{const n=e.ws;e.wsconnected&&n&&n.readyState===n.OPEN&&n.send(t),e.bcconnected&&_t(e.bcChannel,t,e)};class jl extends wn{constructor(t,n,s,{connect:r=!0,awareness:i=new Rl(s),params:o={},protocols:c=[],WebSocketPolyfill:l=WebSocket,resyncInterval:h=-1,maxBackoffTime:a=2500,disableBc:u=!1}={}){for(super();t[t.length-1]==="/";)t=t.slice(0,t.length-1);this.serverUrl=t,this.bcChannel=t+"/"+n,this.maxBackoffTime=a,this.params=o,this.protocols=c,this.roomname=n,this.doc=s,this._WS=l,this.awareness=i,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=u,this.wsUnsuccessfulReconnects=0,this.messageHandlers=se.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=r,this._resyncInterval=0,h>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const d=N();p(d,lt),un(d,s),this.ws.send(C(d))}},h)),this._bcSubscriber=(d,f)=>{if(f!==this){const g=Xr(this,new Uint8Array(d),!1);yn(g)>1&&_t(this.bcChannel,C(g),this)}},this._updateHandler=(d,f)=>{if(f!==this){const g=N();p(g,lt),Ol(g,d),Qe(this,C(g))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:d,updated:f,removed:g},w)=>{const b=d.concat(f).concat(g),k=N();p(k,xt),E(k,Ft(i,b)),Qe(this,C(k))},this._exitHandler=()=>{Jn(this.awareness,[s.clientID],"app closed")},ot&&typeof process<"u"&&process.on("exit",this._exitHandler),i.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Cs<it()-this.wsLastMessageReceived&&dn(this,this.ws,null)},Cs/10),r&&this.connect()}get url(){const t=Bl(this.params);return this.serverUrl+"/"+this.roomname+(t.length===0?"":"?"+t)}get synced(){return this._synced}set synced(t){this._synced!==t&&(this._synced=t,this.emit("synced",[t]),this.emit("sync",[t]))}destroy(){this._resyncInterval!==0&&clearInterval(this._resyncInterval),clearInterval(this._checkInterval),this.disconnect(),ot&&typeof process<"u"&&process.off("exit",this._exitHandler),this.awareness.off("update",this._awarenessUpdateHandler),this.doc.off("update",this._updateHandler),super.destroy()}connectBc(){if(this.disableBc)return;this.bcconnected||(Il(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const t=N();p(t,lt),un(t,this.doc),_t(this.bcChannel,C(t),this);const n=N();p(n,lt),Gr(n,this.doc),_t(this.bcChannel,C(n),this);const s=N();p(s,Wr),_t(this.bcChannel,C(s),this);const r=N();p(r,xt),E(r,Ft(this.awareness,[this.doc.clientID])),_t(this.bcChannel,C(r),this)}disconnectBc(){const t=N();p(t,xt),E(t,Ft(this.awareness,[this.doc.clientID],new Map)),Qe(this,C(t)),this.bcconnected&&(Tl(this.bcChannel,this._bcSubscriber),this.bcconnected=!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&dn(this,this.ws,null)}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(Pr(this),this.connectBc())}}function Hl(e){return e instanceof Q||e instanceof q}function Gn(e){return e.toArray().filter(Hl)}function Yl(e,t){if(e===t)return null;let n=0;const s=Math.min(e.length,t.length);for(;n<s&&e[n]===t[n];)n++;let r=0;const i=Math.min(e.length-n,t.length-n);for(;r<i&&e[e.length-1-r]===t[t.length-1-r];)r++;return{start:n,deleteCount:e.length-n-r,insertText:t.slice(n,t.length-r)}}function zl(e){const t=new q(e.tagName.toLowerCase());for(const s of Array.from(e.attributes))t.setAttribute(s.name,s.value);const n=qr(e.childNodes);return n.length&&t.insert(0,n),t}function qr(e){const t=[];for(const n of Array.from(e))n.nodeType===Node.TEXT_NODE?t.push(new Q(n.textContent??"")):n.nodeType===Node.ELEMENT_NODE&&t.push(zl(n));return t}function Jl(e,t){const n=t.createElement(e.nodeName);for(const[s,r]of Object.entries(e.getAttributes()))n.setAttribute(s,r);for(const s of Gn(e))n.appendChild(Qr(s,t));return n}function Qr(e,t){return e instanceof Q?t.createTextNode(e.toString()):Jl(e,t)}function Zr(e,t){return e.tagName.toLowerCase()===t.nodeName.toLowerCase()}function fn(e,t){const n=Array.from(t.childNodes).filter(o=>o.nodeType===Node.TEXT_NODE||o.nodeType===Node.ELEMENT_NODE),s=Gn(e),r=Math.min(n.length,s.length);let i=0;for(;i<r;i++){const o=n[i],c=s[i];if(o.nodeType===Node.TEXT_NODE){if(c instanceof Q){const l=Yl(c.toString(),o.textContent??"");l&&(l.deleteCount>0&&c.delete(l.start,l.deleteCount),l.insertText&&c.insert(l.start,l.insertText));continue}break}if(c instanceof q&&Zr(o,c)){Gl(c,o),fn(c,o);continue}break}if(i<s.length&&e.delete(i,s.length-i),i<n.length){const o=qr(n.slice(i));o.length&&e.insert(i,o)}}function Gl(e,t){const n=e.getAttributes(),s=new Set(Array.from(t.attributes).map(r=>r.name));for(const r of Object.keys(n))s.has(r)||e.removeAttribute(r);for(const r of Array.from(t.attributes))n[r.name]!==r.value&&e.setAttribute(r.name,r.value)}function ti(e,t,n){const s=Gn(t),r=Array.from(e.childNodes).filter(c=>c.nodeType===Node.TEXT_NODE||c.nodeType===Node.ELEMENT_NODE),i=Math.min(s.length,r.length);let o=0;for(;o<i;o++){const c=s[o],l=r[o];if(c instanceof Q){if(l.nodeType===Node.TEXT_NODE){const h=c.toString();l.textContent!==h&&(l.textContent=h);continue}break}if(l.nodeType===Node.ELEMENT_NODE&&Zr(l,c)){Kl(l,c),ti(l,c,n);continue}break}for(let c=r.length-1;c>=o;c--)e.removeChild(r[c]);for(let c=o;c<s.length;c++)e.appendChild(Qr(s[c],n))}function Kl(e,t){const n=t.getAttributes(),s=new Set(Array.from(e.attributes).map(r=>r.name));for(const r of s)r in n||e.removeAttribute(r);for(const[r,i]of Object.entries(n))e.getAttribute(r)!==i&&e.setAttribute(r,i)}class Wl{constructor(t,n,s){this.root=t,this.doc=n,this.fragment=s,this.pending=!1,this.observer=new MutationObserver(()=>this.scheduleLocalSync()),this.fragment.length===0&&this.root.childNodes.length>0?this.doc.transact(()=>fn(this.fragment,this.root),this):this.applyRemoteToDom(),this.observer.observe(this.root,{childList:!0,characterData:!0,subtree:!0,attributes:!0}),this.fragment.observeDeep((r,i)=>{i.origin!==this&&this.applyRemoteToDom()})}scheduleLocalSync(){this.pending||(this.pending=!0,queueMicrotask(()=>{this.pending=!1,this.doc.transact(()=>fn(this.fragment,this.root),this)}))}applyRemoteToDom(){const t=this.captureSelection();this.observer.disconnect();try{ti(this.root,this.fragment,this.root.ownerDocument),this.root.dispatchEvent(new Event("input",{bubbles:!0,composed:!0}))}finally{this.observer.observe(this.root,{childList:!0,characterData:!0,subtree:!0,attributes:!0})}t&&this.restoreSelection(t)}pathTo(t,n){if(!this.root.contains(t))return null;const s=[];let r=t;for(;r&&r!==this.root;){const i=r.parentNode;if(!i)return null;s.unshift(Array.prototype.indexOf.call(i.childNodes,r)),r=i}return{path:s,offset:n}}resolvePath(t){let n=this.root;for(const s of t){const r=n.childNodes[s];if(!r)return null;n=r}return n}captureSelection(){const t=this.root.ownerDocument.defaultView?.getSelection();if(!t||t.rangeCount===0||!t.anchorNode||!t.focusNode)return null;const n=this.pathTo(t.anchorNode,t.anchorOffset),s=this.pathTo(t.focusNode,t.focusOffset);return!n||!s?null:{anchor:n,focus:s}}restoreSelection(t){const n=this.root.ownerDocument.defaultView?.getSelection();if(!n)return;const s=this.resolvePath(t.anchor.path),r=this.resolvePath(t.focus.path);if(!(!s||!r))try{const i=Math.min(t.anchor.offset,(s.textContent??"").length),o=Math.min(t.focus.offset,(r.textContent??"").length);n.setBaseAndExtent(s,i,r,o)}catch{}}destroy(){this.observer.disconnect()}}const Es="editora-collaboration-cursor-styles";function Xl(){if(typeof document>"u"||document.getElementById(Es))return;const e=document.createElement("style");e.id=Es,e.textContent=`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const R=()=>new Map,en=e=>{const t=R();return e.forEach((n,s)=>{t.set(s,n)}),t},J=(e,t,n)=>{let s=e.get(t);return s===void 0&&e.set(t,s=n()),s},di=(e,t)=>{const n=[];for(const[s,r]of e)n.push(t(r,s));return n},fi=(e,t)=>{for(const[n,s]of e)if(t(s,n))return!0;return!1},rt=()=>new Set,He=e=>e[e.length-1],gi=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},X=Array.from,pn=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},wn=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},pi=(e,t)=>{const n=new Array(e);for(let s=0;s<e;s++)n[s]=t(s,n);return n},xt=Array.isArray;class mn{constructor(){this._observers=R()}on(t,n){return J(this._observers,t,rt).add(n),n}once(t,n){const s=(...r)=>{this.off(t,s),n(...r)};this.on(t,s)}off(t,n){const s=this._observers.get(t);s!==void 0&&(s.delete(n),s.size===0&&this._observers.delete(t))}emit(t,n){return X((this._observers.get(t)||R()).values()).forEach(s=>s(...n))}destroy(){this._observers=R()}}class wi{constructor(){this._observers=R()}on(t,n){J(this._observers,t,rt).add(n)}once(t,n){const s=(...r)=>{this.off(t,s),n(...r)};this.on(t,s)}off(t,n){const s=this._observers.get(t);s!==void 0&&(s.delete(n),s.size===0&&this._observers.delete(t))}emit(t,n){return X((this._observers.get(t)||R()).values()).forEach(s=>s(...n))}destroy(){this._observers=R()}}const H=Math.floor,ce=Math.abs,yn=(e,t)=>e<t?e:t,wt=(e,t)=>e>t?e:t,mi=Math.pow,Ns=e=>e!==0?e<0:1/e<0,qn=1,Qn=2,ze=4,Ye=8,jt=32,W=64,$=128,Te=31,nn=63,at=127,yi=2147483647,fe=Number.MAX_SAFE_INTEGER,Zn=Number.MIN_SAFE_INTEGER,bi=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&H(e)===e),Ms=String.fromCharCode,ki=e=>e.toLowerCase(),_i=/^\s*/g,Si=e=>e.replace(_i,""),Ci=/([A-Z])/g,ts=(e,t)=>Si(e.replace(Ci,n=>`${t}${ki(n)}`)),Ei=e=>{const t=unescape(encodeURIComponent(e)),n=t.length,s=new Uint8Array(n);for(let r=0;r<n;r++)s[r]=t.codePointAt(r);return s},Ht=typeof TextEncoder<"u"?new TextEncoder:null,Di=e=>Ht.encode(e),Ai=Ht?Di:Ei;let Ft=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Ft&&Ft.decode(new Uint8Array).length===1&&(Ft=null);const Ti=(e,t)=>pi(t,()=>e).join("");class qt{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const N=()=>new qt,bn=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},C=e=>{const t=new Uint8Array(bn(e));let n=0;for(let s=0;s<e.bufs.length;s++){const r=e.bufs[s];t.set(r,n),n+=r.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},xi=(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(wt(n,t)*2),e.cpos=0)},x=(e,t)=>{const n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},sn=x,w=(e,t)=>{for(;t>at;)x(e,$|at&t),t=H(t/128);x(e,at&t)},kn=(e,t)=>{const n=Ns(t);for(n&&(t=-t),x(e,(t>nn?$:0)|(n?W:0)|nn&t),t=H(t/64);t>0;)x(e,(t>at?$:0)|at&t),t=H(t/128)},rn=new Uint8Array(3e4),Ii=rn.length/3,Li=(e,t)=>{if(t.length<Ii){const n=Ht.encodeInto(t,rn).written||0;w(e,n);for(let s=0;s<n;s++)x(e,rn[s])}else E(e,Ai(t))},Oi=(e,t)=>{const n=unescape(encodeURIComponent(t)),s=n.length;w(e,s);for(let r=0;r<s;r++)x(e,n.codePointAt(r))},ht=Ht&&Ht.encodeInto?Li:Oi,xe=(e,t)=>{const n=e.cbuf.length,s=e.cpos,r=yn(n-s,t.length),i=t.length-r;e.cbuf.set(t.subarray(0,r),s),e.cpos+=r,i>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(wt(n*2,i)),e.cbuf.set(t.subarray(r)),e.cpos=i)},E=(e,t)=>{w(e,t.byteLength),xe(e,t)},_n=(e,t)=>{xi(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Ni=(e,t)=>_n(e,4).setFloat32(0,t,!1),Mi=(e,t)=>_n(e,8).setFloat64(0,t,!1),Ui=(e,t)=>_n(e,8).setBigInt64(0,t,!1),es=new DataView(new ArrayBuffer(4)),vi=e=>(es.setFloat32(0,e),es.getFloat32(0)===e),zt=(e,t)=>{switch(typeof t){case"string":x(e,119),ht(e,t);break;case"number":bi(t)&&ce(t)<=yi?(x(e,125),kn(e,t)):vi(t)?(x(e,124),Ni(e,t)):(x(e,123),Mi(e,t));break;case"bigint":x(e,122),Ui(e,t);break;case"object":if(t===null)x(e,126);else if(xt(t)){x(e,117),w(e,t.length);for(let n=0;n<t.length;n++)zt(e,t[n])}else if(t instanceof Uint8Array)x(e,116),E(e,t);else{x(e,118);const n=Object.keys(t);w(e,n.length);for(let s=0;s<n.length;s++){const r=n[s];ht(e,r),zt(e,t[r])}}break;case"boolean":x(e,t?120:121);break;default:x(e,127)}};class ns extends qt{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&w(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const ss=e=>{e.count>0&&(kn(e.encoder,e.count===1?e.s:-e.s),e.count>1&&w(e.encoder,e.count-2))};class le{constructor(){this.encoder=new qt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(ss(this),this.count=1,this.s=t)}toUint8Array(){return ss(this),C(this.encoder)}}const rs=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);kn(e.encoder,t),e.count>1&&w(e.encoder,e.count-2)}};class Pe{constructor(){this.encoder=new qt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(rs(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return rs(this),C(this.encoder)}}class Ri{constructor(){this.sarr=[],this.s="",this.lensE=new le}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new qt;return this.sarr.push(this.s),this.s="",ht(t,this.sarr.join("")),xe(t,this.lensE.toUint8Array()),C(t)}}const Y=e=>new Error(e),j=()=>{throw Y("Method unimplemented")},V=()=>{throw Y("Unexpected case")},Ie=Y("Unexpected end of array"),Us=Y("Integer out of Range"),$i=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw Ie;return new Uint8Array(e.buffer,e.byteOffset+t,n)},Bi=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw Ie;return new DataView(e.buffer,e.byteOffset+t,n)};class Le{constructor(t){this.arr=t,this.pos=0}}const ct=e=>new Le(e),Fi=e=>e.pos!==e.arr.length,Vi=(e,t)=>{const n=$i(e.arr,e.pos,t);return e.pos+=t,n},O=e=>Vi(e,m(e)),It=e=>e.arr[e.pos++],m=e=>{let t=0,n=1;const s=e.arr.length;for(;e.pos<s;){const r=e.arr[e.pos++];if(t=t+(r&at)*n,n*=128,r<$)return t;if(t>fe)throw Us}throw Ie},Sn=e=>{let t=e.arr[e.pos++],n=t&nn,s=64;const r=(t&W)>0?-1:1;if((t&$)===0)return r*n;const i=e.arr.length;for(;e.pos<i;){if(t=e.arr[e.pos++],n=n+(t&at)*s,s*=128,t<$)return r*n;if(n>fe)throw Us}throw Ie},ji=e=>{let t=m(e);if(t===0)return"";{let n=String.fromCodePoint(It(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(It(e));else for(;t>0;){const s=t<1e4?t:1e4,r=e.arr.subarray(e.pos,e.pos+s);e.pos+=s,n+=String.fromCodePoint.apply(null,r),t-=s}return decodeURIComponent(escape(n))}},Hi=e=>Ft.decode(O(e)),st=Ft?Hi:ji,Cn=(e,t)=>{const n=Bi(e.arr,e.pos,t);return e.pos+=t,n},zi=e=>Cn(e,4).getFloat32(0,!1),Yi=e=>Cn(e,8).getFloat64(0,!1),Pi=e=>Cn(e,8).getBigInt64(0,!1),Gi=[e=>{},e=>null,Sn,zi,Yi,Pi,e=>!1,e=>!0,st,e=>{const t=m(e),n={};for(let s=0;s<t;s++){const r=st(e);n[r]=Yt(e)}return n},e=>{const t=m(e),n=[];for(let s=0;s<t;s++)n.push(Yt(e));return n},O],Yt=e=>Gi[127-It(e)](e);class is extends Le{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Fi(this)?this.count=m(this)+1:this.count=-1),this.count--,this.s}}class ae extends Le{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Sn(this);const t=Ns(this.s);this.count=1,t&&(this.s=-this.s,this.count=m(this)+2)}return this.count--,this.s}}class Ge extends Le{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=Sn(this),n=t&1;this.diff=H(t/2),this.count=1,n&&(this.count=m(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Ji{constructor(t){this.decoder=new ae(t),this.str=st(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}}const Ki=crypto.getRandomValues.bind(crypto),vs=()=>Ki(new Uint32Array(1))[0],Wi="10000000-1000-4000-8000"+-1e11,Xi=()=>Wi.replace(/[018]/g,e=>(e^vs()&15>>e/4).toString(16)),it=Date.now,os=e=>new Promise(e);Promise.all.bind(Promise);const cs=e=>e===void 0?null:e;class qi{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}}let Rs=new qi,En=!0;try{typeof localStorage<"u"&&localStorage&&(Rs=localStorage,En=!1)}catch{}const $s=Rs,Qi=e=>En||addEventListener("storage",e),Zi=e=>En||removeEventListener("storage",e),Pt=Symbol("Equality"),Bs=(e,t)=>e===t||!!e?.[Pt]?.(t)||!1,to=e=>typeof e=="object",eo=Object.assign,no=Object.keys,so=(e,t)=>{for(const n in e)t(e[n],n)},ro=(e,t)=>{const n=[];for(const s in e)n.push(t(e[s],s));return n},ge=e=>no(e).length,io=e=>{for(const t in e)return!1;return!0},Qt=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},Dn=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),oo=(e,t)=>e===t||ge(e)===ge(t)&&Qt(e,(n,s)=>(n!==void 0||Dn(t,s))&&Bs(t[s],n)),co=Object.freeze,Fs=e=>{for(const t in e){const n=e[t];(typeof n=="object"||typeof n=="function")&&Fs(e[t])}return co(e)},An=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&An(e,t,n+1)}},lo=e=>e,Ct=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[Pt]!=null)return e[Pt](t);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)||!Ct(e.get(n),t.get(n)))return!1;break}case void 0:case Object:if(ge(e)!==ge(t))return!1;for(const n in e)if(!Dn(e,n)||!Ct(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(!Ct(e[n],t[n]))return!1;break;default:return!1}return!0},ao=(e,t)=>t.includes(e),ot=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",Vs=typeof window<"u"&&typeof document<"u"&&!ot;let z;const ho=()=>{if(z===void 0)if(ot){z=R();const e=process.argv;let t=null;for(let n=0;n<e.length;n++){const s=e[n];s[0]==="-"?(t!==null&&z.set(t,""),t=s):t!==null&&(z.set(t,s),t=null)}t!==null&&z.set(t,"")}else typeof location=="object"?(z=R(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){const[t,n]=e.split("=");z.set(`--${ts(t,"-")}`,n),z.set(`-${ts(t,"-")}`,n)}})):z=R();return z},on=e=>ho().has(e),pe=e=>cs(ot?process.env[e.toUpperCase().replaceAll("-","_")]:$s.getItem(e)),js=e=>on("--"+e)||pe(e)!==null,uo=js("production"),fo=ot&&ao(process.env.FORCE_COLOR,["true","1","2"]),go=fo||!on("--no-colors")&&!js("no-color")&&(!ot||process.stdout.isTTY)&&(!ot||on("--color")||pe("COLORTERM")!==null||(pe("TERM")||"").includes("color")),Hs=e=>new Uint8Array(e),po=e=>new Uint8Array(e),wo=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=Ms(e[n]);return btoa(t)},mo=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),yo=e=>{const t=atob(e),n=Hs(t.length);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return n},bo=e=>new Uint8Array(Buffer.from(e,"base64")),ko=Vs?wo:mo,_o=Vs?yo:bo,So=e=>{const t=Hs(e.byteLength);return t.set(e),t};class Co{constructor(t,n){this.left=t,this.right=n}}const K=(e,t)=>new Co(e,t),ls=e=>e.next()>=.5,Je=(e,t,n)=>H(e.next()*(n+1-t)+t),zs=(e,t,n)=>H(e.next()*(n+1-t)+t),Tn=(e,t,n)=>zs(e,t,n),Eo=e=>Ms(Tn(e,97,122)),Do=(e,t=0,n=20)=>{const s=Tn(e,t,n);let r="";for(let i=0;i<s;i++)r+=Eo(e);return r},Ke=(e,t)=>t[Tn(e,0,t.length-1)],Ao=Symbol("0schema");class To{constructor(){this._rerrs=[]}extend(t,n,s,r=null){this._rerrs.push({path:t,expected:n,has:s,message:r})}toString(){const t=[];for(let n=this._rerrs.length-1;n>0;n--){const s=this._rerrs[n];t.push(Ti(" ",(this._rerrs.length-n)*2)+`${s.path!=null?`[${s.path}] `:""}${s.has} doesn't match ${s.expected}. ${s.message}`)}return t.join(`
2
+ `)}}const cn=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[Pt]?Bs(e,t):xt(e)?pn(e,n=>wn(t,s=>cn(n,s))):to(e)?Qt(e,(n,s)=>cn(n,t[s])):!1;class U{static _dilutes=!1;extends(t){let[n,s]=[this.shape,t.shape];return this.constructor._dilutes&&([s,n]=[n,s]),cn(n,s)}equals(t){return this.constructor===t.constructor&&Ct(this.shape,t.shape)}[Ao](){return!0}[Pt](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){j()}get nullable(){return vt(this,ve)}get optional(){return new Gs(this)}cast(t){return as(t,this),t}expect(t){return as(t,this),t}}class xn extends U{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n=void 0){const s=t?.constructor===this.shape&&(this._c==null||this._c(t));return!s&&n?.extend(null,this.shape.name,t?.constructor.name,t?.constructor!==this.shape?"Constructor match failed":"Check failed"),s}}const D=(e,t=null)=>new xn(e,t);D(xn);class In extends U{constructor(t){super(),this.shape=t}check(t,n){const s=this.shape(t);return!s&&n?.extend(null,"custom prop",t?.constructor.name,"failed to check custom prop"),s}}const L=e=>new In(e);D(In);class Oe extends U{constructor(t){super(),this.shape=t}check(t,n){const s=this.shape.some(r=>r===t);return!s&&n?.extend(null,this.shape.join(" | "),t.toString()),s}}const Ne=(...e)=>new Oe(e),Ys=D(Oe),xo=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,t=>"\\"+t)),Ps=e=>{if(Lt.check(e))return[xo(e)];if(Ys.check(e))return e.shape.map(t=>t+"");if(er.check(e))return["[+-]?\\d+.?\\d*"];if(nr.check(e))return[".*"];if(we.check(e))return e.shape.map(Ps).flat(1);V()};class Io extends U{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(Ps).map(n=>`(${n.join("|")})`).join("")+"$")}check(t,n){const s=this._r.exec(t)!=null;return!s&&n?.extend(null,this._r.toString(),t.toString(),"String doesn't match string template."),s}}D(Io);const Lo=Symbol("optional");class Gs extends U{constructor(t){super(),this.shape=t}check(t,n){const s=t===void 0||this.shape.check(t);return!s&&n?.extend(null,"undefined (optional)","()"),s}get[Lo](){return!0}}const Oo=D(Gs);class No extends U{check(t,n){return n?.extend(null,"never",typeof t),!1}}D(No);class Me extends U{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}static _dilutes=!0;get partial(){return new Me(this.shape,!0)}check(t,n){return t==null?(n?.extend(null,"object","null"),!1):Qt(this.shape,(s,r)=>{const i=this._isPartial&&!Dn(t,r)||s.check(t[r],n);return!i&&n?.extend(r.toString(),s.toString(),typeof t[r],"Object property does not match"),i})}}const Mo=e=>new Me(e),Uo=D(Me),vo=L(e=>e!=null&&(e.constructor===Object||e.constructor==null));class Js extends U{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return t!=null&&Qt(t,(s,r)=>{const i=this.shape.keys.check(r,n);return!i&&n?.extend(r+"","Record",typeof t,i?"Key doesn't match schema":"Value doesn't match value"),i&&this.shape.values.check(s,n)})}}const Ks=(e,t)=>new Js(e,t),Ro=D(Js);class Ws extends U{constructor(t){super(),this.shape=t}check(t,n){return t!=null&&Qt(this.shape,(s,r)=>{const i=s.check(t[r],n);return!i&&n?.extend(r.toString(),"Tuple",typeof s),i})}}const $o=(...e)=>new Ws(e);D(Ws);class Xs extends U{constructor(t){super(),this.shape=t.length===1?t[0]:new Ln(t)}check(t,n){const s=xt(t)&&pn(t,r=>this.shape.check(r));return!s&&n?.extend(null,"Array",""),s}}const qs=(...e)=>new Xs(e),Bo=D(Xs),Fo=L(e=>xt(e));class Qs extends U{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n){const s=t instanceof this.shape&&(this._c==null||this._c(t));return!s&&n?.extend(null,this.shape.name,t?.constructor.name),s}}const Vo=(e,t=null)=>new Qs(e,t);D(Qs);const jo=Vo(U);class Ho extends U{constructor(t){super(),this.len=t.length-1,this.args=$o(...t.slice(-1)),this.res=t[this.len]}check(t,n){const s=t.constructor===Function&&t.length<=this.len;return!s&&n?.extend(null,"function",typeof t),s}}const zo=D(Ho),Yo=L(e=>typeof e=="function");class Po extends U{constructor(t){super(),this.shape=t}check(t,n){const s=pn(this.shape,r=>r.check(t,n));return!s&&n?.extend(null,"Intersectinon",typeof t),s}}D(Po,e=>e.shape.length>0);class Ln extends U{static _dilutes=!0;constructor(t){super(),this.shape=t}check(t,n){const s=wn(this.shape,r=>r.check(t,n));return n?.extend(null,"Union",typeof t),s}}const vt=(...e)=>e.findIndex(t=>we.check(t))>=0?vt(...e.map(t=>Gt(t)).map(t=>we.check(t)?t.shape:[t]).flat(1)):e.length===1?e[0]:new Ln(e),we=D(Ln),Zs=()=>!0,me=L(Zs),Go=D(In,e=>e.shape===Zs),On=L(e=>typeof e=="bigint"),Jo=L(e=>e===On),tr=L(e=>typeof e=="symbol");L(e=>e===tr);const Et=L(e=>typeof e=="number"),er=L(e=>e===Et),Lt=L(e=>typeof e=="string"),nr=L(e=>e===Lt),Ue=L(e=>typeof e=="boolean"),Ko=L(e=>e===Ue),sr=Ne(void 0);D(Oe,e=>e.shape.length===1&&e.shape[0]===void 0);Ne(void 0);const ve=Ne(null),Wo=D(Oe,e=>e.shape.length===1&&e.shape[0]===null);D(Uint8Array);D(xn,e=>e.shape===Uint8Array);const Xo=vt(Et,Lt,ve,sr,On,Ue,tr);(()=>{const e=qs(me),t=Ks(Lt,me),n=vt(Et,Lt,ve,Ue,e,t);return e.shape=n,t.shape.values=n,n})();const Gt=e=>{if(jo.check(e))return e;if(vo.check(e)){const t={};for(const n in e)t[n]=Gt(e[n]);return Mo(t)}else{if(Fo.check(e))return vt(...e.map(Gt));if(Xo.check(e))return Ne(e);if(Yo.check(e))return D(e)}V()},as=uo?()=>{}:(e,t)=>{const n=new To;if(!t.check(e,n))throw Y(`Expected value to be of type ${t.constructor.name}.
3
+ ${n.toString()}`)};class qo{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:Gt(t),h:n}),this}else(t){return this.if(me,t)}done(){return(t,n)=>{for(let s=0;s<this.patterns.length;s++){const r=this.patterns[s];if(r.if.check(t))return r.h(t,n)}throw Y("Unhandled pattern")}}}const Qo=e=>new qo(e),rr=Qo(me).if(er,(e,t)=>Je(t,Zn,fe)).if(nr,(e,t)=>Do(t)).if(Ko,(e,t)=>ls(t)).if(Jo,(e,t)=>BigInt(Je(t,Zn,fe))).if(we,(e,t)=>bt(t,Ke(t,e.shape))).if(Uo,(e,t)=>{const n={};for(const s in e.shape){let r=e.shape[s];if(Oo.check(r)){if(ls(t))continue;r=r.shape}n[s]=rr(r,t)}return n}).if(Bo,(e,t)=>{const n=[],s=zs(t,0,42);for(let r=0;r<s;r++)n.push(bt(t,e.shape));return n}).if(Ys,(e,t)=>Ke(t,e.shape)).if(Wo,(e,t)=>null).if(zo,(e,t)=>{const n=bt(t,e.res);return()=>n}).if(Go,(e,t)=>bt(t,Ke(t,[Et,Lt,ve,sr,On,Ue,qs(Et),Ks(vt("a","b","c"),Et)]))).if(Ro,(e,t)=>{const n={},s=Je(t,0,3);for(let r=0;r<s;r++){const i=bt(t,e.shape.keys),o=bt(t,e.shape.values);n[i]=o}return n}).done(),bt=(e,t)=>rr(Gt(t),e),Re=typeof document<"u"?document:{};L(e=>e.nodeType===sc);typeof DOMParser<"u"&&new DOMParser;L(e=>e.nodeType===tc);L(e=>e.nodeType===ec);const Zo=e=>di(e,(t,n)=>`${n}:${t};`).join(""),tc=Re.ELEMENT_NODE,ec=Re.TEXT_NODE,nc=Re.DOCUMENT_NODE,sc=Re.DOCUMENT_FRAGMENT_NODE;L(e=>e.nodeType===nc);const Z=Symbol,ir=Z(),or=Z(),rc=Z(),ic=Z(),oc=Z(),cr=Z(),cc=Z(),Nn=Z(),lc=Z(),ac=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());const t=[],n=[];let s=0;for(;s<e.length;s++){const r=e[s];if(r===void 0)break;if(r.constructor===String||r.constructor===Number)t.push(r);else if(r.constructor===Object)break}for(s>0&&n.push(t.join(""));s<e.length;s++){const r=e[s];r instanceof Symbol||n.push(r)}return n},hc={[ir]:K("font-weight","bold"),[or]:K("font-weight","normal"),[rc]:K("color","blue"),[oc]:K("color","green"),[ic]:K("color","grey"),[cr]:K("color","red"),[cc]:K("color","purple"),[Nn]:K("color","orange"),[lc]:K("color","black")},uc=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());const t=[],n=[],s=R();let r=[],i=0;for(;i<e.length;i++){const o=e[i],c=hc[o];if(c!==void 0)s.set(c.left,c.right);else{if(o===void 0)break;if(o.constructor===String||o.constructor===Number){const l=Zo(s);i>0||l.length>0?(t.push("%c"+o),n.push(l)):t.push(o)}else break}}for(i>0&&(r=n,r.unshift(t.join("")));i<e.length;i++){const o=e[i];o instanceof Symbol||r.push(o)}return r},lr=go?uc:ac,dc=(...e)=>{console.log(...lr(e)),hr.forEach(t=>t.print(e))},ar=(...e)=>{console.warn(...lr(e)),e.unshift(Nn),hr.forEach(t=>t.print(e))},hr=rt(),ur=e=>({[Symbol.iterator](){return this},next:e}),fc=(e,t)=>ur(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),We=(e,t)=>ur(()=>{const{done:n,value:s}=e.next();return{done:n,value:n?void 0:t(s)}});class $e{constructor(t,n){this.clock=t,this.len=n}}class Rt{constructor(){this.clients=new Map}}const Ot=(e,t,n)=>t.clients.forEach((s,r)=>{const i=e.doc.store.clients.get(r);if(i!=null){const o=i[i.length-1],c=o.id.clock+o.length;for(let l=0,a=s[l];l<s.length&&a.clock<c;a=s[++l])Cr(e,i,a.clock,a.len,n)}}),gc=(e,t)=>{let n=0,s=e.length-1;for(;n<=s;){const r=H((n+s)/2),i=e[r],o=i.clock;if(o<=t){if(t<o+i.len)return r;n=r+1}else s=r-1}return null},Zt=(e,t)=>{const n=e.clients.get(t.client);return n!==void 0&&gc(n,t.clock)!==null},Mn=e=>{e.clients.forEach(t=>{t.sort((r,i)=>r.clock-i.clock);let n,s;for(n=1,s=1;n<t.length;n++){const r=t[s-1],i=t[n];r.clock+r.len>=i.clock?t[s-1]=new $e(r.clock,wt(r.len,i.clock+i.len-r.clock)):(s<n&&(t[s]=i),s++)}t.length=s})},ln=e=>{const t=new Rt;for(let n=0;n<e.length;n++)e[n].clients.forEach((s,r)=>{if(!t.clients.has(r)){const i=s.slice();for(let o=n+1;o<e.length;o++)gi(i,e[o].clients.get(r)||[]);t.clients.set(r,i)}});return Mn(t),t},Jt=(e,t,n,s)=>{J(e.clients,t,()=>[]).push(new $e(n,s))},pc=()=>new Rt,wc=e=>{const t=pc();return e.clients.forEach((n,s)=>{const r=[];for(let i=0;i<n.length;i++){const o=n[i];if(o.deleted){const c=o.id.clock;let l=o.length;if(i+1<n.length)for(let a=n[i+1];i+1<n.length&&a.deleted;a=n[++i+1])l+=a.length;r.push(new $e(c,l))}}r.length>0&&t.clients.set(s,r)}),t},$t=(e,t)=>{w(e.restEncoder,t.clients.size),X(t.clients.entries()).sort((n,s)=>s[0]-n[0]).forEach(([n,s])=>{e.resetDsCurVal(),w(e.restEncoder,n);const r=s.length;w(e.restEncoder,r);for(let i=0;i<r;i++){const o=s[i];e.writeDsClock(o.clock),e.writeDsLen(o.len)}})},Un=e=>{const t=new Rt,n=m(e.restDecoder);for(let s=0;s<n;s++){e.resetDsCurVal();const r=m(e.restDecoder),i=m(e.restDecoder);if(i>0){const o=J(t.clients,r,()=>[]);for(let c=0;c<i;c++)o.push(new $e(e.readDsClock(),e.readDsLen()))}}return t},hs=(e,t,n)=>{const s=new Rt,r=m(e.restDecoder);for(let i=0;i<r;i++){e.resetDsCurVal();const o=m(e.restDecoder),c=m(e.restDecoder),l=n.clients.get(o)||[],a=A(n,o);for(let h=0;h<c;h++){const u=e.readDsClock(),d=u+e.readDsLen();if(u<a){a<d&&Jt(s,o,a,d-a);let f=P(l,u),g=l[f];for(!g.deleted&&g.id.clock<u&&(l.splice(f+1,0,Ee(t,g,u-g.id.clock)),f++);f<l.length&&(g=l[f++],g.id.clock<d);)g.deleted||(d<g.id.clock+g.length&&l.splice(f,0,Ee(t,g,d-g.id.clock)),g.delete(t))}else Jt(s,o,u,d-u)}}if(s.clients.size>0){const i=new ut;return w(i.restEncoder,0),$t(i,s),i.toUint8Array()}return null},dr=vs;class mt extends mn{constructor({guid:t=Xi(),collectionid:n=null,gc:s=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:o=!1,shouldLoad:c=!0}={}){super(),this.gc=s,this.gcFilter=r,this.clientID=dr(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new _r,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=o,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=os(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const l=()=>os(a=>{const h=u=>{(u===void 0||u===!0)&&(this.off("sync",h),a())};this.on("sync",h)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=a===void 0||a===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){const t=this._item;t!==null&&!this.shouldLoad&&_(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(X(this.subdocs).map(t=>t.guid))}transact(t,n=null){return _(this,t,n)}get(t,n=I){const s=J(this.share,t,()=>{const i=new n;return i._integrate(this,null),i}),r=s.constructor;if(n!==I&&r!==n)if(r===I){const i=new n;i._map=s._map,s._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=i}),i._start=s._start;for(let o=i._start;o!==null;o=o.right)o.parent=i;return i._length=s._length,this.share.set(t,i),i._integrate(this,null),i}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return s}getArray(t=""){return this.get(t,At)}getText(t=""){return this.get(t,Ut)}getMap(t=""){return this.get(t,Mt)}getXmlElement(t=""){return this.get(t,q)}getXmlFragment(t=""){return this.get(t,dt)}toJSON(){const t={};return this.share.forEach((n,s)=>{t[s]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,X(this.subdocs).forEach(n=>n.destroy());const t=this._item;if(t!==null){this._item=null;const n=t.content;n.doc=new mt({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,_(t.parent.doc,s=>{const r=n.doc;t.deleted||s.subdocsAdded.add(r),s.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class fr{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return m(this.restDecoder)}readDsLen(){return m(this.restDecoder)}}class gr extends fr{readLeftID(){return y(m(this.restDecoder),m(this.restDecoder))}readRightID(){return y(m(this.restDecoder),m(this.restDecoder))}readClient(){return m(this.restDecoder)}readInfo(){return It(this.restDecoder)}readString(){return st(this.restDecoder)}readParentInfo(){return m(this.restDecoder)===1}readTypeRef(){return m(this.restDecoder)}readLen(){return m(this.restDecoder)}readAny(){return Yt(this.restDecoder)}readBuf(){return So(O(this.restDecoder))}readJSON(){return JSON.parse(st(this.restDecoder))}readKey(){return st(this.restDecoder)}}class mc{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=m(this.restDecoder),this.dsCurrVal}readDsLen(){const t=m(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class Nt extends mc{constructor(t){super(t),this.keys=[],m(t),this.keyClockDecoder=new Ge(O(t)),this.clientDecoder=new ae(O(t)),this.leftClockDecoder=new Ge(O(t)),this.rightClockDecoder=new Ge(O(t)),this.infoDecoder=new is(O(t),It),this.stringDecoder=new Ji(O(t)),this.parentInfoDecoder=new is(O(t),It),this.typeRefDecoder=new ae(O(t)),this.lenDecoder=new ae(O(t))}readLeftID(){return new Dt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Dt(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Yt(this.restDecoder)}readBuf(){return O(this.restDecoder)}readJSON(){return Yt(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{const n=this.stringDecoder.read();return this.keys.push(n),n}}}class pr{constructor(){this.restEncoder=N()}toUint8Array(){return C(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){w(this.restEncoder,t)}writeDsLen(t){w(this.restEncoder,t)}}class te extends pr{writeLeftID(t){w(this.restEncoder,t.client),w(this.restEncoder,t.clock)}writeRightID(t){w(this.restEncoder,t.client),w(this.restEncoder,t.clock)}writeClient(t){w(this.restEncoder,t)}writeInfo(t){sn(this.restEncoder,t)}writeString(t){ht(this.restEncoder,t)}writeParentInfo(t){w(this.restEncoder,t?1:0)}writeTypeRef(t){w(this.restEncoder,t)}writeLen(t){w(this.restEncoder,t)}writeAny(t){zt(this.restEncoder,t)}writeBuf(t){E(this.restEncoder,t)}writeJSON(t){ht(this.restEncoder,JSON.stringify(t))}writeKey(t){ht(this.restEncoder,t)}}class wr{constructor(){this.restEncoder=N(),this.dsCurrVal=0}toUint8Array(){return C(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,w(this.restEncoder,n)}writeDsLen(t){t===0&&V(),w(this.restEncoder,t-1),this.dsCurrVal+=t}}class ut extends wr{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Pe,this.clientEncoder=new le,this.leftClockEncoder=new Pe,this.rightClockEncoder=new Pe,this.infoEncoder=new ns(sn),this.stringEncoder=new Ri,this.parentInfoEncoder=new ns(sn),this.typeRefEncoder=new le,this.lenEncoder=new le}toUint8Array(){const t=N();return w(t,0),E(t,this.keyClockEncoder.toUint8Array()),E(t,this.clientEncoder.toUint8Array()),E(t,this.leftClockEncoder.toUint8Array()),E(t,this.rightClockEncoder.toUint8Array()),E(t,C(this.infoEncoder)),E(t,this.stringEncoder.toUint8Array()),E(t,C(this.parentInfoEncoder)),E(t,this.typeRefEncoder.toUint8Array()),E(t,this.lenEncoder.toUint8Array()),xe(t,C(this.restEncoder)),C(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){zt(this.restEncoder,t)}writeBuf(t){E(this.restEncoder,t)}writeJSON(t){zt(this.restEncoder,t)}writeKey(t){const n=this.keyMap.get(t);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}}const yc=(e,t,n,s)=>{s=wt(s,t[0].id.clock);const r=P(t,s);w(e.restEncoder,t.length-r),e.writeClient(n),w(e.restEncoder,s);const i=t[r];i.write(e,s-i.id.clock);for(let o=r+1;o<t.length;o++)t[o].write(e,0)},vn=(e,t,n)=>{const s=new Map;n.forEach((r,i)=>{A(t,i)>r&&s.set(i,r)}),Be(t).forEach((r,i)=>{n.has(i)||s.set(i,0)}),w(e.restEncoder,s.size),X(s.entries()).sort((r,i)=>i[0]-r[0]).forEach(([r,i])=>{yc(e,t.clients.get(r),r,i)})},bc=(e,t)=>{const n=R(),s=m(e.restDecoder);for(let r=0;r<s;r++){const i=m(e.restDecoder),o=new Array(i),c=e.readClient();let l=m(e.restDecoder);n.set(c,{i:0,refs:o});for(let a=0;a<i;a++){const h=e.readInfo();switch(Te&h){case 0:{const u=e.readLen();o[a]=new B(y(c,l),u),l+=u;break}case 10:{const u=m(e.restDecoder);o[a]=new F(y(c,l),u),l+=u;break}default:{const u=(h&(W|$))===0,d=new S(y(c,l),null,(h&$)===$?e.readLeftID():null,null,(h&W)===W?e.readRightID():null,u?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,u&&(h&jt)===jt?e.readString():null,zr(e,h));o[a]=d,l+=d.length}}}}return n},kc=(e,t,n)=>{const s=[];let r=X(n.keys()).sort((f,g)=>f-g);if(r.length===0)return null;const i=()=>{if(r.length===0)return null;let f=n.get(r[r.length-1]);for(;f.refs.length===f.i;)if(r.pop(),r.length>0)f=n.get(r[r.length-1]);else return null;return f};let o=i();if(o===null)return null;const c=new _r,l=new Map,a=(f,g)=>{const p=l.get(f);(p==null||p>g)&&l.set(f,g)};let h=o.refs[o.i++];const u=new Map,d=()=>{for(const f of s){const g=f.id.client,p=n.get(g);p?(p.i--,c.clients.set(g,p.refs.slice(p.i)),n.delete(g),p.i=0,p.refs=[]):c.clients.set(g,[f]),r=r.filter(b=>b!==g)}s.length=0};for(;;){if(h.constructor!==F){const g=J(u,h.id.client,()=>A(t,h.id.client))-h.id.clock;if(g<0)s.push(h),a(h.id.client,h.id.clock-1),d();else{const p=h.getMissing(e,t);if(p!==null){s.push(h);const b=n.get(p)||{refs:[],i:0};if(b.refs.length===b.i)a(p,A(t,p)),d();else{h=b.refs[b.i++];continue}}else(g===0||g<h.length)&&(h.integrate(e,g),u.set(h.id.client,h.id.clock+h.length))}}if(s.length>0)h=s.pop();else if(o!==null&&o.i<o.refs.length)h=o.refs[o.i++];else{if(o=i(),o===null)break;h=o.refs[o.i++]}}if(c.clients.size>0){const f=new ut;return vn(f,c,new Map),w(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},_c=(e,t)=>vn(e,t.doc.store,t.beforeState),Sc=(e,t,n,s=new Nt(e))=>_(t,r=>{r.local=!1;let i=!1;const o=r.doc,c=o.store,l=bc(s,o),a=kc(r,c,l),h=c.pendingStructs;if(h){for(const[d,f]of h.missing)if(f<A(c,d)){i=!0;break}if(a){for(const[d,f]of a.missing){const g=h.missing.get(d);(g==null||g>f)&&h.missing.set(d,f)}h.update=be([h.update,a.update])}}else c.pendingStructs=a;const u=hs(s,r,c);if(c.pendingDs){const d=new Nt(ct(c.pendingDs));m(d.restDecoder);const f=hs(d,r,c);u&&f?c.pendingDs=be([u,f]):c.pendingDs=u||f}else c.pendingDs=u;if(i){const d=c.pendingStructs.update;c.pendingStructs=null,mr(r.doc,d)}},n,!1),mr=(e,t,n,s=Nt)=>{const r=ct(t);Sc(r,e,n,new s(r))},Cc=(e,t,n)=>mr(e,t,n,gr),Ec=(e,t,n=new Map)=>{vn(e,t.store,n),$t(e,wc(t.store))},Dc=(e,t=new Uint8Array([0]),n=new ut)=>{const s=yr(t);Ec(n,e,s);const r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(zc(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===te)return jc(r.map((i,o)=>o===0?i:Pc(i)));if(n.constructor===ut)return be(r)}return r[0]},Ac=(e,t)=>Dc(e,t,new te),Tc=e=>{const t=new Map,n=m(e.restDecoder);for(let s=0;s<n;s++){const r=m(e.restDecoder),i=m(e.restDecoder);t.set(r,i)}return t},yr=e=>Tc(new fr(ct(e))),br=(e,t)=>(w(e.restEncoder,t.size),X(t.entries()).sort((n,s)=>s[0]-n[0]).forEach(([n,s])=>{w(e.restEncoder,n),w(e.restEncoder,s)}),e),xc=(e,t)=>br(e,Be(t.store)),Ic=(e,t=new wr)=>(e instanceof Map?br(t,e):xc(t,e),t.toUint8Array()),Lc=e=>Ic(e,new pr);class Oc{constructor(){this.l=[]}}const us=()=>new Oc,ds=(e,t)=>e.l.push(t),fs=(e,t)=>{const n=e.l,s=n.length;e.l=n.filter(r=>t!==r),s===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},kr=(e,t,n)=>An(e.l,[t,n]);class Dt{constructor(t,n){this.client=t,this.clock=n}}const re=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,y=(e,t)=>new Dt(e,t),Nc=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw V()},ye=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},kt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Zt(t.ds,e.id),an=(e,t)=>{const n=J(e.meta,an,rt),s=e.doc.store;n.has(t)||(t.sv.forEach((r,i)=>{r<A(s,i)&&v(e,y(i,r))}),Ot(e,t.ds,r=>{}),n.add(t))};class _r{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Be=e=>{const t=new Map;return e.clients.forEach((n,s)=>{const r=n[n.length-1];t.set(s,r.id.clock+r.length)}),t},A=(e,t)=>{const n=e.clients.get(t);if(n===void 0)return 0;const s=n[n.length-1];return s.id.clock+s.length},Sr=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{const s=n[n.length-1];if(s.id.clock+s.length!==t.id.clock)throw V()}n.push(t)},P=(e,t)=>{let n=0,s=e.length-1,r=e[s],i=r.id.clock;if(i===t)return s;let o=H(t/(i+r.length-1)*s);for(;n<=s;){if(r=e[o],i=r.id.clock,i<=t){if(t<i+r.length)return o;n=o+1}else s=o-1;o=H((n+s)/2)}throw V()},Mc=(e,t)=>{const n=e.clients.get(t.client);return n[P(n,t.clock)]},he=Mc,hn=(e,t,n)=>{const s=P(t,n),r=t[s];return r.id.clock<n&&r instanceof S?(t.splice(s+1,0,Ee(e,r,n-r.id.clock)),s+1):s},v=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[hn(e,n,t.clock)]},gs=(e,t,n)=>{const s=t.clients.get(n.client),r=P(s,n.clock),i=s[r];return n.clock!==i.id.clock+i.length-1&&i.constructor!==B&&s.splice(r+1,0,Ee(e,i,n.clock-i.id.clock+1)),i},Uc=(e,t,n)=>{const s=e.clients.get(t.id.client);s[P(s,t.id.clock)]=n},Cr=(e,t,n,s,r)=>{if(s===0)return;const i=n+s;let o=hn(e,t,n),c;do c=t[o++],i<c.id.clock+c.length&&hn(e,t,i),r(c);while(o<t.length&&t[o].id.clock<i)};class vc{constructor(t,n,s){this.doc=t,this.deleteSet=new Rt,this.beforeState=Be(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=s,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const ps=(e,t)=>t.deleteSet.clients.size===0&&!fi(t.afterState,(n,s)=>t.beforeState.get(s)!==n)?!1:(Mn(t.deleteSet),_c(e,t),$t(e,t.deleteSet),!0),ws=(e,t,n)=>{const s=t._item;(s===null||s.id.clock<(e.beforeState.get(s.id.client)||0)&&!s.deleted)&&J(e.changed,t,rt).add(n)},ue=(e,t)=>{let n=e[t],s=e[t-1],r=t;for(;r>0;n=s,s=e[--r-1]){if(s.deleted===n.deleted&&s.constructor===n.constructor&&s.mergeWith(n)){n instanceof S&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,s);continue}break}const i=t-r;return i&&e.splice(t+1-i,i),i},Rc=(e,t,n)=>{for(const[s,r]of e.clients.entries()){const i=t.clients.get(s);for(let o=r.length-1;o>=0;o--){const c=r[o],l=c.clock+c.len;for(let a=P(i,c.clock),h=i[a];a<i.length&&h.id.clock<l;h=i[++a]){const u=i[a];if(c.clock+c.len<=u.id.clock)break;u instanceof S&&u.deleted&&!u.keep&&n(u)&&u.gc(t,!1)}}}},$c=(e,t)=>{e.clients.forEach((n,s)=>{const r=t.clients.get(s);for(let i=n.length-1;i>=0;i--){const o=n[i],c=yn(r.length-1,1+P(r,o.clock+o.len-1));for(let l=c,a=r[l];l>0&&a.id.clock>=o.clock;a=r[l])l-=1+ue(r,l)}})},Er=(e,t)=>{if(t<e.length){const n=e[t],s=n.doc,r=s.store,i=n.deleteSet,o=n._mergeStructs;try{Mn(i),n.afterState=Be(n.doc.store),s.emit("beforeObserverCalls",[n,s]);const c=[];n.changed.forEach((l,a)=>c.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(n,l)})),c.push(()=>{n.changedParentTypes.forEach((l,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&c.push(()=>{l=l.filter(h=>h.target._item===null||!h.target._item.deleted),l.forEach(h=>{h.currentTarget=a,h._path=null}),l.sort((h,u)=>h.path.length-u.path.length),kr(a._dEH,l,n)})}),c.push(()=>s.emit("afterTransaction",[n,s])),c.push(()=>{n._needFormattingCleanup&&il(n)})}),An(c,[])}finally{s.gc&&Rc(i,r,s.gcFilter),$c(i,r),n.afterState.forEach((h,u)=>{const d=n.beforeState.get(u)||0;if(d!==h){const f=r.clients.get(u),g=wt(P(f,d),1);for(let p=f.length-1;p>=g;)p-=1+ue(f,p)}});for(let h=o.length-1;h>=0;h--){const{client:u,clock:d}=o[h].id,f=r.clients.get(u),g=P(f,d);g+1<f.length&&ue(f,g+1)>1||g>0&&ue(f,g)}if(!n.local&&n.afterState.get(s.clientID)!==n.beforeState.get(s.clientID)&&(dc(Nn,ir,"[yjs] ",or,cr,"Changed the client-id because another client seems to be using it."),s.clientID=dr()),s.emit("afterTransactionCleanup",[n,s]),s._observers.has("update")){const h=new te;ps(h,n)&&s.emit("update",[h.toUint8Array(),n.origin,s,n])}if(s._observers.has("updateV2")){const h=new ut;ps(h,n)&&s.emit("updateV2",[h.toUint8Array(),n.origin,s,n])}const{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:a}=n;(c.size>0||a.size>0||l.size>0)&&(c.forEach(h=>{h.clientID=s.clientID,h.collectionid==null&&(h.collectionid=s.collectionid),s.subdocs.add(h)}),a.forEach(h=>s.subdocs.delete(h)),s.emit("subdocs",[{loaded:l,added:c,removed:a},s,n]),a.forEach(h=>h.destroy())),e.length<=t+1?(s._transactionCleanups=[],s.emit("afterAllTransactions",[s,e])):Er(e,t+1)}}},_=(e,t,n=null,s=!0)=>{const r=e._transactionCleanups;let i=!1,o=null;e._transaction===null&&(i=!0,e._transaction=new vc(e,n,s),r.push(e._transaction),r.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(i){const c=e._transaction===r[0];e._transaction=null,c&&Er(r,0)}}return o};class Bc{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const ms=(e,t,n)=>{Ot(e,n.deletions,s=>{s instanceof S&&t.scope.some(r=>r===e.doc||ye(r,s))&&zn(s,!1)})},ys=(e,t,n)=>{let s=null;const r=e.doc,i=e.scope;_(r,c=>{for(;t.length>0&&e.currStackItem===null;){const l=r.store,a=t.pop(),h=new Set,u=[];let d=!1;Ot(c,a.insertions,f=>{if(f instanceof S){if(f.redone!==null){let{item:g,diff:p}=Nl(l,f.id);p>0&&(g=v(c,y(g.id.client,g.id.clock+p))),f=g}!f.deleted&&i.some(g=>g===c.doc||ye(g,f))&&u.push(f)}}),Ot(c,a.deletions,f=>{f instanceof S&&i.some(g=>g===c.doc||ye(g,f))&&!Zt(a.insertions,f.id)&&h.add(f)}),h.forEach(f=>{d=Hr(c,f,h,a.insertions,e.ignoreRemoteMapChanges,e)!==null||d});for(let f=u.length-1;f>=0;f--){const g=u[f];e.deleteFilter(g)&&(g.delete(c),d=!0)}e.currStackItem=d?a:null}c.changed.forEach((l,a)=>{l.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),s=c},e);const o=e.currStackItem;if(o!=null){const c=s.changedParentTypes;e.emit("stack-item-popped",[{stackItem:o,type:n,changedParentTypes:c,origin:e},e]),e.currStackItem=null}return o};class Fc extends mn{constructor(t,{captureTimeout:n=500,captureTransaction:s=l=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:c=xt(t)?t[0].doc:t instanceof mt?t:t.doc}={}){super(),this.scope=[],this.doc=c,this.addToScope(t),this.deleteFilter=r,i.add(this),this.trackedOrigins=i,this.captureTransaction=s,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=n,this.afterTransactionHandler=l=>{if(!this.captureTransaction(l)||!this.scope.some(b=>l.changedParentTypes.has(b)||b===this.doc)||!this.trackedOrigins.has(l.origin)&&(!l.origin||!this.trackedOrigins.has(l.origin.constructor)))return;const a=this.undoing,h=this.redoing,u=a?this.redoStack:this.undoStack;a?this.stopCapturing():h||this.clear(!1,!0);const d=new Rt;l.afterState.forEach((b,k)=>{const Wn=l.beforeState.get(k)||0,Xn=b-Wn;Xn>0&&Jt(d,k,Wn,Xn)});const f=it();let g=!1;if(this.lastChange>0&&f-this.lastChange<this.captureTimeout&&u.length>0&&!a&&!h){const b=u[u.length-1];b.deletions=ln([b.deletions,l.deleteSet]),b.insertions=ln([b.insertions,d])}else u.push(new Bc(l.deleteSet,d)),g=!0;!a&&!h&&(this.lastChange=f),Ot(l,l.deleteSet,b=>{b instanceof S&&this.scope.some(k=>k===l.doc||ye(k,b))&&zn(b,!0)});const p=[{stackItem:u[u.length-1],origin:l.origin,type:a?"redo":"undo",changedParentTypes:l.changedParentTypes},this];g?this.emit("stack-item-added",p):this.emit("stack-item-updated",p)},this.destroy=this.destroy.bind(this),this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",this.destroy)}addToScope(t){const n=new Set(this.scope);t=xt(t)?t:[t],t.forEach(s=>{n.has(s)||(n.add(s),(s instanceof I?s.doc!==this.doc:s!==this.doc)&&ar("[yjs#509] Not same Y.Doc"),this.scope.push(s))})}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,n=!0){(t&&this.canUndo()||n&&this.canRedo())&&this.doc.transact(s=>{t&&(this.undoStack.forEach(r=>ms(s,this,r)),this.undoStack=[]),n&&(this.redoStack.forEach(r=>ms(s,this,r)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let t;try{t=ys(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=ys(this,this.redoStack,"redo")}finally{this.redoing=!1}return t}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),this.doc.off("destroy",this.destroy),super.destroy()}}function*Vc(e){const t=m(e.restDecoder);for(let n=0;n<t;n++){const s=m(e.restDecoder),r=e.readClient();let i=m(e.restDecoder);for(let o=0;o<s;o++){const c=e.readInfo();if(c===10){const l=m(e.restDecoder);yield new F(y(r,i),l),i+=l}else if((Te&c)!==0){const l=(c&(W|$))===0,a=new S(y(r,i),null,(c&$)===$?e.readLeftID():null,null,(c&W)===W?e.readRightID():null,l?e.readParentInfo()?e.readString():e.readLeftID():null,l&&(c&jt)===jt?e.readString():null,zr(e,c));yield a,i+=a.length}else{const l=e.readLen();yield new B(y(r,i),l),i+=l}}}}class Rn{constructor(t,n){this.gen=Vc(t),this.curr=null,this.done=!1,this.filterSkips=n,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===F);return this.curr}}class $n{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const jc=e=>be(e,gr,te),Hc=(e,t)=>{if(e.constructor===B){const{client:n,clock:s}=e.id;return new B(y(n,s+t),e.length-t)}else if(e.constructor===F){const{client:n,clock:s}=e.id;return new F(y(n,s+t),e.length-t)}else{const n=e,{client:s,clock:r}=n.id;return new S(y(s,r+t),null,y(s,r+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},be=(e,t=Nt,n=ut)=>{if(e.length===1)return e[0];const s=e.map(h=>new t(ct(h)));let r=s.map(h=>new Rn(h,!0)),i=null;const o=new n,c=new $n(o);for(;r=r.filter(d=>d.curr!==null),r.sort((d,f)=>{if(d.curr.id.client===f.curr.id.client){const g=d.curr.id.clock-f.curr.id.clock;return g===0?d.curr.constructor===f.curr.constructor?0:d.curr.constructor===F?1:-1:g}else return f.curr.id.client-d.curr.id.client}),r.length!==0;){const h=r[0],u=h.curr.id.client;if(i!==null){let d=h.curr,f=!1;for(;d!==null&&d.id.clock+d.length<=i.struct.id.clock+i.struct.length&&d.id.client>=i.struct.id.client;)d=h.next(),f=!0;if(d===null||d.id.client!==u||f&&d.id.clock>i.struct.id.clock+i.struct.length)continue;if(u!==i.struct.id.client)et(c,i.struct,i.offset),i={struct:d,offset:0},h.next();else if(i.struct.id.clock+i.struct.length<d.id.clock)if(i.struct.constructor===F)i.struct.length=d.id.clock+d.length-i.struct.id.clock;else{et(c,i.struct,i.offset);const g=d.id.clock-i.struct.id.clock-i.struct.length;i={struct:new F(y(u,i.struct.id.clock+i.struct.length),g),offset:0}}else{const g=i.struct.id.clock+i.struct.length-d.id.clock;g>0&&(i.struct.constructor===F?i.struct.length-=g:d=Hc(d,g)),i.struct.mergeWith(d)||(et(c,i.struct,i.offset),i={struct:d,offset:0},h.next())}}else i={struct:h.curr,offset:0},h.next();for(let d=h.curr;d!==null&&d.id.client===u&&d.id.clock===i.struct.id.clock+i.struct.length&&d.constructor!==F;d=h.next())et(c,i.struct,i.offset),i={struct:d,offset:0}}i!==null&&(et(c,i.struct,i.offset),i=null),Bn(c);const l=s.map(h=>Un(h)),a=ln(l);return $t(o,a),o.toUint8Array()},zc=(e,t,n=Nt,s=ut)=>{const r=yr(t),i=new s,o=new $n(i),c=new n(ct(e)),l=new Rn(c,!1);for(;l.curr;){const h=l.curr,u=h.id.client,d=r.get(u)||0;if(l.curr.constructor===F){l.next();continue}if(h.id.clock+h.length>d)for(et(o,h,wt(d-h.id.clock,0)),l.next();l.curr&&l.curr.id.client===u;)et(o,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===u&&l.curr.id.clock+l.curr.length<=d;)l.next()}Bn(o);const a=Un(c);return $t(i,a),i.toUint8Array()},Dr=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:C(e.encoder.restEncoder)}),e.encoder.restEncoder=N(),e.written=0)},et=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Dr(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),w(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Bn=e=>{Dr(e);const t=e.encoder.restEncoder;w(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const s=e.clientStructs[n];w(t,s.written),xe(t,s.restEncoder)}},Yc=(e,t,n,s)=>{const r=new n(ct(e)),i=new Rn(r,!1),o=new s,c=new $n(o);for(let a=i.curr;a!==null;a=i.next())et(c,t(a),0);Bn(c);const l=Un(r);return $t(o,l),o.toUint8Array()},Pc=e=>Yc(e,lo,Nt,te),bs="You must not compute changes after the event-handler fired.";class Fe{constructor(t,n){this.target=t,this.currentTarget=t,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Gc(this.currentTarget,this.target))}deletes(t){return Zt(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Y(bs);const t=new Map,n=this.target;this.transaction.changed.get(n).forEach(r=>{if(r!==null){const i=n._map.get(r);let o,c;if(this.adds(i)){let l=i.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(i))if(l!==null&&this.deletes(l))o="delete",c=He(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",c=He(l.content.getContent())):(o="add",c=void 0)}else if(this.deletes(i))o="delete",c=He(i.content.getContent());else return;t.set(r,{action:o,oldValue:c})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw Y(bs);const n=this.target,s=rt(),r=rt(),i=[];if(t={added:s,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(n).has(null)){let c=null;const l=()=>{c&&i.push(c)};for(let a=n._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((c===null||c.delete===void 0)&&(l(),c={delete:0}),c.delete+=a.length,r.add(a)):this.adds(a)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(a.content.getContent()),s.add(a)):((c===null||c.retain===void 0)&&(l(),c={retain:0}),c.retain+=a.length);c!==null&&c.retain===void 0&&l()}this._changes=t}return t}}const Gc=(e,t)=>{const n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let s=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)!r.deleted&&r.countable&&(s+=r.length),r=r.right;n.unshift(s)}t=t._item.parent}return n},M=()=>{ar("Invalid access: Add Yjs type to a document before reading data.")},Ar=80;let Fn=0;class Jc{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=Fn++}}const Kc=e=>{e.timestamp=Fn++},Tr=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Fn++},Wc=(e,t,n)=>{if(e.length>=Ar){const s=e.reduce((r,i)=>r.timestamp<i.timestamp?r:i);return Tr(s,t,n),s}else{const s=new Jc(t,n);return e.push(s),s}},Ve=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;const n=e._searchMarker.length===0?null:e._searchMarker.reduce((i,o)=>ce(t-i.index)<ce(t-o.index)?i:o);let s=e._start,r=0;for(n!==null&&(s=n.p,r=n.index,Kc(n));s.right!==null&&r<t;){if(!s.deleted&&s.countable){if(t<r+s.length)break;r+=s.length}s=s.right}for(;s.left!==null&&r>t;)s=s.left,!s.deleted&&s.countable&&(r-=s.length);for(;s.left!==null&&s.left.id.client===s.id.client&&s.left.id.clock+s.left.length===s.id.clock;)s=s.left,!s.deleted&&s.countable&&(r-=s.length);return n!==null&&ce(n.index-r)<s.parent.length/Ar?(Tr(n,s,r),n):Wc(e._searchMarker,s,r)},Kt=(e,t,n)=>{for(let s=e.length-1;s>=0;s--){const r=e[s];if(n>0){let i=r.p;for(i.marker=!1;i&&(i.deleted||!i.countable);)i=i.left,i&&!i.deleted&&i.countable&&(r.index-=i.length);if(i===null||i.marker===!0){e.splice(s,1);continue}r.p=i,i.marker=!0}(t<r.index||n>0&&t===r.index)&&(r.index=wt(t,r.index+n))}},je=(e,t,n)=>{const s=e,r=t.changedParentTypes;for(;J(r,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;kr(s._eH,n,t)};class I{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=us(),this._dEH=us(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw j()}clone(){throw j()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,n){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){ds(this._eH,t)}observeDeep(t){ds(this._dEH,t)}unobserve(t){fs(this._eH,t)}unobserveDeep(t){fs(this._dEH,t)}toJSON(){}}const xr=(e,t,n)=>{e.doc??M(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let s=n-t;const r=[];let i=e._start;for(;i!==null&&s>0;){if(i.countable&&!i.deleted){const o=i.content.getContent();if(o.length<=t)t-=o.length;else{for(let c=t;c<o.length&&s>0;c++)r.push(o[c]),s--;t=0}}i=i.right}return r},Ir=e=>{e.doc??M();const t=[];let n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){const s=n.content.getContent();for(let r=0;r<s.length;r++)t.push(s[r])}n=n.right}return t},Wt=(e,t)=>{let n=0,s=e._start;for(e.doc??M();s!==null;){if(s.countable&&!s.deleted){const r=s.content.getContent();for(let i=0;i<r.length;i++)t(r[i],n++,e)}s=s.right}},Lr=(e,t)=>{const n=[];return Wt(e,(s,r)=>{n.push(t(s,r,e))}),n},Xc=e=>{let t=e._start,n=null,s=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),s=0,t=t.right}const r=n[s++];return n.length<=s&&(n=null),{done:!1,value:r}}}},Or=(e,t)=>{e.doc??M();const n=Ve(e,t);let s=e._start;for(n!==null&&(s=n.p,t-=n.index);s!==null;s=s.right)if(!s.deleted&&s.countable){if(t<s.length)return s.content.getContent()[t];t-=s.length}},ke=(e,t,n,s)=>{let r=n;const i=e.doc,o=i.clientID,c=i.store,l=n===null?t._start:n.right;let a=[];const h=()=>{a.length>0&&(r=new S(y(o,A(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new ft(a)),r.integrate(e,0),a=[])};s.forEach(u=>{if(u===null)a.push(u);else switch(u.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(u);break;default:switch(h(),u.constructor){case Uint8Array:case ArrayBuffer:r=new S(y(o,A(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new ee(new Uint8Array(u))),r.integrate(e,0);break;case mt:r=new S(y(o,A(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new ne(u)),r.integrate(e,0);break;default:if(u instanceof I)r=new S(y(o,A(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new tt(u)),r.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},Nr=()=>Y("Length exceeded!"),Mr=(e,t,n,s)=>{if(n>t._length)throw Nr();if(n===0)return t._searchMarker&&Kt(t._searchMarker,n,s.length),ke(e,t,null,s);const r=n,i=Ve(t,n);let o=t._start;for(i!==null&&(o=i.p,n-=i.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&v(e,y(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&Kt(t._searchMarker,r,s.length),ke(e,t,o,s)},qc=(e,t,n)=>{let r=(t._searchMarker||[]).reduce((i,o)=>o.index>i.index?o:i,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return ke(e,t,r,n)},Ur=(e,t,n,s)=>{if(s===0)return;const r=n,i=s,o=Ve(t,n);let c=t._start;for(o!==null&&(c=o.p,n-=o.index);c!==null&&n>0;c=c.right)!c.deleted&&c.countable&&(n<c.length&&v(e,y(c.id.client,c.id.clock+n)),n-=c.length);for(;s>0&&c!==null;)c.deleted||(s<c.length&&v(e,y(c.id.client,c.id.clock+s)),c.delete(e),s-=c.length),c=c.right;if(s>0)throw Nr();t._searchMarker&&Kt(t._searchMarker,r,-i+s)},_e=(e,t,n)=>{const s=t._map.get(n);s!==void 0&&s.delete(e)},Vn=(e,t,n,s)=>{const r=t._map.get(n)||null,i=e.doc,o=i.clientID;let c;if(s==null)c=new ft([s]);else switch(s.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:c=new ft([s]);break;case Uint8Array:c=new ee(s);break;case mt:c=new ne(s);break;default:if(s instanceof I)c=new tt(s);else throw new Error("Unexpected content type")}new S(y(o,A(i.store,o)),r,r&&r.lastId,null,null,t,n,c).integrate(e,0)},jn=(e,t)=>{e.doc??M();const n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},vr=e=>{const t={};return e.doc??M(),e._map.forEach((n,s)=>{n.deleted||(t[s]=n.content.getContent()[n.length-1])}),t},Rr=(e,t)=>{e.doc??M();const n=e._map.get(t);return n!==void 0&&!n.deleted},Qc=(e,t)=>{const n={};return e._map.forEach((s,r)=>{let i=s;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&kt(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},ie=e=>(e.doc??M(),fc(e._map.entries(),t=>!t[1].deleted));class Zc extends Fe{}class At extends I{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new At;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new At}clone(){const t=new At;return t.insert(0,this.toArray().map(n=>n instanceof I?n.clone():n)),t}get length(){return this.doc??M(),this._length}_callObserver(t,n){super._callObserver(t,n),je(this,t,new Zc(this,t))}insert(t,n){this.doc!==null?_(this.doc,s=>{Mr(s,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?_(this.doc,n=>{qc(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?_(this.doc,s=>{Ur(s,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return Or(this,t)}toArray(){return Ir(this)}slice(t=0,n=this.length){return xr(this,t,n)}toJSON(){return this.map(t=>t instanceof I?t.toJSON():t)}map(t){return Lr(this,t)}forEach(t){Wt(this,t)}[Symbol.iterator](){return Xc(this)}_write(t){t.writeTypeRef(El)}}const tl=e=>new At;class el extends Fe{constructor(t,n,s){super(t,n),this.keysChanged=s}}class Mt extends I{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach((s,r)=>{this.set(r,s)}),this._prelimContent=null}_copy(){return new Mt}clone(){const t=new Mt;return this.forEach((n,s)=>{t.set(s,n instanceof I?n.clone():n)}),t}_callObserver(t,n){je(this,t,new el(this,t,n))}toJSON(){this.doc??M();const t={};return this._map.forEach((n,s)=>{if(!n.deleted){const r=n.content.getContent()[n.length-1];t[s]=r instanceof I?r.toJSON():r}}),t}get size(){return[...ie(this)].length}keys(){return We(ie(this),t=>t[0])}values(){return We(ie(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return We(ie(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??M(),this._map.forEach((n,s)=>{n.deleted||t(n.content.getContent()[n.length-1],s,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?_(this.doc,n=>{_e(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?_(this.doc,s=>{Vn(s,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return jn(this,t)}has(t){return Rr(this,t)}clear(){this.doc!==null?_(this.doc,t=>{this.forEach(function(n,s,r){_e(t,r,s)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Dl)}}const nl=e=>new Mt,nt=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&oo(e,t);class un{constructor(t,n,s,r){this.left=t,this.right=n,this.index=s,this.currentAttributes=r}forward(){this.right===null&&V(),this.right.content.constructor===T?this.right.deleted||Bt(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}}const ks=(e,t,n)=>{for(;t.right!==null&&n>0;)t.right.content.constructor===T?t.right.deleted||Bt(t.currentAttributes,t.right.content):t.right.deleted||(n<t.right.length&&v(e,y(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length),t.left=t.right,t.right=t.right.right;return t},oe=(e,t,n,s)=>{const r=new Map,i=s?Ve(t,n):null;if(i){const o=new un(i.p.left,i.p,i.index,r);return ks(e,o,n-i.index)}else{const o=new un(null,t._start,0,r);return ks(e,o,n)}},$r=(e,t,n,s)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===T&&nt(s.get(n.right.content.key),n.right.content.value));)n.right.deleted||s.delete(n.right.content.key),n.forward();const r=e.doc,i=r.clientID;s.forEach((o,c)=>{const l=n.left,a=n.right,h=new S(y(i,A(r.store,i)),l,l&&l.lastId,a,a&&a.id,t,null,new T(c,o));h.integrate(e,0),n.right=h,n.forward()})},Bt=(e,t)=>{const{key:n,value:s}=t;s===null?e.delete(n):e.set(n,s)},Br=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===T&&nt(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},Fr=(e,t,n,s)=>{const r=e.doc,i=r.clientID,o=new Map;for(const c in s){const l=s[c],a=n.currentAttributes.get(c)??null;if(!nt(a,l)){o.set(c,a);const{left:h,right:u}=n;n.right=new S(y(i,A(r.store,i)),h,h&&h.lastId,u,u&&u.id,t,null,new T(c,l)),n.right.integrate(e,0),n.forward()}}return o},Xe=(e,t,n,s,r)=>{n.currentAttributes.forEach((d,f)=>{r[f]===void 0&&(r[f]=null)});const i=e.doc,o=i.clientID;Br(n,r);const c=Fr(e,t,n,r),l=s.constructor===String?new G(s):s instanceof I?new tt(s):new yt(s);let{left:a,right:h,index:u}=n;t._searchMarker&&Kt(t._searchMarker,n.index,l.getLength()),h=new S(y(o,A(i.store,o)),a,a&&a.lastId,h,h&&h.id,t,null,l),h.integrate(e,0),n.right=h,n.index=u,n.forward(),$r(e,t,n,c)},_s=(e,t,n,s,r)=>{const i=e.doc,o=i.clientID;Br(n,r);const c=Fr(e,t,n,r);t:for(;n.right!==null&&(s>0||c.size>0&&(n.right.deleted||n.right.content.constructor===T));){if(!n.right.deleted)switch(n.right.content.constructor){case T:{const{key:l,value:a}=n.right.content,h=r[l];if(h!==void 0){if(nt(h,a))c.delete(l);else{if(s===0)break t;c.set(l,a)}n.right.delete(e)}else n.currentAttributes.set(l,a);break}default:s<n.right.length&&v(e,y(n.right.id.client,n.right.id.clock+s)),s-=n.right.length;break}n.forward()}if(s>0){let l="";for(;s>0;s--)l+=`
4
+ `;n.right=new S(y(o,A(i.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new G(l)),n.right.integrate(e,0),n.forward()}$r(e,t,n,c)},Vr=(e,t,n,s,r)=>{let i=t;const o=R();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===T){const a=i.content;o.set(a.key,a)}i=i.right}let c=0,l=!1;for(;t!==i;){if(n===t&&(l=!0),!t.deleted){const a=t.content;if(a.constructor===T){const{key:h,value:u}=a,d=s.get(h)??null;(o.get(h)!==a||d===u)&&(t.delete(e),c++,!l&&(r.get(h)??null)===u&&d!==u&&(d===null?r.delete(h):r.set(h,d))),!l&&!t.deleted&&Bt(r,a)}}t=t.right}return c},sl=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===T){const s=t.content.key;n.has(s)?t.delete(e):n.add(s)}t=t.left}},rl=e=>{let t=0;return _(e.doc,n=>{let s=e._start,r=e._start,i=R();const o=en(i);for(;r;)r.deleted===!1&&(r.content.constructor===T?Bt(o,r.content):(t+=Vr(n,s,r,i,o),i=en(o),s=r)),r=r.right}),t},il=e=>{const t=new Set,n=e.doc;for(const[s,r]of e.afterState.entries()){const i=e.beforeState.get(s)||0;r!==i&&Cr(e,n.store.clients.get(s),i,r,o=>{!o.deleted&&o.content.constructor===T&&o.constructor!==B&&t.add(o.parent)})}_(n,s=>{Ot(e,e.deleteSet,r=>{if(r instanceof B||!r.parent._hasFormatting||t.has(r.parent))return;const i=r.parent;r.content.constructor===T?t.add(i):sl(s,r)});for(const r of t)rl(r)})},Ss=(e,t,n)=>{const s=n,r=en(t.currentAttributes),i=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case tt:case yt:case G:n<t.right.length&&v(e,y(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}i&&Vr(e,i,t.right,r,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&Kt(o._searchMarker,t.index,-s+n),t};class ol extends Fe{constructor(t,n,s){super(t,n),this.childListChanged=!1,this.keysChanged=new Set,s.forEach(r=>{r===null?this.childListChanged=!0:this.keysChanged.add(r)})}get changes(){if(this._changes===null){const t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){const t=this.target.doc,n=[];_(t,s=>{const r=new Map,i=new Map;let o=this.target._start,c=null;const l={};let a="",h=0,u=0;const d=()=>{if(c!==null){let f=null;switch(c){case"delete":u>0&&(f={delete:u}),u=0;break;case"insert":(typeof a=="object"||a.length>0)&&(f={insert:a},r.size>0&&(f.attributes={},r.forEach((g,p)=>{g!==null&&(f.attributes[p]=g)}))),a="";break;case"retain":h>0&&(f={retain:h},io(l)||(f.attributes=eo({},l))),h=0;break}f&&n.push(f),c=null}};for(;o!==null;){switch(o.content.constructor){case tt:case yt:this.adds(o)?this.deletes(o)||(d(),c="insert",a=o.content.getContent()[0],d()):this.deletes(o)?(c!=="delete"&&(d(),c="delete"),u+=1):o.deleted||(c!=="retain"&&(d(),c="retain"),h+=1);break;case G:this.adds(o)?this.deletes(o)||(c!=="insert"&&(d(),c="insert"),a+=o.content.str):this.deletes(o)?(c!=="delete"&&(d(),c="delete"),u+=o.length):o.deleted||(c!=="retain"&&(d(),c="retain"),h+=o.length);break;case T:{const{key:f,value:g}=o.content;if(this.adds(o)){if(!this.deletes(o)){const p=r.get(f)??null;nt(p,g)?g!==null&&o.delete(s):(c==="retain"&&d(),nt(g,i.get(f)??null)?delete l[f]:l[f]=g)}}else if(this.deletes(o)){i.set(f,g);const p=r.get(f)??null;nt(p,g)||(c==="retain"&&d(),l[f]=p)}else if(!o.deleted){i.set(f,g);const p=l[f];p!==void 0&&(nt(p,g)?p!==null&&o.delete(s):(c==="retain"&&d(),g===null?delete l[f]:l[f]=g))}o.deleted||(c==="insert"&&d(),Bt(r,o.content));break}}o=o.right}for(d();n.length>0;){const f=n[n.length-1];if(f.retain!==void 0&&f.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class Ut extends I{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??M(),this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach(s=>s())}catch(s){console.error(s)}this._pending=null}_copy(){return new Ut}clone(){const t=new Ut;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const s=new ol(this,t,n);je(this,t,s),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??M();let t="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===G&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){this.doc!==null?_(this.doc,s=>{const r=new un(null,this._start,0,new Map);for(let i=0;i<t.length;i++){const o=t[i];if(o.insert!==void 0){const c=!n&&typeof o.insert=="string"&&i===t.length-1&&r.right===null&&o.insert.slice(-1)===`
5
+ `?o.insert.slice(0,-1):o.insert;(typeof c!="string"||c.length>0)&&Xe(s,this,r,c,o.attributes||{})}else o.retain!==void 0?_s(s,this,r,o.retain,o.attributes||{}):o.delete!==void 0&&Ss(s,r,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,s){this.doc??M();const r=[],i=new Map,o=this.doc;let c="",l=this._start;function a(){if(c.length>0){const u={};let d=!1;i.forEach((g,p)=>{d=!0,u[p]=g});const f={insert:c};d&&(f.attributes=u),r.push(f),c=""}}const h=()=>{for(;l!==null;){if(kt(l,t)||n!==void 0&&kt(l,n))switch(l.content.constructor){case G:{const u=i.get("ychange");t!==void 0&&!kt(l,t)?(u===void 0||u.user!==l.id.client||u.type!=="removed")&&(a(),i.set("ychange",s?s("removed",l.id):{type:"removed"})):n!==void 0&&!kt(l,n)?(u===void 0||u.user!==l.id.client||u.type!=="added")&&(a(),i.set("ychange",s?s("added",l.id):{type:"added"})):u!==void 0&&(a(),i.delete("ychange")),c+=l.content.str;break}case tt:case yt:{a();const u={insert:l.content.getContent()[0]};if(i.size>0){const d={};u.attributes=d,i.forEach((f,g)=>{d[g]=f})}r.push(u);break}case T:kt(l,t)&&(a(),Bt(i,l.content));break}l=l.right}a()};return t||n?_(o,u=>{t&&an(u,t),n&&an(u,n),h()},"cleanup"):h(),r}insert(t,n,s){if(n.length<=0)return;const r=this.doc;r!==null?_(r,i=>{const o=oe(i,this,t,!s);s||(s={},o.currentAttributes.forEach((c,l)=>{s[l]=c})),Xe(i,this,o,n,s)}):this._pending.push(()=>this.insert(t,n,s))}insertEmbed(t,n,s){const r=this.doc;r!==null?_(r,i=>{const o=oe(i,this,t,!s);Xe(i,this,o,n,s||{})}):this._pending.push(()=>this.insertEmbed(t,n,s||{}))}delete(t,n){if(n===0)return;const s=this.doc;s!==null?_(s,r=>{Ss(r,oe(r,this,t,!0),n)}):this._pending.push(()=>this.delete(t,n))}format(t,n,s){if(n===0)return;const r=this.doc;r!==null?_(r,i=>{const o=oe(i,this,t,!1);o.right!==null&&_s(i,this,o,n,s)}):this._pending.push(()=>this.format(t,n,s))}removeAttribute(t){this.doc!==null?_(this.doc,n=>{_e(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?_(this.doc,s=>{Vn(s,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return jn(this,t)}getAttributes(){return vr(this)}_write(t){t.writeTypeRef(Al)}}const cl=e=>new Ut;class qe{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??M()}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(n)))do if(n=t.content.type,!t.deleted&&(n.constructor===q||n.constructor===dt)&&n._start!==null)t=n._start;else for(;t!==null;){const s=t.next;if(s!==null){t=s;break}else t.parent===this._root?t=null:t=t.parent._item}while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class dt extends I{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new dt}clone(){const t=new dt;return t.insert(0,this.toArray().map(n=>n instanceof I?n.clone():n)),t}get length(){return this.doc??M(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new qe(this,t)}querySelector(t){t=t.toUpperCase();const s=new qe(this,r=>r.nodeName&&r.nodeName.toUpperCase()===t).next();return s.done?null:s.value}querySelectorAll(t){return t=t.toUpperCase(),X(new qe(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){je(this,t,new hl(this,n,t))}toString(){return Lr(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},s){const r=t.createDocumentFragment();return s!==void 0&&s._createAssociation(r,this),Wt(this,i=>{r.insertBefore(i.toDOM(t,n,s),null)}),r}insert(t,n){this.doc!==null?_(this.doc,s=>{Mr(s,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)_(this.doc,s=>{const r=t&&t instanceof I?t._item:t;ke(s,this,r,n)});else{const s=this._prelimContent,r=t===null?0:s.findIndex(i=>i===t)+1;if(r===0&&t!==null)throw Y("Reference item not found");s.splice(r,0,...n)}}delete(t,n=1){this.doc!==null?_(this.doc,s=>{Ur(s,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return Ir(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Or(this,t)}slice(t=0,n=this.length){return xr(this,t,n)}forEach(t){Wt(this,t)}_write(t){t.writeTypeRef(xl)}}const ll=e=>new dt;class q extends dt{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach((s,r)=>{this.setAttribute(r,s)}),this._prelimAttrs=null}_copy(){return new q(this.nodeName)}clone(){const t=new q(this.nodeName),n=this.getAttributes();return so(n,(s,r)=>{t.setAttribute(r,s)}),t.insert(0,this.toArray().map(s=>s instanceof I?s.clone():s)),t}toString(){const t=this.getAttributes(),n=[],s=[];for(const c in t)s.push(c);s.sort();const r=s.length;for(let c=0;c<r;c++){const l=s[c];n.push(l+'="'+t[l]+'"')}const i=this.nodeName.toLocaleLowerCase(),o=n.length>0?" "+n.join(" "):"";return`<${i}${o}>${super.toString()}</${i}>`}removeAttribute(t){this.doc!==null?_(this.doc,n=>{_e(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?_(this.doc,s=>{Vn(s,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return jn(this,t)}hasAttribute(t){return Rr(this,t)}getAttributes(t){return t?Qc(this,t):vr(this)}toDOM(t=document,n={},s){const r=t.createElement(this.nodeName),i=this.getAttributes();for(const o in i){const c=i[o];typeof c=="string"&&r.setAttribute(o,c)}return Wt(this,o=>{r.appendChild(o.toDOM(t,n,s))}),s!==void 0&&s._createAssociation(r,this),r}_write(t){t.writeTypeRef(Tl),t.writeKey(this.nodeName)}}const al=e=>new q(e.readKey());class hl extends Fe{constructor(t,n,s){super(t,s),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(r=>{r===null?this.childListChanged=!0:this.attributesChanged.add(r)})}}class Se extends Mt{constructor(t){super(),this.hookName=t}_copy(){return new Se(this.hookName)}clone(){const t=new Se(this.hookName);return this.forEach((n,s)=>{t.set(s,n)}),t}toDOM(t=document,n={},s){const r=n[this.hookName];let i;return r!==void 0?i=r.createDom(this):i=document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),s!==void 0&&s._createAssociation(i,this),i}_write(t){t.writeTypeRef(Il),t.writeKey(this.hookName)}}const ul=e=>new Se(e.readKey());class Q extends Ut{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new Q}clone(){const t=new Q;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,s){const r=t.createTextNode(this.toString());return s!==void 0&&s._createAssociation(r,this),r}toString(){return this.toDelta().map(t=>{const n=[];for(const r in t.attributes){const i=[];for(const o in t.attributes[r])i.push({key:o,value:t.attributes[r][o]});i.sort((o,c)=>o.key<c.key?-1:1),n.push({nodeName:r,attrs:i})}n.sort((r,i)=>r.nodeName<i.nodeName?-1:1);let s="";for(let r=0;r<n.length;r++){const i=n[r];s+=`<${i.nodeName}`;for(let o=0;o<i.attrs.length;o++){const c=i.attrs[o];s+=` ${c.key}="${c.value}"`}s+=">"}s+=t.insert;for(let r=n.length-1;r>=0;r--)s+=`</${n[r].nodeName}>`;return s}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(Ll)}}const dl=e=>new Q;class Hn{constructor(t,n){this.id=t,this.length=n}get deleted(){throw j()}mergeWith(t){return!1}write(t,n,s){throw j()}integrate(t,n){throw j()}}const fl=0;class B extends Hn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){n>0&&(this.id.clock+=n,this.length-=n),Sr(t.doc.store,this)}write(t,n){t.writeInfo(fl),t.writeLen(this.length-n)}getMissing(t,n){return null}}class ee{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new ee(this.content)}splice(t){throw j()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}const gl=e=>new ee(e.readBuf());class Xt{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Xt(this.len)}splice(t){const n=new Xt(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){Jt(t.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(t){}gc(t){}write(t,n){t.writeLen(this.len-n)}getRef(){return 1}}const pl=e=>new Xt(e.readLen()),jr=(e,t)=>new mt({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class ne{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const n={};this.opts=n,t.gc||(n.gc=!1),t.autoLoad&&(n.autoLoad=!0),t.meta!==null&&(n.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new ne(jr(this.doc.guid,this.opts))}splice(t){throw j()}mergeWith(t){return!1}integrate(t,n){this.doc._item=n,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,n){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}const wl=e=>new ne(jr(e.readString(),e.readAny()));class yt{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new yt(this.embed)}splice(t){throw j()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}const ml=e=>new yt(e.readJSON());class T{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new T(this.key,this.value)}splice(t){throw j()}mergeWith(t){return!1}integrate(t,n){const s=n.parent;s._searchMarker=null,s._hasFormatting=!0}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}const yl=e=>new T(e.readKey(),e.readJSON());class Ce{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Ce(this.arr)}splice(t){const n=new Ce(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const s=this.arr.length;t.writeLen(s-n);for(let r=n;r<s;r++){const i=this.arr[r];t.writeString(i===void 0?"undefined":JSON.stringify(i))}}getRef(){return 2}}const bl=e=>{const t=e.readLen(),n=[];for(let s=0;s<t;s++){const r=e.readString();r==="undefined"?n.push(void 0):n.push(JSON.parse(r))}return new Ce(n)},kl=pe("node_env")==="development";class ft{constructor(t){this.arr=t,kl&&Fs(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ft(this.arr)}splice(t){const n=new ft(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const s=this.arr.length;t.writeLen(s-n);for(let r=n;r<s;r++){const i=this.arr[r];t.writeAny(i)}}getRef(){return 8}}const _l=e=>{const t=e.readLen(),n=[];for(let s=0;s<t;s++)n.push(e.readAny());return new ft(n)};class G{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new G(this.str)}splice(t){const n=new G(this.str.slice(t));this.str=this.str.slice(0,t);const s=this.str.charCodeAt(t-1);return s>=55296&&s<=56319&&(this.str=this.str.slice(0,t-1)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(t){return this.str+=t.str,!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}}const Sl=e=>new G(e.readString()),Cl=[tl,nl,cl,al,ll,ul,dl],El=0,Dl=1,Al=2,Tl=3,xl=4,Il=5,Ll=6;class tt{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new tt(this.type._copy())}splice(t){throw j()}mergeWith(t){return!1}integrate(t,n){this.type._integrate(t.doc,n)}delete(t){let n=this.type._start;for(;n!==null;)n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t),n=n.right;this.type._map.forEach(s=>{s.deleted?s.id.clock<(t.beforeState.get(s.id.client)||0)&&t._mergeStructs.push(s):s.delete(t)}),t.changed.delete(this.type)}gc(t){let n=this.type._start;for(;n!==null;)n.gc(t,!0),n=n.right;this.type._start=null,this.type._map.forEach(s=>{for(;s!==null;)s.gc(t,!0),s=s.left}),this.type._map=new Map}write(t,n){this.type._write(t)}getRef(){return 7}}const Ol=e=>new tt(Cl[e.readTypeRef()](e)),Nl=(e,t)=>{let n=t,s=0,r;do s>0&&(n=y(n.client,n.clock+s)),r=he(e,n),s=n.clock-r.id.clock,n=r.redone;while(n!==null&&r instanceof S);return{item:r,diff:s}},zn=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Ee=(e,t,n)=>{const{client:s,clock:r}=t.id,i=new S(y(s,r+n),t,y(s,r+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),t.redone!==null&&(i.redone=y(t.redone.client,t.redone.clock+n)),t.right=i,i.right!==null&&(i.right.left=i),e._mergeStructs.push(i),i.parentSub!==null&&i.right===null&&i.parent._map.set(i.parentSub,i),t.length=n,i},Cs=(e,t)=>wn(e,n=>Zt(n.deletions,t)),Hr=(e,t,n,s,r,i)=>{const o=e.doc,c=o.store,l=o.clientID,a=t.redone;if(a!==null)return v(e,a);let h=t.parent._item,u=null,d;if(h!==null&&h.deleted===!0){if(h.redone===null&&(!n.has(h)||Hr(e,h,n,s,r,i)===null))return null;for(;h.redone!==null;)h=v(e,h.redone)}const f=h===null?t.parent:h.content.type;if(t.parentSub===null){for(u=t.left,d=t;u!==null;){let k=u;for(;k!==null&&k.parent._item!==h;)k=k.redone===null?null:v(e,k.redone);if(k!==null&&k.parent._item===h){u=k;break}u=u.left}for(;d!==null;){let k=d;for(;k!==null&&k.parent._item!==h;)k=k.redone===null?null:v(e,k.redone);if(k!==null&&k.parent._item===h){d=k;break}d=d.right}}else{if(d=null,t.right&&!r){for(u=t;u!==null&&u.right!==null&&(u.right.redone||Zt(s,u.right.id)||Cs(i.undoStack,u.right.id)||Cs(i.redoStack,u.right.id));)for(u=u.right;u.redone;)u=v(e,u.redone);if(u&&u.right!==null)return null}else u=f._map.get(t.parentSub)||null;u!==null&&u.parent._item!==h&&(u=f._map.get(t.parentSub)||null)}const g=A(c,l),p=y(l,g),b=new S(p,u,u&&u.lastId,d,d&&d.id,f,t.parentSub,t.content.copy());return t.redone=p,zn(b,!0),b.integrate(e,0),b};class S extends Hn{constructor(t,n,s,r,i,o,c,l){super(t,l.getLength()),this.origin=s,this.left=n,this.right=r,this.rightOrigin=i,this.parent=o,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?Qn:0}set marker(t){(this.info&Ye)>0!==t&&(this.info^=Ye)}get marker(){return(this.info&Ye)>0}get keep(){return(this.info&qn)>0}set keep(t){this.keep!==t&&(this.info^=qn)}get countable(){return(this.info&Qn)>0}get deleted(){return(this.info&ze)>0}set deleted(t){this.deleted!==t&&(this.info^=ze)}markDeleted(){this.info|=ze}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=A(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=A(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Dt&&this.id.client!==this.parent.client&&this.parent.clock>=A(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=gs(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=v(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===B||this.right&&this.right.constructor===B)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===S?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===S&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Dt){const s=he(n,this.parent);s.constructor===B?this.parent=null:this.parent=s.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=gs(t,t.doc.store,y(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let s=this.left,r;if(s!==null)r=s.right;else if(this.parentSub!==null)for(r=this.parent._map.get(this.parentSub)||null;r!==null&&r.left!==null;)r=r.left;else r=this.parent._start;const i=new Set,o=new Set;for(;r!==null&&r!==this.right;){if(o.add(r),i.add(r),re(this.origin,r.origin)){if(r.id.client<this.id.client)s=r,i.clear();else if(re(this.rightOrigin,r.rightOrigin))break}else if(r.origin!==null&&o.has(he(t.doc.store,r.origin)))i.has(he(t.doc.store,r.origin))||(s=r,i.clear());else break;r=r.right}this.left=s}if(this.left!==null){const s=this.left.right;this.right=s,this.left.right=this}else{let s;if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start,this.parent._start=this;this.right=s}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Sr(t.doc.store,this),this.content.integrate(t,this),ws(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new B(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;t!==null&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;t!==null&&t.deleted;)t=t.left;return t}get lastId(){return this.length===1?this.id:y(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&re(t.origin,this.lastId)&&this.right===t&&re(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const n=this.parent._searchMarker;return n&&n.forEach(s=>{s.p===t&&(s.p=this,!this.deleted&&this.countable&&(s.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),Jt(t.deleteSet,this.id.client,this.id.clock,this.length),ws(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw V();this.content.gc(t),n?Uc(t,this,new B(this.id,this.length)):this.content=new Xt(this.length)}write(t,n){const s=n>0?y(this.id.client,this.id.clock+n-1):this.origin,r=this.rightOrigin,i=this.parentSub,o=this.content.getRef()&Te|(s===null?0:$)|(r===null?0:W)|(i===null?0:jt);if(t.writeInfo(o),s!==null&&t.writeLeftID(s),r!==null&&t.writeRightID(r),s===null&&r===null){const c=this.parent;if(c._item!==void 0){const l=c._item;if(l===null){const a=Nc(c);t.writeParentInfo(!0),t.writeString(a)}else t.writeParentInfo(!1),t.writeLeftID(l.id)}else c.constructor===String?(t.writeParentInfo(!0),t.writeString(c)):c.constructor===Dt?(t.writeParentInfo(!1),t.writeLeftID(c)):V();i!==null&&t.writeString(i)}this.content.write(t,n)}}const zr=(e,t)=>Ml[t&Te](e),Ml=[()=>{V()},pl,bl,gl,Sl,ml,yl,Ol,_l,wl,()=>{V()}],Ul=10;class F extends Hn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){V()}write(t,n){t.writeInfo(Ul),w(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const Yr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Pr="__ $YJS$ __";Yr[Pr]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Yr[Pr]=!0;const Gr=new Map;class vl{constructor(t){this.room=t,this.onmessage=null,this._onChange=n=>n.key===t&&this.onmessage!==null&&this.onmessage({data:_o(n.newValue||"")}),Qi(this._onChange)}postMessage(t){$s.setItem(this.room,ko(po(t)))}close(){Zi(this._onChange)}}const Rl=typeof BroadcastChannel>"u"?vl:BroadcastChannel,Yn=e=>J(Gr,e,()=>{const t=rt(),n=new Rl(e);return n.onmessage=s=>t.forEach(r=>r(s.data,"broadcastchannel")),{bc:n,subs:t}}),$l=(e,t)=>(Yn(e).subs.add(t),t),Bl=(e,t)=>{const n=Yn(e),s=n.subs.delete(t);return s&&n.subs.size===0&&(n.bc.close(),Gr.delete(e)),s},_t=(e,t,n=null)=>{const s=Yn(e);s.bc.postMessage(t),s.subs.forEach(r=>r(t,n))},Jr=0,Pn=1,Kr=2,dn=(e,t)=>{w(e,Jr);const n=Lc(t);E(e,n)},Wr=(e,t,n)=>{w(e,Pn),E(e,Ac(t,n))},Fl=(e,t,n)=>Wr(t,n,O(e)),Xr=(e,t,n,s)=>{try{Cc(t,O(e),n)}catch(r){s?.(r),console.error("Caught error while handling a Yjs update",r)}},Vl=(e,t)=>{w(e,Kr),E(e,t)},jl=Xr,Hl=(e,t,n,s,r)=>{const i=m(e);switch(i){case Jr:Fl(e,t,n);break;case Pn:Xr(e,n,s,r);break;case Kr:jl(e,n,s,r);break;default:throw new Error("Unknown message type")}return i},zl=0,Yl=(e,t,n)=>{m(e)===zl&&n(t,st(e))},Qe=3e4;class Pl extends wi{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const n=it();this.getLocalState()!==null&&Qe/2<=n-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const s=[];this.meta.forEach((r,i)=>{i!==this.clientID&&Qe<=n-r.lastUpdated&&this.states.has(i)&&s.push(i)}),s.length>0&&Gn(this,s,"timeout")},H(Qe/10)),t.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(t){const n=this.clientID,s=this.meta.get(n),r=s===void 0?0:s.clock+1,i=this.states.get(n);t===null?this.states.delete(n):this.states.set(n,t),this.meta.set(n,{clock:r,lastUpdated:it()});const o=[],c=[],l=[],a=[];t===null?a.push(n):i==null?t!=null&&o.push(n):(c.push(n),Ct(i,t)||l.push(n)),(o.length>0||l.length>0||a.length>0)&&this.emit("change",[{added:o,updated:l,removed:a},"local"]),this.emit("update",[{added:o,updated:c,removed:a},"local"])}setLocalStateField(t,n){const s=this.getLocalState();s!==null&&this.setLocalState({...s,[t]:n})}getStates(){return this.states}}const Gn=(e,t,n)=>{const s=[];for(let r=0;r<t.length;r++){const i=t[r];if(e.states.has(i)){if(e.states.delete(i),i===e.clientID){const o=e.meta.get(i);e.meta.set(i,{clock:o.clock+1,lastUpdated:it()})}s.push(i)}}s.length>0&&(e.emit("change",[{added:[],updated:[],removed:s},n]),e.emit("update",[{added:[],updated:[],removed:s},n]))},Vt=(e,t,n=e.states)=>{const s=t.length,r=N();w(r,s);for(let i=0;i<s;i++){const o=t[i],c=n.get(o)||null,l=e.meta.get(o).clock;w(r,o),w(r,l),ht(r,JSON.stringify(c))}return C(r)},Gl=(e,t,n)=>{const s=ct(t),r=it(),i=[],o=[],c=[],l=[],a=m(s);for(let h=0;h<a;h++){const u=m(s);let d=m(s);const f=JSON.parse(st(s)),g=e.meta.get(u),p=e.states.get(u),b=g===void 0?0:g.clock;(b<d||b===d&&f===null&&e.states.has(u))&&(f===null?u===e.clientID&&e.getLocalState()!=null?d++:e.states.delete(u):e.states.set(u,f),e.meta.set(u,{clock:d,lastUpdated:r}),g===void 0&&f!==null?i.push(u):g!==void 0&&f===null?l.push(u):f!==null&&(Ct(f,p)||c.push(u),o.push(u)))}(i.length>0||c.length>0||l.length>0)&&e.emit("change",[{added:i,updated:c,removed:l},n]),(i.length>0||o.length>0||l.length>0)&&e.emit("update",[{added:i,updated:o,removed:l},n])},Jl=e=>ro(e,(t,n)=>`${encodeURIComponent(n)}=${encodeURIComponent(t)}`).join("&"),lt=0,qr=3,Tt=1,Kl=2,se=[];se[lt]=(e,t,n,s,r)=>{w(e,lt);const i=Hl(t,e,n.doc,n);s&&i===Pn&&!n.synced&&(n.synced=!0)};se[qr]=(e,t,n,s,r)=>{w(e,Tt),E(e,Vt(n.awareness,Array.from(n.awareness.getStates().keys())))};se[Tt]=(e,t,n,s,r)=>{Gl(n.awareness,O(t),n)};se[Kl]=(e,t,n,s,r)=>{Yl(t,n.doc,(i,o)=>Wl(n,o))};const Es=3e4,Wl=(e,t)=>console.warn(`Permission denied to access ${e.url}.
6
+ ${t}`),Qr=(e,t,n)=>{const s=ct(t),r=N(),i=m(s),o=e.messageHandlers[i];return o?o(r,s,e,n,i):console.error("Unable to compute message"),r},fn=(e,t,n)=>{t===e.ws&&(e.emit("connection-close",[n,e]),e.ws=null,t.close(),e.wsconnecting=!1,e.wsconnected?(e.wsconnected=!1,e.synced=!1,Gn(e.awareness,Array.from(e.awareness.getStates().keys()).filter(s=>s!==e.doc.clientID),e),e.emit("status",[{status:"disconnected"}])):e.wsUnsuccessfulReconnects++,setTimeout(Zr,yn(mi(2,e.wsUnsuccessfulReconnects)*100,e.maxBackoffTime),e))},Zr=e=>{if(e.shouldConnect&&e.ws===null){const t=new e._WS(e.url,e.protocols);t.binaryType="arraybuffer",e.ws=t,e.wsconnecting=!0,e.wsconnected=!1,e.synced=!1,t.onmessage=n=>{e.wsLastMessageReceived=it();const s=Qr(e,new Uint8Array(n.data),!0);bn(s)>1&&t.send(C(s))},t.onerror=n=>{e.emit("connection-error",[n,e])},t.onclose=n=>{fn(e,t,n)},t.onopen=()=>{e.wsLastMessageReceived=it(),e.wsconnecting=!1,e.wsconnected=!0,e.wsUnsuccessfulReconnects=0,e.emit("status",[{status:"connected"}]);const n=N();if(w(n,lt),dn(n,e.doc),t.send(C(n)),e.awareness.getLocalState()!==null){const s=N();w(s,Tt),E(s,Vt(e.awareness,[e.doc.clientID])),t.send(C(s))}},e.emit("status",[{status:"connecting"}])}},Ze=(e,t)=>{const n=e.ws;e.wsconnected&&n&&n.readyState===n.OPEN&&n.send(t),e.bcconnected&&_t(e.bcChannel,t,e)};class Xl extends mn{constructor(t,n,s,{connect:r=!0,awareness:i=new Pl(s),params:o={},protocols:c=[],WebSocketPolyfill:l=WebSocket,resyncInterval:a=-1,maxBackoffTime:h=2500,disableBc:u=!1}={}){for(super();t[t.length-1]==="/";)t=t.slice(0,t.length-1);this.serverUrl=t,this.bcChannel=t+"/"+n,this.maxBackoffTime=h,this.params=o,this.protocols=c,this.roomname=n,this.doc=s,this._WS=l,this.awareness=i,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=u,this.wsUnsuccessfulReconnects=0,this.messageHandlers=se.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=r,this._resyncInterval=0,a>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const d=N();w(d,lt),dn(d,s),this.ws.send(C(d))}},a)),this._bcSubscriber=(d,f)=>{if(f!==this){const g=Qr(this,new Uint8Array(d),!1);bn(g)>1&&_t(this.bcChannel,C(g),this)}},this._updateHandler=(d,f)=>{if(f!==this){const g=N();w(g,lt),Vl(g,d),Ze(this,C(g))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:d,updated:f,removed:g},p)=>{const b=d.concat(f).concat(g),k=N();w(k,Tt),E(k,Vt(i,b)),Ze(this,C(k))},this._exitHandler=()=>{Gn(this.awareness,[s.clientID],"app closed")},ot&&typeof process<"u"&&process.on("exit",this._exitHandler),i.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Es<it()-this.wsLastMessageReceived&&fn(this,this.ws,null)},Es/10),r&&this.connect()}get url(){const t=Jl(this.params);return this.serverUrl+"/"+this.roomname+(t.length===0?"":"?"+t)}get synced(){return this._synced}set synced(t){this._synced!==t&&(this._synced=t,this.emit("synced",[t]),this.emit("sync",[t]))}destroy(){this._resyncInterval!==0&&clearInterval(this._resyncInterval),clearInterval(this._checkInterval),this.disconnect(),ot&&typeof process<"u"&&process.off("exit",this._exitHandler),this.awareness.off("update",this._awarenessUpdateHandler),this.doc.off("update",this._updateHandler),super.destroy()}connectBc(){if(this.disableBc)return;this.bcconnected||($l(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const t=N();w(t,lt),dn(t,this.doc),_t(this.bcChannel,C(t),this);const n=N();w(n,lt),Wr(n,this.doc),_t(this.bcChannel,C(n),this);const s=N();w(s,qr),_t(this.bcChannel,C(s),this);const r=N();w(r,Tt),E(r,Vt(this.awareness,[this.doc.clientID])),_t(this.bcChannel,C(r),this)}disconnectBc(){const t=N();w(t,Tt),E(t,Vt(this.awareness,[this.doc.clientID],new Map)),Ze(this,C(t)),this.bcconnected&&(Bl(this.bcChannel,this._bcSubscriber),this.bcconnected=!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&fn(this,this.ws,null)}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(Zr(this),this.connectBc())}}const ti="data-collab-blocked",ei=/^[a-z][a-z0-9-]*$/,ql=/^[a-z_:][-a-z0-9_:.]*$/i,Ql=new Set(["script","style","iframe","frame","frameset","object","embed","applet","link","meta","base","noscript","template","portal"]),Zl=new Set(["href","src","xlink:href","action","formaction","data","poster","background","cite","codebase","manifest","ping","longdesc","usemap","lowsrc","dynsrc"]),ta=/^data:image\/(?:png|gif|jpe?g|webp|avif|bmp|x-icon);/,ea=new RegExp("[\\u0000-\\u0020\\u007f-\\u009f\\u00ad\\u200b-\\u200f\\u2028\\u2029\\ufeff]","g");function na(e){const t=e.replace(ea,"").toLowerCase();return/^(?:javascript|vbscript|livescript|mocha):/.test(t)?!1:t.startsWith("data:")?ta.test(t):!0}function sa(e){if(!("data-editora-embed"in e))return!1;const t=e.src?.trim();if(!t||/\s/.test(t))return!1;try{const n=new URL(t);return(n.protocol==="https:"||n.protocol==="http:")&&n.hostname.length>0}catch{return!1}}function ra(e,t){const n=e.toLowerCase();return ei.test(n)?n==="iframe"?!sa(t):Ql.has(n):!0}function ni(e,t){if(!ql.test(e))return!1;const n=e.toLowerCase();return n.startsWith("on")||n==="srcdoc"?!1:Zl.has(n)?na(String(t)):!0}function ia(e,t){const n=e.createElement("span");return n.setAttribute(ti,ei.test(t.toLowerCase())?t.toLowerCase().slice(0,32):"invalid"),n.hidden=!0,n}function De(e){return e.nodeType===Node.ELEMENT_NODE&&e.hasAttribute(ti)}function oa(e){return e instanceof Q||e instanceof q}function Jn(e){return e.toArray().filter(oa)}function ca(e,t){if(e===t)return null;let n=0;const s=Math.min(e.length,t.length);for(;n<s&&e[n]===t[n];)n++;let r=0;const i=Math.min(e.length-n,t.length-n);for(;r<i&&e[e.length-1-r]===t[t.length-1-r];)r++;return{start:n,deleteCount:e.length-n-r,insertText:t.slice(n,t.length-r)}}function la(e){const t=new q(e.tagName.toLowerCase());for(const s of Array.from(e.attributes))t.setAttribute(s.name,s.value);const n=si(e.childNodes);return n.length&&t.insert(0,n),t}function si(e){const t=[];for(const n of Array.from(e))n.nodeType===Node.TEXT_NODE?t.push(new Q(n.textContent??"")):n.nodeType===Node.ELEMENT_NODE&&t.push(la(n));return t}function ri(e){return ra(e.nodeName,e.getAttributes())}function aa(e,t){if(ri(e))return ia(t,e.nodeName);const n=t.createElement(e.nodeName);for(const[s,r]of Object.entries(e.getAttributes()))ni(s,r)&&n.setAttribute(s,r);for(const s of Jn(e))n.appendChild(ii(s,t));return n}function ii(e,t){return e instanceof Q?t.createTextNode(e.toString()):aa(e,t)}function oi(e,t){return ri(t)?De(e):!De(e)&&e.tagName.toLowerCase()===t.nodeName.toLowerCase()}function gn(e,t){const n=Array.from(t.childNodes).filter(o=>o.nodeType===Node.TEXT_NODE||o.nodeType===Node.ELEMENT_NODE),s=Jn(e),r=Math.min(n.length,s.length);let i=0;for(;i<r;i++){const o=n[i],c=s[i];if(o.nodeType===Node.TEXT_NODE){if(c instanceof Q){const l=ca(c.toString(),o.textContent??"");l&&(l.deleteCount>0&&c.delete(l.start,l.deleteCount),l.insertText&&c.insert(l.start,l.insertText));continue}break}if(c instanceof q&&oi(o,c)){if(De(o))continue;ha(c,o),gn(c,o);continue}break}if(i<s.length&&e.delete(i,s.length-i),i<n.length){const o=si(n.slice(i));o.length&&e.insert(i,o)}}function ha(e,t){const n=e.getAttributes(),s=new Set(Array.from(t.attributes).map(r=>r.name));for(const r of Object.keys(n))s.has(r)||e.removeAttribute(r);for(const r of Array.from(t.attributes))n[r.name]!==r.value&&e.setAttribute(r.name,r.value)}function ci(e,t,n){const s=Jn(t),r=Array.from(e.childNodes).filter(c=>c.nodeType===Node.TEXT_NODE||c.nodeType===Node.ELEMENT_NODE),i=Math.min(s.length,r.length);let o=0;for(;o<i;o++){const c=s[o],l=r[o];if(c instanceof Q){if(l.nodeType===Node.TEXT_NODE){const a=c.toString();l.textContent!==a&&(l.textContent=a);continue}break}if(l.nodeType===Node.ELEMENT_NODE&&oi(l,c)){if(De(l))continue;ua(l,c),ci(l,c,n);continue}break}for(let c=r.length-1;c>=o;c--)e.removeChild(r[c]);for(let c=o;c<s.length;c++)e.appendChild(ii(s[c],n))}function ua(e,t){const n=t.getAttributes(),s=new Set(Array.from(e.attributes).map(r=>r.name));for(const r of s)r in n||e.removeAttribute(r);for(const[r,i]of Object.entries(n)){if(!ni(r,i)){e.removeAttribute(r);continue}e.getAttribute(r)!==i&&e.setAttribute(r,i)}}class da{constructor(t,n,s){this.root=t,this.doc=n,this.fragment=s,this.pending=!1,this.destroyed=!1,this.onFragmentChange=(r,i)=>{i.origin!==this&&this.applyRemoteToDom()},this.observer=new MutationObserver(()=>this.scheduleLocalSync()),this.fragment.length===0&&this.root.childNodes.length>0?this.doc.transact(()=>gn(this.fragment,this.root),this):this.applyRemoteToDom(),this.observer.observe(this.root,{childList:!0,characterData:!0,subtree:!0,attributes:!0}),this.fragment.observeDeep(this.onFragmentChange)}scheduleLocalSync(){this.pending||(this.pending=!0,queueMicrotask(()=>{this.pending=!1,!this.destroyed&&this.doc.transact(()=>gn(this.fragment,this.root),this)}))}applyRemoteToDom(){if(this.destroyed)return;const t=this.captureSelection();this.observer.disconnect();try{ci(this.root,this.fragment,this.root.ownerDocument),this.root.dispatchEvent(new Event("input",{bubbles:!0,composed:!0}))}finally{this.observer.observe(this.root,{childList:!0,characterData:!0,subtree:!0,attributes:!0})}t&&this.restoreSelection(t)}pathTo(t,n){if(!this.root.contains(t))return null;const s=[];let r=t;for(;r&&r!==this.root;){const i=r.parentNode;if(!i)return null;s.unshift(Array.prototype.indexOf.call(i.childNodes,r)),r=i}return{path:s,offset:n}}resolvePath(t){let n=this.root;for(const s of t){const r=n.childNodes[s];if(!r)return null;n=r}return n}captureSelection(){const t=this.root.ownerDocument.defaultView?.getSelection();if(!t||t.rangeCount===0||!t.anchorNode||!t.focusNode)return null;const n=this.pathTo(t.anchorNode,t.anchorOffset),s=this.pathTo(t.focusNode,t.focusOffset);return!n||!s?null:{anchor:n,focus:s}}restoreSelection(t){const n=this.root.ownerDocument.defaultView?.getSelection();if(!n)return;const s=this.resolvePath(t.anchor.path),r=this.resolvePath(t.focus.path);if(!(!s||!r))try{const i=Math.min(t.anchor.offset,(s.textContent??"").length),o=Math.min(t.focus.offset,(r.textContent??"").length);n.setBaseAndExtent(s,i,r,o)}catch{}}destroy(){this.destroyed=!0,this.observer.disconnect(),this.fragment.unobserveDeep(this.onFragmentChange)}}const Ds="editora-collaboration-cursor-styles";function fa(){if(typeof document>"u"||document.getElementById(Ds))return;const e=document.createElement("style");e.id=Ds,e.textContent=`
7
7
  .editora-collab-caret {
8
8
  position: fixed;
9
9
  width: 2px;
@@ -30,7 +30,7 @@ ${t}`),Xr=(e,t,n)=>{const s=ct(t),r=N(),i=m(s),o=e.messageHandlers[i];return o?o
30
30
  z-index: 2147482999;
31
31
  opacity: 0.25;
32
32
  }
33
- `,document.head.appendChild(e)}function Ds(e,t){let n=e;for(const s of t){const r=n.childNodes[s];if(!r)return null;n=r}return n}function As(e,t,n){if(!e.contains(t))return null;const s=[];let r=t;for(;r&&r!==e;){const i=r.parentNode;if(!i)return null;s.unshift(Array.prototype.indexOf.call(i.childNodes,r)),r=i}return{path:s,offset:n}}class Pl{constructor(t,n,s){this.root=t,this.awareness=n,this.user=s,this.caretElements=new Map,this.pendingBroadcast=!1,this.onSelectionChange=()=>this.scheduleBroadcast(),this.onAwarenessChange=()=>this.renderRemoteCursors(),this.onViewportChange=()=>this.renderRemoteCursors(),Xl(),this.awareness.setLocalStateField("user",this.user),document.addEventListener("selectionchange",this.onSelectionChange),this.awareness.on("change",this.onAwarenessChange),window.addEventListener("scroll",this.onViewportChange,!0),window.addEventListener("resize",this.onViewportChange)}scheduleBroadcast(){this.pendingBroadcast||(this.pendingBroadcast=!0,queueMicrotask(()=>{this.pendingBroadcast=!1,this.broadcastCursor()}))}broadcastCursor(){const t=window.getSelection();if(!t||t.rangeCount===0||!t.anchorNode||!t.focusNode){this.awareness.setLocalStateField("cursor",null);return}if(!this.root.contains(t.anchorNode)||!this.root.contains(t.focusNode)){this.awareness.setLocalStateField("cursor",null);return}const n=As(this.root,t.anchorNode,t.anchorOffset),s=As(this.root,t.focusNode,t.focusOffset);if(!n||!s)return;const r={anchorPath:n.path,anchorOffset:n.offset,focusPath:t.isCollapsed?void 0:s.path,focusOffset:t.isCollapsed?void 0:s.offset};this.awareness.setLocalStateField("cursor",r)}renderRemoteCursors(){const t=this.awareness.getStates(),n=new Set;t.forEach((s,r)=>{if(r!==this.awareness.clientID){if(!s.cursor||!s.user){this.removeCursor(r);return}n.add(r),this.renderCursor(r,s.user,s.cursor)}});for(const s of Array.from(this.caretElements.keys()))n.has(s)||this.removeCursor(s)}renderCursor(t,n,s){const r=Ds(this.root,s.anchorPath);if(!r){this.removeCursor(t);return}let i=this.caretElements.get(t);if(!i){const c=document.createElement("div");c.className="editora-collab-caret";const l=document.createElement("div");l.className="editora-collab-caret__label",c.appendChild(l);const h=document.createElement("div");h.className="editora-collab-selection",document.body.appendChild(h),document.body.appendChild(c),i={caret:c,selectionBox:h},this.caretElements.set(t,i)}const o=i.caret.firstElementChild;o.textContent=n.name,o.style.backgroundColor=n.color,i.caret.style.backgroundColor=n.color,i.selectionBox.style.backgroundColor=n.color;try{const c=document.createRange(),l=Math.min(s.anchorOffset,(r.textContent??"").length);c.setStart(r,l),c.setEnd(r,l);const h=c.getBoundingClientRect();if(i.caret.style.top=`${h.top}px`,i.caret.style.left=`${h.left}px`,i.caret.style.height=`${h.height||16}px`,s.focusPath){const a=Ds(this.root,s.focusPath);if(a){const u=Math.min(s.focusOffset??0,(a.textContent??"").length),d=document.createRange();d.setStart(r,l),d.setEnd(a,u);const f=d.getBoundingClientRect();i.selectionBox.style.display="block",i.selectionBox.style.top=`${f.top}px`,i.selectionBox.style.left=`${f.left}px`,i.selectionBox.style.width=`${f.width}px`,i.selectionBox.style.height=`${f.height}px`}}else i.selectionBox.style.display="none"}catch{this.removeCursor(t)}}removeCursor(t){const n=this.caretElements.get(t);n&&(n.caret.remove(),n.selectionBox.remove(),this.caretElements.delete(t))}destroy(){document.removeEventListener("selectionchange",this.onSelectionChange),this.awareness.off("change",this.onAwarenessChange),window.removeEventListener("scroll",this.onViewportChange,!0),window.removeEventListener("resize",this.onViewportChange),this.awareness.setLocalState(null);for(const t of Array.from(this.caretElements.keys()))this.removeCursor(t)}}const ql="editora-content",Ql="wss://demos.yjs.dev",xs=["#f97316","#0ea5e9","#22c55e","#a855f7","#ec4899","#eab308","#14b8a6","#ef4444"],gt=new WeakMap,Kn=new Set,pt=new Set,De=new Map;function Is(){const e=Math.floor(Math.random()*1e4);return{name:`Guest ${e}`,color:xs[e%xs.length]}}let Zl=1;const St=[],ei=".rte-content, .editora-content, [contenteditable]";let Ze=null;function th(e){return e.matches(ei)}function eh(e){const t=[];return e instanceof HTMLElement&&th(e)&&!gt.has(e)&&!pt.has(e)&&t.push(e),e.querySelectorAll(ei).forEach(n=>{n instanceof HTMLElement&&!gt.has(n)&&!pt.has(n)&&t.push(n)}),t}function ni(){if(St.length===0||typeof document>"u")return;const e=eh(document.body);for(const t of e){const n=St.find(s=>!s.claimed);if(!n)break;n.claimed=!0,oh(t,n.options)}for(;St.length&&St[0].claimed;)St.shift()}function nh(){Ze||typeof document>"u"||typeof MutationObserver>"u"||(Ze=new MutationObserver(()=>ni()),Ze.observe(document.body,{childList:!0,subtree:!0}))}function sh(e){const t={id:Zl++,options:e,claimed:!1};return St.push(t),nh(),ni(),t}function rh(){const e="editora-collaboration-presence-styles";if(typeof document>"u"||document.getElementById(e))return;const t=document.createElement("style");t.id=e,t.textContent=`
33
+ `,document.head.appendChild(e)}const ga=/^(?:#[0-9a-f]{3,8}|[a-z]{3,20}|(?:rgb|hsl)a?\([\d\s.,%/-]+\))$/i,pa="#64748b";function li(e){if(!e||typeof e!="object")return null;const{name:t,color:n}=e;return typeof t!="string"||t.length===0?null:{name:t.slice(0,64),color:typeof n=="string"&&ga.test(n.trim())?n.trim():pa}}function As(e){return Array.isArray(e)&&e.length<=256&&e.every(t=>Number.isInteger(t)&&t>=0)}function wa(e){if(!e||typeof e!="object")return null;const t=e;if(!As(t.anchorPath))return null;const n=s=>typeof s=="number"&&Number.isFinite(s)&&s>=0?Math.floor(s):0;return{anchorPath:t.anchorPath,anchorOffset:n(t.anchorOffset),focusPath:As(t.focusPath)?t.focusPath:void 0,focusOffset:n(t.focusOffset)}}function Ts(e,t){let n=e;for(const s of t){const r=n.childNodes[s];if(!r)return null;n=r}return n}function xs(e,t,n){if(!e.contains(t))return null;const s=[];let r=t;for(;r&&r!==e;){const i=r.parentNode;if(!i)return null;s.unshift(Array.prototype.indexOf.call(i.childNodes,r)),r=i}return{path:s,offset:n}}class ma{constructor(t,n,s){this.root=t,this.awareness=n,this.user=s,this.caretElements=new Map,this.pendingBroadcast=!1,this.onSelectionChange=()=>this.scheduleBroadcast(),this.onAwarenessChange=()=>this.renderRemoteCursors(),this.onViewportChange=()=>this.renderRemoteCursors(),fa(),this.awareness.setLocalStateField("user",this.user),document.addEventListener("selectionchange",this.onSelectionChange),this.awareness.on("change",this.onAwarenessChange),window.addEventListener("scroll",this.onViewportChange,!0),window.addEventListener("resize",this.onViewportChange)}scheduleBroadcast(){this.pendingBroadcast||(this.pendingBroadcast=!0,queueMicrotask(()=>{this.pendingBroadcast=!1,this.broadcastCursor()}))}broadcastCursor(){const t=window.getSelection();if(!t||t.rangeCount===0||!t.anchorNode||!t.focusNode){this.awareness.setLocalStateField("cursor",null);return}if(!this.root.contains(t.anchorNode)||!this.root.contains(t.focusNode)){this.awareness.setLocalStateField("cursor",null);return}const n=xs(this.root,t.anchorNode,t.anchorOffset),s=xs(this.root,t.focusNode,t.focusOffset);if(!n||!s)return;const r={anchorPath:n.path,anchorOffset:n.offset,focusPath:t.isCollapsed?void 0:s.path,focusOffset:t.isCollapsed?void 0:s.offset};this.awareness.setLocalStateField("cursor",r)}renderRemoteCursors(){const t=this.awareness.getStates(),n=new Set;t.forEach((s,r)=>{if(r===this.awareness.clientID)return;const i=li(s?.user),o=wa(s?.cursor);if(!i||!o){this.removeCursor(r);return}n.add(r),this.renderCursor(r,i,o)});for(const s of Array.from(this.caretElements.keys()))n.has(s)||this.removeCursor(s)}renderCursor(t,n,s){const r=Ts(this.root,s.anchorPath);if(!r){this.removeCursor(t);return}let i=this.caretElements.get(t);if(!i){const c=document.createElement("div");c.className="editora-collab-caret";const l=document.createElement("div");l.className="editora-collab-caret__label",c.appendChild(l);const a=document.createElement("div");a.className="editora-collab-selection",document.body.appendChild(a),document.body.appendChild(c),i={caret:c,selectionBox:a},this.caretElements.set(t,i)}const o=i.caret.firstElementChild;o.textContent=n.name,o.style.backgroundColor=n.color,i.caret.style.backgroundColor=n.color,i.selectionBox.style.backgroundColor=n.color;try{const c=document.createRange(),l=Math.min(s.anchorOffset,(r.textContent??"").length);c.setStart(r,l),c.setEnd(r,l);const a=c.getBoundingClientRect();if(i.caret.style.top=`${a.top}px`,i.caret.style.left=`${a.left}px`,i.caret.style.height=`${a.height||16}px`,s.focusPath){const h=Ts(this.root,s.focusPath);if(h){const u=Math.min(s.focusOffset??0,(h.textContent??"").length),d=document.createRange();d.setStart(r,l),d.setEnd(h,u);const f=d.getBoundingClientRect();i.selectionBox.style.display="block",i.selectionBox.style.top=`${f.top}px`,i.selectionBox.style.left=`${f.left}px`,i.selectionBox.style.width=`${f.width}px`,i.selectionBox.style.height=`${f.height}px`}}else i.selectionBox.style.display="none"}catch{this.removeCursor(t)}}removeCursor(t){const n=this.caretElements.get(t);n&&(n.caret.remove(),n.selectionBox.remove(),this.caretElements.delete(t))}destroy(){document.removeEventListener("selectionchange",this.onSelectionChange),this.awareness.off("change",this.onAwarenessChange),window.removeEventListener("scroll",this.onViewportChange,!0),window.removeEventListener("resize",this.onViewportChange),this.awareness.setLocalState(null);for(const t of Array.from(this.caretElements.keys()))this.removeCursor(t)}}const ya="editora-content",ai="wss://demos.yjs.dev",ba="editora-default-room",Is=["#f97316","#0ea5e9","#22c55e","#a855f7","#ec4899","#eab308","#14b8a6","#ef4444"],gt=new WeakMap,Kn=new Set,pt=new Set,Ae=new Map;let Ls=!1;function ka(e){Ls||(Ls=!0,console.warn(`[@editora/collaboration] No websocketUrl was provided, so room "${e}" is syncing through the public demo server (${ai}); anyone who knows the room name can read and edit this document. Pass your own y-websocket server via the websocketUrl option (or a provider) for real use.`))}function Os(){const e=Math.floor(Math.random()*1e4);return{name:`Guest ${e}`,color:Is[e%Is.length]}}let _a=1;const St=[],hi=".rte-content, .editora-content, [contenteditable]";let tn=null;function Sa(e){return e.matches(hi)}function Ca(e){const t=[];return e instanceof HTMLElement&&Sa(e)&&!gt.has(e)&&!pt.has(e)&&t.push(e),e.querySelectorAll(hi).forEach(n=>{n instanceof HTMLElement&&!gt.has(n)&&!pt.has(n)&&t.push(n)}),t}function ui(){if(St.length===0||typeof document>"u")return;const e=Ca(document.body);for(const t of e){const n=St.find(s=>!s.claimed);if(!n)break;n.claimed=!0,xa(t,n.options)}for(;St.length&&St[0].claimed;)St.shift()}function Ea(){tn||typeof document>"u"||typeof MutationObserver>"u"||(tn=new MutationObserver(()=>ui()),tn.observe(document.body,{childList:!0,subtree:!0}))}function Da(e){const t={id:_a++,options:e,claimed:!1};return St.push(t),Ea(),ui(),t}function Aa(){const e="editora-collaboration-presence-styles";if(typeof document>"u"||document.getElementById(e))return;const t=document.createElement("style");t.id=e,t.textContent=`
34
34
  .editora-collab-presence {
35
35
  display: inline-flex;
36
36
  align-items: center;
@@ -65,4 +65,4 @@ ${t}`),Xr=(e,t,n)=>{const s=ct(t),r=N(),i=m(s),o=e.messageHandlers[i];return o?o
65
65
  margin-left: -6px;
66
66
  border: 1.5px solid var(--rte-color-bg-primary, #ffffff);
67
67
  }
68
- `,document.head.appendChild(t)}function ih(){rh();const e=document.createElement("div");e.className="editora-collab-presence";const t=document.createElement("span");t.className="editora-collab-presence__dot",t.dataset.status="connecting";const n=document.createElement("span");return n.className="editora-collab-presence__avatars",e.appendChild(t),e.appendChild(n),e}function de(e,t,n){const s=e.querySelector(".editora-collab-presence__dot");s&&(s.dataset.status=t);const r=e.querySelector(".editora-collab-presence__avatars");if(!r)return;r.innerHTML="",n.getStates().forEach((o,c)=>{if(c===n.clientID||!o.user)return;const l=document.createElement("span");l.className="editora-collab-presence__avatar",l.style.backgroundColor=o.user.color,l.title=o.user.name,l.textContent=o.user.name.charAt(0).toUpperCase(),r.appendChild(l)})}function oh(e,t){if(gt.has(e)||pt.has(e))return;pt.add(e);const n=t.doc??new mt,s=typeof t.roomName=="function"?t.roomName(e):t.roomName??e.id??"editora-default-room",r=!t.provider,i=t.provider??new jl(t.websocketUrl??Ql,s,n),o={name:t.userName??Is().name,color:t.userColor??Is().color},c=ih();e.insertAdjacentElement("beforebegin",c),de(c,"connecting",i.awareness);const l=({status:u})=>de(c,u,i.awareness),h=()=>de(c,i.wsconnected?"connected":"connecting",i.awareness);i.on("status",l),i.awareness.on("change",h);const a=u=>{u&&(i.off("sync",a),De.delete(e),ch(e,n,i,r,o,c,l,h))};De.set(e,()=>{i.off("sync",a),i.off("status",l),i.awareness.off("change",h),c.remove(),r&&(i.destroy(),n.destroy())}),i.synced?a(!0):i.on("sync",a)}function ch(e,t,n,s,r,i,o,c){if(pt.delete(e),gt.has(e))return;const l=t.getXmlFragment(ql),h=new Wl(e,t,l),a=new Pl(e,n.awareness,r),u=new Lc(l,{trackedOrigins:new Set([h])});de(i,n.wsconnected?"connected":"connecting",n.awareness);const d=g=>{(g.metaKey||g.ctrlKey)&&(g.key.toLowerCase()==="z"&&!g.shiftKey?(g.preventDefault(),g.stopImmediatePropagation(),u.undo()):(g.key.toLowerCase()==="z"&&g.shiftKey||g.key.toLowerCase()==="y")&&(g.preventDefault(),g.stopImmediatePropagation(),u.redo()))};e.addEventListener("keydown",d,{capture:!0});const f=()=>{e.removeEventListener("keydown",d,{capture:!0}),n.off("status",o),n.awareness.off("change",c),i.remove(),a.destroy()};gt.set(e,{doc:t,provider:n,ownsProvider:s,binding:h,undoManager:u,cursorCleanup:f,connectionIndicator:i}),Kn.add(e)}function lh(e){const t=De.get(e);t&&(t(),De.delete(e),pt.delete(e));const n=gt.get(e);n&&(n.cursorCleanup(),n.binding.destroy(),n.ownsProvider&&(n.provider.destroy(),n.doc.destroy()),gt.delete(e),Kn.delete(e))}const hh=(e={})=>{let t=!1;const n={name:"collaboration",init:()=>{t||(t=!0,sh({...e,...n.__pluginConfig??{}}))},commands:{},destroy:()=>{const s=new Set([...Kn,...pt]);Array.from(s).forEach(r=>lh(r))}};return n};exports.CollaborationPlugin=hh;
68
+ `,document.head.appendChild(t)}function Ta(){Aa();const e=document.createElement("div");e.className="editora-collab-presence";const t=document.createElement("span");t.className="editora-collab-presence__dot",t.dataset.status="connecting";const n=document.createElement("span");return n.className="editora-collab-presence__avatars",e.appendChild(t),e.appendChild(n),e}function de(e,t,n){const s=e.querySelector(".editora-collab-presence__dot");s&&(s.dataset.status=t);const r=e.querySelector(".editora-collab-presence__avatars");if(!r)return;r.innerHTML="",n.getStates().forEach((o,c)=>{if(c===n.clientID)return;const l=li(o?.user);if(!l)return;const a=document.createElement("span");a.className="editora-collab-presence__avatar",a.style.backgroundColor=l.color,a.title=l.name,a.textContent=Array.from(l.name)[0].toUpperCase(),r.appendChild(a)})}function xa(e,t){if(gt.has(e)||pt.has(e))return;pt.add(e);const n=t.doc??t.provider?.doc??new mt,s=!t.doc&&!t.provider,r=typeof t.roomName=="function"?t.roomName(e):t.roomName||e.id||ba,i=!t.provider;i&&!t.websocketUrl&&ka(r);const o=t.provider??new Xl(t.websocketUrl??ai,r,n),c={name:t.userName??Os().name,color:t.userColor??Os().color},l=Ta();e.insertAdjacentElement("beforebegin",l),de(l,"connecting",o.awareness);const a=({status:d})=>de(l,d,o.awareness),h=()=>de(l,o.wsconnected?"connected":"connecting",o.awareness);o.on("status",a),o.awareness.on("change",h);const u=d=>{d&&(o.off("sync",u),Ae.delete(e),Ia(e,n,o,i,s,c,l,a,h))};Ae.set(e,()=>{o.off("sync",u),o.off("status",a),o.awareness.off("change",h),l.remove(),i&&o.destroy(),s&&n.destroy()}),o.synced?u(!0):o.on("sync",u)}function Ia(e,t,n,s,r,i,o,c,l){if(pt.delete(e),gt.has(e))return;const a=t.getXmlFragment(ya),h=new da(e,t,a),u=new ma(e,n.awareness,i),d=new Fc(a,{trackedOrigins:new Set([h])});de(o,n.wsconnected?"connected":"connecting",n.awareness);const f=p=>{(p.metaKey||p.ctrlKey)&&(p.key.toLowerCase()==="z"&&!p.shiftKey?(p.preventDefault(),p.stopImmediatePropagation(),d.undo()):(p.key.toLowerCase()==="z"&&p.shiftKey||p.key.toLowerCase()==="y")&&(p.preventDefault(),p.stopImmediatePropagation(),d.redo()))};e.addEventListener("keydown",f,{capture:!0});const g=()=>{e.removeEventListener("keydown",f,{capture:!0}),n.off("status",c),n.awareness.off("change",l),o.remove(),u.destroy()};gt.set(e,{doc:t,provider:n,ownsProvider:s,ownsDoc:r,binding:h,undoManager:d,cursorCleanup:g,connectionIndicator:o}),Kn.add(e)}function La(e){const t=Ae.get(e);t&&(t(),Ae.delete(e),pt.delete(e));const n=gt.get(e);n&&(n.cursorCleanup(),n.binding.destroy(),n.undoManager.destroy(),n.ownsProvider&&n.provider.destroy(),n.ownsDoc&&n.doc.destroy(),gt.delete(e),Kn.delete(e))}const Oa=(e={})=>{let t=!1;const n={name:"collaboration",init:()=>{t||(t=!0,Da({...e,...n.__pluginConfig??{}}))},commands:{},destroy:()=>{const s=new Set([...Kn,...pt]);Array.from(s).forEach(r=>La(r))}};return n};exports.CollaborationPlugin=Oa;