collabmd 0.1.21 → 0.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -7
- package/bin/collabmd.js +3 -2
- package/docker-compose.yml +13 -1
- package/package.json +2 -1
- package/public/assets/css/style.css +1 -1
- package/public/assets/js/chunks/{chunk-HEWVH67U.js → chunk-CYK7KO7W.js} +8 -8
- package/public/assets/js/chunks/editor-session-S5AT7BMV.js +22 -0
- package/public/assets/js/{excalidraw-editor-TCIH6GJL.js → excalidraw-editor-5YWMGLKF.js} +145 -62
- package/public/assets/js/excalidraw-editor.js +1 -1
- package/public/assets/js/main.js +503 -182
- package/public/index.html +104 -84
- package/src/client/application/app-shell/git-feature.js +247 -9
- package/src/client/application/app-shell/ui-feature.js +65 -7
- package/src/client/application/app-shell/workspace-feature.js +46 -0
- package/src/client/application/app-shell-elements.js +2 -0
- package/src/client/application/mermaid-preview-hydrator.js +1 -1
- package/src/client/application/plantuml-preview-hydrator.js +1 -1
- package/src/client/application/workspace-coordinator.js +147 -18
- package/src/client/application/workspace-preview-controller.js +34 -0
- package/src/client/application/workspace-route-controller.js +104 -0
- package/src/client/bootstrap/collabmd-app-shell.js +95 -0
- package/src/client/domain/runtime-paths.js +5 -0
- package/src/client/excalidraw-editor.js +50 -2
- package/src/client/infrastructure/auth-client.js +219 -52
- package/src/client/infrastructure/browser-navigation-port.js +20 -0
- package/src/client/infrastructure/editor-collaboration-client.js +4 -0
- package/src/client/infrastructure/editor-session.js +47 -7
- package/src/client/infrastructure/editor-view-adapter.js +122 -58
- package/src/client/infrastructure/runtime-config.js +66 -0
- package/src/client/presentation/comment-ui-controller.js +82 -26
- package/src/client/presentation/comments-panel.js +2 -2
- package/src/client/presentation/excalidraw-embed-controller.js +60 -2
- package/src/client/presentation/file-history-view-controller.js +806 -0
- package/src/client/presentation/git-diff-view-controller.js +718 -121
- package/src/client/presentation/git-panel-controller.js +458 -66
- package/src/client/presentation/layout-controller.js +1 -1
- package/src/client/styles/components/actions.css +89 -0
- package/src/client/styles/components/feedback.css +43 -0
- package/src/client/styles/components/navigation.css +68 -0
- package/src/client/styles/components/scrollbars.css +104 -0
- package/src/client/styles/components/states.css +289 -0
- package/src/client/styles/components/surfaces.css +155 -0
- package/src/client/styles/features/backlinks.css +213 -0
- package/src/client/styles/features/collaboration-chat.css +228 -0
- package/src/client/styles/features/collaboration-dialogs.css +154 -0
- package/src/client/styles/features/collaboration-presence.css +103 -0
- package/src/client/styles/features/collaboration-ui.css +3 -0
- package/src/client/styles/features/comment-card.css +236 -0
- package/src/client/styles/features/comment-markdown.css +127 -0
- package/src/client/styles/features/comment-overlays.css +60 -0
- package/src/client/styles/features/comments-drawer.css +120 -0
- package/src/client/styles/features/comments.css +4 -0
- package/src/client/styles/features/diagram-preview.css +227 -0
- package/src/client/styles/features/diff-commit.css +268 -0
- package/src/client/styles/features/diff-lines.css +160 -0
- package/src/client/styles/features/diff-toolbar.css +98 -0
- package/src/client/styles/features/diff.css +3 -0
- package/src/client/styles/features/embedded-preview.css +218 -0
- package/src/client/styles/features/git-branch.css +155 -0
- package/src/client/styles/features/git-files.css +105 -0
- package/src/client/styles/features/git-history.css +339 -0
- package/src/client/styles/features/git.css +3 -0
- package/src/client/styles/features/media-lightbox.css +157 -0
- package/src/client/styles/features/outline.css +115 -0
- package/src/client/styles/features/preview-content.css +3 -0
- package/src/client/styles/features/preview-markdown.css +201 -0
- package/src/client/styles/features/preview-sidebars.css +2 -0
- package/src/client/styles/features/quick-switcher.css +167 -0
- package/src/client/styles/foundation/themes.css +347 -0
- package/src/client/styles/foundation/tokens.css +66 -0
- package/src/client/styles/foundation/utilities.css +36 -0
- package/src/client/styles/layout/editor-page.css +203 -0
- package/src/client/styles/layout/overlays.css +132 -0
- package/src/client/styles/layout/responsive.css +251 -0
- package/src/client/styles/layout/shell.css +314 -0
- package/src/client/styles/layout/sidebar.css +176 -0
- package/src/client/styles/layout/view-modes.css +92 -0
- package/src/client/styles/overrides/codemirror.css +53 -0
- package/src/client/styles/overrides/highlightjs.css +7 -0
- package/src/client/styles/overrides/vendor.css +2 -0
- package/src/client/styles/primitives/controls.css +276 -0
- package/src/client/styles/style.css +25 -4945
- package/src/server/auth/create-auth-service.js +373 -15
- package/src/server/auth/session-cookie.js +30 -4
- package/src/server/config/env.js +121 -5
- package/src/server/create-app-server.js +8 -0
- package/src/server/domain/collaboration/collaboration-room.js +90 -47
- package/src/server/index.js +3 -1
- package/src/server/infrastructure/git/command-runner.js +2 -1
- package/src/server/infrastructure/git/git-service.js +48 -2
- package/src/server/infrastructure/git/history-service.js +683 -0
- package/src/server/infrastructure/git/parsers.js +30 -0
- package/src/server/infrastructure/git/responses.js +73 -0
- package/src/server/infrastructure/http/create-auth-api-handler.js +30 -2
- package/src/server/infrastructure/http/create-git-api-command-handler.js +2 -0
- package/src/server/infrastructure/http/create-git-api-handler.js +2 -0
- package/src/server/infrastructure/http/create-git-api-query-handler.js +61 -0
- package/src/server/infrastructure/http/create-request-handler.js +15 -0
- package/public/assets/js/chunks/editor-session-EAUBJCHH.js +0 -22
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var L=()=>new Map,Ye=e=>{let t=L();return e.forEach((n,r)=>{t.set(r,n)}),t},z=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},bs=(e,t)=>{let n=[];for(let[r,s]of e)n.push(t(s,r));return n},Ss=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1};var J=()=>new Set;var We=e=>e[e.length-1];var ks=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},X=Array.from,Xe=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},ue=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1};var _s=(e,t)=>{let n=new Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n};var ct=Array.isArray;var St=class{constructor(){this._observers=L()}on(t,n){return z(this._observers,t,J).add(n),n}once(t,n){let r=(...s)=>{this.off(t,r),n(...s)};this.on(t,r)}off(t,n){let r=this._observers.get(t);r!==void 0&&(r.delete(n),r.size===0&&this._observers.delete(t))}emit(t,n){return X((this._observers.get(t)||L()).values()).forEach(r=>r(...n))}destroy(){this._observers=L()}},Ke=class{constructor(){this._observers=L()}on(t,n){z(this._observers,t,J).add(n)}once(t,n){let r=(...s)=>{this.off(t,r),n(...s)};this.on(t,r)}off(t,n){let r=this._observers.get(t);r!==void 0&&(r.delete(n),r.size===0&&this._observers.delete(t))}emit(t,n){return X((this._observers.get(t)||L()).values()).forEach(r=>r(...n))}destroy(){this._observers=L()}};var B=Math.floor;var kt=Math.abs;var Ot=(e,t)=>e<t?e:t,lt=(e,t)=>e>t?e:t,fh=Number.isNaN,Us=Math.pow;var Qe=e=>e!==0?e<0:1/e<0;var Bt=Number.MAX_SAFE_INTEGER,Zn=Number.MIN_SAFE_INTEGER,ph=1<<31;var Es=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&B(e)===e),gh=Number.isNaN,mh=Number.parseInt;var pe=String.fromCharCode,Yi=String.fromCodePoint,wh=pe(65535),Ji=e=>e.toLowerCase(),Wi=/^\s*/g,Xi=e=>e.replace(Wi,""),Ki=/([A-Z])/g,er=(e,t)=>Xi(e.replace(Ki,n=>`${t}${Ji(n)}`));var Qi=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let s=0;s<n;s++)r[s]=t.codePointAt(s);return r},Rt=typeof TextEncoder<"u"?new TextEncoder:null,Zi=e=>Rt.encode(e),As=Rt?Zi:Qi;var Mt=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Mt&&Mt.decode(new Uint8Array).length===1&&(Mt=null);var Cs=(e,t)=>_s(t,()=>e).join("");var Ut=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},T=()=>new Ut;var tn=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t};var k=e=>{let t=new Uint8Array(tn(e)),n=0;for(let r=0;r<e.bufs.length;r++){let s=e.bufs[r];t.set(s,n),n+=s.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},tc=(e,t)=>{let n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(lt(n,t)*2),e.cpos=0)},O=(e,t)=>{let 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};var en=O;var g=(e,t)=>{for(;t>127;)O(e,128|127&t),t=B(t/128);O(e,127&t)},nn=(e,t)=>{let n=Qe(t);for(n&&(t=-t),O(e,(t>63?128:0)|(n?64:0)|63&t),t=B(t/64);t>0;)O(e,(t>127?128:0)|127&t),t=B(t/128)},nr=new Uint8Array(3e4),ec=nr.length/3,nc=(e,t)=>{if(t.length<ec){let n=Rt.encodeInto(t,nr).written||0;g(e,n);for(let r=0;r<n;r++)O(e,nr[r])}else U(e,As(t))},rc=(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;g(e,r);for(let s=0;s<r;s++)O(e,n.codePointAt(s))},at=Rt&&Rt.encodeInto?nc:rc;var we=(e,t)=>{let n=e.cbuf.length,r=e.cpos,s=Ot(n-r,t.length),o=t.length-s;e.cbuf.set(t.subarray(0,s),r),e.cpos+=s,o>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(lt(n*2,o)),e.cbuf.set(t.subarray(s)),e.cpos=o)},U=(e,t)=>{g(e,t.byteLength),we(e,t)},rr=(e,t)=>{tc(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},sc=(e,t)=>rr(e,4).setFloat32(0,t,!1),oc=(e,t)=>rr(e,8).setFloat64(0,t,!1),ic=(e,t)=>rr(e,8).setBigInt64(0,t,!1);var Ts=new DataView(new ArrayBuffer(4)),cc=e=>(Ts.setFloat32(0,e),Ts.getFloat32(0)===e),$t=(e,t)=>{switch(typeof t){case"string":O(e,119),at(e,t);break;case"number":Es(t)&&kt(t)<=2147483647?(O(e,125),nn(e,t)):cc(t)?(O(e,124),sc(e,t)):(O(e,123),oc(e,t));break;case"bigint":O(e,122),ic(e,t);break;case"object":if(t===null)O(e,126);else if(ct(t)){O(e,117),g(e,t.length);for(let n=0;n<t.length;n++)$t(e,t[n])}else if(t instanceof Uint8Array)O(e,116),U(e,t);else{O(e,118);let n=Object.keys(t);g(e,n.length);for(let r=0;r<n.length;r++){let s=n[r];at(e,s),$t(e,t[s])}}break;case"boolean":O(e,t?120:121);break;default:O(e,127)}},me=class extends Ut{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&g(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}};var Ds=e=>{e.count>0&&(nn(e.encoder,e.count===1?e.s:-e.s),e.count>1&&g(e.encoder,e.count-2))},Et=class{constructor(){this.encoder=new Ut,this.s=0,this.count=0}write(t){this.s===t?this.count++:(Ds(this),this.count=1,this.s=t)}toUint8Array(){return Ds(this),k(this.encoder)}};var Vs=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);nn(e.encoder,t),e.count>1&&g(e.encoder,e.count-2)}},jt=class{constructor(){this.encoder=new Ut,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(Vs(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return Vs(this),k(this.encoder)}},Ze=class{constructor(){this.sarr=[],this.s="",this.lensE=new Et}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){let t=new Ut;return this.sarr.push(this.s),this.s="",at(t,this.sarr.join("")),we(t,this.lensE.toUint8Array()),k(t)}};var H=e=>new Error(e),G=()=>{throw H("Method unimplemented")},$=()=>{throw H("Unexpected case")};var Ns=H("Unexpected end of array"),Ls=H("Integer out of Range"),Ft=class{constructor(t){this.arr=t,this.pos=0}},Q=e=>new Ft(e),Os=e=>e.pos!==e.arr.length;var lc=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},D=e=>lc(e,m(e));var At=e=>e.arr[e.pos++];var m=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let s=e.arr[e.pos++];if(t=t+(s&127)*n,n*=128,s<128)return t;if(t>Bt)throw Ls}throw Ns},on=e=>{let t=e.arr[e.pos++],n=t&63,r=64,s=(t&64)>0?-1:1;if((t&128)===0)return s*n;let o=e.arr.length;for(;e.pos<o;){if(t=e.arr[e.pos++],n=n+(t&127)*r,r*=128,t<128)return s*n;if(n>Bt)throw Ls}throw Ns};var ac=e=>{let t=m(e);if(t===0)return"";{let n=String.fromCodePoint(At(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(At(e));else for(;t>0;){let r=t<1e4?t:1e4,s=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,s),t-=r}return decodeURIComponent(escape(n))}},hc=e=>Mt.decode(D(e)),K=Mt?hc:ac;var or=(e,t)=>{let n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},dc=e=>or(e,4).getFloat32(0,!1),uc=e=>or(e,8).getFloat64(0,!1),fc=e=>or(e,8).getBigInt64(0,!1);var pc=[e=>{},e=>null,on,dc,uc,fc,e=>!1,e=>!0,K,e=>{let t=m(e),n={};for(let r=0;r<t;r++){let s=K(e);n[s]=Pt(e)}return n},e=>{let t=m(e),n=[];for(let r=0;r<t;r++)n.push(Pt(e));return n},D],Pt=e=>pc[127-At(e)](e),ye=class extends Ft{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Os(this)?this.count=m(this)+1:this.count=-1),this.count--,this.s}};var Ct=class extends Ft{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=on(this);let t=Qe(this.s);this.count=1,t&&(this.s=-this.s,this.count=m(this)+2)}return this.count--,this.s}};var zt=class extends Ft{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let t=on(this),n=t&1;this.diff=B(t/2),this.count=1,n&&(this.count=m(this)+2)}return this.s+=this.diff,this.count--,this.s}},sn=class{constructor(t){this.decoder=new Ct(t),this.str=K(this.decoder),this.spos=0}read(){let t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}};var bh=crypto.subtle,Bs=crypto.getRandomValues.bind(crypto);var ir=()=>Bs(new Uint32Array(1))[0];var gc="10000000-1000-4000-8000"+-1e11,Ms=()=>gc.replace(/[018]/g,e=>(e^ir()&15>>e/4).toString(16));var q=Date.now;var cr=e=>new Promise(e);var _h=Promise.all.bind(Promise);var lr=e=>e===void 0?null:e;var ar=class{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}},Rs=new ar,hr=!0;try{typeof localStorage<"u"&&localStorage&&(Rs=localStorage,hr=!1)}catch{}var ln=Rs,vs=e=>hr||addEventListener("storage",e),$s=e=>hr||removeEventListener("storage",e);var It=Symbol("Equality"),an=(e,t)=>e===t||!!e?.[It]?.(t)||!1;var Fs=e=>typeof e=="object",Ps=Object.assign,xc=Object.keys;var zs=(e,t)=>{for(let n in e)t(e[n],n)},Hs=(e,t)=>{let n=[];for(let r in e)n.push(t(e[r],r));return n};var be=e=>xc(e).length;var Gs=e=>{for(let t in e)return!1;return!0},Ht=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Se=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),ur=(e,t)=>e===t||be(e)===be(t)&&Ht(e,(n,r)=>(n!==void 0||Se(t,r))&&an(t[r],n)),bc=Object.freeze,fr=e=>{for(let t in e){let n=e[t];(typeof n=="object"||typeof n=="function")&&fr(e[t])}return bc(e)};var ke=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&ke(e,t,n+1)}};var qs=e=>e;var pt=(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[It]!=null)return e[It](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(let n of e)if(!t.has(n))return!1;break}case Map:{if(e.size!==t.size)return!1;for(let n of e.keys())if(!t.has(n)||!pt(e.get(n),t.get(n)))return!1;break}case void 0:case Object:if(be(e)!==be(t))return!1;for(let n in e)if(!Se(e,n)||!pt(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(!pt(e[n],t[n]))return!1;break;default:return!1}return!0},Ys=(e,t)=>t.includes(e);var ht=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",un=typeof window<"u"&&typeof document<"u"&&!ht,Uh=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,Z,Sc=[],kc=()=>{if(Z===void 0)if(ht){Z=L();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]==="-"?(t!==null&&Z.set(t,""),t=r):t!==null?(Z.set(t,r),t=null):Sc.push(r)}t!==null&&Z.set(t,"")}else typeof location=="object"?(Z=L(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){let[t,n]=e.split("=");Z.set(`--${er(t,"-")}`,n),Z.set(`-${er(t,"-")}`,n)}})):Z=L();return Z},pr=e=>kc().has(e);var _e=e=>ht?lr(process.env[e.toUpperCase().replaceAll("-","_")]):lr(ln.getItem(e));var Js=e=>pr("--"+e)||_e(e)!==null,Ws=Js("production"),_c=ht&&Ys(process.env.FORCE_COLOR,["true","1","2"]),Xs=_c||!pr("--no-colors")&&!Js("no-color")&&(!ht||process.stdout.isTTY)&&(!ht||pr("--color")||_e("COLORTERM")!==null||(_e("TERM")||"").includes("color"));var Ks=e=>new Uint8Array(e),Uc=(e,t,n)=>new Uint8Array(e,t,n),Qs=e=>new Uint8Array(e),Ec=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=pe(e[n]);return btoa(t)},Ac=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),Cc=e=>{let t=atob(e),n=Ks(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n},Ic=e=>{let t=Buffer.from(e,"base64");return Uc(t.buffer,t.byteOffset,t.byteLength)},Zs=un?Ec:Ac,to=un?Cc:Ic;var eo=e=>{let t=Ks(e.byteLength);return t.set(e),t};var gr=class{constructor(t,n){this.left=t,this.right=n}},tt=(e,t)=>new gr(e,t);var ro=(e,t)=>e.forEach(n=>t(n.left,n.right));var mr=e=>e.next()>=.5,fn=(e,t,n)=>B(e.next()*(n+1-t)+t);var wr=(e,t,n)=>B(e.next()*(n+1-t)+t);var yr=(e,t,n)=>wr(e,t,n);var Tc=e=>pe(yr(e,97,122)),oo=(e,t=0,n=20)=>{let r=yr(e,t,n),s="";for(let o=0;o<r;o++)s+=Tc(e);return s};var pn=(e,t)=>t[yr(e,0,t.length-1)];var Vc=Symbol("0schema"),xr=class{constructor(){this._rerrs=[]}extend(t,n,r,s=null){this._rerrs.push({path:t,expected:n,has:r,message:s})}toString(){let t=[];for(let n=this._rerrs.length-1;n>0;n--){let r=this._rerrs[n];t.push(Cs(" ",(this._rerrs.length-n)*2)+`${r.path!=null?`[${r.path}] `:""}${r.has} doesn't match ${r.expected}. ${r.message}`)}return t.join(`
|
|
2
|
-
`)}},
|
|
3
|
-
${n.toString()}`)},Ur=class{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:Ie(t),h:n}),this}else(t){return this.if(_n,t)}done(){return(t,n)=>{for(let r=0;r<this.patterns.length;r++){let s=this.patterns[r];if(s.if.check(t))return s.h(t,n)}throw H("Unhandled pattern")}}},Kc=e=>new Ur(e),wo=Kc(_n).if(po,(e,t)=>fn(t,Zn,Bt)).if(go,(e,t)=>oo(t)).if(Jc,(e,t)=>mr(t)).if(Yc,(e,t)=>BigInt(fn(t,Zn,Bt))).if(kn,(e,t)=>Gt(t,pn(t,e.shape))).if(Mc,(e,t)=>{let n={};for(let r in e.shape){let s=e.shape[r];if(Oc.check(s)){if(mr(t))continue;s=s.shape}n[r]=wo(s,t)}return n}).if(jc,(e,t)=>{let n=[],r=wr(t,0,42);for(let s=0;s<r;s++)n.push(Gt(t,e.shape));return n}).if(co,(e,t)=>pn(t,e.shape)).if(Wc,(e,t)=>null).if(Hc,(e,t)=>{let n=Gt(t,e.res);return()=>n}).if(qc,(e,t)=>Gt(t,pn(t,[qt,Jt,An,mo,Er,En,ho(qt),ao(Wt("a","b","c"),qt)]))).if(vc,(e,t)=>{let n={},r=fn(t,0,3);for(let s=0;s<r;s++){let o=Gt(t,e.shape.keys),i=Gt(t,e.shape.values);n[o]=i}return n}).done(),Gt=(e,t)=>wo(Ie(t),e);var et=typeof document<"u"?document:{},Zc=e=>et.createElement(e),tl=()=>et.createDocumentFragment(),jh=V(e=>e.nodeType===al),el=e=>et.createTextNode(e),Fh=typeof DOMParser<"u"?new DOMParser:null;var nl=(e,t)=>(ro(t,(n,r)=>{r===!1?e.removeAttribute(n):r===!0?e.setAttribute(n,""):e.setAttribute(n,r)}),e);var rl=e=>{let t=tl();for(let n=0;n<e.length;n++)bo(t,e[n]);return t},yo=(e,t)=>(bo(e,rl(t)),e);var sl=(e,t=[],n=[])=>yo(nl(Zc(e),t),n),Ph=V(e=>e.nodeType===il);var ol=el,zh=V(e=>e.nodeType===cl);var xo=e=>bs(e,(t,n)=>`${n}:${t};`).join("");var bo=(e,t)=>e.appendChild(t),il=et.ELEMENT_NODE,cl=et.TEXT_NODE,Hh=et.CDATA_SECTION_NODE,Gh=et.COMMENT_NODE,ll=et.DOCUMENT_NODE,qh=et.DOCUMENT_TYPE_NODE,al=et.DOCUMENT_FRAGMENT_NODE,Yh=V(e=>e.nodeType===ll);var nt=Symbol;var Te=nt(),De=nt(),Ar=nt(),Cr=nt(),Ir=nt(),Ve=nt(),Tr=nt(),Xt=nt(),Dr=nt(),So=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r<e.length;r++){let s=e[r];if(s===void 0)break;if(s.constructor===String||s.constructor===Number)t.push(s);else if(s.constructor===Object)break}for(r>0&&n.push(t.join(""));r<e.length;r++){let s=e[r];s instanceof Symbol||n.push(s)}return n};var Jh=q();var fl={[Te]:tt("font-weight","bold"),[De]:tt("font-weight","normal"),[Ar]:tt("color","blue"),[Ir]:tt("color","green"),[Cr]:tt("color","grey"),[Ve]:tt("color","red"),[Tr]:tt("color","purple"),[Xt]:tt("color","orange"),[Dr]:tt("color","black")},pl=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=L(),s=[],o=0;for(;o<e.length;o++){let i=e[o],c=fl[i];if(c!==void 0)r.set(c.left,c.right);else{if(i===void 0)break;if(i.constructor===String||i.constructor===Number){let l=xo(r);o>0||l.length>0?(t.push("%c"+i),n.push(l)):t.push(i)}else break}}for(o>0&&(s=n,s.unshift(t.join("")));o<e.length;o++){let i=e[o];i instanceof Symbol||s.push(i)}return s},ko=Xs?pl:So,_o=(...e)=>{console.log(...ko(e)),Uo.forEach(t=>t.print(e))},Vr=(...e)=>{console.warn(...ko(e)),e.unshift(Xt),Uo.forEach(t=>t.print(e))};var Uo=J();var Eo=e=>({[Symbol.iterator](){return this},next:e}),Ao=(e,t)=>Eo(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),Cn=(e,t)=>Eo(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}});var Le=class{constructor(t,n){this.clock=t,this.len=n}},yt=class{constructor(){this.clients=new Map}},te=(e,t,n)=>t.clients.forEach((r,s)=>{let o=e.doc.store.clients.get(s);if(o!=null){let i=o[o.length-1],c=i.id.clock+i.length;for(let l=0,h=r[l];l<r.length&&h.clock<c;h=r[++l])ei(e,o,h.clock,h.len,n)}}),xl=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let s=B((n+r)/2),o=e[s],i=o.clock;if(i<=t){if(t<i+o.len)return s;n=s+1}else r=s-1}return null},Ge=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&xl(n,t.clock)!==null},Qr=e=>{e.clients.forEach(t=>{t.sort((s,o)=>s.clock-o.clock);let n,r;for(n=1,r=1;n<t.length;n++){let s=t[r-1],o=t[n];s.clock+s.len>=o.clock?s.len=lt(s.len,o.clock+o.len-s.clock):(r<n&&(t[r]=o),r++)}t.length=r})},Lr=e=>{let t=new yt;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,s)=>{if(!t.clients.has(s)){let o=r.slice();for(let i=n+1;i<e.length;i++)ks(o,e[i].clients.get(s)||[]);t.clients.set(s,o)}});return Qr(t),t},Oe=(e,t,n,r)=>{z(e.clients,t,()=>[]).push(new Le(n,r))},Ho=()=>new yt,bl=e=>{let t=Ho();return e.clients.forEach((n,r)=>{let s=[];for(let o=0;o<n.length;o++){let i=n[o];if(i.deleted){let c=i.id.clock,l=i.length;if(o+1<n.length)for(let h=n[o+1];o+1<n.length&&h.deleted;h=n[++o+1])l+=h.length;s.push(new Le(c,l))}}s.length>0&&t.clients.set(r,s)}),t},oe=(e,t)=>{g(e.restEncoder,t.clients.size),X(t.clients.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{e.resetDsCurVal(),g(e.restEncoder,n);let s=r.length;g(e.restEncoder,s);for(let o=0;o<s;o++){let i=r[o];e.writeDsClock(i.clock),e.writeDsLen(i.len)}})},Zr=e=>{let t=new yt,n=m(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();let s=m(e.restDecoder),o=m(e.restDecoder);if(o>0){let i=z(t.clients,s,()=>[]);for(let c=0;c<o;c++)i.push(new Le(e.readDsClock(),e.readDsLen()))}}return t},To=(e,t,n)=>{let r=new yt,s=m(e.restDecoder);for(let o=0;o<s;o++){e.resetDsCurVal();let i=m(e.restDecoder),c=m(e.restDecoder),l=n.clients.get(i)||[],h=E(n,i);for(let a=0;a<c;a++){let d=e.readDsClock(),u=d+e.readDsLen();if(d<h){h<u&&Oe(r,i,h,u-h);let f=rt(l,d),p=l[f];for(!p.deleted&&p.id.clock<d&&(l.splice(f+1,0,Hn(t,p,d-p.id.clock)),f++);f<l.length&&(p=l[f++],p.id.clock<u);)p.deleted||(u<p.id.clock+p.length&&l.splice(f,0,Hn(t,p,u-p.id.clock)),p.delete(t))}else Oe(r,i,d,u-d)}}if(r.clients.size>0){let o=new dt;return g(o.restEncoder,0),oe(o,r),o.toUint8Array()}return null};var Go=ir,ee=class e extends St{constructor({guid:t=Ms(),collectionid:n=null,gc:r=!0,gcFilter:s=()=>!0,meta:o=null,autoLoad:i=!1,shouldLoad:c=!0}={}){super(),this.gc=r,this.gcFilter=s,this.clientID=Go(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new $n,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=i,this.meta=o,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=cr(h=>{this.on("load",()=>{this.isLoaded=!0,h(this)})});let l=()=>cr(h=>{let a=d=>{(d===void 0||d===!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(){let t=this._item;t!==null&&!this.shouldLoad&&S(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 S(this,t,n)}get(t,n=I){let r=z(this.share,t,()=>{let o=new n;return o._integrate(this,null),o}),s=r.constructor;if(n!==I&&s!==n)if(s===I){let o=new n;o._map=r._map,r._map.forEach(i=>{for(;i!==null;i=i.left)i.parent=o}),o._start=r._start;for(let i=o._start;i!==null;i=i.right)i.parent=o;return o._length=r._length,this.share.set(t,o),o._integrate(this,null),o}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return r}getArray(t=""){return this.get(t,bt)}getText(t=""){return this.get(t,je)}getMap(t=""){return this.get(t,st)}getXmlElement(t=""){return this.get(t,Fe)}getXmlFragment(t=""){return this.get(t,re)}toJSON(){let t={};return this.share.forEach((n,r)=>{t[r]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,X(this.subdocs).forEach(n=>n.destroy());let t=this._item;if(t!==null){this._item=null;let n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,S(t.parent.doc,r=>{let s=n.doc;t.deleted||r.subdocsAdded.add(s),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}},Ln=class{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return m(this.restDecoder)}readDsLen(){return m(this.restDecoder)}},On=class extends Ln{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 At(this.restDecoder)}readString(){return K(this.restDecoder)}readParentInfo(){return m(this.restDecoder)===1}readTypeRef(){return m(this.restDecoder)}readLen(){return m(this.restDecoder)}readAny(){return Pt(this.restDecoder)}readBuf(){return eo(D(this.restDecoder))}readJSON(){return JSON.parse(K(this.restDecoder))}readKey(){return K(this.restDecoder)}},Or=class{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=m(this.restDecoder),this.dsCurrVal}readDsLen(){let t=m(this.restDecoder)+1;return this.dsCurrVal+=t,t}},xt=class extends Or{constructor(t){super(t),this.keys=[],m(t),this.keyClockDecoder=new zt(D(t)),this.clientDecoder=new Ct(D(t)),this.leftClockDecoder=new zt(D(t)),this.rightClockDecoder=new zt(D(t)),this.infoDecoder=new ye(D(t),At),this.stringDecoder=new sn(D(t)),this.parentInfoDecoder=new ye(D(t),At),this.typeRefDecoder=new Ct(D(t)),this.lenDecoder=new Ct(D(t))}readLeftID(){return new wt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new wt(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 Pt(this.restDecoder)}readBuf(){return D(this.restDecoder)}readJSON(){return Pt(this.restDecoder)}readKey(){let t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{let n=this.stringDecoder.read();return this.keys.push(n),n}}},Bn=class{constructor(){this.restEncoder=T()}toUint8Array(){return k(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){g(this.restEncoder,t)}writeDsLen(t){g(this.restEncoder,t)}},Tt=class extends Bn{writeLeftID(t){g(this.restEncoder,t.client),g(this.restEncoder,t.clock)}writeRightID(t){g(this.restEncoder,t.client),g(this.restEncoder,t.clock)}writeClient(t){g(this.restEncoder,t)}writeInfo(t){en(this.restEncoder,t)}writeString(t){at(this.restEncoder,t)}writeParentInfo(t){g(this.restEncoder,t?1:0)}writeTypeRef(t){g(this.restEncoder,t)}writeLen(t){g(this.restEncoder,t)}writeAny(t){$t(this.restEncoder,t)}writeBuf(t){U(this.restEncoder,t)}writeJSON(t){at(this.restEncoder,JSON.stringify(t))}writeKey(t){at(this.restEncoder,t)}},Mn=class{constructor(){this.restEncoder=T(),this.dsCurrVal=0}toUint8Array(){return k(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){let n=t-this.dsCurrVal;this.dsCurrVal=t,g(this.restEncoder,n)}writeDsLen(t){t===0&&$(),g(this.restEncoder,t-1),this.dsCurrVal+=t}},dt=class extends Mn{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new jt,this.clientEncoder=new Et,this.leftClockEncoder=new jt,this.rightClockEncoder=new jt,this.infoEncoder=new me(en),this.stringEncoder=new Ze,this.parentInfoEncoder=new me(en),this.typeRefEncoder=new Et,this.lenEncoder=new Et}toUint8Array(){let t=T();return g(t,0),U(t,this.keyClockEncoder.toUint8Array()),U(t,this.clientEncoder.toUint8Array()),U(t,this.leftClockEncoder.toUint8Array()),U(t,this.rightClockEncoder.toUint8Array()),U(t,k(this.infoEncoder)),U(t,this.stringEncoder.toUint8Array()),U(t,k(this.parentInfoEncoder)),U(t,this.typeRefEncoder.toUint8Array()),U(t,this.lenEncoder.toUint8Array()),we(t,k(this.restEncoder)),k(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){$t(this.restEncoder,t)}writeBuf(t){U(this.restEncoder,t)}writeJSON(t){$t(this.restEncoder,t)}writeKey(t){let n=this.keyMap.get(t);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}},Sl=(e,t,n,r)=>{r=lt(r,t[0].id.clock);let s=rt(t,r);g(e.restEncoder,t.length-s),e.writeClient(n),g(e.restEncoder,r);let o=t[s];o.write(e,r-o.id.clock);for(let i=s+1;i<t.length;i++)t[i].write(e,0)},ts=(e,t,n)=>{let r=new Map;n.forEach((s,o)=>{E(t,o)>s&&r.set(o,s)}),Gn(t).forEach((s,o)=>{n.has(o)||r.set(o,0)}),g(e.restEncoder,r.size),X(r.entries()).sort((s,o)=>o[0]-s[0]).forEach(([s,o])=>{Sl(e,t.clients.get(s),s,o)})},kl=(e,t)=>{let n=L(),r=m(e.restDecoder);for(let s=0;s<r;s++){let o=m(e.restDecoder),i=new Array(o),c=e.readClient(),l=m(e.restDecoder);n.set(c,{i:0,refs:i});for(let h=0;h<o;h++){let a=e.readInfo();switch(31&a){case 0:{let d=e.readLen();i[h]=new F(y(c,l),d),l+=d;break}case 10:{let d=m(e.restDecoder);i[h]=new P(y(c,l),d),l+=d;break}default:{let d=(a&192)===0,u=new _(y(c,l),null,(a&128)===128?e.readLeftID():null,null,(a&64)===64?e.readRightID():null,d?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,d&&(a&32)===32?e.readString():null,Si(e,a));i[h]=u,l+=u.length}}}}return n},_l=(e,t,n)=>{let r=[],s=X(n.keys()).sort((f,p)=>f-p);if(s.length===0)return null;let o=()=>{if(s.length===0)return null;let f=n.get(s[s.length-1]);for(;f.refs.length===f.i;)if(s.pop(),s.length>0)f=n.get(s[s.length-1]);else return null;return f},i=o();if(i===null)return null;let c=new $n,l=new Map,h=(f,p)=>{let w=l.get(f);(w==null||w>p)&&l.set(f,p)},a=i.refs[i.i++],d=new Map,u=()=>{for(let f of r){let p=f.id.client,w=n.get(p);w?(w.i--,c.clients.set(p,w.refs.slice(w.i)),n.delete(p),w.i=0,w.refs=[]):c.clients.set(p,[f]),s=s.filter(x=>x!==p)}r.length=0};for(;;){if(a.constructor!==P){let p=z(d,a.id.client,()=>E(t,a.id.client))-a.id.clock;if(p<0)r.push(a),h(a.id.client,a.id.clock-1),u();else{let w=a.getMissing(e,t);if(w!==null){r.push(a);let x=n.get(w)||{refs:[],i:0};if(x.refs.length===x.i)h(w,E(t,w)),u();else{a=x.refs[x.i++];continue}}else(p===0||p<a.length)&&(a.integrate(e,p),d.set(a.id.client,a.id.clock+a.length))}}if(r.length>0)a=r.pop();else if(i!==null&&i.i<i.refs.length)a=i.refs[i.i++];else{if(i=o(),i===null)break;a=i.refs[i.i++]}}if(c.clients.size>0){let f=new dt;return ts(f,c,new Map),g(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},Ul=(e,t)=>ts(e,t.doc.store,t.beforeState),El=(e,t,n,r=new xt(e))=>S(t,s=>{s.local=!1;let o=!1,i=s.doc,c=i.store,l=kl(r,i),h=_l(s,c,l),a=c.pendingStructs;if(a){for(let[u,f]of a.missing)if(f<E(c,u)){o=!0;break}if(h){for(let[u,f]of h.missing){let p=a.missing.get(u);(p==null||p>f)&&a.missing.set(u,f)}a.update=jn([a.update,h.update])}}else c.pendingStructs=h;let d=To(r,s,c);if(c.pendingDs){let u=new xt(Q(c.pendingDs));m(u.restDecoder);let f=To(u,s,c);d&&f?c.pendingDs=jn([d,f]):c.pendingDs=d||f}else c.pendingDs=d;if(o){let u=c.pendingStructs.update;c.pendingStructs=null,qo(s.doc,u)}},n,!1);var qo=(e,t,n,r=xt)=>{let s=Q(t);El(s,e,n,new r(s))},Yo=(e,t,n)=>qo(e,t,n,On),Al=(e,t,n=new Map)=>{ts(e,t.store,n),oe(e,bl(t.store))},Cl=(e,t=new Uint8Array([0]),n=new dt)=>{let r=Wo(t);Al(n,e,r);let s=[n.toUint8Array()];if(e.store.pendingDs&&s.push(e.store.pendingDs),e.store.pendingStructs&&s.push(Fl(e.store.pendingStructs.update,t)),s.length>1){if(n.constructor===Tt)return $l(s.map((o,i)=>i===0?o:zl(o)));if(n.constructor===dt)return jn(s)}return s[0]},Jo=(e,t)=>Cl(e,t,new Tt),Il=e=>{let t=new Map,n=m(e.restDecoder);for(let r=0;r<n;r++){let s=m(e.restDecoder),o=m(e.restDecoder);t.set(s,o)}return t},Wo=e=>Il(new Ln(Q(e))),Xo=(e,t)=>(g(e.restEncoder,t.size),X(t.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{g(e.restEncoder,n),g(e.restEncoder,r)}),e),Tl=(e,t)=>Xo(e,Gn(t.store)),Dl=(e,t=new Mn)=>(e instanceof Map?Xo(t,e):Tl(t,e),t.toUint8Array()),Ko=e=>Dl(e,new Bn),Br=class{constructor(){this.l=[]}},Do=()=>new Br,Vo=(e,t)=>e.l.push(t),No=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(s=>t!==s),r===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Qo=(e,t,n)=>ke(e.l,[t,n]),wt=class{constructor(t,n){this.client=t,this.clock=n}},Qt=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,y=(e,t)=>new wt(e,t);var Zo=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw $()},Rn=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1};var vn=class{constructor(t,n,r,s=0){this.type=t,this.tname=n,this.item=r,this.assoc=s}},ed=e=>{let t={};return e.type&&(t.type=e.type),e.tname&&(t.tname=e.tname),e.item&&(t.item=e.item),e.assoc!=null&&(t.assoc=e.assoc),t},nd=e=>new vn(e.type==null?null:y(e.type.client,e.type.clock),e.tname??null,e.item==null?null:y(e.item.client,e.item.clock),e.assoc==null?0:e.assoc),Mr=class{constructor(t,n,r=0){this.type=t,this.index=n,this.assoc=r}},Vl=(e,t,n=0)=>new Mr(e,t,n),In=(e,t,n)=>{let r=null,s=null;return e._item===null?s=Zo(e):r=y(e._item.id.client,e._item.id.clock),new vn(r,s,t,n)},rd=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return In(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return In(e,y(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return In(e,r.lastId,n);r=r.right}return In(e,null,n)};var Nl=(e,t)=>{let n=Zt(e,t),r=t.clock-n.id.clock;return{item:n,diff:r}},sd=(e,t,n=!0)=>{let r=t.store,s=e.item,o=e.type,i=e.tname,c=e.assoc,l=null,h=0;if(s!==null){if(E(r,s.client)<=s.clock)return null;let a=n?Xr(r,s):Nl(r,s),d=a.item;if(!(d instanceof _))return null;if(l=d.parent,l._item===null||!l._item.deleted){h=d.deleted||!d.countable?0:a.diff+(c>=0?0:1);let u=d.left;for(;u!==null;)!u.deleted&&u.countable&&(h+=u.length),u=u.left}}else{if(i!==null)l=t.get(i);else if(o!==null){if(E(r,o.client)<=o.clock)return null;let{item:a}=n?Xr(r,o):{item:Zt(r,o)};if(a instanceof _&&a.content instanceof ot)l=a.content.type;else return null}else throw $();c>=0?h=l._length:h=0}return Vl(l,h,e.assoc)},od=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&Qt(e.item,t.item)&&Qt(e.type,t.type)&&e.assoc===t.assoc,Rr=class{constructor(t,n){this.ds=t,this.sv=n}};var Ll=(e,t)=>new Rr(e,t),id=Ll(Ho(),new Map);var Kt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Ge(t.ds,e.id),vr=(e,t)=>{let n=z(e.meta,vr,J),r=e.doc.store;n.has(t)||(t.sv.forEach((s,o)=>{s<E(r,o)&&j(e,y(o,s))}),te(e,t.ds,s=>{}),n.add(t))};var $n=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Gn=e=>{let t=new Map;return e.clients.forEach((n,r)=>{let s=n[n.length-1];t.set(r,s.id.clock+s.length)}),t},E=(e,t)=>{let n=e.clients.get(t);if(n===void 0)return 0;let r=n[n.length-1];return r.id.clock+r.length},ti=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let r=n[n.length-1];if(r.id.clock+r.length!==t.id.clock)throw $()}n.push(t)},rt=(e,t)=>{let n=0,r=e.length-1,s=e[r],o=s.id.clock;if(o===t)return r;let i=B(t/(o+s.length-1)*r);for(;n<=r;){if(s=e[i],o=s.id.clock,o<=t){if(t<o+s.length)return i;n=i+1}else r=i-1;i=B((n+r)/2)}throw $()},Ol=(e,t)=>{let n=e.clients.get(t.client);return n[rt(n,t.clock)]},Zt=Ol,$r=(e,t,n)=>{let r=rt(t,n),s=t[r];return s.id.clock<n&&s instanceof _?(t.splice(r+1,0,Hn(e,s,n-s.id.clock)),r+1):r},j=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[$r(e,n,t.clock)]},Lo=(e,t,n)=>{let r=t.clients.get(n.client),s=rt(r,n.clock),o=r[s];return n.clock!==o.id.clock+o.length-1&&o.constructor!==F&&r.splice(s+1,0,Hn(e,o,n.clock-o.id.clock+1)),o},Bl=(e,t,n)=>{let r=e.clients.get(t.id.client);r[rt(r,t.id.clock)]=n},ei=(e,t,n,r,s)=>{if(r===0)return;let o=n+r,i=$r(e,t,n),c;do c=t[i++],o<c.id.clock+c.length&&$r(e,t,o),s(c);while(i<t.length&&t[i].id.clock<o)},jr=class{constructor(t,n,r){this.doc=t,this.deleteSet=new yt,this.beforeState=Gn(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=r,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}},Oo=(e,t)=>t.deleteSet.clients.size===0&&!Ss(t.afterState,(n,r)=>t.beforeState.get(r)!==n)?!1:(Qr(t.deleteSet),Ul(e,t),oe(e,t.deleteSet),!0),Bo=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&z(e.changed,t,J).add(n)},Vn=(e,t)=>{let n=e[t],r=e[t-1],s=t;for(;s>0;n=r,r=e[--s-1]){if(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n)){n instanceof _&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}let o=t-s;return o&&e.splice(t+1-o,o),o},Ml=(e,t,n)=>{for(let[r,s]of e.clients.entries()){let o=t.clients.get(r);for(let i=s.length-1;i>=0;i--){let c=s[i],l=c.clock+c.len;for(let h=rt(o,c.clock),a=o[h];h<o.length&&a.id.clock<l;a=o[++h]){let d=o[h];if(c.clock+c.len<=d.id.clock)break;d instanceof _&&d.deleted&&!d.keep&&n(d)&&d.gc(t,!1)}}}},Rl=(e,t)=>{e.clients.forEach((n,r)=>{let s=t.clients.get(r);for(let o=n.length-1;o>=0;o--){let i=n[o],c=Ot(s.length-1,1+rt(s,i.clock+i.len-1));for(let l=c,h=s[l];l>0&&h.id.clock>=i.clock;h=s[l])l-=1+Vn(s,l)}})};var ni=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,s=r.store,o=n.deleteSet,i=n._mergeStructs;try{Qr(o),n.afterState=Gn(n.doc.store),r.emit("beforeObserverCalls",[n,r]);let 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)&&(l=l.filter(a=>a.target._item===null||!a.target._item.deleted),l.forEach(a=>{a.currentTarget=h,a._path=null}),l.sort((a,d)=>a.path.length-d.path.length),c.push(()=>{Qo(h._dEH,l,n)}))}),c.push(()=>r.emit("afterTransaction",[n,r])),c.push(()=>{n._needFormattingCleanup&&ta(n)})}),ke(c,[])}finally{r.gc&&Ml(o,s,r.gcFilter),Rl(o,s),n.afterState.forEach((a,d)=>{let u=n.beforeState.get(d)||0;if(u!==a){let f=s.clients.get(d),p=lt(rt(f,u),1);for(let w=f.length-1;w>=p;)w-=1+Vn(f,w)}});for(let a=i.length-1;a>=0;a--){let{client:d,clock:u}=i[a].id,f=s.clients.get(d),p=rt(f,u);p+1<f.length&&Vn(f,p+1)>1||p>0&&Vn(f,p)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(_o(Xt,Te,"[yjs] ",De,Ve,"Changed the client-id because another client seems to be using it."),r.clientID=Go()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){let a=new Tt;Oo(a,n)&&r.emit("update",[a.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){let a=new dt;Oo(a,n)&&r.emit("updateV2",[a.toUint8Array(),n.origin,r,n])}let{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:h}=n;(c.size>0||h.size>0||l.size>0)&&(c.forEach(a=>{a.clientID=r.clientID,a.collectionid==null&&(a.collectionid=r.collectionid),r.subdocs.add(a)}),h.forEach(a=>r.subdocs.delete(a)),r.emit("subdocs",[{loaded:l,added:c,removed:h},r,n]),h.forEach(a=>a.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,e])):ni(e,t+1)}}},S=(e,t,n=null,r=!0)=>{let s=e._transactionCleanups,o=!1,i=null;e._transaction===null&&(o=!0,e._transaction=new jr(e,n,r),s.push(e._transaction),s.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{i=t(e._transaction)}finally{if(o){let c=e._transaction===s[0];e._transaction=null,c&&ni(s,0)}}return i},Fr=class{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}},Mo=(e,t,n)=>{te(e,n.deletions,r=>{r instanceof _&&t.scope.some(s=>s===e.doc||Rn(s,r))&&os(r,!1)})},Ro=(e,t,n)=>{let r=null,s=e.doc,o=e.scope;S(s,c=>{for(;t.length>0&&e.currStackItem===null;){let l=s.store,h=t.pop(),a=new Set,d=[],u=!1;te(c,h.insertions,f=>{if(f instanceof _){if(f.redone!==null){let{item:p,diff:w}=Xr(l,f.id);w>0&&(p=j(c,y(p.id.client,p.id.clock+w))),f=p}!f.deleted&&o.some(p=>p===c.doc||Rn(p,f))&&d.push(f)}}),te(c,h.deletions,f=>{f instanceof _&&o.some(p=>p===c.doc||Rn(p,f))&&!Ge(h.insertions,f.id)&&a.add(f)}),a.forEach(f=>{u=bi(c,f,a,h.insertions,e.ignoreRemoteMapChanges,e)!==null||u});for(let f=d.length-1;f>=0;f--){let p=d[f];e.deleteFilter(p)&&(p.delete(c),u=!0)}e.currStackItem=u?h:null}c.changed.forEach((l,h)=>{l.has(null)&&h._searchMarker&&(h._searchMarker.length=0)}),r=c},e);let i=e.currStackItem;if(i!=null){let c=r.changedParentTypes;e.emit("stack-item-popped",[{stackItem:i,type:n,changedParentTypes:c,origin:e},e]),e.currStackItem=null}return i},vo=class extends St{constructor(t,{captureTimeout:n=500,captureTransaction:r=l=>!0,deleteFilter:s=()=>!0,trackedOrigins:o=new Set([null]),ignoreRemoteMapChanges:i=!1,doc:c=ct(t)?t[0].doc:t instanceof ee?t:t.doc}={}){super(),this.scope=[],this.doc=c,this.addToScope(t),this.deleteFilter=s,o.add(this),this.trackedOrigins=o,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=i,this.captureTimeout=n,this.afterTransactionHandler=l=>{if(!this.captureTransaction(l)||!this.scope.some(x=>l.changedParentTypes.has(x)||x===this.doc)||!this.trackedOrigins.has(l.origin)&&(!l.origin||!this.trackedOrigins.has(l.origin.constructor)))return;let h=this.undoing,a=this.redoing,d=h?this.redoStack:this.undoStack;h?this.stopCapturing():a||this.clear(!1,!0);let u=new yt;l.afterState.forEach((x,b)=>{let ys=l.beforeState.get(b)||0,xs=x-ys;xs>0&&Oe(u,b,ys,xs)});let f=q(),p=!1;if(this.lastChange>0&&f-this.lastChange<this.captureTimeout&&d.length>0&&!h&&!a){let x=d[d.length-1];x.deletions=Lr([x.deletions,l.deleteSet]),x.insertions=Lr([x.insertions,u])}else d.push(new Fr(l.deleteSet,u)),p=!0;!h&&!a&&(this.lastChange=f),te(l,l.deleteSet,x=>{x instanceof _&&this.scope.some(b=>b===l.doc||Rn(b,x))&&os(x,!0)});let w=[{stackItem:d[d.length-1],origin:l.origin,type:h?"redo":"undo",changedParentTypes:l.changedParentTypes},this];p?this.emit("stack-item-added",w):this.emit("stack-item-updated",w)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){let n=new Set(this.scope);t=ct(t)?t:[t],t.forEach(r=>{n.has(r)||(n.add(r),(r instanceof I?r.doc!==this.doc:r!==this.doc)&&Vr("[yjs#509] Not same Y.Doc"),this.scope.push(r))})}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(r=>{t&&(this.undoStack.forEach(s=>Mo(r,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>Mo(r,this,s)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let t;try{t=Ro(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=Ro(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),super.destroy()}};function*vl(e){let t=m(e.restDecoder);for(let n=0;n<t;n++){let r=m(e.restDecoder),s=e.readClient(),o=m(e.restDecoder);for(let i=0;i<r;i++){let c=e.readInfo();if(c===10){let l=m(e.restDecoder);yield new P(y(s,o),l),o+=l}else if((31&c)!==0){let l=(c&192)===0,h=new _(y(s,o),null,(c&128)===128?e.readLeftID():null,null,(c&64)===64?e.readRightID():null,l?e.readParentInfo()?e.readString():e.readLeftID():null,l&&(c&32)===32?e.readString():null,Si(e,c));yield h,o+=h.length}else{let l=e.readLen();yield new F(y(s,o),l),o+=l}}}}var Be=class{constructor(t,n){this.gen=vl(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===P);return this.curr}};var Me=class{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}},$l=e=>jn(e,On,Tt);var jl=(e,t)=>{if(e.constructor===F){let{client:n,clock:r}=e.id;return new F(y(n,r+t),e.length-t)}else if(e.constructor===P){let{client:n,clock:r}=e.id;return new P(y(n,r+t),e.length-t)}else{let n=e,{client:r,clock:s}=n.id;return new _(y(r,s+t),null,y(r,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},jn=(e,t=xt,n=dt)=>{if(e.length===1)return e[0];let r=e.map(a=>new t(Q(a))),s=r.map(a=>new Be(a,!0)),o=null,i=new n,c=new Me(i);for(;s=s.filter(u=>u.curr!==null),s.sort((u,f)=>{if(u.curr.id.client===f.curr.id.client){let p=u.curr.id.clock-f.curr.id.clock;return p===0?u.curr.constructor===f.curr.constructor?0:u.curr.constructor===P?1:-1:p}else return f.curr.id.client-u.curr.id.client}),s.length!==0;){let a=s[0],d=a.curr.id.client;if(o!==null){let u=a.curr,f=!1;for(;u!==null&&u.id.clock+u.length<=o.struct.id.clock+o.struct.length&&u.id.client>=o.struct.id.client;)u=a.next(),f=!0;if(u===null||u.id.client!==d||f&&u.id.clock>o.struct.id.clock+o.struct.length)continue;if(d!==o.struct.id.client)gt(c,o.struct,o.offset),o={struct:u,offset:0},a.next();else if(o.struct.id.clock+o.struct.length<u.id.clock)if(o.struct.constructor===P)o.struct.length=u.id.clock+u.length-o.struct.id.clock;else{gt(c,o.struct,o.offset);let p=u.id.clock-o.struct.id.clock-o.struct.length;o={struct:new P(y(d,o.struct.id.clock+o.struct.length),p),offset:0}}else{let p=o.struct.id.clock+o.struct.length-u.id.clock;p>0&&(o.struct.constructor===P?o.struct.length-=p:u=jl(u,p)),o.struct.mergeWith(u)||(gt(c,o.struct,o.offset),o={struct:u,offset:0},a.next())}}else o={struct:a.curr,offset:0},a.next();for(let u=a.curr;u!==null&&u.id.client===d&&u.id.clock===o.struct.id.clock+o.struct.length&&u.constructor!==P;u=a.next())gt(c,o.struct,o.offset),o={struct:u,offset:0}}o!==null&&(gt(c,o.struct,o.offset),o=null),es(c);let l=r.map(a=>Zr(a)),h=Lr(l);return oe(i,h),i.toUint8Array()},Fl=(e,t,n=xt,r=dt)=>{let s=Wo(t),o=new r,i=new Me(o),c=new n(Q(e)),l=new Be(c,!1);for(;l.curr;){let a=l.curr,d=a.id.client,u=s.get(d)||0;if(l.curr.constructor===P){l.next();continue}if(a.id.clock+a.length>u)for(gt(i,a,lt(u-a.id.clock,0)),l.next();l.curr&&l.curr.id.client===d;)gt(i,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===d&&l.curr.id.clock+l.curr.length<=u;)l.next()}es(i);let h=Zr(c);return oe(o,h),o.toUint8Array()};var ri=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:k(e.encoder.restEncoder)}),e.encoder.restEncoder=T(),e.written=0)},gt=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&ri(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),g(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},es=e=>{ri(e);let t=e.encoder.restEncoder;g(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];g(t,r.written),we(t,r.restEncoder)}},Pl=(e,t,n,r)=>{let s=new n(Q(e)),o=new Be(s,!1),i=new r,c=new Me(i);for(let h=o.curr;h!==null;h=o.next())gt(c,t(h),0);es(c);let l=Zr(s);return oe(i,l),i.toUint8Array()};var zl=e=>Pl(e,qs,xt,Tt),$o="You must not compute changes after the event-handler fired.",ne=class{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=Hl(this.currentTarget,this.target))}deletes(t){return Ge(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw H($o);let t=new Map,n=this.target;this.transaction.changed.get(n).forEach(s=>{if(s!==null){let o=n._map.get(s),i,c;if(this.adds(o)){let l=o.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(o))if(l!==null&&this.deletes(l))i="delete",c=We(l.content.getContent());else return;else l!==null&&this.deletes(l)?(i="update",c=We(l.content.getContent())):(i="add",c=void 0)}else if(this.deletes(o))i="delete",c=We(o.content.getContent());else return;t.set(s,{action:i,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 H($o);let n=this.target,r=J(),s=J(),o=[];if(t={added:r,deleted:s,delta:o,keys:this.keys},this.transaction.changed.get(n).has(null)){let c=null,l=()=>{c&&o.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,s.add(h)):this.adds(h)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(h.content.getContent()),r.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}},Hl=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let r=0,s=t._item.parent._start;for(;s!==t._item&&s!==null;)!s.deleted&&s.countable&&(r+=s.length),s=s.right;n.unshift(r)}t=t._item.parent}return n},v=()=>{Vr("Invalid access: Add Yjs type to a document before reading data.")},si=80,ns=0,Pr=class{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=ns++}},Gl=e=>{e.timestamp=ns++},oi=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=ns++},ql=(e,t,n)=>{if(e.length>=si){let r=e.reduce((s,o)=>s.timestamp<o.timestamp?s:o);return oi(r,t,n),r}else{let r=new Pr(t,n);return e.push(r),r}},qn=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((o,i)=>kt(t-o.index)<kt(t-i.index)?o:i),r=e._start,s=0;for(n!==null&&(r=n.p,s=n.index,Gl(n));r.right!==null&&s<t;){if(!r.deleted&&r.countable){if(t<s+r.length)break;s+=r.length}r=r.right}for(;r.left!==null&&s>t;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);return n!==null&&kt(n.index-s)<r.parent.length/si?(oi(n,r,s),n):ql(e._searchMarker,r,s)},Re=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){let s=e[r];if(n>0){let o=s.p;for(o.marker=!1;o&&(o.deleted||!o.countable);)o=o.left,o&&!o.deleted&&o.countable&&(s.index-=o.length);if(o===null||o.marker===!0){e.splice(r,1);continue}s.p=o,o.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=lt(t,s.index+n))}};var Yn=(e,t,n)=>{let r=e,s=t.changedParentTypes;for(;z(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Qo(r._eH,n,t)},I=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Do(),this._dEH=Do(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw G()}clone(){throw G()}_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){Vo(this._eH,t)}observeDeep(t){Vo(this._dEH,t)}unobserve(t){No(this._eH,t)}unobserveDeep(t){No(this._dEH,t)}toJSON(){}},ii=(e,t,n)=>{e.doc??v(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,s=[],o=e._start;for(;o!==null&&r>0;){if(o.countable&&!o.deleted){let i=o.content.getContent();if(i.length<=t)t-=i.length;else{for(let c=t;c<i.length&&r>0;c++)s.push(i[c]),r--;t=0}}o=o.right}return s},ci=e=>{e.doc??v();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let r=n.content.getContent();for(let s=0;s<r.length;s++)t.push(r[s])}n=n.right}return t};var ve=(e,t)=>{let n=0,r=e._start;for(e.doc??v();r!==null;){if(r.countable&&!r.deleted){let s=r.content.getContent();for(let o=0;o<s.length;o++)t(s[o],n++,e)}r=r.right}},li=(e,t)=>{let n=[];return ve(e,(r,s)=>{n.push(t(r,s,e))}),n},Yl=e=>{let t=e._start,n=null,r=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(),r=0,t=t.right}let s=n[r++];return n.length<=r&&(n=null),{done:!1,value:s}}}},ai=(e,t)=>{e.doc??v();let n=qn(e,t),r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},Fn=(e,t,n,r)=>{let s=n,o=e.doc,i=o.clientID,c=o.store,l=n===null?t._start:n.right,h=[],a=()=>{h.length>0&&(s=new _(y(i,E(c,i)),s,s&&s.lastId,l,l&&l.id,t,null,new se(h)),s.integrate(e,0),h=[])};r.forEach(d=>{if(d===null)h.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:h.push(d);break;default:switch(a(),d.constructor){case Uint8Array:case ArrayBuffer:s=new _(y(i,E(c,i)),s,s&&s.lastId,l,l&&l.id,t,null,new ze(new Uint8Array(d))),s.integrate(e,0);break;case ee:s=new _(y(i,E(c,i)),s,s&&s.lastId,l,l&&l.id,t,null,new He(d)),s.integrate(e,0);break;default:if(d instanceof I)s=new _(y(i,E(c,i)),s,s&&s.lastId,l,l&&l.id,t,null,new ot(d)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),a()},hi=()=>H("Length exceeded!"),di=(e,t,n,r)=>{if(n>t._length)throw hi();if(n===0)return t._searchMarker&&Re(t._searchMarker,n,r.length),Fn(e,t,null,r);let s=n,o=qn(t,n),i=t._start;for(o!==null&&(i=o.p,n-=o.index,n===0&&(i=i.prev,n+=i&&i.countable&&!i.deleted?i.length:0));i!==null;i=i.right)if(!i.deleted&&i.countable){if(n<=i.length){n<i.length&&j(e,y(i.id.client,i.id.clock+n));break}n-=i.length}return t._searchMarker&&Re(t._searchMarker,s,r.length),Fn(e,t,i,r)},Jl=(e,t,n)=>{let s=(t._searchMarker||[]).reduce((o,i)=>i.index>o.index?i:o,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return Fn(e,t,s,n)},ui=(e,t,n,r)=>{if(r===0)return;let s=n,o=r,i=qn(t,n),c=t._start;for(i!==null&&(c=i.p,n-=i.index);c!==null&&n>0;c=c.right)!c.deleted&&c.countable&&(n<c.length&&j(e,y(c.id.client,c.id.clock+n)),n-=c.length);for(;r>0&&c!==null;)c.deleted||(r<c.length&&j(e,y(c.id.client,c.id.clock+r)),c.delete(e),r-=c.length),c=c.right;if(r>0)throw hi();t._searchMarker&&Re(t._searchMarker,s,-o+r)},Pn=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},rs=(e,t,n,r)=>{let s=t._map.get(n)||null,o=e.doc,i=o.clientID,c;if(r==null)c=new se([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:c=new se([r]);break;case Uint8Array:c=new ze(r);break;case ee:c=new He(r);break;default:if(r instanceof I)c=new ot(r);else throw new Error("Unexpected content type")}new _(y(i,E(o.store,i)),s,s&&s.lastId,null,null,t,n,c).integrate(e,0)},ss=(e,t)=>{e.doc??v();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},fi=e=>{let t={};return e.doc??v(),e._map.forEach((n,r)=>{n.deleted||(t[r]=n.content.getContent()[n.length-1])}),t},pi=(e,t)=>{e.doc??v();let n=e._map.get(t);return n!==void 0&&!n.deleted};var Wl=(e,t)=>{let n={};return e._map.forEach((r,s)=>{let o=r;for(;o!==null&&(!t.sv.has(o.id.client)||o.id.clock>=(t.sv.get(o.id.client)||0));)o=o.left;o!==null&&Kt(o,t)&&(n[s]=o.content.getContent()[o.length-1])}),n},Tn=e=>(e.doc??v(),Ao(e._map.entries(),t=>!t[1].deleted)),zr=class extends ne{},bt=class e extends I{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(n=>n instanceof I?n.clone():n)),t}get length(){return this.doc??v(),this._length}_callObserver(t,n){super._callObserver(t,n),Yn(this,t,new zr(this,t))}insert(t,n){this.doc!==null?S(this.doc,r=>{di(r,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?S(this.doc,n=>{Jl(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?S(this.doc,r=>{ui(r,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return ai(this,t)}toArray(){return ci(this)}slice(t=0,n=this.length){return ii(this,t,n)}toJSON(){return this.map(t=>t instanceof I?t.toJSON():t)}map(t){return li(this,t)}forEach(t){ve(this,t)}[Symbol.iterator](){return Yl(this)}_write(t){t.writeTypeRef(wa)}},Xl=e=>new bt,Hr=class extends ne{constructor(t,n,r){super(t,n),this.keysChanged=r}},st=class e 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((r,s)=>{this.set(s,r)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((n,r)=>{t.set(r,n instanceof I?n.clone():n)}),t}_callObserver(t,n){Yn(this,t,new Hr(this,t,n))}toJSON(){this.doc??v();let t={};return this._map.forEach((n,r)=>{if(!n.deleted){let s=n.content.getContent()[n.length-1];t[r]=s instanceof I?s.toJSON():s}}),t}get size(){return[...Tn(this)].length}keys(){return Cn(Tn(this),t=>t[0])}values(){return Cn(Tn(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Cn(Tn(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??v(),this._map.forEach((n,r)=>{n.deleted||t(n.content.getContent()[n.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?S(this.doc,n=>{Pn(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?S(this.doc,r=>{rs(r,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return ss(this,t)}has(t){return pi(this,t)}clear(){this.doc!==null?S(this.doc,t=>{this.forEach(function(n,r,s){Pn(t,s,r)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(ya)}},Kl=e=>new st,mt=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&ur(e,t),$e=class{constructor(t,n,r,s){this.left=t,this.right=n,this.index=r,this.currentAttributes=s}forward(){this.right===null&&$(),this.right.content.constructor===N?this.right.deleted||ie(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}},jo=(e,t,n)=>{for(;t.right!==null&&n>0;)t.right.content.constructor===N?t.right.deleted||ie(t.currentAttributes,t.right.content):t.right.deleted||(n<t.right.length&&j(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},Dn=(e,t,n,r)=>{let s=new Map,o=r?qn(t,n):null;if(o){let i=new $e(o.p.left,o.p,o.index,s);return jo(e,i,n-o.index)}else{let i=new $e(null,t._start,0,s);return jo(e,i,n)}},gi=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===N&&mt(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let s=e.doc,o=s.clientID;r.forEach((i,c)=>{let l=n.left,h=n.right,a=new _(y(o,E(s.store,o)),l,l&&l.lastId,h,h&&h.id,t,null,new N(c,i));a.integrate(e,0),n.right=a,n.forward()})},ie=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},mi=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===N&&mt(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},wi=(e,t,n,r)=>{let s=e.doc,o=s.clientID,i=new Map;for(let c in r){let l=r[c],h=n.currentAttributes.get(c)??null;if(!mt(h,l)){i.set(c,h);let{left:a,right:d}=n;n.right=new _(y(o,E(s.store,o)),a,a&&a.lastId,d,d&&d.id,t,null,new N(c,l)),n.right.integrate(e,0),n.forward()}}return i},Nr=(e,t,n,r,s)=>{n.currentAttributes.forEach((u,f)=>{s[f]===void 0&&(s[f]=null)});let o=e.doc,i=o.clientID;mi(n,s);let c=wi(e,t,n,s),l=r.constructor===String?new ut(r):r instanceof I?new ot(r):new Dt(r),{left:h,right:a,index:d}=n;t._searchMarker&&Re(t._searchMarker,n.index,l.getLength()),a=new _(y(i,E(o.store,i)),h,h&&h.lastId,a,a&&a.id,t,null,l),a.integrate(e,0),n.right=a,n.index=d,n.forward(),gi(e,t,n,c)},Fo=(e,t,n,r,s)=>{let o=e.doc,i=o.clientID;mi(n,s);let c=wi(e,t,n,s);t:for(;n.right!==null&&(r>0||c.size>0&&(n.right.deleted||n.right.content.constructor===N));){if(!n.right.deleted)switch(n.right.content.constructor){case N:{let{key:l,value:h}=n.right.content,a=s[l];if(a!==void 0){if(mt(a,h))c.delete(l);else{if(r===0)break t;c.set(l,h)}n.right.delete(e)}else n.currentAttributes.set(l,h);break}default:r<n.right.length&&j(e,y(n.right.id.client,n.right.id.clock+r)),r-=n.right.length;break}n.forward()}if(r>0){let l="";for(;r>0;r--)l+=`
|
|
4
|
-
`;n.right=new _(y(
|
|
5
|
-
`?i.insert.slice(0,-1):i.insert;(typeof c!="string"||c.length>0)&&Nr(r,this,s,c,i.attributes||{})}else i.retain!==void 0?Fo(r,this,s,i.retain,i.attributes||{}):i.delete!==void 0&&Po(r,s,i.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,r){this.doc??v();let s=[],o=new Map,i=this.doc,c="",l=this._start;function h(){if(c.length>0){let d={},u=!1;o.forEach((p,w)=>{u=!0,d[w]=p});let f={insert:c};u&&(f.attributes=d),s.push(f),c=""}}let a=()=>{for(;l!==null;){if(Kt(l,t)||n!==void 0&&Kt(l,n))switch(l.content.constructor){case ut:{let d=o.get("ychange");t!==void 0&&!Kt(l,t)?(d===void 0||d.user!==l.id.client||d.type!=="removed")&&(h(),o.set("ychange",r?r("removed",l.id):{type:"removed"})):n!==void 0&&!Kt(l,n)?(d===void 0||d.user!==l.id.client||d.type!=="added")&&(h(),o.set("ychange",r?r("added",l.id):{type:"added"})):d!==void 0&&(h(),o.delete("ychange")),c+=l.content.str;break}case ot:case Dt:{h();let d={insert:l.content.getContent()[0]};if(o.size>0){let u={};d.attributes=u,o.forEach((f,p)=>{u[p]=f})}s.push(d);break}case N:Kt(l,t)&&(h(),ie(o,l.content));break}l=l.right}h()};return t||n?S(i,d=>{t&&vr(d,t),n&&vr(d,n),a()},"cleanup"):a(),s}insert(t,n,r){if(n.length<=0)return;let s=this.doc;s!==null?S(s,o=>{let i=Dn(o,this,t,!r);r||(r={},i.currentAttributes.forEach((c,l)=>{r[l]=c})),Nr(o,this,i,n,r)}):this._pending.push(()=>this.insert(t,n,r))}insertEmbed(t,n,r){let s=this.doc;s!==null?S(s,o=>{let i=Dn(o,this,t,!r);Nr(o,this,i,n,r||{})}):this._pending.push(()=>this.insertEmbed(t,n,r||{}))}delete(t,n){if(n===0)return;let r=this.doc;r!==null?S(r,s=>{Po(s,Dn(s,this,t,!0),n)}):this._pending.push(()=>this.delete(t,n))}format(t,n,r){if(n===0)return;let s=this.doc;s!==null?S(s,o=>{let i=Dn(o,this,t,!1);i.right!==null&&Fo(o,this,i,n,r)}):this._pending.push(()=>this.format(t,n,r))}removeAttribute(t){this.doc!==null?S(this.doc,n=>{Pn(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?S(this.doc,r=>{rs(r,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return ss(this,t)}getAttributes(){return fi(this)}_write(t){t.writeTypeRef(xa)}},ea=e=>new je,Ne=class{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??v()}[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===Fe||n.constructor===re)&&n._start!==null)t=n._start;else for(;t!==null;){let r=t.next;if(r!==null){t=r;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})}},re=class e extends I{constructor(){super(),this._prelimContent=[]}get firstChild(){let 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 e}clone(){let t=new e;return t.insert(0,this.toArray().map(n=>n instanceof I?n.clone():n)),t}get length(){return this.doc??v(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Ne(this,t)}querySelector(t){t=t.toUpperCase();let r=new Ne(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return r.done?null:r.value}querySelectorAll(t){return t=t.toUpperCase(),X(new Ne(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){Yn(this,t,new qr(this,n,t))}toString(){return li(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},r){let s=t.createDocumentFragment();return r!==void 0&&r._createAssociation(s,this),ve(this,o=>{s.insertBefore(o.toDOM(t,n,r),null)}),s}insert(t,n){this.doc!==null?S(this.doc,r=>{di(r,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)S(this.doc,r=>{let s=t&&t instanceof I?t._item:t;Fn(r,this,s,n)});else{let r=this._prelimContent,s=t===null?0:r.findIndex(o=>o===t)+1;if(s===0&&t!==null)throw H("Reference item not found");r.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?S(this.doc,r=>{ui(r,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return ci(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return ai(this,t)}slice(t=0,n=this.length){return ii(this,t,n)}forEach(t){ve(this,t)}_write(t){t.writeTypeRef(Sa)}},na=e=>new re,Fe=class e extends re{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach((r,s)=>{this.setAttribute(s,r)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName),n=this.getAttributes();return zs(n,(r,s)=>{t.setAttribute(s,r)}),t.insert(0,this.toArray().map(r=>r instanceof I?r.clone():r)),t}toString(){let t=this.getAttributes(),n=[],r=[];for(let c in t)r.push(c);r.sort();let s=r.length;for(let c=0;c<s;c++){let l=r[c];n.push(l+'="'+t[l]+'"')}let o=this.nodeName.toLocaleLowerCase(),i=n.length>0?" "+n.join(" "):"";return`<${o}${i}>${super.toString()}</${o}>`}removeAttribute(t){this.doc!==null?S(this.doc,n=>{Pn(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?S(this.doc,r=>{rs(r,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return ss(this,t)}hasAttribute(t){return pi(this,t)}getAttributes(t){return t?Wl(this,t):fi(this)}toDOM(t=document,n={},r){let s=t.createElement(this.nodeName),o=this.getAttributes();for(let i in o){let c=o[i];typeof c=="string"&&s.setAttribute(i,c)}return ve(this,i=>{s.appendChild(i.toDOM(t,n,r))}),r!==void 0&&r._createAssociation(s,this),s}_write(t){t.writeTypeRef(ba),t.writeKey(this.nodeName)}},ra=e=>new Fe(e.readKey()),qr=class extends ne{constructor(t,n,r){super(t,r),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}},Yr=class e extends st{constructor(t){super(),this.hookName=t}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((n,r)=>{t.set(r,n)}),t}toDOM(t=document,n={},r){let s=n[this.hookName],o;return s!==void 0?o=s.createDom(this):o=document.createElement(this.hookName),o.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(o,this),o}_write(t){t.writeTypeRef(ka),t.writeKey(this.hookName)}},sa=e=>new Yr(e.readKey()),Jr=class e extends je{get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,r){let s=t.createTextNode(this.toString());return r!==void 0&&r._createAssociation(s,this),s}toString(){return this.toDelta().map(t=>{let n=[];for(let s in t.attributes){let o=[];for(let i in t.attributes[s])o.push({key:i,value:t.attributes[s][i]});o.sort((i,c)=>i.key<c.key?-1:1),n.push({nodeName:s,attrs:o})}n.sort((s,o)=>s.nodeName<o.nodeName?-1:1);let r="";for(let s=0;s<n.length;s++){let o=n[s];r+=`<${o.nodeName}`;for(let i=0;i<o.attrs.length;i++){let c=o.attrs[i];r+=` ${c.key}="${c.value}"`}r+=">"}r+=t.insert;for(let s=n.length-1;s>=0;s--)r+=`</${n[s].nodeName}>`;return r}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(_a)}},oa=e=>new Jr,Pe=class{constructor(t,n){this.id=t,this.length=n}get deleted(){throw G()}mergeWith(t){return!1}write(t,n,r){throw G()}integrate(t,n){throw G()}},ia=0,F=class extends Pe{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),ti(t.doc.store,this)}write(t,n){t.writeInfo(ia),t.writeLen(this.length-n)}getMissing(t,n){return null}},ze=class e{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(t){throw G()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}},ca=e=>new ze(e.readBuf()),zn=class e{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){Oe(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}},la=e=>new zn(e.readLen()),xi=(e,t)=>new ee({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),He=class e{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;let 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 e(xi(this.doc.guid,this.opts))}splice(t){throw G()}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}},aa=e=>new He(xi(e.readString(),e.readAny())),Dt=class e{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(t){throw G()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}},ha=e=>new Dt(e.readJSON()),N=class e{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(t){throw G()}mergeWith(t){return!1}integrate(t,n){let r=n.parent;r._searchMarker=null,r._hasFormatting=!0}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}},da=e=>new N(e.readKey(),e.readJSON()),Wr=class e{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(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){let r=this.arr.length;t.writeLen(r-n);for(let s=n;s<r;s++){let o=this.arr[s];t.writeString(o===void 0?"undefined":JSON.stringify(o))}}getRef(){return 2}},ua=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++){let s=e.readString();s==="undefined"?n.push(void 0):n.push(JSON.parse(s))}return new Wr(n)},fa=_e("node_env")==="development",se=class e{constructor(t){this.arr=t,fa&&fr(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(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){let r=this.arr.length;t.writeLen(r-n);for(let s=n;s<r;s++){let o=this.arr[s];t.writeAny(o)}}getRef(){return 8}},pa=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new se(n)},ut=class e{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new e(this.str)}splice(t){let n=new e(this.str.slice(t));this.str=this.str.slice(0,t);let r=this.str.charCodeAt(t-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+"\uFFFD",n.str="\uFFFD"+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}},ga=e=>new ut(e.readString()),ma=[Xl,Kl,ea,ra,na,sa,oa],wa=0,ya=1,xa=2,ba=3,Sa=4,ka=5,_a=6,ot=class e{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(t){throw G()}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(r=>{r.deleted?r.id.clock<(t.beforeState.get(r.id.client)||0)&&t._mergeStructs.push(r):r.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(r=>{for(;r!==null;)r.gc(t,!0),r=r.left}),this.type._map=new Map}write(t,n){this.type._write(t)}getRef(){return 7}},Ua=e=>new ot(ma[e.readTypeRef()](e)),Xr=(e,t)=>{let n=t,r=0,s;do r>0&&(n=y(n.client,n.clock+r)),s=Zt(e,n),r=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof _);return{item:s,diff:r}},os=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Hn=(e,t,n)=>{let{client:r,clock:s}=t.id,o=new _(y(r,s+n),t,y(r,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&o.markDeleted(),t.keep&&(o.keep=!0),t.redone!==null&&(o.redone=y(t.redone.client,t.redone.clock+n)),t.right=o,o.right!==null&&(o.right.left=o),e._mergeStructs.push(o),o.parentSub!==null&&o.right===null&&o.parent._map.set(o.parentSub,o),t.length=n,o},zo=(e,t)=>ue(e,n=>Ge(n.deletions,t)),bi=(e,t,n,r,s,o)=>{let i=e.doc,c=i.store,l=i.clientID,h=t.redone;if(h!==null)return j(e,h);let a=t.parent._item,d=null,u;if(a!==null&&a.deleted===!0){if(a.redone===null&&(!n.has(a)||bi(e,a,n,r,s,o)===null))return null;for(;a.redone!==null;)a=j(e,a.redone)}let f=a===null?t.parent:a.content.type;if(t.parentSub===null){for(d=t.left,u=t;d!==null;){let b=d;for(;b!==null&&b.parent._item!==a;)b=b.redone===null?null:j(e,b.redone);if(b!==null&&b.parent._item===a){d=b;break}d=d.left}for(;u!==null;){let b=u;for(;b!==null&&b.parent._item!==a;)b=b.redone===null?null:j(e,b.redone);if(b!==null&&b.parent._item===a){u=b;break}u=u.right}}else if(u=null,t.right&&!s){for(d=t;d!==null&&d.right!==null&&(d.right.redone||Ge(r,d.right.id)||zo(o.undoStack,d.right.id)||zo(o.redoStack,d.right.id));)for(d=d.right;d.redone;)d=j(e,d.redone);if(d&&d.right!==null)return null}else d=f._map.get(t.parentSub)||null;let p=E(c,l),w=y(l,p),x=new _(w,d,d&&d.lastId,u,u&&u.id,f,t.parentSub,t.content.copy());return t.redone=w,os(x,!0),x.integrate(e,0),x},_=class e extends Pe{constructor(t,n,r,s,o,i,c,l){super(t,l.getLength()),this.origin=r,this.left=n,this.right=s,this.rightOrigin=o,this.parent=i,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?2:0}set marker(t){(this.info&8)>0!==t&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(t){this.keep!==t&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(t){this.deleted!==t&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=E(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=E(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===wt&&this.id.client!==this.parent.client&&this.parent.clock>=E(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Lo(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=j(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===F||this.right&&this.right.constructor===F)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===wt){let r=Zt(n,this.parent);r.constructor===F?this.parent=null:this.parent=r.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=Lo(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 r=this.left,s;if(r!==null)s=r.right;else 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;let o=new Set,i=new Set;for(;s!==null&&s!==this.right;){if(i.add(s),o.add(s),Qt(this.origin,s.origin)){if(s.id.client<this.id.client)r=s,o.clear();else if(Qt(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&i.has(Zt(t.doc.store,s.origin)))o.has(Zt(t.doc.store,s.origin))||(r=s,o.clear());else break;s=s.right}this.left=r}if(this.left!==null){let r=this.left.right;this.right=r,this.left.right=this}else{let r;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,this.parent._start=this;this.right=r}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),ti(t.doc.store,this),this.content.integrate(t,this),Bo(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new F(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&&Qt(t.origin,this.lastId)&&this.right===t&&Qt(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)){let n=this.parent._searchMarker;return n&&n.forEach(r=>{r.p===t&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){let n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),Oe(t.deleteSet,this.id.client,this.id.clock,this.length),Bo(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw $();this.content.gc(t),n?Bl(t,this,new F(this.id,this.length)):this.content=new zn(this.length)}write(t,n){let r=n>0?y(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,o=this.parentSub,i=this.content.getRef()&31|(r===null?0:128)|(s===null?0:64)|(o===null?0:32);if(t.writeInfo(i),r!==null&&t.writeLeftID(r),s!==null&&t.writeRightID(s),r===null&&s===null){let c=this.parent;if(c._item!==void 0){let l=c._item;if(l===null){let h=Zo(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===wt?(t.writeParentInfo(!1),t.writeLeftID(c)):$();o!==null&&t.writeString(o)}this.content.write(t,n)}},Si=(e,t)=>Ea[t&31](e),Ea=[()=>{$()},la,ua,ca,ga,ha,da,Ua,pa,aa,()=>{$()}],Aa=10,P=class extends Pe{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){$()}write(t,n){t.writeInfo(Aa),g(t.restEncoder,this.length-n)}getMissing(t,n){return null}},ki=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},_i="__ $YJS$ __";ki[_i]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");ki[_i]=!0;function Jn(e){return e.endsWith("/")?e.slice(0,-1):e}function cs(e){let t=Jn(String(e??"").trim());if(!t||t==="/")return"";if(/^[a-zA-Z][a-zA-Z\d+.-]*:/u.test(t))try{return cs(new URL(t).pathname)}catch{return""}return t.startsWith("/")?t:`/${t}`}function Ca(e,t){let n=Jn(String(e??"").trim());return!n||n==="/"?t:n.startsWith("/")?n:`/${n}`}function is(e,t){let n=cs(e),r=String(t??"").trim();return r?/^[a-zA-Z][a-zA-Z\d+.-]*:/u.test(r)||n&&(r===n||r.startsWith(`${n}/`))?r:r==="/"?n||"/":r.startsWith("/")?n?`${n}${r}`:r:n?`${n}/${r}`:`/${r}`:n||"/"}function le(){let e={auth:{enabled:!1,implemented:!0,requiresLogin:!1,sessionEndpoint:"/api/auth/session",statusEndpoint:"/api/auth/status",strategy:"none"},basePath:"",environment:"development",gitEnabled:!0,publicWsBaseUrl:"",wsBasePath:"/ws",...window.__COLLABMD_CONFIG__??{}},t=cs(e.basePath),n={enabled:!1,implemented:!0,requiresLogin:!1,sessionEndpoint:"/api/auth/session",statusEndpoint:"/api/auth/status",strategy:"none",...e.auth??{}};return{...e,auth:{...n,sessionEndpoint:is(t,n.sessionEndpoint),statusEndpoint:is(t,n.statusEndpoint)},basePath:t,wsBasePath:Ca(e.wsBasePath,"/ws")}}function ce(e="/",t=le()){return is(t.basePath,e)}function Ia(e="/",t=le()){return new URL(ce(e,t),window.location.origin).toString()}function Ta(e="/",t=le()){let n=String(e??"").trim();return!n||n==="/"?ce("/api",t):n.startsWith("/api")?ce(n,t):ce(`/api${n.startsWith("/")?n:`/${n}`}`,t)}function Da(e=le()){let n=new URLSearchParams(window.location.search).get("server");return n?Jn(n):e.publicWsBaseUrl?Jn(e.publicWsBaseUrl):`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}${ce(e.wsBasePath,e)}`}var Va=["Alice","Bob","Charlie","Dana","Eve","Frank","Grace","Hank","Iris","Jack","Kim","Leo","Maya","Nate","Olivia","Pete","Quinn","Ruby","Sam","Tara"],Na=["#ef4444","#f97316","#eab308","#22c55e","#06b6d4","#3b82f6","#8b5cf6","#ec4899","#14b8a6","#f59e0b","#6366f1","#10b981","#f43f5e","#0ea5e9","#a855f7"];var Ei="collabmd-user-id";function Ai(e){return e[Math.floor(Math.random()*e.length)]}function Ci(){let e=new Uint8Array(8);return(globalThis.crypto??{}).getRandomValues?.(e),Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}function La(){return globalThis.crypto?.randomUUID?globalThis.crypto.randomUUID():`${Ci()}-${Date.now().toString(36)}`}var ls=null,ae=null;function Oa(){return ls||(ls=Ci()),ls}function Ba(e=globalThis.localStorage){if(ae)return ae;try{let t=e?.getItem?.(Ei);if(t)return ae=t,t}catch{}ae=La();try{e?.setItem?.(Ei,ae)}catch{}return ae}function Ma(e){return String(e??"").trim().replace(/\s+/g," ").slice(0,24)||null}function ld(e=null){let t=Ai(Na);return{color:t,colorLight:`${t}33`,name:Ma(e)??Ai(Va),peerId:Oa(),userId:Ba()}}var Ii=new Map,as=class{constructor(t){this.room=t,this.onmessage=null,this._onChange=n=>n.key===t&&this.onmessage!==null&&this.onmessage({data:to(n.newValue||"")}),vs(this._onChange)}postMessage(t){ln.setItem(this.room,Zs(Qs(t)))}close(){$s(this._onChange)}},Ra=typeof BroadcastChannel>"u"?as:BroadcastChannel,hs=e=>z(Ii,e,()=>{let t=J(),n=new Ra(e);return n.onmessage=r=>t.forEach(s=>s(r.data,"broadcastchannel")),{bc:n,subs:t}}),Ti=(e,t)=>(hs(e).subs.add(t),t),Di=(e,t)=>{let n=hs(e),r=n.subs.delete(t);return r&&n.subs.size===0&&(n.bc.close(),Ii.delete(e)),r},Vt=(e,t,n=null)=>{let r=hs(e);r.bc.postMessage(t),r.subs.forEach(s=>s(t,n))};var Vi=0,Wn=1,Ni=2,Xn=(e,t)=>{g(e,Vi);let n=Ko(t);U(e,n)},ds=(e,t,n)=>{g(e,Wn),U(e,Jo(t,n))},$a=(e,t,n)=>ds(t,n,D(e)),Li=(e,t,n,r)=>{try{Yo(t,D(e),n)}catch(s){r?.(s),console.error("Caught error while handling a Yjs update",s)}},Oi=(e,t)=>{g(e,Ni),U(e,t)},ja=Li,Bi=(e,t,n,r,s)=>{let o=m(e);switch(o){case Vi:$a(e,t,n);break;case Wn:Li(e,n,r,s);break;case Ni:ja(e,n,r,s);break;default:throw new Error("Unknown message type")}return o};var Pa=0;var Mi=(e,t,n)=>{m(e)===Pa&&n(t,K(e))};var us=3e4,Kn=class extends Ke{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let n=q();this.getLocalState()!==null&&us/2<=n-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((s,o)=>{o!==this.clientID&&us<=n-s.lastUpdated&&this.states.has(o)&&r.push(o)}),r.length>0&&Qn(this,r,"timeout")},B(us/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){let n=this.clientID,r=this.meta.get(n),s=r===void 0?0:r.clock+1,o=this.states.get(n);t===null?this.states.delete(n):this.states.set(n,t),this.meta.set(n,{clock:s,lastUpdated:q()});let i=[],c=[],l=[],h=[];t===null?h.push(n):o==null?t!=null&&i.push(n):(c.push(n),pt(o,t)||l.push(n)),(i.length>0||l.length>0||h.length>0)&&this.emit("change",[{added:i,updated:l,removed:h},"local"]),this.emit("update",[{added:i,updated:c,removed:h},"local"])}setLocalStateField(t,n){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[t]:n})}getStates(){return this.states}},Qn=(e,t,n)=>{let r=[];for(let s=0;s<t.length;s++){let o=t[s];if(e.states.has(o)){if(e.states.delete(o),o===e.clientID){let i=e.meta.get(o);e.meta.set(o,{clock:i.clock+1,lastUpdated:q()})}r.push(o)}}r.length>0&&(e.emit("change",[{added:[],updated:[],removed:r},n]),e.emit("update",[{added:[],updated:[],removed:r},n]))},he=(e,t,n=e.states)=>{let r=t.length,s=T();g(s,r);for(let o=0;o<r;o++){let i=t[o],c=n.get(i)||null,l=e.meta.get(i).clock;g(s,i),g(s,l),at(s,JSON.stringify(c))}return k(s)};var Ri=(e,t,n)=>{let r=Q(t),s=q(),o=[],i=[],c=[],l=[],h=m(r);for(let a=0;a<h;a++){let d=m(r),u=m(r),f=JSON.parse(K(r)),p=e.meta.get(d),w=e.states.get(d),x=p===void 0?0:p.clock;(x<u||x===u&&f===null&&e.states.has(d))&&(f===null?d===e.clientID&&e.getLocalState()!=null?u++:e.states.delete(d):e.states.set(d,f),e.meta.set(d,{clock:u,lastUpdated:s}),p===void 0&&f!==null?o.push(d):p!==void 0&&f===null?l.push(d):f!==null&&(pt(f,w)||c.push(d),i.push(d)))}(o.length>0||c.length>0||l.length>0)&&e.emit("change",[{added:o,updated:c,removed:l},n]),(o.length>0||i.length>0||l.length>0)&&e.emit("update",[{added:o,updated:i,removed:l},n])};var vi=e=>Hs(e,(t,n)=>`${encodeURIComponent(n)}=${encodeURIComponent(t)}`).join("&");var Nt=0,Fi=3,de=1,qa=2,qe=[];qe[Nt]=(e,t,n,r,s)=>{g(e,Nt);let o=Bi(t,e,n.doc,n);r&&o===Wn&&!n.synced&&(n.synced=!0)};qe[Fi]=(e,t,n,r,s)=>{g(e,de),U(e,he(n.awareness,Array.from(n.awareness.getStates().keys())))};qe[de]=(e,t,n,r,s)=>{Ri(n.awareness,D(t),n)};qe[qa]=(e,t,n,r,s)=>{Mi(t,n.doc,(o,i)=>Ya(n,i))};var $i=3e4,Ya=(e,t)=>console.warn(`Permission denied to access ${e.url}.
|
|
6
|
-
${t}`),
|
|
1
|
+
var L=()=>new Map,Ye=e=>{let t=L();return e.forEach((n,r)=>{t.set(r,n)}),t},z=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},bs=(e,t)=>{let n=[];for(let[r,s]of e)n.push(t(s,r));return n},Ss=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1};var J=()=>new Set;var We=e=>e[e.length-1];var ks=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},X=Array.from,Xe=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},ue=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1};var _s=(e,t)=>{let n=new Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n};var ct=Array.isArray;var St=class{constructor(){this._observers=L()}on(t,n){return z(this._observers,t,J).add(n),n}once(t,n){let r=(...s)=>{this.off(t,r),n(...s)};this.on(t,r)}off(t,n){let r=this._observers.get(t);r!==void 0&&(r.delete(n),r.size===0&&this._observers.delete(t))}emit(t,n){return X((this._observers.get(t)||L()).values()).forEach(r=>r(...n))}destroy(){this._observers=L()}},Ke=class{constructor(){this._observers=L()}on(t,n){z(this._observers,t,J).add(n)}once(t,n){let r=(...s)=>{this.off(t,r),n(...s)};this.on(t,r)}off(t,n){let r=this._observers.get(t);r!==void 0&&(r.delete(n),r.size===0&&this._observers.delete(t))}emit(t,n){return X((this._observers.get(t)||L()).values()).forEach(r=>r(...n))}destroy(){this._observers=L()}};var B=Math.floor;var kt=Math.abs;var Ot=(e,t)=>e<t?e:t,lt=(e,t)=>e>t?e:t,fh=Number.isNaN,Us=Math.pow;var Qe=e=>e!==0?e<0:1/e<0;var Bt=Number.MAX_SAFE_INTEGER,tr=Number.MIN_SAFE_INTEGER,ph=1<<31;var Es=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&B(e)===e),gh=Number.isNaN,mh=Number.parseInt;var pe=String.fromCharCode,Yo=String.fromCodePoint,wh=pe(65535),Jo=e=>e.toLowerCase(),Wo=/^\s*/g,Xo=e=>e.replace(Wo,""),Ko=/([A-Z])/g,nr=(e,t)=>Xo(e.replace(Ko,n=>`${t}${Jo(n)}`));var Qo=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let s=0;s<n;s++)r[s]=t.codePointAt(s);return r},vt=typeof TextEncoder<"u"?new TextEncoder:null,Zo=e=>vt.encode(e),As=vt?Zo:Qo;var Mt=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Mt&&Mt.decode(new Uint8Array).length===1&&(Mt=null);var Cs=(e,t)=>_s(t,()=>e).join("");var Ut=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},T=()=>new Ut;var tn=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t};var k=e=>{let t=new Uint8Array(tn(e)),n=0;for(let r=0;r<e.bufs.length;r++){let s=e.bufs[r];t.set(s,n),n+=s.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},tc=(e,t)=>{let n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(lt(n,t)*2),e.cpos=0)},O=(e,t)=>{let 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};var en=O;var g=(e,t)=>{for(;t>127;)O(e,128|127&t),t=B(t/128);O(e,127&t)},nn=(e,t)=>{let n=Qe(t);for(n&&(t=-t),O(e,(t>63?128:0)|(n?64:0)|63&t),t=B(t/64);t>0;)O(e,(t>127?128:0)|127&t),t=B(t/128)},rr=new Uint8Array(3e4),ec=rr.length/3,nc=(e,t)=>{if(t.length<ec){let n=vt.encodeInto(t,rr).written||0;g(e,n);for(let r=0;r<n;r++)O(e,rr[r])}else U(e,As(t))},rc=(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;g(e,r);for(let s=0;s<r;s++)O(e,n.codePointAt(s))},at=vt&&vt.encodeInto?nc:rc;var we=(e,t)=>{let n=e.cbuf.length,r=e.cpos,s=Ot(n-r,t.length),i=t.length-s;e.cbuf.set(t.subarray(0,s),r),e.cpos+=s,i>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(lt(n*2,i)),e.cbuf.set(t.subarray(s)),e.cpos=i)},U=(e,t)=>{g(e,t.byteLength),we(e,t)},sr=(e,t)=>{tc(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},sc=(e,t)=>sr(e,4).setFloat32(0,t,!1),ic=(e,t)=>sr(e,8).setFloat64(0,t,!1),oc=(e,t)=>sr(e,8).setBigInt64(0,t,!1);var Ts=new DataView(new ArrayBuffer(4)),cc=e=>(Ts.setFloat32(0,e),Ts.getFloat32(0)===e),$t=(e,t)=>{switch(typeof t){case"string":O(e,119),at(e,t);break;case"number":Es(t)&&kt(t)<=2147483647?(O(e,125),nn(e,t)):cc(t)?(O(e,124),sc(e,t)):(O(e,123),ic(e,t));break;case"bigint":O(e,122),oc(e,t);break;case"object":if(t===null)O(e,126);else if(ct(t)){O(e,117),g(e,t.length);for(let n=0;n<t.length;n++)$t(e,t[n])}else if(t instanceof Uint8Array)O(e,116),U(e,t);else{O(e,118);let n=Object.keys(t);g(e,n.length);for(let r=0;r<n.length;r++){let s=n[r];at(e,s),$t(e,t[s])}}break;case"boolean":O(e,t?120:121);break;default:O(e,127)}},me=class extends Ut{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&g(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}};var Ds=e=>{e.count>0&&(nn(e.encoder,e.count===1?e.s:-e.s),e.count>1&&g(e.encoder,e.count-2))},Et=class{constructor(){this.encoder=new Ut,this.s=0,this.count=0}write(t){this.s===t?this.count++:(Ds(this),this.count=1,this.s=t)}toUint8Array(){return Ds(this),k(this.encoder)}};var Vs=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);nn(e.encoder,t),e.count>1&&g(e.encoder,e.count-2)}},Ft=class{constructor(){this.encoder=new Ut,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(Vs(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return Vs(this),k(this.encoder)}},Ze=class{constructor(){this.sarr=[],this.s="",this.lensE=new Et}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){let t=new Ut;return this.sarr.push(this.s),this.s="",at(t,this.sarr.join("")),we(t,this.lensE.toUint8Array()),k(t)}};var H=e=>new Error(e),G=()=>{throw H("Method unimplemented")},$=()=>{throw H("Unexpected case")};var Ns=H("Unexpected end of array"),Ls=H("Integer out of Range"),jt=class{constructor(t){this.arr=t,this.pos=0}},Q=e=>new jt(e),Os=e=>e.pos!==e.arr.length;var lc=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},D=e=>lc(e,m(e));var At=e=>e.arr[e.pos++];var m=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let s=e.arr[e.pos++];if(t=t+(s&127)*n,n*=128,s<128)return t;if(t>Bt)throw Ls}throw Ns},on=e=>{let t=e.arr[e.pos++],n=t&63,r=64,s=(t&64)>0?-1:1;if((t&128)===0)return s*n;let i=e.arr.length;for(;e.pos<i;){if(t=e.arr[e.pos++],n=n+(t&127)*r,r*=128,t<128)return s*n;if(n>Bt)throw Ls}throw Ns};var ac=e=>{let t=m(e);if(t===0)return"";{let n=String.fromCodePoint(At(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(At(e));else for(;t>0;){let r=t<1e4?t:1e4,s=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,s),t-=r}return decodeURIComponent(escape(n))}},hc=e=>Mt.decode(D(e)),K=Mt?hc:ac;var or=(e,t)=>{let n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},dc=e=>or(e,4).getFloat32(0,!1),uc=e=>or(e,8).getFloat64(0,!1),fc=e=>or(e,8).getBigInt64(0,!1);var pc=[e=>{},e=>null,on,dc,uc,fc,e=>!1,e=>!0,K,e=>{let t=m(e),n={};for(let r=0;r<t;r++){let s=K(e);n[s]=Pt(e)}return n},e=>{let t=m(e),n=[];for(let r=0;r<t;r++)n.push(Pt(e));return n},D],Pt=e=>pc[127-At(e)](e),ye=class extends jt{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Os(this)?this.count=m(this)+1:this.count=-1),this.count--,this.s}};var Ct=class extends jt{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=on(this);let t=Qe(this.s);this.count=1,t&&(this.s=-this.s,this.count=m(this)+2)}return this.count--,this.s}};var zt=class extends jt{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let t=on(this),n=t&1;this.diff=B(t/2),this.count=1,n&&(this.count=m(this)+2)}return this.s+=this.diff,this.count--,this.s}},sn=class{constructor(t){this.decoder=new Ct(t),this.str=K(this.decoder),this.spos=0}read(){let t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}};var bh=crypto.subtle,Bs=crypto.getRandomValues.bind(crypto);var cr=()=>Bs(new Uint32Array(1))[0];var gc="10000000-1000-4000-8000"+-1e11,Ms=()=>gc.replace(/[018]/g,e=>(e^cr()&15>>e/4).toString(16));var q=Date.now;var lr=e=>new Promise(e);var _h=Promise.all.bind(Promise);var ar=e=>e===void 0?null:e;var hr=class{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}},vs=new hr,dr=!0;try{typeof localStorage<"u"&&localStorage&&(vs=localStorage,dr=!1)}catch{}var ln=vs,Rs=e=>dr||addEventListener("storage",e),$s=e=>dr||removeEventListener("storage",e);var It=Symbol("Equality"),an=(e,t)=>e===t||!!e?.[It]?.(t)||!1;var js=e=>typeof e=="object",Ps=Object.assign,xc=Object.keys;var zs=(e,t)=>{for(let n in e)t(e[n],n)},Hs=(e,t)=>{let n=[];for(let r in e)n.push(t(e[r],r));return n};var be=e=>xc(e).length;var Gs=e=>{for(let t in e)return!1;return!0},Ht=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Se=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),fr=(e,t)=>e===t||be(e)===be(t)&&Ht(e,(n,r)=>(n!==void 0||Se(t,r))&&an(t[r],n)),bc=Object.freeze,pr=e=>{for(let t in e){let n=e[t];(typeof n=="object"||typeof n=="function")&&pr(e[t])}return bc(e)};var ke=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&ke(e,t,n+1)}};var qs=e=>e;var pt=(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[It]!=null)return e[It](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(let n of e)if(!t.has(n))return!1;break}case Map:{if(e.size!==t.size)return!1;for(let n of e.keys())if(!t.has(n)||!pt(e.get(n),t.get(n)))return!1;break}case void 0:case Object:if(be(e)!==be(t))return!1;for(let n in e)if(!Se(e,n)||!pt(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(!pt(e[n],t[n]))return!1;break;default:return!1}return!0},Ys=(e,t)=>t.includes(e);var ht=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",un=typeof window<"u"&&typeof document<"u"&&!ht,Uh=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,Z,Sc=[],kc=()=>{if(Z===void 0)if(ht){Z=L();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]==="-"?(t!==null&&Z.set(t,""),t=r):t!==null?(Z.set(t,r),t=null):Sc.push(r)}t!==null&&Z.set(t,"")}else typeof location=="object"?(Z=L(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){let[t,n]=e.split("=");Z.set(`--${nr(t,"-")}`,n),Z.set(`-${nr(t,"-")}`,n)}})):Z=L();return Z},gr=e=>kc().has(e);var _e=e=>ht?ar(process.env[e.toUpperCase().replaceAll("-","_")]):ar(ln.getItem(e));var Js=e=>gr("--"+e)||_e(e)!==null,Ws=Js("production"),_c=ht&&Ys(process.env.FORCE_COLOR,["true","1","2"]),Xs=_c||!gr("--no-colors")&&!Js("no-color")&&(!ht||process.stdout.isTTY)&&(!ht||gr("--color")||_e("COLORTERM")!==null||(_e("TERM")||"").includes("color"));var Ks=e=>new Uint8Array(e),Uc=(e,t,n)=>new Uint8Array(e,t,n),Qs=e=>new Uint8Array(e),Ec=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=pe(e[n]);return btoa(t)},Ac=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),Cc=e=>{let t=atob(e),n=Ks(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n},Ic=e=>{let t=Buffer.from(e,"base64");return Uc(t.buffer,t.byteOffset,t.byteLength)},Zs=un?Ec:Ac,ti=un?Cc:Ic;var ei=e=>{let t=Ks(e.byteLength);return t.set(e),t};var mr=class{constructor(t,n){this.left=t,this.right=n}},tt=(e,t)=>new mr(e,t);var ri=(e,t)=>e.forEach(n=>t(n.left,n.right));var wr=e=>e.next()>=.5,fn=(e,t,n)=>B(e.next()*(n+1-t)+t);var yr=(e,t,n)=>B(e.next()*(n+1-t)+t);var xr=(e,t,n)=>yr(e,t,n);var Tc=e=>pe(xr(e,97,122)),ii=(e,t=0,n=20)=>{let r=xr(e,t,n),s="";for(let i=0;i<r;i++)s+=Tc(e);return s};var pn=(e,t)=>t[xr(e,0,t.length-1)];var Vc=Symbol("0schema"),br=class{constructor(){this._rerrs=[]}extend(t,n,r,s=null){this._rerrs.push({path:t,expected:n,has:r,message:s})}toString(){let t=[];for(let n=this._rerrs.length-1;n>0;n--){let r=this._rerrs[n];t.push(Cs(" ",(this._rerrs.length-n)*2)+`${r.path!=null?`[${r.path}] `:""}${r.has} doesn't match ${r.expected}. ${r.message}`)}return t.join(`
|
|
2
|
+
`)}},Sr=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[It]?an(e,t):ct(e)?Xe(e,n=>ue(t,r=>Sr(n,r))):js(e)?Ht(e,(n,r)=>Sr(n,t[r])):!1,M=class{static _dilutes=!1;extends(t){let[n,r]=[this.shape,t.shape];return this.constructor._dilutes&&([r,n]=[n,r]),Sr(n,r)}equals(t){return this.constructor===t.constructor&&pt(this.shape,t.shape)}[Vc](){return!0}[It](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){G()}get nullable(){return Wt(this,An)}get optional(){return new gn(this)}cast(t){return oi(t,this),t}expect(t){return oi(t,this),t}},Ee=class extends M{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n=void 0){let r=t?.constructor===this.shape&&(this._c==null||this._c(t));return!r&&n?.extend(null,this.shape.name,t?.constructor.name,t?.constructor!==this.shape?"Constructor match failed":"Check failed"),r}},C=(e,t=null)=>new Ee(e,t),Ah=C(Ee),Ae=class extends M{constructor(t){super(),this.shape=t}check(t,n){let r=this.shape(t);return!r&&n?.extend(null,"custom prop",t?.constructor.name,"failed to check custom prop"),r}},V=e=>new Ae(e),Ch=C(Ae),Yt=class extends M{constructor(t){super(),this.shape=t}check(t,n){let r=this.shape.some(s=>s===t);return!r&&n?.extend(null,this.shape.join(" | "),t.toString()),r}},Un=(...e)=>new Yt(e),ci=C(Yt),Nc=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,t=>"\\"+t)),li=e=>{if(Jt.check(e))return[Nc(e)];if(ci.check(e))return e.shape.map(t=>t+"");if(fi.check(e))return["[+-]?\\d+.?\\d*"];if(pi.check(e))return[".*"];if(kn.check(e))return e.shape.map(li).flat(1);$()},kr=class extends M{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(li).map(n=>`(${n.join("|")})`).join("")+"$")}check(t,n){let r=this._r.exec(t)!=null;return!r&&n?.extend(null,this._r.toString(),t.toString(),"String doesn't match string template."),r}};var Ih=C(kr),Lc=Symbol("optional"),gn=class extends M{constructor(t){super(),this.shape=t}check(t,n){let r=t===void 0||this.shape.check(t);return!r&&n?.extend(null,"undefined (optional)","()"),r}get[Lc](){return!0}},Oc=C(gn),mn=class extends M{check(t,n){return n?.extend(null,"never",typeof t),!1}},Th=new mn,Dh=C(mn),wn=class e extends M{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}static _dilutes=!0;get partial(){return new e(this.shape,!0)}check(t,n){return t==null?(n?.extend(null,"object","null"),!1):Ht(this.shape,(r,s)=>{let i=this._isPartial&&!Se(t,s)||r.check(t[s],n);return!i&&n?.extend(s.toString(),r.toString(),typeof t[s],"Object property does not match"),i})}},Bc=e=>new wn(e),Mc=C(wn),vc=V(e=>e!=null&&(e.constructor===Object||e.constructor==null)),yn=class extends M{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return t!=null&&Ht(t,(r,s)=>{let i=this.shape.keys.check(s,n);return!i&&n?.extend(s+"","Record",typeof t,i?"Key doesn't match schema":"Value doesn't match value"),i&&this.shape.values.check(r,n)})}},ai=(e,t)=>new yn(e,t),Rc=C(yn),xn=class extends M{constructor(t){super(),this.shape=t}check(t,n){return t!=null&&Ht(this.shape,(r,s)=>{let i=r.check(t[s],n);return!i&&n?.extend(s.toString(),"Tuple",typeof r),i})}},$c=(...e)=>new xn(e),Vh=C(xn),bn=class extends M{constructor(t){super(),this.shape=t.length===1?t[0]:new Ce(t)}check(t,n){let r=ct(t)&&Xe(t,s=>this.shape.check(s));return!r&&n?.extend(null,"Array",""),r}},hi=(...e)=>new bn(e),Fc=C(bn),jc=V(e=>ct(e)),Sn=class extends M{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n){let r=t instanceof this.shape&&(this._c==null||this._c(t));return!r&&n?.extend(null,this.shape.name,t?.constructor.name),r}},Pc=(e,t=null)=>new Sn(e,t),Nh=C(Sn),zc=Pc(M),_r=class extends M{constructor(t){super(),this.len=t.length-1,this.args=$c(...t.slice(-1)),this.res=t[this.len]}check(t,n){let r=t.constructor===Function&&t.length<=this.len;return!r&&n?.extend(null,"function",typeof t),r}};var Hc=C(_r),Gc=V(e=>typeof e=="function"),Ur=class extends M{constructor(t){super(),this.shape=t}check(t,n){let r=Xe(this.shape,s=>s.check(t,n));return!r&&n?.extend(null,"Intersectinon",typeof t),r}};var Lh=C(Ur,e=>e.shape.length>0),Ce=class extends M{static _dilutes=!0;constructor(t){super(),this.shape=t}check(t,n){let r=ue(this.shape,s=>s.check(t,n));return n?.extend(null,"Union",typeof t),r}},Wt=(...e)=>e.findIndex(t=>kn.check(t))>=0?Wt(...e.map(t=>Ie(t)).map(t=>kn.check(t)?t.shape:[t]).flat(1)):e.length===1?e[0]:new Ce(e),kn=C(Ce),di=()=>!0,_n=V(di),qc=C(Ae,e=>e.shape===di),Ar=V(e=>typeof e=="bigint"),Yc=V(e=>e===Ar),ui=V(e=>typeof e=="symbol"),Oh=V(e=>e===ui),qt=V(e=>typeof e=="number"),fi=V(e=>e===qt),Jt=V(e=>typeof e=="string"),pi=V(e=>e===Jt),En=V(e=>typeof e=="boolean"),Jc=V(e=>e===En),gi=Un(void 0),Bh=C(Yt,e=>e.shape.length===1&&e.shape[0]===void 0),Mh=Un(void 0);var An=Un(null),Wc=C(Yt,e=>e.shape.length===1&&e.shape[0]===null),vh=C(Uint8Array),Rh=C(Ee,e=>e.shape===Uint8Array),Xc=Wt(qt,Jt,An,gi,Ar,En,ui),$h=(()=>{let e=hi(_n),t=ai(Jt,_n),n=Wt(qt,Jt,An,En,e,t);return e.shape=n,t.shape.values=n,n})(),Ie=e=>{if(zc.check(e))return e;if(vc.check(e)){let t={};for(let n in e)t[n]=Ie(e[n]);return Bc(t)}else{if(jc.check(e))return Wt(...e.map(Ie));if(Xc.check(e))return Un(e);if(Gc.check(e))return C(e)}$()},oi=Ws?()=>{}:(e,t)=>{let n=new br;if(!t.check(e,n))throw H(`Expected value to be of type ${t.constructor.name}.
|
|
3
|
+
${n.toString()}`)},Er=class{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:Ie(t),h:n}),this}else(t){return this.if(_n,t)}done(){return(t,n)=>{for(let r=0;r<this.patterns.length;r++){let s=this.patterns[r];if(s.if.check(t))return s.h(t,n)}throw H("Unhandled pattern")}}},Kc=e=>new Er(e),mi=Kc(_n).if(fi,(e,t)=>fn(t,tr,Bt)).if(pi,(e,t)=>ii(t)).if(Jc,(e,t)=>wr(t)).if(Yc,(e,t)=>BigInt(fn(t,tr,Bt))).if(kn,(e,t)=>Gt(t,pn(t,e.shape))).if(Mc,(e,t)=>{let n={};for(let r in e.shape){let s=e.shape[r];if(Oc.check(s)){if(wr(t))continue;s=s.shape}n[r]=mi(s,t)}return n}).if(Fc,(e,t)=>{let n=[],r=yr(t,0,42);for(let s=0;s<r;s++)n.push(Gt(t,e.shape));return n}).if(ci,(e,t)=>pn(t,e.shape)).if(Wc,(e,t)=>null).if(Hc,(e,t)=>{let n=Gt(t,e.res);return()=>n}).if(qc,(e,t)=>Gt(t,pn(t,[qt,Jt,An,gi,Ar,En,hi(qt),ai(Wt("a","b","c"),qt)]))).if(Rc,(e,t)=>{let n={},r=fn(t,0,3);for(let s=0;s<r;s++){let i=Gt(t,e.shape.keys),o=Gt(t,e.shape.values);n[i]=o}return n}).done(),Gt=(e,t)=>mi(Ie(t),e);var et=typeof document<"u"?document:{},Zc=e=>et.createElement(e),tl=()=>et.createDocumentFragment(),Fh=V(e=>e.nodeType===al),el=e=>et.createTextNode(e),jh=typeof DOMParser<"u"?new DOMParser:null;var nl=(e,t)=>(ri(t,(n,r)=>{r===!1?e.removeAttribute(n):r===!0?e.setAttribute(n,""):e.setAttribute(n,r)}),e);var rl=e=>{let t=tl();for(let n=0;n<e.length;n++)xi(t,e[n]);return t},wi=(e,t)=>(xi(e,rl(t)),e);var sl=(e,t=[],n=[])=>wi(nl(Zc(e),t),n),Ph=V(e=>e.nodeType===ol);var il=el,zh=V(e=>e.nodeType===cl);var yi=e=>bs(e,(t,n)=>`${n}:${t};`).join("");var xi=(e,t)=>e.appendChild(t),ol=et.ELEMENT_NODE,cl=et.TEXT_NODE,Hh=et.CDATA_SECTION_NODE,Gh=et.COMMENT_NODE,ll=et.DOCUMENT_NODE,qh=et.DOCUMENT_TYPE_NODE,al=et.DOCUMENT_FRAGMENT_NODE,Yh=V(e=>e.nodeType===ll);var nt=Symbol;var Te=nt(),De=nt(),Cr=nt(),Ir=nt(),Tr=nt(),Ve=nt(),Dr=nt(),Xt=nt(),Vr=nt(),bi=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r<e.length;r++){let s=e[r];if(s===void 0)break;if(s.constructor===String||s.constructor===Number)t.push(s);else if(s.constructor===Object)break}for(r>0&&n.push(t.join(""));r<e.length;r++){let s=e[r];s instanceof Symbol||n.push(s)}return n};var Jh=q();var fl={[Te]:tt("font-weight","bold"),[De]:tt("font-weight","normal"),[Cr]:tt("color","blue"),[Tr]:tt("color","green"),[Ir]:tt("color","grey"),[Ve]:tt("color","red"),[Dr]:tt("color","purple"),[Xt]:tt("color","orange"),[Vr]:tt("color","black")},pl=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=L(),s=[],i=0;for(;i<e.length;i++){let o=e[i],c=fl[o];if(c!==void 0)r.set(c.left,c.right);else{if(o===void 0)break;if(o.constructor===String||o.constructor===Number){let l=yi(r);i>0||l.length>0?(t.push("%c"+o),n.push(l)):t.push(o)}else break}}for(i>0&&(s=n,s.unshift(t.join("")));i<e.length;i++){let o=e[i];o instanceof Symbol||s.push(o)}return s},Si=Xs?pl:bi,ki=(...e)=>{console.log(...Si(e)),_i.forEach(t=>t.print(e))},Nr=(...e)=>{console.warn(...Si(e)),e.unshift(Xt),_i.forEach(t=>t.print(e))};var _i=J();var Ui=e=>({[Symbol.iterator](){return this},next:e}),Ei=(e,t)=>Ui(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),Cn=(e,t)=>Ui(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}});var Le=class{constructor(t,n){this.clock=t,this.len=n}},yt=class{constructor(){this.clients=new Map}},te=(e,t,n)=>t.clients.forEach((r,s)=>{let i=e.doc.store.clients.get(s);if(i!=null){let o=i[i.length-1],c=o.id.clock+o.length;for(let l=0,h=r[l];l<r.length&&h.clock<c;h=r[++l])to(e,i,h.clock,h.len,n)}}),xl=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let s=B((n+r)/2),i=e[s],o=i.clock;if(o<=t){if(t<o+i.len)return s;n=s+1}else r=s-1}return null},Ge=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&xl(n,t.clock)!==null},Zr=e=>{e.clients.forEach(t=>{t.sort((s,i)=>s.clock-i.clock);let n,r;for(n=1,r=1;n<t.length;n++){let s=t[r-1],i=t[n];s.clock+s.len>=i.clock?s.len=lt(s.len,i.clock+i.len-s.clock):(r<n&&(t[r]=i),r++)}t.length=r})},Or=e=>{let t=new yt;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,s)=>{if(!t.clients.has(s)){let i=r.slice();for(let o=n+1;o<e.length;o++)ks(i,e[o].clients.get(s)||[]);t.clients.set(s,i)}});return Zr(t),t},Oe=(e,t,n,r)=>{z(e.clients,t,()=>[]).push(new Le(n,r))},zi=()=>new yt,bl=e=>{let t=zi();return e.clients.forEach((n,r)=>{let s=[];for(let i=0;i<n.length;i++){let o=n[i];if(o.deleted){let c=o.id.clock,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;s.push(new Le(c,l))}}s.length>0&&t.clients.set(r,s)}),t},ie=(e,t)=>{g(e.restEncoder,t.clients.size),X(t.clients.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{e.resetDsCurVal(),g(e.restEncoder,n);let s=r.length;g(e.restEncoder,s);for(let i=0;i<s;i++){let o=r[i];e.writeDsClock(o.clock),e.writeDsLen(o.len)}})},ts=e=>{let t=new yt,n=m(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();let s=m(e.restDecoder),i=m(e.restDecoder);if(i>0){let o=z(t.clients,s,()=>[]);for(let c=0;c<i;c++)o.push(new Le(e.readDsClock(),e.readDsLen()))}}return t},Ii=(e,t,n)=>{let r=new yt,s=m(e.restDecoder);for(let i=0;i<s;i++){e.resetDsCurVal();let o=m(e.restDecoder),c=m(e.restDecoder),l=n.clients.get(o)||[],h=E(n,o);for(let a=0;a<c;a++){let d=e.readDsClock(),u=d+e.readDsLen();if(d<h){h<u&&Oe(r,o,h,u-h);let f=rt(l,d),p=l[f];for(!p.deleted&&p.id.clock<d&&(l.splice(f+1,0,Hn(t,p,d-p.id.clock)),f++);f<l.length&&(p=l[f++],p.id.clock<u);)p.deleted||(u<p.id.clock+p.length&&l.splice(f,0,Hn(t,p,u-p.id.clock)),p.delete(t))}else Oe(r,o,d,u-d)}}if(r.clients.size>0){let i=new dt;return g(i.restEncoder,0),ie(i,r),i.toUint8Array()}return null};var Hi=cr,ee=class e extends St{constructor({guid:t=Ms(),collectionid:n=null,gc:r=!0,gcFilter:s=()=>!0,meta:i=null,autoLoad:o=!1,shouldLoad:c=!0}={}){super(),this.gc=r,this.gcFilter=s,this.clientID=Hi(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new $n,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=lr(h=>{this.on("load",()=>{this.isLoaded=!0,h(this)})});let l=()=>lr(h=>{let a=d=>{(d===void 0||d===!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(){let t=this._item;t!==null&&!this.shouldLoad&&S(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 S(this,t,n)}get(t,n=I){let r=z(this.share,t,()=>{let i=new n;return i._integrate(this,null),i}),s=r.constructor;if(n!==I&&s!==n)if(s===I){let i=new n;i._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=i}),i._start=r._start;for(let o=i._start;o!==null;o=o.right)o.parent=i;return i._length=r._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 r}getArray(t=""){return this.get(t,bt)}getText(t=""){return this.get(t,Fe)}getMap(t=""){return this.get(t,st)}getXmlElement(t=""){return this.get(t,je)}getXmlFragment(t=""){return this.get(t,re)}toJSON(){let t={};return this.share.forEach((n,r)=>{t[r]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,X(this.subdocs).forEach(n=>n.destroy());let t=this._item;if(t!==null){this._item=null;let n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,S(t.parent.doc,r=>{let s=n.doc;t.deleted||r.subdocsAdded.add(s),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}},Ln=class{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return m(this.restDecoder)}readDsLen(){return m(this.restDecoder)}},On=class extends Ln{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 At(this.restDecoder)}readString(){return K(this.restDecoder)}readParentInfo(){return m(this.restDecoder)===1}readTypeRef(){return m(this.restDecoder)}readLen(){return m(this.restDecoder)}readAny(){return Pt(this.restDecoder)}readBuf(){return ei(D(this.restDecoder))}readJSON(){return JSON.parse(K(this.restDecoder))}readKey(){return K(this.restDecoder)}},Br=class{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=m(this.restDecoder),this.dsCurrVal}readDsLen(){let t=m(this.restDecoder)+1;return this.dsCurrVal+=t,t}},xt=class extends Br{constructor(t){super(t),this.keys=[],m(t),this.keyClockDecoder=new zt(D(t)),this.clientDecoder=new Ct(D(t)),this.leftClockDecoder=new zt(D(t)),this.rightClockDecoder=new zt(D(t)),this.infoDecoder=new ye(D(t),At),this.stringDecoder=new sn(D(t)),this.parentInfoDecoder=new ye(D(t),At),this.typeRefDecoder=new Ct(D(t)),this.lenDecoder=new Ct(D(t))}readLeftID(){return new wt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new wt(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 Pt(this.restDecoder)}readBuf(){return D(this.restDecoder)}readJSON(){return Pt(this.restDecoder)}readKey(){let t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{let n=this.stringDecoder.read();return this.keys.push(n),n}}},Bn=class{constructor(){this.restEncoder=T()}toUint8Array(){return k(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){g(this.restEncoder,t)}writeDsLen(t){g(this.restEncoder,t)}},Tt=class extends Bn{writeLeftID(t){g(this.restEncoder,t.client),g(this.restEncoder,t.clock)}writeRightID(t){g(this.restEncoder,t.client),g(this.restEncoder,t.clock)}writeClient(t){g(this.restEncoder,t)}writeInfo(t){en(this.restEncoder,t)}writeString(t){at(this.restEncoder,t)}writeParentInfo(t){g(this.restEncoder,t?1:0)}writeTypeRef(t){g(this.restEncoder,t)}writeLen(t){g(this.restEncoder,t)}writeAny(t){$t(this.restEncoder,t)}writeBuf(t){U(this.restEncoder,t)}writeJSON(t){at(this.restEncoder,JSON.stringify(t))}writeKey(t){at(this.restEncoder,t)}},Mn=class{constructor(){this.restEncoder=T(),this.dsCurrVal=0}toUint8Array(){return k(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){let n=t-this.dsCurrVal;this.dsCurrVal=t,g(this.restEncoder,n)}writeDsLen(t){t===0&&$(),g(this.restEncoder,t-1),this.dsCurrVal+=t}},dt=class extends Mn{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Ft,this.clientEncoder=new Et,this.leftClockEncoder=new Ft,this.rightClockEncoder=new Ft,this.infoEncoder=new me(en),this.stringEncoder=new Ze,this.parentInfoEncoder=new me(en),this.typeRefEncoder=new Et,this.lenEncoder=new Et}toUint8Array(){let t=T();return g(t,0),U(t,this.keyClockEncoder.toUint8Array()),U(t,this.clientEncoder.toUint8Array()),U(t,this.leftClockEncoder.toUint8Array()),U(t,this.rightClockEncoder.toUint8Array()),U(t,k(this.infoEncoder)),U(t,this.stringEncoder.toUint8Array()),U(t,k(this.parentInfoEncoder)),U(t,this.typeRefEncoder.toUint8Array()),U(t,this.lenEncoder.toUint8Array()),we(t,k(this.restEncoder)),k(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){$t(this.restEncoder,t)}writeBuf(t){U(this.restEncoder,t)}writeJSON(t){$t(this.restEncoder,t)}writeKey(t){let n=this.keyMap.get(t);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}},Sl=(e,t,n,r)=>{r=lt(r,t[0].id.clock);let s=rt(t,r);g(e.restEncoder,t.length-s),e.writeClient(n),g(e.restEncoder,r);let i=t[s];i.write(e,r-i.id.clock);for(let o=s+1;o<t.length;o++)t[o].write(e,0)},es=(e,t,n)=>{let r=new Map;n.forEach((s,i)=>{E(t,i)>s&&r.set(i,s)}),Gn(t).forEach((s,i)=>{n.has(i)||r.set(i,0)}),g(e.restEncoder,r.size),X(r.entries()).sort((s,i)=>i[0]-s[0]).forEach(([s,i])=>{Sl(e,t.clients.get(s),s,i)})},kl=(e,t)=>{let n=L(),r=m(e.restDecoder);for(let s=0;s<r;s++){let i=m(e.restDecoder),o=new Array(i),c=e.readClient(),l=m(e.restDecoder);n.set(c,{i:0,refs:o});for(let h=0;h<i;h++){let a=e.readInfo();switch(31&a){case 0:{let d=e.readLen();o[h]=new j(y(c,l),d),l+=d;break}case 10:{let d=m(e.restDecoder);o[h]=new P(y(c,l),d),l+=d;break}default:{let d=(a&192)===0,u=new _(y(c,l),null,(a&128)===128?e.readLeftID():null,null,(a&64)===64?e.readRightID():null,d?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,d&&(a&32)===32?e.readString():null,So(e,a));o[h]=u,l+=u.length}}}}return n},_l=(e,t,n)=>{let r=[],s=X(n.keys()).sort((f,p)=>f-p);if(s.length===0)return null;let i=()=>{if(s.length===0)return null;let f=n.get(s[s.length-1]);for(;f.refs.length===f.i;)if(s.pop(),s.length>0)f=n.get(s[s.length-1]);else return null;return f},o=i();if(o===null)return null;let c=new $n,l=new Map,h=(f,p)=>{let w=l.get(f);(w==null||w>p)&&l.set(f,p)},a=o.refs[o.i++],d=new Map,u=()=>{for(let f of r){let p=f.id.client,w=n.get(p);w?(w.i--,c.clients.set(p,w.refs.slice(w.i)),n.delete(p),w.i=0,w.refs=[]):c.clients.set(p,[f]),s=s.filter(x=>x!==p)}r.length=0};for(;;){if(a.constructor!==P){let p=z(d,a.id.client,()=>E(t,a.id.client))-a.id.clock;if(p<0)r.push(a),h(a.id.client,a.id.clock-1),u();else{let w=a.getMissing(e,t);if(w!==null){r.push(a);let x=n.get(w)||{refs:[],i:0};if(x.refs.length===x.i)h(w,E(t,w)),u();else{a=x.refs[x.i++];continue}}else(p===0||p<a.length)&&(a.integrate(e,p),d.set(a.id.client,a.id.clock+a.length))}}if(r.length>0)a=r.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){let f=new dt;return es(f,c,new Map),g(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},Ul=(e,t)=>es(e,t.doc.store,t.beforeState),El=(e,t,n,r=new xt(e))=>S(t,s=>{s.local=!1;let i=!1,o=s.doc,c=o.store,l=kl(r,o),h=_l(s,c,l),a=c.pendingStructs;if(a){for(let[u,f]of a.missing)if(f<E(c,u)){i=!0;break}if(h){for(let[u,f]of h.missing){let p=a.missing.get(u);(p==null||p>f)&&a.missing.set(u,f)}a.update=Fn([a.update,h.update])}}else c.pendingStructs=h;let d=Ii(r,s,c);if(c.pendingDs){let u=new xt(Q(c.pendingDs));m(u.restDecoder);let f=Ii(u,s,c);d&&f?c.pendingDs=Fn([d,f]):c.pendingDs=d||f}else c.pendingDs=d;if(i){let u=c.pendingStructs.update;c.pendingStructs=null,Gi(s.doc,u)}},n,!1);var Gi=(e,t,n,r=xt)=>{let s=Q(t);El(s,e,n,new r(s))},qi=(e,t,n)=>Gi(e,t,n,On),Al=(e,t,n=new Map)=>{es(e,t.store,n),ie(e,bl(t.store))},Cl=(e,t=new Uint8Array([0]),n=new dt)=>{let r=Ji(t);Al(n,e,r);let s=[n.toUint8Array()];if(e.store.pendingDs&&s.push(e.store.pendingDs),e.store.pendingStructs&&s.push(jl(e.store.pendingStructs.update,t)),s.length>1){if(n.constructor===Tt)return $l(s.map((i,o)=>o===0?i:zl(i)));if(n.constructor===dt)return Fn(s)}return s[0]},Yi=(e,t)=>Cl(e,t,new Tt),Il=e=>{let t=new Map,n=m(e.restDecoder);for(let r=0;r<n;r++){let s=m(e.restDecoder),i=m(e.restDecoder);t.set(s,i)}return t},Ji=e=>Il(new Ln(Q(e))),Wi=(e,t)=>(g(e.restEncoder,t.size),X(t.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{g(e.restEncoder,n),g(e.restEncoder,r)}),e),Tl=(e,t)=>Wi(e,Gn(t.store)),Dl=(e,t=new Mn)=>(e instanceof Map?Wi(t,e):Tl(t,e),t.toUint8Array()),Xi=e=>Dl(e,new Bn),Mr=class{constructor(){this.l=[]}},Ti=()=>new Mr,Di=(e,t)=>e.l.push(t),Vi=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(s=>t!==s),r===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Ki=(e,t,n)=>ke(e.l,[t,n]),wt=class{constructor(t,n){this.client=t,this.clock=n}},Qt=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,y=(e,t)=>new wt(e,t);var Qi=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw $()},vn=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1};var Rn=class{constructor(t,n,r,s=0){this.type=t,this.tname=n,this.item=r,this.assoc=s}},ed=e=>{let t={};return e.type&&(t.type=e.type),e.tname&&(t.tname=e.tname),e.item&&(t.item=e.item),e.assoc!=null&&(t.assoc=e.assoc),t},nd=e=>new Rn(e.type==null?null:y(e.type.client,e.type.clock),e.tname??null,e.item==null?null:y(e.item.client,e.item.clock),e.assoc==null?0:e.assoc),vr=class{constructor(t,n,r=0){this.type=t,this.index=n,this.assoc=r}},Vl=(e,t,n=0)=>new vr(e,t,n),In=(e,t,n)=>{let r=null,s=null;return e._item===null?s=Qi(e):r=y(e._item.id.client,e._item.id.clock),new Rn(r,s,t,n)},rd=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return In(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return In(e,y(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return In(e,r.lastId,n);r=r.right}return In(e,null,n)};var Nl=(e,t)=>{let n=Zt(e,t),r=t.clock-n.id.clock;return{item:n,diff:r}},sd=(e,t,n=!0)=>{let r=t.store,s=e.item,i=e.type,o=e.tname,c=e.assoc,l=null,h=0;if(s!==null){if(E(r,s.client)<=s.clock)return null;let a=n?Kr(r,s):Nl(r,s),d=a.item;if(!(d instanceof _))return null;if(l=d.parent,l._item===null||!l._item.deleted){h=d.deleted||!d.countable?0:a.diff+(c>=0?0:1);let u=d.left;for(;u!==null;)!u.deleted&&u.countable&&(h+=u.length),u=u.left}}else{if(o!==null)l=t.get(o);else if(i!==null){if(E(r,i.client)<=i.clock)return null;let{item:a}=n?Kr(r,i):{item:Zt(r,i)};if(a instanceof _&&a.content instanceof it)l=a.content.type;else return null}else throw $();c>=0?h=l._length:h=0}return Vl(l,h,e.assoc)},id=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&Qt(e.item,t.item)&&Qt(e.type,t.type)&&e.assoc===t.assoc,Rr=class{constructor(t,n){this.ds=t,this.sv=n}};var Ll=(e,t)=>new Rr(e,t),od=Ll(zi(),new Map);var Kt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Ge(t.ds,e.id),$r=(e,t)=>{let n=z(e.meta,$r,J),r=e.doc.store;n.has(t)||(t.sv.forEach((s,i)=>{s<E(r,i)&&F(e,y(i,s))}),te(e,t.ds,s=>{}),n.add(t))};var $n=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Gn=e=>{let t=new Map;return e.clients.forEach((n,r)=>{let s=n[n.length-1];t.set(r,s.id.clock+s.length)}),t},E=(e,t)=>{let n=e.clients.get(t);if(n===void 0)return 0;let r=n[n.length-1];return r.id.clock+r.length},Zi=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let r=n[n.length-1];if(r.id.clock+r.length!==t.id.clock)throw $()}n.push(t)},rt=(e,t)=>{let n=0,r=e.length-1,s=e[r],i=s.id.clock;if(i===t)return r;let o=B(t/(i+s.length-1)*r);for(;n<=r;){if(s=e[o],i=s.id.clock,i<=t){if(t<i+s.length)return o;n=o+1}else r=o-1;o=B((n+r)/2)}throw $()},Ol=(e,t)=>{let n=e.clients.get(t.client);return n[rt(n,t.clock)]},Zt=Ol,Fr=(e,t,n)=>{let r=rt(t,n),s=t[r];return s.id.clock<n&&s instanceof _?(t.splice(r+1,0,Hn(e,s,n-s.id.clock)),r+1):r},F=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[Fr(e,n,t.clock)]},Ni=(e,t,n)=>{let r=t.clients.get(n.client),s=rt(r,n.clock),i=r[s];return n.clock!==i.id.clock+i.length-1&&i.constructor!==j&&r.splice(s+1,0,Hn(e,i,n.clock-i.id.clock+1)),i},Bl=(e,t,n)=>{let r=e.clients.get(t.id.client);r[rt(r,t.id.clock)]=n},to=(e,t,n,r,s)=>{if(r===0)return;let i=n+r,o=Fr(e,t,n),c;do c=t[o++],i<c.id.clock+c.length&&Fr(e,t,i),s(c);while(o<t.length&&t[o].id.clock<i)},jr=class{constructor(t,n,r){this.doc=t,this.deleteSet=new yt,this.beforeState=Gn(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=r,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}},Li=(e,t)=>t.deleteSet.clients.size===0&&!Ss(t.afterState,(n,r)=>t.beforeState.get(r)!==n)?!1:(Zr(t.deleteSet),Ul(e,t),ie(e,t.deleteSet),!0),Oi=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&z(e.changed,t,J).add(n)},Vn=(e,t)=>{let n=e[t],r=e[t-1],s=t;for(;s>0;n=r,r=e[--s-1]){if(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n)){n instanceof _&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}let i=t-s;return i&&e.splice(t+1-i,i),i},Ml=(e,t,n)=>{for(let[r,s]of e.clients.entries()){let i=t.clients.get(r);for(let o=s.length-1;o>=0;o--){let c=s[o],l=c.clock+c.len;for(let h=rt(i,c.clock),a=i[h];h<i.length&&a.id.clock<l;a=i[++h]){let d=i[h];if(c.clock+c.len<=d.id.clock)break;d instanceof _&&d.deleted&&!d.keep&&n(d)&&d.gc(t,!1)}}}},vl=(e,t)=>{e.clients.forEach((n,r)=>{let s=t.clients.get(r);for(let i=n.length-1;i>=0;i--){let o=n[i],c=Ot(s.length-1,1+rt(s,o.clock+o.len-1));for(let l=c,h=s[l];l>0&&h.id.clock>=o.clock;h=s[l])l-=1+Vn(s,l)}})};var eo=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,s=r.store,i=n.deleteSet,o=n._mergeStructs;try{Zr(i),n.afterState=Gn(n.doc.store),r.emit("beforeObserverCalls",[n,r]);let 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)&&(l=l.filter(a=>a.target._item===null||!a.target._item.deleted),l.forEach(a=>{a.currentTarget=h,a._path=null}),l.sort((a,d)=>a.path.length-d.path.length),c.push(()=>{Ki(h._dEH,l,n)}))}),c.push(()=>r.emit("afterTransaction",[n,r])),c.push(()=>{n._needFormattingCleanup&&ta(n)})}),ke(c,[])}finally{r.gc&&Ml(i,s,r.gcFilter),vl(i,s),n.afterState.forEach((a,d)=>{let u=n.beforeState.get(d)||0;if(u!==a){let f=s.clients.get(d),p=lt(rt(f,u),1);for(let w=f.length-1;w>=p;)w-=1+Vn(f,w)}});for(let a=o.length-1;a>=0;a--){let{client:d,clock:u}=o[a].id,f=s.clients.get(d),p=rt(f,u);p+1<f.length&&Vn(f,p+1)>1||p>0&&Vn(f,p)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(ki(Xt,Te,"[yjs] ",De,Ve,"Changed the client-id because another client seems to be using it."),r.clientID=Hi()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){let a=new Tt;Li(a,n)&&r.emit("update",[a.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){let a=new dt;Li(a,n)&&r.emit("updateV2",[a.toUint8Array(),n.origin,r,n])}let{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:h}=n;(c.size>0||h.size>0||l.size>0)&&(c.forEach(a=>{a.clientID=r.clientID,a.collectionid==null&&(a.collectionid=r.collectionid),r.subdocs.add(a)}),h.forEach(a=>r.subdocs.delete(a)),r.emit("subdocs",[{loaded:l,added:c,removed:h},r,n]),h.forEach(a=>a.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,e])):eo(e,t+1)}}},S=(e,t,n=null,r=!0)=>{let s=e._transactionCleanups,i=!1,o=null;e._transaction===null&&(i=!0,e._transaction=new jr(e,n,r),s.push(e._transaction),s.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(i){let c=e._transaction===s[0];e._transaction=null,c&&eo(s,0)}}return o},Pr=class{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}},Bi=(e,t,n)=>{te(e,n.deletions,r=>{r instanceof _&&t.scope.some(s=>s===e.doc||vn(s,r))&&os(r,!1)})},Mi=(e,t,n)=>{let r=null,s=e.doc,i=e.scope;S(s,c=>{for(;t.length>0&&e.currStackItem===null;){let l=s.store,h=t.pop(),a=new Set,d=[],u=!1;te(c,h.insertions,f=>{if(f instanceof _){if(f.redone!==null){let{item:p,diff:w}=Kr(l,f.id);w>0&&(p=F(c,y(p.id.client,p.id.clock+w))),f=p}!f.deleted&&i.some(p=>p===c.doc||vn(p,f))&&d.push(f)}}),te(c,h.deletions,f=>{f instanceof _&&i.some(p=>p===c.doc||vn(p,f))&&!Ge(h.insertions,f.id)&&a.add(f)}),a.forEach(f=>{u=bo(c,f,a,h.insertions,e.ignoreRemoteMapChanges,e)!==null||u});for(let f=d.length-1;f>=0;f--){let p=d[f];e.deleteFilter(p)&&(p.delete(c),u=!0)}e.currStackItem=u?h:null}c.changed.forEach((l,h)=>{l.has(null)&&h._searchMarker&&(h._searchMarker.length=0)}),r=c},e);let o=e.currStackItem;if(o!=null){let c=r.changedParentTypes;e.emit("stack-item-popped",[{stackItem:o,type:n,changedParentTypes:c,origin:e},e]),e.currStackItem=null}return o},vi=class extends St{constructor(t,{captureTimeout:n=500,captureTransaction:r=l=>!0,deleteFilter:s=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:c=ct(t)?t[0].doc:t instanceof ee?t:t.doc}={}){super(),this.scope=[],this.doc=c,this.addToScope(t),this.deleteFilter=s,i.add(this),this.trackedOrigins=i,this.captureTransaction=r,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(x=>l.changedParentTypes.has(x)||x===this.doc)||!this.trackedOrigins.has(l.origin)&&(!l.origin||!this.trackedOrigins.has(l.origin.constructor)))return;let h=this.undoing,a=this.redoing,d=h?this.redoStack:this.undoStack;h?this.stopCapturing():a||this.clear(!1,!0);let u=new yt;l.afterState.forEach((x,b)=>{let ys=l.beforeState.get(b)||0,xs=x-ys;xs>0&&Oe(u,b,ys,xs)});let f=q(),p=!1;if(this.lastChange>0&&f-this.lastChange<this.captureTimeout&&d.length>0&&!h&&!a){let x=d[d.length-1];x.deletions=Or([x.deletions,l.deleteSet]),x.insertions=Or([x.insertions,u])}else d.push(new Pr(l.deleteSet,u)),p=!0;!h&&!a&&(this.lastChange=f),te(l,l.deleteSet,x=>{x instanceof _&&this.scope.some(b=>b===l.doc||vn(b,x))&&os(x,!0)});let w=[{stackItem:d[d.length-1],origin:l.origin,type:h?"redo":"undo",changedParentTypes:l.changedParentTypes},this];p?this.emit("stack-item-added",w):this.emit("stack-item-updated",w)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){let n=new Set(this.scope);t=ct(t)?t:[t],t.forEach(r=>{n.has(r)||(n.add(r),(r instanceof I?r.doc!==this.doc:r!==this.doc)&&Nr("[yjs#509] Not same Y.Doc"),this.scope.push(r))})}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(r=>{t&&(this.undoStack.forEach(s=>Bi(r,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>Bi(r,this,s)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let t;try{t=Mi(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=Mi(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),super.destroy()}};function*Rl(e){let t=m(e.restDecoder);for(let n=0;n<t;n++){let r=m(e.restDecoder),s=e.readClient(),i=m(e.restDecoder);for(let o=0;o<r;o++){let c=e.readInfo();if(c===10){let l=m(e.restDecoder);yield new P(y(s,i),l),i+=l}else if((31&c)!==0){let l=(c&192)===0,h=new _(y(s,i),null,(c&128)===128?e.readLeftID():null,null,(c&64)===64?e.readRightID():null,l?e.readParentInfo()?e.readString():e.readLeftID():null,l&&(c&32)===32?e.readString():null,So(e,c));yield h,i+=h.length}else{let l=e.readLen();yield new j(y(s,i),l),i+=l}}}}var Be=class{constructor(t,n){this.gen=Rl(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===P);return this.curr}};var Me=class{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}},$l=e=>Fn(e,On,Tt);var Fl=(e,t)=>{if(e.constructor===j){let{client:n,clock:r}=e.id;return new j(y(n,r+t),e.length-t)}else if(e.constructor===P){let{client:n,clock:r}=e.id;return new P(y(n,r+t),e.length-t)}else{let n=e,{client:r,clock:s}=n.id;return new _(y(r,s+t),null,y(r,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Fn=(e,t=xt,n=dt)=>{if(e.length===1)return e[0];let r=e.map(a=>new t(Q(a))),s=r.map(a=>new Be(a,!0)),i=null,o=new n,c=new Me(o);for(;s=s.filter(u=>u.curr!==null),s.sort((u,f)=>{if(u.curr.id.client===f.curr.id.client){let p=u.curr.id.clock-f.curr.id.clock;return p===0?u.curr.constructor===f.curr.constructor?0:u.curr.constructor===P?1:-1:p}else return f.curr.id.client-u.curr.id.client}),s.length!==0;){let a=s[0],d=a.curr.id.client;if(i!==null){let u=a.curr,f=!1;for(;u!==null&&u.id.clock+u.length<=i.struct.id.clock+i.struct.length&&u.id.client>=i.struct.id.client;)u=a.next(),f=!0;if(u===null||u.id.client!==d||f&&u.id.clock>i.struct.id.clock+i.struct.length)continue;if(d!==i.struct.id.client)gt(c,i.struct,i.offset),i={struct:u,offset:0},a.next();else if(i.struct.id.clock+i.struct.length<u.id.clock)if(i.struct.constructor===P)i.struct.length=u.id.clock+u.length-i.struct.id.clock;else{gt(c,i.struct,i.offset);let p=u.id.clock-i.struct.id.clock-i.struct.length;i={struct:new P(y(d,i.struct.id.clock+i.struct.length),p),offset:0}}else{let p=i.struct.id.clock+i.struct.length-u.id.clock;p>0&&(i.struct.constructor===P?i.struct.length-=p:u=Fl(u,p)),i.struct.mergeWith(u)||(gt(c,i.struct,i.offset),i={struct:u,offset:0},a.next())}}else i={struct:a.curr,offset:0},a.next();for(let u=a.curr;u!==null&&u.id.client===d&&u.id.clock===i.struct.id.clock+i.struct.length&&u.constructor!==P;u=a.next())gt(c,i.struct,i.offset),i={struct:u,offset:0}}i!==null&&(gt(c,i.struct,i.offset),i=null),ns(c);let l=r.map(a=>ts(a)),h=Or(l);return ie(o,h),o.toUint8Array()},jl=(e,t,n=xt,r=dt)=>{let s=Ji(t),i=new r,o=new Me(i),c=new n(Q(e)),l=new Be(c,!1);for(;l.curr;){let a=l.curr,d=a.id.client,u=s.get(d)||0;if(l.curr.constructor===P){l.next();continue}if(a.id.clock+a.length>u)for(gt(o,a,lt(u-a.id.clock,0)),l.next();l.curr&&l.curr.id.client===d;)gt(o,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===d&&l.curr.id.clock+l.curr.length<=u;)l.next()}ns(o);let h=ts(c);return ie(i,h),i.toUint8Array()};var no=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:k(e.encoder.restEncoder)}),e.encoder.restEncoder=T(),e.written=0)},gt=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&no(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),g(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},ns=e=>{no(e);let t=e.encoder.restEncoder;g(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];g(t,r.written),we(t,r.restEncoder)}},Pl=(e,t,n,r)=>{let s=new n(Q(e)),i=new Be(s,!1),o=new r,c=new Me(o);for(let h=i.curr;h!==null;h=i.next())gt(c,t(h),0);ns(c);let l=ts(s);return ie(o,l),o.toUint8Array()};var zl=e=>Pl(e,qs,xt,Tt),Ri="You must not compute changes after the event-handler fired.",ne=class{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=Hl(this.currentTarget,this.target))}deletes(t){return Ge(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw H(Ri);let t=new Map,n=this.target;this.transaction.changed.get(n).forEach(s=>{if(s!==null){let i=n._map.get(s),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=We(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",c=We(l.content.getContent())):(o="add",c=void 0)}else if(this.deletes(i))o="delete",c=We(i.content.getContent());else return;t.set(s,{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 H(Ri);let n=this.target,r=J(),s=J(),i=[];if(t={added:r,deleted:s,delta:i,keys:this.keys},this.transaction.changed.get(n).has(null)){let c=null,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,s.add(h)):this.adds(h)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(h.content.getContent()),r.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}},Hl=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let r=0,s=t._item.parent._start;for(;s!==t._item&&s!==null;)!s.deleted&&s.countable&&(r+=s.length),s=s.right;n.unshift(r)}t=t._item.parent}return n},R=()=>{Nr("Invalid access: Add Yjs type to a document before reading data.")},ro=80,rs=0,zr=class{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=rs++}},Gl=e=>{e.timestamp=rs++},so=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=rs++},ql=(e,t,n)=>{if(e.length>=ro){let r=e.reduce((s,i)=>s.timestamp<i.timestamp?s:i);return so(r,t,n),r}else{let r=new zr(t,n);return e.push(r),r}},qn=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((i,o)=>kt(t-i.index)<kt(t-o.index)?i:o),r=e._start,s=0;for(n!==null&&(r=n.p,s=n.index,Gl(n));r.right!==null&&s<t;){if(!r.deleted&&r.countable){if(t<s+r.length)break;s+=r.length}r=r.right}for(;r.left!==null&&s>t;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);return n!==null&&kt(n.index-s)<r.parent.length/ro?(so(n,r,s),n):ql(e._searchMarker,r,s)},ve=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){let s=e[r];if(n>0){let i=s.p;for(i.marker=!1;i&&(i.deleted||!i.countable);)i=i.left,i&&!i.deleted&&i.countable&&(s.index-=i.length);if(i===null||i.marker===!0){e.splice(r,1);continue}s.p=i,i.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=lt(t,s.index+n))}};var Yn=(e,t,n)=>{let r=e,s=t.changedParentTypes;for(;z(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Ki(r._eH,n,t)},I=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Ti(),this._dEH=Ti(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw G()}clone(){throw G()}_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){Di(this._eH,t)}observeDeep(t){Di(this._dEH,t)}unobserve(t){Vi(this._eH,t)}unobserveDeep(t){Vi(this._dEH,t)}toJSON(){}},io=(e,t,n)=>{e.doc??R(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,s=[],i=e._start;for(;i!==null&&r>0;){if(i.countable&&!i.deleted){let o=i.content.getContent();if(o.length<=t)t-=o.length;else{for(let c=t;c<o.length&&r>0;c++)s.push(o[c]),r--;t=0}}i=i.right}return s},oo=e=>{e.doc??R();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let r=n.content.getContent();for(let s=0;s<r.length;s++)t.push(r[s])}n=n.right}return t};var Re=(e,t)=>{let n=0,r=e._start;for(e.doc??R();r!==null;){if(r.countable&&!r.deleted){let s=r.content.getContent();for(let i=0;i<s.length;i++)t(s[i],n++,e)}r=r.right}},co=(e,t)=>{let n=[];return Re(e,(r,s)=>{n.push(t(r,s,e))}),n},Yl=e=>{let t=e._start,n=null,r=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(),r=0,t=t.right}let s=n[r++];return n.length<=r&&(n=null),{done:!1,value:s}}}},lo=(e,t)=>{e.doc??R();let n=qn(e,t),r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},jn=(e,t,n,r)=>{let s=n,i=e.doc,o=i.clientID,c=i.store,l=n===null?t._start:n.right,h=[],a=()=>{h.length>0&&(s=new _(y(o,E(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new se(h)),s.integrate(e,0),h=[])};r.forEach(d=>{if(d===null)h.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:h.push(d);break;default:switch(a(),d.constructor){case Uint8Array:case ArrayBuffer:s=new _(y(o,E(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new ze(new Uint8Array(d))),s.integrate(e,0);break;case ee:s=new _(y(o,E(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new He(d)),s.integrate(e,0);break;default:if(d instanceof I)s=new _(y(o,E(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new it(d)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),a()},ao=()=>H("Length exceeded!"),ho=(e,t,n,r)=>{if(n>t._length)throw ao();if(n===0)return t._searchMarker&&ve(t._searchMarker,n,r.length),jn(e,t,null,r);let s=n,i=qn(t,n),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&&F(e,y(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&ve(t._searchMarker,s,r.length),jn(e,t,o,r)},Jl=(e,t,n)=>{let s=(t._searchMarker||[]).reduce((i,o)=>o.index>i.index?o:i,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return jn(e,t,s,n)},uo=(e,t,n,r)=>{if(r===0)return;let s=n,i=r,o=qn(t,n),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&&F(e,y(c.id.client,c.id.clock+n)),n-=c.length);for(;r>0&&c!==null;)c.deleted||(r<c.length&&F(e,y(c.id.client,c.id.clock+r)),c.delete(e),r-=c.length),c=c.right;if(r>0)throw ao();t._searchMarker&&ve(t._searchMarker,s,-i+r)},Pn=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},ss=(e,t,n,r)=>{let s=t._map.get(n)||null,i=e.doc,o=i.clientID,c;if(r==null)c=new se([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:c=new se([r]);break;case Uint8Array:c=new ze(r);break;case ee:c=new He(r);break;default:if(r instanceof I)c=new it(r);else throw new Error("Unexpected content type")}new _(y(o,E(i.store,o)),s,s&&s.lastId,null,null,t,n,c).integrate(e,0)},is=(e,t)=>{e.doc??R();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},fo=e=>{let t={};return e.doc??R(),e._map.forEach((n,r)=>{n.deleted||(t[r]=n.content.getContent()[n.length-1])}),t},po=(e,t)=>{e.doc??R();let n=e._map.get(t);return n!==void 0&&!n.deleted};var Wl=(e,t)=>{let n={};return e._map.forEach((r,s)=>{let i=r;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[s]=i.content.getContent()[i.length-1])}),n},Tn=e=>(e.doc??R(),Ei(e._map.entries(),t=>!t[1].deleted)),Hr=class extends ne{},bt=class e extends I{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(n=>n instanceof I?n.clone():n)),t}get length(){return this.doc??R(),this._length}_callObserver(t,n){super._callObserver(t,n),Yn(this,t,new Hr(this,t))}insert(t,n){this.doc!==null?S(this.doc,r=>{ho(r,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?S(this.doc,n=>{Jl(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?S(this.doc,r=>{uo(r,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return lo(this,t)}toArray(){return oo(this)}slice(t=0,n=this.length){return io(this,t,n)}toJSON(){return this.map(t=>t instanceof I?t.toJSON():t)}map(t){return co(this,t)}forEach(t){Re(this,t)}[Symbol.iterator](){return Yl(this)}_write(t){t.writeTypeRef(wa)}},Xl=e=>new bt,Gr=class extends ne{constructor(t,n,r){super(t,n),this.keysChanged=r}},st=class e 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((r,s)=>{this.set(s,r)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((n,r)=>{t.set(r,n instanceof I?n.clone():n)}),t}_callObserver(t,n){Yn(this,t,new Gr(this,t,n))}toJSON(){this.doc??R();let t={};return this._map.forEach((n,r)=>{if(!n.deleted){let s=n.content.getContent()[n.length-1];t[r]=s instanceof I?s.toJSON():s}}),t}get size(){return[...Tn(this)].length}keys(){return Cn(Tn(this),t=>t[0])}values(){return Cn(Tn(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Cn(Tn(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??R(),this._map.forEach((n,r)=>{n.deleted||t(n.content.getContent()[n.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?S(this.doc,n=>{Pn(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?S(this.doc,r=>{ss(r,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return is(this,t)}has(t){return po(this,t)}clear(){this.doc!==null?S(this.doc,t=>{this.forEach(function(n,r,s){Pn(t,s,r)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(ya)}},Kl=e=>new st,mt=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&fr(e,t),$e=class{constructor(t,n,r,s){this.left=t,this.right=n,this.index=r,this.currentAttributes=s}forward(){this.right===null&&$(),this.right.content.constructor===N?this.right.deleted||oe(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}},$i=(e,t,n)=>{for(;t.right!==null&&n>0;)t.right.content.constructor===N?t.right.deleted||oe(t.currentAttributes,t.right.content):t.right.deleted||(n<t.right.length&&F(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},Dn=(e,t,n,r)=>{let s=new Map,i=r?qn(t,n):null;if(i){let o=new $e(i.p.left,i.p,i.index,s);return $i(e,o,n-i.index)}else{let o=new $e(null,t._start,0,s);return $i(e,o,n)}},go=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===N&&mt(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let s=e.doc,i=s.clientID;r.forEach((o,c)=>{let l=n.left,h=n.right,a=new _(y(i,E(s.store,i)),l,l&&l.lastId,h,h&&h.id,t,null,new N(c,o));a.integrate(e,0),n.right=a,n.forward()})},oe=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},mo=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===N&&mt(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},wo=(e,t,n,r)=>{let s=e.doc,i=s.clientID,o=new Map;for(let c in r){let l=r[c],h=n.currentAttributes.get(c)??null;if(!mt(h,l)){o.set(c,h);let{left:a,right:d}=n;n.right=new _(y(i,E(s.store,i)),a,a&&a.lastId,d,d&&d.id,t,null,new N(c,l)),n.right.integrate(e,0),n.forward()}}return o},Lr=(e,t,n,r,s)=>{n.currentAttributes.forEach((u,f)=>{s[f]===void 0&&(s[f]=null)});let i=e.doc,o=i.clientID;mo(n,s);let c=wo(e,t,n,s),l=r.constructor===String?new ut(r):r instanceof I?new it(r):new Dt(r),{left:h,right:a,index:d}=n;t._searchMarker&&ve(t._searchMarker,n.index,l.getLength()),a=new _(y(o,E(i.store,o)),h,h&&h.lastId,a,a&&a.id,t,null,l),a.integrate(e,0),n.right=a,n.index=d,n.forward(),go(e,t,n,c)},Fi=(e,t,n,r,s)=>{let i=e.doc,o=i.clientID;mo(n,s);let c=wo(e,t,n,s);t:for(;n.right!==null&&(r>0||c.size>0&&(n.right.deleted||n.right.content.constructor===N));){if(!n.right.deleted)switch(n.right.content.constructor){case N:{let{key:l,value:h}=n.right.content,a=s[l];if(a!==void 0){if(mt(a,h))c.delete(l);else{if(r===0)break t;c.set(l,h)}n.right.delete(e)}else n.currentAttributes.set(l,h);break}default:r<n.right.length&&F(e,y(n.right.id.client,n.right.id.clock+r)),r-=n.right.length;break}n.forward()}if(r>0){let l="";for(;r>0;r--)l+=`
|
|
4
|
+
`;n.right=new _(y(o,E(i.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new ut(l)),n.right.integrate(e,0),n.forward()}go(e,t,n,c)},yo=(e,t,n,r,s)=>{let i=t,o=L();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===N){let 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){let h=t.content;if(h.constructor===N){let{key:a,value:d}=h,u=r.get(a)??null;(o.get(a)!==h||u===d)&&(t.delete(e),c++,!l&&(s.get(a)??null)===d&&u!==d&&(u===null?s.delete(a):s.set(a,u))),!l&&!t.deleted&&oe(s,h)}}t=t.right}return c},Ql=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===N){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},Zl=e=>{let t=0;return S(e.doc,n=>{let r=e._start,s=e._start,i=L(),o=Ye(i);for(;s;)s.deleted===!1&&(s.content.constructor===N?oe(o,s.content):(t+=yo(n,r,s,i,o),i=Ye(o),r=s)),s=s.right}),t},ta=e=>{let t=new Set,n=e.doc;for(let[r,s]of e.afterState.entries()){let i=e.beforeState.get(r)||0;s!==i&&to(e,n.store.clients.get(r),i,s,o=>{!o.deleted&&o.content.constructor===N&&o.constructor!==j&&t.add(o.parent)})}S(n,r=>{te(e,e.deleteSet,s=>{if(s instanceof j||!s.parent._hasFormatting||t.has(s.parent))return;let i=s.parent;s.content.constructor===N?t.add(i):Ql(r,s)});for(let s of t)Zl(s)})},ji=(e,t,n)=>{let r=n,s=Ye(t.currentAttributes),i=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case it:case Dt:case ut:n<t.right.length&&F(e,y(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}i&&yo(e,i,t.right,s,t.currentAttributes);let o=(t.left||t.right).parent;return o._searchMarker&&ve(o._searchMarker,t.index,-r+n),t},qr=class extends ne{constructor(t,n,r){super(t,n),this.childListChanged=!1,this.keysChanged=new Set,r.forEach(s=>{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}get changes(){if(this._changes===null){let t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){let t=this.target.doc,n=[];S(t,r=>{let s=new Map,i=new Map,o=this.target._start,c=null,l={},h="",a=0,d=0,u=()=>{if(c!==null){let f=null;switch(c){case"delete":d>0&&(f={delete:d}),d=0;break;case"insert":(typeof h=="object"||h.length>0)&&(f={insert:h},s.size>0&&(f.attributes={},s.forEach((p,w)=>{p!==null&&(f.attributes[w]=p)}))),h="";break;case"retain":a>0&&(f={retain:a},Gs(l)||(f.attributes=Ps({},l))),a=0;break}f&&n.push(f),c=null}};for(;o!==null;){switch(o.content.constructor){case it:case Dt:this.adds(o)?this.deletes(o)||(u(),c="insert",h=o.content.getContent()[0],u()):this.deletes(o)?(c!=="delete"&&(u(),c="delete"),d+=1):o.deleted||(c!=="retain"&&(u(),c="retain"),a+=1);break;case ut:this.adds(o)?this.deletes(o)||(c!=="insert"&&(u(),c="insert"),h+=o.content.str):this.deletes(o)?(c!=="delete"&&(u(),c="delete"),d+=o.length):o.deleted||(c!=="retain"&&(u(),c="retain"),a+=o.length);break;case N:{let{key:f,value:p}=o.content;if(this.adds(o)){if(!this.deletes(o)){let w=s.get(f)??null;mt(w,p)?p!==null&&o.delete(r):(c==="retain"&&u(),mt(p,i.get(f)??null)?delete l[f]:l[f]=p)}}else if(this.deletes(o)){i.set(f,p);let w=s.get(f)??null;mt(w,p)||(c==="retain"&&u(),l[f]=w)}else if(!o.deleted){i.set(f,p);let w=l[f];w!==void 0&&(mt(w,p)?w!==null&&o.delete(r):(c==="retain"&&u(),p===null?delete l[f]:l[f]=p))}o.deleted||(c==="insert"&&u(),oe(s,o.content));break}}o=o.right}for(u();n.length>0;){let f=n[n.length-1];if(f.retain!==void 0&&f.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}},Fe=class e extends I{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??R(),this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);let r=new qr(this,t,n);Yn(this,t,r),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??R();let t="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===ut&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){this.doc!==null?S(this.doc,r=>{let s=new $e(null,this._start,0,new Map);for(let i=0;i<t.length;i++){let o=t[i];if(o.insert!==void 0){let c=!n&&typeof o.insert=="string"&&i===t.length-1&&s.right===null&&o.insert.slice(-1)===`
|
|
5
|
+
`?o.insert.slice(0,-1):o.insert;(typeof c!="string"||c.length>0)&&Lr(r,this,s,c,o.attributes||{})}else o.retain!==void 0?Fi(r,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&ji(r,s,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,r){this.doc??R();let s=[],i=new Map,o=this.doc,c="",l=this._start;function h(){if(c.length>0){let d={},u=!1;i.forEach((p,w)=>{u=!0,d[w]=p});let f={insert:c};u&&(f.attributes=d),s.push(f),c=""}}let a=()=>{for(;l!==null;){if(Kt(l,t)||n!==void 0&&Kt(l,n))switch(l.content.constructor){case ut:{let d=i.get("ychange");t!==void 0&&!Kt(l,t)?(d===void 0||d.user!==l.id.client||d.type!=="removed")&&(h(),i.set("ychange",r?r("removed",l.id):{type:"removed"})):n!==void 0&&!Kt(l,n)?(d===void 0||d.user!==l.id.client||d.type!=="added")&&(h(),i.set("ychange",r?r("added",l.id):{type:"added"})):d!==void 0&&(h(),i.delete("ychange")),c+=l.content.str;break}case it:case Dt:{h();let d={insert:l.content.getContent()[0]};if(i.size>0){let u={};d.attributes=u,i.forEach((f,p)=>{u[p]=f})}s.push(d);break}case N:Kt(l,t)&&(h(),oe(i,l.content));break}l=l.right}h()};return t||n?S(o,d=>{t&&$r(d,t),n&&$r(d,n),a()},"cleanup"):a(),s}insert(t,n,r){if(n.length<=0)return;let s=this.doc;s!==null?S(s,i=>{let o=Dn(i,this,t,!r);r||(r={},o.currentAttributes.forEach((c,l)=>{r[l]=c})),Lr(i,this,o,n,r)}):this._pending.push(()=>this.insert(t,n,r))}insertEmbed(t,n,r){let s=this.doc;s!==null?S(s,i=>{let o=Dn(i,this,t,!r);Lr(i,this,o,n,r||{})}):this._pending.push(()=>this.insertEmbed(t,n,r||{}))}delete(t,n){if(n===0)return;let r=this.doc;r!==null?S(r,s=>{ji(s,Dn(s,this,t,!0),n)}):this._pending.push(()=>this.delete(t,n))}format(t,n,r){if(n===0)return;let s=this.doc;s!==null?S(s,i=>{let o=Dn(i,this,t,!1);o.right!==null&&Fi(i,this,o,n,r)}):this._pending.push(()=>this.format(t,n,r))}removeAttribute(t){this.doc!==null?S(this.doc,n=>{Pn(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?S(this.doc,r=>{ss(r,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return is(this,t)}getAttributes(){return fo(this)}_write(t){t.writeTypeRef(xa)}},ea=e=>new Fe,Ne=class{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??R()}[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===je||n.constructor===re)&&n._start!==null)t=n._start;else for(;t!==null;){let r=t.next;if(r!==null){t=r;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})}},re=class e extends I{constructor(){super(),this._prelimContent=[]}get firstChild(){let 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 e}clone(){let t=new e;return t.insert(0,this.toArray().map(n=>n instanceof I?n.clone():n)),t}get length(){return this.doc??R(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Ne(this,t)}querySelector(t){t=t.toUpperCase();let r=new Ne(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return r.done?null:r.value}querySelectorAll(t){return t=t.toUpperCase(),X(new Ne(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){Yn(this,t,new Yr(this,n,t))}toString(){return co(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},r){let s=t.createDocumentFragment();return r!==void 0&&r._createAssociation(s,this),Re(this,i=>{s.insertBefore(i.toDOM(t,n,r),null)}),s}insert(t,n){this.doc!==null?S(this.doc,r=>{ho(r,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)S(this.doc,r=>{let s=t&&t instanceof I?t._item:t;jn(r,this,s,n)});else{let r=this._prelimContent,s=t===null?0:r.findIndex(i=>i===t)+1;if(s===0&&t!==null)throw H("Reference item not found");r.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?S(this.doc,r=>{uo(r,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return oo(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return lo(this,t)}slice(t=0,n=this.length){return io(this,t,n)}forEach(t){Re(this,t)}_write(t){t.writeTypeRef(Sa)}},na=e=>new re,je=class e extends re{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach((r,s)=>{this.setAttribute(s,r)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName),n=this.getAttributes();return zs(n,(r,s)=>{t.setAttribute(s,r)}),t.insert(0,this.toArray().map(r=>r instanceof I?r.clone():r)),t}toString(){let t=this.getAttributes(),n=[],r=[];for(let c in t)r.push(c);r.sort();let s=r.length;for(let c=0;c<s;c++){let l=r[c];n.push(l+'="'+t[l]+'"')}let i=this.nodeName.toLocaleLowerCase(),o=n.length>0?" "+n.join(" "):"";return`<${i}${o}>${super.toString()}</${i}>`}removeAttribute(t){this.doc!==null?S(this.doc,n=>{Pn(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?S(this.doc,r=>{ss(r,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return is(this,t)}hasAttribute(t){return po(this,t)}getAttributes(t){return t?Wl(this,t):fo(this)}toDOM(t=document,n={},r){let s=t.createElement(this.nodeName),i=this.getAttributes();for(let o in i){let c=i[o];typeof c=="string"&&s.setAttribute(o,c)}return Re(this,o=>{s.appendChild(o.toDOM(t,n,r))}),r!==void 0&&r._createAssociation(s,this),s}_write(t){t.writeTypeRef(ba),t.writeKey(this.nodeName)}},ra=e=>new je(e.readKey()),Yr=class extends ne{constructor(t,n,r){super(t,r),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}},Jr=class e extends st{constructor(t){super(),this.hookName=t}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((n,r)=>{t.set(r,n)}),t}toDOM(t=document,n={},r){let s=n[this.hookName],i;return s!==void 0?i=s.createDom(this):i=document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(i,this),i}_write(t){t.writeTypeRef(ka),t.writeKey(this.hookName)}},sa=e=>new Jr(e.readKey()),Wr=class e extends Fe{get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,r){let s=t.createTextNode(this.toString());return r!==void 0&&r._createAssociation(s,this),s}toString(){return this.toDelta().map(t=>{let n=[];for(let s in t.attributes){let i=[];for(let o in t.attributes[s])i.push({key:o,value:t.attributes[s][o]});i.sort((o,c)=>o.key<c.key?-1:1),n.push({nodeName:s,attrs:i})}n.sort((s,i)=>s.nodeName<i.nodeName?-1:1);let r="";for(let s=0;s<n.length;s++){let i=n[s];r+=`<${i.nodeName}`;for(let o=0;o<i.attrs.length;o++){let c=i.attrs[o];r+=` ${c.key}="${c.value}"`}r+=">"}r+=t.insert;for(let s=n.length-1;s>=0;s--)r+=`</${n[s].nodeName}>`;return r}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(_a)}},ia=e=>new Wr,Pe=class{constructor(t,n){this.id=t,this.length=n}get deleted(){throw G()}mergeWith(t){return!1}write(t,n,r){throw G()}integrate(t,n){throw G()}},oa=0,j=class extends Pe{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),Zi(t.doc.store,this)}write(t,n){t.writeInfo(oa),t.writeLen(this.length-n)}getMissing(t,n){return null}},ze=class e{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(t){throw G()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}},ca=e=>new ze(e.readBuf()),zn=class e{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){Oe(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}},la=e=>new zn(e.readLen()),xo=(e,t)=>new ee({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),He=class e{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;let 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 e(xo(this.doc.guid,this.opts))}splice(t){throw G()}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}},aa=e=>new He(xo(e.readString(),e.readAny())),Dt=class e{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(t){throw G()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}},ha=e=>new Dt(e.readJSON()),N=class e{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(t){throw G()}mergeWith(t){return!1}integrate(t,n){let r=n.parent;r._searchMarker=null,r._hasFormatting=!0}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}},da=e=>new N(e.readKey(),e.readJSON()),Xr=class e{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(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){let r=this.arr.length;t.writeLen(r-n);for(let s=n;s<r;s++){let i=this.arr[s];t.writeString(i===void 0?"undefined":JSON.stringify(i))}}getRef(){return 2}},ua=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++){let s=e.readString();s==="undefined"?n.push(void 0):n.push(JSON.parse(s))}return new Xr(n)},fa=_e("node_env")==="development",se=class e{constructor(t){this.arr=t,fa&&pr(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(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){let r=this.arr.length;t.writeLen(r-n);for(let s=n;s<r;s++){let i=this.arr[s];t.writeAny(i)}}getRef(){return 8}},pa=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new se(n)},ut=class e{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new e(this.str)}splice(t){let n=new e(this.str.slice(t));this.str=this.str.slice(0,t);let r=this.str.charCodeAt(t-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+"\uFFFD",n.str="\uFFFD"+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}},ga=e=>new ut(e.readString()),ma=[Xl,Kl,ea,ra,na,sa,ia],wa=0,ya=1,xa=2,ba=3,Sa=4,ka=5,_a=6,it=class e{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(t){throw G()}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(r=>{r.deleted?r.id.clock<(t.beforeState.get(r.id.client)||0)&&t._mergeStructs.push(r):r.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(r=>{for(;r!==null;)r.gc(t,!0),r=r.left}),this.type._map=new Map}write(t,n){this.type._write(t)}getRef(){return 7}},Ua=e=>new it(ma[e.readTypeRef()](e)),Kr=(e,t)=>{let n=t,r=0,s;do r>0&&(n=y(n.client,n.clock+r)),s=Zt(e,n),r=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof _);return{item:s,diff:r}},os=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Hn=(e,t,n)=>{let{client:r,clock:s}=t.id,i=new _(y(r,s+n),t,y(r,s+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},Pi=(e,t)=>ue(e,n=>Ge(n.deletions,t)),bo=(e,t,n,r,s,i)=>{let o=e.doc,c=o.store,l=o.clientID,h=t.redone;if(h!==null)return F(e,h);let a=t.parent._item,d=null,u;if(a!==null&&a.deleted===!0){if(a.redone===null&&(!n.has(a)||bo(e,a,n,r,s,i)===null))return null;for(;a.redone!==null;)a=F(e,a.redone)}let f=a===null?t.parent:a.content.type;if(t.parentSub===null){for(d=t.left,u=t;d!==null;){let b=d;for(;b!==null&&b.parent._item!==a;)b=b.redone===null?null:F(e,b.redone);if(b!==null&&b.parent._item===a){d=b;break}d=d.left}for(;u!==null;){let b=u;for(;b!==null&&b.parent._item!==a;)b=b.redone===null?null:F(e,b.redone);if(b!==null&&b.parent._item===a){u=b;break}u=u.right}}else if(u=null,t.right&&!s){for(d=t;d!==null&&d.right!==null&&(d.right.redone||Ge(r,d.right.id)||Pi(i.undoStack,d.right.id)||Pi(i.redoStack,d.right.id));)for(d=d.right;d.redone;)d=F(e,d.redone);if(d&&d.right!==null)return null}else d=f._map.get(t.parentSub)||null;let p=E(c,l),w=y(l,p),x=new _(w,d,d&&d.lastId,u,u&&u.id,f,t.parentSub,t.content.copy());return t.redone=w,os(x,!0),x.integrate(e,0),x},_=class e extends Pe{constructor(t,n,r,s,i,o,c,l){super(t,l.getLength()),this.origin=r,this.left=n,this.right=s,this.rightOrigin=i,this.parent=o,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?2:0}set marker(t){(this.info&8)>0!==t&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(t){this.keep!==t&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(t){this.deleted!==t&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=E(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=E(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===wt&&this.id.client!==this.parent.client&&this.parent.clock>=E(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Ni(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=F(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===j||this.right&&this.right.constructor===j)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===wt){let r=Zt(n,this.parent);r.constructor===j?this.parent=null:this.parent=r.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=Ni(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 r=this.left,s;if(r!==null)s=r.right;else 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;let i=new Set,o=new Set;for(;s!==null&&s!==this.right;){if(o.add(s),i.add(s),Qt(this.origin,s.origin)){if(s.id.client<this.id.client)r=s,i.clear();else if(Qt(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&o.has(Zt(t.doc.store,s.origin)))i.has(Zt(t.doc.store,s.origin))||(r=s,i.clear());else break;s=s.right}this.left=r}if(this.left!==null){let r=this.left.right;this.right=r,this.left.right=this}else{let r;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,this.parent._start=this;this.right=r}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),Zi(t.doc.store,this),this.content.integrate(t,this),Oi(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new j(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&&Qt(t.origin,this.lastId)&&this.right===t&&Qt(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)){let n=this.parent._searchMarker;return n&&n.forEach(r=>{r.p===t&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){let n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),Oe(t.deleteSet,this.id.client,this.id.clock,this.length),Oi(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw $();this.content.gc(t),n?Bl(t,this,new j(this.id,this.length)):this.content=new zn(this.length)}write(t,n){let r=n>0?y(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,i=this.parentSub,o=this.content.getRef()&31|(r===null?0:128)|(s===null?0:64)|(i===null?0:32);if(t.writeInfo(o),r!==null&&t.writeLeftID(r),s!==null&&t.writeRightID(s),r===null&&s===null){let c=this.parent;if(c._item!==void 0){let l=c._item;if(l===null){let h=Qi(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===wt?(t.writeParentInfo(!1),t.writeLeftID(c)):$();i!==null&&t.writeString(i)}this.content.write(t,n)}},So=(e,t)=>Ea[t&31](e),Ea=[()=>{$()},la,ua,ca,ga,ha,da,Ua,pa,aa,()=>{$()}],Aa=10,P=class extends Pe{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){$()}write(t,n){t.writeInfo(Aa),g(t.restEncoder,this.length-n)}getMissing(t,n){return null}},ko=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},_o="__ $YJS$ __";ko[_o]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");ko[_o]=!0;function Wn(e){return e.endsWith("/")?e.slice(0,-1):e}function cs(e){let t=Wn(String(e??"").trim());if(!t||t==="/")return"";if(/^[a-zA-Z][a-zA-Z\d+.-]*:/u.test(t))try{return cs(new URL(t).pathname)}catch{return""}return t.startsWith("/")?t:`/${t}`}function Ca(e,t){let n=Wn(String(e??"").trim());return!n||n==="/"?t:n.startsWith("/")?n:`/${n}`}function Jn(e,t){let n=cs(e),r=String(t??"").trim();return r?/^[a-zA-Z][a-zA-Z\d+.-]*:/u.test(r)||n&&(r===n||r.startsWith(`${n}/`))?r:r==="/"?n||"/":r.startsWith("/")?n?`${n}${r}`:r:n?`${n}/${r}`:`/${r}`:n||"/"}function le(){let e={auth:{enabled:!1,implemented:!0,loginEndpoint:"/api/auth/oidc/login",provider:"",requiresLogin:!1,sessionEndpoint:"/api/auth/session",statusEndpoint:"/api/auth/status",strategy:"none"},basePath:"",environment:"development",gitEnabled:!0,publicWsBaseUrl:"",wsBasePath:"/ws",...window.__COLLABMD_CONFIG__??{}},t=cs(e.basePath),n={enabled:!1,implemented:!0,loginEndpoint:"/api/auth/oidc/login",provider:"",requiresLogin:!1,sessionEndpoint:"/api/auth/session",statusEndpoint:"/api/auth/status",strategy:"none",...e.auth??{}};return{...e,auth:{...n,loginEndpoint:Jn(t,n.loginEndpoint),sessionEndpoint:Jn(t,n.sessionEndpoint),statusEndpoint:Jn(t,n.statusEndpoint)},basePath:t,wsBasePath:Ca(e.wsBasePath,"/ws")}}function ce(e="/",t=le()){return Jn(t.basePath,e)}function Ia(e="/",t=le()){return new URL(ce(e,t),window.location.origin).toString()}function Ta(e="/",t=le()){let n=String(e??"").trim();return!n||n==="/"?ce("/api",t):n.startsWith("/api")?ce(n,t):ce(`/api${n.startsWith("/")?n:`/${n}`}`,t)}function Da(e=le()){let n=new URLSearchParams(window.location.search).get("server");return n?Wn(n):e.publicWsBaseUrl?Wn(e.publicWsBaseUrl):`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}${ce(e.wsBasePath,e)}`}var Va=["Alice","Bob","Charlie","Dana","Eve","Frank","Grace","Hank","Iris","Jack","Kim","Leo","Maya","Nate","Olivia","Pete","Quinn","Ruby","Sam","Tara"],Na=["#ef4444","#f97316","#eab308","#22c55e","#06b6d4","#3b82f6","#8b5cf6","#ec4899","#14b8a6","#f59e0b","#6366f1","#10b981","#f43f5e","#0ea5e9","#a855f7"];var Eo="collabmd-user-id";function Ao(e){return e[Math.floor(Math.random()*e.length)]}function Co(){let e=new Uint8Array(8);return(globalThis.crypto??{}).getRandomValues?.(e),Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}function La(){return globalThis.crypto?.randomUUID?globalThis.crypto.randomUUID():`${Co()}-${Date.now().toString(36)}`}var ls=null,ae=null;function Oa(){return ls||(ls=Co()),ls}function Ba(e=globalThis.localStorage){if(ae)return ae;try{let t=e?.getItem?.(Eo);if(t)return ae=t,t}catch{}ae=La();try{e?.setItem?.(Eo,ae)}catch{}return ae}function Ma(e){return String(e??"").trim().replace(/\s+/g," ").slice(0,24)||null}function ld(e=null){let t=Ao(Na);return{color:t,colorLight:`${t}33`,name:Ma(e)??Ao(Va),peerId:Oa(),userId:Ba()}}var Io=new Map,as=class{constructor(t){this.room=t,this.onmessage=null,this._onChange=n=>n.key===t&&this.onmessage!==null&&this.onmessage({data:ti(n.newValue||"")}),Rs(this._onChange)}postMessage(t){ln.setItem(this.room,Zs(Qs(t)))}close(){$s(this._onChange)}},va=typeof BroadcastChannel>"u"?as:BroadcastChannel,hs=e=>z(Io,e,()=>{let t=J(),n=new va(e);return n.onmessage=r=>t.forEach(s=>s(r.data,"broadcastchannel")),{bc:n,subs:t}}),To=(e,t)=>(hs(e).subs.add(t),t),Do=(e,t)=>{let n=hs(e),r=n.subs.delete(t);return r&&n.subs.size===0&&(n.bc.close(),Io.delete(e)),r},Vt=(e,t,n=null)=>{let r=hs(e);r.bc.postMessage(t),r.subs.forEach(s=>s(t,n))};var Vo=0,Xn=1,No=2,Kn=(e,t)=>{g(e,Vo);let n=Xi(t);U(e,n)},ds=(e,t,n)=>{g(e,Xn),U(e,Yi(t,n))},$a=(e,t,n)=>ds(t,n,D(e)),Lo=(e,t,n,r)=>{try{qi(t,D(e),n)}catch(s){r?.(s),console.error("Caught error while handling a Yjs update",s)}},Oo=(e,t)=>{g(e,No),U(e,t)},Fa=Lo,Bo=(e,t,n,r,s)=>{let i=m(e);switch(i){case Vo:$a(e,t,n);break;case Xn:Lo(e,n,r,s);break;case No:Fa(e,n,r,s);break;default:throw new Error("Unknown message type")}return i};var Pa=0;var Mo=(e,t,n)=>{m(e)===Pa&&n(t,K(e))};var us=3e4,Qn=class extends Ke{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let n=q();this.getLocalState()!==null&&us/2<=n-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((s,i)=>{i!==this.clientID&&us<=n-s.lastUpdated&&this.states.has(i)&&r.push(i)}),r.length>0&&Zn(this,r,"timeout")},B(us/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){let n=this.clientID,r=this.meta.get(n),s=r===void 0?0:r.clock+1,i=this.states.get(n);t===null?this.states.delete(n):this.states.set(n,t),this.meta.set(n,{clock:s,lastUpdated:q()});let o=[],c=[],l=[],h=[];t===null?h.push(n):i==null?t!=null&&o.push(n):(c.push(n),pt(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){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[t]:n})}getStates(){return this.states}},Zn=(e,t,n)=>{let r=[];for(let s=0;s<t.length;s++){let i=t[s];if(e.states.has(i)){if(e.states.delete(i),i===e.clientID){let o=e.meta.get(i);e.meta.set(i,{clock:o.clock+1,lastUpdated:q()})}r.push(i)}}r.length>0&&(e.emit("change",[{added:[],updated:[],removed:r},n]),e.emit("update",[{added:[],updated:[],removed:r},n]))},he=(e,t,n=e.states)=>{let r=t.length,s=T();g(s,r);for(let i=0;i<r;i++){let o=t[i],c=n.get(o)||null,l=e.meta.get(o).clock;g(s,o),g(s,l),at(s,JSON.stringify(c))}return k(s)};var vo=(e,t,n)=>{let r=Q(t),s=q(),i=[],o=[],c=[],l=[],h=m(r);for(let a=0;a<h;a++){let d=m(r),u=m(r),f=JSON.parse(K(r)),p=e.meta.get(d),w=e.states.get(d),x=p===void 0?0:p.clock;(x<u||x===u&&f===null&&e.states.has(d))&&(f===null?d===e.clientID&&e.getLocalState()!=null?u++:e.states.delete(d):e.states.set(d,f),e.meta.set(d,{clock:u,lastUpdated:s}),p===void 0&&f!==null?i.push(d):p!==void 0&&f===null?l.push(d):f!==null&&(pt(f,w)||c.push(d),o.push(d)))}(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])};var Ro=e=>Hs(e,(t,n)=>`${encodeURIComponent(n)}=${encodeURIComponent(t)}`).join("&");var Nt=0,jo=3,de=1,qa=2,qe=[];qe[Nt]=(e,t,n,r,s)=>{g(e,Nt);let i=Bo(t,e,n.doc,n);r&&i===Xn&&!n.synced&&(n.synced=!0)};qe[jo]=(e,t,n,r,s)=>{g(e,de),U(e,he(n.awareness,Array.from(n.awareness.getStates().keys())))};qe[de]=(e,t,n,r,s)=>{vo(n.awareness,D(t),n)};qe[qa]=(e,t,n,r,s)=>{Mo(t,n.doc,(i,o)=>Ya(n,o))};var $o=3e4,Ya=(e,t)=>console.warn(`Permission denied to access ${e.url}.
|
|
6
|
+
${t}`),Po=(e,t,n)=>{let r=Q(t),s=T(),i=m(r),o=e.messageHandlers[i];return o?o(s,r,e,n,i):console.error("Unable to compute message"),s},ps=(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,Zn(e.awareness,Array.from(e.awareness.getStates().keys()).filter(r=>r!==e.doc.clientID),e),e.emit("status",[{status:"disconnected"}])):e.wsUnsuccessfulReconnects++,setTimeout(zo,Ot(Us(2,e.wsUnsuccessfulReconnects)*100,e.maxBackoffTime),e))},zo=e=>{if(e.shouldConnect&&e.ws===null){let 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=q();let r=Po(e,new Uint8Array(n.data),!0);tn(r)>1&&t.send(k(r))},t.onerror=n=>{e.emit("connection-error",[n,e])},t.onclose=n=>{ps(e,t,n)},t.onopen=()=>{e.wsLastMessageReceived=q(),e.wsconnecting=!1,e.wsconnected=!0,e.wsUnsuccessfulReconnects=0,e.emit("status",[{status:"connected"}]);let n=T();if(g(n,Nt),Kn(n,e.doc),t.send(k(n)),e.awareness.getLocalState()!==null){let r=T();g(r,de),U(r,he(e.awareness,[e.doc.clientID])),t.send(k(r))}},e.emit("status",[{status:"connecting"}])}},fs=(e,t)=>{let n=e.ws;e.wsconnected&&n&&n.readyState===n.OPEN&&n.send(t),e.bcconnected&&Vt(e.bcChannel,t,e)},Fo=class extends St{constructor(t,n,r,{connect:s=!0,awareness:i=new Qn(r),params:o={},protocols:c=[],WebSocketPolyfill:l=WebSocket,resyncInterval:h=-1,maxBackoffTime:a=2500,disableBc:d=!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=r,this._WS=l,this.awareness=i,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=d,this.wsUnsuccessfulReconnects=0,this.messageHandlers=qe.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=s,this._resyncInterval=0,h>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){let u=T();g(u,Nt),Kn(u,r),this.ws.send(k(u))}},h)),this._bcSubscriber=(u,f)=>{if(f!==this){let p=Po(this,new Uint8Array(u),!1);tn(p)>1&&Vt(this.bcChannel,k(p),this)}},this._updateHandler=(u,f)=>{if(f!==this){let p=T();g(p,Nt),Oo(p,u),fs(this,k(p))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:u,updated:f,removed:p},w)=>{let x=u.concat(f).concat(p),b=T();g(b,de),U(b,he(i,x)),fs(this,k(b))},this._exitHandler=()=>{Zn(this.awareness,[r.clientID],"app closed")},ht&&typeof process<"u"&&process.on("exit",this._exitHandler),i.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&$o<q()-this.wsLastMessageReceived&&ps(this,this.ws,null)},$o/10),s&&this.connect()}get url(){let t=Ro(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(),ht&&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||(To(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);let t=T();g(t,Nt),Kn(t,this.doc),Vt(this.bcChannel,k(t),this);let n=T();g(n,Nt),ds(n,this.doc),Vt(this.bcChannel,k(n),this);let r=T();g(r,jo),Vt(this.bcChannel,k(r),this);let s=T();g(s,de),U(s,he(this.awareness,[this.doc.clientID])),Vt(this.bcChannel,k(s),this)}disconnectBc(){let t=T();g(t,de),U(t,he(this.awareness,[this.doc.clientID],new Map)),fs(this,k(t)),this.bcconnected&&(Do(this.bcChannel,this._bcSubscriber),this.bcconnected=!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&ps(this,this.ws,null)}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(zo(this),this.connectBc())}};function pd(){return le()}function Ja(){let e=window.location.hash.startsWith("#")?window.location.hash.slice(1):window.location.hash;return new URLSearchParams(e)}function Ho(e){return e==="staged"||e==="all"||e==="working-tree"?e:"all"}function gd(){let e=Ja();if(e.has("git-file-preview")){let t=e.get("git-file-preview")||null;return{currentFilePath:e.get("current")||t,filePath:t,hash:e.get("hash")||null,type:"git-file-preview"}}if(e.has("git-file-history"))return{filePath:e.get("git-file-history")||null,type:"git-file-history"};if(e.has("git-history"))return{type:"git-history"};if(e.has("git-commit"))return{hash:e.get("git-commit")||null,historyFilePath:e.get("history")||null,path:e.get("path")||null,type:"git-commit"};if(e.has("git-diff")){let t=e.get("git-diff")||null;return{filePath:t,scope:Ho(e.get("scope")||(t?"working-tree":"all")),type:"git-diff"}}return e.has("file")?{filePath:e.get("file"),type:"file"}:{type:"empty"}}function md(e){let t=new URLSearchParams;e&&t.set("file",e),window.location.hash=t.toString()}function wd({filePath:e=null,scope:t="all"}={}){let n=new URLSearchParams;n.set("git-diff",e??""),n.set("scope",Ho(t)),window.location.hash=n.toString()}function yd({hash:e,path:t=null,historyFilePath:n=null}={}){let r=String(e??"").trim(),s=new URLSearchParams;s.set("git-commit",r),n&&s.set("history",n),t&&s.set("path",t),window.location.hash=s.toString()}function xd(){let e=new URLSearchParams;e.set("git-history","1"),window.location.hash=e.toString()}function bd({filePath:e}={}){let t=new URLSearchParams;t.set("git-file-history",e??""),window.location.hash=t.toString()}function Sd({hash:e,path:t,currentFilePath:n=null}={}){let r=String(e??"").trim(),s=new URLSearchParams;s.set("git-file-preview",t??""),n&&s.set("current",n),s.set("hash",r),window.location.hash=s.toString()}var Wa=new Set(["Room reset","Server shutting down"]);function _d(e){!e||typeof e.on!="function"||typeof e.disconnect!="function"||e.on("connection-close",t=>{let n=String(t?.reason||"");Wa.has(n)&&e.disconnect()})}var Xa=2e3,Ka=160,Qa=280,Za=16,th=new Set(["line","text"]);function ot(e){return Number.isFinite(e)?e:null}function Go(e){return e instanceof st?e.toJSON():e&&typeof e=="object"&&!Array.isArray(e)?e:null}function A(e){return typeof e=="string"?e:""}function ms(e){return e instanceof bt?e.toArray():Array.isArray(e)?e:[]}function v(e,t){return e instanceof st?e.get(t):e?.[t]}function eh(e){return ot(v(e,"resolvedAt"))!==null}function Y(e,t){return e instanceof st?e.get(t):e?.[t]}function nh(e){return th.has(e)?e:null}function rh(e){return String(e??"").replace(/\r\n?/g,`
|
|
7
7
|
`).trim().slice(0,Xa)||null}function sh(e){return String(e??"").replace(/\r\n?/g,`
|
|
8
|
-
`).trim().slice(0,Qa)||""}function
|
|
9
|
-
`).replace(/\s+/g," ").trim()}function
|
|
8
|
+
`).trim().slice(0,Qa)||""}function ih(e){return String(e??"").replace(/\r\n?/g,`
|
|
9
|
+
`).replace(/\s+/g," ").trim()}function Ed(e,t=Ka){let n=ih(e);return n?n.length<=t?n:`${n.slice(0,Math.max(t-1,1)).trimEnd()}\u2026`:""}function oh(e){return Array.from(String(e??"").trim()).slice(0,Za).join("")}function ch(e){let t=A(Y(e,"userId")).trim();return t?{reactedAt:ot(Y(e,"reactedAt"))??Date.now(),userColor:A(Y(e,"userColor")),userId:t,userName:A(Y(e,"userName"))||"Anonymous"}:null}function lh(e){let t=oh(Y(e,"emoji"));if(!t)return null;let n=new Map;return ms(Y(e,"users")).forEach(r=>{let s=ch(r);s&&n.set(s.userId,s)}),n.size===0?null:{emoji:t,users:Array.from(n.values())}}function ah(e){let t=new Map;return ms(e).forEach(n=>{let r=lh(n);if(!r)return;let s=t.get(r.emoji);if(!s){t.set(r.emoji,r);return}let i=new Map(s.users.map(o=>[o.userId,o]));r.users.forEach(o=>i.set(o.userId,o)),t.set(r.emoji,{emoji:r.emoji,users:Array.from(i.values())})}),Array.from(t.values())}function gs(e){let t=rh(Y(e,"body"));return t?{body:t,createdAt:ot(Y(e,"createdAt"))??Date.now(),id:A(Y(e,"id"))||ws("comment"),peerId:A(Y(e,"peerId")),reactions:ah(Y(e,"reactions")),userColor:A(Y(e,"userColor")),userName:A(Y(e,"userName"))||"Anonymous"}:null}function hh(e){return ms(e).map(t=>gs(t)).filter(Boolean)}function ws(e="comment"){return globalThis.crypto?.randomUUID?`${e}-${globalThis.crypto.randomUUID()}`:`${e}-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function qo(e={}){let t=nh(e.anchorKind),n=Go(e.anchorStart),r=Go(e.anchorEnd),s=ot(e.anchorStartLine),i=ot(e.anchorEndLine),o=sh(e.anchorQuote);return!t||!n||!r||s===null||i===null?null:{anchorEnd:r,anchorEndLine:Math.max(i,s),anchorKind:t,anchorQuote:o,anchorStart:n,anchorStartLine:Math.max(s,1)}}function Ad(e={}){if(ot(e.resolvedAt)!==null)return null;let t=qo(e),n=gs(e.messages?.[0]);if(!t||!n)return null;let r=new bt,s=e.messages?.map(o=>gs(o)).filter(Boolean)??[];r.push(s.length>0?s:[n]);let i=new st;return i.set("anchorEnd",t.anchorEnd),i.set("anchorEndLine",t.anchorEndLine),i.set("anchorKind",t.anchorKind),i.set("anchorQuote",t.anchorQuote),i.set("anchorStart",t.anchorStart),i.set("anchorStartLine",t.anchorStartLine),i.set("createdAt",ot(e.createdAt)??Date.now()),i.set("createdByColor",A(e.createdByColor)),i.set("createdByName",A(e.createdByName)||n.userName),i.set("createdByPeerId",A(e.createdByPeerId)||n.peerId),i.set("id",A(e.id)||ws("thread")),i.set("messages",r),i.set("resolvedAt",ot(e.resolvedAt)),i.set("resolvedByColor",A(e.resolvedByColor)),i.set("resolvedByName",A(e.resolvedByName)),i.set("resolvedByPeerId",A(e.resolvedByPeerId)),i}function dh(e){if(eh(e))return null;let t=qo({anchorEnd:v(e,"anchorEnd"),anchorEndLine:v(e,"anchorEndLine"),anchorKind:v(e,"anchorKind"),anchorQuote:v(e,"anchorQuote"),anchorStart:v(e,"anchorStart"),anchorStartLine:v(e,"anchorStartLine")}),n=hh(v(e,"messages"));return!t||n.length===0?null:{...t,createdAt:ot(v(e,"createdAt"))??n[0].createdAt,createdByColor:A(v(e,"createdByColor"))||n[0].userColor,createdByName:A(v(e,"createdByName"))||n[0].userName,createdByPeerId:A(v(e,"createdByPeerId"))||n[0].peerId,id:A(v(e,"id"))||ws("thread"),messages:n,resolvedAt:ot(v(e,"resolvedAt")),resolvedByColor:A(v(e,"resolvedByColor")),resolvedByName:A(v(e,"resolvedByName")),resolvedByPeerId:A(v(e,"resolvedByPeerId"))}}function Cd(e){return(e instanceof bt?e.toArray():Array.isArray(e)?e:[]).map(n=>dh(n)).filter(Boolean)}export{Ia as a,Ta as b,Da as c,Ma as d,ld as e,Ot as f,lt as g,tt as h,sl as i,il as j,ee as k,ed as l,nd as m,rd as n,sd as o,id as p,vi as q,bt as r,st as s,Fo as t,pd as u,gd as v,md as w,wd as x,yd as y,xd as z,bd as A,Sd as B,_d as C,Xa as D,rh as E,sh as F,ih as G,Ed as H,ws as I,qo as J,Ad as K,Cd as L};
|