@hyperpuncher/pi-ui 0.38.2 → 0.39.0
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 +53 -18
- package/dist/npm/server-main.js +123 -120
- package/package.json +7 -7
- package/static/app/file-transfer.js +13 -2
- package/static/app/file-transfer_test.ts +16 -0
- package/static/build/chunks/{code-theme-y49p9zss.js → code-theme-4n26zw8w.js} +1 -1
- package/static/build/chunks/{fonts-pcnzbv4q.js → fonts-fmjkwnbd.js} +1 -1
- package/static/build/chunks/{main-61mzprk0.js → main-3kywnyz0.js} +5 -5
- package/static/build/chunks/{main-wcnadmhs.js → main-r8cn68g6.js} +1 -1
- package/static/build/chunks/{workspace-review-3scrbyaw.js → workspace-review-p84b3znd.js} +1 -1
- package/static/build/main.js +4 -4
- package/static/vendor/datastar-inspector.min.js +0 -1021
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{$ as yn,B as Nr,C as Fc,D as Rs,E as qr,F as ic,G as Is,H as Ms,I as Hs,J as Ps,K as hn,L as fn,M as pn,N as mn,O as z,P as Qd,Q as Yd,R as Jd,S as rd,T as od,U as Er,V as pc,W as Ki,X as bn,Y as _c,Z as Oc,_ as mc,aa as Dr,ba as ea,ca as le,da as ui,ea as ta,fa as hi,ga as ln,ha as yt,ia as $n,ja as Ee,ka as oe,pa as gn,qa as yr,ta as Fr}from"./main-7fchxg57.js";import{Pb as $r,Rb as Gc}from"./main-
|
|
1
|
+
import{$ as yn,B as Nr,C as Fc,D as Rs,E as qr,F as ic,G as Is,H as Ms,I as Hs,J as Ps,K as hn,L as fn,M as pn,N as mn,O as z,P as Qd,Q as Yd,R as Jd,S as rd,T as od,U as Er,V as pc,W as Ki,X as bn,Y as _c,Z as Oc,_ as mc,aa as Dr,ba as ea,ca as le,da as ui,ea as ta,fa as hi,ga as ln,ha as yt,ia as $n,ja as Ee,ka as oe,pa as gn,qa as yr,ta as Fr}from"./main-7fchxg57.js";import{Pb as $r,Rb as Gc}from"./main-3kywnyz0.js";import{ec as Gs,fc as p}from"./main-x61973bh.js";function se(e,t){return e-(t===0?0:1)}function ee(e,t){return se(e,t)+t}function ke(e){let t=e.length;if(e.charCodeAt(t-1)===10){if(t--,e.charCodeAt(t-1)===13)t--}return e.slice(0,t)}var jc=new TextEncoder,qc=new TextDecoder("utf-8",{ignoreBOM:!0}),Kc=/[\uD800-\uDFFF]/;var zt=new Uint8Array(1024);function Vr(){if(zt.length!==1024)zt=new Uint8Array(1024)}function Z(e){if(e.length===0)return e;if(Kc.test(e))return JSON.parse(JSON.stringify(e));let t=e.length*3;if(zt.length<t)zt=new Uint8Array(t);let{written:n}=jc.encodeInto(e,zt);return qc.decode(zt.subarray(0,n))}function ws(e){for(let t of e.hunks){for(let n=0;n<t.hunkContent.length;n++){let i=t.hunkContent[n];if(i.type!=="change")continue;let r=Yc(e,i);if(r!=null)t.hunkContent.splice(n,1,...r),n+=r.length-1}Xc(t,e)}}function Xc(e,t){let{hunkContent:n}=e;for(let i=1;i<n.length;i++){let r=n[i],o=n[i-1];if(r.type!=="change"||r.additions>0&&r.deletions>0||o.type!=="context")continue;let s=r.additions>0,a=s?t.additionLines:t.deletionLines,l=s?r.additionLineIndex:r.deletionLineIndex,d=s?r.additions:r.deletions,c=a[l]??"";if(c.trim()!=="")continue;let u=!0;for(let v=1;v<d;v++)if(a[l+v]!==c){u=!1;break}if(!u)continue;let h=0;while(h<o.lines&&t.additionLines[o.additionLineIndex+o.lines-1-h]===c)h++;if(h===0)continue;if(i===1&&h===o.lines)continue;r.additionLineIndex-=h,r.deletionLineIndex-=h;let f=r.additionLineIndex+r.additions,m=r.deletionLineIndex+r.deletions,y=n[i+1];if(y?.type==="context")y.lines+=h,y.additionLineIndex=f,y.deletionLineIndex=m;else n.splice(i+1,0,{type:"context",lines:h,additionLineIndex:f,deletionLineIndex:m});if(o.lines-=h,o.lines===0)n.splice(i-1,1),i--}}function Yc(e,t){let{deletions:n,additions:i,deletionLineIndex:r,additionLineIndex:o}=t,s=Math.min(n,i),a=Math.abs(i-n);if(s===0||a===0||s*(a+1)>4096)return null;let l=[];for(let y=0;y<n;y++)l.push(ks(e.deletionLines[r+y]??""));let d=[];for(let y=0;y<i;y++)d.push(ks(e.additionLines[o+y]??""));let c=i>n,u=0,h=-1;for(let y=0;y<=a;y++){let v=0;for(let g=0;g<s;g++)v+=Zc(l[g+(c?0:y)],d[g+(c?y:0)]);if(y===0)h=v+s*0.5;else if(v>h)h=v,u=y}if(u===0)return null;let f=[],m=(y,v,g,S)=>{if(y>0||v>0)f.push({type:"change",deletions:y,additions:v,deletionLineIndex:g,additionLineIndex:S})};if(c)m(0,u,r,o),m(s,s,r,o+u),m(0,i-s-u,r+s,o+u+s);else m(u,0,r,o),m(s,s,r+u,o),m(n-s-u,0,r+u+s,o+s);return f}var Jc=/\s+/g;function ks(e){return e.replace(Jc,"")}function Zc(e,t){if(e===t)return 1;let n=Math.max(e.length,t.length),i=Math.min(e.length,t.length);if(i===0)return 0;let r=0;while(r<i&&e[r]===t[r])r++;let o=0;while(o<i-r&&e[e.length-1-o]===t[t.length-1-o])o++;return(r+o)/n}function Ns(e,t,n){try{return Qc(e,t,n)}finally{Vr()}}function Qc(e,t,n=!1){let i=lu(e),r=i?nu(e):iu(e),o,s=[];for(let a of r){if(i&&!qr.test(a)){if(o==null)o=Z(a);else if(n)throw Error("parsePatchContent: unknown file blob");else console.error("parsePatchContent: unknown file blob:",a);continue}else if(!i&&!ru(a)){if(o==null)o=Z(a);else if(n)throw Error("parsePatchContent: unknown file blob");else console.error("parsePatchContent: unknown file blob:",a);continue}let l=Ds(a,{cacheKey:t!=null?`${t}-${s.length}`:void 0,isGitDiff:i,throwOnError:n});if(l!=null)s.push(l)}return{patchMetadata:o,files:s}}function Kr(e,t){try{return Ds(e,t)}finally{Vr()}}function Ds(e,{cacheKey:t,isGitDiff:n=qr.test(e),oldFile:i,newFile:r,throwOnError:o=!1}={}){let s=0,a=Us(e,"@@ "),l,d=i==null||r==null,c=0,u=0;for(let h of a){let f=Fs(h),m=f[0];if(m==null){if(o)throw Error("parsePatchContent: invalid hunk");else console.error("parsePatchContent: invalid hunk",h);continue}let y=Os(m),v=0,g=0;if(y==null||l==null){if(l!=null){if(o)throw Error("parsePatchContent: Invalid hunk");else console.error("parsePatchContent: Invalid hunk",h);continue}if(l={name:"",type:"change",hunks:[],splitLineCount:0,unifiedLineCount:0,isPartial:d,additionLines:!d&&i!=null&&r!=null?Ls(r.contents):[],deletionLines:!d&&i!=null&&r!=null?Ls(i.contents):[],cacheKey:As(t)},l.additionLines.length===1&&r?.contents==="")l.additionLines.length=0;if(l.deletionLines.length===1&&i?.contents==="")l.deletionLines.length=0;for(let L of f){if(L.startsWith("diff --git")){let O=L.trim().match(Hs),A=O?.[1]??O?.[2],R=O?.[3]??O?.[4];if(A==null||R==null){if(o)throw Error("parsePatchContent: invalid git diff header");else console.error("parsePatchContent: invalid git diff header",L);continue}if(l.name=Z(R.trim()),A!==R)l.prevName=Z(A.trim());continue}let I=L.startsWith("---")||L.startsWith("+++")?L.match(n?Ms:Is):null;if(I!=null){let[,O,A]=I;if(O==="---"&&A!=="/dev/null"){let R=Z(A.trim());l.prevName=R,l.name=R}else if(O==="+++"&&A!=="/dev/null")l.name=Z(A.trim())}else if(n){if(L.startsWith("new mode "))l.mode=Z(L.slice(8).trim());if(L.startsWith("old mode "))l.prevMode=Z(L.slice(8).trim());if(L.startsWith("new file mode"))l.type="new",l.mode=Z(L.slice(13).trim());if(L.startsWith("deleted file mode"))l.type="deleted",l.mode=Z(L.slice(17).trim());if(L.startsWith("similarity index"))if(L.startsWith("similarity index 100%"))l.type="rename-pure";else l.type="rename-changed";if(L.startsWith("index ")){let[,O,A,R]=L.trim().match(Ps)??[];if(O!=null)l.prevObjectId=Z(O);if(A!=null)l.newObjectId=Z(A);if(R!=null)l.mode=Z(R)}if(L.startsWith("rename from "))l.prevName=Z(L.slice(12).trim());if(L.startsWith("rename to "))l.name=Z(L.slice(10).trim())}}continue}let S,b;while(f.length>0&&(f[f.length-1]===`
|
|
2
2
|
`||f[f.length-1]==="\r"||f[f.length-1]===`\r
|
|
3
3
|
`||f[f.length-1]===""))f.pop();let{additionStart:x,deletionStart:C}=y;c=d?c:C-1,u=d?u:x-1;let k={collapsedBefore:0,splitLineCount:0,splitLineStart:0,unifiedLineCount:0,unifiedLineStart:0,additionCount:y.additionCount,additionStart:x,additionLines:v,deletionCount:y.deletionCount,deletionStart:C,deletionLines:g,deletionLineIndex:c,additionLineIndex:u,hunkContent:[],hunkContext:As(y.hunkContext),hunkSpecs:Z(m),noEOFCRAdditions:!1,noEOFCRDeletions:!1},w=0,T=0;for(let L=1;L<f.length;L++){let I=f[L];if(w>=k.additionCount&&T>=k.deletionCount&&!I.startsWith("\\")){if(o&&ou(I)&&!su(I))throw Error("parsePatchContent: hunk has more lines than expected");break}let O=I[0];if(O!=="+"&&O!=="-"&&O!==" "&&O!=="\\"){if(o)throw Error("parsePatchContent: invalid hunk line");console.error(`parseLineType: Invalid firstChar: "${O}", full line: "${I}"`),console.error("processFile: invalid rawLine:",I);continue}let A=du(O);if(A==="addition"){if(o&&w>=k.additionCount)throw Error("parsePatchContent: hunk has too many addition lines");let R=Gr(I);if(S==null||S.type!=="change")S=Wr("change",c,u),k.hunkContent.push(S);if(u++,w++,d)l.additionLines.push(R);S.additions++,v++,b="addition"}else if(A==="deletion"){if(o&&T>=k.deletionCount)throw Error("parsePatchContent: hunk has too many deletion lines");let R=Gr(I);if(S==null||S.type!=="change")S=Wr("change",c,u),k.hunkContent.push(S);if(c++,T++,d)l.deletionLines.push(R);S.deletions++,g++,b="deletion"}else if(A==="context"){if(o&&(T>=k.deletionCount||w>=k.additionCount))throw Error("parsePatchContent: hunk has too many context lines");let R=Gr(I);if(S==null||S.type!=="context")S=Wr("context",c,u),k.hunkContent.push(S);if(u++,c++,w++,T++,d)l.deletionLines.push(R),l.additionLines.push(R);S.lines++,b="context"}else if(A==="metadata"&&S!=null){if(S.type==="context")k.noEOFCRAdditions=!0,k.noEOFCRDeletions=!0;else if(b==="deletion")k.noEOFCRDeletions=!0;else if(b==="addition")k.noEOFCRAdditions=!0;if(d&&(b==="addition"||b==="context")){let R=l.additionLines.length-1;if(R>=0)l.additionLines[R]=ke(l.additionLines[R])}if(d&&(b==="deletion"||b==="context")){let R=l.deletionLines.length-1;if(R>=0)l.deletionLines[R]=ke(l.deletionLines[R])}}}if(o&&(w!==k.additionCount||T!==k.deletionCount))throw Error("parsePatchContent: hunk line count mismatch");k.additionLines=v,k.deletionLines=g,k.collapsedBefore=Math.max(se(k.additionStart,k.additionCount)-s,0),l.hunks.push(k),s=ee(k.additionStart,k.additionCount);for(let L of k.hunkContent)if(L.type==="context")k.splitLineCount+=L.lines,k.unifiedLineCount+=L.lines;else k.splitLineCount+=Math.max(L.additions,L.deletions),k.unifiedLineCount+=L.deletions+L.additions;k.splitLineStart=l.splitLineCount+k.collapsedBefore,k.unifiedLineStart=l.unifiedLineCount+k.collapsedBefore,l.splitLineCount+=k.collapsedBefore+k.splitLineCount,l.unifiedLineCount+=k.collapsedBefore+k.unifiedLineCount}if(l==null)return;if(o&&d&&!n&&l.hunks.length===0)throw Error("parsePatchContent: unified file has no hunks");if(l.hunks.length>0&&!d&&l.additionLines.length>0&&l.deletionLines.length>0){let h=l.hunks[l.hunks.length-1],f=ee(h.additionStart,h.additionCount),m=l.additionLines.length,y=Math.max(m-f,0);l.splitLineCount+=y,l.unifiedLineCount+=y}if(!n){if(l.prevName!=null&&l.name!==l.prevName)if(l.hunks.length>0)l.type="rename-changed";else l.type="rename-pure";else if((i==null||i.contents==="")&&r!=null&&r.contents!=="")l.type="new";else if(i!=null&&i.contents!==""&&(r==null||r.contents===""))l.type="deleted"}if(l.type!=="rename-pure"&&l.type!=="rename-changed")l.prevName=void 0;return ws(l),l}function eu(e,t,n=!1){let i=[],r=tu(e)?e.split(Rs):[e];for(let o of r)try{i.push(Ns(o,t!=null?`${t}-${i.length}`:void 0,n))}catch(s){if(n)throw s;else console.error(s)}return i}function tu(e){return e.startsWith("From ")||e.includes(`
|
|
4
4
|
From `)}function Ls(e){let t=Fs(e);for(let n=0;n<t.length;n++)t[n]=Z(t[n]);return t}function Fs(e){if(e.length===0)return[""];let t=[],n=0;for(;;){let i=e.indexOf(`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{A as vs,a as sd,b as zr,c as $s,d as Us,e as qr,f as Js,g as Ks,h as Gs,i as Ji,l as Zs,m as ea,n as to,o as no,p as ro,q as Kr,r as ta,s as Nu,t as na,u as io,v as ir,w as ra,x as ad,y as ld,z as Cr}from"./main-wcnadmhs.js";import{O as Qi,ka as Ur,la as Zi,ma as eo}from"./main-7fchxg57.js";import{Pb as B,Qb as hs,Rb as Ci,Sb as xr,Tb as Sr,Ub as xu,Vb as en}from"./main-61mzprk0.js";import{cc as Sh,dc as Ih,fc as fm}from"./main-x61973bh.js";var Xs=Ih(function(Wr,Ys){(function(e,t){typeof Wr=="object"&&typeof Ys<"u"?t(Wr):typeof define=="function"&&define.amd?define(["exports"],t):t((e=e||self).lru_map=e.lru_map||{})})(Wr,function(e){let t=Symbol("newer"),n=Symbol("older");class r{constructor(l,c){typeof l!=="number"&&(c=l,l=0),this.size=0,this.limit=l,this.oldest=this.newest=void 0,this._keymap=new Map,c&&(this.assign(c),l<1&&(this.limit=this.size))}_markEntryAsUsed(l){if(l===this.newest)return;l[t]&&(l===this.oldest&&(this.oldest=l[t]),l[t][n]=l[n]),l[n]&&(l[n][t]=l[t]),l[t]=void 0,l[n]=this.newest,this.newest&&(this.newest[t]=l),this.newest=l}assign(l){let c,d=this.limit||Number.MAX_VALUE;this._keymap.clear();let f=l[Symbol.iterator]();for(let u=f.next();!u.done;u=f.next()){let m=new i(u.value[0],u.value[1]);if(this._keymap.set(m.key,m),c?(c[t]=m,m[n]=c):this.oldest=m,c=m,d--==0)throw Error("overflow")}this.newest=c,this.size=this._keymap.size}get(l){var c=this._keymap.get(l);return c?(this._markEntryAsUsed(c),c.value):void 0}set(l,c){var d=this._keymap.get(l);return d?(d.value=c,this._markEntryAsUsed(d),this):(this._keymap.set(l,d=new i(l,c)),this.newest?(this.newest[t]=d,d[n]=this.newest):this.oldest=d,this.newest=d,++this.size,this.size>this.limit&&this.shift(),this)}shift(){var l=this.oldest;if(l)return this.oldest[t]?(this.oldest=this.oldest[t],this.oldest[n]=void 0):(this.oldest=void 0,this.newest=void 0),l[t]=l[n]=void 0,this._keymap.delete(l.key),--this.size,[l.key,l.value]}find(l){let c=this._keymap.get(l);return c?c.value:void 0}has(l){return this._keymap.has(l)}delete(l){var c=this._keymap.get(l);return c?(this._keymap.delete(c.key),c[t]&&c[n]?(c[n][t]=c[t],c[t][n]=c[n]):c[t]?(c[t][n]=void 0,this.oldest=c[t]):c[n]?(c[n][t]=void 0,this.newest=c[n]):this.oldest=this.newest=void 0,this.size--,c.value):void 0}clear(){this.oldest=this.newest=void 0,this.size=0,this._keymap.clear()}keys(){return new s(this.oldest)}values(){return new a(this.oldest)}entries(){return this}[Symbol.iterator](){return new o(this.oldest)}forEach(l,c){typeof c!=="object"&&(c=this);let d=this.oldest;for(;d;)l.call(c,d.value,d.key,this),d=d[t]}toJSON(){for(var l=Array(this.size),c=0,d=this.oldest;d;)l[c++]={key:d.key,value:d.value},d=d[t];return l}toString(){for(var l="",c=this.oldest;c;)l+=String(c.key)+":"+c.value,c=c[t],c&&(l+=" < ");return l}}e.LRUMap=r;function i(l,c){this.key=l,this.value=c,this[t]=void 0,this[n]=void 0}function o(l){this.entry=l}o.prototype[Symbol.iterator]=function(){return this},o.prototype.next=function(){let l=this.entry;return l?(this.entry=l[t],{done:!1,value:[l.key,l.value]}):{done:!0,value:void 0}};function s(l){this.entry=l}s.prototype[Symbol.iterator]=function(){return this},s.prototype.next=function(){let l=this.entry;return l?(this.entry=l[t],{done:!1,value:l.key}):{done:!0,value:void 0}};function a(l){this.entry=l}a.prototype[Symbol.iterator]=function(){return this},a.prototype.next=function(){let l=this.entry;return l?(this.entry=l[t],{done:!1,value:l.value}):{done:!0,value:void 0}}})});function ji(e){let t=[];for(let n of e){let r=zr.get(n);if(r==null)throw Error(`getResolvedLanguages: ${n} is not resolved. Please resolve languages before calling getResolvedLanguages`);t.push(r)}return t}function $i(e){for(let t of Array.isArray(e)?e:[e])if(!zr.has(t))return!1;return!0}async function Ui(e){let t=[],n=[];for(let r of e){if(r==="text"||r==="ansi")continue;let i=Us(r)??$s(r);if("then"in i)n.push(i);else t.push(i)}if(n.length>0)await Promise.all(n).then((r)=>{for(let i of r){if(i==null)throw Error("resolvedLanguages: unable to resolve language");t.push(i)}});return t}function Ki(e){return qr.getResolvedThemes(e)}async function Gi(e){for(let n of e)Ks(n);let t=await qr.resolveThemes(e);for(let n=0;n<e.length;n++)Gs(e[n],t[n]);return t}var oo=Sh(Xs(),1),jr=Symbol("IGNORE_RESPONSE"),$r=class extends Error{constructor(){super("WorkerPoolManager: operation canceled because the pool terminated")}},Yi=class extends Error{constructor(){super("WorkerPoolManager: operation canceled before the task completed")}},ia=class{options;highlighter;preferredHighlighter;renderOptions;renderOptionsRequestVersion=0;renderOptionsVersion=0;initialized=!1;workers=[];queuedTasks=[];queuedTaskByInstance=new Map;taskByHighlightKey=new Map;activeTaskById=new Map;activeRequestByInstance=new Map;nextRequestId=0;themeSubscribers=new Set;workersFailed=!1;statSubscribers=new Set;fileCache;diffCache;_queuedBroadcast;lifecycleGeneration=0;constructor(e,{langs:t,theme:n=Qi,useTokenTransformer:r=!1,lineDiffType:i="word-alt",maxLineDiffLength:o=1000,tokenizeMaxLineLength:s=1000,preferredHighlighter:a="shiki-js"}){this.options=e,this.preferredHighlighter=a,this.renderOptions={theme:n,useTokenTransformer:r,lineDiffType:i,maxLineDiffLength:o,tokenizeMaxLineLength:s},this.fileCache=new oo.default.LRUMap(e.totalASTLRUCacheSize??100),this.diffCache=new oo.default.LRUMap(e.totalASTLRUCacheSize??100),this.queueInitialization(t)}isWorkingPool(){return!this.workersFailed}getFileResultCache(e){return e.cacheKey!=null?this.fileCache.get(e.cacheKey):void 0}getDiffResultCache(e){return e.cacheKey!=null?this.diffCache.get(e.cacheKey):void 0}inspectCaches(){let{fileCache:e,diffCache:t}=this;return{fileCache:e,diffCache:t}}evictFileFromCache(e){try{return this.fileCache.delete(e)!==void 0}finally{this.queueBroadcastStateChanges()}}evictDiffFromCache(e){try{return this.diffCache.delete(e)!==void 0}finally{this.queueBroadcastStateChanges()}}async setRenderOptions({theme:e=this.renderOptions.theme??Qi,useTokenTransformer:t=this.renderOptions.useTokenTransformer??!1,lineDiffType:n=this.renderOptions.lineDiffType??"word-alt",maxLineDiffLength:r=this.renderOptions.maxLineDiffLength??1000,tokenizeMaxLineLength:i=this.renderOptions.tokenizeMaxLineLength??1000}){let{lifecycleGeneration:o}=this,s=++this.renderOptionsRequestVersion,a=()=>this.isCurrentLifecycle(o)&&this.renderOptionsRequestVersion===s;try{let l={theme:e,useTokenTransformer:t,lineDiffType:n,maxLineDiffLength:r,tokenizeMaxLineLength:i};if(!this.isInitialized())await this.initialize();if(!a()||ir(l,this.renderOptions))return;let c=no(e),d=[];if(!Zs(l.theme,this.renderOptions.theme))if(ro(c))d=Ki(c);else d=await Gi(c);if(!a())return;if(this.highlighter!=null)Js(d,this.highlighter);else{let u=await Ji({themes:c,langs:["text"],preferredHighlighter:this.preferredHighlighter});if(!a())return;this.highlighter=u}let f=this.setRenderOptionsOnWorkers(l,d);this.renderOptions=l,this.renderOptionsVersion++,this.diffCache.clear(),this.fileCache.clear(),this.invalidateRenderTasks();for(let u of this.themeSubscribers)u.onThemeChange();await f}catch(l){if(l instanceof $r||!a())return;throw l}}getPreferredHighlighter(){return this.preferredHighlighter}getFileRenderOptions(){let{tokenizeMaxLineLength:e,theme:t,useTokenTransformer:n}=this.renderOptions;return{theme:t,useTokenTransformer:n,tokenizeMaxLineLength:e}}getDiffRenderOptions(){return{...this.renderOptions}}async setRenderOptionsOnWorkers(e,t){if(this.workersFailed)return;if(!this.isInitialized())await this.initialize();let n=[];for(let r of this.workers){if(!r.initialized)throw console.log({managedWorker:r}),Error("setRenderOptionsOnWorkers: Somehow we have an uninitialized worker");n.push(new Promise((i,o)=>{let s=this.generateRequestId(),a={type:"set-render-options",id:s,request:{type:"set-render-options",id:s,renderOptions:e,resolvedThemes:t},resolve:i,reject:o,requestStart:Date.now()};this.activeTaskById.set(s,a),r.pendingSetupRequestId=s,r.worker.postMessage(a.request)}))}await Promise.all(n)}subscribeToThemeChanges(e){return this.themeSubscribers.add(e),this.queueBroadcastStateChanges(),()=>{this.unsubscribeToThemeChanges(e),this.queueBroadcastStateChanges()}}unsubscribeToThemeChanges(e){this.themeSubscribers.delete(e),this.queueBroadcastStateChanges()}subscribeToStatChanges(e){return this.statSubscribers.add(e),e(this.getStats()),()=>{this.statSubscribers.delete(e)}}queueBroadcastStateChanges(){if(this._queuedBroadcast!=null)return;this._queuedBroadcast=requestAnimationFrame(this._broadcastStateChanges)}_broadcastStateChanges=()=>{if(this._queuedBroadcast!=null)cancelAnimationFrame(this._queuedBroadcast),this._queuedBroadcast=void 0;let e=this.getStats();for(let t of this.statSubscribers)t(e)};cleanUpTasks(e){this.detachInstanceFromQueuedTasks(e);let t=this.activeRequestByInstance.get(e);if(t!=null){let n=this.activeTaskById.get(t);if(Rt(n)){if(this.detachInstanceFromRenderTask(n,e),!n.primeCache&&n.instances.size===0)this.removeActiveTask(n)}else this.activeTaskById.delete(t)}this.activeRequestByInstance.delete(e),this.queueBroadcastStateChanges()}isInitialized(){return this.initialized===!0}async initialize(e=[]){if(this.initialized===!0)return;else if(this.initialized===!1){let{lifecycleGeneration:t}=this;this.initialized=new Promise((n,r)=>{(async()=>{try{let i=no(this.renderOptions.theme),o=[];if(ro(i))o=Ki(i);else o=await Gi(i);if(!this.isCurrentLifecycle(t)){n();return}let s=[];if($i(e))s=ji(e);else s=await Ui(e);if(!this.isCurrentLifecycle(t)){n();return}let[a]=await Promise.all([Ji({themes:i,langs:["text",...e],preferredHighlighter:this.preferredHighlighter}),this.initializeWorkers(o,s)]);if(!this.isCurrentLifecycle(t)){this.terminateWorkers(),n();return}this.highlighter=a,this.initialized=!0,this.diffCache.clear(),this.fileCache.clear(),this.drainQueue(),this.queueBroadcastStateChanges(),n()}catch(i){if(i instanceof $r||!this.isCurrentLifecycle(t)){n();return}this.initialized=!1,this.workersFailed=!0;for(let o of this.queuedTasks)this.rejectRenderTaskCallbacks(o,Xi(i));this.queueBroadcastStateChanges(),r(i)}})()}),this.queueBroadcastStateChanges()}else return this.initialized}async initializeWorkers(e,t){this.workersFailed=!1;let n=[],r=Zi(),i=r>0?eo():void 0;if(this.workers.length>0)this.terminateWorkers();for(let o=0;o<(this.options.poolSize??8);o++){let s=this.options.workerFactory(),a={worker:s,requestId:void 0,pendingSetupRequestId:void 0,initialized:!1,langs:new Set(["text",...t.map(({name:l})=>l)]),customExtensionsVersion:0};s.addEventListener("message",(l)=>{this.handleWorkerMessage(a,l.data)}),s.addEventListener("error",(l)=>console.error("Worker error:",l,a)),this.workers.push(a),n.push(new Promise((l,c)=>{let d=this.generateRequestId(),f={type:"initialize",id:d,request:{type:"initialize",id:d,renderOptions:this.renderOptions,preferredHighlighter:this.preferredHighlighter,resolvedThemes:e,resolvedLanguages:t,customExtensionsVersion:i!=null?r:void 0,customExtensionMap:i},resolve(){a.initialized=!0,l()},reject:c,requestStart:Date.now()};this.activeTaskById.set(d,f),this.executeTask(a,f)}))}await Promise.all(n)}drainQueue=()=>{if(this._queuedDrain=void 0,this.initialized!==!0||this.queuedTasks.length===0)return;for(let e=0;e<this.queuedTasks.length;){let t=this.queuedTasks[e];if(this.hasActiveRequest(t)){e++;continue}let n=Qs(t),r=this.getAvailableWorker(n);if(r==null)break;this.queuedTasks.splice(e,1),this.assignWorkerToTask(t,r),this.resolveLanguagesAndExecuteTask(r,t,n)}this.queueBroadcastStateChanges()};highlightFileAST(e,t){let n=this.getFileResultCache(t);if(to(t)||n!=null&&Kr(n.options,this.getFileRenderOptions()))return;if(!this.hasMatchingFileInstanceTask(e,t))this.submitTask(e,{type:"file",file:t})}primeFileHighlightCache(e){if(!this.isWorkingPool())return Promise.reject(Error("WorkerPoolManager.primeFileHighlightCache: worker pool is not working"));let t=this.getOrCreateFileHighlightCacheTask(e);return t!=null?this.createRenderTaskCallbacks(t):Promise.resolve()}getOrCreateFileHighlightCacheTask(e){if(e.cacheKey==null){console.warn(`WorkerPoolManager.primeFileHighlightCache: priming highlight cache requires file.cacheKey; skipping "${e.name}".`);return}let t=this.getFileResultCache(e),n=this.getFileHighlightKey(e);if(n==null||to(e)||t!=null&&Kr(t.options,this.getFileRenderOptions()))return;let r=this.getTaskByHighlightKey(n);if(r!=null)return r.primeCache=!0,r.type==="file"?r:void 0;else{let i=this.submitCacheTask({type:"file",file:e},n);return i.type==="file"?i:void 0}}getPlainFileAST(e,t,n,r){if(this.highlighter==null){this.queueInitialization();return}return ta(e,this.highlighter,this.renderOptions,{forcePlainText:!0,startingLine:t,totalLines:n,lines:r})}highlightDiffAST(e,t){let n=this.getDiffResultCache(t);if(io(t)||n!=null&&ir(n.options,this.getDiffRenderOptions()))return;if(!this.hasMatchingDiffInstanceTask(e,t))this.submitTask(e,{type:"diff",diff:t})}primeDiffHighlightCache(e){if(!this.isWorkingPool())return Promise.reject(Error("WorkerPoolManager.primeDiffHighlightCache: worker pool is not working"));let t=this.getOrCreateDiffHighlightCacheTask(e);return t!=null?this.createRenderTaskCallbacks(t):Promise.resolve()}getOrCreateDiffHighlightCacheTask(e){if(e.cacheKey==null){console.warn(`WorkerPoolManager.primeDiffHighlightCache: priming highlight cache requires diff.cacheKey; skipping "${e.prevName??e.name}" -> "${e.name}".`);return}let t=this.getDiffResultCache(e),n=this.getDiffHighlightKey(e);if(n==null||io(e)||t!=null&&ir(t.options,this.getDiffRenderOptions()))return;let r=this.getTaskByHighlightKey(n);if(r!=null)return r.primeCache=!0,r.type==="diff"?r:void 0;else{let i=this.submitCacheTask({type:"diff",diff:e},n);return i.type==="diff"?i:void 0}}getPlainDiffAST(e,t,n,r,i){return this.highlighter!=null?ra(e,this.highlighter,this.renderOptions,{forcePlainText:!0,startingLine:t,totalLines:n,expandedHunks:r,collapsedContextThreshold:i}):void 0}terminate(){this.lifecycleGeneration++,this.cancelActiveWorkerTasks(),this.terminateWorkers();let e=new $r;for(let t of this.queuedTasks)this.rejectRenderTaskCallbacks(t,e);this.fileCache.clear(),this.diffCache.clear(),this.activeRequestByInstance.clear(),this.queuedTasks.length=0,this.queuedTaskByInstance.clear(),this.taskByHighlightKey.clear(),this.activeTaskById.clear(),this.highlighter=void 0,this.initialized=!1,this.workersFailed=!1,this.queueBroadcastStateChanges()}isCurrentLifecycle(e){return this.lifecycleGeneration===e}queueInitialization(e){this.initialize(e).catch((t)=>{console.error(t)})}cancelActiveWorkerTasks(){let e=new $r;for(let t of this.activeTaskById.values())if("reject"in t)t.reject(e);else if(Rt(t))this.rejectRenderTaskCallbacks(t,e)}terminateWorkers(){for(let e of this.workers)e.worker.terminate();this.workers.length=0}getStats(){return{managerState:(()=>{if(this.initialized===!1)return"waiting";if(this.initialized!==!0)return"initializing";return"initialized"})(),totalWorkers:this.workers.length,workersFailed:this.workersFailed,busyWorkers:this.workers.filter((e)=>e.requestId!=null||e.pendingSetupRequestId!=null).length,queuedTasks:this.queuedTasks.length,activeTasks:this.activeTaskById.size,themeSubscribers:this.themeSubscribers.size,fileCacheSize:this.fileCache.size,diffCacheSize:this.diffCache.size}}submitTask(e,t){if(this.initialized===!1)this.queueInitialization();let n=this.getHighlightKeyForRequest(t),r=n!=null?this.getTaskByHighlightKey(n):void 0;if(r!=null){this.detachInstanceFromQueuedTasks(e,r),this.addInstanceToTask(r,e),this.queueBroadcastStateChanges();return}this.detachInstanceFromQueuedTasks(e);let i=this.generateRequestId(),o=Date.now(),{renderOptionsVersion:s}=this,a=(()=>{switch(t.type){case"file":return{type:"file",id:i,request:{...t,id:i},instances:new Set([e]),primeCache:!1,highlightKey:n,callbacks:new Set,renderOptionsVersion:s,requestStart:o};case"diff":return{type:"diff",id:i,request:{...t,id:i},instances:new Set([e]),primeCache:!1,highlightKey:n,callbacks:new Set,renderOptionsVersion:s,requestStart:o}}})();this.enqueueRenderTask(a,e)}submitCacheTask(e,t){if(this.initialized===!1)this.queueInitialization();let n=this.generateRequestId(),r=Date.now(),{renderOptionsVersion:i}=this,o=(()=>{switch(e.type){case"file":return{type:"file",id:n,request:{...e,id:n},instances:new Set,primeCache:!0,highlightKey:t,callbacks:new Set,renderOptionsVersion:i,requestStart:r};case"diff":return{type:"diff",id:n,request:{...e,id:n},instances:new Set,primeCache:!0,highlightKey:t,callbacks:new Set,renderOptionsVersion:i,requestStart:r}}})();return this.enqueueRenderTask(o),o}enqueueRenderTask(e,t){if(this.queuedTasks.push(e),t!=null)this.queuedTaskByInstance.set(t,e);if(e.highlightKey!=null)this.taskByHighlightKey.set(e.highlightKey,e);this.queueDrain()}async resolveLanguagesAndExecuteTask(e,t,n){try{let r=n.filter((i)=>!e.langs.has(i));if(r.length>0)if($i(r))t.request.resolvedLanguages=ji(r);else t.request.resolvedLanguages=await Ui(r);if(!this.activeTaskById.has(t.id)){if(e.requestId===t.id){if(this.cleanWorkerAndTask(e,t),this.queueBroadcastStateChanges(),this.queuedTasks.length>0)this.queueDrain()}return}this.executeTask(e,t)}catch(r){if(this.rejectRenderTaskCallbacks(t,Xi(r)),this.cleanWorkerAndTask(e,t),this.queueBroadcastStateChanges(),this.queuedTasks.length>0)this.queueDrain()}}handleWorkerMessage(e,t){let n=this.activeTaskById.get(t.id);try{if(n==null)throw jr;else if(t.type==="error"){let r=Error(t.error);if(t.stack)r.stack=t.stack;if("reject"in n)n.reject(r);else if(Rt(n))this.notifyHighlightError(n,r),this.rejectRenderTaskCallbacks(n,r);else throw Error("handleWorkerMessage: unknown task type");throw r}else switch(t.requestType){case"initialize":if(n.type!=="initialize")throw Error("handleWorkerMessage: task/response dont match");this.syncCustomExtensionVersion(e,n.request),n.resolve();break;case"set-render-options":if(n.type!=="set-render-options")throw Error("handleWorkerMessage: task/response dont match");n.resolve();break;case"file":{if(n.type!=="file")throw Error("handleWorkerMessage: task/response dont match");let{result:r,options:i}=t;if(!this.isCurrentRenderTask(n)||!Kr(i,this.getFileRenderOptions()))throw jr;let{request:o}=n;if(this.syncCustomExtensionVersion(e,o),n.cacheKeyAtDispatch!=null)this.fileCache.set(n.cacheKeyAtDispatch,{result:r,options:i});this.resolveRenderTaskCallbacks(n),this.notifyFileInstances(n,r,i);break}case"diff":{if(n.type!=="diff")throw Error("handleWorkerMessage: task/response dont match");let{result:r,options:i}=t;if(!this.isCurrentRenderTask(n)||!ir(i,this.getDiffRenderOptions()))throw jr;let{request:o}=n;if(this.syncCustomExtensionVersion(e,o),n.cacheKeyAtDispatch!=null)this.diffCache.set(n.cacheKeyAtDispatch,{result:r,options:i});this.resolveRenderTaskCallbacks(n),this.notifyDiffInstances(n,r,i);break}}}catch(r){if(r!==jr)console.error(r,n,t)}if(this.cleanWorkerAndTask(e,n,t.id),this.queueBroadcastStateChanges(),this.queuedTasks.length>0)this.queueDrain()}_queuedDrain;queueDrain(){if(this._queuedDrain!=null)return;this._queuedDrain=Promise.resolve().then(this.drainQueue),this.queueBroadcastStateChanges()}assignWorkerToTask(e,t){if(t.requestId=e.id,Rt(e))this.clearQueuedInstanceRequests(e),this.trackInstanceRequests(e);this.activeTaskById.set(e.id,e)}cleanWorkerAndTask(e,t,n=t?.id){if(e.requestId===n)e.requestId=void 0;if(e.pendingSetupRequestId===n)e.pendingSetupRequestId=void 0;if(t!=null){if(Rt(t))this.rejectRenderTaskCallbacks(t,new Yi),this.clearInstanceRequests(t),this.clearHighlightKey(t);this.activeTaskById.delete(t.id)}}executeTask(e,t){if(Ch(t.request))this.maybeAttachCustomExtensions(e,t.request);if(!this.activeTaskById.has(t.id))this.assignWorkerToTask(t,e);for(let n of Qs(t))e.langs.add(n);try{if(t.type==="file")t.cacheKeyAtDispatch=t.request.file.cacheKey;else if(t.type==="diff")t.cacheKeyAtDispatch=t.request.diff.cacheKey;e.worker.postMessage(t.request)}catch(n){if(console.error("Failed to post message to worker:",n),Rt(t))this.notifyHighlightError(t,n),this.rejectRenderTaskCallbacks(t,Xi(n));else if("reject"in t)t.reject(n);if(this.cleanWorkerAndTask(e,t),this.queuedTasks.length>0)this.queueDrain()}this.queueBroadcastStateChanges()}maybeAttachCustomExtensions(e,t){if(t.customExtensionsVersion!=null)return;let n=Zi();if(e.customExtensionsVersion>=n)return;t.customExtensionsVersion=n,t.customExtensionMap=eo()}syncCustomExtensionVersion(e,t){if(t.customExtensionsVersion==null)return;e.customExtensionsVersion=t.customExtensionsVersion}getAvailableWorker(e){let t;for(let n of this.workers){if(n.requestId!=null||n.pendingSetupRequestId!=null||!n.initialized)continue;if(t=n,e.length===0)break;let r=!0;for(let i of e)if(!n.langs.has(i)){r=!1;break}if(r)break}return t}getFileHighlightKey(e){if(e.cacheKey==null)return;return`file:${e.cacheKey}:${this.renderOptionsVersion}`}getDiffHighlightKey(e){if(e.cacheKey==null)return;return`diff:${e.cacheKey}:${this.renderOptionsVersion}`}getHighlightKeyForRequest(e){switch(e.type){case"file":return this.getFileHighlightKey(e.file);case"diff":return this.getDiffHighlightKey(e.diff)}}hasActiveRequest(e){for(let t of rr(e))if(this.activeRequestByInstance.has(t))return!0;return!1}addInstanceToTask(e,t){if(e.type==="file")e.instances.add(t);else e.instances.add(t);if(this.activeTaskById.has(e.id))this.activeRequestByInstance.set(t,e.id);else this.queuedTaskByInstance.set(t,e)}detachInstanceFromQueuedTasks(e,t){let n=this.queuedTaskByInstance.get(e);if(n==null||n===t)return;if(this.queuedTaskByInstance.delete(e),this.detachInstanceFromRenderTask(n,e),!n.primeCache&&n.instances.size===0)this.removeQueuedTask(n)}detachInstanceFromRenderTask(e,t){if(e.type==="file")e.instances.delete(t);else e.instances.delete(t)}removeQueuedTask(e){let t=this.queuedTasks.indexOf(e);if(t!==-1)this.queuedTasks.splice(t,1);this.rejectRenderTaskCallbacks(e,new Yi),this.clearQueuedInstanceRequests(e),this.clearHighlightKey(e)}removeActiveTask(e){this.rejectRenderTaskCallbacks(e,new Yi),this.clearInstanceRequests(e),this.clearHighlightKey(e),this.activeTaskById.delete(e.id)}createRenderTaskCallbacks(e){return new Promise((t,n)=>{e.callbacks.add({resolve:t,reject:n})})}resolveRenderTaskCallbacks(e){for(let t of e.callbacks)t.resolve();e.callbacks.clear()}rejectRenderTaskCallbacks(e,t){for(let n of e.callbacks)n.reject(t);e.callbacks.clear()}invalidateRenderTasks(){for(let e=this.queuedTasks.length-1;e>=0;e--){let t=this.queuedTasks[e];if(t.renderOptionsVersion!==this.renderOptionsVersion)this.removeQueuedTask(t)}for(let e of Array.from(this.activeTaskById.values()))if(Rt(e)&&e.renderOptionsVersion!==this.renderOptionsVersion)this.removeActiveTask(e)}clearQueuedInstanceRequests(e){for(let t of rr(e))if(this.queuedTaskByInstance.get(t)===e)this.queuedTaskByInstance.delete(t)}clearHighlightKey(e){if(e.highlightKey!=null&&this.taskByHighlightKey.get(e.highlightKey)===e)this.taskByHighlightKey.delete(e.highlightKey)}trackInstanceRequests(e){for(let t of rr(e))this.activeRequestByInstance.set(t,e.id)}clearInstanceRequests(e){for(let t of rr(e))if(this.activeRequestByInstance.get(t)===e.id)this.activeRequestByInstance.delete(t)}notifyFileInstances(e,t,n){for(let r of e.instances)if(this.activeRequestByInstance.get(r)===e.id)r.onHighlightSuccess(e.request.file,t,n)}notifyDiffInstances(e,t,n){for(let r of e.instances)if(this.activeRequestByInstance.get(r)===e.id)r.onHighlightSuccess(e.request.diff,t,n)}notifyHighlightError(e,t){for(let n of rr(e))if(this.activeRequestByInstance.get(n)===e.id)n.onHighlightError(t)}hasMatchingFileInstanceTask(e,t){for(let n of this.iterateRenderTasks())if(n.type==="file"&&this.isCurrentRenderTask(n)&&n.instances.has(e)&&ea(t,n.request.file))return!0;return!1}hasMatchingDiffInstanceTask(e,t){for(let n of this.iterateRenderTasks())if(n.type==="diff"&&this.isCurrentRenderTask(n)&&n.instances.has(e)&&na(n.request.diff,t))return!0;return!1}getTaskByHighlightKey(e){let t=this.taskByHighlightKey.get(e);return t!=null&&this.isCurrentRenderTask(t)?t:void 0}isCurrentRenderTask(e){return e.renderOptionsVersion===this.renderOptionsVersion}*iterateRenderTasks(){for(let e of this.queuedTasks)yield e;for(let e of this.activeTaskById.values())if(Rt(e))yield e}generateRequestId(){return`req_${++this.nextRequestId}`}};function Ch(e){return e.type==="initialize"||e.type==="file"||e.type==="diff"}function Qs(e){let t=new Set;if(e.type==="initialize"||e.type==="set-render-options")return[];switch(e.type){case"file":t.add(e.request.file.lang??Ur(e.request.file.name));break;case"diff":t.add(e.request.diff.lang??Ur(e.request.diff.name)),t.add(e.request.diff.lang??Ur(e.request.diff.prevName??"-"));break}return t.delete("text"),Array.from(t)}function Rt(e){return e?.type==="file"||e?.type==="diff"}function rr(e){return e.instances}function Xi(e){return e instanceof Error?e:Error(String(e))}var or;function so({poolOptions:e,highlighterOptions:t}){return or??=new ia(e,t),or}function ao(){if(or==null)return;or.terminate(),or=void 0}function Gt(){return{childIdByNameId:new Map,childIds:[],childPositionById:new Map,childVisibleChunkSums:null,totalChildSubtreeNodeCount:0,totalChildVisibleSubtreeCount:0}}function lo(){return{childIdByNameId:null,childIds:[],childPositionById:null,childVisibleChunkSums:null,totalChildSubtreeNodeCount:0,totalChildVisibleSubtreeCount:0}}function Dt(e,t){if(t.childIdByNameId!=null)return t.childIdByNameId;let n=new Map;for(let r of t.childIds){let i=e[r];if(i!=null)n.set(i.nameId,r)}return t.childIdByNameId=n,n}function mn(e){if(e.childPositionById!=null)return e.childPositionById;let t=new Map;for(let n=0;n<e.childIds.length;n++){let r=e.childIds[n];if(r!=null)t.set(r,n)}return e.childPositionById=t,t}function gn(e,t){if(e.childPositionById!=null)e.childPositionById.set(t,e.childIds.length);e.childIds.push(t)}function co(e,t){if(e.childPositionById==null)return;for(let n=t;n<e.childIds.length;n++){let r=e.childIds[n];if(r!=null)e.childPositionById.set(r,n)}}function Yt(e,t){let n=0,r=0;for(let i of t.childIds){let o=e[i];if(o==null)continue;n+=o.subtreeNodeCount,r+=o.visibleSubtreeCount}t.totalChildSubtreeNodeCount=n,t.totalChildVisibleSubtreeCount=r,Mt(e,t)}function Gr(e,t,n,r){if(e.totalChildSubtreeNodeCount+=n,e.totalChildVisibleSubtreeCount+=r,e.childVisibleChunkSums==null||r===0)return;let i=mn(e).get(t);if(i===void 0)return;let o=i>>5;e.childVisibleChunkSums[o]+=r}function Yr(e,t,n){let r=t.childVisibleChunkSums;if(r!=null){let o=n,s=0;for(let a of r){if(o<a){let l=xh(e,t,s,o);return{...l,childVisibleIndex:n-l.localVisibleIndex}}o-=a,s+=32}throw Error(`Visible child index ${String(n)} is out of range`)}let i=n;for(let o=0;o<t.childIds.length;o++){let s=t.childIds[o];if(s==null)continue;let a=e[s];if(a==null)continue;if(i<a.visibleSubtreeCount)return{childIndex:o,childVisibleIndex:n-i,localVisibleIndex:i};i-=a.visibleSubtreeCount}throw Error(`Visible child index ${String(n)} is out of range`)}function oa(e,t,n){let r=0,i=t.childVisibleChunkSums,o=0;if(i!=null){let s=n>>5;for(let a=0;a<s;a+=1)r+=i[a]??0;o=s<<5}for(let s=o;s<n;s+=1){let a=t.childIds[s];if(a==null)continue;let l=e[a];if(l==null)continue;r+=l.visibleSubtreeCount}return r}function Mt(e,t){if(t.childIds.length<128){t.childVisibleChunkSums=null;return}let n=Math.ceil(t.childIds.length/32),r=new Int32Array(n);for(let i=0;i<t.childIds.length;i++){let o=t.childIds[i];if(o==null)continue;let s=e[o];if(s==null)continue;r[i>>5]+=s.visibleSubtreeCount}t.childVisibleChunkSums=r}function xh(e,t,n,r){let i=Math.min(t.childIds.length,n+32),o=r;for(let s=n;s<i;s++){let a=t.childIds[s];if(a==null)continue;let l=e[a];if(l==null)continue;if(o<l.visibleSubtreeCount)return{childIndex:s,localVisibleIndex:o};o-=l.visibleSubtreeCount}throw Error(`Visible child index ${String(r)} is out of range`)}function Ae(e,t,n=0){return e<<4|n<<3|t}function Ve(e){return e.depthAndFlags>>>4}function sr(e){return(e.depthAndFlags&8)>>3}function D(e){return(e.depthAndFlags&8)!==0}function sa(e){return e.depthAndFlags&7}function ue(e,t){return(sa(e)&t)!==0}function vn(e,t){e.depthAndFlags|=t}function aa(e,t){e.depthAndFlags=Ae(t,sa(e),sr(e))}var la=Symbol("benchmarkInstrumentation");function ca(e,t){if(t==null)return e;return Object.defineProperty(e,la,{configurable:!0,enumerable:!1,value:t,writable:!1}),e}function ar(e){if(e==null)return null;return e[la]??null}function E(e,t,n){if(e==null)return n();return e.measurePhase(t,n)}function yn(e,t,n){if(!Number.isFinite(n)||e==null)return;e.setCounter(t,n)}function ua(e){return e>=48&&e<=57}function kh(e){let t=[],n=0,r=0;while(r<e.length){while(r<e.length&&!ua(e.charCodeAt(r)))r+=1;if(r>=e.length)break;if(r>n)t.push(e.slice(n,r));let i=0;while(r<e.length&&ua(e.charCodeAt(r)))i=i*10+(e.charCodeAt(r)-48),r+=1;t.push(i),n=r}if(n<e.length||t.length===0)t.push(e.slice(n));return t}function Xt(e){let t=e.toLowerCase();return{lowerValue:t,tokens:kh(t)}}function _h(e,t){let n=Math.min(e.length,t.length);for(let r=0;r<n;r++){let i=e[r],o=t[r];if(i===o)continue;if(typeof i==="number"&&typeof o==="number")return i<o?-1:1;let s=String(i),a=String(o);if(s!==a)return s<a?-1:1}if(e.length!==t.length)return e.length<t.length?-1:1;return 0}function lr(e,t){if(e.tokens.length===1&&t.tokens.length===1&&typeof e.tokens[0]==="string"&&typeof t.tokens[0]==="string"){if(e.lowerValue===t.lowerValue)return 0;return e.lowerValue<t.lowerValue?-1:1}let n=_h(e.tokens,t.tokens);if(n!==0)return n;if(e.lowerValue!==t.lowerValue)return e.lowerValue<t.lowerValue?-1:1;return 0}function da(e,t,n){let r=lr(n(e),n(t));if(r!==0)return r;if(e===t)return 0;return e<t?-1:1}function Eh(e,t){return da(e,t,Xt)}function Xr(e,t){if(t!==e.segments.length-1)return 1;return e.isDirectory?1:0}function Th(e,t){let n=Math.min(e.segments.length,t.segments.length);for(let r=0;r<n;r++){let i=e.segments[r],o=t.segments[r];if(i===o)continue;let s=Xr(e,r);if(s!==Xr(t,r))return s===1?-1:1;return Eh(i,o)}if(e.segments.length!==t.segments.length)return e.segments.length<t.segments.length?-1:1;if(e.isDirectory===t.isDirectory)return 0;return e.isDirectory?-1:1}function ha(e,t){return Th(e,t)}function fa(e,t,n){let r=(o)=>{let s=n.get(o);if(s!=null)return s;let a=Xt(o);return n.set(o,a),a},i=Math.min(e.segments.length,t.segments.length);for(let o=0;o<i;o++){let s=e.segments[o],a=t.segments[o];if(s===a)continue;let l=Xr(e,o);if(l!==Xr(t,o))return l===1?-1:1;return da(s,a,r)}if(e.segments.length!==t.segments.length)return e.segments.length<t.segments.length?-1:1;if(e.isDirectory===t.isDirectory)return 0;return e.isDirectory?-1:1}function cr(e,t){let n=e.sortKeyById[t];if(n!==void 0)return n;let r=e.valueById[t],i=Xt(r);return e.sortKeyById[t]=i,i}function uo(e={}){return{flattenEmptyDirectories:e.flattenEmptyDirectories!==!1,sort:e.sort??"default"}}function pa(e){let t=e.length>0&&e.charCodeAt(e.length-1)===47,n=t?e.length-1:e.length,r=[],i=0;for(let o=0;o<n;o++){if(e.charCodeAt(o)!==47)continue;r.push(e.slice(i,o)),i=o+1}return r.push(e.slice(i,n)),{hasTrailingSlash:t,segments:r}}function Qt(e){let{hasTrailingSlash:t,segments:n}=pa(e);return{basename:n[n.length-1]??"",isDirectory:t,path:e,segments:n}}function Qr(e){if(e.length===0)return{requiresDirectory:!1,segments:[]};let{hasTrailingSlash:t,segments:n}=pa(e);return{requiresDirectory:t,segments:n}}function Jr(){let e=new Map;return e.set("",0),{idByValue:e,valueById:[""],sortKeyById:[Xt("")]}}function rt(e,t){let n=e.idByValue.get(t);if(n!==void 0)return n;let r=e.valueById.length;return e.idByValue.set(t,r),e.valueById.push(t),r}function qe(e,t){let n=e.valueById[t];if(n===void 0)throw Error(`Unknown segment ID: ${String(t)}`);return n}var ho=Symbol("pathStorePreparedInputKind");function va(e,t){return e[ho]=t,e}function ma(e){return{basename:e.basename,depth:e.segments.length,isDirectory:e.isDirectory,path:e.path,segments:e.segments}}function ya(e,t,n){if(n==="default")return ha(e,t);return n(ma(e),ma(t))}function Ph(){return{depthAndFlags:Ae(0,3,1),nameId:0,parentId:0,subtreeNodeCount:1,visibleSubtreeCount:1}}function Rh(e,t){let n=Math.min(e.length,t.length);for(let r=0;r<n;r++)if(e[r]!==t[r])return r;return n}function ga(e){return e.isDirectory?e.segments.length:e.segments.length-1}function Dh(e){return Array.isArray(e)&&e.every((t)=>t!=null&&typeof t==="object"&&typeof t.path==="string"&&Array.isArray(t.segments)&&typeof t.basename==="string"&&typeof t.isDirectory==="boolean")}function Mh(e){return Array.isArray(e)&&e.every((t)=>typeof t==="string")}function ba(e,t={}){return Zr(e,t).map((n)=>n.path)}function wa(e,t={}){let n=Zr(e,t);return va({paths:n.map((r)=>r.path),preparedPaths:n},"prepared")}function Ia(e){let t=e.length,n=!1;for(let r=0;r<t;r+=1){let i=e[r];if(i.length>0&&i.charCodeAt(i.length-1)===47){n=!0;break}}return va({paths:e,presortedPaths:e,presortedPathsContainDirectories:n},"presorted")}function Sa(e){let t=e,n=t.preparedPaths;if(t[ho]==="prepared"&&n!=null)return n;if(!Dh(n))throw Error("preparedInput must come from PathStore.prepareInput()");return n}function Ca(e){let t=e;if(t[ho]==="presorted"&&t.presortedPaths!=null)return t.presortedPaths;return Mh(t.presortedPaths)?t.presortedPaths:null}function xa(e){let t=e;return typeof t.presortedPathsContainDirectories==="boolean"?t.presortedPathsContainDirectories:null}function Zr(e,t={}){let n=uo(t),r=ar(t);yn(r,"workload.inputFiles",e.length);let i=E(r,"store.preparePathEntries.parse",()=>e.map((o)=>Qt(o)));return E(r,"store.preparePathEntries.sort",()=>i.sort((o,s)=>ya(o,s,n.sort))),i}var ei=class{directories=new Map;directoryStack=[0];presortedDirectoryNodeIds=[];initialExpandedPathSet;createdDirectoriesAllExpanded=!1;createdDirectoryCount=0;lastPreparedPath=null;nodes=[Ph()];options;instrumentation;segmentSortKeyCache=new Map;segmentTable=Jr();hasDeferredDirectoryIndexes=!1;constructor(e={}){this.instrumentation=ar(e),this.options=uo(e);let t=e.initialExpandedPaths??null;if(t==null||t.length===0)this.initialExpandedPathSet=null;else{let n=new Set,r=t.length;for(let i=0;i<r;i+=1){let o=t[i],s=o.length;n.add(s>0&&o.charCodeAt(s-1)===47?o.slice(0,s-1):o)}this.initialExpandedPathSet=n,this.createdDirectoriesAllExpanded=!0}this.directories.set(0,Gt())}appendPaths(e){return E(this.instrumentation,"store.builder.appendPaths.parse",()=>this.appendPreparedPaths(e.map((t)=>Qt(t))))}appendPreparedPaths(e,t=!0){return this.createdDirectoriesAllExpanded=!1,E(this.instrumentation,"store.builder.appendPreparedPaths",()=>{for(let n of e)this.appendPreparedPath(n,t)}),this}appendPresortedPaths(e,t=null){return E(this.instrumentation,"store.builder.appendPresortedPaths",()=>{if(t===!1){this.appendPresortedFilePaths(e);return}this.createdDirectoriesAllExpanded=!1;let n=null,r=0,i=this.nodes,o=this.segmentTable,s=o.idByValue,a=o.valueById,l=this.directoryStack,c=0,d="",f=0;for(let u of e){if(n===u)throw Error(`Duplicate path: "${u}"`);let m=u.length>0&&u.charCodeAt(u.length-1)===47,p=m?u.length-1:u.length,g=0,v=0;if(n!=null)if(d.length>0&&u.length>d.length&&u.startsWith(d))g=f,v=d.length;else{let y=Math.min(p,n.length),w=!0;for(let x=0;x<y;x++){let P=u.charCodeAt(x);if(P!==n.charCodeAt(x)){w=!1;break}if(P===47)g++,v=x+1}if(w&&m&&y===p&&n.length>p&&n.charCodeAt(p)===47)g++,v=p+1}c=g,r=g;let S=v,C=u.indexOf("/",S);while(C>=0&&C<p){let y=l[c];if(y===void 0)throw Error("Directory stack underflow while building the path store");r++;let w=u.slice(S,C),x=s.get(w);if(x===void 0)x=a.length,s.set(w,x),a.push(w);let P=i.length;i.push({depthAndFlags:Ae(r,0,1),nameId:x,parentId:y,subtreeNodeCount:1,visibleSubtreeCount:1}),this.recordCreatedDirectoryPath(u.slice(0,C)),c++,l[c]=P,S=C+1,C=u.indexOf("/",S)}if(m){if(S<p){let w=l[c];if(w===void 0)throw Error(`Unable to resolve directory parent for "${u}"`);r++;let x=u.slice(S,p),P=s.get(x);if(P===void 0)P=a.length,s.set(x,P),a.push(x);let O=i.length;i.push({depthAndFlags:Ae(r,0,1),nameId:P,parentId:w,subtreeNodeCount:1,visibleSubtreeCount:1}),c++,l[c]=O,S=p+1}let y=l[c];if(y===void 0)throw Error(`Unable to resolve directory node for "${u}"`);this.promoteDirectoryToExplicit(y,u)}else{let y=l[c];if(y===void 0)throw Error(`Unable to resolve file parent for "${u}"`);let w=u.slice(S),x=s.get(w);if(x===void 0)x=a.length,s.set(w,x),a.push(w);i.push({depthAndFlags:Ae(r+1,0),nameId:x,parentId:y,subtreeNodeCount:1,visibleSubtreeCount:1})}if(S!==d.length)d=u.substring(0,S),f=r;n=u}if(l.length=c+1,n!=null)this.lastPreparedPath=Qt(n);this.hasDeferredDirectoryIndexes=!0}),this}appendPresortedFilePaths(e){let t=null,n=0,r=this.nodes,i=this.segmentTable,o=i.idByValue,s=i.valueById,a=this.directoryStack,l=0,c="",d=0;for(let f of e){if(t===f)throw Error(`Duplicate path: "${f}"`);let u=f.length,m=0,p=0;if(t!=null)if(c.length>0&&f.length>c.length&&f.startsWith(c))m=d,p=c.length;else{let w=Math.min(u,t.length);for(let x=0;x<w;x++){let P=f.charCodeAt(x);if(P!==t.charCodeAt(x))break;if(P===47)m++,p=x+1}}l=m,n=m;let g=p,v=f.indexOf("/",g);while(v>=0){let w=a[l];if(w===void 0)throw Error("Directory stack underflow while building the path store");n++;let x=f.slice(g,v),P=o.get(x);if(P===void 0)P=s.length,o.set(x,P),s.push(x);let O=r.length;r.push({depthAndFlags:Ae(n,0,1),nameId:P,parentId:w,subtreeNodeCount:1,visibleSubtreeCount:1}),this.recordCreatedDirectoryPath(f.slice(0,v)),this.presortedDirectoryNodeIds.push(O),l++,a[l]=O,g=v+1,v=f.indexOf("/",g)}let S=a[l];if(S===void 0)throw Error(`Unable to resolve file parent for "${f}"`);let C=f.slice(g),y=o.get(C);if(y===void 0)y=s.length,o.set(C,y),s.push(C);if(r.push({depthAndFlags:Ae(n+1,0),nameId:y,parentId:S,subtreeNodeCount:1,visibleSubtreeCount:1}),g!==c.length)c=f.substring(0,g),d=n;t=f}if(a.length=l+1,t!=null)this.lastPreparedPath=Qt(t);this.hasDeferredDirectoryIndexes=!0}finish(e={}){let t=e.skipSubtreeCountPass===!0;if(this.hasDeferredDirectoryIndexes)E(this.instrumentation,"store.builder.buildDirectoryIndexes",()=>this.buildPresortedFinish(t)),this.hasDeferredDirectoryIndexes=!1;else if(!t)E(this.instrumentation,"store.builder.computeSubtreeCounts",()=>this.computeSubtreeCounts(0));return{directories:this.directories,nodes:this.nodes,options:this.options,rootId:0,segmentTable:this.segmentTable,presortedDirectoryNodeIds:this.presortedDirectoryNodeIds.length>0?this.presortedDirectoryNodeIds:null}}didMatchAllInitialExpandedPaths(){return this.createdDirectoriesAllExpanded&&this.initialExpandedPathSet!=null&&this.createdDirectoryCount===this.initialExpandedPathSet.size}appendPreparedPath(e,t){if(this.hasDeferredDirectoryIndexes)this.buildDirectoryIndexes(),this.hasDeferredDirectoryIndexes=!1;if(this.lastPreparedPath!=null){if(e.path===this.lastPreparedPath.path)throw Error(`Duplicate path: "${e.path}"`);if(t){if((this.options.sort==="default"?fa(this.lastPreparedPath,e,this.segmentSortKeyCache):ya(this.lastPreparedPath,e,this.options.sort))>0)throw Error(`Builder input must be sorted before appendPaths(): "${e.path}"`)}}let n=this.lastPreparedPath,r=ga(e),i=n==null?0:ga(n),o=n==null?0:Rh(n.segments,e.segments),s=Math.min(o,r,i);this.directoryStack.length=s+1;for(let l=s;l<r;l++){let c=this.directoryStack[this.directoryStack.length-1];if(c===void 0)throw Error("Directory stack underflow while building the path store");let d=t?this.getOrCreateDirectoryChild(c,e.segments[l]):this.createDirectoryChild(c,e.segments[l]);this.directoryStack.push(d)}if(e.isDirectory){let l=this.directoryStack[this.directoryStack.length-1];if(l===void 0)throw Error(`Unable to resolve directory node for "${e.path}"`);this.promoteDirectoryToExplicit(l,e.path),this.lastPreparedPath=e;return}let a=this.directoryStack[this.directoryStack.length-1];if(a===void 0)throw Error(`Unable to resolve file parent for "${e.path}"`);if(t)this.createFileChild(a,e.basename,e.path);else this.createFileChildUnchecked(a,e.basename);this.lastPreparedPath=e}recordCreatedDirectoryPath(e){if(!this.createdDirectoriesAllExpanded||this.initialExpandedPathSet==null)return;if(this.createdDirectoryCount+=1,!this.initialExpandedPathSet.has(e))this.createdDirectoriesAllExpanded=!1}createFileChild(e,t,n){let r=rt(this.segmentTable,t),i=this.getDirectoryIndex(e),o=i.childIdByNameId;if(o!=null){if(o.get(r)!==void 0)throw Error(`Path collides with an existing entry: "${n}"`)}let s=this.nodes[e];if(s===void 0)throw Error(`Unknown parent node ID: ${String(e)}`);let a=this.nodes.length;if(this.nodes.push({depthAndFlags:Ae(Ve(s)+1,0),nameId:r,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),o!=null)o.set(r,a);return gn(i,a),a}createFileChildUnchecked(e,t){let n=rt(this.segmentTable,t),r=this.getDirectoryIndex(e),i=this.nodes[e];if(i===void 0)throw Error(`Unknown parent node ID: ${String(e)}`);let o=this.nodes.length;if(this.nodes.push({depthAndFlags:Ae(Ve(i)+1,0),nameId:n,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),r.childIdByNameId!=null)r.childIdByNameId.set(n,o);return gn(r,o),o}getOrCreateDirectoryChild(e,t){let n=rt(this.segmentTable,t),r=this.getDirectoryIndex(e);if(r.childIdByNameId!=null){let s=r.childIdByNameId.get(n);if(s!==void 0){let a=this.nodes[s];if(a!=null&&!D(a))throw Error(`Path collides with an existing file while creating directory "${t}"`);return s}}let i=this.nodes[e];if(i===void 0)throw Error(`Unknown parent node ID: ${String(e)}`);let o=this.nodes.length;if(this.nodes.push({depthAndFlags:Ae(Ve(i)+1,0,1),nameId:n,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),r.childIdByNameId!=null)r.childIdByNameId.set(n,o);return gn(r,o),this.directories.set(o,Gt()),o}createDirectoryChild(e,t){let n=rt(this.segmentTable,t),r=this.getDirectoryIndex(e),i=this.nodes[e];if(i===void 0)throw Error(`Unknown parent node ID: ${String(e)}`);let o=this.nodes.length;if(this.nodes.push({depthAndFlags:Ae(Ve(i)+1,0,1),nameId:n,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),r.childIdByNameId!=null)r.childIdByNameId.set(n,o);return gn(r,o),this.directories.set(o,Gt()),o}promoteDirectoryToExplicit(e,t){let n=this.nodes[e];if(n===void 0)throw Error(`Unknown directory node ID: ${String(e)}`);if(!D(n))throw Error(`Path is not a directory: "${t}"`);if(ue(n,1))throw Error(`Duplicate path: "${t}"`);vn(n,1)}getDirectoryIndex(e){let t=this.directories.get(e);if(t!==void 0)return t;throw Error(`Unknown directory child index for node ${String(e)}`)}buildPresortedFinish(e){let t=this.nodes,n=this.directories;n.set(0,lo());let r=-1,i=null;for(let o=1;o<t.length;o++){let s=t[o];if(s==null)continue;if(D(s)){let l=lo();n.set(o,l),r=o,i=l}let a;if(s.parentId===r)a=i;else a=n.get(s.parentId),r=s.parentId,i=a??null;if(a!=null)a.childIds.push(o)}if(e)return;for(let o=t.length-1;o>=1;o--){let s=t[o];if(s==null)continue;let a=t[s.parentId];if(a!=null)a.subtreeNodeCount+=s.subtreeNodeCount,a.visibleSubtreeCount+=s.visibleSubtreeCount}}buildDirectoryIndexes(){let e=this.nodes;for(let t=1;t<e.length;t++){let n=e[t];if(n==null)continue;if(D(n))this.directories.set(t,Gt());let r=this.directories.get(n.parentId);if(r!=null){if(r.childIdByNameId!=null)r.childIdByNameId.set(n.nameId,t);gn(r,t)}}}computeSubtreeCounts(e){let t=this.nodes[e];if(t===void 0)throw Error(`Unknown node ID: ${String(e)}`);if(!D(t))return t.subtreeNodeCount=1,t.visibleSubtreeCount=1,1;let n=this.getDirectoryIndex(e),r=1;for(let i of n.childIds)r+=this.computeSubtreeCounts(i);return Yt(this.nodes,n),t.subtreeNodeCount=r,t.visibleSubtreeCount=r,r}};function ka(e,t="closed",n=null){let r=Ah(t);return{activeNodeCount:e.nodes.length-1,collapsedDirectoryIds:new Set,collapseNewDirectoriesByDefault:!1,defaultExpansion:r,directoriesOpenByDefault:r==="open",hasCollapsedDirectoryOverrides:!1,directoryLoadInfoById:new Map,expandedDirectoryIds:new Set,instrumentation:n,listeners:new Map,pathCacheByNodeId:new Map([[e.rootId,{path:"",version:0}]]),pathCacheVersion:0,snapshot:e,transactionStack:[]}}function _a(){return{affectedAncestorIds:new Set,affectedNodeIds:new Set,events:[]}}function Ah(e){if(typeof e!=="number")return e;if(!Number.isInteger(e)||e<0)throw Error(`initialExpansion must be "open", "closed", or a non-negative integer depth. Received: ${String(e)}`);return e}function Ea(e,t){if(ue(t,2))return!0;if(e.defaultExpansion==="open")return!0;if(e.defaultExpansion==="closed")return!1;return Ve(t)<=e.defaultExpansion}function Ce(e,t,n=e.snapshot.nodes[t]){if(n==null||!D(n))return!1;if(e.directoriesOpenByDefault&&!e.hasCollapsedDirectoryOverrides)return!0;if(e.collapsedDirectoryIds.has(t))return!1;if(e.expandedDirectoryIds.has(t))return!0;return Ea(e,n)}function At(e,t,n,r=e.snapshot.nodes[t]){if(r==null||!D(r))return;let i=Ea(e,r);if(n){if(i){e.collapsedDirectoryIds.delete(t),e.hasCollapsedDirectoryOverrides=e.collapsedDirectoryIds.size>0;return}e.expandedDirectoryIds.add(t);return}if(i){e.collapsedDirectoryIds.add(t),e.hasCollapsedDirectoryOverrides=!0;return}e.expandedDirectoryIds.delete(t)}function Ta(e,t){let n=e.directoryLoadInfoById.get(t);if(n!=null)return n;let r={activeAttemptId:null,errorMessage:null,nextAttemptId:1,state:"loaded"};return e.directoryLoadInfoById.set(t,r),r}function Nt(e,t){return e.directoryLoadInfoById.get(t)?.state??"loaded"}function Pa(e,t){let n=Ta(e,t);if(n.state==="loading"&&n.activeAttemptId!=null)return{attemptId:n.activeAttemptId,nodeId:t,reused:!0};let r=n.nextAttemptId;return n.activeAttemptId=r,n.errorMessage=null,n.nextAttemptId+=1,n.state="loading",{attemptId:r,nodeId:t,reused:!1}}function Ra(e,t){let n=Ta(e,t);n.activeAttemptId=null,n.errorMessage=null,n.state="unloaded"}function Da(e,t,n){let r=e.directoryLoadInfoById.get(t);if(r==null||r.activeAttemptId!==n)return!1;return r.activeAttemptId=null,r.errorMessage=null,r.state="loaded",!0}function Ma(e,t,n){return e.directoryLoadInfoById.get(t)?.activeAttemptId===n}function Aa(e,t,n,r){let i=e.directoryLoadInfoById.get(t);if(i==null||i.activeAttemptId!==n)return!1;return i.activeAttemptId=null,i.errorMessage=r??null,i.state="error",!0}function Na(e,t){e.directoryLoadInfoById.delete(t)}function Va(e,t,n){let r=n,i=e.listeners.get(t);if(i!=null)i.add(r);else e.listeners.set(t,new Set([r]));return()=>{let o=e.listeners.get(t);if(o==null)return;if(o.delete(r),o.size===0)e.listeners.delete(t)}}function Oa(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!0,operation:"add",path:e.path,projectionChanged:e.projectionChanged,visibleCountDelta:null}}function za(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!0,operation:"remove",path:e.path,projectionChanged:e.projectionChanged,recursive:e.recursive,visibleCountDelta:null}}function qa(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!0,from:e.from,operation:"move",projectionChanged:e.projectionChanged,to:e.to,visibleCountDelta:null}}function Wa(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!1,operation:"expand",path:e.path,projectionChanged:!0,visibleCountDelta:null}}function ja(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!1,operation:"collapse",path:e.path,projectionChanged:!0,visibleCountDelta:null}}function $a(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!1,operation:"mark-directory-unloaded",path:e.path,projectionChanged:e.projectionChanged,visibleCountDelta:null}}function Ua(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],attemptId:e.attemptId,canonicalChanged:!1,operation:"begin-child-load",path:e.path,projectionChanged:e.projectionChanged,reused:e.reused,visibleCountDelta:null}}function Ka(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],attemptId:e.attemptId,canonicalChanged:e.childEvents.some((t)=>t.canonicalChanged),childEvents:e.childEvents,operation:"apply-child-patch",path:e.path,projectionChanged:e.projectionChanged,visibleCountDelta:null}}function Ga(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],attemptId:e.attemptId,canonicalChanged:!1,operation:"complete-child-load",path:e.path,projectionChanged:e.projectionChanged,stale:e.stale,visibleCountDelta:null}}function Ya(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],attemptId:e.attemptId,canonicalChanged:!1,errorMessage:e.errorMessage,operation:"fail-child-load",path:e.path,projectionChanged:e.projectionChanged,stale:e.stale,visibleCountDelta:null}}function Xa(e){return{activeNodeCountAfter:e.activeNodeCountAfter,activeNodeCountBefore:e.activeNodeCountBefore,affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],cachedPathEntryCountAfter:e.cachedPathEntryCountAfter,cachedPathEntryCountBefore:e.cachedPathEntryCountBefore,canonicalChanged:!1,idsPreserved:e.idsPreserved,loadInfoEntryCountAfter:e.loadInfoEntryCountAfter,loadInfoEntryCountBefore:e.loadInfoEntryCountBefore,mode:e.mode,operation:"cleanup",projectionChanged:e.projectionChanged,reclaimedCachedPathEntryCount:e.reclaimedCachedPathEntryCount,reclaimedLoadInfoEntryCount:e.reclaimedLoadInfoEntryCount,reclaimedNodeSlotCount:e.reclaimedNodeSlotCount,reclaimedSegmentCount:e.reclaimedSegmentCount,segmentCountAfter:e.segmentCountAfter,segmentCountBefore:e.segmentCountBefore,totalNodeSlotCountAfter:e.totalNodeSlotCountAfter,totalNodeSlotCountBefore:e.totalNodeSlotCountBefore,visibleCountDelta:null}}function Ne(e,t,n){return{...n,visibleCountDelta:po(e)-t}}function Qa(e,t){let n=po(e),r=_a();e.transactionStack.push(r);try{t()}catch(i){throw Fa(e,r,!1),i}Fa(e,r,!0,po(e)-n)}function Xe(e,t){let n=e.instrumentation;if(n==null){La(e,t);return}E(n,"store.events.record",()=>La(e,t))}function La(e,t){let n=e.transactionStack[e.transactionStack.length-1]??null;if(n==null){fo(e,t);return}n.events.push(t),Fh(n,t)}function Fa(e,t,n,r=null){if(e.transactionStack.pop()!==t)throw Error("Transaction stack underflow");if(!n)return;let i=e.transactionStack[e.transactionStack.length-1]??null;if(i!=null){let a=e.instrumentation;if(a==null)Ba(i,t);else E(a,"store.events.batch.merge",()=>Ba(i,t));return}let o=Nh(t,r),s=e.instrumentation;if(s==null){fo(e,o);return}E(s,"store.events.batch.commit",()=>fo(e,o))}function Nh(e,t){return{affectedAncestorIds:[...e.affectedAncestorIds],affectedNodeIds:[...e.affectedNodeIds],canonicalChanged:e.events.some((n)=>n.canonicalChanged),events:[...e.events],operation:"batch",projectionChanged:e.events.some((n)=>n.projectionChanged),visibleCountDelta:t}}function Lh(e,t){for(let n of t.affectedAncestorIds)e.affectedAncestorIds.add(n);for(let n of t.affectedNodeIds)e.affectedNodeIds.add(n)}function Ba(e,t){for(let n of t.events)e.events.push(n);Lh(e,t)}function Fh(e,t){for(let n of t.affectedNodeIds)e.affectedNodeIds.add(n);for(let n of t.affectedAncestorIds)e.affectedAncestorIds.add(n)}function fo(e,t){let n=e.instrumentation;if(n==null){Ha(e,t);return}E(n,"store.events.emit",()=>Ha(e,t))}function Ha(e,t){e.listeners.get(t.operation)?.forEach((n)=>n(t)),e.listeners.get("*")?.forEach((n)=>n(t))}function po(e){return e.snapshot.nodes[e.snapshot.rootId]?.visibleSubtreeCount??0}function yt(e,t){if(e.snapshot.options.flattenEmptyDirectories!==!0)return null;let n=e.snapshot.nodes[t];if(n==null||!D(n)||ue(n,2))return null;let r=e.snapshot.directories.get(t);if(r==null||r.childIds.length!==1)return null;let i=r.childIds[0];if(i==null)return null;let o=e.snapshot.nodes[i];if(o==null||!D(o))return null;return i}function bt(e,t){let n=t;while(!0){let r=yt(e,n);if(r==null)return n;n=r}}function bn(e,t){let n=[t],r=t;while(!0){let i=yt(e,r);if(i==null)return n;n.push(i),r=i}}function ti(e,t){let n=t==null?e.snapshot.rootId:Le(e,t);if(n==null)return[];return Hh(e,n)}function go(e,t){let n=Qt(t),r=n.isDirectory?n.segments:n.segments.slice(0,-1),i=Lt(e,Kh(e,r)),{createdNodeIds:o,directoryId:s}=Vh(e,r),a=new Set(o),l=s;if(n.isDirectory){let d=M(e,s);if(ue(d,1))throw Error(`Path already exists: "${t}"`);vn(d,1),e.pathCacheByNodeId.set(s,{path:t,version:e.pathCacheVersion}),a.add(s)}else l=zh(e,s,n.basename),a.add(l);Ft(e,s);let c=Lt(e,s);return Oa({affectedAncestorIds:We(e,l),affectedNodeIds:[...a],path:t,projectionChanged:il(i,c)})}function vo(e,t,n){let r=Le(e,t);if(r==null)throw Error(`Path does not exist: "${t}"`);let i=M(e,r);if(ue(i,2))throw Error("The root node cannot be removed");if(D(i)&&ae(e,r).childIds.length>0&&n.recursive!==!0)throw Error(`Cannot remove a non-empty directory without recursive: "${t}"`);let o=i.parentId,s=Lt(e,o),a=rl(e,r);wo(e,o,r,i.nameId),Io(e,o),Ft(e,o);let l=Lt(e,o);return za({affectedAncestorIds:We(e,o),affectedNodeIds:a,path:t,projectionChanged:il(s,l),recursive:n.recursive===!0})}function yo(e,t,n,r){let i=Le(e,t);if(i==null)throw Error(`Source path does not exist: "${t}"`);let o=M(e,i);if(ue(o,2))throw Error("The root node cannot be moved");let s=r.collision??"error",a=$h(e,i,n),l=Lt(e,o.parentId),c=Lt(e,a.parentId),d=qe(e.snapshot.segmentTable,o.nameId),f=rt(e.snapshot.segmentTable,a.basename);if(a.parentId===o.parentId&&d===a.basename)return null;if(D(o)&&Yh(e,i,a.parentId))throw Error("Cannot move a directory into one of its descendants");let u=Dt(e.snapshot.nodes,ae(e,a.parentId)).get(f),m=a.existingNodeId??u??null;if(m!=null&&m!==i){if(Uh(e,m,s,sr(o))==="skip")return null}let p=o.parentId;if(wo(e,p,i,o.nameId),o.parentId=a.parentId,o.nameId=f,e.pathCacheByNodeId.delete(i),sl(e,i),bo(e,a.parentId,i),Io(e,p),e.pathCacheVersion++,Ft(e,p),a.parentId!==p)Ft(e,a.parentId);let g=Lt(e,p),v=Lt(e,a.parentId);return qa({affectedAncestorIds:[...new Set([...We(e,p),...We(e,a.parentId)])],affectedNodeIds:[i],from:t,projectionChanged:ol([l,c],[g,v]),to:ne(e,i)})}function Bh(e,t){let n=e.pathCacheByNodeId.get(t);return n!=null&&n.version===e.pathCacheVersion?n.path:null}function Ja(e,t,n){return e.pathCacheByNodeId.set(t,{path:n,version:e.pathCacheVersion}),n}function ne(e,t){let n=M(e,t),r=Bh(e,t);if(r!=null)return r;if(ue(n,2))return Ja(e,t,"");let i=ne(e,n.parentId),o=qe(e.snapshot.segmentTable,n.nameId),s=i.length===0?o:`${i}${o}`;return Ja(e,t,D(n)?`${s}/`:s)}function Ft(e,t){let n=e.instrumentation;if(n==null){el(e,t);return}E(n,"store.recomputeCountsUpwardFrom",()=>el(e,t))}function ur(e,t){let n=[[t,0]],{nodes:r,directories:i}=e.snapshot;while(n.length>0){let o=n[n.length-1],s=o[0],a=r[s];if(a==null||!D(a)){mo(e,s,a,!0),n.pop();continue}let l=i.get(s);if(l==null||o[1]>=l.childIds.length){mo(e,s,a,!0),n.pop();continue}let c=l.childIds[o[1]++];n.push([c,0])}}function We(e,t){let n=[],r=t;while(r!=null){let i=M(e,r);if(n.push(r),r===e.snapshot.rootId)break;r=i.parentId}return n}function Le(e,t){if(t.length===0)return e.snapshot.rootId;let n=Qr(t);return nl(e,n.segments,n.requiresDirectory)}function nl(e,t,n){let r=e.snapshot.rootId;for(let o of t){let s=e.snapshot.segmentTable.idByValue.get(o);if(s===void 0)return null;let a=ae(e,r),l=Dt(e.snapshot.nodes,a).get(s);if(l===void 0)return null;r=l}let i=M(e,r);if(n&&!D(i))return null;return r}function ae(e,t){let n=e.snapshot.directories.get(t);if(n===void 0)throw Error(`Unknown directory child index for node ${String(t)}`);return n}function M(e,t){let n=e.snapshot.nodes[t];if(n===void 0||ue(n,4))throw Error(`Unknown node ID: ${String(t)}`);return n}function Hh(e,t){let n=e.snapshot.nodes[t];if(n===void 0||ue(n,4))return[];if(!D(n))return[ne(e,t)];if(ae(e,t).childIds.length===0)return ue(n,1)&&!ue(n,2)?[ne(e,t)]:[];let r=[],i=[{childIndex:0,nodeId:t}];while(i.length>0){let o=i[i.length-1];if(o==null)break;let s=e.snapshot.nodes[o.nodeId];if(s===void 0||ue(s,4)){i.pop();continue}if(!D(s)){r.push(ne(e,o.nodeId)),i.pop();continue}let a=ae(e,o.nodeId);if(a.childIds.length===0){if(ue(s,1)&&!ue(s,2))r.push(ne(e,o.nodeId));i.pop();continue}let l=a.childIds[o.childIndex];if(l==null){i.pop();continue}o.childIndex++,i.push({childIndex:0,nodeId:l})}return r}function Vh(e,t){let n=[],r=e.snapshot.rootId;for(let i of t){let o=rt(e.snapshot.segmentTable,i),s=ae(e,r),a=Dt(e.snapshot.nodes,s).get(o);if(a!==void 0){if(!D(M(e,a)))throw Error(`Cannot create a directory that collides with an existing file: "${i}"`);r=a;continue}r=Oh(e,r,o),n.push(r)}return{createdNodeIds:n,directoryId:r}}function Oh(e,t,n){let r=M(e,t),i=e.snapshot.nodes.length;if(e.snapshot.nodes.push({depthAndFlags:Ae(Ve(r)+1,0,1),nameId:n,parentId:t,subtreeNodeCount:1,visibleSubtreeCount:1}),e.snapshot.directories.set(i,Gt()),bo(e,t,i),e.collapseNewDirectoriesByDefault)e.collapsedDirectoryIds.add(i),e.hasCollapsedDirectoryOverrides=!0;return e.activeNodeCount++,i}function zh(e,t,n){let r=rt(e.snapshot.segmentTable,n),i=ae(e,t);if(Dt(e.snapshot.nodes,i).has(r))throw Error(`Path already exists: "${Xh(e,t,n)}"`);let o=M(e,t),s=e.snapshot.nodes.length;return e.snapshot.nodes.push({depthAndFlags:Ae(Ve(o)+1,0),nameId:r,parentId:t,subtreeNodeCount:1,visibleSubtreeCount:1}),bo(e,t,s),e.activeNodeCount++,s}function qh(e,t,n){let r=0,i=t.childIds.length;while(r<i){let o=r+i>>>1,s=t.childIds[o];if(s==null){i=o;continue}if(Wh(e,n,s)<0)i=o;else r=o+1}return r}function bo(e,t,n){let r=ae(e,t),i=M(e,n);Dt(e.snapshot.nodes,r).set(i.nameId,n),Gr(r,n,i.subtreeNodeCount,i.visibleSubtreeCount);let o=qh(e,r,n);r.childIds.splice(o,0,n),co(r,o),Mt(e.snapshot.nodes,r)}function wo(e,t,n,r){let i=ae(e,t),o=mn(i),s=o.get(n)??-1;Dt(e.snapshot.nodes,i).delete(r),o.delete(n);let a=e.snapshot.nodes[n];if(a!=null)Gr(i,n,-a.subtreeNodeCount,-a.visibleSubtreeCount);if(s>=0)i.childIds.splice(s,1),co(i,s),Mt(e.snapshot.nodes,i)}function Wh(e,t,n){let r=e.snapshot.options.sort;if(r==="default")return jh(e,t,n);return r(Za(e,t),Za(e,n))}function jh(e,t,n){let r=M(e,t),i=M(e,n),o=D(r);if(o!==D(i))return o?-1:1;let s=lr(cr(e.snapshot.segmentTable,r.nameId),cr(e.snapshot.segmentTable,i.nameId));if(s!==0)return s;let a=qe(e.snapshot.segmentTable,r.nameId),l=qe(e.snapshot.segmentTable,i.nameId);if(a!==l)return a<l?-1:1;return t<n?-1:1}function Za(e,t){let n=M(e,t),r=ne(e,t),i=D(n),o=i?r.slice(0,-1):r;return{basename:qe(e.snapshot.segmentTable,n.nameId),depth:Ve(n),isDirectory:i,path:r,segments:o.length===0?[]:o.split("/")}}function $h(e,t,n){let r=M(e,t),i=Le(e,n);if(i!=null){let c=M(e,i);if(D(c))return{basename:qe(e.snapshot.segmentTable,r.nameId),existingNodeId:null,parentId:i};let d=Qr(n).segments;return{basename:d[d.length-1]??"",existingNodeId:i,parentId:c.parentId}}let o=Qr(n),s=o.segments[o.segments.length-1]??"",a=o.segments.slice(0,-1),l=a.length===0?e.snapshot.rootId:nl(e,a,!0);if(l==null)throw Error(`Destination parent does not exist: "${n}"`);return{basename:s,existingNodeId:null,parentId:l}}function Uh(e,t,n,r){if(n==="skip")return"skip";if(n==="error")throw Error(`Destination already exists: "${ne(e,t)}"`);let i=M(e,t);if(sr(i)!==r)throw Error("replace collision requires the same source and destination kinds");if(D(i)&&ae(e,t).childIds.length>0)throw Error("replace collision does not support non-empty directories");let{parentId:o,nameId:s}=i;return rl(e,t),wo(e,o,t,s),Io(e,o),Ft(e,o),"handled"}function rl(e,t){let n=[],r=[{nodeId:t,visitedChildren:!1}];while(r.length>0){let i=r.pop();if(i==null)break;let o=M(e,i.nodeId);if(i.visitedChildren||!D(o)){if(D(o))e.snapshot.directories.delete(i.nodeId);if(vn(o,4),e.pathCacheByNodeId.delete(i.nodeId),e.collapsedDirectoryIds.delete(i.nodeId))e.hasCollapsedDirectoryOverrides=e.collapsedDirectoryIds.size>0;e.expandedDirectoryIds.delete(i.nodeId),Na(e,i.nodeId),e.activeNodeCount--,n.push(i.nodeId);continue}r.push({nodeId:i.nodeId,visitedChildren:!0});let s=ae(e,i.nodeId);for(let a=s.childIds.length-1;a>=0;a--){let l=s.childIds[a];if(l!=null)r.push({nodeId:l,visitedChildren:!1})}}return n}function Io(e,t){let n=t;while(n!=null){let r=M(e,n);if(!D(r)||ue(r,2))return;if(ae(e,n).childIds.length>0)return;vn(r,1),n=r.parentId===n?null:r.parentId}}function Kh(e,t){let n=e.snapshot.rootId;for(let r of t){let i=e.snapshot.segmentTable.idByValue.get(r);if(i==null)break;let o=Dt(e.snapshot.nodes,ae(e,n)).get(i);if(o==null)break;if(!D(M(e,o)))break;n=o}return n}function Lt(e,t){let n=Gh(e,t);if(n==null)return null;let r=bt(e,n),i=M(e,r),o=n===r?null:bn(e,n).map((s)=>ne(e,s));return JSON.stringify({flattenedSegmentPaths:o,hasChildren:ae(e,r).childIds.length>0,path:ne(e,r),terminalKind:sr(i)})}function il(e,t){return ol([e],[t])}function ol(e,t){for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(r==null||i==null||r!==i)return!0}return!1}function Gh(e,t){let n=t;while(n!=null){let r=M(e,n);if(!D(r)||ue(r,2))return null;if(!Ce(e,n,r))return n;n=r.parentId}return null}function sl(e,t){let n=M(e,t);if(aa(n,(t===e.snapshot.rootId?-1:Ve(M(e,n.parentId)))+1),!D(n))return;let r=ae(e,t);for(let i of r.childIds)sl(e,i)}function Yh(e,t,n){let r=n;while(r!=null){if(r===t)return!0;let i=M(e,r);if(r===e.snapshot.rootId)return!1;r=i.parentId}return!1}function mo(e,t,n=M(e,t),r=!1){let i=e.instrumentation;if(i==null){tl(e,t,n,r);return}E(i,"store.recomputeNodeCounts",()=>tl(e,t,n,r))}function el(e,t){let n=t;while(n!=null){let r=M(e,n),i=r.subtreeNodeCount,o=r.visibleSubtreeCount;if(mo(e,n,r),n===e.snapshot.rootId)return;let s=r.subtreeNodeCount-i,a=r.visibleSubtreeCount-o,l=r.parentId;if(s!==0||a!==0)Gr(ae(e,l),n,s,a);n=l}}function tl(e,t,n,r){if(!D(n)){n.subtreeNodeCount=1,n.visibleSubtreeCount=1;return}let i=ae(e,t);if(r){let a=e.instrumentation;if(a==null)Yt(e.snapshot.nodes,i);else E(a,"store.recomputeNodeCounts.rebuildChildAggregates",()=>Yt(e.snapshot.nodes,i))}let o=1+i.totalChildSubtreeNodeCount,s=i.totalChildVisibleSubtreeCount;if(n.subtreeNodeCount=o,ue(n,2)){n.visibleSubtreeCount=s;return}n.visibleSubtreeCount=yt(e,t)!=null?s:Ce(e,t,n)?1+s:1}function Xh(e,t,n){let r=ne(e,t);return r.length===0?n:`${r}${n}`}function wn(e){return e!=null&&!ue(e,4)}function ni(e,t){let n=e.snapshot.nodes[t];if(!wn(n)||!D(n)||ue(n,2))return null;return n}function Qh(e){let t=0;for(let[n,r]of e.pathCacheByNodeId){if(r.version!==e.pathCacheVersion)continue;if(!wn(e.snapshot.nodes[n]))continue;t+=1}return t}function Jh(e){return Math.max(0,e.valueById.length-1)}function al(e){return{activeNodeCount:e.activeNodeCount,cachedPathEntryCount:Qh(e),loadInfoEntryCount:e.directoryLoadInfoById.size,segmentCount:Jh(e.snapshot.segmentTable),totalNodeSlotCount:Math.max(0,e.snapshot.nodes.length-1)}}function Zh(e,t,n,r){return{activeNodeCountAfter:r.activeNodeCount,activeNodeCountBefore:n.activeNodeCount,cachedPathEntryCountAfter:r.cachedPathEntryCount,cachedPathEntryCountBefore:n.cachedPathEntryCount,idsPreserved:t,loadInfoEntryCountAfter:r.loadInfoEntryCount,loadInfoEntryCountBefore:n.loadInfoEntryCount,mode:e,reclaimedCachedPathEntryCount:n.cachedPathEntryCount-r.cachedPathEntryCount,reclaimedLoadInfoEntryCount:n.loadInfoEntryCount-r.loadInfoEntryCount,reclaimedNodeSlotCount:n.totalNodeSlotCount-r.totalNodeSlotCount,reclaimedSegmentCount:n.segmentCount-r.segmentCount,segmentCountAfter:r.segmentCount,segmentCountBefore:n.segmentCount,totalNodeSlotCountAfter:r.totalNodeSlotCount,totalNodeSlotCountBefore:n.totalNodeSlotCount}}function ll(e){let t=[],n=[];for(let r of e.collapsedDirectoryIds)if(ni(e,r)!=null)t.push(ne(e,r));for(let r of e.expandedDirectoryIds)if(ni(e,r)!=null)n.push(ne(e,r));return{collapsedPaths:t,expandedPaths:n}}function cl(e){let t=[];for(let[n,r]of e.directoryLoadInfoById){if(ni(e,n)==null||Nt(e,n)==="loaded")continue;t.push({info:{activeAttemptId:null,errorMessage:r.errorMessage,nextAttemptId:r.nextAttemptId,state:r.state},path:ne(e,n)})}return t}function ul(e,t){e.collapsedDirectoryIds.clear(),e.hasCollapsedDirectoryOverrides=!1,e.expandedDirectoryIds.clear();for(let n of t.expandedPaths){let r=Le(e,n);if(r==null)continue;At(e,r,!0,M(e,r))}for(let n of t.collapsedPaths){let r=Le(e,n);if(r==null)continue;At(e,r,!1,M(e,r))}}function dl(e,t){e.directoryLoadInfoById.clear();for(let n of t){let r=Le(e,n.path);if(r==null)continue;if(ni(e,r)==null)continue;e.directoryLoadInfoById.set(r,{activeAttemptId:null,errorMessage:n.info.errorMessage,nextAttemptId:n.info.nextAttemptId,state:n.info.state})}}function ef(e){e.pathCacheVersion+=1,e.pathCacheByNodeId.clear(),e.pathCacheByNodeId.set(e.snapshot.rootId,{path:"",version:e.pathCacheVersion})}function tf(e){let t=e.snapshot.segmentTable,n=Jr();for(let r of e.snapshot.nodes){if(!wn(r))continue;if(ue(r,2)){r.nameId=0;continue}r.nameId=rt(n,qe(t,r.nameId))}e.snapshot.segmentTable=n}function nf(e){for(let[t,n]of e.snapshot.directories){let r=e.snapshot.nodes[t];if(!wn(r)||!D(r)){e.snapshot.directories.delete(t);continue}let i=n.childIds.filter((o)=>{let s=e.snapshot.nodes[o];return wn(s)&&s.parentId===t});n.childIds=i,n.childIdByNameId=new Map(i.map((o)=>[M(e,o).nameId,o])),n.childPositionById=new Map(i.map((o,s)=>[o,s])),Yt(e.snapshot.nodes,n)}}function rf(e){let t=e.snapshot.nodes.length-1;while(t>e.snapshot.rootId){let n=e.snapshot.nodes[t];if(wn(n))break;t-=1}e.snapshot.nodes.length=t+1}function of(e){let t=ll(e),n=cl(e);E(e.instrumentation,"store.cleanup.stable.clearPathCaches",()=>ef(e)),E(e.instrumentation,"store.cleanup.stable.rebuildSegmentTable",()=>tf(e)),E(e.instrumentation,"store.cleanup.stable.rebuildDirectoryIndexes",()=>nf(e)),E(e.instrumentation,"store.cleanup.stable.trimTrailingRemovedNodeSlots",()=>rf(e)),E(e.instrumentation,"store.cleanup.stable.restoreExpansionOverrides",()=>ul(e,t)),E(e.instrumentation,"store.cleanup.stable.restoreDirectoryLoadInfos",()=>dl(e,n)),E(e.instrumentation,"store.cleanup.stable.recomputeCounts",()=>ur(e,e.snapshot.rootId))}function sf(e){let t=ll(e),n=cl(e),r=E(e.instrumentation,"store.cleanup.aggressive.listPaths",()=>ti(e)),i=ca({...e.snapshot.options},e.instrumentation),o=E(e.instrumentation,"store.cleanup.aggressive.rebuildSnapshot",()=>{let s=new ei(i);return s.appendPaths(r),s.finish()});e.snapshot=o,e.activeNodeCount=o.nodes.length-1,e.pathCacheByNodeId=new Map([[o.rootId,{path:"",version:0}]]),e.pathCacheVersion=0,E(e.instrumentation,"store.cleanup.aggressive.restoreExpansionOverrides",()=>ul(e,t)),E(e.instrumentation,"store.cleanup.aggressive.restoreDirectoryLoadInfos",()=>dl(e,n)),E(e.instrumentation,"store.cleanup.aggressive.recomputeCounts",()=>ur(e,e.snapshot.rootId))}function hl(e){for(let t of e.directoryLoadInfoById.values())if(t.state==="loading"&&t.activeAttemptId!=null)return!0;return!1}function fl(e,t){let n=al(e);if(t==="stable")E(e.instrumentation,"store.cleanup.stable",()=>of(e));else E(e.instrumentation,"store.cleanup.aggressive",()=>sf(e));let r=al(e);return Zh(t,t==="stable",n,r)}var af=64;function lf(e,t){let n=t+2;if(n<=e.length)return e;let r=e.length;while(r<n)r*=2;let i=new Int32Array(r);return i.fill(-1),i.set(e),i}function xe(e){return M(e,e.snapshot.rootId).visibleSubtreeCount}function vl(e,t,n,r){let i=M(e,t.terminalNodeId),o=Math.max(1,i.visibleSubtreeCount);return Math.min(r-1,n+o-1)}function cf(e,t,n,r){return{ancestorPaths:r,index:t.index,posInSet:t.posInSet,row:dr(e,t.cursor),setSize:t.setSize,subtreeEndIndex:vl(e,t.cursor,t.index,n)}}function yl(e,t,n,r,i,o){let s=ae(e,t),{childIndex:a,childVisibleIndex:l,localVisibleIndex:c}=Yr(e.snapshot.nodes,s,n),d=s.childIds[a];if(d==null)throw Error(`Visible index ${String(n)} is out of range`);return uf(e,d,c,r+l,i+1,a,s.childIds.length,o)}function uf(e,t,n,r,i,o,s,a){if(!D(M(e,t))){if(n===0)return{ancestors:a,cursor:{headNodeId:t,terminalNodeId:t,visibleDepth:i},index:r,posInSet:o,setSize:s};throw Error(`Visible index ${String(n)} is out of range for file`)}let l=_l(e,t,i);if(n===0)return{ancestors:a,cursor:l,index:r,posInSet:o,setSize:s};let c=M(e,l.terminalNodeId);if(!D(c)||!Ce(e,l.terminalNodeId,c))throw Error(`Visible index ${String(n)} is out of range for collapsed directory`);return yl(e,l.terminalNodeId,n-1,r+1,l.visibleDepth,[...a,{cursor:l,index:r,posInSet:o,setSize:s}])}function bl(e,t){let n=xe(e);if(t<0||t>=n)return null;let r=yl(e,e.snapshot.rootId,t,0,-1,[]),i=r.ancestors.map((s)=>ne(e,s.cursor.terminalNodeId)),o=null;return{ancestorPaths:i,get ancestorRows(){if(o!=null)return o;let s=[],a=[];for(let l of r.ancestors){let c=cf(e,l,n,[...a]);s.push(c),a.push(c.row.path)}return o=s,o},index:r.index,posInSet:r.posInSet,row:dr(e,r.cursor),setSize:r.setSize,subtreeEndIndex:vl(e,r.cursor,r.index,n)}}function wl(e,t,n){let r=e.instrumentation,i=xe(e);if(i<=0||n<t)return[];let o=Math.max(0,Math.min(t,i-1)),s=Math.max(o,Math.min(n,i-1));if(r==null){if(o===0)return ff(e,s+1);let f=[],u=pl(e,o);for(let m=o;m<=s&&u!=null;m++){let p=dr(e,u);f.push(p),u=ml(e,u)}return f}let a=[],l=0,c=0,d=E(r,"store.getVisibleSlice.selectFirstRow",()=>pl(e,o));for(let f=o;f<=s&&d!=null;f++){let u=E(r,"store.getVisibleSlice.materializeRow",()=>dr(e,d));if(a.push(u),u.isFlattened)l++,c+=u.flattenedSegments?.length??0;d=E(r,"store.getVisibleSlice.advanceCursor",()=>ml(e,d))}return yn(r,"workload.visibleRowsRead",a.length),yn(r,"workload.flattenedRowsRead",l),yn(r,"workload.flattenedSegmentsRead",c),a}function Co(e,t=xe(e)){let n=e.instrumentation;if(n==null)return gl(e,t);return E(n,"store.getVisibleTreeProjection",()=>gl(e,t))}function Il(e){return hf(Co(e))}function Sl(e,t){let n=Le(e,t);if(n==null||n===e.snapshot.rootId)return null;if(D(M(e,n))&&bt(e,n)!==n)return null;let r=0,i=n,{nodes:o,rootId:s}=e.snapshot;while(i!==s){let a=M(e,i).parentId,l=ae(e,a),c=mn(l).get(i);if(c==null)throw Error(`Child ${String(i)} was not found in its parent index`);if(r+=oa(o,l,c),a!==s){let d=M(e,a),f=yt(e,a);if(!Ce(e,a,d)&&f!==i)return null;if(bt(e,a)===a)r+=1}i=a}return r}function Cl(e,t){let n=Le(e,t);if(n==null)throw Error(`Path does not exist: "${t}"`);let r=M(e,n);if(!D(r))throw Error(`Path is not a directory: "${t}"`);if(Ce(e,n,r))return null;return At(e,n,!0,r),Ft(e,n),Wa({affectedAncestorIds:We(e,n),affectedNodeIds:[n],path:t,projectionChanged:!0})}function xl(e,t){let n=Le(e,t);if(n==null)throw Error(`Path does not exist: "${t}"`);let r=M(e,n);if(!D(r))throw Error(`Path is not a directory: "${t}"`);if(!Ce(e,n,r))return null;return At(e,n,!1,r),Ft(e,n),ja({affectedAncestorIds:We(e,n),affectedNodeIds:[n],path:t,projectionChanged:!0})}function pl(e,t){if(t<0||t>=xe(e))return null;return kl(e,e.snapshot.rootId,t,-1)}function kl(e,t,n,r){let i=ae(e,t),o=e.instrumentation,{childIndex:s,localVisibleIndex:a}=o==null?Yr(e.snapshot.nodes,i,n):E(o,"store.getVisibleSlice.selectChildIndex",()=>Yr(e.snapshot.nodes,i,n)),l=i.childIds[s];if(l!=null)return So(e,l,a,r+1);throw Error(`Visible index ${String(n)} is out of range`)}function So(e,t,n,r){if(!D(M(e,t))){if(n===0)return{headNodeId:t,terminalNodeId:t,visibleDepth:r};throw Error(`Visible index ${String(n)} is out of range for file`)}let i=_l(e,t,r);if(n===0)return i;let o=M(e,i.terminalNodeId);if(!D(o)||!Ce(e,i.terminalNodeId,o))throw Error(`Visible index ${String(n)} is out of range for collapsed directory`);return kl(e,i.terminalNodeId,n-1,i.visibleDepth)}function _l(e,t,n){if(!D(M(e,t)))return{headNodeId:t,terminalNodeId:t,visibleDepth:n};if(e.instrumentation==null)return{headNodeId:t,terminalNodeId:bt(e,t),visibleDepth:n};return{headNodeId:t,terminalNodeId:E(e.instrumentation,"store.getVisibleSlice.flatten.resolveTerminalDirectory",()=>bt(e,t)),visibleDepth:n}}function df(e,t){let n=M(e,t);if(!D(n))return!0;let r=n.parentId;if(r===e.snapshot.rootId)return!0;return yt(e,r)!==t}function ml(e,t){let n=M(e,t.terminalNodeId);if(D(n)){let o=ae(e,t.terminalNodeId);if(Ce(e,t.terminalNodeId,n)&&o.childIds.length>0){let s=o.childIds[0];return s==null?null:So(e,s,0,t.visibleDepth+1)}}let{terminalNodeId:r,visibleDepth:i}=t;while(!0){let o=M(e,r);if(r===e.snapshot.rootId)return null;let s=o.parentId,a=ae(e,s),l=mn(a).get(r)??-1;if(l<0)throw Error(`Child ${String(r)} was not found in its parent index`);let c=a.childIds[l+1]??null;if(c!=null)return So(e,c,0,i);if(df(e,r))i--;r=s}}function hf(e){let t=e.paths.length,n=Array(t);for(let r=0;r<t;r+=1){let i=e.getParentIndex(r);n[r]={index:r,parentPath:i>=0?e.paths[i]??null:null,path:e.paths[r]??"",posInSet:e.posInSetByIndex[r]??0,setSize:e.setSizeByIndex[r]??0}}return{getParentIndex:e.getParentIndex,rows:n,get visibleIndexByPath(){return e.visibleIndexByPath}}}function gl(e,t){let n=Array(t),r=new Int32Array(t),i=new Int32Array(t),o=new Int32Array(t),s=new Int32Array(af);s.fill(-1);let a=0,{nodes:l,directories:c,segmentTable:d}=e.snapshot,f=[[c.get(e.snapshot.rootId),0,-1,""]],u=e.snapshot.options.flattenEmptyDirectories,m=e.pathCacheByNodeId,p=e.pathCacheVersion,g=d.valueById;while(f.length>0&&a<t){let w=f[f.length-1],x=w[0];if(w[1]>=x.childIds.length){f.pop();continue}let P=w[1],O=x.childIds[w[1]++],pe=l[O],G=w[2]+1,me=w[3];s=lf(s,G);let j,N=O;if(!D(pe)){let W=m.get(O);j=W!=null&&W.version===p?W.path:`${me}${g[pe.nameId]}`}else N=u?bt(e,O):O,j=N===O?`${me}${g[pe.nameId]}/`:ne(e,N);r[a]=s[G],n[a]=j,i[a]=P,o[a]=x.childIds.length,s[G+1]=a,a+=1;let re=l[N];if(re!=null&&D(re)&&Ce(e,N,re))f.push([c.get(N),0,G,j])}if(a<t)n.length=a;let v=r.subarray(0,a),S=i.subarray(0,a),C=o.subarray(0,a),y=null;return{getParentIndex(w){return w<0||w>=a?-1:v[w]??-1},paths:n,posInSetByIndex:S,setSizeByIndex:C,get visibleIndexByPath(){if(y==null){y=new Map;for(let w=0;w<a;w+=1)y.set(n[w]??"",w)}return y}}}function ff(e,t){let n=Array(t),r=0,{nodes:i,directories:o,segmentTable:s}=e.snapshot,a=[[o.get(e.snapshot.rootId),0,-1]],l=s.valueById,c=e.snapshot.options.flattenEmptyDirectories,d=e.pathCacheByNodeId,f=e.pathCacheVersion;while(a.length>0&&r<t){let u=a[a.length-1],m=u[0];if(u[1]>=m.childIds.length){a.pop();continue}let p=m.childIds[u[1]++],g=i[p],v=u[2]+1;if(!D(g)){let w=d.get(p);n[r++]={depth:v,flattenedSegments:void 0,hasChildren:!1,id:p,isExpanded:!1,isFlattened:!1,isLoading:!1,kind:"file",loadState:void 0,name:l[g.nameId],path:w!=null&&w.version===f?w.path:ne(e,p)};continue}let S=c?bt(e,p):p,C={headNodeId:p,terminalNodeId:S,visibleDepth:v};n[r++]=dr(e,C);let y=i[S];if(y!=null&&D(y)&&Ce(e,S,y))a.push([o.get(S),0,v])}if(r<t)n.length=r;return n}function dr(e,t){let n=M(e,t.terminalNodeId),r=D(n)?pf(e,t):null,i=ne(e,t.terminalNodeId),o=qe(e.snapshot.segmentTable,n.nameId),s=D(n)&&ae(e,t.terminalNodeId).childIds.length>0,a=t.headNodeId!==t.terminalNodeId,l=e.instrumentation,c=a?l==null?bn(e,t.headNodeId).map((d)=>{let f=M(e,d);return{isTerminal:d===t.terminalNodeId,name:qe(e.snapshot.segmentTable,f.nameId),nodeId:d,path:ne(e,d)}}):E(l,"store.getVisibleSlice.flatten.collectSegments",()=>bn(e,t.headNodeId).map((d)=>{let f=M(e,d);return{isTerminal:d===t.terminalNodeId,name:qe(e.snapshot.segmentTable,f.nameId),nodeId:d,path:ne(e,d)}})):void 0;return{depth:t.visibleDepth,flattenedSegments:c,hasChildren:s,id:t.terminalNodeId,isExpanded:D(n)&&Ce(e,t.terminalNodeId,n),isFlattened:a,isLoading:r==="loading",kind:D(n)?"directory":"file",loadState:r==null||r==="loaded"?void 0:r,name:o,path:i}}function pf(e,t){if(t.headNodeId===t.terminalNodeId)return Nt(e,t.terminalNodeId);let n=bn(e,t.headNodeId),r=!1,i=!1;for(let o of n){let s=Nt(e,o);if(s==="loading")return"loading";if(s==="error"){i=!0;continue}if(s==="unloaded")r=!0}if(i)return"error";if(r)return"unloaded";return"loaded"}var El=8;function Tl(e){let{nodes:t,directories:n,rootId:r,options:i}=e,o=t.length,s=new Int32Array(o),a=new Int32Array(o),l=new Int32Array(o),c=new Int32Array(o),d=new Int32Array(o),f=new Int32Array(o),u=new Int32Array(o);for(let v=0;v<o;v+=1){let S=t[v];if(S==null)continue;s[v]=S.parentId,a[v]=S.nameId,l[v]=S.depthAndFlags,c[v]=S.subtreeNodeCount,d[v]=S.visibleSubtreeCount}let m=0;for(let v of n.values())m+=v.childIds.length;let p=new Int32Array(m),g=0;for(let[v,S]of n){let C=S.childIds;f[v]=g,u[v]=C.length;for(let y=0;y<C.length;y+=1)p[g]=C[y],g+=1}return{nodeCount:o,rootId:r,flattenEmptyDirectories:i.flattenEmptyDirectories===!0,parentId:s,nameId:a,depthAndFlags:l,subtreeNodeCount:c,visibleSubtreeCount:d,childStart:f,childCount:u,childIdsFlat:p}}function Pl(e){let{nodeCount:t,rootId:n,flattenEmptyDirectories:r,depthAndFlags:i,subtreeNodeCount:o,visibleSubtreeCount:s,childStart:a,childCount:l,childIdsFlat:c}=e;for(let p=t-1;p>=1;p-=1){if((i[p]&El)===0)continue;let g=a[p],v=l[p],S=0,C=0;for(let w=0;w<v;w+=1){let x=c[g+w];S+=o[x],C+=s[x]}o[p]=1+S;let y;if(r&&v===1)y=(i[c[g]]&El)!==0?C:1+C;else y=1+C;s[p]=y}let d=a[n],f=l[n],u=0,m=0;for(let p=0;p<f;p+=1){let g=c[d+p];u+=o[g],m+=s[g]}o[n]=1+u,s[n]=m}function mf(e){let{directories:t,nodes:n,options:r,rootId:i,presortedDirectoryNodeIds:o}=e.snapshot,s=r.flattenEmptyDirectories===!0,a=(m)=>{let p=n[m];if(p==null||!D(p))return;let g=t.get(m);if(g==null)throw Error(`Unknown directory child index for node ${String(m)}`);let v=g.childIds,S=v.length,C=0,y=0;for(let x=0;x<S;x++){let P=v[x];if(P==null)continue;let O=n[P];C+=O.subtreeNodeCount,y+=O.visibleSubtreeCount}if(g.totalChildSubtreeNodeCount=C,g.totalChildVisibleSubtreeCount=y,S>=128)Mt(n,g);p.subtreeNodeCount=1+C;let w;if(s&&S===1){let x=n[v[0]];w=x!=null&&D(x)?y:1+y}else w=1+y;p.visibleSubtreeCount=w};if(o!=null)for(let m=o.length-1;m>=0;m--)a(o[m]);else for(let m=n.length-1;m>=1;m--)a(m);let l=n[i],c=t.get(i);if(l==null||c==null)return;let d=c.childIds,f=0,u=0;for(let m=0;m<d.length;m++){let p=d[m];if(p==null)continue;let g=n[p];f+=g.subtreeNodeCount,u+=g.visibleSubtreeCount}c.totalChildSubtreeNodeCount=f,c.totalChildVisibleSubtreeCount=u,Mt(n,c),l.subtreeNodeCount=1+f,l.visibleSubtreeCount=u}function gf(e){let{directories:t,nodes:n,rootId:r}=e.snapshot,i=Tl(e.snapshot);Pl(i);let{subtreeNodeCount:o,visibleSubtreeCount:s}=i;for(let a=0;a<n.length;a+=1){let l=n[a];if(l==null)continue;l.subtreeNodeCount=o[a],l.visibleSubtreeCount=s[a]}for(let[a,l]of t){let c=l.childIds,d=c.length,f=0,u=0;for(let m=0;m<d;m++){let p=c[m];if(p==null)continue;let g=n[p];f+=g.subtreeNodeCount,u+=g.visibleSubtreeCount}if(l.totalChildSubtreeNodeCount=f,l.totalChildVisibleSubtreeCount=u,a===r||d>=128)Mt(n,l)}}function vf(e){return e.initialExpansion==="open"&&(e.initialExpandedPaths==null||e.initialExpandedPaths.length===0)}var hr=class e{#e;constructor(t={}){let n=ar(t),r=E(n,"store.builder.create",()=>new ei(t));if(t.preparedInput!=null){let a=Ca(t.preparedInput);if(a!=null)r.appendPresortedPaths(a,xa(t.preparedInput));else r.appendPreparedPaths(Sa(t.preparedInput),!1)}else{let a=t.paths??[];if(t.presorted===!0)r.appendPaths(a);else r.appendPreparedPaths(E(n,"store.preparePathEntries",()=>Zr(a,t)))}let i=E(n,"store.builder.finish",()=>r.finish({skipSubtreeCountPass:!0})),o=E(n,"store.state.detectAllDirectoriesExpanded",()=>(t.initialExpansion??"closed")==="closed"&&r.didMatchAllInitialExpandedPaths());if(this.#e=E(n,"store.state.create",()=>ka(i,o?"open":t.initialExpansion??"closed",n)),o)this.#e.collapseNewDirectoriesByDefault=!0;let s=o?this.#e.snapshot.directories.size-1:E(n,"store.state.initializeExpandedPaths",()=>this.initializeExpandedPaths(t.initialExpandedPaths));if(o||vf(t)||(t.initialExpansion??"closed")==="closed"&&s===this.#e.snapshot.directories.size-1||(t.initialExpandedPaths?.length??0)>0&&E(n,"store.state.checkAllDirectoriesExpanded",()=>this.hasAllDirectoriesExpanded()))if(t.useSoaCountSweep===!0)E(n,"store.state.initializeOpenVisibleCountsViaSoa",()=>gf(this.#e));else E(n,"store.state.initializeOpenVisibleCounts",()=>mf(this.#e));else E(n,"store.state.recomputeCounts",()=>ur(this.#e,this.#e.snapshot.rootId))}static preparePaths(t,n={}){return ba(t,n)}static prepareInput(t,n={}){return wa(t,n)}static preparePresortedInput(t){return Ia(t)}list(t){return E(this.#e.instrumentation,"store.list",()=>ti(this.#e,t))}add(t){E(this.#e.instrumentation,"store.add",()=>{let n=xe(this.#e);Xe(this.#e,Ne(this.#e,n,go(this.#e,t)))})}remove(t,n={}){E(this.#e.instrumentation,"store.remove",()=>{let r=xe(this.#e);Xe(this.#e,Ne(this.#e,r,vo(this.#e,t,n)))})}move(t,n,r={}){E(this.#e.instrumentation,"store.move",()=>{let i=xe(this.#e),o=yo(this.#e,t,n,r);if(o!=null)Xe(this.#e,Ne(this.#e,i,o))})}batch(t){Qa(this.#e,()=>{if(typeof t==="function"){t(this);return}for(let n of t)switch(n.type){case"add":this.add(n.path);break;case"remove":this.remove(n.path,{recursive:n.recursive});break;case"move":this.move(n.from,n.to,{collision:n.collision});break}})}getVisibleCount(){return E(this.#e.instrumentation,"store.getVisibleCount",()=>xe(this.#e))}getVisibleSlice(t,n){return E(this.#e.instrumentation,"store.getVisibleSlice",()=>wl(this.#e,t,n))}getVisibleRowContext(t){return E(this.#e.instrumentation,"store.getVisibleRowContext",()=>bl(this.#e,t))}getVisibleTreeProjection(){return Il(this.#e)}getVisibleTreeProjectionData(t){return Co(this.#e,t)}getVisibleIndex(t){return E(this.#e.instrumentation,"store.getVisibleIndex",()=>Sl(this.#e,t))}getPathInfo(t){return E(this.#e.instrumentation,"store.getPathInfo",()=>{let n=Le(this.#e,t);if(n==null)return null;let r=M(this.#e,n);return{depth:Ve(r),kind:D(r)?"directory":"file",path:ne(this.#e,n)}})}isExpanded(t){return E(this.#e.instrumentation,"store.isExpanded",()=>{let n=this.requireDirectoryNodeId(t),r=M(this.#e,n);return Ce(this.#e,n,r)})}expand(t){E(this.#e.instrumentation,"store.expand",()=>{let n=xe(this.#e),r=Cl(this.#e,t);if(r!=null)Xe(this.#e,Ne(this.#e,n,r))})}collapse(t){E(this.#e.instrumentation,"store.collapse",()=>{let n=xe(this.#e),r=xl(this.#e,t);if(r!=null)Xe(this.#e,Ne(this.#e,n,r))})}on(t,n){return Va(this.#e,t,n)}getDirectoryLoadState(t){let n=this.requireDirectoryNodeId(t);return Nt(this.#e,n)}markDirectoryUnloaded(t){E(this.#e.instrumentation,"store.markDirectoryUnloaded",()=>{let n=this.requireDirectoryNodeId(t);if(ae(this.#e,n).childIds.length>0)throw Error(`Cannot mark a directory with known children as unloaded: "${t}"`);let r=xe(this.#e);Ra(this.#e,n),Xe(this.#e,Ne(this.#e,r,$a({affectedAncestorIds:We(this.#e,n),affectedNodeIds:[n],path:t,projectionChanged:this.isDirectoryProjectionVisible(n)})))})}beginChildLoad(t){return E(this.#e.instrumentation,"store.beginChildLoad",()=>{let n=this.requireDirectoryNodeId(t),r=xe(this.#e),i=Pa(this.#e,n);return Xe(this.#e,Ne(this.#e,r,Ua({affectedAncestorIds:We(this.#e,n),affectedNodeIds:[n],attemptId:i.attemptId,path:t,projectionChanged:this.isDirectoryProjectionVisible(n),reused:i.reused}))),i})}applyChildPatch(t,n){return E(this.#e.instrumentation,"store.applyChildPatch",()=>{let r=this.resolveActiveDirectoryNodeId(t.nodeId);if(r==null||Nt(this.#e,r)!=="loading"||!Ma(this.#e,r,t.attemptId))return!1;let i=ne(this.#e,r);this.validateChildPatch(i,n);let o=xe(this.#e),s=[];for(let l of n.operations){yf(i,l);let c=xe(this.#e);switch(l.type){case"add":s.push(Ne(this.#e,c,go(this.#e,l.path)));break;case"remove":s.push(Ne(this.#e,c,vo(this.#e,l.path,{recursive:l.recursive})));break;case"move":{let d=yo(this.#e,l.from,l.to,{collision:l.collision});if(d!=null)s.push(Ne(this.#e,c,d));break}}}let a=s.some((l)=>l.projectionChanged)||this.isDirectoryProjectionVisible(r);return Xe(this.#e,Ne(this.#e,o,Ka({affectedAncestorIds:We(this.#e,r),affectedNodeIds:[r],attemptId:t.attemptId,childEvents:s,path:ne(this.#e,r),projectionChanged:a}))),!0})}completeChildLoad(t){return E(this.#e.instrumentation,"store.completeChildLoad",()=>{let n=this.resolveActiveDirectoryNodeId(t.nodeId);if(n==null)return!1;let r=xe(this.#e),i=Da(this.#e,n,t.attemptId);return Xe(this.#e,Ne(this.#e,r,Ga({affectedAncestorIds:We(this.#e,n),affectedNodeIds:[n],attemptId:t.attemptId,path:ne(this.#e,n),projectionChanged:this.isDirectoryProjectionVisible(n),stale:!i}))),i})}failChildLoad(t,n){return E(this.#e.instrumentation,"store.failChildLoad",()=>{let r=this.resolveActiveDirectoryNodeId(t.nodeId);if(r==null)return!1;let i=xe(this.#e),o=Aa(this.#e,r,t.attemptId,n);return Xe(this.#e,Ne(this.#e,i,Ya({affectedAncestorIds:We(this.#e,r),affectedNodeIds:[r],attemptId:t.attemptId,errorMessage:n,path:ne(this.#e,r),projectionChanged:this.isDirectoryProjectionVisible(r),stale:!o}))),o})}cleanup(t={}){return E(this.#e.instrumentation,"store.cleanup",()=>{if(this.#e.transactionStack.length>0)throw Error("Cleanup cannot run during an open batch or transaction.");if(hl(this.#e))throw Error("Cleanup cannot run while directory loads are active.");let n=xe(this.#e),r=fl(this.#e,t.mode??"stable");return Xe(this.#e,Ne(this.#e,n,Xa({...r,affectedAncestorIds:[],affectedNodeIds:[],projectionChanged:r.idsPreserved===!1}))),r})}getNodeCount(){return this.#e.activeNodeCount}initializeExpandedPaths(t){if(t==null||t.length===0)return 0;let n=0,r=[],i=[],o=0,s=null,a=this.#e.snapshot.segmentTable,l=a.valueById,c=this.#e.snapshot.nodes,d=new Map;for(let f of t){if(s!=null&&f<s)s=null,o=0,r.length=0,i.length=0;let u=f.length>0&&f.charCodeAt(f.length-1)===47?f.length-1:f.length;if(u===0){s=f,o=u,r.length=0,i.length=0;continue}let m=0,p=0;if(s!=null){let y=Math.min(u,o),w=!0;for(let x=0;x<y;x+=1){let P=f.charCodeAt(x);if(P!==s.charCodeAt(x)){w=!1;break}if(P===47)m+=1,p=x+1}if(w){if(y===o&&u>y&&f.charCodeAt(y)===47)m+=1,p=y+1;else if(y===u&&o>y&&s.charCodeAt(y)===47)m+=1,p=u+1}m=Math.min(m,i.length)}let g=m===0?this.#e.snapshot.rootId:i[m-1]??this.#e.snapshot.rootId,v=m,S=!0,C=p;while(C<=u){let y=f.indexOf("/",C),w=y===-1||y>u?u:y,x=f.slice(C,w),P=ae(this.#e,g).childIds,O=v===m?r[v]??0:0,pe=O,G,me=d.get(x)??Xt(x);d.set(x,me);let j=(N,re)=>{for(pe=N;pe<re;pe+=1){let W=P[pe],Ee=c[W],U=l[Ee.nameId];if(U===x)return G=W,!0;let de=lr(cr(a,Ee.nameId),me);if(de>0||de===0&&U>x)return!1}return!1};if(!j(O,P.length)&&O>0)j(0,O);if(G===void 0){S=!1;break}if(!D(M(this.#e,G))){S=!1;break}if(r[v]=pe,i[v]=G,g=G,v+=1,w===u)break;C=w+1}if(s=f,o=u,r.length=v,i.length=v,!S){s=null,o=0,r.length=0,i.length=0;continue}for(let y=m;y<v;y+=1){let w=i[y];if(w==null)continue;let x=M(this.#e,w);if(Ce(this.#e,w,x))continue;At(this.#e,w,!0,x),n+=1}}return n}hasAllDirectoriesExpanded(){for(let t of this.#e.snapshot.directories.keys()){if(t===this.#e.snapshot.rootId)continue;let n=M(this.#e,t);if(!Ce(this.#e,t,n))return!1}return!0}requireDirectoryNodeId(t){let n=Le(this.#e,t);if(n==null)throw Error(`Path does not exist: "${t}"`);if(!D(M(this.#e,n)))throw Error(`Path is not a directory: "${t}"`);return n}resolveActiveDirectoryNodeId(t){try{if(!D(M(this.#e,t)))throw Error(`Node is not a directory: ${String(t)}`);return t}catch{return null}}isDirectoryProjectionVisible(t){let n=t;while(n!==this.#e.snapshot.rootId){let r=M(this.#e,n).parentId;if(r!==this.#e.snapshot.rootId){let i=M(this.#e,r),o=yt(this.#e,r);if(!Ce(this.#e,r,i)&&o!==n)return!1}n=r}return!0}validateChildPatch(t,n){new e({paths:this.list(t),presorted:!0,sort:this.#e.snapshot.options.sort}).batch(n.operations)}};function yf(e,t){switch(t.type){case"add":case"remove":if(!t.path.startsWith(e)||t.path===e)throw Error(`Child patch operation must stay within ${e}: "${t.path}"`);break;case"move":if(!t.from.startsWith(e)||!t.to.startsWith(e)||t.from===e||t.to===e)throw Error(`Child patch move must stay within ${e}: "${t.from}" -> "${t.to}"`);break}}var bf=[`<symbol id="file-tree-builtin-bash" viewBox="0 0 16 16">
|
|
1
|
+
import{A as vs,a as sd,b as zr,c as $s,d as Us,e as qr,f as Js,g as Ks,h as Gs,i as Ji,l as Zs,m as ea,n as to,o as no,p as ro,q as Kr,r as ta,s as Nu,t as na,u as io,v as ir,w as ra,x as ad,y as ld,z as Cr}from"./main-r8cn68g6.js";import{O as Qi,ka as Ur,la as Zi,ma as eo}from"./main-7fchxg57.js";import{Pb as B,Qb as hs,Rb as Ci,Sb as xr,Tb as Sr,Ub as xu,Vb as en}from"./main-3kywnyz0.js";import{cc as Sh,dc as Ih,fc as fm}from"./main-x61973bh.js";var Xs=Ih(function(Wr,Ys){(function(e,t){typeof Wr=="object"&&typeof Ys<"u"?t(Wr):typeof define=="function"&&define.amd?define(["exports"],t):t((e=e||self).lru_map=e.lru_map||{})})(Wr,function(e){let t=Symbol("newer"),n=Symbol("older");class r{constructor(l,c){typeof l!=="number"&&(c=l,l=0),this.size=0,this.limit=l,this.oldest=this.newest=void 0,this._keymap=new Map,c&&(this.assign(c),l<1&&(this.limit=this.size))}_markEntryAsUsed(l){if(l===this.newest)return;l[t]&&(l===this.oldest&&(this.oldest=l[t]),l[t][n]=l[n]),l[n]&&(l[n][t]=l[t]),l[t]=void 0,l[n]=this.newest,this.newest&&(this.newest[t]=l),this.newest=l}assign(l){let c,d=this.limit||Number.MAX_VALUE;this._keymap.clear();let f=l[Symbol.iterator]();for(let u=f.next();!u.done;u=f.next()){let m=new i(u.value[0],u.value[1]);if(this._keymap.set(m.key,m),c?(c[t]=m,m[n]=c):this.oldest=m,c=m,d--==0)throw Error("overflow")}this.newest=c,this.size=this._keymap.size}get(l){var c=this._keymap.get(l);return c?(this._markEntryAsUsed(c),c.value):void 0}set(l,c){var d=this._keymap.get(l);return d?(d.value=c,this._markEntryAsUsed(d),this):(this._keymap.set(l,d=new i(l,c)),this.newest?(this.newest[t]=d,d[n]=this.newest):this.oldest=d,this.newest=d,++this.size,this.size>this.limit&&this.shift(),this)}shift(){var l=this.oldest;if(l)return this.oldest[t]?(this.oldest=this.oldest[t],this.oldest[n]=void 0):(this.oldest=void 0,this.newest=void 0),l[t]=l[n]=void 0,this._keymap.delete(l.key),--this.size,[l.key,l.value]}find(l){let c=this._keymap.get(l);return c?c.value:void 0}has(l){return this._keymap.has(l)}delete(l){var c=this._keymap.get(l);return c?(this._keymap.delete(c.key),c[t]&&c[n]?(c[n][t]=c[t],c[t][n]=c[n]):c[t]?(c[t][n]=void 0,this.oldest=c[t]):c[n]?(c[n][t]=void 0,this.newest=c[n]):this.oldest=this.newest=void 0,this.size--,c.value):void 0}clear(){this.oldest=this.newest=void 0,this.size=0,this._keymap.clear()}keys(){return new s(this.oldest)}values(){return new a(this.oldest)}entries(){return this}[Symbol.iterator](){return new o(this.oldest)}forEach(l,c){typeof c!=="object"&&(c=this);let d=this.oldest;for(;d;)l.call(c,d.value,d.key,this),d=d[t]}toJSON(){for(var l=Array(this.size),c=0,d=this.oldest;d;)l[c++]={key:d.key,value:d.value},d=d[t];return l}toString(){for(var l="",c=this.oldest;c;)l+=String(c.key)+":"+c.value,c=c[t],c&&(l+=" < ");return l}}e.LRUMap=r;function i(l,c){this.key=l,this.value=c,this[t]=void 0,this[n]=void 0}function o(l){this.entry=l}o.prototype[Symbol.iterator]=function(){return this},o.prototype.next=function(){let l=this.entry;return l?(this.entry=l[t],{done:!1,value:[l.key,l.value]}):{done:!0,value:void 0}};function s(l){this.entry=l}s.prototype[Symbol.iterator]=function(){return this},s.prototype.next=function(){let l=this.entry;return l?(this.entry=l[t],{done:!1,value:l.key}):{done:!0,value:void 0}};function a(l){this.entry=l}a.prototype[Symbol.iterator]=function(){return this},a.prototype.next=function(){let l=this.entry;return l?(this.entry=l[t],{done:!1,value:l.value}):{done:!0,value:void 0}}})});function ji(e){let t=[];for(let n of e){let r=zr.get(n);if(r==null)throw Error(`getResolvedLanguages: ${n} is not resolved. Please resolve languages before calling getResolvedLanguages`);t.push(r)}return t}function $i(e){for(let t of Array.isArray(e)?e:[e])if(!zr.has(t))return!1;return!0}async function Ui(e){let t=[],n=[];for(let r of e){if(r==="text"||r==="ansi")continue;let i=Us(r)??$s(r);if("then"in i)n.push(i);else t.push(i)}if(n.length>0)await Promise.all(n).then((r)=>{for(let i of r){if(i==null)throw Error("resolvedLanguages: unable to resolve language");t.push(i)}});return t}function Ki(e){return qr.getResolvedThemes(e)}async function Gi(e){for(let n of e)Ks(n);let t=await qr.resolveThemes(e);for(let n=0;n<e.length;n++)Gs(e[n],t[n]);return t}var oo=Sh(Xs(),1),jr=Symbol("IGNORE_RESPONSE"),$r=class extends Error{constructor(){super("WorkerPoolManager: operation canceled because the pool terminated")}},Yi=class extends Error{constructor(){super("WorkerPoolManager: operation canceled before the task completed")}},ia=class{options;highlighter;preferredHighlighter;renderOptions;renderOptionsRequestVersion=0;renderOptionsVersion=0;initialized=!1;workers=[];queuedTasks=[];queuedTaskByInstance=new Map;taskByHighlightKey=new Map;activeTaskById=new Map;activeRequestByInstance=new Map;nextRequestId=0;themeSubscribers=new Set;workersFailed=!1;statSubscribers=new Set;fileCache;diffCache;_queuedBroadcast;lifecycleGeneration=0;constructor(e,{langs:t,theme:n=Qi,useTokenTransformer:r=!1,lineDiffType:i="word-alt",maxLineDiffLength:o=1000,tokenizeMaxLineLength:s=1000,preferredHighlighter:a="shiki-js"}){this.options=e,this.preferredHighlighter=a,this.renderOptions={theme:n,useTokenTransformer:r,lineDiffType:i,maxLineDiffLength:o,tokenizeMaxLineLength:s},this.fileCache=new oo.default.LRUMap(e.totalASTLRUCacheSize??100),this.diffCache=new oo.default.LRUMap(e.totalASTLRUCacheSize??100),this.queueInitialization(t)}isWorkingPool(){return!this.workersFailed}getFileResultCache(e){return e.cacheKey!=null?this.fileCache.get(e.cacheKey):void 0}getDiffResultCache(e){return e.cacheKey!=null?this.diffCache.get(e.cacheKey):void 0}inspectCaches(){let{fileCache:e,diffCache:t}=this;return{fileCache:e,diffCache:t}}evictFileFromCache(e){try{return this.fileCache.delete(e)!==void 0}finally{this.queueBroadcastStateChanges()}}evictDiffFromCache(e){try{return this.diffCache.delete(e)!==void 0}finally{this.queueBroadcastStateChanges()}}async setRenderOptions({theme:e=this.renderOptions.theme??Qi,useTokenTransformer:t=this.renderOptions.useTokenTransformer??!1,lineDiffType:n=this.renderOptions.lineDiffType??"word-alt",maxLineDiffLength:r=this.renderOptions.maxLineDiffLength??1000,tokenizeMaxLineLength:i=this.renderOptions.tokenizeMaxLineLength??1000}){let{lifecycleGeneration:o}=this,s=++this.renderOptionsRequestVersion,a=()=>this.isCurrentLifecycle(o)&&this.renderOptionsRequestVersion===s;try{let l={theme:e,useTokenTransformer:t,lineDiffType:n,maxLineDiffLength:r,tokenizeMaxLineLength:i};if(!this.isInitialized())await this.initialize();if(!a()||ir(l,this.renderOptions))return;let c=no(e),d=[];if(!Zs(l.theme,this.renderOptions.theme))if(ro(c))d=Ki(c);else d=await Gi(c);if(!a())return;if(this.highlighter!=null)Js(d,this.highlighter);else{let u=await Ji({themes:c,langs:["text"],preferredHighlighter:this.preferredHighlighter});if(!a())return;this.highlighter=u}let f=this.setRenderOptionsOnWorkers(l,d);this.renderOptions=l,this.renderOptionsVersion++,this.diffCache.clear(),this.fileCache.clear(),this.invalidateRenderTasks();for(let u of this.themeSubscribers)u.onThemeChange();await f}catch(l){if(l instanceof $r||!a())return;throw l}}getPreferredHighlighter(){return this.preferredHighlighter}getFileRenderOptions(){let{tokenizeMaxLineLength:e,theme:t,useTokenTransformer:n}=this.renderOptions;return{theme:t,useTokenTransformer:n,tokenizeMaxLineLength:e}}getDiffRenderOptions(){return{...this.renderOptions}}async setRenderOptionsOnWorkers(e,t){if(this.workersFailed)return;if(!this.isInitialized())await this.initialize();let n=[];for(let r of this.workers){if(!r.initialized)throw console.log({managedWorker:r}),Error("setRenderOptionsOnWorkers: Somehow we have an uninitialized worker");n.push(new Promise((i,o)=>{let s=this.generateRequestId(),a={type:"set-render-options",id:s,request:{type:"set-render-options",id:s,renderOptions:e,resolvedThemes:t},resolve:i,reject:o,requestStart:Date.now()};this.activeTaskById.set(s,a),r.pendingSetupRequestId=s,r.worker.postMessage(a.request)}))}await Promise.all(n)}subscribeToThemeChanges(e){return this.themeSubscribers.add(e),this.queueBroadcastStateChanges(),()=>{this.unsubscribeToThemeChanges(e),this.queueBroadcastStateChanges()}}unsubscribeToThemeChanges(e){this.themeSubscribers.delete(e),this.queueBroadcastStateChanges()}subscribeToStatChanges(e){return this.statSubscribers.add(e),e(this.getStats()),()=>{this.statSubscribers.delete(e)}}queueBroadcastStateChanges(){if(this._queuedBroadcast!=null)return;this._queuedBroadcast=requestAnimationFrame(this._broadcastStateChanges)}_broadcastStateChanges=()=>{if(this._queuedBroadcast!=null)cancelAnimationFrame(this._queuedBroadcast),this._queuedBroadcast=void 0;let e=this.getStats();for(let t of this.statSubscribers)t(e)};cleanUpTasks(e){this.detachInstanceFromQueuedTasks(e);let t=this.activeRequestByInstance.get(e);if(t!=null){let n=this.activeTaskById.get(t);if(Rt(n)){if(this.detachInstanceFromRenderTask(n,e),!n.primeCache&&n.instances.size===0)this.removeActiveTask(n)}else this.activeTaskById.delete(t)}this.activeRequestByInstance.delete(e),this.queueBroadcastStateChanges()}isInitialized(){return this.initialized===!0}async initialize(e=[]){if(this.initialized===!0)return;else if(this.initialized===!1){let{lifecycleGeneration:t}=this;this.initialized=new Promise((n,r)=>{(async()=>{try{let i=no(this.renderOptions.theme),o=[];if(ro(i))o=Ki(i);else o=await Gi(i);if(!this.isCurrentLifecycle(t)){n();return}let s=[];if($i(e))s=ji(e);else s=await Ui(e);if(!this.isCurrentLifecycle(t)){n();return}let[a]=await Promise.all([Ji({themes:i,langs:["text",...e],preferredHighlighter:this.preferredHighlighter}),this.initializeWorkers(o,s)]);if(!this.isCurrentLifecycle(t)){this.terminateWorkers(),n();return}this.highlighter=a,this.initialized=!0,this.diffCache.clear(),this.fileCache.clear(),this.drainQueue(),this.queueBroadcastStateChanges(),n()}catch(i){if(i instanceof $r||!this.isCurrentLifecycle(t)){n();return}this.initialized=!1,this.workersFailed=!0;for(let o of this.queuedTasks)this.rejectRenderTaskCallbacks(o,Xi(i));this.queueBroadcastStateChanges(),r(i)}})()}),this.queueBroadcastStateChanges()}else return this.initialized}async initializeWorkers(e,t){this.workersFailed=!1;let n=[],r=Zi(),i=r>0?eo():void 0;if(this.workers.length>0)this.terminateWorkers();for(let o=0;o<(this.options.poolSize??8);o++){let s=this.options.workerFactory(),a={worker:s,requestId:void 0,pendingSetupRequestId:void 0,initialized:!1,langs:new Set(["text",...t.map(({name:l})=>l)]),customExtensionsVersion:0};s.addEventListener("message",(l)=>{this.handleWorkerMessage(a,l.data)}),s.addEventListener("error",(l)=>console.error("Worker error:",l,a)),this.workers.push(a),n.push(new Promise((l,c)=>{let d=this.generateRequestId(),f={type:"initialize",id:d,request:{type:"initialize",id:d,renderOptions:this.renderOptions,preferredHighlighter:this.preferredHighlighter,resolvedThemes:e,resolvedLanguages:t,customExtensionsVersion:i!=null?r:void 0,customExtensionMap:i},resolve(){a.initialized=!0,l()},reject:c,requestStart:Date.now()};this.activeTaskById.set(d,f),this.executeTask(a,f)}))}await Promise.all(n)}drainQueue=()=>{if(this._queuedDrain=void 0,this.initialized!==!0||this.queuedTasks.length===0)return;for(let e=0;e<this.queuedTasks.length;){let t=this.queuedTasks[e];if(this.hasActiveRequest(t)){e++;continue}let n=Qs(t),r=this.getAvailableWorker(n);if(r==null)break;this.queuedTasks.splice(e,1),this.assignWorkerToTask(t,r),this.resolveLanguagesAndExecuteTask(r,t,n)}this.queueBroadcastStateChanges()};highlightFileAST(e,t){let n=this.getFileResultCache(t);if(to(t)||n!=null&&Kr(n.options,this.getFileRenderOptions()))return;if(!this.hasMatchingFileInstanceTask(e,t))this.submitTask(e,{type:"file",file:t})}primeFileHighlightCache(e){if(!this.isWorkingPool())return Promise.reject(Error("WorkerPoolManager.primeFileHighlightCache: worker pool is not working"));let t=this.getOrCreateFileHighlightCacheTask(e);return t!=null?this.createRenderTaskCallbacks(t):Promise.resolve()}getOrCreateFileHighlightCacheTask(e){if(e.cacheKey==null){console.warn(`WorkerPoolManager.primeFileHighlightCache: priming highlight cache requires file.cacheKey; skipping "${e.name}".`);return}let t=this.getFileResultCache(e),n=this.getFileHighlightKey(e);if(n==null||to(e)||t!=null&&Kr(t.options,this.getFileRenderOptions()))return;let r=this.getTaskByHighlightKey(n);if(r!=null)return r.primeCache=!0,r.type==="file"?r:void 0;else{let i=this.submitCacheTask({type:"file",file:e},n);return i.type==="file"?i:void 0}}getPlainFileAST(e,t,n,r){if(this.highlighter==null){this.queueInitialization();return}return ta(e,this.highlighter,this.renderOptions,{forcePlainText:!0,startingLine:t,totalLines:n,lines:r})}highlightDiffAST(e,t){let n=this.getDiffResultCache(t);if(io(t)||n!=null&&ir(n.options,this.getDiffRenderOptions()))return;if(!this.hasMatchingDiffInstanceTask(e,t))this.submitTask(e,{type:"diff",diff:t})}primeDiffHighlightCache(e){if(!this.isWorkingPool())return Promise.reject(Error("WorkerPoolManager.primeDiffHighlightCache: worker pool is not working"));let t=this.getOrCreateDiffHighlightCacheTask(e);return t!=null?this.createRenderTaskCallbacks(t):Promise.resolve()}getOrCreateDiffHighlightCacheTask(e){if(e.cacheKey==null){console.warn(`WorkerPoolManager.primeDiffHighlightCache: priming highlight cache requires diff.cacheKey; skipping "${e.prevName??e.name}" -> "${e.name}".`);return}let t=this.getDiffResultCache(e),n=this.getDiffHighlightKey(e);if(n==null||io(e)||t!=null&&ir(t.options,this.getDiffRenderOptions()))return;let r=this.getTaskByHighlightKey(n);if(r!=null)return r.primeCache=!0,r.type==="diff"?r:void 0;else{let i=this.submitCacheTask({type:"diff",diff:e},n);return i.type==="diff"?i:void 0}}getPlainDiffAST(e,t,n,r,i){return this.highlighter!=null?ra(e,this.highlighter,this.renderOptions,{forcePlainText:!0,startingLine:t,totalLines:n,expandedHunks:r,collapsedContextThreshold:i}):void 0}terminate(){this.lifecycleGeneration++,this.cancelActiveWorkerTasks(),this.terminateWorkers();let e=new $r;for(let t of this.queuedTasks)this.rejectRenderTaskCallbacks(t,e);this.fileCache.clear(),this.diffCache.clear(),this.activeRequestByInstance.clear(),this.queuedTasks.length=0,this.queuedTaskByInstance.clear(),this.taskByHighlightKey.clear(),this.activeTaskById.clear(),this.highlighter=void 0,this.initialized=!1,this.workersFailed=!1,this.queueBroadcastStateChanges()}isCurrentLifecycle(e){return this.lifecycleGeneration===e}queueInitialization(e){this.initialize(e).catch((t)=>{console.error(t)})}cancelActiveWorkerTasks(){let e=new $r;for(let t of this.activeTaskById.values())if("reject"in t)t.reject(e);else if(Rt(t))this.rejectRenderTaskCallbacks(t,e)}terminateWorkers(){for(let e of this.workers)e.worker.terminate();this.workers.length=0}getStats(){return{managerState:(()=>{if(this.initialized===!1)return"waiting";if(this.initialized!==!0)return"initializing";return"initialized"})(),totalWorkers:this.workers.length,workersFailed:this.workersFailed,busyWorkers:this.workers.filter((e)=>e.requestId!=null||e.pendingSetupRequestId!=null).length,queuedTasks:this.queuedTasks.length,activeTasks:this.activeTaskById.size,themeSubscribers:this.themeSubscribers.size,fileCacheSize:this.fileCache.size,diffCacheSize:this.diffCache.size}}submitTask(e,t){if(this.initialized===!1)this.queueInitialization();let n=this.getHighlightKeyForRequest(t),r=n!=null?this.getTaskByHighlightKey(n):void 0;if(r!=null){this.detachInstanceFromQueuedTasks(e,r),this.addInstanceToTask(r,e),this.queueBroadcastStateChanges();return}this.detachInstanceFromQueuedTasks(e);let i=this.generateRequestId(),o=Date.now(),{renderOptionsVersion:s}=this,a=(()=>{switch(t.type){case"file":return{type:"file",id:i,request:{...t,id:i},instances:new Set([e]),primeCache:!1,highlightKey:n,callbacks:new Set,renderOptionsVersion:s,requestStart:o};case"diff":return{type:"diff",id:i,request:{...t,id:i},instances:new Set([e]),primeCache:!1,highlightKey:n,callbacks:new Set,renderOptionsVersion:s,requestStart:o}}})();this.enqueueRenderTask(a,e)}submitCacheTask(e,t){if(this.initialized===!1)this.queueInitialization();let n=this.generateRequestId(),r=Date.now(),{renderOptionsVersion:i}=this,o=(()=>{switch(e.type){case"file":return{type:"file",id:n,request:{...e,id:n},instances:new Set,primeCache:!0,highlightKey:t,callbacks:new Set,renderOptionsVersion:i,requestStart:r};case"diff":return{type:"diff",id:n,request:{...e,id:n},instances:new Set,primeCache:!0,highlightKey:t,callbacks:new Set,renderOptionsVersion:i,requestStart:r}}})();return this.enqueueRenderTask(o),o}enqueueRenderTask(e,t){if(this.queuedTasks.push(e),t!=null)this.queuedTaskByInstance.set(t,e);if(e.highlightKey!=null)this.taskByHighlightKey.set(e.highlightKey,e);this.queueDrain()}async resolveLanguagesAndExecuteTask(e,t,n){try{let r=n.filter((i)=>!e.langs.has(i));if(r.length>0)if($i(r))t.request.resolvedLanguages=ji(r);else t.request.resolvedLanguages=await Ui(r);if(!this.activeTaskById.has(t.id)){if(e.requestId===t.id){if(this.cleanWorkerAndTask(e,t),this.queueBroadcastStateChanges(),this.queuedTasks.length>0)this.queueDrain()}return}this.executeTask(e,t)}catch(r){if(this.rejectRenderTaskCallbacks(t,Xi(r)),this.cleanWorkerAndTask(e,t),this.queueBroadcastStateChanges(),this.queuedTasks.length>0)this.queueDrain()}}handleWorkerMessage(e,t){let n=this.activeTaskById.get(t.id);try{if(n==null)throw jr;else if(t.type==="error"){let r=Error(t.error);if(t.stack)r.stack=t.stack;if("reject"in n)n.reject(r);else if(Rt(n))this.notifyHighlightError(n,r),this.rejectRenderTaskCallbacks(n,r);else throw Error("handleWorkerMessage: unknown task type");throw r}else switch(t.requestType){case"initialize":if(n.type!=="initialize")throw Error("handleWorkerMessage: task/response dont match");this.syncCustomExtensionVersion(e,n.request),n.resolve();break;case"set-render-options":if(n.type!=="set-render-options")throw Error("handleWorkerMessage: task/response dont match");n.resolve();break;case"file":{if(n.type!=="file")throw Error("handleWorkerMessage: task/response dont match");let{result:r,options:i}=t;if(!this.isCurrentRenderTask(n)||!Kr(i,this.getFileRenderOptions()))throw jr;let{request:o}=n;if(this.syncCustomExtensionVersion(e,o),n.cacheKeyAtDispatch!=null)this.fileCache.set(n.cacheKeyAtDispatch,{result:r,options:i});this.resolveRenderTaskCallbacks(n),this.notifyFileInstances(n,r,i);break}case"diff":{if(n.type!=="diff")throw Error("handleWorkerMessage: task/response dont match");let{result:r,options:i}=t;if(!this.isCurrentRenderTask(n)||!ir(i,this.getDiffRenderOptions()))throw jr;let{request:o}=n;if(this.syncCustomExtensionVersion(e,o),n.cacheKeyAtDispatch!=null)this.diffCache.set(n.cacheKeyAtDispatch,{result:r,options:i});this.resolveRenderTaskCallbacks(n),this.notifyDiffInstances(n,r,i);break}}}catch(r){if(r!==jr)console.error(r,n,t)}if(this.cleanWorkerAndTask(e,n,t.id),this.queueBroadcastStateChanges(),this.queuedTasks.length>0)this.queueDrain()}_queuedDrain;queueDrain(){if(this._queuedDrain!=null)return;this._queuedDrain=Promise.resolve().then(this.drainQueue),this.queueBroadcastStateChanges()}assignWorkerToTask(e,t){if(t.requestId=e.id,Rt(e))this.clearQueuedInstanceRequests(e),this.trackInstanceRequests(e);this.activeTaskById.set(e.id,e)}cleanWorkerAndTask(e,t,n=t?.id){if(e.requestId===n)e.requestId=void 0;if(e.pendingSetupRequestId===n)e.pendingSetupRequestId=void 0;if(t!=null){if(Rt(t))this.rejectRenderTaskCallbacks(t,new Yi),this.clearInstanceRequests(t),this.clearHighlightKey(t);this.activeTaskById.delete(t.id)}}executeTask(e,t){if(Ch(t.request))this.maybeAttachCustomExtensions(e,t.request);if(!this.activeTaskById.has(t.id))this.assignWorkerToTask(t,e);for(let n of Qs(t))e.langs.add(n);try{if(t.type==="file")t.cacheKeyAtDispatch=t.request.file.cacheKey;else if(t.type==="diff")t.cacheKeyAtDispatch=t.request.diff.cacheKey;e.worker.postMessage(t.request)}catch(n){if(console.error("Failed to post message to worker:",n),Rt(t))this.notifyHighlightError(t,n),this.rejectRenderTaskCallbacks(t,Xi(n));else if("reject"in t)t.reject(n);if(this.cleanWorkerAndTask(e,t),this.queuedTasks.length>0)this.queueDrain()}this.queueBroadcastStateChanges()}maybeAttachCustomExtensions(e,t){if(t.customExtensionsVersion!=null)return;let n=Zi();if(e.customExtensionsVersion>=n)return;t.customExtensionsVersion=n,t.customExtensionMap=eo()}syncCustomExtensionVersion(e,t){if(t.customExtensionsVersion==null)return;e.customExtensionsVersion=t.customExtensionsVersion}getAvailableWorker(e){let t;for(let n of this.workers){if(n.requestId!=null||n.pendingSetupRequestId!=null||!n.initialized)continue;if(t=n,e.length===0)break;let r=!0;for(let i of e)if(!n.langs.has(i)){r=!1;break}if(r)break}return t}getFileHighlightKey(e){if(e.cacheKey==null)return;return`file:${e.cacheKey}:${this.renderOptionsVersion}`}getDiffHighlightKey(e){if(e.cacheKey==null)return;return`diff:${e.cacheKey}:${this.renderOptionsVersion}`}getHighlightKeyForRequest(e){switch(e.type){case"file":return this.getFileHighlightKey(e.file);case"diff":return this.getDiffHighlightKey(e.diff)}}hasActiveRequest(e){for(let t of rr(e))if(this.activeRequestByInstance.has(t))return!0;return!1}addInstanceToTask(e,t){if(e.type==="file")e.instances.add(t);else e.instances.add(t);if(this.activeTaskById.has(e.id))this.activeRequestByInstance.set(t,e.id);else this.queuedTaskByInstance.set(t,e)}detachInstanceFromQueuedTasks(e,t){let n=this.queuedTaskByInstance.get(e);if(n==null||n===t)return;if(this.queuedTaskByInstance.delete(e),this.detachInstanceFromRenderTask(n,e),!n.primeCache&&n.instances.size===0)this.removeQueuedTask(n)}detachInstanceFromRenderTask(e,t){if(e.type==="file")e.instances.delete(t);else e.instances.delete(t)}removeQueuedTask(e){let t=this.queuedTasks.indexOf(e);if(t!==-1)this.queuedTasks.splice(t,1);this.rejectRenderTaskCallbacks(e,new Yi),this.clearQueuedInstanceRequests(e),this.clearHighlightKey(e)}removeActiveTask(e){this.rejectRenderTaskCallbacks(e,new Yi),this.clearInstanceRequests(e),this.clearHighlightKey(e),this.activeTaskById.delete(e.id)}createRenderTaskCallbacks(e){return new Promise((t,n)=>{e.callbacks.add({resolve:t,reject:n})})}resolveRenderTaskCallbacks(e){for(let t of e.callbacks)t.resolve();e.callbacks.clear()}rejectRenderTaskCallbacks(e,t){for(let n of e.callbacks)n.reject(t);e.callbacks.clear()}invalidateRenderTasks(){for(let e=this.queuedTasks.length-1;e>=0;e--){let t=this.queuedTasks[e];if(t.renderOptionsVersion!==this.renderOptionsVersion)this.removeQueuedTask(t)}for(let e of Array.from(this.activeTaskById.values()))if(Rt(e)&&e.renderOptionsVersion!==this.renderOptionsVersion)this.removeActiveTask(e)}clearQueuedInstanceRequests(e){for(let t of rr(e))if(this.queuedTaskByInstance.get(t)===e)this.queuedTaskByInstance.delete(t)}clearHighlightKey(e){if(e.highlightKey!=null&&this.taskByHighlightKey.get(e.highlightKey)===e)this.taskByHighlightKey.delete(e.highlightKey)}trackInstanceRequests(e){for(let t of rr(e))this.activeRequestByInstance.set(t,e.id)}clearInstanceRequests(e){for(let t of rr(e))if(this.activeRequestByInstance.get(t)===e.id)this.activeRequestByInstance.delete(t)}notifyFileInstances(e,t,n){for(let r of e.instances)if(this.activeRequestByInstance.get(r)===e.id)r.onHighlightSuccess(e.request.file,t,n)}notifyDiffInstances(e,t,n){for(let r of e.instances)if(this.activeRequestByInstance.get(r)===e.id)r.onHighlightSuccess(e.request.diff,t,n)}notifyHighlightError(e,t){for(let n of rr(e))if(this.activeRequestByInstance.get(n)===e.id)n.onHighlightError(t)}hasMatchingFileInstanceTask(e,t){for(let n of this.iterateRenderTasks())if(n.type==="file"&&this.isCurrentRenderTask(n)&&n.instances.has(e)&&ea(t,n.request.file))return!0;return!1}hasMatchingDiffInstanceTask(e,t){for(let n of this.iterateRenderTasks())if(n.type==="diff"&&this.isCurrentRenderTask(n)&&n.instances.has(e)&&na(n.request.diff,t))return!0;return!1}getTaskByHighlightKey(e){let t=this.taskByHighlightKey.get(e);return t!=null&&this.isCurrentRenderTask(t)?t:void 0}isCurrentRenderTask(e){return e.renderOptionsVersion===this.renderOptionsVersion}*iterateRenderTasks(){for(let e of this.queuedTasks)yield e;for(let e of this.activeTaskById.values())if(Rt(e))yield e}generateRequestId(){return`req_${++this.nextRequestId}`}};function Ch(e){return e.type==="initialize"||e.type==="file"||e.type==="diff"}function Qs(e){let t=new Set;if(e.type==="initialize"||e.type==="set-render-options")return[];switch(e.type){case"file":t.add(e.request.file.lang??Ur(e.request.file.name));break;case"diff":t.add(e.request.diff.lang??Ur(e.request.diff.name)),t.add(e.request.diff.lang??Ur(e.request.diff.prevName??"-"));break}return t.delete("text"),Array.from(t)}function Rt(e){return e?.type==="file"||e?.type==="diff"}function rr(e){return e.instances}function Xi(e){return e instanceof Error?e:Error(String(e))}var or;function so({poolOptions:e,highlighterOptions:t}){return or??=new ia(e,t),or}function ao(){if(or==null)return;or.terminate(),or=void 0}function Gt(){return{childIdByNameId:new Map,childIds:[],childPositionById:new Map,childVisibleChunkSums:null,totalChildSubtreeNodeCount:0,totalChildVisibleSubtreeCount:0}}function lo(){return{childIdByNameId:null,childIds:[],childPositionById:null,childVisibleChunkSums:null,totalChildSubtreeNodeCount:0,totalChildVisibleSubtreeCount:0}}function Dt(e,t){if(t.childIdByNameId!=null)return t.childIdByNameId;let n=new Map;for(let r of t.childIds){let i=e[r];if(i!=null)n.set(i.nameId,r)}return t.childIdByNameId=n,n}function mn(e){if(e.childPositionById!=null)return e.childPositionById;let t=new Map;for(let n=0;n<e.childIds.length;n++){let r=e.childIds[n];if(r!=null)t.set(r,n)}return e.childPositionById=t,t}function gn(e,t){if(e.childPositionById!=null)e.childPositionById.set(t,e.childIds.length);e.childIds.push(t)}function co(e,t){if(e.childPositionById==null)return;for(let n=t;n<e.childIds.length;n++){let r=e.childIds[n];if(r!=null)e.childPositionById.set(r,n)}}function Yt(e,t){let n=0,r=0;for(let i of t.childIds){let o=e[i];if(o==null)continue;n+=o.subtreeNodeCount,r+=o.visibleSubtreeCount}t.totalChildSubtreeNodeCount=n,t.totalChildVisibleSubtreeCount=r,Mt(e,t)}function Gr(e,t,n,r){if(e.totalChildSubtreeNodeCount+=n,e.totalChildVisibleSubtreeCount+=r,e.childVisibleChunkSums==null||r===0)return;let i=mn(e).get(t);if(i===void 0)return;let o=i>>5;e.childVisibleChunkSums[o]+=r}function Yr(e,t,n){let r=t.childVisibleChunkSums;if(r!=null){let o=n,s=0;for(let a of r){if(o<a){let l=xh(e,t,s,o);return{...l,childVisibleIndex:n-l.localVisibleIndex}}o-=a,s+=32}throw Error(`Visible child index ${String(n)} is out of range`)}let i=n;for(let o=0;o<t.childIds.length;o++){let s=t.childIds[o];if(s==null)continue;let a=e[s];if(a==null)continue;if(i<a.visibleSubtreeCount)return{childIndex:o,childVisibleIndex:n-i,localVisibleIndex:i};i-=a.visibleSubtreeCount}throw Error(`Visible child index ${String(n)} is out of range`)}function oa(e,t,n){let r=0,i=t.childVisibleChunkSums,o=0;if(i!=null){let s=n>>5;for(let a=0;a<s;a+=1)r+=i[a]??0;o=s<<5}for(let s=o;s<n;s+=1){let a=t.childIds[s];if(a==null)continue;let l=e[a];if(l==null)continue;r+=l.visibleSubtreeCount}return r}function Mt(e,t){if(t.childIds.length<128){t.childVisibleChunkSums=null;return}let n=Math.ceil(t.childIds.length/32),r=new Int32Array(n);for(let i=0;i<t.childIds.length;i++){let o=t.childIds[i];if(o==null)continue;let s=e[o];if(s==null)continue;r[i>>5]+=s.visibleSubtreeCount}t.childVisibleChunkSums=r}function xh(e,t,n,r){let i=Math.min(t.childIds.length,n+32),o=r;for(let s=n;s<i;s++){let a=t.childIds[s];if(a==null)continue;let l=e[a];if(l==null)continue;if(o<l.visibleSubtreeCount)return{childIndex:s,localVisibleIndex:o};o-=l.visibleSubtreeCount}throw Error(`Visible child index ${String(r)} is out of range`)}function Ae(e,t,n=0){return e<<4|n<<3|t}function Ve(e){return e.depthAndFlags>>>4}function sr(e){return(e.depthAndFlags&8)>>3}function D(e){return(e.depthAndFlags&8)!==0}function sa(e){return e.depthAndFlags&7}function ue(e,t){return(sa(e)&t)!==0}function vn(e,t){e.depthAndFlags|=t}function aa(e,t){e.depthAndFlags=Ae(t,sa(e),sr(e))}var la=Symbol("benchmarkInstrumentation");function ca(e,t){if(t==null)return e;return Object.defineProperty(e,la,{configurable:!0,enumerable:!1,value:t,writable:!1}),e}function ar(e){if(e==null)return null;return e[la]??null}function E(e,t,n){if(e==null)return n();return e.measurePhase(t,n)}function yn(e,t,n){if(!Number.isFinite(n)||e==null)return;e.setCounter(t,n)}function ua(e){return e>=48&&e<=57}function kh(e){let t=[],n=0,r=0;while(r<e.length){while(r<e.length&&!ua(e.charCodeAt(r)))r+=1;if(r>=e.length)break;if(r>n)t.push(e.slice(n,r));let i=0;while(r<e.length&&ua(e.charCodeAt(r)))i=i*10+(e.charCodeAt(r)-48),r+=1;t.push(i),n=r}if(n<e.length||t.length===0)t.push(e.slice(n));return t}function Xt(e){let t=e.toLowerCase();return{lowerValue:t,tokens:kh(t)}}function _h(e,t){let n=Math.min(e.length,t.length);for(let r=0;r<n;r++){let i=e[r],o=t[r];if(i===o)continue;if(typeof i==="number"&&typeof o==="number")return i<o?-1:1;let s=String(i),a=String(o);if(s!==a)return s<a?-1:1}if(e.length!==t.length)return e.length<t.length?-1:1;return 0}function lr(e,t){if(e.tokens.length===1&&t.tokens.length===1&&typeof e.tokens[0]==="string"&&typeof t.tokens[0]==="string"){if(e.lowerValue===t.lowerValue)return 0;return e.lowerValue<t.lowerValue?-1:1}let n=_h(e.tokens,t.tokens);if(n!==0)return n;if(e.lowerValue!==t.lowerValue)return e.lowerValue<t.lowerValue?-1:1;return 0}function da(e,t,n){let r=lr(n(e),n(t));if(r!==0)return r;if(e===t)return 0;return e<t?-1:1}function Eh(e,t){return da(e,t,Xt)}function Xr(e,t){if(t!==e.segments.length-1)return 1;return e.isDirectory?1:0}function Th(e,t){let n=Math.min(e.segments.length,t.segments.length);for(let r=0;r<n;r++){let i=e.segments[r],o=t.segments[r];if(i===o)continue;let s=Xr(e,r);if(s!==Xr(t,r))return s===1?-1:1;return Eh(i,o)}if(e.segments.length!==t.segments.length)return e.segments.length<t.segments.length?-1:1;if(e.isDirectory===t.isDirectory)return 0;return e.isDirectory?-1:1}function ha(e,t){return Th(e,t)}function fa(e,t,n){let r=(o)=>{let s=n.get(o);if(s!=null)return s;let a=Xt(o);return n.set(o,a),a},i=Math.min(e.segments.length,t.segments.length);for(let o=0;o<i;o++){let s=e.segments[o],a=t.segments[o];if(s===a)continue;let l=Xr(e,o);if(l!==Xr(t,o))return l===1?-1:1;return da(s,a,r)}if(e.segments.length!==t.segments.length)return e.segments.length<t.segments.length?-1:1;if(e.isDirectory===t.isDirectory)return 0;return e.isDirectory?-1:1}function cr(e,t){let n=e.sortKeyById[t];if(n!==void 0)return n;let r=e.valueById[t],i=Xt(r);return e.sortKeyById[t]=i,i}function uo(e={}){return{flattenEmptyDirectories:e.flattenEmptyDirectories!==!1,sort:e.sort??"default"}}function pa(e){let t=e.length>0&&e.charCodeAt(e.length-1)===47,n=t?e.length-1:e.length,r=[],i=0;for(let o=0;o<n;o++){if(e.charCodeAt(o)!==47)continue;r.push(e.slice(i,o)),i=o+1}return r.push(e.slice(i,n)),{hasTrailingSlash:t,segments:r}}function Qt(e){let{hasTrailingSlash:t,segments:n}=pa(e);return{basename:n[n.length-1]??"",isDirectory:t,path:e,segments:n}}function Qr(e){if(e.length===0)return{requiresDirectory:!1,segments:[]};let{hasTrailingSlash:t,segments:n}=pa(e);return{requiresDirectory:t,segments:n}}function Jr(){let e=new Map;return e.set("",0),{idByValue:e,valueById:[""],sortKeyById:[Xt("")]}}function rt(e,t){let n=e.idByValue.get(t);if(n!==void 0)return n;let r=e.valueById.length;return e.idByValue.set(t,r),e.valueById.push(t),r}function qe(e,t){let n=e.valueById[t];if(n===void 0)throw Error(`Unknown segment ID: ${String(t)}`);return n}var ho=Symbol("pathStorePreparedInputKind");function va(e,t){return e[ho]=t,e}function ma(e){return{basename:e.basename,depth:e.segments.length,isDirectory:e.isDirectory,path:e.path,segments:e.segments}}function ya(e,t,n){if(n==="default")return ha(e,t);return n(ma(e),ma(t))}function Ph(){return{depthAndFlags:Ae(0,3,1),nameId:0,parentId:0,subtreeNodeCount:1,visibleSubtreeCount:1}}function Rh(e,t){let n=Math.min(e.length,t.length);for(let r=0;r<n;r++)if(e[r]!==t[r])return r;return n}function ga(e){return e.isDirectory?e.segments.length:e.segments.length-1}function Dh(e){return Array.isArray(e)&&e.every((t)=>t!=null&&typeof t==="object"&&typeof t.path==="string"&&Array.isArray(t.segments)&&typeof t.basename==="string"&&typeof t.isDirectory==="boolean")}function Mh(e){return Array.isArray(e)&&e.every((t)=>typeof t==="string")}function ba(e,t={}){return Zr(e,t).map((n)=>n.path)}function wa(e,t={}){let n=Zr(e,t);return va({paths:n.map((r)=>r.path),preparedPaths:n},"prepared")}function Ia(e){let t=e.length,n=!1;for(let r=0;r<t;r+=1){let i=e[r];if(i.length>0&&i.charCodeAt(i.length-1)===47){n=!0;break}}return va({paths:e,presortedPaths:e,presortedPathsContainDirectories:n},"presorted")}function Sa(e){let t=e,n=t.preparedPaths;if(t[ho]==="prepared"&&n!=null)return n;if(!Dh(n))throw Error("preparedInput must come from PathStore.prepareInput()");return n}function Ca(e){let t=e;if(t[ho]==="presorted"&&t.presortedPaths!=null)return t.presortedPaths;return Mh(t.presortedPaths)?t.presortedPaths:null}function xa(e){let t=e;return typeof t.presortedPathsContainDirectories==="boolean"?t.presortedPathsContainDirectories:null}function Zr(e,t={}){let n=uo(t),r=ar(t);yn(r,"workload.inputFiles",e.length);let i=E(r,"store.preparePathEntries.parse",()=>e.map((o)=>Qt(o)));return E(r,"store.preparePathEntries.sort",()=>i.sort((o,s)=>ya(o,s,n.sort))),i}var ei=class{directories=new Map;directoryStack=[0];presortedDirectoryNodeIds=[];initialExpandedPathSet;createdDirectoriesAllExpanded=!1;createdDirectoryCount=0;lastPreparedPath=null;nodes=[Ph()];options;instrumentation;segmentSortKeyCache=new Map;segmentTable=Jr();hasDeferredDirectoryIndexes=!1;constructor(e={}){this.instrumentation=ar(e),this.options=uo(e);let t=e.initialExpandedPaths??null;if(t==null||t.length===0)this.initialExpandedPathSet=null;else{let n=new Set,r=t.length;for(let i=0;i<r;i+=1){let o=t[i],s=o.length;n.add(s>0&&o.charCodeAt(s-1)===47?o.slice(0,s-1):o)}this.initialExpandedPathSet=n,this.createdDirectoriesAllExpanded=!0}this.directories.set(0,Gt())}appendPaths(e){return E(this.instrumentation,"store.builder.appendPaths.parse",()=>this.appendPreparedPaths(e.map((t)=>Qt(t))))}appendPreparedPaths(e,t=!0){return this.createdDirectoriesAllExpanded=!1,E(this.instrumentation,"store.builder.appendPreparedPaths",()=>{for(let n of e)this.appendPreparedPath(n,t)}),this}appendPresortedPaths(e,t=null){return E(this.instrumentation,"store.builder.appendPresortedPaths",()=>{if(t===!1){this.appendPresortedFilePaths(e);return}this.createdDirectoriesAllExpanded=!1;let n=null,r=0,i=this.nodes,o=this.segmentTable,s=o.idByValue,a=o.valueById,l=this.directoryStack,c=0,d="",f=0;for(let u of e){if(n===u)throw Error(`Duplicate path: "${u}"`);let m=u.length>0&&u.charCodeAt(u.length-1)===47,p=m?u.length-1:u.length,g=0,v=0;if(n!=null)if(d.length>0&&u.length>d.length&&u.startsWith(d))g=f,v=d.length;else{let y=Math.min(p,n.length),w=!0;for(let x=0;x<y;x++){let P=u.charCodeAt(x);if(P!==n.charCodeAt(x)){w=!1;break}if(P===47)g++,v=x+1}if(w&&m&&y===p&&n.length>p&&n.charCodeAt(p)===47)g++,v=p+1}c=g,r=g;let S=v,C=u.indexOf("/",S);while(C>=0&&C<p){let y=l[c];if(y===void 0)throw Error("Directory stack underflow while building the path store");r++;let w=u.slice(S,C),x=s.get(w);if(x===void 0)x=a.length,s.set(w,x),a.push(w);let P=i.length;i.push({depthAndFlags:Ae(r,0,1),nameId:x,parentId:y,subtreeNodeCount:1,visibleSubtreeCount:1}),this.recordCreatedDirectoryPath(u.slice(0,C)),c++,l[c]=P,S=C+1,C=u.indexOf("/",S)}if(m){if(S<p){let w=l[c];if(w===void 0)throw Error(`Unable to resolve directory parent for "${u}"`);r++;let x=u.slice(S,p),P=s.get(x);if(P===void 0)P=a.length,s.set(x,P),a.push(x);let O=i.length;i.push({depthAndFlags:Ae(r,0,1),nameId:P,parentId:w,subtreeNodeCount:1,visibleSubtreeCount:1}),c++,l[c]=O,S=p+1}let y=l[c];if(y===void 0)throw Error(`Unable to resolve directory node for "${u}"`);this.promoteDirectoryToExplicit(y,u)}else{let y=l[c];if(y===void 0)throw Error(`Unable to resolve file parent for "${u}"`);let w=u.slice(S),x=s.get(w);if(x===void 0)x=a.length,s.set(w,x),a.push(w);i.push({depthAndFlags:Ae(r+1,0),nameId:x,parentId:y,subtreeNodeCount:1,visibleSubtreeCount:1})}if(S!==d.length)d=u.substring(0,S),f=r;n=u}if(l.length=c+1,n!=null)this.lastPreparedPath=Qt(n);this.hasDeferredDirectoryIndexes=!0}),this}appendPresortedFilePaths(e){let t=null,n=0,r=this.nodes,i=this.segmentTable,o=i.idByValue,s=i.valueById,a=this.directoryStack,l=0,c="",d=0;for(let f of e){if(t===f)throw Error(`Duplicate path: "${f}"`);let u=f.length,m=0,p=0;if(t!=null)if(c.length>0&&f.length>c.length&&f.startsWith(c))m=d,p=c.length;else{let w=Math.min(u,t.length);for(let x=0;x<w;x++){let P=f.charCodeAt(x);if(P!==t.charCodeAt(x))break;if(P===47)m++,p=x+1}}l=m,n=m;let g=p,v=f.indexOf("/",g);while(v>=0){let w=a[l];if(w===void 0)throw Error("Directory stack underflow while building the path store");n++;let x=f.slice(g,v),P=o.get(x);if(P===void 0)P=s.length,o.set(x,P),s.push(x);let O=r.length;r.push({depthAndFlags:Ae(n,0,1),nameId:P,parentId:w,subtreeNodeCount:1,visibleSubtreeCount:1}),this.recordCreatedDirectoryPath(f.slice(0,v)),this.presortedDirectoryNodeIds.push(O),l++,a[l]=O,g=v+1,v=f.indexOf("/",g)}let S=a[l];if(S===void 0)throw Error(`Unable to resolve file parent for "${f}"`);let C=f.slice(g),y=o.get(C);if(y===void 0)y=s.length,o.set(C,y),s.push(C);if(r.push({depthAndFlags:Ae(n+1,0),nameId:y,parentId:S,subtreeNodeCount:1,visibleSubtreeCount:1}),g!==c.length)c=f.substring(0,g),d=n;t=f}if(a.length=l+1,t!=null)this.lastPreparedPath=Qt(t);this.hasDeferredDirectoryIndexes=!0}finish(e={}){let t=e.skipSubtreeCountPass===!0;if(this.hasDeferredDirectoryIndexes)E(this.instrumentation,"store.builder.buildDirectoryIndexes",()=>this.buildPresortedFinish(t)),this.hasDeferredDirectoryIndexes=!1;else if(!t)E(this.instrumentation,"store.builder.computeSubtreeCounts",()=>this.computeSubtreeCounts(0));return{directories:this.directories,nodes:this.nodes,options:this.options,rootId:0,segmentTable:this.segmentTable,presortedDirectoryNodeIds:this.presortedDirectoryNodeIds.length>0?this.presortedDirectoryNodeIds:null}}didMatchAllInitialExpandedPaths(){return this.createdDirectoriesAllExpanded&&this.initialExpandedPathSet!=null&&this.createdDirectoryCount===this.initialExpandedPathSet.size}appendPreparedPath(e,t){if(this.hasDeferredDirectoryIndexes)this.buildDirectoryIndexes(),this.hasDeferredDirectoryIndexes=!1;if(this.lastPreparedPath!=null){if(e.path===this.lastPreparedPath.path)throw Error(`Duplicate path: "${e.path}"`);if(t){if((this.options.sort==="default"?fa(this.lastPreparedPath,e,this.segmentSortKeyCache):ya(this.lastPreparedPath,e,this.options.sort))>0)throw Error(`Builder input must be sorted before appendPaths(): "${e.path}"`)}}let n=this.lastPreparedPath,r=ga(e),i=n==null?0:ga(n),o=n==null?0:Rh(n.segments,e.segments),s=Math.min(o,r,i);this.directoryStack.length=s+1;for(let l=s;l<r;l++){let c=this.directoryStack[this.directoryStack.length-1];if(c===void 0)throw Error("Directory stack underflow while building the path store");let d=t?this.getOrCreateDirectoryChild(c,e.segments[l]):this.createDirectoryChild(c,e.segments[l]);this.directoryStack.push(d)}if(e.isDirectory){let l=this.directoryStack[this.directoryStack.length-1];if(l===void 0)throw Error(`Unable to resolve directory node for "${e.path}"`);this.promoteDirectoryToExplicit(l,e.path),this.lastPreparedPath=e;return}let a=this.directoryStack[this.directoryStack.length-1];if(a===void 0)throw Error(`Unable to resolve file parent for "${e.path}"`);if(t)this.createFileChild(a,e.basename,e.path);else this.createFileChildUnchecked(a,e.basename);this.lastPreparedPath=e}recordCreatedDirectoryPath(e){if(!this.createdDirectoriesAllExpanded||this.initialExpandedPathSet==null)return;if(this.createdDirectoryCount+=1,!this.initialExpandedPathSet.has(e))this.createdDirectoriesAllExpanded=!1}createFileChild(e,t,n){let r=rt(this.segmentTable,t),i=this.getDirectoryIndex(e),o=i.childIdByNameId;if(o!=null){if(o.get(r)!==void 0)throw Error(`Path collides with an existing entry: "${n}"`)}let s=this.nodes[e];if(s===void 0)throw Error(`Unknown parent node ID: ${String(e)}`);let a=this.nodes.length;if(this.nodes.push({depthAndFlags:Ae(Ve(s)+1,0),nameId:r,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),o!=null)o.set(r,a);return gn(i,a),a}createFileChildUnchecked(e,t){let n=rt(this.segmentTable,t),r=this.getDirectoryIndex(e),i=this.nodes[e];if(i===void 0)throw Error(`Unknown parent node ID: ${String(e)}`);let o=this.nodes.length;if(this.nodes.push({depthAndFlags:Ae(Ve(i)+1,0),nameId:n,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),r.childIdByNameId!=null)r.childIdByNameId.set(n,o);return gn(r,o),o}getOrCreateDirectoryChild(e,t){let n=rt(this.segmentTable,t),r=this.getDirectoryIndex(e);if(r.childIdByNameId!=null){let s=r.childIdByNameId.get(n);if(s!==void 0){let a=this.nodes[s];if(a!=null&&!D(a))throw Error(`Path collides with an existing file while creating directory "${t}"`);return s}}let i=this.nodes[e];if(i===void 0)throw Error(`Unknown parent node ID: ${String(e)}`);let o=this.nodes.length;if(this.nodes.push({depthAndFlags:Ae(Ve(i)+1,0,1),nameId:n,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),r.childIdByNameId!=null)r.childIdByNameId.set(n,o);return gn(r,o),this.directories.set(o,Gt()),o}createDirectoryChild(e,t){let n=rt(this.segmentTable,t),r=this.getDirectoryIndex(e),i=this.nodes[e];if(i===void 0)throw Error(`Unknown parent node ID: ${String(e)}`);let o=this.nodes.length;if(this.nodes.push({depthAndFlags:Ae(Ve(i)+1,0,1),nameId:n,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),r.childIdByNameId!=null)r.childIdByNameId.set(n,o);return gn(r,o),this.directories.set(o,Gt()),o}promoteDirectoryToExplicit(e,t){let n=this.nodes[e];if(n===void 0)throw Error(`Unknown directory node ID: ${String(e)}`);if(!D(n))throw Error(`Path is not a directory: "${t}"`);if(ue(n,1))throw Error(`Duplicate path: "${t}"`);vn(n,1)}getDirectoryIndex(e){let t=this.directories.get(e);if(t!==void 0)return t;throw Error(`Unknown directory child index for node ${String(e)}`)}buildPresortedFinish(e){let t=this.nodes,n=this.directories;n.set(0,lo());let r=-1,i=null;for(let o=1;o<t.length;o++){let s=t[o];if(s==null)continue;if(D(s)){let l=lo();n.set(o,l),r=o,i=l}let a;if(s.parentId===r)a=i;else a=n.get(s.parentId),r=s.parentId,i=a??null;if(a!=null)a.childIds.push(o)}if(e)return;for(let o=t.length-1;o>=1;o--){let s=t[o];if(s==null)continue;let a=t[s.parentId];if(a!=null)a.subtreeNodeCount+=s.subtreeNodeCount,a.visibleSubtreeCount+=s.visibleSubtreeCount}}buildDirectoryIndexes(){let e=this.nodes;for(let t=1;t<e.length;t++){let n=e[t];if(n==null)continue;if(D(n))this.directories.set(t,Gt());let r=this.directories.get(n.parentId);if(r!=null){if(r.childIdByNameId!=null)r.childIdByNameId.set(n.nameId,t);gn(r,t)}}}computeSubtreeCounts(e){let t=this.nodes[e];if(t===void 0)throw Error(`Unknown node ID: ${String(e)}`);if(!D(t))return t.subtreeNodeCount=1,t.visibleSubtreeCount=1,1;let n=this.getDirectoryIndex(e),r=1;for(let i of n.childIds)r+=this.computeSubtreeCounts(i);return Yt(this.nodes,n),t.subtreeNodeCount=r,t.visibleSubtreeCount=r,r}};function ka(e,t="closed",n=null){let r=Ah(t);return{activeNodeCount:e.nodes.length-1,collapsedDirectoryIds:new Set,collapseNewDirectoriesByDefault:!1,defaultExpansion:r,directoriesOpenByDefault:r==="open",hasCollapsedDirectoryOverrides:!1,directoryLoadInfoById:new Map,expandedDirectoryIds:new Set,instrumentation:n,listeners:new Map,pathCacheByNodeId:new Map([[e.rootId,{path:"",version:0}]]),pathCacheVersion:0,snapshot:e,transactionStack:[]}}function _a(){return{affectedAncestorIds:new Set,affectedNodeIds:new Set,events:[]}}function Ah(e){if(typeof e!=="number")return e;if(!Number.isInteger(e)||e<0)throw Error(`initialExpansion must be "open", "closed", or a non-negative integer depth. Received: ${String(e)}`);return e}function Ea(e,t){if(ue(t,2))return!0;if(e.defaultExpansion==="open")return!0;if(e.defaultExpansion==="closed")return!1;return Ve(t)<=e.defaultExpansion}function Ce(e,t,n=e.snapshot.nodes[t]){if(n==null||!D(n))return!1;if(e.directoriesOpenByDefault&&!e.hasCollapsedDirectoryOverrides)return!0;if(e.collapsedDirectoryIds.has(t))return!1;if(e.expandedDirectoryIds.has(t))return!0;return Ea(e,n)}function At(e,t,n,r=e.snapshot.nodes[t]){if(r==null||!D(r))return;let i=Ea(e,r);if(n){if(i){e.collapsedDirectoryIds.delete(t),e.hasCollapsedDirectoryOverrides=e.collapsedDirectoryIds.size>0;return}e.expandedDirectoryIds.add(t);return}if(i){e.collapsedDirectoryIds.add(t),e.hasCollapsedDirectoryOverrides=!0;return}e.expandedDirectoryIds.delete(t)}function Ta(e,t){let n=e.directoryLoadInfoById.get(t);if(n!=null)return n;let r={activeAttemptId:null,errorMessage:null,nextAttemptId:1,state:"loaded"};return e.directoryLoadInfoById.set(t,r),r}function Nt(e,t){return e.directoryLoadInfoById.get(t)?.state??"loaded"}function Pa(e,t){let n=Ta(e,t);if(n.state==="loading"&&n.activeAttemptId!=null)return{attemptId:n.activeAttemptId,nodeId:t,reused:!0};let r=n.nextAttemptId;return n.activeAttemptId=r,n.errorMessage=null,n.nextAttemptId+=1,n.state="loading",{attemptId:r,nodeId:t,reused:!1}}function Ra(e,t){let n=Ta(e,t);n.activeAttemptId=null,n.errorMessage=null,n.state="unloaded"}function Da(e,t,n){let r=e.directoryLoadInfoById.get(t);if(r==null||r.activeAttemptId!==n)return!1;return r.activeAttemptId=null,r.errorMessage=null,r.state="loaded",!0}function Ma(e,t,n){return e.directoryLoadInfoById.get(t)?.activeAttemptId===n}function Aa(e,t,n,r){let i=e.directoryLoadInfoById.get(t);if(i==null||i.activeAttemptId!==n)return!1;return i.activeAttemptId=null,i.errorMessage=r??null,i.state="error",!0}function Na(e,t){e.directoryLoadInfoById.delete(t)}function Va(e,t,n){let r=n,i=e.listeners.get(t);if(i!=null)i.add(r);else e.listeners.set(t,new Set([r]));return()=>{let o=e.listeners.get(t);if(o==null)return;if(o.delete(r),o.size===0)e.listeners.delete(t)}}function Oa(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!0,operation:"add",path:e.path,projectionChanged:e.projectionChanged,visibleCountDelta:null}}function za(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!0,operation:"remove",path:e.path,projectionChanged:e.projectionChanged,recursive:e.recursive,visibleCountDelta:null}}function qa(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!0,from:e.from,operation:"move",projectionChanged:e.projectionChanged,to:e.to,visibleCountDelta:null}}function Wa(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!1,operation:"expand",path:e.path,projectionChanged:!0,visibleCountDelta:null}}function ja(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!1,operation:"collapse",path:e.path,projectionChanged:!0,visibleCountDelta:null}}function $a(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!1,operation:"mark-directory-unloaded",path:e.path,projectionChanged:e.projectionChanged,visibleCountDelta:null}}function Ua(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],attemptId:e.attemptId,canonicalChanged:!1,operation:"begin-child-load",path:e.path,projectionChanged:e.projectionChanged,reused:e.reused,visibleCountDelta:null}}function Ka(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],attemptId:e.attemptId,canonicalChanged:e.childEvents.some((t)=>t.canonicalChanged),childEvents:e.childEvents,operation:"apply-child-patch",path:e.path,projectionChanged:e.projectionChanged,visibleCountDelta:null}}function Ga(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],attemptId:e.attemptId,canonicalChanged:!1,operation:"complete-child-load",path:e.path,projectionChanged:e.projectionChanged,stale:e.stale,visibleCountDelta:null}}function Ya(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],attemptId:e.attemptId,canonicalChanged:!1,errorMessage:e.errorMessage,operation:"fail-child-load",path:e.path,projectionChanged:e.projectionChanged,stale:e.stale,visibleCountDelta:null}}function Xa(e){return{activeNodeCountAfter:e.activeNodeCountAfter,activeNodeCountBefore:e.activeNodeCountBefore,affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],cachedPathEntryCountAfter:e.cachedPathEntryCountAfter,cachedPathEntryCountBefore:e.cachedPathEntryCountBefore,canonicalChanged:!1,idsPreserved:e.idsPreserved,loadInfoEntryCountAfter:e.loadInfoEntryCountAfter,loadInfoEntryCountBefore:e.loadInfoEntryCountBefore,mode:e.mode,operation:"cleanup",projectionChanged:e.projectionChanged,reclaimedCachedPathEntryCount:e.reclaimedCachedPathEntryCount,reclaimedLoadInfoEntryCount:e.reclaimedLoadInfoEntryCount,reclaimedNodeSlotCount:e.reclaimedNodeSlotCount,reclaimedSegmentCount:e.reclaimedSegmentCount,segmentCountAfter:e.segmentCountAfter,segmentCountBefore:e.segmentCountBefore,totalNodeSlotCountAfter:e.totalNodeSlotCountAfter,totalNodeSlotCountBefore:e.totalNodeSlotCountBefore,visibleCountDelta:null}}function Ne(e,t,n){return{...n,visibleCountDelta:po(e)-t}}function Qa(e,t){let n=po(e),r=_a();e.transactionStack.push(r);try{t()}catch(i){throw Fa(e,r,!1),i}Fa(e,r,!0,po(e)-n)}function Xe(e,t){let n=e.instrumentation;if(n==null){La(e,t);return}E(n,"store.events.record",()=>La(e,t))}function La(e,t){let n=e.transactionStack[e.transactionStack.length-1]??null;if(n==null){fo(e,t);return}n.events.push(t),Fh(n,t)}function Fa(e,t,n,r=null){if(e.transactionStack.pop()!==t)throw Error("Transaction stack underflow");if(!n)return;let i=e.transactionStack[e.transactionStack.length-1]??null;if(i!=null){let a=e.instrumentation;if(a==null)Ba(i,t);else E(a,"store.events.batch.merge",()=>Ba(i,t));return}let o=Nh(t,r),s=e.instrumentation;if(s==null){fo(e,o);return}E(s,"store.events.batch.commit",()=>fo(e,o))}function Nh(e,t){return{affectedAncestorIds:[...e.affectedAncestorIds],affectedNodeIds:[...e.affectedNodeIds],canonicalChanged:e.events.some((n)=>n.canonicalChanged),events:[...e.events],operation:"batch",projectionChanged:e.events.some((n)=>n.projectionChanged),visibleCountDelta:t}}function Lh(e,t){for(let n of t.affectedAncestorIds)e.affectedAncestorIds.add(n);for(let n of t.affectedNodeIds)e.affectedNodeIds.add(n)}function Ba(e,t){for(let n of t.events)e.events.push(n);Lh(e,t)}function Fh(e,t){for(let n of t.affectedNodeIds)e.affectedNodeIds.add(n);for(let n of t.affectedAncestorIds)e.affectedAncestorIds.add(n)}function fo(e,t){let n=e.instrumentation;if(n==null){Ha(e,t);return}E(n,"store.events.emit",()=>Ha(e,t))}function Ha(e,t){e.listeners.get(t.operation)?.forEach((n)=>n(t)),e.listeners.get("*")?.forEach((n)=>n(t))}function po(e){return e.snapshot.nodes[e.snapshot.rootId]?.visibleSubtreeCount??0}function yt(e,t){if(e.snapshot.options.flattenEmptyDirectories!==!0)return null;let n=e.snapshot.nodes[t];if(n==null||!D(n)||ue(n,2))return null;let r=e.snapshot.directories.get(t);if(r==null||r.childIds.length!==1)return null;let i=r.childIds[0];if(i==null)return null;let o=e.snapshot.nodes[i];if(o==null||!D(o))return null;return i}function bt(e,t){let n=t;while(!0){let r=yt(e,n);if(r==null)return n;n=r}}function bn(e,t){let n=[t],r=t;while(!0){let i=yt(e,r);if(i==null)return n;n.push(i),r=i}}function ti(e,t){let n=t==null?e.snapshot.rootId:Le(e,t);if(n==null)return[];return Hh(e,n)}function go(e,t){let n=Qt(t),r=n.isDirectory?n.segments:n.segments.slice(0,-1),i=Lt(e,Kh(e,r)),{createdNodeIds:o,directoryId:s}=Vh(e,r),a=new Set(o),l=s;if(n.isDirectory){let d=M(e,s);if(ue(d,1))throw Error(`Path already exists: "${t}"`);vn(d,1),e.pathCacheByNodeId.set(s,{path:t,version:e.pathCacheVersion}),a.add(s)}else l=zh(e,s,n.basename),a.add(l);Ft(e,s);let c=Lt(e,s);return Oa({affectedAncestorIds:We(e,l),affectedNodeIds:[...a],path:t,projectionChanged:il(i,c)})}function vo(e,t,n){let r=Le(e,t);if(r==null)throw Error(`Path does not exist: "${t}"`);let i=M(e,r);if(ue(i,2))throw Error("The root node cannot be removed");if(D(i)&&ae(e,r).childIds.length>0&&n.recursive!==!0)throw Error(`Cannot remove a non-empty directory without recursive: "${t}"`);let o=i.parentId,s=Lt(e,o),a=rl(e,r);wo(e,o,r,i.nameId),Io(e,o),Ft(e,o);let l=Lt(e,o);return za({affectedAncestorIds:We(e,o),affectedNodeIds:a,path:t,projectionChanged:il(s,l),recursive:n.recursive===!0})}function yo(e,t,n,r){let i=Le(e,t);if(i==null)throw Error(`Source path does not exist: "${t}"`);let o=M(e,i);if(ue(o,2))throw Error("The root node cannot be moved");let s=r.collision??"error",a=$h(e,i,n),l=Lt(e,o.parentId),c=Lt(e,a.parentId),d=qe(e.snapshot.segmentTable,o.nameId),f=rt(e.snapshot.segmentTable,a.basename);if(a.parentId===o.parentId&&d===a.basename)return null;if(D(o)&&Yh(e,i,a.parentId))throw Error("Cannot move a directory into one of its descendants");let u=Dt(e.snapshot.nodes,ae(e,a.parentId)).get(f),m=a.existingNodeId??u??null;if(m!=null&&m!==i){if(Uh(e,m,s,sr(o))==="skip")return null}let p=o.parentId;if(wo(e,p,i,o.nameId),o.parentId=a.parentId,o.nameId=f,e.pathCacheByNodeId.delete(i),sl(e,i),bo(e,a.parentId,i),Io(e,p),e.pathCacheVersion++,Ft(e,p),a.parentId!==p)Ft(e,a.parentId);let g=Lt(e,p),v=Lt(e,a.parentId);return qa({affectedAncestorIds:[...new Set([...We(e,p),...We(e,a.parentId)])],affectedNodeIds:[i],from:t,projectionChanged:ol([l,c],[g,v]),to:ne(e,i)})}function Bh(e,t){let n=e.pathCacheByNodeId.get(t);return n!=null&&n.version===e.pathCacheVersion?n.path:null}function Ja(e,t,n){return e.pathCacheByNodeId.set(t,{path:n,version:e.pathCacheVersion}),n}function ne(e,t){let n=M(e,t),r=Bh(e,t);if(r!=null)return r;if(ue(n,2))return Ja(e,t,"");let i=ne(e,n.parentId),o=qe(e.snapshot.segmentTable,n.nameId),s=i.length===0?o:`${i}${o}`;return Ja(e,t,D(n)?`${s}/`:s)}function Ft(e,t){let n=e.instrumentation;if(n==null){el(e,t);return}E(n,"store.recomputeCountsUpwardFrom",()=>el(e,t))}function ur(e,t){let n=[[t,0]],{nodes:r,directories:i}=e.snapshot;while(n.length>0){let o=n[n.length-1],s=o[0],a=r[s];if(a==null||!D(a)){mo(e,s,a,!0),n.pop();continue}let l=i.get(s);if(l==null||o[1]>=l.childIds.length){mo(e,s,a,!0),n.pop();continue}let c=l.childIds[o[1]++];n.push([c,0])}}function We(e,t){let n=[],r=t;while(r!=null){let i=M(e,r);if(n.push(r),r===e.snapshot.rootId)break;r=i.parentId}return n}function Le(e,t){if(t.length===0)return e.snapshot.rootId;let n=Qr(t);return nl(e,n.segments,n.requiresDirectory)}function nl(e,t,n){let r=e.snapshot.rootId;for(let o of t){let s=e.snapshot.segmentTable.idByValue.get(o);if(s===void 0)return null;let a=ae(e,r),l=Dt(e.snapshot.nodes,a).get(s);if(l===void 0)return null;r=l}let i=M(e,r);if(n&&!D(i))return null;return r}function ae(e,t){let n=e.snapshot.directories.get(t);if(n===void 0)throw Error(`Unknown directory child index for node ${String(t)}`);return n}function M(e,t){let n=e.snapshot.nodes[t];if(n===void 0||ue(n,4))throw Error(`Unknown node ID: ${String(t)}`);return n}function Hh(e,t){let n=e.snapshot.nodes[t];if(n===void 0||ue(n,4))return[];if(!D(n))return[ne(e,t)];if(ae(e,t).childIds.length===0)return ue(n,1)&&!ue(n,2)?[ne(e,t)]:[];let r=[],i=[{childIndex:0,nodeId:t}];while(i.length>0){let o=i[i.length-1];if(o==null)break;let s=e.snapshot.nodes[o.nodeId];if(s===void 0||ue(s,4)){i.pop();continue}if(!D(s)){r.push(ne(e,o.nodeId)),i.pop();continue}let a=ae(e,o.nodeId);if(a.childIds.length===0){if(ue(s,1)&&!ue(s,2))r.push(ne(e,o.nodeId));i.pop();continue}let l=a.childIds[o.childIndex];if(l==null){i.pop();continue}o.childIndex++,i.push({childIndex:0,nodeId:l})}return r}function Vh(e,t){let n=[],r=e.snapshot.rootId;for(let i of t){let o=rt(e.snapshot.segmentTable,i),s=ae(e,r),a=Dt(e.snapshot.nodes,s).get(o);if(a!==void 0){if(!D(M(e,a)))throw Error(`Cannot create a directory that collides with an existing file: "${i}"`);r=a;continue}r=Oh(e,r,o),n.push(r)}return{createdNodeIds:n,directoryId:r}}function Oh(e,t,n){let r=M(e,t),i=e.snapshot.nodes.length;if(e.snapshot.nodes.push({depthAndFlags:Ae(Ve(r)+1,0,1),nameId:n,parentId:t,subtreeNodeCount:1,visibleSubtreeCount:1}),e.snapshot.directories.set(i,Gt()),bo(e,t,i),e.collapseNewDirectoriesByDefault)e.collapsedDirectoryIds.add(i),e.hasCollapsedDirectoryOverrides=!0;return e.activeNodeCount++,i}function zh(e,t,n){let r=rt(e.snapshot.segmentTable,n),i=ae(e,t);if(Dt(e.snapshot.nodes,i).has(r))throw Error(`Path already exists: "${Xh(e,t,n)}"`);let o=M(e,t),s=e.snapshot.nodes.length;return e.snapshot.nodes.push({depthAndFlags:Ae(Ve(o)+1,0),nameId:r,parentId:t,subtreeNodeCount:1,visibleSubtreeCount:1}),bo(e,t,s),e.activeNodeCount++,s}function qh(e,t,n){let r=0,i=t.childIds.length;while(r<i){let o=r+i>>>1,s=t.childIds[o];if(s==null){i=o;continue}if(Wh(e,n,s)<0)i=o;else r=o+1}return r}function bo(e,t,n){let r=ae(e,t),i=M(e,n);Dt(e.snapshot.nodes,r).set(i.nameId,n),Gr(r,n,i.subtreeNodeCount,i.visibleSubtreeCount);let o=qh(e,r,n);r.childIds.splice(o,0,n),co(r,o),Mt(e.snapshot.nodes,r)}function wo(e,t,n,r){let i=ae(e,t),o=mn(i),s=o.get(n)??-1;Dt(e.snapshot.nodes,i).delete(r),o.delete(n);let a=e.snapshot.nodes[n];if(a!=null)Gr(i,n,-a.subtreeNodeCount,-a.visibleSubtreeCount);if(s>=0)i.childIds.splice(s,1),co(i,s),Mt(e.snapshot.nodes,i)}function Wh(e,t,n){let r=e.snapshot.options.sort;if(r==="default")return jh(e,t,n);return r(Za(e,t),Za(e,n))}function jh(e,t,n){let r=M(e,t),i=M(e,n),o=D(r);if(o!==D(i))return o?-1:1;let s=lr(cr(e.snapshot.segmentTable,r.nameId),cr(e.snapshot.segmentTable,i.nameId));if(s!==0)return s;let a=qe(e.snapshot.segmentTable,r.nameId),l=qe(e.snapshot.segmentTable,i.nameId);if(a!==l)return a<l?-1:1;return t<n?-1:1}function Za(e,t){let n=M(e,t),r=ne(e,t),i=D(n),o=i?r.slice(0,-1):r;return{basename:qe(e.snapshot.segmentTable,n.nameId),depth:Ve(n),isDirectory:i,path:r,segments:o.length===0?[]:o.split("/")}}function $h(e,t,n){let r=M(e,t),i=Le(e,n);if(i!=null){let c=M(e,i);if(D(c))return{basename:qe(e.snapshot.segmentTable,r.nameId),existingNodeId:null,parentId:i};let d=Qr(n).segments;return{basename:d[d.length-1]??"",existingNodeId:i,parentId:c.parentId}}let o=Qr(n),s=o.segments[o.segments.length-1]??"",a=o.segments.slice(0,-1),l=a.length===0?e.snapshot.rootId:nl(e,a,!0);if(l==null)throw Error(`Destination parent does not exist: "${n}"`);return{basename:s,existingNodeId:null,parentId:l}}function Uh(e,t,n,r){if(n==="skip")return"skip";if(n==="error")throw Error(`Destination already exists: "${ne(e,t)}"`);let i=M(e,t);if(sr(i)!==r)throw Error("replace collision requires the same source and destination kinds");if(D(i)&&ae(e,t).childIds.length>0)throw Error("replace collision does not support non-empty directories");let{parentId:o,nameId:s}=i;return rl(e,t),wo(e,o,t,s),Io(e,o),Ft(e,o),"handled"}function rl(e,t){let n=[],r=[{nodeId:t,visitedChildren:!1}];while(r.length>0){let i=r.pop();if(i==null)break;let o=M(e,i.nodeId);if(i.visitedChildren||!D(o)){if(D(o))e.snapshot.directories.delete(i.nodeId);if(vn(o,4),e.pathCacheByNodeId.delete(i.nodeId),e.collapsedDirectoryIds.delete(i.nodeId))e.hasCollapsedDirectoryOverrides=e.collapsedDirectoryIds.size>0;e.expandedDirectoryIds.delete(i.nodeId),Na(e,i.nodeId),e.activeNodeCount--,n.push(i.nodeId);continue}r.push({nodeId:i.nodeId,visitedChildren:!0});let s=ae(e,i.nodeId);for(let a=s.childIds.length-1;a>=0;a--){let l=s.childIds[a];if(l!=null)r.push({nodeId:l,visitedChildren:!1})}}return n}function Io(e,t){let n=t;while(n!=null){let r=M(e,n);if(!D(r)||ue(r,2))return;if(ae(e,n).childIds.length>0)return;vn(r,1),n=r.parentId===n?null:r.parentId}}function Kh(e,t){let n=e.snapshot.rootId;for(let r of t){let i=e.snapshot.segmentTable.idByValue.get(r);if(i==null)break;let o=Dt(e.snapshot.nodes,ae(e,n)).get(i);if(o==null)break;if(!D(M(e,o)))break;n=o}return n}function Lt(e,t){let n=Gh(e,t);if(n==null)return null;let r=bt(e,n),i=M(e,r),o=n===r?null:bn(e,n).map((s)=>ne(e,s));return JSON.stringify({flattenedSegmentPaths:o,hasChildren:ae(e,r).childIds.length>0,path:ne(e,r),terminalKind:sr(i)})}function il(e,t){return ol([e],[t])}function ol(e,t){for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(r==null||i==null||r!==i)return!0}return!1}function Gh(e,t){let n=t;while(n!=null){let r=M(e,n);if(!D(r)||ue(r,2))return null;if(!Ce(e,n,r))return n;n=r.parentId}return null}function sl(e,t){let n=M(e,t);if(aa(n,(t===e.snapshot.rootId?-1:Ve(M(e,n.parentId)))+1),!D(n))return;let r=ae(e,t);for(let i of r.childIds)sl(e,i)}function Yh(e,t,n){let r=n;while(r!=null){if(r===t)return!0;let i=M(e,r);if(r===e.snapshot.rootId)return!1;r=i.parentId}return!1}function mo(e,t,n=M(e,t),r=!1){let i=e.instrumentation;if(i==null){tl(e,t,n,r);return}E(i,"store.recomputeNodeCounts",()=>tl(e,t,n,r))}function el(e,t){let n=t;while(n!=null){let r=M(e,n),i=r.subtreeNodeCount,o=r.visibleSubtreeCount;if(mo(e,n,r),n===e.snapshot.rootId)return;let s=r.subtreeNodeCount-i,a=r.visibleSubtreeCount-o,l=r.parentId;if(s!==0||a!==0)Gr(ae(e,l),n,s,a);n=l}}function tl(e,t,n,r){if(!D(n)){n.subtreeNodeCount=1,n.visibleSubtreeCount=1;return}let i=ae(e,t);if(r){let a=e.instrumentation;if(a==null)Yt(e.snapshot.nodes,i);else E(a,"store.recomputeNodeCounts.rebuildChildAggregates",()=>Yt(e.snapshot.nodes,i))}let o=1+i.totalChildSubtreeNodeCount,s=i.totalChildVisibleSubtreeCount;if(n.subtreeNodeCount=o,ue(n,2)){n.visibleSubtreeCount=s;return}n.visibleSubtreeCount=yt(e,t)!=null?s:Ce(e,t,n)?1+s:1}function Xh(e,t,n){let r=ne(e,t);return r.length===0?n:`${r}${n}`}function wn(e){return e!=null&&!ue(e,4)}function ni(e,t){let n=e.snapshot.nodes[t];if(!wn(n)||!D(n)||ue(n,2))return null;return n}function Qh(e){let t=0;for(let[n,r]of e.pathCacheByNodeId){if(r.version!==e.pathCacheVersion)continue;if(!wn(e.snapshot.nodes[n]))continue;t+=1}return t}function Jh(e){return Math.max(0,e.valueById.length-1)}function al(e){return{activeNodeCount:e.activeNodeCount,cachedPathEntryCount:Qh(e),loadInfoEntryCount:e.directoryLoadInfoById.size,segmentCount:Jh(e.snapshot.segmentTable),totalNodeSlotCount:Math.max(0,e.snapshot.nodes.length-1)}}function Zh(e,t,n,r){return{activeNodeCountAfter:r.activeNodeCount,activeNodeCountBefore:n.activeNodeCount,cachedPathEntryCountAfter:r.cachedPathEntryCount,cachedPathEntryCountBefore:n.cachedPathEntryCount,idsPreserved:t,loadInfoEntryCountAfter:r.loadInfoEntryCount,loadInfoEntryCountBefore:n.loadInfoEntryCount,mode:e,reclaimedCachedPathEntryCount:n.cachedPathEntryCount-r.cachedPathEntryCount,reclaimedLoadInfoEntryCount:n.loadInfoEntryCount-r.loadInfoEntryCount,reclaimedNodeSlotCount:n.totalNodeSlotCount-r.totalNodeSlotCount,reclaimedSegmentCount:n.segmentCount-r.segmentCount,segmentCountAfter:r.segmentCount,segmentCountBefore:n.segmentCount,totalNodeSlotCountAfter:r.totalNodeSlotCount,totalNodeSlotCountBefore:n.totalNodeSlotCount}}function ll(e){let t=[],n=[];for(let r of e.collapsedDirectoryIds)if(ni(e,r)!=null)t.push(ne(e,r));for(let r of e.expandedDirectoryIds)if(ni(e,r)!=null)n.push(ne(e,r));return{collapsedPaths:t,expandedPaths:n}}function cl(e){let t=[];for(let[n,r]of e.directoryLoadInfoById){if(ni(e,n)==null||Nt(e,n)==="loaded")continue;t.push({info:{activeAttemptId:null,errorMessage:r.errorMessage,nextAttemptId:r.nextAttemptId,state:r.state},path:ne(e,n)})}return t}function ul(e,t){e.collapsedDirectoryIds.clear(),e.hasCollapsedDirectoryOverrides=!1,e.expandedDirectoryIds.clear();for(let n of t.expandedPaths){let r=Le(e,n);if(r==null)continue;At(e,r,!0,M(e,r))}for(let n of t.collapsedPaths){let r=Le(e,n);if(r==null)continue;At(e,r,!1,M(e,r))}}function dl(e,t){e.directoryLoadInfoById.clear();for(let n of t){let r=Le(e,n.path);if(r==null)continue;if(ni(e,r)==null)continue;e.directoryLoadInfoById.set(r,{activeAttemptId:null,errorMessage:n.info.errorMessage,nextAttemptId:n.info.nextAttemptId,state:n.info.state})}}function ef(e){e.pathCacheVersion+=1,e.pathCacheByNodeId.clear(),e.pathCacheByNodeId.set(e.snapshot.rootId,{path:"",version:e.pathCacheVersion})}function tf(e){let t=e.snapshot.segmentTable,n=Jr();for(let r of e.snapshot.nodes){if(!wn(r))continue;if(ue(r,2)){r.nameId=0;continue}r.nameId=rt(n,qe(t,r.nameId))}e.snapshot.segmentTable=n}function nf(e){for(let[t,n]of e.snapshot.directories){let r=e.snapshot.nodes[t];if(!wn(r)||!D(r)){e.snapshot.directories.delete(t);continue}let i=n.childIds.filter((o)=>{let s=e.snapshot.nodes[o];return wn(s)&&s.parentId===t});n.childIds=i,n.childIdByNameId=new Map(i.map((o)=>[M(e,o).nameId,o])),n.childPositionById=new Map(i.map((o,s)=>[o,s])),Yt(e.snapshot.nodes,n)}}function rf(e){let t=e.snapshot.nodes.length-1;while(t>e.snapshot.rootId){let n=e.snapshot.nodes[t];if(wn(n))break;t-=1}e.snapshot.nodes.length=t+1}function of(e){let t=ll(e),n=cl(e);E(e.instrumentation,"store.cleanup.stable.clearPathCaches",()=>ef(e)),E(e.instrumentation,"store.cleanup.stable.rebuildSegmentTable",()=>tf(e)),E(e.instrumentation,"store.cleanup.stable.rebuildDirectoryIndexes",()=>nf(e)),E(e.instrumentation,"store.cleanup.stable.trimTrailingRemovedNodeSlots",()=>rf(e)),E(e.instrumentation,"store.cleanup.stable.restoreExpansionOverrides",()=>ul(e,t)),E(e.instrumentation,"store.cleanup.stable.restoreDirectoryLoadInfos",()=>dl(e,n)),E(e.instrumentation,"store.cleanup.stable.recomputeCounts",()=>ur(e,e.snapshot.rootId))}function sf(e){let t=ll(e),n=cl(e),r=E(e.instrumentation,"store.cleanup.aggressive.listPaths",()=>ti(e)),i=ca({...e.snapshot.options},e.instrumentation),o=E(e.instrumentation,"store.cleanup.aggressive.rebuildSnapshot",()=>{let s=new ei(i);return s.appendPaths(r),s.finish()});e.snapshot=o,e.activeNodeCount=o.nodes.length-1,e.pathCacheByNodeId=new Map([[o.rootId,{path:"",version:0}]]),e.pathCacheVersion=0,E(e.instrumentation,"store.cleanup.aggressive.restoreExpansionOverrides",()=>ul(e,t)),E(e.instrumentation,"store.cleanup.aggressive.restoreDirectoryLoadInfos",()=>dl(e,n)),E(e.instrumentation,"store.cleanup.aggressive.recomputeCounts",()=>ur(e,e.snapshot.rootId))}function hl(e){for(let t of e.directoryLoadInfoById.values())if(t.state==="loading"&&t.activeAttemptId!=null)return!0;return!1}function fl(e,t){let n=al(e);if(t==="stable")E(e.instrumentation,"store.cleanup.stable",()=>of(e));else E(e.instrumentation,"store.cleanup.aggressive",()=>sf(e));let r=al(e);return Zh(t,t==="stable",n,r)}var af=64;function lf(e,t){let n=t+2;if(n<=e.length)return e;let r=e.length;while(r<n)r*=2;let i=new Int32Array(r);return i.fill(-1),i.set(e),i}function xe(e){return M(e,e.snapshot.rootId).visibleSubtreeCount}function vl(e,t,n,r){let i=M(e,t.terminalNodeId),o=Math.max(1,i.visibleSubtreeCount);return Math.min(r-1,n+o-1)}function cf(e,t,n,r){return{ancestorPaths:r,index:t.index,posInSet:t.posInSet,row:dr(e,t.cursor),setSize:t.setSize,subtreeEndIndex:vl(e,t.cursor,t.index,n)}}function yl(e,t,n,r,i,o){let s=ae(e,t),{childIndex:a,childVisibleIndex:l,localVisibleIndex:c}=Yr(e.snapshot.nodes,s,n),d=s.childIds[a];if(d==null)throw Error(`Visible index ${String(n)} is out of range`);return uf(e,d,c,r+l,i+1,a,s.childIds.length,o)}function uf(e,t,n,r,i,o,s,a){if(!D(M(e,t))){if(n===0)return{ancestors:a,cursor:{headNodeId:t,terminalNodeId:t,visibleDepth:i},index:r,posInSet:o,setSize:s};throw Error(`Visible index ${String(n)} is out of range for file`)}let l=_l(e,t,i);if(n===0)return{ancestors:a,cursor:l,index:r,posInSet:o,setSize:s};let c=M(e,l.terminalNodeId);if(!D(c)||!Ce(e,l.terminalNodeId,c))throw Error(`Visible index ${String(n)} is out of range for collapsed directory`);return yl(e,l.terminalNodeId,n-1,r+1,l.visibleDepth,[...a,{cursor:l,index:r,posInSet:o,setSize:s}])}function bl(e,t){let n=xe(e);if(t<0||t>=n)return null;let r=yl(e,e.snapshot.rootId,t,0,-1,[]),i=r.ancestors.map((s)=>ne(e,s.cursor.terminalNodeId)),o=null;return{ancestorPaths:i,get ancestorRows(){if(o!=null)return o;let s=[],a=[];for(let l of r.ancestors){let c=cf(e,l,n,[...a]);s.push(c),a.push(c.row.path)}return o=s,o},index:r.index,posInSet:r.posInSet,row:dr(e,r.cursor),setSize:r.setSize,subtreeEndIndex:vl(e,r.cursor,r.index,n)}}function wl(e,t,n){let r=e.instrumentation,i=xe(e);if(i<=0||n<t)return[];let o=Math.max(0,Math.min(t,i-1)),s=Math.max(o,Math.min(n,i-1));if(r==null){if(o===0)return ff(e,s+1);let f=[],u=pl(e,o);for(let m=o;m<=s&&u!=null;m++){let p=dr(e,u);f.push(p),u=ml(e,u)}return f}let a=[],l=0,c=0,d=E(r,"store.getVisibleSlice.selectFirstRow",()=>pl(e,o));for(let f=o;f<=s&&d!=null;f++){let u=E(r,"store.getVisibleSlice.materializeRow",()=>dr(e,d));if(a.push(u),u.isFlattened)l++,c+=u.flattenedSegments?.length??0;d=E(r,"store.getVisibleSlice.advanceCursor",()=>ml(e,d))}return yn(r,"workload.visibleRowsRead",a.length),yn(r,"workload.flattenedRowsRead",l),yn(r,"workload.flattenedSegmentsRead",c),a}function Co(e,t=xe(e)){let n=e.instrumentation;if(n==null)return gl(e,t);return E(n,"store.getVisibleTreeProjection",()=>gl(e,t))}function Il(e){return hf(Co(e))}function Sl(e,t){let n=Le(e,t);if(n==null||n===e.snapshot.rootId)return null;if(D(M(e,n))&&bt(e,n)!==n)return null;let r=0,i=n,{nodes:o,rootId:s}=e.snapshot;while(i!==s){let a=M(e,i).parentId,l=ae(e,a),c=mn(l).get(i);if(c==null)throw Error(`Child ${String(i)} was not found in its parent index`);if(r+=oa(o,l,c),a!==s){let d=M(e,a),f=yt(e,a);if(!Ce(e,a,d)&&f!==i)return null;if(bt(e,a)===a)r+=1}i=a}return r}function Cl(e,t){let n=Le(e,t);if(n==null)throw Error(`Path does not exist: "${t}"`);let r=M(e,n);if(!D(r))throw Error(`Path is not a directory: "${t}"`);if(Ce(e,n,r))return null;return At(e,n,!0,r),Ft(e,n),Wa({affectedAncestorIds:We(e,n),affectedNodeIds:[n],path:t,projectionChanged:!0})}function xl(e,t){let n=Le(e,t);if(n==null)throw Error(`Path does not exist: "${t}"`);let r=M(e,n);if(!D(r))throw Error(`Path is not a directory: "${t}"`);if(!Ce(e,n,r))return null;return At(e,n,!1,r),Ft(e,n),ja({affectedAncestorIds:We(e,n),affectedNodeIds:[n],path:t,projectionChanged:!0})}function pl(e,t){if(t<0||t>=xe(e))return null;return kl(e,e.snapshot.rootId,t,-1)}function kl(e,t,n,r){let i=ae(e,t),o=e.instrumentation,{childIndex:s,localVisibleIndex:a}=o==null?Yr(e.snapshot.nodes,i,n):E(o,"store.getVisibleSlice.selectChildIndex",()=>Yr(e.snapshot.nodes,i,n)),l=i.childIds[s];if(l!=null)return So(e,l,a,r+1);throw Error(`Visible index ${String(n)} is out of range`)}function So(e,t,n,r){if(!D(M(e,t))){if(n===0)return{headNodeId:t,terminalNodeId:t,visibleDepth:r};throw Error(`Visible index ${String(n)} is out of range for file`)}let i=_l(e,t,r);if(n===0)return i;let o=M(e,i.terminalNodeId);if(!D(o)||!Ce(e,i.terminalNodeId,o))throw Error(`Visible index ${String(n)} is out of range for collapsed directory`);return kl(e,i.terminalNodeId,n-1,i.visibleDepth)}function _l(e,t,n){if(!D(M(e,t)))return{headNodeId:t,terminalNodeId:t,visibleDepth:n};if(e.instrumentation==null)return{headNodeId:t,terminalNodeId:bt(e,t),visibleDepth:n};return{headNodeId:t,terminalNodeId:E(e.instrumentation,"store.getVisibleSlice.flatten.resolveTerminalDirectory",()=>bt(e,t)),visibleDepth:n}}function df(e,t){let n=M(e,t);if(!D(n))return!0;let r=n.parentId;if(r===e.snapshot.rootId)return!0;return yt(e,r)!==t}function ml(e,t){let n=M(e,t.terminalNodeId);if(D(n)){let o=ae(e,t.terminalNodeId);if(Ce(e,t.terminalNodeId,n)&&o.childIds.length>0){let s=o.childIds[0];return s==null?null:So(e,s,0,t.visibleDepth+1)}}let{terminalNodeId:r,visibleDepth:i}=t;while(!0){let o=M(e,r);if(r===e.snapshot.rootId)return null;let s=o.parentId,a=ae(e,s),l=mn(a).get(r)??-1;if(l<0)throw Error(`Child ${String(r)} was not found in its parent index`);let c=a.childIds[l+1]??null;if(c!=null)return So(e,c,0,i);if(df(e,r))i--;r=s}}function hf(e){let t=e.paths.length,n=Array(t);for(let r=0;r<t;r+=1){let i=e.getParentIndex(r);n[r]={index:r,parentPath:i>=0?e.paths[i]??null:null,path:e.paths[r]??"",posInSet:e.posInSetByIndex[r]??0,setSize:e.setSizeByIndex[r]??0}}return{getParentIndex:e.getParentIndex,rows:n,get visibleIndexByPath(){return e.visibleIndexByPath}}}function gl(e,t){let n=Array(t),r=new Int32Array(t),i=new Int32Array(t),o=new Int32Array(t),s=new Int32Array(af);s.fill(-1);let a=0,{nodes:l,directories:c,segmentTable:d}=e.snapshot,f=[[c.get(e.snapshot.rootId),0,-1,""]],u=e.snapshot.options.flattenEmptyDirectories,m=e.pathCacheByNodeId,p=e.pathCacheVersion,g=d.valueById;while(f.length>0&&a<t){let w=f[f.length-1],x=w[0];if(w[1]>=x.childIds.length){f.pop();continue}let P=w[1],O=x.childIds[w[1]++],pe=l[O],G=w[2]+1,me=w[3];s=lf(s,G);let j,N=O;if(!D(pe)){let W=m.get(O);j=W!=null&&W.version===p?W.path:`${me}${g[pe.nameId]}`}else N=u?bt(e,O):O,j=N===O?`${me}${g[pe.nameId]}/`:ne(e,N);r[a]=s[G],n[a]=j,i[a]=P,o[a]=x.childIds.length,s[G+1]=a,a+=1;let re=l[N];if(re!=null&&D(re)&&Ce(e,N,re))f.push([c.get(N),0,G,j])}if(a<t)n.length=a;let v=r.subarray(0,a),S=i.subarray(0,a),C=o.subarray(0,a),y=null;return{getParentIndex(w){return w<0||w>=a?-1:v[w]??-1},paths:n,posInSetByIndex:S,setSizeByIndex:C,get visibleIndexByPath(){if(y==null){y=new Map;for(let w=0;w<a;w+=1)y.set(n[w]??"",w)}return y}}}function ff(e,t){let n=Array(t),r=0,{nodes:i,directories:o,segmentTable:s}=e.snapshot,a=[[o.get(e.snapshot.rootId),0,-1]],l=s.valueById,c=e.snapshot.options.flattenEmptyDirectories,d=e.pathCacheByNodeId,f=e.pathCacheVersion;while(a.length>0&&r<t){let u=a[a.length-1],m=u[0];if(u[1]>=m.childIds.length){a.pop();continue}let p=m.childIds[u[1]++],g=i[p],v=u[2]+1;if(!D(g)){let w=d.get(p);n[r++]={depth:v,flattenedSegments:void 0,hasChildren:!1,id:p,isExpanded:!1,isFlattened:!1,isLoading:!1,kind:"file",loadState:void 0,name:l[g.nameId],path:w!=null&&w.version===f?w.path:ne(e,p)};continue}let S=c?bt(e,p):p,C={headNodeId:p,terminalNodeId:S,visibleDepth:v};n[r++]=dr(e,C);let y=i[S];if(y!=null&&D(y)&&Ce(e,S,y))a.push([o.get(S),0,v])}if(r<t)n.length=r;return n}function dr(e,t){let n=M(e,t.terminalNodeId),r=D(n)?pf(e,t):null,i=ne(e,t.terminalNodeId),o=qe(e.snapshot.segmentTable,n.nameId),s=D(n)&&ae(e,t.terminalNodeId).childIds.length>0,a=t.headNodeId!==t.terminalNodeId,l=e.instrumentation,c=a?l==null?bn(e,t.headNodeId).map((d)=>{let f=M(e,d);return{isTerminal:d===t.terminalNodeId,name:qe(e.snapshot.segmentTable,f.nameId),nodeId:d,path:ne(e,d)}}):E(l,"store.getVisibleSlice.flatten.collectSegments",()=>bn(e,t.headNodeId).map((d)=>{let f=M(e,d);return{isTerminal:d===t.terminalNodeId,name:qe(e.snapshot.segmentTable,f.nameId),nodeId:d,path:ne(e,d)}})):void 0;return{depth:t.visibleDepth,flattenedSegments:c,hasChildren:s,id:t.terminalNodeId,isExpanded:D(n)&&Ce(e,t.terminalNodeId,n),isFlattened:a,isLoading:r==="loading",kind:D(n)?"directory":"file",loadState:r==null||r==="loaded"?void 0:r,name:o,path:i}}function pf(e,t){if(t.headNodeId===t.terminalNodeId)return Nt(e,t.terminalNodeId);let n=bn(e,t.headNodeId),r=!1,i=!1;for(let o of n){let s=Nt(e,o);if(s==="loading")return"loading";if(s==="error"){i=!0;continue}if(s==="unloaded")r=!0}if(i)return"error";if(r)return"unloaded";return"loaded"}var El=8;function Tl(e){let{nodes:t,directories:n,rootId:r,options:i}=e,o=t.length,s=new Int32Array(o),a=new Int32Array(o),l=new Int32Array(o),c=new Int32Array(o),d=new Int32Array(o),f=new Int32Array(o),u=new Int32Array(o);for(let v=0;v<o;v+=1){let S=t[v];if(S==null)continue;s[v]=S.parentId,a[v]=S.nameId,l[v]=S.depthAndFlags,c[v]=S.subtreeNodeCount,d[v]=S.visibleSubtreeCount}let m=0;for(let v of n.values())m+=v.childIds.length;let p=new Int32Array(m),g=0;for(let[v,S]of n){let C=S.childIds;f[v]=g,u[v]=C.length;for(let y=0;y<C.length;y+=1)p[g]=C[y],g+=1}return{nodeCount:o,rootId:r,flattenEmptyDirectories:i.flattenEmptyDirectories===!0,parentId:s,nameId:a,depthAndFlags:l,subtreeNodeCount:c,visibleSubtreeCount:d,childStart:f,childCount:u,childIdsFlat:p}}function Pl(e){let{nodeCount:t,rootId:n,flattenEmptyDirectories:r,depthAndFlags:i,subtreeNodeCount:o,visibleSubtreeCount:s,childStart:a,childCount:l,childIdsFlat:c}=e;for(let p=t-1;p>=1;p-=1){if((i[p]&El)===0)continue;let g=a[p],v=l[p],S=0,C=0;for(let w=0;w<v;w+=1){let x=c[g+w];S+=o[x],C+=s[x]}o[p]=1+S;let y;if(r&&v===1)y=(i[c[g]]&El)!==0?C:1+C;else y=1+C;s[p]=y}let d=a[n],f=l[n],u=0,m=0;for(let p=0;p<f;p+=1){let g=c[d+p];u+=o[g],m+=s[g]}o[n]=1+u,s[n]=m}function mf(e){let{directories:t,nodes:n,options:r,rootId:i,presortedDirectoryNodeIds:o}=e.snapshot,s=r.flattenEmptyDirectories===!0,a=(m)=>{let p=n[m];if(p==null||!D(p))return;let g=t.get(m);if(g==null)throw Error(`Unknown directory child index for node ${String(m)}`);let v=g.childIds,S=v.length,C=0,y=0;for(let x=0;x<S;x++){let P=v[x];if(P==null)continue;let O=n[P];C+=O.subtreeNodeCount,y+=O.visibleSubtreeCount}if(g.totalChildSubtreeNodeCount=C,g.totalChildVisibleSubtreeCount=y,S>=128)Mt(n,g);p.subtreeNodeCount=1+C;let w;if(s&&S===1){let x=n[v[0]];w=x!=null&&D(x)?y:1+y}else w=1+y;p.visibleSubtreeCount=w};if(o!=null)for(let m=o.length-1;m>=0;m--)a(o[m]);else for(let m=n.length-1;m>=1;m--)a(m);let l=n[i],c=t.get(i);if(l==null||c==null)return;let d=c.childIds,f=0,u=0;for(let m=0;m<d.length;m++){let p=d[m];if(p==null)continue;let g=n[p];f+=g.subtreeNodeCount,u+=g.visibleSubtreeCount}c.totalChildSubtreeNodeCount=f,c.totalChildVisibleSubtreeCount=u,Mt(n,c),l.subtreeNodeCount=1+f,l.visibleSubtreeCount=u}function gf(e){let{directories:t,nodes:n,rootId:r}=e.snapshot,i=Tl(e.snapshot);Pl(i);let{subtreeNodeCount:o,visibleSubtreeCount:s}=i;for(let a=0;a<n.length;a+=1){let l=n[a];if(l==null)continue;l.subtreeNodeCount=o[a],l.visibleSubtreeCount=s[a]}for(let[a,l]of t){let c=l.childIds,d=c.length,f=0,u=0;for(let m=0;m<d;m++){let p=c[m];if(p==null)continue;let g=n[p];f+=g.subtreeNodeCount,u+=g.visibleSubtreeCount}if(l.totalChildSubtreeNodeCount=f,l.totalChildVisibleSubtreeCount=u,a===r||d>=128)Mt(n,l)}}function vf(e){return e.initialExpansion==="open"&&(e.initialExpandedPaths==null||e.initialExpandedPaths.length===0)}var hr=class e{#e;constructor(t={}){let n=ar(t),r=E(n,"store.builder.create",()=>new ei(t));if(t.preparedInput!=null){let a=Ca(t.preparedInput);if(a!=null)r.appendPresortedPaths(a,xa(t.preparedInput));else r.appendPreparedPaths(Sa(t.preparedInput),!1)}else{let a=t.paths??[];if(t.presorted===!0)r.appendPaths(a);else r.appendPreparedPaths(E(n,"store.preparePathEntries",()=>Zr(a,t)))}let i=E(n,"store.builder.finish",()=>r.finish({skipSubtreeCountPass:!0})),o=E(n,"store.state.detectAllDirectoriesExpanded",()=>(t.initialExpansion??"closed")==="closed"&&r.didMatchAllInitialExpandedPaths());if(this.#e=E(n,"store.state.create",()=>ka(i,o?"open":t.initialExpansion??"closed",n)),o)this.#e.collapseNewDirectoriesByDefault=!0;let s=o?this.#e.snapshot.directories.size-1:E(n,"store.state.initializeExpandedPaths",()=>this.initializeExpandedPaths(t.initialExpandedPaths));if(o||vf(t)||(t.initialExpansion??"closed")==="closed"&&s===this.#e.snapshot.directories.size-1||(t.initialExpandedPaths?.length??0)>0&&E(n,"store.state.checkAllDirectoriesExpanded",()=>this.hasAllDirectoriesExpanded()))if(t.useSoaCountSweep===!0)E(n,"store.state.initializeOpenVisibleCountsViaSoa",()=>gf(this.#e));else E(n,"store.state.initializeOpenVisibleCounts",()=>mf(this.#e));else E(n,"store.state.recomputeCounts",()=>ur(this.#e,this.#e.snapshot.rootId))}static preparePaths(t,n={}){return ba(t,n)}static prepareInput(t,n={}){return wa(t,n)}static preparePresortedInput(t){return Ia(t)}list(t){return E(this.#e.instrumentation,"store.list",()=>ti(this.#e,t))}add(t){E(this.#e.instrumentation,"store.add",()=>{let n=xe(this.#e);Xe(this.#e,Ne(this.#e,n,go(this.#e,t)))})}remove(t,n={}){E(this.#e.instrumentation,"store.remove",()=>{let r=xe(this.#e);Xe(this.#e,Ne(this.#e,r,vo(this.#e,t,n)))})}move(t,n,r={}){E(this.#e.instrumentation,"store.move",()=>{let i=xe(this.#e),o=yo(this.#e,t,n,r);if(o!=null)Xe(this.#e,Ne(this.#e,i,o))})}batch(t){Qa(this.#e,()=>{if(typeof t==="function"){t(this);return}for(let n of t)switch(n.type){case"add":this.add(n.path);break;case"remove":this.remove(n.path,{recursive:n.recursive});break;case"move":this.move(n.from,n.to,{collision:n.collision});break}})}getVisibleCount(){return E(this.#e.instrumentation,"store.getVisibleCount",()=>xe(this.#e))}getVisibleSlice(t,n){return E(this.#e.instrumentation,"store.getVisibleSlice",()=>wl(this.#e,t,n))}getVisibleRowContext(t){return E(this.#e.instrumentation,"store.getVisibleRowContext",()=>bl(this.#e,t))}getVisibleTreeProjection(){return Il(this.#e)}getVisibleTreeProjectionData(t){return Co(this.#e,t)}getVisibleIndex(t){return E(this.#e.instrumentation,"store.getVisibleIndex",()=>Sl(this.#e,t))}getPathInfo(t){return E(this.#e.instrumentation,"store.getPathInfo",()=>{let n=Le(this.#e,t);if(n==null)return null;let r=M(this.#e,n);return{depth:Ve(r),kind:D(r)?"directory":"file",path:ne(this.#e,n)}})}isExpanded(t){return E(this.#e.instrumentation,"store.isExpanded",()=>{let n=this.requireDirectoryNodeId(t),r=M(this.#e,n);return Ce(this.#e,n,r)})}expand(t){E(this.#e.instrumentation,"store.expand",()=>{let n=xe(this.#e),r=Cl(this.#e,t);if(r!=null)Xe(this.#e,Ne(this.#e,n,r))})}collapse(t){E(this.#e.instrumentation,"store.collapse",()=>{let n=xe(this.#e),r=xl(this.#e,t);if(r!=null)Xe(this.#e,Ne(this.#e,n,r))})}on(t,n){return Va(this.#e,t,n)}getDirectoryLoadState(t){let n=this.requireDirectoryNodeId(t);return Nt(this.#e,n)}markDirectoryUnloaded(t){E(this.#e.instrumentation,"store.markDirectoryUnloaded",()=>{let n=this.requireDirectoryNodeId(t);if(ae(this.#e,n).childIds.length>0)throw Error(`Cannot mark a directory with known children as unloaded: "${t}"`);let r=xe(this.#e);Ra(this.#e,n),Xe(this.#e,Ne(this.#e,r,$a({affectedAncestorIds:We(this.#e,n),affectedNodeIds:[n],path:t,projectionChanged:this.isDirectoryProjectionVisible(n)})))})}beginChildLoad(t){return E(this.#e.instrumentation,"store.beginChildLoad",()=>{let n=this.requireDirectoryNodeId(t),r=xe(this.#e),i=Pa(this.#e,n);return Xe(this.#e,Ne(this.#e,r,Ua({affectedAncestorIds:We(this.#e,n),affectedNodeIds:[n],attemptId:i.attemptId,path:t,projectionChanged:this.isDirectoryProjectionVisible(n),reused:i.reused}))),i})}applyChildPatch(t,n){return E(this.#e.instrumentation,"store.applyChildPatch",()=>{let r=this.resolveActiveDirectoryNodeId(t.nodeId);if(r==null||Nt(this.#e,r)!=="loading"||!Ma(this.#e,r,t.attemptId))return!1;let i=ne(this.#e,r);this.validateChildPatch(i,n);let o=xe(this.#e),s=[];for(let l of n.operations){yf(i,l);let c=xe(this.#e);switch(l.type){case"add":s.push(Ne(this.#e,c,go(this.#e,l.path)));break;case"remove":s.push(Ne(this.#e,c,vo(this.#e,l.path,{recursive:l.recursive})));break;case"move":{let d=yo(this.#e,l.from,l.to,{collision:l.collision});if(d!=null)s.push(Ne(this.#e,c,d));break}}}let a=s.some((l)=>l.projectionChanged)||this.isDirectoryProjectionVisible(r);return Xe(this.#e,Ne(this.#e,o,Ka({affectedAncestorIds:We(this.#e,r),affectedNodeIds:[r],attemptId:t.attemptId,childEvents:s,path:ne(this.#e,r),projectionChanged:a}))),!0})}completeChildLoad(t){return E(this.#e.instrumentation,"store.completeChildLoad",()=>{let n=this.resolveActiveDirectoryNodeId(t.nodeId);if(n==null)return!1;let r=xe(this.#e),i=Da(this.#e,n,t.attemptId);return Xe(this.#e,Ne(this.#e,r,Ga({affectedAncestorIds:We(this.#e,n),affectedNodeIds:[n],attemptId:t.attemptId,path:ne(this.#e,n),projectionChanged:this.isDirectoryProjectionVisible(n),stale:!i}))),i})}failChildLoad(t,n){return E(this.#e.instrumentation,"store.failChildLoad",()=>{let r=this.resolveActiveDirectoryNodeId(t.nodeId);if(r==null)return!1;let i=xe(this.#e),o=Aa(this.#e,r,t.attemptId,n);return Xe(this.#e,Ne(this.#e,i,Ya({affectedAncestorIds:We(this.#e,r),affectedNodeIds:[r],attemptId:t.attemptId,errorMessage:n,path:ne(this.#e,r),projectionChanged:this.isDirectoryProjectionVisible(r),stale:!o}))),o})}cleanup(t={}){return E(this.#e.instrumentation,"store.cleanup",()=>{if(this.#e.transactionStack.length>0)throw Error("Cleanup cannot run during an open batch or transaction.");if(hl(this.#e))throw Error("Cleanup cannot run while directory loads are active.");let n=xe(this.#e),r=fl(this.#e,t.mode??"stable");return Xe(this.#e,Ne(this.#e,n,Xa({...r,affectedAncestorIds:[],affectedNodeIds:[],projectionChanged:r.idsPreserved===!1}))),r})}getNodeCount(){return this.#e.activeNodeCount}initializeExpandedPaths(t){if(t==null||t.length===0)return 0;let n=0,r=[],i=[],o=0,s=null,a=this.#e.snapshot.segmentTable,l=a.valueById,c=this.#e.snapshot.nodes,d=new Map;for(let f of t){if(s!=null&&f<s)s=null,o=0,r.length=0,i.length=0;let u=f.length>0&&f.charCodeAt(f.length-1)===47?f.length-1:f.length;if(u===0){s=f,o=u,r.length=0,i.length=0;continue}let m=0,p=0;if(s!=null){let y=Math.min(u,o),w=!0;for(let x=0;x<y;x+=1){let P=f.charCodeAt(x);if(P!==s.charCodeAt(x)){w=!1;break}if(P===47)m+=1,p=x+1}if(w){if(y===o&&u>y&&f.charCodeAt(y)===47)m+=1,p=y+1;else if(y===u&&o>y&&s.charCodeAt(y)===47)m+=1,p=u+1}m=Math.min(m,i.length)}let g=m===0?this.#e.snapshot.rootId:i[m-1]??this.#e.snapshot.rootId,v=m,S=!0,C=p;while(C<=u){let y=f.indexOf("/",C),w=y===-1||y>u?u:y,x=f.slice(C,w),P=ae(this.#e,g).childIds,O=v===m?r[v]??0:0,pe=O,G,me=d.get(x)??Xt(x);d.set(x,me);let j=(N,re)=>{for(pe=N;pe<re;pe+=1){let W=P[pe],Ee=c[W],U=l[Ee.nameId];if(U===x)return G=W,!0;let de=lr(cr(a,Ee.nameId),me);if(de>0||de===0&&U>x)return!1}return!1};if(!j(O,P.length)&&O>0)j(0,O);if(G===void 0){S=!1;break}if(!D(M(this.#e,G))){S=!1;break}if(r[v]=pe,i[v]=G,g=G,v+=1,w===u)break;C=w+1}if(s=f,o=u,r.length=v,i.length=v,!S){s=null,o=0,r.length=0,i.length=0;continue}for(let y=m;y<v;y+=1){let w=i[y];if(w==null)continue;let x=M(this.#e,w);if(Ce(this.#e,w,x))continue;At(this.#e,w,!0,x),n+=1}}return n}hasAllDirectoriesExpanded(){for(let t of this.#e.snapshot.directories.keys()){if(t===this.#e.snapshot.rootId)continue;let n=M(this.#e,t);if(!Ce(this.#e,t,n))return!1}return!0}requireDirectoryNodeId(t){let n=Le(this.#e,t);if(n==null)throw Error(`Path does not exist: "${t}"`);if(!D(M(this.#e,n)))throw Error(`Path is not a directory: "${t}"`);return n}resolveActiveDirectoryNodeId(t){try{if(!D(M(this.#e,t)))throw Error(`Node is not a directory: ${String(t)}`);return t}catch{return null}}isDirectoryProjectionVisible(t){let n=t;while(n!==this.#e.snapshot.rootId){let r=M(this.#e,n).parentId;if(r!==this.#e.snapshot.rootId){let i=M(this.#e,r),o=yt(this.#e,r);if(!Ce(this.#e,r,i)&&o!==n)return!1}n=r}return!0}validateChildPatch(t,n){new e({paths:this.list(t),presorted:!0,sort:this.#e.snapshot.options.sort}).batch(n.operations)}};function yf(e,t){switch(t.type){case"add":case"remove":if(!t.path.startsWith(e)||t.path===e)throw Error(`Child patch operation must stay within ${e}: "${t.path}"`);break;case"move":if(!t.from.startsWith(e)||!t.to.startsWith(e)||t.from===e||t.to===e)throw Error(`Child patch move must stay within ${e}: "${t.from}" -> "${t.to}"`);break}}var bf=[`<symbol id="file-tree-builtin-bash" viewBox="0 0 16 16">
|
|
2
2
|
<path fill="currentColor" d="M8 1C2.24 1 1 2.24 1 8s1.24 7 7 7 7-1.24 7-7-1.24-7-7-7" class="bg" opacity=".2"/>
|
|
3
3
|
<path fill="currentColor" d="M11.5 11a.5.5 0 0 1 0 1h-3a.5.5 0 0 1 0-1zM7 6.75C7 6.42 6.64 6 6 6s-1 .42-1 .75q-.01.25.22.41.26.21.89.35.74.14 1.28.53c.37.29.61.7.61 1.21 0 .87-.68 1.5-1.5 1.7v.55a.5.5 0 0 1-1 0v-.56c-.82-.18-1.5-.82-1.5-1.69a.5.5 0 0 1 1 0c0 .33.36.75 1 .75s1-.42 1-.75q.01-.25-.22-.41a2 2 0 0 0-.89-.35q-.74-.14-1.28-.53A1.5 1.5 0 0 1 4 6.75c0-.87.68-1.5 1.5-1.7V4.5a.5.5 0 0 1 1 0v.56c.82.18 1.5.82 1.5 1.69a.5.5 0 0 1-1 0" class="fg-stroke"/>
|
|
4
4
|
</symbol>`,`<symbol id="file-tree-builtin-c" viewBox="0 0 16 16">
|