collabmd 0.1.18 → 0.1.19
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 +99 -17
- package/package.json +1 -1
- package/public/assets/css/style.css +1 -1
- package/public/assets/js/chunks/{preview-render-compiler-WD3A76I6.js → chunk-5QRWYPYT.js} +18 -18
- package/public/assets/js/chunks/chunk-HEWVH67U.js +9 -0
- package/public/assets/js/chunks/chunk-R3DDMJHH.js +1 -0
- package/public/assets/js/chunks/editor-session-AH6Z3MXW.js +22 -0
- package/public/assets/js/chunks/preview-render-compiler-UZ4SZDQQ.js +1 -0
- package/public/assets/js/chunks/quick-switcher-controller-J7I3CUET.js +5 -0
- package/public/assets/js/{excalidraw-editor-LKW2AZBU.js → excalidraw-editor-ZDYKMZOL.js} +33 -33
- package/public/assets/js/excalidraw-editor.js +1 -1
- package/public/assets/js/main.js +59 -59
- package/public/assets/js/preview-render-worker.js +19 -19
- package/src/client/application/app-shell/presence-feature.js +2 -1
- package/src/client/application/app-shell/ui-feature.js +113 -1
- package/src/client/application/app-shell/workspace-feature.js +9 -0
- package/src/client/application/preview-render-compiler.js +55 -5
- package/src/client/application/preview-render-executor.js +8 -0
- package/src/client/application/preview-render-worker.js +13 -2
- package/src/client/application/preview-renderer.js +5 -0
- package/src/client/application/workspace-chrome-controller.js +12 -1
- package/src/client/application/workspace-coordinator.js +16 -7
- package/src/client/application/workspace-preview-controller.js +45 -5
- package/src/client/application/workspace-route-controller.js +4 -0
- package/src/client/bootstrap/collabmd-app-shell.js +15 -3
- package/src/client/domain/room.js +37 -0
- package/src/client/domain/vault-utils.js +46 -0
- package/src/client/infrastructure/comment-thread-store.js +98 -0
- package/src/client/infrastructure/editor-paste-utils.js +45 -0
- package/src/client/infrastructure/editor-session.js +10 -0
- package/src/client/infrastructure/editor-view-adapter.js +34 -1
- package/src/client/infrastructure/vault-api-client.js +17 -0
- package/src/client/presentation/comment-markdown-renderer.js +68 -0
- package/src/client/presentation/comment-ui-controller.js +311 -15
- package/src/client/presentation/file-explorer-controller.js +5 -0
- package/src/client/presentation/file-explorer-view.js +10 -2
- package/src/client/presentation/file-tree-state.js +7 -1
- package/src/client/presentation/image-lightbox-controller.js +394 -0
- package/src/client/styles/style.css +539 -14
- package/src/domain/comment-threads.js +95 -13
- package/src/domain/file-kind.js +16 -1
- package/src/server/infrastructure/http/create-vault-api-command-handler.js +48 -2
- package/src/server/infrastructure/http/create-vault-api-query-handler.js +67 -1
- package/src/server/infrastructure/http/request-body.js +11 -2
- package/src/server/infrastructure/persistence/path-utils.js +1 -1
- package/src/server/infrastructure/persistence/vault-file-store.js +187 -2
- package/public/assets/js/chunks/chunk-BBHPYU2R.js +0 -1
- package/public/assets/js/chunks/chunk-OG2TNZEU.js +0 -9
- package/public/assets/js/chunks/chunk-QSTBGTWJ.js +0 -1
- package/public/assets/js/chunks/chunk-SR3U53EQ.js +0 -1
- package/public/assets/js/chunks/editor-session-IHFTYG5D.js +0 -22
- package/public/assets/js/chunks/quick-switcher-controller-JYDIJVAJ.js +0 -5
|
@@ -0,0 +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
|
+
`)}},br=(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=>br(n,r))):Fs(e)?Ht(e,(n,r)=>br(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]),br(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 io(t,this),t}expect(t){return io(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),co=C(Yt),Nc=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,t=>"\\"+t)),lo=e=>{if(Jt.check(e))return[Nc(e)];if(co.check(e))return e.shape.map(t=>t+"");if(po.check(e))return["[+-]?\\d+.?\\d*"];if(go.check(e))return[".*"];if(kn.check(e))return e.shape.map(lo).flat(1);$()},Sr=class extends M{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(lo).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(Sr),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 o=this._isPartial&&!Se(t,s)||r.check(t[s],n);return!o&&n?.extend(s.toString(),r.toString(),typeof t[s],"Object property does not match"),o})}},Bc=e=>new wn(e),Mc=C(wn),Rc=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 o=this.shape.keys.check(s,n);return!o&&n?.extend(s+"","Record",typeof t,o?"Key doesn't match schema":"Value doesn't match value"),o&&this.shape.values.check(r,n)})}},ao=(e,t)=>new yn(e,t),vc=C(yn),xn=class extends M{constructor(t){super(),this.shape=t}check(t,n){return t!=null&&Ht(this.shape,(r,s)=>{let o=r.check(t[s],n);return!o&&n?.extend(s.toString(),"Tuple",typeof r),o})}},$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}},ho=(...e)=>new bn(e),jc=C(bn),Fc=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),kr=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(kr),Gc=V(e=>typeof e=="function"),_r=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(_r,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),uo=()=>!0,_n=V(uo),qc=C(Ae,e=>e.shape===uo),Er=V(e=>typeof e=="bigint"),Yc=V(e=>e===Er),fo=V(e=>typeof e=="symbol"),Oh=V(e=>e===fo),qt=V(e=>typeof e=="number"),po=V(e=>e===qt),Jt=V(e=>typeof e=="string"),go=V(e=>e===Jt),En=V(e=>typeof e=="boolean"),Jc=V(e=>e===En),mo=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),Rh=C(Uint8Array),vh=C(Ee,e=>e.shape===Uint8Array),Xc=Wt(qt,Jt,An,mo,Er,En,fo),$h=(()=>{let e=ho(_n),t=ao(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(Rc.check(e)){let t={};for(let n in e)t[n]=Ie(e[n]);return Bc(t)}else{if(Fc.check(e))return Wt(...e.map(Ie));if(Xc.check(e))return Un(e);if(Gc.check(e))return C(e)}$()},io=Ws?()=>{}:(e,t)=>{let n=new xr;if(!t.check(e,n))throw H(`Expected value to be of type ${t.constructor.name}.
|
|
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(i,E(o.store,i)),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()}gi(e,t,n,c)},yi=(e,t,n,r,s)=>{let o=t,i=L();for(;o&&(!o.countable||o.deleted);){if(!o.deleted&&o.content.constructor===N){let h=o.content;i.set(h.key,h)}o=o.right}let c=0,l=!1;for(;t!==o;){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;(i.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&&ie(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,o=L(),i=Ye(o);for(;s;)s.deleted===!1&&(s.content.constructor===N?ie(i,s.content):(t+=yi(n,r,s,o,i),o=Ye(i),r=s)),s=s.right}),t},ta=e=>{let t=new Set,n=e.doc;for(let[r,s]of e.afterState.entries()){let o=e.beforeState.get(r)||0;s!==o&&ei(e,n.store.clients.get(r),o,s,i=>{!i.deleted&&i.content.constructor===N&&i.constructor!==F&&t.add(i.parent)})}S(n,r=>{te(e,e.deleteSet,s=>{if(s instanceof F||!s.parent._hasFormatting||t.has(s.parent))return;let o=s.parent;s.content.constructor===N?t.add(o):Ql(r,s)});for(let s of t)Zl(s)})},Po=(e,t,n)=>{let r=n,s=Ye(t.currentAttributes),o=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case ot:case Dt:case ut:n<t.right.length&&j(e,y(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}o&&yi(e,o,t.right,s,t.currentAttributes);let i=(t.left||t.right).parent;return i._searchMarker&&Re(i._searchMarker,t.index,-r+n),t},Gr=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,o=new Map,i=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(;i!==null;){switch(i.content.constructor){case ot:case Dt:this.adds(i)?this.deletes(i)||(u(),c="insert",h=i.content.getContent()[0],u()):this.deletes(i)?(c!=="delete"&&(u(),c="delete"),d+=1):i.deleted||(c!=="retain"&&(u(),c="retain"),a+=1);break;case ut:this.adds(i)?this.deletes(i)||(c!=="insert"&&(u(),c="insert"),h+=i.content.str):this.deletes(i)?(c!=="delete"&&(u(),c="delete"),d+=i.length):i.deleted||(c!=="retain"&&(u(),c="retain"),a+=i.length);break;case N:{let{key:f,value:p}=i.content;if(this.adds(i)){if(!this.deletes(i)){let w=s.get(f)??null;mt(w,p)?p!==null&&i.delete(r):(c==="retain"&&u(),mt(p,o.get(f)??null)?delete l[f]:l[f]=p)}}else if(this.deletes(i)){o.set(f,p);let w=s.get(f)??null;mt(w,p)||(c==="retain"&&u(),l[f]=w)}else if(!i.deleted){o.set(f,p);let w=l[f];w!==void 0&&(mt(w,p)?w!==null&&i.delete(r):(c==="retain"&&u(),p===null?delete l[f]:l[f]=p))}i.deleted||(c==="insert"&&u(),ie(s,i.content));break}}i=i.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}},je=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??v(),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 Gr(this,t,n);Yn(this,t,r),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??v();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 o=0;o<t.length;o++){let i=t[o];if(i.insert!==void 0){let c=!n&&typeof i.insert=="string"&&o===t.length-1&&s.right===null&&i.insert.slice(-1)===`
|
|
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}`),Pi=(e,t,n)=>{let r=Q(t),s=T(),o=m(r),i=e.messageHandlers[o];return i?i(s,r,e,n,o):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,Qn(e.awareness,Array.from(e.awareness.getStates().keys()).filter(r=>r!==e.doc.clientID),e),e.emit("status",[{status:"disconnected"}])):e.wsUnsuccessfulReconnects++,setTimeout(zi,Ot(Us(2,e.wsUnsuccessfulReconnects)*100,e.maxBackoffTime),e))},zi=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=Pi(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),Xn(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)},ji=class extends St{constructor(t,n,r,{connect:s=!0,awareness:o=new Kn(r),params:i={},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=i,this.protocols=c,this.roomname=n,this.doc=r,this._WS=l,this.awareness=o,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),Xn(u,r),this.ws.send(k(u))}},h)),this._bcSubscriber=(u,f)=>{if(f!==this){let p=Pi(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),Oi(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(o,x)),fs(this,k(b))},this._exitHandler=()=>{Qn(this.awareness,[r.clientID],"app closed")},ht&&typeof process<"u"&&process.on("exit",this._exitHandler),o.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&$i<q()-this.wsLastMessageReceived&&ps(this,this.ws,null)},$i/10),s&&this.connect()}get url(){let t=vi(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||(Ti(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);let t=T();g(t,Nt),Xn(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,Fi),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&&(Di(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&&(zi(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 Hi(e){return e==="staged"||e==="all"||e==="working-tree"?e:"all"}function gd(){let e=Ja();if(e.has("git-diff")){let t=e.get("git-diff")||null;return{filePath:t,scope:Hi(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",Hi(t)),window.location.hash=n.toString()}var Wa=new Set(["Room reset","Server shutting down"]);function xd(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 it(e){return Number.isFinite(e)?e:null}function Gi(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 R(e,t){return e instanceof st?e.get(t):e?.[t]}function eh(e){return it(R(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
|
+
`).trim().slice(0,Xa)||null}function sh(e){return String(e??"").replace(/\r\n?/g,`
|
|
8
|
+
`).trim().slice(0,Qa)||""}function oh(e){return String(e??"").replace(/\r\n?/g,`
|
|
9
|
+
`).replace(/\s+/g," ").trim()}function Sd(e,t=Ka){let n=oh(e);return n?n.length<=t?n:`${n.slice(0,Math.max(t-1,1)).trimEnd()}\u2026`:""}function ih(e){return Array.from(String(e??"").trim()).slice(0,Za).join("")}function ch(e){let t=A(Y(e,"userId")).trim();return t?{reactedAt:it(Y(e,"reactedAt"))??Date.now(),userColor:A(Y(e,"userColor")),userId:t,userName:A(Y(e,"userName"))||"Anonymous"}:null}function lh(e){let t=ih(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 o=new Map(s.users.map(i=>[i.userId,i]));r.users.forEach(i=>o.set(i.userId,i)),t.set(r.emoji,{emoji:r.emoji,users:Array.from(o.values())})}),Array.from(t.values())}function gs(e){let t=rh(Y(e,"body"));return t?{body:t,createdAt:it(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 qi(e={}){let t=nh(e.anchorKind),n=Gi(e.anchorStart),r=Gi(e.anchorEnd),s=it(e.anchorStartLine),o=it(e.anchorEndLine),i=sh(e.anchorQuote);return!t||!n||!r||s===null||o===null?null:{anchorEnd:r,anchorEndLine:Math.max(o,s),anchorKind:t,anchorQuote:i,anchorStart:n,anchorStartLine:Math.max(s,1)}}function kd(e={}){if(it(e.resolvedAt)!==null)return null;let t=qi(e),n=gs(e.messages?.[0]);if(!t||!n)return null;let r=new bt,s=e.messages?.map(i=>gs(i)).filter(Boolean)??[];r.push(s.length>0?s:[n]);let o=new st;return o.set("anchorEnd",t.anchorEnd),o.set("anchorEndLine",t.anchorEndLine),o.set("anchorKind",t.anchorKind),o.set("anchorQuote",t.anchorQuote),o.set("anchorStart",t.anchorStart),o.set("anchorStartLine",t.anchorStartLine),o.set("createdAt",it(e.createdAt)??Date.now()),o.set("createdByColor",A(e.createdByColor)),o.set("createdByName",A(e.createdByName)||n.userName),o.set("createdByPeerId",A(e.createdByPeerId)||n.peerId),o.set("id",A(e.id)||ws("thread")),o.set("messages",r),o.set("resolvedAt",it(e.resolvedAt)),o.set("resolvedByColor",A(e.resolvedByColor)),o.set("resolvedByName",A(e.resolvedByName)),o.set("resolvedByPeerId",A(e.resolvedByPeerId)),o}function dh(e){if(eh(e))return null;let t=qi({anchorEnd:R(e,"anchorEnd"),anchorEndLine:R(e,"anchorEndLine"),anchorKind:R(e,"anchorKind"),anchorQuote:R(e,"anchorQuote"),anchorStart:R(e,"anchorStart"),anchorStartLine:R(e,"anchorStartLine")}),n=hh(R(e,"messages"));return!t||n.length===0?null:{...t,createdAt:it(R(e,"createdAt"))??n[0].createdAt,createdByColor:A(R(e,"createdByColor"))||n[0].userColor,createdByName:A(R(e,"createdByName"))||n[0].userName,createdByPeerId:A(R(e,"createdByPeerId"))||n[0].peerId,id:A(R(e,"id"))||ws("thread"),messages:n,resolvedAt:it(R(e,"resolvedAt")),resolvedByColor:A(R(e,"resolvedByColor")),resolvedByName:A(R(e,"resolvedByName")),resolvedByPeerId:A(R(e,"resolvedByPeerId"))}}function _d(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,ol as j,ee as k,ed as l,nd as m,rd as n,sd as o,od as p,vo as q,bt as r,st as s,ji as t,pd as u,gd as v,md as w,wd as x,xd as y,Xa as z,rh as A,sh as B,oh as C,Sd as D,ws as E,qi as F,kd as G,_d as H};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function x(t){let e=String(t??"").trim();return e?e.endsWith(".md")?e:`${e}.md`:null}function l(t,e){let n=x(t);if(!n||!Array.isArray(e)||e.length===0)return null;let o=String(t??"").trim();return e.find(r=>r===n||r.endsWith(`/${n}`)||r.replace(/\.md$/i,"")===o)??null}function N(t){return String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function k(t,e){return l(t,e)??void 0}function M(t,e,n){return Math.min(Math.max(t,e),n)}function h(t){return String(t??"").replace(/\\/g,"/").split("/").filter(Boolean)}function _(t,e){let n=h(t),o=String(e??"").split("/").map(u=>{try{return decodeURIComponent(u)}catch{return u}});if(o.length===0)return"";n.pop();let r=[...n];for(let u of o){let c=String(u??"").trim();if(!(!c||c===".")){if(c===".."){if(r.length===0)return"";r.pop();continue}r.push(c)}}return r.join("/")}var s=Object.freeze([".md",".markdown",".mdx"]),m=".excalidraw",p=Object.freeze([".mmd",".mermaid"]),f=Object.freeze([".puml",".plantuml"]),g=Object.freeze([".png",".jpg",".jpeg",".webp",".gif",".svg"]),E=Object.freeze([m,...p,...f]),S=Object.freeze([...s,...E,...g]),T=/\.(?:md|markdown|mdx|excalidraw|mmd|mermaid|puml|plantuml|png|jpe?g|webp|gif|svg)$/i;function d(t){return String(t??"").trim().toLowerCase()}function a(t,e){let n=d(t);return e.some(o=>n.endsWith(o))}function i(t){return a(t,s)?"markdown":a(t,[m])?"excalidraw":a(t,p)?"mermaid":a(t,f)?"plantuml":a(t,g)?"image":null}function P(t){let e=i(t);return e?e==="image"?"image":e==="markdown"?"file":e:null}function O(t){let e=d(t);return S.find(n=>e.endsWith(n))??""}function w(t){return i(t)==="markdown"}function W(t){return i(t)==="excalidraw"}function z(t){return i(t)==="mermaid"}function L(t){return i(t)==="plantuml"}function j(t){return i(t)==="image"}function v(t){let e=i(t);return e==="excalidraw"||e==="mermaid"||e==="plantuml"}function X(t){let e=i(t);return e==="markdown"||e==="mermaid"||e==="plantuml"}function b(t){return w(t)}function R(t){return String(t??"").replace(T,"")}export{N as a,k as b,M as c,_ as d,i as e,P as f,O as g,w as h,W as i,z as j,L as k,j as l,v as m,X as n,b as o,R as p};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import{b as Vn,g as Pn}from"./chunk-X6EEYWV4.js";import"./chunk-OOT2HALX.js";import"./chunk-NO7UPWTU.js";import"./chunk-CGVY4PKT.js";import{e as En,f as In,g as Rn}from"./chunk-OQLLZFFN.js";import{A as mn,Aa as ve,Ba as Dn,C as O,Ca as Bn,D as y,E as dn,Ea as q,F as fn,Fa as we,G as pn,H as gn,I as xn,J as yn,K as Cn,N as ut,O as Sn,P as bn,Q as kn,R as Ln,S as Se,a as ht,aa as f,b as P,c as on,d as rn,e as sn,g as an,ga as be,h as ln,i as p,ia as ke,j as V,ja as c,k as pe,ka as vn,l as ge,la as Le,m as xe,ma as ae,n as F,na as mt,o as j,oa as dt,p as ye,q as v,r as ie,s as se,ta as wn,u as cn,v as hn,w as Ce,x as w,xa as Mn,y as un,ya as An,z as b,za as Tn}from"./chunk-G7NUGGE7.js";import{A as lt,B as re,D as Zt,E as ct,F as en,G as tn,H as nn,c as qt,d as Ht,e as Yt,f as Gt,g as Jt,h as te,i as fe,j as ne,k as Kt,l as G,m as I,n as U,o as R,p as st,q as J,r as at,s as oe,t as Qt,y as Xt}from"./chunk-HEWVH67U.js";import"./chunk-775E65SU.js";function Fn({body:e,user:t}){return{body:e,createdAt:Date.now(),id:ct("comment"),peerId:t?.peerId??"",reactions:[],userColor:t?.color??"",userName:t?.name??"Anonymous"}}function dr(e,t){return e instanceof oe?e.get(t):e?.[t]}function fr(e=[]){return Array.isArray(e)?e.map(t=>({emoji:typeof t?.emoji=="string"?t.emoji:"",users:Array.isArray(t?.users)?t.users.map(n=>({reactedAt:Number.isFinite(n?.reactedAt)?n.reactedAt:Date.now(),userColor:typeof n?.userColor=="string"?n.userColor:"",userId:typeof n?.userId=="string"?n.userId:"",userName:typeof n?.userName=="string"&&n.userName?n.userName:"Anonymous"})).filter(n=>n.userId):[]})).filter(t=>t.emoji&&t.users.length>0):[]}function pr(e,t){let n=t?.doc;if(!n)return null;let o=e?.anchor??e,r=o?.anchorKind==="text"?"text":"line",i=n.lines,s=Math.min(Math.max(Math.round(o?.startLine??1),1),i),a=Math.min(Math.max(Math.round(o?.endLine??s),s),i),l=n.line(s).from,h=n.line(a).to,m=Math.min(Math.max(Math.round(o?.startIndex??l),0),n.length),d=Math.min(Math.max(Math.round(o?.endIndex??h),m),n.length);return{anchorEndLine:a,anchorKind:r,anchorQuote:re(o?.anchorQuote||n.sliceString(m,d)),anchorStartLine:s,endIndex:d,startIndex:m}}var Me=class{constructor({getDoc:t,getEditorState:n,getLocalUser:o,onCommentsChange:r=null}){this.getDoc=t,this.getEditorState=n,this.getLocalUser=o,this.onCommentsChange=r,this.commentThreads=null,this.ydoc=null,this.ytext=null,this.handleCommentThreadsChange=null,this.handleTextChange=null}bind({commentThreads:t,ydoc:n,ytext:o}){this.unbind(),this.commentThreads=t,this.ydoc=n,this.ytext=o,this.handleCommentThreadsChange=()=>{this.emitCommentsChange()},this.handleTextChange=()=>{this.emitCommentsChange()},this.commentThreads.observeDeep(this.handleCommentThreadsChange),this.ytext?.observe?.(this.handleTextChange),this.emitCommentsChange()}unbind(){this.commentThreads&&this.handleCommentThreadsChange&&this.commentThreads.unobserveDeep(this.handleCommentThreadsChange),this.ytext&&this.handleTextChange&&this.ytext.unobserve(this.handleTextChange),this.commentThreads=null,this.ydoc=null,this.ytext=null,this.handleCommentThreadsChange=null,this.handleTextChange=null}emitCommentsChange(){this.onCommentsChange?.(this.getCommentThreads())}getCommentThreads(){return this.commentThreads?nn(this.commentThreads).map(t=>this.resolveCommentThread(t)).filter(Boolean):[]}createCommentThread({anchor:t,body:n}){let o=this.getEditorState();if(!o||!this.commentThreads||!this.ytext||!this.ydoc)return null;let r=lt(n),i=pr(t,o);if(!r||!i)return null;let s=tn({anchorEnd:G(U(this.ytext,i.endIndex)),anchorEndLine:i.anchorEndLine,anchorKind:i.anchorKind,anchorQuote:i.anchorQuote,anchorStart:G(U(this.ytext,i.startIndex)),anchorStartLine:i.anchorStartLine,createdAt:Date.now(),createdByColor:this.getLocalUser()?.color??"",createdByName:this.getLocalUser()?.name??"Anonymous",createdByPeerId:this.getLocalUser()?.peerId??"",id:ct("thread"),messages:[Fn({body:r,user:this.getLocalUser()})]});return s?(this.ydoc.transact(()=>{this.commentThreads.push([s])},"comment-thread-create"),s.get("id")):null}replyToCommentThread(t,n){let o=lt(n);if(!o||!this.ydoc)return null;let i=this.findSharedCommentThread(t)?.get("messages");if(!(i instanceof at))return null;let s=Fn({body:o,user:this.getLocalUser()});return this.ydoc.transact(()=>{i.push([s])},"comment-thread-reply"),s.id}toggleCommentReaction(t,n,o){if(!this.ydoc||!t||!n||typeof o!="string"||!o.trim())return!1;let r=this.getLocalUser?.(),i=typeof r?.userId=="string"?r.userId:"";if(!i)return!1;let a=this.findSharedCommentThread(t)?.get("messages");if(!(a instanceof at))return!1;let l=a.toArray(),h=l.findIndex(x=>dr(x,"id")===n);if(h<0)return!1;let m=l[h]instanceof oe?l[h].toJSON():{...l[h]},d=fr(m.reactions),g=d.findIndex(x=>x.emoji===o);if(g>=0){let x=d[g].users.filter(S=>S.userId!==i);x.length===d[g].users.length&&x.push({reactedAt:Date.now(),userColor:r?.color??"",userId:i,userName:r?.name??"Anonymous"}),x.length===0?d.splice(g,1):d[g]={...d[g],users:x}}else d.push({emoji:o,users:[{reactedAt:Date.now(),userColor:r?.color??"",userId:i,userName:r?.name??"Anonymous"}]});let C={...m,reactions:d};return this.ydoc.transact(()=>{a.delete(h,1),a.insert(h,[C])},"comment-reaction-toggle"),!0}deleteCommentThread(t){if(!this.commentThreads||!this.ydoc)return!1;let n=this.findSharedCommentThreadIndex(t);return n<0?!1:(this.ydoc.transact(()=>{this.commentThreads.delete(n,1)},"comment-thread-resolve"),!0)}findSharedCommentThread(t){return this.commentThreads?this.commentThreads.toArray().find(n=>n instanceof oe&&n.get("id")===t)??null:null}findSharedCommentThreadIndex(t){return this.commentThreads?this.commentThreads.toArray().findIndex(n=>n instanceof oe&&n.get("id")===t):-1}resolveCommentThread(t){let n=this.getEditorState();if(!t||!n||!this.ydoc)return null;let o=en(t);if(!o)return null;let r=this.resolveCommentPosition(o.anchorStart),i=this.resolveCommentPosition(o.anchorEnd),s=r?.index??n.doc.line(o.anchorStartLine).from,a=Math.min(Math.max(o.anchorEndLine??o.anchorStartLine,o.anchorStartLine),n.doc.lines),l=i?.index??n.doc.line(a).to,h=n.doc.lineAt(s).number,m=Math.min(Math.max(l,s),n.doc.length),d=n.doc.lineAt(m).number,g=n.doc.sliceString(s,o.anchorKind==="text"?Math.max(l,s):n.doc.line(d).to),C=Zt(g)||o.anchorQuote;return{...t,anchor:{endIndex:l,endLine:d,excerpt:C,quote:o.anchorQuote,startIndex:s,startLine:h,kind:o.anchorKind},anchorEnd:o.anchorEnd,anchorEndLine:o.anchorEndLine,anchorKind:o.anchorKind,anchorQuote:o.anchorQuote,anchorStart:o.anchorStart,anchorStartLine:o.anchorStartLine}}resolveCommentPosition(t){if(!t||!this.ydoc||!this.ytext)return null;try{let n=I(t),o=R(n,this.ydoc);return!o||o.type!==this.ytext?null:o}catch{return null}}};var Ae=class{constructor({localUser:t=null,onAwarenessChange:n=null,onConnectionChange:o=null,onInitialSync:r=null,preferredUserName:i,resolveAwarenessCursor:s=null}){this.onAwarenessChange=n,this.onConnectionChange=o,this.onInitialSync=r,this.preferredUserName=i,this.providedLocalUser=t,this.resolveAwarenessCursor=s??(()=>null),this.provider=null,this.awareness=null,this.localUser=null,this.ydoc=null,this.ytext=null,this.commentThreads=null,this.wsBaseUrl="",this.initialSyncComplete=!1,this.initialSyncPromise=Promise.resolve(),this.resolveInitialSync=null}normalizeViewport(t){if(!t||typeof t!="object")return null;let n=Number(t.topLine),o=Number(t.viewportRatio);return!Number.isFinite(n)||n<1?null:{topLine:Math.max(1,Math.round(n)),viewportRatio:Number.isFinite(o)?Math.min(Math.max(o,0),1):.35}}async initialize(t){this.wsBaseUrl=qt(),this.ydoc=new Kt,this.ytext=this.ydoc.getText("codemirror"),this.commentThreads=this.ydoc.getArray("comments");let n=new J(this.ytext),o=new Qt(this.wsBaseUrl,t,this.ydoc,{disableBc:!0,maxBackoffTime:5e3});Xt(o);let r=o.awareness,i=this.providedLocalUser??Yt(this.preferredUserName);this.provider=o,this.awareness=r,this.localUser=i,this.initialSyncComplete=!1,this.initialSyncPromise=new Promise(a=>{this.resolveInitialSync=a}),r.setLocalStateField("user",i),r.on("change",()=>{this.onAwarenessChange?.(this.collectUsers(this.resolveAwarenessCursor))}),this.trackConnectionStatus();let s=!1;return o.on("sync",a=>{!a||s||(s=!0,this.initialSyncComplete=!0,this.resolveInitialSync?.(),this.resolveInitialSync=null,this.onInitialSync?.())}),{awareness:r,commentThreads:this.commentThreads,localUser:this.localUser,undoManager:n,ydoc:this.ydoc,ytext:this.ytext}}destroy(){this.resolveInitialSync?.(),this.resolveInitialSync=null,this.initialSyncComplete=!1,this.initialSyncPromise=Promise.resolve(),this.provider?.disconnect(),this.provider?.destroy(),this.provider=null,this.awareness=null,this.localUser=null,this.ydoc?.destroy(),this.ydoc=null,this.ytext=null,this.commentThreads=null}waitForInitialSync(t=1500){return this.initialSyncComplete?Promise.resolve():Promise.race([this.initialSyncPromise,new Promise(n=>{window.setTimeout(n,t)})])}getText(){return this.ytext?.toString()??""}getLocalUser(){return this.localUser}setUserName(t){let n=Ht(t);return!n||!this.awareness||!this.localUser?null:(this.localUser={...this.localUser,name:n},this.awareness.setLocalStateField("user",this.localUser),n)}getUserCursor(t,n){if(!this.awareness)return null;let o=this.awareness.getStates().get(t);return n(o?.cursor)}getUserViewport(t){if(!this.awareness)return null;let n=this.awareness.getStates().get(t);return this.normalizeViewport(n?.viewport)}setLocalViewport(t){if(!this.awareness)return null;let n=this.normalizeViewport(t);return this.awareness.setLocalStateField("viewport",n),n}collectUsers(t=()=>null){if(!this.awareness)return[];let n=[];return this.awareness.getStates().forEach((o,r)=>{if(!o.user)return;let i=t(o.cursor);n.push({...i??{},...o.user,clientId:r,hasCursor:!!i,isLocal:r===this.awareness.clientID,viewport:this.normalizeViewport(o.viewport)})}),n}trackConnectionStatus(){if(!this.provider)return;let t=0,n=!1;this.provider.on("status",({status:o})=>{o==="connecting"&&(t+=1);let r=o==="connected"&&!n;o==="connected"&&(t=0,n=!0),this.onConnectionChange?.({attempts:t,firstConnection:r,hasEverConnected:n,status:o,unreachable:!n&&t>=3,wsBaseUrl:this.wsBaseUrl})})}};var gr=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),o=St(e.state,n.from);return o.line?xr(e):o.block?Cr(e):!1};function Ct(e,t){return({state:n,dispatch:o})=>{if(n.readOnly)return!1;let r=e(t,n);return r?(o(n.update(r)),!0):!1}}var xr=Ct(kr,0);var yr=Ct(qn,0);var Cr=Ct((e,t)=>qn(e,t,br(t)),0);function St(e,t){let n=e.languageDataAt("commentTokens",t,1);return n.length?n[0]:{}}var le=50;function Sr(e,{open:t,close:n},o,r){let i=e.sliceDoc(o-le,o),s=e.sliceDoc(r,r+le),a=/\s*$/.exec(i)[0].length,l=/^\s*/.exec(s)[0].length,h=i.length-a;if(i.slice(h-t.length,h)==t&&s.slice(l,l+n.length)==n)return{open:{pos:o-a,margin:a&&1},close:{pos:r+l,margin:l&&1}};let m,d;r-o<=2*le?m=d=e.sliceDoc(o,r):(m=e.sliceDoc(o,o+le),d=e.sliceDoc(r-le,r));let g=/^\s*/.exec(m)[0].length,C=/\s*$/.exec(d)[0].length,x=d.length-C-n.length;return m.slice(g,g+t.length)==t&&d.slice(x,x+n.length)==n?{open:{pos:o+g+t.length,margin:/\s/.test(m.charAt(g+t.length))?1:0},close:{pos:r-C-n.length,margin:/\s/.test(d.charAt(x-1))?1:0}}:null}function br(e){let t=[];for(let n of e.selection.ranges){let o=e.doc.lineAt(n.from),r=n.to<=o.to?o:e.doc.lineAt(n.to);r.from>o.from&&r.from==n.to&&(r=n.to==o.to+1?o:e.doc.lineAt(n.to-1));let i=t.length-1;i>=0&&t[i].to>o.from?t[i].to=r.to:t.push({from:o.from+/^\s*/.exec(o.text)[0].length,to:r.to})}return t}function qn(e,t,n=t.selection.ranges){let o=n.map(i=>St(t,i.from).block);if(!o.every(i=>i))return null;let r=n.map((i,s)=>Sr(t,o[s],i.from,i.to));if(e!=2&&!r.every(i=>i))return{changes:t.changes(n.map((i,s)=>r[s]?[]:[{from:i.from,insert:o[s].open+" "},{from:i.to,insert:" "+o[s].close}]))};if(e!=1&&r.some(i=>i)){let i=[];for(let s=0,a;s<r.length;s++)if(a=r[s]){let l=o[s],{open:h,close:m}=a;i.push({from:h.pos-l.open.length,to:h.pos+h.margin},{from:m.pos-m.margin,to:m.pos+l.close.length})}return{changes:i}}return null}function kr(e,t,n=t.selection.ranges){let o=[],r=-1;e:for(let{from:i,to:s}of n){let a=o.length,l=1e9,h;for(let m=i;m<=s;){let d=t.doc.lineAt(m);if(h==null&&(h=St(t,d.from).line,!h))continue e;if(d.from>r&&(i==s||s>d.from)){r=d.from;let g=/^\s*/.exec(d.text)[0].length,C=g==d.length,x=d.text.slice(g,g+h.length)==h?g:-1;g<d.text.length&&g<l&&(l=g),o.push({line:d,comment:x,token:h,indent:g,empty:C,single:!1})}m=d.to+1}if(l<1e9)for(let m=a;m<o.length;m++)o[m].indent<o[m].line.text.length&&(o[m].indent=l);o.length==a+1&&(o[a].single=!0)}if(e!=2&&o.some(i=>i.comment<0&&(!i.empty||i.single))){let i=[];for(let{line:a,token:l,indent:h,empty:m,single:d}of o)(d||!m)&&i.push({from:a.from+h,insert:l+" "});let s=t.changes(i);return{changes:s,selection:t.selection.map(s,1)}}else if(e!=1&&o.some(i=>i.comment>=0)){let i=[];for(let{line:s,comment:a,token:l}of o)if(a>=0){let h=s.from+a,m=h+l.length;s.text[m-s.from]==" "&&m++,i.push({from:h,to:m})}return{changes:i}}return null}var pt=F.define(),Lr=F.define(),vr=V.define(),Hn=V.define({combine(e){return se(e,{minDepth:100,newGroupDelay:500,joinToEvent:(t,n)=>n},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,n)=>(o,r)=>t(o,r)||n(o,r)})}}),Yn=pe.define({create(){return H.empty},update(e,t){let n=t.state.facet(Hn),o=t.annotation(pt);if(o){let l=D.fromTransaction(t,o.selection),h=o.side,m=h==0?e.undone:e.done;return l?m=De(m,m.length,n.minDepth,l):m=Qn(m,t.startState.selection),new H(h==0?o.rest:m,h==0?m:o.rest)}let r=t.annotation(Lr);if((r=="full"||r=="before")&&(e=e.isolate()),t.annotation(ye.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let i=D.fromTransaction(t),s=t.annotation(ye.time),a=t.annotation(ye.userEvent);return i?e=e.addChanges(i,s,a,n,t):t.selection&&(e=e.addSelection(t.startState.selection,s,a,n.newGroupDelay)),(r=="full"||r=="after")&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(t=>t.toJSON()),undone:e.undone.map(t=>t.toJSON())}},fromJSON(e){return new H(e.done.map(D.fromJSON),e.undone.map(D.fromJSON))}});function Gn(e={}){return[Yn,Hn.of(e),y.domEventHandlers({beforeinput(t,n){let o=t.inputType=="historyUndo"?Jn:t.inputType=="historyRedo"?gt:null;return o?(t.preventDefault(),o(n)):!1}})]}function Be(e,t){return function({state:n,dispatch:o}){if(!t&&n.readOnly)return!1;let r=n.field(Yn,!1);if(!r)return!1;let i=r.pop(e,n,t);return i?(o(i),!0):!1}}var Jn=Be(0,!1),gt=Be(1,!1),wr=Be(0,!0),Mr=Be(1,!0);var D=class e{constructor(t,n,o,r,i){this.changes=t,this.effects=n,this.mapped=o,this.startSelection=r,this.selectionsAfter=i}setSelAfter(t){return new e(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,n,o;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(n=this.mapped)===null||n===void 0?void 0:n.toJSON(),startSelection:(o=this.startSelection)===null||o===void 0?void 0:o.toJSON(),selectionsAfter:this.selectionsAfter.map(r=>r.toJSON())}}static fromJSON(t){return new e(t.changes&&ln.fromJSON(t.changes),[],t.mapped&&an.fromJSON(t.mapped),t.startSelection&&p.fromJSON(t.startSelection),t.selectionsAfter.map(p.fromJSON))}static fromTransaction(t,n){let o=A;for(let r of t.startState.facet(vr)){let i=r(t);i.length&&(o=o.concat(i))}return!o.length&&t.changes.empty?null:new e(t.changes.invert(t.startState.doc),o,void 0,n||t.startState.selection,A)}static selection(t){return new e(void 0,A,void 0,void 0,t)}};function De(e,t,n,o){let r=t+1>n+20?t-n-1:0,i=e.slice(r,t);return i.push(o),i}function Ar(e,t){let n=[],o=!1;return e.iterChangedRanges((r,i)=>n.push(r,i)),t.iterChangedRanges((r,i,s,a)=>{for(let l=0;l<n.length;){let h=n[l++],m=n[l++];a>=h&&s<=m&&(o=!0)}}),o}function Tr(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((n,o)=>n.empty!=t.ranges[o].empty).length===0}function Kn(e,t){return e.length?t.length?e.concat(t):e:t}var A=[],Dr=200;function Qn(e,t){if(e.length){let n=e[e.length-1],o=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-Dr));return o.length&&o[o.length-1].eq(t)?e:(o.push(t),De(e,e.length-1,1e9,n.setSelAfter(o)))}else return[D.selection([t])]}function Br(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function ft(e,t){if(!e.length)return e;let n=e.length,o=A;for(;n;){let r=Er(e[n-1],t,o);if(r.changes&&!r.changes.empty||r.effects.length){let i=e.slice(0,n);return i[n-1]=r,i}else t=r.mapped,n--,o=r.selectionsAfter}return o.length?[D.selection(o)]:A}function Er(e,t,n){let o=Kn(e.selectionsAfter.length?e.selectionsAfter.map(a=>a.map(t)):A,n);if(!e.changes)return D.selection(o);let r=e.changes.map(t),i=t.mapDesc(e.changes,!0),s=e.mapped?e.mapped.composeDesc(i):i;return new D(r,j.mapEffects(e.effects,t),s,e.startSelection.map(i),o)}var Ir=/^(input\.type|delete)($|\.)/,H=class e{constructor(t,n,o=0,r=void 0){this.done=t,this.undone=n,this.prevTime=o,this.prevUserEvent=r}isolate(){return this.prevTime?new e(this.done,this.undone):this}addChanges(t,n,o,r,i){let s=this.done,a=s[s.length-1];return a&&a.changes&&!a.changes.empty&&t.changes&&(!o||Ir.test(o))&&(!a.selectionsAfter.length&&n-this.prevTime<r.newGroupDelay&&r.joinToEvent(i,Ar(a.changes,t.changes))||o=="input.type.compose")?s=De(s,s.length-1,r.minDepth,new D(t.changes.compose(a.changes),Kn(j.mapEffects(t.effects,a.changes),a.effects),a.mapped,a.startSelection,A)):s=De(s,s.length,r.minDepth,t),new e(s,A,n,o)}addSelection(t,n,o,r){let i=this.done.length?this.done[this.done.length-1].selectionsAfter:A;return i.length>0&&n-this.prevTime<r&&o==this.prevUserEvent&&o&&/^select($|\.)/.test(o)&&Tr(i[i.length-1],t)?this:new e(Qn(this.done,t),this.undone,n,o)}addMapping(t){return new e(ft(this.done,t),ft(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,n,o){let r=t==0?this.done:this.undone;if(r.length==0)return null;let i=r[r.length-1],s=i.selectionsAfter[0]||(i.startSelection?i.startSelection.map(i.changes.invertedDesc,1):n.selection);if(o&&i.selectionsAfter.length)return n.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:pt.of({side:t,rest:Br(r),selection:s}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(i.changes){let a=r.length==1?A:r.slice(0,r.length-1);return i.mapped&&(a=ft(a,i.mapped)),n.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:pt.of({side:t,rest:a,selection:s}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}};H.empty=new H(A,A);var Xn=[{key:"Mod-z",run:Jn,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:gt,preventDefault:!0},{linux:"Ctrl-Shift-z",run:gt,preventDefault:!0},{key:"Mod-u",run:wr,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Mr,preventDefault:!0}];function Q(e,t){return p.create(e.ranges.map(t),e.mainIndex)}function B(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function E({state:e,dispatch:t},n){let o=Q(e.selection,n);return o.eq(e.selection,!0)?!1:(t(B(e,o)),!0)}function Ee(e,t){return p.cursor(t?e.to:e.from)}function Zn(e,t){return E(e,n=>n.empty?e.moveByChar(n,t):Ee(n,t))}function L(e){return e.textDirectionAt(e.state.selection.main.head)==mn.LTR}var eo=e=>Zn(e,!L(e)),to=e=>Zn(e,L(e));function no(e,t){return E(e,n=>n.empty?e.moveByGroup(n,t):Ee(n,t))}var Rr=e=>no(e,!L(e)),Vr=e=>no(e,L(e));var $s=typeof Intl<"u"&&Intl.Segmenter?new Intl.Segmenter(void 0,{granularity:"word"}):null;function Pr(e,t,n){if(t.type.prop(n))return!0;let o=t.to-t.from;return o&&(o>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function Ie(e,t,n){let o=be(e).resolveInner(t.head),r=n?Se.closedBy:Se.openedBy;for(let l=t.head;;){let h=n?o.childAfter(l):o.childBefore(l);if(!h)break;Pr(e,h,r)?o=h:l=n?h.to:h.from}let i=o.type.prop(r),s,a;return i&&(s=n?q(e,o.from,1):q(e,o.to,-1))&&s.matched?a=n?s.end.to:s.end.from:a=n?o.to:o.from,p.cursor(a,n?-1:1)}var Fr=e=>E(e,t=>Ie(e.state,t,!L(e))),Or=e=>E(e,t=>Ie(e.state,t,L(e)));function oo(e,t){return E(e,n=>{if(!n.empty)return Ee(n,t);let o=e.moveVertically(n,t);return o.head!=n.head?o:e.moveToLineBoundary(n,t)})}var ro=e=>oo(e,!1),io=e=>oo(e,!0);function so(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,o=0,r;if(t){for(let i of e.state.facet(y.scrollMargins)){let s=i(e);s?.top&&(n=Math.max(s?.top,n)),s?.bottom&&(o=Math.max(s?.bottom,o))}r=e.scrollDOM.clientHeight-n-o}else r=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:o,selfScroll:t,height:Math.max(e.defaultLineHeight,r-5)}}function ao(e,t){let n=so(e),{state:o}=e,r=Q(o.selection,s=>s.empty?e.moveVertically(s,t,n.height):Ee(s,t));if(r.eq(o.selection))return!1;let i;if(n.selfScroll){let s=e.coordsAtPos(o.selection.main.head),a=e.scrollDOM.getBoundingClientRect(),l=a.top+n.marginTop,h=a.bottom-n.marginBottom;s&&s.top>l&&s.bottom<h&&(i=y.scrollIntoView(r.main.head,{y:"start",yMargin:s.top-l}))}return e.dispatch(B(o,r),{effects:i}),!0}var On=e=>ao(e,!1),xt=e=>ao(e,!0);function N(e,t,n){let o=e.lineBlockAt(t.head),r=e.moveToLineBoundary(t,n);if(r.head==t.head&&r.head!=(n?o.to:o.from)&&(r=e.moveToLineBoundary(t,n,!1)),!n&&r.head==o.from&&o.length){let i=/^\s*/.exec(e.state.sliceDoc(o.from,Math.min(o.from+100,o.to)))[0].length;i&&t.head!=o.from+i&&(r=p.cursor(o.from+i))}return r}var Ur=e=>E(e,t=>N(e,t,!0)),Nr=e=>E(e,t=>N(e,t,!1)),Wr=e=>E(e,t=>N(e,t,!L(e))),$r=e=>E(e,t=>N(e,t,L(e))),zr=e=>E(e,t=>p.cursor(e.lineBlockAt(t.head).from,1)),_r=e=>E(e,t=>p.cursor(e.lineBlockAt(t.head).to,-1));function jr(e,t,n){let o=!1,r=Q(e.selection,i=>{let s=q(e,i.head,-1)||q(e,i.head,1)||i.head>0&&q(e,i.head-1,1)||i.head<e.doc.length&&q(e,i.head+1,-1);if(!s||!s.end)return i;o=!0;let a=s.start.from==i.head?s.end.to:s.end.from;return n?p.range(i.anchor,a):p.cursor(a)});return o?(t(B(e,r)),!0):!1}var qr=({state:e,dispatch:t})=>jr(e,t,!1);function T(e,t){let n=Q(e.state.selection,o=>{let r=t(o);return p.range(o.anchor,r.head,r.goalColumn,r.bidiLevel||void 0)});return n.eq(e.state.selection)?!1:(e.dispatch(B(e.state,n)),!0)}function lo(e,t){return T(e,n=>e.moveByChar(n,t))}var co=e=>lo(e,!L(e)),ho=e=>lo(e,L(e));function uo(e,t){return T(e,n=>e.moveByGroup(n,t))}var Hr=e=>uo(e,!L(e)),Yr=e=>uo(e,L(e));var Gr=e=>T(e,t=>Ie(e.state,t,!L(e))),Jr=e=>T(e,t=>Ie(e.state,t,L(e)));function mo(e,t){return T(e,n=>e.moveVertically(n,t))}var fo=e=>mo(e,!1),po=e=>mo(e,!0);function go(e,t){return T(e,n=>e.moveVertically(n,t,so(e).height))}var Un=e=>go(e,!1),Nn=e=>go(e,!0),Kr=e=>T(e,t=>N(e,t,!0)),Qr=e=>T(e,t=>N(e,t,!1)),Xr=e=>T(e,t=>N(e,t,!L(e))),Zr=e=>T(e,t=>N(e,t,L(e))),ei=e=>T(e,t=>p.cursor(e.lineBlockAt(t.head).from)),ti=e=>T(e,t=>p.cursor(e.lineBlockAt(t.head).to)),Wn=({state:e,dispatch:t})=>(t(B(e,{anchor:0})),!0),$n=({state:e,dispatch:t})=>(t(B(e,{anchor:e.doc.length})),!0),zn=({state:e,dispatch:t})=>(t(B(e,{anchor:e.selection.main.anchor,head:0})),!0),_n=({state:e,dispatch:t})=>(t(B(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),ni=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0),oi=({state:e,dispatch:t})=>{let n=Re(e).map(({from:o,to:r})=>p.range(o,Math.min(r+1,e.doc.length)));return t(e.update({selection:p.create(n),userEvent:"select"})),!0},ri=({state:e,dispatch:t})=>{let n=Q(e.selection,o=>{let r=be(e),i=r.resolveStack(o.from,1);if(o.empty){let s=r.resolveStack(o.from,-1);s.node.from>=i.node.from&&s.node.to<=i.node.to&&(i=s)}for(let s=i;s;s=s.next){let{node:a}=s;if((a.from<o.from&&a.to>=o.to||a.to>o.to&&a.from<=o.from)&&s.next)return p.range(a.to,a.from)}return o});return n.eq(e.selection)?!1:(t(B(e,n)),!0)};function xo(e,t){let{state:n}=e,o=n.selection,r=n.selection.ranges.slice();for(let i of n.selection.ranges){let s=n.doc.lineAt(i.head);if(t?s.to<e.state.doc.length:s.from>0)for(let a=i;;){let l=e.moveVertically(a,t);if(l.head<s.from||l.head>s.to){r.some(h=>h.head==l.head)||r.push(l);break}else{if(l.head==a.head)break;a=l}}}return r.length==o.ranges.length?!1:(e.dispatch(B(n,p.create(r,r.length-1))),!0)}var ii=e=>xo(e,!1),si=e=>xo(e,!0),ai=({state:e,dispatch:t})=>{let n=e.selection,o=null;return n.ranges.length>1?o=p.create([n.main]):n.main.empty||(o=p.create([p.cursor(n.main.head)])),o?(t(B(e,o)),!0):!1};function ce(e,t){if(e.state.readOnly)return!1;let n="delete.selection",{state:o}=e,r=o.changeByRange(i=>{let{from:s,to:a}=i;if(s==a){let l=t(i);l<s?(n="delete.backward",l=Te(e,l,!1)):l>s&&(n="delete.forward",l=Te(e,l,!0)),s=Math.min(s,l),a=Math.max(a,l)}else s=Te(e,s,!1),a=Te(e,a,!0);return s==a?{range:i}:{changes:{from:s,to:a},range:p.cursor(s,s<i.head?-1:1)}});return r.changes.empty?!1:(e.dispatch(o.update(r,{scrollIntoView:!0,userEvent:n,effects:n=="delete.selection"?y.announce.of(o.phrase("Selection deleted")):void 0})),!0)}function Te(e,t,n){if(e instanceof y)for(let o of e.state.facet(y.atomicRanges).map(r=>r(e)))o.between(t,t,(r,i)=>{r<t&&i>t&&(t=n?i:r)});return t}var yo=(e,t,n)=>ce(e,o=>{let r=o.from,{state:i}=e,s=i.doc.lineAt(r),a,l;if(n&&!t&&r>s.from&&r<s.from+200&&!/[^ \t]/.test(a=s.text.slice(0,r-s.from))){if(a[a.length-1]==" ")return r-1;let h=Ce(a,i.tabSize),m=h%Le(i)||Le(i);for(let d=0;d<m&&a[a.length-1-d]==" ";d++)r--;l=r}else l=P(s.text,r-s.from,t,t)+s.from,l==r&&s.number!=(t?i.doc.lines:1)?l+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(s.text.slice(l-s.from,r-s.from))&&(l=P(s.text,l-s.from,!1,!1)+s.from);return l}),yt=e=>yo(e,!1,!0);var Co=e=>yo(e,!0,!1),So=(e,t)=>ce(e,n=>{let o=n.head,{state:r}=e,i=r.doc.lineAt(o),s=r.charCategorizer(o);for(let a=null;;){if(o==(t?i.to:i.from)){o==n.head&&i.number!=(t?r.doc.lines:1)&&(o+=t?1:-1);break}let l=P(i.text,o-i.from,t)+i.from,h=i.text.slice(Math.min(o,l)-i.from,Math.max(o,l)-i.from),m=s(h);if(a!=null&&m!=a)break;(h!=" "||o!=n.head)&&(a=m),o=l}return o}),bo=e=>So(e,!1),li=e=>So(e,!0);var ci=e=>ce(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)});var hi=e=>ce(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),ui=e=>ce(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)});var mi=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(o=>({changes:{from:o.from,to:o.to,insert:ht.of(["",""])},range:p.cursor(o.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},di=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(o=>{if(!o.empty||o.from==0||o.from==e.doc.length)return{range:o};let r=o.from,i=e.doc.lineAt(r),s=r==i.from?r-1:P(i.text,r-i.from,!1)+i.from,a=r==i.to?r+1:P(i.text,r-i.from,!0)+i.from;return{changes:{from:s,to:a,insert:e.doc.slice(r,a).append(e.doc.slice(s,r))},range:p.cursor(a)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function Re(e){let t=[],n=-1;for(let o of e.selection.ranges){let r=e.doc.lineAt(o.from),i=e.doc.lineAt(o.to);if(!o.empty&&o.to==i.from&&(i=e.doc.lineAt(o.to-1)),n>=r.number){let s=t[t.length-1];s.to=i.to,s.ranges.push(o)}else t.push({from:r.from,to:i.to,ranges:[o]});n=i.number+1}return t}function ko(e,t,n){if(e.readOnly)return!1;let o=[],r=[];for(let i of Re(e)){if(n?i.to==e.doc.length:i.from==0)continue;let s=e.doc.lineAt(n?i.to+1:i.from-1),a=s.length+1;if(n){o.push({from:i.to,to:s.to},{from:i.from,insert:s.text+e.lineBreak});for(let l of i.ranges)r.push(p.range(Math.min(e.doc.length,l.anchor+a),Math.min(e.doc.length,l.head+a)))}else{o.push({from:s.from,to:i.from},{from:i.to,insert:e.lineBreak+s.text});for(let l of i.ranges)r.push(p.range(l.anchor-a,l.head-a))}}return o.length?(t(e.update({changes:o,scrollIntoView:!0,selection:p.create(r,e.selection.mainIndex),userEvent:"move.line"})),!0):!1}var fi=({state:e,dispatch:t})=>ko(e,t,!1),pi=({state:e,dispatch:t})=>ko(e,t,!0);function Lo(e,t,n){if(e.readOnly)return!1;let o=[];for(let i of Re(e))n?o.push({from:i.from,insert:e.doc.slice(i.from,i.to)+e.lineBreak}):o.push({from:i.to,insert:e.lineBreak+e.doc.slice(i.from,i.to)});let r=e.changes(o);return t(e.update({changes:r,selection:e.selection.map(r,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}var gi=({state:e,dispatch:t})=>Lo(e,t,!1),xi=({state:e,dispatch:t})=>Lo(e,t,!0),yi=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(Re(t).map(({from:r,to:i})=>(r>0?r--:i<t.doc.length&&i++,{from:r,to:i}))),o=Q(t.selection,r=>{let i;if(e.lineWrapping){let s=e.lineBlockAt(r.head),a=e.coordsAtPos(r.head,r.assoc||1);a&&(i=s.bottom+e.documentTop-a.bottom+e.defaultLineHeight/2)}return e.moveVertically(r,!0,i)}).map(n);return e.dispatch({changes:n,selection:o,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Ci(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=be(e).resolveInner(t),o=n.childBefore(t),r=n.childAfter(t),i;return o&&r&&o.to<=t&&r.from>=t&&(i=o.type.prop(Se.closedBy))&&i.indexOf(r.name)>-1&&e.doc.lineAt(o.to).from==e.doc.lineAt(r.from).from&&!/\S/.test(e.sliceDoc(o.to,r.from))?{from:o.to,to:r.from}:null}var jn=vo(!1),Si=vo(!0);function vo(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let o=t.changeByRange(r=>{let{from:i,to:s}=r,a=t.doc.lineAt(i),l=!e&&i==s&&Ci(t,i);e&&(i=s=(s<=a.to?a:t.doc.lineAt(s)).to);let h=new dt(t,{simulateBreak:i,simulateDoubleBreak:!!l}),m=mt(h,i);for(m==null&&(m=Ce(/^\s*/.exec(t.doc.lineAt(i).text)[0],t.tabSize));s<a.to&&/\s/.test(a.text[s-a.from]);)s++;l?{from:i,to:s}=l:i>a.from&&i<a.from+100&&!/\S/.test(a.text.slice(0,i))&&(i=a.from);let d=["",ae(t,m)];return l&&d.push(ae(t,h.lineIndent(a.from,-1))),{changes:{from:i,to:s,insert:ht.of(d)},range:p.cursor(i+1+d[1].length)}});return n(t.update(o,{scrollIntoView:!0,userEvent:"input"})),!0}}function bt(e,t){let n=-1;return e.changeByRange(o=>{let r=[];for(let s=o.from;s<=o.to;){let a=e.doc.lineAt(s);a.number>n&&(o.empty||o.to>a.from)&&(t(a,r,o),n=a.number),s=a.to+1}let i=e.changes(r);return{changes:r,range:p.range(i.mapPos(o.anchor,1),i.mapPos(o.head,1))}})}var bi=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),o=new dt(e,{overrideIndentation:i=>{let s=n[i];return s??-1}}),r=bt(e,(i,s,a)=>{let l=mt(o,i.from);if(l==null)return;/\S/.test(i.text)||(l=0);let h=/^\s*/.exec(i.text)[0],m=ae(e,l);(h!=m||a.from<i.from+h.length)&&(n[i.from]=l,s.push({from:i.from,to:i.from+h.length,insert:m}))});return r.changes.empty||t(e.update(r,{userEvent:"indent"})),!0},wo=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(bt(e,(n,o)=>{o.push({from:n.from,insert:e.facet(vn)})}),{userEvent:"input.indent"})),!0),Mo=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(bt(e,(n,o)=>{let r=/^\s*/.exec(n.text)[0];if(!r)return;let i=Ce(r,e.tabSize),s=0,a=ae(e,Math.max(0,i-Le(e)));for(;s<r.length&&s<a.length&&r.charCodeAt(s)==a.charCodeAt(s);)s++;o.push({from:n.from+s,to:n.from+r.length,insert:a.slice(s)})}),{userEvent:"delete.dedent"})),!0),ki=e=>(e.setTabFocusMode(),!0);var Li=[{key:"Ctrl-b",run:eo,shift:co,preventDefault:!0},{key:"Ctrl-f",run:to,shift:ho},{key:"Ctrl-p",run:ro,shift:fo},{key:"Ctrl-n",run:io,shift:po},{key:"Ctrl-a",run:zr,shift:ei},{key:"Ctrl-e",run:_r,shift:ti},{key:"Ctrl-d",run:Co},{key:"Ctrl-h",run:yt},{key:"Ctrl-k",run:ci},{key:"Ctrl-Alt-h",run:bo},{key:"Ctrl-o",run:mi},{key:"Ctrl-t",run:di},{key:"Ctrl-v",run:xt}],vi=[{key:"ArrowLeft",run:eo,shift:co,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Rr,shift:Hr,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Wr,shift:Xr,preventDefault:!0},{key:"ArrowRight",run:to,shift:ho,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Vr,shift:Yr,preventDefault:!0},{mac:"Cmd-ArrowRight",run:$r,shift:Zr,preventDefault:!0},{key:"ArrowUp",run:ro,shift:fo,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Wn,shift:zn},{mac:"Ctrl-ArrowUp",run:On,shift:Un},{key:"ArrowDown",run:io,shift:po,preventDefault:!0},{mac:"Cmd-ArrowDown",run:$n,shift:_n},{mac:"Ctrl-ArrowDown",run:xt,shift:Nn},{key:"PageUp",run:On,shift:Un},{key:"PageDown",run:xt,shift:Nn},{key:"Home",run:Nr,shift:Qr,preventDefault:!0},{key:"Mod-Home",run:Wn,shift:zn},{key:"End",run:Ur,shift:Kr,preventDefault:!0},{key:"Mod-End",run:$n,shift:_n},{key:"Enter",run:jn,shift:jn},{key:"Mod-a",run:ni},{key:"Backspace",run:yt,shift:yt,preventDefault:!0},{key:"Delete",run:Co,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:bo,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:li,preventDefault:!0},{mac:"Mod-Backspace",run:hi,preventDefault:!0},{mac:"Mod-Delete",run:ui,preventDefault:!0}].concat(Li.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),Ao=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Fr,shift:Gr},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Or,shift:Jr},{key:"Alt-ArrowUp",run:fi},{key:"Shift-Alt-ArrowUp",run:gi},{key:"Alt-ArrowDown",run:pi},{key:"Shift-Alt-ArrowDown",run:xi},{key:"Mod-Alt-ArrowUp",run:ii},{key:"Mod-Alt-ArrowDown",run:si},{key:"Escape",run:ai},{key:"Mod-Enter",run:Si},{key:"Alt-l",mac:"Ctrl-l",run:oi},{key:"Mod-i",run:ri,preventDefault:!0},{key:"Mod-[",run:Mo},{key:"Mod-]",run:wo},{key:"Mod-Alt-\\",run:bi},{key:"Shift-Mod-k",run:yi},{key:"Shift-Mod-\\",run:qr},{key:"Mod-/",run:gr},{key:"Alt-A",run:yr},{key:"Ctrl-m",mac:"Shift-Alt-m",run:ki}].concat(vi),To={key:"Tab",run:wo,shift:Mo};function u(e){return new ke(we.define(e))}function W(e){return import("./dist-DPBSGC3Y.js").then(t=>t.sql({dialect:t[e]}))}var Do=[c.of({name:"C",extensions:["c","h","ino"],load(){return import("./dist-IQA4KVJK.js").then(e=>e.cpp())}}),c.of({name:"C++",alias:["cpp"],extensions:["cpp","c++","cc","cxx","hpp","h++","hh","hxx"],load(){return import("./dist-IQA4KVJK.js").then(e=>e.cpp())}}),c.of({name:"CQL",alias:["cassandra"],extensions:["cql"],load(){return W("Cassandra")}}),c.of({name:"CSS",extensions:["css"],load(){return import("./dist-HAB5NIXI.js").then(e=>e.css())}}),c.of({name:"Go",extensions:["go"],load(){return import("./dist-7RQKSOUX.js").then(e=>e.go())}}),c.of({name:"HTML",alias:["xhtml"],extensions:["html","htm","handlebars","hbs"],load(){return import("./dist-XOODBV4L.js").then(e=>e.html())}}),c.of({name:"Java",extensions:["java"],load(){return import("./dist-RCQFQRLD.js").then(e=>e.java())}}),c.of({name:"JavaScript",alias:["ecmascript","js","node"],extensions:["js","mjs","cjs"],load(){return import("./dist-ERADYPEK.js").then(e=>e.javascript())}}),c.of({name:"Jinja",extensions:["j2","jinja","jinja2"],load(){return import("./dist-E5NM7OBW.js").then(e=>e.jinja())}}),c.of({name:"JSON",alias:["json5"],extensions:["json","map"],load(){return import("./dist-F43RIHBZ.js").then(e=>e.json())}}),c.of({name:"JSX",extensions:["jsx"],load(){return import("./dist-ERADYPEK.js").then(e=>e.javascript({jsx:!0}))}}),c.of({name:"LESS",extensions:["less"],load(){return import("./dist-ZFZNCRZY.js").then(e=>e.less())}}),c.of({name:"Liquid",extensions:["liquid"],load(){return import("./dist-RSJGLSKC.js").then(e=>e.liquid())}}),c.of({name:"MariaDB SQL",load(){return W("MariaSQL")}}),c.of({name:"Markdown",extensions:["md","markdown","mkd"],load(){return import("./dist-RQLC4GVI.js").then(e=>e.markdown())}}),c.of({name:"MS SQL",load(){return W("MSSQL")}}),c.of({name:"MySQL",load(){return W("MySQL")}}),c.of({name:"PHP",extensions:["php","php3","php4","php5","php7","phtml"],load(){return import("./dist-HG23OLRA.js").then(e=>e.php())}}),c.of({name:"PLSQL",extensions:["pls"],load(){return W("PLSQL")}}),c.of({name:"PostgreSQL",load(){return W("PostgreSQL")}}),c.of({name:"Python",extensions:["BUILD","bzl","py","pyw"],filename:/^(BUCK|BUILD)$/,load(){return import("./dist-OIQTNVT2.js").then(e=>e.python())}}),c.of({name:"Rust",extensions:["rs"],load(){return import("./dist-VCFTF7Z6.js").then(e=>e.rust())}}),c.of({name:"Sass",extensions:["sass"],load(){return import("./dist-ARWGZ6MN.js").then(e=>e.sass({indented:!0}))}}),c.of({name:"SCSS",extensions:["scss"],load(){return import("./dist-ARWGZ6MN.js").then(e=>e.sass())}}),c.of({name:"SQL",extensions:["sql"],load(){return W("StandardSQL")}}),c.of({name:"SQLite",load(){return W("SQLite")}}),c.of({name:"TSX",extensions:["tsx"],load(){return import("./dist-ERADYPEK.js").then(e=>e.javascript({jsx:!0,typescript:!0}))}}),c.of({name:"TypeScript",alias:["ts"],extensions:["ts","mts","cts"],load(){return import("./dist-ERADYPEK.js").then(e=>e.javascript({typescript:!0}))}}),c.of({name:"WebAssembly",extensions:["wat","wast"],load(){return import("./dist-PMZJ734S.js").then(e=>e.wast())}}),c.of({name:"XML",alias:["rss","wsdl","xsd"],extensions:["xml","xsl","xsd","svg"],load(){return import("./dist-IEJXBSDJ.js").then(e=>e.xml())}}),c.of({name:"YAML",alias:["yml"],extensions:["yaml","yml"],load(){return import("./dist-VTO23SHH.js").then(e=>e.yaml())}}),c.of({name:"APL",extensions:["dyalog","apl"],load(){return import("./apl-C5P5JBDI.js").then(e=>u(e.apl))}}),c.of({name:"PGP",alias:["asciiarmor"],extensions:["asc","pgp","sig"],load(){return import("./asciiarmor-3NCLLELT.js").then(e=>u(e.asciiArmor))}}),c.of({name:"ASN.1",extensions:["asn","asn1"],load(){return import("./asn1-KF4WXU3M.js").then(e=>u(e.asn1({})))}}),c.of({name:"Asterisk",filename:/^extensions\.conf$/i,load(){return import("./asterisk-EA3VIN65.js").then(e=>u(e.asterisk))}}),c.of({name:"Brainfuck",extensions:["b","bf"],load(){return import("./brainfuck-A3CTQVFD.js").then(e=>u(e.brainfuck))}}),c.of({name:"Cobol",extensions:["cob","cpy"],load(){return import("./cobol-V6EIK6DN.js").then(e=>u(e.cobol))}}),c.of({name:"C#",alias:["csharp","cs"],extensions:["cs"],load(){return import("./clike-RTBH33GE.js").then(e=>u(e.csharp))}}),c.of({name:"Clojure",extensions:["clj","cljc","cljx"],load(){return import("./clojure-BR2VJ2JI.js").then(e=>u(e.clojure))}}),c.of({name:"ClojureScript",extensions:["cljs"],load(){return import("./clojure-BR2VJ2JI.js").then(e=>u(e.clojure))}}),c.of({name:"Closure Stylesheets (GSS)",extensions:["gss"],load(){return import("./css-C5DVWGB4.js").then(e=>u(e.gss))}}),c.of({name:"CMake",extensions:["cmake","cmake.in"],filename:/^CMakeLists\.txt$/,load(){return import("./cmake-2HEWVFEE.js").then(e=>u(e.cmake))}}),c.of({name:"CoffeeScript",alias:["coffee","coffee-script"],extensions:["coffee"],load(){return import("./coffeescript-JW3ZOGMD.js").then(e=>u(e.coffeeScript))}}),c.of({name:"Common Lisp",alias:["lisp"],extensions:["cl","lisp","el"],load(){return import("./commonlisp-UCWSIHYK.js").then(e=>u(e.commonLisp))}}),c.of({name:"Cypher",extensions:["cyp","cypher"],load(){return import("./cypher-K7FZM5GC.js").then(e=>u(e.cypher))}}),c.of({name:"Cython",extensions:["pyx","pxd","pxi"],load(){return import("./python-6YGH4S47.js").then(e=>u(e.cython))}}),c.of({name:"Crystal",extensions:["cr"],load(){return import("./crystal-GR4VLC3M.js").then(e=>u(e.crystal))}}),c.of({name:"D",extensions:["d"],load(){return import("./d-CF3QNNH5.js").then(e=>u(e.d))}}),c.of({name:"Dart",extensions:["dart"],load(){return import("./clike-RTBH33GE.js").then(e=>u(e.dart))}}),c.of({name:"diff",extensions:["diff","patch"],load(){return import("./diff-KOMSZU7O.js").then(e=>u(e.diff))}}),c.of({name:"Dockerfile",filename:/^Dockerfile$/,load(){return import("./dockerfile-XCIKYOSI.js").then(e=>u(e.dockerFile))}}),c.of({name:"DTD",extensions:["dtd"],load(){return import("./dtd-3XFH7W6Z.js").then(e=>u(e.dtd))}}),c.of({name:"Dylan",extensions:["dylan","dyl","intr"],load(){return import("./dylan-3UWPKVOR.js").then(e=>u(e.dylan))}}),c.of({name:"EBNF",load(){return import("./ebnf-OLHTL3VN.js").then(e=>u(e.ebnf))}}),c.of({name:"ECL",extensions:["ecl"],load(){return import("./ecl-43LZ3ZRM.js").then(e=>u(e.ecl))}}),c.of({name:"edn",extensions:["edn"],load(){return import("./clojure-BR2VJ2JI.js").then(e=>u(e.clojure))}}),c.of({name:"Eiffel",extensions:["e"],load(){return import("./eiffel-ISPO2UJF.js").then(e=>u(e.eiffel))}}),c.of({name:"Elm",extensions:["elm"],load(){return import("./elm-CLK576PK.js").then(e=>u(e.elm))}}),c.of({name:"Erlang",extensions:["erl"],load(){return import("./erlang-AVQXQFOT.js").then(e=>u(e.erlang))}}),c.of({name:"Esper",load(){return import("./sql-BPLIIUYC.js").then(e=>u(e.esper))}}),c.of({name:"Factor",extensions:["factor"],load(){return import("./factor-CRTVBD6Q.js").then(e=>u(e.factor))}}),c.of({name:"FCL",load(){return import("./fcl-FX24LKTH.js").then(e=>u(e.fcl))}}),c.of({name:"Forth",extensions:["forth","fth","4th"],load(){return import("./forth-YKDKCTVS.js").then(e=>u(e.forth))}}),c.of({name:"Fortran",extensions:["f","for","f77","f90","f95"],load(){return import("./fortran-UJWC6SLU.js").then(e=>u(e.fortran))}}),c.of({name:"F#",alias:["fsharp"],extensions:["fs"],load(){return import("./mllike-VV3KS46B.js").then(e=>u(e.fSharp))}}),c.of({name:"Gas",extensions:["s"],load(){return import("./gas-MYEMWGRE.js").then(e=>u(e.gas))}}),c.of({name:"Gherkin",extensions:["feature"],load(){return import("./gherkin-JWHAU2YG.js").then(e=>u(e.gherkin))}}),c.of({name:"Groovy",extensions:["groovy","gradle"],filename:/^Jenkinsfile$/,load(){return import("./groovy-QZIZQIAK.js").then(e=>u(e.groovy))}}),c.of({name:"Haskell",extensions:["hs"],load(){return import("./haskell-JR3G7YNW.js").then(e=>u(e.haskell))}}),c.of({name:"Haxe",extensions:["hx"],load(){return import("./haxe-TVLAIYEN.js").then(e=>u(e.haxe))}}),c.of({name:"HXML",extensions:["hxml"],load(){return import("./haxe-TVLAIYEN.js").then(e=>u(e.hxml))}}),c.of({name:"HTTP",load(){return import("./http-YXQRE77G.js").then(e=>u(e.http))}}),c.of({name:"IDL",extensions:["pro"],load(){return import("./idl-RAQGJ6LJ.js").then(e=>u(e.idl))}}),c.of({name:"JSON-LD",alias:["jsonld"],extensions:["jsonld"],load(){return import("./javascript-NM7KDJUE.js").then(e=>u(e.jsonld))}}),c.of({name:"Julia",extensions:["jl"],load(){return import("./julia-LG3BH25B.js").then(e=>u(e.julia))}}),c.of({name:"Kotlin",extensions:["kt","kts"],load(){return import("./clike-RTBH33GE.js").then(e=>u(e.kotlin))}}),c.of({name:"LiveScript",alias:["ls"],extensions:["ls"],load(){return import("./livescript-4CVWVI4M.js").then(e=>u(e.liveScript))}}),c.of({name:"Lua",extensions:["lua"],load(){return import("./lua-VWGE7DQ7.js").then(e=>u(e.lua))}}),c.of({name:"mIRC",extensions:["mrc"],load(){return import("./mirc-565WBI76.js").then(e=>u(e.mirc))}}),c.of({name:"Mathematica",extensions:["m","nb","wl","wls"],load(){return import("./mathematica-D7APQSEU.js").then(e=>u(e.mathematica))}}),c.of({name:"Modelica",extensions:["mo"],load(){return import("./modelica-EGX44FZV.js").then(e=>u(e.modelica))}}),c.of({name:"MUMPS",extensions:["mps"],load(){return import("./mumps-POZYWSMI.js").then(e=>u(e.mumps))}}),c.of({name:"Mbox",extensions:["mbox"],load(){return import("./mbox-BN3XQBYX.js").then(e=>u(e.mbox))}}),c.of({name:"Nginx",filename:/nginx.*\.conf$/i,load(){return import("./nginx-JUBX55EU.js").then(e=>u(e.nginx))}}),c.of({name:"NSIS",extensions:["nsh","nsi"],load(){return import("./nsis-RC4CREGM.js").then(e=>u(e.nsis))}}),c.of({name:"NTriples",extensions:["nt","nq"],load(){return import("./ntriples-4WK6CNVE.js").then(e=>u(e.ntriples))}}),c.of({name:"Objective-C",alias:["objective-c","objc"],extensions:["m"],load(){return import("./clike-RTBH33GE.js").then(e=>u(e.objectiveC))}}),c.of({name:"Objective-C++",alias:["objective-c++","objc++"],extensions:["mm"],load(){return import("./clike-RTBH33GE.js").then(e=>u(e.objectiveCpp))}}),c.of({name:"OCaml",extensions:["ml","mli","mll","mly"],load(){return import("./mllike-VV3KS46B.js").then(e=>u(e.oCaml))}}),c.of({name:"Octave",extensions:["m"],load(){return import("./octave-GOKFN2V7.js").then(e=>u(e.octave))}}),c.of({name:"Oz",extensions:["oz"],load(){return import("./oz-OQUMNC63.js").then(e=>u(e.oz))}}),c.of({name:"Pascal",extensions:["p","pas"],load(){return import("./pascal-BBWQWWWD.js").then(e=>u(e.pascal))}}),c.of({name:"Perl",extensions:["pl","pm"],load(){return import("./perl-KTPJTTAM.js").then(e=>u(e.perl))}}),c.of({name:"Pig",extensions:["pig"],load(){return import("./pig-IJMBS4FZ.js").then(e=>u(e.pig))}}),c.of({name:"PowerShell",extensions:["ps1","psd1","psm1"],load(){return import("./powershell-6YGCBHDP.js").then(e=>u(e.powerShell))}}),c.of({name:"Properties files",alias:["ini","properties"],extensions:["properties","ini","in"],load(){return import("./properties-5QTD3364.js").then(e=>u(e.properties))}}),c.of({name:"ProtoBuf",extensions:["proto"],load(){return import("./protobuf-LTRWBIK3.js").then(e=>u(e.protobuf))}}),c.of({name:"Pug",alias:["jade"],extensions:["pug","jade"],load(){return import("./pug-U4PV3WLG.js").then(e=>u(e.pug))}}),c.of({name:"Puppet",extensions:["pp"],load(){return import("./puppet-WGYJPR3Y.js").then(e=>u(e.puppet))}}),c.of({name:"Q",extensions:["q"],load(){return import("./q-VIG4IJLI.js").then(e=>u(e.q))}}),c.of({name:"R",alias:["rscript"],extensions:["r","R"],load(){return import("./r-NVPCXGTR.js").then(e=>u(e.r))}}),c.of({name:"RPM Changes",load(){return import("./rpm-UEA257HD.js").then(e=>u(e.rpmChanges))}}),c.of({name:"RPM Spec",extensions:["spec"],load(){return import("./rpm-UEA257HD.js").then(e=>u(e.rpmSpec))}}),c.of({name:"Ruby",alias:["jruby","macruby","rake","rb","rbx"],extensions:["rb"],filename:/^(Gemfile|Rakefile)$/,load(){return import("./ruby-KPQRAJGE.js").then(e=>u(e.ruby))}}),c.of({name:"SAS",extensions:["sas"],load(){return import("./sas-L7VATVH5.js").then(e=>u(e.sas))}}),c.of({name:"Scala",extensions:["scala"],load(){return import("./clike-RTBH33GE.js").then(e=>u(e.scala))}}),c.of({name:"Scheme",extensions:["scm","ss"],load(){return import("./scheme-T2NOWR3P.js").then(e=>u(e.scheme))}}),c.of({name:"Shell",alias:["bash","sh","zsh"],extensions:["sh","ksh","bash"],filename:/^PKGBUILD$/,load(){return import("./shell-DLVDUNFA.js").then(e=>u(e.shell))}}),c.of({name:"Sieve",extensions:["siv","sieve"],load(){return import("./sieve-BKBZYDBU.js").then(e=>u(e.sieve))}}),c.of({name:"Smalltalk",extensions:["st"],load(){return import("./smalltalk-WRJQKJSD.js").then(e=>u(e.smalltalk))}}),c.of({name:"Solr",load(){return import("./solr-66B3BIDL.js").then(e=>u(e.solr))}}),c.of({name:"SML",extensions:["sml","sig","fun","smackspec"],load(){return import("./mllike-VV3KS46B.js").then(e=>u(e.sml))}}),c.of({name:"SPARQL",alias:["sparul"],extensions:["rq","sparql"],load(){return import("./sparql-S25Z47JG.js").then(e=>u(e.sparql))}}),c.of({name:"Spreadsheet",alias:["excel","formula"],load(){return import("./spreadsheet-B272EF7Y.js").then(e=>u(e.spreadsheet))}}),c.of({name:"Squirrel",extensions:["nut"],load(){return import("./clike-RTBH33GE.js").then(e=>u(e.squirrel))}}),c.of({name:"Stylus",extensions:["styl"],load(){return import("./stylus-PJUHLGPT.js").then(e=>u(e.stylus))}}),c.of({name:"Swift",extensions:["swift"],load(){return import("./swift-UYHTO4SX.js").then(e=>u(e.swift))}}),c.of({name:"sTeX",load(){return import("./stex-4IJY64QX.js").then(e=>u(e.stex))}}),c.of({name:"LaTeX",alias:["tex"],extensions:["text","ltx","tex"],load(){return import("./stex-4IJY64QX.js").then(e=>u(e.stex))}}),c.of({name:"SystemVerilog",extensions:["v","sv","svh"],load(){return import("./verilog-EWWQPMNN.js").then(e=>u(e.verilog))}}),c.of({name:"Tcl",extensions:["tcl"],load(){return import("./tcl-OQ5J3VO2.js").then(e=>u(e.tcl))}}),c.of({name:"Textile",extensions:["textile"],load(){return import("./textile-NOGVBEYF.js").then(e=>u(e.textile))}}),c.of({name:"TiddlyWiki",load(){return import("./tiddlywiki-SYTK4QUE.js").then(e=>u(e.tiddlyWiki))}}),c.of({name:"Tiki wiki",load(){return import("./tiki-P7K4ZLOM.js").then(e=>u(e.tiki))}}),c.of({name:"TOML",extensions:["toml"],load(){return import("./toml-AUZYRP36.js").then(e=>u(e.toml))}}),c.of({name:"Troff",extensions:["1","2","3","4","5","6","7","8","9"],load(){return import("./troff-XFYJNQOJ.js").then(e=>u(e.troff))}}),c.of({name:"TTCN",extensions:["ttcn","ttcn3","ttcnpp"],load(){return import("./ttcn-AK2IXWU6.js").then(e=>u(e.ttcn))}}),c.of({name:"TTCN_CFG",extensions:["cfg"],load(){return import("./ttcn-cfg-3IDPIYPU.js").then(e=>u(e.ttcnCfg))}}),c.of({name:"Turtle",extensions:["ttl"],load(){return import("./turtle-OIDMF46P.js").then(e=>u(e.turtle))}}),c.of({name:"Web IDL",extensions:["webidl"],load(){return import("./webidl-XVBHXCRV.js").then(e=>u(e.webIDL))}}),c.of({name:"VB.NET",extensions:["vb"],load(){return import("./vb-J6K4XVA2.js").then(e=>u(e.vb))}}),c.of({name:"VBScript",extensions:["vbs"],load(){return import("./vbscript-FM7DDZZE.js").then(e=>u(e.vbScript))}}),c.of({name:"Velocity",extensions:["vtl"],load(){return import("./velocity-6KZFEOFD.js").then(e=>u(e.velocity))}}),c.of({name:"Verilog",extensions:["v"],load(){return import("./verilog-EWWQPMNN.js").then(e=>u(e.verilog))}}),c.of({name:"VHDL",extensions:["vhd","vhdl"],load(){return import("./vhdl-CJ3M4IHI.js").then(e=>u(e.vhdl))}}),c.of({name:"XQuery",extensions:["xy","xquery","xq","xqm","xqy"],load(){return import("./xquery-7WZOZ4UK.js").then(e=>u(e.xQuery))}}),c.of({name:"Yacas",extensions:["ys"],load(){return import("./yacas-MZ2ZZPF3.js").then(e=>u(e.yacas))}}),c.of({name:"Z80",extensions:["z80"],load(){return import("./z80-I447CBF7.js").then(e=>u(e.z80))}}),c.of({name:"MscGen",extensions:["mscgen","mscin","msc"],load(){return import("./mscgen-GFGTHENT.js").then(e=>u(e.mscgen))}}),c.of({name:"X\xF9",extensions:["xu"],load(){return import("./mscgen-GFGTHENT.js").then(e=>u(e.xu))}}),c.of({name:"MsGenny",extensions:["msgenny"],load(){return import("./mscgen-GFGTHENT.js").then(e=>u(e.msgenny))}}),c.of({name:"Vue",extensions:["vue"],load(){return import("./dist-E36PJE5M.js").then(e=>e.vue())}}),c.of({name:"Angular Template",load(){return import("./dist-SGNQZVVX.js").then(e=>e.angular())}})];var Bo=typeof String.prototype.normalize=="function"?e=>e.normalize("NFKD"):e=>e,z=class{constructor(t,n,o=0,r=t.length,i,s){this.test=s,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(o,r),this.bufferStart=o,this.normalize=i?a=>i(Bo(a)):Bo,this.query=this.normalize(n)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return on(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let n=rn(t),o=this.bufferStart+this.bufferPos;this.bufferPos+=sn(t);let r=this.normalize(n);if(r.length)for(let i=0,s=o;;i++){let a=r.charCodeAt(i),l=this.match(a,s,this.bufferPos+this.bufferStart);if(i==r.length-1){if(l)return this.value=l,this;break}s==o&&i<n.length&&n.charCodeAt(i)==a&&s++}}}match(t,n,o){let r=null;for(let i=0;i<this.matches.length;i+=2){let s=this.matches[i],a=!1;this.query.charCodeAt(s)==t&&(s==this.query.length-1?r={from:this.matches[i+1],to:o}:(this.matches[i]++,a=!0)),a||(this.matches.splice(i,2),i-=2)}return this.query.charCodeAt(0)==t&&(this.query.length==1?r={from:n,to:o}:this.matches.push(1,n)),r&&this.test&&!this.test(r.from,r.to,this.buffer,this.bufferStart)&&(r=null),r}};typeof Symbol<"u"&&(z.prototype[Symbol.iterator]=function(){return this});var Ro={from:-1,to:-1,match:/.*/.exec("")},At="gm"+(/x/.unicode==null?"":"u"),Fe=class{constructor(t,n,o,r=0,i=t.length){if(this.text=t,this.to=i,this.curLine="",this.done=!1,this.value=Ro,/\\[sWDnr]|\n|\r|\[\^/.test(n))return new Ue(t,n,o,r,i);this.re=new RegExp(n,At+(o?.ignoreCase?"i":"")),this.test=o?.test,this.iter=t.iter();let s=t.lineAt(r);this.curLineStart=s.from,this.matchPos=Ne(t,r),this.getLine(this.curLineStart)}getLine(t){this.iter.next(t),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let n=this.matchPos<=this.to&&this.re.exec(this.curLine);if(n){let o=this.curLineStart+n.index,r=o+n[0].length;if(this.matchPos=Ne(this.text,r+(o==r?1:0)),o==this.curLineStart+this.curLine.length&&this.nextLine(),(o<r||o>this.value.to)&&(!this.test||this.test(o,r,n)))return this.value={from:o,to:r,match:n},this;t=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),t=0;else return this.done=!0,this}}},kt=new WeakMap,Oe=class e{constructor(t,n){this.from=t,this.text=n}get to(){return this.from+this.text.length}static get(t,n,o){let r=kt.get(t);if(!r||r.from>=o||r.to<=n){let a=new e(n,t.sliceString(n,o));return kt.set(t,a),a}if(r.from==n&&r.to==o)return r;let{text:i,from:s}=r;return s>n&&(i=t.sliceString(n,s)+i,s=n),r.to<o&&(i+=t.sliceString(r.to,o)),kt.set(t,new e(s,i)),new e(n,i.slice(n-s,o-s))}},Ue=class{constructor(t,n,o,r,i){this.text=t,this.to=i,this.done=!1,this.value=Ro,this.matchPos=Ne(t,r),this.re=new RegExp(n,At+(o?.ignoreCase?"i":"")),this.test=o?.test,this.flat=Oe.get(t,r,this.chunkEnd(r+5e3))}chunkEnd(t){return t>=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,n=this.re.exec(this.flat.text);if(n&&!n[0]&&n.index==t&&(this.re.lastIndex=t+1,n=this.re.exec(this.flat.text)),n){let o=this.flat.from+n.index,r=o+n[0].length;if((this.flat.to>=this.to||n.index+n[0].length<=this.flat.text.length-10)&&(!this.test||this.test(o,r,n)))return this.value={from:o,to:r,match:n},this.matchPos=Ne(this.text,r+(o==r?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Oe.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}};typeof Symbol<"u"&&(Fe.prototype[Symbol.iterator]=Ue.prototype[Symbol.iterator]=function(){return this});function wi(e){try{return new RegExp(e,At),!0}catch{return!1}}function Ne(e,t){if(t>=e.length)return t;let n=e.lineAt(t),o;for(;t<n.to&&(o=n.text.charCodeAt(t-n.from))>=56320&&o<57344;)t++;return t}var Mi=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:o,result:r}=bn(e,{label:t.phrase("Go to line"),input:{type:"text",name:"line",value:n},focus:!0,submitLabel:t.phrase("go")});return r.then(i=>{let s=i&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(i.elements.line.value);if(!s){e.dispatch({effects:o});return}let a=t.doc.lineAt(t.selection.main.head),[,l,h,m,d]=s,g=m?+m.slice(1):0,C=h?+h:a.number;if(h&&d){let k=C/100;l&&(k=k*(l=="-"?-1:1)+a.number/t.doc.lines),C=Math.round(t.doc.lines*k)}else h&&l&&(C=C*(l=="-"?-1:1)+a.number);let x=t.doc.line(Math.max(1,Math.min(t.doc.lines,C))),S=p.cursor(x.from+Math.max(0,Math.min(g,x.length)));e.dispatch({effects:[o,y.scrollIntoView(S.from,{y:"center"})],selection:S})}),!0},Ai={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Vo=V.define({combine(e){return se(e,Ai,{highlightWordAroundCursor:(t,n)=>t||n,minSelectionLength:Math.min,maxMatches:Math.min})}});function Po(e){let t=[Ii,Ei];return e&&t.push(Vo.of(e)),t}var Ti=b.mark({class:"cm-selectionMatch"}),Di=b.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Eo(e,t,n,o){return(n==0||e(t.sliceDoc(n-1,n))!=v.Word)&&(o==t.doc.length||e(t.sliceDoc(o,o+1))!=v.Word)}function Bi(e,t,n,o){return e(t.sliceDoc(n,n+1))==v.Word&&e(t.sliceDoc(o-1,o))==v.Word}var Ei=O.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(Vo),{state:n}=e,o=n.selection;if(o.ranges.length>1)return b.none;let r=o.main,i,s=null;if(r.empty){if(!t.highlightWordAroundCursor)return b.none;let l=n.wordAt(r.head);if(!l)return b.none;s=n.charCategorizer(r.head),i=n.sliceDoc(l.from,l.to)}else{let l=r.to-r.from;if(l<t.minSelectionLength||l>200)return b.none;if(t.wholeWords){if(i=n.sliceDoc(r.from,r.to),s=n.charCategorizer(r.head),!(Eo(s,n,r.from,r.to)&&Bi(s,n,r.from,r.to)))return b.none}else if(i=n.sliceDoc(r.from,r.to),!i)return b.none}let a=[];for(let l of e.visibleRanges){let h=new z(n.doc,i,l.from,l.to);for(;!h.next().done;){let{from:m,to:d}=h.value;if((!s||Eo(s,n,m,d))&&(r.empty&&m<=r.from&&d>=r.to?a.push(Di.range(m,d)):(m>=r.to||d<=r.from)&&a.push(Ti.range(m,d)),a.length>t.maxMatches))return b.none}}return b.set(a)}},{decorations:e=>e.decorations}),Ii=y.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),Ri=({state:e,dispatch:t})=>{let{selection:n}=e,o=p.create(n.ranges.map(r=>e.wordAt(r.head)||p.cursor(r.head)),n.mainIndex);return o.eq(n)?!1:(t(e.update({selection:o})),!0)};function Vi(e,t){let{main:n,ranges:o}=e.selection,r=e.wordAt(n.head),i=r&&r.from==n.from&&r.to==n.to;for(let s=!1,a=new z(e.doc,t,o[o.length-1].to);;)if(a.next(),a.done){if(s)return null;a=new z(e.doc,t,0,Math.max(0,o[o.length-1].from-1)),s=!0}else{if(s&&o.some(l=>l.from==a.value.from))continue;if(i){let l=e.wordAt(a.value.from);if(!l||l.from!=a.value.from||l.to!=a.value.to)continue}return a.value}}var Pi=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(i=>i.from===i.to))return Ri({state:e,dispatch:t});let o=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(i=>e.sliceDoc(i.from,i.to)!=o))return!1;let r=Vi(e,o);return r?(t(e.update({selection:e.selection.addRange(p.range(r.from,r.to),!1),effects:y.scrollIntoView(r.to)})),!0):!1},ee=V.define({combine(e){return se(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new Mt(t),scrollToMatch:t=>y.scrollIntoView(t)})}});var We=class{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||wi(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord,this.test=t.test}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,(n,o)=>o=="n"?`
|
|
2
|
+
`:o=="r"?"\r":o=="t"?" ":"\\")}eq(t){return this.search==t.search&&this.replace==t.replace&&this.caseSensitive==t.caseSensitive&&this.regexp==t.regexp&&this.wholeWord==t.wholeWord&&this.test==t.test}create(){return this.regexp?new vt(this):new Lt(this)}getCursor(t,n=0,o){let r=t.doc?t:ie.create({doc:t});return o==null&&(o=r.doc.length),this.regexp?Z(this,r,n,o):X(this,r,n,o)}},$e=class{constructor(t){this.spec=t}};function Fi(e,t,n){return(o,r,i,s)=>{if(n&&!n(o,r,i,s))return!1;let a=o>=s&&r<=s+i.length?i.slice(o-s,r-s):t.doc.sliceString(o,r);return e(a,t,o,r)}}function X(e,t,n,o){let r;return e.wholeWord&&(r=Oi(t.doc,t.charCategorizer(t.selection.main.head))),e.test&&(r=Fi(e.test,t,r)),new z(t.doc,e.unquoted,n,o,e.caseSensitive?void 0:i=>i.toLowerCase(),r)}function Oi(e,t){return(n,o,r,i)=>((i>n||i+r.length<o)&&(i=Math.max(0,n-2),r=e.sliceString(i,Math.min(e.length,o+2))),(t(ze(r,n-i))!=v.Word||t(_e(r,n-i))!=v.Word)&&(t(_e(r,o-i))!=v.Word||t(ze(r,o-i))!=v.Word))}var Lt=class extends $e{constructor(t){super(t)}nextMatch(t,n,o){let r=X(this.spec,t,o,t.doc.length).nextOverlapping();if(r.done){let i=Math.min(t.doc.length,n+this.spec.unquoted.length);r=X(this.spec,t,0,i).nextOverlapping()}return r.done||r.value.from==n&&r.value.to==o?null:r.value}prevMatchInRange(t,n,o){for(let r=o;;){let i=Math.max(n,r-1e4-this.spec.unquoted.length),s=X(this.spec,t,i,r),a=null;for(;!s.nextOverlapping().done;)a=s.value;if(a)return a;if(i==n)return null;r-=1e4}}prevMatch(t,n,o){let r=this.prevMatchInRange(t,0,n);return r||(r=this.prevMatchInRange(t,Math.max(0,o-this.spec.unquoted.length),t.doc.length)),r&&(r.from!=n||r.to!=o)?r:null}getReplacement(t){return this.spec.unquote(this.spec.replace)}matchAll(t,n){let o=X(this.spec,t,0,t.doc.length),r=[];for(;!o.next().done;){if(r.length>=n)return null;r.push(o.value)}return r}highlight(t,n,o,r){let i=X(this.spec,t,Math.max(0,n-this.spec.unquoted.length),Math.min(o+this.spec.unquoted.length,t.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}};function Ui(e,t,n){return(o,r,i)=>(!n||n(o,r,i))&&e(i[0],t,o,r)}function Z(e,t,n,o){let r;return e.wholeWord&&(r=Ni(t.charCategorizer(t.selection.main.head))),e.test&&(r=Ui(e.test,t,r)),new Fe(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:r},n,o)}function ze(e,t){return e.slice(P(e,t,!1),t)}function _e(e,t){return e.slice(t,P(e,t))}function Ni(e){return(t,n,o)=>!o[0].length||(e(ze(o.input,o.index))!=v.Word||e(_e(o.input,o.index))!=v.Word)&&(e(_e(o.input,o.index+o[0].length))!=v.Word||e(ze(o.input,o.index+o[0].length))!=v.Word)}var vt=class extends $e{nextMatch(t,n,o){let r=Z(this.spec,t,o,t.doc.length).next();return r.done&&(r=Z(this.spec,t,0,n).next()),r.done?null:r.value}prevMatchInRange(t,n,o){for(let r=1;;r++){let i=Math.max(n,o-r*1e4),s=Z(this.spec,t,i,o),a=null;for(;!s.next().done;)a=s.value;if(a&&(i==n||a.from>i+10))return a;if(i==n)return null}}prevMatch(t,n,o){return this.prevMatchInRange(t,0,n)||this.prevMatchInRange(t,o,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(n,o)=>{if(o=="&")return t.match[0];if(o=="$")return"$";for(let r=o.length;r>0;r--){let i=+o.slice(0,r);if(i>0&&i<t.match.length)return t.match[i]+o.slice(r)}return n})}matchAll(t,n){let o=Z(this.spec,t,0,t.doc.length),r=[];for(;!o.next().done;){if(r.length>=n)return null;r.push(o.value)}return r}highlight(t,n,o,r){let i=Z(this.spec,t,Math.max(0,n-250),Math.min(o+250,t.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}},ue=j.define(),Tt=j.define(),$=pe.define({create(e){return new he(wt(e).create(),null)},update(e,t){for(let n of t.effects)n.is(ue)?e=new he(n.value.create(),e.panel):n.is(Tt)&&(e=new he(e.query,n.value?Dt:null));return e},provide:e=>Sn.from(e,t=>t.panel)});var he=class{constructor(t,n){this.query=t,this.panel=n}},Wi=b.mark({class:"cm-searchMatch"}),$i=b.mark({class:"cm-searchMatch cm-searchMatch-selected"}),zi=O.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field($))}update(e){let t=e.state.field($);(t!=e.startState.field($)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return b.none;let{view:n}=this,o=new hn;for(let r=0,i=n.visibleRanges,s=i.length;r<s;r++){let{from:a,to:l}=i[r];for(;r<s-1&&l>i[r+1].from-500;)l=i[++r].to;e.highlight(n.state,a,l,(h,m)=>{let d=n.state.selection.ranges.some(g=>g.from==h&&g.to==m);o.add(h,m,d?$i:Wi)})}return o.finish()}},{decorations:e=>e.decorations});function me(e){return t=>{let n=t.state.field($,!1);return n&&n.query.spec.valid?e(t,n):Uo(t)}}var je=me((e,{query:t})=>{let{to:n}=e.state.selection.main,o=t.nextMatch(e.state,n,n);if(!o)return!1;let r=p.single(o.from,o.to),i=e.state.facet(ee);return e.dispatch({selection:r,effects:[Bt(e,o),i.scrollToMatch(r.main,e)],userEvent:"select.search"}),Oo(e),!0}),qe=me((e,{query:t})=>{let{state:n}=e,{from:o}=n.selection.main,r=t.prevMatch(n,o,o);if(!r)return!1;let i=p.single(r.from,r.to),s=e.state.facet(ee);return e.dispatch({selection:i,effects:[Bt(e,r),s.scrollToMatch(i.main,e)],userEvent:"select.search"}),Oo(e),!0}),_i=me((e,{query:t})=>{let n=t.matchAll(e.state,1e3);return!n||!n.length?!1:(e.dispatch({selection:p.create(n.map(o=>p.range(o.from,o.to))),userEvent:"select.search.matches"}),!0)}),ji=({state:e,dispatch:t})=>{let n=e.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:o,to:r}=n.main,i=[],s=0;for(let a=new z(e.doc,e.sliceDoc(o,r));!a.next().done;){if(i.length>1e3)return!1;a.value.from==o&&(s=i.length),i.push(p.range(a.value.from,a.value.to))}return t(e.update({selection:p.create(i,s),userEvent:"select.search.matches"})),!0},Io=me((e,{query:t})=>{let{state:n}=e,{from:o,to:r}=n.selection.main;if(n.readOnly)return!1;let i=t.nextMatch(n,o,o);if(!i)return!1;let s=i,a=[],l,h,m=[];s.from==o&&s.to==r&&(h=n.toText(t.getReplacement(s)),a.push({from:s.from,to:s.to,insert:h}),s=t.nextMatch(n,s.from,s.to),m.push(y.announce.of(n.phrase("replaced match on line $",n.doc.lineAt(o).number)+".")));let d=e.state.changes(a);return s&&(l=p.single(s.from,s.to).map(d),m.push(Bt(e,s)),m.push(n.facet(ee).scrollToMatch(l.main,e))),e.dispatch({changes:d,selection:l,effects:m,userEvent:"input.replace"}),!0}),qi=me((e,{query:t})=>{if(e.state.readOnly)return!1;let n=t.matchAll(e.state,1e9).map(r=>{let{from:i,to:s}=r;return{from:i,to:s,insert:t.getReplacement(r)}});if(!n.length)return!1;let o=e.state.phrase("replaced $ matches",n.length)+".";return e.dispatch({changes:n,effects:y.announce.of(o),userEvent:"input.replace.all"}),!0});function Dt(e){return e.state.facet(ee).createPanel(e)}function wt(e,t){var n,o,r,i,s;let a=e.selection.main,l=a.empty||a.to>a.from+100?"":e.sliceDoc(a.from,a.to);if(t&&!l)return t;let h=e.facet(ee);return new We({search:((n=t?.literal)!==null&&n!==void 0?n:h.literal)?l:l.replace(/\n/g,"\\n"),caseSensitive:(o=t?.caseSensitive)!==null&&o!==void 0?o:h.caseSensitive,literal:(r=t?.literal)!==null&&r!==void 0?r:h.literal,regexp:(i=t?.regexp)!==null&&i!==void 0?i:h.regexp,wholeWord:(s=t?.wholeWord)!==null&&s!==void 0?s:h.wholeWord})}function Fo(e){let t=ut(e,Dt);return t&&t.dom.querySelector("[main-field]")}function Oo(e){let t=Fo(e);t&&t==e.root.activeElement&&t.select()}var Uo=e=>{let t=e.state.field($,!1);if(t&&t.panel){let n=Fo(e);if(n&&n!=e.root.activeElement){let o=wt(e.state,t.query.spec);o.valid&&e.dispatch({effects:ue.of(o)}),n.focus(),n.select()}}else e.dispatch({effects:[Tt.of(!0),t?ue.of(wt(e.state,t.query.spec)):j.appendConfig.of(Yi)]});return!0},No=e=>{let t=e.state.field($,!1);if(!t||!t.panel)return!1;let n=ut(e,Dt);return n&&n.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:Tt.of(!1)}),!0},Wo=[{key:"Mod-f",run:Uo,scope:"editor search-panel"},{key:"F3",run:je,shift:qe,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:je,shift:qe,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:No,scope:"editor search-panel"},{key:"Mod-Shift-l",run:ji},{key:"Mod-Alt-g",run:Mi},{key:"Mod-d",run:Pi,preventDefault:!0}],Mt=class{constructor(t){this.view=t;let n=this.query=t.state.field($).query.spec;this.commit=this.commit.bind(this),this.searchField=w("input",{value:n.search,placeholder:M(t,"Find"),"aria-label":M(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=w("input",{value:n.replace,placeholder:M(t,"Replace"),"aria-label":M(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=w("input",{type:"checkbox",name:"case",form:"",checked:n.caseSensitive,onchange:this.commit}),this.reField=w("input",{type:"checkbox",name:"re",form:"",checked:n.regexp,onchange:this.commit}),this.wordField=w("input",{type:"checkbox",name:"word",form:"",checked:n.wholeWord,onchange:this.commit});function o(r,i,s){return w("button",{class:"cm-button",name:r,onclick:i,type:"button"},s)}this.dom=w("div",{onkeydown:r=>this.keydown(r),class:"cm-search"},[this.searchField,o("next",()=>je(t),[M(t,"next")]),o("prev",()=>qe(t),[M(t,"previous")]),o("select",()=>_i(t),[M(t,"all")]),w("label",null,[this.caseField,M(t,"match case")]),w("label",null,[this.reField,M(t,"regexp")]),w("label",null,[this.wordField,M(t,"by word")]),...t.state.readOnly?[]:[w("br"),this.replaceField,o("replace",()=>Io(t),[M(t,"replace")]),o("replaceAll",()=>qi(t),[M(t,"replace all")])],w("button",{name:"close",onclick:()=>No(t),"aria-label":M(t,"close"),type:"button"},["\xD7"])])}commit(){let t=new We({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:ue.of(t)}))}keydown(t){fn(this.view,t,"search-panel")?t.preventDefault():t.keyCode==13&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?qe:je)(this.view)):t.keyCode==13&&t.target==this.replaceField&&(t.preventDefault(),Io(this.view))}update(t){for(let n of t.transactions)for(let o of n.effects)o.is(ue)&&!o.value.eq(this.query)&&this.setQuery(o.value)}setQuery(t){this.query=t,this.searchField.value=t.search,this.replaceField.value=t.replace,this.caseField.checked=t.caseSensitive,this.reField.checked=t.regexp,this.wordField.checked=t.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(ee).top}};function M(e,t){return e.state.phrase(t)}var Ve=30,Pe=/[\s\.,:;?!]/;function Bt(e,{from:t,to:n}){let o=e.state.doc.lineAt(t),r=e.state.doc.lineAt(n).to,i=Math.max(o.from,t-Ve),s=Math.min(r,n+Ve),a=e.state.sliceDoc(i,s);if(i!=o.from){for(let l=0;l<Ve;l++)if(!Pe.test(a[l+1])&&Pe.test(a[l])){a=a.slice(l);break}}if(s!=r){for(let l=a.length-1;l>a.length-Ve;l--)if(!Pe.test(a[l-1])&&Pe.test(a[l])){a=a.slice(0,l);break}}return y.announce.of(`${e.state.phrase("current match")}. ${a} ${e.state.phrase("on line")} ${o.number}.`)}var Hi=y.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),Yi=[$,ge.low(zi),Hi];var Gi="#e5c07b",$o="#e06c75",Ji="#56b6c2",Ki="#ffffff",He="#abb2bf",It="#7d8799",Qi="#61afef",Xi="#98c379",zo="#d19a66",Zi="#c678dd",es="#21252b",_o="#2c313a",jo="#282c34",Et="#353a42",ts="#3E4451",qo="#528bff";var ns=y.theme({"&":{color:He,backgroundColor:jo},".cm-content":{caretColor:qo},".cm-cursor, .cm-dropCursor":{borderLeftColor:qo},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:ts},".cm-panels":{backgroundColor:es,color:He},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:"1px solid #457dff"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"#6199ff2f"},".cm-activeLine":{backgroundColor:"#6699ff0b"},".cm-selectionMatch":{backgroundColor:"#aafe661a"},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bad0f847"},".cm-gutters":{backgroundColor:jo,color:It,border:"none"},".cm-activeLineGutter":{backgroundColor:_o},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:Et},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:Et,borderBottomColor:Et},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:_o,color:He}}},{dark:!0}),os=Tn.define([{tag:f.keyword,color:Zi},{tag:[f.name,f.deleted,f.character,f.propertyName,f.macroName],color:$o},{tag:[f.function(f.variableName),f.labelName],color:Qi},{tag:[f.color,f.constant(f.name),f.standard(f.name)],color:zo},{tag:[f.definition(f.name),f.separator],color:He},{tag:[f.typeName,f.className,f.number,f.changed,f.annotation,f.modifier,f.self,f.namespace],color:Gi},{tag:[f.operator,f.operatorKeyword,f.url,f.escape,f.regexp,f.link,f.special(f.string)],color:Ji},{tag:[f.meta,f.comment],color:It},{tag:f.strong,fontWeight:"bold"},{tag:f.emphasis,fontStyle:"italic"},{tag:f.strikethrough,textDecoration:"line-through"},{tag:f.link,color:It,textDecoration:"underline"},{tag:f.heading,fontWeight:"bold",color:$o},{tag:[f.atom,f.bool,f.special(f.variableName)],color:zo},{tag:[f.processingInstruction,f.string,f.inserted],color:Xi},{tag:f.invalid,color:Ki}]),Rt=[ns,ve(os)];var Ye=class e{constructor(t,n){this.yanchor=t,this.yhead=n}toJSON(){return{yanchor:G(this.yanchor),yhead:G(this.yhead)}}static fromJSON(t){return new e(I(t.yanchor),I(t.yhead))}};var Ge=class{constructor(t,n){this.ytext=t,this.awareness=n,this.undoManager=new J(t)}toYPos(t,n=0){return U(this.ytext,t,n)}fromYPos(t){let n=R(I(t),this.ytext.doc);if(n==null||n.type!==this.ytext)throw new Error("[y-codemirror] The position you want to retrieve was created by a different document");return{pos:n.index,assoc:n.assoc}}toYRange(t){let n=t.assoc,o=this.toYPos(t.anchor,n),r=this.toYPos(t.head,n);return new Ye(o,r)}fromYRange(t){let n=this.fromYPos(t.yanchor),o=this.fromYPos(t.yhead);return n.pos===o.pos?p.cursor(o.pos,o.assoc):p.range(n.pos,o.pos)}},Y=V.define({combine(e){return e[e.length-1]}}),Je=F.define(),Vt=class{constructor(t){this.view=t,this.conf=t.state.facet(Y),this._observer=(n,o)=>{if(o.origin!==this.conf){let r=n.delta,i=[],s=0;for(let a=0;a<r.length;a++){let l=r[a];l.insert!=null?i.push({from:s,to:s,insert:l.insert}):l.delete!=null?(i.push({from:s,to:s+l.delete,insert:""}),s+=l.delete):s+=l.retain}t.dispatch({changes:i,annotations:[Je.of(this.conf)]})}},this._ytext=this.conf.ytext,this._ytext.observe(this._observer)}update(t){if(!t.docChanged||t.transactions.length>0&&t.transactions[0].annotation(Je)===this.conf)return;let n=this.conf.ytext;n.doc.transact(()=>{let o=0;t.changes.iterChanges((r,i,s,a,l)=>{let h=l.sliceString(0,l.length,`
|
|
3
|
+
`);r!==i&&n.delete(r+o,i-r),h.length>0&&n.insert(r+o,h),o+=h.length-(i-r)})},this.conf)}destroy(){this._ytext.unobserve(this._observer)}},Yo=O.fromClass(Vt);var Go=y.baseTheme({".cm-ySelection":{},".cm-yLineSelection":{padding:0,margin:"0px 2px 0px 4px"},".cm-ySelectionCaret":{position:"relative",borderLeft:"1px solid black",borderRight:"1px solid black",marginLeft:"-1px",marginRight:"-1px",boxSizing:"border-box",display:"inline"},".cm-ySelectionCaretDot":{borderRadius:"50%",position:"absolute",width:".4em",height:".4em",top:"-.2em",left:"-.2em",backgroundColor:"inherit",transition:"transform .3s ease-in-out",boxSizing:"border-box"},".cm-ySelectionCaret:hover > .cm-ySelectionCaretDot":{transformOrigin:"bottom center",transform:"scale(0)"},".cm-ySelectionInfo":{position:"absolute",top:"-1.05em",left:"-1px",fontSize:".75em",fontFamily:"serif",fontStyle:"normal",fontWeight:"normal",lineHeight:"normal",userSelect:"none",color:"white",paddingLeft:"2px",paddingRight:"2px",zIndex:101,transition:"opacity .3s ease-in-out",backgroundColor:"inherit",opacity:0,transitionDelay:"0s",whiteSpace:"nowrap"},".cm-ySelectionCaret:hover > .cm-ySelectionInfo":{opacity:1,transitionDelay:"0s"}}),rs=F.define(),Ft=class extends un{constructor(t,n){super(),this.color=t,this.name=n}toDOM(){return fe("span",[te("class","cm-ySelectionCaret"),te("style",`background-color: ${this.color}; border-color: ${this.color}`)],[ne("\u2060"),fe("div",[te("class","cm-ySelectionCaretDot")]),ne("\u2060"),fe("div",[te("class","cm-ySelectionInfo")],[ne(this.name)]),ne("\u2060")])}eq(t){return t.color===this.color}compare(t){return t.color===this.color}updateDOM(){return!1}get estimatedHeight(){return-1}ignoreEvent(){return!0}},Ot=class{constructor(t){this.conf=t.state.facet(Y),this._listener=({added:n,updated:o,removed:r},i,s)=>{n.concat(o).concat(r).findIndex(l=>l!==this.conf.awareness.doc.clientID)>=0&&t.dispatch({annotations:[rs.of([])]})},this._awareness=this.conf.awareness,this._awareness.on("change",this._listener),this.decorations=cn.of([])}destroy(){this._awareness.off("change",this._listener)}update(t){let n=this.conf.ytext,o=n.doc,r=this.conf.awareness,i=[],s=this.conf.awareness.getLocalState();if(s!=null){let a=t.view.hasFocus&&t.view.dom.ownerDocument.hasFocus(),l=a?t.state.selection.main:null,h=s.cursor==null?null:I(s.cursor.anchor),m=s.cursor==null?null:I(s.cursor.head);if(l!=null){let d=U(n,l.anchor),g=U(n,l.head);(s.cursor==null||!st(h,d)||!st(m,g))&&r.setLocalStateField("cursor",{anchor:d,head:g})}else s.cursor!=null&&a&&r.setLocalStateField("cursor",null)}r.getStates().forEach((a,l)=>{if(l===r.doc.clientID)return;let h=a.cursor;if(h==null||h.anchor==null||h.head==null)return;let m=R(h.anchor,o),d=R(h.head,o);if(m==null||d==null||m.type!==n||d.type!==n)return;let{color:g="#30bced",name:C="Anonymous"}=a.user||{},x=a.user&&a.user.colorLight||g+"33",S=Gt(m.index,d.index),k=Jt(m.index,d.index),_=t.view.state.doc.lineAt(S),rt=t.view.state.doc.lineAt(k);if(_.number===rt.number)i.push({from:S,to:k,value:b.mark({attributes:{style:`background-color: ${x}`},class:"cm-ySelection"})});else{i.push({from:S,to:_.from+_.length,value:b.mark({attributes:{style:`background-color: ${x}`},class:"cm-ySelection"})}),i.push({from:rt.from,to:k,value:b.mark({attributes:{style:`background-color: ${x}`},class:"cm-ySelection"})});for(let it=_.number+1;it<rt.number;it++){let jt=t.view.state.doc.line(it).from;i.push({from:jt,to:jt,value:b.line({attributes:{style:`background-color: ${x}`,class:"cm-yLineSelection"}})})}}i.push({from:d.index,to:d.index,value:b.widget({side:d.index-m.index>0?-1:1,block:!1,widget:new Ft(g,C)})})}),this.decorations=b.set(i,!0)}},Jo=O.fromClass(Ot,{decorations:e=>e.decorations});var Ko=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}};var Ke=class{constructor(t){this.undoManager=t}addTrackedOrigin(t){this.undoManager.addTrackedOrigin(t)}removeTrackedOrigin(t){this.undoManager.removeTrackedOrigin(t)}undo(){return this.undoManager.undo()!=null}redo(){return this.undoManager.redo()!=null}},de=V.define({combine(e){return e[e.length-1]}}),ma=F.define(),Ut=class{constructor(t){this.view=t,this.conf=t.state.facet(de),this._undoManager=this.conf.undoManager,this.syncConf=t.state.facet(Y),this._beforeChangeSelection=null,this._mux=Ko(),this._onStackItemAdded=({stackItem:n,changedParentTypes:o})=>{o.has(this.syncConf.ytext)&&this._beforeChangeSelection&&!n.meta.has(this)&&n.meta.set(this,this._beforeChangeSelection)},this._onStackItemPopped=({stackItem:n})=>{let o=n.meta.get(this);if(o){let r=this.syncConf.fromYRange(o);t.dispatch(t.state.update({selection:r,effects:[y.scrollIntoView(r)]})),this._storeSelection()}},this._storeSelection=()=>{this._beforeChangeSelection=this.syncConf.toYRange(this.view.state.selection.main)},this._undoManager.on("stack-item-added",this._onStackItemAdded),this._undoManager.on("stack-item-popped",this._onStackItemPopped),this._undoManager.addTrackedOrigin(this.syncConf)}update(t){t.selectionSet&&(t.transactions.length===0||t.transactions[0].annotation(Je)!==this.syncConf)&&this._storeSelection()}destroy(){this._undoManager.off("stack-item-added",this._onStackItemAdded),this._undoManager.off("stack-item-popped",this._onStackItemPopped),this._undoManager.removeTrackedOrigin(this.syncConf)}},Qo=O.fromClass(Ut),Xo=({state:e,dispatch:t})=>e.facet(de).undo()||!0,Zo=({state:e,dispatch:t})=>e.facet(de).redo()||!0;var er=(e,t,{undoManager:n=new J(e)}={})=>{let o=new Ge(e,t),r=[Y.of(o),Yo];return t&&r.push(Go,Jo),n!==!1&&r.push(de.of(new Ke(n)),Qo,y.domEventHandlers({beforeinput(i,s){return i.inputType==="historyUndo"?Xo(s):i.inputType==="historyRedo"?Zo(s):!1}})),r};var Qe=Object.freeze({bold:"bold text",code:"code",italic:"emphasis",strikethrough:"struck text"}),Xe="link text",Nt="https://",Ze="alt text",Wt="https://",et="Video",$t="https://",tr="code",or=Object.freeze(["Column 1","Column 2"]),nr="Value";function is(e,t){let n=Math.max(0,Math.min(e.from,e.to,t)),o=Math.max(0,Math.min(Math.max(e.from,e.to),t));return{from:n,to:o}}function ss(e,t){return t===0||e[t-1]===`
|
|
4
|
+
`}function as(e,t){if(t<=0)return 0;let n=e.lastIndexOf(`
|
|
5
|
+
`,t-1);return n<0?0:n+1}function ls(e,t){let n=e.indexOf(`
|
|
6
|
+
`,t);return n<0?e.length:n}function rr(e,t){let{from:n}=t,{to:o}=t;return o>n&&ss(e,o)&&(o-=1),{from:as(e,n),to:ls(e,Math.max(n,o))}}function tt(e,t,n,o){let r=e.slice(t.from,t.to);return r.length>0?{anchor:t.from+n.length,from:t.from,head:t.from+n.length+r.length,insert:`${n}${r}${n}`,to:t.to}:{anchor:t.from+n.length,from:t.from,head:t.from+n.length+o.length,insert:`${n}${o}${n}`,to:t.to}}function zt(e){return/^https?:\/\//i.test(e.trim())}function cs(e,t){let n=e.slice(t.from,t.to);if(n.length>0&&zt(n))return{anchor:t.from+1,from:t.from,head:t.from+1+Xe.length,insert:`[${Xe}](${n})`,to:t.to};if(n.length>0){let o=`[${n}](`;return{anchor:t.from+o.length,from:t.from,head:t.from+o.length+Nt.length,insert:`${o}${Nt})`,to:t.to}}return{anchor:t.from+1,from:t.from,head:t.from+1+Xe.length,insert:`[${Xe}](${Nt})`,to:t.to}}function hs(e,t){let n=e.slice(t.from,t.to);if(n.length>0&&zt(n))return{anchor:t.from+2,from:t.from,head:t.from+2+Ze.length,insert:``,to:t.to};if(n.length>0){let o=``,to:t.to}}return{anchor:t.from+2,from:t.from,head:t.from+2+Ze.length,insert:``,to:t.to}}function us(e,t){let n=e.slice(t.from,t.to);if(n.length>0&&zt(n))return{anchor:t.from+2,from:t.from,head:t.from+2+et.length,insert:``,to:t.to};if(n.length>0){let o=``,to:t.to}}return{anchor:t.from+2,from:t.from,head:t.from+2+et.length,insert:``,to:t.to}}function nt(e,t,n,o){let r=rr(e,t),s=e.slice(r.from,r.to).split(`
|
|
7
|
+
`),a=d=>o.test(d),l=s.every(d=>d.trim().length===0||a(d)),h=0,m=s.map(d=>{if(d.trim().length===0)return d;if(l)return a(d)?d.replace(o,""):d;let g=n(h);return h+=1,`${g}${d}`});return{anchor:r.from,from:r.from,head:r.from+m.join(`
|
|
8
|
+
`).length,insert:m.join(`
|
|
9
|
+
`),to:r.to}}function ms(e,t){return nt(e,t,()=>"## ",/^#{1,6}\s+/)}function ds(e,t){return nt(e,t,()=>"- ",/^[-*+]\s+/)}function fs(e,t){return nt(e,t,()=>"> ",/^>\s+/)}function ps(e,t){return nt(e,t,()=>"- [ ] ",/^-\s\[(?: |x|X)\]\s+/)}function gs(e,t){let n=rr(e,t),r=e.slice(n.from,n.to).split(`
|
|
10
|
+
`),i=r.every(l=>l.trim().length===0||/^\d+\.\s+/.test(l)),s=1,a=r.map(l=>{if(l.trim().length===0)return l;if(i)return l.replace(/^\d+\.\s+/,"");let h=`${s}. ${l}`;return s+=1,h});return{anchor:n.from,from:n.from,head:n.from+a.join(`
|
|
11
|
+
`).length,insert:a.join(`
|
|
12
|
+
`),to:n.to}}function xs(e){let n=e.replace(/\r\n/g,`
|
|
13
|
+
`).match(/^```[^\n]*\n([\s\S]*?)\n```$/);return n?n[1]:null}function ys(e,t){let n=e.slice(t.from,t.to);if(n.length>0){let o=xs(n);return o!==null?{anchor:t.from,from:t.from,head:t.from+o.length,insert:o,to:t.to}:{anchor:t.from+4,from:t.from,head:t.from+4+n.length,insert:`\`\`\`
|
|
14
|
+
${n}
|
|
15
|
+
\`\`\``,to:t.to}}return{anchor:t.from+4,from:t.from,head:t.from+4+tr.length,insert:`\`\`\`
|
|
16
|
+
${tr}
|
|
17
|
+
\`\`\``,to:t.to}}function ir(e,t,n,o,r=0){let i=t.from>0&&e[t.from-1]!==`
|
|
18
|
+
`,s=t.to<e.length&&e[t.to]!==`
|
|
19
|
+
`,a=i?`
|
|
20
|
+
`:"",h=`${a}${n}${s?`
|
|
21
|
+
`:""}`,m=t.from+a.length+o;return{anchor:m,from:t.from,head:m+r,insert:h,to:t.to}}function Cs(e=""){let t=e.trim()||nr;return[`| ${or.join(" | ")} |`,"| --- | --- |",`| ${t} | ${nr} |`].join(`
|
|
22
|
+
`)}function Ss(e,t){let n=e.slice(t.from,t.to),o=Cs(n);return ir(e,t,o,2,or[0].length)}function bs(e,t){return ir(e,t,"---",4,0)}function sr(e,t,n){let o=String(e??""),r=is(t,o.length);switch(n){case"bold":return tt(o,r,"**",Qe.bold);case"italic":return tt(o,r,"_",Qe.italic);case"strikethrough":return tt(o,r,"~~",Qe.strikethrough);case"code":return tt(o,r,"`",Qe.code);case"link":return cs(o,r);case"image":return hs(o,r);case"video":return us(o,r);case"heading":return ms(o,r);case"quote":return fs(o,r);case"bullet-list":return ds(o,r);case"numbered-list":return gs(o,r);case"task-list":return ps(o,r);case"code-block":return ys(o,r);case"table":return Ss(o,r);case"horizontal-rule":return bs(o,r);default:return null}}function ar(e){return t=>{let n=t.state.doc.lineAt(t.pos),o=n.text.slice(0,t.pos-n.from),r=o.lastIndexOf("[[");if(r===-1)return null;let i=o.slice(r+2);if(i.includes("]]"))return null;let s=i.toLowerCase(),a=n.from+r+2,h=e().map(m=>{let d=m.replace(/\.md$/i,""),g=d.split("/").pop();return{filePath:m,label:d,fileName:g}}).filter(({label:m,fileName:d})=>m.toLowerCase().includes(s)||d.toLowerCase().includes(s)).map(({label:m,fileName:d})=>({label:m,detail:m.includes("/")?` ${d}`:void 0,apply:(g,C,x,S)=>{let k=g.state.doc.toString(),_=S;k.slice(S,S+2)==="]]"&&(_=S+2),g.dispatch({changes:{from:x,to:_,insert:`${C.label}]]`},selection:{anchor:x+C.label.length+2}})},type:"text",boost:m.toLowerCase().startsWith(s)?1:0}));return h.length===0?null:{from:a,options:h,filter:!1}}}var ks=new Set(["@startuml","@enduml","@startmindmap","@endmindmap","@startwbs","@endwbs","@startgantt","@endgantt","@startjson","@endjson","@startyaml","@endyaml","@startsalt","@endsalt"]),Ls=new Set(["activate","actor","agent","allowmixing","alt","annotation","artifact","as","autonumber","boundary","box","break","caption","card","case","circle","class","cloud","collections","component","control","create","critical","database","deactivate","destroy","detach","else","elseif","end","endlegend","endif","endwhile","entity","enum","exception","file","folder","footer","fork","frame","group","header","hide","hnote","if","interface","json","kill","label","legend","loop","map","namespace","newpage","node","note","object","of","opt","order","over","package","page","par","participant","partition","person","port","protocol","queue","rectangle","ref","repeat","return","rnote","show","skinparam","split","stack","start","state","stop","storage","struct","switch","then","title","usecase","while"]),vs=new Set(["false","no","off","on","true","yes"]);function ws(e){let t=e.match(/[@!A-Za-z_][\w.-]*/u,!1);return t?(e.match(/[@!A-Za-z_][\w.-]*/u),t[0]):""}var Ms=we.define({languageData:{commentTokens:{block:{close:"'/",open:"/'"},line:"'"}},startState(){return{inBlockComment:!1}},token(e,t){if(t.inBlockComment)return e.skipTo("'/")?(e.match("'/"),t.inBlockComment=!1):e.skipToEnd(),"comment";if(e.eatSpace())return null;if(e.match("/'"))return t.inBlockComment=!0,"comment";let n=e.pos===0?" ":e.string.charAt(e.pos-1);if(e.peek()==="'"&&(e.sol()||/\s/u.test(n)))return e.skipToEnd(),"comment";if(e.match(/"(?:[^"\\]|\\.)*"?/u))return"string";if(e.match(/#[0-9a-f]{3,8}\b/iu)||e.match(/#[A-Za-z][\w-]*/u))return"atom";if(e.match(/\b\d+(?:\.\d+)?\b/u))return"number";if(e.match(/[<>{}[\]():,]/u))return"punctuation";if(e.match(/[ox*+<#]?[-=.\\/]+(?:left|right|up|down)?[-=.\\/]*[ox*+>#]?/iu))return"operator";let o=ws(e);if(o){let r=o.toLowerCase();return r.startsWith("!")||ks.has(r)?"meta":Ls.has(r)?"keyword":vs.has(r)?"bool":/^[A-Z][A-Z0-9_]*$/u.test(o)?"typeName":"variableName"}return e.next(),null}}),_t=new ke(Ms),lr=c.of({alias:["plantuml","puml"],extensions:["plantuml","puml"],name:"PlantUML",support:_t});function As(e){let t=Array.from(e?.clipboardData?.files??[]);for(let o of t)if(o?.type?.startsWith?.("image/"))return o;let n=Array.from(e?.clipboardData?.items??[]);for(let o of n){if(o.kind!=="file"||!o.type?.startsWith?.("image/"))continue;let r=o.getAsFile?.();if(r)return r}return null}function cr(e,t){let n=As(e);return n?typeof t!="function"?(console.warn("[editor] Ignoring pasted image because no image paste handler is registered."),!1):(console.debug("[editor] Detected pasted image.",{name:n.name??"",size:n.size??null,type:n.type??""}),e.preventDefault?.(),Promise.resolve(t(n)).catch(o=>{console.error("[editor] Failed to process pasted image:",o)}),!0):!1}var Ts=[...Do,lr];function hr(e){let t=e==="dark"?"oklch(from var(--color-surface-offset) l c h / 0.55)":"oklch(from var(--color-surface-offset) l c h / 0.75)",n=e==="dark"?"oklch(from var(--color-primary) l c h / 0.28)":"oklch(from var(--color-primary) l c h / 0.18)",o=e==="dark"?"oklch(from var(--color-primary) l c h / 0.4)":"oklch(from var(--color-primary) l c h / 0.26)",r=e==="dark"?"oklch(from var(--color-primary) l c h / 0.65)":"oklch(from var(--color-primary) l c h / 0.5)";return y.theme({"&":{backgroundColor:"var(--color-bg)",color:"var(--color-text)"},".cm-content":{caretColor:"var(--color-primary)",fontFamily:"var(--font-mono)",padding:"16px 0"},".cm-cursor, .cm-dropCursor":{borderLeftColor:"var(--color-primary)",borderLeftWidth:"2px"},".cm-foldPlaceholder":{backgroundColor:"var(--color-surface-dynamic)",border:"none",color:"var(--color-text-muted)"},".cm-gutters":{backgroundColor:"var(--color-surface)",borderRight:"1px solid var(--color-divider)",color:"var(--color-text-muted)",minWidth:"44px"},".cm-line":{padding:"0 16px"},".cm-activeLine":{backgroundColor:t,boxShadow:`inset 3px 0 0 ${n}`},".cm-activeLineGutter":{backgroundColor:t,boxShadow:`inset 3px 0 0 ${n}`,color:"var(--color-text-muted)"},".cm-matchingBracket":{backgroundColor:"var(--color-primary-highlight)",outline:"1px solid var(--color-primary)"},".cm-selectionMatch":{backgroundColor:"var(--color-primary-highlight)"},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:o},"&.cm-focused .cm-selectionLayer .cm-selectionBackground":{border:`1px solid ${r}`,borderRadius:"2px"}},{dark:e==="dark"})}function Ds(e){return typeof e=="string"&&(e.toLowerCase().endsWith(".puml")||e.toLowerCase().endsWith(".plantuml"))?_t:Pn({base:Vn,codeLanguages:Ts})}function ur(e){return{from:Math.min(...e.ranges.map(t=>Math.min(t.from,t.to))),to:Math.max(...e.ranges.map(t=>Math.max(t.from,t.to)))}}var ot=class{constructor({editorContainer:t,getFileList:n,initialTheme:o,lineInfoElement:r,lineWrappingEnabled:i=!0,onDocChanged:s=null,onImagePaste:a=null,onSelectionChanged:l=null,onViewportChanged:h=null}){this.editorContainer=t,this.getFileList=n??(()=>[]),this.initialTheme=o,this.lineInfoElement=r,this.lineWrappingEnabled=i,this.onDocChanged=s,this.onImagePaste=a,this.onSelectionChanged=l,this.onViewportChanged=h,this.editorView=null,this.themeCompartment=new xe,this.syntaxThemeCompartment=new xe,this.lineWrappingCompartment=new xe,this.viewportFrame=0,this.handleScroll=()=>{this.viewportFrame||(this.viewportFrame=requestAnimationFrame(()=>{this.viewportFrame=0,this.emitViewportChange()}))}}initialize({awareness:t,filePath:n,undoManager:o,ytext:r}){let i=y.updateListener.of(a=>{a.docChanged&&this.onDocChanged?.(),(a.selectionSet||a.docChanged)&&(this.updateCursorInfo(a.state),this.onSelectionChanged?.(a.state))}),s=this.editorContainer.querySelector("#editorLoading");Array.from(this.editorContainer.children).forEach(a=>{a!==s&&a.remove()}),this.editorView=new y({parent:this.editorContainer,state:ie.create({doc:r.toString(),extensions:[kn(),Ln(),gn(),Gn(),An(),pn(),ie.allowMultipleSelections.of(!0),wn(),ve(Dn,{fallback:!0}),Bn(),En(),Rn({override:[ar(this.getFileList)]}),yn(),Cn(),xn(),Po(),dn.of([...In,...Ao,...Xn,...Wo,...Mn,To]),y.contentAttributes.of({"aria-label":"Markdown editor"}),ge.highest(y.domEventHandlers({paste:a=>cr(a,this.onImagePaste)})),Ds(n),this.themeCompartment.of(hr(this.initialTheme)),this.syntaxThemeCompartment.of(this.initialTheme==="dark"?Rt:[]),this.lineWrappingCompartment.of(this.lineWrappingEnabled?y.lineWrapping:[]),er(r,t,{undoManager:o}),i]})}),this.editorView.scrollDOM.addEventListener("scroll",this.handleScroll,{passive:!0}),this.updateCursorInfo(this.editorView.state),this.onSelectionChanged?.(this.editorView.state),this.emitViewportChange()}destroy(){this.viewportFrame&&(cancelAnimationFrame(this.viewportFrame),this.viewportFrame=0),this.editorView?.scrollDOM?.removeEventListener("scroll",this.handleScroll),this.editorView?.destroy(),this.editorView=null,this.editorContainer&&(this.editorContainer.innerHTML="")}getText(){return this.editorView?.state.doc.toString()??""}getDoc(){return this.editorView?.state.doc??null}getState(){return this.editorView?.state??null}getScrollContainer(){return this.editorView?.scrollDOM??null}applyTheme(t){this.editorView&&this.editorView.dispatch({effects:[this.themeCompartment.reconfigure(hr(t)),this.syntaxThemeCompartment.reconfigure(t==="dark"?Rt:[])]})}isLineWrappingEnabled(){return this.lineWrappingEnabled}setLineWrapping(t){return this.lineWrappingEnabled=!!t,this.editorView?(this.editorView.dispatch({effects:this.lineWrappingCompartment.reconfigure(this.lineWrappingEnabled?y.lineWrapping:[])}),this.lineWrappingEnabled):this.lineWrappingEnabled}requestMeasure(){this.editorView?.requestMeasure()}getViewportState(t=.35){return{topLine:this.getTopVisibleLineNumber(t),viewportRatio:t}}getTopVisibleLineNumber(t=0){if(!this.editorView)return 1;let n=this.editorView.scrollDOM.getBoundingClientRect(),o=Math.max(n.height*t,8),r=this.editorView.lineBlockAtHeight(n.top+o-this.editorView.documentTop);return r?this.editorView.state.doc.lineAt(r.from).number:1}getCurrentSelectionLineRange(){let t=this.editorView?.state;if(!t)return null;let{doc:n,selection:o}=t,{from:r,to:i}=ur(o),s=n.lineAt(r).number,a=Math.min(Math.max(i,r),n.length);return a>r&&n.lineAt(a).from===a&&(a-=1),{endLine:n.lineAt(a).number,startLine:s}}getCurrentSelectionCommentAnchor(){let t=this.editorView?.state;if(!t)return null;let{doc:n,selection:o}=t,{from:r,to:i}=ur(o);if(r===i){let l=n.lineAt(r);return{anchorKind:"line",anchorQuote:re(l.text),endIndex:l.to,endLine:l.number,startIndex:l.from,startLine:l.number}}let a=Math.min(Math.max(i,r),n.length);return a>r&&n.lineAt(a).from===a&&(a-=1),{anchorKind:"text",anchorQuote:re(n.sliceString(r,i)),endIndex:i,endLine:n.lineAt(a).number,startIndex:r,startLine:n.lineAt(r).number}}normalizeLineRange({endLine:t,startLine:n}){let o=this.editorView?.state;if(!o)return{endLine:1,startLine:1};let r=o.doc.lines,i=Math.min(Math.max(Math.round(n??1),1),r);return{endLine:Math.min(Math.max(Math.round(t??i),i),r),startLine:i}}getLineInfoAt(t){let n=this.editorView?.state;if(!n)return null;let o=Math.min(Math.max(t,0),n.doc.length),r=n.doc.lineAt(o);return{line:r,lineNumber:r.number}}getAnchorClientRect(t){let n=this.editorView?.state,o=this.editorView;if(!n||!o||!t)return null;let r=t.anchorKind||t.kind||"line",i=Math.min(Math.max(Math.round(t.startIndex??0),0),n.doc.length),s=Math.min(Math.max(Math.round(t.endIndex??i),i),n.doc.length);if(r==="text"&&s>i){let S=o.coordsAtPos(i),k=o.coordsAtPos(Math.max(s-1,i));if(S&&k)return{bottom:Math.max(S.bottom,k.bottom),height:Math.max(S.bottom,k.bottom)-Math.min(S.top,k.top),left:Math.min(S.left,k.left),right:Math.max(S.right,k.right),top:Math.min(S.top,k.top),width:Math.max(S.right,k.right)-Math.min(S.left,k.left)}}let a=n.doc.line(Math.min(Math.max(Math.round(t.startLine??1),1),n.doc.lines)),l=o.lineBlockAt(a.from),h=o.scrollDOM.getBoundingClientRect(),m=o.scrollDOM.scrollTop,d=o.contentDOM.getBoundingClientRect(),g=d.left,C=Math.max(d.right,h.right-8),x=h.top+l.top-m;return{bottom:x+l.height,height:l.height,left:g,right:C,top:x,width:Math.max(C-g,0)}}getSelectionChipClientRect(t){let n=this.editorView?.state,o=this.editorView;if(!n||!o||!t)return null;let r=Math.min(Math.max(Math.round(t.startIndex??0),0),n.doc.length),i=n.doc.lineAt(r),s=o.lineBlockAt(i.from),a=o.scrollDOM.getBoundingClientRect(),l=o.scrollDOM.scrollTop,h=o.contentDOM.getBoundingClientRect(),m=Math.max(h.right,a.right-8),d=a.top+s.top-l;return{bottom:d+s.height,height:s.height,left:h.left,right:m,top:d,width:Math.max(m-h.left,0)}}scrollToLine(t,n=0){let o=this.editorView?.state,r=this.editorView?.scrollDOM;if(!o||!r||!this.editorView)return!1;let i=Math.min(Math.max(Math.round(t),1),o.doc.lines),s=o.doc.line(i),a=this.editorView.lineBlockAt(s.from),l=Math.max(r.scrollHeight-r.clientHeight,0),h=n>0?r.clientHeight*n:8,m=Math.min(Math.max(a.top-h,0),l);return r.scrollTo({top:m}),!0}scrollToPosition(t,n="center"){let o=this.editorView?.state,r=this.editorView?.scrollDOM;if(!o||!r||!this.editorView)return!1;let i=Math.min(Math.max(Math.round(t),0),o.doc.length),s=this.editorView.lineBlockAt(i),a=Math.max(r.scrollHeight-r.clientHeight,0),l=s.top;return n==="center"&&(l=s.top-(r.clientHeight-s.height)/2),r.scrollTo({top:Math.min(Math.max(l,0),a)}),!0}applyMarkdownToolbarAction(t){if(!this.editorView)return!1;let{state:n}=this.editorView,o=n.doc.toString(),r=!1,i=n.changeByRange(s=>{let a=sr(o,s,t);return a?(r=!0,{changes:{from:a.from,insert:a.insert,to:a.to},range:p.range(a.anchor,a.head)}):{range:s}});return r?(this.editorView.dispatch(n.update(i,{scrollIntoView:!0,userEvent:"input"})),this.editorView.focus(),!0):!1}insertText(t){if(!this.editorView)return!1;let n=String(t??""),{state:o}=this.editorView,r=o.selection.main,i=r.from+n.length;return this.editorView.dispatch({changes:{from:r.from,insert:n,to:r.to},scrollIntoView:!0,selection:{anchor:i,head:i},userEvent:"input"}),this.editorView.focus(),!0}updateCursorInfo(t){if(!this.lineInfoElement)return;let n=t.selection.main.head,o=t.doc.lineAt(n),r=n-o.from+1;this.lineInfoElement.textContent=`Ln ${o.number}, Col ${r}`}emitViewportChange(){this.onViewportChanged?.(this.getViewportState())}};var mr=class{constructor({editorContainer:t,lineWrappingEnabled:n=!0,initialTheme:o,lineInfoElement:r,onAwarenessChange:i,onConnectionChange:s,onCommentsChange:a,onContentChange:l,onImagePaste:h,onSelectionChange:m,preferredUserName:d,localUser:g,getFileList:C}){this.onAwarenessChange=i,this.onCommentsChange=a,this.onContentChange=l,this.onSelectionChange=m,this.hasDeliveredContent=!1,this.lastDeliveredContent=null,this.collaborationClient=new Ae({localUser:g,onAwarenessChange:x=>this.onAwarenessChange?.(x),onConnectionChange:s,onInitialSync:()=>this.emitContentChange(),preferredUserName:d,resolveAwarenessCursor:x=>this.resolveAwarenessCursor(x)}),this.viewAdapter=new ot({editorContainer:t,getFileList:C||(()=>[]),initialTheme:o,lineInfoElement:r,lineWrappingEnabled:n,onDocChanged:()=>{this.emitContentChange()},onImagePaste:h,onViewportChanged:x=>{this.collaborationClient.setLocalViewport(x)},onSelectionChanged:()=>{this.onSelectionChange?.(this.getCurrentSelectionCommentAnchor())}}),this.commentThreadStore=new Me({getDoc:()=>this.collaborationClient.ydoc,getEditorState:()=>this.viewAdapter.getState(),getLocalUser:()=>this.collaborationClient.getLocalUser(),onCommentsChange:x=>this.onCommentsChange?.(x)})}async initialize(t){this.hasDeliveredContent=!1,this.lastDeliveredContent=null;let n=await this.collaborationClient.initialize(t);this.viewAdapter.initialize({awareness:n.awareness,filePath:t,undoManager:n.undoManager,ytext:n.ytext}),this.commentThreadStore.bind({commentThreads:n.commentThreads,ydoc:n.ydoc,ytext:n.ytext}),this.onAwarenessChange?.(this.collaborationClient.collectUsers(o=>this.resolveAwarenessCursor(o)))}emitContentChange({force:t=!1}={}){let n=this.getText();return!t&&this.hasDeliveredContent&&n===this.lastDeliveredContent?!1:(this.hasDeliveredContent=!0,this.lastDeliveredContent=n,this.onContentChange?.(),!0)}ensureInitialContent(){return this.emitContentChange()}applyTheme(t){this.viewAdapter.applyTheme(t)}getText(){return this.collaborationClient.getText()||this.viewAdapter.getText()}getScrollContainer(){return this.viewAdapter.getScrollContainer()}getTopVisibleLineNumber(t=0){return this.viewAdapter.getTopVisibleLineNumber(t)}getLocalUser(){return this.collaborationClient.getLocalUser()}get awareness(){return this.collaborationClient.awareness}get provider(){return this.collaborationClient.provider}get ydoc(){return this.collaborationClient.ydoc}get ytext(){return this.collaborationClient.ytext}getCurrentSelectionLineRange(){return this.viewAdapter.getCurrentSelectionLineRange()}getCurrentSelectionCommentAnchor(){return this.viewAdapter.getCurrentSelectionCommentAnchor()}getCommentAnchorClientRect(t){return this.viewAdapter.getAnchorClientRect(t)}getSelectionChipClientRect(t){return this.viewAdapter.getSelectionChipClientRect(t)}getCommentThreads(){return this.commentThreadStore.getCommentThreads()}createCommentThread(t){return this.commentThreadStore.createCommentThread(t)}replyToCommentThread(t,n){return this.commentThreadStore.replyToCommentThread(t,n)}toggleCommentReaction(t,n,o){return this.commentThreadStore.toggleCommentReaction(t,n,o)}deleteCommentThread(t){return this.commentThreadStore.deleteCommentThread(t)}isLineWrappingEnabled(){return this.viewAdapter.isLineWrappingEnabled()}setLineWrapping(t){return this.viewAdapter.setLineWrapping(t)}scrollToLine(t,n=0){return this.viewAdapter.scrollToLine(t,n)}getUserCursor(t){return this.collaborationClient.getUserCursor(t,n=>this.resolveAwarenessCursor(n))}getUserViewport(t){return this.collaborationClient.getUserViewport(t)}scrollToPosition(t,n="center"){return this.viewAdapter.scrollToPosition(t,n)}scrollToUserViewport(t){let n=this.getUserViewport(t);return n?this.scrollToLine(n.topLine,n.viewportRatio):!1}scrollToUserCursor(t,n="center"){let o=this.getUserCursor(t);return o?this.scrollToPosition(o.cursorHead,n)||this.scrollToLine(o.cursorLine):!1}setUserName(t){return this.collaborationClient.setUserName(t)}requestMeasure(){this.viewAdapter.requestMeasure()}applyMarkdownToolbarAction(t){return this.viewAdapter.applyMarkdownToolbarAction(t)}insertText(t){return this.viewAdapter.insertText(t)}waitForInitialSync(t=1500){return this.collaborationClient.waitForInitialSync(t)}destroy(){this.commentThreadStore.unbind(),this.hasDeliveredContent=!1,this.lastDeliveredContent=null,this.collaborationClient.destroy(),this.viewAdapter.destroy()}resolveAwarenessCursor(t){let n=this.collaborationClient.ydoc,o=this.collaborationClient.ytext,r=this.viewAdapter.getState();if(!t?.anchor||!t?.head||!n||!r||!o)return null;let i=R(t.anchor,n),s=R(t.head,n);if(!i||!s||i.type!==o||s.type!==o)return null;let a=r.doc.lineAt(s.index);return{cursorAnchor:i.index,cursorHead:s.index,cursorLine:a.number}}};export{mr as EditorSession};
|