@p4code/cli 0.1.45 → 0.1.46

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/dist/bin.mjs CHANGED
@@ -237,7 +237,7 @@ const make$87 = () => {
237
237
  const layer$79 = Layer.sync(NetService, make$87);
238
238
  //#endregion
239
239
  //#region package.json
240
- var version = "0.1.45";
240
+ var version = "0.1.46";
241
241
  //#endregion
242
242
  //#region src/config.ts
243
243
  /**
@@ -63283,6 +63283,18 @@ function normalizeClaudeStreamMessages(cause) {
63283
63283
  const squashed = toMessage(Cause.squash(cause), "").trim();
63284
63284
  return squashed.length > 0 ? [squashed] : [];
63285
63285
  }
63286
+ const CLAUDE_MISSING_PATH_PATTERN = /path "([^"]+)" does not exist/i;
63287
+ /**
63288
+ * Raw cause text never reaches a runtime event: it is CLI output that can carry
63289
+ * credential material, which is why the event payload stays structural. But the
63290
+ * wrapper detail alone ("Claude runtime stream failed.") reads the same whether
63291
+ * the CLI crashed or the thread's directory was deleted, so recognized failure
63292
+ * shapes get a curated sentence built from matched fragments only.
63293
+ */
63294
+ function describeProcessFailure(failure) {
63295
+ const missingPath = CLAUDE_MISSING_PATH_PATTERN.exec(toMessage(failure.cause, ""))?.[1];
63296
+ return missingPath === void 0 ? failure.detail : `${failure.detail} Directory does not exist: ${missingPath}`;
63297
+ }
63286
63298
  function getEffectiveClaudeAgentEffort(effort, model) {
63287
63299
  const normalized = normalizeClaudeCliEffort(effort, model);
63288
63300
  return normalized ? normalized : null;
@@ -65388,7 +65400,8 @@ const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (claudeSettin
65388
65400
  if (context.turnState) yield* completeTurn(context, "interrupted", "Claude runtime interrupted.");
65389
65401
  } else {
65390
65402
  const failures = exit.cause.reasons.flatMap((reason) => Cause.isFailReason(reason) ? [reason.error] : []);
65391
- const message = failures[0]?.detail ?? "Claude runtime stream failed.";
65403
+ const firstFailure = failures[0];
65404
+ const message = firstFailure === void 0 ? "Claude runtime stream failed." : describeProcessFailure(firstFailure);
65392
65405
  yield* emitRuntimeError(context, message, {
65393
65406
  failureCount: failures.length,
65394
65407
  failureTags: failures.map((failure) => failure._tag)
@@ -65481,6 +65494,13 @@ const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (claudeSettin
65481
65494
  operation: "startSession",
65482
65495
  issue: `Expected provider '${PROVIDER$6}' but received '${input.provider}'.`
65483
65496
  });
65497
+ if (input.cwd !== void 0 && input.cwd.length > 0) {
65498
+ if (!(yield* fileSystem.exists(input.cwd).pipe(Effect.orElseSucceed(() => false)))) return yield* new ProviderAdapterValidationError({
65499
+ provider: PROVIDER$6,
65500
+ operation: "startSession",
65501
+ issue: `Working directory does not exist: ${input.cwd}`
65502
+ });
65503
+ }
65484
65504
  const existingContext = sessions.get(input.threadId);
65485
65505
  if (existingContext) {
65486
65506
  yield* Effect.logWarning("claude.session.replacing", {
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{n as t,r as n,t as r}from"./compiler-runtime-CLAvuQ-D.js";import{$r as i,As as a,Ms as o,Pp as s,Q as c,Rc as l,S as u,Yr as ee,Ys as d,an as te,b as f,dc as ne,di as re,dn as ie,ec as p,en as ae,fi as oe,gc as m,i as h,ii as g,j as _,js as v,ks as y,li as b,nt as x,oc as S,pi as C,ri as w,u as T,ui as E,v as D,y as O,z as k}from"./terminal-links-FRGOm6CP.js";import{t as A}from"./arrow-right-04_CsPkt.js";import{a as se,i as j,n as M,o as ce,r as le,s as ue,t as de}from"./toggle-group-Cf1S-sq1.js";import{$n as fe,F as pe,Fr as me,Hr as he,I as ge,Ir as _e,J as ve,L as N,Lr as ye,Qn as be,Wr as xe,Zn as Se,_ as Ce,ar as we,at as Te,ct as Ee,dt as De,er as Oe,fi as ke,h as Ae,ir as je,lt as Me,nr as Ne,ot as Pe,pi as Fe,pr as Ie,q as Le,rr as Re,sr as ze,st as Be,tr as Ve,ut as He,zr as Ue}from"./index-f-_IK-Sg.js";import{a as P,n as We}from"./fileCommentAnnotations-BDsUcVBu.js";var Ge=o(`pilcrow`,[[`path`,{d:`M13 4v16`,key:`8vvj80`}],[`path`,{d:`M17 4v16`,key:`7dpous`}],[`path`,{d:`M19 4H9.5a4.5 4.5 0 0 0 0 9H13`,key:`sh4n9v`}]]),F=e(n(),1);function Ke({threadRef:e,filePath:t,activeCwd:n,openInEditor:r}){if(e){D.getState().openFile(e,t);return}r(n?h(t,n):t)}var I=r();function qe(e,t){let n=(0,I.c)(4),r=ze(e,t),i;return n[0]!==r.data||n[1]!==r.error||n[2]!==r.isPending?(i={data:r.data,error:r.error,isPending:r.isPending},n[0]=r.data,n[1]=r.error,n[2]=r.isPending,n[3]=i):i=n[3],i}var L=t(),Je=[];function Ye(e){return(e.endSide??e.side)===`deletions`?`deletions`:`additions`}function R(e,t,n){let r=Ye(t),i=e.findIndex(e=>e.side===r&&e.lineNumber===t.end);return i<0?[...e,{side:r,lineNumber:t.end,metadata:{entries:[n]}}]:e.map((e,t)=>t===i?{...e,metadata:{entries:[...e.metadata.entries,n]}}:e)}function Xe(e){let t=(0,I.c)(50),{files:n,sectionId:r,sectionTitle:i,composerDraftTarget:a,options:o,viewerRef:s,className:c,renderHeaderPrefix:l}=e,u=ae($e),ee=ae(B),d;t[0]===a?d=t[1]:(d=e=>e.getComposerDraft(a)?.reviewComments??Je,t[0]=a,t[1]=d);let f=ae(d),[ne,re]=(0,F.useState)(null),[p,oe]=(0,F.useState)(null),m;t[2]===n?m=t[3]:(m=new Map(n.map(Qe)),t[2]=n,t[3]=m);let h=m,g;if(t[4]!==p||t[5]!==n||t[6]!==f||t[7]!==r){let e;t[9]!==p||t[10]!==f||t[11]!==r?(e=e=>{let{fileDiff:t,filePath:n,fileKey:i,collapsed:a}=e,o=f.filter(e=>e.sectionId===r&&e.filePath===n&&(e.fenceLanguage??`diff`)===`diff`).reduce((e,n)=>{let r=ie(t,n);return r?R(e,r,{id:n.id,kind:`comment`,range:r,rangeLabel:n.rangeLabel,text:n.text}):e},[]),s=p?.fileKey===i?[...o,p.annotation]:o;return{id:i,type:`diff`,fileDiff:t,annotations:s,collapsed:a,version:Pe(`${a?`1`:`0`}:${s.flatMap(z).join(`:`)}`)}},t[9]=p,t[10]=f,t[11]=r,t[12]=e):e=t[12],g=n.map(e),t[4]=p,t[5]=n,t[6]=f,t[7]=r,t[8]=g}else g=t[8];let _=g,v;t[13]!==a||t[14]!==p?.annotation||t[15]!==ee?(v=e=>{re(null),p?.annotation.metadata.entries.some(t=>t.id===e)?oe(null):ee(a,e)},t[13]=a,t[14]=p?.annotation,t[15]=ee,t[16]=v):v=t[16];let y=v,b;t[17]!==u||t[18]!==a||t[19]!==p||t[20]!==h||t[21]!==r||t[22]!==i?(b=(e,t)=>{let n=p?.annotation.metadata.entries.find(t=>t.id===e),o=p?h.get(p.fileKey):void 0;if(!n||!o)return;let s=te({id:n.id,sectionId:r,sectionTitle:i,filePath:o.filePath,fileDiff:o.fileDiff,range:n.range,text:t});s&&u(a,s),re(null),oe(null)},t[17]=u,t[18]=a,t[19]=p,t[20]=h,t[21]=r,t[22]=i,t[23]=b):b=t[23];let x=b,S;t[24]!==h||t[25]!==r||t[26]!==i?(S=(e,t)=>{if(!e)return;let n=t.item;if(n.type!==`diff`)return;let a=h.get(n.id);if(!a)return;let o=We(),s=te({id:o,sectionId:r,sectionTitle:i,filePath:a.filePath,fileDiff:a.fileDiff,range:e,text:``});s&&oe({fileKey:n.id,annotation:{side:Ye(e),lineNumber:e.end,metadata:{entries:[{id:o,kind:`draft`,range:e,rangeLabel:s.rangeLabel,text:``}]}}})},t[24]=h,t[25]=r,t[26]=i,t[27]=S):S=t[27];let C=S,w=p!==null,T;t[28]===s?T=t[29]:(T=s?{ref:s}:{},t[28]=s,t[29]=T);let E;t[30]===c?E=t[31]:(E=c?{className:c}:{},t[30]=c,t[31]=E);let D=!w,O=!w,k;t[32]!==C||t[33]!==o||t[34]!==O||t[35]!==D?(k={...o,enableGutterUtility:D,enableLineSelection:O,onLineSelectionEnd:C},t[32]=C,t[33]=o,t[34]=O,t[35]=D,t[36]=k):k=t[36];let A;t[37]===l?A=t[38]:(A=e=>e.type===`diff`?l(e.fileDiff,e.id,e.collapsed===!0):null,t[37]=l,t[38]=A);let j;t[39]!==y||t[40]!==x?(j=e=>(0,L.jsx)(`div`,{className:`py-1`,children:e.metadata.entries.map(e=>(0,L.jsx)(P,{kind:e.kind,rangeLabel:e.rangeLabel,text:e.text,onCancel:()=>y(e.id),onComment:t=>x(e.id,t),onDelete:()=>y(e.id)},e.id))}),t[39]=y,t[40]=x,t[41]=j):j=t[41];let M;return t[42]!==_||t[43]!==ne||t[44]!==k||t[45]!==A||t[46]!==j||t[47]!==T||t[48]!==E?(M=(0,L.jsx)(se,{...T,...E,items:_,selectedLines:ne,onSelectedLinesChange:re,options:k,renderHeaderPrefix:A,renderAnnotation:j}),t[42]=_,t[43]=ne,t[44]=k,t[45]=A,t[46]=j,t[47]=T,t[48]=E,t[49]=M):M=t[49],M}function z(e){return e.metadata.entries.map(Ze)}function Ze(e){return`${e.id}:${e.rangeLabel}:${e.text}`}function Qe(e){return[e.fileKey,e]}function B(e){return e.removeReviewComment}function $e(e){return e.addReviewComment}function et(e){return{diffPreview:p(e,{label:`environment-data:review:diff-preview`,tag:l.reviewGetDiffPreview,staleTimeMs:5e3})}}var tt=et(x);function V(e){return e.remoteName&&e.name.startsWith(`${e.remoteName}/`)?e.name.slice(e.remoteName.length+1):e.name}function nt(e,t){let n=new Set(t),r=e.map(e=>{let r=t.filter(t=>n.has(t)&&V(t)===e.name),i=r.find(e=>e.remoteName===`origin`)??r[0]??null;return i&&n.delete(i),{id:`local:${e.name}`,label:e.name,local:e,remote:i}}),i=t.filter(e=>n.has(e)).map(e=>({id:`remote:${e.name}`,label:e.name,local:null,remote:e}));return[...r,...i]}function rt(e,t){let n=t.trim().toLocaleLowerCase();return n.length===0?e:e.filter(e=>e.label.toLocaleLowerCase().includes(n)||e.local?.name.toLocaleLowerCase().includes(n)===!0||e.remote?.name.toLocaleLowerCase().includes(n)===!0)}var H=`__automatic_base_ref__`,it=new Set,at=`
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{n as t,r as n,t as r}from"./compiler-runtime-CLAvuQ-D.js";import{$r as i,As as a,Ms as o,Pp as s,Q as c,Rc as l,S as u,Yr as ee,Ys as d,an as te,b as f,dc as ne,di as re,dn as ie,ec as p,en as ae,fi as oe,gc as m,i as h,ii as g,j as _,js as v,ks as y,li as b,nt as x,oc as S,pi as C,ri as w,u as T,ui as E,v as D,y as O,z as k}from"./terminal-links-FRGOm6CP.js";import{t as A}from"./arrow-right-04_CsPkt.js";import{a as se,i as j,n as M,o as ce,r as le,s as ue,t as de}from"./toggle-group-DSjkAIxH.js";import{$n as fe,F as pe,Fr as me,Hr as he,I as ge,Ir as _e,J as ve,L as N,Lr as ye,Qn as be,Wr as xe,Zn as Se,_ as Ce,ar as we,at as Te,ct as Ee,dt as De,er as Oe,fi as ke,h as Ae,ir as je,lt as Me,nr as Ne,ot as Pe,pi as Fe,pr as Ie,q as Le,rr as Re,sr as ze,st as Be,tr as Ve,ut as He,zr as Ue}from"./index-C4Mhhj24.js";import{a as P,n as We}from"./fileCommentAnnotations-Dy17abwC.js";var Ge=o(`pilcrow`,[[`path`,{d:`M13 4v16`,key:`8vvj80`}],[`path`,{d:`M17 4v16`,key:`7dpous`}],[`path`,{d:`M19 4H9.5a4.5 4.5 0 0 0 0 9H13`,key:`sh4n9v`}]]),F=e(n(),1);function Ke({threadRef:e,filePath:t,activeCwd:n,openInEditor:r}){if(e){D.getState().openFile(e,t);return}r(n?h(t,n):t)}var I=r();function qe(e,t){let n=(0,I.c)(4),r=ze(e,t),i;return n[0]!==r.data||n[1]!==r.error||n[2]!==r.isPending?(i={data:r.data,error:r.error,isPending:r.isPending},n[0]=r.data,n[1]=r.error,n[2]=r.isPending,n[3]=i):i=n[3],i}var L=t(),Je=[];function Ye(e){return(e.endSide??e.side)===`deletions`?`deletions`:`additions`}function R(e,t,n){let r=Ye(t),i=e.findIndex(e=>e.side===r&&e.lineNumber===t.end);return i<0?[...e,{side:r,lineNumber:t.end,metadata:{entries:[n]}}]:e.map((e,t)=>t===i?{...e,metadata:{entries:[...e.metadata.entries,n]}}:e)}function Xe(e){let t=(0,I.c)(50),{files:n,sectionId:r,sectionTitle:i,composerDraftTarget:a,options:o,viewerRef:s,className:c,renderHeaderPrefix:l}=e,u=ae($e),ee=ae(B),d;t[0]===a?d=t[1]:(d=e=>e.getComposerDraft(a)?.reviewComments??Je,t[0]=a,t[1]=d);let f=ae(d),[ne,re]=(0,F.useState)(null),[p,oe]=(0,F.useState)(null),m;t[2]===n?m=t[3]:(m=new Map(n.map(Qe)),t[2]=n,t[3]=m);let h=m,g;if(t[4]!==p||t[5]!==n||t[6]!==f||t[7]!==r){let e;t[9]!==p||t[10]!==f||t[11]!==r?(e=e=>{let{fileDiff:t,filePath:n,fileKey:i,collapsed:a}=e,o=f.filter(e=>e.sectionId===r&&e.filePath===n&&(e.fenceLanguage??`diff`)===`diff`).reduce((e,n)=>{let r=ie(t,n);return r?R(e,r,{id:n.id,kind:`comment`,range:r,rangeLabel:n.rangeLabel,text:n.text}):e},[]),s=p?.fileKey===i?[...o,p.annotation]:o;return{id:i,type:`diff`,fileDiff:t,annotations:s,collapsed:a,version:Pe(`${a?`1`:`0`}:${s.flatMap(z).join(`:`)}`)}},t[9]=p,t[10]=f,t[11]=r,t[12]=e):e=t[12],g=n.map(e),t[4]=p,t[5]=n,t[6]=f,t[7]=r,t[8]=g}else g=t[8];let _=g,v;t[13]!==a||t[14]!==p?.annotation||t[15]!==ee?(v=e=>{re(null),p?.annotation.metadata.entries.some(t=>t.id===e)?oe(null):ee(a,e)},t[13]=a,t[14]=p?.annotation,t[15]=ee,t[16]=v):v=t[16];let y=v,b;t[17]!==u||t[18]!==a||t[19]!==p||t[20]!==h||t[21]!==r||t[22]!==i?(b=(e,t)=>{let n=p?.annotation.metadata.entries.find(t=>t.id===e),o=p?h.get(p.fileKey):void 0;if(!n||!o)return;let s=te({id:n.id,sectionId:r,sectionTitle:i,filePath:o.filePath,fileDiff:o.fileDiff,range:n.range,text:t});s&&u(a,s),re(null),oe(null)},t[17]=u,t[18]=a,t[19]=p,t[20]=h,t[21]=r,t[22]=i,t[23]=b):b=t[23];let x=b,S;t[24]!==h||t[25]!==r||t[26]!==i?(S=(e,t)=>{if(!e)return;let n=t.item;if(n.type!==`diff`)return;let a=h.get(n.id);if(!a)return;let o=We(),s=te({id:o,sectionId:r,sectionTitle:i,filePath:a.filePath,fileDiff:a.fileDiff,range:e,text:``});s&&oe({fileKey:n.id,annotation:{side:Ye(e),lineNumber:e.end,metadata:{entries:[{id:o,kind:`draft`,range:e,rangeLabel:s.rangeLabel,text:``}]}}})},t[24]=h,t[25]=r,t[26]=i,t[27]=S):S=t[27];let C=S,w=p!==null,T;t[28]===s?T=t[29]:(T=s?{ref:s}:{},t[28]=s,t[29]=T);let E;t[30]===c?E=t[31]:(E=c?{className:c}:{},t[30]=c,t[31]=E);let D=!w,O=!w,k;t[32]!==C||t[33]!==o||t[34]!==O||t[35]!==D?(k={...o,enableGutterUtility:D,enableLineSelection:O,onLineSelectionEnd:C},t[32]=C,t[33]=o,t[34]=O,t[35]=D,t[36]=k):k=t[36];let A;t[37]===l?A=t[38]:(A=e=>e.type===`diff`?l(e.fileDiff,e.id,e.collapsed===!0):null,t[37]=l,t[38]=A);let j;t[39]!==y||t[40]!==x?(j=e=>(0,L.jsx)(`div`,{className:`py-1`,children:e.metadata.entries.map(e=>(0,L.jsx)(P,{kind:e.kind,rangeLabel:e.rangeLabel,text:e.text,onCancel:()=>y(e.id),onComment:t=>x(e.id,t),onDelete:()=>y(e.id)},e.id))}),t[39]=y,t[40]=x,t[41]=j):j=t[41];let M;return t[42]!==_||t[43]!==ne||t[44]!==k||t[45]!==A||t[46]!==j||t[47]!==T||t[48]!==E?(M=(0,L.jsx)(se,{...T,...E,items:_,selectedLines:ne,onSelectedLinesChange:re,options:k,renderHeaderPrefix:A,renderAnnotation:j}),t[42]=_,t[43]=ne,t[44]=k,t[45]=A,t[46]=j,t[47]=T,t[48]=E,t[49]=M):M=t[49],M}function z(e){return e.metadata.entries.map(Ze)}function Ze(e){return`${e.id}:${e.rangeLabel}:${e.text}`}function Qe(e){return[e.fileKey,e]}function B(e){return e.removeReviewComment}function $e(e){return e.addReviewComment}function et(e){return{diffPreview:p(e,{label:`environment-data:review:diff-preview`,tag:l.reviewGetDiffPreview,staleTimeMs:5e3})}}var tt=et(x);function V(e){return e.remoteName&&e.name.startsWith(`${e.remoteName}/`)?e.name.slice(e.remoteName.length+1):e.name}function nt(e,t){let n=new Set(t),r=e.map(e=>{let r=t.filter(t=>n.has(t)&&V(t)===e.name),i=r.find(e=>e.remoteName===`origin`)??r[0]??null;return i&&n.delete(i),{id:`local:${e.name}`,label:e.name,local:e,remote:i}}),i=t.filter(e=>n.has(e)).map(e=>({id:`remote:${e.name}`,label:e.name,local:null,remote:e}));return[...r,...i]}function rt(e,t){let n=t.trim().toLocaleLowerCase();return n.length===0?e:e.filter(e=>e.label.toLocaleLowerCase().includes(n)||e.local?.name.toLocaleLowerCase().includes(n)===!0||e.remote?.name.toLocaleLowerCase().includes(n)===!0)}var H=`__automatic_base_ref__`,it=new Set,at=`
2
2
  [data-diffs-header],
3
3
  [data-diff],
4
4
  [data-file],
@@ -95,4 +95,4 @@ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{n as t,r as n,t as r}f
95
95
  text-decoration-color: currentColor;
96
96
  }
97
97
  `;function U({mode:e=`inline`,composerDraftTarget:t,initialGitScope:n}){let{resolvedTheme:r}=T(),o=Ue(),[l]=(0,F.useState)(n),[te,ie]=(0,F.useState)(`stacked`),[p,ae]=(0,F.useState)(o.wordWrap),[h,x]=(0,F.useState)(o.diffIgnoreWhitespace),[D,se]=(0,F.useState)(``),[Ce,Pe]=(0,F.useState)(()=>({scopeKey:null,fileKeys:it})),ze=(0,F.useRef)(null),P=s({strict:!1,select:e=>k(e)}),We=P?.threadId??null,I=ye(P),Je=I?.projectId??null,Ye=_e(I&&Je?{environmentId:I.environmentId,projectId:Je}:null),R=I?.worktreePath??Ye?.workspaceRoot,z=d(c.configValueAtom(I?.environmentId??null)),Ze=we(I?.environmentId??null,z?.availableEditors??[]),Qe=_(I!=null&&R!=null?me.status({environmentId:I.environmentId,input:{cwd:R}}):null),B=N(e=>ge(e.byThreadKey,P,l===`unstaged`)),$e=Qe.data?.isRepo??!0,{turnDiffSummaries:et,inferredCheckpointTurnCountByTurnId:V}=pe(I),U=(0,F.useMemo)(()=>[...et].toSorted((e,t)=>{let n=e.checkpointTurnCount??V[e.turnId]??0,r=t.checkpointTurnCount??V[t.turnId]??0;return n===r?t.completedAt.localeCompare(e.completedAt):r-n}),[V,et]);(0,F.useEffect)(()=>{!P||B.kind!==`turn`||N.getState().reconcileTurnSelection(P,U.map(e=>e.turnId))},[B,U,P]);let W=B.kind===`turn`?B.turnId:null,G=B.kind===`unstaged`?`unstaged`:`branch`,K=B.kind===`branch`?B.baseRef:null,ot=B.kind===`turn`?B.filePath:null,st=B.kind===`turn`?B.revealRequestId:0,q=W===null?void 0:U.find(e=>e.turnId===W)??U[0],J=q&&(q.checkpointTurnCount??V[q.turnId]),ct=U[0],lt=W===null?G===`unstaged`?`Working tree`:`Branch changes`:q?.turnId===ct?.turnId?`Latest turn`:`Turn ${J??`?`}`,ut=q?`turn:${q.turnId}`:G,Y=P?`${P.environmentId}:${P.threadId}:${ut}`:null,dt=Ce.scopeKey===Y?Ce.fileKeys:it,ft=q?`Turn ${J??`?`}`:G===`unstaged`?`Working tree`:`Branch changes`,pt=(0,F.useMemo)(()=>typeof J==`number`?{fromTurnCount:Math.max(0,J-1),toTurnCount:J}:null,[J]),mt=qe({environmentId:I?.environmentId??null,threadId:We,fromTurnCount:pt?.fromTurnCount??null,toTurnCount:pt?.toTurnCount??null,ignoreWhitespace:h,cacheScope:q?`turn:${q.turnId}`:null},{enabled:$e&&q!==void 0}),ht=_(W===null&&I&&R?tt.diffPreview({environmentId:I.environmentId,input:{cwd:R,...K?{baseRef:K}:{},ignoreWhitespace:h}}):null),gt=W===null&&ht.error?.includes(`configured workspace root`)===!0&&z?.cwd!==void 0&&z.cwd!==R,_t=_(gt&&I&&z?tt.diffPreview({environmentId:I.environmentId,input:{cwd:z.cwd,...K?{baseRef:K}:{},ignoreWhitespace:h}}):null),X=gt?_t:ht,Z=X.data?.sources.find(e=>e.kind===(G===`unstaged`?`working-tree`:`branch-range`)),vt=_(W===null&&G===`branch`&&I&&X.data?.cwd?me.listRefs({environmentId:I.environmentId,input:{cwd:X.data.cwd,includeMatchingRemoteRefs:!0,refKind:`local`,...D.trim().length>0?{query:D.trim()}:{},limit:100}}):null),yt=_(W===null&&G===`branch`&&I&&X.data?.cwd?me.listRefs({environmentId:I.environmentId,input:{cwd:X.data.cwd,includeMatchingRemoteRefs:!0,refKind:`remote`,...D.trim().length>0?{query:D.trim()}:{},limit:100}}):null),bt=nt(vt.data?.refs.filter(e=>e.name!==Z?.headRef)??[],yt.data?.refs??[]),xt=rt(bt,D),St=e=>K&&K===e.remote?.name?K:e.local?.name??e.remote?.name??e.id,Ct=[H,...bt.map(St)],wt=[...D.trim().length===0?[H]:[],...xt.map(St)],Tt=Z?.diff,Et=q?mt.data?.diff:Tt,Dt=!q&&Z?.truncated===!0,Ot=q?mt.isPending:X.isPending,kt=q?mt.error:X.error,At=typeof Et==`string`&&Et.trim().length===0,Q=(0,F.useMemo)(()=>Me(Et,`diff-panel:${r}`,{compactPartialHunkOffsets:W===null}),[r,Et,W]),jt=(0,F.useMemo)(()=>!Q||Q.kind!==`files`?[]:Q.files.toSorted((e,t)=>De(e).localeCompare(De(t),void 0,{numeric:!0,sensitivity:`base`})),[Q]),$=(0,F.useMemo)(()=>jt.map(e=>{let t=Te(e);return{fileDiff:e,filePath:De(e),fileKey:t,collapsed:dt.has(t)}}),[dt,jt]),Mt=(0,F.useMemo)(()=>$.map(e=>e.fileKey),[$]),Nt=le(Mt,dt),Pt=(0,F.useMemo)(()=>Ee(jt),[jt]);(0,F.useEffect)(()=>{if(!ot)return;let e=$.find(e=>e.filePath===ot);e&&ze.current?.scrollTo({type:`item`,id:e.fileKey,align:`start`})},[$,ot,st]);let Ft=(0,F.useCallback)(e=>{Ke({threadRef:P,filePath:e,activeCwd:R,openInEditor:e=>{(async()=>{let t=await Ze(e);t._tag===`Failure`&&!S(t)&&console.warn(`Failed to open diff file in editor.`,{operation:`open-diff-file`,...P?{environmentId:P.environmentId,threadId:P.threadId}:{},...m(ne(t))})})()}})},[R,Ze,P]),It=(0,F.useCallback)(e=>{Pe(t=>{let n=new Set(t.scopeKey===Y?t.fileKeys:[]);return n.has(e)?n.delete(e):n.add(e),{scopeKey:Y,fileKeys:n}})},[Y]),Lt=(0,F.useCallback)(()=>{Pe(e=>{let t=e.scopeKey===Y?e.fileKeys:it;return{scopeKey:Y,fileKeys:j(Mt,t)}})},[Y,Mt]),Rt=e=>{P&&N.getState().selectTurn(P,e)},zt=e=>{P&&N.getState().selectGitScope(P,e)},Bt=e=>{P&&N.getState().selectBranchBaseRef(P,e)};return(0,L.jsx)(ve,{mode:e,header:(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3 [-webkit-app-region:no-drag]`,children:[(0,L.jsxs)(i,{children:[(0,L.jsxs)(oe,{className:`inline-flex h-6 max-w-full items-center gap-1 rounded-md bg-muted/70 px-2 text-xs font-medium text-foreground outline-none transition-colors hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":`Diff scope: ${lt}`,children:[(0,L.jsx)(`span`,{className:`truncate`,children:lt}),(0,L.jsx)(a,{className:`size-3.5 shrink-0 text-muted-foreground`})]}),(0,L.jsxs)(g,{align:`start`,className:`w-60`,children:[(0,L.jsx)(w,{className:W===null&&G===`unstaged`?`bg-foreground/[0.08]`:void 0,onClick:()=>zt(`unstaged`),children:(0,L.jsx)(`span`,{children:`Working tree`})}),(0,L.jsx)(w,{className:W===null&&G===`branch`?`bg-foreground/[0.08]`:void 0,onClick:()=>zt(`branch`),children:(0,L.jsx)(`span`,{children:`Branch changes`})}),(0,L.jsx)(w,{className:W!==null&&q?.turnId===ct?.turnId?`bg-foreground/[0.08]`:void 0,onClick:()=>{ct&&Rt(ct.turnId)},children:(0,L.jsx)(`span`,{children:`Latest turn`})}),(0,L.jsxs)(b,{children:[(0,L.jsx)(re,{children:`Turn`}),(0,L.jsx)(E,{className:`w-64`,children:U.map(e=>{let t=e.checkpointTurnCount??V[e.turnId]??`?`;return(0,L.jsxs)(w,{className:e.turnId===q?.turnId?`bg-foreground/[0.08]`:void 0,onClick:()=>Rt(e.turnId),children:[(0,L.jsxs)(`span`,{children:[`Turn `,t]}),(0,L.jsx)(`span`,{className:`ml-auto text-xs tabular-nums text-muted-foreground`,children:Ie(e.completedAt,o.timestampFormat)})]},e.turnId)})})]})]})]}),W===null&&G===`branch`&&Z?.baseRef&&(0,L.jsxs)(`div`,{className:`flex min-w-0 max-w-full items-center gap-2 overflow-hidden text-xs text-muted-foreground`,title:`${Z.headRef??`HEAD`} → ${Z.baseRef}`,"aria-label":`Comparing ${Z.headRef??`HEAD`} against ${Z.baseRef}`,children:[(0,L.jsx)(`span`,{className:`min-w-0 max-w-48 truncate`,children:Z.headRef??`HEAD`}),(0,L.jsx)(A,{className:`size-3.5 shrink-0 opacity-70`}),(0,L.jsxs)(be,{items:Ct,filteredItems:wt,value:K??H,onOpenChange:e=>{e||se(``)},onValueChange:e=>{e&&Bt(e===H?null:e)},children:[(0,L.jsxs)(je,{className:`inline-flex min-w-0 max-w-48 items-center gap-1 overflow-hidden rounded-md px-1.5 py-1 outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":`Change comparison target. Currently ${Z.baseRef}`,children:[(0,L.jsx)(`span`,{className:`min-w-0 truncate`,children:Z.baseRef}),(0,L.jsx)(a,{className:`size-3.5 shrink-0 opacity-70`})]}),(0,L.jsxs)(Re,{align:`start`,className:`w-72 min-w-0 max-w-[calc(100vw-1rem)] overflow-hidden [&>[data-slot=combobox-popup]]:min-w-0 [&>[data-slot=combobox-popup]]:overflow-hidden`,children:[(0,L.jsx)(`div`,{className:`min-w-0 shrink-0 px-3 pt-2.5`,children:(0,L.jsxs)(`div`,{className:`relative -translate-y-px border-b border-border/70 pb-1.5 transition-colors focus-within:border-ring`,children:[(0,L.jsx)(xe,{"aria-hidden":`true`,className:`pointer-events-none absolute top-1.5 left-0 size-4 shrink-0 text-muted-foreground/55`}),(0,L.jsx)(Oe,{className:`[&_input]:h-6.5 [&_input]:ps-5 [&_input]:font-sans [&_input]:leading-6.5`,inputClassName:`rounded-none bg-transparent text-sm`,placeholder:`Search refs...`,showTrigger:!1,size:`sm`,unstyled:!0,value:D,onChange:e=>se(e.target.value)})]})}),(0,L.jsxs)(`div`,{className:`grid shrink-0 grid-cols-[1rem_minmax(0,1fr)] items-center gap-2 border-b border-border/70 ps-3 pe-6.5 pt-2 pb-1.5 font-medium text-[10px] text-muted-foreground uppercase tracking-wide`,children:[(0,L.jsx)(`span`,{"aria-hidden":`true`}),(0,L.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[minmax(0,1fr)_2rem] items-center`,children:[(0,L.jsx)(`span`,{children:`Branch`}),(0,L.jsx)(`span`,{className:`text-right`,children:`Remote`})]})]}),(0,L.jsx)(fe,{children:`No matching refs.`}),(0,L.jsxs)(Ne,{className:`max-h-64 min-w-0 overflow-x-hidden`,children:[(0,L.jsx)(Ve,{className:`h-8 w-full min-w-0 grid-cols-[1rem_minmax(0,1fr)] py-0`,contentClassName:`w-full min-w-0 overflow-hidden`,value:H,children:(0,L.jsx)(`span`,{className:`block min-w-0 truncate`,children:`Automatic`})}),bt.map(e=>{let t=St(e),n=e.local!==null&&e.remote!==null,r=e.remote?.name===t;return(0,L.jsx)(Ve,{className:`h-8 w-full min-w-0 grid-cols-[1rem_minmax(0,1fr)] py-0`,contentClassName:`w-full min-w-0 overflow-hidden`,value:t,children:(0,L.jsxs)(`div`,{className:`grid w-full min-w-0 grid-cols-[minmax(0,1fr)_2rem] items-center overflow-hidden`,children:[(0,L.jsx)(`span`,{className:`block min-w-0 truncate pe-2`,children:e.label}),n?(0,L.jsx)(`div`,{className:`flex justify-end`,onClick:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),children:(0,L.jsx)(Se,{"aria-label":`Use remote version of ${e.label}`,checked:r,className:`[--thumb-size:--spacing(3)]`,onCheckedChange:t=>{let n=t?e.remote?.name:e.local?.name;n&&Bt(n)}})}):e.remote?(0,L.jsx)(`span`,{className:`flex justify-end text-muted-foreground`,title:`Remote only`,children:(0,L.jsx)(v,{"aria-hidden":`true`,className:`size-3`})}):null]})},e.id)})]})]})]})]})]}),(0,L.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 [-webkit-app-region:no-drag]`,children:[$.length>0&&(0,L.jsx)(Ae,{additions:Pt.additions,deletions:Pt.deletions,className:`mr-1 text-[11px]`,layout:`inline`}),$.length>0&&(0,L.jsxs)(O,{children:[(0,L.jsx)(u,{render:(0,L.jsx)(ee,{type:`button`,size:`icon-xs`,variant:`outline`,"aria-label":Nt?`Expand all files`:`Collapse all files`,onClick:Lt}),children:Nt?(0,L.jsx)(ke,{className:`size-3`}):(0,L.jsx)(Fe,{className:`size-3`})}),(0,L.jsx)(f,{side:`top`,children:Nt?`Expand all files`:`Collapse all files`})]}),(0,L.jsxs)(M,{className:`shrink-0`,variant:`outline`,size:`xs`,value:[te],onValueChange:e=>{let t=e[0];(t===`stacked`||t===`split`)&&ie(t)},children:[(0,L.jsx)(de,{"aria-label":`Stacked diff view`,value:`stacked`,children:(0,L.jsx)(ce,{className:`size-3`})}),(0,L.jsx)(de,{"aria-label":`Split diff view`,value:`split`,children:(0,L.jsx)(ue,{className:`size-3`})})]}),(0,L.jsxs)(O,{children:[(0,L.jsx)(u,{render:(0,L.jsx)(de,{"aria-label":p?`Disable diff line wrapping`:`Enable diff line wrapping`,variant:`outline`,size:`xs`,pressed:p,onPressedChange:e=>{ae(!!e)}}),children:(0,L.jsx)(he,{className:`size-3`})}),(0,L.jsx)(f,{side:`top`,children:p?`Disable line wrapping`:`Enable line wrapping`})]}),(0,L.jsxs)(O,{children:[(0,L.jsx)(u,{render:(0,L.jsx)(de,{"aria-label":h?`Show whitespace changes`:`Hide whitespace changes`,variant:`outline`,size:`xs`,pressed:h,onPressedChange:e=>{x(!!e)}}),children:(0,L.jsx)(Ge,{className:`size-3`})}),(0,L.jsx)(f,{side:`top`,children:h?`Show whitespace changes`:`Hide whitespace changes`})]})]})]}),children:I?$e?W!==null&&U.length===0?(0,L.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:`No completed turns yet.`}):(0,L.jsx)(L.Fragment,{children:(0,L.jsxs)(`div`,{className:`diff-panel-viewport flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[Dt&&(0,L.jsx)(`p`,{className:`shrink-0 border-b border-border/70 bg-muted/40 px-3 py-1.5 text-[11px] text-muted-foreground`,children:`This diff was truncated because it exceeded the preview limit. The changes shown are incomplete.`}),kt&&!Q&&(0,L.jsx)(`div`,{className:`px-3`,children:(0,L.jsx)(`p`,{className:`mb-2 text-[11px] text-red-500/80`,children:kt})}),Q?Q.kind===`files`?(0,L.jsx)(`div`,{className:`min-h-0 flex-1`,onClickCapture:e=>{let t=(e.nativeEvent.composedPath?.()??[]).find(e=>e instanceof HTMLElement&&e.hasAttribute(`data-title`))?.textContent?.trim();t&&Ft(t)},children:(0,L.jsx)(Xe,{viewerRef:ze,className:`diff-render-surface h-full min-h-0 overflow-auto`,files:$,sectionId:ut,sectionTitle:ft,composerDraftTarget:t,renderHeaderPrefix:(e,t,n)=>{let r=De(e);return(0,L.jsxs)(O,{children:[(0,L.jsx)(u,{render:(0,L.jsx)(`button`,{type:`button`,className:C(`inline-flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-sm border-0 bg-transparent p-0 transition-colors hover:bg-foreground/10 focus-visible:outline-hidden`,Be(e)),"aria-label":n?`Expand ${r}`:`Collapse ${r}`,"aria-expanded":!n,onClick:e=>{e.stopPropagation(),It(t)}}),children:n?(0,L.jsx)(y,{className:`size-4`}):(0,L.jsx)(a,{className:`size-4`})}),(0,L.jsx)(f,{side:`top`,children:n?`Expand diff`:`Collapse diff`})]})},options:{diffStyle:te===`split`?`split`:`unified`,lineDiffType:`none`,overflow:p?`wrap`:`scroll`,theme:He(r),themeType:r,unsafeCSS:at,stickyHeaders:!0,itemMetrics:{diffHeaderHeight:33},layout:{paddingTop:0,paddingBottom:8,gap:8}}},Y??ut)}):(0,L.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2`,children:(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(`p`,{className:`text-[11px] text-muted-foreground/75`,children:Q.reason}),(0,L.jsx)(`pre`,{className:C(`max-h-[72vh] rounded-md border border-border/70 bg-background/70 p-3 font-mono text-[11px] leading-relaxed text-muted-foreground/90`,p?`overflow-auto whitespace-pre-wrap wrap-break-word`:`overflow-auto`),children:Q.text})]})}):Ot?(0,L.jsx)(Le,{label:q?`Loading checkpoint diff...`:G===`unstaged`?`Loading working tree diff...`:`Loading branch diff...`}):(0,L.jsx)(`div`,{className:`flex h-full items-center justify-center px-3 py-2 text-xs text-muted-foreground/70`,children:(0,L.jsx)(`p`,{children:At?`No net changes in this selection.`:`No patch available for this selection.`})})]})}):(0,L.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:`Turn diffs are unavailable because this project is not a git repository.`}):(0,L.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:`Select a thread to inspect turn diffs.`})})}export{Ce as DiffWorkerPoolProvider,U as default};
98
- //# sourceMappingURL=DiffPanel-Dps-Ks2f.js.map
98
+ //# sourceMappingURL=DiffPanel-CPaFbotP.js.map
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{n as t,r as n,t as r}from"./compiler-runtime-CLAvuQ-D.js";import{E as i,F as a,Ku as o,Ms as s,N as c,Rs as l,S as u,Yr as d,b as f,dc as p,en as m,i as h,k as g,ks as _,oc as v,on as y,pi as b,u as x,w as S,y as C,zs as w}from"./terminal-links-FRGOm6CP.js";import{n as T,r as E,t as D}from"./renderFileChildren-Ct5gmhVW.js";import{$ as ee,$r as O,$t as k,Ar as A,Bn as j,Bt as M,C as N,D as P,Fn as te,Ht as ne,In as re,Ln as ie,Mr as ae,Nr as oe,On as se,Pn as F,Pr as ce,Q as le,Rn as ue,Rr as I,Rt as de,S as fe,Vn as pe,Wr as me,X as he,b as ge,cr as _e,d as ve,dr as ye,en as be,et as xe,f as Se,jr as Ce,kr as we,l as L,li as Te,lr as Ee,m as De,mr as Oe,ni as ke,oi as R,or as Ae,p as je,pn as Me,qr as Ne,ri as Pe,rt as Fe,si as Ie,tt as Le,u as Re,ur as ze,ut as Be,v as Ve,vr as He,w as Ue,wn as We,x as Ge,y as Ke,zn as qe,zr as Je}from"./index-f-_IK-Sg.js";import{a as Ye,i as Xe,n as Ze,r as Qe,t as $e}from"./fileCommentAnnotations-BDsUcVBu.js";var et=s(`code-xml`,[[`path`,{d:`m18 16 4-4-4-4`,key:`1inbqp`}],[`path`,{d:`m6 8-4 4 4 4`,key:`15zrgr`}],[`path`,{d:`m14.5 4-5 16`,key:`e7oirm`}]]),tt=s(`file-question-mark`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}],[`path`,{d:`M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3`,key:`mhlwft`}]]),nt=s(`folder-tree`,[[`path`,{d:`M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`hod4my`}],[`path`,{d:`M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`w4yl2u`}],[`path`,{d:`M3 5a2 2 0 0 0 2 2h3`,key:`f2jnh7`}],[`path`,{d:`M3 3v13a2 2 0 0 0 2 2h3`,key:`k8epm1`}]]),rt=`file-tree-container`,it=`data-file-tree-style`,at=`data-file-tree-unsafe-css`,z=`data-file-tree-scrollbar-measure`,B=`data-file-tree-scrollbar-gutter-measured`,ot=`--trees-scrollbar-gutter-measured`,st=`header`,ct=`context-menu`,lt=`context-menu-trigger`,ut=5,dt=1<<ut,ft=dt*4;function pt(){return{childIdByNameId:new Map,childIds:[],childPositionById:new Map,childVisibleChunkSums:null,totalChildSubtreeNodeCount:0,totalChildVisibleSubtreeCount:0}}function mt(){return{childIdByNameId:null,childIds:[],childPositionById:null,childVisibleChunkSums:null,totalChildSubtreeNodeCount:0,totalChildVisibleSubtreeCount:0}}function ht(e,t){if(t.childIdByNameId!=null)return t.childIdByNameId;let n=new Map;for(let r of t.childIds){let t=e[r];t!=null&&n.set(t.nameId,r)}return t.childIdByNameId=n,n}function gt(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];r!=null&&t.set(r,n)}return e.childPositionById=t,t}function _t(e,t){e.childPositionById!=null&&e.childPositionById.set(t,e.childIds.length),e.childIds.push(t)}function vt(e,t){if(e.childPositionById!=null)for(let n=t;n<e.childIds.length;n++){let t=e.childIds[n];t!=null&&e.childPositionById.set(t,n)}}function yt(e,t){let n=0,r=0;for(let i of t.childIds){let t=e[i];t!=null&&(n+=t.subtreeNodeCount,r+=t.visibleSubtreeCount)}t.totalChildSubtreeNodeCount=n,t.totalChildVisibleSubtreeCount=r,Ct(e,t)}function bt(e,t,n,r){if(e.totalChildSubtreeNodeCount+=n,e.totalChildVisibleSubtreeCount+=r,e.childVisibleChunkSums==null||r===0)return;let i=gt(e).get(t);if(i===void 0)return;let a=i>>ut;e.childVisibleChunkSums[a]+=r}function xt(e,t,n){let r=t.childVisibleChunkSums;if(r!=null){let i=n,a=0;for(let o of r){if(i<o){let r=wt(e,t,a,i);return{...r,childVisibleIndex:n-r.localVisibleIndex}}i-=o,a+=dt}throw Error(`Visible child index ${String(n)} is out of range`)}let i=n;for(let r=0;r<t.childIds.length;r++){let a=t.childIds[r];if(a==null)continue;let o=e[a];if(o!=null){if(i<o.visibleSubtreeCount)return{childIndex:r,childVisibleIndex:n-i,localVisibleIndex:i};i-=o.visibleSubtreeCount}}throw Error(`Visible child index ${String(n)} is out of range`)}function St(e,t,n){let r=0,i=t.childVisibleChunkSums,a=0;if(i!=null){let e=n>>ut;for(let t=0;t<e;t+=1)r+=i[t]??0;a=e<<ut}for(let i=a;i<n;i+=1){let n=t.childIds[i];if(n==null)continue;let a=e[n];a!=null&&(r+=a.visibleSubtreeCount)}return r}function Ct(e,t){if(t.childIds.length<ft){t.childVisibleChunkSums=null;return}let n=Math.ceil(t.childIds.length/dt),r=new Int32Array(n);for(let n=0;n<t.childIds.length;n++){let i=t.childIds[n];if(i==null)continue;let a=e[i];a!=null&&(r[n>>ut]+=a.visibleSubtreeCount)}t.childVisibleChunkSums=r}function wt(e,t,n,r){let i=Math.min(t.childIds.length,n+dt),a=r;for(let r=n;r<i;r++){let n=t.childIds[r];if(n==null)continue;let i=e[n];if(i!=null){if(a<i.visibleSubtreeCount)return{childIndex:r,localVisibleIndex:a};a-=i.visibleSubtreeCount}}throw Error(`Visible child index ${String(r)} is out of range`)}var Tt=7,Et=3,Dt=1<<Et,Ot=4;function kt(e,t,n=0){return e<<Ot|n<<Et|t}function At(e){return e.depthAndFlags>>>Ot}function jt(e){return(e.depthAndFlags&Dt)>>Et}function V(e){return(e.depthAndFlags&Dt)!==0}function Mt(e){return e.depthAndFlags&Tt}function H(e,t){return(Mt(e)&t)!==0}function Nt(e,t){e.depthAndFlags|=t}function Pt(e,t){e.depthAndFlags=kt(t,Mt(e),jt(e))}var Ft=Symbol(`benchmarkInstrumentation`);function It(e,t){return t==null||Object.defineProperty(e,Ft,{configurable:!0,enumerable:!1,value:t,writable:!1}),e}function Lt(e){return e==null?null:e[Ft]??null}function U(e,t,n){return e==null?n():e.measurePhase(t,n)}function Rt(e,t,n){!Number.isFinite(n)||e==null||e.setCounter(t,n)}function zt(e){return e>=48&&e<=57}function Bt(e){let t=[],n=0,r=0;for(;r<e.length;){for(;r<e.length&&!zt(e.charCodeAt(r));)r+=1;if(r>=e.length)break;r>n&&t.push(e.slice(n,r));let i=0;for(;r<e.length&&zt(e.charCodeAt(r));)i=i*10+(e.charCodeAt(r)-48),r+=1;t.push(i),n=r}return(n<e.length||t.length===0)&&t.push(e.slice(n)),t}function Vt(e){let t=e.toLowerCase();return{lowerValue:t,tokens:Bt(t)}}function Ht(e,t){let n=Math.min(e.length,t.length);for(let r=0;r<n;r++){let n=e[r],i=t[r];if(n===i)continue;if(typeof n==`number`&&typeof i==`number`)return n<i?-1:1;let a=String(n),o=String(i);if(a!==o)return a<o?-1:1}return e.length===t.length?0:e.length<t.length?-1:1}function Ut(e,t){if(e.tokens.length===1&&t.tokens.length===1&&typeof e.tokens[0]==`string`&&typeof t.tokens[0]==`string`)return e.lowerValue===t.lowerValue?0:e.lowerValue<t.lowerValue?-1:1;let n=Ht(e.tokens,t.tokens);return n===0?e.lowerValue===t.lowerValue?0:e.lowerValue<t.lowerValue?-1:1:n}function Wt(e,t,n){let r=Ut(n(e),n(t));return r===0?e===t?0:e<t?-1:1:r}function Gt(e,t){return Wt(e,t,Vt)}function Kt(e,t){return t===e.segments.length-1?+!!e.isDirectory:1}function qt(e,t){let n=Math.min(e.segments.length,t.segments.length);for(let r=0;r<n;r++){let n=e.segments[r],i=t.segments[r];if(n===i)continue;let a=Kt(e,r);return a===Kt(t,r)?Gt(n,i):a===1?-1:1}return e.segments.length===t.segments.length?e.isDirectory===t.isDirectory?0:e.isDirectory?-1:1:e.segments.length<t.segments.length?-1:1}function Jt(e,t){return qt(e,t)}function Yt(e,t,n){let r=e=>{let t=n.get(e);if(t!=null)return t;let r=Vt(e);return n.set(e,r),r},i=Math.min(e.segments.length,t.segments.length);for(let n=0;n<i;n++){let i=e.segments[n],a=t.segments[n];if(i===a)continue;let o=Kt(e,n);return o===Kt(t,n)?Wt(i,a,r):o===1?-1:1}return e.segments.length===t.segments.length?e.isDirectory===t.isDirectory?0:e.isDirectory?-1:1:e.segments.length<t.segments.length?-1:1}function Xt(e,t){let n=e.sortKeyById[t];if(n!==void 0)return n;let r=e.valueById[t],i=Vt(r);return e.sortKeyById[t]=i,i}function Zt(e={}){return{flattenEmptyDirectories:e.flattenEmptyDirectories!==!1,sort:e.sort??`default`}}function Qt(e){let t=e.length>0&&e.charCodeAt(e.length-1)===47,n=t?e.length-1:e.length,r=[],i=0;for(let t=0;t<n;t++)e.charCodeAt(t)===47&&(r.push(e.slice(i,t)),i=t+1);return r.push(e.slice(i,n)),{hasTrailingSlash:t,segments:r}}function $t(e){let{hasTrailingSlash:t,segments:n}=Qt(e);return{basename:n[n.length-1]??``,isDirectory:t,path:e,segments:n}}function en(e){if(e.length===0)return{requiresDirectory:!1,segments:[]};let{hasTrailingSlash:t,segments:n}=Qt(e);return{requiresDirectory:t,segments:n}}var tn=``;function nn(){let e=new Map;return e.set(tn,0),{idByValue:e,valueById:[tn],sortKeyById:[Vt(tn)]}}function rn(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 an(e,t){let n=e.valueById[t];if(n===void 0)throw Error(`Unknown segment ID: ${String(t)}`);return n}var on=Symbol(`pathStorePreparedInputKind`);function sn(e,t){return e[on]=t,e}function cn(e){return{basename:e.basename,depth:e.segments.length,isDirectory:e.isDirectory,path:e.path,segments:e.segments}}function ln(e,t,n){return n==="default"?Jt(e,t):n(cn(e),cn(t))}function un(){return{depthAndFlags:kt(0,3,1),nameId:0,parentId:0,subtreeNodeCount:1,visibleSubtreeCount:1}}function dn(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 fn(e){return e.isDirectory?e.segments.length:e.segments.length-1}function pn(e){return Array.isArray(e)&&e.every(e=>typeof e==`object`&&!!e&&typeof e.path==`string`&&Array.isArray(e.segments)&&typeof e.basename==`string`&&typeof e.isDirectory==`boolean`)}function mn(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}function hn(e,t={}){return xn(e,t).map(e=>e.path)}function gn(e,t={}){let n=xn(e,t);return sn({paths:n.map(e=>e.path),preparedPaths:n},`prepared`)}function _n(e){let t=e.length,n=!1;for(let r=0;r<t;r+=1){let t=e[r];if(t.length>0&&t.charCodeAt(t.length-1)===47){n=!0;break}}return sn({paths:e,presortedPaths:e,presortedPathsContainDirectories:n},`presorted`)}function vn(e){let t=e,n=t.preparedPaths;if(t[on]===`prepared`&&n!=null)return n;if(!pn(n))throw Error(`preparedInput must come from PathStore.prepareInput()`);return n}function yn(e){let t=e;return t[on]===`presorted`&&t.presortedPaths!=null||mn(t.presortedPaths)?t.presortedPaths:null}function bn(e){let t=e;return typeof t.presortedPathsContainDirectories==`boolean`?t.presortedPathsContainDirectories:null}function xn(e,t={}){let n=Zt(t),r=Lt(t);Rt(r,`workload.inputFiles`,e.length);let i=U(r,`store.preparePathEntries.parse`,()=>e.map(e=>$t(e)));return U(r,`store.preparePathEntries.sort`,()=>i.sort((e,t)=>ln(e,t,n.sort))),i}var Sn=class{directories=new Map;directoryStack=[0];presortedDirectoryNodeIds=[];initialExpandedPathSet;createdDirectoriesAllExpanded=!1;createdDirectoryCount=0;lastPreparedPath=null;nodes=[un()];options;instrumentation;segmentSortKeyCache=new Map;segmentTable=nn();hasDeferredDirectoryIndexes=!1;constructor(e={}){this.instrumentation=Lt(e),this.options=Zt(e);let t=e.initialExpandedPaths??null;if(t==null||t.length===0)this.initialExpandedPathSet=null;else{let e=new Set,n=t.length;for(let r=0;r<n;r+=1){let n=t[r],i=n.length;e.add(i>0&&n.charCodeAt(i-1)===47?n.slice(0,i-1):n)}this.initialExpandedPathSet=e,this.createdDirectoriesAllExpanded=!0}this.directories.set(0,pt())}appendPaths(e){return U(this.instrumentation,`store.builder.appendPaths.parse`,()=>this.appendPreparedPaths(e.map(e=>$t(e))))}appendPreparedPaths(e,t=!0){return this.createdDirectoriesAllExpanded=!1,U(this.instrumentation,`store.builder.appendPreparedPaths`,()=>{for(let n of e)this.appendPreparedPath(n,t)}),this}appendPresortedPaths(e,t=null){return U(this.instrumentation,`store.builder.appendPresortedPaths`,()=>{if(t===!1){this.appendPresortedFilePaths(e);return}this.createdDirectoriesAllExpanded=!1;let n=null,r=0,i=this.nodes,a=this.segmentTable,o=a.idByValue,s=a.valueById,c=this.directoryStack,l=0,u=``,d=0;for(let t of e){if(n===t)throw Error(`Duplicate path: "${t}"`);let e=t.length>0&&t.charCodeAt(t.length-1)===47,a=e?t.length-1:t.length,f=0,p=0;if(n!=null)if(u.length>0&&t.length>u.length&&t.startsWith(u))f=d,p=u.length;else{let r=Math.min(a,n.length),i=!0;for(let e=0;e<r;e++){let r=t.charCodeAt(e);if(r!==n.charCodeAt(e)){i=!1;break}r===47&&(f++,p=e+1)}i&&e&&r===a&&n.length>a&&n.charCodeAt(a)===47&&(f++,p=a+1)}l=f,r=f;let m=p,h=t.indexOf(`/`,m);for(;h>=0&&h<a;){let e=c[l];if(e===void 0)throw Error(`Directory stack underflow while building the path store`);r++;let n=t.slice(m,h),a=o.get(n);a===void 0&&(a=s.length,o.set(n,a),s.push(n));let u=i.length;i.push({depthAndFlags:kt(r,0,1),nameId:a,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),this.recordCreatedDirectoryPath(t.slice(0,h)),l++,c[l]=u,m=h+1,h=t.indexOf(`/`,m)}if(e){if(m<a){let e=c[l];if(e===void 0)throw Error(`Unable to resolve directory parent for "${t}"`);r++;let n=t.slice(m,a),u=o.get(n);u===void 0&&(u=s.length,o.set(n,u),s.push(n));let d=i.length;i.push({depthAndFlags:kt(r,0,1),nameId:u,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),l++,c[l]=d}let e=c[l];if(e===void 0)throw Error(`Unable to resolve directory node for "${t}"`);this.promoteDirectoryToExplicit(e,t)}else{let e=c[l];if(e===void 0)throw Error(`Unable to resolve file parent for "${t}"`);let n=t.slice(m),a=o.get(n);a===void 0&&(a=s.length,o.set(n,a),s.push(n)),i.push({depthAndFlags:kt(r+1,0),nameId:a,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1})}m!==u.length&&(u=t.substring(0,m),d=r),n=t}c.length=l+1,n!=null&&(this.lastPreparedPath=$t(n)),this.hasDeferredDirectoryIndexes=!0}),this}appendPresortedFilePaths(e){let t=null,n=0,r=this.nodes,i=this.segmentTable,a=i.idByValue,o=i.valueById,s=this.directoryStack,c=0,l=``,u=0;for(let i of e){if(t===i)throw Error(`Duplicate path: "${i}"`);let e=i.length,d=0,f=0;if(t!=null)if(l.length>0&&i.length>l.length&&i.startsWith(l))d=u,f=l.length;else{let n=Math.min(e,t.length);for(let e=0;e<n;e++){let n=i.charCodeAt(e);if(n!==t.charCodeAt(e))break;n===47&&(d++,f=e+1)}}c=d,n=d;let p=f,m=i.indexOf(`/`,p);for(;m>=0;){let e=s[c];if(e===void 0)throw Error(`Directory stack underflow while building the path store`);n++;let t=i.slice(p,m),l=a.get(t);l===void 0&&(l=o.length,a.set(t,l),o.push(t));let u=r.length;r.push({depthAndFlags:kt(n,0,1),nameId:l,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),this.recordCreatedDirectoryPath(i.slice(0,m)),this.presortedDirectoryNodeIds.push(u),c++,s[c]=u,p=m+1,m=i.indexOf(`/`,p)}let h=s[c];if(h===void 0)throw Error(`Unable to resolve file parent for "${i}"`);let g=i.slice(p),_=a.get(g);_===void 0&&(_=o.length,a.set(g,_),o.push(g)),r.push({depthAndFlags:kt(n+1,0),nameId:_,parentId:h,subtreeNodeCount:1,visibleSubtreeCount:1}),p!==l.length&&(l=i.substring(0,p),u=n),t=i}s.length=c+1,t!=null&&(this.lastPreparedPath=$t(t)),this.hasDeferredDirectoryIndexes=!0}finish(e={}){let t=e.skipSubtreeCountPass===!0;return this.hasDeferredDirectoryIndexes?(U(this.instrumentation,`store.builder.buildDirectoryIndexes`,()=>this.buildPresortedFinish(t)),this.hasDeferredDirectoryIndexes=!1):t||U(this.instrumentation,`store.builder.computeSubtreeCounts`,()=>this.computeSubtreeCounts(0)),{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(),!1),this.lastPreparedPath!=null){if(e.path===this.lastPreparedPath.path)throw Error(`Duplicate path: "${e.path}"`);if(t&&(this.options.sort==="default"?Yt(this.lastPreparedPath,e,this.segmentSortKeyCache):ln(this.lastPreparedPath,e,this.options.sort))>0)throw Error(`Builder input must be sorted before appendPaths(): "${e.path}"`)}let n=this.lastPreparedPath,r=fn(e),i=n==null?0:fn(n),a=n==null?0:dn(n.segments,e.segments),o=Math.min(a,r,i);this.directoryStack.length=o+1;for(let n=o;n<r;n++){let r=this.directoryStack[this.directoryStack.length-1];if(r===void 0)throw Error(`Directory stack underflow while building the path store`);let i=t?this.getOrCreateDirectoryChild(r,e.segments[n]):this.createDirectoryChild(r,e.segments[n]);this.directoryStack.push(i)}if(e.isDirectory){let t=this.directoryStack[this.directoryStack.length-1];if(t===void 0)throw Error(`Unable to resolve directory node for "${e.path}"`);this.promoteDirectoryToExplicit(t,e.path),this.lastPreparedPath=e;return}let s=this.directoryStack[this.directoryStack.length-1];if(s===void 0)throw Error(`Unable to resolve file parent for "${e.path}"`);t?this.createFileChild(s,e.basename,e.path):this.createFileChildUnchecked(s,e.basename),this.lastPreparedPath=e}recordCreatedDirectoryPath(e){!this.createdDirectoriesAllExpanded||this.initialExpandedPathSet==null||(this.createdDirectoryCount+=1,this.initialExpandedPathSet.has(e)||(this.createdDirectoriesAllExpanded=!1))}createFileChild(e,t,n){let r=rn(this.segmentTable,t),i=this.getDirectoryIndex(e),a=i.childIdByNameId;if(a!=null&&a.get(r)!==void 0)throw Error(`Path collides with an existing entry: "${n}"`);let o=this.nodes[e];if(o===void 0)throw Error(`Unknown parent node ID: ${String(e)}`);let s=this.nodes.length;return this.nodes.push({depthAndFlags:kt(At(o)+1,0),nameId:r,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),a?.set(r,s),_t(i,s),s}createFileChildUnchecked(e,t){let n=rn(this.segmentTable,t),r=this.getDirectoryIndex(e),i=this.nodes[e];if(i===void 0)throw Error(`Unknown parent node ID: ${String(e)}`);let a=this.nodes.length;return this.nodes.push({depthAndFlags:kt(At(i)+1,0),nameId:n,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),r.childIdByNameId!=null&&r.childIdByNameId.set(n,a),_t(r,a),a}getOrCreateDirectoryChild(e,t){let n=rn(this.segmentTable,t),r=this.getDirectoryIndex(e);if(r.childIdByNameId!=null){let e=r.childIdByNameId.get(n);if(e!==void 0){let n=this.nodes[e];if(n!=null&&!V(n))throw Error(`Path collides with an existing file while creating directory "${t}"`);return e}}let i=this.nodes[e];if(i===void 0)throw Error(`Unknown parent node ID: ${String(e)}`);let a=this.nodes.length;return this.nodes.push({depthAndFlags:kt(At(i)+1,0,1),nameId:n,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),r.childIdByNameId!=null&&r.childIdByNameId.set(n,a),_t(r,a),this.directories.set(a,pt()),a}createDirectoryChild(e,t){let n=rn(this.segmentTable,t),r=this.getDirectoryIndex(e),i=this.nodes[e];if(i===void 0)throw Error(`Unknown parent node ID: ${String(e)}`);let a=this.nodes.length;return this.nodes.push({depthAndFlags:kt(At(i)+1,0,1),nameId:n,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),r.childIdByNameId!=null&&r.childIdByNameId.set(n,a),_t(r,a),this.directories.set(a,pt()),a}promoteDirectoryToExplicit(e,t){let n=this.nodes[e];if(n===void 0)throw Error(`Unknown directory node ID: ${String(e)}`);if(!V(n))throw Error(`Path is not a directory: "${t}"`);if(H(n,1))throw Error(`Duplicate path: "${t}"`);Nt(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,mt());let r=-1,i=null;for(let e=1;e<t.length;e++){let a=t[e];if(a==null)continue;if(V(a)){let t=mt();n.set(e,t),r=e,i=t}let o;a.parentId===r?o=i:(o=n.get(a.parentId),r=a.parentId,i=o??null),o?.childIds.push(e)}if(!e)for(let e=t.length-1;e>=1;e--){let n=t[e];if(n==null)continue;let r=t[n.parentId];r!=null&&(r.subtreeNodeCount+=n.subtreeNodeCount,r.visibleSubtreeCount+=n.visibleSubtreeCount)}}buildDirectoryIndexes(){let e=this.nodes;for(let t=1;t<e.length;t++){let n=e[t];if(n==null)continue;V(n)&&this.directories.set(t,pt());let r=this.directories.get(n.parentId);r!=null&&(r.childIdByNameId!=null&&r.childIdByNameId.set(n.nameId,t),_t(r,t))}}computeSubtreeCounts(e){let t=this.nodes[e];if(t===void 0)throw Error(`Unknown node ID: ${String(e)}`);if(!V(t))return t.subtreeNodeCount=1,t.visibleSubtreeCount=1,1;let n=this.getDirectoryIndex(e),r=1;for(let e of n.childIds)r+=this.computeSubtreeCounts(e);return yt(this.nodes,n),t.subtreeNodeCount=r,t.visibleSubtreeCount=r,r}};function Cn(e,t=`closed`,n=null){let r=Tn(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 wn(){return{affectedAncestorIds:new Set,affectedNodeIds:new Set,events:[]}}function Tn(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 En(e,t){return H(t,2)||e.defaultExpansion===`open`?!0:e.defaultExpansion===`closed`?!1:At(t)<=e.defaultExpansion}function Dn(e,t,n=e.snapshot.nodes[t]){return n==null||!V(n)?!1:e.directoriesOpenByDefault&&!e.hasCollapsedDirectoryOverrides?!0:e.collapsedDirectoryIds.has(t)?!1:e.expandedDirectoryIds.has(t)?!0:En(e,n)}function On(e,t,n,r=e.snapshot.nodes[t]){if(r==null||!V(r))return;let i=En(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 kn(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 An(e,t){return e.directoryLoadInfoById.get(t)?.state??`loaded`}function jn(e,t){let n=kn(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 Mn(e,t){let n=kn(e,t);n.activeAttemptId=null,n.errorMessage=null,n.state=`unloaded`}function Nn(e,t,n){let r=e.directoryLoadInfoById.get(t);return r==null||r.activeAttemptId!==n?!1:(r.activeAttemptId=null,r.errorMessage=null,r.state=`loaded`,!0)}function Pn(e,t,n){return e.directoryLoadInfoById.get(t)?.activeAttemptId===n}function Fn(e,t,n,r){let i=e.directoryLoadInfoById.get(t);return i==null||i.activeAttemptId!==n?!1:(i.activeAttemptId=null,i.errorMessage=r??null,i.state=`error`,!0)}function In(e,t){e.directoryLoadInfoById.delete(t)}function Ln(e,t,n){let r=n,i=e.listeners.get(t);return i==null?e.listeners.set(t,new Set([r])):i.add(r),()=>{let n=e.listeners.get(t);n!=null&&(n.delete(r),n.size===0&&e.listeners.delete(t))}}function Rn(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!0,operation:`add`,path:e.path,projectionChanged:e.projectionChanged,visibleCountDelta:null}}function zn(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!0,operation:`remove`,path:e.path,projectionChanged:e.projectionChanged,recursive:e.recursive,visibleCountDelta:null}}function Bn(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!0,from:e.from,operation:`move`,projectionChanged:e.projectionChanged,to:e.to,visibleCountDelta:null}}function Vn(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!1,operation:`expand`,path:e.path,projectionChanged:!0,visibleCountDelta:null}}function Hn(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!1,operation:`collapse`,path:e.path,projectionChanged:!0,visibleCountDelta:null}}function Un(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!1,operation:`mark-directory-unloaded`,path:e.path,projectionChanged:e.projectionChanged,visibleCountDelta:null}}function Wn(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 Gn(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],attemptId:e.attemptId,canonicalChanged:e.childEvents.some(e=>e.canonicalChanged),childEvents:e.childEvents,operation:`apply-child-patch`,path:e.path,projectionChanged:e.projectionChanged,visibleCountDelta:null}}function Kn(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 qn(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 Jn(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 Yn(e,t,n){return{...n,visibleCountDelta:or(e)-t}}function Xn(e,t){let n=or(e),r=wn();e.transactionStack.push(r);try{t()}catch(t){throw $n(e,r,!1),t}$n(e,r,!0,or(e)-n)}function Zn(e,t){let n=e.instrumentation;if(n==null){Qn(e,t);return}U(n,`store.events.record`,()=>Qn(e,t))}function Qn(e,t){let n=e.transactionStack[e.transactionStack.length-1]??null;if(n==null){ir(e,t);return}n.events.push(t),rr(n,t)}function $n(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 n=e.instrumentation;n==null?nr(i,t):U(n,`store.events.batch.merge`,()=>nr(i,t));return}let a=er(t,r),o=e.instrumentation;if(o==null){ir(e,a);return}U(o,`store.events.batch.commit`,()=>ir(e,a))}function er(e,t){return{affectedAncestorIds:[...e.affectedAncestorIds],affectedNodeIds:[...e.affectedNodeIds],canonicalChanged:e.events.some(e=>e.canonicalChanged),events:[...e.events],operation:`batch`,projectionChanged:e.events.some(e=>e.projectionChanged),visibleCountDelta:t}}function tr(e,t){for(let n of t.affectedAncestorIds)e.affectedAncestorIds.add(n);for(let n of t.affectedNodeIds)e.affectedNodeIds.add(n)}function nr(e,t){for(let n of t.events)e.events.push(n);tr(e,t)}function rr(e,t){for(let n of t.affectedNodeIds)e.affectedNodeIds.add(n);for(let n of t.affectedAncestorIds)e.affectedAncestorIds.add(n)}function ir(e,t){let n=e.instrumentation;if(n==null){ar(e,t);return}U(n,`store.events.emit`,()=>ar(e,t))}function ar(e,t){e.listeners.get(t.operation)?.forEach(e=>e(t)),e.listeners.get(`*`)?.forEach(e=>e(t))}function or(e){return e.snapshot.nodes[e.snapshot.rootId]?.visibleSubtreeCount??0}function sr(e,t){if(e.snapshot.options.flattenEmptyDirectories!==!0)return null;let n=e.snapshot.nodes[t];if(n==null||!V(n)||H(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 a=e.snapshot.nodes[i];return a==null||!V(a)?null:i}function cr(e,t){let n=t;for(;;){let t=sr(e,n);if(t==null)return n;n=t}}function lr(e,t){let n=[t],r=t;for(;;){let t=sr(e,r);if(t==null)return n;n.push(t),r=t}}function ur(e,t){let n=t==null?e.snapshot.rootId:yr(e,t);return n==null?[]:xr(e,n)}function dr(e,t){let n=$t(t),r=n.isDirectory?n.segments:n.segments.slice(0,-1),i=Ir(e,Fr(e,r)),{createdNodeIds:a,directoryId:o}=Sr(e,r),s=new Set(a),c=o;if(n.isDirectory){let n=K(e,o);if(H(n,1))throw Error(`Path already exists: "${t}"`);Nt(n,1),e.pathCacheByNodeId.set(o,{path:t,version:e.pathCacheVersion}),s.add(o)}else c=wr(e,o,n.basename),s.add(c);gr(e,o);let l=Ir(e,o);return Rn({affectedAncestorIds:vr(e,c),affectedNodeIds:[...s],path:t,projectionChanged:Lr(i,l)})}function fr(e,t,n){let r=yr(e,t);if(r==null)throw Error(`Path does not exist: "${t}"`);let i=K(e,r);if(H(i,2))throw Error(`The root node cannot be removed`);if(V(i)&&G(e,r).childIds.length>0&&n.recursive!==!0)throw Error(`Cannot remove a non-empty directory without recursive: "${t}"`);let a=i.parentId,o=Ir(e,a),s=Nr(e,r);Dr(e,a,r,i.nameId),Pr(e,a),gr(e,a);let c=Ir(e,a);return zn({affectedAncestorIds:vr(e,a),affectedNodeIds:s,path:t,projectionChanged:Lr(o,c),recursive:n.recursive===!0})}function pr(e,t,n,r){let i=yr(e,t);if(i==null)throw Error(`Source path does not exist: "${t}"`);let a=K(e,i);if(H(a,2))throw Error(`The root node cannot be moved`);let o=r.collision??`error`,s=jr(e,i,n),c=Ir(e,a.parentId),l=Ir(e,s.parentId),u=an(e.snapshot.segmentTable,a.nameId),d=rn(e.snapshot.segmentTable,s.basename);if(s.parentId===a.parentId&&u===s.basename)return null;if(V(a)&&Vr(e,i,s.parentId))throw Error(`Cannot move a directory into one of its descendants`);let f=ht(e.snapshot.nodes,G(e,s.parentId)).get(d),p=s.existingNodeId??f??null;if(p!=null&&p!==i&&Mr(e,p,o,jt(a))===`skip`)return null;let m=a.parentId;Dr(e,m,i,a.nameId),a.parentId=s.parentId,a.nameId=d,e.pathCacheByNodeId.delete(i),Br(e,i),Er(e,s.parentId,i),Pr(e,m),e.pathCacheVersion++,gr(e,m),s.parentId!==m&&gr(e,s.parentId);let h=Ir(e,m),g=Ir(e,s.parentId);return Bn({affectedAncestorIds:[...new Set([...vr(e,m),...vr(e,s.parentId)])],affectedNodeIds:[i],from:t,projectionChanged:Rr([c,l],[h,g]),to:W(e,i)})}function mr(e,t){let n=e.pathCacheByNodeId.get(t);return n!=null&&n.version===e.pathCacheVersion?n.path:null}function hr(e,t,n){return e.pathCacheByNodeId.set(t,{path:n,version:e.pathCacheVersion}),n}function W(e,t){let n=K(e,t),r=mr(e,t);if(r!=null)return r;if(H(n,2))return hr(e,t,``);let i=W(e,n.parentId),a=an(e.snapshot.segmentTable,n.nameId),o=i.length===0?a:`${i}${a}`;return hr(e,t,V(n)?`${o}/`:o)}function gr(e,t){let n=e.instrumentation;if(n==null){Ur(e,t);return}U(n,`store.recomputeCountsUpwardFrom`,()=>Ur(e,t))}function _r(e,t){let n=[[t,0]],{nodes:r,directories:i}=e.snapshot;for(;n.length>0;){let t=n[n.length-1],a=t[0],o=r[a];if(o==null||!V(o)){Hr(e,a,o,!0),n.pop();continue}let s=i.get(a);if(s==null||t[1]>=s.childIds.length){Hr(e,a,o,!0),n.pop();continue}let c=s.childIds[t[1]++];n.push([c,0])}}function vr(e,t){let n=[],r=t;for(;r!=null;){let t=K(e,r);if(n.push(r),r===e.snapshot.rootId)break;r=t.parentId}return n}function yr(e,t){if(t.length===0)return e.snapshot.rootId;let n=en(t);return br(e,n.segments,n.requiresDirectory)}function br(e,t,n){let r=e.snapshot.rootId;for(let n of t){let t=e.snapshot.segmentTable.idByValue.get(n);if(t===void 0)return null;let i=G(e,r),a=ht(e.snapshot.nodes,i).get(t);if(a===void 0)return null;r=a}let i=K(e,r);return n&&!V(i)?null:r}function G(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 K(e,t){let n=e.snapshot.nodes[t];if(n===void 0||H(n,4))throw Error(`Unknown node ID: ${String(t)}`);return n}function xr(e,t){let n=e.snapshot.nodes[t];if(n===void 0||H(n,4))return[];if(!V(n))return[W(e,t)];if(G(e,t).childIds.length===0)return H(n,1)&&!H(n,2)?[W(e,t)]:[];let r=[],i=[{childIndex:0,nodeId:t}];for(;i.length>0;){let t=i[i.length-1];if(t==null)break;let n=e.snapshot.nodes[t.nodeId];if(n===void 0||H(n,4)){i.pop();continue}if(!V(n)){r.push(W(e,t.nodeId)),i.pop();continue}let a=G(e,t.nodeId);if(a.childIds.length===0){H(n,1)&&!H(n,2)&&r.push(W(e,t.nodeId)),i.pop();continue}let o=a.childIds[t.childIndex];if(o==null){i.pop();continue}t.childIndex++,i.push({childIndex:0,nodeId:o})}return r}function Sr(e,t){let n=[],r=e.snapshot.rootId;for(let i of t){let t=rn(e.snapshot.segmentTable,i),a=G(e,r),o=ht(e.snapshot.nodes,a).get(t);if(o!==void 0){if(!V(K(e,o)))throw Error(`Cannot create a directory that collides with an existing file: "${i}"`);r=o;continue}r=Cr(e,r,t),n.push(r)}return{createdNodeIds:n,directoryId:r}}function Cr(e,t,n){let r=K(e,t),i=e.snapshot.nodes.length;return e.snapshot.nodes.push({depthAndFlags:kt(At(r)+1,0,1),nameId:n,parentId:t,subtreeNodeCount:1,visibleSubtreeCount:1}),e.snapshot.directories.set(i,pt()),Er(e,t,i),e.collapseNewDirectoriesByDefault&&(e.collapsedDirectoryIds.add(i),e.hasCollapsedDirectoryOverrides=!0),e.activeNodeCount++,i}function wr(e,t,n){let r=rn(e.snapshot.segmentTable,n),i=G(e,t);if(ht(e.snapshot.nodes,i).has(r))throw Error(`Path already exists: "${Gr(e,t,n)}"`);let a=K(e,t),o=e.snapshot.nodes.length;return e.snapshot.nodes.push({depthAndFlags:kt(At(a)+1,0),nameId:r,parentId:t,subtreeNodeCount:1,visibleSubtreeCount:1}),Er(e,t,o),e.activeNodeCount++,o}function Tr(e,t,n){let r=0,i=t.childIds.length;for(;r<i;){let a=r+i>>>1,o=t.childIds[a];if(o==null){i=a;continue}Or(e,n,o)<0?i=a:r=a+1}return r}function Er(e,t,n){let r=G(e,t),i=K(e,n);ht(e.snapshot.nodes,r).set(i.nameId,n),bt(r,n,i.subtreeNodeCount,i.visibleSubtreeCount);let a=Tr(e,r,n);r.childIds.splice(a,0,n),vt(r,a),Ct(e.snapshot.nodes,r)}function Dr(e,t,n,r){let i=G(e,t),a=gt(i),o=a.get(n)??-1;ht(e.snapshot.nodes,i).delete(r),a.delete(n);let s=e.snapshot.nodes[n];s!=null&&bt(i,n,-s.subtreeNodeCount,-s.visibleSubtreeCount),o>=0&&(i.childIds.splice(o,1),vt(i,o),Ct(e.snapshot.nodes,i))}function Or(e,t,n){let r=e.snapshot.options.sort;return r==="default"?kr(e,t,n):r(Ar(e,t),Ar(e,n))}function kr(e,t,n){let r=K(e,t),i=K(e,n),a=V(r);if(a!==V(i))return a?-1:1;let o=Ut(Xt(e.snapshot.segmentTable,r.nameId),Xt(e.snapshot.segmentTable,i.nameId));if(o!==0)return o;let s=an(e.snapshot.segmentTable,r.nameId),c=an(e.snapshot.segmentTable,i.nameId);return s===c?t<n?-1:1:s<c?-1:1}function Ar(e,t){let n=K(e,t),r=W(e,t),i=V(n),a=i?r.slice(0,-1):r;return{basename:an(e.snapshot.segmentTable,n.nameId),depth:At(n),isDirectory:i,path:r,segments:a.length===0?[]:a.split(`/`)}}function jr(e,t,n){let r=K(e,t),i=yr(e,n);if(i!=null){let t=K(e,i);if(V(t))return{basename:an(e.snapshot.segmentTable,r.nameId),existingNodeId:null,parentId:i};let a=en(n).segments;return{basename:a[a.length-1]??``,existingNodeId:i,parentId:t.parentId}}let a=en(n),o=a.segments[a.segments.length-1]??``,s=a.segments.slice(0,-1),c=s.length===0?e.snapshot.rootId:br(e,s,!0);if(c==null)throw Error(`Destination parent does not exist: "${n}"`);return{basename:o,existingNodeId:null,parentId:c}}function Mr(e,t,n,r){if(n===`skip`)return`skip`;if(n===`error`)throw Error(`Destination already exists: "${W(e,t)}"`);let i=K(e,t);if(jt(i)!==r)throw Error(`replace collision requires the same source and destination kinds`);if(V(i)&&G(e,t).childIds.length>0)throw Error(`replace collision does not support non-empty directories`);let a=i.parentId,o=i.nameId;return Nr(e,t),Dr(e,a,t,o),Pr(e,a),gr(e,a),`handled`}function Nr(e,t){let n=[],r=[{nodeId:t,visitedChildren:!1}];for(;r.length>0;){let t=r.pop();if(t==null)break;let i=K(e,t.nodeId);if(t.visitedChildren||!V(i)){V(i)&&e.snapshot.directories.delete(t.nodeId),Nt(i,4),e.pathCacheByNodeId.delete(t.nodeId),e.collapsedDirectoryIds.delete(t.nodeId)&&(e.hasCollapsedDirectoryOverrides=e.collapsedDirectoryIds.size>0),e.expandedDirectoryIds.delete(t.nodeId),In(e,t.nodeId),e.activeNodeCount--,n.push(t.nodeId);continue}r.push({nodeId:t.nodeId,visitedChildren:!0});let a=G(e,t.nodeId);for(let e=a.childIds.length-1;e>=0;e--){let t=a.childIds[e];t!=null&&r.push({nodeId:t,visitedChildren:!1})}}return n}function Pr(e,t){let n=t;for(;n!=null;){let t=K(e,n);if(!V(t)||H(t,2)||G(e,n).childIds.length>0)return;Nt(t,1),n=t.parentId===n?null:t.parentId}}function Fr(e,t){let n=e.snapshot.rootId;for(let r of t){let t=e.snapshot.segmentTable.idByValue.get(r);if(t==null)break;let i=ht(e.snapshot.nodes,G(e,n)).get(t);if(i==null||!V(K(e,i)))break;n=i}return n}function Ir(e,t){let n=zr(e,t);if(n==null)return null;let r=cr(e,n),i=K(e,r),a=n===r?null:lr(e,n).map(t=>W(e,t));return JSON.stringify({flattenedSegmentPaths:a,hasChildren:G(e,r).childIds.length>0,path:W(e,r),terminalKind:jt(i)})}function Lr(e,t){return Rr([e],[t])}function Rr(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 zr(e,t){let n=t;for(;n!=null;){let t=K(e,n);if(!V(t)||H(t,2))return null;if(!Dn(e,n,t))return n;n=t.parentId}return null}function Br(e,t){let n=K(e,t);if(Pt(n,(t===e.snapshot.rootId?-1:At(K(e,n.parentId)))+1),!V(n))return;let r=G(e,t);for(let t of r.childIds)Br(e,t)}function Vr(e,t,n){let r=n;for(;r!=null;){if(r===t)return!0;let n=K(e,r);if(r===e.snapshot.rootId)return!1;r=n.parentId}return!1}function Hr(e,t,n=K(e,t),r=!1){let i=e.instrumentation;if(i==null){Wr(e,t,n,r);return}U(i,`store.recomputeNodeCounts`,()=>Wr(e,t,n,r))}function Ur(e,t){let n=t;for(;n!=null;){let t=K(e,n),r=t.subtreeNodeCount,i=t.visibleSubtreeCount;if(Hr(e,n,t),n===e.snapshot.rootId)return;let a=t.subtreeNodeCount-r,o=t.visibleSubtreeCount-i,s=t.parentId;(a!==0||o!==0)&&bt(G(e,s),n,a,o),n=s}}function Wr(e,t,n,r){if(!V(n)){n.subtreeNodeCount=1,n.visibleSubtreeCount=1;return}let i=G(e,t);if(r){let t=e.instrumentation;t==null?yt(e.snapshot.nodes,i):U(t,`store.recomputeNodeCounts.rebuildChildAggregates`,()=>yt(e.snapshot.nodes,i))}let a=1+i.totalChildSubtreeNodeCount,o=i.totalChildVisibleSubtreeCount;if(n.subtreeNodeCount=a,H(n,2)){n.visibleSubtreeCount=o;return}n.visibleSubtreeCount=sr(e,t)==null?Dn(e,t,n)?1+o:1:o}function Gr(e,t,n){let r=W(e,t);return r.length===0?n:`${r}${n}`}function Kr(e){return e!=null&&!H(e,4)}function qr(e,t){let n=e.snapshot.nodes[t];return!Kr(n)||!V(n)||H(n,2)?null:n}function Jr(e){let t=0;for(let[n,r]of e.pathCacheByNodeId)r.version===e.pathCacheVersion&&Kr(e.snapshot.nodes[n])&&(t+=1);return t}function Yr(e){return Math.max(0,e.valueById.length-1)}function Xr(e){return{activeNodeCount:e.activeNodeCount,cachedPathEntryCount:Jr(e),loadInfoEntryCount:e.directoryLoadInfoById.size,segmentCount:Yr(e.snapshot.segmentTable),totalNodeSlotCount:Math.max(0,e.snapshot.nodes.length-1)}}function Zr(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 Qr(e){let t=[],n=[];for(let n of e.collapsedDirectoryIds)qr(e,n)!=null&&t.push(W(e,n));for(let t of e.expandedDirectoryIds)qr(e,t)!=null&&n.push(W(e,t));return{collapsedPaths:t,expandedPaths:n}}function $r(e){let t=[];for(let[n,r]of e.directoryLoadInfoById)qr(e,n)==null||An(e,n)===`loaded`||t.push({info:{activeAttemptId:null,errorMessage:r.errorMessage,nextAttemptId:r.nextAttemptId,state:r.state},path:W(e,n)});return t}function ei(e,t){e.collapsedDirectoryIds.clear(),e.hasCollapsedDirectoryOverrides=!1,e.expandedDirectoryIds.clear();for(let n of t.expandedPaths){let t=yr(e,n);t!=null&&On(e,t,!0,K(e,t))}for(let n of t.collapsedPaths){let t=yr(e,n);t!=null&&On(e,t,!1,K(e,t))}}function ti(e,t){e.directoryLoadInfoById.clear();for(let n of t){let t=yr(e,n.path);t!=null&&qr(e,t)!=null&&e.directoryLoadInfoById.set(t,{activeAttemptId:null,errorMessage:n.info.errorMessage,nextAttemptId:n.info.nextAttemptId,state:n.info.state})}}function ni(e){e.pathCacheVersion+=1,e.pathCacheByNodeId.clear(),e.pathCacheByNodeId.set(e.snapshot.rootId,{path:``,version:e.pathCacheVersion})}function ri(e){let t=e.snapshot.segmentTable,n=nn();for(let r of e.snapshot.nodes)if(Kr(r)){if(H(r,2)){r.nameId=0;continue}r.nameId=rn(n,an(t,r.nameId))}e.snapshot.segmentTable=n}function ii(e){for(let[t,n]of e.snapshot.directories){let r=e.snapshot.nodes[t];if(!Kr(r)||!V(r)){e.snapshot.directories.delete(t);continue}let i=n.childIds.filter(n=>{let r=e.snapshot.nodes[n];return Kr(r)&&r.parentId===t});n.childIds=i,n.childIdByNameId=new Map(i.map(t=>[K(e,t).nameId,t])),n.childPositionById=new Map(i.map((e,t)=>[e,t])),yt(e.snapshot.nodes,n)}}function ai(e){let t=e.snapshot.nodes.length-1;for(;t>e.snapshot.rootId;){let n=e.snapshot.nodes[t];if(Kr(n))break;--t}e.snapshot.nodes.length=t+1}function oi(e){let t=Qr(e),n=$r(e);U(e.instrumentation,`store.cleanup.stable.clearPathCaches`,()=>ni(e)),U(e.instrumentation,`store.cleanup.stable.rebuildSegmentTable`,()=>ri(e)),U(e.instrumentation,`store.cleanup.stable.rebuildDirectoryIndexes`,()=>ii(e)),U(e.instrumentation,`store.cleanup.stable.trimTrailingRemovedNodeSlots`,()=>ai(e)),U(e.instrumentation,`store.cleanup.stable.restoreExpansionOverrides`,()=>ei(e,t)),U(e.instrumentation,`store.cleanup.stable.restoreDirectoryLoadInfos`,()=>ti(e,n)),U(e.instrumentation,`store.cleanup.stable.recomputeCounts`,()=>_r(e,e.snapshot.rootId))}function si(e){let t=Qr(e),n=$r(e),r=U(e.instrumentation,`store.cleanup.aggressive.listPaths`,()=>ur(e)),i=It({...e.snapshot.options},e.instrumentation),a=U(e.instrumentation,`store.cleanup.aggressive.rebuildSnapshot`,()=>{let e=new Sn(i);return e.appendPaths(r),e.finish()});e.snapshot=a,e.activeNodeCount=a.nodes.length-1,e.pathCacheByNodeId=new Map([[a.rootId,{path:``,version:0}]]),e.pathCacheVersion=0,U(e.instrumentation,`store.cleanup.aggressive.restoreExpansionOverrides`,()=>ei(e,t)),U(e.instrumentation,`store.cleanup.aggressive.restoreDirectoryLoadInfos`,()=>ti(e,n)),U(e.instrumentation,`store.cleanup.aggressive.recomputeCounts`,()=>_r(e,e.snapshot.rootId))}function ci(e){for(let t of e.directoryLoadInfoById.values())if(t.state===`loading`&&t.activeAttemptId!=null)return!0;return!1}function li(e,t){let n=Xr(e);t===`stable`?U(e.instrumentation,`store.cleanup.stable`,()=>oi(e)):U(e.instrumentation,`store.cleanup.aggressive`,()=>si(e));let r=Xr(e);return Zr(t,t===`stable`,n,r)}var ui=64;function di(e,t){let n=t+2;if(n<=e.length)return e;let r=e.length;for(;r<n;)r*=2;let i=new Int32Array(r);return i.fill(-1),i.set(e),i}function fi(e){return K(e,e.snapshot.rootId).visibleSubtreeCount}function pi(e,t,n,r){let i=K(e,t.terminalNodeId),a=Math.max(1,i.visibleSubtreeCount);return Math.min(r-1,n+a-1)}function mi(e,t,n,r){return{ancestorPaths:r,index:t.index,posInSet:t.posInSet,row:Ni(e,t.cursor),setSize:t.setSize,subtreeEndIndex:pi(e,t.cursor,t.index,n)}}function hi(e,t,n,r,i,a){let o=G(e,t),{childIndex:s,childVisibleIndex:c,localVisibleIndex:l}=xt(e.snapshot.nodes,o,n),u=o.childIds[s];if(u==null)throw Error(`Visible index ${String(n)} is out of range`);return gi(e,u,l,r+c,i+1,s,o.childIds.length,a)}function gi(e,t,n,r,i,a,o,s){if(!V(K(e,t))){if(n===0)return{ancestors:s,cursor:{headNodeId:t,terminalNodeId:t,visibleDepth:i},index:r,posInSet:a,setSize:o};throw Error(`Visible index ${String(n)} is out of range for file`)}let c=Di(e,t,i);if(n===0)return{ancestors:s,cursor:c,index:r,posInSet:a,setSize:o};let l=K(e,c.terminalNodeId);if(!V(l)||!Dn(e,c.terminalNodeId,l))throw Error(`Visible index ${String(n)} is out of range for collapsed directory`);return hi(e,c.terminalNodeId,n-1,r+1,c.visibleDepth,[...s,{cursor:c,index:r,posInSet:a,setSize:o}])}function _i(e,t){let n=fi(e);if(t<0||t>=n)return null;let r=hi(e,e.snapshot.rootId,t,0,-1,[]),i=r.ancestors.map(t=>W(e,t.cursor.terminalNodeId)),a=null;return{ancestorPaths:i,get ancestorRows(){if(a!=null)return a;let t=[],i=[];for(let a of r.ancestors){let r=mi(e,a,n,[...i]);t.push(r),i.push(r.row.path)}return a=t,a},index:r.index,posInSet:r.posInSet,row:Ni(e,r.cursor),setSize:r.setSize,subtreeEndIndex:pi(e,r.cursor,r.index,n)}}function vi(e,t,n){let r=e.instrumentation,i=fi(e);if(i<=0||n<t)return[];let a=Math.max(0,Math.min(t,i-1)),o=Math.max(a,Math.min(n,i-1));if(r==null){if(a===0)return Mi(e,o+1);let t=[],n=wi(e,a);for(let r=a;r<=o&&n!=null;r++){let r=Ni(e,n);t.push(r),n=ki(e,n)}return t}let s=[],c=0,l=0,u=U(r,`store.getVisibleSlice.selectFirstRow`,()=>wi(e,a));for(let t=a;t<=o&&u!=null;t++){let t=U(r,`store.getVisibleSlice.materializeRow`,()=>Ni(e,u));s.push(t),t.isFlattened&&(c++,l+=t.flattenedSegments?.length??0),u=U(r,`store.getVisibleSlice.advanceCursor`,()=>ki(e,u))}return Rt(r,`workload.visibleRowsRead`,s.length),Rt(r,`workload.flattenedRowsRead`,c),Rt(r,`workload.flattenedSegmentsRead`,l),s}function yi(e,t=fi(e)){let n=e.instrumentation;return n==null?ji(e,t):U(n,`store.getVisibleTreeProjection`,()=>ji(e,t))}function bi(e){return Ai(yi(e))}function xi(e,t){let n=yr(e,t);if(n==null||n===e.snapshot.rootId||V(K(e,n))&&cr(e,n)!==n)return null;let r=0,i=n,{nodes:a,rootId:o}=e.snapshot;for(;i!==o;){let t=K(e,i).parentId,n=G(e,t),s=gt(n).get(i);if(s==null)throw Error(`Child ${String(i)} was not found in its parent index`);if(r+=St(a,n,s),t!==o){let n=K(e,t),a=sr(e,t);if(!Dn(e,t,n)&&a!==i)return null;cr(e,t)===t&&(r+=1)}i=t}return r}function Si(e,t){let n=yr(e,t);if(n==null)throw Error(`Path does not exist: "${t}"`);let r=K(e,n);if(!V(r))throw Error(`Path is not a directory: "${t}"`);return Dn(e,n,r)?null:(On(e,n,!0,r),gr(e,n),Vn({affectedAncestorIds:vr(e,n),affectedNodeIds:[n],path:t,projectionChanged:!0}))}function Ci(e,t){let n=yr(e,t);if(n==null)throw Error(`Path does not exist: "${t}"`);let r=K(e,n);if(!V(r))throw Error(`Path is not a directory: "${t}"`);return Dn(e,n,r)?(On(e,n,!1,r),gr(e,n),Hn({affectedAncestorIds:vr(e,n),affectedNodeIds:[n],path:t,projectionChanged:!0})):null}function wi(e,t){return t<0||t>=fi(e)?null:Ti(e,e.snapshot.rootId,t,-1)}function Ti(e,t,n,r){let i=G(e,t),a=e.instrumentation,{childIndex:o,localVisibleIndex:s}=a==null?xt(e.snapshot.nodes,i,n):U(a,`store.getVisibleSlice.selectChildIndex`,()=>xt(e.snapshot.nodes,i,n)),c=i.childIds[o];if(c!=null)return Ei(e,c,s,r+1);throw Error(`Visible index ${String(n)} is out of range`)}function Ei(e,t,n,r){if(!V(K(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=Di(e,t,r);if(n===0)return i;let a=K(e,i.terminalNodeId);if(!V(a)||!Dn(e,i.terminalNodeId,a))throw Error(`Visible index ${String(n)} is out of range for collapsed directory`);return Ti(e,i.terminalNodeId,n-1,i.visibleDepth)}function Di(e,t,n){return V(K(e,t))?e.instrumentation==null?{headNodeId:t,terminalNodeId:cr(e,t),visibleDepth:n}:{headNodeId:t,terminalNodeId:U(e.instrumentation,`store.getVisibleSlice.flatten.resolveTerminalDirectory`,()=>cr(e,t)),visibleDepth:n}:{headNodeId:t,terminalNodeId:t,visibleDepth:n}}function Oi(e,t){let n=K(e,t);if(!V(n))return!0;let r=n.parentId;return r===e.snapshot.rootId?!0:sr(e,r)!==t}function ki(e,t){let n=K(e,t.terminalNodeId);if(V(n)){let r=G(e,t.terminalNodeId);if(Dn(e,t.terminalNodeId,n)&&r.childIds.length>0){let n=r.childIds[0];return n==null?null:Ei(e,n,0,t.visibleDepth+1)}}let r=t.terminalNodeId,i=t.visibleDepth;for(;;){let t=K(e,r);if(r===e.snapshot.rootId)return null;let n=t.parentId,a=G(e,n),o=gt(a).get(r)??-1;if(o<0)throw Error(`Child ${String(r)} was not found in its parent index`);let s=a.childIds[o+1]??null;if(s!=null)return Ei(e,s,0,i);Oi(e,r)&&i--,r=n}}function Ai(e){let t=e.paths.length,n=Array(t);for(let r=0;r<t;r+=1){let t=e.getParentIndex(r);n[r]={index:r,parentPath:t>=0?e.paths[t]??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 ji(e,t){let n=Array(t),r=new Int32Array(t),i=new Int32Array(t),a=new Int32Array(t),o=new Int32Array(ui);o.fill(-1);let s=0,{nodes:c,directories:l,segmentTable:u}=e.snapshot,d=[[l.get(e.snapshot.rootId),0,-1,``]],f=e.snapshot.options.flattenEmptyDirectories,p=e.pathCacheByNodeId,m=e.pathCacheVersion,h=u.valueById;for(;d.length>0&&s<t;){let t=d[d.length-1],u=t[0];if(t[1]>=u.childIds.length){d.pop();continue}let g=t[1],_=u.childIds[t[1]++],v=c[_],y=t[2]+1,b=t[3];o=di(o,y);let x,S=_;if(V(v))S=f?cr(e,_):_,x=S===_?`${b}${h[v.nameId]}/`:W(e,S);else{let e=p.get(_);x=e!=null&&e.version===m?e.path:`${b}${h[v.nameId]}`}r[s]=o[y],n[s]=x,i[s]=g,a[s]=u.childIds.length,o[y+1]=s,s+=1;let C=c[S];C!=null&&V(C)&&Dn(e,S,C)&&d.push([l.get(S),0,y,x])}s<t&&(n.length=s);let g=r.subarray(0,s),_=i.subarray(0,s),v=a.subarray(0,s),y=null;return{getParentIndex(e){return e<0||e>=s?-1:g[e]??-1},paths:n,posInSetByIndex:_,setSizeByIndex:v,get visibleIndexByPath(){if(y==null){y=new Map;for(let e=0;e<s;e+=1)y.set(n[e]??``,e)}return y}}}function Mi(e,t){let n=Array(t),r=0,{nodes:i,directories:a,segmentTable:o}=e.snapshot,s=[[a.get(e.snapshot.rootId),0,-1]],c=o.valueById,l=e.snapshot.options.flattenEmptyDirectories,u=e.pathCacheByNodeId,d=e.pathCacheVersion;for(;s.length>0&&r<t;){let t=s[s.length-1],o=t[0];if(t[1]>=o.childIds.length){s.pop();continue}let f=o.childIds[t[1]++],p=i[f],m=t[2]+1;if(!V(p)){let t=u.get(f);n[r++]={depth:m,flattenedSegments:void 0,hasChildren:!1,id:f,isExpanded:!1,isFlattened:!1,isLoading:!1,kind:`file`,loadState:void 0,name:c[p.nameId],path:t!=null&&t.version===d?t.path:W(e,f)};continue}let h=l?cr(e,f):f,g={headNodeId:f,terminalNodeId:h,visibleDepth:m};n[r++]=Ni(e,g);let _=i[h];_!=null&&V(_)&&Dn(e,h,_)&&s.push([a.get(h),0,m])}return r<t&&(n.length=r),n}function Ni(e,t){let n=K(e,t.terminalNodeId),r=V(n)?Pi(e,t):null,i=W(e,t.terminalNodeId),a=an(e.snapshot.segmentTable,n.nameId),o=V(n)&&G(e,t.terminalNodeId).childIds.length>0,s=t.headNodeId!==t.terminalNodeId,c=e.instrumentation,l=s?c==null?lr(e,t.headNodeId).map(n=>{let r=K(e,n);return{isTerminal:n===t.terminalNodeId,name:an(e.snapshot.segmentTable,r.nameId),nodeId:n,path:W(e,n)}}):U(c,`store.getVisibleSlice.flatten.collectSegments`,()=>lr(e,t.headNodeId).map(n=>{let r=K(e,n);return{isTerminal:n===t.terminalNodeId,name:an(e.snapshot.segmentTable,r.nameId),nodeId:n,path:W(e,n)}})):void 0;return{depth:t.visibleDepth,flattenedSegments:l,hasChildren:o,id:t.terminalNodeId,isExpanded:V(n)&&Dn(e,t.terminalNodeId,n),isFlattened:s,isLoading:r===`loading`,kind:V(n)?`directory`:`file`,loadState:r==null||r===`loaded`?void 0:r,name:a,path:i}}function Pi(e,t){if(t.headNodeId===t.terminalNodeId)return An(e,t.terminalNodeId);let n=lr(e,t.headNodeId),r=!1,i=!1;for(let t of n){let n=An(e,t);if(n===`loading`)return`loading`;if(n===`error`){i=!0;continue}n===`unloaded`&&(r=!0)}return i?`error`:r?`unloaded`:`loaded`}function Fi(e){let{directories:t,nodes:n,options:r,rootId:i,presortedDirectoryNodeIds:a}=e.snapshot,o=r.flattenEmptyDirectories===!0,s=e=>{let r=n[e];if(r==null||!V(r))return;let i=t.get(e);if(i==null)throw Error(`Unknown directory child index for node ${String(e)}`);let a=i.childIds,s=a.length,c=0,l=0;for(let e=0;e<s;e++){let t=a[e];if(t==null)continue;let r=n[t];c+=r.subtreeNodeCount,l+=r.visibleSubtreeCount}i.totalChildSubtreeNodeCount=c,i.totalChildVisibleSubtreeCount=l,s>=128&&Ct(n,i),r.subtreeNodeCount=1+c;let u;if(o&&s===1){let e=n[a[0]];u=e!=null&&V(e)?l:1+l}else u=1+l;r.visibleSubtreeCount=u};if(a!=null)for(let e=a.length-1;e>=0;e--)s(a[e]);else for(let e=n.length-1;e>=1;e--)s(e);let c=n[i],l=t.get(i);if(c==null||l==null)return;let u=l.childIds,d=0,f=0;for(let e=0;e<u.length;e++){let t=u[e];if(t==null)continue;let r=n[t];d+=r.subtreeNodeCount,f+=r.visibleSubtreeCount}l.totalChildSubtreeNodeCount=d,l.totalChildVisibleSubtreeCount=f,Ct(n,l),c.subtreeNodeCount=1+d,c.visibleSubtreeCount=f}function Ii(e){return e.initialExpansion===`open`&&(e.initialExpandedPaths==null||e.initialExpandedPaths.length===0)}var Li=class e{#e;constructor(e={}){let t=Lt(e),n=U(t,`store.builder.create`,()=>new Sn(e));if(e.preparedInput!=null){let t=yn(e.preparedInput);t==null?n.appendPreparedPaths(vn(e.preparedInput),!1):n.appendPresortedPaths(t,bn(e.preparedInput))}else{let r=e.paths??[];e.presorted===!0?n.appendPaths(r):n.appendPreparedPaths(U(t,`store.preparePathEntries`,()=>xn(r,e)))}let r=U(t,`store.builder.finish`,()=>n.finish({skipSubtreeCountPass:!0})),i=U(t,`store.state.detectAllDirectoriesExpanded`,()=>(e.initialExpansion??`closed`)===`closed`&&n.didMatchAllInitialExpandedPaths());this.#e=U(t,`store.state.create`,()=>Cn(r,i?`open`:e.initialExpansion??`closed`,t)),i&&(this.#e.collapseNewDirectoriesByDefault=!0);let a=i?this.#e.snapshot.directories.size-1:U(t,`store.state.initializeExpandedPaths`,()=>this.initializeExpandedPaths(e.initialExpandedPaths));i||Ii(e)||(e.initialExpansion??`closed`)===`closed`&&a===this.#e.snapshot.directories.size-1||(e.initialExpandedPaths?.length??0)>0&&U(t,`store.state.checkAllDirectoriesExpanded`,()=>this.hasAllDirectoriesExpanded())?U(t,`store.state.initializeOpenVisibleCounts`,()=>Fi(this.#e)):U(t,`store.state.recomputeCounts`,()=>_r(this.#e,this.#e.snapshot.rootId))}static preparePaths(e,t={}){return hn(e,t)}static prepareInput(e,t={}){return gn(e,t)}static preparePresortedInput(e){return _n(e)}list(e){return U(this.#e.instrumentation,`store.list`,()=>ur(this.#e,e))}add(e){U(this.#e.instrumentation,`store.add`,()=>{let t=fi(this.#e);Zn(this.#e,Yn(this.#e,t,dr(this.#e,e)))})}remove(e,t={}){U(this.#e.instrumentation,`store.remove`,()=>{let n=fi(this.#e);Zn(this.#e,Yn(this.#e,n,fr(this.#e,e,t)))})}move(e,t,n={}){U(this.#e.instrumentation,`store.move`,()=>{let r=fi(this.#e),i=pr(this.#e,e,t,n);i!=null&&Zn(this.#e,Yn(this.#e,r,i))})}batch(e){Xn(this.#e,()=>{if(typeof e==`function`){e(this);return}for(let t of e)switch(t.type){case`add`:this.add(t.path);break;case`remove`:this.remove(t.path,{recursive:t.recursive});break;case`move`:this.move(t.from,t.to,{collision:t.collision});break}})}getVisibleCount(){return U(this.#e.instrumentation,`store.getVisibleCount`,()=>fi(this.#e))}getVisibleSlice(e,t){return U(this.#e.instrumentation,`store.getVisibleSlice`,()=>vi(this.#e,e,t))}getVisibleRowContext(e){return U(this.#e.instrumentation,`store.getVisibleRowContext`,()=>_i(this.#e,e))}getVisibleTreeProjection(){return bi(this.#e)}getVisibleTreeProjectionData(e){return yi(this.#e,e)}getVisibleIndex(e){return U(this.#e.instrumentation,`store.getVisibleIndex`,()=>xi(this.#e,e))}getPathInfo(e){return U(this.#e.instrumentation,`store.getPathInfo`,()=>{let t=yr(this.#e,e);if(t==null)return null;let n=K(this.#e,t);return{depth:At(n),kind:V(n)?`directory`:`file`,path:W(this.#e,t)}})}isExpanded(e){return U(this.#e.instrumentation,`store.isExpanded`,()=>{let t=this.requireDirectoryNodeId(e),n=K(this.#e,t);return Dn(this.#e,t,n)})}expand(e){U(this.#e.instrumentation,`store.expand`,()=>{let t=fi(this.#e),n=Si(this.#e,e);n!=null&&Zn(this.#e,Yn(this.#e,t,n))})}collapse(e){U(this.#e.instrumentation,`store.collapse`,()=>{let t=fi(this.#e),n=Ci(this.#e,e);n!=null&&Zn(this.#e,Yn(this.#e,t,n))})}on(e,t){return Ln(this.#e,e,t)}getDirectoryLoadState(e){let t=this.requireDirectoryNodeId(e);return An(this.#e,t)}markDirectoryUnloaded(e){U(this.#e.instrumentation,`store.markDirectoryUnloaded`,()=>{let t=this.requireDirectoryNodeId(e);if(G(this.#e,t).childIds.length>0)throw Error(`Cannot mark a directory with known children as unloaded: "${e}"`);let n=fi(this.#e);Mn(this.#e,t),Zn(this.#e,Yn(this.#e,n,Un({affectedAncestorIds:vr(this.#e,t),affectedNodeIds:[t],path:e,projectionChanged:this.isDirectoryProjectionVisible(t)})))})}beginChildLoad(e){return U(this.#e.instrumentation,`store.beginChildLoad`,()=>{let t=this.requireDirectoryNodeId(e),n=fi(this.#e),r=jn(this.#e,t);return Zn(this.#e,Yn(this.#e,n,Wn({affectedAncestorIds:vr(this.#e,t),affectedNodeIds:[t],attemptId:r.attemptId,path:e,projectionChanged:this.isDirectoryProjectionVisible(t),reused:r.reused}))),r})}applyChildPatch(e,t){return U(this.#e.instrumentation,`store.applyChildPatch`,()=>{let n=this.resolveActiveDirectoryNodeId(e.nodeId);if(n==null||An(this.#e,n)!==`loading`||!Pn(this.#e,n,e.attemptId))return!1;let r=W(this.#e,n);this.validateChildPatch(r,t);let i=fi(this.#e),a=[];for(let e of t.operations){Ri(r,e);let t=fi(this.#e);switch(e.type){case`add`:a.push(Yn(this.#e,t,dr(this.#e,e.path)));break;case`remove`:a.push(Yn(this.#e,t,fr(this.#e,e.path,{recursive:e.recursive})));break;case`move`:{let n=pr(this.#e,e.from,e.to,{collision:e.collision});n!=null&&a.push(Yn(this.#e,t,n));break}}}let o=a.some(e=>e.projectionChanged)||this.isDirectoryProjectionVisible(n);return Zn(this.#e,Yn(this.#e,i,Gn({affectedAncestorIds:vr(this.#e,n),affectedNodeIds:[n],attemptId:e.attemptId,childEvents:a,path:W(this.#e,n),projectionChanged:o}))),!0})}completeChildLoad(e){return U(this.#e.instrumentation,`store.completeChildLoad`,()=>{let t=this.resolveActiveDirectoryNodeId(e.nodeId);if(t==null)return!1;let n=fi(this.#e),r=Nn(this.#e,t,e.attemptId);return Zn(this.#e,Yn(this.#e,n,Kn({affectedAncestorIds:vr(this.#e,t),affectedNodeIds:[t],attemptId:e.attemptId,path:W(this.#e,t),projectionChanged:this.isDirectoryProjectionVisible(t),stale:!r}))),r})}failChildLoad(e,t){return U(this.#e.instrumentation,`store.failChildLoad`,()=>{let n=this.resolveActiveDirectoryNodeId(e.nodeId);if(n==null)return!1;let r=fi(this.#e),i=Fn(this.#e,n,e.attemptId,t);return Zn(this.#e,Yn(this.#e,r,qn({affectedAncestorIds:vr(this.#e,n),affectedNodeIds:[n],attemptId:e.attemptId,errorMessage:t,path:W(this.#e,n),projectionChanged:this.isDirectoryProjectionVisible(n),stale:!i}))),i})}cleanup(e={}){return U(this.#e.instrumentation,`store.cleanup`,()=>{if(this.#e.transactionStack.length>0)throw Error(`Cleanup cannot run during an open batch or transaction.`);if(ci(this.#e))throw Error(`Cleanup cannot run while directory loads are active.`);let t=fi(this.#e),n=li(this.#e,e.mode??`stable`);return Zn(this.#e,Yn(this.#e,t,Jn({...n,affectedAncestorIds:[],affectedNodeIds:[],projectionChanged:n.idsPreserved===!1}))),n})}getNodeCount(){return this.#e.activeNodeCount}initializeExpandedPaths(e){if(e==null||e.length===0)return 0;let t=0,n=[],r=[],i=0,a=null,o=this.#e.snapshot.segmentTable,s=o.valueById,c=this.#e.snapshot.nodes,l=new Map;for(let u of e){a!=null&&u<a&&(a=null,i=0,n.length=0,r.length=0);let e=u.length>0&&u.charCodeAt(u.length-1)===47?u.length-1:u.length;if(e===0){a=u,i=e,n.length=0,r.length=0;continue}let d=0,f=0;if(a!=null){let t=Math.min(e,i),n=!0;for(let e=0;e<t;e+=1){let t=u.charCodeAt(e);if(t!==a.charCodeAt(e)){n=!1;break}t===47&&(d+=1,f=e+1)}n&&(t===i&&e>t&&u.charCodeAt(t)===47?(d+=1,f=t+1):t===e&&i>t&&a.charCodeAt(t)===47&&(d+=1,f=e+1)),d=Math.min(d,r.length)}let p=d===0?this.#e.snapshot.rootId:r[d-1]??this.#e.snapshot.rootId,m=d,h=!0,g=f;for(;g<=e;){let t=u.indexOf(`/`,g),i=t===-1||t>e?e:t,a=u.slice(g,i),f=G(this.#e,p).childIds,_=m===d?n[m]??0:0,v=_,y,b=l.get(a)??Vt(a);l.set(a,b);let x=(e,t)=>{for(v=e;v<t;v+=1){let e=f[v],t=c[e],n=s[t.nameId];if(n===a)return y=e,!0;let r=Ut(Xt(o,t.nameId),b);if(r>0||r===0&&n>a)return!1}return!1};if(!x(_,f.length)&&_>0&&x(0,_),y===void 0){h=!1;break}if(!V(K(this.#e,y))){h=!1;break}if(n[m]=v,r[m]=y,p=y,m+=1,i===e)break;g=i+1}if(a=u,i=e,n.length=m,r.length=m,!h){a=null,i=0,n.length=0,r.length=0;continue}for(let e=d;e<m;e+=1){let n=r[e];if(n==null)continue;let i=K(this.#e,n);Dn(this.#e,n,i)||(On(this.#e,n,!0,i),t+=1)}}return t}hasAllDirectoriesExpanded(){for(let e of this.#e.snapshot.directories.keys()){if(e===this.#e.snapshot.rootId)continue;let t=K(this.#e,e);if(!Dn(this.#e,e,t))return!1}return!0}requireDirectoryNodeId(e){let t=yr(this.#e,e);if(t==null)throw Error(`Path does not exist: "${e}"`);if(!V(K(this.#e,t)))throw Error(`Path is not a directory: "${e}"`);return t}resolveActiveDirectoryNodeId(e){try{if(!V(K(this.#e,e)))throw Error(`Node is not a directory: ${String(e)}`);return e}catch{return null}}isDirectoryProjectionVisible(e){let t=e;for(;t!==this.#e.snapshot.rootId;){let e=K(this.#e,t).parentId;if(e!==this.#e.snapshot.rootId){let n=K(this.#e,e),r=sr(this.#e,e);if(!Dn(this.#e,e,n)&&r!==t)return!1}t=e}return!0}validateChildPatch(t,n){new e({paths:this.list(t),presorted:!0,sort:this.#e.snapshot.options.sort}).batch(n.operations)}};function Ri(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 zi={compact:{itemHeight:24,factor:.8},default:{itemHeight:30,factor:1},relaxed:{itemHeight:36,factor:1.2}};function Bi(e,t){if(typeof e==`number`)return{itemHeight:t??zi.default.itemHeight,factor:e};let n=zi[e??`default`];return{itemHeight:t??n.itemHeight,factor:n.factor}}var Vi=zi.default.itemHeight,Hi=`@layer base, theme, unsafe;
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{n as t,r as n,t as r}from"./compiler-runtime-CLAvuQ-D.js";import{E as i,F as a,Ku as o,Ms as s,N as c,Rs as l,S as u,Yr as d,b as f,dc as p,en as m,i as h,k as g,ks as _,oc as v,on as y,pi as b,u as x,w as S,y as C,zs as w}from"./terminal-links-FRGOm6CP.js";import{n as T,r as E,t as D}from"./renderFileChildren-uPwkTxXP.js";import{$ as ee,$r as O,$t as k,Ar as A,Bn as j,Bt as M,C as N,D as P,Fn as te,Ht as ne,In as re,Ln as ie,Mr as ae,Nr as oe,On as se,Pn as F,Pr as ce,Q as le,Rn as ue,Rr as I,Rt as de,S as fe,Vn as pe,Wr as me,X as he,b as ge,cr as _e,d as ve,dr as ye,en as be,et as xe,f as Se,jr as Ce,kr as we,l as L,li as Te,lr as Ee,m as De,mr as Oe,ni as ke,oi as R,or as Ae,p as je,pn as Me,qr as Ne,ri as Pe,rt as Fe,si as Ie,tt as Le,u as Re,ur as ze,ut as Be,v as Ve,vr as He,w as Ue,wn as We,x as Ge,y as Ke,zn as qe,zr as Je}from"./index-C4Mhhj24.js";import{a as Ye,i as Xe,n as Ze,r as Qe,t as $e}from"./fileCommentAnnotations-Dy17abwC.js";var et=s(`code-xml`,[[`path`,{d:`m18 16 4-4-4-4`,key:`1inbqp`}],[`path`,{d:`m6 8-4 4 4 4`,key:`15zrgr`}],[`path`,{d:`m14.5 4-5 16`,key:`e7oirm`}]]),tt=s(`file-question-mark`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}],[`path`,{d:`M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3`,key:`mhlwft`}]]),nt=s(`folder-tree`,[[`path`,{d:`M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`hod4my`}],[`path`,{d:`M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`w4yl2u`}],[`path`,{d:`M3 5a2 2 0 0 0 2 2h3`,key:`f2jnh7`}],[`path`,{d:`M3 3v13a2 2 0 0 0 2 2h3`,key:`k8epm1`}]]),rt=`file-tree-container`,it=`data-file-tree-style`,at=`data-file-tree-unsafe-css`,z=`data-file-tree-scrollbar-measure`,B=`data-file-tree-scrollbar-gutter-measured`,ot=`--trees-scrollbar-gutter-measured`,st=`header`,ct=`context-menu`,lt=`context-menu-trigger`,ut=5,dt=1<<ut,ft=dt*4;function pt(){return{childIdByNameId:new Map,childIds:[],childPositionById:new Map,childVisibleChunkSums:null,totalChildSubtreeNodeCount:0,totalChildVisibleSubtreeCount:0}}function mt(){return{childIdByNameId:null,childIds:[],childPositionById:null,childVisibleChunkSums:null,totalChildSubtreeNodeCount:0,totalChildVisibleSubtreeCount:0}}function ht(e,t){if(t.childIdByNameId!=null)return t.childIdByNameId;let n=new Map;for(let r of t.childIds){let t=e[r];t!=null&&n.set(t.nameId,r)}return t.childIdByNameId=n,n}function gt(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];r!=null&&t.set(r,n)}return e.childPositionById=t,t}function _t(e,t){e.childPositionById!=null&&e.childPositionById.set(t,e.childIds.length),e.childIds.push(t)}function vt(e,t){if(e.childPositionById!=null)for(let n=t;n<e.childIds.length;n++){let t=e.childIds[n];t!=null&&e.childPositionById.set(t,n)}}function yt(e,t){let n=0,r=0;for(let i of t.childIds){let t=e[i];t!=null&&(n+=t.subtreeNodeCount,r+=t.visibleSubtreeCount)}t.totalChildSubtreeNodeCount=n,t.totalChildVisibleSubtreeCount=r,Ct(e,t)}function bt(e,t,n,r){if(e.totalChildSubtreeNodeCount+=n,e.totalChildVisibleSubtreeCount+=r,e.childVisibleChunkSums==null||r===0)return;let i=gt(e).get(t);if(i===void 0)return;let a=i>>ut;e.childVisibleChunkSums[a]+=r}function xt(e,t,n){let r=t.childVisibleChunkSums;if(r!=null){let i=n,a=0;for(let o of r){if(i<o){let r=wt(e,t,a,i);return{...r,childVisibleIndex:n-r.localVisibleIndex}}i-=o,a+=dt}throw Error(`Visible child index ${String(n)} is out of range`)}let i=n;for(let r=0;r<t.childIds.length;r++){let a=t.childIds[r];if(a==null)continue;let o=e[a];if(o!=null){if(i<o.visibleSubtreeCount)return{childIndex:r,childVisibleIndex:n-i,localVisibleIndex:i};i-=o.visibleSubtreeCount}}throw Error(`Visible child index ${String(n)} is out of range`)}function St(e,t,n){let r=0,i=t.childVisibleChunkSums,a=0;if(i!=null){let e=n>>ut;for(let t=0;t<e;t+=1)r+=i[t]??0;a=e<<ut}for(let i=a;i<n;i+=1){let n=t.childIds[i];if(n==null)continue;let a=e[n];a!=null&&(r+=a.visibleSubtreeCount)}return r}function Ct(e,t){if(t.childIds.length<ft){t.childVisibleChunkSums=null;return}let n=Math.ceil(t.childIds.length/dt),r=new Int32Array(n);for(let n=0;n<t.childIds.length;n++){let i=t.childIds[n];if(i==null)continue;let a=e[i];a!=null&&(r[n>>ut]+=a.visibleSubtreeCount)}t.childVisibleChunkSums=r}function wt(e,t,n,r){let i=Math.min(t.childIds.length,n+dt),a=r;for(let r=n;r<i;r++){let n=t.childIds[r];if(n==null)continue;let i=e[n];if(i!=null){if(a<i.visibleSubtreeCount)return{childIndex:r,localVisibleIndex:a};a-=i.visibleSubtreeCount}}throw Error(`Visible child index ${String(r)} is out of range`)}var Tt=7,Et=3,Dt=1<<Et,Ot=4;function kt(e,t,n=0){return e<<Ot|n<<Et|t}function At(e){return e.depthAndFlags>>>Ot}function jt(e){return(e.depthAndFlags&Dt)>>Et}function V(e){return(e.depthAndFlags&Dt)!==0}function Mt(e){return e.depthAndFlags&Tt}function H(e,t){return(Mt(e)&t)!==0}function Nt(e,t){e.depthAndFlags|=t}function Pt(e,t){e.depthAndFlags=kt(t,Mt(e),jt(e))}var Ft=Symbol(`benchmarkInstrumentation`);function It(e,t){return t==null||Object.defineProperty(e,Ft,{configurable:!0,enumerable:!1,value:t,writable:!1}),e}function Lt(e){return e==null?null:e[Ft]??null}function U(e,t,n){return e==null?n():e.measurePhase(t,n)}function Rt(e,t,n){!Number.isFinite(n)||e==null||e.setCounter(t,n)}function zt(e){return e>=48&&e<=57}function Bt(e){let t=[],n=0,r=0;for(;r<e.length;){for(;r<e.length&&!zt(e.charCodeAt(r));)r+=1;if(r>=e.length)break;r>n&&t.push(e.slice(n,r));let i=0;for(;r<e.length&&zt(e.charCodeAt(r));)i=i*10+(e.charCodeAt(r)-48),r+=1;t.push(i),n=r}return(n<e.length||t.length===0)&&t.push(e.slice(n)),t}function Vt(e){let t=e.toLowerCase();return{lowerValue:t,tokens:Bt(t)}}function Ht(e,t){let n=Math.min(e.length,t.length);for(let r=0;r<n;r++){let n=e[r],i=t[r];if(n===i)continue;if(typeof n==`number`&&typeof i==`number`)return n<i?-1:1;let a=String(n),o=String(i);if(a!==o)return a<o?-1:1}return e.length===t.length?0:e.length<t.length?-1:1}function Ut(e,t){if(e.tokens.length===1&&t.tokens.length===1&&typeof e.tokens[0]==`string`&&typeof t.tokens[0]==`string`)return e.lowerValue===t.lowerValue?0:e.lowerValue<t.lowerValue?-1:1;let n=Ht(e.tokens,t.tokens);return n===0?e.lowerValue===t.lowerValue?0:e.lowerValue<t.lowerValue?-1:1:n}function Wt(e,t,n){let r=Ut(n(e),n(t));return r===0?e===t?0:e<t?-1:1:r}function Gt(e,t){return Wt(e,t,Vt)}function Kt(e,t){return t===e.segments.length-1?+!!e.isDirectory:1}function qt(e,t){let n=Math.min(e.segments.length,t.segments.length);for(let r=0;r<n;r++){let n=e.segments[r],i=t.segments[r];if(n===i)continue;let a=Kt(e,r);return a===Kt(t,r)?Gt(n,i):a===1?-1:1}return e.segments.length===t.segments.length?e.isDirectory===t.isDirectory?0:e.isDirectory?-1:1:e.segments.length<t.segments.length?-1:1}function Jt(e,t){return qt(e,t)}function Yt(e,t,n){let r=e=>{let t=n.get(e);if(t!=null)return t;let r=Vt(e);return n.set(e,r),r},i=Math.min(e.segments.length,t.segments.length);for(let n=0;n<i;n++){let i=e.segments[n],a=t.segments[n];if(i===a)continue;let o=Kt(e,n);return o===Kt(t,n)?Wt(i,a,r):o===1?-1:1}return e.segments.length===t.segments.length?e.isDirectory===t.isDirectory?0:e.isDirectory?-1:1:e.segments.length<t.segments.length?-1:1}function Xt(e,t){let n=e.sortKeyById[t];if(n!==void 0)return n;let r=e.valueById[t],i=Vt(r);return e.sortKeyById[t]=i,i}function Zt(e={}){return{flattenEmptyDirectories:e.flattenEmptyDirectories!==!1,sort:e.sort??`default`}}function Qt(e){let t=e.length>0&&e.charCodeAt(e.length-1)===47,n=t?e.length-1:e.length,r=[],i=0;for(let t=0;t<n;t++)e.charCodeAt(t)===47&&(r.push(e.slice(i,t)),i=t+1);return r.push(e.slice(i,n)),{hasTrailingSlash:t,segments:r}}function $t(e){let{hasTrailingSlash:t,segments:n}=Qt(e);return{basename:n[n.length-1]??``,isDirectory:t,path:e,segments:n}}function en(e){if(e.length===0)return{requiresDirectory:!1,segments:[]};let{hasTrailingSlash:t,segments:n}=Qt(e);return{requiresDirectory:t,segments:n}}var tn=``;function nn(){let e=new Map;return e.set(tn,0),{idByValue:e,valueById:[tn],sortKeyById:[Vt(tn)]}}function rn(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 an(e,t){let n=e.valueById[t];if(n===void 0)throw Error(`Unknown segment ID: ${String(t)}`);return n}var on=Symbol(`pathStorePreparedInputKind`);function sn(e,t){return e[on]=t,e}function cn(e){return{basename:e.basename,depth:e.segments.length,isDirectory:e.isDirectory,path:e.path,segments:e.segments}}function ln(e,t,n){return n==="default"?Jt(e,t):n(cn(e),cn(t))}function un(){return{depthAndFlags:kt(0,3,1),nameId:0,parentId:0,subtreeNodeCount:1,visibleSubtreeCount:1}}function dn(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 fn(e){return e.isDirectory?e.segments.length:e.segments.length-1}function pn(e){return Array.isArray(e)&&e.every(e=>typeof e==`object`&&!!e&&typeof e.path==`string`&&Array.isArray(e.segments)&&typeof e.basename==`string`&&typeof e.isDirectory==`boolean`)}function mn(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}function hn(e,t={}){return xn(e,t).map(e=>e.path)}function gn(e,t={}){let n=xn(e,t);return sn({paths:n.map(e=>e.path),preparedPaths:n},`prepared`)}function _n(e){let t=e.length,n=!1;for(let r=0;r<t;r+=1){let t=e[r];if(t.length>0&&t.charCodeAt(t.length-1)===47){n=!0;break}}return sn({paths:e,presortedPaths:e,presortedPathsContainDirectories:n},`presorted`)}function vn(e){let t=e,n=t.preparedPaths;if(t[on]===`prepared`&&n!=null)return n;if(!pn(n))throw Error(`preparedInput must come from PathStore.prepareInput()`);return n}function yn(e){let t=e;return t[on]===`presorted`&&t.presortedPaths!=null||mn(t.presortedPaths)?t.presortedPaths:null}function bn(e){let t=e;return typeof t.presortedPathsContainDirectories==`boolean`?t.presortedPathsContainDirectories:null}function xn(e,t={}){let n=Zt(t),r=Lt(t);Rt(r,`workload.inputFiles`,e.length);let i=U(r,`store.preparePathEntries.parse`,()=>e.map(e=>$t(e)));return U(r,`store.preparePathEntries.sort`,()=>i.sort((e,t)=>ln(e,t,n.sort))),i}var Sn=class{directories=new Map;directoryStack=[0];presortedDirectoryNodeIds=[];initialExpandedPathSet;createdDirectoriesAllExpanded=!1;createdDirectoryCount=0;lastPreparedPath=null;nodes=[un()];options;instrumentation;segmentSortKeyCache=new Map;segmentTable=nn();hasDeferredDirectoryIndexes=!1;constructor(e={}){this.instrumentation=Lt(e),this.options=Zt(e);let t=e.initialExpandedPaths??null;if(t==null||t.length===0)this.initialExpandedPathSet=null;else{let e=new Set,n=t.length;for(let r=0;r<n;r+=1){let n=t[r],i=n.length;e.add(i>0&&n.charCodeAt(i-1)===47?n.slice(0,i-1):n)}this.initialExpandedPathSet=e,this.createdDirectoriesAllExpanded=!0}this.directories.set(0,pt())}appendPaths(e){return U(this.instrumentation,`store.builder.appendPaths.parse`,()=>this.appendPreparedPaths(e.map(e=>$t(e))))}appendPreparedPaths(e,t=!0){return this.createdDirectoriesAllExpanded=!1,U(this.instrumentation,`store.builder.appendPreparedPaths`,()=>{for(let n of e)this.appendPreparedPath(n,t)}),this}appendPresortedPaths(e,t=null){return U(this.instrumentation,`store.builder.appendPresortedPaths`,()=>{if(t===!1){this.appendPresortedFilePaths(e);return}this.createdDirectoriesAllExpanded=!1;let n=null,r=0,i=this.nodes,a=this.segmentTable,o=a.idByValue,s=a.valueById,c=this.directoryStack,l=0,u=``,d=0;for(let t of e){if(n===t)throw Error(`Duplicate path: "${t}"`);let e=t.length>0&&t.charCodeAt(t.length-1)===47,a=e?t.length-1:t.length,f=0,p=0;if(n!=null)if(u.length>0&&t.length>u.length&&t.startsWith(u))f=d,p=u.length;else{let r=Math.min(a,n.length),i=!0;for(let e=0;e<r;e++){let r=t.charCodeAt(e);if(r!==n.charCodeAt(e)){i=!1;break}r===47&&(f++,p=e+1)}i&&e&&r===a&&n.length>a&&n.charCodeAt(a)===47&&(f++,p=a+1)}l=f,r=f;let m=p,h=t.indexOf(`/`,m);for(;h>=0&&h<a;){let e=c[l];if(e===void 0)throw Error(`Directory stack underflow while building the path store`);r++;let n=t.slice(m,h),a=o.get(n);a===void 0&&(a=s.length,o.set(n,a),s.push(n));let u=i.length;i.push({depthAndFlags:kt(r,0,1),nameId:a,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),this.recordCreatedDirectoryPath(t.slice(0,h)),l++,c[l]=u,m=h+1,h=t.indexOf(`/`,m)}if(e){if(m<a){let e=c[l];if(e===void 0)throw Error(`Unable to resolve directory parent for "${t}"`);r++;let n=t.slice(m,a),u=o.get(n);u===void 0&&(u=s.length,o.set(n,u),s.push(n));let d=i.length;i.push({depthAndFlags:kt(r,0,1),nameId:u,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),l++,c[l]=d}let e=c[l];if(e===void 0)throw Error(`Unable to resolve directory node for "${t}"`);this.promoteDirectoryToExplicit(e,t)}else{let e=c[l];if(e===void 0)throw Error(`Unable to resolve file parent for "${t}"`);let n=t.slice(m),a=o.get(n);a===void 0&&(a=s.length,o.set(n,a),s.push(n)),i.push({depthAndFlags:kt(r+1,0),nameId:a,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1})}m!==u.length&&(u=t.substring(0,m),d=r),n=t}c.length=l+1,n!=null&&(this.lastPreparedPath=$t(n)),this.hasDeferredDirectoryIndexes=!0}),this}appendPresortedFilePaths(e){let t=null,n=0,r=this.nodes,i=this.segmentTable,a=i.idByValue,o=i.valueById,s=this.directoryStack,c=0,l=``,u=0;for(let i of e){if(t===i)throw Error(`Duplicate path: "${i}"`);let e=i.length,d=0,f=0;if(t!=null)if(l.length>0&&i.length>l.length&&i.startsWith(l))d=u,f=l.length;else{let n=Math.min(e,t.length);for(let e=0;e<n;e++){let n=i.charCodeAt(e);if(n!==t.charCodeAt(e))break;n===47&&(d++,f=e+1)}}c=d,n=d;let p=f,m=i.indexOf(`/`,p);for(;m>=0;){let e=s[c];if(e===void 0)throw Error(`Directory stack underflow while building the path store`);n++;let t=i.slice(p,m),l=a.get(t);l===void 0&&(l=o.length,a.set(t,l),o.push(t));let u=r.length;r.push({depthAndFlags:kt(n,0,1),nameId:l,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),this.recordCreatedDirectoryPath(i.slice(0,m)),this.presortedDirectoryNodeIds.push(u),c++,s[c]=u,p=m+1,m=i.indexOf(`/`,p)}let h=s[c];if(h===void 0)throw Error(`Unable to resolve file parent for "${i}"`);let g=i.slice(p),_=a.get(g);_===void 0&&(_=o.length,a.set(g,_),o.push(g)),r.push({depthAndFlags:kt(n+1,0),nameId:_,parentId:h,subtreeNodeCount:1,visibleSubtreeCount:1}),p!==l.length&&(l=i.substring(0,p),u=n),t=i}s.length=c+1,t!=null&&(this.lastPreparedPath=$t(t)),this.hasDeferredDirectoryIndexes=!0}finish(e={}){let t=e.skipSubtreeCountPass===!0;return this.hasDeferredDirectoryIndexes?(U(this.instrumentation,`store.builder.buildDirectoryIndexes`,()=>this.buildPresortedFinish(t)),this.hasDeferredDirectoryIndexes=!1):t||U(this.instrumentation,`store.builder.computeSubtreeCounts`,()=>this.computeSubtreeCounts(0)),{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(),!1),this.lastPreparedPath!=null){if(e.path===this.lastPreparedPath.path)throw Error(`Duplicate path: "${e.path}"`);if(t&&(this.options.sort==="default"?Yt(this.lastPreparedPath,e,this.segmentSortKeyCache):ln(this.lastPreparedPath,e,this.options.sort))>0)throw Error(`Builder input must be sorted before appendPaths(): "${e.path}"`)}let n=this.lastPreparedPath,r=fn(e),i=n==null?0:fn(n),a=n==null?0:dn(n.segments,e.segments),o=Math.min(a,r,i);this.directoryStack.length=o+1;for(let n=o;n<r;n++){let r=this.directoryStack[this.directoryStack.length-1];if(r===void 0)throw Error(`Directory stack underflow while building the path store`);let i=t?this.getOrCreateDirectoryChild(r,e.segments[n]):this.createDirectoryChild(r,e.segments[n]);this.directoryStack.push(i)}if(e.isDirectory){let t=this.directoryStack[this.directoryStack.length-1];if(t===void 0)throw Error(`Unable to resolve directory node for "${e.path}"`);this.promoteDirectoryToExplicit(t,e.path),this.lastPreparedPath=e;return}let s=this.directoryStack[this.directoryStack.length-1];if(s===void 0)throw Error(`Unable to resolve file parent for "${e.path}"`);t?this.createFileChild(s,e.basename,e.path):this.createFileChildUnchecked(s,e.basename),this.lastPreparedPath=e}recordCreatedDirectoryPath(e){!this.createdDirectoriesAllExpanded||this.initialExpandedPathSet==null||(this.createdDirectoryCount+=1,this.initialExpandedPathSet.has(e)||(this.createdDirectoriesAllExpanded=!1))}createFileChild(e,t,n){let r=rn(this.segmentTable,t),i=this.getDirectoryIndex(e),a=i.childIdByNameId;if(a!=null&&a.get(r)!==void 0)throw Error(`Path collides with an existing entry: "${n}"`);let o=this.nodes[e];if(o===void 0)throw Error(`Unknown parent node ID: ${String(e)}`);let s=this.nodes.length;return this.nodes.push({depthAndFlags:kt(At(o)+1,0),nameId:r,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),a?.set(r,s),_t(i,s),s}createFileChildUnchecked(e,t){let n=rn(this.segmentTable,t),r=this.getDirectoryIndex(e),i=this.nodes[e];if(i===void 0)throw Error(`Unknown parent node ID: ${String(e)}`);let a=this.nodes.length;return this.nodes.push({depthAndFlags:kt(At(i)+1,0),nameId:n,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),r.childIdByNameId!=null&&r.childIdByNameId.set(n,a),_t(r,a),a}getOrCreateDirectoryChild(e,t){let n=rn(this.segmentTable,t),r=this.getDirectoryIndex(e);if(r.childIdByNameId!=null){let e=r.childIdByNameId.get(n);if(e!==void 0){let n=this.nodes[e];if(n!=null&&!V(n))throw Error(`Path collides with an existing file while creating directory "${t}"`);return e}}let i=this.nodes[e];if(i===void 0)throw Error(`Unknown parent node ID: ${String(e)}`);let a=this.nodes.length;return this.nodes.push({depthAndFlags:kt(At(i)+1,0,1),nameId:n,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),r.childIdByNameId!=null&&r.childIdByNameId.set(n,a),_t(r,a),this.directories.set(a,pt()),a}createDirectoryChild(e,t){let n=rn(this.segmentTable,t),r=this.getDirectoryIndex(e),i=this.nodes[e];if(i===void 0)throw Error(`Unknown parent node ID: ${String(e)}`);let a=this.nodes.length;return this.nodes.push({depthAndFlags:kt(At(i)+1,0,1),nameId:n,parentId:e,subtreeNodeCount:1,visibleSubtreeCount:1}),r.childIdByNameId!=null&&r.childIdByNameId.set(n,a),_t(r,a),this.directories.set(a,pt()),a}promoteDirectoryToExplicit(e,t){let n=this.nodes[e];if(n===void 0)throw Error(`Unknown directory node ID: ${String(e)}`);if(!V(n))throw Error(`Path is not a directory: "${t}"`);if(H(n,1))throw Error(`Duplicate path: "${t}"`);Nt(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,mt());let r=-1,i=null;for(let e=1;e<t.length;e++){let a=t[e];if(a==null)continue;if(V(a)){let t=mt();n.set(e,t),r=e,i=t}let o;a.parentId===r?o=i:(o=n.get(a.parentId),r=a.parentId,i=o??null),o?.childIds.push(e)}if(!e)for(let e=t.length-1;e>=1;e--){let n=t[e];if(n==null)continue;let r=t[n.parentId];r!=null&&(r.subtreeNodeCount+=n.subtreeNodeCount,r.visibleSubtreeCount+=n.visibleSubtreeCount)}}buildDirectoryIndexes(){let e=this.nodes;for(let t=1;t<e.length;t++){let n=e[t];if(n==null)continue;V(n)&&this.directories.set(t,pt());let r=this.directories.get(n.parentId);r!=null&&(r.childIdByNameId!=null&&r.childIdByNameId.set(n.nameId,t),_t(r,t))}}computeSubtreeCounts(e){let t=this.nodes[e];if(t===void 0)throw Error(`Unknown node ID: ${String(e)}`);if(!V(t))return t.subtreeNodeCount=1,t.visibleSubtreeCount=1,1;let n=this.getDirectoryIndex(e),r=1;for(let e of n.childIds)r+=this.computeSubtreeCounts(e);return yt(this.nodes,n),t.subtreeNodeCount=r,t.visibleSubtreeCount=r,r}};function Cn(e,t=`closed`,n=null){let r=Tn(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 wn(){return{affectedAncestorIds:new Set,affectedNodeIds:new Set,events:[]}}function Tn(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 En(e,t){return H(t,2)||e.defaultExpansion===`open`?!0:e.defaultExpansion===`closed`?!1:At(t)<=e.defaultExpansion}function Dn(e,t,n=e.snapshot.nodes[t]){return n==null||!V(n)?!1:e.directoriesOpenByDefault&&!e.hasCollapsedDirectoryOverrides?!0:e.collapsedDirectoryIds.has(t)?!1:e.expandedDirectoryIds.has(t)?!0:En(e,n)}function On(e,t,n,r=e.snapshot.nodes[t]){if(r==null||!V(r))return;let i=En(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 kn(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 An(e,t){return e.directoryLoadInfoById.get(t)?.state??`loaded`}function jn(e,t){let n=kn(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 Mn(e,t){let n=kn(e,t);n.activeAttemptId=null,n.errorMessage=null,n.state=`unloaded`}function Nn(e,t,n){let r=e.directoryLoadInfoById.get(t);return r==null||r.activeAttemptId!==n?!1:(r.activeAttemptId=null,r.errorMessage=null,r.state=`loaded`,!0)}function Pn(e,t,n){return e.directoryLoadInfoById.get(t)?.activeAttemptId===n}function Fn(e,t,n,r){let i=e.directoryLoadInfoById.get(t);return i==null||i.activeAttemptId!==n?!1:(i.activeAttemptId=null,i.errorMessage=r??null,i.state=`error`,!0)}function In(e,t){e.directoryLoadInfoById.delete(t)}function Ln(e,t,n){let r=n,i=e.listeners.get(t);return i==null?e.listeners.set(t,new Set([r])):i.add(r),()=>{let n=e.listeners.get(t);n!=null&&(n.delete(r),n.size===0&&e.listeners.delete(t))}}function Rn(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!0,operation:`add`,path:e.path,projectionChanged:e.projectionChanged,visibleCountDelta:null}}function zn(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!0,operation:`remove`,path:e.path,projectionChanged:e.projectionChanged,recursive:e.recursive,visibleCountDelta:null}}function Bn(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!0,from:e.from,operation:`move`,projectionChanged:e.projectionChanged,to:e.to,visibleCountDelta:null}}function Vn(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!1,operation:`expand`,path:e.path,projectionChanged:!0,visibleCountDelta:null}}function Hn(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!1,operation:`collapse`,path:e.path,projectionChanged:!0,visibleCountDelta:null}}function Un(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],canonicalChanged:!1,operation:`mark-directory-unloaded`,path:e.path,projectionChanged:e.projectionChanged,visibleCountDelta:null}}function Wn(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 Gn(e){return{affectedAncestorIds:e.affectedAncestorIds??[],affectedNodeIds:e.affectedNodeIds??[],attemptId:e.attemptId,canonicalChanged:e.childEvents.some(e=>e.canonicalChanged),childEvents:e.childEvents,operation:`apply-child-patch`,path:e.path,projectionChanged:e.projectionChanged,visibleCountDelta:null}}function Kn(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 qn(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 Jn(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 Yn(e,t,n){return{...n,visibleCountDelta:or(e)-t}}function Xn(e,t){let n=or(e),r=wn();e.transactionStack.push(r);try{t()}catch(t){throw $n(e,r,!1),t}$n(e,r,!0,or(e)-n)}function Zn(e,t){let n=e.instrumentation;if(n==null){Qn(e,t);return}U(n,`store.events.record`,()=>Qn(e,t))}function Qn(e,t){let n=e.transactionStack[e.transactionStack.length-1]??null;if(n==null){ir(e,t);return}n.events.push(t),rr(n,t)}function $n(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 n=e.instrumentation;n==null?nr(i,t):U(n,`store.events.batch.merge`,()=>nr(i,t));return}let a=er(t,r),o=e.instrumentation;if(o==null){ir(e,a);return}U(o,`store.events.batch.commit`,()=>ir(e,a))}function er(e,t){return{affectedAncestorIds:[...e.affectedAncestorIds],affectedNodeIds:[...e.affectedNodeIds],canonicalChanged:e.events.some(e=>e.canonicalChanged),events:[...e.events],operation:`batch`,projectionChanged:e.events.some(e=>e.projectionChanged),visibleCountDelta:t}}function tr(e,t){for(let n of t.affectedAncestorIds)e.affectedAncestorIds.add(n);for(let n of t.affectedNodeIds)e.affectedNodeIds.add(n)}function nr(e,t){for(let n of t.events)e.events.push(n);tr(e,t)}function rr(e,t){for(let n of t.affectedNodeIds)e.affectedNodeIds.add(n);for(let n of t.affectedAncestorIds)e.affectedAncestorIds.add(n)}function ir(e,t){let n=e.instrumentation;if(n==null){ar(e,t);return}U(n,`store.events.emit`,()=>ar(e,t))}function ar(e,t){e.listeners.get(t.operation)?.forEach(e=>e(t)),e.listeners.get(`*`)?.forEach(e=>e(t))}function or(e){return e.snapshot.nodes[e.snapshot.rootId]?.visibleSubtreeCount??0}function sr(e,t){if(e.snapshot.options.flattenEmptyDirectories!==!0)return null;let n=e.snapshot.nodes[t];if(n==null||!V(n)||H(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 a=e.snapshot.nodes[i];return a==null||!V(a)?null:i}function cr(e,t){let n=t;for(;;){let t=sr(e,n);if(t==null)return n;n=t}}function lr(e,t){let n=[t],r=t;for(;;){let t=sr(e,r);if(t==null)return n;n.push(t),r=t}}function ur(e,t){let n=t==null?e.snapshot.rootId:yr(e,t);return n==null?[]:xr(e,n)}function dr(e,t){let n=$t(t),r=n.isDirectory?n.segments:n.segments.slice(0,-1),i=Ir(e,Fr(e,r)),{createdNodeIds:a,directoryId:o}=Sr(e,r),s=new Set(a),c=o;if(n.isDirectory){let n=K(e,o);if(H(n,1))throw Error(`Path already exists: "${t}"`);Nt(n,1),e.pathCacheByNodeId.set(o,{path:t,version:e.pathCacheVersion}),s.add(o)}else c=wr(e,o,n.basename),s.add(c);gr(e,o);let l=Ir(e,o);return Rn({affectedAncestorIds:vr(e,c),affectedNodeIds:[...s],path:t,projectionChanged:Lr(i,l)})}function fr(e,t,n){let r=yr(e,t);if(r==null)throw Error(`Path does not exist: "${t}"`);let i=K(e,r);if(H(i,2))throw Error(`The root node cannot be removed`);if(V(i)&&G(e,r).childIds.length>0&&n.recursive!==!0)throw Error(`Cannot remove a non-empty directory without recursive: "${t}"`);let a=i.parentId,o=Ir(e,a),s=Nr(e,r);Dr(e,a,r,i.nameId),Pr(e,a),gr(e,a);let c=Ir(e,a);return zn({affectedAncestorIds:vr(e,a),affectedNodeIds:s,path:t,projectionChanged:Lr(o,c),recursive:n.recursive===!0})}function pr(e,t,n,r){let i=yr(e,t);if(i==null)throw Error(`Source path does not exist: "${t}"`);let a=K(e,i);if(H(a,2))throw Error(`The root node cannot be moved`);let o=r.collision??`error`,s=jr(e,i,n),c=Ir(e,a.parentId),l=Ir(e,s.parentId),u=an(e.snapshot.segmentTable,a.nameId),d=rn(e.snapshot.segmentTable,s.basename);if(s.parentId===a.parentId&&u===s.basename)return null;if(V(a)&&Vr(e,i,s.parentId))throw Error(`Cannot move a directory into one of its descendants`);let f=ht(e.snapshot.nodes,G(e,s.parentId)).get(d),p=s.existingNodeId??f??null;if(p!=null&&p!==i&&Mr(e,p,o,jt(a))===`skip`)return null;let m=a.parentId;Dr(e,m,i,a.nameId),a.parentId=s.parentId,a.nameId=d,e.pathCacheByNodeId.delete(i),Br(e,i),Er(e,s.parentId,i),Pr(e,m),e.pathCacheVersion++,gr(e,m),s.parentId!==m&&gr(e,s.parentId);let h=Ir(e,m),g=Ir(e,s.parentId);return Bn({affectedAncestorIds:[...new Set([...vr(e,m),...vr(e,s.parentId)])],affectedNodeIds:[i],from:t,projectionChanged:Rr([c,l],[h,g]),to:W(e,i)})}function mr(e,t){let n=e.pathCacheByNodeId.get(t);return n!=null&&n.version===e.pathCacheVersion?n.path:null}function hr(e,t,n){return e.pathCacheByNodeId.set(t,{path:n,version:e.pathCacheVersion}),n}function W(e,t){let n=K(e,t),r=mr(e,t);if(r!=null)return r;if(H(n,2))return hr(e,t,``);let i=W(e,n.parentId),a=an(e.snapshot.segmentTable,n.nameId),o=i.length===0?a:`${i}${a}`;return hr(e,t,V(n)?`${o}/`:o)}function gr(e,t){let n=e.instrumentation;if(n==null){Ur(e,t);return}U(n,`store.recomputeCountsUpwardFrom`,()=>Ur(e,t))}function _r(e,t){let n=[[t,0]],{nodes:r,directories:i}=e.snapshot;for(;n.length>0;){let t=n[n.length-1],a=t[0],o=r[a];if(o==null||!V(o)){Hr(e,a,o,!0),n.pop();continue}let s=i.get(a);if(s==null||t[1]>=s.childIds.length){Hr(e,a,o,!0),n.pop();continue}let c=s.childIds[t[1]++];n.push([c,0])}}function vr(e,t){let n=[],r=t;for(;r!=null;){let t=K(e,r);if(n.push(r),r===e.snapshot.rootId)break;r=t.parentId}return n}function yr(e,t){if(t.length===0)return e.snapshot.rootId;let n=en(t);return br(e,n.segments,n.requiresDirectory)}function br(e,t,n){let r=e.snapshot.rootId;for(let n of t){let t=e.snapshot.segmentTable.idByValue.get(n);if(t===void 0)return null;let i=G(e,r),a=ht(e.snapshot.nodes,i).get(t);if(a===void 0)return null;r=a}let i=K(e,r);return n&&!V(i)?null:r}function G(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 K(e,t){let n=e.snapshot.nodes[t];if(n===void 0||H(n,4))throw Error(`Unknown node ID: ${String(t)}`);return n}function xr(e,t){let n=e.snapshot.nodes[t];if(n===void 0||H(n,4))return[];if(!V(n))return[W(e,t)];if(G(e,t).childIds.length===0)return H(n,1)&&!H(n,2)?[W(e,t)]:[];let r=[],i=[{childIndex:0,nodeId:t}];for(;i.length>0;){let t=i[i.length-1];if(t==null)break;let n=e.snapshot.nodes[t.nodeId];if(n===void 0||H(n,4)){i.pop();continue}if(!V(n)){r.push(W(e,t.nodeId)),i.pop();continue}let a=G(e,t.nodeId);if(a.childIds.length===0){H(n,1)&&!H(n,2)&&r.push(W(e,t.nodeId)),i.pop();continue}let o=a.childIds[t.childIndex];if(o==null){i.pop();continue}t.childIndex++,i.push({childIndex:0,nodeId:o})}return r}function Sr(e,t){let n=[],r=e.snapshot.rootId;for(let i of t){let t=rn(e.snapshot.segmentTable,i),a=G(e,r),o=ht(e.snapshot.nodes,a).get(t);if(o!==void 0){if(!V(K(e,o)))throw Error(`Cannot create a directory that collides with an existing file: "${i}"`);r=o;continue}r=Cr(e,r,t),n.push(r)}return{createdNodeIds:n,directoryId:r}}function Cr(e,t,n){let r=K(e,t),i=e.snapshot.nodes.length;return e.snapshot.nodes.push({depthAndFlags:kt(At(r)+1,0,1),nameId:n,parentId:t,subtreeNodeCount:1,visibleSubtreeCount:1}),e.snapshot.directories.set(i,pt()),Er(e,t,i),e.collapseNewDirectoriesByDefault&&(e.collapsedDirectoryIds.add(i),e.hasCollapsedDirectoryOverrides=!0),e.activeNodeCount++,i}function wr(e,t,n){let r=rn(e.snapshot.segmentTable,n),i=G(e,t);if(ht(e.snapshot.nodes,i).has(r))throw Error(`Path already exists: "${Gr(e,t,n)}"`);let a=K(e,t),o=e.snapshot.nodes.length;return e.snapshot.nodes.push({depthAndFlags:kt(At(a)+1,0),nameId:r,parentId:t,subtreeNodeCount:1,visibleSubtreeCount:1}),Er(e,t,o),e.activeNodeCount++,o}function Tr(e,t,n){let r=0,i=t.childIds.length;for(;r<i;){let a=r+i>>>1,o=t.childIds[a];if(o==null){i=a;continue}Or(e,n,o)<0?i=a:r=a+1}return r}function Er(e,t,n){let r=G(e,t),i=K(e,n);ht(e.snapshot.nodes,r).set(i.nameId,n),bt(r,n,i.subtreeNodeCount,i.visibleSubtreeCount);let a=Tr(e,r,n);r.childIds.splice(a,0,n),vt(r,a),Ct(e.snapshot.nodes,r)}function Dr(e,t,n,r){let i=G(e,t),a=gt(i),o=a.get(n)??-1;ht(e.snapshot.nodes,i).delete(r),a.delete(n);let s=e.snapshot.nodes[n];s!=null&&bt(i,n,-s.subtreeNodeCount,-s.visibleSubtreeCount),o>=0&&(i.childIds.splice(o,1),vt(i,o),Ct(e.snapshot.nodes,i))}function Or(e,t,n){let r=e.snapshot.options.sort;return r==="default"?kr(e,t,n):r(Ar(e,t),Ar(e,n))}function kr(e,t,n){let r=K(e,t),i=K(e,n),a=V(r);if(a!==V(i))return a?-1:1;let o=Ut(Xt(e.snapshot.segmentTable,r.nameId),Xt(e.snapshot.segmentTable,i.nameId));if(o!==0)return o;let s=an(e.snapshot.segmentTable,r.nameId),c=an(e.snapshot.segmentTable,i.nameId);return s===c?t<n?-1:1:s<c?-1:1}function Ar(e,t){let n=K(e,t),r=W(e,t),i=V(n),a=i?r.slice(0,-1):r;return{basename:an(e.snapshot.segmentTable,n.nameId),depth:At(n),isDirectory:i,path:r,segments:a.length===0?[]:a.split(`/`)}}function jr(e,t,n){let r=K(e,t),i=yr(e,n);if(i!=null){let t=K(e,i);if(V(t))return{basename:an(e.snapshot.segmentTable,r.nameId),existingNodeId:null,parentId:i};let a=en(n).segments;return{basename:a[a.length-1]??``,existingNodeId:i,parentId:t.parentId}}let a=en(n),o=a.segments[a.segments.length-1]??``,s=a.segments.slice(0,-1),c=s.length===0?e.snapshot.rootId:br(e,s,!0);if(c==null)throw Error(`Destination parent does not exist: "${n}"`);return{basename:o,existingNodeId:null,parentId:c}}function Mr(e,t,n,r){if(n===`skip`)return`skip`;if(n===`error`)throw Error(`Destination already exists: "${W(e,t)}"`);let i=K(e,t);if(jt(i)!==r)throw Error(`replace collision requires the same source and destination kinds`);if(V(i)&&G(e,t).childIds.length>0)throw Error(`replace collision does not support non-empty directories`);let a=i.parentId,o=i.nameId;return Nr(e,t),Dr(e,a,t,o),Pr(e,a),gr(e,a),`handled`}function Nr(e,t){let n=[],r=[{nodeId:t,visitedChildren:!1}];for(;r.length>0;){let t=r.pop();if(t==null)break;let i=K(e,t.nodeId);if(t.visitedChildren||!V(i)){V(i)&&e.snapshot.directories.delete(t.nodeId),Nt(i,4),e.pathCacheByNodeId.delete(t.nodeId),e.collapsedDirectoryIds.delete(t.nodeId)&&(e.hasCollapsedDirectoryOverrides=e.collapsedDirectoryIds.size>0),e.expandedDirectoryIds.delete(t.nodeId),In(e,t.nodeId),e.activeNodeCount--,n.push(t.nodeId);continue}r.push({nodeId:t.nodeId,visitedChildren:!0});let a=G(e,t.nodeId);for(let e=a.childIds.length-1;e>=0;e--){let t=a.childIds[e];t!=null&&r.push({nodeId:t,visitedChildren:!1})}}return n}function Pr(e,t){let n=t;for(;n!=null;){let t=K(e,n);if(!V(t)||H(t,2)||G(e,n).childIds.length>0)return;Nt(t,1),n=t.parentId===n?null:t.parentId}}function Fr(e,t){let n=e.snapshot.rootId;for(let r of t){let t=e.snapshot.segmentTable.idByValue.get(r);if(t==null)break;let i=ht(e.snapshot.nodes,G(e,n)).get(t);if(i==null||!V(K(e,i)))break;n=i}return n}function Ir(e,t){let n=zr(e,t);if(n==null)return null;let r=cr(e,n),i=K(e,r),a=n===r?null:lr(e,n).map(t=>W(e,t));return JSON.stringify({flattenedSegmentPaths:a,hasChildren:G(e,r).childIds.length>0,path:W(e,r),terminalKind:jt(i)})}function Lr(e,t){return Rr([e],[t])}function Rr(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 zr(e,t){let n=t;for(;n!=null;){let t=K(e,n);if(!V(t)||H(t,2))return null;if(!Dn(e,n,t))return n;n=t.parentId}return null}function Br(e,t){let n=K(e,t);if(Pt(n,(t===e.snapshot.rootId?-1:At(K(e,n.parentId)))+1),!V(n))return;let r=G(e,t);for(let t of r.childIds)Br(e,t)}function Vr(e,t,n){let r=n;for(;r!=null;){if(r===t)return!0;let n=K(e,r);if(r===e.snapshot.rootId)return!1;r=n.parentId}return!1}function Hr(e,t,n=K(e,t),r=!1){let i=e.instrumentation;if(i==null){Wr(e,t,n,r);return}U(i,`store.recomputeNodeCounts`,()=>Wr(e,t,n,r))}function Ur(e,t){let n=t;for(;n!=null;){let t=K(e,n),r=t.subtreeNodeCount,i=t.visibleSubtreeCount;if(Hr(e,n,t),n===e.snapshot.rootId)return;let a=t.subtreeNodeCount-r,o=t.visibleSubtreeCount-i,s=t.parentId;(a!==0||o!==0)&&bt(G(e,s),n,a,o),n=s}}function Wr(e,t,n,r){if(!V(n)){n.subtreeNodeCount=1,n.visibleSubtreeCount=1;return}let i=G(e,t);if(r){let t=e.instrumentation;t==null?yt(e.snapshot.nodes,i):U(t,`store.recomputeNodeCounts.rebuildChildAggregates`,()=>yt(e.snapshot.nodes,i))}let a=1+i.totalChildSubtreeNodeCount,o=i.totalChildVisibleSubtreeCount;if(n.subtreeNodeCount=a,H(n,2)){n.visibleSubtreeCount=o;return}n.visibleSubtreeCount=sr(e,t)==null?Dn(e,t,n)?1+o:1:o}function Gr(e,t,n){let r=W(e,t);return r.length===0?n:`${r}${n}`}function Kr(e){return e!=null&&!H(e,4)}function qr(e,t){let n=e.snapshot.nodes[t];return!Kr(n)||!V(n)||H(n,2)?null:n}function Jr(e){let t=0;for(let[n,r]of e.pathCacheByNodeId)r.version===e.pathCacheVersion&&Kr(e.snapshot.nodes[n])&&(t+=1);return t}function Yr(e){return Math.max(0,e.valueById.length-1)}function Xr(e){return{activeNodeCount:e.activeNodeCount,cachedPathEntryCount:Jr(e),loadInfoEntryCount:e.directoryLoadInfoById.size,segmentCount:Yr(e.snapshot.segmentTable),totalNodeSlotCount:Math.max(0,e.snapshot.nodes.length-1)}}function Zr(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 Qr(e){let t=[],n=[];for(let n of e.collapsedDirectoryIds)qr(e,n)!=null&&t.push(W(e,n));for(let t of e.expandedDirectoryIds)qr(e,t)!=null&&n.push(W(e,t));return{collapsedPaths:t,expandedPaths:n}}function $r(e){let t=[];for(let[n,r]of e.directoryLoadInfoById)qr(e,n)==null||An(e,n)===`loaded`||t.push({info:{activeAttemptId:null,errorMessage:r.errorMessage,nextAttemptId:r.nextAttemptId,state:r.state},path:W(e,n)});return t}function ei(e,t){e.collapsedDirectoryIds.clear(),e.hasCollapsedDirectoryOverrides=!1,e.expandedDirectoryIds.clear();for(let n of t.expandedPaths){let t=yr(e,n);t!=null&&On(e,t,!0,K(e,t))}for(let n of t.collapsedPaths){let t=yr(e,n);t!=null&&On(e,t,!1,K(e,t))}}function ti(e,t){e.directoryLoadInfoById.clear();for(let n of t){let t=yr(e,n.path);t!=null&&qr(e,t)!=null&&e.directoryLoadInfoById.set(t,{activeAttemptId:null,errorMessage:n.info.errorMessage,nextAttemptId:n.info.nextAttemptId,state:n.info.state})}}function ni(e){e.pathCacheVersion+=1,e.pathCacheByNodeId.clear(),e.pathCacheByNodeId.set(e.snapshot.rootId,{path:``,version:e.pathCacheVersion})}function ri(e){let t=e.snapshot.segmentTable,n=nn();for(let r of e.snapshot.nodes)if(Kr(r)){if(H(r,2)){r.nameId=0;continue}r.nameId=rn(n,an(t,r.nameId))}e.snapshot.segmentTable=n}function ii(e){for(let[t,n]of e.snapshot.directories){let r=e.snapshot.nodes[t];if(!Kr(r)||!V(r)){e.snapshot.directories.delete(t);continue}let i=n.childIds.filter(n=>{let r=e.snapshot.nodes[n];return Kr(r)&&r.parentId===t});n.childIds=i,n.childIdByNameId=new Map(i.map(t=>[K(e,t).nameId,t])),n.childPositionById=new Map(i.map((e,t)=>[e,t])),yt(e.snapshot.nodes,n)}}function ai(e){let t=e.snapshot.nodes.length-1;for(;t>e.snapshot.rootId;){let n=e.snapshot.nodes[t];if(Kr(n))break;--t}e.snapshot.nodes.length=t+1}function oi(e){let t=Qr(e),n=$r(e);U(e.instrumentation,`store.cleanup.stable.clearPathCaches`,()=>ni(e)),U(e.instrumentation,`store.cleanup.stable.rebuildSegmentTable`,()=>ri(e)),U(e.instrumentation,`store.cleanup.stable.rebuildDirectoryIndexes`,()=>ii(e)),U(e.instrumentation,`store.cleanup.stable.trimTrailingRemovedNodeSlots`,()=>ai(e)),U(e.instrumentation,`store.cleanup.stable.restoreExpansionOverrides`,()=>ei(e,t)),U(e.instrumentation,`store.cleanup.stable.restoreDirectoryLoadInfos`,()=>ti(e,n)),U(e.instrumentation,`store.cleanup.stable.recomputeCounts`,()=>_r(e,e.snapshot.rootId))}function si(e){let t=Qr(e),n=$r(e),r=U(e.instrumentation,`store.cleanup.aggressive.listPaths`,()=>ur(e)),i=It({...e.snapshot.options},e.instrumentation),a=U(e.instrumentation,`store.cleanup.aggressive.rebuildSnapshot`,()=>{let e=new Sn(i);return e.appendPaths(r),e.finish()});e.snapshot=a,e.activeNodeCount=a.nodes.length-1,e.pathCacheByNodeId=new Map([[a.rootId,{path:``,version:0}]]),e.pathCacheVersion=0,U(e.instrumentation,`store.cleanup.aggressive.restoreExpansionOverrides`,()=>ei(e,t)),U(e.instrumentation,`store.cleanup.aggressive.restoreDirectoryLoadInfos`,()=>ti(e,n)),U(e.instrumentation,`store.cleanup.aggressive.recomputeCounts`,()=>_r(e,e.snapshot.rootId))}function ci(e){for(let t of e.directoryLoadInfoById.values())if(t.state===`loading`&&t.activeAttemptId!=null)return!0;return!1}function li(e,t){let n=Xr(e);t===`stable`?U(e.instrumentation,`store.cleanup.stable`,()=>oi(e)):U(e.instrumentation,`store.cleanup.aggressive`,()=>si(e));let r=Xr(e);return Zr(t,t===`stable`,n,r)}var ui=64;function di(e,t){let n=t+2;if(n<=e.length)return e;let r=e.length;for(;r<n;)r*=2;let i=new Int32Array(r);return i.fill(-1),i.set(e),i}function fi(e){return K(e,e.snapshot.rootId).visibleSubtreeCount}function pi(e,t,n,r){let i=K(e,t.terminalNodeId),a=Math.max(1,i.visibleSubtreeCount);return Math.min(r-1,n+a-1)}function mi(e,t,n,r){return{ancestorPaths:r,index:t.index,posInSet:t.posInSet,row:Ni(e,t.cursor),setSize:t.setSize,subtreeEndIndex:pi(e,t.cursor,t.index,n)}}function hi(e,t,n,r,i,a){let o=G(e,t),{childIndex:s,childVisibleIndex:c,localVisibleIndex:l}=xt(e.snapshot.nodes,o,n),u=o.childIds[s];if(u==null)throw Error(`Visible index ${String(n)} is out of range`);return gi(e,u,l,r+c,i+1,s,o.childIds.length,a)}function gi(e,t,n,r,i,a,o,s){if(!V(K(e,t))){if(n===0)return{ancestors:s,cursor:{headNodeId:t,terminalNodeId:t,visibleDepth:i},index:r,posInSet:a,setSize:o};throw Error(`Visible index ${String(n)} is out of range for file`)}let c=Di(e,t,i);if(n===0)return{ancestors:s,cursor:c,index:r,posInSet:a,setSize:o};let l=K(e,c.terminalNodeId);if(!V(l)||!Dn(e,c.terminalNodeId,l))throw Error(`Visible index ${String(n)} is out of range for collapsed directory`);return hi(e,c.terminalNodeId,n-1,r+1,c.visibleDepth,[...s,{cursor:c,index:r,posInSet:a,setSize:o}])}function _i(e,t){let n=fi(e);if(t<0||t>=n)return null;let r=hi(e,e.snapshot.rootId,t,0,-1,[]),i=r.ancestors.map(t=>W(e,t.cursor.terminalNodeId)),a=null;return{ancestorPaths:i,get ancestorRows(){if(a!=null)return a;let t=[],i=[];for(let a of r.ancestors){let r=mi(e,a,n,[...i]);t.push(r),i.push(r.row.path)}return a=t,a},index:r.index,posInSet:r.posInSet,row:Ni(e,r.cursor),setSize:r.setSize,subtreeEndIndex:pi(e,r.cursor,r.index,n)}}function vi(e,t,n){let r=e.instrumentation,i=fi(e);if(i<=0||n<t)return[];let a=Math.max(0,Math.min(t,i-1)),o=Math.max(a,Math.min(n,i-1));if(r==null){if(a===0)return Mi(e,o+1);let t=[],n=wi(e,a);for(let r=a;r<=o&&n!=null;r++){let r=Ni(e,n);t.push(r),n=ki(e,n)}return t}let s=[],c=0,l=0,u=U(r,`store.getVisibleSlice.selectFirstRow`,()=>wi(e,a));for(let t=a;t<=o&&u!=null;t++){let t=U(r,`store.getVisibleSlice.materializeRow`,()=>Ni(e,u));s.push(t),t.isFlattened&&(c++,l+=t.flattenedSegments?.length??0),u=U(r,`store.getVisibleSlice.advanceCursor`,()=>ki(e,u))}return Rt(r,`workload.visibleRowsRead`,s.length),Rt(r,`workload.flattenedRowsRead`,c),Rt(r,`workload.flattenedSegmentsRead`,l),s}function yi(e,t=fi(e)){let n=e.instrumentation;return n==null?ji(e,t):U(n,`store.getVisibleTreeProjection`,()=>ji(e,t))}function bi(e){return Ai(yi(e))}function xi(e,t){let n=yr(e,t);if(n==null||n===e.snapshot.rootId||V(K(e,n))&&cr(e,n)!==n)return null;let r=0,i=n,{nodes:a,rootId:o}=e.snapshot;for(;i!==o;){let t=K(e,i).parentId,n=G(e,t),s=gt(n).get(i);if(s==null)throw Error(`Child ${String(i)} was not found in its parent index`);if(r+=St(a,n,s),t!==o){let n=K(e,t),a=sr(e,t);if(!Dn(e,t,n)&&a!==i)return null;cr(e,t)===t&&(r+=1)}i=t}return r}function Si(e,t){let n=yr(e,t);if(n==null)throw Error(`Path does not exist: "${t}"`);let r=K(e,n);if(!V(r))throw Error(`Path is not a directory: "${t}"`);return Dn(e,n,r)?null:(On(e,n,!0,r),gr(e,n),Vn({affectedAncestorIds:vr(e,n),affectedNodeIds:[n],path:t,projectionChanged:!0}))}function Ci(e,t){let n=yr(e,t);if(n==null)throw Error(`Path does not exist: "${t}"`);let r=K(e,n);if(!V(r))throw Error(`Path is not a directory: "${t}"`);return Dn(e,n,r)?(On(e,n,!1,r),gr(e,n),Hn({affectedAncestorIds:vr(e,n),affectedNodeIds:[n],path:t,projectionChanged:!0})):null}function wi(e,t){return t<0||t>=fi(e)?null:Ti(e,e.snapshot.rootId,t,-1)}function Ti(e,t,n,r){let i=G(e,t),a=e.instrumentation,{childIndex:o,localVisibleIndex:s}=a==null?xt(e.snapshot.nodes,i,n):U(a,`store.getVisibleSlice.selectChildIndex`,()=>xt(e.snapshot.nodes,i,n)),c=i.childIds[o];if(c!=null)return Ei(e,c,s,r+1);throw Error(`Visible index ${String(n)} is out of range`)}function Ei(e,t,n,r){if(!V(K(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=Di(e,t,r);if(n===0)return i;let a=K(e,i.terminalNodeId);if(!V(a)||!Dn(e,i.terminalNodeId,a))throw Error(`Visible index ${String(n)} is out of range for collapsed directory`);return Ti(e,i.terminalNodeId,n-1,i.visibleDepth)}function Di(e,t,n){return V(K(e,t))?e.instrumentation==null?{headNodeId:t,terminalNodeId:cr(e,t),visibleDepth:n}:{headNodeId:t,terminalNodeId:U(e.instrumentation,`store.getVisibleSlice.flatten.resolveTerminalDirectory`,()=>cr(e,t)),visibleDepth:n}:{headNodeId:t,terminalNodeId:t,visibleDepth:n}}function Oi(e,t){let n=K(e,t);if(!V(n))return!0;let r=n.parentId;return r===e.snapshot.rootId?!0:sr(e,r)!==t}function ki(e,t){let n=K(e,t.terminalNodeId);if(V(n)){let r=G(e,t.terminalNodeId);if(Dn(e,t.terminalNodeId,n)&&r.childIds.length>0){let n=r.childIds[0];return n==null?null:Ei(e,n,0,t.visibleDepth+1)}}let r=t.terminalNodeId,i=t.visibleDepth;for(;;){let t=K(e,r);if(r===e.snapshot.rootId)return null;let n=t.parentId,a=G(e,n),o=gt(a).get(r)??-1;if(o<0)throw Error(`Child ${String(r)} was not found in its parent index`);let s=a.childIds[o+1]??null;if(s!=null)return Ei(e,s,0,i);Oi(e,r)&&i--,r=n}}function Ai(e){let t=e.paths.length,n=Array(t);for(let r=0;r<t;r+=1){let t=e.getParentIndex(r);n[r]={index:r,parentPath:t>=0?e.paths[t]??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 ji(e,t){let n=Array(t),r=new Int32Array(t),i=new Int32Array(t),a=new Int32Array(t),o=new Int32Array(ui);o.fill(-1);let s=0,{nodes:c,directories:l,segmentTable:u}=e.snapshot,d=[[l.get(e.snapshot.rootId),0,-1,``]],f=e.snapshot.options.flattenEmptyDirectories,p=e.pathCacheByNodeId,m=e.pathCacheVersion,h=u.valueById;for(;d.length>0&&s<t;){let t=d[d.length-1],u=t[0];if(t[1]>=u.childIds.length){d.pop();continue}let g=t[1],_=u.childIds[t[1]++],v=c[_],y=t[2]+1,b=t[3];o=di(o,y);let x,S=_;if(V(v))S=f?cr(e,_):_,x=S===_?`${b}${h[v.nameId]}/`:W(e,S);else{let e=p.get(_);x=e!=null&&e.version===m?e.path:`${b}${h[v.nameId]}`}r[s]=o[y],n[s]=x,i[s]=g,a[s]=u.childIds.length,o[y+1]=s,s+=1;let C=c[S];C!=null&&V(C)&&Dn(e,S,C)&&d.push([l.get(S),0,y,x])}s<t&&(n.length=s);let g=r.subarray(0,s),_=i.subarray(0,s),v=a.subarray(0,s),y=null;return{getParentIndex(e){return e<0||e>=s?-1:g[e]??-1},paths:n,posInSetByIndex:_,setSizeByIndex:v,get visibleIndexByPath(){if(y==null){y=new Map;for(let e=0;e<s;e+=1)y.set(n[e]??``,e)}return y}}}function Mi(e,t){let n=Array(t),r=0,{nodes:i,directories:a,segmentTable:o}=e.snapshot,s=[[a.get(e.snapshot.rootId),0,-1]],c=o.valueById,l=e.snapshot.options.flattenEmptyDirectories,u=e.pathCacheByNodeId,d=e.pathCacheVersion;for(;s.length>0&&r<t;){let t=s[s.length-1],o=t[0];if(t[1]>=o.childIds.length){s.pop();continue}let f=o.childIds[t[1]++],p=i[f],m=t[2]+1;if(!V(p)){let t=u.get(f);n[r++]={depth:m,flattenedSegments:void 0,hasChildren:!1,id:f,isExpanded:!1,isFlattened:!1,isLoading:!1,kind:`file`,loadState:void 0,name:c[p.nameId],path:t!=null&&t.version===d?t.path:W(e,f)};continue}let h=l?cr(e,f):f,g={headNodeId:f,terminalNodeId:h,visibleDepth:m};n[r++]=Ni(e,g);let _=i[h];_!=null&&V(_)&&Dn(e,h,_)&&s.push([a.get(h),0,m])}return r<t&&(n.length=r),n}function Ni(e,t){let n=K(e,t.terminalNodeId),r=V(n)?Pi(e,t):null,i=W(e,t.terminalNodeId),a=an(e.snapshot.segmentTable,n.nameId),o=V(n)&&G(e,t.terminalNodeId).childIds.length>0,s=t.headNodeId!==t.terminalNodeId,c=e.instrumentation,l=s?c==null?lr(e,t.headNodeId).map(n=>{let r=K(e,n);return{isTerminal:n===t.terminalNodeId,name:an(e.snapshot.segmentTable,r.nameId),nodeId:n,path:W(e,n)}}):U(c,`store.getVisibleSlice.flatten.collectSegments`,()=>lr(e,t.headNodeId).map(n=>{let r=K(e,n);return{isTerminal:n===t.terminalNodeId,name:an(e.snapshot.segmentTable,r.nameId),nodeId:n,path:W(e,n)}})):void 0;return{depth:t.visibleDepth,flattenedSegments:l,hasChildren:o,id:t.terminalNodeId,isExpanded:V(n)&&Dn(e,t.terminalNodeId,n),isFlattened:s,isLoading:r===`loading`,kind:V(n)?`directory`:`file`,loadState:r==null||r===`loaded`?void 0:r,name:a,path:i}}function Pi(e,t){if(t.headNodeId===t.terminalNodeId)return An(e,t.terminalNodeId);let n=lr(e,t.headNodeId),r=!1,i=!1;for(let t of n){let n=An(e,t);if(n===`loading`)return`loading`;if(n===`error`){i=!0;continue}n===`unloaded`&&(r=!0)}return i?`error`:r?`unloaded`:`loaded`}function Fi(e){let{directories:t,nodes:n,options:r,rootId:i,presortedDirectoryNodeIds:a}=e.snapshot,o=r.flattenEmptyDirectories===!0,s=e=>{let r=n[e];if(r==null||!V(r))return;let i=t.get(e);if(i==null)throw Error(`Unknown directory child index for node ${String(e)}`);let a=i.childIds,s=a.length,c=0,l=0;for(let e=0;e<s;e++){let t=a[e];if(t==null)continue;let r=n[t];c+=r.subtreeNodeCount,l+=r.visibleSubtreeCount}i.totalChildSubtreeNodeCount=c,i.totalChildVisibleSubtreeCount=l,s>=128&&Ct(n,i),r.subtreeNodeCount=1+c;let u;if(o&&s===1){let e=n[a[0]];u=e!=null&&V(e)?l:1+l}else u=1+l;r.visibleSubtreeCount=u};if(a!=null)for(let e=a.length-1;e>=0;e--)s(a[e]);else for(let e=n.length-1;e>=1;e--)s(e);let c=n[i],l=t.get(i);if(c==null||l==null)return;let u=l.childIds,d=0,f=0;for(let e=0;e<u.length;e++){let t=u[e];if(t==null)continue;let r=n[t];d+=r.subtreeNodeCount,f+=r.visibleSubtreeCount}l.totalChildSubtreeNodeCount=d,l.totalChildVisibleSubtreeCount=f,Ct(n,l),c.subtreeNodeCount=1+d,c.visibleSubtreeCount=f}function Ii(e){return e.initialExpansion===`open`&&(e.initialExpandedPaths==null||e.initialExpandedPaths.length===0)}var Li=class e{#e;constructor(e={}){let t=Lt(e),n=U(t,`store.builder.create`,()=>new Sn(e));if(e.preparedInput!=null){let t=yn(e.preparedInput);t==null?n.appendPreparedPaths(vn(e.preparedInput),!1):n.appendPresortedPaths(t,bn(e.preparedInput))}else{let r=e.paths??[];e.presorted===!0?n.appendPaths(r):n.appendPreparedPaths(U(t,`store.preparePathEntries`,()=>xn(r,e)))}let r=U(t,`store.builder.finish`,()=>n.finish({skipSubtreeCountPass:!0})),i=U(t,`store.state.detectAllDirectoriesExpanded`,()=>(e.initialExpansion??`closed`)===`closed`&&n.didMatchAllInitialExpandedPaths());this.#e=U(t,`store.state.create`,()=>Cn(r,i?`open`:e.initialExpansion??`closed`,t)),i&&(this.#e.collapseNewDirectoriesByDefault=!0);let a=i?this.#e.snapshot.directories.size-1:U(t,`store.state.initializeExpandedPaths`,()=>this.initializeExpandedPaths(e.initialExpandedPaths));i||Ii(e)||(e.initialExpansion??`closed`)===`closed`&&a===this.#e.snapshot.directories.size-1||(e.initialExpandedPaths?.length??0)>0&&U(t,`store.state.checkAllDirectoriesExpanded`,()=>this.hasAllDirectoriesExpanded())?U(t,`store.state.initializeOpenVisibleCounts`,()=>Fi(this.#e)):U(t,`store.state.recomputeCounts`,()=>_r(this.#e,this.#e.snapshot.rootId))}static preparePaths(e,t={}){return hn(e,t)}static prepareInput(e,t={}){return gn(e,t)}static preparePresortedInput(e){return _n(e)}list(e){return U(this.#e.instrumentation,`store.list`,()=>ur(this.#e,e))}add(e){U(this.#e.instrumentation,`store.add`,()=>{let t=fi(this.#e);Zn(this.#e,Yn(this.#e,t,dr(this.#e,e)))})}remove(e,t={}){U(this.#e.instrumentation,`store.remove`,()=>{let n=fi(this.#e);Zn(this.#e,Yn(this.#e,n,fr(this.#e,e,t)))})}move(e,t,n={}){U(this.#e.instrumentation,`store.move`,()=>{let r=fi(this.#e),i=pr(this.#e,e,t,n);i!=null&&Zn(this.#e,Yn(this.#e,r,i))})}batch(e){Xn(this.#e,()=>{if(typeof e==`function`){e(this);return}for(let t of e)switch(t.type){case`add`:this.add(t.path);break;case`remove`:this.remove(t.path,{recursive:t.recursive});break;case`move`:this.move(t.from,t.to,{collision:t.collision});break}})}getVisibleCount(){return U(this.#e.instrumentation,`store.getVisibleCount`,()=>fi(this.#e))}getVisibleSlice(e,t){return U(this.#e.instrumentation,`store.getVisibleSlice`,()=>vi(this.#e,e,t))}getVisibleRowContext(e){return U(this.#e.instrumentation,`store.getVisibleRowContext`,()=>_i(this.#e,e))}getVisibleTreeProjection(){return bi(this.#e)}getVisibleTreeProjectionData(e){return yi(this.#e,e)}getVisibleIndex(e){return U(this.#e.instrumentation,`store.getVisibleIndex`,()=>xi(this.#e,e))}getPathInfo(e){return U(this.#e.instrumentation,`store.getPathInfo`,()=>{let t=yr(this.#e,e);if(t==null)return null;let n=K(this.#e,t);return{depth:At(n),kind:V(n)?`directory`:`file`,path:W(this.#e,t)}})}isExpanded(e){return U(this.#e.instrumentation,`store.isExpanded`,()=>{let t=this.requireDirectoryNodeId(e),n=K(this.#e,t);return Dn(this.#e,t,n)})}expand(e){U(this.#e.instrumentation,`store.expand`,()=>{let t=fi(this.#e),n=Si(this.#e,e);n!=null&&Zn(this.#e,Yn(this.#e,t,n))})}collapse(e){U(this.#e.instrumentation,`store.collapse`,()=>{let t=fi(this.#e),n=Ci(this.#e,e);n!=null&&Zn(this.#e,Yn(this.#e,t,n))})}on(e,t){return Ln(this.#e,e,t)}getDirectoryLoadState(e){let t=this.requireDirectoryNodeId(e);return An(this.#e,t)}markDirectoryUnloaded(e){U(this.#e.instrumentation,`store.markDirectoryUnloaded`,()=>{let t=this.requireDirectoryNodeId(e);if(G(this.#e,t).childIds.length>0)throw Error(`Cannot mark a directory with known children as unloaded: "${e}"`);let n=fi(this.#e);Mn(this.#e,t),Zn(this.#e,Yn(this.#e,n,Un({affectedAncestorIds:vr(this.#e,t),affectedNodeIds:[t],path:e,projectionChanged:this.isDirectoryProjectionVisible(t)})))})}beginChildLoad(e){return U(this.#e.instrumentation,`store.beginChildLoad`,()=>{let t=this.requireDirectoryNodeId(e),n=fi(this.#e),r=jn(this.#e,t);return Zn(this.#e,Yn(this.#e,n,Wn({affectedAncestorIds:vr(this.#e,t),affectedNodeIds:[t],attemptId:r.attemptId,path:e,projectionChanged:this.isDirectoryProjectionVisible(t),reused:r.reused}))),r})}applyChildPatch(e,t){return U(this.#e.instrumentation,`store.applyChildPatch`,()=>{let n=this.resolveActiveDirectoryNodeId(e.nodeId);if(n==null||An(this.#e,n)!==`loading`||!Pn(this.#e,n,e.attemptId))return!1;let r=W(this.#e,n);this.validateChildPatch(r,t);let i=fi(this.#e),a=[];for(let e of t.operations){Ri(r,e);let t=fi(this.#e);switch(e.type){case`add`:a.push(Yn(this.#e,t,dr(this.#e,e.path)));break;case`remove`:a.push(Yn(this.#e,t,fr(this.#e,e.path,{recursive:e.recursive})));break;case`move`:{let n=pr(this.#e,e.from,e.to,{collision:e.collision});n!=null&&a.push(Yn(this.#e,t,n));break}}}let o=a.some(e=>e.projectionChanged)||this.isDirectoryProjectionVisible(n);return Zn(this.#e,Yn(this.#e,i,Gn({affectedAncestorIds:vr(this.#e,n),affectedNodeIds:[n],attemptId:e.attemptId,childEvents:a,path:W(this.#e,n),projectionChanged:o}))),!0})}completeChildLoad(e){return U(this.#e.instrumentation,`store.completeChildLoad`,()=>{let t=this.resolveActiveDirectoryNodeId(e.nodeId);if(t==null)return!1;let n=fi(this.#e),r=Nn(this.#e,t,e.attemptId);return Zn(this.#e,Yn(this.#e,n,Kn({affectedAncestorIds:vr(this.#e,t),affectedNodeIds:[t],attemptId:e.attemptId,path:W(this.#e,t),projectionChanged:this.isDirectoryProjectionVisible(t),stale:!r}))),r})}failChildLoad(e,t){return U(this.#e.instrumentation,`store.failChildLoad`,()=>{let n=this.resolveActiveDirectoryNodeId(e.nodeId);if(n==null)return!1;let r=fi(this.#e),i=Fn(this.#e,n,e.attemptId,t);return Zn(this.#e,Yn(this.#e,r,qn({affectedAncestorIds:vr(this.#e,n),affectedNodeIds:[n],attemptId:e.attemptId,errorMessage:t,path:W(this.#e,n),projectionChanged:this.isDirectoryProjectionVisible(n),stale:!i}))),i})}cleanup(e={}){return U(this.#e.instrumentation,`store.cleanup`,()=>{if(this.#e.transactionStack.length>0)throw Error(`Cleanup cannot run during an open batch or transaction.`);if(ci(this.#e))throw Error(`Cleanup cannot run while directory loads are active.`);let t=fi(this.#e),n=li(this.#e,e.mode??`stable`);return Zn(this.#e,Yn(this.#e,t,Jn({...n,affectedAncestorIds:[],affectedNodeIds:[],projectionChanged:n.idsPreserved===!1}))),n})}getNodeCount(){return this.#e.activeNodeCount}initializeExpandedPaths(e){if(e==null||e.length===0)return 0;let t=0,n=[],r=[],i=0,a=null,o=this.#e.snapshot.segmentTable,s=o.valueById,c=this.#e.snapshot.nodes,l=new Map;for(let u of e){a!=null&&u<a&&(a=null,i=0,n.length=0,r.length=0);let e=u.length>0&&u.charCodeAt(u.length-1)===47?u.length-1:u.length;if(e===0){a=u,i=e,n.length=0,r.length=0;continue}let d=0,f=0;if(a!=null){let t=Math.min(e,i),n=!0;for(let e=0;e<t;e+=1){let t=u.charCodeAt(e);if(t!==a.charCodeAt(e)){n=!1;break}t===47&&(d+=1,f=e+1)}n&&(t===i&&e>t&&u.charCodeAt(t)===47?(d+=1,f=t+1):t===e&&i>t&&a.charCodeAt(t)===47&&(d+=1,f=e+1)),d=Math.min(d,r.length)}let p=d===0?this.#e.snapshot.rootId:r[d-1]??this.#e.snapshot.rootId,m=d,h=!0,g=f;for(;g<=e;){let t=u.indexOf(`/`,g),i=t===-1||t>e?e:t,a=u.slice(g,i),f=G(this.#e,p).childIds,_=m===d?n[m]??0:0,v=_,y,b=l.get(a)??Vt(a);l.set(a,b);let x=(e,t)=>{for(v=e;v<t;v+=1){let e=f[v],t=c[e],n=s[t.nameId];if(n===a)return y=e,!0;let r=Ut(Xt(o,t.nameId),b);if(r>0||r===0&&n>a)return!1}return!1};if(!x(_,f.length)&&_>0&&x(0,_),y===void 0){h=!1;break}if(!V(K(this.#e,y))){h=!1;break}if(n[m]=v,r[m]=y,p=y,m+=1,i===e)break;g=i+1}if(a=u,i=e,n.length=m,r.length=m,!h){a=null,i=0,n.length=0,r.length=0;continue}for(let e=d;e<m;e+=1){let n=r[e];if(n==null)continue;let i=K(this.#e,n);Dn(this.#e,n,i)||(On(this.#e,n,!0,i),t+=1)}}return t}hasAllDirectoriesExpanded(){for(let e of this.#e.snapshot.directories.keys()){if(e===this.#e.snapshot.rootId)continue;let t=K(this.#e,e);if(!Dn(this.#e,e,t))return!1}return!0}requireDirectoryNodeId(e){let t=yr(this.#e,e);if(t==null)throw Error(`Path does not exist: "${e}"`);if(!V(K(this.#e,t)))throw Error(`Path is not a directory: "${e}"`);return t}resolveActiveDirectoryNodeId(e){try{if(!V(K(this.#e,e)))throw Error(`Node is not a directory: ${String(e)}`);return e}catch{return null}}isDirectoryProjectionVisible(e){let t=e;for(;t!==this.#e.snapshot.rootId;){let e=K(this.#e,t).parentId;if(e!==this.#e.snapshot.rootId){let n=K(this.#e,e),r=sr(this.#e,e);if(!Dn(this.#e,e,n)&&r!==t)return!1}t=e}return!0}validateChildPatch(t,n){new e({paths:this.list(t),presorted:!0,sort:this.#e.snapshot.options.sort}).batch(n.operations)}};function Ri(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 zi={compact:{itemHeight:24,factor:.8},default:{itemHeight:30,factor:1},relaxed:{itemHeight:36,factor:1.2}};function Bi(e,t){if(typeof e==`number`)return{itemHeight:t??zi.default.itemHeight,factor:e};let n=zi[e??`default`];return{itemHeight:t??n.itemHeight,factor:n.factor}}var Vi=zi.default.itemHeight,Hi=`@layer base, theme, unsafe;
2
2
 
3
3
  @layer base {
4
4
  :host {
@@ -1775,4 +1775,4 @@ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{n as t,r as n,t as r}f
1775
1775
  color: var(--diffs-selection-number-fg) !important;
1776
1776
  }
1777
1777
  `;function Mf(e){let t=(0,af.c)(5),n=oe(e.environmentId,e.resource),[r,i]=(0,X.useState)(null);if(n._tag===`Failure`||n._tag===`Success`&&r===n.url){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center px-6 text-center text-xs leading-relaxed text-destructive`,children:`Unable to load image.`}),t[0]=e):e=t[0],e}let a;return t[1]!==n._tag||t[2]!==n.url||t[3]!==e.alt?(a=n._tag===`Success`?(0,Z.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center overflow-auto p-4`,children:(0,Z.jsx)(`img`,{className:`max-h-full max-w-full object-contain`,src:n.url,alt:e.alt,onError:()=>i(n.url)})}):(0,Z.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center text-muted-foreground`,children:(0,Z.jsx)(Pe,{className:`size-5 animate-spin`})}),t[1]=n._tag,t[2]=n.url,t[3]=e.alt,t[4]=a):a=t[4],a}function Nf(e,t){let n=1;for(let t=0;t<e.length;t+=1){let r=e.charCodeAt(t);r===10?n+=1:r===13&&(n+=1,e.charCodeAt(t+1)===10&&(t+=1))}return Math.min(Math.max(1,t),n)}function Pf(e,t){let n=e.shadowRoot??e;for(let e of n.querySelectorAll(`[${Af}]`))e.removeAttribute(Af);t!==null&&(n.querySelector(`[data-line="${t}"]`)?.setAttribute(Af,``),n.querySelector(`[data-column-number="${t}"]`)?.setAttribute(Af,``))}function Ff(e,t,n){let r=(0,af.c)(7),[i]=(0,X.useState)(Rf),[a]=(0,X.useState)(Lf),[o]=(0,X.useState)(If),s;return r[0]!==i||r[1]!==a||r[2]!==o||r[3]!==e||r[4]!==t||r[5]!==n?(s=(r,s,c)=>{if(e===null)return;let l=()=>{let t=o.get(e);t!==void 0&&(cancelAnimationFrame(t),o.delete(e))};if(c===`unmount`){l();return}let u=t===null?null:Nf(s.file?.contents??``,t);if(Pf(r,u),!(s instanceof T))return;if(a.get(e)!==n&&(l(),a.set(e,n)),u===null){r.style.minHeight=``;return}let d=r.closest(`.file-preview-virtualizer`);!d||(r.style.minHeight=`${Math.ceil(Math.max(s.height,d.clientHeight))}px`,i.get(e)===n||o.has(e))||o.set(e,requestAnimationFrame(()=>{if(o.delete(e),a.get(e)!==n||!r.isConnected)return;let t=s.getLinePosition(u);if(!t)return;let c=d.scrollTop+r.getBoundingClientRect().top-d.getBoundingClientRect().top,l=Math.max(0,c+t.top-Math.max(0,(d.clientHeight-t.height)/2)),f=Math.max(0,d.scrollHeight-d.clientHeight);d.scrollTop=Math.min(l,f),i.set(e,n)}))},r[0]=i,r[1]=a,r[2]=o,r[3]=e,r[4]=t,r[5]=n,r[6]=s):s=r[6],s}function If(){return new Map}function Lf(){return new Map}function Rf(){return new Map}function zf(e){let t=(0,af.c)(19),{environmentId:n,cwd:r,relativePath:i,onPendingChange:a}=e,o=S(I.writeFile),s;t[0]!==a||t[1]!==i?(s=e=>a(i,e),t[0]=a,t[1]=i,t[2]=s):s=t[2];let c;t[3]!==r||t[4]!==n||t[5]!==i||t[6]!==o?(c=e=>o({environmentId:n,input:{cwd:r,relativePath:i,contents:e}}),t[3]=r,t[4]=n,t[5]=i,t[6]=o,t[7]=c):c=t[7];let l;t[8]!==r||t[9]!==n||t[10]!==i?(l=e=>{L(n,r,i,e)},t[8]=r,t[9]=n,t[10]=i,t[11]=l):l=t[11];let u;t[12]!==s||t[13]!==c||t[14]!==l?(u=new Df({debounceMs:kf,onPendingChange:s,persist:c,onConfirmed:l}),t[12]=s,t[13]=c,t[14]=l,t[15]=u):u=t[15];let d=u,f,p;return t[16]===d?(f=t[17],p=t[18]):(f=()=>()=>d.dispose(),p=[d],t[16]=d,t[17]=f,t[18]=p),(0,X.useEffect)(f,p),d}function Bf(e){let t=(0,af.c)(74),{environmentId:n,cwd:r,relativePath:i,composerDraftTarget:a,contents:o,resolvedTheme:s,revealRequestId:c,wordWrap:l,onPostRender:u,onPendingChange:d}=e,f=m(qf),p=m(Kf),h;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(h=[],t[0]=h):h=t[0];let[g,_]=(0,X.useState)(h),[v,b]=(0,X.useState)(null),x=v?.revealRequestId===c?v.range:null,S;t[1]===c?S=t[2]:(S=e=>{b({revealRequestId:c,range:e})},t[1]=c,t[2]=S);let C=S,w=(0,X.useRef)(null),T=(0,X.useRef)(null),E;t[3]!==r||t[4]!==n||t[5]!==d||t[6]!==i?(E={environmentId:n,cwd:r,relativePath:i,onPendingChange:d},t[3]=r,t[4]=n,t[5]=d,t[6]=i,t[7]=E):E=t[7];let D=zf(E),ee;t[8]!==f||t[9]!==a||t[10]!==r||t[11]!==n||t[12]!==i||t[13]!==D?(ee=new Xd({onChange:(e,t)=>{if(ve(n,r,i,e.contents),D.change(e.contents),t){let n=Xe(t);_(n);for(let t of n)for(let n of t.metadata.entries)n.kind===`comment`&&f(a,y({id:n.id,filePath:i,startLine:n.startLine,endLine:n.endLine,text:n.text,contents:e.contents}))}}}),t[8]=f,t[9]=a,t[10]=r,t[11]=n,t[12]=i,t[13]=D,t[14]=ee):ee=t[14];let O=ee,k,A;t[15]===O?(k=t[16],A=t[17]):(k=()=>()=>{O.cleanUp()},A=[O],t[15]=O,t[16]=k,t[17]=A),(0,X.useEffect)(k,A);let j;t[18]!==a||t[19]!==p||t[20]!==C?(j=e=>{C(null),p(a,e),_(t=>t.flatMap(t=>{let n=t.metadata.entries.filter(t=>t.id!==e);return n.length>0?[{...t,metadata:{entries:n}}]:[]}))},t[18]=a,t[19]=p,t[20]=C,t[21]=j):j=t[21];let M=j,N;t[22]!==f||t[23]!==a||t[24]!==o||t[25]!==g||t[26]!==i||t[27]!==C?(N=(e,t)=>{C(null);let n=g.flatMap(Gf).find(t=>t.id===e);n&&f(a,y({id:n.id,filePath:i,startLine:n.startLine,endLine:n.endLine,text:t,contents:o})),_(n=>n.map(n=>({...n,metadata:{entries:n.metadata.entries.map(n=>n.id===e?{...n,kind:`comment`,text:t}:n)}})))},t[22]=f,t[23]=a,t[24]=o,t[25]=g,t[26]=i,t[27]=C,t[28]=N):N=t[28];let P=N,te;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(te=e=>{let{startLine:t,endLine:n}=Qe(e),r={id:Ze(),kind:`draft`,startLine:t,endLine:n,text:``};_(e=>{let t=e.flatMap(Uf),i=t.findIndex(e=>e.lineNumber===n);return i<0?[...t,{lineNumber:n,metadata:{entries:[r]}}]:t.map((e,t)=>t===i?{...e,metadata:{entries:[...e.metadata.entries,r]}}:e)})},t[29]=te):te=t[29];let ne=te,re;t[30]===g?re=t[31]:(re=g.some(Vf),t[30]=g,t[31]=re);let ie=re,ae,oe;t[32]!==O||t[33]!==ie||t[34]!==C?(ae=()=>{let e=w.current;if(e)return xf({root:e,editor:O,isBlocked:()=>ie,onDismiss:()=>C(null)})},oe=[O,ie,C],t[32]=O,t[33]=ie,t[34]=C,t[35]=ae,t[36]=oe):(ae=t[35],oe=t[36]),(0,X.useEffect)(ae,oe);let se;t[37]===C?se=t[38]:(se=e=>{C(e),e&&ne(e)},t[37]=C,t[38]=se);let F=se,ce;t[39]!==u||t[40]!==x?(ce=(e,t,n)=>{u(e,t,n),T.current!==null&&(cancelAnimationFrame(T.current),T.current=null),n!==`unmount`&&(T.current=requestAnimationFrame(()=>{T.current=null,e.isConnected&&t.setSelectedLines(x,{notify:!1})}))},t[39]=u,t[40]=x,t[41]=ce):ce=t[41];let le=ce,ue;t[42]===Symbol.for(`react.memo_cache_sentinel`)?(ue={overscrollSize:600,intersectionObserverMargin:1200},t[42]=ue):ue=t[42];let I;t[43]!==o||t[44]!==r||t[45]!==i?(I=Cf(r,i,o),t[43]=o,t[44]=r,t[45]=i,t[46]=I):I=t[46];let de;t[47]!==o||t[48]!==i||t[49]!==I?(de={name:i,contents:o,cacheKey:I},t[47]=o,t[48]=i,t[49]=I,t[50]=de):de=t[50];let fe=!ie,pe=!ie,me=l?`wrap`:`scroll`,he;t[51]===s?he=t[52]:(he=Be(s),t[51]=s,t[52]=he);let ge;t[53]!==F||t[54]!==le||t[55]!==s||t[56]!==C||t[57]!==fe||t[58]!==pe||t[59]!==me||t[60]!==he?(ge={disableFileHeader:!0,enableGutterUtility:fe,enableLineSelection:pe,onGutterUtilityClick:C,onLineSelectionChange:C,onLineSelectionEnd:F,overflow:me,theme:he,themeType:s,unsafeCSS:jf,onPostRender:le},t[53]=F,t[54]=le,t[55]=s,t[56]=C,t[57]=fe,t[58]=pe,t[59]=me,t[60]=he,t[61]=ge):ge=t[61];let _e;t[62]!==M||t[63]!==P?(_e=e=>(0,Z.jsx)(`div`,{className:`py-1`,children:e.metadata.entries.map(e=>(0,Z.jsx)(Ye,{kind:e.kind,rangeLabel:$e(e.startLine,e.endLine),text:e.text,onCancel:()=>M(e.id),onComment:t=>P(e.id,t),onDelete:()=>M(e.id)},e.id))}),t[62]=M,t[63]=P,t[64]=_e):_e=t[64];let ye;t[65]!==g||t[66]!==x||t[67]!==de||t[68]!==ge||t[69]!==_e?(ye=(0,Z.jsx)(`div`,{ref:w,className:`flex min-h-0 flex-1`,children:(0,Z.jsx)(Ve,{className:`file-preview-virtualizer min-h-0 flex-1 overflow-auto`,config:ue,children:(0,Z.jsx)(zl,{file:de,options:ge,selectedLines:x,lineAnnotations:g,renderAnnotation:_e,className:`min-h-full`,contentEditable:!0})})}),t[65]=g,t[66]=x,t[67]=de,t[68]=ge,t[69]=_e,t[70]=ye):ye=t[70];let be;return t[71]!==O||t[72]!==ye?(be=(0,Z.jsx)(Ge,{editor:O,children:ye}),t[71]=O,t[72]=ye,t[73]=be):be=t[73],be}function Vf(e){return e.metadata.entries.some(Hf)}function Hf(e){return e.kind===`draft`}function Uf(e){let t=e.metadata.entries.filter(Wf);return t.length>0?[{...e,metadata:{entries:t}}]:[]}function Wf(e){return e.kind!==`draft`}function Gf(e){return e.metadata.entries}function Kf(e){return e.removeReviewComment}function qf(e){return e.addReviewComment}function Jf(e){let t=(0,af.c)(17),{environmentId:n,cwd:r,relativePath:i,contents:a,threadRef:o,readOnly:s,onPendingChange:c}=e,l;t[0]!==r||t[1]!==n||t[2]!==c||t[3]!==i?(l={environmentId:n,cwd:r,relativePath:i,onPendingChange:c},t[0]=r,t[1]=n,t[2]=c,t[3]=i,t[4]=l):l=t[4];let u=zf(l),d;t[5]!==a||t[6]!==r||t[7]!==n||t[8]!==s||t[9]!==i||t[10]!==u?(d=s?{}:{onTaskListChange:e=>{let{markerOffset:t,checked:o}=e,s=Re(n,r,i)?.contents??a,c=Ef(s,t,o);c!==s&&(ve(n,r,i,c),u.change(c))}},t[5]=a,t[6]=r,t[7]=n,t[8]=s,t[9]=i,t[10]=u,t[11]=d):d=t[11];let f;return t[12]!==a||t[13]!==r||t[14]!==d||t[15]!==o?(f=(0,Z.jsx)(Oe,{className:`min-h-0 flex-1`,children:(0,Z.jsx)(le,{text:a,cwd:r,threadRef:o,className:`mx-auto max-w-4xl px-6 py-5`,...d})}),t[12]=a,t[13]=r,t[14]=d,t[15]=o,t[16]=f):f=t[16],f}function Yf(){try{return l(Of,o)??!0}catch(e){return console.error(e),!0}}function Xf(e){let t=(0,af.c)(102),{environmentId:n,cwd:r,projectName:a,workspaceRoot:o,relativePath:s,isOutsideWorkspace:l,threadRef:d,composerDraftTarget:m,keybindings:y,availableEditors:w,revealLine:T,revealRequestId:E,onOpenFile:D,onPendingChange:k}=e,{resolvedTheme:j}=x(),M=Je(Qf),N=g(),P=i(n),te;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(te={reportFailure:!1},t[0]=te):te=t[0];let ne=_e(ce.createUrl,te),re;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(re={reportFailure:!1},t[1]=re):re=t[1];let ie=S(we.open,re),ae=n===N,oe;t[2]===s?oe=t[3]:(oe=s!==null&&Fe(s),t[2]=s,t[3]=oe);let se=oe,F=je(n,r,s,!se),[le,ue]=(0,X.useState)(Yf),[I,de]=(0,X.useState)(!1),fe;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(fe={path:null,revealRequestId:null},t[4]=fe):fe=t[4];let[pe,me]=(0,X.useState)(fe),ge=(0,X.useRef)(null),ve;t[5]===s?ve=t[6]:(ve=s?Tf(s):!1,t[5]=s,t[6]=ve);let ye=ve,be=ye&&pe.path===s&&(T===null||pe.revealRequestId===E),Se;t[7]===s?Se=t[8]:(Se=s!==null&&He()&&ee(s),t[7]=s,t[8]=Se);let L=Se,Ee;t[9]!==r||t[10]!==s?(Ee=s?h(s,r):null,t[9]=r,t[10]=s,t[11]=Ee):Ee=t[11];let R=Ee,Ae;t[12]!==R||t[13]!==ae||t[14]!==d.threadId||t[15]!==o?(Ae=R===null?null:Le({filePath:R,threadId:d.threadId,workspaceRoot:o,allowLocalFiles:ae}),t[12]=R,t[13]=ae,t[14]=d.threadId,t[15]=o,t[16]=Ae):Ae=t[16];let Me=Ae,Ne;t[17]!==r||t[18]!==l||t[19]!==a||t[20]!==s?(Ne=s?wf(l?r:a,s):[],t[17]=r,t[18]=l,t[19]=a,t[20]=s,t[21]=Ne):Ne=t[21];let Re=Ne,ze=Ff(s,T,E),Ue;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(Ue=()=>{(ge.current?.querySelector(`[data-current-file-crumb='true']`))?.scrollIntoView({block:`nearest`,inline:`end`})},t[22]=Ue):Ue=t[22];let We;t[23]===s?We=t[24]:(We=[s],t[23]=s,t[24]=We),(0,X.useEffect)(Ue,We);let Ge;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(Ge=()=>{ue(Zf)},t[25]=Ge):Ge=t[25];let Ke=Ge,qe;t[26]!==R||t[27]!==ae||t[28]!==ne||t[29]!==P||t[30]!==ie||t[31]!==j||t[32]!==d||t[33]!==o?(qe=()=>{!R||!P||(async()=>{let e=await xe({threadRef:d,filePath:R,httpBaseUrl:P,workspaceRoot:o,allowLocalFiles:ae,theme:j,createAssetUrl:ne,openPreview:ie});if(e._tag===`Success`||v(e))return;let t=p(e);A.add(Ce({type:`error`,title:`Unable to open file in browser`,description:t instanceof Error?t.message:`An error occurred.`}))})()},t[26]=R,t[27]=ae,t[28]=ne,t[29]=P,t[30]=ie,t[31]=j,t[32]=d,t[33]=o,t[34]=qe):qe=t[34];let Ye=qe,Xe;t[35]!==R||t[36]!==ae||t[37]!==w||t[38]!==m||t[39]!==r||t[40]!==n||t[41]!==F||t[42]!==Me||t[43]!==se||t[44]!==ye||t[45]!==l||t[46]!==y||t[47]!==ze||t[48]!==k||t[49]!==s||t[50]!==be||t[51]!==j||t[52]!==E||t[53]!==d||t[54]!==M?(Xe=s&&se&&Me?(0,Z.jsx)(Mf,{environmentId:n,resource:Me,alt:s},R??s):s&&F.error&&F.data===null?(0,Z.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center px-6 text-center text-xs leading-relaxed text-destructive`,children:F.error}):s&&F.data===null?(0,Z.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center text-muted-foreground`,children:(0,Z.jsx)(Pe,{className:`size-5 animate-spin`})}):s&&F.data?F.data.binary&&R?(0,Z.jsx)(gf,{environmentId:n,keybindings:y,availableEditors:w,absolutePath:R,name:s.slice(s.lastIndexOf(`/`)+1),byteLength:F.data.byteLength,canRevealInFileManager:ae&&c()}):ye&&be?(0,Z.jsx)(Jf,{environmentId:n,cwd:r,relativePath:s,threadRef:d,contents:F.data.contents,readOnly:l,onPendingChange:k}):F.data.truncated||l?(0,Z.jsx)(Ve,{className:`file-preview-virtualizer min-h-0 flex-1 overflow-auto`,config:{overscrollSize:600,intersectionObserverMargin:1200},children:(0,Z.jsx)(zl,{file:{name:s,contents:F.data.contents,cacheKey:Cf(r,s,F.data.contents)},options:{disableFileHeader:!0,overflow:M?`wrap`:`scroll`,theme:Be(j),themeType:j,unsafeCSS:jf,onPostRender:ze},className:`min-h-full`})},`${s}:${j}:${F.data.byteLength}`):(0,Z.jsx)(Bf,{environmentId:n,cwd:r,relativePath:s,composerDraftTarget:m,contents:F.data.contents,resolvedTheme:j,revealRequestId:E,wordWrap:M,onPostRender:ze,onPendingChange:k},`${s}:${j}`):null,t[35]=R,t[36]=ae,t[37]=w,t[38]=m,t[39]=r,t[40]=n,t[41]=F,t[42]=Me,t[43]=se,t[44]=ye,t[45]=l,t[46]=y,t[47]=ze,t[48]=k,t[49]=s,t[50]=be,t[51]=j,t[52]=E,t[53]=d,t[54]=M,t[55]=Xe):Xe=t[55];let Ze=Xe,Qe;t[56]!==R||t[57]!==w||t[58]!==Re||t[59]!==L||t[60]!==n||t[61]!==I||t[62]!==le||t[63]!==Ye||t[64]!==ye||t[65]!==y||t[66]!==N||t[67]!==a||t[68]!==s||t[69]!==be||t[70]!==E?(Qe=s?(0,Z.jsxs)(`div`,{className:`surface-subheader gap-2 px-3`,"data-surface-subheader":!0,children:[(0,Z.jsx)(Oe,{ref:ge,hideScrollbars:!0,scrollFade:!0,className:`min-w-0 flex-1 rounded-none`,"data-file-breadcrumbs":!0,children:(0,Z.jsx)(`div`,{className:`flex h-full w-max min-w-full items-center text-xs`,children:Re.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex min-w-0 shrink-0 items-center`,"data-current-file-crumb":e.kind===`file`,children:[t>0?(0,Z.jsx)(_,{className:`mx-1 size-3.5 shrink-0 text-muted-foreground/60`}):null,(0,Z.jsx)(`span`,{className:b(`max-w-40 truncate`,e.kind===`file`?`font-medium text-foreground`:`text-muted-foreground`),title:e.path||a,children:e.label})]},e.path||`project`))})}),R&&n===N?(0,Z.jsx)(De,{environmentId:n,keybindings:y,availableEditors:w,openInCwd:R,compact:!0,enableShortcut:!1}):null,ye?(0,Z.jsxs)(C,{children:[(0,Z.jsx)(u,{render:(0,Z.jsx)(he,{className:`shrink-0`,pressed:be,onPressedChange:e=>{me({path:e?s:null,revealRequestId:e?E:null})},"aria-label":be?`Show markdown source`:`Show rendered markdown`,variant:`ghost`,size:`sm`,children:be?(0,Z.jsx)(et,{className:`size-3.5`}):(0,Z.jsx)(Ie,{className:`size-3.5`})})}),(0,Z.jsx)(f,{children:be?`Show markdown source`:`Show rendered markdown`})]}):null,L?(0,Z.jsxs)(C,{children:[(0,Z.jsx)(u,{render:(0,Z.jsx)(he,{className:`shrink-0`,pressed:!1,onPressedChange:Ye,"aria-label":`Open file in preview browser`,variant:`ghost`,size:`sm`,children:(0,Z.jsx)(Te,{className:`size-3.5`})})}),(0,Z.jsx)(f,{children:`Open file in preview browser`})]}):null,(0,Z.jsxs)(C,{children:[(0,Z.jsx)(u,{render:(0,Z.jsx)(he,{className:`shrink-0`,pressed:I,onPressedChange:de,"aria-label":I?`Collapse file preview`:`Expand file preview`,variant:`ghost`,size:`sm`,children:I?(0,Z.jsx)(O,{className:`size-3.5`}):(0,Z.jsx)(ke,{className:`size-3.5`})})}),(0,Z.jsx)(f,{children:I?`Collapse file preview`:`Expand file preview`})]}),(0,Z.jsxs)(C,{children:[(0,Z.jsx)(u,{render:(0,Z.jsx)(he,{className:`shrink-0`,pressed:le,onPressedChange:Ke,"aria-label":le?`Hide file explorer`:`Show file explorer`,variant:`ghost`,size:`sm`,children:(0,Z.jsx)(nt,{className:`size-3.5`})})}),(0,Z.jsx)(f,{children:le?`Hide file explorer`:`Show file explorer`})]})]}):null,t[56]=R,t[57]=w,t[58]=Re,t[59]=L,t[60]=n,t[61]=I,t[62]=le,t[63]=Ye,t[64]=ye,t[65]=y,t[66]=N,t[67]=a,t[68]=s,t[69]=be,t[70]=E,t[71]=Qe):Qe=t[71];let $e;t[72]!==F||t[73]!==s?($e=s&&F.data?.truncated?(0,Z.jsxs)(`div`,{className:`shrink-0 border-b border-amber-500/20 bg-amber-500/8 px-3 py-1.5 text-[11px] text-amber-700 dark:text-amber-300`,children:[`Preview limited to the first 1 MB of a `,F.data.byteLength.toLocaleString(),` byte file.`]}):null,t[72]=F,t[73]=s,t[74]=$e):$e=t[74];let tt=s?`flex`:`hidden`,rt;t[75]===tt?rt=t[76]:(rt=b(`min-w-0 flex-1 flex-col overflow-hidden`,tt),t[75]=tt,t[76]=rt);let it;t[77]!==I||t[78]!==Ze?(it=I?(0,Z.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center px-6 text-center text-xs text-muted-foreground`,children:`Shown in the expanded view.`}):Ze,t[77]=I,t[78]=Ze,t[79]=it):it=t[79];let at;t[80]!==rt||t[81]!==it?(at=(0,Z.jsx)(`div`,{className:rt,children:it}),t[80]=rt,t[81]=it,t[82]=at):at=t[82];let z;t[83]!==r||t[84]!==n||t[85]!==le||t[86]!==D||t[87]!==a||t[88]!==s?(z=le||s===null?(0,Z.jsx)(`aside`,{className:b(`flex min-h-0 shrink-0 bg-background`,s?`w-[min(22rem,46%)] min-w-64 border-l border-border/60`:`min-w-0 flex-1`),children:(0,Z.jsx)(uf,{environmentId:n,cwd:r,projectName:a,onOpenFile:D},`${n}:${r}`)}):null,t[83]=r,t[84]=n,t[85]=le,t[86]=D,t[87]=a,t[88]=s,t[89]=z):z=t[89];let B;t[90]!==at||t[91]!==z?(B=(0,Z.jsxs)(`div`,{className:`flex min-h-0 flex-1 overflow-hidden`,children:[at,z]}),t[90]=at,t[91]=z,t[92]=B):B=t[92];let ot=I&&s!==null,st=s??``,ct;t[93]!==Ze||t[94]!==ot||t[95]!==st?(ct=(0,Z.jsx)(df,{open:ot,title:st,onOpenChange:de,children:Ze}),t[93]=Ze,t[94]=ot,t[95]=st,t[96]=ct):ct=t[96];let lt;return t[97]!==Qe||t[98]!==$e||t[99]!==B||t[100]!==ct?(lt=(0,Z.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden bg-background`,children:[Qe,$e,B,ct]}),t[97]=Qe,t[98]=$e,t[99]=B,t[100]=ct,t[101]=lt):lt=t[101],lt}function Zf(e){let t=!e;try{w(Of,t,o)}catch(e){console.error(e)}return t}function Qf(e){return e.wordWrap}export{Xf as default};
1778
- //# sourceMappingURL=FilePreviewPanel-B9z36OYa.js.map
1778
+ //# sourceMappingURL=FilePreviewPanel-DFsoFXYz.js.map