@pi-chamber/web 1.0.5-rc.1 → 1.0.5-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/bin/lib/DOCUMENTATION.md +1 -1
  2. package/bin/lib/commands-status.js +3 -2
  3. package/bin/lib/commands-status.test.js +62 -0
  4. package/dist/assets/{DiagramView-D-OSWTbO.js → DiagramView-DxLAcmg-.js} +1 -1
  5. package/dist/assets/{DiffView-BKT-MIH4.js → DiffView-BzVBoNCp.js} +1 -1
  6. package/dist/assets/{FileSaveConflictDialog-DBkVFssC.js → FileSaveConflictDialog-2KqGdUdB.js} +1 -1
  7. package/dist/assets/{FilesView-B7GIuRlh.js → FilesView-3spQTRpf.js} +1 -1
  8. package/dist/assets/{GitHubDetailScaffold-C9rCZMUT.js → GitHubDetailScaffold-C2d4WqKe.js} +1 -1
  9. package/dist/assets/{GitHubLinkPicker-Bm09hvhJ.js → GitHubLinkPicker-BDwZtk0x.js} +1 -1
  10. package/dist/assets/{GitHubListPrimitives-DlhAlxI6.js → GitHubListPrimitives-Dor_K85Y.js} +1 -1
  11. package/dist/assets/{GitView-BgqdMb0m.js → GitView-CSAJagWK.js} +3 -3
  12. package/dist/assets/{IssuesSurface-BZXAvt49.js → IssuesSurface-euZzv2L9.js} +1 -1
  13. package/dist/assets/{JsonTreeView-BKgCQjh_.js → JsonTreeView-Drmn7tIN.js} +1 -1
  14. package/dist/assets/{MarkdownRendererImpl-BdcyMPw-.js → MarkdownRendererImpl-Bq0p5v9N.js} +1 -1
  15. package/dist/assets/{PatchDiff-2MmWXcGe.js → PatchDiff-BegAimf3.js} +1 -1
  16. package/dist/assets/{PierreDiffViewer-D1F2WvD0.js → PierreDiffViewer-DgU2Zcmr.js} +1 -1
  17. package/dist/assets/{PullRequestsSurface-CN2z3DFv.js → PullRequestsSurface-CnGgmkuf.js} +2 -2
  18. package/dist/assets/{SessionSwitcherContent-CCljxAZb.js → SessionSwitcherContent-Cq5LIBuG.js} +1 -1
  19. package/dist/assets/{SessionSwitcherDropdown-DtNt3qw4.js → SessionSwitcherDropdown-Dpob2_y5.js} +2 -2
  20. package/dist/assets/{SessionUnreadDot-B9bHMy5q.js → SessionUnreadDot-BPKnpGAh.js} +1 -1
  21. package/dist/assets/{SettingsView-DaZVCInW.js → SettingsView-DcOJRyym.js} +4 -4
  22. package/dist/assets/{SettingsWindow-C-ydfopH.js → SettingsWindow-C2RB0AjV.js} +1 -1
  23. package/dist/assets/{ToolOutputDialog-DJUAx_Oj.js → ToolOutputDialog-DmzNX2QX.js} +1 -1
  24. package/dist/assets/{ToolPartDiffPreview-DFyuJM4c.js → ToolPartDiffPreview-CO5Gg17_.js} +1 -1
  25. package/dist/assets/{VirtualizedFileDiff-BS-af6rn.js → VirtualizedFileDiff-CJ1m8JE-.js} +1 -1
  26. package/dist/assets/{computeVirtualFileMetrics-BI6wORhM.js → computeVirtualFileMetrics-8mC_o5zA.js} +1 -1
  27. package/dist/assets/{contextFileOpenGuard-DUMSGR4M.js → contextFileOpenGuard-CRboGmXF.js} +1 -1
  28. package/dist/assets/{gitStatusPredicates-FdKYDZe3.js → gitStatusPredicates-BqV-kOGY.js} +1 -1
  29. package/dist/assets/{githubLink-B3-BaGpb.js → githubLink-DSgdECMr.js} +1 -1
  30. package/dist/assets/{index-Df-vmvzu.js → index-B3qmI8VW.js} +1 -1
  31. package/dist/assets/{main-61_cd7S7.js → main-Bn93XwxQ.js} +2 -2
  32. package/dist/assets/{main-q43jqZ2I.js → main-HPNu-7DG.js} +4 -4
  33. package/dist/assets/{markdownCore-CqHYlXi_.js → markdownCore-Csm6UEBe.js} +1 -1
  34. package/dist/assets/{miniChat-vOuWN5pV.js → miniChat-C3W5IvM4.js} +2 -2
  35. package/dist/assets/{mobile-mrXWV5ky.js → mobile-COEEitAQ.js} +2 -2
  36. package/dist/assets/{pi-session-focus-preference-BEufpwC6.js → pi-session-focus-preference-DQjF7Nh1.js} +1 -1
  37. package/dist/assets/{renderDiffWithHighlighter-BD9CAhZU.js → renderDiffWithHighlighter-BBwvKSDe.js} +1 -1
  38. package/dist/assets/{renderElectronMiniChatApp-QQFXkY5Y.js → renderElectronMiniChatApp-7vIiCPiK.js} +2 -2
  39. package/dist/assets/{renderFileWithHighlighter-KiEWMtzI.js → renderFileWithHighlighter-VOwWxIE1.js} +1 -1
  40. package/dist/assets/{renderMobileApp-DIZYvrhi.js → renderMobileApp-BQDG02OP.js} +3 -3
  41. package/dist/assets/{runtimeEndpointReset-BA2uP2rj.js → runtimeEndpointReset-CzwDZ_EP.js} +4 -4
  42. package/dist/assets/{useAppFontEffects-Bfw_d5eB.js → useAppFontEffects-BQ1JUauS.js} +6 -6
  43. package/dist/assets/{useFilesViewSearch-Budwejnx.js → useFilesViewSearch-BYG2TZWz.js} +1 -1
  44. package/dist/assets/{useGitHubRemoteSearch-gUdylYy3.js → useGitHubRemoteSearch-Bo1LF-x_.js} +1 -1
  45. package/dist/assets/{useSwitcherItems-yHSMduoo.js → useSwitcherItems-q0ZavMJb.js} +1 -1
  46. package/dist/assets/{web-components-CeHLxvED.js → web-components-CJ0xIy7r.js} +1 -1
  47. package/dist/index.html +1 -1
  48. package/dist/mini-chat.html +1 -1
  49. package/dist/mobile.html +1 -1
  50. package/package.json +1 -1
  51. package/server/index.js +4 -1
  52. package/server/lib/tailscale/DOCUMENTATION.md +56 -6
  53. package/server/lib/tailscale/nc-probe.js +220 -0
  54. package/server/lib/tailscale/public-dns.js +72 -0
  55. package/server/lib/tailscale/service.js +183 -7
  56. package/server/lib/tailscale/tailscale.test.js +537 -1
@@ -1,5 +1,5 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-DWSrsQWl.js","assets/vendor-zustand-CUi8eEds.js","assets/vendor-react-DASdDPIk.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index-DsQIBAWK.css"])))=>i.map(i=>d[i]);
2
- import{k as t}from"./vendor-boot-EC6IyLt1.js";import{R as u}from"./vendor-react-DASdDPIk.js";import{i as Pe,j as ot,p as lt,l as it,m as ct,r as ut,b as dt,c as mt,G as ht,h as Ne,u as ft,n as bt,o as gt}from"./useGitHubRemoteSearch-gUdylYy3.js";import{ae as xt,B as j,I as R,au as pt,av as yt,aw as vt,ax as Ct,ay as jt,az as wt,z as $e,h as kt,t as P,cU as St,o as ye,as as Oe,ai as Re,al as Le,an as Ee,cH as Nt,cI as Rt,ap as xe,aq as Lt,y as Et}from"./useAppFontEffects-Bfw_d5eB.js";import{ae as It,af as Ie,ag as pe,ah as Ae,ai as ce,aj as At,ak as ue,U as Dt,_ as _e,a4 as Gt,a1 as Tt,al as Ht}from"./runtimeEndpointReset-BA2uP2rj.js";import{_ as Bt}from"./vendor-vite-runtime-DD1OZmLC.js";import{c as Ft,d as Mt}from"./vendor-zustand-CUi8eEds.js";import{n as Ue,m as zt}from"./index-DWSrsQWl.js";import{a as Ke,u as Pt,p as $t,r as Ot,t as De,x as _t,z as Ut,A as Kt,w as ie,y as Wt,B as oe,C as We,D as qt,R as Vt,E as Ge,G as Qt,H as Jt,I as Yt,J as Zt,K as Te}from"./GitHubDetailScaffold-C9rCZMUT.js";import{I as He,a as Xt,b as es,i as qe,c as ts,d as ss,s as as,g as le,e as ns,f as rs,h as Be,j as Fe,C as os,k as ls,v as is}from"./githubLink-B3-BaGpb.js";import{a as cs,b as us}from"./GitHubListPrimitives-DlhAlxI6.js";import"./vendor-clsx-B-dksMZM.js";import"./runtimeSurface-Der4qUnI.js";import"./nativeFileSave-CFuugNKV.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./SessionUnreadDot-B9bHMy5q.js";/* empty css */import"./permissionStore-B9Hkrqny.js";import"./vendor-dompurify-r8glNMJW.js";const ve={state:"open",involvement:"all",labels:"",search:"",sort:"updated"},ds=3e4,ms=100,hs=50,Ve=(e,s)=>ue([e,"issues-collection",s]),Qe=(e,s)=>ue([e,"issues-remote",s.state,s.involvement,s.labels.trim(),s.q.trim()]),Ce=(e,s)=>ue([e,"issue-detail",s]),je=(e,s)=>ue([e,"issue-comments",s]),fs=e=>({state:e,perPage:ms}),bs=(e,s)=>({state:e.state,filter:e.involvement,q:e.q.trim()?e.q.trim():void 0,labels:e.labels.trim()?e.labels.trim():void 0,perPage:hs,...s?{cursor:s}:{}}),gs={set:e=>{typeof e=="function"?C.setState(s=>{const n={filtersByScope:s.filtersByScope,selectionByDirectory:s.selectionByDirectory};return e(n)}):C.setState(e)},get:()=>{const e=C.getState();return{filtersByScope:e.filtersByScope,selectionByDirectory:e.selectionByDirectory}}},g=At({openCollection:"open",closedCollection:"closed",defaultFilters:ve,freshWindowMs:ds,serverKind:"issues",errorFallback:"Issue request failed",collectionKeyFor:Ve,remoteKeyFor:Qe,detailKeyFor:Ce,commentsKeyFor:je,buildCollectionQuery:e=>({...fs(e)}),buildRemoteQuery:(e,s)=>({...bs(e,s)}),fetchList:async(e,s,n,r)=>{const l=await e.issuesList(s,n,r);return{items:l.items,nextCursor:l.nextCursor,fetchedAt:l.fetchedAt}},fetchDetail:async(e,s,n,r)=>e.issueGet(s,n,r),fetchComments:async(e,s,n,r,l)=>{const a=await e.issueComments(s,n,r,l);return{comments:a.comments,nextCursor:a.nextCursor,fetchedAt:a.fetchedAt}}},gs),C=Ft()(Mt((e,s)=>({...g.initialState,actionErrorByDetail:{},actingActions:{},setFilters:g.setFilters,resetFilters:g.resetFilters,selectIssue:g.select,ensureCollection:g.ensureCollection,ensureCollectionsFresh:g.ensureCollectionsFresh,prefetchClosedCollection:g.prefetchClosedCollection,loadMoreCollection:g.loadMoreCollection,refreshCollections:g.refreshCollections,searchRemote:g.searchRemote,loadMoreRemote:g.loadMoreRemote,dropRemoteForRepo:g.dropRemoteForRepo,refreshAllForScope:g.refreshAllForScope,ensureDetail:g.ensureDetail,refreshDetail:g.refreshDetail,ensureComments:g.ensureComments,loadMoreComments:g.loadMoreComments,refreshComments:g.refreshComments,updateIssue:async(n,r,l,a,d)=>{const b=Ae(r,l),o=Ce(r,l);if(s().actingActions[b])return{ok:!1,error:{kind:"failed",message:"An update is already in progress"}};e(x=>({actingActions:{...x.actingActions,[b]:!0},actionErrorByDetail:{...x.actionErrorByDetail,[b]:null}}));const c=g.resources.details.getEntry(o)?.data?.detail??null,y=c?.issue??null,w=y?{...y,title:a.title??y.title,body:a.body??y.body,state:a.state??y.state,stateReason:a.state!==void 0?a.stateReason??null:y.stateReason,labels:a.labels!==void 0?a.labels.map(x=>({name:x})):y.labels,assignees:a.assignees!==void 0?a.assignees.map(x=>({login:x})):y.assignees}:null;w&&c&&await g.resources.details.refresh(o,async()=>({detail:{...c,issue:w}})).catch(()=>null);try{return await d.issueUpdate(n,r,l,a),await pe(d,{directory:n,repo:r,kind:"issues",number:l}),s().dropRemoteForRepo(r),await s().refreshCollections(n,r,"both",d).catch(()=>null),await s().refreshDetail(n,r,l,d).catch(()=>null),e(x=>({actingActions:{...x.actingActions,[b]:!1}})),{ok:!0}}catch(x){const S=g.toStoreError(x);return c&&await g.resources.details.refresh(o,async()=>({detail:c})).catch(()=>null),e(f=>({actingActions:{...f.actingActions,[b]:!1},actionErrorByDetail:{...f.actionErrorByDetail,[b]:S}})),{ok:!1,error:S}}},addComment:async(n,r,l,a,d)=>{const b=Ae(r,l),o=je(r,l),c=a.trim(),y={id:-Date.now(),url:"",body:c,author:null,createdAt:new Date().toISOString(),updatedAt:null},w=g.resources.comments.getEntry(o)?.data??null;if(w){const x={comments:[...w.comments,y],nextCursor:w.nextCursor,fetchedAt:w.fetchedAt};await g.resources.comments.refresh(o,async()=>x).catch(()=>null)}try{return await d.issueComment(n,r,l,c),await pe(d,{directory:n,repo:r,kind:"issues",number:l}),await s().refreshComments(n,r,l,d).catch(()=>null),await s().refreshDetail(n,r,l,d).catch(()=>null),{ok:!0}}catch(x){const S=g.toStoreError(x);return w?await g.resources.comments.refresh(o,async()=>w).catch(()=>null):g.resources.comments.remove(o),e(f=>({actionErrorByDetail:{...f.actionErrorByDetail,[b]:S}})),{ok:!1,error:S}}},createIssue:async(n,r)=>{try{const l=await r.issueCreate(n.directory,n.repo,{title:n.title,body:n.body,labels:n.labels,assignees:n.assignees});return await pe(r,{directory:n.directory,repo:n.repo,kind:"issues"}),s().dropRemoteForRepo(n.repo),await s().refreshCollections(n.directory,n.repo,"both",r).catch(()=>null),{ok:!0,number:l.issue.number}}catch(l){return{ok:!1,error:g.toStoreError(l)}}},notifyAgentTurnComplete:n=>{const r=Ue((n||"").trim());if(!r)return;const l=s().selectionByDirectory[r];!l?.repo||typeof l.number!="number"||(g.markCollectionsStale(l.repo),Bt(async()=>{const{getRegisteredRuntimeAPIs:a}=await import("./index-DWSrsQWl.js").then(d=>d.cA);return{getRegisteredRuntimeAPIs:a}},__vite__mapDeps([0,1,2,3,4,5,6,7])).then(({getRegisteredRuntimeAPIs:a})=>{const d=a()?.github??null;if(d)return s().refreshDetail(r,l.repo,l.number,d)}).catch(()=>{}))},resetForRuntimeSwitch:()=>{g.resetCore(),e({actionErrorByDetail:{},actingActions:{}})}}),{name:"github-issues-store"}));typeof window<"u"&&zt(()=>{C.getState().resetForRuntimeSwitch()});const xs=e=>g.getLocalIndex(e),ps=(e,s)=>g.getLocalIndex(e).find(n=>n.number===s)??null,Me=(e,s)=>ce(g.resources.collections,e?Ve(e,s):null),ys=(e,s)=>ce(g.resources.remote,e?Qe(e,s):null),vs=(e,s)=>ce(g.resources.details,e!=null&&s!=null?Ce(e,s):null),Cs=(e,s)=>ce(g.resources.comments,e!=null&&s!=null?je(e,s):null),js=(e,s)=>C(n=>!e||!s?ve:n.filtersByScope[It(e,s)]??ve),ws=e=>C(s=>e?s.selectionByDirectory[Ue(e)]??Ie:Ie),ks=e=>typeof e!="number"||e===0?null:t.jsxs("span",{className:"inline-flex shrink-0 items-center gap-0.5 typography-micro tabular-nums text-muted-foreground",title:`${e} comments`,"aria-label":`${e} comments`,children:[t.jsx(R,{name:"chat-1",className:"size-3.5"}),e]}),Ss=({items:e,hasMore:s,isLoadingMore:n,isLoading:r,isRefreshing:l,stale:a,error:d,filters:b,countComplete:o=!0,incompleteNotice:c=null,remote:y=null,numberJump:w=null,onFiltersChange:x,onClearFilters:S,onLoadMore:f,onRetry:p,onOpen:N,onNewIssue:k,headerActionsSlot:T=null,headerActionsPresentation:H="drawer"})=>{const z=b.state==="open"&&b.involvement==="all"&&!b.search.trim()&&!b.labels.trim(),{isMobile:D,isTablet:I}=xt(),B=D||I,G=T!=null,A=H??"drawer",$=G?A==="desktop"?t.jsxs(j,{type:"button",variant:"ghost",size:"sm",onClick:k,"aria-label":"New issue",title:"New issue",children:[t.jsx(R,{name:"add",className:"size-4"}),"New issue"]}):t.jsxs(j,{type:"button",variant:"ghost",size:"default",onClick:k,"aria-label":"New issue",title:"New issue",children:[t.jsx(R,{name:"add",className:"size-4"}),"New issue"]}):t.jsxs(j,{type:"button",variant:"ghost",size:B?"sm":"xs",onClick:k,"aria-label":"New issue",title:"New issue",children:[t.jsx(R,{name:"add",className:"size-3.5"}),"New issue"]}),O=u.useCallback(h=>t.jsx("li",{role:"listitem",children:t.jsx(Pe,{glyph:t.jsx(Ke,{kind:"issue",state:h.state}),number:`#${h.number}`,title:h.title,signals:ks(h.comments),meta:t.jsxs(t.Fragment,{children:[t.jsx(ot,{login:h.author?.login,avatarUrl:h.author?.avatarUrl}),t.jsx(lt,{labels:h.labels??[]})]}),updatedAt:h.updatedAt,onOpen:()=>N(h.number),ariaLabel:`Open issue #${h.number} ${h.title}`})},h.number),[N]);return t.jsx(it,{items:e,renderRow:O,hasMore:s,isLoadingMore:n,isLoading:r,isRefreshing:l,stale:a,error:d,searchValue:b.search,onSearchChange:h=>x({search:h}),searchPlaceholder:"Search issues, or label:bug",searchAriaLabel:"Search issues",toolbarControls:t.jsx(ct,{stateValue:b.state,stateOptions:He.map(h=>({id:h.id,label:h.label})),onStateChange:h=>x({state:h}),involvementValue:b.involvement,involvementOptions:es.map(h=>({id:h.id,label:h.label})),onInvolvementChange:h=>x({involvement:h}),labelsValue:b.labels,onLabelsChange:h=>x({labels:h}),sortValue:b.sort,sortOptions:Xt.map(h=>({id:h.id,label:h.label})),onSortChange:h=>x({sort:h}),sortAriaLabel:"Sort issues"}),primaryAction:$,headerActionsSlot:T,headerActionsPresentation:A,isDefaultFilters:z,stateLabel:He.find(h=>h.id===b.state)?.label??b.state,kindSingular:"issue",kindPlural:"issues",noItemsTitle:b.state==="open"?"No open issues":"No issues yet",noItemsBody:"Issues for this repository appear here.",noItemsIcon:"inbox-archive",noItemsAction:t.jsxs(j,{type:"button",variant:"outline",size:"sm",onClick:k,children:[t.jsx(R,{name:"add",className:"size-3.5"}),"New issue"]}),listAriaLabel:"Issues",skeletonLabel:"Loading issues",updatedAtOf:h=>h.updatedAt,countComplete:o,incompleteNotice:c,remote:y,numberJump:w,numberJumpKind:"issue",onClearFilters:S,onLoadMore:f,onRetry:p,onOpen:N})},Je=(e,s,n)=>{const[r,l]=u.useState([]),[a,d]=u.useState([]),[b,o]=u.useState(!1);return u.useEffect(()=>{if(!n)return;let c=!1;return o(!0),n.repoMeta(e,s).then(y=>{c||(l(y.labels??[]),d(y.assignees??[]))}).catch(()=>{c||(l([]),d([]))}).finally(()=>{c||o(!1)}),()=>{c=!0}},[n,e,s]),{labels:r,assignees:a,loading:b}},Ye=(e,s)=>e.includes(s)?e.filter(n=>n!==s):[...e,s],Ze=({candidates:e,loading:s,selected:n,onChange:r})=>s?t.jsx("p",{className:"typography-micro text-muted-foreground",children:"Loading labels…"}):e.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground",children:"No labels in this repository."}):t.jsx("div",{className:"flex flex-wrap gap-1",children:e.map(l=>{const a=n.includes(l.name);return t.jsx(j,{type:"button",variant:"chip",size:"xs","aria-pressed":a,onClick:()=>r(Ye(n,l.name)),children:l.name},l.name)})}),Xe=({candidates:e,loading:s,selected:n,onChange:r})=>s?t.jsx("p",{className:"typography-micro text-muted-foreground",children:"Loading assignees…"}):e.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground",children:"No assignable users found."}):t.jsx("div",{className:"flex flex-wrap gap-1",children:e.map(l=>{const a=l.login,d=a?n.includes(a):!1;return t.jsx(j,{type:"button",variant:"chip",size:"xs","aria-pressed":d,onClick:()=>{a&&r(Ye(n,a))},children:a},a)})}),Ns=({open:e,onOpenChange:s,issueNumber:n,issueTitle:r,busy:l,onChoose:a})=>{const[d,b]=u.useState("worktree"),o=qe(n,r);return t.jsx(pt,{open:e,onOpenChange:s,children:t.jsxs(yt,{className:"max-w-md w-[calc(100vw-2rem)]",children:[t.jsxs(vt,{children:[t.jsxs(Ct,{children:["Start session from issue #",n]}),t.jsx(jt,{children:"Choose where the new session works. The composer is pre-filled — nothing is sent automatically."})]}),t.jsxs("div",{className:"flex flex-col gap-1",role:"radiogroup","aria-label":"Session location",children:[t.jsxs("button",{type:"button",role:"radio","aria-checked":d==="current",onClick:()=>b("current"),className:"flex items-start gap-2 rounded-md border border-border px-3 py-2 text-left hover:bg-interactive-hover",children:[t.jsx(R,{name:d==="current"?"record-circle":"checkbox-blank-circle-fill",className:"mt-0.5 size-4 shrink-0 text-muted-foreground"}),t.jsxs("span",{className:"min-w-0",children:[t.jsx("span",{className:"block typography-ui-label text-foreground",children:"Current checkout"}),t.jsx("span",{className:"block typography-micro text-muted-foreground",children:"Work directly where you are now."})]})]}),t.jsxs("button",{type:"button",role:"radio","aria-checked":d==="worktree",onClick:()=>b("worktree"),className:"flex items-start gap-2 rounded-md border border-border px-3 py-2 text-left hover:bg-interactive-hover",children:[t.jsx(R,{name:d==="worktree"?"record-circle":"checkbox-blank-circle-fill",className:"mt-0.5 size-4 shrink-0 text-muted-foreground"}),t.jsxs("span",{className:"min-w-0",children:[t.jsx("span",{className:"block typography-ui-label text-foreground",children:"New worktree"}),t.jsxs("span",{className:"block truncate font-mono typography-micro text-muted-foreground",title:o,children:["Branch ",o]})]})]})]}),t.jsxs(wt,{children:[t.jsx(j,{type:"button",variant:"outline",size:"sm",onClick:()=>s(!1),disabled:l,children:"Cancel"}),t.jsx(j,{type:"button",variant:"default",size:"sm",onClick:()=>a(d),disabled:l,"aria-label":d==="worktree"?"Create worktree and open session draft":"Open session draft in current checkout",children:l?"Working…":d==="worktree"?"Create worktree":"Open draft"})]})]})})},ze=e=>{const s=as(e.title);return e.kind==="pr"?`pr-${e.number}-${s}`:qe(e.number,e.title)},Rs=async(e,s)=>{const{github:n,git:r,openDraft:l,refreshWorktrees:a}=s;if(!l)return{ok:!1,error:"Sessions are not available in this runtime"};let d;try{d=(await n.agentContext(e.directory,e.repo,e.kind==="pr"?"pr":"issue",e.number)).text}catch(p){return{ok:!1,error:p instanceof Error?p.message:"Failed to load issue context"}}const o=`${e.kind==="pr"?"PR":"Issue"} #${e.number}: ${e.title.trim()||"(untitled)"}`,c=e.kind==="pr"?`Work on this GitHub pull request. Read the quoted context below, then propose a plan and wait for confirmation before changing code.
2
+ import{k as t}from"./vendor-boot-EC6IyLt1.js";import{R as u}from"./vendor-react-DASdDPIk.js";import{i as Pe,j as ot,p as lt,l as it,m as ct,r as ut,b as dt,c as mt,G as ht,h as Ne,u as ft,n as bt,o as gt}from"./useGitHubRemoteSearch-Bo1LF-x_.js";import{ae as xt,B as j,I as R,au as pt,av as yt,aw as vt,ax as Ct,ay as jt,az as wt,z as $e,h as kt,t as P,cU as St,o as ye,as as Oe,ai as Re,al as Le,an as Ee,cH as Nt,cI as Rt,ap as xe,aq as Lt,y as Et}from"./useAppFontEffects-BQ1JUauS.js";import{ae as It,af as Ie,ag as pe,ah as Ae,ai as ce,aj as At,ak as ue,U as Dt,_ as _e,a4 as Gt,a1 as Tt,al as Ht}from"./runtimeEndpointReset-CzwDZ_EP.js";import{_ as Bt}from"./vendor-vite-runtime-DD1OZmLC.js";import{c as Ft,d as Mt}from"./vendor-zustand-CUi8eEds.js";import{n as Ue,m as zt}from"./index-DWSrsQWl.js";import{a as Ke,u as Pt,p as $t,r as Ot,t as De,x as _t,z as Ut,A as Kt,w as ie,y as Wt,B as oe,C as We,D as qt,R as Vt,E as Ge,G as Qt,H as Jt,I as Yt,J as Zt,K as Te}from"./GitHubDetailScaffold-C2d4WqKe.js";import{I as He,a as Xt,b as es,i as qe,c as ts,d as ss,s as as,g as le,e as ns,f as rs,h as Be,j as Fe,C as os,k as ls,v as is}from"./githubLink-DSgdECMr.js";import{a as cs,b as us}from"./GitHubListPrimitives-Dor_K85Y.js";import"./vendor-clsx-B-dksMZM.js";import"./runtimeSurface-Der4qUnI.js";import"./nativeFileSave-CFuugNKV.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./SessionUnreadDot-BPKnpGAh.js";/* empty css */import"./permissionStore-B9Hkrqny.js";import"./vendor-dompurify-r8glNMJW.js";const ve={state:"open",involvement:"all",labels:"",search:"",sort:"updated"},ds=3e4,ms=100,hs=50,Ve=(e,s)=>ue([e,"issues-collection",s]),Qe=(e,s)=>ue([e,"issues-remote",s.state,s.involvement,s.labels.trim(),s.q.trim()]),Ce=(e,s)=>ue([e,"issue-detail",s]),je=(e,s)=>ue([e,"issue-comments",s]),fs=e=>({state:e,perPage:ms}),bs=(e,s)=>({state:e.state,filter:e.involvement,q:e.q.trim()?e.q.trim():void 0,labels:e.labels.trim()?e.labels.trim():void 0,perPage:hs,...s?{cursor:s}:{}}),gs={set:e=>{typeof e=="function"?C.setState(s=>{const n={filtersByScope:s.filtersByScope,selectionByDirectory:s.selectionByDirectory};return e(n)}):C.setState(e)},get:()=>{const e=C.getState();return{filtersByScope:e.filtersByScope,selectionByDirectory:e.selectionByDirectory}}},g=At({openCollection:"open",closedCollection:"closed",defaultFilters:ve,freshWindowMs:ds,serverKind:"issues",errorFallback:"Issue request failed",collectionKeyFor:Ve,remoteKeyFor:Qe,detailKeyFor:Ce,commentsKeyFor:je,buildCollectionQuery:e=>({...fs(e)}),buildRemoteQuery:(e,s)=>({...bs(e,s)}),fetchList:async(e,s,n,r)=>{const l=await e.issuesList(s,n,r);return{items:l.items,nextCursor:l.nextCursor,fetchedAt:l.fetchedAt}},fetchDetail:async(e,s,n,r)=>e.issueGet(s,n,r),fetchComments:async(e,s,n,r,l)=>{const a=await e.issueComments(s,n,r,l);return{comments:a.comments,nextCursor:a.nextCursor,fetchedAt:a.fetchedAt}}},gs),C=Ft()(Mt((e,s)=>({...g.initialState,actionErrorByDetail:{},actingActions:{},setFilters:g.setFilters,resetFilters:g.resetFilters,selectIssue:g.select,ensureCollection:g.ensureCollection,ensureCollectionsFresh:g.ensureCollectionsFresh,prefetchClosedCollection:g.prefetchClosedCollection,loadMoreCollection:g.loadMoreCollection,refreshCollections:g.refreshCollections,searchRemote:g.searchRemote,loadMoreRemote:g.loadMoreRemote,dropRemoteForRepo:g.dropRemoteForRepo,refreshAllForScope:g.refreshAllForScope,ensureDetail:g.ensureDetail,refreshDetail:g.refreshDetail,ensureComments:g.ensureComments,loadMoreComments:g.loadMoreComments,refreshComments:g.refreshComments,updateIssue:async(n,r,l,a,d)=>{const b=Ae(r,l),o=Ce(r,l);if(s().actingActions[b])return{ok:!1,error:{kind:"failed",message:"An update is already in progress"}};e(x=>({actingActions:{...x.actingActions,[b]:!0},actionErrorByDetail:{...x.actionErrorByDetail,[b]:null}}));const c=g.resources.details.getEntry(o)?.data?.detail??null,y=c?.issue??null,w=y?{...y,title:a.title??y.title,body:a.body??y.body,state:a.state??y.state,stateReason:a.state!==void 0?a.stateReason??null:y.stateReason,labels:a.labels!==void 0?a.labels.map(x=>({name:x})):y.labels,assignees:a.assignees!==void 0?a.assignees.map(x=>({login:x})):y.assignees}:null;w&&c&&await g.resources.details.refresh(o,async()=>({detail:{...c,issue:w}})).catch(()=>null);try{return await d.issueUpdate(n,r,l,a),await pe(d,{directory:n,repo:r,kind:"issues",number:l}),s().dropRemoteForRepo(r),await s().refreshCollections(n,r,"both",d).catch(()=>null),await s().refreshDetail(n,r,l,d).catch(()=>null),e(x=>({actingActions:{...x.actingActions,[b]:!1}})),{ok:!0}}catch(x){const S=g.toStoreError(x);return c&&await g.resources.details.refresh(o,async()=>({detail:c})).catch(()=>null),e(f=>({actingActions:{...f.actingActions,[b]:!1},actionErrorByDetail:{...f.actionErrorByDetail,[b]:S}})),{ok:!1,error:S}}},addComment:async(n,r,l,a,d)=>{const b=Ae(r,l),o=je(r,l),c=a.trim(),y={id:-Date.now(),url:"",body:c,author:null,createdAt:new Date().toISOString(),updatedAt:null},w=g.resources.comments.getEntry(o)?.data??null;if(w){const x={comments:[...w.comments,y],nextCursor:w.nextCursor,fetchedAt:w.fetchedAt};await g.resources.comments.refresh(o,async()=>x).catch(()=>null)}try{return await d.issueComment(n,r,l,c),await pe(d,{directory:n,repo:r,kind:"issues",number:l}),await s().refreshComments(n,r,l,d).catch(()=>null),await s().refreshDetail(n,r,l,d).catch(()=>null),{ok:!0}}catch(x){const S=g.toStoreError(x);return w?await g.resources.comments.refresh(o,async()=>w).catch(()=>null):g.resources.comments.remove(o),e(f=>({actionErrorByDetail:{...f.actionErrorByDetail,[b]:S}})),{ok:!1,error:S}}},createIssue:async(n,r)=>{try{const l=await r.issueCreate(n.directory,n.repo,{title:n.title,body:n.body,labels:n.labels,assignees:n.assignees});return await pe(r,{directory:n.directory,repo:n.repo,kind:"issues"}),s().dropRemoteForRepo(n.repo),await s().refreshCollections(n.directory,n.repo,"both",r).catch(()=>null),{ok:!0,number:l.issue.number}}catch(l){return{ok:!1,error:g.toStoreError(l)}}},notifyAgentTurnComplete:n=>{const r=Ue((n||"").trim());if(!r)return;const l=s().selectionByDirectory[r];!l?.repo||typeof l.number!="number"||(g.markCollectionsStale(l.repo),Bt(async()=>{const{getRegisteredRuntimeAPIs:a}=await import("./index-DWSrsQWl.js").then(d=>d.cA);return{getRegisteredRuntimeAPIs:a}},__vite__mapDeps([0,1,2,3,4,5,6,7])).then(({getRegisteredRuntimeAPIs:a})=>{const d=a()?.github??null;if(d)return s().refreshDetail(r,l.repo,l.number,d)}).catch(()=>{}))},resetForRuntimeSwitch:()=>{g.resetCore(),e({actionErrorByDetail:{},actingActions:{}})}}),{name:"github-issues-store"}));typeof window<"u"&&zt(()=>{C.getState().resetForRuntimeSwitch()});const xs=e=>g.getLocalIndex(e),ps=(e,s)=>g.getLocalIndex(e).find(n=>n.number===s)??null,Me=(e,s)=>ce(g.resources.collections,e?Ve(e,s):null),ys=(e,s)=>ce(g.resources.remote,e?Qe(e,s):null),vs=(e,s)=>ce(g.resources.details,e!=null&&s!=null?Ce(e,s):null),Cs=(e,s)=>ce(g.resources.comments,e!=null&&s!=null?je(e,s):null),js=(e,s)=>C(n=>!e||!s?ve:n.filtersByScope[It(e,s)]??ve),ws=e=>C(s=>e?s.selectionByDirectory[Ue(e)]??Ie:Ie),ks=e=>typeof e!="number"||e===0?null:t.jsxs("span",{className:"inline-flex shrink-0 items-center gap-0.5 typography-micro tabular-nums text-muted-foreground",title:`${e} comments`,"aria-label":`${e} comments`,children:[t.jsx(R,{name:"chat-1",className:"size-3.5"}),e]}),Ss=({items:e,hasMore:s,isLoadingMore:n,isLoading:r,isRefreshing:l,stale:a,error:d,filters:b,countComplete:o=!0,incompleteNotice:c=null,remote:y=null,numberJump:w=null,onFiltersChange:x,onClearFilters:S,onLoadMore:f,onRetry:p,onOpen:N,onNewIssue:k,headerActionsSlot:T=null,headerActionsPresentation:H="drawer"})=>{const z=b.state==="open"&&b.involvement==="all"&&!b.search.trim()&&!b.labels.trim(),{isMobile:D,isTablet:I}=xt(),B=D||I,G=T!=null,A=H??"drawer",$=G?A==="desktop"?t.jsxs(j,{type:"button",variant:"ghost",size:"sm",onClick:k,"aria-label":"New issue",title:"New issue",children:[t.jsx(R,{name:"add",className:"size-4"}),"New issue"]}):t.jsxs(j,{type:"button",variant:"ghost",size:"default",onClick:k,"aria-label":"New issue",title:"New issue",children:[t.jsx(R,{name:"add",className:"size-4"}),"New issue"]}):t.jsxs(j,{type:"button",variant:"ghost",size:B?"sm":"xs",onClick:k,"aria-label":"New issue",title:"New issue",children:[t.jsx(R,{name:"add",className:"size-3.5"}),"New issue"]}),O=u.useCallback(h=>t.jsx("li",{role:"listitem",children:t.jsx(Pe,{glyph:t.jsx(Ke,{kind:"issue",state:h.state}),number:`#${h.number}`,title:h.title,signals:ks(h.comments),meta:t.jsxs(t.Fragment,{children:[t.jsx(ot,{login:h.author?.login,avatarUrl:h.author?.avatarUrl}),t.jsx(lt,{labels:h.labels??[]})]}),updatedAt:h.updatedAt,onOpen:()=>N(h.number),ariaLabel:`Open issue #${h.number} ${h.title}`})},h.number),[N]);return t.jsx(it,{items:e,renderRow:O,hasMore:s,isLoadingMore:n,isLoading:r,isRefreshing:l,stale:a,error:d,searchValue:b.search,onSearchChange:h=>x({search:h}),searchPlaceholder:"Search issues, or label:bug",searchAriaLabel:"Search issues",toolbarControls:t.jsx(ct,{stateValue:b.state,stateOptions:He.map(h=>({id:h.id,label:h.label})),onStateChange:h=>x({state:h}),involvementValue:b.involvement,involvementOptions:es.map(h=>({id:h.id,label:h.label})),onInvolvementChange:h=>x({involvement:h}),labelsValue:b.labels,onLabelsChange:h=>x({labels:h}),sortValue:b.sort,sortOptions:Xt.map(h=>({id:h.id,label:h.label})),onSortChange:h=>x({sort:h}),sortAriaLabel:"Sort issues"}),primaryAction:$,headerActionsSlot:T,headerActionsPresentation:A,isDefaultFilters:z,stateLabel:He.find(h=>h.id===b.state)?.label??b.state,kindSingular:"issue",kindPlural:"issues",noItemsTitle:b.state==="open"?"No open issues":"No issues yet",noItemsBody:"Issues for this repository appear here.",noItemsIcon:"inbox-archive",noItemsAction:t.jsxs(j,{type:"button",variant:"outline",size:"sm",onClick:k,children:[t.jsx(R,{name:"add",className:"size-3.5"}),"New issue"]}),listAriaLabel:"Issues",skeletonLabel:"Loading issues",updatedAtOf:h=>h.updatedAt,countComplete:o,incompleteNotice:c,remote:y,numberJump:w,numberJumpKind:"issue",onClearFilters:S,onLoadMore:f,onRetry:p,onOpen:N})},Je=(e,s,n)=>{const[r,l]=u.useState([]),[a,d]=u.useState([]),[b,o]=u.useState(!1);return u.useEffect(()=>{if(!n)return;let c=!1;return o(!0),n.repoMeta(e,s).then(y=>{c||(l(y.labels??[]),d(y.assignees??[]))}).catch(()=>{c||(l([]),d([]))}).finally(()=>{c||o(!1)}),()=>{c=!0}},[n,e,s]),{labels:r,assignees:a,loading:b}},Ye=(e,s)=>e.includes(s)?e.filter(n=>n!==s):[...e,s],Ze=({candidates:e,loading:s,selected:n,onChange:r})=>s?t.jsx("p",{className:"typography-micro text-muted-foreground",children:"Loading labels…"}):e.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground",children:"No labels in this repository."}):t.jsx("div",{className:"flex flex-wrap gap-1",children:e.map(l=>{const a=n.includes(l.name);return t.jsx(j,{type:"button",variant:"chip",size:"xs","aria-pressed":a,onClick:()=>r(Ye(n,l.name)),children:l.name},l.name)})}),Xe=({candidates:e,loading:s,selected:n,onChange:r})=>s?t.jsx("p",{className:"typography-micro text-muted-foreground",children:"Loading assignees…"}):e.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground",children:"No assignable users found."}):t.jsx("div",{className:"flex flex-wrap gap-1",children:e.map(l=>{const a=l.login,d=a?n.includes(a):!1;return t.jsx(j,{type:"button",variant:"chip",size:"xs","aria-pressed":d,onClick:()=>{a&&r(Ye(n,a))},children:a},a)})}),Ns=({open:e,onOpenChange:s,issueNumber:n,issueTitle:r,busy:l,onChoose:a})=>{const[d,b]=u.useState("worktree"),o=qe(n,r);return t.jsx(pt,{open:e,onOpenChange:s,children:t.jsxs(yt,{className:"max-w-md w-[calc(100vw-2rem)]",children:[t.jsxs(vt,{children:[t.jsxs(Ct,{children:["Start session from issue #",n]}),t.jsx(jt,{children:"Choose where the new session works. The composer is pre-filled — nothing is sent automatically."})]}),t.jsxs("div",{className:"flex flex-col gap-1",role:"radiogroup","aria-label":"Session location",children:[t.jsxs("button",{type:"button",role:"radio","aria-checked":d==="current",onClick:()=>b("current"),className:"flex items-start gap-2 rounded-md border border-border px-3 py-2 text-left hover:bg-interactive-hover",children:[t.jsx(R,{name:d==="current"?"record-circle":"checkbox-blank-circle-fill",className:"mt-0.5 size-4 shrink-0 text-muted-foreground"}),t.jsxs("span",{className:"min-w-0",children:[t.jsx("span",{className:"block typography-ui-label text-foreground",children:"Current checkout"}),t.jsx("span",{className:"block typography-micro text-muted-foreground",children:"Work directly where you are now."})]})]}),t.jsxs("button",{type:"button",role:"radio","aria-checked":d==="worktree",onClick:()=>b("worktree"),className:"flex items-start gap-2 rounded-md border border-border px-3 py-2 text-left hover:bg-interactive-hover",children:[t.jsx(R,{name:d==="worktree"?"record-circle":"checkbox-blank-circle-fill",className:"mt-0.5 size-4 shrink-0 text-muted-foreground"}),t.jsxs("span",{className:"min-w-0",children:[t.jsx("span",{className:"block typography-ui-label text-foreground",children:"New worktree"}),t.jsxs("span",{className:"block truncate font-mono typography-micro text-muted-foreground",title:o,children:["Branch ",o]})]})]})]}),t.jsxs(wt,{children:[t.jsx(j,{type:"button",variant:"outline",size:"sm",onClick:()=>s(!1),disabled:l,children:"Cancel"}),t.jsx(j,{type:"button",variant:"default",size:"sm",onClick:()=>a(d),disabled:l,"aria-label":d==="worktree"?"Create worktree and open session draft":"Open session draft in current checkout",children:l?"Working…":d==="worktree"?"Create worktree":"Open draft"})]})]})})},ze=e=>{const s=as(e.title);return e.kind==="pr"?`pr-${e.number}-${s}`:qe(e.number,e.title)},Rs=async(e,s)=>{const{github:n,git:r,openDraft:l,refreshWorktrees:a}=s;if(!l)return{ok:!1,error:"Sessions are not available in this runtime"};let d;try{d=(await n.agentContext(e.directory,e.repo,e.kind==="pr"?"pr":"issue",e.number)).text}catch(p){return{ok:!1,error:p instanceof Error?p.message:"Failed to load issue context"}}const o=`${e.kind==="pr"?"PR":"Issue"} #${e.number}: ${e.title.trim()||"(untitled)"}`,c=e.kind==="pr"?`Work on this GitHub pull request. Read the quoted context below, then propose a plan and wait for confirmation before changing code.
3
3
 
4
4
  PR #${e.number}: ${e.title}
5
5
  ${e.url}
@@ -1 +1 @@
1
- import{ci as H,dE as Z,dF as Fe,dG as Ce,dH as ke,dI as Ie,dJ as ze,dz as Ne,dK as Oe,B as ee,I as te,dL as Ve}from"./useAppFontEffects-Bfw_d5eB.js";import{a as ie,s as Pe,b as Se,c as ne,d as ve,g as Be,e as re,f as I,h as De,i as Ue,j as _e,k as We,R as Ge,I as je,p as se,l as $e,m as Ke,n as qe,o as Je,w as Ye,q as ae,u as Xe,r as Qe,t as Ze,v as et,x as oe,S as tt,y as it,z as nt,A as rt,B as ye,C as he,F as st}from"./web-components-CeHLxvED.js";import{G as at,u as ot,W as ht,a as lt,b as dt,n as le,t as ct}from"./Virtualizer-DP6HbEeC.js";import{k as C}from"./vendor-boot-EC6IyLt1.js";import{o as ut,i as j,f as A,a as ft,q as de,s as pt,t as ce,d as gt,u as ue,b as mt,w as B,x as fe}from"./computeVirtualFileMetrics-BI6wORhM.js";import{a as F,i as q,l as pe,h as Ct,r as St}from"./renderFileWithHighlighter-KiEWMtzI.js";import{t as M}from"./vendor-hast-util-to-html-BKBhbTDb.js";import{a as k,R as L}from"./vendor-react-DASdDPIk.js";let vt=-1;var yt=class{options;onRenderUpdate;workerManager;__id=`file-renderer:${++vt}`;highlighter;renderCache;computedLang="text";lineAnnotations={};lineCache;textDoucmentCache=new WeakMap;constructor(i={theme:H},e,t){this.options=i,this.onRenderUpdate=e,this.workerManager=t,t?.isWorkingPool()!==!0&&(this.highlighter=ie(i.theme??H)?ut():void 0)}setOptions(i){this.options=i}mergeOptions(i){this.options={...this.options,...i}}setLineAnnotations(i){this.lineAnnotations={};for(const e of i){const t=this.lineAnnotations[e.lineNumber]??[];this.lineAnnotations[e.lineNumber]=t,t.push(e)}}cleanUp(){this.recycle(),this.workerManager=void 0,this.onRenderUpdate=void 0}recycle(){this.clearRenderCache(),this.highlighter=void 0,this.workerManager?.cleanUpTasks(this),this.lineCache=void 0}clearRenderCache(){const i=this.renderCache;this.renderCache=void 0,i!=null&&i.isDirty===!0&&i.file.cacheKey!=null&&this.workerManager?.evictFileFromCache(i.file.cacheKey)}hydrate(i){const{options:e}=this.getRenderOptions(i),t=$(this.getOrCreateLineCache(i).length,this.getTokenizeMaxLength());let n=this.workerManager?.getFileResultCache(i);n!=null&&!F(e,n.options)&&(n=void 0),this.renderCache??={file:i,options:e,highlighted:!t&&!q(i),result:t?void 0:n?.result,renderRange:void 0},this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!t&&this.workerManager.highlightFileAST(this,i):this.highlighter==null&&(this.computedLang=i.lang??j(i.name),this.initializeHighlighter())}getRenderOptions(i){const e=(()=>{if(this.workerManager?.isWorkingPool()===!0)return this.workerManager.getFileRenderOptions();const{theme:n=H,tokenizeMaxLineLength:r=1e3}=this.options;return{theme:n,useTokenTransformer:Pe(this.options),tokenizeMaxLineLength:r}})(),{renderCache:t}=this;return t?.result==null?{options:e,forceHighlight:!0}:!A(i,t.file)||!F(e,t.options)?{options:e,forceHighlight:!0}:{options:e,forceHighlight:!1}}getOrCreateLineCache(i){if(i.cacheKey==null)return this.lineCache=void 0,pe(i.contents);let{lineCache:e}=this;return(e==null||e.cacheKey!==i.cacheKey)&&(e={cacheKey:i.cacheKey,lines:pe(i.contents)}),this.lineCache=e,e.lines}getLineCount(i){return this.textDoucmentCache.get(i)?.lineCount??this.getOrCreateLineCache(i).length}updateRenderCache(i,e){if(this.renderCache==null)return;const{result:t}=this.renderCache;if(t!=null){for(const[n,r]of i)t.code[n]={type:"element",tagName:"div",properties:{"data-line":n+1,"data-line-type":"context","data-line-index":n},children:r.map(([s,a,o])=>s===0&&a===""?o===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:o}:{type:"element",tagName:"span",properties:{"data-char":s,style:`--diffs-token-${e}:${a};`},children:[{type:"text",value:o}]})};t.baseThemeType=e,this.renderCache.isDirty=!0}}applyDocumentChange(i){if(this.renderCache==null)return;const{file:e,result:t}=this.renderCache;if(t!=null&&t.code.length!==i.lineCount){t.code.length=Math.min(t.code.length,i.lineCount);for(let n=t.code.length;n<i.lineCount;n++)t.code.push({type:"element",tagName:"div",properties:{"data-line":n+1,"data-line-type":"context","data-line-index":n},children:[{type:"element",tagName:"span",properties:{"data-char":0},children:[{type:"text",value:i.getLineText(n)}]}]});this.renderCache.isDirty=!0}this.textDoucmentCache.set(e,i)}renderFile(i=this.renderCache?.file,e=Z){if(i==null)return;let{options:t,forceHighlight:n}=this.getRenderOptions(i);const r=this.getMatchingWorkerResultCache(i,t);r!=null&&!this.hasHighlightedRenderCache(i,t)&&(this.renderCache={file:i,highlighted:!0,renderRange:void 0,...r},n=!1),this.renderCache??={file:i,highlighted:!1,options:t,result:void 0,renderRange:void 0};const s=this.getOrCreateLineCache(i),a=i.contents.length>0,o=!a||q(i)||$(s.length,this.getTokenizeMaxLength()),h=!A(i,this.renderCache.file),d=!Se(this.renderCache.renderRange,e);if(this.workerManager?.isWorkingPool()===!0)(o||this.renderCache.result==null||!this.renderCache.highlighted&&(h||d))&&(this.renderCache.file=i,this.renderCache.options=t,this.renderCache.highlighted=!1,(this.renderCache.result==null||h||d||n)&&(this.renderCache.result=this.workerManager.getPlainFileAST(i,e.startingLine,e.totalLines,s)),this.renderCache.renderRange=e),!o&&a&&(!this.renderCache.highlighted||n)&&this.workerManager.highlightFileAST(this,i);else{this.computedLang=i.lang??j(i.name);const l=this.highlighter!=null&&ie(t.theme),c=this.highlighter!=null&&ne(this.computedLang),u=!o&&c;if(this.highlighter!=null&&l&&(n||o||!this.renderCache.highlighted&&u||this.renderCache.result==null)){const{result:p,options:f}=this.renderFileWithHighlighter(i,this.highlighter,o||!c);this.renderCache={file:i,options:f,highlighted:u,result:p,renderRange:void 0}}(!l||!o&&!c)&&this.asyncHighlight(i).then(({result:p,options:f})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.onHighlightSuccess(i,p,f,!o)})}return this.renderCache.result!=null?this.processFileResult(this.renderCache.file,e,this.renderCache.result):void 0}async asyncRender(i,e=Z){const{result:t}=await this.asyncHighlight(i);return this.processFileResult(i,e,t)}async asyncHighlight(i){const e=$(this.getOrCreateLineCache(i).length,this.getTokenizeMaxLength());this.computedLang=e?"text":i.lang??j(i.name);const t=this.highlighter!=null&&Ct(ft(this.options.theme)),n=e||this.highlighter!=null&&ne(this.computedLang);return(this.highlighter==null||!t||!n)&&(this.highlighter=await this.initializeHighlighter()),this.renderFileWithHighlighter(i,this.highlighter,e)}renderFileWithHighlighter(i,e,t=!1){const{options:n}=this.getRenderOptions(i);return{result:St(i,e,n,{forcePlainText:t}),options:n}}processFileResult(i,e,{code:t,themeStyles:n,baseThemeType:r}){const s=this.getLineCount(i),{disableFileHeader:a=!1}=this.options,o=[],h=ue(),d=Math.min(e.startingLine+e.totalLines,s);let l=0;const c=ve(e)?Be(this.lineAnnotations):void 0;c!=null&&(h.children.push(de("context","annotation",1)),o.push(re({hunkIndex:-1,lineIndex:-1,annotations:c.map(u=>I(u))})),l++);for(let u=e.startingLine;u<d;u++){const p=u+1,f=t[u];if(f==null){const g="FileRenderer.processFileResult: Line doesnt exist";throw console.error(g,{name:i.name,lineIndex:u,lineNumber:p}),new Error(g)}h.children.push(pt("context",p,`${u}`)),o.push(f),l++;const S=this.lineAnnotations[p];S!=null&&(h.children.push(de("context","annotation",1)),o.push(re({hunkIndex:0,lineIndex:p,annotations:S.map(g=>I(g))})),l++)}return h.properties.style=`grid-row: span ${l}`,{gutterAST:h.children??[],contentAST:o,preAST:this.createPreElement(s),headerAST:a?void 0:this.renderHeader(i),totalLines:s,rowCount:l,themeStyles:n,baseThemeType:r,bufferBefore:e.bufferBefore,bufferAfter:e.bufferAfter,css:""}}renderHeader(i){const{headerRenderMode:e="default",stickyHeader:t=!1}=this.options;return De({fileOrDiff:i,mode:e,stickyHeader:t})}renderFullHTML(i){return M(this.renderFullAST(i))}renderFullAST(i,e=[]){return e.push(ce({tagName:"code",children:this.renderCodeAST(i),properties:{"data-code":""}})),{...i.preAST,children:e}}renderCodeAST(i){const e=ue();return e.children=i.gutterAST,e.properties.style=`grid-row: span ${i.rowCount}`,[e,Ue(i.contentAST,i.rowCount)]}renderPartialHTML(i,e=!1){return e?M(ce({tagName:"code",children:i,properties:{"data-code":""}})):M(i)}async initializeHighlighter(){return this.highlighter=await gt(_e(this.computedLang,this.options)),this.highlighter}onHighlightSuccess(i,e,t,n=!0){if(this.renderCache==null)return;const r=!A(i,this.renderCache.file)||!this.renderCache.highlighted||!F(t,this.renderCache.options);this.renderCache={file:i,options:t,highlighted:n,result:e,renderRange:void 0},r&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(i,e){const t=this.workerManager?.getFileResultCache(i);if(!(t==null||!F(e,t.options)))return t}hasHighlightedRenderCache(i,e){const{renderCache:t}=this;return t?.result!=null&&t.highlighted&&A(i,t.file)&&F(e,t.options)}onHighlightError(i){console.error(i)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}createPreElement(i){const{disableLineNumbers:e=!1,overflow:t="scroll"}=this.options;return We({type:"file",diffIndicators:"none",disableBackground:!0,disableLineNumbers:e,overflow:t,split:!1,totalLines:i})}};function $(i,e){return i>e}function Tt(i,e){return i.lineNumber===e.lineNumber&&i.metadata===e.metadata}function ge(i){return{theme:i?.theme,disableLineNumbers:i?.disableLineNumbers,overflow:i?.overflow,themeType:i?.themeType,collapsed:i?.collapsed,disableFileHeader:i?.disableFileHeader,disableVirtualizationBuffers:i?.disableVirtualizationBuffers,stickyHeader:i?.stickyHeader,preferredHighlighter:i?.preferredHighlighter,useCSSClasses:i?.useCSSClasses,useTokenTransformer:i?.useTokenTransformer,tokenizeMaxLineLength:i?.tokenizeMaxLineLength,tokenizeMaxLength:i?.tokenizeMaxLength,unsafeCSS:i?.unsafeCSS,headerRenderMode:i?.renderCustomHeader!=null?"custom":"default"}}const bt=[""];let Rt=-1;var Te=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file:${++Rt}`;type="file";fileContainer;spriteSVG;pre;code;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;errorWrapper;placeHolder;lastRenderedHeaderHTML;cachedHeaderHTML;appliedPreAttributes;lastRowCount;mounted=!1;headerElement;headerCustom;headerPrefix;headerFilenameSuffix;headerMetadata;fileRenderer;resizeManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;file;renderRange;enabled=!0;editor;constructor(e={theme:H},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.fileRenderer=new yt(e,this.handleHighlightRender,this.workerManager),this.resizeManager=new Ge,this.interactionManager=new je("file",se(e)),this.workerManager?.subscribeToThemeChanges(this)}handleHighlightRender=()=>{this.rerender()};rerender(){!this.enabled||this.file==null||this.render({file:this.file,forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.fileRenderer.clearRenderCache(),this.rerender()}setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(se(this.options))}mergeOptions(e){this.options={...this.options,...e}}setThemeType(e){(this.options.themeType??"system")!==e&&(this.mergeOptions({themeType:e}),this.applyCachedThemeState(e))}applyCachedThemeState(e){if(typeof this.options.theme=="string"||this.fileContainer==null||this.appliedThemeCSS==null)return!1;const t=this.appliedThemeCSS.baseThemeType??e;return this.appliedThemeCSS.themeType===t?!1:(this.applyThemeState(this.fileContainer,this.appliedThemeCSS.themeStyles,e,this.appliedThemeCSS.baseThemeType),!0)}hasThemeChanged(){return this.appliedThemeCSS!=null&&!mt(this.appliedThemeCSS.theme,this.options.theme??H)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}setSelectedLines(e,t){this.interactionManager.setSelection(e,t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}const{overflow:e="scroll"}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,e==="wrap"),this.managersDirty=!1}cleanUp(e=!1){this.emitPostRender(!0),this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.annotationCache.clear(),this.pre=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.placeHolder=void 0,this.unsafeCSSStyle=void 0,e?this.fileRenderer.recycle():(this.fileRenderer.cleanUp(),this.workerManager=void 0,this.file=void 0),this.enabled=!1,this.editor?.cleanUp(),this.editor=void 0}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate(e){const{fileContainer:t,prerenderedHTML:n,preventEmit:r=!1,file:s,lineAnnotations:a}=e;this.hydrateElements(t,n),Lt(this.pre,s,this.options.collapsed)||At(this.headerElement,s,this.options.disableFileHeader)?this.render({...e,preventEmit:!0}):this.hydrationSetup({file:s,lineAnnotations:a}),r||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),$e(e,t);for(const n of Array.from(e.shadowRoot?.children??[])){if(n instanceof SVGElement){this.spriteSVG=n;continue}if(n instanceof HTMLElement){if(n instanceof HTMLPreElement){this.pre=n,this.appliedPreAttributes=void 0;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-theme-css")){this.themeCSSStyle=n;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-unsafe-css")){this.unsafeCSSStyle=n,this.appliedUnsafeCSS=n.textContent;continue}if("diffsHeader"in n.dataset){this.headerElement=n,this.lastRenderedHeaderHTML=void 0;continue}}}this.pre!=null&&(this.syncCodeNodeFromPre(this.pre),this.pre.removeAttribute("data-dehydrated")),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({file:e,lineAnnotations:t}){this.lineAnnotations=t??this.lineAnnotations,this.file=e,this.fileRenderer.setOptions(ge(this.options)),this.syncInteractionOptions(),this.pre!=null&&(this.fileRenderer.hydrate(e),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}getOrCreateLineCache(e=this.file){return e!=null?this.fileRenderer.getOrCreateLineCache(e):bt}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}syncRenderViewToEditor(){const e=this.editor,t=this.fileContainer,n=this.file;e!=null&&t!=null&&n!=null&&this.fileRenderer.initializeHighlighter().then(r=>{e.__syncRenderView(r,t,n,this.lineAnnotations,this.renderRange)})}attachEditor(e){return this.editor?.cleanUp(),this.editor=e,this.interactionManager.setEditorAttached(!0),this.syncRenderViewToEditor(),()=>{this.editor=void 0,this.interactionManager.setEditorAttached(!1)}}applyDocumentChange(e,t){this.fileRenderer.applyDocumentChange(e),t!=null&&t!==this.lineAnnotations&&this.file!=null&&(this.setLineAnnotations(t),this.fileRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations())}updateRenderCache(e,t){this.fileRenderer.updateRenderCache(e,t)}render({file:e,fileContainer:t,forceRender:n=!1,preventEmit:r=!1,containerWrapper:s,deferManagers:a=!1,lineAnnotations:o,renderRange:h}){if(!this.enabled)throw new Error("File.render: attempting to call render after cleaned up");this.editor?.__postponeBackgroundTokenizeToNextFrame();const{collapsed:d=!1,themeType:l="system"}=this.options,c=d?void 0:h,u=this.renderRange,p=this.hasThemeChanged(),f=o!=null&&(o.length>0||this.lineAnnotations.length>0)?o!==this.lineAnnotations:!1,S=!A(this.file,e);if(!d&&!n&&Se(c,this.renderRange)&&!S&&!f&&!p)return this.applyCachedThemeState(l);this.renderRange=c,S&&(this.cachedHeaderHTML=void 0),this.file=e,this.fileRenderer.setOptions(ge(this.options)),this.syncInteractionOptions(),o!=null&&this.setLineAnnotations(o),this.fileRenderer.setLineAnnotations(this.lineAnnotations);const{disableErrorHandling:g=!1,disableFileHeader:y=!1}=this.options;if(y&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),t=this.getOrCreateFileContainerNode(t,s),this.applyCachedThemeState(l),d){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const m=this.fileRenderer.renderFile(e,Fe);m!=null&&this.applyThemeState(t,m.themeStyles,l,m.baseThemeType),m?.headerAST!=null&&this.applyHeaderToDOM(m.headerAST,t),this.injectUnsafeCSS()}catch(m){if(g)throw m;console.error(m),m instanceof Error&&this.applyErrorToDOM(m,t)}return r||this.emitPostRender(),!0}try{const m=this.getOrCreatePreNode(t);if(!this.canPartiallyRender(n,f,S||p)||!this.applyPartialRender(u,c)){const v=this.fileRenderer.renderFile(e,c);if(v==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(t,v.themeStyles,l,v.baseThemeType),v.headerAST!=null&&this.applyHeaderToDOM(v.headerAST,t),this.applyFullRender(v,m)}this.applyBuffers(m,c),this.injectUnsafeCSS(),this.managersDirty=!0,a||this.flushManagers(),this.renderAnnotations(),this.renderGutterUtility(),this.editor!=null&&this.syncRenderViewToEditor()}catch(m){if(g)throw m;console.error(m),m instanceof Error&&this.applyErrorToDOM(m,t)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){const{fileContainer:t,options:{onPostRender:n}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;n?.(t,this,"unmount");return}if(t==null)return;const r=this.mounted?"update":"mount";this.mounted=!0,n?.(t,this,r)}removeRenderedCode(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.code?.remove(),this.code=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(const{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}canPartiallyRender(e,t,n){return!(e||t||n)}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){const t=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:"open"});this.placeHolder=document.createElement("div"),this.placeHolder.dataset.placeholder="",t.appendChild(this.placeHolder)}return this.placeHolder.style.setProperty("height",`${e}px`),!0}primeHighlightCache(){const{file:e,workerManager:t}=this;e==null||e.cacheKey==null||t==null||q(e)||this.fileRenderer.getOrCreateLineCache(e).length>(this.options.tokenizeMaxLength??1e5)||t.primeFileHighlightCache(e)}cleanChildNodes(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.code?.remove(),this.errorWrapper?.remove(),this.headerElement?.remove(),this.gutterUtilityContent?.remove(),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.pre?.remove(),this.spriteSVG?.remove(),this.themeCSSStyle?.remove(),this.unsafeCSSStyle?.remove(),this.bufferAfter=void 0,this.bufferBefore=void 0,this.code=void 0,this.errorWrapper=void 0,this.headerElement=void 0,this.gutterUtilityContent=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.pre=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.lastRenderedHeaderHTML=void 0,this.lastRowCount=void 0,this.mounted=!1}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(const{element:n}of this.annotationCache.values())n.remove();this.annotationCache.clear();return}const e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(const[n,r]of this.lineAnnotations.entries()){const s=`${n}-${I(r)}`;let a=this.annotationCache.get(s);if(a==null||!Tt(r,a.annotation)){a?.element.remove();const o=t(r);if(o==null)continue;a={element:Ke(I(r)),annotation:r},a.element.appendChild(o),this.fileContainer.appendChild(a.element),this.annotationCache.set(s,a)}e.delete(s)}for(const[n,{element:r}]of e.entries())this.annotationCache.delete(n),r.remove()}renderGutterUtility(){const{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const n=qe();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}injectUnsafeCSS(){const{unsafeCSS:e}=this.options,t=this.fileContainer?.shadowRoot;if(t!=null){if(e==null||e===""){this.unsafeCSSStyle!=null&&(this.unsafeCSSStyle.remove(),this.unsafeCSSStyle=void 0),this.appliedUnsafeCSS=void 0;return}this.unsafeCSSStyle?.parentNode===t&&this.appliedUnsafeCSS===e||(this.unsafeCSSStyle??=Je(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=Ye(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,r){const s=e.shadowRoot??e.attachShadow({mode:"open"}),a=r??n,o=this.options.theme??H,h=typeof o=="string"?o:{...o},d=ae(s);if(this.themeCSSStyle?.parentNode===s&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===a&&this.appliedThemeCSS.scrollbarGutter===d){this.appliedThemeCSS.theme=h;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===s){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:h,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:d};return}this.themeCSSStyle=Xe({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:Qe(t,a,d)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:h,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:d}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=Ze(this.themeCSSStyle.textContent??"",ae(e)))}applyFullRender(e,t){this.cleanupErrorWrapper(),this.applyPreNodeAttributes(t,e),this.code=et({code:this.code});const n=this.fileRenderer.renderCodeAST(e);if(this.code.childElementCount>=2)for(let r=0;r<2;r++){const s=this.code.children[r],a=n[r];s.innerHTML=M(a.children),s.style.cssText=a.properties.style}else this.code.innerHTML=M(n);t.contains(this.code)||t.replaceChildren(this.code),this.lastRowCount=e.rowCount}applyPartialRender(e,t){if(e==null||t==null)return!1;const{file:n,code:r}=this,s=r!=null?this.getColumns(r):void 0;if(n==null||r==null||s==null)return!1;const a=e.startingLine,o=t.startingLine,h=e.totalLines===1/0?Number.POSITIVE_INFINITY:a+e.totalLines,d=t.totalLines===1/0?Number.POSITIVE_INFINITY:o+t.totalLines,l=Math.max(a,o),c=Math.min(h,d);if(c<=l||!this.trimDOMToOverlap(s.gutter,l,c)||!this.trimDOMToOverlap(s.content,l,c))return!1;let{length:u}=s.content.children;const p=(y,m)=>{if(!(m<=0))return this.fileRenderer.renderFile(n,{startingLine:y,totalLines:m,bufferBefore:0,bufferAfter:0})},f=o<l?p(o,l-o):void 0;if(f===void 0&&o<l)return!1;const S=d===Number.POSITIVE_INFINITY?Number.POSITIVE_INFINITY:Math.max(0,d-c),g=d>c?p(c,S):void 0;return g===void 0&&d>c?!1:(this.cleanupErrorWrapper(),f!=null&&(s.gutter.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(f.gutterAST)),s.content.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(f.contentAST)),u+=f.rowCount),g!=null&&(s.gutter.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(g.gutterAST)),s.content.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(g.contentAST)),u+=g.rowCount),this.lastRowCount!==u&&(s.gutter.style.setProperty("grid-row",`span ${u}`),s.content.style.setProperty("grid-row",`span ${u}`),this.lastRowCount=u),!0)}getColumns(e){const t=e.children[0],n=e.children[1];if(!(!(t instanceof HTMLElement)||!(n instanceof HTMLElement)||t.dataset.gutter==null||n.dataset.content==null))return{gutter:t,content:n}}trimDOMToOverlap(e,t,n){const r=this.getDOMBoundaryIndices(e,[t,n]),s=r.get(t)??e.children.length,a=r.get(n)??e.children.length;if(s>a)return!1;for(let o=e.children.length-1;o>=a;o-=1)e.children[o]?.remove();for(let o=s-1;o>=0;o-=1)e.children[o]?.remove();return!0}getDOMBoundaryIndices(e,t){const n=[...new Set(t)].sort((h,d)=>h-d),r=new Map;if(n.length===0)return r;let s=0,a=n[s];const{children:o}=e;a===0&&(r.set(0,0),s+=1,a=n[s]);for(let h=0;h<o.length;h+=1){const d=o[h];if(!(d instanceof HTMLElement))continue;const l=this.getLineIndexFromDOMNode(d);if(l!=null){for(;a!=null&&l>=a;)r.set(a,h),s+=1,a=n[s];if(s>=n.length)break}}for(const h of n)r.has(h)||r.set(h,o.length);return r}getLineIndexFromDOMNode(e){const t=e.dataset.lineIndex;if(t==null)return;const n=Number(t);return Number.isNaN(n)?void 0:n}applyBuffers(e,t){if(t==null||this.shouldDisableVirtualizationBuffers()){this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0);return}t.bufferBefore>0?(this.bufferBefore==null&&(this.bufferBefore=document.createElement("div"),this.bufferBefore.dataset.virtualizerBuffer="before",e.before(this.bufferBefore)),this.bufferBefore.style.setProperty("height",`${t.bufferBefore}px`),this.bufferBefore.style.setProperty("contain","strict")):this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),t.bufferAfter>0?(this.bufferAfter==null&&(this.bufferAfter=document.createElement("div"),this.bufferAfter.dataset.virtualizerBuffer="after",e.after(this.bufferAfter)),this.bufferAfter.style.setProperty("height",`${t.bufferAfter}px`),this.bufferAfter.style.setProperty("contain","strict")):this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0)}shouldDisableVirtualizationBuffers(){return this.options.disableVirtualizationBuffers??!1}applyHeaderToDOM(e,t){const{file:n}=this;if(n==null)return;this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;const r=this.cachedHeaderHTML??M(e);if(this.cachedHeaderHTML=r,r!==this.lastRenderedHeaderHTML){const d=document.createElement("div");d.innerHTML=r;const l=d.firstElementChild;if(!(l instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(l,this.headerElement):t.shadowRoot?.prepend(l),this.headerElement=l,this.lastRenderedHeaderHTML=r}if(this.isContainerManaged)return;const{renderHeaderPrefix:s,renderHeaderFilenameSuffix:a,renderCustomHeader:o,renderHeaderMetadata:h}=this.options;if(o!=null){const d=o(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,Ce,d),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0}else{const d=s?.(n)??void 0,l=a?.(n)??void 0,c=h?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,ke,d),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Ie,l),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,ze,c),this.headerCustom?.remove(),this.headerCustom=void 0}}clearHeaderSlots(){this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0}upsertHeaderSlotElement(e,t,n,r){if(r==null){t?.remove();return}const s=t??this.createHeaderSlotElement(n);return t==null&&e.appendChild(s),this.replaceHeaderSlotContent(s,r),s}replaceHeaderSlotContent(e,t){e.replaceChildren(),t instanceof Element?e.appendChild(t):e.innerText=`${t}`}createHeaderSlotElement(e){const t=document.createElement("div");return t.slot=e,t}getOrCreateFileContainerNode(e,t){const{fileContainer:n}=this,r=e??n??document.createElement("diffs-container"),s=n!==r;return s&&this.emitPostRender(!0),this.fileContainer=r,n!=null&&s&&(this.lastRenderedHeaderHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),s&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){const{shadowRoot:t}=e;if(t!=null)for(const n of t.children)n instanceof SVGElement?this.spriteSVG??=n:oe(n)&&n.hasAttribute("data-theme-css")?(this.themeCSSStyle??=n,this.hasAdoptedThemeCSS=!0):oe(n)&&n.hasAttribute("data-unsafe-css")&&(this.unsafeCSSStyle??=n,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});if(this.spriteSVG==null){const n=document.createElement("div");n.innerHTML=tt;const r=n.firstChild;r instanceof SVGElement&&(this.spriteSVG=r)}this.spriteSVG!=null&&this.spriteSVG.parentNode!==t&&t.appendChild(this.spriteSVG)}getOrCreatePreNode(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});return this.pre==null?(this.pre=document.createElement("pre"),this.appliedPreAttributes=void 0,this.code=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(e.shadowRoot?.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodeFromPre(e){this.code=void 0;for(const t of Array.from(e.children))if(t instanceof HTMLElement&&t.hasAttribute("data-code")){this.code=t;return}}applyPreNodeAttributes(e,{totalLines:t}){const{overflow:n="scroll",disableLineNumbers:r=!1}=this.options,s={type:"file",split:!1,overflow:n,disableLineNumbers:r,diffIndicators:"none",disableBackground:!0,totalLines:t};it(s,this.appliedPreAttributes)||(nt(e,s),this.appliedPreAttributes=s)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;const n=t.shadowRoot??t.attachShadow({mode:"open"});this.errorWrapper??=document.createElement("div"),this.errorWrapper.dataset.errorWrapper="",this.errorWrapper.textContent="",n.appendChild(this.errorWrapper);const r=document.createElement("div");r.dataset.errorMessage="",r.innerText=e.message,this.errorWrapper.appendChild(r);const s=document.createElement("pre");s.dataset.errorStack="",s.innerText=e.stack??"No Error Stack",this.errorWrapper.appendChild(s)}cleanupErrorWrapper(){this.errorWrapper?.remove(),this.errorWrapper=void 0}};function Lt(i,e,t=!1){return!t&&i==null&&e!=null}function At(i,e,t=!1){return i==null&&e!=null&&!t}const Ht=5e3;let Mt=-1;function xt(i,e){return(i.overflow??"scroll")!==(e.overflow??"scroll")||(i.collapsed??!1)!==(e.collapsed??!1)||(i.disableLineNumbers??!1)!==(e.disableLineNumbers??!1)||(i.disableFileHeader??!1)!==(e.disableFileHeader??!1)||i.unsafeCSS!==e.unsafeCSS}var wt=class extends Te{virtualizer;metrics;__id=`virtualized-file:${++Mt}`;top;height=0;cache={heights:new Map,checkpoints:[],fileAnnotationHeight:0};isVisible=!1;isSetup=!1;layoutDirty=!0;forceRenderOverride;currentCollapsed;constructor(i,e,t=Ne,n,r=!1){super(i,n,r),this.virtualizer=e,this.metrics=t}setMetrics(i,e=!1){!e&&rt(this.metrics,i)||(this.metrics=i,this.resetLayoutCache())}setLineAnnotations(i){this.syncLineAnnotations(i)&&this.resetLayoutCache()}syncLineAnnotations(i){return i==null||i===this.lineAnnotations||i.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(i),!0)}hasLineAnnotations(){return this.lineAnnotations.some(i=>i.lineNumber>0)}getLineHeight(i,e=!1){const t=this.cache.heights.get(i);if(t!=null)return t;const n=e?2:1;return this.metrics.lineHeight*n}setOptions(i){if(this.isAdvancedMode())throw new Error("VirtualizedFile.setOptions cannot be used inside CodeView. Update CodeView options instead.");if(i==null)return;const{options:e}=this,t=!ye(e,i),n=xt(e,i);super.setOptions(i),n&&this.resetLayoutCache(!0),t&&(this.forceRenderOverride=!0),t&&this.virtualizer.instanceChanged(this,n)}setThemeType(i){if(this.isAdvancedMode())throw new Error("VirtualizedFile.setThemeType cannot be used inside CodeView. Update CodeView options instead.");super.setThemeType(i)}resetLayoutCache(i=!1){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heights.size>0&&this.cache.heights.clear(),this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.renderRange!=null&&(this.renderRange=void 0),i&&this.isSimpleMode()&&this.computeApproximateSize()}reconcileHeights(){let i=!1;if(this.fileContainer==null||this.file==null)return this.height!==0&&(i=!0),this.height=0,i;const{overflow:e="scroll"}=this.options;if(this.top=this.getVirtualizedTop(),e==="scroll"&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled()||this.code==null)return i;const t=this.code.children[1];if(!(t instanceof HTMLElement))return i;const n=he(this.lineAnnotations);if(this.renderRange!=null&&n&&ve(this.renderRange)){const r=Et(t)??0;r!==this.cache.fileAnnotationHeight&&(this.cache.fileAnnotationHeight=r,i=!0)}else!n&&this.cache.fileAnnotationHeight!==0&&(this.cache.fileAnnotationHeight=0,i=!0);for(const r of t.children){if(!(r instanceof HTMLElement))continue;const s=r.dataset.lineIndex;if(s==null)continue;const a=Number(s);let o=r.getBoundingClientRect().height,h=!1;r.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in r.nextElementSibling.dataset||"noNewline"in r.nextElementSibling.dataset)&&("noNewline"in r.nextElementSibling.dataset&&(h=!0),o+=r.nextElementSibling.getBoundingClientRect().height);const d=this.getLineHeight(a,h);o!==d&&(i=!0,o===this.metrics.lineHeight*(h?2:1)?this.cache.heights.delete(a):this.cache.heights.set(a,o))}return(i||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),i}onRender=i=>this.fileContainer==null||this.file==null?!1:(i&&(this.top=this.getVirtualizedTop()),this.render({file:this.file}));prepareCodeViewItem(i,e,t,n){const r=this.syncLineAnnotations(n);let s=t?.resetFileLayoutCache===!0||r;t?.metrics!=null&&(this.metrics=t.metrics,s=!0);const{collapsed:a=!1}=this.options;return this.currentCollapsed!==a&&(this.currentCollapsed=a,s=!0),s&&this.resetLayoutCache(),this.file!==i&&(this.layoutDirty=!0),this.file=i,this.top=e,this.computeApproximateSize(),this.height}getLinePosition(i){if(this.file==null||i<1)return;const{disableFileHeader:e=!1,collapsed:t=!1}=this.options,n=this.fileRenderer.getLineCount(this.file)-1;let r=B(this.metrics,e);if(t||n<0)return{top:r,height:0};const s=Math.min(Math.max(i-1,0),n),{overflow:a="scroll"}=this.options,{lineHeight:o}=this.metrics;if(r+=this.cache.fileAnnotationHeight,a==="scroll"&&!this.hasLineAnnotations())return{top:r+s*o,height:o};const h=this.getLayoutCheckpointBeforeLineIndex(s);r=h?.top??r;for(let d=h?.lineIndex??0;d<s;d++)r+=this.getLineHeight(d,!1);return{top:r,height:this.getLineHeight(s,!1)}}getNumericScrollAnchor(i){if(this.file==null||this.renderRange==null)return;const{disableFileHeader:e=!1,collapsed:t=!1,overflow:n="scroll"}=this.options;if(t||this.renderRange.totalLines<=0)return;const r=this.fileRenderer.getLineCount(this.file)-1;if(r<0)return;const s=B(this.metrics,e),a=Math.min(this.renderRange.startingLine,r),o=Math.min(a+this.renderRange.totalLines-1,r);if(o<a)return;const{fileAnnotationHeight:h}=this.cache;if(n==="scroll"&&!this.hasLineAnnotations()){const{lineHeight:l}=this.metrics,c=s+(a===0?h:this.renderRange.bufferBefore),u=a+Math.max(Math.ceil((i-c)/l),0);return u>o?void 0:{lineNumber:u+1,top:s+h+u*l}}let d=s+(a===0?h:this.renderRange.bufferBefore);for(let l=a;l<=o;l++){if(d>=i)return{lineNumber:l+1,top:d};d+=this.getLineHeight(l)}}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(i){if(this.top==null||this.file==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};const e=i!=null?this.computeRenderRangeFromWindow(this.file,this.top,i):this.renderRange;if(e==null)return;const{bufferBefore:t,bufferAfter:n,totalLines:r}=e;let s=0;if(r===0){const a=i??this.virtualizer.getWindowSpecs();this.top<a.top&&(s=n)}return{topOffset:this.top+t+s,height:this.height-(t+n)}}cleanUp(i=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),i||this.resetLayoutCache(),this.isSetup=!1,super.cleanUp(i)}computeApproximateSize(i=!1){const e=this.isResizeDebuggingEnabled();if(!i&&!this.layoutDirty&&!e)return;const t=this.height===0;if(this.height=0,this.cache.checkpoints=[],this.file==null){this.layoutDirty=!1;return}const{disableFileHeader:n=!1,collapsed:r=!1,overflow:s="scroll"}=this.options,{lineHeight:a}=this.metrics,o=this.fileRenderer.getLineCount(this.file),h=B(this.metrics,n),d=fe(this.metrics);if(this.height+=h,r){this.layoutDirty=!1;return}if(this.height+=this.cache.fileAnnotationHeight,s==="scroll"&&!this.hasLineAnnotations())this.height+=o*a;else for(let l=0;l<o;l++)this.addLayoutCheckpoint(l,this.height),this.height+=this.getLineHeight(l,!1);if(o>0&&(this.height+=d),this.fileContainer!=null&&e&&!t){const l=this.fileContainer.getBoundingClientRect();l.height!==this.height?console.log("VirtualizedFile.computeApproximateSize: computed height doesnt match",{name:this.file.name,elementHeight:l.height,computedHeight:this.height}):console.log("VirtualizedFile.computeApproximateSize: computed height IS CORRECT")}this.layoutDirty=!1}setVisibility(i){this.isAdvancedMode()||this.fileContainer==null||(i&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!i&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.file==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(i,e,t=!1){const{heights:n,checkpoints:r}=this.cache,s=this.renderRange;if(super.applyDocumentChange(i,e),this.getSimpleVirtualizer()?.markDOMDirty(),this.layoutDirty=!0,n.size>0&&n.clear(),r.length>0&&(r.length=0),this.isSimpleMode()&&this.computeApproximateSize(),t&&s!==void 0&&this.file!==void 0){const a=this.virtualizer.getWindowSpecs(),o=this.computeRenderRangeFromWindow(this.file,this.top??0,a);o.bufferAfter!==s.bufferAfter&&this.updateBuffers(o)}}render({fileContainer:i,file:e,forceRender:t=!1,lineAnnotations:n,...r}){const s=this.file==null||!A(this.file,e),{forceRenderOverride:a,isSetup:o}=this;this.forceRenderOverride=void 0;const h=this.syncLineAnnotations(n);if(h&&this.resetLayoutCache(),this.file=e,i=this.getOrCreateFileContainerNode(i),this.file==null)return console.error("VirtualizedFile.render: attempting to virtually render when we dont have file"),!1;if(o)this.top??=this.getVirtualizedTop(),s&&this.isSimpleMode()&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache(!0));else{this.computeApproximateSize();const u=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(u==null)throw new Error("VirtualizedFile.render: simple virtualizer is not available");u.connect(i,this),this.isVisible=u.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode())return this.renderPlaceholder(this.height);const d=this.virtualizer.getWindowSpecs(),l=this.top??0,c=this.computeRenderRangeFromWindow(this.file,l,d);return super.render({file:this.file,fileContainer:i,renderRange:c,lineAnnotations:n,forceRender:(a??t)||h,...r})}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}isSimpleMode(){return this.virtualizer.type==="simple"}isAdvancedMode(){return this.virtualizer.type==="advanced"}addLayoutCheckpoint(i,e){i%Ht===0&&this.cache.checkpoints.push({lineIndex:i,top:e})}getLayoutCheckpointBeforeLineIndex(i){if(i<=0||this.cache.checkpoints.length===0)return;let e=0,t=this.cache.checkpoints.length-1,n;for(;e<=t;){const r=e+t>>1,s=this.cache.checkpoints[r];if(s==null)throw new Error("VirtualizedFile: invalid checkpoint index");s.lineIndex<=i?(n=s,e=r+1):t=r-1}return n}getLayoutCheckpointBeforeTop(i,e){let t=0,n=this.cache.checkpoints.length-1,r=-1;for(;t<=n;){const s=t+n>>1,a=this.cache.checkpoints[s];if(a==null)throw new Error("VirtualizedFile: invalid checkpoint index");a.top<=i?(r=s,t=s+1):n=s-1}if(e==null)return r>=0?this.cache.checkpoints[r]:void 0;for(let s=r;s>=0;s--){const a=this.cache.checkpoints[s];if(a==null)throw new Error("VirtualizedFile: invalid checkpoint index");if(a.lineIndex%e===0)return a}}getVirtualizedTop(){return this.virtualizer.type==="advanced"?this.virtualizer.getLocalTopForInstance(this):this.fileContainer!=null?this.virtualizer.getOffsetInScrollContainer(this.fileContainer):0}getSimpleVirtualizer(){return this.virtualizer.type==="simple"?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}computeRenderRangeFromWindow(i,e,{top:t,bottom:n}){const{disableFileHeader:r=!1,overflow:s="scroll"}=this.options,{hunkLineCount:a,lineHeight:o}=this.metrics,h=this.fileRenderer.getLineCount(i),d=this.height,l=B(this.metrics,r),c=h>0?fe(this.metrics):0,{fileAnnotationHeight:u}=this.cache,p=l+u,f=Math.max(0,d-l-u-c),S=he(this.lineAnnotations),g=e+l,y=u>0&&S&&g<n&&g+u>t;if(e<t-d||e>n)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:d-l-c};if(h<=a)return{startingLine:0,totalLines:a,bufferBefore:0,bufferAfter:0};const m=Math.ceil(Math.max(n-t,0)/o),v=Math.ceil(m/a)*a+a*2,z=v/a,D=(t+n)/2;if(s==="scroll"&&!this.hasLineAnnotations()){const R=e+p,P=R+f;if(!y&&!(R<n&&P>t))return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:d-l-c};const w=Math.floor(y&&D<e+p?0:(D-(e+p))/o),b=Math.floor(w/a)-Math.floor(z/2),xe=Math.ceil(h/a),E=Math.max(0,Math.min(b,xe))*a,Q=b<0?v+b*a:v,we=E===0?0:u+E*o,Ee=Math.min(Q,h-E);return{startingLine:E,totalLines:Q,bufferBefore:we,bufferAfter:Math.max(0,(h-E-Ee)*o)}}const be=z,N=[],U=this.getLayoutCheckpointBeforeTop(Math.max(0,t-e-v*o*2),a);let T=e+(U?.top??p),_=U?.lineIndex??0,O,V,x;const Re=U?.lineIndex??0;for(let R=Re;R<h;R++){const P=_%a===0,w=Math.floor(_/a);if(P&&(N[w]=T-(e+p),x!=null)){if(x<=0)break;x--}const b=this.getLineHeight(R,!1);T>t-b&&T<n&&(O??=w),T+b>D&&(V??=w),x==null&&T>=n&&P&&(x=be),_++,T+=b}if(O==null)if(y)O=0,V=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:d-l-c};V??=O;const W=Math.round(V-z/2),Le=Math.max(0,Math.ceil(h/a)-z),G=Math.max(0,Math.min(W,Le)),J=G*a,Y=W<0?v+W*a:v,Ae=N[G]??0,He=J===0?0:u+Ae,X=G+Y/a,Me=X<N.length?f-N[X]:f-(T-e-p);return{startingLine:J,totalLines:Y,bufferBefore:He,bufferAfter:Math.max(0,Me)}}};function Et(i){let e;for(const t of i.children)t instanceof HTMLElement&&t.dataset.lineAnnotation===st&&(e=Math.max(e??0,t.getBoundingClientRect().height));return e}function Ft({file:i,renderCustomHeader:e,renderHeaderPrefix:t,renderHeaderFilenameSuffix:n,renderHeaderMetadata:r,renderAnnotation:s,lineAnnotations:a,renderGutterUtility:o,getHoveredLine:h}){const d=e?.(i),l=t?.(i),c=n?.(i),u=r?.(i);return C.jsxs(C.Fragment,{children:[d!=null?C.jsx("div",{slot:Ce,children:d}):C.jsxs(C.Fragment,{children:[l!=null&&C.jsx("div",{slot:"header-prefix",children:l}),c!=null&&C.jsx("div",{slot:"header-filename-suffix",children:c}),u!=null&&C.jsx("div",{slot:"header-metadata",children:u})]}),s!=null&&a?.map((p,f)=>C.jsx("div",{slot:I(p),children:s(p)},f)),o!=null&&C.jsx("div",{slot:"gutter-utility-slot",style:at,children:o(h)})]})}const me=typeof window>"u"?k.useEffect:k.useLayoutEffect;function kt({file:i,options:e,lineAnnotations:t,selectedLines:n,prerenderedHTML:r,metrics:s,hasGutterRenderUtility:a,hasCustomHeader:o,disableWorkerPool:h,contentEditable:d}){const l=ot(),c=n!==void 0,u=k.useContext(ht),p=lt(),f=k.useRef(null),S=dt(g=>{if(g!=null){if(f.current!=null)throw new Error("File: An instance should not already exist when a node is created");l!=null?f.current=new wt(K({controlledSelection:c,contentEditable:d,hasCustomHeader:o,hasEditor:p!==void 0,hasGutterRenderUtility:a,options:e}),l,s,h?void 0:u,!0):f.current=new Te(K({controlledSelection:c,contentEditable:d,hasCustomHeader:o,hasEditor:p!==void 0,hasGutterRenderUtility:a,options:e}),h?void 0:u,!0),f.current.hydrate({file:i,fileContainer:g,lineAnnotations:t,prerenderedHTML:r})}else{if(f.current==null)throw new Error("File: A File instance should exist when unmounting");f.current.cleanUp(),f.current=null}});return me(()=>{if(f.current==null)return;const g=K({controlledSelection:c,contentEditable:d,hasCustomHeader:o,hasEditor:p!==void 0,hasGutterRenderUtility:a,options:e}),y=!ye(f.current.options,g);f.current.setOptions(g),f.current.render({file:i,lineAnnotations:t,forceRender:y}),n!==void 0&&f.current.setSelectedLines(n)}),me(()=>{if(d&&f.current!=null){if(p===void 0)throw new Error("File: Editor is not attached");return p.edit(f.current)}},[d,p]),{ref:S,getHoveredLine:k.useCallback(()=>f.current?.getHoveredLine(),[])}}function K({options:i,controlledSelection:e,contentEditable:t,hasCustomHeader:n,hasEditor:r,hasGutterRenderUtility:s}){const a=t&&r,o=e||s||n;if(!o&&!a)return i;let h={...i};return o&&(h={...h,controlledSelection:e,renderCustomHeader:n?le:i?.renderCustomHeader,renderGutterUtility:s?le:i?.renderGutterUtility}),a&&(h={...h,useTokenTransformer:!0,enableGutterUtility:!1,enableLineSelection:!1,lineHoverHighlight:"disabled"}),h}function _t({file:i,lineAnnotations:e,selectedLines:t,options:n,metrics:r,className:s,style:a,renderAnnotation:o,renderCustomHeader:h,renderHeaderPrefix:d,renderHeaderFilenameSuffix:l,renderHeaderMetadata:c,prerenderedHTML:u,renderGutterUtility:p,disableWorkerPool:f=!1,contentEditable:S=!1}){const{ref:g,getHoveredLine:y}=kt({file:i,options:n,metrics:r,lineAnnotations:e,selectedLines:t,prerenderedHTML:u,hasGutterRenderUtility:p!=null,hasCustomHeader:h!=null,disableWorkerPool:f,contentEditable:S});return C.jsx(Oe,{ref:g,className:s,style:a,children:ct(Ft({file:i,renderAnnotation:o,renderCustomHeader:h,renderHeaderPrefix:d,renderHeaderFilenameSuffix:l,renderHeaderMetadata:c,renderGutterUtility:p,lineAnnotations:e,getHoveredLine:y}),u)})}const Wt=L.memo(function({jsonString:e,className:t,maxHeight:n="100%",initiallyExpandedDepth:r=2}){const s=L.useRef(null),[a,o]=L.useState(null),h=L.useMemo(()=>{try{const c=e.trim();if(!c)return o("Empty JSON content"),null;const u=JSON.parse(c);return o(null),u}catch(c){return o(c instanceof Error?c.message:"Invalid JSON"),null}},[e]),d=L.useCallback(()=>{s.current?.expandAll()},[]),l=L.useCallback(()=>{s.current?.collapseAll()},[]);return a?C.jsx("div",{className:t,children:C.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--syntax-base-background)] p-4",children:[C.jsx("div",{className:"mb-1 font-medium text-[var(--surface-foreground)]",children:"Invalid JSON"}),C.jsx("div",{className:"font-mono text-xs text-[var(--surface-mutedForeground)]",children:a})]})}):h===null?null:C.jsxs("div",{className:t,children:[C.jsxs("div",{className:"flex items-center gap-1 border-b border-[var(--interactive-border)] px-2 py-1",children:[C.jsxs(ee,{variant:"ghost",size:"xs",onClick:d,className:"gap-1 text-xs text-muted-foreground",children:[C.jsx(te,{name:"arrow-down-s",className:"h-3 w-3"}),"Expand All"]}),C.jsxs(ee,{variant:"ghost",size:"xs",onClick:l,className:"gap-1 text-xs text-muted-foreground",children:[C.jsx(te,{name:"arrow-up-s",className:"h-3 w-3"}),"Collapse All"]})]}),C.jsx("div",{className:"bg-[var(--syntax-base-background)] py-1",style:{maxHeight:n,overflow:"auto"},children:C.jsx(Ve,{ref:s,data:h,maxHeight:n,initiallyExpandedDepth:r})})]})});export{_t as F,Wt as J};
1
+ import{ci as H,dE as Z,dF as Fe,dG as Ce,dH as ke,dI as Ie,dJ as ze,dz as Ne,dK as Oe,B as ee,I as te,dL as Ve}from"./useAppFontEffects-BQ1JUauS.js";import{a as ie,s as Pe,b as Se,c as ne,d as ve,g as Be,e as re,f as I,h as De,i as Ue,j as _e,k as We,R as Ge,I as je,p as se,l as $e,m as Ke,n as qe,o as Je,w as Ye,q as ae,u as Xe,r as Qe,t as Ze,v as et,x as oe,S as tt,y as it,z as nt,A as rt,B as ye,C as he,F as st}from"./web-components-CJ0xIy7r.js";import{G as at,u as ot,W as ht,a as lt,b as dt,n as le,t as ct}from"./Virtualizer-DP6HbEeC.js";import{k as C}from"./vendor-boot-EC6IyLt1.js";import{o as ut,i as j,f as A,a as ft,q as de,s as pt,t as ce,d as gt,u as ue,b as mt,w as B,x as fe}from"./computeVirtualFileMetrics-8mC_o5zA.js";import{a as F,i as q,l as pe,h as Ct,r as St}from"./renderFileWithHighlighter-VOwWxIE1.js";import{t as M}from"./vendor-hast-util-to-html-BKBhbTDb.js";import{a as k,R as L}from"./vendor-react-DASdDPIk.js";let vt=-1;var yt=class{options;onRenderUpdate;workerManager;__id=`file-renderer:${++vt}`;highlighter;renderCache;computedLang="text";lineAnnotations={};lineCache;textDoucmentCache=new WeakMap;constructor(i={theme:H},e,t){this.options=i,this.onRenderUpdate=e,this.workerManager=t,t?.isWorkingPool()!==!0&&(this.highlighter=ie(i.theme??H)?ut():void 0)}setOptions(i){this.options=i}mergeOptions(i){this.options={...this.options,...i}}setLineAnnotations(i){this.lineAnnotations={};for(const e of i){const t=this.lineAnnotations[e.lineNumber]??[];this.lineAnnotations[e.lineNumber]=t,t.push(e)}}cleanUp(){this.recycle(),this.workerManager=void 0,this.onRenderUpdate=void 0}recycle(){this.clearRenderCache(),this.highlighter=void 0,this.workerManager?.cleanUpTasks(this),this.lineCache=void 0}clearRenderCache(){const i=this.renderCache;this.renderCache=void 0,i!=null&&i.isDirty===!0&&i.file.cacheKey!=null&&this.workerManager?.evictFileFromCache(i.file.cacheKey)}hydrate(i){const{options:e}=this.getRenderOptions(i),t=$(this.getOrCreateLineCache(i).length,this.getTokenizeMaxLength());let n=this.workerManager?.getFileResultCache(i);n!=null&&!F(e,n.options)&&(n=void 0),this.renderCache??={file:i,options:e,highlighted:!t&&!q(i),result:t?void 0:n?.result,renderRange:void 0},this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!t&&this.workerManager.highlightFileAST(this,i):this.highlighter==null&&(this.computedLang=i.lang??j(i.name),this.initializeHighlighter())}getRenderOptions(i){const e=(()=>{if(this.workerManager?.isWorkingPool()===!0)return this.workerManager.getFileRenderOptions();const{theme:n=H,tokenizeMaxLineLength:r=1e3}=this.options;return{theme:n,useTokenTransformer:Pe(this.options),tokenizeMaxLineLength:r}})(),{renderCache:t}=this;return t?.result==null?{options:e,forceHighlight:!0}:!A(i,t.file)||!F(e,t.options)?{options:e,forceHighlight:!0}:{options:e,forceHighlight:!1}}getOrCreateLineCache(i){if(i.cacheKey==null)return this.lineCache=void 0,pe(i.contents);let{lineCache:e}=this;return(e==null||e.cacheKey!==i.cacheKey)&&(e={cacheKey:i.cacheKey,lines:pe(i.contents)}),this.lineCache=e,e.lines}getLineCount(i){return this.textDoucmentCache.get(i)?.lineCount??this.getOrCreateLineCache(i).length}updateRenderCache(i,e){if(this.renderCache==null)return;const{result:t}=this.renderCache;if(t!=null){for(const[n,r]of i)t.code[n]={type:"element",tagName:"div",properties:{"data-line":n+1,"data-line-type":"context","data-line-index":n},children:r.map(([s,a,o])=>s===0&&a===""?o===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:o}:{type:"element",tagName:"span",properties:{"data-char":s,style:`--diffs-token-${e}:${a};`},children:[{type:"text",value:o}]})};t.baseThemeType=e,this.renderCache.isDirty=!0}}applyDocumentChange(i){if(this.renderCache==null)return;const{file:e,result:t}=this.renderCache;if(t!=null&&t.code.length!==i.lineCount){t.code.length=Math.min(t.code.length,i.lineCount);for(let n=t.code.length;n<i.lineCount;n++)t.code.push({type:"element",tagName:"div",properties:{"data-line":n+1,"data-line-type":"context","data-line-index":n},children:[{type:"element",tagName:"span",properties:{"data-char":0},children:[{type:"text",value:i.getLineText(n)}]}]});this.renderCache.isDirty=!0}this.textDoucmentCache.set(e,i)}renderFile(i=this.renderCache?.file,e=Z){if(i==null)return;let{options:t,forceHighlight:n}=this.getRenderOptions(i);const r=this.getMatchingWorkerResultCache(i,t);r!=null&&!this.hasHighlightedRenderCache(i,t)&&(this.renderCache={file:i,highlighted:!0,renderRange:void 0,...r},n=!1),this.renderCache??={file:i,highlighted:!1,options:t,result:void 0,renderRange:void 0};const s=this.getOrCreateLineCache(i),a=i.contents.length>0,o=!a||q(i)||$(s.length,this.getTokenizeMaxLength()),h=!A(i,this.renderCache.file),d=!Se(this.renderCache.renderRange,e);if(this.workerManager?.isWorkingPool()===!0)(o||this.renderCache.result==null||!this.renderCache.highlighted&&(h||d))&&(this.renderCache.file=i,this.renderCache.options=t,this.renderCache.highlighted=!1,(this.renderCache.result==null||h||d||n)&&(this.renderCache.result=this.workerManager.getPlainFileAST(i,e.startingLine,e.totalLines,s)),this.renderCache.renderRange=e),!o&&a&&(!this.renderCache.highlighted||n)&&this.workerManager.highlightFileAST(this,i);else{this.computedLang=i.lang??j(i.name);const l=this.highlighter!=null&&ie(t.theme),c=this.highlighter!=null&&ne(this.computedLang),u=!o&&c;if(this.highlighter!=null&&l&&(n||o||!this.renderCache.highlighted&&u||this.renderCache.result==null)){const{result:p,options:f}=this.renderFileWithHighlighter(i,this.highlighter,o||!c);this.renderCache={file:i,options:f,highlighted:u,result:p,renderRange:void 0}}(!l||!o&&!c)&&this.asyncHighlight(i).then(({result:p,options:f})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.onHighlightSuccess(i,p,f,!o)})}return this.renderCache.result!=null?this.processFileResult(this.renderCache.file,e,this.renderCache.result):void 0}async asyncRender(i,e=Z){const{result:t}=await this.asyncHighlight(i);return this.processFileResult(i,e,t)}async asyncHighlight(i){const e=$(this.getOrCreateLineCache(i).length,this.getTokenizeMaxLength());this.computedLang=e?"text":i.lang??j(i.name);const t=this.highlighter!=null&&Ct(ft(this.options.theme)),n=e||this.highlighter!=null&&ne(this.computedLang);return(this.highlighter==null||!t||!n)&&(this.highlighter=await this.initializeHighlighter()),this.renderFileWithHighlighter(i,this.highlighter,e)}renderFileWithHighlighter(i,e,t=!1){const{options:n}=this.getRenderOptions(i);return{result:St(i,e,n,{forcePlainText:t}),options:n}}processFileResult(i,e,{code:t,themeStyles:n,baseThemeType:r}){const s=this.getLineCount(i),{disableFileHeader:a=!1}=this.options,o=[],h=ue(),d=Math.min(e.startingLine+e.totalLines,s);let l=0;const c=ve(e)?Be(this.lineAnnotations):void 0;c!=null&&(h.children.push(de("context","annotation",1)),o.push(re({hunkIndex:-1,lineIndex:-1,annotations:c.map(u=>I(u))})),l++);for(let u=e.startingLine;u<d;u++){const p=u+1,f=t[u];if(f==null){const g="FileRenderer.processFileResult: Line doesnt exist";throw console.error(g,{name:i.name,lineIndex:u,lineNumber:p}),new Error(g)}h.children.push(pt("context",p,`${u}`)),o.push(f),l++;const S=this.lineAnnotations[p];S!=null&&(h.children.push(de("context","annotation",1)),o.push(re({hunkIndex:0,lineIndex:p,annotations:S.map(g=>I(g))})),l++)}return h.properties.style=`grid-row: span ${l}`,{gutterAST:h.children??[],contentAST:o,preAST:this.createPreElement(s),headerAST:a?void 0:this.renderHeader(i),totalLines:s,rowCount:l,themeStyles:n,baseThemeType:r,bufferBefore:e.bufferBefore,bufferAfter:e.bufferAfter,css:""}}renderHeader(i){const{headerRenderMode:e="default",stickyHeader:t=!1}=this.options;return De({fileOrDiff:i,mode:e,stickyHeader:t})}renderFullHTML(i){return M(this.renderFullAST(i))}renderFullAST(i,e=[]){return e.push(ce({tagName:"code",children:this.renderCodeAST(i),properties:{"data-code":""}})),{...i.preAST,children:e}}renderCodeAST(i){const e=ue();return e.children=i.gutterAST,e.properties.style=`grid-row: span ${i.rowCount}`,[e,Ue(i.contentAST,i.rowCount)]}renderPartialHTML(i,e=!1){return e?M(ce({tagName:"code",children:i,properties:{"data-code":""}})):M(i)}async initializeHighlighter(){return this.highlighter=await gt(_e(this.computedLang,this.options)),this.highlighter}onHighlightSuccess(i,e,t,n=!0){if(this.renderCache==null)return;const r=!A(i,this.renderCache.file)||!this.renderCache.highlighted||!F(t,this.renderCache.options);this.renderCache={file:i,options:t,highlighted:n,result:e,renderRange:void 0},r&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(i,e){const t=this.workerManager?.getFileResultCache(i);if(!(t==null||!F(e,t.options)))return t}hasHighlightedRenderCache(i,e){const{renderCache:t}=this;return t?.result!=null&&t.highlighted&&A(i,t.file)&&F(e,t.options)}onHighlightError(i){console.error(i)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}createPreElement(i){const{disableLineNumbers:e=!1,overflow:t="scroll"}=this.options;return We({type:"file",diffIndicators:"none",disableBackground:!0,disableLineNumbers:e,overflow:t,split:!1,totalLines:i})}};function $(i,e){return i>e}function Tt(i,e){return i.lineNumber===e.lineNumber&&i.metadata===e.metadata}function ge(i){return{theme:i?.theme,disableLineNumbers:i?.disableLineNumbers,overflow:i?.overflow,themeType:i?.themeType,collapsed:i?.collapsed,disableFileHeader:i?.disableFileHeader,disableVirtualizationBuffers:i?.disableVirtualizationBuffers,stickyHeader:i?.stickyHeader,preferredHighlighter:i?.preferredHighlighter,useCSSClasses:i?.useCSSClasses,useTokenTransformer:i?.useTokenTransformer,tokenizeMaxLineLength:i?.tokenizeMaxLineLength,tokenizeMaxLength:i?.tokenizeMaxLength,unsafeCSS:i?.unsafeCSS,headerRenderMode:i?.renderCustomHeader!=null?"custom":"default"}}const bt=[""];let Rt=-1;var Te=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file:${++Rt}`;type="file";fileContainer;spriteSVG;pre;code;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;errorWrapper;placeHolder;lastRenderedHeaderHTML;cachedHeaderHTML;appliedPreAttributes;lastRowCount;mounted=!1;headerElement;headerCustom;headerPrefix;headerFilenameSuffix;headerMetadata;fileRenderer;resizeManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;file;renderRange;enabled=!0;editor;constructor(e={theme:H},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.fileRenderer=new yt(e,this.handleHighlightRender,this.workerManager),this.resizeManager=new Ge,this.interactionManager=new je("file",se(e)),this.workerManager?.subscribeToThemeChanges(this)}handleHighlightRender=()=>{this.rerender()};rerender(){!this.enabled||this.file==null||this.render({file:this.file,forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.fileRenderer.clearRenderCache(),this.rerender()}setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(se(this.options))}mergeOptions(e){this.options={...this.options,...e}}setThemeType(e){(this.options.themeType??"system")!==e&&(this.mergeOptions({themeType:e}),this.applyCachedThemeState(e))}applyCachedThemeState(e){if(typeof this.options.theme=="string"||this.fileContainer==null||this.appliedThemeCSS==null)return!1;const t=this.appliedThemeCSS.baseThemeType??e;return this.appliedThemeCSS.themeType===t?!1:(this.applyThemeState(this.fileContainer,this.appliedThemeCSS.themeStyles,e,this.appliedThemeCSS.baseThemeType),!0)}hasThemeChanged(){return this.appliedThemeCSS!=null&&!mt(this.appliedThemeCSS.theme,this.options.theme??H)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}setSelectedLines(e,t){this.interactionManager.setSelection(e,t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}const{overflow:e="scroll"}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,e==="wrap"),this.managersDirty=!1}cleanUp(e=!1){this.emitPostRender(!0),this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.annotationCache.clear(),this.pre=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.placeHolder=void 0,this.unsafeCSSStyle=void 0,e?this.fileRenderer.recycle():(this.fileRenderer.cleanUp(),this.workerManager=void 0,this.file=void 0),this.enabled=!1,this.editor?.cleanUp(),this.editor=void 0}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate(e){const{fileContainer:t,prerenderedHTML:n,preventEmit:r=!1,file:s,lineAnnotations:a}=e;this.hydrateElements(t,n),Lt(this.pre,s,this.options.collapsed)||At(this.headerElement,s,this.options.disableFileHeader)?this.render({...e,preventEmit:!0}):this.hydrationSetup({file:s,lineAnnotations:a}),r||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),$e(e,t);for(const n of Array.from(e.shadowRoot?.children??[])){if(n instanceof SVGElement){this.spriteSVG=n;continue}if(n instanceof HTMLElement){if(n instanceof HTMLPreElement){this.pre=n,this.appliedPreAttributes=void 0;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-theme-css")){this.themeCSSStyle=n;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-unsafe-css")){this.unsafeCSSStyle=n,this.appliedUnsafeCSS=n.textContent;continue}if("diffsHeader"in n.dataset){this.headerElement=n,this.lastRenderedHeaderHTML=void 0;continue}}}this.pre!=null&&(this.syncCodeNodeFromPre(this.pre),this.pre.removeAttribute("data-dehydrated")),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({file:e,lineAnnotations:t}){this.lineAnnotations=t??this.lineAnnotations,this.file=e,this.fileRenderer.setOptions(ge(this.options)),this.syncInteractionOptions(),this.pre!=null&&(this.fileRenderer.hydrate(e),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}getOrCreateLineCache(e=this.file){return e!=null?this.fileRenderer.getOrCreateLineCache(e):bt}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}syncRenderViewToEditor(){const e=this.editor,t=this.fileContainer,n=this.file;e!=null&&t!=null&&n!=null&&this.fileRenderer.initializeHighlighter().then(r=>{e.__syncRenderView(r,t,n,this.lineAnnotations,this.renderRange)})}attachEditor(e){return this.editor?.cleanUp(),this.editor=e,this.interactionManager.setEditorAttached(!0),this.syncRenderViewToEditor(),()=>{this.editor=void 0,this.interactionManager.setEditorAttached(!1)}}applyDocumentChange(e,t){this.fileRenderer.applyDocumentChange(e),t!=null&&t!==this.lineAnnotations&&this.file!=null&&(this.setLineAnnotations(t),this.fileRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations())}updateRenderCache(e,t){this.fileRenderer.updateRenderCache(e,t)}render({file:e,fileContainer:t,forceRender:n=!1,preventEmit:r=!1,containerWrapper:s,deferManagers:a=!1,lineAnnotations:o,renderRange:h}){if(!this.enabled)throw new Error("File.render: attempting to call render after cleaned up");this.editor?.__postponeBackgroundTokenizeToNextFrame();const{collapsed:d=!1,themeType:l="system"}=this.options,c=d?void 0:h,u=this.renderRange,p=this.hasThemeChanged(),f=o!=null&&(o.length>0||this.lineAnnotations.length>0)?o!==this.lineAnnotations:!1,S=!A(this.file,e);if(!d&&!n&&Se(c,this.renderRange)&&!S&&!f&&!p)return this.applyCachedThemeState(l);this.renderRange=c,S&&(this.cachedHeaderHTML=void 0),this.file=e,this.fileRenderer.setOptions(ge(this.options)),this.syncInteractionOptions(),o!=null&&this.setLineAnnotations(o),this.fileRenderer.setLineAnnotations(this.lineAnnotations);const{disableErrorHandling:g=!1,disableFileHeader:y=!1}=this.options;if(y&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),t=this.getOrCreateFileContainerNode(t,s),this.applyCachedThemeState(l),d){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const m=this.fileRenderer.renderFile(e,Fe);m!=null&&this.applyThemeState(t,m.themeStyles,l,m.baseThemeType),m?.headerAST!=null&&this.applyHeaderToDOM(m.headerAST,t),this.injectUnsafeCSS()}catch(m){if(g)throw m;console.error(m),m instanceof Error&&this.applyErrorToDOM(m,t)}return r||this.emitPostRender(),!0}try{const m=this.getOrCreatePreNode(t);if(!this.canPartiallyRender(n,f,S||p)||!this.applyPartialRender(u,c)){const v=this.fileRenderer.renderFile(e,c);if(v==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(t,v.themeStyles,l,v.baseThemeType),v.headerAST!=null&&this.applyHeaderToDOM(v.headerAST,t),this.applyFullRender(v,m)}this.applyBuffers(m,c),this.injectUnsafeCSS(),this.managersDirty=!0,a||this.flushManagers(),this.renderAnnotations(),this.renderGutterUtility(),this.editor!=null&&this.syncRenderViewToEditor()}catch(m){if(g)throw m;console.error(m),m instanceof Error&&this.applyErrorToDOM(m,t)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){const{fileContainer:t,options:{onPostRender:n}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;n?.(t,this,"unmount");return}if(t==null)return;const r=this.mounted?"update":"mount";this.mounted=!0,n?.(t,this,r)}removeRenderedCode(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.code?.remove(),this.code=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(const{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}canPartiallyRender(e,t,n){return!(e||t||n)}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){const t=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:"open"});this.placeHolder=document.createElement("div"),this.placeHolder.dataset.placeholder="",t.appendChild(this.placeHolder)}return this.placeHolder.style.setProperty("height",`${e}px`),!0}primeHighlightCache(){const{file:e,workerManager:t}=this;e==null||e.cacheKey==null||t==null||q(e)||this.fileRenderer.getOrCreateLineCache(e).length>(this.options.tokenizeMaxLength??1e5)||t.primeFileHighlightCache(e)}cleanChildNodes(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.code?.remove(),this.errorWrapper?.remove(),this.headerElement?.remove(),this.gutterUtilityContent?.remove(),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.pre?.remove(),this.spriteSVG?.remove(),this.themeCSSStyle?.remove(),this.unsafeCSSStyle?.remove(),this.bufferAfter=void 0,this.bufferBefore=void 0,this.code=void 0,this.errorWrapper=void 0,this.headerElement=void 0,this.gutterUtilityContent=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.pre=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.lastRenderedHeaderHTML=void 0,this.lastRowCount=void 0,this.mounted=!1}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(const{element:n}of this.annotationCache.values())n.remove();this.annotationCache.clear();return}const e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(const[n,r]of this.lineAnnotations.entries()){const s=`${n}-${I(r)}`;let a=this.annotationCache.get(s);if(a==null||!Tt(r,a.annotation)){a?.element.remove();const o=t(r);if(o==null)continue;a={element:Ke(I(r)),annotation:r},a.element.appendChild(o),this.fileContainer.appendChild(a.element),this.annotationCache.set(s,a)}e.delete(s)}for(const[n,{element:r}]of e.entries())this.annotationCache.delete(n),r.remove()}renderGutterUtility(){const{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const n=qe();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}injectUnsafeCSS(){const{unsafeCSS:e}=this.options,t=this.fileContainer?.shadowRoot;if(t!=null){if(e==null||e===""){this.unsafeCSSStyle!=null&&(this.unsafeCSSStyle.remove(),this.unsafeCSSStyle=void 0),this.appliedUnsafeCSS=void 0;return}this.unsafeCSSStyle?.parentNode===t&&this.appliedUnsafeCSS===e||(this.unsafeCSSStyle??=Je(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=Ye(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,r){const s=e.shadowRoot??e.attachShadow({mode:"open"}),a=r??n,o=this.options.theme??H,h=typeof o=="string"?o:{...o},d=ae(s);if(this.themeCSSStyle?.parentNode===s&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===a&&this.appliedThemeCSS.scrollbarGutter===d){this.appliedThemeCSS.theme=h;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===s){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:h,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:d};return}this.themeCSSStyle=Xe({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:Qe(t,a,d)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:h,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:d}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=Ze(this.themeCSSStyle.textContent??"",ae(e)))}applyFullRender(e,t){this.cleanupErrorWrapper(),this.applyPreNodeAttributes(t,e),this.code=et({code:this.code});const n=this.fileRenderer.renderCodeAST(e);if(this.code.childElementCount>=2)for(let r=0;r<2;r++){const s=this.code.children[r],a=n[r];s.innerHTML=M(a.children),s.style.cssText=a.properties.style}else this.code.innerHTML=M(n);t.contains(this.code)||t.replaceChildren(this.code),this.lastRowCount=e.rowCount}applyPartialRender(e,t){if(e==null||t==null)return!1;const{file:n,code:r}=this,s=r!=null?this.getColumns(r):void 0;if(n==null||r==null||s==null)return!1;const a=e.startingLine,o=t.startingLine,h=e.totalLines===1/0?Number.POSITIVE_INFINITY:a+e.totalLines,d=t.totalLines===1/0?Number.POSITIVE_INFINITY:o+t.totalLines,l=Math.max(a,o),c=Math.min(h,d);if(c<=l||!this.trimDOMToOverlap(s.gutter,l,c)||!this.trimDOMToOverlap(s.content,l,c))return!1;let{length:u}=s.content.children;const p=(y,m)=>{if(!(m<=0))return this.fileRenderer.renderFile(n,{startingLine:y,totalLines:m,bufferBefore:0,bufferAfter:0})},f=o<l?p(o,l-o):void 0;if(f===void 0&&o<l)return!1;const S=d===Number.POSITIVE_INFINITY?Number.POSITIVE_INFINITY:Math.max(0,d-c),g=d>c?p(c,S):void 0;return g===void 0&&d>c?!1:(this.cleanupErrorWrapper(),f!=null&&(s.gutter.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(f.gutterAST)),s.content.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(f.contentAST)),u+=f.rowCount),g!=null&&(s.gutter.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(g.gutterAST)),s.content.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(g.contentAST)),u+=g.rowCount),this.lastRowCount!==u&&(s.gutter.style.setProperty("grid-row",`span ${u}`),s.content.style.setProperty("grid-row",`span ${u}`),this.lastRowCount=u),!0)}getColumns(e){const t=e.children[0],n=e.children[1];if(!(!(t instanceof HTMLElement)||!(n instanceof HTMLElement)||t.dataset.gutter==null||n.dataset.content==null))return{gutter:t,content:n}}trimDOMToOverlap(e,t,n){const r=this.getDOMBoundaryIndices(e,[t,n]),s=r.get(t)??e.children.length,a=r.get(n)??e.children.length;if(s>a)return!1;for(let o=e.children.length-1;o>=a;o-=1)e.children[o]?.remove();for(let o=s-1;o>=0;o-=1)e.children[o]?.remove();return!0}getDOMBoundaryIndices(e,t){const n=[...new Set(t)].sort((h,d)=>h-d),r=new Map;if(n.length===0)return r;let s=0,a=n[s];const{children:o}=e;a===0&&(r.set(0,0),s+=1,a=n[s]);for(let h=0;h<o.length;h+=1){const d=o[h];if(!(d instanceof HTMLElement))continue;const l=this.getLineIndexFromDOMNode(d);if(l!=null){for(;a!=null&&l>=a;)r.set(a,h),s+=1,a=n[s];if(s>=n.length)break}}for(const h of n)r.has(h)||r.set(h,o.length);return r}getLineIndexFromDOMNode(e){const t=e.dataset.lineIndex;if(t==null)return;const n=Number(t);return Number.isNaN(n)?void 0:n}applyBuffers(e,t){if(t==null||this.shouldDisableVirtualizationBuffers()){this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0);return}t.bufferBefore>0?(this.bufferBefore==null&&(this.bufferBefore=document.createElement("div"),this.bufferBefore.dataset.virtualizerBuffer="before",e.before(this.bufferBefore)),this.bufferBefore.style.setProperty("height",`${t.bufferBefore}px`),this.bufferBefore.style.setProperty("contain","strict")):this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),t.bufferAfter>0?(this.bufferAfter==null&&(this.bufferAfter=document.createElement("div"),this.bufferAfter.dataset.virtualizerBuffer="after",e.after(this.bufferAfter)),this.bufferAfter.style.setProperty("height",`${t.bufferAfter}px`),this.bufferAfter.style.setProperty("contain","strict")):this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0)}shouldDisableVirtualizationBuffers(){return this.options.disableVirtualizationBuffers??!1}applyHeaderToDOM(e,t){const{file:n}=this;if(n==null)return;this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;const r=this.cachedHeaderHTML??M(e);if(this.cachedHeaderHTML=r,r!==this.lastRenderedHeaderHTML){const d=document.createElement("div");d.innerHTML=r;const l=d.firstElementChild;if(!(l instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(l,this.headerElement):t.shadowRoot?.prepend(l),this.headerElement=l,this.lastRenderedHeaderHTML=r}if(this.isContainerManaged)return;const{renderHeaderPrefix:s,renderHeaderFilenameSuffix:a,renderCustomHeader:o,renderHeaderMetadata:h}=this.options;if(o!=null){const d=o(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,Ce,d),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0}else{const d=s?.(n)??void 0,l=a?.(n)??void 0,c=h?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,ke,d),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Ie,l),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,ze,c),this.headerCustom?.remove(),this.headerCustom=void 0}}clearHeaderSlots(){this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0}upsertHeaderSlotElement(e,t,n,r){if(r==null){t?.remove();return}const s=t??this.createHeaderSlotElement(n);return t==null&&e.appendChild(s),this.replaceHeaderSlotContent(s,r),s}replaceHeaderSlotContent(e,t){e.replaceChildren(),t instanceof Element?e.appendChild(t):e.innerText=`${t}`}createHeaderSlotElement(e){const t=document.createElement("div");return t.slot=e,t}getOrCreateFileContainerNode(e,t){const{fileContainer:n}=this,r=e??n??document.createElement("diffs-container"),s=n!==r;return s&&this.emitPostRender(!0),this.fileContainer=r,n!=null&&s&&(this.lastRenderedHeaderHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),s&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){const{shadowRoot:t}=e;if(t!=null)for(const n of t.children)n instanceof SVGElement?this.spriteSVG??=n:oe(n)&&n.hasAttribute("data-theme-css")?(this.themeCSSStyle??=n,this.hasAdoptedThemeCSS=!0):oe(n)&&n.hasAttribute("data-unsafe-css")&&(this.unsafeCSSStyle??=n,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});if(this.spriteSVG==null){const n=document.createElement("div");n.innerHTML=tt;const r=n.firstChild;r instanceof SVGElement&&(this.spriteSVG=r)}this.spriteSVG!=null&&this.spriteSVG.parentNode!==t&&t.appendChild(this.spriteSVG)}getOrCreatePreNode(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});return this.pre==null?(this.pre=document.createElement("pre"),this.appliedPreAttributes=void 0,this.code=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(e.shadowRoot?.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodeFromPre(e){this.code=void 0;for(const t of Array.from(e.children))if(t instanceof HTMLElement&&t.hasAttribute("data-code")){this.code=t;return}}applyPreNodeAttributes(e,{totalLines:t}){const{overflow:n="scroll",disableLineNumbers:r=!1}=this.options,s={type:"file",split:!1,overflow:n,disableLineNumbers:r,diffIndicators:"none",disableBackground:!0,totalLines:t};it(s,this.appliedPreAttributes)||(nt(e,s),this.appliedPreAttributes=s)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;const n=t.shadowRoot??t.attachShadow({mode:"open"});this.errorWrapper??=document.createElement("div"),this.errorWrapper.dataset.errorWrapper="",this.errorWrapper.textContent="",n.appendChild(this.errorWrapper);const r=document.createElement("div");r.dataset.errorMessage="",r.innerText=e.message,this.errorWrapper.appendChild(r);const s=document.createElement("pre");s.dataset.errorStack="",s.innerText=e.stack??"No Error Stack",this.errorWrapper.appendChild(s)}cleanupErrorWrapper(){this.errorWrapper?.remove(),this.errorWrapper=void 0}};function Lt(i,e,t=!1){return!t&&i==null&&e!=null}function At(i,e,t=!1){return i==null&&e!=null&&!t}const Ht=5e3;let Mt=-1;function xt(i,e){return(i.overflow??"scroll")!==(e.overflow??"scroll")||(i.collapsed??!1)!==(e.collapsed??!1)||(i.disableLineNumbers??!1)!==(e.disableLineNumbers??!1)||(i.disableFileHeader??!1)!==(e.disableFileHeader??!1)||i.unsafeCSS!==e.unsafeCSS}var wt=class extends Te{virtualizer;metrics;__id=`virtualized-file:${++Mt}`;top;height=0;cache={heights:new Map,checkpoints:[],fileAnnotationHeight:0};isVisible=!1;isSetup=!1;layoutDirty=!0;forceRenderOverride;currentCollapsed;constructor(i,e,t=Ne,n,r=!1){super(i,n,r),this.virtualizer=e,this.metrics=t}setMetrics(i,e=!1){!e&&rt(this.metrics,i)||(this.metrics=i,this.resetLayoutCache())}setLineAnnotations(i){this.syncLineAnnotations(i)&&this.resetLayoutCache()}syncLineAnnotations(i){return i==null||i===this.lineAnnotations||i.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(i),!0)}hasLineAnnotations(){return this.lineAnnotations.some(i=>i.lineNumber>0)}getLineHeight(i,e=!1){const t=this.cache.heights.get(i);if(t!=null)return t;const n=e?2:1;return this.metrics.lineHeight*n}setOptions(i){if(this.isAdvancedMode())throw new Error("VirtualizedFile.setOptions cannot be used inside CodeView. Update CodeView options instead.");if(i==null)return;const{options:e}=this,t=!ye(e,i),n=xt(e,i);super.setOptions(i),n&&this.resetLayoutCache(!0),t&&(this.forceRenderOverride=!0),t&&this.virtualizer.instanceChanged(this,n)}setThemeType(i){if(this.isAdvancedMode())throw new Error("VirtualizedFile.setThemeType cannot be used inside CodeView. Update CodeView options instead.");super.setThemeType(i)}resetLayoutCache(i=!1){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heights.size>0&&this.cache.heights.clear(),this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.renderRange!=null&&(this.renderRange=void 0),i&&this.isSimpleMode()&&this.computeApproximateSize()}reconcileHeights(){let i=!1;if(this.fileContainer==null||this.file==null)return this.height!==0&&(i=!0),this.height=0,i;const{overflow:e="scroll"}=this.options;if(this.top=this.getVirtualizedTop(),e==="scroll"&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled()||this.code==null)return i;const t=this.code.children[1];if(!(t instanceof HTMLElement))return i;const n=he(this.lineAnnotations);if(this.renderRange!=null&&n&&ve(this.renderRange)){const r=Et(t)??0;r!==this.cache.fileAnnotationHeight&&(this.cache.fileAnnotationHeight=r,i=!0)}else!n&&this.cache.fileAnnotationHeight!==0&&(this.cache.fileAnnotationHeight=0,i=!0);for(const r of t.children){if(!(r instanceof HTMLElement))continue;const s=r.dataset.lineIndex;if(s==null)continue;const a=Number(s);let o=r.getBoundingClientRect().height,h=!1;r.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in r.nextElementSibling.dataset||"noNewline"in r.nextElementSibling.dataset)&&("noNewline"in r.nextElementSibling.dataset&&(h=!0),o+=r.nextElementSibling.getBoundingClientRect().height);const d=this.getLineHeight(a,h);o!==d&&(i=!0,o===this.metrics.lineHeight*(h?2:1)?this.cache.heights.delete(a):this.cache.heights.set(a,o))}return(i||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),i}onRender=i=>this.fileContainer==null||this.file==null?!1:(i&&(this.top=this.getVirtualizedTop()),this.render({file:this.file}));prepareCodeViewItem(i,e,t,n){const r=this.syncLineAnnotations(n);let s=t?.resetFileLayoutCache===!0||r;t?.metrics!=null&&(this.metrics=t.metrics,s=!0);const{collapsed:a=!1}=this.options;return this.currentCollapsed!==a&&(this.currentCollapsed=a,s=!0),s&&this.resetLayoutCache(),this.file!==i&&(this.layoutDirty=!0),this.file=i,this.top=e,this.computeApproximateSize(),this.height}getLinePosition(i){if(this.file==null||i<1)return;const{disableFileHeader:e=!1,collapsed:t=!1}=this.options,n=this.fileRenderer.getLineCount(this.file)-1;let r=B(this.metrics,e);if(t||n<0)return{top:r,height:0};const s=Math.min(Math.max(i-1,0),n),{overflow:a="scroll"}=this.options,{lineHeight:o}=this.metrics;if(r+=this.cache.fileAnnotationHeight,a==="scroll"&&!this.hasLineAnnotations())return{top:r+s*o,height:o};const h=this.getLayoutCheckpointBeforeLineIndex(s);r=h?.top??r;for(let d=h?.lineIndex??0;d<s;d++)r+=this.getLineHeight(d,!1);return{top:r,height:this.getLineHeight(s,!1)}}getNumericScrollAnchor(i){if(this.file==null||this.renderRange==null)return;const{disableFileHeader:e=!1,collapsed:t=!1,overflow:n="scroll"}=this.options;if(t||this.renderRange.totalLines<=0)return;const r=this.fileRenderer.getLineCount(this.file)-1;if(r<0)return;const s=B(this.metrics,e),a=Math.min(this.renderRange.startingLine,r),o=Math.min(a+this.renderRange.totalLines-1,r);if(o<a)return;const{fileAnnotationHeight:h}=this.cache;if(n==="scroll"&&!this.hasLineAnnotations()){const{lineHeight:l}=this.metrics,c=s+(a===0?h:this.renderRange.bufferBefore),u=a+Math.max(Math.ceil((i-c)/l),0);return u>o?void 0:{lineNumber:u+1,top:s+h+u*l}}let d=s+(a===0?h:this.renderRange.bufferBefore);for(let l=a;l<=o;l++){if(d>=i)return{lineNumber:l+1,top:d};d+=this.getLineHeight(l)}}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(i){if(this.top==null||this.file==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};const e=i!=null?this.computeRenderRangeFromWindow(this.file,this.top,i):this.renderRange;if(e==null)return;const{bufferBefore:t,bufferAfter:n,totalLines:r}=e;let s=0;if(r===0){const a=i??this.virtualizer.getWindowSpecs();this.top<a.top&&(s=n)}return{topOffset:this.top+t+s,height:this.height-(t+n)}}cleanUp(i=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),i||this.resetLayoutCache(),this.isSetup=!1,super.cleanUp(i)}computeApproximateSize(i=!1){const e=this.isResizeDebuggingEnabled();if(!i&&!this.layoutDirty&&!e)return;const t=this.height===0;if(this.height=0,this.cache.checkpoints=[],this.file==null){this.layoutDirty=!1;return}const{disableFileHeader:n=!1,collapsed:r=!1,overflow:s="scroll"}=this.options,{lineHeight:a}=this.metrics,o=this.fileRenderer.getLineCount(this.file),h=B(this.metrics,n),d=fe(this.metrics);if(this.height+=h,r){this.layoutDirty=!1;return}if(this.height+=this.cache.fileAnnotationHeight,s==="scroll"&&!this.hasLineAnnotations())this.height+=o*a;else for(let l=0;l<o;l++)this.addLayoutCheckpoint(l,this.height),this.height+=this.getLineHeight(l,!1);if(o>0&&(this.height+=d),this.fileContainer!=null&&e&&!t){const l=this.fileContainer.getBoundingClientRect();l.height!==this.height?console.log("VirtualizedFile.computeApproximateSize: computed height doesnt match",{name:this.file.name,elementHeight:l.height,computedHeight:this.height}):console.log("VirtualizedFile.computeApproximateSize: computed height IS CORRECT")}this.layoutDirty=!1}setVisibility(i){this.isAdvancedMode()||this.fileContainer==null||(i&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!i&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.file==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(i,e,t=!1){const{heights:n,checkpoints:r}=this.cache,s=this.renderRange;if(super.applyDocumentChange(i,e),this.getSimpleVirtualizer()?.markDOMDirty(),this.layoutDirty=!0,n.size>0&&n.clear(),r.length>0&&(r.length=0),this.isSimpleMode()&&this.computeApproximateSize(),t&&s!==void 0&&this.file!==void 0){const a=this.virtualizer.getWindowSpecs(),o=this.computeRenderRangeFromWindow(this.file,this.top??0,a);o.bufferAfter!==s.bufferAfter&&this.updateBuffers(o)}}render({fileContainer:i,file:e,forceRender:t=!1,lineAnnotations:n,...r}){const s=this.file==null||!A(this.file,e),{forceRenderOverride:a,isSetup:o}=this;this.forceRenderOverride=void 0;const h=this.syncLineAnnotations(n);if(h&&this.resetLayoutCache(),this.file=e,i=this.getOrCreateFileContainerNode(i),this.file==null)return console.error("VirtualizedFile.render: attempting to virtually render when we dont have file"),!1;if(o)this.top??=this.getVirtualizedTop(),s&&this.isSimpleMode()&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache(!0));else{this.computeApproximateSize();const u=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(u==null)throw new Error("VirtualizedFile.render: simple virtualizer is not available");u.connect(i,this),this.isVisible=u.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode())return this.renderPlaceholder(this.height);const d=this.virtualizer.getWindowSpecs(),l=this.top??0,c=this.computeRenderRangeFromWindow(this.file,l,d);return super.render({file:this.file,fileContainer:i,renderRange:c,lineAnnotations:n,forceRender:(a??t)||h,...r})}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}isSimpleMode(){return this.virtualizer.type==="simple"}isAdvancedMode(){return this.virtualizer.type==="advanced"}addLayoutCheckpoint(i,e){i%Ht===0&&this.cache.checkpoints.push({lineIndex:i,top:e})}getLayoutCheckpointBeforeLineIndex(i){if(i<=0||this.cache.checkpoints.length===0)return;let e=0,t=this.cache.checkpoints.length-1,n;for(;e<=t;){const r=e+t>>1,s=this.cache.checkpoints[r];if(s==null)throw new Error("VirtualizedFile: invalid checkpoint index");s.lineIndex<=i?(n=s,e=r+1):t=r-1}return n}getLayoutCheckpointBeforeTop(i,e){let t=0,n=this.cache.checkpoints.length-1,r=-1;for(;t<=n;){const s=t+n>>1,a=this.cache.checkpoints[s];if(a==null)throw new Error("VirtualizedFile: invalid checkpoint index");a.top<=i?(r=s,t=s+1):n=s-1}if(e==null)return r>=0?this.cache.checkpoints[r]:void 0;for(let s=r;s>=0;s--){const a=this.cache.checkpoints[s];if(a==null)throw new Error("VirtualizedFile: invalid checkpoint index");if(a.lineIndex%e===0)return a}}getVirtualizedTop(){return this.virtualizer.type==="advanced"?this.virtualizer.getLocalTopForInstance(this):this.fileContainer!=null?this.virtualizer.getOffsetInScrollContainer(this.fileContainer):0}getSimpleVirtualizer(){return this.virtualizer.type==="simple"?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}computeRenderRangeFromWindow(i,e,{top:t,bottom:n}){const{disableFileHeader:r=!1,overflow:s="scroll"}=this.options,{hunkLineCount:a,lineHeight:o}=this.metrics,h=this.fileRenderer.getLineCount(i),d=this.height,l=B(this.metrics,r),c=h>0?fe(this.metrics):0,{fileAnnotationHeight:u}=this.cache,p=l+u,f=Math.max(0,d-l-u-c),S=he(this.lineAnnotations),g=e+l,y=u>0&&S&&g<n&&g+u>t;if(e<t-d||e>n)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:d-l-c};if(h<=a)return{startingLine:0,totalLines:a,bufferBefore:0,bufferAfter:0};const m=Math.ceil(Math.max(n-t,0)/o),v=Math.ceil(m/a)*a+a*2,z=v/a,D=(t+n)/2;if(s==="scroll"&&!this.hasLineAnnotations()){const R=e+p,P=R+f;if(!y&&!(R<n&&P>t))return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:d-l-c};const w=Math.floor(y&&D<e+p?0:(D-(e+p))/o),b=Math.floor(w/a)-Math.floor(z/2),xe=Math.ceil(h/a),E=Math.max(0,Math.min(b,xe))*a,Q=b<0?v+b*a:v,we=E===0?0:u+E*o,Ee=Math.min(Q,h-E);return{startingLine:E,totalLines:Q,bufferBefore:we,bufferAfter:Math.max(0,(h-E-Ee)*o)}}const be=z,N=[],U=this.getLayoutCheckpointBeforeTop(Math.max(0,t-e-v*o*2),a);let T=e+(U?.top??p),_=U?.lineIndex??0,O,V,x;const Re=U?.lineIndex??0;for(let R=Re;R<h;R++){const P=_%a===0,w=Math.floor(_/a);if(P&&(N[w]=T-(e+p),x!=null)){if(x<=0)break;x--}const b=this.getLineHeight(R,!1);T>t-b&&T<n&&(O??=w),T+b>D&&(V??=w),x==null&&T>=n&&P&&(x=be),_++,T+=b}if(O==null)if(y)O=0,V=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:d-l-c};V??=O;const W=Math.round(V-z/2),Le=Math.max(0,Math.ceil(h/a)-z),G=Math.max(0,Math.min(W,Le)),J=G*a,Y=W<0?v+W*a:v,Ae=N[G]??0,He=J===0?0:u+Ae,X=G+Y/a,Me=X<N.length?f-N[X]:f-(T-e-p);return{startingLine:J,totalLines:Y,bufferBefore:He,bufferAfter:Math.max(0,Me)}}};function Et(i){let e;for(const t of i.children)t instanceof HTMLElement&&t.dataset.lineAnnotation===st&&(e=Math.max(e??0,t.getBoundingClientRect().height));return e}function Ft({file:i,renderCustomHeader:e,renderHeaderPrefix:t,renderHeaderFilenameSuffix:n,renderHeaderMetadata:r,renderAnnotation:s,lineAnnotations:a,renderGutterUtility:o,getHoveredLine:h}){const d=e?.(i),l=t?.(i),c=n?.(i),u=r?.(i);return C.jsxs(C.Fragment,{children:[d!=null?C.jsx("div",{slot:Ce,children:d}):C.jsxs(C.Fragment,{children:[l!=null&&C.jsx("div",{slot:"header-prefix",children:l}),c!=null&&C.jsx("div",{slot:"header-filename-suffix",children:c}),u!=null&&C.jsx("div",{slot:"header-metadata",children:u})]}),s!=null&&a?.map((p,f)=>C.jsx("div",{slot:I(p),children:s(p)},f)),o!=null&&C.jsx("div",{slot:"gutter-utility-slot",style:at,children:o(h)})]})}const me=typeof window>"u"?k.useEffect:k.useLayoutEffect;function kt({file:i,options:e,lineAnnotations:t,selectedLines:n,prerenderedHTML:r,metrics:s,hasGutterRenderUtility:a,hasCustomHeader:o,disableWorkerPool:h,contentEditable:d}){const l=ot(),c=n!==void 0,u=k.useContext(ht),p=lt(),f=k.useRef(null),S=dt(g=>{if(g!=null){if(f.current!=null)throw new Error("File: An instance should not already exist when a node is created");l!=null?f.current=new wt(K({controlledSelection:c,contentEditable:d,hasCustomHeader:o,hasEditor:p!==void 0,hasGutterRenderUtility:a,options:e}),l,s,h?void 0:u,!0):f.current=new Te(K({controlledSelection:c,contentEditable:d,hasCustomHeader:o,hasEditor:p!==void 0,hasGutterRenderUtility:a,options:e}),h?void 0:u,!0),f.current.hydrate({file:i,fileContainer:g,lineAnnotations:t,prerenderedHTML:r})}else{if(f.current==null)throw new Error("File: A File instance should exist when unmounting");f.current.cleanUp(),f.current=null}});return me(()=>{if(f.current==null)return;const g=K({controlledSelection:c,contentEditable:d,hasCustomHeader:o,hasEditor:p!==void 0,hasGutterRenderUtility:a,options:e}),y=!ye(f.current.options,g);f.current.setOptions(g),f.current.render({file:i,lineAnnotations:t,forceRender:y}),n!==void 0&&f.current.setSelectedLines(n)}),me(()=>{if(d&&f.current!=null){if(p===void 0)throw new Error("File: Editor is not attached");return p.edit(f.current)}},[d,p]),{ref:S,getHoveredLine:k.useCallback(()=>f.current?.getHoveredLine(),[])}}function K({options:i,controlledSelection:e,contentEditable:t,hasCustomHeader:n,hasEditor:r,hasGutterRenderUtility:s}){const a=t&&r,o=e||s||n;if(!o&&!a)return i;let h={...i};return o&&(h={...h,controlledSelection:e,renderCustomHeader:n?le:i?.renderCustomHeader,renderGutterUtility:s?le:i?.renderGutterUtility}),a&&(h={...h,useTokenTransformer:!0,enableGutterUtility:!1,enableLineSelection:!1,lineHoverHighlight:"disabled"}),h}function _t({file:i,lineAnnotations:e,selectedLines:t,options:n,metrics:r,className:s,style:a,renderAnnotation:o,renderCustomHeader:h,renderHeaderPrefix:d,renderHeaderFilenameSuffix:l,renderHeaderMetadata:c,prerenderedHTML:u,renderGutterUtility:p,disableWorkerPool:f=!1,contentEditable:S=!1}){const{ref:g,getHoveredLine:y}=kt({file:i,options:n,metrics:r,lineAnnotations:e,selectedLines:t,prerenderedHTML:u,hasGutterRenderUtility:p!=null,hasCustomHeader:h!=null,disableWorkerPool:f,contentEditable:S});return C.jsx(Oe,{ref:g,className:s,style:a,children:ct(Ft({file:i,renderAnnotation:o,renderCustomHeader:h,renderHeaderPrefix:d,renderHeaderFilenameSuffix:l,renderHeaderMetadata:c,renderGutterUtility:p,lineAnnotations:e,getHoveredLine:y}),u)})}const Wt=L.memo(function({jsonString:e,className:t,maxHeight:n="100%",initiallyExpandedDepth:r=2}){const s=L.useRef(null),[a,o]=L.useState(null),h=L.useMemo(()=>{try{const c=e.trim();if(!c)return o("Empty JSON content"),null;const u=JSON.parse(c);return o(null),u}catch(c){return o(c instanceof Error?c.message:"Invalid JSON"),null}},[e]),d=L.useCallback(()=>{s.current?.expandAll()},[]),l=L.useCallback(()=>{s.current?.collapseAll()},[]);return a?C.jsx("div",{className:t,children:C.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--syntax-base-background)] p-4",children:[C.jsx("div",{className:"mb-1 font-medium text-[var(--surface-foreground)]",children:"Invalid JSON"}),C.jsx("div",{className:"font-mono text-xs text-[var(--surface-mutedForeground)]",children:a})]})}):h===null?null:C.jsxs("div",{className:t,children:[C.jsxs("div",{className:"flex items-center gap-1 border-b border-[var(--interactive-border)] px-2 py-1",children:[C.jsxs(ee,{variant:"ghost",size:"xs",onClick:d,className:"gap-1 text-xs text-muted-foreground",children:[C.jsx(te,{name:"arrow-down-s",className:"h-3 w-3"}),"Expand All"]}),C.jsxs(ee,{variant:"ghost",size:"xs",onClick:l,className:"gap-1 text-xs text-muted-foreground",children:[C.jsx(te,{name:"arrow-up-s",className:"h-3 w-3"}),"Collapse All"]})]}),C.jsx("div",{className:"bg-[var(--syntax-base-background)] py-1",style:{maxHeight:n,overflow:"auto"},children:C.jsx(Ve,{ref:s,data:h,maxHeight:n,initiallyExpandedDepth:r})})]})});export{_t as F,Wt as J};
@@ -1,4 +1,4 @@
1
- import{k as _}from"./vendor-boot-EC6IyLt1.js";import{R as y}from"./vendor-react-DASdDPIk.js";import{m as je}from"./vendor-morphdom-B7dS_VPB.js";import{r as Ue}from"./vendor-beautiful-mermaid-DApbjBp2.js";import{z as Ze,A as Xe,f as ve,v as Ge,a2 as ee,bN as Ye,e as Z,T as te}from"./index-DWSrsQWl.js";import{cj as Ae,ck as Je,cl as Qe,ao as W,bC as et,bD as tt,cm as rt,cn as nt,o as ot,co as re,cp as at,cq as it,cr as st,z as ke,y as Ee,cs as Ce,ct as lt,b5 as ct}from"./useAppFontEffects-Bfw_d5eB.js";import{r as dt,s as ut,i as mt,a as ft,b as pt}from"./markdownCore-CqHYlXi_.js";import{r as ht}from"./registerCustomTheme-DmolaWWZ.js";import{saveOrShareFile as gt}from"./nativeFileSave-CFuugNKV.js";import{i as bt}from"./runtimeSurface-Der4qUnI.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-elkjs-D27273Ms.js";import"./vendor-entities-C3BA0AJP.js";import"./vendor-zustand-CUi8eEds.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-marked-CX41MkDF.js";import"./vendor-dompurify-r8glNMJW.js";import"./vendor-remend-BWYYytN3.js";import"./themeResolver-yJ9XpNMI.js";import"./vendor-pierre-theming-Dgp7B_O4.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";const Se="pichamber-md",wt={name:Se,colors:{"editor.background":"transparent","editor.foreground":"var(--md-syntax-foreground)"},tokenColors:[{scope:["comment","punctuation.definition.comment","string.comment"],settings:{foreground:"var(--md-syntax-comment)",fontStyle:"italic"}},{scope:["string","punctuation.definition.string","string.template"],settings:{foreground:"var(--md-syntax-string)"}},{scope:["constant.numeric","constant.language","constant.character","constant"],settings:{foreground:"var(--md-syntax-number)"}},{scope:["keyword","storage","storage.type","storage.modifier","keyword.control"],settings:{foreground:"var(--md-syntax-keyword)"}},{scope:["keyword.operator","punctuation.separator","punctuation.terminator"],settings:{foreground:"var(--md-syntax-operator)"}},{scope:["entity.name.function","support.function","meta.function-call"],settings:{foreground:"var(--md-syntax-function)"}},{scope:["entity.name.type","entity.name.class","support.type","support.class","entity.other.inherited-class"],settings:{foreground:"var(--md-syntax-type)"}},{scope:["variable","variable.other","variable.parameter","meta.definition.variable"],settings:{foreground:"var(--md-syntax-variable)"}},{scope:["variable.other.property","meta.property-name","support.type.property-name"],settings:{foreground:"var(--md-syntax-property)"}},{scope:["entity.name.tag","punctuation.definition.tag"],settings:{foreground:"var(--md-syntax-keyword)"}},{scope:["entity.other.attribute-name"],settings:{foreground:"var(--md-syntax-property)"}},{scope:["markup.bold","punctuation.definition.bold"],settings:{fontStyle:"bold"}},{scope:["markup.italic","punctuation.definition.italic"],settings:{fontStyle:"italic"}},{scope:["markup.heading","markup.heading entity.name"],settings:{foreground:"var(--md-syntax-keyword)",fontStyle:"bold"}},{scope:["markup.inserted","punctuation.definition.inserted"],settings:{foreground:"var(--md-syntax-inserted)"}},{scope:["markup.deleted","punctuation.definition.deleted"],settings:{foreground:"var(--md-syntax-deleted)"}},{scope:["invalid","invalid.illegal"],settings:{foreground:"var(--md-syntax-deleted)"}}]};let ne=!1;const yt=()=>{ne||(ne=!0,ht(Se,()=>Promise.resolve(wt)))},k=e=>Number.isFinite(e)&&e>0,oe=e=>{if(typeof e=="number")return k(e)?e:null;if(typeof e!="string")return null;const t=e.trim().match(/^([+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:[eE][+-]?\d+)?)(?:px)?$/);if(!t)return null;const n=Number(t[1]);return k(n)?n:null},B=(e,t,n)=>Math.min(n,Math.max(t,e)),vt=6,ae=1.25,At=1.0015,kt=.5,Et=12,ie=3,Ct=400,I='[data-markdown="mermaid-block"]',M=e=>e.querySelector(I)!==null,St=e=>[e.x,e.y,e.width,e.height].map(t=>{const n=Number(t.toFixed(vt));return Object.is(n,-0)?"0":String(n)}).join(" "),Mt=e=>{const t=e.viewBox?.trim().split(/[\s,]+/).map(s=>Number.parseFloat(s));if(t?.length===4){const[s,o,a,i]=t;if(Number.isFinite(s)&&Number.isFinite(o)&&k(a)&&k(i))return{x:s,y:o,width:a,height:i}}const n=oe(e.width),r=oe(e.height);return n===null||r===null?null:{x:0,y:0,width:n,height:r}},Lt=e=>{let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)},Nt=e=>{const t=e.renderMode||"unknown",n=e.svgMarkup??"";if(!n){const r=[e.viewBox??"",e.width??"",e.height??""];return r.some(s=>s!=="")?`${t}:bounds:${r.join(":")}`:`${t}:no-svg`}return[t,Lt(n)].join(":")},Me=(e,t)=>{if(!k(t.width)||!k(t.height))return e;const n=e.width/e.height,r=t.width/t.height;if(n>r){const o=e.width/r;return{x:e.x,y:e.y-(o-e.height)/2,width:e.width,height:o}}const s=e.height*r;return{x:e.x-(s-e.width)/2,y:e.y,width:s,height:e.height}},xt=({currentBox:e,viewport:t,delta:n})=>!k(t.width)||!k(t.height)||!k(e.width)||!k(e.height)?e:{x:e.x-n.x/t.width*e.width,y:e.y-n.y/t.height*e.height,width:e.width,height:e.height},Tt=(e,t)=>{const n=t.x-e.x,r=t.y-e.y;return n*n+r*r>ie*ie},Pt=({currentBox:e,contentBox:t,viewport:n,pointer:r,zoomFactor:s,minScale:o,maxScale:a})=>{if(!k(n.width)||!k(n.height)||!k(s)||!k(e.width)||!k(e.height)||!k(t.width)||!k(t.height)||!k(o)||!k(a))return e;const i=Math.min(o,a),l=Math.max(o,a),d=Me(t,n),c=d.width/e.width,m=B(c*s,i,l),f=d.width/m,p=f/(e.width/e.height),h=B(r.x/n.width,0,1),v=B(r.y/n.height,0,1),A=e.x+h*e.width,w=e.y+v*e.height;return{x:A-h*f,y:w-v*p,width:f,height:p}},X=new WeakMap,Rt=e=>e instanceof HTMLElement?X.get(e)??null:null,_t=e=>e.querySelector('[data-markdown="mermaid-viewport"]')??e.querySelector('[data-markdown="mermaid"]'),se=e=>{const t=e.querySelector('[data-markdown="mermaid"] svg'),n=e.querySelector('[data-markdown="mermaid"]');return Nt({renderMode:e.getAttribute("data-mermaid-render"),svgMarkup:n?.getAttribute("data-md-original-svg")??t?.outerHTML??null,viewBox:t?.getAttribute("viewBox"),width:t?.getAttribute("width"),height:t?.getAttribute("height")})},R=e=>{const t=e.getBoundingClientRect();return{width:t.width,height:t.height}},It=(e,t)=>{const n=t.getBoundingClientRect();return{x:e.clientX-n.left,y:e.clientY-n.top}},Ft=e=>e instanceof Element&&!!e.closest('button, a, [role="button"]'),Ot=e=>{const t=_t(e),n=e.querySelector('[data-markdown="mermaid"] svg');if(!t||!n)return null;const r=Mt({viewBox:n.getAttribute("viewBox"),width:n.getAttribute("width"),height:n.getAttribute("height")});if(!r)return null;let s=r,o=null,a=null,i=null,l=null;const d=u=>{s=u,n.setAttribute("viewBox",St(u)),n.removeAttribute("width"),n.removeAttribute("height")},c=()=>{d(Me(r,R(t)))},m=(u,E)=>{d(Pt({currentBox:s,contentBox:r,viewport:R(t),pointer:u,zoomFactor:E,minScale:kt,maxScale:Et}))},f=()=>{const u=R(t);m({x:u.width/2,y:u.height/2},ae)},p=()=>{const u=R(t);m({x:u.width/2,y:u.height/2},1/ae)},h=u=>{!u.ctrlKey&&!u.metaKey||(u.preventDefault(),u.stopPropagation(),m(It(u,t),Math.pow(At,-u.deltaY)))},v=u=>{u.button!==0||Ft(u.target)||(o=u.pointerId,a={x:u.clientX,y:u.clientY},i=a,l!==null&&(window.clearTimeout(l),l=null),e.removeAttribute("data-mermaid-suppress-click"),t.setPointerCapture?.(u.pointerId),e.setAttribute("data-mermaid-panning","true"),u.preventDefault())},A=u=>{if(o!==u.pointerId||!i)return;const E={x:u.clientX,y:u.clientY};d(xt({currentBox:s,viewport:R(t),delta:{x:E.x-i.x,y:E.y-i.y}})),i=E,a&&Tt(a,E)&&e.setAttribute("data-mermaid-suppress-click","true"),u.preventDefault()},w=u=>{o===u.pointerId&&(t.releasePointerCapture?.(u.pointerId),o=null,a=null,i=null,e.removeAttribute("data-mermaid-panning"),e.hasAttribute("data-mermaid-suppress-click")&&(l=window.setTimeout(()=>{e.removeAttribute("data-mermaid-suppress-click"),l=null},Ct)))},g=()=>{c()};t.addEventListener("wheel",h,{passive:!1}),t.addEventListener("pointerdown",v),t.addEventListener("pointermove",A),t.addEventListener("pointerup",w),t.addEventListener("pointercancel",w),window.addEventListener("resize",g);const b=typeof ResizeObserver>"u"?null:new ResizeObserver(g);return b?.observe(t),c(),{zoomIn:f,zoomOut:p,fit:c,cleanup:()=>{t.removeEventListener("wheel",h),t.removeEventListener("pointerdown",v),t.removeEventListener("pointermove",A),t.removeEventListener("pointerup",w),t.removeEventListener("pointercancel",w),window.removeEventListener("resize",g),b?.disconnect(),l!==null&&window.clearTimeout(l),e.removeAttribute("data-mermaid-panning"),e.removeAttribute("data-mermaid-suppress-click"),X.delete(e)}}},Dt=e=>{const t=new Map,n=new Map,r=()=>{for(const[o,a]of Array.from(t.entries())){const i=se(o);(!e.contains(o)||i!==n.get(o))&&(a.cleanup(),t.delete(o),n.delete(o))}for(const o of Array.from(e.querySelectorAll(I))){if(t.has(o)||o.querySelector('[data-markdown="mermaid"] svg')===null)continue;const a=Ot(o);a&&(t.set(o,a),n.set(o,se(o)),X.set(o,a))}},s=()=>{for(const o of t.values())o.cleanup();t.clear(),n.clear()};return r(),{refresh:r,cleanup:s}},x=e=>`<svg class="remixicon size-3.5" viewBox="0 0 24 24" aria-hidden="true"><use href="#oc-${e}"></use></svg>`,q={copy:x("file-copy"),check:x("check"),download:x("download"),zoomIn:x("add"),zoomOut:x("subtract"),fit:x("refresh")},Le="p-1 rounded hover:bg-interactive-hover/60 text-muted-foreground hover:text-foreground transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--interactive-focus-ring)]",$=(e,t)=>{e.innerHTML=t},S=(e,t,n)=>{const r=document.createElement("button");return r.type="button",r.className=Le,r.setAttribute("data-md-action",n),r.setAttribute("title",t),r.setAttribute("aria-label",t),$(r,q[e]),r},Ne=e=>{const t=e.querySelector("[data-md-code-body]"),n=e.querySelector("pre"),r=e.querySelector("pre code"),s=e.querySelectorAll("[data-md-code-line-content]");e.setAttribute("data-code-wrap","true"),t?.classList.remove("overflow-x-auto"),t?.classList.add("overflow-x-hidden"),n?.classList.add("whitespace-pre-wrap","break-words"),r?.classList.add("whitespace-pre-wrap","break-words"),n&&(n.style.whiteSpace="pre-wrap",n.style.overflowWrap="anywhere"),r&&(r.style.whiteSpace="pre-wrap",r.style.overflowWrap="anywhere");for(const o of Array.from(s))o.style.whiteSpace="pre-wrap",o.style.overflowWrap="anywhere"},xe=e=>{const t=e.querySelector(":scope > code");if(!t||t.hasAttribute("data-md-code-lines"))return;const n=t.textContent??"",r=n.endsWith(`
1
+ import{k as _}from"./vendor-boot-EC6IyLt1.js";import{R as y}from"./vendor-react-DASdDPIk.js";import{m as je}from"./vendor-morphdom-B7dS_VPB.js";import{r as Ue}from"./vendor-beautiful-mermaid-DApbjBp2.js";import{z as Ze,A as Xe,f as ve,v as Ge,a2 as ee,bN as Ye,e as Z,T as te}from"./index-DWSrsQWl.js";import{cj as Ae,ck as Je,cl as Qe,ao as W,bC as et,bD as tt,cm as rt,cn as nt,o as ot,co as re,cp as at,cq as it,cr as st,z as ke,y as Ee,cs as Ce,ct as lt,b5 as ct}from"./useAppFontEffects-BQ1JUauS.js";import{r as dt,s as ut,i as mt,a as ft,b as pt}from"./markdownCore-Csm6UEBe.js";import{r as ht}from"./registerCustomTheme-DmolaWWZ.js";import{saveOrShareFile as gt}from"./nativeFileSave-CFuugNKV.js";import{i as bt}from"./runtimeSurface-Der4qUnI.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-elkjs-D27273Ms.js";import"./vendor-entities-C3BA0AJP.js";import"./vendor-zustand-CUi8eEds.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-marked-CX41MkDF.js";import"./vendor-dompurify-r8glNMJW.js";import"./vendor-remend-BWYYytN3.js";import"./themeResolver-yJ9XpNMI.js";import"./vendor-pierre-theming-Dgp7B_O4.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";const Se="pichamber-md",wt={name:Se,colors:{"editor.background":"transparent","editor.foreground":"var(--md-syntax-foreground)"},tokenColors:[{scope:["comment","punctuation.definition.comment","string.comment"],settings:{foreground:"var(--md-syntax-comment)",fontStyle:"italic"}},{scope:["string","punctuation.definition.string","string.template"],settings:{foreground:"var(--md-syntax-string)"}},{scope:["constant.numeric","constant.language","constant.character","constant"],settings:{foreground:"var(--md-syntax-number)"}},{scope:["keyword","storage","storage.type","storage.modifier","keyword.control"],settings:{foreground:"var(--md-syntax-keyword)"}},{scope:["keyword.operator","punctuation.separator","punctuation.terminator"],settings:{foreground:"var(--md-syntax-operator)"}},{scope:["entity.name.function","support.function","meta.function-call"],settings:{foreground:"var(--md-syntax-function)"}},{scope:["entity.name.type","entity.name.class","support.type","support.class","entity.other.inherited-class"],settings:{foreground:"var(--md-syntax-type)"}},{scope:["variable","variable.other","variable.parameter","meta.definition.variable"],settings:{foreground:"var(--md-syntax-variable)"}},{scope:["variable.other.property","meta.property-name","support.type.property-name"],settings:{foreground:"var(--md-syntax-property)"}},{scope:["entity.name.tag","punctuation.definition.tag"],settings:{foreground:"var(--md-syntax-keyword)"}},{scope:["entity.other.attribute-name"],settings:{foreground:"var(--md-syntax-property)"}},{scope:["markup.bold","punctuation.definition.bold"],settings:{fontStyle:"bold"}},{scope:["markup.italic","punctuation.definition.italic"],settings:{fontStyle:"italic"}},{scope:["markup.heading","markup.heading entity.name"],settings:{foreground:"var(--md-syntax-keyword)",fontStyle:"bold"}},{scope:["markup.inserted","punctuation.definition.inserted"],settings:{foreground:"var(--md-syntax-inserted)"}},{scope:["markup.deleted","punctuation.definition.deleted"],settings:{foreground:"var(--md-syntax-deleted)"}},{scope:["invalid","invalid.illegal"],settings:{foreground:"var(--md-syntax-deleted)"}}]};let ne=!1;const yt=()=>{ne||(ne=!0,ht(Se,()=>Promise.resolve(wt)))},k=e=>Number.isFinite(e)&&e>0,oe=e=>{if(typeof e=="number")return k(e)?e:null;if(typeof e!="string")return null;const t=e.trim().match(/^([+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:[eE][+-]?\d+)?)(?:px)?$/);if(!t)return null;const n=Number(t[1]);return k(n)?n:null},B=(e,t,n)=>Math.min(n,Math.max(t,e)),vt=6,ae=1.25,At=1.0015,kt=.5,Et=12,ie=3,Ct=400,I='[data-markdown="mermaid-block"]',M=e=>e.querySelector(I)!==null,St=e=>[e.x,e.y,e.width,e.height].map(t=>{const n=Number(t.toFixed(vt));return Object.is(n,-0)?"0":String(n)}).join(" "),Mt=e=>{const t=e.viewBox?.trim().split(/[\s,]+/).map(s=>Number.parseFloat(s));if(t?.length===4){const[s,o,a,i]=t;if(Number.isFinite(s)&&Number.isFinite(o)&&k(a)&&k(i))return{x:s,y:o,width:a,height:i}}const n=oe(e.width),r=oe(e.height);return n===null||r===null?null:{x:0,y:0,width:n,height:r}},Lt=e=>{let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)},Nt=e=>{const t=e.renderMode||"unknown",n=e.svgMarkup??"";if(!n){const r=[e.viewBox??"",e.width??"",e.height??""];return r.some(s=>s!=="")?`${t}:bounds:${r.join(":")}`:`${t}:no-svg`}return[t,Lt(n)].join(":")},Me=(e,t)=>{if(!k(t.width)||!k(t.height))return e;const n=e.width/e.height,r=t.width/t.height;if(n>r){const o=e.width/r;return{x:e.x,y:e.y-(o-e.height)/2,width:e.width,height:o}}const s=e.height*r;return{x:e.x-(s-e.width)/2,y:e.y,width:s,height:e.height}},xt=({currentBox:e,viewport:t,delta:n})=>!k(t.width)||!k(t.height)||!k(e.width)||!k(e.height)?e:{x:e.x-n.x/t.width*e.width,y:e.y-n.y/t.height*e.height,width:e.width,height:e.height},Tt=(e,t)=>{const n=t.x-e.x,r=t.y-e.y;return n*n+r*r>ie*ie},Pt=({currentBox:e,contentBox:t,viewport:n,pointer:r,zoomFactor:s,minScale:o,maxScale:a})=>{if(!k(n.width)||!k(n.height)||!k(s)||!k(e.width)||!k(e.height)||!k(t.width)||!k(t.height)||!k(o)||!k(a))return e;const i=Math.min(o,a),l=Math.max(o,a),d=Me(t,n),c=d.width/e.width,m=B(c*s,i,l),f=d.width/m,p=f/(e.width/e.height),h=B(r.x/n.width,0,1),v=B(r.y/n.height,0,1),A=e.x+h*e.width,w=e.y+v*e.height;return{x:A-h*f,y:w-v*p,width:f,height:p}},X=new WeakMap,Rt=e=>e instanceof HTMLElement?X.get(e)??null:null,_t=e=>e.querySelector('[data-markdown="mermaid-viewport"]')??e.querySelector('[data-markdown="mermaid"]'),se=e=>{const t=e.querySelector('[data-markdown="mermaid"] svg'),n=e.querySelector('[data-markdown="mermaid"]');return Nt({renderMode:e.getAttribute("data-mermaid-render"),svgMarkup:n?.getAttribute("data-md-original-svg")??t?.outerHTML??null,viewBox:t?.getAttribute("viewBox"),width:t?.getAttribute("width"),height:t?.getAttribute("height")})},R=e=>{const t=e.getBoundingClientRect();return{width:t.width,height:t.height}},It=(e,t)=>{const n=t.getBoundingClientRect();return{x:e.clientX-n.left,y:e.clientY-n.top}},Ft=e=>e instanceof Element&&!!e.closest('button, a, [role="button"]'),Ot=e=>{const t=_t(e),n=e.querySelector('[data-markdown="mermaid"] svg');if(!t||!n)return null;const r=Mt({viewBox:n.getAttribute("viewBox"),width:n.getAttribute("width"),height:n.getAttribute("height")});if(!r)return null;let s=r,o=null,a=null,i=null,l=null;const d=u=>{s=u,n.setAttribute("viewBox",St(u)),n.removeAttribute("width"),n.removeAttribute("height")},c=()=>{d(Me(r,R(t)))},m=(u,E)=>{d(Pt({currentBox:s,contentBox:r,viewport:R(t),pointer:u,zoomFactor:E,minScale:kt,maxScale:Et}))},f=()=>{const u=R(t);m({x:u.width/2,y:u.height/2},ae)},p=()=>{const u=R(t);m({x:u.width/2,y:u.height/2},1/ae)},h=u=>{!u.ctrlKey&&!u.metaKey||(u.preventDefault(),u.stopPropagation(),m(It(u,t),Math.pow(At,-u.deltaY)))},v=u=>{u.button!==0||Ft(u.target)||(o=u.pointerId,a={x:u.clientX,y:u.clientY},i=a,l!==null&&(window.clearTimeout(l),l=null),e.removeAttribute("data-mermaid-suppress-click"),t.setPointerCapture?.(u.pointerId),e.setAttribute("data-mermaid-panning","true"),u.preventDefault())},A=u=>{if(o!==u.pointerId||!i)return;const E={x:u.clientX,y:u.clientY};d(xt({currentBox:s,viewport:R(t),delta:{x:E.x-i.x,y:E.y-i.y}})),i=E,a&&Tt(a,E)&&e.setAttribute("data-mermaid-suppress-click","true"),u.preventDefault()},w=u=>{o===u.pointerId&&(t.releasePointerCapture?.(u.pointerId),o=null,a=null,i=null,e.removeAttribute("data-mermaid-panning"),e.hasAttribute("data-mermaid-suppress-click")&&(l=window.setTimeout(()=>{e.removeAttribute("data-mermaid-suppress-click"),l=null},Ct)))},g=()=>{c()};t.addEventListener("wheel",h,{passive:!1}),t.addEventListener("pointerdown",v),t.addEventListener("pointermove",A),t.addEventListener("pointerup",w),t.addEventListener("pointercancel",w),window.addEventListener("resize",g);const b=typeof ResizeObserver>"u"?null:new ResizeObserver(g);return b?.observe(t),c(),{zoomIn:f,zoomOut:p,fit:c,cleanup:()=>{t.removeEventListener("wheel",h),t.removeEventListener("pointerdown",v),t.removeEventListener("pointermove",A),t.removeEventListener("pointerup",w),t.removeEventListener("pointercancel",w),window.removeEventListener("resize",g),b?.disconnect(),l!==null&&window.clearTimeout(l),e.removeAttribute("data-mermaid-panning"),e.removeAttribute("data-mermaid-suppress-click"),X.delete(e)}}},Dt=e=>{const t=new Map,n=new Map,r=()=>{for(const[o,a]of Array.from(t.entries())){const i=se(o);(!e.contains(o)||i!==n.get(o))&&(a.cleanup(),t.delete(o),n.delete(o))}for(const o of Array.from(e.querySelectorAll(I))){if(t.has(o)||o.querySelector('[data-markdown="mermaid"] svg')===null)continue;const a=Ot(o);a&&(t.set(o,a),n.set(o,se(o)),X.set(o,a))}},s=()=>{for(const o of t.values())o.cleanup();t.clear(),n.clear()};return r(),{refresh:r,cleanup:s}},x=e=>`<svg class="remixicon size-3.5" viewBox="0 0 24 24" aria-hidden="true"><use href="#oc-${e}"></use></svg>`,q={copy:x("file-copy"),check:x("check"),download:x("download"),zoomIn:x("add"),zoomOut:x("subtract"),fit:x("refresh")},Le="p-1 rounded hover:bg-interactive-hover/60 text-muted-foreground hover:text-foreground transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--interactive-focus-ring)]",$=(e,t)=>{e.innerHTML=t},S=(e,t,n)=>{const r=document.createElement("button");return r.type="button",r.className=Le,r.setAttribute("data-md-action",n),r.setAttribute("title",t),r.setAttribute("aria-label",t),$(r,q[e]),r},Ne=e=>{const t=e.querySelector("[data-md-code-body]"),n=e.querySelector("pre"),r=e.querySelector("pre code"),s=e.querySelectorAll("[data-md-code-line-content]");e.setAttribute("data-code-wrap","true"),t?.classList.remove("overflow-x-auto"),t?.classList.add("overflow-x-hidden"),n?.classList.add("whitespace-pre-wrap","break-words"),r?.classList.add("whitespace-pre-wrap","break-words"),n&&(n.style.whiteSpace="pre-wrap",n.style.overflowWrap="anywhere"),r&&(r.style.whiteSpace="pre-wrap",r.style.overflowWrap="anywhere");for(const o of Array.from(s))o.style.whiteSpace="pre-wrap",o.style.overflowWrap="anywhere"},xe=e=>{const t=e.querySelector(":scope > code");if(!t||t.hasAttribute("data-md-code-lines"))return;const n=t.textContent??"",r=n.endsWith(`
2
2
  `),s=r?n.slice(0,-1).split(`
3
3
  `):n.split(`
4
4
  `),o=s.length>0?s:[""],a=Array.from(t.children).filter(d=>d.classList.contains("line"));r&&a.length===o.length+1&&a.at(-1)?.textContent===""&&a.pop();const i=a.length===o.length,l=document.createDocumentFragment();o.forEach((d,c)=>{const m=document.createElement("span");m.setAttribute("data-md-code-line","");const f=document.createElement("span");f.setAttribute("data-md-code-line-number",""),f.setAttribute("aria-hidden","true"),f.textContent=String(c+1);const p=document.createElement("span");if(p.setAttribute("data-md-code-line-content",""),i){const h=a[c];h&&p.append(...Array.from(h.childNodes))}else p.textContent=d;if(m.append(f,p),l.appendChild(m),c<o.length-1||r){const h=document.createElement("span");h.setAttribute("data-md-code-line-break",""),h.textContent=`
@@ -1 +1 @@
1
- import{e4 as j,dG as k,dK as y}from"./useAppFontEffects-Bfw_d5eB.js";import{f as D,B as C}from"./web-components-CeHLxvED.js";import{M as P,G as O,u as L,W as A,a as M,b as R,n as F,t as H}from"./Virtualizer-DP6HbEeC.js";import{k as d}from"./vendor-boot-EC6IyLt1.js";import{V as _,F as N}from"./VirtualizedFileDiff-BS-af6rn.js";import{a as w}from"./vendor-react-DASdDPIk.js";function T({hunkIndex:e,lineIndex:t,conflictIndex:n}){return`merge-conflict-action-${e}-${t}-${n}`}function V(e,t){const n=t.hunks[e.hunkIndex];if(n!=null)return{hunkIndex:e.hunkIndex,lineIndex:z(n,e.startContentIndex)}}function z(e,t){let n=e.unifiedLineStart;for(let l=0;l<t;l++){const s=e.hunkContent[l];n+=s.type==="context"?s.lines:s.deletions+s.additions}return n}function G(e){const t=j(e);if(t.length!==1)throw console.error(t),new Error("PatchDiff: Provided patch must include only 1 patch, with 1 diff");const{files:n}=t[0];if(n.length!==1)throw console.error(n),new Error("FileDiff: Provided patch must contain exactly 1 file diff");return n[0]}function U({fileDiff:e,actions:t,renderCustomHeader:n,renderHeaderPrefix:l,renderHeaderFilenameSuffix:s,renderHeaderMetadata:x,renderAnnotation:f,renderGutterUtility:u,renderMergeConflictUtility:o,lineAnnotations:a,getHoveredLine:g,getInstance:m}){const p=n?.(e),c=l?.(e),i=s?.(e),v=x?.(e);return d.jsxs(d.Fragment,{children:[p!=null?d.jsx("div",{slot:k,children:p}):d.jsxs(d.Fragment,{children:[c!=null&&d.jsx("div",{slot:"header-prefix",children:c}),i!=null&&d.jsx("div",{slot:"header-filename-suffix",children:i}),v!=null&&d.jsx("div",{slot:"header-metadata",children:v})]}),f!=null&&a?.map((r,h)=>d.jsx("div",{slot:D(r),children:f(r)},h)),t!=null&&o!=null&&m!=null&&t.map(r=>{if(r==null)return;const h=$(r,e);return d.jsx("div",{slot:h,style:P,children:o(r,m)},h)}),u!=null&&d.jsx("div",{slot:"gutter-utility-slot",style:O,children:u(g)})]})}function $(e,t){const n=V(e,t);return n!=null?T({hunkIndex:n.hunkIndex,lineIndex:n.lineIndex,conflictIndex:e.conflictIndex}):void 0}const S=typeof window>"u"?w.useEffect:w.useLayoutEffect;function b({fileDiff:e,options:t,lineAnnotations:n,selectedLines:l,prerenderedHTML:s,metrics:x,hasGutterRenderUtility:f,hasCustomHeader:u,disableWorkerPool:o,contentEditable:a}){const g=L(),m=l!==void 0,p=w.useContext(A),c=M(),i=w.useRef(null),v=R(r=>{if(r!=null){if(i.current!=null)throw new Error("useFileDiffInstance: An instance should not already exist when a node is created");g!=null?i.current=new _(E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),g,x,o?void 0:p,!0):i.current=new N(E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),o?void 0:p,!0),i.current.hydrate({fileDiff:e,fileContainer:r,lineAnnotations:n,prerenderedHTML:s})}else{if(i.current==null)throw new Error("useFileDiffInstance: A FileDiff instance should exist when unmounting");i.current.cleanUp(),i.current=null}});return S(()=>{const{current:r}=i;if(r==null)return;const h=E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),I=!C(r.options,h);r.setOptions(h),r.render({forceRender:I,fileDiff:e,lineAnnotations:n}),l!==void 0&&r.setSelectedLines(l)}),S(()=>{if(a&&i.current!=null){if(c===void 0)throw new Error("FileDiff: Editor is not attached");return c.edit(i.current)}},[a,c]),{ref:v,getHoveredLine:w.useCallback(()=>i.current?.getHoveredLine(),[])}}function E({options:e,controlledSelection:t,contentEditable:n,hasCustomHeader:l,hasEditor:s,hasGutterRenderUtility:x}){const f=n&&s,u=t||x||l;if(!u&&!f)return e;let o={...e};return u&&(o={...o,controlledSelection:t,renderCustomHeader:l?F:e?.renderCustomHeader,renderGutterUtility:x?F:e?.renderGutterUtility}),f&&(o={...o,useTokenTransformer:!0,enableGutterUtility:!1,enableLineSelection:!1,expandUnchanged:!0,lineHoverHighlight:"disabled"}),o}function Y({patch:e,options:t,metrics:n,lineAnnotations:l,selectedLines:s,className:x,style:f,prerenderedHTML:u,renderAnnotation:o,renderCustomHeader:a,renderHeaderPrefix:g,renderHeaderFilenameSuffix:m,renderHeaderMetadata:p,renderGutterUtility:c,disableWorkerPool:i=!1,contentEditable:v=!1}){const r=q(e),{ref:h,getHoveredLine:I}=b({fileDiff:r,options:t,metrics:n,lineAnnotations:l,selectedLines:s,prerenderedHTML:u,hasGutterRenderUtility:c!=null,hasCustomHeader:a!=null,disableWorkerPool:i,contentEditable:v});return d.jsx(y,{ref:h,className:x,style:f,children:H(U({fileDiff:r,renderCustomHeader:a,renderHeaderPrefix:g,renderHeaderFilenameSuffix:m,renderHeaderMetadata:p,renderAnnotation:o,lineAnnotations:l,renderGutterUtility:c,getHoveredLine:I}),u)})}function q(e){return w.useMemo(()=>G(e),[e])}export{Y as P};
1
+ import{e4 as j,dG as k,dK as y}from"./useAppFontEffects-BQ1JUauS.js";import{f as D,B as C}from"./web-components-CJ0xIy7r.js";import{M as P,G as O,u as L,W as A,a as M,b as R,n as F,t as H}from"./Virtualizer-DP6HbEeC.js";import{k as d}from"./vendor-boot-EC6IyLt1.js";import{V as _,F as N}from"./VirtualizedFileDiff-CJ1m8JE-.js";import{a as w}from"./vendor-react-DASdDPIk.js";function T({hunkIndex:e,lineIndex:t,conflictIndex:n}){return`merge-conflict-action-${e}-${t}-${n}`}function V(e,t){const n=t.hunks[e.hunkIndex];if(n!=null)return{hunkIndex:e.hunkIndex,lineIndex:z(n,e.startContentIndex)}}function z(e,t){let n=e.unifiedLineStart;for(let l=0;l<t;l++){const s=e.hunkContent[l];n+=s.type==="context"?s.lines:s.deletions+s.additions}return n}function G(e){const t=j(e);if(t.length!==1)throw console.error(t),new Error("PatchDiff: Provided patch must include only 1 patch, with 1 diff");const{files:n}=t[0];if(n.length!==1)throw console.error(n),new Error("FileDiff: Provided patch must contain exactly 1 file diff");return n[0]}function U({fileDiff:e,actions:t,renderCustomHeader:n,renderHeaderPrefix:l,renderHeaderFilenameSuffix:s,renderHeaderMetadata:x,renderAnnotation:f,renderGutterUtility:u,renderMergeConflictUtility:o,lineAnnotations:a,getHoveredLine:g,getInstance:m}){const p=n?.(e),c=l?.(e),i=s?.(e),v=x?.(e);return d.jsxs(d.Fragment,{children:[p!=null?d.jsx("div",{slot:k,children:p}):d.jsxs(d.Fragment,{children:[c!=null&&d.jsx("div",{slot:"header-prefix",children:c}),i!=null&&d.jsx("div",{slot:"header-filename-suffix",children:i}),v!=null&&d.jsx("div",{slot:"header-metadata",children:v})]}),f!=null&&a?.map((r,h)=>d.jsx("div",{slot:D(r),children:f(r)},h)),t!=null&&o!=null&&m!=null&&t.map(r=>{if(r==null)return;const h=$(r,e);return d.jsx("div",{slot:h,style:P,children:o(r,m)},h)}),u!=null&&d.jsx("div",{slot:"gutter-utility-slot",style:O,children:u(g)})]})}function $(e,t){const n=V(e,t);return n!=null?T({hunkIndex:n.hunkIndex,lineIndex:n.lineIndex,conflictIndex:e.conflictIndex}):void 0}const S=typeof window>"u"?w.useEffect:w.useLayoutEffect;function b({fileDiff:e,options:t,lineAnnotations:n,selectedLines:l,prerenderedHTML:s,metrics:x,hasGutterRenderUtility:f,hasCustomHeader:u,disableWorkerPool:o,contentEditable:a}){const g=L(),m=l!==void 0,p=w.useContext(A),c=M(),i=w.useRef(null),v=R(r=>{if(r!=null){if(i.current!=null)throw new Error("useFileDiffInstance: An instance should not already exist when a node is created");g!=null?i.current=new _(E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),g,x,o?void 0:p,!0):i.current=new N(E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),o?void 0:p,!0),i.current.hydrate({fileDiff:e,fileContainer:r,lineAnnotations:n,prerenderedHTML:s})}else{if(i.current==null)throw new Error("useFileDiffInstance: A FileDiff instance should exist when unmounting");i.current.cleanUp(),i.current=null}});return S(()=>{const{current:r}=i;if(r==null)return;const h=E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),I=!C(r.options,h);r.setOptions(h),r.render({forceRender:I,fileDiff:e,lineAnnotations:n}),l!==void 0&&r.setSelectedLines(l)}),S(()=>{if(a&&i.current!=null){if(c===void 0)throw new Error("FileDiff: Editor is not attached");return c.edit(i.current)}},[a,c]),{ref:v,getHoveredLine:w.useCallback(()=>i.current?.getHoveredLine(),[])}}function E({options:e,controlledSelection:t,contentEditable:n,hasCustomHeader:l,hasEditor:s,hasGutterRenderUtility:x}){const f=n&&s,u=t||x||l;if(!u&&!f)return e;let o={...e};return u&&(o={...o,controlledSelection:t,renderCustomHeader:l?F:e?.renderCustomHeader,renderGutterUtility:x?F:e?.renderGutterUtility}),f&&(o={...o,useTokenTransformer:!0,enableGutterUtility:!1,enableLineSelection:!1,expandUnchanged:!0,lineHoverHighlight:"disabled"}),o}function Y({patch:e,options:t,metrics:n,lineAnnotations:l,selectedLines:s,className:x,style:f,prerenderedHTML:u,renderAnnotation:o,renderCustomHeader:a,renderHeaderPrefix:g,renderHeaderFilenameSuffix:m,renderHeaderMetadata:p,renderGutterUtility:c,disableWorkerPool:i=!1,contentEditable:v=!1}){const r=q(e),{ref:h,getHoveredLine:I}=b({fileDiff:r,options:t,metrics:n,lineAnnotations:l,selectedLines:s,prerenderedHTML:u,hasGutterRenderUtility:c!=null,hasCustomHeader:a!=null,disableWorkerPool:i,contentEditable:v});return d.jsx(y,{ref:h,className:x,style:f,children:H(U({fileDiff:r,renderCustomHeader:a,renderHeaderPrefix:g,renderHeaderFilenameSuffix:m,renderHeaderMetadata:p,renderAnnotation:o,lineAnnotations:l,renderGutterUtility:c,getHoveredLine:I}),u)})}function q(e){return w.useMemo(()=>G(e),[e])}export{Y as P};
@@ -1,4 +1,4 @@
1
- import{aN as Se,k as z}from"./vendor-boot-EC6IyLt1.js";import{a as f,R as ae}from"./vendor-react-DASdDPIk.js";import{B as Ee}from"./web-components-CeHLxvED.js";import{f as ce}from"./computeVirtualFileMetrics-BI6wORhM.js";import{V as ke,F as Te}from"./VirtualizedFileDiff-BS-af6rn.js";import{b5 as xe,at as Oe}from"./useAppFontEffects-Bfw_d5eB.js";import{P as ze,S as De}from"./StickyHorizontalScrollbar-BMITjK4e.js";import{b0 as Ce}from"./runtimeEndpointReset-BA2uP2rj.js";import{ensurePierreThemeRegistered as ue,getResolvedShikiTheme as he}from"./appThemeRegistry-gegrE2dq.js";import{T as de,e as fe}from"./index-DWSrsQWl.js";const J=new Set;let ne=null;function E(n){J.add(n),ne??=requestAnimationFrame(be)}function be(n){const e=new Set(J);J.clear();for(const t of e)try{t(n)}catch(r){console.error(r)}J.size>0?ne=requestAnimationFrame(be):ne=null}function ge({scrollTop:n,scrollHeight:e,height:t,fitPerfectly:r=!1,fitPerfectlyOverscroll:i=0,overscrollSize:s}){const h=t+s*2,d=r?t+i*2:h;if(e=Math.max(e,d),h>=e||r){const g=Math.max(n-i,0),y=Math.min(n+d,e);return{top:g,bottom:Math.max(y,g)}}let c=n+t/2-h/2,m=c+h;return c<0&&(c=0),m>e&&(m=e),c=Math.floor(Math.max(c,0)),{top:c,bottom:Math.ceil(Math.max(Math.min(m,e),c))}}function Ie(n,e){return n==null||e==null?n===e:n.top===e.top&&n.bottom===e.bottom}const ye=1e3,Me=ye*4,He=[0,1e-6,.99999,1],Pe={overscrollSize:ye,intersectionObserverMargin:Me,resizeDebugging:!1};let Z=0,Le=-1;var _e=class T{static __STOP=!1;static __lastScrollPosition=0;__id=`virtualizer-${++Le}`;config;type="simple";intersectionObserver;scrollTop=0;height=0;scrollHeight=0;windowSpecs={top:0,bottom:0};root;contentContainer;resizeObserver;observers=new Map;visibleInstances=new Map;visibleInstancesDirty=!1;instancesChanged=new Set;scrollDirty=!0;heightDirty=!0;scrollHeightDirty=!0;renderedObservers=0;connectQueue=new Map;constructor(e){this.config={...Pe,...e}}setup(e,t){if(this.root==null){this.root=e,this.resizeObserver=new ResizeObserver(this.handleContainerResize),this.intersectionObserver=new IntersectionObserver(this.handleIntersectionChange,{root:this.root,threshold:He,rootMargin:`${this.config.intersectionObserverMargin}px 0px ${this.config.intersectionObserverMargin}px 0px`}),e instanceof Document?this.setupWindow():this.setupElement(t),window.__INSTANCE=this,window.__TOGGLE=()=>{T.__STOP?(T.__STOP=!1,(this.getScrollContainerElement()??window).scrollTo({top:T.__lastScrollPosition}),E(this.computeRenderRangeAndEmit)):(T.__lastScrollPosition=this.getScrollTop(),T.__STOP=!0)};for(const[r,i]of this.connectQueue.entries())this.connect(r,i);this.connectQueue.clear(),this.markDOMDirty(),E(this.computeRenderRangeAndEmit)}}instanceChanged(e,t){this.instancesChanged.add(e),t&&this.markDOMDirty(),E(this.computeRenderRangeAndEmit)}getWindowSpecs(){return this.windowSpecs.top===0&&this.windowSpecs.bottom===0&&(this.windowSpecs=ge({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize})),this.windowSpecs}isInstanceVisible(e,t){const r=this.getScrollTop(),i=this.getHeight(),s=this.config.intersectionObserverMargin,h=r-s,d=r+i+s;return!(e<h-t||e>d)}handleContainerResize=e=>{if(this.root==null)return;let t=!1;for(const r of e){const i=r.borderBoxSize[0].blockSize;this.root instanceof Document?i!==this.scrollHeight&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log("Virtualizer: content size change",this.__id,{sizeChange:i-Z,newSize:i}),Z=i)):r.target===this.root?i!==this.height&&(this.heightDirty=!0,t=!0):r.target===this.contentContainer&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log("Virtualizer: scroller size change",this.__id,{sizeChange:i-Z,newSize:i}),Z=i))}t&&E(this.computeRenderRangeAndEmit)};setupWindow(){if(this.root==null||!(this.root instanceof Document))throw new Error("Virtualizer.setupWindow: Invalid setup method");window.addEventListener("scroll",this.handleWindowScroll,{passive:!0}),window.addEventListener("resize",this.handleWindowResize,{passive:!0}),this.resizeObserver?.observe(this.root.documentElement)}setupElement(e){if(this.root==null||this.root instanceof Document)throw new Error("Virtualizer.setupElement: Invalid setup method");this.root.addEventListener("scroll",this.handleElementScroll,{passive:!0}),this.resizeObserver?.observe(this.root),e??=this.root.firstElementChild??void 0,e instanceof HTMLElement&&(this.contentContainer=e,this.resizeObserver?.observe(e))}cleanUp(){this.resizeObserver?.disconnect(),this.resizeObserver=void 0,this.intersectionObserver?.disconnect(),this.intersectionObserver=void 0,this.root?.removeEventListener("scroll",this.handleElementScroll),window.removeEventListener("scroll",this.handleWindowScroll),window.removeEventListener("resize",this.handleWindowResize),this.root=void 0,this.contentContainer=void 0,this.observers.clear(),this.visibleInstances.clear(),this.instancesChanged.clear(),this.connectQueue.clear(),this.visibleInstancesDirty=!1,this.windowSpecs={top:0,bottom:0},this.scrollTop=0,this.height=0,this.scrollHeight=0}getOffsetInScrollContainer(e){return this.getScrollTop()+U(e,this.getScrollContainerElement())}connect(e,t){if(this.observers.has(e))throw new Error("Virtualizer.connect: instance is already connected...");return this.intersectionObserver==null?this.connectQueue.set(e,t):(this.intersectionObserver.observe(e),this.observers.set(e,t),this.instancesChanged.add(t),this.markDOMDirty(),E(this.computeRenderRangeAndEmit)),()=>this.disconnect(e)}disconnect(e){const t=this.observers.get(e);this.connectQueue.delete(e),t!=null&&(this.intersectionObserver?.unobserve(e),this.observers.delete(e),this.visibleInstances.delete(e)&&(this.visibleInstancesDirty=!0),this.markDOMDirty(),E(this.computeRenderRangeAndEmit))}handleWindowResize=()=>{T.__STOP||window.innerHeight===this.height||(this.heightDirty=!0,E(this.computeRenderRangeAndEmit))};handleWindowScroll=()=>{T.__STOP||this.root==null||!(this.root instanceof Document)||(this.scrollDirty=!0,E(this.computeRenderRangeAndEmit))};handleElementScroll=()=>{T.__STOP||this.root==null||this.root instanceof Document||(this.scrollDirty=!0,E(this.computeRenderRangeAndEmit))};computeRenderRangeAndEmit=()=>{if(T.__STOP)return;const e=this.heightDirty||this.scrollHeightDirty;if(!this.scrollDirty&&!this.scrollHeightDirty&&!this.heightDirty&&this.renderedObservers===this.observers.size&&!this.visibleInstancesDirty&&this.instancesChanged.size===0)return;let t=this.instancesChanged.size>0;if(this.instancesChanged.size===0){const s=ge({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize});if(!e&&Ie(this.windowSpecs,s)&&this.renderedObservers===this.observers.size&&!this.visibleInstancesDirty)return;this.windowSpecs=s}this.visibleInstancesDirty=!1,this.renderedObservers=this.observers.size;const r=this.getScrollAnchor(this.height),i=new Set;for(const s of e?this.observers.values():this.visibleInstances.values())s.onRender(e)&&i.add(s);for(const s of this.instancesChanged)i.has(s)||s.onRender(e)&&i.add(s);this.scrollFix(r);for(const s of i)s.reconcileHeights();t||=this.instancesChanged.size>0,t&&this.markDOMDirty(),(t||e)&&E(this.computeRenderRangeAndEmit),i.clear(),this.instancesChanged.clear()};scrollFix(e){if(e==null)return;const t=this.getScrollContainerElement(),{lineIndex:r,lineOffset:i,fileElement:s,fileOffset:h,fileTypeOffset:d}=e;if(r!=null&&i!=null){const m=s.shadowRoot?.querySelector(`[data-line][data-line-index="${r}"]`);if(m instanceof HTMLElement){const g=U(m,t);if(g!==i){const y=g-i;this.applyScrollFix(y)}return}}const c=U(s,t);if(d==="top")c!==h&&this.applyScrollFix(c-h);else{const m=c+s.getBoundingClientRect().height;m!==h&&this.applyScrollFix(m-h)}}applyScrollFix(e){this.root==null||this.root instanceof Document?window.scrollTo({top:window.scrollY+e,behavior:"instant"}):this.root.scrollTo({top:this.root.scrollTop+e,behavior:"instant"}),this.markDOMDirty()}getScrollAnchor(e){const t=this.getScrollContainerElement();let r;for(const[i]of this.visibleInstances.entries()){const s=U(i,t),h=s+i.offsetHeight;let d,c;h<=0?(d=h,c="bottom"):(d=s,c="top");let m,g;if(h>0&&s<e)for(const w of i.shadowRoot?.querySelectorAll("[data-line][data-line-index]")??[]){if(!(w instanceof HTMLElement))continue;const B=w.dataset.lineIndex;if(B==null)continue;const D=U(w,t);if(!(D<0)){m=B,g=D;break}}if(r?.lineOffset!=null&&g==null)continue;let y=!1;(r==null||g!=null&&(r.lineOffset==null||g<r.lineOffset)||g==null&&r.lineOffset==null&&(d>=0&&(r.fileOffset<0||d<r.fileOffset)||d<0&&r.fileOffset<0&&d>r.fileOffset))&&(y=!0),y&&(r={fileElement:i,fileTypeOffset:c,fileOffset:d,lineIndex:m,lineOffset:g})}return r}handleIntersectionChange=e=>{this.scrollDirty=!0;for(const{target:t,isIntersecting:r}of e){if(!(t instanceof HTMLElement))throw new Error("Virtualizer.handleIntersectionChange: target not an HTMLElement");const i=this.observers.get(t);i!=null&&(r&&!this.visibleInstances.has(t)?(i.setVisibility(!0),this.visibleInstances.set(t,i),this.visibleInstancesDirty=!0):!r&&this.visibleInstances.has(t)&&(i.setVisibility(!1),this.visibleInstances.delete(t),this.visibleInstancesDirty=!0))}this.visibleInstancesDirty&&E(this.computeRenderRangeAndEmit)};getScrollTop(){if(!this.scrollDirty)return this.scrollTop;this.scrollDirty=!1;let e=this.root==null?0:this.root instanceof Document?window.scrollY:this.root.scrollTop;return e=Math.max(0,Math.min(e,this.getScrollHeight()-this.getHeight())),this.scrollTop=e,e}getScrollHeight(){return this.scrollHeightDirty?(this.scrollHeightDirty=!1,this.scrollHeight=this.root==null?0:this.root instanceof Document?this.root.documentElement.scrollHeight:this.root.scrollHeight,this.scrollHeight):this.scrollHeight}getHeight(){return this.heightDirty?(this.heightDirty=!1,this.height=this.root==null?0:this.root instanceof Document?globalThis.innerHeight:this.root.getBoundingClientRect().height,this.height):this.height}markDOMDirty(){this.scrollDirty=!0,this.scrollHeightDirty=!0,this.heightDirty=!0}getScrollContainerElement(){return this.root==null||this.root instanceof Document?void 0:this.root}};function U(n,e){const t=n.getBoundingClientRect(),r=e?.getBoundingClientRect().top??0;return t.top-r}const pe=5e5,Fe=`
1
+ import{aN as Se,k as z}from"./vendor-boot-EC6IyLt1.js";import{a as f,R as ae}from"./vendor-react-DASdDPIk.js";import{B as Ee}from"./web-components-CJ0xIy7r.js";import{f as ce}from"./computeVirtualFileMetrics-8mC_o5zA.js";import{V as ke,F as Te}from"./VirtualizedFileDiff-CJ1m8JE-.js";import{b5 as xe,at as Oe}from"./useAppFontEffects-BQ1JUauS.js";import{P as ze,S as De}from"./StickyHorizontalScrollbar-BMITjK4e.js";import{b0 as Ce}from"./runtimeEndpointReset-CzwDZ_EP.js";import{ensurePierreThemeRegistered as ue,getResolvedShikiTheme as he}from"./appThemeRegistry-gegrE2dq.js";import{T as de,e as fe}from"./index-DWSrsQWl.js";const J=new Set;let ne=null;function E(n){J.add(n),ne??=requestAnimationFrame(be)}function be(n){const e=new Set(J);J.clear();for(const t of e)try{t(n)}catch(r){console.error(r)}J.size>0?ne=requestAnimationFrame(be):ne=null}function ge({scrollTop:n,scrollHeight:e,height:t,fitPerfectly:r=!1,fitPerfectlyOverscroll:i=0,overscrollSize:s}){const h=t+s*2,d=r?t+i*2:h;if(e=Math.max(e,d),h>=e||r){const g=Math.max(n-i,0),y=Math.min(n+d,e);return{top:g,bottom:Math.max(y,g)}}let c=n+t/2-h/2,m=c+h;return c<0&&(c=0),m>e&&(m=e),c=Math.floor(Math.max(c,0)),{top:c,bottom:Math.ceil(Math.max(Math.min(m,e),c))}}function Ie(n,e){return n==null||e==null?n===e:n.top===e.top&&n.bottom===e.bottom}const ye=1e3,Me=ye*4,He=[0,1e-6,.99999,1],Pe={overscrollSize:ye,intersectionObserverMargin:Me,resizeDebugging:!1};let Z=0,Le=-1;var _e=class T{static __STOP=!1;static __lastScrollPosition=0;__id=`virtualizer-${++Le}`;config;type="simple";intersectionObserver;scrollTop=0;height=0;scrollHeight=0;windowSpecs={top:0,bottom:0};root;contentContainer;resizeObserver;observers=new Map;visibleInstances=new Map;visibleInstancesDirty=!1;instancesChanged=new Set;scrollDirty=!0;heightDirty=!0;scrollHeightDirty=!0;renderedObservers=0;connectQueue=new Map;constructor(e){this.config={...Pe,...e}}setup(e,t){if(this.root==null){this.root=e,this.resizeObserver=new ResizeObserver(this.handleContainerResize),this.intersectionObserver=new IntersectionObserver(this.handleIntersectionChange,{root:this.root,threshold:He,rootMargin:`${this.config.intersectionObserverMargin}px 0px ${this.config.intersectionObserverMargin}px 0px`}),e instanceof Document?this.setupWindow():this.setupElement(t),window.__INSTANCE=this,window.__TOGGLE=()=>{T.__STOP?(T.__STOP=!1,(this.getScrollContainerElement()??window).scrollTo({top:T.__lastScrollPosition}),E(this.computeRenderRangeAndEmit)):(T.__lastScrollPosition=this.getScrollTop(),T.__STOP=!0)};for(const[r,i]of this.connectQueue.entries())this.connect(r,i);this.connectQueue.clear(),this.markDOMDirty(),E(this.computeRenderRangeAndEmit)}}instanceChanged(e,t){this.instancesChanged.add(e),t&&this.markDOMDirty(),E(this.computeRenderRangeAndEmit)}getWindowSpecs(){return this.windowSpecs.top===0&&this.windowSpecs.bottom===0&&(this.windowSpecs=ge({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize})),this.windowSpecs}isInstanceVisible(e,t){const r=this.getScrollTop(),i=this.getHeight(),s=this.config.intersectionObserverMargin,h=r-s,d=r+i+s;return!(e<h-t||e>d)}handleContainerResize=e=>{if(this.root==null)return;let t=!1;for(const r of e){const i=r.borderBoxSize[0].blockSize;this.root instanceof Document?i!==this.scrollHeight&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log("Virtualizer: content size change",this.__id,{sizeChange:i-Z,newSize:i}),Z=i)):r.target===this.root?i!==this.height&&(this.heightDirty=!0,t=!0):r.target===this.contentContainer&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log("Virtualizer: scroller size change",this.__id,{sizeChange:i-Z,newSize:i}),Z=i))}t&&E(this.computeRenderRangeAndEmit)};setupWindow(){if(this.root==null||!(this.root instanceof Document))throw new Error("Virtualizer.setupWindow: Invalid setup method");window.addEventListener("scroll",this.handleWindowScroll,{passive:!0}),window.addEventListener("resize",this.handleWindowResize,{passive:!0}),this.resizeObserver?.observe(this.root.documentElement)}setupElement(e){if(this.root==null||this.root instanceof Document)throw new Error("Virtualizer.setupElement: Invalid setup method");this.root.addEventListener("scroll",this.handleElementScroll,{passive:!0}),this.resizeObserver?.observe(this.root),e??=this.root.firstElementChild??void 0,e instanceof HTMLElement&&(this.contentContainer=e,this.resizeObserver?.observe(e))}cleanUp(){this.resizeObserver?.disconnect(),this.resizeObserver=void 0,this.intersectionObserver?.disconnect(),this.intersectionObserver=void 0,this.root?.removeEventListener("scroll",this.handleElementScroll),window.removeEventListener("scroll",this.handleWindowScroll),window.removeEventListener("resize",this.handleWindowResize),this.root=void 0,this.contentContainer=void 0,this.observers.clear(),this.visibleInstances.clear(),this.instancesChanged.clear(),this.connectQueue.clear(),this.visibleInstancesDirty=!1,this.windowSpecs={top:0,bottom:0},this.scrollTop=0,this.height=0,this.scrollHeight=0}getOffsetInScrollContainer(e){return this.getScrollTop()+U(e,this.getScrollContainerElement())}connect(e,t){if(this.observers.has(e))throw new Error("Virtualizer.connect: instance is already connected...");return this.intersectionObserver==null?this.connectQueue.set(e,t):(this.intersectionObserver.observe(e),this.observers.set(e,t),this.instancesChanged.add(t),this.markDOMDirty(),E(this.computeRenderRangeAndEmit)),()=>this.disconnect(e)}disconnect(e){const t=this.observers.get(e);this.connectQueue.delete(e),t!=null&&(this.intersectionObserver?.unobserve(e),this.observers.delete(e),this.visibleInstances.delete(e)&&(this.visibleInstancesDirty=!0),this.markDOMDirty(),E(this.computeRenderRangeAndEmit))}handleWindowResize=()=>{T.__STOP||window.innerHeight===this.height||(this.heightDirty=!0,E(this.computeRenderRangeAndEmit))};handleWindowScroll=()=>{T.__STOP||this.root==null||!(this.root instanceof Document)||(this.scrollDirty=!0,E(this.computeRenderRangeAndEmit))};handleElementScroll=()=>{T.__STOP||this.root==null||this.root instanceof Document||(this.scrollDirty=!0,E(this.computeRenderRangeAndEmit))};computeRenderRangeAndEmit=()=>{if(T.__STOP)return;const e=this.heightDirty||this.scrollHeightDirty;if(!this.scrollDirty&&!this.scrollHeightDirty&&!this.heightDirty&&this.renderedObservers===this.observers.size&&!this.visibleInstancesDirty&&this.instancesChanged.size===0)return;let t=this.instancesChanged.size>0;if(this.instancesChanged.size===0){const s=ge({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize});if(!e&&Ie(this.windowSpecs,s)&&this.renderedObservers===this.observers.size&&!this.visibleInstancesDirty)return;this.windowSpecs=s}this.visibleInstancesDirty=!1,this.renderedObservers=this.observers.size;const r=this.getScrollAnchor(this.height),i=new Set;for(const s of e?this.observers.values():this.visibleInstances.values())s.onRender(e)&&i.add(s);for(const s of this.instancesChanged)i.has(s)||s.onRender(e)&&i.add(s);this.scrollFix(r);for(const s of i)s.reconcileHeights();t||=this.instancesChanged.size>0,t&&this.markDOMDirty(),(t||e)&&E(this.computeRenderRangeAndEmit),i.clear(),this.instancesChanged.clear()};scrollFix(e){if(e==null)return;const t=this.getScrollContainerElement(),{lineIndex:r,lineOffset:i,fileElement:s,fileOffset:h,fileTypeOffset:d}=e;if(r!=null&&i!=null){const m=s.shadowRoot?.querySelector(`[data-line][data-line-index="${r}"]`);if(m instanceof HTMLElement){const g=U(m,t);if(g!==i){const y=g-i;this.applyScrollFix(y)}return}}const c=U(s,t);if(d==="top")c!==h&&this.applyScrollFix(c-h);else{const m=c+s.getBoundingClientRect().height;m!==h&&this.applyScrollFix(m-h)}}applyScrollFix(e){this.root==null||this.root instanceof Document?window.scrollTo({top:window.scrollY+e,behavior:"instant"}):this.root.scrollTo({top:this.root.scrollTop+e,behavior:"instant"}),this.markDOMDirty()}getScrollAnchor(e){const t=this.getScrollContainerElement();let r;for(const[i]of this.visibleInstances.entries()){const s=U(i,t),h=s+i.offsetHeight;let d,c;h<=0?(d=h,c="bottom"):(d=s,c="top");let m,g;if(h>0&&s<e)for(const w of i.shadowRoot?.querySelectorAll("[data-line][data-line-index]")??[]){if(!(w instanceof HTMLElement))continue;const B=w.dataset.lineIndex;if(B==null)continue;const D=U(w,t);if(!(D<0)){m=B,g=D;break}}if(r?.lineOffset!=null&&g==null)continue;let y=!1;(r==null||g!=null&&(r.lineOffset==null||g<r.lineOffset)||g==null&&r.lineOffset==null&&(d>=0&&(r.fileOffset<0||d<r.fileOffset)||d<0&&r.fileOffset<0&&d>r.fileOffset))&&(y=!0),y&&(r={fileElement:i,fileTypeOffset:c,fileOffset:d,lineIndex:m,lineOffset:g})}return r}handleIntersectionChange=e=>{this.scrollDirty=!0;for(const{target:t,isIntersecting:r}of e){if(!(t instanceof HTMLElement))throw new Error("Virtualizer.handleIntersectionChange: target not an HTMLElement");const i=this.observers.get(t);i!=null&&(r&&!this.visibleInstances.has(t)?(i.setVisibility(!0),this.visibleInstances.set(t,i),this.visibleInstancesDirty=!0):!r&&this.visibleInstances.has(t)&&(i.setVisibility(!1),this.visibleInstances.delete(t),this.visibleInstancesDirty=!0))}this.visibleInstancesDirty&&E(this.computeRenderRangeAndEmit)};getScrollTop(){if(!this.scrollDirty)return this.scrollTop;this.scrollDirty=!1;let e=this.root==null?0:this.root instanceof Document?window.scrollY:this.root.scrollTop;return e=Math.max(0,Math.min(e,this.getScrollHeight()-this.getHeight())),this.scrollTop=e,e}getScrollHeight(){return this.scrollHeightDirty?(this.scrollHeightDirty=!1,this.scrollHeight=this.root==null?0:this.root instanceof Document?this.root.documentElement.scrollHeight:this.root.scrollHeight,this.scrollHeight):this.scrollHeight}getHeight(){return this.heightDirty?(this.heightDirty=!1,this.height=this.root==null?0:this.root instanceof Document?globalThis.innerHeight:this.root.getBoundingClientRect().height,this.height):this.height}markDOMDirty(){this.scrollDirty=!0,this.scrollHeightDirty=!0,this.heightDirty=!0}getScrollContainerElement(){return this.root==null||this.root instanceof Document?void 0:this.root}};function U(n,e){const t=n.getBoundingClientRect(),r=e?.getBoundingClientRect().top??0;return t.top-r}const pe=5e5,Fe=`
2
2
  :host {
3
3
  font-family: var(--font-mono);
4
4
  font-size: var(--text-code);